[
  {
    "path": ".github/workflows/build.yml",
    "content": "name: build\n\non: \n  push:\n    paths: \n      - build/**\n      - .github/workflows/build.yml\n\njobs:\n  android:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip\n          sudo apt install unzip -y\n          unzip -q NDK\n          ANDROID_NDK_HOME=$(pwd)/android-ndk-r21b\n      - name: Build\n        run: |\n          cd build\n          ./make_android_lua54.sh\n          ./make_android_lua53.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_android\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_android \n\n  android_luajit:\n    runs-on: ubuntu-22.04\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip\n          sudo apt install unzip -y\n          unzip -q NDK\n          ANDROID_NDK_HOME=$(pwd)/android-ndk-r15c\n      - name: Build\n        run: |\n          cd build\n          sudo apt install gcc-multilib libncurses5 -y\n          ./make_android_luajit_arm64.sh  \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_android\n  \n  ohos:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          cd ~\n          curl -O https://repo.huaweicloud.com/harmonyos/os/4.1-Release/ohos-sdk-windows_linux-public.tar.gz\n          tar xvfz ohos-sdk-windows_linux-public.tar.gz\n          cd ohos-sdk/linux\n          unzip -o -d ./ native-linux-x64-4.1.7.5-Release.zip\n      - name: Build\n        run: |\n          cd build\n          chmod +x make_ohos_lua5*.sh\n          OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos_lua54.sh\n          OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos_lua53.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_ohos\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_ohos\n\n  linux:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_linux_lua54.sh\n          ./make_linux64_lua53.sh\n          ./make_linux64_luajit.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_linux  \n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_linux     \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_linux  \n  ios:\n    runs-on: macos-latest\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_ios_lua54.sh\n          ./make_ios_lua53.sh\n          ./make_ios_luajit.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_ios\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_ios   \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_ios\n  osx:\n    runs-on: macos-latest\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_osx_lua54.sh\n          ./make_osx_lua53.sh\n          ./make_osx_luajit.sh\n          ./make_osx_silicon_lua53.sh\n          ./make_osx_silicon_lua54.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_osx  \n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_osx     \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_osx  \n  windows:\n    runs-on: windows-2022\n\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: Insatll MSVC\n        uses: microsoft/setup-msbuild@v1.0.2\n      \n      - name: Build\n        run: |\n          cd build\n          .\\make_win_lua54.bat\n          .\\make_uwp_lua54.bat\n          .\\make_win32_lua53.bat\n          .\\make_win64_lua53.bat\n          .\\make_uwp.bat\n      - uses: ilammy/msvc-dev-cmd@v1\n      - name: Build Luajit\n        run: |\n          cd build\n          .\\make_win64_luajit.bat\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_window\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_window   \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_window\n          \n  windows-luajit-32:\n    runs-on: windows-2022\n\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: Insatll MSVC\n        uses: microsoft/setup-msbuild@v1.0.2\n      \n      - uses: ilammy/msvc-dev-cmd@v1\n        with:\n          arch: x86\n      - name: Build Luajit\n        run: |\n          cd build\n          .\\make_win32_luajit.bat  \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_window32\n    \n\n   \n"
  },
  {
    "path": ".github/workflows/publish.yml",
    "content": "name: publish\n\non: \n  workflow_dispatch:\n    inputs:\n      tag_name:\n        description: 'tag name'     \n        required: true\n\njobs:\n  android:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip\n          sudo apt install unzip -y\n          unzip -q NDK\n          ANDROID_NDK_HOME=$(pwd)/android-ndk-r21b\n      - name: Build\n        run: |\n          cd build\n          ./make_android_lua54.sh\n          ./make_android_lua53.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_android\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_android \n\n  android_luajit:\n    runs-on: ubuntu-22.04\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip\n          sudo apt install unzip -y\n          unzip -q NDK\n          ANDROID_NDK_HOME=$(pwd)/android-ndk-r15c\n      - name: Build\n        run: |\n          cd build\n          sudo apt update\n          sudo apt install gcc-multilib libncurses5 -y\n          ./make_android_luajit_arm64.sh  \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_android\n  \n  ohos:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install NDK\n        run: |\n          cd ~\n          cd ~\n          curl -O https://repo.huaweicloud.com/harmonyos/os/4.1-Release/ohos-sdk-windows_linux-public.tar.gz\n          tar xvfz ohos-sdk-windows_linux-public.tar.gz\n          cd ohos-sdk/linux\n          unzip -o -d ./ native-linux-x64-4.1.7.5-Release.zip\n      - name: Build\n        run: |\n          cd build\n          chmod +x make_ohos_lua5*.sh\n          OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos_lua54.sh\n          OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos_lua53.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_ohos\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_ohos\n\n  linux:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_linux_lua54.sh\n          ./make_linux64_lua53.sh\n          ./make_linux64_luajit.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_linux  \n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_linux     \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_linux  \n  ios:\n    runs-on: macos-latest\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_ios_lua54.sh\n          ./make_ios_lua53.sh\n          ./make_ios_luajit.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_ios\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_ios   \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_ios\n  osx:\n    runs-on: macos-latest\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Build\n        run: |\n          cd build\n          ./make_osx_lua54.sh\n          ./make_osx_lua53.sh\n          ./make_osx_luajit.sh\n          ./make_osx_silicon_lua53.sh\n          ./make_osx_silicon_lua54.sh\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_osx  \n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_osx     \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_osx  \n  windows:\n    runs-on: windows-2022\n\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: Insatll MSVC\n        uses: microsoft/setup-msbuild@v1.0.2\n      \n      - name: Build\n        run: |\n          cd build\n          .\\make_win_lua54.bat\n          .\\make_uwp_lua54.bat\n          .\\make_win32_lua53.bat\n          .\\make_win64_lua53.bat\n          .\\make_uwp.bat\n      - uses: ilammy/msvc-dev-cmd@v1\n      - name: Build Luajit\n        run: |\n          cd build\n          .\\make_win64_luajit.bat\n      - name: Upload\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua54/**/*\n          name: plugin_lua54_window\n      - name: Upload53\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_lua53/**/*\n          name: plugin_lua53_window   \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_window\n          \n  windows-luajit-32:\n    runs-on: windows-2022\n\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: Insatll MSVC\n        uses: microsoft/setup-msbuild@v1.0.2\n      \n      - uses: ilammy/msvc-dev-cmd@v1\n        with:\n          arch: x86\n      - name: Build Luajit\n        run: |\n          cd build\n          .\\make_win32_luajit.bat  \n      - name: UploadJit\n        uses: actions/upload-artifact@v4\n        with:\n          path: ./build/plugin_luajit/**/*\n          name: plugin_luajit_window32\n\n  publish:\n    runs-on: ubuntu-latest\n    needs: [windows,osx,ios,android,windows-luajit-32,ohos,android_luajit,linux]\n    steps:\n      - uses: actions/download-artifact@v4\n        with:\n          pattern: plugin_luajit_*\n          path: plugin_luajit/\n          merge-multiple: true\n          \n      - uses: actions/download-artifact@v4\n        with:\n          pattern: plugin_lua53_*\n          path: plugin_lua53/\n          merge-multiple: true\n          \n      - uses: actions/download-artifact@v4\n        with:\n          pattern: plugin_lua54_*\n          path: plugin_lua54/\n          merge-multiple: true\n          \n      - name: Create Release Asset\n        run: |\n          cd plugin_luajit/ && tar cvfz ../luajit_${{ github.event.inputs.tag_name }}.tgz Plugins && cd -\n          cd plugin_lua53/ && tar cvfz ../lua53_${{ github.event.inputs.tag_name }}.tgz Plugins && cd -\n          cd plugin_lua54/ && tar cvfz ../lua54_${{ github.event.inputs.tag_name }}.tgz Plugins && cd -\n          \n      - name: Create Release\n        id: create_release\n        uses: actions/create-release@v1\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        with:\n          tag_name: ${{ github.event.inputs.tag_name }}\n          release_name: Tag:${{ github.event.inputs.tag_name }}\n          draft: false\n          prerelease: false\n          \n      - name: Upload luajit Plugins\n        #id: upload-release-asset \n        uses: actions/upload-release-asset@v1\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        with:\n          upload_url: ${{ steps.create_release.outputs.upload_url }}\n          asset_path: ./luajit_${{ github.event.inputs.tag_name }}.tgz\n          asset_name: luajit_${{ github.event.inputs.tag_name }}.tgz\n          asset_content_type: application/tgz\n          \n      - name: Upload lua53 Plugins\n        #id: upload-release-asset \n        uses: actions/upload-release-asset@v1\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        with:\n          upload_url: ${{ steps.create_release.outputs.upload_url }}\n          asset_path: ./lua53_${{ github.event.inputs.tag_name }}.tgz\n          asset_name: lua53_${{ github.event.inputs.tag_name }}.tgz\n          asset_content_type: application/tgz\n          \n      - name: Upload lua54 Plugins\n        #id: upload-release-asset \n        uses: actions/upload-release-asset@v1\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        with:\n          upload_url: ${{ steps.create_release.outputs.upload_url }}\n          asset_path: ./lua54_${{ github.event.inputs.tag_name }}.tgz\n          asset_name: lua54_${{ github.event.inputs.tag_name }}.tgz\n          asset_content_type: application/tgz\n   \n"
  },
  {
    "path": ".gitignore",
    "content": ".vs\r\n/Library\r\n/ProjectSettings\r\n/Temp\r\n/Assets/XLua/Gen\r\n/Assets/XLua/Gen.meta\r\nAssets/StreamingAssets.meta\r\nAssets/StreamingAssets/\r\nAssets/xLuaTest.meta\r\nAssets/xLuaTest/\r\n/*.csproj\r\n/*.sln\r\n/build/build*\r\nUnityVS\r\n/Assets/UnityVS.meta\r\n.DS_Store\r\n*.o\r\n/build/*/*.a\r\nluajit\r\nbuildvm\r\nminilua\r\nlibluajit.so\r\nlj_vm.S\r\nbuild/luajit-2.1.0b2/src/host/buildvm_arch.h\r\nbuild/luajit-2.1.0b2/src/jit/vmdef.lua\r\nbuild/luajit-2.1.0b2/src/lj_bcdef.h\r\nbuild/luajit-2.1.0b2/src/lj_ffdef.h\r\nbuild/luajit-2.1.0b2/src/lj_folddef.h\r\nbuild/luajit-2.1.0b2/src/lj_libdef.h\r\nbuild/luajit-2.1.0b2/src/lj_recdef.h\r\nbuild/luajit-2.1.0b2/src/lua51.lib\r\nbuild/luajit-2.1.0b2/src/luajit.exe\r\nbuild/luajit-2.1.0b2/src/luajit.exp\r\nbuild/luajit-2.1.0b2/src/luajit.lib\r\n\r\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: csharp\r\nscript:\r\n  - cd build\r\n  - chmod +x *.sh\r\n  - ./make_linux64_lua53.sh\r\n  - ./make_linux64_luajit.sh\r\n  - cd ../General\r\n  - msbuild /property:Configuration=Release vs2013/XLua.sln\r\n  - cp ../build/build_linux64/libxlua.so Bin/\r\n  - cp ../build/build_linux64/libxlua.so Tools/\r\n  - mono Bin/XLuaUnitTest.exe\r\n  - mono Tools/XLuaGenerate.exe Bin/XLuaTest.exe\r\n  - mv Gen Gen1\r\n  - mono Tools/XLuaGenerate.exe Bin/XLuaUnitTest.exe\r\n  - mv Gen Gen2\r\n  - msbuild /property:Configuration=Release vs2013/XLuaGenTest.sln\r\n  - mono Bin/XLuaUnitTestGenCode.exe\r\n  - cp ../build/build_linux64_lj/libxlua.so Bin/\r\n  - mono Bin/XLuaUnitTest.exe\r\n  - mono Bin/XLuaUnitTestGenCode.exe\r\n#  - pdb2mdb Bin/XLuaTestGenCode.exe\r\n#  - mono Tools/XLuaHotfixInject.exe Bin/XLuaTestGenCode.exe ./\r\n#  - mono Bin/XLuaTestGenCode.exe\r\n"
  },
  {
    "path": "Assets/Plugins/Android/libs/arm64-v8a/libxlua.so.meta",
    "content": "fileFormatVersion: 2\nguid: 6c76d1cfa11c6b741ba30b24d36cbcf2\nPluginImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  iconMap: {}\n  executionOrder: {}\n  defineConstraints: []\n  isPreloaded: 0\n  isOverridable: 0\n  isExplicitlyReferenced: 0\n  platformData:\n  - first:\n      Android: Android\n    second:\n      enabled: 1\n      settings:\n        CPU: ARM64\n  - first:\n      Any: \n    second:\n      enabled: 0\n      settings: {}\n  - first:\n      Editor: Editor\n    second:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs/arm64-v8a.meta",
    "content": "fileFormatVersion: 2\nguid: 084116138e3349d48bdf50214aebefc5\nfolderAsset: yes\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs/armeabi-v7a/libxlua.so.meta",
    "content": "fileFormatVersion: 2\nguid: 6e1b2e17cce240d4c8ff5457ac996e0d\ntimeCreated: 1451443249\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 1\n      settings:\n        CPU: ARMv7\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs/armeabi-v7a.meta",
    "content": "fileFormatVersion: 2\nguid: b8d0cd0f5702f0144af2498bce3ee3e9\nfolderAsset: yes\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs/x86/libxlua.so.meta",
    "content": "fileFormatVersion: 2\nguid: 038a89637b659e346a7a712ce0c9271b\ntimeCreated: 1451443249\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 1\n      settings:\n        CPU: x86\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs/x86.meta",
    "content": "fileFormatVersion: 2\nguid: 079ea0ed741ff194a80cce029630b5ac\nfolderAsset: yes\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android/libs.meta",
    "content": "fileFormatVersion: 2\nguid: 9cd62bafd75e7604daf2b561b80d136d\nfolderAsset: yes\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/Android.meta",
    "content": "fileFormatVersion: 2\nguid: 0004c0a5ad641d4468ebb65779ee48b2\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/Plugins/WSA/ARM/xlua.dll.meta",
    "content": "fileFormatVersion: 2\nguid: cb3d94d8757d66b40b20f0386b52d01d\ntimeCreated: 1490146878\nlicenseType: Free\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  isOverridable: 0\n  platformData:\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n    WindowsStoreApps:\n      enabled: 1\n      settings:\n        CPU: ARM\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA/ARM.meta",
    "content": "fileFormatVersion: 2\nguid: e6375603a0a1e2647b0c426b27646eb7\nfolderAsset: yes\ntimeCreated: 1490146877\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA/x64/xlua.dll.meta",
    "content": "fileFormatVersion: 2\nguid: a73864467778862409da51f9feb60004\ntimeCreated: 1490146878\nlicenseType: Free\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  isOverridable: 0\n  platformData:\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n    WindowsStoreApps:\n      enabled: 1\n      settings:\n        CPU: x64\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA/x64.meta",
    "content": "fileFormatVersion: 2\nguid: 4d5a7116d7e9a33409205303635b8635\nfolderAsset: yes\ntimeCreated: 1490146877\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA/x86/xlua.dll.meta",
    "content": "fileFormatVersion: 2\nguid: 3fd23a6414095674493657a67a8043a1\ntimeCreated: 1489995544\nlicenseType: Free\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  isOverridable: 0\n  platformData:\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n    WindowsStoreApps:\n      enabled: 1\n      settings:\n        CPU: x86\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA/x86.meta",
    "content": "fileFormatVersion: 2\nguid: 6e0f35de38a8ed24fa8b20d444c9ee5e\nfolderAsset: yes\ntimeCreated: 1490146877\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WSA.meta",
    "content": "fileFormatVersion: 2\nguid: b8c5688e381fddc4eb22e6f96f69541c\nfolderAsset: yes\ntimeCreated: 1489995541\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WebGL/xlua_webgl.cpp",
    "content": "extern \"C\" {\n#include \"../../../WebGLPlugins/lapi.c\"\n#include \"../../../WebGLPlugins/lauxlib.c\"\n#include \"../../../WebGLPlugins/lbaselib.c\"\n#include \"../../../WebGLPlugins/lbitlib.c\"\n#include \"../../../WebGLPlugins/lcode.c\"\n#include \"../../../WebGLPlugins/lcorolib.c\"\n#include \"../../../WebGLPlugins/lctype.c\"\n#include \"../../../WebGLPlugins/ldblib.c\"\n#include \"../../../WebGLPlugins/ldebug.c\"\n#include \"../../../WebGLPlugins/ldo.c\"\n#include \"../../../WebGLPlugins/ldump.c\"\n#include \"../../../WebGLPlugins/lfunc.c\"\n#include \"../../../WebGLPlugins/lgc.c\"\n#include \"../../../WebGLPlugins/linit.c\"\n#include \"../../../WebGLPlugins/liolib.c\"\n#include \"../../../WebGLPlugins/llex.c\"\n#include \"../../../WebGLPlugins/lmathlib.c\"\n#include \"../../../WebGLPlugins/lmem.c\"\n#include \"../../../WebGLPlugins/loadlib.c\"\n#include \"../../../WebGLPlugins/lobject.c\"\n#include \"../../../WebGLPlugins/lopcodes.c\"\n#include \"../../../WebGLPlugins/loslib.c\"\n#include \"../../../WebGLPlugins/lparser.c\"\n#include \"../../../WebGLPlugins/lstate.c\"\n#include \"../../../WebGLPlugins/lstring.c\"\n#include \"../../../WebGLPlugins/lstrlib.c\"\n#include \"../../../WebGLPlugins/ltable.c\"\n#include \"../../../WebGLPlugins/ltablib.c\"\n#include \"../../../WebGLPlugins/ltm.c\"\n#include \"../../../WebGLPlugins/lundump.c\"\n#include \"../../../WebGLPlugins/lutf8lib.c\"\n#include \"../../../WebGLPlugins/lvm.c\"\n#include \"../../../WebGLPlugins/lzio.c\"\n#include \"../../../WebGLPlugins/i64lib.c\"\n#include \"../../../WebGLPlugins/perflib.c\"\n#include \"../../../WebGLPlugins/xlua.c\"\n}\n\n\n\n"
  },
  {
    "path": "Assets/Plugins/WebGL/xlua_webgl.cpp.meta",
    "content": "fileFormatVersion: 2\nguid: 92f9773841d5ffd44b794b9b584a5c05\ntimeCreated: 1504062948\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 2\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  isOverridable: 0\n  platformData:\n    data:\n      first:\n        Any: \n      second:\n        enabled: 0\n        settings: {}\n    data:\n      first:\n        Editor: Editor\n      second:\n        enabled: 0\n        settings:\n          DefaultValueInitialized: true\n    data:\n      first:\n        Facebook: WebGL\n      second:\n        enabled: 1\n        settings: {}\n    data:\n      first:\n        WebGL: WebGL\n      second:\n        enabled: 1\n        settings: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/WebGL.meta",
    "content": "fileFormatVersion: 2\nguid: e7f3a5adb034d684cb13cb257c29a1c3\nfolderAsset: yes\ntimeCreated: 1504062948\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/arm64/libxlua.dylib.meta",
    "content": "fileFormatVersion: 2\nguid: 27cd65c4cc42b42f49caa94f462466de\nPluginImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  iconMap: {}\n  executionOrder: {}\n  defineConstraints: []\n  isPreloaded: 0\n  isOverridable: 0\n  isExplicitlyReferenced: 0\n  validateReferences: 1\n  platformData:\n  - first:\n      : Any\n    second:\n      enabled: 0\n      settings:\n        Exclude Editor: 0\n        Exclude Linux64: 1\n        Exclude OSXUniversal: 0\n        Exclude Win: 1\n        Exclude Win64: 1\n  - first:\n      Any: \n    second:\n      enabled: 0\n      settings: {}\n  - first:\n      Editor: Editor\n    second:\n      enabled: 1\n      settings:\n        CPU: ARM64\n        DefaultValueInitialized: true\n        OS: AnyOS\n  - first:\n      Standalone: Linux64\n    second:\n      enabled: 0\n      settings:\n        CPU: None\n  - first:\n      Standalone: OSXUniversal\n    second:\n      enabled: 1\n      settings:\n        CPU: ARM64\n  - first:\n      Standalone: Win\n    second:\n      enabled: 0\n      settings:\n        CPU: x86\n  - first:\n      Standalone: Win64\n    second:\n      enabled: 0\n      settings:\n        CPU: x86_64\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/iOS/HotfixFlags.cpp",
    "content": "#include <stddef.h>\n#include <stdlib.h>\n\nint* xlua_hotfix_flags = NULL;\nint xlua_hotfix_flags_len = 0;\n\nextern \"C\" {\n\nint xlua_get_hotfix_flag(int idx) {\n\tif (idx >= xlua_hotfix_flags_len) {\n\t\treturn 0;\n\t} else {\n\t\treturn xlua_hotfix_flags[idx];\n\t}\n}\n\nvoid xlua_set_hotfix_flag(int idx, int flag) {\n\tint i = 0;\n        int* new_hotfix_flags = NULL;\n\tif (idx >= xlua_hotfix_flags_len) {\n\t\tif (xlua_hotfix_flags == NULL) {\n\t\t\txlua_hotfix_flags = (int*)malloc((idx + 1) * sizeof(int));\n\t\t} else {\n\t\t\tnew_hotfix_flags = (int*)realloc(xlua_hotfix_flags, (idx + 1) * sizeof(int));\n                        if (NULL == new_hotfix_flags) { // just skip operation\n                            return;\n                        }\n                        xlua_hotfix_flags = new_hotfix_flags;\n\t\t}\n\t\tfor(i = xlua_hotfix_flags_len; i < (idx + 1); i++) {\n\t\t\txlua_hotfix_flags[i] = 0;\n\t\t}\n                xlua_hotfix_flags_len = idx + 1;\n\t} \n\txlua_hotfix_flags[idx] = flag;\n}\n}\n"
  },
  {
    "path": "Assets/Plugins/iOS/HotfixFlags.cpp.meta",
    "content": "fileFormatVersion: 2\nguid: ef0ed550afe43d449b58d883fad0585c\ntimeCreated: 1498103331\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  isOverridable: 0\n  platformData:\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n    iOS:\n      enabled: 1\n      settings: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/iOS/libxlua.a.meta",
    "content": "fileFormatVersion: 2\nguid: 2d65468f3356ca741b3fbebea91dfb6c\ntimeCreated: 1451443249\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 0\n      settings:\n        DefaultValueInitialized: true\n    iOS:\n      enabled: 1\n      settings: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/iOS.meta",
    "content": "fileFormatVersion: 2\nguid: 5a4ab2e5e00054b03a7bf96d03e5b4e1\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/Plugins/x86/libxlua.so.meta",
    "content": "fileFormatVersion: 2\nguid: 9f19d785ae44ddc478a08a87ccd9dbb2\ntimeCreated: 1488352111\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 1\n      settings:\n        CPU: x86\n        DefaultValueInitialized: true\n        OS: AnyOS\n    Linux:\n      enabled: 1\n      settings:\n        CPU: x86\n    Linux64:\n      enabled: 0\n      settings:\n        CPU: None\n    LinuxUniversal:\n      enabled: 1\n      settings:\n        CPU: x86\n    OSXIntel:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXIntel64:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXUniversal:\n      enabled: 0\n      settings:\n        CPU: None\n    WP8:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n    Win:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    Win64:\n      enabled: 0\n      settings:\n        CPU: None\n    WindowsStoreApps:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n        SDK: AnySDK\n    iOS:\n      enabled: 0\n      settings:\n        CompileFlags: \n        FrameworkDependencies: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/x86/xlua.dll.meta",
    "content": "fileFormatVersion: 2\nguid: 79f5c811b2e4e444ab2d97cad5cfd934\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 1\n      settings:\n        CPU: x86\n        DefaultValueInitialized: true\n        OS: Windows\n    Linux:\n      enabled: 1\n      settings:\n        CPU: x86\n    Linux64:\n      enabled: 0\n      settings:\n        CPU: None\n    LinuxUniversal:\n      enabled: 0\n      settings:\n        CPU: x86\n    OSXIntel:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    OSXIntel64:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXUniversal:\n      enabled: 0\n      settings:\n        CPU: x86\n    WP8:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n    Win:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    Win64:\n      enabled: 0\n      settings:\n        CPU: None\n    WindowsStoreApps:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n        SDK: AnySDK\n    iOS:\n      enabled: 0\n      settings:\n        CompileFlags: \n        FrameworkDependencies: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/x86.meta",
    "content": "fileFormatVersion: 2\nguid: 8b0b0c4ffe67d2f4292c5211de91e55f\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/Plugins/x86_64/libxlua.so.meta",
    "content": "fileFormatVersion: 2\nguid: 1055830ddb882704fa71275ed9b2a78d\ntimeCreated: 1488352111\nlicenseType: Pro\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 1\n      settings:\n        CPU: x86_64\n        DefaultValueInitialized: true\n        OS: AnyOS\n    Linux:\n      enabled: 0\n      settings:\n        CPU: None\n    Linux64:\n      enabled: 1\n      settings:\n        CPU: x86_64\n    LinuxUniversal:\n      enabled: 1\n      settings:\n        CPU: x86_64\n    OSXIntel:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXIntel64:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXUniversal:\n      enabled: 0\n      settings:\n        CPU: None\n    WP8:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n    Win:\n      enabled: 0\n      settings:\n        CPU: None\n    Win64:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    WindowsStoreApps:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n        SDK: AnySDK\n    iOS:\n      enabled: 0\n      settings:\n        CompileFlags: \n        FrameworkDependencies: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/x86_64/xlua.dll.meta",
    "content": "fileFormatVersion: 2\nguid: abe4c5ca91772ea4fae0ae15603c10e4\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 1\n      settings:\n        CPU: x86_64\n        DefaultValueInitialized: true\n        OS: Windows\n    Linux:\n      enabled: 0\n      settings:\n        CPU: None\n    Linux64:\n      enabled: 1\n      settings:\n        CPU: x86_64\n    LinuxUniversal:\n      enabled: 0\n      settings:\n        CPU: x86_64\n    OSXIntel:\n      enabled: 0\n      settings:\n        CPU: None\n    OSXIntel64:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    OSXUniversal:\n      enabled: 0\n      settings:\n        CPU: x86_64\n    WP8:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n    Win:\n      enabled: 0\n      settings:\n        CPU: None\n    Win64:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    WindowsStoreApps:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n        DontProcess: False\n        PlaceholderPath: \n        SDK: AnySDK\n    iOS:\n      enabled: 0\n      settings:\n        CompileFlags: \n        FrameworkDependencies: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/x86_64.meta",
    "content": "fileFormatVersion: 2\nguid: 8dba1dfb80e5b7d40bd214fc4ed2ed6b\nfolderAsset: yes\ntimeCreated: 1451020766\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle/Contents/Info.plist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>BuildMachineOSBuild</key>\n\t<string>15G31</string>\n\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleExecutable</key>\n\t<string>xlua</string>\n\t<key>CFBundleIdentifier</key>\n\t<string>com.xlua</string>\n\t<key>CFBundleInfoDictionaryVersion</key>\n\t<string>6.0</string>\n\t<key>CFBundleName</key>\n\t<string>xlua</string>\n\t<key>CFBundlePackageType</key>\n\t<string>BNDL</string>\n\t<key>CFBundleShortVersionString</key>\n\t<string>1.0</string>\n\t<key>CFBundleSignature</key>\n\t<string>????</string>\n\t<key>CFBundleSupportedPlatforms</key>\n\t<array>\n\t\t<string>MacOSX</string>\n\t</array>\n\t<key>CFBundleVersion</key>\n\t<string>1</string>\n\t<key>DTCompiler</key>\n\t<string>com.apple.compilers.llvm.clang.1_0</string>\n\t<key>DTPlatformBuild</key>\n\t<string>7D1014</string>\n\t<key>DTPlatformVersion</key>\n\t<string>GM</string>\n\t<key>DTSDKBuild</key>\n\t<string>15E60</string>\n\t<key>DTSDKName</key>\n\t<string>macosx10.11</string>\n\t<key>DTXcode</key>\n\t<string>0731</string>\n\t<key>DTXcodeBuild</key>\n\t<string>7D1014</string>\n\t<key>NSHumanReadableCopyright</key>\n\t<string>Copyright @2017 THL A29 Limited, a Tencent company.  All rights reserved.</string>\n</dict>\n</plist>\n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle/Contents/Info.plist.meta",
    "content": "fileFormatVersion: 2\nguid: ac30af4fb2add4d41a9f50fe4f8292a3\ntimeCreated: 1457422749\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle/Contents/MacOS/xlua.meta",
    "content": "fileFormatVersion: 2\nguid: 6f3b1cda03ac84924b1ee0595fc019f5\ntimeCreated: 1457422749\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle/Contents/MacOS.meta",
    "content": "fileFormatVersion: 2\nguid: c9d8e68fa0fd1465294f1255f6ed8563\nfolderAsset: yes\ntimeCreated: 1457422691\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle/Contents.meta",
    "content": "fileFormatVersion: 2\nguid: 7e4b7549f5e4a4e71806e3ec8e428b15\nfolderAsset: yes\ntimeCreated: 1457422691\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins/xlua.bundle.meta",
    "content": "fileFormatVersion: 2\nguid: e6a34038df77e48438826b6ff94aa69e\nfolderAsset: yes\nPluginImporter:\n  serializedVersion: 1\n  iconMap: {}\n  executionOrder: {}\n  isPreloaded: 0\n  platformData:\n    Android:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Any:\n      enabled: 0\n      settings: {}\n    Editor:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n        DefaultValueInitialized: true\n        OS: OSX\n    Linux:\n      enabled: 0\n      settings:\n        CPU: x86\n    Linux64:\n      enabled: 0\n      settings:\n        CPU: x86_64\n    OSXIntel:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    OSXIntel64:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    OSXUniversal:\n      enabled: 1\n      settings:\n        CPU: AnyCPU\n    Win:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    Win64:\n      enabled: 0\n      settings:\n        CPU: AnyCPU\n    iOS:\n      enabled: 0\n      settings:\n        CompileFlags: \n        FrameworkDependencies: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/Plugins.meta",
    "content": "fileFormatVersion: 2\nguid: a16bb6756d0496e42a92390340cb94f5\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/CHANGELOG.txt",
    "content": "﻿v2.1.15 2020年6月24日\r\n新增特性\r\n1、生成代码过滤器\r\n2、优化反射查找delegate匹配bridge的性能\r\n3、unity 2019.2以上版本手机版本注入不了的问题\r\n\r\n变更\r\n\r\nbug修复\r\n1、反射查找同名delegate桥接在不生成代码的时候表现不一致\r\n2、嵌套struct标注为PackAsTable时生成代码报错\r\n3、反射wrap代码加入栈空间检查\r\n4、如果枚举定义了很多个值（几千个），会触发unity在android下的一个bug：函数体很大而且有很多分支，执行该函数会crash\r\n5、chunkname和脚本文件名不一致的问题\r\n6、最小生成模式枚举生成代码报错\r\n7、当采用反射方式注册枚举值时，如果一个枚举有多个相同的值，比如A,B都是1，那么在lua里头访问B将会为空\r\n8、sbyte[]在.net 4下push到lua变成字符串的问题\r\n9、泛型导致生成代码失败的问题\r\n10、非Assembly-CSharp程序集注入时，out参数处理有误\r\n11、内嵌类通过xlua.private_accessible设置私有访问可能失败的问题\r\n12、cecil插入指令后，并未自动更新offset，某种情况下会导致计算偏移量错误\r\n\r\n\r\nv2.1.14 2019年2月27日\r\n新增特性\r\n1、新增nintento switch的支持\r\n2、unity 2018兼容\r\n3、android arm64支持\r\n4、原生库的visual studio 2017编译支持\r\n5、增加“XLua/Generate Minimize Code”菜单\r\n6、防止有的工程有非法的dll导致生成代码中断\r\n7、更高效的lua_pushstring（需要通过NATIVE_LUA_PUSHSTRING开启）\r\n\r\n变更\r\n1、window库默认编译器改为visual studio 2017\r\n\r\nbug修复\r\n1、修正枚举类型如果只加GCOptimize不加LuaCallCSharp会crash的问题\r\n2、示例配置加入对Edtitor类的过滤\r\n3、UWP兼容修复\r\n4、接口继承引入的同签名方法实现\r\n5、未生成代码，extension方法行为不一致\r\n6、修复Nullable类型参数，如果最后一个参数是nil，会导致其他参数全是nil的问题\r\n\r\n\r\nv2.1.13 2018年12月5日\r\n新增特性\r\n1、新增AdaptByDelegate注入模式；\r\n2、新增xlua.get_generic_method，用于调用泛型函数；\r\n3、支持类似CS.System.Collections.Generic.List(CS.System.Int32)的泛型写法；\r\n4、注入新选项：忽略编译器自动生成代码，以及不生成base代理；\r\n5、针对lua编程以及热补丁，均添加直接可用的自动化配置样例；\r\n6、新增luajit的gc64支持；\r\n7、加入兼容字节码（一份字节码支持32位和64位系统）的支持；\r\n8、内置新lua内存泄漏检测工具；\r\n9、delegate桥接动态实例化：delegate是4个参数以内，参数均引用类型，无返回值或者返回引用类型，不用配置CSharpCallLua也能调用lua函数；\r\n10、提供util.print_func_ref_by_csharp函数，用于查看当前被C#引用的lua函数；\r\n11、支持无CS全局变量的工作方式；\r\n\r\n\r\n变更\r\n1、虚拟机升级：lua5.3.4 -> lua5.3.5，luajit2.1b2 -> luajit2.1b3；\r\n2、delegate bridge代码段占用优化；\r\n3、改为PostProcessBuild事件检查是否生成代码；\r\n4、适配xcode 10：osx平台不再支持32bit版本构建；\r\n5、名字空间、类名拼写错误时，对静态成员的设置会报错；\r\n6、防止CS全局table被删除导致xlua工作异常；\r\n7、Windows下构建lib，若使用vs 2015参数执行cmake失败，则继续尝试使用vs 2017；\r\n8、编辑器下不生成代码时，也检查Blacklist，维持和运行时一致；\r\n\r\nbug修复\r\n1、泛型的数组生成代码报错；\r\n2、防止对TypeExtensions配置了LuaCallCSharp后，lua里头IsValueType之类的判断永真；\r\n3、生成代码过滤掉含指针的函数和字段；\r\n4、适应索引器属性名不是Item的情况；\r\n5、解决attribute初始化异常会导致生成代码，注入终止的问题；\r\n6、精简模式下空Enum生成代码错误；\r\n7、通过把初始化函数分割成小函数，规避unity在android下执行大函数crash的bug；\r\n8、Assignable处理obj为null情况；\r\n9、内嵌类不Obsolete，但外层类Obsolete的生成代码报错\r\n10、解决inline注入方式下，如果lua逻辑跑异常，看不到异常信息的问题；\r\n11、修复xlua.private_accessible访问后，同名public的方法无法访问的Bug；\r\n12、[Out]修饰的参数不应该生成out关键字；\r\n13、通过反射查找合适的适配器时，有可能访问到非适配器函数；\r\n14、精简模式导出代码无get_Item、set_Item；\r\n15、IntKey方式下不自动xlua.private_accessible的问题；\r\n\r\n\r\nv2.1.12 2018年7月9日\r\n新增特性\r\n1、Nullable的支持\r\n2、支持Assembly-CSharp之外的dll注入（beta）\r\n3、执行xlua.hotfix，会自动让该类private能访问\r\n4、xlua.private_accessible优化：1、会把基类的也设置能私有访问；2、延迟到第一次访问类才私有化\r\n5、新增xlua.util.state，可为一个c#对象新增状态\r\n6、this[string field]或者this[object field]操作符重载新增get_Item和set_Item调用\r\n7、正在编译时注入打印error信息\r\n8、interface配置到CSharpCallLua时的事件跟索引映射的自动实现\r\n9、unity5.5以上去掉WARNING: The runtime version supported by this application is unavailable打印\r\n\r\n变更\r\n1、去除Stateful方式（因为xlua.util.state已经可以达成类似的效果）\r\n2、废弃掉内嵌模式模式\r\n\r\nbug修复\r\n1、生成代码局部变量加下划线，防止符号冲突\r\n2、如果类没放到Hotfix列表，不生成base调用代理\r\n3、代码重构，可读性优化\r\n4、解决带params byte[]可能会导致生成代码编译错误的问题\r\n5、解决类含有private event的时候，无法xlua.private_accessible的问题\r\n6、构造函数注入，如果branch外紧跟Ret指令，注入逻辑应该在branch以及Ret之间\r\n7、构造函数注入，如果注入指令后导致跳转范围大于一个字节，应修改为长跳转\r\n8、解决一个delegate如果不是某个类的内嵌类型时，CS.namespace.classname为空的问题\r\n9、防止Editor下的Util类名字冲突\r\n10、泛型override有异常，先过滤掉\r\n11、解决空enum导致生成代码编译错误\r\n12、解决uwp平台下il2cpp方式打包无法访问任何类的问题\r\n13、hotfix一个私有类型的params参数的函数，导致生成代码编译错误、注入失败的问题\r\n14、如果两个LuaBase指向的是同一个Lua对象，GetHashCode应该返回的是同一个值\r\n15、[Out]标记参数生成代码编译失败\r\n16、交错数组+多维数组的复合，生成代码报错的问题\r\n\r\nv2.1.11 2018年3月20日\r\n新增特性\r\n1、xlua.private_accessible支持私有内嵌类型\r\n2、添加xlua.release，用于主动解除lua对c#某对象的引用\r\n3、支持内嵌委托的显示构造\r\n4、需要传class的地方（比如xlua.private_accessible），支持传C#的Type对象\r\n5、支持用pairs遍历IEnumerable对象\r\n6、热补丁场景下，支持override函数调用被override函数（对应c# base关键字）\r\n\r\n变更\r\n1、简化property的反射访问，简化后有更好的兼容性；\r\n\r\nbug修复\r\n1、ios 11兼容（去除system调用）\r\n2、实现了interface的struct不走gc优化代码的问题\r\n3、emit特性的.net兼容性\r\n4、emit对于ulong的const值处理不当\r\n5、interface桥接代码，interface继承时，父interface和子interface有同名不同类型属性时的生成代码报错\r\n6、多虚拟机下，不断创建和销毁协程时，可能出现协程指针重复\r\n7、当参数为泛型类型时，如ICollectio时，不应该生成代码\r\n\r\nv2.1.10 2017年9月18日\r\n新增特性\r\n1、新增DoNotGen配置，支持一个类型部分函数用反射，部分用生成；\r\n2、新增wrapper的emit；\r\n3、webgl支持；\r\n4、lua实现interface支持interface继承；\r\n5、window下支持android编译（由xdestiny110提供）；\r\n6、打包时，如果没执行过“Generate Code”将报错；\r\n\r\n变更\r\n1、\tasync_to_sync的改为resume错误时报错；\r\n2、il2cpp下，暂时去掉泛型的反射调用；\r\n3、升级到lua5.3.4并合入2017-9-1为止所有官方patch；\r\n\r\nbug修复\r\n1、C#仅声明delegate和MulticastDelegate，通过反射创建lua function映射时crash；\r\n2、解决一些古老版本window（比如xp）的dll兼容问题；\r\n\r\nv2.1.9 2017年8月10日\r\n新增特性\r\n1、新增最小生成模式（通过GEN_CODE_MINIMIZE切换），可以节省50%的text段空间；\r\n2、新增xlua.util.createdelegate，支持在lua直接用C#函数创建delegate而不需要通过lua适配；\r\n3、xlua.private_accessible支持public int Prop { get; private set; }\r\n4、新增\txlua.getmetatable、xlua.setmetatable、xlua.setclass、xlua.genaccessor，用以支持lua使用C#类型直接在lua侧完成；\r\n5、反射下扩展方法的支持；\r\n6、lua53版本支持位操作符重载：C#侧的位操作符重载对应到lua的位操作符重载；enum全部加上&和|位操作符；\r\n\r\n工程优化\r\n1、加入travis持续集成；\r\n\r\n变更\r\n1、LuaCallCSharp自动去除匿名类型；\r\n2、THREAD_SAFT改为THREAD_SAFE；\r\n3、GenFlag.GCOptimize标记为过时；\r\n4、删除过时的GenConfig配置方式；\r\n\r\nbug修复\r\n1、window phone下一些系统api是禁用的，源码中去掉；\r\n2、泛型约束是struct的时候，生成代码失败；\r\n3、unity2017 .net 4.6，枚举生成代码报错；\r\n\r\nv2.1.8 2017年6月27日\r\n新增特性\r\n1、Hotfix标签添加几个订制参数：ValueTypeBoxing、IgnoreProperty、IgnoreNotPublic、Inline、IntKey\r\n2、Hotfix代码注入优化，减少text段占用；\r\n3、Hotfix配置支持放Editor目录，可以减少text段占用；\r\n4、支持以指定类型传递object参数；\r\n5、反射调用Obsolete方法在Editor下打印warning；\r\n\r\n变更\r\n\r\nbug修复\r\n1、pinvoke独立设置的In，Out属性可能导致生成代码失败；\r\n2、如果业务在全局名字空间有和xLua名字空间的同名类，生成代码编译失败；\r\n\r\nv2.1.7 2017年5月17日\r\n新增特性\r\n1、支持发布UWP（含HoloLens，Xbox one，Win10 Mobile、Win10 PC）应用；\r\n2、支持对lua源代码ras+sha1签名；\r\n3、如果没安装Tools提示“please install the Tools”；\r\n4、linxu版本的支持；\r\n5、支持bitcode打包；\r\n6、对所有struct新增无参数构造函数；\r\n7、delegate的参数名改为p0到pn，防止hotfix时业务代码变量和生成代码冲突；\r\n8、支持对成员名为C#关键字的情况；\r\n9、新增util.loadpackage，和require类似，通过searcher加载文件，不同的是，它不执行，而且也不会cache到package.loaded；\r\n10、优化模版引擎大文件的生成性能；\r\n11、新增不需要生成代码的注入方式；\r\n12、支持构造函数参数带ref和out修饰符；\r\n13、构造函数也支持黑名单排除；\r\n\r\n变更\r\n1、this[object field]操作符重载；\r\n2、反射的数据转换规则改成和生成代码一致；\r\n3、忽略掉匿名类及匿名函数的注入；\r\n\r\nbug修复\r\n1、规避Unity的bug：List<CustomType>，CustomType是当前执行程序集的类型，这在.Net是不需要指明程序集就可以通过Type.GetType得到，但Unity下不行。\r\n2、解决反射下，可变参数不提供时，传null的问题；\r\n3、继承了另外一个程序集的类型，使用了protected类型会导致注入失败；\r\n4、luajit去掉dlopen和dlsym的调用；\r\n5、解决通用版本的生成代码工具找不到模版的问题；\r\n6、修复通用版本反射导入泛化类型的问题；\r\n7、反射调用含delegate参数的的api，会因为缓存而导致调用LuaEnv.Dispose失败；\r\n8、兼容老版本的C编译器，声明要放开头；\r\n9、生成代码对hotfix的检测算法和注入工具不一致导致的注入失败；\r\n10、注入的nested类型是public，但其的外层类型非public，生成代码报错；\r\n11、析构函数只判断名字可能出现误判；\r\n12、构造函数是非public的，可能会导致找不到适配delegate而注入失败；\r\n13、修正Extension method会在所有子类都生成代码的bug（2.1.6泛化特性引入）；\r\n14、构造函数重载，只有一个能hotfix成功；\r\n15、规避一个可能是il2cpp的bug（unity5.4）：字符串参数默认值是\"\"，ios下在反射的default value也是Reflection.Missing；\r\n16、将一个table传到List<>，取了最后一个参数，而不是那个table的长度；\r\n17、ldarg指令在这种场景下il2cpp转换时会出现异常：1、采用模版注入；2、从4到255间有一个输出参数；改为兼容性更好的ldarg.s；\r\n18、解决配置了System.Delegate到CSCallLua，执行生成代码会编辑器会crash的问题；\r\n19、扩展函数可能和原来的函数同名，反射实现并未考虑到这种情况；\r\n20、通用版本的可变参数delegate调用异常；\r\n21、unity4规避lua53冲突的方式改为返回null更合适，异常方式会导致IsNull无法正常工作；\r\n22、lua_tostring解码失败改为UTF8解码；\r\n\r\nv2.1.6 2017年3月1日\r\n新增特性\r\n1、带约束的泛型支持（by forsakenyang）；\r\n2、非Unity的.net环境支持；\r\n3、代码注入支持小工具方式，该方式不用拷贝cecil库，可以解决拷错cecil库版本或者和Unity，VS插件冲突的问题；\r\n4、Hotfix配置支持字段和属性\r\n5、更方便的Unity协程hotfix\r\n6、在hotfix触发事件；\r\n7、LuaTable添加ForEach方法以及Length属性；\r\n8、cmake生成项目优化：保留源文件目录结构；\r\n9、对已经Dispose的LuaEnv的访问做保护；Dispose时检查callback是否已经都释放，没释放的话报错；\r\n10、支持释放Hotfix回调；\r\n\r\n变更\r\n1、构造函数改为执行原有逻辑后调用lua；\r\n2、this[string field]操作符重载会影响到继承调用，去掉该特性的支持；\r\n3、编辑器下的代码注入改为手动方式；\r\n\r\nbug修复\r\n1、防止定义了同时定义get_xx方法以及xx属性的生成代码的重名。\r\n2、struct注入代码无效；\r\n3、Utils加名字空间，防止和业务冲突；\r\n4、返回定长多维数组的delegate，生成代码可能会冲突；\r\n5、interface，以及编辑器下不生成代码情况下，对可变参数的展开；\r\n6、il2cpp下，如果不生成代码，会报ManifestModule不支持；\r\n7、规避Unity4的bug：访问一个已经被Distroy的UnityEngine.Object，编辑器下会崩溃，这个问题在Unity5，或者luajit版本都不会出现；\r\n8、修改上个版本引入的问题：xlua_setglobal会漏一个值在栈上，这会导致一些32位应用不稳定；\r\n9、当delegate参数只有ref和out的区别的话，报重载冲突；\r\n\r\nv2.1.5 2017年1月13日\r\n\r\n新增特性\r\n1、全平台热补丁；\r\n2、新增线程安全模式，可通过THREAD_SAFT宏打开；\r\n3、新增更简便的配置方式，具体参见XLua\\Doc下《XLua的配置.doc》；\r\n4、多虚拟机实例时的自动Dispose；\r\n5、内存优化：减少匿名闭包到delegate映射的内存占用；减少LuaFunction以及LuaTable内存占用；减少lua table映射C#interface的gc；\r\n6、生成代码速度优化；\r\n7、支持直接在lua侧clone C#结构体；\r\n8、LuaFunction新增无gc调用api；\r\n\r\n变更\r\n1、delegate必须都加[CSharpCallLua]才支持C#到lua的回调（以前参数和返回值都相同的delegate只要其中一个加了就可以）；\r\n2、加回string/number到枚举的自动转换；\r\n\r\nbug修复\r\n1、枚举不生成代码时，第一次使用会产生两个不同的userdata；\r\n2、数组和System.Type的相互引用导致System.Type生成代码无法加载；\r\n3、更安全的异常处理，封装lua_setglobal,lua_getglobal的异常，C#回调保证所有C#异常都catch并转换到成lua error。\r\n\r\n\r\nv2.1.4 2016年11月29日\r\n新增特性\r\n1、加了ReflectionUse会自动生成到link.xml，可以防止il2cpp下因stripping导致的反射不可用；\r\n2、开放生成引擎，可二次开发自己生成插件，生成所需的代码或配置；\r\n3、GetInPath和SetInPath无C# gc优化；\r\n4、一个lua table自动转换为带GCOptimize标签的复杂类型以及该复杂类型的一维数组不使用反射，如果这复杂类型是纯值类型，无c# gc；\r\n\r\n变更\r\n1、基于一致性以及性能的考虑，不支持数字和字符串到枚举的静默转换，须主动调用起类下的__CastFrom；\r\n2、名字空间从LuaInterface改为XLua；\r\n3、LuaTable的几个可能导致gc的api标注为Obsolete；\r\n4、在不指明返回类型的情况下，如果一个number是整数会优先转换成整数；\r\n\r\nbug修复\r\n1、含能隐式转换int，long，decimal的类型传到lua变成decimal；\r\n2、反射的重载判断，如果可变参数的位置上是一个不匹配的参数，也会判断为匹配成功；\r\n3、可变参数+重载的话，可变部分不传会报无效参数；\r\n4、加了LuaCallCSharp的Extension method，在Editor下不生成代码不可用；\r\n\r\nv2.1.3 2016年11月09日\r\n新增特性\r\n1、LuaTable新增Get<TKey, TValue>和Set<TKey, TValue>接口，table操作支持值类型无gc；\r\n2、支持decimal，不丢失精度而且传递到lua无gc；\r\n3、增加LuaEnv.LoadString<T>接口，用于指定返回的delegate类型；\r\n4、例子刷新：新增Helloworld，无GC调用，Lua面向对象，协程例子；\r\n5、enum优化：传递到lua无gc，从int或者string到枚举转换无gc；\r\n6、event的+/-优化：性能提升一倍，而且无gc；\r\n7、生成代码简化；\r\n\r\n变更\r\n1、uint在lua53映射到lua_Integer；\r\n2、StreamingAssets加载改为优先级最低；\r\n\r\nbug修复\r\n1、生成代码下，如果LuaTable或者LuaFunction参数为null会抛异常；\r\n2、lua5.3下，浮点到枚举的静默转换失败；\r\n3、反射下struct类型参数带默认值抛异常；\r\n4、lua53下Length返回浮点；\r\n\r\nv2.1.2 2016年10月08日\r\n新增特性\r\n1、支持lua5.3，进而支持苹果bitcode，原生64位整数，位运算，utf8等特性；\r\n2、CMake编译，更方便加入第三方插件\r\n3、数组性能优化，包括访问性能以及gc\r\n4、C#调用lua函数减少一次lua gc；\r\n5、优化启动时间；\r\n6、减少类型加载的gc；\r\n7、优化ObjectPool的内存占用；\r\n8、优化小字符串传入lua的gc；\r\n9、LuaTable添加Cast接口，用于LuaTable到其它类型的转换，比如interface；\r\n10、LuaFunction添加Cast接口，用于LuaFunction到delegate的转换；\r\n\r\n变更\r\n1、lua内部只有带符号的64整数类型，并增加无符号数库\r\n2、如果不想对Extension Method生成代码，又希望在反射下用，需要添加ReflectionUse；\r\n\r\nbug修复\r\n1、对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除功能的内存泄漏问题；\r\n2、规避某些版本（已知是5.3.3）的Unity的bug导致的内存泄漏问题；\r\n3、LuaTable或者LuaFunction做返回值的delegate生成代码可能报错；\r\n\r\nv2.1.1 2016年08月29日\r\n新增特性\r\n1、支持编辑器下不用生成代码能运行；\r\n2、新增IntPtr的支持\r\n3、增加对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除；\r\n4、在LuaEnv添加对lua_gc一些封装；\r\n\r\nbug修复\r\n1、生成代码传送一个LuaFunction、LuaTable到lua和反射版本不一致，生成代码传送过去是一个C#对象，而反射是Lua函数、table对象，反射的处理更合适；\r\n2、修复同名的静态以及成员方法冲突的问题；\r\n3、修复对interface生成CSharpCallLua代码时，interface含indexer时的报错；\r\n4、修复Editor在运行后会new一个xlua实例的bug；\r\n5、修复通过生成代码调用同时含可变参数和默认值的函数，如果不传参数，将会出错的bug；\r\n6、修复调试时，找不到socket库的bug；\r\n\r\n\r\n变更\r\n1、反射不做重载方法顺序调整，顺序改为固定且生成代码保持一致；\r\n2、i64加上fade_id，参数传递时更安全；\r\n3、重新加入tdr的from_file的支持；\r\n\r\nv2.1.0 2016年08月08日\r\n新增特性\r\n1、满足条件struct传递到lua无gc，struct需要满足什么条件才能被优化呢？\r\na. struct允许嵌套其它struct，但它以及它嵌套的struct只能包含这几种基本类型：byte、sbyte、short、ushort、int、uint、long、ulong、float、double；\r\nb. struct本身以及使用到该struct的地方需要加LuaCallCSharp，并且加了GCOptimize设置；\r\n2、全新实现的反射机制，更容易和生成代码配合使用\r\na. 支持extension methods，Enum.__CastFrom；\r\nb. ios下支持反射使用event；\r\nc. 对类型映射、可变参数调用调整为和生成代码一致；\r\nd. 性能更好，gc更少；\r\n3、生成代码菜单简化，并增加“Generate Minimum”选项；\r\n4、支持生成代码配置文件放Editor目录；\r\n\r\n变更\r\n1、luajit统一升级成2.1.0b2；\r\n2、luasocket库改为按需加载；\r\n3、重载的string，byte[]参数检查允许为nil；\r\n4、子类访问不触发父类加载；\r\n5、struct的ref参数的修改会修改lua测该参数的值；\r\n6、生成代码加载改为静态（原来是反射）；\r\n7、菜单改为更简洁；\r\n8、tdr改为默认不加载；\r\n9、StreamingAssets加载lua改为废弃特性；\r\n\r\nbug修复\r\n1、参数或者返回值是泛型类的数组，或者是二维数组，生成代码报编译错误；\r\n2、抽象类生成代码报编译错误；\r\n3、消除Clear生成代码的warning；\r\n4、profiler、i64库不支持多实例；\r\n\r\nv2.0.5 2016年05月18日\r\n新增特性\r\n1、util.async_to_sync，可以更好的利用lua的协程实现同步编程、异步执行；或者异步等待www等；\r\n2、生成代码的规范度调整，消除一些工具的告警；\r\nbug修复\r\n1、解决在lua gc移除weak table和调用__gc的时间窗内push同一对象，会生成指向同一C#对象的不同userdata的问题；\r\n2、上版本的的lua内存工具并未打包；\r\n3、修正嵌套类型不能生成代码的问题；\r\n\r\nv2.0.4 2016年05月04日\r\n新增特性\r\n1、新增函数调用时长报告功能；\r\n2、新增lua内存泄漏定位工具；\r\n3、lua测加入对64位无符号数的支持；\r\n变更\r\n1、支持多种delegate绑定到一个clousre。调整之前一个clousre只能对应一种delegate；\r\nbug修复\r\n1、tdr处理长度为1的数组的错误（本来解包应该是{[1] = {a = 1}}的，却是{{a=1}}）；\r\n2、tdr数值处理错误（int的-1会解成一个很大的正数）\r\n\r\nv2.0.3 2016年04月13日\r\n新功能\r\n1、添加“Advanced Gen”功能，用户可以自定义生成代码的范围；\r\n2、支持对库生成Static pusher；\r\n变更\r\n1、LuaTable以及InterfaceBirdage改为触发metatable；\r\n2、Extension Methods不自动加到被扩展类，需要加入生成列表；\r\n3、移除特殊ValueType优化；\r\nbug修复\r\n1、Extension Methods为私有时，生成代码语法错误；\r\n2、重载函数含ulong时，生成代码语法错误；\r\n3、反射调用时的默认值处理错误；\r\n4、C#向lua传中文字符的长度处理错误；\r\n\r\nv2.0.2 2016年04月06日\r\n变更\r\n1、库的生成代码配置支持多份，方便项目的模块化；\r\n2、enum的生成代码合并到一个文件里头；\r\n3、优化异常处理；\r\n4、发布包把库和教程、例子分离，更干净；\r\n5、小bug修改；\r\n\r\n升级指引\r\n由于文件有点变动，直接覆盖原有lib会报错，需要：\r\n1、删除原来的XLua目录；\r\n2、解压xlua_v2.0.2.zip到Assets下；\r\n3、重新执行代码生成；\r\n\r\nv2.0.1 2016年03月24日\r\n1、支持C# 的extension methods；\r\n2、lua调试方面的支持；\r\n3、android下require一个不存在的lua文件可能成功的bug；\r\n4、TDR 4 Lua库的更新；\r\n5、多机型的兼容性测试；\r\n\r\nv2.0.0 2016年03月08日\r\n1、性能优化，性能对比报告请看主页；\r\n2、加入官方lua版本的tdr；\r\n3、支持64位整数；\r\n4、修正lua中对C#异常pcall引发的不稳定；\r\n5、易用性的优化；\r\n6、其它一些bug的修改。\r\n\r\n1.0.2 2015年12月09日\r\n1、解决新版本（已知5.2版本）下，streamAssetsPath不允许在构造函数访问导致的bug；\r\n2、新增windows x64版本的支持；\r\n3、对web版本才用到的代码加入条件编译，减少对手机版发布包的影响；\r\n4、生成代码文件名去掉“+”号；\r\n5、删除4.6的生成代码，以免在新版本报引用过时api的错；\r\n\r\nv1.0.1 2015年11月30日\r\n1、支持pcall捕捉C#异常；\r\n2、新增cast方法，支持这种场景：实现类是internal声明，只提供interface；\r\n3、解决interface下如果有event，生成代码编译报错的bug；\r\n4、解决interface下有Obsolete的方法，字段，生成代码编译报错的bug；\r\n5、解决含private的默认geter/setter生成代码编译报错的bug；\r\n6、修正类在全局空间下生成代码不可用的bug；\r\n7、修正bridge代码返回值处理错误。\r\n\r\nv1.0.0 2015年03月30日\r\n第一个版本"
  },
  {
    "path": "Assets/XLua/CHANGELOG.txt.meta",
    "content": "fileFormatVersion: 2\nguid: be3fe4ee249c5274693e7b6f8053e861\ntimeCreated: 1470364015\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Add_Remove_Lua_Lib.md",
    "content": "## What & Why\n\nXLua's currently built-in extension libraries:\n\n* LuaJIT support for 64-bit integers;\n* Positioning tool for function call times and memory leaks;\n* LuaSocket library for supporting ZeroBraneStudio;\n* tdr 4 lua;\n\nWith the increasing extensiveness and intensiveness of project use, the current extension libraries have been unable to meet the project team needs. Since various projects require very different extension libraries, and since mobile phone platforms are sensitive to the size of the installation package, xLua is unable to meet these needs through pre-integration. That is why we are offering this tutorial.\n\nIn this tutorial, we will use lua-rapidjson as an example to explain step by step how to add C/C++ extensions to xLua. Once you know how to add them, you will also know how to delete them naturally. The project team can delete those pre-integrated extensions if they are not used any more.\n\n## How it is done\n\nThere are three steps:\n\n1. Modify the build file and project settings. Compile the extensions you want to integrate into the XLua Plugin directory.\n2. Call the C# APIs on xLua so that the extensions can be loaded as needed (when required in the Lua code).\n3. (Optional) If you need to use 64-bit integers in your extensions, you can use xLua's 64-bit extension library to work with C#.\n\n### First, add extensions & compile.\n\nPreparations\n\n1. Extract the xLua’s C source code package to the same level directory as the Assets of your Unity project.\n\n   Download the lua-rapidjson code and place it anywhere you like. In this tutorial, we place the rapidjson header file in the $UnityProj\\build\\lua-rapidjson\\include directory, and place the extended source code rapidjson.cpp in the $UnityProj\\build\\lua-rapidjson\\source directory (Note: $UnityProj refers to your project directory).\n\n2. Add extensions to CMakeLists.txt\n\n   xLua’s platform Plugins are compiled using CMake. The advantage of this is that the compilations of all platforms are written in a makefile, and most compilation processing logic is cross-platform.\n\n   XLua's CMakeLists.txt provides extension points (all lists) for third-party extensions:\n   1. THIRDPART_INC: Third-party extension header search path.\n   2. THIRDPART_SRC: Third-party extended source code.\n   3. THIRDPART_LIB: The library on which third-party extensions rely.\n\n   The following is added with RapidJSON:\n\n       #begin lua-rapidjson\n       set (RAPIDJSON_SRC lua-rapidjson/source/rapidjson.cpp)\n       set_property(\n       SOURCE ${RAPIDJSON_SRC}\n       APPEND\n       PROPERTY COMPILE_DEFINITIONS\n       LUA_LIB\n       )\n       list(APPEND THIRDPART_INC  lua-rapidjson/include)\n       set (THIRDPART_SRC ${THIRDPART_SRC} ${RAPIDJSON_SRC})\n       #end lua-rapidjson\n\n   See the attachment for the complete code.\n\n3. Compile platforms\n\n   All compiled scripts are named with this format: make_platform_lua version.extension name.\n\n   For example, the name of the Windows 64-bit Lua 5.3 version is make_win64_lua53.bat, and the name of the Android LuaJIT version is make_android_luajit.sh. you can execute the corresponding script to compile the target version.\n\n   The compiled scripts are automatically copied to the plugin_lua53 or plugin_luajit directory. The former is for Lua 5.3 and the latter for LuaJIT.\n\n   The supporting Android script is used on Linux. The NDK path at the beginning of the script must be modified accordingly.\n\n### Second, C# side integration:\n\nEach C extension library on Lua will provide a function, luaopen_xxx, where xxx is the name of the dynamic library. For example, the function for the Lua-RapidJSON library is luaopen_rapidjson. Such functions are automatically called by the Lua virtual machine when loading the dynamic library. In the mobile platform, we cannot load the dynamic library due to iOS restrictions. They are compiled directly into the process instead.\n\nFor this purpose, xLua provides an API to replace this feature (LuaEnv's member methods):\n\n    public void AddBuildin(string name, LuaCSFunction initer)\n\nParameters:\n\n    Name: name of the buildin module, a parameter entered during require; \n    initer: the initialization function; Its prototype is public delegate int lua_CSFunction(IntPtr L); This must be a static function and be modified with the property MonoPInvokeCallbackProperty; This API will check these two conditions.\n\nWe use calling luaopen_rapidjson to show how to use it.\n\nExtend the LuaDLL.Lua type, export luaopen_rapidjson to C# via pinvoke, and then write a static function that satisfies the definition of lua_CSFunction. You can write initialization work in it, such as calling luaopen_rapidjson. Here is the complete code:\n\n    namespace LuaDLL\n    {\n    public partial class Lua\n    {\n    [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\n    public static extern int luaopen_rapidjson(System.IntPtr L);\n    \n    [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]\n    public static int LoadRapidJson(System.IntPtr L)\n    {\n    return luaopen_rapidjson(L);\n    }\n    }\n    }\n\nThen call AddBuildin:\n\n    luaenv.AddBuildin(\"rapidjson\", LuaDLL.Lua.LoadRapidJson);\n\nAfter this, it should work properly. Try the extension in the Lua code:\n\n    local rapidjson = require('rapidjson')\n    local t = rapidjson.decode('{\"a\":123}')\n    print(t.a)\n    t.a = 456\n    local s = rapidjson.encode(t)\n    print('json', s)\n\n### Third, 64-bit transformation\n\nInclude the i64lib.h file in a file that requires a 64-bit transformation. \nThe header file include these APIs:\n\n    //Place an int64 on stack/uint64\n    void lua_pushint64(lua_State* L, int64_t n);\n    void lua_pushuint64(lua_State* L, uint64_t n);\n    //Judge whether int64 is at the pos position on stack/uint64\n    int lua_isint64(lua_State* L, int pos);\n    int lua_isuint64(lua_State* L, int pos);\n    //Get an int64 from the pos position on stack/uint64\n    int64_t lua_toint64(lua_State* L, int pos);\n    uint64_t lua_touint64(lua_State* L, int pos);\n\nThe usage of these APIs varies depending on the actual situation. See the attached file (rapidjson.cpp file).\n\nCompile project related modifications\n\n"
  },
  {
    "path": "Assets/XLua/Doc/Add_Remove_Lua_Lib.md.meta",
    "content": "fileFormatVersion: 2\nguid: 0ae08314c9c889249bbd484254109060\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Configure_EN.md",
    "content": "# XLua configuration\r\n\r\nAll xLua configurations support three methods: tagging, static lists, and dynamic lists.\r\n\r\nThere are two requirements and two recommended items for configuration:\r\n\r\n* List mode must use static fields/properties.\r\n* List mode must be placed in a static type.\r\n* Using tagging is not recommended.\r\n* Placing the list mode configuration in the Editor directory is recommended.\r\n\r\n**Tagging**\r\n\r\nxLua uses a whitelist to indicate which code is to be generated, and the whitelist is configured via attributes. For example, if you want to call a C# type from Lua or you want to generate the adaptation code, you can add a LuaCallCSharp tag for this type:\r\n\r\n~~~csharp\r\n[LuaCallCSharp]\r\npublicclassA\r\n{\r\n\r\n}\r\n~~~\r\n\r\nThis mode is convenient, but it will increase the code on the il2cpp and therefore is not recommended.\r\n\r\n**Static list**\r\n\r\nSometimes we cannot directly tag a type, such as a system API, a library without source code, or an instantiated generic type. In this case, you can declare a static field in a static type. This field can be any type except for BlackList and AdditionalProperties, as long as IEnumerable&lt;Type&gt; is implemented (these two exceptions will be specifically described later). Then add a tag to this field:\r\n\r\n~~~csharp\r\n[LuaCallCSharp]\r\npublic static List<Type> mymodule_lua_call_cs_list = new List<Type>()\r\n{\r\n    typeof(GameObject),\r\n    typeof(Dictionary<string, int>),\r\n};\r\n~~~\r\n\r\nThis field needs to be placed in a **static type** and placing it in the **Editor directory** is recommended.\r\n\r\n**Dynamic list**\r\n\r\nDeclare a static property and tag it accordingly.\r\n\r\n~~~csharp\r\n[Hotfix]\r\npublic static List<Type> by_property\r\n{\r\n    get\r\n    {\r\n        return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\r\n                where type.Namespace == \"XXXX\"\r\n                select type).ToList();\r\n    }\r\n}\r\n~~~\r\n\r\nGetter is code. You can use it to implement a lot of results, such as configuration by namespace, configuration by assembly, and so on.\r\n\r\nThis property needs to be placed in a **static type** and placing it in the **Editor directory** is recommended.\r\n\r\n### XLua.LuaCallCSharp\r\n\r\nWhen adding this configuration for a C# type, xLua will generate the adapter code for this type (including constructing an instance for the type, and accessing its member properties & methods and static properties & methods). Otherwise, it will try to gain access using the reflection mode with lower performance.\r\n\r\nAdding this configuration to the Extension Methods of a type will also generate the adaptation code and append it to the member methods of the extended type.\r\n\r\nXLua will only generate the type loaded with this configuration. It will not automatically generate the adaptation code of its parent type. When accessing the parent type method of the child type object, if the parent type has the LuaCallCSharp configuration, the parent type's adaptation code will be executed. Otherwise it will try to gain access using the reflection mode.\r\n\r\nThe reflection mode access not only has poor performance, but also may cause failed access on the il2cpp due to code stripping. This problem can be avoided through the ReflectionUse tag, which is described below.\r\n\r\n### XLua.ReflectionUse\r\n\r\nWhen adding this configuration to a C# type, xLua generates a link.xml to block code stripping on the il2cpp.\r\n\r\nFor extension methods, you must add LuaCallCSharp or ReflectionUse to make them accessible.\r\n\r\nIt is recommended that all types to be accessed in Lua have the LuaCallCSharp or ReflectionUse tag, to insure their proper operation on all platforms.\r\n\r\n### XLua.DoNotGen\r\n\r\nThis indicates that some of the functions, fields, and properties in a type do not generate code and are accessed through the reflection mode.\r\n\r\nOnly the fields or properties in the standard Dictionary<Type, List<string>> can be used. The key indicates the effective type. Value is a list. The name of the functions, fields, and properties with no code generated are configured.\r\n\r\nThe differences from ReflectionUse are: 1. ReflectionUse specifies the entire type; 2. Upon the first access to a function (field, property), ReflectionUse will wrap the entire type, while DoNotGen will only wrap the function (field, property). In other words, DoNotGen is lazier.\r\n\r\nThe differences from BlackList are: 1. BlackList cannot be used when it is configured. 2. BlackList can specify an overloaded function, while DoNotGen cannot.\r\n\r\n### XLua.CSharpCallLua\r\n\r\nThis allows you to adapt a Lua function to a C# delegate (one scenario is various callbacks at the C# side: UI events, delegate parameters, such as List&lt;T&gt;:ForEach; another scenario is to use the Get function of LuaTable to indicate that a Lua function is bound to a delegate), or to adapt a Lua table to a C# interface. The delegate or interface needs this configuration.\r\n\r\n### XLua.GCOptimize\r\n\r\nA C# pure value type (Note: It refers to a struct that contains only the value type, and it can nest other structs that contain only the value type) or a C# enumerated value has this configuration. xLua generates gc-optimized code for this type. The result is that the value type is passed between Lua and C# with no (C#)gc alloc generated, and that no gc is generated during array access to this type. For various GC-free scenarios, refer to the 05\\_NoGc example.\r\n\r\nAny type except enumeration (including the complex types that contain parameterless constructors) will generate Lua tables for that type, as well as the conversion code of a one-dimensional array with modified type. This will optimize the performance of this conversion, including fewer gc allocs.\r\n\r\n### XLua.AdditionalProperties\r\n\r\nThis is GCOptimize's extended configuration. Sometimes, some structs want to make the field private and access the field through the property. In this case, you need to use this configuration (by default, GCOptimize only packetizes/depacketizes the public field).\r\n\r\nThe tagging mode is relatively simple and the configuration mode is complicated. The requirements are that Dictionary&lt;Type, List&lt;string&gt;&gt; type, and the Key of the Dictionary are effective types; and value is the list of property names. See xLua's configuration of several UnityEngine value types and the SysGCOptimize type.\r\n\r\n### XLua.BlackList\r\n\r\nIf you do not want to generate an adaption code for a member of a type, you can implement it with this configuration.\r\n\r\nThe tagging method is relatively simple, and the corresponding member can be added.\r\n\r\nConsidering that it may be necessary to add one of the overloaded functions to the blacklist, the configuration is more complicated. The type is List&lt;List&lt;string&gt;&gt;. For each member, the first-level list has only one entry and the second-level list is a string list. The first string is the full path name of the type, the second string is the member name. If the member is a method, you also need to list the full path of the type of its parameters starting from the third string.\r\n\r\nFor example, the following adds a property of GameObject and a method of FileInfo to the blacklist:\r\n\r\n~~~csharp\r\n[BlackList]\r\npublic static List<List<string>> BlackList = new List<List<string>>()  {\r\n    new List<string>(){\"UnityEngine.GameObject\", \"networkView\"},\r\n    //new List<string>(){ typeof(UnityEngine.GameObject).FullName, \"networkView\"},\r\n    new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n    //new List<string>(){ typeof(System.IO.FileInfo).FullName, \"GetAccessControl\",typeof(System.Security.AccessControl.AccessControlSections).FullName },\r\n};\r\n~~~\r\n\r\n### The following is the generator configuration, which must be placed in the Editor directory.\r\n\r\n### CSObjectWrapEditor.GenPath\r\n\r\nConfigures the path of the generated code, with the type being a string. By default, it is plated in &quot;Assets/XLua/Gen/&quot;.\r\n\r\n### CSObjectWrapEditor.GenCodeMenu\r\n\r\nThis configuration is used for secondary development of the build engine. When adding this tag to a parameterless function, it will trigger calling the function when executing the &quot;XLua/Generate Code&quot; menu.\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Doc/Configure_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: 198070d8475ff3043b6c72a906feebee\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Custom_Generate_EN.md",
    "content": "## Secondary development of the build engine\r\n\r\nxLua's build engine supports secondary development, and you can use it to generate some text files (for example, code and configuration files). The xLua's link.xml file is generated by the build engine plugin. Other application scenarios (such as generating a Lua IDE auto configuration file) can also be accomplished using this feature.\r\n\r\n## Overview\r\n\r\nThe plugin needs to provide two things: 1. a template for generated files, 2. a callback function that accepts the user configuration and returns the data that needs to be injected into the template and the output stream of the files.\r\n\r\n## Template syntax\r\n\r\nThe template syntax is simple, with only three elements:\r\n\r\n* eval: The syntax is <%=exp%>. Exp is an arbitrary expression that will calculate and output the value of exp as a string.\r\n* Code: The syntax is <% if true then end%>. The blue part is any Lua code that will be executed.\r\n* Literal: This contains the parts other than eval and code. Literal means output as it is.\r\n\r\nExample:\r\n\r\n~~~xml\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\n<linker>\r\n<%ForEachCsList(assembly_infos, function(assembly_info)%>\r\n\t<assembly fullname=\"<%=assembly_info.FullName%>\">\r\n\t    <%ForEachCsList(assembly_info.Types, function(type)\r\n\t\t%><type fullname=\"<%=type:ToString()%>\" preserve=\"all\"/>\r\n\t\t<%end)%>\r\n\t</assembly>\r\n<%end)%>\r\n</linker>\r\n~~~\r\n\r\nTemplateCommon has some predefined functions that can be used (for example ForEachCsList). You can search in TemplateCommon.lua.txt of the project to see which functions are available. For ordinary Lua, you can write one.\r\n\r\n## API\r\n\r\n~~~csharp\r\npublic static void CSObjectWrapEditor.Generator.CustomGen(string template_src, GetTasks get_tasks)\r\n~~~\r\n\r\n* template_src: template source code\r\n* get_tasks: This is a callback function. The type is GetTasks. This function is used to accept the user configuration and return the data that needs to be injected into the template and the output stream of the files.\r\n\r\n~~~csharp\r\npublic delegate IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg);\r\n~~~\r\n\r\n* lua_env: This is a LuaEnv object. Because the returned template data needs to be placed in LuaTable, LuaEnv.NewTable is required.\r\n* user_cfg: user configuration\r\n* return: Among the returned values, CustomGenTask represents a generated file, and IEnumerable type indicates that the same template can generate multiple files.\r\n\r\n~~~csharp\r\npublic struct UserConfig\r\n{\r\n    public IEnumerable<Type> LuaCallCSharp;\r\n    public IEnumerable<Type> CSharpCallLua;\r\n    public IEnumerable<Type> ReflectionUse;\r\n}\r\n~~~\r\n\r\n~~~csharp\r\npublic struct CustomGenTask\r\n{\r\n    public LuaTable Data;\r\n    public TextWriter Output;\r\n}\r\n~~~\r\n\r\nExample:\r\n\r\n~~~csharp\r\npublic static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg)\r\n{\r\n    LuaTable data = lua_env.NewTable();\r\n    var assembly_infos = (from type in user_cfg.ReflectionUse\r\n                          group type by type.Assembly.GetName().Name into assembly_info\r\n                          select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList();\r\n    data.Set(\"assembly_infos\", assembly_infos);\r\n\r\n    yield return new CustomGenTask\r\n    {\r\n        Data = data,\r\n        Output = new StreamWriter(GeneratorConfig.common_path + \"/link.xml\",\r\n        false, Encoding.UTF8)\r\n    };\r\n}\r\n~~~\r\n\r\n* Only one file is generated here, so only one CustomGenTask is returned.\r\n* data is the data to be used in the template. There is an assembly_infos field included. See the template section for how to use this field.\r\n\r\n## Tag\r\n\r\nGenerally speaking, you can use MenuItem to create a menu to trigger a custom generate operation. However, sometimes you may want the generate operation to be triggered directly by the xLua \"Generate Code\" menu. In this situation, you will need to use CSObjectWrapEditor.GenCodeMenu\r\n\r\nExample:\r\n\r\n~~~csharp\r\n[GenCodeMenu]//加到Generate Code菜单里头\r\npublic static void GenLinkXml()\r\n{\r\n    Generator.CustomGen(ScriptableObject.CreateInstance<LinkXmlGen>().Template.text, GetTasks);\r\n}\r\n~~~\r\n\r\nPS: All the code related to the content above is in the XLua\\Src\\Editor\\LinkXmlGen directory, which is also the implementation of the link.xml generation function that was explained at the beginning.\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Doc/Custom_Generate_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: c0765c3c416e8f746bf142b05be65ea7\ntimeCreated: 1529661500\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Faq_EN.md",
    "content": "# FAQs\r\n\r\n## How to use xLua distribution package?\r\n\r\nxLua is currently released as a zip package and can be extracted to the project directory.\r\n\r\n## Can xLua be placed in another directory?\r\n\r\nYes, but the generated code directory needs to be configured (by default, it is in the Assets\\XLua\\Gen directory). For details, see the GenPath configuration in XLua Configuration.doc.\r\n\r\nThe important thing to note about changing directories is that the generated code and xLua core code must be in the same assembly. If you want to use the hotfix function, the xLua core code must be in the Assembly-CSharp assembly.\r\n\r\n## Does Lua source code only use the txt extension?\r\n\r\nIt can use any extension.\r\n\r\nIf you want to add TextAsset to an installation package (for example, to the Resources directory), Unity does not identify the Lua extension. This is Unity's rule.\r\n\r\nIf you do not add it to the installation package, there is no limit to the extension. For example, in case that you download it to a directory (this is also practicable in hotfix mode), and then read this directory with CustomLoader or by setting package.path.\r\n\r\nWhy does the Lua source code (including examples) of xLua use the txt extension? Because xLua itself is a library, it doesn't provide download functionality, and it's inconvenience to download code from somewhere else during runtime. TextAsset is a simpler solution.\r\n\r\n## The editor (or non-il2cpp for Android) runs normally, but when iOS calls a function, \"attempt to call a nil value\" is reported.\r\n\r\nBy default, il2cpp will strip code, such as engine code, C# system APIs, and third-party dlls. In simple terms, functions in these places will not be compiled into your final release package if your C# code does not access them.\r\n\r\nSolution: Add a reference (for example, configuring it to LuaCallCSharp, or adding access to that function to your C# code), or use the link.xml configuration (When ReflectionUse is configured, xLua will automatically configure it for you in link.xml) to tell il2cpp not to strip a certain type of code.\r\n\r\n## Where can I find Plugins source code and how can I use it?\r\n\r\nPlugins source code is in the xLua_Project_Root/build.\r\n\r\nThe source code compilation relies on CMake. After installing CMake, execute make_xxxx_yyyy.zz. xxxx stands for the platform, such as iOS or Android; yyyy is the virtual machine to be integrated, including Lua 5.3 and LuaJIT. The file extension is zz. The extension is bat for Windows and sh for other platforms.\r\n\r\nWindows compilation relies on Visual Studio 2015.\r\n\r\nAndroid compilation uses Linux, relies on NDK, and needs to point ANDROID_NDK in the script to the installation directory of NDK.\r\n\r\niOS and OS X need to be compiled on a Mac.\r\n\r\n## How do I solve the \"xlua.access, no field __Hitfix0_Update\" error?\r\n\r\nFollow the [Hotfix Operation Guide](hotfix.md).\r\n\r\n## How do I solve the \"please install the Tools\" error?\r\n\r\nDo not install Tools to the same level directory as Assets. You can find Tools in the installation package, or in the master directory.\r\n\r\n## How do I solve the \"This delegate/interface must add to CSharpCallLua: XXX\" error?\r\n\r\nIn the editor, xLua can run even without generating code. This prompt appears either because CSharpCallLua was not to the type, or because the code was generated before adding, but no generation was executed again.\r\n\r\nSolution: After confirming that CSharpCallLua has been added to XXX (type name), clear the code and run it again.\r\n\r\nIf there is no problem with the editor, the error will be reported to the mobile phone. This means that you did not generate the code (execute “XLua/Generate Code”) before release.\r\n\r\n## What do I do if executing \"XLua/Hotfix Inject In Editor\" menu on Unity 5.5 or later versions produces the following prompt: \"WARNING: The runtime version supported by this application is unavailable.\"\r\n\r\nThis is because the injection tool was compiled with .NET 3.5. The Unity 5.5 warning means that MonoBleedingEdge's mono environment does not support .NET 3.5. However, due to backward compatibility, no real problems related to this warning have been found so far.\r\n\r\nYou may find that defining INJECT_WITHOUT_TOOL in nested mode will not produce this warning. However, the problem is that this mode is used for debugging and is not recommended because it may cause some library conflicts.\r\n\r\n## How do I trigger an event in hotfix?\r\n\r\nFirstly, enable private member access using xlua.private_accessible.\r\n\r\nThen, call delegates using the \"&event name\" field of the object, for example self\\['&MyEvent'\\](), where MyEvent is the event name.\r\n\r\n## How do I patch Unity Coroutine's implementation function?\r\n\r\nSee the corresponding section of the [Hotfix Operation Guide](hotfix.md).\r\n\r\n## Is NGUI (or UGUI/DOTween, etc...) supported?\r\n\r\nYes. The most important feature of xLua is that what you write with C# can be originally replaced with Lua, and the plugins available on C# will remain available.\r\n\r\n## If debugging is needed, how do I deal with the filepath parameter of CustomLoader?\r\n\r\nWhen Lua calls require 'a.b', CustomLoader will be called and the string \"a.b\" will be injected. You need to understand this string, load the Lua file (from file/memory/network, etc...) and return two things. The first thing is a path that the debugger can understand, for example a/b.lua, which is returned by setting the filepath parameter of the ref type. The second thing is the bytes[] of the source code in UTF8 format, which is returned with the returned value.\r\n\r\n## What is generated code?\r\n\r\nXLua supports one kind of Lua-C# interaction technique, which implements interaction by generating adaptation code between the two. It has better performance and is therefore recommended.\r\n\r\nAnother interaction technique is reflection, which has less impact on the installation package and can be used in scenarios which have lower performance requirements and has installation package size limit.\r\n\r\n## How do I solve errors with the code generated before and after changing the interface?\r\n\r\nClear the generated code (execute the \"Clear Generated Code\" menu, which may disappear after restart. Then you can manually delete the entire generated code directory), and then regenerate the code when the compilation is completed.\r\n\r\n## When should the code be generated?\r\n\r\nDuring the development period, it is not recommended that code be generated, to avoid many compilation failures due to inconsistency and waiting time during compilation of the generated code.\r\n\r\nThe generated code must be executed before the build version for the mobile phone. Automatic execution is recommended.\r\n\r\nOptimize performance. The generated code must be executed before the performance test because there are significant differences between the generated code and the code not generated.\r\n\r\n## Do all C# APIs in CS namespaces occupy high memory?\r\n\r\nDue to the use of LazyLoad, their existences are just a virtual concepts. For example, for UnityEngine.GameObject, its methods, and properties are loaded only when accessing the first CS.UnityEngine.GameObject or transferring the first instance to Lua.\r\n\r\n## In what scenarios are LuaCallSharp and CSharpCallLua used?\r\n\r\nIt depends on the caller and the callee. For example, if you want to call C#'s GameObject, find a function in Lua, or call GameObject's instance methods or properties, the GameObject type needs to be added to LuaCallSharp. If you want to add a Lua function to the UI callback (in this case, C# is the caller and the Lua function is the callee), the delegate declared by the callback needs to be added to CSharpCallLua.\r\n\r\nSometimes, it is confusing, like when calling List<int>, for example. Find(Predicate<int> match) and List<int> will of course be added to LuaCallSharp. However, Predicate<int> needs to be added to CSharpCallLua, because the caller of match is C#, and a Lua function is called.\r\n\r\nA more unthinkable way: When you see, \"This delegate/interface must add to CSharpCallLua: XXX\", just add XXX to CSharpCallLua.\r\n\r\n## Will gc alloc appear in value type transfer?\r\n\r\nIf you are using the delegate to call a Lua function, if the LuaTable and LuaFunction that you use have no gc interface, or if there is an array, the following value types have no gc:\r\n\r\n1. All the basic value types (all integers, all floating-point numbers, decimals)\r\n\r\n2. All enumerated types\r\n\r\n3. The field contains only the struct of value type, and it can nest other struct. \r\n\r\nFor 2 and 3, pleases add those types to GCOptimize.\r\n\r\n## Is reflection available on iOS?\r\n\r\nThere are two restrictions on iOS: 1. no JIT; 2. code stripping;\r\n\r\nWhen C# calls Lua via delegates or interfaces, using reflection emit instead of the generated code relies on JIT, so this is currently only available in the editor mode.\r\n\r\nIf Lua calls C#, it will be mainly affected by code stripping. In this case, you can configure ReflectionUse (but not LuaCallSharp), and execute \"Generate Code\". No package code except link.xml will be generated for the type this time. Set this type to 'not to be stripped'.\r\n\r\nIn short, only CSharpCallLua is necessary (a little code of this type is generated), and reflection can be used in LuaCallSharp generation.\r\n\r\n## Is calling generic methods supported?\r\n\r\nThis is partially supported. See [Example 9 for the degree of support.](../Examples/09_GenericMethod/)\r\n\r\nThere are other ways to call generic methods. If it is a static method, you can write a package to instantiate the generic method.\r\n\r\nIf it is a member method, xLua supports the extension method. You can add an extension method to instantiate a generic method. This extension method is just like an ordinary member method.\r\n\r\n```csharp\r\n// C#\r\npublic static Button GetButton(this GameObject go)\r\n{\r\n    return go.GetComponent<Button>();\r\n}\r\n```\r\n\r\n```lua\r\n-- lua\r\nlocal go = CS.UnityEngine.GameObject.Find(\"button\")\r\ngo:GetButton().onClick:AddListener(function()\r\n    print('onClick')\r\nend)\r\n```\r\n\r\n## Can Lua call C# overloaded functions?\r\n\r\nYes, but this is not as well supported as on C#. For example, in the overloaded methods void Foo(int a) and void Foo(short a), because int and short both correspond to the number on Lua, it is impossible to use the parameters to judge which overloaded method is called. In this situation, you can use the extension method to give an alias to one of them.\r\n\r\n## What should I do if \"A method/property/field is not defined\" is reported when the code is generated during packaging, but it runs normally on the editor?\r\n\r\nThis is often because the method/property/field is extended in the conditional compilation, which is only available in UNITY_EDITOR. This can be solved by adding this method/property/field to the blacklist, and then re-executing code generation when the compilation is completed. \r\n\r\n## Why is this[string field] or this[object field] operator overload inaccessible in Lua? (For example, in Dictionary\\<string, xxx\\>, I cannot retrieve values in Dictionary\\<object, xxx\\> using dic['abc'] or dic.abc on Lua)\r\n\r\nBecause: 1. This feature will cause the base type-defined methods, properties, and fields to be inaccessible. (For example, the Animation cannot access the GetComponent method.); 2. The data cannot be retrieved if the key is the name of a method, property, or field of the current type. For example, in the Dictionary type, dic['TryGetValue'] returns a function that points to the TryGetValue method of the Dictionary.\r\n\r\nIf your version is newer than 2.1.11, you can use get_Item to get the value and set_Item to set the value. It should be noted that only this[string field] or this[object field] operator has these two alternative APIs. The keys of other types do not.\r\n\r\n~~~lua\r\ndic:set_Item('a', 1)\r\ndic:set_Item('b', 2)\r\nprint(dic:get_Item('a'))\r\nprint(dic:get_Item('b'))\r\n~~~\r\n\r\nIf your version is 2.1.11 or earlier, it is recommended that you directly use the equivalent method of the operator, such as the TryGetValue of the Dictionary. If this method is not available, you can package a method through the Extension method on C# and then use it.\r\n\r\n## Why are some Unity objects null in C# but not nil in Lua, for example, a GameObject that has been destroyed?\r\n\r\nIn fact, the C# object is not null, but the UnityEngine.Object overloads the == operator. When an object is destroyed, or in the case of failed initialization, true is returned for obj == null, but this C# object is not null. You can check this using System.Object.ReferenceEquals(null, obj).\r\n\r\nIn this case, you can write an extension method for UnityEngine.Object.\r\n\r\n~~~csharp\r\n[LuaCallCSharp]\r\n[ReflectionUse]\r\npublic static class UnityEngineObjectExtention\r\n{\r\n    public static bool IsNull(this UnityEngine.Object o) // 或者名字叫IsDestroyed等等\r\n    {\r\n        return o == null;\r\n    }\r\n}\r\n~~~\r\n\r\nThen, in Lua, use IsNull for all UnityEngine.Object instances.\r\n\r\n~~~lua\r\nprint(go:GetComponent('Animator'):IsNull())\r\n~~~\r\n\r\n## How do I construct a generic instance?\r\n\r\nIf the types involved are all in the mscorlib and Assembly-CSharp assembly, the construction of the generic instance is the same as that of ordinary types. Both are CS.namespace.typename(). The typename expression is special, and the typename expression of the generic instance contains the identifier illegal symbol. The last part should be replaced with [\"typename\"]. Use List<string> as an example.\r\n\r\n~~~lua\r\nlocal lst = CS.System.Collections.Generic[\"List`1[System.String]\"]()\r\n~~~\r\n\r\nIf the typename of a generic instance is undefined, typeof(undefined type).ToString() can be printed on C#.\r\n\r\nIf the types involved are not in the mscorlib and Assembly-CSharp assembly, you can use the C# reflection:\r\n\r\n~~~lua\r\nlocal dic = CS.System.Activator.CreateInstance(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UnityEngine.Vector3, UnityEngine]],mscorlib'))\r\ndic:Add('a', CS.UnityEngine.Vector3(1, 2, 3))\r\nprint(dic:TryGetValue('a'))\r\n~~~\r\n\r\nIf your xLua version is larger than v2.1.12, you can\r\n\r\n~~~lua\r\n-- local List_String = CS.System.Collections.Generic['List<>'](CS.System.String) -- another way\r\nlocal List_String = CS.System.Collections.Generic.List(CS.System.String)\r\nlocal lst = List_String()\r\n\r\nlocal Dictionary_String_Vector3 = CS.System.Collections.Generic.Dictionary(CS.System.String, CS.UnityEngine.Vector3)\r\nlocal dic = Dictionary_String_Vector3()\r\ndic:Add('a', CS.UnityEngine.Vector3(1, 2, 3))\r\nprint(dic:TryGetValue('a'))\r\n~~~\r\n\r\n## Why is the \"try to dispose a LuaEnv with C# callback!\" error reported when LuaEnv.Dispose is called?\r\n\r\nThis is because C# still has a delegate pointing to a function in the Lua virtual machine. Check this to prevent calling these invalid delegates after the virtual machine is released (They are invalid because the virtual machine on which the Lua function is referenced has been released.) from causing exceptions or even crashes.\r\n\r\nHow do I solve this? Release these delegates, that is the delegates nonexistent on C# that will not be referenced:\r\n\r\nIf you get and save the object member through LuaTable.Get on C#, then assign null to the member.\r\n\r\nIf you register the Lua function in Lua to some event callbacks, then deregister these callbacks.\r\n\r\nIf you perform an injection to C# via xlua.hotfix(class, method, func), then delete it via xlua.hotfix(type, method, nil).\r\n\r\nNote that this should be done before Dispose.\r\n\r\n## Crashes occur when calling LuaEnv.Dispose.\r\n\r\nIt is very likely that this Dispose operation is executed by Lua, which is equivalent to releasing the Lua virtual machine during the execution by Lua. Thus, this can only be executed by C#.\r\n\r\n## When the C# parameter (or field) type is object, the integer is transferred as the long type by default. How do I specify other types like int, for example?\r\n\r\nSee [Example 11](../Examples/11_RawObject/RawObjectTest.cs)\r\n\r\n## How do I execute the original C# logic before executing hotfix?\r\n\r\nWith util.hotfix_ex, you can call the original C# logic.\r\n\r\n~~~lua\r\nlocal util = require 'xlua.util'\r\nutil.hotfix_ex(CS.HotfixTest, 'Add', function(self, a, b)\r\n   local org_sum = self:Add(a, b)\r\n   print('org_sum', org_sum)\r\n   return a + b\r\nend)\r\n~~~\r\n\r\n## How do I assign a C# function to a delegate field?\r\n\r\nIn 2.1.8 or earlier versions, you can just use the C# function as a Lua function. The performance is lower, because the delegate calls Lua through the Birdage adaptation code first, and then Lua calls C#.\r\n\r\nIn 2.1.9, the createdelegate function is added in xlua.util. \r\n\r\nFor example, see the following C# code:\r\n\r\n~~~csharp\r\npublic class TestClass\r\n{\r\n    public void Foo(int a)\r\n    { \r\n    }\r\n\t\r\n    public static void SFoo(int a)\r\n    {\r\n    }\r\n｝\r\npublic delegate void TestDelegate(int a);\r\n~~~\r\n\r\nYou can specify using the Foo function to create a TestDelegate instance.\r\n\r\n~~~lua\r\nlocal util = require 'xlua.util'\r\n\r\nlocal d1 = util.createdelegate(CS.TestDelegate, obj, CS.TestClass, 'Foo', {typeof(CS.System.Int32)}) --由于Foo是实例方法，所以参数2需要传TestClass实例\r\nlocal d2 = util.createdelegate(CS.TestDelegate, nil, CS.TestClass, 'SFoo', {typeof(CS.System.Int32)})\r\n\r\nobj_has_TestDelegate.field = d1 + d2 --到时调用field的时候将会触发Foo和SFoo，这不会经过Lua适配\r\n~~~\r\n\r\n## Why is Lua sometimes interrupted without an error message?\r\n\r\nGenerally, this happens in two situations:\r\n\r\n1. You used a coroutine instead of the standard Lua to run the code that had an error. Coroutine errors are expressed via the returned resume value. Please refer to the relevant Lua official documents for more information. If you want to throw an exception directly for the coroutine error, you can add an assert in your resume call.\r\n\r\nChange the following code:\r\n\r\n~~~lua\r\ncoroutine.resume(co, ...)\r\n~~~\r\n\r\nto:\r\n\r\n~~~lua\r\nassert(coroutine.resume(co, ...))\r\n~~~\r\n\r\n2. Print doesn't work after upper layer catch.\r\n\r\nFor example, in some SDKs, the exception disappears after try-catch during callback.\r\n\r\n## How do I deal with overload ambiguity?\r\n\r\nFor example, due to ignoring the out parameter, one of the overloads of Physics.Raycast cannot be called. (For example, short and int cannot be distinguished.)\r\n\r\nFirst, it’s rare that the out parameter causes overload ambiguity. At present, we have only received such feedback about Physics.Raycast (as of Sept. 22, 2017). We recommended that you solve this via self-packaging (This is also applicable to short and int): Directly package static functions with other names. For a member method, package it with the Extension method.\r\n\r\nIn the hotfix scenario, we do not package it in advance. How do I call the specified overload?\r\n\r\nUse xlua.tofunction and reflection. xlua.tofunction inputs a MethodBase object and returns a Lua function. For example, see the following C# code:\r\n\r\n~~~csharp\r\nclass TestOverload\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        Debug.Log(\"int version\");\r\n        return a + b;\r\n    }\r\n\r\n    public short Add(short a, short b)\r\n    {\r\n        Debug.Log(\"short version\");\r\n        return (short)(a + b);\r\n    }\r\n}\r\n~~~\r\n\r\nWe can call the specified overload this way:\r\n\r\n~~~lua\r\nlocal m1 = typeof(CS.TestOverload):GetMethod('Add', {typeof(CS.System.Int16), typeof(CS.System.Int16)})\r\nlocal m2 = typeof(CS.TestOverload):GetMethod('Add', {typeof(CS.System.Int32), typeof(CS.System.Int32)})\r\nlocal f1 = xlua.tofunction(m1) --切记对于同一个MethodBase，只tofunction一次，然后重复使用\r\nlocal f2 = xlua.tofunction(m2)\r\n\r\nlocal obj = CS.TestOverload()\r\n\r\nf1(obj, 1, 2) --调用short版本，成员方法，所以要传对象，静态方法则不需要\r\nf2(obj, 1, 2) --调用int版本\r\n~~~\r\n\r\nNote: Since xlua.tofunction is not easy to use and reflection can also be used, doing this is recommended only as a temporary solution. Instead, try doing this with a package method.\r\n\r\n## Is interface expansion method supported?\r\n\r\nDue to the quantity of generated code, calling with obj:ExtentionMethod() is not supported. You can only call CS.ExtentionClass.ExtentionMethod(obj) through the static method. \r\n\r\n"
  },
  {
    "path": "Assets/XLua/Doc/Faq_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: 7b6232183a3c52f4f9af4b68f8a687cc\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Hotfix_EN.md",
    "content": "## Usage\r\n\r\n1. Add the HOTFIX_ENABLE macro to enable this feature (to File->Build Setting->Scripting Define Symbols on Unity3D). This macro should be set separately on the editor and each mobile platform! For automatic packaging, it should be noted that the macro set in the code in the API are not valid and it needs to be set in the editor.\r\n\r\n(It is recommended that you use HOTFIX_ENABLE only for mobile phone build versions or for developing a patch in the editor, but not for usual development codes)\r\n\r\n2. Execute the XLua/Generate Code menu.\r\n\r\n3. This step will be automatically carried out in injection and construction of mobile phone packages. You need to manually execute the \"XLua/Hotfix Inject In Editor\" menu when developing a hotfix in the editor. After successful injection, \"hotfix inject finish!\" or \"had injected!\" will be printed.\r\n\r\n## Constraints\r\n\r\nStatic constructors are not supported.\r\n\r\nAt present, only the code hotfix for Assets is supported, but not the code hotfix for engine or for the C# system library.\r\n\r\n## API\r\n\r\nxlua.hotfix(class, [method_name], fix)\r\n\r\n* Description: Inject Lua patch\r\n* class: C# class, two representation methods, CS.Namespace.Typename or string method \"Namespace.Typename\"; The string format is consistent with the Type.GetType of C#; If the nested type is non-Public type, you can only use the string method to represent \"Namespace.TypeName+NestedTypeName\".\r\n* method_name: method name, optional;\r\n* fix: If you transfer method_name, fix will be a function; otherwise it will provide a set of functions through the table. The table organization is based on the principle that key is method_name and value is the function.\r\n\r\nbase(csobj)\r\n\r\n* Description: The child type override function is implemented by calling the parent type via base.\r\n* csobj: object\r\n* Returned value: new object, which can be used to call the method via base\r\n\r\nExample (in HotfixTest2.cs):\r\n\r\n```lua\r\nxlua.hotfix(CS.BaseTest, 'Foo', function(self, p)\r\n    print('BaseTest', p)\r\n    base(self):Foo(p)\r\nend)\r\n```\r\n\r\nutil.hotfix_ex(class, method_name, fix)\r\n\r\n* Description: This is the enhanced version of xlua.hotfix, which can perform the original function in the fix function. Its disadvantage is that the implementation of fix will be slightly slower.\r\n* method_name: method name;\r\n* fix: This is the Lua function used to replace the C# method.\r\n\r\n## Tag the type of hotfix\r\n\r\nLike other configurations, there are two methods:\r\n\r\nConfigure a list in the static field or property of a static type. Properties can be used to implement more complex configurations, such as whitelisting based on Namespace. \r\n\r\n~~~csharp\r\npublic static class HotfixCfg\r\n{\r\n    [Hotfix]\r\n    public static List<Type> by_field = new List<Type>()\r\n    {\r\n        typeof(HotFixSubClass),\r\n        typeof(GenericClass<>),\r\n    };\r\n\r\n    [Hotfix]\r\n    public static List<Type> by_property\r\n    {\r\n        get\r\n        {\r\n            return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\r\n                    where type.Namespace == \"XXXX\"\r\n                    select type).ToList();\r\n        }\r\n    }\r\n}\r\n~~~\r\n\r\n## Hotfix Flag\r\n\r\nThe Hotfix flag can set some flags to customize the generated code and instrumentation.\r\n\r\n* Stateless and Stateful\r\n\r\nThis is is a legacy setting. The Stateful method has been removed in the new version because similar effects can be achieved with the xlua.util.state interface. For how to use this interface, see the sample code in HotfixTest2.cs.\r\n\r\nWithout Stateful, the default is Stateless, so there is no need to set this flag.\r\n\r\n* ValueTypeBoxing\r\n\r\nValue type adaptation. The delegate will converge to the object. Its advantage lies in having less code. Its disadvantage is that boxing and gc are generated. It is suitable for text segment sensitive services.\r\n\r\n* IgnoreProperty\r\n\r\nNo property injection and generation of adaptation code. In general, most properties have simple implementation and lower error probability. No injection is recommended.\r\n\r\n* IgnoreNotPublic\r\n\r\nNo injection or generation of adaptation code for non-public methods. Only private methods (such as MonoBehaviour) which are called by reflection will be injected. Other non-public methods that are only called by this type may not be injected. but the workload for repair will be slightly heavier. All public methods that reference this function must be rewritten.\r\n\r\n* Inline\r\n\r\nNo generation of the adaptation delegate. The process code is directly injected into the function body.\r\n\r\n* IntKey\r\n\r\nInstead of generating static fields, all injection points are managed centrally in an array.\r\n\r\nAdvantages: Little effect on the text segment.\r\n\r\nDisadvantages: This is not as convenient as the default method, and needs to use the id to indicate which function the hotfix is used for. This id is assigned when the code is injected into the tool. The function-id mapping will be saved in Gen/Resources/hotfix_id_map.lua.txt. Automatic timestamping is backed up to the same level directory as hotfix_id_map.lua.txt. After releasing the mobile version, properly save the file.\r\n\r\nThe format of this file is like this (Note: This file is only used in IntKey mode. If you do not specify IntKey mode injection, only an empty table is returned in the file):\r\n\r\n~~~lua\r\nreturn {\r\n    [\"HotfixTest\"] = {\r\n        [\".ctor\"] = {\r\n            5\r\n        },\r\n        [\"Start\"] = {\r\n            6\r\n        },\r\n        [\"Update\"] = {\r\n            7\r\n        },\r\n        [\"FixedUpdate\"] = {\r\n            8\r\n        },\r\n        [\"Add\"] = {\r\n            9,10\r\n        },\r\n        [\"OnGUI\"] = {\r\n            11\r\n        },\r\n    },\r\n}\r\n~~~\r\n\r\nTo replace the Update function of HotfixTest, you have to\r\n\r\n~~~lua\r\nCS.XLua.HotfixDelegateBridge.Set(7, func)\r\n~~~\r\n\r\nIf it is an overloaded function, a function name will correspond to multiple ids, such as the Add function above.\r\n\r\nCan it be automated? Yes. xlua.util provides the auto_id_map function. When it is executed once, you can use the type and method name to indicate the repaired function.\r\n\r\n~~~lua\r\n(require 'xlua.util').auto_id_map()\r\nxlua.hotfix(CS.HotfixTest, 'Update', function(self)\r\n        self.tick = self.tick + 1\r\n        if (self.tick % 50) == 0 then\r\n            print('<<<<<<<<Update in lua, tick = ' .. self.tick)\r\n        end\r\n    end)\r\n~~~\r\n\r\nThe premise is that hotfix_id_map.lua.txt is in a directory that can be referenced by require 'hotfix_id_map'.\r\n\r\n## Usage suggestions\r\n\r\n* Add the Hotfix flag to all types that are most likely to be modified.\r\n* It is recommended that you use reflection to find all delegate types involved in the function parameters, fields, properties and events, and then add CSharpCallLua.\r\n* Add LuaCallCSharp to business code, engine APIs, system APIs, and the types to which the Lua hotfix requires high-performance access.\r\n* Engine APIs and system APIs may be stripped by code (those not referenced by C# will be stripped). If you think you may add API calls other than C# codes, these APIs are added to either LuaCallCSharp or ReflectionUse.\r\n\r\n## Patching\r\n\r\nXlua uses Lua functions to replace C#'s constructors, functions, properties and events. Lua implementations are based on functions. For example, the property corresponds to a getter function and a setter function, and the event corresponds to an add function and a remove function.\r\n\r\n* Functions\r\n\r\nmethod_name transfers the function name and supports overload. Different overloads are forwarded to the same Lua function.\r\n\r\nFor example:\r\n\r\n```csharp\r\n// 要fix的C#类\r\n[Hotfix]\r\npublic class HotfixCalc\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        return a - b;\r\n    }\r\n\r\n    public Vector3 Add(Vector3 a, Vector3 b)\r\n    {\r\n        return a - b;\r\n    }\r\n｝\r\n```\r\n\r\n```lua\r\nxlua.hotfix(CS.HotfixCalc, 'Add', function(self, a, b)\r\n    return a + b\r\nend)\r\n```\r\n\r\nThe difference between a static function and a member function is that a member function will have a self parameter added. This self is the C# object itself in Stateless mode (corresponding to C#'s this).\r\n\r\nOrdinary parameters correspond to Lua parameters. The ref parameter corresponds to a Lua parameter and a returned value, and the out parameter corresponds to a returned value on Lua.\r\n\r\nGeneric functions have the same hotfix rules as ordinary functions.\r\n\r\n* Constructors\r\n\r\nThe method_name corresponding to the constructor is \".ctor\".\r\n\r\nUnlike the ordinary function, the hotfix of the constructor is not a replacement, but calls Lua after executing the original logic.\r\n\r\n* Properties\r\n\r\nThe property named \"AProp\" will correspond to a getter, its method_name equals to get_AProp, and the setter's method_name is equal to set_AProp.\r\n\r\n* []Operators\r\n\r\nThe setter corresponds to set_Item, and the getter corresponds to get_Item. The first parameter is self, which is followed by key and value for the setter. The getter has only the key parameter, and the returned value is the value that it has gotten. \r\n\r\n* Other operators\r\n\r\nThe operators of C# have a set of internal representations. For example, the + operator function name is op_Addition (for the internal representation of other operators, see the relevant document). Overriding this function will override the + operator of C#.\r\n\r\n* Events\r\n\r\nFor example, for the event \"AEvent\", the += operator is add_AEvent, and the -= operator is remove_AEvent. The first parameter of the two functions is self, and the second parameter is the delegate immediately after the operator.\r\n\r\nThen, directly access the private delegate corresponding to the event via xlua.private_accessible. (For versions newer than 2.1.11, calling xlua.private_accessible is not required.) The event can be triggered directly through the object's \"&event name\" field, such as self\\['&MyEvent'\\](), where MyEvent is the event name.\r\n\r\n* Destructors\r\n\r\nThe method_name is \"Finalize” and transfers a self parameter.\r\n\r\nUnlike the ordinary function, the hotfix of the destructor is not a replacement, but continues the original logic after calling the Lua function.\r\n\r\n* Generic types\r\n\r\nOther rules are the same. It should be noted that each instantiated generic type is an independent type. You can only patch each instantiated type. For example:\r\n\r\n```csharp\r\npublic class GenericClass<T>\r\n{\r\n｝\r\n```\r\n\r\nYou can only patch GenericClass\\<double\\> and GenericClass\\<int\\>, instead of GenericClass.\r\n\r\nThe following is an example of patching GenericClass<double>:\r\n\r\n```csharp\r\nluaenv.DoString(@\"\r\n    xlua.hotfix(CS.GenericClass(CS.System.Double), {\r\n        ['.ctor'] = function(obj, a)\r\n            print('GenericClass<double>', obj, a)\r\n        end;\r\n        Func1 = function(obj)\r\n            print('GenericClass<double>.Func1', obj)\r\n        end;\r\n        Func2 = function(obj)\r\n            print('GenericClass<double>.Func2', obj)\r\n            return 1314\r\n        end\r\n    })\r\n\");\r\n```\r\n\r\n* Unity coroutine\r\n\r\nUsing util.cs_generator, you can simulate an IEnumerator with a function. The coroutine.yield here is similar to the yield return in C#. For example, the following C# code is equivalent to the corresponding hotfix code.\r\n\r\n~~~csharp\r\n[XLua.Hotfix]\r\npublic class HotFixSubClass : MonoBehaviour {\r\n    IEnumerator Start()\r\n    {\r\n        while (true)\r\n        {\r\n            yield return new WaitForSeconds(3);\r\n            Debug.Log(\"Wait for 3 seconds\");\r\n        }\r\n    }\r\n}\r\n~~~\r\n\r\n~~~csharp\r\nluaenv.DoString(@\"\r\n    local util = require 'xlua.util'\r\n    xlua.hotfix(CS.HotFixSubClass,{\r\n        Start = function(self)\r\n            return util.cs_generator(function()\r\n                while true do\r\n                    coroutine.yield(CS.UnityEngine.WaitForSeconds(3))\r\n                    print('Wait for 3 seconds')\r\n                end\r\n            end)\r\n        end;\r\n    })\r\n\");\r\n~~~\r\n\r\n* Entire type\r\n\r\nIf you want to replace the entire type, you don't need to call xlua.hotfix again and again, you can do it all at once. Just give a table and press method_name = function.\r\n\r\n```lua\r\nxlua.hotfix(CS.StatefullTest, {\r\n    ['.ctor'] = function(csobj)\r\n        return util.state(csobj, {evt = {}, start = 0, prop = 0})\r\n    end;\r\n    set_AProp = function(self, v)\r\n        print('set_AProp', v)\r\n        self.prop = v\r\n    end;\r\n    get_AProp = function(self)\r\n        return self.prop\r\n    end;\r\n    get_Item = function(self, k)\r\n        print('get_Item', k)\r\n        return 1024\r\n    end;\r\n    set_Item = function(self, k, v)\r\n        print('set_Item', k, v)\r\n    end;\r\n    add_AEvent = function(self, cb)\r\n        print('add_AEvent', cb)\r\n        table.insert(self.evt, cb)\r\n    end;\r\n    remove_AEvent = function(self, cb)\r\n       print('remove_AEvent', cb)\r\n       for i, v in ipairs(self.evt) do\r\n           if v == cb then\r\n               table.remove(self.evt, i)\r\n               break\r\n           end\r\n       end\r\n    end;\r\n    Start = function(self)\r\n        print('Start')\r\n        for _, cb in ipairs(self.evt) do\r\n            cb(self.start, 2)\r\n        end\r\n        self.start = self.start + 1\r\n    end;\r\n    StaticFunc = function(a, b, c)\r\n       print(a, b, c)\r\n    end;\r\n    GenericTest = function(self, a)\r\n       print(self, a)\r\n    end;\r\n    Finalize = function(self)\r\n       print('Finalize', self)\r\n    end\r\n})\r\n```\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Doc/Hotfix_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: 7919d0bddff7ee340852008d36cd68ec\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/Materials/logo.mat.meta",
    "content": "fileFormatVersion: 2\nguid: 953e2ba39b9a2d54388919b75877efb7\nNativeFormatImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Doc/Materials.meta",
    "content": "fileFormatVersion: 2\nguid: ee1eae11fbe87b04193ab2c3d15ba2b3\nfolderAsset: yes\ntimeCreated: 1481715983\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_API.doc.meta",
    "content": "fileFormatVersion: 2\nguid: f05e875da3e1b3844b2360d177d617c9\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_API.md",
    "content": "## C# API\n\n### LuaEnv类\n\n#### object[] DoString(string chunk, string chunkName = \"chuck\", LuaTable env = null)\n\n描述：\n\n    执行一个代码块。\n\n参数：\n\n    chunk: Lua代码的字符串；\n    chunkName： 发生error时的debug显示信息中使用，指明某某代码块的某行错误；\n    env ：这个代码块的环境变量；\n返回值：\n\n    代码块里return语句的返回值;\n    比如：return 1, “hello”，DoString返回将包含两个object的数组， 一个是double类型的1， 一个是string类型的“hello”\n\n例如：\n\n    LuaEnv luaenv = new LuaEnv();\n    object[] ret = luaenv.DoString(\"print(‘hello’)\\r\\nreturn 1\")\n    UnityEngine.Debug.Log(\"ret=\"+ret[0]);\n    luaenv.Dispose()\n\n#### T LoadString<T>(string chunk, string chunkName = \"chunk\", LuaTable env = null)\n\n描述：\n\n    加载一个代码块，但不执行，只返回类型可以指定为一个delegate或者一个LuaFunction\n\n参数：\n\n    chunk: Lua代码的字符串；\n    chunkName： 发生error时的debug显示信息中使用，指明某某代码块的某行错误；\n    env ：这个代码块的环境变量；\n\n返回值：\n\n    代表该代码块的delegate或者LuaFunction类；\n\n#### LuaTable Global\n\n描述：\n\n    代表lua全局环境的LuaTable\n\n### void Tick()\n\n描述：\n\n    清除Lua的未手动释放的LuaBase对象（比如：LuaTable， LuaFunction），以及其它一些事情。\n    需要定期调用，比如在MonoBehaviour的Update中调用。\n\n### void AddLoader(CustomLoader loader)\n\n描述：\n\n    增加一个自定义loader\n\n参数：\n\n    loader：一个包括了加载函数的委托，其类型为delegate byte[] CustomLoader(ref string filepath)，当一个文件被require时，这个loader会被回调，其参数是调用require所使用的参数，如果该loader找到文件，可以将其读进内存，返回一个byte数组。如果需要支持调试的话，而filepath要设置成IDE能找到的路径（相对或者绝对都可以）\n\n#### void Dispose()\n\n描述：\n\n    Dispose该LuaEnv。\n\n> LuaEnv的使用建议：全局就一个实例，并在Update中调用GC方法，完全不需要时调用Dispose\n\n### LuaTable类\n\n#### `T Get<T>(string key)`\n\n描述：\n\n    获取在key下，类型为T的value，如果不存在或者类型不匹配，返回null；\n\n#### `T GetInPath<T>(string path)`\n\n描述：\n\n    和Get的区别是，这个函数会识别path里头的“.”，比如var i = tbl.GetInPath<int>(“a.b.c”)相当于在lua里头执行i = tbl.a.b.c，避免仅为了获取中间变量而多次调用Get，执行效率更高。\n\n#### `void SetInPath<T>(string path, T val)`\n\n描述：\n\n    和GetInPaht<T>对应的setter；\n\n#### `void Get<TKey, TValue>(TKey key, out TValue value)`\n\n描述：\n\n     上面的API的Key都只能是string，而这个API无此限制；\n\n#### `void Set<TKey, TValue>(TKey key, TValue value)`\n\n描述：\n\n     对应Get<TKey, TValue>的setter；\n\n#### `T Cast<T>()`\n\n描述：\n\n    把该table转成一个T指明的类型，可以是一个加了CSharpCallLua声明的interface，一个有默认构造函数的class或者struct，一个Dictionary，List等等。\n\n#### void SetMetaTable(LuaTable metaTable)\n\n描述：\n\n    设置metaTable为table的metatable\n\n### LuaFunction 类\n\n> 注意：用该类访问Lua函数会有boxing，unboxing的开销，为了性能考虑，需要频繁调用的地方不要用该类。建议通过 `table.Get<ABCDelegate>` 获取一个 delegate 再调用（假设 `ABCDelegate` 是 C# 的一个 delegate）。在使用使用 `table.Get<ABCDelegate>` 之前，请先把ABCDelegate加到代码生成列表。\n\n#### object[] Call(params object[] args)\n\n描述：\n\n    以可变参数调用Lua函数，并返回该调用的返回值。\n\n#### object[] Call(object[] args, Type[] returnTypes)\n\n描述：\n\n    调用Lua函数，并指明返回参数的类型，系统会自动按指定类型进行转换。\n\n#### void SetEnv(LuaTable env)\n\n描述：\n\n    相当于lua的setfenv函数。\n\n## Lua API\n\n### CS对象\n\n#### CS.namespace.class(...)\n\n描述：\n\n    调用一个C#类型的构造函数,并返回类型实例\n\n例如：\n\n    local v1=CS.UnityEngine.Vector3(1,1,1) \n\n#### CS.namespace.class.field\n\n描述：\n\n    访问一个C#静态成员\n\n例如：\n\n    Print(CS.UnityEngine.Vector3.one)\n\n#### CS.namespace.enum.field\n\n描述：\n\n    访问一个枚举值\n\n#### typeof函数\n\n描述：\n\n    类似C#里头的typeof关键字，返回一个Type对象，比如GameObject.AddComponent其中一个重载需要一个Type参数\n\n例如：\n\n    newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))\n\n#### 无符号64位支持\n\n##### uint64.tostring\n\n描述：\n\n    无符号数转字符串。\n\n##### uint64.divide\n\n描述：\n\n    无符号数除法。\n\n##### uint64.compare\n\n描述：\n\n    无符号比较，相对返回0，大于返回正数，小于返回负数。\n\n##### uint64.remainder\n\n描述：\n\n    无符号数取模。\n\n##### uint64.parse\n\n描述：\n    字符串转无符号数。\n\n#### xlua.structclone\n\n描述：\n\n    克隆一个c#结构体\n\n#### xlua.private_accessible(class)\n\n描述：\n\n    让一个类的私有字段，属性，方法等可用\n例子：\n\n    xlua.private_accessible(CS.UnityEngine.GameObject)\n\n#### xlua.get_generic_method\n\n描述：\n\n    获取一个泛型方法\n例子：\n\n```lua\nlocal foo_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Foo')\nlocal bar_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Bar')\n\nlocal foo = foo_generic(CS.System.Int32, CS.System.Double)\nlocal bar = bar_generic(CS.System.Double, CS.UnityEngine.GameObject)\n\n-- call instance method\nlocal o = CS.GetGenericMethodTest()\nlocal ret = foo(o, 1, 2)\nprint(ret)\n\n-- call static method\nbar(2, nil)\n```\n\n#### cast函数\n\n描述：\n\n    指明以特定的接口访问对象，这在实现类无法访问的时候（比如internal修饰）很有用，这时可以这么来（假设下面的calc对象实现了C#的PerformentTest.ICalc接口）\n\n例子：\n\n    cast(calc, typeof(CS.PerformentTest.ICalc))\n\n然后就木有其它API了\n访问csharp对象和访问一个table一样，调用函数跟调用lua函数一样，也可以通过操作符访问c#的操作符，下面是一个例如：\n\n    local v1=CS.UnityEngine.Vector3(1,1,1) \n    local v2=CS.UnityEngine.Vector3(1,1,1) \n    v1.x = 100 \n    v2.y = 100 \n    print(v1, v2)\n    local v3 = v1 + v2\n    print(v1.x, v2.x) \n    print(CS.UnityEngine.Vector3.one)\n    print(CS.UnityEngine.Vector3.Distance(v1, v2))\n\n## 类型映射\n\n### 基本数据类型\n\n|C#类型|Lua类型|\n|-|-|\n|sbyte，byte，short，ushort，int，uint，double，char，float|number|\n|decimal|userdata|\n|long，ulong|userdata/lua_Integer(lua53)|\n|bytes[]|string|\n|bool|boolean|\n|string|string|\n\n### 复杂数据类型\n\n|C#类型|Lua类型|\n|-|-|\n|LuaTable|table|\n|LuaFunction|function|\n|class或者 struct的实例|userdata，table|\n|method，delegate|function|\n\n#### LuaTable\n\nC#侧指明从Lua侧输入（包括C#方法的输入参数或者Lua方法的返回值）LuaTable类型，则要求Lua侧为table。或者Lua侧的table，在C#侧未指明类型的情况下转换成LuaTable。\n\n#### LuaFunction\n\nC#侧指明从Lua侧输入（包括C#方法的输入参数或者Lua方法的返回值）LuaFunction类型，则要求Lua侧为function。或者Lua侧的function，在C#侧未指明类型的情况下转换成LuaFunction。\n\n#### LuaUserData\n\n对应非 C# Managered 对象的lua userdata。\n\n#### class 或者 struct 的实例\n\n从C#传一个class或者struct的实例，将映射到Lua的userdata，并通过__index访问该userdata的成员\nC#侧指明从Lua侧输入指定类型对象，Lua侧为该类型实例的userdata可以直接使用；如果该指明类型有默认构造函数，Lua侧是table则会自动转换，转换规则是：调用构造函数构造实例，并用table对应字段转换到c#对应值后赋值各成员。\n\n#### method， delegate\n\n成员方法以及delegate都是对应lua侧的函数。\nC#侧的普通参数以及引用参数，对应lua侧函数参数；C#侧的返回值对应于Lua的第一个返回值；引用参数和out参数则按序对应于Lua的第2到第N个参数。\n\n## 宏\n\n#### HOTFIX_ENABLE\n\n打开hotfix功能。\n\n#### NOT_GEN_WARNING\n\n反射时打印warning。\n\n#### GEN_CODE_MINIMIZE\n\n以偏向减少代码段的方式生成代码。\n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_API.md.meta",
    "content": "fileFormatVersion: 2\nguid: d97e183eaa307684b9b99ded9005b181\ntimeCreated: 1518577405\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_API_EN.md",
    "content": "## C# APIs\n\n### LuaEnv type\n\n#### object[] DoString(string chunk, string chunkName = \"chuck\", LuaTable env = null)\n\nDescription:\n\n    Executes a code block.\n\nParameter:\n\n    chunk: Lua code string; \n    chunkName: This is used in the debug message when an error occurs, indicating a certain line in a certain code block has an error. \n    env: This is the environment variable of this code block.\n\nReturned value:\n\n    The returned value of the return statement in the code block. \n    For example: return 1, \"hello\". DoString returns an array that will contain two objects. One is 1 of the double type, and the other is the string \"hello\".\n\nFor example:\n\n    LuaEnv luaenv = new LuaEnv();\n    object[] ret = luaenv.DoString(\"print(‘hello’)\\r\\nreturn 1\")\n    UnityEngine.Debug.Log(\"ret=\"+ret[0]);\n    luaenv.Dispose()\n\n#### T LoadString<T>(string chunk, string chunkName = \"chunk\", LuaTable env = null)\n\nDescription:\n\n    This loads a code block, but does not execute it. It only returns the type can be specified as a delegate or a LuaFunction.\n\nParameter:\n\n    chunk: Lua code string; \n    chunkName: This is used in the debug message when an error occurs, indicating a certain line in a certain code block has an error. \n    env: This is the environment variable of this code block.\n\nReturned Value:\n\n    This is the delegate or LuaFunction type that represents the code block.\n\n#### LuaTable Global;\n\nDescription:\n\n    This is the LuaTable representing the Lua global environment.\n\n### void Tick()\n\nDescription:\n\n    This clears Lua's LuaBase objects that have not been manually released (for example LuaTable, LuaFunction), and other things. \n    This needs to be called periodically, for example in the Update of MonoBehaviour.\n\n### void AddLoader(CustomLoader loader)\n\nDescription:\n\n    Adds a custom loader\n\nParameter:\n\n    loader: A delegate that includes the loaded function. The type is delegate byte[] CustomLoader(ref string filepath). When a file is required, the loader will be called back. Its parameters are the parameters used to call require. If the loader finds the file, it reads it into memory and returns a byte array. If debug support is required, the filepath should be set to one the IDE can find (relative or absolute).\n\n#### void Dispose()\n\nDescription:\n\n    This disposes the LuaEnv.\n\n> LuaEnv usage suggestion: use only one instance globally. Call the GC method in Update, and call Dispose when it is not required.\n\n### LuaTable type\n\n#### T Get<T>(string key)\n\nDescription:\n\n    Gets the value of type T on key. Null is returned if it does not exist or the type does not match.\n\n#### T GetInPath<T>(string path)\n\nDescription:\n\n    The difference from Get is that this function will identify the \".\" in the path. For example, var i = tbl.GetInPath<int>(“a.b.c”) is equivalent to executing i = tbl.abc in Lua. This avoids calling Get multiple times and obtaining intermediate variables. It has higher execution efficiency.\n\n#### void SetInPath<T>(string path, T val)\n\nDescription:\n\n    Setter corresponding to SetInPath<T>;\n\n#### void Get<TKey, TValue>(TKey key, out TValue value)\n\nDescription:\n\n    The key of the APIs described above can only be a string, but this API has no such restriction.\n\n#### void Set<TKey, TValue>(TKey key, TValue value)\n\nDescription:\n\n    This is the setter corresponding to Get<TKey, TValue>.\n\n#### T Cast<T>()\n\nDescription:\n\n    Converts the table to a type specified by T. It can be an interface with a CSharpCallLua declaration, a type or struct with a default constructor, a Dictionary, a List, and so on.\n\n#### void SetMetaTable(LuaTable metaTable)\n\nDescription:\n\n    Sets metatable to a table metatable\n\n### LuaFunction type\n\n> Note: Accessing Lua functions with this type will result in overhead from boxing and unboxing. For the sake of performance, do not use this type if frequent calls are required. It is recommended that you use table.Get<ABCDelegate> to get a delegate and then call it (assuming ABCDelegate is a delegate of C#). Before using table.Get<ABCDelegate>, add ABCDelegate to the list of generated code.\n\n#### object[] Call(params object[] args)\n\nDescription:\n\n    This calls the Lua function with the variable parameters and returns the returned value of the call.\n\n#### object[] Call(object[] args, Type[] returnTypes)\n\nDescription:\n\n    This calls the Lua function and specifies the type of the returned parameter. The system will automatically convert the specified type.\n\n#### void SetEnv(LuaTable env)\n\nDescription:\n\n    Equivalent to Lua's setfenv function.\n\n## Lua API\n\n### CS objects\n\n#### CS.namespace.class(...)\n\nDescription:\n\n    This calls a C# type constructor and returns a type instance.\n\nFor Example:\n\n    local v1=CS.UnityEngine.Vector3(1,1,1)\n\n#### CS.namespace.class.field\n\nDescription:\n\n    This accesses a C# static member.\n\nFor Example:\n\n    Print(CS.UnityEngine.Vector3.one)\n\n#### CS.namespace.enum.field\n\nDescription:\n\n    This accesses an enumerated value.\n\n#### Typeof Functions\n\nDescription:\n\n    This is similar to the typeof keyword in C#: a Type object is returned. For example, in GameObject.AddComponent, one overload requires a Type parameter.\n\nFor Example:\n\n    newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))\n\n#### Unsigned 64-bit is supported\n\n##### uint64.tostring\n\nDescription:\n\n    Unsigned number to string.\n\n##### uint64.divide\n\nDescription:\n\n    Unsigned number division.\n\n##### uint64.compare\n\nDescription:\n\n    Unsigned comparison: 0 is returned for equal, positive for greater than, and negative for less than.\n\n##### uint64.remainder\n\nDescription:\n\n    Unsigned modulus.\n\n##### uint64.parse\n\nDescription: \nString to unsigned number.\n\n#### xlua.structclone\n\nDescription:\n\n    This clones a c# structure.\n\n#### xlua.private_accessible(class)\n\nDescription:\n\n    This makes the private fields, properties, methods of a type available.\n\n#### Cast Function\n\nDescription:\n\n    This indicates that the object is accessed with a specific interface, which is useful when the implementation type is inaccessible (such as internal modification). Use it in the following way (assuming that the following calc object implements C#'s PerformentTest.ICalc interface):\n\nFor Example:\n\n    cast(calc, typeof(CS.PerformentTest.ICalc))\n\nThen, no other APIs are available.\nAccessing a csharp object is like accessing a table. Calling a function is like calling the Lua function. Operators can also be used to access the C# operator. Here is an example:\n\n    local v1=CS.UnityEngine.Vector3(1,1,1)\n    local v2=CS.UnityEngine.Vector3(1,1,1)\n    v1.x = 100\n    v2.y = 100\n    print(v1, v2)\n    local v3 = v1 + v2\n    print(v1.x, v2.x)\n    print(CS.UnityEngine.Vector3.one)\n    print(CS.UnityEngine.Vector3.Distance(v1, v2))\n\n## Type mapping\n\n### Basic data type\n\n|C# type|Lua type|\n|-|-|\n|sbyte, byte, short, ushort, int ,uint ,double ,char ,float|number|\n|decimal|userdata|\n|long ,ulong|userdata/lua_Integer(lua53)|\n|bytes[]|string|\n|bool|boolean|\n|string|string|\n\n### Complex data type\n\n|C# type|Lua type|\n|-|-|\n|LuaTable|table|\n|LuaFunction|function|\n|class or struct instance|userdata, table|\n|method, delegate|function|\n\n#### LuaTable:\n\nIf C# specifies inputting the LuaTable type (including the input parameters of the C# method or the returned value of the Lua method) from Lua, then it must be a table in Lua. Or, if C# does not specify the type, the table in Lua should be converted to LuaTable .\n\n#### LuaFunction:\n\nIf C# specifies inputting the LuaFunction type (including the input parameters of the C# method or the returned value of the Lua method) from Lua, then it must be a function in Lua. Or, if C# does not specify the type, the function on Lua should be converted to LuaFunction.\n\n#### LuaUserData:\n\nThis is Lua userdata corresponding to the non-C# Managered object.\n\n#### Class or struct instance:\n\nThis transfers a class or struct instance from C#, maps it to Lua userdata, and accesses the member of the userdata via __index.\nIf C# specifies inputting objects of the specified type from Lua, then the userdata of the type instance is used directly in Lua. If the specified type has a default constructor, the table in Lua is automatically converted. The conversion rule is: call the constructor to construct an instance, and convert the field corresponding to table to each setter member in C#.\n\n#### Method and delegate:\n\nBoth member methods and delegates correspond to the Lua functions. \nThe ordinary parameters and reference parameters on C# correspond to the Lua function parameters. The returned value on C# corresponds to the first returned value on Lua. The reference parameters and out parameters correspond to the 2nd to Nth parameters on Lua in sequence.\n\n## Macros\n\n#### HOTFIX_ENABLE\n\nThis enables the hotfix function.\n\n#### NOT_GEN_WARNING\n\nThis prints warning when there is reflection.\n\n#### GEN_CODE_MINIMIZE\n\nGenerates code in a way that minimizes the code segments.\n\n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_API_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: 563bce1ceae59334c860773faa7b3a7a\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_Tutorial_EN.md",
    "content": "## xLua Tutorial\n\n### Load Lua files\n\n1. Execute strings\n\n   The most basic way to execute a string is to use LuaEnv.DoString. The string must be compliant with Lua syntax.\nFor example:\n\n       luaenv.DoString(\"print('hello world')\")\n\n   See the full code in the XLua\\Tutorial\\LoadLuaScript\\ByString directory.\n\n   > However, this mode is not recommended. We recommend the following mode:\n\n2. Load Lua files.\n\n   Use Lua's require function.\n\n       DoString(\"require 'byfile'\")\n\n   See the full code in the XLua\\Tutorial\\LoadLuaScript\\ByFile directory.\n\n   The require actually calls the loaders one by one to load the file. The loading process stops if one loader succeeds. If all loaders fail, no file found will be reported. \nIn addition to native loaders, xLua also adds loaders loaded from the Resource. Note that because the Resource supports only  limited numbers of extensions, the Lua file under Resources must be added the txt extension (see the attached example).\n\n   The recommended way to load Lua scripts is as follows: Ensure the entire program is a DoString (\"require 'main'\"). Then, load other scripts in main.lua (like executing the Lua script's command line: lua main.lua).\n\n   Someone may ask: What should I do if my Lua file is downloaded, is extracted from a file in a custom format, or needs to be decrypted? Good question. XLua's custom loader can meet your needs.\n\n3. Customized loaders\n\n   It’s simple to customize loaders on xLua. Only one interface is involved:\n\n       public delegate byte[] CustomLoader(ref string filepath);\n       public void LuaEnv.AddLoader(CustomLoader loader)\n\n   With the AddLoader, you can register a callback. Its parameter is a string. When calling require in the Lua code, the parameter will be transparently transferred to the callback, which can load the specified files based on this parameter. If debugging support is required, you need to modify the filepath to a real path and transfer it. The returned value of this callback is a byte array. Null means the loader is not found. Otherwise, the content of the Lua file is returned. \nCan IIPS IFS be loaded? Yes. Write a loader to call IIPS interface to read the content of the file. Can encrypted files be loaded? Yes, write the loader to read the file and return it after decrypting it. \nSee the complete example in the XLua\\Tutorial\\LoadLuaScript\\Loader directory.\n\n### C# accesses Lua.\n\nThis means that C# initiates access to the Lua data structure. \nThe examples mentioned in this chapter can be found in the XLua\\Tutorial\\CSharpCallLua directory.\n\n1. Get a global basic data type\nAccess LuaEnv.Global, which provides a template Get method. You can specify the type returned.\n\n       luaenv.Global.Get<int>(\"a\")\n       luaenv.Global.Get<string>(\"b\")\n       luaenv.Global.Get<bool>(\"c\")\n\n2. Access a global table\n\n   What class should I specify if the above Get method also been used?\n\n   1. Map it to an ordinary class or struct.\n\n      Define a class, which has a public property of the field corresponding to table. Doing this either with or without a parameter constructor is OK. For example, for {f1 = 100, f2 = 100}, you can define a class that contains public int f1;public int f2;. \nIn this way, xLua will help you to create a new instance and set the corresponding fields to it.\n\n      Table properties can be more or less than class properties. You can nest other complex classes. \nIt should be noted that this process is to copy values. Complex classes will have higher overhead. And, modified field values of the class will not be synchronized to table, and vice versa.\n\n      This feature can reduce the generation overhead by adding the class to GCOptimize. For details, please see the configuration documentation. \nIs mapping in the reference mode available? Yes, this is one method:\n\n   2. Map to an interface\n\n      This mode relies on the generated code. (If no code is generated, the InvalidCastException error will be reported.) The code generator will generate an instance of this interface. When getting a property, the generated code will get the corresponding table field; when setting a property, the generated code will also set the corresponding table field. You can even access Lua functions via the interface method.\n\n   3. Lightweight by value mode: map to Dictionary<>, List<>\n\n      If you do not want to define the type or interface, you can using this. The premise is that table key and value are of the same type.\n\n   4. Another methods are woking on ref mode: map to LuaTable class.\n\n      The advantage of this mode lies in that there is no need to generate code, but there are also some problems with this method. For example, it is an order of magnitude slower than mode 2, and there is no class checking.\n\n3. Access a global function.\n\n   This still uses the Get method, but maps to a different class.\n\n   1. Map to a delegate\n\n      This is the recommended approach, with much better performance and higher class safety. The disadvantage of this method is the generated code. (If no code is generated, the InvalidCastException error will be reported.)\n\n      How do I declare a delegate? \nFor each parameter of the function, declare an input type parameter. \nHow do I deal with multiple returned values? Map to the C# output parameters from left to right. The output parameters include returned value, out parameter, and ref parameter.\n\n      What parameters and returned value types are supported? All are supported. A variety of complex types can be returned, including out, ref modified, and even another delegate.\n\n      Using a delegate is even simpler. It can be used just like a function.\n\n   2. Map to LuaFunction\n\n      The advantages and disadvantages of this approach are exactly the opposite of the first method. \nUsing this is also simple. LuaFunction has a Call function with variable parameters, and you can transfer any type and any number of parameters. The returned values are an array of objects, corresponding to Lua multiple returned values.\n\n4. Usage suggestions\n\n   1. The overhead is high to access Lua global data, especially tables and functions. We recommended doing this as little as possible. For example, during initialization, get the Lua function to be called later (map to the delegate) and save it. Then, you can directly call the delegate. (Tables are similar)\n\n   2. If all implementations of Lua are in the delegate and an interface mode, their use can be completely decoupled from xLua. A dedicated module can be responsible for the initialization of xLua and the mapping of delegates and interfaces. Then, you can set these delegates and interfaces to where they will be used.\n\n### Lua calls C#\n\n> The examples covered in this section are all under XLua\\Tutorial\\LuaCallCSharp\n\n#### Create a new C# object\n\nYou can create a new C# object this way:\n\n    var newGameObj = new UnityEngine.GameObject();\n\nMake it correspond to Lua this way:\n\n    local newGameObj = CS.UnityEngine.GameObject()\n\nThese are basically the same, except in the following ways:\n\n    1. No new keyword is provided in Lua; \n    2. All C# related content is placed in the CS, including constructors, static member properties, and methods.\n\nHow do I deal with multiple constructors? No problem, xLua supports overloads. For example, if you want to call the constructor for GameObject with a string parameter, you can write it this way:\n\n    local newGameObj2 = CS.UnityEngine.GameObject('helloworld')\n\n#### Access C# static properties and methods.\n\n##### Read static properties\n\n    CS.UnityEngine.Time.deltaTime\n\n##### Write static properties\n\n    CS.UnityEngine.Time.timeScale = 0.5\n\n##### Call static methods\n\n    CS.UnityEngine.GameObject.Find('helloworld')\n\nTip: For the types you need to frequently access, you can reference them with local variables before calling them. This can reduce programing time and improve performance.\n\n    local GameObject = CS.UnityEngine.GameObject\n    GameObject.Find('helloworld')\n\n#### Access C# member properties, methods\n\n##### Read member properties\n\n    testobj.DMF\n\n##### Write member properties\n\n    testobj.DMF = 1024\n\n##### Call member methods\n\nNote: When calling the member method, the first parameter needs to transfer this object. We recommended using the colon syntactic sugar as shown below:\n\n    testobj:DMFunc()\n\n##### Parent properties and methods\n\nXLua supports (via derived types) access to static properties and static methods of a base type, (via derived type instances) access to member properties, and member methods of base type.\n\n##### Parameter input and output properties (out and ref)\n\nProcessing rules for parameters called by Lua: The ordinary parameter of C# is an input formal parameter. Ref modified is an input formal parameter, but out is not. The rest correspond from left to right to the actual parameter list called by Lua.\n\nThe processing rule for returned values called by Lua: The returned value of a C# function (if any) is a returned value, out is a returned value, and ref is a returned value. The rest correspond to multiple returned values of Lua from left to right.\n\n##### Overload method:\n\nThis method allows you to access overloaded functions directly through different parameter types, for example:\n\n    testobj:TestFunc(100)\n    testobj:TestFunc('hello')\n\nThe integer parameter TestFunc and the string parameter TestFunc will be accessed separately.\n\nNote: xLua only supports overloaded function calls to a certain extent. Because Lua supports far fewer types than C# does, there will be one-to-many situations. For example, C#'s int, float, and double types all correspond to Lua's number type. In the above example, if TestFunc has these overload parameters, the first line will not be able to distinguish between them and only one of them can be called (the first in the generated code).\n\n##### Operators\n\nThese operators are supported: +, -, *, /, ==, unary-, <, <=, %[]\n\n##### Methods whose parameters have default values:\n\nThis is the same as when C# calls a function with a default value. If the given actual parameters are less than the formal parameters, the default values will be added.\n\n##### Variable parameter methods\n\nFor the following C# parameter:\n\n    void VariableParamsFunc(int a, params string[] strs)\n\nYou can call it in Lua this way:\n\n    testobj:VariableParamsFunc(5, 'hello', 'john')\n\n##### Use extension methods\n\nLua can use these directly after you define them in C#.\n\n##### Generic (template) methods\n\nThese are not directly supported, but you can call them after packaging them through the Extension methods feature.\n\n##### The Enumerated Type\n\nEnumerated values are just like static properties of the enumerated type.\n\n    testobj:EnumTestFunc(CS.Tutorial.TestEnum.E1)\n\nThe EnumTestFunc function parameter shown above is the Tutorial.TestEnum type.\n\nEnum has a __CastFrom method. This implements conversion from an integer or string to an enumerated value. For example:\n\n    CS.Tutorial.TestEnum.__CastFrom(1)\n    CS.Tutorial.TestEnum.__CastFrom('E1')\n\n##### Delegate use (call, +, -)\n\nCall C# delegate: This is the same as calling the ordinary Lua function.\n\n+ operator: This corresponds to the C# + operator. It combines two calls into a call chain, and the right operand can be of the same type as the C# delegate or Lua function.\n\n- operator: In contrast to +, this removes a delegate from the call chain.\n\n> PS: The delegate property can be set with a Lua function.\n\n##### Events:\n\nFor example, testobj has the following event definition: public event Action TestEvent;\n\nAdd event callbacks\n\n    testobj:TestEvent('+', lua_event_callback)\n\nRemove event callbacks\n\n    testobj:TestEvent('-', lua_event_callback)\n\n##### Support for 64-bit integers\n\n    In Lua version 5.3, 64-bit integers (long, ulong) are mapped to native 64-bit integers. Since the LuaJIT version (equivalent to the standard Lua 5.1 version ) does not support 64-bit integers, xLua provides a 64-bit support extension library. Both C# long and ulong integers will be mapped to userdata. \n    \n     64-bit operations, comparisons, print\n    \n     support, and Lua number operations are supported in Lua. It should be noted for comparison\n    \n     that in the 64 extension library, only int64 and ulong integers will be strongly converted to long integers first and then transferred to Lua. In some of Ulong's operations, for the sake of comparison, we use the same support mode as Java: providing a set of APIs. For details, see the API documentation.\n\n##### Automatic conversion between C# complex types and tables\n\nFor a C# complex type with no parameter constructor, a table can be used directly as a substitute on Lua. The table corresponds to a public field of a complex type. It supports function parameter transfer, property assignment, etc. For example: \nThe definition of B structure (type also supported) on C# is as follows:\n\n    public struct A\n    {\n    public int a;\n    }\n    \n    public struct B\n    {\n    public A b;\n    public double c;\n    }\n\nA type has this member function:\n\n    void Foo(B b)\n\nLua can call it in this way:\n\n    obj:Foo({b = {a = 100}, c = 200})\n\n##### Get type (equivalent to C#'s typeof)\n\nFor example, you can get the type information of the UnityEngine.ParticleSystem type this way:\n\n    typeof(CS.UnityEngine.ParticleSystem)\n\n##### \"Strong\" conversion\n\nLua is not a typed language, so it has no \"strong\" conversion with strongly typed languages. However, there's something similar: tell xLua to call an object with the specified generated code. Under what circumstances will it be used? The answer is that, sometimes third-party libraries expose an interface or an abstract type. The implementation type is hidden, so we cannot generate code for the implementation type. This implementation type will be identified by xLua as the ungenerated code and accessed via reflection. Frequently calling it will affect performance significantly. We can add this interface or abstract type to the generated code, and then specify using the generated code to access objects:\n\n    cast(calc, typeof(CS.Tutorial.Calc))\n\nThe above example specifies using the generated code of CS.Tutorial.Calc to access the calc object.\n\n"
  },
  {
    "path": "Assets/XLua/Doc/XLua_Tutorial_EN.md.meta",
    "content": "fileFormatVersion: 2\nguid: 76e3df78477813b47bb62712878a2f62\ntimeCreated: 1529661499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua增加删除第三方lua库.doc.meta",
    "content": "fileFormatVersion: 2\nguid: 40e0633beaaf4dd49aca86e58539a814\ntimeCreated: 1469709930\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua增加删除第三方lua库.md",
    "content": "## What&Why\n\nXLua目前内置的扩展库：\n\n* 针对luajit的64位整数支持；\n* 函数调用耗时以及内存泄漏定位工具；\n* 用于支持ZeroBraneStudio的luasocket库；\n* tdr 4 lua；\n\n随着使用项目的增加以及项目使用的深入程度，仅有这几个扩展已经没法满足项目组了，而由于各个项目对扩展差异化比较大，以及手机平台对安装包大小的敏感，XLua是无法通过预集成去满足这些需求，这也是这篇教程的由来。\n\n这篇教程，将以lua-rapidjson为例，一步步的讲述怎么往xLua添加c/c++扩展，当然，会添加了，自然删除也就会了，项目组可以自行删除不需要用到的预集成扩展。\n\n## How\n\n分三步\n\n1. 修改build文件、工程设置，把要集成的扩展编译到XLua Plugin里头；\n2. 调用xLua的C# API，使得扩展可以被按需（在lua代码里头require的时候）加载；\n3. 可选，如果你的扩展里头需要用到64位整数，你可以通过XLua的64位扩展库来实现和C#的配合。\n\n### 一、添加扩展&编译\n\n准备工作\n\n1. 把xLua的C源码包解压到你Unity工程的Assets同级目录下。\n\n    下载lua-rapidjson代码，按你的习惯放置。本教程是把rapidjson头文件放到$UnityProj\\build\\lua-rapidjson\\include目录下，而扩展的源码rapidjson.cpp放到$UnityProj\\build\\lua-rapidjson\\source目录下（注：$UnityProj指的是你工程的目录）\n\n2. 在CMakeLists.txt加入扩展\n\n    xLua的各平台Plugins编译使用cmake编译，好处是所有平台的编译都写在一个makefile，大部分编译处理逻辑是跨平台的。\n    \n    xLua配套的CMakeLists.txt为第三方扩展提供了扩展点（都是list）：\n    \n    1. THIRDPART_INC：第三方扩展的头文件搜索路径。\n    2. THIRDPART_SRC：第三方扩展的源代码。\n    3. THIRDPART_LIB：第三方扩展依赖的库。\n\n    如下是rapidjson的加法\n\n        #begin lua-rapidjson\n        set (RAPIDJSON_SRC lua-rapidjson/source/rapidjson.cpp)\n        set_property(\n            SOURCE ${RAPIDJSON_SRC}\n            APPEND\n            PROPERTY COMPILE_DEFINITIONS\n            LUA_LIB\n        )\n        list(APPEND THIRDPART_INC  lua-rapidjson/include)\n        set (THIRDPART_SRC ${THIRDPART_SRC} ${RAPIDJSON_SRC})\n        #end lua-rapidjson\n\n    完整代码请见附件。\n\n3. 各平台编译\n\n    所有编译脚本都是按这个方式命名：make_平台_lua版本.后缀。\n\n    比如windows 64位lua53版本是make_win64_lua53.bat，android的luajit版本是make_android_luajit.sh，要编译哪个版本就执行相应的脚本即可。\n\n    执行完编译脚本会自动拷贝到plugin_lua53或者plugin_luajit目录，前者是lua53版本放置路径，后者是luajit。\n\n    配套的android脚本是在linux下使用的，脚本开头的NDK路径要根据实际情况修改。\n\n### 二、C#侧集成\n\n所有lua的C扩展库都会提供个luaopen_xxx的函数，xxx是动态库的名字，比如lua-rapidjson库该函数是luaopen_rapidjson，这类函数由lua虚拟机在加载动态库时自动调用，而在手机平台，由于ios的限制我们加载不了动态库，而是直接编译进进程里头。\n\n为此，XLua提供了一个API来替代这功能（LuaEnv的成员方法）：\n\n    public void AddBuildin(string name, LuaCSFunction initer)\n\n参数：\n\n    name：buildin模块的名字，require时输入的参数；\n    initer：初始化函数，原型是这样的public delegate int lua_CSFunction(IntPtr L)，必须是静态函数，而且带MonoPInvokeCallbackAttribute属性修饰，这个api会检查这两个条件。\n\n我们以luaopen_rapidjson的调用来看看怎么使用。\n\n扩展LuaDLL.Lua类，用pinvoke把luaopen_rapidjson导出到C#，然后写一个符合lua_CSFunction定义的静态函数，你可以在里头做写初始化工作，比如luaopen_rapidjson的调用，以下是完整代码：\n\n    namespace LuaDLL\n    { \n        public partial class Lua\n        { \n            [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\n            public static extern int luaopen_rapidjson(System.IntPtr L);\n\n            [MonoPInvokeCallback(typeof(LuaDLL.lua_CSFunction))]\n            public static int LoadRapidJson(System.IntPtr L)\n            {\n                return luaopen_rapidjson(L);\n            }\n        }\n    }\n\n然后调用AddBuildin：\n\n    luaenv.AddBuildin(\"rapidjson\", LuaDLL.Lua.LoadRapidJson);\n\n然后就ok了，在lua代码中试试该扩展：\n\n    local rapidjson = require('rapidjson')\n    local t = rapidjson.decode('{\"a\":123}')\n    print(t.a)\n    t.a = 456\n    local s = rapidjson.encode(t)\n    print('json', s)\n\n### 三、64位改造\n\n把i64lib.h文件include到需要64位改造的文件里头。\n该头文件的API就以下几个：\n\n    //往栈上放一个int64/uint64\n    void lua_pushint64(lua_State* L, int64_t n);\n    void lua_pushuint64(lua_State* L, uint64_t n);\n    //判断栈上pos位置是否是int64/uint64\n    int lua_isint64(lua_State* L, int pos);\n    int lua_isuint64(lua_State* L, int pos);\n    //从栈上pos位置取一个int64/uint64\n    int64_t lua_toint64(lua_State* L, int pos);\n    uint64_t lua_touint64(lua_State* L, int pos);\n\n这些API的使用依情况而定，可以看看本文附带的附件（rapidjson.cpp文件）\n\n编译工程相关修改"
  },
  {
    "path": "Assets/XLua/Doc/XLua增加删除第三方lua库.md.meta",
    "content": "fileFormatVersion: 2\nguid: 6a5e50ce3ca4b6140858bd4eb6efc2e9\ntimeCreated: 1518577405\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua复杂值类型（struct）gc优化指南.doc.meta",
    "content": "fileFormatVersion: 2\nguid: 11d97e567c78f3147b86070c103f3d2d\ntimeCreated: 1472455442\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua复杂值类型（struct）gc优化指南.md",
    "content": "## 复杂值类型的gc问题\n\nxLua复杂值类型（struct）的默认传递方式是引用传递，这种方式要求先对值类型boxing，传递给lua，lua使用后释放该引用。由于值类型每次boxing将产生一个新对象，当lua侧使用完毕释放该对象的引用时，则产生一次gc。\n为此，xLua实现了一套struct的gc优化方案，您只要通过简单的配置，则可以实现满足条件的struct传递到lua侧无gc。\n\n## struct需要满足什么条件？\n\n1. struct允许嵌套其它struct，但它以及它嵌套的struct只能包含这几种基本类型：byte、sbyte、short、ushort、int、uint、long、ulong、float、double；例如UnityEngine定义的大多数值类型：Vector系列，Quaternion，Color。。。均满足条件，或者用户自定义的一些struct\n2. 该struct配置了GCOptimize属性（对于常用的UnityEngine的几个struct，Vector系列，Quaternion，Color。。。均已经配置了该属性），这个属性可以通过配置文件或者C# Attribute实现；\n3. 使用到该struct的地方，需要添加到生成代码列表；\n\n## 如何配置？\n\n见`XLua的配置.md`的GCOptimize章节。"
  },
  {
    "path": "Assets/XLua/Doc/XLua复杂值类型（struct）gc优化指南.md.meta",
    "content": "fileFormatVersion: 2\nguid: 688574fb2ae996243b1cb02ec3a78bee\ntimeCreated: 1518577405\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua性能分析工具.doc.meta",
    "content": "fileFormatVersion: 2\nguid: 5e83c211c4c43834b9c8027b7480ab5f\ntimeCreated: 1462265117\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua性能分析工具.md",
    "content": "XLua内置两个小工具进行性能方面问题的分析：一个是Lua函数，Lua调用C#函数的时长（不一定等同于CPU耗时，比如协程yield出去那段时间也会被算入调用时间）分析工具；一个是内存泄漏定位工具。\n\n## 函数调用时长分析工具\n\n### 典型使用案例：\n\n说明：\n\napi很简单，就三个，start和stop都是无参数，也很好理解，分别是统计开始以及结束。在start以及stop之间可以多次调用report（也可以考虑不调stop）。每次report会得到从start到调用report为止的函数时长统计报告（以字符串返回）。report函数只有一个可选参数，可以指明按照总时间（参数是字符串的”TOTAL”，这个是默认值），平均每次调用时间（“AVERAGE”），以及调用次数（“CALLED”）来排序。\n典型的一个时长统计报告如下：\n\n第一列是函数名\n\n第二列是源代码，如果是lua文件将会统计到文件，行号，如果是C#的导出代码，将会标注[C#]，如果是C函数，标准为[C]。\n\n后面几列分别是总时间，平均每次调用时间，占总统计时间的百分比，以及调用次数。\n\n## 内存泄漏定位工具\n\n### 典型使用案例：\n\n说明：\n\napi就两个，total获取lua虚拟机的内存占用，单位是Kbytes，以lua number返回。而snapshot返回当前内存快照信息，一个典型的快照报告如下：\n\n第一列是table变量名；\n\n第二列是table的大小，如果该table下有子table也会被统计到；\n\n第三列是变量的类型，UPVALUE代表是闭包里头的变量（内层函数对外层local变量的引用），GLOBAL是全局变量，REGISTRY是C侧（包含虚拟机内部的）的一些私有数据。一般主要关注前面两种；\n\n第四列是变量的ID，其实就是内存指针，如果两次报告间没被重新分配，该ID是不变的，便于识别是否同一table；\n\n最后一列是一些附加信息，比如闭包变量可能存在很多同名的，这里会通过有那些函数引用了该变量来协助定位。\n\n如何定位内存泄漏：通过memory.total检测出内存的持续增长，然后通过memory.snapshot定位出哪里泄漏（lua测的内存泄漏都是表现为往某table添加了数据忘了删除）。"
  },
  {
    "path": "Assets/XLua/Doc/XLua性能分析工具.md.meta",
    "content": "fileFormatVersion: 2\nguid: f8b5c3f531c153c409bb336ba21682ab\ntimeCreated: 1518577405\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua教程.doc.meta",
    "content": "fileFormatVersion: 2\nguid: 9678cc58c9b40e147b514f7f5122ee20\ntimeCreated: 1456291064\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua教程.md",
    "content": "## xLua教程\n\n### Lua文件加载\n\n1. 执行字符串\n\n    最基本是直接用LuaEnv.DoString执行一个字符串，当然，字符串得符合Lua语法\n    比如：\n\n        luaenv.DoString(\"print('hello world')\")\n\n    完整代码见XLua\\Tutorial\\LoadLuaScript\\ByString目录\n    > 但这种方式并不建议，更建议下面介绍这种方法。\n\n2. 加载Lua文件\n\n    用lua的require函数即可\n    比如：\n\n        DoString(\"require 'byfile'\")\n\n    完整代码见XLua\\Tutorial\\LoadLuaScript\\ByFile目录\n\n    require实际上是调一个个的loader去加载，有一个成功就不再往下尝试，全失败则报文件找不到。\n    目前xLua除了原生的loader外，还添加了从Resource加载的loader，需要注意的是因为Resource只支持有限的后缀，放Resources下的lua文件得加上txt后缀（见附带的例子）。\n\n    建议的加载Lua脚本方式是：整个程序就一个DoString(\"require 'main'\")，然后在main.lua加载其它脚本（类似lua脚本的命令行执行：lua main.lua）。\n\n    有童鞋会问：要是我的Lua文件是下载回来的，或者某个自定义的文件格式里头解压出来，或者需要解密等等，怎么办？问得好，xLua的自定义Loader可以满足这些需求。\n\n3. 自定义Loader\n\n    在xLua加自定义loader是很简单的，只涉及到一个接口：\n\n        public delegate byte[] CustomLoader(ref string filepath);\n        public void LuaEnv.AddLoader(CustomLoader loader)\n\n    通过AddLoader可以注册个回调，该回调参数是字符串，lua代码里头调用require时，参数将会透传给回调，回调中就可以根据这个参数去加载指定文件，如果需要支持调试，需要把filepath修改为真实路径传出。该回调返回值是一个byte数组，如果为空表示该loader找不到，否则则为lua文件的内容。\n    有了这个就简单了，用IIPS的IFS？没问题。写个loader调用IIPS的接口读文件内容即可。文件已经加密？没问题，自己写loader读取文件解密后返回即可。。。\n    完整示例见XLua\\Tutorial\\LoadLuaScript\\Loader\n\n### C#访问Lua\n\n这里指的是C#主动发起对Lua数据结构的访问。\n本章涉及到的例子都可以在XLua\\Tutorial\\CSharpCallLua下找到。\n\n1. 获取一个全局基本数据类型\n    访问LuaEnv.Global就可以了，上面有个模版Get方法，可指定返回的类型。\n\n        luaenv.Global.Get<int>(\"a\")\n        luaenv.Global.Get<string>(\"b\")\n        luaenv.Global.Get<bool>(\"c\")\n\n2. 访问一个全局的table\n\n    也是用上面的Get方法，那类型要指定成啥呢？\n    1. 映射到普通class或struct\n\n        定义一个class，有对应于table的字段的public属性，而且有无参数构造函数即可，比如对于{f1 = 100, f2 = 100}可以定义一个包含public int f1;public int f2;的class。\n        这种方式下xLua会帮你new一个实例，并把对应的字段赋值过去。\n\n        table的属性可以多于或者少于class的属性。可以嵌套其它复杂类型。\n        要注意的是，这个过程是值拷贝，如果class比较复杂代价会比较大。而且修改class的字段值不会同步到table，反过来也不会。\n\n        这个功能可以通过把类型加到GCOptimize生成降低开销，详细可参见配置介绍文档。\n        那有没有引用方式的映射呢？有，下面这个就是：\n\n    2. 映射到一个interface\n\n        这种方式依赖于生成代码（如果没生成代码会抛InvalidCastException异常），代码生成器会生成这个interface的实例，如果get一个属性，生成代码会get对应的table字段，如果set属性也会设置对应的字段。甚至可以通过interface的方法访问lua的函数。\n\n    3. 更轻量级的by value方式：映射到Dictionary<>，List<>\n\n        不想定义class或者interface的话，可以考虑用这个，前提table下key和value的类型都是一致的。\n\n    4. 另外一种by ref方式：映射到LuaTable类\n\n        这种方式好处是不需要生成代码，但也有一些问题，比如慢，比方式2要慢一个数量级，比如没有类型检查。\n\n3. 访问一个全局的function\n\n    仍然是用Get方法，不同的是类型映射。\n    1. 映射到delegate\n\n        这种是建议的方式，性能好很多，而且类型安全。缺点是要生成代码（如果没生成代码会抛InvalidCastException异常）。\n\n        delegate要怎样声明呢？\n        对于function的每个参数就声明一个输入类型的参数。\n        多返回值要怎么处理？从左往右映射到c#的输出参数，输出参数包括返回值，out参数，ref参数。\n\n        参数、返回值类型支持哪些呢？都支持，各种复杂类型，out，ref修饰的，甚至可以返回另外一个delegate。\n\n        delegate的使用就更简单了，直接像个函数那样用就可以了。\n\n    2. 映射到LuaFunction\n\n        这种方式的优缺点刚好和第一种相反。\n        使用也简单，LuaFunction上有个变参的Call函数，可以传任意类型，任意个数的参数，返回值是object的数组，对应于lua的多返回值。\n\n4. 使用建议\n\n    1. 访问lua全局数据，特别是table以及function，代价比较大，建议尽量少做，比如在初始化时把要调用的lua function获取一次（映射到delegate）后，保存下来，后续直接调用该delegate即可。table也类似。\n\n    2. 如果lua侧的实现的部分都以delegate和interface的方式提供，使用方可以完全和xLua解耦：由一个专门的模块负责xlua的初始化以及delegate、interface的映射，然后把这些delegate和interface设置到要用到它们的地方。\n\n### Lua 调用 C#\n\n> 本章节涉及到的实例均在XLua\\Tutorial\\LuaCallCSharp下\n\n#### new C#对象\n\n你在C#这样new一个对象：\n\n    var newGameObj = new UnityEngine.GameObject();\n\n对应到Lua是这样：\n\n    local newGameObj = CS.UnityEngine.GameObject()\n\n基本类似，除了：\n\n    1. lua里头没有new关键字；\n    2. 所有C#相关的都放到CS下，包括构造函数，静态成员属性、方法；\n\n如果有多个构造函数呢？放心，xlua支持重载，比如你要调用GameObject的带一个string参数的构造函数，这么写：\n\n    local newGameObj2 = CS.UnityEngine.GameObject('helloworld')\n\n#### 访问C#静态属性，方法\n\n##### 读静态属性\n\n    CS.UnityEngine.Time.deltaTime\n\n##### 写静态属性\n\n    CS.UnityEngine.Time.timeScale = 0.5\n\n##### 调用静态方法\n\n    CS.UnityEngine.GameObject.Find('helloworld')\n\n小技巧：如果需要经常访问的类，可以先用局部变量引用后访问，除了减少敲代码的时间，还能提高性能：\n\n    local GameObject = CS.UnityEngine.GameObject\n    GameObject.Find('helloworld')\n\n#### 访问C#成员属性，方法\n\n##### 读成员属性\n\n    testobj.DMF\n\n##### 写成员属性\n\n    testobj.DMF = 1024\n\n##### 调用成员方法\n\n注意：调用成员方法，第一个参数需要传该对象，建议用冒号语法糖，如下\n\n    testobj:DMFunc()\n\n##### 父类属性，方法\n\nxlua支持（通过派生类）访问基类的静态属性，静态方法，（通过派生类实例）访问基类的成员属性，成员方法\n\n##### 参数的输入输出属性（out，ref）\n\nLua调用侧的参数处理规则：C#的普通参数算一个输入形参，ref修饰的算一个输入形参，out不算，然后从左往右对应lua 调用侧的实参列表；\n\nLua调用侧的返回值处理规则：C#函数的返回值（如果有的话）算一个返回值，out算一个返回值，ref算一个返回值，然后从左往右对应lua的多返回值。\n\n##### 重载方法\n\n直接通过不同的参数类型进行重载函数的访问，例如：\n\n    testobj:TestFunc(100)\n    testobj:TestFunc('hello')\n\n将分别访问整数参数的TestFunc和字符串参数的TestFunc。\n\n注意：xlua只一定程度上支持重载函数的调用，因为lua的类型远远不如C#丰富，存在一对多的情况，比如C#的int，float，double都对应于lua的number，上面的例子中TestFunc如果有这些重载参数，第一行将无法区分开来，只能调用到其中一个（生成代码中排前面的那个）\n\n##### 操作符\n\n支持的操作符有：+，-，*，/，==，一元-，<，<=， %，[]\n\n##### 参数带默认值的方法\n\n和C#调用有默认值参数的函数一样，如果所给的实参少于形参，则会用默认值补上。\n\n##### 可变参数方法\n\n对于C#的如下方法：\n\n    void VariableParamsFunc(int a, params string[] strs)\n\n可以在lua里头这样调用：\n\n    testobj:VariableParamsFunc(5, 'hello', 'john')\n\n##### 使用Extension methods\n\n在C#里定义了，lua里就能直接使用。\n\n##### 泛化（模版）方法\n\n不直接支持，可以通过Extension methods功能进行封装后调用。\n\n##### 枚举类型\n\n枚举值就像枚举类型下的静态属性一样。\n\n    testobj:EnumTestFunc(CS.Tutorial.TestEnum.E1)\n\n上面的EnumTestFunc函数参数是Tutorial.TestEnum类型的。\n\n枚举类支持__CastFrom方法，可以实现从一个整数或者字符串到枚举值的转换，例如：\n\n    CS.Tutorial.TestEnum.__CastFrom(1)\n    CS.Tutorial.TestEnum.__CastFrom('E1')\n\n##### delegate使用（调用，+，-）\n\nC#的delegate调用：和调用普通lua函数一样\n\n+操作符：对应C#的+操作符，把两个调用串成一个调用链，右操作数可以是同类型的C# delegate或者是lua函数。\n\n-操作符：和+相反，把一个delegate从调用链中移除。\n\n> Ps：delegate属性可以用一个luafunction来赋值。\n\n##### event\n\n比如testobj里头有个事件定义是这样：public event Action TestEvent;\n\n增加事件回调\n\n    testobj:TestEvent('+', lua_event_callback)\n\n移除事件回调\n\n    testobj:TestEvent('-', lua_event_callback)\n\n##### 64位整数支持\n\n    Lua53版本64位整数（long，ulong）映射到原生的64位整数，而luajit版本，相当于lua5.1的标准，本身不支持64位，xlua做了个64位支持的扩展库，C#的long和ulong都将映射到userdata：\n    \n    支持在lua里头进行64位的运算，比较，打印\n    \n    支持和lua number的运算，比较\n    \n    要注意的是，在64扩展库中，实际上只有int64，ulong也会先强转成long再传递到lua，而对ulong的一些运算，比较，我们采取和java一样的支持方式，提供一组API，详情请看API文档。\n\n##### C#复杂类型和table的自动转换\n\n对于一个有无参构造函数的C#复杂类型，在lua侧可以直接用一个table来代替，该table对应复杂类型的public字段有相应字段即可，支持函数参数传递，属性赋值等，例如：\nC#下B结构体（class也支持）定义如下：\n\n    public struct A\n    {\n        public int a;\n    }\n\n    public struct B\n    {\n        public A b;\n        public double c;\n    }\n\n某个类有成员函数如下：\n\n    void Foo(B b)\n\n在lua可以这么调用\n\n    obj:Foo({b = {a = 100}, c = 200})\n\n##### 获取类型（相当于C#的typeof）\n\n比如要获取UnityEngine.ParticleSystem类的Type信息，可以这样\n\n    typeof(CS.UnityEngine.ParticleSystem)\n\n##### “强”转\n\nlua没类型，所以不会有强类型语言的“强转”，但有个有点像的东西：告诉xlua要用指定的生成代码去调用一个对象，这在什么情况下能用到呢？有的时候第三方库对外暴露的是一个interface或者抽象类，实现类是隐藏的，这样我们无法对实现类进行代码生成。该实现类将会被xlua识别为未生成代码而用反射来访问，如果这个调用是很频繁的话还是很影响性能的，这时我们就可以把这个interface或者抽象类加到生成代码，然后指定用该生成代码来访问：\n\n    cast(calc, typeof(CS.Tutorial.Calc))\n\n上面就是指定用CS.Tutorial.Calc的生成代码来访问calc对象。\n"
  },
  {
    "path": "Assets/XLua/Doc/XLua教程.md.meta",
    "content": "fileFormatVersion: 2\nguid: 9d871df7bbc973d468622dd10b6f7ea9\ntimeCreated: 1518577405\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/XLua的配置.doc.meta",
    "content": "fileFormatVersion: 2\nguid: 57c6cf634c35eb146b95206d498cbf99\ntimeCreated: 1480488641\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/compatible_bytecode.md",
    "content": "# 通用字节码\r\n\r\n不少项目希望把项目的 lua 源码通过 luac 编译后加载，但官方 lua 有个缺陷：字节码是分 32 位和 64 位版本的，换句话你 32 位 lua 环境只能跑 32 位 luac 编译出来的东西。\r\n\r\n为此，xLua 尝试对 lua 源码做了少许改造，可以编译一份字节码，跨平台使用。\r\n\r\n## 注意事项\r\n\r\n* 1、如果你做了本文所描述的改动，你的 xLua 将加载不了官方 luac 所编译的字节码；\r\n\r\n* 2、截至 2018/9/14，已知此改法在一个上线一个多月的项目正常运行，但不代表此改法在任何情况都没问题。\r\n\r\n## 操作指南\r\n\r\n### 1、编译 xlua 的 Plugins\r\n\r\n修改各平台编译脚本，在 cmake 命令加上 `-DLUAC_COMPATIBLE_FORMAT=ON` 参数，以 make_win64_lua53.bat 为例，修改后是这样的：\r\n\r\n```bash\r\nmkdir build64 & pushd build64\r\ncmake -DLUAC_COMPATIBLE_FORMAT=ON -G \"Visual Studio 14 2015 Win64\" ..\r\npopd\r\ncmake --build build64 --config Release\r\nmd plugin_lua53\\Plugins\\x86_64\r\ncopy /Y build64\\Release\\xlua.dll plugin_lua53\\Plugins\\x86_64\\xlua.dll\r\npause\r\n```\r\n\r\n用修改后的编译脚本重新编译各平台的 xlua 库，并覆盖原 Plugins 目录下对应文件。\r\n\r\n## 2、编译能生成兼容格式的luac（后续只能用这特定的luac和步骤1的Plugins配套使用）\r\n\r\n到[这里](../../../build/luac/)，如果你想编译 Windows 版本的，执行 make_win64.bat，如果你要编译 Mac 或者 Linux 的，用make_unix.sh\r\n\r\n## 3、加载字节码\r\n\r\n通过 CustomLoader 加载即可，CustomLoader 的详细情况请看教程。这个步骤常犯的错误是用某种Encoding去加载二进制文件，这会破坏lua字节码文件格式。谨记得以二进制方式加载。\r\n\r\n## PS: OpCode修改\r\n\r\n有项目想修改为专用格式的字节码，直接在 lua 源码（目前是lua-5.3.5）上修改后，重新执行上述1、2操作步骤即可。\r\n"
  },
  {
    "path": "Assets/XLua/Doc/compatible_bytecode.md.meta",
    "content": "fileFormatVersion: 2\nguid: 9ace0cd26c96dc6468f5e054d8168b43\ntimeCreated: 1536904183\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/configure.md",
    "content": "# xLua的配置\r\n\r\nxLua所有的配置都支持三种方式：打标签；静态列表；动态列表。\r\n\r\n配置有两必须两建议：\r\n\r\n* 列表方式均必须是static的字段/属性\r\n* 列表方式均必须放到一个static类\r\n* 建议不用标签方式\r\n* 建议列表方式配置放Editor目录（如果是Hotfix配置，而且类位于Assembly-CSharp.dll之外的其它dll，必须放Editor目录）\r\n\r\n**打标签**\r\n\r\nxLua用白名单来指明生成哪些代码，而白名单通过attribute来配置，比如你想从lua调用c#的某个类，希望生成适配代码，你可以为这个类型打一个LuaCallCSharp标签：\r\n\r\n```csharp\r\n\r\n[LuaCallCSharp]\r\npublicclassA\r\n{\r\n\r\n}\r\n\r\n```\r\n\r\n该方式方便，但在il2cpp下会增加不少的代码量，不建议使用。\r\n\r\n**静态列表**\r\n\r\n有时我们无法直接给一个类型打标签，比如系统api，没源码的库，或者实例化的泛化类型，这时你可以在一个静态类里声明一个静态字段，该字段的类型除BlackList和AdditionalProperties之外只要实现了IEnumerable&lt;Type&gt;就可以了（这两个例外后面具体会说），然后为这字段加上标签：\r\n\r\n```csharp\r\n\r\n[LuaCallCSharp]\r\npublic static List<Type> mymodule_lua_call_cs_list = new List<Type>()\r\n{\r\n    typeof(GameObject),\r\n    typeof(Dictionary<string, int>),\r\n};\r\n\r\n```\r\n\r\n这个字段需要放到一个 **静态类** 里头，建议放到 **Editor目录** 。\r\n\r\n**动态列表**\r\n\r\n声明一个静态属性，打上相应的标签即可。\r\n\r\n```csharp\r\n\r\n[Hotfix]\r\npublic static List<Type> by_property\r\n{\r\n    get\r\n    {\r\n        return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\r\n                where type.Namespace == \"XXXX\"\r\n                select type).ToList();\r\n    }\r\n}\r\n\r\n```\r\n\r\nGetter是代码，你可以实现很多效果，比如按名字空间配置，按程序集配置等等。\r\n\r\n这个属性需要放到一个 **静态类** 里头，建议放到 **Editor目录** 。\r\n\r\n### XLua.LuaCallCSharp\r\n\r\n一个C#类型加了这个配置，xLua会生成这个类型的适配代码（包括构造该类型实例，访问其成员属性、方法，静态属性、方法），否则将会尝试用性能较低的反射方式来访问。\r\n\r\n一个类型的扩展方法（Extension Methods）加了这配置，也会生成适配代码并追加到被扩展类型的成员方法上。\r\n\r\nxLua只会生成加了该配置的类型，不会自动生成其父类的适配代码，当访问子类对象的父类方法，如果该父类加了LuaCallCSharp配置，则执行父类的适配代码，否则会尝试用反射来访问。\r\n\r\n反射访问除了性能不佳之外，在il2cpp下还有可能因为代码剪裁而导致无法访问，后者可以通过下面介绍的ReflectionUse标签来避免。\r\n\r\n### XLua.ReflectionUse\r\n\r\n一个C#类型类型加了这个配置，xLua会生成link.xml阻止il2cpp的代码剪裁。\r\n\r\n对于扩展方法，必须加上 `LuaCallCSharp` 或者 `ReflectionUse` 才可以被访问到。\r\n\r\n建议所有要在Lua访问的类型，要么加LuaCallCSharp，要么加上ReflectionUse，这才能够保证在各平台都能正常运行。\r\n\r\n### XLua.DoNotGen\r\n\r\n指明一个类里头的部分函数、字段、属性不生成代码，通过反射访问。\r\n\r\n只能标准 `Dictionary<Type, List<string>>` 的field或者property。key指明的是生效的类，value是一个列表，配置的是不生成代码的函数、字段、属性的名字。\r\n\r\n和ReflectionUse的区别是：1、ReflectionUse指明的是整个类；2、当第一次访问一个函数（字段、属性）时，ReflectionUse会把整个类都wrap，而DoNotGen只wrap该函数（字段、属性），换句话DoNotGen更lazy一些；\r\n\r\n和BlackList的区别是：1、BlackList配了就不能用；2、BlackList能指明某重载函数，DoNotGen不能；\r\n\r\n### XLua.CSharpCallLua\r\n\r\n如果希望把一个lua函数适配到一个C# delegate（一类是C#侧各种回调：UI事件，delegate参数，比如List&lt;T&gt;:ForEach；另外一类场景是通过LuaTable的Get函数指明一个lua函数绑定到一个delegate）。或者把一个lua table适配到一个C# interface，该delegate或者interface需要加上该配置。\r\n\r\n### XLua.GCOptimize\r\n\r\n一个C#纯值类型（注：指的是一个只包含值类型的struct，可以嵌套其它只包含值类型的struct）或者C#枚举值加上了这个配置。xLua会为该类型生成gc优化代码，效果是该值类型在lua和c#间传递不产生（C#）gc alloc，该类型的数组访问也不产生gc。各种无GC的场景，可以参考 `05_Gc` 例子。\r\n\r\n除枚举之外，包含无参构造函数的复杂类型，都会生成lua table到该类型，以及改类型的一维数组的转换代码，这将会优化这个转换的性能，包括更少的gc alloc。\r\n\r\n### XLua.AdditionalProperties\r\n\r\n这个是GCOptimize的扩展配置，有的时候，一些struct喜欢把field做成是私有的，通过property来访问field，这时就需要用到该配置（默认情况下GCOptimize只对public的field打解包）。\r\n\r\n标签方式比较简单，配置方式复杂一点，要求是 `Dictionary<Type, List<string>>` 类型，Dictionary 的 Key 是要生效的类型，Value 是属性名列表。可以参考XLua对几个UnityEngine下值类型的配置，SysGCOptimize类。\r\n\r\n### XLua.BlackList\r\n\r\n如果你不要生成一个类型的一些成员的适配代码，你可以通过这个配置来实现。\r\n\r\n标签方式比较简单，对应的成员上加就可以了。\r\n\r\n由于考虑到有可能需要把重载函数的其中一个重载列入黑名单，配置方式比较复杂，类型是 `List<List<string>>`，对于每个成员，在第一层List有一个条目，第二层List是个string的列表，第一个string是类型的全路径名，第二个string是成员名，如果成员是一个方法，还需要从第三个string开始，把其参数的类型全路径全列出来。\r\n\r\n例如下面是对 GameObject 的一个属性以及FileInfo的一个方法列入黑名单：\r\n\r\n```csharp\r\n\r\n[BlackList]\r\npublic static List<List<string>> BlackList = new List<List<string>>()  {\r\n    new List<string>(){\"UnityEngine.GameObject\", \"networkView\"},\r\n    //new List<string>(){ typeof(UnityEngine.GameObject).FullName, \"networkView\"},\r\n    new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n    //new List<string>(){ typeof(System.IO.FileInfo).FullName, \"GetAccessControl\",typeof(System.Security.AccessControl.AccessControlSections).FullName },\r\n};\r\n\r\n```\r\n\r\n### 下面是生成期配置，必须放到Editor目录下\r\n\r\n### CSObjectWrapEditor.GenPath\r\n\r\n配置生成代码的放置路径，类型是string。默认放在&quot;Assets/XLua/Gen/&quot;下。\r\n\r\n### CSObjectWrapEditor.GenCodeMenu\r\n\r\n该配置用于生成引擎的二次开发，一个无参数函数加了这个标签，在执行&quot;XLua/Generate Code&quot;菜单时会触发这个函数的调用。"
  },
  {
    "path": "Assets/XLua/Doc/configure.md.meta",
    "content": "fileFormatVersion: 2\nguid: 8e8a250c7dbdf6b48ae79313470374dc\ntimeCreated: 1498554474\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/custom_generate.md",
    "content": "## 生成引擎二次开发\r\n\r\nxLua的生成引擎支持二次开发，你可以利用它来生成一些文本类型的文件（比如代码，配置等）。xLua本身的link.xml文件的生成就是一个生成引擎插件做的。其它应用场景，比如生成Lua IDE的自动完成配置文件，都可以用这特性来完成。\r\n\r\n## 总体介绍\r\n\r\n插件需要提供两个东西：1、生成文件的模版；2、一个回调函数，该回调函数接受用户的配置，返回需要注入到模版的数据以及文件的输出流。\r\n\r\n## 模版语法\r\n\r\n模版语法很简单，只有三种元素：\r\n\r\n* eval：语法是<%=exp%>，exp是任意表达式，将计算并以字符串形式输出exp的值；\r\n* code：语法是<% if true then end%>，蓝色部分是任意lua代码，这些代码会执行；\r\n* literal：除eval和code之外其它部分，literal原样输出。\r\n\r\n示例：\r\n\r\n```xml\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\n<linker>\r\n<%ForEachCsList(assembly_infos, function(assembly_info)%>\r\n\t<assembly fullname=\"<%=assembly_info.FullName%>\">\r\n\t    <%ForEachCsList(assembly_info.Types, function(type)\r\n\t\t%><type fullname=\"<%=type:ToString()%>\" preserve=\"all\"/>\r\n\t\t<%end)%>\r\n\t</assembly>\r\n<%end)%>\r\n</linker>\r\n```\r\n\r\nTemplateCommon有一些预定义的函数可以使用，比如ForEachCsList，可以搜索下工程的TemplateCommon.lua.txt看下有那些函数可以用，就普通的lua而已，你自己写一套也可以。\r\n\r\n## API\r\n\r\n```csharp\r\npublic static void CSObjectWrapEditor.Generator.CustomGen(string template_src, GetTasks get_tasks)\r\n```\r\n\r\n* template_src ： 模版的源码；\r\n* get_tasks    ： 回调函数，类型是GetTasks，用来接受用户的配置，返回需要注入到模版的数据以及文件的输出流；\r\n\r\n```csharp\r\npublic delegate IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg);\r\n```\r\n\r\n* lua_env      ： LuaEnv对象，因为返回的模版数据需要放到LuaTable，需要用到LuaEnv.NewTable；\r\n* user_cfg     ： 用户的配置；\r\n* return       ： 返回值中，CustomGenTask代表的是一个生成文件，而IEnumerable类型表示同一个模版可以生成多个文件；\r\n\r\n```csharp\r\npublic struct UserConfig\r\n{\r\n    public IEnumerable<Type> LuaCallCSharp;\r\n    public IEnumerable<Type> CSharpCallLua;\r\n    public IEnumerable<Type> ReflectionUse;\r\n}\r\n```\r\n\r\n```csharp\r\npublic struct CustomGenTask\r\n{\r\n    public LuaTable Data;\r\n    public TextWriter Output;\r\n}\r\n```\r\n\r\n示例：\r\n\r\n```csharp\r\npublic static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg)\r\n{\r\n    LuaTable data = lua_env.NewTable();\r\n    var assembly_infos = (from type in user_cfg.ReflectionUse\r\n                          group type by type.Assembly.GetName().Name into assembly_info\r\n                          select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList();\r\n    data.Set(\"assembly_infos\", assembly_infos);\r\n\r\n    yield return new CustomGenTask\r\n    {\r\n        Data = data,\r\n        Output = new StreamWriter(GeneratorConfig.common_path + \"/link.xml\",\r\n        false, Encoding.UTF8)\r\n    };\r\n}\r\n```\r\n\r\n* 这里只生成一个文件，故只返回一个CustomGenTask；\r\n* data就是模版要使用的数据，这里塞了一个assembly_infos字段，这个字段如何使用可以回头看看模版部分；\r\n\r\n## 标签\r\n\r\n一般来说你可以通过MenuItem开一个菜单来执行触发自定义生成操作，但有时你希望生成操作直接由xLua的“Generate Code”菜单触发，你就需要用到CSObjectWrapEditor.GenCodeMenu\r\n\r\n示例：\r\n\r\n```csharp\r\n[GenCodeMenu]//加到Generate Code菜单里头\r\npublic static void GenLinkXml()\r\n{\r\n    Generator.CustomGen(ScriptableObject.CreateInstance<LinkXmlGen>().Template.text, GetTasks);\r\n}\r\n```\r\n\r\n\r\nps：以上所有相关代码都在XLua\\Src\\Editor\\LinkXmlGen目录下，也正是文章开头说的link.xml的生成功能的实现。\r\n"
  },
  {
    "path": "Assets/XLua/Doc/custom_generate.md.meta",
    "content": "fileFormatVersion: 2\nguid: 6436d38981b6f5a4d8a2255ea3145ed1\ntimeCreated: 1486519283\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/faq.md",
    "content": "# FAQ\r\n\r\n## xLua发布包怎么用？\r\n\r\nxLua目前以zip包形式发布，在工程目录下解压即可。\r\n\r\n## xLua可以放别的目录吗？\r\n\r\n可以，但生成代码目录需要配置一下（默认放Assets\\XLua\\Gen目录），具体可以看《XLua的配置.doc》的GenPath配置介绍。\r\n\r\n更改目录要注意的是：生成代码和xLua核心代码必须在同一程序集。如果你要用热补丁特性，xLua核心代码必须在Assembly-CSharp程序集。\r\n\r\n## xLua的配置\r\n\r\n如果你用的是lua编程，你可能需要把一些频繁访问的类配置到LuaCallCSharp，这些类的成员如果有条件编译（大多数情况下是UNITY_EDITOR）的话，你需要通过BlackList配置排除；如果你需要通过delegate回调到lua的地方，得把这些delegate配置到CSharpCallLua。\r\n\r\n如果你用的是热补丁，你需要把要注入的代码加到Hotfix列表；如果你需要通过delegate回调到lua的地方，也得把这些delegate配置到CSharpCallLua。\r\n\r\nxLua提供了强大的动态配置，让你可以结合反射实现任意的自动化配置，动态配置介绍看[这里](configure.md)。xLua希望你能根据自身项目的需求自行配置，同时为了方便部分对反射api了解不够的童鞋，xLua也针对上面两者方式分别写了参考配置：[ExampleConfig.cs](../Editor/ExampleConfig.cs)，直接打开相应部分的注释即可使用。\r\n\r\n## lua源码只能以txt后缀？\r\n\r\n什么后缀都可以。\r\n\r\n如果你想以TextAsset打包到安装包（比如放到Resources目录），Unity不认lua后缀，这是Unity的规则。\r\n\r\n如果你不打包到安装包，就没有后缀的限制：比如自行下载到某个目录（这也是热更的正确姿势），然后通过CustomLoader或者设置package.path去读这个目录。\r\n\r\n那为啥xLua本身带的lua源码（包括示例）为什么都是txt结尾呢？因为xLua本身就一个库，不含下载功能，也不方便运行时去某个地方下载代码，通过TextAsset是较简单的方式。\r\n\r\n## 编辑器(或非il2cpp的android)下运行正常，ios下运行调用某函数报“attempt to call a nil value”\r\n\r\nil2cpp默认会对诸如引擎、c#系统api，第三方dll等等进行代码剪裁。简单来说就是这些地方的函数如果你C#代码没访问到的就不编译到你最终发布包。\r\n\r\n解决办法：增加引用（比如配置到LuaCallCSharp，或者你自己C#代码增加那函数的访问），或者通过link.xml配置（当配置了ReflectionUse后，xlua会自动帮你配置到link.xml）告诉il2cpp别剪裁某类型。\r\n\r\n## Unity 2018及以上版本兼容性问题解决\r\n\r\n2.1.14前的版本都建议先升级到2.1.14，升级后，还有如下两个使用注意事项：\r\n\r\n1、默认配置不生成代码运行会报错\r\n\r\n这是因为Api Compatibility Level设置为.NET Standard 2.0，而.NET Standard 2.0不支持emit导致的。\r\n\r\n解决方案：平时开发Api Compatibility Level设置为.NET 4.x，就能支持编辑器不生成代码开发。发布手机版本时，按Unity官方的建议，可配置为.NET Standard 2.0，包会更小些。\r\n\r\n2、生成代码后，一些系统类型的生成代码会报一些方法不存在。\r\n\r\n据研究表明，Unity 2018设置.NET 4.X Equivalent的话，其运行和编译用的库不一致，前者比后者多一些API。\r\n\r\n运行用的是：unity安装目录\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\unityjit\\mscorlib.dll\r\n\r\n编译链接的是：unity安装目录\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\4.7.1-api\\mscorlib.dll\r\n\r\n解决办法：用黑名单排除报错方法即可。不过2019年8月6号以前的版本的黑名单配置对泛型不友好，要一个个泛型实例的配置（比如，Dictionary<int, int>和Dictionary<float, int>要分别配置），而目前发现该问题主要出在泛型Dictionary上。可以更新到2019年8月6号之后的版本，该版本支持配置一个过滤器对泛型方法过滤。这里有对unity 2018的Dictionary的[针对性配置](https://github.com/Tencent/xLua/blob/master/Assets/XLua/Editor/ExampleConfig.cs#L277)，直接拷贝使用，如果碰到其它泛型也有多出来的方法，参考Dictionary进行配置。\r\n\r\n## Plugins源码在哪里可以找到，怎么使用？\r\n\r\nPlugins源码位于xLua_Project_Root/build下。\r\n\r\n源码编译依赖cmake，安装cmake后执行make_xxxx_yyyy.zz即可，xxxx代表平台，比如ios，android等，yyyy是要集成的虚拟机，有lua53和luajit两者，zz是后缀，windows下是bat，其它平台是sh。\r\n\r\nwindows编译依赖Visual Studio 2015。\r\n\r\nandroid编译在linux下执行，依赖NDK，并且需要把脚本中ANDROID_NDK指向NDK的安装目录。\r\n\r\nios和osx需要在mac下编译。\r\n\r\n## 报类似“xlua.access, no field __Hitfix0_Update”的错误怎么解决？\r\n\r\n按[Hotfix操作指南](hotfix.md)一步步操作，以及注意事项。确保上述步骤完成后，可尝试使用[解决方案](https://github.com/Tencent/xLua/issues/850)。\r\n\r\n出现这报错，肯定是这个导致的：最终包的这个方法（函数）没注入。\r\n\r\n但造成“最终包的这个方法（函数）没注入”的原因会有很多：比如没按文档操作，注入失败，比如Hotfix列表漏了这个类，比如你的打包脚本在注入后，又触发了重新编译，覆盖了注入结果。。。\r\n\r\n统一的解决方式是找出并解决导致“最终包的这个方法（函数）没注入”的具体原因。\r\n\r\n## visual studio 2017下编译UWP原生库\r\n\r\nvisual studio 2017需要安装：1、“工作负载”下的“通用Window平台开发”；2、“单个组件”下的“用于ARM的Visual C++编译器和库”、“用于ARM64的Visual C++编译器和库”、“是用于ARM64的C++通用Windows平台工具”\r\n\r\n## visual studio 2015下编译原生库\r\n\r\n把build\\vs2015下的bat文件拷贝到build目录，覆盖同名文件\r\n\r\n## 报“please install the Tools”\r\n\r\n没有把Tools安装到Assets平级目录，安装包，或者master下都能找到这个目录。\r\n\r\n## 报“This delegate/interface must add to CSharpCallLua : XXX”异常怎么解决？\r\n\r\n在编辑器下xLua不生成代码都可以运行，出现这种提示，要么是该类型没加CSharpCallLua，要么是加之前生成过代码，没重新执行生成。\r\n\r\n解决办法，确认XXX（类型名）加上CSharpCallLua后，清除代码后运行。\r\n\r\n如果编辑器下没问题，发布到手机报这错，表示你发布前没生成代码（执行“XLua/Generate Code”）。\r\n\r\n如果你Unity版本大于或等于2018，看下前面兼容性的章节。\r\n\r\n## unity5.5以上执行\"XLua/Hotfix Inject In Editor\"菜单会提示\"WARNING: The runtime version supported by this application is unavailable.\"\r\n\r\n这是因为注入工具是用.net3.5编译，而unity5.5意思MonoBleedingEdge的mono环境并没3.5支持导致的，不过一般而言都向下兼容，目前为止也没发现该warning带来什么问题。\r\n\r\n可能有人发现定义INJECT_WITHOUT_TOOL用内嵌模式会没有该warning，但问题是这模式是调试问题用的，不建议使用，因为可能会有一些库冲突问题。\r\n\r\n## hotfix下怎么触发一个event\r\n\r\n首先通过xlua.private_accessible开启私有成员访问。\r\n\r\n跟着通过对象的\"&事件名\"字段调用delegate，例如self\\['&MyEvent'\\]()，其中MyEvent是事件名。\r\n\r\n## 怎么对Unity Coroutine的实现函数打补丁？\r\n\r\n见[Hotfix操作指南](hotfix.md)相应章节。\r\n\r\n## 支持NGUI（或者UGUI/DOTween等等）么？\r\n\r\n支持，xLua最主要的特性是让你原来用C#写的地方可以换成用lua写，你C#能用的插件，基本都能用。\r\n\r\n## 如果需要调试，CustomLoader的filepath参数该如何处理？\r\n\r\nlua里头调用require 'a.b'时，CustomLoader会被调用，并传入字符串\"a.b\"，你需要理解这字符串，（从文件/内存/网络等）加载好lua文件，返回两个东西，第一个是调试器可以理解的路径，比如：a/b.lua，这个通过设置ref类型的filepath参数返回，第二个是UTF8格式的源码的字节流（byte[]），通过返回值返回。\r\n\r\n## 什么是生成代码？\r\n\r\nxLua支持的lua和C#间交互技术之一，这种技术通过生成两者间的适配代码来实现交互，性能较好，是推荐的方式。\r\n\r\n另一种交互技术是反射，这种方式对安装包的影响更少，可以在性能要求不高或者对安装包大小很敏感的场景下使用。\r\n\r\n## 改了接口后，之前生成的代码出现错误怎么办？\r\n\r\n清除掉生成代码（执行“Clear Generated Code”菜单，如果你重启过，会找不到这个菜单，这时你可以手动删除整个生成代码目录），等编译完成后重新生成。\r\n\r\n## 应该什么时候生成代码？\r\n\r\n开发期不建议生成代码，可以避免很多由于不一致导致的编译失败，以及生成代码本身的编译等待。\r\n\r\nbuild手机版本前必须执行生成代码，建议做成自动化的。\r\n\r\n做性能调优，性能测试前必须执行生成代码，因为生成和不生成性能的区别还是很大的。\r\n\r\n## CS名字空间下有所有C# API是不是很占内存？\r\n\r\n由于用了lazyload，这个“有”只是个虚拟的概念，比如UnityEngine.GameObject，是访问第一次CS.UnityEngine.GameObject或者第一个实例往lua传送才加载该类型方法，属性等。\r\n\r\n## LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？\r\n\r\n看调用者和被调用者，比如要在lua调用C#的GameObject.Find函数，或者调用gameobject的实例方法，属性等，GameObject类要加LuaCallSharp，而想把一个lua函数挂到UI回调，这是调用者是C#，被调用的是一个lua函数，所以回调声明的delegate要加CSharpCallLua。\r\n\r\n有时会比较迷惑人，比如List<int>.Find(Predicate<int> match)的调用，List<int>当然是加LuaCallSharp，而Predicate<int>却要加CSharpCallLua，因为match的调用者在C#，被调用的是一个lua函数。\r\n\r\n更无脑一点的方式是看到“This delegate/interface must add to CSharpCallLua : XXX”，就把XXX加到CSharpCallLua即可。\r\n\r\n## 值类型传递会有gc alloc么？\r\n\r\n如果你使用的是delegate调用lua函数，或者用LuaTable、LuaFunction的无gc接口，或者数组的话，以下值类型都是没gc的：\r\n\r\n1、所有的基本值类型（所有整数，所有浮点数，decimal）；\r\n\r\n2、所有的枚举类型；\r\n\r\n3、字段只包含值类型的struct，可嵌套其它只包含值类型struct；\r\n\r\n其中2、3需要把该类型加到GCOptimize。\r\n\r\n## 反射在ios下可用吗？\r\n\r\nios下的限制有两个：1、没有jit；2、代码剪裁（stripping）；\r\n\r\n对于C#通过delegate或者interface调用lua，如果不生成代码是用反射的emit，这依赖jit，所以这目前只在编辑器可用。\r\n\r\n对于lua调用C#，主要会被代码剪裁影响，这时你可以配置ReflectionUse（不要配LuaCallSharp），执行“Generate Code”，这时不会对该类生成封装代码，而是生成link.xml把该类配置为不剪裁。\r\n\r\n简而言之，除了CSharpCallLua是必须的（这类生成代码往往不多），LuaCallSharp生成都可以改为用反射。\r\n\r\n## 支持泛型方法的调用么？\r\n\r\n1、泛型约束到某个基类的支持，看例子：(../Examples/09_GenericMethod/)\r\n\r\n2、没有泛型约束的建议封装为非泛型使用\r\n如果是静态方法，可以自己写个封装来实例化泛型方法。\r\n\r\n如果是成员方法，xLua支持扩展方法，你可以添加一个扩展方法来实例化泛型方法。该扩展方法使用起来就和普通成员方法一样。\r\n\r\n```csharp\r\n// C#\r\npublic static Button GetButton(this GameObject go)\r\n{\r\n    return go.GetComponent<Button>();\r\n}\r\n```\r\n\r\n```lua\r\n-- lua\r\nlocal go = CS.UnityEngine.GameObject.Find(\"button\")\r\ngo:GetButton().onClick:AddListener(function()\r\n    print('onClick')\r\nend)\r\n```\r\n\r\n3、如果xlua版本大于2.1.12的话，新增反射调用泛型方法的支持（有一定的限制，看后面的说明），比如对于这么个C#类型：\r\n\r\n```csharp\r\npublic class GetGenericMethodTest\r\n{\r\n    int a = 100;\r\n    public int Foo<T1, T2>(T1 p1, T2 p2)\r\n    {\r\n        Debug.Log(typeof(T1));\r\n        Debug.Log(typeof(T2));\r\n        Debug.Log(p1);\r\n        Debug.Log(p2);\r\n        return a;\r\n    }\r\n\r\n    public static void Bar<T1, T2>(T1 p1, T2 p2)\r\n    {\r\n        Debug.Log(typeof(T1));\r\n        Debug.Log(typeof(T2));\r\n        Debug.Log(p1);\r\n        Debug.Log(p2);\r\n    }\r\n}\r\n```\r\n\r\n在lua那这么调用：\r\n\r\n```lua\r\nlocal foo_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Foo')\r\nlocal bar_generic = xlua.get_generic_method(CS.GetGenericMethodTest, 'Bar')\r\n\r\nlocal foo = foo_generic(CS.System.Int32, CS.System.Double)\r\nlocal bar = bar_generic(CS.System.Double, CS.UnityEngine.GameObject)\r\n\r\n-- call instance method\r\nlocal o = CS.GetGenericMethodTest()\r\nlocal ret = foo(o, 1, 2)\r\nprint(ret)\r\n\r\n-- call static method\r\nbar(2, nil)\r\n```\r\n\r\n使用限制，只有下面几种情况可以：\r\n\r\n* mono下可以\r\n* il2cpp下，如果泛型参数是引用类型可以\r\n* il2cpp下，如果泛型参数是值类型，C#那有用同样的泛型参数调用过（如果是hotfix场景下，一般在C#那会用同样的泛型参数调用过，所以在hotfix功能下一般都可用）\r\n\r\n\r\n## 支持lua调用C#重载函数吗？\r\n\r\n支持，但没有C#端支持的那么完善，比如重载方法void Foo(int a)和void Foo(short a)，由于int和short都对应lua的number，是没法根据参数判断调用的是哪个重载。这时你可以借助扩展方法来为其中一个起一个别名。\r\n\r\n## 编辑器下运行正常，打包的时候生成代码报“没有某方法/属性/字段定义”怎么办？\r\n\r\n往往是由于该方法/属性/字段是扩在条件编译里头，只在UNITY_EDITOR下有效，这是可以通过把这方法/属性/字段加到黑名单来解决，加了之后要等编译完成后重新执行代码生成。\r\n\r\n## this[string field]或者this[object field]操作符重载为什么在lua无法访问？（比如Dictionary\\<string, xxx\\>, Dictionary\\<object, xxx\\>在lua中无法通过dic['abc']或者dic.abc检索值）\r\n\r\n因为：1、这个特性会导致基类定义的方法、属性、字段等无法访问（比如Animation无法访问到GetComponent方法）；2、key为当前类某方法、属性、字段的名字的数据无法检索，比如Dictionary类型，dic['TryGetValue']返回的是一个函数，指向Dictionary的TryGetValue方法。\r\n\r\n如果你的版本大于2.1.11，可以用get_Item来获取值，用set_Item来设置值。要注意只有this[string field]或者this[object field]才有这两个替代api，其它类型的key是没有的。\r\n\r\n```lua\r\ndic:set_Item('a', 1)\r\ndic:set_Item('b', 2)\r\nprint(dic:get_Item('a'))\r\nprint(dic:get_Item('b'))\r\n```\r\n\r\n如果你的版本小于或等于2.1.11，建议直接方法该操作符的等效方法，比如Dictionary的TryGetValue，如果该方法没有提供，可以在C#那通过Extension method封装一个使用。\r\n\r\n## 有的Unity对象，在C#为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject\r\n\r\n其实那C#对象并不为null，是UnityEngine.Object重载的==操作符，当一个对象被Destroy，未初始化等情况，obj == null返回true，但这C#对象并不为null，可以通过System.Object.ReferenceEquals(null, obj)来验证下。\r\n\r\n对应这种情况，可以为UnityEngine.Object写一个扩展方法：\r\n\r\n```csharp\r\n[LuaCallCSharp]\r\n[ReflectionUse]\r\npublic static class UnityEngineObjectExtention\r\n{\r\n    public static bool IsNull(this UnityEngine.Object o) // 或者名字叫IsDestroyed等等\r\n    {\r\n        return o == null;\r\n    }\r\n}\r\n```\r\n\r\n然后在lua那你对所有UnityEngine.Object实例都使用IsNull判断\r\n\r\n```lua\r\nprint(go:GetComponent('Animator'):IsNull())\r\n```\r\n\r\n## 泛型实例怎么构造\r\n\r\n涉及的类型都在mscorlib，Assembly-CSharp程序集的话，泛型实例的构造和普通类型是一样的，都是CS.namespace.typename()，可能比较特殊的是typename的表达，泛型实例的typename的表达包含了标识符非法符号，最后一部分要换成[\"typename\"]，以List<string>为例\r\n\r\n```lua\r\nlocal lst = CS.System.Collections.Generic[\"List`1[System.String]\"]()\r\n```\r\n\r\n如果某个泛型实例的typename不确定，可以在C#测打印下typeof(不确定的类型).ToString()\r\n\r\n如果涉及mscorlib，Assembly-CSharp程序集之外的类型的话，可以用C#的反射来做：\r\n\r\n```lua\r\nlocal dic = CS.System.Activator.CreateInstance(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UnityEngine.Vector3, UnityEngine]],mscorlib'))\r\ndic:Add('a', CS.UnityEngine.Vector3(1, 2, 3))\r\nprint(dic:TryGetValue('a'))\r\n```\r\n\r\n如果你的xLua版本大于v2.1.12，将会有更漂亮的表达方式\r\n\r\n```lua\r\n-- local List_String = CS.System.Collections.Generic['List<>'](CS.System.String) -- another way\r\nlocal List_String = CS.System.Collections.Generic.List(CS.System.String)\r\nlocal lst = List_String()\r\n\r\nlocal Dictionary_String_Vector3 = CS.System.Collections.Generic.Dictionary(CS.System.String, CS.UnityEngine.Vector3)\r\nlocal dic = Dictionary_String_Vector3()\r\ndic:Add('a', CS.UnityEngine.Vector3(1, 2, 3))\r\nprint(dic:TryGetValue('a'))\r\n```\r\n\r\n\r\n## 调用LuaEnv.Dispose时，报“try to dispose a LuaEnv with C# callback!”错是什么原因？\r\n\r\n这是由于C#还存在指向lua虚拟机里头某个函数的delegate，为了防止业务在虚拟机释放后调用这些无效（因为其引用的lua函数所在虚拟机都释放了）delegate导致的异常甚至崩溃，做了这个检查。\r\n\r\n怎么解决？释放这些delegate即可，所谓释放，在C#中，就是没有引用：\r\n\r\n你是在C#通过LuaTable.Get获取并保存到对象成员，赋值该成员为null；\r\n\r\n你是在lua那把lua函数注册到一些事件事件回调，反注册这些回调；\r\n\r\n如果你是通过xlua.hotfix(class, method, func)注入到C#，则通过xlua.hotfix(class, method, nil)删除；\r\n\r\n要注意以上操作在Dispose之前完成。\r\n\r\nxlua提供了一个工具函数来帮助你找到被C#引用着的lua函数，util.print_func_ref_by_csharp，使用很简单，执行如下lua代码：\r\n\r\n```lua\r\nlocal util = require 'xlua.util'\r\nutil.print_func_ref_by_csharp()\r\n```\r\n\r\n可以看到控制台有类似这样的输出，下面第一行表示有一个在main.lua的第2行定义的函数被C#引用着\r\n\r\n```bash\r\nLUA: main.lua:2\r\nLUA: main.lua:13\r\n```\r\n\r\n## 调用LuaEnv.Dispose崩溃\r\n\r\n很可能是这个Dispose操作是由lua那驱动执行，相当于在lua执行的过程中把lua虚拟机给释放了，改为只由C#执行即可。\r\n\r\n## C#参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int\r\n\r\n看[例子11](../Examples/11_RawObject/RawObjectTest.cs)\r\n\r\n\r\n## 如何做到先执行原来的C#逻辑，然后再执行补丁\r\n\r\n用util.hotfix_ex，可以调用原先的C#逻辑\r\n\r\n```lua\r\nlocal util = require 'xlua.util'\r\nutil.hotfix_ex(CS.HotfixTest, 'Add', function(self, a, b)\r\n   local org_sum = self:Add(a, b)\r\n   print('org_sum', org_sum)\r\n   return a + b\r\nend)\r\n```\r\n\r\n## 怎么把C#的函数赋值给一个委托字段\r\n\r\n2.1.8及之前版本，你把C#函数当成一个lua函数即可，性能会略低，因为委托调用时先通过Birdage适配代码调用lua，然后lua再调用回C#。\r\n\r\n2.1.9 xlua.util新增createdelegate函数\r\n\r\n比如如下C#代码\r\n\r\n```csharp\r\npublic class TestClass\r\n{\r\n    public void Foo(int a)\r\n    { \r\n    }\r\n\t\r\n    public static void SFoo(int a)\r\n    {\r\n    }\r\n｝\r\npublic delegate void TestDelegate(int a);\r\n```\r\n\r\n你可以指明用Foo函数创建一个TestDelegate实例\r\n```lua\r\nlocal util = require 'xlua.util'\r\n\r\nlocal d1 = util.createdelegate(CS.TestDelegate, obj, CS.TestClass, 'Foo', {typeof(CS.System.Int32)}) --由于Foo是实例方法，所以参数2需要传TestClass实例\r\nlocal d2 = util.createdelegate(CS.TestDelegate, nil, CS.TestClass, 'SFoo', {typeof(CS.System.Int32)})\r\n\r\nobj_has_TestDelegate.field = d1 + d2 --到时调用field的时候将会触发Foo和SFoo，这不会经过Lua适配\r\n\r\n```\r\n\r\n## 为什么有时Lua错误直接中断了而没错误信息？\r\n\r\n一般两种情况：\r\n\r\n1、你的错误代码用协程跑，而标准的lua，协程出错是通过resume返回值来表示，可以查阅相关的lua官方文档。如果你希望协程出错直接抛异常，可以在你的resume调用那加个assert。\r\n\r\n把类似下面的代码：\r\n\r\n```lua\r\ncoroutine.resume(co, ...)\r\n```\r\n\r\n改为：\r\n\r\n```lua\r\nassert(coroutine.resume(co, ...))\r\n```\r\n\r\n2、上层catch后，不打印\r\n\r\n比如某些sdk，在回调业务时，try-catch后把异常吃了。\r\n\r\n## 重载含糊如何处理\r\n\r\n比如由于忽略out参数导致的Physics.Raycast其中一个重载调用不了，比如short，int无法区分的问题。\r\n\r\n首先out参数导致重载含糊比较少见，目前只反馈（截至2017-9-22）过Physics.Raycast一个，建议通过自行封装来解决（short，int这种情况也适用）：静态函数的直接封装个另外名字的，如果是成员方法则通过Extension method来封装。\r\n\r\n如果是hotfix场景，我们之前并没有提前封装，又希望调用指定重载怎么办？\r\n\r\n可以通过xlua.tofunction结合反射来处理，xlua.tofunction输入一个MethodBase对象，返回一个lua函数。比如下面的C#代码：\r\n\r\n```csharp\r\nclass TestOverload\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        Debug.Log(\"int version\");\r\n        return a + b;\r\n    }\r\n\r\n    public short Add(short a, short b)\r\n    {\r\n        Debug.Log(\"short version\");\r\n        return (short)(a + b);\r\n    }\r\n}\r\n```\r\n\r\n我们可以这么调用指定重载：\r\n\r\n```lua\r\nlocal m1 = typeof(CS.TestOverload):GetMethod('Add', {typeof(CS.System.Int16), typeof(CS.System.Int16)})\r\nlocal m2 = typeof(CS.TestOverload):GetMethod('Add', {typeof(CS.System.Int32), typeof(CS.System.Int32)})\r\nlocal f1 = xlua.tofunction(m1) --切记对于同一个MethodBase，只tofunction一次，然后重复使用\r\nlocal f2 = xlua.tofunction(m2)\r\n\r\nlocal obj = CS.TestOverload()\r\n\r\nf1(obj, 1, 2) --调用short版本，成员方法，所以要传对象，静态方法则不需要\r\nf2(obj, 1, 2) --调用int版本\r\n```\r\n\r\n注意：xlua.tofunction由于使用不太方便，以及使用了反射，所以建议做作为临时方案，尽量用封装的方法来解决。\r\n\r\n## 支持interface扩展方法么？\r\n\r\n考虑到生成代码量，不支持通过obj:ExtentionMethod()的方式去调用，支持通过静态方法的方式去调用CS.ExtentionClass.ExtentionMethod(obj)\r\n\r\n## 如何把xLua的Wrap生成操作集成到我项目的自动打包流程中？\r\n\r\n可以参考[例子13](../Examples/13_BuildFromCLI/)，通过命令行调用Unity自定义类方法出包。\r\n\r\n## 使用热补丁特性，打手机版本时报DelegatesGensBridge.cs引用了不存在的类（比如仅编辑器使用的类型），应该如何处理？\r\n\r\n这是因为Hotfix列表里头配置的类型（假设是类型A），对这些不存在的类型（假设是类型B）引用。找到这种类型，从Hotfix配置列表中排除（注意，排除的类型A，而不是类型B）。\r\n\r\n如何找？VS中选中报不存在的类型，然后“Find All References”找到引用了这个类型的所有方法、属性。。这些方法、属性等等所在的类型就是你要排除的类型。\r\n\r\n## 如何加载字节码\r\n\r\n用luac编译后直接加载即可。\r\n\r\n要注意默认lua字节码是区分32位和64位的，32位luac生成的字节码只能在32位虚拟机里头跑，可以按《[通用字节码](compatible_bytecode.md)》一文处理下。\r\n\r\n## lua持有的c#对象怎么释放\r\n\r\n达成下面两点即可释放：\r\n\r\n* 1、lua所有对该C#对象释放\r\n* 2、lua完成一次gc周期\r\n\r\n貌似所有gc都是上述条件，但对于lua要特别说明下第二点，lua不像C#那样会后台启动一个gc线程在做垃圾回收，而是把gc拆分成小步骤插入到有内存分配。\r\n\r\n所以注意一点：你没在运行lua代码，或者lua代码运行并未分配内存，你怎么等也不会有内存回收。\r\n\r\n默认gc配置，lua要到达上次内存回收完成时内存占用的两倍才开启一轮新的gc周期，举例上次回收完毕20M内存，那么下次要等到40M才开始一轮gc周期。\r\n\r\n按xLua的设计，一个C#对象引用传递到lua，仅让lua增加4字节内存（然而这可能是在C#侧内存占用很大的对象，比如贴图），可以看到通过持有C#引用要达成默认配置开启gc周期条件是比较困难的。\r\n\r\n这时可以这么干：\r\n\r\n* 1、设置GcPause，让gc更快开启，默认200表示2倍上次回收内存时开启，coco2dx设置为100，表示完成一趟gc后马上开启下一趟，另外也可以设置GcStepmul来加快gc回收速度，默认是200表示回收比内存分配快两倍，GcStepmul在coco2dx设置为5000\r\n* 2、可以在场景切换之类对于性能要求不高的地方加入全量gc调用（通过LuaEnv.FullGc或者在lua里头调用collectgarbage('collect')都可以）。\r\n\r\n## 多线程下莫名crash怎么解决\r\n\r\n多线程使用需要在（Player Setting/Scripting Define Symbols）下添加THREAD_SAFE宏。\r\n\r\n常见的不明显的多线程的场景，比如c#异步socket，对象析构函数等。\r\n\r\n## maOS10.15以上,启动unity的时候提示xlua.bundle损坏,移动到废纸篓\r\n\r\n执行\r\n\r\n```bash\r\nsudo xattr -r -d com.apple.quarantine xlua.bundle\r\n```\r\n"
  },
  {
    "path": "Assets/XLua/Doc/faq.md.meta",
    "content": "fileFormatVersion: 2\nguid: 13645b7c8597d7840adaff65764ad40f\ntimeCreated: 1481765808\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/features.md",
    "content": "# 特性\r\n\r\n## 总体\r\n\r\n* Lua虚拟机支持\r\n  * Lua5.3\r\n  * Luajit2.1\r\n* Unity3D版本支持\r\n  * 各版本均支持\r\n* 平台支持\r\n  * windows 64/32\r\n  * android\r\n  * ios 64/32/bitcode\r\n  * osx\r\n  * uwp\r\n  * webgl\r\n* 互访技术\r\n  * 生成适配代码\r\n  * 反射\r\n* 易用性\r\n  * 解压即可用\r\n  * 开发期无需生成代码\r\n  * 生成代码和反射间可无缝切换\r\n  * 更简单的无GC api\r\n  * 菜单简单易懂\r\n  * 配置可以多份，按模块划分，也可以直接在目标类型上打Attribute标签\r\n  * 自动生成link.xml防止代码剪裁\r\n  * Plugins部分采用cmake编译，更简单\r\n  * 核心代码不依赖生成代码，可以随时删除生成目录\r\n* 性能\r\n  * Lazyload技术，避免用不上的类型的开销\r\n  * lua函数映射到c# delegate，lua table映射到interface，可实现接口层面无C# gc alloc开销\r\n  * 所有基本值类型，所有枚举，字段都是值类型的struct，在Lua和C#间传递无C# gc alloc\r\n  * LuaTable，LuaFunction提供无gc访问接口\r\n  * 通过代码生成期的静态分析，生成最优代码\r\n  * 支持C#和Lua间指针传递\r\n  * 自动解除已经Destroy的UnityEngine.Object的引用\r\n* 扩展性\r\n  * 不用改代码就可以加入Lua第三方扩展\r\n  * 生成引擎提供接口做二次开发\r\n \r\n## 支持为如下C#实现打补丁\r\n\r\n* 构造函数\r\n* 析构函数\r\n* 成员函数\r\n* 静态函数\r\n* 泛化函数\r\n* 操作符重载\r\n* 成员属性\r\n* 静态属性\r\n* 事件\r\n\r\n## Lua代码加载\r\n\r\n* 加载字符串\r\n  * 支持加载后立即执行\r\n  * 支持加载后返回一个delegate或者LuaFunction，调用delegate或者LuaFunction后可传脚本参数\r\n* Resources目录的文件\r\n  * 直接require\r\n* 自定义loader\r\n  * Lua里头require时触发\r\n  * require参数透传给loader，loader读取Lua代码返回\r\n* Lua原有的方式\r\n  * Lua原有的方式都保留\r\n\r\n## Lua调用C#\r\n\r\n* 创建C#对象\r\n* C#静态属性，字段\r\n* C#静态方法\r\n* C#成员属性，字段\r\n* C#成员方法\r\n* C#继承\r\n  * 子类对象可以直接调用父类的方法，访问父类属性\r\n  * 子类模块可以直接调用父类的静态方法，静态属性\r\n* 扩展方法（Extension methods）\r\n  * 就像普通成员方法一样使用\r\n* 参数的输入输出属性（out，ref）\r\n  * out对应一个lua返回值\r\n  * ref对应一个lua参数以及一个lua返回值\r\n* 函数重载\r\n  * 支持重载\r\n  * 由于lua数据类型远比C#要少，会出现无法判断的情况，可通过扩展方法来来调用。\r\n* 操作符重载\r\n  * 支持的操作符：+，-，*，/，==，一元-，<，<=， %，[]\r\n  * 其它操作符可以借助扩展方法调用\r\n* 参数默认值\r\n  * C#参数有默认值，在lua可以不传\r\n* 可变参数\r\n  * 在对应可变参数部分，直接输入一个个参数即可，不需要把这些参数扩到一个数组里头\r\n* 泛化方法调用\r\n  * 静态方法可以自行封装使用\r\n  * 成员函数可通过扩展方法封装使用\r\n* 枚举类型\r\n  * 数字或字符串到枚举的转换\r\n* delegate\r\n  * 调用一个C# delegate\r\n  * +操作符\r\n  * -操作符\r\n  * 把一个lua函数作为一个c# delegate传递给c#\r\n* event\r\n  * 增加事件回调\r\n  * 移除事件回调\r\n* 64位整数\r\n  * 传递无gc而且无精度损失\r\n  * lua53下使用原生64位支持\r\n  * 可以和number运算\r\n  * 以java的方式支持无符号64位整数\r\n* table的自动转换到C#复杂类型\r\n  * obj.complexField = {a = 1, b = {c = 1}}，obj是一个C#对象，complexField是两层嵌套的struct或者class\r\n* typeof\r\n  * 对应C#的typeof操作符，返回Type对象\r\n* lua侧直接clone\r\n* decimal\r\n  * 传递无gc而且无精度损失\r\n\r\n## C#调用Lua\r\n\r\n* 调用Lua函数\r\n  * 以delegate方式调用Lua函数\r\n  * 以LuaFunction调用lua函数\r\n* 访问Lua的table\r\n  * LuaTable的泛化Get/Set接口，调用无gc，可指明Key，Value的类型\r\n  * 用标注了CSharpCallLua的interface访问\r\n  * 值拷贝到struct，class\r\n \r\n## Lua虚拟机\r\n\r\n* 虚拟机gc参数读取及设置\r\n\r\n## 工具链\r\n\r\n* Lua Profiler\r\n  * 可根据函数调用总时长，平均每次调用时长，调用次数排序\r\n  * 显示lua函数名及其所在文件的名字及行号\r\n  * 如果C#函数，会显示这个是C#函数\r\n* 支持真机调试\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Doc/features.md.meta",
    "content": "fileFormatVersion: 2\nguid: 6dcae34981e53564ea1ad644fe0b2f7c\ntimeCreated: 1481768591\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/hotfix.md",
    "content": "## 简介\r\n\r\n热补丁允许你使用 xLua 的代码逻辑, 替换掉原有的 C# 程序逻辑, 以实现热补丁.\r\n\r\n## 使用方式\r\n\r\n1. 打开该特性\r\n\r\n    添加 `HOTFIX_ENABLE` 宏，（在 Unity3D 的 \"File->Build Setting->Scripting Define Symbols\" 下添加）。编辑器、各手机平台这个宏要分别设置！如果是自动化打包，要注意在代码里头用 API 设置的宏是不生效的，需要在编辑器设置。\r\n\r\n    （建议平时开发业务代码不打开 `HOTFIX_ENABLE`，只在构建手机版本或者要在编译器下开发补丁时打开 `HOTFIX_ENABLE`）\r\n\r\n2. 在菜单中找到 \"XLua/Generate Code\" 按钮并单击。\r\n\r\n3. 注入，构建手机包这个步骤会在构建时自动进行，编辑器下开发补丁需要手动执行 \"XLua/Hotfix Inject In Editor\" 菜单。打印 “hotfix inject finish!” 或者 “had injected!” 才算成功，否则会打印错误信息。\r\n\r\n    如果已经打印了 “hotfix inject finish!” 或者 “had injected!”，执行 `xlua.hotfix` 仍然报类似 “xlua.access, no field __Hitfix0_Update” 的错误，要么是该类没配置到 Hotfix 列表，要么是注入成功后，又触发了编译，覆盖了注入结果。\r\n\r\n## 局限性\r\n\r\n不支持静态构造函数。\r\n\r\n目前只支持 Assets 下代码的热补丁，不支持引擎，C# 系统库的热补丁。\r\n\r\n## API\r\n\r\n`xlua.hotfix(class, [method_name], fix)`\r\n\r\n* 描述         ： 注入lua补丁\r\n* class        ： C#类，两种表示方法，CS.Namespace.TypeName或者字符串方式\"Namespace.TypeName\"，字符串格式和C#的Type.GetType要求一致，如果是内嵌类型（Nested Type）是非Public类型的话，只能用字符串方式表示\"Namespace.TypeName+NestedTypeName\"；\r\n* method_name  ： 方法名，可选；\r\n* fix          ： 如果传了method_name，fix将会是一个function，否则通过table提供一组函数。table的组织按key是method_name，value是function的方式。\r\n\r\n`base(csobj)`\r\n\r\n* 描述         ： 子类override函数通过base调用父类实现。\r\n* csobj        ： 对象\r\n* 返回值       ： 新对象，可以通过该对象base上的方法\r\n\r\n例子（位于HotfixTest2.cs）：\r\n\r\n```lua\r\nxlua.hotfix(CS.BaseTest, 'Foo', function(self, p)\r\n    print('BaseTest', p)\r\n    base(self):Foo(p)\r\nend)\r\n```\r\n\r\n`util.hotfix_ex(class, method_name, fix)`\r\n\r\n* 描述         ： xlua.hotfix的增强版本，可以在fix函数里头执行原来的函数，缺点是fix的执行会略慢。\r\n* method_name  ： 方法名；\r\n* fix          ： 用来替换C#方法的lua function。\r\n\r\n## 标识要热更新的类型\r\n\r\n和其它配置一样，有两种方式\r\n\r\n方式一：直接在类里头打Hotfix标签（不建议，示例只是为了方便演示采取这种方式）；\r\n\r\n！！注意，方式一在高版本 Unity 不支持\r\n\r\n方式二：在一个静态类的静态字段或者属性里头配置一个列表。属性可以用于实现的比较复杂的配置，比如根据命名空间做白名单。\r\n\r\n！！注意，高版本 Unity 需要把配置文件放 Editor 目录下\r\n\r\n```csharp\r\n//如果涉及到Assembly-CSharp.dll之外的其它dll，如下代码需要放到Editor目录\r\npublic static class HotfixCfg\r\n{\r\n    [Hotfix]\r\n    public static List<Type> by_field = new List<Type>()\r\n    {\r\n        typeof(HotFixSubClass),\r\n        typeof(GenericClass<>),\r\n    };\r\n\r\n    [Hotfix]\r\n    public static List<Type> by_property\r\n    {\r\n        get\r\n        {\r\n            return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\r\n                    where type.Namespace == \"XXXX\"\r\n                    select type).ToList();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Hotfix Flag\r\n\r\nHotfix标签可以设置一些标志位对生成代码及插桩定制化\r\n\r\n* Stateless、Stateful\r\n\r\n    遗留设置，`Stateful` 方式在新版本已经删除，因为这种方式可以用 `xlua.util.state` 接口达到类似的效果，该接口的使用可以看下`HotfixTest2.cs` 里的示例代码。\r\n\r\n    由于没 `Stateful`，默认就是 `Stateless`，所以也没必要设置该标志位。\r\n\r\n* ValueTypeBoxing\r\n\r\n    值类型的适配delegate会收敛到object，好处是代码量更少，不好的是值类型会产生boxing及gc，适用于对text段敏感的业务。\r\n\r\n* IgnoreProperty\r\n\r\n    不对属性注入及生成适配代码，一般而言，大多数属性的实现都很简单，出错几率比较小，建议不注入。\r\n\r\n* IgnoreNotPublic\r\n\r\n    不对非public的方法注入及生成适配代码。除了像MonoBehaviour那种会被反射调用的私有方法必须得注入，其它仅被本类调用的非public方法可以不注入，只不过修复时会工作量稍大，所有引用到这个函数的public方法都要重写。\r\n\r\n* Inline\r\n\r\n    不生成适配 delegate，直接在函数体注入处理代码。\r\n\r\n* IntKey\r\n\r\n    不生成静态字段，而是把所有注入点放到一个数组集中管理。\r\n\r\n    好处：对 text 段影响小。\r\n\r\n    坏处：使用不像默认方式那么方便，需要通过id来指明hotfix哪个函数，而这个id是代码注入工具时分配的，函数到id的映射会保存在 `Gen/Resources/hotfix_id_map.lua.txt`，并且自动加时间戳备份到 `hotfix_id_map.lua.txt` 同级目录，发布手机版本后请妥善保存该文件。\r\n\r\n    该文件的格式大概如下（注意：该文件仅IntKey模式使用，当你没类型指定IntKey模式注入，该文件只返回个空表）：\r\n\r\n```lua\r\nreturn {\r\n    [\"HotfixTest\"] = {\r\n        [\".ctor\"] = {\r\n            5\r\n        },\r\n        [\"Start\"] = {\r\n            6\r\n        },\r\n        [\"Update\"] = {\r\n            7\r\n        },\r\n        [\"FixedUpdate\"] = {\r\n            8\r\n        },\r\n        [\"Add\"] = {\r\n            9,10\r\n        },\r\n        [\"OnGUI\"] = {\r\n            11\r\n        },\r\n    },\r\n}\r\n```\r\n\r\n想要替换 `HotfixTest` 的 `Update` 函数，你得\r\n\r\n```lua\r\nCS.XLua.HotfixDelegateBridge.Set(7, func)\r\n```\r\n\r\n如果是重载函数，将会一个函数名对应多个 id，比如上面的 `Add` 函数。\r\n\r\n能不能自动化一些呢？可以，`xlua.util` 提供了 `auto_id_map` 函数，执行一次后你就可以像以前那样直接用类，方法名去指明修补的函数。\r\n\r\n```lua\r\n(require 'xlua.util').auto_id_map()\r\nxlua.hotfix(CS.HotfixTest, 'Update', function(self)\r\n        self.tick = self.tick + 1\r\n        if (self.tick % 50) == 0 then\r\n            print('<<<<<<<<Update in lua, tick = ' .. self.tick)\r\n        end\r\n    end)\r\n```\r\n\r\n前提是 `hotfix_id_map.lua.txt` 放到可以通过 `require 'hotfix_id_map'` 引用到的地方。\r\n\r\n## 使用建议\r\n\r\n* 对所有较大可能变动的类型加上 `Hotfix` 标识；\r\n* 建议用反射找出所有函数参数、字段、属性、事件涉及的 delegate 类型，标注 `CSharpCallLua`；\r\n* 业务代码、引擎 API、系统 API，需要在 Lua 补丁里头高性能访问的类型，加上 `LuaCallCSharp`；\r\n* 引擎 API、系统 API 可能被代码剪裁调（C#无引用的地方都会被剪裁），如果觉得可能会新增 C# 代码之外的 API 调用，这些 API 所在的类型要么加 `LuaCallCSharp`，要么加 `ReflectionUse`；\r\n\r\n## 打补丁\r\n\r\nxlua可以用lua函数替换 C# 的构造函数，函数，属性，事件的替换。lua实现都是函数，比如属性对于一个 getter 函数和一个 setter 函数，事件对应一个 `add` 函数和一个 `remove` 函数。\r\n\r\n* 函数\r\n\r\n`method_name` 传函数名，支持重载，不同重载都是转发到同一个 lua 函数。\r\n\r\n比如：\r\n\r\n```csharp\r\n\r\n// 要fix的C#类\r\n[Hotfix]\r\npublic class HotfixCalc\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        return a - b;\r\n    }\r\n\r\n    public Vector3 Add(Vector3 a, Vector3 b)\r\n    {\r\n        return a - b;\r\n    }\r\n｝\r\n\r\n```\r\n\r\n```lua\r\n\r\nxlua.hotfix(CS.HotfixCalc, 'Add', function(self, a, b)\r\n    return a + b\r\nend)\r\n\r\n```\r\n\r\n静态函数和成员函数的区别是，成员函数会加一个 self 参数，这个 self 在 Stateless 方式下是 C# 对象本身（对应 C# 的 this）\r\n\r\n普通参数对于 lua 的参数，ref 参数对应 lua 的一个参数和一个返回值，out参数对于lua的一个返回值。\r\n\r\n泛化函数的打补丁规则和普通函数一样。\r\n\r\n* 构造函数\r\n\r\n构造函数对应的 `method_name` 是 \".ctor\"。\r\n\r\n和普通函数不一样的是，构造函数的热补丁并不是替换，而是执行原有逻辑后调用lua。\r\n\r\n* 属性\r\n\r\n对于名为 “AProp” 的属性，会对应一个 getter，`method_name` 等于 `get_AProp`，setter 的 `method_name` 等于 `set_AProp`。\r\n\r\n* []操作符\r\n\r\n赋值对应 `set_Item`，取值对应 `get_Item`。第一个参数是 self，赋值后面跟 key，value，取值只有 key 参数，返回值是取出的值。\r\n\r\n* 其它操作符\r\n\r\nC#的操作符都有一套内部表示，比如 `+` 号的操作符函数名是 `op_Addition`（其它操作符的内部表示可以去请参照相关资料），覆盖这函数就覆盖了 C# 的 `+` 号操作符。\r\n\r\n* 事件\r\n\r\n比如对于事件“AEvent”，+= 操作符是 add_AEvent，-=对应的是 remove_AEvent。这两个函数均是第一个参数是self，第二个参数是操作符后面跟的delegate。\r\n\r\n通过 `xlua.private_accessible`（版本号大于2.1.11不需要调用 `xlua.private_accessible`）来直接访问事件对应的私有 delegate 的直接访问后，可以通过对象的\"&事件名\"字段直接触发事件，例如 `self['&MyEvent']()`，其中MyEvent是事件名。\r\n\r\n* 析构函数\r\n\r\nmethod_name 是 \"Finalize\"，传一个 self 参数。\r\n\r\n和普通函数不一样的是，析构函数的热补丁并不是替换，而是开头调用 lua 函数后继续原有逻辑。\r\n\r\n* 泛化类型\r\n\r\n其它规则一致，需要说明的是，每个泛化类型实例化后都是一个独立的类型，只能针对实例化后的类型分别打补丁。比如：\r\n\r\n```csharp\r\npublic class GenericClass<T>\r\n{\r\n｝\r\n```\r\n\r\n你只能对 `GenericClass<double>`，`GenericClass<int>` 这些类，而不是对 `GenericClass` 打补丁。\r\n\r\n对 `GenericClass<double>` 打补丁的实例如下：\r\n\r\n```csharp\r\nluaenv.DoString(@\"\r\n    xlua.hotfix(CS.GenericClass(CS.System.Double), {\r\n        ['.ctor'] = function(obj, a)\r\n            print('GenericClass<double>', obj, a)\r\n        end;\r\n        Func1 = function(obj)\r\n            print('GenericClass<double>.Func1', obj)\r\n        end;\r\n        Func2 = function(obj)\r\n            print('GenericClass<double>.Func2', obj)\r\n            return 1314\r\n        end\r\n    })\r\n\");\r\n```\r\n\r\n* Unity协程\r\n\r\n通过 `util.cs_generator` 可以用一个 function 模拟一个 `IEnumerator`，在里头用 `coroutine.yield`，就类似 C# 里头的 yield return。比如下面的 C# 代码和对应的 hotfix 代码是等同效果的\r\n\r\n```csharp\r\n[XLua.Hotfix]\r\npublic class HotFixSubClass : MonoBehaviour {\r\n    IEnumerator Start()\r\n    {\r\n        while (true)\r\n        {\r\n            yield return new WaitForSeconds(3);\r\n            Debug.Log(\"Wait for 3 seconds\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n```csharp\r\nluaenv.DoString(@\"\r\n    local util = require 'xlua.util'\r\n    xlua.hotfix(CS.HotFixSubClass,{\r\n        Start = function(self)\r\n            return util.cs_generator(function()\r\n                while true do\r\n                    coroutine.yield(CS.UnityEngine.WaitForSeconds(3))\r\n                    print('Wait for 3 seconds')\r\n                end\r\n            end)\r\n        end;\r\n    })\r\n\");\r\n```\r\n\r\n* 整个类\r\n\r\n如果要替换整个类，不需要一次次的调用 `xlua.hotfix` 去替换，可以整个一次完成。只要给一个 table，按 `method_name = function` 组织即可\r\n\r\n```lua\r\n\r\nxlua.hotfix(CS.StatefullTest, {\r\n    ['.ctor'] = function(csobj)\r\n        return util.state(csobj, {evt = {}, start = 0, prop = 0})\r\n    end;\r\n    set_AProp = function(self, v)\r\n        print('set_AProp', v)\r\n        self.prop = v\r\n    end;\r\n    get_AProp = function(self)\r\n        return self.prop\r\n    end;\r\n    get_Item = function(self, k)\r\n        print('get_Item', k)\r\n        return 1024\r\n    end;\r\n    set_Item = function(self, k, v)\r\n        print('set_Item', k, v)\r\n    end;\r\n    add_AEvent = function(self, cb)\r\n        print('add_AEvent', cb)\r\n        table.insert(self.evt, cb)\r\n    end;\r\n    remove_AEvent = function(self, cb)\r\n       print('remove_AEvent', cb)\r\n       for i, v in ipairs(self.evt) do\r\n           if v == cb then\r\n               table.remove(self.evt, i)\r\n               break\r\n           end\r\n       end\r\n    end;\r\n    Start = function(self)\r\n        print('Start')\r\n        for _, cb in ipairs(self.evt) do\r\n            cb(self.start, 2)\r\n        end\r\n        self.start = self.start + 1\r\n    end;\r\n    StaticFunc = function(a, b, c)\r\n       print(a, b, c)\r\n    end;\r\n    GenericTest = function(self, a)\r\n       print(self, a)\r\n    end;\r\n    Finalize = function(self)\r\n       print('Finalize', self)\r\n    end\r\n})\r\n\r\n```\r\n"
  },
  {
    "path": "Assets/XLua/Doc/hotfix.md.meta",
    "content": "fileFormatVersion: 2\nguid: a96cb06c040f28c4aab024ca7634360b\ntimeCreated: 1482837382\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/logo.png.meta",
    "content": "fileFormatVersion: 2\nguid: 6b9f4e2e38c36db40bc5bdfe20038d94\ntimeCreated: 1481715979\nlicenseType: Pro\nTextureImporter:\n  fileIDToRecycleName: {}\n  serializedVersion: 2\n  mipmaps:\n    mipMapMode: 0\n    enableMipMap: 1\n    linearTexture: 0\n    correctGamma: 0\n    fadeOut: 0\n    borderMipMap: 0\n    mipMapFadeDistanceStart: 1\n    mipMapFadeDistanceEnd: 3\n  bumpmap:\n    convertToNormalMap: 0\n    externalNormalMap: 0\n    heightScale: .25\n    normalMapFilter: 0\n  isReadable: 0\n  grayScaleToAlpha: 0\n  generateCubemap: 0\n  cubemapConvolution: 0\n  cubemapConvolutionSteps: 8\n  cubemapConvolutionExponent: 1.5\n  seamlessCubemap: 0\n  textureFormat: -1\n  maxTextureSize: 2048\n  textureSettings:\n    filterMode: -1\n    aniso: -1\n    mipBias: -1\n    wrapMode: -1\n  nPOTScale: 1\n  lightmap: 0\n  rGBM: 0\n  compressionQuality: 50\n  allowsAlphaSplitting: 0\n  spriteMode: 0\n  spriteExtrude: 1\n  spriteMeshType: 1\n  alignment: 0\n  spritePivot: {x: .5, y: .5}\n  spriteBorder: {x: 0, y: 0, z: 0, w: 0}\n  spritePixelsToUnits: 100\n  alphaIsTransparency: 0\n  textureType: -1\n  buildTargetSettings: []\n  spriteSheet:\n    sprites: []\n  spritePackingTag: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/signature.md",
    "content": "## 源代码签名的用处\r\n\r\n可以防止文件传输的过程被黑客篡改。\r\n\r\n## xLua的签名功能的使用\r\n\r\n* 用Tools/KeyPairsGen.exe生成公私钥对，key_ras文件保存的是私钥，key_ras.pub保存的是公钥，这两个文件请妥善保存，私钥关系到游戏安全，请做好保密工作；\r\n* 用Tools/FilesSignature.exe对源代码进行签名：\r\n  * key_ras文件要放到执行目录；\r\n  * 参数是源目录和目标目录，这个工具会自动把源目录及其子目录下所有lua后缀的文件签名，按同样的目录结构放到目标目录下；\r\n* 通过SignatureLoader对自己原有的CustomLoader包装后使用；\r\n  * SignatureLoader的构造函数有两个，一个是公钥，也就是key_ras.pub里头的内容，一个是原来的Loader；\r\n"
  },
  {
    "path": "Assets/XLua/Doc/signature.md.meta",
    "content": "fileFormatVersion: 2\nguid: 54ea702ea6cb89a46b7986dc7fa8482e\ntimeCreated: 1489376033\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc/xLua.png.meta",
    "content": "fileFormatVersion: 2\nguid: b2926ca0864130e40b99cbe18d0fc395\ntimeCreated: 1481699971\nlicenseType: Pro\nTextureImporter:\n  fileIDToRecycleName: {}\n  serializedVersion: 2\n  mipmaps:\n    mipMapMode: 0\n    enableMipMap: 1\n    linearTexture: 0\n    correctGamma: 0\n    fadeOut: 0\n    borderMipMap: 0\n    mipMapFadeDistanceStart: 1\n    mipMapFadeDistanceEnd: 3\n  bumpmap:\n    convertToNormalMap: 0\n    externalNormalMap: 0\n    heightScale: .25\n    normalMapFilter: 0\n  isReadable: 0\n  grayScaleToAlpha: 0\n  generateCubemap: 0\n  cubemapConvolution: 0\n  cubemapConvolutionSteps: 8\n  cubemapConvolutionExponent: 1.5\n  seamlessCubemap: 0\n  textureFormat: -1\n  maxTextureSize: 2048\n  textureSettings:\n    filterMode: -1\n    aniso: -1\n    mipBias: -1\n    wrapMode: -1\n  nPOTScale: 1\n  lightmap: 0\n  rGBM: 0\n  compressionQuality: 50\n  allowsAlphaSplitting: 0\n  spriteMode: 0\n  spriteExtrude: 1\n  spriteMeshType: 1\n  alignment: 0\n  spritePivot: {x: .5, y: .5}\n  spriteBorder: {x: 0, y: 0, z: 0, w: 0}\n  spritePixelsToUnits: 100\n  alphaIsTransparency: 0\n  textureType: -1\n  buildTargetSettings: []\n  spriteSheet:\n    sprites: []\n  spritePackingTag: \n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Doc.meta",
    "content": "fileFormatVersion: 2\nguid: 67edfc4b640373846b14362bf8769576\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Editor/ExampleConfig.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing XLua;\r\nusing System.Reflection;\r\nusing System.Linq;\r\n\r\n//配置的详细介绍请看Doc下《XLua的配置.doc》\r\npublic static class ExampleConfig\r\n{\r\n    /***************如果你全lua编程，可以参考这份自动化配置***************/\r\n    //--------------begin 纯lua编程配置参考----------------------------\r\n    //static List<string> exclude = new List<string> {\r\n    //    \"HideInInspector\", \"ExecuteInEditMode\",\r\n    //    \"AddComponentMenu\", \"ContextMenu\",\r\n    //    \"RequireComponent\", \"DisallowMultipleComponent\",\r\n    //    \"SerializeField\", \"AssemblyIsEditorAssembly\",\r\n    //    \"Attribute\", \"Types\",\r\n    //    \"UnitySurrogateSelector\", \"TrackedReference\",\r\n    //    \"TypeInferenceRules\", \"FFTWindow\",\r\n    //    \"RPC\", \"Network\", \"MasterServer\",\r\n    //    \"BitStream\", \"HostData\",\r\n    //    \"ConnectionTesterStatus\", \"GUI\", \"EventType\",\r\n    //    \"EventModifiers\", \"FontStyle\", \"TextAlignment\",\r\n    //    \"TextEditor\", \"TextEditorDblClickSnapping\",\r\n    //    \"TextGenerator\", \"TextClipping\", \"Gizmos\",\r\n    //    \"ADBannerView\", \"ADInterstitialAd\",\r\n    //    \"Android\", \"Tizen\", \"jvalue\",\r\n    //    \"iPhone\", \"iOS\", \"Windows\", \"CalendarIdentifier\",\r\n    //    \"CalendarUnit\", \"CalendarUnit\",\r\n    //    \"ClusterInput\", \"FullScreenMovieControlMode\",\r\n    //    \"FullScreenMovieScalingMode\", \"Handheld\",\r\n    //    \"LocalNotification\", \"NotificationServices\",\r\n    //    \"RemoteNotificationType\", \"RemoteNotification\",\r\n    //    \"SamsungTV\", \"TextureCompressionQuality\",\r\n    //    \"TouchScreenKeyboardType\", \"TouchScreenKeyboard\",\r\n    //    \"MovieTexture\", \"UnityEngineInternal\",\r\n    //    \"Terrain\", \"Tree\", \"SplatPrototype\",\r\n    //    \"DetailPrototype\", \"DetailRenderMode\",\r\n    //    \"MeshSubsetCombineUtility\", \"AOT\", \"Social\", \"Enumerator\",\r\n    //    \"SendMouseEvents\", \"Cursor\", \"Flash\", \"ActionScript\",\r\n    //    \"OnRequestRebuild\", \"Ping\",\r\n    //    \"ShaderVariantCollection\", \"SimpleJson.Reflection\",\r\n    //    \"CoroutineTween\", \"GraphicRebuildTracker\",\r\n    //    \"Advertisements\", \"UnityEditor\", \"WSA\",\r\n    //    \"EventProvider\", \"Apple\",\r\n    //    \"ClusterInput\", \"Motion\",\r\n    //    \"UnityEngine.UI.ReflectionMethodsCache\", \"NativeLeakDetection\",\r\n    //    \"NativeLeakDetectionMode\", \"WWWAudioExtensions\", \"UnityEngine.Experimental\",\r\n    //};\r\n\r\n    //static bool isExcluded(Type type)\r\n    //{\r\n    //    var fullName = type.FullName;\r\n    //    for (int i = 0; i < exclude.Count; i++)\r\n    //    {\r\n    //        if (fullName.Contains(exclude[i]))\r\n    //        {\r\n    //            return true;\r\n    //        }\r\n    //    }\r\n    //    return false;\r\n    //}\r\n\r\n    //[LuaCallCSharp]\r\n    //public static IEnumerable<Type> LuaCallCSharp\r\n    //{\r\n    //    get\r\n    //    {\r\n    //        List<string> namespaces = new List<string>() // 在这里添加名字空间\r\n    //        {\r\n    //            \"UnityEngine\",\r\n    //            \"UnityEngine.UI\"\r\n    //        };\r\n    //        var unityTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies()\r\n    //                          where !(assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)\r\n    //                          from type in assembly.GetExportedTypes()\r\n    //                          where type.Namespace != null && namespaces.Contains(type.Namespace) && !isExcluded(type)\r\n    //                                  && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum\r\n    //                          select type);\r\n\r\n    //        string[] customAssemblys = new string[] {\r\n    //            \"Assembly-CSharp\",\r\n    //        };\r\n    //        var customTypes = (from assembly in customAssemblys.Select(s => Assembly.Load(s))\r\n    //                           from type in assembly.GetExportedTypes()\r\n    //                           where type.Namespace == null || !type.Namespace.StartsWith(\"XLua\")\r\n    //                                   && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum\r\n    //                           select type);\r\n    //        return unityTypes.Concat(customTypes);\r\n    //    }\r\n    //}\r\n\r\n    ////自动把LuaCallCSharp涉及到的delegate加到CSharpCallLua列表，后续可以直接用lua函数做callback\r\n    //[CSharpCallLua]\r\n    //public static List<Type> CSharpCallLua\r\n    //{\r\n    //    get\r\n    //    {\r\n    //        var lua_call_csharp = LuaCallCSharp;\r\n    //        var delegate_types = new List<Type>();\r\n    //        var flag = BindingFlags.Public | BindingFlags.Instance\r\n    //            | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly;\r\n    //        foreach (var field in (from type in lua_call_csharp select type).SelectMany(type => type.GetFields(flag)))\r\n    //        {\r\n    //            if (typeof(Delegate).IsAssignableFrom(field.FieldType))\r\n    //            {\r\n    //                delegate_types.Add(field.FieldType);\r\n    //            }\r\n    //        }\r\n\r\n    //        foreach (var method in (from type in lua_call_csharp select type).SelectMany(type => type.GetMethods(flag)))\r\n    //        {\r\n    //            if (typeof(Delegate).IsAssignableFrom(method.ReturnType))\r\n    //            {\r\n    //                delegate_types.Add(method.ReturnType);\r\n    //            }\r\n    //            foreach (var param in method.GetParameters())\r\n    //            {\r\n    //                var paramType = param.ParameterType.IsByRef ? param.ParameterType.GetElementType() : param.ParameterType;\r\n    //                if (typeof(Delegate).IsAssignableFrom(paramType))\r\n    //                {\r\n    //                    delegate_types.Add(paramType);\r\n    //                }\r\n    //            }\r\n    //        }\r\n    //        return delegate_types.Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct().ToList();\r\n    //    }\r\n    //}\r\n    //--------------end 纯lua编程配置参考----------------------------\r\n\r\n    /***************热补丁可以参考这份自动化配置***************/\r\n    //[Hotfix]\r\n    //static IEnumerable<Type> HotfixInject\r\n    //{\r\n    //    get\r\n    //    {\r\n    //        return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\r\n    //                where type.Namespace == null || !type.Namespace.StartsWith(\"XLua\")\r\n    //                select type);\r\n    //    }\r\n    //}\r\n    //--------------begin 热补丁自动化配置-------------------------\r\n    //static bool hasGenericParameter(Type type)\r\n    //{\r\n    //    if (type.IsGenericTypeDefinition) return true;\r\n    //    if (type.IsGenericParameter) return true;\r\n    //    if (type.IsByRef || type.IsArray)\r\n    //    {\r\n    //        return hasGenericParameter(type.GetElementType());\r\n    //    }\r\n    //    if (type.IsGenericType)\r\n    //    {\r\n    //        foreach (var typeArg in type.GetGenericArguments())\r\n    //        {\r\n    //            if (hasGenericParameter(typeArg))\r\n    //            {\r\n    //                return true;\r\n    //            }\r\n    //        }\r\n    //    }\r\n    //    return false;\r\n    //}\r\n\r\n    //static bool typeHasEditorRef(Type type)\r\n    //{\r\n    //    if (type.Namespace != null && (type.Namespace == \"UnityEditor\" || type.Namespace.StartsWith(\"UnityEditor.\")))\r\n    //    {\r\n    //        return true;\r\n    //    }\r\n    //    if (type.IsNested)\r\n    //    {\r\n    //        return typeHasEditorRef(type.DeclaringType);\r\n    //    }\r\n    //    if (type.IsByRef || type.IsArray)\r\n    //    {\r\n    //        return typeHasEditorRef(type.GetElementType());\r\n    //    }\r\n    //    if (type.IsGenericType)\r\n    //    {\r\n    //        foreach (var typeArg in type.GetGenericArguments())\r\n    //        {\r\n    //            if (typeArg.IsGenericParameter) {\r\n    //                //skip unsigned type parameter\r\n    //                continue;\r\n    //            } \r\n    //            if (typeHasEditorRef(typeArg))\r\n    //            {\r\n    //                return true;\r\n    //            }\r\n    //        }\r\n    //    }\r\n    //    return false;\r\n    //}\r\n\r\n    //static bool delegateHasEditorRef(Type delegateType)\r\n    //{\r\n    //    if (typeHasEditorRef(delegateType)) return true;\r\n    //    var method = delegateType.GetMethod(\"Invoke\");\r\n    //    if (method == null)\r\n    //    {\r\n    //        return false;\r\n    //    }\r\n    //    if (typeHasEditorRef(method.ReturnType)) return true;\r\n    //    return method.GetParameters().Any(pinfo => typeHasEditorRef(pinfo.ParameterType));\r\n    //}\r\n\r\n    // 配置某Assembly下所有涉及到的delegate到CSharpCallLua下，Hotfix下拿不准那些delegate需要适配到lua function可以这么配置\r\n    //[CSharpCallLua]\r\n    //static IEnumerable<Type> AllDelegate\r\n    //{\r\n    //    get\r\n    //    {\r\n    //        BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;\r\n    //        List<Type> allTypes = new List<Type>();\r\n    //        var allAssemblys = new Assembly[]\r\n    //        {\r\n    //            Assembly.Load(\"Assembly-CSharp\")\r\n    //        };\r\n    //        foreach (var t in (from assembly in allAssemblys from type in assembly.GetTypes() select type))\r\n    //        {\r\n    //            var p = t;\r\n    //            while (p != null)\r\n    //            {\r\n    //                allTypes.Add(p);\r\n    //                p = p.BaseType;\r\n    //            }\r\n    //        }\r\n    //        allTypes = allTypes.Distinct().ToList();\r\n    //        var allMethods = from type in allTypes\r\n    //                         from method in type.GetMethods(flag)\r\n    //                         select method;\r\n    //        var returnTypes = from method in allMethods\r\n    //                          select method.ReturnType;\r\n    //        var paramTypes = allMethods.SelectMany(m => m.GetParameters()).Select(pinfo => pinfo.ParameterType.IsByRef ? pinfo.ParameterType.GetElementType() : pinfo.ParameterType);\r\n    //        var fieldTypes = from type in allTypes\r\n    //                         from field in type.GetFields(flag)\r\n    //                         select field.FieldType;\r\n    //        return (returnTypes.Concat(paramTypes).Concat(fieldTypes)).Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct();\r\n    //    }\r\n    //}\r\n    //--------------end 热补丁自动化配置-------------------------\r\n\r\n    //黑名单\r\n    [BlackList]\r\n    public static List<List<string>> BlackList = new List<List<string>>()  {\r\n                new List<string>(){\"System.Xml.XmlNodeList\", \"ItemOf\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"movie\"},\r\n    #if UNITY_WEBGL\r\n                new List<string>(){\"UnityEngine.WWW\", \"threadPriority\"},\r\n    #endif\r\n                new List<string>(){\"UnityEngine.Texture2D\", \"alphaIsTransparency\"},\r\n                new List<string>(){\"UnityEngine.Security\", \"GetChainOfTrustValue\"},\r\n                new List<string>(){\"UnityEngine.CanvasRenderer\", \"onRequestRebuild\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"areaSize\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"lightmapBakeType\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"MovieTexture\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"GetMovieTexture\"},\r\n                new List<string>(){\"UnityEngine.AnimatorOverrideController\", \"PerformOverrideClipListCleanup\"},\r\n    #if !UNITY_WEBPLAYER\r\n                new List<string>(){\"UnityEngine.Application\", \"ExternalEval\"},\r\n    #endif\r\n                new List<string>(){\"UnityEngine.GameObject\", \"networkView\"}, //4.6.2 not support\r\n                new List<string>(){\"UnityEngine.Component\", \"networkView\"},  //4.6.2 not support\r\n                new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.FileInfo\", \"SetAccessControl\", \"System.Security.AccessControl.FileSecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"SetAccessControl\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"CreateSubdirectory\", \"System.String\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"Create\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"UnityEngine.MonoBehaviour\", \"runInEditMode\"},\r\n            };\r\n\r\n#if UNITY_2018_1_OR_NEWER\r\n    [BlackList]\r\n    public static Func<MemberInfo, bool> MethodFilter = (memberInfo) =>\r\n    {\r\n        if (memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Dictionary<,>))\r\n        {\r\n            if (memberInfo.MemberType == MemberTypes.Constructor)\r\n            {\r\n                ConstructorInfo constructorInfo = memberInfo as ConstructorInfo;\r\n                var parameterInfos = constructorInfo.GetParameters();\r\n                if (parameterInfos.Length > 0)\r\n                {\r\n                    if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameterInfos[0].ParameterType))\r\n                    {\r\n                        return true;\r\n                    }\r\n                }\r\n            }\r\n            else if (memberInfo.MemberType == MemberTypes.Method)\r\n            {\r\n                var methodInfo = memberInfo as MethodInfo;\r\n                if (methodInfo.Name == \"TryAdd\" || methodInfo.Name == \"Remove\" && methodInfo.GetParameters().Length == 2)\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n        }\r\n        return false;\r\n    };\r\n#endif\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Editor/ExampleConfig.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1b852d3c62124624888d03e611f7b1fc\ntimeCreated: 1534126175\nlicenseType: Pro\nMonoImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Editor/XLuaUnityDefaultConfig.cs",
    "content": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Reflection;\nusing System.Text;\nusing System.Threading.Tasks;\nusing XLua;\n\n/// <summary>\n/// xLua 默认配置\n/// </summary>\nstatic class XLuaUnityDefaultConfig\n{\n\n#if UNITY_2022_1_OR_NEWER\n    static bool IsSpanType(Type type)\n    {\n        if (!type.IsGenericType)\n            return false;\n\n        var genericDefinition = type.GetGenericTypeDefinition();\n\n        return\n            genericDefinition == typeof(Span<>) ||\n            genericDefinition == typeof(ReadOnlySpan<>);\n    }\n\n    static bool IsSpanMember(MemberInfo memberInfo)\n    {\n        switch (memberInfo)\n        {\n            case FieldInfo fieldInfo:\n                return IsSpanType(fieldInfo.FieldType);\n\n            case PropertyInfo propertyInfo:\n                return IsSpanType(propertyInfo.PropertyType);\n\n            case ConstructorInfo constructorInfo:\n                return constructorInfo.GetParameters().Any(p => IsSpanType(p.ParameterType));\n\n            case MethodInfo methodInfo:\n                return methodInfo.GetParameters().Any(p => IsSpanType(p.ParameterType)) || IsSpanType(methodInfo.ReturnType);\n\n            default:\n                return false;\n        }\n    }\n\n    [BlackList]\n    public static Func<MemberInfo, bool> SpanMembersFilter = IsSpanMember;\n\n#endif\n}"
  },
  {
    "path": "Assets/XLua/Editor.meta",
    "content": "fileFormatVersion: 2\nguid: f890416e958ceb54694b165fb109582a\nfolderAsset: yes\ntimeCreated: 1534492498\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/01_Helloworld/Helloworld.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class Helloworld : MonoBehaviour\r\n    {\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n            luaenv.DoString(\"CS.UnityEngine.Debug.Log('hello world')\");\r\n            luaenv.Dispose();\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/01_Helloworld/Helloworld.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 480b23bd4e378f2499f8b31ae84b1c05\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/01_Helloworld/Helloworld.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 58e2eda480b0c6e41a793391a9fb9a72\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/01_Helloworld.meta",
    "content": "fileFormatVersion: 2\nguid: c8fbb1a01533805479599cd3e19a5e4c\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting/LuaBehaviour.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\n\r\nnamespace XLuaTest\r\n{\r\n    [System.Serializable]\r\n    public class Injection\r\n    {\r\n        public string name;\r\n        public GameObject value;\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class LuaBehaviour : MonoBehaviour\r\n    {\r\n        public TextAsset luaScript;\r\n        public Injection[] injections;\r\n\r\n        internal static LuaEnv luaEnv = new LuaEnv(); //all lua behaviour shared one luaenv only!\r\n        internal static float lastGCTime = 0;\r\n        internal const float GCInterval = 1;//1 second \r\n\r\n        private Action luaStart;\r\n        private Action luaUpdate;\r\n        private Action luaOnDestroy;\r\n\r\n        private LuaTable scriptScopeTable;\r\n\r\n        void Awake()\r\n        {\r\n            // 为每个脚本设置一个独立的脚本域，可一定程度上防止脚本间全局变量、函数冲突\r\n            scriptScopeTable = luaEnv.NewTable();\r\n\r\n            // 设置其元表的 __index, 使其能够访问全局变量\r\n            using (LuaTable meta = luaEnv.NewTable())\r\n            {\r\n                meta.Set(\"__index\", luaEnv.Global);\r\n                scriptScopeTable.SetMetaTable(meta);\r\n            }\r\n\r\n            // 将所需值注入到 Lua 脚本域中\r\n            scriptScopeTable.Set(\"self\", this);\r\n            foreach (var injection in injections)\r\n            {\r\n                scriptScopeTable.Set(injection.name, injection.value);\r\n            }\r\n\r\n            // 如果你希望在脚本内能够设置全局变量, 也可以直接将全局脚本域注入到当前脚本的脚本域中\r\n            // 这样, 你就可以在 Lua 脚本中通过 Global.XXX 来访问全局变量\r\n            // scriptScopeTable.Set(\"Global\", luaEnv.Global);\r\n\r\n            // 执行脚本\r\n            luaEnv.DoString(luaScript.text, luaScript.name, scriptScopeTable);\r\n\r\n            // 从 Lua 脚本域中获取定义的函数\r\n            Action luaAwake = scriptScopeTable.Get<Action>(\"awake\");\r\n            scriptScopeTable.Get(\"start\", out luaStart);\r\n            scriptScopeTable.Get(\"update\", out luaUpdate);\r\n            scriptScopeTable.Get(\"ondestroy\", out luaOnDestroy);\r\n\r\n            if (luaAwake != null)\r\n            {\r\n                luaAwake();\r\n            }\r\n        }\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            if (luaStart != null)\r\n            {\r\n                luaStart();\r\n            }\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaUpdate != null)\r\n            {\r\n                luaUpdate();\r\n            }\r\n\r\n            if (Time.time - LuaBehaviour.lastGCTime > GCInterval)\r\n            {\r\n                luaEnv.Tick();\r\n                LuaBehaviour.lastGCTime = Time.time;\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            if (luaOnDestroy != null)\r\n            {\r\n                luaOnDestroy();\r\n            }\r\n\r\n            scriptScopeTable.Dispose();\r\n            luaOnDestroy = null;\r\n            luaUpdate = null;\r\n            luaStart = null;\r\n            injections = null;\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting/LuaBehaviour.cs.meta",
    "content": "fileFormatVersion: 2\nguid: b9173d38911503c4a9a371b0760bdd15\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting/LuaTestScript.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal speed = 10\r\nlocal lightCpnt = nil\r\n\r\nfunction start()\r\n\tprint(\"lua start...\")\r\n\tprint(\"injected object\", lightObject)\r\n\tlightCpnt= lightObject:GetComponent(typeof(CS.UnityEngine.Light))\r\nend\r\n\r\nfunction update()\r\n\tlocal r = CS.UnityEngine.Vector3.up * CS.UnityEngine.Time.deltaTime * speed\r\n\tself.transform:Rotate(r)\r\n\tlightCpnt.color = CS.UnityEngine.Color(CS.UnityEngine.Mathf.Sin(CS.UnityEngine.Time.time) / 2 + 0.5, 0, 0, 1)\r\nend\r\n\r\nfunction ondestroy()\r\n    print(\"lua destroy\")\r\nend\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting/LuaTestScript.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 7cfed86298c2da543b693ffd8436367a\nTextScriptImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting/U3DScripting.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 6d9b7cd8ac592564796c9c24b3636677\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/02_U3DScripting.meta",
    "content": "fileFormatVersion: 2\nguid: afd3fcbd8a9d48945b874adff2c0aa6d\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/03_UIEvent/ButtonInteraction.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nfunction start()\r\n\tprint(\"lua start...\")\r\n\r\n\tself:GetComponent(\"Button\").onClick:AddListener(function()\r\n\t\tprint(\"clicked, you input is '\" ..input:GetComponent(\"InputField\").text ..\"'\")\r\n\tend)\r\nend\r\n"
  },
  {
    "path": "Assets/XLua/Examples/03_UIEvent/ButtonInteraction.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 9b998ff8754d165438f1f34adb4f3d7e\nTextScriptImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/03_UIEvent/UI.unity.meta",
    "content": "fileFormatVersion: 2\nguid: f835eeddd75e9f74d95c957aa7ca44b2\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/03_UIEvent.meta",
    "content": "fileFormatVersion: 2\nguid: e4adea5640e39ca43a54b81b93ea2f32\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/04_LuaObjectOrented/InvokeLua.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System;\r\nusing UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class PropertyChangedEventArgs : EventArgs\r\n    {\r\n        public string name;\r\n        public object value;\r\n    }\r\n\r\n    public class InvokeLua : MonoBehaviour\r\n    {\r\n        [CSharpCallLua]\r\n        public interface ICalc\r\n        {\r\n            event EventHandler<PropertyChangedEventArgs> PropertyChanged;\r\n\r\n            int Add(int a, int b);\r\n            int Mult { get; set; }\r\n\r\n            object this[int index] { get; set; }\r\n        }\r\n\r\n        [CSharpCallLua]\r\n        public delegate ICalc CalcNew(int mult, params string[] args);\r\n\r\n        private string script = @\"\r\n                local calc_mt = {\r\n                    __index = {\r\n                        Add = function(self, a, b)\r\n                            return (a + b) * self.Mult\r\n                        end,\r\n                        \r\n                        get_Item = function(self, index)\r\n                            return self.list[index + 1]\r\n                        end,\r\n\r\n                        set_Item = function(self, index, value)\r\n                            self.list[index + 1] = value\r\n                            self:notify({name = index, value = value})\r\n                        end,\r\n                        \r\n                        add_PropertyChanged = function(self, delegate)\r\n\t                        if self.notifylist == nil then\r\n\t\t                        self.notifylist = {}\r\n\t                        end\r\n\t                        table.insert(self.notifylist, delegate)\r\n                            print('add',delegate)\r\n                        end,\r\n                                                \r\n                        remove_PropertyChanged = function(self, delegate)\r\n                            for i=1, #self.notifylist do\r\n\t\t                        if CS.System.Object.Equals(self.notifylist[i], delegate) then\r\n\t\t\t                        table.remove(self.notifylist, i)\r\n\t\t\t                        break\r\n\t\t                        end\r\n\t                        end\r\n                            print('remove', delegate)\r\n                        end,\r\n\r\n                        notify = function(self, evt)\r\n\t                        if self.notifylist ~= nil then\r\n\t\t                        for i=1, #self.notifylist do\r\n\t\t\t                        self.notifylist[i](self, evt)\r\n\t\t                        end\r\n\t                        end\t\r\n                        end,\r\n                    }\r\n                }\r\n\r\n                Calc = {\r\n\t                New = function (mult, ...)\r\n                        print(...)\r\n                        return setmetatable({Mult = mult, list = {'aaaa','bbbb','cccc'}}, calc_mt)\r\n                    end\r\n                }\r\n\t        \";\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n            Test(luaenv);//调用了带可变参数的delegate，函数结束都不会释放delegate，即使置空并调用GC\r\n            luaenv.Dispose();\r\n        }\r\n\r\n        void Test(LuaEnv luaenv)\r\n        {\r\n            luaenv.DoString(script);\r\n            CalcNew calc_new = luaenv.Global.GetInPath<CalcNew>(\"Calc.New\");\r\n            ICalc calc = calc_new(10, \"hi\", \"john\"); //constructor\r\n            Debug.Log(\"sum(*10) =\" + calc.Add(1, 2));\r\n            calc.Mult = 100;\r\n            Debug.Log(\"sum(*100)=\" + calc.Add(1, 2));\r\n\r\n            Debug.Log(\"list[0]=\" + calc[0]);\r\n            Debug.Log(\"list[1]=\" + calc[1]);\r\n\r\n            calc.PropertyChanged += Notify;\r\n            calc[1] = \"dddd\";\r\n            Debug.Log(\"list[1]=\" + calc[1]);\r\n\r\n            calc.PropertyChanged -= Notify;\r\n\r\n            calc[1] = \"eeee\";\r\n            Debug.Log(\"list[1]=\" + calc[1]);\r\n        }\r\n\r\n        void Notify(object sender, PropertyChangedEventArgs e)\r\n        {\r\n            Debug.Log(string.Format(\"{0} has property changed {1}={2}\", sender, e.name, e.value));\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Examples/04_LuaObjectOrented/InvokeLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 2e190b5ef59b7a84dbb262cfd11f9107\ntimeCreated: 1478591887\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/04_LuaObjectOrented/InvokeLua.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 554d570d8b369434ba8a099ebafee542\ntimeCreated: 1478591886\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/04_LuaObjectOrented.meta",
    "content": "fileFormatVersion: 2\nguid: 8d8101efdb236b04b9b7cfa592bee593\nfolderAsset: yes\ntimeCreated: 1480404151\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/05_NoGc/NoGc.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    [GCOptimize]\r\n    [LuaCallCSharp]\r\n    public struct Pedding\r\n    {\r\n        public byte c;\r\n    }\r\n\r\n    [GCOptimize]\r\n    [LuaCallCSharp]\r\n    public struct MyStruct\r\n    {\r\n        public MyStruct(int p1, int p2)\r\n        {\r\n            a = p1;\r\n            b = p2;\r\n            c = p2;\r\n            e.c = (byte)p1;\r\n        }\r\n        public int a;\r\n        public int b;\r\n        public decimal c;\r\n        public Pedding e;\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public enum MyEnum\r\n    {\r\n        E1,\r\n        E2\r\n    }\r\n\r\n    [CSharpCallLua]\r\n    public delegate int IntParam(int p);\r\n\r\n    [CSharpCallLua]\r\n    public delegate Vector3 Vector3Param(Vector3 p);\r\n\r\n    [CSharpCallLua]\r\n    public delegate MyStruct CustomValueTypeParam(MyStruct p);\r\n\r\n    [CSharpCallLua]\r\n    public delegate MyEnum EnumParam(MyEnum p);\r\n\r\n    [CSharpCallLua]\r\n    public delegate decimal DecimalParam(decimal p);\r\n\r\n    [CSharpCallLua]\r\n    public delegate void ArrayAccess(Array arr);\r\n\r\n    [CSharpCallLua]\r\n    public interface IExchanger\r\n    {\r\n        void exchange(Array arr);\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class NoGc : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = new LuaEnv();\r\n\r\n        IntParam f1;\r\n        Vector3Param f2;\r\n        CustomValueTypeParam f3;\r\n        EnumParam f4;\r\n        DecimalParam f5;\r\n\r\n        ArrayAccess farr;\r\n        Action flua;\r\n        IExchanger ie;\r\n        LuaFunction add;\r\n\r\n        [NonSerialized]\r\n        public double[] a1 = new double[] { 1, 2 };\r\n        [NonSerialized]\r\n        public Vector3[] a2 = new Vector3[] { new Vector3(1, 2, 3), new Vector3(4, 5, 6) };\r\n        [NonSerialized]\r\n        public MyStruct[] a3 = new MyStruct[] { new MyStruct(1, 2), new MyStruct(3, 4) };\r\n        [NonSerialized]\r\n        public MyEnum[] a4 = new MyEnum[] { MyEnum.E1, MyEnum.E2 };\r\n        [NonSerialized]\r\n        public decimal[] a5 = new decimal[] { 1.00001M, 2.00002M };\r\n\r\n        public float FloatParamMethod(float p)\r\n        {\r\n            return p;\r\n        }\r\n\r\n        public Vector3 Vector3ParamMethod(Vector3 p)\r\n        {\r\n            return p;\r\n        }\r\n\r\n        public MyStruct StructParamMethod(MyStruct p)\r\n        {\r\n            return p;\r\n        }\r\n\r\n        public MyEnum EnumParamMethod(MyEnum p)\r\n        {\r\n            return p;\r\n        }\r\n\r\n        public decimal DecimalParamMethod(decimal p)\r\n        {\r\n            return p;\r\n        }\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv.DoString(@\"\r\n                function id(...)\r\n                    return ...\r\n                end\r\n\r\n                function add(a, b) return a + b end\r\n            \r\n                function array_exchange(arr)\r\n                    arr[0], arr[1] = arr[1], arr[0]\r\n                end\r\n\r\n                local v3 = CS.UnityEngine.Vector3(7, 8, 9)\r\n                local vt = CS.XLuaTest.MyStruct(5, 6)\r\n\r\n                function lua_access_csharp()\r\n                    monoBehaviour:FloatParamMethod(123) --primitive\r\n                    monoBehaviour:Vector3ParamMethod(v3) --vector3\r\n                    local rnd = math.random(1, 100)\r\n                    local r = monoBehaviour:Vector3ParamMethod({x = 1, y = 2, z = rnd}) --vector3\r\n                    assert(r.x == 1 and r.y == 2 and r.z == rnd)\r\n                    monoBehaviour:StructParamMethod(vt) --custom struct\r\n                    r = monoBehaviour:StructParamMethod({a = 1, b = rnd, e = {c = rnd}})\r\n                    assert(r.b == rnd and r.e.c == rnd)\r\n                    monoBehaviour:EnumParamMethod(CS.XLuaTest.MyEnum.E2) --enum\r\n                    monoBehaviour:DecimalParamMethod(monoBehaviour.a5[0])\r\n                    monoBehaviour.a1[0], monoBehaviour.a1[1] = monoBehaviour.a1[1], monoBehaviour.a1[0] -- field\r\n                end\r\n\r\n                exchanger = {\r\n                    exchange = function(self, arr)\r\n                        array_exchange(arr)\r\n                    end\r\n                }\r\n\r\n                A = { B = { C = 789}}\r\n                GDATA = 1234;\r\n            \");\r\n\r\n            luaenv.Global.Set(\"monoBehaviour\", this);\r\n\r\n            luaenv.Global.Get(\"id\", out f1);\r\n            luaenv.Global.Get(\"id\", out f2);\r\n            luaenv.Global.Get(\"id\", out f3);\r\n            luaenv.Global.Get(\"id\", out f4);\r\n            luaenv.Global.Get(\"id\", out f5);\r\n\r\n            luaenv.Global.Get(\"array_exchange\", out farr);\r\n            luaenv.Global.Get(\"lua_access_csharp\", out flua);\r\n            luaenv.Global.Get(\"exchanger\", out ie);\r\n            luaenv.Global.Get(\"add\", out add);\r\n\r\n            luaenv.Global.Set(\"g_int\", 123);\r\n            luaenv.Global.Set(123, 456);\r\n            int i;\r\n            luaenv.Global.Get(\"g_int\", out i);\r\n            Debug.Log(\"g_int:\" + i);\r\n            luaenv.Global.Get(123, out i);\r\n            Debug.Log(\"123:\" + i);\r\n        }\r\n\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            // c# call lua function with value type but no gc (using delegate)\r\n            f1(1); // primitive type\r\n            f2(new Vector3(1, 2, 3)); // vector3\r\n            MyStruct mystruct1 = new MyStruct(5, 6);\r\n            f3(mystruct1); // custom complex value type\r\n            f4(MyEnum.E1); //enum\r\n            decimal dec1 = -32132143143100109.00010001010M;\r\n            f5(dec1); //decimal\r\n\r\n            // using LuaFunction.Func<T1, T2, TResult>\r\n            add.Func<int, int, int>(34, 56); // LuaFunction.Func<T1, T2, TResult>\r\n\r\n            // lua access c# value type array no gc\r\n            farr(a1); //primitive value type array\r\n            farr(a2); //vector3 array\r\n            farr(a3); //custom struct array\r\n            farr(a4); //enum arry\r\n            farr(a5); //decimal arry\r\n\r\n            // lua call c# no gc with value type\r\n            flua();\r\n\r\n            //c# call lua using interface\r\n            ie.exchange(a2);\r\n\r\n            //no gc LuaTable use\r\n            luaenv.Global.Set(\"g_int\", 456);\r\n            int i;\r\n            luaenv.Global.Get(\"g_int\", out i);\r\n\r\n            luaenv.Global.Set(123.0001, mystruct1);\r\n            MyStruct mystruct2;\r\n            luaenv.Global.Get(123.0001, out mystruct2);\r\n\r\n            decimal dec2 = 0.0000001M;\r\n            luaenv.Global.Set((byte)12, dec1);\r\n            luaenv.Global.Get((byte)12, out dec2);\r\n\r\n            int gdata = luaenv.Global.Get<int>(\"GDATA\");\r\n            luaenv.Global.SetInPath(\"GDATA\", gdata + 1);\r\n\r\n            int abc = luaenv.Global.GetInPath<int>(\"A.B.C\");\r\n            luaenv.Global.SetInPath(\"A.B.C\", abc + 1);\r\n\r\n            luaenv.Tick();\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            f1 =  null;\r\n            f2 = null;\r\n            f3 = null;\r\n            f4 = null;\r\n            f5 = null;\r\n            farr = null;\r\n            flua = null;\r\n            ie = null;\r\n            add = null;\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/05_NoGc/NoGc.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 577a670e2d7ad5e4691e30c9249edf3e\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/05_NoGc/NoGc.unity.meta",
    "content": "fileFormatVersion: 2\nguid: fa308fa7f40ec0348addeff1475bb164\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/05_NoGc.meta",
    "content": "fileFormatVersion: 2\nguid: 1e2eb0ecfd63eea4f820ff8575288639\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Coroutine.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 15727d4119afc7a47b7d3284ca6990db\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/CoroutineTest.cs",
    "content": "﻿using UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class CoroutineTest : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.DoString(\"require 'coruntine_test'\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/CoroutineTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 07b1a6730b144ab479c11ab079e2eb68\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Coroutine_Runner.cs",
    "content": "using UnityEngine;\r\nusing XLua;\r\nusing System.Collections.Generic;\r\nusing System.Collections;\r\nusing System;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class Coroutine_Runner : MonoBehaviour\r\n    {\r\n    }\r\n\r\n\r\n    public static class CoroutineConfig\r\n    {\r\n        [LuaCallCSharp]\r\n        public static List<Type> LuaCallCSharp\r\n        {\r\n            get\r\n            {\r\n                return new List<Type>()\r\n            {\r\n                typeof(WaitForSeconds),\r\n                typeof(WWW)\r\n            };\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Coroutine_Runner.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 9abe5e754f1c63247a254d53e34d1e40\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Resources/coruntine_test.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal cs_coroutine = (require 'cs_coroutine')\r\n\r\nlocal a = cs_coroutine.start(function()\r\n    print('coroutine a started')\r\n\r\n\tcoroutine.yield(cs_coroutine.start(function() \r\n\t\tprint('coroutine b stated inside cotoutine a')\r\n\t\tcoroutine.yield(CS.UnityEngine.WaitForSeconds(1))\r\n\t\tprint('i am coroutine b')\r\n\tend))\r\n\tprint('coroutine b finish')\r\n\r\n\twhile true do\r\n\t\tcoroutine.yield(CS.UnityEngine.WaitForSeconds(1))\r\n\t\tprint('i am coroutine a')\r\n\tend\r\nend)\r\n\r\ncs_coroutine.start(function()\r\n    print('stop coroutine a after 5 seconds')\r\n\tcoroutine.yield(CS.UnityEngine.WaitForSeconds(5))\r\n\tcs_coroutine.stop(a)\r\n    print('coroutine a stoped')\r\nend)\r\n\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Resources/coruntine_test.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 13b04a36211388b45849c1fb7dd7b956\ntimeCreated: 1463554448\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Resources/cs_coroutine.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal util = require 'xlua.util'\r\n\r\nlocal gameobject = CS.UnityEngine.GameObject('Coroutine_Runner')\r\nCS.UnityEngine.Object.DontDestroyOnLoad(gameobject)\r\nlocal cs_coroutine_runner = gameobject:AddComponent(typeof(CS.XLuaTest.Coroutine_Runner))\r\n\r\nreturn {\r\n    start = function(...)\r\n\t    return cs_coroutine_runner:StartCoroutine(util.cs_generator(...))\r\n\tend;\r\n\r\n\tstop = function(coroutine)\r\n\t    cs_coroutine_runner:StopCoroutine(coroutine)\r\n\tend\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Resources/cs_coroutine.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 4f3d9471c4ae0aa47957ff35c0df972e\ntimeCreated: 1463555211\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 08227e7d0eccf384aab65fb19928d3ef\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/06_Coroutine.meta",
    "content": "fileFormatVersion: 2\nguid: 6a4f6da9af53d384d8228950f82ae562\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/AsyncTest.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing XLua;\r\nusing System.Collections.Generic;\r\nusing System;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class AsyncTest : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.DoString(\"require 'async_test'\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/AsyncTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: b5b2cbe03aa30c446ab56ae6f520277b\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/AsyncTest.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 50ee330b40bfcc54cbdfb1c7c79a02d9\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/MessageBox.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing UnityEngine.UI;\r\nusing XLua;\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing UnityEngine.Events;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class MessageBox : MonoBehaviour\r\n    {\r\n\r\n        public static void ShowAlertBox(string message, string title, Action onFinished = null)\r\n        {\r\n            var alertPanel = GameObject.Find(\"Canvas\").transform.Find(\"AlertBox\");\r\n            if (alertPanel == null)\r\n            {\r\n                alertPanel = (Instantiate(Resources.Load(\"AlertBox\")) as GameObject).transform;\r\n                alertPanel.gameObject.name = \"AlertBox\";\r\n                alertPanel.SetParent(GameObject.Find(\"Canvas\").transform);\r\n                alertPanel.localPosition = new Vector3(-6f, -6f, 0f);\r\n            }\r\n\r\n            alertPanel.Find(\"title\").GetComponent<Text>().text = title;\r\n            alertPanel.Find(\"message\").GetComponent<Text>().text = message;\r\n\r\n            var button = alertPanel.Find(\"alertBtn\").GetComponent<Button>();\r\n            UnityAction onclick = () =>\r\n            {\r\n                if (onFinished != null)\r\n                {\r\n                    onFinished();\r\n                }\r\n                button.onClick.RemoveAllListeners();\r\n                alertPanel.gameObject.SetActive(false);\r\n            };\r\n            //防止消息框未关闭时多次被调用\r\n            button.onClick.RemoveAllListeners();\r\n            button.onClick.AddListener(onclick);\r\n            alertPanel.gameObject.SetActive(true);\r\n        }\r\n\r\n        public static void ShowConfirmBox(string message, string title, Action<bool> onFinished = null)\r\n        {\r\n            var confirmPanel = GameObject.Find(\"Canvas\").transform.Find(\"ConfirmBox\");\r\n            if (confirmPanel == null)\r\n            {\r\n                confirmPanel = (Instantiate(Resources.Load(\"ConfirmBox\")) as GameObject).transform;\r\n                confirmPanel.gameObject.name = \"ConfirmBox\";\r\n                confirmPanel.SetParent(GameObject.Find(\"Canvas\").transform);\r\n                confirmPanel.localPosition = new Vector3(-8f, -18f, 0f);\r\n            }\r\n\r\n            confirmPanel.Find(\"confirmTitle\").GetComponent<Text>().text = title;\r\n            confirmPanel.Find(\"conmessage\").GetComponent<Text>().text = message;\r\n\r\n            var confirmBtn = confirmPanel.Find(\"confirmBtn\").GetComponent<Button>();\r\n            var cancelBtn = confirmPanel.Find(\"cancelBtn\").GetComponent<Button>();\r\n            Action cleanup = () =>\r\n            {\r\n                confirmBtn.onClick.RemoveAllListeners();\r\n                cancelBtn.onClick.RemoveAllListeners();\r\n                confirmPanel.gameObject.SetActive(false);\r\n            };\r\n\r\n            UnityAction onconfirm = () =>\r\n            {\r\n                if (onFinished != null)\r\n                {\r\n                    onFinished(true);\r\n                }\r\n                cleanup();\r\n            };\r\n\r\n            UnityAction oncancel = () =>\r\n            {\r\n                if (onFinished != null)\r\n                {\r\n                    onFinished(false);\r\n                }\r\n                cleanup();\r\n            };\r\n\r\n            //防止消息框未关闭时多次被调用\r\n            confirmBtn.onClick.RemoveAllListeners();\r\n            confirmBtn.onClick.AddListener(onconfirm);\r\n            cancelBtn.onClick.RemoveAllListeners();\r\n            cancelBtn.onClick.AddListener(oncancel);\r\n            confirmPanel.gameObject.SetActive(true);\r\n        }\r\n    }\r\n\r\n    public static class MessageBoxConfig\r\n    {\r\n        [CSharpCallLua]\r\n        public static List<Type> CSharpCallLua = new List<Type>()\r\n    {\r\n        typeof(Action),\r\n        typeof(Action<bool>),\r\n        typeof(UnityAction),\r\n    };\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/MessageBox.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 20d92fd634185584eb982e0ad93a13a9\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/AlertBox.prefab.meta",
    "content": "fileFormatVersion: 2\nguid: dbfc57f47cf3853418df75ee656fdf90\nNativeFormatImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/ConfirmBox.prefab.meta",
    "content": "fileFormatVersion: 2\nguid: 18c683fc899b71146b50b40d8d5fe57a\nNativeFormatImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/async_test.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal util = require 'xlua.util'\r\nlocal message_box = require 'message_box'\r\n\r\n-------------------------async_recharge-----------------------------\r\nlocal function async_recharge(num, cb) --模拟的异步充值\r\n    print('requst server...')\r\n    cb(true, num)\r\nend\r\n\r\nlocal recharge = util.async_to_sync(async_recharge)\r\n-------------------------async_recharge end----------------------------\r\nlocal buy = function()\r\n    message_box.alert(\"您余额不足，请充值！\", \"余额提醒\")\r\n\tif message_box.confirm(\"确认充值10元吗？\", \"确认框\") then\r\n\t\tlocal r1, r2 = recharge(10)\r\n\t\tprint('recharge result:', r1, r2)\r\n\t\tmessage_box.alert(\"充值成功！\", \"提示\")\r\n\telse\r\n\t    print('cancel')\r\n\t    message_box.alert(\"取消充值！\", \"提示\")\r\n\tend\r\n\tprint('recharge finished')\r\nend\r\n--将按钮监听点击事件，绑定buy方法\r\nCS.UnityEngine.GameObject.Find(\"Button\"):GetComponent(\"Button\").onClick:AddListener(util.coroutine_call(buy))\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/async_test.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 40d0922483b73c8408f163088c9adc26\nTextScriptImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/message_box.lua.txt",
    "content": "﻿-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal util = require 'xlua.util'\r\n\r\nlocal sync_alert = util.async_to_sync(CS.XLuaTest.MessageBox.ShowAlertBox)\r\nlocal sync_confirm = util.async_to_sync(CS.XLuaTest.MessageBox.ShowConfirmBox) \r\n\r\n--构造alert和confirm函数\r\nreturn {\r\n    alert = function(message, title)\r\n\t\t sync_alert(message, title)\r\n    end;\r\n\t\r\n\tconfirm = function(message, title)\r\n\t\tlocal ret = sync_confirm(message, title)\r\n\t\treturn ret == true\r\n    end;\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources/message_box.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 8cdad601850bd814c9a22efaff55928f\nTextScriptImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: bf7e4682a398f4243b4b200c3a8a1e35\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/07_AsyncTest.meta",
    "content": "fileFormatVersion: 2\nguid: 9c07f66d94f59e944b4b4e50357847c2\nfolderAsset: yes\ntimeCreated: 1480404151\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/Editor/HotfixTestCfg.cs",
    "content": "﻿using System;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\n\r\nnamespace XLuaTest.Editor\r\n{\r\n    public static class HotfixTestCfg\r\n    {\r\n        [Hotfix]\r\n        public static List<Type> by_field = new List<Type>()\r\n        {\r\n            typeof(HotfixTest),\r\n            typeof(HotfixCalc),\r\n            typeof(GenericClass<>),\r\n            typeof(InnerTypeTest),\r\n            typeof(BaseTest),\r\n            typeof(StructTest),\r\n            typeof(GenericStruct<>),\r\n            typeof(StatefullTest)\r\n        };\r\n\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/Editor/HotfixTestCfg.cs.meta",
    "content": "fileFormatVersion: 2\nguid: f5a751e2beef908429c5908d9e24696a\nMonoImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/Editor.meta",
    "content": "fileFormatVersion: 2\nguid: 2def16135c9e7644bae2869109a0b48e\nfolderAsset: yes\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest.cs",
    "content": "﻿using UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    [Hotfix]\r\n    public class HotfixTest : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = new LuaEnv();\r\n\r\n        private int tick = 0;\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (++tick % 50 == 0)\r\n            {\r\n                Debug.Log(\">>>>>>>>Update in C#, tick = \" + tick);\r\n            }\r\n        }\r\n\r\n        void OnGUI()\r\n        {\r\n            if (GUI.Button(new Rect(10, 10, 300, 80), \"Hotfix\"))\r\n            {\r\n                luaenv.DoString(@\"\r\n                xlua.hotfix(CS.XLuaTest.HotfixTest, 'Update', function(self)\r\n                    self.tick = self.tick + 1\r\n                    if (self.tick % 50) == 0 then\r\n                        print('<<<<<<<<Update in lua, tick = ' .. self.tick)\r\n                    end\r\n                end)\r\n            \");\r\n            }\r\n\r\n            string chHint = @\"在运行该示例之前，请细致阅读xLua文档，并执行以下步骤：\r\n\r\n1.宏定义：添加 HOTFIX_ENABLE 到 'Edit > Project Settings > Player > Other Settings > Scripting Define Symbols'。\r\n（注意：各平台需要分别设置）\r\n\r\n2.生成代码：执行 'XLua > Generate Code' 菜单，等待Unity编译完成。\r\n\r\n3.注入：执行 'XLua > Hotfix Inject In Editor' 菜单。注入成功会打印 'hotfix inject finish!' 或者 'had injected!' 。\";\r\n            string enHint = @\"Read documents carefully before you run this example, then follow the steps below:\r\n\r\n1. Define: Add 'HOTFIX_ENABLE' to 'Edit > Project Settings > Player > Other Settings > Scripting Define Symbols'.\r\n(Note: Each platform needs to set this respectively)\r\n\r\n2.Generate Code: Execute menu 'XLua > Generate Code', wait for Unity's compilation.\r\n\r\n\r\n3.Inject: Execute menu 'XLua > Hotfix Inject In Editor'.There should be 'hotfix inject finish!' or 'had injected!' print in the Console if the Injection is successful.\";\r\n            GUIStyle style = GUI.skin.textArea;\r\n            style.normal.textColor = Color.red;\r\n            style.fontSize = 16;\r\n            GUI.TextArea(new Rect(10, 100, 500, 290), chHint, style);\r\n            GUI.TextArea(new Rect(10, 400, 500, 290), enHint, style);\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 496cbe3b76e0a8649b6b6e429a322a9a\ntimeCreated: 1482318818\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 71b8de6dc619ca64da460a7200f00b9c\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest2.cs",
    "content": "﻿using UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    [Hotfix]\r\n    public class HotfixCalc\r\n    {\r\n        public int Add(int a, int b)\r\n        {\r\n            return a - b;\r\n        }\r\n\r\n        public Vector3 Add(Vector3 a, Vector3 b)\r\n        {\r\n            return a - b;\r\n        }\r\n\r\n        public int TestOut(int a, out double b, ref string c)\r\n        {\r\n            b = a + 2;\r\n            c = \"wrong version\";\r\n            return a + 3;\r\n        }\r\n\r\n        public int TestOut(int a, out double b, ref string c, GameObject go)\r\n        {\r\n            return TestOut(a, out b, ref c);\r\n        }\r\n\r\n        public T Test1<T>()\r\n        {\r\n            return default(T);\r\n        }\r\n\r\n        public T1 Test2<T1, T2, T3>(T1 a, out T2 b, ref T3 c)\r\n        {\r\n            b = default(T2);\r\n            return a;\r\n        }\r\n\r\n        public static int Test3<T>(T a)\r\n        {\r\n            return 0;\r\n        }\r\n\r\n        public static void Test4<T>(T a)\r\n        {\r\n        }\r\n\r\n        public void Test5<T>(int a, params T[] arg)\r\n        {\r\n\r\n        }\r\n    }\r\n\r\n    public class NoHotfixCalc\r\n    {\r\n        public int Add(int a, int b)\r\n        {\r\n            return a + b;\r\n        }\r\n    }\r\n\r\n    [Hotfix]\r\n    public class GenericClass<T>\r\n    {\r\n        T a;\r\n\r\n        public GenericClass(T a)\r\n        {\r\n            this.a = a;\r\n        }\r\n\r\n        public void Func1()\r\n        {\r\n            Debug.Log(\"a=\" + a);\r\n        }\r\n\r\n        public T Func2()\r\n        {\r\n            return default(T);\r\n        }\r\n    }\r\n\r\n    [Hotfix]\r\n    public class InnerTypeTest\r\n    {\r\n        public void Foo()\r\n        {\r\n            _InnerStruct ret = Bar();\r\n            Debug.Log(\"{x=\" + ret.x + \",y= \" + ret.y + \"}\");\r\n        }\r\n\r\n        struct _InnerStruct\r\n        {\r\n            public int x;\r\n            public int y;\r\n        }\r\n\r\n        _InnerStruct Bar()\r\n        {\r\n            return new _InnerStruct { x = 1, y = 2 };\r\n        }\r\n    }\r\n\r\n    public class BaseTestHelper\r\n    {\r\n\r\n    }\r\n\r\n    public class BaseTestBase<T> : BaseTestHelper\r\n    {\r\n        public virtual void Foo(int p)\r\n        {\r\n            Debug.Log(\"BaseTestBase<>.Foo, p = \" + p);\r\n        }\r\n    }\r\n\r\n    [Hotfix]\r\n    [LuaCallCSharp]\r\n    public class BaseTest : BaseTestBase<InnerTypeTest>\r\n    {\r\n        public override void Foo(int p)\r\n        {\r\n            Debug.Log(\"BaseTest<>.Foo, p = \" + p);\r\n        }\r\n\r\n        public void Proxy(int p)\r\n        {\r\n            base.Foo(p);\r\n        }\r\n\r\n        public override string ToString()\r\n        {\r\n            return base.ToString();\r\n        }\r\n    }\r\n\r\n    [Hotfix]\r\n    public struct StructTest\r\n    {\r\n        GameObject go;\r\n        public StructTest(GameObject go)\r\n        {\r\n            this.go = go;\r\n        }\r\n\r\n        public GameObject GetGo(int a, object b)\r\n        {\r\n            return go;\r\n        }\r\n\r\n        public override string ToString()\r\n        {\r\n            return base.ToString();\r\n        }\r\n\r\n        public string Proxy()\r\n        {\r\n            return base.ToString();\r\n        }\r\n    }\r\n\r\n    [Hotfix]\r\n    public struct GenericStruct<T>\r\n    {\r\n        T a;\r\n\r\n        public GenericStruct(T a)\r\n        {\r\n            this.a = a;\r\n        }\r\n\r\n        public T GetA(int p)\r\n        {\r\n            return a;\r\n        }\r\n    }\r\n\r\n    public class HotfixTest2 : MonoBehaviour\r\n    {\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n            HotfixCalc calc = new HotfixCalc();\r\n            NoHotfixCalc ordinaryCalc = new NoHotfixCalc();\r\n\r\n            int CALL_TIME = 100 * 1000 * 1000;\r\n            var start = System.DateTime.Now;\r\n            for (int i = 0; i < CALL_TIME; i++)\r\n            {\r\n                calc.Add(2, 1);\r\n            }\r\n            var d1 = (System.DateTime.Now - start).TotalMilliseconds;\r\n            Debug.Log(\"Hotfix using:\" + d1);\r\n\r\n            start = System.DateTime.Now;\r\n            for (int i = 0; i < CALL_TIME; i++)\r\n            {\r\n                ordinaryCalc.Add(2, 1);\r\n            }\r\n            var d2 = (System.DateTime.Now - start).TotalMilliseconds;\r\n            Debug.Log(\"No Hotfix using:\" + d2);\r\n\r\n            Debug.Log(\"drop:\" + ((d1 - d2) / d1));\r\n\r\n            Debug.Log(\"Before Fix: 2 + 1 = \" + calc.Add(2, 1));\r\n            Debug.Log(\"Before Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = \" + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3)));\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.HotfixCalc, 'Add', function(self, a, b)\r\n                return a + b\r\n            end)\r\n        \");\r\n            Debug.Log(\"After Fix: 2 + 1 = \" + calc.Add(2, 1));\r\n            Debug.Log(\"After Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = \" + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3)));\r\n\r\n            double num;\r\n            string str = \"hehe\";\r\n            int ret = calc.TestOut(100, out num, ref str);\r\n            Debug.Log(\"ret = \" + ret + \", num = \" + num + \", str = \" + str);\r\n\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.HotfixCalc, 'TestOut', function(self, a, c, go)\r\n                    print('TestOut', self, a, c, go)\r\n                    if go then error('test error') end\r\n                    return a + 10, a + 20, 'right version'\r\n                end)\r\n        \");\r\n            str = \"hehe\";\r\n            ret = calc.TestOut(100, out num, ref str);\r\n            Debug.Log(\"ret = \" + ret + \", num = \" + num + \", str = \" + str);\r\n\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.HotfixCalc, {\r\n                 Test1 = function(self)\r\n                    print('Test1', self)\r\n                    return 1\r\n                 end;\r\n                 Test2 = function(self, a, b)\r\n                     print('Test1', self, a, b)\r\n                     return a + 10, 1024, b\r\n                 end;\r\n                 Test3 = function(a)\r\n                    print(a)\r\n                    return 10\r\n                 end;\r\n                 Test4 = function(a)\r\n                    print(a)\r\n                 end;\r\n                 Test5 = function(self, a, ...)\r\n                    print('Test4', self, a, ...)\r\n                 end\r\n            })\r\n        \");\r\n\r\n            int r1 = calc.Test1<int>();\r\n            double r2 = calc.Test1<double>();\r\n\r\n            Debug.Log(\"r1:\" + r1 + \",r2:\" + r2);\r\n\r\n            string ss = \"heihei\";\r\n            int r3 = calc.Test2(r1, out r2, ref ss);\r\n            Debug.Log(\"r1:\" + r1 + \",r2:\" + r2 + \",r3:\" + r3 + \",ss:\" + ss);\r\n\r\n            r3 = HotfixCalc.Test3(\"test3\");\r\n            r3 = HotfixCalc.Test3(2);\r\n            r3 = HotfixCalc.Test3(this);\r\n            Debug.Log(\"r3:\" + r3);\r\n            HotfixCalc.Test4(this);\r\n            HotfixCalc.Test4(2);\r\n            calc.Test5(10, \"a\", \"b\", \"c\");\r\n            calc.Test5(10, 1, 3, 5);\r\n\r\n            Debug.Log(\"----------------------before------------------------\");\r\n            TestStateful();\r\n            System.GC.Collect();\r\n            System.GC.WaitForPendingFinalizers();\r\n            luaenv.DoString(@\"\r\n            local util = require 'xlua.util'\r\n            xlua.hotfix(CS.XLuaTest.StatefullTest, {\r\n                ['.ctor'] = function(csobj)\r\n                    util.state(csobj, {evt = {}, start = 0, prop = 0})\r\n                end;\r\n                set_AProp = function(self, v)\r\n                    print('set_AProp', v)\r\n                    self.prop = v\r\n                end;\r\n                get_AProp = function(self)\r\n                    return self.prop\r\n                end;\r\n                get_Item = function(self, k)\r\n                    print('get_Item', k)\r\n                    return 1024\r\n                end;\r\n                set_Item = function(self, k, v)\r\n                    print('set_Item', k, v)\r\n                end;\r\n                add_AEvent = function(self, cb)\r\n                    print('add_AEvent', cb)\r\n                    table.insert(self.evt, cb)\r\n                end;\r\n                remove_AEvent = function(self, cb)\r\n                   print('remove_AEvent', cb)\r\n                   for i, v in ipairs(self.evt) do\r\n                       if v == cb then\r\n                           table.remove(self.evt, i)\r\n                           break\r\n                       end\r\n                   end\r\n                end;\r\n                Start = function(self)\r\n                    print('Start')\r\n                    for _, cb in ipairs(self.evt) do\r\n                        cb(self.start, 2)\r\n                    end\r\n                    self.start = self.start + 1\r\n                end;\r\n                StaticFunc = function(a, b, c)\r\n                   print(a, b, c)\r\n                end;\r\n                GenericTest = function(self, a)\r\n                   print(self, a)\r\n                end;\r\n                Finalize = function(self)\r\n                   print('Finalize', self)\r\n                end\r\n           })\r\n        \");\r\n            Debug.Log(\"----------------------after------------------------\");\r\n            TestStateful();\r\n            luaenv.FullGc();\r\n            System.GC.Collect();\r\n            System.GC.WaitForPendingFinalizers();\r\n\r\n            var genericObj = new GenericClass<double>(1.1);\r\n            genericObj.Func1();\r\n            Debug.Log(genericObj.Func2());\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.GenericClass(CS.System.Double), {\r\n                ['.ctor'] = function(obj, a)\r\n                    print('GenericClass<double>', obj, a)\r\n                end;\r\n                Func1 = function(obj)\r\n                    print('GenericClass<double>.Func1', obj)\r\n                end;\r\n                Func2 = function(obj)\r\n                    print('GenericClass<double>.Func2', obj)\r\n                    return 1314\r\n                end\r\n            })\r\n        \");\r\n            genericObj = new GenericClass<double>(1.1);\r\n            genericObj.Func1();\r\n            Debug.Log(genericObj.Func2());\r\n\r\n            InnerTypeTest itt = new InnerTypeTest();\r\n            itt.Foo();\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.InnerTypeTest, 'Bar', function(obj)\r\n                    print('lua Bar', obj)\r\n                    return {x = 10, y = 20}\r\n                end)\r\n        \");\r\n            itt.Foo();\r\n\r\n            StructTest st = new StructTest(gameObject);\r\n            Debug.Log(\"go=\" + st.GetGo(123, \"john\"));\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.StructTest, 'GetGo', function(self, a, b)\r\n                    print('GetGo', self, a, b)\r\n                    return nil\r\n                end)\r\n        \");\r\n            Debug.Log(\"go=\" + st.GetGo(123, \"john\"));\r\n\r\n            GenericStruct<int> gs = new GenericStruct<int>(1);\r\n            Debug.Log(\"gs.GetA()=\" + gs.GetA(123));\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.GenericStruct(CS.System.Int32), 'GetA', function(self, a)\r\n                    print('GetA',self, a)\r\n                    return 789\r\n                end)\r\n        \");\r\n            Debug.Log(\"gs.GetA()=\" + gs.GetA(123));\r\n\r\n            try\r\n            {\r\n                calc.TestOut(100, out num, ref str, gameObject);\r\n            }\r\n            catch (LuaException e)\r\n            {\r\n                Debug.Log(\"throw in lua an catch in c# ok, e.Message:\" + e.Message);\r\n            }\r\n\r\n\r\n            BaseTestBase<InnerTypeTest> bt = new BaseTest();\r\n            bt.Foo(1);\r\n            Debug.Log(bt);\r\n\r\n            luaenv.DoString(@\"\r\n            xlua.hotfix(CS.XLuaTest.BaseTest, 'Foo', function(self, p)\r\n                    print('BaseTest', p)\r\n                end)\r\n            xlua.hotfix(CS.XLuaTest.BaseTest, 'ToString', function(self)\r\n                    return '>>>' .. base(self):ToString()\r\n                end)\r\n        \");\r\n            bt.Foo(2);\r\n            Debug.Log(bt);\r\n        }\r\n\r\n        void TestStateful()\r\n        {\r\n            StatefullTest sft = new StatefullTest();\r\n            sft.AProp = 10;\r\n            Debug.Log(\"sft.AProp:\" + sft.AProp);\r\n            sft[\"1\"] = 1;\r\n            Debug.Log(\"sft['1']:\" + sft[\"1\"]);\r\n            System.Action<int, double> cb = (a, b) =>\r\n            {\r\n                Debug.Log(\"a:\" + a + \",b:\" + b);\r\n            };\r\n            sft.AEvent += cb;\r\n            sft.Start();\r\n            sft.Start();\r\n            sft.AEvent -= cb;\r\n            sft.Start();\r\n            StatefullTest.StaticFunc(1, 2);\r\n            StatefullTest.StaticFunc(\"e\", 3, 4);\r\n            sft.GenericTest(1);\r\n            sft.GenericTest(\"hehe\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest2.cs.meta",
    "content": "fileFormatVersion: 2\nguid: beae9af8e5f127546a20bde154f9a580\ntimeCreated: 1482398730\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/HotfixTest2.unity.meta",
    "content": "fileFormatVersion: 2\nguid: eb945840f7055384cbf1a3fb17903afe\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/StatefullTest.cs",
    "content": "﻿using UnityEngine;\r\n\r\nnamespace XLuaTest\r\n{\r\n    [XLua.Hotfix]\r\n    public class StatefullTest\r\n    {\r\n        public StatefullTest()\r\n        {\r\n\r\n        }\r\n\r\n        public StatefullTest(int a, int b)\r\n        {\r\n            if (a > 0)\r\n            {\r\n                return;\r\n            }\r\n\r\n            Debug.Log(\"a=\" + a);\r\n            if (b > 0)\r\n            {\r\n                return;\r\n            }\r\n            else\r\n            {\r\n                if (a + b > 0)\r\n                {\r\n                    return;\r\n                }\r\n            }\r\n            Debug.Log(\"b=\" + b);\r\n        }\r\n\r\n        public int AProp\r\n        {\r\n            get;\r\n            set;\r\n        }\r\n\r\n        public event System.Action<int, double> AEvent;\r\n\r\n        public int this[string field]\r\n        {\r\n            get\r\n            {\r\n                return 1;\r\n            }\r\n            set\r\n            {\r\n            }\r\n        }\r\n\r\n        public void Start()\r\n        {\r\n\r\n        }\r\n\r\n        void Update()\r\n        {\r\n\r\n        }\r\n\r\n        public void GenericTest<T>(T a)\r\n        {\r\n\r\n        }\r\n\r\n        static public void StaticFunc(int a, int b)\r\n        {\r\n        }\r\n        static public void StaticFunc(string a, int b, int c)\r\n        {\r\n        }\r\n\r\n        ~StatefullTest()\r\n        {\r\n            Debug.Log(\"~StatefullTest\");\r\n        }\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix/StatefullTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: b093a617e1bf7984c8824ba9d40afbe0\ntimeCreated: 1482643106\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/08_Hotfix.meta",
    "content": "fileFormatVersion: 2\nguid: 08ebe6e4959b8c34aad49a439411e429\nfolderAsset: yes\ntimeCreated: 1482318804\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod/Foo.cs",
    "content": "﻿using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing XLua;\n\nnamespace XLuaTest\r\n{\r\n\r\n    [LuaCallCSharp]\r\n    public class Foo1Parent\r\n    {\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class Foo2Parent\r\n    {\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class Foo1Child : Foo1Parent\r\n    {\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class Foo2Child : Foo2Parent\r\n    {\r\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public class Foo\r\n    {\r\n        #region Supported methods\n\r\n        public void Test1<T>(T a) where T : Foo1Parent\r\n        {\r\n            Debug.Log(string.Format(\"Test1<{0}>\", typeof(T)));\r\n        }\r\n\r\n        public T1 Test2<T1, T2>(T1 a, T2 b, GameObject c) where T1 : Foo1Parent where T2 : Foo2Parent\r\n        {\r\n            Debug.Log(string.Format(\"Test2<{0},{1}>\", typeof(T1), typeof(T2)), c);\r\n            return a;\r\n        }\r\n\r\n        #endregion\n\r\n        #region Unsupported methods\n\r\n        /// <summary>\n        /// 不支持生成lua的泛型方法（没有泛型约束）\n        /// </summary>\n        public void UnsupportedMethod1<T>(T a)\r\n        {\r\n            Debug.Log(\"UnsupportedMethod1\");\r\n        }\r\n\r\n        /// <summary>\n        /// 不支持生成lua的泛型方法（缺少带约束的泛型参数）\n        /// </summary>\n        public void UnsupportedMethod2<T>() where T : Foo1Parent\r\n        {\r\n            Debug.Log(string.Format(\"UnsupportedMethod2<{0}>\", typeof(T)));\r\n        }\r\n\r\n        /// <summary>\n        /// 不支持生成lua的泛型方法（泛型约束必须为class）\n        /// </summary>\n        public void UnsupportedMethod3<T>(T a) where T : IDisposable\r\n        {\r\n            Debug.Log(string.Format(\"UnsupportedMethod3<{0}>\", typeof(T)));\r\n        }\r\n\r\n        #endregion\n    }\r\n\r\n    [LuaCallCSharp]\r\n    public static class FooExtension\r\n    {\r\n        public static void PlainExtension(this Foo1Parent a)\r\n        {\r\n            Debug.Log(\"PlainExtension\");\r\n        }\r\n\r\n        public static T Extension1<T>(this T a) where T : Foo1Parent\r\n        {\r\n            Debug.Log(string.Format(\"Extension1<{0}>\", typeof(T)));\r\n            return a;\r\n        }\r\n\r\n        public static T Extension2<T>(this T a, GameObject b) where T : Foo1Parent\r\n        {\r\n            Debug.Log(string.Format(\"Extension2<{0}>\", typeof(T)), b);\r\n            return a;\r\n        }\r\n\r\n        public static void Extension2<T1, T2>(this T1 a, T2 b) where T1 : Foo1Parent where T2 : Foo2Parent\r\n        {\r\n            Debug.Log(string.Format(\"Extension2<{0},{1}>\", typeof(T1), typeof(T2)));\r\n        }\r\n\r\n        public static T UnsupportedExtension<T>(this GameObject obj) where T : Component\r\n        {\r\n            return obj.GetComponent<T>();\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod/Foo.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 3894dbe73b280d44e9c58b8e33c93995\ntimeCreated: 1486348303\nlicenseType: Free\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod/GenericMethod.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 19477d725133da049be476cb4caedf7d\ntimeCreated: 1486350257\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod/GenericMethodExample.cs",
    "content": "﻿using UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n\r\n    public class GenericMethodExample : MonoBehaviour\r\n    {\r\n        private const string script = @\"\r\n        local foo1 = CS.XLuaTest.Foo1Child()\r\n        local foo2 = CS.XLuaTest.Foo2Child()\r\n\r\n        local obj = CS.UnityEngine.GameObject()\r\n        foo1:PlainExtension()\r\n        foo1:Extension1()\r\n        foo1:Extension2(obj) -- overload1\r\n        foo1:Extension2(foo2) -- overload2\r\n        \r\n        local foo = CS.XLuaTest.Foo()\r\n        foo:Test1(foo1)\r\n        foo:Test2(foo1,foo2,obj)\r\n\";\r\n        private LuaEnv env;\r\n\r\n        private void Start()\r\n        {\r\n            env = new LuaEnv();\r\n            env.DoString(script);\r\n        }\r\n\r\n        private void Update()\r\n        {\r\n            if (env != null)\r\n                env.Tick();\r\n        }\r\n\r\n        private void OnDestroy()\r\n        {\r\n            env.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod/GenericMethodExample.cs.meta",
    "content": "fileFormatVersion: 2\nguid: ce77e35c083e6fe4c88cb64a97466161\ntimeCreated: 1486353566\nlicenseType: Free\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/09_GenericMethod.meta",
    "content": "fileFormatVersion: 2\nguid: 0c2493fccdb6a2141933ed2ec5d4786b\nfolderAsset: yes\ntimeCreated: 1486348159\nlicenseType: Free\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources/signatured1.lua.bytes.meta",
    "content": "fileFormatVersion: 2\nguid: 44928e4c9a6ef3542b8dc8f3fed4c9d8\ntimeCreated: 1489377018\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources/signatured2.lua.bytes",
    "content": "\u00129ў+4D\u000b\u001eb\u0016r\u001b⁘*\u0005Fən\u0013[b\\؈k\u001b\u0019\u0014\u001ap/9+x\u0015D.C\u0012\u0013\u0007=\u000f8-P^jq*<FViz\u0012*U+ \u001aT\"0g\u001eprint('signatured2: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources/signatured2.lua.bytes.meta",
    "content": "fileFormatVersion: 2\nguid: dfe267f4b0fe1a349a23184f840622bd\ntimeCreated: 1489377018\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources/signatured3.lua.bytes",
    "content": "j?\u001eSc\u0017=D\u000e'c+\\TF\u0003]OS'{Kr_\u00132\"F۴@kߐvm<\u0004\u0018+c0t33I+G{\f]s*#0]#\nIˬ={A*Bp*\u001bprint('signatured3: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources/signatured3.lua.bytes.meta",
    "content": "fileFormatVersion: 2\nguid: 25beaf0816ae33a43b715f68010bbfdd\ntimeCreated: 1489377018\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 2e7d0896355998b4fa5efcfa1b9f1f84\nfolderAsset: yes\ntimeCreated: 1489376947\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/SignatureLoaderTest.cs",
    "content": "﻿using UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\nusing System.IO;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class SignatureLoaderTest : MonoBehaviour\r\n    {\r\n        public static string PUBLIC_KEY = \"BgIAAACkAABSU0ExAAQAAAEAAQBVDDC5QJ+0uSCJA+EysIC9JBzIsd6wcXa+FuTGXcsJuwyUkabwIiT2+QEjP454RwfSQP8s4VZE1m4npeVD2aDnY4W6ZNJe+V+d9Drt9b+9fc/jushj/5vlEksGBIIC/plU4ZaR6/nDdMIs/JLvhN8lDQthwIYnSLVlPmY1Wgyatw==\";\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n#if UNITY_EDITOR\r\n            luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>\r\n            {\r\n                filepath = Application.dataPath + \"/XLua/Examples/10_SignatureLoader/\" + filepath.Replace('.', '/') + \".lua\";\r\n                if (File.Exists(filepath))\r\n                {\r\n                    return File.ReadAllBytes(filepath);\r\n                }\r\n                else\r\n                {\r\n                    return null;\r\n                }\r\n            }));\r\n#else //为了让手机也能测试\r\n        luaenv.AddLoader(new SignatureLoader(PUBLIC_KEY, (ref string filepath) =>\r\n        {\r\n            filepath = filepath.Replace('.', '/') + \".lua\";\r\n            TextAsset file = (TextAsset)Resources.Load(filepath);\r\n            if (file != null)\r\n            {\r\n                return file.bytes;\r\n            }\r\n            else\r\n            {\r\n                return null;\r\n            }\r\n        }));\r\n#endif\r\n            luaenv.DoString(@\"\r\n            require 'signatured1'\r\n            require 'signatured2'\r\n        \");\r\n            luaenv.Dispose();\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/SignatureLoaderTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 552b1f9f9174fe446907357379f128b2\ntimeCreated: 1489222400\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/SignatureLoaderTest.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 7bf24e9d2076ecd4ba65687e9d238c34\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/key_ras",
    "content": "<RSAKeyValue><Modulus>t5oMWjVmPmW1SCeGwGELDSXfhO+S/CzCdMP565GW4VSZ/gKCBAZLEuWb/2PIuuPPfb2/9e069J1f+V7SZLqFY+eg2UPlpSdu1kRW4Sz/QNIHR3iOPyMB+fYkIvCmkZQMuwnLXcbkFr52cbDescgcJL2AsDLhA4kgubSfQLkwDFU=</Modulus><Exponent>AQAB</Exponent><P>6O+mc4PRwjoKd7rryroYhseCmb1vJIfsM86kIHgu+mUgFUSFsyzgKRbhq79qvbqkGp0KTxQcOCMjv9v+n/dIoQ==</P><Q>ycflANIkcfOCpKI8CYmlL2+oNNy4QiabyAfXmvY8WfpF4t8ED6mqxwhaf5SlwFqwndNtDH6a2cSlnVqFAhAjNQ==</Q><DP>Vbb6FT/IjCQ3fd92rN7V76Ky2EfxAgxSSq4bjycqglF8ANd6K3iz8+rLmBuT98UaZgCrrnXD/JRRr2QQymSAgQ==</DP><DQ>kc6FV2OCfGknJUoqMgYpvC5mENTRvNNjTFcGYG7AS5CDAZ5/s8W5pxsNMhW69FVUPKezrAysXuIvfpYTeNsqZQ==</DQ><InverseQ>ki6U0JwjiCnxikfyPBgj6dYBRStCCASi4rczfXvIKLUNZSk+PW3LCMrEMOf8B7wUXc53e3JF4io2FEL6Wdr16w==</InverseQ><D>kVx+sSEcDQTbjP/2WPO8GzHEEOzY05zgbDAI+6/t5ALmVMxJgcQ1xgVSB9ZJw2XADk6f36ZuCeNbbATd0HA4UHORz1Ao8xuWscPbnBobg4cOstL/9Zbd/hxtRJgHF4lMw1BSLrLywqCgPTi4dFA2qpWHrWkRjcrKosahnyvpt4E=</D></RSAKeyValue>"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/key_ras.meta",
    "content": "fileFormatVersion: 2\nguid: 059b7b0b901925a49a1aab1169c15dee\ntimeCreated: 1489371190\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/key_ras.pub",
    "content": "BgIAAACkAABSU0ExAAQAAAEAAQBVDDC5QJ+0uSCJA+EysIC9JBzIsd6wcXa+FuTGXcsJuwyUkabwIiT2+QEjP454RwfSQP8s4VZE1m4npeVD2aDnY4W6ZNJe+V+d9Drt9b+9fc/jushj/5vlEksGBIIC/plU4ZaR6/nDdMIs/JLvhN8lDQthwIYnSLVlPmY1Wgyatw=="
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/key_ras.pub.meta",
    "content": "fileFormatVersion: 2\nguid: ccd4f9e35fcee3b439e31a15449a1765\ntimeCreated: 1489371190\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured1.lua",
    "content": "require 'signatured3'\r\nprint('signatured1: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured1.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 213d1592ca01d9a4fba0477875fcd2ef\ntimeCreated: 1489371350\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured2.lua",
    "content": "print('signatured2: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured2.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 384893ab7180e0c448d6521421f1859f\ntimeCreated: 1489371350\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured3.lua",
    "content": "print('signatured3: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles/signatured3.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 8771a42e51c869743bd8cbf0511b8afd\ntimeCreated: 1489371350\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/otherfiles.meta",
    "content": "fileFormatVersion: 2\nguid: 41c79b0f7edf32d48a7a81664f1e96ec\nfolderAsset: yes\ntimeCreated: 1489371190\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/signatured1.lua.meta",
    "content": "fileFormatVersion: 2\nguid: c9d3a7e24d889a7418ad19a390178f88\ntimeCreated: 1489370693\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/signatured2.lua",
    "content": "\u00129ў+4D\u000b\u001eb\u0016r\u001b⁘*\u0005Fən\u0013[b\\؈k\u001b\u0019\u0014\u001ap/9+x\u0015D.C\u0012\u0013\u0007=\u000f8-P^jq*<FViz\u0012*U+ \u001aT\"0g\u001eprint('signatured2: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/signatured2.lua.meta",
    "content": "fileFormatVersion: 2\nguid: dceaef6c0e4f511489f2a9d6d198afa7\ntimeCreated: 1489370693\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/signatured3.lua",
    "content": "j?\u001eSc\u0017=D\u000e'c+\\TF\u0003]OS'{Kr_\u00132\"F۴@kߐvm<\u0004\u0018+c0t33I+G{\f]s*#0]#\nIˬ={A*Bp*\u001bprint('signatured3: this source was signatured!')"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader/signatured3.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 4ee183ed57618894dab4d3b9a68790cf\ntimeCreated: 1489370693\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/10_SignatureLoader.meta",
    "content": "fileFormatVersion: 2\nguid: c91c5604efec9954b85970057e91b759\nfolderAsset: yes\ntimeCreated: 1489222333\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/11_RawObject/RawObject.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 338b384cc2d92bf42b28fbe2f172c4ec\ntimeCreated: 1520415330\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/11_RawObject/RawObjectTest.cs",
    "content": "﻿using UnityEngine;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public class RawObjectTest : MonoBehaviour\r\n    {\r\n        public static void PrintType(object o)\r\n        {\r\n            Debug.Log(\"type:\" + o.GetType() + \", value:\" + o);\r\n        }\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n            //直接传1234到一个object参数，xLua将选择能保留最大精度的long来传递\r\n            luaenv.DoString(\"CS.XLuaTest.RawObjectTest.PrintType(1234)\");\r\n            //通过一个继承RawObject的类，能实现指明以一个int来传递\r\n            luaenv.DoString(\"CS.XLuaTest.RawObjectTest.PrintType(CS.XLua.Cast.Int32(1234))\");\r\n            luaenv.Dispose();\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/11_RawObject/RawObjectTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 5c9d37dc5ac4e44448bd8858d68604e5\ntimeCreated: 1498116708\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/11_RawObject.meta",
    "content": "fileFormatVersion: 2\nguid: 7e8c24c5719ad6b4b8b2d9ecf19cfec7\nfolderAsset: yes\ntimeCreated: 1498116676\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/12_ReImplementInLua/ReImplementInLua.cs",
    "content": "﻿using UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n\r\n    [GCOptimize(OptimizeFlag.PackAsTable)]\r\n    public struct PushAsTableStruct\r\n    {\r\n        public int x;\r\n        public int y;\r\n    }\r\n\r\n    public class ReImplementInLua : MonoBehaviour\r\n    {\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            LuaEnv luaenv = new LuaEnv();\r\n            //这两个例子都必须生成代码才能正常运行\r\n            //例子1：改造Vector3\r\n            //沿用Vector3原来的映射方案Vector3 -> userdata，但是把Vector3的方法实现改为lua实现，通过xlua.genaccessor实现不经过C#直接操作内存\r\n            //改为不经过C#的好处是性能更高，而且你可以省掉相应的生成代码以达成省text段的效果\r\n            //仍然沿用映射方案的好处是userdata比table更省内存，但操作字段比table性能稍低，当然，你也可以结合例子2的思路，把Vector3也改为映射到table\r\n            luaenv.DoString(@\"\r\n            function test_vector3(title, v1, v2)\r\n               print(title)\r\n               v1.x = 100\r\n               print(v1.x, v1.y, v1.z)\r\n               print(v1, v2)\r\n               print(v1 + v2)\r\n               v1:Set(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z)\r\n               print(v1)\r\n               print(CS.UnityEngine.Vector3.Normalize(v1))\r\n            end\r\n            test_vector3('----before change metatable----', CS.UnityEngine.Vector3(1, 2, 3), CS.UnityEngine.Vector3(7, 8, 9))\r\n\r\n            local get_x, set_x = xlua.genaccessor(0, 8)\r\n            local get_y, set_y = xlua.genaccessor(4, 8)\r\n            local get_z, set_z = xlua.genaccessor(8, 8)\r\n            \r\n            local fields_getters = {\r\n                x = get_x, y = get_y, z = get_z\r\n            }\r\n            local fields_setters = {\r\n                x = set_x, y = set_y, z = set_z\r\n            }\r\n\r\n            local ins_methods = {\r\n                Set = function(o, x, y, z)\r\n                    set_x(o, x)\r\n                    set_y(o, y)\r\n                    set_z(o, z)\r\n                end\r\n            }\r\n\r\n            local mt = {\r\n                __index = function(o, k)\r\n                    --print('__index', k)\r\n                    if ins_methods[k] then return ins_methods[k] end\r\n                    return fields_getters[k] and fields_getters[k](o)\r\n                end,\r\n\r\n                __newindex = function(o, k, v)\r\n                    if fields_setters[k] then fields_setters[k](o, v) else error('no such field ' .. k) end\r\n                end,\r\n\r\n                __tostring = function(o)\r\n                    return string.format('vector3 { %f, %f, %f}', o.x, o.y, o.z)\r\n                end,\r\n\r\n                __add = function(a, b)\r\n                    return CS.UnityEngine.Vector3(a.x + b.x, a.y + b.y, a.z + b.z)\r\n                end\r\n            }\r\n\r\n            xlua.setmetatable(CS.UnityEngine.Vector3, mt)\r\n            test_vector3('----after change metatable----', CS.UnityEngine.Vector3(1, 2, 3), CS.UnityEngine.Vector3(7, 8, 9))\r\n        \");\r\n\r\n            Debug.Log(\"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\");\r\n\r\n            //例子2：struct映射到table改造\r\n            //PushAsTableStruct传送到lua侧将会是table，例子里头还为这个table添加了一个成员方法SwapXY，静态方法Print，打印格式化，以及构造函数\r\n            luaenv.DoString(@\"\r\n            local mt = {\r\n                __index = {\r\n                    SwapXY = function(o) --成员函数\r\n                        o.x, o.y = o.y, o.x\r\n                    end\r\n                },\r\n\r\n                __tostring = function(o) --打印格式化函数\r\n                    return string.format('struct { %d, %d}', o.x, o.y)\r\n                end,\r\n            }\r\n\r\n            xlua.setmetatable(CS.XLuaTest.PushAsTableStruct, mt)\r\n            \r\n            local PushAsTableStruct = {\r\n                Print = function(o) --静态函数\r\n                    print(o.x, o.y)\r\n                end\r\n            }\r\n\r\n            setmetatable(PushAsTableStruct, {\r\n                __call = function(_, x, y) --构造函数\r\n                    return setmetatable({x = x, y = y}, mt)\r\n                end\r\n            })\r\n            \r\n            xlua.setclass(CS.XLuaTest, 'PushAsTableStruct', PushAsTableStruct)\r\n        \");\r\n\r\n            PushAsTableStruct test;\r\n            test.x = 100;\r\n            test.y = 200;\r\n            luaenv.Global.Set(\"from_cs\", test);\r\n\r\n            luaenv.DoString(@\"\r\n            print('--------------from csharp---------------------')\r\n            assert(type(from_cs) == 'table')\r\n            print(from_cs)\r\n            CS.XLuaTest.PushAsTableStruct.Print(from_cs)\r\n            from_cs:SwapXY()\r\n            print(from_cs)\r\n\r\n            print('--------------from lua---------------------')\r\n            local from_lua = CS.XLuaTest.PushAsTableStruct(4, 5)\r\n            assert(type(from_lua) == 'table')\r\n            print(from_lua)\r\n            CS.XLuaTest.PushAsTableStruct.Print(from_lua)\r\n            from_lua:SwapXY()\r\n            print(from_lua)\r\n        \");\r\n\r\n            luaenv.Dispose();\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/12_ReImplementInLua/ReImplementInLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: cffb50bfe4f87494c8a4851450dfb340\ntimeCreated: 1501577402\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/12_ReImplementInLua/ReImplementInLua.unity.meta",
    "content": "fileFormatVersion: 2\nguid: c4695949a6b369345a5ecdcc82c946c1\ntimeCreated: 1520415435\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/12_ReImplementInLua.meta",
    "content": "fileFormatVersion: 2\nguid: 58695f06576335e46bf1769637db2255\nfolderAsset: yes\ntimeCreated: 1501577332\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI/Editor/BuildFromCLI.cs",
    "content": "﻿using System;\r\nusing UnityEditor;\r\nusing UnityEngine;\r\nusing CSObjectWrapEditor;\r\nusing XLua;\r\n\r\nnamespace XLuaTest\r\n{\r\n    public static class BuildFromCLI\r\n    {\r\n        /// <summary>\r\n        /// 此方法通过Unity菜单调用。\r\n        /// </summary>\r\n        [MenuItem(\"XLua/Examples/13_BuildFromCLI\")]\r\n        public static void BuildFromUnityMenu()\r\n        {\r\n            var outputDir = Application.dataPath.Substring(0, Application.dataPath.Length - \"/Assets\".Length) + \"/output\";\r\n            var packageName = \"xLuaGame.exe\";\r\n            build(outputDir, packageName);\r\n        }\r\n\r\n        /// <summary>\r\n        /// 此方法通过命令行调用。\r\n        /// </summary>\r\n        public static void Build()\r\n        {\r\n            var outputDir = Application.dataPath.Substring(0, Application.dataPath.Length - \"/Assets\".Length) + \"/output\";\r\n            var packageName = \"xLuaGame.exe\";\r\n            build(outputDir, packageName);\r\n        }\r\n\r\n        private static void build(string outputDir, string packageName)\r\n        {\r\n            Debug.Log(\"构建开始：输出目录 \" + outputDir);\r\n            DelegateBridge.Gen_Flag = true;\r\n            Generator.ClearAll();\r\n            Generator.GenAll();\r\n\r\n            var levels = new string[0];\r\n            var locationPathName = string.Format(\"{0}/{1}\", outputDir, packageName);\r\n            var target = BuildTarget.StandaloneWindows64;\r\n            var options = BuildOptions.None;\r\n            BuildPipeline.BuildPlayer(levels, locationPathName, target, options);\r\n            Debug.Log(\"构建完成\");\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI/Editor/BuildFromCLI.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1fd3fcc7509943c45af11f63df13d137\ntimeCreated: 1531790057\nlicenseType: Free\nMonoImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI/Editor.meta",
    "content": "fileFormatVersion: 2\nguid: 266e4ca9a64f701449b0468b9a4f1d32\nfolderAsset: yes\ntimeCreated: 1531790107\nlicenseType: Free\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI/build.bat",
    "content": "@echo off\r\necho =======================================================\r\necho ˵ʾʾеUnityԶ\r\necho       C#ԴοBuildFromCLI.cs\r\necho.\r\necho ע1޸ıļ·\r\necho        UNITY_PATHunity.exe·\r\necho        PROJECT_PATH̸Ŀ¼·\r\necho        LOG_PATH־·\r\necho ע2ִȹرUnity\r\necho =======================================================\r\n\r\nset UNITY_PATH=\"D:\\Program Files (x86)\\Unity 2017.4.3f1\\Editor\\Unity.exe\"\r\nset PROJECT_PATH=\"D:\\work\\xLua_forsakenyang\"\r\nset LOG_PATH=\"D:\\work\\xLua_forsakenyang\\output\\log.txt\"\r\n\r\necho start...\r\n\r\nrem ȷ־Ŀ¼\r\nfor %%a in (%LOG_PATH%) do (\r\n    set log_root=%%~dpa\r\n)    \r\nif not exist %log_root% mkdir %log_root%\r\n\r\n%UNITY_PATH% -batchmode -quit -projectPath %PROJECT_PATH% -logFile %LOG_PATH% -executeMethod XLuaTest.BuildFromCLI.Build\r\n\r\necho done.\r\npause"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI/build.bat.meta",
    "content": "fileFormatVersion: 2\nguid: 165d35780a78009469ee772b2ab15e81\ntimeCreated: 1531791711\nlicenseType: Free\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/13_BuildFromCLI.meta",
    "content": "fileFormatVersion: 2\nguid: 7ea057dec6022624fa54a0ccc12648ee\nfolderAsset: yes\ntimeCreated: 1531790017\nlicenseType: Free\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/HotfixAsyncAwaitTest.cs",
    "content": "﻿using System.Collections;\nusing System.Collections.Generic;\nusing System.Threading.Tasks;\nusing UnityEngine;\nusing XLua;\n\nnamespace XLuaTest\n{\n    [Hotfix]\n    public partial class HotfixAsyncAwaitTest : MonoBehaviour\n    {\n        [Hotfix]\n        [ContextMenu(\"Method1\")]\n        public void Method1()\n        {\n            Debug.Log($\"Method1 in C#!\");\n        }\n\n        [Hotfix]\n        [ContextMenu(\"AsyncMethod1\")]\n#pragma warning disable CS1998 // 异步方法缺少 \"await\" 运算符，将以同步方式运行\n        public async void AsyncMethod1()\n#pragma warning restore CS1998 // 异步方法缺少 \"await\" 运算符，将以同步方式运行\n        {\n            Debug.Log($\"AsyncMethod1 in C#!\");\n        }\n\n        [Hotfix]\n        [ContextMenu(\"AsyncMethod2\")]\n        public async void AsyncMethod2()\n        {\n            Debug.Log($\"AsyncMethod2 in C#!    001\");\n            await Task.Delay(1000);\n            Debug.Log($\"AsyncMethod2 in C#!    002\");\n        }\n\n        [Hotfix]\n        [ContextMenu(\"AsyncMethod3\")]\n        public async void AsyncMethod3()\n        {\n            Debug.Log($\"AsyncMethod3 in C#!    001\");\n            await Task.Delay(1000);\n            Debug.Log($\"AsyncMethod3 in C#!    002\");\n            await MyTask();\n            Debug.Log($\"AsyncMethod3 in C#!    003\");\n        }\n\n        [Hotfix]\n        [ContextMenu(\"AsyncMethod4\")]\n        public async void AsyncMethod4()\n        {\n            Debug.Log($\"AsyncMethod4 in C#!    001\");\n            var result = await MyTask1();\n            Debug.Log($\"AsyncMethod4 in C#!    002    MyTask1 Result:{result}\");\n        }\n\n        [Hotfix]\n        [ContextMenu(\"MyTask\")]\n        public async Task MyTask()\n        {\n            Debug.Log($\"MyTask in C#!    001\");\n            await Task.Delay(1000);\n            Debug.Log($\"MyTask in C#!    002\");\n            return;\n        }\n\n        [Hotfix]\n        [ContextMenu(\"MyTask1\")]\n        public async Task<int> MyTask1()\n        {\n            Debug.Log($\"MyTask1 in C#!    001\");\n            await Task.Delay(1000);\n            Debug.Log($\"MyTask1 in C#!    002\");\n            return 9999;\n        }\n\n        [Hotfix]\n        [ContextMenu(\"MyTask2\")]\n        public Task<int> MyTask2()\n        {\n            Debug.Log($\"MyTask2 in C#!    001\");\n            return Task.FromResult(9998);\n        }\n    }\n\n    public partial class HotfixAsyncAwaitTest\n    {\n        public TextAsset Method1Lua;\n        public TextAsset AsyncMethod1Lua;\n        public TextAsset AsyncMethod2Lua;\n        public TextAsset AsyncMethod3Lua;\n        public TextAsset AsyncMethod4Lua;\n        public TextAsset MyTaskLua;\n        public TextAsset MyTask1Lua;\n        public TextAsset MyTask2Lua;\n\n        internal static LuaEnv luaEnv = new LuaEnv(); //all lua behaviour shared one luaenv only!\n\n        [ContextMenu(\"DoHotfix Method1\")]\n        public void DoHotfixMethod1()\n        {\n            // 执行脚本\n            luaEnv.DoString(Method1Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix AsyncMethod1\")]\n        public void DoHotfixAsyncMethod1()\n        {\n            // 执行脚本\n            luaEnv.DoString(AsyncMethod1Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix AsyncMethod2\")]\n        public void DoHotfixAsyncMethod2()\n        {\n            // 执行脚本\n            luaEnv.DoString(AsyncMethod2Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix AsyncMethod3\")]\n        public void DoHotfixAsyncMethod3()\n        {\n            // 执行脚本\n            luaEnv.DoString(AsyncMethod3Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix AsyncMethod4\")]\n        public void DoHotfixAsyncMethod4()\n        {\n            // 执行脚本\n            luaEnv.DoString(AsyncMethod4Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix MyTask\")]\n        public void DoHotfixMyTask()\n        {\n            // 执行脚本\n            luaEnv.DoString(MyTaskLua.text);\n        }\n\n        [ContextMenu(\"DoHotfix MyTask1\")]\n        public void DoHotfixMyTask1()\n        {\n            // 执行脚本\n            luaEnv.DoString(MyTask1Lua.text);\n        }\n\n        [ContextMenu(\"DoHotfix MyTask2\")]\n        public void DoHotfixMyTask2()\n        {\n            // 执行脚本\n            luaEnv.DoString(MyTask2Lua.text);\n        }\n\n\n        void OnGUI()\n        {\n            Vector2 size = new Vector2(200, 40);\n            Vector2 position = new Vector2(600, 100);\n            Vector2 rightPposition = position + new Vector2(240, 0);\n            int inteval = 50;\n\n\n            if (GUI.Button(new Rect(position, size), nameof(Method1)))\n            {\n                Method1();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixMethod1)))\n            {\n                DoHotfixMethod1();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(AsyncMethod1)))\n            {\n                AsyncMethod1();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixAsyncMethod1)))\n            {\n                DoHotfixAsyncMethod1();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(AsyncMethod2)))\n            {\n                AsyncMethod2();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixAsyncMethod2)))\n            {\n                DoHotfixAsyncMethod2();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(AsyncMethod3)))\n            {\n                AsyncMethod3();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixAsyncMethod3)))\n            {\n                DoHotfixAsyncMethod3();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(AsyncMethod4)))\n            {\n                AsyncMethod4();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixAsyncMethod4)))\n            {\n                DoHotfixAsyncMethod4();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(MyTask)))\n            {\n                MyTask();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixMyTask)))\n            {\n                DoHotfixMyTask();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(MyTask1)))\n            {\n                MyTask1();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixMyTask1)))\n            {\n                DoHotfixMyTask1();\n            }\n\n            position.y += inteval;\n            rightPposition.y += inteval;\n\n            if (GUI.Button(new Rect(position, size), nameof(MyTask2)))\n            {\n                MyTask2();\n            }\n\n            if (GUI.Button(new Rect(rightPposition, size), nameof(DoHotfixMyTask2)))\n            {\n                DoHotfixMyTask2();\n            }\n\n\n            string chHint = @\"在运行该示例之前，请细致阅读xLua文档，并执行以下步骤：\n\n1.宏定义：添加 HOTFIX_ENABLE 到 'Edit > Project Settings > Player > Other Settings > Scripting Define Symbols'。\n（注意：各平台需要分别设置）\n\n2.生成代码：执行 'XLua > Generate Code' 菜单，等待Unity编译完成。\n\n3.注入：执行 'XLua > Hotfix Inject In Editor' 菜单。注入成功会打印 'hotfix inject finish!' 或者 'had injected!' 。\";\n            string enHint = @\"Read documents carefully before you run this example, then follow the steps below:\n\n1. Define: Add 'HOTFIX_ENABLE' to 'Edit > Project Settings > Player > Other Settings > Scripting Define Symbols'.\n(Note: Each platform needs to set this respectively)\n\n2.Generate Code: Execute menu 'XLua > Generate Code', wait for Unity's compilation.\n\n\n3.Inject: Execute menu 'XLua > Hotfix Inject In Editor'.There should be 'hotfix inject finish!' or 'had injected!' print in the Console if the Injection is successful.\";\n            GUIStyle style = GUI.skin.textArea;\n            style.normal.textColor = Color.red;\n            style.fontSize = 16;\n            GUI.TextArea(new Rect(10, 100, 500, 290), chHint, style);\n            GUI.TextArea(new Rect(10, 400, 500, 290), enHint, style);\n        }\n    }\n}\n\n\n\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/HotfixAsyncAwaitTest.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 95b78f460e49eea41a858079fd008ef3\nMonoImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/HotfixAsyncAwaitTest.unity",
    "content": "%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!29 &1\nOcclusionCullingSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 2\n  m_OcclusionBakeSettings:\n    smallestOccluder: 5\n    smallestHole: 0.25\n    backfaceThreshold: 100\n  m_SceneGUID: 00000000000000000000000000000000\n  m_OcclusionCullingData: {fileID: 0}\n--- !u!104 &2\nRenderSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 9\n  m_Fog: 0\n  m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}\n  m_FogMode: 3\n  m_FogDensity: 0.01\n  m_LinearFogStart: 0\n  m_LinearFogEnd: 300\n  m_AmbientSkyColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}\n  m_AmbientEquatorColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}\n  m_AmbientGroundColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}\n  m_AmbientIntensity: 1\n  m_AmbientMode: 3\n  m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}\n  m_SkyboxMaterial: {fileID: 0}\n  m_HaloStrength: 0.5\n  m_FlareStrength: 1\n  m_FlareFadeSpeed: 3\n  m_HaloTexture: {fileID: 0}\n  m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}\n  m_DefaultReflectionMode: 0\n  m_DefaultReflectionResolution: 128\n  m_ReflectionBounces: 1\n  m_ReflectionIntensity: 1\n  m_CustomReflection: {fileID: 0}\n  m_Sun: {fileID: 0}\n  m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}\n  m_UseRadianceAmbientProbe: 0\n--- !u!157 &4\nLightmapSettings:\n  m_ObjectHideFlags: 0\n  serializedVersion: 12\n  m_GIWorkflowMode: 1\n  m_GISettings:\n    serializedVersion: 2\n    m_BounceScale: 1\n    m_IndirectOutputScale: 1\n    m_AlbedoBoost: 1\n    m_EnvironmentLightingMode: 0\n    m_EnableBakedLightmaps: 1\n    m_EnableRealtimeLightmaps: 0\n  m_LightmapEditorSettings:\n    serializedVersion: 12\n    m_Resolution: 1\n    m_BakeResolution: 50\n    m_AtlasSize: 1024\n    m_AO: 1\n    m_AOMaxDistance: 1\n    m_CompAOExponent: 1\n    m_CompAOExponentDirect: 0\n    m_ExtractAmbientOcclusion: 0\n    m_Padding: 2\n    m_LightmapParameters: {fileID: 0}\n    m_LightmapsBakeMode: 1\n    m_TextureCompression: 0\n    m_FinalGather: 0\n    m_FinalGatherFiltering: 1\n    m_FinalGatherRayCount: 256\n    m_ReflectionCompression: 2\n    m_MixedBakeMode: 1\n    m_BakeBackend: 0\n    m_PVRSampling: 1\n    m_PVRDirectSampleCount: 32\n    m_PVRSampleCount: 512\n    m_PVRBounces: 2\n    m_PVREnvironmentSampleCount: 512\n    m_PVREnvironmentReferencePointCount: 2048\n    m_PVRFilteringMode: 0\n    m_PVRDenoiserTypeDirect: 0\n    m_PVRDenoiserTypeIndirect: 0\n    m_PVRDenoiserTypeAO: 0\n    m_PVRFilterTypeDirect: 0\n    m_PVRFilterTypeIndirect: 0\n    m_PVRFilterTypeAO: 0\n    m_PVREnvironmentMIS: 0\n    m_PVRCulling: 1\n    m_PVRFilteringGaussRadiusDirect: 1\n    m_PVRFilteringGaussRadiusIndirect: 5\n    m_PVRFilteringGaussRadiusAO: 2\n    m_PVRFilteringAtrousPositionSigmaDirect: 0.5\n    m_PVRFilteringAtrousPositionSigmaIndirect: 2\n    m_PVRFilteringAtrousPositionSigmaAO: 1\n    m_ExportTrainingData: 0\n    m_TrainingDataDestination: TrainingData\n    m_LightProbeSampleCountMultiplier: 4\n  m_LightingDataAsset: {fileID: 0}\n  m_LightingSettings: {fileID: 4890085278179872738, guid: 8c5ded13af488ad48bb6922d92d28040, type: 2}\n--- !u!196 &5\nNavMeshSettings:\n  serializedVersion: 2\n  m_ObjectHideFlags: 0\n  m_BuildSettings:\n    serializedVersion: 2\n    agentTypeID: 0\n    agentRadius: 0.5\n    agentHeight: 2\n    agentSlope: 45\n    agentClimb: 0.4\n    ledgeDropHeight: 0\n    maxJumpAcrossDistance: 0\n    minRegionArea: 2\n    manualCellSize: 0\n    cellSize: 0.16666666\n    manualTileSize: 0\n    tileSize: 256\n    accuratePlacement: 0\n    maxJobWorkers: 0\n    preserveTilesOutsideBounds: 0\n    debug:\n      m_Flags: 0\n  m_NavMeshData: {fileID: 0}\n--- !u!1 &1829375650\nGameObject:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  serializedVersion: 6\n  m_Component:\n  - component: {fileID: 1829375656}\n  - component: {fileID: 1829375655}\n  - component: {fileID: 1829375653}\n  - component: {fileID: 1829375652}\n  - component: {fileID: 1829375657}\n  m_Layer: 0\n  m_Name: Main Camera\n  m_TagString: MainCamera\n  m_Icon: {fileID: 0}\n  m_NavMeshLayer: 0\n  m_StaticEditorFlags: 0\n  m_IsActive: 1\n--- !u!81 &1829375652\nAudioListener:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  m_GameObject: {fileID: 1829375650}\n  m_Enabled: 1\n--- !u!124 &1829375653\nBehaviour:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  m_GameObject: {fileID: 1829375650}\n  m_Enabled: 1\n--- !u!20 &1829375655\nCamera:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  m_GameObject: {fileID: 1829375650}\n  m_Enabled: 1\n  serializedVersion: 2\n  m_ClearFlags: 1\n  m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}\n  m_projectionMatrixMode: 1\n  m_GateFitMode: 2\n  m_FOVAxisMode: 0\n  m_SensorSize: {x: 36, y: 24}\n  m_LensShift: {x: 0, y: 0}\n  m_FocalLength: 50\n  m_NormalizedViewPortRect:\n    serializedVersion: 2\n    x: 0\n    y: 0\n    width: 1\n    height: 1\n  near clip plane: 0.3\n  far clip plane: 1000\n  field of view: 60\n  orthographic: 0\n  orthographic size: 5\n  m_Depth: -1\n  m_CullingMask:\n    serializedVersion: 2\n    m_Bits: 4294967295\n  m_RenderingPath: -1\n  m_TargetTexture: {fileID: 0}\n  m_TargetDisplay: 0\n  m_TargetEye: 3\n  m_HDR: 0\n  m_AllowMSAA: 1\n  m_AllowDynamicResolution: 0\n  m_ForceIntoRT: 0\n  m_OcclusionCulling: 1\n  m_StereoConvergence: 10\n  m_StereoSeparation: 0.022\n--- !u!4 &1829375656\nTransform:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  m_GameObject: {fileID: 1829375650}\n  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}\n  m_LocalPosition: {x: 0, y: 1, z: -10}\n  m_LocalScale: {x: 1, y: 1, z: 1}\n  m_ConstrainProportionsScale: 0\n  m_Children: []\n  m_Father: {fileID: 0}\n  m_RootOrder: 0\n  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}\n--- !u!114 &1829375657\nMonoBehaviour:\n  m_ObjectHideFlags: 0\n  m_CorrespondingSourceObject: {fileID: 0}\n  m_PrefabInstance: {fileID: 0}\n  m_PrefabAsset: {fileID: 0}\n  m_GameObject: {fileID: 1829375650}\n  m_Enabled: 1\n  m_EditorHideFlags: 0\n  m_Script: {fileID: 11500000, guid: 95b78f460e49eea41a858079fd008ef3, type: 3}\n  m_Name: \n  m_EditorClassIdentifier: \n  Method1Lua: {fileID: 4900000, guid: a59f9c8e574bd1e468d14345150310b0, type: 3}\n  AsyncMethod1Lua: {fileID: 4900000, guid: 7adbdc2e78a73584b913b58f384be6a8, type: 3}\n  AsyncMethod2Lua: {fileID: 4900000, guid: 9c4e4d89f12c0f04eac6514685f20c97, type: 3}\n  AsyncMethod3Lua: {fileID: 4900000, guid: 891ada61bf6814041aaa71aa9e6b3672, type: 3}\n  AsyncMethod4Lua: {fileID: 4900000, guid: fb1cf630ec008e34fa7c390922442d07, type: 3}\n  MyTaskLua: {fileID: 4900000, guid: 88db0679d06b9f042894e74b462bb3ca, type: 3}\n  MyTask1Lua: {fileID: 4900000, guid: 042048e04fec74f41ab573d2a01e5569, type: 3}\n  MyTask2Lua: {fileID: 4900000, guid: 61677c80fedcddc49b602a7ae3d1b3b3, type: 3}\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/HotfixAsyncAwaitTest.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 7ece71c1ce3943d4b8b9d0d2bfdc531d\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod1.lua.txt",
    "content": "﻿xlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'AsyncMethod1', function(self)\n        CS.UnityEngine.Debug.Log(\"AsyncMethod1 in lua!\")\n    end\n)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod1.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 7adbdc2e78a73584b913b58f384be6a8\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod2.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\n\nlocal function AsyncMethod2(self)\n    CS.UnityEngine.Debug.Log(\"AsyncMethod2 in lua!    001\")\n    await(Task.Delay(1000), function ()\n        CS.UnityEngine.Debug.Log(\"AsyncMethod2 in lua!    002\")\n    end)\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'AsyncMethod2', AsyncMethod2)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod2.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 9c4e4d89f12c0f04eac6514685f20c97\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod3.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\n\nlocal function AsyncMethod3(self)\n    CS.UnityEngine.Debug.Log(\"AsyncMethod3 in lua!    001\")\n    await(Task.Delay(1000), function ()\n        CS.UnityEngine.Debug.Log(\"AsyncMethod3 in lua!    002\")\n        await(self:MyTask(), function ()\n            CS.UnityEngine.Debug.Log(\"AsyncMethod3 in lua!    003\")\n        end)\n    end)\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'AsyncMethod3', AsyncMethod3)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod3.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 891ada61bf6814041aaa71aa9e6b3672\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod4.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\n\nlocal function AsyncMethod4(self)\n    CS.UnityEngine.Debug.Log(\"AsyncMethod4 in lua!    001\")\n    await(self:MyTask1(), function (result)\n        CS.UnityEngine.Debug.Log(\"AsyncMethod4 in lua!    002    MyTask1 Result:\"..tostring(result))\n    end)\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'AsyncMethod4', AsyncMethod4)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/AsyncMethod4.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: fb1cf630ec008e34fa7c390922442d07\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/Method1.lua.txt",
    "content": "﻿xlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'Method1', function(self)\n        CS.UnityEngine.Debug.Log(\"Method1 in lua!\")\n    end\n)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/Method1.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: a59f9c8e574bd1e468d14345150310b0\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\nlocal TaskSource = CS.System.Threading.Tasks.TaskCompletionSource(CS.System.Int32)\n\nlocal function MyTask(self)\n    --使用TaskCompletionSource来模拟C#中async关键字\n    local source = TaskSource()\n\n    CS.UnityEngine.Debug.Log(\"MyTask in lua!    001\")\n    await(Task.Delay(1000), function ()\n        CS.UnityEngine.Debug.Log(\"MyTask in lua!    002\")\n        source:SetResult(0)\n    end)\n\n    return source.Task\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'MyTask', MyTask)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 88db0679d06b9f042894e74b462bb3ca\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask1.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\nlocal TaskSource = CS.System.Threading.Tasks.TaskCompletionSource(CS.System.Int32)\n\nlocal function MyTask1(self)\n    --使用TaskCompletionSource来模拟C#中async关键字\n    local source = TaskSource()\n\n    CS.UnityEngine.Debug.Log(\"MyTask1 in lua!    001\")\n    await(Task.Delay(1000), function ()\n        CS.UnityEngine.Debug.Log(\"MyTask1 in lua!    002\")\n        source:SetResult(9999)\n    end)\n\n    return source.Task\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'MyTask1', MyTask1)\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask1.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 042048e04fec74f41ab573d2a01e5569\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask2.lua.txt",
    "content": "﻿require 'await'\nlocal Task = CS.System.Threading.Tasks.Task\nlocal FromResult = xlua.get_generic_method(Task, 'FromResult')\nlocal FromIntResult = FromResult(CS.System.Int32)\n\nlocal function MyTask2(self)\n    CS.UnityEngine.Debug.Log(\"MyTask2 in lua!    001\")\n    return FromIntResult(1000);\nend\n\nxlua.hotfix(CS.XLuaTest.HotfixAsyncAwaitTest, 'MyTask2', MyTask2)\n\n-- await(MyTask2(nil),function (result)\n--     print(result)\n-- end)\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/MyTask2.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 61677c80fedcddc49b602a7ae3d1b3b3\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/await.lua.txt",
    "content": "--如果通过require加载，文件格式不能是UTF-8 with BOM，需要保存为UTF-8\n--或者将await方法复制到util中\n\n---\n--- 模拟C# [await](https://learn.microsoft.com/dotnet/csharp/language-reference/operators/await) 关键字\n---\n---@param awaitable any 异步任务实例，或者含有GetAwaiter方法的对象，查看C#可等待对象文档 [查看文档](https://learn.microsoft.com/dotnet/csharp/asynchronous-programming/async-return-types#generalized-async-return-types-and-valuetasktresult)\n---@param continuation function 异步延续函数。将C#代码中await关键字下面的代码封装为一个函数，作为异步任务完成时，要执行的回调函数。 [查看文档](https://learn.microsoft.com/dotnet/api/system.runtime.compilerservices.taskawaiter-1.unsafeoncompleted)\nfunction await(awaitable, continuation)\n    local awaiter = awaitable:GetAwaiter()\n    if awaiter.IsCompleted then\n        --如果同步完成，直接调用异步延续函数\n        local result = awaiter:GetResult()\n        continuation(result)\n    else\n        --如果异步挂起，将异步延续函数注册到异步任务中\n        awaiter:UnsafeOnCompleted(function ()\n            local result = awaiter:GetResult()\n            continuation(result)\n        end)\n    end\nend\n\n\n\n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources/await.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: effc794ec3dec7645bee0864b61842b2\nTextScriptImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 5c7d25082887a994485c2a81fd8b00ba\nfolderAsset: yes\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/14_HotfixAsyncAwait.meta",
    "content": "fileFormatVersion: 2\nguid: 401821773f114d54c980b6fd8716010c\nfolderAsset: yes\nDefaultImporter:\n  externalObjects: {}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples/ExampleGenConfig.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing UnityEngine;\r\nusing XLua;\r\nusing System.Linq;\r\nusing System.Reflection;\r\n\r\n//配置的详细介绍请看Doc下《XLua的配置.doc》\r\npublic static class ExampleGenConfig\r\n{\r\n    //lua中要使用到C#库的配置，比如C#标准库，或者Unity API，第三方库等。\r\n    [LuaCallCSharp]\r\n    public static List<Type> LuaCallCSharp = new List<Type>() {\r\n                typeof(System.Object),\r\n                typeof(UnityEngine.Object),\r\n                typeof(Vector2),\r\n                typeof(Vector3),\r\n                typeof(Vector4),\r\n                typeof(Quaternion),\r\n                typeof(Color),\r\n                typeof(Ray),\r\n                typeof(Bounds),\r\n                typeof(Ray2D),\r\n                typeof(Time),\r\n                typeof(GameObject),\r\n                typeof(Component),\r\n                typeof(Behaviour),\r\n                typeof(Transform),\r\n                typeof(Resources),\r\n                typeof(TextAsset),\r\n                typeof(Keyframe),\r\n                typeof(AnimationCurve),\r\n                typeof(AnimationClip),\r\n                typeof(MonoBehaviour),\r\n                typeof(ParticleSystem),\r\n                typeof(SkinnedMeshRenderer),\r\n                typeof(Renderer),\r\n                typeof(WWW),\r\n                typeof(Light),\r\n                typeof(Mathf),\r\n                typeof(System.Collections.Generic.List<int>),\r\n                typeof(Action<string>),\r\n                typeof(UnityEngine.Debug)\r\n            };\r\n\r\n    //C#静态调用Lua的配置（包括事件的原型），仅可以配delegate，interface\r\n    [CSharpCallLua]\r\n    public static List<Type> CSharpCallLua = new List<Type>() {\r\n                typeof(Action),\r\n                typeof(Func<double, double, double>),\r\n                typeof(Action<string>),\r\n                typeof(Action<double>),\r\n                typeof(UnityEngine.Events.UnityAction),\r\n                typeof(System.Collections.IEnumerator)\r\n            };\r\n\r\n    //黑名单\r\n    [BlackList]\r\n    public static List<List<string>> BlackList = new List<List<string>>()  {\r\n                new List<string>(){\"System.Xml.XmlNodeList\", \"ItemOf\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"movie\"},\r\n    #if UNITY_WEBGL\r\n                new List<string>(){\"UnityEngine.WWW\", \"threadPriority\"},\r\n    #endif\r\n                new List<string>(){\"UnityEngine.Texture2D\", \"alphaIsTransparency\"},\r\n                new List<string>(){\"UnityEngine.Security\", \"GetChainOfTrustValue\"},\r\n                new List<string>(){\"UnityEngine.CanvasRenderer\", \"onRequestRebuild\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"areaSize\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"lightmapBakeType\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"SetLightDirty\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"shadowRadius\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"shadowAngle\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"MovieTexture\"},\r\n                new List<string>(){\"UnityEngine.WWW\", \"GetMovieTexture\"},\r\n                new List<string>(){\"UnityEngine.AnimatorOverrideController\", \"PerformOverrideClipListCleanup\"},\r\n    #if !UNITY_WEBPLAYER\r\n                new List<string>(){\"UnityEngine.Application\", \"ExternalEval\"},\r\n    #endif\r\n                new List<string>(){\"UnityEngine.GameObject\", \"networkView\"}, //4.6.2 not support\r\n                new List<string>(){\"UnityEngine.Component\", \"networkView\"},  //4.6.2 not support\r\n                new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.FileInfo\", \"SetAccessControl\", \"System.Security.AccessControl.FileSecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"SetAccessControl\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"CreateSubdirectory\", \"System.String\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"Create\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"UnityEngine.MonoBehaviour\", \"runInEditMode\"},\r\n            };\r\n    \r\n    public static List<Type> BlackGenericTypeList = new List<Type>()\r\n    {\r\n        typeof(Span<>),\r\n        typeof(ReadOnlySpan<>),\r\n    };\r\n\r\n    private static bool IsBlacklistedGenericType(Type type)\r\n    {\r\n        if (!type.IsGenericType) return false;\r\n        return BlackGenericTypeList.Contains(type.GetGenericTypeDefinition());\r\n    }\r\n\r\n    [BlackList] public static Func<MemberInfo, bool> GenericTypeFilter = (memberInfo) =>\r\n    {\r\n        switch (memberInfo)\r\n        {\r\n            case PropertyInfo propertyInfo:\r\n                return IsBlacklistedGenericType(propertyInfo.PropertyType);\r\n\r\n            case ConstructorInfo constructorInfo:\r\n                return constructorInfo.GetParameters().Any(p => IsBlacklistedGenericType(p.ParameterType));\r\n\r\n            case MethodInfo methodInfo:\r\n                return methodInfo.GetParameters().Any(p => IsBlacklistedGenericType(p.ParameterType));\r\n\r\n            default:\r\n                return false;\r\n        }\r\n    };\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Examples/ExampleGenConfig.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 62b967797782a6d46a759bf0693f7351\ntimeCreated: 1459510243\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Examples.meta",
    "content": "fileFormatVersion: 2\nguid: 1feab61bf70ce6a4d951cbf76ea6c32f\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Resources/perf/memory.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal function snapshot()\r\n    error('use memory leak checker instead!')\r\nend\r\n\r\n--returns the total memory in use by Lua (in Kbytes).\r\nlocal function total()\r\n    error('use memory leak checker instead!')\r\nend\r\n\r\n\r\nreturn {\r\n    snapshot = snapshot,\r\n    total = total\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Resources/perf/memory.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 6a5cba5df35473342b614686c15f8a4c\ntimeCreated: 1461833890\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/perf/profiler.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal get_time = os.clock\r\nlocal sethook = xlua.sethook or debug.sethook\r\nlocal func_info_map = nil\r\n\r\nlocal start_time\r\n\r\nlocal function create_func_info(db_info)\r\n    return {\r\n\t\tdb_info = db_info,\r\n\t\tcount = 0,\r\n\t\ttotal_time = 0\r\n\t}\r\nend\r\n\r\nlocal function on_hook(event, func_info_id, source)\r\n    local func_info = func_info_map[func_info_id]\r\n    if not func_info then\r\n        func_info = create_func_info(debug.getinfo( 2, 'nS' ))\r\n        func_info_map[func_info_id] = func_info\r\n    end\r\n\tif event == \"call\" then\r\n\t\tfunc_info.call_time = get_time()\r\n        func_info.count = func_info.count + 1\r\n        func_info.return_time = nil\r\n\telseif event == \"return\" or event == 'tail return' then\r\n        local now = get_time()\r\n        if func_info.call_time then\r\n            func_info.total_time = func_info.total_time + (now - func_info.call_time)\r\n            func_info.call_time = nil\r\n        else\r\n            func_info.total_time = func_info.total_time + (now - (func_info.return_time or now))\r\n            func_info.count = func_info.count + 1\r\n        end\r\n        func_info.return_time = now\r\n        if source and func_info.count == 1 then\r\n            func_info.db_info.short_src = source\r\n        end\r\n\tend\r\nend\r\n\r\nlocal function start()\r\n    func_info_map = {}\r\n    start_time = get_time()\r\n    sethook(on_hook, 'cr')\r\nend\r\n\r\nlocal function pause()\r\n    sethook()\r\nend\r\n\r\nlocal function resume()\r\n    sethook(on_hook, 'cr')\r\nend\r\n\r\nlocal function stop()\r\n    sethook()\r\n    func_info_map = nil\r\n    start_time = nil\r\nend\r\n\r\nlocal function report_output_line(rp, stat_interval)\r\n    local source        = rp.db_info.short_src or '[NA]'\r\n    local linedefined   = (rp.db_info.linedefined and rp.db_info.linedefined >= 0) and string.format(\":%i\", rp.db_info.linedefined) or ''\r\n    source = source .. linedefined\r\n    local name          = rp.db_info.name or '[anonymous]'\r\n    local total_time    = string.format(\"%04.3f\", rp.total_time * 1000)\r\n    local average_time    = string.format(\"%04.3f\", rp.total_time / rp.count * 1000)\r\n    local relative_time = string.format(\"%03.2f%%\", (rp.total_time / stat_interval) * 100 )\r\n    local count         = string.format(\"%7i\", rp.count)\r\n        \r\n    return string.format(\"|%-40.40s: %-50.50s: %-12s: %-12s: %-12s: %-12s|\\n\", name, source, total_time, average_time, relative_time, count)\r\nend\r\n\r\nlocal sort_funcs = {\r\n    TOTAL = function(a, b) return a.total_time > b.total_time end,\r\n    AVERAGE = function(a, b) return a.average > b.average end,\r\n    CALLED = function(a, b) return a.count > b.count end\r\n}\r\n\r\nlocal function report(sort_by)\r\n    sethook()\r\n    local sort_func = type(sort_by) == 'function' and sort_by or sort_funcs[sort_by]\r\n    \r\n    local FORMAT_HEADER_LINE       = \"|%-40s: %-50s: %-12s: %-12s: %-12s: %-12s|\\n\"\r\n    local header = string.format( FORMAT_HEADER_LINE, \"FUNCTION\", \"SOURCE\", \"TOTAL(MS)\", \"AVERAGE(MS)\", \"RELATIVE\", \"CALLED\" )\r\n    local stat_interval = get_time() - (start_time or get_time())\r\n    \r\n    local report_list = {}\r\n    for _, rp in pairs(func_info_map) do\r\n        table.insert(report_list, {\r\n            total_time = rp.total_time,\r\n            count = rp.count,\r\n            average = rp.total_time / rp.count,\r\n            output = report_output_line(rp, stat_interval)\r\n        })\r\n    end\r\n    \r\n    table.sort(report_list, sort_func or sort_funcs.TOTAL)\r\n    \r\n    local output = header\r\n    \r\n    for i, rp in ipairs(report_list) do\r\n        output = output .. rp.output\r\n    end\r\n    \r\n    sethook(on_hook, 'cr')\r\n    \r\n    return output\r\nend\r\n\r\nreturn {\r\n    --开始统计\r\n    start = start,\r\n    --获取报告，start和stop之间可以多次调用，参数sort_by类型是string，可以是'TOTAL','AVERAGE', 'CALLED'\r\n    report = report,\r\n    --停止统计\r\n    stop = stop\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Resources/perf/profiler.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 4841b87b13a684649aab9de0e72132b7\ntimeCreated: 1461553714\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/perf.meta",
    "content": "fileFormatVersion: 2\nguid: 866368b69ae1a2040943783fa31d2f74\nfolderAsset: yes\ntimeCreated: 1461553627\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/tdr/tdr.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nrequire \"libtdrlua\"\r\nlocal m = {}\r\nfor k, v in pairs(libtdrlua) do m[k] = v end\r\nlocal load_metalib, load_metalib_buf, free_metalib, get_meta, table2buf, buf2table, str2table, metamaxbufsize, bufalloc, buffree, buf2str\r\nload_metalib, m.load_metalib = m.load_metalib, nil\r\nload_metalib_buf, m.load_metalib_buf = m.load_metalib_buf, nil\r\nfree_metalib, m.free_metalib = m.free_metalib, nil\r\nget_meta, m.get_meta = m.get_meta, nil\r\ntable2buf, m.table2buf = m.table2buf, nil\r\nbuf2table, m.buf2table = m.buf2table, nil\r\nstr2table, m.str2table = m.str2table, nil\r\nbuf2str, m.buf2str = m.buf2str, nil\r\n\r\nmetamaxbufsize, m.metamaxbufsize = m.metamaxbufsize, nil\r\nbufalloc, m.bufalloc = m.bufalloc, nil\r\nbuffree, m.buffree = m.buffree, nil\r\n\r\nlocal function create_msg_pk(meta, buf, buf_size)\r\n    return {\r\n        buff = buf,\r\n        pack = function(obj)\r\n            local ret_code, used_size = table2buf(meta, obj, buf, buf_size, 0)\r\n            if ret_code ~= 0 then\r\n                return ret_code, used_size\r\n            end\r\n            return buf2str(buf, used_size)\r\n        end,\r\n        unpack = function(str)\r\n            return libtdrlua.str2table(meta, str, 0)\r\n        end\r\n    }\r\nend\r\n\r\nlocal function create_lib(metalib)\r\n    return setmetatable({}, {\r\n        __index = function(obj, k)\r\n            local ret_code, meta = libtdrlua.get_meta(metalib, k)\r\n            if ret_code ~= 0 then\r\n                error(\"libtdrlua.get_meta() failed: errno=\".. ret_code .. \",msg=\" .. meta)\r\n            end\r\n            local ret_code, buf_size = libtdrlua.metamaxbufsize(metalib, k)\r\n            if ret_code ~= 0 then\r\n                error(\"libtdrlua.metamaxbufsize() failed: errno=\".. ret_code .. \",msg=\" .. buf_size)\r\n            end\r\n            \r\n            local ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n            if ret_code ~= 0 then\r\n                error(\"libtdrlua.bufalloc() failed: errno=\".. ret_code .. \",msg=\" .. buf)\r\n            end\r\n    \r\n            local pk = create_msg_pk(meta, buf, buf_size)\r\n            rawset(obj, k, pk)\r\n            return pk\r\n        end\r\n    })\r\nend\r\n\r\nfunction m.from_file(file)\r\n    local ret_code, metalib = libtdrlua.load_metalib(file)\r\n    if ret_code ~= 0 then\r\n        error(\"libtdrlua.load_metalib() failed: \" .. metalib)\r\n    end\r\n    return create_lib(metalib)\r\nend\r\n\r\nfunction m.from_memory(str)\r\n    local ret_code, metalib = libtdrlua.load_metalib_buf(str)\r\n    if ret_code ~= 0 then\r\n        error(\"libtdrlua.load_metalib_buf() failed: errno=\".. ret_code .. \",msg=\" .. metalib)\r\n    end\r\n    return create_lib(metalib)\r\nend\r\n\r\nreturn m"
  },
  {
    "path": "Assets/XLua/Resources/tdr/tdr.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 9e05f05f4a331bc45a04832062650a9e\ntimeCreated: 1458812943\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/tdr.meta",
    "content": "fileFormatVersion: 2\nguid: 8f08dfe3f4634334ea0810ea31d8b593\nfolderAsset: yes\ntimeCreated: 1454039150\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/xlua/util.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal unpack = unpack or table.unpack\r\n\r\nlocal function async_to_sync(async_func, callback_pos)\r\n    return function(...)\r\n        local _co = coroutine.running() or error ('this function must be run in coroutine')\r\n        local rets\r\n        local waiting = false\r\n        local function cb_func(...)\r\n            if waiting then\r\n                assert(coroutine.resume(_co, ...))\r\n            else\r\n                rets = {...}\r\n            end\r\n        end\r\n        local params = {...}\r\n        table.insert(params, callback_pos or (#params + 1), cb_func)\r\n        async_func(unpack(params))\r\n        if rets == nil then\r\n            waiting = true\r\n            rets = {coroutine.yield()}\r\n        end\r\n        \r\n        return unpack(rets)\r\n    end\r\nend\r\n\r\nlocal function coroutine_call(func)\r\n    return function(...)\r\n        local co = coroutine.create(func)\r\n        assert(coroutine.resume(co, ...))\r\n    end\r\nend\r\n\r\nlocal move_end = {}\r\n\r\nlocal generator_mt = {\r\n    __index = {\r\n        MoveNext = function(self)\r\n            self.Current = self.co()\r\n            if self.Current == move_end then\r\n                self.Current = nil\r\n                return false\r\n            else\r\n                return true\r\n            end\r\n        end;\r\n        Reset = function(self)\r\n            self.co = coroutine.wrap(self.w_func)\r\n        end\r\n    }\r\n}\r\n\r\nlocal function cs_generator(func, ...)\r\n    local params = {...}\r\n    local generator = setmetatable({\r\n        w_func = function()\r\n            func(unpack(params))\r\n            return move_end\r\n        end\r\n    }, generator_mt)\r\n    generator:Reset()\r\n    return generator\r\nend\r\n\r\nlocal function loadpackage(...)\r\n    for _, loader in ipairs(package.searchers) do\r\n        local func = loader(...)\r\n        if type(func) == 'function' then\r\n            return func\r\n        end\r\n    end\r\nend\r\n\r\nlocal function auto_id_map()\r\n    local hotfix_id_map = require 'hotfix_id_map'\r\n    local org_hotfix = xlua.hotfix\r\n    xlua.hotfix = function(cs, field, func)\r\n        local map_info_of_type = hotfix_id_map[typeof(cs):ToString()]\r\n        if map_info_of_type then\r\n            if func == nil then func = false end\r\n            local tbl = (type(field) == 'table') and field or {[field] = func}\r\n            for k, v in pairs(tbl) do\r\n                local map_info_of_methods = map_info_of_type[k]\r\n                local f = type(v) == 'function' and v or nil\r\n                for _, id in ipairs(map_info_of_methods or {}) do\r\n                    CS.XLua.HotfixDelegateBridge.Set(id, f)\r\n                end\r\n                --CS.XLua.HotfixDelegateBridge.Set(\r\n            end\r\n            xlua.private_accessible(cs)\r\n        else\r\n            return org_hotfix(cs, field, func)\r\n        end\r\n    end\r\nend\r\n\r\n--和xlua.hotfix的区别是：这个可以调用原来的函数\r\nlocal function hotfix_ex(cs, field, func)\r\n    assert(type(field) == 'string' and type(func) == 'function', 'invalid argument: #2 string needed, #3 function needed!')\r\n    local function func_after(...)\r\n        xlua.hotfix(cs, field, nil)\r\n        local ret = {func(...)}\r\n        xlua.hotfix(cs, field, func_after)\r\n        return unpack(ret)\r\n    end\r\n    xlua.hotfix(cs, field, func_after)\r\nend\r\n\r\nlocal function bind(func, obj)\r\n    return function(...)\r\n        return func(obj, ...)\r\n    end\r\nend\r\n\r\n--为了兼容luajit，lua53版本直接用|操作符即可\r\nlocal enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor\r\nlocal enum_or_op_ex = function(first, ...)\r\n    for _, e in ipairs({...}) do\r\n        first = enum_or_op(first, e)\r\n    end\r\n    return first\r\nend\r\n\r\n-- description: 直接用C#函数创建delegate\r\nlocal function createdelegate(delegate_cls, obj, impl_cls, method_name, parameter_type_list)\r\n    local flag = enum_or_op_ex(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.NonPublic, \r\n        CS.System.Reflection.BindingFlags.Instance, CS.System.Reflection.BindingFlags.Static)\r\n    local m = parameter_type_list and typeof(impl_cls):GetMethod(method_name, flag, nil, parameter_type_list, nil)\r\n             or typeof(impl_cls):GetMethod(method_name, flag)\r\n    return CS.System.Delegate.CreateDelegate(typeof(delegate_cls), obj, m)\r\nend\r\n\r\nlocal function state(csobj, state)\r\n    local csobj_mt = getmetatable(csobj)\r\n    for k, v in pairs(csobj_mt) do rawset(state, k, v) end\r\n    local csobj_index, csobj_newindex = state.__index, state.__newindex\r\n    state.__index = function(obj, k)\r\n        return rawget(state, k) or csobj_index(obj, k)\r\n    end\r\n    state.__newindex = function(obj, k, v)\r\n        if rawget(state, k) ~= nil then\r\n            rawset(state, k, v)\r\n        else\r\n            csobj_newindex(obj, k, v)\r\n        end\r\n    end\r\n    debug.setmetatable(csobj, state)\r\n    return state\r\nend\r\n\r\nlocal function print_func_ref_by_csharp()\r\n    local registry = debug.getregistry()\r\n    for k, v in pairs(registry) do\r\n        if type(k) == 'number' and type(v) == 'function' and registry[v] == k then\r\n            local info = debug.getinfo(v)\r\n            print(string.format('%s:%d', info.short_src, info.linedefined))\r\n        end\r\n    end\r\nend\r\n\r\nreturn {\r\n    async_to_sync = async_to_sync,\r\n    coroutine_call = coroutine_call,\r\n    cs_generator = cs_generator,\r\n    loadpackage = loadpackage,\r\n    auto_id_map = auto_id_map,\r\n    hotfix_ex = hotfix_ex,\r\n    bind = bind,\r\n    createdelegate = createdelegate,\r\n    state = state,\r\n    print_func_ref_by_csharp = print_func_ref_by_csharp,\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Resources/xlua/util.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 4397ec772c2d41e46a9766cf46b8bec6\ntimeCreated: 1463477791\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources/xlua.meta",
    "content": "fileFormatVersion: 2\nguid: e0924e56a40ddb34e9b004c2056288fa\nfolderAsset: yes\ntimeCreated: 1463477791\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: fa4f7e825d6ae9742bd6f88af5865c13\nfolderAsset: yes\ntimeCreated: 1458812833\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/CodeEmit.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\nusing System.Collections.Generic;\r\nusing System.Reflection.Emit;\r\nusing System.Reflection;\r\nusing System;\r\nusing System.Linq;\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nnamespace XLua\r\n{\r\n    public class CodeEmit\r\n    {\r\n        private ModuleBuilder codeEmitModule = null;\r\n        private ulong genID = 0;\r\n\r\n        private MethodInfo LuaEnv_ThrowExceptionFromError = typeof(LuaEnv).GetMethod(\"ThrowExceptionFromError\");\r\n        private FieldInfo LuaBase_luaEnv = typeof(LuaBase).GetField(\"luaEnv\", BindingFlags.NonPublic | BindingFlags.Instance);\r\n        private MethodInfo DelegateBridgeBase_errorFuncRef_getter = typeof(LuaBase).GetProperty(\"_errorFuncRef\", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true);\r\n        private MethodInfo LuaAPI_load_error_func = typeof(LuaAPI).GetMethod(\"load_error_func\");\r\n        private MethodInfo LuaBase_translator_getter  = typeof(LuaBase).GetProperty(\"_translator\", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true);\r\n        private FieldInfo LuaBase_luaReference = typeof(LuaBase).GetField(\"luaReference\", BindingFlags.NonPublic | BindingFlags.Instance);\r\n        private MethodInfo LuaAPI_lua_getref = typeof(LuaAPI).GetMethod(\"lua_getref\");\r\n        private MethodInfo Type_GetTypeFromHandle = typeof(Type).GetMethod(\"GetTypeFromHandle\", new Type[] { typeof(RuntimeTypeHandle) });\r\n        private MethodInfo ObjectTranslator_PushAny = typeof(ObjectTranslator).GetMethod(\"PushAny\");\r\n        private MethodInfo ObjectTranslator_PushParams = typeof(ObjectTranslator).GetMethod(\"PushParams\");\r\n        private MethodInfo LuaBase_L_getter = typeof(LuaBase).GetProperty(\"_L\", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true);\r\n        private MethodInfo LuaAPI_lua_pcall = typeof(LuaAPI).GetMethod(\"lua_pcall\");\r\n        private MethodInfo LuaAPI_lua_type = typeof(LuaAPI).GetMethod(\"lua_type\");\r\n        private MethodInfo ObjectTranslator_GetObject = typeof(ObjectTranslator).GetMethod(\"GetObject\", new Type[] { typeof(RealStatePtr),\r\n               typeof(int), typeof(Type)});\r\n        private MethodInfo ObjectTranslator_GetParams = typeof(ObjectTranslator).GetMethod(\"GetParams\", new Type[] { typeof(RealStatePtr), typeof(int) });\r\n        private MethodInfo ObjectTranslator_Update = typeof(ObjectTranslator).GetMethod(\"Update\");\r\n        private MethodInfo LuaAPI_lua_pushvalue = typeof(LuaAPI).GetMethod(\"lua_pushvalue\");\r\n        private MethodInfo LuaAPI_lua_remove = typeof(LuaAPI).GetMethod(\"lua_remove\");\r\n        private MethodInfo LuaAPI_lua_pushstring = typeof(LuaAPI).GetMethod(\"lua_pushstring\", new Type[] { typeof(RealStatePtr), typeof(string)});\r\n        private MethodInfo LuaAPI_lua_gettop = typeof(LuaAPI).GetMethod(\"lua_gettop\");\r\n        private MethodInfo LuaAPI_xlua_pgettable = typeof(LuaAPI).GetMethod(\"xlua_pgettable\");\r\n        private MethodInfo LuaAPI_xlua_psettable = typeof(LuaAPI).GetMethod(\"xlua_psettable\");\r\n        private MethodInfo LuaAPI_lua_pop = typeof(LuaAPI).GetMethod(\"lua_pop\");\r\n        private MethodInfo LuaAPI_lua_settop = typeof(LuaAPI).GetMethod(\"lua_settop\");\r\n        private MethodInfo LuaAPI_luaL_error = typeof(LuaAPI).GetMethod(\"luaL_error\");\r\n        private MethodInfo LuaAPI_xlua_is_eq_str = typeof(LuaAPI).GetMethod(\"xlua_is_eq_str\", new Type[] {\r\n        typeof(RealStatePtr), typeof(int), typeof(string)});\r\n\r\n        private MethodInfo LuaAPI_xlua_pushinteger = typeof(LuaAPI).GetMethod(\"xlua_pushinteger\");\r\n        private MethodInfo LuaAPI_lua_pushint64 = typeof(LuaAPI).GetMethod(\"lua_pushint64\");\r\n        private MethodInfo LuaAPI_lua_pushnumber = typeof(LuaAPI).GetMethod(\"lua_pushnumber\");\r\n        private MethodInfo LuaAPI_xlua_pushuint = typeof(LuaAPI).GetMethod(\"xlua_pushuint\");\r\n        private MethodInfo LuaAPI_lua_pushuint64 = typeof(LuaAPI).GetMethod(\"lua_pushuint64\");\r\n        private MethodInfo LuaAPI_lua_pushboolean = typeof(LuaAPI).GetMethod(\"lua_pushboolean\");\r\n        private MethodInfo LuaAPI_lua_pushbytes = typeof(LuaAPI).GetMethod(\"lua_pushstring\", new Type[] { typeof(RealStatePtr), typeof(byte[]) });\r\n        private MethodInfo LuaAPI_lua_pushlightuserdata = typeof(LuaAPI).GetMethod(\"lua_pushlightuserdata\");\r\n        private MethodInfo ObjectTranslator_PushDecimal = typeof(ObjectTranslator).GetMethod(\"PushDecimal\");\r\n        private MethodInfo ObjectTranslator_GetDecimal = typeof(ObjectTranslator).GetMethod(\"GetDecimal\");\r\n\r\n        private Dictionary<Type, MethodInfo> fixPush;\r\n\r\n        private MethodInfo LuaAPI_xlua_tointeger = typeof(LuaAPI).GetMethod(\"xlua_tointeger\");\r\n        private MethodInfo LuaAPI_lua_tonumber = typeof(LuaAPI).GetMethod(\"lua_tonumber\");\r\n        private MethodInfo LuaAPI_lua_tostring = typeof(LuaAPI).GetMethod(\"lua_tostring\");\r\n        private MethodInfo LuaAPI_lua_toboolean = typeof(LuaAPI).GetMethod(\"lua_toboolean\");\r\n        private MethodInfo LuaAPI_lua_tobytes = typeof(LuaAPI).GetMethod(\"lua_tobytes\");\r\n        private MethodInfo LuaAPI_lua_touserdata = typeof(LuaAPI).GetMethod(\"lua_touserdata\");\r\n        private MethodInfo LuaAPI_xlua_touint = typeof(LuaAPI).GetMethod(\"xlua_touint\");\r\n        private MethodInfo LuaAPI_lua_touint64 = typeof(LuaAPI).GetMethod(\"lua_touint64\");\r\n        private MethodInfo LuaAPI_lua_toint64 = typeof(LuaAPI).GetMethod(\"lua_toint64\");\r\n\r\n        private Dictionary<Type, MethodInfo> typedCaster;\r\n        private Dictionary<Type, MethodInfo> fixCaster;\r\n\r\n        public CodeEmit()\r\n        {\r\n            fixPush = new Dictionary<Type, MethodInfo>()\r\n            {\r\n                {typeof(byte), LuaAPI_xlua_pushinteger},\r\n                {typeof(char), LuaAPI_xlua_pushinteger},\r\n                {typeof(short), LuaAPI_xlua_pushinteger},\r\n                {typeof(int), LuaAPI_xlua_pushinteger},\r\n                {typeof(long), LuaAPI_lua_pushint64},\r\n                {typeof(sbyte), LuaAPI_xlua_pushinteger},\r\n                {typeof(float), LuaAPI_lua_pushnumber},\r\n                {typeof(ushort), LuaAPI_xlua_pushinteger},\r\n                {typeof(uint), LuaAPI_xlua_pushuint},\r\n                {typeof(ulong), LuaAPI_lua_pushuint64},\r\n                {typeof(double), LuaAPI_lua_pushnumber},\r\n                {typeof(string), LuaAPI_lua_pushstring},\r\n                {typeof(byte[]), LuaAPI_lua_pushbytes},\r\n                {typeof(bool), LuaAPI_lua_pushboolean},\r\n                {typeof(IntPtr), LuaAPI_lua_pushlightuserdata},\r\n            };\r\n\r\n            fixCaster = new Dictionary<Type, MethodInfo>()\r\n            {\r\n                {typeof(double), LuaAPI_lua_tonumber},\r\n                {typeof(string), LuaAPI_lua_tostring},\r\n                {typeof(bool), LuaAPI_lua_toboolean},\r\n                {typeof(byte[]), LuaAPI_lua_tobytes},\r\n                {typeof(IntPtr), LuaAPI_lua_touserdata},\r\n                {typeof(uint), LuaAPI_xlua_touint},\r\n                {typeof(ulong), LuaAPI_lua_touint64},\r\n                {typeof(int), LuaAPI_xlua_tointeger},\r\n                {typeof(long), LuaAPI_lua_toint64},\r\n            };\r\n\r\n            typedCaster = new Dictionary<Type, MethodInfo>()\r\n            {\r\n                {typeof(byte), LuaAPI_xlua_tointeger},\r\n                {typeof(char), LuaAPI_xlua_tointeger},\r\n                {typeof(short), LuaAPI_xlua_tointeger},\r\n                {typeof(sbyte), LuaAPI_xlua_tointeger},\r\n                {typeof(float), LuaAPI_lua_tonumber},\r\n                {typeof(ushort), LuaAPI_xlua_tointeger},\r\n            };\r\n\r\n            initBlackList();\r\n        }\r\n\r\n        private void emitPush(ILGenerator il, Type type, short dataPos, bool isParam, LocalBuilder L, LocalBuilder translator, bool isArg)\r\n        {\r\n            var paramElemType = type.IsByRef ? type.GetElementType() : type;\r\n            var ldd = isArg ? OpCodes.Ldarg : OpCodes.Ldloc;\r\n            MethodInfo pusher;\r\n            if (fixPush.TryGetValue(paramElemType, out pusher))\r\n            {\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(ldd, dataPos);\r\n\r\n                if (type.IsByRef)\r\n                {\r\n                    if (paramElemType.IsValueType)\r\n                    {\r\n                        il.Emit(OpCodes.Ldobj, paramElemType);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Ldind_Ref);\r\n                    }\r\n                }\r\n\r\n                il.Emit(OpCodes.Call, pusher);\r\n            }\r\n            else if (paramElemType == typeof(decimal))\r\n            {\r\n                il.Emit(OpCodes.Ldloc, translator);\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(ldd, dataPos);\r\n                if (type.IsByRef)\r\n                {\r\n                    il.Emit(OpCodes.Ldobj, paramElemType);\r\n                }\r\n                il.Emit(OpCodes.Callvirt, ObjectTranslator_PushDecimal);\r\n            }\r\n            else\r\n            {\r\n                il.Emit(OpCodes.Ldloc, translator);\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(ldd, dataPos);\r\n                if (type.IsByRef)\r\n                {\r\n                    if (paramElemType.IsValueType)\r\n                    {\r\n                        il.Emit(OpCodes.Ldobj, paramElemType);\r\n                        il.Emit(OpCodes.Box, paramElemType);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Ldind_Ref);\r\n                    }\r\n                }\r\n                else if (type.IsValueType)\r\n                {\r\n                    il.Emit(OpCodes.Box, type);\r\n                }\r\n                if (isParam)\r\n                {\r\n                    il.Emit(OpCodes.Callvirt, ObjectTranslator_PushParams);\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Callvirt, ObjectTranslator_PushAny);\r\n                }\r\n            }\r\n        }\r\n\r\n        private ModuleBuilder CodeEmitModule\r\n        {\r\n            get\r\n            {\r\n                if (codeEmitModule == null)\r\n                {\r\n                    var assemblyName = new AssemblyName();\r\n                    assemblyName.Name = \"XLuaCodeEmit\";\r\n#if NET5_0_OR_GREATER\r\n                    codeEmitModule = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run)\r\n#else\r\n                    codeEmitModule = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run)\r\n#endif\r\n                        .DefineDynamicModule(\"XLuaCodeEmit\");\r\n                }\r\n                return codeEmitModule;\r\n            }\r\n        }\r\n\r\n        public Type EmitDelegateImpl(IEnumerable<IGrouping<MethodInfo, Type>> groups)\r\n        {\r\n            TypeBuilder impl_type_builder = CodeEmitModule.DefineType(\"XLuaGenDelegateImpl\" + (genID++), TypeAttributes.Public, typeof(DelegateBridge));\r\n\r\n            MethodBuilder get_deleate_by_type = impl_type_builder.DefineMethod(\"GetDelegateByType\", MethodAttributes.Public\r\n                    | MethodAttributes.HideBySig\r\n                    | MethodAttributes.NewSlot\r\n                    | MethodAttributes.Virtual\r\n                    | MethodAttributes.Final,\r\n                    typeof(System.Delegate), new Type[] { typeof(System.Type) });\r\n\r\n            ILGenerator get_deleate_by_type_il = get_deleate_by_type.GetILGenerator();\r\n\r\n            foreach (var group in groups)\r\n            {\r\n                var to_be_impl = group.Key;\r\n\r\n                var method_builder = defineImplementMethod(impl_type_builder, to_be_impl, to_be_impl.Attributes, \"__Gen_Delegate_Imp\" + (genID++));\r\n\r\n                emitMethodImpl(to_be_impl, method_builder.GetILGenerator(), false);\r\n\r\n                foreach(var dt in group)\r\n                {\r\n                    Label end_of_if = get_deleate_by_type_il.DefineLabel();\r\n                    get_deleate_by_type_il.Emit(OpCodes.Ldarg_1);\r\n                    get_deleate_by_type_il.Emit(OpCodes.Ldtoken, dt);\r\n                    get_deleate_by_type_il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n                    get_deleate_by_type_il.Emit(OpCodes.Bne_Un, end_of_if);\r\n\r\n                    get_deleate_by_type_il.Emit(OpCodes.Ldarg_0);\r\n                    get_deleate_by_type_il.Emit(OpCodes.Ldftn, method_builder);\r\n                    get_deleate_by_type_il.Emit(OpCodes.Newobj, dt.GetConstructor(new Type[] { typeof(object), typeof(IntPtr) }));\r\n                    get_deleate_by_type_il.Emit(OpCodes.Ret);\r\n                    get_deleate_by_type_il.MarkLabel(end_of_if);\r\n                }\r\n            }\r\n\r\n            // Constructor\r\n            var ctor_param_types = new Type[] { typeof(int), typeof(LuaEnv) };\r\n            ConstructorInfo parent_ctor = typeof(DelegateBridge).GetConstructor(ctor_param_types);\r\n            var ctor_builder = impl_type_builder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ctor_param_types);\r\n            var ctor_il = ctor_builder.GetILGenerator();\r\n            ctor_il.Emit(OpCodes.Ldarg_0);\r\n            ctor_il.Emit(OpCodes.Ldarg_1);\r\n            ctor_il.Emit(OpCodes.Ldarg_2);\r\n            ctor_il.Emit(OpCodes.Call, parent_ctor);\r\n            ctor_il.Emit(OpCodes.Ret);\r\n\r\n            // end of GetDelegateByType\r\n            get_deleate_by_type_il.Emit(OpCodes.Ldnull);\r\n            get_deleate_by_type_il.Emit(OpCodes.Ret);\r\n\r\n            impl_type_builder.DefineMethodOverride(get_deleate_by_type, typeof(DelegateBridgeBase).GetMethod(\"GetDelegateByType\"));\r\n\r\n\r\n            return impl_type_builder.CreateType();\r\n        }\r\n\r\n        private void EmitGetObject(ILGenerator il, int offset, Type type, LocalBuilder L, LocalBuilder translator, LocalBuilder offsetBase, bool isParam = false)\r\n        {\r\n            if (!fixCaster.ContainsKey(type) && !typedCaster.ContainsKey(type))\r\n            {\r\n                il.Emit(OpCodes.Ldloc, translator); // translator\r\n            }\r\n            il.Emit(OpCodes.Ldloc, L); // L\r\n            if (offsetBase != null)\r\n            {\r\n                il.Emit(OpCodes.Ldloc, offsetBase); // err_func\r\n                il.Emit(OpCodes.Ldc_I4, offset);\r\n                il.Emit(OpCodes.Add);\r\n            }\r\n            else\r\n            {\r\n                il.Emit(OpCodes.Ldc_I4, offset);\r\n            }\r\n\r\n            MethodInfo caster;\r\n            \r\n            if (fixCaster.TryGetValue(type, out caster))\r\n            {\r\n                il.Emit(OpCodes.Call, caster);\r\n            }\r\n            else if (typedCaster.TryGetValue(type, out caster))\r\n            {\r\n                il.Emit(OpCodes.Call, caster);\r\n                if (type == typeof(byte))\r\n                {\r\n                    il.Emit(OpCodes.Conv_U1);\r\n                }\r\n                else if(type == typeof(char))\r\n                {\r\n                    il.Emit(OpCodes.Conv_U2);\r\n                }\r\n                else if (type == typeof(short))\r\n                {\r\n                    il.Emit(OpCodes.Conv_I2);\r\n                }\r\n                else if (type == typeof(sbyte))\r\n                {\r\n                    il.Emit(OpCodes.Conv_I1);\r\n                }\r\n                else if (type == typeof(ushort))\r\n                {\r\n                    il.Emit(OpCodes.Conv_U2);\r\n                }\r\n                else if (type == typeof(float))\r\n                {\r\n                    il.Emit(OpCodes.Conv_R4);\r\n                }\r\n                else\r\n                {\r\n                    throw new InvalidProgramException(type + \" is not a type need cast\");\r\n                }\r\n            }\r\n            else if (type == typeof(decimal))\r\n            {\r\n                il.Emit(OpCodes.Callvirt, ObjectTranslator_GetDecimal);\r\n            }\r\n            else\r\n            {\r\n                if (isParam)\r\n                {\r\n                    il.Emit(OpCodes.Callvirt, ObjectTranslator_GetParams.MakeGenericMethod(new Type[] { type.GetElementType() }));\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Ldtoken, type);\r\n                    il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n                    il.Emit(OpCodes.Callvirt, ObjectTranslator_GetObject);\r\n                }\r\n                if (type.IsValueType)\r\n                {\r\n                    Label not_null = il.DefineLabel();\r\n                    Label null_done = il.DefineLabel();\r\n                    LocalBuilder local_new = il.DeclareLocal(type);\r\n\r\n                    il.Emit(OpCodes.Dup);\r\n                    il.Emit(OpCodes.Brtrue_S, not_null);\r\n\r\n                    il.Emit(OpCodes.Pop);\r\n                    il.Emit(OpCodes.Ldloca, local_new);\r\n                    il.Emit(OpCodes.Initobj, type);\r\n                    il.Emit(OpCodes.Ldloc, local_new);\r\n                    il.Emit(OpCodes.Br_S, null_done);\r\n\r\n                    il.MarkLabel(not_null);\r\n                    il.Emit(OpCodes.Unbox_Any, type);\r\n                    il.MarkLabel(null_done);\r\n                }\r\n                else if (type != typeof(object))\r\n                {\r\n                    il.Emit(OpCodes.Castclass, type);\r\n                }\r\n            }\r\n        }\r\n\r\n        HashSet<Type> gen_interfaces = new HashSet<Type>();\r\n\r\n        public void SetGenInterfaces(List<Type> gen_interfaces)\r\n        {\r\n            gen_interfaces.ForEach((item) =>\r\n            {\r\n                if (!this.gen_interfaces.Contains(item))\r\n                {\r\n                    this.gen_interfaces.Add(item);\r\n                }\r\n            });\r\n        }\r\n\r\n        public Type EmitInterfaceImpl(Type to_be_impl)\r\n        {\r\n            if (!to_be_impl.IsInterface)\r\n            {\r\n                throw new InvalidOperationException(\"interface expected, but got \" + to_be_impl);\r\n            }\r\n\r\n            if (!gen_interfaces.Contains(to_be_impl))\r\n            {\r\n                throw new InvalidCastException(\"This type must add to CSharpCallLua: \" + to_be_impl.GetFriendlyName());\r\n            }\r\n\r\n            TypeBuilder impl_type_builder = CodeEmitModule.DefineType(\"XLuaGenInterfaceImpl\" + (genID++), TypeAttributes.Public | TypeAttributes.Class, typeof(LuaBase), new Type[] { to_be_impl});\r\n\r\n            foreach(var member in (new Type[] { to_be_impl }.Concat(to_be_impl.GetInterfaces()).SelectMany(i=> i.GetMembers())))\r\n            {\r\n                if (member.MemberType == MemberTypes.Method)\r\n                {\r\n                    MethodInfo method = member as MethodInfo;\r\n                    if (method.Name.StartsWith(\"get_\") || method.Name.StartsWith(\"set_\") ||\r\n                        method.Name.StartsWith(\"add_\") || method.Name.StartsWith(\"remove_\"))\r\n                    {\r\n                        continue;\r\n                    }\r\n\r\n                    var method_builder = defineImplementMethod(impl_type_builder, method,\r\n                        MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual);\r\n\r\n                    emitMethodImpl(method, method_builder.GetILGenerator(), true);\r\n                }\r\n                else if (member.MemberType == MemberTypes.Property)\r\n                {\r\n                    PropertyInfo property = member as PropertyInfo;\r\n                    PropertyBuilder prop_builder = impl_type_builder.DefineProperty(property.Name, property.Attributes, property.PropertyType, Type.EmptyTypes);\r\n                    if (property.Name == \"Item\")\r\n                    {\r\n                        if (property.CanRead)\r\n                        {\r\n                            var getter_buildler = defineImplementMethod(impl_type_builder, property.GetGetMethod(), \r\n                                MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig);\r\n                            emitMethodImpl(property.GetGetMethod(), getter_buildler.GetILGenerator(), true);\r\n                            prop_builder.SetGetMethod(getter_buildler);\r\n                        }\r\n                        if (property.CanWrite)\r\n                        {\r\n                            var setter_buildler = defineImplementMethod(impl_type_builder, property.GetSetMethod(),\r\n                                MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig);\r\n                            emitMethodImpl(property.GetSetMethod(), setter_buildler.GetILGenerator(), true);\r\n                            prop_builder.SetSetMethod(setter_buildler);\r\n                        }\r\n                        continue;\r\n                    }\r\n                    if (property.CanRead)\r\n                    {\r\n                        MethodBuilder getter_buildler = impl_type_builder.DefineMethod(\"get_\" + property.Name, \r\n                            MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,\r\n                            property.PropertyType, Type.EmptyTypes);\r\n\r\n                        ILGenerator il = getter_buildler.GetILGenerator();\r\n\r\n                        LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n                        LocalBuilder oldTop = il.DeclareLocal(typeof(int));\r\n                        LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n                        LocalBuilder ret = il.DeclareLocal(property.PropertyType);\r\n\r\n                        // L = LuaBase.L;\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Callvirt, LuaBase_L_getter);\r\n                        il.Emit(OpCodes.Stloc, L);\r\n\r\n                        //oldTop = LuaAPI.lua_gettop(L);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_gettop);\r\n                        il.Emit(OpCodes.Stloc, oldTop);\r\n\r\n                        //translator = LuaBase.translator;\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Callvirt, LuaBase_translator_getter);\r\n                        il.Emit(OpCodes.Stloc, translator);\r\n\r\n                        //LuaAPI.lua_getref(L, luaReference);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Ldfld, LuaBase_luaReference);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_getref);\r\n\r\n                        //LuaAPI.lua_pushstring(L, \"xxx\");\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldstr, property.Name);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_pushstring);\r\n\r\n                        //LuaAPI.xlua_pgettable(L, -2)\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldc_I4_S, (sbyte)-2);\r\n                        il.Emit(OpCodes.Call, LuaAPI_xlua_pgettable);\r\n                        Label gettable_no_exception = il.DefineLabel();\r\n                        il.Emit(OpCodes.Brfalse, gettable_no_exception);\r\n\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Ldfld, LuaBase_luaEnv);\r\n                        il.Emit(OpCodes.Ldloc, oldTop);\r\n                        il.Emit(OpCodes.Callvirt, LuaEnv_ThrowExceptionFromError);\r\n                        il.MarkLabel(gettable_no_exception);\r\n\r\n                        EmitGetObject(il, -1, property.PropertyType, L, translator, null);\r\n                        il.Emit(OpCodes.Stloc, ret);\r\n\r\n                        //LuaAPI.lua_pop(L, 2);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldc_I4_S, (sbyte)2);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_pop);\r\n\r\n                        il.Emit(OpCodes.Ldloc, ret);\r\n                        il.Emit(OpCodes.Ret);\r\n\r\n                        prop_builder.SetGetMethod(getter_buildler);\r\n                    }\r\n                    if (property.CanWrite)\r\n                    {\r\n                        MethodBuilder setter_builder = impl_type_builder.DefineMethod(\"set_\" + property.Name, \r\n                            MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, \r\n                            null, new Type[] { property.PropertyType });\r\n\r\n                        ILGenerator il = setter_builder.GetILGenerator();\r\n\r\n                        LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n                        LocalBuilder oldTop = il.DeclareLocal(typeof(int));\r\n                        LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n\r\n                        // L = LuaBase.L;\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Callvirt, LuaBase_L_getter);\r\n                        il.Emit(OpCodes.Stloc, L);\r\n\r\n                        //oldTop = LuaAPI.lua_gettop(L);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_gettop);\r\n                        il.Emit(OpCodes.Stloc, oldTop);\r\n\r\n                        //translator = LuaBase.translator;\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Callvirt, LuaBase_translator_getter);\r\n                        il.Emit(OpCodes.Stloc, translator);\r\n\r\n                        //LuaAPI.lua_getref(L, luaReference);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Ldfld, LuaBase_luaReference);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_getref);\r\n\r\n                        //LuaAPI.lua_pushstring(L, \"xxx\");\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldstr, property.Name);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_pushstring);\r\n\r\n                        //translator.Push(L, value);\r\n                        emitPush(il, property.PropertyType, 1, false, L, translator, true);\r\n\r\n                        //LuaAPI.xlua_psettable(L, -2)\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldc_I4_S, (sbyte)-3);\r\n                        il.Emit(OpCodes.Call, LuaAPI_xlua_psettable);\r\n                        Label settable_no_exception = il.DefineLabel();\r\n                        il.Emit(OpCodes.Brfalse, settable_no_exception);\r\n\r\n                        il.Emit(OpCodes.Ldarg_0);\r\n                        il.Emit(OpCodes.Ldfld, LuaBase_luaEnv);\r\n                        il.Emit(OpCodes.Ldloc, oldTop);\r\n                        il.Emit(OpCodes.Callvirt, LuaEnv_ThrowExceptionFromError);\r\n                        il.MarkLabel(settable_no_exception);\r\n\r\n                        //LuaAPI.lua_pop(L, 1);\r\n                        il.Emit(OpCodes.Ldloc, L);\r\n                        il.Emit(OpCodes.Ldc_I4_S, (sbyte)1);\r\n                        il.Emit(OpCodes.Call, LuaAPI_lua_pop);\r\n\r\n                        il.Emit(OpCodes.Ret);\r\n\r\n                        prop_builder.SetSetMethod(setter_builder);\r\n\r\n                    }\r\n                }\r\n                else if(member.MemberType == MemberTypes.Event)\r\n                {\r\n                    \r\n                    EventInfo event_info = member as EventInfo;\r\n                    EventBuilder event_builder = impl_type_builder.DefineEvent(event_info.Name, event_info.Attributes, event_info.EventHandlerType);\r\n                    if (event_info.GetAddMethod() != null)\r\n                    {\r\n                        var add_buildler = defineImplementMethod(impl_type_builder, event_info.GetAddMethod(),\r\n                            MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig);\r\n                        emitMethodImpl(event_info.GetAddMethod(), add_buildler.GetILGenerator(), true);\r\n                        event_builder.SetAddOnMethod(add_buildler);\r\n                    }\r\n                    if (event_info.GetRemoveMethod() != null)\r\n                    {\r\n                        var remove_buildler = defineImplementMethod(impl_type_builder, event_info.GetRemoveMethod(),\r\n                            MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig);\r\n                        emitMethodImpl(event_info.GetRemoveMethod(), remove_buildler.GetILGenerator(), true);\r\n                        event_builder.SetRemoveOnMethod(remove_buildler);\r\n                    }\r\n                }\r\n            }\r\n            \r\n\r\n            // Constructor\r\n            var ctor_param_types = new Type[] { typeof(int), typeof(LuaEnv) };\r\n            ConstructorInfo parent_ctor = typeof(LuaBase).GetConstructor(ctor_param_types);\r\n            var ctor_builder = impl_type_builder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ctor_param_types);\r\n            var ctor_il = ctor_builder.GetILGenerator();\r\n            ctor_il.Emit(OpCodes.Ldarg_0);\r\n            ctor_il.Emit(OpCodes.Ldarg_1);\r\n            ctor_il.Emit(OpCodes.Ldarg_2);\r\n            ctor_il.Emit(OpCodes.Call, parent_ctor);\r\n            ctor_il.Emit(OpCodes.Ret);\r\n\r\n            return impl_type_builder.CreateType();\r\n        }\r\n\r\n        private void emitEmptyMethod(ILGenerator il, Type returnType)\r\n        {\r\n            if(returnType != typeof(void))\r\n            {\r\n                if (returnType.IsValueType)\r\n                {\r\n                    LocalBuilder local_new = il.DeclareLocal(returnType);\r\n                    il.Emit(OpCodes.Ldloca, local_new);\r\n                    il.Emit(OpCodes.Initobj, returnType);\r\n                    il.Emit(OpCodes.Ldloc, local_new);\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Ldnull);\r\n                }\r\n            }\r\n            il.Emit(OpCodes.Ret);\r\n        }\r\n\r\n        private MethodBuilder defineImplementMethod(TypeBuilder type_builder, MethodInfo to_be_impl, MethodAttributes attributes, string methodName = null)\r\n        {\r\n            var parameters = to_be_impl.GetParameters();\r\n\r\n            Type[] param_types = new Type[parameters.Length];\r\n            for (int i = 0; i < parameters.Length; ++i)\r\n            {\r\n                param_types[i] = parameters[i].ParameterType;\r\n            }\r\n\r\n            var method_builder = type_builder.DefineMethod(methodName == null ? to_be_impl.Name : methodName, attributes, to_be_impl.ReturnType, param_types);\r\n            for (int i = 0; i < parameters.Length; ++i)\r\n            {\r\n                method_builder.DefineParameter(i + 1, parameters[i].Attributes, parameters[i].Name);\r\n            }\r\n            return method_builder;\r\n        }\r\n\r\n        ConstructorInfo decimalConstructor = typeof(decimal).GetConstructor(new Type[] {\r\n            typeof(int), typeof(int), typeof(int), typeof(bool), typeof(byte)\r\n        });\r\n\r\n        private void emitLiteralLoad(ILGenerator il, Type type, object obj, int localIndex)\r\n        {\r\n            if (!type.IsValueType && ReferenceEquals(obj, null))\r\n            {\r\n                il.Emit(OpCodes.Ldnull);\r\n            }\r\n            else if(type.IsPrimitive || type.IsEnum())\r\n            {\r\n                if (type.IsEnum())\r\n                {\r\n                    type = Enum.GetUnderlyingType(type);\r\n                }\r\n                if (typeof(bool) == type)\r\n                {\r\n                    if ((bool)obj == true)\r\n                    {\r\n                        il.Emit(OpCodes.Ldc_I4_1);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Ldc_I4_0);\r\n                    }\r\n                }\r\n                else if (typeof(uint) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_I4, (int)Convert.ToUInt32(obj));\r\n                }\r\n                else if(typeof(byte) == type || typeof(sbyte) == type || typeof(short) == type ||\r\n                    typeof(ushort) == type || typeof(int) == type || typeof(char) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_I4, Convert.ToInt32(obj));\r\n                }\r\n                else if (typeof(long) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_I8, Convert.ToInt64(obj));\r\n                }\r\n                else if (typeof(ulong) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_I8, (long)Convert.ToUInt64(obj));\r\n                }\r\n                else if (typeof(IntPtr) == type || typeof(UIntPtr) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldloca, localIndex);\r\n                    il.Emit(OpCodes.Initobj, type);\r\n                    il.Emit(OpCodes.Ldloc, localIndex);\r\n                }\r\n                else if (typeof(float) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_R4, Convert.ToSingle(obj));\r\n                }\r\n                else if (typeof(double) == type)\r\n                {\r\n                    il.Emit(OpCodes.Ldc_R8, Convert.ToDouble(obj));\r\n                }\r\n                else\r\n                {\r\n                    throw new Exception(type + \" is not primitive or enum!\");\r\n                }\r\n            }\r\n            else if (type == typeof(string))\r\n            {\r\n                il.Emit(OpCodes.Ldstr, obj as string);\r\n            }\r\n            else if (type == typeof(decimal))\r\n            {\r\n                var buffer = decimal.GetBits(Convert.ToDecimal(obj));\r\n                il.Emit(OpCodes.Ldc_I4, buffer[0]);\r\n                il.Emit(OpCodes.Ldc_I4, buffer[1]);\r\n                il.Emit(OpCodes.Ldc_I4, buffer[2]);\r\n                //UnityEngine.Debug.Log(string.Format(\"{0}.{1}.{2}.{3}--{4}\", buffer[0], buffer[1], buffer[2], buffer[3], obj));\r\n                il.Emit(OpCodes.Ldc_I4, (buffer[3] & 0x80000000) == 0 ? 0 : 1);\r\n                il.Emit(OpCodes.Ldc_I4, (buffer[3] >> 16) & 0xFF);\r\n                il.Emit(OpCodes.Newobj, decimalConstructor);\r\n            }\r\n            else if (type.IsValueType) \r\n            {\r\n                il.Emit(OpCodes.Ldloca, localIndex);\r\n                il.Emit(OpCodes.Initobj, type);\r\n                il.Emit(OpCodes.Ldloc, localIndex);\r\n            }\r\n            else\r\n            {\r\n                il.Emit(OpCodes.Ldnull);\r\n            }\r\n        }\r\n\r\n        private void emitMethodImpl(MethodInfo to_be_impl, ILGenerator il, bool isObj)\r\n        {\r\n            var parameters = to_be_impl.GetParameters();\r\n\r\n            LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));//RealStatePtr L;  0\r\n            LocalBuilder err_func = il.DeclareLocal(typeof(int));//int err_func; 1\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));//ObjectTranslator translator; 2\r\n            LocalBuilder ret = null;\r\n            bool has_return = to_be_impl.ReturnType != typeof(void);\r\n            if (has_return)\r\n            {\r\n                ret = il.DeclareLocal(to_be_impl.ReturnType); //ReturnType ret; 3\r\n            }\r\n\r\n            // L = LuaBase.L;\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Callvirt, LuaBase_L_getter);\r\n            il.Emit(OpCodes.Stloc, L);\r\n\r\n            //err_func =LuaAPI.load_error_func(L, errorFuncRef);\r\n            il.Emit(OpCodes.Ldloc, L);\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Callvirt, DelegateBridgeBase_errorFuncRef_getter);\r\n            il.Emit(OpCodes.Call, LuaAPI_load_error_func);\r\n            il.Emit(OpCodes.Stloc, err_func);\r\n\r\n            //translator = LuaBase.translator;\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Callvirt, LuaBase_translator_getter);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            //LuaAPI.lua_getref(L, luaReference);\r\n            il.Emit(OpCodes.Ldloc, L);\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldfld, LuaBase_luaReference);\r\n            il.Emit(OpCodes.Call, LuaAPI_lua_getref);\r\n\r\n            if (isObj)\r\n            {\r\n                //LuaAPI.lua_pushstring(L, \"xxx\");\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(OpCodes.Ldstr, to_be_impl.Name);\r\n                il.Emit(OpCodes.Call, LuaAPI_lua_pushstring);\r\n\r\n                //LuaAPI.xlua_pgettable(L, -2)\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(OpCodes.Ldc_I4_S, (sbyte)-2);\r\n                il.Emit(OpCodes.Call, LuaAPI_xlua_pgettable);\r\n                Label gettable_no_exception = il.DefineLabel();\r\n                il.Emit(OpCodes.Brfalse, gettable_no_exception);\r\n\r\n                il.Emit(OpCodes.Ldarg_0);\r\n                il.Emit(OpCodes.Ldfld, LuaBase_luaEnv);\r\n                il.Emit(OpCodes.Ldloc, err_func);\r\n                il.Emit(OpCodes.Ldc_I4_1);\r\n                il.Emit(OpCodes.Sub);\r\n                il.Emit(OpCodes.Callvirt, LuaEnv_ThrowExceptionFromError);\r\n                il.MarkLabel(gettable_no_exception);\r\n\r\n                //LuaAPI.lua_pushvalue(L, -2);\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(OpCodes.Ldc_I4_S, (sbyte)-2);\r\n                il.Emit(OpCodes.Call, LuaAPI_lua_pushvalue);\r\n\r\n                //LuaAPI.lua_remove(L, -3);\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(OpCodes.Ldc_I4_S, (sbyte)-3);\r\n                il.Emit(OpCodes.Call, LuaAPI_lua_remove);\r\n            }\r\n\r\n            int in_param_count = 0;\r\n            int out_param_count = 0;\r\n            bool has_params = false;\r\n            //translator.PushAny(L, param_in)\r\n            for (int i = 0; i < parameters.Length; ++i)\r\n            {\r\n                var pinfo = parameters[i];\r\n                if (!pinfo.IsOut)\r\n                {\r\n                    var ptype = pinfo.ParameterType;\r\n                    bool isParam = pinfo.IsDefined(typeof(ParamArrayAttribute), false);\r\n                    emitPush(il, ptype, (short)(i + 1), isParam, L, translator, true);\r\n                    if (isParam)\r\n                    {\r\n                        has_params = true;\r\n                    }\r\n                    else\r\n                    {\r\n                        ++in_param_count;\r\n                    }\r\n                }\r\n\r\n                if (pinfo.ParameterType.IsByRef)\r\n                {\r\n                    ++out_param_count;\r\n                }\r\n            }\r\n\r\n            il.Emit(OpCodes.Ldloc, L);\r\n            il.Emit(OpCodes.Ldc_I4, in_param_count + (isObj ? 1 : 0));\r\n            if (has_params)\r\n            {\r\n                Label l1 = il.DefineLabel();\r\n\r\n                il.Emit(OpCodes.Ldarg, (short)parameters.Length);\r\n                il.Emit(OpCodes.Brfalse, l1);\r\n\r\n                il.Emit(OpCodes.Ldarg, (short)parameters.Length);\r\n                il.Emit(OpCodes.Ldlen);\r\n                il.Emit(OpCodes.Add);\r\n                il.MarkLabel(l1);\r\n            }\r\n            il.Emit(OpCodes.Ldc_I4, out_param_count + (has_return ? 1 : 0));\r\n            il.Emit(OpCodes.Ldloc, err_func);\r\n            il.Emit(OpCodes.Call, LuaAPI_lua_pcall);\r\n            Label no_exception = il.DefineLabel();\r\n            il.Emit(OpCodes.Brfalse, no_exception);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldfld, LuaBase_luaEnv);\r\n            il.Emit(OpCodes.Ldloc, err_func);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Sub);\r\n            il.Emit(OpCodes.Callvirt, LuaEnv_ThrowExceptionFromError);\r\n            il.MarkLabel(no_exception);\r\n\r\n            int offset = 1;\r\n            if (has_return)\r\n            {\r\n                EmitGetObject(il, offset++, to_be_impl.ReturnType, L, translator, err_func);\r\n                il.Emit(OpCodes.Stloc, ret);\r\n            }\r\n\r\n            for (int i = 0; i < parameters.Length; ++i)\r\n            {\r\n                var pinfo = parameters[i];\r\n                var ptype = pinfo.ParameterType;\r\n                if (ptype.IsByRef)\r\n                {\r\n                    il.Emit(OpCodes.Ldarg, (short)(i + 1));\r\n                    var pelemtype = ptype.GetElementType();\r\n                    EmitGetObject(il, offset++, pelemtype, L, translator, err_func);\r\n                    if (pelemtype.IsValueType)\r\n                    {\r\n                        il.Emit(OpCodes.Stobj, pelemtype);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Stind_Ref);\r\n                    }\r\n\r\n                }\r\n            }\r\n\r\n            if (has_return)\r\n            {\r\n                il.Emit(OpCodes.Ldloc, ret);\r\n            }\r\n\r\n            //LuaAPI.lua_settop(L, err_func - 1);\r\n            il.Emit(OpCodes.Ldloc, L);\r\n            il.Emit(OpCodes.Ldloc, err_func);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Sub);\r\n            il.Emit(OpCodes.Call, LuaAPI_lua_settop);\r\n\r\n            il.Emit(OpCodes.Ret);\r\n        }\r\n\r\n        private MethodInfo ObjectTranslatorPool_FindTranslator = typeof(ObjectTranslatorPool).GetMethod(\"FindTranslator\");\r\n        private Type[] parameterTypeOfWrap = new Type[] { typeof(RealStatePtr) };\r\n        private MethodInfo ObjectTranslator_Assignable = typeof(ObjectTranslator).GetMethod(\"Assignable\", new Type[] { typeof(RealStatePtr),\r\n               typeof(int), typeof(Type)});\r\n\r\n        private MethodInfo Utils_BeginObjectRegister = typeof(Utils).GetMethod(\"BeginObjectRegister\");\r\n        private MethodInfo Utils_EndObjectRegister = typeof(Utils).GetMethod(\"EndObjectRegister\");\r\n        private MethodInfo Utils_BeginClassRegister = typeof(Utils).GetMethod(\"BeginClassRegister\");\r\n        private MethodInfo Utils_EndClassRegister = typeof(Utils).GetMethod(\"EndClassRegister\");\r\n        private MethodInfo Utils_RegisterFunc = typeof(Utils).GetMethod(\"RegisterFunc\");\r\n        private MethodInfo Utils_RegisterObject = typeof(Utils).GetMethod(\"RegisterObject\");\r\n\r\n        private ConstructorInfo LuaCSFunction_Constructor = typeof(LuaCSFunction).GetConstructor(new Type[] { typeof(object), typeof(IntPtr) });\r\n\r\n        private MethodInfo String_Concat = typeof(string).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) });\r\n\r\n        void checkType(ILGenerator il, Type type, LocalBuilder translator, int argPos, Label endOfBlock, bool isVParam, bool isDefault)\r\n        {\r\n            Label endOfCheckType = il.DefineLabel();\r\n\r\n            if (isVParam || isDefault)\r\n            {\r\n                il.Emit(OpCodes.Ldarg_0);\r\n                il.Emit(OpCodes.Ldc_I4, argPos);\r\n                il.Emit(OpCodes.Call, LuaAPI_lua_type);\r\n                il.Emit(OpCodes.Ldc_I4_M1);\r\n                il.Emit(OpCodes.Beq, endOfCheckType);\r\n            }\r\n\r\n            il.Emit(OpCodes.Ldloc, translator);\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldc_I4, argPos);\r\n            il.Emit(OpCodes.Ldtoken, isVParam ? type.GetElementType() : type);\r\n            il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(DeclaringType)\r\n            il.Emit(OpCodes.Callvirt, ObjectTranslator_Assignable);\r\n            il.Emit(OpCodes.Brfalse, endOfBlock);\r\n\r\n            il.MarkLabel(endOfCheckType);\r\n        }\r\n\r\n        void emitRegisterFunc(ILGenerator il, MethodBuilder method, int index, string name)\r\n        {\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldc_I4, index);\r\n            il.Emit(OpCodes.Ldstr, name);\r\n            il.Emit(OpCodes.Ldnull);\r\n            il.Emit(OpCodes.Ldftn, method);\r\n            il.Emit(OpCodes.Newobj, LuaCSFunction_Constructor);\r\n            il.Emit(OpCodes.Call, Utils_RegisterFunc);\r\n        }\r\n\r\n        void emitCatchBlock(ILGenerator il, LocalBuilder ex, LocalBuilder wrapRet, Label retPoint, Label exceptionBlock)\r\n        {\r\n            il.BeginCatchBlock(typeof(Exception));\r\n            il.Emit(OpCodes.Stloc, ex);\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldstr, \"c# exception:\");\r\n            il.Emit(OpCodes.Ldloc, ex);\r\n            il.Emit(OpCodes.Call, String_Concat);\r\n            il.Emit(OpCodes.Call, LuaAPI_luaL_error);\r\n            il.Emit(OpCodes.Stloc, wrapRet);\r\n            il.Emit(OpCodes.Leave, retPoint);\r\n            il.Emit(OpCodes.Leave, exceptionBlock);\r\n\r\n            il.EndExceptionBlock();\r\n        }\r\n\r\n        public MethodBuilder emitFieldWrap(TypeBuilder typeBuilder, FieldInfo field, bool genGetter)\r\n        {\r\n            MethodBuilder methodBuilder = typeBuilder.DefineMethod(field.Name + (genID++), MethodAttributes.Static, typeof(int), parameterTypeOfWrap);\r\n            methodBuilder.DefineParameter(1, ParameterAttributes.None, \"L\");\r\n\r\n            ILGenerator il = methodBuilder.GetILGenerator();\r\n\r\n            LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n            LocalBuilder fieldStore = il.DeclareLocal(field.FieldType);\r\n            LocalBuilder wrapRet = il.DeclareLocal(typeof(int));\r\n            LocalBuilder ex = il.DeclareLocal(typeof(Exception));\r\n\r\n            Label exceptionBlock = il.BeginExceptionBlock();\r\n            Label retPoint = il.DefineLabel();\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Stloc, L);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Call, ObjectTranslatorPool_FindTranslator);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            if (genGetter)\r\n            {\r\n                if (!field.IsStatic)\r\n                {\r\n                    EmitGetObject(il, 1, field.DeclaringType, L, translator, null);\r\n                    il.Emit(OpCodes.Ldfld, field);\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Ldsfld, field);\r\n                }\r\n                il.Emit(OpCodes.Stloc, fieldStore);\r\n                emitPush(il, field.FieldType, 2, false, L, translator, false);\r\n            }\r\n            else\r\n            {\r\n                if (!field.IsStatic)\r\n                {\r\n                    EmitGetObject(il, 1, field.DeclaringType, L, translator, null);\r\n                    LocalBuilder self = null;\r\n                    if (field.DeclaringType.IsValueType)\r\n                    {\r\n                        self = il.DeclareLocal(field.DeclaringType);\r\n                        il.Emit(OpCodes.Stloc, self);\r\n                        il.Emit(OpCodes.Ldloca, self);\r\n                    }\r\n                    EmitGetObject(il, 2, field.FieldType, L, translator, null);\r\n                    il.Emit(OpCodes.Stfld, field);\r\n                    if (self != null)\r\n                    {\r\n                        emitUpdateIfNeeded(il, L, translator, field.DeclaringType, 1, self.LocalIndex);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    EmitGetObject(il, 1, field.FieldType, L, translator, null);\r\n                    il.Emit(OpCodes.Stsfld, field);\r\n                }\r\n            }\r\n\r\n            il.Emit(OpCodes.Leave, exceptionBlock);\r\n\r\n            emitCatchBlock(il, ex, wrapRet, retPoint, exceptionBlock);\r\n\r\n            il.Emit(genGetter ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            il.MarkLabel(retPoint);\r\n            il.Emit(OpCodes.Ldloc, wrapRet);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            return methodBuilder;\r\n        }\r\n\r\n        public MethodBuilder emitPropertyWrap(TypeBuilder typeBuilder, PropertyInfo prop, MethodInfo op, bool genGetter)\r\n        {\r\n            MethodBuilder methodBuilder = typeBuilder.DefineMethod(prop.Name + (genID++), MethodAttributes.Static, typeof(int), parameterTypeOfWrap);\r\n            methodBuilder.DefineParameter(1, ParameterAttributes.None, \"L\");\r\n\r\n            ILGenerator il = methodBuilder.GetILGenerator();\r\n\r\n            LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n            LocalBuilder propStore = il.DeclareLocal(prop.PropertyType);\r\n            LocalBuilder wrapRet = il.DeclareLocal(typeof(int));\r\n            LocalBuilder ex = il.DeclareLocal(typeof(Exception));\r\n\r\n            Label exceptionBlock = il.BeginExceptionBlock();\r\n            Label retPoint = il.DefineLabel();\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Stloc, L);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Call, ObjectTranslatorPool_FindTranslator);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            if (genGetter)\r\n            {\r\n                if (!op.IsStatic)\r\n                {\r\n                    EmitGetObject(il, 1, prop.DeclaringType, L, translator, null);\r\n                    if (prop.DeclaringType.IsValueType)\r\n                    {\r\n                        var self = il.DeclareLocal(prop.DeclaringType);\r\n                        il.Emit(OpCodes.Stloc, self);\r\n                        il.Emit(OpCodes.Ldloca, self);\r\n                        il.Emit(OpCodes.Call, op);\r\n                        emitUpdateIfNeeded(il, L, translator, prop.DeclaringType, 1, self.LocalIndex);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Callvirt, op);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Call, op);\r\n                }\r\n                il.Emit(OpCodes.Stloc, propStore);\r\n                emitPush(il, prop.PropertyType, (short)propStore.LocalIndex, false, L, translator, false);\r\n            }\r\n            else\r\n            {\r\n                if (!op.IsStatic)\r\n                {\r\n                    EmitGetObject(il, 1, prop.DeclaringType, L, translator, null);\r\n                    LocalBuilder self = null;\r\n                    if (prop.DeclaringType.IsValueType)\r\n                    {\r\n                        self = il.DeclareLocal(prop.DeclaringType);\r\n                        il.Emit(OpCodes.Stloc, self);\r\n                        il.Emit(OpCodes.Ldloca, self);\r\n                    }\r\n                    EmitGetObject(il, 2, prop.PropertyType, L, translator, null);\r\n                    il.Emit(prop.DeclaringType.IsValueType ? OpCodes.Call : OpCodes.Callvirt, op);\r\n                    if (self != null)\r\n                    {\r\n                        emitUpdateIfNeeded(il, L, translator, prop.DeclaringType, 1, self.LocalIndex);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    EmitGetObject(il, 1, prop.PropertyType, L, translator, null);\r\n                    il.Emit(OpCodes.Call, op);\r\n                }\r\n            }\r\n\r\n            il.Emit(OpCodes.Leave, exceptionBlock);\r\n\r\n            emitCatchBlock(il, ex, wrapRet, retPoint, exceptionBlock);\r\n\r\n            il.Emit(genGetter ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            il.MarkLabel(retPoint);\r\n            il.Emit(OpCodes.Ldloc, wrapRet);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            return methodBuilder;\r\n        }\r\n\r\n        static HashSet<MemberInfo> BlackList = new HashSet<MemberInfo>();\r\n\r\n        static void addToBlackList(List<string> info)\r\n        {\r\n            try\r\n            {\r\n                var type = Type.GetType(info[0], true);\r\n                var members = type.GetMember(info[1], BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);\r\n                foreach(var member in members)\r\n                {\r\n                    if (member.MemberType == MemberTypes.Method)\r\n                    {\r\n                        var mb = member as MethodBase;\r\n                        var parameters = mb.GetParameters();\r\n                        if (parameters.Length != info.Count - 2)\r\n                        {\r\n                            continue;\r\n                        }\r\n\r\n                        bool paramsMatch = true;\r\n\r\n                        for (int i = 0; i < parameters.Length; i++)\r\n                        {\r\n                            if (parameters[i].ParameterType.FullName != info[i + 2])\r\n                            {\r\n                                paramsMatch = false;\r\n                                break;\r\n                            }\r\n                        }\r\n                        if (paramsMatch)\r\n                        {\r\n                            BlackList.Add(member);\r\n                        }\r\n                    }\r\n                    else if (info.Count == 2)\r\n                    {\r\n                        BlackList.Add(member);\r\n                    }\r\n                }\r\n            } catch { }\r\n        }\r\n\r\n        static void initBlackList()\r\n        {\r\n            foreach (var t in Utils.GetAllTypes(true))\r\n            {\r\n                if (!t.IsAbstract || !t.IsSealed) continue;\r\n\r\n                var fields = t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                for (int i = 0; i < fields.Length; i++)\r\n                {\r\n                    var field = fields[i];\r\n                    if (field.IsDefined(typeof(BlackListAttribute), false)\r\n                        && (typeof(List<List<string>>)).IsAssignableFrom(field.FieldType))\r\n                    {\r\n                        foreach (var info in (field.GetValue(null) as List<List<string>>))\r\n                        {\r\n                            addToBlackList(info);\r\n                        }\r\n                    }\r\n                }\r\n\r\n                var props = t.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                for (int i = 0; i < props.Length; i++)\r\n                {\r\n                    var prop = props[i];\r\n                    if (prop.IsDefined(typeof(BlackListAttribute), false)\r\n                        && (typeof(List<List<string>>)).IsAssignableFrom(prop.PropertyType))\r\n                    {\r\n                        foreach (var info in (prop.GetValue(null, null) as List<List<string>>))\r\n                        {\r\n                            addToBlackList(info);\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        static bool isMemberInBlackList(MemberInfo mb)\r\n        {\r\n            if (mb is FieldInfo && (mb as FieldInfo).FieldType.IsPointer) return true;\r\n            if (mb is PropertyInfo && (mb as PropertyInfo).PropertyType.IsPointer) return true;\r\n\r\n            if (mb.IsDefined(typeof(BlackListAttribute), false) || mb.IsDefined(typeof(ObsoleteAttribute), false)) return true;\r\n\r\n            return BlackList.Contains(mb);\r\n        }\r\n\r\n        static bool isMethodInBlackList(MethodBase mb)\r\n        {\r\n            if (mb.GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer)) return true;\r\n            if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return false;\r\n\r\n            if (mb.IsDefined(typeof(BlackListAttribute), false) || mb.IsDefined(typeof(ObsoleteAttribute), false)) return true;\r\n\r\n            return BlackList.Contains(mb);\r\n        }\r\n\r\n        public Type EmitTypeWrap(Type toBeWrap)\r\n        {\r\n            TypeBuilder wrapTypeBuilder = CodeEmitModule.DefineType(toBeWrap.Name + \"Wrap\" + (genID++), TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Abstract | TypeAttributes.Sealed);\r\n\r\n            var methodBuilder = wrapTypeBuilder.DefineMethod(\"__Register\", MethodAttributes.Static | MethodAttributes.Public, null, parameterTypeOfWrap);\r\n            methodBuilder.DefineParameter(1, ParameterAttributes.None, \"L\");\r\n\r\n            ILGenerator il = methodBuilder.GetILGenerator();\r\n\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Call, ObjectTranslatorPool_FindTranslator);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            var instanceFlag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;\r\n            var staticFlag = BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly;\r\n\r\n            var instanceFields = toBeWrap.GetFields(instanceFlag).Where(m => !isMemberInBlackList(m));\r\n            var instanceProperties = toBeWrap.GetProperties(instanceFlag).Where(m => !isMemberInBlackList(m));\r\n            var extensionMethods = Utils.GetExtensionMethodsOf(toBeWrap);\r\n            extensionMethods = (extensionMethods == null) ? Enumerable.Empty<MethodInfo>() : extensionMethods.Where(m => !isMemberInBlackList(m));\r\n            var instanceMethods = toBeWrap.GetMethods(instanceFlag)\r\n                .Where(m => !isMethodInBlackList(m))\r\n                .Concat(extensionMethods)\r\n                .Where(m => Utils.IsSupportedMethod(m))\r\n                .Where(m => !m.IsSpecialName\r\n                    || (\r\n                         ((m.Name == \"get_Item\" && m.GetParameters().Length == 1) || (m.Name == \"set_Item\" && m.GetParameters().Length == 2))\r\n                         && m.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))\r\n                       )\r\n                ).GroupBy(m => m.Name).ToList();\r\n            var supportOperators = toBeWrap.GetMethods(staticFlag)\r\n                .Where(m => !isMethodInBlackList(m))\r\n                .Where(m => m.IsSpecialName && InternalGlobals.supportOp.ContainsKey(m.Name))\r\n                .GroupBy(m => m.Name);\r\n\r\n            //begin obj\r\n            il.Emit(OpCodes.Ldtoken, toBeWrap);\r\n            il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldloc, translator);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_M1);\r\n            il.Emit(OpCodes.Call, Utils_BeginObjectRegister);\r\n\r\n            foreach(var field in instanceFields)\r\n            {\r\n                emitRegisterFunc(il, emitFieldWrap(wrapTypeBuilder, field, true), Utils.GETTER_IDX, field.Name);\r\n                emitRegisterFunc(il, emitFieldWrap(wrapTypeBuilder, field, false), Utils.SETTER_IDX, field.Name);\r\n            }\r\n\r\n            List<MethodBase> itemGetter = new List<MethodBase>();\r\n            List<MethodBase> itemSetter = new List<MethodBase>();\r\n\r\n            foreach(var prop in instanceProperties)\r\n            {\r\n                var getter = prop.GetGetMethod();\r\n                if (getter != null && getter.IsPublic)\r\n                {\r\n                    if (prop.GetIndexParameters().Length > 0)\r\n                    {\r\n                        if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))\r\n                        {\r\n                            itemGetter.Add(getter);\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        emitRegisterFunc(il, emitPropertyWrap(wrapTypeBuilder, prop, getter, true), Utils.GETTER_IDX, prop.Name);\r\n                    }\r\n                }\r\n\r\n                var setter = prop.GetSetMethod();\r\n                if (setter != null && setter.IsPublic)\r\n                {\r\n                    if (prop.GetIndexParameters().Length > 0)\r\n                    {\r\n                        if (!prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))\r\n                        {\r\n                            itemSetter.Add(setter);\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        emitRegisterFunc(il, emitPropertyWrap(wrapTypeBuilder, prop, setter, false), Utils.SETTER_IDX, prop.Name);\r\n                    }\r\n                }\r\n            }\r\n\r\n            foreach (var group in instanceMethods)\r\n            {\r\n                emitRegisterFunc(il, emitMethodWrap(wrapTypeBuilder, group.Cast<MethodBase>().ToList(), false, toBeWrap), Utils.METHOD_IDX, group.Key);\r\n            }\r\n\r\n            foreach (var group in supportOperators)\r\n            {\r\n                emitRegisterFunc(il, emitMethodWrap(wrapTypeBuilder, group.Cast<MethodBase>().ToList(), false, toBeWrap), Utils.OBJ_META_IDX, InternalGlobals.supportOp[group.Key]);\r\n            }\r\n\r\n            foreach (var ev in toBeWrap.GetEvents(instanceFlag).Where(m => !isMemberInBlackList(m)))\r\n            {\r\n                emitRegisterFunc(il, emitEventWrap(wrapTypeBuilder, ev), Utils.METHOD_IDX, ev.Name);\r\n            }\r\n\r\n            //end obj\r\n            il.Emit(OpCodes.Ldtoken, toBeWrap);\r\n            il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldloc, translator);\r\n            il.Emit(OpCodes.Ldnull);\r\n            if (itemGetter.Count > 0)\r\n            {\r\n                il.Emit(OpCodes.Ldftn, emitMethodWrap(wrapTypeBuilder, itemGetter, true, toBeWrap));\r\n                il.Emit(OpCodes.Newobj, LuaCSFunction_Constructor);\r\n            }\r\n            il.Emit(OpCodes.Ldnull);\r\n            if (itemSetter.Count > 0)\r\n            {\r\n                il.Emit(OpCodes.Ldftn, emitMethodWrap(wrapTypeBuilder, itemSetter, true, toBeWrap));\r\n                il.Emit(OpCodes.Newobj, LuaCSFunction_Constructor);\r\n            }\r\n            il.Emit(OpCodes.Ldnull);\r\n            il.Emit(OpCodes.Ldnull);\r\n            il.Emit(OpCodes.Ldnull);\r\n            il.Emit(OpCodes.Call, Utils_EndObjectRegister);\r\n\r\n            // begin class\r\n            il.Emit(OpCodes.Ldtoken, toBeWrap);\r\n            il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldnull);\r\n            il.Emit(OpCodes.Ldftn, emitMethodWrap(wrapTypeBuilder,\r\n                toBeWrap.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase)\r\n                .Where(m => !isMethodInBlackList(m))\r\n                .Cast<MethodBase>().ToList(), false, toBeWrap, toBeWrap.ToString() + \" constructor\"));\r\n            il.Emit(OpCodes.Newobj, LuaCSFunction_Constructor);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Ldc_I4_1);\r\n            il.Emit(OpCodes.Call, Utils_BeginClassRegister);\r\n\r\n            var staticMethods = toBeWrap.GetMethods(staticFlag)\r\n                .Where(m => !isMethodInBlackList(m))\r\n                .Where(m => Utils.IsSupportedMethod(m))\r\n                .Where(m => !m.IsSpecialName).GroupBy(m => m.Name);\r\n\r\n            var staticFields = toBeWrap.GetFields(staticFlag).Where(m => !isMemberInBlackList(m));\r\n\r\n            var staticProperties = toBeWrap.GetProperties(staticFlag).Where(m => !isMemberInBlackList(m));\r\n\r\n            foreach (var group in staticMethods)\r\n            {\r\n                emitRegisterFunc(il, emitMethodWrap(wrapTypeBuilder, group.Cast<MethodBase>().ToList(), false, toBeWrap), Utils.CLS_IDX, group.Key);\r\n            }\r\n\r\n            foreach (var ev in toBeWrap.GetEvents(staticFlag).Where(m => !isMemberInBlackList(m)))\r\n            {\r\n                emitRegisterFunc(il, emitEventWrap(wrapTypeBuilder, ev), Utils.CLS_IDX, ev.Name);\r\n            }\r\n\r\n            foreach (var prop in staticProperties)\r\n            {\r\n                var getter = prop.GetGetMethod();\r\n                if (getter != null && getter.IsPublic)\r\n                {\r\n                    emitRegisterFunc(il, emitPropertyWrap(wrapTypeBuilder, prop, getter, true), Utils.GETTER_IDX, prop.Name);\r\n                }\r\n\r\n                var setter = prop.GetSetMethod();\r\n                if (setter != null && setter.IsPublic)\r\n                {\r\n                    emitRegisterFunc(il, emitPropertyWrap(wrapTypeBuilder, prop, setter, false), Utils.SETTER_IDX, prop.Name);\r\n                }\r\n            }\r\n\r\n            foreach (var field in staticFields)\r\n            {\r\n                if (field.IsInitOnly || field.IsLiteral)\r\n                {\r\n                    il.Emit(OpCodes.Ldarg_0);\r\n                    il.Emit(OpCodes.Ldloc, translator);\r\n                    il.Emit(OpCodes.Ldc_I4, Utils.CLS_IDX);\r\n                    il.Emit(OpCodes.Ldstr, field.Name);\r\n                    if (field.IsLiteral)\r\n                    {\r\n                        LocalBuilder literalStore = il.DeclareLocal(field.FieldType);\r\n                        emitLiteralLoad(il, field.FieldType, field.GetValue(null), literalStore.LocalIndex);\r\n                        il.Emit(OpCodes.Stloc, literalStore);\r\n                        il.Emit(OpCodes.Ldloc, literalStore);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Ldsfld, field);\r\n                    }\r\n                    if (field.FieldType.IsValueType)\r\n                    {\r\n                        il.Emit(OpCodes.Box, field.FieldType);\r\n                    }\r\n                    il.Emit(OpCodes.Call, Utils_RegisterObject);\r\n                }\r\n                else\r\n                {\r\n                    emitRegisterFunc(il, emitFieldWrap(wrapTypeBuilder, field, true), Utils.CLS_GETTER_IDX, field.Name);\r\n                    emitRegisterFunc(il, emitFieldWrap(wrapTypeBuilder, field, false), Utils.CLS_SETTER_IDX, field.Name);\r\n                }\r\n            }\r\n\r\n            //end class\r\n            il.Emit(OpCodes.Ldtoken, toBeWrap);\r\n            il.Emit(OpCodes.Call, Type_GetTypeFromHandle); // typeof(type)\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldloc, translator);\r\n            il.Emit(OpCodes.Call, Utils_EndClassRegister);\r\n\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            return wrapTypeBuilder.CreateType();\r\n        }\r\n\r\n        MethodBuilder emitEventWrap(TypeBuilder typeBuilder, EventInfo ev)\r\n        {\r\n            var addEvent = ev.GetAddMethod();\r\n            var removeEvent = ev.GetRemoveMethod();\r\n\r\n            if (addEvent == null && removeEvent == null)\r\n            {\r\n                return null;\r\n            }\r\n\r\n            bool isStatic = addEvent != null ? addEvent.IsStatic : removeEvent.IsStatic;\r\n\r\n            var methodBuilder = typeBuilder.DefineMethod(ev.Name + (genID++), MethodAttributes.Static, typeof(int), parameterTypeOfWrap);\r\n            methodBuilder.DefineParameter(1, ParameterAttributes.None, \"L\");\r\n\r\n            ILGenerator il = methodBuilder.GetILGenerator();\r\n\r\n            LocalBuilder wrapRet = il.DeclareLocal(typeof(int));\r\n            LocalBuilder ex = il.DeclareLocal(typeof(Exception));\r\n            LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n            LocalBuilder callback = il.DeclareLocal(ev.EventHandlerType);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Stloc, L);\r\n\r\n            Label exceptionBlock = il.BeginExceptionBlock();\r\n            Label retPoint = il.DefineLabel();\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Call, ObjectTranslatorPool_FindTranslator);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            EmitGetObject(il, isStatic ? 2 : 3, ev.EventHandlerType, L, translator, null);\r\n            il.Emit(OpCodes.Stloc, callback);\r\n            il.Emit(OpCodes.Ldloc, callback);\r\n            Label ifBlock = il.DefineLabel();\r\n            il.Emit(OpCodes.Brtrue, ifBlock);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldstr, string.Format(\"#{0}, need {1}\", isStatic ? 2 : 3, ev.EventHandlerType));\r\n            il.Emit(OpCodes.Call, LuaAPI_luaL_error);\r\n            il.Emit(OpCodes.Stloc, wrapRet);\r\n            il.Emit(OpCodes.Leave, retPoint);\r\n            il.MarkLabel(ifBlock);\r\n\r\n            if (addEvent != null)\r\n            {\r\n                il.Emit(OpCodes.Ldarg_0);\r\n                il.Emit(isStatic ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_2);\r\n                il.Emit(OpCodes.Ldstr, \"+\");\r\n                il.Emit(OpCodes.Call, LuaAPI_xlua_is_eq_str);\r\n                ifBlock = il.DefineLabel();\r\n                il.Emit(OpCodes.Brfalse, ifBlock);\r\n\r\n                if (!isStatic)\r\n                {\r\n                    EmitGetObject(il, 1, ev.DeclaringType, L, translator, null);\r\n                    if (ev.DeclaringType.IsValueType)\r\n                    {\r\n                        var self = il.DeclareLocal(ev.DeclaringType);\r\n                        il.Emit(OpCodes.Stloc, self);\r\n                        il.Emit(OpCodes.Ldloca, self);\r\n                    }\r\n                }\r\n                il.Emit(OpCodes.Ldloc, callback);\r\n                il.Emit(OpCodes.Call, addEvent);\r\n                il.Emit(OpCodes.Ldc_I4_0);\r\n                il.Emit(OpCodes.Leave, retPoint);\r\n                il.MarkLabel(ifBlock);\r\n            }\r\n\r\n            if (removeEvent != null)\r\n            {\r\n                il.Emit(OpCodes.Ldarg_0);\r\n                il.Emit(isStatic ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_2);\r\n                il.Emit(OpCodes.Ldstr, \"-\");\r\n                il.Emit(OpCodes.Call, LuaAPI_xlua_is_eq_str);\r\n                ifBlock = il.DefineLabel();\r\n                il.Emit(OpCodes.Brfalse, ifBlock);\r\n\r\n                if (!isStatic)\r\n                {\r\n                    EmitGetObject(il, 1, ev.DeclaringType, L, translator, null);\r\n                    if (ev.DeclaringType.IsValueType)\r\n                    {\r\n                        var self = il.DeclareLocal(ev.DeclaringType);\r\n                        il.Emit(OpCodes.Stloc, self);\r\n                        il.Emit(OpCodes.Ldloca, self);\r\n                    }\r\n                }\r\n                il.Emit(OpCodes.Ldloc, callback);\r\n                il.Emit(OpCodes.Call, removeEvent);\r\n                il.Emit(OpCodes.Ldc_I4_0);\r\n                il.Emit(OpCodes.Leave, retPoint);\r\n                il.MarkLabel(ifBlock);\r\n            }\r\n\r\n            il.Emit(OpCodes.Leave, exceptionBlock);\r\n\r\n            emitCatchBlock(il, ex, wrapRet, retPoint, exceptionBlock);\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Ldstr, \"invalid arguments to \" + ev.DeclaringType + \".\" + ev.Name + \"!\");\r\n            il.Emit(OpCodes.Call, LuaAPI_luaL_error);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            il.MarkLabel(retPoint);\r\n            il.Emit(OpCodes.Ldloc, wrapRet);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            return methodBuilder;\r\n        }\r\n\r\n        void emitUpdateIfNeeded(ILGenerator il, LocalBuilder L, LocalBuilder translator, Type type, int luaIndex, int localIndex)\r\n        {\r\n            if (type.IsValueType && !type.IsPrimitive && !type.IsEnum() && type != typeof(decimal))\r\n            {\r\n                //UnityEngine.Debug.LogWarning(\"-----------------emit update:\" + type);\r\n                il.Emit(OpCodes.Ldloc, translator);\r\n                il.Emit(OpCodes.Ldloc, L);\r\n                il.Emit(OpCodes.Ldc_I4, luaIndex);\r\n                il.Emit(OpCodes.Ldloc, localIndex);\r\n                il.Emit(OpCodes.Box, type);\r\n                il.Emit(OpCodes.Callvirt, ObjectTranslator_Update);\r\n            }\r\n        }\r\n\r\n        //private MethodInfo UnityEngine_Debug_Log = typeof(UnityEngine.Debug).GetMethod(\"Log\", new Type[] { typeof(object)});\r\n        int firstDefaultValue(MethodBase method)\r\n        {\r\n            var parameters = method.GetParameters();\r\n            for(int i = 0; i < parameters.Length; i++)\r\n            {\r\n                if (parameters[i].IsOptional) return i;\r\n            }\r\n            return -1;\r\n        }\r\n\r\n        MethodBuilder emitMethodWrap(TypeBuilder typeBuilder, List<MethodBase> methodsToCall, bool isIndexer, Type declaringType, string methodDesciption = null)\r\n        {\r\n            string wrapName = (methodsToCall.Count > 0 ? methodsToCall[0].Name : \"Constructor\");\r\n            var methodBuilder = typeBuilder.DefineMethod(wrapName + (genID++), MethodAttributes.Static, typeof(int), parameterTypeOfWrap);\r\n            methodBuilder.DefineParameter(1,  ParameterAttributes.None, \"L\");\r\n\r\n            bool needCheckParameterType = (methodsToCall.Count > 1)  || isIndexer;\r\n\r\n            if (methodsToCall.Count == 0 || methodsToCall[0].IsConstructor)\r\n            {\r\n                needCheckParameterType = true;\r\n            }\r\n\r\n            if (methodsToCall.Count == 1 && firstDefaultValue(methodsToCall[0]) != -1)\r\n            {\r\n                needCheckParameterType = true;\r\n            }\r\n\r\n            ILGenerator il = methodBuilder.GetILGenerator();\r\n\r\n            LocalBuilder wrapRet = il.DeclareLocal(typeof(int));\r\n            LocalBuilder ex = il.DeclareLocal(typeof(Exception));\r\n            LocalBuilder L = il.DeclareLocal(typeof(RealStatePtr));\r\n            LocalBuilder translator = il.DeclareLocal(typeof(ObjectTranslator));\r\n            LocalBuilder top = il.DeclareLocal(typeof(int));\r\n\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Stloc, L);\r\n\r\n            Label exceptionBlock = il.BeginExceptionBlock();\r\n            Label retPoint = il.DefineLabel();\r\n            il.Emit(OpCodes.Ldarg_0);\r\n            il.Emit(OpCodes.Call, ObjectTranslatorPool_FindTranslator);\r\n            il.Emit(OpCodes.Stloc, translator);\r\n\r\n            if (needCheckParameterType)\r\n            {\r\n                il.Emit(OpCodes.Ldarg_0);\r\n                il.Emit(OpCodes.Call, LuaAPI_lua_gettop);\r\n                il.Emit(OpCodes.Stloc, top);\r\n            }\r\n\r\n            for (int i = 0; i < methodsToCall.Count; i++)\r\n            {\r\n                var method = methodsToCall[i];\r\n                if ((method is MethodInfo) && method.ContainsGenericParameters)\r\n                {\r\n                    method = Utils.MakeGenericMethodWithConstraints(method as MethodInfo);\r\n                }\r\n                bool isStatic = method.IsStatic;\r\n                var paramInfos = method.GetParameters();\r\n                int minInParamCount = 0;\r\n                int maxInParamCount = 0;\r\n                int outParamCount = 0;\r\n                bool hasParams = paramInfos.Length > 0 && paramInfos[paramInfos.Length - 1].IsDefined(typeof(ParamArrayAttribute), false);\r\n                bool hasOptional = false;\r\n\r\n                LocalBuilder methodReturn = null;\r\n\r\n                for (int j = 0; j < paramInfos.Length; j++)\r\n                {\r\n                    if (!paramInfos[j].IsOut)\r\n                    {\r\n                        if (!paramInfos[j].IsOptional && (!hasParams || j != paramInfos.Length - 1))\r\n                        {\r\n                            minInParamCount++;\r\n                        }\r\n                        maxInParamCount++;\r\n                    }\r\n                    if (paramInfos[j].IsOptional)\r\n                    {\r\n                        hasOptional = true;\r\n                    }\r\n                    if (paramInfos[j].ParameterType.IsByRef)\r\n                    {\r\n                        outParamCount++;\r\n                    }\r\n                }\r\n\r\n                Label endOfBlock = il.DefineLabel();\r\n\r\n                if (needCheckParameterType)\r\n                {\r\n                    il.Emit(OpCodes.Ldloc, top);\r\n                    il.Emit(OpCodes.Ldc_I4, minInParamCount + (isStatic ? 0 : 1));\r\n                    il.Emit((hasParams || hasOptional) ? OpCodes.Blt : OpCodes.Bne_Un, endOfBlock);\r\n\r\n                    if (hasOptional && !hasParams)\r\n                    {\r\n                        il.Emit(OpCodes.Ldloc, top);\r\n                        il.Emit(OpCodes.Ldc_I4, maxInParamCount + (isStatic ? 0 : 1));\r\n                        il.Emit(OpCodes.Bgt, endOfBlock);\r\n                    }\r\n                    \r\n                    if (!isStatic && !method.IsConstructor)\r\n                    {\r\n                        checkType(il, method.DeclaringType, translator, 1, endOfBlock, false, false);\r\n                    }\r\n\r\n                    int argPos = isStatic ? 1 : 2;\r\n\r\n                    for (int j = 0; j < paramInfos.Length; j++)\r\n                    {\r\n                        var paramInfo = paramInfos[j];\r\n                        if (!paramInfo.IsOut)\r\n                        {\r\n                            var rawParamType = paramInfo.ParameterType;\r\n                            if (rawParamType.IsByRef)\r\n                            {\r\n                                rawParamType = rawParamType.GetElementType();\r\n                            }\r\n                            checkType(il, rawParamType, translator, argPos++, endOfBlock, \r\n                                hasParams && (j == paramInfos.Length - 1), paramInfo.IsOptional);\r\n                        }\r\n                    }\r\n                }\r\n\r\n                int luaPos = isStatic ? 1 : 2;\r\n\r\n                int argStoreStart = -1;\r\n\r\n                for (int j = 0; j < paramInfos.Length; j++)\r\n                {\r\n                    var paramInfo = paramInfos[j];\r\n                    var paramRawType = paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() :\r\n                        paramInfo.ParameterType;\r\n                    var argStore = il.DeclareLocal(paramRawType);\r\n                    if (paramInfo.IsOptional)\r\n                    {\r\n                        //UnityEngine.Debug.Log(paramInfo.Name + \",\" + paramRawType + \",\" + paramInfo.DefaultValue);\r\n                        emitLiteralLoad(il, paramRawType, paramInfo.DefaultValue, argStore.LocalIndex);\r\n                        il.Emit(OpCodes.Stloc, argStore);\r\n                    }\r\n                    //UnityEngine.Debug.LogWarning(declaringType.Name + \".\" + method.Name + \".\" + paramInfos[j].Name + \" pos(d):\" + argStore.LocalIndex + \", pt:\" + paramRawType + \", j:\" + j);\r\n                    if (argStoreStart == -1)\r\n                    {\r\n                        argStoreStart = argStore.LocalIndex;\r\n                    }\r\n                    \r\n                }\r\n                for (int j = 0; j < paramInfos.Length; j++)\r\n                {\r\n                    var paramInfo = paramInfos[j];\r\n                    var paramRawType = paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() :\r\n                        paramInfo.ParameterType;\r\n                    if (!paramInfo.IsOut)\r\n                    {\r\n                        Label endOfGetValue = il.DefineLabel();\r\n                        if (paramInfo.IsOptional)\r\n                        {\r\n                            il.Emit(OpCodes.Ldarg_0);\r\n                            il.Emit(OpCodes.Ldc_I4, luaPos);\r\n                            il.Emit(OpCodes.Call, LuaAPI_lua_type);\r\n                            il.Emit(OpCodes.Ldc_I4_M1);\r\n                            il.Emit(OpCodes.Beq, endOfGetValue);\r\n                        }\r\n                        EmitGetObject(il, luaPos++, paramRawType, L, translator, null, hasParams && (j == paramInfos.Length - 1));\r\n                        il.Emit(OpCodes.Stloc, argStoreStart + j);\r\n                        il.MarkLabel(endOfGetValue);\r\n                    }\r\n                }\r\n\r\n                LocalBuilder valueTypeTmp = null;\r\n\r\n                if (!isStatic && (!method.IsConstructor || method.DeclaringType.IsValueType))\r\n                {\r\n                    if (!method.IsConstructor)\r\n                    {\r\n                        EmitGetObject(il, 1, method.DeclaringType, L, translator, null);\r\n                    }\r\n                    if (method.DeclaringType.IsValueType)\r\n                    {\r\n                        if (method.IsConstructor)\r\n                        {\r\n                            methodReturn = il.DeclareLocal(method.DeclaringType);\r\n                            il.Emit(OpCodes.Ldloca, methodReturn);\r\n                        }\r\n                        else\r\n                        {\r\n                            valueTypeTmp = il.DeclareLocal(method.DeclaringType);\r\n                            il.Emit(OpCodes.Stloc, valueTypeTmp);\r\n                            il.Emit(OpCodes.Ldloca, valueTypeTmp);\r\n                        }\r\n                    }\r\n                }\r\n\r\n                for (int j = 0; j < paramInfos.Length; j++)\r\n                {\r\n                    //UnityEngine.Debug.LogWarning(declaringType.Name + \".\" + method.Name + \".\" + paramInfos[j].Name +\" pos:\" + (argStoreStart + j) + \", op:\" + (paramInfos[j].ParameterType.IsByRef ? OpCodes.Ldloca : OpCodes.Ldloc) + \", j:\" + j );\r\n                    il.Emit(paramInfos[j].ParameterType.IsByRef ? OpCodes.Ldloca : OpCodes.Ldloc, argStoreStart + j);\r\n                }\r\n\r\n                if (method.IsConstructor)\r\n                {\r\n                    if (method.DeclaringType.IsValueType)\r\n                    {\r\n                        il.Emit(OpCodes.Call, method as ConstructorInfo);\r\n                    }\r\n                    else\r\n                    {\r\n                        il.Emit(OpCodes.Newobj, method as ConstructorInfo);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(isStatic ? OpCodes.Call : OpCodes.Callvirt, method as MethodInfo);\r\n                }\r\n\r\n                if (valueTypeTmp != null)\r\n                {\r\n                    emitUpdateIfNeeded(il, L, translator, method.DeclaringType, 1, valueTypeTmp.LocalIndex);\r\n                }\r\n\r\n                if (isIndexer)\r\n                {\r\n                    il.Emit(OpCodes.Ldarg_0);\r\n                    il.Emit(OpCodes.Ldc_I4_1);\r\n                    il.Emit(OpCodes.Call, LuaAPI_lua_pushboolean);\r\n                }\r\n\r\n                bool hasReturn = false;\r\n\r\n                MethodInfo methodInfo = method as MethodInfo;\r\n                if (methodInfo == null || methodInfo.ReturnType != typeof(void))\r\n                {\r\n                    hasReturn = true;\r\n                    Type returnType = methodInfo == null ? method.DeclaringType : methodInfo.ReturnType;\r\n                    if (methodReturn == null)\r\n                    {\r\n                        methodReturn = il.DeclareLocal(returnType);\r\n                        il.Emit(OpCodes.Stloc, methodReturn);\r\n                    }\r\n                    emitPush(il, returnType, (short)methodReturn.LocalIndex, false, L, translator, false);\r\n                }\r\n\r\n                int luaIndex = isStatic ? 1 : 2;\r\n                for (int j = 0; j < paramInfos.Length; j++)\r\n                {\r\n                    if (paramInfos[j].ParameterType.IsByRef)\r\n                    {\r\n                        var rawParamType = paramInfos[j].ParameterType.GetElementType();\r\n                        emitPush(il, rawParamType,\r\n                            (short)(argStoreStart + j), false, L, translator, false);\r\n                        if (!paramInfos[j].IsOut)\r\n                        {\r\n                            emitUpdateIfNeeded(il, L, translator, rawParamType, luaIndex, argStoreStart + j);\r\n                        }\r\n                    }\r\n                    if (!paramInfos[j].IsOut)\r\n                    {\r\n                        luaIndex++;\r\n                    }\r\n                }\r\n\r\n                il.Emit(OpCodes.Ldc_I4, outParamCount + (hasReturn ? 1 : 0) + (isIndexer ? 1 : 0));\r\n                il.Emit(OpCodes.Stloc, wrapRet);\r\n                il.Emit(OpCodes.Leave, retPoint);\r\n                //il.Emit(OpCodes.Ret);\r\n\r\n                if (needCheckParameterType)\r\n                {\r\n                    il.MarkLabel(endOfBlock);\r\n                }\r\n            }\r\n\r\n            if (declaringType.IsValueType && (methodsToCall.Count == 0 || methodsToCall[0].IsConstructor))\r\n            {\r\n                Label endOfBlock = il.DefineLabel();\r\n                il.Emit(OpCodes.Ldloc, top);\r\n                il.Emit(OpCodes.Ldc_I4_1);\r\n                il.Emit(OpCodes.Bne_Un, endOfBlock);\r\n\r\n                var methodReturn = il.DeclareLocal(declaringType);\r\n\r\n                il.Emit(OpCodes.Ldloca, methodReturn);\r\n                il.Emit(OpCodes.Initobj, declaringType);\r\n                emitPush(il, declaringType, (short)methodReturn.LocalIndex, false, L, translator, false);\r\n                il.Emit(OpCodes.Ldc_I4_1);\r\n                il.Emit(OpCodes.Stloc, wrapRet);\r\n                il.Emit(OpCodes.Leave_S, retPoint);\r\n                il.MarkLabel(endOfBlock);\r\n            }\r\n\r\n            il.Emit(OpCodes.Leave, exceptionBlock);\r\n            emitCatchBlock(il, ex, wrapRet, retPoint, exceptionBlock);\r\n\r\n            if (needCheckParameterType)\r\n            {\r\n                if (isIndexer)\r\n                {\r\n                    il.Emit(OpCodes.Ldarg_0);\r\n                    il.Emit(OpCodes.Ldc_I4_0);\r\n                    il.Emit(OpCodes.Call, LuaAPI_lua_pushboolean);\r\n                    il.Emit(OpCodes.Ldc_I4_1);\r\n                    il.Emit(OpCodes.Ret);\r\n                }\r\n                else\r\n                {\r\n                    il.Emit(OpCodes.Ldarg_0);\r\n                    if (methodDesciption == null)\r\n                    {\r\n                        if (methodsToCall.Count > 0)\r\n                        {\r\n                            methodDesciption = declaringType + \".\" + methodsToCall[0].Name;\r\n                        }\r\n                        else\r\n                        {\r\n                            methodDesciption = \"unknow method in \" + declaringType;\r\n                        }\r\n                    }\r\n                    il.Emit(OpCodes.Ldstr, \"invalid arguments to \" + methodDesciption + \"!\");\r\n                    il.Emit(OpCodes.Call, LuaAPI_luaL_error);\r\n                    il.Emit(OpCodes.Ret);\r\n                }\r\n            }\r\n\r\n            il.MarkLabel(retPoint);\r\n            il.Emit(OpCodes.Ldloc, wrapRet);\r\n            il.Emit(OpCodes.Ret);\r\n\r\n            return methodBuilder;\r\n        }\r\n    }\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "Assets/XLua/Src/CodeEmit.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 93ce5fd372271b04199841c920eb0268\ntimeCreated: 1470883945\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/CopyByValue.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\n\r\nnamespace XLua\r\n{\r\n    public static partial class CopyByValue\r\n    {\r\n        // for int 8\r\n        public static bool Pack(IntPtr buff, int offset, byte field)\r\n        {\r\n            return LuaAPI.xlua_pack_int8_t(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out byte field)\r\n        {\r\n            return LuaAPI.xlua_unpack_int8_t(buff, offset, out field);\r\n        }\r\n        public static bool Pack(IntPtr buff, int offset, sbyte field)\r\n        {\r\n            return LuaAPI.xlua_pack_int8_t(buff, offset, (byte)field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out sbyte field)\r\n        {\r\n            byte tfield;\r\n            bool ret = LuaAPI.xlua_unpack_int8_t(buff, offset, out tfield);\r\n            field = (sbyte)tfield;\r\n            return ret;\r\n        }\r\n        // for int16\r\n        public static bool Pack(IntPtr buff, int offset, short field)\r\n        {\r\n            return LuaAPI.xlua_pack_int16_t(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out short field)\r\n        {\r\n            return LuaAPI.xlua_unpack_int16_t(buff, offset, out field);\r\n        }\r\n        public static bool Pack(IntPtr buff, int offset, ushort field)\r\n        {\r\n            return LuaAPI.xlua_pack_int16_t(buff, offset, (short)field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out ushort field)\r\n        {\r\n            short tfield;\r\n            bool ret = LuaAPI.xlua_unpack_int16_t(buff, offset, out tfield);\r\n            field = (ushort)tfield;\r\n            return ret;\r\n        }\r\n        // for int32\r\n        public static bool Pack(IntPtr buff, int offset, int field)\r\n        {\r\n            return LuaAPI.xlua_pack_int32_t(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out int field)\r\n        {\r\n            return LuaAPI.xlua_unpack_int32_t(buff, offset, out field);\r\n        }\r\n        public static bool Pack(IntPtr buff, int offset, uint field)\r\n        {\r\n            return LuaAPI.xlua_pack_int32_t(buff, offset, (int)field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out uint field)\r\n        {\r\n            int tfield;\r\n            bool ret = LuaAPI.xlua_unpack_int32_t(buff, offset, out tfield);\r\n            field = (uint)tfield;\r\n            return ret;\r\n        }\r\n        // for int64\r\n        public static bool Pack(IntPtr buff, int offset, long field)\r\n        {\r\n            return LuaAPI.xlua_pack_int64_t(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out long field)\r\n        {\r\n            return LuaAPI.xlua_unpack_int64_t(buff, offset, out field);\r\n        }\r\n        public static bool Pack(IntPtr buff, int offset, ulong field)\r\n        {\r\n            return LuaAPI.xlua_pack_int64_t(buff, offset, (long)field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out ulong field)\r\n        {\r\n            long tfield;\r\n            bool ret = LuaAPI.xlua_unpack_int64_t(buff, offset, out tfield);\r\n            field = (ulong)tfield;\r\n            return ret;\r\n        }\r\n        // for float\r\n        public static bool Pack(IntPtr buff, int offset, float field)\r\n        {\r\n            return LuaAPI.xlua_pack_float(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out float field)\r\n        {\r\n            return LuaAPI.xlua_unpack_float(buff, offset, out field);\r\n        }\r\n        // for double\r\n        public static bool Pack(IntPtr buff, int offset, double field)\r\n        {\r\n            return LuaAPI.xlua_pack_double(buff, offset, field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out double field)\r\n        {\r\n            return LuaAPI.xlua_unpack_double(buff, offset, out field);\r\n        }\r\n        // for decimal\r\n        public static bool Pack(IntPtr buff, int offset, decimal field)\r\n        {\r\n            return LuaAPI.xlua_pack_decimal(buff, offset, ref field);\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out decimal field)\r\n        {\r\n            byte scale;\r\n            byte sign;\r\n            int hi32;\r\n            ulong lo64;\r\n            if (!LuaAPI.xlua_unpack_decimal(buff, offset, out scale, out sign, out hi32, out lo64))\r\n            {\r\n                field = default(decimal);\r\n                return false;\r\n            }\r\n\r\n            field = new Decimal((int)(lo64 & 0xFFFFFFFF), (int)(lo64 >> 32), hi32, (sign & 0x80) != 0, scale);\r\n            return true;\r\n        }\r\n\r\n        public static bool IsStruct(Type type)\r\n        {\r\n            return type.IsValueType() && !type.IsEnum() && !type.IsPrimitive();\r\n        }\r\n\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/CopyByValue.cs.meta",
    "content": "fileFormatVersion: 2\nguid: aba23a1792dbc49438a2357566447979\ntimeCreated: 1467189953\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/DelegateBridge.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Runtime.InteropServices;\r\n\r\nnamespace XLua\r\n{\r\n    public abstract class DelegateBridgeBase : LuaBase\r\n    {\r\n        private Type firstKey = null;\r\n\r\n        private Delegate firstValue = null;\r\n\r\n        private Dictionary<Type, Delegate> bindTo = null;\r\n\r\n        protected int errorFuncRef;\r\n\r\n        public DelegateBridgeBase(int reference, LuaEnv luaenv) : base(reference, luaenv)\r\n        {\r\n            errorFuncRef = luaenv.errorFuncRef;\r\n        }\r\n\r\n        public bool TryGetDelegate(Type key, out Delegate value)\r\n        {\r\n            if(key == firstKey)\r\n            {\r\n                value = firstValue;\r\n                return true;\r\n            }\r\n            if (bindTo != null)\r\n            {\r\n                return bindTo.TryGetValue(key, out value);\r\n            }\r\n            value = null;\r\n            return false;\r\n        }\r\n\r\n        public void AddDelegate(Type key, Delegate value)\r\n        {\r\n            if (key == firstKey)\r\n            {\r\n                throw new ArgumentException(\"An element with the same key already exists in the dictionary.\");\r\n            }\r\n\r\n            if (firstKey == null && bindTo == null) // nothing \r\n            {\r\n                firstKey = key;\r\n                firstValue = value;\r\n            }\r\n            else if (firstKey != null && bindTo == null) // one key existed\r\n            {\r\n                bindTo = new Dictionary<Type, Delegate>();\r\n                bindTo.Add(firstKey, firstValue);\r\n                firstKey = null;\r\n                firstValue = null;\r\n                bindTo.Add(key, value);\r\n            }\r\n            else\r\n            {\r\n                bindTo.Add(key, value);\r\n            }\r\n        }\r\n\r\n        public virtual Delegate GetDelegateByType(Type type)\r\n        {\r\n            return null;\r\n        }\r\n    }\r\n\r\n    public static class HotfixDelegateBridge\r\n    {\r\n#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR\r\n        [DllImport(\"__Internal\", CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_get_hotfix_flag(int idx);\r\n\r\n        \r\n        [DllImport(\"__Internal\", CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_set_hotfix_flag(int idx, bool flag);\r\n#else\r\n        public static bool xlua_get_hotfix_flag(int idx)\r\n        {\r\n            return (idx < DelegateBridge.DelegateBridgeList.Length) && (DelegateBridge.DelegateBridgeList[idx] != null);\r\n        }\r\n#endif\r\n\r\n        public static DelegateBridge Get(int idx)\r\n        {\r\n            return DelegateBridge.DelegateBridgeList[idx];\r\n        }\r\n\r\n        public static void Set(int idx, DelegateBridge val)\r\n        {\r\n            if (idx >= DelegateBridge.DelegateBridgeList.Length)\r\n            {\r\n                DelegateBridge[] newList = new DelegateBridge[idx + 1];\r\n                for (int i = 0; i < DelegateBridge.DelegateBridgeList.Length; i++)\r\n                {\r\n                    newList[i] = DelegateBridge.DelegateBridgeList[i];\r\n                }\r\n                DelegateBridge.DelegateBridgeList = newList;\r\n            }\r\n            DelegateBridge.DelegateBridgeList[idx] = val;\r\n#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR\r\n            xlua_set_hotfix_flag(idx, val != null);\r\n#endif\r\n        }\r\n    }\r\n\r\n    public partial class DelegateBridge : DelegateBridgeBase\r\n    {\r\n        internal static DelegateBridge[] DelegateBridgeList = new DelegateBridge[0];\r\n\r\n        public static bool Gen_Flag = false;\r\n\r\n        public DelegateBridge(int reference, LuaEnv luaenv) : base(reference, luaenv)\r\n        {\r\n        }\r\n\r\n        public void PCall(IntPtr L, int nArgs, int nResults, int errFunc)\r\n        {\r\n            if (LuaAPI.lua_pcall(L, nArgs, nResults, errFunc) != 0)\r\n                luaEnv.ThrowExceptionFromError(errFunc - 1);\r\n        }\r\n\r\n#if HOTFIX_ENABLE\r\n\r\n        private int _oldTop = 0;\r\n        private Stack<int> _stack = new Stack<int>();\r\n\r\n        public void InvokeSessionStart()\r\n        {\r\n            System.Threading.Monitor.Enter(luaEnv.luaEnvLock);\r\n            var L = luaEnv.L;\r\n            _stack.Push(_oldTop);\r\n            _oldTop = LuaAPI.lua_gettop(L);\r\n            LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n            LuaAPI.lua_getref(L, luaReference);\r\n        }\r\n\r\n        public void Invoke(int nRet)\r\n        {\r\n            int error = LuaAPI.lua_pcall(luaEnv.L, LuaAPI.lua_gettop(luaEnv.L) - _oldTop - 2, nRet, _oldTop + 1);\r\n            if (error != 0)\r\n            {\r\n                var lastOldTop = _oldTop;\r\n                _oldTop = _stack.Pop();\r\n                System.Threading.Monitor.Exit(luaEnv.luaEnvLock);\r\n                luaEnv.ThrowExceptionFromError(lastOldTop);\r\n            }\r\n        }\r\n\r\n        public void InvokeSessionEnd()\r\n        {\r\n            LuaAPI.lua_settop(luaEnv.L, _oldTop);\r\n            _oldTop = _stack.Pop();\r\n            System.Threading.Monitor.Exit(luaEnv.luaEnvLock);\r\n        }\r\n\r\n        public TResult InvokeSessionEndWithResult<TResult>()\r\n        {\r\n            if (LuaAPI.lua_gettop(luaEnv.L) < _oldTop + 2)\r\n            {\r\n                InvokeSessionEnd();\r\n                throw new InvalidOperationException(\"no result!\");\r\n            }\r\n\r\n            try\r\n            {\r\n                TResult ret;\r\n                luaEnv.translator.Get(luaEnv.L, _oldTop + 2, out ret);\r\n                return ret;\r\n            }\r\n            finally\r\n            {\r\n                InvokeSessionEnd();\r\n            }\r\n        }\r\n\r\n        public void InParam<T>(T p)\r\n        {\r\n            try\r\n            {\r\n                luaEnv.translator.PushByType(luaEnv.L, p);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                InvokeSessionEnd();\r\n                throw e;\r\n            }\r\n        }\r\n\r\n        public void InParams<T>(T[] ps)\r\n        {\r\n            try\r\n            {\r\n                for (int i = 0; i < ps.Length; i++)\r\n                {\r\n                    luaEnv.translator.PushByType<T>(luaEnv.L, ps[i]);\r\n                }\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                InvokeSessionEnd();\r\n                throw e;\r\n            }\r\n        }\r\n\r\n        //pos start from 0\r\n        public void OutParam<TResult>(int pos, out TResult ret)\r\n        {\r\n            if (LuaAPI.lua_gettop(luaEnv.L) < _oldTop + 2 + pos)\r\n            {\r\n                InvokeSessionEnd();\r\n                throw new InvalidOperationException(\"no result in \" + pos);\r\n            }\r\n\r\n            try\r\n            {\r\n                luaEnv.translator.Get(luaEnv.L, _oldTop + 2 + pos, out ret);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                InvokeSessionEnd();\r\n                throw e;\r\n            }\r\n        }\r\n#endif\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/DelegateBridge.cs.meta",
    "content": "fileFormatVersion: 2\nguid: b8c4165852e3e92468656dc6efb30a28\ntimeCreated: 1452574309\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Generator.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if !XLUA_GENERAL\r\nusing UnityEngine;\r\nusing UnityEditor;\r\n#endif\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing XLua;\r\nusing System;\r\nusing System.Reflection;\r\nusing System.Text;\r\nusing System.Linq;\r\nusing System.Runtime.CompilerServices;\r\n\r\nnamespace CSObjectWrapEditor\r\n{\r\n    public static class GeneratorConfig\r\n    {\r\n#if XLUA_GENERAL\r\n        public static string common_path = \"./Gen/\";\r\n#else\r\n        public static string common_path = Application.dataPath + \"/XLua/Gen/\";\r\n#endif\r\n\r\n        static GeneratorConfig()\r\n        {\r\n            foreach(var type in (from type in XLua.Utils.GetAllTypes()\r\n            where type.IsAbstract && type.IsSealed\r\n            select type))\r\n            {\r\n                foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))\r\n                {\r\n                    if (field.FieldType == typeof(string) && field.IsDefined(typeof(GenPathAttribute), false))\r\n                    {\r\n                        common_path = field.GetValue(null) as string;\r\n                        if (!common_path.EndsWith(\"/\"))\r\n                        {\r\n                            common_path = common_path + \"/\";\r\n                        }\r\n                    }\r\n                }\r\n\r\n                foreach (var prop in type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))\r\n                {\r\n                    if (prop.PropertyType == typeof(string) && prop.IsDefined(typeof(GenPathAttribute), false))\r\n                    {\r\n                        common_path = prop.GetValue(null, null) as string;\r\n                        if (!common_path.EndsWith(\"/\"))\r\n                        {\r\n                            common_path = common_path + \"/\";\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    public struct CustomGenTask\r\n    {\r\n        public LuaTable Data;\r\n        public TextWriter Output;\r\n    }\r\n\r\n    public struct UserConfig\r\n    {\r\n        public IEnumerable<Type> LuaCallCSharp;\r\n        public IEnumerable<Type> CSharpCallLua;\r\n        public IEnumerable<Type> ReflectionUse;\r\n    }\r\n\r\n    public class GenCodeMenuAttribute : Attribute\r\n    {\r\n\r\n    }\r\n\r\n    public class GenPathAttribute : Attribute\r\n    {\r\n\r\n    }\r\n\r\n    public struct XLuaTemplate\r\n    {\r\n        public string name;\r\n        public string text;\r\n    }\r\n\r\n    public struct XLuaTemplates\r\n    {\r\n        public XLuaTemplate LuaClassWrap;\r\n        public XLuaTemplate LuaDelegateBridge;\r\n        public XLuaTemplate LuaDelegateWrap;\r\n        public XLuaTemplate LuaEnumWrap;\r\n        public XLuaTemplate LuaInterfaceBridge;\r\n        public XLuaTemplate LuaRegister;\r\n        public XLuaTemplate LuaWrapPusher;\r\n        public XLuaTemplate PackUnpack;\r\n        public XLuaTemplate TemplateCommon;\r\n    }\r\n\r\n    public static class Generator\r\n    {\r\n        static LuaEnv luaenv = new LuaEnv();\r\n        static List<string> OpMethodNames = new List<string>() { \"op_Addition\", \"op_Subtraction\", \"op_Multiply\", \"op_Division\", \"op_Equality\", \"op_UnaryNegation\", \"op_LessThan\", \"op_LessThanOrEqual\", \"op_Modulus\",\r\n            \"op_BitwiseAnd\", \"op_BitwiseOr\", \"op_ExclusiveOr\", \"op_OnesComplement\", \"op_LeftShift\", \"op_RightShift\"};\r\n        private static XLuaTemplates templateRef;\r\n\r\n        static Generator()\r\n        {\r\n#if !XLUA_GENERAL\r\n            TemplateRef template_ref = ScriptableObject.CreateInstance<TemplateRef>();\r\n\r\n            templateRef = new XLuaTemplates()\r\n            {\r\n#if GEN_CODE_MINIMIZE\r\n                LuaClassWrap = { name = template_ref.LuaClassWrapGCM.name, text = template_ref.LuaClassWrapGCM.text },\r\n#else\r\n                LuaClassWrap = { name = template_ref.LuaClassWrap.name, text = template_ref.LuaClassWrap.text },\r\n#endif\r\n                LuaDelegateBridge = { name = template_ref.LuaDelegateBridge.name, text = template_ref.LuaDelegateBridge.text },\r\n                LuaDelegateWrap = { name = template_ref.LuaDelegateWrap.name, text = template_ref.LuaDelegateWrap.text },\r\n#if GEN_CODE_MINIMIZE\r\n                LuaEnumWrap = { name = template_ref.LuaEnumWrapGCM.name, text = template_ref.LuaEnumWrapGCM.text },\r\n#else\r\n                LuaEnumWrap = { name = template_ref.LuaEnumWrap.name, text = template_ref.LuaEnumWrap.text },\r\n#endif\r\n                LuaInterfaceBridge = { name = template_ref.LuaInterfaceBridge.name, text = template_ref.LuaInterfaceBridge.text },\r\n#if GEN_CODE_MINIMIZE\r\n                LuaRegister = { name = template_ref.LuaRegisterGCM.name, text = template_ref.LuaRegisterGCM.text },\r\n#else\r\n                LuaRegister = { name = template_ref.LuaRegister.name, text = template_ref.LuaRegister.text },\r\n#endif\r\n                LuaWrapPusher = { name = template_ref.LuaWrapPusher.name, text = template_ref.LuaWrapPusher.text },\r\n                PackUnpack = { name = template_ref.PackUnpack.name, text = template_ref.PackUnpack.text },\r\n                TemplateCommon = { name = template_ref.TemplateCommon.name, text = template_ref.TemplateCommon.text },\r\n            };\r\n#endif\r\n            luaenv.AddLoader((ref string filepath) =>\r\n            {\r\n                if (filepath == \"TemplateCommon\")\r\n                {\r\n                    return Encoding.UTF8.GetBytes(templateRef.TemplateCommon.text);\r\n                }\r\n                else\r\n                {\r\n                    return null;\r\n                }\r\n            });\r\n        }\r\n\r\n        static bool IsOverride(MethodBase method)\r\n        {\r\n            var m = method as MethodInfo;\r\n            return m != null && !m.IsConstructor && m.IsVirtual && (m.GetBaseDefinition().DeclaringType != m.DeclaringType);\r\n        }\r\n\r\n        static int OverloadCosting(MethodBase mi)\r\n        {\r\n            int costing = 0;\r\n\r\n            if (!mi.IsStatic)\r\n            {\r\n                costing++;\r\n            }\r\n\r\n            foreach (var paraminfo in mi.GetParameters())\r\n            {\r\n                if ((!paraminfo.ParameterType.IsPrimitive ) && (paraminfo.IsIn || !paraminfo.IsOut))\r\n                {\r\n                    costing++;\r\n                }\r\n            }\r\n            costing = costing * 10000 + (mi.GetParameters().Length + (mi.IsStatic ? 0 : 1));\r\n            return costing;\r\n        }\r\n\r\n        static IEnumerable<Type> type_has_extension_methods = null;\r\n\r\n        static IEnumerable<MethodInfo> GetExtensionMethods(Type extendedType)\r\n        {\r\n            if (type_has_extension_methods == null)\r\n            {\r\n                var gen_types = LuaCallCSharp;\r\n\r\n                type_has_extension_methods = from type in gen_types\r\n                                             where type.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n                                                    .Any(method => isDefined(method, typeof(ExtensionAttribute)))\r\n                                             select type;\r\n            }\r\n            return from type in type_has_extension_methods\r\n                   where type.IsSealed && !type.IsGenericType && !type.IsNested\r\n                        from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n                        where isSupportedExtensionMethod(method, extendedType)\r\n                        select method;\r\n        }\r\n\r\n        static bool isSupportedExtensionMethod(MethodBase method, Type extendedType)\r\n        {\r\n            if (!isDefined(method, typeof(ExtensionAttribute)))\r\n                return false;\r\n            var methodParameters = method.GetParameters();\r\n            if (methodParameters.Length < 1)\r\n                return false;\r\n\r\n            var hasValidGenericParameter = false;\r\n            for (var i = 0; i < methodParameters.Length; i++)\r\n            {\r\n                var parameterType = methodParameters[i].ParameterType;\r\n                if (i == 0)\r\n                {\r\n                    if (parameterType.IsGenericParameter)\r\n                    {\r\n                        var parameterConstraints = parameterType.GetGenericParameterConstraints();\r\n                        if (parameterConstraints.Length == 0) return false;\r\n                        bool firstParamMatch = false;\r\n                        foreach (var parameterConstraint in parameterConstraints)\r\n                        {\r\n                            if (parameterConstraint != typeof(ValueType) && parameterConstraint.IsAssignableFrom(extendedType))\r\n                            {\r\n                                firstParamMatch = true;\r\n                            }\r\n                        }\r\n                        if (!firstParamMatch) return false;\r\n\r\n                        hasValidGenericParameter = true;\r\n                    }\r\n                    else if (parameterType != extendedType)\r\n                        return false;\r\n                }\r\n                else if (parameterType.IsGenericParameter)\r\n                {\r\n                    var parameterConstraints = parameterType.GetGenericParameterConstraints();\r\n                    if (parameterConstraints.Length == 0) return false;\r\n                    foreach (var parameterConstraint in parameterConstraints)\r\n                    {\r\n                        if (!parameterConstraint.IsClass || (parameterConstraint == typeof(ValueType)) || Generator.hasGenericParameter(parameterConstraint))\r\n                            return false;\r\n                    }\r\n                    hasValidGenericParameter = true;\r\n                }\r\n            }\r\n            return hasValidGenericParameter || !method.ContainsGenericParameters;\r\n        }\r\n\r\n        static bool IsDoNotGen(Type type, string name)\r\n        {\r\n            return DoNotGen.ContainsKey(type) && DoNotGen[type].Contains(name);\r\n        }\r\n\r\n        static void getClassInfo(Type type, LuaTable parameters)\r\n        {\r\n            parameters.Set(\"type\", type);\r\n\r\n            var constructors = new List<MethodBase>();\r\n            var constructor_def_vals = new List<int>();\r\n            if (!type.IsAbstract)\r\n            {\r\n                foreach (var con in type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase).Cast<MethodBase>()\r\n                    .Where(constructor => !isMethodInBlackList(constructor) && !isObsolete(constructor)))\r\n                {\r\n                    int def_count = 0;\r\n                    constructors.Add(con);\r\n                    constructor_def_vals.Add(def_count);\r\n\r\n                    var ps = con.GetParameters();\r\n                    for (int i = ps.Length - 1; i >= 0; i--)\r\n                    {\r\n                        if (ps[i].IsOptional ||\r\n                            (ps[i].IsDefined(typeof(ParamArrayAttribute), false) && i > 0 && ps[i - 1].IsOptional))\r\n                        {\r\n                            def_count++;\r\n                            constructors.Add(con);\r\n                            constructor_def_vals.Add(def_count);\r\n                        }\r\n                        else\r\n                        {\r\n                            break;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n            parameters.Set(\"constructors\", constructors);\r\n            parameters.Set(\"constructor_def_vals\", constructor_def_vals);\r\n\r\n            List<string> extension_methods_namespace = new List<string>();\r\n            var extension_methods = type.IsInterface ? new MethodInfo[0]:GetExtensionMethods(type).ToArray();\r\n            foreach(var extension_method in extension_methods)\r\n            {\r\n                if (extension_method.DeclaringType.Namespace != null\r\n                    && extension_method.DeclaringType.Namespace != \"System.Collections.Generic\"\r\n                    && extension_method.DeclaringType.Namespace != \"XLua\")\r\n                {\r\n                    extension_methods_namespace.Add(extension_method.DeclaringType.Namespace);\r\n                }\r\n            }\r\n            parameters.Set(\"namespaces\", extension_methods_namespace.Distinct().ToList());\r\n\r\n            List<LazyMemberInfo> lazyMemberInfos = new List<LazyMemberInfo>();\r\n\r\n            //warnning: filter all method start with \"op_\"  \"add_\" \"remove_\" may  filter some ordinary method\r\n            parameters.Set(\"methods\", type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                .Where(method => !isDefined(method, typeof (ExtensionAttribute)) || method.GetParameters()[0].ParameterType.IsInterface || method.DeclaringType != type)\r\n                .Where(method => !method.IsSpecialName \r\n                    || (\r\n                         ((method.Name == \"get_Item\" && method.GetParameters().Length == 1) || (method.Name == \"set_Item\" && method.GetParameters().Length == 2)) \r\n                         && method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string))\r\n                       )\r\n                 ) \r\n                .Concat(extension_methods)\r\n                .Where(method => !IsDoNotGen(type, method.Name))\r\n                .Where(method => !isMethodInBlackList(method) && (!method.IsGenericMethod || extension_methods.Contains(method) || isSupportedGenericMethod(method)) && !isObsolete(method))\r\n                .GroupBy(method => (method.Name + ((method.IsStatic && (!isDefined(method, typeof (ExtensionAttribute)) || method.GetParameters()[0].ParameterType.IsInterface)) ? \"_xlua_st_\" : \"\")), (k, v) =>\r\n                {\r\n                    var overloads = new List<MethodBase>();\r\n                    List<int> def_vals = new List<int>();\r\n                    bool isOverride = false;\r\n                    foreach (var overload in v.Cast<MethodBase>().OrderBy(mb => OverloadCosting(mb)))\r\n                    {\r\n                        int def_count = 0;\r\n                        overloads.Add(overload);\r\n                        def_vals.Add(def_count);\r\n\r\n                        if (!isOverride)\r\n                        {\r\n                            isOverride = IsOverride(overload);\r\n                        }\r\n\r\n                        var ps = overload.GetParameters();\r\n                        for (int i = ps.Length - 1; i >=0; i--)\r\n                        {\r\n                            if(ps[i].IsOptional ||\r\n                            (ps[i].IsDefined(typeof(ParamArrayAttribute), false) && i > 0 && ps[i - 1].IsOptional))\r\n                            {\r\n                                def_count++;\r\n                                overloads.Add(overload);\r\n                                def_vals.Add(def_count);\r\n                            }\r\n                            else\r\n                            {\r\n                                break;\r\n                            }\r\n                        }\r\n                    }\r\n\r\n                    return new {\r\n                        Name = k,\r\n                        IsStatic = overloads[0].IsStatic && (!isDefined(overloads[0], typeof(ExtensionAttribute)) || overloads[0].GetParameters()[0].ParameterType.IsInterface),\r\n                        Overloads = overloads,\r\n                        DefaultValues = def_vals\r\n                    };\r\n                }).ToList());\r\n\r\n            parameters.Set(\"getters\", type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                \r\n                .Where(prop => prop.GetIndexParameters().Length == 0 && prop.CanRead && (prop.GetGetMethod() != null)  && prop.Name != \"Item\" && !isObsolete(prop) && !isObsolete(prop.GetGetMethod()) && !isMemberInBlackList(prop) && !isMemberInBlackList(prop.GetGetMethod())).Select(prop => new { prop.Name, IsStatic = prop.GetGetMethod().IsStatic, ReadOnly = false, Type = prop.PropertyType })\r\n                .Concat(\r\n                    type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                    .Where(field => !isObsolete(field) && !isMemberInBlackList(field))\r\n                    .Select(field => new { field.Name, field.IsStatic, ReadOnly = field.IsInitOnly || field.IsLiteral, Type = field.FieldType })\r\n                ).Where(info => !IsDoNotGen(type, info.Name))/*.Where(getter => !typeof(Delegate).IsAssignableFrom(getter.Type))*/.ToList());\r\n\r\n            parameters.Set(\"setters\", type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                .Where(prop => prop.GetIndexParameters().Length == 0 && prop.CanWrite && (prop.GetSetMethod() != null) && prop.Name != \"Item\" && !isObsolete(prop) && !isObsolete(prop.GetSetMethod()) && !isMemberInBlackList(prop) && !isMemberInBlackList(prop.GetSetMethod())).Select(prop => new { prop.Name, IsStatic = prop.GetSetMethod().IsStatic, Type = prop.PropertyType, IsProperty = true })\r\n                .Concat(\r\n                    type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                    .Where(field => !isObsolete(field) && !isMemberInBlackList(field) && !field.IsInitOnly && !field.IsLiteral)\r\n                    .Select(field => new { field.Name, field.IsStatic, Type = field.FieldType, IsProperty = false })\r\n                ).Where(info => !IsDoNotGen(type, info.Name))/*.Where(setter => !typeof(Delegate).IsAssignableFrom(setter.Type))*/.ToList());\r\n\r\n            parameters.Set(\"operators\", type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                .Where(method => OpMethodNames.Contains(method.Name))\r\n                .GroupBy(method => method.Name, (k, v) => new { Name = k, Overloads = v.Cast<MethodBase>().OrderBy(mb => mb.GetParameters().Length).ToList() }).ToList());\r\n\r\n            var indexers = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(prop => prop.GetIndexParameters().Length > 0);\r\n\r\n            parameters.Set(\"indexers\", indexers.Where(prop => prop.CanRead && (prop.GetGetMethod() != null)).Select(prop => prop.GetGetMethod())\r\n                .Where(method => method.GetParameters().Length == 1 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))\r\n                .ToList());\r\n\r\n            parameters.Set(\"newindexers\", indexers.Where(prop => prop.CanWrite && (prop.GetSetMethod() != null)).Select(prop => prop.GetSetMethod())\r\n                .Where(method => method.GetParameters().Length == 2 && !method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))\r\n                .ToList());\r\n\r\n            parameters.Set(\"events\", type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly).Where(e => !isObsolete(e) && !isMemberInBlackList(e))\r\n                .Where(ev=> ev.GetAddMethod() != null || ev.GetRemoveMethod() != null)\r\n                .Where(ev => !IsDoNotGen(type, ev.Name))\r\n                .Select(ev => new { IsStatic = ev.GetAddMethod() != null? ev.GetAddMethod().IsStatic: ev.GetRemoveMethod().IsStatic, ev.Name,\r\n                    CanSet = false, CanAdd = ev.GetRemoveMethod() != null, CanRemove = ev.GetRemoveMethod() != null, Type = ev.EventHandlerType})\r\n                .ToList());\r\n            \r\n            parameters.Set(\"lazymembers\", lazyMemberInfos);\r\n            foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly)\r\n                .Where(m => IsDoNotGen(type, m.Name))\r\n                .GroupBy(m=>m.Name).Select(g => g.First())\r\n                )\r\n            {\r\n                switch(member.MemberType)\r\n                {\r\n                    case MemberTypes.Method:\r\n                        MethodBase mb = member as MethodBase;\r\n                        lazyMemberInfos.Add(new LazyMemberInfo\r\n                        {\r\n                            Index = mb.IsStatic ? \"CLS_IDX\" : \"METHOD_IDX\",\r\n                            Name = member.Name,\r\n                            MemberType = \"LazyMemberTypes.Method\",\r\n                            IsStatic = mb.IsStatic ? \"true\" : \"false\"\r\n                        });\r\n                        break;\r\n                    case MemberTypes.Event:\r\n                        EventInfo ev = member as EventInfo;\r\n                        if (ev.GetAddMethod() == null && ev.GetRemoveMethod() == null) break;\r\n                        bool eventIsStatic = ev.GetAddMethod() != null ? ev.GetAddMethod().IsStatic : ev.GetRemoveMethod().IsStatic;\r\n                        lazyMemberInfos.Add(new LazyMemberInfo {\r\n                            Index = eventIsStatic ? \"CLS_IDX\" : \"METHOD_IDX\",\r\n                            Name = member.Name,\r\n                            MemberType = \"LazyMemberTypes.Event\",\r\n                            IsStatic = eventIsStatic ? \"true\" : \"false\"\r\n                        });\r\n                        break;\r\n                    case MemberTypes.Field:\r\n                        FieldInfo field = member as FieldInfo;\r\n                        lazyMemberInfos.Add(new LazyMemberInfo\r\n                        {\r\n                            Index = field.IsStatic ? \"CLS_GETTER_IDX\" : \"GETTER_IDX\",\r\n                            Name = member.Name,\r\n                            MemberType = \"LazyMemberTypes.FieldGet\",\r\n                            IsStatic = field.IsStatic ? \"true\" : \"false\"\r\n                        });\r\n                        lazyMemberInfos.Add(new LazyMemberInfo\r\n                        {\r\n                            Index = field.IsStatic ? \"CLS_SETTER_IDX\" : \"SETTER_IDX\",\r\n                            Name = member.Name,\r\n                            MemberType = \"LazyMemberTypes.FieldSet\",\r\n                            IsStatic = field.IsStatic ? \"true\" : \"false\"\r\n                        });\r\n                        break;\r\n                    case MemberTypes.Property:\r\n                        PropertyInfo prop = member as PropertyInfo;\r\n                        if (prop.Name != \"Item\" || prop.GetIndexParameters().Length == 0)\r\n                        {\r\n                            if (prop.CanRead && prop.GetGetMethod() != null)\r\n                            {\r\n                                var isStatic = prop.GetGetMethod().IsStatic;\r\n                                lazyMemberInfos.Add(new LazyMemberInfo\r\n                                {\r\n                                    Index = isStatic ? \"CLS_GETTER_IDX\" : \"GETTER_IDX\",\r\n                                    Name = member.Name,\r\n                                    MemberType = \"LazyMemberTypes.PropertyGet\",\r\n                                    IsStatic = isStatic ? \"true\" : \"false\"\r\n                                });\r\n                            }\r\n                            if (prop.CanWrite && prop.GetSetMethod() != null)\r\n                            {\r\n                                var isStatic = prop.GetSetMethod().IsStatic;\r\n                                lazyMemberInfos.Add(new LazyMemberInfo\r\n                                {\r\n                                    Index = isStatic ? \"CLS_SETTER_IDX\" : \"SETTER_IDX\",\r\n                                    Name = member.Name,\r\n                                    MemberType = \"LazyMemberTypes.PropertySet\",\r\n                                    IsStatic = isStatic ? \"true\" : \"false\"\r\n                                });\r\n                            }\r\n                        }\r\n                        break;\r\n                }\r\n            }\r\n        }\r\n\r\n        class LazyMemberInfo\r\n        {\r\n            public string Index;\r\n            public string Name;\r\n            public string MemberType;\r\n            public string IsStatic;\r\n        }\r\n\r\n        static void getInterfaceInfo(Type type, LuaTable parameters)\r\n        {\r\n            parameters.Set(\"type\", type);\r\n\r\n            var itfs = new Type[] { type }.Concat(type.GetInterfaces());\r\n            parameters.Set(\"methods\", itfs.SelectMany(i => i.GetMethods())\r\n                .Where(method => !method.IsSpecialName && !method.IsGenericMethod && !method.Name.StartsWith(\"op_\") && !method.Name.StartsWith(\"add_\") && !method.Name.StartsWith(\"remove_\")) //GenericMethod can not be invoke becuase not static info available!\r\n                    .ToList());\r\n\r\n            parameters.Set(\"propertys\", itfs.SelectMany(i => i.GetProperties())\r\n                .Where(prop => (prop.CanRead || prop.CanWrite) && prop.Name != \"Item\")\r\n                    .ToList());\r\n\r\n            parameters.Set(\"events\", itfs.SelectMany(i => i.GetEvents()).ToList());\r\n\r\n            parameters.Set(\"indexers\", itfs.SelectMany(i => i.GetProperties())\r\n                .Where(prop => (prop.CanRead || prop.CanWrite) && prop.Name == \"Item\")\r\n                    .ToList());\r\n        }\r\n\r\n        static bool isObsolete(MemberInfo mb)\r\n        {\r\n            if (mb == null) return false;\r\n            ObsoleteAttribute oa = GetCustomAttribute(mb, typeof(ObsoleteAttribute)) as ObsoleteAttribute;\r\n#if XLUA_GENERAL && !XLUA_ALL_OBSOLETE || XLUA_JUST_EXCLUDE_ERROR\r\n            return oa != null && oa.IsError;\r\n#else\r\n            return oa != null;\r\n#endif\r\n        }\r\n\r\n        static bool isObsolete(Type type)\r\n        {\r\n            if (type == null) return false;\r\n            if (isObsolete(type as MemberInfo))\r\n            {\r\n                return true;\r\n            }\r\n            return (type.DeclaringType != null) ? isObsolete(type.DeclaringType) : false;\r\n        }\r\n\r\n        static bool isMemberInBlackList(MemberInfo mb)\r\n        {\r\n            if (isDefined(mb, typeof(BlackListAttribute))) return true;\r\n            if (mb is FieldInfo && (mb as FieldInfo).FieldType.IsPointer) return true;\r\n            if (mb is PropertyInfo && (mb as PropertyInfo).PropertyType.IsPointer) return true;\r\n\r\n            foreach(var filter in memberFilters)\r\n            {\r\n                if (filter(mb))\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n\r\n            foreach (var exclude in BlackList)\r\n            {\r\n                if (mb.DeclaringType.ToString() == exclude[0] && mb.Name == exclude[1])\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n\r\n            return false;\r\n        }\r\n\r\n        static bool isMethodInBlackList(MethodBase mb)\r\n        {\r\n            if (isDefined(mb, typeof(BlackListAttribute))) return true;\r\n\r\n            //指针目前不支持，先过滤\r\n            if (mb.GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer)) return true;\r\n            if (mb is MethodInfo && (mb as MethodInfo).ReturnType.IsPointer) return true;\r\n\r\n            foreach (var filter in memberFilters)\r\n            {\r\n                if (filter(mb))\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n\r\n            foreach (var exclude in BlackList)\r\n            {\r\n                if (mb.DeclaringType.ToString() == exclude[0] && mb.Name == exclude[1])\r\n                {\r\n                    var parameters = mb.GetParameters();\r\n                    if (parameters.Length != exclude.Count - 2)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    bool paramsMatch = true;\r\n\r\n                    for (int i = 0; i < parameters.Length; i++)\r\n                    {\r\n                        if (parameters[i].ParameterType.ToString() != exclude[i + 2])\r\n                        {\r\n                            paramsMatch = false;\r\n                            break;\r\n                        }\r\n                    }\r\n                    if (paramsMatch) return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\r\n        static Dictionary<string, LuaFunction> templateCache = new Dictionary<string, LuaFunction>();\r\n        static void GenOne(Type type, Action<Type, LuaTable> type_info_getter, XLuaTemplate templateAsset, StreamWriter textWriter)\r\n        {\r\n            if (isObsolete(type)) return;\r\n            LuaFunction template;\r\n            if (!templateCache.TryGetValue(templateAsset.name, out template))\r\n            {\r\n                template = XLua.TemplateEngine.LuaTemplate.Compile(luaenv, templateAsset.text);\r\n                templateCache[templateAsset.name] = template;\r\n            }\r\n\r\n            LuaTable type_info = luaenv.NewTable();\r\n            LuaTable meta = luaenv.NewTable();\r\n            meta.Set(\"__index\", luaenv.Global);\r\n            type_info.SetMetaTable(meta);\r\n            meta.Dispose();\r\n\r\n            type_info_getter(type, type_info);\r\n\r\n            try\r\n            {\r\n                string genCode = XLua.TemplateEngine.LuaTemplate.Execute(template, type_info);\r\n                //string filePath = save_path + type.ToString().Replace(\"+\", \"\").Replace(\".\", \"\").Replace(\"`\", \"\").Replace(\"&\", \"\").Replace(\"[\", \"\").Replace(\"]\", \"\").Replace(\",\", \"\") + file_suffix + \".cs\";\r\n                textWriter.Write(genCode);\r\n                textWriter.Flush();\r\n            }\r\n            catch (Exception e)\r\n            {\r\n#if XLUA_GENERAL\r\n                System.Console.WriteLine(\"Error: gen wrap file fail! err=\" + e.Message + \", stack=\" + e.StackTrace);\r\n#else\r\n                Debug.LogError(\"gen wrap file fail! err=\" + e.Message + \", stack=\" + e.StackTrace);\r\n#endif\r\n            }\r\n            finally\r\n            {\r\n                type_info.Dispose();\r\n            }\r\n        }\r\n\r\n        static void GenEnumWrap(IEnumerable<Type> types, string save_path)\r\n        {\r\n            string filePath = save_path + \"EnumWrap.cs\";\r\n            StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n            \r\n            GenOne(null, (type, type_info) =>\r\n            {\r\n                var type2fields = luaenv.NewTable();\r\n                foreach(var _type in types)\r\n                    type2fields.Set(_type, _type.GetFields(BindingFlags.Public | BindingFlags.Static).Where(x => !isMemberInBlackList(x)).ToArray());\r\n                type_info.Set(\"type2fields\", type2fields);\r\n                type_info.Set(\"types\", types.ToList());\r\n            }, templateRef.LuaEnumWrap, textWriter);\r\n\r\n            textWriter.Close();\r\n        }\r\n\r\n        static string NonmalizeName(string name)\r\n        {\r\n            return name.Replace(\"+\", \"_\").Replace(\".\", \"_\").Replace(\"`\", \"_\").Replace(\"&\", \"_\").Replace(\"[\", \"_\").Replace(\"]\", \"_\").Replace(\",\", \"_\");\r\n        }\r\n\r\n        static void GenInterfaceBridge(IEnumerable<Type> types, string save_path)\r\n        {\r\n            foreach (var wrap_type in types)\r\n            {\r\n                if (!wrap_type.IsInterface) continue;\r\n\r\n                string filePath = save_path + NonmalizeName(wrap_type.ToString()) + \"Bridge.cs\";\r\n                StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n                GenOne(wrap_type, (type, type_info) =>\r\n                {\r\n                    getInterfaceInfo(type, type_info);\r\n                }, templateRef.LuaInterfaceBridge, textWriter);\r\n                textWriter.Close();\r\n            }\r\n        }\r\n\r\n        class ParameterInfoSimulation\r\n        {\r\n            public string Name;\r\n            public bool IsOut;\r\n            public bool IsIn;\r\n            public Type ParameterType;\r\n            public bool IsParamArray;\r\n        }\r\n\r\n        class MethodInfoSimulation\r\n        {\r\n            public Type ReturnType;\r\n            public ParameterInfoSimulation[] ParameterInfos;\r\n\r\n            public int HashCode;\r\n\r\n            public ParameterInfoSimulation[]  GetParameters()\r\n            {\r\n                return ParameterInfos;\r\n            }\r\n\r\n            public Type DeclaringType = null;\r\n            public string DeclaringTypeName = null;\r\n        }\r\n\r\n        static MethodInfoSimulation makeMethodInfoSimulation(MethodInfo method)\r\n        {\r\n            int hashCode = method.ReturnType.GetHashCode();\r\n\r\n            List<ParameterInfoSimulation> paramsExpect = new List<ParameterInfoSimulation>();\r\n\r\n            foreach (var param in method.GetParameters())\r\n            {\r\n                if (param.IsOut)\r\n                {\r\n                    hashCode++;\r\n                }\r\n                hashCode += param.ParameterType.GetHashCode();\r\n                paramsExpect.Add(new ParameterInfoSimulation()\r\n                {\r\n                    Name = param.Name,\r\n                    IsOut = param.IsOut,\r\n                    IsIn = param.IsIn,\r\n                    ParameterType = param.ParameterType,\r\n                    IsParamArray = param.IsDefined(typeof(System.ParamArrayAttribute), false)\r\n                });\r\n            }\r\n\r\n            return new MethodInfoSimulation()\r\n            {\r\n                ReturnType = method.ReturnType,\r\n                HashCode = hashCode,\r\n                ParameterInfos = paramsExpect.ToArray(),\r\n                DeclaringType = method.DeclaringType\r\n            };\r\n        }\r\n\r\n        static bool isNotPublic(Type type)\r\n        {\r\n            if (type.IsByRef || type.IsArray)\r\n            {\r\n                return isNotPublic(type.GetElementType());\r\n            }\r\n            else\r\n            {\r\n                if ((!type.IsNested && !type.IsPublic) || (type.IsNested && !type.IsNestedPublic))\r\n                {\r\n                    return true;\r\n                }\r\n                if (type.IsGenericType)\r\n                {\r\n                    foreach (var ga in type.GetGenericArguments())\r\n                    {\r\n                        if (isNotPublic(ga))\r\n                        {\r\n                            return true;\r\n                        }\r\n                    }\r\n                }\r\n                if (type.IsNested)\r\n                {\r\n                    var parent = type.DeclaringType;\r\n                    while (parent != null)\r\n                    {\r\n                        if ((!parent.IsNested && !parent.IsPublic) || (parent.IsNested && !parent.IsNestedPublic))\r\n                        {\r\n                            return true;\r\n                        }\r\n                        if (parent.IsNested)\r\n                        {\r\n                            parent = parent.DeclaringType;\r\n                        }\r\n                        else\r\n                        {\r\n                            break;\r\n                        }\r\n                    }\r\n                }\r\n                return false;\r\n            }\r\n        }\r\n\r\n        static bool hasGenericParameter(Type type)\r\n        {\r\n            if (type.IsByRef || type.IsArray)\r\n            {\r\n                return hasGenericParameter(type.GetElementType());\r\n            }\r\n            if (type.IsGenericType)\r\n            {\r\n                foreach (var typeArg in type.GetGenericArguments())\r\n                {\r\n                    if (hasGenericParameter(typeArg))\r\n                    {\r\n                        return true;\r\n                    }\r\n                }\r\n                return false;\r\n            }\r\n            return type.IsGenericParameter;\r\n        }\r\n\r\n        static MethodInfoSimulation makeHotfixMethodInfoSimulation(MethodBase hotfixMethod, HotfixFlag hotfixType)\r\n        {\r\n            bool ignoreValueType = hotfixType.HasFlag(HotfixFlag.ValueTypeBoxing);\r\n            //ignoreValueType = true;\r\n\r\n            Type retTypeExpect = (hotfixMethod.IsConstructor ? typeof(void) : (hotfixMethod as MethodInfo).ReturnType);\r\n            int hashCode = retTypeExpect.GetHashCode();\r\n            List<ParameterInfoSimulation> paramsExpect = new List<ParameterInfoSimulation>();\r\n            if (!hotfixMethod.IsStatic) // add self\r\n            {\r\n                paramsExpect.Add(new ParameterInfoSimulation()\r\n                {\r\n                    Name = \"self\",\r\n                    IsOut = false,\r\n                    IsIn = true,\r\n                    ParameterType = (hotfixMethod.DeclaringType.IsValueType && !ignoreValueType) ? hotfixMethod.DeclaringType : typeof(object),\r\n                    IsParamArray = false\r\n                });\r\n                hashCode += paramsExpect[0].ParameterType.GetHashCode();\r\n            }\r\n\r\n            foreach (var param in hotfixMethod.GetParameters())\r\n            {\r\n                var paramExpect = new ParameterInfoSimulation()\r\n                {\r\n                    Name = param.Name,\r\n                    IsOut = param.IsOut,\r\n                    IsIn = param.IsIn,\r\n                    ParameterType = (param.ParameterType.IsByRef || (param.ParameterType.IsValueType && !ignoreValueType)\r\n                      || param.IsDefined(typeof(System.ParamArrayAttribute), false)) ? param.ParameterType : typeof(object),\r\n                    IsParamArray = param.IsDefined(typeof(System.ParamArrayAttribute), false)\r\n                };\r\n                if (param.IsOut)\r\n                {\r\n                    hashCode++;\r\n                }\r\n                hashCode += paramExpect.ParameterType.GetHashCode();\r\n                paramsExpect.Add(paramExpect);\r\n            }\r\n\r\n            return new MethodInfoSimulation()\r\n            {\r\n                HashCode = hashCode,\r\n                ReturnType = retTypeExpect,\r\n                ParameterInfos = paramsExpect.ToArray()\r\n            };\r\n        }\r\n\r\n        class MethodInfoSimulationComparer : IEqualityComparer<MethodInfoSimulation>\r\n        {\r\n            public bool Equals(MethodInfoSimulation x, MethodInfoSimulation y)\r\n            {\r\n                if (object.ReferenceEquals(x, y)) return true;\r\n                if (x == null || y == null)\r\n                {\r\n                    return false;\r\n                }\r\n                if (x.ReturnType != y.ReturnType)\r\n                {\r\n                    return false;\r\n                }\r\n                var xParams = x.GetParameters();\r\n                var yParams = y.GetParameters();\r\n                if (xParams.Length != yParams.Length)\r\n                {\r\n                    return false;\r\n                }\r\n\r\n                for (int i = 0; i < xParams.Length; i++)\r\n                {\r\n                    if (xParams[i].ParameterType != yParams[i].ParameterType || xParams[i].IsOut != yParams[i].IsOut)\r\n                    {\r\n                        return false;\r\n                    }\r\n                }\r\n\r\n                var lastPos = xParams.Length - 1;\r\n                return lastPos < 0 || xParams[lastPos].IsParamArray == yParams[lastPos].IsParamArray;\r\n            }\r\n            public int GetHashCode(MethodInfoSimulation obj)\r\n            {\r\n                return obj.HashCode;\r\n            }\r\n        }\r\n\r\n        static bool injectByGeneric(MethodBase method, HotfixFlag hotfixType)\r\n        {\r\n            bool ignoreValueType = hotfixType.HasFlag(HotfixFlag.ValueTypeBoxing);\r\n            //ignoreValueType = true;\r\n\r\n            if (!method.IsConstructor && (isNotPublic((method as MethodInfo).ReturnType) || hasGenericParameter((method as MethodInfo).ReturnType))) return true;\r\n\r\n            if (!method.IsStatic \r\n                &&(((method.DeclaringType.IsValueType && !ignoreValueType) && isNotPublic(method.DeclaringType)) || hasGenericParameter(method.DeclaringType)))\r\n            {\r\n                return true;\r\n            }\r\n\r\n            foreach (var param in method.GetParameters())\r\n            {\r\n                if ((((param.ParameterType.IsValueType && !ignoreValueType) \r\n                    || param.ParameterType.IsByRef || param.IsDefined(typeof(System.ParamArrayAttribute), false)) && isNotPublic(param.ParameterType)) \r\n                    || hasGenericParameter(param.ParameterType))\r\n                    return true;\r\n            }\r\n            return false;\r\n        }\r\n\r\n        static bool HasFlag(this HotfixFlag toCheck, HotfixFlag flag)\r\n        {\r\n            return (toCheck != HotfixFlag.Stateless) && ((toCheck & flag) == flag);\r\n        }\r\n\r\n        static void GenDelegateBridge(IEnumerable<Type> types, string save_path, IEnumerable<Type> hotfix_check_types)\r\n        {\r\n            string filePath = save_path + \"DelegatesGensBridge.cs\";\r\n            StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n            types = types.Where(type => !type.GetMethod(\"Invoke\").GetParameters().Any(paramInfo => paramInfo.ParameterType.IsGenericParameter));\r\n            var hotfxDelegates = new List<MethodInfoSimulation>();\r\n            var comparer = new MethodInfoSimulationComparer();\r\n\r\n            var bindingAttrOfMethod = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic;\r\n            var bindingAttrOfConstructor = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic;\r\n            foreach (var type in (from type in hotfix_check_types where isDefined(type, typeof(HotfixAttribute)) select type))\r\n            {\r\n                var ca = GetCustomAttribute(type, typeof(HotfixAttribute));\r\n#if XLUA_GENERAL\r\n                var hotfixType = (HotfixFlag)Convert.ToInt32(ca.GetType().GetProperty(\"Flag\").GetValue(ca, null));\r\n#else\r\n                var hotfixType = (ca as HotfixAttribute).Flag;\r\n#endif\r\n                HotfixCfg[type] = hotfixType;\r\n            }\r\n            foreach (var kv in HotfixCfg)\r\n            {\r\n                if (kv.Key.Name.Contains(\"<\") || kv.Value.HasFlag(HotfixFlag.Inline))\r\n                {\r\n                    continue;\r\n                }\r\n                bool ignoreProperty = kv.Value.HasFlag(HotfixFlag.IgnoreProperty);\r\n                bool ignoreNotPublic = kv.Value.HasFlag(HotfixFlag.IgnoreNotPublic);\r\n                bool ignoreCompilerGenerated = kv.Value.HasFlag(HotfixFlag.IgnoreCompilerGenerated);\r\n                if (ignoreCompilerGenerated && isDefined(kv.Key, typeof(CompilerGeneratedAttribute)))\r\n                {\r\n                    continue;\r\n                }\r\n                //ignoreProperty = true;\r\n                hotfxDelegates.AddRange(kv.Key.GetMethods(bindingAttrOfMethod)\r\n                    .Where(method => method.GetMethodBody() != null)\r\n                    .Where(method => !method.Name.Contains(\"<\"))\r\n                    .Where(method => !ignoreCompilerGenerated || !isDefined(method, typeof(CompilerGeneratedAttribute)))\r\n                    .Where(method => !ignoreNotPublic || method.IsPublic)\r\n                    .Where(method => !ignoreProperty || !method.IsSpecialName || (!method.Name.StartsWith(\"get_\") && !method.Name.StartsWith(\"set_\")))\r\n                    .Where(method => !method.GetParameters().Any(pInfo => pInfo.ParameterType.IsPointer))\r\n                    .Where(method => !method.ReturnType.IsPointer)\r\n                    .Cast<MethodBase>()\r\n                    .Concat(kv.Key.GetConstructors(bindingAttrOfConstructor).Cast<MethodBase>())\r\n                    .Where(method => !injectByGeneric(method, kv.Value))\r\n                    .Select(method => makeHotfixMethodInfoSimulation(method, kv.Value)));\r\n            }\r\n            hotfxDelegates = hotfxDelegates.Distinct(comparer).ToList();\r\n            for(int i = 0; i < hotfxDelegates.Count; i++)\r\n            {\r\n                hotfxDelegates[i].DeclaringTypeName = \"__Gen_Hotfix_Delegate\" + i;\r\n            }\r\n\r\n            var delegates_groups = types.Select(delegate_type => makeMethodInfoSimulation(delegate_type.GetMethod(\"Invoke\")))\r\n                .Where(d => d.DeclaringType.FullName != null)\r\n                .Concat(hotfxDelegates)\r\n                .GroupBy(d => d, comparer).Select((group) => new { Key = group.Key, Value = group.ToList()});\r\n            GenOne(typeof(DelegateBridge), (type, type_info) =>\r\n            {\r\n                type_info.Set(\"delegates_groups\", delegates_groups.ToList());\r\n            }, templateRef.LuaDelegateBridge, textWriter);\r\n            textWriter.Close();\r\n        }\r\n\r\n        static void GenWrapPusher(IEnumerable<Type> types, string save_path)\r\n        {\r\n            string filePath = save_path + \"WrapPusher.cs\";\r\n            StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n            var emptyMap = new Dictionary<Type, Type>();\r\n            GenOne(typeof(ObjectTranslator), (type, type_info) =>\r\n            {\r\n                type_info.Set(\"purevaluetypes\", types\r\n                     .Where(t => t.IsEnum || (!t.IsPrimitive && SizeOf(t) != -1))\r\n                     .Select(t => new {\r\n                         Type = t,\r\n                         Size = SizeOf(t),\r\n                         Flag = t.IsEnum ? OptimizeFlag.Default : OptimizeCfg[t],\r\n                         FieldInfos = (t.IsEnum || OptimizeCfg[t] == OptimizeFlag.Default) ? null : getXluaTypeInfo(t, emptyMap).FieldInfos\r\n                     }).ToList());\r\n                type_info.Set(\"tableoptimzetypes\", types.Where(t => !t.IsEnum && SizeOf(t) == -1)\r\n                     .Select(t => new { Type = t, Fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) })\r\n                     .ToList());\r\n            }, templateRef.LuaWrapPusher, textWriter);\r\n            textWriter.Close();\r\n        }\r\n\r\n        static void GenWrap(IEnumerable<Type> types, string save_path)\r\n        {\r\n            types = types.Where(type=>!type.IsEnum);\r\n\r\n#if GENERIC_SHARING\r\n            types = types.GroupBy(t => t.IsGenericType ? t.GetGenericTypeDefinition() : t).Select(g => g.Key);\r\n#endif\r\n\r\n            var typeMap = types.ToDictionary(type => {\r\n                //Debug.Log(\"type:\" + type);\r\n                return type.ToString();\r\n            });\r\n\r\n            foreach (var wrap_type in types)\r\n            {\r\n                string filePath = save_path + NonmalizeName(wrap_type.ToString()) + \"Wrap.cs\";\r\n                StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n                if (wrap_type.IsEnum)\r\n                {\r\n                    GenOne(wrap_type, (type, type_info) =>\r\n                    {\r\n                        type_info.Set(\"type\", type);\r\n                        type_info.Set(\"fields\", type.GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static)\r\n                            .Where(field => !isObsolete(field))\r\n                            .ToList());\r\n                    }, templateRef.LuaEnumWrap, textWriter);\r\n                }\r\n                else if (typeof(Delegate).IsAssignableFrom(wrap_type))\r\n                {\r\n\r\n\r\n                    GenOne(wrap_type, (type, type_info) =>\r\n                    {\r\n                        type_info.Set(\"type\", type);\r\n                        type_info.Set(\"delegate\", type.GetMethod(\"Invoke\"));\r\n                    }, templateRef.LuaDelegateWrap, textWriter);\r\n\r\n                }\r\n                else\r\n                {\r\n                    GenOne(wrap_type, (type, type_info) =>\r\n                    {\r\n                        if (type.BaseType != null && typeMap.ContainsKey(type.BaseType.ToString()))\r\n                        {\r\n                            type_info.Set(\"base\", type.BaseType);\r\n                        }\r\n                        getClassInfo(type, type_info);\r\n                    }, templateRef.LuaClassWrap, textWriter);\r\n                }\r\n                textWriter.Close();\r\n            }\r\n        }\r\n\r\n#if !XLUA_GENERAL\r\n        static void clear(string path)\r\n        {\r\n            if (Directory.Exists(path))\r\n            {\r\n                Directory.Delete(path, true);\r\n                AssetDatabase.DeleteAsset(path.Substring(path.IndexOf(\"Assets\") + \"Assets\".Length));\r\n\r\n                AssetDatabase.Refresh();\r\n            }\r\n        }\r\n#endif\r\n\r\n        class DelegateByMethodDecComparer : IEqualityComparer<Type>\r\n        {\r\n            public bool Equals(Type x, Type y)\r\n            {\r\n                return XLua.Utils.IsParamsMatch(x.GetMethod(\"Invoke\"), y.GetMethod(\"Invoke\"));\r\n            }\r\n            public int GetHashCode(Type obj)\r\n            {\r\n                int hc = 0;\r\n                var method = obj.GetMethod(\"Invoke\");\r\n                hc += method.ReturnType.GetHashCode();\r\n                foreach (var pi in method.GetParameters())\r\n                {\r\n                    hc += pi.ParameterType.GetHashCode();\r\n                }\r\n                return hc;\r\n            }\r\n        }\r\n\r\n        public static void GenDelegateBridges(IEnumerable<Type> hotfix_check_types)\r\n        {\r\n            var delegate_types = CSharpCallLua.Where(type => typeof(Delegate).IsAssignableFrom(type));\r\n\r\n            GenDelegateBridge(delegate_types, GeneratorConfig.common_path, hotfix_check_types);\r\n        }\r\n\r\n        public static void GenEnumWraps()\r\n        {\r\n            var enum_types = LuaCallCSharp.Where(type => type.IsEnum).Distinct();\r\n\r\n            GenEnumWrap(enum_types, GeneratorConfig.common_path);\r\n        }\r\n\r\n        static MethodInfo makeGenericMethodIfNeeded(MethodInfo method)\r\n        {\r\n            if (!method.ContainsGenericParameters) return method;\r\n\r\n            var genericArguments = method.GetGenericArguments();\r\n            var constraintedArgumentTypes = new Type[genericArguments.Length];\r\n            for (var i = 0; i < genericArguments.Length; i++)\r\n            {\r\n                var argumentType = genericArguments[i];\r\n                var parameterConstraints = argumentType.GetGenericParameterConstraints();\r\n                Type parameterConstraint = parameterConstraints[0];\r\n                foreach(var type in argumentType.GetGenericParameterConstraints())\r\n                {\r\n                    if (parameterConstraint.IsAssignableFrom(type))\r\n                    {\r\n                        parameterConstraint = type;\r\n                    }\r\n                }\r\n                \r\n                constraintedArgumentTypes[i] = parameterConstraint;\r\n            }\r\n            return method.MakeGenericMethod(constraintedArgumentTypes);\r\n        }\r\n\r\n        public static void GenLuaRegister(bool minimum = false)\r\n        {\r\n            var wraps = minimum ? new List<Type>() : LuaCallCSharp;\r\n\r\n            var itf_bridges = CSharpCallLua.Where(t => t.IsInterface);\r\n\r\n            string filePath = GeneratorConfig.common_path + \"XLuaGenAutoRegister.cs\";\r\n            StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n\r\n            var lookup = LuaCallCSharp.Distinct().ToDictionary(t => t);\r\n\r\n            var extension_methods_from_lcs = (from t in LuaCallCSharp\r\n                                    where isDefined(t, typeof(ExtensionAttribute))\r\n                                    from method in t.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n                                    where isDefined(method, typeof(ExtensionAttribute)) && !isObsolete(method)\r\n                                    where !method.ContainsGenericParameters || isSupportedGenericMethod(method)\r\n                                    select makeGenericMethodIfNeeded(method))\r\n                                    .Where(method => !lookup.ContainsKey(method.GetParameters()[0].ParameterType));\r\n\r\n            var extension_methods = (from t in ReflectionUse\r\n                                     where isDefined(t, typeof(ExtensionAttribute))\r\n                                     from method in t.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n                                     where isDefined(method, typeof(ExtensionAttribute)) && !isObsolete(method)\r\n                                     where !method.ContainsGenericParameters || isSupportedGenericMethod(method)\r\n                                     select makeGenericMethodIfNeeded(method)).Concat(extension_methods_from_lcs);\r\n            GenOne(typeof(DelegateBridgeBase), (type, type_info) =>\r\n            {\r\n#if GENERIC_SHARING\r\n                type_info.Set(\"wraps\", wraps.Where(t=>!t.IsGenericType).ToList());\r\n                var genericTypeGroups = wraps.Where(t => t.IsGenericType).GroupBy(t => t.GetGenericTypeDefinition());\r\n\r\n                var typeToArgsList = luaenv.NewTable();\r\n                foreach (var genericTypeGroup in genericTypeGroups)\r\n                {\r\n                    var argsList = luaenv.NewTable();\r\n                    int i = 1;\r\n                    foreach(var genericType in genericTypeGroup)\r\n                    {\r\n                        argsList.Set(i++, genericType.GetGenericArguments());\r\n                    }\r\n                    typeToArgsList.Set(genericTypeGroup.Key, argsList);\r\n                    argsList.Dispose();\r\n                }\r\n\r\n                type_info.Set(\"generic_wraps\", typeToArgsList);\r\n                typeToArgsList.Dispose();\r\n#else\r\n                type_info.Set(\"wraps\", wraps.ToList());\r\n#endif\r\n\r\n                type_info.Set(\"itf_bridges\", itf_bridges.ToList());\r\n                type_info.Set(\"extension_methods\", extension_methods.ToList());\r\n            }, templateRef.LuaRegister, textWriter);\r\n            textWriter.Close();\r\n        }\r\n\r\n        public static void AllSubStruct(Type type, Action<Type> cb)\r\n        {\r\n            if (!type.IsPrimitive && type != typeof(decimal))\r\n            {\r\n                cb(type);\r\n                foreach(var fieldInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))\r\n                {\r\n                    AllSubStruct(fieldInfo.FieldType, cb);\r\n                }\r\n\r\n                foreach(var propInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))\r\n                {\r\n                    if ((AdditionalProperties.ContainsKey(type) && AdditionalProperties[type].Contains(propInfo.Name))\r\n                        || isDefined(propInfo, typeof(AdditionalPropertiesAttribute)))\r\n                    {\r\n                        AllSubStruct(propInfo.PropertyType, cb);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        class XluaFieldInfo\r\n        {\r\n            public string Name;\r\n            public Type Type;\r\n            public bool IsField;\r\n            public int Size;\r\n        }\r\n\r\n        class XluaTypeInfo\r\n        {\r\n            public Type Type;\r\n            public List<XluaFieldInfo> FieldInfos;\r\n            public List<List<XluaFieldInfo>> FieldGroup;\r\n            public bool IsRoot;\r\n        }\r\n\r\n        static XluaTypeInfo getXluaTypeInfo(Type t, Dictionary<Type, Type> set)\r\n        {\r\n            var fs = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)\r\n                        .Select(fi => new XluaFieldInfo { Name = fi.Name, Type = fi.FieldType, IsField = true, Size = SizeOf(fi.FieldType) })\r\n                        .Concat(t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)\r\n                        .Where(prop => {\r\n                            return (AdditionalProperties.ContainsKey(t) && AdditionalProperties[t].Contains(prop.Name))\r\n                                || isDefined(prop, typeof(AdditionalPropertiesAttribute));\r\n                        })\r\n                        .Select(prop => new XluaFieldInfo { Name = prop.Name, Type = prop.PropertyType, IsField = false, Size = SizeOf(prop.PropertyType) }));\r\n            int float_field_count = 0;\r\n            bool only_float = true;\r\n            foreach (var f in fs)\r\n            {\r\n                if (f.Type == typeof(float))\r\n                {\r\n                    float_field_count++;\r\n                }\r\n                else\r\n                {\r\n                    only_float = false;\r\n                    break;\r\n                }\r\n            }\r\n            List<List<XluaFieldInfo>> grouped_field = null;\r\n            if (only_float && float_field_count > 1)\r\n            {\r\n                grouped_field = new List<List<XluaFieldInfo>>();\r\n                List<XluaFieldInfo> group = null;\r\n                foreach (var f in fs)\r\n                {\r\n                    if (group == null) group = new List<XluaFieldInfo>();\r\n                    group.Add(f);\r\n                    if (group.Count >= 6)\r\n                    {\r\n                        grouped_field.Add(group);\r\n                        group = null;\r\n                    }\r\n                }\r\n                if (group != null) grouped_field.Add(group);\r\n            }\r\n            return new XluaTypeInfo { Type = t, FieldInfos = fs.ToList(), FieldGroup = grouped_field, IsRoot = set.ContainsKey(t) };\r\n        }\r\n\r\n        public static void GenPackUnpack(IEnumerable<Type> types, string save_path)\r\n        {\r\n            var set = types.ToDictionary(type => type);\r\n            List<Type> all_types = new List<Type>();\r\n\r\n            foreach(var type in types)\r\n            {\r\n                AllSubStruct(type, (t) =>\r\n                {\r\n                    all_types.Add(t);\r\n                });\r\n            }\r\n\r\n            string filePath = save_path + \"PackUnpack.cs\";\r\n            StreamWriter textWriter = new StreamWriter(filePath, false, Encoding.UTF8);\r\n            GenOne(typeof(CopyByValue), (type, type_info) =>\r\n            {\r\n                type_info.Set(\"type_infos\", all_types.Distinct().Select(t => getXluaTypeInfo(t, set)).ToList());\r\n            }, templateRef.PackUnpack, textWriter);\r\n            textWriter.Close();\r\n        }\r\n\r\n        //lua中要使用到C#库的配置，比如C#标准库，或者Unity API，第三方库等。\r\n        public static List<Type> LuaCallCSharp = null;\r\n\r\n        //C#静态调用Lua的配置（包括事件的原型），仅可以配delegate，interface\r\n        public static List<Type> CSharpCallLua = null;\r\n\r\n        //黑名单\r\n        public static List<List<string>> BlackList = null;\r\n\r\n        public static List<Type> GCOptimizeList = null;\r\n\r\n        public static Dictionary<Type, List<string>> AdditionalProperties = null;\r\n\r\n        public static List<Type> ReflectionUse = null;\r\n\r\n        public static Dictionary<Type, HotfixFlag> HotfixCfg = null;\r\n\r\n        public static Dictionary<Type, OptimizeFlag> OptimizeCfg = null;\r\n\r\n        public static Dictionary<Type, HashSet<string>> DoNotGen = null;\r\n\r\n        public static List<string> assemblyList = null;\r\n\r\n        public static List<Func<MemberInfo, bool>> memberFilters = null;\r\n\r\n        static void AddToList(List<Type> list, Func<object> get, object attr)\r\n        {\r\n            object obj = get();\r\n            if (obj is Type)\r\n            {\r\n                list.Add(obj as Type);\r\n            }\r\n            else if (obj is IEnumerable<Type>)\r\n            {\r\n                list.AddRange(obj as IEnumerable<Type>);\r\n            }\r\n            else\r\n            {\r\n                throw new InvalidOperationException(\"Only field/property with the type IEnumerable<Type> can be marked \" + attr.GetType().Name);\r\n            }\r\n#if XLUA_GENERAL\r\n            if (attr != null && attr.GetType().ToString() == typeof(GCOptimizeAttribute).ToString())\r\n            {\r\n                var flag = (OptimizeFlag)Convert.ToInt32(attr.GetType().GetProperty(\"Flag\").GetValue(attr, null));\r\n#else\r\n            if (attr is GCOptimizeAttribute)\r\n            {\r\n                var flag = (attr as GCOptimizeAttribute).Flag;\r\n#endif\r\n                if (obj is Type)\r\n                {\r\n                    OptimizeCfg.Add(obj as Type, flag);\r\n                }\r\n                else if (obj is IEnumerable<Type>)\r\n                {\r\n                    foreach(var type in (obj as IEnumerable<Type>))\r\n                    {\r\n                        OptimizeCfg.Add(type, flag);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        static bool isDefined(MemberInfo test, Type type)\r\n        {\r\n#if XLUA_GENERAL\r\n            return test.GetCustomAttributes(false).Any(ca => ca.GetType().ToString() == type.ToString());\r\n#else\r\n            return test.IsDefined(type, false);\r\n#endif\r\n        }\r\n\r\n        static object GetCustomAttribute(MemberInfo test, Type type)\r\n        {\r\n#if XLUA_GENERAL\r\n            return test.GetCustomAttributes(false).FirstOrDefault(ca => ca.GetType().ToString() == type.ToString());\r\n#else\r\n            return test.GetCustomAttributes(type, false).FirstOrDefault();\r\n#endif\r\n        }\r\n\r\n        static void MergeCfg(MemberInfo test, Type cfg_type, Func<object> get_cfg)\r\n        {\r\n            if (isDefined(test, typeof(LuaCallCSharpAttribute)))\r\n            {\r\n                object ccla = GetCustomAttribute(test, typeof(LuaCallCSharpAttribute));\r\n                AddToList(LuaCallCSharp, get_cfg, ccla);\r\n#if !XLUA_GENERAL\r\n#pragma warning disable 618\r\n                if (ccla != null && (((ccla as LuaCallCSharpAttribute).Flag & GenFlag.GCOptimize) != 0))\r\n#pragma warning restore 618\r\n                {\r\n                    AddToList(GCOptimizeList, get_cfg, ccla);\r\n                }\r\n#endif\r\n            }\r\n            if (isDefined(test, typeof(CSharpCallLuaAttribute)))\r\n            {\r\n                AddToList(CSharpCallLua, get_cfg, GetCustomAttribute(test, typeof(CSharpCallLuaAttribute)));\r\n            }\r\n            if (isDefined(test, typeof(GCOptimizeAttribute)))\r\n            {\r\n                AddToList(GCOptimizeList, get_cfg, GetCustomAttribute(test, typeof(GCOptimizeAttribute)));\r\n            }\r\n            if (isDefined(test, typeof(ReflectionUseAttribute)))\r\n            {\r\n                AddToList(ReflectionUse, get_cfg, GetCustomAttribute(test, typeof(ReflectionUseAttribute)));\r\n            }\r\n            if (isDefined(test, typeof(HotfixAttribute)))\r\n            {\r\n                object cfg = get_cfg();\r\n                if (cfg is IEnumerable<Type>)\r\n                {\r\n                    var ca = GetCustomAttribute(test, typeof(HotfixAttribute));\r\n#if XLUA_GENERAL\r\n                    var hotfixType = (HotfixFlag)Convert.ToInt32(ca.GetType().GetProperty(\"Flag\").GetValue(ca, null));\r\n#else\r\n                    var hotfixType = (ca as HotfixAttribute).Flag;\r\n#endif\r\n                    foreach (var type in cfg as IEnumerable<Type>)\r\n                    {\r\n                        if (!HotfixCfg.ContainsKey(type) && !isObsolete(type) \r\n                            && !type.IsEnum && !typeof(Delegate).IsAssignableFrom(type)\r\n                            && (!type.IsGenericType || type.IsGenericTypeDefinition) \r\n                            && (type.Namespace == null || (type.Namespace != \"XLua\" && !type.Namespace.StartsWith(\"XLua.\")))\r\n                            && (assemblyList.Contains(type.Module.Assembly.GetName().Name)))\r\n                        {\r\n                            HotfixCfg.Add(type, hotfixType);\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n            if (isDefined(test, typeof(BlackListAttribute))\r\n                        && (typeof(List<List<string>>)).IsAssignableFrom(cfg_type))\r\n            {\r\n                BlackList.AddRange(get_cfg() as List<List<string>>);\r\n            }\r\n            if (isDefined(test, typeof(BlackListAttribute)) && typeof(Func<MemberInfo, bool>).IsAssignableFrom(cfg_type))\r\n            {\r\n                memberFilters.Add(get_cfg() as Func<MemberInfo, bool>);\r\n            }\r\n\r\n            if (isDefined(test, typeof(AdditionalPropertiesAttribute))\r\n                        && (typeof(Dictionary<Type, List<string>>)).IsAssignableFrom(cfg_type))\r\n            {\r\n                var cfg = get_cfg() as Dictionary<Type, List<string>>;\r\n                foreach (var kv in cfg)\r\n                {\r\n                    if (!AdditionalProperties.ContainsKey(kv.Key))\r\n                    {\r\n                        AdditionalProperties.Add(kv.Key, kv.Value);\r\n                    }\r\n                }\r\n            }\r\n\r\n            if (isDefined(test, typeof(DoNotGenAttribute))\r\n                        && (typeof(Dictionary<Type, List<string>>)).IsAssignableFrom(cfg_type))\r\n            {\r\n                var cfg = get_cfg() as Dictionary<Type, List<string>>;\r\n                foreach (var kv in cfg)\r\n                {\r\n                    HashSet<string> set;\r\n                    if (!DoNotGen.TryGetValue(kv.Key, out set))\r\n                    {\r\n                        set = new HashSet<string>();\r\n                        DoNotGen.Add(kv.Key, set);\r\n                    }\r\n                    set.UnionWith(kv.Value);\r\n                }\r\n            }\r\n        }\r\n\r\n        static bool IsPublic(Type type)\r\n        {\r\n            if (type.IsPublic || type.IsNestedPublic)\r\n            {\r\n                if (type.DeclaringType != null)\r\n                {\r\n                    return IsPublic(type.DeclaringType);\r\n                }\r\n                else\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\r\n        public static void GetGenConfig(IEnumerable<Type> check_types)\r\n        {\r\n            LuaCallCSharp = new List<Type>();\r\n\r\n            CSharpCallLua = new List<Type>();\r\n\r\n            GCOptimizeList = new List<Type>();\r\n\r\n            AdditionalProperties = new Dictionary<Type, List<string>>();\r\n\r\n            ReflectionUse = new List<Type>();\r\n\r\n            BlackList = new List<List<string>>()\r\n            {\r\n            };\r\n\r\n            HotfixCfg = new Dictionary<Type, HotfixFlag>();\r\n\r\n            OptimizeCfg = new Dictionary<Type, OptimizeFlag>();\r\n\r\n            DoNotGen = new Dictionary<Type, HashSet<string>>();\r\n\r\n#if UNITY_EDITOR && HOTFIX_ENABLE\r\n            assemblyList = HotfixConfig.GetHotfixAssembly().Select(a => a.GetName().Name).ToList();\r\n#else\r\n            assemblyList = new List<string>();\r\n#endif\r\n            memberFilters = new List<Func<MemberInfo, bool>>();\r\n\r\n            foreach (var t in check_types)\r\n            {\r\n                MergeCfg(t, null, () => t);\r\n\r\n                if (!t.IsAbstract || !t.IsSealed) continue;\r\n\r\n                var fields = t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                for (int i = 0; i < fields.Length; i++)\r\n                {\r\n                    var field = fields[i];\r\n                    MergeCfg(field, field.FieldType, () => field.GetValue(null));\r\n                }\r\n\r\n                var props = t.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                for (int i = 0; i < props.Length; i++)\r\n                {\r\n                    var prop = props[i];\r\n                    MergeCfg(prop, prop.PropertyType, () => prop.GetValue(null, null));\r\n                }\r\n            }\r\n            LuaCallCSharp = LuaCallCSharp.Distinct()\r\n                .Where(type=> IsPublic(type) && !isObsolete(type) && !type.IsGenericTypeDefinition)\r\n                .Where(type => !typeof(Delegate).IsAssignableFrom(type))\r\n                .Where(type => !type.Name.Contains(\"<\"))\r\n                .ToList();\r\n            CSharpCallLua = CSharpCallLua.Distinct()\r\n                .Where(type => IsPublic(type) && !isObsolete(type) && !type.IsGenericTypeDefinition)\r\n                .Where(type => type != typeof(Delegate) && type != typeof(MulticastDelegate))\r\n                .ToList();\r\n            GCOptimizeList = GCOptimizeList.Distinct()\r\n                .Where(type => IsPublic(type) && !isObsolete(type) && !type.IsGenericTypeDefinition)\r\n                .ToList();\r\n            ReflectionUse = ReflectionUse.Distinct()\r\n                .Where(type => !isObsolete(type) && !type.IsGenericTypeDefinition)\r\n                .ToList();\r\n        }\r\n\r\n        static Dictionary<Type, int> type_size = new Dictionary<Type, int>()\r\n        {\r\n            { typeof(byte), 1 },\r\n            { typeof(sbyte), 1 },\r\n            { typeof(short), 2 },\r\n            { typeof(ushort), 2 },\r\n            { typeof(int), 4 },\r\n            { typeof(uint), 4 },\r\n            { typeof(long), 8 },\r\n            { typeof(ulong), 8 },\r\n            { typeof(float), 4 },\r\n            { typeof(double), 8 },\r\n            { typeof(decimal), 16 }\r\n        };\r\n\r\n        static int SizeOf(Type type)\r\n        {\r\n            if (type_size.ContainsKey(type))\r\n            {\r\n                return type_size[type];\r\n            }\r\n\r\n            if (!CopyByValue.IsStruct(type))\r\n            {\r\n                return -1;\r\n            }\r\n\r\n            int size = 0;\r\n            foreach(var fieldInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))\r\n            {\r\n                int t_size = SizeOf(fieldInfo.FieldType);\r\n                if (t_size == -1)\r\n                {\r\n                    size = -1;\r\n                    break;\r\n                }\r\n                size += t_size;\r\n            }\r\n            if (size != -1)\r\n            {\r\n                foreach (var propInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))\r\n                {\r\n                    if ((AdditionalProperties.ContainsKey(type) && AdditionalProperties[type].Contains(propInfo.Name)) || isDefined(propInfo, typeof(AdditionalPropertiesAttribute)))\r\n                    {\r\n                        int t_size = SizeOf(propInfo.PropertyType);\r\n                        if (t_size == -1)\r\n                        {\r\n                            size = -1;\r\n                            break;\r\n                        }\r\n                        size += t_size;\r\n                    }\r\n                }\r\n            }\r\n\r\n            if (!type_size.ContainsKey(type))\r\n            {\r\n                type_size.Add(type, size);\r\n            }\r\n\r\n            return size;\r\n        }\r\n\r\n        public static void Gen(IEnumerable<Type> wraps, IEnumerable<Type> gc_optimze_list, IEnumerable<Type> itf_bridges, string save_path)\r\n        {\r\n            templateCache.Clear();\r\n            Directory.CreateDirectory(save_path);\r\n            GenWrap(wraps, save_path);\r\n            GenWrapPusher(gc_optimze_list.Concat(wraps.Where(type=>type.IsEnum)).Distinct(), save_path);\r\n            GenPackUnpack(gc_optimze_list.Where(type => !type.IsPrimitive && SizeOf(type) != -1), save_path);\r\n            GenInterfaceBridge(itf_bridges, save_path);\r\n        }\r\n\r\n        public static void GenCodeForClass(bool minimum = false)\r\n        {\r\n            var warp_types = minimum ? new List<Type>() : LuaCallCSharp;\r\n            var itf_bridges_types = CSharpCallLua.Where(type => type.IsInterface).Distinct();\r\n\r\n            Gen(warp_types, GCOptimizeList, itf_bridges_types, GeneratorConfig.common_path);\r\n        }\r\n\r\n#if XLUA_GENERAL\r\n        static bool IsExtensionMethod(MethodInfo method)\r\n        {\r\n            return isDefined(method, typeof(ExtensionAttribute));\r\n        }\r\n\r\n        static bool IsDelegate(Type type)\r\n        {\r\n            return type.BaseType != null && type.BaseType.ToString() == \"System.MulticastDelegate\";\r\n        }\r\n\r\n        public static void GenAll(XLuaTemplates templates, IEnumerable<Type> all_types)\r\n        {\r\n            var start = DateTime.Now;\r\n            Directory.CreateDirectory(GeneratorConfig.common_path);\r\n            templateRef = templates;\r\n            GetGenConfig(all_types.Where(type => !type.IsGenericTypeDefinition));\r\n            luaenv.DoString(\"require 'TemplateCommon'\");\r\n            luaenv.Global.Set(\"IsExtensionMethod\", new Func<MethodInfo, bool>(IsExtensionMethod));\r\n            luaenv.Global.Set(\"IsDelegate\", new Func<Type, bool>(IsDelegate));\r\n            var gen_push_types_setter = luaenv.Global.Get<LuaFunction>(\"SetGenPushAndUpdateTypes\");\r\n            gen_push_types_setter.Call(GCOptimizeList.Where(t => !t.IsPrimitive && SizeOf(t) != -1).Concat(LuaCallCSharp.Where(t => t.IsEnum)).Distinct().ToList());\r\n            var xlua_classes_setter = luaenv.Global.Get<LuaFunction>(\"SetXLuaClasses\");\r\n            xlua_classes_setter.Call(XLua.Utils.GetAllTypes().Where(t => t.Namespace == \"XLua\").ToList());\r\n            GenDelegateBridges(all_types);\r\n            GenEnumWraps();\r\n            GenCodeForClass();\r\n            GenLuaRegister();\r\n            Console.WriteLine(\"finished! use \" + (DateTime.Now - start).TotalMilliseconds + \" ms\");\r\n            luaenv.Dispose();\r\n        }\r\n#endif\r\n\r\n#if !XLUA_GENERAL\r\n        static void callCustomGen()\r\n        {\r\n            foreach (var method in (from type in XLua.Utils.GetAllTypes()\r\n                               from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n                               where method.IsDefined(typeof(GenCodeMenuAttribute), false) select method))\r\n            {\r\n                method.Invoke(null, new object[] { });\r\n            }\r\n        }\r\n\r\n        [MenuItem(\"XLua/Generate Code\", false, 1)]\r\n        public static void GenAll()\r\n        {\r\n#if UNITY_2018 && (UNITY_EDITOR_WIN || UNITY_EDITOR_OSX)\r\n            if (File.Exists(\"./Tools/MonoBleedingEdge/bin/mono.exe\"))\r\n            {\r\n                GenUsingCLI();\r\n                return;\r\n            }\r\n#endif\r\n            var start = DateTime.Now;\r\n            Directory.CreateDirectory(GeneratorConfig.common_path);\r\n            GetGenConfig(XLua.Utils.GetAllTypes());\r\n            luaenv.DoString(\"require 'TemplateCommon'\");\r\n            var gen_push_types_setter = luaenv.Global.Get<LuaFunction>(\"SetGenPushAndUpdateTypes\");\r\n            gen_push_types_setter.Call(GCOptimizeList.Where(t => !t.IsPrimitive && SizeOf(t) != -1).Concat(LuaCallCSharp.Where(t => t.IsEnum)).Distinct().ToList());\r\n            var xlua_classes_setter = luaenv.Global.Get<LuaFunction>(\"SetXLuaClasses\");\r\n            xlua_classes_setter.Call(XLua.Utils.GetAllTypes().Where(t => t.Namespace == \"XLua\").ToList());\r\n            GenDelegateBridges(XLua.Utils.GetAllTypes(false));\r\n            GenEnumWraps();\r\n            GenCodeForClass();\r\n            GenLuaRegister();\r\n            callCustomGen();\r\n            Debug.Log(\"finished! use \" + (DateTime.Now - start).TotalMilliseconds + \" ms\");\r\n            AssetDatabase.Refresh();\r\n        }\r\n\r\n#if UNITY_EDITOR_OSX || UNITY_EDITOR_WIN\r\n        public static void GenUsingCLI()\r\n        {\r\n#if UNITY_EDITOR_OSX\r\n            var monoPath = \"./Tools/MonoBleedingEdge/bin/mono\";\r\n#else\r\n            var monoPath = \"./Tools/MonoBleedingEdge/bin/mono.exe\";\r\n#endif\r\n\r\n            var args = new List<string>()\r\n            {\r\n                \"./Tools/XLuaGenerate.exe\",\r\n                \"./Library/ScriptAssemblies/Assembly-CSharp.dll\",\r\n                \"./Library/ScriptAssemblies/Assembly-CSharp-Editor.dll\",\r\n                GeneratorConfig.common_path\r\n            };\r\n\r\n            var searchPaths = new List<string>();\r\n            foreach (var path in\r\n                (from asm in AppDomain.CurrentDomain.GetAssemblies() select asm.ManifestModule.FullyQualifiedName)\r\n                 .Distinct())\r\n            {\r\n                try\r\n                {\r\n                    searchPaths.Add(Path.GetDirectoryName(path));\r\n                }\r\n                catch { }\r\n            }\r\n            args.AddRange(searchPaths.Distinct());\r\n\r\n            System.Diagnostics.Process process = new System.Diagnostics.Process();\r\n            process.StartInfo.FileName = monoPath;\r\n            process.StartInfo.Arguments = \"\\\"\" + string.Join(\"\\\" \\\"\", args.ToArray()) + \"\\\"\";\r\n            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;\r\n            process.StartInfo.RedirectStandardOutput = true;\r\n            process.StartInfo.RedirectStandardError = true;\r\n            process.StartInfo.UseShellExecute = false;\r\n            process.StartInfo.CreateNoWindow = true;\r\n            process.Start();\r\n\r\n            while (!process.StandardError.EndOfStream)\r\n            {\r\n                Debug.LogError(process.StandardError.ReadLine());\r\n            }\r\n\r\n            while (!process.StandardOutput.EndOfStream)\r\n            {\r\n                Debug.Log(process.StandardOutput.ReadLine());\r\n            }\r\n\r\n            process.WaitForExit();\r\n            GetGenConfig(XLua.Utils.GetAllTypes());\r\n            callCustomGen();\r\n            AssetDatabase.Refresh();\r\n        }\r\n#endif\r\n\r\n        [MenuItem(\"XLua/Clear Generated Code\", false, 2)]\r\n        public static void ClearAll()\r\n        {\r\n            clear(GeneratorConfig.common_path);\r\n        }\r\n\r\n        public delegate IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg);\r\n\r\n        public static void CustomGen(string template_src, GetTasks get_tasks)\r\n        {\r\n            GetGenConfig(XLua.Utils.GetAllTypes());\r\n\r\n            LuaFunction template = XLua.TemplateEngine.LuaTemplate.Compile(luaenv,\r\n                template_src);\r\n            foreach (var gen_task in get_tasks(luaenv, new UserConfig() {\r\n                LuaCallCSharp = LuaCallCSharp,\r\n                CSharpCallLua = CSharpCallLua,\r\n                ReflectionUse = ReflectionUse\r\n            }))\r\n            {\r\n                LuaTable meta = luaenv.NewTable();\r\n                meta.Set(\"__index\", luaenv.Global);\r\n                gen_task.Data.SetMetaTable(meta);\r\n                meta.Dispose();\r\n\r\n                try\r\n                {\r\n                    string genCode = XLua.TemplateEngine.LuaTemplate.Execute(template, gen_task.Data);\r\n                    gen_task.Output.Write(genCode);\r\n                    gen_task.Output.Flush();\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    Debug.LogError(\"gen file fail! template=\" + template_src + \", err=\" + e.Message + \", stack=\" + e.StackTrace);\r\n                }\r\n                finally\r\n                {\r\n                    gen_task.Output.Close();\r\n                }\r\n            }\r\n        }\r\n\r\n#endif\r\n\r\n        private static bool isSupportedGenericMethod(MethodInfo method)\r\n        {\r\n\r\n            if (!method.ContainsGenericParameters)\r\n                return true;\r\n            var methodParameters = method.GetParameters();\r\n            var _hasGenericParameter = false;\r\n            for (var i = 0; i < methodParameters.Length; i++)\r\n            {\r\n                var parameterType = methodParameters[i].ParameterType;\r\n                if (!isSupportGenericParameter(parameterType, true, ref _hasGenericParameter))\r\n                    return false;\r\n            }\r\n            return _hasGenericParameter;\r\n        }\r\n        private static bool isSupportGenericParameter(Type parameterType,bool checkConstraint, ref bool _hasGenericParameter)\r\n        {\r\n\r\n            if (parameterType.IsGenericParameter)\r\n            {\r\n                if (!checkConstraint)\r\n                    return false;\r\n                var parameterConstraints = parameterType.GetGenericParameterConstraints();\r\n                if (parameterConstraints.Length == 0) return false;\r\n                foreach (var parameterConstraint in parameterConstraints)\r\n                {\r\n                    if (!parameterConstraint.IsClass || (parameterConstraint == typeof(ValueType)) || Generator.hasGenericParameter(parameterConstraint))\r\n                        return false;\r\n                }\r\n                _hasGenericParameter = true;\r\n            }\r\n            else if(parameterType.IsGenericType)\r\n            {\r\n                foreach (var argument in parameterType.GetGenericArguments())\r\n                {\r\n                    if (!isSupportGenericParameter(argument,false, ref _hasGenericParameter))\r\n                        return false;\r\n                }\r\n            }\r\n            return true;\r\n        }\r\n#if !XLUA_GENERAL\r\n        [UnityEditor.Callbacks.PostProcessBuild(1)]\r\n        public static void CheckGenerate(BuildTarget target, string pathToBuiltProject)\r\n        {\r\n            if (EditorApplication.isCompiling || Application.isPlaying)\r\n            {\r\n                return;\r\n            }\r\n            if (!DelegateBridge.Gen_Flag)\r\n            {\r\n                throw new InvalidOperationException(\"Code has not been generated, may be not work in phone!\");\r\n            }\r\n        }\r\n#endif\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Generator.cs.meta",
    "content": "fileFormatVersion: 2\nguid: e866a5f1000c29940843aece98d0c706\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Hotfix.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if HOTFIX_ENABLE\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing System.Reflection;\r\nusing System.Linq;\r\nusing System.IO;\r\nusing System.Text.RegularExpressions;\r\n\r\n#if XLUA_GENERAL\r\nusing Mono.Cecil;\r\nusing Mono.Cecil.Cil;\r\n#endif\r\n\r\n#if !XLUA_GENERAL\r\nusing UnityEngine;\r\nusing UnityEditor;\r\nusing UnityEditor.Callbacks;\r\nusing System.Diagnostics;\r\n#if UNITY_2019_1_OR_NEWER\r\nusing UnityEditor.Build;\r\nusing UnityEditor.Build.Reporting;\r\n#endif\r\n#endif\r\n\r\nnamespace XLua\r\n{\r\n    public static class HotfixConfig\r\n    {\r\n        //返回-1表示没有标签\r\n        static int getHotfixType(MemberInfo memberInfo)\r\n        {\r\n            try\r\n            {\r\n                foreach (var ca in memberInfo.GetCustomAttributes(false))\r\n                {\r\n                    var ca_type = ca.GetType();\r\n                    if (ca_type.ToString() == \"XLua.HotfixAttribute\")\r\n                    {\r\n                        return (int)(ca_type.GetProperty(\"Flag\").GetValue(ca, null));\r\n                    }\r\n                }\r\n            }\r\n            catch { }\r\n            return -1;\r\n        }\r\n\r\n        static void mergeConfig(MemberInfo test, Type cfg_type, Func<IEnumerable<Type>> get_cfg, Action<Type, int> on_cfg)\r\n        {\r\n            int hotfixType = getHotfixType(test);\r\n            if (-1 == hotfixType || !typeof(IEnumerable<Type>).IsAssignableFrom(cfg_type))\r\n            {\r\n                return;\r\n            }\r\n\r\n            foreach (var type in get_cfg())\r\n            {\r\n                if (!type.IsDefined(typeof(ObsoleteAttribute), false)\r\n                    && !type.IsEnum && !typeof(Delegate).IsAssignableFrom(type)\r\n                    && (!type.IsGenericType || type.IsGenericTypeDefinition))\r\n                {\r\n                    if ((type.Namespace == null || (type.Namespace != \"XLua\" && !type.Namespace.StartsWith(\"XLua.\"))))\r\n                    {\r\n                        on_cfg(type, hotfixType);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        public static void GetConfig(Dictionary<string, int> hotfixCfg, IEnumerable<Type> cfg_check_types)\r\n        {\r\n            if (cfg_check_types != null)\r\n            {\r\n                Action<Type, int> on_cfg = (type, hotfixType) =>\r\n                {\r\n                    string key = type.FullName.Replace('+', '/');\r\n                    if (!hotfixCfg.ContainsKey(key))\r\n                    {\r\n                        hotfixCfg.Add(key, hotfixType);\r\n                    }\r\n                };\r\n                foreach (var type in cfg_check_types.Where(t => !t.IsGenericTypeDefinition && t.IsAbstract && t.IsSealed))\r\n                {\r\n                    var flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;\r\n                    foreach (var field in type.GetFields(flags))\r\n                    {\r\n                        mergeConfig(field, field.FieldType, () => field.GetValue(null) as IEnumerable<Type>, on_cfg);\r\n                    }\r\n                    foreach (var prop in type.GetProperties(flags))\r\n                    {\r\n                        mergeConfig(prop, prop.PropertyType, () => prop.GetValue(null, null) as IEnumerable<Type>, on_cfg);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        public static List<Assembly> GetHotfixAssembly()\r\n        {\r\n            var projectPath = Assembly.Load(\"Assembly-CSharp\").ManifestModule.FullyQualifiedName;\r\n            Regex rgx = new Regex(@\"^(.*)[\\\\/]Library[\\\\/]ScriptAssemblies[\\\\/]Assembly-CSharp.dll$\");\r\n            MatchCollection matches = rgx.Matches(projectPath);\r\n            projectPath = matches[0].Groups[1].Value;\r\n\r\n            List<Type> types = new List<Type>();\r\n            Action<Type, int> on_cfg = (type, hotfixType) =>\r\n            {\r\n                types.Add(type);\r\n            };\r\n\r\n            foreach (var assmbly in AppDomain.CurrentDomain.GetAssemblies())\r\n            {\r\n                try\r\n                {\r\n                    foreach (var type in (from type in assmbly.GetTypes()\r\n                                          where !type.IsGenericTypeDefinition\r\n                                          select type))\r\n                    {\r\n                        if (getHotfixType(type) != -1)\r\n                        {\r\n                            types.Add(type);\r\n                        }\r\n                        else\r\n                        {\r\n                            var flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;\r\n                            foreach (var field in type.GetFields(flags))\r\n                            {\r\n                                mergeConfig(field, field.FieldType, () => field.GetValue(null) as IEnumerable<Type>, on_cfg);\r\n                            }\r\n                            foreach (var prop in type.GetProperties(flags))\r\n                            {\r\n                                mergeConfig(prop, prop.PropertyType, () => prop.GetValue(null, null) as IEnumerable<Type>, on_cfg);\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n                catch { } // 防止有的工程有非法的dll导致中断\r\n            }\r\n            return types.Select(t => t.Assembly).Distinct()\r\n                .Where(a => a.ManifestModule.FullyQualifiedName.IndexOf(projectPath) == 0)\r\n                .ToList();\r\n        }\r\n\r\n        public static List<string> GetHotfixAssemblyPaths()\r\n        {\r\n            return GetHotfixAssembly().Select(a => a.ManifestModule.FullyQualifiedName).Distinct().ToList();\r\n        }\r\n    }\r\n}\r\n#if XLUA_GENERAL\r\n\r\nnamespace XLua\r\n{\r\n    [Flags]\r\n    enum HotfixFlagInTool\r\n    {\r\n        Stateless = 0,\r\n        Stateful = 1,\r\n        ValueTypeBoxing = 2,\r\n        IgnoreProperty = 4,\r\n        IgnoreNotPublic = 8,\r\n        Inline = 16,\r\n        IntKey = 32,\r\n        AdaptByDelegate = 64,\r\n        IgnoreCompilerGenerated = 128,\r\n        NoBaseProxy = 256,\r\n    }\r\n\r\n    static class ExtentionMethods\r\n    {\r\n        public static bool HasFlag(this HotfixFlagInTool toCheck, HotfixFlagInTool flag)\r\n        {\r\n            return (toCheck != HotfixFlagInTool.Stateless) && ((toCheck & flag) == flag);\r\n        }\r\n\r\n        public static MethodReference MakeGenericMethod(this MethodReference self, params TypeReference[] arguments)\r\n        {\r\n            if (self.GenericParameters.Count != arguments.Length)\r\n                throw new ArgumentException();\r\n\r\n            var instance = new GenericInstanceMethod(self);\r\n            foreach (var argument in arguments)\r\n                instance.GenericArguments.Add(argument);\r\n\r\n            return instance;\r\n        }\r\n\r\n        public static FieldReference GetGeneric(this FieldDefinition definition)\r\n        {\r\n            if (definition.DeclaringType.HasGenericParameters)\r\n            {\r\n                var declaringType = new GenericInstanceType(definition.DeclaringType);\r\n                foreach (var parameter in definition.DeclaringType.GenericParameters)\r\n                {\r\n                    declaringType.GenericArguments.Add(parameter);\r\n                }\r\n                return new FieldReference(definition.Name, definition.FieldType, declaringType);\r\n            }\r\n\r\n            return definition;\r\n        }\r\n\r\n        public static TypeReference GetGeneric(this TypeDefinition definition)\r\n        {\r\n            if (definition.HasGenericParameters)\r\n            {\r\n                var genericInstanceType = new GenericInstanceType(definition);\r\n                foreach (var parameter in definition.GenericParameters)\r\n                {\r\n                    genericInstanceType.GenericArguments.Add(parameter);\r\n                }\r\n                return genericInstanceType;\r\n            }\r\n\r\n            return definition;\r\n        }\r\n\r\n        public static TypeReference TryImport(this ModuleDefinition module, TypeReference type)\r\n        {\r\n            if (module.Assembly.FullName == type.Module.Assembly.FullName\r\n                && module.FullyQualifiedName == type.Module.FullyQualifiedName)\r\n            {\r\n                return type;\r\n            }\r\n            else\r\n            {\r\n#if XLUA_GENERAL\r\n                return module.ImportReference(type);\r\n#else\r\n                return module.Import(type);\r\n#endif\r\n            }\r\n        }\r\n\r\n        public static MethodReference TryImport(this ModuleDefinition module, MethodReference method)\r\n        {\r\n            if (module.Assembly.FullName == method.Module.Assembly.FullName\r\n                && module.FullyQualifiedName == method.Module.FullyQualifiedName)\r\n            {\r\n                return method;\r\n            }\r\n            else\r\n            {\r\n#if XLUA_GENERAL\r\n                return module.ImportReference(method);\r\n#else\r\n                return module.Import(method);\r\n#endif\r\n            }\r\n        }\r\n    }\r\n\r\n    public class Hotfix\r\n    {\r\n        private TypeReference objType = null;\r\n        private TypeReference delegateBridgeType = null;\r\n        private AssemblyDefinition injectAssembly = null;\r\n\r\n        private MethodReference delegateBridgeGetter = null;\r\n        private MethodReference hotfixFlagGetter = null;\r\n        private MethodReference invokeSessionStart = null;\r\n        private MethodReference functionInvoke = null;\r\n        private MethodReference invokeSessionEnd = null;\r\n        private MethodReference invokeSessionEndWithResult = null;\r\n        private MethodReference inParam = null;\r\n        private MethodReference inParams = null;\r\n        private MethodReference outParam = null;\r\n\r\n        private Dictionary<string, int> hotfixCfg = null;\r\n        private List<MethodDefinition> hotfixBridgesDef = null;\r\n        private Dictionary<MethodDefinition, MethodDefinition> hotfixBridgeToDelegate = null;\r\n\r\n        private List<MethodDefinition> bridgeIndexByKey = null;\r\n\r\n        private bool isTheSameAssembly = false;\r\n\r\n        private int delegateId = 0;\r\n\r\n        public void Init(AssemblyDefinition injectAssembly, AssemblyDefinition xluaAssembly, IEnumerable<string> searchDirectorys, Dictionary<string, int> hotfixCfg)\r\n        {\r\n            isTheSameAssembly = injectAssembly == xluaAssembly;\r\n            this.injectAssembly = injectAssembly;\r\n            this.hotfixCfg = hotfixCfg;\r\n            var injectModule = injectAssembly.MainModule;\r\n            objType = injectModule.TypeSystem.Object;\r\n\r\n            var delegateBridgeTypeDef = xluaAssembly.MainModule.Types.Single(t => t.FullName == \"XLua.DelegateBridge\");\r\n            delegateBridgeType = injectModule.TryImport(delegateBridgeTypeDef);\r\n            delegateBridgeGetter = injectModule.TryImport(xluaAssembly.MainModule.Types.Single(t => t.FullName == \"XLua.HotfixDelegateBridge\")\r\n                .Methods.Single(m => m.Name == \"Get\"));\r\n            hotfixFlagGetter = injectModule.TryImport(xluaAssembly.MainModule.Types.Single(t => t.FullName == \"XLua.HotfixDelegateBridge\")\r\n                .Methods.Single(m => m.Name == \"xlua_get_hotfix_flag\"));\r\n\r\n            //luaFunctionType = assembly.MainModule.Types.Single(t => t.FullName == \"XLua.LuaFunction\");\r\n            invokeSessionStart = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"InvokeSessionStart\"));\r\n            functionInvoke = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"Invoke\"));\r\n            invokeSessionEnd = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"InvokeSessionEnd\"));\r\n            invokeSessionEndWithResult = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"InvokeSessionEndWithResult\"));\r\n            inParam = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"InParam\"));\r\n            inParams = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"InParams\"));\r\n            outParam = injectModule.TryImport(delegateBridgeTypeDef.Methods.Single(m => m.Name == \"OutParam\"));\r\n\r\n            hotfixBridgesDef = (from method in delegateBridgeTypeDef.Methods\r\n                              where method.Name.StartsWith(\"__Gen_Delegate_Imp\")\r\n                              select method).ToList();\r\n            hotfixBridgeToDelegate = new Dictionary<MethodDefinition, MethodDefinition>();\r\n            delegateId = 0;\r\n\r\n            //hotfixBridges = hotfixBridgesDef.Select(m => injectModule.TryImport(m)).ToList();\r\n\r\n            bridgeIndexByKey = new List<MethodDefinition>();\r\n\r\n            var resolverOfInjectAssembly = injectAssembly.MainModule.AssemblyResolver as BaseAssemblyResolver;\r\n            var resolverOfXluaAssembly = xluaAssembly.MainModule.AssemblyResolver as BaseAssemblyResolver;\r\n            if (!isTheSameAssembly)\r\n            {\r\n                resolverOfXluaAssembly.AddSearchDirectory(Path.GetDirectoryName(injectAssembly.MainModule.FullyQualifiedName));\r\n            }\r\n            Action<string> addSearchDirectory = (string dir) =>\r\n            {\r\n                resolverOfInjectAssembly.AddSearchDirectory(dir);\r\n                if (!isTheSameAssembly)\r\n                {\r\n                    resolverOfXluaAssembly.AddSearchDirectory(dir);\r\n                }\r\n            };\r\n            addSearchDirectory(\"./Library/ScriptAssemblies/\");\r\n            foreach (var path in\r\n                (from asm in AppDomain.CurrentDomain.GetAssemblies() select asm.ManifestModule.FullyQualifiedName)\r\n                 .Distinct())\r\n            {\r\n                try\r\n                {\r\n                    addSearchDirectory(Path.GetDirectoryName(path));\r\n                }\r\n                catch(Exception)\r\n                {\r\n\r\n                }\r\n            }\r\n\r\n            if (searchDirectorys != null)\r\n            {\r\n                foreach(var directory in searchDirectorys.Distinct())\r\n                {\r\n                    addSearchDirectory(directory);\r\n                }\r\n            }\r\n\r\n            var nameToOpcodes = typeof(OpCodes).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)\r\n                .ToDictionary(f => f.Name, f => ((OpCode)f.GetValue(null)));\r\n            foreach(var kv in nameToOpcodes)\r\n            {\r\n                if (kv.Key.EndsWith(\"_S\"))\r\n                {\r\n                    shortToLong[kv.Value] = nameToOpcodes[kv.Key.Substring(0, kv.Key.Length - 2)];\r\n                }\r\n            }\r\n        }\r\n\r\n        static string getAssemblyFullName(IMetadataScope scope)\r\n        {\r\n            if (scope == null) return null;\r\n            switch(scope.MetadataScopeType)\r\n            {\r\n                case MetadataScopeType.ModuleDefinition:\r\n                    {\r\n                        ModuleDefinition md = scope as ModuleDefinition;\r\n                        return md.Assembly.FullName;\r\n                    }\r\n                case MetadataScopeType.AssemblyNameReference:\r\n                    {\r\n                        AssemblyNameReference anr = scope as AssemblyNameReference;\r\n                        return anr.FullName;\r\n                    }\r\n            }\r\n            return null;\r\n        }\r\n\r\n        static bool isSameType(TypeReference left, TypeReference right)\r\n        {\r\n            if (left.FullName != right.FullName)\r\n            {\r\n                return false;\r\n            }\r\n\r\n            //TypeReference.Module.FullyQualifiedName不验证\r\n            if (left.Module.Assembly.FullName == right.Module.Assembly.FullName)\r\n            {\r\n                return true;\r\n            }\r\n            else\r\n            {\r\n                var lafn = getAssemblyFullName(left.Scope);\r\n                var rafn = getAssemblyFullName(right.Scope);\r\n                if (lafn != null && lafn == rafn)\r\n                {\r\n                    return true;\r\n                }\r\n                var lr = left.Resolve();\r\n                var rr = right.Resolve();\r\n                if (lr == null || rr == null) return false;\r\n                return lr.Module.Assembly.FullName == rr.Module.Assembly.FullName;\r\n            }\r\n        }\r\n\r\n        MethodDefinition createDelegateFor(MethodDefinition method, AssemblyDefinition assembly, string delegateName, bool ignoreValueType)\r\n        {\r\n            var voidType = assembly.MainModule.TypeSystem.Void;\r\n            var objectType = assembly.MainModule.TypeSystem.Object;\r\n            var nativeIntType = assembly.MainModule.TypeSystem.IntPtr;\r\n            var asyncResultType = assembly.MainModule.Import(typeof(IAsyncResult));\r\n            var asyncCallbackType = assembly.MainModule.Import(typeof(AsyncCallback));\r\n\r\n            Mono.Cecil.MethodAttributes delegateMethodAttributes = Mono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.Virtual | Mono.Cecil.MethodAttributes.VtableLayoutMask;\r\n\r\n            var delegateDef = new TypeDefinition(\"XLua\", delegateName, Mono.Cecil.TypeAttributes.Sealed | Mono.Cecil.TypeAttributes.Public,\r\n                    assembly.MainModule.Import(typeof(MulticastDelegate)));\r\n            List<TypeReference> argTypes = new List<TypeReference>();\r\n            TypeReference self = null;\r\n            if (!method.IsStatic)\r\n            {\r\n                self = (!ignoreValueType && method.DeclaringType.IsValueType) ? method.DeclaringType : objType;\r\n            }\r\n            foreach(var parameter in method.Parameters)\r\n            {\r\n                bool isparam = parameter.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.Name == \"ParamArrayAttribute\") != null;\r\n                argTypes.Add((isparam || parameter.ParameterType.IsByReference || (!ignoreValueType && parameter.ParameterType.IsValueType)) ? parameter.ParameterType : objType);\r\n            }\r\n\r\n            var constructor = new MethodDefinition(\".ctor\", Mono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.SpecialName | Mono.Cecil.MethodAttributes.RTSpecialName, voidType);\r\n            constructor.Parameters.Add(new ParameterDefinition(\"objectInstance\", Mono.Cecil.ParameterAttributes.None, objectType));\r\n            constructor.Parameters.Add(new ParameterDefinition(\"functionPtr\", Mono.Cecil.ParameterAttributes.None, nativeIntType));\r\n            constructor.ImplAttributes = Mono.Cecil.MethodImplAttributes.Runtime;\r\n            delegateDef.Methods.Add(constructor);\r\n\r\n            var beginInvoke = new MethodDefinition(\"BeginInvoke\", delegateMethodAttributes, asyncResultType);\r\n            if (self != null)\r\n            {\r\n                beginInvoke.Parameters.Add(new ParameterDefinition(self));\r\n            }\r\n            for (int i = 0; i < argTypes.Count; i++)\r\n            {\r\n                beginInvoke.Parameters.Add(new ParameterDefinition(method.Parameters[i].Name, (method.Parameters[i].IsOut ? Mono.Cecil.ParameterAttributes.Out : Mono.Cecil.ParameterAttributes.None), argTypes[i]));\r\n            }\r\n            beginInvoke.Parameters.Add(new ParameterDefinition(\"callback\", Mono.Cecil.ParameterAttributes.None, asyncCallbackType));\r\n            beginInvoke.Parameters.Add(new ParameterDefinition(\"object\", Mono.Cecil.ParameterAttributes.None, objectType));\r\n            beginInvoke.ImplAttributes = Mono.Cecil.MethodImplAttributes.Runtime;\r\n            delegateDef.Methods.Add(beginInvoke);\r\n\r\n            var endInvoke = new MethodDefinition(\"EndInvoke\", delegateMethodAttributes, method.ReturnType);\r\n            for (int i = 0; i < argTypes.Count; i++)\r\n            {\r\n                if (argTypes[i].IsByReference)\r\n                {\r\n                    endInvoke.Parameters.Add(new ParameterDefinition(method.Parameters[i].Name, (method.Parameters[i].IsOut ? Mono.Cecil.ParameterAttributes.Out : Mono.Cecil.ParameterAttributes.None), argTypes[i]));\r\n                }\r\n            }\r\n            endInvoke.Parameters.Add(new ParameterDefinition(\"result\", Mono.Cecil.ParameterAttributes.None, asyncResultType));\r\n            endInvoke.ImplAttributes = Mono.Cecil.MethodImplAttributes.Runtime;\r\n            delegateDef.Methods.Add(endInvoke);\r\n\r\n            var invoke = new MethodDefinition(\"Invoke\", delegateMethodAttributes, method.ReturnType);\r\n            if (self != null)\r\n            {\r\n                invoke.Parameters.Add(new ParameterDefinition(self));\r\n            }\r\n            for(int i = 0; i < argTypes.Count; i++)\r\n            {\r\n                invoke.Parameters.Add(new ParameterDefinition(method.Parameters[i].Name, (method.Parameters[i].IsOut ? Mono.Cecil.ParameterAttributes.Out : Mono.Cecil.ParameterAttributes.None), argTypes[i]));\r\n            }\r\n            invoke.ImplAttributes = Mono.Cecil.MethodImplAttributes.Runtime;\r\n            delegateDef.Methods.Add(invoke);\r\n\r\n            assembly.MainModule.Types.Add(delegateDef);\r\n\r\n            return invoke;\r\n        }\r\n\r\n        MethodDefinition getDelegateInvokeFor(MethodDefinition method, MethodDefinition bridgeDef, bool ignoreValueType)\r\n        {\r\n            MethodDefinition ret;\r\n            if (!hotfixBridgeToDelegate.TryGetValue(bridgeDef, out ret))\r\n            {\r\n                ret = createDelegateFor(method, injectAssembly, (\"__XLua_Gen_Delegate\" + (delegateId++)), ignoreValueType);\r\n                hotfixBridgeToDelegate.Add(bridgeDef, ret);\r\n            }\r\n\r\n            return ret;\r\n        }\r\n\r\n        bool findHotfixDelegate(MethodDefinition method, out MethodReference invoke, HotfixFlagInTool hotfixType)\r\n        {\r\n            bool ignoreValueType = hotfixType.HasFlag(HotfixFlagInTool.ValueTypeBoxing);\r\n\r\n            bool isIntKey = hotfixType.HasFlag(HotfixFlagInTool.IntKey) && !method.DeclaringType.HasGenericParameters && isTheSameAssembly;\r\n\r\n            bool isAdaptByDelegate = !isIntKey && hotfixType.HasFlag(HotfixFlagInTool.AdaptByDelegate);\r\n\r\n            for (int i = 0; i < hotfixBridgesDef.Count; i++)\r\n            {\r\n                MethodDefinition hotfixBridgeDef = hotfixBridgesDef[i];\r\n                var returnType = method.ReturnType;\r\n                if (isSameType(returnType, hotfixBridgeDef.ReturnType))\r\n                {\r\n                    var parametersOfDelegate = hotfixBridgeDef.Parameters;\r\n                    int compareOffset = 0;\r\n                    if (!method.IsStatic)\r\n                    {\r\n                        var typeOfSelf = (!ignoreValueType && method.DeclaringType.IsValueType) ? method.DeclaringType : objType;\r\n                        if ((parametersOfDelegate.Count == 0) || parametersOfDelegate[0].ParameterType.IsByReference || !isSameType(typeOfSelf, parametersOfDelegate[0].ParameterType))\r\n                        {\r\n                            continue;\r\n                        }\r\n                        compareOffset++;\r\n                    }\r\n                    if (method.Parameters.Count != (parametersOfDelegate.Count - compareOffset))\r\n                    {\r\n                        continue;\r\n                    }\r\n                    bool paramMatch = true;\r\n                    for (int j = 0; j < method.Parameters.Count; j++)\r\n                    {\r\n                        var param_left = method.Parameters[j];\r\n                        var param_right = parametersOfDelegate[compareOffset++];\r\n                        if (param_left.IsOut != param_right.IsOut\r\n                            || param_left.ParameterType.IsByReference != param_right.ParameterType.IsByReference)\r\n                        {\r\n                            paramMatch = false;\r\n                            break;\r\n                        }\r\n                        if (!ignoreValueType && param_left.ParameterType.IsValueType != param_right.ParameterType.IsValueType)\r\n                        {\r\n                            paramMatch = false;\r\n                            break;\r\n                        }\r\n\t\t\t\t\t\tbool isparam = param_left.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.Name == \"ParamArrayAttribute\") != null;\r\n\t\t\t\t\t\tvar type_left = (isparam || param_left.ParameterType.IsByReference || (!ignoreValueType && param_left.ParameterType.IsValueType)) ? param_left.ParameterType : objType;\r\n                        if (!isSameType(type_left, param_right.ParameterType))\r\n                        {\r\n                            paramMatch = false;\r\n                            break;\r\n                        }\r\n                    }\r\n\r\n                    if (!paramMatch)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    invoke = (isTheSameAssembly && !isAdaptByDelegate) ? hotfixBridgeDef : getDelegateInvokeFor(method, hotfixBridgeDef, ignoreValueType);\r\n                    return true;\r\n                }\r\n            }\r\n            invoke = null;\r\n            return false;\r\n        }\r\n\r\n        static bool hasGenericParameter(TypeReference type)\r\n        {\r\n            if (type.HasGenericParameters)\r\n            {\r\n                return true;\r\n            }\r\n            if (type.IsByReference)\r\n            {\r\n                return hasGenericParameter(((ByReferenceType)type).ElementType);\r\n            }\r\n            if (type.IsArray)\r\n            {\r\n                return hasGenericParameter(((ArrayType)type).ElementType);\r\n            }\r\n            if (type.IsGenericInstance)\r\n            {\r\n                foreach (var typeArg in ((GenericInstanceType)type).GenericArguments)\r\n                {\r\n                    if (hasGenericParameter(typeArg))\r\n                    {\r\n                        return true;\r\n                    }\r\n                }\r\n                return false;\r\n            }\r\n            return type.IsGenericParameter;\r\n        }\r\n\r\n        static bool hasGenericParameter(MethodDefinition method)\r\n        {\r\n            if (!method.IsStatic && hasGenericParameter(method.DeclaringType)) return true;\r\n            return hasGenericParameterSkipDelaringType(method);\r\n        }\r\n\r\n        static bool hasGenericParameterSkipDelaringType(MethodDefinition method)\r\n        {\r\n            if (method.HasGenericParameters) return true;\r\n            //if (!method.IsStatic && hasGenericParameter(method.DeclaringType)) return true;\r\n            if (hasGenericParameter(method.ReturnType)) return true;\r\n            foreach (var paramInfo in method.Parameters)\r\n            {\r\n                if (hasGenericParameter(paramInfo.ParameterType)) return true;\r\n            }\r\n            return false;\r\n        }\r\n\r\n        static bool isNoPublic(TypeReference type)\r\n        {\r\n            if (type.IsByReference)\r\n            {\r\n                return isNoPublic(((ByReferenceType)type).ElementType);\r\n            }\r\n            if (type.IsArray)\r\n            {\r\n                return isNoPublic(((ArrayType)type).ElementType);\r\n            }\r\n            else\r\n            {\r\n                if (type.IsGenericInstance)\r\n                {\r\n                    foreach (var typeArg in ((GenericInstanceType)type).GenericArguments)\r\n                    {\r\n                        if (isNoPublic(typeArg))\r\n                        {\r\n                            return true;\r\n                        }\r\n                    }\r\n                }\r\n\r\n                var resolveType = type.Resolve();\r\n                if ((!type.IsNested && !resolveType.IsPublic) || (type.IsNested && !resolveType.IsNestedPublic))\r\n                {\r\n                    return true;\r\n                }\r\n                if (type.IsNested)\r\n                {\r\n                    var parent = type.DeclaringType;\r\n                    while (parent != null)\r\n                    {\r\n                        var resolveParent = parent.Resolve();\r\n                        if ((!parent.IsNested && !resolveParent.IsPublic) || (parent.IsNested && !resolveParent.IsNestedPublic))\r\n                        {\r\n                            return true;\r\n                        }\r\n                        if (parent.IsNested)\r\n                        {\r\n                            parent = parent.DeclaringType;\r\n                        }\r\n                        else\r\n                        {\r\n                            break;\r\n                        }\r\n                    }\r\n                }\r\n                return false;\r\n            }\r\n\r\n        }\r\n\r\n        static bool genericInOut(MethodDefinition method, HotfixFlagInTool hotfixType)\r\n        {\r\n            bool ignoreValueType = hotfixType.HasFlag(HotfixFlagInTool.ValueTypeBoxing);\r\n\r\n            if (hasGenericParameter(method.ReturnType) || isNoPublic(method.ReturnType))\r\n            {\r\n                return true;\r\n            }\r\n            var parameters = method.Parameters;\r\n\r\n            if (!method.IsStatic \r\n                && (hasGenericParameter(method.DeclaringType) || ((!ignoreValueType && method.DeclaringType.IsValueType) && isNoPublic(method.DeclaringType))))\r\n            {\r\n                    return true;\r\n            }\r\n            for (int i = 0; i < parameters.Count; i++)\r\n            {\r\n                if ( hasGenericParameter(parameters[i].ParameterType) || (((!ignoreValueType && parameters[i].ParameterType.IsValueType) || parameters[i].ParameterType.IsByReference || parameters[i].CustomAttributes.Any(ca => ca.AttributeType.FullName == \"System.ParamArrayAttribute\")) && isNoPublic(parameters[i].ParameterType)))\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\r\n        public bool InjectType(TypeReference hotfixAttributeType, TypeDefinition type)\r\n        {\r\n            foreach(var nestedTypes in type.NestedTypes)\r\n            {\r\n                if (!InjectType(hotfixAttributeType, nestedTypes))\r\n                {\r\n                    return false;\r\n                }\r\n            }\r\n            if (type.Name.Contains(\"<\") || type.IsInterface || type.Methods.Count == 0) // skip anonymous type and interface\r\n            {\r\n                return true;\r\n            }\r\n            CustomAttribute hotfixAttr = type.CustomAttributes.FirstOrDefault(ca => ca.AttributeType == hotfixAttributeType);\r\n            HotfixFlagInTool hotfixType;\r\n            if (hotfixAttr != null)\r\n            {\r\n                hotfixType = (HotfixFlagInTool)(int)hotfixAttr.ConstructorArguments[0].Value;\r\n            }\r\n            else\r\n            {\r\n                if (!hotfixCfg.ContainsKey(type.FullName))\r\n                {\r\n                    return true;\r\n                }\r\n                hotfixType = (HotfixFlagInTool)hotfixCfg[type.FullName];\r\n            }\r\n\r\n            bool ignoreProperty = hotfixType.HasFlag(HotfixFlagInTool.IgnoreProperty);\r\n            bool ignoreCompilerGenerated = hotfixType.HasFlag(HotfixFlagInTool.IgnoreCompilerGenerated);\r\n            bool ignoreNotPublic = hotfixType.HasFlag(HotfixFlagInTool.IgnoreNotPublic);\r\n            bool isInline = hotfixType.HasFlag(HotfixFlagInTool.Inline);\r\n            bool isIntKey = hotfixType.HasFlag(HotfixFlagInTool.IntKey);\r\n            bool noBaseProxy = hotfixType.HasFlag(HotfixFlagInTool.NoBaseProxy);\r\n            if (ignoreCompilerGenerated && type.CustomAttributes.Any(ca => ca.AttributeType.FullName == \"System.Runtime.CompilerServices.CompilerGeneratedAttribute\"))\r\n            {\r\n                return true;\r\n            }\r\n            if (isIntKey && type.HasGenericParameters)\r\n            {\r\n                throw new InvalidOperationException(type.FullName + \" is generic definition, can not be mark as IntKey!\");\r\n            }\r\n            //isIntKey = !type.HasGenericParameters;\r\n\r\n            foreach (var method in type.Methods)\r\n            {\r\n                if (ignoreNotPublic && !method.IsPublic)\r\n                {\r\n                    continue;\r\n                }\r\n                if (ignoreProperty && method.IsSpecialName && (method.Name.StartsWith(\"get_\") || method.Name.StartsWith(\"set_\")))\r\n                {\r\n                    continue;\r\n                }\r\n                if (ignoreCompilerGenerated && method.CustomAttributes.Any(ca => ca.AttributeType.FullName == \"System.Runtime.CompilerServices.CompilerGeneratedAttribute\"))\r\n                {\r\n                    continue;\r\n                }\r\n                if (method.Parameters.Any(pd => pd.ParameterType.IsPointer) || method.ReturnType.IsPointer)\r\n                {\r\n                    continue;\r\n                }\r\n                if (method.Name != \".cctor\" && !method.IsAbstract && !method.IsPInvokeImpl && method.Body != null && !method.Name.Contains(\"<\"))\r\n                {\r\n                    //Debug.Log(method);\r\n                    if ((isInline || method.HasGenericParameters || genericInOut(method, hotfixType)) \r\n                        ? !injectGenericMethod(method, hotfixType) :\r\n                        !injectMethod(method, hotfixType))\r\n                    {\r\n                        return false;\r\n                    }\r\n                }\r\n            }\r\n\r\n            if (!noBaseProxy)\r\n            {\r\n                List<MethodDefinition> toAdd = new List<MethodDefinition>();\r\n                foreach (var method in type.Methods)\r\n                {\r\n                    if (ignoreNotPublic && !method.IsPublic)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    if (ignoreProperty && method.IsSpecialName && (method.Name.StartsWith(\"get_\") || method.Name.StartsWith(\"set_\")))\r\n                    {\r\n                        continue;\r\n                    }\r\n                    if (ignoreCompilerGenerated && method.CustomAttributes.Any(ca => ca.AttributeType.FullName == \"System.Runtime.CompilerServices.CompilerGeneratedAttribute\"))\r\n                    {\r\n                        continue;\r\n                    }\r\n                    if (method.Parameters.Any(pd => pd.ParameterType.IsPointer) || method.ReturnType.IsPointer)\r\n                    {\r\n                        continue;\r\n                    }\r\n                    if (method.Name != \".cctor\" && !method.IsAbstract && !method.IsPInvokeImpl && method.Body != null && !method.Name.Contains(\"<\"))\r\n                    {\r\n                        var proxyMethod = tryAddBaseProxy(type, method);\r\n                        if (proxyMethod != null) toAdd.Add(proxyMethod);\r\n                    }\r\n                }\r\n\r\n                foreach (var md in toAdd)\r\n                {\r\n                    type.Methods.Add(md);\r\n                }\r\n            }\r\n\r\n            return true;\r\n        }\r\n\r\n#if !XLUA_GENERAL\r\n        [PostProcessScene]\r\n        [MenuItem(\"XLua/Hotfix Inject In Editor\", false, 3)]\r\n        public static void HotfixInject()\r\n        {\r\n            if (EditorApplication.isCompiling || Application.isPlaying)\r\n            {\r\n                return;\r\n            }\r\n            var hotfixCfg = new Dictionary<string, int>();\r\n            HotfixConfig.GetConfig(hotfixCfg, Utils.GetAllTypes());\r\n            var xluaAssemblyPath = typeof(LuaEnv).Module.FullyQualifiedName;\r\n            var idMapFileName = CSObjectWrapEditor.GeneratorConfig.common_path + \"Resources/hotfix_id_map.lua.txt\";\r\n            var injectAssemblyPaths = HotfixConfig.GetHotfixAssemblyPaths();\r\n\r\n            foreach (var injectAssemblyPath in injectAssemblyPaths)\r\n            {\r\n                Info(\"injecting \" + injectAssemblyPath);\r\n                if (injectAssemblyPaths.Count > 1)\r\n                {\r\n                    var injectAssemblyFileName = Path.GetFileName(injectAssemblyPath);\r\n                    idMapFileName = CSObjectWrapEditor.GeneratorConfig.common_path + \"Resources/hotfix_id_map_\" + injectAssemblyFileName.Substring(0, injectAssemblyFileName.Length - 4) + \".lua.txt\";\r\n                }\r\n                HotfixInject(injectAssemblyPath, xluaAssemblyPath, null, idMapFileName, hotfixCfg);\r\n            }\r\n            AssetDatabase.Refresh();\r\n        }\r\n#endif\r\n\r\n        static AssemblyDefinition readAssembly(string assemblyPath)\r\n        {\r\n#if HOTFIX_SYMBOLS_DISABLE\r\n            return AssemblyDefinition.ReadAssembly(assemblyPath);\r\n#else\r\n            if (File.Exists(assemblyPath + \".mdb\"))\r\n            {\r\n                var readerParameters = new ReaderParameters { ReadSymbols = true };\r\n                return AssemblyDefinition.ReadAssembly(assemblyPath, readerParameters);\r\n            }\r\n            else\r\n            {\r\n                return AssemblyDefinition.ReadAssembly(assemblyPath);\r\n            }\r\n#endif\r\n        }\r\n\r\n        static void writeAssembly(AssemblyDefinition assembly, string assemblyPath)\r\n        {\r\n#if HOTFIX_SYMBOLS_DISABLE\r\n            assembly.Write(assemblyPath);\r\n#else\r\n            if (File.Exists(assemblyPath + \".mdb\"))\r\n            {\r\n                var writerParameters = new WriterParameters { WriteSymbols = true };\r\n                assembly.Write(assemblyPath, writerParameters);\r\n            }\r\n            else\r\n            {\r\n                assembly.Write(assemblyPath);\r\n            }\r\n#endif\r\n        }\r\n\r\n        public static void HotfixInject(string injectAssemblyPath, string xluaAssemblyPath, IEnumerable<string> searchDirectorys, string idMapFilePath, Dictionary<string, int> hotfixConfig)\r\n        {\r\n            AssemblyDefinition injectAssembly = null;\r\n            AssemblyDefinition xluaAssembly = null;\r\n            try\r\n            {\r\n                injectAssembly = readAssembly(injectAssemblyPath);\r\n                \r\n                // injected flag check\r\n                if (injectAssembly.MainModule.Types.Any(t => t.Name == \"__XLUA_GEN_FLAG\"))\r\n                {\r\n                    Info(injectAssemblyPath + \" had injected!\");\r\n                    return;\r\n                }\r\n                injectAssembly.MainModule.Types.Add(new TypeDefinition(\"__XLUA_GEN\", \"__XLUA_GEN_FLAG\", Mono.Cecil.TypeAttributes.Class,\r\n                    injectAssembly.MainModule.TypeSystem.Object));\r\n\r\n                xluaAssembly = (injectAssemblyPath == xluaAssemblyPath || injectAssembly.MainModule.FullyQualifiedName == xluaAssemblyPath) ? \r\n                    injectAssembly : readAssembly(xluaAssemblyPath);\r\n\r\n                Hotfix hotfix = new Hotfix();\r\n                hotfix.Init(injectAssembly, xluaAssembly, searchDirectorys, hotfixConfig);\r\n\r\n                //var hotfixDelegateAttributeType = assembly.MainModule.Types.Single(t => t.FullName == \"XLua.HotfixDelegateAttribute\");\r\n                var hotfixAttributeType = xluaAssembly.MainModule.Types.Single(t => t.FullName == \"XLua.HotfixAttribute\");\r\n                var toInject = (from module in injectAssembly.Modules from type in module.Types select type).ToList();\r\n                foreach (var type in toInject)\r\n                {\r\n                    if (!hotfix.InjectType(hotfixAttributeType, type))\r\n                    {\r\n                        return;\r\n                    }\r\n                }\r\n                Directory.CreateDirectory(Path.GetDirectoryName(idMapFilePath));\r\n                hotfix.OutputIntKeyMapper(new FileStream(idMapFilePath, FileMode.Create, FileAccess.Write));\r\n                File.Copy(idMapFilePath, idMapFilePath + \".\" + DateTime.Now.ToString(\"yyyyMMddHHmmssfff\"));\r\n\r\n                writeAssembly(injectAssembly, injectAssemblyPath);\r\n                Info(injectAssemblyPath + \" inject finish!\");\r\n            }\r\n            catch(Exception e)\r\n            {\r\n                Error(injectAssemblyPath + \" inject Exception! \" + e);\r\n            }\r\n            finally\r\n            {\r\n                if (injectAssembly != null)\r\n                {\r\n                    Clean(injectAssembly);\r\n                }\r\n                if (xluaAssembly != null)\r\n                {\r\n                    Clean(xluaAssembly);\r\n                }\r\n            }\r\n        }\r\n\r\n        static void Info(string info)\r\n        {\r\n#if XLUA_GENERAL\r\n            System.Console.WriteLine(info);\r\n#else\r\n            UnityEngine.Debug.Log(info);\r\n#endif\r\n        }\r\n\r\n        static void Error(string info)\r\n        {\r\n#if XLUA_GENERAL\r\n            System.Console.WriteLine(\"Error:\" + info);\r\n#else\r\n            UnityEngine.Debug.LogError(info);\r\n#endif\r\n        }\r\n\r\n        static void Clean(AssemblyDefinition assembly)\r\n\t\t{\r\n\t\t\tif (assembly.MainModule.SymbolReader != null)\r\n\t\t\t{\r\n\t\t\t\tassembly.MainModule.SymbolReader.Dispose();\r\n\t\t\t}\r\n\t\t}\r\n\r\n        static OpCode[] ldargs = new OpCode[] { OpCodes.Ldarg_0, OpCodes.Ldarg_1, OpCodes.Ldarg_2, OpCodes.Ldarg_3 };\r\n\r\n        static readonly int MAX_OVERLOAD = 100;\r\n\r\n        static string getDelegateName(MethodDefinition method)\r\n        {\r\n            string fieldName = method.Name;\r\n            if (fieldName.StartsWith(\".\"))\r\n            {\r\n                fieldName = fieldName.Substring(1);\r\n            }\r\n            string ccFlag = method.IsConstructor ? \"_c\" : \"\";\r\n            string luaDelegateName = null;\r\n            var type = method.DeclaringType;\r\n            for (int i = 0; i < MAX_OVERLOAD; i++)\r\n            {\r\n                string tmp = ccFlag + \"__Hotfix\" + i + \"_\" + fieldName;\r\n                if (!type.Fields.Any(f => f.Name == tmp)) // injected\r\n                {\r\n                    luaDelegateName = tmp;\r\n                    break;\r\n                }\r\n            }\r\n            return luaDelegateName;\r\n        }\r\n\r\n        static Instruction findNextRet(Mono.Collections.Generic.Collection<Instruction> instructions, Instruction pos)\r\n        {\r\n            bool posFound = false;\r\n            for(int i = 0; i < instructions.Count; i++)\r\n            {\r\n                if (posFound && instructions[i].OpCode == OpCodes.Ret)\r\n                {\r\n                    return instructions[i];\r\n                }\r\n                else if (instructions[i] == pos)\r\n                {\r\n                    posFound = true;\r\n                }\r\n            }\r\n            return null;\r\n        }\r\n\r\n        Dictionary<OpCode, OpCode> shortToLong = new Dictionary<OpCode, OpCode>();\r\n\r\n        void fixBranch(ILProcessor processor, Mono.Collections.Generic.Collection<Instruction> instructions, Dictionary<Instruction, Instruction> originToNewTarget, HashSet<Instruction> noCheck)\r\n        {\r\n            foreach(var instruction in instructions)\r\n            {\r\n                Instruction target = instruction.Operand as Instruction;\r\n                if (target != null && !noCheck.Contains(instruction))\r\n                {\r\n                    if (originToNewTarget.ContainsKey(target))\r\n                    {\r\n                        instruction.Operand = originToNewTarget[target];\r\n                    }\r\n                }\r\n            }\r\n\r\n            int offset = 0;\r\n            for (int i = 0; i < instructions.Count; i++)\r\n            {\r\n                var instruction = instructions[i];\r\n                instruction.Offset = offset;\r\n                offset += instruction.GetSize();\r\n            }\r\n\r\n            for (int i = 0; i < instructions.Count; i++)\r\n            {\r\n                var instruction = instructions[i];\r\n                Instruction target = instruction.Operand as Instruction;\r\n                \r\n                if (target != null)\r\n                {\r\n                    int diff = target.Offset - instruction.Offset;\r\n                    if ((diff > sbyte.MaxValue || diff < sbyte.MinValue) && shortToLong.ContainsKey(instruction.OpCode))\r\n                    {\r\n                        instructions[i] = processor.Create(shortToLong[instruction.OpCode], target);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        static MethodDefinition findOverride(TypeDefinition type, MethodReference vmethod)\r\n        {\r\n            foreach (var method in type.Methods)\r\n            {\r\n                if (method.Name == vmethod.Name && method.IsVirtual && !method.IsAbstract && (method.ReturnType.FullName == vmethod.ReturnType.FullName) && method.Parameters.Count == vmethod.Parameters.Count)\r\n                {\r\n                    bool isParamsMatch = true;\r\n                    for (int i = 0; i < method.Parameters.Count; i++)\r\n                    {\r\n                        if (method.Parameters[i].Attributes != vmethod.Parameters[i].Attributes\r\n                            || (method.Parameters[i].ParameterType.FullName != vmethod.Parameters[i].ParameterType.FullName))\r\n                        {\r\n                            isParamsMatch = false;\r\n                            break;\r\n                        }\r\n                    }\r\n                    if (isParamsMatch) return method;\r\n                }\r\n            }\r\n            return null;\r\n        }\r\n\r\n        static MethodReference _findBase(TypeReference type, MethodDefinition method)\r\n        {\r\n            TypeDefinition td = type.Resolve();\r\n            if (td == null)\r\n            {\r\n                return null;\r\n            }\r\n            //if (type.IsGenericInstance && \r\n            //    (method.Module.Assembly.FullName != type.Module.Assembly.FullName || method.Module.Assembly.FullName != td.Module.Assembly.FullName\r\n            //    || method.Module.FullyQualifiedName != type.Module.FullyQualifiedName || method.Module.FullyQualifiedName != td.Module.FullyQualifiedName))\r\n            //{\r\n            //    return _findBase(td.BaseType, method);\r\n            //}\r\n            var m = findOverride(td, method);\r\n            if (m != null)\r\n            {\r\n                if (type.IsGenericInstance)\r\n                {\r\n                    var reference = new MethodReference(m.Name, tryImport(method.DeclaringType, m.ReturnType), tryImport(method.DeclaringType, type))\r\n                    {\r\n                        HasThis = m.HasThis,\r\n                        ExplicitThis = m.ExplicitThis,\r\n                        CallingConvention = m.CallingConvention\r\n                    };\r\n                    foreach (var parameter in m.Parameters)\r\n                        reference.Parameters.Add(new ParameterDefinition(tryImport(method.DeclaringType, parameter.ParameterType)));\r\n                    foreach (var generic_parameter in m.GenericParameters)\r\n                        reference.GenericParameters.Add(new GenericParameter(generic_parameter.Name, reference));\r\n                    return reference;\r\n                }\r\n                else\r\n                {\r\n                    return m;\r\n                }\r\n            }\r\n            return _findBase(getBaseType(type), method);\r\n        }\r\n\r\n        static MethodReference findBase(TypeDefinition type, MethodDefinition method)\r\n        {\r\n            if (method.IsVirtual && !method.IsNewSlot) //表明override\r\n            {\r\n                try\r\n                {\r\n                    if (hasGenericParameter(method)) return null;\r\n                    var b = _findBase(type.BaseType, method);\r\n                    try\r\n                    {\r\n                        if (hasGenericParameterSkipDelaringType(b.Resolve())) return null;\r\n                    }catch { }\r\n                    return b;\r\n                }\r\n                catch { }\r\n            }\r\n            return null;\r\n        }\r\n\r\n        static TypeReference getBaseType(TypeReference typeReference)\r\n        {\r\n            var typeDefinition = typeReference.Resolve();\r\n            var baseType = typeDefinition.BaseType;\r\n            if (typeReference.IsGenericInstance && baseType.IsGenericInstance)\r\n            {\r\n                var genericType = typeReference as GenericInstanceType;\r\n                var baseGenericType = baseType as GenericInstanceType;\r\n                var genericInstanceType = new GenericInstanceType(tryImport(typeReference, baseGenericType.ElementType));\r\n                foreach (var genericArgument in genericType.GenericArguments)\r\n                {\r\n                    genericInstanceType.GenericArguments.Add(genericArgument);\r\n                }\r\n                baseType = genericInstanceType;\r\n            }\r\n            return baseType;\r\n        }\r\n\r\n        const string BASE_RPOXY_PERFIX = \"<>xLuaBaseProxy_\";\r\n\r\n        static TypeReference tryImport(TypeReference type, TypeReference toImport)\r\n        {\r\n            if (type.Module.Assembly.FullName == toImport.Module.Assembly.FullName\r\n                && type.Module.FullyQualifiedName == toImport.Module.FullyQualifiedName)\r\n            {\r\n                return toImport;\r\n            }\r\n            else\r\n            {\r\n#if XLUA_GENERAL\r\n                return type.Module.ImportReference(toImport);\r\n#else\r\n                return type.Module.Import(toImport);\r\n#endif\r\n            }\r\n        }\r\n\r\n        static MethodReference tryImport(TypeReference type, MethodReference toImport)\r\n        {\r\n            if (type.Module.Assembly.FullName == toImport.Module.Assembly.FullName\r\n                && type.Module.FullyQualifiedName == toImport.Module.FullyQualifiedName)\r\n            {\r\n                return toImport;\r\n            }\r\n            else\r\n            {\r\n#if XLUA_GENERAL\r\n                return type.Module.ImportReference(toImport);\r\n#else\r\n                return type.Module.Import(toImport);\r\n#endif\r\n            }\r\n        }\r\n\r\n        static MethodDefinition tryAddBaseProxy(TypeDefinition type, MethodDefinition method)\r\n        {\r\n            var mbase = findBase(type, method);\r\n            if (mbase != null)\r\n            {\r\n                var proxyMethod = new MethodDefinition(BASE_RPOXY_PERFIX + method.Name, Mono.Cecil.MethodAttributes.Private, tryImport(type, method.ReturnType));\r\n                for (int i = 0; i < method.Parameters.Count; i++)\r\n                {\r\n                    proxyMethod.Parameters.Add(new ParameterDefinition(\"P\" + i, method.Parameters[i].IsOut ? Mono.Cecil.ParameterAttributes.Out : Mono.Cecil.ParameterAttributes.None, tryImport(type, method.Parameters[i].ParameterType)));\r\n                }\r\n                var instructions = proxyMethod.Body.Instructions;\r\n                var processor = proxyMethod.Body.GetILProcessor();\r\n                int paramCount = method.Parameters.Count + 1;\r\n                for (int i = 0; i < paramCount; i++)\r\n                {\r\n                    if (i < ldargs.Length)\r\n                    {\r\n                        instructions.Add(processor.Create(ldargs[i]));\r\n                    }\r\n                    else if (i < 256)\r\n                    {\r\n                        instructions.Add(processor.Create(OpCodes.Ldarg_S, (byte)i));\r\n                    }\r\n                    else\r\n                    {\r\n                        instructions.Add(processor.Create(OpCodes.Ldarg, (short)i));\r\n                    }\r\n                    if (i == 0 && type.IsValueType)\r\n                    {\r\n                        instructions.Add(Instruction.Create(OpCodes.Ldobj, type));\r\n                        instructions.Add(Instruction.Create(OpCodes.Box, type));\r\n                    }\r\n                }\r\n                instructions.Add(Instruction.Create(OpCodes.Call, tryImport(type, mbase)));\r\n                instructions.Add(Instruction.Create(OpCodes.Ret));\r\n                return proxyMethod;\r\n            }\r\n            return null;\r\n        }\r\n\r\n        bool injectMethod(MethodDefinition method, HotfixFlagInTool hotfixType)\r\n        {\r\n            var type = method.DeclaringType;\r\n            \r\n            bool isFinalize = (method.Name == \"Finalize\" && method.IsSpecialName);\r\n\r\n            MethodReference invoke = null;\r\n\r\n            int param_count = method.Parameters.Count + (method.IsStatic ? 0 : 1);\r\n\r\n            if (!findHotfixDelegate(method, out invoke, hotfixType))\r\n            {\r\n                Error(\"can not find delegate for \" + method.DeclaringType + \".\" + method.Name + \"! try re-genertate code.\");\r\n                return false;\r\n            }\r\n\r\n            if (invoke == null)\r\n            {\r\n                throw new Exception(\"unknow exception!\");\r\n            }\r\n\r\n#if XLUA_GENERAL\r\n            invoke = injectAssembly.MainModule.ImportReference(invoke);\r\n#else\r\n            invoke = injectAssembly.MainModule.Import(invoke);\r\n#endif\r\n\r\n            FieldReference fieldReference = null;\r\n            VariableDefinition injection = null;\r\n            bool isIntKey = hotfixType.HasFlag(HotfixFlagInTool.IntKey) && !type.HasGenericParameters && isTheSameAssembly;\r\n            //isIntKey = !type.HasGenericParameters;\r\n\r\n            if (!isIntKey)\r\n            {\r\n                injection = new VariableDefinition(invoke.DeclaringType);\r\n                method.Body.Variables.Add(injection);\r\n\r\n                var luaDelegateName = getDelegateName(method);\r\n                if (luaDelegateName == null)\r\n                {\r\n                    Error(\"too many overload!\");\r\n                    return false;\r\n                }\r\n\r\n                FieldDefinition fieldDefinition = new FieldDefinition(luaDelegateName, Mono.Cecil.FieldAttributes.Static | Mono.Cecil.FieldAttributes.Private,\r\n                    invoke.DeclaringType);\r\n                type.Fields.Add(fieldDefinition);\r\n                fieldReference = fieldDefinition.GetGeneric();\r\n            }\r\n\r\n            bool ignoreValueType = hotfixType.HasFlag(HotfixFlagInTool.ValueTypeBoxing);\r\n\r\n            var insertPoint = method.Body.Instructions[0];\r\n            var processor = method.Body.GetILProcessor();\r\n\r\n            if (method.IsConstructor)\r\n            {\r\n                insertPoint = findNextRet(method.Body.Instructions, insertPoint);\r\n            }\r\n\r\n            Dictionary<Instruction, Instruction> originToNewTarget = new Dictionary<Instruction, Instruction>();\r\n            HashSet<Instruction> noCheck = new HashSet<Instruction>();\r\n\r\n            while (insertPoint != null)\r\n            {\r\n                Instruction firstInstruction;\r\n                if (isIntKey)\r\n                {\r\n                    firstInstruction = processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count);\r\n                    processor.InsertBefore(insertPoint, firstInstruction);\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, hotfixFlagGetter));\r\n                }\r\n                else\r\n                {\r\n                    firstInstruction = processor.Create(OpCodes.Ldsfld, fieldReference);\r\n                    processor.InsertBefore(insertPoint, firstInstruction);\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Stloc, injection));\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                }\r\n\r\n                var jmpInstruction = processor.Create(OpCodes.Brfalse, insertPoint);\r\n                processor.InsertBefore(insertPoint, jmpInstruction);\r\n\r\n                if (isIntKey)\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count));\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, delegateBridgeGetter));\r\n                }\r\n                else\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                }\r\n\r\n                for (int i = 0; i < param_count; i++)\r\n                {\r\n                    if (i < ldargs.Length)\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(ldargs[i]));\r\n                    }\r\n                    else if (i < 256)\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg_S, (byte)i));\r\n                    }\r\n                    else\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg, (short)i));\r\n                    }\r\n                    if (i == 0 && !method.IsStatic && type.IsValueType)\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldobj, type));\r\n                        \r\n                    }\r\n                    if (ignoreValueType)\r\n                    {\r\n                        TypeReference paramType;\r\n                        if (method.IsStatic)\r\n                        {\r\n                            paramType = method.Parameters[i].ParameterType;\r\n                        }\r\n                        else\r\n                        {\r\n                            paramType = (i == 0) ? type : method.Parameters[i - 1].ParameterType;\r\n                        }\r\n                        if (paramType.IsValueType)\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(OpCodes.Box, paramType));\r\n                        }\r\n                    }\r\n                }\r\n\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, invoke));\r\n\r\n                if (!method.IsConstructor && !isFinalize)\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ret));\r\n                }\r\n\r\n                if (!method.IsConstructor)\r\n                {\r\n                    break;\r\n                }\r\n                else\r\n                {\r\n                    originToNewTarget[insertPoint] = firstInstruction;\r\n                    noCheck.Add(jmpInstruction);\r\n                }\r\n                insertPoint = findNextRet(method.Body.Instructions, insertPoint);\r\n            }\r\n\r\n            if (method.IsConstructor)\r\n            {\r\n                fixBranch(processor, method.Body.Instructions, originToNewTarget, noCheck);\r\n            }\r\n\r\n            if (isFinalize)\r\n            {\r\n                if (method.Body.ExceptionHandlers.Count == 0)\r\n                {\r\n                    throw new InvalidProgramException(\"Finalize has not try-catch? Type :\" + method.DeclaringType);\r\n                }\r\n                method.Body.ExceptionHandlers[0].TryStart = method.Body.Instructions[0];\r\n            }\r\n            if (isIntKey)\r\n            {\r\n                bridgeIndexByKey.Add(method);\r\n            }\r\n            return true;\r\n        }\r\n\r\n        bool injectGenericMethod(MethodDefinition method, HotfixFlagInTool hotfixType)\r\n        {\r\n            //如果注入的是xlua所在之外的Assembly的话，不支持该方式\r\n            if (!isTheSameAssembly)\r\n            {\r\n                return true;\r\n            }\r\n            var type = method.DeclaringType;\r\n            \r\n            bool isFinalize = (method.Name == \"Finalize\" && method.IsSpecialName);\r\n            bool isIntKey = hotfixType.HasFlag(HotfixFlagInTool.IntKey) && !type.HasGenericParameters;\r\n            //isIntKey = !type.HasGenericParameters;\r\n\r\n            FieldReference fieldReference = null;\r\n            VariableDefinition injection = null;\r\n            if (!isIntKey)\r\n            {\r\n                var luaDelegateName = getDelegateName(method);\r\n                if (luaDelegateName == null)\r\n                {\r\n                    Error(\"too many overload!\");\r\n                    return false;\r\n                }\r\n\r\n                FieldDefinition fieldDefinition = new FieldDefinition(luaDelegateName, Mono.Cecil.FieldAttributes.Static | Mono.Cecil.FieldAttributes.Private,\r\n                    delegateBridgeType);\r\n                type.Fields.Add(fieldDefinition);\r\n\r\n                fieldReference = fieldDefinition.GetGeneric();\r\n            }\r\n\r\n            injection = new VariableDefinition(delegateBridgeType);\r\n            method.Body.Variables.Add(injection);\r\n\r\n            int param_start = method.IsStatic ? 0 : 1;\r\n            int param_count = method.Parameters.Count + param_start;\r\n            var insertPoint = method.Body.Instructions[0];\r\n            var processor = method.Body.GetILProcessor();\r\n\r\n            if (method.IsConstructor)\r\n            {\r\n                insertPoint = findNextRet(method.Body.Instructions, insertPoint);\r\n            }\r\n\r\n            Dictionary<Instruction, Instruction> originToNewTarget = new Dictionary<Instruction, Instruction>();\r\n            HashSet<Instruction> noCheck = new HashSet<Instruction>();\r\n\r\n            while (insertPoint != null)\r\n            {\r\n                Instruction firstInstruction;\r\n                Instruction jmpInstruction;\r\n                if (isIntKey)\r\n                {\r\n                    firstInstruction = processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count);\r\n                    processor.InsertBefore(insertPoint, firstInstruction);\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, hotfixFlagGetter));\r\n                    jmpInstruction = processor.Create(OpCodes.Brfalse, insertPoint);\r\n                    processor.InsertBefore(insertPoint, jmpInstruction);\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, bridgeIndexByKey.Count));\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Call, delegateBridgeGetter));\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Stloc, injection));\r\n                }\r\n                else\r\n                {\r\n                    firstInstruction = processor.Create(OpCodes.Ldsfld, fieldReference);\r\n                    processor.InsertBefore(insertPoint, firstInstruction);\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Stloc, injection));\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                    jmpInstruction = processor.Create(OpCodes.Brfalse, insertPoint);\r\n                    processor.InsertBefore(insertPoint, jmpInstruction);\r\n                }\r\n\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, invokeSessionStart));\r\n\r\n                TypeReference returnType = method.ReturnType;\r\n\r\n                bool isVoid = returnType.FullName == \"System.Void\";\r\n\r\n                int outCout = 0;\r\n\r\n                for (int i = 0; i < param_count; i++)\r\n                {\r\n                    if (i == 0 && !method.IsStatic)\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg_0));\r\n                        if (type.IsValueType)\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldobj, method.DeclaringType.GetGeneric()));\r\n                        }\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, inParam.MakeGenericMethod(method.DeclaringType.GetGeneric())));\r\n                    }\r\n                    else\r\n                    {\r\n                        var param = method.Parameters[i - param_start];\r\n                        if (param.ParameterType.IsByReference)\r\n                        {\r\n                            outCout++;\r\n                        }\r\n                        if (!param.IsOut)\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n\r\n                            if (i < ldargs.Length)\r\n                            {\r\n                                processor.InsertBefore(insertPoint, processor.Create(ldargs[i]));\r\n                            }\r\n                            else if (i < 256)\r\n                            {\r\n                                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg_S, (byte)i));\r\n                            }\r\n                            else\r\n                            {\r\n                                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg, (short)i));\r\n                            }\r\n\r\n                            var paramType = param.ParameterType;\r\n\r\n                            if (param.ParameterType.IsByReference)\r\n                            {\r\n                                paramType = ((ByReferenceType)paramType).ElementType;\r\n                                if (paramType.IsValueType || paramType.IsGenericParameter)\r\n                                {\r\n                                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldobj, paramType));\r\n                                }\r\n                                else\r\n                                {\r\n                                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldind_Ref));\r\n                                }\r\n                            }\r\n                            if (i == param_count - 1 && param.CustomAttributes.Any(ca => ca.AttributeType.FullName == \"System.ParamArrayAttribute\"))\r\n                            {\r\n                                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, inParams.MakeGenericMethod(((ArrayType)paramType).ElementType)));\r\n                            }\r\n                            else\r\n                            {\r\n                                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, inParam.MakeGenericMethod(paramType)));\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n\r\n                int outStart = (isVoid ? 0 : 1);\r\n\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, outCout + outStart));\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, functionInvoke));\r\n\r\n                int outPos = outStart;\r\n                for (int i = 0; i < method.Parameters.Count; i++)\r\n                {\r\n                    if (method.Parameters[i].ParameterType.IsByReference)\r\n                    {\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldc_I4, outPos));\r\n                        int arg_pos = param_start + i;\r\n                        if (arg_pos < ldargs.Length)\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(ldargs[arg_pos]));\r\n                        }\r\n                        else if (arg_pos < 256)\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg_S, (byte)arg_pos));\r\n                        }\r\n                        else\r\n                        {\r\n                            processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldarg, (short)arg_pos));\r\n                        }\r\n                        processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, outParam.MakeGenericMethod(\r\n                            ((ByReferenceType)method.Parameters[i].ParameterType).ElementType)));\r\n                        outPos++;\r\n                    }\r\n                }\r\n\r\n                processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ldloc, injection));\r\n                if (isVoid)\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, invokeSessionEnd));\r\n                }\r\n                else\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Callvirt, invokeSessionEndWithResult.MakeGenericMethod(returnType)));\r\n                }\r\n\r\n                if (!method.IsConstructor && !isFinalize)\r\n                {\r\n                    processor.InsertBefore(insertPoint, processor.Create(OpCodes.Ret));\r\n                }\r\n\r\n                if (!method.IsConstructor)\r\n                {\r\n                    break;\r\n                }\r\n                else\r\n                {\r\n                    originToNewTarget[insertPoint] = firstInstruction;\r\n                    noCheck.Add(jmpInstruction);\r\n                }\r\n\r\n                insertPoint = findNextRet(method.Body.Instructions, insertPoint);\r\n            }\r\n\r\n            if (method.IsConstructor)\r\n            {\r\n                fixBranch(processor, method.Body.Instructions, originToNewTarget, noCheck);\r\n            }\r\n\r\n            if (isFinalize)\r\n            {\r\n                method.Body.ExceptionHandlers[0].TryStart = method.Body.Instructions[0];\r\n            }\r\n\r\n            if (isIntKey)\r\n            {\r\n                bridgeIndexByKey.Add(method);\r\n            }\r\n\r\n            return true;\r\n        }\r\n\r\n        public void OutputIntKeyMapper(Stream output)\r\n        {\r\n            using (StreamWriter writer = new StreamWriter(output))\r\n            {\r\n                writer.WriteLine(\"return {\");\r\n                var data = bridgeIndexByKey\r\n                    .Select((md, idx) => new { Method = md, Index = idx})\r\n                    .GroupBy(info => info.Method.DeclaringType)\r\n                    .ToDictionary(group => group.Key, group =>\r\n                    {\r\n                        return group.GroupBy(info => info.Method.Name).ToDictionary(group_by_name => group_by_name.Key, group_by_name => group_by_name.Select(info => info.Index.ToString()).ToArray());\r\n                    });\r\n                foreach(var kv in data)\r\n                {\r\n                    writer.WriteLine(\"    [\\\"\" + kv.Key.FullName.Replace('/', '+') + \"\\\"] = {\");\r\n                    foreach(var kv2 in kv.Value)\r\n                    {\r\n                        writer.WriteLine(\"        [\\\"\" + kv2.Key + \"\\\"] = {\");\r\n                        writer.WriteLine(\"            \" + string.Join(\",\", kv2.Value));\r\n                        writer.WriteLine(\"        },\");\r\n                    }\r\n                    writer.WriteLine(\"    },\");\r\n                }\r\n                writer.WriteLine(\"}\");\r\n            }\r\n        }\r\n    }\r\n}\r\n#else\r\n\r\nnamespace XLua\r\n{\r\n#if UNITY_2019_1_OR_NEWER\r\n    class MyCustomBuildProcessor : IPostBuildPlayerScriptDLLs\r\n    {\r\n        public int callbackOrder { get { return 0; } }\r\n        public void OnPostBuildPlayerScriptDLLs(BuildReport report)\r\n        {\r\n            var dir = Path.GetDirectoryName(report.files.Single(file => file.path.EndsWith(\"Assembly-CSharp.dll\")).path);\r\n            Hotfix.HotfixInject(dir);\r\n        }\r\n    }\r\n#endif\r\n\r\n    public static class Hotfix\r\n    {\r\n        static bool ContainNotAsciiChar(string s)\r\n        {\r\n            for (int i = 0; i < s.Length; ++i)\r\n            {\r\n                if (s[i] > 127)\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\r\n#if !UNITY_2019_1_OR_NEWER\r\n        [PostProcessScene]\r\n#endif\r\n        [MenuItem(\"XLua/Hotfix Inject In Editor\", false, 3)]\r\n        public static void HotfixInject()\r\n        {\r\n            HotfixInject(\"./Library/ScriptAssemblies\");\r\n        }\r\n\r\n        public static void HotfixInject(string assemblyDir)\r\n        {\r\n            if (Application.isPlaying)\r\n            {\r\n                return;\r\n            }\r\n\r\n            if (EditorApplication.isCompiling)\r\n            {\r\n                UnityEngine.Debug.LogError(\"You can't inject before the compilation is done\");\r\n                return;\r\n            }\r\n\r\n#if UNITY_EDITOR_OSX\r\n\t\t\tvar mono_path = Path.Combine(Path.GetDirectoryName(typeof(UnityEngine.Debug).Module.FullyQualifiedName),\r\n\t\t\t\t\"../MonoBleedingEdge/bin/mono\");\r\n\t\t\tif(!File.Exists(mono_path))\r\n\t\t\t{\r\n\t\t\t\tmono_path = Path.Combine(Path.GetDirectoryName(typeof(UnityEngine.Debug).Module.FullyQualifiedName),\r\n\t\t\t\t\t\"../../MonoBleedingEdge/bin/mono\");\r\n\t\t\t}\r\n\t\t\tif(!File.Exists(mono_path))\r\n\t\t\t{\r\n\t\t\t\tUnityEngine.Debug.LogError(\"can not find mono!\");\r\n\t\t\t}\r\n#elif UNITY_EDITOR_WIN\r\n            var mono_path = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),\r\n                \"Data/MonoBleedingEdge/bin/mono.exe\");\r\n#endif\r\n            var inject_tool_path = \"./Tools/XLuaHotfixInject.exe\";\r\n            if (!File.Exists(inject_tool_path))\r\n            {\r\n                UnityEngine.Debug.LogError(\"please install the Tools\");\r\n                return;\r\n            }\r\n\r\n            var assembly_csharp_path = Path.Combine(assemblyDir, \"Assembly-CSharp.dll\");\r\n            var id_map_file_path = CSObjectWrapEditor.GeneratorConfig.common_path + \"Resources/hotfix_id_map.lua.txt\";\r\n            var hotfix_cfg_in_editor = CSObjectWrapEditor.GeneratorConfig.common_path + \"hotfix_cfg_in_editor.data\";\r\n\r\n            Dictionary<string, int> editor_cfg = new Dictionary<string, int>();\r\n            Assembly editor_assembly = typeof(Hotfix).Assembly;\r\n            HotfixConfig.GetConfig(editor_cfg, Utils.GetAllTypes().Where(t => t.Assembly == editor_assembly));\r\n\r\n            if (!Directory.Exists(CSObjectWrapEditor.GeneratorConfig.common_path))\r\n            {\r\n                Directory.CreateDirectory(CSObjectWrapEditor.GeneratorConfig.common_path);\r\n            }\r\n\r\n            using (BinaryWriter writer = new BinaryWriter(new FileStream(hotfix_cfg_in_editor, FileMode.Create, FileAccess.Write)))\r\n            {\r\n                writer.Write(editor_cfg.Count);\r\n                foreach (var kv in editor_cfg)\r\n                {\r\n                    writer.Write(kv.Key);\r\n                    writer.Write(kv.Value);\r\n                }\r\n            }\r\n\r\n#if UNITY_2019_1_OR_NEWER\r\n            List<string> args = new List<string>() { assembly_csharp_path, assembly_csharp_path, id_map_file_path, hotfix_cfg_in_editor };\r\n#else\r\n            List<string> args = new List<string>() { assembly_csharp_path, typeof(LuaEnv).Module.FullyQualifiedName, id_map_file_path, hotfix_cfg_in_editor };\r\n#endif\r\n\r\n            foreach (var path in\r\n                (from asm in AppDomain.CurrentDomain.GetAssemblies() select asm.ManifestModule.FullyQualifiedName)\r\n                 .Distinct())\r\n            {\r\n                try\r\n                {\r\n                    args.Add(System.IO.Path.GetDirectoryName(path));\r\n                }\r\n                catch (Exception)\r\n                {\r\n\r\n                }\r\n            }\r\n            var injectAssemblyPaths = HotfixConfig.GetHotfixAssemblyPaths();\r\n            var idMapFileNames = new List<string>();\r\n            foreach (var injectAssemblyPath in injectAssemblyPaths)\r\n            {\r\n                args[0] = Path.Combine(assemblyDir, Path.GetFileName(injectAssemblyPath));\r\n                if (ContainNotAsciiChar(args[0]))\r\n                {\r\n                    throw new Exception(\"project path must contain only ascii characters\");\r\n                }\r\n\r\n                if (injectAssemblyPaths.Count > 1)\r\n                {\r\n                    var injectAssemblyFileName = Path.GetFileName(injectAssemblyPath);\r\n                    args[2] = CSObjectWrapEditor.GeneratorConfig.common_path + \"Resources/hotfix_id_map_\" + injectAssemblyFileName.Substring(0, injectAssemblyFileName.Length - 4) + \".lua.txt\";\r\n                    idMapFileNames.Add(args[2]);\r\n                }\r\n                Process hotfix_injection = new Process();\r\n                hotfix_injection.StartInfo.FileName = mono_path;\r\n#if UNITY_5_6_OR_NEWER\r\n                hotfix_injection.StartInfo.Arguments = \"--runtime=v4.0.30319 \" + inject_tool_path + \" \\\"\" + String.Join(\"\\\" \\\"\", args.ToArray()) + \"\\\"\";\r\n#else\r\n                hotfix_injection.StartInfo.Arguments = inject_tool_path + \" \\\"\" + String.Join(\"\\\" \\\"\", args.ToArray()) + \"\\\"\";\r\n#endif\r\n                hotfix_injection.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;\r\n                hotfix_injection.StartInfo.RedirectStandardOutput = true;\r\n                hotfix_injection.StartInfo.UseShellExecute = false;\r\n                hotfix_injection.StartInfo.CreateNoWindow = true;\r\n                hotfix_injection.Start();\r\n                UnityEngine.Debug.Log(hotfix_injection.StandardOutput.ReadToEnd());\r\n                hotfix_injection.WaitForExit();\r\n            }\r\n\r\n            File.Delete(hotfix_cfg_in_editor);\r\n            AssetDatabase.Refresh();\r\n        }\r\n    }\r\n}\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Hotfix.cs.meta",
    "content": "fileFormatVersion: 2\nguid: f9f175d9e85601f4da903e391b8b7c77\ntimeCreated: 1482299911\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs",
    "content": "﻿using UnityEngine;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System.IO;\r\nusing System.Text;\r\nusing System.Linq;\r\nusing CSObjectWrapEditor;\r\n\r\npublic class LinkXmlGen : ScriptableObject\r\n{\r\n    public TextAsset Template;\r\n\r\n    public static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg)\r\n    {\r\n        LuaTable data = lua_env.NewTable();\r\n        var assembly_infos = (from type in (user_cfg.ReflectionUse.Concat(user_cfg.LuaCallCSharp))\r\n                              group type by type.Assembly.GetName().Name into assembly_info\r\n                              select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList();\r\n        data.Set(\"assembly_infos\", assembly_infos);\r\n\r\n        yield return new CustomGenTask\r\n        {\r\n            Data = data,\r\n            Output = new StreamWriter(GeneratorConfig.common_path + \"/link.xml\",\r\n            false, Encoding.UTF8)\r\n        };\r\n    }\r\n\r\n    [GenCodeMenu]//加到Generate Code菜单里头\r\n    public static void GenLinkXml()\r\n    {\r\n        Generator.CustomGen(ScriptableObject.CreateInstance<LinkXmlGen>().Template.text, GetTasks);\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 5fa8c6bd6daed854c98654418f48a830\ntimeCreated: 1482482561\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences:\n  - Template: {fileID: 4900000, guid: 384feb229d259f549bbbac9e910b782b, type: 3}\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt",
    "content": "<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\n<linker>\r\n<%ForEachCsList(assembly_infos, function(assembly_info)%>\r\n\t<assembly fullname=\"<%=assembly_info.FullName%>\">\r\n\t    <%ForEachCsList(assembly_info.Types, function(type)\r\n\t\t%><type fullname=\"<%=type:ToString()%>\" preserve=\"all\"/>\r\n\t\t<%end)%>\r\n\t</assembly>\r\n<%end)%>\r\n</linker>"
  },
  {
    "path": "Assets/XLua/Src/Editor/LinkXmlGen/LinkXmlGen.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 384feb229d259f549bbbac9e910b782b\ntimeCreated: 1481621844\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/LinkXmlGen.meta",
    "content": "fileFormatVersion: 2\nguid: 9f94464b9267f9b4cbf2f98681e22880\nfolderAsset: yes\ntimeCreated: 1479105499\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Report.cs",
    "content": "#if UNITY_5_6_OR_NEWER\n\nnamespace XLua\n{\n    using UnityEngine;\n    using UnityEditor;\n    using System.Net.Sockets;\n    using System.Text;\n    using System.Threading;\n\n    [InitializeOnLoad]\n    public class Report\n    {\n        private const string PREFS_KEY = \"XLuaReport\";\n        private const string DIALOG_MSG_FORMAT = @\"Ƿǳע˽ȨҪռ±ҪϢṩõķ\n\nXLua汾{0}\n汾{1}\n豸ʶ{2}\n\nWe attach great importance to your privacy and need to collect the following necessary information to provide better services:\n\nXLua Version: {0}\nUnity Version: {1}\nDevice Identifier: {2}\";\n\n        static Report()\n        {\n            if (EditorPrefs.HasKey(PREFS_KEY) && !EditorPrefs.GetBool(PREFS_KEY))\n                return;\n\n            var version = \"2.1.16\";\n            var engine = Application.unityVersion;\n            var machine = SystemInfo.deviceUniqueIdentifier;\n            var msg = string.Format(\"cmd=0&tag=glcoud.xlua.report&version={0}&engine={1}&machine_name={2}\", version, engine, machine);\n\n            if (!EditorPrefs.HasKey(PREFS_KEY))\n            {\n                var dialogMsg = string.Format(DIALOG_MSG_FORMAT, version, engine, machine);\n                var result = EditorUtility.DisplayDialog(string.Empty, dialogMsg, \" Allow\", \"ܾ Deny\");\n                EditorPrefs.SetBool(PREFS_KEY, result);\n                if (!result)\n                    return;\n            }\n\n            new Thread(() =>\n            {\n                var data = Encoding.UTF8.GetBytes(msg);\n                var client = new UdpClient();\n                client.Send(data, data.Length, \"101.226.141.148\", 8080);\n                client.Close();\n            }).Start();\n        }\n    }\n}\n\n#endif\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Report.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1a3eea7e2e9e8e94ca50f9b792bc9416\nMonoImporter:\n  externalObjects: {}\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>\r\n<%\r\nrequire \"TemplateCommon\"\r\n\r\nlocal OpNameMap = {\r\n    op_Addition = \"__AddMeta\",\r\n\top_Subtraction = \"__SubMeta\",\r\n\top_Multiply = \"__MulMeta\",\r\n\top_Division = \"__DivMeta\",\r\n\top_Equality = \"__EqMeta\",\r\n\top_UnaryNegation = \"__UnmMeta\",\r\n\top_LessThan = \"__LTMeta\",\r\n\top_LessThanOrEqual = \"__LEMeta\",\r\n\top_Modulus = \"__ModMeta\",\r\n    op_BitwiseAnd = \"__BandMeta\",\r\n    op_BitwiseOr = \"__BorMeta\",\r\n    op_ExclusiveOr = \"__BxorMeta\",\r\n    op_OnesComplement = \"__BnotMeta\",\r\n    op_LeftShift = \"__ShlMeta\",\r\n    op_RightShift = \"__ShrMeta\",\r\n}\r\n\r\nlocal OpCallNameMap = {\r\n    op_Addition = \"+\",\r\n\top_Subtraction = \"-\",\r\n\top_Multiply = \"*\",\r\n\top_Division = \"/\",\r\n\top_Equality = \"==\",\r\n\top_UnaryNegation = \"-\",\r\n\top_LessThan = \"<\",\r\n\top_LessThanOrEqual = \"<=\",\r\n\top_Modulus = \"%\",\r\n\top_BitwiseAnd = \"&\",\r\n    op_BitwiseOr = \"|\",\r\n    op_ExclusiveOr = \"^\",\r\n    op_OnesComplement = \"~\",\r\n    op_LeftShift = \"<<\",\r\n    op_RightShift = \">>\",\r\n}\r\n\r\nlocal obj_method_count = 0\r\nlocal obj_getter_count = 0\r\nlocal obj_setter_count = 0\r\nlocal meta_func_count = operators.Count\r\nlocal cls_field_count = 1\r\nlocal cls_getter_count = 0\r\nlocal cls_setter_count = 0\r\n\r\nForEachCsList(methods, function(method)\r\n    if method.IsStatic then\r\n\t    cls_field_count = cls_field_count + 1\r\n\telse\r\n\t    obj_method_count = obj_method_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(events, function(event)\r\n    if event.IsStatic then\r\n\t    cls_field_count = cls_field_count + 1\r\n\telse\r\n\t    obj_method_count = obj_method_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(getters, function(getter)\r\n    if getter.IsStatic then\r\n\t    if getter.ReadOnly then\r\n\t        cls_field_count = cls_field_count + 1\r\n\t    else\r\n\t\t    cls_getter_count = cls_getter_count + 1\r\n\t\tend\r\n\telse\r\n\t    obj_getter_count = obj_getter_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(setters, function(setter)\r\n    if setter.IsStatic then\r\n\t    cls_setter_count = cls_setter_count + 1\r\n\telse\r\n\t    obj_setter_count = obj_setter_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(lazymembers, function(lazymember)\r\n    if lazymember.IsStatic == 'true' then\r\n\t    if 'CLS_IDX' == lazymember.Index then\r\n\t\t    cls_field_count = cls_field_count + 1\r\n\t    elseif 'CLS_GETTER_IDX' == lazymember.Index then\r\n\t\t    cls_getter_count = cls_getter_count + 1\r\n\t\telseif 'CLS_SETTER_IDX' == lazymember.Index then\r\n\t\t    cls_setter_count = cls_setter_count + 1\r\n\t\tend\r\n\telse\r\n\t\tif 'METHOD_IDX' == lazymember.Index then\r\n\t\t    obj_method_count = obj_method_count + 1\r\n\t    elseif 'GETTER_IDX' == lazymember.Index then\r\n\t\t    obj_getter_count = obj_getter_count + 1\r\n\t\telseif 'SETTER_IDX' == lazymember.Index then\r\n\t\t    obj_setter_count = obj_setter_count + 1\r\n\t\tend\r\n\tend\r\nend)\r\n\r\nlocal generic_arg_list, type_constraints = GenericArgumentList(type)\r\n\r\n%>\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    using Utils = XLua.Utils;\r\n    public class <%=CSVariableName(type)%>Wrap<%=generic_arg_list%> <%=type_constraints%>\r\n    {\r\n        public static void __Register(RealStatePtr L)\r\n        {\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\tSystem.Type type = typeof(<%=CsFullTypeName(type)%>);\r\n\t\t\tUtils.BeginObjectRegister(type, L, translator, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);\r\n\t\t\t<%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, \"<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>\", <%=OpNameMap[operator.Name]%>);\r\n            <%end)%>\r\n\t\t\t<%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, \"<%=method.Name%>\", _m_<%=method.Name%>);\r\n\t\t\t<% end end)%>\r\n\t\t\t<%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, \"<%=event.Name%>\", _e_<%=event.Name%>);\r\n\t\t\t<% end end)%>\r\n\t\t\t<%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, \"<%=getter.Name%>\", _g_get_<%=getter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, \"<%=setter.Name%>\", _s_set_<%=setter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, \"<%=lazymember.Name%>\", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);\r\n            <%end end)%>\r\n\t\t\tUtils.EndObjectRegister(type, L, translator, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%else%>null<%end%>,\r\n\t\t\t    null, null, null);\r\n\r\n\t\t    Utils.BeginClassRegister(type, L, __CreateInstance, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);\r\n\t\t\t<%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, \"<%=method.Overloads[0].Name%>\", _m_<%=method.Name%>);\r\n            <% end end)%>\r\n\t\t\t<%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, \"<%=event.Name%>\", _e_<%=event.Name%>);\r\n\t\t\t<% end end)%>\r\n            <%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, translator, Utils.CLS_IDX, \"<%=getter.Name%>\", <%=CsFullTypeName(type)..\".\"..getter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, \"<%=getter.Name%>\", _g_get_<%=getter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, \"<%=setter.Name%>\", _s_set_<%=setter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, \"<%=lazymember.Name%>\", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);\r\n            <%end end)%>\r\n\t\t\tUtils.EndClassRegister(type, L, translator);\r\n        }\r\n        \r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int __CreateInstance(RealStatePtr L)\r\n        {\r\n            <% \r\n            if constructors.Count == 0 and (not type.IsValueType)  then \r\n            %>return LuaAPI.luaL_error(L, \"<%=CsFullTypeName(type)%> does not have a constructor!\");<% \r\n            else %>\r\n\t\t\ttry {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t<% \r\n\t\t\t\tlocal hasZeroParamsCtor = false\r\n\t\t\t\tForEachCsList(constructors, function(constructor, ci)\r\n\t\t\t\t\tlocal parameters = constructor:GetParameters()\r\n\t\t\t\t\tif parameters.Length == 0 then\r\n\t\t\t\t\t    hasZeroParamsCtor = true\r\n\t\t\t\t\tend\r\n\t\t\t\t\tlocal def_count = constructor_def_vals[ci]\r\n\t\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\t\tlocal in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n                    local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n\t\t\t\t\tlocal real_param_count = param_count - def_count\r\n                    local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\t\t\t\t\tlocal in_pos = 0\r\n\t\t\t\t%>if(LuaAPI.lua_gettop(L) <%=has_v_params and \">=\" or \"==\"%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi) \r\n                if pi >= real_param_count then return end \r\n                local parameterType = parameter.ParameterType\r\n                if has_v_params and pi == param_count - 1 then  parameterType = parameterType:GetElementType() end\r\n\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1\r\n                %> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><% \r\n\t\t\t\tend\r\n\t\t\t\tend)%>)\r\n\t\t\t\t{\r\n\t\t\t\t\t<%ForEachCsList(parameters, function(parameter, pi) \r\n                    if pi >= real_param_count then return end \r\n                    %><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t\t<%end)%>\r\n\t\t\t\t\tvar gen_ret = new <%=CsFullTypeName(type)%>(<%ForEachCsList(parameters, function(parameter, pi) if pi >= real_param_count then return end; if pi ~=0 then %><%=', '%><% end ;if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end)%>);\r\n\t\t\t\t\t<%=GetPushStatement(type, \"gen_ret\")%>;\r\n                    <%local in_pos = 0\r\n                    ForEachCsList(parameters, function(parameter, pi)\r\n                        if pi >= real_param_count then return end\r\n                        if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                            in_pos = in_pos + 1\r\n                        end\r\n                        if parameter.ParameterType.IsByRef then\r\n                        %><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;\r\n                        <%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then \r\n                  %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;\r\n                        <%end%>\r\n                    <%\r\n                        end\r\n                    end)\r\n                    %>\r\n\t\t\t\t\treturn <%=out_num + 1%>;\r\n\t\t\t\t}\r\n\t\t\t\t<%end)\r\n\t\t\t\tif (not hasZeroParamsCtor) and type.IsValueType then\r\n\t\t\t\t%>\r\n\t\t\t\tif (LuaAPI.lua_gettop(L) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t    <%=GetPushStatement(type, \"default(\" .. CsFullTypeName(type).. \")\")%>;\r\n\t\t\t        return 1;\r\n\t\t\t\t}\r\n\t\t\t\t<%end%>\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%> constructor!\");\r\n            <% end %>\r\n        }\r\n        \r\n\t\t<% if type.IsArray or ((indexers.Count or 0) > 0) then %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        public static int __CSIndexer(RealStatePtr L)\r\n        {\r\n\t\t\t<%if type.IsArray then %>\r\n\t\t\ttry {\r\n\t\t\t    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\r\n\t\t\t\tif (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))\r\n\t\t\t\t{\r\n\t\t\t\t\tint index = (int)LuaAPI.lua_tonumber(L, 2);\r\n\t\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t\t<%=GetPushStatement(type:GetElementType(), \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\t\treturn 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n\t\t\t<%elseif indexers.Count > 0 then\r\n\t\t\t%>try {\r\n\t\t\t    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t<%\r\n\t\t\t\t\tForEachCsList(indexers, function(indexer)\r\n\t\t\t\t\t\tlocal paramter = indexer:GetParameters()[0]\r\n\t\t\t\t%>\r\n\t\t\t\tif (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)\r\n\t\t\t\t{\r\n\t\t\t\t\t\r\n\t\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(paramter.ParameterType, 2, \"index\", true)%>;\r\n\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t\t<%=GetPushStatement(indexer.ReturnType, \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\t\treturn 2;\r\n\t\t\t\t}\r\n\t\t\t\t<%end)%>\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n\t\t\t<%end%>\r\n            LuaAPI.lua_pushboolean(L, false);\r\n\t\t\treturn 1;\r\n        }\r\n\t\t<% end %>\r\n        \r\n\t\t<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        public static int __NewIndexer(RealStatePtr L)\r\n        {\r\n\t\t\t<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>\r\n\t\t\t<%if type.IsArray then \r\n\t\t\t\tlocal elementType = type:GetElementType()\r\n\t\t\t%>\r\n\t\t\ttry {\r\n\t\t\t\tif (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)\r\n\t\t\t\t{\r\n\t\t\t\t\tint index = (int)LuaAPI.lua_tonumber(L, 2);\r\n\t\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(elementType, 3, \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n\t\t\t<%elseif newindexers.Count > 0 then%>\r\n\t\t\ttry {\r\n\t\t\t\t<%ForEachCsList(newindexers, function(newindexer)\r\n\t\t\t\t\t\tlocal keyType = newindexer:GetParameters()[0].ParameterType\r\n\t\t\t\t\t\tlocal valueType = newindexer:GetParameters()[1].ParameterType\r\n\t\t\t\t%>\r\n\t\t\t\tif (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)\r\n\t\t\t\t{\r\n\t\t\t\t\t\r\n\t\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t\t<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, \"gen_value\", true)%>;\r\n\t\t\t\t\tgen_to_be_invoked[key] = gen_value;<%else\r\n                  %><%=GetCasterStatement(valueType, 3, \"gen_to_be_invoked[key]\")%>;<%end%>\r\n\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t\t<%end)%>\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n\t\t\t<%end%>\r\n\t\t\tLuaAPI.lua_pushboolean(L, false);\r\n            return 1;\r\n        }\r\n\t\t<% end %>\r\n        \r\n        <%ForEachCsList(operators, function(operator) %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int <%=OpNameMap[operator.Name]%>(RealStatePtr L)\r\n        {\r\n            <% if operator.Name ~= \"op_UnaryNegation\" and operator.Name ~= \"op_OnesComplement\"  then %>\r\n\t\t\ttry {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n            <%ForEachCsList(operator.Overloads, function(overload)\r\n                local left_param = overload:GetParameters()[0]\r\n                local right_param = overload:GetParameters()[1]\r\n            %>\r\n\t\t\t\r\n\t\t\t\tif (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)\r\n\t\t\t\t{\r\n\t\t\t\t\t<%=GetCasterStatement(left_param.ParameterType, 1, \"leftside\", true)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(right_param.ParameterType, 2, \"rightside\", true)%>;\r\n\t\t\t\t\t\r\n\t\t\t\t\t<%=GetPushStatement(overload.ReturnType, \"leftside \" .. OpCallNameMap[operator.Name] .. \" rightside\")%>;\r\n\t\t\t\t\t\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n            <%end)%>\r\n\t\t\t}\r\n\t\t\tcatch(System.Exception gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n\t\t\t}\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!\");\r\n            <%else%>\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n            try {\r\n                <%=GetCasterStatement(type, 1, \"rightside\", true)%>;\r\n                <%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. \" rightside\")%>;\r\n            } catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n            return 1;\r\n            <%end%>\r\n        }\r\n        <%end)%>\r\n        \r\n        <%ForEachCsList(methods, function(method)%>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int _m_<%=method.Name%>(RealStatePtr L)\r\n        {\r\n\t\t    try {\r\n            <%\r\n            local need_obj = not method.IsStatic\r\n            if MethodCallNeedTranslator(method) then\r\n            %>\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n            <%end%>\r\n            <%if need_obj then%>\r\n                <%=GetSelfStatement(type)%>;\r\n            <%end%>\r\n            <%if method.Overloads.Count > 1 then%>\r\n\t\t\t    int gen_param_count = LuaAPI.lua_gettop(L);\r\n            <%end%>\r\n                <%ForEachCsList(method.Overloads, function(overload, oi)\r\n                local parameters = MethodParameters(overload)\r\n                local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n                local param_offset = method.IsStatic and 0 or 1\r\n                local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n                local in_pos = 0\r\n                local has_return = (overload.ReturnType.FullName ~= \"System.Void\")\r\n                local def_count = method.DefaultValues[oi]\r\n\t\t\t\tlocal param_count = parameters.Length\r\n                local real_param_count = param_count - def_count\r\n                local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n                if method.Overloads.Count > 1 then\r\n                %>if(gen_param_count <%=has_v_params and \">=\" or \"==\"%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%\r\n                    ForEachCsList(parameters, function(parameter, pi)\r\n                        if pi >= real_param_count then return end\r\n                        local parameterType = parameter.ParameterType\r\n                        if has_v_params and pi == param_count - 1 then  parameterType = parameterType:GetElementType() end\r\n                        if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1; \r\n                        %>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><% \r\n                        end \r\n                    end)%>) <%end%>\r\n                {\r\n                    <%if overload.Name == \"get_Item\" and overload.IsSpecialName then\r\n\t\t\t\t\t    local keyType = overload:GetParameters()[0].ParameterType%>\r\n\t\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t\t<%=GetPushStatement(overload.ReturnType, \"gen_to_be_invoked[key]\")%>;\r\n\t\t\t\t\t<%elseif overload.Name == \"set_Item\" and overload.IsSpecialName then\r\n\t\t\t\t\t    local keyType = overload:GetParameters()[0].ParameterType\r\n\t\t\t\t\t\tlocal valueType = overload:GetParameters()[1].ParameterType%>\r\n\t\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(valueType, 3, \"gen_value\", true)%>;\r\n                    gen_to_be_invoked[key] = gen_value;\r\n                    <% else\r\n                    in_pos = 0;\r\n                    ForEachCsList(parameters, function(parameter, pi) \r\n                        if pi >= real_param_count then return end\r\n                        %><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                            in_pos = in_pos + 1\r\n                        %><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%\r\n\t\t\t\t\t    else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;\r\n                    <%end)%>\r\n                    <%\r\n                    if has_return then\r\n                        %>    var gen_ret = <%\r\n                    end\r\n                    %><%if method.IsStatic then\r\n                    %><%=CsFullTypeName(type)..\".\"..UnK(overload.Name)%><%\r\n                    else\r\n                    %>gen_to_be_invoked.<%=UnK(overload.Name)%><%\r\n                    end%>( <%ForEachCsList(parameters, function(parameter, pi) \r\n                        if pi >= real_param_count then return end\r\n                        if pi ~= 0 then %>, <% end; if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end) %> );\r\n                    <%\r\n                    if has_return then\r\n                    %>    <%=GetPushStatement(overload.ReturnType, \"gen_ret\")%>;\r\n                    <%\r\n                    end\r\n                    local in_pos = 0\r\n                    ForEachCsList(parameters, function(parameter, pi)\r\n                        if pi >= real_param_count then return end\r\n                        if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                            in_pos = in_pos + 1\r\n                        end\r\n                        if parameter.ParameterType.IsByRef then\r\n                        %><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;\r\n                        <%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then \r\n                  %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;\r\n                        <%end%>\r\n                    <%\r\n                        end\r\n                    end)\r\n\t\t\t\t\tend\r\n                    %>\r\n                    <%if NeedUpdate(type) and not method.IsStatic then%>\r\n                        <%=GetUpdateStatement(type, 1, \"gen_to_be_invoked\")%>;\r\n                    <%end%>\r\n                    \r\n                    return <%=out_num+(has_return and 1 or 0)%>;\r\n                }\r\n                <% end)%>\r\n            } catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n            <%if method.Overloads.Count > 1 then%>\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!\");\r\n            <%end%>\r\n        }\r\n        <% end)%>\r\n        \r\n        \r\n        <%ForEachCsList(getters, function(getter) \r\n        if getter.IsStatic and getter.ReadOnly then return end --readonly static\r\n        %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int _g_get_<%=getter.Name%>(RealStatePtr L)\r\n        {\r\n\t\t    try {\r\n            <%if AccessorNeedTranslator(getter) then %>    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>\r\n\t\t\t<%if not getter.IsStatic then%>\r\n                <%=GetSelfStatement(type)%>;\r\n                <%=GetPushStatement(getter.Type, \"gen_to_be_invoked.\"..UnK(getter.Name))%>;<% else %>    <%=GetPushStatement(getter.Type, CsFullTypeName(type)..\".\"..UnK(getter.Name))%>;<% end%>\r\n            } catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n            return 1;\r\n        }\r\n        <%end)%>\r\n        \r\n        <%ForEachCsList(setters, function(setter)\r\n        local is_struct = IsStruct(setter.Type)\r\n        %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int _s_set_<%=setter.Name%>(RealStatePtr L)\r\n        {\r\n\t\t    try {\r\n                <%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>\r\n\t\t\t<%if not setter.IsStatic then %>\r\n                <%=GetSelfStatement(type)%>;\r\n                <%if is_struct then %><%=GetCasterStatement(setter.Type, 2, \"gen_value\", true)%>;\r\n\t\t\t\tgen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else \r\n              %><%=GetCasterStatement(setter.Type, 2, \"gen_to_be_invoked.\" .. UnK(setter.Name))%>;<%end\r\n            else \r\n\t\t\t\tif is_struct then %><%=GetCasterStatement(setter.Type, 1, \"gen_value\", true)%>;\r\n\t\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else\r\n          %>    <%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) ..\".\" .. UnK(setter.Name))%>;<%end\r\n            end%>\r\n            <%if NeedUpdate(type) and not setter.IsStatic then%>\r\n                <%=GetUpdateStatement(type, 1, \"gen_to_be_invoked\")%>;\r\n            <%end%>\r\n            } catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n            return 0;\r\n        }\r\n        <%end)%>\r\n\t\t\r\n\t\t<%ForEachCsList(events, function(event) if not event.IsStatic then %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int _e_<%=event.Name%>(RealStatePtr L)\r\n        {\r\n\t\t    try {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t    int gen_param_count = LuaAPI.lua_gettop(L);\r\n\t\t\t<%=GetSelfStatement(type)%>;\r\n                <%=GetCasterStatement(event.Type, 3, \"gen_delegate\", true)%>;\r\n                if (gen_delegate == null) {\r\n                    return LuaAPI.luaL_error(L, \"#3 need <%=CsFullTypeName(event.Type)%>!\");\r\n                }\r\n\t\t\t\t\r\n\t\t\t\tif (gen_param_count == 3)\r\n\t\t\t\t{\r\n\t\t\t\t\t<%if event.CanAdd then%>\r\n\t\t\t\t\tif (LuaAPI.xlua_is_eq_str(L, 2, \"+\")) {\r\n\t\t\t\t\t\tgen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;\r\n\t\t\t\t\t\treturn 0;\r\n\t\t\t\t\t} \r\n\t\t\t\t\t<%end%>\r\n\t\t\t\t\t<%if event.CanRemove then%>\r\n\t\t\t\t\tif (LuaAPI.xlua_is_eq_str(L, 2, \"-\")) {\r\n\t\t\t\t\t\tgen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;\r\n\t\t\t\t\t\treturn 0;\r\n\t\t\t\t\t} \r\n\t\t\t\t\t<%end%>\r\n\t\t\t\t}\r\n\t\t\t} catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n\t\t\tLuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!\");\r\n            return 0;\r\n        }\r\n        <%end end)%>\r\n\t\t\r\n\t\t<%ForEachCsList(events, function(event) if event.IsStatic then %>\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int _e_<%=event.Name%>(RealStatePtr L)\r\n        {\r\n\t\t    try {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t    int gen_param_count = LuaAPI.lua_gettop(L);\r\n                <%=GetCasterStatement(event.Type, 2, \"gen_delegate\", true)%>;\r\n                if (gen_delegate == null) {\r\n                    return LuaAPI.luaL_error(L, \"#2 need <%=CsFullTypeName(event.Type)%>!\");\r\n                }\r\n                \r\n\t\t\t\t<%if event.CanAdd then%>\r\n\t\t\t\tif (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, \"+\")) {\r\n\t\t\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t} \r\n\t\t\t\t<%end%>\r\n\t\t\t\t<%if event.CanRemove then%>\r\n\t\t\t\tif (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, \"-\")) {\r\n\t\t\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t} \r\n\t\t\t\t<%end%>\r\n\t\t\t} catch(System.Exception gen_e) {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + gen_e);\r\n            }\r\n\t\t\treturn LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!\");\r\n        }\r\n        <%end end)%>\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaClassWrap.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 8503038eabbabe44dac0f5f749d4411a\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>\r\n<%\r\nrequire \"TemplateCommon\"\r\n\r\nlocal OpNameMap = {\r\n    op_Addition = \"__AddMeta\",\r\n\top_Subtraction = \"__SubMeta\",\r\n\top_Multiply = \"__MulMeta\",\r\n\top_Division = \"__DivMeta\",\r\n\top_Equality = \"__EqMeta\",\r\n\top_UnaryNegation = \"__UnmMeta\",\r\n\top_LessThan = \"__LTMeta\",\r\n\top_LessThanOrEqual = \"__LEMeta\",\r\n\top_Modulus = \"__ModMeta\",\r\n    op_BitwiseAnd = \"__BandMeta\",\r\n    op_BitwiseOr = \"__BorMeta\",\r\n    op_ExclusiveOr = \"__BxorMeta\",\r\n    op_OnesComplement = \"__BnotMeta\",\r\n    op_LeftShift = \"__ShlMeta\",\r\n    op_RightShift = \"__ShrMeta\",\r\n}\r\n\r\nlocal OpCallNameMap = {\r\n    op_Addition = \"+\",\r\n\top_Subtraction = \"-\",\r\n\top_Multiply = \"*\",\r\n\top_Division = \"/\",\r\n\top_Equality = \"==\",\r\n\top_UnaryNegation = \"-\",\r\n\top_LessThan = \"<\",\r\n\top_LessThanOrEqual = \"<=\",\r\n\top_Modulus = \"%\",\r\n\top_BitwiseAnd = \"&\",\r\n    op_BitwiseOr = \"|\",\r\n    op_ExclusiveOr = \"^\",\r\n    op_OnesComplement = \"~\",\r\n    op_LeftShift = \"<<\",\r\n    op_RightShift = \">>\",\r\n}\r\n\r\nlocal obj_method_count = 0\r\nlocal obj_getter_count = 0\r\nlocal obj_setter_count = 0\r\nlocal meta_func_count = operators.Count\r\nlocal cls_field_count = 1\r\nlocal cls_getter_count = 0\r\nlocal cls_setter_count = 0\r\n\r\nForEachCsList(methods, function(method)\r\n    if method.IsStatic then\r\n\t    cls_field_count = cls_field_count + 1\r\n\telse\r\n\t    obj_method_count = obj_method_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(events, function(event)\r\n    if event.IsStatic then\r\n\t    cls_field_count = cls_field_count + 1\r\n\telse\r\n\t    obj_method_count = obj_method_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(getters, function(getter)\r\n    if getter.IsStatic then\r\n\t    if getter.ReadOnly then\r\n\t        cls_field_count = cls_field_count + 1\r\n\t    else\r\n\t\t    cls_getter_count = cls_getter_count + 1\r\n\t\tend\r\n\telse\r\n\t    obj_getter_count = obj_getter_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(setters, function(setter)\r\n    if setter.IsStatic then\r\n\t    cls_setter_count = cls_setter_count + 1\r\n\telse\r\n\t    obj_setter_count = obj_setter_count + 1\r\n    end \r\nend)\r\n\r\nForEachCsList(lazymembers, function(lazymember)\r\n    if lazymember.IsStatic == 'true' then\r\n\t    if 'CLS_IDX' == lazymember.Index then\r\n\t\t    cls_field_count = cls_field_count + 1\r\n\t    elseif 'CLS_GETTER_IDX' == lazymember.Index then\r\n\t\t    cls_getter_count = cls_getter_count + 1\r\n\t\telseif 'CLS_SETTER_IDX' == lazymember.Index then\r\n\t\t    cls_setter_count = cls_setter_count + 1\r\n\t\tend\r\n\telse\r\n\t\tif 'METHOD_IDX' == lazymember.Index then\r\n\t\t    obj_method_count = obj_method_count + 1\r\n\t    elseif 'GETTER_IDX' == lazymember.Index then\r\n\t\t    obj_getter_count = obj_getter_count + 1\r\n\t\telseif 'SETTER_IDX' == lazymember.Index then\r\n\t\t    obj_setter_count = obj_setter_count + 1\r\n\t\tend\r\n\tend\r\nend)\r\n\r\nlocal v_type_name = CSVariableName(type)\r\nlocal generic_arg_list, type_constraints = GenericArgumentList(type)\r\n\r\n%>\r\nnamespace XLua\r\n{\r\n    public partial class ObjectTranslator\r\n    {\r\n        public void __Register<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L) <%=type_constraints%>\r\n        {\r\n\t\t    System.Type type = typeof(<%=CsFullTypeName(type)%>);\r\n\t\t\tUtils.BeginObjectRegister(type, L, this, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);\r\n\t\t\t<%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, \"<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>\", <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>);\r\n            <%end)%>\r\n\t\t\t<%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, \"<%=method.Name%>\", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);\r\n\t\t\t<% end end)%>\r\n\t\t\t<%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, \"<%=event.Name%>\", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);\r\n\t\t\t<% end end)%>\r\n\t\t\t<%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, \"<%=getter.Name%>\", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, \"<%=setter.Name%>\", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, \"<%=lazymember.Name%>\", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);\r\n            <%end end)%>\r\n\t\t\tUtils.EndObjectRegister(type, L, this, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>,\r\n\t\t\t    null, null, null);\r\n\r\n\t\t    Utils.BeginClassRegister(type, L, __CreateInstance<%=v_type_name%><%=generic_arg_list%>, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);\r\n\t\t\t<%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, \"<%=method.Overloads[0].Name%>\", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);\r\n            <% end end)%>\r\n\t\t\t<%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, \"<%=event.Name%>\", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);\r\n\t\t\t<% end end)%>\r\n            <%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, this, Utils.CLS_IDX, \"<%=getter.Name%>\", <%=CsFullTypeName(type)..\".\"..getter.Name%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, \"<%=getter.Name%>\", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, \"<%=setter.Name%>\", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);\r\n            <%end end)%>\r\n\t\t\t<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, \"<%=lazymember.Name%>\", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);\r\n            <%end end)%>\r\n\t\t\tUtils.EndClassRegister(type, L, this);\r\n        }\r\n        \r\n        int __CreateInstance<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            <% \r\n            if constructors.Count == 0 and (not type.IsValueType)  then \r\n            %>return LuaAPI.luaL_error(L, \"<%=CsFullTypeName(type)%> does not have a constructor!\");<% \r\n            else %>\r\n            ObjectTranslator translator = this;\r\n\t\t\t<% \r\n\t\t\tlocal hasZeroParamsCtor = false\r\n\t\t\tForEachCsList(constructors, function(constructor, ci)\r\n\t\t\t\tlocal parameters = constructor:GetParameters()\r\n\t\t\t\tif parameters.Length == 0 then\r\n\t\t\t\t\thasZeroParamsCtor = true\r\n\t\t\t\tend\r\n\t\t\t\tlocal def_count = constructor_def_vals[ci]\r\n\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\tlocal in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n\t\t\t\tlocal out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n\t\t\t\tlocal real_param_count = param_count - def_count\r\n\t\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\t\t\t\tlocal in_pos = 0\r\n\t\t\t%>if(gen_param_count <%=has_v_params and \">=\" or \"==\"%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi) \r\n\t\t\tif pi >= real_param_count then return end \r\n\t\t\tlocal parameterType = parameter.ParameterType\r\n\t\t\tif has_v_params and pi == param_count - 1 then  parameterType = parameterType:GetElementType() end\r\n\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1\r\n\t\t\t%> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><% \r\n\t\t\tend\r\n\t\t\tend)%>)\r\n\t\t\t{\r\n\t\t\t\t<%ForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\tif pi >= real_param_count then return end \r\n\t\t\t\t%><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t<%end)%>\r\n\t\t\t\tvar gen_ret = new <%=CsFullTypeName(type)%>(<%ForEachCsList(parameters, function(parameter, pi) if pi >= real_param_count then return end; if pi ~=0 then %><%=', '%><% end ;if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end)%>);\r\n\t\t\t\t<%=GetPushStatement(type, \"gen_ret\")%>;\r\n\t\t\t\t<%local in_pos = 0\r\n\t\t\t\tForEachCsList(parameters, function(parameter, pi)\r\n\t\t\t\t\tif pi >= real_param_count then return end\r\n\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\tin_pos = in_pos + 1\r\n\t\t\t\t\tend\r\n\t\t\t\t\tif parameter.ParameterType.IsByRef then\r\n\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;\r\n\t\t\t\t\t<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then \r\n\t\t\t  %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;\r\n\t\t\t\t\t<%end%>\r\n\t\t\t\t<%\r\n\t\t\t\t\tend\r\n\t\t\t\tend)\r\n\t\t\t\t%>\r\n\t\t\t\treturn <%=out_num + 1%>;\r\n\t\t\t}\r\n\t\t\t<%end)\r\n\t\t\tif (not hasZeroParamsCtor) and type.IsValueType then\r\n\t\t\t%>\r\n\t\t\tif (gen_param_count == 1)\r\n\t\t\t{\r\n\t\t\t\t<%=GetPushStatement(type, \"default(\" .. CsFullTypeName(type).. \")\")%>;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t<%end%>\r\n\t\t\t\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%> constructor!\");\r\n            <% end %>\r\n        }\r\n        \r\n\t\t<% if type.IsArray or ((indexers.Count or 0) > 0) then %>\r\n        int __CSIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n\t\t\t<%if type.IsArray then %>\r\n\t\t\tObjectTranslator translator = this;\r\n\t\t\tif (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))\r\n\t\t\t{\r\n\t\t\t\tint index = (int)LuaAPI.lua_tonumber(L, 2);\r\n\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t<%=GetPushStatement(type:GetElementType(), \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\treturn 2;\r\n\t\t\t}\r\n\t\t\t<%elseif indexers.Count > 0 then\r\n\t\t\t%>ObjectTranslator translator = this;\r\n\t\t\t<%\r\n\t\t\t\tForEachCsList(indexers, function(indexer)\r\n\t\t\t\t\tlocal paramter = indexer:GetParameters()[0]\r\n\t\t\t%>\r\n\t\t\tif (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t<%=GetCasterStatement(paramter.ParameterType, 2, \"index\", true)%>;\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t<%=GetPushStatement(indexer.ReturnType, \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\treturn 2;\r\n\t\t\t}\r\n\t\t\t<%end)\r\n\t\t\tend%>\r\n            LuaAPI.lua_pushboolean(L, false);\r\n\t\t\treturn 1;\r\n        }\r\n\t\t<% end %>\r\n        \r\n\t\t<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>\r\n        int __NewIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n\t\t\t<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = this;<%end%>\r\n\t\t\t<%if type.IsArray then \r\n\t\t\t\tlocal elementType = type:GetElementType()\r\n\t\t\t%>\r\n\t\t\tif (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)\r\n\t\t\t{\r\n\t\t\t\tint index = (int)LuaAPI.lua_tonumber(L, 2);\r\n\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t<%=GetCasterStatement(elementType, 3, \"gen_to_be_invoked[index]\")%>;\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t<%elseif newindexers.Count > 0 then%>\r\n\t\t\t<%ForEachCsList(newindexers, function(newindexer)\r\n\t\t\t\t\tlocal keyType = newindexer:GetParameters()[0].ParameterType\r\n\t\t\t\t\tlocal valueType = newindexer:GetParameters()[1].ParameterType\r\n\t\t\t%>\r\n\t\t\tif (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)\r\n\t\t\t{\r\n\t\t\t\t\r\n\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, \"gen_value\", true)%>;\r\n\t\t\t\tgen_to_be_invoked[key] = gen_value;<%else\r\n\t\t\t  %><%=GetCasterStatement(valueType, 3, \"gen_to_be_invoked[key]\")%>;<%end%>\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t<%end)\r\n\t\t\tend%>\r\n\t\t\tLuaAPI.lua_pushboolean(L, false);\r\n            return 1;\r\n        }\r\n\t\t<% end %>\r\n        \r\n        <%ForEachCsList(operators, function(operator) %>\r\n        int <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            ObjectTranslator translator = this;\r\n            <% if operator.Name ~= \"op_UnaryNegation\" and operator.Name ~= \"op_OnesComplement\"  then \r\n                ForEachCsList(operator.Overloads, function(overload)\r\n                local left_param = overload:GetParameters()[0]\r\n                local right_param = overload:GetParameters()[1]\r\n            %>\r\n\t\t\tif (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)\r\n\t\t\t{\r\n\t\t\t\t<%=GetCasterStatement(left_param.ParameterType, 1, \"leftside\", true)%>;\r\n\t\t\t\t<%=GetCasterStatement(right_param.ParameterType, 2, \"rightside\", true)%>;\r\n\t\t\t\t\r\n\t\t\t\t<%=GetPushStatement(overload.ReturnType, \"leftside \" .. OpCallNameMap[operator.Name] .. \" rightside\")%>;\r\n\t\t\t\t\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n            <%end)%>\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!\");\r\n            <%else%>\r\n\t\t\t<%=GetCasterStatement(type, 1, \"rightside\", true)%>;\r\n\t\t\t<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. \" rightside\")%>;\r\n            return 1;\r\n            <%end%>\r\n        }\r\n        <%end)%>\r\n        \r\n        <%ForEachCsList(methods, function(method)%>\r\n        int <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            <%\r\n            local need_obj = not method.IsStatic\r\n            if MethodCallNeedTranslator(method) then\r\n            %>\r\n            ObjectTranslator translator = this;\r\n            <%end%>\r\n            <%if need_obj then%>\r\n            <%=GetSelfStatement(type)%>;\r\n            <%end%>\r\n\t\t\t<%ForEachCsList(method.Overloads, function(overload, oi)\r\n\t\t\tlocal parameters = MethodParameters(overload)\r\n\t\t\tlocal in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n\t\t\tlocal param_offset = method.IsStatic and 0 or 1\r\n\t\t\tlocal out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n\t\t\tlocal in_pos = 0\r\n\t\t\tlocal has_return = (overload.ReturnType.FullName ~= \"System.Void\")\r\n\t\t\tlocal def_count = method.DefaultValues[oi]\r\n\t\t\tlocal param_count = parameters.Length\r\n\t\t\tlocal real_param_count = param_count - def_count\r\n\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\t\t\tif method.Overloads.Count > 1 then\r\n\t\t\t%>if(gen_param_count <%=has_v_params and \">=\" or \"==\"%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%\r\n\t\t\t\tForEachCsList(parameters, function(parameter, pi)\r\n\t\t\t\t\tif pi >= real_param_count then return end\r\n\t\t\t\t\tlocal parameterType = parameter.ParameterType\r\n\t\t\t\t\tif has_v_params and pi == param_count - 1 then  parameterType = parameterType:GetElementType() end\r\n\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1; \r\n\t\t\t\t\t%>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><% \r\n\t\t\t\t\tend \r\n\t\t\t\tend)%>) <%end%>\r\n\t\t\t{\r\n\t\t\t\t<%if overload.Name == \"get_Item\" and overload.IsSpecialName then\r\n\t\t\t\t\tlocal keyType = overload:GetParameters()[0].ParameterType%>\r\n\t\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t\t<%=GetPushStatement(overload.ReturnType, \"gen_to_be_invoked[key]\")%>;\r\n\t\t\t\t<%elseif overload.Name == \"set_Item\" and overload.IsSpecialName then\r\n\t\t\t\t\tlocal keyType = overload:GetParameters()[0].ParameterType\r\n\t\t\t\t\tlocal valueType = overload:GetParameters()[1].ParameterType%>\r\n\t\t\t\t\t<%=GetCasterStatement(keyType, 2, \"key\", true)%>;\r\n\t\t\t\t\t<%=GetCasterStatement(valueType, 3, \"gen_to_be_invoked[key]\")%>;\r\n\t\t\t\t<% else\r\n\t\t\t\tin_pos = 0;\r\n\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\tif pi >= real_param_count then return end\r\n\t\t\t\t\t%><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\tin_pos = in_pos + 1\r\n\t\t\t\t\t%><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%\r\n\t\t\t\t\telse%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;\r\n\t\t\t\t<%end)%>\r\n\t\t\t\t<%\r\n\t\t\t\tif has_return then\r\n\t\t\t\t%>var gen_ret = <%\r\n\t\t\t\tend\r\n\t\t\t\t%><%if method.IsStatic then\r\n\t\t\t\t%><%=CsFullTypeName(type)..\".\"..UnK(overload.Name)%><%\r\n\t\t\t\telse\r\n\t\t\t\t%>gen_to_be_invoked.<%=UnK(overload.Name)%><%\r\n\t\t\t\tend%>( <%ForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\tif pi >= real_param_count then return end\r\n\t\t\t\t\tif pi ~= 0 then %>, <% end; if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef and not parameter.IsIn then %>ref <% end %><%=LocalName(parameter.Name)%><% end) %> );\r\n\t\t\t\t<%\r\n\t\t\t\tif has_return then\r\n\t\t\t\t%><%=GetPushStatement(overload.ReturnType, \"gen_ret\")%>;\r\n\t\t\t\t<%\r\n\t\t\t\tend\r\n\t\t\t\tlocal in_pos = 0\r\n\t\t\t\tForEachCsList(parameters, function(parameter, pi)\r\n\t\t\t\t\tif pi >= real_param_count then return end\r\n\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\tin_pos = in_pos + 1\r\n\t\t\t\t\tend\r\n\t\t\t\t\tif parameter.ParameterType.IsByRef then\r\n\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;\r\n\t\t\t\t\t<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then \r\n\t\t\t  %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;\r\n\t\t\t\t\t<%end%>\r\n\t\t\t\t<%\r\n\t\t\t\t\tend\r\n\t\t\t\tend)\r\n\t\t\t\tend\r\n\t\t\t\t%>\r\n\t\t\t\t<%if NeedUpdate(type) and not method.IsStatic then%>\r\n\t\t\t\t<%=GetUpdateStatement(type, 1, \"gen_to_be_invoked\")%>;\r\n\t\t\t\t<%end%>\r\n\t\t\t\t\r\n\t\t\t\treturn <%=out_num+(has_return and 1 or 0)%>;\r\n\t\t\t}\r\n\t\t\t<% end)%>\r\n            <%if method.Overloads.Count > 1 then%>\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!\");\r\n            <%end%>\r\n        }\r\n        <% end)%>\r\n        \r\n        \r\n        <%ForEachCsList(getters, function(getter) \r\n        if getter.IsStatic and getter.ReadOnly then return end --readonly static\r\n        %>\r\n        int <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            <%if AccessorNeedTranslator(getter) then %>ObjectTranslator translator = this;<%end%>\r\n\t\t\t<%if not getter.IsStatic then%>\r\n\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t<%=GetPushStatement(getter.Type, \"gen_to_be_invoked.\"..UnK(getter.Name))%>;<% else %>    <%=GetPushStatement(getter.Type, CsFullTypeName(type)..\".\"..UnK(getter.Name))%>;<% end%>\r\n            return 1;\r\n        }\r\n        <%end)%>\r\n        \r\n        <%ForEachCsList(setters, function(setter)\r\n        local is_struct = IsStruct(setter.Type)\r\n        %>\r\n        int <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            <%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = this;<%end%>\r\n\t\t\t<%if not setter.IsStatic then %>\r\n            <%=GetSelfStatement(type)%>;\r\n            <%if is_struct then %><%=GetCasterStatement(setter.Type, 2, \"gen_value\", true)%>;\r\n\t\t\tgen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else \r\n              %><%=GetCasterStatement(setter.Type, 2, \"gen_to_be_invoked.\" .. UnK(setter.Name))%>;<%end\r\n            else \r\n\t\t\t\tif is_struct then %><%=GetCasterStatement(setter.Type, 1, \"gen_value\", true)%>;\r\n\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else\r\n          %><%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) ..\".\" .. UnK(setter.Name))%>;<%end\r\n            end%>\r\n            <%if NeedUpdate(type) and not setter.IsStatic then%>\r\n            <%=GetUpdateStatement(type, 1, \"gen_to_be_invoked\")%>;\r\n            <%end%>\r\n            return 0;\r\n        }\r\n        <%end)%>\r\n\t\t\r\n\t\t<%ForEachCsList(events, function(event) if not event.IsStatic then %>\r\n        int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            ObjectTranslator translator = this;\r\n\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t<%=GetCasterStatement(event.Type, 3, \"gen_delegate\", true)%>;\r\n\t\t\tif (gen_delegate == null) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"#3 need <%=CsFullTypeName(event.Type)%>!\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (gen_param_count == 3)\r\n\t\t\t{\r\n\t\t\t\t<%if event.CanAdd then%>\r\n\t\t\t\tif (LuaAPI.xlua_is_eq_str(L, 2, \"+\")) {\r\n\t\t\t\t\tgen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t} \r\n\t\t\t\t<%end%>\r\n\t\t\t\t<%if event.CanRemove then%>\r\n\t\t\t\tif (LuaAPI.xlua_is_eq_str(L, 2, \"-\")) {\r\n\t\t\t\t\tgen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t} \r\n\t\t\t\t<%end%>\r\n\t\t\t}\r\n\t\t\tLuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!\");\r\n            return 0;\r\n        }\r\n        <%end end)%>\r\n\t\t\r\n\t\t<%ForEachCsList(events, function(event) if event.IsStatic then %>\r\n        int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>\r\n        {\r\n            ObjectTranslator translator = this;\r\n\t\t\t<%=GetCasterStatement(event.Type, 2, \"gen_delegate\", true)%>;\r\n\t\t\tif (gen_delegate == null) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"#2 need <%=CsFullTypeName(event.Type)%>!\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t<%if event.CanAdd then%>\r\n\t\t\tif (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, \"+\")) {\r\n\t\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;\r\n\t\t\t\treturn 0;\r\n\t\t\t} \r\n\t\t\t<%end%>\r\n\t\t\t<%if event.CanRemove then%>\r\n\t\t\tif (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, \"-\")) {\r\n\t\t\t\t<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;\r\n\t\t\t\treturn 0;\r\n\t\t\t} \r\n\t\t\t<%end%>\r\n\t\t\treturn LuaAPI.luaL_error(L, \"invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!\");\r\n        }\r\n        <%end end)%>\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaClassWrapGCM.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 2bd79d95fd859724283926ad8fa4df30\ntimeCreated: 1501232428\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\nnamespace XLua\r\n{\r\n    public partial class DelegateBridge : DelegateBridgeBase\r\n    {\r\n\t\t<%\r\n\t\tForEachCsList(delegates_groups, function(delegates_group, group_idx)\r\n\t\tlocal delegate = delegates_group.Key\r\n\t\tlocal parameters = delegate:GetParameters()\r\n\t\tlocal in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n\t\tlocal out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n\t\tlocal in_pos = 0\r\n\t\tlocal has_return = (delegate.ReturnType.FullName ~= \"System.Void\")\r\n\t\tlocal return_type_name = has_return and CsFullTypeName(delegate.ReturnType) or \"void\"\r\n\t\tlocal out_idx = has_return and 2 or 1\r\n\t\tif has_return then out_num = out_num + 1 end\r\n\t\t%>\r\n\t\tpublic <%=return_type_name%> __Gen_Delegate_Imp<%=group_idx%>(<%ForEachCsList(parameters, function(parameter, pi) \r\n\t\t\tif pi ~= 0 then \r\n\t\t\t\t%>, <% \r\n\t\t\tend\r\n\t\t\tif parameter.IsOut and parameter.ParameterType.IsByRef then \r\n\t\t\t\t%>out <%\r\n\t\t\telseif parameter.ParameterType.IsByRef then\r\n\t\t\t\t%>ref <%\r\n\t\t\tend \r\n\t\t\t%><%=CsFullTypeName(parameter.ParameterType)%> p<%=pi%><% \r\n\t\tend) %>)\r\n\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                RealStatePtr L = luaEnv.rawL;\r\n                int errFunc = LuaAPI.pcall_prepare(L, errorFuncRef, luaReference);\r\n                <%if CallNeedTranslator(delegate, \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n                <%\r\n                local param_count = parameters.Length\r\n                local has_v_params = param_count > 0 and parameters[param_count - 1].IsParamArray\r\n                ForEachCsList(parameters, function(parameter, pi) \r\n                    if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                        %><%=GetPushStatement(parameter.ParameterType, 'p' .. pi, has_v_params and pi == param_count - 1)%>;\r\n                <% \r\n                    end\r\n                end) %>\r\n                PCall(L, <%=has_v_params and ((in_num - 1) .. \" + (p\".. (param_count - 1) .. \" == null ? 0 : p\" .. (param_count - 1) .. \".Length)\" ) or in_num%>, <%=out_num%>, errFunc);\r\n                \r\n                <%ForEachCsList(parameters, function(parameter, pi) \r\n                    if parameter.IsOut or parameter.ParameterType.IsByRef then \r\n                        %><%=GetCasterStatement(parameter.ParameterType, \"errFunc\" .. (\" + \"..out_idx), 'p' .. pi)%>;\r\n                <%\r\n                    out_idx = out_idx + 1\r\n                    end\r\n                end) %>\r\n                <%if has_return then %><%=GetCasterStatement(delegate.ReturnType, \"errFunc + 1\", \"__gen_ret\", true)%>;<% end%>\r\n                LuaAPI.lua_settop(L, errFunc - 1);\r\n                <%if has_return then %>return  __gen_ret;<% end%>\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n\t\t}\r\n        <%end)%>\r\n        \r\n\t\tstatic DelegateBridge()\r\n\t\t{\r\n\t\t    Gen_Flag = true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic override Delegate GetDelegateByType(Type type)\r\n\t\t{\r\n\t\t<%\r\n\t\tForEachCsList(delegates_groups, function(delegates_group, group_idx)\r\n\t\t    ForEachCsList(delegates_group.Value, function(delegate)\r\n            if delegate.DeclaringType then\r\n\t\t\tlocal delegate_type_name = CsFullTypeName(delegate.DeclaringType)\r\n\t\t%>\r\n\t\t    if (type == typeof(<%=delegate_type_name%>))\r\n\t\t\t{\r\n\t\t\t    return new <%=delegate_type_name%>(__Gen_Delegate_Imp<%=group_idx%>);\r\n\t\t\t}\r\n\t\t<%\r\n            end\r\n\t\t    end)\r\n\t\tend)\r\n\t\t%>\r\n\t\t    return null;\r\n\t\t}\r\n\t}\r\n    \r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaDelegateBridge.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 3d992756e2469044484be75f78e4e556\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n<%\r\nrequire \"TemplateCommon\"\r\n\r\nlocal parameters = delegate:GetParameters()\r\nlocal in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\nlocal out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\nlocal in_pos = 0\r\nlocal has_return = (delegate.ReturnType.Name ~= \"Void\")\r\n%>\r\n\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    using Utils = XLua.Utils;\r\n    public class <%=CSVariableName(type)%>Wrap\r\n    {\r\n\t\tpublic static void __Register(RealStatePtr L)\r\n        {\r\n            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t    Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);\r\n\t\t\tUtils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);\r\n\t\t\t\r\n\t\t\tUtils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, 1, 0, 0);\r\n            Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);\r\n        }\r\n\t\t\r\n\t\tstatic Dictionary<string, LuaCSFunction> __MetaFucntions_Dic = new Dictionary<string, LuaCSFunction>(){\r\n            {\"__call\", __CallMeta},\r\n\t\t\t{\"__add\", __AddMeta},\r\n\t\t\t{\"__sub\", __SubMeta},\r\n        };\r\n\t\t\r\n\t\t[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int __CallMeta(RealStatePtr L)\r\n        {\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\ttry {\r\n\t\t\t\tif(LuaAPI.lua_gettop(L) == <%=in_num+1%> && <%=GetCheckStatement(type, 1)%><%\r\n\t\t\t\t\tForEachCsList(parameters, function(parameter) \r\n\t\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1; \r\n\t\t\t\t\t\t%>&& <%=GetCheckStatement(parameter.ParameterType, in_pos+1)%><% \r\n\t\t\t\t\t\tend \r\n\t\t\t\t\tend)%>)\r\n\t\t\t\t{\r\n                <% \r\n                in_pos = 0;\r\n                ForEachCsList(parameters, function(parameter) \r\n                    %><% \r\n                    if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                        in_pos = in_pos + 1\r\n                        %><%=GetCasterStatement(parameter.ParameterType, in_pos+1, parameter.Name, true)%><%\r\n\t\t\t\t\telse%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%end%>;\r\n                <%end)%>\r\n\t\t\t\t<%=GetSelfStatement(type)%>;\r\n\t\t\t\t\r\n\t\t\t\t<%\r\n                if has_return then\r\n                    %>    var __cl_gen_ret = <%\r\n                end\r\n                %>    __cl_gen_to_be_invoked( <%ForEachCsList(parameters, function(parameter, pi) if pi ~= 0 then %>, <% end; if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=parameter.Name%><% end) %> );\r\n                <%\r\n                if has_return then\r\n                %>    <%=GetPushStatement(delegate.ReturnType, \"__cl_gen_ret\")%>;\r\n                <%\r\n                end\r\n                local in_pos = 0\r\n                ForEachCsList(parameters, function(parameter)\r\n                    if not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n                        in_pos = in_pos + 1\r\n                    end\r\n                    if parameter.IsOut or parameter.ParameterType.IsByRef then\r\n                    %><%=GetPushStatement(parameter.ParameterType:GetElementType(), parameter.Name)%>;\r\n                    <%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then \r\n                  %><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, parameter.Name)%>;\r\n                        <%end%>\r\n                <%\r\n                    end\r\n                end)\r\n                %>\r\n\t\t\t\t\t\r\n\t\t\t\t\treturn <%=out_num+(has_return and 1 or 0)%>;\r\n\t\t\t\t}\r\n\t\t\t} catch(System.Exception __gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + __gen_e);\r\n\t\t\t}\r\n            return LuaAPI.luaL_error(L, \"invalid arguments to Delegate <%=CsFullTypeName(type)%>!\");\r\n\t\t}\r\n\t\t\r\n\t\t[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int __AddMeta(RealStatePtr L)\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\ttry {\r\n\t\t\t\t<%=GetCasterStatement(type, 1, \"leftside\", true)%>;\r\n\t\t\t\t<%=GetCasterStatement(type, 2, \"rightside\", true)%>;\r\n\t\t\t\t<%=GetPushStatement(type, \"leftside + rightside\")%>;\r\n\t\t\t\treturn 1;\r\n\t\t\t} catch(System.Exception __gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + __gen_e);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int __SubMeta(RealStatePtr L)\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\ttry {\r\n\t\t\t\t<%=GetCasterStatement(type, 1, \"leftside\", true)%>;\r\n\t\t\t\t<%=GetCasterStatement(type, 2, \"rightside\", true)%>;\r\n\t\t\t\t<%=GetPushStatement(type, \"leftside - rightside\")%>;\r\n\t\t\t\treturn 1;\r\n\t\t\t} catch(System.Exception __gen_e) {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception:\" + __gen_e);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaDelegateWrap.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 33b33e1cd617f794b8c801a32f3b2539\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n<%\r\nrequire \"TemplateCommon\"\r\nlocal enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor\r\n%>\r\n\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    using Utils = XLua.Utils;\r\n    <%ForEachCsList(types, function(type)\r\n\tlocal fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))\r\n\tlocal fields_to_gen  = {}\r\n\tForEachCsList(fields, function(field) \r\n\t    if field.Name ~= \"value__\" and not IsObsolute(field) then \r\n\t\t    table.insert(fields_to_gen, field)\r\n\t\tend\r\n\tend)\r\n\t%>\r\n    public class <%=CSVariableName(type)%>Wrap\r\n    {\r\n\t\tpublic static void __Register(RealStatePtr L)\r\n        {\r\n\t\t    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t    Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);\r\n\t\t\tUtils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);\r\n\t\t\t\r\n\t\t\tUtils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);\r\n<%if #fields_to_gen <= 20 then%>\r\n            <% ForEachCsList(fields, function(field) \r\n\t\t\tif field.Name == \"value__\" or IsObsolute(field) then return end\r\n\t\t\t%>\r\n            Utils.RegisterObject(L, translator, Utils.CLS_IDX, \"<%=field.Name%>\", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);\r\n            <%end)%>\r\n<%else%>\r\n            Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));\r\n<%end%>\r\n\t\t\tUtils.RegisterFunc(L, Utils.CLS_IDX, \"__CastFrom\", __CastFrom);\r\n            \r\n            Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);\r\n        }\r\n\t\t\r\n\t\t[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        static int __CastFrom(RealStatePtr L)\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\tLuaTypes lua_type = LuaAPI.lua_type(L, 1);\r\n            if (lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                translator.Push<%=CSVariableName(type)%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));\r\n            }\r\n\t\t\t<%if #fields_to_gen > 0 then%>\r\n            else if(lua_type == LuaTypes.LUA_TSTRING)\r\n            {\r\n<%if #fields_to_gen <= 20 then%>\r\n\t\t\t    <%\r\n                local is_first = true\r\n\t\t\t\tForEachCsList(fields, function(field, i) \r\n\t\t\t        if field.Name == \"value__\" or IsObsolute(field) then return end\r\n\t\t\t    %><%=(is_first and \"\" or \"else \")%>if (LuaAPI.xlua_is_eq_str(L, 1, \"<%=field.Name%>\"))\r\n                {\r\n                    translator.Push<%=CSVariableName(type)%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);\r\n                }\r\n\t\t\t\t<%\r\n\t\t\t\tis_first = false\r\n\t\t\t\tend)\r\n                %>else\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"invalid string for <%=CsFullTypeName(type)%>!\");\r\n                }\r\n<%else%>\r\n                try\r\n\t\t\t\t{\r\n                    translator.TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);\r\n\t\t\t\t}\r\n\t\t\t\tcatch (System.Exception e)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(L, \"cast to \" + typeof(<%=CsFullTypeName(type)%>) + \" exception:\" + e);\r\n\t\t\t\t}\r\n<%end%>\r\n            }\r\n\t\t\t<%end%>\r\n            else\r\n            {\r\n                return LuaAPI.luaL_error(L, \"invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + \" + lua_type);\r\n            }\r\n\r\n            return 1;\r\n\t\t}\r\n\t}\r\n    <%end)%>\r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaEnumWrap.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: ae16c73aad9a21a44aef65decb7e4928\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n<%\r\nrequire \"TemplateCommon\"\r\nlocal enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor\r\n%>\r\n\r\nnamespace XLua\r\n{\r\n\tpublic partial class ObjectTranslator\r\n    {\r\n    <%ForEachCsList(types, function(type)\r\n\tlocal fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))\r\n\tlocal fields_to_gen  = {}\r\n\tForEachCsList(fields, function(field) \r\n\t    if field.Name ~= \"value__\" and not IsObsolute(field) then \r\n\t\t    table.insert(fields_to_gen, field)\r\n\t\tend\r\n\tend)\r\n\tlocal v_type_name = CSVariableName(type)\r\n\t%>\r\n\t\tpublic void __Register<%=v_type_name%>(RealStatePtr L)\r\n        {\r\n\t\t    Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, 0, 0, 0, 0);\r\n\t\t\tUtils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, null, null, null, null, null);\r\n\t\t\t\r\n\t\t\tUtils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);\r\n<%if #fields_to_gen <= 20 then%>\r\n            <% ForEachCsList(fields, function(field) \r\n\t\t\tif field.Name == \"value__\" or IsObsolute(field) then return end\r\n\t\t\t%>\r\n            Utils.RegisterObject(L, this, Utils.CLS_IDX, \"<%=field.Name%>\", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);\r\n            <%end)%>\r\n<%else%>\r\n            Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));\r\n<%end%>\r\n\t\t\tUtils.RegisterFunc(L, Utils.CLS_IDX, \"__CastFrom\", __CastFrom<%=v_type_name%>);\r\n            \r\n            Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, this);\r\n        }\r\n\t\t\r\n        int __CastFrom<%=v_type_name%>(RealStatePtr L, int __gen_top)\r\n\t\t{\r\n\t\t\tLuaTypes lua_type = LuaAPI.lua_type(L, 1);\r\n            if (lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                Push<%=v_type_name%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));\r\n            }\r\n\t\t\t<%if #fields_to_gen > 0 then%>\r\n            else if(lua_type == LuaTypes.LUA_TSTRING)\r\n            {\r\n<%if #fields_to_gen <= 20 then%>\r\n\t\t\t    <%\r\n                local is_first = true\r\n\t\t\t\tForEachCsList(fields, function(field, i) \r\n\t\t\t        if field.Name == \"value__\" or IsObsolute(field) then return end\r\n\t\t\t    %><%=(is_first and \"\" or \"else \")%>if (LuaAPI.xlua_is_eq_str(L, 1, \"<%=field.Name%>\"))\r\n                {\r\n                    Push<%=v_type_name%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);\r\n                }\r\n\t\t\t\t<%\r\n\t\t\t\tis_first = false\r\n\t\t\t\tend)\r\n                %>else\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"invalid string for <%=CsFullTypeName(type)%>!\");\r\n                }\r\n<%else%>\r\n                try\r\n\t\t\t\t{\r\n                    TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);\r\n\t\t\t\t}\r\n\t\t\t\tcatch (System.Exception e)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(L, \"cast to \" + typeof(<%=CsFullTypeName(type)%>) + \" exception:\" + e);\r\n\t\t\t\t}\r\n<%end%>\r\n            }\r\n\t\t\t<%end%>\r\n            else\r\n            {\r\n                return LuaAPI.luaL_error(L, \"invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + \" + lua_type);\r\n            }\r\n\r\n            return 1;\r\n\t\t}\r\n    <%end)%>\r\n\t}\r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaEnumWrapGCM.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: ea84a5ee7abf8e347a810eb7848add46\ntimeCreated: 1501232428\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing XLua;\r\nusing System;\r\n<%\r\nrequire \"TemplateCommon\"\r\n\r\n%>\r\n\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    public class <%=CSVariableName(type)%>Bridge : LuaBase, <%=CsFullTypeName(type)%>\r\n    {\r\n\t    public static LuaBase __Create(int reference, LuaEnv luaenv)\r\n\t\t{\r\n\t\t    return new <%=CSVariableName(type)%>Bridge(reference, luaenv);\r\n\t\t}\r\n\t\t\r\n\t\tpublic <%=CSVariableName(type)%>Bridge(int reference, LuaEnv luaenv) : base(reference, luaenv)\r\n        {\r\n        }\r\n\t\t\r\n        <%\r\n        ForEachCsList(methods, function(method)\r\n            local parameters = method:GetParameters()\r\n            local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n            local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n            local in_pos = 0\r\n            local has_return = (method.ReturnType.FullName ~= \"System.Void\")\r\n            local return_type_name = has_return and CsFullTypeName(method.ReturnType) or \"void\"\r\n            local out_idx = has_return and 2 or 1\r\n\t\t\tif has_return then out_num = out_num + 1 end\r\n        %>\r\n\t\t<%=return_type_name%> <%=CsFullTypeName(method.DeclaringType)%>.<%=method.Name%>(<%ForEachCsList(parameters, function(parameter, pi) \r\n\t\t\tif pi ~= 0 then \r\n\t\t\t\t%>, <% \r\n\t\t\tend\r\n\t\t\tif parameter.IsOut and parameter.ParameterType.IsByRef then \r\n\t\t\t\t%>out <%\r\n\t\t\telseif parameter.ParameterType.IsByRef then\r\n\t\t\t\t%>ref <%\r\n\t\t\tend \r\n\t\t\t%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><% \r\n\t\tend) %>)\r\n\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\tint err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\t<%if CallNeedTranslator(method, \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=method.Name%>\");\r\n\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t{\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t}\r\n\t\t\t\tif(!LuaAPI.lua_isfunction(L, -1))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"no such function <%=method.Name%>\");\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\tLuaAPI.lua_remove(L, -3);\r\n\t\t\t\t<%\r\n\t\t\t\tlocal param_count = parameters.Length\r\n                local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\r\n\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t<% \r\n\t\t\t\t\tend\r\n\t\t\t\tend) %>\r\n\t\t\t\tint __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. \" + (\".. parameters[param_count - 1].Name .. \" == null ? 0 : \" .. parameters[param_count - 1].Name .. \".Length)\" ) or (in_num + 1)%>, <%=out_num%>, err_func);\r\n\t\t\t\tif (__gen_error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\r\n\t\t\t\t<%ForEachCsList(parameters, function(parameter) \r\n\t\t\t\t\tif parameter.IsOut or parameter.ParameterType.IsByRef then \r\n\t\t\t\t\t\t%><%=GetCasterStatement(parameter.ParameterType, \"err_func\" .. (\" + \"..out_idx), parameter.Name)%>;\r\n\t\t\t\t<%\r\n\t\t\t\t\tout_idx = out_idx + 1\r\n\t\t\t\t\tend\r\n\t\t\t\tend) %>\r\n\t\t\t\t<%if has_return then %><%=GetCasterStatement(method.ReturnType, \"err_func + 1\", \"__gen_ret\", true)%>;<% end%>\r\n\t\t\t\tLuaAPI.lua_settop(L, err_func - 1);\r\n\t\t\t\t<%if has_return then %>return  __gen_ret;<% end%>\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n\t\t}\r\n        <%end)%>\r\n\r\n        <%\r\n        ForEachCsList(propertys, function(property)\r\n        %>\r\n        <%=CsFullTypeName(property.PropertyType)%> <%=CsFullTypeName(property.DeclaringType)%>.<%=property.Name%> \r\n        {\r\n            <%if property.CanRead then%>\r\n            get \r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnv.luaEnvLock)\r\n                {\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\t\t<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=property.Name%>\");\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t<%=GetCasterStatement(property.PropertyType, \"-1\", \"__gen_ret\", true)%>;\r\n\t\t\t\t\tLuaAPI.lua_pop(L, 2);\r\n\t\t\t\t\treturn __gen_ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n            <%end%>\r\n            <%if property.CanWrite then%>\r\n            set\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnv.luaEnvLock)\r\n                {\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\t\t<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=property.Name%>\");\r\n\t\t\t\t\t<%=GetPushStatement(property.PropertyType, \"value\")%>;\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_psettable(L, -3))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n            <%end%>\r\n        }\r\n        <%end)%>\r\n        \r\n        <%ForEachCsList(events, function(event) %>\r\n\t\tevent <%=CsFullTypeName(event.EventHandlerType)%> <%=CsFullTypeName(event.DeclaringType)%>.<%=event.Name%>\r\n\t\t{<%local parameters = event:GetAddMethod():GetParameters()%>\r\n\t\t\tadd\r\n\t\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\tlock (luaEnv.luaEnvLock)\r\n\t\t\t\t{\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\t\t<%if CallNeedTranslator(event:GetAddMethod(), \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"add_<%=event.Name%>\");\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(!LuaAPI.lua_isfunction(L, -1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"no such function add_<%=event.Name%>\");\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\t\tLuaAPI.lua_remove(L, -3);\r\n\t\t\t\t\t<%\r\n\t\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\r\n\t\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t\t<% \r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\tint __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);\r\n\t\t\t\t\tif (__gen_error != 0)\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_settop(L, err_func - 1);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\t}\r\n#endif\r\n\t\t\t}\r\n\r\n\t\t\tremove\r\n\t\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\tlock (luaEnv.luaEnvLock)\r\n\t\t\t\t{\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\t\t<%if CallNeedTranslator(event:GetRemoveMethod(), \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"remove_<%=event.Name%>\");\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(!LuaAPI.lua_isfunction(L, -1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"no such function remove_<%=event.Name%>\");\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\t\tLuaAPI.lua_remove(L, -3);\r\n\t\t\t\t\t<%\r\n\t\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\r\n\t\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t\t<% \r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\tint __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);\r\n\t\t\t\t\tif (__gen_error != 0)\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_settop(L, err_func - 1);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\t}\r\n#endif\r\n\t\t\t}\r\n\t\t}\r\n        <%end)%>\r\n\t\t\r\n\t\t<%ForEachCsList(indexers, function(indexer) \r\n\t\tlocal ptype = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].ParameterType\r\n\t\tlocal pname = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].Name\r\n\t\t%>\r\n        <%=CsFullTypeName(indexer.PropertyType)%> <%=CsFullTypeName(indexer.DeclaringType)%>.this[<%=CsFullTypeName(ptype)%> <%=pname%>]\r\n\t\t{<%if indexer:GetGetMethod() then\r\n\t\t\tlocal method = indexer:GetGetMethod()\t\t\r\n            local parameters = method:GetParameters()\r\n            local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n            local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n            local in_pos = 0\r\n            local has_return = (method.ReturnType.FullName ~= \"System.Void\")\r\n            local return_type_name = has_return and CsFullTypeName(method.ReturnType) or \"void\"\r\n            local out_idx = has_return and 2 or 1\r\n\t\t\tif has_return then out_num = out_num + 1 end\r\n\t\t%>\r\n\t\t    get\r\n\t\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\tlock (luaEnv.luaEnvLock)\r\n\t\t\t\t{\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\t\t<%if CallNeedTranslator(method, \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=method.Name%>\");\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(!LuaAPI.lua_isfunction(L, -1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"no such function <%=method.Name%>\");\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\t\tLuaAPI.lua_remove(L, -3);\r\n\t\t\t\t\t<%\r\n\t\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\r\n\t\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t\t<% \r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\tint __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. \" + \" .. parameters[param_count - 1].Name .. \".Length\" ) or (in_num + 1)%>, <%=out_num%>, err_func);\r\n\t\t\t\t\tif (__gen_error != 0)\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\r\n\t\t\t\t\t<%ForEachCsList(parameters, function(parameter) \r\n\t\t\t\t\t\tif parameter.IsOut or parameter.ParameterType.IsByRef then \r\n\t\t\t\t\t\t\t%><%=GetCasterStatement(parameter.ParameterType, \"err_func\" .. (\" + \"..out_idx), parameter.Name)%>;\r\n\t\t\t\t\t<%\r\n\t\t\t\t\t\tout_idx = out_idx + 1\r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\t<%if has_return then %><%=GetCasterStatement(method.ReturnType, \"err_func + 1\", \"__gen_ret\", true)%>;<% end%>\r\n\t\t\t\t\tLuaAPI.lua_settop(L, err_func - 1);\r\n\t\t\t\t\t<%if has_return then %>return  __gen_ret;<% end%>\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\t}\r\n#endif\r\n\t\t\t}\r\n\t\t<%end%>\r\n\t\t<%if indexer:GetSetMethod() then\r\n\t\t\tlocal method = indexer:GetSetMethod()\t\t\r\n            local parameters = method:GetParameters()\r\n            local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)\r\n            local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)\r\n            local in_pos = 0\r\n            local has_return = (method.ReturnType.FullName ~= \"System.Void\")\r\n            local return_type_name = has_return and CsFullTypeName(method.ReturnType) or \"void\"\r\n            local out_idx = has_return and 2 or 1\r\n\t\t\tif has_return then out_num = out_num + 1 end\r\n\t\t%>\r\n\t\t\tset\r\n\t\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\tlock (luaEnv.luaEnvLock)\r\n\t\t\t\t{\r\n#endif\r\n\t\t\t\t\tRealStatePtr L = luaEnv.L;\r\n\t\t\t\t\tint err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\t\t<%if CallNeedTranslator(method, \"\") then %>ObjectTranslator translator = luaEnv.translator;<%end%>\r\n\t\t\t\t\r\n\t\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=method.Name%>\");\r\n\t\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(!LuaAPI.lua_isfunction(L, -1))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"no such function <%=method.Name%>\");\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\t\tLuaAPI.lua_remove(L, -3);\r\n\t\t\t\t\t<%\r\n\t\t\t\t\tlocal param_count = parameters.Length\r\n\t\t\t\t\tlocal has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])\r\n\r\n\t\t\t\t\tForEachCsList(parameters, function(parameter, pi) \r\n\t\t\t\t\t\tif not (parameter.IsOut and parameter.ParameterType.IsByRef) then \r\n\t\t\t\t\t\t\t%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;\r\n\t\t\t\t\t<% \r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\tint __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. \" + \" .. parameters[param_count - 1].Name .. \".Length\" ) or (in_num + 1)%>, <%=out_num%>, err_func);\r\n\t\t\t\t\tif (__gen_error != 0)\r\n\t\t\t\t\t\tluaEnv.ThrowExceptionFromError(err_func - 1);\r\n\t\t\t\t\r\n\t\t\t\t\t<%ForEachCsList(parameters, function(parameter) \r\n\t\t\t\t\t\tif parameter.IsOut or parameter.ParameterType.IsByRef then \r\n\t\t\t\t\t\t\t%><%=GetCasterStatement(parameter.ParameterType, \"err_func\" .. (\" + \"..out_idx), parameter.Name)%>;\r\n\t\t\t\t\t<%\r\n\t\t\t\t\t\tout_idx = out_idx + 1\r\n\t\t\t\t\t\tend\r\n\t\t\t\t\tend) %>\r\n\t\t\t\t\t<%if has_return then %><%=GetCasterStatement(method.ReturnType, \"err_func + 1\", \"__gen_ret\", true)%>;<% end%>\r\n\t\t\t\t\tLuaAPI.lua_settop(L, err_func - 1);\r\n\t\t\t\t\t<%if has_return then %>return  __gen_ret;<% end%>\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t\t}\r\n#endif\r\n\t\t\t} \r\n\t\t<%end%>\r\n\t\t}\r\n        <%end)%>\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaInterfaceBridge.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 7165d08e91378494dadeb10e5338accb\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Reflection;\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    public class XLua_Gen_Initer_Register__\r\n\t{\r\n        <%\r\n        local split_method_perfix = 'wrapInit'\r\n        local split_method_count = 0\r\n        local wrap_in_split_method = 0\r\n        local max_wrap_in_split_method = 50\r\n        %>\r\n        <%ForEachCsList(wraps, function(wrap)%>\r\n        <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n        <%end%>\r\n            translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), <%=CSVariableName(wrap)%>Wrap.__Register);\r\n        <%if wrap_in_split_method == max_wrap_in_split_method then\r\n        wrap_in_split_method = 0\r\n        split_method_count = split_method_count + 1\r\n        %>\r\n        }\r\n        <%else\r\n        wrap_in_split_method = wrap_in_split_method + 1\r\n        end\r\n        end)%>\r\n        <% if generic_wraps then \r\n        for generic_def, instances in pairs(generic_wraps) do\r\n        for _, args in ipairs(instances) do\r\n        local generic_arg_list = \"<\"\r\n        ForEachCsList(args, function(generic_arg, gai)\r\n            if gai ~= 0 then generic_arg_list = generic_arg_list .. \", \" end\r\n            generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)\r\n        end)\r\n        generic_arg_list = generic_arg_list .. \">\"\r\n        \r\n        %>\r\n        <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n        <%end%>\r\n            translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub(\"`%d+\", \"\") .. generic_arg_list%>), <%=CSVariableName(generic_def)%>Wrap<%=generic_arg_list%>.__Register);\r\n        <%if wrap_in_split_method == max_wrap_in_split_method then\r\n        wrap_in_split_method = 0\r\n        split_method_count = split_method_count + 1\r\n        %>\r\n        }\r\n        <%else\r\n        wrap_in_split_method = wrap_in_split_method + 1\r\n        end\r\n        end\r\n        end\r\n        end%>\r\n        \r\n        <%if wrap_in_split_method ~= 0 then\r\n        split_method_count = split_method_count + 1\r\n        %>}<%end%>\r\n        \r\n        static void Init(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n            <%for i = 1, split_method_count do%>\r\n            <%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);\r\n            <%end%>\r\n            <%ForEachCsList(itf_bridges, function(itf_bridge)%>\r\n            translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);\r\n            <%end)%>\r\n        }\r\n        \r\n\t    static XLua_Gen_Initer_Register__()\r\n        {\r\n\t\t    XLua.LuaEnv.AddIniter(Init);\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t}\r\n\t\r\n}\r\nnamespace XLua\r\n{\r\n\tpublic partial class ObjectTranslator\r\n\t{\r\n\t\tstatic XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();\r\n\t\tstatic XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}\r\n\t}\r\n\t\r\n\tinternal partial class InternalGlobals\r\n    {\r\n\t    <%\r\n\t\tlocal type_to_methods = {}\r\n\t\tlocal seq_tbl = {}\r\n\t\tForEachCsList(extension_methods, function(extension_method, idx)\r\n\t\t    local parameters = extension_method:GetParameters()\r\n\t\t\tlocal type = parameters[0].ParameterType\r\n\t\t\tif not type_to_methods[type] then\r\n\t\t\t\ttype_to_methods[type] = {type = type}\r\n\t\t\t\ttable.insert(seq_tbl, type_to_methods[type])\r\n\t\t\tend\r\n\t\t\ttable.insert(type_to_methods[type], {method = extension_method, index = idx})\r\n\t\t%>\r\n\t\tdelegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)\r\n\t\t%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%\r\n\t\tend)%>);\r\n\t\t<%end)%>\r\n\t    static InternalGlobals()\r\n\t\t{\r\n\t\t    extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()\r\n\t\t\t{\r\n\t\t\t    <%for _, methods_info in ipairs(seq_tbl) do%>\r\n\t\t\t\t{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){\r\n\t\t\t\t<%  for _, method_info in ipairs(methods_info) do%>\r\n\t\t\t\t  new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n                                      .GetMethodInfo(),\r\n#else\r\n                                      .Method,\r\n#endif\r\n\t\t\t\t<%  end%>\r\n\t\t\t\t}},\r\n\t\t\t\t<%end%>\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tgenTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;\r\n            genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaRegister.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: e416b82ec9fe340458f97cf1e3468ef7\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Reflection;\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\nnamespace XLua.CSObjectWrap\r\n{\r\n    public class XLua_Gen_Initer_Register__\r\n\t{\r\n        <%\r\n        local split_method_perfix = 'wrapInit'\r\n        local split_method_count = 0\r\n        local wrap_in_split_method = 0\r\n        local max_wrap_in_split_method = 50\r\n        %>\r\n        <%ForEachCsList(wraps, function(wrap)%>\r\n        <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n        <%end%>\r\n            translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), translator.__Register<%=CSVariableName(wrap)%>);\r\n        <%if wrap_in_split_method == max_wrap_in_split_method then\r\n        wrap_in_split_method = 0\r\n        split_method_count = split_method_count + 1\r\n        %>\r\n        }\r\n        <%else\r\n        wrap_in_split_method = wrap_in_split_method + 1\r\n        end\r\n        end)%>\r\n        <% if generic_wraps then \r\n        for generic_def, instances in pairs(generic_wraps) do\r\n        for _, args in ipairs(instances) do\r\n        local generic_arg_list = \"<\"\r\n        ForEachCsList(args, function(generic_arg, gai)\r\n            if gai ~= 0 then generic_arg_list = generic_arg_list .. \", \" end\r\n            generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)\r\n        end)\r\n        generic_arg_list = generic_arg_list .. \">\"\r\n        \r\n        %>\r\n        <%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n        <%end%>\r\n            translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub(\"`%d+\", \"\") .. generic_arg_list%>), translator.__Register<%=CSVariableName(generic_def)%><%=generic_arg_list%>);\r\n        <%if wrap_in_split_method == max_wrap_in_split_method then\r\n        wrap_in_split_method = 0\r\n        split_method_count = split_method_count + 1\r\n        %>\r\n        }\r\n        <%else\r\n        wrap_in_split_method = wrap_in_split_method + 1\r\n        end\r\n        end\r\n        end\r\n        end%>\r\n        \r\n        <%if wrap_in_split_method ~= 0 then\r\n        split_method_count = split_method_count + 1\r\n        %>}<%end%>\r\n        \r\n        static void Init(LuaEnv luaenv, ObjectTranslator translator)\r\n        {\r\n            <%for i = 1, split_method_count do%>\r\n            <%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);\r\n            <%end%>\r\n            <%ForEachCsList(itf_bridges, function(itf_bridge)%>\r\n            translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);\r\n            <%end)%>\r\n        }\r\n        \r\n\t    static XLua_Gen_Initer_Register__()\r\n        {\r\n\t\t    XLua.LuaEnv.AddIniter(Init);\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t}\r\n\t\r\n}\r\nnamespace XLua\r\n{\r\n\tpublic partial class ObjectTranslator\r\n\t{\r\n\t\tstatic XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();\r\n\t\tstatic XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}\r\n\t}\r\n\t\r\n\tinternal partial class InternalGlobals\r\n    {\r\n\t    <%\r\n\t\tlocal type_to_methods = {}\r\n\t\tlocal seq_tbl = {}\r\n\t\tForEachCsList(extension_methods, function(extension_method, idx)\r\n\t\t    local parameters = extension_method:GetParameters()\r\n\t\t\tlocal type = parameters[0].ParameterType\r\n\t\t\tif not type_to_methods[type] then\r\n\t\t\t\ttype_to_methods[type] = {type = type}\r\n\t\t\t\ttable.insert(seq_tbl, type_to_methods[type])\r\n\t\t\tend\r\n\t\t\ttable.insert(type_to_methods[type], {method = extension_method, index = idx})\r\n\t\t%>\r\n\t\tdelegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)\r\n\t\t%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%\r\n\t\tend)%>);\r\n\t\t<%end)%>\r\n\t    static InternalGlobals()\r\n\t\t{\r\n\t\t    extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()\r\n\t\t\t{\r\n\t\t\t    <%for _, methods_info in ipairs(seq_tbl) do%>\r\n\t\t\t\t{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){\r\n\t\t\t\t<%  for _, method_info in ipairs(methods_info) do%>\r\n\t\t\t\t  new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n                                      .GetMethodInfo(),\r\n#else\r\n                                      .Method,\r\n#endif\r\n\t\t\t\t<%  end%>\r\n\t\t\t\t}},\r\n\t\t\t\t<%end%>\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tgenTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;\r\n            genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaRegisterGCM.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 46c7366d55afbf1459674448d92c44c8\ntimeCreated: 1501232428\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\nnamespace XLua\r\n{\r\n    public partial class ObjectTranslator\r\n    {\r\n        <%if purevaluetypes.Count > 0 then\r\n        local init_class_name = \"IniterAdder\" .. CSVariableName(purevaluetypes[0].Type)\r\n        %>\r\n        class <%=init_class_name%>\r\n        {\r\n            static <%=init_class_name%>()\r\n            {\r\n                LuaEnv.AddIniter(Init);\r\n            }\r\n\t\t\t\r\n\t\t\tstatic void Init(LuaEnv luaenv, ObjectTranslator translator)\r\n\t\t\t{\r\n\t\t\t<%ForEachCsList(purevaluetypes, function(type_info)\r\n            if not type_info.Type.IsValueType then return end\r\n            local full_type_name = CsFullTypeName(type_info.Type)%>\r\n\t\t\t\ttranslator.RegisterPushAndGetAndUpdate<<%=full_type_name%>>(translator.Push<%=CSVariableName(type_info.Type)%>, translator.Get, translator.Update<%=CSVariableName(type_info.Type)%>);<%\r\n\t\t\tend)%>\r\n\t\t\t<%ForEachCsList(tableoptimzetypes, function(type_info)\r\n            local full_type_name = CsFullTypeName(type_info.Type)%>\r\n\t\t\t\ttranslator.RegisterCaster<<%=full_type_name%>>(translator.Get);<%\r\n\t\t\tend)%>\r\n\t\t\t}\r\n        }\r\n        \r\n        static <%=init_class_name%> s_<%=init_class_name%>_dumb_obj = new <%=init_class_name%>();\r\n        static <%=init_class_name%> <%=init_class_name%>_dumb_obj {get{return s_<%=init_class_name%>_dumb_obj;}}\r\n        <%end%>\r\n        \r\n        <%ForEachCsList(purevaluetypes, function(type_info)\r\n        local type_id_var_name = CSVariableName(type_info.Type) .. '_TypeID'\r\n\t\tlocal enum_ref_var_name = CSVariableName(type_info.Type)..'_EnumRef'\r\n        local full_type_name = CsFullTypeName(type_info.Type)\r\n\t\tlocal is_enum = type_info.Type.IsEnum\r\n        %>int <%=type_id_var_name%> = -1;<%if is_enum then%>\r\n\t\tint <%=enum_ref_var_name%> = -1;\r\n        <%end%>\r\n        public void Push<%=CSVariableName(type_info.Type)%>(RealStatePtr L, <%=full_type_name%> val)\r\n        {\r\n            if (<%=type_id_var_name%> == -1)\r\n            {\r\n\t\t\t    bool is_first;\r\n                <%=type_id_var_name%> = getTypeId(L, typeof(<%=full_type_name%>), out is_first);\r\n\t\t\t\t<%if is_enum then%>\r\n\t\t\t\tif (<%=enum_ref_var_name%> == -1)\r\n\t\t\t\t{\r\n\t\t\t\t    Utils.LoadCSTable(L, typeof(<%=full_type_name%>));\r\n\t\t\t\t    <%=enum_ref_var_name%> = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\t\t}\r\n\t\t\t\t<%end%>\r\n            }\r\n\t\t\t<%if is_enum then%>\r\n\t\t\tif (LuaAPI.xlua_tryget_cachedud(L, (int)val, <%=enum_ref_var_name%>) == 1)\r\n            {\r\n\t\t\t    return;\r\n\t\t\t}\r\n\t\t\t<%\r\n\t\t\tend\r\n\t\t\tif type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then\r\n\t\t\t%>\r\n\t\t\t<%if PushObjectNeedTranslator(type_info) then %>    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>\r\n\t\t\tLuaAPI.xlua_pushcstable(L, <%=type_info.FieldInfos.Count%>, <%=type_id_var_name%>);\r\n\t\t\t<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"<%=fieldInfo.Name%>\");\r\n\t\t\t<%=GetPushStatement(fieldInfo.Type, \"val.\"..fieldInfo.Name)%>;\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t<%end)%>\r\n\t\t\t<%else%>\r\n            IntPtr buff = LuaAPI.xlua_pushstruct(L, <%=is_enum and 4 or type_info.Size%>, <%=type_id_var_name%>);\r\n            if (!CopyByValue.Pack(buff, 0, <%=is_enum and \"(int)\" or \"\"%>val))\r\n            {\r\n                throw new Exception(\"pack fail fail for <%=full_type_name%> ,value=\"+val);\r\n            }\r\n\t\t\t<%\r\n\t\t\tend\r\n\t\t\tif is_enum then\r\n\t\t\t%>\r\n\t\t\tLuaAPI.lua_getref(L, <%=enum_ref_var_name%>);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\tLuaAPI.xlua_rawseti(L, -2, (int)val);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t<%end%>\r\n        }\r\n\t\t\r\n        public void Get(RealStatePtr L, int index, out <%=full_type_name%> val)\r\n        {\r\n\t\t    LuaTypes type = LuaAPI.lua_type(L, index);\r\n            if (type == LuaTypes.LUA_TUSERDATA )\r\n            {\r\n\t\t\t    if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)\r\n\t\t\t\t{\r\n\t\t\t\t    throw new Exception(\"invalid userdata for <%=full_type_name%>\");\r\n\t\t\t\t}\r\n\t\t\t\t\r\n                IntPtr buff = LuaAPI.lua_touserdata(L, index);<%if is_enum then%>\r\n\t\t\t\tint e;\r\n                <%end%>if (!CopyByValue.UnPack(buff, 0, out <%=is_enum and \"e\" or \"val\"%>))\r\n                {\r\n                    throw new Exception(\"unpack fail for <%=full_type_name%>\");\r\n                }<%if is_enum then%>\r\n\t\t\t\tval = (<%=full_type_name%>)e;\r\n                <%end%>\r\n            }<%if not is_enum then%>\r\n\t\t\telse if (type ==LuaTypes.LUA_TTABLE)\r\n\t\t\t{\r\n\t\t\t    CopyByValue.UnPack(this, L, index, out val);\r\n\t\t\t}<%end%>\r\n            else\r\n            {\r\n                val = (<%=full_type_name%>)objectCasters.GetCaster(typeof(<%=full_type_name%>))(L, index, null);\r\n            }\r\n        }\r\n\t\t\r\n        public void Update<%=CSVariableName(type_info.Type)%>(RealStatePtr L, int index, <%=full_type_name%> val)\r\n        {\r\n\t\t    <%if type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then%>\r\n\t\t\tif (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TTABLE)\r\n            {\r\n\t\t\t    return;\r\n\t\t\t}\r\n\t\t\t<%else%>\r\n            if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)\r\n            {\r\n\t\t\t    if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)\r\n\t\t\t\t{\r\n\t\t\t\t    throw new Exception(\"invalid userdata for <%=full_type_name%>\");\r\n\t\t\t\t}\r\n\t\t\t\t\r\n                IntPtr buff = LuaAPI.lua_touserdata(L, index);\r\n                if (!CopyByValue.Pack(buff, 0,  <%=is_enum and \"(int)\" or \"\"%>val))\r\n                {\r\n                    throw new Exception(\"pack fail for <%=full_type_name%> ,value=\"+val);\r\n                }\r\n            }\r\n\t\t\t<%end%>\r\n            else\r\n            {\r\n                throw new Exception(\"try to update a data with lua type:\" + LuaAPI.lua_type(L, index));\r\n            }\r\n        }\r\n        \r\n        <%end)%>\r\n\t\t// table cast optimze\r\n\t\t<%ForEachCsList(tableoptimzetypes, function(type_info)\r\n\t\tlocal full_type_name = CsFullTypeName(type_info.Type)\r\n\t\t%>\r\n\t\tpublic void Get(RealStatePtr L, int index, out <%=full_type_name%> val)\r\n        {\r\n\t\t    LuaTypes type = LuaAPI.lua_type(L, index);\r\n            if (type == LuaTypes.LUA_TUSERDATA )\r\n            {\r\n\t\t\t    val = (<%=full_type_name%>)FastGetCSObj(L, index);\r\n            }\r\n\t\t\telse if (type == LuaTypes.LUA_TTABLE)\r\n\t\t\t{\r\n\t\t\t    val = new <%=full_type_name%>();\r\n\t\t\t\tint top = LuaAPI.lua_gettop(L);\r\n\t\t\t\t<%ForEachCsList(type_info.Fields, function(fieldInfo)%>\r\n\t\t\t\tif (Utils.LoadField(L, index, \"<%=fieldInfo.Name%>\"))\r\n\t\t\t\t{\r\n\t\t\t\t\tGet(L, top + 1, out val.<%=fieldInfo.Name%>);\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\t<%end)%>\r\n\t\t\t}<%if not type_info.Type.IsValueType then%>\r\n            else if (type == LuaTypes.LUA_TNIL || type == LuaTypes.LUA_TNONE)\r\n            {\r\n                val = null;\r\n            }<%end%>\r\n            else\r\n            {\r\n                throw new Exception(\"can not cast \" + LuaAPI.lua_type(L, index) + \" to \" + typeof(<%=full_type_name%>));\r\n            }\r\n        }\r\n\t\t<%end)%>\r\n        \r\n    }\r\n\t\r\n\tpublic partial class StaticLuaCallbacks\r\n    {\r\n\t    internal static bool __tryArrayGet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int index)\r\n\t\t{\r\n\t\t<%ForEachCsList(purevaluetypes, function(type_info, idx)\r\n\t\tif not type_info.Type.IsValueType then return end\r\n\t\tlocal full_type_name = CsFullTypeName(type_info.Type)\r\n\t\t%>\r\n\t\t\t<%=(idx == 0 and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))\r\n\t\t\t{\r\n\t\t\t    <%=full_type_name%>[] array = obj as <%=full_type_name%>[];\r\n\t\t\t\ttranslator.Push<%=CSVariableName(type_info.Type)%>(L, array[index]);\r\n\t\t\t\treturn true;\r\n\t\t\t}<%\r\n\t\tend)%>\r\n            return false;\r\n\t\t}\r\n\t\t\r\n\t\tinternal static bool __tryArraySet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int array_idx, int obj_idx)\r\n\t\t{\r\n\t\t<%\r\n\t\tlocal is_first = true\r\n\t\tForEachCsList(purevaluetypes, tableoptimzetypes, function(type_info)\r\n\t\tlocal full_type_name = CsFullTypeName(type_info.Type)\r\n\t\t%>\r\n\t\t\t<%=(is_first and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))\r\n\t\t\t{\r\n\t\t\t    <%=full_type_name%>[] array = obj as <%=full_type_name%>[];\r\n\t\t\t\ttranslator.Get(L, obj_idx, out array[array_idx]);\r\n\t\t\t\treturn true;\r\n\t\t\t}<%\r\n\t\t    is_first = false\r\n\t\tend)%>\r\n            return false;\r\n\t\t}\r\n\t}\r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/LuaWrapPusher.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: d1a916469d261d447972d287b6c5b7a0\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt",
    "content": "#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\n<%\r\nrequire \"TemplateCommon\"\r\n%>\r\n\r\nnamespace XLua\r\n{\r\n    public static partial class CopyByValue\r\n    {\r\n        <%ForEachCsList(type_infos, function(type_info)\r\n        local full_type_name = CsFullTypeName(type_info.Type)\r\n        %>\r\n\t\t<%if type_info.IsRoot then\r\n\t\tForEachCsList(type_info.FieldInfos, function(fieldInfo) fieldInfo.Name = UnK(fieldInfo.Name) end)\r\n\t\t%>\r\n\t\tpublic static void UnPack(ObjectTranslator translator, RealStatePtr L, int idx, out <%=full_type_name%> val)\r\n\t\t{\r\n\t\t    val = new <%=full_type_name%>();\r\n            int top = LuaAPI.lua_gettop(L);\r\n\t\t\t<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>\r\n\t\t\tif (Utils.LoadField(L, idx, \"<%=fieldInfo.Name%>\"))\r\n            {\r\n\t\t\t    <%if fieldInfo.IsField then%>\r\n                translator.Get(L, top + 1, out val.<%=fieldInfo.Name%>);\r\n\t\t\t\t<%else%>\r\n\t\t\t\tvar <%=fieldInfo.Name%> = val.<%=fieldInfo.Name%>;\r\n\t\t\t\ttranslator.Get(L, top + 1, out <%=fieldInfo.Name%>);\r\n\t\t\t\tval.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;\r\n\t\t\t\t<%end%>\r\n            }\r\n            LuaAPI.lua_pop(L, 1);\r\n\t\t\t<%end)%>\r\n\t\t}\r\n\t\t<%end%>\r\n        public static bool Pack(IntPtr buff, int offset, <%=full_type_name%> field)\r\n        {\r\n            <%\r\n            local offset_inner = 0\r\n            if not type_info.FieldGroup then\r\n            ForEachCsList(type_info.FieldInfos, function(fieldInfo)\r\n            %>\r\n            if(!Pack(buff, offset<%=(offset_inner == 0 and \"\" or (\" + \" .. offset_inner))%>, field.<%=fieldInfo.Name%>))\r\n            {\r\n                return false;\r\n            }\r\n            <%\r\n            offset_inner = offset_inner + fieldInfo.Size\r\n            end)\r\n            else\r\n            ForEachCsList(type_info.FieldGroup, function(group)\r\n            %>\r\n            if(!LuaAPI.xlua_pack_float<%=(group.Count == 1 and \"\" or group.Count)%>(buff, offset<%=(offset_inner == 0 and \"\" or (\" + \" .. offset_inner))%><%\r\n            ForEachCsList(group, function(fieldInfo, i)\r\n            %>, field.<%=fieldInfo.Name%><%\r\n            end)\r\n            %>))\r\n            {\r\n                return false;\r\n            }\r\n            <%\r\n            offset_inner = offset_inner + group.Count * 4\r\n            end)\r\n            end%>\r\n            return true;\r\n        }\r\n        public static bool UnPack(IntPtr buff, int offset, out <%=full_type_name%> field)\r\n        {\r\n            field = default(<%=full_type_name%>);\r\n            <%\r\n            local offset_inner = 0\r\n            if not type_info.FieldGroup then\r\n            ForEachCsList(type_info.FieldInfos, function(fieldInfo)\r\n            if fieldInfo.IsField then\r\n            %>\r\n            if(!UnPack(buff, offset<%=(offset_inner == 0 and \"\" or (\" + \" .. offset_inner))%>, out field.<%=fieldInfo.Name%>))\r\n            {\r\n                return false;\r\n            }\r\n            <%else%>\r\n            var <%=fieldInfo.Name%> = field.<%=fieldInfo.Name%>;\r\n            if(!UnPack(buff, offset<%=(offset_inner == 0 and \"\" or (\" + \" .. offset_inner))%>, out <%=fieldInfo.Name%>))\r\n            {\r\n                return false;\r\n            }\r\n            field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;\r\n            <%\r\n            end\r\n            offset_inner = offset_inner + fieldInfo.Size\r\n            end)\r\n            else\r\n            ForEachCsList(type_info.FieldGroup, function(group)\r\n            %>\r\n            <%ForEachCsList(group, function(fieldInfo)%>float <%=fieldInfo.Name%> = default(float);\r\n            <%end)%>\r\n            if(!LuaAPI.xlua_unpack_float<%=(group.Count == 1 and \"\" or group.Count)%>(buff, offset<%=(offset_inner == 0 and \"\" or (\" + \" .. offset_inner))%><%\r\n            ForEachCsList(group, function(fieldInfo)\r\n            %>, out <%=fieldInfo.Name%><%\r\n            end)\r\n            %>))\r\n            {\r\n                return false;\r\n            }\r\n            <%ForEachCsList(group, function(fieldInfo)%>field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;\r\n            <%end)%>\r\n            <%\r\n            offset_inner = offset_inner + group.Count * 4\r\n            end)\r\n            end%>\r\n            return true;\r\n        }\r\n        <%end)%>\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/PackUnpack.tpl.txt.meta",
    "content": "fileFormatVersion: 2\nguid: c9ef7e8f2a3b37744aad49b99370c16b\ntimeCreated: 1481620508\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt",
    "content": "-- Tencent is pleased to support the open source community by making xLua available.\r\n-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n-- Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n-- http://opensource.org/licenses/MIT\r\n-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\nlocal friendlyNameMap = {\r\n\t[\"System.Object\"] = \"object\",\r\n\t[\"System.String\"] = \"string\",\r\n\t[\"System.Boolean\"] = \"bool\",\r\n\t[\"System.Byte\"] = \"byte\",\r\n\t[\"System.Char\"] = \"char\",\r\n\t[\"System.Decimal\"] = \"decimal\",\r\n\t[\"System.Double\"] = \"double\",\r\n\t[\"System.Int16\"] = \"short\",\r\n\t[\"System.Int32\"] = \"int\",\r\n\t[\"System.Int64\"] = \"long\",\r\n\t[\"System.SByte\"] = \"sbyte\",\r\n\t[\"System.Single\"] = \"float\",\r\n\t[\"System.UInt16\"] = \"ushort\",\r\n\t[\"System.UInt32\"] = \"uint\",\r\n\t[\"System.UInt64\"] = \"ulong\",\r\n\t[\"System.Void\"] = \"void\",\r\n}\r\n\r\nlocal csKeywords = {\r\n\"abstract\", \"as\", \"base\", \"bool\",\r\n\"break\", \"byte\", \"case\", \"catch\",\r\n\"char\", \"checked\", \"class\", \"const\",\r\n\"continue\", \"decimal\", \"default\", \"delegate\",\r\n\"do\", \"double\", \"else\", \"enum\",\r\n\"event\", \"explicit\", \"extern\", \"false\",\r\n\"finally\", \"fixed\", \"float\", \"for\",\r\n\"foreach\", \"goto\", \"if\", \"implicit\",\r\n\"in\", \"int\", \"interface\",\r\n\"internal\", \"is\", \"lock\", \"long\",\r\n\"namespace\", \"new\", \"null\", \"object\",\r\n\"operator\", \"out\", \"override\",\r\n\"params\", \"private\", \"protected\", \"public\",\r\n\"readonly\", \"ref\", \"return\", \"sbyte\",\r\n\"sealed\", \"short\", \"sizeof\", \"stackalloc\",\r\n\"static\", \"string\", \"struct\", \"switch\",\r\n\"this\", \"throw\", \"true\", \"try\",\r\n\"typeof\", \"uint\", \"ulong\", \"unchecked\",\r\n\"unsafe\", \"ushort\", \"using\", \"virtual\",\r\n\"void\", \"volatile\", \"while\"\r\n}\r\n\r\nfor _, kw in ipairs(csKeywords) do\r\n    csKeywords[kw] = '@'..kw\r\nend\r\nfor i = 1, #csKeywords do\r\n    csKeywords[i] = nil\r\nend\r\n\r\nfunction UnK(symbol)\r\n    return csKeywords[symbol] or symbol\r\nend\r\n\r\nlocal fixChecker = {\r\n    --[\"System.String\"] = \"LuaAPI.lua_isstring\",\r\n\t[\"System.Boolean\"] = \"LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type\",\r\n\t[\"System.Byte\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.Char\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t--[\"System.Decimal\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.Double\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.Int16\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.Int32\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t--[\"System.Int64\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.SByte\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.Single\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.UInt16\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.UInt32\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t--[\"System.UInt64\"] = \"LuaTypes.LUA_TNUMBER == LuaAPI.lua_type\",\r\n\t[\"System.IntPtr\"] = \"LuaTypes.LUA_TLIGHTUSERDATA == LuaAPI.lua_type\",\r\n}\r\n\r\nlocal typedCaster = {\r\n\t[\"System.Byte\"] = \"LuaAPI.xlua_tointeger\",\r\n\t[\"System.Char\"] = \"LuaAPI.xlua_tointeger\",\r\n\t[\"System.Int16\"] = \"LuaAPI.xlua_tointeger\",\r\n\t[\"System.SByte\"] = \"LuaAPI.xlua_tointeger\",\r\n\t[\"System.Single\"] = \"LuaAPI.lua_tonumber\",\r\n\t[\"System.UInt16\"] = \"LuaAPI.xlua_tointeger\",\r\n}\r\n\r\nlocal fixCaster = {\r\n\t[\"System.Double\"] = \"LuaAPI.lua_tonumber\",\r\n    [\"System.String\"] = \"LuaAPI.lua_tostring\",\r\n\t[\"System.Boolean\"] = \"LuaAPI.lua_toboolean\",\r\n    [\"System.Byte[]\"] = \"LuaAPI.lua_tobytes\",\r\n\t[\"System.IntPtr\"] = \"LuaAPI.lua_touserdata\",\r\n\t[\"System.UInt32\"] = \"LuaAPI.xlua_touint\",\r\n\t[\"System.UInt64\"] = \"LuaAPI.lua_touint64\",\r\n\t[\"System.Int32\"] = \"LuaAPI.xlua_tointeger\",\r\n\t[\"System.Int64\"] = \"LuaAPI.lua_toint64\",\r\n}\r\n\r\nlocal fixPush = {\r\n\t[\"System.Byte\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.Char\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.Int16\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.Int32\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.Int64\"] = \"LuaAPI.lua_pushint64\",\r\n\t[\"System.SByte\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.Single\"] = \"LuaAPI.lua_pushnumber\",\r\n\t[\"System.UInt16\"] = \"LuaAPI.xlua_pushinteger\",\r\n\t[\"System.UInt32\"] = \"LuaAPI.xlua_pushuint\",\r\n\t[\"System.UInt64\"] = \"LuaAPI.lua_pushuint64\",\r\n    [\"System.Double\"] = \"LuaAPI.lua_pushnumber\",\r\n    [\"System.String\"] = \"LuaAPI.lua_pushstring\",\r\n\t[\"System.Byte[]\"] = \"LuaAPI.lua_pushstring\",\r\n\t[\"System.Boolean\"] = \"LuaAPI.lua_pushboolean\",\r\n\t[\"System.IntPtr\"] = \"LuaAPI.lua_pushlightuserdata\",\r\n\t[\"System.Decimal\"] = \"translator.PushDecimal\",\r\n\t[\"System.Object\"] = \"translator.PushAny\",\r\n}\r\n\r\nlocal notranslator = {\r\n\t[\"System.Byte\"] = true,\r\n\t[\"System.Char\"] = true,\r\n\t[\"System.Int16\"] = true,\r\n\t[\"System.Int32\"] = true,\r\n\t[\"System.Int64\"] = true,\r\n\t[\"System.SByte\"] = true,\r\n\t[\"System.Single\"] = true,\r\n\t[\"System.UInt16\"] = true,\r\n\t[\"System.UInt32\"] = true,\r\n\t[\"System.UInt64\"] = true,\r\n    [\"System.Double\"] = true,\r\n    [\"System.String\"] = true,\r\n\t[\"System.Boolean\"] = true,\r\n    [\"System.Void\"] = true,\r\n\t[\"System.IntPtr\"] = true,\r\n\t[\"System.Byte[]\"] = true,\r\n}\r\n\r\nfunction ForEachCsList(...)\r\n    local list_count = select('#', ...) - 1\r\n\tlocal callback = select(list_count + 1, ...)\r\n\tfor i = 1, list_count do\r\n\t    local list = select(i, ...)\r\n\t\tfor i = 0, (list.Count or list.Length) - 1 do \r\n\t\t\tcallback(list[i], i)\r\n\t\tend\r\n\tend\r\nend\r\n\r\nfunction CalcCsList(list, predicate)\r\n    local count = 0\r\n    for i = 0, (list.Count or list.Length) - 1 do \r\n        if predicate(list[i], i) then count = count + 1 end\r\n    end\r\n    return count\r\nend\r\n\r\nfunction IfAny(list, predicate)\r\n    for i = 0, (list.Count or list.Length) - 1 do \r\n        if predicate(list[i], i) then return true end\r\n    end\r\n    return false\r\nend\r\n\r\nlocal genPushAndUpdateTypes\r\n\r\nfunction SetGenPushAndUpdateTypes(list)\r\n    genPushAndUpdateTypes = {}\r\n    ForEachCsList(list, function(t)\r\n        genPushAndUpdateTypes[t] = true\r\n    end)\r\nend\r\n\r\nlocal xLuaClasses\r\nfunction SetXLuaClasses(list)\r\n    xLuaClasses = {}\r\n\tForEachCsList(list, function(t)\r\n        xLuaClasses[t.Name] = true\r\n    end)\r\nend\r\n\r\nlocal objType = typeof(CS.System.Object)\r\nlocal valueType = typeof(CS.System.ValueType)\r\n\r\nlocal function _CsFullTypeName(t)\r\n    if t.IsArray then\r\n\t    local element_name, element_is_array = _CsFullTypeName(t:GetElementType())\r\n\t\tif element_is_array then\r\n\t\t    local bracket_pos = element_name:find('%[')\r\n\t\t\treturn element_name:sub(1, bracket_pos - 1) .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']' .. element_name:sub(bracket_pos, -1), true\r\n\t\telse\r\n            return element_name .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']', true\r\n\t    end\r\n    elseif t.IsByRef then\r\n        return _CsFullTypeName(t:GetElementType())\r\n    elseif t.IsGenericParameter then\r\n        return (t.BaseType == objType or t.BaseType == valueType) and t.Name or _CsFullTypeName(t.BaseType) --TODO:应该判断是否类型约束\r\n    end\r\n\r\n    local name = t.FullName:gsub(\"&\", \"\"):gsub(\"%+\", \".\") \r\n    if not t.IsGenericType then \r\n        return friendlyNameMap[name] or name\r\n    end\r\n\tlocal genericParameter = \"\"\r\n    ForEachCsList(t:GetGenericArguments(), function(at, ati)\r\n        if ati ~= 0 then  genericParameter = genericParameter .. ', ' end\r\n        genericParameter = genericParameter .. _CsFullTypeName(at)\r\n    end)\r\n    return name:gsub(\"`%d+\", '<' .. genericParameter .. '>'):gsub(\"%[[^,%]].*\", \"\"), false\r\nend\r\n\r\nfunction CsFullTypeName(t)\r\n    if t.DeclaringType then\r\n        local name = _CsFullTypeName(t)\r\n        local declaringTypeName = _CsFullTypeName(t.DeclaringType);\r\n        return xLuaClasses[declaringTypeName] and (\"global::\" .. name) or name\r\n    else\r\n        local name = _CsFullTypeName(t)\r\n        return xLuaClasses[name] and (\"global::\" .. name) or name\r\n    end\r\nend\r\n\r\nfunction CSVariableName(t)\r\n    if t.IsArray then\r\n\t    return CSVariableName(t:GetElementType()) .. '_'.. t:GetArrayRank() ..'_'\r\n\tend\r\n    return t:ToString():gsub(\"&\", \"\"):gsub(\"%+\", \"\"):gsub(\"`\", \"_\"):gsub(\"%.\", \"\"):gsub(\"%[\", \"_\"):gsub(\"%]\", \"_\"):gsub(\",\", \"\")\r\nend\r\n\r\nlocal function getSafeFullName(t)\r\n    if t == nil then\r\n        return \"\"\r\n    end\r\n\r\n    if t.IsGenericParameter then\r\n        return t.BaseType == objType and t.Name or getSafeFullName(t.BaseType)\r\n    end\r\n\t\r\n\tif not t.FullName then return \"\" end\r\n\r\n    return t.FullName:gsub(\"&\", \"\")\r\nend\r\n\r\nfunction GetCheckStatement(t, idx, is_v_params)\r\n    local cond_start = is_v_params and \"(LuaTypes.LUA_TNONE == LuaAPI.lua_type(L, \".. idx ..\") || \" or \"\"\r\n\tlocal cond_end = is_v_params and \")\" or \"\"\r\n    local testname = getSafeFullName(t)\r\n    if testname ==  \"System.String\" or testname == \"System.Byte[]\" then\r\n        return cond_start .. \"(LuaAPI.lua_isnil(L, \" .. idx .. \") || LuaAPI.lua_type(L, \".. idx ..\") == LuaTypes.LUA_TSTRING)\" .. cond_end\r\n    elseif testname == \"System.Int64\" then\r\n        return cond_start .. \"(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, \".. idx ..\") || LuaAPI.lua_isint64(L, \".. idx ..\"))\" .. cond_end\r\n    elseif testname == \"System.UInt64\" then\r\n        return cond_start .. \"(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, \".. idx ..\") || LuaAPI.lua_isuint64(L, \".. idx ..\"))\" .. cond_end\r\n    elseif testname == \"System.Decimal\" then\r\n\t    return cond_start .. \"(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, \".. idx ..\") || translator.IsDecimal(L, \".. idx ..\"))\" .. cond_end\r\n    elseif testname == \"XLua.LuaTable\" then\r\n        return cond_start .. \"(LuaAPI.lua_isnil(L, \" .. idx .. \") || LuaAPI.lua_type(L, \".. idx ..\") == LuaTypes.LUA_TTABLE)\" .. cond_end\r\n\telseif testname == \"XLua.LuaFunction\" then\r\n        return cond_start .. \"(LuaAPI.lua_isnil(L, \" .. idx .. \") || LuaAPI.lua_type(L, \".. idx ..\") == LuaTypes.LUA_TFUNCTION)\" .. cond_end\r\n    end\r\n    return cond_start .. (fixChecker[testname] or (\"translator.Assignable<\" .. CsFullTypeName(t).. \">\")) .. \"(L, \".. idx ..\")\" .. cond_end\r\nend\r\n\r\nlocal delegateType = typeof(CS.System.Delegate)\r\nlocal ExtensionAttribute = typeof(CS.System.Runtime.CompilerServices.ExtensionAttribute)\r\n\r\nfunction IsExtensionMethod(method)\r\n    return method:IsDefined(ExtensionAttribute, false)\r\nend\r\n\r\nfunction IsDelegate(t)\r\n    return delegateType:IsAssignableFrom(t)\r\nend\r\n\r\nfunction MethodParameters(method)\r\n    if not IsExtensionMethod(method) then\r\n        return method:GetParameters()\r\n    else\r\n        local parameters = method:GetParameters()\r\n\t\tif parameters[0].ParameterType.IsInterface then\r\n\t\t    return parameters\r\n\t\tend\r\n        local ret = {}\r\n        for i = 1, parameters.Length - 1 do \r\n            ret[i - 1] = parameters[i]\r\n        end\r\n        ret.Length = parameters.Length - 1\r\n        return ret\r\n    end\r\nend\r\n\r\nfunction IsStruct(t)\r\n    if t.IsByRef then t = t:GetElementType() end\r\n    return t.IsValueType and not t.IsPrimitive\r\nend\r\n\r\nfunction NeedUpdate(t)\r\n    if t.IsByRef then t = t:GetElementType() end\r\n    return t.IsValueType and not t.IsPrimitive and not t.IsEnum and t ~= typeof(CS.System.Decimal)\r\nend\r\n\r\nfunction GetCasterStatement(t, idx, var_name, need_declare, is_v_params)\r\n    local testname = getSafeFullName(t)\r\n\tlocal statement = \"\"\r\n    local is_struct = IsStruct(t)\r\n\t\r\n    if need_declare then\r\n        statement = CsFullTypeName(t) .. \" \" .. var_name\r\n        if is_struct and not typedCaster[testname] and not fixCaster[testname] then\r\n            statement = statement .. \";\"\r\n        else\r\n            statement = statement .. \" = \"\r\n        end\r\n    elseif not is_struct then\r\n\t    statement = var_name .. \" = \"\r\n    end\r\n\t\r\n    if is_v_params then\r\n        return statement .. \"translator.GetParams<\" .. CsFullTypeName(t:GetElementType()).. \">\" .. \"(L, \".. idx ..\")\" \r\n    elseif typedCaster[testname] then\r\n        return statement .. \"(\" .. CsFullTypeName(t) .. \")\" ..typedCaster[testname] .. \"(L, \".. idx ..\")\" \r\n\telseif IsDelegate(t) then\r\n\t    return statement .. \"translator.GetDelegate<\" .. CsFullTypeName(t).. \">\" .. \"(L, \".. idx ..\")\" \r\n    elseif fixCaster[testname] then\r\n        return statement .. fixCaster[testname] .. \"(L, \".. idx ..\")\" \r\n    elseif testname == \"System.Object\" then\r\n        return statement .. \"translator.GetObject(L, \".. idx ..\", typeof(\" .. CsFullTypeName(t) ..\"))\"\r\n    elseif is_struct then\r\n        return statement .. \"translator.Get(L, \".. idx ..\", out \" .. var_name .. \")\"\r\n\telseif t.IsGenericParameter and not t.DeclaringMethod then\r\n\t    return statement .. \"translator.GetByType<\"..t.Name..\">(L, \".. idx ..\")\" \r\n    else\r\n        return statement .. \"(\"..CsFullTypeName(t)..\")translator.GetObject(L, \".. idx ..\", typeof(\" .. CsFullTypeName(t) ..\"))\" \r\n    end\r\nend\r\n\r\nlocal paramsAttriType = typeof(CS.System.ParamArrayAttribute)\r\nfunction IsParams(pi)\r\n    if (not pi.IsDefined) then\r\n        return pi.IsParamArray\r\n    end\r\n    return pi:IsDefined(paramsAttriType, false)\r\nend\r\n\r\nlocal obsoluteAttriType = typeof(CS.System.ObsoleteAttribute)\r\nfunction IsObsolute(f)\r\n    return f:IsDefined(obsoluteAttriType, false)\r\nend\r\n\r\nlocal objectType = typeof(CS.System.Object)\r\nfunction GetSelfStatement(t)\r\n    local fulltypename = CsFullTypeName(t)\r\n    local is_struct = IsStruct(t)\r\n    if is_struct then\r\n\t    return fulltypename .. \" gen_to_be_invoked;translator.Get(L, 1, out gen_to_be_invoked)\"\r\n\telse\r\n\t    if t == objectType then\r\n            return \"object gen_to_be_invoked = translator.FastGetCSObj(L, 1)\"\r\n        else\r\n            return fulltypename .. \" gen_to_be_invoked = (\" .. fulltypename .. \")translator.FastGetCSObj(L, 1)\"\r\n        end\r\n\tend\r\n    \r\nend\r\n\r\nlocal GetNullableUnderlyingType = CS.System.Nullable.GetUnderlyingType\r\n\r\nfunction GetPushStatement(t, variable, is_v_params)\r\n    if is_v_params then\r\n\t    local item_push = GetPushStatement(t:GetElementType(), variable..'[__gen_i]')\r\n\t\treturn 'if ('.. variable ..' != null)  { for (int __gen_i = 0; __gen_i < ' .. variable .. '.Length; ++__gen_i) ' .. item_push .. '; }'\r\n\tend\r\n    if t.IsByRef then t = t:GetElementType() end\r\n    local testname = getSafeFullName(t)\r\n    if fixPush[testname] then\r\n        return fixPush[testname] .. \"(L, \".. variable ..\")\" \r\n    elseif genPushAndUpdateTypes[t] then\r\n        return \"translator.Push\".. CSVariableName(t) ..\"(L, \"..variable..\")\"\r\n    elseif t.IsGenericParameter and not t.DeclaringMethod then\r\n\t    return \"translator.PushByType(L, \"..variable..\")\"\r\n\telseif t.IsInterface or GetNullableUnderlyingType(t) then\r\n\t    return \"translator.PushAny(L, \"..variable..\")\"\r\n    else\r\n        return \"translator.Push(L, \"..variable..\")\"\r\n    end\r\nend\r\n\r\nfunction GetUpdateStatement(t, idx, variable)\r\n    if t.IsByRef then t = t:GetElementType() end\r\n    if typeof(CS.System.Decimal) == t then error('Decimal not update!') end\r\n    if genPushAndUpdateTypes[t] then\r\n        return \"translator.Update\".. CSVariableName(t) ..\"(L, \".. idx ..\", \"..variable..\")\"\r\n    else\r\n        return \"translator.Update(L, \".. idx ..\", \"..variable..\")\"\r\n    end\r\nend\r\n\r\nfunction JustLuaType(t)\r\n    return notranslator[getSafeFullName(t)]\r\nend\r\n\r\nfunction CallNeedTranslator(overload, isdelegate)\r\n    if not overload.IsStatic and not isdelegate then return true end\r\n\tlocal ret_type_name = getSafeFullName(overload.ReturnType)\r\n    if not notranslator[ret_type_name] then return true end \r\n    local parameters = overload:GetParameters()\r\n    return IfAny(overload:GetParameters(), function(parameter) \r\n        return IsParams(parameter) or (not notranslator[getSafeFullName(parameter.ParameterType)])\r\n    end)\r\nend\r\n\r\nfunction MethodCallNeedTranslator(method)\r\n    return IfAny(method.Overloads, function(overload) return CallNeedTranslator(overload) end)\r\nend\r\n\r\nfunction AccessorNeedTranslator(accessor)\r\n    return not accessor.IsStatic or not JustLuaType(accessor.Type)\r\nend\r\n\r\nfunction PushObjectNeedTranslator(type_info)\r\n    return IfAny(type_info.FieldInfos, function(field_info) return not JustLuaType(field_info.Type) end)\r\nend\r\n\r\nlocal GenericParameterAttributes = CS.System.Reflection.GenericParameterAttributes\r\nlocal enum_and_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__band\r\nlocal has_generic_flag = function(f1, f2)\r\n    return (f1 ~= GenericParameterAttributes.None) and (enum_and_op(f1, f2) == f2)\r\nend\r\n\r\nfunction GenericArgumentList(type)\r\n    local generic_arg_list = \"\"\r\n    local type_constraints = \"\"\r\n    if type.IsGenericTypeDefinition then\r\n        generic_arg_list = \"<\"\r\n        \r\n        local constraints = {}\r\n        \r\n        ForEachCsList(type:GetGenericArguments(), function(generic_arg, gai)\r\n            local constraint = {}\r\n            if gai ~= 0 then generic_arg_list = generic_arg_list .. \", \" end\r\n            \r\n            generic_arg_list = generic_arg_list .. generic_arg.Name\r\n            \r\n            if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.ReferenceTypeConstraint) then\r\n                table.insert(constraint, 'class')\r\n            end\r\n            if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then\r\n                table.insert(constraint, 'struct')\r\n            end\r\n            ForEachCsList(generic_arg:GetGenericParameterConstraints(), function(gpc)\r\n                if gpc ~= typeof(CS.System.ValueType) or not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then\r\n                    table.insert(constraint, CsFullTypeName(gpc))\r\n                end\r\n            end)\r\n            if not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) and has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.DefaultConstructorConstraint) then\r\n                table.insert(constraint, 'new()')\r\n            end\r\n            if #constraint > 0 then\r\n                table.insert(constraints, 'where ' .. generic_arg.Name .. ' : ' .. table.concat(constraint, ','))\r\n            end\r\n        end)\r\n        generic_arg_list = generic_arg_list .. \">\"\r\n        if #constraints > 0 then\r\n            type_constraints = table.concat(constraints, ',')\r\n        end\r\n    end\r\n    return generic_arg_list, type_constraints\r\nend\r\n\r\nfunction LocalName(name)\r\n    return \"_\" .. name\r\nend\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template/TemplateCommon.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: cb41d53afe75a9443b182e284298feeb\nTextScriptImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/Template.meta",
    "content": "fileFormatVersion: 2\nguid: 9c7307955fb71fc4090eb2a906a78a0a\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor/TemplateRef.cs",
    "content": "﻿using UnityEngine;\r\nusing System.Collections;\r\nnamespace XLua\r\n{\r\n    public class TemplateRef : ScriptableObject\r\n    {\r\n        public TextAsset LuaClassWrap;\r\n        public TextAsset LuaClassWrapGCM;\r\n        public TextAsset LuaDelegateBridge;\r\n        public TextAsset LuaDelegateWrap;\r\n        public TextAsset LuaEnumWrap;\r\n        public TextAsset LuaEnumWrapGCM;\r\n        public TextAsset LuaInterfaceBridge;\r\n        public TextAsset LuaRegister;\r\n        public TextAsset LuaRegisterGCM;\r\n        public TextAsset LuaWrapPusher;\r\n        public TextAsset PackUnpack;\r\n        public TextAsset TemplateCommon;\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Editor/TemplateRef.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 4898604144dd928468ddca1af81d58ae\ntimeCreated: 1501232546\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences:\n  - LuaClassWrap: {fileID: 4900000, guid: 8503038eabbabe44dac0f5f749d4411a, type: 3}\n  - LuaClassWrapGCM: {fileID: 4900000, guid: 2bd79d95fd859724283926ad8fa4df30, type: 3}\n  - LuaDelegateBridge: {fileID: 4900000, guid: 3d992756e2469044484be75f78e4e556, type: 3}\n  - LuaDelegateWrap: {fileID: 4900000, guid: 33b33e1cd617f794b8c801a32f3b2539, type: 3}\n  - LuaEnumWrap: {fileID: 4900000, guid: ae16c73aad9a21a44aef65decb7e4928, type: 3}\n  - LuaEnumWrapGCM: {fileID: 4900000, guid: ea84a5ee7abf8e347a810eb7848add46, type: 3}\n  - LuaInterfaceBridge: {fileID: 4900000, guid: 7165d08e91378494dadeb10e5338accb,\n      type: 3}\n  - LuaRegister: {fileID: 4900000, guid: e416b82ec9fe340458f97cf1e3468ef7, type: 3}\n  - LuaRegisterGCM: {fileID: 4900000, guid: 46c7366d55afbf1459674448d92c44c8, type: 3}\n  - LuaWrapPusher: {fileID: 4900000, guid: d1a916469d261d447972d287b6c5b7a0, type: 3}\n  - PackUnpack: {fileID: 4900000, guid: c9ef7e8f2a3b37744aad49b99370c16b, type: 3}\n  - TemplateCommon: {fileID: 4900000, guid: cb41d53afe75a9443b182e284298feeb, type: 3}\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Editor.meta",
    "content": "fileFormatVersion: 2\nguid: 1e53aa922da0a00469e5760902833e71\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/GenAttributes.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace XLua\r\n{\r\n    public enum GenFlag\r\n    {\r\n        No = 0,\r\n        [Obsolete(\"use GCOptimizeAttribute instead\")]\r\n        GCOptimize = 1\r\n    }\r\n\r\n    //如果你要生成Lua调用CSharp的代码，加这个标签\r\n    public class LuaCallCSharpAttribute : Attribute\r\n    {\r\n        GenFlag flag;\r\n        public GenFlag Flag {\r\n            get\r\n            {\r\n                return flag;\r\n            }\r\n        }\r\n\r\n        public LuaCallCSharpAttribute(GenFlag flag = GenFlag.No)\r\n        {\r\n            this.flag = flag;\r\n        }\r\n    }\r\n\r\n    //生成CSharp调用Lua，加这标签\r\n    //[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Interface)]\r\n    public class CSharpCallLuaAttribute : Attribute\r\n    {\r\n    }\r\n\r\n    //如果某属性、方法不需要生成，加这个标签\r\n    public class BlackListAttribute : Attribute\r\n    {\r\n\r\n    }\r\n\r\n    [Flags]\r\n    public enum OptimizeFlag\r\n    {\r\n        Default = 0,\r\n        PackAsTable = 1\r\n    }\r\n\r\n    //如果想对struct生成免GC代码，加这个标签\r\n    public class GCOptimizeAttribute : Attribute\r\n    {\r\n        OptimizeFlag flag;\r\n        public OptimizeFlag Flag\r\n        {\r\n            get\r\n            {\r\n                return flag;\r\n            }\r\n        }\r\n\r\n        public GCOptimizeAttribute(OptimizeFlag flag = OptimizeFlag.Default)\r\n        {\r\n            this.flag = flag;\r\n        }\r\n    }\r\n\r\n    //如果想在反射下使用，加这个标签\r\n    public class ReflectionUseAttribute : Attribute\r\n    {\r\n\r\n    }\r\n\r\n    //只能标注Dictionary<Type, List<string>>的field或者property\r\n    public class DoNotGenAttribute : Attribute\r\n    {\r\n        \r\n    }\r\n\r\n    public class AdditionalPropertiesAttribute : Attribute\r\n    {\r\n\r\n    }\r\n\r\n    [Flags]\r\n    public enum HotfixFlag\r\n    {\r\n        Stateless = 0,\r\n        [Obsolete(\"use xlua.util.state instead!\", true)]\r\n        Stateful = 1,\r\n        ValueTypeBoxing = 2,\r\n        IgnoreProperty = 4,\r\n        IgnoreNotPublic = 8,\r\n        Inline = 16,\r\n        IntKey = 32,\r\n        AdaptByDelegate = 64,\r\n        IgnoreCompilerGenerated = 128,\r\n        NoBaseProxy = 256,\r\n    }\r\n\r\n    public class HotfixAttribute : Attribute\r\n    {\r\n        HotfixFlag flag;\r\n        public HotfixFlag Flag\r\n        {\r\n            get\r\n            {\r\n                return flag;\r\n            }\r\n        }\r\n\r\n        public HotfixAttribute(HotfixFlag e = HotfixFlag.Stateless)\r\n        {\r\n            flag = e;\r\n        }\r\n    }\r\n\r\n    [AttributeUsage(AttributeTargets.Delegate)]\r\n    internal class HotfixDelegateAttribute : Attribute\r\n    {\r\n    }\r\n\r\n#if !XLUA_GENERAL\r\n    public static class SysGenConfig\r\n    {\r\n        [GCOptimize]\r\n        static List<Type> GCOptimize\r\n        {\r\n            get\r\n            {\r\n                return new List<Type>() {\r\n                    typeof(UnityEngine.Vector2),\r\n                    typeof(UnityEngine.Vector3),\r\n                    typeof(UnityEngine.Vector4),\r\n                    typeof(UnityEngine.Color),\r\n                    typeof(UnityEngine.Quaternion),\r\n                    typeof(UnityEngine.Ray),\r\n                    typeof(UnityEngine.Bounds),\r\n                    typeof(UnityEngine.Ray2D),\r\n                };\r\n            }\r\n        }\r\n\r\n        [AdditionalProperties]\r\n        static Dictionary<Type, List<string>> AdditionalProperties\r\n        {\r\n            get\r\n            {\r\n                return new Dictionary<Type, List<string>>()\r\n                {\r\n                    { typeof(UnityEngine.Ray), new List<string>() { \"origin\", \"direction\" } },\r\n                    { typeof(UnityEngine.Ray2D), new List<string>() { \"origin\", \"direction\" } },\r\n                    { typeof(UnityEngine.Bounds), new List<string>() { \"center\", \"extents\" } },\r\n                };\r\n            }\r\n        }\r\n    }\r\n#endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Src/GenAttributes.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 4455254bac5b6644893ae8183b9eb87c\ntimeCreated: 1452509750\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/GenericDelegateBridge.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System;\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\n\r\nnamespace XLua {\r\n\tpublic partial class DelegateBridge : DelegateBridgeBase {\r\n\t\tpublic void Action() {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                int error = LuaAPI.lua_pcall(L, 0, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic void Action<T1>(T1 p1) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n                int error = LuaAPI.lua_pcall(L, 1, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic void Action<T1, T2>(T1 p1, T2 p2) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n                int error = LuaAPI.lua_pcall(L, 2, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic void Action<T1, T2, T3>(T1 p1, T2 p2, T3 p3) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n\t\t\t\ttranslator.PushByType(L, p3);\r\n                int error = LuaAPI.lua_pcall(L, 3, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic void Action<T1, T2, T3, T4>(T1 p1, T2 p2, T3 p3, T4 p4) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n\t\t\t\ttranslator.PushByType(L, p3);\r\n\t\t\t\ttranslator.PushByType(L, p4);\r\n                int error = LuaAPI.lua_pcall(L, 4, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\r\n\t\tpublic TResult Func<TResult>() {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n\t\t\t\tvar translator = luaEnv.translator;\r\n\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\tint errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\tint error = LuaAPI.lua_pcall(L, 0, 1, errFunc);\r\n\t\t\t\tif (error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\tTResult ret;\r\n\t\t\t\ttry {\r\n\t\t\t\t\ttranslator.Get(L, -1, out ret);\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\tthrow e;\r\n\t\t\t\t} finally {\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t}\r\n\t\t\t\treturn ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic TResult Func<T1, TResult>(T1 p1) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n\t\t\t\tvar translator = luaEnv.translator;\r\n\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\tint errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\tint error = LuaAPI.lua_pcall(L, 1, 1, errFunc);\r\n\t\t\t\tif (error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\tTResult ret;\r\n\t\t\t\ttry {\r\n\t\t\t\t\ttranslator.Get(L, -1, out ret);\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\tthrow e;\r\n\t\t\t\t} finally {\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t}\r\n\t\t\t\treturn ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic TResult Func<T1, T2, TResult>(T1 p1, T2 p2) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n\t\t\t\tvar translator = luaEnv.translator;\r\n\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\tint errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n\t\t\t\tint error = LuaAPI.lua_pcall(L, 2, 1, errFunc);\r\n\t\t\t\tif (error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\tTResult ret;\r\n\t\t\t\ttry {\r\n\t\t\t\t\ttranslator.Get(L, -1, out ret);\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\tthrow e;\r\n\t\t\t\t} finally {\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t}\r\n\t\t\t\treturn ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic TResult Func<T1, T2, T3, TResult>(T1 p1, T2 p2, T3 p3) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n\t\t\t\tvar translator = luaEnv.translator;\r\n\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\tint errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n\t\t\t\ttranslator.PushByType(L, p3);\r\n\t\t\t\tint error = LuaAPI.lua_pcall(L, 3, 1, errFunc);\r\n\t\t\t\tif (error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\tTResult ret;\r\n\t\t\t\ttry {\r\n\t\t\t\t\ttranslator.Get(L, -1, out ret);\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\tthrow e;\r\n\t\t\t\t} finally {\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t}\r\n\t\t\t\treturn ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic TResult Func<T1, T2, T3, T4, TResult>(T1 p1, T2 p2, T3 p3, T4 p4) {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\tlock(luaEnv.luaEnvLock) {\r\n#endif\r\n\t\t\t\tvar L = luaEnv.L;\r\n\t\t\t\tvar translator = luaEnv.translator;\r\n\t\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\t\tint errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n\t\t\t\tLuaAPI.lua_getref(L, luaReference);\r\n\t\t\t\ttranslator.PushByType(L, p1);\r\n\t\t\t\ttranslator.PushByType(L, p2);\r\n\t\t\t\ttranslator.PushByType(L, p3);\r\n\t\t\t\ttranslator.PushByType(L, p4);\r\n\t\t\t\tint error = LuaAPI.lua_pcall(L, 4, 1, errFunc);\r\n\t\t\t\tif (error != 0)\r\n\t\t\t\t\tluaEnv.ThrowExceptionFromError(oldTop);\r\n\t\t\t\tTResult ret;\r\n\t\t\t\ttry {\r\n\t\t\t\t\ttranslator.Get(L, -1, out ret);\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\tthrow e;\r\n\t\t\t\t} finally {\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t}\r\n\t\t\t\treturn ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n\t\t\t}\r\n#endif\r\n\t\t}\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Src/GenericDelegateBridge.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1bd0a3260371756449c4f642cc7ead00\ntimeCreated: 1537950363\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/InternalGlobals.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Reflection;\r\n\r\nnamespace XLua\r\n{\r\n    internal partial class InternalGlobals\r\n    {\r\n#if !THREAD_SAFE && !HOTFIX_ENABLE\r\n        internal static byte[] strBuff = new byte[256];\r\n#endif\r\n\r\n        internal delegate bool TryArrayGet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int index);\r\n        internal delegate bool TryArraySet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int array_idx, int obj_idx);\r\n        internal static volatile TryArrayGet genTryArrayGetPtr = null;\r\n        internal static volatile TryArraySet genTryArraySetPtr = null;\r\n\r\n        internal static volatile ObjectTranslatorPool objectTranslatorPool = new ObjectTranslatorPool();\r\n\r\n        internal static volatile int LUA_REGISTRYINDEX = -10000;\r\n\r\n        internal static volatile Dictionary<string, string> supportOp = new Dictionary<string, string>()\r\n        {\r\n            { \"op_Addition\", \"__add\" },\r\n            { \"op_Subtraction\", \"__sub\" },\r\n            { \"op_Multiply\", \"__mul\" },\r\n            { \"op_Division\", \"__div\" },\r\n            { \"op_Equality\", \"__eq\" },\r\n            { \"op_UnaryNegation\", \"__unm\" },\r\n            { \"op_LessThan\", \"__lt\" },\r\n            { \"op_LessThanOrEqual\", \"__le\" },\r\n            { \"op_Modulus\", \"__mod\" },\r\n            { \"op_BitwiseAnd\", \"__band\" },\r\n            { \"op_BitwiseOr\", \"__bor\" },\r\n            { \"op_ExclusiveOr\", \"__bxor\" },\r\n            { \"op_OnesComplement\", \"__bnot\" },\r\n            { \"op_LeftShift\", \"__shl\" },\r\n            { \"op_RightShift\", \"__shr\" },\r\n        };\r\n\r\n        internal static volatile Dictionary<Type, IEnumerable<MethodInfo>> extensionMethodMap = null;\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        internal static volatile LuaDLL.CSharpWrapperCaller CSharpWrapperCallerPtr = new LuaDLL.CSharpWrapperCaller(StaticLuaCallbacks.CSharpWrapperCallerImpl);\r\n#endif\r\n\r\n        internal static volatile LuaCSFunction LazyReflectionWrap = new LuaCSFunction(Utils.LazyReflectionCall);\r\n    }\r\n\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Src/InternalGlobals.cs.meta",
    "content": "fileFormatVersion: 2\nguid: bacb817c6d0b48644892c8dc3cb6cfc1\ntimeCreated: 1496994941\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaBase.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\n\r\nnamespace XLua\r\n{\r\n    public abstract class LuaBase : IDisposable\r\n    {\r\n        protected bool disposed;\r\n        protected readonly int luaReference;\r\n        protected readonly LuaEnv luaEnv;\r\n\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n        protected int _errorFuncRef { get { return luaEnv.errorFuncRef; } }\r\n        protected RealStatePtr _L { get { return luaEnv.L; } }\r\n        protected ObjectTranslator _translator { get { return luaEnv.translator; } }\r\n#endif\r\n\r\n        public LuaBase(int reference, LuaEnv luaenv)\r\n        {\r\n            luaReference = reference;\r\n            luaEnv = luaenv;\r\n        }\r\n\r\n        ~LuaBase()\r\n        {\r\n            Dispose(false);\r\n        }\r\n\r\n        public void Dispose()\r\n        {\r\n            Dispose(true);\r\n            GC.SuppressFinalize(this);\r\n        }\r\n\r\n        public virtual void Dispose(bool disposeManagedResources)\r\n        {\r\n            if (!disposed)\r\n            {\r\n                if (luaReference != 0)\r\n                {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                    lock (luaEnv.luaEnvLock)\r\n                    {\r\n#endif\r\n                        bool is_delegate = this is DelegateBridgeBase;\r\n                        if (disposeManagedResources)\r\n                        {\r\n                            luaEnv.translator.ReleaseLuaBase(luaEnv.L, luaReference, is_delegate);\r\n                        }\r\n                        else //will dispse by LuaEnv.GC\r\n                        {\r\n                            luaEnv.equeueGCAction(new LuaEnv.GCAction { Reference = luaReference, IsDelegate = is_delegate });\r\n                        }\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                    }\r\n#endif\r\n                }\r\n                disposed = true;\r\n            }\r\n        }\r\n\r\n        public override bool Equals(object o)\r\n        {\r\n            if (o != null && this.GetType() == o.GetType())\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnv.luaEnvLock)\r\n                {\r\n#endif\r\n                    LuaBase rhs = (LuaBase)o;\r\n                    var L = luaEnv.L;\r\n                    if (L != rhs.luaEnv.L)\r\n                        return false;\r\n                    int top = LuaAPI.lua_gettop(L);\r\n                    LuaAPI.lua_getref(L, rhs.luaReference);\r\n                    LuaAPI.lua_getref(L, luaReference);\r\n                    int equal = LuaAPI.lua_rawequal(L, -1, -2);\r\n                    LuaAPI.lua_settop(L, top);\r\n                    return (equal != 0);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n            else return false;\r\n        }\r\n\r\n        public override int GetHashCode()\r\n        {\r\n            LuaAPI.lua_getref(luaEnv.L, luaReference);\r\n            var pointer = LuaAPI.lua_topointer(luaEnv.L, -1);\r\n            LuaAPI.lua_pop(luaEnv.L, 1);\r\n            return pointer.ToInt32();\r\n        }\r\n\r\n        internal virtual void push(RealStatePtr L)\r\n        {\r\n            LuaAPI.lua_getref(L, luaReference);\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaBase.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 36f6e0ab03586ce4493d45dbc2a0ff5c\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaDLL.cs",
    "content": "/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nnamespace XLua.LuaDLL\r\n{\r\n\r\n    using System;\r\n    using System.Runtime.InteropServices;\r\n    using System.Text;\r\n    using XLua;\r\n\r\n#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)\r\n    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r\n    public delegate int lua_CSFunction(IntPtr L);\r\n\r\n#if GEN_CODE_MINIMIZE\r\n    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r\n    public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);\r\n#endif\r\n#else\r\n    public delegate int lua_CSFunction(IntPtr L);\r\n\r\n#if GEN_CODE_MINIMIZE\r\n    public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);\r\n#endif\r\n#endif\r\n\r\n\r\n    public partial class Lua\r\n\t{\r\n#if (UNITY_IPHONE || UNITY_TVOS || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR\r\n        const string LUADLL = \"__Internal\";\r\n#else\r\n        const string LUADLL = \"xlua\";\r\n#endif\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr lua_tothread(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern int xlua_get_lib_version();\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int lua_gc(IntPtr L, LuaGCOptions what, int data);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr lua_getupvalue(IntPtr L, int funcindex, int n);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr lua_setupvalue(IntPtr L, int funcindex, int n);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_pushthread(IntPtr L);\r\n\r\n\t\tpublic static bool lua_isfunction(IntPtr L, int stackPos)\r\n\t\t{\r\n\t\t\treturn lua_type(L, stackPos) == LuaTypes.LUA_TFUNCTION;\r\n\t\t}\r\n\r\n\t\tpublic static bool lua_islightuserdata(IntPtr L, int stackPos)\r\n\t\t{\r\n\t\t\treturn lua_type(L, stackPos) == LuaTypes.LUA_TLIGHTUSERDATA;\r\n\t\t}\r\n\r\n\t\tpublic static bool lua_istable(IntPtr L, int stackPos)\r\n\t\t{\r\n\t\t\treturn lua_type(L, stackPos) == LuaTypes.LUA_TTABLE;\r\n\t\t}\r\n\r\n\t\tpublic static bool lua_isthread(IntPtr L, int stackPos)\r\n\t\t{\r\n\t\t\treturn lua_type(L, stackPos) == LuaTypes.LUA_TTHREAD;\r\n\t\t}\r\n\r\n        public static int luaL_error(IntPtr L, string message) //[-0, +1, m]\r\n        {\r\n            xlua_csharp_str_error(L, message);\r\n            return 0;\r\n        }\r\n\r\n\t\t[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_setfenv(IntPtr L, int stackPos);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern IntPtr luaL_newstate();\r\n\r\n\t\t[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_close(IntPtr L);\r\n\r\n\t\t[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]\r\n        public static extern void luaopen_xlua(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]\r\n        public static extern void luaL_openlibs(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern uint xlua_objlen(IntPtr L, int stackPos);\r\n\r\n\t\t[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_createtable(IntPtr L, int narr, int nrec);//[-0, +0, m]\r\n\r\n        public static void lua_newtable(IntPtr L)//[-0, +0, m]\r\n        {\r\n\t\t\tlua_createtable(L, 0, 0);\r\n\t\t}\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_getglobal(IntPtr L, string name);//[-1, +0, m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_setglobal(IntPtr L, string name);//[-1, +0, m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_getloaders(IntPtr L);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_settop(IntPtr L, int newTop);\r\n\r\n\t\tpublic static void lua_pop(IntPtr L, int amount)\r\n\t\t{\r\n\t\t\tlua_settop(L, -(amount) - 1);\r\n\t\t}\r\n\t\t[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_insert(IntPtr L, int newTop);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_remove(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_rawget(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_rawset(IntPtr L, int index);//[-2, +0, m]\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_setmetatable(IntPtr L, int objIndex);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int lua_rawequal(IntPtr L, int index1, int index2);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_pushvalue(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void lua_pushcclosure(IntPtr L, IntPtr fn, int n);//[-n, +1, m]\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_replace(IntPtr L, int index);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_gettop(IntPtr L);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern LuaTypes lua_type(IntPtr L, int index);\r\n\r\n\t\tpublic static bool lua_isnil(IntPtr L, int index)\r\n\t\t{\r\n\t\t\treturn (lua_type(L,index)==LuaTypes.LUA_TNIL);\r\n\t\t}\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern bool lua_isnumber(IntPtr L, int index);\r\n\r\n\t\tpublic static bool lua_isboolean(IntPtr L, int index)\r\n\t\t{\r\n\t\t\treturn lua_type(L,index)==LuaTypes.LUA_TBOOLEAN;\r\n\t\t}\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int luaL_ref(IntPtr L, int registryIndex);\r\n\r\n        public static int luaL_ref(IntPtr L)//[-1, +0, m]\r\n        {\r\n\t\t\treturn luaL_ref(L,LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t}\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void xlua_rawgeti(IntPtr L, int tableIndex, long index);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void xlua_rawseti(IntPtr L, int tableIndex, long index);//[-1, +0, m]\r\n\r\n        public static void lua_getref(IntPtr L, int reference)\r\n\t\t{\r\n\t\t\txlua_rawgeti(L,LuaIndexes.LUA_REGISTRYINDEX,reference);\r\n\t\t}\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int pcall_prepare(IntPtr L, int error_func_ref, int func_ref);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void luaL_unref(IntPtr L, int registryIndex, int reference);\r\n\r\n\t\tpublic static void lua_unref(IntPtr L, int reference)\r\n\t\t{\r\n\t\t\tluaL_unref(L,LuaIndexes.LUA_REGISTRYINDEX,reference);\r\n\t\t}\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern bool lua_isstring(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool lua_isinteger(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_pushnil(IntPtr L);\r\n\r\n\t\tpublic static void lua_pushstdcallcfunction(IntPtr L, lua_CSFunction function, int n = 0)//[-0, +1, m]\r\n        {\r\n#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)\r\n            GCHandle.Alloc(function);\r\n#endif\r\n            IntPtr fn = Marshal.GetFunctionPointerForDelegate(function);\r\n            xlua_push_csharp_function(L, fn, n);\r\n        }\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_upvalueindex(int n);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int lua_pcall(IntPtr L, int nArgs, int nResults, int errfunc);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern double lua_tonumber(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_tointeger(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern uint xlua_touint(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern bool lua_toboolean(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr lua_topointer(IntPtr L, int index);\r\n\r\n        [DllImport(LUADLL,CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern IntPtr lua_tolstring(IntPtr L, int index, out IntPtr strLen);//[-0, +0, m]\r\n\r\n        public static string lua_tostring(IntPtr L, int index)\r\n\t\t{\r\n            IntPtr strlen;\r\n\r\n            IntPtr str = lua_tolstring(L, index, out strlen);\r\n            if (str != IntPtr.Zero)\r\n\t\t\t{\r\n#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)\r\n                int len = strlen.ToInt32();\r\n                byte[] buffer = new byte[len];\r\n                Marshal.Copy(str, buffer, 0, len);\r\n                return Encoding.UTF8.GetString(buffer);\r\n#else\r\n                string ret = Marshal.PtrToStringAnsi(str, strlen.ToInt32());\r\n                if (ret == null)\r\n                {\r\n                    int len = strlen.ToInt32();\r\n                    byte[] buffer = new byte[len];\r\n                    Marshal.Copy(str, buffer, 0, len);\r\n                    return Encoding.UTF8.GetString(buffer);\r\n                }\r\n                return ret;\r\n#endif\r\n            }\r\n            else\r\n\t\t\t{\r\n                return null;\r\n\t\t\t}\r\n\t\t}\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern IntPtr lua_atpanic(IntPtr L, lua_CSFunction panicf);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_pushnumber(IntPtr L, double number);\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_pushboolean(IntPtr L, bool value);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_pushinteger(IntPtr L, int value);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_pushuint(IntPtr L, uint value);\r\n\r\n#if NATIVE_LUA_PUSHSTRING\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void lua_pushstring(IntPtr L, string str);\r\n#else\r\n        public static void lua_pushstring(IntPtr L, string str) //业务使用\r\n        {\r\n            if (str == null)\r\n            {\r\n                lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n#if !THREAD_SAFE && !HOTFIX_ENABLE\r\n                if (Encoding.UTF8.GetByteCount(str) > InternalGlobals.strBuff.Length)\r\n                {\r\n                    byte[] bytes = Encoding.UTF8.GetBytes(str);\r\n                    xlua_pushlstring(L, bytes, bytes.Length);\r\n                }\r\n                else\r\n                {\r\n                    int bytes_len = Encoding.UTF8.GetBytes(str, 0, str.Length, InternalGlobals.strBuff, 0);\r\n                    xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);\r\n                }\r\n#else\r\n                var bytes = Encoding.UTF8.GetBytes(str);\r\n                xlua_pushlstring(L, bytes, bytes.Length);\r\n#endif\r\n            }\r\n        }\r\n#endif\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_pushlstring(IntPtr L, byte[] str, int size);\r\n\r\n        public static void xlua_pushasciistring(IntPtr L, string str) // for inner use only\r\n        {\r\n            if (str == null)\r\n            {\r\n                lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n#if NATIVE_LUA_PUSHSTRING\r\n                lua_pushstring(L, str);\r\n#else\r\n#if !THREAD_SAFE && !HOTFIX_ENABLE\r\n                int str_len = str.Length;\r\n                if (InternalGlobals.strBuff.Length < str_len)\r\n                {\r\n                    InternalGlobals.strBuff = new byte[str_len];\r\n                }\r\n\r\n                int bytes_len = Encoding.UTF8.GetBytes(str, 0, str_len, InternalGlobals.strBuff, 0);\r\n                xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);\r\n#else\r\n                var bytes = Encoding.UTF8.GetBytes(str);\r\n                xlua_pushlstring(L, bytes, bytes.Length);\r\n#endif\r\n#endif\r\n            }\r\n        }\r\n\r\n        public static void lua_pushstring(IntPtr L, byte[] str)\r\n        {\r\n            if (str == null)\r\n            {\r\n                lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n                xlua_pushlstring(L, str, str.Length);\r\n            }\r\n        }\r\n\r\n        public static byte[] lua_tobytes(IntPtr L, int index)//[-0, +0, m]\r\n        {\r\n            if (lua_type(L, index) == LuaTypes.LUA_TSTRING)\r\n            { \r\n                IntPtr strlen;\r\n                IntPtr str = lua_tolstring(L, index, out strlen);\r\n                if (str != IntPtr.Zero)\r\n                {\r\n                    int buff_len = strlen.ToInt32();\r\n                    byte[] buffer = new byte[buff_len];\r\n                    Marshal.Copy(str, buffer, 0, buff_len);\r\n                    return buffer;\r\n                }\r\n            }\r\n            return null;\r\n        }\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int luaL_newmetatable(IntPtr L, string meta);//[-0, +1, m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_pgettable(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_psettable(IntPtr L, int idx);\r\n\r\n        public static void luaL_getmetatable(IntPtr L, string meta)\r\n\t\t{\r\n            xlua_pushasciistring(L, meta);\r\n\t\t\tlua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t}\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, string name);\r\n\r\n        public static int luaL_loadbuffer(IntPtr L, string buff, string name)//[-0, +1, m]\r\n        {\r\n            byte[] bytes = Encoding.UTF8.GetBytes(buff);\r\n            return xluaL_loadbuffer(L, bytes, bytes.Length, name);\r\n        }\r\n\r\n\t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int xlua_tocsobj_safe(IntPtr L,int obj);//[-0, +0, m]\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int xlua_tocsobj_fast(IntPtr L,int obj);\r\n\r\n        public static int lua_error(IntPtr L)\r\n        {\r\n            xlua_csharp_error(L);\r\n            return 0;\r\n        }\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n\t\tpublic static extern bool lua_checkstack(IntPtr L,int extra);//[-0, +0, m]\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern int lua_next(IntPtr L,int index);//[-1, +(2|0), e]\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern void lua_pushlightuserdata(IntPtr L, IntPtr udata);\r\n\r\n \t\t[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n\t\tpublic static extern IntPtr xlua_tag();\r\n\r\n        [DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]\r\n        public static extern void luaL_where (IntPtr L, int level);//[-0, +1, m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_tryget_cachedud(IntPtr L, int key, int cache_ref);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_pushcsobj(IntPtr L, int key, int meta_ref, bool need_cache, int cache_ref);//[-0, +1, m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int gen_obj_indexer(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int gen_obj_newindexer(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int gen_cls_indexer(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int gen_cls_newindexer(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int get_error_func_ref(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]\r\n        public static extern int load_error_func(IntPtr L, int Ref);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int luaopen_i64lib(IntPtr L);//[,,m]\r\n\r\n#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int luaopen_socket_core(IntPtr L);//[,,m]\r\n#endif\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void lua_pushint64(IntPtr L, long n);//[,,m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void lua_pushuint64(IntPtr L, ulong n);//[,,m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool lua_isint64(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool lua_isuint64(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern long lua_toint64(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern ulong lua_touint64(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_push_csharp_function(IntPtr L, IntPtr fn, int n);//[-0,+1,m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_csharp_str_error(IntPtr L, string message);//[-0,+1,m]\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[-0,+0,m]\r\n        public static extern int xlua_csharp_error(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_int8_t(IntPtr buff, int offset, byte field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_int8_t(IntPtr buff, int offset, out byte field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_int16_t(IntPtr buff, int offset, short field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_int16_t(IntPtr buff, int offset, out short field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_int32_t(IntPtr buff, int offset, int field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_int32_t(IntPtr buff, int offset, out int field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_int64_t(IntPtr buff, int offset, long field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_int64_t(IntPtr buff, int offset, out long field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float(IntPtr buff, int offset, float field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float(IntPtr buff, int offset, out float field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_double(IntPtr buff, int offset, double field);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_double(IntPtr buff, int offset, out double field);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr xlua_pushstruct(IntPtr L, uint size, int meta_ref);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_pushcstable(IntPtr L, uint field_count, int meta_ref);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr lua_touserdata(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_gettypeid(IntPtr L, int idx);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_get_registry_index();\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_pgettable_bypath(IntPtr L, int idx, string path);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern int xlua_psettable_bypath(IntPtr L, int idx, string path);\r\n\r\n        //[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        //public static extern void xlua_pushbuffer(IntPtr L, byte[] buff);\r\n\r\n        //对于Unity，仅浮点组成的struct较多，这几个api用于优化这类struct\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float2(IntPtr buff, int offset, float f1, float f2);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float2(IntPtr buff, int offset, out float f1, out float f2);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float3(IntPtr buff, int offset, float f1, float f2, float f3);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float3(IntPtr buff, int offset, out float f1, out float f2, out float f3);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float4(IntPtr buff, int offset, float f1, float f2, float f3, float f4);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float4(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float5(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float5(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_float6(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5, float f6);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_float6(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5, out float f6);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_pack_decimal(IntPtr buff, int offset, ref decimal dec);\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_unpack_decimal(IntPtr buff, int offset, out byte scale, out byte sign, out int hi32, out ulong lo64);\r\n\r\n        public static bool xlua_is_eq_str(IntPtr L, int index, string str)\r\n        {\r\n            return xlua_is_eq_str(L, index, str, str.Length);\r\n        }\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern bool xlua_is_eq_str(IntPtr L, int index, string str, int str_len);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr xlua_gl(IntPtr L);\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_set_csharp_wrapper_caller(IntPtr wrapper);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_push_csharp_wrapper(IntPtr L, int wrapperID);\r\n\r\n        public static void xlua_set_csharp_wrapper_caller(CSharpWrapperCaller wrapper_caller)\r\n        {\r\n#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)\r\n            GCHandle.Alloc(wrapper);\r\n#endif\r\n            xlua_set_csharp_wrapper_caller(Marshal.GetFunctionPointerForDelegate(wrapper_caller));\r\n        }\r\n#endif\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaDLL.cs.meta",
    "content": "fileFormatVersion: 2\nguid: d60cef534e986e849a829838fbeb74b5\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaEnv.cs",
    "content": "/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\n\r\nnamespace XLua\r\n{\r\n    using System;\r\n    using System.Collections.Generic;\r\n\r\n    public class LuaEnv : IDisposable\r\n    {\r\n        public const string CSHARP_NAMESPACE = \"xlua_csharp_namespace\";\r\n        public const string MAIN_SHREAD = \"xlua_main_thread\";\r\n\r\n        internal RealStatePtr rawL;\r\n\r\n        internal RealStatePtr L\r\n        {\r\n            get\r\n            {\r\n                if (rawL == RealStatePtr.Zero)\r\n                {\r\n                    throw new InvalidOperationException(\"this lua env had disposed!\");\r\n                }\r\n                return rawL;\r\n            }\r\n        }\r\n\r\n        private LuaTable _G;\r\n\r\n        internal ObjectTranslator translator;\r\n\r\n        internal int errorFuncRef = -1;\r\n\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n        internal /*static*/ object luaLock = new object();\r\n\r\n        internal object luaEnvLock\r\n        {\r\n            get\r\n            {\r\n                return luaLock;\r\n            }\r\n        }\r\n#endif\r\n\r\n        const int LIB_VERSION_EXPECT = 105;\r\n\r\n        public LuaEnv()\r\n        {\r\n            if (LuaAPI.xlua_get_lib_version() != LIB_VERSION_EXPECT)\r\n            {\r\n                throw new InvalidProgramException(\"wrong lib version expect:\"\r\n                    + LIB_VERSION_EXPECT + \" but got:\" + LuaAPI.xlua_get_lib_version());\r\n            }\r\n\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock(luaEnvLock)\r\n#endif\r\n            {\r\n                LuaIndexes.LUA_REGISTRYINDEX = LuaAPI.xlua_get_registry_index();\r\n#if GEN_CODE_MINIMIZE\r\n                LuaAPI.xlua_set_csharp_wrapper_caller(InternalGlobals.CSharpWrapperCallerPtr);\r\n#endif\r\n                // Create State\r\n                rawL = LuaAPI.luaL_newstate();\r\n\r\n                //Init Base Libs\r\n                LuaAPI.luaopen_xlua(rawL);\r\n                LuaAPI.luaopen_i64lib(rawL);\r\n\r\n                translator = new ObjectTranslator(this, rawL);\r\n                translator.createFunctionMetatable(rawL);\r\n                translator.OpenLib(rawL);\r\n                ObjectTranslatorPool.Instance.Add(rawL, translator);\r\n\r\n                LuaAPI.lua_atpanic(rawL, StaticLuaCallbacks.Panic);\r\n\r\n#if !XLUA_GENERAL\r\n                LuaAPI.lua_pushstdcallcfunction(rawL, StaticLuaCallbacks.Print);\r\n                if (0 != LuaAPI.xlua_setglobal(rawL, \"print\"))\r\n                {\r\n                    throw new Exception(\"call xlua_setglobal fail!\");\r\n                }\r\n#endif\r\n\r\n                //template engine lib register\r\n                TemplateEngine.LuaTemplate.OpenLib(rawL);\r\n\r\n                AddSearcher(StaticLuaCallbacks.LoadBuiltinLib, 2); // just after the preload searcher\r\n                AddSearcher(StaticLuaCallbacks.LoadFromCustomLoaders, 3);\r\n#if !XLUA_GENERAL\r\n                AddSearcher(StaticLuaCallbacks.LoadFromResource, 4);\r\n                AddSearcher(StaticLuaCallbacks.LoadFromStreamingAssetsPath, -1);\r\n#endif\r\n                DoString(init_xlua, \"Init\");\r\n                init_xlua = null;\r\n\r\n#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR\r\n                AddBuildin(\"socket.core\", StaticLuaCallbacks.LoadSocketCore);\r\n                AddBuildin(\"socket\", StaticLuaCallbacks.LoadSocketCore);\r\n#endif\r\n\r\n                AddBuildin(\"CS\", StaticLuaCallbacks.LoadCS);\r\n\r\n                LuaAPI.lua_newtable(rawL); //metatable of indexs and newindexs functions\r\n                LuaAPI.xlua_pushasciistring(rawL, \"__index\");\r\n                LuaAPI.lua_pushstdcallcfunction(rawL, StaticLuaCallbacks.MetaFuncIndex);\r\n                LuaAPI.lua_rawset(rawL, -3);\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, Utils.LuaIndexsFieldName);\r\n                LuaAPI.lua_newtable(rawL);\r\n                LuaAPI.lua_pushvalue(rawL, -3);\r\n                LuaAPI.lua_setmetatable(rawL, -2);\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, Utils.LuaNewIndexsFieldName);\r\n                LuaAPI.lua_newtable(rawL);\r\n                LuaAPI.lua_pushvalue(rawL, -3);\r\n                LuaAPI.lua_setmetatable(rawL, -2);\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, Utils.LuaClassIndexsFieldName);\r\n                LuaAPI.lua_newtable(rawL);\r\n                LuaAPI.lua_pushvalue(rawL, -3);\r\n                LuaAPI.lua_setmetatable(rawL, -2);\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, Utils.LuaClassNewIndexsFieldName);\r\n                LuaAPI.lua_newtable(rawL);\r\n                LuaAPI.lua_pushvalue(rawL, -3);\r\n                LuaAPI.lua_setmetatable(rawL, -2);\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n                LuaAPI.lua_pop(rawL, 1); // pop metatable of indexs and newindexs functions\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, MAIN_SHREAD);\r\n                LuaAPI.lua_pushthread(rawL);\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n                LuaAPI.xlua_pushasciistring(rawL, CSHARP_NAMESPACE);\r\n                if (0 != LuaAPI.xlua_getglobal(rawL, \"CS\"))\r\n                {\r\n                    throw new Exception(\"get CS fail!\");\r\n                }\r\n                LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n#if !XLUA_GENERAL && (!UNITY_WSA || UNITY_EDITOR)\r\n                translator.Alias(typeof(Type), \"System.MonoType\");\r\n#endif\r\n\r\n                if (0 != LuaAPI.xlua_getglobal(rawL, \"_G\"))\r\n                {\r\n                    throw new Exception(\"get _G fail!\");\r\n                }\r\n                translator.Get(rawL, -1, out _G);\r\n                LuaAPI.lua_pop(rawL, 1);\r\n\r\n                errorFuncRef = LuaAPI.get_error_func_ref(rawL);\r\n\r\n                if (initers != null)\r\n                {\r\n                    for (int i = 0; i < initers.Count; i++)\r\n                    {\r\n                        initers[i](this, translator);\r\n                    }\r\n                }\r\n\r\n                translator.CreateArrayMetatable(rawL);\r\n                translator.CreateDelegateMetatable(rawL);\r\n                translator.CreateEnumerablePairs(rawL);\r\n            }\r\n        }\r\n\r\n        private static List<Action<LuaEnv, ObjectTranslator>> initers = null;\r\n\r\n        public static void AddIniter(Action<LuaEnv, ObjectTranslator> initer)\r\n        {\r\n            if (initers == null)\r\n            {\r\n                initers = new List<Action<LuaEnv, ObjectTranslator>>();\r\n            }\r\n            initers.Add(initer);\r\n        }\r\n\r\n        public LuaTable Global\r\n        {\r\n            get\r\n            {\r\n                return _G;\r\n            }\r\n        }\r\n\r\n        public T LoadString<T>(byte[] chunk, string chunkName = \"chunk\", LuaTable env = null)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                if (typeof(T) != typeof(LuaFunction) && !typeof(T).IsSubclassOf(typeof(Delegate)))\r\n                {\r\n                    throw new InvalidOperationException(typeof(T).Name + \" is not a delegate type nor LuaFunction\");\r\n                }\r\n                var _L = L;\r\n                int oldTop = LuaAPI.lua_gettop(_L);\r\n\r\n                if (LuaAPI.xluaL_loadbuffer(_L, chunk, chunk.Length, chunkName) != 0)\r\n                    ThrowExceptionFromError(oldTop);\r\n\r\n                if (env != null)\r\n                {\r\n                    env.push(_L);\r\n                    LuaAPI.lua_setfenv(_L, -2);\r\n                }\r\n\r\n                T result = (T)translator.GetObject(_L, -1, typeof(T));\r\n                LuaAPI.lua_settop(_L, oldTop);\r\n\r\n                return result;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public T LoadString<T>(string chunk, string chunkName = \"chunk\", LuaTable env = null)\r\n        {\r\n            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(chunk);\r\n            return LoadString<T>(bytes, chunkName, env);\r\n        }\r\n\r\n        public LuaFunction LoadString(string chunk, string chunkName = \"chunk\", LuaTable env = null)\r\n        {\r\n            return LoadString<LuaFunction>(chunk, chunkName, env);\r\n        }\r\n\r\n        public object[] DoString(byte[] chunk, string chunkName = \"chunk\", LuaTable env = null)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                var _L = L;\r\n                int oldTop = LuaAPI.lua_gettop(_L);\r\n                int errFunc = LuaAPI.load_error_func(_L, errorFuncRef);\r\n                if (LuaAPI.xluaL_loadbuffer(_L, chunk, chunk.Length, chunkName) == 0)\r\n                {\r\n                    if (env != null)\r\n                    {\r\n                        env.push(_L);\r\n                        LuaAPI.lua_setfenv(_L, -2);\r\n                    }\r\n\r\n                    if (LuaAPI.lua_pcall(_L, 0, -1, errFunc) == 0)\r\n                    {\r\n                        LuaAPI.lua_remove(_L, errFunc);\r\n                        return translator.popValues(_L, oldTop);\r\n                    }\r\n                    else\r\n                        ThrowExceptionFromError(oldTop);\r\n                }\r\n                else\r\n                    ThrowExceptionFromError(oldTop);\r\n\r\n                return null;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public object[] DoString(string chunk, string chunkName = \"chunk\", LuaTable env = null)\r\n        {\r\n            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(chunk);\r\n            return DoString(bytes, chunkName, env);\r\n        }\r\n\r\n        private void AddSearcher(LuaCSFunction searcher, int index)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                var _L = L;\r\n                //insert the loader\r\n                LuaAPI.xlua_getloaders(_L);\r\n                if (!LuaAPI.lua_istable(_L, -1))\r\n                {\r\n                    throw new Exception(\"Can not set searcher!\");\r\n                }\r\n                uint len = LuaAPI.xlua_objlen(_L, -1);\r\n                index = index < 0 ? (int)(len + index + 2) : index;\r\n                for (int e = (int)len + 1; e > index; e--)\r\n                {\r\n                    LuaAPI.xlua_rawgeti(_L, -1, e - 1);\r\n                    LuaAPI.xlua_rawseti(_L, -2, e);\r\n                }\r\n                LuaAPI.lua_pushstdcallcfunction(_L, searcher);\r\n                LuaAPI.xlua_rawseti(_L, -2, index);\r\n                LuaAPI.lua_pop(_L, 1);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void Alias(Type type, string alias)\r\n        {\r\n            translator.Alias(type, alias);\r\n        }\r\n\r\n#if !XLUA_GENERAL\r\n        int last_check_point = 0;\r\n\r\n        int max_check_per_tick = 20;\r\n\r\n        static bool ObjectValidCheck(object obj)\r\n        {\r\n            return (!(obj is UnityEngine.Object)) ||  ((obj as UnityEngine.Object) != null);\r\n        }\r\n\r\n        Func<object, bool> object_valid_checker = new Func<object, bool>(ObjectValidCheck);\r\n#endif\r\n\r\n        public void Tick()\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                var _L = L;\r\n                lock (refQueue)\r\n                {\r\n                    while (refQueue.Count > 0)\r\n                    {\r\n                        GCAction gca = refQueue.Dequeue();\r\n                        translator.ReleaseLuaBase(_L, gca.Reference, gca.IsDelegate);\r\n                    }\r\n                }\r\n#if !XLUA_GENERAL\r\n                last_check_point = translator.objects.Check(last_check_point, max_check_per_tick, object_valid_checker, translator.reverseMap);\r\n#endif\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        //API\r\n        public void GC()\r\n        {\r\n            Tick();\r\n        }\r\n\r\n        public LuaTable NewTable()\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                var _L = L;\r\n                int oldTop = LuaAPI.lua_gettop(_L);\r\n\r\n                LuaAPI.lua_newtable(_L);\r\n                LuaTable returnVal = (LuaTable)translator.GetObject(_L, -1, typeof(LuaTable));\r\n\r\n                LuaAPI.lua_settop(_L, oldTop);\r\n                return returnVal;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        private bool disposed = false;\r\n\r\n        public void Dispose()\r\n        {\r\n            FullGc();\r\n            System.GC.Collect();\r\n            System.GC.WaitForPendingFinalizers();\r\n\r\n            Dispose(true);\r\n\r\n            System.GC.Collect();\r\n            System.GC.WaitForPendingFinalizers();\r\n        }\r\n\r\n        public virtual void Dispose(bool dispose)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                if (disposed) return;\r\n                Tick();\r\n\r\n                if (!translator.AllDelegateBridgeReleased())\r\n                {\r\n                    throw new InvalidOperationException(\"try to dispose a LuaEnv with C# callback!\");\r\n                }\r\n                \r\n                ObjectTranslatorPool.Instance.Remove(L);\r\n\r\n                LuaAPI.lua_close(L);\r\n                translator = null;\r\n\r\n                rawL = IntPtr.Zero;\r\n\r\n                disposed = true;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void ThrowExceptionFromError(int oldTop)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                object err = translator.GetObject(L, -1);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n\r\n                // A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)\r\n                Exception ex = err as Exception;\r\n                if (ex != null) throw ex;\r\n\r\n                // A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it\r\n                if (err == null) err = \"Unknown Lua Error\";\r\n                throw new LuaException(err.ToString());\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        internal struct GCAction\r\n        {\r\n            public int Reference;\r\n            public bool IsDelegate;\r\n        }\r\n\r\n        Queue<GCAction> refQueue = new Queue<GCAction>();\r\n\r\n        internal void equeueGCAction(GCAction action)\r\n        {\r\n            lock (refQueue)\r\n            {\r\n                refQueue.Enqueue(action);\r\n            }\r\n        }\r\n\r\n        private string init_xlua = @\" \r\n            local metatable = {}\r\n            local rawget = rawget\r\n            local setmetatable = setmetatable\r\n            local import_type = xlua.import_type\r\n            local import_generic_type = xlua.import_generic_type\r\n            local load_assembly = xlua.load_assembly\r\n\r\n            function metatable:__index(key) \r\n                local fqn = rawget(self,'.fqn')\r\n                fqn = ((fqn and fqn .. '.') or '') .. key\r\n\r\n                local obj = import_type(fqn)\r\n\r\n                if obj == nil then\r\n                    -- It might be an assembly, so we load it too.\r\n                    obj = { ['.fqn'] = fqn }\r\n                    setmetatable(obj, metatable)\r\n                elseif obj == true then\r\n                    return rawget(self, key)\r\n                end\r\n\r\n                -- Cache this lookup\r\n                rawset(self, key, obj)\r\n                return obj\r\n            end\r\n\r\n            function metatable:__newindex()\r\n                error('No such type: ' .. rawget(self,'.fqn'), 2)\r\n            end\r\n\r\n            -- A non-type has been called; e.g. foo = System.Foo()\r\n            function metatable:__call(...)\r\n                local n = select('#', ...)\r\n                local fqn = rawget(self,'.fqn')\r\n                if n > 0 then\r\n                    local gt = import_generic_type(fqn, ...)\r\n                    if gt then\r\n                        return rawget(CS, gt)\r\n                    end\r\n                end\r\n                error('No such type: ' .. fqn, 2)\r\n            end\r\n\r\n            CS = CS or {}\r\n            setmetatable(CS, metatable)\r\n\r\n            typeof = function(t) return t.UnderlyingSystemType end\r\n            cast = xlua.cast\r\n            if not setfenv or not getfenv then\r\n                local function getfunction(level)\r\n                    local info = debug.getinfo(level + 1, 'f')\r\n                    return info and info.func\r\n                end\r\n\r\n                function setfenv(fn, env)\r\n                  if type(fn) == 'number' then fn = getfunction(fn + 1) end\r\n                  local i = 1\r\n                  while true do\r\n                    local name = debug.getupvalue(fn, i)\r\n                    if name == '_ENV' then\r\n                      debug.upvaluejoin(fn, i, (function()\r\n                        return env\r\n                      end), 1)\r\n                      break\r\n                    elseif not name then\r\n                      break\r\n                    end\r\n\r\n                    i = i + 1\r\n                  end\r\n\r\n                  return fn\r\n                end\r\n\r\n                function getfenv(fn)\r\n                  if type(fn) == 'number' then fn = getfunction(fn + 1) end\r\n                  local i = 1\r\n                  while true do\r\n                    local name, val = debug.getupvalue(fn, i)\r\n                    if name == '_ENV' then\r\n                      return val\r\n                    elseif not name then\r\n                      break\r\n                    end\r\n                    i = i + 1\r\n                  end\r\n                end\r\n            end\r\n\r\n            xlua.hotfix = function(cs, field, func)\r\n                if func == nil then func = false end\r\n                local tbl = (type(field) == 'table') and field or {[field] = func}\r\n                for k, v in pairs(tbl) do\r\n                    local cflag = ''\r\n                    if k == '.ctor' then\r\n                        cflag = '_c'\r\n                        k = 'ctor'\r\n                    end\r\n                    local f = type(v) == 'function' and v or nil\r\n                    xlua.access(cs, cflag .. '__Hotfix0_'..k, f) -- at least one\r\n                    pcall(function()\r\n                        for i = 1, 99 do\r\n                            xlua.access(cs, cflag .. '__Hotfix'..i..'_'..k, f)\r\n                        end\r\n                    end)\r\n                end\r\n                xlua.private_accessible(cs)\r\n            end\r\n            xlua.getmetatable = function(cs)\r\n                return xlua.metatable_operation(cs)\r\n            end\r\n            xlua.setmetatable = function(cs, mt)\r\n                return xlua.metatable_operation(cs, mt)\r\n            end\r\n            xlua.setclass = function(parent, name, impl)\r\n                impl.UnderlyingSystemType = parent[name].UnderlyingSystemType\r\n                rawset(parent, name, impl)\r\n            end\r\n            \r\n            local base_mt = {\r\n                __index = function(t, k)\r\n                    local csobj = t['__csobj']\r\n                    local func = csobj['<>xLuaBaseProxy_'..k]\r\n                    return function(_, ...)\r\n                         return func(csobj, ...)\r\n                    end\r\n                end\r\n            }\r\n            base = function(csobj)\r\n                return setmetatable({__csobj = csobj}, base_mt)\r\n            end\r\n            \";\r\n\r\n        public delegate byte[] CustomLoader(ref string filepath);\r\n\r\n        internal List<CustomLoader> customLoaders = new List<CustomLoader>();\r\n\r\n        //loader : CustomLoader filepathrefͣrequireĲҪֵ֧ԣҪʵ·\r\n        //                        ֵnullظԴ޺ʵļ򷵻UTF8byte[]\r\n        public void AddLoader(CustomLoader loader)\r\n        {\r\n            customLoaders.Add(loader);\r\n        }\r\n\r\n        internal Dictionary<string, LuaCSFunction> buildin_initer = new Dictionary<string, LuaCSFunction>();\r\n\r\n        public void AddBuildin(string name, LuaCSFunction initer)\r\n        {\r\n            if (!Utils.IsStaticPInvokeCSFunction(initer))\r\n            {\r\n                throw new Exception(\"initer must be static and has MonoPInvokeCallback Attribute!\");\r\n            }\r\n            buildin_initer.Add(name, initer);\r\n        }\r\n\r\n        //The garbage-collector pause controls how long the collector waits before starting a new cycle. \r\n        //Larger values make the collector less aggressive. Values smaller than 100 mean the collector \r\n        //will not wait to start a new cycle. A value of 200 means that the collector waits for the total \r\n        //memory in use to double before starting a new cycle.\r\n        public int GcPause\r\n        {\r\n            get\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnvLock)\r\n                {\r\n#endif\r\n                    int val = LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, 200);\r\n                    LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, val);\r\n                    return val;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n            set\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnvLock)\r\n                {\r\n#endif\r\n                    LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, value);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n        }\r\n\r\n        //The step multiplier controls the relative speed of the collector relative to memory allocation. \r\n        //Larger values make the collector more aggressive but also increase the size of each incremental \r\n        //step. Values smaller than 100 make the collector too slow and can result in the collector never \r\n        //finishing a cycle. The default, 200, means that the collector runs at \"twice\" the speed of memory \r\n        //allocation.\r\n        public int GcStepmul\r\n        {\r\n            get\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnvLock)\r\n                {\r\n#endif\r\n                    int val = LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, 200);\r\n                    LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, val);\r\n                    return val;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n            set\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnvLock)\r\n                {\r\n#endif\r\n                    LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, value);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n        }\r\n\r\n        public void FullGc()\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void StopGc()\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSTOP, 0);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void RestartGc()\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCRESTART, 0);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public bool GcStep(int data)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnvLock)\r\n            {\r\n#endif\r\n                return LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSTEP, data) != 0;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public int Memroy\r\n        {\r\n            get\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnvLock)\r\n                {\r\n#endif\r\n                    return LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCCOUNT, 0);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaEnv.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1a72df23459239b4d901cdacabd469d1\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaException.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System;\r\n\r\nnamespace XLua\r\n{\r\n    [Serializable]\r\n    public class LuaException : Exception\r\n    {\r\n        public LuaException(string message) : base(message)\r\n        {}\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaException.cs.meta",
    "content": "fileFormatVersion: 2\nguid: b209468b680ef7d4195de21a39bfcae0\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaFunction.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace XLua\r\n{\r\n    public partial class LuaFunction : LuaBase\r\n    {\r\n        public LuaFunction(int reference, LuaEnv luaenv) : base(reference, luaenv)\r\n        {\r\n        }\r\n\r\n        //Action和Func是方便使用的无gc api，如果需要用到out，ref参数，建议使用delegate\r\n        //如果需要其它个数的Action和Func， 这个类声明为partial，可以自己加\r\n        public void Action<T>(T a)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, a);\r\n                int error = LuaAPI.lua_pcall(L, 1, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public TResult Func<T, TResult>(T a)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, a);\r\n                int error = LuaAPI.lua_pcall(L, 1, 1, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                TResult ret;\r\n                try\r\n                {\r\n                    translator.Get(L, -1, out ret);\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    throw e;\r\n                }\r\n                finally\r\n                {\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                }\r\n                return ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void Action<T1, T2>(T1 a1, T2 a2)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, a1);\r\n                translator.PushByType(L, a2);\r\n                int error = LuaAPI.lua_pcall(L, 2, 0, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public TResult Func<T1, T2, TResult>(T1 a1, T2 a2)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, a1);\r\n                translator.PushByType(L, a2);\r\n                int error = LuaAPI.lua_pcall(L, 2, 1, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                TResult ret;\r\n                try\r\n                {\r\n                    translator.Get(L, -1, out ret);\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    throw e;\r\n                }\r\n                finally\r\n                {\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                }\r\n                return ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        //deprecated\r\n        public object[] Call(object[] args, Type[] returnTypes)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                int nArgs = 0;\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n\r\n                int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                if (args != null)\r\n                {\r\n                    nArgs = args.Length;\r\n                    for (int i = 0; i < args.Length; i++)\r\n                    {\r\n                        translator.PushAny(L, args[i]);\r\n                    }\r\n                }\r\n                int error = LuaAPI.lua_pcall(L, nArgs, -1, errFunc);\r\n                if (error != 0)\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n\r\n                LuaAPI.lua_remove(L, errFunc);\r\n                if (returnTypes != null)\r\n                    return translator.popValues(L, oldTop, returnTypes);\r\n                else\r\n                    return translator.popValues(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        //deprecated\r\n        public object[] Call(params object[] args)\r\n        {\r\n            return Call(args, null);\r\n        }\r\n\r\n        public T Cast<T>()\r\n        {\r\n            if (!typeof(T).IsSubclassOf(typeof(Delegate)))\r\n            {\r\n                throw new InvalidOperationException(typeof(T).Name + \" is not a delegate type\");\r\n            }\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                push(L);\r\n                T ret = (T)translator.GetObject(L, -1, typeof(T));\r\n                LuaAPI.lua_pop(luaEnv.L, 1);\r\n                return ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void SetEnv(LuaTable env)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                push(L);\r\n                env.push(L);\r\n                LuaAPI.lua_setfenv(L, -2);\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        internal override void push(RealStatePtr L)\r\n        {\r\n            LuaAPI.lua_getref(L, luaReference);\r\n        }\r\n\r\n        public override string ToString()\r\n        {\r\n            return \"function :\" + luaReference;\r\n        }\r\n    }\r\n\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaFunction.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 7c45cd490d853cb409d042c641784718\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/LuaTable.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\nusing System.Collections;\r\n\r\nnamespace XLua\r\n{\r\n    public partial class LuaTable : LuaBase\r\n    {\r\n        public LuaTable(int reference, LuaEnv luaenv) : base(reference, luaenv)\r\n        {\r\n        }\r\n\r\n        // no boxing version get\r\n        public void Get<TKey, TValue>(TKey key, out TValue value)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, key);\r\n\r\n                if (0 != LuaAPI.xlua_pgettable(L, -2))\r\n                {\r\n                    string err = LuaAPI.lua_tostring(L, -1);\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                    throw new Exception(\"get field [\" + key + \"] error:\" + err);\r\n                }\r\n\r\n                LuaTypes lua_type = LuaAPI.lua_type(L, -1);\r\n                Type type_of_value = typeof(TValue);\r\n                if (lua_type == LuaTypes.LUA_TNIL && type_of_value.IsValueType())\r\n                {\r\n                    throw new InvalidCastException(\"can not assign nil to \" + type_of_value.GetFriendlyName());\r\n                }\r\n\r\n                try\r\n                {\r\n                    translator.Get(L, -1, out value);\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    throw e;\r\n                }\r\n                finally\r\n                {\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                }\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        // no boxing version get\r\n        public bool ContainsKey<TKey>(TKey key)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, key);\r\n\r\n                if (0 != LuaAPI.xlua_pgettable(L, -2))\r\n                {\r\n                    string err = LuaAPI.lua_tostring(L, -1);\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                    throw new Exception(\"get field [\" + key + \"] error:\" + err);\r\n                }\r\n\r\n                bool ret =  LuaAPI.lua_type(L, -1) != LuaTypes.LUA_TNIL;\r\n\r\n                LuaAPI.lua_settop(L, oldTop);\r\n\r\n                return ret;\r\n\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        //no boxing version set\r\n        public void Set<TKey, TValue>(TKey key, TValue value)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                var translator = luaEnv.translator;\r\n\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                translator.PushByType(L, key);\r\n                translator.PushByType(L, value);\r\n\r\n                if (0 != LuaAPI.xlua_psettable(L, -3))\r\n                {\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                }\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n\r\n        public T GetInPath<T>(string path)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                if (0 != LuaAPI.xlua_pgettable_bypath(L, -1, path))\r\n                {\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                }\r\n                LuaTypes lua_type = LuaAPI.lua_type(L, -1);\r\n                if (lua_type == LuaTypes.LUA_TNIL && typeof(T).IsValueType())\r\n                {\r\n                    throw new InvalidCastException(\"can not assign nil to \" + typeof(T).GetFriendlyName());\r\n                }\r\n\r\n                T value;\r\n                try\r\n                {\r\n                    translator.Get(L, -1, out value);\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    throw e;\r\n                }\r\n                finally\r\n                {\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                }\r\n                return value;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public void SetInPath<T>(string path, T val)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                luaEnv.translator.PushByType(L, val);\r\n                if (0 != LuaAPI.xlua_psettable_bypath(L, -2, path))\r\n                {\r\n                    luaEnv.ThrowExceptionFromError(oldTop);\r\n                }\r\n\r\n                LuaAPI.lua_settop(L, oldTop);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        [Obsolete(\"use no boxing version: GetInPath/SetInPath Get/Set instead!\")]\r\n        public object this[string field]\r\n        {\r\n            get\r\n            {\r\n                return GetInPath<object>(field);\r\n            }\r\n            set\r\n            {\r\n                SetInPath(field, value);\r\n            }\r\n        }\r\n\r\n        [Obsolete(\"use no boxing version: GetInPath/SetInPath Get/Set instead!\")]\r\n        public object this[object field]\r\n        {\r\n            get\r\n            {\r\n                return Get<object>(field);\r\n            }\r\n            set\r\n            {\r\n                Set(field, value);\r\n            }\r\n        }\r\n\r\n        public void ForEach<TKey, TValue>(Action<TKey, TValue> action)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                var L = luaEnv.L;\r\n                var translator = luaEnv.translator;\r\n                int oldTop = LuaAPI.lua_gettop(L);\r\n                try\r\n                {\r\n                    LuaAPI.lua_getref(L, luaReference);\r\n                    LuaAPI.lua_pushnil(L);\r\n                    while (LuaAPI.lua_next(L, -2) != 0)\r\n                    {\r\n                        if (translator.Assignable<TKey>(L, -2))\r\n                        {\r\n                            TKey key;\r\n                            TValue val;\r\n                            translator.Get(L, -2, out key);\r\n                            translator.Get(L, -1, out val);\r\n                            action(key, val);\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1);\r\n                    }\r\n                }\r\n                finally\r\n                {\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                }\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public int Length\r\n        {\r\n            get\r\n            {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                lock (luaEnv.luaEnvLock)\r\n                {\r\n#endif\r\n                    var L = luaEnv.L;\r\n                    int oldTop = LuaAPI.lua_gettop(L);\r\n                    LuaAPI.lua_getref(L, luaReference);\r\n                    var len = (int)LuaAPI.xlua_objlen(L, -1);\r\n                    LuaAPI.lua_settop(L, oldTop);\r\n                    return len;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n                }\r\n#endif\r\n            }\r\n        }\r\n\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n        [Obsolete(\"not thread safe!\", true)]\r\n#endif\r\n        public IEnumerable GetKeys()\r\n        {\r\n            var L = luaEnv.L;\r\n            var translator = luaEnv.translator;\r\n            int oldTop = LuaAPI.lua_gettop(L);\r\n            try\r\n            {\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                LuaAPI.lua_pushnil(L);\r\n                while (LuaAPI.lua_next(L, -2) != 0)\r\n                {\r\n                    yield return translator.GetObject(L, -2);\r\n                    LuaAPI.lua_pop(L, 1);\r\n                }\r\n            }\r\n            finally\r\n            {\r\n                LuaAPI.lua_settop(L, oldTop);\r\n            }\r\n        }\r\n\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n        [Obsolete(\"not thread safe!\", true)]\r\n#endif\r\n        public IEnumerable<T> GetKeys<T>()\r\n        {\r\n            var L = luaEnv.L;\r\n            var translator = luaEnv.translator;\r\n            int oldTop = LuaAPI.lua_gettop(L);\r\n            try\r\n            {\r\n                LuaAPI.lua_getref(L, luaReference);\r\n                LuaAPI.lua_pushnil(L);\r\n                while (LuaAPI.lua_next(L, -2) != 0)\r\n                {\r\n                    if (translator.Assignable<T>(L, -2))\r\n                    {\r\n                        T v;\r\n                        translator.Get(L, -2, out v);\r\n                        yield return v;\r\n                    }\r\n                    LuaAPI.lua_pop(L, 1);\r\n                }\r\n            }\r\n            finally\r\n            {\r\n                LuaAPI.lua_settop(L, oldTop);\r\n            }\r\n        }\r\n\r\n        [Obsolete(\"use no boxing version: Get<TKey, TValue> !\")]\r\n        public T Get<T>(object key)\r\n        {\r\n            T ret;\r\n            Get(key, out ret);\r\n            return ret;\r\n        }\r\n\r\n        public TValue Get<TKey, TValue>(TKey key)\r\n        {\r\n            TValue ret;\r\n            Get(key, out ret);\r\n            return ret;\r\n        }\r\n\r\n        public TValue Get<TValue>(string key)\r\n        {\r\n            TValue ret;\r\n            Get(key, out ret);\r\n            return ret;\r\n        }\r\n\r\n        public void SetMetaTable(LuaTable metaTable)\r\n        {\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                push(luaEnv.L);\r\n                metaTable.push(luaEnv.L);\r\n                LuaAPI.lua_setmetatable(luaEnv.L, -2);\r\n                LuaAPI.lua_pop(luaEnv.L, 1);\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        public T Cast<T>()\r\n        {\r\n            var L = luaEnv.L;\r\n            var translator = luaEnv.translator;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (luaEnv.luaEnvLock)\r\n            {\r\n#endif\r\n                push(L);\r\n                T ret = (T)translator.GetObject(L, -1, typeof(T));\r\n                LuaAPI.lua_pop(luaEnv.L, 1);\r\n                return ret;\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            }\r\n#endif\r\n        }\r\n\r\n        internal override void push(RealStatePtr L)\r\n        {\r\n            LuaAPI.lua_getref(L, luaReference);\r\n        }\r\n        public override string ToString()\r\n        {\r\n            return \"table :\" + luaReference;\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/LuaTable.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 3a4d72d338110544b8538c1a5fd33c11\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/MethodWarpsCache.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing System.Reflection;\r\n\r\nnamespace XLua\r\n{\r\n    public class OverloadMethodWrap\r\n    {\r\n        ObjectTranslator translator;\r\n        Type targetType;\r\n        MethodBase method;\r\n\r\n        ObjectCheck[] checkArray;\r\n        ObjectCast[] castArray;\r\n\r\n        int[] inPosArray;\r\n        int[] outPosArray;\r\n\r\n        bool[] isOptionalArray;\r\n\r\n        object[] defaultValueArray;\r\n\r\n        bool isVoid = true;\r\n\r\n        int luaStackPosStart = 1;\r\n\r\n        bool targetNeeded = false;\r\n\r\n        object[] args;\r\n\r\n        int[] refPos;\r\n\r\n        Type paramsType = null;\r\n\r\n        public bool HasDefalutValue{ get; private set; }\r\n\r\n        public OverloadMethodWrap(ObjectTranslator translator, Type targetType, MethodBase method)\r\n        {\r\n            this.translator = translator;\r\n            this.targetType = targetType;\r\n            this.method = method;\r\n            HasDefalutValue = false;\r\n        }\r\n\r\n        public void Init(ObjectCheckers objCheckers, ObjectCasters objCasters)\r\n        {\r\n            if ((typeof(Delegate) != targetType && typeof(Delegate).IsAssignableFrom(targetType)) ||\r\n                !method.IsStatic || method.IsConstructor)\r\n            {\r\n                luaStackPosStart = 2;\r\n                if (!method.IsConstructor)\r\n                {\r\n                    targetNeeded = true;\r\n                }\r\n            }\r\n\r\n            var paramInfos = method.GetParameters();\r\n            refPos = new int[paramInfos.Length];\r\n\r\n            List<int> inPosList = new List<int>();\r\n            List<int> outPosList = new List<int>();\r\n\r\n            List<ObjectCheck> paramsChecks = new List<ObjectCheck>();\r\n            List<ObjectCast> paramsCasts = new List<ObjectCast>();\r\n            List<bool> isOptionalList = new List<bool>();\r\n            List<object> defaultValueList = new List<object>();\r\n\r\n            for(int i = 0; i < paramInfos.Length; i++)\r\n            {\r\n                refPos[i] = -1;\r\n                if (!paramInfos[i].IsIn && paramInfos[i].IsOut)  // out parameter\r\n\t\t\t\t{\r\n\t\t\t\t\toutPosList.Add(i);\r\n\t\t\t\t}\r\n                else\r\n                {\r\n                    if(paramInfos[i].ParameterType.IsByRef)\r\n                    {\r\n                        var ttype = paramInfos[i].ParameterType.GetElementType();\r\n                        if(CopyByValue.IsStruct(ttype) && ttype != typeof(decimal))\r\n                        {\r\n                            refPos[i] = inPosList.Count;\r\n                        }\r\n                        outPosList.Add(i);\r\n                    }\r\n\r\n                    inPosList.Add(i);\r\n                    var paramType = paramInfos[i].IsDefined(typeof(ParamArrayAttribute), false) || (!paramInfos[i].ParameterType.IsArray && paramInfos[i].ParameterType.IsByRef ) ? \r\n                        paramInfos[i].ParameterType.GetElementType() : paramInfos[i].ParameterType;\r\n                    paramsChecks.Add (objCheckers.GetChecker(paramType));\r\n                    paramsCasts.Add (objCasters.GetCaster(paramType));\r\n                    isOptionalList.Add(paramInfos[i].IsOptional);\r\n                    var defalutValue = paramInfos[i].DefaultValue;\r\n                    if (paramInfos[i].IsOptional)\r\n                    {\r\n                        if (defalutValue != null && defalutValue.GetType() != paramInfos[i].ParameterType)\r\n                        {\r\n                            defalutValue = defalutValue.GetType() == typeof(Missing) ? (paramInfos[i].ParameterType.IsValueType() ? Activator.CreateInstance(paramInfos[i].ParameterType) : Missing.Value) \r\n                                : Convert.ChangeType(defalutValue, paramInfos[i].ParameterType);\r\n                        }\r\n                        HasDefalutValue = true;\r\n                    }\r\n                    defaultValueList.Add(paramInfos[i].IsOptional ? defalutValue : null);\r\n                }\r\n            }\r\n            checkArray = paramsChecks.ToArray();\r\n            castArray = paramsCasts.ToArray();\r\n            inPosArray = inPosList.ToArray();\r\n            outPosArray = outPosList.ToArray();\r\n            isOptionalArray = isOptionalList.ToArray();\r\n            defaultValueArray = defaultValueList.ToArray();\r\n\r\n            if (paramInfos.Length > 0 && paramInfos[paramInfos.Length - 1].IsDefined(typeof(ParamArrayAttribute), false))\r\n            {\r\n                paramsType = paramInfos[paramInfos.Length - 1].ParameterType.GetElementType();\r\n            }\r\n\r\n            args = new object[paramInfos.Length];\r\n\r\n            if (method is MethodInfo) //constructor is not MethodInfo?\r\n            {\r\n                isVoid = (method as MethodInfo).ReturnType == typeof(void);\r\n            }\r\n            else if(method is ConstructorInfo)\r\n            {\r\n                isVoid = false;\r\n            }\r\n        }\r\n\r\n        public bool Check(RealStatePtr L)\r\n        {\r\n            int luaTop = LuaAPI.lua_gettop(L);\r\n            int luaStackPos = luaStackPosStart;\r\n\r\n            for(int i = 0; i < checkArray.Length; i++)\r\n            {\r\n                if ((i == (checkArray.Length - 1)) && (paramsType != null))\r\n                {\r\n                    break;\r\n                }\r\n                if(luaStackPos > luaTop && !isOptionalArray[i])\r\n                {\r\n                    return false;\r\n                }\r\n                else if(luaStackPos <= luaTop && !checkArray[i](L, luaStackPos))\r\n                {\r\n                    return false;\r\n                }\r\n\r\n                if (luaStackPos <= luaTop || !isOptionalArray[i])\r\n                {\r\n                    luaStackPos++;\r\n                }\r\n            }\r\n\r\n            return paramsType != null ? (luaStackPos < luaTop + 1 ? \r\n                checkArray[checkArray.Length - 1](L, luaStackPos) : true) : luaStackPos == luaTop + 1;\r\n        }\r\n\r\n        public int Call(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n#if UNITY_EDITOR && !DISABLE_OBSOLETE_WARNING\r\n                if (method.IsDefined(typeof(ObsoleteAttribute), true))\r\n                {\r\n                    ObsoleteAttribute info = Attribute.GetCustomAttribute(method, typeof(ObsoleteAttribute)) as ObsoleteAttribute;\r\n                    UnityEngine.Debug.LogWarning(\"Obsolete Method [\" + method.DeclaringType.ToString() + \".\" + method.Name + \"]: \" + info.Message);\r\n                } \r\n#endif\r\n                object target = null;\r\n                MethodBase toInvoke = method;\r\n\r\n                if (luaStackPosStart > 1)\r\n                {\r\n                    target = translator.FastGetCSObj(L, 1);\r\n                    if (target is Delegate)\r\n                    {\r\n                        Delegate delegateInvoke = (Delegate)target;\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n                        toInvoke = delegateInvoke.GetMethodInfo();\r\n#else\r\n                        toInvoke = delegateInvoke.Method;\r\n#endif\r\n                    }\r\n                }\r\n\r\n\r\n                int luaTop = LuaAPI.lua_gettop(L);\r\n                int luaStackPos = luaStackPosStart;\r\n\r\n                for (int i = 0; i < castArray.Length; i++)\r\n                {\r\n                    //UnityEngine.Debug.Log(\"inPos:\" + inPosArray[i]);\r\n                    if (luaStackPos > luaTop) //after check\r\n                    {\r\n                        if (paramsType != null && i == castArray.Length - 1)\r\n                        {\r\n                            args[inPosArray[i]] = Array.CreateInstance(paramsType, 0);\r\n                        }\r\n                        else\r\n                        {\r\n                            args[inPosArray[i]] = defaultValueArray[i];\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        if (paramsType != null && i == castArray.Length - 1)\r\n                        {\r\n                            args[inPosArray[i]] = translator.GetParams(L, luaStackPos, paramsType);\r\n                        }\r\n                        else\r\n                        {\r\n                            args[inPosArray[i]] = castArray[i](L, luaStackPos, null);\r\n                        }\r\n                        luaStackPos++;\r\n                    }\r\n                    //UnityEngine.Debug.Log(\"value:\" + args[inPosArray[i]]);\r\n                }\r\n\r\n                object ret = null;\r\n\r\n\r\n                ret = toInvoke.IsConstructor ? ((ConstructorInfo)method).Invoke(args) : method.Invoke(targetNeeded ? target : null, args);\r\n\r\n                if (targetNeeded && targetType.IsValueType())\r\n                {\r\n                    translator.Update(L, 1, target);\r\n                }\r\n\r\n                int nRet = 0;\r\n\r\n                if (!isVoid)\r\n                {\r\n                    //UnityEngine.Debug.Log(toInvoke.ToString() + \" ret:\" + ret);\r\n                    translator.PushAny(L, ret);\r\n                    nRet++;\r\n                }\r\n\r\n                for (int i = 0; i < outPosArray.Length; i++)\r\n                {\r\n                    if (refPos[outPosArray[i]] != -1)\r\n                    {\r\n                        translator.Update(L, luaStackPosStart + refPos[outPosArray[i]], args[outPosArray[i]]);\r\n                    }\r\n                    translator.PushAny(L, args[outPosArray[i]]);\r\n                    nRet++;\r\n                }\r\n\r\n                return nRet;\r\n            }\r\n            finally\r\n            {\r\n                for(int i = 0; i < args.Length; i++)\r\n                {\r\n                    args[i] = null;\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    public class MethodWrap\r\n    {\r\n        private string methodName;\r\n        private List<OverloadMethodWrap> overloads = new List<OverloadMethodWrap>();\r\n        private bool forceCheck;\r\n\r\n        public MethodWrap(string methodName, List<OverloadMethodWrap> overloads, bool forceCheck)\r\n        {\r\n            this.methodName = methodName;\r\n            this.overloads = overloads;\r\n            this.forceCheck = forceCheck;\r\n        }\r\n\r\n        public int Call(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                if (overloads.Count == 1 && !overloads[0].HasDefalutValue && !forceCheck) return overloads[0].Call(L);\r\n\r\n                for (int i = 0; i < overloads.Count; ++i)\r\n                {\r\n                    var overload = overloads[i];\r\n                    if (overload.Check(L))\r\n                    {\r\n                        return overload.Call(L);\r\n                    }\r\n                }\r\n                return LuaAPI.luaL_error(L, \"invalid arguments to \" + methodName);\r\n            }\r\n            catch (System.Reflection.TargetInvocationException e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + e.InnerException.Message + \",stack:\" + e.InnerException.StackTrace);\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + e.Message + \",stack:\" + e.StackTrace);\r\n            }\r\n        }\r\n    }\r\n\r\n    public class MethodWrapsCache\r\n    {\r\n        ObjectTranslator translator;\r\n        ObjectCheckers objCheckers;\r\n        ObjectCasters objCasters;\r\n\r\n        Dictionary<Type, LuaCSFunction> constructorCache = new Dictionary<Type, LuaCSFunction>();\r\n        Dictionary<Type, Dictionary<string, LuaCSFunction>> methodsCache = new Dictionary<Type, Dictionary<string, LuaCSFunction>>();\r\n        Dictionary<Type, LuaCSFunction> delegateCache = new Dictionary<Type, LuaCSFunction>();\r\n\r\n        public MethodWrapsCache(ObjectTranslator translator, ObjectCheckers objCheckers, ObjectCasters objCasters)\r\n        {\r\n            this.translator = translator;\r\n            this.objCheckers = objCheckers;\r\n            this.objCasters = objCasters;\r\n        }\r\n\r\n        public LuaCSFunction GetConstructorWrap(Type type)\r\n        {\r\n            //UnityEngine.Debug.LogWarning(\"GetConstructor:\" + type);\r\n            if (!constructorCache.ContainsKey(type))\r\n            {\r\n                var constructors = type.GetConstructors();\r\n                if (type.IsAbstract() || constructors == null || constructors.Length == 0)\r\n                {\r\n                    if (type.IsValueType())\r\n                    {\r\n                        constructorCache[type] = (L) =>\r\n                        {\r\n                            translator.PushAny(L, Activator.CreateInstance(type));\r\n                            return 1;\r\n                        };\r\n                    }\r\n                    else\r\n                    {\r\n                        return null;\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    LuaCSFunction ctor = _GenMethodWrap(type, \".ctor\", constructors, true).Call;\r\n                    \r\n                    if (type.IsValueType())\r\n                    {\r\n                        bool hasZeroParamsCtor = false;\r\n                        for (int i = 0; i < constructors.Length; i++)\r\n                        {\r\n                            if (constructors[i].GetParameters().Length == 0)\r\n                            {\r\n                                hasZeroParamsCtor = true;\r\n                                break;\r\n                            }\r\n                        }\r\n                        if (hasZeroParamsCtor)\r\n                        {\r\n                            constructorCache[type] = ctor;\r\n                        }\r\n                        else\r\n                        {\r\n                            constructorCache[type] = (L) =>\r\n                            {\r\n                                if (LuaAPI.lua_gettop(L) == 1)\r\n                                {\r\n                                    translator.PushAny(L, Activator.CreateInstance(type));\r\n                                    return 1;\r\n                                }\r\n                                else\r\n                                {\r\n                                    return ctor(L);\r\n                                }\r\n                            };\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        constructorCache[type] = ctor;\r\n                    }\r\n                }\r\n            }\r\n            return constructorCache[type];\r\n        }\r\n\r\n        public LuaCSFunction GetMethodWrap(Type type, string methodName)\r\n        {\r\n            //UnityEngine.Debug.LogWarning(\"GetMethodWrap:\" + type + \" \" + methodName);\r\n            if (!methodsCache.ContainsKey(type))\r\n            {\r\n                methodsCache[type] = new Dictionary<string, LuaCSFunction>();\r\n            }\r\n            var methodsOfType = methodsCache[type];\r\n            if (!methodsOfType.ContainsKey(methodName))\r\n            {\r\n                MemberInfo[] methods = type.GetMember(methodName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);\r\n                if (methods == null || methods.Length == 0 ||\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n                    methods[0] is MethodBase\r\n#else\r\n                    methods[0].MemberType != MemberTypes.Method\r\n#endif\r\n                    )\r\n                {\r\n                    return null;\r\n                }\r\n                methodsOfType[methodName] = _GenMethodWrap(type, methodName, methods).Call;\r\n            }\r\n            return methodsOfType[methodName];\r\n        }\r\n\r\n        public LuaCSFunction GetMethodWrapInCache(Type type, string methodName)\r\n        {\r\n            //string retriKey = type.ToString() + \".\" + methodName;\r\n            //return methodsCache.ContainsKey(retriKey) ? methodsCache[retriKey] : null;\r\n            if (!methodsCache.ContainsKey(type))\r\n            {\r\n                methodsCache[type] = new Dictionary<string, LuaCSFunction>();\r\n            }\r\n            var methodsOfType = methodsCache[type];\r\n            return methodsOfType.ContainsKey(methodName) ? methodsOfType[methodName] : null;\r\n        }\r\n\r\n        public LuaCSFunction GetDelegateWrap(Type type)\r\n        {\r\n            //UnityEngine.Debug.LogWarning(\"GetDelegateWrap:\" + type );\r\n            if (!typeof(Delegate).IsAssignableFrom(type))\r\n            {\r\n                return null;\r\n            }\r\n            if (!delegateCache.ContainsKey(type))\r\n            {\r\n                delegateCache[type] = _GenMethodWrap(type, type.ToString(), new MethodBase[] { type.GetMethod(\"Invoke\") }).Call;\r\n            }\r\n            return delegateCache[type];\r\n        }\r\n\r\n        public LuaCSFunction GetEventWrap(Type type, string eventName)\r\n        {\r\n            if (!methodsCache.ContainsKey(type))\r\n            {\r\n                methodsCache[type] = new Dictionary<string, LuaCSFunction>();\r\n            }\r\n\r\n            var methodsOfType = methodsCache[type];\r\n            if (!methodsOfType.ContainsKey(eventName))\r\n            {\r\n                {\r\n                    EventInfo eventInfo = type.GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic);\r\n                    if (eventInfo == null)\r\n                    {\r\n                        throw new Exception(type.Name + \" has no event named: \" + eventName);\r\n                    }\r\n                    int start_idx = 0;\r\n\r\n                    MethodInfo add = eventInfo.GetAddMethod(true);\r\n                    MethodInfo remove = eventInfo.GetRemoveMethod(true);\r\n\r\n                    if (add == null && remove == null)\r\n                    {\r\n                        throw new Exception(type.Name + \"'s \" + eventName + \" has either add nor remove\");\r\n                    }\r\n\r\n                    bool is_static = add != null ? add.IsStatic : remove.IsStatic;\r\n                    if (!is_static) start_idx = 1;\r\n\r\n                    methodsOfType[eventName] = (L) =>\r\n                    {\r\n                        object obj = null;\r\n\r\n                        if (!is_static)\r\n                        {\r\n                            obj = translator.GetObject(L, 1, type);\r\n                            if (obj == null)\r\n                            {\r\n                                return LuaAPI.luaL_error(L, \"invalid #1, needed:\" + type);\r\n                            }\r\n                        }\r\n\r\n                        try\r\n                        {\r\n                            object handlerDelegate = translator.CreateDelegateBridge(L, eventInfo.EventHandlerType, start_idx + 2);\r\n                            if (handlerDelegate == null)\r\n                            {\r\n                                return LuaAPI.luaL_error(L, \"invalid #\" + (start_idx + 2) + \", needed:\" + eventInfo.EventHandlerType);\r\n                            }\r\n                            switch (LuaAPI.lua_tostring(L, start_idx + 1))\r\n                            {\r\n                                case \"+\":\r\n                                    if (add == null)\r\n                                    {\r\n                                        return LuaAPI.luaL_error(L, \"no add for event \" + eventName);\r\n                                    }\r\n                                    add.Invoke(obj, new object[] { handlerDelegate });\r\n                                    break;\r\n                                case \"-\":\r\n                                    if (remove == null)\r\n                                    {\r\n                                        return LuaAPI.luaL_error(L, \"no remove for event \" + eventName);\r\n                                    }\r\n                                    remove.Invoke(obj, new object[] { handlerDelegate });\r\n                                    break;\r\n                                default:\r\n                                    return LuaAPI.luaL_error(L, \"invalid #\" + (start_idx + 1) + \", needed: '+' or '-'\" + eventInfo.EventHandlerType);\r\n                            }\r\n                        }\r\n                        catch (System.Exception e)\r\n                        {\r\n                            return LuaAPI.luaL_error(L, \"c# exception:\" + e + \",stack:\" + e.StackTrace);\r\n                        }\r\n\r\n                        return 0;\r\n                    };\r\n                }\r\n            }\r\n            return methodsOfType[eventName];\r\n        }\r\n\r\n        public MethodWrap _GenMethodWrap(Type type, string methodName, IEnumerable<MemberInfo> methodBases, bool forceCheck = false)\r\n        { \r\n            List<OverloadMethodWrap> overloads = new List<OverloadMethodWrap>();\r\n            foreach(var methodBase in methodBases)\r\n            {\r\n                var mb = methodBase as MethodBase;\r\n                if (mb == null)\r\n                    continue;\r\n\r\n                if (mb.IsGenericMethodDefinition\r\n#if !ENABLE_IL2CPP\r\n                     && !tryMakeGenericMethod(ref mb)\r\n#endif\r\n                    )\r\n                    continue;\r\n\r\n                var overload = new OverloadMethodWrap(translator, type, mb);\r\n                overload.Init(objCheckers, objCasters);\r\n                overloads.Add(overload);\r\n            }\r\n            return new MethodWrap(methodName, overloads, forceCheck);\r\n        }\r\n\r\n        private static bool tryMakeGenericMethod(ref MethodBase method)\r\n        {\r\n            try\r\n            {\r\n                if (!(method is MethodInfo) || !Utils.IsSupportedMethod(method as MethodInfo) )\r\n                {\r\n                    return false;\r\n                }\r\n                var genericArguments = method.GetGenericArguments();\r\n                var constraintedArgumentTypes = new Type[genericArguments.Length];\r\n                for (var i = 0; i < genericArguments.Length; i++)\r\n                {\r\n                    var argumentType = genericArguments[i];\r\n                    var parameterConstraints = argumentType.GetGenericParameterConstraints();\r\n                    constraintedArgumentTypes[i] = parameterConstraints[0];\r\n                }\r\n                method = ((MethodInfo)method).MakeGenericMethod(constraintedArgumentTypes);\r\n                return true;\r\n            }\r\n            catch (Exception)\r\n            {\r\n                return false;\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/MethodWarpsCache.cs.meta",
    "content": "fileFormatVersion: 2\nguid: d5f029e1a01fd984f92bf8d5c2b51923\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/ObjectCasters.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing System.Reflection;\r\n\r\nnamespace XLua\r\n{\r\n    public delegate bool ObjectCheck(RealStatePtr L, int idx);\r\n\r\n    public delegate object ObjectCast(RealStatePtr L, int idx, object target); // if target is null, will new one\r\n\r\n    public class ObjectCheckers\r\n    {\r\n        Dictionary<Type, ObjectCheck> checkersMap = new Dictionary<Type, ObjectCheck>();\r\n        ObjectTranslator translator;\r\n\r\n        public ObjectCheckers(ObjectTranslator translator)\r\n        {\r\n            this.translator = translator;\r\n            checkersMap[typeof(sbyte)] = numberCheck;\r\n            checkersMap[typeof(byte)] = numberCheck;\r\n            checkersMap[typeof(short)] = numberCheck;\r\n            checkersMap[typeof(ushort)] = numberCheck;\r\n            checkersMap[typeof(int)] = numberCheck;\r\n            checkersMap[typeof(uint)] = numberCheck;\r\n            checkersMap[typeof(long)] = int64Check;\r\n            checkersMap[typeof(ulong)] = uint64Check;\r\n            checkersMap[typeof(double)] = numberCheck;\r\n            checkersMap[typeof(char)] = numberCheck;\r\n            checkersMap[typeof(float)] = numberCheck;\r\n            checkersMap[typeof(decimal)] = decimalCheck;\r\n            checkersMap[typeof(bool)] = boolCheck;\r\n            checkersMap[typeof(string)] = strCheck;\r\n            checkersMap[typeof(object)] = objectCheck;\r\n            checkersMap[typeof(byte[])] = bytesCheck;\r\n            checkersMap[typeof(IntPtr)] = intptrCheck;\r\n\r\n            checkersMap[typeof(LuaTable)] = luaTableCheck;\r\n            checkersMap[typeof(LuaFunction)] = luaFunctionCheck;\r\n        }\r\n\r\n        private static bool objectCheck(RealStatePtr L, int idx)\r\n        {\r\n            return true;\r\n        }\r\n\r\n        private bool luaTableCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_istable(L, idx) || (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA && translator.SafeGetCSObj(L, idx) is LuaTable);\r\n        }\r\n\r\n        private bool numberCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER;\r\n        }\r\n\r\n        private bool decimalCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || translator.IsDecimal(L, idx);\r\n        }\r\n\r\n        private bool strCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING || LuaAPI.lua_isnil(L, idx);\r\n        }\r\n\r\n        private bool bytesCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING || LuaAPI.lua_isnil(L, idx) || (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA && translator.SafeGetCSObj(L, idx) is byte[]);\r\n        }\r\n\r\n        private bool boolCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TBOOLEAN;\r\n        }\r\n\r\n        private bool int64Check(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || LuaAPI.lua_isint64(L, idx);\r\n        }\r\n\r\n        private bool uint64Check(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || LuaAPI.lua_isuint64(L, idx);\r\n        }\r\n\r\n        private bool luaFunctionCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_isfunction(L, idx) || (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA && translator.SafeGetCSObj(L, idx) is LuaFunction);\r\n        }\r\n\r\n        private bool intptrCheck(RealStatePtr L, int idx)\r\n        {\r\n            return LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TLIGHTUSERDATA;\r\n        }\r\n\r\n        private ObjectCheck genChecker(Type type)\r\n        {\r\n            ObjectCheck fixTypeCheck = (RealStatePtr L, int idx) =>\r\n            {\r\n                if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA)\r\n                {\r\n                    object obj = translator.SafeGetCSObj(L, idx);\r\n                    if (obj != null)\r\n                    {\r\n                        return type.IsAssignableFrom(obj.GetType());\r\n                    }\r\n                    else\r\n                    {\r\n                        Type type_of_obj = translator.GetTypeOf(L, idx);\r\n                        if (type_of_obj != null) return type.IsAssignableFrom(type_of_obj);\r\n                    }\r\n                }\r\n                return false;\r\n            };\r\n\r\n            if (!type.IsAbstract() && typeof(Delegate).IsAssignableFrom(type))\r\n            {\r\n                return (RealStatePtr L, int idx) =>\r\n                {\r\n                    return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_isfunction(L, idx) || fixTypeCheck(L, idx);\r\n                };\r\n            }\r\n            else if (type.IsEnum())\r\n            {\r\n                return fixTypeCheck;\r\n            }\r\n            else if (type.IsInterface())\r\n            {\r\n                return (RealStatePtr L, int idx) =>\r\n                {\r\n                    return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_istable(L, idx) || fixTypeCheck(L, idx);\r\n                };\r\n            }\r\n            else\r\n            {\r\n                if ((type.IsClass() && type.GetConstructor(System.Type.EmptyTypes) != null)) //class has default construtor\r\n                {\r\n                    return (RealStatePtr L, int idx) =>\r\n                    {\r\n                        return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_istable(L, idx) || fixTypeCheck(L, idx);\r\n                    };\r\n                }\r\n                else if (type.IsValueType())\r\n                {\r\n                    return (RealStatePtr L, int idx) =>\r\n                    {\r\n                        return LuaAPI.lua_istable(L, idx) || fixTypeCheck(L, idx);\r\n                    };\r\n                }\r\n                else if (type.IsArray)\r\n                {\r\n                    return (RealStatePtr L, int idx) =>\r\n                    {\r\n                        return LuaAPI.lua_isnil(L, idx) || LuaAPI.lua_istable(L, idx) || fixTypeCheck(L, idx);\r\n                    };\r\n                }\r\n                else\r\n                {\r\n                    return (RealStatePtr L, int idx) =>\r\n                    {\r\n                        return LuaAPI.lua_isnil(L, idx) || fixTypeCheck(L, idx);\r\n                    };\r\n                }\r\n            }\r\n        }\r\n\r\n        public ObjectCheck genNullableChecker(ObjectCheck oc)\r\n        {\r\n            return (RealStatePtr L, int idx) =>\r\n            {\r\n                return LuaAPI.lua_isnil(L, idx) || oc(L, idx);\r\n            };\r\n        }\r\n\r\n        public void AddChecker(Type type, ObjectCheck oc)\r\n        {\r\n            checkersMap[type] = oc;\r\n        }\r\n\r\n        public ObjectCheck GetChecker(Type type)\r\n        {\r\n            if (type.IsByRef) type = type.GetElementType();\r\n\r\n            Type underlyingType = Nullable.GetUnderlyingType(type);\r\n            if (underlyingType != null)\r\n            {\r\n                return genNullableChecker(GetChecker(underlyingType));\r\n            }\r\n            ObjectCheck oc;\r\n            if (!checkersMap.TryGetValue(type, out oc))\r\n            {\r\n                oc = genChecker(type);\r\n                checkersMap.Add(type, oc);\r\n            }\r\n            return oc;\r\n        }\r\n    }\r\n\r\n    public class ObjectCasters\r\n    {\r\n        Dictionary<Type, ObjectCast> castersMap = new Dictionary<Type, ObjectCast>();\r\n        ObjectTranslator translator;\r\n\r\n        public ObjectCasters(ObjectTranslator translator)\r\n        {\r\n            this.translator = translator;\r\n            castersMap[typeof(char)] = charCaster;\r\n            castersMap[typeof(sbyte)] = sbyteCaster;\r\n            castersMap[typeof(byte)] = byteCaster;\r\n            castersMap[typeof(short)] = shortCaster;\r\n            castersMap[typeof(ushort)] = ushortCaster;\r\n            castersMap[typeof(int)] = intCaster;\r\n            castersMap[typeof(uint)] = uintCaster;\r\n            castersMap[typeof(long)] = longCaster;\r\n            castersMap[typeof(ulong)] = ulongCaster;\r\n            castersMap[typeof(double)] = getDouble;\r\n            castersMap[typeof(float)] = floatCaster;\r\n            castersMap[typeof(decimal)] = decimalCaster;\r\n            castersMap[typeof(bool)] = getBoolean;\r\n            castersMap[typeof(string)] =  getString;\r\n            castersMap[typeof(object)] = getObject;\r\n            castersMap[typeof(byte[])] = getBytes;\r\n            castersMap[typeof(IntPtr)] = getIntptr;\r\n            //special type\r\n            castersMap[typeof(LuaTable)] = getLuaTable;\r\n            castersMap[typeof(LuaFunction)] = getLuaFunction;\r\n        }\r\n\r\n        private static object charCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (char)LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object sbyteCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (sbyte)LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object byteCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (byte)LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object shortCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (short)LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object ushortCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (ushort)LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object intCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.xlua_tointeger(L, idx);\r\n        }\r\n\r\n        private static object uintCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.xlua_touint(L, idx);\r\n        }\r\n\r\n        private static object longCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_toint64(L, idx);\r\n        }\r\n\r\n        private static object ulongCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_touint64(L, idx);\r\n        }\r\n\r\n        private static object getDouble(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_tonumber(L, idx);\r\n        }\r\n\r\n        private static object floatCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            return (float)LuaAPI.lua_tonumber(L, idx);\r\n        }\r\n\r\n        private object decimalCaster(RealStatePtr L, int idx, object target)\r\n        {\r\n            decimal ret;\r\n            translator.Get(L, idx, out ret);\r\n            return ret;\r\n        }\r\n\r\n        private static object getBoolean(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_toboolean(L, idx);\r\n        }\r\n\r\n        private static object getString(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_tostring(L, idx);\r\n        }\r\n\r\n        private object getBytes(RealStatePtr L, int idx, object target)\r\n        {\r\n            if(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING)\r\n            {\r\n                return LuaAPI.lua_tobytes(L, idx);\r\n            }\r\n            object obj = translator.SafeGetCSObj(L, idx);\r\n            return (obj is RawObject) ? (obj as RawObject).Target : obj as byte[];\r\n        }\r\n\r\n        private object getIntptr(RealStatePtr L, int idx, object target)\r\n        {\r\n            return LuaAPI.lua_touserdata(L, idx);\r\n        }\r\n\r\n        private object getObject(RealStatePtr L, int idx, object target)\r\n        {\r\n            //return translator.getObject(L, idx); //TODO: translator.getObject move to here??\r\n            LuaTypes type = (LuaTypes)LuaAPI.lua_type(L, idx);\r\n            switch (type)\r\n            {\r\n                case LuaTypes.LUA_TNUMBER:\r\n                    {\r\n                        if (LuaAPI.lua_isint64(L, idx))\r\n                        {\r\n                            return LuaAPI.lua_toint64(L, idx);\r\n                        }\r\n                        else if(LuaAPI.lua_isinteger(L, idx))\r\n                        {\r\n                            return LuaAPI.xlua_tointeger(L, idx);\r\n                        }\r\n                        else\r\n                        {\r\n                            return LuaAPI.lua_tonumber(L, idx);\r\n                        }\r\n                    }\r\n                case LuaTypes.LUA_TSTRING:\r\n                    {\r\n                        return LuaAPI.lua_tostring(L, idx);\r\n                    }\r\n                case LuaTypes.LUA_TBOOLEAN:\r\n                    {\r\n                        return LuaAPI.lua_toboolean(L, idx);\r\n                    }\r\n                case LuaTypes.LUA_TTABLE:\r\n                    {\r\n                        return getLuaTable(L, idx, null);\r\n                    }\r\n                case LuaTypes.LUA_TFUNCTION:\r\n                    {\r\n                        return getLuaFunction(L, idx, null);\r\n                    }\r\n                case LuaTypes.LUA_TUSERDATA:\r\n                    {\r\n                        if (LuaAPI.lua_isint64(L, idx))\r\n                        {\r\n                            return LuaAPI.lua_toint64(L, idx);\r\n                        }\r\n                        else if(LuaAPI.lua_isuint64(L, idx))\r\n                        {\r\n                            return LuaAPI.lua_touint64(L, idx);\r\n                        }\r\n                        else\r\n                        {\r\n                            object obj = translator.SafeGetCSObj(L, idx);\r\n                            return (obj is RawObject) ? (obj as RawObject).Target : obj;\r\n                        }\r\n                    }\r\n                default:\r\n                    return null;\r\n            }\r\n        }\r\n\r\n        private object getLuaTable(RealStatePtr L, int idx, object target)\r\n        {\r\n            if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA)\r\n            {\r\n                object obj = translator.SafeGetCSObj(L, idx);\r\n                return (obj != null && obj is LuaTable) ? obj : null;\r\n            }\r\n            if (!LuaAPI.lua_istable(L, idx))\r\n            {\r\n                return null;\r\n            }\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            return new LuaTable(LuaAPI.luaL_ref(L), translator.luaEnv);\r\n        }\r\n\r\n        private object getLuaFunction(RealStatePtr L, int idx, object target)\r\n        {\r\n            if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA)\r\n            {\r\n                object obj = translator.SafeGetCSObj(L, idx);\r\n                return (obj != null && obj is LuaFunction) ? obj : null;\r\n            }\r\n            if (!LuaAPI.lua_isfunction(L, idx))\r\n            {\r\n                return null;\r\n            }\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            return new LuaFunction(LuaAPI.luaL_ref(L), translator.luaEnv);\r\n        }\r\n\r\n        public void AddCaster(Type type, ObjectCast oc)\r\n        {\r\n            castersMap[type] = oc;\r\n        }\r\n\r\n        private ObjectCast genCaster(Type type)\r\n        {\r\n            ObjectCast fixTypeGetter = (RealStatePtr L, int idx, object target) =>\r\n            {\r\n                if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TUSERDATA)\r\n                {\r\n                    object obj = translator.SafeGetCSObj(L, idx);\r\n                    return (obj != null && type.IsAssignableFrom(obj.GetType())) ? obj : null;\r\n                }\r\n                return null;\r\n            }; \r\n\r\n            if (typeof(Delegate).IsAssignableFrom(type))\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_isfunction(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    return translator.CreateDelegateBridge(L, type, idx);\r\n                };\r\n            }\r\n            else if (typeof(DelegateBridgeBase).IsAssignableFrom(type))\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_isfunction(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    return translator.CreateDelegateBridge(L, null, idx);\r\n                };\r\n            }\r\n            else if (type.IsInterface())\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_istable(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n                    return translator.CreateInterfaceBridge(L, type, idx);\r\n                };\r\n            }\r\n            else if (type.IsEnum())\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    LuaTypes lua_type = LuaAPI.lua_type(L, idx);\r\n                    if (lua_type == LuaTypes.LUA_TSTRING)\r\n                    {\r\n                        return Enum.Parse(type, LuaAPI.lua_tostring(L, idx));\r\n                    }\r\n                    else if (lua_type == LuaTypes.LUA_TNUMBER)\r\n                    {\r\n                        return Enum.ToObject(type, LuaAPI.xlua_tointeger(L, idx));\r\n                    }\r\n                    throw new InvalidCastException(\"invalid value for enum \" + type);\r\n                };\r\n            }\r\n            else if (type.IsArray)\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_istable(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    uint len = LuaAPI.xlua_objlen(L, idx);\r\n                    int n = LuaAPI.lua_gettop(L);\r\n                    idx = idx > 0 ? idx : LuaAPI.lua_gettop(L) + idx + 1;// abs of index\r\n                    Type et = type.GetElementType();\r\n                    ObjectCast elementCaster = GetCaster(et);\r\n                    Array ary = target == null ? Array.CreateInstance(et, (int)len) : target as Array;\r\n                    if (!LuaAPI.lua_checkstack(L, 1))\r\n                    {\r\n                        throw new Exception(\"stack overflow while cast to Array\");\r\n                    }\r\n                    for (int i = 0; i < len; ++i)\r\n                    {\r\n                        LuaAPI.lua_pushnumber(L, i + 1);\r\n                        LuaAPI.lua_rawget(L, idx);\r\n                        if (et.IsPrimitive())\r\n                        {\r\n                            if (!StaticLuaCallbacks.TryPrimitiveArraySet(type, L, ary, i, n + 1))\r\n                            {\r\n                                ary.SetValue(elementCaster(L, n + 1, null), i);\r\n                            }\r\n                        }\r\n                        else\r\n                        {\r\n                            if (InternalGlobals.genTryArraySetPtr == null\r\n                                || !InternalGlobals.genTryArraySetPtr(type, L, translator, ary, i, n + 1))\r\n                            {\r\n                                ary.SetValue(elementCaster(L, n + 1, null), i);\r\n                            }\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1);\r\n                    }\r\n                    return ary;\r\n                };\r\n            }\r\n            else if (typeof(IList).IsAssignableFrom(type) && type.IsGenericType())\r\n            {\r\n                Type elementType = type.GetGenericArguments()[0];\r\n                ObjectCast elementCaster = GetCaster(elementType);\r\n\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_istable(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    obj = target == null ? Activator.CreateInstance(type) : target;\r\n                    int n = LuaAPI.lua_gettop(L);\r\n                    idx = idx > 0 ? idx : LuaAPI.lua_gettop(L) + idx + 1;// abs of index\r\n                    IList list = obj as IList;\r\n\r\n\r\n                    uint len = LuaAPI.xlua_objlen(L, idx);\r\n                    if (!LuaAPI.lua_checkstack(L, 1))\r\n                    {\r\n                        throw new Exception(\"stack overflow while cast to IList\");\r\n                    }\r\n                    for (int i = 0; i < len; ++i)\r\n                    {\r\n                        LuaAPI.lua_pushnumber(L, i + 1);\r\n                        LuaAPI.lua_rawget(L, idx);\r\n                        if (i < list.Count && target != null)\r\n                        {\r\n                            if (translator.Assignable(L, n + 1, elementType))\r\n                            {\r\n                                list[i] = elementCaster(L, n + 1, list[i]); ;\r\n                            }\r\n                        }\r\n                        else\r\n                        {\r\n                            if (translator.Assignable(L, n + 1, elementType))\r\n                            {\r\n                                list.Add(elementCaster(L, n + 1, null));\r\n                            }\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1);\r\n                    }\r\n                    return obj;\r\n                };\r\n            }\r\n            else if (typeof(IDictionary).IsAssignableFrom(type) && type.IsGenericType())\r\n            {\r\n                Type keyType = type.GetGenericArguments()[0];\r\n                ObjectCast keyCaster = GetCaster(keyType);\r\n                Type valueType = type.GetGenericArguments()[1];\r\n                ObjectCast valueCaster = GetCaster(valueType);\r\n\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_istable(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    IDictionary dic = (target == null ? Activator.CreateInstance(type) : target) as IDictionary;\r\n                    int n = LuaAPI.lua_gettop(L);\r\n                    idx = idx > 0 ? idx : LuaAPI.lua_gettop(L) + idx + 1;// abs of index\r\n\r\n                    LuaAPI.lua_pushnil(L);\r\n                    if (!LuaAPI.lua_checkstack(L, 1))\r\n                    {\r\n                        throw new Exception(\"stack overflow while cast to IDictionary\");\r\n                    }\r\n                    while (LuaAPI.lua_next(L, idx) != 0)\r\n                    {\r\n                        if (translator.Assignable(L, n + 1, keyType) && translator.Assignable(L, n + 2, valueType))\r\n                        {\r\n                            object k = keyCaster(L, n + 1, null);\r\n                            dic[k] = valueCaster(L, n + 2, !dic.Contains(k) ? null : dic[k]);\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1); // removes value, keeps key for next iteration\r\n                    }\r\n                    return dic;\r\n                };\r\n            }\r\n            else if ((type.IsClass() && type.GetConstructor(System.Type.EmptyTypes) != null) || (type.IsValueType() && !type.IsEnum())) //class has default construtor\r\n            {\r\n                return (RealStatePtr L, int idx, object target) =>\r\n                {\r\n                    object obj = fixTypeGetter(L, idx, target);\r\n                    if (obj != null) return obj;\r\n\r\n                    if (!LuaAPI.lua_istable(L, idx))\r\n                    {\r\n                        return null;\r\n                    }\r\n\r\n                    obj = target == null ? Activator.CreateInstance(type) : target;\r\n\r\n                    int n = LuaAPI.lua_gettop(L);\r\n                    idx = idx > 0 ? idx : LuaAPI.lua_gettop(L) + idx + 1;// abs of index\r\n                    if (!LuaAPI.lua_checkstack(L, 1))\r\n                    {\r\n                        throw new Exception(\"stack overflow while cast to \" + type);\r\n                    }\r\n                    /*foreach (PropertyInfo prop in type.GetProperties())\r\n                    {\r\n                        var _setMethod = prop.GetSetMethod();\r\n\r\n                        if (_setMethod == null ||\r\n                            _setMethod.IsPrivate)\r\n                        {\r\n                            continue;\r\n                        }\r\n\r\n                        LuaAPI.xlua_pushasciistring(L, prop.Name);\r\n                        LuaAPI.lua_rawget(L, idx);\r\n                        if (!LuaAPI.lua_isnil(L, -1))\r\n                        {\r\n                            try\r\n                            {\r\n                                prop.SetValue(obj, GetCaster(prop.PropertyType)(L, n + 1,\r\n                                    target == null || prop.PropertyType.IsPrimitive() || prop.PropertyType == typeof(string) ? null : prop.GetValue(obj, null)), null);\r\n                            }\r\n                            catch (Exception e)\r\n                            {\r\n                                throw new Exception(\"exception in tran \" + prop.Name + \", msg=\" + e.Message);\r\n                            }\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1);\r\n                    }*/\r\n                    foreach (FieldInfo field in type.GetFields())\r\n                    {\r\n                        LuaAPI.xlua_pushasciistring(L, field.Name);\r\n                        LuaAPI.lua_rawget(L, idx);\r\n                        if (!LuaAPI.lua_isnil(L, -1))\r\n                        {\r\n                            try\r\n                            {\r\n                                field.SetValue(obj, GetCaster(field.FieldType)(L, n + 1,\r\n                                        target == null || field.FieldType.IsPrimitive() || field.FieldType == typeof(string) ? null : field.GetValue(obj)));\r\n                            }\r\n                            catch (Exception e)\r\n                            {\r\n                                throw new Exception(\"exception in tran \" + field.Name + \", msg=\" + e.Message);\r\n                            }\r\n                        }\r\n                        LuaAPI.lua_pop(L, 1);\r\n                    }\r\n\r\n                    return obj;\r\n                };\r\n            }\r\n            else\r\n            {\r\n                return fixTypeGetter;\r\n            }\r\n        }\r\n\r\n        ObjectCast genNullableCaster(ObjectCast oc)\r\n        {\r\n            return (RealStatePtr L, int idx, object target) =>\r\n            {\r\n                if (LuaAPI.lua_isnil(L, idx))\r\n                {\r\n                    return null;\r\n                }\r\n                else\r\n                {\r\n                    return oc(L, idx, target);\r\n                }\r\n            };\r\n        }\r\n\r\n        public ObjectCast GetCaster(Type type)\r\n        {\r\n            if (type.IsByRef) type = type.GetElementType();\r\n\r\n            Type underlyingType = Nullable.GetUnderlyingType(type);\r\n            if (underlyingType != null)\r\n            {\r\n                return genNullableCaster(GetCaster(underlyingType)); \r\n            }\r\n            ObjectCast oc;\r\n            if (!castersMap.TryGetValue(type, out oc))\r\n            {\r\n                oc = genCaster(type);\r\n                castersMap.Add(type, oc);\r\n            }\r\n            return oc;\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/ObjectCasters.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 04cef766c4f15b341bcb4659831e6748\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/ObjectPool.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\n\r\nnamespace XLua\r\n{\r\n    public class ObjectPool\r\n    {\r\n        const int LIST_END = -1;\r\n        const int ALLOCED = -2;\r\n        struct Slot\r\n        {\r\n            public int next;\r\n            public object obj;\r\n\r\n            public Slot(int next, object obj)\r\n            {\r\n                this.next = next;\r\n                this.obj = obj;\r\n            }\r\n        }\r\n\r\n        private Slot[] list = new Slot[512];\r\n        private int freelist = LIST_END;\r\n        private int count = 0;\r\n\r\n        public object this[int i]\r\n        {\r\n            get\r\n            {\r\n                if (i >= 0 && i < count)\r\n                {\r\n                    return list[i].obj;\r\n                }\r\n\r\n                return null;\r\n            }\r\n        }\r\n\r\n        public void Clear()\r\n        {\r\n            freelist = LIST_END;\r\n            count = 0;\r\n            list = new Slot[512];\r\n        }\r\n\r\n        void extend_capacity()\r\n        {\r\n            Slot[] new_list = new Slot[list.Length * 2];\r\n            for (int i = 0; i < list.Length; i++)\r\n            {\r\n                new_list[i] = list[i];\r\n            }\r\n            list = new_list;\r\n        }\r\n\r\n        public int Add(object obj)\r\n        {\r\n            int index = LIST_END;\r\n\r\n            if (freelist != LIST_END)\r\n            {\r\n                index = freelist;\r\n                list[index].obj = obj;\r\n                freelist = list[index].next;\r\n                list[index].next = ALLOCED;\r\n            }\r\n            else\r\n            {\r\n                if (count == list.Length)\r\n                {\r\n                    extend_capacity();\r\n                }\r\n                index = count;\r\n                list[index] = new Slot(ALLOCED, obj);\r\n                count = index + 1;\r\n            }\r\n\r\n            return index;\r\n        }\r\n\r\n        public bool TryGetValue(int index, out object obj)\r\n        {\r\n            if (index >= 0 && index < count && list[index].next == ALLOCED)\r\n            {\r\n                obj = list[index].obj;\r\n                return true;\r\n            }\r\n\r\n            obj = null;\r\n            return false;\r\n        }\r\n\r\n        public object Get(int index)\r\n        {\r\n            if (index >= 0 && index < count)\r\n            {\r\n                return list[index].obj;\r\n            }\r\n            return null;\r\n        }\r\n\r\n        public object Remove(int index)\r\n        {\r\n            if (index >= 0 && index < count && list[index].next == ALLOCED)\r\n            {\r\n                object o = list[index].obj;\r\n                list[index].obj = null;\r\n                list[index].next = freelist;\r\n                freelist = index;\r\n                return o;\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public object Replace(int index, object o)\r\n        {\r\n            if (index >= 0 && index < count)\r\n            {\r\n                object obj = list[index].obj;\r\n                list[index].obj = o;\r\n                return obj;\r\n            }\r\n\r\n            return null;\r\n        }\r\n\r\n        public int Check(int check_pos, int max_check, Func<object, bool> checker, Dictionary<object, int> reverse_map)\r\n        {\r\n            if (count == 0)\r\n            {\r\n                return 0;\r\n            }\r\n            for (int i = 0; i < Math.Min(max_check, count); ++i)\r\n            {\r\n                check_pos %= count;\r\n                if (list[check_pos].next == ALLOCED && !Object.ReferenceEquals(list[check_pos].obj, null))\r\n                {\r\n                    if (!checker(list[check_pos].obj))\r\n                    {\r\n                        object obj = Replace(check_pos, null);\r\n                        int obj_index;\r\n                        if (reverse_map.TryGetValue(obj, out obj_index) && obj_index == check_pos)\r\n                        {\r\n                            reverse_map.Remove(obj);\r\n                        }\r\n                    }\r\n                }\r\n                ++check_pos;\r\n            }\r\n\r\n            return check_pos %= count;\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Src/ObjectPool.cs.meta",
    "content": "fileFormatVersion: 2\nguid: acf2cec75841d9646900284e2ba1ca4f\ntimeCreated: 1480296949\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/ObjectTranslator.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\n\r\nnamespace XLua\r\n{\r\n    using System;\r\n    using System.Collections;\r\n    using System.Reflection;\r\n    using System.Collections.Generic;\r\n    using System.Diagnostics;\r\n    using System.Linq;\r\n\r\n    class ReferenceEqualsComparer : IEqualityComparer<object>\r\n    {\r\n        public new bool Equals(object o1, object o2)\r\n        {\r\n            return object.ReferenceEquals(o1, o2);\r\n        }\r\n        public int GetHashCode(object obj)\r\n        {\r\n            return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj);\r\n        }\r\n    }\r\n\r\n#pragma warning disable 414\r\n    public class MonoPInvokeCallbackAttribute : System.Attribute\r\n    {\r\n        private Type type;\r\n        public MonoPInvokeCallbackAttribute(Type t) { type = t; }\r\n    }\r\n#pragma warning restore 414\r\n\r\n    public enum LuaTypes\r\n    {\r\n        LUA_TNONE = -1,\r\n        LUA_TNIL = 0,\r\n        LUA_TNUMBER = 3,\r\n        LUA_TSTRING = 4,\r\n        LUA_TBOOLEAN = 1,\r\n        LUA_TTABLE = 5,\r\n        LUA_TFUNCTION = 6,\r\n        LUA_TUSERDATA = 7,\r\n        LUA_TTHREAD = 8,\r\n        LUA_TLIGHTUSERDATA = 2\r\n    }\r\n\r\n    public enum LuaGCOptions\r\n    {\r\n        LUA_GCSTOP = 0,\r\n        LUA_GCRESTART = 1,\r\n        LUA_GCCOLLECT = 2,\r\n        LUA_GCCOUNT = 3,\r\n        LUA_GCCOUNTB = 4,\r\n        LUA_GCSTEP = 5,\r\n        LUA_GCSETPAUSE = 6,\r\n        LUA_GCSETSTEPMUL = 7,\r\n    }\r\n\r\n    public enum LuaThreadStatus\r\n    {\r\n        LUA_RESUME_ERROR = -1,\r\n        LUA_OK = 0,\r\n        LUA_YIELD = 1,\r\n        LUA_ERRRUN = 2,\r\n        LUA_ERRSYNTAX = 3,\r\n        LUA_ERRMEM = 4,\r\n        LUA_ERRERR = 5,\r\n    }\r\n\r\n    sealed class LuaIndexes\r\n    {\r\n        public static int LUA_REGISTRYINDEX\r\n        {\r\n            get\r\n            {\r\n                return InternalGlobals.LUA_REGISTRYINDEX;\r\n            }\r\n            set\r\n            {\r\n                InternalGlobals.LUA_REGISTRYINDEX = value;\r\n            }\r\n        }\r\n    }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n    public delegate int CSharpWrapper(IntPtr L, int top);\r\n#endif\r\n\r\n    public partial class ObjectTranslator\r\n\t{\r\n        internal MethodWrapsCache methodWrapsCache;\r\n        internal ObjectCheckers objectCheckers;\r\n        internal ObjectCasters objectCasters;\r\n\r\n        internal readonly ObjectPool objects = new ObjectPool();\r\n        internal readonly Dictionary<object, int> reverseMap = new Dictionary<object, int>(new ReferenceEqualsComparer());\r\n\t\tinternal LuaEnv luaEnv;\r\n\t\tinternal StaticLuaCallbacks metaFunctions;\r\n\t\tinternal List<Assembly> assemblies;\r\n\t\tprivate LuaCSFunction importTypeFunction,loadAssemblyFunction, castFunction;\r\n        //延迟加载\r\n        private readonly Dictionary<Type, Action<RealStatePtr>> delayWrap = new Dictionary<Type, Action<RealStatePtr>>();\r\n\r\n        private readonly Dictionary<Type, Func<int, LuaEnv, LuaBase>> interfaceBridgeCreators = new Dictionary<Type, Func<int, LuaEnv, LuaBase>>();\r\n\r\n        //无法访问的类，比如声明成internal，可以用其接口、基类的生成代码来访问\r\n        private readonly Dictionary<Type, Type> aliasCfg = new Dictionary<Type, Type>();\r\n\r\n        public void DelayWrapLoader(Type type, Action<RealStatePtr> loader)\r\n        {\r\n            delayWrap[type] = loader;\r\n        }\r\n\r\n        public void AddInterfaceBridgeCreator(Type type, Func<int, LuaEnv, LuaBase> creator)\r\n        {\r\n            interfaceBridgeCreators.Add(type, creator);\r\n        }\r\n\r\n        Dictionary<Type, bool> loaded_types = new Dictionary<Type, bool>();\r\n        public bool TryDelayWrapLoader(RealStatePtr L, Type type)\r\n        {\r\n            if (loaded_types.ContainsKey(type)) return true;\r\n            loaded_types.Add(type, true);\r\n\r\n            LuaAPI.luaL_newmetatable(L, type.FullName); //先建一个metatable，因为加载过程可能会需要用到\r\n            LuaAPI.lua_pop(L, 1);\r\n\r\n            Action<RealStatePtr> loader;\r\n            int top = LuaAPI.lua_gettop(L);\r\n            if (delayWrap.TryGetValue(type, out loader))\r\n            {\r\n                delayWrap.Remove(type);\r\n                loader(L);\r\n            }\r\n            else\r\n            {\r\n#if !GEN_CODE_MINIMIZE && !ENABLE_IL2CPP && (UNITY_EDITOR || XLUA_GENERAL) && !FORCE_REFLECTION && !NET_STANDARD_2_0\r\n                if (!DelegateBridge.Gen_Flag && !type.IsEnum() && !typeof(Delegate).IsAssignableFrom(type) && Utils.IsPublic(type))\r\n                {\r\n                    Type wrap = ce.EmitTypeWrap(type);\r\n                    MethodInfo method = wrap.GetMethod(\"__Register\", BindingFlags.Static | BindingFlags.Public);\r\n                    method.Invoke(null, new object[] { L });\r\n                }\r\n                else\r\n                {\r\n                    Utils.ReflectionWrap(L, type, privateAccessibleFlags.Contains(type));\r\n                }\r\n#else\r\n                Utils.ReflectionWrap(L, type, privateAccessibleFlags.Contains(type));\r\n#endif\r\n#if NOT_GEN_WARNING\r\n                if (!typeof(Delegate).IsAssignableFrom(type))\r\n                {\r\n#if !XLUA_GENERAL\r\n                    UnityEngine.Debug.LogWarning(string.Format(\"{0} not gen, using reflection instead\", type));\r\n#else\r\n                    System.Console.WriteLine(string.Format(\"Warning: {0} not gen, using reflection instead\", type));\r\n#endif\r\n                }\r\n#endif\r\n            }\r\n            if (top != LuaAPI.lua_gettop(L))\r\n            {\r\n                throw new Exception(\"top change, before:\" + top + \", after:\" + LuaAPI.lua_gettop(L));\r\n            }\r\n\r\n            foreach (var nested_type in type.GetNestedTypes(BindingFlags.Public))\r\n            {\r\n                if (nested_type.IsGenericTypeDefinition())\r\n                {\r\n                    continue;\r\n                }\r\n                GetTypeId(L, nested_type);\r\n            }\r\n            \r\n            return true;\r\n        }\r\n        \r\n        public void Alias(Type type, string alias)\r\n        {\r\n            Type alias_type = FindType(alias);\r\n            if (alias_type == null)\r\n            {\r\n                throw new ArgumentException(\"Can not find \" + alias);\r\n            }\r\n            aliasCfg[alias_type] = type;\r\n        }\r\n\r\n        public int cacheRef;\r\n\r\n        void addAssemblieByName(IEnumerable<Assembly> assemblies_usorted, string name)\r\n        {\r\n            foreach(var assemblie in assemblies_usorted)\r\n            {\r\n                if (assemblie.FullName.StartsWith(name) && !assemblies.Contains(assemblie))\r\n                {\r\n                    assemblies.Add(assemblie);\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n\r\n        public ObjectTranslator(LuaEnv luaenv,RealStatePtr L)\r\n\t\t{\r\n#if XLUA_GENERAL  || (UNITY_WSA && !UNITY_EDITOR)\r\n            var dumb_field = typeof(ObjectTranslator).GetField(\"s_gen_reg_dumb_obj\", BindingFlags.Static| BindingFlags.DeclaredOnly | BindingFlags.NonPublic);\r\n            if (dumb_field != null)\r\n            {\r\n                dumb_field.GetValue(null);\r\n            }\r\n#endif\r\n            assemblies = new List<Assembly>();\r\n\r\n#if (UNITY_WSA && !ENABLE_IL2CPP) && !UNITY_EDITOR\r\n            var assemblies_usorted = Utils.GetAssemblies();\r\n#else\r\n            assemblies.Add(Assembly.GetExecutingAssembly());\r\n            var assemblies_usorted = AppDomain.CurrentDomain.GetAssemblies();\r\n#endif\r\n            addAssemblieByName(assemblies_usorted, \"mscorlib,\");\r\n            addAssemblieByName(assemblies_usorted, \"System,\");\r\n            addAssemblieByName(assemblies_usorted, \"System.Core,\");\r\n            foreach (Assembly assembly in assemblies_usorted)\r\n            {\r\n                if (!assemblies.Contains(assembly))\r\n                {\r\n                    assemblies.Add(assembly);\r\n                }\r\n            }\r\n\r\n            this.luaEnv=luaenv;\r\n            objectCasters = new ObjectCasters(this);\r\n            objectCheckers = new ObjectCheckers(this);\r\n            methodWrapsCache = new MethodWrapsCache(this, objectCheckers, objectCasters);\r\n\t\t\tmetaFunctions=new StaticLuaCallbacks();\r\n\r\n            importTypeFunction = new LuaCSFunction(StaticLuaCallbacks.ImportType);\r\n            loadAssemblyFunction = new LuaCSFunction(StaticLuaCallbacks.LoadAssembly);\r\n            castFunction = new LuaCSFunction(StaticLuaCallbacks.Cast);\r\n\r\n            LuaAPI.lua_newtable(L);\r\n            LuaAPI.lua_newtable(L);\r\n            LuaAPI.xlua_pushasciistring(L, \"__mode\");\r\n            LuaAPI.xlua_pushasciistring(L, \"v\");\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.lua_setmetatable(L, -2);\r\n            cacheRef = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n            initCSharpCallLua();\r\n        }\r\n\r\n        internal enum LOGLEVEL{\r\n            NO,\r\n            INFO,\r\n            WARN,\r\n            ERROR\r\n        }\r\n\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n        Type delegate_birdge_type;\r\n\r\n        class CompareByArgRet : IEqualityComparer<MethodInfo>\r\n        {\r\n            public bool Equals(MethodInfo x, MethodInfo y)\r\n            {\r\n                return Utils.IsParamsMatch(x, y);\r\n            }\r\n            public int GetHashCode(MethodInfo method)\r\n            {\r\n                int hc = 0;\r\n                hc += method.ReturnType.GetHashCode();\r\n                foreach (var pi in method.GetParameters())\r\n                {\r\n                    hc += pi.ParameterType.GetHashCode();\r\n                }\r\n                return hc;\r\n            }\r\n        }\r\n#endif\r\n\r\n        void initCSharpCallLua()\r\n        {\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n            delegate_birdge_type = typeof(DelegateBridge);\r\n            if (!DelegateBridge.Gen_Flag)\r\n            {\r\n                List<Type> cs_call_lua = new List<Type>();\r\n                foreach (var type in Utils.GetAllTypes())\r\n                {\r\n                    if(type.IsDefined(typeof(CSharpCallLuaAttribute), false))\r\n                    {\r\n                        cs_call_lua.Add(type);\r\n                    }\r\n\r\n                    if (!type.IsAbstract || !type.IsSealed) continue;\r\n\r\n                    var fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                    for (int i = 0; i < fields.Length; i++)\r\n                    {\r\n                        var field = fields[i];\r\n                        if (field.IsDefined(typeof(CSharpCallLuaAttribute), false) && (typeof(IEnumerable<Type>)).IsAssignableFrom(field.FieldType))\r\n                        {\r\n                            cs_call_lua.AddRange(field.GetValue(null) as IEnumerable<Type>);\r\n                        }\r\n                    }\r\n\r\n                    var props = type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n                    for (int i = 0; i < props.Length; i++)\r\n                    {\r\n                        var prop = props[i];\r\n                        if (prop.IsDefined(typeof(CSharpCallLuaAttribute), false) && (typeof(IEnumerable<Type>)).IsAssignableFrom(prop.PropertyType))\r\n                        {\r\n                            cs_call_lua.AddRange(prop.GetValue(null, null) as IEnumerable<Type>);\r\n                        }\r\n                    }\r\n                }\r\n                IEnumerable<IGrouping<MethodInfo, Type>> groups = (from type in cs_call_lua\r\n                              where typeof(Delegate).IsAssignableFrom(type) && type != typeof(Delegate) && type != typeof(MulticastDelegate)\r\n                              where !type.GetMethod(\"Invoke\").GetParameters().Any(paramInfo => paramInfo.ParameterType.IsGenericParameter)\r\n                               select type).GroupBy(t => t.GetMethod(\"Invoke\"), new CompareByArgRet());\r\n\r\n                ce.SetGenInterfaces(cs_call_lua.Where(type=>type.IsInterface()).ToList());\r\n                delegate_birdge_type = ce.EmitDelegateImpl(groups);\r\n            }\r\n#endif\r\n        }\r\n\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n        CodeEmit ce = new CodeEmit();\r\n#endif\r\n        MethodInfo[] genericAction = null;\r\n        MethodInfo[] genericFunc = null;\r\n        Dictionary<Type, Func<DelegateBridgeBase, Delegate>> delegateCreatorCache\r\n            = new Dictionary<Type, Func<DelegateBridgeBase, Delegate>>();\r\n\r\n        Func<DelegateBridgeBase, Delegate> getCreatorUsingGeneric(DelegateBridgeBase bridge, Type delegateType, MethodInfo delegateMethod)\r\n        {\r\n            Func<DelegateBridgeBase, Delegate> genericDelegateCreator = null;\r\n\r\n            if (genericAction == null)\r\n            {\r\n                var methods = typeof(DelegateBridge).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);\r\n                genericAction = methods.Where(m => m.Name == \"Action\").OrderBy(m => m.GetParameters().Length).ToArray();\r\n                genericFunc = methods.Where(m => m.Name == \"Func\").OrderBy(m => m.GetParameters().Length).ToArray();\r\n            }\r\n            if (genericAction.Length != 5 || genericFunc.Length != 5)\r\n            {\r\n                return null;\r\n            }\r\n            var parameters = delegateMethod.GetParameters();\r\n#if !XLUA_GENERAL\r\n            if ((delegateMethod.ReturnType.IsValueType() && delegateMethod.ReturnType != typeof(void)) || parameters.Length > 4)\r\n            {\r\n                genericDelegateCreator = (x) => null;\r\n            }\r\n            else\r\n#endif\r\n            {\r\n                foreach (var pinfo in parameters)\r\n                {\r\n                    if (pinfo.ParameterType.IsValueType() || pinfo.IsOut || pinfo.ParameterType.IsByRef)\r\n                    {\r\n                        genericDelegateCreator = (x) => null;\r\n                        break;\r\n                    }\r\n                }\r\n                if (genericDelegateCreator == null)\r\n                {\r\n                    var typeArgs = parameters.Select(pinfo => pinfo.ParameterType);\r\n                    MethodInfo genericMethodInfo = null;\r\n                    if (delegateMethod.ReturnType == typeof(void))\r\n                    {\r\n                        genericMethodInfo = genericAction[parameters.Length];\r\n                    }\r\n                    else\r\n                    {\r\n                        genericMethodInfo = genericFunc[parameters.Length];\r\n                        typeArgs = typeArgs.Concat(new Type[] { delegateMethod.ReturnType });\r\n                    }\r\n                    if (genericMethodInfo.IsGenericMethodDefinition)\r\n                    {\r\n                        var methodInfo = genericMethodInfo.MakeGenericMethod(typeArgs.ToArray());\r\n                        genericDelegateCreator = (o) =>\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n                            Delegate.CreateDelegate(delegateType, o, methodInfo);\r\n#else\r\n                            methodInfo.CreateDelegate(delegateType, bridge); \r\n#endif\r\n                    }\r\n                    else\r\n                    {\r\n                        genericDelegateCreator = (o) =>\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n                            Delegate.CreateDelegate(delegateType, o, genericMethodInfo);\r\n#else\r\n                            genericMethodInfo.CreateDelegate(delegateType, o);\r\n#endif\r\n                    }\r\n                }\r\n            }\r\n\r\n            return genericDelegateCreator;\r\n        }\r\n\r\n        Delegate getDelegate(DelegateBridgeBase bridge, Type delegateType)\r\n        {\r\n            Delegate ret = bridge.GetDelegateByType(delegateType);\r\n\r\n            if (ret != null)\r\n            {\r\n                return ret;\r\n            }\r\n\r\n            if (delegateType == typeof(Delegate) || delegateType == typeof(MulticastDelegate))\r\n            {\r\n                return null;\r\n            }\r\n\r\n            Func<DelegateBridgeBase, Delegate> delegateCreator;\r\n            if (!delegateCreatorCache.TryGetValue(delegateType, out delegateCreator))\r\n            {\r\n                // get by parameters\r\n                MethodInfo delegateMethod = delegateType.GetMethod(\"Invoke\");\r\n                var methods = bridge.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => !m.IsGenericMethodDefinition && (m.Name.StartsWith(\"__Gen_Delegate_Imp\") || m.Name == \"Action\")).ToArray();\r\n                for (int i = 0; i < methods.Length; i++)\r\n                {\r\n                    if (!methods[i].IsConstructor && Utils.IsParamsMatch(delegateMethod, methods[i]))\r\n                    {\r\n                        var foundMethod = methods[i];\r\n                        delegateCreator = (o) =>\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n                            Delegate.CreateDelegate(delegateType, o, foundMethod);\r\n#else\r\n                            foundMethod.CreateDelegate(delegateType, o); \r\n#endif\r\n                        break;\r\n                    }\r\n                }\r\n\r\n                if (delegateCreator == null)\r\n                {\r\n                    delegateCreator = getCreatorUsingGeneric(bridge, delegateType, delegateMethod);\r\n                }\r\n                delegateCreatorCache.Add(delegateType, delegateCreator);\r\n            }\r\n\r\n            ret = delegateCreator(bridge);\r\n            if (ret != null)\r\n            {\r\n                return ret;\r\n            }\r\n\r\n            throw new InvalidCastException(\"This type must add to CSharpCallLua: \" + delegateType.GetFriendlyName());\r\n        }\r\n        Dictionary<int, WeakReference> delegate_bridges = new Dictionary<int, WeakReference>();\r\n        public object CreateDelegateBridge(RealStatePtr L, Type delegateType, int idx)\r\n        {\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            if (!LuaAPI.lua_isnil(L, -1))\r\n            {\r\n                int referenced = LuaAPI.xlua_tointeger(L, -1);\r\n                LuaAPI.lua_pop(L, 1);\r\n\r\n                if (delegate_bridges[referenced].IsAlive)\r\n                {\r\n                    if (delegateType == null)\r\n                    {\r\n                        return delegate_bridges[referenced].Target;\r\n                    }\r\n                    DelegateBridgeBase exist_bridge = delegate_bridges[referenced].Target as DelegateBridgeBase;\r\n                    Delegate exist_delegate;\r\n                    if (exist_bridge.TryGetDelegate(delegateType, out exist_delegate))\r\n                    {\r\n                        return exist_delegate;\r\n                    }\r\n                    else\r\n                    {\r\n                        exist_delegate = getDelegate(exist_bridge, delegateType);\r\n                        exist_bridge.AddDelegate(delegateType, exist_delegate);\r\n                        return exist_delegate;\r\n                    }\r\n                }\r\n            }\r\n            else\r\n            {\r\n                LuaAPI.lua_pop(L, 1);\r\n            }\r\n\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            int reference = LuaAPI.luaL_ref(L);\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            LuaAPI.lua_pushnumber(L, reference);\r\n            LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            DelegateBridgeBase bridge;\r\n            try\r\n            {\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n                if (!DelegateBridge.Gen_Flag)\r\n                {\r\n                    bridge = Activator.CreateInstance(delegate_birdge_type, new object[] { reference, luaEnv }) as DelegateBridgeBase;\r\n                }\r\n                else\r\n#endif\r\n                {\r\n                    bridge = new DelegateBridge(reference, luaEnv);\r\n                }\r\n            }\r\n            catch(Exception e)\r\n            {\r\n                LuaAPI.lua_pushvalue(L, idx);\r\n                LuaAPI.lua_pushnil(L);\r\n                LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n                LuaAPI.lua_pushnil(L);\r\n                LuaAPI.xlua_rawseti(L, LuaIndexes.LUA_REGISTRYINDEX, reference);\r\n                throw e;\r\n            }\r\n            if (delegateType == null)\r\n            {\r\n                delegate_bridges[reference] = new WeakReference(bridge);\r\n                return bridge;\r\n            }\r\n            try {\r\n                var ret = getDelegate(bridge, delegateType);\r\n                bridge.AddDelegate(delegateType, ret);\r\n                delegate_bridges[reference] = new WeakReference(bridge);\r\n                return ret;\r\n            }\r\n            catch(Exception e)\r\n            {\r\n                bridge.Dispose();\r\n                throw e;\r\n            }\r\n        }\r\n\r\n        public bool AllDelegateBridgeReleased()\r\n        {\r\n            foreach (var kv in delegate_bridges)\r\n            {\r\n                if (kv.Value.IsAlive)\r\n                {\r\n                    return false;\r\n                }\r\n            }\r\n            return true;\r\n        }\r\n\r\n        public void ReleaseLuaBase(RealStatePtr L, int reference, bool is_delegate)\r\n        {\r\n            if(is_delegate)\r\n            {\r\n                LuaAPI.xlua_rawgeti(L, LuaIndexes.LUA_REGISTRYINDEX, reference);\r\n                if (LuaAPI.lua_isnil(L, -1))\r\n                {\r\n                    LuaAPI.lua_pop(L, 1);\r\n                }\r\n                else\r\n                {\r\n                    LuaAPI.lua_pushvalue(L, -1);\r\n                    LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n                    if (LuaAPI.lua_type(L, -1) == LuaTypes.LUA_TNUMBER && LuaAPI.xlua_tointeger(L, -1) == reference) //\r\n                    {\r\n                        //UnityEngine.Debug.LogWarning(\"release delegate ref = \" + luaReference);\r\n                        LuaAPI.lua_pop(L, 1);// pop LUA_REGISTRYINDEX[func]\r\n                        LuaAPI.lua_pushnil(L);\r\n                        LuaAPI.lua_rawset(L, LuaIndexes.LUA_REGISTRYINDEX); // LUA_REGISTRYINDEX[func] = nil\r\n                    }\r\n                    else //another Delegate ref the function before the GC tick\r\n                    {\r\n                        LuaAPI.lua_pop(L, 2); // pop LUA_REGISTRYINDEX[func] & func\r\n                    }\r\n                }\r\n\r\n                LuaAPI.lua_unref(L, reference);\r\n                delegate_bridges.Remove(reference);\r\n            }\r\n            else\r\n            {\r\n                LuaAPI.lua_unref(L, reference);\r\n            }\r\n        }\r\n\r\n\t\tpublic object CreateInterfaceBridge(RealStatePtr L, Type interfaceType, int idx)\r\n        {\r\n            Func<int, LuaEnv, LuaBase> creator;\r\n\r\n            if (!interfaceBridgeCreators.TryGetValue(interfaceType, out creator))\r\n            {\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n                var bridgeType = ce.EmitInterfaceImpl(interfaceType);\r\n                creator = (int reference, LuaEnv luaenv) =>\r\n                {\r\n                    return Activator.CreateInstance(bridgeType, new object[] { reference, luaEnv }) as LuaBase;\r\n                };\r\n                interfaceBridgeCreators.Add(interfaceType, creator);\r\n#else\r\n                throw new InvalidCastException(\"This type must add to CSharpCallLua: \" + interfaceType);\r\n#endif\r\n            }\r\n            LuaAPI.lua_pushvalue(L, idx);\r\n            return creator(LuaAPI.luaL_ref(L), luaEnv);\r\n        }\r\n\r\n        int common_array_meta = -1;\r\n        public void CreateArrayMetatable(RealStatePtr L)\r\n        {\r\n            Utils.BeginObjectRegister(null, L, this, 0, 0, 1, 0, common_array_meta);\r\n            Utils.RegisterFunc(L, Utils.GETTER_IDX, \"Length\", StaticLuaCallbacks.ArrayLength);\r\n            Utils.EndObjectRegister(null, L, this, null, null,\r\n                 typeof(System.Array), StaticLuaCallbacks.ArrayIndexer, StaticLuaCallbacks.ArrayNewIndexer);\r\n        }\r\n\r\n        int common_delegate_meta = -1;\r\n        public void CreateDelegateMetatable(RealStatePtr L)\r\n        {\r\n            Utils.BeginObjectRegister(null, L, this, 3, 0, 0, 0, common_delegate_meta);\r\n            Utils.RegisterFunc(L, Utils.OBJ_META_IDX, \"__call\", StaticLuaCallbacks.DelegateCall);\r\n            Utils.RegisterFunc(L, Utils.OBJ_META_IDX, \"__add\", StaticLuaCallbacks.DelegateCombine);\r\n            Utils.RegisterFunc(L, Utils.OBJ_META_IDX, \"__sub\", StaticLuaCallbacks.DelegateRemove);\r\n            Utils.EndObjectRegister(null, L, this, null, null,\r\n                 typeof(System.MulticastDelegate), null, null);\r\n        }\r\n\r\n        int enumerable_pairs_func = -1;\r\n\r\n        internal void CreateEnumerablePairs(RealStatePtr L)\r\n        {\r\n            LuaFunction func = luaEnv.DoString(@\"\r\n                return function(obj)\r\n                    local isKeyValuePair\r\n                    local function lua_iter(cs_iter, k)\r\n                        if cs_iter:MoveNext() then\r\n                            local current = cs_iter.Current\r\n                            if isKeyValuePair == nil then\r\n                                if type(current) == 'userdata' then\r\n                                    local t = current:GetType()\r\n                                    isKeyValuePair = t.Name == 'KeyValuePair`2' and t.Namespace == 'System.Collections.Generic'\r\n                                 else\r\n                                    isKeyValuePair = false\r\n                                 end\r\n                                 --print(current, isKeyValuePair)\r\n                            end\r\n                            if isKeyValuePair then\r\n                                return current.Key, current.Value\r\n                            else\r\n                                return k + 1, current\r\n                            end\r\n                        end\r\n                    end\r\n                    return lua_iter, obj:GetEnumerator(), -1\r\n                end\r\n            \")[0] as LuaFunction;\r\n            func.push(L);\r\n            enumerable_pairs_func = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            func.Dispose();\r\n        }\r\n\r\n        public void OpenLib(RealStatePtr L)\r\n\t\t{\r\n            if (0 != LuaAPI.xlua_getglobal(L, \"xlua\"))\r\n            {\r\n                throw new Exception(\"call xlua_getglobal fail!\" + LuaAPI.lua_tostring(L, -1));\r\n            }\r\n            LuaAPI.xlua_pushasciistring(L, \"import_type\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L,importTypeFunction);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"import_generic_type\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.ImportGenericType);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"cast\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, castFunction);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"load_assembly\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L,loadAssemblyFunction);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"access\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.XLuaAccess);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"private_accessible\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.XLuaPrivateAccessible);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"metatable_operation\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.XLuaMetatableOperation);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"tofunction\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.ToFunction);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"get_generic_method\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.GetGenericMethod);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"release\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.ReleaseCsObject);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.lua_pop(L, 1);\r\n\r\n            LuaAPI.lua_createtable(L, 1, 4); // 4 for __gc, __tostring, __index, __newindex\r\n            common_array_meta = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            LuaAPI.lua_createtable(L, 1, 4); // 4 for __gc, __tostring, __index, __newindex\r\n            common_delegate_meta = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n        }\r\n\t\t\r\n\t\tinternal void createFunctionMetatable(RealStatePtr L)\r\n\t\t{\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L,\"__gc\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L,metaFunctions.GcMeta);\r\n\t\t\tLuaAPI.lua_rawset(L,-3);\r\n            LuaAPI.lua_pushlightuserdata(L, LuaAPI.xlua_tag());\r\n            LuaAPI.lua_pushnumber(L, 1);\r\n            LuaAPI.lua_rawset(L, -3);\r\n\r\n            LuaAPI.lua_pushvalue(L, -1);\r\n            int type_id = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            LuaAPI.lua_pushnumber(L, type_id);\r\n            LuaAPI.xlua_rawseti(L, -2, 1);\r\n            LuaAPI.lua_pop(L, 1);\r\n\r\n            typeIdMap.Add(typeof(LuaCSFunction), type_id);\r\n        }\r\n\t\t\r\n\t\tinternal Type FindType(string className, bool isQualifiedName = false)\r\n\t\t{\r\n            foreach (Assembly assembly in assemblies)\r\n\t\t\t{\r\n                Type klass = assembly.GetType(className);\r\n\r\n                if (klass!=null)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn klass;\r\n\t\t\t\t}\r\n\t\t\t}\r\n            int p1 = className.IndexOf('[');\r\n            if (p1 > 0 && !isQualifiedName)\r\n            {\r\n                string qualified_name = className.Substring(0, p1 + 1);\r\n                string[] generic_params = className.Substring(p1 + 1, className.Length - qualified_name.Length - 1).Split(',');\r\n                for(int i = 0; i < generic_params.Length; i++)\r\n                {\r\n                    Type generic_param = FindType(generic_params[i].Trim());\r\n                    if (generic_param == null)\r\n                    {\r\n                        return null;\r\n                    }\r\n                    if (i != 0 )\r\n                    {\r\n                        qualified_name += \", \";\r\n                    }\r\n                    qualified_name = qualified_name + \"[\" + generic_param.AssemblyQualifiedName + \"]\";\r\n                }\r\n                qualified_name += \"]\";\r\n                return FindType(qualified_name, true);\r\n            }\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n        bool hasMethod(Type type, string methodName)\r\n        {\r\n            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))\r\n            {\r\n                if (method.Name == methodName)\r\n                {\r\n                    return true;\r\n                }\r\n            }\r\n            return false;\r\n        }\r\n\t\t\r\n\t\tinternal void collectObject(int obj_index_to_collect)\r\n\t\t{\r\n\t\t\tobject o;\r\n\t\t\t\r\n\t\t\tif (objects.TryGetValue(obj_index_to_collect, out o))\r\n\t\t\t{\r\n\t\t\t\tobjects.Remove(obj_index_to_collect);\r\n                \r\n                if (o != null)\r\n                {\r\n                    int obj_index;\r\n                    //lua gc是先把weak table移除后再调用__gc，这期间同一个对象可能再次push到lua，关联到新的index\r\n                    bool is_enum = o.GetType().IsEnum();\r\n                    if ((is_enum ? enumMap.TryGetValue(o, out obj_index) : reverseMap.TryGetValue(o, out obj_index))\r\n                        && obj_index == obj_index_to_collect)\r\n                    {\r\n                        if (is_enum)\r\n                        {\r\n                            enumMap.Remove(o);\r\n                        }\r\n                        else\r\n                        {\r\n                            reverseMap.Remove(o);\r\n                        }\r\n                    }\r\n                }\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tint addObject(object obj, bool is_valuetype, bool is_enum)\r\n\t\t{\r\n            int index = objects.Add(obj);\r\n            if (is_enum)\r\n            {\r\n                enumMap[obj] = index;\r\n            }\r\n            else if (!is_valuetype)\r\n            {\r\n                reverseMap[obj] = index;\r\n            }\r\n\t\t\t\r\n\t\t\treturn index;\r\n\t\t}\r\n\t\t\r\n\t\tinternal object GetObject(RealStatePtr L,int index)\r\n\t\t{\r\n            return (objectCasters.GetCaster(typeof(object))(L, index, null));\r\n        }\r\n\r\n        public Type GetTypeOf(RealStatePtr L, int idx)\r\n        {\r\n            Type type = null;\r\n            int type_id = LuaAPI.xlua_gettypeid(L, idx);\r\n            if (type_id != -1)\r\n            {\r\n                typeMap.TryGetValue(type_id, out type);\r\n            }\r\n            return type;\r\n        }\r\n\r\n        public bool Assignable<T>(RealStatePtr L, int index)\r\n\t\t{\r\n            return Assignable(L, index, typeof(T));\r\n        }\r\n\r\n        public bool Assignable(RealStatePtr L, int index, Type type)\r\n        {\r\n            if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA) // 快路径\r\n            {\r\n                int udata = LuaAPI.xlua_tocsobj_safe(L, index);\r\n                object obj;\r\n                if (udata != -1 && objects.TryGetValue(udata, out obj))\r\n                {\r\n                    RawObject rawObject = obj as RawObject;\r\n                    if (rawObject != null)\r\n                    {\r\n                        obj = rawObject.Target;\r\n                    }\r\n                    if (obj == null)\r\n                    {\r\n                        return !type.IsValueType();\r\n                    }\r\n                    return type.IsAssignableFrom(obj.GetType());\r\n                }\r\n\r\n                int type_id = LuaAPI.xlua_gettypeid(L, index);\r\n                Type type_of_struct;\r\n                if (type_id != -1 && typeMap.TryGetValue(type_id, out type_of_struct)) // is struct\r\n                {\r\n                    return type.IsAssignableFrom(type_of_struct);\r\n                }\r\n            }\r\n\r\n            return objectCheckers.GetChecker(type)(L, index);\r\n        }\r\n\r\n        public object GetObject(RealStatePtr L, int index, Type type)\r\n        {\r\n            int udata = LuaAPI.xlua_tocsobj_safe(L, index);\r\n\r\n            if (udata != -1)\r\n            {\r\n                object obj = objects.Get(udata);\r\n                RawObject rawObject = obj as RawObject;\r\n                return rawObject == null ? obj : rawObject.Target;\r\n            }\r\n            else\r\n            {\r\n                if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)\r\n                {\r\n                    GetCSObject get;\r\n                    int type_id = LuaAPI.xlua_gettypeid(L, index);\r\n                    if (type_id != -1 && type_id == decimal_type_id)\r\n                    {\r\n                        decimal d;\r\n                        Get(L, index, out d);\r\n                        return d;\r\n                    }\r\n                    Type type_of_struct;\r\n                    if (type_id != -1 && typeMap.TryGetValue(type_id, out type_of_struct) && type.IsAssignableFrom(type_of_struct) && custom_get_funcs.TryGetValue(type, out get))\r\n                    {\r\n                        return get(L, index);\r\n                    }\r\n                }\r\n                return (objectCasters.GetCaster(type)(L, index, null));\r\n            }\r\n        }\r\n\r\n        public void Get<T>(RealStatePtr L, int index, out T v)\r\n        {\r\n            Func<RealStatePtr, int, T> get_func;\r\n            if (tryGetGetFuncByType(typeof(T), out get_func))\r\n            {\r\n                v = get_func(L, index);\r\n            }\r\n            else\r\n            {\r\n                v = (T)GetObject(L, index, typeof(T));\r\n            }\r\n        }\r\n\r\n        public void PushByType<T>(RealStatePtr L,  T v)\r\n        {\r\n            Action<RealStatePtr, T> push_func;\r\n            if (tryGetPushFuncByType(typeof(T), out push_func))\r\n            {\r\n                push_func(L, v);\r\n            }\r\n            else\r\n            {\r\n                PushAny(L, v);\r\n            }\r\n        }\r\n\r\n#if GENERIC_SHARING\r\n        public T GetByType<T>(RealStatePtr L, int index)\r\n        {\r\n            Func<RealStatePtr, int, T> get_func;\r\n            if (tryGetGetFuncByType(typeof(T), out get_func))\r\n            {\r\n                return get_func(L, index);\r\n            }\r\n            else\r\n            {\r\n                return (T)GetObject(L, index, typeof(T));\r\n            }\r\n        }\r\n#endif\r\n\r\n        public T[] GetParams<T>(RealStatePtr L, int index)\r\n        {\r\n            T[] ret = new T[Math.Max(LuaAPI.lua_gettop(L) - index + 1, 0)];\r\n            for(int i = 0; i < ret.Length; i++)\r\n            {\r\n                Get(L, index + i, out ret[i]);\r\n            }\r\n            return ret;\r\n        }\r\n\r\n        public Array GetParams(RealStatePtr L, int index, Type type) //反射版本\r\n        {\r\n            Array ret = Array.CreateInstance(type, Math.Max(LuaAPI.lua_gettop(L) - index + 1, 0)); //这个函数，长度为0的话，返回null\r\n            for (int i = 0; i < ret.Length; i++)\r\n            {\r\n                ret.SetValue(GetObject(L, index + i, type), i); \r\n            }\r\n            return ret;\r\n        }\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n        public void PushParams(RealStatePtr L, Array ary)\r\n        {\r\n            if (ary != null)\r\n            {\r\n                for (int i = 0; i < ary.Length; i++)\r\n                {\r\n                    PushAny(L, ary.GetValue(i));\r\n                }\r\n            }\r\n        }\r\n#endif\r\n\r\n        public T GetDelegate<T>(RealStatePtr L, int index) where T :class\r\n        {\r\n            \r\n            if (LuaAPI.lua_isfunction(L, index))\r\n            {\r\n                return CreateDelegateBridge(L, typeof(T), index) as T;\r\n            }\r\n            else if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)\r\n            {\r\n                return (T)SafeGetCSObj(L, index);\r\n            }\r\n            else\r\n            {\r\n                return null;\r\n            }\r\n        }\r\n\r\n        Dictionary<Type, int> typeIdMap = new Dictionary<Type, int>();\r\n\r\n        //only store the type id to type map for struct\r\n        Dictionary<int, Type> typeMap = new Dictionary<int, Type>();\r\n\r\n        public int GetTypeId(RealStatePtr L, Type type)\r\n        {\r\n            bool isFirst;\r\n            return getTypeId(L, type, out isFirst);\r\n        }\r\n\r\n        HashSet<Type> privateAccessibleFlags = new HashSet<Type>();\r\n\r\n        public void PrivateAccessible(RealStatePtr L, Type type)\r\n        {\r\n            if (!privateAccessibleFlags.Contains(type)) //未处理\r\n            {\r\n                privateAccessibleFlags.Add(type);\r\n                if (typeIdMap.ContainsKey(type)) //loaded\r\n                {\r\n                    Utils.MakePrivateAccessible(L, type);\r\n                }\r\n            }\r\n        }\r\n\r\n        internal int getTypeId(RealStatePtr L, Type type, out bool is_first, LOGLEVEL log_level = LOGLEVEL.WARN)\r\n        {\r\n            int type_id;\r\n            is_first = false;\r\n            if (!typeIdMap.TryGetValue(type, out type_id)) // no reference\r\n            {\r\n                if (type.IsArray)\r\n                {\r\n                    if (common_array_meta == -1) throw new Exception(\"Fatal Exception! Array Metatable not inited!\");\r\n                    return common_array_meta;\r\n                }\r\n                if (typeof(MulticastDelegate).IsAssignableFrom(type))\r\n                {\r\n                    if (common_delegate_meta == -1) throw new Exception(\"Fatal Exception! Delegate Metatable not inited!\");\r\n                    TryDelayWrapLoader(L, type);\r\n                    return common_delegate_meta;\r\n                }\r\n\r\n                is_first = true;\r\n                Type alias_type = null;\r\n                aliasCfg.TryGetValue(type, out alias_type);\r\n                LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName);\r\n\r\n                if (LuaAPI.lua_isnil(L, -1)) //no meta yet, try to use reflection meta\r\n                {\r\n                    LuaAPI.lua_pop(L, 1);\r\n\r\n                    if (TryDelayWrapLoader(L, alias_type == null ? type : alias_type))\r\n                    {\r\n                        LuaAPI.luaL_getmetatable(L, alias_type == null ? type.FullName : alias_type.FullName);\r\n                    }\r\n                    else\r\n                    {\r\n                        throw new Exception(\"Fatal: can not load metatable of type:\" + type);\r\n                    }\r\n                }\r\n\r\n                //循环依赖，自身依赖自己的class，比如有个自身类型的静态readonly对象。\r\n                if (typeIdMap.TryGetValue(type, out type_id))\r\n                {\r\n                    LuaAPI.lua_pop(L, 1);\r\n                }\r\n                else\r\n                {\r\n                    if (type.IsEnum())\r\n                    {\r\n                        LuaAPI.xlua_pushasciistring(L, \"__band\");\r\n                        LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.EnumAndMeta);\r\n                        LuaAPI.lua_rawset(L, -3);\r\n                        LuaAPI.xlua_pushasciistring(L, \"__bor\");\r\n                        LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.EnumOrMeta);\r\n                        LuaAPI.lua_rawset(L, -3);\r\n                    }\r\n                    if (typeof(IEnumerable).IsAssignableFrom(type))\r\n                    {\r\n                        LuaAPI.xlua_pushasciistring(L, \"__pairs\");\r\n                        LuaAPI.lua_getref(L, enumerable_pairs_func);\r\n                        LuaAPI.lua_rawset(L, -3);\r\n                    }\r\n                    LuaAPI.lua_pushvalue(L, -1);\r\n                    type_id = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n                    LuaAPI.lua_pushnumber(L, type_id);\r\n                    LuaAPI.xlua_rawseti(L, -2, 1);\r\n                    LuaAPI.lua_pop(L, 1);\r\n\r\n                    if (type.IsValueType())\r\n                    {\r\n                        typeMap.Add(type_id, type);\r\n                    }\r\n\r\n                    typeIdMap.Add(type, type_id);\r\n                }\r\n            }\r\n            return type_id;\r\n        }\r\n\r\n        void pushPrimitive(RealStatePtr L, object o)\r\n        {\r\n            if (o is sbyte || o is byte || o is short || o is ushort ||\r\n                    o is int)\r\n            {\r\n                int i = Convert.ToInt32(o);\r\n                LuaAPI.xlua_pushinteger(L, i);\r\n            }\r\n            else if (o is uint)\r\n            {\r\n                LuaAPI.xlua_pushuint(L, (uint)o);\r\n            }\r\n            else if (o is float || o is double)\r\n            {\r\n                double d = Convert.ToDouble(o);\r\n                LuaAPI.lua_pushnumber(L, d);\r\n            }\r\n            else if (o is IntPtr)\r\n            {\r\n                LuaAPI.lua_pushlightuserdata(L, (IntPtr)o);\r\n            }\r\n            else if (o is char)\r\n            {\r\n                LuaAPI.xlua_pushinteger(L, (char)o);\r\n            }\r\n            else if (o is long)\r\n            {\r\n                LuaAPI.lua_pushint64(L, Convert.ToInt64(o));\r\n            }\r\n            else if (o is ulong)\r\n            {\r\n                LuaAPI.lua_pushuint64(L, Convert.ToUInt64(o));\r\n            }\r\n            else if (o is bool)\r\n            {\r\n                bool b = (bool)o;\r\n                LuaAPI.lua_pushboolean(L, b);\r\n            }\r\n            else\r\n            {\r\n                throw new Exception(\"No support type \" + o.GetType());\r\n            }\r\n        }\r\n\r\n        public void PushAny(RealStatePtr L, object o)\r\n        {\r\n            if (o == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n                return;\r\n            }\r\n\r\n            Type type = o.GetType();\r\n            if (type.IsPrimitive())\r\n            {\r\n                pushPrimitive(L, o);\r\n            }\r\n            else if (o is string)\r\n            {\r\n                LuaAPI.lua_pushstring(L, o as string);\r\n            }\r\n            else if (type == typeof(byte[]))\r\n            {\r\n                LuaAPI.lua_pushstring(L, o as byte[]);\r\n            }\r\n            else if (o is decimal)\r\n            {\r\n                PushDecimal(L, (decimal)o);\r\n            }\r\n            else if (o is LuaBase)\r\n            {\r\n                ((LuaBase)o).push(L);\r\n            }\r\n            else if (o is LuaCSFunction)\r\n            {\r\n                Push(L, o as LuaCSFunction);\r\n            }\r\n            else if (o is ValueType)\r\n            {\r\n                PushCSObject push;\r\n                if (custom_push_funcs.TryGetValue(o.GetType(), out push))\r\n                {\r\n                    push(L, o);\r\n                }\r\n                else\r\n                {\r\n                    Push(L, o);\r\n                }\r\n            }\r\n            else\r\n            {\r\n                Push(L, o);\r\n            }\r\n        }\r\n\r\n        Dictionary<object, int> enumMap = new Dictionary<object, int>();\r\n\r\n        public int TranslateToEnumToTop(RealStatePtr L, Type type, int idx)\r\n        {\r\n            object res = null;\r\n            LuaTypes lt = (LuaTypes)LuaAPI.lua_type(L, idx);\r\n            if (lt == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                int ival = (int)LuaAPI.lua_tonumber(L, idx);\r\n                res = Enum.ToObject(type, ival);\r\n            }\r\n            else if (lt == LuaTypes.LUA_TSTRING)\r\n            {\r\n                string sflags = LuaAPI.lua_tostring(L, idx);\r\n                res = Enum.Parse(type, sflags);\r\n            }\r\n            else \r\n            {\r\n                return LuaAPI.luaL_error(L, \"#1 argument must be a integer or a string\");\r\n            }\r\n            PushAny(L, res);\r\n            return 1;\r\n        }\r\n\r\n        public void Push(RealStatePtr L, LuaCSFunction o)\r\n        {\r\n            if (Utils.IsStaticPInvokeCSFunction(o))\r\n            {\r\n                LuaAPI.lua_pushstdcallcfunction(L, o);\r\n            }\r\n            else\r\n            {\r\n                Push(L, (object)o);\r\n                LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.StaticCSFunctionWraper, 1);\r\n            }\r\n        }\r\n\r\n        public void Push(RealStatePtr L, LuaBase o)\r\n        {\r\n            if (o == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n                o.push(L);\r\n            }\r\n        }\r\n\r\n        public void Push(RealStatePtr L, object o)\r\n        {\r\n            if (o == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n                return;\r\n            }\r\n\r\n            int index = -1;\r\n            Type type = o.GetType();\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            bool is_enum = type.IsEnum;\r\n            bool is_valuetype = type.IsValueType;\r\n#else\r\n            bool is_enum = type.GetTypeInfo().IsEnum;\r\n            bool is_valuetype = type.GetTypeInfo().IsValueType;\r\n#endif\r\n            bool needcache = !is_valuetype || is_enum;\r\n            if (needcache && (is_enum ? enumMap.TryGetValue(o, out index) : reverseMap.TryGetValue(o, out index)))\r\n            {\r\n                if (LuaAPI.xlua_tryget_cachedud(L, index, cacheRef) == 1)\r\n                {\r\n                    return;\r\n                }\r\n                //这里实在太经典了，weaktable先删除，然后GC会延迟调用，当index会循环利用的时候，不注释这行将会导致重复释放\r\n                //collectObject(index);\r\n            }\r\n\r\n            bool is_first;\r\n            int type_id = getTypeId(L, type, out is_first);\r\n\r\n            //如果一个type的定义含本身静态readonly实例时，getTypeId会push一个实例，这时候应该用这个实例\r\n            if (is_first && needcache && (is_enum ? enumMap.TryGetValue(o, out index) : reverseMap.TryGetValue(o, out index))) \r\n            {\r\n                if (LuaAPI.xlua_tryget_cachedud(L, index, cacheRef) == 1)\r\n                {\r\n                    return;\r\n                }\r\n            }\r\n\r\n            index = addObject(o, is_valuetype, is_enum);\r\n            LuaAPI.xlua_pushcsobj(L, index, type_id, needcache, cacheRef);\r\n        }\r\n\r\n        public void PushObject(RealStatePtr L, object o, int type_id)\r\n        {\r\n            if (o == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n                return;\r\n            }\r\n\r\n            int index = -1;\r\n            if (reverseMap.TryGetValue(o, out index))\r\n            {\r\n                if (LuaAPI.xlua_tryget_cachedud(L, index, cacheRef) == 1)\r\n                {\r\n                    return;\r\n                }\r\n            }\r\n\r\n            index = addObject(o, false, false);\r\n\r\n            LuaAPI.xlua_pushcsobj(L, index, type_id, true, cacheRef);\r\n        }\r\n\r\n        public void Update(RealStatePtr L, int index, object obj)\r\n        {\r\n            int udata = LuaAPI.xlua_tocsobj_fast(L, index);\r\n\r\n            if (udata != -1)\r\n            {\r\n                objects.Replace(udata, obj);\r\n            }\r\n            else\r\n            {\r\n                UpdateCSObject update;\r\n                if (custom_update_funcs.TryGetValue(obj.GetType(), out update))\r\n                {\r\n                    update(L, index, obj);\r\n                }\r\n                else\r\n                {\r\n                    throw new Exception(\"can not update [\" + obj + \"]\");\r\n                }\r\n            }\r\n        }\r\n\r\n        private object getCsObj(RealStatePtr L, int index, int udata)\r\n        {\r\n            object obj;\r\n            if (udata == -1)\r\n            {\r\n                if (LuaAPI.lua_type(L, index) != LuaTypes.LUA_TUSERDATA) return null;\r\n\r\n                Type type = GetTypeOf(L, index);\r\n                if (type == typeof(decimal))\r\n                {\r\n                    decimal v;\r\n                    Get(L, index, out v);\r\n                    return v;\r\n                }\r\n                GetCSObject get;\r\n                if (type != null && custom_get_funcs.TryGetValue(type, out get))\r\n                {\r\n                    return get(L, index);\r\n                }\r\n                else\r\n                {\r\n                    return null;\r\n                }\r\n            }\r\n            else if (objects.TryGetValue(udata, out obj))\r\n            {\r\n#if !UNITY_5 && !XLUA_GENERAL && !UNITY_2017 && !UNITY_2017_1_OR_NEWER && !UNITY_2018\r\n                if (obj != null && obj is UnityEngine.Object && ((obj as UnityEngine.Object) == null))\r\n                {\r\n                    //throw new UnityEngine.MissingReferenceException(\"The object of type '\"+ obj.GetType().Name +\"' has been destroyed but you are still trying to access it.\");\r\n                    return null;\r\n                }\r\n#endif\r\n                return obj;\r\n            }\r\n            return null;\r\n        }\r\n\r\n        internal object SafeGetCSObj(RealStatePtr L, int index)\r\n        {\r\n            return getCsObj(L, index, LuaAPI.xlua_tocsobj_safe(L, index));\r\n        }\r\n\r\n\t\tinternal object FastGetCSObj(RealStatePtr L,int index)\r\n\t\t{\r\n            return getCsObj(L, index, LuaAPI.xlua_tocsobj_fast(L,index));\r\n        }\r\n\r\n        internal void ReleaseCSObj(RealStatePtr L, int index)\r\n        {\r\n            int udata = LuaAPI.xlua_tocsobj_safe(L, index);\r\n            if (udata != -1)\r\n            {\r\n                object o = objects.Replace(udata, null);\r\n                if (o != null && reverseMap.ContainsKey(o))\r\n                {\r\n                    reverseMap.Remove(o);\r\n                }\r\n            }\r\n        }\r\n\r\n        List<LuaCSFunction> fix_cs_functions = new List<LuaCSFunction>();\r\n\r\n        internal LuaCSFunction GetFixCSFunction(int index)\r\n        {\r\n            return fix_cs_functions[index];\r\n        }\r\n\r\n        internal void PushFixCSFunction(RealStatePtr L, LuaCSFunction func)\r\n        {\r\n            if (func == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n                LuaAPI.xlua_pushinteger(L, fix_cs_functions.Count);\r\n                fix_cs_functions.Add(func);\r\n                LuaAPI.lua_pushstdcallcfunction(L, metaFunctions.FixCSFunctionWraper, 1);\r\n            }\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        CSharpWrapper[] csharpWrapper = new CSharpWrapper[0];\r\n        int csharpWrapperSize = 0;\r\n\r\n        internal int CallCSharpWrapper(RealStatePtr L, int funcidx, int top)\r\n        {\r\n            return csharpWrapper[funcidx](L, top);\r\n        }\r\n\r\n        void ensureCSharpWrapperCapacity(int min)\r\n        {\r\n            if (csharpWrapper.Length < min)\r\n            {\r\n                int num = (csharpWrapper.Length == 0) ? 4 : (csharpWrapper.Length * 2);\r\n                if (num > 2146435071)\r\n                {\r\n                    num = 2146435071;\r\n                }\r\n                if (num < min)\r\n                {\r\n                    num = min;\r\n                }\r\n\r\n                var array = new CSharpWrapper[num];\r\n                Array.Copy(csharpWrapper, 0, array, 0, csharpWrapper.Length);\r\n                csharpWrapper = array;\r\n            }\r\n        }\r\n\r\n        internal void PushCSharpWrapper(RealStatePtr L, CSharpWrapper func)\r\n        {\r\n            if (func == null)\r\n            {\r\n                LuaAPI.lua_pushnil(L);\r\n            }\r\n            else\r\n            {\r\n                LuaAPI.xlua_push_csharp_wrapper(L, csharpWrapperSize);\r\n                ensureCSharpWrapperCapacity(csharpWrapperSize + 1);\r\n                csharpWrapper[csharpWrapperSize++] = func;\r\n            }\r\n        }\r\n#endif\r\n\r\n        internal object[] popValues(RealStatePtr L,int oldTop)\r\n\t\t{\r\n\t\t\tint newTop=LuaAPI.lua_gettop(L);\r\n\t\t\tif(oldTop==newTop)\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tArrayList returnValues=new ArrayList();\r\n\t\t\t\tfor(int i=oldTop+1;i<=newTop;i++)\r\n\t\t\t\t{\r\n\t\t\t\t\treturnValues.Add(GetObject(L,i));\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_settop(L,oldTop);\r\n\t\t\t\treturn returnValues.ToArray();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tinternal object[] popValues(RealStatePtr L,int oldTop,Type[] popTypes)\r\n\t\t{\r\n\t\t\tint newTop=LuaAPI.lua_gettop(L);\r\n\t\t\tif(oldTop==newTop)\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint iTypes;\r\n\t\t\t\tArrayList returnValues=new ArrayList();\r\n\t\t\t\tif(popTypes[0] == typeof(void))\r\n\t\t\t\t\tiTypes=1;\r\n\t\t\t\telse\r\n\t\t\t\t\tiTypes=0;\r\n\t\t\t\tfor(int i=oldTop+1;i<=newTop;i++)\r\n\t\t\t\t{\r\n\t\t\t\t\treturnValues.Add(GetObject(L,i,popTypes[iTypes]));\r\n\t\t\t\t\tiTypes++;\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_settop(L,oldTop);\r\n\t\t\t\treturn returnValues.ToArray();\r\n\t\t\t}\r\n\t\t}\r\n\r\n        public delegate void PushCSObject(RealStatePtr L, object obj);\r\n        public delegate object GetCSObject(RealStatePtr L, int idx);\r\n        public delegate void UpdateCSObject(RealStatePtr L, int idx, object obj);\r\n\r\n        private Dictionary<Type, PushCSObject> custom_push_funcs = new Dictionary<Type, PushCSObject>();\r\n        private Dictionary<Type, GetCSObject> custom_get_funcs = new Dictionary<Type, GetCSObject>();\r\n        private Dictionary<Type, UpdateCSObject> custom_update_funcs = new Dictionary<Type, UpdateCSObject>();\r\n\r\n        void registerCustomOp(Type type, PushCSObject push, GetCSObject get, UpdateCSObject update)\r\n        {\r\n            if (push != null) custom_push_funcs.Add(type, push);\r\n            if (get != null) custom_get_funcs.Add(type, get);\r\n            if (update != null) custom_update_funcs.Add(type, update);\r\n        }\r\n\r\n        public bool HasCustomOp(Type type)\r\n        {\r\n            return custom_push_funcs.ContainsKey(type);\r\n        }\r\n\r\n        private Dictionary<Type, Delegate> push_func_with_type = null;\r\n        \r\n        bool tryGetPushFuncByType<T>(Type type, out T func) where T : class\r\n        {\r\n            if (push_func_with_type == null)\r\n            {\r\n                push_func_with_type = new Dictionary<Type, Delegate>()\r\n                {\r\n                    {typeof(int),  new Action<RealStatePtr, int>(LuaAPI.xlua_pushinteger) },\r\n                    {typeof(double), new Action<RealStatePtr, double>(LuaAPI.lua_pushnumber) },\r\n                    {typeof(string), new Action<RealStatePtr, string>(LuaAPI.lua_pushstring) },\r\n                    {typeof(byte[]), new Action<RealStatePtr, byte[]>(LuaAPI.lua_pushstring) },\r\n                    {typeof(bool), new Action<RealStatePtr, bool>(LuaAPI.lua_pushboolean) },\r\n                    {typeof(long), new Action<RealStatePtr, long>(LuaAPI.lua_pushint64) },\r\n                    {typeof(ulong), new Action<RealStatePtr, ulong>(LuaAPI.lua_pushuint64) },\r\n                    {typeof(IntPtr), new Action<RealStatePtr, IntPtr>(LuaAPI.lua_pushlightuserdata) },\r\n                    {typeof(decimal), new Action<RealStatePtr, decimal>(PushDecimal) },\r\n                    {typeof(byte),  new Action<RealStatePtr, byte>((L, v) => LuaAPI.xlua_pushinteger(L, v)) },\r\n                    {typeof(sbyte),  new Action<RealStatePtr, sbyte>((L, v) => LuaAPI.xlua_pushinteger(L, v)) },\r\n                    {typeof(char),  new Action<RealStatePtr, char>((L, v) => LuaAPI.xlua_pushinteger(L, v)) },\r\n                    {typeof(short),  new Action<RealStatePtr, short>((L, v) => LuaAPI.xlua_pushinteger(L, v)) },\r\n                    {typeof(ushort),  new Action<RealStatePtr, ushort>((L, v) => LuaAPI.xlua_pushinteger(L, v)) },\r\n                    {typeof(uint),  new Action<RealStatePtr, uint>(LuaAPI.xlua_pushuint) },\r\n                    {typeof(float),  new Action<RealStatePtr, float>((L, v) => LuaAPI.lua_pushnumber(L, v)) },\r\n                };\r\n            }\r\n\r\n            Delegate obj;\r\n            if (push_func_with_type.TryGetValue(type, out obj))\r\n            {\r\n                func = obj as T;\r\n                return true;\r\n            }\r\n            else\r\n            {\r\n                func = null;\r\n                return false;\r\n            }\r\n        }\r\n\r\n        private Dictionary<Type, Delegate> get_func_with_type = null;\r\n\r\n        bool tryGetGetFuncByType<T>(Type type, out T func) where T : class\r\n        {\r\n            if (get_func_with_type == null)\r\n            {\r\n                get_func_with_type = new Dictionary<Type, Delegate>()\r\n                {\r\n                    {typeof(int), new Func<RealStatePtr, int, int>(LuaAPI.xlua_tointeger) },\r\n                    {typeof(double), new Func<RealStatePtr, int, double>(LuaAPI.lua_tonumber) },\r\n                    {typeof(string), new Func<RealStatePtr, int, string>(LuaAPI.lua_tostring) },\r\n                    {typeof(byte[]), new Func<RealStatePtr, int, byte[]>(LuaAPI.lua_tobytes) },\r\n                    {typeof(bool), new Func<RealStatePtr, int, bool>(LuaAPI.lua_toboolean) },\r\n                    {typeof(long), new Func<RealStatePtr, int, long>(LuaAPI.lua_toint64) },\r\n                    {typeof(ulong), new Func<RealStatePtr, int, ulong>(LuaAPI.lua_touint64) },\r\n                    {typeof(IntPtr), new Func<RealStatePtr, int, IntPtr>(LuaAPI.lua_touserdata) },\r\n                    {typeof(decimal), new Func<RealStatePtr, int, decimal>((L, idx) => {\r\n                        decimal ret;\r\n                        Get(L, idx, out ret);\r\n                        return ret;\r\n                    }) },\r\n                    {typeof(byte), new Func<RealStatePtr, int, byte>((L, idx) => (byte)LuaAPI.xlua_tointeger(L, idx) ) },\r\n                    {typeof(sbyte), new Func<RealStatePtr, int, sbyte>((L, idx) => (sbyte)LuaAPI.xlua_tointeger(L, idx) ) },\r\n                    {typeof(char), new Func<RealStatePtr, int, char>((L, idx) => (char)LuaAPI.xlua_tointeger(L, idx) ) },\r\n                    {typeof(short), new Func<RealStatePtr, int, short>((L, idx) => (short)LuaAPI.xlua_tointeger(L, idx) ) },\r\n                    {typeof(ushort), new Func<RealStatePtr, int, ushort>((L, idx) => (ushort)LuaAPI.xlua_tointeger(L, idx) ) },\r\n                    {typeof(uint), new Func<RealStatePtr, int, uint>(LuaAPI.xlua_touint) },\r\n                    {typeof(float), new Func<RealStatePtr, int, float>((L, idx) => (float)LuaAPI.lua_tonumber(L, idx) ) },\r\n                };\r\n            }\r\n\r\n            Delegate obj;\r\n            if (get_func_with_type.TryGetValue(type, out obj))\r\n            {\r\n                func = obj as T;\r\n                return true;\r\n            }\r\n            else\r\n            {\r\n                func = null;\r\n                return false;\r\n            }\r\n        }\r\n\r\n        public delegate bool CheckFunc<T>(RealStatePtr L, int idx);\r\n        public delegate void GetFunc<T>(RealStatePtr L, int idx,  out T val);\r\n\r\n        public void RegisterPushAndGetAndUpdate<T>(Action<RealStatePtr, T> push, GetFunc<T> get, Action<RealStatePtr, int, T> update)\r\n        {\r\n            Type type = typeof(T);\r\n            Action<RealStatePtr, T> org_push;\r\n            Func<RealStatePtr, int, T> org_get;\r\n            if (tryGetPushFuncByType(type, out org_push) || tryGetGetFuncByType(type, out org_get))\r\n            {\r\n                throw new InvalidOperationException(\"push or get of \" + type + \" has register!\");\r\n            }\r\n            push_func_with_type.Add(type, push);\r\n            get_func_with_type.Add(type, new Func<RealStatePtr, int, T>((L, idx) => {\r\n                T ret;\r\n                get(L, idx, out ret);\r\n                return ret;\r\n            }));\r\n\r\n            registerCustomOp(type, \r\n                (RealStatePtr L, object obj) => {\r\n                    push(L, (T)obj);\r\n                },\r\n                (RealStatePtr L, int idx) => {\r\n                    T val;\r\n                    get(L, idx, out val);\r\n                    return val;\r\n                },\r\n                (RealStatePtr L, int idx, object obj) => {\r\n                    update(L, idx, (T)obj);\r\n                }\r\n            );\r\n        }\r\n\r\n        public void RegisterChecker<T>(CheckFunc<T> check)\r\n        {\r\n            objectCheckers.AddChecker(typeof(T), (L, idx) =>\r\n            {\r\n                return check(L, idx);\r\n            });\r\n        }\r\n\r\n        public void RegisterCaster<T>(GetFunc<T> get)\r\n        {\r\n            objectCasters.AddCaster(typeof(T), (L, idx, o) =>\r\n            {\r\n                T obj;\r\n                get(L, idx, out obj);\r\n                return obj;\r\n            });\r\n        }\r\n\r\n        int decimal_type_id = -1;\r\n\r\n        public void PushDecimal(RealStatePtr L, decimal val)\r\n        {\r\n            if (decimal_type_id == -1)\r\n            {\r\n                bool is_first;\r\n                decimal_type_id = getTypeId(L, typeof(decimal), out is_first);\r\n            }\r\n            IntPtr buff = LuaAPI.xlua_pushstruct(L, 16, decimal_type_id);\r\n            if (!CopyByValue.Pack(buff, 0, val))\r\n            {\r\n                throw new Exception(\"pack fail for decimal ,value=\" + val);\r\n            }\r\n            \r\n        }\r\n\r\n        public bool IsDecimal(RealStatePtr L, int index)\r\n        {\r\n            if (decimal_type_id == -1) return false;\r\n            return LuaAPI.xlua_gettypeid(L, index) == decimal_type_id;\r\n        }\r\n\r\n        public decimal GetDecimal(RealStatePtr L, int index)\r\n        {\r\n            decimal ret;\r\n            Get(L, index, out ret);\r\n            return ret;\r\n        }\r\n\r\n        public void Get(RealStatePtr L, int index, out decimal val)\r\n        {\r\n            LuaTypes lua_type = LuaAPI.lua_type(L, index);\r\n            if (lua_type == LuaTypes.LUA_TUSERDATA)\r\n            {\r\n                if (LuaAPI.xlua_gettypeid(L, index) != decimal_type_id)\r\n                {\r\n                    throw new Exception(\"invalid userdata for decimal!\");\r\n                }\r\n\r\n                IntPtr buff = LuaAPI.lua_touserdata(L, index);\r\n\r\n                if (!CopyByValue.UnPack(buff, 0, out val))\r\n                {\r\n                    throw new Exception(\"unpack decimal fail!\");\r\n                }\r\n            }\r\n            else if(lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                if (LuaAPI.lua_isint64(L, index))\r\n                {\r\n                    val = (decimal)LuaAPI.lua_toint64(L, index);\r\n                }\r\n                else\r\n                {\r\n                    val = (decimal)LuaAPI.lua_tonumber(L, index); // has gc\r\n                }\r\n            }\r\n            else\r\n            {\r\n                throw new Exception(\"invalid lua value for decimal, LuaType=\" + lua_type);\r\n            }\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Src/ObjectTranslator.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 41d53bdd4bbda0f41a6bd1eb35af4f99\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/ObjectTranslatorPool.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\n\r\nnamespace XLua\r\n{\r\n\tpublic class ObjectTranslatorPool\r\n\t{\r\n#if !SINGLE_ENV\r\n        private Dictionary<RealStatePtr, WeakReference> translators = new Dictionary<RealStatePtr, WeakReference>();\r\n        RealStatePtr lastPtr = default(RealStatePtr);\r\n#endif\r\n        ObjectTranslator lastTranslator = default(ObjectTranslator);\r\n\r\n        public static ObjectTranslatorPool Instance\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn InternalGlobals.objectTranslatorPool;\r\n\t\t\t}\r\n\t\t}\r\n\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n        public static ObjectTranslator FindTranslator(RealStatePtr L)\r\n        {\r\n            return InternalGlobals.objectTranslatorPool.Find(L);\r\n        }\r\n#endif\r\n\r\n        public ObjectTranslatorPool ()\r\n\t\t{\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Add (RealStatePtr L, ObjectTranslator translator)\r\n\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (this)\r\n#endif\r\n            {\r\n                lastTranslator = translator;\r\n#if !SINGLE_ENV\r\n                var ptr = LuaAPI.xlua_gl(L);\r\n                lastPtr = ptr;\r\n                translators.Add(ptr , new WeakReference(translator));\r\n#endif\r\n            }\r\n        }\r\n\r\n\t\tpublic ObjectTranslator Find (RealStatePtr L)\r\n\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (this)\r\n#endif\r\n            {\r\n#if SINGLE_ENV\r\n                return lastTranslator;\r\n#else\r\n                var ptr = LuaAPI.xlua_gl(L);\r\n                if (lastPtr == ptr) return lastTranslator;\r\n                if (translators.ContainsKey(ptr))\r\n                {\r\n                    lastPtr = ptr;\r\n                    lastTranslator = translators[ptr].Target as ObjectTranslator;\r\n                    return lastTranslator;\r\n                }\r\n                \r\n                return null;\r\n#endif\r\n            }\r\n        }\r\n\t\t\r\n\t\tpublic void Remove (RealStatePtr L)\r\n\t\t{\r\n#if THREAD_SAFE || HOTFIX_ENABLE\r\n            lock (this)\r\n#endif\r\n            {\r\n#if SINGLE_ENV\r\n                lastTranslator = default(ObjectTranslator);\r\n#else\r\n                var ptr = LuaAPI.xlua_gl(L);\r\n                if (!translators.ContainsKey (ptr))\r\n                    return;\r\n                \r\n                if (lastPtr == ptr)\r\n                {\r\n                    lastPtr = default(RealStatePtr);\r\n                    lastTranslator = default(ObjectTranslator);\r\n                }\r\n\r\n                translators.Remove(ptr);\r\n#endif\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Src/ObjectTranslatorPool.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 069f15dde2065491db1e68ca5fb1279d\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/RawObject.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nnamespace XLua\r\n{\r\n    public interface RawObject\r\n    {\r\n        object Target { get; }\r\n    }\r\n}\r\n\r\nnamespace XLua.Cast\r\n{\r\n    public class Any<T> : RawObject\r\n    {\r\n        T mTarget;\r\n\r\n        public Any(T i)\r\n        {\r\n            mTarget = i;\r\n        }\r\n\r\n        public object Target\r\n        {\r\n            get\r\n            {\r\n                return mTarget;\r\n            }\r\n        }\r\n    }\r\n\r\n    public class Byte : Any<byte>\r\n    {\r\n        public Byte(byte i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class SByte : Any<sbyte>\r\n    {\r\n        public SByte(sbyte i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Char : Any<char>\r\n    {\r\n        public Char(char i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Int16 : Any<short>\r\n    {\r\n        public Int16(short i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class UInt16 : Any<ushort>\r\n    {\r\n        public UInt16(ushort i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Int32 : Any<int>\r\n    {\r\n        public Int32(int i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class UInt32 : Any<uint>\r\n    {\r\n        public UInt32(uint i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Int64 : Any<long>\r\n    {\r\n        public Int64(long i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class UInt64 : Any<ulong>\r\n    {\r\n        public UInt64(ulong i) : base(i)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Float : Any<float>\r\n    {\r\n        public Float(float i) : base(i)\r\n        {\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/RawObject.cs.meta",
    "content": "fileFormatVersion: 2\nguid: f3f2b65020c56dc4985af0768b06c63c\ntimeCreated: 1498116130\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/SignatureLoader.cs",
    "content": "﻿#if !UNITY_WSA || UNITY_EDITOR\r\nusing System.Security.Cryptography;\r\n#else\r\nusing Windows.Security.Cryptography;\r\nusing Windows.Security.Cryptography.Core;\r\n#endif\r\nusing System;\r\n\r\nnamespace XLua\r\n{\r\n    public class SignatureLoader\r\n    {\r\n        private LuaEnv.CustomLoader userLoader;\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n        RSACryptoServiceProvider rsa;\r\n        SHA1 sha;\r\n#else\r\n        AsymmetricKeyAlgorithmProvider rsa;\r\n        CryptographicKey key;\r\n#endif\r\n\r\n        public SignatureLoader(string publicKey, LuaEnv.CustomLoader loader)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            rsa = new RSACryptoServiceProvider();\r\n            rsa.ImportCspBlob(Convert.FromBase64String(publicKey));\r\n            sha = new SHA1CryptoServiceProvider();\r\n#else\r\n            rsa = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaSignPkcs1Sha1);\r\n            key = rsa.ImportPublicKey(CryptographicBuffer.DecodeFromBase64String(publicKey), CryptographicPublicKeyBlobType.Capi1PublicKey);\r\n#endif\r\n            userLoader = loader;\r\n        }\r\n\r\n\r\n        byte[] load_and_verify(ref string filepath)\r\n        {\r\n            byte[] data = userLoader(ref filepath);\r\n            if (data == null)\r\n            {\r\n                return null;\r\n            }\r\n            if (data.Length < 128)\r\n            {\r\n                throw new InvalidProgramException(filepath + \" length less than 128!\");\r\n            }\r\n\r\n            byte[] sig = new byte[128];\r\n            byte[] filecontent = new byte[data.Length - 128];\r\n            Array.Copy(data, sig, 128);\r\n            Array.Copy(data, 128, filecontent, 0, filecontent.Length);\r\n\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            if (!rsa.VerifyData(filecontent, sha, sig))\r\n            {\r\n                throw new InvalidProgramException(filepath + \" has invalid signature!\");\r\n            }\r\n#else\r\n            if (!CryptographicEngine.VerifySignature(key, CryptographicBuffer.CreateFromByteArray(filecontent), CryptographicBuffer.CreateFromByteArray(sig)))\r\n            {\r\n                throw new InvalidProgramException(filepath + \" has invalid signature!\");\r\n            }\r\n#endif\r\n            return filecontent;\r\n        }\r\n\r\n\r\n        public static implicit operator LuaEnv.CustomLoader(SignatureLoader signatureLoader)\r\n        {\r\n            return signatureLoader.load_and_verify;\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Src/SignatureLoader.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 5dfa9c69dddc18849bd3c1dfc4ac42de\ntimeCreated: 1489222429\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/StaticLuaCallbacks.cs",
    "content": "/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nnamespace XLua\r\n{\r\n    using System;\r\n    using System.IO;\r\n    using System.Reflection;\r\n\r\n    public partial class StaticLuaCallbacks\r\n    {\r\n        internal LuaCSFunction GcMeta, ToStringMeta, EnumAndMeta, EnumOrMeta;\r\n\r\n        internal LuaCSFunction StaticCSFunctionWraper, FixCSFunctionWraper;\r\n\r\n        internal LuaCSFunction DelegateCtor;\r\n\r\n        public StaticLuaCallbacks()\r\n        {\r\n            GcMeta = new LuaCSFunction(StaticLuaCallbacks.LuaGC);\r\n            ToStringMeta = new LuaCSFunction(StaticLuaCallbacks.ToString);\r\n            EnumAndMeta = new LuaCSFunction(EnumAnd);\r\n            EnumOrMeta = new LuaCSFunction(EnumOr);\r\n            StaticCSFunctionWraper = new LuaCSFunction(StaticLuaCallbacks.StaticCSFunction);\r\n            FixCSFunctionWraper = new LuaCSFunction(StaticLuaCallbacks.FixCSFunction);\r\n            DelegateCtor = new LuaCSFunction(DelegateConstructor);\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int EnumAnd(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                object left = translator.FastGetCSObj(L, 1);\r\n                object right = translator.FastGetCSObj(L, 2);\r\n                Type typeOfLeft = left.GetType();\r\n                if (!typeOfLeft.IsEnum() || typeOfLeft != right.GetType())\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"invalid argument for Enum BitwiseAnd\");\r\n                }\r\n                translator.PushAny(L, Enum.ToObject(typeOfLeft, Convert.ToInt64(left) & Convert.ToInt64(right)));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in Enum BitwiseAnd:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int EnumOr(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                object left = translator.FastGetCSObj(L, 1);\r\n                object right = translator.FastGetCSObj(L, 2);\r\n                Type typeOfLeft = left.GetType();\r\n                if (!typeOfLeft.IsEnum() || typeOfLeft != right.GetType())\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"invalid argument for Enum BitwiseOr\");\r\n                }\r\n                translator.PushAny(L, Enum.ToObject(typeOfLeft, Convert.ToInt64(left) | Convert.ToInt64(right)));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in Enum BitwiseOr:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        static int StaticCSFunction(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                LuaCSFunction func = (LuaCSFunction)translator.FastGetCSObj(L, LuaAPI.xlua_upvalueindex(1));\r\n                return func(L);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in StaticCSFunction:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        static int FixCSFunction(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                int idx = LuaAPI.xlua_tointeger(L, LuaAPI.xlua_upvalueindex(1));\r\n                LuaCSFunction func = (LuaCSFunction)translator.GetFixCSFunction(idx);\r\n                return func(L);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in FixCSFunction:\" + e);\r\n            }\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        [MonoPInvokeCallback(typeof(LuaDLL.CSharpWrapperCaller))]\r\n        internal static int CSharpWrapperCallerImpl(RealStatePtr L, int funcidx, int top)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                return translator.CallCSharpWrapper(L, funcidx, top);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception:\" + e);\r\n            }\r\n        }\r\n#endif\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int DelegateCall(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int DelegateCall(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                object objDelegate = translator.FastGetCSObj(L, 1);\r\n                if (objDelegate == null || !(objDelegate is Delegate))\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"trying to invoke a value that is not delegate nor callable\");\r\n                }\r\n                return translator.methodWrapsCache.GetDelegateWrap(objDelegate.GetType())(L);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in DelegateCall:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int LuaGC(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                int udata = LuaAPI.xlua_tocsobj_safe(L, 1);\r\n                if (udata != -1)\r\n                {\r\n                    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                    if ( translator != null )\r\n                    {\r\n                        translator.collectObject(udata);\r\n                    }\r\n                }\r\n                return 0;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in LuaGC:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ToString(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                object obj = translator.FastGetCSObj(L, 1);\r\n                translator.PushAny(L, obj != null ? (obj.ToString() + \": \" + obj.GetHashCode()) : \"<invalid c# object>\");\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ToString:\" + e);\r\n            }\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int DelegateCombine(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int DelegateCombine(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                var translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = translator.FastGetCSObj(L, LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TUSERDATA ? 1 : 2).GetType();\r\n                Delegate d1 = translator.GetObject(L, 1, type) as Delegate;\r\n                Delegate d2 = translator.GetObject(L, 2, type) as Delegate;\r\n                if (d1 == null || d2 == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"one parameter must be a delegate, other one must be delegate or function\");\r\n                }\r\n                translator.PushAny(L, Delegate.Combine(d1, d2));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in DelegateCombine:\" + e);\r\n            }\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int DelegateRemove(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int DelegateRemove(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                var translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Delegate d1 = translator.FastGetCSObj(L, 1) as Delegate;\r\n                if (d1 == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#1 parameter must be a delegate\");\r\n                }\r\n                Delegate d2 = translator.GetObject(L, 2, d1.GetType()) as Delegate;\r\n                if (d2 == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#2 parameter must be a delegate or a function \");\r\n                }\r\n                translator.PushAny(L, Delegate.Remove(d1, d2));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in DelegateRemove:\" + e);\r\n            }\r\n        }\r\n\r\n        static bool tryPrimitiveArrayGet(Type type, RealStatePtr L, object obj, int index)\r\n        {\r\n            bool ok = true;\r\n\r\n            if (type == typeof(int[]))\r\n            {\r\n                int[] array = obj as int[];\r\n                LuaAPI.xlua_pushinteger(L, array[index]);\r\n            }\r\n            else if (type == typeof(float[]))\r\n            {\r\n                float[] array = obj as float[];\r\n                LuaAPI.lua_pushnumber(L, array[index]);\r\n            }\r\n            else if (type == typeof(double[]))\r\n            {\r\n                double[] array = obj as double[];\r\n                LuaAPI.lua_pushnumber(L, array[index]);\r\n            }\r\n            else if (type == typeof(bool[]))\r\n            {\r\n                bool[] array = obj as bool[];\r\n                LuaAPI.lua_pushboolean(L, array[index]);\r\n            }\r\n            else if (type == typeof(long[]))\r\n            {\r\n                long[] array = obj as long[];\r\n                LuaAPI.lua_pushint64(L, array[index]);\r\n            }\r\n            else if (type == typeof(ulong[]))\r\n            {\r\n                ulong[] array = obj as ulong[];\r\n                LuaAPI.lua_pushuint64(L, array[index]);\r\n            }\r\n            else if (type == typeof(sbyte[]))\r\n            {\r\n                sbyte[] array = obj as sbyte[];\r\n                LuaAPI.xlua_pushinteger(L, array[index]);\r\n            }\r\n            else if (type == typeof(short[]))\r\n            {\r\n                short[] array = obj as short[];\r\n                LuaAPI.xlua_pushinteger(L, array[index]);\r\n            }\r\n            else if (type == typeof(ushort[]))\r\n            {\r\n                ushort[] array = obj as ushort[];\r\n                LuaAPI.xlua_pushinteger(L, array[index]);\r\n            }\r\n            else if (type == typeof(char[]))\r\n            {\r\n                char[] array = obj as char[];\r\n                LuaAPI.xlua_pushinteger(L, array[index]);\r\n            }\r\n            else if (type == typeof(uint[]))\r\n            {\r\n                uint[] array = obj as uint[];\r\n                LuaAPI.xlua_pushuint(L, array[index]);\r\n            }\r\n            else if (type == typeof(IntPtr[]))\r\n            {\r\n                IntPtr[] array = obj as IntPtr[];\r\n                LuaAPI.lua_pushlightuserdata(L, array[index]);\r\n            }\r\n            else if (type == typeof(decimal[]))\r\n            {\r\n                decimal[] array = obj as decimal[];\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                translator.PushDecimal(L, array[index]);\r\n            }\r\n            else if (type == typeof(string[]))\r\n            {\r\n                string[] array = obj as string[];\r\n                LuaAPI.lua_pushstring(L, array[index]);\r\n            }\r\n            else\r\n            {\r\n                ok = false;\r\n            }\r\n            return ok;\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int ArrayIndexer(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ArrayIndexer(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                System.Array array = (System.Array)translator.FastGetCSObj(L, 1);\r\n\r\n                if (array == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#1 parameter is not a array!\");\r\n                }\r\n\r\n                int i = LuaAPI.xlua_tointeger(L, 2);\r\n\r\n                if (i >= array.Length)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"index out of range! i =\" + i + \", array.Length=\" + array.Length);\r\n                }\r\n\r\n                Type type = array.GetType();\r\n                if (tryPrimitiveArrayGet(type, L, array, i))\r\n                {\r\n                    return 1;\r\n                }\r\n\r\n                if (InternalGlobals.genTryArrayGetPtr != null)\r\n                {\r\n                    try\r\n                    {\r\n                        if (InternalGlobals.genTryArrayGetPtr(type, L, translator, array, i))\r\n                        {\r\n                            return 1;\r\n                        }\r\n                    }\r\n                    catch (Exception e)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"c# exception:\" + e.Message + \",stack:\" + e.StackTrace);\r\n                    }\r\n                }\r\n\r\n                object ret = array.GetValue(i);\r\n                translator.PushAny(L, ret);\r\n\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ArrayIndexer:\" + e);\r\n            }\r\n        }\r\n\r\n\r\n        public static bool TryPrimitiveArraySet(Type type, RealStatePtr L, object obj, int array_idx, int obj_idx)\r\n        {\r\n            bool ok = true;\r\n\r\n            LuaTypes lua_type = LuaAPI.lua_type(L, obj_idx);\r\n\r\n            if (type == typeof(int[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                int[] array = obj as int[];\r\n                array[array_idx] = LuaAPI.xlua_tointeger(L, obj_idx);\r\n            }\r\n            else if (type == typeof(float[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                float[] array = obj as float[];\r\n                array[array_idx] = (float)LuaAPI.lua_tonumber(L, obj_idx);\r\n            }\r\n            else if (type == typeof(double[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                double[] array = obj as double[];\r\n                array[array_idx] = LuaAPI.lua_tonumber(L, obj_idx); ;\r\n            }\r\n            else if (type == typeof(bool[]) && lua_type == LuaTypes.LUA_TBOOLEAN)\r\n            {\r\n                bool[] array = obj as bool[];\r\n                array[array_idx] = LuaAPI.lua_toboolean(L, obj_idx);\r\n            }\r\n            else if (type == typeof(long[]) && LuaAPI.lua_isint64(L, obj_idx))\r\n            {\r\n                long[] array = obj as long[];\r\n                array[array_idx] = LuaAPI.lua_toint64(L, obj_idx);\r\n            }\r\n            else if (type == typeof(ulong[]) && LuaAPI.lua_isuint64(L, obj_idx))\r\n            {\r\n                ulong[] array = obj as ulong[];\r\n                array[array_idx] = LuaAPI.lua_touint64(L, obj_idx);\r\n            }\r\n            else if (type == typeof(sbyte[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                sbyte[] array = obj as sbyte[];\r\n                array[array_idx] = (sbyte)LuaAPI.xlua_tointeger(L, obj_idx);\r\n            }\r\n            else if (type == typeof(short[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                short[] array = obj as short[];\r\n                array[array_idx] = (short)LuaAPI.xlua_tointeger(L, obj_idx);\r\n            }\r\n            else if (type == typeof(ushort[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                ushort[] array = obj as ushort[];\r\n                array[array_idx] = (ushort)LuaAPI.xlua_tointeger(L, obj_idx);\r\n            }\r\n            else if (type == typeof(char[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                char[] array = obj as char[];\r\n                array[array_idx] = (char)LuaAPI.xlua_tointeger(L, obj_idx);\r\n            }\r\n            else if (type == typeof(uint[]) && lua_type == LuaTypes.LUA_TNUMBER)\r\n            {\r\n                uint[] array = obj as uint[];\r\n                array[array_idx] = LuaAPI.xlua_touint(L, obj_idx);\r\n            }\r\n            else if (type == typeof(IntPtr[]) && lua_type == LuaTypes.LUA_TLIGHTUSERDATA)\r\n            {\r\n                IntPtr[] array = obj as IntPtr[];\r\n                array[array_idx] = LuaAPI.lua_touserdata(L, obj_idx);\r\n            }\r\n            else if (type == typeof(decimal[]))\r\n            {\r\n                decimal[] array = obj as decimal[];\r\n                if (lua_type == LuaTypes.LUA_TNUMBER)\r\n                {\r\n                    array[array_idx] = (decimal)LuaAPI.lua_tonumber(L, obj_idx);\r\n                }\r\n\r\n                if (lua_type == LuaTypes.LUA_TUSERDATA)\r\n                {\r\n                    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                    if (translator.IsDecimal(L, obj_idx))\r\n                    {\r\n                        translator.Get(L, obj_idx, out array[array_idx]);\r\n                    }\r\n                    else\r\n                    {\r\n                        ok = false;\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    ok = false;\r\n                }\r\n            }\r\n            else if (type == typeof(string[]) && lua_type == LuaTypes.LUA_TSTRING)\r\n            {\r\n                string[] array = obj as string[];\r\n                array[array_idx] = LuaAPI.lua_tostring(L, obj_idx);\r\n            }\r\n            else\r\n            {\r\n                ok = false;\r\n            }\r\n            return ok;\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int ArrayNewIndexer(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ArrayNewIndexer(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                System.Array array = (System.Array)translator.FastGetCSObj(L, 1);\r\n\r\n                if (array == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#1 parameter is not a array!\");\r\n                }\r\n\r\n                int i = LuaAPI.xlua_tointeger(L, 2);\r\n\r\n                if (i >= array.Length)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"index out of range! i =\" + i + \", array.Length=\" + array.Length);\r\n                }\r\n\r\n                Type type = array.GetType();\r\n                if (TryPrimitiveArraySet(type, L, array, i, 3))\r\n                {\r\n                    return 0;\r\n                }\r\n\r\n                if (InternalGlobals.genTryArraySetPtr != null)\r\n                {\r\n                    try\r\n                    {\r\n                        if (InternalGlobals.genTryArraySetPtr(type, L, translator, array, i, 3))\r\n                        {\r\n                            return 0;\r\n                        }\r\n                    }\r\n                    catch (Exception e)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"c# exception:\" + e.Message + \",stack:\" + e.StackTrace);\r\n                    }\r\n                }\r\n\r\n                object val = translator.GetObject(L, 3, type.GetElementType());\r\n                array.SetValue(val, i);\r\n\r\n                return 0;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ArrayNewIndexer:\" + e);\r\n            }\r\n        }\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static int ArrayLength(RealStatePtr L, int top)\r\n#else\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ArrayLength(RealStatePtr L)\r\n#endif\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                System.Array array = (System.Array)translator.FastGetCSObj(L, 1);\r\n                LuaAPI.xlua_pushinteger(L, array.Length);\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ArrayLength:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int MetaFuncIndex(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = translator.FastGetCSObj(L, 2) as Type;\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#2 param need a System.Type!\");\r\n                }\r\n                //UnityEngine.Debug.Log(\"============================load type by __index:\" + type);\r\n                //translator.TryDelayWrapLoader(L, type);\r\n                translator.GetTypeId(L, type);\r\n                LuaAPI.lua_pushvalue(L, 2);\r\n                LuaAPI.lua_rawget(L, 1);\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in MetaFuncIndex:\" + e);\r\n            }\r\n        }\r\n\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int Panic(RealStatePtr L)\r\n        {\r\n            string reason = String.Format(\"unprotected error in call to Lua API ({0})\", LuaAPI.lua_tostring(L, -1));\r\n            throw new LuaException(reason);\r\n        }\r\n\r\n#if !XLUA_GENERAL\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int Print(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                int n = LuaAPI.lua_gettop(L);\r\n                string s = String.Empty;\r\n\r\n                if (0 != LuaAPI.xlua_getglobal(L, \"tostring\"))\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"can not get tostring in print:\");\r\n                }\r\n\r\n                for (int i = 1; i <= n; i++)\r\n                {\r\n                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */\r\n                    LuaAPI.lua_pushvalue(L, i);   /* value to print */\r\n                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))\r\n                    {\r\n                        return LuaAPI.lua_error(L);\r\n                    }\r\n                    s += LuaAPI.lua_tostring(L, -1);\r\n\r\n                    if (i != n) s += \"\\t\";\r\n\r\n                    LuaAPI.lua_pop(L, 1);  /* pop result */\r\n                }\r\n                UnityEngine.Debug.Log(\"LUA: \" + s);\r\n                return 0;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in print:\" + e);\r\n            }\r\n        }\r\n#endif\r\n\r\n#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadSocketCore(RealStatePtr L)\r\n        {\r\n            return LuaAPI.luaopen_socket_core(L);\r\n        }\r\n#endif\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadCS(RealStatePtr L)\r\n        {\r\n            LuaAPI.xlua_pushasciistring(L, LuaEnv.CSHARP_NAMESPACE);\r\n            LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            return 1;\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadBuiltinLib(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                string builtin_lib = LuaAPI.lua_tostring(L, 1);\r\n\r\n                LuaEnv self = ObjectTranslatorPool.Instance.Find(L).luaEnv;\r\n\r\n                LuaCSFunction initer;\r\n\r\n                if (self.buildin_initer.TryGetValue(builtin_lib, out initer))\r\n                {\r\n                    LuaAPI.lua_pushstdcallcfunction(L, initer);\r\n                }\r\n                else\r\n                {\r\n                    LuaAPI.lua_pushstring(L, string.Format(\r\n                        \"\\n\\tno such builtin lib '{0}'\", builtin_lib));\r\n                }\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in LoadBuiltinLib:\" + e);\r\n            }\r\n        }\r\n\r\n#if !XLUA_GENERAL\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadFromResource(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + \".lua\";\r\n\r\n                // Load with Unity3D resources\r\n                UnityEngine.TextAsset file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);\r\n                if (file == null)\r\n                {\r\n                    LuaAPI.lua_pushstring(L, string.Format(\r\n                        \"\\n\\tno such resource '{0}'\", filename));\r\n                }\r\n                else\r\n                {\r\n                    if (LuaAPI.xluaL_loadbuffer(L, file.bytes, file.bytes.Length, \"@\" + filename) != 0)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, String.Format(\"error loading module {0} from resource, {1}\",\r\n                            LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));\r\n                    }\r\n                }\r\n\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in LoadFromResource:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadFromStreamingAssetsPath(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + \".lua\";\r\n                var filepath = UnityEngine.Application.streamingAssetsPath + \"/\" + filename;\r\n#if UNITY_ANDROID && !UNITY_EDITOR\r\n                UnityEngine.WWW www = new UnityEngine.WWW(filepath);\r\n                while (true)\r\n                {\r\n                    if (www.isDone || !string.IsNullOrEmpty(www.error))\r\n                    {\r\n                        System.Threading.Thread.Sleep(50); //�Ƚ�hacker������\r\n                        if (!string.IsNullOrEmpty(www.error))\r\n                        {\r\n                            LuaAPI.lua_pushstring(L, string.Format(\r\n                               \"\\n\\tno such file '{0}' in streamingAssetsPath!\", filename));\r\n                        }\r\n                        else\r\n                        {\r\n                            UnityEngine.Debug.LogWarning(\"load lua file from StreamingAssets is obsolete, filename:\" + filename);\r\n                            if (LuaAPI.xluaL_loadbuffer(L, www.bytes, www.bytes.Length , \"@\" + filename) != 0)\r\n                            {\r\n                                return LuaAPI.luaL_error(L, String.Format(\"error loading module {0} from streamingAssetsPath, {1}\",\r\n                                    LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));\r\n                            }\r\n                        }\r\n                        break;\r\n                    }\r\n                }\r\n#else\r\n                if (File.Exists(filepath))\r\n                {\r\n                    // string text = File.ReadAllText(filepath);\r\n                    var bytes = File.ReadAllBytes(filepath);\r\n\r\n                    UnityEngine.Debug.LogWarning(\"load lua file from StreamingAssets is obsolete, filename:\" + filename);\r\n                    if (LuaAPI.xluaL_loadbuffer(L, bytes, bytes.Length, \"@\" + filename) != 0)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, String.Format(\"error loading module {0} from streamingAssetsPath, {1}\",\r\n                            LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    LuaAPI.lua_pushstring(L, string.Format(\r\n                        \"\\n\\tno such file '{0}' in streamingAssetsPath!\", filename));\r\n                }\r\n#endif\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in LoadFromStreamingAssetsPath:\" + e);\r\n            }\r\n        }\r\n#endif\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        internal static int LoadFromCustomLoaders(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                string filename = LuaAPI.lua_tostring(L, 1);\r\n\r\n                LuaEnv self = ObjectTranslatorPool.Instance.Find(L).luaEnv;\r\n\r\n                foreach (var loader in self.customLoaders)\r\n                {\r\n                    string real_file_path = filename;\r\n                    byte[] bytes = loader(ref real_file_path);\r\n                    if (bytes != null)\r\n                    {\r\n                        if (LuaAPI.xluaL_loadbuffer(L, bytes, bytes.Length, \"@\" + real_file_path) != 0)\r\n                        {\r\n                            return LuaAPI.luaL_error(L, String.Format(\"error loading module {0} from CustomLoader, {1}\",\r\n                                LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1)));\r\n                        }\r\n                        return 1;\r\n                    }\r\n                }\r\n                LuaAPI.lua_pushstring(L, string.Format(\r\n                    \"\\n\\tno such file '{0}' in CustomLoaders!\", filename));\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in LoadFromCustomLoaders:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int LoadAssembly(RealStatePtr L)\r\n        {\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n            return LuaAPI.luaL_error(L, \"xlua.load_assembly no support in uwp!\");\r\n#else\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                string assemblyName = LuaAPI.lua_tostring(L, 1);\r\n\r\n                Assembly assembly = null;\r\n\r\n                try\r\n                {\r\n                    assembly = Assembly.Load(assemblyName);\r\n                }\r\n                catch (BadImageFormatException)\r\n                {\r\n                    // The assemblyName was invalid.  It is most likely a path.\r\n                }\r\n\r\n                if (assembly == null)\r\n                {\r\n                    assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));\r\n                }\r\n\r\n                if (assembly != null && !translator.assemblies.Contains(assembly))\r\n                {\r\n                    translator.assemblies.Add(assembly);\r\n                }\r\n                return 0;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.load_assembly:\" + e);\r\n            }\r\n#endif\r\n        }\r\n\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ImportType(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                string className = LuaAPI.lua_tostring(L, 1);\r\n                Type type = translator.FindType(className);\r\n                if (type != null)\r\n                {\r\n                    if (translator.GetTypeId(L, type) >= 0)\r\n                    {\r\n                        LuaAPI.lua_pushboolean(L, true);\r\n                    }\r\n                    else\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"can not load type \" + type);\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    LuaAPI.lua_pushnil(L);\r\n                }\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.import_type:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ImportGenericType(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                int top = LuaAPI.lua_gettop(L);\r\n                if (top < 2) return LuaAPI.luaL_error(L, \"import generic type need at lease 2 arguments\");\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                string className = LuaAPI.lua_tostring(L, 1);\r\n                if (className.EndsWith(\"<>\")) className = className.Substring(0, className.Length - 2);\r\n                Type genericDef = translator.FindType(className + \"`\" + (top - 1));\r\n                if (genericDef == null || !genericDef.IsGenericTypeDefinition())\r\n                {\r\n                    LuaAPI.lua_pushnil(L);\r\n                }\r\n                else\r\n                {\r\n                    Type[] typeArguments = new Type[top - 1];\r\n                    for(int i = 2; i <= top; i++)\r\n                    {\r\n\r\n                        typeArguments[i - 2] = getType(L, translator, i);\r\n                        if (typeArguments[i - 2] == null)\r\n                        {\r\n                            return LuaAPI.luaL_error(L, \"param need a type\");\r\n                        }\r\n                    }\r\n                    Type genericInc = genericDef.MakeGenericType(typeArguments);\r\n                    translator.GetTypeId(L, genericInc);\r\n                    translator.PushAny(L, genericInc);\r\n                }\r\n\r\n                return 1;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.import_type:\" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int Cast(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type;\r\n                translator.Get(L, 2, out type);\r\n\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"#2 param[\" + LuaAPI.lua_tostring(L, 2) + \"]is not valid type indicator\");\r\n                }\r\n                LuaAPI.luaL_getmetatable(L, type.FullName);\r\n                if (LuaAPI.lua_isnil(L, -1))\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"no gen code for \" + LuaAPI.lua_tostring(L, 2));\r\n                }\r\n                LuaAPI.lua_setmetatable(L, 1);\r\n                return 0;\r\n            }\r\n            catch (System.Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.cast:\" + e);\r\n            }\r\n        }\r\n\r\n        static Type getType(RealStatePtr L, ObjectTranslator translator, int idx)\r\n        {\r\n            if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TTABLE)\r\n            {\r\n                LuaTable tbl;\r\n                translator.Get(L, idx, out tbl);\r\n                return tbl.Get<Type>(\"UnderlyingSystemType\");\r\n            }\r\n            else if (LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TSTRING)\r\n            {\r\n                string className = LuaAPI.lua_tostring(L, idx);\r\n                return translator.FindType(className);\r\n            }\r\n            else if (translator.GetObject(L, idx) is Type)\r\n            {\r\n                return translator.GetObject(L, idx) as Type;\r\n            }\r\n            else\r\n            {\r\n                return null;\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int XLuaAccess(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = getType(L, translator, 1);\r\n                object obj = null;\r\n                if (type == null && LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TUSERDATA)\r\n                {\r\n                    obj = translator.SafeGetCSObj(L, 1);\r\n                    if (obj == null)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"xlua.access, #1 parameter must a type/c# object/string\");\r\n                    }\r\n                    type = obj.GetType();\r\n                }\r\n\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"xlua.access, can not find c# type\");\r\n                }\r\n\r\n                string fieldName = LuaAPI.lua_tostring(L, 2);\r\n\r\n                BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;\r\n\r\n                if (LuaAPI.lua_gettop(L) > 2) // set\r\n                {\r\n                    var field = type.GetField(fieldName, bindingFlags);\r\n                    if (field != null)\r\n                    {\r\n                        field.SetValue(obj, translator.GetObject(L, 3, field.FieldType));\r\n                        return 0;\r\n                    }\r\n                    var prop = type.GetProperty(fieldName, bindingFlags);\r\n                    if (prop != null)\r\n                    {\r\n                        prop.SetValue(obj, translator.GetObject(L, 3, prop.PropertyType), null);\r\n                        return 0;\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    var field = type.GetField(fieldName, bindingFlags);\r\n                    if (field != null)\r\n                    {\r\n                        translator.PushAny(L, field.GetValue(obj));\r\n                        return 1;\r\n                    }\r\n                    var prop = type.GetProperty(fieldName, bindingFlags);\r\n                    if (prop != null)\r\n                    {\r\n                        translator.PushAny(L, prop.GetValue(obj, null));\r\n                        return 1;\r\n                    }\r\n                }\r\n                return LuaAPI.luaL_error(L, \"xlua.access, no field \" + fieldName);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.access: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int XLuaPrivateAccessible(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = getType(L, translator, 1); ;\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"xlua.private_accessible, can not find c# type\");\r\n                }\r\n\r\n                while(type != null)\r\n                {\r\n                    translator.PrivateAccessible(L, type);\r\n                    type = type.BaseType();\r\n                }\r\n                return 0;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.private_accessible: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int XLuaMetatableOperation(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = getType(L, translator, 1);\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"xlua.metatable_operation, can not find c# type\");\r\n                }\r\n\r\n                bool is_first = false;\r\n                int type_id = translator.getTypeId(L, type, out is_first);\r\n\r\n                var param_num = LuaAPI.lua_gettop(L);\r\n\r\n                if (param_num == 1) //get\r\n                {\r\n                    LuaAPI.xlua_rawgeti(L, LuaIndexes.LUA_REGISTRYINDEX, type_id);\r\n                    return 1;\r\n                }\r\n                else if (param_num == 2) //set\r\n                {\r\n                    if (LuaAPI.lua_type(L, 2) != LuaTypes.LUA_TTABLE)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"argument #2 must be a table\");\r\n                    }\r\n                    LuaAPI.lua_pushnumber(L, type_id);\r\n                    LuaAPI.xlua_rawseti(L, 2, 1);\r\n                    LuaAPI.xlua_rawseti(L, LuaIndexes.LUA_REGISTRYINDEX, type_id);\r\n                    return 0;\r\n                }\r\n                else\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"invalid argument num for xlua.metatable_operation: \" + param_num);\r\n                }\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.metatable_operation: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int DelegateConstructor(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = getType(L, translator, 1);\r\n                if (type == null || !typeof(Delegate).IsAssignableFrom(type))\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"delegate constructor: #1 argument must be a Delegate's type\");\r\n                }\r\n                translator.PushAny(L, translator.GetObject(L, 2, type));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in delegate constructor: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ToFunction(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                MethodBase m;\r\n                translator.Get(L, 1, out m);\r\n                if (m == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"ToFunction: #1 argument must be a MethodBase\");\r\n                }\r\n                translator.PushFixCSFunction(L,\r\n                        new LuaCSFunction(translator.methodWrapsCache._GenMethodWrap(m.DeclaringType, m.Name, new MethodBase[] { m }).Call));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ToFunction: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int GenericMethodWraper(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                MethodInfo genericMethod;\r\n                translator.Get(L, LuaAPI.xlua_upvalueindex(1), out genericMethod);\r\n                int n = LuaAPI.lua_gettop(L);\r\n                Type[] typeArguments = new Type[n];\r\n                for(int i = 0; i < n; i++)\r\n                {\r\n                    Type type = getType(L, translator, i + 1);\r\n                    if (type == null)\r\n                    {\r\n                        return LuaAPI.luaL_error(L, \"param #\" + (i + 1) + \" is not a type\");\r\n                    }\r\n                    typeArguments[i] = type;\r\n                }\r\n                var method = genericMethod.MakeGenericMethod(typeArguments);\r\n                translator.PushFixCSFunction(L,\r\n                        new LuaCSFunction(translator.methodWrapsCache._GenMethodWrap(method.DeclaringType, method.Name, new MethodBase[] { method }).Call));\r\n                return 1;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in GenericMethodWraper: \" + e);\r\n            }\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int GetGenericMethod(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                Type type = getType(L, translator, 1);\r\n                if (type == null)\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"xlua.get_generic_method, can not find c# type\");\r\n                }\r\n                string methodName = LuaAPI.lua_tostring(L, 2);\r\n                if (string.IsNullOrEmpty(methodName))\r\n                {\r\n                    return LuaAPI.luaL_error(L, \"xlua.get_generic_method, #2 param need a string\");\r\n                }\r\n                System.Collections.Generic.List<MethodInfo> matchMethods = new System.Collections.Generic.List<MethodInfo>();\r\n                var allMethods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);\r\n                for(int i = 0; i < allMethods.Length; i++)\r\n                {\r\n                    var method = allMethods[i];\r\n                    if (method.Name == methodName && method.IsGenericMethodDefinition)\r\n                    {\r\n                        matchMethods.Add(method);\r\n                    }\r\n                }\r\n\r\n                int methodIdx = 0;\r\n\r\n                if (matchMethods.Count == 0)\r\n                {\r\n                    LuaAPI.lua_pushnil(L);\r\n                }\r\n                else\r\n                {\r\n                    if (LuaAPI.lua_isinteger(L, 3))\r\n                    {\r\n                        methodIdx = LuaAPI.xlua_tointeger(L, 3);\r\n                    }\r\n                    translator.PushAny(L, matchMethods[methodIdx]);\r\n                    LuaAPI.lua_pushstdcallcfunction(L, GenericMethodWraper, 1);\r\n                }\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in xlua.get_generic_method: \" + e);\r\n            }\r\n            return 1;\r\n        }\r\n\r\n        [MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n        public static int ReleaseCsObject(RealStatePtr L)\r\n        {\r\n            try\r\n            {\r\n                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n                translator.ReleaseCSObj(L, 1);\r\n                return 0;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                return LuaAPI.luaL_error(L, \"c# exception in ReleaseCsObject: \" + e);\r\n            }\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "Assets/XLua/Src/StaticLuaCallbacks.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 300ed412007935e45a1546a984b89059\ntimeCreated: 1469175028\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/TemplateEngine/TemplateEngine.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nusing System;\r\nusing System.Linq;\r\nusing System.Text.RegularExpressions;\r\nusing System.Collections.Generic;\r\nusing System.Collections;\r\nusing System.Text;\r\nusing XLua;\r\n\r\nnamespace XLua.TemplateEngine\r\n{\r\n    public enum TokenType\r\n    {\r\n        Code, Eval, Text\r\n    }\r\n\r\n    public class Chunk\r\n    {\r\n        public TokenType Type {get; private set;}\r\n        public string Text { get; private set; }\r\n        public Chunk(TokenType type, string text)\r\n        {\r\n            Type = type;\r\n            Text = text;\r\n        }\r\n    }\r\n\r\n    class TemplateFormatException : Exception\r\n    {\r\n        public TemplateFormatException(string message)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class Parser\r\n    {\r\n        public static string RegexString\r\n        {\r\n            get;\r\n            private set;\r\n        }\r\n\r\n        static Parser()\r\n        {\r\n            RegexString = GetRegexString();\r\n        }\r\n\r\n        /// <summary>\r\n        /// Replaces special characters with their literal representation.\r\n        /// </summary>\r\n        /// <returns>Resulting string.</returns>\r\n        /// <param name=\"input\">Input string.</param>\r\n        static string EscapeString(string input)\r\n        {\r\n            var output = input\r\n                .Replace(\"\\\\\", @\"\\\\\")\r\n                    .Replace(\"\\'\", @\"\\'\")\r\n                    .Replace(\"\\\"\", @\"\\\"\"\")\r\n                    .Replace(\"\\n\", @\"\\n\")\r\n                    .Replace(\"\\t\", @\"\\t\")\r\n                    .Replace(\"\\r\", @\"\\r\")\r\n                    .Replace(\"\\b\", @\"\\b\")\r\n                    .Replace(\"\\f\", @\"\\f\")\r\n                    .Replace(\"\\a\", @\"\\a\")\r\n                    .Replace(\"\\v\", @\"\\v\")\r\n                    .Replace(\"\\0\", @\"\\0\");\r\n            /*          var surrogateMin = (char)0xD800;\r\n            var surrogateMax = (char)0xDFFF;\r\n            for (char sur = surrogateMin; sur <= surrogateMax; sur++)\r\n                output.Replace(sur, '\\uFFFD');*/\r\n            return output;\r\n        }\r\n\r\n        static string GetRegexString()\r\n        {\r\n            string regexBadUnopened = @\"(?<error>((?!<%).)*%>)\";\r\n            string regexText = @\"(?<text>((?!<%).)+)\";\r\n            string regexNoCode = @\"(?<nocode><%=?%>)\";\r\n            string regexCode = @\"<%(?<code>[^=]((?!<%|%>).)*)%>\";\r\n            string regexEval = @\"<%=(?<eval>((?!<%|%>).)*)%>\";\r\n            string regexBadUnclosed = @\"(?<error><%.*)\";\r\n            string regexBadEmpty = @\"(?<error>^$)\";\r\n\r\n            return '(' + regexBadUnopened\r\n                + '|' + regexText\r\n                + '|' + regexNoCode\r\n                + '|' + regexCode\r\n                + '|' + regexEval\r\n                + '|' + regexBadUnclosed\r\n                + '|' + regexBadEmpty\r\n                + \")*\";\r\n        }\r\n\r\n        /// <summary>\r\n        /// Parses the string into regex groups, \r\n        /// stores group:value pairs in List of Chunk\r\n        /// <returns>List of group:value pairs.</returns>;\r\n        /// </summary>\r\n        public static List<Chunk> Parse(string snippet)\r\n        {\r\n            Regex templateRegex = new Regex(\r\n                RegexString,\r\n                RegexOptions.ExplicitCapture | RegexOptions.Singleline\r\n            );\r\n            Match matches = templateRegex.Match(snippet);\r\n\r\n            if (matches.Groups[\"error\"].Length > 0)\r\n            {\r\n                throw new TemplateFormatException(\"Messed up brackets\");\r\n            }\r\n\r\n            List<Chunk> Chunks = matches.Groups[\"code\"].Captures\r\n                .Cast<Capture>()\r\n                .Select(p => new { Type = TokenType.Code, p.Value, p.Index })\r\n                .Concat(matches.Groups[\"text\"].Captures\r\n                .Cast<Capture>()\r\n                .Select(p => new { Type = TokenType.Text, Value = EscapeString(p.Value), p.Index }))\r\n                .Concat(matches.Groups[\"eval\"].Captures\r\n                .Cast<Capture>()\r\n                .Select(p => new { Type = TokenType.Eval, p.Value, p.Index }))\r\n                .OrderBy(p => p.Index)\r\n                .Select(m => new Chunk(m.Type, m.Value))\r\n                .ToList();\r\n\r\n            if (Chunks.Count == 0)\r\n            {\r\n                throw new TemplateFormatException(\"Empty template\");\r\n            }\r\n            return Chunks;\r\n        }\r\n    }\r\n\r\n    public class LuaTemplate\r\n    {\r\n        public static string ComposeCode(List<Chunk> chunks)\r\n        {\r\n            StringBuilder code = new StringBuilder();\r\n\r\n            code.Append(\"local __text_gen = {}\\r\\n\");\r\n            foreach (var chunk in chunks)\r\n            {\r\n                switch (chunk.Type)\r\n                {\r\n                    case TokenType.Text:\r\n                        code.Append(\"table.insert(__text_gen, \\\"\" + chunk.Text + \"\\\")\\r\\n\");\r\n                        break;\r\n                    case TokenType.Eval:\r\n                        code.Append(\"table.insert(__text_gen, tostring(\" + chunk.Text + \"))\\r\\n\");\r\n                        break;\r\n                    case TokenType.Code:\r\n                        code.Append(chunk.Text + \"\\r\\n\");\r\n                        break;\r\n                }\r\n            }\r\n\r\n            code.Append(\"return table.concat(__text_gen)\\r\\n\");\r\n            //UnityEngine.Debug.Log(\"code compose:\"+code.ToString());\r\n            return code.ToString();\r\n        }\r\n\r\n        public static LuaFunction Compile(LuaEnv luaenv, string snippet)\r\n        {\r\n            return luaenv.LoadString(ComposeCode(Parser.Parse(snippet)), \"luatemplate\");\r\n        }\r\n\r\n        public static string Execute(LuaFunction compiledTemplate, LuaTable parameters)\r\n        {\r\n            compiledTemplate.SetEnv(parameters);\r\n            object[] result = compiledTemplate.Call();\r\n            System.Diagnostics.Debug.Assert(result.Length == 1);\r\n            return result[0].ToString();\r\n        }\r\n\r\n        public static string Execute(LuaFunction compiledTemplate)\r\n        {\r\n            object[] result = compiledTemplate.Call();\r\n            System.Diagnostics.Debug.Assert(result.Length == 1);\r\n            return result[0].ToString();\r\n        }\r\n\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        public static int Compile(RealStatePtr L)\r\n        {\r\n\t\t\tstring snippet = LuaAPI.lua_tostring(L, 1);\r\n            \r\n            string code;\r\n            try\r\n            {\r\n                code = ComposeCode(Parser.Parse(snippet));\r\n            }\r\n            catch (Exception e)\r\n            {\r\n\t\t\t\treturn LuaAPI.luaL_error(L, String.Format(\"template compile error:{0}\\r\\n\", e.Message));\r\n            }\r\n            //UnityEngine.Debug.Log(\"code=\" + code);\r\n            if (LuaAPI.luaL_loadbuffer(L, code, \"luatemplate\") != 0)\r\n            {\r\n                return LuaAPI.lua_error(L);\r\n            }\r\n            return 1;\r\n        }\r\n\r\n        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]\r\n        public static int Execute(RealStatePtr L)\r\n        {\r\n            if (!LuaAPI.lua_isfunction(L, 1))\r\n            {\r\n                return LuaAPI.luaL_error(L, \"invalid compiled template, function needed!\\r\\n\");\r\n            }\r\n            if (LuaAPI.lua_istable(L, 2))\r\n            {\r\n                LuaAPI.lua_setfenv(L, 1);\r\n            }\r\n            LuaAPI.lua_pcall(L, 0, 1, 0);\r\n            return 1;\r\n        }\r\n\r\n        static LuaCSFunction templateCompileFunction = Compile;\r\n        static LuaCSFunction templateExecuteFunction = Execute;\r\n\r\n        public static void OpenLib(RealStatePtr L)\r\n        {\r\n            LuaAPI.lua_newtable(L);\r\n            LuaAPI.xlua_pushasciistring(L, \"compile\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, templateCompileFunction);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            LuaAPI.xlua_pushasciistring(L, \"execute\");\r\n            LuaAPI.lua_pushstdcallcfunction(L, templateExecuteFunction);\r\n            LuaAPI.lua_rawset(L, -3);\r\n            if (0 != LuaAPI.xlua_setglobal(L, \"template\"))\r\n            {\r\n                throw new Exception(\"call xlua_setglobal fail!\");\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n"
  },
  {
    "path": "Assets/XLua/Src/TemplateEngine/TemplateEngine.cs.meta",
    "content": "fileFormatVersion: 2\nguid: d416b4da0b828854c8e997f0c1ae4072\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/TemplateEngine.meta",
    "content": "fileFormatVersion: 2\nguid: 4f996f6400fcbdd4db02eeab46d9dd1e\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src/TypeExtensions.cs",
    "content": "﻿using System;\r\nusing System.Linq;\r\nusing System.Reflection;\r\n\r\nnamespace XLua\r\n{\r\n\r\n    internal static class TypeExtensions\r\n    {\r\n        public static bool IsValueType(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsValueType;\r\n#else\r\n            return type.GetTypeInfo().IsValueType;\r\n#endif\r\n        }\r\n\r\n        public static bool IsEnum(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsEnum;\r\n#else\r\n            return type.GetTypeInfo().IsEnum;\r\n#endif\r\n        }\r\n\r\n        public static bool IsPrimitive(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsPrimitive;\r\n#else\r\n            return type.GetTypeInfo().IsPrimitive;\r\n#endif\r\n        }\r\n\r\n        public static bool IsAbstract(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsAbstract;\r\n#else\r\n            return type.GetTypeInfo().IsAbstract;\r\n#endif\r\n        }\r\n\r\n        public static bool IsSealed(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsSealed;\r\n#else\r\n            return type.GetTypeInfo().IsSealed;\r\n#endif\r\n        }\r\n\r\n        public static bool IsInterface(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsInterface;\r\n#else\r\n            return type.GetTypeInfo().IsInterface;\r\n#endif\r\n        }\r\n\r\n        public static bool IsClass(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsClass;\r\n#else\r\n            return type.GetTypeInfo().IsClass;\r\n#endif\r\n        }\r\n\r\n        public static Type BaseType(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.BaseType;\r\n#else\r\n            return type.GetTypeInfo().BaseType;\r\n#endif\r\n        }\r\n\r\n        public static bool IsGenericType(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsGenericType;\r\n#else\r\n            return type.GetTypeInfo().IsGenericType;\r\n#endif\r\n        }\r\n\r\n        public static bool IsGenericTypeDefinition(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsGenericTypeDefinition;\r\n#else\r\n            return type.GetTypeInfo().IsGenericTypeDefinition;\r\n#endif\r\n        }\r\n\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n        public static bool IsSubclassOf(this Type type, Type c)\r\n        {\r\n            return type.GetTypeInfo().IsSubclassOf(c);\r\n        }\r\n\r\n        public static bool IsDefined(this Type type, Type attributeType, bool inherit)\r\n        {\r\n            return type.GetTypeInfo().IsDefined(attributeType, inherit);\r\n        }\r\n\r\n        public static Type[] GetGenericParameterConstraints(this Type type)\r\n        {\r\n            return type.GetTypeInfo().GetGenericParameterConstraints();\r\n        }\r\n#endif\r\n\r\n        public static bool IsNestedPublic(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsNestedPublic;\r\n#else\r\n            return type.GetTypeInfo().IsNestedPublic;\r\n#endif        \r\n        }\r\n\r\n        public static bool IsPublic(this Type type)\r\n        {\r\n#if !UNITY_WSA || UNITY_EDITOR\r\n            return type.IsPublic;\r\n#else\r\n            return type.GetTypeInfo().IsPublic;\r\n#endif        \r\n        }\r\n\r\n        public static string GetFriendlyName(this Type type)\r\n        {\r\n            if (type == typeof(int))\r\n                return \"int\";\r\n            else if (type == typeof(short))\r\n                return \"short\";\r\n            else if (type == typeof(byte))\r\n                return \"byte\";\r\n            else if (type == typeof(bool))\r\n                return \"bool\";\r\n            else if (type == typeof(long))\r\n                return \"long\";\r\n            else if (type == typeof(float))\r\n                return \"float\";\r\n            else if (type == typeof(double))\r\n                return \"double\";\r\n            else if (type == typeof(decimal))\r\n                return \"decimal\";\r\n            else if (type == typeof(string))\r\n                return \"string\";\r\n            else if (type.IsGenericType())\r\n                return type.FullName.Split('`')[0] + \"<\" + string.Join(\", \", type.GetGenericArguments()\r\n                    .Select(x => GetFriendlyName(x)).ToArray()) + \">\";\r\n            else\r\n                return type.FullName;\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/TypeExtensions.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 0099a231859d6da43932d0c36714e17f\ntimeCreated: 1489998065\nlicenseType: Free\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Src/Utils.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\nusing System.Reflection;\r\nusing System.Linq;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#if USE_UNI_LUA\r\nusing LuaAPI = UniLua.Lua;\r\nusing RealStatePtr = UniLua.ILuaState;\r\nusing LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n#else\r\nusing LuaAPI = XLua.LuaDLL.Lua;\r\nusing RealStatePtr = System.IntPtr;\r\nusing LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n#endif\r\n\r\nnamespace XLua\r\n{\r\n\tpublic enum LazyMemberTypes\r\n\t{\r\n\t\tMethod,\r\n\t\tFieldGet,\r\n\t\tFieldSet,\r\n\t\tPropertyGet,\r\n\t\tPropertySet,\r\n\t\tEvent,\r\n\t}\r\n\r\n\tpublic static partial class Utils\r\n\t{\r\n\t\tpublic static bool LoadField(RealStatePtr L, int idx, string field_name)\r\n\t\t{\r\n\t\t\tidx = idx > 0 ? idx : LuaAPI.lua_gettop(L) + idx + 1;// abs of index\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, field_name);\r\n\t\t\tLuaAPI.lua_rawget(L, idx);\r\n\t\t\treturn !LuaAPI.lua_isnil(L, -1);\r\n\t\t}\r\n\r\n\t\tpublic static RealStatePtr GetMainState(RealStatePtr L)\r\n\t\t{\r\n\t\t\tRealStatePtr ret = default(RealStatePtr);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaEnv.MAIN_SHREAD);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tif (LuaAPI.lua_isthread(L, -1))\r\n\t\t\t{\r\n\t\t\t\tret = LuaAPI.lua_tothread(L, -1);\r\n\t\t\t}\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\treturn ret;\r\n\t\t}\r\n\r\n#if (UNITY_WSA && !ENABLE_IL2CPP) && !UNITY_EDITOR\r\n        public static List<Assembly> _assemblies;\r\n        public static List<Assembly> GetAssemblies()\r\n        {\r\n            if (_assemblies == null)\r\n            {\r\n                System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(() =>\r\n                {\r\n                    _assemblies = GetAssemblyList().Result;\r\n                });\r\n                t.Start();\r\n                t.Wait();\r\n            }\r\n            return _assemblies;\r\n            \r\n        }\r\n        public static async System.Threading.Tasks.Task<List<Assembly>> GetAssemblyList()\r\n        {\r\n            List<Assembly> assemblies = new List<Assembly>();\r\n            //return assemblies;\r\n            var files = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFilesAsync();\r\n            if (files == null)\r\n                return assemblies;\r\n\r\n            foreach (var file in files.Where(file => file.FileType == \".dll\" || file.FileType == \".exe\"))\r\n            {\r\n                try\r\n                {\r\n                    assemblies.Add(Assembly.Load(new AssemblyName(file.DisplayName)));\r\n                }\r\n                catch (Exception ex)\r\n                {\r\n                    System.Diagnostics.Debug.WriteLine(ex.Message);\r\n                }\r\n\r\n            }\r\n            return assemblies;\r\n        }\r\n        public static IEnumerable<Type> GetAllTypes(bool exclude_generic_definition = true)\r\n        {\r\n            var assemblies = GetAssemblies();\r\n            return from assembly in assemblies\r\n                   where !(assembly.IsDynamic)\r\n                   from type in assembly.GetTypes()\r\n                   where exclude_generic_definition ? !type.GetTypeInfo().IsGenericTypeDefinition : true\r\n                   select type;\r\n        }\r\n#else\r\n\t\tpublic static List<Type> GetAllTypes(bool exclude_generic_definition = true)\r\n\t\t{\r\n\t\t\tList<Type> allTypes = new List<Type>();\r\n\t\t\tvar assemblies = AppDomain.CurrentDomain.GetAssemblies();\r\n\t\t\tfor (int i = 0; i < assemblies.Length; i++)\r\n\t\t\t{\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n\t\t\t\t\tif (!(assemblies[i].ManifestModule is System.Reflection.Emit.ModuleBuilder))\r\n\t\t\t\t\t{\r\n#endif\r\n\t\t\t\t\t\tallTypes.AddRange(assemblies[i].GetTypes()\r\n\t\t\t\t\t\t.Where(type => exclude_generic_definition ? !type.IsGenericTypeDefinition() : true)\r\n\t\t\t\t\t\t);\r\n#if (UNITY_EDITOR || XLUA_GENERAL) && !NET_STANDARD_2_0\r\n\t\t\t\t\t}\r\n#endif\r\n\t\t\t\t}\r\n\t\t\t\tcatch (Exception)\r\n\t\t\t\t{\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn allTypes;\r\n\t\t}\r\n#endif\r\n\r\n\t\tstatic LuaCSFunction genFieldGetter(Type type, FieldInfo field)\r\n\t\t{\r\n\t\t\tif (field.IsStatic)\r\n\t\t\t{\r\n\t\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t\t{\r\n\t\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t\ttranslator.PushAny(L, field.GetValue(null));\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t\t{\r\n\t\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t\tobject obj = translator.FastGetCSObj(L, 1);\r\n\t\t\t\t\tif (obj == null || !type.IsInstanceOfType(obj))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"Expected type \" + type + \", but got \" + (obj == null ? \"null\" : obj.GetType().ToString()) + \", while get field \" + field);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\ttranslator.PushAny(L, field.GetValue(obj));\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic LuaCSFunction genFieldSetter(Type type, FieldInfo field)\r\n\t\t{\r\n\t\t\tif (field.IsStatic)\r\n\t\t\t{\r\n\t\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t\t{\r\n\t\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t\tobject val = translator.GetObject(L, 1, field.FieldType);\r\n\t\t\t\t\tif (field.FieldType.IsValueType() && Nullable.GetUnderlyingType(field.FieldType) == null && val == null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn LuaAPI.luaL_error(L, type.Name + \".\" + field.Name + \" Expected type \" + field.FieldType);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfield.SetValue(null, val);\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t\t{\r\n\t\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\r\n\t\t\t\t\tobject obj = translator.FastGetCSObj(L, 1);\r\n\t\t\t\t\tif (obj == null || !type.IsInstanceOfType(obj))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"Expected type \" + type + \", but got \" + (obj == null ? \"null\" : obj.GetType().ToString()) + \", while set field \" + field);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tobject val = translator.GetObject(L, 2, field.FieldType);\r\n\t\t\t\t\tif (field.FieldType.IsValueType() && Nullable.GetUnderlyingType(field.FieldType) == null && val == null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn LuaAPI.luaL_error(L, type.Name + \".\" + field.Name + \" Expected type \" + field.FieldType);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfield.SetValue(obj, val);\r\n\t\t\t\t\tif (type.IsValueType())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttranslator.Update(L, 1, obj);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic LuaCSFunction genItemGetter(Type type, PropertyInfo[] props)\r\n\t\t{\r\n\t\t\tprops = props.Where(prop => !prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string))).ToArray();\r\n\t\t\tif (props.Length == 0)\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\tType[] params_type = new Type[props.Length];\r\n\t\t\tfor (int i = 0; i < props.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tparams_type[i] = props[i].GetIndexParameters()[0].ParameterType;\r\n\t\t\t}\r\n\t\t\tobject[] arg = new object[1] { null };\r\n\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t{\r\n\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\tobject obj = translator.FastGetCSObj(L, 1);\r\n\t\t\t\tif (obj == null || !type.IsInstanceOfType(obj))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(L, \"Expected type \" + type + \", but got \" + (obj == null ? \"null\" : obj.GetType().ToString()) + \", while get prop \" + props[0].Name);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tfor (int i = 0; i < props.Length; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!translator.Assignable(L, 2, params_type[i]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tPropertyInfo prop = props[i];\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tobject index = translator.GetObject(L, 2, params_type[i]);\r\n\t\t\t\t\t\t\targ[0] = index;\r\n\t\t\t\t\t\t\tobject ret = prop.GetValue(obj, arg);\r\n\t\t\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\t\t\t\t\t\t\ttranslator.PushAny(L, ret);\r\n\t\t\t\t\t\t\treturn 2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (Exception e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"try to get \" + type + \".\" + prop.Name + \" throw a exception:\" + e + \",stack:\" + e.StackTrace);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, false);\r\n\t\t\t\treturn 1;\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tstatic LuaCSFunction genItemSetter(Type type, PropertyInfo[] props)\r\n\t\t{\r\n\t\t\tprops = props.Where(prop => !prop.GetIndexParameters()[0].ParameterType.IsAssignableFrom(typeof(string))).ToArray();\r\n\t\t\tif (props.Length == 0)\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t\tType[] params_type = new Type[props.Length];\r\n\t\t\tfor (int i = 0; i < props.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tparams_type[i] = props[i].GetIndexParameters()[0].ParameterType;\r\n\t\t\t}\r\n\t\t\tobject[] arg = new object[1] { null };\r\n\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t{\r\n\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\tobject obj = translator.FastGetCSObj(L, 1);\r\n\t\t\t\tif (obj == null || !type.IsInstanceOfType(obj))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(L, \"Expected type \" + type + \", but got \" + (obj == null ? \"null\" : obj.GetType().ToString()) + \", while set prop \" + props[0].Name);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tfor (int i = 0; i < props.Length; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!translator.Assignable(L, 2, params_type[i]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tPropertyInfo prop = props[i];\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\targ[0] = translator.GetObject(L, 2, params_type[i]);\r\n\t\t\t\t\t\t\tobject val = translator.GetObject(L, 3, prop.PropertyType);\r\n\t\t\t\t\t\t\tif (val == null)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, type.Name + \".\" + prop.Name + \" Expected type \" + prop.PropertyType);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tprop.SetValue(obj, val, arg);\r\n\t\t\t\t\t\t\tLuaAPI.lua_pushboolean(L, true);\r\n\r\n\t\t\t\t\t\t\treturn 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (Exception e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"try to set \" + type + \".\" + prop.Name + \" throw a exception:\" + e + \",stack:\" + e.StackTrace);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tLuaAPI.lua_pushboolean(L, false);\r\n\t\t\t\treturn 1;\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tstatic LuaCSFunction genEnumCastFrom(Type type)\r\n\t\t{\r\n\t\t\treturn (RealStatePtr L) =>\r\n\t\t\t{\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\t\treturn translator.TranslateToEnumToTop(L, type, 1);\r\n\t\t\t\t}\r\n\t\t\t\tcatch (Exception e)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(L, \"cast to \" + type + \" exception:\" + e);\r\n\t\t\t\t}\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tinternal static IEnumerable<MethodInfo> GetExtensionMethodsOf(Type type_to_be_extend)\r\n\t\t{\r\n\t\t\tif (InternalGlobals.extensionMethodMap == null)\r\n\t\t\t{\r\n\t\t\t\tList<Type> type_def_extention_method = new List<Type>();\r\n\r\n\t\t\t\tIEnumerator<Type> enumerator = GetAllTypes().GetEnumerator();\r\n\r\n\t\t\t\twhile (enumerator.MoveNext())\r\n\t\t\t\t{\r\n\t\t\t\t\tType type = enumerator.Current;\r\n\t\t\t\t\tif (type.IsDefined(typeof(ExtensionAttribute), false) && (\r\n\t\t\t\t\t\t\ttype.IsDefined(typeof(ReflectionUseAttribute), false)\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n\t\t\t\t\t\t\t|| type.IsDefined(typeof(LuaCallCSharpAttribute), false)\r\n#endif\r\n\t\t\t\t\t\t))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttype_def_extention_method.Add(type);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (!type.IsAbstract() || !type.IsSealed()) continue;\r\n\r\n\t\t\t\t\tvar fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n\t\t\t\t\tfor (int i = 0; i < fields.Length; i++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar field = fields[i];\r\n\t\t\t\t\t\tif ((field.IsDefined(typeof(ReflectionUseAttribute), false)\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n\t\t\t\t\t\t\t|| field.IsDefined(typeof(LuaCallCSharpAttribute), false)\r\n#endif\r\n\t\t\t\t\t\t\t) && (typeof(IEnumerable<Type>)).IsAssignableFrom(field.FieldType))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ttype_def_extention_method.AddRange((field.GetValue(null) as IEnumerable<Type>)\r\n\t\t\t\t\t\t\t\t.Where(t => t.IsDefined(typeof(ExtensionAttribute), false)));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tvar props = type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);\r\n\t\t\t\t\tfor (int i = 0; i < props.Length; i++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar prop = props[i];\r\n\t\t\t\t\t\tif ((prop.IsDefined(typeof(ReflectionUseAttribute), false)\r\n#if UNITY_EDITOR || XLUA_GENERAL\r\n\t\t\t\t\t\t\t|| prop.IsDefined(typeof(LuaCallCSharpAttribute), false)\r\n#endif\r\n\t\t\t\t\t\t\t) && (typeof(IEnumerable<Type>)).IsAssignableFrom(prop.PropertyType))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ttype_def_extention_method.AddRange((prop.GetValue(null, null) as IEnumerable<Type>)\r\n\t\t\t\t\t\t\t\t.Where(t => t.IsDefined(typeof(ExtensionAttribute), false)));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tenumerator.Dispose();\r\n\r\n\t\t\t\tInternalGlobals.extensionMethodMap = (from type in type_def_extention_method\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t  from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t  where method.IsDefined(typeof(ExtensionAttribute), false) && IsSupportedMethod(method)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t  group method by getExtendedType(method)).ToDictionary(g => g.Key, g => g as IEnumerable<MethodInfo>);\r\n\t\t\t}\r\n\t\t\tIEnumerable<MethodInfo> ret = null;\r\n\t\t\tInternalGlobals.extensionMethodMap.TryGetValue(type_to_be_extend, out ret);\r\n\t\t\treturn ret;\r\n\t\t}\r\n\r\n\t\tstruct MethodKey\r\n\t\t{\r\n\t\t\tpublic string Name;\r\n\t\t\tpublic bool IsStatic;\r\n\t\t}\r\n\r\n\t\tstatic void makeReflectionWrap(RealStatePtr L, Type type, int cls_field, int cls_getter, int cls_setter,\r\n\t\t\tint obj_field, int obj_getter, int obj_setter, int obj_meta, out LuaCSFunction item_getter, out LuaCSFunction item_setter, BindingFlags access)\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\tBindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | access;\r\n\t\t\tFieldInfo[] fields = type.GetFields(flag);\r\n\t\t\tEventInfo[] all_events = type.GetEvents(flag | BindingFlags.Public | BindingFlags.NonPublic);\r\n\r\n            LuaAPI.lua_checkstack(L, 2);\r\n\r\n            for (int i = 0; i < fields.Length; ++i)\r\n\t\t\t{\r\n\t\t\t\tFieldInfo field = fields[i];\r\n\t\t\t\tstring fieldName = field.Name;\r\n\t\t\t\t// skip hotfix inject field\r\n\t\t\t\tif (field.IsStatic && (field.Name.StartsWith(\"__Hotfix\") || field.Name.StartsWith(\"_c__Hotfix\")) && typeof(Delegate).IsAssignableFrom(field.FieldType))\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tif (all_events.Any(e => e.Name == fieldName))\r\n\t\t\t\t{\r\n\t\t\t\t\tfieldName = \"&\" + fieldName;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (field.IsStatic && (field.IsInitOnly || field.IsLiteral))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, fieldName);\r\n\t\t\t\t\ttranslator.PushAny(L, field.GetValue(null));\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, cls_field);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, fieldName);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L, genFieldGetter(type, field));\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, field.IsStatic ? cls_getter : obj_getter);\r\n\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, fieldName);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L, genFieldSetter(type, field));\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, field.IsStatic ? cls_setter : obj_setter);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEventInfo[] events = type.GetEvents(flag);\r\n\t\t\tfor (int i = 0; i < events.Length; ++i)\r\n\t\t\t{\r\n\t\t\t\tEventInfo eventInfo = events[i];\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, eventInfo.Name);\r\n\t\t\t\ttranslator.PushFixCSFunction(L, translator.methodWrapsCache.GetEventWrap(type, eventInfo.Name));\r\n\t\t\t\tbool is_static = (eventInfo.GetAddMethod(true) != null) ? eventInfo.GetAddMethod(true).IsStatic : eventInfo.GetRemoveMethod(true).IsStatic;\r\n\t\t\t\tLuaAPI.lua_rawset(L, is_static ? cls_field : obj_field);\r\n\t\t\t}\r\n\r\n\t\t\tList<PropertyInfo> items = new List<PropertyInfo>();\r\n\t\t\tPropertyInfo[] props = type.GetProperties(flag);\r\n\t\t\tfor (int i = 0; i < props.Length; ++i)\r\n\t\t\t{\r\n\t\t\t\tPropertyInfo prop = props[i];\r\n\t\t\t\tif (prop.GetIndexParameters().Length > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\titems.Add(prop);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tvar item_array = items.ToArray();\r\n\t\t\titem_getter = item_array.Length > 0 ? genItemGetter(type, item_array) : null;\r\n\t\t\titem_setter = item_array.Length > 0 ? genItemSetter(type, item_array) : null;\r\n\t\t\tMethodInfo[] methods = type.GetMethods(flag);\r\n\t\t\tif (access == BindingFlags.NonPublic)\r\n\t\t\t{\r\n\t\t\t\tmethods = type.GetMethods(flag | BindingFlags.Public).Join(methods, p => p.Name, q => q.Name, (p, q) => p).ToArray();\r\n\t\t\t}\r\n\t\t\tDictionary<MethodKey, List<MemberInfo>> pending_methods = new Dictionary<MethodKey, List<MemberInfo>>();\r\n\t\t\tfor (int i = 0; i < methods.Length; ++i)\r\n\t\t\t{\r\n\t\t\t\tMethodInfo method = methods[i];\r\n\t\t\t\tstring method_name = method.Name;\r\n\r\n\t\t\t\tMethodKey method_key = new MethodKey { Name = method_name, IsStatic = method.IsStatic };\r\n\t\t\t\tList<MemberInfo> overloads;\r\n\t\t\t\tif (pending_methods.TryGetValue(method_key, out overloads))\r\n\t\t\t\t{\r\n\t\t\t\t\toverloads.Add(method);\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//indexer\r\n\t\t\t\tif (method.IsSpecialName && ((method.Name == \"get_Item\" && method.GetParameters().Length == 1) || (method.Name == \"set_Item\" && method.GetParameters().Length == 2)))\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!method.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(string)))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif ((method_name.StartsWith(\"add_\") || method_name.StartsWith(\"remove_\")) && method.IsSpecialName)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (method_name.StartsWith(\"op_\") && method.IsSpecialName) // 操作符\r\n\t\t\t\t{\r\n\t\t\t\t\tif (InternalGlobals.supportOp.ContainsKey(method_name))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (overloads == null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toverloads = new List<MemberInfo>();\r\n\t\t\t\t\t\t\tpending_methods.Add(method_key, overloads);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toverloads.Add(method);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\telse if (method_name.StartsWith(\"get_\") && method.IsSpecialName && method.GetParameters().Length != 1) // getter of property\r\n\t\t\t\t{\r\n\t\t\t\t\tstring prop_name = method.Name.Substring(4);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, prop_name);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L, translator.methodWrapsCache._GenMethodWrap(method.DeclaringType, prop_name, new MethodBase[] { method }).Call);\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, method.IsStatic ? cls_getter : obj_getter);\r\n\t\t\t\t}\r\n\t\t\t\telse if (method_name.StartsWith(\"set_\") && method.IsSpecialName && method.GetParameters().Length != 2) // setter of property\r\n\t\t\t\t{\r\n\t\t\t\t\tstring prop_name = method.Name.Substring(4);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, prop_name);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L, translator.methodWrapsCache._GenMethodWrap(method.DeclaringType, prop_name, new MethodBase[] { method }).Call);\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, method.IsStatic ? cls_setter : obj_setter);\r\n\t\t\t\t}\r\n\t\t\t\telse if (method_name == \".ctor\" && method.IsConstructor)\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (overloads == null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toverloads = new List<MemberInfo>();\r\n\t\t\t\t\t\tpending_methods.Add(method_key, overloads);\r\n\t\t\t\t\t}\r\n\t\t\t\t\toverloads.Add(method);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\r\n\t\t\tIEnumerable<MethodInfo> extend_methods = GetExtensionMethodsOf(type);\r\n\t\t\tif (extend_methods != null)\r\n\t\t\t{\r\n\t\t\t\tforeach (var extend_method in extend_methods)\r\n\t\t\t\t{\r\n\t\t\t\t\tMethodKey method_key = new MethodKey { Name = extend_method.Name, IsStatic = false };\r\n\t\t\t\t\tList<MemberInfo> overloads;\r\n\t\t\t\t\tif (pending_methods.TryGetValue(method_key, out overloads))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toverloads.Add(extend_method);\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toverloads = new List<MemberInfo>() { extend_method };\r\n\t\t\t\t\t\tpending_methods.Add(method_key, overloads);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tforeach (var kv in pending_methods)\r\n\t\t\t{\r\n\t\t\t\tif (kv.Key.Name.StartsWith(\"op_\")) // 操作符\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, InternalGlobals.supportOp[kv.Key.Name]);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L,\r\n\t\t\t\t\t\tnew LuaCSFunction(translator.methodWrapsCache._GenMethodWrap(type, kv.Key.Name, kv.Value.ToArray()).Call));\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, obj_meta);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, kv.Key.Name);\r\n\t\t\t\t\ttranslator.PushFixCSFunction(L,\r\n\t\t\t\t\t\tnew LuaCSFunction(translator.methodWrapsCache._GenMethodWrap(type, kv.Key.Name, kv.Value.ToArray()).Call));\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, kv.Key.IsStatic ? cls_field : obj_field);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static void loadUpvalue(RealStatePtr L, Type type, string metafunc, int index)\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, metafunc);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_rawget(L, -2);\r\n\t\t\tLuaAPI.lua_remove(L, -2);\r\n\t\t\tfor (int i = 1; i <= index; i++)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_getupvalue(L, -i, i);\r\n\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -1);\r\n\t\t\t\t\tLuaAPI.lua_setupvalue(L, -i - 2, i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (int i = 0; i < index; i++)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_remove(L, -2);\r\n\t\t\t}\r\n\t\t}\r\n\r\n        public static void RegisterEnumType(RealStatePtr L, Type type)\r\n        {\r\n            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n            foreach (var name in Enum.GetNames(type))\r\n            {\r\n                RegisterObject(L, translator, Utils.CLS_IDX, name, Enum.Parse(type, name));\r\n            }\r\n        }\r\n\r\n\r\n        public static void MakePrivateAccessible(RealStatePtr L, Type type)\r\n\t\t{\r\n            LuaAPI.lua_checkstack(L, 20);\r\n\r\n            int oldTop = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tLuaAPI.luaL_getmetatable(L, type.FullName);\r\n\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\tthrow new Exception(\"can not find the metatable for \" + type);\r\n\t\t\t}\r\n\t\t\tint obj_meta = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tLoadCSTable(L, type);\r\n\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\tthrow new Exception(\"can not find the class for \" + type);\r\n\t\t\t}\r\n\t\t\tint cls_field = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 2);\r\n\t\t\tint obj_getter = LuaAPI.lua_gettop(L);\r\n\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 1);\r\n\t\t\tint obj_field = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tloadUpvalue(L, type, LuaNewIndexsFieldName, 1);\r\n\t\t\tint obj_setter = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tloadUpvalue(L, type, LuaClassIndexsFieldName, 1);\r\n\t\t\tint cls_getter = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tloadUpvalue(L, type, LuaClassNewIndexsFieldName, 1);\r\n\t\t\tint cls_setter = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tLuaCSFunction item_getter;\r\n\t\t\tLuaCSFunction item_setter;\r\n\t\t\tmakeReflectionWrap(L, type, cls_field, cls_getter, cls_setter, obj_field, obj_getter, obj_setter, obj_meta,\r\n\t\t\t\tout item_getter, out item_setter, BindingFlags.NonPublic);\r\n\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\r\n\t\t\tforeach (var nested_type in type.GetNestedTypes(BindingFlags.NonPublic))\r\n\t\t\t{\r\n\t\t\t\tif ((!nested_type.IsAbstract() && typeof(Delegate).IsAssignableFrom(nested_type))\r\n\t\t\t\t\t|| nested_type.IsGenericTypeDefinition())\r\n\t\t\t\t{\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tObjectTranslatorPool.Instance.Find(L).TryDelayWrapLoader(L, nested_type);\r\n\t\t\t\tMakePrivateAccessible(L, nested_type);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t[MonoPInvokeCallback(typeof(LuaCSFunction))]\r\n\t\tinternal static int LazyReflectionCall(RealStatePtr L)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t\tType type;\r\n\t\t\t\ttranslator.Get(L, LuaAPI.xlua_upvalueindex(1), out type);\r\n\t\t\t\tLazyMemberTypes memberType = (LazyMemberTypes)LuaAPI.xlua_tointeger(L, LuaAPI.xlua_upvalueindex(2));\r\n\t\t\t\tstring memberName = LuaAPI.lua_tostring(L, LuaAPI.xlua_upvalueindex(3));\r\n\t\t\t\tbool isStatic = LuaAPI.lua_toboolean(L, LuaAPI.xlua_upvalueindex(4));\r\n\t\t\t\tLuaCSFunction wrap = null;\r\n\t\t\t\t//UnityEngine.Debug.Log(\">>>>> \" + type + \" \" + memberName);\r\n\r\n\t\t\t\tswitch (memberType)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase LazyMemberTypes.Method:\r\n\t\t\t\t\t\tvar members = type.GetMember(memberName);\r\n\t\t\t\t\t\tif (members == null || members.Length == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find \" + memberName + \" for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tIEnumerable<MemberInfo> methods = members;\r\n\t\t\t\t\t\tif (!isStatic)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tvar extensionMethods = GetExtensionMethodsOf(type);\r\n\t\t\t\t\t\t\tif (extensionMethods != null)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmethods = methods.Concat(extensionMethods.Where(m => m.Name == memberName).Cast<MemberInfo>());\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\twrap = new LuaCSFunction(translator.methodWrapsCache._GenMethodWrap(type, memberName, methods.ToArray()).Call);\r\n\t\t\t\t\t\tif (isStatic)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tLoadCSTable(L, type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find the meta info for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase LazyMemberTypes.FieldGet:\r\n\t\t\t\t\tcase LazyMemberTypes.FieldSet:\r\n\t\t\t\t\t\tvar field = type.GetField(memberName);\r\n\t\t\t\t\t\tif (field == null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find \" + memberName + \" for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (isStatic)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (memberType == LazyMemberTypes.FieldGet)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaClassIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaClassNewIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (memberType == LazyMemberTypes.FieldGet)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaNewIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\twrap = (memberType == LazyMemberTypes.FieldGet) ? genFieldGetter(type, field) : genFieldSetter(type, field);\r\n\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase LazyMemberTypes.PropertyGet:\r\n\t\t\t\t\tcase LazyMemberTypes.PropertySet:\r\n\t\t\t\t\t\tvar prop = type.GetProperty(memberName);\r\n\t\t\t\t\t\tif (prop == null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find \" + memberName + \" for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (isStatic)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (memberType == LazyMemberTypes.PropertyGet)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaClassIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaClassNewIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (memberType == LazyMemberTypes.PropertyGet)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tloadUpvalue(L, type, LuaNewIndexsFieldName, 1);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find the meta info for \" + type);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\twrap = translator.methodWrapsCache._GenMethodWrap(prop.DeclaringType, prop.Name, new MethodBase[] { (memberType == LazyMemberTypes.PropertyGet) ? prop.GetGetMethod() : prop.GetSetMethod() }).Call;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase LazyMemberTypes.Event:\r\n\t\t\t\t\t\tvar eventInfo = type.GetEvent(memberName);\r\n\t\t\t\t\t\tif (eventInfo == null)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find \" + memberName + \" for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (isStatic)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tLoadCSTable(L, type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tloadUpvalue(L, type, LuaIndexsFieldName, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"can not find the meta info for \" + type);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\twrap = translator.methodWrapsCache.GetEventWrap(type, eventInfo.Name);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\treturn LuaAPI.luaL_error(L, \"unsupport member type\" + memberType);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, memberName);\r\n\t\t\t\ttranslator.PushFixCSFunction(L, wrap);\r\n\t\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\treturn wrap(L);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\treturn LuaAPI.luaL_error(L, \"c# exception in LazyReflectionCall:\" + e);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static void ReflectionWrap(RealStatePtr L, Type type, bool privateAccessible)\r\n\t\t{\r\n            LuaAPI.lua_checkstack(L, 20);\r\n\r\n            int top_enter = LuaAPI.lua_gettop(L);\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\t//create obj meta table\r\n\t\t\tLuaAPI.luaL_getmetatable(L, type.FullName);\r\n\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\tLuaAPI.luaL_newmetatable(L, type.FullName);\r\n\t\t\t}\r\n\t\t\tLuaAPI.lua_pushlightuserdata(L, LuaAPI.xlua_tag());\r\n\t\t\tLuaAPI.lua_pushnumber(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tint obj_meta = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint cls_meta = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint obj_field = LuaAPI.lua_gettop(L);\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint obj_getter = LuaAPI.lua_gettop(L);\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint obj_setter = LuaAPI.lua_gettop(L);\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint cls_field = LuaAPI.lua_gettop(L);\r\n            //set cls_field to namespace\r\n            SetCSTable(L, type, cls_field);\r\n            //finish set cls_field to namespace\r\n            LuaAPI.lua_newtable(L);\r\n\t\t\tint cls_getter = LuaAPI.lua_gettop(L);\r\n\t\t\tLuaAPI.lua_newtable(L);\r\n\t\t\tint cls_setter = LuaAPI.lua_gettop(L);\r\n\r\n            LuaCSFunction item_getter;\r\n\t\t\tLuaCSFunction item_setter;\r\n\t\t\tmakeReflectionWrap(L, type, cls_field, cls_getter, cls_setter, obj_field, obj_getter, obj_setter, obj_meta,\r\n\t\t\t\tout item_getter, out item_setter, privateAccessible ? (BindingFlags.Public | BindingFlags.NonPublic) : BindingFlags.Public);\r\n\r\n\t\t\t// init obj metatable\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__gc\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L, translator.metaFunctions.GcMeta);\r\n\t\t\tLuaAPI.lua_rawset(L, obj_meta);\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__tostring\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L, translator.metaFunctions.ToStringMeta);\r\n\t\t\tLuaAPI.lua_rawset(L, obj_meta);\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__index\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, obj_field);\r\n\t\t\tLuaAPI.lua_pushvalue(L, obj_getter);\r\n\t\t\ttranslator.PushFixCSFunction(L, item_getter);\r\n\t\t\ttranslator.PushAny(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\tLuaAPI.gen_obj_indexer(L);\r\n\t\t\t//store in lua indexs function tables\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, obj_meta); // set __index\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__newindex\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, obj_setter);\r\n\t\t\ttranslator.PushFixCSFunction(L, item_setter);\r\n\t\t\ttranslator.Push(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\tLuaAPI.gen_obj_newindexer(L);\r\n\t\t\t//store in lua newindexs function tables\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, obj_meta); // set __newindex\r\n\t\t\t\t\t\t\t\t\t\t\t//finish init obj metatable\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"UnderlyingSystemType\");\r\n\t\t\ttranslator.PushAny(L, type);\r\n\t\t\tLuaAPI.lua_rawset(L, cls_field);\r\n\r\n\t\t\tif (type != null && type.IsEnum())\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"__CastFrom\");\r\n\t\t\t\ttranslator.PushFixCSFunction(L, genEnumCastFrom(type));\r\n\t\t\t\tLuaAPI.lua_rawset(L, cls_field);\r\n\t\t\t}\r\n\r\n\t\t\t//init class meta\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__index\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_getter);\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_field);\r\n\t\t\ttranslator.Push(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.gen_cls_indexer(L);\r\n\t\t\t//store in lua indexs function tables\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, cls_meta); // set __index \r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__newindex\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_setter);\r\n\t\t\ttranslator.Push(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.gen_cls_newindexer(L);\r\n\t\t\t//store in lua newindexs function tables\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, cls_meta); // set __newindex\r\n\r\n\t\t\tLuaCSFunction constructor = typeof(Delegate).IsAssignableFrom(type) ? translator.metaFunctions.DelegateCtor : translator.methodWrapsCache.GetConstructorWrap(type);\r\n\t\t\tif (constructor == null)\r\n\t\t\t{\r\n\t\t\t\tconstructor = (RealStatePtr LL) =>\r\n\t\t\t\t{\r\n\t\t\t\t\treturn LuaAPI.luaL_error(LL, \"No constructor for \" + type);\r\n\t\t\t\t};\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__call\");\r\n\t\t\ttranslator.PushFixCSFunction(L, constructor);\r\n\t\t\tLuaAPI.lua_rawset(L, cls_meta);\r\n\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_meta);\r\n\t\t\tLuaAPI.lua_setmetatable(L, cls_field);\r\n\r\n\t\t\tLuaAPI.lua_pop(L, 8);\r\n\r\n\t\t\tSystem.Diagnostics.Debug.Assert(top_enter == LuaAPI.lua_gettop(L));\r\n\t\t}\r\n\r\n\t\t//meta: -4, method:-3, getter: -2, setter: -1\r\n\t\tpublic static void BeginObjectRegister(Type type, RealStatePtr L, ObjectTranslator translator, int meta_count, int method_count, int getter_count,\r\n\t\t\tint setter_count, int type_id = -1)\r\n\t\t{\r\n\t\t\tif (type == null)\r\n\t\t\t{\r\n\t\t\t\tif (type_id == -1) throw new Exception(\"Fatal: must provide a type of type_id\");\r\n\t\t\t\tLuaAPI.xlua_rawgeti(L, LuaIndexes.LUA_REGISTRYINDEX, type_id);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.luaL_getmetatable(L, type.FullName);\r\n\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\t\tLuaAPI.luaL_newmetatable(L, type.FullName);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tLuaAPI.lua_pushlightuserdata(L, LuaAPI.xlua_tag());\r\n\t\t\tLuaAPI.lua_pushnumber(L, 1);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\r\n\t\t\tif ((type == null || !translator.HasCustomOp(type)) && type != typeof(decimal))\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"__gc\");\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, translator.metaFunctions.GcMeta);\r\n\t\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__tostring\");\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L, translator.metaFunctions.ToStringMeta);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\r\n\t\t\tif (method_count == 0)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_createtable(L, 0, method_count);\r\n\t\t\t}\r\n\r\n\t\t\tif (getter_count == 0)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_createtable(L, 0, getter_count);\r\n\t\t\t}\r\n\r\n\t\t\tif (setter_count == 0)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_createtable(L, 0, setter_count);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic int abs_idx(int top, int idx)\r\n\t\t{\r\n\t\t\treturn idx > 0 ? idx : top + idx + 1;\r\n\t\t}\r\n\r\n\t\tpublic const int OBJ_META_IDX = -4;\r\n\t\tpublic const int METHOD_IDX = -3;\r\n\t\tpublic const int GETTER_IDX = -2;\r\n\t\tpublic const int SETTER_IDX = -1;\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static void EndObjectRegister(Type type, RealStatePtr L, ObjectTranslator translator, CSharpWrapper csIndexer,\r\n            CSharpWrapper csNewIndexer, Type base_type, CSharpWrapper arrayIndexer, CSharpWrapper arrayNewIndexer)\r\n#else\r\n\t\tpublic static void EndObjectRegister(Type type, RealStatePtr L, ObjectTranslator translator, LuaCSFunction csIndexer,\r\n\t\t\tLuaCSFunction csNewIndexer, Type base_type, LuaCSFunction arrayIndexer, LuaCSFunction arrayNewIndexer)\r\n#endif\r\n\t\t{\r\n\t\t\tint top = LuaAPI.lua_gettop(L);\r\n\t\t\tint meta_idx = abs_idx(top, OBJ_META_IDX);\r\n\t\t\tint method_idx = abs_idx(top, METHOD_IDX);\r\n\t\t\tint getter_idx = abs_idx(top, GETTER_IDX);\r\n\t\t\tint setter_idx = abs_idx(top, SETTER_IDX);\r\n\r\n\t\t\t//begin index gen\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__index\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, method_idx);\r\n\t\t\tLuaAPI.lua_pushvalue(L, getter_idx);\r\n\r\n\t\t\tif (csIndexer == null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n#if GEN_CODE_MINIMIZE\r\n                translator.PushCSharpWrapper(L, csIndexer);\r\n#else\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, csIndexer);\r\n#endif\r\n\t\t\t}\r\n\r\n\t\t\ttranslator.Push(L, type == null ? base_type : type.BaseType());\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tif (arrayIndexer == null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n#if GEN_CODE_MINIMIZE\r\n                translator.PushCSharpWrapper(L, arrayIndexer);\r\n#else\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, arrayIndexer);\r\n#endif\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.gen_obj_indexer(L);\r\n\r\n\t\t\tif (type != null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, LuaIndexsFieldName);\r\n\t\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);//store in lua indexs function tables\r\n\t\t\t\ttranslator.Push(L, type);\r\n\t\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.lua_rawset(L, meta_idx);\r\n\t\t\t//end index gen\r\n\r\n\t\t\t//begin newindex gen\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__newindex\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, setter_idx);\r\n\r\n\t\t\tif (csNewIndexer == null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n#if GEN_CODE_MINIMIZE\r\n                translator.PushCSharpWrapper(L, csNewIndexer);\r\n#else\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, csNewIndexer);\r\n#endif\r\n\t\t\t}\r\n\r\n\t\t\ttranslator.Push(L, type == null ? base_type : type.BaseType());\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n\t\t\tif (arrayNewIndexer == null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n#if GEN_CODE_MINIMIZE\r\n                translator.PushCSharpWrapper(L, arrayNewIndexer);\r\n#else\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, arrayNewIndexer);\r\n#endif\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.gen_obj_newindexer(L);\r\n\r\n\t\t\tif (type != null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, LuaNewIndexsFieldName);\r\n\t\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);//store in lua newindexs function tables\r\n\t\t\t\ttranslator.Push(L, type);\r\n\t\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.lua_rawset(L, meta_idx);\r\n\t\t\t//end new index gen\r\n\t\t\tLuaAPI.lua_pop(L, 4);\r\n\t\t}\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static void RegisterFunc(RealStatePtr L, int idx, string name, CSharpWrapper func)\r\n        {\r\n            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n            idx = abs_idx(LuaAPI.lua_gettop(L), idx);\r\n            LuaAPI.xlua_pushasciistring(L, name);\r\n            translator.PushCSharpWrapper(L, func);\r\n            LuaAPI.lua_rawset(L, idx);\r\n        }\r\n#else\r\n\t\tpublic static void RegisterFunc(RealStatePtr L, int idx, string name, LuaCSFunction func)\r\n\t\t{\r\n\t\t\tidx = abs_idx(LuaAPI.lua_gettop(L), idx);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, name);\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L, func);\r\n\t\t\tLuaAPI.lua_rawset(L, idx);\r\n\t\t}\r\n#endif\r\n\r\n\t\tpublic static void RegisterLazyFunc(RealStatePtr L, int idx, string name, Type type, LazyMemberTypes memberType, bool isStatic)\r\n\t\t{\r\n\t\t\tidx = abs_idx(LuaAPI.lua_gettop(L), idx);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, name);\r\n\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\ttranslator.PushAny(L, type);\r\n\t\t\tLuaAPI.xlua_pushinteger(L, (int)memberType);\r\n\t\t\tLuaAPI.lua_pushstring(L, name);\r\n\t\t\tLuaAPI.lua_pushboolean(L, isStatic);\r\n\t\t\tLuaAPI.lua_pushstdcallcfunction(L, InternalGlobals.LazyReflectionWrap, 4);\r\n\t\t\tLuaAPI.lua_rawset(L, idx);\r\n\t\t}\r\n\r\n\t\tpublic static void RegisterObject(RealStatePtr L, ObjectTranslator translator, int idx, string name, object obj)\r\n\t\t{\r\n\t\t\tidx = abs_idx(LuaAPI.lua_gettop(L), idx);\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, name);\r\n\t\t\ttranslator.PushAny(L, obj);\r\n\t\t\tLuaAPI.lua_rawset(L, idx);\r\n\t\t}\r\n\r\n#if GEN_CODE_MINIMIZE\r\n        public static void BeginClassRegister(Type type, RealStatePtr L, CSharpWrapper creator, int class_field_count,\r\n            int static_getter_count, int static_setter_count)\r\n#else\r\n\t\tpublic static void BeginClassRegister(Type type, RealStatePtr L, LuaCSFunction creator, int class_field_count,\r\n\t\t\tint static_getter_count, int static_setter_count)\r\n#endif\r\n\t\t{\r\n\t\t\tObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);\r\n\t\t\tLuaAPI.lua_createtable(L, 0, class_field_count);\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"UnderlyingSystemType\");\r\n\t\t\ttranslator.PushAny(L, type);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\r\n\t\t\tint cls_table = LuaAPI.lua_gettop(L);\r\n\r\n\t\t\tSetCSTable(L, type, cls_table);\r\n\r\n\t\t\tLuaAPI.lua_createtable(L, 0, 3);\r\n\t\t\tint meta_table = LuaAPI.lua_gettop(L);\r\n\t\t\tif (creator != null)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, \"__call\");\r\n#if GEN_CODE_MINIMIZE\r\n                translator.PushCSharpWrapper(L, creator);\r\n#else\r\n\t\t\t\tLuaAPI.lua_pushstdcallcfunction(L, creator);\r\n#endif\r\n\t\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\t}\r\n\r\n\t\t\tif (static_getter_count == 0)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_createtable(L, 0, static_getter_count);\r\n\t\t\t}\r\n\r\n\t\t\tif (static_setter_count == 0)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.lua_createtable(L, 0, static_setter_count);\r\n\t\t\t}\r\n\t\t\tLuaAPI.lua_pushvalue(L, meta_table);\r\n\t\t\tLuaAPI.lua_setmetatable(L, cls_table);\r\n\t\t}\r\n\r\n\t\tpublic const int CLS_IDX = -4;\r\n\t\tpublic const int CLS_META_IDX = -3;\r\n\t\tpublic const int CLS_GETTER_IDX = -2;\r\n\t\tpublic const int CLS_SETTER_IDX = -1;\r\n\r\n\t\tpublic static void EndClassRegister(Type type, RealStatePtr L, ObjectTranslator translator)\r\n\t\t{\r\n\t\t\tint top = LuaAPI.lua_gettop(L);\r\n\t\t\tint cls_idx = abs_idx(top, CLS_IDX);\r\n\t\t\tint cls_getter_idx = abs_idx(top, CLS_GETTER_IDX);\r\n\t\t\tint cls_setter_idx = abs_idx(top, CLS_SETTER_IDX);\r\n\t\t\tint cls_meta_idx = abs_idx(top, CLS_META_IDX);\r\n\r\n\t\t\t//begin cls index\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__index\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_getter_idx);\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_idx);\r\n\t\t\ttranslator.Push(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.gen_cls_indexer(L);\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);//store in lua indexs function tables\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\r\n\t\t\tLuaAPI.lua_rawset(L, cls_meta_idx);\r\n\t\t\t//end cls index\r\n\r\n\t\t\t//begin cls newindex\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, \"__newindex\");\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_setter_idx);\r\n\t\t\ttranslator.Push(L, type.BaseType());\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\t\t\tLuaAPI.gen_cls_newindexer(L);\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, LuaClassNewIndexsFieldName);\r\n\t\t\tLuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);//store in lua newindexs function tables\r\n\t\t\ttranslator.Push(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, -3);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\r\n\t\t\tLuaAPI.lua_rawset(L, cls_meta_idx);\r\n\t\t\t//end cls newindex\r\n\r\n\t\t\tLuaAPI.lua_pop(L, 4);\r\n\t\t}\r\n\r\n\t\tstatic List<string> getPathOfType(Type type)\r\n\t\t{\r\n\t\t\tList<string> path = new List<string>();\r\n\r\n\t\t\tif (type.Namespace != null)\r\n\t\t\t{\r\n\t\t\t\tpath.AddRange(type.Namespace.Split(new char[] { '.' }));\r\n\t\t\t}\r\n\r\n\t\t\tstring class_name = type.ToString().Substring(type.Namespace == null ? 0 : type.Namespace.Length + 1);\r\n\r\n\t\t\tif (type.IsNested)\r\n\t\t\t{\r\n\t\t\t\tpath.AddRange(class_name.Split(new char[] { '+' }));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tpath.Add(class_name);\r\n\t\t\t}\r\n\t\t\treturn path;\r\n\t\t}\r\n\r\n\t\tpublic static void LoadCSTable(RealStatePtr L, Type type)\r\n\t\t{\r\n\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n            LuaAPI.xlua_pushasciistring(L, LuaEnv.CSHARP_NAMESPACE);\r\n            LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n            List<string> path = getPathOfType(type);\r\n\r\n\t\t\tfor (int i = 0; i < path.Count; ++i)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, path[i]);\r\n\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tif (!LuaAPI.lua_istable(L, -1) && i < path.Count - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t\tLuaAPI.lua_pushnil(L);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_remove(L, -2);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static void SetCSTable(RealStatePtr L, Type type, int cls_table)\r\n\t\t{\r\n\t\t\tint oldTop = LuaAPI.lua_gettop(L);\r\n\t\t\tcls_table = abs_idx(oldTop, cls_table);\r\n            LuaAPI.xlua_pushasciistring(L, LuaEnv.CSHARP_NAMESPACE);\r\n            LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n\r\n            List<string> path = getPathOfType(type);\r\n\r\n\t\t\tfor (int i = 0; i < path.Count - 1; ++i)\r\n\t\t\t{\r\n\t\t\t\tLuaAPI.xlua_pushasciistring(L, path[i]);\r\n\t\t\t\tif (0 != LuaAPI.xlua_pgettable(L, -2))\r\n\t\t\t\t{\r\n\t\t\t\t\tvar err = LuaAPI.lua_tostring(L, -1);\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t\tthrow new Exception(\"SetCSTable for [\" + type + \"] error: \" + err);\r\n\t\t\t\t}\r\n\t\t\t\tif (LuaAPI.lua_isnil(L, -1))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t\t\t\tLuaAPI.lua_createtable(L, 0, 0);\r\n\t\t\t\t\tLuaAPI.xlua_pushasciistring(L, path[i]);\r\n\t\t\t\t\tLuaAPI.lua_pushvalue(L, -2);\r\n\t\t\t\t\tLuaAPI.lua_rawset(L, -4);\r\n\t\t\t\t}\r\n\t\t\t\telse if (!LuaAPI.lua_istable(L, -1))\r\n\t\t\t\t{\r\n\t\t\t\t\tLuaAPI.lua_settop(L, oldTop);\r\n\t\t\t\t\tthrow new Exception(\"SetCSTable for [\" + type + \"] error: ancestors is not a table!\");\r\n\t\t\t\t}\r\n\t\t\t\tLuaAPI.lua_remove(L, -2);\r\n\t\t\t}\r\n\r\n\t\t\tLuaAPI.xlua_pushasciistring(L, path[path.Count - 1]);\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_table);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\r\n            LuaAPI.xlua_pushasciistring(L, LuaEnv.CSHARP_NAMESPACE);\r\n            LuaAPI.lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);\r\n            ObjectTranslatorPool.Instance.Find(L).PushAny(L, type);\r\n\t\t\tLuaAPI.lua_pushvalue(L, cls_table);\r\n\t\t\tLuaAPI.lua_rawset(L, -3);\r\n\t\t\tLuaAPI.lua_pop(L, 1);\r\n\t\t}\r\n\r\n\t\tpublic const string LuaIndexsFieldName = \"LuaIndexs\";\r\n\r\n\t\tpublic const string LuaNewIndexsFieldName = \"LuaNewIndexs\";\r\n\r\n\t\tpublic const string LuaClassIndexsFieldName = \"LuaClassIndexs\";\r\n\r\n\t\tpublic const string LuaClassNewIndexsFieldName = \"LuaClassNewIndexs\";\r\n\r\n\t\tpublic static bool IsParamsMatch(MethodInfo delegateMethod, MethodInfo bridgeMethod)\r\n\t\t{\r\n\t\t\tif (delegateMethod == null || bridgeMethod == null)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tif (delegateMethod.ReturnType != bridgeMethod.ReturnType)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tParameterInfo[] delegateParams = delegateMethod.GetParameters();\r\n\t\t\tParameterInfo[] bridgeParams = bridgeMethod.GetParameters();\r\n\t\t\tif (delegateParams.Length != bridgeParams.Length)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\r\n\t\t\tfor (int i = 0; i < delegateParams.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tif (delegateParams[i].ParameterType != bridgeParams[i].ParameterType || delegateParams[i].IsOut != bridgeParams[i].IsOut)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n            var lastPos = delegateParams.Length - 1;\r\n            return lastPos < 0 || delegateParams[lastPos].IsDefined(typeof(ParamArrayAttribute), false) == bridgeParams[lastPos].IsDefined(typeof(ParamArrayAttribute), false);\r\n\t\t}\r\n\r\n\t\tpublic static bool IsSupportedMethod(MethodInfo method)\r\n\t\t{\r\n\t\t\tif (!method.ContainsGenericParameters)\r\n\t\t\t\treturn true;\r\n\t\t\tvar methodParameters = method.GetParameters();\r\n\t\t\tvar returnType = method.ReturnType;\r\n\t\t\tvar hasValidGenericParameter = false;\r\n\t\t\tvar returnTypeValid = !returnType.IsGenericParameter;\r\n\t\t\tfor (var i = 0; i < methodParameters.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tvar parameterType = methodParameters[i].ParameterType;\r\n\t\t\t\tif (parameterType.IsGenericParameter)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar parameterConstraints = parameterType.GetGenericParameterConstraints();\r\n\t\t\t\t\tif (parameterConstraints.Length == 0) return false;\r\n\t\t\t\t\tforeach (var parameterConstraint in parameterConstraints)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!parameterConstraint.IsClass() || (parameterConstraint == typeof(ValueType)))\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\thasValidGenericParameter = true;\r\n\t\t\t\t\tif (!returnTypeValid)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (parameterType == returnType)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturnTypeValid = true;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn hasValidGenericParameter && returnTypeValid;\r\n\t\t}\r\n\r\n\t\tpublic static MethodInfo MakeGenericMethodWithConstraints(MethodInfo method)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tvar genericArguments = method.GetGenericArguments();\r\n\t\t\t\tvar constraintedArgumentTypes = new Type[genericArguments.Length];\r\n\t\t\t\tfor (var i = 0; i < genericArguments.Length; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tvar argumentType = genericArguments[i];\r\n\t\t\t\t\tvar parameterConstraints = argumentType.GetGenericParameterConstraints();\r\n\t\t\t\t\tconstraintedArgumentTypes[i] = parameterConstraints[0];\r\n\t\t\t\t}\r\n\t\t\t\treturn method.MakeGenericMethod(constraintedArgumentTypes);\r\n\t\t\t}\r\n\t\t\tcatch (Exception)\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static Type getExtendedType(MethodInfo method)\r\n\t\t{\r\n\t\t\tvar type = method.GetParameters()[0].ParameterType;\r\n\t\t\tif (!type.IsGenericParameter)\r\n\t\t\t\treturn type;\r\n\t\t\tvar parameterConstraints = type.GetGenericParameterConstraints();\r\n\t\t\tif (parameterConstraints.Length == 0)\r\n\t\t\t\tthrow new InvalidOperationException();\r\n\r\n\t\t\tvar firstParameterConstraint = parameterConstraints[0];\r\n\t\t\tif (!firstParameterConstraint.IsClass())\r\n\t\t\t\tthrow new InvalidOperationException();\r\n\t\t\treturn firstParameterConstraint;\r\n\t\t}\r\n\r\n\t\tpublic static bool IsStaticPInvokeCSFunction(LuaCSFunction csFunction)\r\n\t\t{\r\n#if UNITY_WSA && !UNITY_EDITOR\r\n            return csFunction.GetMethodInfo().IsStatic && csFunction.GetMethodInfo().GetCustomAttribute<MonoPInvokeCallbackAttribute>() != null;\r\n#else\r\n\t\t\treturn csFunction.Method.IsStatic && Attribute.IsDefined(csFunction.Method, typeof(MonoPInvokeCallbackAttribute));\r\n#endif\r\n\t\t}\r\n\r\n\t\tpublic static bool IsPublic(Type type)\r\n\t\t{\r\n\t\t\tif (type.IsNested)\r\n\t\t\t{\r\n\t\t\t\tif (!type.IsNestedPublic()) return false;\r\n\t\t\t\treturn IsPublic(type.DeclaringType);\r\n\t\t\t}\r\n\t\t\tif (type.IsGenericType())\r\n\t\t\t{\r\n\t\t\t\tvar gas = type.GetGenericArguments();\r\n\t\t\t\tfor (int i = 0; i < gas.Length; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!IsPublic(gas[i]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn type.IsPublic();\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Src/Utils.cs.meta",
    "content": "fileFormatVersion: 2\nguid: d9c14a5b76adb7d41926526af904beda\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Src.meta",
    "content": "fileFormatVersion: 2\nguid: ac2f50d02ed9ec24b8fcc1921bfb244c\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/CSharpCallLua/CSCallLua.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\n\r\nnamespace Tutorial\r\n{\r\n    public class CSCallLua : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n        string script = @\"\r\n        a = 1\r\n        b = 'hello world'\r\n        c = true\r\n\r\n        d = {\r\n           f1 = 12, f2 = 34, \r\n           1, 2, 3,\r\n           add = function(self, a, b) \r\n              print('d.add called')\r\n              return a + b \r\n           end\r\n        }\r\n\r\n        function e()\r\n            print('i am e')\r\n        end\r\n\r\n        function f(a, b)\r\n            print('a', a, 'b', b)\r\n            return 1, {f1 = 1024}\r\n        end\r\n        \r\n        function ret_e()\r\n            print('ret_e called')\r\n            return e\r\n        end\r\n    \";\r\n\r\n        public class DClass\r\n        {\r\n            public int f1;\r\n            public int f2;\r\n        }\r\n\r\n        [CSharpCallLua]\r\n        public interface ItfD\r\n        {\r\n            int f1 { get; set; }\r\n            int f2 { get; set; }\r\n            int add(int a, int b);\r\n        }\r\n\r\n        [CSharpCallLua]\r\n        public delegate int FDelegate(int a, string b, out DClass c);\r\n\r\n        [CSharpCallLua]\r\n        public delegate Action GetE();\r\n\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.DoString(script);\r\n\r\n            Debug.Log(\"_G.a = \" + luaenv.Global.Get<int>(\"a\"));\r\n            Debug.Log(\"_G.b = \" + luaenv.Global.Get<string>(\"b\"));\r\n            Debug.Log(\"_G.c = \" + luaenv.Global.Get<bool>(\"c\"));\r\n\r\n\r\n            DClass d = luaenv.Global.Get<DClass>(\"d\");//映射到有对应字段的class，by value\r\n            Debug.Log(\"_G.d = {f1=\" + d.f1 + \", f2=\" + d.f2 + \"}\");\r\n\r\n            Dictionary<string, double> d1 = luaenv.Global.Get<Dictionary<string, double>>(\"d\");//映射到Dictionary<string, double>，by value\r\n            Debug.Log(\"_G.d = {f1=\" + d1[\"f1\"] + \", f2=\" + d1[\"f2\"] + \"}, d.Count=\" + d1.Count);\r\n\r\n            List<double> d2 = luaenv.Global.Get<List<double>>(\"d\"); //映射到List<double>，by value\r\n            Debug.Log(\"_G.d.len = \" + d2.Count);\r\n\r\n            ItfD d3 = luaenv.Global.Get<ItfD>(\"d\"); //映射到interface实例，by ref，这个要求interface加到生成列表，否则会返回null，建议用法\r\n            d3.f2 = 1000;\r\n            Debug.Log(\"_G.d = {f1=\" + d3.f1 + \", f2=\" + d3.f2 + \"}\");\r\n            Debug.Log(\"_G.d:add(1, 2)=\" + d3.add(1, 2));\r\n\r\n            LuaTable d4 = luaenv.Global.Get<LuaTable>(\"d\");//映射到LuaTable，by ref\r\n            Debug.Log(\"_G.d = {f1=\" + d4.Get<int>(\"f1\") + \", f2=\" + d4.Get<int>(\"f2\") + \"}\");\r\n\r\n\r\n            Action e = luaenv.Global.Get<Action>(\"e\");//映射到一个delgate，要求delegate加到生成列表，否则返回null，建议用法\r\n            e();\r\n\r\n            FDelegate f = luaenv.Global.Get<FDelegate>(\"f\");\r\n            DClass d_ret;\r\n            int f_ret = f(100, \"John\", out d_ret);//lua的多返回值映射：从左往右映射到c#的输出参数，输出参数包括返回值，out参数，ref参数\r\n            Debug.Log(\"ret.d = {f1=\" + d_ret.f1 + \", f2=\" + d_ret.f2 + \"}, ret=\" + f_ret);\r\n\r\n            GetE ret_e = luaenv.Global.Get<GetE>(\"ret_e\");//delegate可以返回更复杂的类型，甚至是另外一个delegate\r\n            e = ret_e();\r\n            e();\r\n\r\n            LuaFunction d_e = luaenv.Global.Get<LuaFunction>(\"e\");\r\n            d_e.Call();\r\n\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Tutorial/CSharpCallLua/CSCallLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1460b2dff8acf954786a3365fa951084\ntimeCreated: 1455871072\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/CSharpCallLua/CSCallLua.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 0b0cb24da8f1e8746b57219f9cb3d794\ntimeCreated: 1455872284\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/CSharpCallLua.meta",
    "content": "fileFormatVersion: 2\nguid: 65e4ae2b615903c4d8797af604056ca7\nfolderAsset: yes\ntimeCreated: 1455871045\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/ByFile.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\n\r\nnamespace Tutorial\r\n{\r\n    public class ByFile : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.DoString(\"require 'byfile'\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/ByFile.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 1d426a45aa481124aaba409c3a9b3f7b\ntimeCreated: 1455706566\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/ByFile.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 645674efb2695c04eb519c16ceed1480\ntimeCreated: 1455708409\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/Resources/byfile.lua.txt",
    "content": "print('hello world')"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/Resources/byfile.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 4065bb64deb0d0447b29928194cc75d2\ntimeCreated: 1455708384\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 802519ecbf0a64d4fb8a54f353552b49\nfolderAsset: yes\ntimeCreated: 1455708380\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByFile.meta",
    "content": "fileFormatVersion: 2\nguid: 0f9154baf514c1746a0f18fcab0e30b6\nfolderAsset: yes\ntimeCreated: 1455708568\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByString/ByString.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\n\r\nnamespace Tutorial\r\n{\r\n    public class ByString : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.DoString(\"print('hello world')\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByString/ByString.cs.meta",
    "content": "fileFormatVersion: 2\nguid: cdd0c0173dd65494ba0f34e6e5a80606\ntimeCreated: 1455706265\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByString/ByString.unity.meta",
    "content": "fileFormatVersion: 2\nguid: d6763539a6ad6444f9367b462faec32a\ntimeCreated: 1455706550\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/ByString.meta",
    "content": "fileFormatVersion: 2\nguid: 5b2568198a0f5764f8a5ae8f44cc1157\nfolderAsset: yes\ntimeCreated: 1455706231\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/Loader/CustomLoader.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\n\r\nnamespace Tutorial\r\n{\r\n    public class CustomLoader : MonoBehaviour\r\n    {\r\n        LuaEnv luaenv = null;\r\n        // Use this for initialization\r\n        void Start()\r\n        {\r\n            luaenv = new LuaEnv();\r\n            luaenv.AddLoader((ref string filename) =>\r\n            {\r\n                if (filename == \"InMemory\")\r\n                {\r\n                    string script = \"return {ccc = 9999}\";\r\n                    return System.Text.Encoding.UTF8.GetBytes(script);\r\n                }\r\n                return null;\r\n            });\r\n            luaenv.DoString(\"print('InMemory.ccc=', require('InMemory').ccc)\");\r\n        }\r\n\r\n        // Update is called once per frame\r\n        void Update()\r\n        {\r\n            if (luaenv != null)\r\n            {\r\n                luaenv.Tick();\r\n            }\r\n        }\r\n\r\n        void OnDestroy()\r\n        {\r\n            luaenv.Dispose();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/Loader/CustomLoader.cs.meta",
    "content": "fileFormatVersion: 2\nguid: dbc67289e99ffa2409f14928b273937c\ntimeCreated: 1455708700\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/Loader/CustomLoader.unity.meta",
    "content": "fileFormatVersion: 2\nguid: d51c6b9168a36a24fa5817d79e1277f0\ntimeCreated: 1455708953\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript/Loader.meta",
    "content": "fileFormatVersion: 2\nguid: 1b50cf5136461cb42989e927ae1e1267\nfolderAsset: yes\ntimeCreated: 1455706231\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LoadLuaScript.meta",
    "content": "fileFormatVersion: 2\nguid: 74a487ac941ce7b478428f413acc20f6\nfolderAsset: yes\ntimeCreated: 1455708477\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LuaCallCSharp/LuaCallCs.cs",
    "content": "﻿/*\r\n * Tencent is pleased to support the open source community by making xLua available.\r\n * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n * Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n * http://opensource.org/licenses/MIT\r\n * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing System;\r\nusing XLua;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Tutorial\r\n{\r\n\t[LuaCallCSharp]\r\n\tpublic class BaseClass\r\n\t{\r\n\t\tpublic static void BSFunc()\r\n\t\t{\r\n\t\t\tDebug.Log(\"Derived Static Func, BSF = \" + BSF);\r\n\t\t}\r\n\r\n\t\tpublic static int BSF = 1;\r\n\r\n\t\tpublic void BMFunc()\r\n\t\t{\r\n\t\t\tDebug.Log(\"Derived Member Func, BMF = \" + BMF);\r\n\t\t}\r\n\r\n\t\tpublic int BMF { get; set; }\r\n\t}\r\n\r\n\tpublic struct Param1\r\n\t{\r\n\t\tpublic int x;\r\n\t\tpublic string y;\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic enum TestEnum\r\n\t{\r\n\t\tE1,\r\n\t\tE2\r\n\t}\r\n\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class DerivedClass : BaseClass\r\n\t{\r\n\t\t[LuaCallCSharp]\r\n\t\tpublic enum TestEnumInner\r\n\t\t{\r\n\t\t\tE3,\r\n\t\t\tE4\r\n\t\t}\r\n\r\n\t\tpublic void DMFunc()\r\n\t\t{\r\n\t\t\tDebug.Log(\"Derived Member Func, DMF = \" + DMF);\r\n\t\t}\r\n\r\n\t\tpublic int DMF { get; set; }\r\n\r\n\t\tpublic double ComplexFunc(Param1 p1, ref int p2, out string p3, Action luafunc, out Action csfunc)\r\n\t\t{\r\n\t\t\tDebug.Log(\"P1 = {x=\" + p1.x + \",y=\" + p1.y + \"},p2 = \" + p2);\r\n\t\t\tluafunc();\r\n\t\t\tp2 = p2 * p1.x;\r\n\t\t\tp3 = \"hello \" + p1.y;\r\n\t\t\tcsfunc = () =>\r\n\t\t\t{\r\n\t\t\t\tDebug.Log(\"csharp callback invoked!\");\r\n\t\t\t};\r\n\t\t\treturn 1.23;\r\n\t\t}\r\n\r\n\t\tpublic void TestFunc(int i)\r\n\t\t{\r\n\t\t\tDebug.Log(\"TestFunc(int i)\");\r\n\t\t}\r\n\r\n\t\tpublic void TestFunc(string i)\r\n\t\t{\r\n\t\t\tDebug.Log(\"TestFunc(string i)\");\r\n\t\t}\r\n\r\n\t\tpublic static DerivedClass operator +(DerivedClass a, DerivedClass b)\r\n\t\t{\r\n            DerivedClass ret = new DerivedClass();\r\n\t\t\tret.DMF = a.DMF + b.DMF;\r\n\t\t\treturn ret;\r\n\t\t}\r\n\r\n\t\tpublic void DefaultValueFunc(int a = 100, string b = \"cccc\", string c = null)\r\n\t\t{\r\n\t\t\tUnityEngine.Debug.Log(\"DefaultValueFunc: a=\" + a + \",b=\" + b + \",c=\" + c);\r\n\t\t}\r\n\r\n\t\tpublic void VariableParamsFunc(int a, params string[] strs)\r\n\t\t{\r\n\t\t\tUnityEngine.Debug.Log(\"VariableParamsFunc: a =\" + a);\r\n\t\t\tforeach (var str in strs)\r\n\t\t\t{\r\n\t\t\t\tUnityEngine.Debug.Log(\"str:\" + str);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic TestEnum EnumTestFunc(TestEnum e)\r\n\t\t{\r\n\t\t\tDebug.Log(\"EnumTestFunc: e=\" + e);\r\n\t\t\treturn TestEnum.E2;\r\n\t\t}\r\n\r\n\t\tpublic Action<string> TestDelegate = (param) =>\r\n\t\t{\r\n\t\t\tDebug.Log(\"TestDelegate in c#:\" + param);\r\n\t\t};\r\n\r\n\t\tpublic event Action TestEvent;\r\n\r\n\t\tpublic void CallEvent()\r\n\t\t{\r\n\t\t\tTestEvent();\r\n\t\t}\r\n\r\n\t\tpublic ulong TestLong(long n)\r\n\t\t{\r\n\t\t\treturn (ulong)(n + 1);\r\n\t\t}\r\n\r\n\t\tclass InnerCalc : ICalc\r\n\t\t{\r\n\t\t\tpublic int add(int a, int b)\r\n\t\t\t{\r\n\t\t\t\treturn a + b;\r\n\t\t\t}\r\n\r\n\t\t\tpublic int id = 100;\r\n\t\t}\r\n\r\n\t\tpublic ICalc GetCalc()\r\n\t\t{\r\n\t\t\treturn new InnerCalc();\r\n\t\t}\r\n\r\n\t\tpublic void GenericMethod<T>()\r\n\t\t{\r\n\t\t\tDebug.Log(\"GenericMethod<\" + typeof(T) + \">\");\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic interface ICalc\r\n\t{\r\n\t\tint add(int a, int b);\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic static class DerivedClassExtensions\r\n    {\r\n\t\tpublic static int GetSomeData(this DerivedClass obj)\r\n\t\t{\r\n\t\t\tDebug.Log(\"GetSomeData ret = \" + obj.DMF);\r\n\t\t\treturn obj.DMF;\r\n\t\t}\r\n\r\n\t\tpublic static int GetSomeBaseData(this BaseClass obj)\r\n\t\t{\r\n\t\t\tDebug.Log(\"GetSomeBaseData ret = \" + obj.BMF);\r\n\t\t\treturn obj.BMF;\r\n\t\t}\r\n\r\n\t\tpublic static void GenericMethodOfString(this DerivedClass obj)\r\n\t\t{\r\n\t\t\tobj.GenericMethod<string>();\r\n\t\t}\r\n\t}\r\n}\r\n\r\npublic class LuaCallCs : MonoBehaviour\r\n{\r\n\tLuaEnv luaenv = null;\r\n\tstring script = @\"\r\n        function demo()\r\n            --new C#对象\r\n            local newGameObj = CS.UnityEngine.GameObject()\r\n            local newGameObj2 = CS.UnityEngine.GameObject('helloworld')\r\n            print(newGameObj, newGameObj2)\r\n        \r\n            --访问静态属性，方法\r\n            local GameObject = CS.UnityEngine.GameObject\r\n            print('UnityEngine.Time.deltaTime:', CS.UnityEngine.Time.deltaTime) --读静态属性\r\n            CS.UnityEngine.Time.timeScale = 0.5 --写静态属性\r\n            print('helloworld', GameObject.Find('helloworld')) --静态方法调用\r\n\r\n            --访问成员属性，方法\r\n            local DerivedClass = CS.Tutorial.DerivedClass\r\n            local testobj = DerivedClass()\r\n            testobj.DMF = 1024--设置成员属性\r\n            print(testobj.DMF)--读取成员属性\r\n            testobj:DMFunc()--成员方法\r\n\r\n            --基类属性，方法\r\n            print(DerivedClass.BSF)--读基类静态属性\r\n            DerivedClass.BSF = 2048--写基类静态属性\r\n            DerivedClass.BSFunc();--基类静态方法\r\n            print(testobj.BMF)--读基类成员属性\r\n            testobj.BMF = 4096--写基类成员属性\r\n            testobj:BMFunc()--基类方法调用\r\n\r\n            --复杂方法调用\r\n            local ret, p2, p3, csfunc = testobj:ComplexFunc({x=3, y = 'john'}, 100, function()\r\n               print('i am lua callback')\r\n            end)\r\n            print('ComplexFunc ret:', ret, p2, p3, csfunc)\r\n            csfunc()\r\n\r\n            --重载方法调用\r\n            testobj:TestFunc(100)\r\n            testobj:TestFunc('hello')\r\n\r\n            --操作符\r\n            local testobj2 = DerivedClass()\r\n            testobj2.DMF = 2048\r\n            print('(testobj + testobj2).DMF = ', (testobj + testobj2).DMF)\r\n\r\n            --默认值\r\n            testobj:DefaultValueFunc(1)\r\n            testobj:DefaultValueFunc(3, 'hello', 'john')\r\n\r\n            --可变参数\r\n            testobj:VariableParamsFunc(5, 'hello', 'john')\r\n\r\n            --Extension methods\r\n            print(testobj:GetSomeData()) \r\n            print(testobj:GetSomeBaseData()) --访问基类的Extension methods\r\n            testobj:GenericMethodOfString()  --通过Extension methods实现访问泛化方法\r\n\r\n            --枚举类型\r\n            local e = testobj:EnumTestFunc(CS.Tutorial.TestEnum.E1)\r\n            print(e, e == CS.Tutorial.TestEnum.E2)\r\n            print(CS.Tutorial.TestEnum.__CastFrom(1), CS.Tutorial.TestEnum.__CastFrom('E1'))\r\n            print(CS.Tutorial.DerivedClass.TestEnumInner.E3)\r\n            assert(CS.Tutorial.BaseClass.TestEnumInner == nil)\r\n\r\n            --Delegate\r\n            testobj.TestDelegate('hello') --直接调用\r\n            local function lua_delegate(str)\r\n                print('TestDelegate in lua:', str)\r\n            end\r\n            testobj.TestDelegate = lua_delegate + testobj.TestDelegate --combine，这里演示的是C#delegate作为右值，左值也支持\r\n            testobj.TestDelegate('hello')\r\n            testobj.TestDelegate = testobj.TestDelegate - lua_delegate --remove\r\n            testobj.TestDelegate('hello')\r\n\r\n            --事件\r\n            local function lua_event_callback1() print('lua_event_callback1') end\r\n            local function lua_event_callback2() print('lua_event_callback2') end\r\n            testobj:TestEvent('+', lua_event_callback1)\r\n            testobj:CallEvent()\r\n            testobj:TestEvent('+', lua_event_callback2)\r\n            testobj:CallEvent()\r\n            testobj:TestEvent('-', lua_event_callback1)\r\n            testobj:CallEvent()\r\n            testobj:TestEvent('-', lua_event_callback2)\r\n\r\n            --64位支持\r\n            local l = testobj:TestLong(11)\r\n            print(type(l), l, l + 100, 10000 + l)\r\n\r\n            --typeof\r\n            newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))\r\n\r\n            --cast\r\n            local calc = testobj:GetCalc()\r\n            print('assess instance of InnerCalc via reflection', calc:add(1, 2))\r\n            assert(calc.id == 100)\r\n            cast(calc, typeof(CS.Tutorial.ICalc))\r\n            print('cast to interface ICalc', calc:add(1, 2))\r\n            assert(calc.id == nil)\r\n       end\r\n\r\n       demo()\r\n\r\n       --协程下使用\r\n       local co = coroutine.create(function()\r\n           print('------------------------------------------------------')\r\n           demo()\r\n       end)\r\n       assert(coroutine.resume(co))\r\n    \";\r\n\r\n\t// Use this for initialization\r\n\tvoid Start()\r\n\t{\r\n\t\tluaenv = new LuaEnv();\r\n\t\tluaenv.DoString(script);\r\n\t}\r\n\r\n\t// Update is called once per frame\r\n\tvoid Update()\r\n\t{\r\n\t\tif (luaenv != null)\r\n\t\t{\r\n\t\t\tluaenv.Tick();\r\n\t\t}\r\n\t}\r\n\r\n\tvoid OnDestroy()\r\n\t{\r\n\t\tluaenv.Dispose();\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Assets/XLua/Tutorial/LuaCallCSharp/LuaCallCs.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 567af7ecaa3d5994c97448357665421b\ntimeCreated: 1456111221\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LuaCallCSharp/LuaCallCs.unity.meta",
    "content": "fileFormatVersion: 2\nguid: d5a67740111b6144d874577073176b35\ntimeCreated: 1456111594\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial/LuaCallCSharp.meta",
    "content": "fileFormatVersion: 2\nguid: 058caabe60eee6042957d66b04c9a634\nfolderAsset: yes\ntimeCreated: 1456111197\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua/Tutorial.meta",
    "content": "fileFormatVersion: 2\nguid: 9f890146b0795ba41af8e4f78c481496\nfolderAsset: yes\ntimeCreated: 1455706231\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Assets/XLua.meta",
    "content": "fileFormatVersion: 2\nguid: 6d2d240998b7a9a44b7402136c946623\nfolderAsset: yes\nDefaultImporter:\n  userData: \n"
  },
  {
    "path": "General/LuaMemoryLeakChecker/LuaMemoryLeakChecker.cs",
    "content": "﻿using System;\r\n\r\nnamespace XLua.LuaDLL\r\n{\r\n    using System.Runtime.InteropServices;\r\n\r\n#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)\r\n    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r\n    public delegate void TableSizeReport(IntPtr p, int size);\r\n\r\n    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r\n    public delegate void ObjectRelationshipReport(IntPtr parent, IntPtr child, RelationshipType type, string key, double d, string key2);\r\n#else\r\n    public delegate void TableSizeReport(IntPtr p, int size);\r\n\r\n    public delegate void ObjectRelationshipReport(IntPtr parent, IntPtr child, RelationshipType type, string key, double d, string key2);\r\n#endif\r\n\r\n    public enum RelationshipType\r\n    {\r\n        TableValue = 1,\r\n        NumberKeyTableValue = 2,\r\n        KeyOfTable = 3,\r\n        Metatable = 4,\r\n        Upvalue = 5,\r\n    }\r\n\r\n    public partial class Lua\r\n    {\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_report_table_size(IntPtr L, TableSizeReport cb, int fast);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern void xlua_report_object_relationship(IntPtr L, ObjectRelationshipReport cb);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr xlua_registry_pointer(IntPtr L);\r\n\r\n        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]\r\n        public static extern IntPtr xlua_global_pointer(IntPtr L);\r\n    }\r\n}\r\n\r\nnamespace XLua\r\n{\r\n    using System.Collections.Generic;\r\n    using System.Text;\r\n    using System.Linq;\r\n\r\n    public static class LuaMemoryLeakChecker\r\n    {\r\n        const string UNKNOW_KEY = \"???\";\r\n        const string METATABLE_KEY = \"__metatable\";\r\n        const string KEY_OF_TABLE = \"!KEY!\";\r\n\r\n        public class Data\r\n        {\r\n            internal int Memroy = 0;\r\n            internal Dictionary<IntPtr, int> TableSizes = new Dictionary<IntPtr, int>();\r\n\r\n            public override string ToString()\r\n            {\r\n                StringBuilder sb = new StringBuilder();\r\n                sb.AppendFormat(\"memroy:{0}, table count:{1}\", Memroy, TableSizes.Count);\r\n                sb.AppendLine();\r\n\r\n                if (TableSizes.Count < 10)\r\n                {\r\n                    foreach (var kv in TableSizes)\r\n                    {\r\n                        sb.AppendLine(string.Format(\"table({0}) : {1}\", kv.Key, kv.Value));\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    sb.AppendLine(\"too much table...\");\r\n                }\r\n\r\n                return sb.ToString();\r\n            }\r\n\r\n            public int PotentialLeakCount { get { return TableSizes.Count; } }\r\n        }\r\n\r\n        static Data getSizeReport(LuaEnv env)\r\n        {\r\n            Data data = new Data();\r\n            data.Memroy = env.Memroy;\r\n\r\n            LuaDLL.Lua.xlua_report_table_size(env.L, (IntPtr p, int size) => {\r\n                data.TableSizes.Add(p, size);\r\n            }, 0);\r\n\r\n            return data;\r\n        }\r\n\r\n        struct RefInfo\r\n        {\r\n            public string Key;\r\n\r\n            public bool HasNext;\r\n\r\n            public IntPtr Parent;\r\n\r\n            public bool IsNumberKey;\r\n        }\r\n\r\n        static string makeKey(LuaDLL.RelationshipType type, string key, double d, string key2)\r\n        {\r\n            switch(type)\r\n            {\r\n                case LuaDLL.RelationshipType.TableValue:\r\n                    return key== null ? ((LuaTypes)(int)d).ToString() : key;\r\n                case LuaDLL.RelationshipType.NumberKeyTableValue:\r\n                    return string.Format(\"[{0}]\", d);\r\n                case LuaDLL.RelationshipType.KeyOfTable:\r\n                    return KEY_OF_TABLE;\r\n                case LuaDLL.RelationshipType.Metatable:\r\n                    return METATABLE_KEY;\r\n                case LuaDLL.RelationshipType.Upvalue:\r\n                    return string.Format(\"{0}:local {1}\", key, key2);\r\n            }\r\n            return UNKNOW_KEY;\r\n        }\r\n\r\n        static Dictionary<IntPtr, List<RefInfo>> getRelationship(LuaEnv env)\r\n        {\r\n            Dictionary<IntPtr, List<RefInfo>> result = new Dictionary<IntPtr, List<RefInfo>>();\r\n            int top = LuaDLL.Lua.lua_gettop(env.L);\r\n            IntPtr registryPointer = LuaDLL.Lua.xlua_registry_pointer(env.L);\r\n            IntPtr globalPointer = LuaDLL.Lua.xlua_global_pointer(env.L);\r\n\r\n            LuaDLL.Lua.xlua_report_object_relationship(env.L, (IntPtr parent, IntPtr child, LuaDLL.RelationshipType type, string key, double d, string key2) => {\r\n                List<RefInfo> infos;\r\n                try\r\n                {\r\n                    if (!result.TryGetValue(child, out infos))\r\n                    {\r\n                        infos = new List<RefInfo>();\r\n                        result.Add(child, infos);\r\n                    }\r\n                    string keyOfRef = makeKey(type, key, d, key2);\r\n\r\n                    bool hasNext = type != LuaDLL.RelationshipType.Upvalue;\r\n\r\n                    if (hasNext)\r\n                    {\r\n                        if (parent == registryPointer)\r\n                        {\r\n                            keyOfRef = \"_R.\" + keyOfRef;\r\n                            hasNext = false;\r\n                        }\r\n                        else if (parent == globalPointer)\r\n                        {\r\n                            keyOfRef = \"_G.\" + keyOfRef;\r\n                            hasNext = false;\r\n                        }\r\n                    }\r\n\r\n                    infos.Add(new RefInfo()\r\n                    {\r\n                        Key = keyOfRef,\r\n                        HasNext = hasNext,\r\n                        Parent = parent,\r\n                        IsNumberKey = type == LuaDLL.RelationshipType.NumberKeyTableValue,\r\n                    });\r\n                }\r\n                catch (Exception e)\r\n                {\r\n                    UnityEngine.Debug.LogError(e.Message);\r\n                }\r\n            });\r\n            LuaDLL.Lua.lua_settop(env.L, top);\r\n            return result;\r\n        }\r\n\r\n        public static Data StartMemoryLeakCheck(this LuaEnv env)\r\n        {\r\n            env.FullGc();\r\n            return getSizeReport(env);\r\n        }\r\n\r\n        static Data findGrowing(Data from, Data to)\r\n        {\r\n            Data result = new Data();\r\n            result.Memroy = to.Memroy;\r\n            bool keepEqual = to.Memroy <= from.Memroy;\r\n            foreach (var kv in to.TableSizes)\r\n            {\r\n                int oldSize;\r\n                if (from.TableSizes.TryGetValue(kv.Key, out oldSize) && (oldSize < kv.Value || (keepEqual && oldSize == kv.Value))) // exist table\r\n                {\r\n                    result.TableSizes.Add(kv.Key, kv.Value);\r\n                }\r\n            }\r\n            return result;\r\n        }\r\n\r\n        public static Data MemoryLeakCheck(this LuaEnv env, Data last)\r\n        {\r\n            env.FullGc();\r\n            return findGrowing(last, getSizeReport(env));\r\n        }\r\n\r\n        public static string MemoryLeakReport(this LuaEnv env, Data data, int maxLevel = 10)\r\n        {\r\n            env.FullGc();\r\n            var relationshipInfo = getRelationship(env);\r\n\r\n            StringBuilder sb = new StringBuilder();\r\n            sb.AppendLine(\"total memroy: \" + data.Memroy);\r\n            foreach(var kv in data.TableSizes)\r\n            {\r\n                List<RefInfo> infos;\r\n                if (!relationshipInfo.TryGetValue(kv.Key, out infos))\r\n                {\r\n                    continue;\r\n                }\r\n                List<string> paths = new List<string>();\r\n                for(int i = 0; i < maxLevel; i++)\r\n                {\r\n                    int pathCount = paths.Count;\r\n                    paths.AddRange(infos.Where(info => !info.HasNext).Select(info => info.Key));\r\n                    if ((paths.Count - pathCount) != infos.Count)\r\n                    {\r\n                        infos = infos.Where(info => info.HasNext)\r\n                            .SelectMany((info) =>\r\n                            {\r\n                                List<RefInfo> infosOfParent;\r\n                                if (!relationshipInfo.TryGetValue(info.Parent, out infosOfParent))\r\n                                {\r\n                                    return new List<RefInfo>();\r\n                                }\r\n\r\n                                return infosOfParent.Select(pinfo =>\r\n                                {\r\n                                    var parentkey = pinfo.Key;\r\n                                    return new RefInfo()\r\n                                    {\r\n                                        HasNext = pinfo.HasNext,\r\n                                        Key = string.Format(info.IsNumberKey ? \"{0}{1}\" : \"{0}.{1}\", pinfo.Key, info.Key),\r\n                                        Parent = pinfo.Parent,\r\n                                        IsNumberKey = pinfo.IsNumberKey,\r\n                                    };\r\n                                });\r\n                            }).ToList();\r\n                    }\r\n                    else\r\n                    {\r\n                        break;\r\n                    }\r\n                }\r\n\r\n                infos = infos.Where(info => info.HasNext).ToList();\r\n                if (infos.Count != 0)\r\n                {\r\n                    paths.AddRange(infos.Select(info => \"...\" + info.Key));\r\n                }\r\n                sb.AppendLine(string.Format(\"potential leak({0}) in {{{1}}}\", kv.Value, string.Join(\",\", paths.ToArray())));\r\n            }\r\n            return sb.ToString();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/LuaMemoryLeakChecker/LuaMemoryLeakCheckerTest.cs",
    "content": "﻿using UnityEngine;\r\nusing System;\r\nusing XLua;\r\n\r\npublic class LuaMemoryLeakCheckerTest : MonoBehaviour\r\n{\r\n    LuaEnv luaenv = new LuaEnv();\r\n    Action update;\r\n    LuaMemoryLeakChecker.Data data = null;\r\n\r\n    void Start()\r\n    {\r\n        luaenv.DoString(@\"\r\n           local local_leak = {}\r\n           global_leak = { a = {}}\r\n           --global_leak.a.b = global_leak\r\n\r\n           local no_leak = {}\r\n           \r\n           function make_leak1()\r\n               table.insert(local_leak, 1)\r\n               table.insert(global_leak, {})\r\n           end\r\n\r\n           -- 会不断创建并持有新table，但其实没泄漏\r\n           function innocent()\r\n               no_leak.a = {x = 1}\r\n               no_leak.b = {y = 1}\r\n           end\r\n        \", \"@leak1.lua\");\r\n\r\n        luaenv.DoString(@\"\r\n           local anthor_leak = {a = {{ b = {}}}}\r\n\r\n           function make_leak2()\r\n               table.insert(anthor_leak.a[1].b, 1)\r\n           end\r\n\r\n           local t = 1\r\n\r\n           slow_global_leak = {}\r\n\r\n           debug.getregistry()['ref_anthor_leak'] = anthor_leak\r\n           \r\n           function slow_leak()\r\n               if t == 40 then\r\n                   t = 0\r\n                   table.insert(slow_global_leak, {x = 0, y = 1})\r\n               else\r\n                   t = t + 1\r\n               end\r\n           end\r\n \r\n        \", \"@leak2.lua\");\r\n\r\n        luaenv.DoString(@\"\r\n            shutdown_fast_leak = false\r\n\r\n            function update()\r\n                 if not shutdown_fast_leak then\r\n                     make_leak1()\r\n                     make_leak2()\r\n                 end\r\n                 innocent()\r\n                 slow_leak()\r\n            end\r\n        \", \"@main.lua\");\r\n\r\n        luaenv.Global.Get(\"update\", out update);\r\n\r\n        data = luaenv.StartMemoryLeakCheck();\r\n        Debug.Log(\"Start, PotentialLeakCount:\" + data.PotentialLeakCount);\r\n    }\r\n\r\n    int tick = 0;\r\n\r\n    bool finished = false;\r\n\r\n    void Update()\r\n    {\r\n        if (!finished)\r\n        {\r\n            tick++;\r\n            update();\r\n            luaenv.Tick();\r\n\r\n            if (tick % 30 == 0)\r\n            {\r\n                data = luaenv.MemoryLeakCheck(data);\r\n                Debug.Log(\"Update, PotentialLeakCount:\" + data.PotentialLeakCount);\r\n            }\r\n\r\n            if (tick % 180 == 0)\r\n            {\r\n                Debug.Log(luaenv.MemoryLeakReport(data));\r\n\r\n                if (tick == 180)\r\n                {\r\n                    //假装解决了快速内存泄漏\r\n                    luaenv.Global.Set(\"shutdown_fast_leak\", true);\r\n                    //开启一个新的泄漏检测\r\n                    data = luaenv.StartMemoryLeakCheck();\r\n                }\r\n                else\r\n                {\r\n                    finished = true;\r\n                    Debug.Log(\"Finished\");\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    void OnDestroy()\r\n    {\r\n        update = null;\r\n        luaenv.Dispose();\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/README.md",
    "content": "## xLua通用版本\r\n\r\nxLua通用版本致力于在C#环境提供lua脚本支持。相比Unity版本，仅去掉了诸如print重定向到Console窗口，Unity专用的脚本加载器。其它的一切功能都保留。特性列表请看[这里](../Assets/XLua/Doc/features.md)。\r\n\r\n## 如何使用\r\n\r\n将XLua.Mini.dll放入工程，对应版本的xlua本地动态库放到能通过pinvoke加载的路径下（比如程序执行目录）。\r\n\r\n## 生成代码[可选]\r\n\r\nXLua.Mini.dll是通过反射来实现lua与C#间的交互，需要更高性能，可以通过生成代码获得。\r\n\r\n1、按教程[XLua的配置.doc](../Assets/XLua/Doc/XLua的配置.doc)配置好要生成的类型；\r\n\r\n2、重新编译后，用配套的工具XLuaGenerate对工程的编译结果（exe或者dll）执行代码生成：XLuaGenerate xxx.exe/xxx.dll，生成代码会放在当前目录下的Gen目录。\r\n\r\n3、新建一个和原来一样的工程，添加XLUA_GENERAL宏\r\n\r\n4、删除XLua.Mini.dll，加入XLua的配套源码包(发布包的Src目录)，加入步骤2的生成代码；\r\n\r\n5、这工程生成exe或者dll已经通过生成代码适配。\r\n\r\n## Hotfix\r\n\r\n对已经生成了代码的exe或者dll，用工具XLuaHotfixInject执行注入即可，Hotfix特性的详细使用请看[Hotfix操作指南](../Assets/XLua/Doc/hotfix.md)\r\n\r\n\r\n## 快速入门\r\n\r\n~~~csharp\r\n\r\nusing XLua;\r\n\r\npublic class XLuaTest\r\n{\r\n    public static void Main()\r\n    {\r\n        LuaEnv luaenv = new LuaEnv();\r\n        luaenv.DoString(\"CS.System.Console.WriteLine('hello world')\");\r\n        luaenv.Dispose();\r\n    }\r\n}\r\n\r\n~~~\r\n\r\n\r\n"
  },
  {
    "path": "General/Src/FilesSignature.cs",
    "content": "using System;\r\nusing System.IO;\r\nusing System.Security.Cryptography;\r\n\r\nnamespace XLua\r\n{\r\n    public class FilesSignature\r\n    {\r\n        static void usage()\r\n        {\r\n            Console.WriteLine(\"FilesSignature from_path to_path\");\r\n        }\r\n\r\n        static void doSignature(string from, string to, SHA1 sha, RSACryptoServiceProvider rsa)\r\n        {\r\n            if (!Directory.Exists(to))\r\n            {\r\n                Directory.CreateDirectory(to);\r\n            }\r\n            foreach (var filename in Directory.GetFiles(from, \"*.lua\"))\r\n            {\r\n                byte[] filecontent = File.ReadAllBytes(filename);\r\n                byte[] sig = rsa.SignData(filecontent, sha);\r\n                string sigFilePath = Path.Combine(to, Path.GetFileName(filename));\r\n                using (FileStream fs = new FileStream(sigFilePath, FileMode.Create))\r\n                {\r\n                    fs.Write(sig, 0, sig.Length);\r\n                    fs.Write(filecontent, 0, filecontent.Length);\r\n                    fs.Flush();\r\n                }\r\n            }\r\n            foreach (var dir in Directory.GetDirectories(from))\r\n            {\r\n                string newDir = Path.Combine(to, new DirectoryInfo(dir).Name);\r\n                doSignature(dir, newDir, sha, rsa);\r\n            }\r\n        }\r\n\r\n        public static void Main(string[] args)\r\n        {\r\n            if (!File.Exists(\"key_rsa\"))\r\n            {\r\n                Console.WriteLine(\"No key_rsa file found!\");\r\n                return;\r\n            }\r\n\r\n            if (args.Length != 2)\r\n            {\r\n                usage();\r\n                return;\r\n            }\r\n\r\n            SHA1 sha = new SHA1CryptoServiceProvider();\r\n            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();\r\n            rsa.FromXmlString(File.ReadAllText(\"key_rsa\"));\r\n            doSignature(args[0], args[1], sha, rsa);\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/Src/KeyPairsGen.cs",
    "content": "using System;\r\nusing System.IO;\r\nusing System.Security.Cryptography;\r\n\r\nnamespace XLua\r\n{\r\n    public class KeyPairsGen\r\n    {\r\n        \r\n        public static void Main(string[] args)\r\n        {\r\n            if (File.Exists(\"key_ras\") || File.Exists(\"key_ras.pub\"))\r\n            {\r\n                Console.WriteLine(\"key pairs existed!\");\r\n            }\r\n            var rsa = new RSACryptoServiceProvider();\r\n            File.WriteAllText(\"key_ras\", rsa.ToXmlString(true));\r\n            File.WriteAllText(\"key_ras.pub\", Convert.ToBase64String(rsa.ExportCspBlob(false)));\r\n        }\r\n    }\r\n}"
  },
  {
    "path": "General/Src/XLuaGenerate.cs",
    "content": "using System;\r\nusing System.Linq;\r\nusing System.Reflection;\r\nusing CSObjectWrapEditor;\r\nusing System.IO;\r\nusing System.Collections.Generic;\r\n\r\nnamespace XLua\r\n{\r\n    public class XLuaGenerate\r\n    {\r\n        public static void Useage()\r\n        {\r\n            Console.WriteLine(\"XLuaGenerate assmbly_path\");\r\n        }\r\n\r\n        public static void Main(string[] args)\r\n        {\r\n            if (args.Length == 0)\r\n            {\r\n                Useage();\r\n                return;\r\n            }\r\n\r\n            List<string> assemblyPathList = args.TakeWhile(path => \r\n                path.EndsWith(\".dll\", StringComparison.OrdinalIgnoreCase) ||\r\n                path.EndsWith(\".exe\", StringComparison.OrdinalIgnoreCase)).ToList();\r\n\r\n            if (args.Length > assemblyPathList.Count)\r\n            {\r\n                GeneratorConfig.common_path = args[assemblyPathList.Count];\r\n            }\r\n\r\n            if (args.Length > assemblyPathList.Count + 1)\r\n            {\r\n                List<string> search_paths = args.Skip(assemblyPathList.Count + 1).ToList();\r\n                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler((object sender, ResolveEventArgs rea) =>\r\n                {\r\n                    foreach (var search_path in search_paths)\r\n                    {\r\n                        string assemblyPath = Path.Combine(search_path, new AssemblyName(rea.Name).Name + \".dll\");\r\n                        if (File.Exists(assemblyPath))\r\n                        {\r\n                            return Assembly.Load(File.ReadAllBytes(assemblyPath));\r\n                        }\r\n                    }\r\n                    return null;\r\n                });\r\n            }\r\n\r\n            var allTypes = assemblyPathList.Select(path => Assembly.Load(File.ReadAllBytes(Path.GetFullPath(path))))\r\n                .SelectMany(assembly => assembly.GetTypes());\r\n            Generator.GenAll(new XLuaTemplates()\r\n            {\r\n                LuaClassWrap = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaClassWrap\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaClassWrap_tpl,\r\n                }, \r\n                LuaDelegateBridge = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaDelegateBridge\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaDelegateBridge_tpl,\r\n                },\r\n                LuaDelegateWrap = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaDelegateWrap\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaDelegateWrap_tpl,\r\n                },\r\n                LuaEnumWrap = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaEnumWrap\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaEnumWrap_tpl,\r\n                },\r\n                LuaInterfaceBridge = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaInterfaceBridge\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaInterfaceBridge_tpl,\r\n                },\r\n                LuaRegister = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaRegister\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaRegister_tpl,\r\n                },\r\n                LuaWrapPusher = new XLuaTemplate()\r\n                {\r\n                    name = \"LuaWrapPusher\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.LuaWrapPusher_tpl,\r\n                },\r\n                PackUnpack = new XLuaTemplate()\r\n                {\r\n                    name = \"PackUnpack\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.PackUnpack_tpl,\r\n                },\r\n                TemplateCommon = new XLuaTemplate()\r\n                {\r\n                    name = \"TemplateCommon\",\r\n                    text = global::XLuaGenerate.Src.XLuaTemplates.TemplateCommon_lua,\r\n                },\r\n            }, allTypes);\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/Src/XLuaHotfixInject.cs",
    "content": "using System;\r\nusing System.Linq;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Reflection;\r\n\r\nnamespace XLua\r\n{\r\n    public class XLuaHotfixInject\r\n    {\r\n        public static void Useage()\r\n        {\r\n            Console.WriteLine(\"XLuaHotfixInject assmbly_path id_map_file_path [cfg_assmbly2_path] [search_path1, search_path2 ...]\");\r\n        }\r\n\r\n        public static void Main(string[] args)\r\n        {\r\n            if (args.Length < 2)\r\n            {\r\n                Useage();\r\n                return;\r\n            }\r\n\r\n            try\r\n            {\r\n                var injectAssmblyPath = Path.GetFullPath(args[0]);\r\n                var xluaAssmblyPath = Path.GetFullPath(args[1]);\r\n                string cfg_append = null;\r\n                if (args.Length > 3)\r\n                {\r\n                    cfg_append = Path.GetFullPath(args[3]);\r\n                    if (!cfg_append.EndsWith(\".data\"))\r\n                    {\r\n                        cfg_append = null;\r\n                    }\r\n                }\r\n                AppDomain currentDomain = AppDomain.CurrentDomain;\r\n                List<string> search_paths = args.Skip(cfg_append == null ? 3 : 4).ToList();\r\n                currentDomain.AssemblyResolve += new ResolveEventHandler((object sender, ResolveEventArgs rea) =>\r\n                {\r\n                    foreach (var search_path in search_paths)\r\n                    {\r\n                        string assemblyPath = Path.Combine(search_path, new AssemblyName(rea.Name).Name + \".dll\");\r\n                        if (File.Exists(assemblyPath))\r\n                        {\r\n                            return Assembly.Load(File.ReadAllBytes(assemblyPath));\r\n                        }\r\n                    }\r\n                    return null;\r\n                });\r\n                var assembly = Assembly.Load(File.ReadAllBytes(injectAssmblyPath));\r\n                var hotfixCfg = new Dictionary<string, int>();\r\n                HotfixConfig.GetConfig(hotfixCfg, assembly.GetTypes());\r\n                if (cfg_append != null)\r\n                {\r\n                    using (BinaryReader reader = new BinaryReader(File.Open(cfg_append, FileMode.Open)))\r\n                    {\r\n                        int count = reader.ReadInt32();\r\n                        for(int i = 0; i < count; i++)\r\n                        {\r\n                            string k = reader.ReadString();\r\n                            int v = reader.ReadInt32();\r\n                            if (!hotfixCfg.ContainsKey(k))\r\n                            {\r\n                                hotfixCfg.Add(k, v);\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n                Hotfix.HotfixInject(injectAssmblyPath, xluaAssmblyPath, args.Skip(cfg_append == null ? 3 : 3), args[2], hotfixCfg);\r\n            }\r\n            catch(Exception e)\r\n            {\r\n                Console.WriteLine(\"Exception in hotfix inject: \" + e);\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/Src/XLuaTemplates.Designer.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <auto-generated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:4.0.30319.42000\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </auto-generated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace XLuaGenerate.Src {\r\n    using System;\r\n    \r\n    \r\n    /// <summary>\r\n    ///   A strongly-typed resource class, for looking up localized strings, etc.\r\n    /// </summary>\r\n    // This class was auto-generated by the StronglyTypedResourceBuilder\r\n    // class via a tool like ResGen or Visual Studio.\r\n    // To add or remove a member, edit your .ResX file then rerun ResGen\r\n    // with the /str option, or rebuild your VS project.\r\n    [global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Resources.Tools.StronglyTypedResourceBuilder\", \"4.0.0.0\")]\r\n    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]\r\n    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]\r\n    internal class XLuaTemplates {\r\n        \r\n        private static global::System.Resources.ResourceManager resourceMan;\r\n        \r\n        private static global::System.Globalization.CultureInfo resourceCulture;\r\n        \r\n        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\r\n        internal XLuaTemplates() {\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Returns the cached ResourceManager instance used by this class.\r\n        /// </summary>\r\n        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]\r\n        internal static global::System.Resources.ResourceManager ResourceManager {\r\n            get {\r\n                if (object.ReferenceEquals(resourceMan, null)) {\r\n                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(\"XLuaGenerate.Src.XLuaTemplates\", typeof(XLuaTemplates).Assembly);\r\n                    resourceMan = temp;\r\n                }\r\n                return resourceMan;\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Overrides the current thread's CurrentUICulture property for all\r\n        ///   resource lookups using this strongly typed resource class.\r\n        /// </summary>\r\n        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]\r\n        internal static global::System.Globalization.CultureInfo Culture {\r\n            get {\r\n                return resourceCulture;\r\n            }\r\n            set {\r\n                resourceCulture = value;\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using XLua;\r\n        ///using System.Collections.Generic;\r\n        ///&lt;%ForEachCsList(namespaces, function(namespace)%&gt;using &lt;%=namespace%&gt;;&lt;%end)%&gt;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///\r\n        ///local OpNameMap = {op_Addition = &quot;__AddMeta&quot;, op_Subtraction = &quot;__SubMeta&quot;, [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaClassWrap_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaClassWrap_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using System;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua\r\n        ///{\r\n        ///    public partial class DelegateBridge : DelegateBridgeBase\r\n        ///    {\r\n        ///\t\t&lt;%\r\n        ///\t\tForEachCsList(delegates_groups, function(delegates_group, group_idx)\r\n        ///\t\tlocal delegate = [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaDelegateBridge_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaDelegateBridge_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using XLua;\r\n        ///using System.Collections.Generic;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///\r\n        ///local parameters = delegate:GetParameters()\r\n        ///local in_num = CalcCsList(parameters, function(p) return p.IsIn or not p.IsOut end)\r\n        ///local out_num = CalcCsLis [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaDelegateWrap_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaDelegateWrap_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using XLua;\r\n        ///using System.Collections.Generic;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua.CSObjectWrap\r\n        ///{\r\n        ///    using Utils = XLua.Utils;\r\n        ///    &lt;%ForEachCsList(types, function(type)\r\n        ///\tlocal fields = g_enum_get_fields_flag and ty [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaEnumWrap_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaEnumWrap_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using XLua;\r\n        ///using System;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua.CSObjectWrap\r\n        ///{\r\n        ///    public class &lt;%=CSVariableName(type)%&gt;Bridge : LuaBase, &lt;%=CsFullTypeName(type)%&gt;\r\n        ///    {\r\n        ///\t    public static LuaBase __Create(int ref [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaInterfaceBridge_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaInterfaceBridge_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using System;\r\n        ///using System.Collections.Generic;\r\n        ///using System.Reflection;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua.CSObjectWrap\r\n        ///{\r\n        ///    public class XLua_Gen_Initer_Register__\r\n        ///\t{\r\n        ///\t    static XLua_Gen_Initer_Register__()\r\n        /// [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaRegister_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaRegister_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using System;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua\r\n        ///{\r\n        ///    public partial class ObjectTranslator\r\n        ///    {\r\n        ///        &lt;%if purevaluetypes.Count &gt; 0 then\r\n        ///        local init_class_name = &quot;IniterAdder&quot; .. CSVariableName(pureval [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string LuaWrapPusher_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"LuaWrapPusher_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to #if USE_UNI_LUA\r\n        ///using LuaAPI = UniLua.Lua;\r\n        ///using RealStatePtr = UniLua.ILuaState;\r\n        ///using LuaCSFunction = UniLua.CSharpFunctionDelegate;\r\n        ///#else\r\n        ///using LuaAPI = XLua.LuaDLL.Lua;\r\n        ///using RealStatePtr = System.IntPtr;\r\n        ///using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;\r\n        ///#endif\r\n        ///\r\n        ///using System;\r\n        ///&lt;%\r\n        ///require &quot;TemplateCommon&quot;\r\n        ///%&gt;\r\n        ///\r\n        ///namespace XLua\r\n        ///{\r\n        ///    public static partial class CopyByValue\r\n        ///    {\r\n        ///        &lt;%ForEachCsList(type_infos, function(type_info)\r\n        ///        local full_type_name = CsFullTypeName(type_info. [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string PackUnpack_tpl {\r\n            get {\r\n                return ResourceManager.GetString(\"PackUnpack_tpl\", resourceCulture);\r\n            }\r\n        }\r\n        \r\n        /// <summary>\r\n        ///   Looks up a localized string similar to -- Tencent is pleased to support the open source community by making xLua available.\r\n        ///-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n        ///-- Licensed under the MIT License (the &quot;License&quot;); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n        ///-- http://opensource.org/licenses/MIT\r\n        ///-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRA [rest of string was truncated]&quot;;.\r\n        /// </summary>\r\n        internal static string TemplateCommon_lua {\r\n            get {\r\n                return ResourceManager.GetString(\"TemplateCommon_lua\", resourceCulture);\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "General/Src/XLuaTemplates.resx",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<root>\r\n  <!-- \r\n    Microsoft ResX Schema \r\n    \r\n    Version 2.0\r\n    \r\n    The primary goals of this format is to allow a simple XML format \r\n    that is mostly human readable. The generation and parsing of the \r\n    various data types are done through the TypeConverter classes \r\n    associated with the data types.\r\n    \r\n    Example:\r\n    \r\n    ... ado.net/XML headers & schema ...\r\n    <resheader name=\"resmimetype\">text/microsoft-resx</resheader>\r\n    <resheader name=\"version\">2.0</resheader>\r\n    <resheader name=\"reader\">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>\r\n    <resheader name=\"writer\">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>\r\n    <data name=\"Name1\"><value>this is my long string</value><comment>this is a comment</comment></data>\r\n    <data name=\"Color1\" type=\"System.Drawing.Color, System.Drawing\">Blue</data>\r\n    <data name=\"Bitmap1\" mimetype=\"application/x-microsoft.net.object.binary.base64\">\r\n        <value>[base64 mime encoded serialized .NET Framework object]</value>\r\n    </data>\r\n    <data name=\"Icon1\" type=\"System.Drawing.Icon, System.Drawing\" mimetype=\"application/x-microsoft.net.object.bytearray.base64\">\r\n        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>\r\n        <comment>This is a comment</comment>\r\n    </data>\r\n                \r\n    There are any number of \"resheader\" rows that contain simple \r\n    name/value pairs.\r\n    \r\n    Each data row contains a name, and value. The row also contains a \r\n    type or mimetype. Type corresponds to a .NET class that support \r\n    text/value conversion through the TypeConverter architecture. \r\n    Classes that don't support this are serialized and stored with the \r\n    mimetype set.\r\n    \r\n    The mimetype is used for serialized objects, and tells the \r\n    ResXResourceReader how to depersist the object. This is currently not \r\n    extensible. For a given mimetype the value must be set accordingly:\r\n    \r\n    Note - application/x-microsoft.net.object.binary.base64 is the format \r\n    that the ResXResourceWriter will generate, however the reader can \r\n    read any of the formats listed below.\r\n    \r\n    mimetype: application/x-microsoft.net.object.binary.base64\r\n    value   : The object must be serialized with \r\n            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter\r\n            : and then encoded with base64 encoding.\r\n    \r\n    mimetype: application/x-microsoft.net.object.soap.base64\r\n    value   : The object must be serialized with \r\n            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter\r\n            : and then encoded with base64 encoding.\r\n\r\n    mimetype: application/x-microsoft.net.object.bytearray.base64\r\n    value   : The object must be serialized into a byte array \r\n            : using a System.ComponentModel.TypeConverter\r\n            : and then encoded with base64 encoding.\r\n    -->\r\n  <xsd:schema id=\"root\" xmlns=\"\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\r\n    <xsd:import namespace=\"http://www.w3.org/XML/1998/namespace\" />\r\n    <xsd:element name=\"root\" msdata:IsDataSet=\"true\">\r\n      <xsd:complexType>\r\n        <xsd:choice maxOccurs=\"unbounded\">\r\n          <xsd:element name=\"metadata\">\r\n            <xsd:complexType>\r\n              <xsd:sequence>\r\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" />\r\n              </xsd:sequence>\r\n              <xsd:attribute name=\"name\" use=\"required\" type=\"xsd:string\" />\r\n              <xsd:attribute name=\"type\" type=\"xsd:string\" />\r\n              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" />\r\n              <xsd:attribute ref=\"xml:space\" />\r\n            </xsd:complexType>\r\n          </xsd:element>\r\n          <xsd:element name=\"assembly\">\r\n            <xsd:complexType>\r\n              <xsd:attribute name=\"alias\" type=\"xsd:string\" />\r\n              <xsd:attribute name=\"name\" type=\"xsd:string\" />\r\n            </xsd:complexType>\r\n          </xsd:element>\r\n          <xsd:element name=\"data\">\r\n            <xsd:complexType>\r\n              <xsd:sequence>\r\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\r\n                <xsd:element name=\"comment\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"2\" />\r\n              </xsd:sequence>\r\n              <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" msdata:Ordinal=\"1\" />\r\n              <xsd:attribute name=\"type\" type=\"xsd:string\" msdata:Ordinal=\"3\" />\r\n              <xsd:attribute name=\"mimetype\" type=\"xsd:string\" msdata:Ordinal=\"4\" />\r\n              <xsd:attribute ref=\"xml:space\" />\r\n            </xsd:complexType>\r\n          </xsd:element>\r\n          <xsd:element name=\"resheader\">\r\n            <xsd:complexType>\r\n              <xsd:sequence>\r\n                <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\r\n              </xsd:sequence>\r\n              <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" />\r\n            </xsd:complexType>\r\n          </xsd:element>\r\n        </xsd:choice>\r\n      </xsd:complexType>\r\n    </xsd:element>\r\n  </xsd:schema>\r\n  <resheader name=\"resmimetype\">\r\n    <value>text/microsoft-resx</value>\r\n  </resheader>\r\n  <resheader name=\"version\">\r\n    <value>2.0</value>\r\n  </resheader>\r\n  <resheader name=\"reader\">\r\n    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r\n  </resheader>\r\n  <resheader name=\"writer\">\r\n    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r\n  </resheader>\r\n  <assembly alias=\"System.Windows.Forms\" name=\"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" />\r\n  <data name=\"LuaClassWrap_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaClassWrap.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaDelegateBridge_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateBridge.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaDelegateWrap_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateWrap.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaEnumWrap_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaEnumWrap.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaInterfaceBridge_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaInterfaceBridge.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaRegister_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaRegister.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"LuaWrapPusher_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaWrapPusher.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"PackUnpack_tpl\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\PackUnpack.tpl.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n  <data name=\"TemplateCommon_lua\" type=\"System.Resources.ResXFileRef, System.Windows.Forms\">\r\n    <value>..\\..\\Assets\\XLua\\Src\\Editor\\Template\\TemplateCommon.lua.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>\r\n  </data>\r\n</root>"
  },
  {
    "path": "General/Src/XLuaTest.cs",
    "content": "using XLua;\r\nusing System.Collections.Generic;\r\nusing System;\r\n\r\npublic static class XLuaTestCfg\r\n{\r\n    [LuaCallCSharp]\r\n    public static List<Type> lua_call_cs = new List<Type>()\r\n    {\r\n        typeof(AccessByGenGode),\r\n    };\r\n\r\n    [Hotfix]\r\n    public static List<Type> hotfix\r\n    {\r\n        get\r\n        {\r\n            return new List<Type>() { typeof(CalcByConfig) };\r\n        }\r\n    }\r\n}\r\n\r\n[LuaCallCSharp]\r\n[Hotfix]\r\npublic class Calc\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        return a - b;\r\n    }\r\n}\r\n\r\npublic class CalcByConfig\r\n{\r\n    public int Add(int a, int b)\r\n    {\r\n        return a * b;\r\n    }\r\n}\r\n\r\n[LuaCallCSharp]\r\n[GCOptimize]\r\npublic struct Point\r\n{\r\n    public Point(float _x, float _y)\r\n    {\r\n        x = _x;\r\n        y = _y;\r\n    }\r\n    public float x;\r\n    public float y;\r\n}\r\n\r\npublic class AccessByGenGode\r\n{\r\n    public void Print(Point pos)\r\n    {\r\n        Console.WriteLine(\"by gen code: x=\" + pos.x + \",y=\" + pos.y);\r\n    }\r\n}\r\n\r\npublic class AccessByReflection\r\n{\r\n    public void Print(Point pos)\r\n    {\r\n        Console.WriteLine(\"by reflection: x=\" + pos.x + \",y=\" + pos.y);\r\n    }\r\n}\r\n\r\npublic class XLuaTest\r\n{\r\n    [CSharpCallLua]\r\n    public delegate double LuaMax(double a, double b);\r\n\r\n    public static void Main()\r\n    {\r\n        LuaEnv luaenv = new LuaEnv();\r\n        luaenv.DoString(\"CS.System.Console.WriteLine('hello world')\");\r\n        \r\n        var max = luaenv.Global.GetInPath<LuaMax>(\"math.max\");\r\n        Console.WriteLine(\"max:\" + max(32, 12));\r\n\r\n        luaenv.Global.Set(\"obj1\", new AccessByGenGode());\r\n        luaenv.Global.Set(\"obj2\", new AccessByReflection());\r\n\r\n        luaenv.DoString(@\"\r\n            local p = CS.Point(3, 4)\r\n            print('-----------------------------')\r\n            obj2:Print(p)\r\n            print('-----------------------------')\r\n            obj1:Print(p)\r\n            print('-----------------------------')\r\n        \");\r\n\r\n\r\n        var calc = new Calc();\r\n        luaenv.Global.Set(\"calc\", calc);\r\n        luaenv.DoString(\"print(calc:Add(2, 4))\");\r\n\r\n\r\n        try\r\n        {\r\n            Console.WriteLine(\"2 + 4 =\" +calc.Add(2, 4));\r\n            luaenv.DoString(@\"\r\n                xlua.hotfix(CS.Calc, 'Add', function(self, a, b)\r\n                    return a + b\r\n                end)\r\n            \");\r\n            Console.WriteLine(\"2 + 4 =\" + calc.Add(2, 4));\r\n\r\n            CalcByConfig calc2 = new CalcByConfig();\r\n            Console.WriteLine(\"2 + 4 =\" + calc2.Add(2, 4));\r\n            luaenv.DoString(@\"\r\n                xlua.hotfix(CS.CalcByConfig, 'Add', function(self, a, b)\r\n                    return a + b\r\n                end)\r\n            \");\r\n            Console.WriteLine(\"2 + 4 =\" + calc2.Add(2, 4));\r\n\r\n            //ͷhotfix\r\n            luaenv.DoString(@\"\r\n                xlua.hotfix(CS.Calc, 'Add', nil)\r\n                xlua.hotfix(CS.CalcByConfig, 'Add', nil)\r\n            \");\r\n        }\r\n        catch(Exception e)\r\n        {\r\n            Console.WriteLine(\"Hotfix exception:\" + e);\r\n        }\r\n        max = null;\r\n        luaenv.Dispose();\r\n    }\r\n}"
  },
  {
    "path": "General/Src/XLuaUnitTest.cs",
    "content": "using XLua;\r\nusing System.Collections.Generic;\r\nusing System;\r\n\r\npublic class XLuaUnitTest\r\n{\r\n\r\n    public static void Main()\r\n    {\r\n        LuaEnv luaenv = LuaEnvSingleton.Instance;\r\n        luaenv.DoString(\"require 'main'\");\r\n    }\r\n}"
  },
  {
    "path": "General/premake5.lua",
    "content": "\r\nsolution \"XLua\"\r\n    configurations {\r\n        \"Debug\", \"Release\"\r\n    }\r\n\r\n    location (\"./\" .. (_ACTION or \"\"))\r\n    debugdir (\".\")\r\n    debugargs {  }\r\n\r\n    platforms { \"Any CPU\" }\r\n\r\nconfiguration \"Debug\"\r\n    symbols \"On\"\r\n    defines { \"_DEBUG\", \"DEBUG\", \"TRACE\" }\r\nconfiguration \"Release\"\r\n    flags { \"Optimize\" }\r\nconfiguration \"vs*\"\r\n    defines { \"\" }\r\n\r\nproject \"XLua.Mini\"\r\nlanguage \"C#\"\r\nkind \"SharedLib\"\r\nframework \"3.5\"\r\ntargetdir \"./Tools\"\r\n\r\nfiles\r\n{\r\n    \"../Assets/XLua/Src/*.cs\",\r\n    \"../Assets/XLua/Src/TemplateEngine/*.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n\t\"XLUA_GENERAL\",\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n}\r\n\r\nproject \"XLuaGenerate\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"4.0\"\r\ntargetdir \"./Tools\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaGenerate.cs\",\r\n    \"./Src/XLuaTemplates.Designer.cs\",\r\n    \"./Src/XLuaTemplates.resx\",\r\n    \"../Assets/XLua/Src/Editor/Generator.cs\",\r\n    \"../Assets/XLua/Src/Editor/Template/*.txt\",\r\n}\r\n\r\ndefines\r\n{\r\n    \"XLUA_GENERAL\",\r\n    \"XLUA_ALL_OBSOLETE\",\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n    \"XLua.Mini\",\r\n}\r\n\r\nproject \"XLuaHotfixInject\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"3.5\"\r\ntargetdir \"./Tools\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaHotfixInject.cs\",\r\n    \"../Assets/XLua/Src/Editor/Hotfix.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n    \"HOTFIX_ENABLE\",\r\n    \"XLUA_GENERAL\",\r\n}\r\n\r\nlinks\r\n{\r\n    --\"C:/Program Files/Unity/Editor/Data/Mono/lib/mono/unity/mscorlib.dll\",\r\n    \"C:/Program Files/Unity/Editor/Data/Mono/lib/mono/unity/System.dll\",\r\n    \"C:/Program Files/Unity/Editor/Data/Mono/lib/mono/unity/System.Core.dll\",\r\n    \"Lib/Mono.Cecil.dll\",\r\n    \"Lib/Mono.Cecil.Mdb.dll\",\r\n    \"Lib/Mono.Cecil.Pdb.dll\",\r\n}\r\n\r\n\r\nproject \"KeyPairsGen\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"3.5\"\r\ntargetdir \"./Tools\"\r\n\r\nfiles\r\n{\r\n    \"./Src/KeyPairsGen.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n}\r\n\r\nproject \"FilesSignature\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"3.5\"\r\ntargetdir \"./Tools\"\r\n\r\nfiles\r\n{\r\n    \"./Src/FilesSignature.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n}\r\n\r\nproject \"XLuaTest\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"4.0\"\r\ntargetdir \"./Bin\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaTest.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n    \"XLua.Mini\",\r\n}\r\n\r\nproject \"XLuaUnitTest\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"4.0\"\r\ntargetdir \"./Bin\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaUnitTest.cs\",\r\n    \"../Test/UnitTest/xLuaTest/**.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n    \"XLUA_GENERAL\",\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n    \"XLua.Mini\",\r\n}\r\n\r\nsolution \"XLuaGenTest\"\r\n    configurations {\r\n        \"Debug\", \"Release\"\r\n    }\r\n\r\n    location (\"./\" .. (_ACTION or \"\"))\r\n    debugdir (\".\")\r\n    debugargs {  }\r\n\r\n    platforms { \"Any CPU\" }\r\n\r\nconfiguration \"Debug\"\r\n    symbols \"On\"\r\n    defines { \"_DEBUG\", \"DEBUG\", \"TRACE\" }\r\nconfiguration \"Release\"\r\n    flags { \"Optimize\" }\r\nconfiguration \"vs*\"\r\n    defines { \"\" }\r\n\r\nproject \"XLuaTestGenCode\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"4.0\"\r\ntargetdir \"./Bin\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaTest.cs\",\r\n    \"../Assets/XLua/Src/*.cs\",\r\n    \"../Assets/XLua/Src/TemplateEngine/*.cs\",\r\n    \"./Gen1/*.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n    \"XLUA_GENERAL\",\r\n    \"HOTFIX_ENABLE\",\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n}\r\n\r\n\r\nproject \"XLuaUnitTestGenCode\"\r\nlanguage \"C#\"\r\nkind \"ConsoleApp\"\r\nframework \"4.0\"\r\ntargetdir \"./Bin\"\r\n\r\nfiles\r\n{\r\n    \"./Src/XLuaUnitTest.cs\",\r\n    \"../Test/UnitTest/xLuaTest/**.cs\",\r\n    \"../Assets/XLua/Src/*.cs\",\r\n    \"../Assets/XLua/Src/TemplateEngine/*.cs\",\r\n    \"./Gen2/*.cs\",\r\n}\r\n\r\ndefines\r\n{\r\n    \"XLUA_GENERAL\",\r\n}\r\n\r\nlinks\r\n{\r\n    \"System\",\r\n    \"System.Core\",\r\n}\r\n"
  },
  {
    "path": "General/vs2013/FilesSignature.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>FilesSignature</RootNamespace>\r\n    <AssemblyName>FilesSignature</AssemblyName>\r\n    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\FilesSignature\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\FilesSignature\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants></DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\Src\\FilesSignature.cs\">\r\n      <Link>Src\\FilesSignature.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/KeyPairsGen.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>KeyPairsGen</RootNamespace>\r\n    <AssemblyName>KeyPairsGen</AssemblyName>\r\n    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\KeyPairsGen\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\KeyPairsGen\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants></DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\Src\\KeyPairsGen.cs\">\r\n      <Link>Src\\KeyPairsGen.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLua.Mini.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}</ProjectGuid>\r\n    <OutputType>Library</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLua.Mini</RootNamespace>\r\n    <AssemblyName>XLua.Mini</AssemblyName>\r\n    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLua.Mini\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLua.Mini\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CodeEmit.cs\">\r\n      <Link>Assets\\XLua\\Src\\CodeEmit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CopyByValue.cs\">\r\n      <Link>Assets\\XLua\\Src\\CopyByValue.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\DelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\DelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenAttributes.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenAttributes.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenericDelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenericDelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\InternalGlobals.cs\">\r\n      <Link>Assets\\XLua\\Src\\InternalGlobals.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaBase.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaDLL.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaDLL.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaEnv.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaEnv.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaException.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaException.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaFunction.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaFunction.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaTable.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaTable.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\MethodWarpsCache.cs\">\r\n      <Link>Assets\\XLua\\Src\\MethodWarpsCache.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectCasters.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectCasters.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslator.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslator.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslatorPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslatorPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\RawObject.cs\">\r\n      <Link>Assets\\XLua\\Src\\RawObject.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\SignatureLoader.cs\">\r\n      <Link>Assets\\XLua\\Src\\SignatureLoader.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\StaticLuaCallbacks.cs\">\r\n      <Link>Assets\\XLua\\Src\\StaticLuaCallbacks.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs\">\r\n      <Link>Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TypeExtensions.cs\">\r\n      <Link>Assets\\XLua\\Src\\TypeExtensions.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\Utils.cs\">\r\n      <Link>Assets\\XLua\\Src\\Utils.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLua.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n# Visual Studio 2013\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLua.Mini\", \"XLua.Mini.csproj\", \"{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaGenerate\", \"XLuaGenerate.csproj\", \"{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaHotfixInject\", \"XLuaHotfixInject.csproj\", \"{0E713D15-FA69-5C67-239C-41EC0FF43B73}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"KeyPairsGen\", \"KeyPairsGen.csproj\", \"{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"FilesSignature\", \"FilesSignature.csproj\", \"{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaTest\", \"XLuaTest.csproj\", \"{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaUnitTest\", \"XLuaUnitTest.csproj\", \"{7F2D7E42-6B90-0DE7-1416-469D0058D969}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{0E713D15-FA69-5C67-239C-41EC0FF43B73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{0E713D15-FA69-5C67-239C-41EC0FF43B73}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{0E713D15-FA69-5C67-239C-41EC0FF43B73}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{0E713D15-FA69-5C67-239C-41EC0FF43B73}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{67F72FA1-D3AC-A896-5CA1-A26DC8559F9A}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{2A7BAA8E-1649-9E94-FFDC-0EBBEB497AF9}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{7F2D7E42-6B90-0DE7-1416-469D0058D969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{7F2D7E42-6B90-0DE7-1416-469D0058D969}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{7F2D7E42-6B90-0DE7-1416-469D0058D969}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{7F2D7E42-6B90-0DE7-1416-469D0058D969}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "General/vs2013/XLuaGenTest.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n# Visual Studio 2013\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaTestGenCode\", \"XLuaTestGenCode.csproj\", \"{54C2A82C-C04D-16F1-C95E-99E5356972F1}\"\r\nEndProject\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"XLuaUnitTestGenCode\", \"XLuaUnitTestGenCode.csproj\", \"{F433BFDC-6095-9CEA-E902-E39C5563D3A9}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{54C2A82C-C04D-16F1-C95E-99E5356972F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{54C2A82C-C04D-16F1-C95E-99E5356972F1}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{54C2A82C-C04D-16F1-C95E-99E5356972F1}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{54C2A82C-C04D-16F1-C95E-99E5356972F1}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\t\t{F433BFDC-6095-9CEA-E902-E39C5563D3A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{F433BFDC-6095-9CEA-E902-E39C5563D3A9}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{F433BFDC-6095-9CEA-E902-E39C5563D3A9}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{F433BFDC-6095-9CEA-E902-E39C5563D3A9}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "General/vs2013/XLuaGenerate.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{6A24C3AC-5687-5251-FF0C-8B07EB4E1ED4}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaGenerate</RootNamespace>\r\n    <AssemblyName>XLuaGenerate</AssemblyName>\r\n    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaGenerate\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL;XLUA_ALL_OBSOLETE</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaGenerate\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;XLUA_GENERAL;XLUA_ALL_OBSOLETE</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Generator.cs\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Generator.cs</Link>\r\n    </Compile>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaClassWrap.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaClassWrap.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateBridge.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateBridge.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateWrap.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaDelegateWrap.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaEnumWrap.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaEnumWrap.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaInterfaceBridge.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaInterfaceBridge.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaRegister.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaRegister.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\LuaWrapPusher.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\LuaWrapPusher.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\PackUnpack.tpl.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\PackUnpack.tpl.txt</Link>\r\n    </None>\r\n    <None Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Template\\TemplateCommon.lua.txt\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Template\\TemplateCommon.lua.txt</Link>\r\n    </None>\r\n    <Compile Include=\"..\\Src\\XLuaGenerate.cs\">\r\n      <Link>Src\\XLuaGenerate.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Src\\XLuaTemplates.Designer.cs\">\r\n      <Link>Src\\XLuaTemplates.Designer.cs</Link>\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>XLuaTemplates.resx</DependentUpon>\r\n    </Compile>\r\n    <EmbeddedResource Include=\"..\\Src\\XLuaTemplates.resx\">\r\n      <Link>Src\\XLuaTemplates.resx</Link>\r\n      <Generator>ResXFileCodeGenerator</Generator>\r\n      <LastGenOutput>XLuaTemplates.Designer.cs</LastGenOutput>\r\n      <SubType>Designer</SubType>\r\n    </EmbeddedResource>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ProjectReference Include=\"XLua.Mini.csproj\">\r\n      <Project>{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}</Project>\r\n      <Name>XLua.Mini</Name>\r\n    </ProjectReference>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLuaHotfixInject.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{0E713D15-FA69-5C67-239C-41EC0FF43B73}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaHotfixInject</RootNamespace>\r\n    <AssemblyName>XLuaHotfixInject</AssemblyName>\r\n    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaHotfixInject\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;HOTFIX_ENABLE;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Tools\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaHotfixInject\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;HOTFIX_ENABLE;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\">\r\n      <HintPath>C:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\unity\\System.dll</HintPath>\r\n    </Reference>\r\n    <Reference Include=\"System.Core\">\r\n      <HintPath>C:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\unity\\System.Core.dll</HintPath>\r\n    </Reference>\r\n    <Reference Include=\"Mono.Cecil\">\r\n      <HintPath>..\\Lib\\Mono.Cecil.dll</HintPath>\r\n    </Reference>\r\n    <Reference Include=\"Mono.Cecil.Mdb\">\r\n      <HintPath>..\\Lib\\Mono.Cecil.Mdb.dll</HintPath>\r\n    </Reference>\r\n    <Reference Include=\"Mono.Cecil.Pdb\">\r\n      <HintPath>..\\Lib\\Mono.Cecil.Pdb.dll</HintPath>\r\n    </Reference>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\Editor\\Hotfix.cs\">\r\n      <Link>Assets\\XLua\\Src\\Editor\\Hotfix.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Src\\XLuaHotfixInject.cs\">\r\n      <Link>Src\\XLuaHotfixInject.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLuaTest.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{DF2795A4-CBF4-EFAF-F40D-DE57E039253E}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaTest</RootNamespace>\r\n    <AssemblyName>XLuaTest</AssemblyName>\r\n    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaTest\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaTest\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants></DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\Src\\XLuaTest.cs\">\r\n      <Link>Src\\XLuaTest.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ProjectReference Include=\"XLua.Mini.csproj\">\r\n      <Project>{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}</Project>\r\n      <Name>XLua.Mini</Name>\r\n    </ProjectReference>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLuaTestGenCode.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{54C2A82C-C04D-16F1-C95E-99E5356972F1}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaTestGenCode</RootNamespace>\r\n    <AssemblyName>XLuaTestGenCode</AssemblyName>\r\n    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaTestGenCode\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL;HOTFIX_ENABLE</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaTestGenCode\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;XLUA_GENERAL;HOTFIX_ENABLE</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CodeEmit.cs\">\r\n      <Link>Assets\\XLua\\Src\\CodeEmit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CopyByValue.cs\">\r\n      <Link>Assets\\XLua\\Src\\CopyByValue.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\DelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\DelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenAttributes.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenAttributes.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenericDelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenericDelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\InternalGlobals.cs\">\r\n      <Link>Assets\\XLua\\Src\\InternalGlobals.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaBase.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaDLL.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaDLL.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaEnv.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaEnv.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaException.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaException.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaFunction.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaFunction.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaTable.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaTable.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\MethodWarpsCache.cs\">\r\n      <Link>Assets\\XLua\\Src\\MethodWarpsCache.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectCasters.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectCasters.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslator.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslator.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslatorPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslatorPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\RawObject.cs\">\r\n      <Link>Assets\\XLua\\Src\\RawObject.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\SignatureLoader.cs\">\r\n      <Link>Assets\\XLua\\Src\\SignatureLoader.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\StaticLuaCallbacks.cs\">\r\n      <Link>Assets\\XLua\\Src\\StaticLuaCallbacks.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs\">\r\n      <Link>Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TypeExtensions.cs\">\r\n      <Link>Assets\\XLua\\Src\\TypeExtensions.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\Utils.cs\">\r\n      <Link>Assets\\XLua\\Src\\Utils.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\AccessByGenGodeWrap.cs\">\r\n      <Link>Gen1\\AccessByGenGodeWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\CalcWrap.cs\">\r\n      <Link>Gen1\\CalcWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\DelegatesGensBridge.cs\">\r\n      <Link>Gen1\\DelegatesGensBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\EnumWrap.cs\">\r\n      <Link>Gen1\\EnumWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\PackUnpack.cs\">\r\n      <Link>Gen1\\PackUnpack.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\PointWrap.cs\">\r\n      <Link>Gen1\\PointWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\WrapPusher.cs\">\r\n      <Link>Gen1\\WrapPusher.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen1\\XLuaGenAutoRegister.cs\">\r\n      <Link>Gen1\\XLuaGenAutoRegister.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Src\\XLuaTest.cs\">\r\n      <Link>Src\\XLuaTest.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLuaUnitTest.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{7F2D7E42-6B90-0DE7-1416-469D0058D969}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaUnitTest</RootNamespace>\r\n    <AssemblyName>XLuaUnitTest</AssemblyName>\r\n    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaUnitTest\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaUnitTest\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\Src\\XLuaUnitTest.cs\">\r\n      <Link>Src\\XLuaUnitTest.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\CSObjectForTestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\CSObjectForTestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TCForTestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TCForTestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaCallCS\\CSObjectForLuaCallCS.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaCallCS\\CSObjectForLuaCallCS.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestCommon.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestCommon.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestObj.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestObj.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestObjReflect.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestObjReflect.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\Main.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\Main.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ProjectReference Include=\"XLua.Mini.csproj\">\r\n      <Project>{9A2C7D34-0697-31AB-4FD5-E250BB7E0F00}</Project>\r\n      <Name>XLua.Mini</Name>\r\n    </ProjectReference>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "General/vs2013/XLuaUnitTestGenCode.csproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"12.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProjectGuid>{F433BFDC-6095-9CEA-E902-E39C5563D3A9}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <AppDesignerFolder>Properties</AppDesignerFolder>\r\n    <RootNamespace>XLuaUnitTestGenCode</RootNamespace>\r\n    <AssemblyName>XLuaUnitTestGenCode</AssemblyName>\r\n    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r\n    <FileAlignment>512</FileAlignment>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Debug\\XLuaUnitTestGenCode\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>_DEBUG;DEBUG;TRACE;;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n    <DebugType>pdbonly</DebugType>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>..\\Bin\\</OutputPath>\r\n    <BaseIntermediateOutputPath>obj\\Any CPU\\Release\\XLuaUnitTestGenCode\\</BaseIntermediateOutputPath>\r\n    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>\r\n    <DefineConstants>;XLUA_GENERAL</DefineConstants>\r\n    <ErrorReport>prompt</ErrorReport>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Core\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CodeEmit.cs\">\r\n      <Link>Assets\\XLua\\Src\\CodeEmit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\CopyByValue.cs\">\r\n      <Link>Assets\\XLua\\Src\\CopyByValue.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\DelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\DelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenAttributes.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenAttributes.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\GenericDelegateBridge.cs\">\r\n      <Link>Assets\\XLua\\Src\\GenericDelegateBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\InternalGlobals.cs\">\r\n      <Link>Assets\\XLua\\Src\\InternalGlobals.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaBase.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaDLL.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaDLL.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaEnv.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaEnv.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaException.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaException.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaFunction.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaFunction.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\LuaTable.cs\">\r\n      <Link>Assets\\XLua\\Src\\LuaTable.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\MethodWarpsCache.cs\">\r\n      <Link>Assets\\XLua\\Src\\MethodWarpsCache.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectCasters.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectCasters.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslator.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslator.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\ObjectTranslatorPool.cs\">\r\n      <Link>Assets\\XLua\\Src\\ObjectTranslatorPool.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\RawObject.cs\">\r\n      <Link>Assets\\XLua\\Src\\RawObject.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\SignatureLoader.cs\">\r\n      <Link>Assets\\XLua\\Src\\SignatureLoader.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\StaticLuaCallbacks.cs\">\r\n      <Link>Assets\\XLua\\Src\\StaticLuaCallbacks.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs\">\r\n      <Link>Assets\\XLua\\Src\\TemplateEngine\\TemplateEngine.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\TypeExtensions.cs\">\r\n      <Link>Assets\\XLua\\Src\\TypeExtensions.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Assets\\XLua\\Src\\Utils.cs\">\r\n      <Link>Assets\\XLua\\Src\\Utils.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\CSObjectForTestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\CSObjectForTestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TCForTestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TCForTestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TestCSCallLua.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\CSharpCallLua\\TestCSCallLua.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaCallCS\\CSObjectForLuaCallCS.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaCallCS\\CSObjectForLuaCallCS.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestCommon.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestCommon.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestObj.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestObj.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\LuaTestObjReflect.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\LuaTestObjReflect.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Test\\UnitTest\\xLuaTest\\Main.cs\">\r\n      <Link>Test\\UnitTest\\xLuaTest\\Main.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\AClassWrap.cs\">\r\n      <Link>Gen2\\AClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\CClassWrap.cs\">\r\n      <Link>Gen2\\CClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\DelegatesGensBridge.cs\">\r\n      <Link>Gen2\\DelegatesGensBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\EmployeeTemplateWrap.cs\">\r\n      <Link>Gen2\\EmployeeTemplateWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\EmployeestructWrap.cs\">\r\n      <Link>Gen2\\EmployeestructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\EnumWrap.cs\">\r\n      <Link>Gen2\\EnumWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\Gen2FloatStructWrap.cs\">\r\n      <Link>Gen2\\Gen2FloatStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\Gen3FloatStructWrap.cs\">\r\n      <Link>Gen2\\Gen3FloatStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\Gen4FloatStructWrap.cs\">\r\n      <Link>Gen2\\Gen4FloatStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\Gen5FloatStructWrap.cs\">\r\n      <Link>Gen2\\Gen5FloatStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\Gen6FloatStructWrap.cs\">\r\n      <Link>Gen2\\Gen6FloatStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\GenCodeBaseClassWrap.cs\">\r\n      <Link>Gen2\\GenCodeBaseClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\GenCodeDrivedClassWrap.cs\">\r\n      <Link>Gen2\\GenCodeDrivedClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\GenCodeStructWrap.cs\">\r\n      <Link>Gen2\\GenCodeStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\HasConstructStructWrap.cs\">\r\n      <Link>Gen2\\HasConstructStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\IGenCodeTestWrap.cs\">\r\n      <Link>Gen2\\IGenCodeTestWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\ITestLuaClassWrap.cs\">\r\n      <Link>Gen2\\ITestLuaClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\LongStaticWrap.cs\">\r\n      <Link>Gen2\\LongStaticWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\LuaTestCommonWrap.cs\">\r\n      <Link>Gen2\\LuaTestCommonWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\LuaTestObjWrap.cs\">\r\n      <Link>Gen2\\LuaTestObjWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\ManagerWrap.cs\">\r\n      <Link>Gen2\\ManagerWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\NoContClassWrap.cs\">\r\n      <Link>Gen2\\NoContClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\PackUnpack.cs\">\r\n      <Link>Gen2\\PackUnpack.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\ReferTestClassWrap.cs\">\r\n      <Link>Gen2\\ReferTestClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\StaticPusherStructAWrap.cs\">\r\n      <Link>Gen2\\StaticPusherStructAWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\StaticPusherStructAllWrap.cs\">\r\n      <Link>Gen2\\StaticPusherStructAllWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\StaticPusherStructBWrap.cs\">\r\n      <Link>Gen2\\StaticPusherStructBWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TCForTestCSCallLuaWrap.cs\">\r\n      <Link>Gen2\\TCForTestCSCallLuaWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TableAutoTransComplexClassWrap.cs\">\r\n      <Link>Gen2\\TableAutoTransComplexClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TableAutoTransComplexStructWrap.cs\">\r\n      <Link>Gen2\\TableAutoTransComplexStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TableAutoTransSimpleClassWrap.cs\">\r\n      <Link>Gen2\\TableAutoTransSimpleClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TableAutoTransSimpleStructWrap.cs\">\r\n      <Link>Gen2\\TableAutoTransSimpleStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestCastClassWrap.cs\">\r\n      <Link>Gen2\\TestCastClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestChineseStringWrap.cs\">\r\n      <Link>Gen2\\TestChineseStringWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestExtensionMethod_TestExtensionMethodFOrClassWrap.cs\">\r\n      <Link>Gen2\\TestExtensionMethod_TestExtensionMethodFOrClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestExtensionMethod_TestExtensionMethodForStructWrap.cs\">\r\n      <Link>Gen2\\TestExtensionMethod_TestExtensionMethodForStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestGenFloatStructClassWrap.cs\">\r\n      <Link>Gen2\\TestGenFloatStructClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestStructWrap.cs\">\r\n      <Link>Gen2\\TestStructWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\TestTableAutoTransClassWrap.cs\">\r\n      <Link>Gen2\\TestTableAutoTransClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\WrapPusher.cs\">\r\n      <Link>Gen2\\WrapPusher.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\XLuaGenAutoRegister.cs\">\r\n      <Link>Gen2\\XLuaGenAutoRegister.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableValue1InfEqualBridge.cs\">\r\n      <Link>Gen2\\tableValue1InfEqualBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableValue1InfLessBridge.cs\">\r\n      <Link>Gen2\\tableValue1InfLessBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableValue1InfMoreBridge.cs\">\r\n      <Link>Gen2\\tableValue1InfMoreBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableValue1InfTypeDiffBridge.cs\">\r\n      <Link>Gen2\\tableValue1InfTypeDiffBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableValue2InfBridge.cs\">\r\n      <Link>Gen2\\tableValue2InfBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\tableVarIncludeInfBridge.cs\">\r\n      <Link>Gen2\\tableVarIncludeInfBridge.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_ChildCalssWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_ChildCalssWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_MultiContClassWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_MultiContClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_OneParamContClassWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_OneParamContClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_OverClassAWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_OverClassAWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_OverClassBWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_OverClassBWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_OverClassCDeriveNGAWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_OverClassCDeriveNGAWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_OverClassCWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_OverClassCWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_StaticTestClassWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_StaticTestClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_TwoParamsContClassWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_TwoParamsContClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Gen2\\testLuaCallCS_abstractFatherClassWrap.cs\">\r\n      <Link>Gen2\\testLuaCallCS_abstractFatherClassWrap.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\Src\\XLuaUnitTest.cs\">\r\n      <Link>Src\\XLuaUnitTest.cs</Link>\r\n    </Compile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r\n       Other similar extension points exist, see Microsoft.Common.targets.\r\n  <Target Name=\"BeforeBuild\">\r\n  </Target>\r\n  <Target Name=\"AfterBuild\">\r\n  </Target>\r\n  -->\r\n</Project>"
  },
  {
    "path": "LICENSE.TXT",
    "content": "Tencent is pleased to support the open source community by making xLua available.  \r\nCopyright (C) 2016 THL A29 Limited, a Tencent company.  All rights reserved.\r\nIf you have downloaded a copy of the xLua binary from Tencent, please note that the xLua binary is licensed under the MIT License.\r\nIf you have downloaded a copy of the xLua source code from Tencent, please note that xLua source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms.  Your integration of xLua into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within xLua.\r\nA copy of the MIT License is included in this file.\r\nOther dependencies and licenses:\r\n\r\nOpen Source Software Licensed under the BSD 3-Clause License:\r\n--------------------------------------------------------------------\r\n1. android-cmake\r\nCopyright (c) 2010-2011, Ethan Rublee\r\nCopyright (c) 2011-2014, Andrey Kamaev\r\nAll rights reserved.\r\nCopyright (c) 2014, Pavel Rojtberg\r\nAll rights reserved.\r\n\r\n\r\nTerms of the BSD 3-Clause License:\r\n--------------------------------------------------------------------\r\n\r\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r\n?Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r\n?Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r\n?Neither the name of [copyright holder] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\r\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n\r\nOpen Source Software Licensed Under the MIT License:\r\n--------------------------------------------------------------------\r\n1. Lua  5.1.5 & 5.3.3 & 5.3.4\r\nCopyright (C) 1994-2016 Lua.org, PUC-Rio.\r\n\r\n2. LuaJIT  2.1.0beta2 \r\nCopyright (C) 2005-2016 Mike Pall. All rights reserved.\r\n\r\n3. luasocket  3.0-rc1\r\nCopyright ? 1999-2013 Diego Nehab. All rights reserved.\r\n\r\n4. Cecil 0.9.6\r\nCopyright (c) 2008 - 2015 Jb Evain\r\nCopyright (c) 2008 - 2011 Novell, Inc.\r\n\r\nTerms of the MIT License:\r\n--------------------------------------------------------------------\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
  },
  {
    "path": "README.md",
    "content": "![](Assets/XLua/Doc/xLua.png)\r\n\r\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Tencent/xLua/blob/master/LICENSE.TXT)\r\n[![release](https://img.shields.io/badge/release-v2.1.15-blue.svg)](https://github.com/Tencent/xLua/releases)\r\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/Tencent/xLua/pulls)\r\n[![Build status](https://github.com/Tencent/xLua/actions/workflows/build.yml/badge.svg)](https://github.com/Tencent/xLua/actions/workflows/build.yml)\r\n\r\n[(English Documents Available)](README_EN.md)\r\n\r\n## C# 下 Lua 编程支持\r\n\r\nxLua 为 Unity、.Net、Mono 等 C# 环境增加 Lua 脚本编程的能力，借助 xLua，这些 Lua 代码可以方便的和 C# 相互调用。\r\n\r\n<br/>\r\n\r\n## xLua 的突破\r\n\r\nxLua 在功能、性能、易用性都有不少突破，这几方面分别最具代表性的是：\r\n\r\n* 可以运行时把 C# 实现（方法，操作符，属性，事件等等）替换成 Lua 实现；\r\n* 出色的 GC 优化，自定义 struct，枚举在 Lua 和 C# 间传递无 C# GC Alloc；\r\n* 编辑器下无需生成代码，开发更轻量；\r\n\r\n更详细的特性、平台支持介绍请参考 [xLua 文档: 功能特性](Assets/XLua/Doc/features.md)。\r\n\r\n<br/>\r\n\r\n## 安装\r\n\r\nxLua 可以直接简单的安装在 Unity 项目中.\r\n\r\n1. 从 [Releases](https://github.com/Tencent/xLua/releases) 中下载发行版, 或直接下载本仓库代码.\r\n2. 打开下载下来的源码压缩包, 你会看到一个 Assets 目录, 这目录就对应 Unity 工程的 Assets 目录，保持这目录结构, 将其内容置入 Unity 项目即可.\r\n\r\n> 注意, Assets/Examples 目录下为示例代码, 你应该在生产环境下删去他们.\r\n\r\n如果希望安装到其它目录，请看 [FAQ](Assets/XLua/Doc/faq.md) 相关介绍。\r\n\r\n<br/>\r\n\r\n## 文档\r\n\r\n* (必看) [XLua 教程](Assets/XLua/Doc/XLua教程.md)：教程，其配套代码[这里](Assets/XLua/Tutorial/)。\r\n* (必看) [XLua 的配置](Assets/XLua/Doc/configure.md)：介绍如何配置xLua。\r\n* [常见问题解答](Assets/XLua/Doc/faq.md)：常见问题都总结在这里，初使用大多数问题都可以在这里找到答案。\r\n* [热补丁操作指南](Assets/XLua/Doc/hotfix.md)：介绍如何使用热补丁特性。\r\n* [XLua增加删除第三方lua库](Assets/XLua/Doc/XLua增加删除第三方lua库.md)：如何增删第三方lua扩展库。\r\n* [XLua API](Assets/XLua/Doc/XLua_API.md)：API文档。\r\n* [生成引擎二次开发指南](Assets/XLua/Doc/custom_generate.md)：介绍如何做生成引擎的二次开发。\r\n\r\n<br/>\r\n\r\n## 快速入门\r\n\r\n一个完整的例子仅需3行代码：\r\n\r\n安装好xLua，建一个MonoBehaviour拖到场景，在Start加入如下代码：\r\n\r\n```csharp\r\nXLua.LuaEnv luaEnv = new XLua.LuaEnv();\r\nluaEnv.DoString(\"CS.UnityEngine.Debug.Log('hello world')\");\r\nluaEnv.Dispose();\r\n```\r\n\r\n1. DoString 参数为 string，可输入任意合法的 Lua 代码，本示例在 Lua 里调用 C# 的 UnityEngine.Debug.Log 打印了个日志。\r\n2. 一个 LuaEnv 实例对应 Lua 虚拟机，出于开销的考虑，建议全局唯一。\r\n\r\nC#主动调用 Lua 也很简单，比如要调用 Lua 的系统函数，推荐方式是：\r\n\r\n* 声明\r\n\r\n  ```csharp\r\n  [XLua.CSharpCallLua]\r\n  public delegate double LuaMax(double a, double b);\r\n  ```\r\n\r\n* 绑定\r\n\r\n  ```csharp\r\n  var max = luaEnv.Global.GetInPath<LuaMax>(\"math.max\");\r\n  ```\r\n\r\n* 调用\r\n\r\n  ```csharp\r\n  Debug.Log(\"max:\" + max(32, 12));\r\n  ```\r\n\r\n注意, 请不要重复调用 `luaEnv.Global.GetInPath<LuaMax>`, 这没有任何必要.\r\n\r\n<br/>\r\n\r\n## 热补丁\r\n\r\n除了使用 Lua 在 Unity 进行脚本编写, 你也可以使用 Lua 实现 \"热补丁\". xLua 提供了使用 Lua 逻辑替换 C# 方法逻辑的方案.\r\n\r\n* 侵入性小，老项目原有代码不做任何调整就可使用。\r\n* 运行时影响小，不打补丁基本和原有程序一样。\r\n* 出问题了可以用 Lua 来打补丁，这时才会走到 Lua 代码逻辑；\r\n\r\n参考使用指南: [xLua 文档: 热补丁](Assets/XLua/Doc/hotfix.md)\r\n\r\n<br/>\r\n\r\n## 更多示例\r\n\r\n* [01_Helloworld](Assets/XLua/Examples/01_Helloworld/): 快速入门的例子。\r\n* [02_U3DScripting](Assets/XLua/Examples/02_U3DScripting/): 展示怎么用 Lua 来写 MonoBehaviour。\r\n* [03_UIEvent](Assets/XLua/Examples/03_UIEvent/): 展示怎么用 Lua 来写 UI 逻辑。\r\n* [04_LuaObjectOrented](Assets/XLua/Examples/04_LuaObjectOrented/): 展示 Lua 面向对象和 C# 的配合。\r\n* [05_NoGc](Assets/XLua/Examples/05_NoGc/): 展示怎么去避免值类型的GC。\r\n* [06_Coroutine](Assets/XLua/Examples/06_Coroutine/): 展示 Lua 协程怎么和 Unity 协程相配合。\r\n* [07_AsyncTest](Assets/XLua/Examples/07_AsyncTest/): 展示怎么用 Lua 协程来把异步逻辑同步化。\r\n* [08_Hotfix](Assets/XLua/Examples/08_Hotfix/): 热补丁的示例（需要开启热补丁特性，如何开启请参考 [xLua 文档: 热补丁](Assets/XLua/Doc/hotfix.md)）。\r\n* [09_GenericMethod](Assets/XLua/Examples/09_GenericMethod/): 泛化函数支持的演示。\r\n* [10_SignatureLoader](Assets/XLua/Examples/10_SignatureLoader/): 展示如何读取经数字签名的lua脚本，参见[数字签名](Assets/XLua/Doc/signature.md)的文档介绍。\r\n* [11_RawObject](Assets/XLua/Examples/11_RawObject/): 当 C# 参数是object时，如何把一个lua number指定以boxing后的int传递过去。\r\n* [12_ReImplementInLua](Assets/XLua/Examples/12_ReImplementInLua/): 展示如何将复杂值类型改为 Lua 实现。\r\n* [14_HotfixAsyncAwait](Assets/XLua/Examples/14_HotfixAsyncAwait/): 展示如何将异步函数和await关键字改为 Lua 实现。\r\n\r\n<br/>\r\n\r\n## 技术支持\r\n\r\n一群：612705778 (已满)\r\n\r\n二群：703073338 (已满)\r\n\r\n三群：811246782\r\n\r\n入群的问题：有问题该先从哪找答案\r\n\r\n回答：FAQ\r\n\r\n平时也要谨记这答案，90%以上问题都可以在[FAQ](Assets/XLua/Doc/faq.md)里头找到答案。这些问题就别在群刷屏了。\r\n\r\n"
  },
  {
    "path": "README_EN.md",
    "content": "![](Assets/XLua/Doc/xLua.png)\r\n\r\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Tencent/xLua/blob/master/LICENSE.TXT)\r\n[![release](https://img.shields.io/badge/release-v2.1.15-blue.svg)](https://github.com/Tencent/xLua/releases)\r\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/Tencent/xLua/pulls)\r\n[![Build status](https://travis-ci.org/Tencent/xLua.svg?branch=master)](https://travis-ci.org/Tencent/xLua)\r\n\r\n## Lua programming solution for C#\r\n\r\nxLua adds Lua scripting capability to Unity, .Net, Mono, and other C# environments. With xLua, Lua code and C# code can easily call each other.\r\n\r\n## xLua's superior features\r\n\r\nxLua has many breakthroughs in function, performance, and ease of use. The most significant features are:\r\n\r\n* You can use C# implementations (methods, operators, properties, events, etc...) in Lua.\r\n* Outstanding GC optimization, customized struct, no C# gc alloc when passing the enumerated objects between C# and Lua;\r\n* Lightweight development with no needs to generate code in editor mode;\r\n\r\n## Installation\r\n\r\nUnpack the ZIP package and you will see an Assets directory, which corresponds to the Unity project's Assets directory. Keep the directory structure in your Unity project.\r\n\r\nIf you want to install it to another directory, please see the [FAQs](Assets/XLua/Doc/Faq_EN.md).\r\n\r\n## Documents\r\n\r\n* [FAQs](Assets/XLua/Doc/Faq_EN.md): Frequently asked questions are summarized here. You can find answers to questions for beginners.\r\n* (Must-read) [XLua Tutorial](Assets/XLua/Doc/XLua_Tutorial_EN.md): This is a tutorial. The supporting code can be found [here](Assets/XLua/Tutorial/).\r\n* (Must-read) [XLua Configuration](Assets/XLua/Doc/Configure_EN.md): Descriptions on how to configure xLua.\r\n* [Hotfix Operation Guide](Assets/XLua/Doc/Hotfix_EN.md): Description on how to use the hotfix feature.\r\n* [Add/remove third-party Lua Libraries on xLua](Assets/XLua/Doc/Add_Remove_Lua_Lib.md): Descriptions on how to add or remove third-party Lua extension libraries.\r\n* [xLua APIs](Assets/XLua/Doc/XLua_API_EN.md): API documentation\r\n* [Secondary Development of the Build Engine](Assets/XLua/Doc/Custom_Generate_EN.md): Descriptions on how to do secondary development of the build engine.\r\n\r\n## Quick Start\r\n\r\nA complete example requires only 3 lines of code:\r\n\r\nInstall xLua, create a MonoBehaviour drag scenario, add the following code to Start:\r\n\r\n```csharp\r\nXLua.LuaEnv luaenv = new XLua.LuaEnv();\r\nluaenv.DoString(\"CS.UnityEngine.Debug.Log('hello world')\");\r\nluaenv.Dispose();\r\n```\r\n\r\n1. The DoString parameter is a string, and you can enter any allowable Lua code. In this example, Lua calls C#’s UnityEngine.Debug.Log to print a log.\r\n\r\n2. A LuaEnv instance corresponds to a Lua virtual machine. Due to overhead, it is recommended that the Lua virtual machine be globally unique.\r\n\r\nIt is simple that C# actively calls Lua. For example, the recommended method to call Lua's system function is:\r\n\r\n* Declare\r\n\r\n```csharp\r\n[XLua.CSharpCallLua]\r\npublic delegate double LuaMax(double a, double b);\r\n```\r\n\r\n* Bind\r\n\r\n```csharp\r\nvar max = luaenv.Global.GetInPath<LuaMax>(\"math.max\");\r\n```\r\n\r\n* Call\r\n\r\n```csharp\r\nDebug.Log(\"max:\" + max(32, 12));\r\n```\r\n\r\nIt is recommended that you bind once and reuse it. If code is generated, no gc alloc is generated when calling max.\r\n\r\n## Hotfix\r\n\r\n* This has lower intrusiveness, and it can be used without any modification of the original code of the old project.\r\n* This has little impact on the runtime, which is almost the same as the original program which hotfix is not used.\r\n* If you have problems, you can also use Lua to patch. Then the Lua code logic is involved.\r\n\r\n[Here](Assets/XLua/Doc/Hotfix_EN.md) is the usage guide:\r\n\r\n## More Examples\r\n\r\n* [01_Helloworld](Assets/XLua/Examples/01_Helloworld/): Quick Start Examples\r\n* [02_U3DScripting](Assets/XLua/Examples/02_U3DScripting/): This example shows how to use Mono to write MonoBehaviour.\r\n* [03_UIEvent](Assets/XLua/Examples/03_UIEvent/): This example shows how to use Lua to write UI logic.\r\n* [04_LuaObjectOrented](Assets/XLua/Examples/04_LuaObjectOrented/): This example shows the cooperation between Lua's object-oriented programming and C#.\r\n* [05_NoGc](Assets/XLua/Examples/05_NoGc/): This example shows how to avoid the value type GC.\r\n* [06_Coroutine](Assets/XLua/Examples/06_Coroutine/): This example shows how Lua coroutines work with Unity coroutines.\r\n* [07_AsyncTest](Assets/XLua/Examples/07_AsyncTest/): This example shows how to use Lua coroutines to synchronize asynchronous logic.\r\n* [08_Hotfix](Assets/XLua/Examples/08_Hotfix/): These are Hotfix examples (Please enable hotfix feature. See the [Guide](Assets/XLua/Doc/Hotfix_EN.md) for details).\r\n* [09_GenericMethod](Assets/XLua/Examples/09_GenericMethod/): This is a generic function support demo.\r\n* [10_SignatureLoader](Assets/XLua/Examples/10_SignatureLoader/): This example shows how to read the Lua script with a digital signature. See the [Digital Signature](Assets/XLua/Doc/signature.md) document for details.\r\n* [11_RawObject](Assets/XLua/Examples/11_RawObject/): This example shows how to specify transferring a Lua number in the int after boxing when the C# parameter is an object.\r\n* [12_ReImplementInLua](Assets/XLua/Examples/12_ReImplementInLua/): This shows how to change complex value types to Lua implementations.\r\n* [14_HotfixAsyncAwait](Assets/XLua/Examples/14_HotfixAsyncAwait/): This shows how to change asynchronous functions and await keyword to Lua implementation.\r\n\r\n## Technical support\r\n\r\nQQ Group 1: 612705778 (may be full)\r\n\r\nQQ Group 2: 703073338\r\n\r\nQQ Group 3: 811246782\r\n\r\nCheck answers: If you encounter a problem, please read the FAQs first.\r\n\r\n"
  },
  {
    "path": "Test/PrefTest/Resources/luaTest.lua.txt",
    "content": "--if CS.TestUtils.IsAndroid() and jit and jit.off then\r\n--    jit.off()\r\n--end\r\n\r\nif jit and jit.off then\r\n    print('it is luajit')\r\nelse\r\n    print('it is lua')\r\nend\r\n\r\n\r\nfunction FuncBasePara(x)\r\nend\r\n\r\nfunction FuncClassPara(x)\r\nend\r\n\r\nfunction FuncStructPara(x)\r\nend\r\n\r\nfunction FuncTwoBasePara(x, y)\r\nend\r\n\r\nluaTable = {\r\n\tid = 0,\r\n\tfunc = function ()\r\n\tend\r\n}\r\n\r\ng = 0\r\n\r\nlocal ClassLuaCallCS = CS.ClassLuaCallCS\r\n\r\nfunction LuaAccessCSBaseMember_get(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tlocal x = csObj.id\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSBaseMember_set(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tcsObj.id = 0\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSClassMember_get(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tlocal x = csObj.paraClass\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSClassMember_set(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x = CS.ParaClass()\r\n\tfor i = 1, num do\r\n\t\tcsObj.paraClass = x\r\n\tend\r\nend\r\n\r\nfunction LuaAccessStructMember_get(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tlocal x = csObj.paraStruct\r\n\tend\r\nend\r\n\r\nfunction LuaAccessStructMember_set(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x = CS.ParaStruct()\r\n\tfor i = 1, num do\r\n\t\tcsObj.paraStruct = x\r\n\tend\r\nend\r\n\r\nfunction LuaAccessVec3Member_get(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tlocal x = csObj.vec3Member\r\n\tend\r\nend\r\n\r\nfunction LuaAccessVec3Member_set(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x = CS.UnityEngine.Vector3(0, 0 , 0)\r\n\tfor i = 1, num do\r\n\t\tlocal x = csObj.vec3Member\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSBaseMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\tcsObj:funcBaseParam(0)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSClassMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal clsObj = CS.ParaClass()\r\n\tfor i = 1, num do\r\n\t\tcsObj:funcClassParam(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStructMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal clsObj = CS.ParaStruct()\r\n\tfor i = 1, num do\r\n\t\tcsObj:funcStructParam(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSVec3MemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal clsObj = CS.UnityEngine.Vector3(0, 0 , 0)\r\n\tfor i = 1, num do\r\n\t\tcsObj:funcVec3Param(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSInMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x = 0\r\n\tfor i = 1, num do\r\n\t\tcsObj:funcInParam(x)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSOutMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x\r\n\tfor i = 1, num do\r\n\t\tx = csObj:funcOutParam()\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSInOutMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal x = 0\r\n\tlocal y\r\n\tfor i = 1, num do\r\n\t\ty = csObj:funcInOutParam(x)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSTwoMemberFunc(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tfor i = 1, num do\r\n\t\ty = csObj:funcTwoParam(0, 0)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticBaseMember_get(num)\r\n\tfor i = 1, num do\r\n\t\tlocal x = ClassLuaCallCS.sId\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticBaseMember_set(num)\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sId = 0\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticClassMember_get(num)\r\n\tfor i = 1, num do\r\n\t\tlocal x = ClassLuaCallCS.sParamClass\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticClassMember_set(num)\r\n\tlocal x = CS.ParaClass()\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sParamClass = x\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticStructMember_get(num)\r\n\tfor i = 1, num do\r\n\t\tlocal x = ClassLuaCallCS.sParamStruct\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticStructMember_set(num)\r\n\tlocal x = CS.ParaStruct()\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sParamStruct = x\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticVec3Member_get(num)\r\n\tfor i = 1, num do\r\n\t\tlocal x = ClassLuaCallCS.sParamVec3\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticVec3Member_set(num)\r\n\tlocal x = CS.UnityEngine.Vector3(0, 0 , 0)\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sParamVec3 = x\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticBaseMemberFunc(num)\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sFuncBaseParam(0)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticClassMemberFunc(num)\r\n\tlocal clsObj = CS.ParaClass()\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sFuncClassParam(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticStructMemberFunc(num)\r\n\tlocal clsObj = CS.ParaStruct()\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sFuncStructParam(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticVec3MemberFunc(num)\r\n\tlocal clsObj = CS.UnityEngine.Vector3(0, 0 , 0)\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sFuncVec3Param(clsObj)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticInMemberFunc(num)\r\n\tlocal x = 0\r\n\tfor i = 1, num do\r\n\t\tClassLuaCallCS.sFuncInParam(x)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticOutMemberFunc(num)\r\n\tlocal x\r\n\tfor i = 1, num do\r\n\t\tx = ClassLuaCallCS.sFuncOutParam()\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticInOutMemberFunc(num)\r\n\tlocal x = 0\r\n\tlocal y\r\n\tfor i = 1, num do\r\n\t\ty = ClassLuaCallCS.sFuncInOutParam(x)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSStaticTwoMemberFunc(num)\r\n\tfor i = 1, num do\r\n\t\ty = ClassLuaCallCS.sFuncTwoParam(0, 0)\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSEnumFunc_get(num)\r\n    local csObj = ClassLuaCallCS()\r\n\tfor i = 1,  num do \r\n\t\tlocal x = csObj.enumParam\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSEnumFunc_set(num)\r\n    local csObj = ClassLuaCallCS()\r\n    local one = ClassLuaCallCS.LuaEnum.ONE\r\n\tfor i = 1, num do \r\n\t\tcsObj.enumParam = one\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSArrayFunc_get(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal csArray = csObj.array\r\n\tfor i = 1, num do \r\n\t\tlocal x = csArray[0]\r\n\tend\r\nend\r\n\r\nfunction LuaAccessCSArrayFunc_set(num)\r\n\tlocal csObj = ClassLuaCallCS()\r\n\tlocal csArray = csObj.array\r\n\tfor i = 1, num do \r\n\t\tcsArray[0] = 1\r\n\tend\r\nend\r\n\r\nfunction LuaAddRemoveCB(num)\r\n\tlocal csObj = ClassLuaCallCS();\r\n    local function cb()\r\n\tend\r\n\tfor i = 1, num do\r\n\t\tcsObj:NullEvent('+', cb)\r\n\t\tcsObj:NullEvent('-', cb)\r\n\tend\r\nend\r\n\r\nfunction LuaBaseParaCB()\r\n\tlocal csObj = ClassLuaCallCS();\r\n\tcsObj:BaseParaEvent('+', function(x)\r\n\tend)\r\n\tcsObj:InvokeBaseParaCB()\r\nend\r\n\r\nfunction LuaClassParaCB()\r\n\tlocal csObj = ClassLuaCallCS();\r\n\tcsObj:ClassParaEvent('+', function(x)\r\n\tend)\r\n\tcsObj:InvokeClassParaCB()\r\nend\r\n\r\nfunction LuaStructParaCB()\r\n\tlocal csObj = ClassLuaCallCS();\r\n\tcsObj:StructParaEvent('+', function(x)\r\n\tend)\r\n\tcsObj:InvokeStructParaCB()\r\nend\r\n\r\nfunction LuaVec3ParaCB()\r\n\tlocal csObj = ClassLuaCallCS();\r\n\tcsObj:Vec3ParaEvent('+', function(x)\r\n\tend)\r\n\tcsObj:InvokeVec3ParaCB()\r\nend\r\n\r\nfunction LuaConstructClass(num)\r\n\tfor i = 1, num do\r\n\t\tlocal clsObj = CS.ParaClass()\r\n\tend\r\nend\r\n\r\nfunction LuaConstructStruct(num)\r\n\tfor i = 1, num do\r\n\t\tlocal structObj = CS.ParaStruct()\r\n\tend\r\nend\r\n"
  },
  {
    "path": "Test/PrefTest/Resources/luaTest.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 14cd7781d98aaeb419b3c2c121a8c609\ntimeCreated: 1476275211\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/PrefTest/xLuaPerfTest/Main.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 1dd456d13ecffe440b0f1e3187d1d3d3\ntimeCreated: 1467600712\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/PrefTest/xLuaPerfTest/PeformentTestConfig.cs",
    "content": "﻿using System.Collections.Generic;\r\nusing System;\r\nusing UnityEngine;\r\nusing XLua;\r\n\r\n\r\npublic static class PeformentTestConfig {\r\n\r\n    [LuaCallCSharp]\r\n    public static List<Type> LuaCallCSharp\r\n    {\r\n        get\r\n        {\r\n            return new List<Type>()\r\n            {\r\n                typeof(System.Object),\r\n                typeof(UnityEngine.Object),\r\n                typeof(Vector3),\r\n            };\r\n        }\r\n    }\r\n    \r\n    [BlackList]\r\n    public static List<List<string>> BlackList\r\n    {\r\n        get\r\n        {\r\n            return new List<List<string>>()\r\n            {\r\n                new List<string>(){\"UnityEngine.WWW\", \"movie\"},\r\n                new List<string>(){\"UnityEngine.Texture2D\", \"alphaIsTransparency\"},\r\n                new List<string>(){\"UnityEngine.Security\", \"GetChainOfTrustValue\"},\r\n                new List<string>(){\"UnityEngine.CanvasRenderer\", \"onRequestRebuild\"},\r\n                new List<string>(){\"UnityEngine.Light\", \"areaSize\"},\r\n                new List<string>(){\"UnityEngine.AnimatorOverrideController\", \"PerformOverrideClipListCleanup\"},\r\n    #if !UNITY_WEBPLAYER\r\n                new List<string>(){\"UnityEngine.Application\", \"ExternalEval\"},\r\n    #endif\r\n                new List<string>(){\"UnityEngine.GameObject\", \"networkView\"}, //4.6.2 not support\r\n                new List<string>(){\"UnityEngine.Component\", \"networkView\"},  //4.6.2 not support\r\n                new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.FileInfo\", \"SetAccessControl\", \"System.Security.AccessControl.FileSecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"SetAccessControl\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"CreateSubdirectory\", \"System.String\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n                new List<string>(){\"System.IO.DirectoryInfo\", \"Create\", \"System.Security.AccessControl.DirectorySecurity\"},\r\n            };\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Test/PrefTest/xLuaPerfTest/PeformentTestConfig.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 0668986d04994e448939e21fb74c5d5a\ntimeCreated: 1475977076\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/PrefTest/xLuaPerfTest/PerfMain.cs",
    "content": "﻿using UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\nusing System.IO;\r\nusing System;\r\n\r\n[LuaCallCSharp]\r\npublic static class TestUtils\r\n{\r\n    public static bool IsAndroid()\r\n    {\r\n#if UNITY_ANDROID\r\n        return true;\r\n#else\r\n        return false;\r\n#endif\r\n    }\r\n}\r\n\r\n[CSharpCallLua]\r\npublic delegate void PerfTest(int load);\r\n\r\npublic class PerfMain : MonoBehaviour {\r\n\tstring resultPath = \"\";\r\n\r\n\tLuaEnv luaenv;\r\n\r\n\tStreamWriter sw;\r\n\r\n    System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();\r\n\r\n\t// Use this for initialization\r\n\tvoid Start () {\r\n#if UNITY_ANDROID && !UNITY_EDITOR\r\n\t    resultPath = \"/sdcard/testResult_android.log\";\r\n#elif UNITY_IPHONE || UNITY_IOS\r\n\t    resultPath = Application.persistentDataPath + \"/testResult_iOS.log\";\r\n#elif UNITY_STANDALONE_WIN || UNITY_EDITOR\r\n        resultPath = Application.dataPath + \"/../testResult_windows.log\";\r\n#else\r\n        resultPath = \"\";\r\n#endif\r\n        var start = Time.realtimeSinceStartup;\r\n        var startMem = System.GC.GetTotalMemory(true);\r\n        luaenv = new LuaEnv();\r\n        Debug.Log(\"start cost: \" + (Time.realtimeSinceStartup - start));\r\n        var endMem = System.GC.GetTotalMemory(true);\r\n        Debug.Log(\"startMem: \" + startMem + \", endMem: \" + endMem + \", \" + \"cost mem: \" + (endMem - startMem));\r\n        luaenv.DoString(\"require 'luaTest'\");\r\n    }\r\n\r\n    // Update is called once per frame\r\n    void Update () {\r\n\t\r\n\t}\r\n\r\n\tvoid OnGUI()\r\n\t{\r\n\t\tif (GUI.Button (new Rect (10, 100, 300, 150), \"Start\")) {\r\n            FileStream fs = new FileStream(resultPath, FileMode.Create);\r\n            sw = new StreamWriter(fs);\r\n\r\n            StartCSCallLua();\r\n\t\t\tStartLuaCallCS ();\r\n\t\t\tStartAddRemoveCB ();\r\n\t\t\tStartCSCallLuaCB ();\r\n\t\t\tStartConstruct ();\r\n\r\n\t\t\tsw.Close ();\r\n\t\t}\r\n\t}\r\n\r\n    //------------------------------------------------------------------------------------------------------\r\n\r\n    const double TEST_MIN_DURATION = 800;\r\n    const double TEST_DURATION = 1000;\r\n\r\n    private int PerformentTest(string title, int load, PerfTest execute)\r\n    {\r\n        stopWatch.Reset();\r\n        stopWatch.Start();\r\n        execute(load);\r\n        stopWatch.Stop();\r\n\r\n        /*int load_added = 0;\r\n\r\n        if (stopWatch.ElapsedMilliseconds < (TEST_MIN_DURATION))\r\n        {\r\n            double dur_added = TEST_DURATION - stopWatch.ElapsedMilliseconds;\r\n            load_added = (int)(load * (dur_added / stopWatch.ElapsedMilliseconds));\r\n        }\r\n\r\n        if (load_added > 0)\r\n        {\r\n            stopWatch.Start();\r\n            execute(load_added);\r\n            stopWatch.Stop();\r\n        }\r\n\r\n        int cps = CPS(load + load_added, stopWatch.ElapsedMilliseconds);*/\r\n\r\n        int cps = CPS(load, stopWatch.ElapsedMilliseconds);\r\n\r\n        if (title != null)\r\n        {\r\n            string log = title + cps + \", elapsed :\" + stopWatch.ElapsedMilliseconds;\r\n            Debug.Log(log);\r\n            sw.WriteLine(log);\r\n        }\r\n\r\n        return cps;\r\n    }\r\n\r\n\tprivate void StartCSCallLua()\r\n\t{\r\n        int LOOP_TIMES = 1000000;\r\n        Debug.Log (\"C# call lua :\");\r\n\t\tsw.WriteLine (\"C# call lua :\");\r\n\r\n\t\tFuncBasePara funcBaseParm = luaenv.Global.Get<FuncBasePara>(\"FuncBasePara\");\r\n        PerformentTest(\"C# call lua : base parameter function :\", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                funcBaseParm(i);\r\n            }\r\n        });\r\n\r\n        FuncClassPara funcClassPara = luaenv.Global.Get<FuncClassPara> (\"FuncClassPara\");\r\n\t\tParaClass paraClass = new ParaClass ();\r\n        PerformentTest(\"C# call lua : class parameter function :\", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                funcClassPara(paraClass);\r\n            }\r\n        });\r\n\r\n        FuncStructPara funcStructPara = luaenv.Global.Get<FuncStructPara> (\"FuncStructPara\");\r\n\t\tParaStruct paraStruct = new ParaStruct ();\r\n        PerformentTest(\"C# call lua : struct parameter function :\", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                funcStructPara(paraStruct);\r\n            }\r\n        });\r\n\r\n        FuncTwoBasePara funcTwoBasePara = luaenv.Global.Get<FuncTwoBasePara> (\"FuncTwoBasePara\");\r\n        PerformentTest(\"C# call lua : two base parameter function :\", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                funcTwoBasePara(i, i);\r\n            }\r\n        });\r\n\r\n        sw.WriteLine (\"C# access lua table : \");\r\n\r\n\t\tITableAccess iTAccess = luaenv.Global.Get<ITableAccess> (\"luaTable\");\r\n        PerformentTest(\"C# access lua table : access member, get : \", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                int x = iTAccess.id;\r\n            }\r\n        });\r\n\r\n        PerformentTest(\"C# access lua table : access member, set : \", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                iTAccess.id = 0;\r\n            }\r\n        });\r\n\r\n        PerformentTest(\"C# access lua table : access member function : \", LOOP_TIMES, loop_times =>\r\n        {\r\n            for (int i = 0; i < loop_times; i++)\r\n            {\r\n                iTAccess.func();\r\n            }\r\n        });\r\n\r\n    }\r\n\r\n\tprivate void StartLuaCallCS()\r\n\t{\r\n        int LOOP_TIMES = 1000000;\r\n\r\n        Debug.Log (\"lua call C# member : \");\r\n\t\tsw.WriteLine (\"lua call C# member : \");\r\n\r\n\t\tPerfTest func = luaenv.Global.Get<PerfTest> (\"LuaAccessCSBaseMember_get\");\r\n        PerformentTest(\"lua call C# member : base member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSBaseMember_set\");\r\n        PerformentTest(\"lua call C# member : base member, set : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest> (\"LuaAccessCSClassMember_get\");\r\n        PerformentTest(\"lua call C# member : class member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSClassMember_set\");\r\n        PerformentTest(\"lua call C# member : class member, set : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessStructMember_get\");\r\n        PerformentTest(\"lua call C# member : struct member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessStructMember_set\");\r\n        PerformentTest(\"lua call C# member : struct member, set : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessVec3Member_get\");\r\n        PerformentTest(\"lua call C# member : vector3 member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessVec3Member_set\");\r\n        PerformentTest(\"lua call C# member : vector3 member, set : \", LOOP_TIMES, func);\r\n\r\n\t\tDebug.Log (\"lua call C# member funtion : \");\r\n\t\tsw.WriteLine (\"lua call C# member funtion : \");\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSBaseMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : base parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSClassMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : class parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStructMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : struct parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSVec3MemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : vector3 parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSInMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : input parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSOutMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : output parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSInOutMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : in & output parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSTwoMemberFunc\");\r\n        PerformentTest(\"lua call C# member funtion : two parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tDebug.Log (\"lua call static memeber : \");\r\n\t\tsw.WriteLine (\"lua call static memeber :\");\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticBaseMember_get\");\r\n        PerformentTest(\"lua call C# static member : base member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSStaticBaseMember_set\");\r\n        PerformentTest(\"lua call C# static member : base member, set : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticClassMember_get\");\r\n        PerformentTest(\"lua call C# static member : class member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSStaticClassMember_set\");\r\n        PerformentTest(\"lua call C# static member : class member, set : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticStructMember_get\");\r\n        PerformentTest(\"lua call C# static member : struct member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSStaticStructMember_set\");\r\n        PerformentTest(\"lua call C# static member : struct member, set : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticVec3Member_get\");\r\n        PerformentTest(\"lua call C# static member : vector3 member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSStaticVec3Member_set\");\r\n        PerformentTest(\"lua call C# static member : vector3 member, set : \", LOOP_TIMES, func);\r\n\r\n\t\tDebug.Log (\"lua call C# static member funtion : \");\r\n\t\tsw.WriteLine (\"lua call C# member funtion : \");\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticBaseMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : base parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticClassMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : class parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticStructMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : struct parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticVec3MemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : vector3 parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticInMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : input parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticOutMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : output parameter member function : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticInOutMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : in & output parameter member function : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaAccessCSStaticTwoMemberFunc\");\r\n        PerformentTest(\"lua call C# static member funtion : two parameter member function : \", LOOP_TIMES, func);\r\n\r\n        Debug.Log(\"lua call C# array & num : \");\r\n        sw.WriteLine(\"lua call C# array & enum : \");\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSEnumFunc_get\");\r\n        PerformentTest(\"lua call C# member : enum member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSEnumFunc_set\");\r\n        PerformentTest(\"lua call C# member : enum member, set : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSArrayFunc_get\");\r\n        PerformentTest(\"lua call C# member : array member, get : \", LOOP_TIMES, func);\r\n\r\n        func = luaenv.Global.Get<PerfTest>(\"LuaAccessCSArrayFunc_set\");\r\n        PerformentTest(\"lua call C# member : array member, set : \", LOOP_TIMES, func);\r\n\t}\r\n\r\n\tprivate void StartConstruct()\r\n\t{\r\n        int LOOP_TIMES = 1000000;\r\n        Debug.Log (\"lua call construct :\");\r\n        sw.WriteLine(\"lua call construct :\");\r\n        PerfTest func = luaenv.Global.Get<PerfTest> (\"LuaConstructClass\");\r\n        PerformentTest(\"lua construct class : \", LOOP_TIMES, func);\r\n\t\t\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaConstructStruct\");\r\n        PerformentTest(\"lua construct struct : \", LOOP_TIMES, func);\r\n\t}\r\n\r\n\tprivate void StartAddRemoveCB()\r\n\t{\r\n        int LOOP_TIMES = 200000;\r\n        Debug.Log (\"lua add & remove callback : \");\r\n\t\tsw.WriteLine (\"lua add & remove call back : \");\r\n\r\n\t\tPerfTest func = luaenv.Global.Get<PerfTest> (\"LuaAddRemoveCB\");\r\n        PerformentTest(\"lua add & remove callback : \", LOOP_TIMES, func);\r\n\t}\r\n\r\n\tprivate void StartCSCallLuaCB()\r\n\t{\r\n        int LOOP_TIMES = 1000000;\r\n        Debug.Log (\"C# call lua callbak :\");\r\n\t\tsw.WriteLine (\"C# call lua callbak :\");\r\n\r\n\t\tPerfTest func = luaenv.Global.Get<PerfTest> (\"LuaBaseParaCB\");\r\n        PerformentTest(\"invoke base param callback : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaClassParaCB\");\r\n        PerformentTest(\"invoke class param callback : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaStructParaCB\");\r\n        PerformentTest(\"invoke struct param callback : \", LOOP_TIMES, func);\r\n\r\n\t\tfunc = luaenv.Global.Get<PerfTest> (\"LuaVec3ParaCB\");\r\n        PerformentTest(\"invoke vector3 param callback : \", LOOP_TIMES, func);\r\n\t}\r\n//------------------------------------------------------------------------------------------------------\r\n\r\n\tprivate int CPS(int loop_times, double ms)\r\n\t{\r\n\t\treturn (int)(((double)loop_times) * 1000.0 / ms);\r\n\t}\r\n\r\n//------------------------------------------------------------------------------------------------------\r\n    [CSharpCallLua]\r\n\tpublic delegate void FuncBasePara(int x);\r\n    [CSharpCallLua]\r\n\tpublic delegate void FuncClassPara(ParaClass x);\r\n    [CSharpCallLua]\r\n\tpublic delegate void FuncStructPara(ParaStruct x);\r\n    [CSharpCallLua]\r\n    public delegate void FuncTwoBasePara(int x, int y);\r\n\r\n}\r\n\r\n[CSharpCallLua]\r\npublic delegate void BaseParaEventHandler(int x);\r\n[CSharpCallLua]\r\npublic delegate void ClassParaEventHandler(ParaClass x);\r\n[CSharpCallLua]\r\npublic delegate void StructParaEventHandler(ParaStruct x);\r\n[CSharpCallLua]\r\npublic delegate void Vec3ParamEventHandler(Vector3 x);\r\n[CSharpCallLua]\r\npublic delegate void NullEventHandler();\r\n\r\n[LuaCallCSharp]\r\npublic class ParaClass\r\n{}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct ParaStruct\r\n{}\r\n\r\n[CSharpCallLua]\r\npublic interface ITableAccess\r\n{\r\n\tint id { get; set;}\r\n\tvoid func();\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class ClassLuaCallCS\r\n{\r\n    public int[] array = new int[5];\r\n\r\n    [LuaCallCSharp]\r\n    public enum LuaEnum\r\n    {\r\n        ONE,\r\n        TWO,\r\n        THREE,\r\n        FOUR,\r\n        FIVE\r\n    };\r\n\r\n    public LuaEnum enumParam;\r\n\r\n\r\n\tpublic event BaseParaEventHandler BaseParaEvent;\r\n\tpublic event ClassParaEventHandler ClassParaEvent;\r\n\tpublic event StructParaEventHandler StructParaEvent;\r\n\tpublic event Vec3ParamEventHandler Vec3ParaEvent;\r\n\tpublic event NullEventHandler NullEvent;\r\n\r\n\tpublic int id;\r\n\tpublic ParaClass paraClass = new ParaClass ();\r\n\tpublic ParaStruct paraStruct = new ParaStruct();\r\n\tpublic Vector3 vec3Member;\r\n\r\n\tpublic void funcBaseParam(int x)\r\n\t{}\r\n\r\n\tpublic void funcClassParam(ParaClass x)\r\n\t{}\r\n\r\n\tpublic void funcStructParam(ParaStruct x)\r\n\t{}\r\n\r\n\tpublic void funcVec3Param(Vector3 x)\r\n\t{}\r\n\r\n\tpublic void funcInParam(ref int x)\r\n\t{}\r\n\r\n\tpublic void funcOutParam(out int x)\r\n\t{\r\n\t\tx = 0;\r\n\t}\r\n\r\n\tpublic void funcInOutParam(ref int x, out int y)\r\n\t{\r\n\t\ty = 0;\r\n\t}\r\n\r\n\tpublic void funcTwoParam(int x, int y)\r\n\t{\r\n\t}\r\n\r\n\tpublic static int sId;\r\n\tpublic static ParaClass sParamClass = new ParaClass();\r\n\tpublic static ParaStruct sParamStruct = new ParaStruct();\r\n\tpublic static Vector3 sParamVec3;\r\n\r\n\tpublic static void sFuncBaseParam(int x)\r\n\t{}\r\n\t\r\n\tpublic static void sFuncClassParam(ParaClass x)\r\n\t{}\r\n\t\r\n\tpublic static void sFuncStructParam(ParaStruct x)\r\n\t{}\r\n\t\r\n\tpublic static void sFuncVec3Param(Vector3 x)\r\n\t{}\r\n\t\r\n\tpublic static void sFuncInParam(ref int x)\r\n\t{}\r\n\t\r\n\tpublic static void sFuncOutParam(out int x)\r\n\t{\r\n\t\tx = 0;\r\n\t}\r\n\t\r\n\tpublic static void sFuncInOutParam(ref int x, out int y)\r\n\t{\r\n\t\ty = 0;\r\n\t}\r\n\r\n\tpublic static void sFuncTwoParam(int x, int y)\r\n\t{\r\n\r\n\t}\r\n\r\n\tpublic void InvokeBaseParaCB()\r\n\t{\r\n\t\tfor (int i = 0; i < 1000000; i++) {\r\n\t\t\tBaseParaEvent(0);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void InvokeClassParaCB()\r\n\t{\r\n\t\tParaClass paraCls = new ParaClass ();\r\n\t\tfor (int i = 0; i < 1000000; i++) {\r\n\t\t\tClassParaEvent(paraCls);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void InvokeStructParaCB()\r\n\t{\r\n\t\tParaStruct paraStruct = new ParaStruct ();\r\n\t\tfor (int i = 0; i < 1000000; i++) {\r\n\t\t\tStructParaEvent(paraStruct);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void InvokeVec3ParaCB()\r\n\t{\r\n\t\tVector3 paraVec3 = new Vector3 (0, 0, 0);\r\n\t\tfor (int i = 0; i < 1000000; i++) {\r\n\t\t\tVec3ParaEvent(paraVec3);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "Test/PrefTest/xLuaPerfTest/PerfMain.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 28450407178d7a04fa5767bb74363a1f\ntimeCreated: 1467600713\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/README.md",
    "content": "## 目录说明\r\n\r\n* UnitTest ： 单元测试用例\r\n* PrefTest ： 性能测试用例\r\n\r\n## 使用说明\r\n\r\n* 把对应目录下的所有目录拷贝到Assets下，比如你要执行单元测试用例，把UnitTest下两个目录都拷贝到Assets下，然后运行main.unity；\r\n* luajit版本比lua53版本性能要好很多，打开HOTFIX_ENABLE或者THREAD_SAFT宏，性能会略降，因为会对所有C#调用lua的地方都会加上锁，所以你要和其它方案对比的话，用luajit版本测试并确认HOTFIX_ENABLE或者THREAD_SAFT没打开；\r\n\r\n## 性能用例的说明\r\n\r\n* 用例和网上流行的不太一样，原因是：\r\n  * Unity API本身的开销会影响到测试结果。举个例子：方案A的Lua调用C#函数开销是1ms，方案B是2ms，那么结论应该是A方案性能是B方案两倍，但如果被调用C#函数本身耗时100ms，那结论就是两个方案性能差不多，甚至有时会因为误差得出B方案性能更好的结论；\r\n  * 如果测试中包含重载函数，对比也是不恰当的，因为每个方案的生成代码对于重载判断的顺序不一定一样，不一样的时候，对比也意义不大；\r\n  * 测试Lua调用C#部分用例选择了Vector3，这其实是错误的，市面上大多方案的Vector3是完全在Lua测重新实现，完全没有达到测试“Lua调用C#”的目的；\r\n* xLua本质上做C#和lua之间的适配，所以所有用例的设计原则都是被调用方无开销，比如函数都是直接return\r\n\r\n## 几个值类型的方法的性能说明\r\n\r\n* 前面也提到，其它方案的Vector3（相类似的还有Vector2，Vector4，Quaternion，Color等）由于直接在lua测实现，而xLua默认仍然是调用C#的实现，测试这些类型的方法的话，xLua性能相比会低很多\r\n  * 你可以选择在lua实现这些方法，配合xlua.genaccessor，性能可以达到同一个数量级。\r\n  * xLua一直坚持使用C#原生实现，一年多的项目应用中，也没有反馈因此而造成的性能问题，应该性能是够用的，如果真的出现不够用的情况，选择在lua实现这块逻辑也是不恰当的，应该直接在C#实现比较合适些。\r\n\r\n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/D.lua",
    "content": "strValue = \"D.lua\""
  },
  {
    "path": "Test/UnitTest/StreamingAssets/D.lua.meta",
    "content": "fileFormatVersion: 2\nguid: af3706b030ae190448b7feef19dbe395\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/csCallLua.lua",
    "content": "require(\"ltest.init\")\r\n\r\nfunction islua53() return not not math.type end\r\n-- for test case\r\nCMyTestCaseCSCallLua = TestCase:new()\r\nfunction CMyTestCaseCSCallLua:new(oo)\r\n    local o = oo or {}\r\n    o.count = 1\r\n    \r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.SetUpTestCase(self)\r\n    self.count = 1 + self.count\r\n\tself.tcForTestCSCallLuaObj = CS.TCForTestCSCallLua()\r\n\tprint(\"CMyTestCaseCSCallLua.SetUpTestCase\")\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.TearDownTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseCSCallLua.TearDownTestCase\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseCSCallLua.SetUp(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseCSCallLua.SetUp\")\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.TearDown(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseCSCallLua.TearDown\")\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testDoString2LoadLua_Step_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testDoString2LoadLua_Step_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testDoString2LoadLua_Step_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testDoString2LoadLua_Step_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testDoString2LoadLua_Step_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testDoString2LoadLua_Step_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testRequire2LoadLua_Step_1_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testRequire2LoadLua_Step_1_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testRequire2LoadLua_Step_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testRequire2LoadLua_Step_4()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\n\r\nfunction CMyTestCaseCSCallLua.testRequire2LoadLua_Step_5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testRequire2LoadLua_Step_5()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend \r\n\r\nfunction CMyTestCaseCSCallLua.testRequire2LoadLua_Step_6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testRequire2LoadLua_Step_6()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testRequire2LoadLua_Step_7(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testRequire2LoadLua_Step_7()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testAddLoader2LoadLua_Step_1_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testAddLoader2LoadLua_Step_1_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testAddLoader2LoadLua_Step_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testAddLoader2LoadLua_Step_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testAddLoader2LoadLua_Step_6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testAddLoader2LoadLua_Step_6()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testAddLoader2LoadLua_Step_7(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testAddLoader2LoadLua_Step_7()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeBool_Step_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeBool_Step_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeString_Step_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeString_Step_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToByte(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToByte()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToSByte(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToSByte()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToShort(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToShort()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToUShort(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToUShort()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToInt(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToInt()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToUInt(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToUInt()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToLong(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToLong()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToULong(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToULong()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToDouble(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToDouble()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToChar(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToChar()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToFloat(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToFloat()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataTypeNumberToDecimal(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataTypeNumberToDecimal()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataType_Step_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataType_Step_4()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetBasicDataType_Step_5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetBasicDataType_Step_5()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_4()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_5()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_1_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_1_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_1_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_1_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToClass_Step_1_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToClass_Step_1_4()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToInterface_Step_6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToInterface_Step_6()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToInterface_Step_7(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToInterface_Step_7()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToInterface_Step_8(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToInterface_Step_8()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToInterface_Step_9(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToInterface_Step_9()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToInterface_Step_6_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToInterface_Step_6_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToDic_Step_10(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToDic_Step_10()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToDic_Step_11_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToDic_Step_11_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToDic_Step_11_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToDic_Step_11_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToDic_Step_11_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToDic_Step_11_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToList_Step_12(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToList_Step_12()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToList_Step_13_1_int(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToList_Step_13_1_int()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToList_Step_13_1_string(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToList_Step_13_1_string()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToList_Step_13_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToList_Step_13_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetTableToLuaTable_Step_14(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetTableToLuaTable_Step_14()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_2_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_2_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_2_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_2_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_2_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_2_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_2_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_2_4()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_5()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_5_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_5_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_5_1_0(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_5_1_0()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\n--[[ ios上il2cpp编译有错，注释掉\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_5_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_5_2()\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n]]\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_6()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToLuaFunc_Step_8(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToLuaFunc_Step_8()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToLuaFunc_Step_9_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToLuaFunc_Step_9_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToLuaFunc_Step_10(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToLuaFunc_Step_10()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToLuaFunc_Step_12(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToLuaFunc_Step_12()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToLuaFunc_Step_13(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToLuaFunc_Step_13()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_7_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_7_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_7_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_7_2()\r\n\tprint(ret.msg)\r\n\tif islua53() then\r\n\t\t--ASSERT_EQ(false, false) --该用例在lua5.3无意义\r\n\t\tASSERT_EQ(ret.result, true)\r\n\telse\r\n\t\tASSERT_EQ(ret.result, true)\r\n\tend\t\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testGetFuncToDelegate_Step_7_3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testGetFuncToDelegate_Step_7_3()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_int_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_int_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_int_2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_int_2()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_string_1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_string_1()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_sbyte(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_sbyte()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_byte(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_byte()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_short(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_short()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_ushort(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_ushort()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_long(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_long()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_ulong(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_ulong()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_double(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_double()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_float(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_float()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_char(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_char()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_BasicType_decimal(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_BasicType_decimal()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_struct(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_struct()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_class(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_class()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_interface(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_interface()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_dict(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_dict()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_list(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_list()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend\r\n\r\nfunction CMyTestCaseCSCallLua.testLuaTableGetSetKeyValue_delegate(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = self.tcForTestCSCallLuaObj:testLuaTableGetSetKeyValue_delegate()\r\n\tprint(ret.msg)\r\n\tASSERT_EQ(ret.result, true)\r\nend"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/csCallLua.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 1f134b58b34a7854ea895e518b4ffb9c\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/genCode.lua",
    "content": "require(\"ltest.init\")\r\n\r\n-- for test case\r\nCMyTestCaseGenCode = TestCase:new()\r\nfunction CMyTestCaseGenCode:new(oo)\r\n    local o = oo or {}\r\n    o.count = 1\r\n    \r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestCaseGenCode.SetUpTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseGenCode.SetUpTestCase\")\r\nend\r\n\r\nfunction CMyTestCaseGenCode.TearDownTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseGenCode.TearDownTestCase\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseGenCode.SetUp(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseGenCode.SetUp\")\r\nend\r\n\r\nfunction CMyTestCaseGenCode.TearDown(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseGenCode.TearDown\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseGenCode.CaseAccess1(self)\r\n    self.count = 1 + self.count\n    if CS.LuaTestCommon.IsIOSPlatform() then\n        return\n    end\r\n\tlocal fileInfo = CS.System.IO.FileInfo(\"abc\")\r\n\tASSERT_EQ(false, fileInfo.Exists)\r\nend\r\n\r\nfunction CMyTestCaseGenCode.CaseAccess2(self)\r\n    self.count = 1 + self.count\n    if CS.LuaTestCommon.IsIOSPlatform() then\n        return\n    end\r\n    if CS.LuaTestCommon.IsXLuaGeneral() then return end\r\n\tlocal resultPath = CS.LuaTestCommon.resultPath\r\n\tresultPath = resultPath..\"ltest_case_list_co.txt\"\r\n\tlocal fileInfo = CS.System.IO.FileInfo(resultPath)\r\n\tlocal access = CS.System.Security.AccessControl.AccessControlSections.None\r\n\tlocal ret, error = pcall(function() fileInfo:GetAccessControl(access) end)\r\n\tASSERT_EQ(false, ret)\r\nend"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/genCode.lua.meta",
    "content": "fileFormatVersion: 2\nguid: d485a1ab7c5b86c459b0a0409164263e\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/init.lua",
    "content": "--[[\n//////////////////////////////////////////////////////////////////////////\n// date : 2013-5-4\n// auth : macroli(idehong@gmail.com)\n// ver  : 0.3\n// desc : ltest - lua tester \n//////////////////////////////////////////////////////////////////////////    \n--]]\n------------------------------------------------------------------------------\n\n--module(..., package.seeall)\n\nVERSION = \"0.51\"\n\n-- for test environment\nTestEnvironment = {}\nfunction TestEnvironment:new(oo)\n    local o = oo or {}\n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction TestEnvironment.privateName(self)\n\treturn \"env_macro\"\t\nend\n\nfunction TestEnvironment.SetUp(self)\t\nend\n\nfunction TestEnvironment.TearDown(self)\t\nend\n\n\n-- for test case\nTestCase = {}\nfunction TestCase:new(oo)\n    local o = oo or {}\n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction TestCase.privateName(self)\n\treturn \"case_macro\"\t\nend\n\nfunction TestCase.SetUpTestCase(self)\t\nend\n\nfunction TestCase.TearDownTestCase(self)\t\nend\n\nfunction TestCase.SetUp(self)\t\nend\n\nfunction TestCase.TearDown(self)\t\nend\n\nrequire(\"ltest.loutput\")\nrequire(\"ltest.lassert\")\n\n\n-- for assert\nlocal _atER = true \t\t\t\t\t\t-- for event result\nlocal _atStopLv = 2 \t\t\t\t\t-- for stop level\nlocal _atStopTip = \"macro_error_stop\"  \t-- for stop level\nlocal _atErrLv = 6 \t\t\t\t\t\t-- for error level\nlocal _atMgr = false\n\nfunction ASSERT_EQ(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertEQ(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_EQ failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_LT(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertLT(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_LT failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_LE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertLE(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_LE failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_GT(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertGT(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_GT failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_GE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertGE(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_GE failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_NE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertNE(v1, v2):PCR(bNoP, _atErrLv, \"ASSERT_NE failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_NEAR(v1, v2, nearValue, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertNear(v1, v2, nearValue):PCR(bNoP, _atErrLv, \"ASSERT_NEAR failed\", v1, v2); return _atMgr\nend\n\nfunction ASSERT_TRUE(v1, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertTrue(v1):PCR1(bNoP, _atErrLv, \"ASSERT_TRUE failed\", v1); return _atMgr\nend\n\nfunction ASSERT_FALSE(v1, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atER = _atMgr:AssertFalse(v1):PCR1(bNoP, _atErrLv, \"ASSERT_FALSE failed\", v1); return _atMgr\nend\n\n\nfunction EXCEPT_EQ(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertEQ(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_EQ failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_LT(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertLT(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_LT failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_LE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertLE(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_LE failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_GT(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertGT(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_GT failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_GE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertGE(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_GE failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_NE(v1, v2, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertNE(v1, v2):PCR(bNoP, _atErrLv, \"EXCEPT_NE failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_NEAR(v1, v2, nearValue, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertNear(v1, v2, nearValue):PCR(bNoP, _atErrLv, \"EXCEPT_NEAR failed\", v1, v2); return _atMgr\nend\n\nfunction EXCEPT_TRUE(v1, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertTrue(v1):PCR1(bNoP, _atErrLv, \"EXCEPT_TRUE failed\", v1); return _atMgr\nend\n\nfunction EXCEPT_FALSE(v1, bNoP)\n\tif not _atMgr then return end\n\tif not _atER then error(_atStopTip, _atStopLv) end\n\t_atMgr:AssertFalse(v1):PCR1(bNoP, _atErrLv, \"EXCEPT_FALSE failed\", v1); return _atMgr\nend\n\n\n-- for test mgr\nlocal TestMgr = {}\nfunction TestMgr:new(oo)\n    local o = {\n    \tdata = {\n\t    \toOut = false, generalGlobalName=\"global\",\n\t    \t\n\t    \t-- suite seq\t    \t\n\t    \tgeneralSuiteNo=2,  \n\t    \t\n\t    \t-- global suite value\n\t    \tglobal={ prop={name=\"global\", generalNo=1,bSys=true, oCls=false, no=1, costTime=0, totalNum=0, okNum=0, failedNum=0,}, list={}},\n\n\t\t\t-- key for name, value = {prop={}, list={}}\n\t    \tall_suite = {}, \n\t    \t\n\t    \t-- filter case name\n\t    \tnotcase = {privateName=true, SetUpTestCase=true, TearDownTestCase=true, SetUp=true, TearDown=true, TestCase=true, new=new},\n    \t},\n    \t\n    \t-- user use para\n    \tpara = {\n    \t\tltest_list_tests=false,\t \t-- List the names of all tests instead of running them.\n    \t\tltest_repeat=false,\t\t\t-- Run the tests repeatedly; use a negative count to repeat forever.\n    \t\tltest_filter=false,\t\t\t-- Run only the tests whose name matches\n\n    \t\tltest_list_falied=false,\t-- Generate an TXT report in the given directory or with the given file name\n    \t\tltest_output=false,\t\t\t-- Generate an XML report in the given directory or with the given file name\n    \t\tltest_silence=false,\t\t-- if true then silence output\n    \t},\n    \t\n    \t-- stat info\n    \tstat = {},\n    }\n    \n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction TestMgr.Init(self, tPara)\t\n\tif tPara and tPara.ltest_list_tests then self.para.ltest_list_tests = tPara.ltest_list_tests end\n\tif tPara and tPara.ltest_repeat then self.para.ltest_repeat = tPara.ltest_repeat end\n\tif tPara and tPara.ltest_filter then self.para.ltest_filter = tPara.ltest_filter end\n\tif tPara and tPara.ltest_list_falied then self.para.ltest_list_falied = tPara.ltest_list_falied end\n\tif tPara and tPara.ltest_output then self.para.ltest_output = tPara.ltest_output end\n\tif tPara and tPara.ltest_silence then self.ltest_silence = tPara.ltest_silence end\n\t\n\tlocal tOutputOther = {}\n\tif self.para.ltest_list_tests then\n\t\tlocal oTmp = CAllCaseListOutPut:new({filename=self.para.ltest_list_tests})\n\t\ttable.insert(tOutputOther, oTmp)\n\tend\n\tif self.para.ltest_list_falied then\n\t\tlocal oTmp = CFailedCaseListOutPut:new({filename=self.para.ltest_list_falied})\n\t\ttable.insert(tOutputOther, oTmp)\n\tend\n\t\n\tself.data.oOutput = CmdTestOutPut:new({outer = tOutputOther, silence=self.ltest_silence})\n\t_atMgr = CAssertMgr:new({oOutput=self.data.oOutput})\n\t\n\tself.data.all_suite[self.data.generalGlobalName] = self.data.global\nend\n\nfunction TestMgr.Fini(self)\t\n\tself.data.all_suite = {}\n\tself.data.generalSuiteNo = 2\n\tself.data.global={ prop={name=\"global\", generalNo=1,bSys=true, oCls=false, no=1, costTime=0, totalNum=0, okNum=0, failedNum=0,}, list={}}\nend\n\nfunction TestMgr.AddSuite(self, strSuiteName, oCls, filterCaseName)\t\n\tif not oCls or  TestCase:privateName() ~= oCls:privateName() or self.data.notcase[strSuiteName] then return false end\n\tlocal strFind = \"Test\"\n\tif filterCaseName and type(filterCaseName) == \"string\" then strFind = filterCaseName end\n\t\t\n\tlocal tSuite = self:addRealSuite(strSuiteName, oCls)\n\tif not tSuite then return false end\n\t\n\tlocal tCaseKey = {}\n\tfor k, v in pairs(oCls) do\n\t\tif type(k) == \"string\" and \"__\" ~= string.sub(k, 1, 2) and type(v) == \"function\" and string.find(k, strFind) and not self.data.notcase[k] then\n\t\t\ttable.insert(tCaseKey, k)\n\t\tend\n\tend\n\tfor k, v in pairs(oCls.__index) do\n\t\tif type(k) == \"string\" and \"__\" ~= string.sub(k, 1, 2) and type(v) == \"function\" and string.find(k, strFind) and not self.data.notcase[k] then\n\t\t\ttable.insert(tCaseKey, k)\n\t\tend\n\tend\n\t\n\ttable.sort(tCaseKey)\n\tfor k, v in pairs(tCaseKey) do\n\t\tself:addRealCase(tSuite, v, oCls[v], nil)\n\tend\n\t\n\treturn true\nend\n\nfunction TestMgr.AddCase(self, strCaseName, oFun, tPara, strSuiteName, oCls)\n\tif type(oFun) ~= \"function\" or type(strCaseName) ~= type(\"\") then return false end\t\n\t\n\tlocal tSuite  = false\n\tif strSuiteName then \n\t\ttSuite = self:addRealSuite(strSuiteName, oCls)\n\telse\n\t\ttSuite = self:addRealSuite(self.data.generalGlobalName, oCls)\t\n\tend\n\t\n\tif tSuite then return self:addRealCase(tSuite, strCaseName, oFun, tPara) else return false\tend\nend\n\nfunction TestMgr.Run(self, oEnv)\n\tlocal oOutput = self.data.oOutput\n\tif self.para.ltest_filter and type(self.para.ltest_filter) == type(\"\") then \n\t\toOutput:FilterInfo(\"Note: ltest filter = %s\\r\\n\", self.para.ltest_filter)\n\tend\n\t\t\n\tlocal iCount, iGroup, tSuiteCaseKey = self:countAllCase(self.para.ltest_filter)\n\toOutput:BeginGroupSuite( iCount, iGroup )\n\t\n\tlocal bUseEnv = (oEnv and TestEnvironment:privateName() == oEnv:privateName())\n\tif bUseEnv then\t oEnv:SetUp(); oOutput:BeginGroupEnv() end\n\n\tlocal tFailedList = self:runAllSuite(oOutput, tSuiteCaseKey)\n\t\n\tif bUseEnv then\toEnv:TearDown(); oOutput:EndGroupEnv() end\t\n\t\n\tlocal iTotalTime = 0\n\tfor k, v in pairs(self.data.all_suite) do\n\t\tiTotalTime = iTotalTime + v.prop.costTime\n\tend\n\n\toOutput:EndGroupSuite(iTotalTime)\n\toOutput:StaticInfo()\n\t\n\tself.data.stat = oOutput:GetStaticInfo()\n\tself:Fini()\n\treturn 0\nend\n\nfunction TestMgr.GetStatInfo(self)\n\treturn self.data.stat\nend\n\nfunction TestMgr.countAllCase(self, strFilter)\t\n\t-- parset filter\n\tlocal tFilter = {}\n\tlocal iPosStart, iPosEnd = 1, 1\n\twhile strFilter do\n\t\tiPosEnd = string.find(strFilter, \":\", iPosStart)\n\t\tif not iPosEnd then \n\t\t\ttable.insert(tFilter, string.sub(strFilter, iPosStart, #strFilter - 1) ) \t\t\n\t\t\tbreak\n\t\tend\n\t\ttable.insert(tFilter, string.sub(strFilter, iPosStart, iPosEnd - 3) )  \n\t\tiPosStart = iPosEnd + 1\n\tend\n\t\n\t-- filter case\n\tlocal iCount, iGroup = 0, 0\n\tlocal tSuiteKey = {}\n\tlocal bUsed = true\n\tfor k, v in pairs(self.data.all_suite) do\n\t\tlocal tCaseKey = {}\n\t\tfor kk, vv in pairs(v.list) do\n\t\t\tif tFilter and #tFilter > 0 then\n\t\t\t\tbUsed = false\n\t\t\t\tfor wk, kf in pairs(tFilter) do\n\t\t\t\t\tif bUsed then break end\n\t\t\t\t\tif k == self.data.generalGlobalName then\n\t\t\t\t\t\tfor w in  string.gmatch(k .. \".\" .. vv.label, kf) do bUsed = true; break end\n\t\t\t\t\telse\n\t\t\t\t\t\tfor w in  string.gmatch(vv.label, kf) do bUsed = true; break end\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\t\tif bUsed then table.insert(tCaseKey, {name=kk, id=vv.no}) end\n\t\tend\n\t\tif #tCaseKey > 0 then \n\t\t\ttable.sort(tCaseKey, function(a, b) return a.id < b.id end)\n\t\t\ttable.insert(tSuiteKey, {name=k, id=v.prop.no, list=tCaseKey}) \n\t\t\tiCount = iCount + #tCaseKey\n\t\t\tiGroup = iGroup + 1\n\t\tend\n\tend\n\ttable.sort(tSuiteKey, function(a, b) return a.id < b.id end)\n\treturn iCount, iGroup, tSuiteKey\nend\t\n\nfunction TestMgr.runAllSuite(self, oOutput, tSuiteCaseKey)\t\n\tlocal tFailedList = {}\t\t\n\tfor k, v in ipairs(tSuiteCaseKey) do\n\t\tself:runGroupSuite(tFailedList, self.data.all_suite[v.name], v.list, oOutput)\n\tend\n\treturn tFailedList\nend\n\n\nfunction TestMgr.runGroupSuite(self, tFailedList, tSuite, tCaseKey, oOutput)\n\toOutput:BeginSuite( #tCaseKey, tSuite.prop.name )\t\n\tif tSuite.prop.oCls then tSuite.prop.oCls:SetUpTestCase() end\n\t\n\tlocal bExecResult = false\n\tfor k, v in ipairs(tCaseKey) do\n\t\tlocal oTmpCase = tSuite.list[v.name]\t\t\n\t\toTmpCase.result, oTmpCase.costTime = self:runCase(oTmpCase, tSuite, oOutput)\n\t\ttSuite.prop.costTime = oTmpCase.costTime + tSuite.prop.costTime\n\t\t\n\t\tif not oTmpCase.result then\n\t\t\ttSuite.prop.failedNum = 1 + tSuite.prop.failedNum\n\t\t\ttable.insert(tFailedList, oTmpCase.label)\t\n\t\telse\n\t\t\ttSuite.prop.okNum = 1 + tSuite.prop.okNum\n\t\tend\n\tend\t\t\n\n\tif tSuite.prop.oCls then tSuite.prop.oCls:TearDownTestCase() end\n\toOutput:EndSuite( #tCaseKey, tSuite.prop.name,  tSuite.prop.costTime, tSuite.prop.failedNum)\nend\n\n\n\nfunction TestMgr.runCase(self, oTmpCase, tSuite, oOutput)\n\t-- for assert step over\n\t_atER = true\n\tlocal bExecResult, bResult, strError = false, false, \"\"\n\t\n\tlocal iItemTime = os.clock()\n\toOutput:BeginCase(oTmpCase.label)\n\t\t\t\t\n\tif tSuite.prop.oCls then \n\t\ttSuite.prop.oCls:SetUp() \t\t\n\t\tif oTmpCase.para  and #oTmpCase.para > 0 then\n\t\t\tbResult, strError = pcall(function () oTmpCase.fun(tSuite.prop.oCls, unpack( oTmpCase.para) ) end)\n\t\telse\n\t\t\tbResult, strError = pcall(function () oTmpCase.fun(tSuite.prop.oCls) end)\t\t\n\t\tend\n\telse\t\n\t\tif oTmpCase.para and #oTmpCase.para > 0 then\n\t\t\tbResult, strError = pcall(function () oTmpCase.fun( unpack( oTmpCase.para) ) end)\n\t\telse\n\t\t\tbResult, strError = pcall(function () oTmpCase.fun() end)\t\t\n\t\tend\t\n\tend\n\t\n\tif not bResult or not _atMgr:GetResult() then \n\t\tif strError and not (not _atER and string.find(strError, _atStopTip)) then oOutput:FailedTxt(strError) end\n\telse\n\t\tbExecResult = true\n\tend\n\t\n\tif tSuite.prop.oCls then tSuite.prop.oCls:TearDown() end\t\t\n\tiItemTime = os.clock() - iItemTime\t\n\toOutput:EndCase(true, bExecResult, iItemTime, oTmpCase.label)\n\n\treturn bExecResult, iItemTime\nend\n\n\nfunction TestMgr.addRealSuite(self, strSuiteName, cCls)\t\n\tif oCls and (type(oCls) ~= type({}) or type(oCls.privateName) ~= type(print) or TestCase:privateName() ~= oCls:privateName()) then return end\n\tif not strSuiteName or type(strSuiteName) ~= type(\"\") or self.data.notcase[strSuiteName] then return end\t\n\n\tlocal tSuiteGroup = self.data.all_suite\n\tif not tSuiteGroup[strSuiteName] then  \n\t\ttSuiteGroup[strSuiteName] = {prop={name=strSuiteName, generalNo=1, bSys=false, oCls=cCls, no=self.data.generalSuiteNo, costTime=0, totalNum=0, okNum=0, failedNum=0,}, list={}} \n\t\tself.data.generalSuiteNo = 1 + self.data.generalSuiteNo\n\tend\n\treturn tSuiteGroup[strSuiteName] \nend\n\t\nfunction TestMgr.addRealCase(self, tSuite, strCaseName, oFun, tPara)\n\tif strCaseName and self.data.notcase[strCaseName] then return false end\n\t\n\tlocal tSuiteProp = tSuite.prop\n\tlocal tCurrSuite = tSuite.list\n\t\n\tif tCurrSuite[strCaseName] then  return false end\n\tlocal strLabel = strCaseName\n\tif not tSuiteProp.bSys then strLabel = tSuiteProp.name .. \".\" .. strCaseName end\n\ttCurrSuite[strCaseName] = {fun=oFun, para=tPara, label=strLabel, result=true, costTime=0, no=tSuiteProp.generalNo,}\n\ttSuiteProp.generalNo = 1 + tSuiteProp.generalNo\n\ttSuiteProp.totalNum = 1 + tSuiteProp.totalNum\n\treturn true\nend\n\n\nlocal _oTestMgr = false\n--------------------------------------------------------------------------------\n-- for init help function\nfunction InitLTest(tPara)\n\tif not _oTestMgr then _oTestMgr = TestMgr:new() else _oTestMgr:Fini() end\n\t_oTestMgr:Init(tPara)\n\treturn _oTestMgr\nend\n\n-- add all case of suite(oCls) by match filterCaseName\n-- oCls \t\t\t: <table>,  for suite class, the mt must is ltest.TestCase\n-- strSuiteName \t: <string>, for suite name\n-- filterCaseName \t: <string>, math case name\n-- return true if add success else return false\nfunction AddLTestSuite(oCls, strSuiteName, filterCaseName)\n\tif not _oTestMgr then return false end\n\treturn _oTestMgr:AddSuite(strSuiteName, oCls, filterCaseName)\nend\n\n-- add  a case of suite(oCls)\n-- oFun \t\t\t: <function>,  for case\n-- strCaseName \t\t: <string>, for case name\n-- tPara \t\t\t: <table>, for oFun para\n-- strSuiteName \t: <string>, for suite name\n-- oCls \t\t\t: <table>,  for suite class, the mt must is ltest.TestCase\n-- return true if add success else return false\nfunction AddLTestCase(oFun, strCaseName, tPara, strSuiteName, oCls)\n\tif not _oTestMgr then return false end\n\treturn _oTestMgr:AddCase(strCaseName, oFun, tPara, strSuiteName, oCls)\nend\n\n\n-- add  a group case of suite(oCls)\n-- oFun \t\t\t: <function>,  for case\n-- strCaseName \t\t: <string>, for case name\n-- tGroupPara \t\t: <table>, for oFun para, like {{},{},...}\n-- strSuiteName \t: <string>, for suite name\n-- oCls \t\t\t: <table>,  for suite class, the mt must is ltest.TestCase\n-- return true if add success else return false\nfunction AddLTestGroupCase(oFun, strCaseName, tGroupPara, strSuiteName, oCls)\n\tif not _oTestMgr then return false end\n\tfor i, v in ipairs(tGroupPara) do\n\t\t_oTestMgr:AddCase(strCaseName .. \"/\" .. i, oFun, v, strSuiteName, oCls)\n\tend\nend\n\n\n-- run all test case\n-- oEnv : <function>,  the mt must is ltest.TestEnvironment\n-- return 0 if success\nfunction RunAllTests(oEnv)\n\tif not _oTestMgr then return false end\n\treturn _oTestMgr:Run(oEnv)\nend\n\n-- return total_suitetotal_case total_faild\nfunction GetRunStatInfo()\n\tif not _oTestMgr then return end\t\n\treturn _oTestMgr:GetStatInfo()\nend\n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/init.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 371aa1acd86c2484596f2b8d4e5d6b67\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/lassert.lua",
    "content": "--[[\n//////////////////////////////////////////////////////////////////////////\n// date : 2013-5-4\n// auth : macroli(idehong@gmail.com)\n// ver  : 0.3\n// desc : assert and except \n//////////////////////////////////////////////////////////////////////////    \n--]]\n------------------------------------------------------------------------------\n\n--module(..., package.seeall)\n\n-- for assert base\nlocal assert_mt_base = {}\nassert_mt_base.__eq = function(v1, v2)\n\treturn type(v1.data) == type(v2.data) and  v1.data == v2.data\t\nend\n\nassert_mt_base.__lt = function (v1, v2)\n\treturn false\nend\n\nassert_mt_base.__le = function (v1, v2)\n\treturn false\nend\n\nassert_mt_base.__tostring = function (v1)\n\treturn tostring(v1.data)\nend\n\nlocal CBaseAssert = {}\nfunction CBaseAssert:new(oo)\n    local o = oo or {}\n    setmetatable(o, assert_mt_base)\n    return o\nend\n\n\nlocal assert_mt_default = {}\nassert_mt_default.__eq = function(v1, v2)\n\treturn type(v1.data) == type(v2.data) and  v1.data == v2.data\t\nend\n\nassert_mt_default.__lt = function (v1, v2)\n\treturn type(v1.data) == type(v2.data) and  v1.data < v2.data\nend\n\nassert_mt_default.__le = function (v1, v2)\n\treturn type(v1.data) == type(v2.data) and  v1.data <= v2.data\nend\n\nassert_mt_default.__tostring = function (v1)\n\treturn tostring(v1.data)\nend\n\n\nlocal CNumberAssert = {}\nfunction CNumberAssert:new(oo)\n    local o = oo or {}\n    setmetatable(o, assert_mt_default)\n    return o\nend\n\n\nlocal CStringAssert = {}\nfunction CStringAssert:new(oo)\n    local o = oo or {}\n    setmetatable(o, assert_mt_default)\n    return o\nend\n\nlocal _strCmpField = \"\"\n\n-- for less than, equal than, great than result\nlocal _iTableLT, _iTableEQ, _iTableGT = -1, 0, 1\n\n-- compare function for table\nlocal function _cmpTable(left, right, iCurLevel, iMaxLevel)\n\tif iCurLevel >= iMaxLevel then return _iTableLT end\n\t\n\tlocal tmpTypeTab = type({})\t\n\tif tmpTypeTab ~= type(left) or tmpTypeTab ~= type(right) then return _iTableLT end\n\t\n\tlocal tK1 = {}\n\tfor k, v in pairs(left) do table.insert(tK1, k) end\n\ttable.sort(tK1, function(a, b) return tostring(a) < tostring(b) end)\t\n\n\tlocal tK2 = {}\n\tfor k, v in pairs(right) do table.insert(tK2, k) end\n\ttable.sort(tK2, function(a, b) return tostring(a) < tostring(b) end)\t\n\t\n\tlocal iLen1, iLen2 = #tK1, #tK2\n\tlocal iLenMin = math.min(iLen1, iLen2)\n\t\n\tlocal tmp1, tmp2, tmpTyp1, tmpTyp2 = 0, 0, 0, 0\n\tlocal tmpTypeStr = type(\"\")\n\tlocal tmpTypeInt = type(0)\n\t\n\tlocal iTmpResult = _iTableEQ\n\tfor i = 1, iLenMin do\n\t\ttmp1 = left[ tK1[i] ]\n\t\tif tmp1 == nil then return _iTableLT end \n\t\t\n\t\ttmp2 = right[ tK2[i] ]\n\t\tif tmp2 == nil then return _iTableGT end\n\n\t\t_strCmpField = string.format(\"level:%d, field:%s vs :%s\", iCurLevel, tK1[i] , tK1[i] )\n\t\t\n\t\ttmpTyp1, tmpTyp2 = type(tmp1), type(tmp2)\t\t\n\t\tif tmpTyp1 ~= tmpTyp2 then return _iTableLT end\n\t\t\n\t\tif tmpTyp1 == tmpTypeStr or tmpTyp1 == tmpTypeInt then\n\t\t\tif tmp1 < tmp2 then return _iTableLT  end\n\t\t\tif tmp1 > tmp2 then return _iTableGT end\n\t\telseif tmpTyp1 == tmpTypeTab then\n\t\t\tiTmpResult = _cmpTable(tmp1, tmp2, iCurLevel + 1, iMaxLevel) \n\t\t\tif iTmpResult ~= _iTableEQ then return iTmpResult end\t\t\t\n\t\telse\n\t\t\treturn _iTableLT \n\t\tend\t\t\t \n\tend\n\t\n\t_strCmpField = string.format(\"level:%d, num: %d vs %d\", iCurLevel, iLen1, iLen2)\n\t\n\tif iLen1 < iLen2 then return _iTableLT end\n\tif iLen1 > iLen2 then return _iTableGT end\n\t\n\treturn _iTableEQ\t\t\nend\n\n\n-- concat function for table\nlocal function _strTable(left, strTip, iCurLevel, iMaxLevel)\n\tif iCurLevel >= iMaxLevel then return strTip end\n\t\n\tlocal tmpTypeTab = type({})\t\n\tif tmpTypeTab ~= type(left) then return strTip end\n\t\n\tlocal tK1 = {}\n\tfor k, v in pairs(left) do table.insert(tK1, k) end\n\ttable.sort(tK1, function(a, b) return tostring(a) < tostring(b) end)\t\n\n\tlocal iLen1 = #tK1\n\tlocal tmp1, tmpTyp1 = 0, 0\t\n\tfor i = 1, iLen1 do\n\t\ttmp1 = left[ tK1[i] ]\n\t\ttmpTyp1 = type(tmp1)\n\t\tif tmpTyp1 == tmpTypeTab then\n\t\t\tstrTip = strTip .. _strTable(tmp1, strTip .. string.format(\"%s={\", tostring(tK1[i]) ), iCurLevel + 1, iMaxLevel) .. \"},\"\n\t\telse\n\t\t\tstrTip = strTip .. \tstring.format(\"%s=%s,\", tostring(tK1[i]), tostring(tmp1))\n\t\tend\t \n\tend\n\t\n\treturn strTip\t\t\nend\n\n-- for table recursion level number\nlocal _iTableLevel = 5\nlocal assert_mt_table = {}\nassert_mt_table.__eq = function(v1, v2)\n\tlocal mt1 = getmetatable(v1.data)\n\tlocal mt2 = getmetatable(v1.data)\n\n\tif mt1 and mt2 and mt1[\"__eq\"] and mt2[\"__eq\"] then\n\t\treturn v1.data == v2.data\n\telse\n\t\treturn type(v1.data) == type(v2.data) and _cmpTable(v1.data, v2.data, 0, _iTableLevel) == _iTableEQ\n\tend\nend\n\nassert_mt_table.__lt = function (v1, v2)\n\tlocal mt1 = getmetatable(v1.data)\n\tlocal mt2 = getmetatable(v1.data)\n\n\tif mt1 and mt2 and mt1[\"__lt\"] and mt2[\"__lt\"] then\n\t\treturn v1.data < v2.data\n\telse\n\t\treturn type(v1.data) == type(v2.data) and _cmpTable(v1.data, v2.data, 0, _iTableLevel) == _iTableLT\n\tend\nend\n\nassert_mt_table.__le = function (v1, v2)\n\tlocal mt1 = getmetatable(v1.data)\n\tlocal mt2 = getmetatable(v1.data)\n\n\tif mt1 and mt2 and mt1[\"__le\"] and mt2[\"__le\"] then\n\t\treturn v1.data <= v2.data\n\telse\n\t\treturn type(v1.data) == type(v2.data) and _cmpTable(v1.data, v2.data, 0, _iTableLevel) <= _iTableEQ\n\tend\nend\n\nassert_mt_table.__tostring = function (v1)\n\tlocal mt1 = getmetatable(v1.data)\n\n\tif mt1 and mt1[\"__tostring\"] then\n\t\treturn tostring(v1.data)\n\telse\n\t\treturn _strTable(v1.data, \"{\", 0, _iTableLevel) .. \"}\"\n\tend\nend\n\n\nlocal CTableAssert = {}\nfunction CTableAssert:new(oo)\n    local o = oo or {}\n    setmetatable(o, assert_mt_table)\n    return o\nend\n\n\n-- for test assert and except\nCAssertMgr = {}\nfunction CAssertMgr:new(oo)\n    local o = oo or {}\n    o.result = true\n    o.at = {}\n    \n    o.at[tostring(type(nil)) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type(nil))]    \n    oTmp.left  = CBaseAssert:new(oTmp.ld)\n    oTmp.right = CBaseAssert:new(oTmp.rd)\n\t\n    o.at[tostring(type(1)) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type(1))]    \n    oTmp.left  = CNumberAssert:new(oTmp.ld)\n    oTmp.right = CNumberAssert:new(oTmp.rd)\n\n    o.at[tostring(type(\"\")) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type(\"\"))]    \n    oTmp.left  = CStringAssert:new(oTmp.ld)\n    oTmp.right = CStringAssert:new(oTmp.rd)\n    \n    o.at[tostring(type(true)) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type(true))]    \n    oTmp.left  = CBaseAssert:new(oTmp.ld)\n    oTmp.right = CBaseAssert:new(oTmp.rd)    \n \n    o.at[tostring(type({})) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type({}))]    \n    oTmp.left  = CTableAssert:new(oTmp.ld)\n    oTmp.right = CTableAssert:new(oTmp.rd)    \n\n    o.at[tostring(type(print)) \t  ] = {ld={}, rd={},}\n    local oTmp = o.at[tostring(type(print))]    \n    oTmp.left  = CBaseAssert:new(oTmp.ld)\n    oTmp.right = CBaseAssert:new(oTmp.rd)    \n\n    o.at[\"thread\"] = {ld={}, rd={},}\n    local oTmp = o.at[\"thread\"]    \n    oTmp.left  = CBaseAssert:new(oTmp.ld)\n    oTmp.right = CBaseAssert:new(oTmp.rd)    \n\n    o.at[\"userdata\"] = {ld={}, rd={},}\n    local oTmp = o.at[\"userdata\"]    \n    oTmp.left  = CBaseAssert:new(oTmp.ld)\n    oTmp.right = CBaseAssert:new(oTmp.rd)    \n   \n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction CAssertMgr.GetResult(self)\n\treturn self.result\nend\n\nfunction CAssertMgr.helpWrapper(self, v1, v2)\n\tself.result = false\n\t_strCmpField = \"\"\n\tlocal tmp = self.at[type(v1)]\n\tif not tmp then return end\n\ttmp.ld.data = v1\n\ttmp.rd.data = v2\n\treturn tmp.left, tmp.right, type(v1)\nend\n\nfunction CAssertMgr.CheckResult(self, lv, strTip)\n\tif not self:GetResult() then error(strTip, lv) end\nend\n\nfunction CAssertMgr.PCRTip(self, bNoPrintDetail, strTip, lv, v1, iParaNum)\n\tlocal tmp = self.at[type(v1)]\n\tl = tmp.left\n\tr = tmp.right\n \n \tlocal strTmp = \"\" \n\twhile true do\n\t\tif type(v1) == type({}) and bNoPrintDetail then\t\n\t\t\tstrTmp = string.format(\"%s --> field=%s.\", strTip, _strCmpField)\n\t\t\tbreak\n\t\tend\n\t\t\n\t\tif iParaNum > 1 then\n\t\t\tif _strCmpField and #_strCmpField > 0 then\n\t\t\t\tstrTmp = string.format(\"%s --> field=%s, left:%s, right:%s.\", strTip, _strCmpField, tostring(l), tostring(r))\n\t\t\telse\n\t\t\t\tstrTmp = string.format(\"%s --> left:%s, right:%s.\", strTip, tostring(l), tostring(r))\n\t\t\tend\n\t\telse\n\t\t\tif _strCmpField and #_strCmpField > 0 then\n\t\t\t\tstrTmp = string.format(\"%s --> field=%s, value:%s.\", strTip, _strCmpField, tostring(l))\n\t\t\telse\n\t\t\t\tstrTmp = string.format(\"%s --> value:%s.\", strTip, tostring(l))\n\t\t\tend\n\t\tend\n\t\tbreak\n\tend\n\treturn strTmp\t\nend\n\n-- PCR = PCallCheckResult1\nfunction CAssertMgr.PCR1(self, bNoPrintDetail, lv, strTip, v1)\n\tlocal bRet = self:GetResult() \n\tif not bRet then \n\t\tlocal strTmp = self:PCRTip(bNoPrintDetail, strTip, lv,  v1, 1)\n\t\tlocal bResult, strError = pcall(function () self:CheckResult(lv, strTmp) end)\n\t\tif not bResult and strError then self:print(\"\\t\" .. strError) end\n\tend\n\treturn bRet\t\t\nend\n\nfunction CAssertMgr.PCR(self, bNoPrintDetail, lv, strTip, v1, v2)\n\tlocal bRet = self:GetResult() \n\tif not bRet then \n\t\tlocal strTmp = self:PCRTip(bNoPrintDetail, strTip, lv, v1, 2)\t\t\n\t\tlocal bResult, strError = pcall(function () self:CheckResult(lv, strTmp) end)\n\t\tif not bResult and strError then self:print(\"\\t\" .. strError) end\n\tend\t\n\treturn bRet\t\t\nend\n\nfunction CAssertMgr.print(self, ...)\n\tif not self:GetResult() then self.oOutput:FailedTxt(...) end\n\treturn self\nend\n\n\nfunction CAssertMgr.AssertEQ(self, v1, v2)\n\tlocal l, r, t = self:helpWrapper(v1, v2)\n\tself.result = l == r\n\treturn self\nend\n\nfunction CAssertMgr.AssertLT(self, v1, v2)\n\tlocal l, r, t = self:helpWrapper(v1, v2)\n\tself.result = l < r\n\treturn self\nend\n\nfunction CAssertMgr.AssertLE(self, v1, v2)\n\tlocal l, r,t = self:helpWrapper(v1, v2)\n\tself.result = l <= r\n\treturn self\nend\n\nfunction CAssertMgr.AssertGT(self, v1, v2)\n\tlocal l, r, t = self:helpWrapper(v1, v2)\n\tself.result = l > r\n\treturn self\t\nend\n\nfunction CAssertMgr.AssertGE(self, v1, v2)\n\tlocal l, r, t = self:helpWrapper(v1, v2)\n\tself.result = l >= r\n\treturn self\t\nend\n\nfunction CAssertMgr.AssertNE(self, v1, v2)\n\tself.result = false\n\tlocal l, r, t = self:helpWrapper(v1, v2)\n\tif type(v1) == type(v2) then \t\t\n\t\tself.result = l ~= r\n\tend\n\treturn self\t\nend\n\nfunction CAssertMgr.AssertNear(self, v1, v2, nearValue)\n\tself.result = false\n\tlocal l, r, t = self:helpWrapper(v1, v2)\t\n\tif type(v1) == type(v2) and type(v1) == type(0.1) then\n\t\tif v1 > v2 then self.result =  (v1 - v2 < nearValue) end\n\t\tif v1 < v2 then self.result =  (v2 - v1 < nearValue) end\n\tend\n\treturn self\t\nend\n\nfunction CAssertMgr.AssertTrue(self, v1)\n\tlocal l, r, t = self:helpWrapper(v1, v1)\n\tif v1 then self.result = true else self.result = false end\n\treturn self\t\nend\n\nfunction CAssertMgr.AssertFalse(self, v1)\n\tself:AssertTrue(v1)\n\tself.result = not self.result \n\treturn self\t\t\nend\n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/lassert.lua.meta",
    "content": "fileFormatVersion: 2\nguid: e399387a268701146881269b83f8f79e\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/loutput.lua",
    "content": "--[[\n//////////////////////////////////////////////////////////////////////////\n// date : 2013-5-4\n// auth : macroli(idehong@gmail.com)\n// ver  : 0.3\n// desc : output \n//////////////////////////////////////////////////////////////////////////    \n--]]\n------------------------------------------------------------------------------\n\n--module(..., package.seeall)\n\n-- for test output\nlocal TestOutPutBase = {}\nfunction TestOutPutBase:new(oo)\n    local o = oo or {}\n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction TestOutPutBase.FilterInfo(self, ...)\nend\n\nfunction TestOutPutBase.BeginCase(self, strLabelName)\nend\n\nfunction TestOutPutBase.EndCase(self, bRun, bSuccess, iTime, strLabelName)\nend\n\nfunction TestOutPutBase.BeginSuite(self, iNumber, strSuiteName)\nend\n\nfunction TestOutPutBase.EndSuite(self, iNumber, strSuiteName, iTime, iFailedNum)\nend\n\nfunction TestOutPutBase.BeginGroupSuite(self, iCaseNum, iSuiteNum)\nend\n\nfunction TestOutPutBase.EndGroupSuite(self, iCaseNum, iSuiteNum, iTime, iFailedNum, iStartTime)\nend\n\nfunction TestOutPutBase.BeginGroupEnv(self, strTip)\nend\n\nfunction TestOutPutBase.EndGroupEnv(self, strTip)\nend\n\nfunction TestOutPutBase.FailedTxt(self, ...)\nend\n\nfunction TestOutPutBase.StaticInfo(self)\nend\n\nfunction TestOutPutBase.GetStaticInfo(self)\nend\n\nfunction TestOutPutBase.Message(self, ...)\n\tprint( self:mergerTxt(...) )\nend\n\nfunction TestOutPutBase.mergerTxt(self, ...)\n\treturn string.format(...) \nend\n\n\n-- for test output\nCmdTestOutPut = TestOutPutBase:new()\nfunction CmdTestOutPut:new(oo)\n    local o = oo or {}\n    o.output = {\n    \tlabelNum = 10,\n    \tfmt = { left = \"[%-10s]\", right = \"[%10s]\", },\n    \tlabel = { run = {label=\" RUN\", fmt=\"left\",}, ok = {label=\"OK \",  fmt=\"right\",}, failed = {label=\"  FAILED\",  fmt=\"left\",},\n    \t\tpassed = {label=\"  PASSED\", fmt=\"left\",},\n    \t\tsplit = {label=\"----------\", fmt=\"right\",},  \n    \t\tgroup = {label=\"==========\", fmt=\"right\",},\n    \t},\n    }\n    o.stat = {\n    \tiTotalCase = 0, iTotalSuite = 0, iTotalPassed = 0,\n    \ttFailedName = {},  \n    \tiCurrCaseCount = 0,  \t\n    }\n    \n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction CmdTestOutPut.outerList(self, strFun, ...)\n\tif not self.outer then return end\n\t\n\tfor i, v in pairs(self.outer) do\n\t\tv[strFun](v, ...)\n\tend\nend\n\nfunction CmdTestOutPut.FilterInfo(self, ...)\n\tself:Message(...)\n\t\n\tself:outerList(\"FilterInfo\", ...)\nend\n\nfunction CmdTestOutPut.BeginCase(self, strLabelName)\n\tself.stat.iCurrCaseCount = 1 + self.stat.iCurrCaseCount\n\tself:Message(\"%s %s\", self:getFMTStr(\"run\", string.format(\" %d%%\", math.floor(self.stat.iCurrCaseCount*100/self.stat.iTotalCase))), strLabelName)\n\t\n\tself:outerList(\"BeginCase\", strLabelName)\nend\n\nfunction CmdTestOutPut.EndCase(self, bRun, bSuccess, iTime, strLabelName)\n\tif not bRun then return end\n\n\tif bSuccess then\n\t\tself.stat.iTotalPassed = 1 + self.stat.iTotalPassed\n\t\tself:Message(\"%s %s (%f ms)\", self:getFMTStr(\"ok\"), strLabelName, iTime)\n\telse\n\t\ttable.insert(self.stat.tFailedName, strLabelName)\n\t\tself:Message(\"%s %s (%f ms)\", self:getFMTStr(\"failed\"), strLabelName, iTime)\n\tend\n\t\n\tself:outerList(\"EndCase\", bRun, bSuccess, iTime, strLabelName)\t\nend\n\nfunction CmdTestOutPut.BeginSuite(self, iNumber, strSuiteName)\n\tself:Message(\"%s %d tests from %s.\", self:getFMTStr(\"split\"), iNumber, strSuiteName)\t\n\n\tself:outerList(\"BeginSuite\", iNumber, strSuiteName)\t\t\nend\n\nfunction CmdTestOutPut.EndSuite(self, iNumber, strSuiteName, iTime, iFailedNum)\n\tself:Message(\"%s %d tests from %s (%f ms total).\\n\", self:getFMTStr(\"split\"), iNumber, strSuiteName, iTime)\n\n\tself:outerList(\"EndSuite\", iNumber, strSuiteName, iTime, iFailedNum)\t\t\nend\n\nfunction CmdTestOutPut.BeginGroupSuite(self, iCaseNum, iSuiteNum)\n    self.stat = {\n    \tiTotalCase = iCaseNum, iTotalSuite = iSuiteNum, iTotalPassed = 0,\n    \ttFailedName = {},  \n    \tiCurrCaseCount = 0,  \t\n    }\n\t\n\tself:Message(\"%s Running %d tests from %d test cases\", self:getFMTStr(\"group\"), iCaseNum, iSuiteNum)\n\n\tself:outerList(\"BeginGroupSuite\", iCaseNum, iSuiteNum)\t\t\nend\n\nfunction CmdTestOutPut.EndGroupSuite(self, iTime)\n\tself:Message(\"%s Running %d  tests from %d test cases ran. (%f ms total)\", self:getFMTStr(\"group\"), self.stat.iTotalCase, self.stat.iTotalSuite, iTime)\n\n\tself:outerList(\"EndGroupSuite\", iTime)\t\t\nend\n\nfunction CmdTestOutPut.BeginGroupEnv(self)\n\tself:Message(\"%s Global test environment set-up.\", self:getFMTStr(\"split\"))\t\nend\n\nfunction CmdTestOutPut.EndGroupEnv(self)\n\tself:Message(\"%s Global test environment tear-down.\", self:getFMTStr(\"split\"))\nend\n\nfunction CmdTestOutPut.FailedTxt(self, ...)\n\tself:Message(...)\n\n\tself:outerList(\"FailedTxt\", ...)\t\t\nend\n\nfunction TestOutPutBase.Message(self, ...)\n\tif not self.silence then print( self:mergerTxt(...) ) end\t\t\nend\n\nfunction CmdTestOutPut.StaticInfo(self)\n\tself:Message(\"%s %d tests.\", self:getFMTStr(\"passed\"), self.stat.iTotalPassed)\n\n\tlocal iFailedNum = #self.stat.tFailedName\n\tif iFailedNum <= 0 then return end\n\tself:Message(\"%s %d tests, listed below:\", self:getFMTStr(\"failed\"), iFailedNum)\n\tfor k, v in pairs(self.stat.tFailedName) do\n\t\tself:Message(\"%s %s\", self:getFMTStr(\"failed\"), v)\n\tend\n\t\n\tself:outerList(\"StaticInfo\")\t\n    \n    error(string.format(\"%d SUITES, %d TESTS, %d FAILED\", self.stat.iTotalSuite, self.stat.iTotalCase, iFailedNum))\nend\n\n\nfunction CmdTestOutPut.GetStaticInfo(self)\n\tlocal iFailedNum = #self.stat.tFailedName\n\treturn {iTotalSuite=self.stat.iTotalSuite, iTotalCase=self.stat.iTotalCase, iFailedNum=iFailedNum}\nend\n\nfunction CmdTestOutPut.getFMTStr(self, label, addvalue)\n\tlocal tObj = self.output.label[label]\n\tif addvalue then\n\t\treturn string.format(self.output.fmt[tObj.fmt], tObj.label .. addvalue)\t\n\telse\n\t\treturn string.format(self.output.fmt[tObj.fmt], tObj.label)\t\n\tend\nend\n\n\n--------------------------------------------------------------------------------\nCAllCaseListOutPut = TestOutPutBase:new()\nfunction CAllCaseListOutPut:new(oo)\n    local o = oo or {}\n    o.data = {f=false}\n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction CAllCaseListOutPut.BeginCase(self, strLabelName)\n\tself:Message(strLabelName)\nend\n\nfunction CAllCaseListOutPut.EndSuite(self, iNumber, strSuiteName, iTime, iFailedNum)\n\tif self.data.f then self.data.f:flush() end\nend\n\nfunction CAllCaseListOutPut.BeginGroupSuite(self, iCaseNum, iSuiteNum)\n\tf = io.open(self.filename, \"w+b\")\n\tif not f then return end\n\tself.data.f = f\nend\n\nfunction CAllCaseListOutPut.EndGroupSuite(self, iCaseNum, iSuiteNum, iTime, iFailedNum, iStartTime)\n\tif self.data.f then \n\t\tself.data.f:close()\n\t\tself.data.f = false\n\tend\nend\n\nfunction CAllCaseListOutPut.Message(self, ...)\n\tif self.data.f then self.data.f:write(self:mergerTxt(...) .. \"\\r\\n\") end\nend\n\n\nCFailedCaseListOutPut = TestOutPutBase:new()\nfunction CFailedCaseListOutPut:new(oo)\n    local o = oo or {}\n    o.data = {f=false}    \n    setmetatable(o, self)\n    self.__index = self\n    return o\nend\n\nfunction CFailedCaseListOutPut.EndCase(self, bRun, bSuccess, iTime, strLabelName)\n\tif bRun and not bSuccess then\n\t\tself:Message(strLabelName .. \"\\r\\n\\r\\n\")\n\tend\nend\n\nfunction CFailedCaseListOutPut.EndSuite(self, iNumber, strSuiteName, iTime, iFailedNum)\n\tif self.data.f then self.data.f:flush() end\nend\n\nfunction CFailedCaseListOutPut.BeginGroupSuite(self, iCaseNum, iSuiteNum)\n\tf = io.open(self.filename, \"w+b\")\n\tif not f then return end\n\tself.data.f = f\nend\n\nfunction CFailedCaseListOutPut.EndGroupSuite(self, iCaseNum, iSuiteNum, iTime, iFailedNum, iStartTime)\n\tif self.data.f then \n\t\tself.data.f:close()\n\t\tself.data.f = false\n\tend\nend\n\nfunction CFailedCaseListOutPut.FailedTxt(self, ...)\n\tself:Message(...)\nend\n\n\nfunction CFailedCaseListOutPut.Message(self, ...)\n\tif self.data.f then self.data.f:write(self:mergerTxt(...) .. \"\\r\\n\") end\nend\n\n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest/loutput.lua.meta",
    "content": "fileFormatVersion: 2\nguid: c81508a9cd6507b43aa52a394d110123\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/ltest.meta",
    "content": "fileFormatVersion: 2\nguid: 5c751f31fa1d4664a8a162241f8a7812\nfolderAsset: yes\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaCallCs.lua",
    "content": "require(\"ltest.init\")\r\n\r\ngTestNumber = 1\r\n\r\nfunction islua53() return not not math.type end\r\n\t\r\n-- for test case\r\nCMyTestCaseLuaCallCS = TestCase:new()\r\nfunction CMyTestCaseLuaCallCS:new(oo)\r\n    local o = oo or {}\r\n    o.count = 1\r\n    \r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.SetUpTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCS.SetUpTestCase\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.TearDownTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCS.TearDownTestCase\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCS.SetUp(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCS.SetUp\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.TearDown(self)\r\n    self.count = 1 + self.count\r\n\r\n\tprint(\"CMyTestCaseLuaCallCS.TearDown\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.DefaultParaFuncSingle(100, \"abc\")\r\n\tASSERT_EQ(ret, 100)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.DefaultParaFuncSingle(100)\r\n\tASSERT_EQ(ret, 100)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.DefaultParaFuncMulti(100, \"\")\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.DefaultParaFuncMulti(100, \"efg\", 1)\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.DefaultParaFuncMulti(100, \"efg\", 1, 98)\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDefaultParamFunc6(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObj.DefaultParaFuncMulti(100, \"efg\", 1, 98, 0) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVariableParamFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.VariableParamFunc(0)\r\n\tASSERT_EQ(ret, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVariableParamFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.VariableParamFunc(0, \"a\")\r\n\tASSERT_EQ(ret, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVariableParamFunc3(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObj.VariableParamFunc(0, \"a\", 1, \"b\") end)\r\n\t\tASSERT_EQ(ret, true)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestEnumFunc(CS.LuaTestType.DEF)\r\n\tASSERT_EQ(ret, 1)\r\nend\r\n\r\n--[[ 2016.11.25 新版本不支持整数直接当枚举用\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum2(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = -1\r\n\tlocal ret = CS.LuaTestObj.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, -1)\r\nend\r\n]]\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum3(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestType.__CastFrom(2)\r\n\tlocal ret = CS.LuaTestObj.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum4(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestType.__CastFrom(4)\r\n\tlocal ret = CS.LuaTestObj.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 4)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum5(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestType.__CastFrom(\"GHI\")\r\n\tlocal ret = CS.LuaTestObj.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseLuaAccessEnum6(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false and CS.LuaTestCommon.IsIOSPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObj.TestEnumFunc(CS.LuaTestType.__CastFrom(\"BCD\")) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.LuaTestObj))\r\n\tASSERT_EQ(ret, \"LuaTestObj\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.System.String))\r\n\tASSERT_EQ(ret, \"System.String\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType3(self)\r\n    self.count = 1 + self.count\r\n    if CS.LuaTestCommon.IsXLuaGeneral() then return end\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.UnityEngine.Vector3))\r\n\tASSERT_EQ(ret, \"UnityEngine.Vector3\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.System.Int16))\r\n\tASSERT_EQ(ret, \"System.Int16\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.XLua.LuaTable))\r\n\tASSERT_EQ(ret, \"XLua.LuaTable\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetType6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.XLua.LuaFunction))\r\n\tASSERT_EQ(ret, \"XLua.LuaFunction\")\r\nend\r\n\r\n--[[ v2.1.0版本中LuaUserData类已去掉\r\nfunction CMyTestCaseLuaCallCS.CaseGetType7(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.TestGetType(typeof(CS.XLua.LuaUserData))\r\n\tASSERT_EQ(ret, \"XLua.LuaUserData\")\r\nend\r\n]]\r\n\r\nfunction CMyTestCaseLuaCallCS.Case64BitInt1(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObj.Gen64BitInt()\r\n\tlocal x1 = CS.LuaTestObj.ulX1\r\n\tlocal x2 = CS.LuaTestObj.ulX2\r\n\tlocal ret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret  = x2 - x1\r\n\t--ASSERT_EQ(\"16140901064495857664\", tostring(ret))\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\n\tx1 = CS.LuaTestObj.lY1\r\n\tx2 = CS.LuaTestObj.lY2\r\n\tret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret = x2 - x1\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\n\tx1 = CS.LuaTestObj.i64Z1\r\n\tx2 = CS.LuaTestObj.i64Z2\r\n\tret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret = x2 - x1\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.Case64BitInt2(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObj.Gen64BitInt()\r\n\tlocal x1 = CS.LuaTestObj.ulX1\r\n\tlocal x2 = CS.LuaTestObj.ulX2\r\n\tASSERT_EQ(true, x2 < x1)\r\n\tASSERT_EQ(true, x2 <= x1)\r\n\tASSERT_EQ(false, x1 <= x2)\r\n\tASSERT_EQ(false, x1 < x2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.Case64BitInt3(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObj.Gen64BitInt()\r\n\tlocal y = CS.LuaTestObj.lY3\r\n\ty = y * 100\r\n\tASSERT_EQ(tostring(y), \"112589990684262400\")\r\n\ty = y / 10000\r\n\tif islua53() then\r\n\t    ASSERT_EQ(tostring(y), \"11258999068426.0\")\r\n\telse\r\n\t\tASSERT_EQ(tostring(y), \"11258999068426\")\r\n\tend\r\n\ty = y % 1000\r\n\tif islua53() then\r\n\t    ASSERT_EQ(tostring(y), \"426.240234375\")\r\n\telse\r\n\t\tASSERT_EQ(tostring(y), \"426\")\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.Case64BitInt4(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObj.Gen64BitInt()\r\n\tlocal ret = CS.LuaTestObj.lY3 * CS.LuaTestObj.lY4\r\n\tASSERT_EQ(tostring(ret), \"138485688541642752\")\r\n\tret = CS.LuaTestObj.lY3 / CS.LuaTestObj.lY5\r\n\tif islua53() then\r\n\t\tASSERT_EQ(tostring(ret), \"91202908614.226\")\r\n\telse\r\n\t    ASSERT_EQ(tostring(ret), \"91202908614\")\r\n\tend\r\n\tret = CS.LuaTestObj.lY3 % CS.LuaTestObj.lY6\r\n\tASSERT_EQ(tostring(ret), \"52636\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseCast1(self)\r\n    self.count = 1 + self.count\r\n\tlocal castObj = CS.TestCastClass()\r\n\tcast(castObj, typeof(CS.TestCastClass))\r\n\tASSERT_EQ(true, castObj:TestFunc1())\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseCast2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal castObj = CS.LuaTestObj.CreateTestLuaObj()\r\n\tcast(castObj, typeof(CS.TestLuaClass))\r\n\tASSERT_EQ(true, castObj:TestFunc1())\r\nend\r\n\r\nfunction LuaFunc1(x)\r\n\treturn x + 1\r\nend\r\n\r\nfunction LuaFunc2(x)\r\n\treturn x * 2\r\nend\t\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseDelgate1(self)\r\n\tself.count = 1 + self.count\r\n\t\r\n\tCS.LuaTestObj.initNumber = 5\r\n\tCS.LuaTestObj.GenDelegate()\r\n\tlocal luaDelgateLink = CS.LuaTestObj.csDelegate\r\n\tluaDelgateLink = CS.LuaTestObj.csDelegate1\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate2\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate3\r\n\tlocal ret = luaDelgateLink(1)\r\n\tASSERT_EQ(5, ret)\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(2, ret)\r\n\tCS.LuaTestObj.csDelegate4 = LuaFunc2\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate4\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(4, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(10)\r\n\tASSERT_EQ(20 ,ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate4\r\n\tret = luaDelgateLink(19)\r\n\tASSERT_EQ(1900, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate3\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(1900, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate2\r\n\tret = luaDelgateLink(3)\r\n\tASSERT_EQ(1903, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate2\r\n\tret = luaDelgateLink(4)\r\n\tASSERT_EQ(1907, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n    local ret, error = pcall(function() luaDelgateLink(5) end)\r\n    ASSERT_EQ(false, ret)\r\n\r\n\tCS.LuaTestObj.initNumber = 5\r\n\tluaDelgateLink = CS.LuaTestObj.csDelegate3\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(5, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(6, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(8, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(9, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(9, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate3\r\n\tCS.LuaTestObj.initNumber = 1\r\n\tlocal function LuaFunc4(x)\r\n\t\tCS.LuaTestObj.initNumber = CS.LuaTestObj.initNumber * 2\r\n\t\treturn CS.LuaTestObj.initNumber\r\n\tend\r\n\tluaDelgateLink = CS.LuaTestObj.csDelegate1\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 4)\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 20)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 42)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 43)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n\t\r\n\tCS.LuaTestObj.initNumber = 1907\r\n\tluaDelgateLink = LuaFunc1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(2, ret)\t\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(1909, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObj.csDelegate4\r\n\tret = luaDelgateLink(3)\r\n\tASSERT_EQ(6, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(4)\r\n\tASSERT_EQ(8, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate1\r\n\tret = luaDelgateLink(5)\r\n\tASSERT_EQ(10, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(6)\r\n\tASSERT_EQ(12, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(7)\r\n\tASSERT_EQ(14, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObj.csDelegate4\r\n    local ret, error = pcall(function() luaDelgateLink(8) end)\r\n    ASSERT_EQ(false, ret)\r\nend\r\n\r\nfunction EvtFunc11(y)\r\n\tgTestNumber = y + gTestNumber\r\n\treturn gTestNumber\r\nend\r\n\r\nfunction EvtFunc12(y)\r\n\tgTestNumber = y + 1 + gTestNumber\r\n\treturn gTestNumber\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseEvent1(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tgTestNumber = 1\r\n\tlocal testObj = CS.LuaTestObj()\r\n\ttestObj:TestEvent1('+', EvtFunc11)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(2, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(2)\r\n\tASSERT_EQ(7, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(12, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(15, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(16, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(17, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc11)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseCalc1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObj()\r\n\ta.testVar = 100\r\n\tlocal b = CS.LuaTestObj()\r\n\tb.testVar = 200\r\n\tlocal ret = a + b\r\n\tASSERT_EQ(ret.testVar, 300)\r\n\tret = a - b\r\n\tASSERT_EQ(ret.testVar, -100)\r\n\tret = a * b\r\n\tASSERT_EQ(ret.testVar, 20000)\r\n\tret = b / a\r\n\tASSERT_EQ(ret.testVar, 2)\r\n\tret = b % a\r\n\tASSERT_EQ(ret.testVar, 0)\r\n\tret = a < b\r\n\tASSERT_EQ(true, ret)\r\n\tret = a <= b\r\n\tASSERT_EQ(true, ret)\r\n\tret = -a\r\n\tASSERT_EQ(ret.testVar, -100)\r\n\tlocal c = CS.LuaTestObj()\r\n\tc.testArr[0] = 1000\r\n\tret = c[0]\r\n\tASSERT_EQ(1000, ret)\r\n\tc[1] = 10000\r\n\tret = c.testArr[1]\r\n\tASSERT_EQ(10000, ret)\r\n\t\r\n\ta.testVar = 100\r\n\tb.testVar = 200\r\n\tc.testVar = 300\r\n\tlocal d = CS.LuaTestObj()\r\n\td.testVar = 20\r\n\tlocal e = CS.LuaTestObj()\r\n\te.testVar = 7\r\n\tret = (a + b) * c / d % e\r\n\tASSERT_EQ(ret.testVar, 6)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseCalc2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObj()\r\n\ta.testVar = 100\r\n\tlocal ret = 300 + a + 200\r\n\tASSERT_EQ(ret.testVar, 600)\r\n\tret = 100 - a - 400\r\n\tASSERT_EQ(ret.testVar, -400)\r\n\tret = 2 * a * 3\r\n\tASSERT_EQ(600, ret.testVar)\r\n\tret = 20000 / a / 2\r\n\tASSERT_EQ(100, ret.testVar)\r\n\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseOverLoad1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.OverLoad1(1, 2)\r\n\tASSERT_EQ(ret, 1)\r\n\tret = CS.LuaTestObj.OverLoad2(\"1\", \"2\")\r\n\tASSERT_EQ(ret, 4);\r\n\tret = CS.LuaTestObj.OverLoad3(1)\r\n\tASSERT_EQ(ret, 5);\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseOutRef1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = 2\r\n\tlocal b\r\n\ta, b = CS.LuaTestObj.OutRefFunc1(1, a, b)\r\n\tASSERT_EQ(a, 100)\r\n\tb, a = CS.LuaTestObj.OutRefFunc2(b, 1, a)\r\n\tASSERT_EQ(a, 200)\r\n\ta, b = CS.LuaTestObj.OutRefFunc3(1, a, b)\r\n\tASSERT_EQ(a, 300)\r\n\tret, a, b = CS.LuaTestObj.OutRefFunc4(1, a, b)\r\n\tASSERT_EQ(a, 400)\r\n\tASSERT_EQ(ret, 400)\r\n\tret, b, a = CS.LuaTestObj.OutRefFunc5(b, 1, a)\r\n\tASSERT_EQ(a, 500)\r\n\tASSERT_EQ(ret, 500)\r\n\tret = CS.LuaTestObj.OutRefFunc6(1, 2)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseOutRef2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObj.CreateTestLuaObj()\r\n\tlocal b = CS.LuaTestObj.CreateTestLuaObj()\r\n\tlocal c = CS.LuaTestObj.CreateTestLuaObj()\r\n\ta, b = CS.LuaTestObj.OutRefFunc11(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 100)\r\n\tb, a = CS.LuaTestObj.OutRefFunc12(b, c, a)\r\n\tASSERT_EQ(a.cmpTarget, 200)\r\n\ta, b = CS.LuaTestObj.OutRefFunc13(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 300)\r\n\tret, a, b = CS.LuaTestObj.OutRefFunc14(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 400)\r\n\tASSERT_EQ(ret, 400)\r\n\tret, b, a = CS.LuaTestObj.OutRefFunc15(b, c, a)\r\n\tASSERT_EQ(a.cmpTarget, 500)\r\n\tASSERT_EQ(ret, 500)\r\n\tret = CS.LuaTestObj.OutRefFunc16(a, b)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseOutRef3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObj.csDelegate11\r\n\tlocal b = CS.LuaTestObj.csDelegate12\r\n\tlocal c = CS.LuaTestObj.csDelegate13\r\n\tCS.LuaTestObj.initNumber = 1\r\n\t\r\n\ta, b = CS.LuaTestObj.OutRefFunc21(c, a, b)\r\n\tASSERT_EQ(a(1), 2)\r\n\tb, a = CS.LuaTestObj.OutRefFunc22(b, c, a)\r\n\tASSERT_EQ(a(1), 3)\r\n\ta, b = CS.LuaTestObj.OutRefFunc23(c, a, b)\r\n\tASSERT_EQ(a(1), 4)\r\n\tret, a, b = CS.LuaTestObj.OutRefFunc24(c, a, b)\r\n\tASSERT_EQ(a(1), 6)\r\n\tASSERT_EQ(ret, 5)\r\n\tret, b, a = CS.LuaTestObj.OutRefFunc25(b, c, a)\r\n\tASSERT_EQ(a(1), 8)\r\n\tASSERT_EQ(ret, 7)\r\n\tret = CS.LuaTestObj.OutRefFunc26(a, b)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass1And5(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.NoContClass()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OneParamContClass(2)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.TwoParamsContClass(2, 3)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass4(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class1 = CS.testLuaCallCS.MultiContClass(2)\r\n\tlocal class2 = CS.testLuaCallCS.MultiContClass()\r\n\tlocal ret = class1:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class1.key1, 2)\r\n\tASSERT_EQ(class1.key2, 1)\r\n\tret = class2:add(2,2)\r\n\tASSERT_EQ(ret, 4)\t\r\n\tASSERT_EQ(class2.key1, 1)\r\n\tASSERT_EQ(class2.key2, 1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass6(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassA()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\r\n\tret = class:sub(9, 1)\r\n\tASSERT_EQ(ret, 8)\r\n\tASSERT_EQ(class.key1, 1)\r\n\tASSERT_EQ(class.key2, 1)\r\n\tASSERT_EQ(class.key3, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseNewClass7(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.StaticTestClass.n = 0\r\n\tCS.testLuaCallCS.StaticTestClass:Add()\r\n\tASSERT_EQ(CS.testLuaCallCS.StaticTestClass.n, 1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStaticMemFunc_1(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.MultiContClass.d = 3\r\n\tlocal ret = CS.testLuaCallCS.MultiContClass.d\r\n\tASSERT_EQ(ret, 3)\r\n\tret = CS.testLuaCallCS.MultiContClass.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStaticMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tCS.NoContClass.d = 4\r\n\tlocal ret = CS.NoContClass.d\r\n\tASSERT_EQ(ret, 4)\r\n\tret = CS.NoContClass.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStaticMemFunc_3(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.StaticTestClass.n = 2\r\n\tCS.testLuaCallCS.StaticTestClass:Add()\r\n\tASSERT_EQ(CS.testLuaCallCS.StaticTestClass.n, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitClassMemFunc_1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.NoContClass()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\r\n\tclass.key3 = false;\r\n\tASSERT_EQ(class.key3, false)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitClassMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OneParamContClass(2)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tclass.key1 = 3\r\n\tclass.key2 = 4\r\n\tASSERT_EQ(class.key1, 3)\r\n\tASSERT_EQ(class.key2, 4)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitFatherClassMemFunc_1_1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassC()\r\n\tCS.testLuaCallCS.OverClassC.bValue = true\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.bValue, true)\t\r\n\tCS.testLuaCallCS.OverClassC.Set(false)\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.bValue, false)\r\n\t\r\n\tCS.testLuaCallCS.OverClassC.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassC.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\tclass.key4 = 5\r\n\tclass.key1 = 1\r\n\tclass.key3 = false\r\n\tret = class:sub(10, 1)\r\n\tASSERT_EQ(ret, 10)\r\n\tASSERT_EQ(class.key4 , 5)\r\n\tASSERT_EQ(class.key1 , 1)\r\n\tASSERT_EQ(class.key3 , false)\r\n\tASSERT_EQ(class:add(1,2), 3)\r\n\t--ASSERT_EQ(class:sum(1, 2, 3), 6)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitFatherClassMemFunc_1_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassB()\r\n\t\r\n\tCS.testLuaCallCS.OverClassB.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassB.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassB.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\tclass.key1 = 2\r\n\tclass.key2 = 3\r\n\tret = class:add(10, 1)\r\n\tASSERT_EQ(ret, 11)\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 3)\r\n\tret = class:sub(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitFatherClassMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassCDeriveNGA()\r\n\t--[[CS.testLuaCallCS.OverClassCDeriveNGA.bValue = true\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.bValue, true)\t\r\n\tCS.testLuaCallCS.OverClassCDeriveNGA.Set(false)\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.bValue, false)]]\r\n\t\r\n\tCS.testLuaCallCS.OverClassCDeriveNGA.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassCDeriveNGA.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\t--class.key4 = 5\r\n\tclass.key1 = 1\r\n\tclass.key3 = false\r\n\t--ret = class:sub(10, 1)\r\n\t--ASSERT_EQ(ret, 9)\r\n\t--ASSERT_EQ(class.key4 , 5)\r\n\tASSERT_EQ(class.key1 , 1)\r\n\tASSERT_EQ(class.key3 , false)\r\n\tASSERT_EQ(class:add(1,2), 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitFatherClassMemFunc_3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.ChildCalss()\r\n\r\n\tlocal ret = class:add(10, 1)\r\n\tASSERT_EQ(ret, 11)\r\n\t\r\n\tclass.a = 3\r\n\tASSERT_EQ(class:getA() , 3)\r\n\tclass:setA(4)\r\n\tASSERT_EQ(class:getA() , 4)\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetChineseString(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestChineseString()\r\n\r\n\tlocal ret = class:GetShortChinString()\r\n\tASSERT_EQ(ret, \"中文字符串\")\r\n\t\r\n\tASSERT_EQ(class:GetLongChineString() , \"为Unity3D增加Lua脚本编程的能力，进而提供代码逻辑增量更新的可能，支持lua的所有基本类型，哈哈哈哈\")\r\n\tASSERT_EQ(class:GetCombineString() , \"中文字符串.* ? [ ] ^ $~`!@#$%^&()_-+=[];',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣12345abc\")\r\n\tASSERT_EQ(class:GetComplexString() , \"繁體國陸\")\r\n\tASSERT_EQ(class:GetHuoxingString() , \"吙煋呅僦媞這樣孒\")\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitUlong(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestUlongAndLongType()\r\n\r\n\tlocal ulong_max = class.UlongMax\r\n\t--ASSERT_EQ(tostring(ulong_max), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ulong_max), \"-1\") --V2.1.1\r\n\t--ASSERT_EQ(tostring(class:UlongAdd()), \"18446744073709550616\")\r\n\tASSERT_EQ(tostring(class:UlongAdd()), \"-1000\") --V2.1.1\r\n\tlocal ulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"0\")\r\n\t\r\n\tlocal ulong_mid = class.UlongMid\r\n\t--ASSERT_EQ(tostring(ulong_mid), \"9223372036854775808\")\r\n\tASSERT_EQ(tostring(ulong_mid), \"-9223372036854775808\") --v2.1.1\r\n\tclass.UlongMax = 1844674407370955\r\n\tulong_max = class.UlongMax\r\n\tASSERT_EQ(tostring(ulong_max), \"1844674407370955\")\r\n\t\r\n\tclass.UlongMin = 100\r\n\tulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"100\")\r\n\t\r\n\tlocal ulong_add = ulong_min + ulong_mid\r\n\t--ASSERT_EQ(tostring(ulong_add), \"9223372036854775908\")\r\n\tASSERT_EQ(tostring(ulong_add), \"-9223372036854775708\") --V2.1.1\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitlong(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestUlongAndLongType()\r\n\r\n\tlocal long_max = class.LongMax\r\n\tASSERT_EQ(tostring(long_max), \"9223372036854775807\")\r\n\t\r\n\tASSERT_EQ(tostring(class:LongAdd()), \"9223372036854774808\")\r\n\t\r\n\tlocal long_min = class.LongMin\r\n\tASSERT_EQ(tostring(long_min), \"-9223372036854775808\")\r\n\t\r\n\tlocal long_mid = class.LongMid\r\n\tASSERT_EQ(tostring(long_mid), \"4611686018427387904\")\r\n\t\r\n\tclass.LongMax = 461168601842738\r\n\tlong_max = class.LongMax\r\n\tASSERT_EQ(tostring(long_max), \"461168601842738\")\r\n\t\r\n\tclass.LongMin = 100\r\n\tlong_min = class.LongMin\r\n\tASSERT_EQ(tostring(long_min), \"100\")\r\n\t\r\n\tlocal long_add = long_min + long_mid\r\n\tASSERT_EQ(tostring(long_add), \"4611686018427388004\")\r\n\t\r\n\tclass.UlongMin = 100\r\n\tulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"100\")\r\n\t\r\n\t--local ret,errMessage = pcall(ulong_min + long_min)\r\n\t--ASSERT_EQ(errMessage, \"type not match, lhs is UInt64, rhs is Int64\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitExtensionMethodForClass(self)\r\n\tself.count = 1 + self.count\r\n    local class = CS.TestChineseString()\r\n    class:PrintAllString()\r\n\t\r\n\tlocal length = class:GetLongStringLength()\r\n\tASSERT_EQ(54, length)\r\n\t\r\n\tlength = class:Add(class)\r\n\tASSERT_EQ(108, length)\r\n\tlocal class_a = CS.TestChineseString()\r\n\tclass_a.short_simple_string = \"啊\"\r\n\tASSERT_EQ(class_a:GetShortChinString() , \"啊\")\r\n\t\r\n\tlocal class_d = CS.TestChineseString()\r\n\tclass_d.short_simple_string = \"ha\"\r\n\tlocal ret1\r\n\tlocal ret2\r\n\tret1, ret2 = class:Replace(class_d, class_a)\r\n\tASSERT_EQ(ret1:GetShortChinString(), \"中文字符串\")\r\n\tASSERT_EQ(ret2:GetCombineString(), \"中文字符串\")\r\n\tASSERT_EQ(ret2:GetShortChinString(), \"中文字符串ha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitExtensionMethodForStruct(self)\r\n\tself.count = 1 + self.count\r\n    local employ_1 = CS.Employeestruct()\r\n\temploy_1.Name = \"HONGFANG\"\r\n\temploy_1.Age = 30\r\n\temploy_1.Salary = 12000\r\n\temploy_1.AnnualBonus = 30000\r\n    employ_1:PrintSalary()\r\n\t\r\n\tlocal income = employ_1:GetIncomeForOneYear()\r\n\tASSERT_EQ(income, 174000)\r\n\t\r\n\tlocal employ_2 = CS.Employeestruct()\r\n\temploy_2.Name = \"xiaojun\"\r\n\temploy_2.Age =25\r\n\temploy_2.Salary = 5000\r\n\temploy_2.AnnualBonus = 10000\r\n    employ_2:PrintSalary()\r\n\t\r\n\tlocal cost = employ_1:Add(employ_2)\r\n\tASSERT_EQ(cost, 244000)\t\r\n\t\r\n\tlocal employ_3 = CS.Employeestruct()\r\n\temploy_3.Name = \"xiaojuan\"\r\n\temploy_3.Age =25\r\n\temploy_3.Salary = 5000\r\n\temploy_3.AnnualBonus = 10000\r\n    employ_3:PrintSalary()\r\n\t\r\n\tlocal ret1\r\n\tlocal ret2\r\n\tret1, ret2 = employ_1:Sub(employ_2, employ_3)\r\n\tASSERT_EQ(ret1.Name, \"xiaojun\")\r\n\tASSERT_EQ(ret1.Salary, 10000)\r\n\tASSERT_EQ(ret2.Name, \"xiaojuan\")\r\n\tASSERT_EQ(ret2.Salary, 7000)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_1(self)\r\n\tself.count = 1 + self.count\r\n    local struct_1 = CS.NoGenCodeStruct()\r\n\t\r\n\tlocal ret = struct_1:Add(2, 3)\r\n\tstruct_1.Byte = 10;\r\n\tstruct_1.Char = 97;\r\n\tstruct_1.Decimal = 12.33333333;\r\n\tstruct_1.Double = 10.111111111111;\r\n\tstruct_1.Float = 11.120;\r\n\tstruct_1.IntVar1 = 12345678;\r\n\tstruct_1.IntVar2 = -12345678;\r\n\tstruct_1.Long = CS.LongStatic.LONG_MAX;\r\n\tstruct_1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tstruct_1.Short = 123;\r\n\tstruct_1.String = \"just for test\";\r\n\tstruct_1.UInt = 12345;\r\n\tstruct_1.UShort = 255;\r\n\tstruct_1.IncludeStruct = CS.ConStruct (1, 2, \"haha\");\r\n\tASSERT_EQ(ret, 5)\r\n\tASSERT_EQ(struct_1.Byte, 10)\r\n\tASSERT_EQ(tostring(struct_1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(struct_1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(struct_1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(struct_1.Float), 1, 6), \"11.119\") --精度损失\r\n\tASSERT_EQ(struct_1.IntVar1, 12345678)\r\n\tASSERT_EQ(struct_1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(struct_1.Long), \"9223372036854775807\")\r\n\tASSERT_EQ(tostring(struct_1.ULong), \"-1\")\r\n\tASSERT_EQ(struct_1.Short, 123)\r\n\tASSERT_EQ(struct_1.String, \"just for test\")\r\n\tASSERT_EQ(struct_1.UInt, 12345)\r\n\tASSERT_EQ(struct_1.UShort, 255)\t\r\n\tASSERT_EQ(struct_1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(struct_1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(struct_1.IncludeStruct.z, \"haha\")\r\n\t\r\n\t\r\n\tlocal struct_2 = CS.ConStruct (2, 2, \"haha\");\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(struct_2.y, 2)\r\n\tASSERT_EQ(struct_2.z, \"haha\")\r\n\t\r\n\tstruct_1.String = nil;\r\n\tASSERT_EQ(struct_1.String, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_2(self)\r\n    --2.struct作为类静态/成员属性\r\n\tself.count = 1 + self.count\r\n    CS.NoGenCodeBaseClass.struct_var2 = CS.ConStruct(33333333, 44444444, \"test\") --分开赋值会失败\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var2.x, 33333333)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var2.y, 44444444)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var2.z, \"test\")\r\n\t\r\n\t\r\n\t--[[值传递所以修改副本，不会改动原本\r\n\tlocal ret = CS.NoGenCodeBaseClass.struct_var1:Add(2, 3)\r\n\tCS.NoGenCodeBaseClass.struct_var1.Byte = 10;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Char = 97;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Decimal = 12.33333333;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Double = 10.111111111111;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Float = 11.1234;\r\n\tCS.NoGenCodeBaseClass.struct_var1.IntVar1 = 12345678;\r\n\tCS.NoGenCodeBaseClass.struct_var1.IntVar2 = -12345678;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Long = CS.LongStatic.LONG_MAX;\r\n\tCS.NoGenCodeBaseClass.struct_var1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tCS.NoGenCodeBaseClass.struct_var1.Short = 123;\r\n\tCS.NoGenCodeBaseClass.struct_var1.String = \"just for test\";\r\n\tCS.NoGenCodeBaseClass.struct_var1.UInt = 12345;\r\n\tCS.NoGenCodeBaseClass.struct_var1.UShort = 255;\r\n\tCS.NoGenCodeBaseClass.struct_var1.IncludeStruct = CS.ConStruct (1, 2, \"haha\");\r\n\tASSERT_EQ(ret, 5)\r\n\t\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.Byte, 10)\r\n\tASSERT_EQ(tostring(CS.NoGenCodeBaseClass.struct_var1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(CS.NoGenCodeBaseClass.struct_var1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(CS.NoGenCodeBaseClass.struct_var1.Float), 1, 7), \"11.1234\")\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.IntVar1, 12345678)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(CS.NoGenCodeBaseClass.struct_var1.Long), \"9223372036854775807\")\r\n\tASSERT_EQ(tostring(CS.NoGenCodeBaseClass.struct_var1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.Short, 123)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.String, \"just for test\")\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.UInt, 12345)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.UShort, 255)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(CS.NoGenCodeBaseClass.struct_var1.IncludeStruct.z, \"haha\")\r\n\t\r\n\tlocal struct_2 = CS.NoGenCodeBaseClass.GetStaticVar();\r\n\tASSERT_EQ(struct_2.Byte, 10)\r\n\tASSERT_EQ(tostring(struct_2.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(struct_2.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(struct_2.Float), 1, 7), \"11.1234\")\r\n\tASSERT_EQ(struct_2.IntVar1, 12345678)\r\n\tASSERT_EQ(struct_2.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(struct_2.Long), \"9223372036854775807\")\r\n\tASSERT_EQ(tostring(struct_2.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(struct_2.Short, 123)\r\n\tASSERT_EQ(struct_2.String, \"just for test\")\r\n\tASSERT_EQ(struct_2.UInt, 12345)\r\n\tASSERT_EQ(struct_2.UShort, 255)\r\n\tASSERT_EQ(struct_2.IncludeStruct.x, 1)\r\n\tASSERT_EQ(struct_2.IncludeStruct.y, 2)\r\n\tASSERT_EQ(struct_2.IncludeStruct.z, \"haha\")\r\n\t]]\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_3_5_9(self)\r\n    --3.struct作为类静态/成员方法输入\r\n\t--5.struct作为类静态/成员方法输入输出，ref修饰\r\n\t--9.struct作为重载方法的输入（in）,输出（out），输入输出（ref）\r\n\tself.count = 1 + self.count\r\n    \t\r\n\tlocal struct_1 = CS.NoGenCodeStruct()\r\n\t\r\n\tstruct_1.Byte = 10;\r\n\tstruct_1.Char = 97;\r\n\tstruct_1.Decimal = 12.33333333;\r\n\tstruct_1.Double = 10.111111111111;\r\n\tstruct_1.Float = 11.1234;\r\n\tstruct_1.IntVar1 = 12345678;\r\n\tstruct_1.IntVar2 = -12345678;\r\n\tstruct_1.Long = CS.LongStatic.LONG_MAX;\r\n\tstruct_1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tstruct_1.Short = 123;\r\n\tstruct_1.String = \"just for test\";\r\n\tstruct_1.UInt = 12345;\r\n\tstruct_1.UShort = 256;\r\n\tstruct_1.IncludeStruct = CS.ConStruct (2, 2, \"haha\");\r\n\t\r\n\tlocal class_1 = CS.NoGenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:SetStruct(struct_1)\r\n\tASSERT_EQ(ret1.Byte, 10)\r\n\tASSERT_EQ(tostring(ret1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 12345678)\r\n\tASSERT_EQ(ret1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"-1\")\r\n\tASSERT_EQ(ret1.Short, 123)\r\n\tASSERT_EQ(ret1.String, \"just for test\")\r\n\tASSERT_EQ(ret1.UInt, 12345)\r\n\tASSERT_EQ(ret1.UShort, 256)\t\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"haha\")\r\n\t\r\n\tASSERT_EQ(ret2.Byte, 10)\r\n\tASSERT_EQ(tostring(ret2.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret2.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret2.Float), 1, 7), \"11.1233\")  --精度损失\r\n\tASSERT_EQ(ret2.IntVar1, 12345678)\r\n\tASSERT_EQ(ret2.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret2.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret2.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret2.ULong), \"-1\")\r\n\tASSERT_EQ(ret2.Short, 123)\r\n\tASSERT_EQ(ret2.String, \"just for test\")\r\n\tASSERT_EQ(ret2.UInt, 12345)\r\n\tASSERT_EQ(ret2.UShort, 256)\t\r\n\tASSERT_EQ(ret2.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret2.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret2.IncludeStruct.z, \"haha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_4(self)\r\n    --4.struct作为类静态/成员方法输出\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.NoGenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tASSERT_EQ(ret1.Byte, 10)\r\n\tASSERT_EQ(tostring(ret1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 12345678)\r\n\tASSERT_EQ(ret1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"-1\")\r\n\tASSERT_EQ(ret1.Short, 123)\r\n\tASSERT_EQ(ret1.String, \"just for test\")\r\n\tASSERT_EQ(ret1.UInt, 12345)\r\n\tASSERT_EQ(ret1.UShort, 255)\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"haha\")\r\n\tASSERT_EQ(ret2, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_6(self)\r\n    --6.struct作为一个类静态/成员方法输出，修改属性后，并作为另一个类静态/成员方法输入\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.NoGenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tret1.Byte = 100\r\n\tret1.Char = 98\r\n\tret1.Decimal = 22.33333333\r\n\tret1.Double = 20.111111111111\r\n\tret1.Float = 21.1234\r\n\tret1.IntVar1 = 22345678\r\n\tret1.IntVar2 = -22345678\r\n\tret1.Long = 9223372036854\r\n\tret1.ULong = 18446744073709\r\n\tret1.Short = 223\r\n\tret1.String = \"lua call c#\"\r\n\tret1.UInt = 22345\r\n\tret1.UShort = 155\r\n\tret1.IncludeStruct = CS.ConStruct (2, 2, \"hahaTEST\");\r\n\t\r\n\tlocal ret3, ret4 = class_1:SetStruct(ret1)\r\n\tASSERT_EQ(ret3.Byte, 100)\r\n\tASSERT_EQ(tostring(ret3.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret3.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret3.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret3.IntVar1, 22345678)\r\n\tASSERT_EQ(ret3.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret3.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret3.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret3.Short, 223)\r\n\tASSERT_EQ(ret3.String, \"lua call c#\")\r\n\tASSERT_EQ(ret3.UInt, 22345)\r\n\tASSERT_EQ(ret3.UShort, 155)\t\r\n\tASSERT_EQ(ret3.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.z, \"hahaTEST\")\r\n\t\r\n\tASSERT_EQ(ret4.Byte, 100)\r\n\tASSERT_EQ(tostring(ret4.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret4.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 22345678)\r\n\tASSERT_EQ(ret4.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret4.Short, 223)\r\n\tASSERT_EQ(ret4.String, \"lua call c#\")\r\n\tASSERT_EQ(ret4.UInt, 22345)\r\n\tASSERT_EQ(ret4.UShort, 155)\t\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"hahaTEST\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitNoGenCodeStruct_7(self)\r\n    --7.struct作为父类静态/成员属性，lua中通过子类实例访问，包括获取和设置\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.NoGenCodeDrivedClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tret1.Byte = 100\r\n\tret1.Char = 98\r\n\tret1.Decimal = 22.33333333\r\n\tret1.Double = 20.111111111111\r\n\tret1.Float = 21.1234\r\n\tret1.IntVar1 = 22345678\r\n\tret1.IntVar2 = -22345678\r\n\tret1.Long = 9223372036854\r\n\tret1.ULong = 18446744073709\r\n\tret1.Short = 223\r\n\tret1.String = \"lua call c#\"\r\n\tret1.UInt = 22345\r\n\tret1.UShort = 155\r\n\tret1.IncludeStruct = CS.ConStruct (2, 2, \"hahaTEST\");\r\n\t\r\n\tlocal ret3, ret4 = class_1:SetStruct(ret1)\r\n\tASSERT_EQ(ret3.Byte, 100)\r\n\tASSERT_EQ(tostring(ret3.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret3.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret3.Float), 1, 7), \"21.1233\")  --精度损失\r\n\tASSERT_EQ(ret3.IntVar1, 22345678)\r\n\tASSERT_EQ(ret3.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret3.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret3.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret3.Short, 223)\r\n\tASSERT_EQ(ret3.String, \"lua call c#\")\r\n\tASSERT_EQ(ret3.UInt, 22345)\r\n\tASSERT_EQ(ret3.UShort, 155)\t\r\n\tASSERT_EQ(ret3.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.z, \"hahaTEST\")\r\n\t\r\n\tASSERT_EQ(ret4.Byte, 100)\r\n\tASSERT_EQ(tostring(ret4.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret4.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 22345678)\r\n\tASSERT_EQ(ret4.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret4.Short, 223)\r\n\tASSERT_EQ(ret4.String, \"lua call c#\")\r\n\tASSERT_EQ(ret4.UInt, 22345)\r\n\tASSERT_EQ(ret4.UShort, 155)\t\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"hahaTEST\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_10(self)\r\n\tself.count = 1 + self.count\r\n    local struct_1 = CS.GenCodeStruct()\r\n\t\r\n\tlocal ret = struct_1:Add(2, 3)\r\n\tstruct_1.Byte = 10;\r\n\tstruct_1.Char = 97;\r\n\tstruct_1.Decimal = 12.33333333;\r\n\tstruct_1.Double = 10.111111111111;\r\n\tstruct_1.Float = 11.1234;\r\n\tstruct_1.IntVar1 = 12345678;\r\n\tstruct_1.IntVar2 = -12345678;\r\n\tstruct_1.Long = CS.LongStatic.LONG_MAX;\r\n\tstruct_1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tstruct_1.Short = 123;\r\n\tstruct_1.String = \"just for test\";\r\n\tstruct_1.UInt = 12345;\r\n\tstruct_1.UShort = 255;\r\n\tstruct_1.IncludeStruct = CS.HasConstructStruct (1, 2, \"haha\");\r\n\tASSERT_EQ(ret, 5)\r\n\tASSERT_EQ(struct_1.Byte, 10)\r\n\tASSERT_EQ(tostring(struct_1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(struct_1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(struct_1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(struct_1.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(struct_1.IntVar1, 12345678)\r\n\tASSERT_EQ(struct_1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(struct_1.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(struct_1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(struct_1.ULong), \"-1\") -- V2.1.1\r\n\tASSERT_EQ(struct_1.Short, 123)\r\n\tASSERT_EQ(struct_1.String, \"just for test\")\r\n\tASSERT_EQ(struct_1.UInt, 12345)\r\n\tASSERT_EQ(struct_1.UShort, 255)\t\r\n\tASSERT_EQ(struct_1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(struct_1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(struct_1.IncludeStruct.z, \"haha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_11(self)\r\n\tself.count = 1 + self.count\r\n    \t\r\n\tlocal ret = CS.GenCodeBaseClass.struct_var1:Add(2, 3)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.GBS, 1)\r\n\tCS.GenCodeBaseClass.GBS = 2;\r\n\tASSERT_EQ(CS.GenCodeBaseClass.GBS, 2)\r\n\tCS.GenCodeBaseClass.GBS = 1;\r\n\tCS.GenCodeBaseClass.struct_var2 = CS.HasConstructStruct(33333333, 44444444, \"test\") --分开赋值会失败\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var2.x, 33333333)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var2.y, 44444444)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var2.z, \"test\")\r\n\t\r\n\t--[[值传递所以修改副本，不会改动原本\r\n\tCS.GenCodeBaseClass.struct_var1.Byte = 10;\r\n\tCS.GenCodeBaseClass.struct_var1.Char = 97;\r\n\tCS.GenCodeBaseClass.struct_var1.Decimal = 12.33333333;\r\n\tCS.GenCodeBaseClass.struct_var1.Double = 10.111111111111;\r\n\tCS.GenCodeBaseClass.struct_var1.Float = 11.1234;\r\n\tCS.GenCodeBaseClass.struct_var1.IntVar1 = 12345678;\r\n\tCS.GenCodeBaseClass.struct_var1.IntVar2 = -12345678;\r\n\tCS.GenCodeBaseClass.struct_var1.Long = CS.LongStatic.LONG_MAX;\r\n\tCS.GenCodeBaseClass.struct_var1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tCS.GenCodeBaseClass.struct_var1.Short = 123;\r\n\tCS.GenCodeBaseClass.struct_var1.String = \"just for test\";\r\n\tCS.GenCodeBaseClass.struct_var1.UInt = 12345;\r\n\tCS.GenCodeBaseClass.struct_var1.UShort = 255;\r\n\tCS.GenCodeBaseClass.struct_var1.IncludeStruct = CS.HasConstructStruct (1, 2, \"haha\");\r\n\tASSERT_EQ(ret, 5)\r\n\t\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.Byte, 10)\r\n\tASSERT_EQ(tostring(CS.GenCodeBaseClass.struct_var1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(CS.GenCodeBaseClass.struct_var1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(CS.GenCodeBaseClass.struct_var1.Float), 1, 7), \"11.1234\")\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.IntVar1, 12345678)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(CS.GenCodeBaseClass.struct_var1.Long), \"9223372036854775807\")\r\n\tASSERT_EQ(tostring(CS.GenCodeBaseClass.struct_var1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.Short, 123)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.String, \"just for test\")\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.UInt, 12345)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.UShort, 255)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(CS.GenCodeBaseClass.struct_var1.IncludeStruct.z, \"haha\")\r\n\t\r\n\tlocal struct_2 = CS.GenCodeBaseClass.GetStaticVar();\r\n\tASSERT_EQ(struct_2.Byte, 10)\r\n\tASSERT_EQ(tostring(struct_2.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(struct_2.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(struct_2.Float), 1, 7), \"11.1234\")\r\n\tASSERT_EQ(struct_2.IntVar1, 12345678)\r\n\tASSERT_EQ(struct_2.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(struct_2.Long), \"9223372036854775807\")\r\n\tASSERT_EQ(tostring(struct_2.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(struct_2.Short, 123)\r\n\tASSERT_EQ(struct_2.String, \"just for test\")\r\n\tASSERT_EQ(struct_2.UInt, 12345)\r\n\tASSERT_EQ(struct_2.UShort, 255)\r\n\tASSERT_EQ(struct_2.IncludeStruct.x, 1)\r\n\tASSERT_EQ(struct_2.IncludeStruct.y, 2)\r\n\tASSERT_EQ(struct_2.IncludeStruct.z, \"haha\")]]\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_12_14_18(self)\r\n\tself.count = 1 + self.count\r\n    \t\r\n\tlocal struct_1 = CS.GenCodeStruct()\r\n\t\r\n\tstruct_1.Byte = 10;\r\n\tstruct_1.Char = 97;\r\n\tstruct_1.Decimal = 12.33333333;\r\n\tstruct_1.Double = 10.111111111111;\r\n\tstruct_1.Float = 11.1234;\r\n\tstruct_1.IntVar1 = 12345678;\r\n\tstruct_1.IntVar2 = -12345678;\r\n\tstruct_1.Long = CS.LongStatic.LONG_MAX;\r\n\tstruct_1.ULong = CS.LongStatic.ULONG_MAX;\r\n\tstruct_1.Short = 123;\r\n\tstruct_1.String = \"just for test\";\r\n\tstruct_1.UInt = 12345;\r\n\tstruct_1.UShort = 256;\r\n\tstruct_1.IncludeStruct = CS.HasConstructStruct (2, 2, \"haha\");\r\n\t\r\n\tlocal class_1 = CS.GenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:SetStruct(struct_1)\r\n\tASSERT_EQ(ret1.Byte, 10)\r\n\tASSERT_EQ(tostring(ret1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 12345678)\r\n\tASSERT_EQ(ret1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"-1\") --v2.1.1\r\n\tASSERT_EQ(ret1.Short, 123)\r\n\tASSERT_EQ(ret1.String, \"just for test\")\r\n\tASSERT_EQ(ret1.UInt, 12345)\r\n\tASSERT_EQ(ret1.UShort, 256)\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"haha\")\r\n\t\r\n\tASSERT_EQ(ret2.Byte, 10)\r\n\tASSERT_EQ(tostring(ret2.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret2.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret2.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret2.IntVar1, 12345678) \r\n\tASSERT_EQ(ret2.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret2.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret2.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret2.ULong), \"-1\") --V2.1.1\r\n\tASSERT_EQ(ret2.Short, 123)\r\n\tASSERT_EQ(ret2.String, \"just for test\")\r\n\tASSERT_EQ(ret2.UInt, 12345)\r\n\tASSERT_EQ(ret2.UShort, 256)\t\r\n\tASSERT_EQ(ret2.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret2.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret2.IncludeStruct.z, \"haha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_13(self)\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.GenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tASSERT_EQ(ret1.Byte, 100)\r\n\tASSERT_EQ(tostring(ret1.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret1.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 22345678)\r\n\tASSERT_EQ(ret1.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"-9223372036854775808\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"0\")\r\n\tASSERT_EQ(ret1.Short, 223)\r\n\tASSERT_EQ(ret1.String, \"2just for test\")\r\n\tASSERT_EQ(ret1.UInt, 22345)\r\n\tASSERT_EQ(ret1.UShort, 128)\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"2haha\")\r\n\tASSERT_EQ(ret2, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_15(self)\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.GenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tret1.Byte = 100\r\n\tret1.Char = 98\r\n\tret1.Decimal = 22.33333333\r\n\tret1.Double = 20.111111111111\r\n\tret1.Float = 21.1234\r\n\tret1.IntVar1 = 22345678\r\n\tret1.IntVar2 = -22345678\r\n\tret1.Long = 9223372036854\r\n\tret1.ULong = 18446744073709\r\n\tret1.Short = 223\r\n\tret1.String = \"lua call c#\"\r\n\tret1.UInt = 22345\r\n\tret1.UShort = 155\r\n\tret1.IncludeStruct = CS.HasConstructStruct (2, 2, \"hahaTEST\");\r\n\t\r\n\tlocal ret3, ret4 = class_1:SetStruct(ret1)\r\n\tASSERT_EQ(ret3.Byte, 100)\r\n\tASSERT_EQ(tostring(ret3.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret3.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret3.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret3.IntVar1, 22345678)\r\n\tASSERT_EQ(ret3.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret3.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret3.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret3.Short, 223)\r\n\tASSERT_EQ(ret3.String, \"lua call c#\")\r\n\tASSERT_EQ(ret3.UInt, 22345)\r\n\tASSERT_EQ(ret3.UShort, 155)\t\r\n\tASSERT_EQ(ret3.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.z, \"hahaTEST\")\r\n\t\r\n\tASSERT_EQ(ret4.Byte, 100)\r\n\tASSERT_EQ(tostring(ret4.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret4.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 22345678)\r\n\tASSERT_EQ(ret4.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret4.Short, 223)\r\n\tASSERT_EQ(ret4.String, \"lua call c#\")\r\n\tASSERT_EQ(ret4.UInt, 22345)\r\n\tASSERT_EQ(ret4.UShort, 155)\t\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"hahaTEST\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenCodeStruct_17(self)\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.GenCodeDrivedClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tret1.Byte = 100\r\n\tret1.Char = 98\r\n\tret1.Decimal = 22.33333333\r\n\tret1.Double = 20.111111111111\r\n\tret1.Float = 11.1234\r\n\tret1.IntVar1 = 22345678\r\n\tret1.IntVar2 = -22345678\r\n\tret1.Long = 9223372036854\r\n\tret1.ULong = 18446744073709\r\n\tret1.Short = 223\r\n\tret1.String = \"lua call c#\"\r\n\tret1.UInt = 22345\r\n\tret1.UShort = 155\r\n\tret1.IncludeStruct = CS.HasConstructStruct (2, 2, \"hahaTEST\");\r\n\t\r\n\tlocal ret3, ret4 = class_1:SetStruct(ret1)\r\n\tASSERT_EQ(ret3.Byte, 100)\r\n\tASSERT_EQ(tostring(ret3.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret3.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret3.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret3.IntVar1, 22345678)\r\n\tASSERT_EQ(ret3.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret3.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret3.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret3.Short, 223)\r\n\tASSERT_EQ(ret3.String, \"lua call c#\")\r\n\tASSERT_EQ(ret3.UInt, 22345)\r\n\tASSERT_EQ(ret3.UShort, 155)\t\r\n\tASSERT_EQ(ret3.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret3.IncludeStruct.z, \"hahaTEST\")\r\n\t\r\n\tASSERT_EQ(ret4.Byte, 100)\r\n\tASSERT_EQ(tostring(ret4.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret4.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"11.1233\") --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 22345678)\r\n\tASSERT_EQ(ret4.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"9223372036854\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"18446744073709\")\r\n\tASSERT_EQ(ret4.Short, 223)\r\n\tASSERT_EQ(ret4.String, \"lua call c#\")\r\n\tASSERT_EQ(ret4.UInt, 22345)\r\n\tASSERT_EQ(ret4.UShort, 155)\t\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"hahaTEST\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStruct_19(self)\r\n    --19.struct从反射接口返回，作为生成代码接口输入/输入输出\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.NoGenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tASSERT_EQ(ret1.Byte, 10)\r\n\tASSERT_EQ(tostring(ret1.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret1.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"11.1233\")  --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 12345678)\r\n\tASSERT_EQ(ret1.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret1.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"-1\")\r\n\tASSERT_EQ(ret1.Short, 123)\r\n\tASSERT_EQ(ret1.String, \"just for test\")\r\n\tASSERT_EQ(ret1.UInt, 12345)\r\n\tASSERT_EQ(ret1.UShort, 255)\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 1)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"haha\")\r\n\tASSERT_EQ(ret2, 0)\r\n\t\r\n\tlocal class_2 = CS.GenCodeBaseClass();\r\n\tlocal ret3, ret4 = class_2:SetStruct(ret1)\r\n\tASSERT_EQ(ret3, 0)\r\n\tASSERT_EQ(ret4.Byte, 10)\r\n\tASSERT_EQ(tostring(ret4.Char), \"97\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"12.33333333\")\r\n\tASSERT_EQ(ret4.Double, 10.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"11.1233\")  --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 12345678)\r\n\tASSERT_EQ(ret4.IntVar2, -12345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"9223372036854775807\")\r\n\t--ASSERT_EQ(tostring(ret4.ULong), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"-1\")\r\n\tASSERT_EQ(ret4.Short, 123)\r\n\tASSERT_EQ(ret4.String, \"just for test\")\r\n\tASSERT_EQ(ret4.UInt, 12345)\r\n\tASSERT_EQ(ret4.UShort, 255)\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 1)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"haha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStruct_20(self)\r\n    --20.struct从生成代码接口返回，作为反射接口输入/输入输出\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal class_1 = CS.GenCodeBaseClass();\r\n\tlocal ret1, ret2 = class_1:InitStruct()\r\n\tASSERT_EQ(ret1.Byte, 100)\r\n\tASSERT_EQ(tostring(ret1.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret1.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret1.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret1.IntVar1, 22345678)\r\n\tASSERT_EQ(ret1.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret1.Long), \"-9223372036854775808\")\r\n\tASSERT_EQ(tostring(ret1.ULong), \"0\")\r\n\tASSERT_EQ(ret1.Short, 223)\r\n\tASSERT_EQ(ret1.String, \"2just for test\")\r\n\tASSERT_EQ(ret1.UInt, 22345)\r\n\tASSERT_EQ(ret1.UShort, 128)\r\n\tASSERT_EQ(ret1.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret1.IncludeStruct.z, \"2haha\")\r\n\tASSERT_EQ(ret2, 0)\r\n\t\r\n\tlocal class_2 = CS.NoGenCodeBaseClass();\r\n\tlocal ret3, ret4 = class_2:SetStruct(ret1)\r\n\tASSERT_EQ(ret3, 0)\r\n\tASSERT_EQ(tostring(ret4.Char), \"98\")\r\n\tASSERT_EQ(string.sub(tostring(ret4.Decimal), 1, 11), \"22.33333333\")\r\n\tASSERT_EQ(ret4.Double, 20.111111111111)\r\n\tASSERT_EQ(string.sub(tostring(ret4.Float), 1, 7), \"21.1233\") --精度损失\r\n\tASSERT_EQ(ret4.IntVar1, 22345678)\r\n\tASSERT_EQ(ret4.IntVar2, -22345678)\r\n\tASSERT_EQ(tostring(ret4.Long), \"-9223372036854775808\")\r\n\tASSERT_EQ(tostring(ret4.ULong), \"0\")\r\n\tASSERT_EQ(ret4.Short, 223)\r\n\tASSERT_EQ(ret4.String, \"2just for test\")\r\n\tASSERT_EQ(ret4.UInt, 22345)\r\n\tASSERT_EQ(ret4.UShort, 128)\r\n\tASSERT_EQ(ret4.IncludeStruct.x, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.y, 2)\r\n\tASSERT_EQ(ret4.IncludeStruct.z, \"2haha\")\r\n\tASSERT_EQ(ret2, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStruct_21(self)\r\n    --21.A继承B，B继承C， A,C生成代码，B不生成代码--->B也需要生成代码，或者A,B,C全部不生成代码\r\n\tself.count = 1 + self.count\r\n\t\r\n\t--22.A的实例访问B，C的struct类型属性\r\n\tlocal class_a = CS.AClass(1, 2, \"haha\")\r\n\tASSERT_EQ(class_a.BConStruct.x, 1)\r\n\tASSERT_EQ(class_a.BConStruct.y, 2)\r\n\tASSERT_EQ(class_a.BConStruct.z, \"haha\")\r\n\tASSERT_EQ(class_a.CConStruct.x, 1)\r\n\tASSERT_EQ(class_a.CConStruct.y, 2)\r\n\tASSERT_EQ(class_a.CConStruct.z, \"haha\")\r\n\t\r\n\t--23.A的实例调用B的输入，输出，输入输出为struct类型的方法\r\n\tlocal struct_1 = CS.HasConstructStruct(2, 3, \"TEST\")\r\n\tASSERT_EQ(struct_1.x, 2)\r\n\tASSERT_EQ(struct_1.y, 3)\r\n\tASSERT_EQ(struct_1.z, \"TEST\")\r\n\tlocal struct_2 = CS.HasConstructStruct(10, 1, \"heihei\")\r\n\tlocal ret1, ret2 = class_a:Sub(struct_1, struct_2)\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(ret1.x, 2)\r\n\tASSERT_EQ(ret1.y, 1)\r\n\tASSERT_EQ(ret1.z, \"heihei\")\r\n\tASSERT_EQ(ret2.x, -8)\r\n\tASSERT_EQ(ret2.y, 3)\r\n\tASSERT_EQ(ret2.z, \"TEST\")\r\n\t\r\n\t--24.A的实例调用C的输入，输出，输入输出为struct类型的方法\r\n\tlocal ret3, ret4 = class_a:Add(struct_1, struct_2)\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(ret3.x, 2)\r\n\tASSERT_EQ(ret3.y, 1)\r\n\tASSERT_EQ(ret3.z, \"heihei\")\r\n    ASSERT_EQ(ret4.x, 4)\r\n\tASSERT_EQ(ret4.y, 3)\r\n\tASSERT_EQ(ret4.z, \"TEST\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStructVaribleParam(self)\r\n    --可变函数参数为struct\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_1 = CS.HasConstructStruct(2, 3, \"TEST\")\r\n\tlocal struct_2 = CS.HasConstructStruct(10, 1, \"heihei\")\r\n\tlocal class_c = CS.CClass(1, 2, \"haha\")\r\n\tlocal ret = class_c:VariableParamFunc(struct_1, struct_2)\r\n\tASSERT_EQ(ret, 12)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitFloat1(self)\r\n\r\n    self.count = 1 + self.count\r\n\t\r\n\tlocal struct_2 = CS.NoGen2FloatStruct(1.17549435e-38, 2.125)\r\n\tASSERT_EQ(string.sub(tostring(struct_2.a), 1, 10) , \"1.17549435\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.a), -4, -1) , \"e-38\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.b), 1, 5), \"2.125\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStructFloat1(self)\r\n    --struct有2个float属性，不生成代码，会有精度损失\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_2 = CS.NoGen2FloatStruct(1.234, 2.125)\r\n\tASSERT_EQ(string.sub(tostring(struct_2.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.b), 1, 5), \"2.125\")\r\n\t\r\n\tlocal struct_3 = CS.NoGen3FloatStruct(struct_2.a, struct_2.b, struct_2.a + struct_2.b)\r\n\t\r\n\tASSERT_EQ(string.sub(tostring(struct_3.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_3.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_3.c), 1, 5), \"3.358\")\r\n\t\r\n\tlocal struct_4 = CS.NoGen4FloatStruct(struct_3.a, struct_3.b, struct_3.a + struct_3.b, struct_3.c)\r\n\t\r\n\tASSERT_EQ(string.sub(tostring(struct_4.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.c), 1, 5), \"3.358\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.d), 1, 5), \"3.358\")\r\n\t\r\n\tlocal struct_5 = CS.NoGen5FloatStruct(struct_2.a - struct_2.b, 2.125, 3.123, 4.500, 5.333)\r\n\tASSERT_EQ(string.sub(tostring(struct_5.a), 1, 6), \"-0.891\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.e), 1, 5), \"5.333\")\r\n\t\r\n\tlocal struct_6 = CS.NoGen6FloatStruct(struct_2.a * struct_2.b, struct_2.a/2, 3.123, 4.500, 5.333, 2.1)\r\n\tASSERT_EQ(string.sub(tostring(struct_6.a), 1, 5), \"2.622\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.b), 1, 6), \"0.6169\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.f), 1, 5), \"2.099\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStructFloatInClass(self)\r\n\t--class包含多个struct类型属性（struct有多个float属性），生成代码和不生成代码各种参数传递，会有精度损失\r\n\tself.count = 1 + self.count\r\n\tlocal class_1 = CS.TestNoGenFloatStructClass()\r\n\tlocal class_2 = CS.TestGenFloatStructClass()\r\n\t\r\n\tlocal no_gen_struct_2 = CS.NoGen2FloatStruct(1.234, 2.125)\r\n\tno_gen_struct_2.a = 1.234\r\n\tno_gen_struct_2.b = 2.125\r\n\t\r\n\tlocal no_gen_struct_3 = CS.NoGen3FloatStruct(970.12, 1012.34, 1111.45)\r\n\tno_gen_struct_3.a = 970.12\r\n\tno_gen_struct_3.b = 1012.34\r\n\tno_gen_struct_3.c = 1111.45\r\n\t\r\n\tlocal no_gen_struct_4 = CS.NoGen4FloatStruct(1.0, 1.0, 1.0, 2.0)\r\n\tno_gen_struct_4.a = 1018.2\r\n\tno_gen_struct_4.b = -972.1\r\n\tno_gen_struct_4.c = -100.2\r\n\tno_gen_struct_4.d = 999.2\r\n\t\r\n\tlocal no_gen_struct_5 = CS.NoGen5FloatStruct(1.2, 1.2, 1.2, 1.3, 1.3)\r\n\tno_gen_struct_5.a = 2.120\r\n\tno_gen_struct_5.b = 2.125\r\n\tno_gen_struct_5.c = 3.123\r\n\tno_gen_struct_5.d = 4.500\r\n\tno_gen_struct_5.e = 5.333\r\n\t\r\n\tlocal no_gen_struct_6 = CS.NoGen6FloatStruct(1.1, 1.1, 1.1, 1.1, 1.1, 1.2)\r\n\tno_gen_struct_6.a = 10.11\r\n\tno_gen_struct_6.b = 120.22\r\n\tno_gen_struct_6.c = 3.123\r\n\tno_gen_struct_6.d = 4.500\r\n\tno_gen_struct_6.e = 5.333\r\n\tno_gen_struct_6.f = 2.1\r\n\t\r\n\tlocal gen_struct_2 = CS.Gen2FloatStruct(1.0, 1.2)\r\n\tgen_struct_2.a = 1.234\r\n\tgen_struct_2.b = 2.125\r\n\t\r\n\tlocal gen_struct_3 = CS.Gen3FloatStruct(1.3, 1.3, 1.3)\r\n\tgen_struct_3.a = 970.12\r\n\tgen_struct_3.b = 1012.34\r\n\tgen_struct_3.c = 1111.45\r\n\t\r\n\tlocal gen_struct_4 = CS.Gen4FloatStruct(1.0, 1.0, 1.0, 2.0)\r\n\tgen_struct_4.a = 1018.2\r\n\tgen_struct_4.b = -972.1\r\n\tgen_struct_4.c = -100.2\r\n\tgen_struct_4.d = 999.2\r\n\t\r\n\tlocal gen_struct_5 = CS.Gen5FloatStruct(1.2, 1.2, 1.2, 1.3, 1.3)\r\n\tgen_struct_5.a = 2.120\r\n\tgen_struct_5.b = 2.125\r\n\tgen_struct_5.c = 3.123\r\n\tgen_struct_5.d = 4.500\r\n\tgen_struct_5.e = 5.333\r\n\t\r\n\tlocal gen_struct_6 = CS.Gen6FloatStruct(1.1, 1.1, 1.1, 1.1, 1.1, 1.2)\r\n\tgen_struct_6.a = 10.11\r\n\tgen_struct_6.b = 120.22\r\n\tgen_struct_6.c = 3.123\r\n\tgen_struct_6.d = 4.500\r\n\tgen_struct_6.e = 5.333\r\n\tgen_struct_6.f = 2.1\r\n\t\r\n\tclass_1.Struct2 = no_gen_struct_2;\r\n\tclass_1.Struct3 = no_gen_struct_3;\r\n\tclass_1.Struct4 = no_gen_struct_4;\r\n\tclass_1.Struct5 = no_gen_struct_5;\r\n\tclass_1.Struct6 = no_gen_struct_6;\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct2.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct2.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct3.a), 1, 6), \"970.11\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct3.b), 1, 7), \"1012.34\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct3.c), 1, 7), \"1111.44\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct4.a), 1, 7), \"1018.20\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct4.b), 1, 7), \"-972.09\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct4.c), 1, 7), \"-100.19\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct4.d), 1, 6), \"999.20\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct5.a), 1, 5), \"2.119\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct5.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct5.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct5.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct5.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.a), 1, 6), \"10.109\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.b), 1, 7), \"120.220\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(class_1.Struct6.f), 1, 5), \"2.099\")\r\n\t\r\n\tclass_2.Struct2 = gen_struct_2;\r\n\tclass_2.Struct3 = gen_struct_3;\r\n\tclass_2.Struct4 = gen_struct_4;\r\n\tclass_2.Struct5 = gen_struct_5;\r\n\tclass_2.Struct6 = gen_struct_6;\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct2.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct2.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct3.a), 1, 6), \"970.11\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct3.b), 1, 7), \"1012.34\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct3.c), 1, 7), \"1111.44\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct4.a), 1, 7), \"1018.20\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct4.b), 1, 7), \"-972.09\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct4.c), 1, 7), \"-100.19\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct4.d), 1, 6), \"999.20\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct5.a), 1, 5), \"2.119\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct5.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct5.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct5.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct5.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.a), 1, 6), \"10.109\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.b), 1, 7), \"120.220\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(class_2.Struct6.f), 1, 5), \"2.099\")\r\n\t\r\n\tlocal ret1, ret2 = class_1:Add2(no_gen_struct_2, gen_struct_2)\r\n\tASSERT_EQ(string.sub(tostring(ret1.a), 1, 5), \"2.467\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.b), 1, 5), \"4.25\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.a), 1, 5), \"2.467\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.b), 1, 5), \"4.25\")\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenStructFloat1(self)\r\n    --struct有2个float属性，生成代码，会有精度损失\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_2 = CS.Gen2FloatStruct(1.234, 2.125)\r\n\tASSERT_EQ(string.sub(tostring(struct_2.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_2.b), 1, 5), \"2.125\")\r\n\t\r\n\tlocal struct_3 = CS.Gen3FloatStruct(struct_2.a, struct_2.b, struct_2.a + struct_2.b)\r\n\t\r\n\tASSERT_EQ(string.sub(tostring(struct_3.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_3.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_3.c), 1, 5), \"3.358\")\r\n\t\r\n\tlocal struct_4 = CS.Gen4FloatStruct(struct_3.a, struct_3.b, struct_3.a + struct_3.b, struct_3.c)\r\n\t\r\n\tASSERT_EQ(string.sub(tostring(struct_4.a), 1, 5), \"1.233\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.c), 1, 5), \"3.358\")\r\n\tASSERT_EQ(string.sub(tostring(struct_4.d), 1, 5), \"3.358\")\r\n\t\r\n\tlocal struct_5 = CS.Gen5FloatStruct(struct_2.a - struct_2.b, 2.125, 3.123, 4.500, 5.333)\r\n\tASSERT_EQ(string.sub(tostring(struct_5.a), 1, 6), \"-0.891\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.b), 1, 5), \"2.125\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(struct_5.e), 1, 5), \"5.333\")\r\n\t\r\n\tlocal struct_6 = CS.Gen6FloatStruct(struct_2.a * struct_2.b, struct_2.a/2, 3.123, 4.500, 5.333, 2.1)\r\n\tASSERT_EQ(string.sub(tostring(struct_6.a), 1, 5), \"2.622\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.b), 1, 6), \"0.6169\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.c), 1, 5), \"3.122\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.d), 1, 5), \"4.5\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.e), 1, 5), \"5.333\")\r\n\tASSERT_EQ(string.sub(tostring(struct_6.f), 1, 5), \"2.099\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStructInt1(self)\r\n    --struct有2个int属性，不生成代码\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_2 = CS.NoGen2IntStruct(2, 3)\r\n\tASSERT_EQ(struct_2.a, 2)\r\n\tASSERT_EQ(struct_2.b, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStructIntString1(self)\r\n    --struct有2个int属性， 1个string属性，不生成代码\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_2 = CS.ConStruct(2, 3, \"haha\")\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(struct_2.y, 3)\r\n\tASSERT_EQ(struct_2.z, \"haha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseReflectEvent1(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tgTestNumber = 1\r\n\tlocal testObj = CS.TestReflectEventClass()\r\n\ttestObj:TestEvent1('+', EvtFunc11)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(2, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(2)\r\n\tASSERT_EQ(7, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(12, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(15, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(16, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(17, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc11)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseEventStatic(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tgTestNumber = 1\r\n\tCS.LuaTestObj.TestStaticEvent1('+', EvtFunc11)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(1)\r\n\tASSERT_EQ(2, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('+', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(2)\r\n\tASSERT_EQ(7, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('+', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(1)\r\n\tASSERT_EQ(12, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(1)\r\n\tASSERT_EQ(15, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(1)\r\n\tASSERT_EQ(16, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObj.CallStaticEvent(1)\r\n\tASSERT_EQ(17, ret)\r\n\tCS.LuaTestObj.TestStaticEvent1('-', EvtFunc11)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseUpLowerMethod(self)\r\n\tself.count = 1 + self.count\r\n\tCS.LuaTestObj.initNumber = 5\r\n\tlocal ret = CS.LuaTestObj.CalcAdd(1)\r\n\tASSERT_EQ(6, ret)\r\n\t\r\n\tlocal ret = CS.LuaTestObj.calcadd(2)\r\n\tASSERT_EQ(8, ret)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseUpLowerMethod(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObj.OverLoad1(1, 2, 3, 5)\r\n\tASSERT_EQ(11, ret)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitStaticPusherStruct_1(self)\r\n\tself.count = 1 + self.count\r\n    local struct_1 = CS.StaticPusherStructA(97, -100)\r\n\tlocal struct_2 = CS.StaticPusherStructB(-32525, 65535, -2147483647, 4294967295)\r\n\tASSERT_EQ(struct_1.byteVar, 97)\r\n\tASSERT_EQ(struct_1.sbyteVar, -100)\r\n\tASSERT_EQ(struct_2.shortVar, -32525)\r\n\tASSERT_EQ(struct_2.ushortVar, 65535)\r\n\tASSERT_EQ(struct_2.intVar, -2147483647)\r\n\tASSERT_EQ(struct_2.uintVar, 4294967295)\r\n\tlocal struct_all = CS.StaticPusherStructAll()\r\n\tstruct_all.structA = struct_1\r\n\tstruct_all.structB = struct_2\r\n\tstruct_all.longVar = -4294967297\r\n\tstruct_all.ulongVar = 4294967297\r\n\tstruct_all.floatVar = 1.123456\r\n\tstruct_all.doubleVar = 1.7976931348623157\r\n\tASSERT_EQ(struct_all.structA.byteVar, 97)\r\n\tASSERT_EQ(struct_all.structA.sbyteVar, -100)\r\n\tASSERT_EQ(struct_all.structB.shortVar, -32525)\r\n\tASSERT_EQ(struct_all.structB.ushortVar, 65535)\r\n\tASSERT_EQ(struct_all.structB.intVar, -2147483647)\r\n\tASSERT_EQ(struct_all.structB.uintVar, 4294967295)\r\n\tASSERT_EQ(tostring(struct_all.longVar + 4294967297), \"0\")\r\n\tASSERT_EQ(tostring(struct_all.ulongVar), \"4294967297\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.floatVar), 1, 8), \"1.123456\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.doubleVar), 1, 14), \"1.797693134862\")\r\n\t\r\n\tlocal struct_all_2 = CS.StaticPusherStructAll()\r\n\tstruct_all_2.structA =  CS.StaticPusherStructA(0, 100)\r\n\tstruct_all_2.structB = CS.StaticPusherStructB(-1, 2, 214748364, 429496729)\r\n\tstruct_all_2.longVar = 4294967298\r\n\tstruct_all_2.ulongVar = 4294967297\r\n\tstruct_all_2.floatVar = 2.12345\r\n\tstruct_all_2.doubleVar = 2.7976931348\r\n\tlocal class_1 = CS.NoGenCodeBaseClass()\r\n\tlocal class_2 = CS.GenCodeBaseClass()\r\n\t\r\n\tlocal ret1, ret2 = class_1:SetStaticPusherStruct(struct_all_2, struct_all)\r\n\tprint(\"test ok\")\r\n\tASSERT_EQ(struct_all.structA.byteVar, 98)\r\n\tASSERT_EQ(struct_all.structA.sbyteVar, 101)\r\n\tASSERT_EQ(struct_all.structB.shortVar, -1)\r\n\tASSERT_EQ(struct_all.structB.ushortVar, 2)\r\n\tASSERT_EQ(struct_all.structB.intVar, -2147483646)\r\n\tASSERT_EQ(struct_all.structB.uintVar, 0)\r\n\tASSERT_EQ(tostring(struct_all.longVar + 4294967298), \"0\")\r\n\tASSERT_EQ(tostring(struct_all.ulongVar), \"4294967296\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.floatVar), 1, 8), \"0.123456\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.doubleVar), 1, 14), \"0.797693134862\")\r\n\tASSERT_EQ(ret1.structA.byteVar, 98)\r\n\tASSERT_EQ(ret1.structA.sbyteVar, 101)\r\n\tASSERT_EQ(ret1.structB.shortVar, -1)\r\n\tASSERT_EQ(ret1.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret1.structB.intVar, -2147483646)\r\n\tASSERT_EQ(ret1.structB.uintVar, 0)\r\n\tASSERT_EQ(tostring(ret1.longVar + 4294967298), \"0\")\r\n\tASSERT_EQ(tostring(ret1.ulongVar), \"4294967296\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.floatVar), 1, 8), \"0.123456\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.doubleVar), 1, 14), \"0.797693134862\")\r\n\tlocal ret3 = class_1.static_pushstruct_var;\r\n\tASSERT_EQ(ret3.structA.byteVar, 10)\r\n\tASSERT_EQ(ret3.structA.sbyteVar, 100)\r\n\tASSERT_EQ(ret3.structB.shortVar, -32525)\r\n\tASSERT_EQ(ret3.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret3.structB.intVar, -1932735283)\r\n\tASSERT_EQ(ret3.structB.uintVar, 429496728)\r\n\tASSERT_EQ(tostring(ret3.longVar), \"1\")\r\n\tASSERT_EQ(tostring(ret3.ulongVar), \"8589934594\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.floatVar), 1, 8), \"3.246906\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.doubleVar), 1, 14), \"4.595386269662\")\r\n\tASSERT_EQ(ret2.structA.byteVar, 10)\r\n\tASSERT_EQ(ret2.structA.sbyteVar, 100)\r\n\tASSERT_EQ(ret2.structB.shortVar, -32525)\r\n\tASSERT_EQ(ret2.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret2.structB.intVar, -1932735283)\r\n\tASSERT_EQ(ret2.structB.uintVar, 429496728)\r\n\tASSERT_EQ(tostring(ret2.longVar), \"1\")\r\n\tASSERT_EQ(tostring(ret2.ulongVar), \"8589934594\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.floatVar), 1, 8), \"3.246906\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.doubleVar), 1, 14), \"4.595386269662\")\r\n\t\r\n\t\r\n\tlocal ret1, ret2 = class_2:SetStaticPusherStruct(struct_all_2, struct_all)\r\n\tprint(\"test ok\")\r\n\tASSERT_EQ(struct_all.structA.byteVar, 98)\r\n\tASSERT_EQ(struct_all.structA.sbyteVar, 101)\r\n\tASSERT_EQ(struct_all.structB.shortVar, -1)\r\n\tASSERT_EQ(struct_all.structB.ushortVar, 2)\r\n\tASSERT_EQ(struct_all.structB.intVar, -2147483645)\r\n\tASSERT_EQ(struct_all.structB.uintVar, 1)\r\n\tASSERT_EQ(tostring(struct_all.longVar + 4294967299), \"0\")\r\n\tASSERT_EQ(tostring(struct_all.ulongVar), \"4294967295\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.floatVar), 1, 8), \"-0.87654\")\r\n\tASSERT_EQ(string.sub(tostring(struct_all.doubleVar), 1, 14), \"-0.20230686513\")\r\n\tASSERT_EQ(ret1.structA.byteVar, 98)\r\n\tASSERT_EQ(ret1.structA.sbyteVar, 101)\r\n\tASSERT_EQ(ret1.structB.shortVar, -1)\r\n\tASSERT_EQ(ret1.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret1.structB.intVar, -2147483645)\r\n\tASSERT_EQ(ret1.structB.uintVar, 1)\r\n\tASSERT_EQ(tostring(ret1.longVar + 4294967299), \"0\")\r\n\tASSERT_EQ(tostring(ret1.ulongVar), \"4294967295\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.floatVar), 1, 8), \"-0.87654\")\r\n\tASSERT_EQ(string.sub(tostring(ret1.doubleVar), 1, 14), \"-0.20230686513\")\r\n\tlocal ret3 = class_2.static_pushstruct_var;\r\n\tASSERT_EQ(ret3.structA.byteVar, 97)\r\n\tASSERT_EQ(ret3.structA.sbyteVar, 100)\r\n\tASSERT_EQ(ret3.structB.shortVar, -1)\r\n\tASSERT_EQ(ret3.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret3.structB.intVar, -1932735282)\r\n\tASSERT_EQ(ret3.structB.uintVar, 429496729)\r\n\tASSERT_EQ(tostring(ret3.longVar), \"0\")\r\n\tASSERT_EQ(tostring(ret3.ulongVar), \"8589934593\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.floatVar), 1, 8), \"2.246906\")\r\n\tASSERT_EQ(string.sub(tostring(ret3.doubleVar), 1, 14), \"3.595386269662\")\r\n\tASSERT_EQ(ret2.structA.byteVar, 97)\r\n\tASSERT_EQ(ret2.structA.sbyteVar, 100)\r\n\tASSERT_EQ(ret2.structB.shortVar, -1)\r\n\tASSERT_EQ(ret2.structB.ushortVar, 2)\r\n\tASSERT_EQ(ret2.structB.intVar, -1932735282)\r\n\tASSERT_EQ(ret2.structB.uintVar, 429496729)\r\n\tASSERT_EQ(tostring(ret2.longVar), \"0\")\r\n\tASSERT_EQ(tostring(ret2.ulongVar), \"8589934593\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.floatVar), 1, 8), \"2.246906\")\r\n\tASSERT_EQ(string.sub(tostring(ret2.doubleVar), 1, 14), \"3.595386269662\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetStaticSum(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.Sum(1, 2)\r\n\tASSERT_EQ(ret, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseGetSum(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\tlocal ret = class:Sum(1, 2, 6)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitTemplateMethod(self)\r\n    self.count = 1 + self.count\r\n\tASSERT_EQ(CS.EmployeeTemplate.GetBasicSalary, nil)\r\n\tASSERT_EQ(CS.EmployeeTemplate.AddBonus, nil)\r\n\tlocal class = CS.Manager()\r\n\tASSERT_EQ(1, class:GetBasicSalary())   \r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitGenericMethod(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\tlocal a = \"abc\"\r\n\tif (true) then\r\n\t\tlocal ret, error = pcall(function() class:GenericMethod(a) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitIntPtr(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\tlocal ptr = class.ptr\r\n\tprint(ptr)\r\n\tlocal ptr1 = class:GetPtr()\r\n    print(ptr1)\r\n    local bytevar = class:PrintPtr(ptr1)\r\n\tASSERT_EQ(bytevar, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitVarAndDefaultFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\r\n\tlocal ret = class:VariableParamFuncDefault(1)\r\n\tASSERT_EQ(ret, 2)\r\n\t\r\n\tlocal ret = CS.LuaTestObj.StaticVariableParamFuncDefault(1.0)\r\n\tASSERT_EQ(ret, 2.0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVisitVarAndDefaultFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\r\n\tlocal ret = class:VariableParamFuncDefault(1, 2, \"john\", \"che\")\r\n\tASSERT_EQ(ret, 3)\r\n\t\r\n\tlocal ret = CS.LuaTestObj.StaticVariableParamFuncDefault(1.0, 2.0, \"john\", \"che\")\r\n\tASSERT_EQ(ret, 3.0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncReturnByteArray(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObj.FuncReturnByteArray()\r\n\tASSERT_EQ(ret, \"abc\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncReturnByte(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObj.FuncReturnByte()\r\n\tASSERT_EQ(ret, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncReturnIntArray(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObj.FuncReturnIntArray()\r\n\tASSERT_EQ(type(ret), \"userdata\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncReturnInt(self)\r\n    self.count = 1 + self.count\r\n\t\r\n\tlocal ret = CS.LuaTestObj.FuncReturnInt()\r\n\tASSERT_EQ(ret, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncUint64Tostring(self)\r\n    self.count = 1 + self.count\r\n\tlocal uint64Var = 1234567890\r\n\tlocal ret = uint64.tostring(uint64Var)\r\n\tASSERT_EQ(ret, \"1234567890\")\r\n\tlocal ret = uint64.tostring(CS.LongStatic.ULONG_MAX)\r\n\tASSERT_EQ(ret, \"18446744073709551615\")\r\n\tlocal ret = uint64.tostring(0)\r\n\tASSERT_EQ(ret, \"0\")\r\n\tlocal ret = uint64.tostring(CS.LongStatic.LONG_MAX)\r\n\tASSERT_EQ(ret, \"9223372036854775807\")\r\n\tlocal ret = uint64.tostring(-1)\r\n\tASSERT_EQ(ret, uint64.tostring(CS.LongStatic.ULONG_MAX))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncUint64divide(self)\r\n    self.count = 1 + self.count\r\n\tlocal uint64Var = 1234567890\r\n\tlocal ret = uint64.divide(uint64Var, 10)\r\n\tASSERT_EQ(tostring(ret), \"123456789\")\r\n\tlocal ret = uint64.divide(CS.LongStatic.ULONG_MAX, 10)\r\n\tASSERT_EQ(tostring(ret), \"1844674407370955161\")\r\n\tlocal ret = uint64.divide(CS.LongStatic.LONG_MAX, 100)\r\n\tASSERT_EQ(tostring(ret), \"92233720368547758\")\r\n\tlocal ret = uint64.divide(CS.LongStatic.ULONG_MAX, -1)\r\n\tASSERT_EQ(tostring(ret), \"1\")\r\n\tlocal ret = uint64.divide(0, CS.LongStatic.ULONG_MAX)\r\n\tASSERT_EQ(tostring(ret), \"0\")\r\n\tif (true) then\r\n\t\tlocal ret, error = pcall(function() uint64.divide(CS.LongStatic.ULONG_MAX, 0) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncUint64compare(self)\r\n    self.count = 1 + self.count\r\n\tlocal uint64Var = 1234567890\r\n\tlocal ret = uint64.compare(uint64Var, uint64Var)\r\n\tASSERT_EQ(ret, 0)\r\n\tlocal ret = uint64.compare(CS.LongStatic.ULONG_MAX, uint64Var)\r\n\tASSERT_EQ(ret, 1)\r\n\tlocal ret = uint64.compare(CS.LongStatic.LONG_MAX, CS.LongStatic.LONG_MAX)\r\n\tASSERT_EQ(ret, 0)\r\n\tlocal ret = uint64.compare(CS.LongStatic.ULONG_MAX, -1)\r\n\tASSERT_EQ(ret, 0)\r\n\tlocal ret = uint64.compare(0, CS.LongStatic.ULONG_MAX)\r\n\tASSERT_EQ(ret, -1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFuncUint64remainder(self)\r\n    self.count = 1 + self.count\r\n\tlocal uint64Var = 1234567890\r\n\tlocal ret = uint64.remainder(uint64Var, uint64Var)\r\n\tASSERT_EQ(tostring(ret), \"0\")\r\n\tlocal ret = uint64.remainder(CS.LongStatic.ULONG_MAX, uint64Var)\r\n\tASSERT_EQ(tostring(ret), \"834183465\")\r\n\tlocal ret = uint64.remainder(CS.LongStatic.LONG_MAX, CS.LongStatic.LONG_MAX)\r\n\tASSERT_EQ(tostring(ret), \"0\")\r\n\tlocal ret = uint64.remainder(CS.LongStatic.ULONG_MAX, -1)\r\n\tASSERT_EQ(tostring(ret), \"0\")\r\n\tlocal ret = uint64.remainder(0, CS.LongStatic.ULONG_MAX)\r\n\tASSERT_EQ(tostring(ret), \"0\")\r\n\tif (true) then\r\n\t\tlocal ret, error = pcall(function() uint64.remainder(CS.LongStatic.ULONG_MAX, 0) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransSimpleClassMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:SimpleClassMethod({x=97, y=\"123\", z=100000000000})\r\n\tASSERT_EQ(ret.x, 97)\r\n\tASSERT_EQ(ret.y, \"123\")\r\n\tASSERT_EQ(tostring(ret.z), \"100000000000\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransComplexClassMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:ComplexClassMethod({A=97, B={x=97, y=\"123\", z=100000000000}})\r\n\tASSERT_EQ(ret.IntVar, 97)\r\n\tASSERT_EQ(ret.ClassVar.IntVar, 97)\r\n\tASSERT_EQ(ret.ClassVar.StringVar, \"123\")\r\n\tASSERT_EQ(tostring(ret.ClassVar.LongVar), \"100000000000\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransSimpleStructMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:SimpleStructMethod({a=97})\r\n\tASSERT_EQ(ret.a, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransComplexStructMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:ComplexStructMethod({a=-101, b=1000, c=1.000000132, d={a=97}})\r\n\tASSERT_EQ(ret.a, -101)\r\n\tASSERT_EQ(ret.b, 1000)\r\n\tASSERT_EQ(string.sub(tostring(ret.c), 1, 11), \"1.000000132\")\r\n\tASSERT_EQ(ret.d.a, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransOneListMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:OneListMethod({1, 2, 3, 4, 5})\r\n\tASSERT_EQ(ret, 15)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTableAutoTransTwoDimensionListMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClass()\r\n\tlocal ret = class:TwoDimensionListMethod({{1, 2, 3},{4, 5, 6}})\r\n\tASSERT_EQ(ret, 21)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseTestImplicit(self)\r\n\tself.count = 1 + self.count\r\n    if CS.LuaTestCommon.IsXLuaGeneral() then return end\r\n\tlocal ret = CS.LuaTestObj.TestImplicit():GetType()\r\n\tASSERT_EQ(ret, typeof(CS.UnityEngine.LayerMask))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVariableParamFunc2_1_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret, err = pcall(function() CS.LuaTestObj.VariableParamFunc(0, CS.LuaTestObj()) end)\r\n\tASSERT_EQ(ret, false)\r\n\tASSERT_TRUE(err:find(\"invalid arguments\"))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseFirstPushEnum(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.FirstPushEnumFunc(1)\r\n\tASSERT_EQ(ret, \"1\")\r\n\tlocal ret = CS.LuaTestObj.FirstPushEnumFunc(2)\r\n\tASSERT_EQ(ret, \"4\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseReferTestClass(self)\r\n\tself.count = 1 + self.count\r\n\tlocal int_x = 10\r\n\tlocal int_y = 12\r\n\tlocal str_z = \"abc\"\r\n\tlocal class1, ret_y, ret_z = CS.ReferTestClass(int_x, int_y)\r\n\tlocal ret = class1:Get_X_Y_ADD()\r\n\tASSERT_EQ(ret, 22)\r\n\tASSERT_EQ(ret_y, 11)\r\n\tASSERT_EQ(ret_z, \"test1\")\r\n\r\n\tlocal class3, ret_z = CS.ReferTestClass(int_x)\r\n\tlocal ret = class3:Get_X_Y_ADD()\r\n\tASSERT_EQ(ret, 20)\r\n\tASSERT_EQ(ret_z, \"test3\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCS.CaseVariableParamFuncNoParam(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.VariableParamFunc2()\r\n\tASSERT_EQ(ret, 0)\r\n\tlocal ret = CS.LuaTestObj.VariableParamFunc2(\"abc\", \"haha\")\r\n\tASSERT_EQ(ret, 2)\r\nend"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaCallCs.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 58a8a02fffd75f04196fa18261f6b200\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaCallCsReflect.lua",
    "content": "require(\"ltest.init\")\r\n\r\ngTestNumber = 1\r\nfunction islua53() return not not math.type end\r\n\r\n-- for test case\r\nCMyTestCaseLuaCallCSReflect = TestCase:new()\r\nfunction CMyTestCaseLuaCallCSReflect:new(oo)\r\n    local o = oo or {}\r\n    o.count = 1\r\n    \r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.SetUpTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCSReflect.SetUpTestCase\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.TearDownTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCSReflect.TearDownTestCase\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.SetUp(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaCallCSReflect.SetUp\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.TearDown(self)\r\n    self.count = 1 + self.count\r\n\r\n\tprint(\"CMyTestCaseLuaCallCSReflect.TearDown\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.DefaultParaFuncSingle(100, \"abc\")\r\n\tASSERT_EQ(ret, 100)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.DefaultParaFuncSingle(100)\r\n\tASSERT_EQ(ret, 100)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc3(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.DefaultParaFuncMulti(100, \"\")\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.DefaultParaFuncMulti(100, \"efg\", 1)\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.DefaultParaFuncMulti(100, \"efg\", 1, 98)\r\n\tASSERT_EQ(ret, 101)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDefaultParamFunc6(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObjReflect.DefaultParaFuncMulti(100, \"efg\", 1, 98, 0) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVariableParamFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.VariableParamFunc(0)\r\n\tASSERT_EQ(ret, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVariableParamFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.VariableParamFunc(0, \"a\")\r\n\tASSERT_EQ(ret, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVariableParamFunc3(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObjReflect.VariableParamFunc(0, \"a\", 1, \"b\") end)\r\n\t\tASSERT_EQ(ret, true)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestEnumFunc(CS.LuaTestTypeReflect.DEF)\r\n\tASSERT_EQ(ret, 1)\r\nend\r\n--[[ 2016.11.25 新版本不支持整数直接当枚举用\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum2(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = -1\r\n\tlocal ret = CS.LuaTestObjReflect.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, -1)\r\nend\r\n]]\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum3(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestTypeReflect.__CastFrom(2)\r\n\tlocal ret = CS.LuaTestObjReflect.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum4(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestTypeReflect.__CastFrom(4)\r\n\tlocal ret = CS.LuaTestObjReflect.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 4)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum5(self)\r\n    self.count = 1 + self.count\r\n\tlocal enumValue = CS.LuaTestTypeReflect.__CastFrom(\"GHI\")\r\n\tlocal ret = CS.LuaTestObjReflect.TestEnumFunc(enumValue)\r\n\tASSERT_EQ(ret, 2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseLuaAccessEnum6(self)\r\n    self.count = 1 + self.count\r\n\t--if (CS.LuaTestCommon.IsMacPlatform() == false and CS.LuaTestCommon.IsIOSPlatform() == false) then\r\n    if (true) then\r\n\t\tlocal ret, error = pcall(function() CS.LuaTestObjReflect.TestEnumFunc(CS.LuaTestTypeReflect.__CastFrom(\"BCD\")) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType1(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.LuaTestObjReflect))\r\n\tASSERT_EQ(ret, \"LuaTestObjReflect\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType2(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.System.String))\r\n\tASSERT_EQ(ret, \"System.String\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType3(self)\r\n    self.count = 1 + self.count\r\n    if CS.LuaTestCommon.IsXLuaGeneral() then return end\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.UnityEngine.Vector3))\r\n\tASSERT_EQ(ret, \"UnityEngine.Vector3\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.System.Int16))\r\n\tASSERT_EQ(ret, \"System.Int16\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType5(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.XLua.LuaTable))\r\n\tASSERT_EQ(ret, \"XLua.LuaTable\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType6(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.XLua.LuaFunction))\r\n\tASSERT_EQ(ret, \"XLua.LuaFunction\")\r\nend\r\n\r\n--[[ v2.1.0中已将LuaUserData类去掉\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetType7(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.TestGetType(typeof(CS.XLua.LuaUserData))\r\n\tASSERT_EQ(ret, \"XLua.LuaUserData\")\r\nend\r\n]]\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.Case64BitInt1(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObjReflect.Gen64BitInt()\r\n\tlocal x1 = CS.LuaTestObjReflect.ulX1\r\n\tlocal x2 = CS.LuaTestObjReflect.ulX2\r\n\tlocal ret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret  = x2 - x1\r\n\t--ASSERT_EQ(\"16140901064495857664\", tostring(ret))\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\n\tx1 = CS.LuaTestObjReflect.lY1\r\n\tx2 = CS.LuaTestObjReflect.lY2\r\n\tret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret = x2 - x1\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\n\tx1 = CS.LuaTestObjReflect.i64Z1\r\n\tx2 = CS.LuaTestObjReflect.i64Z2\r\n\tret = x1 + x2\r\n\tASSERT_EQ(\"6917529027641081856\", tostring(ret))\r\n\tret = x2 - x1\r\n\tASSERT_EQ(\"-2305843009213693952\", tostring(ret))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.Case64BitInt2(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObjReflect.Gen64BitInt()\r\n\tlocal x1 = CS.LuaTestObjReflect.ulX1\r\n\tlocal x2 = CS.LuaTestObjReflect.ulX2\r\n\tASSERT_EQ(true, x2 < x1)\r\n\tASSERT_EQ(true, x2 <= x1)\r\n\tASSERT_EQ(false, x1 <= x2)\r\n\tASSERT_EQ(false, x1 < x2)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.Case64BitInt3(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObjReflect.Gen64BitInt()\r\n\tlocal y = CS.LuaTestObjReflect.lY3\r\n\ty = y * 100\r\n\tASSERT_EQ(tostring(y), \"112589990684262400\")\r\n\ty = y / 10000\r\n\tif islua53() then\r\n\t    ASSERT_EQ(tostring(y), \"11258999068426.0\")\r\n\telse\r\n\t\tASSERT_EQ(tostring(y), \"11258999068426\")\r\n\tend\r\n\ty = y % 1000\r\n\tif islua53() then\r\n\t    ASSERT_EQ(tostring(y), \"426.240234375\")\r\n\telse\r\n\t\tASSERT_EQ(tostring(y), \"426\")\r\n\tend\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.Case64BitInt4(self)\r\n    self.count = 1 + self.count\r\n\tCS.LuaTestObjReflect.Gen64BitInt()\r\n\tlocal ret = CS.LuaTestObjReflect.lY3 * CS.LuaTestObjReflect.lY4\r\n\tASSERT_EQ(tostring(ret), \"138485688541642752\")\r\n\tret = CS.LuaTestObjReflect.lY3 / CS.LuaTestObjReflect.lY5\r\n\tif islua53() then\r\n\t\tASSERT_EQ(tostring(ret), \"91202908614.226\")\r\n\telse\r\n\t    ASSERT_EQ(tostring(ret), \"91202908614\")\r\n\tend\r\n\tret = CS.LuaTestObjReflect.lY3 % CS.LuaTestObjReflect.lY6\r\n\tASSERT_EQ(tostring(ret), \"52636\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseCast1(self)\r\n    self.count = 1 + self.count\r\n\tlocal castObj = CS.TestCastClassReflect()\r\n\tcast(castObj, typeof(CS.TestCastClassReflect))\r\n\tASSERT_EQ(true, castObj:TestFunc1())\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseCast2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal castObj = CS.LuaTestObjReflect.CreateTestLuaObj()\r\n\tcast(castObj, typeof(CS.TestLuaClassReflect))\r\n\tASSERT_EQ(true, castObj:TestFunc1())\r\nend\r\n\r\nfunction LuaFunc1(x)\r\n\treturn x + 1\r\nend\r\n\r\nfunction LuaFunc2(x)\r\n\treturn x * 2\r\nend\t\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseDelgate1(self)\r\n\tself.count = 1 + self.count\r\n\t\r\n\tCS.LuaTestObjReflect.initNumber = 5\r\n\tCS.LuaTestObjReflect.GenDelegate()\r\n\tlocal luaDelgateLink = CS.LuaTestObjReflect.csDelegate\r\n\tluaDelgateLink = CS.LuaTestObjReflect.csDelegate1\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate2\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate3\r\n\tlocal ret = luaDelgateLink(1)\r\n\tASSERT_EQ(5, ret)\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(2, ret)\r\n\tCS.LuaTestObjReflect.csDelegate4 = LuaFunc2\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate4\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(4, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(10)\r\n\tASSERT_EQ(20 ,ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate4\r\n\tret = luaDelgateLink(19)\r\n\tASSERT_EQ(1900, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate3\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(1900, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate2\r\n\tret = luaDelgateLink(3)\r\n\tASSERT_EQ(1903, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate2\r\n\tret = luaDelgateLink(4)\r\n\tASSERT_EQ(1907, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n    local ret, error = pcall(function() luaDelgateLink(5) end)\r\n    ASSERT_EQ(false, ret)\r\n\r\n\tCS.LuaTestObjReflect.initNumber = 5\r\n\tluaDelgateLink = CS.LuaTestObjReflect.csDelegate3\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(5, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(6, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(8, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(9, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(9, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate3\r\n\tCS.LuaTestObjReflect.initNumber = 1\r\n\tlocal function LuaFunc4(x)\r\n\t\tCS.LuaTestObjReflect.initNumber = CS.LuaTestObjReflect.initNumber * 2\r\n\t\treturn CS.LuaTestObjReflect.initNumber\r\n\tend\r\n\tluaDelgateLink = CS.LuaTestObjReflect.csDelegate1\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 4)\r\n\tluaDelgateLink = luaDelgateLink + LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 20)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 42)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc4\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(ret, 43)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n\t\r\n\tCS.LuaTestObjReflect.initNumber = 1907\r\n\tluaDelgateLink = LuaFunc1\r\n\tret = luaDelgateLink(1)\r\n\tASSERT_EQ(2, ret)\t\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(2)\r\n\tASSERT_EQ(1909, ret)\r\n\tluaDelgateLink = luaDelgateLink + CS.LuaTestObjReflect.csDelegate4\r\n\tret = luaDelgateLink(3)\r\n\tASSERT_EQ(6, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(4)\r\n\tASSERT_EQ(8, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate1\r\n\tret = luaDelgateLink(5)\r\n\tASSERT_EQ(10, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(6)\r\n\tASSERT_EQ(12, ret)\r\n\tluaDelgateLink = luaDelgateLink - LuaFunc1\r\n\tret = luaDelgateLink(7)\r\n\tASSERT_EQ(14, ret)\r\n\tluaDelgateLink = luaDelgateLink - CS.LuaTestObjReflect.csDelegate4\r\n    local ret, error = pcall(function() luaDelgateLink(8) end)\r\n    ASSERT_EQ(false, ret)\r\nend\r\n\r\nfunction EvtFunc11(y)\r\n\tgTestNumber = y + gTestNumber\r\n\treturn gTestNumber\r\nend\r\n\r\nfunction EvtFunc12(y)\r\n\tgTestNumber = y + 1 + gTestNumber\r\n\treturn gTestNumber\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseEvent1(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tgTestNumber = 1\r\n\tlocal testObj = CS.LuaTestObjReflect()\r\n\ttestObj:TestEvent1('+', EvtFunc11)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(2, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(2)\r\n\tASSERT_EQ(7, ret)\r\n\ttestObj:TestEvent1('+', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(12, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(15, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(16, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc12)\r\n\tlocal ret = testObj:CallEvent(1)\r\n\tASSERT_EQ(17, ret)\r\n\ttestObj:TestEvent1('-', EvtFunc11)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseCalc1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObjReflect()\r\n\ta.testVar = 100\r\n\tlocal b = CS.LuaTestObjReflect()\r\n\tb.testVar = 200\r\n\tlocal ret = a + b\r\n\tASSERT_EQ(ret.testVar, 300)\r\n\tret = a - b\r\n\tASSERT_EQ(ret.testVar, -100)\r\n\tret = a * b\r\n\tASSERT_EQ(ret.testVar, 20000)\r\n\tret = b / a\r\n\tASSERT_EQ(ret.testVar, 2)\r\n\tret = b % a\r\n\tASSERT_EQ(ret.testVar, 0)\r\n\tret = a < b\r\n\tASSERT_EQ(true, ret)\r\n\tret = a <= b\r\n\tASSERT_EQ(true, ret)\r\n\tret = -a\r\n\tASSERT_EQ(ret.testVar, -100)\r\n\tlocal c = CS.LuaTestObjReflect()\r\n\tc.testArr[0] = 1000\r\n\tret = c[0]\r\n\tASSERT_EQ(1000, ret)\r\n\tc[1] = 10000\r\n\tret = c.testArr[1]\r\n\tASSERT_EQ(10000, ret)\r\n\t\r\n\ta.testVar = 100\r\n\tb.testVar = 200\r\n\tc.testVar = 300\r\n\tlocal d = CS.LuaTestObjReflect()\r\n\td.testVar = 20\r\n\tlocal e = CS.LuaTestObjReflect()\r\n\te.testVar = 7\r\n\tret = (a + b) * c / d % e\r\n\tASSERT_EQ(ret.testVar, 6)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseCalc2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObjReflect()\r\n\ta.testVar = 100\r\n\tlocal ret = 300 + a + 200\r\n\tASSERT_EQ(ret.testVar, 600)\r\n\tret = 100 - a - 400\r\n\tASSERT_EQ(ret.testVar, -400)\r\n\tret = 2 * a * 3\r\n\tASSERT_EQ(600, ret.testVar)\r\n\tret = 20000 / a / 2\r\n\tASSERT_EQ(100, ret.testVar)\r\n\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseOverLoad1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.OverLoad1(1, 2)\r\n\tASSERT_EQ(ret, 1)\r\n\tret = CS.LuaTestObjReflect.OverLoad2(\"1\", \"2\")\r\n\tASSERT_EQ(ret, 4);\r\n\tret = CS.LuaTestObjReflect.OverLoad3(1)\r\n\tASSERT_EQ(ret, 5);\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseOutRef1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = 2\r\n\tlocal b\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc1(1, a, b)\r\n\tASSERT_EQ(a, 100)\r\n\tb, a = CS.LuaTestObjReflect.OutRefFunc2(b, 1, a)\r\n\tASSERT_EQ(a, 200)\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc3(1, a, b)\r\n\tASSERT_EQ(a, 300)\r\n\tret, a, b = CS.LuaTestObjReflect.OutRefFunc4(1, a, b)\r\n\tASSERT_EQ(a, 400)\r\n\tASSERT_EQ(ret, 400)\r\n\tret, b, a = CS.LuaTestObjReflect.OutRefFunc5(b, 1, a)\r\n\tASSERT_EQ(a, 500)\r\n\tASSERT_EQ(ret, 500)\r\n\tret = CS.LuaTestObjReflect.OutRefFunc6(1, 2)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseOutRef2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObjReflect.CreateTestLuaObj()\r\n\tlocal b = CS.LuaTestObjReflect.CreateTestLuaObj()\r\n\tlocal c = CS.LuaTestObjReflect.CreateTestLuaObj()\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc11(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 100)\r\n\tb, a = CS.LuaTestObjReflect.OutRefFunc12(b, c, a)\r\n\tASSERT_EQ(a.cmpTarget, 200)\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc13(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 300)\r\n\tret, a, b = CS.LuaTestObjReflect.OutRefFunc14(c, a, b)\r\n\tASSERT_EQ(a.cmpTarget, 400)\r\n\tASSERT_EQ(ret, 400)\r\n\tret, b, a = CS.LuaTestObjReflect.OutRefFunc15(b, c, a)\r\n\tASSERT_EQ(a.cmpTarget, 500)\r\n\tASSERT_EQ(ret, 500)\r\n\tret = CS.LuaTestObjReflect.OutRefFunc16(a, b)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseOutRef3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal a = CS.LuaTestObjReflect.csDelegate11\r\n\tlocal b = CS.LuaTestObjReflect.csDelegate12\r\n\tlocal c = CS.LuaTestObjReflect.csDelegate13\r\n\tCS.LuaTestObjReflect.initNumber = 1\r\n\t\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc21(c, a, b)\r\n\tASSERT_EQ(a(1), 2)\r\n\tb, a = CS.LuaTestObjReflect.OutRefFunc22(b, c, a)\r\n\tASSERT_EQ(a(1), 3)\r\n\ta, b = CS.LuaTestObjReflect.OutRefFunc23(c, a, b)\r\n\tASSERT_EQ(a(1), 4)\r\n\tret, a, b = CS.LuaTestObjReflect.OutRefFunc24(c, a, b)\r\n\tASSERT_EQ(a(1), 6)\r\n\tASSERT_EQ(ret, 5)\r\n\tret, b, a = CS.LuaTestObjReflect.OutRefFunc25(b, c, a)\r\n\tASSERT_EQ(a(1), 8)\r\n\tASSERT_EQ(ret, 7)\r\n\tret = CS.LuaTestObjReflect.OutRefFunc26(a, b)\r\n\tASSERT_EQ(ret, 600)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass1And5(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.NoContClass()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OneParamContClass(2)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.TwoParamsContClass(2, 3)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass4(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class1 = CS.testLuaCallCS.MultiContClass(2)\r\n\tlocal class2 = CS.testLuaCallCS.MultiContClass()\r\n\tlocal ret = class1:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tASSERT_EQ(class1.key1, 2)\r\n\tASSERT_EQ(class1.key2, 1)\r\n\tret = class2:add(2,2)\r\n\tASSERT_EQ(ret, 4)\t\r\n\tASSERT_EQ(class2.key1, 1)\r\n\tASSERT_EQ(class2.key2, 1)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass6(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassA()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\r\n\tret = class:sub(9, 1)\r\n\tASSERT_EQ(ret, 8)\r\n\tASSERT_EQ(class.key1, 1)\r\n\tASSERT_EQ(class.key2, 1)\r\n\tASSERT_EQ(class.key3, 0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseNewClass7(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.StaticTestClass.n = 0\r\n\tCS.testLuaCallCS.StaticTestClass:Add()\r\n\tASSERT_EQ(CS.testLuaCallCS.StaticTestClass.n, 1)\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitStaticMemFunc_1(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.MultiContClass.d = 3\r\n\tlocal ret = CS.testLuaCallCS.MultiContClass.d\r\n\tASSERT_EQ(ret, 3)\r\n\tret = CS.testLuaCallCS.MultiContClass.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitStaticMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tCS.NoContClass.d = 4\r\n\tlocal ret = CS.NoContClass.d\r\n\tASSERT_EQ(ret, 4)\r\n\tret = CS.NoContClass.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitStaticMemFunc_3(self)\r\n\tself.count = 1 + self.count\r\n\tCS.testLuaCallCS.StaticTestClass.n = 2\r\n\tCS.testLuaCallCS.StaticTestClass:Add()\r\n\tASSERT_EQ(CS.testLuaCallCS.StaticTestClass.n, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitClassMemFunc_1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.NoContClass()\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\r\n\tclass.key3 = false;\r\n\tASSERT_EQ(class.key3, false)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitClassMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OneParamContClass(2)\r\n\tlocal ret = class:add(1,2)\r\n\tASSERT_EQ(ret, 3)\t\r\n\tclass.key1 = 3\r\n\tclass.key2 = 4\r\n\tASSERT_EQ(class.key1, 3)\r\n\tASSERT_EQ(class.key2, 4)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitFatherClassMemFunc_1_1(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassC()\r\n\tCS.testLuaCallCS.OverClassC.bValue = true\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.bValue, true)\t\r\n\tCS.testLuaCallCS.OverClassC.Set(false)\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.bValue, false)\r\n\t\r\n\tCS.testLuaCallCS.OverClassC.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassC.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassC.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\tclass.key4 = 5\r\n\tclass.key1 = 1\r\n\tclass.key3 = false\r\n\tret = class:sub(10, 1)\r\n\tASSERT_EQ(ret, 10)\r\n\tASSERT_EQ(class.key4 , 5)\r\n\tASSERT_EQ(class.key1 , 1)\r\n\tASSERT_EQ(class.key3 , false)\r\n\tASSERT_EQ(class:add(1,2), 3)\r\n\t--ASSERT_EQ(class:sum(1, 2, 3), 6)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitFatherClassMemFunc_1_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassB()\r\n\t\r\n\tCS.testLuaCallCS.OverClassB.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassB.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassB.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\tclass.key1 = 2\r\n\tclass.key2 = 3\r\n\tret = class:add(10, 1)\r\n\tASSERT_EQ(ret, 11)\r\n\tASSERT_EQ(class.key1, 2)\r\n\tASSERT_EQ(class.key2, 3)\r\n\tret = class:sub(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitFatherClassMemFunc_2(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.OverClassCDeriveNGA()\r\n\t--[[CS.testLuaCallCS.OverClassCDeriveNGA.bValue = true\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.bValue, true)\t\r\n\tCS.testLuaCallCS.OverClassCDeriveNGA.Set(false)\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.bValue, false)]]\r\n\t\r\n\tCS.testLuaCallCS.OverClassCDeriveNGA.d = 3\r\n\tASSERT_EQ(CS.testLuaCallCS.OverClassCDeriveNGA.d, 3)\t\r\n\tlocal ret = CS.testLuaCallCS.OverClassCDeriveNGA.dec(10, 1)\r\n\tASSERT_EQ(ret, 9)\r\n\t--class.key4 = 5\r\n\tclass.key1 = 1\r\n\tclass.key3 = false\r\n\t--ret = class:sub(10, 1)\r\n\t--ASSERT_EQ(ret, 9)\r\n\t--ASSERT_EQ(class.key4 , 5)\r\n\tASSERT_EQ(class.key1 , 1)\r\n\tASSERT_EQ(class.key3 , false)\r\n\tASSERT_EQ(class:add(1,2), 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitFatherClassMemFunc_3(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.testLuaCallCS.ChildCalss()\r\n\r\n\tlocal ret = class:add(10, 1)\r\n\tASSERT_EQ(ret, 11)\r\n\t\r\n\tclass.a = 3\r\n\tASSERT_EQ(class:getA() , 3)\r\n\tclass:setA(4)\r\n\tASSERT_EQ(class:getA() , 4)\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetChineseString(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestChineseStringReflect()\r\n\r\n\tlocal ret = class:GetShortChinString()\r\n\tASSERT_EQ(ret, \"中文字符串\")\r\n\t\r\n\tASSERT_EQ(class:GetLongChineString() , \"为Unity3D增加Lua脚本编程的能力，进而提供代码逻辑增量更新的可能，支持lua的所有基本类型，哈哈哈哈\")\r\n\tASSERT_EQ(class:GetCombineString() , \"中文字符串.* ? [ ] ^ $~`!@#$%^&()_-+=[];',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣12345abc\")\r\n\tASSERT_EQ(class:GetComplexString() , \"繁體國陸\")\r\n\tASSERT_EQ(class:GetHuoxingString() , \"吙煋呅僦媞這樣孒\")\r\n\t\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitUlong(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestUlongAndLongTypeReflect()\r\n\r\n\tlocal ulong_max = class.UlongMax\r\n\t--ASSERT_EQ(tostring(ulong_max), \"18446744073709551615\")\r\n\tASSERT_EQ(tostring(ulong_max), \"-1\") --V2.1.1\r\n\t--ASSERT_EQ(tostring(class:UlongAdd()), \"18446744073709550616\")\r\n\tASSERT_EQ(tostring(class:UlongAdd()), \"-1000\") --V2.1.1\r\n\tlocal ulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"0\")\r\n\t\r\n\tlocal ulong_mid = class.UlongMid\r\n\t--ASSERT_EQ(tostring(ulong_mid), \"9223372036854775808\")\r\n\tASSERT_EQ(tostring(ulong_mid), \"-9223372036854775808\") --v2.1.1\r\n\t\r\n\tclass.UlongMax = 1844674407370955\r\n\tulong_max = class.UlongMax\r\n\tASSERT_EQ(tostring(ulong_max), \"1844674407370955\")\r\n\t\r\n\tclass.UlongMin = 100\r\n\tulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"100\")\r\n\t\r\n\tlocal ulong_add = ulong_min + ulong_mid\r\n\t--ASSERT_EQ(tostring(ulong_add), \"9223372036854775908\")\r\n\tASSERT_EQ(tostring(ulong_add), \"-9223372036854775708\") --V2.1.1\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitlong(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.TestUlongAndLongTypeReflect()\r\n\r\n\tlocal long_max = class.LongMax\r\n\tASSERT_EQ(tostring(long_max), \"9223372036854775807\")\r\n\t\r\n\tASSERT_EQ(tostring(class:LongAdd()), \"9223372036854774808\")\r\n\t\r\n\tlocal long_min = class.LongMin\r\n\tASSERT_EQ(tostring(long_min), \"-9223372036854775808\")\r\n\t\r\n\tlocal long_mid = class.LongMid\r\n\tASSERT_EQ(tostring(long_mid), \"4611686018427387904\")\r\n\t\r\n\tclass.LongMax = 461168601842738\r\n\tlong_max = class.LongMax\r\n\tASSERT_EQ(tostring(long_max), \"461168601842738\")\r\n\t\r\n\tclass.LongMin = 100\r\n\tlong_min = class.LongMin\r\n\tASSERT_EQ(tostring(long_min), \"100\")\r\n\t\r\n\tlocal long_add = long_min + long_mid\r\n\tASSERT_EQ(tostring(long_add), \"4611686018427388004\")\r\n\t\r\n\tclass.UlongMin = 100\r\n\tulong_min = class.UlongMin\r\n\tASSERT_EQ(tostring(ulong_min), \"100\")\r\n\t\r\n\t--local ret,errMessage = pcall(ulong_min + long_min)\r\n\t--ASSERT_EQ(errMessage, \"type not match, lhs is UInt64, rhs is Int64\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitExtensionMethodForClass(self)\r\n\tself.count = 1 + self.count\r\n    local class = CS.TestChineseStringReflect()\r\n    class:PrintAllString()\r\n\t\r\n\tlocal length = class:GetLongStringLength()\r\n\tASSERT_EQ(54, length)\r\n\t\r\n\tlength = class:Add(class)\r\n\tASSERT_EQ(108, length)\r\n\tlocal class_a = CS.TestChineseStringReflect()\r\n\tclass_a.short_simple_string = \"啊\"\r\n\tASSERT_EQ(class_a:GetShortChinString() , \"啊\")\r\n\t\r\n\tlocal class_d = CS.TestChineseStringReflect()\r\n\tclass_d.short_simple_string = \"ha\"\r\n\tlocal ret1\r\n\tlocal ret2\r\n\tret1, ret2 = class:Replace(class_d, class_a)\r\n\tASSERT_EQ(ret1:GetShortChinString(), \"中文字符串\")\r\n\tASSERT_EQ(ret2:GetCombineString(), \"中文字符串\")\r\n\tASSERT_EQ(ret2:GetShortChinString(), \"中文字符串ha\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitExtensionMethodForStruct(self)\r\n\tself.count = 1 + self.count\r\n    local employ_1 = CS.EmployeestructReflect()\r\n\temploy_1.Name = \"HONGFANG\"\r\n\temploy_1.Age = 30\r\n\temploy_1.Salary = 12000\r\n\temploy_1.AnnualBonus = 30000\r\n    employ_1:PrintSalary()\r\n\t\r\n\tlocal income = employ_1:GetIncomeForOneYear()\r\n\tASSERT_EQ(income, 174000)\r\n\t\r\n\tlocal employ_2 = CS.EmployeestructReflect()\r\n\temploy_2.Name = \"xiaojun\"\r\n\temploy_2.Age =25\r\n\temploy_2.Salary = 5000\r\n\temploy_2.AnnualBonus = 10000\r\n    employ_2:PrintSalary()\r\n\t\r\n\tlocal cost = employ_1:Add(employ_2)\r\n\tASSERT_EQ(cost, 244000)\t\r\n\t\r\n\tlocal employ_3 = CS.EmployeestructReflect()\r\n\temploy_3.Name = \"xiaojuan\"\r\n\temploy_3.Age =25\r\n\temploy_3.Salary = 5000\r\n\temploy_3.AnnualBonus = 10000\r\n    employ_3:PrintSalary()\r\n\t\r\n\tlocal ret1\r\n\tlocal ret2\r\n\tret1, ret2 = employ_1:Sub(employ_2, employ_3)\r\n\tASSERT_EQ(ret1.Name, \"xiaojun\")\r\n\tASSERT_EQ(ret1.Salary, 10000)\r\n\tASSERT_EQ(ret2.Name, \"xiaojuan\")\r\n\tASSERT_EQ(ret2.Salary, 7000)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitStruct_21(self)\r\n    --21.A继承B，B继承C， A,C生成代码，B不生成代码--->B也需要生成代码，或者A,B,C全部不生成代码\r\n\tself.count = 1 + self.count\r\n\t\r\n\t--22.A的实例访问B，C的struct类型属性\r\n\tlocal class_a = CS.AClassReflect(1, 2, \"haha\")\r\n\tASSERT_EQ(class_a.BConStruct.x, 1)\r\n\tASSERT_EQ(class_a.BConStruct.y, 2)\r\n\tASSERT_EQ(class_a.BConStruct.z, \"haha\")\r\n\tASSERT_EQ(class_a.CConStruct.x, 1)\r\n\tASSERT_EQ(class_a.CConStruct.y, 2)\r\n\tASSERT_EQ(class_a.CConStruct.z, \"haha\")\r\n\t\r\n\t--23.A的实例调用B的输入，输出，输入输出为struct类型的方法\r\n\tlocal struct_1 = CS.HasConstructStructReflect(2, 3, \"TEST\")\r\n\tASSERT_EQ(struct_1.x, 2)\r\n\tASSERT_EQ(struct_1.y, 3)\r\n\tASSERT_EQ(struct_1.z, \"TEST\")\r\n\tlocal struct_2 = CS.HasConstructStructReflect(10, 1, \"heihei\")\r\n\tlocal ret1, ret2 = class_a:Sub(struct_1, struct_2)\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(ret1.x, 2)\r\n\tASSERT_EQ(ret1.y, 1)\r\n\tASSERT_EQ(ret1.z, \"heihei\")\r\n\tASSERT_EQ(ret2.x, -8)\r\n\tASSERT_EQ(ret2.y, 3)\r\n\tASSERT_EQ(ret2.z, \"TEST\")\r\n\t\r\n\t--24.A的实例调用C的输入，输出，输入输出为struct类型的方法\r\n\tlocal ret3, ret4 = class_a:Add(struct_1, struct_2)\r\n\tASSERT_EQ(struct_2.x, 2)\r\n\tASSERT_EQ(ret3.x, 2)\r\n\tASSERT_EQ(ret3.y, 1)\r\n\tASSERT_EQ(ret3.z, \"heihei\")\r\n\tASSERT_EQ(ret4.x, 4)\r\n\tASSERT_EQ(ret4.y, 3)\r\n\tASSERT_EQ(ret4.z, \"TEST\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitStructVaribleParam(self)\r\n    --可变函数参数为struct\r\n\tself.count = 1 + self.count\r\n\t\r\n\tlocal struct_1 = CS.HasConstructStructReflect(2, 3, \"TEST\")\r\n\tlocal struct_2 = CS.HasConstructStructReflect(10, 1, \"heihei\")\r\n\tlocal class_c = CS.CClassReflect(1, 2, \"haha\")\r\n\tlocal ret = class_c:VariableParamFunc(struct_1, struct_2)\r\n\tASSERT_EQ(ret, 12)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseEventStatic(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tgTestNumber = 1\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('+', EvtFunc11)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(1)\r\n\tASSERT_EQ(2, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('+', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(2)\r\n\tASSERT_EQ(7, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('+', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(1)\r\n\tASSERT_EQ(12, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(1)\r\n\tASSERT_EQ(15, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(1)\r\n\tASSERT_EQ(16, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('-', EvtFunc12)\r\n\tlocal ret = CS.LuaTestObjReflect.CallStaticEvent(1)\r\n\tASSERT_EQ(17, ret)\r\n\tCS.LuaTestObjReflect.TestStaticEvent1('-', EvtFunc11)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseUpLowerMethod(self)\r\n\tself.count = 1 + self.count\r\n\tCS.LuaTestObjReflect.initNumber = 5\r\n\tlocal ret = CS.LuaTestObjReflect.CalcAdd(1)\r\n\tASSERT_EQ(6, ret)\r\n\t\r\n\tlocal ret = CS.LuaTestObjReflect.calcadd(2)\r\n\tASSERT_EQ(8, ret)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseUpLowerMethod(self)\r\n\tself.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObjReflect.OverLoad1(1, 2, 3, 5)\r\n\tASSERT_EQ(11, ret)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetStaticSum(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObj.Sum(1, 2)\r\n\tASSERT_EQ(ret, 3)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseGetSum(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObj()\r\n\tlocal ret = class:Sum(1, 2, 6)\r\n\tASSERT_EQ(ret, 9)\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitTemplateMethod(self)\r\n    self.count = 1 + self.count\r\n\tASSERT_EQ(CS.EmployeeTemplateReflect.GetBasicSalary, nil)\r\n\tASSERT_EQ(CS.EmployeeTemplateReflect.AddBonus, nil)\r\n\tlocal class = CS.ManagerReflect()\r\n\tASSERT_EQ(1, class:GetBasicSalary())\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitGenericMethod(self)\r\n\tself.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObjReflect()\r\n\tlocal a = \"abc\"\r\n\tif (true) then\r\n\t\tlocal ret, error = pcall(function() class:GenericMethod(a) end)\r\n\t\tASSERT_EQ(ret, false)\r\n    else\r\n        ASSERT_EQ(true, false)\r\n\tend\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitIntPtr(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObjReflect()\r\n\tlocal ptr = class.ptr\r\n\tprint(ptr)\r\n\tlocal ptr1 = class:GetPtr()\r\n    print(ptr1)\r\n    local bytevar = class:PrintPtr(ptr1)\r\n\tASSERT_EQ(bytevar, 97)\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitVarAndDefaultFunc1(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObjReflect()\r\n\r\n\tlocal ret = class:VariableParamFuncDefault(1)\r\n\tASSERT_EQ(ret, 2)\r\n\t\r\n\tlocal ret = CS.LuaTestObjReflect.StaticVariableParamFuncDefault(1.0)\r\n    ASSERT_EQ(ret, 2.0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVisitVarAndDefaultFunc2(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.LuaTestObjReflect()\r\n\r\n\tlocal ret = class:VariableParamFuncDefault(1, 2, \"john\", \"che\")\r\n\tASSERT_EQ(ret, 3)\r\n\t\r\n\tlocal ret = CS.LuaTestObjReflect.StaticVariableParamFuncDefault(1.0, 2.0, \"john\", \"che\")\r\n\tASSERT_EQ(ret, 3.0)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseFuncReturnByteArray(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObjReflect.FuncReturnByteArray()\r\n\tASSERT_EQ(ret, \"abc\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseFuncReturnByte(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObjReflect.FuncReturnByte()\r\n\tASSERT_EQ(ret, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseFuncReturnIntArray(self)\r\n    self.count = 1 + self.count\r\n\r\n\tlocal ret = CS.LuaTestObjReflect.FuncReturnIntArray()\r\n\tASSERT_EQ(type(ret), \"userdata\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseFuncReturnInt(self)\r\n    self.count = 1 + self.count\r\n\t\r\n\tlocal ret = CS.LuaTestObjReflect.FuncReturnInt()\r\n\tASSERT_EQ(ret, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransSimpleClassMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:SimpleClassMethod({x=97, y=\"123\", z=100000000000})\r\n\tASSERT_EQ(ret.x, 97)\r\n\tASSERT_EQ(ret.y, \"123\")\r\n\tASSERT_EQ(tostring(ret.z), \"100000000000\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransComplexClassMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:ComplexClassMethod({A=97, B={x=97, y=\"123\", z=100000000000}})\r\n\tASSERT_EQ(ret.IntVar, 97)\r\n\tASSERT_EQ(ret.ClassVar.IntVar, 97)\r\n\tASSERT_EQ(ret.ClassVar.StringVar, \"123\")\r\n\tASSERT_EQ(tostring(ret.ClassVar.LongVar), \"100000000000\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransSimpleStructMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:SimpleStructMethod({a=97})\r\n\tASSERT_EQ(ret.a, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransComplexStructMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:ComplexStructMethod({a=-101, b=1000, c=1.000000132, d={a=97}})\r\n\tASSERT_EQ(ret.a, -101)\r\n\tASSERT_EQ(ret.b, 1000)\r\n\tASSERT_EQ(string.sub(tostring(ret.c), 1, 11), \"1.000000132\")\r\n\tASSERT_EQ(ret.d.a, 97)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransOneListMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:OneListMethod({1, 2, 3, 4, 5})\r\n\tASSERT_EQ(ret, 15)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTableAutoTransTwoDimensionListMethod(self)\r\n    self.count = 1 + self.count\r\n\tlocal class = CS.TestTableAutoTransClassReflect()\r\n\tlocal ret = class:TwoDimensionListMethod({{1, 2, 3},{4, 5, 6}})\r\n\tASSERT_EQ(ret, 21)\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseTestImplicit(self)\r\n\tself.count = 1 + self.count\r\n    if CS.LuaTestCommon.IsXLuaGeneral() then return end\r\n\tlocal ret = CS.LuaTestObjReflect.TestImplicit():GetType()\r\n\tASSERT_EQ(ret, typeof(CS.UnityEngine.LayerMask))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVariableParamFunc2_1_4(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret, err = pcall(function() CS.LuaTestObjReflect.VariableParamFunc(0, CS.LuaTestObjReflect()) end)\r\n\tASSERT_EQ(ret, false)\r\n\tASSERT_TRUE(err:find(\"invalid arguments\"))\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseFirstPushEnum(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.FirstPushEnumFunc(1)\r\n\tASSERT_EQ(ret, \"1\")\r\n\tlocal ret = CS.LuaTestObjReflect.FirstPushEnumFunc(2)\r\n\tASSERT_EQ(ret, \"4\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseReferTestClass(self)\r\n\tself.count = 1 + self.count\r\n\tlocal int_x = 10\r\n\tlocal int_y = 12\r\n\tlocal str_z = \"abc\"\r\n\tlocal class1, ret_y, ret_z = CS.ReferTestClassReflect(int_x, int_y)\r\n\tlocal ret = class1:Get_X_Y_ADD()\r\n\tASSERT_EQ(ret, 22)\r\n\tASSERT_EQ(ret_y, 11)\r\n\tASSERT_EQ(ret_z, \"test1\")\r\n\t\r\n\tlocal class3, ret_z = CS.ReferTestClassReflect(int_x)\r\n\tlocal ret = class3:Get_X_Y_ADD()\r\n\tASSERT_EQ(ret, 20)\r\n\tASSERT_EQ(ret_z, \"test3\")\r\nend\r\n\r\nfunction CMyTestCaseLuaCallCSReflect.CaseVariableParamFuncNoParam(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret = CS.LuaTestObjReflect.VariableParamFunc2()\r\n\tASSERT_EQ(ret, 0)\r\n\tlocal ret = CS.LuaTestObjReflect.VariableParamFunc2(\"abc\", \"haha\")\r\n\tASSERT_EQ(ret, 2)\r\nend"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaCallCsReflect.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 3def27a586fdac545a71c421a4593354\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaTdrTest.lua",
    "content": "require(\"ltest.init\")\r\nrequire \"libtdrlua\"\r\n\r\npkg_table = {\r\n    head = {\r\n        magic = 0x7FFF,\r\n        msgid = 10000001,\r\n        cmd = 1,\r\n        version = 0,\r\n        bodyLen = 0,\r\n        datetime = libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"),\r\n        srcIp = libtdrlua.str2tdrip(\"127.0.0.1\"),\r\n    },\r\n    \r\n    body = {\r\n        login = {\r\n            name = \"FrancisHe\",\r\n            pass = \"123456\",\r\n            zone = \"Japan\",\r\n            destIp = libtdrlua.str2tdrip(\"127.0.0.1\"),\r\n        },\r\n        logout = {\r\n            reason = -1,\r\n            count = 2,\r\n            attr = {-1, 0, 1},\r\n        },\r\n        xxx = {\r\n            typeTester = {\r\n                date = libtdrlua.str2tdrdate(\"2015-09-08\"),\r\n                time = libtdrlua.str2tdrtime(\"22:17:59\"),\r\n                \r\n                int8 = -1,\r\n                uint8Array = {0, 23, 255},\r\n                int8VarArrayRefer = 2,\r\n                int8VarArray = {-128, 127 ,0},\r\n                \r\n                int = -6, -- -6.6\r\n                uintArray = {0, 1721, 0xFFFFFFFF},\r\n                intVarArrayRefer = 1, -- 0\r\n                intVarArray = {-0x80000000, 0x7FFFFFFF, 0},\r\n                \r\n                strArray = {\"Francis\", \"Francis\"},\r\n                \r\n                uint64 = 0xFFFFFFFFFFFFF, -- 1(s) + 11(e) + 52(m)\r\n                int64Array = {-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},\r\n                \r\n                float = 0xFFFFFFFF,\r\n                floatArray = {-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}, -- 3.40282347e+38\r\n                \r\n                double = 2.2250738585072014e-308,\r\n                doubleArray = {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308},\r\n            },\r\n            boundary = -1.1,\r\n            selector = 1,\r\n            innerUnion = {\r\n                field1 = {\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0,\r\n                    }\r\n                }\r\n            },\r\n            structArray = {\r\n                count = 1, -- 0\r\n                array = {\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                }\r\n            },\r\n            boundary2 = 1.111111,\r\n        },\r\n        ext1 = -1,\r\n        ext2 = {0, 1, 2},\r\n        ext3 = {\"Francis\", \"Francis\"},\r\n        ext4 = \"Francis\",\r\n    }\r\n}\r\n\r\npkg_table_v4 = {\r\n    head = {\r\n        magic = 0x7FFF,\r\n        msgid = 10000001,\r\n        cmd = 1,\r\n        version = 0,\r\n        bodyLen = 0,\r\n        datetime = libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"),\r\n        srcIp = libtdrlua.str2tdrip(\"127.0.0.1\"),\r\n\t\tdestIp = libtdrlua.str2tdrip(\"127.0.0.2\"),\r\n    },\r\n    \r\n    body = {\r\n        login = {\r\n            name = \"FrancisHe\",\r\n            pass = \"123456\",\r\n            zone = \"Japan\",\r\n            destIp = libtdrlua.str2tdrip(\"127.0.0.1\"),\r\n        },\r\n        logout = {\r\n            reason = -1,\r\n            count = 2,\r\n            attr = {-1, 0, 1},\r\n        },\r\n        xxx = {\r\n            typeTester = {\r\n                date = libtdrlua.str2tdrdate(\"2015-09-08\"),\r\n                time = libtdrlua.str2tdrtime(\"22:17:59\"),\r\n                \r\n                int8 = -1,\r\n                uint8Array = {0, 23, 255},\r\n                int8VarArrayRefer = 2,\r\n                int8VarArray = {-128, 127 ,0},\r\n                \r\n                int = -6, -- -6.6\r\n                uintArray = {0, 1721, 0xFFFFFFFF},\r\n                intVarArrayRefer = 1, -- 0\r\n                intVarArray = {-0x80000000, 0x7FFFFFFF, 0},\r\n                \r\n                strArray = {\"Francis\", \"Francis\"},\r\n                \r\n                uint64 = 0xFFFFFFFFFFFFF, -- 1(s) + 11(e) + 52(m)\r\n                int64Array = {-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},\r\n                \r\n                float = 0xFFFFFFFF,\r\n                floatArray = {-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}, -- 3.40282347e+38\r\n                \r\n                double = 2.2250738585072014e-308,\r\n                doubleArray = {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308},\r\n            },\r\n            boundary = -1.1,\r\n            selector = 1,\r\n            innerUnion = {\r\n                field1 = {\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0,\r\n                    }\r\n                }\r\n            },\r\n            structArray = {\r\n                count = 1, -- 0\r\n                array = {\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                    {\r\n                        uint64 = 0x0FFFFFFFFFFFFFFF,\r\n                        uint = 0xFFFFFFFF,\r\n                    },\r\n                }\r\n            },\r\n            boundary2 = 1.111111,\r\n        },\r\n        ext1 = -1,\r\n        ext2 = {0, 1, 2},\r\n        ext3 = {\"Francis\", \"Francis\"},\r\n        ext4 = \"Francis\",\r\n    }\r\n}\r\n\r\nfunction copyTab(st)\r\n    local tab = {}\r\n    for k, v in pairs(st or {}) do\r\n        if type(v) ~= \"table\" then\r\n            tab[k] = v\r\n        else\r\n            tab[k] = copyTab(v)\r\n        end\r\n    end\r\n    return tab\r\nend\r\n\r\nlocal function table_to_string(t)\r\n  local ret = ''\r\n  local ltype = type(t)\r\n  if (ltype == 'table') then\r\n    ret = ret .. '{ '\r\n    for key,value in pairs(t) do\r\n      ret = ret .. tostring(key) .. '=' .. table_to_string(value) .. ' '\r\n    end\r\n    ret = ret .. '}'\r\n  elseif ltype == 'string' then\r\n    ret = ret .. \"'\" .. tostring(t) .. \"'\"\r\n  else\r\n    ret = ret .. tostring(t)\r\n  end\r\n  return ret\r\nend\r\n\r\n-- for test case\r\nCMyTestCaseLuaTdr = TestCase:new()\r\nfunction CMyTestCaseLuaTdr:new(oo)\r\n    local o = oo or {}\r\n    o.count = 1\r\n    \r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.SetUpTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaTdr.SetUpTestCase\")\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.TearDownTestCase(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaTdr.TearDownTestCase\")\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaTdr.SetUp(self)\r\n    self.count = 1 + self.count\r\n\tprint(\"CMyTestCaseLuaTdr.SetUp\")\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.TearDown(self)\r\n    self.count = 1 + self.count\r\n\r\n\tprint(\"CMyTestCaseLuaTdr.TearDown\")\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.LoadMetalib(self, load_type, file_path, cmd)\r\n    --加载meta元数据库\t\r\n\tlocal ret_code, metalib\r\n\tif load_type == 0 then\r\n\t    ret_code, metalib = libtdrlua.load_metalib(file_path)\r\n\t\tif ret_code ~= 0 then\r\n\t\t\tprint(\"libtdrlua.load_metalib() failed: \" .. metalib)\r\n\t\tend\r\n\tend\r\n\t\r\n\tif load_type == 1 then\r\n\t\tlocal tdrmeta = CS.UnityEngine.Resources.Load(file_path).bytes\r\n\t\tret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\t\tif ret_code ~= 0 then\r\n\t\t\tprint(\"libtdrlua.load_metalib_buf() failed: \" .. metalib)\r\n\t\tend\r\n    end\r\n\t\r\n\tASSERT_EQ(ret_code, 0)\r\n    print(\"libtdrlua.load_metalib ok\")\r\n\t\r\n\t--获取最大meta buff size\t\r\n\tlocal ret_code, buf_size = libtdrlua.metamaxbufsize(metalib, \"Pkg\")\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.metamaxbufsize() failed: \" .. buf_size)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.metamaxbufsize() ok: buf_size = \" .. buf_size)\r\n\t\r\n\t--分配buff\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.bufalloc() failed: \" .. buf)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.bufalloc() ok\")\r\n\tprint( \"pkg = \" .. table_to_string(pkg_table))\r\n\t\r\n\t------------------------------------------------------------------------\r\n\t-- API - get_meta\r\n\t-- return value - ret_code, meta/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.get_meta() failed: \" .. meta)\r\n    end\r\n\tASSERT_EQ(ret_code, 0)\r\n    print(\"libtdrlua.get_meta() ok\")\r\n\t\r\n\tpkg_table.head.cmd = cmd\r\n\t----------------------------------------------------------------------\r\n\t-- API - table2buf\r\n\t-- return value - ret_code, used_size/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.table2buf() failed: \" .. used_size)\r\n\t\tlibtdrlua.buffree(buf)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.table2buf() ok, used_size = \" .. used_size)\r\n    \r\n\t\r\n\t----------------------------------------------------------------------\r\n\t-- API - buf2str\r\n\t-- return value - ret_code, str/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, str = libtdrlua.buf2str(buf, used_size)\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.buf2str() failed: \" .. str)\r\n\t\tlibtdrlua.buffree(buf)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.buf2str() ok\")\r\n\tprint(\"buf2str:\" .. str)\r\n\t\r\n\t----------------------------------------------------------------------\r\n\t-- API - buf2table\r\n\t-- return value - ret_code, pkg_table, used_size/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size, 0)\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.buf2table() failed: \" .. used_size2)\r\n\t\tprint(DataDumper(pkg_table2, \"pkg2 = \"))\r\n\t\tlibtdrlua.buffree(buf)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.buf2table() ok, used_size = \" .. used_size2)\r\n\tprint(\"unpakc pkg = \", table_to_string(pkg_table2))\r\n\t\r\n\t--print(DataDumper(pkg_table2, \"pkg2 = \"))\r\n    --因为str为空，所以会引起Unity crash\r\n\t----------------------------------------------------------------------\r\n\t-- API - str2table\r\n\t-- return value - ret_code, pkg_table, used_size/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, pkg_table3, used_size3 = libtdrlua.str2table(meta, str, 0)\r\n\tif ret_code ~= 0 then\r\n\t\tprint(\"libtdrlua.str2table() failed: \" .. used_size3)\r\n\t\tprint(DataDumper(pkg_table3, \"pkg3 = \"))\r\n\t\tlibtdrlua.buffree(buf)\r\n\tend\r\n\tASSERT_EQ(ret_code, 0)\r\n\tprint(\"libtdrlua.str2table() ok, used_size = \" .. used_size3)\r\n\tprint(\"str2buf unpack pkg = \", table_to_string(pkg_table2))\r\n\t\r\n\t----------------------------------------------------------------------\r\n\t-- API - buffree\r\n\t-- return value - nil/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tif err_msg ~= nil then\r\n\t\tprint(\"libtdrlua.buffree() failed: \" .. err_msg)\r\n\tend\r\n\tprint(\"libtdrlua.buffree() ok\")\r\n\tASSERT_EQ(err_msg, nil)\r\n\r\n\t----------------------------------------------------------------------\r\n\t-- API - free_metalib\r\n\t-- return value - nil/err_msg\r\n\t-- Note: metalib will be automatically released by lua gc. Thus, this\r\n\t--   step is optional.\r\n\t----------------------------------------------------------------------\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tif err_msg ~= nil then\r\n\t\tprint(\"libtdrlua.free_metalib() failed: \" .. err_msg)\r\n\tend\r\n\tprint(\"libtdrlua.free_metalib() ok\")\r\n\tASSERT_EQ(err_msg, nil)\r\n\treturn pkg_table2, pkg_table3\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_1(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 1)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\t--ASSERT_EQ(tostring(pkg_table2.head.bodyLen),\"39\")\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 39)\r\n\t--ASSERT_EQ(tostring(pkg_table3.head.bodyLen),\"39\")\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table3.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table3.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table3.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table3.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.ext1, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_1(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(1, \"testxxx.tdr\", 1)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table3.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table3.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table3.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table3.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.ext1, nil)\r\nend\t\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_2(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 2)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 16)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table2.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.logout.count, 2)\r\n\tASSERT_EQ(pkg_table2.body.logout.attr, {-1, 0})\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 16)\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table3.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.login, nil)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table3.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table3.body.logout.count, 2)\r\n\tASSERT_EQ(pkg_table3.body.logout.attr, {-1, 0})\r\n\tASSERT_EQ(pkg_table3.body.ext1, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_2(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(1, \"testxxx.tdr\", 2)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 16)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tlocal ret = -1\r\n\tASSERT_EQ(ret, -1)\r\n\tASSERT_EQ(tostring(pkg_table2.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.logout.count, 2)\r\n\tASSERT_EQ(pkg_table2.body.logout.attr, {-1, 0})\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 16)\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table3.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table3.body.login, nil)\r\n\tlocal ret = -1\r\n\tASSERT_EQ(ret, -1)\r\n\tASSERT_EQ(tostring(pkg_table3.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table3.body.logout.count, 2)\r\n\tASSERT_EQ(pkg_table3.body.logout.attr, {-1, 0})\r\n\tASSERT_EQ(pkg_table3.body.ext1, nil)\r\nend\t\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_3(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 3)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 3)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 222)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(libtdrlua.tdrip2str(pkg_table2.head.srcIp), \"127.0.0.1\")\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.logout, nil)\r\n\tASSERT_EQ(libtdrlua.tdrdate2str(pkg_table2.body.xxx.typeTester.date), \"2015-09-08\")\r\n\tASSERT_EQ(libtdrlua.tdrtime2str(pkg_table2.body.xxx.typeTester.time), \" 22:17:59\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.time, libtdrlua.str2tdrtime(\"22:17:59\"))\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8, -1)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.uint8Array, {0, 23, 255})\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8VarArrayRefer, 2)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8VarArray, {-128, 127})\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.uintArray, {0, 1721, 0xFFFFFFFF}) --测试不过，0xFFFFFFFF解包后变长了0x80000000\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.intVarArray, {-0x80000000})\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.strArray, {\"Francis\", \"Francis\"})\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.uint64), \"4503599627370495\") --0xFFFFFFFFFFFFF\r\n\t\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.int64Array, {-9223372036854775808, 4503599627370495, 9223372036854775807}) --{-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},，测试不过，解包后0x7FFFFFFFFFFFFFFF变长了-9223372036854775808\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.int64Array[3], 0x7FFFFFFFFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.float, 0xFFFFFFFF) --此处验证不过，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.float, 0xFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t---会存在精度问题，实际为{-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[1]), \"-3.4028234663853e+38\")\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[2]), \"1.1754943508223e-38\")\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[3]), \"3.4028234663853e+38\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.double, 2.2250738585072014e-308)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.doubleArray, {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308})\r\n\tASSERT_EQ(string.sub(tostring(pkg_table2.body.xxx.boundary),1, 4), \"-1.1\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.selector, 1)\r\n\tprint(\"to_string filed1:\" .. table_to_string(pkg_table2.body.xxx.innerUnion.field1[1]))\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[1], {unit64 = 0x0FFFFFFFFFFFFFFF, uint = 0xFFFFFFFF})\r\n\t\r\n\tASSERT_EQ(type(pkg_table.body.xxx.innerUnion.field1[1]), 'table')\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint, 0)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.innerUnion.field1[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.innerUnion.field1[2].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[2].uint, 0)\r\n\tASSERT_EQ(pkg_table2.body.xxx.structArray.count, 1)\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.structArray.array[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n    --ASSERT_EQ(pkg_table2.body.xxx.structArray.array[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table2.body.xxx.structArray.array[2], nil)\r\n\tASSERT_EQ(string.sub(tostring(pkg_table2.body.xxx.boundary2),1, 8), \"1.111111\")\t\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 3)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 222)\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(libtdrlua.tdrip2str(pkg_table3.head.srcIp), \"127.0.0.1\")\r\n\tASSERT_EQ(pkg_table3.body.login, nil)\r\n\tASSERT_EQ(pkg_table3.body.logout, nil)\r\n\tASSERT_EQ(libtdrlua.tdrdate2str(pkg_table3.body.xxx.typeTester.date), \"2015-09-08\")\r\n\tASSERT_EQ(libtdrlua.tdrtime2str(pkg_table3.body.xxx.typeTester.time), \" 22:17:59\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.time, libtdrlua.str2tdrtime(\"22:17:59\"))\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8, -1)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.uint8Array, {0, 23, 255})\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8VarArrayRefer, 2)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8VarArray, {-128, 127})\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.uintArray, {0, 1721, 0xFFFFFFFF}) --测试不过，0xFFFFFFFF解包后变长了0x80000000\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.intVarArray, {-0x80000000})\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.strArray, {\"Francis\", \"Francis\"})\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.uint64), \"4503599627370495\") --0xFFFFFFFFFFFFF\r\n\t\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.int64Array, {-9223372036854775808, 4503599627370495, 9223372036854775807}) --{-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},，测试不过，解包后0x7FFFFFFFFFFFFFFF变长了-9223372036854775808\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.int64Array[3], 0x7FFFFFFFFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.float, 0xFFFFFFFF) --此处验证不过，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.float, 0xFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t---会存在精度问题，实际为{-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[1]), \"-3.4028234663853e+38\")\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[2]), \"1.1754943508223e-38\")\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[3]), \"3.4028234663853e+38\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.double, 2.2250738585072014e-308)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.doubleArray, {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308})\r\n\tASSERT_EQ(string.sub(tostring(pkg_table3.body.xxx.boundary),1, 4), \"-1.1\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.selector, 1)\r\n\tprint(\"to_string filed1:\" .. table_to_string(pkg_table3.body.xxx.innerUnion.field1[1]))\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[1], {unit64 = 0x0FFFFFFFFFFFFFFF, uint = 0xFFFFFFFF})\r\n\t\r\n\tASSERT_EQ(type(pkg_table.body.xxx.innerUnion.field1[1]), 'table')\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint, 0)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.innerUnion.field1[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.innerUnion.field1[2].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[2].uint, 0)\r\n\tASSERT_EQ(pkg_table3.body.xxx.structArray.count, 1)\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.structArray.array[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n    --ASSERT_EQ(pkg_table3.body.xxx.structArray.array[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table3.body.xxx.structArray.array[2], nil)\r\n\tASSERT_EQ(string.sub(tostring(pkg_table3.body.xxx.boundary2),1, 8), \"1.111111\")\t\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_3(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2, pkg_table3 = self:LoadMetalib(1, \"testxxx.tdr\", 3)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 3)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 222)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.logout, nil)\r\n\tASSERT_EQ(libtdrlua.tdrdate2str(pkg_table2.body.xxx.typeTester.date), \"2015-09-08\")\r\n\tASSERT_EQ(libtdrlua.tdrtime2str(pkg_table2.body.xxx.typeTester.time), \" 22:17:59\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.time, libtdrlua.str2tdrtime(\"22:17:59\"))\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8, -1)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.uint8Array, {0, 23, 255})\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8VarArrayRefer, 2)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.int8VarArray, {-128, 127})\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.uintArray, {0, 1721, 0xFFFFFFFF})\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.uintArray, {0, 1721, 0xFFFFFFFF}) --测试不过，0xFFFFFFFF解包后变长了0x80000000\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.intVarArray, {-0x80000000})\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.strArray, {\"Francis\", \"Francis\"})\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.uint64), \"4503599627370495\") --0xFFFFFFFFFFFFF\r\n\t\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.int64Array, {-9223372036854775808, 4503599627370495, 9223372036854775807}) --{-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},，测试不过，解包后0x7FFFFFFFFFFFFFFF变长了-9223372036854775808\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.int64Array[3], 0x7FFFFFFFFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.typeTester.float, 0xFFFFFFFF) --此处验证不过，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.float, 0xFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t---会存在精度问题，实际为{-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[1]), \"-3.4028234663853e+38\")\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[2]), \"1.1754943508223e-38\")\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.typeTester.floatArray[3]), \"3.4028234663853e+38\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.double, 2.2250738585072014e-308)\r\n\tASSERT_EQ(pkg_table2.body.xxx.typeTester.doubleArray, {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308})\r\n\tASSERT_EQ(string.sub(tostring(pkg_table2.body.xxx.boundary),1, 4), \"-1.1\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.selector, 1)\r\n\tprint(\"to_string filed1:\" .. table_to_string(pkg_table2.body.xxx.innerUnion.field1[1]))\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[1], {unit64 = 0x0FFFFFFFFFFFFFFF, uint = 0xFFFFFFFF})\r\n\t\r\n\tASSERT_EQ(type(pkg_table.body.xxx.innerUnion.field1[1]), 'table')\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint, 0)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.innerUnion.field1[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\t--ASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.innerUnion.field1[2].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.xxx.innerUnion.field1[2].uint, 0)\r\n\tASSERT_EQ(pkg_table2.body.xxx.structArray.count, 1)\r\n\tASSERT_EQ(tostring(pkg_table2.body.xxx.structArray.array[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n    --ASSERT_EQ(pkg_table2.body.xxx.structArray.array[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table2.body.xxx.structArray.array[2], nil)\r\n\tASSERT_EQ(string.sub(tostring(pkg_table2.body.xxx.boundary2),1, 8), \"1.111111\")\r\n\t\r\n\tASSERT_EQ(pkg_table3.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table3.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table3.head.cmd, 3)\r\n\tASSERT_EQ(pkg_table3.head.version, 3)\r\n\tASSERT_EQ(pkg_table3.head.bodyLen, 222)\r\n\tASSERT_EQ(pkg_table3.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(libtdrlua.tdrip2str(pkg_table3.head.srcIp), \"127.0.0.1\")\r\n\tASSERT_EQ(pkg_table3.body.login, nil)\r\n\tASSERT_EQ(pkg_table3.body.logout, nil)\r\n\tASSERT_EQ(libtdrlua.tdrdate2str(pkg_table3.body.xxx.typeTester.date), \"2015-09-08\")\r\n\tASSERT_EQ(libtdrlua.tdrtime2str(pkg_table3.body.xxx.typeTester.time), \" 22:17:59\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.time, libtdrlua.str2tdrtime(\"22:17:59\"))\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8, -1)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.uint8Array, {0, 23, 255})\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8VarArrayRefer, 2)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.int8VarArray, {-128, 127})\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.uintArray, {0, 1721, 0xFFFFFFFF}) --测试不过，0xFFFFFFFF解包后变长了0x80000000\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.intVarArray, {-0x80000000})\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.strArray, {\"Francis\", \"Francis\"})\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.uint64), \"4503599627370495\") --0xFFFFFFFFFFFFF\r\n\t\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.int64Array, {-9223372036854775808, 4503599627370495, 9223372036854775807}) --{-0x8000000000000000, 0xFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF},，测试不过，解包后0x7FFFFFFFFFFFFFFF变长了-9223372036854775808\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.int64Array[3], 0x7FFFFFFFFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.typeTester.float, 0xFFFFFFFF) --此处验证不过，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table.body.xxx.typeTester.float, 0xFFFFFFFF)--此处验证打包前是ok的\r\n\t\r\n\t---会存在精度问题，实际为{-3.40282346e+38, 1.17549435e-38, 3.40282346e+38}\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[1]), \"-3.4028234663853e+38\")\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[2]), \"1.1754943508223e-38\")\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.typeTester.floatArray[3]), \"3.4028234663853e+38\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.double, 2.2250738585072014e-308)\r\n\tASSERT_EQ(pkg_table3.body.xxx.typeTester.doubleArray, {-1.7976931348623157e+308, -2.2250738585072014e-308, 1.7976931348623157e+308})\r\n\tASSERT_EQ(string.sub(tostring(pkg_table3.body.xxx.boundary),1, 4), \"-1.1\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.selector, 1)\r\n\tprint(\"to_string filed1:\" .. table_to_string(pkg_table3.body.xxx.innerUnion.field1[1]))\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[1], {unit64 = 0x0FFFFFFFFFFFFFFF, uint = 0xFFFFFFFF})\r\n\t\r\n\tASSERT_EQ(type(pkg_table.body.xxx.innerUnion.field1[1]), 'table')\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint64, 0x0FFFFFFFFFFFFFFF)\r\n\tASSERT_EQ(pkg_table.body.xxx.innerUnion.field1[2].uint, 0)\r\n\t\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.innerUnion.field1[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\t--ASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.innerUnion.field1[2].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n\tASSERT_EQ(pkg_table3.body.xxx.innerUnion.field1[2].uint, 0)\r\n\tASSERT_EQ(pkg_table3.body.xxx.structArray.count, 1)\r\n\tASSERT_EQ(tostring(pkg_table3.body.xxx.structArray.array[1].uint64 - 0x0FFFFFFFFFFFFFFF), \"0\")\r\n    --ASSERT_EQ(pkg_table3.body.xxx.structArray.array[1].uint, 0xFFFFFFFF) --这个值解包后有问题，ASSERT_EQ failed --> left:4294967296, right:4294967295.\r\n\tASSERT_EQ(pkg_table3.body.xxx.structArray.array[2], nil)\r\n\tASSERT_EQ(string.sub(tostring(pkg_table3.body.xxx.boundary2),1, 8), \"1.111111\")\t\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_4(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 4)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 4)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 4)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext1, -1)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_4(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2 = self:LoadMetalib(1, \"testxxx.tdr\", 5)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 5)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 4)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext1, -1)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_5(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 70)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 70)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 3)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext2, {0, 1, 2})\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_5(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2 = self:LoadMetalib(1, \"testxxx.tdr\", 80)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 80)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 3)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext2, {0, 1, 2})\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_6(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 75)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 75)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 3)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext2, {0, 1, 2})\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_6(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2 = self:LoadMetalib(1, \"testxxx.tdr\", 81)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 81)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 4)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext1, -1)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalib_7(self)\r\n    self.count = 1 + self.count\r\n\tif CS.LuaTestCommon.android_platform == true then\r\n\t    return\r\n\tend\r\n\tpkg_table2 = self:LoadMetalib(0, CS.LuaTestCommon.xxxtdrfilepath, 15)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 15)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 24)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext3, {\"Francis\", \"Francis\"})\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBuff_7(self)\r\n    self.count = 1 + self.count\r\n\tpkg_table2 = self:LoadMetalib(1, \"testxxx.tdr\", 100)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 100)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 12)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tASSERT_EQ(pkg_table2.body.ext4, \"Francis\")\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibNoExistTdr(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret_code, err_msg = libtdrlua.load_metalib(\"noexist.tdr\")\r\n\tASSERT_EQ(ret_code, -2113862584)\r\n    print(\"CaseLoadMetalibNoExistTdr err_msg:\" .. err_msg)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibErrorTdrFile(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret_code, err_msg = libtdrlua.load_metalib(\"test2.lua\")\r\n\tASSERT_EQ(ret_code, -2113862584)\r\n\tprint(\"CaseLoadMetalibErrorTdrFile err_msg:\" .. err_msg)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibMultiTimes(self)\r\n    self.count = 1 + self.count\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tlocal ret_code2, metalib2 = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(ret_code2, 0)\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg2 = libtdrlua.free_metalib(metalib2)\r\n\tASSERT_EQ(err_msg2, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibDiffTdrFile(self)\r\n    self.count = 1 + self.count\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal tdrmeta2 = CS.UnityEngine.Resources.Load(\"testxxx2.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tlocal ret_code2, metalib2 = libtdrlua.load_metalib_buf(tdrmeta2)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(ret_code2, 0)\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg2 = libtdrlua.free_metalib(metalib2)\r\n\tASSERT_EQ(err_msg2, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBufFromEmptyStr(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(\"\")\r\n\tASSERT_EQ(ret_code, -2113862536)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseLoadMetalibBufFromNoTdrStr(self)\r\n    self.count = 1 + self.count\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(\"testtdr\")\r\n\tASSERT_EQ(ret_code, -2113862536)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseGetMeta(self)\r\n    --加载meta元数据库\t\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n    print(\"libtdrlua.load_metalib ok\")\r\n\t\r\n\t------------------------------------------------------------------------\r\n\t-- API - get_meta\r\n\t-- return value - ret_code, meta/err_msg\r\n\t----------------------------------------------------------------------\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"PkgBody\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"PkgNoExist\")\r\n\tASSERT_EQ(ret_code, -1)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"PKG_ID\")\r\n\tASSERT_EQ(ret_code, -1)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseTable2Buf_1(self)\r\n    --长度等于实际长度\t\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\r\n\tbuf_size = 71\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(used_size, buf_size)\r\n\t\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size, 0)\r\n\tprint(\"table2buf pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseTable2Buf_2(self)\r\n    --buf 和 len 小于pkg_table实际长度\t\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\r\n\tbuf_size = 56\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, -2113862654)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseTable2Buf_3(self)\t\r\n\t--4.不设置version参数打包\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal buf_size = 71\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(used_size, buf_size)\r\n\t\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size)\r\n\tprint(\"table2buf pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseTable2Buf_4(self)\t\r\n\t--5.version参数值小于等于meta中设置的version\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal buf_size = 71\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\t--Struct Pkg有设置versionindicator=\"head.version\"，因此会按照打包时的version解包，buf2table输入的version不会生效\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 2)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size, 3)\r\n\tprint(\"table2buf pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 2)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, 0) --srcIp的version为3\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"PkgHead\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table.head, buf, buf_size, 3)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size, 2)\r\n\tprint(\"table2buf pkghead pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.version, 2)\r\n\tASSERT_EQ(pkg_table2.bodyLen, 0)\r\n\tASSERT_EQ(pkg_table2.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.srcIp, 0) --srcIp的version为3\r\n\t\r\n\t--6.version参数值大于meta中设置的version\r\n\tlocal ret_code, pkg_table3, used_size2 = libtdrlua.buf2table(meta, buf, used_size, 4)\r\n\tprint(\"table2buf pkghead pkg_table3: \" .. table_to_string(pkg_table3))\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table.head, buf, buf_size, 4)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseBuf2Table_1(self)\r\n    --2.len 大于buf长度，version为0\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\r\n\tbuf_size = 128\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size + 10, 0)\r\n\tprint(\"table2buf pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\t--3.len小于message（buf）长度\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta, buf, used_size - 10, 0)\r\n\tASSERT_EQ(ret_code, -2113862654)\r\n\t\r\n\t--4.meta和buf中数据结构定义不一致\r\n\tlocal ret_code, meta_2 = libtdrlua.get_meta(metalib, \"PkgBodyPrevious\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, pkg_table2, used_size2 = libtdrlua.buf2table(meta_2, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, -2113862552)\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseStr2Buf(self)\t\r\n\t--1. str为空\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal buf_size = 71\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"PkgHead\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table.head, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, str = libtdrlua.buf2str(buf, used_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, err_msg = libtdrlua.str2table(meta, \"\", 3)\r\n\tASSERT_EQ(ret_code, -2113862552)\r\n\t\r\n\t--3.meta和str中数据结构定义不一致\r\n\tlocal ret_code, meta2 = libtdrlua.get_meta(metalib, \"PkgBody\")\r\n\tlocal ret_code, err_msg = libtdrlua.str2table(meta2, str, 0)\r\n\tASSERT_EQ(ret_code, -2113862552)\r\n\t\r\n    --4. version不设置\r\n\tlocal ret_code, pkg_table2 = libtdrlua.str2table(meta, str)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n    --5. version小于等于meta中version值\r\n\tlocal ret_code, pkg_table3 = libtdrlua.str2table(meta, str, 2)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n    --6. version大于meta中version值\r\n\tlocal ret_code, pkg_table4 = libtdrlua.str2table(meta, str, 2)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tprint(\"table2buf pkghead pkg_table2: \" .. table_to_string(pkg_table2))\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.version, 3)\r\n\tASSERT_EQ(pkg_table2.bodyLen, 0)\r\n\tASSERT_EQ(pkg_table2.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\t\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseZZZRefer_1(self)\r\n    --2 某数组refer的值大于数组count，调用table2buf函数\r\n    self.count = 1 + self.count\r\n\tpkg_table.body.logout.count = 4\r\n\tpkg_table.head.cmd = 2\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\r\n\tbuf_size = 128\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta = libtdrlua.get_meta(metalib, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, -2113862521)\r\n\t\r\n\t--3 某数组refer的值等于数组count，调用table2buf打包和buf2table解包\r\n\tpkg_table.body.logout.count = 3\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 17)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tlocal ret = -1\r\n\tASSERT_EQ(ret, -1)\r\n\tASSERT_EQ(tostring(pkg_table2.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.logout.count, 3)\r\n\tASSERT_EQ(pkg_table2.body.logout.attr, {-1, 0, 1})\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\t-- 4 某数组refer的值等于0，调用table2buf打包和buf2table解包\r\n\tpkg_table.body.logout.count = 0\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 2)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 14)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.login, nil)\r\n\tlocal ret = -1\r\n\tASSERT_EQ(ret, -1)\r\n\tASSERT_EQ(tostring(pkg_table2.body.logout.reason + 1), \"0\")\r\n\tASSERT_EQ(pkg_table2.body.logout.count, 0)\r\n\tASSERT_EQ(pkg_table2.body.logout.attr, {})\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\tpkg_table.body.logout.count = 2\r\n\tpkg_table.head.cmd = 1\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\nfunction CMyTestCaseLuaTdr.CaseZZZZVersion_1(self)\r\n\r\n    --4.高版本多2个字段，用高版本meta，打包时传入低版本version， 然后用低版本meta解包（version为0）\r\n\t\r\n    self.count = 1 + self.count\r\n\tpkg_table.head.cmd = 1\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib_v3 = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tlocal tdrmeta2 = CS.UnityEngine.Resources.Load(\"testxxx2.tdr\").bytes\r\n\tlocal ret_code, metalib_v4 = libtdrlua.load_metalib_buf(tdrmeta2)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tbuf_size = 128\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta_v3 = libtdrlua.get_meta(metalib_v3, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta_v4 = libtdrlua.get_meta(metalib_v4, \"Pkg\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta_v4, pkg_table_v4, buf, buf_size, 3)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta_v3, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.head.magic, 32767)\r\n\tASSERT_EQ(tostring(pkg_table2.head.msgid), \"10000001\")\r\n\tASSERT_EQ(pkg_table2.head.cmd, 1)\r\n\tASSERT_EQ(pkg_table2.head.version, 3)\r\n\tASSERT_EQ(pkg_table2.head.bodyLen, 39)\r\n\tASSERT_EQ(pkg_table2.head.datetime, libtdrlua.str2tdrdatetime(\"2015-09-08 21:17:59\"))\r\n\tASSERT_EQ(pkg_table2.head.srcIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.head.destIp, nil)\r\n\tASSERT_EQ(pkg_table2.body.login.name, \"FrancisHe\")\r\n\tASSERT_EQ(pkg_table2.body.login.pass, \"123456\")\r\n\tASSERT_EQ(pkg_table2.body.login.zone, \"Japan\")\r\n\tASSERT_EQ(pkg_table2.body.login.destIp, libtdrlua.str2tdrip(\"127.0.0.1\"))\r\n\tASSERT_EQ(pkg_table2.body.ext1, nil)\r\n\t\r\n\t--1.1 pack低版本（meta对应低版本），unpack高版本（meta对应高版本）\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta_v3, pkg_table, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta_v4, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\t--1.2 pack高版本，unpack低版本 \r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta_v4, pkg_table_v4, buf, buf_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta_v3, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, -2113862544)\r\n\t\r\n\tpkg_table.head.cmd = 1\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib_v3)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib_v4)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend\r\n\r\n\r\nfunction CMyTestCaseLuaTdr.CaseZZZZRandom(self)\r\n    --6.同一个结构类 entry 类型乱序排列，调用table2buf打包和buf2table解包\r\n\t\r\n    self.count = 1 + self.count\r\n\tlocal tdrmeta = CS.UnityEngine.Resources.Load(\"testxxx.tdr\").bytes\r\n\tlocal ret_code, metalib = libtdrlua.load_metalib_buf(tdrmeta)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tbuf_size = 128\r\n\tlocal ret_code, buf = libtdrlua.bufalloc(buf_size)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta_v1 = libtdrlua.get_meta(metalib, \"TestInnerStruct1\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, meta_v2 = libtdrlua.get_meta(metalib, \"TestInnerStruct2\")\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tpkg_table_v1 = {\r\n\t\tint8 = 127,\r\n\t\tdouble = 2.2250738585072114e-308,\r\n\t\tfloat = 1,\r\n\t\tint16 = 32767,\r\n\t\tint32Array = {-0x7FFFFFFF, 0, 0x7FFFFFFF},\r\n\t}\r\n\t\r\n\tpkg_table_v2 = {\r\n\t\tdouble = 2.2250738585072114e-308,\r\n\t\tint8 = 127,\r\n\t\tint32Array = {-0x7FFFFFFF, 0, 0x7FFFFFFF},\r\n\t\tint16 = 32767,\r\n\t\tfloat = 1,\r\n\t}\r\n\t\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta_v1, pkg_table_v1, buf, buf_size, 3)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta_v1, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.int8, 127)\r\n\tASSERT_EQ(pkg_table2.double, 2.2250738585072114e-308)\r\n\tASSERT_EQ(pkg_table2.float, 1)\r\n\tASSERT_EQ(pkg_table2.int16, 32767)\r\n\tASSERT_EQ(pkg_table2.int32Array, {-0x7FFFFFFF, 0, 0x7FFFFFFF})\r\n\t\r\n\tlocal ret_code, used_size = libtdrlua.table2buf(meta_v2, pkg_table_v2, buf, buf_size, 3)\r\n\tASSERT_EQ(ret_code, 0)\r\n\t\r\n\tlocal ret_code, pkg_table2 = libtdrlua.buf2table(meta_v2, buf, used_size, 0)\r\n\tASSERT_EQ(ret_code, 0)\r\n\tASSERT_EQ(pkg_table2.int8, 127)\r\n\tASSERT_EQ(pkg_table2.double, 2.2250738585072114e-308)\r\n\tASSERT_EQ(pkg_table2.float, 1)\r\n\tASSERT_EQ(pkg_table2.int16, 32767)\r\n\tASSERT_EQ(pkg_table2.int32Array, {-0x7FFFFFFF, 0, 0x7FFFFFFF})\r\n\r\n\tlocal err_msg = libtdrlua.free_metalib(metalib)\r\n\tASSERT_EQ(err_msg, nil)\r\n\tlocal err_msg = libtdrlua.buffree(buf)\r\n\tASSERT_EQ(err_msg, nil)\r\nend"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/luaTdrTest.lua.meta",
    "content": "fileFormatVersion: 2\nguid: fa1392032a89cd8489d1e9d150190b68\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/main.lua",
    "content": "\r\nrequire(\"luaCallCs\") \r\nrequire(\"luaCallCsReflect\") \r\nrequire(\"csCallLua\")\r\nrequire(\"genCode\")\r\n--require(\"luaTdrTest\")\r\nfunction islua53() return not not math.type end\r\n-- for test case\r\nCMyTestEnv = TestEnvironment:new()\r\nfunction CMyTestEnv:new(oo)\r\n    local o = oo or {}\r\n    setmetatable(o, self)\r\n    self.__index = self\r\n    return o\r\nend\r\n\r\nfunction CMyTestEnv.SetUp(self)\r\n\tprint(\"CMyTestEnv.SetUp\")\r\nend\r\n\r\nfunction CMyTestEnv.TearDown(self)\r\n\tprint(\"CMyTestEnv.TearDown\")\r\nend\r\n\r\nco = coroutine.create(function()\r\n\tlocal resultPath = CS.LuaTestCommon.resultPath\r\n\tlocal tInitPara = {\r\n\t\t--ltest_filter = \"CMyTestCaseLuaCallCS.*:CMyTestCase3.*\",\r\n\t\tltest_list_tests = resultPath..\"ltest_case_list_co.txt\",\r\n\t\tltest_list_falied = resultPath..\"ltest_case_failed_co.txt\",\r\n\t}\r\n\tInitLTest(tInitPara)\r\n\r\n\tAddLTestSuite(CMyTestCaseLuaCallCS:new(), \"CMyTestCaseLuaCallCS\", \"Case\")\r\n\tAddLTestSuite(CMyTestCaseLuaCallCSReflect:new(), \"CMyTestCaseLuaCallCSReflect\", \"Case\")\r\n\t--AddLTestSuite(CMyTestCaseGenCode:new(), \"CMyTestCaseGenCode\", \"Case\")\r\n\tAddLTestSuite(CMyTestCaseCSCallLua:new(), \"CMyTestCaseCSCallLua\", \"test\")\r\n\t--AddLTestSuite(CMyTestCaseLuaTdr:new(), \"CMyTestCaseLuaTdr\", \"Case\")\r\n\t\r\n\tRunAllTests(CMyTestEnv:new())\r\n\r\n\tlocal t = GetRunStatInfo()\r\n\t--print(t.iFailedNum)\r\n\tcoroutine.yield()\r\nend)\r\n\r\nfunction main()\r\n\r\n\r\n    print(coroutine.resume(co));\r\n\t\r\n\tlocal resultPath = CS.LuaTestCommon.resultPath\r\n\tlocal tInitPara = {\r\n\t\t--ltest_filter = \"CMyTestCaseLuaCallCS.*:CMyTestCase3.*\",\r\n\t\tltest_list_tests = resultPath..\"ltest_case_list.txt\",\r\n\t\tltest_list_falied = resultPath..\"ltest_case_failed.txt\",\r\n\t}\r\n\tInitLTest(tInitPara)\r\n\r\n\tAddLTestSuite(CMyTestCaseLuaCallCS:new(), \"CMyTestCaseLuaCallCS\", \"Case\")\r\n\tAddLTestSuite(CMyTestCaseLuaCallCSReflect:new(), \"CMyTestCaseLuaCallCSReflect\", \"Case\")\r\n\t--AddLTestSuite(CMyTestCaseGenCode:new(), \"CMyTestCaseGenCode\", \"Case\")\r\n\tAddLTestSuite(CMyTestCaseCSCallLua:new(), \"CMyTestCaseCSCallLua\", \"test\")\r\n\t--AddLTestSuite(CMyTestCaseLuaTdr:new(), \"CMyTestCaseLuaTdr\", \"Case\")\r\n\tRunAllTests(CMyTestEnv:new())\r\n\t\r\n\tprint('--------------------------------------------------------')\r\n\r\n\tlocal t = GetRunStatInfo()\r\n\t--print(t.iFailedNum)\r\n\r\nend   \r\n\r\nmain()\r\n\r\nlocal ret = islua53()\r\nprint(\"islua53\")\r\nprint(tostring(ret))"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/main.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 6614b2ace2f43764b9e587155b572200\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/B.lua",
    "content": "tableValue1 = {\r\nkey1 = 100000, key2 = 10, key3 = true,\r\n'red', 'yellow', 'green',\r\nsub = function(self, a, b) \r\n\t\t\t  print('tableValue1.sub called')\r\n\t\t\t  return a - b \r\n\t  end,\r\ntableValueInclude = {\r\n1,2,3,4,5,6,7,8,9,0\r\n},\r\ntableVarInclude = {ikey1 = 10, ikey2 = 12}\r\n}\r\n\r\ntableValue2 = {\r\nkv1 = true, kv2 = 'monday', kv3 = 1\r\n}\r\n\r\ntableValue3 = {\r\n'apple', 'banana', 'orange', 'kiwi', 'grape', 'lemon', 'strawberry', 'pear'\r\n}\r\n\r\ntableValue4 = {\r\nk1= 1, k2= 10, k3 = 100, k4 = 1000, k5 = 10000\r\n}\r\n\r\ntableValue5 = {\r\n[100] =  100, [101] = 1000, [102] = 10000\r\n}\r\n\r\ntableValue6 = {1,2,3}"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/B.lua.meta",
    "content": "fileFormatVersion: 2\nguid: 1f7ef963c7bf8eb4db37942e665f8fd0\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/C.lua.txt",
    "content": "tableValue1 = {\r\nkey1 = 100000, key2 = 10,\r\n'red', 'yellow', 'green',\r\nsub = function(self, a, b) \r\n\t\t\t  print('tableValue1.sub called')\r\n\t\t\t  return a - b \r\n\t  end,\r\ntableValueInclude = {\r\n1,2,3,4,5,6,7,8,9,0\r\n}\r\n}\r\n\r\ntableValue2 = {\r\nkv1 = true, kv2 = 'monday', kv3 = 1\r\n}\r\n\r\ntableValue3 = {\r\n'apple', 'banana', 'orange', 'kiwi', 'grape', 'lemon', 'strawberry', 'pear'\r\n}\r\n\r\ntableValue4 = {\r\nk1= 1, k2= 10, k3 = 100, k4 = 1000, k5 = 10000\r\n}\r\n\r\ntableValue5 = {\r\n[100] =  100, [101] = 1000, [102] = 10000\r\n}\r\n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/C.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 7a0e47ac3a7d33d429fdc4554f7ff117\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/main.lua",
    "content": "require \"testlua.B\"\r\nrequire \"D\"\r\nrequire \"A\""
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua/main.lua.meta",
    "content": "fileFormatVersion: 2\nguid: ace603416f40bbc4281897da7294b5d4\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testlua.meta",
    "content": "fileFormatVersion: 2\nguid: 2e4a7e3c0d82cd04e809dc62d243d3d8\nfolderAsset: yes\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testxxx.tdr.meta",
    "content": "fileFormatVersion: 2\nguid: acb0c591472f9cc45ba9c85e5c8253bc\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/StreamingAssets/testxxx2.tdr.meta",
    "content": "fileFormatVersion: 2\nguid: 88bc84a96f56e814ca9205beefdb5665\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/CSObjectForTestCSCallLua.cs",
    "content": "﻿#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\nusing System.IO;\r\n\r\npublic class tableValue1ClassEqual{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic List<int> tableValueInclude;\r\n}\r\n\r\npublic class tableValue1ClassLess{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic tableValue1ClassLess()\r\n\t{\r\n\t}\r\n}\r\n\r\npublic class tableValue1ClassMore{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic int key4;\r\n}\r\n\r\npublic class tableValue1ClassPrivate{\r\n\tpublic int key1;\r\n\tprivate int key2;\r\n\tpublic bool key3;\r\n\tpublic int Get()\r\n\t{\r\n\t\treturn key2;\r\n\t}\r\n\tpublic void Set(int value)\r\n\t{\r\n\t\tthis.key2 = value;\r\n\t}\r\n}\r\n\r\npublic class tableValue1ClassParamConstucter{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic tableValue1ClassParamConstucter(int key1, int key2, bool key3)\r\n\t{\r\n\t\tthis.key1 = key1;\r\n\t\tthis.key2 = key2;\r\n\t\tthis.key3 = key3;\r\n\t}\r\n}\r\n\r\npublic class tableValue1ClassTwoConstructer{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic tableValue1ClassTwoConstructer()\r\n\t{\r\n\t}\r\n\r\n\tpublic tableValue1ClassTwoConstructer(int key1, int key2, bool key3)\r\n\t{\r\n\t\tthis.key1 = key1;\r\n\t\tthis.key2 = key2;\r\n\t\tthis.key3 = key3;\r\n\t}\r\n}\r\n\r\npublic class tableValue1ClassException{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic tableValue1ClassException()\r\n\t{\r\n\t\tthrow new Exception(\"constructor throw exception.\"); \r\n\t}\r\n}\r\n\r\npublic class tableValue2Class\r\n{\r\n\tpublic bool kv1;\r\n\tpublic string kv3;\r\n\tpublic int kv2;\r\n}\r\n\r\npublic class tableValue4Class\r\n{\r\n\tpublic int k1;\r\n\tpublic int k2;\r\n\tpublic int k3;\r\n\tpublic int k4;\r\n\tpublic int k5;\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableVarIncludeInf\r\n{\r\n\tint ikey1 { get; set; }\r\n\tint ikey2 { get; set; }\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableValue1InfEqual\r\n{\r\n\tint key1 { get; set; }\r\n\tint key2 { get; set; }\r\n\tbool key3 { get; set; }\r\n\ttableVarIncludeInf tableVarInclude {get; set; }\r\n\tint sub(int a, int b);\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableValue1InfMore\r\n{\r\n\tint key1 { get; set; }\r\n\tint key2 { get; set; }\r\n\tbool key3 { get; set; }\r\n\tstring key4 { get; set;}\r\n\tint sub(int a, int b);\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableValue1InfLess\r\n{\r\n\tint key1 { get; set; }\r\n\tint key2 { get; set; }\r\n\tint sub(int a, int b);\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableValue1InfTypeDiff\r\n{\r\n\tstring key1 { get; set; }\r\n\tint key2 { get; set; }\r\n\tint sub(int a, int b);\r\n}\r\n\r\n[CSharpCallLua]\r\npublic interface tableValue2Inf\r\n{\r\n\tbool kv1 { get; set; }\r\n\tstring kv2 { get; set; }\r\n\tint kv3 { get; set; }\r\n}\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncSelfINcreaseDelegate();\r\n\r\n[CSharpCallLua]\r\npublic delegate int FuncAddTableDelegate(LuaTable a);\r\n\r\n[CSharpCallLua]\r\npublic delegate int FuncAdd2elegate(Dictionary<string, int> a);\r\n\r\n[CSharpCallLua]\r\npublic delegate Action GetFuncIncreaseDelegate();\r\n\r\n[CSharpCallLua]\r\npublic delegate bool FuncReturnMultivaluesDelegate1(out string str, out tableValue4Class table);\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncReturnMultivaluesDelegate2(out bool update, out string str, out tableValue4Class table);\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncReturnMultivaluesDelegate3(out bool update, out string str, out tableValue4Class table, out int a);\r\n\r\n[CSharpCallLua]\r\npublic delegate bool FuncReturnMultivaluesDelegate4(out string str);\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncReturnMultivaluesDelegate31(out bool update, out string str, out tableValue4Class table, out tableValue4Class a);\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncMultiParamsDelegate(ref bool a, ref int b, ref string c, out int d);\r\n\r\n/*\r\n[CSharpCallLua]\r\npublic delegate Action FuncMultiParams2Delegate(ref bool a, int b, out int c);\r\n*/\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncMultiParams3Delegate(out int c, int b, ref bool a);\r\n\r\n[CSharpCallLua]\r\npublic delegate void FuncMultiParams3Delegate2(int b, out int c, ref bool a);\r\n\r\n[CSharpCallLua]\r\npublic delegate int FucnVarParamsDelegate(int a, int b);\r\n\r\n[CSharpCallLua]\r\npublic delegate string FucnReadFileDelegate(string filename);\r\n\r\n[CSharpCallLua]\r\npublic delegate System.Object FuncReturnObjectDelegate(int type);\r\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/CSObjectForTestCSCallLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 80bd2608758187a4a8a8a2b867fde5fd\ntimeCreated: 1483527547\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/A.lua.txt",
    "content": "bValue1 = false\r\nbValue2 = true\r\nstrValueEmpty = ''\r\nstrValueLong = string.rep('a', 2^10)\r\nstrValueShort = 'boo123'\r\nstrValueExp = '.* ? [ ] ^ $~`!@#$%^&()_-+=[];\\',    ڢ'\r\nstrValue5 = '\\r\\na'\r\nstrValue6 = [[\r\n<html>\r\n\t<head>\r\n\t\t<title>test</title>\r\n\t</head>\r\n\t<body>\r\n\tthis is just a test lua multi lines string\r\n\t</body>\r\n</html>]]\r\nstrValueChin = 'ַ'\r\nstrValueComp = 'w'\r\nstrValueHoX = '֋q@ӌH'\r\nsbyteValueMax = 127\r\nsbyteValueMin = -128\r\nbyteValueMax = 255\r\nbyteValueMin = 0\r\nshortValueMax = 32767\r\nshortValueMin= -32768\r\nushortValueMax = 65535\r\nushortValueMid = 32768\r\nintValueMax = 2147483647\r\nintValueMin = -2147483648\r\nuintValueMax = 4294967295\r\nuintValueMid = 2147483648\r\nlongValue = 42949672960\r\nlongValue2 = -42949672960\r\nulongValueMax = 42949672960\r\nulongValueMin = 0\r\ndoubleValue = 3.14159265\r\ndoubleValue2 = -3.14159265\r\nfloatValue = 3.14159265\r\nfloatValue2 = -3.14\r\ncharValue = 97\r\ncharValue2 = 65\r\ndecValue = 12.3111111111\r\ndecValue2 = -12.3111111111\r\nintZero= 0"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/A.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 8873402992e800449a66083a965efa13\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/D.lua.txt",
    "content": "strValue = \"D.lua.txt\""
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/D.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 383779e020c98e545b46bcffb0e8eb6b\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/E.lua",
    "content": "strFile = \"E.lua\""
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/E.lua.meta",
    "content": "fileFormatVersion: 2\nguid: b919ed1d655c59340a46f05706d83828\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/InFile.lua.txt",
    "content": "filestring = \"b\""
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/InFile.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: d6e01491f79d6294182471d0f2f58b8d\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/empty.lua.txt",
    "content": ""
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/empty.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: be8f8d969eceb234980e5b556c229e12\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/error.lua.txt",
    "content": "boolDefine = false\r\nif boolDefine:\r\nthen\r\n\tprint(\"error\")\r\nend"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources/error.lua.txt.meta",
    "content": "fileFormatVersion: 2\nguid: 7e0c4d2e49abdf748bf76ad0328dca25\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 04eee5a18722aca49bfb2fb28416ede1\nfolderAsset: yes\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/TCForTestCSCallLua.cs",
    "content": "#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\nusing System.IO;\r\n\r\npublic class LuaEnvSingletonForTest  {\r\n\t\r\n\tstatic private LuaEnv instance = null;\r\n\tstatic public LuaEnv Instance\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif(instance == null)\r\n\t\t\t{\r\n\t\t\t\tinstance = new LuaEnv();\r\n#if XLUA_GENERAL\r\n                instance.DoString(\"package.path = package.path..';../Test/UnitTest/xLuaTest/CSharpCallLua/Resources/?.lua.txt;../Test/UnitTest/StreamingAssets/?.lua'\");\r\n#endif\r\n            }\r\n\t\t\t\r\n\t\t\treturn instance;\r\n\t\t}\r\n\t}\r\n    \r\n}\r\n\r\n\r\npublic static class GenClass\r\n{\r\n    [CSharpCallLua]\r\n    public static List<Type> mymodule_lua_call_cs_list = new List<Type>()\r\n    {\r\n        typeof(System.Action),\r\n    };\r\n}\r\n\r\npublic struct Pedding\r\n{\r\n    public byte c;\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct TestStruct\r\n{\r\n    public TestStruct(int p1, int p2)\r\n    {\r\n        a = p1;\r\n        b = p2;\r\n        c = p2;\r\n        e.c = (byte)p1;\r\n    }\r\n    public int a;\r\n    public int b;\r\n    public decimal c;\r\n    public Pedding e;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class TCForTestCSCallLua{\r\n\tpublic static LuaEnv luaEnv = LuaEnvSingletonForTest.Instance;\r\n\tstring msg = \"\";\r\n\r\n\tpublic void LOG(string text)\r\n\t{\r\n\t\tmsg += text;\r\n\t}\r\n\r\n    string script = @\"\r\n\t\tbValue1 = false\r\n\t\tbValue2 = true\r\n\t\tstrValueEmpty = ''\r\n\t\tstrValueLong = string.rep('a', 2^10)\r\n\t\tstrValueShort = 'boo123'\r\n\t\tstrValueExp = '.* ? [ ] ^ $~`!@#$%^&()_-+=[];\\',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣'\r\n\t\tstrValue5 = '\\r\\na'\r\n\t\tstrValue6 = [[\r\n         <html>\r\n\t\t    <head>\r\n\t\t        <title>test</title>\r\n\t\t    </head>\r\n\t\t    <body>\r\n\t\t\tthis is just a test lua multi lines string\r\n\t\t    </body>\r\n\t\t</html>]]\r\n\t\tstrValueChin = '中文字符串'\r\n\t\tstrValueComp = '繁體國陸'\r\n\t\tstrValueHoX = '吙煋呅僦媞這樣孒'\r\n\t\tsbyteValueMax = 127\r\n\t\tsbyteValueMin = -128\r\n\t\tbyteValueMax = 255\r\n\t\tbyteValueMin = 0\r\n\t\tshortValueMax = 32767\r\n\t\tshortValueMin= -32768\r\n\t\tushortValueMax = 65535\r\n\t\tushortValueMid = 32768\r\n\t\tintValueMax = 2147483647\r\n\t\tintValueMin = -2147483648\r\n\t\tuintValueMax = 4294967295\r\n\t\tuintValueMid = 2147483648\r\n\t\tlongValue = 42949672960\r\n\t\tlongValue2 = -42949672960\r\n\t\tulongValueMax = 42949672961111\r\n\t\tulongValueMin = 0\r\n\t\tdoubleValue = 3.14159265\r\n\t\tdoubleValue2 = -3.14159265\r\n\t\tfloatValue = 3.14159265\r\n\t\tfloatValue2 = -3.14\r\n\t\tcharValue = 97\r\n\t\tcharValue2 = 65\r\n\t\tdecValue = 12.3111111111\r\n\t\tdecValue2 = -12.3111111111\r\n\t\tintValue3 = 0\r\n\t\tintZero = 0\r\n\r\n\t\ttableValue1 = {\r\n\t\tkey1 = 100000, key2 = 10, key3 = true,\r\n\t\t'red', 'yellow', 'green',\r\n\t\tsub = function(self, a, b) \r\n\t\t              print('tableValue1.sub called')\r\n\t\t              return a - b \r\n\t\t      end,\r\n\t\ttableValueInclude = {\r\n\t\t1,2,3,4,5,6,7,8,9,0\r\n\t\t},\r\n\t\ttableVarInclude = {ikey1 = 10, ikey2 = 12}\r\n\t\t}\r\n\r\n\t\ttableValue2 = {\r\n\t\tkv1 = true, kv2 = 'monday', kv3 = 1\r\n\t\t}\r\n\r\n\t\ttableValue3 = {\r\n\t\t'apple', 'banana', 'orange', 'kiwi', 'grape', 'lemon', 'strawberry', 'pear'\r\n\t\t}\r\n\r\n\t\ttableValue4 = {\r\n\t\tk1= 1, k2= 10, k3 = 100, k4 = 1000, k5 = 10000\r\n\t\t}\r\n\r\n\t\ttableValue5 = {\r\n\t\t[100] =  100, [101] = 1000, [102] = 10000\r\n\t\t}\r\n\r\n\t\ttableValue6 = {1,2,3}\r\n\r\n\t\ttableValue7 = {\r\n\t\tkey1 = 'abc',  key2 = 10}\r\n\r\n\t\tfunction func_self_increase()\r\n\t\t\tprint('func_self_inscrease called')\r\n\t\t\tintValue3 = intValue3 + 1;\r\n\t\tend\r\n\r\n\t\tfunction func_add_table(a)\r\n\t\t    local sum = 0  \r\n\t\t    for i, v in ipairs(a) do  \r\n\t\t        sum = sum + v  \r\n\t\t    end  \r\n\t\t    return sum\r\n\t\tend\r\n\r\n\t\tfunction func_add_2(a)\r\n\t\t    local sum = 0  \r\n\t\t    for i, v in pairs(a) do  \r\n\t\t        sum = sum + v  \r\n\t\t    end  \r\n\t\t    return sum\r\n\t\tend  \r\n\r\n\t\tfunction func_return_multivalues()\r\n\t\t\tlocal update = false\r\n\t\t\tlocal strShort = 'false'\r\n\t\t\tprint('intValue3=', intValue3)\r\n\t\t\tif intValue3 > 0\r\n\t\t\tthen\r\n\t\t\tprint('in if, intValue3=', intValue3)\r\n\t\t\t\tupdate = true\r\n\t\t\t\tstrShort = 'true'\r\n\t\t\tend\r\n\t\t\treturn update, strShort, {k1 = 11, k2 = 12}\r\n\t\tend\r\n\r\n\t\tfunction func_return_multivalues2()\r\n\t\t\tlocal update = false\r\n\t\t\tlocal strShort = 'false'\r\n\t\t\tprint('intValue3=', intValue3)\r\n\t\t\tif intValue3 > 0\r\n\t\t\tthen\r\n\t\t\tprint('in if, intValue3=', intValue3)\r\n\t\t\t\tupdate = true\r\n\t\t\t\tstrShort = 'true'\r\n\t\t\tend\r\n\t\t\treturn update, strShort, {k1 = 11, k2 = 12}\r\n\t\tend\r\n\r\n\t\tfunction func_return_func()\r\n\t\t\tprint('func_return_func called')\r\n\t\t\treturn func_self_increase\r\n\t\tend\r\n\r\n\t\tfunction func_closure()\r\n\t\t\tlocal i = 0\r\n\t\t    return function()\r\n\t\t              i = i + 1\r\n\t\t              return i\r\n\t\t\t\t   end\r\n\t\tend\r\n\r\n\t\tfunction func_multi_params(a, b, c)\r\n\t\t    if a == true\r\n\t\t\tthen\r\n\t\t\t\tb = b + 1\r\n\t\t\t\tc = string.lower(c)\r\n\t\t\tend\r\n\t\t    return a, b, c\r\n\t\tend\r\n\r\n\t\tfunction func_multi_params2(a, b)\r\n\t\t\tlocal sum = 0\r\n\t\t    if a == true\r\n\t\t\tthen\r\n\t\t\t\tsum = b + 1\r\n\t\t\tend\r\n\t\t    return func_self_increase, a, sum\r\n\t\tend \r\n\r\n\t\tfunction func_multi_params3(b, a)\r\n\t\t\tlocal sum = 0\r\n\t\t    if a == true\r\n\t\t\tthen\r\n\t\t\t\tsum = b + 1 \r\n\t\t\tend\r\n\t\t    return sum, a\r\n\t\tend\r\n\r\n\t\tfunction func_multi_params4(b, a)\r\n\t\t\tlocal sum = 0\r\n\t\t    if a == true\r\n\t\t\tthen\r\n\t\t\t\tsum = b + 1 \r\n\t\t\tend\r\n\t\t    return sum, a\r\n\t\tend \r\n\r\n\t\tfunction func_varparams(...)\r\n \t\t\tlocal arg={...}\r\n\t\t\tlocal sum = 0  \r\n\t\t    print(select('#', ...))\r\n\t\t\tfor key, value in ipairs(arg)\r\n\t\t\tdo\r\n\t\t\t\tsum = sum + value\r\n\t\t\t\t--print(value)\r\n\t\t\t\t--sum = sum + 1\r\n\t\t\tend\r\n\t\t    return sum\r\n\t\tend\r\n\r\n\t\tfunction func_readfile(file_name)\r\n\t\t\tlocal hFile = io.open(file_name, r)\r\n\t\t\tif hFile\r\n\t\t\tthen\r\n\t\t\t\tlocal strContent = hFile:read('*all')\r\n\t\t\t\tprint(strContent)\r\n\t\t\t\treturn strContent\r\n\t\t\telse\r\n\t\t\t\tprint('file is not exist')\r\n\t\t\tend\r\n\t\treturn nil\r\n\t\tend\r\n      \r\n        function func_return_object(type)\r\n            if type == 0 then\r\n\t\t\t\tlocal ret = io.open(CS.LuaTestCommon.xxxtdrfilepath, r)\r\n\t\t\t\tprint('open A.lua.txt ret is ', ret)\r\n\t\t\t\treturn ret\r\n\t\t\tend\r\n            if type == 1 then\r\n\t\t\t\treturn CS.LongStatic.LONG_MAX\r\n\t\t\tend\r\n\t\t\tif type == 2 then\r\n\t\t\t\treturn CS.LongStatic.ULONG_MAX\r\n\t\t\tend\r\n\t\t\treturn 0\r\n\t\tend\r\n    \";\r\n\t\r\n\tpublic struct TestResult\r\n\t{\r\n\t\tpublic bool result;\r\n\t\tpublic string msg;\r\n\t\tpublic override string ToString()\r\n\t\t{\r\n\t\t\treturn \"Result: \" + result.ToString () + \", Msg:\" + msg;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic TCForTestCSCallLua()\r\n\t{\r\n\r\n\t}\r\n\r\n\tpublic void setResult(bool result, string msg, out TestResult resultStruct)\r\n\t{\r\n\t\tresultStruct.result = result;\r\n\t\tresultStruct.msg = msg;\r\n\t}\r\n\r\n\tpublic void updateResult(bool result, string msg, ref TestResult resultStruct)\r\n\t{\r\n\t\tif (resultStruct.result == true) {\r\n\t\t\tresultStruct.msg = msg;\r\n\t\t} else {\r\n\t\t\tresultStruct.msg = resultStruct.msg + \"\\r\\n\" + msg;\r\n\t\t}\r\n\t\tresultStruct.result = result;\r\n\t}\r\n\r\n\tpublic byte[] AddLoader1(ref string filename)\r\n\t{\r\n\t\tif (filename == \"InMemory\")\r\n\t\t{\r\n\t\t\tstring script = \"return {ccc = 9999}\";\r\n\t\t\treturn System.Text.Encoding.UTF8.GetBytes(script);\r\n\t\t}\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic byte[] AddLoader2(ref string filename)\r\n\t{\r\n\t\tif (filename == \"InFile\") {\r\n\t\t\tstring script = \"filestring = 'addloader2'\";\r\n\t\t\treturn System.Text.Encoding.UTF8.GetBytes (script);\r\n\t\t} else if (filename == \"other\") {\r\n\t\t\tstring script = \"error('filename is error')\";\r\n\t\t\treturn System.Text.Encoding.UTF8.GetBytes (script);\r\n\t\t} else if (filename == \"error_lua\") {\r\n\t\t\tstring script = \"maths:abs(-10)\";\r\n\t\t\treturn System.Text.Encoding.UTF8.GetBytes (script);\r\n\t\t}\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic string listToString(List<int> a)\r\n\t{\r\n\t\tstring result = \"\";\r\n\t\tforeach (int i in a) {\r\n\t\t\tresult += i.ToString() + \",\";\r\n\t\t}\r\n\t\treturn result.TrimEnd(',');\r\n\t}\r\n\r\n\tpublic string listToStr(List<string> a)\r\n\t{\r\n\t\tstring result = \"\";\r\n\t\tforeach (string i in a) {\r\n\t\t\tresult += i + \",\";\r\n\t\t}\r\n\t\treturn result.TrimEnd(',');\r\n\t}\r\n\t\r\n\tpublic TestResult testDoString2LoadLua_Step_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testDoString2LoadLua_Step_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tstring luaScript = @\"\r\n            --call standard lib\r\n\t\t\trequire 'math'\r\n\t\t\ta = math.abs(-10)\r\n\t\t\tprint('abs: ', a)\r\n\t\t\t\";\r\n\r\n\t\t\tluaEnv.DoString (luaScript);\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult(false, e.Message , out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testDoString2LoadLua_Step_2()\r\n\t{\r\n\t\t/*\r\n\t\t *\r\n\t\t */\r\n\t\tstring caseName = \"testDoString2LoadLua_Step_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tstring luaScript = @\"\r\n            checkFlag = false;\r\n\t\t\ta  = 100\r\n\t\t\tb = 1000\r\n\t\t\tif a < b then\r\n\t\t\t\terror('error raise')\r\n\t\t\tend\r\n\t\t\t\";\r\n\t\t\tluaEnv.DoString (luaScript);\r\n\t\t\tsetResult(false, \"syntax error should be found, but there is no exception.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testDoString2LoadLua_Step_3()\r\n\t{\r\n\t\t/*\r\n\t\t *\r\n\t\t */\r\n\t\tstring caseName = \"testDoString2LoadLua_Step_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tstring luaScript = @\"\r\n            --call standard lib\r\n\t\t\ta = maths.abs(-10)\r\n\t\t\tprint('abs: ', a)\r\n\t\t\t\";\r\n\t\t\tluaEnv.DoString (luaScript);\r\n\t\t\tsetResult(false, \"exception should be raised, but there is no exception.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testRequire2LoadLua_Step_1_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testRequire2LoadLua_Step_1_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString(\"require 'A'\");\r\n\t\t\tluaEnv.DoString(\"require 'testlua.B';require 'D'\");\r\n\t\t\tluaEnv.DoString(\"require 'empty'\");\r\n\t\t\t// luaEnv.DoString (\"require 'testlua.main'\");\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult(false, e.Message , out result);\r\n\t\t}\r\n\t\tstring dValue = luaEnv.Global.Get<string> (\"strValue\");\r\n\t\tLOG (\"_G.strValue = \" + dValue);\r\n\t\tif (dValue != \"D.lua.txt\") {\r\n\t\t\tsetResult (false, result.msg + \", require should require d from Resources, but strValue=\" + dValue, out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testRequire2LoadLua_Step_4()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testRequire2LoadLua_Step_4: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString (\"require 'testlua.main'\");\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult(false, e.Message , out result);\r\n\t\t}\r\n\t\tstring dValue = luaEnv.Global.Get<string> (\"strValue\");\r\n\t\tLOG (\"_G.strValue = \" + dValue);\r\n\t\tif (dValue != \"D.lua.txt\") {\r\n\t\t\tsetResult (false, result.msg + \", require should require d from Resources, but strValue=\" + dValue, out result);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testRequire2LoadLua_Step_5()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testRequire2LoadLua_Step_5: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString (\"require 'E'\");\r\n\t\t\tsetResult(false, \"E.lua in Resources path, but be loaded, no exception be raised.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testRequire2LoadLua_Step_6()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testRequire2LoadLua_Step_6: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString (\"require 'F'\");\r\n\t\t\tsetResult(false, \"F.lua deesn't exist, but no exception be raised.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testRequire2LoadLua_Step_7()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testRequire2LoadLua_Step_7: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString (\"require 'error'\");\r\n\t\t\tsetResult(false, \"there is syntax errors in error.lua, but no exception be raised.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testAddLoader2LoadLua_Step_1_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testAddLoader2LoadLua_Step_1_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.AddLoader(AddLoader1);\r\n\t\t\tluaEnv.DoString(\"inmemory = require('InMemory').ccc\");\r\n\t\t\tluaEnv.AddLoader(AddLoader2);\r\n\t\t\tluaEnv.DoString(\"require('InFile')\");\r\n\t\t\tluaEnv.AddLoader(AddLoader2);\r\n\t\t\tluaEnv.DoString(\"require('InFile')\");\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult(false, e.Message , out result);\r\n\t\t}\r\n\t\tLuaTestCommon.Log (\"InMemory.ccc=\" + luaEnv.Global.Get<int> (\"inmemory\"));\r\n        LuaTestCommon.Log(\"InFile.filestring=\" + luaEnv.Global.Get<string>(\"filestring\"));\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testAddLoader2LoadLua_Step_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testAddLoader2LoadLua_Step_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.AddLoader(AddLoader2);\r\n\t\t\tluaEnv.DoString(\" require('other')\");\r\n\t\t\tsetResult(false, \"AddLoader2 should raise exception, but it doesn't.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\" , out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testAddLoader2LoadLua_Step_6()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testAddLoader2LoadLua_Step_6: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.AddLoader(AddLoader2);\r\n\t\t\tluaEnv.DoString(\" require('error_lua')\");\r\n\t\t\tsetResult(false, \"AddLoader2 should raise exception, but it doesn't.\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testAddLoader2LoadLua_Step_7()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testAddLoader2LoadLua_Step_7: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.AddLoader(AddLoader2);\r\n            luaEnv.DoString(@\"package.loaded['InFil'] = nil\");\r\n\t\t\tluaEnv.DoString(\"require('InFile')\");\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tsetResult(false, e.Message , out result);\r\n\t\t}\r\n\t\tstring filestring = luaEnv.Global.Get<string> (\"filestring\");\r\n        if (filestring != \"addloader2\")\r\n        {\r\n            setResult(false, \"shoulde load loader defined, but loadfile in Resources.\", out result);\r\n\t\t}\r\n\t\tLuaTestCommon.Log (\"InFile.filestring=\" + filestring);\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testGetBasicDataTypeBool_Step_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeBool_step_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\r\n\t\tluaEnv.DoString(script);\r\n\r\n\t\tbool falseVar = luaEnv.Global.Get<bool> (\"bValue1\");\r\n\t\tbool trueVar = luaEnv.Global.Get<bool> (\"bValue2\");\r\n\t\tLOG (\"bValue1=\" + falseVar + \"; bValue2=\" + trueVar);\r\n\t\tif (falseVar == false && trueVar == true) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"fail\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeString_Step_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeString_step_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tstring emptyStr = luaEnv.Global.Get<string> (\"strValueEmpty\");\r\n\t\tstring longStr = luaEnv.Global.Get<string> (\"strValueLong\");\r\n\t\tstring shortStr = luaEnv.Global.Get<string> (\"strValueShort\");\r\n\t\tstring expStr = luaEnv.Global.Get<string> (\"strValueExp\");\r\n\t\tstring zhuanyiStr = luaEnv.Global.Get<string> (\"strValue5\"); \r\n\t\tstring linesStr = luaEnv.Global.Get<string> (\"strValue6\"); \r\n\t\tstring chinStr = luaEnv.Global.Get<string> (\"strValueChin\"); \r\n\t\tstring compStr = luaEnv.Global.Get<string> (\"strValueComp\"); \r\n\t\tstring huoxingStr = luaEnv.Global.Get<string> (\"strValueHoX\"); \r\n\r\n\t\tLOG (\"strValueEmpty=\" + emptyStr + \"; strValueLong length=\" + longStr.Length);\r\n\t\tLOG (\"strValueShort=\" + shortStr + \"; trValueExp=\" + expStr);\r\n\t\tLOG (\"strValue5=\" + zhuanyiStr + \"; strValue6=\" + linesStr);\r\n\t\tLOG (\"strValueChin=\" + chinStr + \"; strValueComp=\" + compStr);\r\n\t\tLOG (\"strValueHoX=\" + huoxingStr);\r\n\r\n\t\tif (emptyStr == \"\") {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).empty string isn't empty, is \" + emptyStr, out result);\r\n\t\t}\r\n\t\tif (longStr.Length != 1024) {\r\n\t\t\tupdateResult(false, \"(2). long string's length should be 1024, but is \" + longStr.Length, ref result);\r\n\t\t}\r\n\t\tif (shortStr != \"boo123\") {\r\n\t\t\tupdateResult(false, \"(3). short string should be bool123 but is \" + shortStr, ref result);\r\n\t\t}\r\n\t\tif (expStr != \".* ? [ ] ^ $~`!@#$%^&()_-+=[];\\',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣\") {\r\n\t\t\tupdateResult(false, \"(4). complex string is wrong, which is  \" + expStr, ref result);\r\n\t\t}\r\n\t\tif (zhuanyiStr != \"\\r\\na\") {\r\n\t\t\tupdateResult(false, \"(5).zhuanyi string is wrong, which is  \" + zhuanyiStr, ref result);\r\n\t\t}\r\n\t\tif (linesStr.Split('\\n').Length !=8) {\r\n\t\t\tupdateResult(false, \"(6).multi lines string should have 8 liens, but it is  \" + linesStr.Split('\\n').Length, ref result);\r\n\t\t}\r\n\t\tif (chinStr != \"中文字符串\") {\r\n\t\t\tupdateResult(false, \"(7).chinese string is wrong, which is \" + chinStr, ref result);\r\n\t\t}\r\n\t\tif (compStr != \"繁體國陸\") {\r\n\t\t\tupdateResult(false, \"(8).fanti string is wrong, which is \" + compStr, ref result);\r\n\t\t}\r\n\t\tif (huoxingStr != \"吙煋呅僦媞這樣孒\") {\r\n\t\t\tupdateResult(false, \"(9).huoxing string is wrong, which is \" + huoxingStr, ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToSByte()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToSByte: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> sbyte\r\n\t\tsbyte sbyteValueMax = luaEnv.Global.Get<sbyte> (\"sbyteValueMax\");\r\n\t\tsbyte sbyteValueMin = luaEnv.Global.Get<sbyte> (\"sbyteValueMin\");\r\n\t\tsbyte sbyteOverMax = luaEnv.Global.Get<sbyte> (\"intValueMax\");\r\n\t\tsbyte sbyteOverMin = luaEnv.Global.Get<sbyte> (\"intValueMin\");\r\n\t\tLOG (\"sbyteValueMax=\" + sbyteValueMax + \"; sbyteValueMin=\" + sbyteValueMin);\r\n\t\tLOG (\"sbyteOverMax=\" + sbyteOverMax + \"; sbyteOverMin=\" + sbyteOverMin);\r\n\t\t\r\n\t\tif (sbyteValueMax == System.SByte.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).sbyteValueMax, is \" + sbyteValueMax, out result);\r\n\t\t}\r\n\t\tif (sbyteValueMin != System.SByte.MinValue) {\r\n\t\t\tupdateResult(false, \"(2).sbyteValueMin, is \" + sbyteValueMin, ref result);\r\n\t\t}\r\n\t\tif (sbyteOverMax != -1) {\r\n\t\t\tupdateResult(false, \"(3).sbyteOverMax, is \" + sbyteOverMax, ref result);\r\n\t\t}\r\n\t\tif (sbyteOverMin != 0) {\r\n\t\t\tupdateResult(false, \"(4).sbyteOverMin, is \" + sbyteOverMin, ref result);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToByte()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToByte: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> byte\r\n\t\tbyte byteValueMax = luaEnv.Global.Get<byte> (\"byteValueMax\");\r\n\t\tbyte byteValueMin = luaEnv.Global.Get<byte> (\"byteValueMin\");\r\n\t\tbyte byteOverMax = luaEnv.Global.Get<byte> (\"intValueMax\");\r\n\t\tbyte byteOverMin = luaEnv.Global.Get<byte> (\"intValueMin\");\r\n\t\tLOG (\"byteValueMax=\" + byteValueMax + \"; byteValueMin=\" + byteValueMin);\r\n\t\tLOG (\"byteOverMax=\" + byteOverMax + \"; byteOverMin=\" + byteOverMin);\r\n\t\t\r\n\t\tif (byteValueMax == System.Byte.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).byteValueMax, is \" + byteValueMax, out result);\r\n\t\t}\r\n\t\tif (byteValueMin != System.Byte.MinValue) {\r\n\t\t\tupdateResult(false, \"(2).byteValueMin, is \" + byteValueMin, ref result);\r\n\t\t}\r\n\t\tif (byteOverMax != 255) {\r\n\t\t\tupdateResult(false, \"(3).byteOverMax, is \" + byteOverMax, ref result);\r\n\t\t}\r\n\t\tif (byteOverMin != 0) {\r\n\t\t\tupdateResult(false, \"(4).sbyteOverMin, is \" + byteOverMin, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToShort()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToShort: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> short\r\n\t\tshort shortValueMax = luaEnv.Global.Get<short> (\"shortValueMax\");\r\n\t\tshort shortValueMin = luaEnv.Global.Get<short> (\"shortValueMin\");\r\n\r\n\t\tLOG (\"shortValueMax=\" + shortValueMax + \"; shortValueMin=\" + shortValueMin);\r\n\t\t\r\n\t\tif (shortValueMax == System.Int16.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).shortValueMax, is \" + shortValueMax, out result);\r\n\t\t}\r\n\t\tif (shortValueMin != System.Int16.MinValue) {\r\n\t\t\tupdateResult(false, \"(2).shortValueMin, is \" + shortValueMin, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToUShort()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToUShort: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> ushort\r\n\t\tushort ushortValueMax = luaEnv.Global.Get<ushort> (\"ushortValueMax\");\r\n\t\tushort ushortValueMid = luaEnv.Global.Get<ushort> (\"ushortValueMid\");\r\n\t\t\r\n\t\tLOG (\"ushortValueMax=\" + ushortValueMax + \"; shortValueMin=\" + ushortValueMid);\r\n\t\t\r\n\t\tif (ushortValueMax == System.UInt16.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).ushortValueMax, is \" + ushortValueMax, out result);\r\n\t\t}\r\n\t\tif (ushortValueMid != 32768) {\r\n\t\t\tupdateResult(false, \"(2).ushortValueMid, is \" + ushortValueMid, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToInt()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToInt: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> int\r\n\t\tint intValueMax = luaEnv.Global.Get<int> (\"intValueMax\");\r\n\t\tint intValueMin = luaEnv.Global.Get<int> (\"intValueMin\");\r\n\t\tint intZero = luaEnv.Global.Get<int> (\"intZero\");\r\n\t\t\r\n\t\tLOG (\"intValueMax=\" + intValueMax + \"; intValueMin=\" + intValueMin);\r\n\r\n\t\tif (intValueMax == System.Int32.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).intValueMax, is \" + intValueMax, out result);\r\n\t\t}\r\n\t\tif (intValueMin != System.Int32.MinValue) {\r\n\t\t\tupdateResult(false, \"(2).intValueMin, is \" + intValueMin, ref result);\r\n\t\t}\r\n\t\tif (intZero != 0) {\r\n\t\t\tupdateResult(false, \"(3).intZero, is \" + intZero, ref result);\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tint intValueOverMax = luaEnv.Global.Get<int> (\"longValue\");\r\n\t\t\tint intValueOverMin = luaEnv.Global.Get<int> (\"uintValueMax\");\r\n\t\t\tLOG (\"intValueOverMax=\" + intValueOverMax + \"; intValueOverMin=\" + intValueOverMin);\r\n\t\t} catch(Exception e) {\r\n\t\t\tupdateResult(false, \"it shouldn't raise exception, but e.msg:\" + e.Message, ref result);\r\n\t\t}\r\n\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToUInt()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToUInt: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> uint\r\n\t\tuint uintValueMax = luaEnv.Global.Get<uint> (\"uintValueMax\");\r\n\t\tuint uintValueMid = luaEnv.Global.Get<uint> (\"uintValueMid\");\r\n\t\t\r\n\t\tLOG (\"uintValueMax=\" + uintValueMax + \"; uintValueMid=\" + uintValueMid);\r\n\t\t\r\n\t\tif (uintValueMax == System.UInt32.MaxValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).uintValueMax, is \" + uintValueMax, out result);\r\n\t\t}\r\n\t\tif (uintValueMid != 2147483648) {\r\n\t\t\tupdateResult(false, \"(2).uintValueMid, is \" + uintValueMid, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToLong()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToLong: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> long\r\n\t\tlong longValue = luaEnv.Global.Get<long> (\"longValue\");\r\n\t\tlong longValue2 = luaEnv.Global.Get<long> (\"longValue2\");\r\n\t\t\r\n\t\tLOG (\"longValue=\" + longValue + \"; longValue2=\" + longValue2);\r\n        LuaTestCommon.Log(\"longValue=\" + longValue + \"; longValue2=\" + longValue2);\r\n\t\t\r\n\t\tif (longValue == 42949672960) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).longValue, is \" + longValue, out result);\r\n\t\t}\r\n\t\tif (longValue2 != -42949672960) {\r\n\t\t\tupdateResult(false, \"(2).longValue2, is \" + longValue2, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToULong()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToULong: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> ulong\r\n\t\tulong ulongValueMax = luaEnv.Global.Get<ulong> (\"ulongValueMax\");\r\n\t\tulong ulongValueMin = luaEnv.Global.Get<ulong> (\"ulongValueMin\");\r\n\t\t\r\n\t\tLOG (\"ulongValueMax=\" + ulongValueMax + \"; ulongValueMin=\" + ulongValueMin);\r\n\t\t\r\n\t\tif (ulongValueMax == 42949672961111) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).ulongValueMax, is \" + ulongValueMax, out result);\r\n\t\t}\r\n\t\tif (ulongValueMin != 0) {\r\n\t\t\tupdateResult(false, \"(2).ulongValueMin, is \" + ulongValueMin, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToDouble()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToDouble: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> double\r\n\t\tdouble doubleValue = luaEnv.Global.Get<double> (\"doubleValue\");\r\n\t\tdouble doubleValue2 = luaEnv.Global.Get<double> (\"doubleValue2\");\r\n\t\t\r\n\t\tLOG (\"doubleValue=\" + doubleValue + \"; doubleValue2=\" + doubleValue2);\r\n\t\t\r\n\t\tif (doubleValue == 3.14159265) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).doubleValue, is \" + doubleValue, out result);\r\n\t\t}\r\n\t\tif (doubleValue2 != -3.14159265) {\r\n\t\t\tupdateResult(false, \"(2).doubleValue2, is \" + doubleValue2, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToChar()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToChar: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> char\r\n\t\tchar charValue = luaEnv.Global.Get<char> (\"charValue\");\r\n\t\tchar charValue2 = luaEnv.Global.Get<char> (\"charValue2\");\r\n\t\t\r\n\t\tLOG (\"charValue=\" + charValue + \"; charValue2=\" + charValue2);\r\n\t\t\r\n\t\tif (charValue == 'a') {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).charValue, is \" + charValue, out result);\r\n\t\t}\r\n\t\tif (charValue2 != 'A') {\r\n\t\t\tupdateResult(false, \"(2).charValue2, is \" + charValue2, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToFloat()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToFloat: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> float\r\n\t\tfloat floatValue = luaEnv.Global.Get<float> (\"floatValue\");\r\n\t\tfloat floatValue2 = luaEnv.Global.Get<float> (\"floatValue2\");\r\n\t\t\r\n\t\tLOG (\"floatValue=\" + floatValue.ToString(\"F8\") + \"; charValue2=\" + floatValue2);\r\n\r\n\t\tif (System.Math.Abs(floatValue - 3.141593) < 0.000001) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).floatValue, is \" + floatValue, out result);\r\n\t\t}\r\n\t\tif (System.Math.Abs(floatValue + 3.14) < 0.000001) {\r\n\t\t\tupdateResult(false, \"(2).floatValue2, is \" + floatValue2, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataTypeNumberToDecimal()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataTypeNumberToDecimal: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t// number -> decimal\r\n\t\tdecimal decValue = luaEnv.Global.Get<decimal> (\"decValue\");\r\n\t\tdecimal decValue2 = luaEnv.Global.Get<decimal> (\"decValue2\");\r\n\t\tdecimal expectValue = 12.3111111111m;\r\n\t\tdecimal expectValue2 = -12.3111111111m;\r\n\r\n\t\tLOG (\"decValue=\" + decValue + \"; decValue2=\" + decValue2);\r\n\t\t\r\n\t\tif (decValue == expectValue) {\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).decValue, is \" + decValue, out result);\r\n\t\t}\r\n\t\tif (decValue2 != expectValue2) {\r\n\t\t\tupdateResult(false, \"(2).decValue2, is \" + decValue2, ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetBasicDataType_Step_4()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataType_Step_4: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString(script);\r\n\t\t\tint noExistInt = luaEnv.Global.Get<int> (\"noExistValue\");\r\n\t\t\tstring noExistString = luaEnv.Global.Get<string> (\"noExistString\");\r\n\t\t\tLOG (\"noExistInt=\" + noExistInt + \"; noExistString=\" + noExistString);\r\n\t\t\t//setResult (false, \"no exist value should raise exception\", out result);\r\n\t\t\t//setResult(false, \"there is no var defined, should raise exception, but it doesn't.\", out result);\r\n\t\t\tsetResult (false, \"v2.1.3 change,noExistValue,  only value type and nil value will raise exception\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tLOG(e.Message);\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testGetBasicDataType_Step_5()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetBasicDataType_Step_5: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\ttry  \r\n\t\t{  \r\n\t\t\tluaEnv.DoString(script);\r\n\t\t\tluaEnv.DoString(\"str2int='123'\");\r\n\t\t\tint string2Int = luaEnv.Global.Get<int> (\"str2int\");\r\n\t\t\t/*string number2str = luaEnv.Global.Get<string>(\"byteValueMax\");\r\n\t\t\tLOG (\"string2Int=\" + string2Int + \", number2str=\" + number2str);\r\n\r\n\t\t\tint bool2int = luaEnv.Global.Get<int> (\"bValue2\");\r\n\t\t\tstring bool2str = luaEnv.Global.Get<string> (\"bValue1\");\r\n\t\t\tLOG (\"bool2int=\" + bool2int + \", bool2str=\" + bool2str);*/\r\n\t\t\t//setResult (false, \"type is not same, should raise exception\", out result);\r\n\t\t\t// setResult(false, \"there is no var defined, should raise exception, but it doesn't.\", out result);\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t}  \r\n\t\tcatch(Exception e)\r\n\t\t{  \r\n\t\t\tLOG(e.Message);\r\n\t\t\tsetResult (false, \"v2.1.3 change, type is not same, only value type and nil value will raise exception\", out result);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t} \r\n\r\n\tpublic TestResult testGetTableToClass_Step_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\r\n\t\ttableValue1ClassEqual tb1Class = luaEnv.Global.Get<tableValue1ClassEqual> (\"tableValue1\");\r\n\t\tList<int> tableValueIncludeList = new List<int>(){1,2,3,4,5,6,7,8,9,0};\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2= \" + tb1Class.key2);\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Class.key3 + \"; tableValue1.tableValueInclude= \" + \r\n\t\t           listToString(tb1Class.tableValueInclude));\r\n\t\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Class.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Class.key2 , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.key3 != true) {\r\n\t\t\tupdateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb1Class.key3 , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.tableValueInclude.Count != tableValueIncludeList.Count || \r\n\t\t    tb1Class.tableValueInclude[0] != tableValueIncludeList[0]) {\r\n\t\t\tupdateResult(false, \"(4).tableValue1.tableValueInclude should be {1,2,3,4,5,6,7,8,9,0},\" +\r\n\t\t\t             \"but in fact is \" +  listToString(tb1Class.tableValueInclude), ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1ClassLess tb1Class = luaEnv.Global.Get<tableValue1ClassLess> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2= \" + tb1Class.key2);\r\n\t\t\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Class.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Class.key2 , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1ClassMore tb1Class = luaEnv.Global.Get<tableValue1ClassMore> (\"tableValue1\");\r\n\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2 = \" + tb1Class.key2);\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Class.key3 + \"; tableValue1ClassMore.key4 = \" +  tb1Class.key4);\r\n\t\t\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Class.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Class.key2 , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.key3 != true) {\r\n\t\t\tupdateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb1Class.key3 , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.key4 != 0) {\r\n\t\t\tupdateResult(false, \"(4).key4 should be 0 default, but in fact is \" + tb1Class.key4 , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_4()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_4: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1ClassMore tb1Class = luaEnv.Global.Get<tableValue1ClassMore> (\"tableValue1\");\r\n\t\t\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2 = \" + tb1Class.key2);\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Class.key3 + \"; tableValue1ClassMore.key4 = \" +  tb1Class.key4);\r\n\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\r\n\t\ttb1Class.key1 = 100;\r\n\t\ttableValue1ClassMore tb1Class2 = luaEnv.Global.Get<tableValue1ClassMore> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class2.key1);\r\n\t\tif (tb1Class2.key1 != 100000){\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key1 should be 100000, but int fact is\" + tb1Class2.key1 , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_5()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_5: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1ClassPrivate tb1Class = luaEnv.Global.Get<tableValue1ClassPrivate> (\"tableValue1\");\r\n\t\t\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2 = \" + tb1Class.Get());\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Class.key3);\r\n\t\t\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Class.Get () != 0){\r\n\t\t\tupdateResult(false, \"(2).private key2 should be 0, but int fact is \" + tb1Class.Get () , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.key3 != true) {\r\n\t\t\tupdateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb1Class.key3 , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_1_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_1_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\ttry{\r\n\r\n\t\t\ttableValue1ClassParamConstucter tb1Class = luaEnv.Global.Get<tableValue1ClassParamConstucter> (\"tableValue1\");\r\n\t\t\t// LOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2 = \" + tb1Class.key2);\r\n\t\t\t// LOG (\"tableValue1.key3 = \" + tb1Class.key3);\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} catch(Exception e){\r\n\t\t\tsetResult (false, \"v2.1.3change, only value type and nil value will raise exception ,class has no non-param constructor will not\", out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_1_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_1_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1ClassTwoConstructer tb1Class = luaEnv.Global.Get<tableValue1ClassTwoConstructer> (\"tableValue1\");\r\n\t\t\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Class.key1 + \"; tableValue1.key2 = \" + tb1Class.key2);\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Class.key3 );\r\n\t\t\r\n\t\tif (tb1Class.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Class.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Class.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Class.key2 , ref result);\r\n\t\t}\r\n\t\tif (tb1Class.key3 != true) {\r\n\t\t\tupdateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb1Class.key3 , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToClass_Step_1_4()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToClass_Step_1_4: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttry{\r\n\t\t\ttableValue1ClassException tb1Class = luaEnv.Global.Get<tableValue1ClassException> (\"tableValue1\");\r\n\t\t\tsetResult (false, \"class constructor should raise exception, but it doesnpt\", out result);\r\n\t\t} catch(Exception e){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToInterface_Step_6()\r\n\t{\r\n\r\n\t\tstring caseName = \"testGetTableToInterface_Step_6: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1InfEqual tb1Inf = luaEnv.Global.Get<tableValue1InfEqual> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Inf.key1 + \"; tableValue1.key2 = \" + tb1Inf.key2);\r\n\t\tLOG (\"tableValue1.key3 = \" + tb1Inf.key3 );\r\n\t\tLOG (\"tableValue1.tableVarInclude.ikey1 = \" + tb1Inf.tableVarInclude.ikey1 +\r\n\t\t           \"; tableValue1.tableVarInclude.ikey2 = \" + tb1Inf.tableVarInclude.ikey2);\r\n\r\n\t\tif (tb1Inf.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Inf.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Inf.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Inf.key2 , ref result);\r\n\t\t}\r\n\t\tif (tb1Inf.key3 != true) {\r\n\t\t\tupdateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb1Inf.key3 , ref result);\r\n\t\t}\r\n\t\tif (tb1Inf.tableVarInclude.ikey1 != 10) {\r\n\t\t\tupdateResult(false, \"(4).tableValue1.tableVarInclude.ikey1 should be 10, but in fact is \" + tb1Inf.tableVarInclude.ikey1 , ref result);\r\n\t\t}\r\n\t\tif (tb1Inf.tableVarInclude.ikey2 != 12) {\r\n\t\t\tupdateResult(false, \"(5).tableValue1.tableVarInclude.ikey2 should be 12, but in fact is \" + tb1Inf.tableVarInclude.ikey2, ref result);\r\n\t\t}\r\n\t\tint subResult = tb1Inf.sub (1000, 100);\r\n\t\tif (subResult != 900 ) {\r\n\t\t\tupdateResult(false, \"(6).sub result is error, 1000 - 100 =  \" + subResult , ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToInterface_Step_7()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToInterface_Step_7: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1InfLess tb1Inf = luaEnv.Global.Get<tableValue1InfLess> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + tb1Inf.key1 + \"; tableValue1.key2 = \" + tb1Inf.key2);\r\n\t\t\r\n\t\tif (tb1Inf.key1 == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb1Inf.key1 + \"\", out result);\r\n\t\t}\r\n\t\tif (tb1Inf.key2 != 10) {\r\n\t\t\tupdateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb1Inf.key2 , ref result);\r\n\t\t}\r\n\r\n\t\tint subResult = tb1Inf.sub (1000, 100);\r\n\t\tif (subResult != 900 ) {\r\n\t\t\tupdateResult(false, \"(3).sub result is error, 1000 - 100 =  \" + subResult , ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToInterface_Step_8()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToInterface_Step_8: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue1InfMore tb1Inf = luaEnv.Global.Get<tableValue1InfMore> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1InfMore.key4 = \" + tb1Inf.key4);\r\n\t\t\r\n\t\tif (tb1Inf.key4 == null){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"(1).key4 should be '' default, but int fact is : \" + tb1Inf.key4 + \"\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToInterface_Step_9()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToInterface_Step_9: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttableValue2Inf tb1Inf = luaEnv.Global.Get<tableValue2Inf> (\"tableValue2\");\r\n\t\tLOG (\"tableValue2.kv1 = \" + tb1Inf.kv1 + \"; tableValue2.kv2 = \" + tb1Inf.kv2);\r\n\t\tLOG (\"tableValue2.kv3 = \" + tb1Inf.kv3 );\r\n\r\n\t\ttb1Inf.kv1 = false;\r\n\t\ttb1Inf.kv2 = \"test\";\r\n\t\ttb1Inf.kv3 = 3;\r\n\t\ttableValue2Inf tb1Inf2 = luaEnv.Global.Get<tableValue2Inf> (\"tableValue2\");\r\n\t\tLOG (\"tableValue2.kv1 = \" + tb1Inf2.kv1 + \"; tableValue2.kv2 = \" + tb1Inf2.kv2);\r\n\t\tLOG (\"tableValue2.kv3 = \" + tb1Inf2.kv3 );\r\n\r\n\t\tif (tb1Inf2.kv1 == false && tb1Inf2.kv2 == \"test\" && tb1Inf2.kv3 == 3){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"by ref, kv1, kv2, kv3 = \" + tb1Inf2.kv1 +\r\n\t\t\t           \", \" + tb1Inf2.kv2 + \", \" + tb1Inf2.kv3, out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToInterface_Step_6_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToInterface_Step_6_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\ttry{\r\n\t\t\ttableValue1InfTypeDiff tb1Inf = luaEnv.Global.Get<tableValue1InfTypeDiff> (\"tableValue1\");\r\n\t\t\tLOG (\"tableValue1.key1 = \" + tb1Inf.key1 + \"; tableValue1.key2 = \" + tb1Inf.key2);\r\n\r\n\t\t\ttableValue1InfLess tb2Inf = luaEnv.Global.Get<tableValue1InfLess> (\"tableValue7\");\r\n\t\t\tLOG (\"tableValue1.key1 = \" + tb2Inf.key1 + \"; tableValue2.key2 = \" + tb2Inf.key2);\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\r\n\t\t} catch(Exception e){\r\n\r\n\t\t\tsetResult (false, \"class constructor should raise exception, but it doesnpt\", out result);\r\n\t\t\tLOG (e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToDic_Step_10()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToDic_Step_10: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tDictionary<string, int> dict = luaEnv.Global.Get<Dictionary<string, int>> (\"tableValue4\");\r\n\t\tLOG (\"tableValue4.k1 = \" + dict[\"k1\"] + \"; tableValue4.k2 = \" + dict[\"k2\"]);\r\n\t\tLOG (\"tableValue4.k3 = \" + dict[\"k3\"] + \"; tableValue4.k4 = \" + dict[\"k4\"]);\r\n\t\tLOG (\"tableValue4.k5 = \" + dict[\"k5\"]);\r\n\t\t\r\n\t\tif (dict[\"k1\"]  == 1 && dict[\"k2\"] == 10 && dict[\"k3\"] == 100 && dict[\"k4\"] == 1000\r\n\t\t    && dict[\"k5\"] == 10000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"tableValue4 should be k1= 1, k2= 10, k3 = 100, k4 = 1000, k5 = 10000\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToDic_Step_11_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToDic_Step_11_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tDictionary<int, string> dict = luaEnv.Global.Get<Dictionary<int, string>> (\"tableValue4\");\r\n\t\tLOG (\"dict.Count = \" + dict.Count);\r\n\t\t\r\n\t\tif (dict.Count == 0){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"dict should be {}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToDic_Step_11_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToDic_Step_11_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tDictionary<string, int> dict = luaEnv.Global.Get<Dictionary<string, int>> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + dict[\"key1\"] + \", tableValue1.key2 = \" + dict[\"key2\"]);\r\n\t\tLOG (\"dict.Count = \" + dict.Count);\r\n\r\n\t\tif (dict.Count == 2 && dict[\"key1\"] == 100000 && dict[\"key2\"] == 10){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"dict should have key1 = 100000, key2 = 10\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToDic_Step_11_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToDic_Step_11_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tDictionary<int, int> dict = luaEnv.Global.Get<Dictionary<int, int>> (\"tableValue3\");\r\n\t\tLOG (\"dict.Count = \" + dict.Count);\r\n\t\t\r\n\t\tif (dict.Count == 0){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"dict should {}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToList_Step_12()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToList_Step_12: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tList<string> listVar = luaEnv.Global.Get<List<string>> (\"tableValue3\");\r\n\t\tLOG (\"listVar = \" + listToStr(listVar));\r\n\t\t\r\n\t\tif (listVar.Count == 8){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"listVar should be {'apple', 'banana', 'orange', 'kiwi', \" +\r\n\t\t\t\t\"'grape', 'lemon', 'strawberry', 'pear'}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToList_Step_13_1_int()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToList_Step_13_1_int: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tList<int> listVar = luaEnv.Global.Get<List<int>> (\"tableValue3\");\r\n\t\tLOG (\"listVar = \" + listToString(listVar));\r\n\t\t\r\n\t\tif (listVar.Count == 0){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"listVar should be {}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToList_Step_13_1_string()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToList_Step_13_1_string: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tList<string> listVar = luaEnv.Global.Get<List<string>> (\"tableValue6\");\r\n\t\tLOG (\"listVar.count = \" + listVar.Count);\r\n\t\t\r\n\t\tif (listVar.Count == 0){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"listVar should be {}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToList_Step_13_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToList_Step_13_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tList<string> listVar = luaEnv.Global.Get<List<string>> (\"tableValue1\");\r\n\t\tLOG (\"listVar.count = \" + listVar.Count + \", listVar = \" + listToStr(listVar));\r\n\t\t\r\n\t\tif (listVar.Count == 3){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"listVar should be {'red', 'yellow', 'green''}\", out result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetTableToLuaTable_Step_14()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetTableToLuaTable_Step_14: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaTable table = luaEnv.Global.Get<LuaTable> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + table.Get<int>(\"key1\"));\r\n\t\tLOG (\"tableValue1.key2 = \" + table.Get<int>(\"key2\"));\r\n\t\tLOG (\"tableValue1.key3 = \" + table.Get<bool>(\"key3\"));\r\n\t\tLOG (\"tableValue1.1 = \" + table[1]);\r\n\t\tLOG (\"tableValue1.2 = \" + table[2]);\r\n\t\tLOG (\"tableValue1.3 = \" + table[3]);\r\n\t\tLOG (\"tableValue1.sub = \" + Convert.ToInt32(table.Get<LuaFunction>(\"sub\").Call (table, 100, 10)[0]));\r\n\r\n\t\tLOG (\"tableValue1.tableValueInclude.count = \" + table.Get<List<int>>(\"tableValueInclude\").Count);\r\n\t\tLOG (\"tableValue1.tableVarInclude.count = \" + table.Get<Dictionary<string, int>>(\"tableVarInclude\").Count);\r\n\t\tif (table.Get<int>(\"key1\") == 100000){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"tablevalue1 is error\", out result);\r\n\t\t}\r\n\r\n\t\ttable [\"key1\"] = 100;\r\n\t\tLuaTable table2 = luaEnv.Global.Get<LuaTable> (\"tableValue1\");\r\n\t\tLOG (\"tableValue1.key1 = \" + table2.Get<int>(\"key1\"));\r\n\t\tif (Convert.ToInt32(table2[\"key1\"]) != 100) {\r\n\t\t\tupdateResult(false, \"modify no change.\", ref result);\r\n\t\t}\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncSelfINcreaseDelegate delegate1 = luaEnv.Global.Get<FuncSelfINcreaseDelegate> (\"func_self_increase\");\r\n\t\tdelegate1 ();\r\n\t\tint intValue3 = luaEnv.Global.Get<int> (\"intValue3\");\r\n\t\tLOG (\"intValues = \" + intValue3);\r\n\t\tif (intValue3 == 1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"intValue3 + 1 = 1, but is \" + intValue3, out result);\r\n\t\t}\r\n\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_2_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_2_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnMultivaluesDelegate2 delegate1 = luaEnv.Global.Get<FuncReturnMultivaluesDelegate2> (\"func_return_multivalues\");\r\n\t\tstring str;\r\n\t\ttableValue4Class table;\r\n\t\tbool update;\r\n\t\tdelegate1(out update, out str, out table);\r\n\r\n\t\tLOG (\"str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table.k1 + \", k2 = \" + table.k2 + \"}\");\r\n\r\n\t\tif (update == false && str == \"false\" && table.k1 == 11 && table.k2 == 12){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be false, 'false', {k1=11, k2=12}\", out result);\r\n\t\t}\r\n\r\n\t\tFuncSelfINcreaseDelegate delegate2 = luaEnv.Global.Get<FuncSelfINcreaseDelegate> (\"func_self_increase\");\r\n\t\tdelegate2 ();\r\n\t\t// int intValue3 = luaEnv.Global.Get<int> (\"intValue3\");\r\n\t\t// intValue3 = 3;\r\n\r\n\t\tdelegate1(out update, out str, out table);\r\n\t\tLOG (\"get again, str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table.k1 + \", k2 = \" + table.k2 + \"}\");\r\n\t\tif (update != true || str != \"true\" || table.k1 != 11 || table.k2 != 12){\r\n\t\t\tupdateResult (false, \"function return error, should be true, 'true', {k1=11, k2=12}\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_2_2()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_2_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnMultivaluesDelegate1 delegate1 = luaEnv.Global.Get<FuncReturnMultivaluesDelegate1> (\"func_return_multivalues\");\r\n\t\tstring str;\r\n\t\ttableValue4Class table;\r\n\t\tbool update = delegate1(out str, out table);\r\n\r\n\t\tif (update == false && str == \"false\" && table.k1 == 11 && table.k2 == 12){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be false, 'false', {k1=11, k2=12}\", out result);\r\n\t\t}\r\n\r\n\t\tFuncSelfINcreaseDelegate delegate2 = luaEnv.Global.Get<FuncSelfINcreaseDelegate> (\"func_self_increase\");\r\n\t\tdelegate2 ();\r\n\t\tupdate = delegate1(out str, out table);\r\n\r\n\t\tLOG (\"get again, str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table.k1 + \", k2 = \" + table.k2 + \"}\");\r\n\t\tif (update != true || str != \"true\" || table.k1 != 11 || table.k2 != 12){\r\n\t\t\tupdateResult (false, \"function return error, should be true, 'true', {k1=11, k2=12}\", ref result);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_2_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_2_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnMultivaluesDelegate3 delegate1 = luaEnv.Global.Get<FuncReturnMultivaluesDelegate3> (\"func_return_multivalues\");\r\n\t\tint a;\r\n\t\tstring str;\r\n\t\ttableValue4Class table;\r\n\t\tbool update;\r\n\t\tdelegate1(out update, out str, out table, out a);\r\n\t\t\r\n\t\tLOG (\"str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table.k1 + \", k2 = \" + table.k2 + \"}\");\r\n\t\t\r\n\t\tif (update == false && str == \"false\" && table.k1 == 11 && table.k2 == 12 && a == 0){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be false, 'false', {k1=11, k2=12}\", out result);\r\n\t\t}\r\n\r\n\t\tFuncReturnMultivaluesDelegate31 delegate2 = luaEnv.Global.Get<FuncReturnMultivaluesDelegate31> (\"func_return_multivalues2\");\r\n\t\ttableValue4Class noreturn;\r\n\t\tdelegate2(out update, out str, out table, out noreturn);\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_2_4()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_2_4: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnMultivaluesDelegate4 delegate1 = luaEnv.Global.Get<FuncReturnMultivaluesDelegate4> (\"func_return_multivalues\");\r\n\t\tstring str;\r\n\t\tbool update = delegate1(out str);\r\n\t\tLOG (\"str = \" + str + \", update = \" + update);\r\n\r\n\t\tif (update == false && str == \"false\"){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be false, 'false'\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic TestResult testGetFuncToDelegate_Step_3()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tGetFuncIncreaseDelegate delegate1 = luaEnv.Global.Get<GetFuncIncreaseDelegate> (\"func_return_func\");\r\n        Action e = delegate1();\r\n\t\te ();\r\n\t\tint intValue3 = luaEnv.Global.Get<int>(\"intValue3\");\r\n\t\tif ( intValue3 == 1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"intValue3 should be 1, but is\" + intValue3, out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_5()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_5: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncMultiParamsDelegate delegate1 = luaEnv.Global.Get<FuncMultiParamsDelegate> (\"func_multi_params\");\r\n\t\tbool a = true;\r\n\t\tint b = 2;\r\n\t\tstring c = \"ABC\";\r\n\t\tint d;\r\n\t\tdelegate1(ref a, ref b, ref c, out d);\r\n\t\tLOG (\"a = \" + a + \", b = \" + b + \", c = \" + c);\r\n\t\tif (a == true && b == 3 && c == \"abc\"){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be true, 3, 'abc'\", out result);\r\n\t\t}\r\n\t\t\r\n\t\ta = false;\r\n\t\tb = 2;\r\n\t\tc = \"ABC\";\r\n\t\tdelegate1(ref a, ref b, ref c, out d);\r\n\t\tif (a != false || b != 2 || c != \"ABC\") {\r\n\t\t\tupdateResult (false, \"function return error, should be false, 2, 'ABC'\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tFuncMultiParams3Delegate2 delegate1;\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_5_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_5_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tdelegate1 = luaEnv.Global.Get<FuncMultiParams3Delegate2> (\"func_multi_params3\");\r\n\t\tbool a = true;\r\n\t\tint b = 5;\r\n\t\tint sum;\r\n\t\tdelegate1(b, out sum, ref a);\r\n\r\n\t\tLOG (\"sum = \" + sum + \", a = \" + a);\r\n\t\tif (a == true && sum == 6 ){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be sum = 6, a = true\", out result);\r\n\t\t}\r\n\r\n\t\ttry {\r\n\t\t\tFuncMultiParams3Delegate delegate2 = luaEnv.Global.Get<FuncMultiParams3Delegate> (\"func_multi_params3\");\r\n\t\t}\t\t\r\n\t\tcatch (Exception e){\r\n            updateResult(false, \"FuncMultiParams3Delegate to same function raise exception.\", ref result);\r\n\t\t\tLOG(e.Message);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_5_1_0()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_5_1_0: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncMultiParams3Delegate2 delegate1 = luaEnv.Global.Get<FuncMultiParams3Delegate2> (\"func_multi_params3\");\r\n\t\tbool a = true;\r\n\t\tint b = 5;\r\n\t\tint sum;\r\n\t\tdelegate1(b, out sum, ref a);\r\n\t\t\r\n\t\tLOG (\"sum = \" + sum + \", a = \" + a);\r\n\t\tif (a == true && sum == 6 ){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be sum = 6, a = true\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tFuncMultiParams3Delegate delegate2 = luaEnv.Global.Get<FuncMultiParams3Delegate> (\"func_multi_params4\");\r\n\t\ta = false;\r\n\t\tdelegate2(out sum, b, ref a);\r\n\t\t\r\n\t\tLOG (\"FuncMultiParams3Delegate, sum = \" + sum + \", a = \" + a);\r\n\t\t\r\n\t\tif (a != false || sum != 0) {\r\n\t\t\tupdateResult (false, \"FuncMultiParams3Delegate, should be sum = 0, a = false\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n/*\r\n\tpublic TestResult testGetFuncToDelegate_Step_5_2()\r\n\t{\r\n\r\n\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_5_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncMultiParams2Delegate delegate1 = luaEnv.Global.Get<FuncMultiParams2Delegate> (\"func_multi_params2\");\r\n\t\tbool a = true;\r\n\t\tint b = 5;\r\n\t\tint sum;\r\n\t\tAction d;\r\n\t\td = delegate1(ref a, b, out sum);\r\n\r\n\t\tLOG (\"sum = \" + sum + \", a = \" + a);\r\n\t\td();\r\n\t\tint intValue3 = luaEnv.Global.Get<int> (\"intValue3\");\r\n\r\n\t\tif (a == true && sum == 6 && intValue3 == 1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be sum = 6, a = true, intValue3 = 1\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n*/\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_6()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_6: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFucnVarParamsDelegate delegate1 = luaEnv.Global.Get<FucnVarParamsDelegate> (\"func_varparams\");\r\n\t\tint sum = delegate1(6, 4);\r\n\t\t\r\n\t\tLOG (\"sum = \" + sum );\r\n\t\t\r\n\t\tif ( sum == 10){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be sum = 10\", out result);\r\n\t\t}\r\n\r\n\t\tsum = delegate1(10, 5);\r\n\t\t\r\n\t\tLOG (\"sum = \" + sum );\r\n\t\tif (sum != 15) {\r\n\t\t\tupdateResult (false, \"more input params, should be sum = 15\", ref result);\r\n\t\t}\r\n\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic TestResult testGetFuncToLuaFunc_Step_8()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToLuaFunc_Step_8: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaFunction func1 = luaEnv.Global.Get<LuaFunction> (\"func_self_increase\");\r\n\t\tfunc1.Call ();\r\n\t\tint intValue3 = luaEnv.Global.Get<int> (\"intValue3\");\r\n\t\tLOG (\"intValues = \" + intValue3);\r\n\t\tif (intValue3 == 1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"intValue3 + 1 = 1, but is \" + intValue3, out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToLuaFunc_Step_9_1()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToLuaFunc_Step_9_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaFunction func1 = luaEnv.Global.Get<LuaFunction> (\"func_return_multivalues\");\r\n\r\n\t\tobject[] returns = func1.Call();\r\n\t\tstring str = (string)returns[1];\r\n\t\tLuaTable table = (LuaTable)returns[2];\r\n\t\tbool update = (bool)returns[0];\r\n\t\t\r\n\t\tLOG (\"str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table[\"k1\"] + \", k2 = \" + table[\"k2\"] + \"}\");\r\n\t\t\r\n\t\tif (update == false && str == \"false\" && Convert.ToInt32(table[\"k1\"]) == 11 && Convert.ToInt32(table[\"k2\"]) == 12){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be false, 'false', {k1=11, k2=12}\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tFuncSelfINcreaseDelegate delegate2 = luaEnv.Global.Get<FuncSelfINcreaseDelegate> (\"func_self_increase\");\r\n\t\tdelegate2 ();\r\n\t\t// int intValue3 = luaEnv.Global.Get<int> (\"intValue3\");\r\n\t\t// intValue3 = 3;\r\n\t\t\r\n\t\treturns = func1.Call();\r\n\t\tstr = (string)returns[1];\r\n\t\ttable = (LuaTable)returns[2];\r\n\t\tupdate = (bool)returns[0];\r\n\t\tLOG (\"get again, str = \" + str + \", update = \" + update + \", {k1 = \" + \r\n\t\t           table[\"k1\"] + \", k2 = \" + table[\"k2\"] + \"}\");\r\n\t\tif (update != true || str != \"true\" || Convert.ToInt32(table[\"k1\"]) != 11 || Convert.ToInt32(table[\"k2\"]) != 12){\r\n\t\t\tupdateResult (false, \"function return error, should be true, 'true', {k1=11, k2=12}\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToLuaFunc_Step_10()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToLuaFunc_Step_10: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaFunction func1 = luaEnv.Global.Get<LuaFunction> (\"func_return_func\");\r\n\t\tLuaFunction e = (LuaFunction)func1.Call ()[0];\r\n\t\te.Call ();\r\n\r\n\t\tint intValue3 = luaEnv.Global.Get<int>(\"intValue3\");\r\n\t\tif ( intValue3 == 1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"intValue3 should be 1, but is\" + intValue3, out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToLuaFunc_Step_12()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToLuaFunc_Step_12: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaFunction func1 = luaEnv.Global.Get<LuaFunction> (\"func_multi_params\");\r\n\t\tbool a = true;\r\n\t\tint b = 2;\r\n\t\tstring c = \"ABC\";\r\n\t\tint d;\r\n\t\tobject[] returns = func1.Call(a, b, c);\r\n\t\ta = (bool)returns [0];\r\n\t\tb = Convert.ToInt32(returns [1]);\r\n\t\tc = (string)returns [2];\r\n\t\tLOG (\"a = \" + a + \", b = \" + b + \", c = \" + c);\r\n\t\tif (a == true && b == 3 && c == \"abc\"){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"function return error, should be true, 3, 'abc'\", out result);\r\n\t\t}\r\n\t\t\r\n\t\ta = false;\r\n\t\tb = 2;\r\n\t\tc = \"ABC\";\r\n\t\treturns = func1.Call(a, b, c);\r\n\t\ta = (bool)returns [0];\r\n\t\tb = Convert.ToInt32(returns [1]);\r\n\t\tc = (string)returns [2];\r\n\t\tif (a != false || b != 2 || c != \"ABC\") {\r\n\t\t\tupdateResult (false, \"function return error, should be false, 2, 'ABC'\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\r\n\tpublic TestResult testGetFuncToLuaFunc_Step_13()\r\n\t{\r\n\t\t/*\r\n\t\t */\r\n\t\tstring caseName = \"testGetFuncToLuaFunc_Step_13: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tLuaFunction func1 = luaEnv.Global.Get<LuaFunction> (\"func_varparams\");\r\n\t\tobject[] returns = func1.Call(6, 4);\r\n\t\tint sum = Convert.ToInt32(returns [0]);\r\n\t\tLOG (\"sum = \" + sum );\r\n\t\t\r\n\t\tif ( sum == 10){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be sum = 10\", out result);\r\n\t\t}\r\n\t\t\r\n\t\treturns = func1.Call(10, 1, 4);\r\n\t\tsum = Convert.ToInt32(returns [0]);\r\n\t\tLOG (\"sum = \" + sum );\r\n\t\t\r\n\t\tLOG (\"sum = \" + sum );\r\n\t\tif (sum != 15) {\r\n\t\t\tupdateResult (false, \"more input params, should be sum = 15\", ref result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\t// 补充用例C#以返回值为object的delegate调用Lua函数，\r\n\t// (1)而在lua函数侧返回的是long，ulong，都能正确返回。\r\n\t// (2)在lua函数返回别的地方创建的userdata，比如io.open返回的文件句柄，在c#那接收到的是null\r\n\tpublic TestResult testGetFuncToDelegate_Step_7_1()\r\n\t{\r\n\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_7_1: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnObjectDelegate delegate1 = luaEnv.Global.Get<FuncReturnObjectDelegate> (\"func_return_object\");\r\n\t\tSystem.Object ret = delegate1(0);\r\n\t\t\r\n\t\tLuaTestCommon.Log (\"ret= \" + ret );\r\n\t\t\r\n\t\tif ( ret == null){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be ret = null\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_7_2()\r\n\t{\r\n\t\t\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_7_2: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnObjectDelegate delegate1 = luaEnv.Global.Get<FuncReturnObjectDelegate> (\"func_return_object\");\r\n\t\tSystem.Object ret = delegate1(1);\r\n\t\t\r\n\t\tLuaTestCommon.Log (\"ret= \" + ret );\r\n\t\t\r\n\t\tif ( Convert.ToInt64(ret)== System.Int64.MaxValue){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be ret = System.Int64.MaxValue\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic TestResult testGetFuncToDelegate_Step_7_3()\r\n\t{\r\n\t\t\r\n\t\tstring caseName = \"testGetFuncToDelegate_Step_7_3: \";\r\n\t\tLOG (\"*************\" + caseName);\r\n\t\tTestResult result;\r\n\t\t\r\n\t\tluaEnv.DoString(script);\r\n\t\t\r\n\t\tFuncReturnObjectDelegate delegate1 = luaEnv.Global.Get<FuncReturnObjectDelegate> (\"func_return_object\");\r\n\t\tSystem.Object ret = delegate1(2);\r\n\t\t\r\n\t\tLuaTestCommon.Log (\"ret= \" + ret );\r\n\t\t\r\n\t\t//if ( Convert.ToUInt64(ret) == System.UInt64.MaxValue){\r\n\t\tif ( Convert.ToInt64(ret) == -1){\r\n\t\t\tsetResult (true, \"pass\", out result);\r\n\t\t} else {\r\n\t\t\tsetResult (false, \"should be ret = System.UInt64.MaxValue\", out result);\r\n\t\t}\r\n\t\t\r\n\t\tLOG (caseName + result.ToString());\r\n\t\treturn result;\r\n\t}\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_int_1()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_int_1: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        int ret = luaEnv.Global.Get<int>(\"intValueMax\");\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == System.Int32.MaxValue)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"(1).intValueMax, is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Set(\"intValueMax\", 12345);\r\n        ret = luaEnv.Global.Get<int>(\"intValueMax\");\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 12345)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2).after set intValueMax=12345, get is \" + ret, ref result);\r\n        }\r\n        ret = 0;\r\n        luaEnv.Global.Get(\"intValueMax\", out ret);\r\n        LuaTestCommon.Log(\"out ret= \" + ret);\r\n        if (ret == 12345)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(3).after set intValueMax=12345, get is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_int_2()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_int_2: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        int ret;\r\n        luaEnv.Global.Set(123, 12345);\r\n        ret = luaEnv.Global.Get<int>(123);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 12345)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"(1).after set 123=12345, get is \" + ret,  out result);\r\n        }\r\n        ret = 0;\r\n        luaEnv.Global.Get(123, out ret);\r\n        LuaTestCommon.Log(\"out ret= \" + ret);\r\n        if (ret == 12345)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2).after set intValueMax=12345, get is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_string_1()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_string_1: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        string ret;\r\n        luaEnv.Global.Set(\"strValueChin\", \"中文字符串mix12345587\");\r\n        luaEnv.Global.Get(\"strValueChin\", out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == \"中文字符串mix12345587\")\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        \r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_sbyte()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_sbyte: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        sbyte ret;\r\n        luaEnv.Global.Set((sbyte)12, (sbyte)23);\r\n        luaEnv.Global.Get((sbyte)12, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == (sbyte)23)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"sbyteValueMin\", out ret);\r\n        if (ret == -128)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get sbyteValueMin is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_byte()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_byte: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        byte ret;\r\n        luaEnv.Global.Set((byte)255, (byte)23);\r\n        luaEnv.Global.Get((byte)255, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == (byte)23)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"byteValueMax\", out ret);\r\n        if (ret == (byte)255)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get byteValueMax is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_short()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_short: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        short ret;\r\n        luaEnv.Global.Set((short)256, (short)512);\r\n        luaEnv.Global.Get((short)256, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 512)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"shortValueMax\", out ret);\r\n        if (ret == 32767)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get shortValueMax is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_ushort()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_ushort: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        ushort ret;\r\n        luaEnv.Global.Set((ushort)1024, (ushort)32768);\r\n        luaEnv.Global.Get((ushort)1024, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 32768)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"ushortValueMax\", out ret);\r\n        if (ret == 65535)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get ushortValueMax is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_long()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_long: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        long ret;\r\n        luaEnv.Global.Set(\"test\", (long)3276800000);\r\n        luaEnv.Global.Get(\"test\", out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 3276800000)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"longValue2\", out ret);\r\n        if (ret == -42949672960)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get longValue2 is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_ulong()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_ulong: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        ulong ret;\r\n        luaEnv.Global.Set(\"test\", (ulong)42949672960);\r\n        luaEnv.Global.Get(\"test\", out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 42949672960)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"ulongValueMax\", out ret);\r\n        if (ret == 42949672961111)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get ulongValueMax is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_double()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_double: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        double ret;\r\n        luaEnv.Global.Set((double)0.0000001, (double)1.000124587);\r\n        luaEnv.Global.Get((double)0.0000001, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 1.000124587)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"doubleValue2\", out ret);\r\n        if (ret == -3.14159265)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get doubleValue2 is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_float()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_float: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        float ret;\r\n        luaEnv.Global.Set((float)3.14, (float)3.15);\r\n        luaEnv.Global.Get((float)3.14, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (System.Math.Abs(ret - 3.15) < 0.000001)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        ret = 0;\r\n        luaEnv.Global.Get(\"floatValue2\", out ret);\r\n        if (System.Math.Abs(ret + 3.14) < 0.000001)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get floatValue2 is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_char()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_char: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        char ret;\r\n        luaEnv.Global.Set('a', 'b');\r\n        luaEnv.Global.Get('a', out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == 'b')\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"charValue\", out ret);\r\n        if (ret == 'a')\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get charValue is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_BasicType_decimal()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_decimal: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        decimal key = -32132143143100109.00010001010M;\r\n        decimal value = 0.0000001M;\r\n        decimal ret;\r\n        luaEnv.Global.Set(123.01, value);\r\n        luaEnv.Global.Get(123.01, out ret);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + ret);\r\n\r\n        if (ret == value)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + ret, out result);\r\n        }\r\n        luaEnv.Global.Get(\"decValue2\", out ret);\r\n        if (ret == -12.3111111111M)\r\n        {\r\n            updateResult(true, \"pass\", ref result);\r\n        }\r\n        else\r\n        {\r\n            updateResult(false, \"(2) get decValue2 is \" + ret, ref result);\r\n        }\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_struct()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_BasicType_struct: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        TestStruct mystruct = new TestStruct(5, 6); // custom complex value type\r\n        TestStruct mystruct2;\r\n        luaEnv.Global.Set(123, mystruct);\r\n        luaEnv.Global.Get(123, out mystruct2);\r\n\r\n        LuaTestCommon.Log(\"ret= \" + mystruct2);\r\n\r\n        if (mystruct.a == mystruct2.a)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"ret is \" + mystruct2.a, out result);\r\n        }\r\n \r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_class()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_class: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        tableValue1ClassPrivate tb1Class = luaEnv.Global.Get<tableValue1ClassPrivate>(\"tableValue1\");\r\n        tableValue1ClassPrivate tb2Class;\r\n        luaEnv.Global.Set(tb1Class.key1, tb1Class);\r\n        luaEnv.Global.Get(tb1Class.key1, out tb2Class);\r\n        LOG(\"tableValue1.key1 = \" + tb2Class.key1 + \"; tableValue1.key2 = \" + tb2Class.Get());\r\n        LOG(\"tableValue1.key3 = \" + tb2Class.key3);\r\n\r\n        if (tb2Class.key1 == 100000)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb2Class.key1 + \"\", out result);\r\n        }\r\n        if (tb2Class.Get() != 0)\r\n        {\r\n            updateResult(false, \"(2).private key2 should be 0, but int fact is \" + tb2Class.Get(), ref result);\r\n        }\r\n        if (tb2Class.key3 != true)\r\n        {\r\n            updateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb2Class.key3, ref result);\r\n        }\r\n\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_interface()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_interface: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        tableValue1InfEqual tb1Inf = luaEnv.Global.Get<tableValue1InfEqual>(\"tableValue1\");\r\n        tb1Inf.key3 = false;\r\n        tableValue1InfEqual tb2Inf;\r\n        LOG(\"tableValue1.key1 = \" + tb1Inf.key1 + \"; tableValue1.key2 = \" + tb1Inf.key2);\r\n        LOG(\"tableValue1.key3 = \" + tb1Inf.key3);\r\n        LOG(\"tableValue1.tableVarInclude.ikey1 = \" + tb1Inf.tableVarInclude.ikey1 +\r\n                   \"; tableValue1.tableVarInclude.ikey2 = \" + tb1Inf.tableVarInclude.ikey2);\r\n\r\n        luaEnv.Global.Set(\"tableValue1\", tb1Inf);\r\n        luaEnv.Global.Get(\"tableValue1\", out tb2Inf);\r\n\r\n        if (tb2Inf.key1 == 100000)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"(1).tableValue1.key1 should be 100000, but int fact is : \" + tb2Inf.key1 + \"\", out result);\r\n        }\r\n        if (tb2Inf.key2 != 10)\r\n        {\r\n            updateResult(false, \"(2).tableValue1.key2 should be 10, but in fact is \" + tb2Inf.key2, ref result);\r\n        }\r\n        if (tb2Inf.key3 != false)\r\n        {\r\n            updateResult(false, \"(3).tableValue1.key3 should be true, but in fact is \" + tb2Inf.key3, ref result);\r\n        }\r\n        if (tb2Inf.tableVarInclude.ikey1 != 10)\r\n        {\r\n            updateResult(false, \"(4).tableValue1.tableVarInclude.ikey1 should be 10, but in fact is \" + tb2Inf.tableVarInclude.ikey1, ref result);\r\n        }\r\n        if (tb2Inf.tableVarInclude.ikey2 != 12)\r\n        {\r\n            updateResult(false, \"(5).tableValue1.tableVarInclude.ikey2 should be 12, but in fact is \" + tb2Inf.tableVarInclude.ikey2, ref result);\r\n        }\r\n        int subResult = tb2Inf.sub(1000, 100);\r\n        if (subResult != 900)\r\n        {\r\n            updateResult(false, \"(6).sub result is error, 1000 - 100 =  \" + subResult, ref result);\r\n        }\r\n\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n    public TestResult testLuaTableGetSetKeyValue_dict()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_dict: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        Dictionary<string, int> dict = luaEnv.Global.Get<Dictionary<string, int>>(\"tableValue1\");\r\n        Dictionary<string, int> dict2;\r\n\r\n        LOG(\"tableValue1.key1 = \" + dict[\"key1\"] + \", tableValue1.key2 = \" + dict[\"key2\"]);\r\n        LOG(\"dict.Count = \" + dict.Count);\r\n\r\n        luaEnv.Global.Set(\"tableValue1\", dict);\r\n        luaEnv.Global.Get(\"tableValue1\", out dict2);\r\n\r\n        LOG(\"tableValue1.key1 = \" + dict2[\"key1\"] + \", tableValue1.key2 = \" + dict2[\"key2\"]);\r\n        LOG(\"dict.Count = \" + dict2.Count);\r\n\r\n        if (dict2.Count == 2 && dict2[\"key1\"] == 100000 && dict2[\"key2\"] == 10)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"dict should have key1 = 100000, key2 = 10\", out result);\r\n        }\r\n\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_list()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_list: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        List<string> listVar = luaEnv.Global.Get<List<string>>(\"tableValue3\");\r\n        List<string> listVar2;\r\n        LOG(\"listVar = \" + listToStr(listVar));\r\n        listVar[0] = \"test\";\r\n        luaEnv.Global.Set(\"tableValue3\", listVar);\r\n        luaEnv.Global.Get(\"tableValue3\", out listVar2);\r\n\r\n        if (listVar2.Count == 8)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"listVar2 should be {'test', 'banana', 'orange', 'kiwi', \" +\r\n                \"'grape', 'lemon', 'strawberry', 'pear'}\", out result);\r\n        }\r\n\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n    public TestResult testLuaTableGetSetKeyValue_delegate()\r\n    {\r\n\r\n        string caseName = \"testLuaTableGetSetKeyValue_delegate: \";\r\n        LOG(\"*************\" + caseName);\r\n        TestResult result;\r\n\r\n        luaEnv.DoString(script);\r\n\r\n        FuncSelfINcreaseDelegate delegate1 = luaEnv.Global.Get<FuncSelfINcreaseDelegate>(\"func_self_increase\");\r\n        FuncSelfINcreaseDelegate delegate2;\r\n\r\n        luaEnv.Global.Set(\"test_delegate\", delegate1);\r\n        luaEnv.Global.Get(\"test_delegate\", out delegate2);\r\n        delegate2();\r\n        int intValue3 = luaEnv.Global.Get<int>(\"intValue3\");\r\n\r\n        LOG(\"intValues = \" + intValue3);\r\n        if (intValue3 == 1)\r\n        {\r\n            setResult(true, \"pass\", out result);\r\n        }\r\n        else\r\n        {\r\n            setResult(false, \"intValue3 + 1 = 1, but is \" + intValue3, out result);\r\n        }\r\n\r\n        LOG(caseName + result.ToString());\r\n        return result;\r\n    }\r\n\r\n}\r\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/TCForTestCSCallLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 76dffed6dedc93a4a93f70367637ac20\ntimeCreated: 1483528414\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/TestCSCallLua.cs",
    "content": "﻿#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\n\r\npublic class TestCSCallLua\r\n#if !XLUA_GENERAL\r\n    : MonoBehaviour\r\n#endif\r\n{\r\n    // Use this for initialization\r\n    void Start()\r\n    {\r\n\t\tTCForTestCSCallLua testSuite = new TCForTestCSCallLua();\r\n\t\ttestSuite.testDoString2LoadLua_Step_1();\r\n\t\ttestSuite.testDoString2LoadLua_Step_2 ();\r\n\t\ttestSuite.testDoString2LoadLua_Step_3 ();\r\n\t\ttestSuite.testRequire2LoadLua_Step_1_3 ();\r\n\t\ttestSuite.testRequire2LoadLua_Step_4 ();\r\n\t\ttestSuite.testRequire2LoadLua_Step_5 ();\r\n\t\ttestSuite.testRequire2LoadLua_Step_6 ();\r\n\t\ttestSuite.testRequire2LoadLua_Step_7 ();\r\n\t\ttestSuite.testAddLoader2LoadLua_Step_1_2 ();\r\n\t\ttestSuite.testAddLoader2LoadLua_Step_3 ();\r\n\t\ttestSuite.testAddLoader2LoadLua_Step_6 ();\r\n\t\ttestSuite.testAddLoader2LoadLua_Step_7 ();\r\n\t\ttestSuite.testGetBasicDataTypeBool_Step_1 ();\r\n\t\ttestSuite.testGetBasicDataTypeString_Step_2 ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToByte ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToSByte ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToShort ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToUShort ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToInt ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToUInt ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToLong ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToULong ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToDouble ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToChar ();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToFloat();\r\n\t\ttestSuite.testGetBasicDataTypeNumberToDecimal ();\r\n\t\ttestSuite.testGetBasicDataType_Step_4 ();\r\n\t\ttestSuite.testGetBasicDataType_Step_5 ();\r\n\t\ttestSuite.testGetTableToClass_Step_1 ();\r\n\t\ttestSuite.testGetTableToClass_Step_2 ();\r\n\t\ttestSuite.testGetTableToClass_Step_3 ();\r\n\t\ttestSuite.testGetTableToClass_Step_4 ();\r\n\t\ttestSuite.testGetTableToClass_Step_5 ();\r\n\t\ttestSuite.testGetTableToClass_Step_1_1 ();\r\n\t\ttestSuite.testGetTableToClass_Step_1_3 ();\r\n\t\ttestSuite.testGetTableToClass_Step_1_4 ();\r\n\t\ttestSuite.testGetTableToInterface_Step_6 ();\r\n\t\ttestSuite.testGetTableToInterface_Step_7 ();\r\n\t\ttestSuite.testGetTableToInterface_Step_8 ();\r\n\t\ttestSuite.testGetTableToInterface_Step_9 ();\r\n\t\ttestSuite.testGetTableToInterface_Step_6_1 ();\r\n\t\ttestSuite.testGetTableToDic_Step_10 ();\r\n\t\ttestSuite.testGetTableToDic_Step_11_1 ();\r\n\t\ttestSuite.testGetTableToDic_Step_11_2 ();\r\n\t\ttestSuite.testGetTableToDic_Step_11_3 ();\r\n\t\ttestSuite.testGetTableToList_Step_12 ();\r\n\t\ttestSuite.testGetTableToList_Step_13_1_int ();\r\n\t\ttestSuite.testGetTableToList_Step_13_1_string ();\r\n\t\ttestSuite.testGetTableToList_Step_13_2 ();\r\n\t\ttestSuite.testGetTableToLuaTable_Step_14 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_1 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_2_1 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_2_2 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_2_3 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_2_4 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_3 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_5 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_5_1 ();\r\n\t\ttestSuite.testGetFuncToDelegate_Step_5_1_0 ();\r\n\t\t//testSuite.testGetFuncToDelegate_Step_5_2 (); // 在ios il2cpp上运行错误，注释掉\r\n\t\ttestSuite.testGetFuncToDelegate_Step_6 ();\r\n\t\ttestSuite.testGetFuncToLuaFunc_Step_8 ();\r\n\t\ttestSuite.testGetFuncToLuaFunc_Step_9_1 ();\r\n\t\ttestSuite.testGetFuncToLuaFunc_Step_10 ();\r\n\t\ttestSuite.testGetFuncToLuaFunc_Step_12 ();\r\n\t\ttestSuite.testGetFuncToLuaFunc_Step_13 ();\r\n    }\r\n\r\n    // Update is called once per frame\r\n    void Update()\r\n    {\r\n\t\tif (TCForTestCSCallLua.luaEnv != null)\r\n        {\r\n\t\t\tTCForTestCSCallLua.luaEnv.GC();\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/TestCSCallLua.cs.meta",
    "content": "fileFormatVersion: 2\nguid: cba25057ebcf1d54c9ad49fde9b6e62d\ntimeCreated: 1483527551\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua/TestCSCallLua.unity.meta",
    "content": "fileFormatVersion: 2\nguid: 545aff291ef305c42b613b7085779131\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/CSharpCallLua.meta",
    "content": "fileFormatVersion: 2\nguid: d3e28212fb5931d44bc37dcd4fd0127f\nfolderAsset: yes\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaCallCS/CSObjectForLuaCallCS.cs",
    "content": "﻿#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing XLua;\r\nusing System;\r\nusing System.IO;\r\n\r\n[LuaCallCSharp]\r\npublic class NoContClass{\r\n\tpublic int key1;\r\n\tpublic int key2;\r\n\tpublic bool key3;\r\n\tpublic int add (int a, int b)\r\n\t{\r\n\t\treturn a + b;\r\n\t}\r\n\tpublic static int d;\r\n\tpublic static int dec(int a, int b)\r\n\t{\r\n\t\treturn a - b;\r\n\t}\r\n}\r\n\r\nnamespace testLuaCallCS\r\n{\r\n\t[LuaCallCSharp]\r\n\tpublic class OneParamContClass{\r\n\t\tpublic int key1;\r\n\t\tpublic int key2;\r\n\t\tpublic bool key3;\r\n\t\tpublic int add (int a, int b)\r\n\t\t{\r\n\t\t\treturn a + b;\r\n\t\t}\r\n\t\tpublic OneParamContClass(int a)\r\n\t\t{\r\n\t\t\tkey1 = a;\r\n\t\t\tkey2 = 1;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class MultiContClass{\r\n\t\tpublic int key1;\r\n\t\tpublic int key2;\r\n\t\tpublic bool key3;\r\n\t\tpublic int add (int a, int b)\r\n\t\t{\r\n\t\t\treturn a + b;\r\n\t\t}\r\n\t\tpublic MultiContClass()\r\n\t\t{\r\n\t\t\tkey1 = 1;\r\n\t\t\tkey2 = 1;\r\n\t\t}\r\n\t\t\r\n\t\tpublic MultiContClass(int a)\r\n\t\t{\r\n\t\t\tkey1 = a;\r\n\t\t\tkey2 = 1;\r\n\t\t}\r\n\t\tpublic static int d;\r\n\t\tpublic static int dec(int a, int b)\r\n\t\t{\r\n\t\t\treturn a - b;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class TwoParamsContClass{\r\n\t\tpublic int key1;\r\n\t\tpublic int key2;\r\n\t\tpublic bool key3;\r\n\t\tpublic int add (int a, int b)\r\n\t\t{\r\n\t\t\treturn a + b;\r\n\t\t}\r\n\t\tpublic TwoParamsContClass(int a, int b)\r\n\t\t{\r\n\t\t\tkey1 = a;\r\n\t\t\tkey2 = b;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class OverClassA : MultiContClass\r\n\t{\r\n\t\tpublic int key3;\r\n\t\tpublic int sub(int a, int b)\r\n\t\t{\r\n\t\t\treturn a - b;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class OverClassB : MultiContClass\r\n\t{\r\n\t\tpublic int key4;\r\n\t\tpublic int sub(int a, int b)\r\n\t\t{\r\n\t\t\treturn a - b;\r\n\t\t}\r\n\t\tpublic static bool bValue;\r\n\t\tpublic static void Set(bool flag)\r\n\t\t{\r\n\t\t\tbValue = flag;\r\n\t\t}\r\n\r\n\t\tprotected internal int sum(int a, int b, int c)\r\n\t\t{\r\n\t\t\treturn a + b + c;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class OverClassC : OverClassB\r\n\t{\r\n\t\tpublic int key5;\r\n\t\tpublic int div(int a, int b)\r\n\t\t{\r\n\t\t\tif (b != 0) {\r\n\t\t\t\treturn a / b;\r\n\t\t\t} else {\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic int sub(int a, int b)\r\n\t\t{\r\n\t\t\treturn a - b + 1;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class NoGenOverClassA : MultiContClass\r\n\t{\r\n\t\tpublic int key4;\r\n\t\tpublic int sub(int a, int b)\r\n\t\t{\r\n\t\t\treturn a - b;\r\n\t\t}\r\n\t\tpublic static bool bValue;\r\n\t\tpublic static void Set(bool flag)\r\n\t\t{\r\n\t\t\tbValue = flag;\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class OverClassCDeriveNGA : NoGenOverClassA\r\n\t{\r\n\t\tpublic int key5;\r\n\t\tpublic int div(int a, int b)\r\n\t\t{\r\n\t\t\tif (b != 0) {\r\n\t\t\t\treturn a / b;\r\n\t\t\t} else {\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic abstract class abstractFatherClass\r\n\t{\r\n\t\tpublic abstract int add(int a, int b);\r\n\t\tpublic int a;\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic class ChildCalss:abstractFatherClass\r\n\t{\r\n\t\tpublic override int add(int a, int b)\r\n\t\t{\r\n\t\t\treturn a + b;\r\n\t\t}\r\n\t\tpublic void setA( int value)\r\n\t\t{\r\n\t\t\ta = value;\r\n\t\t}\r\n\t\tpublic int getA()\r\n\t\t{\r\n\t\t\treturn a;\r\n\t\t}\r\n\t}\r\n\t\r\n\t[LuaCallCSharp]\r\n\tpublic static class StaticTestClass\r\n\t{\r\n\t\tpublic static int n = 0;\r\n\t\t\r\n\t\tpublic static void Add()\r\n\t\t{\r\n\t\t\tn++;\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaCallCS/CSObjectForLuaCallCS.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 5cfcc83451afbc44da0435dfaf0f3a8e\ntimeCreated: 1483527547\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaCallCS.meta",
    "content": "fileFormatVersion: 2\nguid: c1cb3557274d1344983c4ef8c8cda643\nfolderAsset: yes\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestCommon.cs",
    "content": "using XLua;\r\n#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\n\r\nusing System.Collections.Generic;\r\nusing System;\r\npublic class LuaEnvSingleton  {\r\n\t\r\n\tstatic private LuaEnv instance = null;\r\n\tstatic public LuaEnv Instance\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif(instance == null)\r\n\t\t\t{\r\n\t\t\t\tinstance = new LuaEnv();\r\n#if XLUA_GENERAL\r\n                instance.DoString(\"package.path = package.path..';../Test/UnitTest/xLuaTest/CSharpCallLua/Resources/?.lua.txt;../Test/UnitTest/StreamingAssets/?.lua'\");\r\n#endif\r\n            }\r\n\r\n            return instance;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class LuaTestCommon\r\n{\r\n#if     UNITY_IOS || UNITY_IPHONE\r\n    public static string resultPath = Application.persistentDataPath + \"/\";\r\n\tpublic static string xxxtdrfilepath = Application.dataPath + \"/Raw\" + \"/testxxx.tdr\";\r\n\tpublic static string xxxtdr2filepath = Application.dataPath + \"/Raw\" + \"/testxxx2.tdr\";\r\n\tpublic static bool android_platform = false;\r\n#elif   UNITY_ANDROID\r\n    public static string resultPath = \"/sdcard/luatest/\";\r\n\tpublic static string xxxtdrfilepath = Application.streamingAssetsPath + \"/testxxx.tdr\";\r\n\tpublic static string xxxtdr2filepath = Application.streamingAssetsPath + \"/testxxx2.tdr\";\r\n\tpublic static bool android_platform = true;\r\n#elif   UNITY_EDITOR || UNITY_WSA\r\n    public static string resultPath = Application.dataPath + \"/xLuaTest/\";\r\n\tpublic static string xxxtdrfilepath = Application.dataPath + \"/StreamingAssets\" + \"/testxxx.tdr\";\r\n\tpublic static string xxxtdr2filepath = Application.dataPath + \"/StreamingAssets\" + \"/testxxx2.tdr\";\r\n\tpublic static bool android_platform = false;\r\n#elif XLUA_GENERAL\r\n    public static string resultPath = \".\";\r\n    public static bool android_platform = false;\r\n    public static string xxxtdrfilepath = \"../Test/UnitTest/StreamingAssets\" + \"/testxxx.tdr\";\r\n#endif\r\n\r\n    public static bool IsXLuaGeneral()\r\n    {\r\n#if XLUA_GENERAL\r\n        return true;\r\n#else\r\n        return false;\r\n#endif\r\n    }\r\n\r\n    public static bool IsMacPlatform()\r\n\t{\r\n#if UNITY_EDITOR\r\n        string os = System.Environment.OSVersion.ToString();\r\n        if (os.Contains(\"Unix\"))\r\n        {\r\n            return true;\r\n        }\r\n        else\r\n        {\r\n            return false;\r\n        }\r\n#else\r\n        return false;\r\n#endif\r\n\t}\r\n\r\n\tpublic static bool IsIOSPlatform()\r\n\t{\r\n#if UNITY_IOS || UNITY_IPHONE\r\n\t\treturn true;\r\n#else\r\n\t\treturn false;\r\n#endif\r\n\t}\r\n\r\n    public static void Log(string str)\r\n    {\r\n#if XLUA_GENERAL\r\n        System.Console.WriteLine(str);\r\n#else\r\n        UnityEngine.Debug.Log(str);\r\n#endif\r\n    }\r\n}\r\n\r\n#if !XLUA_GENERAL\r\n//注意：用户自己代码不建议在这里配置，建议通过标签来声明!!\r\npublic class TestCaseGenConfig\r\n{\r\n\r\n    //lua中要使用到C#库的配置，比如C#标准库，或者Unity API，第三方库等。\r\n    [LuaCallCSharp]\r\n    public List<Type> LuaCallCSharp\r\n    {\r\n        get\r\n        {\r\n            return new List<Type>()\r\n            {\r\n                typeof(UnityEngine.TextAsset),\r\n            };\r\n        }\r\n    }\r\n}\r\n#endif\r\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestCommon.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 7c683d1a1acf2cd47aa488b3dbd06aca\ntimeCreated: 1483528414\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestObj.cs",
    "content": "using XLua;\r\nusing System;\r\n#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\n\r\n[LuaCallCSharp]\r\npublic class LongStatic\r\n{\r\n    public static long LONG_MAX = System.Int64.MaxValue;\r\n    public static ulong ULONG_MAX = System.UInt64.MaxValue;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic enum LuaTestType\r\n{\r\n\tABC = 0,\r\n\tDEF,\r\n\tGHI,\r\n\tJKL\r\n};\r\n\r\n[LuaCallCSharp]\r\npublic enum FirstPushEnum\r\n{\r\n\tE1\r\n};\r\n\r\n[CSharpCallLua]\r\npublic delegate int TestDelegate(int x);\r\n[CSharpCallLua]\r\npublic delegate int TestEvtHandler1(float y);\r\n[CSharpCallLua]\r\npublic delegate int TestEvtHandler2(byte y, float z);\r\n\r\n[LuaCallCSharp]\r\npublic class LuaTestObj\r\n{\r\n\tpublic static LuaEnv luaEnv = LuaEnvSingletonForTest.Instance;\r\n    public int testVar { get; set; }\r\n    public int[] testArr = new int[3];\r\n    public static LuaTestObj operator + (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar + b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator +(LuaTestObj a, int b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar + b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator +(int a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a + b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator - (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar - b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator -(LuaTestObj a, int b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar - b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator -(int a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a - b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator * (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar * b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator *(LuaTestObj a, int b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar * b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator *(int a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a * b.testVar;\r\n        return ret;\r\n    }\r\n\r\n\r\n    public static LuaTestObj operator /(LuaTestObj a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar / b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator /(LuaTestObj a, int b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar / b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator /(int a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a / b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator % (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar % b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator %(int a, LuaTestObj b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a % b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator %(LuaTestObj a, int b)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar % b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObj operator - (LuaTestObj a)\r\n    {\r\n        LuaTestObj ret = new LuaTestObj();\r\n        ret.testVar = a.testVar * (-1);\r\n        return ret;\r\n    }\r\n\r\n    public static bool operator < (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        return (a.testVar < b.testVar);\r\n    }\r\n\r\n\r\n    public static bool operator <= (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        return (a.testVar <= b.testVar);\r\n    }\r\n\r\n\r\n\r\n    public static bool operator > (LuaTestObj a, LuaTestObj b)\r\n    {\r\n        return (a.testVar > b.testVar);\r\n    }\r\n\r\n\r\n\r\n    public static bool operator >=(LuaTestObj a, LuaTestObj b)\r\n    {\r\n        return (a.testVar >= b.testVar);\r\n    }\r\n\r\n   \r\n\r\n    public int this[int i]\r\n    {\r\n        get\r\n        {\r\n            return testArr[i];\r\n        }\r\n        set\r\n        {\r\n            testArr[i] = value;\r\n        }\r\n    }  \r\n\r\n    \r\n    public event TestEvtHandler1 TestEvent1;\r\n    public event TestEvtHandler2 TestEvent2;\r\n\r\n\tpublic static event TestEvtHandler1 TestStaticEvent1;\r\n\r\n    public int CallEvent(float y)\r\n    {\r\n        return TestEvent1(y);\r\n    }\r\n\r\n\tpublic static int CallStaticEvent(float y)\r\n\t{\r\n\t\treturn TestStaticEvent1(y);\r\n\t}\r\n\r\n\tpublic static int DefaultParaFuncSingle(int i, string str = \"abc\")\r\n\t{\r\n\t\treturn i;\r\n\t}\r\n\r\n\tpublic static int DefaultParaFuncMulti(int i, string str = \"abc\", double d = 0, byte c = 97)\r\n\t{\r\n\t\treturn (i + 1);\r\n\t}\r\n\r\n\tpublic static int VariableParamFunc(int i, params string[] strs)\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static int VariableParamFunc2(params int[] strs)\r\n    {\r\n        return strs.Length;\r\n    }\r\n\t\r\n\tpublic static int TestEnumFunc(LuaTestType x)\r\n\t{\r\n\t\treturn (int)x;\r\n\t}\r\n\r\n\tpublic static string TestGetType(Type x)\r\n\t{\r\n\t\treturn x.ToString ();\r\n\t}\r\n\r\n\tpublic static ulong ulX1 = 1;\r\n\tpublic static ulong ulX2 = 1;\r\n\tpublic static long lY1 = 1;\r\n\tpublic static long lY2 = 1;\r\n\tpublic static Int64 i64Z1 = 1;\r\n\tpublic static Int64 i64Z2 = 1;\r\n\tpublic static long lY3 = 1;\r\n\tpublic static long lY4 = 123;\r\n\tpublic static long lY5 = 12345;\r\n\tpublic static long lY6 = 54321;\r\n\r\n\tpublic static void Gen64BitInt()\r\n\t{\r\n\t\tulX1 = ulX2 = 1;\r\n\t\tlY1 = lY2 = lY3 = 1;\r\n\t\ti64Z1 = i64Z2 = 1;\r\n\t\tulX1 = ulX1 << 62;\r\n\t\tulX2 = ulX2 << 61;\r\n\t\tlY1 = lY1 << 62;\r\n\t\tlY2 = lY2 << 61;\r\n\t\ti64Z1 = i64Z1 << 62;\r\n\t\ti64Z2 = i64Z2 << 61;\r\n\t\tlY3 = lY3 << 50;\r\n\r\n\t}\r\n\r\n\tpublic static ITestLuaClass CreateTestLuaObj()\r\n\t{\r\n\t\treturn new TestLuaClass ();\r\n\t}\r\n\r\n    public static TestDelegate csDelegate;\r\n    public static TestDelegate csDelegate1;\r\n    public static TestDelegate csDelegate2;\r\n    public static TestDelegate csDelegate3;\r\n    public static TestDelegate csDelegate4;\r\n\r\n    public static TestDelegate csDelegate11;\r\n    public static TestDelegate csDelegate12;\r\n    public static TestDelegate csDelegate13;\r\n\r\n\tpublic static int initNumber = 5;\r\n\r\n\tpublic static int CalcAdd(int x)\r\n\t{\r\n\t\tinitNumber += x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int calcadd(int x)\r\n\t{\r\n\t\tinitNumber += x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int CalcDel(int x)\r\n\t{\r\n\t\tinitNumber -= x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int CalcMul(int x)\r\n\t{\r\n\t\tinitNumber *= x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static void GenDelegate()\r\n\t{\r\n        csDelegate1 = new TestDelegate(CalcAdd);\r\n        csDelegate2 = new TestDelegate(CalcDel);\r\n        csDelegate3 = new TestDelegate(CalcMul);\r\n\t}\r\n\r\n\r\n    public static int OverLoad1(int x, int y)\r\n    {\r\n        return 1;\r\n    }\r\n\r\n    public static int OverLoad1(int x)\r\n    {\r\n        return 2;\r\n    }\r\n\r\n\tpublic static int OverLoad1(params int[] vars)\r\n\t{\r\n\t\tint ret = 0;\r\n\t\tforeach (int var in vars) \r\n\t\t{ \r\n\t\t\tret += var; \r\n\t\t} \r\n\t\treturn ret;\r\n\t}\r\n\t\r\n\tpublic static int OverLoad2(int x, float y)\r\n    {\r\n        return 3;\r\n    }\r\n\r\n    public static int OverLoad2(string x, string y)\r\n    {\r\n        return 4;\r\n    }\r\n\r\n    public static int OverLoad3(int x)\r\n    {\r\n        return 5;\r\n    }\r\n\r\n    public static int OverLoad3(short y)\r\n    {\r\n        return 6;\r\n    }\r\n\r\n\r\n    public static void OutRefFunc1(int x, out int y, ref int z)\r\n    {\r\n        y = 100;\r\n    }\r\n\r\n    public static void OutRefFunc2(ref int x, int y, out int z)\r\n    {\r\n        z = 200;\r\n    }\r\n\r\n    public static void OutRefFunc3(int x, out int y, ref int z)\r\n    {\r\n        y = 300;\r\n    }\r\n\r\n    public static int OutRefFunc4(int x, out int y, ref int z)\r\n    {\r\n        y = 400;\r\n        return y;\r\n    }\r\n\r\n    public static int OutRefFunc5(ref int x, int y, out int z)\r\n    {\r\n        z = 500;\r\n        return z;\r\n    }\r\n\r\n    public static int OutRefFunc6(int x, int y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n    public static void OutRefFunc11(ITestLuaClass x, out ITestLuaClass y, ref ITestLuaClass z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 100;\r\n    }\r\n\r\n    public static void OutRefFunc12(ref ITestLuaClass x, ITestLuaClass y, out ITestLuaClass z)\r\n    {\r\n        z = CreateTestLuaObj();\r\n        z.cmpTarget = 200;\r\n    }\r\n\r\n    public static void OutRefFunc13(ITestLuaClass x, out ITestLuaClass y, ref ITestLuaClass z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 300;\r\n    }\r\n\r\n    public static int OutRefFunc14(ITestLuaClass x, out ITestLuaClass y, ref ITestLuaClass z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 400;\r\n        return y.cmpTarget;\r\n    }\r\n\r\n    public static int OutRefFunc15(ref ITestLuaClass x, ITestLuaClass y, out ITestLuaClass z)\r\n    {\r\n        z = CreateTestLuaObj();\r\n        z.cmpTarget = 500;\r\n        return z.cmpTarget;\r\n    }\r\n\r\n    public static int OutRefFunc16(ITestLuaClass x, ITestLuaClass y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n    public static void OutRefFunc21(TestDelegate x, out TestDelegate y, ref TestDelegate z)\r\n    {\r\n        y = new TestDelegate(CalcAdd);\r\n    }\r\n\r\n    public static void OutRefFunc22(ref TestDelegate x, TestDelegate y, out TestDelegate z)\r\n    {\r\n        z = new TestDelegate(CalcAdd);\r\n    }\r\n\r\n    public static void OutRefFunc23(TestDelegate x, out TestDelegate y, ref TestDelegate z)\r\n    {\r\n        y = new TestDelegate(CalcAdd);\r\n    }\r\n\r\n    public static int OutRefFunc24(TestDelegate x, out TestDelegate y, ref TestDelegate z)\r\n    {\r\n        y = new TestDelegate(CalcAdd);\r\n        return y(1);\r\n    }\r\n\r\n    public static int OutRefFunc25(ref TestDelegate x, TestDelegate y, out TestDelegate z)\r\n    {\r\n        z = new TestDelegate(CalcAdd);\r\n        return z(1);\r\n    }\r\n\r\n    public static int OutRefFunc26(TestDelegate x, TestDelegate y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n\tpublic int Sum(int a, int b, int c)\r\n\t{\r\n\t\treturn a + b + c;\r\n\t}\r\n\r\n\tpublic static int Sum(int a, int b)\r\n\t{\r\n\t\treturn a + b;\r\n\t}\r\n\r\n\tpublic void GenericMethod<T>()\r\n\t{\r\n\t\tLuaTestCommon.Log(\"GenericMethod<\" + typeof(T) +\">\");\r\n\t}\r\n\r\n    public IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(100);\r\n\r\n    public IntPtr GetPtr()\r\n    {\r\n        byte[] abc = new byte[] { 97, 98, 99 };\r\n        System.Runtime.InteropServices.Marshal.Copy(abc, 0, ptr, abc.Length);\r\n        return ptr;\r\n    }\r\n\r\n    public byte PrintPtr(IntPtr p)\r\n    {\r\n        LuaTestCommon.Log(\"p == ptr?\" + (p == ptr));\r\n        byte[] abc = new byte[] { 0, 0, 0 };\r\n        System.Runtime.InteropServices.Marshal.Copy(p, abc, 0, abc.Length);\r\n        LuaTestCommon.Log(string.Format(\"{0},{1},{2}\", abc[0], abc[1], abc[2]));\r\n        return abc[0];\r\n    }\r\n\r\n    public int VariableParamFuncDefault(int d, int i = 1, params string[] strs)\r\n    {\r\n        return i + d;\r\n    }\r\n\r\n    public static double StaticVariableParamFuncDefault(double d, double i = 1.0, params string[] strs)\r\n    {\r\n        return i + d;\r\n    }\r\n\t\r\n\tpublic static byte[] FuncReturnByteArray()\r\n\t{\r\n\t\tbyte[] abc = new byte[] { 97, 98, 99 };\r\n\t\treturn abc;\r\n\t}\r\n\r\n    public static byte FuncReturnByte()\r\n    {\r\n        byte abc = 97;\r\n        return abc;\r\n    }\r\n\t\r\n\tpublic static int[] FuncReturnIntArray()\r\n\t{\r\n\t\tint[] abc = new int[] { 97, 98, 99 };\r\n\t\treturn abc;\r\n\t}\r\n\r\n    public static int FuncReturnInt()\r\n    {\r\n        int abc = 97;\r\n        return abc;\r\n    }\r\n\r\n#if !XLUA_GENERAL\r\n    public static LayerMask TestImplicit()\r\n    {\r\n        return new LayerMask();\r\n    }\r\n#endif\r\n\r\n    public static int VariableParamFunc(int i, params int[] strs)\r\n    {\r\n        return 0;\r\n    }\r\n\t\r\n\tpublic static string FirstPushEnumFunc(int i)\r\n\t{\r\n        string luaScript = @\"\r\n        function first_push(t,obj)\r\n\t        if t==1 then\r\n\t\t        if obj == CS.FirstPushEnum.E1 then\r\n\t\t\t        return 1\r\n\t\t        else\r\n\t\t\t        return 2\r\n\t\t        end\r\n\t        elseif t==2 then\r\n\t\t        if obj == CS.FirstPushEnum.self then\r\n\t\t\t        return 3\r\n\t\t        else\r\n\t\t\t        return 4\r\n\t\t        end\r\n\t        else\r\n\t\t        return 5\r\n\t        end\r\n        end\";\r\n        luaEnv.DoString(luaScript);\r\n\t\tLuaFunction f1 = luaEnv.Global.Get<LuaFunction>(\"first_push\");\r\n        LuaTestCommon.Log(\"LuaFunction<\" + f1);\r\n        object[] ret = f1.Call(i, FirstPushEnum.E1);\r\n        return ret[0].ToString();\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class TestCastClass\r\n{\r\n\tpublic bool TestFunc1()\r\n\t{\r\n\t\treturn true;\r\n\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic interface ITestLuaClass\r\n{\r\n\tbool TestFunc1();\r\n    int cmpTarget{ set; get; }\r\n}\r\n\r\ninternal class TestLuaClass : ITestLuaClass\r\n{\r\n\tpublic bool TestFunc1()\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n    public int cmpTarget { set; get; }\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class  TestChineseString\r\n{\r\n\r\n\tpublic string GetShortChinString()\r\n\t{\r\n\t\treturn short_simple_string;\r\n\t}\r\n\r\n\tpublic string GetLongChineString()\r\n\t{\r\n\t\treturn long_simple_string;\r\n\t}\r\n\r\n\tpublic string GetCombineString()\r\n\t{\r\n\t\treturn combine_string;\r\n\t}\r\n\r\n\tpublic string GetComplexString()\r\n\t{\r\n\t\treturn complex_string;\r\n\t}\r\n\r\n\tpublic string GetHuoxingString()\r\n\t{\r\n\t\treturn huoxing_string;\r\n\t}\r\n\r\n\tpublic string short_simple_string = \"中文字符串\";\r\n\tpublic string long_simple_string = \"为Unity3D增加Lua脚本编程的能力，进而提供代码逻辑增量更新的可能，支持lua的所有基本类型，哈哈哈哈\";\r\n\tpublic string combine_string = \"中文字符串.* ? [ ] ^ $~`!@#$%^&()_-+=[];',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣12345abc\";\r\n\tpublic string complex_string = \"繁體國陸\";\r\n\tpublic string huoxing_string = \"吙煋呅僦媞這樣孒\";\r\n}\r\n\r\npublic class TestUlongAndLongType\r\n{\r\n\tpublic ulong UlongMax\r\n\t{\r\n\r\n\t\tget { return ulong_max; }\r\n\t\tset { ulong_max=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongMin\r\n\t{\r\n\t\t\r\n\t\tget { return ulong_min; }\r\n\t\tset { ulong_min=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongMid\r\n\t{\r\n\t\t\r\n\t\tget { return ulong_mid; }\r\n\t\tset { ulong_mid=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongAdd()\r\n\t{\r\n\t\treturn ulong_max - 1000 + 1;\r\n\t}\r\n\r\n\tpublic long LongMax\r\n\t{\r\n\t\t\r\n\t\tget { return long_max; }\r\n\t\tset { long_max=value; }\r\n\t}\r\n\t\r\n\tpublic long LongMin\r\n\t{\r\n\t\t\r\n\t\tget { return long_min; }\r\n\t\tset { long_min=value; }\r\n\t}\r\n\t\r\n\tpublic long LongMid\r\n\t{\r\n\t\t\r\n\t\tget { return long_mid; }\r\n\t\tset { long_mid=value; }\r\n\t}\r\n\r\n\tpublic long LongAdd()\r\n\t{\r\n\t\treturn long_max - 1000 + 1;\r\n\t}\r\n\r\n\tulong ulong_max = System.UInt64.MaxValue;\r\n\tulong ulong_min = System.UInt64.MinValue;\r\n\tulong ulong_mid = 9223372036854775808;\r\n\tlong long_max = System.Int64.MaxValue;\r\n\tlong long_min = System.Int64.MinValue;\r\n\tlong long_mid = 4611686018427387904;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic struct Employeestruct\r\n{\r\n\tprivate string name;\r\n\tpublic string Name\r\n\t{\r\n\t\tget { return name; }\r\n\t\tset { name = value; }\r\n\t}\r\n\t\r\n\tprivate int age;\r\n\tpublic int Age\r\n\t{\r\n\t\tget { return age; }\r\n\t\tset { age = value; }\r\n\t}\r\n\t\r\n\tprivate int salary;\r\n\tprivate int annual_bonus;\r\n\r\n\tpublic int Salary\r\n\t{\r\n\t\tget { return salary; }\r\n\t\tset { salary = value; }\r\n\t}\r\n\r\n\tpublic int AnnualBonus\r\n\t{\r\n\t\tget { return annual_bonus; }\r\n\t\tset { annual_bonus = value; }\r\n\t}\r\n\r\n}\r\n\r\n\r\npublic struct ConStruct{\r\n\tpublic int x;\r\n\tpublic int y;\r\n\tpublic string z;\r\n\tpublic ConStruct(int x, int y, string z)\r\n\t{\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t\tthis.z = z;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct StaticPusherStructA\r\n{\r\n\tpublic byte byteVar;\r\n\tpublic sbyte sbyteVar;\r\n\tpublic StaticPusherStructA(byte a, sbyte b)\r\n\t{\r\n\t\tthis.byteVar = a;\r\n\t\tthis.sbyteVar = b;\r\n\t}\r\n}\r\n\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct StaticPusherStructB\r\n{\r\n\tpublic short shortVar;\r\n\tpublic ushort ushortVar;\r\n\tpublic int intVar;\r\n\tpublic uint uintVar;\r\n\tpublic StaticPusherStructB(short a, ushort b, int c, uint d)\r\n\t{\r\n\t\tthis.shortVar = a;\r\n\t\tthis.ushortVar = b;\r\n\t\tthis.intVar = c;\r\n\t\tthis.uintVar = d;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct StaticPusherStructAll\r\n{\r\n\tpublic long longVar;\r\n\tpublic ulong ulongVar;\r\n\tpublic float floatVar;\r\n\tpublic double doubleVar;\r\n\tpublic StaticPusherStructA structA;\r\n\tpublic StaticPusherStructB structB;\r\n}\r\n\r\npublic interface ITest\r\n{\r\n\tint Add(int x,int y);\r\n}\r\n\r\npublic struct NoGenCodeStruct:ITest{\r\n\r\n\tprivate byte byte_var;\r\n\tprivate short short_var;\r\n\tprivate ushort ushort_var;\r\n\tprivate int int_var1;\r\n\tprivate int int_var2;\r\n\tprivate uint uint_var;\r\n\tprivate long long_var;\r\n\tprivate ulong ulong_var;\r\n\tprivate double double_var;\r\n\tprivate float float_var;\r\n\tprivate char char_var;\r\n\tprivate decimal decimal_var;\r\n\tprivate string string_var;\r\n\r\n\tpublic byte Byte\r\n\t{\r\n\t\tget { return byte_var; }\r\n\t\tset { byte_var = value; }\r\n\t}\r\n\r\n\tpublic short Short\r\n\t{\r\n\t\tget { return short_var; }\r\n\t\tset { short_var = value; }\r\n\t}\r\n\r\n\tpublic ushort UShort\r\n\t{\r\n\t\tget { return ushort_var; }\r\n\t\tset { ushort_var = value; }\r\n\t}\r\n\r\n\tpublic int IntVar1\r\n\t{\r\n\t\tget { return int_var1; }\r\n\t\tset { int_var1 = value; }\r\n\t}\r\n\r\n\tpublic int IntVar2\r\n\t{\r\n\t\tget { return int_var2; }\r\n\t\tset { int_var2 = value; }\r\n\t}\r\n\r\n\tpublic uint UInt\r\n\t{\r\n\t\tget { return uint_var; }\r\n\t\tset { uint_var = value; }\r\n\t}\r\n\r\n\tpublic long Long\r\n\t{\r\n\t\tget { return long_var; }\r\n\t\tset { long_var = value; }\r\n\t}\r\n\r\n\tpublic ulong ULong\r\n\t{\r\n\t\tget { return ulong_var; }\r\n\t\tset { ulong_var = value; }\r\n\t}\r\n\r\n\tpublic double Double\r\n\t{\r\n\t\tget { return double_var; }\r\n\t\tset { double_var = value; }\r\n\t}\r\n\r\n\tpublic float Float\r\n\t{\r\n\t\tget { return float_var; }\r\n\t\tset { float_var = value; }\r\n\t}\r\n\r\n\tpublic char Char\r\n\t{\r\n\t\tget { return char_var; }\r\n\t\tset { char_var = value; }\r\n\t}\r\n\t\r\n\tpublic decimal Decimal\r\n\t{\r\n\t\tget { return decimal_var; }\r\n\t\tset { decimal_var = value; }\r\n\t}\r\n\t\r\n\tpublic string String\r\n\t{\r\n\t\tget { return string_var; }\r\n\t\tset { string_var = value; }\r\n\t}\r\n\r\n\tpublic int Add(int x, int y)\r\n\t{\r\n\t\treturn x + y;\r\n\t}\r\n\r\n\tprivate ConStruct con;\r\n\r\n\tpublic ConStruct IncludeStruct\r\n\t{\r\n\t\tget { return con; }\r\n\t\tset { con = value; }\r\n\t}\r\n}\r\n\r\npublic class NoGenCodeBaseClass\r\n{\r\n\tpublic NoGenCodeStruct InitStruct(out int add){\r\n\t\tstruct_var.Byte = 10;\r\n\t\tstruct_var.Char = 'a';\r\n\t\tstruct_var.Decimal = 12.33333333m;\r\n\t\tstruct_var.Double = 10.111111111111;\r\n\t\tstruct_var.Float = 11.1234f;\r\n\t\tstruct_var.IntVar1 = 12345678;\r\n\t\tstruct_var.IntVar2 = -12345678;\r\n\t\tstruct_var.Long = System.Int64.MaxValue;\r\n\t\tstruct_var.ULong = System.UInt64.MaxValue;\r\n\t\tstruct_var.Short = 123;\r\n\t\tstruct_var.String = \"just for test\";\r\n\t\tstruct_var.UInt = 12345;\r\n\t\tstruct_var.UShort = 255;\r\n\t\tstruct_var.IncludeStruct = new ConStruct (1, 2, \"haha\");\r\n\t\tadd = struct_var.Add (struct_var.IntVar1, struct_var.IntVar2);\r\n\t\treturn struct_var;\r\n\t}\r\n\r\n\tpublic void SetStruct(ref NoGenCodeStruct var, out NoGenCodeStruct value)\r\n\t{\r\n\t\tstruct_var.Byte = var.Byte;\r\n\t\tstruct_var.Char = var.Char;\r\n\t\tstruct_var.Decimal = var.Decimal;\r\n\t\tstruct_var.Double = var.Double;\r\n\t\tstruct_var.Float = var.Float;\r\n\t\tstruct_var.IntVar1 = var.IntVar1;\r\n\t\tstruct_var.IntVar2 = var.IntVar2;\r\n\t\tstruct_var.Long = var.Long;\r\n\t\tstruct_var.ULong = var.ULong;\r\n\t\tstruct_var.Short = var.Short;\r\n\t\tstruct_var.String = var.String;\r\n\t\tstruct_var.UInt = var.UInt;\r\n\t\tstruct_var.UShort = var.UShort;\r\n\t\tstruct_var.IncludeStruct = new ConStruct(var.IncludeStruct.x, var.IncludeStruct.y, var.IncludeStruct.z);\r\n\t\tvalue = struct_var;\r\n\t}\r\n\r\n\tpublic NoGenCodeStruct GetStruct(){\r\n\t\treturn struct_var;\r\n\t}\r\n\r\n\tpublic void SetStruct(GenCodeStruct var, out int add, out NoGenCodeStruct value)\r\n\t{\r\n\t\tstruct_var.Byte = var.Byte;\r\n\t\tstruct_var.Char = var.Char;\r\n\t\tstruct_var.Decimal = var.Decimal;\r\n\t\tstruct_var.Double = var.Double;\r\n\t\tstruct_var.Float = var.Float;\r\n\t\tstruct_var.IntVar1 = var.IntVar1;\r\n\t\tstruct_var.IntVar2 = var.IntVar2;\r\n\t\tstruct_var.Long = var.Long;\r\n\t\tstruct_var.ULong = var.ULong;\r\n\t\tstruct_var.Short = var.Short;\r\n\t\tstruct_var.String = var.String;\r\n\t\tstruct_var.UInt = var.UInt;\r\n\t\tstruct_var.UShort = var.UShort;\r\n\t\tstruct_var.IncludeStruct = new ConStruct(var.IncludeStruct.x, var.IncludeStruct.y, var.IncludeStruct.z);\r\n\t\tadd = struct_var.Add (var.IntVar1, var.IntVar2);\r\n\t\tvalue = struct_var;\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Byte:\" + struct_var.Byte);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Char:\" + struct_var.Char);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Decimal:\" + struct_var.Decimal);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Double:\" + struct_var.Double);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Float:\" + struct_var.Float);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct IntVar1:\" + struct_var.IntVar1);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct IntVar2:\" + struct_var.IntVar2);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Long:\" + struct_var.Long);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct ULong:\" + struct_var.ULong);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct Short:\" + struct_var.Short);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct String:\" + struct_var.String);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct UInt:\" + struct_var.UInt);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct UShort:\" + struct_var.UShort);\r\n\t\tLuaTestCommon.Log (\"NoGenCodeStruct IncludeStruct.x:\" + struct_var.IncludeStruct.x + \", IncludeStruct.y:\" \r\n\t\t           + struct_var.IncludeStruct.y + \", IncludeStruct.z:\" + struct_var.IncludeStruct.z);\r\n\t}\r\n\r\n\tpublic static NoGenCodeStruct GetStaticVar()\r\n\t{\r\n\t\tLuaTestCommon.Log (\"static struct byte:\" + struct_var1.Byte);\r\n\t\treturn struct_var1;\r\n\t}\r\n\r\n\tpublic void SetStaticPusherStruct(StaticPusherStructAll inVar, ref StaticPusherStructAll refVar, out StaticPusherStructAll outVar)\r\n\t{\r\n\t\tstatic_pushstruct_var.longVar = inVar.longVar + refVar.longVar;\r\n\t\tstatic_pushstruct_var.ulongVar = inVar.ulongVar + refVar.ulongVar;\r\n\t\tstatic_pushstruct_var.floatVar = inVar.floatVar + refVar.floatVar;\r\n\t\tstatic_pushstruct_var.doubleVar = inVar.doubleVar + refVar.doubleVar;\r\n\t\tstatic_pushstruct_var.structA.byteVar = 10;\r\n\t\tstatic_pushstruct_var.structA.sbyteVar = 100;\r\n\t\tstatic_pushstruct_var.structB.intVar = inVar.structB.intVar + refVar.structB.intVar;\r\n\t\tstatic_pushstruct_var.structB.uintVar = inVar.structB.uintVar + refVar.structB.uintVar;\r\n\t\tstatic_pushstruct_var.structB.shortVar = refVar.structB.shortVar;\r\n\t\tstatic_pushstruct_var.structB.ushortVar = inVar.structB.ushortVar;\r\n\t\toutVar = static_pushstruct_var;\r\n\t\trefVar.longVar = refVar.longVar - 1;\r\n\t\trefVar.ulongVar = refVar.ulongVar - 1;\r\n\t\trefVar.floatVar = refVar.floatVar - 1.0f;\r\n\t\trefVar.doubleVar = refVar.doubleVar - 1.0;\r\n\t\trefVar.structA.byteVar = 98;\r\n\t\trefVar.structA.sbyteVar = 101;\r\n\t\trefVar.structB.intVar = refVar.structB.intVar + 1;\r\n\t\trefVar.structB.uintVar = refVar.structB.uintVar + 1;\r\n\t\trefVar.structB.shortVar = inVar.structB.shortVar;\r\n\t\trefVar.structB.ushortVar = inVar.structB.ushortVar;\r\n\t}\r\n\r\n\tprivate NoGenCodeStruct struct_var;\r\n\tpublic static NoGenCodeStruct struct_var1;\r\n\tpublic static ConStruct struct_var2 = new ConStruct (3, 4, \"enen\");\r\n\tpublic static int GBS = 1;\r\n\tpublic StaticPusherStructAll static_pushstruct_var;\r\n}\r\n\r\npublic class NoGenCodeDrivedClass:NoGenCodeBaseClass\r\n{\r\n\tpublic ConStruct SimpleConStruct\r\n\t{\r\n\t\tget { return simple_struct; }\r\n\t\tset { simple_struct = value; }\r\n\t}\r\n\r\n\tpublic int Add(int x, int y)\r\n\t{\r\n\t\treturn x + y;\r\n\t}\r\n\r\n\tpublic void Add(ConStruct invar, ref ConStruct refvar, out ConStruct outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x + refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t}\r\n\r\n\tprivate ConStruct simple_struct;\r\n}\r\n\r\n\r\n[LuaCallCSharp]\r\npublic struct HasConstructStruct{\r\n\tpublic int x;\r\n\tpublic int y;\r\n\tpublic string z;\r\n\tpublic HasConstructStruct(int x, int y, string z)\r\n\t{\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t\tthis.z = z;\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic interface IGenCodeTest\r\n{\r\n\tint Add(int x,int y);\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic struct GenCodeStruct:IGenCodeTest{\r\n\t\r\n\tprivate byte byte_var;\r\n\tprivate short short_var;\r\n\tprivate ushort ushort_var;\r\n\tprivate int int_var1;\r\n\tprivate int int_var2;\r\n\tprivate uint uint_var;\r\n\tprivate long long_var;\r\n\tprivate ulong ulong_var;\r\n\tprivate double double_var;\r\n\tprivate float float_var;\r\n\tprivate char char_var;\r\n\tprivate decimal decimal_var;\r\n\tprivate string string_var;\r\n\t\r\n\tpublic byte Byte\r\n\t{\r\n\t\tget { return byte_var; }\r\n\t\tset { byte_var = value; }\r\n\t}\r\n\t\r\n\tpublic short Short\r\n\t{\r\n\t\tget { return short_var; }\r\n\t\tset { short_var = value; }\r\n\t}\r\n\t\r\n\tpublic ushort UShort\r\n\t{\r\n\t\tget { return ushort_var; }\r\n\t\tset { ushort_var = value; }\r\n\t}\r\n\t\r\n\tpublic int IntVar1\r\n\t{\r\n\t\tget { return int_var1; }\r\n\t\tset { int_var1 = value; }\r\n\t}\r\n\t\r\n\tpublic int IntVar2\r\n\t{\r\n\t\tget { return int_var2; }\r\n\t\tset { int_var2 = value; }\r\n\t}\r\n\t\r\n\tpublic uint UInt\r\n\t{\r\n\t\tget { return uint_var; }\r\n\t\tset { uint_var = value; }\r\n\t}\r\n\t\r\n\tpublic long Long\r\n\t{\r\n\t\tget { return long_var; }\r\n\t\tset { long_var = value; }\r\n\t}\r\n\t\r\n\tpublic ulong ULong\r\n\t{\r\n\t\tget { return ulong_var; }\r\n\t\tset { ulong_var = value; }\r\n\t}\r\n\t\r\n\tpublic double Double\r\n\t{\r\n\t\tget { return double_var; }\r\n\t\tset { double_var = value; }\r\n\t}\r\n\t\r\n\tpublic float Float\r\n\t{\r\n\t\tget { return float_var; }\r\n\t\tset { float_var = value; }\r\n\t}\r\n\t\r\n\tpublic char Char\r\n\t{\r\n\t\tget { return char_var; }\r\n\t\tset { char_var = value; }\r\n\t}\r\n\t\r\n\tpublic decimal Decimal\r\n\t{\r\n\t\tget { return decimal_var; }\r\n\t\tset { decimal_var = value; }\r\n\t}\r\n\t\r\n\tpublic string String\r\n\t{\r\n\t\tget { return string_var; }\r\n\t\tset { string_var = value; }\r\n\t}\r\n\t\r\n\tpublic int Add(int x, int y)\r\n\t{\r\n\t\treturn x + y;\r\n\t}\r\n\t\r\n\tprivate HasConstructStruct con;\r\n\t\r\n\tpublic HasConstructStruct IncludeStruct\r\n\t{\r\n\t\tget { return con; }\r\n\t\tset { con = value; }\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class GenCodeBaseClass\r\n{\r\n\tpublic GenCodeStruct InitStruct(out int add){\r\n\t\tstruct_var.Byte = 100;\r\n\t\tstruct_var.Char = 'b';\r\n\t\tstruct_var.Decimal = 22.33333333m;\r\n\t\tstruct_var.Double = 20.111111111111;\r\n\t\tstruct_var.Float = 21.1234f;\r\n\t\tstruct_var.IntVar1 = 22345678;\r\n\t\tstruct_var.IntVar2 = -22345678;\r\n\t\tstruct_var.Long = System.Int64.MinValue;\r\n\t\tstruct_var.ULong = System.UInt64.MinValue;\r\n\t\tstruct_var.Short = 223;\r\n\t\tstruct_var.String = \"2just for test\";\r\n\t\tstruct_var.UInt = 22345;\r\n\t\tstruct_var.UShort = 128;\r\n\t\tstruct_var.IncludeStruct = new HasConstructStruct (2, 2, \"2haha\");\r\n\t\tadd = struct_var.Add (struct_var.IntVar1, struct_var.IntVar2);\r\n\t\treturn struct_var;\r\n\t}\r\n\r\n\tpublic void SetStruct(ref GenCodeStruct var, out GenCodeStruct value)\r\n\t{\r\n\t\tstruct_var.Byte = var.Byte;\r\n\t\tstruct_var.Char = var.Char;\r\n\t\tstruct_var.Decimal = var.Decimal;\r\n\t\tstruct_var.Double = var.Double;\r\n\t\tstruct_var.Float = var.Float;\r\n\t\tstruct_var.IntVar1 = var.IntVar1;\r\n\t\tstruct_var.IntVar2 = var.IntVar2;\r\n\t\tstruct_var.Long = var.Long;\r\n\t\tstruct_var.ULong = var.ULong;\r\n\t\tstruct_var.Short = var.Short;\r\n\t\tstruct_var.String = var.String;\r\n\t\tstruct_var.UInt = var.UInt;\r\n\t\tstruct_var.UShort = var.UShort;\r\n\t\tstruct_var.IncludeStruct = new HasConstructStruct(var.IncludeStruct.x, var.IncludeStruct.y, var.IncludeStruct.z);\r\n\t\tvalue = struct_var;\r\n\t}\r\n\t\r\n\tpublic GenCodeStruct GetStruct(){\r\n\t\treturn struct_var;\r\n\t}\r\n\t\r\n\tpublic void SetStruct(NoGenCodeStruct var, out int add, out GenCodeStruct value)\r\n\t{\r\n\t\tstruct_var.Byte = var.Byte;\r\n\t\tstruct_var.Char = var.Char;\r\n\t\tstruct_var.Decimal = var.Decimal;\r\n\t\tstruct_var.Double = var.Double;\r\n\t\tstruct_var.Float = var.Float;\r\n\t\tstruct_var.IntVar1 = var.IntVar1;\r\n\t\tstruct_var.IntVar2 = var.IntVar2;\r\n\t\tstruct_var.Long = var.Long;\r\n\t\tstruct_var.ULong = var.ULong;\r\n\t\tstruct_var.Short = var.Short;\r\n\t\tstruct_var.String = var.String;\r\n\t\tstruct_var.UInt = var.UInt;\r\n\t\tstruct_var.UShort = var.UShort;\r\n\t\tstruct_var.IncludeStruct = new HasConstructStruct(var.IncludeStruct.x, var.IncludeStruct.y, var.IncludeStruct.z);\r\n\t\tadd = struct_var.Add (var.IntVar1, var.IntVar2);\r\n\t\tvalue = struct_var;\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Byte:\" + struct_var.Byte);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Char:\" + struct_var.Char);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Decimal:\" + struct_var.Decimal);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Double:\" + struct_var.Double);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Float:\" + struct_var.Float);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct IntVar1:\" + struct_var.IntVar1);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct IntVar2:\" + struct_var.IntVar2);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Long:\" + struct_var.Long);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct ULong:\" + struct_var.ULong);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct Short:\" + struct_var.Short);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct String:\" + struct_var.String);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct UInt:\" + struct_var.UInt);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct UShort:\" + struct_var.UShort);\r\n\t\tLuaTestCommon.Log (\"GenCodeStruct IncludeStruct.x:\" + struct_var.IncludeStruct.x + \", IncludeStruct.y:\" \r\n\t\t           + struct_var.IncludeStruct.y + \", IncludeStruct.z:\" + struct_var.IncludeStruct.z);\r\n\t}\r\n\r\n    public void SetStaticPusherStruct(StaticPusherStructAll inVar, ref StaticPusherStructAll refVar, out StaticPusherStructAll outVar)\r\n    {\r\n        static_pushstruct_var.longVar = inVar.longVar + refVar.longVar;\r\n        static_pushstruct_var.ulongVar = inVar.ulongVar + refVar.ulongVar;\r\n        static_pushstruct_var.floatVar = inVar.floatVar + refVar.floatVar;\r\n        static_pushstruct_var.doubleVar = inVar.doubleVar + refVar.doubleVar;\r\n        static_pushstruct_var.structA.byteVar = 97;\r\n        static_pushstruct_var.structA.sbyteVar = 100;\r\n        static_pushstruct_var.structB.intVar = inVar.structB.intVar + refVar.structB.intVar;\r\n        static_pushstruct_var.structB.uintVar = inVar.structB.uintVar + refVar.structB.uintVar;\r\n        static_pushstruct_var.structB.shortVar = refVar.structB.shortVar;\r\n        static_pushstruct_var.structB.ushortVar = inVar.structB.ushortVar;\r\n        outVar = static_pushstruct_var;\r\n        refVar.longVar = refVar.longVar - 1;\r\n        refVar.ulongVar = refVar.ulongVar - 1;\r\n        refVar.floatVar = refVar.floatVar - 1.0f;\r\n        refVar.doubleVar = refVar.doubleVar - 1.0;\r\n        refVar.structA.byteVar = 98;\r\n        refVar.structA.sbyteVar = 101;\r\n        refVar.structB.intVar = refVar.structB.intVar + 1;\r\n        refVar.structB.uintVar = refVar.structB.uintVar + 1;\r\n        refVar.structB.shortVar = inVar.structB.shortVar;\r\n        refVar.structB.ushortVar = inVar.structB.ushortVar;\r\n    }\r\n\t\r\n\tprivate GenCodeStruct struct_var;\r\n    public StaticPusherStructAll static_pushstruct_var;\r\n\tpublic static GenCodeStruct struct_var1;\r\n\tpublic static HasConstructStruct struct_var2 = new HasConstructStruct (4, 5, \"enen\");\r\n\tpublic static int GBS = 1;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class GenCodeDrivedClass:GenCodeBaseClass\r\n{\r\n\tpublic HasConstructStruct SimpleConStruct\r\n\t{\r\n\t\tget { return simple_struct; }\r\n\t\tset { simple_struct = value; }\r\n\t}\r\n\t\r\n\tpublic int Add(int x, int y)\r\n\t{\r\n\t\treturn x + y;\r\n\t}\r\n\t\r\n\tpublic void Add(HasConstructStruct invar, ref HasConstructStruct refvar, out HasConstructStruct outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x + refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t}\r\n\t\r\n\tprivate HasConstructStruct simple_struct;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class CClass\r\n{\r\n\tpublic CClass(int x, int y, string z)\r\n\t{\r\n\t\tc_struct = new HasConstructStruct(x, y, z);\r\n\t}\r\n\r\n\tpublic HasConstructStruct CConStruct\r\n\t{\r\n\t\tget { return c_struct; }\r\n\t\tset { c_struct = value; }\r\n\t}\r\n\t\r\n\tpublic void Add(HasConstructStruct invar, ref HasConstructStruct refvar, out HasConstructStruct outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x + refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t}\r\n\r\n\tpublic int VariableParamFunc(params HasConstructStruct[] structs)\r\n\t{\r\n\t\tint ret = 0;\r\n\t\tforeach (HasConstructStruct var in structs) \r\n\t\t{ \r\n\t\t\tret += var.x; \r\n\t\t} \r\n\t\treturn ret;\r\n\t}\r\n\t\r\n\tprivate HasConstructStruct c_struct;\r\n}\r\n\r\npublic class BClass:CClass\r\n{\r\n\tpublic BClass(int x, int y, string z):base(x, y, z)\r\n\t{\r\n\t\tb_struct = new HasConstructStruct(x, y, z);\r\n\t}\r\n\r\n\tpublic HasConstructStruct BConStruct\r\n\t{\r\n\t\tget { return b_struct; }\r\n\t\tset { b_struct = value; }\r\n\t}\r\n\t\r\n\tpublic void Sub(HasConstructStruct invar, ref HasConstructStruct refvar, out HasConstructStruct outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x - refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t\tLuaTestCommon.Log (\"refvar.x:\" + refvar.x + \",refvar.y:\" + refvar.y + \", refvar.z:\" + refvar.z);\r\n\t}\r\n\t\r\n\tprivate HasConstructStruct b_struct;\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class AClass:BClass\r\n{\r\n\tpublic AClass(int x, int y , string z):base(x, y, z)\r\n\t{\r\n\t\tLuaTestCommon.Log (\"AClass Constructor\");\r\n\t}\r\n\r\n    public int Div(int x, int y)\r\n    {\r\n\t\tif (y == 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse \r\n\t\t{\r\n\t\t\treturn x / y;\r\n\t\t}\r\n\t}\r\n}\r\n\r\npublic struct NoGen2FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic NoGen2FloatStruct(float a, float b)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t}\r\n}\r\n\r\npublic struct NoGen3FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic NoGen3FloatStruct(float a, float b, float c)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t}\r\n}\r\n\r\npublic struct NoGen4FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic NoGen4FloatStruct(float a, float b, float c, float d)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t}\r\n}\r\n\r\npublic struct NoGen5FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic float e;\r\n\tpublic NoGen5FloatStruct(float a, float b, float c, float d, float e)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t\tthis.e = e;\r\n\t}\r\n}\r\n\r\npublic struct NoGen6FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic float e;\r\n\tpublic float f;\r\n\tpublic NoGen6FloatStruct(float a, float b, float c, float d, float e, float f)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t\tthis.e = e;\r\n\t\tthis.f = f;\r\n\t}\r\n}\r\n\r\npublic class TestNoGenFloatStructClass {\r\n\r\n\tpublic NoGen2FloatStruct Struct2{\r\n\t\tset { struct_2 = value; }\r\n\t\tget { return struct_2; }\r\n\t}\r\n\r\n\tpublic NoGen3FloatStruct Struct3{\r\n\t\tset { struct_3 = value; }\r\n\t\tget { return struct_3; }\r\n\t}\r\n\r\n\tpublic NoGen4FloatStruct Struct4{\r\n\t\tset { struct_4 = value; }\r\n\t\tget { return struct_4; }\r\n\t}\r\n\r\n\tpublic NoGen5FloatStruct Struct5{\r\n\t\tset { struct_5 = value; }\r\n\t\tget { return struct_5; }\r\n\t}\r\n\r\n\tpublic NoGen6FloatStruct Struct6{\r\n\t\tset { struct_6 = value; }\r\n\t\tget { return struct_6; }\r\n\t}\r\n\r\n\tpublic void Add2(ref NoGen2FloatStruct x, ref Gen2FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a + y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t}\r\n\r\n\tpublic void Sub3(ref NoGen3FloatStruct x, ref Gen3FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a - y.a;\r\n\t\tx.b = x.b - y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.a = x.c;\r\n\t}\r\n\r\n\tpublic void Multiply4(ref NoGen4FloatStruct x, ref Gen4FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d * y.d;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t}\r\n\r\n\tpublic void All5(ref NoGen5FloatStruct x, ref Gen5FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d / y.d;\r\n\t\tx.e = y.e + x.e;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t\ty.e = x.e;\r\n\t}\r\n\r\n\tpublic void All6(ref NoGen6FloatStruct x, ref Gen6FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d / y.d;\r\n\t\tx.e = y.e + x.e;\r\n\t\tx.f = x.f - y.f;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t\ty.e = x.e;\r\n\t\ty.f = x.f;\r\n\t}\r\n\r\n\tprivate NoGen2FloatStruct struct_2;\r\n\tprivate NoGen3FloatStruct struct_3;\r\n\tprivate NoGen4FloatStruct struct_4;\r\n\tprivate NoGen5FloatStruct struct_5;\r\n\tprivate NoGen6FloatStruct struct_6; \r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct Gen2FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic Gen2FloatStruct(float a, float b)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct Gen3FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic Gen3FloatStruct(float a, float b, float c)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct Gen4FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic Gen4FloatStruct(float a, float b, float c, float d)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct Gen5FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic float e;\r\n\tpublic Gen5FloatStruct(float a, float b, float c, float d, float e)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t\tthis.e = e;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct Gen6FloatStruct{\r\n\tpublic float a;\r\n\tpublic float b;\r\n\tpublic float c;\r\n\tpublic float d;\r\n\tpublic float e;\r\n\tpublic float f;\r\n\tpublic Gen6FloatStruct(float a, float b, float c, float d, float e, float f)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t\tthis.c = c;\r\n\t\tthis.d = d;\r\n\t\tthis.e = e;\r\n\t\tthis.f = f;\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class TestGenFloatStructClass {\r\n\t\r\n\tpublic Gen2FloatStruct Struct2{\r\n\t\tset { struct_2 = value; }\r\n\t\tget { return struct_2; }\r\n\t}\r\n\t\r\n\tpublic Gen3FloatStruct Struct3{\r\n\t\tset { struct_3 = value; }\r\n\t\tget { return struct_3; }\r\n\t}\r\n\t\r\n\tpublic Gen4FloatStruct Struct4{\r\n\t\tset { struct_4 = value; }\r\n\t\tget { return struct_4; }\r\n\t}\r\n\t\r\n\tpublic Gen5FloatStruct Struct5{\r\n\t\tset { struct_5 = value; }\r\n\t\tget { return struct_5; }\r\n\t}\r\n\t\r\n\tpublic Gen6FloatStruct Struct6{\r\n\t\tset { struct_6 = value; }\r\n\t\tget { return struct_6; }\r\n\t}\r\n\t\r\n\tpublic void Add2(ref NoGen2FloatStruct x, ref Gen2FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a + y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t}\r\n\t\r\n\tpublic void Sub3(ref NoGen3FloatStruct x, ref Gen3FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a - y.a;\r\n\t\tx.b = x.b - y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.a = x.c;\r\n\t}\r\n\t\r\n\tpublic void Multiply4(ref NoGen4FloatStruct x, ref Gen4FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d * y.d;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t}\r\n\t\r\n\tpublic void All5(ref NoGen5FloatStruct x, ref Gen5FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d / y.d;\r\n\t\tx.e = y.e + x.e;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t\ty.e = x.e;\r\n\t}\r\n\t\r\n\tpublic void All6(ref NoGen6FloatStruct x, ref Gen6FloatStruct y)\r\n\t{\r\n\t\tx.a = x.a * y.a;\r\n\t\tx.b = x.b + y.b;\r\n\t\tx.c = x.c - y.c;\r\n\t\tx.d = x.d / y.d;\r\n\t\tx.e = y.e + x.e;\r\n\t\tx.f = x.f - y.f;\r\n\t\ty.a = x.a;\r\n\t\ty.b = x.b;\r\n\t\ty.c = x.c;\r\n\t\ty.d = x.d;\r\n\t\ty.e = x.e;\r\n\t\ty.f = x.f;\r\n\t}\r\n\t\r\n\tprivate Gen2FloatStruct struct_2;\r\n\tprivate Gen3FloatStruct struct_3;\r\n\tprivate Gen4FloatStruct struct_4;\r\n\tprivate Gen5FloatStruct struct_5;\r\n\tprivate Gen6FloatStruct struct_6; \r\n}\r\n\r\npublic struct NoGen2IntStruct{\r\n\tpublic int a;\r\n\tpublic int b;\r\n\tpublic NoGen2IntStruct(int a, int b)\r\n\t{\r\n\t\tthis.a = a;\r\n\t\tthis.b = b;\r\n\t}\r\n}\r\n[CSharpCallLua]\r\npublic delegate int TestReflectEvtHandler1(float y);\r\npublic class TestReflectEventClass{\r\n\r\n\tpublic event TestReflectEvtHandler1 TestEvent1;\r\n\t\r\n\tpublic int CallEvent(float y)\r\n\t{\r\n\t\treturn TestEvent1(y);\r\n\t}\r\n}\r\n\r\nnamespace TestExtensionMethod\r\n{\r\n\t[LuaCallCSharp]\r\n\tpublic static class TestExtensionMethodForStruct\r\n\t{\r\n\t\tpublic static void PrintSalary(this Employeestruct i)\r\n\t\t{\r\n\t\t\tLuaTestCommon.Log(\"Salary:\" + i.Salary);\r\n\t\t}\r\n\t\t\r\n\t\tpublic static int GetIncomeForOneYear(this Employeestruct i)\r\n\t\t{\r\n\t\t\treturn i.Salary * 12 + i.AnnualBonus;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static int Add(this Employeestruct i, Employeestruct d)\r\n\t\t{\r\n\t\t\treturn i.Salary * 12 + i.AnnualBonus + d.Salary * 12 + d.AnnualBonus;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void Sub(this Employeestruct i, Employeestruct d, out Employeestruct e, ref Employeestruct a)\r\n\t\t{\r\n\t\t\te = d;\r\n\t\t\te.Salary = 10000;\r\n\t\t\ta.Salary = i.Salary - d.Salary;\r\n\t\t\tLuaTestCommon.Log (\"e.name:\" + e.Name +\", e.salary:\"+ e.Salary);\r\n\t\t\tLuaTestCommon.Log (\"a.name:\" + a.Name +\", a.salary:\"+ a.Salary);\r\n\r\n\r\n\t\t}\r\n\t}\r\n\r\n\t[LuaCallCSharp]\r\n\tpublic static class TestExtensionMethodFOrClass\r\n\t{\r\n\t\tpublic static void PrintAllString(this TestChineseString i)\r\n\t\t{\r\n\t\t\tLuaTestCommon.Log(\"GetLongChineString:\" + i.GetLongChineString());\r\n\t\t}\r\n\r\n\t\tpublic static int GetLongStringLength(this TestChineseString i)\r\n\t\t{\r\n\t\t\treturn i.GetLongChineString ().Length;\r\n\t\t}\r\n\r\n\t\tpublic static int Add(this TestChineseString i, TestChineseString d)\r\n\t\t{\r\n\t\t\treturn i.GetLongChineString ().Length + d.GetLongChineString ().Length;\r\n\t\t}\r\n\r\n\t\tpublic static void Replace(this TestChineseString i , TestChineseString d, out TestChineseString e, ref TestChineseString a)\r\n\t\t{\r\n\t\t\te = i;\r\n\t\t\ta.combine_string = i.short_simple_string;\r\n\t\t\ta.short_simple_string = i.short_simple_string + d.short_simple_string;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic abstract class EmployeeTemplate\r\n{\r\n\tpublic void GetSalary()\r\n\t{\r\n\t\tGetBasicSalary();\r\n\t\tAddBonus();\r\n\t}\r\n\r\n\tpublic abstract int GetBasicSalary();\r\n\tpublic abstract int AddBonus();\r\n}\r\n\r\n[LuaCallCSharp]\r\npublic class Manager : EmployeeTemplate\r\n{\r\n\tpublic override int GetBasicSalary()\r\n\t{\r\n\t\t//Console.WriteLine(\"Get Manager Basic Salary\");\r\n\t\treturn 1;\r\n\t}\r\n\t\r\n\tpublic override int AddBonus()\r\n\t{\r\n\t\t//Console.WriteLine(\"Add Manager Bonus\");\r\n\t\treturn 2;\r\n\t}\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic class TableAutoTransSimpleClass\r\n{\r\n    public TableAutoTransSimpleClass()\r\n    {\r\n    }\r\n    public TableAutoTransSimpleClass(int x, string y, long z)\r\n    {\r\n        IntVar = x;\r\n        StringVar = y;\r\n        LongVar = z;\r\n    }\r\n    public int IntVar{\r\n    \r\n        get { return x; }\r\n\t\t\r\n        set { x = value; }\r\n    }\r\n\r\n    public string StringVar\r\n    {\r\n\r\n        get { return y; }\r\n\r\n        set { y = value; }\r\n    }\r\n\r\n    public long LongVar\r\n    {\r\n\r\n        get { return z; }\r\n\r\n        set { z = value; }\r\n    }\r\n\r\n    public int x;\r\n    public string y;\r\n    public long z;\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic class TableAutoTransComplexClass\r\n{\r\n    public TableAutoTransComplexClass()\r\n    {\r\n    }\r\n\r\n    public TableAutoTransComplexClass(int A, TableAutoTransSimpleClass B )\r\n    {\r\n        IntVar = A;\r\n        ClassVar = B;\r\n    }\r\n    public int IntVar\r\n    {\r\n\r\n        get { return A; }\r\n\r\n        set { A = value; }\r\n    }\r\n\r\n    public TableAutoTransSimpleClass ClassVar\r\n    {\r\n\r\n        get { return B; }\r\n\r\n        set { B = value; }\r\n    }\r\n\r\n    public int A;\r\n    public TableAutoTransSimpleClass B;\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct TableAutoTransSimpleStruct\r\n{\r\n    public byte a;\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic struct TableAutoTransComplexStruct\r\n{\r\n    public int a;\r\n    public int b;\r\n    public decimal c;\r\n    public TableAutoTransSimpleStruct d;\r\n}\r\n\r\n[GCOptimize]\r\n[LuaCallCSharp]\r\npublic class TestTableAutoTransClass\r\n{\r\n    public TableAutoTransSimpleClass SimpleClassMethod(TableAutoTransSimpleClass p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransComplexClass ComplexClassMethod(TableAutoTransComplexClass p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransSimpleStruct SimpleStructMethod(TableAutoTransSimpleStruct p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransComplexStruct ComplexStructMethod(TableAutoTransComplexStruct p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public int OneListMethod(int[] args)\r\n    {\r\n        int value = 0;\r\n        for (int i = 0; i < args.Length; i++)  \r\n        {\r\n            value += args[i];\r\n         }\r\n        return value;\r\n    }\r\n\r\n    public int TwoDimensionListMethod(int[][] args)\r\n    {\r\n        int value = 0;\r\n        for (int i = 0; i < args.Length; i++)\r\n        {\r\n            foreach (int j in args[i])  \r\n            {  \r\n                value += j;  \r\n            }  \r\n        }\r\n        return value;\r\n    }\r\n}\r\n\r\n//验证构造函数支持refer，out修饰符，add@2017.05.09 for v2.1.7\r\n[LuaCallCSharp]\r\npublic class ReferTestClass\r\n{\r\n    public ReferTestClass(int x, ref int y, out string z)\r\n    {\r\n        var_x = x;\r\n        var_y = y;\r\n        y = y - 1;\r\n        z = \"test1\";\r\n        var_z = z;\r\n    }\r\n\r\n    public ReferTestClass(int x, out string z)\r\n    {\r\n        var_x = x;\r\n        var_y = 10;\r\n        z = \"test3\";\r\n        var_z = z;\r\n    }\r\n\r\n    public int Get_X_Y_ADD()\r\n    {\r\n        return var_x + var_y;\r\n    }\r\n\r\n    private int var_x;\r\n    private int var_y;\r\n    private string var_z;\r\n}"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestObj.cs.meta",
    "content": "fileFormatVersion: 2\nguid: 84ce37be2f5dabf448aa5270f51153e6\ntimeCreated: 1483528414\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestObjReflect.cs",
    "content": "using XLua;\r\nusing System;\r\n#if !XLUA_GENERAL\r\nusing UnityEngine;\r\n#endif\r\n\r\npublic enum LuaTestTypeReflect\r\n{\r\n\tABC = 0,\r\n\tDEF,\r\n\tGHI,\r\n\tJKL\r\n};\r\n\r\npublic enum FirstPushEnumReflect\r\n{\r\n\tE1\r\n};\r\n[CSharpCallLua]\r\npublic delegate int TestDelegateReflect(int x);\r\n[CSharpCallLua]\r\npublic delegate int TestEvtHandler1Reflect(float y);\r\n[CSharpCallLua]\r\npublic delegate int TestEvtHandler2Reflect(byte y, float z);\r\n\r\npublic class LuaTestObjReflect\r\n{\r\n\tpublic static LuaEnv luaEnv = LuaEnvSingletonForTest.Instance;\r\n    public int testVar { get; set; }\r\n    public int[] testArr = new int[3];\r\n    public static LuaTestObjReflect operator + (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar + b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator +(LuaTestObjReflect a, int b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar + b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator +(int a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a + b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator - (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar - b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator -(LuaTestObjReflect a, int b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar - b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator -(int a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a - b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator * (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar * b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator *(LuaTestObjReflect a, int b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar * b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator *(int a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a * b.testVar;\r\n        return ret;\r\n    }\r\n\r\n\r\n    public static LuaTestObjReflect operator /(LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar / b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator /(LuaTestObjReflect a, int b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar / b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator /(int a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a / b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator % (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar % b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator %(int a, LuaTestObjReflect b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a % b.testVar;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator %(LuaTestObjReflect a, int b)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar % b;\r\n        return ret;\r\n    }\r\n\r\n    public static LuaTestObjReflect operator - (LuaTestObjReflect a)\r\n    {\r\n        LuaTestObjReflect ret = new LuaTestObjReflect();\r\n        ret.testVar = a.testVar * (-1);\r\n        return ret;\r\n    }\r\n\r\n    public static bool operator < (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        return (a.testVar < b.testVar);\r\n    }\r\n\r\n\r\n    public static bool operator <= (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        return (a.testVar <= b.testVar);\r\n    }\r\n\r\n\r\n\r\n    public static bool operator > (LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        return (a.testVar > b.testVar);\r\n    }\r\n\r\n\r\n\r\n    public static bool operator >=(LuaTestObjReflect a, LuaTestObjReflect b)\r\n    {\r\n        return (a.testVar >= b.testVar);\r\n    }\r\n\r\n   \r\n\r\n    public int this[int i]\r\n    {\r\n        get\r\n        {\r\n            return testArr[i];\r\n        }\r\n        set\r\n        {\r\n            testArr[i] = value;\r\n        }\r\n    }  \r\n\r\n    \r\n    public event TestEvtHandler1Reflect TestEvent1;\r\n    public event TestEvtHandler2Reflect TestEvent2;\r\n\r\n    public int CallEvent(float y)\r\n    {\r\n        return TestEvent1(y);\r\n    }\r\n\r\n\tpublic static event TestEvtHandler1Reflect TestStaticEvent1;\r\n\t\r\n\tpublic static int CallStaticEvent(float y)\r\n\t{\r\n\t\treturn TestStaticEvent1(y);\r\n\t}\r\n\r\n\tpublic static int DefaultParaFuncSingle(int i, string str = \"abc\")\r\n\t{\r\n\t\treturn i;\r\n\t}\r\n\r\n\tpublic static int DefaultParaFuncMulti(int i, string str = \"abc\", double d = 0, byte c = 97)\r\n\t{\r\n\t\treturn (i + 1);\r\n\t}\r\n\r\n\tpublic static int VariableParamFunc(int i, params string[] strs)\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static int TestEnumFunc(LuaTestTypeReflect x)\r\n\t{\r\n\t\treturn (int)x;\r\n\t}\r\n\r\n\tpublic static string TestGetType(Type x)\r\n\t{\r\n\t\treturn x.ToString ();\r\n\t}\r\n\r\n\tpublic static ulong ulX1 = 1;\r\n\tpublic static ulong ulX2 = 1;\r\n\tpublic static long lY1 = 1;\r\n\tpublic static long lY2 = 1;\r\n\tpublic static Int64 i64Z1 = 1;\r\n\tpublic static Int64 i64Z2 = 1;\r\n\tpublic static long lY3 = 1;\r\n\tpublic static long lY4 = 123;\r\n\tpublic static long lY5 = 12345;\r\n\tpublic static long lY6 = 54321;\r\n\r\n\tpublic static void Gen64BitInt()\r\n\t{\r\n\t\tulX1 = ulX2 = 1;\r\n\t\tlY1 = lY2 = lY3 = 1;\r\n\t\ti64Z1 = i64Z2 = 1;\r\n\t\tulX1 = ulX1 << 62;\r\n\t\tulX2 = ulX2 << 61;\r\n\t\tlY1 = lY1 << 62;\r\n\t\tlY2 = lY2 << 61;\r\n\t\ti64Z1 = i64Z1 << 62;\r\n\t\ti64Z2 = i64Z2 << 61;\r\n\t\tlY3 = lY3 << 50;\r\n\r\n\t}\r\n\r\n\tpublic static ITestLuaClassReflect CreateTestLuaObj()\r\n\t{\r\n\t\treturn new TestLuaClassReflect ();\r\n\t}\r\n\r\n    public static TestDelegateReflect csDelegate;\r\n    public static TestDelegateReflect csDelegate1;\r\n    public static TestDelegateReflect csDelegate2;\r\n    public static TestDelegateReflect csDelegate3;\r\n    public static TestDelegateReflect csDelegate4;\r\n\r\n    public static TestDelegateReflect csDelegate11;\r\n    public static TestDelegateReflect csDelegate12;\r\n    public static TestDelegateReflect csDelegate13;\r\n\r\n\tpublic static int initNumber = 5;\r\n\r\n\tpublic static int CalcAdd(int x)\r\n\t{\r\n\t\tinitNumber += x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int calcadd(int x)\r\n\t{\r\n\t\tinitNumber += x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int CalcDel(int x)\r\n\t{\r\n\t\tinitNumber -= x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static int CalcMul(int x)\r\n\t{\r\n\t\tinitNumber *= x;\r\n\t\treturn initNumber;\r\n\t}\r\n\r\n\tpublic static void GenDelegate()\r\n\t{\r\n        csDelegate1 = new TestDelegateReflect(CalcAdd);\r\n        csDelegate2 = new TestDelegateReflect(CalcDel);\r\n        csDelegate3 = new TestDelegateReflect(CalcMul);\r\n\t}\r\n\r\n    public static int OverLoad1(int x, int y)\r\n    {\r\n        return 1;\r\n    }\r\n\r\n    public static int OverLoad1(int x)\r\n    {\r\n        return 2;\r\n    }\r\n\r\n\tpublic static int OverLoad1(params int[] vars)\r\n\t{\r\n\t\tint ret = 0;\r\n\t\tforeach (int var in vars) \r\n\t\t{ \r\n\t\t\tret += var; \r\n\t\t} \r\n\t\treturn ret;\r\n\t}\r\n\r\n\tpublic static int OverLoad2(int x, float y)\r\n    {\r\n        return 3;\r\n    }\r\n\r\n    public static int OverLoad2(string x, string y)\r\n    {\r\n        return 4;\r\n    }\r\n\r\n    public static int OverLoad3(int x)\r\n    {\r\n        return 5;\r\n    }\r\n\r\n    public static int OverLoad3(short y)\r\n    {\r\n        return 6;\r\n    }\r\n\r\n\r\n    public static void OutRefFunc1(int x, out int y, ref int z)\r\n    {\r\n        y = 100;\r\n    }\r\n\r\n    public static void OutRefFunc2(ref int x, int y, out int z)\r\n    {\r\n        z = 200;\r\n    }\r\n\r\n    public static void OutRefFunc3(int x, out int y, ref int z)\r\n    {\r\n        y = 300;\r\n    }\r\n\r\n    public static int OutRefFunc4(int x, out int y, ref int z)\r\n    {\r\n        y = 400;\r\n        return y;\r\n    }\r\n\r\n    public static int OutRefFunc5(ref int x, int y, out int z)\r\n    {\r\n        z = 500;\r\n        return z;\r\n    }\r\n\r\n    public static int OutRefFunc6(int x, int y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n    public static void OutRefFunc11(ITestLuaClassReflect x, out ITestLuaClassReflect y, ref ITestLuaClassReflect z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 100;\r\n    }\r\n\r\n    public static void OutRefFunc12(ref ITestLuaClassReflect x, ITestLuaClassReflect y, out ITestLuaClassReflect z)\r\n    {\r\n        z = CreateTestLuaObj();\r\n        z.cmpTarget = 200;\r\n    }\r\n\r\n    public static void OutRefFunc13(ITestLuaClassReflect x, out ITestLuaClassReflect y, ref ITestLuaClassReflect z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 300;\r\n    }\r\n\r\n    public static int OutRefFunc14(ITestLuaClassReflect x, out ITestLuaClassReflect y, ref ITestLuaClassReflect z)\r\n    {\r\n        y = CreateTestLuaObj();\r\n        y.cmpTarget = 400;\r\n        return y.cmpTarget;\r\n    }\r\n\r\n    public static int OutRefFunc15(ref ITestLuaClassReflect x, ITestLuaClassReflect y, out ITestLuaClassReflect z)\r\n    {\r\n        z = CreateTestLuaObj();\r\n        z.cmpTarget = 500;\r\n        return z.cmpTarget;\r\n    }\r\n\r\n    public static int OutRefFunc16(ITestLuaClassReflect x, ITestLuaClassReflect y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n    public static void OutRefFunc21(TestDelegateReflect x, out TestDelegateReflect y, ref TestDelegateReflect z)\r\n    {\r\n        y = new TestDelegateReflect(CalcAdd);\r\n    }\r\n\r\n    public static void OutRefFunc22(ref TestDelegateReflect x, TestDelegateReflect y, out TestDelegateReflect z)\r\n    {\r\n        z = new TestDelegateReflect(CalcAdd);\r\n    }\r\n\r\n    public static void OutRefFunc23(TestDelegateReflect x, out TestDelegateReflect y, ref TestDelegateReflect z)\r\n    {\r\n        y = new TestDelegateReflect(CalcAdd);\r\n    }\r\n\r\n    public static int OutRefFunc24(TestDelegateReflect x, out TestDelegateReflect y, ref TestDelegateReflect z)\r\n    {\r\n        y = new TestDelegateReflect(CalcAdd);\r\n        return y(1);\r\n    }\r\n\r\n    public static int OutRefFunc25(ref TestDelegateReflect x, TestDelegateReflect y, out TestDelegateReflect z)\r\n    {\r\n        z = new TestDelegateReflect(CalcAdd);\r\n        return z(1);\r\n    }\r\n\r\n    public static int OutRefFunc26(TestDelegateReflect x, TestDelegateReflect y)\r\n    {\r\n        return 600;\r\n    }\r\n\r\n\tpublic int Sum(int a, int b, int c)\r\n\t{\r\n\t\treturn a + b + c;\r\n\t}\r\n\t\r\n\tpublic static int Sum(int a, int b)\r\n\t{\r\n\t\treturn a + b;\r\n\t}\r\n\r\n\tpublic void GenericMethod<T>()\r\n\t{\r\n\t\tLuaTestCommon.Log(\"GenericMethod<\" + typeof(T) +\">\");\r\n\t}\r\n\r\n    public IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(100);\r\n\r\n    public IntPtr GetPtr()\r\n    {\r\n        byte[] abc = new byte[] { 97, 98, 99 };\r\n        System.Runtime.InteropServices.Marshal.Copy(abc, 0, ptr, abc.Length);\r\n        return ptr;\r\n    }\r\n\r\n    public byte PrintPtr(IntPtr p)\r\n    {\r\n        LuaTestCommon.Log(\"p == ptr?\" + (p == ptr));\r\n        byte[] abc = new byte[] { 0, 0, 0 };\r\n        System.Runtime.InteropServices.Marshal.Copy(p, abc, 0, abc.Length);\r\n        LuaTestCommon.Log(string.Format(\"{0},{1},{2}\", abc[0], abc[1], abc[2]));\r\n        return abc[0];\r\n    }\r\n    public int VariableParamFuncDefault(int d, int i = 1, params string[] strs)\r\n    {\r\n        return i + d;\r\n    }\r\n\r\n    public static double StaticVariableParamFuncDefault(double d, double i = 1.0, params string[] strs)\r\n    {\r\n        return i + d;\r\n    }\r\n\t\r\n\tpublic static byte[] FuncReturnByteArray()\r\n\t{\r\n\t\tbyte[] abc = new byte[] { 97, 98, 99 };\r\n\t\treturn abc;\r\n\t}\r\n\t\r\n\tpublic static byte FuncReturnByte()\r\n    {\r\n        byte abc = 97;\r\n        return abc;\r\n    }\r\n\t\r\n\tpublic static int[] FuncReturnIntArray()\r\n\t{\r\n\t\tint[] abc = new int[] { 97, 98, 99 };\r\n\t\treturn abc;\r\n\t}\r\n\r\n    public static int FuncReturnInt()\r\n    {\r\n        int abc = 97;\r\n        return abc;\r\n    }\r\n\r\n#if !XLUA_GENERAL\r\n    public static LayerMask TestImplicit()\r\n    {\r\n        return new LayerMask();\r\n    }\r\n#endif\r\n\r\n    public static int VariableParamFunc(int i, params int[] strs)\r\n    {\r\n        return 0;\r\n    }\r\n\r\n\tpublic static int VariableParamFunc2(params int[] strs)\r\n    {\r\n        return strs.Length;\r\n    }\r\n\t\r\n    public static string FirstPushEnumFunc(int i)\r\n\t{\r\n        string luaScript = @\"\r\n        function first_push_reflect(t,obj)\r\n\t        if t==1 then\r\n\t\t        if obj == CS.FirstPushEnumReflect.E1 then\r\n\t\t\t        return 1\r\n\t\t        else\r\n\t\t\t        return 2\r\n\t\t        end\r\n\t        elseif t==2 then\r\n\t\t        if obj == CS.FirstPushEnumReflect.self then\r\n\t\t\t        return 3\r\n\t\t        else\r\n\t\t\t        return 4\r\n\t\t        end\r\n\t        else\r\n\t\t        return 5\r\n\t        end\r\n        end\";\r\n        luaEnv.DoString(luaScript);\r\n\t\tLuaFunction f1 = luaEnv.Global.Get<LuaFunction>(\"first_push_reflect\");\r\n        LuaTestCommon.Log(\"LuaFunction<\" + f1);\r\n\t\tobject[] ret = f1.Call(i, FirstPushEnumReflect.E1);\r\n\t\treturn ret[0].ToString();\r\n\t}\r\n}\r\n\r\npublic class TestCastClassReflect\r\n{\r\n\tpublic bool TestFunc1()\r\n\t{\r\n\t\treturn true;\r\n\r\n\t}\r\n}\r\n\r\npublic interface ITestLuaClassReflect\r\n{\r\n\tbool TestFunc1();\r\n    int cmpTarget{ set; get; }\r\n}\r\n\r\ninternal class TestLuaClassReflect : ITestLuaClassReflect\r\n{\r\n\tpublic bool TestFunc1()\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n    public int cmpTarget { set; get; }\r\n}\r\n\r\npublic class  TestChineseStringReflect\r\n{\r\n\r\n\tpublic string GetShortChinString()\r\n\t{\r\n\t\treturn short_simple_string;\r\n\t}\r\n\r\n\tpublic string GetLongChineString()\r\n\t{\r\n\t\treturn long_simple_string;\r\n\t}\r\n\r\n\tpublic string GetCombineString()\r\n\t{\r\n\t\treturn combine_string;\r\n\t}\r\n\r\n\tpublic string GetComplexString()\r\n\t{\r\n\t\treturn complex_string;\r\n\t}\r\n\r\n\tpublic string GetHuoxingString()\r\n\t{\r\n\t\treturn huoxing_string;\r\n\t}\r\n\r\n\tpublic string short_simple_string = \"中文字符串\";\r\n\tpublic string long_simple_string = \"为Unity3D增加Lua脚本编程的能力，进而提供代码逻辑增量更新的可能，支持lua的所有基本类型，哈哈哈哈\";\r\n\tpublic string combine_string = \"中文字符串.* ? [ ] ^ $~`!@#$%^&()_-+=[];',““〈〉〖【℃ ＄ ¤№ ☆ ★■ⅷ②㈣12345abc\";\r\n\tpublic string complex_string = \"繁體國陸\";\r\n\tpublic string huoxing_string = \"吙煋呅僦媞這樣孒\";\r\n}\r\n\r\npublic class TestUlongAndLongTypeReflect\r\n{\r\n\tpublic ulong UlongMax\r\n\t{\r\n\r\n\t\tget { return ulong_max; }\r\n\t\tset { ulong_max=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongMin\r\n\t{\r\n\t\t\r\n\t\tget { return ulong_min; }\r\n\t\tset { ulong_min=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongMid\r\n\t{\r\n\t\t\r\n\t\tget { return ulong_mid; }\r\n\t\tset { ulong_mid=value; }\r\n\t}\r\n\r\n\tpublic ulong UlongAdd()\r\n\t{\r\n\t\treturn ulong_max - 1000 + 1;\r\n\t}\r\n\r\n\tpublic long LongMax\r\n\t{\r\n\t\t\r\n\t\tget { return long_max; }\r\n\t\tset { long_max=value; }\r\n\t}\r\n\t\r\n\tpublic long LongMin\r\n\t{\r\n\t\t\r\n\t\tget { return long_min; }\r\n\t\tset { long_min=value; }\r\n\t}\r\n\t\r\n\tpublic long LongMid\r\n\t{\r\n\t\t\r\n\t\tget { return long_mid; }\r\n\t\tset { long_mid=value; }\r\n\t}\r\n\r\n\tpublic long LongAdd()\r\n\t{\r\n\t\treturn long_max - 1000 + 1;\r\n\t}\r\n\r\n\tulong ulong_max = System.UInt64.MaxValue;\r\n\tulong ulong_min = System.UInt64.MinValue;\r\n\tulong ulong_mid = 9223372036854775808;\r\n\tlong long_max = System.Int64.MaxValue;\r\n\tlong long_min = System.Int64.MinValue;\r\n\tlong long_mid = 4611686018427387904;\r\n}\r\n\r\npublic struct EmployeestructReflect\r\n{\r\n\tprivate string name;\r\n\tpublic string Name\r\n\t{\r\n\t\tget { return name; }\r\n\t\tset { name = value; }\r\n\t}\r\n\t\r\n\tprivate int age;\r\n\tpublic int Age\r\n\t{\r\n\t\tget { return age; }\r\n\t\tset { age = value; }\r\n\t}\r\n\t\r\n\tprivate int salary;\r\n\tprivate int annual_bonus;\r\n\r\n\tpublic int Salary\r\n\t{\r\n\t\tget { return salary; }\r\n\t\tset { salary = value; }\r\n\t}\r\n\r\n\tpublic int AnnualBonus\r\n\t{\r\n\t\tget { return annual_bonus; }\r\n\t\tset { annual_bonus = value; }\r\n\t}\r\n\r\n}\r\n\r\npublic struct HasConstructStructReflect{\r\n\tpublic int x;\r\n\tpublic int y;\r\n\tpublic string z;\r\n\tpublic HasConstructStructReflect(int x, int y, string z)\r\n\t{\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t\tthis.z = z;\r\n\t}\r\n}\r\n\r\npublic class CClassReflect\r\n{\r\n\tpublic CClassReflect(int x, int y, string z)\r\n\t{\r\n\t\tc_struct = new HasConstructStructReflect(x, y, z);\r\n\t}\r\n\r\n\tpublic HasConstructStructReflect CConStruct\r\n\t{\r\n\t\tget { return c_struct; }\r\n\t\tset { c_struct = value; }\r\n\t}\r\n\t\r\n\tpublic void Add(HasConstructStructReflect invar, ref HasConstructStructReflect refvar, out HasConstructStructReflect outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x + refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t}\r\n\r\n\tpublic int VariableParamFunc(params HasConstructStructReflect[] structs)\r\n\t{\r\n\t\tint ret = 0;\r\n\t\tforeach (HasConstructStructReflect var in structs) \r\n\t\t{ \r\n\t\t\tret += var.x; \r\n\t\t} \r\n\t\treturn ret;\r\n\t}\r\n\t\r\n\tprivate HasConstructStructReflect c_struct;\r\n}\r\n\r\npublic class BClassReflect:CClassReflect\r\n{\r\n\tpublic BClassReflect(int x, int y, string z):base(x, y, z)\r\n\t{\r\n\t\tb_struct = new HasConstructStructReflect(x, y, z);\r\n\t}\r\n\r\n\tpublic HasConstructStructReflect BConStruct\r\n\t{\r\n\t\tget { return b_struct; }\r\n\t\tset { b_struct = value; }\r\n\t}\r\n\t\r\n\tpublic void Sub(HasConstructStructReflect invar, ref HasConstructStructReflect refvar, out HasConstructStructReflect outvar)\r\n\t{\r\n\t\toutvar = invar;\r\n\t\toutvar.x = invar.x - refvar.x;\r\n\t\trefvar.x = invar.x;\r\n\t\tLuaTestCommon.Log (\"refvar.x:\" + refvar.x + \",refvar.y:\" + refvar.y + \", refvar.z:\" + refvar.z);\r\n\t}\r\n\t\r\n\tprivate HasConstructStructReflect b_struct;\r\n}\r\n\r\npublic class AClassReflect:BClassReflect\r\n{\r\n\tpublic AClassReflect(int x, int y , string z):base(x, y, z)\r\n\t{\r\n\t\tLuaTestCommon.Log (\"AClass Constructor\");\r\n\t}\r\n\r\n    public int Div(int x, int y)\r\n    {\r\n\t\tif (y == 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse \r\n\t\t{\r\n\t\t\treturn x / y;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nnamespace TestExtensionMethodReflect\r\n{\r\n\t[ReflectionUse]\r\n\tpublic static class TestExtensionMethodForStructReflect\r\n\t{\r\n\t\tpublic static void PrintSalary(this EmployeestructReflect i)\r\n\t\t{\r\n\t\t\tLuaTestCommon.Log(\"Salary:\" + i.Salary);\r\n\t\t}\r\n\t\t\r\n\t\tpublic static int GetIncomeForOneYear(this EmployeestructReflect i)\r\n\t\t{\r\n\t\t\treturn i.Salary * 12 + i.AnnualBonus;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static int Add(this EmployeestructReflect i, EmployeestructReflect d)\r\n\t\t{\r\n\t\t\treturn i.Salary * 12 + i.AnnualBonus + d.Salary * 12 + d.AnnualBonus;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void Sub(this EmployeestructReflect i, EmployeestructReflect d, out EmployeestructReflect e, ref EmployeestructReflect a)\r\n\t\t{\r\n\t\t\te = d;\r\n\t\t\te.Salary = 10000;\r\n\t\t\ta.Salary = i.Salary - d.Salary;\r\n\t\t\tLuaTestCommon.Log (\"e.name:\" + e.Name +\", e.salary:\"+ e.Salary);\r\n\t\t\tLuaTestCommon.Log (\"a.name:\" + a.Name +\", a.salary:\"+ a.Salary);\r\n\t\t}\r\n\t}\r\n\t\r\n    [ReflectionUse]\r\n\tpublic static class TestExtensionMethodForClassReflect\r\n\t{\r\n\t\tpublic static void PrintAllString(this TestChineseStringReflect i)\r\n\t\t{\r\n\t\t\tLuaTestCommon.Log(\"GetLongChineString:\" + i.GetLongChineString());\r\n\t\t}\r\n\r\n\t\tpublic static int GetLongStringLength(this TestChineseStringReflect i)\r\n\t\t{\r\n\t\t\treturn i.GetLongChineString ().Length;\r\n\t\t}\r\n\r\n\t\tpublic static int Add(this TestChineseStringReflect i, TestChineseStringReflect d)\r\n\t\t{\r\n\t\t\treturn i.GetLongChineString ().Length + d.GetLongChineString ().Length;\r\n\t\t}\r\n\r\n\t\tpublic static void Replace(this TestChineseStringReflect i , TestChineseStringReflect d, out TestChineseStringReflect e, ref TestChineseStringReflect a)\r\n\t\t{\r\n\t\t\te = i;\r\n\t\t\ta.combine_string = i.short_simple_string;\r\n\t\t\ta.short_simple_string = i.short_simple_string + d.short_simple_string;\r\n\t\t}\r\n\t}\r\n}\r\n\r\npublic abstract class EmployeeTemplateReflect\r\n{\r\n\tpublic void GetSalary()\r\n\t{\r\n\t\tGetBasicSalary();\r\n\t\tAddBonus();\r\n\t}\r\n\tpublic abstract int GetBasicSalary();\r\n\tpublic abstract int AddBonus();\r\n}\r\n\r\npublic class ManagerReflect : EmployeeTemplateReflect\r\n{\r\n\tpublic override int GetBasicSalary()\r\n\t{\r\n\t\t//Console.WriteLine(\"Get Manager Basic Salary\");\r\n\t\treturn 1;\r\n\t}\r\n\t\r\n\tpublic override int AddBonus()\r\n\t{\r\n\t\t//Console.WriteLine(\"Add Manager Bonus\");\r\n\t\treturn 2;\r\n\t}\r\n}\r\n\r\npublic class TableAutoTransSimpleClassReflect\r\n{\r\n    public TableAutoTransSimpleClassReflect()\r\n    {\r\n    }\r\n    public TableAutoTransSimpleClassReflect(int x, string y, long z)\r\n    {\r\n        IntVar = x;\r\n        StringVar = y;\r\n        LongVar = z;\r\n    }\r\n    public int IntVar\r\n    {\r\n\r\n        get { return x; }\r\n\r\n        set { x = value; }\r\n    }\r\n\r\n    public string StringVar\r\n    {\r\n\r\n        get { return y; }\r\n\r\n        set { y = value; }\r\n    }\r\n\r\n    public long LongVar\r\n    {\r\n\r\n        get { return z; }\r\n\r\n        set { z = value; }\r\n    }\r\n\r\n    public int x;\r\n    public string y;\r\n    public long z;\r\n}\r\npublic class TableAutoTransComplexClassReflect\r\n{\r\n    public TableAutoTransComplexClassReflect()\r\n    {\r\n    }\r\n\r\n    public TableAutoTransComplexClassReflect(int A, TableAutoTransSimpleClassReflect B)\r\n    {\r\n        IntVar = A;\r\n        ClassVar = B;\r\n    }\r\n    public int IntVar\r\n    {\r\n\r\n        get { return A; }\r\n\r\n        set { A = value; }\r\n    }\r\n\r\n    public TableAutoTransSimpleClassReflect ClassVar\r\n    {\r\n\r\n        get { return B; }\r\n\r\n        set { B = value; }\r\n    }\r\n\r\n    public int A;\r\n    public TableAutoTransSimpleClassReflect B;\r\n}\r\n\r\npublic struct TableAutoTransSimpleStructReflect\r\n{\r\n    public byte a;\r\n}\r\n\r\n\r\npublic struct TableAutoTransComplexStructReflect\r\n{\r\n    public int a;\r\n    public int b;\r\n    public decimal c;\r\n    public TableAutoTransSimpleStructReflect d;\r\n}\r\npublic class TestTableAutoTransClassReflect\r\n{\r\n    public TableAutoTransSimpleClassReflect SimpleClassMethod(TableAutoTransSimpleClassReflect p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransComplexClassReflect ComplexClassMethod(TableAutoTransComplexClassReflect p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransSimpleStructReflect SimpleStructMethod(TableAutoTransSimpleStructReflect p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public TableAutoTransComplexStructReflect ComplexStructMethod(TableAutoTransComplexStructReflect p)\r\n    {\r\n        return p;\r\n    }\r\n\r\n    public int OneListMethod(int[] args)\r\n    {\r\n        int value = 0;\r\n        for (int i = 0; i < args.Length; i++)\r\n        {\r\n            value += args[i];\r\n        }\r\n        return value;\r\n    }\r\n\r\n    public int TwoDimensionListMethod(int[][] args)\r\n    {\r\n        int value = 0;\r\n        for (int i = 0; i < args.Length; i++)\r\n        {\r\n            foreach (int j in args[i])\r\n            {\r\n                value += j;\r\n            }\r\n        }\r\n        return value;\r\n    }\r\n}\r\n\r\n\r\n//验证构造函数支持refer，out修饰符，add@2017.05.09 for v2.1.7\r\npublic class ReferTestClassReflect\r\n{\r\n    public ReferTestClassReflect(int x, ref int y, out string z)\r\n    {\r\n        var_x = x;\r\n        var_y = y;\r\n        y = y - 1;\r\n        z = \"test1\";\r\n        var_z = z;\r\n    }\r\n\r\n    public ReferTestClassReflect(int x, out string z)\r\n    {\r\n        var_x = x;\r\n        var_y = 10;\r\n        z = \"test3\";\r\n        var_z = z;\r\n    }\r\n\r\n    public int Get_X_Y_ADD()\r\n    {\r\n        return var_x + var_y;\r\n    }\r\n\r\n    private int var_x;\r\n    private int var_y;\r\n    private string var_z;\r\n}"
  },
  {
    "path": "Test/UnitTest/xLuaTest/LuaTestObjReflect.cs.meta",
    "content": "fileFormatVersion: 2\nguid: c5ef0d5b807af9e42a0671fcb4b375fa\ntimeCreated: 1483528418\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Main.cs",
    "content": "﻿#if !XLUA_GENERAL\r\nusing UnityEngine;\r\nusing System.Collections;\r\nusing XLua;\r\n\r\npublic class Main : MonoBehaviour {\r\n\tLuaEnv luaenv;\r\n\t// Use this for initialization\r\n\tvoid Start () {\r\n\t\tluaenv = LuaEnvSingleton.Instance;\r\n\t\tluaenv.DoString (\"require 'main'\");\r\n\t}\r\n\t\r\n\t// Update is called once per frame\r\n\tvoid Update () {\r\n\t\tluaenv.GC ();\r\n\t}\r\n}\r\n#endif"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Main.cs.meta",
    "content": "fileFormatVersion: 2\nguid: a51b9f781bcbff34a82d5c9dcb2f0b5d\ntimeCreated: 1483528414\nlicenseType: Pro\nMonoImporter:\n  serializedVersion: 2\n  defaultReferences: []\n  executionOrder: 0\n  icon: {instanceID: 0}\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_msg_type.xml",
    "content": "<?xml version=\"1.0\" ?>\n<metalib name=\"net\" >\n    <macro name=\"MAX_NAME_LEN\" value=\"128\" />\n    <macro name=\"MAX_PASS_LEN\" value=\"32\" />\n    <struct name=\"CmdLogin\" version=\"1\" id=\"1\" >\n        <entry name=\"name\" type=\"string\" id=\"1\" defaultvalue=\"腾讯\" size=\"MAX_NAME_LEN\" sizeinfo=\"smalluint\" />\n        <entry name=\"pass\" type=\"string\" id=\"2\" size=\"MAX_PASS_LEN\" />\n        <entry name=\"zone\" type=\"string\" id=\"3\" size=\"MAX_PASS_LEN\" />\n        <entry name=\"destIp\" type=\"ip\" id=\"4\" version=\"2\" defaultvalue=\"10.6.221.149\" />\n    </struct>\n    <macro name=\"MAX_ATTR_SIZE\" value=\"3\" />\n    <struct name=\"CmdLogout\" version=\"2\" id=\"2\" >\n        <entry name=\"reason\" type=\"bigint\" id=\"1\" />\n        <entry name=\"count\" type=\"int\" id=\"2\" defaultvalue=\"10\" />\n        <entry name=\"attr\" type=\"tinyint\" id=\"3\" count=\"MAX_ATTR_SIZE\" refer=\"count\" />\n    </struct>\n    \n    <struct name=\"TypeTester\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"date\" type=\"Date\" id=\"10\" />\n        <entry name=\"time\" type=\"Time\" id=\"20\" defaultvalue=\"14:36:30\" />\n        \n        <entry name=\"int8\"              type=\"int8\" id=\"30\" version=\"3\" />\n        <entry name=\"uint8Array\"        type=\"uint8\" id=\"31\" count=\"3\" version=\"3\" />\n        <entry name=\"int8VarArrayRefer\" type=\"int\"  id=\"32\" version=\"3\" />\n        <entry name=\"int8VarArray\"      type=\"int8\" id=\"33\" count=\"3\" refer=\"int8VarArrayRefer\" version=\"3\" />\n\n        <entry name=\"int\"               type=\"int\"  id=\"40\" version=\"3\" defaultvalue=\"0x7FFFFFFF\" />\n        <entry name=\"uintArray\"         type=\"uint\"  id=\"41\" count=\"3\" version=\"3\" />\n        <entry name=\"intVarArrayRefer\"  type=\"int\"  id=\"42\" version=\"3\" />\n        <entry name=\"intVarArray\"       type=\"int\"  id=\"43\" count=\"3\" refer=\"intVarArrayRefer\" version=\"3\" />\n        \n        <entry name=\"strArray\" type=\"string\" id=\"50\" count=\"2\" size=\"16\" version=\"3\" />\n        \n        <entry name=\"uint64\"              type=\"uint64\"  id=\"60\" version=\"3\" />\n        <entry name=\"int64Array\"          type=\"int64\"  id=\"61\" count=\"3\" version=\"3\" />\n        \n        <entry name=\"float\"               type=\"float\"  id=\"70\" version=\"3\" />\n        <entry name=\"floatArray\"          type=\"float\"  id=\"71\" count=\"3\" version=\"3\" />\n        \n        <entry name=\"double\"              type=\"double\"  id=\"80\" version=\"3\" />\n        <entry name=\"doubleArray\"         type=\"double\"  id=\"81\" count=\"3\" version=\"3\" />\n    </struct>\n    <struct name=\"InnerStruct\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"uint64\" type=\"uint64\" id=\"1\" />\n        <entry name=\"uint\" type=\"uint\" id=\"2\" />\n    </struct>\n    <struct name=\"InnerStructList\" version=\"3\" >\n        <entry name=\"count\" type=\"int\" id=\"1\" defaultvalue=\"2\" />\n        <entry name=\"array\" type=\"InnerStruct\" count=\"3\" refer=\"count\" id=\"2\" />\n    </struct>\n    <union name=\"InnerUnion\" version=\"3\" >\n        <entry name=\"field1\" type=\"InnerStruct\" count=\"2\" id=\"1\" />\n        <entry name=\"field2\" type=\"InnerStruct\" id=\"2\" />\n    </union>\n    <struct name=\"CmdXXX\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"typeTester\" type=\"TypeTester\" id=\"1\" />\n        <entry name=\"boundary\" type=\"float\" id=\"11\" />\n        <entry name=\"selector\" type=\"int\" version=\"3\" id=\"21\" />\n        <entry name=\"innerUnion\" type=\"InnerUnion\" select=\"selector\" version=\"3\" id=\"22\" sizeinfo=\"int\" />\n        <entry name=\"structArray\" type=\"InnerStructList\" version=\"3\" id=\"31\" />\n        <entry name=\"boundary2\" type=\"float\" id=\"51\" version=\"3\" defaultvalue=\"-3.40282346e+38\" />\n    </struct>\n\t\n\t<struct name=\"TestInnerStruct1\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"int8\" type=\"int8\" id=\"1\" />\n        <entry name=\"double\" type=\"double\" id=\"2\" />\n\t\t<entry name=\"float\" type=\"float\" id=\"3\" />\n\t\t<entry name=\"int16\" type=\"int16\" id=\"4\" />\n\t\t<entry name=\"int32Array\" type=\"int32\" count=\"3\" id=\"5\" />\n    </struct>\n\t\n\t<struct name=\"TestInnerStruct2\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"double\" type=\"double\" id=\"1\" />\n        <entry name=\"int8\" type=\"int8\" id=\"2\" />\n\t\t<entry name=\"int32Array\" type=\"int32\" count=\"3\" id=\"10\" />\n\t\t<entry name=\"int16\" type=\"int16\" id=\"20\" />\n\t\t<entry name=\"float\" type=\"float\" id=\"21\" />\n    </struct>\n\t\n\t<union name=\"TestUnion\" version=\"3\" >\n        <entry name=\"field1\" type=\"TestInnerStruct1\" id=\"1\" />\n        <entry name=\"field2\" type=\"TestInnerStruct2\" id=\"2\" />\n    </union>\n\t\n\t<struct name=\"CmdOther\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"int8\" type=\"int8\" id=\"1\" />\n        <entry name=\"double\" type=\"float\" id=\"11\" />\n        <entry name=\"selector\" type=\"int\" version=\"3\" id=\"21\" />\n        <entry name=\"testunion\" type=\"TestUnion\" select=\"selector\" version=\"3\" id=\"22\" sizeinfo=\"int\" />\n    </struct>\n    \n    <!-- Test version compatibility -->\n    <struct name=\"TypeTesterPrevious\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"date\" type=\"Date\" id=\"10\" />\n        <entry name=\"time\" type=\"Time\" id=\"20\" defaultvalue=\"14:36:30\" />\n    </struct>\n    <struct name=\"CmdXXXPrevious\" sizeinfo=\"int\" version=\"2\" >\n        <entry name=\"typeTester\" type=\"TypeTesterPrevious\" id=\"1\" />\n        <entry name=\"boundary\" type=\"float\" id=\"11\" />\n    </struct>\n</metalib>\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_msg_type.xml.meta",
    "content": "fileFormatVersion: 2\nguid: 568886381954c3b408d0b9ace77f3af3\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_protocol.xml",
    "content": "<?xml version=\"1.0\" ?>\n<metalib name=\"net\" version=\"3\" >\n    <include file=\"non_tlv_net_msg_type.xml\" />\n    <struct name=\"PkgHead\" version=\"1\" id=\"3\" desc=\"package header\" >\n        <entry name=\"magic\" type=\"smallint\" id=\"1\" defaultvalue=\"13124\" />\n        <entry name=\"msgid\" type=\"biguint\" id=\"2\" />\n        <entry name=\"cmd\" type=\"smallint\" id=\"3\" />\n        <entry name=\"version\" type=\"smallint\" id=\"4\" />\n        <entry name=\"bodyLen\" type=\"smallint\" id=\"5\" />\n        <entry name=\"datetime\" type=\"datetime\" id=\"6\" version=\"2\" />\n        <entry name=\"srcIp\" type=\"ip\" id=\"7\" version=\"3\" />\n    </struct>\n    <macrosgroup name=\"NET_CMD_ID\" >\n        <macro name=\"CMD_LOGIN\" value=\"1\" />\n        <macro name=\"CMD_LOGOUT\" value=\"2\" />\n        <macro name=\"CMD_STRUCT\" value=\"3\" />\n        <macro name=\"CMD_EXT1\" value=\"13\" />\n        <macro name=\"CMD_EXT2_MIN\" value=\"70\" />\n        <macro name=\"CMD_EXT2_MAX\" value=\"80\" />\n        <macro name=\"CMD_EXT3\" value=\"15\" />\n        <macro name=\"CMD_EXT4\" value=\"100\" />\n\t\t<macro name=\"CMD_OTHER\" value=\"200\" />\n    </macrosgroup>\n    <union name=\"PkgBody\" version=\"2\" id=\"4\" desc=\"pakcage body\" >\n        <entry name=\"login\" type=\"CmdLogin\" id=\"CMD_LOGIN\" sizeinfo=\"smalluint\" />\n        <entry name=\"logout\" type=\"CmdLogout\" id=\"CMD_LOGOUT\" sizeinfo=\"smalluint\" />\n        <entry name=\"xxx\" type=\"CmdXXX\" id=\"CMD_STRUCT\" />\n        <!-- no id --><entry name=\"ext1\" type=\"int\" version=\"3\" />\n        <!-- minid & maxid --><entry name=\"ext2\" type=\"byte\" minid=\"CMD_EXT2_MIN\" maxid=\"CMD_EXT2_MAX\" count=\"3\" version=\"3\" />\n        <entry name=\"ext3\" type=\"string\" id=\"CMD_EXT3\" size=\"40\" count=\"2\" defaultvalue=\"string: ext3\" version=\"3\" />\n        <entry name=\"ext4\" type=\"string\" id=\"CMD_EXT4\" size=\"40\" version=\"3\" />\n\t\t<entry name=\"other\" type=\"CmdOther\" id=\"CMD_OTHER\" />\n    </union>\n    <macrosgroup name=\"PKG_ID\" >\n        <macro name=\"PKG_HEADER\" value=\"1\" />\n        <macro name=\"PKG_BODY\" value=\"2\" />\n    </macrosgroup>\n    <struct name=\"Pkg\" versionindicator=\"head.version\" version=\"1\" id=\"5\" sizeinfo=\"int\" >\n        <entry name=\"head\" type=\"PkgHead\" id=\"PKG_HEADER\" />\n        <entry name=\"body\" type=\"PkgBody\" id=\"PKG_BODY\" select=\"head.cmd\" version=\"2\" sizeinfo=\"head.bodyLen\" />\n    </struct>\n    \n    <!-- Test version compatibility -->\n    <struct name=\"PkgHeadPrevious\" version=\"1\" id=\"103\" desc=\"package header\" >\n        <entry name=\"magic\" type=\"smallint\" id=\"1\" defaultvalue=\"13124\" />\n        <entry name=\"msgid\" type=\"biguint\" id=\"2\" />\n        <entry name=\"cmd\" type=\"smallint\" id=\"3\" />\n        <entry name=\"version\" type=\"smallint\" id=\"4\" />\n        <entry name=\"bodyLen\" type=\"smallint\" id=\"5\" />\n        <entry name=\"datetime\" type=\"datetime\" id=\"6\" version=\"2\" />\n    </struct>\n    <union name=\"PkgBodyPrevious\" version=\"2\" id=\"104\" desc=\"pakcage body\" >\n        <entry name=\"login\" type=\"CmdLogin\" id=\"CMD_LOGIN\" sizeinfo=\"smalluint\" />\n        <entry name=\"logout\" type=\"CmdLogout\" id=\"CMD_LOGOUT\" sizeinfo=\"smalluint\" />\n        <entry name=\"xxx\" type=\"CmdXXXPrevious\" id=\"CMD_STRUCT\" />\n    </union>\n    <struct name=\"PkgPrevious\" versionindicator=\"head.version\" version=\"1\" id=\"105\" sizeinfo=\"int\" >\n        <entry name=\"head\" type=\"PkgHeadPrevious\" id=\"PKG_HEADER\" />\n        <entry name=\"body\" type=\"PkgBodyPrevious\" id=\"PKG_BODY\" select=\"head.cmd\" version=\"2\" sizeinfo=\"head.bodyLen\" />\n    </struct>\n</metalib>\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_protocol.xml.meta",
    "content": "fileFormatVersion: 2\nguid: 3b1bbaf398add15499486b67e8211845\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_protocol_v4.xml",
    "content": "<?xml version=\"1.0\" ?>\n<metalib name=\"net\" version=\"4\" >\n    <include file=\"non_tlv_net_msg_type.xml\" />\n    <struct name=\"PkgHead\" version=\"1\" id=\"3\" desc=\"package header\" >\n        <entry name=\"magic\" type=\"smallint\" id=\"1\" defaultvalue=\"13124\" />\n        <entry name=\"msgid\" type=\"biguint\" id=\"2\" />\n        <entry name=\"cmd\" type=\"smallint\" id=\"3\" />\n        <entry name=\"version\" type=\"smallint\" id=\"4\" />\n        <entry name=\"bodyLen\" type=\"smallint\" id=\"5\" />\n        <entry name=\"datetime\" type=\"datetime\" id=\"6\" version=\"2\" />\n        <entry name=\"srcIp\" type=\"ip\" id=\"7\" version=\"3\" />\n\t\t<entry name=\"destIp\" type=\"ip\" id=\"8\" version=\"4\" />\n    </struct>\n    <macrosgroup name=\"NET_CMD_ID\" >\n        <macro name=\"CMD_LOGIN\" value=\"1\" />\n        <macro name=\"CMD_LOGOUT\" value=\"2\" />\n        <macro name=\"CMD_STRUCT\" value=\"3\" />\n        <macro name=\"CMD_EXT1\" value=\"13\" />\n        <macro name=\"CMD_EXT2_MIN\" value=\"70\" />\n        <macro name=\"CMD_EXT2_MAX\" value=\"80\" />\n        <macro name=\"CMD_EXT3\" value=\"15\" />\n        <macro name=\"CMD_EXT4\" value=\"100\" />\n    </macrosgroup>\n    <union name=\"PkgBody\" version=\"2\" id=\"4\" desc=\"pakcage body\" >\n        <entry name=\"login\" type=\"CmdLogin\" id=\"CMD_LOGIN\" sizeinfo=\"smalluint\" />\n        <entry name=\"logout\" type=\"CmdLogout\" id=\"CMD_LOGOUT\" sizeinfo=\"smalluint\" />\n        <entry name=\"xxx\" type=\"CmdXXX\" id=\"CMD_STRUCT\" />\n        <!-- no id --><entry name=\"ext1\" type=\"int\" version=\"3\" />\n        <!-- minid & maxid --><entry name=\"ext2\" type=\"byte\" minid=\"CMD_EXT2_MIN\" maxid=\"CMD_EXT2_MAX\" count=\"3\" version=\"3\" />\n        <entry name=\"ext3\" type=\"string\" id=\"CMD_EXT3\" size=\"40\" count=\"2\" defaultvalue=\"string: ext3\" version=\"3\" />\n        <entry name=\"ext4\" type=\"string\" id=\"CMD_EXT4\" size=\"40\" version=\"3\" />\n    </union>\n    <macrosgroup name=\"PKG_ID\" >\n        <macro name=\"PKG_HEADER\" value=\"1\" />\n        <macro name=\"PKG_BODY\" value=\"2\" />\n    </macrosgroup>\n    <struct name=\"Pkg\" versionindicator=\"head.version\" version=\"1\" id=\"5\" sizeinfo=\"int\" >\n        <entry name=\"head\" type=\"PkgHead\" id=\"PKG_HEADER\" />\n        <entry name=\"body\" type=\"PkgBody\" id=\"PKG_BODY\" select=\"head.cmd\" version=\"2\" sizeinfo=\"head.bodyLen\" />\n    </struct>\n    \n    \n    <!-- Test version compatibility -->\n    <struct name=\"PkgHeadPrevious\" version=\"1\" id=\"103\" desc=\"package header\" >\n        <entry name=\"magic\" type=\"smallint\" id=\"1\" defaultvalue=\"13124\" />\n        <entry name=\"msgid\" type=\"biguint\" id=\"2\" />\n        <entry name=\"cmd\" type=\"smallint\" id=\"3\" />\n        <entry name=\"version\" type=\"smallint\" id=\"4\" />\n        <entry name=\"bodyLen\" type=\"smallint\" id=\"5\" />\n        <entry name=\"datetime\" type=\"datetime\" id=\"6\" version=\"2\" />\n    </struct>\n    <union name=\"PkgBodyPrevious\" version=\"2\" id=\"104\" desc=\"pakcage body\" >\n        <entry name=\"login\" type=\"CmdLogin\" id=\"CMD_LOGIN\" sizeinfo=\"smalluint\" />\n        <entry name=\"logout\" type=\"CmdLogout\" id=\"CMD_LOGOUT\" sizeinfo=\"smalluint\" />\n        <entry name=\"xxx\" type=\"CmdXXXPrevious\" id=\"CMD_STRUCT\" />\n    </union>\n    <struct name=\"PkgPrevious\" versionindicator=\"head.version\" version=\"1\" id=\"105\" sizeinfo=\"int\" >\n        <entry name=\"head\" type=\"PkgHeadPrevious\" id=\"PKG_HEADER\" />\n        <entry name=\"body\" type=\"PkgBodyPrevious\" id=\"PKG_BODY\" select=\"head.cmd\" version=\"2\" sizeinfo=\"head.bodyLen\" />\n    </struct>\n</metalib>\n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/non_tlv_net_protocol_v4.xml.meta",
    "content": "fileFormatVersion: 2\nguid: 657558324b4147b42b960f741e98d671\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/testxxx.tdr.bytes.meta",
    "content": "fileFormatVersion: 2\nguid: 8a08842234ae5524396a80430fe94928\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources/testxxx2.tdr.bytes.meta",
    "content": "fileFormatVersion: 2\nguid: d91f27258b672db439cd96a0d141fcc3\ntimeCreated: 1483527551\nlicenseType: Pro\nTextScriptImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/Resources.meta",
    "content": "fileFormatVersion: 2\nguid: 9331fb732c3f3e34aa1642e545db60f4\nfolderAsset: yes\ntimeCreated: 1483527547\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "Test/UnitTest/xLuaTest/main.unity.meta",
    "content": "fileFormatVersion: 2\nguid: abaec912059a37f4cb0397ad29113f61\ntimeCreated: 1483528414\nlicenseType: Pro\nDefaultImporter:\n  userData: \n  assetBundleName: \n  assetBundleVariant: \n"
  },
  {
    "path": "WebGLPlugins/i64lib.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"i64lib.h\"\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n\n#if ( defined (_WIN32) ||  defined (_WIN64) ) && !defined (__MINGW32__) && !defined (__MINGW64__)\n\n#if !defined(PRId64)\n# if __WORDSIZE == 64  \n#  define PRId64    \"ld\"   \n# else  \n#  define PRId64    \"lld\"  \n# endif \n#endif\n\n#if !defined(PRIu64)\n# if __WORDSIZE == 64  \n#  define PRIu64    \"lu\"   \n# else  \n#  define PRIu64    \"llu\"  \n# endif\n#endif\n\n#else\n#include <inttypes.h>\n#endif\n\n#if LUA_VERSION_NUM == 501\n\n#define INT64_META_REF 8\n\nenum IntegerType {\n\tInt,\n\tUInt,\n\tNum\n};\n\ntypedef struct {\n\tint fake_id;\n\tint8_t type;\n    union {\n\t\tint64_t i64;\n\t\tuint64_t u64;\n\t} data;\n} Integer64;\n\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n) {\n\tInteger64* p = (Integer64*)lua_newuserdata(L, sizeof(Integer64));\n\tp->fake_id = -1;\n\tp->data.i64 = n;\n\tp->type = Int;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n\tlua_setmetatable(L, -2);            \n}\n\nLUALIB_API int lua_isint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal && (p->type == Int);\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API int lua_isint64_or_uint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal;\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos) {\n    int64_t n = 0;\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n = (int64_t)lua_tonumber(L, pos);\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isint64_or_uint64(L, pos)) {\n\t\t\t\tn = ((Integer64*)lua_touserdata(L, pos))->data.i64;\n\t\t\t}\n\t\t\tbreak;\n        default:\n            break;\n    }\n    \n    return n;\n}\n\n#if defined(UINT_ESPECIALLY)\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tInteger64* p = (Integer64*)lua_newuserdata(L, sizeof(Integer64));\n\tp->fake_id = -1;\n\tp->data.u64 = n;\n\tp->type = UInt;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n\tlua_setmetatable(L, -2);            \n}\n\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal && (p->type == UInt);\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n    uint64_t n = 0;\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n = (int64_t)lua_tonumber(L, pos);\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isint64_or_uint64(L, pos)) {\n\t\t\t\tn = ((Integer64*)lua_touserdata(L, pos))->data.u64;\n\t\t\t}\n\t\t\tbreak;\n        default:\n            break;\n    }\n    \n    return n;\n}\n#else\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tlua_pushint64(L, (int64_t)n);\n}\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n    return lua_isint64(L, pos);\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n    return (uint64_t)lua_toint64(L, pos);\n}\n#endif\n\nLUALIB_API int lua_isinteger64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal;\n        }\n    }\n\n    return 0;\n}\n\nstatic Integer64 lua_checkinteger64(lua_State* L, int pos) {\n    Integer64 n = {0};\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n.data.i64 = (int64_t)lua_tonumber(L, pos);\n\t\t\tn.type = Num;\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isinteger64(L, pos)) {\n\t\t\t\tn = *(Integer64*)lua_touserdata(L, pos);\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tluaL_typerror(L, pos, \"Integer64\");\n\t\t\t\treturn n;\n\t\t\t}\n        default:\n            luaL_typerror(L, pos, \"Integer64\");\n\t\t\treturn n;\n    }\n    \n    return n;\n}\n\nstatic int int64_add(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 + rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 + rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_sub(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 - rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 - rhs.data.i64);\n\t}\n    return 1;\n}\n\n\nstatic int int64_mul(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 * rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 * rhs.data.i64);\n\t}\n    return 1;    \n}\n\nstatic int int64_div(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (rhs.data.i64 == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 / rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 / rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_mod(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\n    if (rhs.data.i64 == 0) {\n        return luaL_error(L, \"mod by zero\");\n    }\n\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 % rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 % rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_unm(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1); \n    lua_pushint64(L, -lhs.data.i64);\n    return 1;\n}\n\nstatic int int64_pow(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, pow(lhs.data.u64, rhs.data.u64));\n\t} else {\n\t\tlua_pushint64(L, pow(lhs.data.i64, rhs.data.i64));\n\t}\n    return 1;\n}\n\nstatic int int64_eq(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);     \n    Integer64 rhs = lua_checkinteger64(L, 2); \n    \n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 == rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 == rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_lt(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1); \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 < rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 < rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_le(lua_State* L) {\n\tInteger64 lhs = lua_checkinteger64(L, 1); \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 <= rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 <= rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_tostring(lua_State* L) { \n    char temp[72];\n\tInteger64 lhs = lua_checkinteger64(L, 1); \n\tif (lhs.type == UInt) {\n\t\tsprintf(temp, \"%\"PRIu64\"U\", lhs.data.u64);\n\t} else {\n\t\tsprintf(temp, \"%\"PRId64, lhs.data.i64);\n\t}\t\t\n    lua_pushstring(L, temp);\n    return 1;\n}\n\n#endif\n\n#if LUA_VERSION_NUM == 503\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n) {\n\tlua_pushinteger(L, n);\n}\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tlua_pushinteger(L, n);\n}\n\nLUALIB_API int lua_isint64(lua_State* L, int pos) {\n\treturn lua_isinteger(L, pos);\n}\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n\treturn lua_isinteger(L, pos);\n}\n\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos) {\n\treturn lua_tointeger(L, pos);\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n\treturn lua_tointeger(L, pos);\n}\n#endif\n\nstatic int uint64_tostring(lua_State* L) {\n\tchar temp[72];\n\tuint64_t n = lua_touint64(L, 1);\n#if ( defined (_WIN32) ||  defined (_WIN64) ) && !defined (__MINGW32__) && !defined (__MINGW64__)\n\tsprintf_s(temp, sizeof(temp), \"%\" PRIu64, n);\n#else\n\tsnprintf(temp, sizeof(temp), \"%\" PRIu64, n);\n#endif\n\t\n\tlua_pushstring(L, temp);\n\t\n\treturn 1;\n}\n\nstatic int uint64_compare(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tlua_pushinteger(L, lhs == rhs ? 0 : (lhs < rhs ? -1 : 1));\n\treturn 1;\n}\n\nstatic int uint64_divide(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tif (rhs == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\tlua_pushuint64(L, lhs / rhs);\n\treturn 1;\n}\n\nstatic int uint64_remainder(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tif (rhs == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\tlua_pushuint64(L, lhs % rhs);\n\treturn 1;\n}\n\nLUALIB_API int uint64_parse(lua_State* L)\n{\n    const char* str = lua_tostring(L, 1);\n    lua_pushuint64(L, strtoull(str, NULL, 0));\n    return 1;\n}\n\nLUALIB_API int luaopen_i64lib(lua_State* L)\n{\n#if LUA_VERSION_NUM == 501\n    lua_newtable(L);\n\t\n    lua_pushcfunction(L, int64_add);\n    lua_setfield(L, -2, \"__add\");\n\n    lua_pushcfunction(L, int64_sub);\n    lua_setfield(L, -2, \"__sub\");\n\n    lua_pushcfunction(L, int64_mul);\n    lua_setfield(L, -2, \"__mul\");\n\n    lua_pushcfunction(L, int64_div);\n    lua_setfield(L, -2, \"__div\");\n\n    lua_pushcfunction(L, int64_mod);\n    lua_setfield(L, -2, \"__mod\");\n\n    lua_pushcfunction(L, int64_unm);\n    lua_setfield(L, -2, \"__unm\");\n\n    lua_pushcfunction(L, int64_pow);\n    lua_setfield(L, -2, \"__pow\");    \n\n    lua_pushcfunction(L, int64_tostring);\n    lua_setfield(L, -2, \"__tostring\");        \n\n    lua_pushcfunction(L, int64_eq);\n    lua_setfield(L, -2, \"__eq\");  \n\n    lua_pushcfunction(L, int64_lt);\n    lua_setfield(L, -2, \"__lt\"); \n\n    lua_pushcfunction(L, int64_le);\n    lua_setfield(L, -2, \"__le\");\n\t\n\tlua_rawseti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n#endif\n    lua_newtable(L);\n\t\n\tlua_pushcfunction(L, uint64_tostring);\n\tlua_setfield(L, -2, \"tostring\");\n\t\n\tlua_pushcfunction(L, uint64_compare);\n\tlua_setfield(L, -2, \"compare\");\n\t\n\tlua_pushcfunction(L, uint64_divide);\n\tlua_setfield(L, -2, \"divide\");\n\t\n\tlua_pushcfunction(L, uint64_remainder);\n\tlua_setfield(L, -2, \"remainder\");\n\t\n\tlua_pushcfunction(L, uint64_parse);\n\tlua_setfield(L, -2, \"parse\");\n\t\n\tlua_setglobal(L, \"uint64\");\n\treturn 0;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/i64lib.h",
    "content": "/*\r\n *Tencent is pleased to support the open source community by making xLua available.\r\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n *http://opensource.org/licenses/MIT\r\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#ifndef I64LIB_H\r\n#define I64LIB_H\r\n\r\n#include <stdint.h>\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n#include \"lualib.h\"\r\n\r\n#ifdef __cplusplus\r\n#if __cplusplus\r\nextern \"C\"{\r\n#endif\r\n#endif /* __cplusplus */\r\n\r\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n);\r\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n);\r\n\r\nLUALIB_API int lua_isint64(lua_State* L, int pos);\r\nLUALIB_API int lua_isuint64(lua_State* L, int pos);\r\n\r\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos);\r\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos);\r\n\r\n#ifdef __cplusplus\r\n#if __cplusplus\r\n}\r\n#endif\r\n#endif /* __cplusplus */ \r\n\r\n\r\n#endif"
  },
  {
    "path": "WebGLPlugins/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$LuaVersion: \" LUA_COPYRIGHT \" $\"\n  \"$LuaAuthors: \" LUA_AUTHORS \" $\";\n\n\n/* value at a non-valid index */\n#define NONVALIDVALUE\t\tcast(TValue *, luaO_nilobject)\n\n/* corresponding test */\n#define isvalid(o)\t((o) != luaO_nilobject)\n\n/* test for pseudo index */\n#define ispseudo(i)\t\t((i) <= LUA_REGISTRYINDEX)\n\n/* test for upvalue */\n#define isupvalue(i)\t\t((i) < LUA_REGISTRYINDEX)\n\n/* test for valid but not pseudo index */\n#define isstackindex(i, o)\t(isvalid(o) && !ispseudo(i))\n\n#define api_checkvalidindex(l,o)  api_check(l, isvalid(o), \"invalid index\")\n\n#define api_checkstackindex(l, i, o)  \\\n\tapi_check(l, isstackindex(i, o), \"index not in the stack\")\n\n\nstatic TValue *index2addr (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    TValue *o = ci->func + idx;\n    api_check(L, idx <= ci->top - (ci->func + 1), \"unacceptable index\");\n    if (o >= L->top) return NONVALIDVALUE;\n    else return o;\n  }\n  else if (!ispseudo(idx)) {  /* negative index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    return L->top + idx;\n  }\n  else if (idx == LUA_REGISTRYINDEX)\n    return &G(L)->l_registry;\n  else {  /* upvalues */\n    idx = LUA_REGISTRYINDEX - idx;\n    api_check(L, idx <= MAXUPVAL + 1, \"upvalue index too large\");\n    if (ttislcf(ci->func))  /* light C function? */\n      return NONVALIDVALUE;  /* it has no upvalues */\n    else {\n      CClosure *func = clCvalue(ci->func);\n      return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;\n    }\n  }\n}\n\n\n/*\n** to be called by 'lua_checkstack' in protected mode, to grow stack\n** capturing memory errors\n*/\nstatic void growstack (lua_State *L, void *ud) {\n  int size = *(int *)ud;\n  luaD_growstack(L, size);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int n) {\n  int res;\n  CallInfo *ci = L->ci;\n  lua_lock(L);\n  api_check(L, n >= 0, \"negative 'n'\");\n  if (L->stack_last - L->top > n)  /* stack large enough? */\n    res = 1;  /* yes; check is OK */\n  else {  /* no; need to grow stack */\n    int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;\n    if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */\n      res = 0;  /* no */\n    else  /* try to grow stack */\n      res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK);\n  }\n  if (res && ci->top < L->top + n)\n    ci->top = L->top + n;  /* adjust frame top */\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to), \"moving among independent states\");\n  api_check(from, to->ci->top - to->top >= n, \"stack overflow\");\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobj2s(to, to->top, from->top + i);\n    to->top++;  /* stack already checked by previous 'api_check' */\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API const lua_Number *lua_version (lua_State *L) {\n  static const lua_Number version = LUA_VERSION_NUM;\n  if (L == NULL) return &version;\n  else return G(L)->version;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\n/*\n** convert an acceptable stack index into an absolute index\n*/\nLUA_API int lua_absindex (lua_State *L, int idx) {\n  return (idx > 0 || ispseudo(idx))\n         ? idx\n         : cast_int(L->top - L->ci->func) + idx;\n}\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - (L->ci->func + 1));\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  StkId func = L->ci->func;\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - (func + 1), \"new top too large\");\n    while (L->top < (func + 1) + idx)\n      setnilvalue(L->top++);\n    L->top = (func + 1) + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - (func + 1)), \"invalid new top\");\n    L->top += idx+1;  /* 'subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\n/*\n** Reverse the stack segment from 'from' to 'to'\n** (auxiliary to 'lua_rotate')\n*/\nstatic void reverse (lua_State *L, StkId from, StkId to) {\n  for (; from < to; from++, to--) {\n    TValue temp;\n    setobj(L, &temp, from);\n    setobjs2s(L, from, to);\n    setobj2s(L, to, &temp);\n  }\n}\n\n\n/*\n** Let x = AB, where A is a prefix of length 'n'. Then,\n** rotate x n == BA. But BA == (A^r . B^r)^r.\n*/\nLUA_API void lua_rotate (lua_State *L, int idx, int n) {\n  StkId p, t, m;\n  lua_lock(L);\n  t = L->top - 1;  /* end of stack segment being rotated */\n  p = index2addr(L, idx);  /* start of segment */\n  api_checkstackindex(L, idx, p);\n  api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), \"invalid 'n'\");\n  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */\n  reverse(L, p, m);  /* reverse the prefix with length 'n' */\n  reverse(L, m + 1, t);  /* reverse the suffix */\n  reverse(L, p, t);  /* reverse the entire segment */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {\n  TValue *fr, *to;\n  lua_lock(L);\n  fr = index2addr(L, fromidx);\n  to = index2addr(L, toidx);\n  api_checkvalidindex(L, to);\n  setobj(L, to, fr);\n  if (isupvalue(toidx))  /* function upvalue? */\n    luaC_barrier(L, clCvalue(L->ci->func), fr);\n  /* LUA_REGISTRYINDEX does not need gc barrier\n     (collector revisits it before finishing collection) */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2addr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (isvalid(o) ? ttnov(o) : LUA_TNONE);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, \"invalid tag\");\n  return ttypename(t);\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (ttislcf(o) || (ttisCclosure(o)));\n}\n\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return ttisinteger(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisstring(o) || cvt2str(o));\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisfulluserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2addr(L, index1);\n  StkId o2 = index2addr(L, index2);\n  return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;\n}\n\n\nLUA_API void lua_arith (lua_State *L, int op) {\n  lua_lock(L);\n  if (op != LUA_OPUNM && op != LUA_OPBNOT)\n    api_checknelems(L, 2);  /* all other operations expect two operands */\n  else {  /* for unary operations, add fake 2nd operand */\n    api_checknelems(L, 1);\n    setobjs2s(L, L->top, L->top - 1);\n    api_incr_top(L);\n  }\n  /* first operand at top - 2, second at top - 1; result go to top - 2 */\n  luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2);\n  L->top--;  /* remove second operand */\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {\n  StkId o1, o2;\n  int i = 0;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2addr(L, index1);\n  o2 = index2addr(L, index2);\n  if (isvalid(o1) && isvalid(o2)) {\n    switch (op) {\n      case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;\n      case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;\n      case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;\n      default: api_check(L, 0, \"invalid option\");\n    }\n  }\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {\n  size_t sz = luaO_str2num(s, L->top);\n  if (sz != 0)\n    api_incr_top(L);\n  return sz;\n}\n\n\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tonumber(o, &n);\n  if (!isnum)\n    n = 0;  /* call to 'tonumber' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return n;\n}\n\n\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {\n  lua_Integer res;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tointeger(o, &res);\n  if (!isnum)\n    res = 0;  /* call to 'tointeger' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return res;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2addr(L, idx);\n  if (!ttisstring(o)) {\n    if (!cvt2str(o)) {  /* not convertible? */\n      if (len != NULL) *len = 0;\n      return NULL;\n    }\n    lua_lock(L);  /* 'luaO_tostring' may create a new string */\n    luaO_tostring(L, o);\n    luaC_checkGC(L);\n    o = index2addr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL)\n    *len = vslen(o);\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_rawlen (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSHRSTR: return tsvalue(o)->shrlen;\n    case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  if (ttislcf(o)) return fvalue(o);\n  else if (ttisCclosure(o))\n    return clCvalue(o)->f;\n  else return NULL;  /* not a C function */\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttnov(o)) {\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TLCL: return clLvalue(o);\n    case LUA_TCCL: return clCvalue(o);\n    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setfltvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setivalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** Pushes on the stack a string with given length. Avoid using 's' when\n** 'len' == 0 (as 's' can be NULL in that case), due to later use of\n** 'memcmp' and 'memcpy'.\n*/\nLUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  TString *ts;\n  lua_lock(L);\n  ts = (len == 0) ? luaS_new(L, \"\") : luaS_newlstr(L, s, len);\n  setsvalue2s(L, L->top, ts);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getstr(ts);\n}\n\n\nLUA_API const char *lua_pushstring (lua_State *L, const char *s) {\n  lua_lock(L);\n  if (s == NULL)\n    setnilvalue(L->top);\n  else {\n    TString *ts;\n    ts = luaS_new(L, s);\n    setsvalue2s(L, L->top, ts);\n    s = getstr(ts);  /* internal copy's address */\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return s;\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  lua_lock(L);\n  if (n == 0) {\n    setfvalue(L->top, fn);\n  }\n  else {\n    CClosure *cl;\n    api_checknelems(L, n);\n    api_check(L, n <= MAXUPVAL, \"upvalue index too large\");\n    cl = luaF_newCclosure(L, n);\n    cl->f = fn;\n    L->top -= n;\n    while (n--) {\n      setobj2n(L, &cl->upvalue[n], L->top + n);\n      /* does not need barrier because closure is white */\n    }\n    setclCvalue(L, L->top, cl);\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(L->top, p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nstatic int auxgetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setsvalue2s(L, L->top, str);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);\n  return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API int lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);\n  return auxgetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  if (luaV_fastget(L, t, n, slot, luaH_getint)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top, luaH_getint(hvalue(t), n));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {\n  StkId t;\n  TValue k;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  setobj2s(L, L->top, luaH_get(hvalue(t), &k));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  Table *t;\n  lua_lock(L);\n  t = luaH_new(L);\n  sethvalue(L, L->top, t);\n  api_incr_top(L);\n  if (narray > 0 || nrec > 0)\n    luaH_resize(L, t, narray, nrec);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt;\n  int res = 0;\n  lua_lock(L);\n  obj = index2addr(L, objindex);\n  switch (ttnov(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(obj)];\n      break;\n  }\n  if (mt != NULL) {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API int lua_getuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  getuservalue(L, uvalue(o), L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n/*\n** t[k] = value at the top of the stack (where 'k' is a string)\n*/\nstatic void auxsetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  api_checknelems(L, 1);\n  if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);  /* lock done by caller */\n}\n\n\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2addr(L, idx);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2addr(L, idx);\n  if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId o;\n  TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  slot = luaH_set(L, hvalue(o), L->top - 2);\n  setobj2t(L, slot, L->top - 1);\n  invalidateTMcache(hvalue(o));\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  luaH_setint(L, hvalue(o), n, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {\n  StkId o;\n  TValue k, *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  slot = luaH_set(L, hvalue(o), &k);\n  setobj2t(L, slot, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2addr(L, objindex);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1), \"table expected\");\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttnov(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, gcvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, uvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    default: {\n      G(L)->mt[ttnov(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API void lua_setuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  setuservalue(L, uvalue(o), L->top - 1);\n  luaC_barrier(L, gcvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\n/*\n** 'load' and 'call' functions (run Lua code)\n*/\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \\\n\t\"results from function overflow current stack size\")\n\n\nLUA_API void lua_callk (lua_State *L, int nargs, int nresults,\n                        lua_KContext ctx, lua_KFunction k) {\n  StkId func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  if (k != NULL && L->nny == 0) {  /* need to prepare continuation? */\n    L->ci->u.c.k = k;  /* save continuation */\n    L->ci->u.c.ctx = ctx;  /* save context */\n    luaD_call(L, func, nresults);  /* do the call */\n  }\n  else  /* no continuation or no yieldable */\n    luaD_callnoyield(L, func, nresults);  /* just do the call */\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to 'f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_callnoyield(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,\n                        lua_KContext ctx, lua_KFunction k) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2addr(L, errfunc);\n    api_checkstackindex(L, errfunc, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  if (k == NULL || L->nny > 0) {  /* no continuation or no yieldable? */\n    c.nresults = nresults;  /* do a 'conventional' protected call */\n    status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  }\n  else {  /* prepare continuation (call is already protected by 'resume') */\n    CallInfo *ci = L->ci;\n    ci->u.c.k = k;  /* save continuation */\n    ci->u.c.ctx = ctx;  /* save context */\n    /* save information for error recovery */\n    ci->extra = savestack(L, c.func);\n    ci->u.c.old_errfunc = L->errfunc;\n    L->errfunc = func;\n    setoah(ci->callstatus, L->allowhook);  /* save value of 'allowhook' */\n    ci->callstatus |= CIST_YPCALL;  /* function can do error recovery */\n    luaD_call(L, c.func, nresults);  /* do the call */\n    ci->callstatus &= ~CIST_YPCALL;\n    L->errfunc = ci->u.c.old_errfunc;\n    status = LUA_OK;  /* if it is here, there were no errors */\n  }\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname, const char *mode) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname, mode);\n  if (status == LUA_OK) {  /* no errors? */\n    LClosure *f = clLvalue(L->top - 1);  /* get newly created function */\n    if (f->nupvalues >= 1) {  /* does it have an upvalue? */\n      /* get global table from registry */\n      Table *reg = hvalue(&G(L)->l_registry);\n      const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);\n      /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */\n      setobj(L, f->upvals[0]->v, gt);\n      luaC_upvalbarrier(L, f->upvals[0]);\n    }\n  }\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, getproto(o), writer, data, strip);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->gcrunning = 0;\n      break;\n    }\n    case LUA_GCRESTART: {\n      luaE_setdebt(g, 0);\n      g->gcrunning = 1;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L, 0);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(gettotalbytes(g) >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(gettotalbytes(g) & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      l_mem debt = 1;  /* =1 to signal that it did an actual step */\n      lu_byte oldrunning = g->gcrunning;\n      g->gcrunning = 1;  /* allow GC to run */\n      if (data == 0) {\n        luaE_setdebt(g, -GCSTEPSIZE);  /* to do a \"small\" step */\n        luaC_step(L);\n      }\n      else {  /* add 'data' to total debt */\n        debt = cast(l_mem, data) * 1024 + g->GCdebt;\n        luaE_setdebt(g, debt);\n        luaC_checkGC(L);\n      }\n      g->gcrunning = oldrunning;  /* restore previous state */\n      if (debt > 0 && g->gcstate == GCSpause)  /* end of cycle? */\n        res = 1;  /* signal it */\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      if (data < 40) data = 40;  /* avoid ridiculous low values (and 0) */\n      g->gcstepmul = data;\n      break;\n    }\n    case LUA_GCISRUNNING: {\n      res = g->gcrunning;\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  /* code unreachable; will unlock when control actually leaves the kernel */\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaV_concat(L, n);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_len (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_objlen(L, L->top, t);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  u = luaS_newudata(L, size);\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getudatamem(u);\n}\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val,\n                                CClosure **owner, UpVal **uv) {\n  switch (ttype(fi)) {\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      if (!(1 <= n && n <= f->nupvalues)) return NULL;\n      *val = &f->upvalue[n-1];\n      if (owner) *owner = f;\n      return \"\";\n    }\n    case LUA_TLCL: {  /* Lua closure */\n      LClosure *f = clLvalue(fi);\n      TString *name;\n      Proto *p = f->p;\n      if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n      *val = f->upvals[n-1]->v;\n      if (uv) *uv = f->upvals[n - 1];\n      name = p->upvalues[n-1].name;\n      return (name == NULL) ? \"(*no name)\" : getstr(name);\n    }\n    default: return NULL;  /* not a closure */\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  lua_lock(L);\n  name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  CClosure *owner = NULL;\n  UpVal *uv = NULL;\n  StkId fi;\n  lua_lock(L);\n  fi = index2addr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val, &owner, &uv);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    if (owner) { luaC_barrier(L, owner, L->top); }\n    else if (uv) { luaC_upvalbarrier(L, uv); }\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {\n  LClosure *f;\n  StkId fi = index2addr(L, fidx);\n  api_check(L, ttisLclosure(fi), \"Lua function expected\");\n  f = clLvalue(fi);\n  api_check(L, (1 <= n && n <= f->p->sizeupvalues), \"invalid upvalue index\");\n  if (pf) *pf = f;\n  return &f->upvals[n - 1];  /* get its upvalue pointer */\n}\n\n\nLUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {\n  StkId fi = index2addr(L, fidx);\n  switch (ttype(fi)) {\n    case LUA_TLCL: {  /* lua closure */\n      return *getupvalref(L, fidx, n, NULL);\n    }\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      api_check(L, 1 <= n && n <= f->nupvalues, \"invalid upvalue index\");\n      return &f->upvalue[n - 1];\n    }\n    default: {\n      api_check(L, 0, \"closure expected\");\n      return NULL;\n    }\n  }\n}\n\n\nLUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,\n                                            int fidx2, int n2) {\n  LClosure *f1;\n  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);\n  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);\n  luaC_upvdeccount(L, *up1);\n  *up1 = *up2;\n  (*up1)->refcount++;\n  if (upisopen(*up1)) (*up1)->u.open.touched = 1;\n  luaC_upvalbarrier(L, *up1);\n}\n\n\n"
  },
  {
    "path": "WebGLPlugins/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"llimits.h\"\n#include \"lstate.h\"\n\n#define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \\\n\t\t\t\t\"stack overflow\");}\n\n#define adjustresults(L,nres) \\\n    { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }\n\n#define api_checknelems(L,n)\tapi_check(L, (n) < (L->top - L->ci->func), \\\n\t\t\t\t  \"not enough elements in the stack\")\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/*\n** This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n/*\n** {======================================================\n** Traceback\n** =======================================================\n*/\n\n\n#define LEVELS1\t10\t/* size of the first part of the stack */\n#define LEVELS2\t11\t/* size of the second part of the stack */\n\n\n\n/*\n** search for 'objidx' in table at index -1.\n** return 1 + string at top if find a good name.\n*/\nstatic int findfield (lua_State *L, int objidx, int level) {\n  if (level == 0 || !lua_istable(L, -1))\n    return 0;  /* not found */\n  lua_pushnil(L);  /* start 'next' loop */\n  while (lua_next(L, -2)) {  /* for each pair in table */\n    if (lua_type(L, -2) == LUA_TSTRING) {  /* ignore non-string keys */\n      if (lua_rawequal(L, objidx, -1)) {  /* found object? */\n        lua_pop(L, 1);  /* remove value (but keep name) */\n        return 1;\n      }\n      else if (findfield(L, objidx, level - 1)) {  /* try recursively */\n        lua_remove(L, -2);  /* remove table (but keep name) */\n        lua_pushliteral(L, \".\");\n        lua_insert(L, -2);  /* place '.' between the two names */\n        lua_concat(L, 3);\n        return 1;\n      }\n    }\n    lua_pop(L, 1);  /* remove value */\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Search for a name for a function in all loaded modules\n*/\nstatic int pushglobalfuncname (lua_State *L, lua_Debug *ar) {\n  int top = lua_gettop(L);\n  lua_getinfo(L, \"f\", ar);  /* push function */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  if (findfield(L, top + 1, 2)) {\n    const char *name = lua_tostring(L, -1);\n    if (strncmp(name, \"_G.\", 3) == 0) {  /* name start with '_G.'? */\n      lua_pushstring(L, name + 3);  /* push name without prefix */\n      lua_remove(L, -2);  /* remove original name */\n    }\n    lua_copy(L, -1, top + 1);  /* move name to proper place */\n    lua_pop(L, 2);  /* remove pushed values */\n    return 1;\n  }\n  else {\n    lua_settop(L, top);  /* remove function and global table */\n    return 0;\n  }\n}\n\n\nstatic void pushfuncname (lua_State *L, lua_Debug *ar) {\n  if (pushglobalfuncname(L, ar)) {  /* try first a global name */\n    lua_pushfstring(L, \"function '%s'\", lua_tostring(L, -1));\n    lua_remove(L, -2);  /* remove name */\n  }\n  else if (*ar->namewhat != '\\0')  /* is there a name from code? */\n    lua_pushfstring(L, \"%s '%s'\", ar->namewhat, ar->name);  /* use it */\n  else if (*ar->what == 'm')  /* main? */\n      lua_pushliteral(L, \"main chunk\");\n  else if (*ar->what != 'C')  /* for Lua functions, use <file:line> */\n    lua_pushfstring(L, \"function <%s:%d>\", ar->short_src, ar->linedefined);\n  else  /* nothing left... */\n    lua_pushliteral(L, \"?\");\n}\n\n\nstatic int lastlevel (lua_State *L) {\n  lua_Debug ar;\n  int li = 1, le = 1;\n  /* find an upper bound */\n  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }\n  /* do a binary search */\n  while (li < le) {\n    int m = (li + le)/2;\n    if (lua_getstack(L, m, &ar)) li = m + 1;\n    else le = m;\n  }\n  return le - 1;\n}\n\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,\n                                const char *msg, int level) {\n  lua_Debug ar;\n  int top = lua_gettop(L);\n  int last = lastlevel(L1);\n  int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;\n  if (msg)\n    lua_pushfstring(L, \"%s\\n\", msg);\n  luaL_checkstack(L, 10, NULL);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (n1-- == 0) {  /* too many levels? */\n      lua_pushliteral(L, \"\\n\\t...\");  /* add a '...' */\n      level = last - LEVELS2 + 1;  /* and skip to last ones */\n    }\n    else {\n      lua_getinfo(L1, \"Slnt\", &ar);\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n      if (ar.currentline > 0)\n        lua_pushfstring(L, \"%d:\", ar.currentline);\n      lua_pushliteral(L, \" in \");\n      pushfuncname(L, &ar);\n      if (ar.istailcall)\n        lua_pushliteral(L, \"\\n\\t(...tail calls...)\");\n      lua_concat(L, lua_gettop(L) - top);\n    }\n  }\n  lua_concat(L, lua_gettop(L) - top);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", arg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    arg--;  /* do not count 'self' */\n    if (arg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling '%s' on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : \"?\";\n  return luaL_error(L, \"bad argument #%d to '%s' (%s)\",\n                        arg, ar.name, extramsg);\n}\n\n\nstatic int typeerror (lua_State *L, int arg, const char *tname) {\n  const char *msg;\n  const char *typearg;  /* name for the type of the actual argument */\n  if (luaL_getmetafield(L, arg, \"__name\") == LUA_TSTRING)\n    typearg = lua_tostring(L, -1);  /* use the given type name */\n  else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)\n    typearg = \"light userdata\";  /* special name for messages */\n  else\n    typearg = luaL_typename(L, arg);  /* standard name */\n  msg = lua_pushfstring(L, \"%s expected, got %s\", tname, typearg);\n  return luaL_argerror(L, arg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int arg, int tag) {\n  typeerror(L, arg, lua_typename(L, tag));\n}\n\n\n/*\n** The use of 'lua_pushfstring' ensures this function does not\n** need reserved stack space when called.\n*/\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushfstring(L, \"\");  /* else, no information available... */\n}\n\n\n/*\n** Again, the use of 'lua_pushvfstring' ensures this function does\n** not need reserved stack space when called. (At worst, it generates\n** an error with \"stack overflow\" instead of the given message.)\n*/\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n\nLUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (stat) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushstring(L, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n#if !defined(l_inspectstat)\t/* { */\n\n#if defined(LUA_USE_POSIX)\n\n#include <sys/wait.h>\n\n/*\n** use appropriate macros to interpret 'pclose' return status\n*/\n#define l_inspectstat(stat,what)  \\\n   if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \\\n   else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = \"signal\"; }\n\n#else\n\n#define l_inspectstat(stat,what)  /* no op */\n\n#endif\n\n#endif\t\t\t\t/* } */\n\n\nLUALIB_API int luaL_execresult (lua_State *L, int stat) {\n  const char *what = \"exit\";  /* type of termination */\n  if (stat == -1)  /* error? */\n    return luaL_fileresult(L, 0, NULL);\n  else {\n    l_inspectstat(stat, what);  /* interpret result */\n    if (*what == 'e' && stat == 0)  /* successful termination? */\n      lua_pushboolean(L, 1);\n    else\n      lua_pushnil(L);\n    lua_pushstring(L, what);\n    lua_pushinteger(L, stat);\n    return 3;  /* return true/nil,what,code */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Userdata's metatable manipulation\n** =======================================================\n*/\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  if (luaL_getmetatable(L, tname) != LUA_TNIL)  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_createtable(L, 0, 2);  /* create metatable */\n  lua_pushstring(L, tname);\n  lua_setfield(L, -2, \"__name\");  /* metatable.__name = tname */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {\n  luaL_getmetatable(L, tname);\n  lua_setmetatable(L, -2);\n}\n\n\nLUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      luaL_getmetatable(L, tname);  /* get correct metatable */\n      if (!lua_rawequal(L, -1, -2))  /* not the same? */\n        p = NULL;  /* value is a userdata with wrong metatable */\n      lua_pop(L, 2);  /* remove both metatables */\n      return p;\n    }\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = luaL_testudata(L, ud, tname);\n  if (p == NULL) typeerror(L, ud, tname);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Argument check functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, arg, def) :\n                             luaL_checkstring(L, arg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, arg,\n                       lua_pushfstring(L, \"invalid option '%s'\", name));\n}\n\n\n/*\n** Ensures the stack has at least 'space' extra slots, raising an error\n** if it cannot fulfill the request. (The error handling needs a few\n** extra slots to format the error message. In case of an error without\n** this extra space, Lua will generate the same 'stack overflow' error,\n** but without 'msg'.)\n*/\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {\n  if (!lua_checkstack(L, space)) {\n    if (msg)\n      luaL_error(L, \"stack overflow (%s)\", msg);\n    else\n      luaL_error(L, \"stack overflow\");\n  }\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int arg, int t) {\n  if (lua_type(L, arg) != t)\n    tag_error(L, arg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNONE)\n    luaL_argerror(L, arg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) {\n  const char *s = lua_tolstring(L, arg, len);\n  if (!s) tag_error(L, arg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int arg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, arg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, arg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) {\n  int isnum;\n  lua_Number d = lua_tonumberx(L, arg, &isnum);\n  if (!isnum)\n    tag_error(L, arg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, arg, def);\n}\n\n\nstatic void interror (lua_State *L, int arg) {\n  if (lua_isnumber(L, arg))\n    luaL_argerror(L, arg, \"number has no integer representation\");\n  else\n    tag_error(L, arg, LUA_TNUMBER);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {\n  int isnum;\n  lua_Integer d = lua_tointegerx(L, arg, &isnum);\n  if (!isnum) {\n    interror(L, arg);\n  }\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, arg, def);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n/* userdata to box arbitrary data */\ntypedef struct UBox {\n  void *box;\n  size_t bsize;\n} UBox;\n\n\nstatic void *resizebox (lua_State *L, int idx, size_t newsize) {\n  void *ud;\n  lua_Alloc allocf = lua_getallocf(L, &ud);\n  UBox *box = (UBox *)lua_touserdata(L, idx);\n  void *temp = allocf(ud, box->box, box->bsize, newsize);\n  if (temp == NULL && newsize > 0) {  /* allocation error? */\n    resizebox(L, idx, 0);  /* free buffer */\n    luaL_error(L, \"not enough memory for buffer allocation\");\n  }\n  box->box = temp;\n  box->bsize = newsize;\n  return temp;\n}\n\n\nstatic int boxgc (lua_State *L) {\n  resizebox(L, 1, 0);\n  return 0;\n}\n\n\nstatic void *newbox (lua_State *L, size_t newsize) {\n  UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));\n  box->box = NULL;\n  box->bsize = 0;\n  if (luaL_newmetatable(L, \"LUABOX\")) {  /* creating metatable? */\n    lua_pushcfunction(L, boxgc);\n    lua_setfield(L, -2, \"__gc\");  /* metatable.__gc = boxgc */\n  }\n  lua_setmetatable(L, -2);\n  return resizebox(L, -1, newsize);\n}\n\n\n/*\n** check whether buffer is using a userdata on the stack as a temporary\n** buffer\n*/\n#define buffonstack(B)\t((B)->b != (B)->initb)\n\n\n/*\n** returns a pointer to a free area with at least 'sz' bytes\n*/\nLUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {\n  lua_State *L = B->L;\n  if (B->size - B->n < sz) {  /* not enough space? */\n    char *newbuff;\n    size_t newsize = B->size * 2;  /* double buffer size */\n    if (newsize - B->n < sz)  /* not big enough? */\n      newsize = B->n + sz;\n    if (newsize < B->n || newsize - B->n < sz)\n      luaL_error(L, \"buffer too large\");\n    /* create larger buffer */\n    if (buffonstack(B))\n      newbuff = (char *)resizebox(L, -1, newsize);\n    else {  /* no buffer yet */\n      newbuff = (char *)newbox(L, newsize);\n      memcpy(newbuff, B->b, B->n * sizeof(char));  /* copy original content */\n    }\n    B->b = newbuff;\n    B->size = newsize;\n  }\n  return &B->b[B->n];\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */\n    char *b = luaL_prepbuffsize(B, l);\n    memcpy(b, s, l * sizeof(char));\n    luaL_addsize(B, l);\n  }\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  lua_pushlstring(L, B->b, B->n);\n  if (buffonstack(B)) {\n    resizebox(L, -2, 0);  /* delete old buffer */\n    lua_remove(L, -2);  /* remove its header from the stack */\n  }\n}\n\n\nLUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {\n  luaL_addsize(B, sz);\n  luaL_pushresult(B);\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t l;\n  const char *s = lua_tolstring(L, -1, &l);\n  if (buffonstack(B))\n    lua_insert(L, -2);  /* put value below buffer */\n  luaL_addlstring(B, s, l);\n  lua_remove(L, (buffonstack(B)) ? -2 : -1);  /* remove value */\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->b = B->initb;\n  B->n = 0;\n  B->size = LUAL_BUFFERSIZE;\n}\n\n\nLUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {\n  luaL_buffinit(L, B);\n  return luaL_prepbuffsize(B, sz);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Reference system\n** =======================================================\n*/\n\n/* index of free-list header */\n#define freelist\t0\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* 'nil' has a unique fixed reference */\n  }\n  t = lua_absindex(L, t);\n  lua_rawgeti(L, t, freelist);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[freelist] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, freelist);  /* (t[freelist] = t[ref]) */\n  }\n  else  /* no free elements */\n    ref = (int)lua_rawlen(L, t) + 1;  /* get a new reference */\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = lua_absindex(L, t);\n    lua_rawgeti(L, t, freelist);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[freelist] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, freelist);  /* t[freelist] = ref */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int n;  /* number of pre-read characters */\n  FILE *f;  /* file being read */\n  char buff[BUFSIZ];  /* area for reading file */\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;  /* not used */\n  if (lf->n > 0) {  /* are there pre-read characters to be read? */\n    *size = lf->n;  /* return them (chars already in buffer) */\n    lf->n = 0;  /* no more pre-read characters */\n  }\n  else {  /* read a block from file */\n    /* 'fread' can return > 0 *and* set the EOF flag. If next call to\n       'getF' called 'fread', it might still wait for user input.\n       The next check avoids this problem. */\n    if (feof(lf->f)) return NULL;\n    *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */\n  }\n  return lf->buff;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nstatic int skipBOM (LoadF *lf) {\n  const char *p = \"\\xEF\\xBB\\xBF\";  /* UTF-8 BOM mark */\n  int c;\n  lf->n = 0;\n  do {\n    c = getc(lf->f);\n    if (c == EOF || c != *(const unsigned char *)p++) return c;\n    lf->buff[lf->n++] = c;  /* to be read by the parser */\n  } while (*p != '\\0');\n  lf->n = 0;  /* prefix matched; discard it */\n  return getc(lf->f);  /* return next character */\n}\n\n\n/*\n** reads the first character of file 'f' and skips an optional BOM mark\n** in its beginning plus its first line if it starts with '#'. Returns\n** true if it skipped the first line.  In any case, '*cp' has the\n** first \"valid\" character of the file (after the optional BOM and\n** a first-line comment).\n*/\nstatic int skipcomment (LoadF *lf, int *cp) {\n  int c = *cp = skipBOM(lf);\n  if (c == '#') {  /* first line is a comment (Unix exec. file)? */\n    do {  /* skip first line */\n      c = getc(lf->f);\n    } while (c != EOF && c != '\\n');\n    *cp = getc(lf->f);  /* skip end-of-line, if present */\n    return 1;  /* there was a comment */\n  }\n  else return 0;  /* no comment */\n}\n\n\nLUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,\n                                             const char *mode) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  if (skipcomment(&lf, &c))  /* read initial portion */\n    lf.buff[lf.n++] = '\\n';  /* add line to correct line numbers */\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    skipcomment(&lf, &c);  /* re-read initial portion */\n  }\n  if (c != EOF)\n    lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;  /* not used */\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,\n                                 const char *name, const char *mode) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name, mode);\n}\n\n\nLUALIB_API int luaL_loadstring (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return LUA_TNIL;\n  else {\n    int tt;\n    lua_pushstring(L, event);\n    tt = lua_rawget(L, -2);\n    if (tt == LUA_TNIL)  /* is metafield nil? */\n      lua_pop(L, 2);  /* remove metatable and metafield */\n    else\n      lua_remove(L, -2);  /* remove only metatable */\n    return tt;  /* return metafield type */\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = lua_absindex(L, obj);\n  if (luaL_getmetafield(L, obj, event) == LUA_TNIL)  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {\n  lua_Integer l;\n  int isnum;\n  lua_len(L, idx);\n  l = lua_tointegerx(L, -1, &isnum);\n  if (!isnum)\n    luaL_error(L, \"object length is not an integer\");\n  lua_pop(L, 1);  /* remove object */\n  return l;\n}\n\n\nLUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {\n  if (luaL_callmeta(L, idx, \"__tostring\")) {  /* metafield? */\n    if (!lua_isstring(L, -1))\n      luaL_error(L, \"'__tostring' must return a string\");\n  }\n  else {\n    switch (lua_type(L, idx)) {\n      case LUA_TNUMBER: {\n        if (lua_isinteger(L, idx))\n          lua_pushfstring(L, \"%I\", (LUAI_UACINT)lua_tointeger(L, idx));\n        else\n          lua_pushfstring(L, \"%f\", (LUAI_UACNUMBER)lua_tonumber(L, idx));\n        break;\n      }\n      case LUA_TSTRING:\n        lua_pushvalue(L, idx);\n        break;\n      case LUA_TBOOLEAN:\n        lua_pushstring(L, (lua_toboolean(L, idx) ? \"true\" : \"false\"));\n        break;\n      case LUA_TNIL:\n        lua_pushliteral(L, \"nil\");\n        break;\n      default: {\n        int tt = luaL_getmetafield(L, idx, \"__name\");  /* try name */\n        const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :\n                                                 luaL_typename(L, idx);\n        lua_pushfstring(L, \"%s: %p\", kind, lua_topointer(L, idx));\n        if (tt != LUA_TNIL)\n          lua_remove(L, -2);  /* remove '__name' */\n        break;\n      }\n    }\n  }\n  return lua_tolstring(L, -1, len);\n}\n\n\n/*\n** {======================================================\n** Compatibility with 5.1 module functions\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\nstatic const char *luaL_findtable (lua_State *L, int idx,\n                                   const char *fname, int szhint) {\n  const char *e;\n  if (idx) lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    if (lua_rawget(L, -2) == LUA_TNIL) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n/*\n** Count number of elements in a luaL_Reg list.\n*/\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l && l->name; l++) size++;\n  return size;\n}\n\n\n/*\n** Find or create a module table with a given name. The function\n** first looks at the LOADED table and, if that fails, try a\n** global variable with that name. In any case, leaves on the stack\n** the module table.\n*/\nLUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,\n                                 int sizehint) {\n  luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);\n  if (lua_getfield(L, -1, modname) != LUA_TTABLE) {  /* no LOADED[modname]? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    lua_pushglobaltable(L);\n    if (luaL_findtable(L, 0, modname, sizehint) != NULL)\n      luaL_error(L, \"name conflict for module '%s'\", modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = new table */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n}\n\n\nLUALIB_API void luaL_openlib (lua_State *L, const char *libname,\n                               const luaL_Reg *l, int nup) {\n  luaL_checkversion(L);\n  if (libname) {\n    luaL_pushmodule(L, libname, libsize(l));  /* get/create library table */\n    lua_insert(L, -(nup + 1));  /* move library table to below upvalues */\n  }\n  if (l)\n    luaL_setfuncs(L, l, nup);\n  else\n    lua_pop(L, nup);  /* remove upvalues */\n}\n\n#endif\n/* }====================================================== */\n\n/*\n** set functions from list 'l' into table at top - 'nup'; each\n** function gets the 'nup' elements at the top as upvalues.\n** Returns with only the table at the stack.\n*/\nLUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name != NULL; l++) {  /* fill the table with given functions */\n    int i;\n    for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** ensure that stack[idx][fname] has a table and push that table\n** into the stack\n*/\nLUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {\n  if (lua_getfield(L, idx, fname) == LUA_TTABLE)\n    return 1;  /* table already there */\n  else {\n    lua_pop(L, 1);  /* remove previous result */\n    idx = lua_absindex(L, idx);\n    lua_newtable(L);\n    lua_pushvalue(L, -1);  /* copy to be left at top */\n    lua_setfield(L, idx, fname);  /* assign new table to field */\n    return 0;  /* false, because did not find table there */\n  }\n}\n\n\n/*\n** Stripped-down 'require': After checking \"loaded\" table, calls 'openf'\n** to open a module, registers the result in 'package.loaded' table and,\n** if 'glb' is true, also registers the result in the global table.\n** Leaves resulting module on the top.\n*/\nLUALIB_API void luaL_requiref (lua_State *L, const char *modname,\n                               lua_CFunction openf, int glb) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, -1, modname);  /* LOADED[modname] */\n  if (!lua_toboolean(L, -1)) {  /* package not already loaded? */\n    lua_pop(L, 1);  /* remove field */\n    lua_pushcfunction(L, openf);\n    lua_pushstring(L, modname);  /* argument to open function */\n    lua_call(L, 1, 1);  /* call 'openf' to open module */\n    lua_pushvalue(L, -1);  /* make copy of module (call result) */\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = module */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n  if (glb) {\n    lua_pushvalue(L, -1);  /* copy of module */\n    lua_setglobal(L, modname);  /* _G[modname] = module */\n  }\n}\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after 'p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud; (void)osize;  /* not used */\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  lua_writestringerror(\"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                        lua_tostring(L, -1));\n  return 0;  /* return to Lua to abort */\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n\nLUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {\n  const lua_Number *v = lua_version(L);\n  if (sz != LUAL_NUMSIZES)  /* check numeric types */\n    luaL_error(L, \"core and library have incompatible numeric types\");\n  if (v != lua_version(NULL))\n    luaL_error(L, \"multiple Lua VMs detected\");\n  else if (*v != ver)\n    luaL_error(L, \"version mismatch: app. needs %f, Lua core provides %f\",\n                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n\n/* extra error code for 'luaL_loadfilex' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\n/* key, in the registry, for table of loaded modules */\n#define LUA_LOADED_TABLE\t\"_LOADED\"\n\n\n/* key, in the registry, for table of preloaded loaders */\n#define LUA_PRELOAD_TABLE\t\"_PRELOAD\"\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n#define LUAL_NUMSIZES\t(sizeof(lua_Integer)*16 + sizeof(lua_Number))\n\nLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);\n#define luaL_checkversion(L)  \\\n\t  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)\n\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\nLUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int arg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void  (luaL_setmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\nLUALIB_API int (luaL_execresult) (lua_State *L, int stat);\n\n/* predefined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n                                               const char *mode);\n\n#define luaL_loadfile(L,f)\tluaL_loadfilex(L,f,NULL)\n\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n                                   const char *name, const char *mode);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\nLUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\n\nLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\n\nLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\n                                  const char *msg, int level);\n\nLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\n                                 lua_CFunction openf, int glb);\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n\n#define luaL_newlibtable(L,l)\t\\\n  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n\n#define luaL_newlib(L,l)  \\\n  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n\n#define luaL_argcheck(L, cond,arg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (arg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n#define luaL_loadbuffer(L,s,sz,n)\tluaL_loadbufferx(L,s,sz,n,NULL)\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\ntypedef struct luaL_Buffer {\n  char *b;  /* buffer address */\n  size_t size;  /* buffer size */\n  size_t n;  /* number of characters in buffer */\n  lua_State *L;\n  char initb[LUAL_BUFFERSIZE];  /* initial buffer */\n} luaL_Buffer;\n\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\\n   ((B)->b[(B)->n++] = (c)))\n\n#define luaL_addsize(B,s)\t((B)->n += (s))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\n\n#define luaL_prepbuffer(B)\tluaL_prepbuffsize(B, LUAL_BUFFERSIZE)\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** File handles for IO library\n** =======================================================\n*/\n\n/*\n** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\n** initial structure 'luaL_Stream' (it may contain other fields\n** after that initial structure).\n*/\n\n#define LUA_FILEHANDLE          \"FILE*\"\n\n\ntypedef struct luaL_Stream {\n  FILE *f;  /* stream (NULL for incompletely created streams) */\n  lua_CFunction closef;  /* to close stream (NULL for closed streams) */\n} luaL_Stream;\n\n/* }====================================================== */\n\n\n\n/* compatibility with old module system */\n#if defined(LUA_COMPAT_MODULE)\n\nLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\n                                   int sizehint);\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\n\n#define luaL_register(L,n,l)\t(luaL_openlib(L,(n),(l),0))\n\n#endif\n\n\n/*\n** {==================================================================\n** \"Abstraction Layer\" for basic report of messages and errors\n** ===================================================================\n*/\n\n/* print a string */\n#if !defined(lua_writestring)\n#define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)\n#endif\n\n/* print a newline and flush the output */\n#if !defined(lua_writeline)\n#define lua_writeline()        (lua_writestring(\"\\n\", 1), fflush(stdout))\n#endif\n\n/* print an error message */\n#if !defined(lua_writestringerror)\n#define lua_writestringerror(s,p) \\\n        (fprintf(stderr, (s), (p)), fflush(stderr))\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {============================================================\n** Compatibility with deprecated conversions\n** =============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define luaL_checkunsigned(L,a)\t((lua_Unsigned)luaL_checkinteger(L,a))\n#define luaL_optunsigned(L,a,d)\t\\\n\t((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))\n\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#endif\n/* }============================================================ */\n\n\n\n#endif\n\n\n"
  },
  {
    "path": "WebGLPlugins/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    size_t l;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tolstring(L, -1, &l);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, \"'tostring' must return a string to 'print'\");\n    if (i>1) lua_writestring(\"\\t\", 1);\n    lua_writestring(s, l);\n    lua_pop(L, 1);  /* pop result */\n  }\n  lua_writeline();\n  return 0;\n}\n\n\n#define SPACECHARS\t\" \\f\\n\\r\\t\\v\"\n\nstatic const char *b_str2int (const char *s, int base, lua_Integer *pn) {\n  lua_Unsigned n = 0;\n  int neg = 0;\n  s += strspn(s, SPACECHARS);  /* skip initial spaces */\n  if (*s == '-') { s++; neg = 1; }  /* handle signal */\n  else if (*s == '+') s++;\n  if (!isalnum((unsigned char)*s))  /* no digit? */\n    return NULL;\n  do {\n    int digit = (isdigit((unsigned char)*s)) ? *s - '0'\n                   : (toupper((unsigned char)*s) - 'A') + 10;\n    if (digit >= base) return NULL;  /* invalid numeral */\n    n = n * base + digit;\n    s++;\n  } while (isalnum((unsigned char)*s));\n  s += strspn(s, SPACECHARS);  /* skip trailing spaces */\n  *pn = (lua_Integer)((neg) ? (0u - n) : n);\n  return s;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */\n    luaL_checkany(L, 1);\n    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */\n      lua_settop(L, 1);  /* yes; return it */\n      return 1;\n    }\n    else {\n      size_t l;\n      const char *s = lua_tolstring(L, 1, &l);\n      if (s != NULL && lua_stringtonumber(L, s) == l + 1)\n        return 1;  /* successful conversion to number */\n      /* else not a number */\n    }\n  }\n  else {\n    size_t l;\n    const char *s;\n    lua_Integer n = 0;  /* to avoid warnings */\n    lua_Integer base = luaL_checkinteger(L, 2);\n    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */\n    s = lua_tolstring(L, 1, &l);\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    if (b_str2int(s, (int)base, &n) == s + l) {\n      lua_pushinteger(L, n);\n      return 1;\n    }  /* else not a number */\n  }  /* else not a number */\n  lua_pushnil(L);  /* not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = (int)luaL_optinteger(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {\n    luaL_where(L, level);   /* add extra information */\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\") != LUA_TNIL)\n    return luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawlen (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,\n                   \"table or string expected\");\n  lua_pushinteger(L, lua_rawlen(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\n    \"isrunning\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n    LUA_GCISRUNNING};\n  int o = optsnum[luaL_checkoption(L, 1, \"collect\", opts)];\n  int ex = (int)luaL_optinteger(L, 2, 0);\n  int res = lua_gc(L, o, ex);\n  switch (o) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: case LUA_GCISRUNNING: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushinteger(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t != LUA_TNONE, 1, \"value expected\");\n  lua_pushstring(L, lua_typename(L, t));\n  return 1;\n}\n\n\nstatic int pairsmeta (lua_State *L, const char *method, int iszero,\n                      lua_CFunction iter) {\n  luaL_checkany(L, 1);\n  if (luaL_getmetafield(L, 1, method) == LUA_TNIL) {  /* no metamethod? */\n    lua_pushcfunction(L, iter);  /* will return generator, */\n    lua_pushvalue(L, 1);  /* state, */\n    if (iszero) lua_pushinteger(L, 0);  /* and initial value */\n    else lua_pushnil(L);\n  }\n  else {\n    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */\n    lua_call(L, 1, 3);  /* get 3 values from metamethod */\n  }\n  return 3;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  return pairsmeta(L, \"__pairs\", 0, luaB_next);\n}\n\n\n/*\n** Traversal function for 'ipairs'\n*/\nstatic int ipairsaux (lua_State *L) {\n  lua_Integer i = luaL_checkinteger(L, 2) + 1;\n  lua_pushinteger(L, i);\n  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;\n}\n\n\n/*\n** 'ipairs' function. Returns 'ipairsaux', given \"table\", 0.\n** (The given \"table\" may not be a table.)\n*/\nstatic int luaB_ipairs (lua_State *L) {\n#if defined(LUA_COMPAT_IPAIRS)\n  return pairsmeta(L, \"__ipairs\", 1, ipairsaux);\n#else\n  luaL_checkany(L, 1);\n  lua_pushcfunction(L, ipairsaux);  /* iteration function */\n  lua_pushvalue(L, 1);  /* state */\n  lua_pushinteger(L, 0);  /* initial value */\n  return 3;\n#endif\n}\n\n\nstatic int load_aux (lua_State *L, int status, int envidx) {\n  if (status == LUA_OK) {\n    if (envidx != 0) {  /* 'env' parameter? */\n      lua_pushvalue(L, envidx);  /* environment for loaded function */\n      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */\n        lua_pop(L, 1);  /* remove 'env' if not used by previous call */\n    }\n    return 1;\n  }\n  else {  /* error (message is on top of the stack) */\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  const char *mode = luaL_optstring(L, 2, NULL);\n  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */\n  int status = luaL_loadfilex(L, fname, mode);\n  return load_aux(L, status, env);\n}\n\n\n/*\n** {======================================================\n** Generic Read function\n** =======================================================\n*/\n\n\n/*\n** reserved slot, above all arguments, to hold a copy of the returned\n** string to avoid it being collected while parsed. 'load' has four\n** optional arguments (chunk, source name, mode, and environment).\n*/\n#define RESERVEDSLOT\t5\n\n\n/*\n** Reader for generic 'load' function: 'lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)(ud);  /* not used */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* pop result */\n    *size = 0;\n    return NULL;\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"reader function must return a string\");\n  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */\n  return lua_tolstring(L, RESERVEDSLOT, size);\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  size_t l;\n  const char *s = lua_tolstring(L, 1, &l);\n  const char *mode = luaL_optstring(L, 3, \"bt\");\n  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */\n  if (s != NULL) {  /* loading a string? */\n    const char *chunkname = luaL_optstring(L, 2, s);\n    status = luaL_loadbufferx(L, s, l, chunkname, mode);\n  }\n  else {  /* loading from a reader function */\n    const char *chunkname = luaL_optstring(L, 2, \"=(load)\");\n    luaL_checktype(L, 1, LUA_TFUNCTION);\n    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */\n    status = lua_load(L, generic_reader, NULL, chunkname, mode);\n  }\n  return load_aux(L, status, env);\n}\n\n/* }====================================================== */\n\n\nstatic int dofilecont (lua_State *L, int d1, lua_KContext d2) {\n  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */\n  return lua_gettop(L) - 1;\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  lua_settop(L, 1);\n  if (luaL_loadfile(L, fname) != LUA_OK)\n    return lua_error(L);\n  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);\n  return dofilecont(L, 0, 0);\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  if (lua_toboolean(L, 1))  /* condition is true? */\n    return lua_gettop(L);  /* return all arguments */\n  else {  /* error */\n    luaL_checkany(L, 1);  /* there must be a condition */\n    lua_remove(L, 1);  /* remove it */\n    lua_pushliteral(L, \"assertion failed!\");  /* default message */\n    lua_settop(L, 1);  /* leave only message (default if no other one) */\n    return luaB_error(L);  /* call 'error' */\n  }\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    lua_Integer i = luaL_checkinteger(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - (int)i;\n  }\n}\n\n\n/*\n** Continuation function for 'pcall' and 'xpcall'. Both functions\n** already pushed a 'true' before doing the call, so in case of success\n** 'finishpcall' only has to return everything in the stack minus\n** 'extra' values (where 'extra' is exactly the number of items to be\n** ignored).\n*/\nstatic int finishpcall (lua_State *L, int status, lua_KContext extra) {\n  if (status != LUA_OK && status != LUA_YIELD) {  /* error? */\n    lua_pushboolean(L, 0);  /* first result (false) */\n    lua_pushvalue(L, -2);  /* error message */\n    return 2;  /* return false, msg */\n  }\n  else\n    return lua_gettop(L) - (int)extra;  /* return all results */\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  lua_pushboolean(L, 1);  /* first result if no errors */\n  lua_insert(L, 1);  /* put it in place */\n  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);\n  return finishpcall(L, status, 0);\n}\n\n\n/*\n** Do a protected call with error handling. After 'lua_rotate', the\n** stack will have <f, err, true, f, [args...]>; so, the function passes\n** 2 to 'finishpcall' to skip the 2 first values when returning results.\n*/\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  int n = lua_gettop(L);\n  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */\n  lua_pushboolean(L, 1);  /* first result */\n  lua_pushvalue(L, 1);  /* function */\n  lua_rotate(L, 3, 2);  /* move them below function's arguments */\n  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);\n  return finishpcall(L, status, 2);\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_tolstring(L, 1, NULL);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"ipairs\", luaB_ipairs},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n#if defined(LUA_COMPAT_LOADSTRING)\n  {\"loadstring\", luaB_load},\n#endif\n  {\"next\", luaB_next},\n  {\"pairs\", luaB_pairs},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawlen\", luaB_rawlen},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"xpcall\", luaB_xpcall},\n  /* placeholders */\n  {\"_G\", NULL},\n  {\"_VERSION\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_base (lua_State *L) {\n  /* open lib into global table */\n  lua_pushglobaltable(L);\n  luaL_setfuncs(L, base_funcs, 0);\n  /* set global _G */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_G\");\n  /* set global _VERSION */\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setfield(L, -2, \"_VERSION\");\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lbitlib.c",
    "content": "/*\n** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $\n** Standard library for bitwise operations\n** See Copyright Notice in lua.h\n*/\n\n#define lbitlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if defined(LUA_COMPAT_BITLIB)\t\t/* { */\n\n\n#define pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define checkunsigned(L,i)\t((lua_Unsigned)luaL_checkinteger(L,i))\n\n\n/* number of bits to consider in a number */\n#if !defined(LUA_NBITS)\n#define LUA_NBITS\t32\n#endif\n\n\n/*\n** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must\n** be made in two parts to avoid problems when LUA_NBITS is equal to the\n** number of bits in a lua_Unsigned.)\n*/\n#define ALLONES\t\t(~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))\n\n\n/* macro to trim extra bits */\n#define trim(x)\t\t((x) & ALLONES)\n\n\n/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */\n#define mask(n)\t\t(~((ALLONES << 1) << ((n) - 1)))\n\n\n\nstatic lua_Unsigned andaux (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = ~(lua_Unsigned)0;\n  for (i = 1; i <= n; i++)\n    r &= checkunsigned(L, i);\n  return trim(r);\n}\n\n\nstatic int b_and (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_test (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  lua_pushboolean(L, r != 0);\n  return 1;\n}\n\n\nstatic int b_or (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r |= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_xor (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r ^= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_not (lua_State *L) {\n  lua_Unsigned r = ~checkunsigned(L, 1);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) {\n  if (i < 0) {  /* shift right? */\n    i = -i;\n    r = trim(r);\n    if (i >= LUA_NBITS) r = 0;\n    else r >>= i;\n  }\n  else {  /* shift left */\n    if (i >= LUA_NBITS) r = 0;\n    else r <<= i;\n    r = trim(r);\n  }\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_lshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_arshift (lua_State *L) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  lua_Integer i = luaL_checkinteger(L, 2);\n  if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1))))\n    return b_shift(L, r, -i);\n  else {  /* arithmetic shift for 'negative' number */\n    if (i >= LUA_NBITS) r = ALLONES;\n    else\n      r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i));  /* add signal bit */\n    pushunsigned(L, r);\n    return 1;\n  }\n}\n\n\nstatic int b_rot (lua_State *L, lua_Integer d) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  int i = d & (LUA_NBITS - 1);  /* i = d % NBITS */\n  r = trim(r);\n  if (i != 0)  /* avoid undefined shift of LUA_NBITS when i == 0 */\n    r = (r << i) | (r >> (LUA_NBITS - i));\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_lrot (lua_State *L) {\n  return b_rot(L, luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rrot (lua_State *L) {\n  return b_rot(L, -luaL_checkinteger(L, 2));\n}\n\n\n/*\n** get field and width arguments for field-manipulation functions,\n** checking whether they are valid.\n** ('luaL_error' called without 'return' to avoid later warnings about\n** 'width' being used uninitialized.)\n*/\nstatic int fieldargs (lua_State *L, int farg, int *width) {\n  lua_Integer f = luaL_checkinteger(L, farg);\n  lua_Integer w = luaL_optinteger(L, farg + 1, 1);\n  luaL_argcheck(L, 0 <= f, farg, \"field cannot be negative\");\n  luaL_argcheck(L, 0 < w, farg + 1, \"width must be positive\");\n  if (f + w > LUA_NBITS)\n    luaL_error(L, \"trying to access non-existent bits\");\n  *width = (int)w;\n  return (int)f;\n}\n\n\nstatic int b_extract (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  int f = fieldargs(L, 2, &w);\n  r = (r >> f) & mask(w);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_replace (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  lua_Unsigned v = trim(checkunsigned(L, 2));\n  int f = fieldargs(L, 3, &w);\n  lua_Unsigned m = mask(w);\n  r = (r & ~(m << f)) | ((v & m) << f);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic const luaL_Reg bitlib[] = {\n  {\"arshift\", b_arshift},\n  {\"band\", b_and},\n  {\"bnot\", b_not},\n  {\"bor\", b_or},\n  {\"bxor\", b_xor},\n  {\"btest\", b_test},\n  {\"extract\", b_extract},\n  {\"lrotate\", b_lrot},\n  {\"lshift\", b_lshift},\n  {\"replace\", b_replace},\n  {\"rrotate\", b_rrot},\n  {\"rshift\", b_rshift},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  luaL_newlib(L, bitlib);\n  return 1;\n}\n\n\n#else\t\t\t\t\t/* }{ */\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  return luaL_error(L, \"library 'bit32' has been deprecated\");\n}\n\n#endif\t\t\t\t\t/* } */\n"
  },
  {
    "path": "WebGLPlugins/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <math.h>\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/* Maximum number of registers in a Lua function (must fit in 8 bits) */\n#define MAXREGS\t\t255\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\n/*\n** If expression is a numeric constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nstatic int tonumeral(const expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a numeral */\n  switch (e->k) {\n    case VKINT:\n      if (v) setivalue(v, e->u.ival);\n      return 1;\n    case VKFLT:\n      if (v) setfltvalue(v, e->u.nval);\n      return 1;\n    default: return 0;\n  }\n}\n\n\n/*\n** Create a OP_LOADNIL instruction, but try to optimize: if the previous\n** instruction is also OP_LOADNIL and ranges are compatible, adjust\n** range of previous instruction instead of emitting a new one. (For\n** instance, 'local a; local b' will generate a single opcode.)\n*/\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  int l = from + n - 1;  /* last register to set nil */\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    previous = &fs->f->code[fs->pc-1];\n    if (GET_OPCODE(*previous) == OP_LOADNIL) {  /* previous is LOADNIL? */\n      int pfrom = GETARG_A(*previous);  /* get previous range */\n      int pl = pfrom + GETARG_B(*previous);\n      if ((pfrom <= from && from <= pl + 1) ||\n          (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */\n        if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */\n        if (pl > l) l = pl;  /* l = max(l, pl) */\n        SETARG_A(*previous, from);\n        SETARG_B(*previous, l - from);\n        return;\n      }\n    }  /* else go through */\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */\n}\n\n\n/*\n** Gets the destination address of a jump instruction. Used to traverse\n** a list of jumps.\n*/\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\n/*\n** Fix jump instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua)\n*/\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** Concatenate jump-list 'l2' into jump-list 'l1'\n*/\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;  /* nothing to concatenate? */\n  else if (*l1 == NO_JUMP)  /* no original list? */\n    *l1 = l2;  /* 'l1' points to 'l2' */\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);  /* last element links to 'l2' */\n  }\n}\n\n\n/*\n** Create a jump instruction and return its position, so its destination\n** can be fixed later (with 'fixjump'). If there are jumps to\n** this position (kept in 'jpc'), link them all together so that\n** 'patchlistaux' will fix all them directly to the final destination.\n*/\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;  /* no more jumps to here */\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\n/*\n** Code a 'return' instruction\n*/\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\n/*\n** Code a \"conditional jump\", that is, a test or comparison opcode\n** followed by a jump. Return jump position.\n*/\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\n/*\n** returns current 'pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\n/*\n** Returns the position of the instruction \"controlling\" a given\n** jump (that is, its condition), or the jump itself if it is\n** unconditional.\n*/\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** Patch destination register for a TESTSET instruction.\n** If instruction in position 'node' is not a TESTSET, return 0 (\"fails\").\n** Otherwise, if 'reg' is not 'NO_REG', set it as the destination\n** register. Otherwise, change instruction to a simple 'TEST' (produces\n** no register value)\n*/\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else {\n     /* no register to put value or register already has the value;\n        change instruction to simple test */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n  }\n  return 1;\n}\n\n\n/*\n** Traverse a list of tests ensuring no one produces a value\n*/\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\n/*\n** Traverse a list of tests, patching their destination address and\n** registers: tests producing values jump to 'vtarget' (and put their\n** values in 'reg'), other tests jump to 'dtarget'.\n*/\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\n/*\n** Ensure all pending jumps to current position are fixed (jumping\n** to current position with no values) and reset list of pending\n** jumps\n*/\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\n/*\n** Add elements in 'list' to list of pending jumps to \"here\"\n** (current position)\n*/\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);  /* mark \"here\" as a jump target */\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\n/*\n** Path all jumps in 'list' to jump to 'target'.\n** (The assert means that we cannot fix a jump to a forward address\n** because we only know addresses once code is generated.)\n*/\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)  /* 'target' is current position? */\n    luaK_patchtohere(fs, list);  /* add list to pending jumps */\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\n/*\n** Path all jumps in 'list' to close upvalues up to given 'level'\n** (The assertion checks that jumps either were closing nothing\n** or were closing higher levels, from inner blocks.)\n*/\nvoid luaK_patchclose (FuncState *fs, int list, int level) {\n  level++;  /* argument is +1 to reserve 0 as non-op */\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&\n                (GETARG_A(fs->f->code[list]) == 0 ||\n                 GETARG_A(fs->f->code[list]) >= level));\n    SETARG_A(fs->f->code[list], level);\n  }\n}\n\n\n/*\n** Emit instruction 'i', checking for array sizes and saving also its\n** line information. Return 'i' position.\n*/\nstatic int luaK_code (FuncState *fs, Instruction i) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* 'pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"opcodes\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"opcodes\");\n  f->lineinfo[fs->pc] = fs->ls->lastline;\n  return fs->pc++;\n}\n\n\n/*\n** Format and emit an 'iABC' instruction. (Assertions check consistency\n** of parameters versus opcode.)\n*/\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c));\n}\n\n\n/*\n** Format and emit an 'iABx' instruction.\n*/\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, bc));\n}\n\n\n/*\n** Emit an \"extra argument\" instruction (format 'iAx')\n*/\nstatic int codeextraarg (FuncState *fs, int a) {\n  lua_assert(a <= MAXARG_Ax);\n  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));\n}\n\n\n/*\n** Emit a \"load constant\" instruction, using either 'OP_LOADK'\n** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'\n** instruction with \"extra argument\".\n*/\nint luaK_codek (FuncState *fs, int reg, int k) {\n  if (k <= MAXARG_Bx)\n    return luaK_codeABx(fs, OP_LOADK, reg, k);\n  else {\n    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);\n    codeextraarg(fs, k);\n    return p;\n  }\n}\n\n\n/*\n** Check register-stack level, keeping track of its maximum size\n** in field 'maxstacksize'\n*/\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXREGS)\n      luaX_syntaxerror(fs->ls,\n        \"function or expression needs too many registers\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\n/*\n** Reserve 'n' registers in register stack\n*/\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\n/*\n** Free register 'reg', if it is neither a constant index nor\n** a local variable.\n)\n*/\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\n/*\n** Free register used by expression 'e' (if any)\n*/\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.info);\n}\n\n\n/*\n** Free registers used by expressions 'e1' and 'e2' (if any) in proper\n** order.\n*/\nstatic void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {\n  int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;\n  int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;\n  if (r1 > r2) {\n    freereg(fs, r1);\n    freereg(fs, r2);\n  }\n  else {\n    freereg(fs, r2);\n    freereg(fs, r1);\n  }\n}\n\n\n/*\n** Add constant 'v' to prototype's list of constants (field 'k').\n** Use scanner's table to cache position of constants in constant list\n** and try to reuse constants. Because some values should not be used\n** as keys (nil cannot be a key, integer keys can collapse with float\n** keys), the caller must provide a useful 'key' for indexing the cache.\n*/\nstatic int addk (FuncState *fs, TValue *key, TValue *v) {\n  lua_State *L = fs->ls->L;\n  Proto *f = fs->f;\n  TValue *idx = luaH_set(L, fs->ls->h, key);  /* index scanner table */\n  int k, oldsize;\n  if (ttisinteger(idx)) {  /* is there an index there? */\n    k = cast_int(ivalue(idx));\n    /* correct value? (warning: must distinguish floats from integers!) */\n    if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&\n                      luaV_rawequalobj(&f->k[k], v))\n      return k;  /* reuse index */\n  }\n  /* constant not found; create a new entry */\n  oldsize = f->sizek;\n  k = fs->nk;\n  /* numerical value does not need GC barrier;\n     table has no metatable, so it does not need to invalidate cache */\n  setivalue(idx, k);\n  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, \"constants\");\n  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n  setobj(L, &f->k[k], v);\n  fs->nk++;\n  luaC_barrier(L, f, v);\n  return k;\n}\n\n\n/*\n** Add a string to list of constants and return its index.\n*/\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->ls->L, &o, s);\n  return addk(fs, &o, &o);  /* use string itself as key */\n}\n\n\n/*\n** Add an integer to list of constants and return its index.\n** Integers use userdata as keys to avoid collision with floats with\n** same value; conversion to 'void*' is used only for hashing, so there\n** are no \"precision\" problems.\n*/\nint luaK_intK (FuncState *fs, lua_Integer n) {\n  TValue k, o;\n  setpvalue(&k, cast(void*, cast(size_t, n)));\n  setivalue(&o, n);\n  return addk(fs, &k, &o);\n}\n\n/*\n** Add a float to list of constants and return its index.\n*/\nstatic int luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setfltvalue(&o, r);\n  return addk(fs, &o, &o);  /* use number itself as key */\n}\n\n\n/*\n** Add a boolean to list of constants and return its index.\n*/\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add nil to list of constants and return its index.\n*/\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->ls->L, &k, fs->ls->h);\n  return addk(fs, &k, &v);\n}\n\n\n/*\n** Fix an expression to return the number of results 'nresults'.\n** Either 'e' is a multi-ret expression (function call or vararg)\n** or 'nresults' is LUA_MULTRET (as any expression can satisfy that).\n*/\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getinstruction(fs, e), nresults + 1);\n  }\n  else if (e->k == VVARARG) {\n    Instruction *pc = &getinstruction(fs, e);\n    SETARG_B(*pc, nresults + 1);\n    SETARG_A(*pc, fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n  else lua_assert(nresults == LUA_MULTRET);\n}\n\n\n/*\n** Fix an expression to return one result.\n** If expression is not a multi-ret expression (function call or\n** vararg), it already returns one result, so nothing needs to be done.\n** Function calls become VNONRELOC expressions (as its result comes\n** fixed in the base register of the call), while vararg expressions\n** become VRELOCABLE (as OP_VARARG puts its results where it wants).\n** (Calls are created returning one result, so that does not need\n** to be fixed.)\n*/\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    /* already returns 1 value */\n    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);\n    e->k = VNONRELOC;  /* result has fixed position */\n    e->u.info = GETARG_A(getinstruction(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getinstruction(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\n/*\n** Ensure that expression 'e' is not a variable.\n*/\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {  /* already in a register */\n      e->k = VNONRELOC;  /* becomes a non-relocatable value */\n      break;\n    }\n    case VUPVAL: {  /* move value to some (pending) register */\n      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      OpCode op;\n      freereg(fs, e->u.ind.idx);\n      if (e->u.ind.vt == VLOCAL) {  /* is 't' in a register? */\n        freereg(fs, e->u.ind.t);\n        op = OP_GETTABLE;\n      }\n      else {\n        lua_assert(e->u.ind.vt == VUPVAL);\n        op = OP_GETTABUP;  /* 't' is in an upvalue */\n      }\n      e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG: case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\n/*\n** Ensures expression value is in register 'reg' (and therefore\n** 'e' will become a non-relocatable expression).\n*/\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE: case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codek(fs, reg, e->u.info);\n      break;\n    }\n    case VKFLT: {\n      luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VKINT: {\n      luaK_codek(fs, reg, luaK_intK(fs, e->u.ival));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getinstruction(fs, e);\n      SETARG_A(*pc, reg);  /* instruction will put result in 'reg' */\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures expression value is in any register.\n*/\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {  /* no fixed register yet? */\n    luaK_reserveregs(fs, 1);  /* get a register */\n    discharge2reg(fs, e, fs->freereg-1);  /* put value there */\n  }\n}\n\n\nstatic int code_loadbool (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** or produce an inverted value\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in register 'reg'.\n** If expression has jumps, need to patch these jumps either to\n** its final position or to \"load\" instructions (for those tests\n** that do not produce values).\n*/\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)  /* expression itself is a test? */\n    luaK_concat(fs, &e->t, e->u.info);  /* put this jump in 't' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_loadbool(fs, reg, 0, 1);\n      p_t = code_loadbool(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in next available register.\n*/\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in some (any) register and return that register.\n*/\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {  /* expression already has a register? */\n    if (!hasjumps(e))  /* no jumps? */\n      return e->u.info;  /* result is already in a register */\n    if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.info);  /* put final result in it */\n      return e->u.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* otherwise, use next available register */\n  return e->u.info;\n}\n\n\n/*\n** Ensures final expression result is either in a register or in an\n** upvalue.\n*/\nvoid luaK_exp2anyregup (FuncState *fs, expdesc *e) {\n  if (e->k != VUPVAL || hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Ensures final expression result is either in a register or it is\n** a constant.\n*/\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\n/*\n** Ensures final expression result is in a valid R/K index\n** (that is, it is either in a register or in 'k' with an index\n** in the range of R/K indices).\n** Returns R/K index.\n*/\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {  /* move constants to 'k' */\n    case VTRUE: e->u.info = boolK(fs, 1); goto vk;\n    case VFALSE: e->u.info = boolK(fs, 0); goto vk;\n    case VNIL: e->u.info = nilK(fs); goto vk;\n    case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;\n    case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;\n    case VK:\n     vk:\n      e->k = VK;\n      if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */\n        return RKASK(e->u.info);\n      else break;\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Generate code to store result of expression 'ex' into variable 'var'.\n*/\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.info);  /* compute 'ex' into proper place */\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);\n      break;\n    }\n    case VINDEXED: {\n      OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);\n      break;\n    }\n    default: lua_assert(0);  /* invalid var kind to store */\n  }\n  freeexp(fs, ex);\n}\n\n\n/*\n** Emit SELF instruction (convert expression 'e' into 'e:key(e,').\n*/\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int ereg;\n  luaK_exp2anyreg(fs, e);\n  ereg = e->u.info;  /* register where 'e' was placed */\n  freeexp(fs, e);\n  e->u.info = fs->freereg;  /* base register for op_self */\n  e->k = VNONRELOC;  /* self expression has a fixed register */\n  luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */\n  luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n}\n\n\n/*\n** Negate condition 'e' (where 'e' is a comparison).\n*/\nstatic void negatecondition (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\n/*\n** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'\n** is true, code will jump if 'e' is true.) Return jump position.\n** Optimize when 'e' is 'not' something, inverting the condition\n** and removing the 'not'.\n*/\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getinstruction(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);\n}\n\n\n/*\n** Emit code to go through if 'e' is true, jump otherwise.\n*/\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {  /* condition? */\n      negatecondition(fs, e);  /* jump when it is false */\n      pc = e->u.info;  /* save jump position */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);  /* jump when false */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert new jump in false list */\n  luaK_patchtohere(fs, e->t);  /* true list jumps to here (to go through) */\n  e->t = NO_JUMP;\n}\n\n\n/*\n** Emit code to go through if 'e' is false, jump otherwise.\n*/\nvoid luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {\n      pc = e->u.info;  /* already jump if true */\n      break;\n    }\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);  /* jump if true */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert new jump in 't' list */\n  luaK_patchtohere(fs, e->f);  /* false list jumps to here (to go through) */\n  e->f = NO_JUMP;\n}\n\n\n/*\n** Code 'not e', doing constant folding.\n*/\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;  /* true == not nil == not false */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      e->k = VFALSE;  /* false == not \"x\" == not 0.5 == not 1 == not true */\n      break;\n    }\n    case VJMP: {\n      negatecondition(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: lua_assert(0);  /* cannot happen */\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);  /* values are useless when negated */\n  removevalues(fs, e->t);\n}\n\n\n/*\n** Create expression 't[k]'. 't' must have its final result already in a\n** register or upvalue.\n*/\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));\n  t->u.ind.t = t->u.info;  /* register or upvalue index */\n  t->u.ind.idx = luaK_exp2RK(fs, k);  /* R/K index for key */\n  t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL;\n  t->k = VINDEXED;\n}\n\n\n/*\n** Return false if folding can raise an error.\n** Bitwise operations need operands convertible to integers; division\n** operations cannot have 0 as divisor.\n*/\nstatic int validop (int op, TValue *v1, TValue *v2) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: {  /* conversion errors */\n      lua_Integer i;\n      return (tointeger(v1, &i) && tointeger(v2, &i));\n    }\n    case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD:  /* division by 0 */\n      return (nvalue(v2) != 0);\n    default: return 1;  /* everything else is valid */\n  }\n}\n\n\n/*\n** Try to \"constant-fold\" an operation; return 1 iff successful.\n** (In this case, 'e1' has the final result.)\n*/\nstatic int constfolding (FuncState *fs, int op, expdesc *e1,\n                                                const expdesc *e2) {\n  TValue v1, v2, res;\n  if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))\n    return 0;  /* non-numeric operands or not safe to fold */\n  luaO_arith(fs->ls->L, op, &v1, &v2, &res);  /* does operation */\n  if (ttisinteger(&res)) {\n    e1->k = VKINT;\n    e1->u.ival = ivalue(&res);\n  }\n  else {  /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */\n    lua_Number n = fltvalue(&res);\n    if (luai_numisnan(n) || n == 0)\n      return 0;\n    e1->k = VKFLT;\n    e1->u.nval = n;\n  }\n  return 1;\n}\n\n\n/*\n** Emit code for unary expressions that \"produce values\"\n** (everything but 'not').\n** Expression to produce final result will be encoded in 'e'.\n*/\nstatic void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {\n  int r = luaK_exp2anyreg(fs, e);  /* opcodes operate only on registers */\n  freeexp(fs, e);\n  e->u.info = luaK_codeABC(fs, op, 0, r, 0);  /* generate opcode */\n  e->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\"\n** (everything but logical operators 'and'/'or' and comparison\n** operators).\n** Expression to produce final result will be encoded in 'e1'.\n** Because 'luaK_exp2RK' can free registers, its calls must be\n** in \"stack order\" (that is, first on 'e2', which may have more\n** recent registers to be released).\n*/\nstatic void codebinexpval (FuncState *fs, OpCode op,\n                           expdesc *e1, expdesc *e2, int line) {\n  int rk2 = luaK_exp2RK(fs, e2);  /* both operands are \"RK\" */\n  int rk1 = luaK_exp2RK(fs, e1);\n  freeexps(fs, e1, e2);\n  e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2);  /* generate opcode */\n  e1->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for comparisons.\n** 'e1' was already put in R/K form by 'luaK_infix'.\n*/\nstatic void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {\n  int rk1 = (e1->k == VK) ? RKASK(e1->u.info)\n                          : check_exp(e1->k == VNONRELOC, e1->u.info);\n  int rk2 = luaK_exp2RK(fs, e2);\n  freeexps(fs, e1, e2);\n  switch (opr) {\n    case OPR_NE: {  /* '(a ~= b)' ==> 'not (a == b)' */\n      e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2);\n      break;\n    }\n    case OPR_GT: case OPR_GE: {\n      /* '(a > b)' ==> '(b < a)';  '(a >= b)' ==> '(b <= a)' */\n      OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk2, rk1);  /* invert operands */\n      break;\n    }\n    default: {  /* '==', '<', '<=' use their own opcodes */\n      OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk1, rk2);\n      break;\n    }\n  }\n  e1->k = VJMP;\n}\n\n\n/*\n** Aplly prefix operation 'op' to expression 'e'.\n*/\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {\n  static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};\n  switch (op) {\n    case OPR_MINUS: case OPR_BNOT:  /* use 'ef' as fake 2nd operand */\n      if (constfolding(fs, op + LUA_OPUNM, e, &ef))\n        break;\n      /* FALLTHROUGH */\n    case OPR_LEN:\n      codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);\n      break;\n    case OPR_NOT: codenot(fs, e); break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Process 1st operand 'v' of binary operation 'op' before reading\n** 2nd operand.\n*/\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);  /* go ahead only if 'v' is true */\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);  /* go ahead only if 'v' is false */\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the 'stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB:\n    case OPR_MUL: case OPR_DIV: case OPR_IDIV:\n    case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2RK(fs, v);\n      /* else keep numeral, which may be folded with 2nd operand */\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\n/*\n** Finalize code for binary operation, after reading 2nd operand.\n** For '(a .. b .. c)' (which is '(a .. (b .. c))', because\n** concatenation is right associative), merge second CONCAT into first\n** one.\n*/\nvoid luaK_posfix (FuncState *fs, BinOpr op,\n                  expdesc *e1, expdesc *e2, int line) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE &&\n          GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getinstruction(fs, e2), e1->u.info);\n        e1->k = VRELOCABLE; e1->u.info = e2->u.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codebinexpval(fs, OP_CONCAT, e1, e2, line);\n      }\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_IDIV: case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!constfolding(fs, op + LUA_OPADD, e1, e2))\n        codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);\n      break;\n    }\n    case OPR_EQ: case OPR_LT: case OPR_LE:\n    case OPR_NE: case OPR_GT: case OPR_GE: {\n      codecomp(fs, op, e1, e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Change line information associated with current position.\n*/\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\n/*\n** Emit a SETLIST instruction.\n** 'base' is register that keeps table;\n** 'nelems' is #table plus those to be stored now;\n** 'tostore' is number of values (in registers 'base + 1',...) to add to\n** table (or LUA_MULTRET to add up to stack top).\n*/\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else if (c <= MAXARG_Ax) {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    codeextraarg(fs, c);\n  }\n  else\n    luaX_syntaxerror(fs->ls, \"constructor too long\");\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums  (ORDER OP)\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,\n  OPR_DIV,\n  OPR_IDIV,\n  OPR_BAND, OPR_BOR, OPR_BXOR,\n  OPR_SHL, OPR_SHR,\n  OPR_CONCAT,\n  OPR_EQ, OPR_LT, OPR_LE,\n  OPR_NE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n/* get (pointer to) instruction of given 'expdesc' */\n#define getinstruction(fs,e)\t((fs)->f->code[(e)->u.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\n#define luaK_jumpto(fs,t)\tluaK_patchlist(fs, luaK_jump(fs), t)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,\n                            expdesc *v2, int line);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lcorolib.c",
    "content": "/*\n** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $\n** Coroutine Library\n** See Copyright Notice in lua.h\n*/\n\n#define lcorolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic lua_State *getco (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"thread expected\");\n  return co;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status;\n  if (!lua_checkstack(co, narg)) {\n    lua_pushliteral(L, \"too many arguments to resume\");\n    return -1;  /* error flag */\n  }\n  if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {\n    lua_pushliteral(L, \"cannot resume dead coroutine\");\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, L, narg);\n  if (status == LUA_OK || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1)) {\n      lua_pop(co, nres);  /* remove results anyway */\n      lua_pushliteral(L, \"too many results to resume\");\n      return -1;  /* error flag */\n    }\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = getco(L);\n  int r;\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + 'resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_type(L, -1) == LUA_TSTRING) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    return lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  NL = lua_newthread(L);\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = getco(L);\n  if (L == co) lua_pushliteral(L, \"running\");\n  else {\n    switch (lua_status(co)) {\n      case LUA_YIELD:\n        lua_pushliteral(L, \"suspended\");\n        break;\n      case LUA_OK: {\n        lua_Debug ar;\n        if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n          lua_pushliteral(L, \"normal\");  /* it is running */\n        else if (lua_gettop(co) == 0)\n            lua_pushliteral(L, \"dead\");\n        else\n          lua_pushliteral(L, \"suspended\");  /* initial state */\n        break;\n      }\n      default:  /* some error occurred */\n        lua_pushliteral(L, \"dead\");\n        break;\n    }\n  }\n  return 1;\n}\n\n\nstatic int luaB_yieldable (lua_State *L) {\n  lua_pushboolean(L, lua_isyieldable(L));\n  return 1;\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  int ismain = lua_pushthread(L);\n  lua_pushboolean(L, ismain);\n  return 2;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {\"isyieldable\", luaB_yieldable},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_coroutine (lua_State *L) {\n  luaL_newlib(L, co_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lctype.c",
    "content": "/*\n** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lctype_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lctype.h\"\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\nLUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {\n  0x00,  /* EOZ */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 0. */\n  0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 1. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\t/* 2. */\n  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,\t/* 3. */\n  0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 4. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 5. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 6. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 7. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 8. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 9. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* a. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* b. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* c. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* d. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* e. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* f. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n};\n\n#endif\t\t\t/* } */\n"
  },
  {
    "path": "WebGLPlugins/lctype.h",
    "content": "/*\n** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lctype_h\n#define lctype_h\n\n#include \"lua.h\"\n\n\n/*\n** WARNING: the functions defined here do not necessarily correspond\n** to the similar functions in the standard C ctype.h. They are\n** optimized for the specific needs of Lua\n*/\n\n#if !defined(LUA_USE_CTYPE)\n\n#if 'A' == 65 && '0' == 48\n/* ASCII case: can use its own tables; faster and fixed */\n#define LUA_USE_CTYPE\t0\n#else\n/* must use standard C ctype */\n#define LUA_USE_CTYPE\t1\n#endif\n\n#endif\n\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n#include \"llimits.h\"\n\n\n#define ALPHABIT\t0\n#define DIGITBIT\t1\n#define PRINTBIT\t2\n#define SPACEBIT\t3\n#define XDIGITBIT\t4\n\n\n#define MASK(B)\t\t(1 << (B))\n\n\n/*\n** add 1 to char to allow index -1 (EOZ)\n*/\n#define testprop(c,p)\t(luai_ctype_[(c)+1] & (p))\n\n/*\n** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'\n*/\n#define lislalpha(c)\ttestprop(c, MASK(ALPHABIT))\n#define lislalnum(c)\ttestprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))\n#define lisdigit(c)\ttestprop(c, MASK(DIGITBIT))\n#define lisspace(c)\ttestprop(c, MASK(SPACEBIT))\n#define lisprint(c)\ttestprop(c, MASK(PRINTBIT))\n#define lisxdigit(c)\ttestprop(c, MASK(XDIGITBIT))\n\n/*\n** this 'ltolower' only works for alphabetic characters\n*/\n#define ltolower(c)\t((c) | ('A' ^ 'a'))\n\n\n/* two more entries for 0 and -1 (EOZ) */\nLUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];\n\n\n#else\t\t\t/* }{ */\n\n/*\n** use standard C ctypes\n*/\n\n#include <ctype.h>\n\n\n#define lislalpha(c)\t(isalpha(c) || (c) == '_')\n#define lislalnum(c)\t(isalnum(c) || (c) == '_')\n#define lisdigit(c)\t(isdigit(c))\n#define lisspace(c)\t(isspace(c))\n#define lisprint(c)\t(isprint(c))\n#define lisxdigit(c)\t(isxdigit(c))\n\n#define ltolower(c)\t(tolower(c))\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** The hook table at registry[&HOOKKEY] maps threads to their current\n** hook function. (We only need the unique address of 'HOOKKEY'.)\n*/\nstatic const int HOOKKEY = 0;\n\n\n/*\n** If L1 != L, L1 can be in any state, and therefore there are no\n** guarantees about its stack space; any push in L1 must be\n** checked.\n*/\nstatic void checkstack (lua_State *L, lua_State *L1, int n) {\n  if (L != L1 && !lua_checkstack(L1, n))\n    luaL_error(L, \"stack overflow\");\n}\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;  /* return 1st argument */\n}\n\n\nstatic int db_getuservalue (lua_State *L) {\n  if (lua_type(L, 1) != LUA_TUSERDATA)\n    lua_pushnil(L);\n  else\n    lua_getuservalue(L, 1);\n  return 1;\n}\n\n\nstatic int db_setuservalue (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TUSERDATA);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_setuservalue(L, 1);\n  return 1;\n}\n\n\n/*\n** Auxiliary function used by several library functions: check for\n** an optional thread as function's first argument and set 'arg' with\n** 1 if this argument is present (so that functions can skip it to\n** access their other arguments)\n*/\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;  /* function will operate over current thread */\n  }\n}\n\n\n/*\n** Variations of 'lua_settable', used by 'db_getinfo' to put results\n** from 'lua_getinfo' into result table. Key is always a string;\n** value can be a string, an int, or a boolean.\n*/\nstatic void settabss (lua_State *L, const char *k, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsi (lua_State *L, const char *k, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsb (lua_State *L, const char *k, int v) {\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, k);\n}\n\n\n/*\n** In function 'db_getinfo', the call to 'lua_getinfo' may push\n** results on the stack; later it creates the result table to put\n** these objects. Function 'treatstackoption' puts the result from\n** 'lua_getinfo' on top of the result table so that it can call\n** 'lua_setfield'.\n*/\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1)\n    lua_rotate(L, -2, 1);  /* exchange object and table */\n  else\n    lua_xmove(L1, L, 1);  /* move object to the \"main\" stack */\n  lua_setfield(L, -2, fname);  /* put object into table */\n}\n\n\n/*\n** Calls 'lua_getinfo' and collects all results in a new table.\n** L1 needs stack space for an optional input (function) plus\n** two optional outputs (function and line table) from function\n** 'lua_getinfo'.\n*/\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnStu\");\n  checkstack(L, L1, 3);\n  if (lua_isfunction(L, arg + 1)) {  /* info about a function? */\n    options = lua_pushfstring(L, \">%s\", options);  /* add '>' to 'options' */\n    lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */\n    lua_xmove(L, L1, 1);\n  }\n  else {  /* stack level */\n    if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_newtable(L);  /* table to collect results */\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u')) {\n    settabsi(L, \"nups\", ar.nups);\n    settabsi(L, \"nparams\", ar.nparams);\n    settabsb(L, \"isvararg\", ar.isvararg);\n  }\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 't'))\n    settabsb(L, \"istailcall\", ar.istailcall);\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n\n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */\n  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\n    lua_pushvalue(L, arg + 1);  /* push function */\n    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\n    return 1;  /* return only name (there is no value) */\n  }\n  else {  /* stack-level argument */\n    int level = (int)luaL_checkinteger(L, arg + 1);\n    if (!lua_getstack(L1, level, &ar))  /* out of range? */\n      return luaL_argerror(L, arg+1, \"level out of range\");\n    checkstack(L, L1, 1);\n    name = lua_getlocal(L1, &ar, nvar);\n    if (name) {\n      lua_xmove(L1, L, 1);  /* move local value */\n      lua_pushstring(L, name);  /* push name */\n      lua_rotate(L, -2, 1);  /* re-order */\n      return 2;\n    }\n    else {\n      lua_pushnil(L);  /* no name (nor value) */\n      return 1;\n    }\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  const char *name;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  int level = (int)luaL_checkinteger(L, arg + 1);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);\n  if (!lua_getstack(L1, level, &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  checkstack(L, L1, 1);\n  lua_xmove(L, L1, 1);\n  name = lua_setlocal(L1, &ar, nvar);\n  if (name == NULL)\n    lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */\n  lua_pushstring(L, name);\n  return 1;\n}\n\n\n/*\n** get (if 'get' is true) or set an upvalue from a closure\n*/\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */\n  luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));  /* no-op if get is false */\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n/*\n** Check whether a given upvalue from a given closure exists and\n** returns its index\n*/\nstatic int checkupval (lua_State *L, int argf, int argnup) {\n  int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */\n  luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */\n  luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup,\n                   \"invalid upvalue index\");\n  return nup;\n}\n\n\nstatic int db_upvalueid (lua_State *L) {\n  int n = checkupval(L, 1, 2);\n  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\n  return 1;\n}\n\n\nstatic int db_upvaluejoin (lua_State *L) {\n  int n1 = checkupval(L, 1, 2);\n  int n2 = checkupval(L, 3, 4);\n  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, \"Lua function expected\");\n  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, \"Lua function expected\");\n  lua_upvaluejoin(L, 1, n1, 3, n2);\n  return 0;\n}\n\n\n/*\n** Call hook function registered at hook table for the current\n** thread (if there is one)\n*/\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail call\"};\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n  lua_pushthread(L);\n  if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */\n    lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);  /* push current line */\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);  /* call hook function */\n  }\n}\n\n\n/*\n** Convert a string mask (for 'sethook') into a bit mask\n*/\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\n/*\n** Convert a bit mask (for 'gethook') into a string mask\n*/\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = (int)luaL_optinteger(L, arg + 3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {\n    lua_createtable(L, 0, 2);  /* create a hook table */\n    lua_pushvalue(L, -1);\n    lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */\n    lua_pushstring(L, \"k\");\n    lua_setfield(L, -2, \"__mode\");  /** hooktable.__mode = \"k\" */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */\n  }\n  checkstack(L, L1, 1);\n  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */\n  lua_pushvalue(L, arg + 1);  /* value (hook function) */\n  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */\n  lua_sethook(L1, func, mask, count);\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook == NULL)  /* no hook? */\n    lua_pushnil(L);\n  else if (hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {  /* hook table must exist */\n    lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n    checkstack(L, L1, 1);\n    lua_pushthread(L1); lua_xmove(L1, L, 1);\n    lua_rawget(L, -2);   /* 1st result = hooktable[L1] */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */\n  lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    lua_writestringerror(\"%s\", \"lua_debug> \");\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0))\n      lua_writestringerror(\"%s\\n\", lua_tostring(L, -1));\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\nstatic int db_traceback (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg + 1);\n  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\n    lua_pushvalue(L, arg + 1);  /* return it untouched */\n  else {\n    int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);\n    luaL_traceback(L, L1, msg, level);\n  }\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getuservalue\", db_getuservalue},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"upvaluejoin\", db_upvaluejoin},\n  {\"upvalueid\", db_upvalueid},\n  {\"setuservalue\", db_setuservalue},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_traceback},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_debug (lua_State *L) {\n  luaL_newlib(L, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n#define noLuaClosure(f)\t\t((f) == NULL || (f)->c.tt == LUA_TCCL)\n\n\n/* Active Lua function (given call info) */\n#define ci_func(ci)\t\t(clLvalue((ci)->func))\n\n\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                    const char **name);\n\n\nstatic int currentpc (CallInfo *ci) {\n  lua_assert(isLua(ci));\n  return pcRel(ci->u.l.savedpc, ci_func(ci)->p);\n}\n\n\nstatic int currentline (CallInfo *ci) {\n  return getfuncline(ci_func(ci)->p, currentpc(ci));\n}\n\n\n/*\n** If function yielded, its 'func' can be in the 'extra' field. The\n** next function restores 'func' to its correct value for debugging\n** purposes. (It exchanges 'func' and 'extra'; so, when called again,\n** after debugging, it also \"re-restores\" ** 'func' to its altered value.\n*/\nstatic void swapextra (lua_State *L) {\n  if (L->status == LUA_YIELD) {\n    CallInfo *ci = L->ci;  /* get function that yielded */\n    StkId temp = ci->func;  /* exchange its 'func' and 'extra' values */\n    ci->func = restorestack(L, ci->extra);\n    ci->extra = savestack(L, temp);\n  }\n}\n\n\n/*\n** This function can be called asynchronously (e.g. during a signal).\n** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by\n** 'resethookcount') are for debug only, and it is no problem if they\n** get arbitrary values (causes at most one wrong hook call). 'hookmask'\n** is an atomic value. We assume that pointers are atomic too (e.g., gcc\n** ensures that for all platforms where it runs). Moreover, 'hook' is\n** always checked before being called (see 'luaD_hook').\n*/\nLUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  if (isLua(L->ci))\n    L->oldpc = L->ci->u.l.savedpc;\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  if (level < 0) return 0;  /* invalid (negative) level */\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)\n    level--;\n  if (level == 0 && ci != &L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = ci;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic const char *upvalname (Proto *p, int uv) {\n  TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);\n  if (s == NULL) return \"?\";\n  else return getstr(s);\n}\n\n\nstatic const char *findvararg (CallInfo *ci, int n, StkId *pos) {\n  int nparams = clLvalue(ci->func)->p->numparams;\n  if (n >= cast_int(ci->u.l.base - ci->func) - nparams)\n    return NULL;  /* no such vararg */\n  else {\n    *pos = ci->func + nparams + n;\n    return \"(*vararg)\";  /* generic name for any vararg */\n  }\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n,\n                              StkId *pos) {\n  const char *name = NULL;\n  StkId base;\n  if (isLua(ci)) {\n    if (n < 0)  /* access to vararg values? */\n      return findvararg(ci, -n, pos);\n    else {\n      base = ci->u.l.base;\n      name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));\n    }\n  }\n  else\n    base = ci->func + 1;\n  if (name == NULL) {  /* no 'standard' name? */\n    StkId limit = (ci == L->ci) ? L->top : ci->next->func;\n    if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      name = \"(*temporary)\";  /* generic name for any valid slot */\n    else\n      return NULL;  /* no name */\n  }\n  *pos = base + (n - 1);\n  return name;\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  if (ar == NULL) {  /* information about non-active function? */\n    if (!isLfunction(L->top - 1))  /* not a Lua function? */\n      name = NULL;\n    else  /* consider live variables at function start (parameters) */\n      name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);\n  }\n  else {  /* active function; get information through 'ar' */\n    StkId pos = NULL;  /* to avoid warnings */\n    name = findlocal(L, ar->i_ci, n, &pos);\n    if (name) {\n      setobj2s(L, L->top, pos);\n      api_incr_top(L);\n    }\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  StkId pos = NULL;  /* to avoid warnings */\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  name = findlocal(L, ar->i_ci, n, &pos);\n  if (name) {\n    setobjs2s(L, pos, L->top - 1);\n    L->top--;  /* pop value */\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (noLuaClosure(cl)) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    Proto *p = cl->l.p;\n    ar->source = p->source ? getstr(p->source) : \"=?\";\n    ar->linedefined = p->linedefined;\n    ar->lastlinedefined = p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (noLuaClosure(f)) {\n    setnilvalue(L->top);\n    api_incr_top(L);\n  }\n  else {\n    int i;\n    TValue v;\n    int *lineinfo = f->l.p->lineinfo;\n    Table *t = luaH_new(L);  /* new table to store active lines */\n    sethvalue(L, L->top, t);  /* push it on stack */\n    api_incr_top(L);\n    setbvalue(&v, 1);  /* boolean 'true' to be the value of all indices */\n    for (i = 0; i < f->l.p->sizelineinfo; i++)  /* for all lines with code */\n      luaH_setint(L, t, lineinfo[i], &v);  /* table[line] = true */\n  }\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  if (ci == NULL)  /* no 'ci'? */\n    return NULL;  /* no info */\n  else if (ci->callstatus & CIST_FIN) {  /* is this a finalizer? */\n    *name = \"__gc\";\n    return \"metamethod\";  /* report it as such */\n  }\n  /* calling function is a known Lua function? */\n  else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))\n    return funcnamefromcode(L, ci->previous, name);\n  else return NULL;  /* no way to find a name */\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                       Closure *f, CallInfo *ci) {\n  int status = 1;\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = (f == NULL) ? 0 : f->c.nupvalues;\n        if (noLuaClosure(f)) {\n          ar->isvararg = 1;\n          ar->nparams = 0;\n        }\n        else {\n          ar->isvararg = f->l.p->is_vararg;\n          ar->nparams = f->l.p->numparams;\n        }\n        break;\n      }\n      case 't': {\n        ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = getfuncname(L, ci, &ar->name);\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *cl;\n  CallInfo *ci;\n  StkId func;\n  lua_lock(L);\n  swapextra(L);\n  if (*what == '>') {\n    ci = NULL;\n    func = L->top - 1;\n    api_check(L, ttisfunction(func), \"function expected\");\n    what++;  /* skip the '>' */\n    L->top--;  /* pop function */\n  }\n  else {\n    ci = ar->i_ci;\n    func = ci->func;\n    lua_assert(ttisfunction(ci->func));\n  }\n  cl = ttisclosure(func) ? clvalue(func) : NULL;\n  status = auxgetinfo(L, what, ar, cl, ci);\n  if (strchr(what, 'f')) {\n    setobjs2s(L, L->top, func);\n    api_incr_top(L);\n  }\n  swapextra(L);  /* correct before option 'L', which can raise a mem. error */\n  if (strchr(what, 'L'))\n    collectvalidlines(L, cl);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution\n** =======================================================\n*/\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name);\n\n\n/*\n** find a \"name\" for the RK value 'c'\n*/\nstatic void kname (Proto *p, int pc, int c, const char **name) {\n  if (ISK(c)) {  /* is 'c' a constant? */\n    TValue *kvalue = &p->k[INDEXK(c)];\n    if (ttisstring(kvalue)) {  /* literal constant? */\n      *name = svalue(kvalue);  /* it is its own name */\n      return;\n    }\n    /* else no reasonable name found */\n  }\n  else {  /* 'c' is a register */\n    const char *what = getobjname(p, pc, c, name); /* search for 'c' */\n    if (what && *what == 'c') {  /* found a constant name? */\n      return;  /* 'name' already filled */\n    }\n    /* else no reasonable name found */\n  }\n  *name = \"?\";  /* no reasonable name found */\n}\n\n\nstatic int filterpc (int pc, int jmptarget) {\n  if (pc < jmptarget)  /* is code conditional (inside a jump)? */\n    return -1;  /* cannot know who sets that register */\n  else return pc;  /* current position sets that register */\n}\n\n\n/*\n** try to find last instruction before 'lastpc' that modified register 'reg'\n*/\nstatic int findsetreg (Proto *p, int lastpc, int reg) {\n  int pc;\n  int setreg = -1;  /* keep last instruction that changed 'reg' */\n  int jmptarget = 0;  /* any code before this address is conditional */\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    switch (op) {\n      case OP_LOADNIL: {\n        int b = GETARG_B(i);\n        if (a <= reg && reg <= a + b)  /* set registers from 'a' to 'a+b' */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_TFORCALL: {\n        if (reg >= a + 2)  /* affect all regs above its base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (reg >= a)  /* affect all registers above base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_JMP: {\n        int b = GETARG_sBx(i);\n        int dest = pc + 1 + b;\n        /* jump is forward and do not skip 'lastpc'? */\n        if (pc < dest && dest <= lastpc) {\n          if (dest > jmptarget)\n            jmptarget = dest;  /* update 'jmptarget' */\n        }\n        break;\n      }\n      default:\n        if (testAMode(op) && reg == a)  /* any instruction that set A */\n          setreg = filterpc(pc, jmptarget);\n        break;\n    }\n  }\n  return setreg;\n}\n\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name) {\n  int pc;\n  *name = luaF_getlocalname(p, reg + 1, lastpc);\n  if (*name)  /* is a local? */\n    return \"local\";\n  /* else try symbolic execution */\n  pc = findsetreg(p, lastpc, reg);\n  if (pc != -1) {  /* could find instruction? */\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    switch (op) {\n      case OP_MOVE: {\n        int b = GETARG_B(i);  /* move from 'b' to 'a' */\n        if (b < GETARG_A(i))\n          return getobjname(p, pc, b, name);  /* get name for 'b' */\n        break;\n      }\n      case OP_GETTABUP:\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        int t = GETARG_B(i);  /* table index */\n        const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */\n                         ? luaF_getlocalname(p, t + 1, pc)\n                         : upvalname(p, t);\n        kname(p, pc, k, name);\n        return (vn && strcmp(vn, LUA_ENV) == 0) ? \"global\" : \"field\";\n      }\n      case OP_GETUPVAL: {\n        *name = upvalname(p, GETARG_B(i));\n        return \"upvalue\";\n      }\n      case OP_LOADK:\n      case OP_LOADKX: {\n        int b = (op == OP_LOADK) ? GETARG_Bx(i)\n                                 : GETARG_Ax(p->code[pc + 1]);\n        if (ttisstring(&p->k[b])) {\n          *name = svalue(&p->k[b]);\n          return \"constant\";\n        }\n        break;\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, pc, k, name);\n        return \"method\";\n      }\n      default: break;  /* go through to return NULL */\n    }\n  }\n  return NULL;  /* could not find reasonable name */\n}\n\n\n/*\n** Try to find a name for a function based on the code that called it.\n** (Only works when function was called by a Lua function.)\n** Returns what the name is (e.g., \"for iterator\", \"method\",\n** \"metamethod\") and sets '*name' to point to the name.\n*/\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                     const char **name) {\n  TMS tm = (TMS)0;  /* (initial value avoids warnings) */\n  Proto *p = ci_func(ci)->p;  /* calling function */\n  int pc = currentpc(ci);  /* calling instruction index */\n  Instruction i = p->code[pc];  /* calling instruction */\n  if (ci->callstatus & CIST_HOOKED) {  /* was it called inside a hook? */\n    *name = \"?\";\n    return \"hook\";\n  }\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n      return getobjname(p, pc, GETARG_A(i), name);  /* get function name */\n    case OP_TFORCALL: {  /* for iterator */\n      *name = \"for iterator\";\n       return \"for iterator\";\n    }\n    /* other instructions can do calls through metamethods */\n    case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:\n      tm = TM_INDEX;\n      break;\n    case OP_SETTABUP: case OP_SETTABLE:\n      tm = TM_NEWINDEX;\n      break;\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:\n    case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:\n    case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {\n      int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD);  /* ORDER OP */\n      tm = cast(TMS, offset + cast_int(TM_ADD));  /* ORDER TM */\n      break;\n    }\n    case OP_UNM: tm = TM_UNM; break;\n    case OP_BNOT: tm = TM_BNOT; break;\n    case OP_LEN: tm = TM_LEN; break;\n    case OP_CONCAT: tm = TM_CONCAT; break;\n    case OP_EQ: tm = TM_EQ; break;\n    case OP_LT: tm = TM_LT; break;\n    case OP_LE: tm = TM_LE; break;\n    default:\n      return NULL;  /* cannot find a reasonable name */\n  }\n  *name = getstr(G(L)->tmname[tm]);\n  return \"metamethod\";\n}\n\n/* }====================================================== */\n\n\n\n/*\n** The subtraction of two potentially unrelated pointers is\n** not ISO C, but it should not crash a program; the subsequent\n** checks are ISO C and ensure a correct result.\n*/\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  ptrdiff_t i = o - ci->u.l.base;\n  return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);\n}\n\n\n/*\n** Checks whether value 'o' came from an upvalue. (That can only happen\n** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on\n** upvalues.)\n*/\nstatic const char *getupvalname (CallInfo *ci, const TValue *o,\n                                 const char **name) {\n  LClosure *c = ci_func(ci);\n  int i;\n  for (i = 0; i < c->nupvalues; i++) {\n    if (c->upvals[i]->v == o) {\n      *name = upvalname(c->p, i);\n      return \"upvalue\";\n    }\n  }\n  return NULL;\n}\n\n\nstatic const char *varinfo (lua_State *L, const TValue *o) {\n  const char *name = NULL;  /* to avoid warnings */\n  CallInfo *ci = L->ci;\n  const char *kind = NULL;\n  if (isLua(ci)) {\n    kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */\n    if (!kind && isinstack(ci, o))  /* no? try a register */\n      kind = getobjname(ci_func(ci)->p, currentpc(ci),\n                        cast_int(o - ci->u.l.base), &name);\n  }\n  return (kind) ? luaO_pushfstring(L, \" (%s '%s')\", kind, name) : \"\";\n}\n\n\nl_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *t = luaT_objtypename(L, o);\n  luaG_runerror(L, \"attempt to %s a %s value%s\", op, t, varinfo(L, o));\n}\n\n\nl_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {\n  if (ttisstring(p1) || cvt2str(p1)) p1 = p2;\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nl_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                         const TValue *p2, const char *msg) {\n  lua_Number temp;\n  if (!tonumber(p1, &temp))  /* first operand is wrong? */\n    p2 = p1;  /* now second is wrong */\n  luaG_typeerror(L, p2, msg);\n}\n\n\n/*\n** Error when both values are convertible to numbers, but not to integers\n*/\nl_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {\n  lua_Integer temp;\n  if (!tointeger(p1, &temp))\n    p2 = p1;\n  luaG_runerror(L, \"number%s has no integer representation\", varinfo(L, p2));\n}\n\n\nl_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_objtypename(L, p1);\n  const char *t2 = luaT_objtypename(L, p2);\n  if (strcmp(t1, t2) == 0)\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n}\n\n\n/* add src:line information to 'msg' */\nconst char *luaG_addinfo (lua_State *L, const char *msg, TString *src,\n                                        int line) {\n  char buff[LUA_IDSIZE];\n  if (src)\n    luaO_chunkid(buff, getstr(src), LUA_IDSIZE);\n  else {  /* no source available; use \"?\" instead */\n    buff[0] = '?'; buff[1] = '\\0';\n  }\n  return luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n}\n\n\nl_noret luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    L->top++;  /* assume EXTRA_STACK */\n    luaD_callnoyield(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nl_noret luaG_runerror (lua_State *L, const char *fmt, ...) {\n  CallInfo *ci = L->ci;\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);  /* format message */\n  va_end(argp);\n  if (isLua(ci))  /* if Lua function, add source:line information */\n    luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));\n  luaG_errormsg(L);\n}\n\n\nvoid luaG_traceexec (lua_State *L) {\n  CallInfo *ci = L->ci;\n  lu_byte mask = L->hookmask;\n  int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));\n  if (counthook)\n    resethookcount(L);  /* reset count */\n  else if (!(mask & LUA_MASKLINE))\n    return;  /* no line hook and count != 0; nothing to be done */\n  if (ci->callstatus & CIST_HOOKYIELD) {  /* called hook last time? */\n    ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */\n    return;  /* do not call hook again (VM yielded, so it did not move) */\n  }\n  if (counthook)\n    luaD_hook(L, LUA_HOOKCOUNT, -1);  /* call count hook */\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(ci)->p;\n    int npc = pcRel(ci->u.l.savedpc, p);\n    int newline = getfuncline(p, npc);\n    if (npc == 0 ||  /* call linehook when enter a new function, */\n        ci->u.l.savedpc <= L->oldpc ||  /* when jump back (loop), or when */\n        newline != getfuncline(p, pcRel(L->oldpc, p)))  /* enter a new line */\n      luaD_hook(L, LUA_HOOKLINE, newline);  /* call line hook */\n  }\n  L->oldpc = ci->u.l.savedpc;\n  if (L->status == LUA_YIELD) {  /* did hook yield? */\n    if (counthook)\n      L->hookcount = 1;  /* undo decrement to zero */\n    ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */\n    ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */\n    ci->func = L->top - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n}\n\n"
  },
  {
    "path": "WebGLPlugins/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getfuncline(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : -1)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,\n                                                const char *opname);\nLUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,\n                                                  const TValue *p2);\nLUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2,\n                                                 const char *msg);\nLUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,\n                                                  TString *src, int line);\nLUAI_FUNC l_noret luaG_errormsg (lua_State *L);\nLUAI_FUNC void luaG_traceexec (lua_State *L);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n#define errorstatus(s)\t((s) > LUA_YIELD)\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n/*\n** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By\n** default, Lua handles errors with exceptions when compiling as\n** C++ code, with _longjmp/_setjmp when asked to use them, and with\n** longjmp/setjmp otherwise.\n*/\n#if !defined(LUAI_THROW)\t\t\t\t/* { */\n\n#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)\t/* { */\n\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\t\tthrow(c)\n#define LUAI_TRY(L,c,a) \\\n\ttry { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\t\tint  /* dummy variable */\n\n#elif defined(LUA_USE_POSIX)\t\t\t\t/* }{ */\n\n/* in POSIX, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#else\t\t\t\t\t\t\t/* }{ */\n\n/* ISO C handling with long jumps */\n#define LUAI_THROW(L,c)\t\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#endif\t\t\t\t\t\t\t/* } */\n\n#endif\t\t\t\t\t\t\t/* } */\n\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nstatic void seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {  /* memory error? */\n      setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    default: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nl_noret luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {  /* thread has an error handler? */\n    L->errorJmp->status = errcode;  /* set status */\n    LUAI_THROW(L, L->errorJmp);  /* jump to it */\n  }\n  else {  /* thread has no error handler */\n    global_State *g = G(L);\n    L->status = cast_byte(errcode);  /* mark it as dead */\n    if (g->mainthread->errorJmp) {  /* main thread has a handler? */\n      setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */\n      luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */\n    }\n    else {  /* no handler at all; abort */\n      if (g->panic) {  /* panic function? */\n        seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */\n        if (L->ci->top < L->top)\n          L->ci->top = L->top;  /* pushing msg. can break this invariant */\n        lua_unlock(L);\n        g->panic(L);  /* call panic function (last chance to jump out) */\n      }\n      abort();\n    }\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  unsigned short oldnCcalls = L->nCcalls;\n  struct lua_longjmp lj;\n  lj.status = LUA_OK;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  L->nCcalls = oldnCcalls;\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\n/*\n** {==================================================================\n** Stack reallocation\n** ===================================================================\n*/\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  UpVal *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->u.open.next)\n    up->v = (up->v - oldstack) + L->stack;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n    if (isLua(ci))\n      ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;\n  }\n}\n\n\n/* some space for error handling */\n#define ERRORSTACKSIZE\t(LUAI_MAXSTACK + 200)\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int lim = L->stacksize;\n  lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);\n  luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);\n  for (; lim < newsize; lim++)\n    setnilvalue(L->stack + lim); /* erase new segment */\n  L->stacksize = newsize;\n  L->stack_last = L->stack + newsize - EXTRA_STACK;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  int size = L->stacksize;\n  if (size > LUAI_MAXSTACK)  /* error after extra size? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;\n    int newsize = 2 * size;\n    if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;\n    if (newsize < needed) newsize = needed;\n    if (newsize > LUAI_MAXSTACK) {  /* stack overflow? */\n      luaD_reallocstack(L, ERRORSTACKSIZE);\n      luaG_runerror(L, \"stack overflow\");\n    }\n    else\n      luaD_reallocstack(L, newsize);\n  }\n}\n\n\nstatic int stackinuse (lua_State *L) {\n  CallInfo *ci;\n  StkId lim = L->top;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    if (lim < ci->top) lim = ci->top;\n  }\n  lua_assert(lim <= L->stack_last);\n  return cast_int(lim - L->stack) + 1;  /* part of stack in use */\n}\n\n\nvoid luaD_shrinkstack (lua_State *L) {\n  int inuse = stackinuse(L);\n  int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;\n  if (goodsize > LUAI_MAXSTACK)\n    goodsize = LUAI_MAXSTACK;  /* respect stack limit */\n  if (L->stacksize > LUAI_MAXSTACK)  /* had been handling stack overflow? */\n    luaE_freeCI(L);  /* free all CIs (list grew because of an error) */\n  else\n    luaE_shrinkCI(L);  /* shrink list */\n  /* if thread is currently not handling a stack overflow and its\n     good size is smaller than current size, shrink its stack */\n  if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) &&\n      goodsize < L->stacksize)\n    luaD_reallocstack(L, goodsize);\n  else  /* don't change stack */\n    condmovestack(L,{},{});  /* (change only for debugging) */\n}\n\n\nvoid luaD_inctop (lua_State *L) {\n  luaD_checkstack(L, 1);\n  L->top++;\n}\n\n/* }================================================================== */\n\n\n/*\n** Call a hook for the given event. Make sure there is a hook to be\n** called. (Both 'L->hook' and 'L->hookmask', which triggers this\n** function, can be changed asynchronously by signals.)\n*/\nvoid luaD_hook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {  /* make sure there is a hook */\n    CallInfo *ci = L->ci;\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    ar.i_ci = ci;\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    ci->top = L->top + LUA_MINSTACK;\n    lua_assert(ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    ci->callstatus |= CIST_HOOKED;\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n    ci->callstatus &= ~CIST_HOOKED;\n  }\n}\n\n\nstatic void callhook (lua_State *L, CallInfo *ci) {\n  int hook = LUA_HOOKCALL;\n  ci->u.l.savedpc++;  /* hooks assume 'pc' is already incremented */\n  if (isLua(ci->previous) &&\n      GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {\n    ci->callstatus |= CIST_TAIL;\n    hook = LUA_HOOKTAILCALL;\n  }\n  luaD_hook(L, hook, -1);\n  ci->u.l.savedpc--;  /* correct 'pc' */\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n  StkId base, fixed;\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i = 0; i < nfixargs && i < actual; i++) {\n    setobjs2s(L, L->top++, fixed + i);\n    setnilvalue(fixed + i);  /* erase original copy (for GC) */\n  }\n  for (; i < nfixargs; i++)\n    setnilvalue(L->top++);  /* complete missing arguments */\n  return base;\n}\n\n\n/*\n** Check whether __call metafield of 'func' is a function. If so, put\n** it in stack below original 'func' so that 'luaD_precall' can call\n** it. Raise an error if __call metafield is not a function.\n*/\nstatic void tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at 'func' */\n  for (p = L->top; p > func; p--)\n    setobjs2s(L, p, p-1);\n  L->top++;  /* slot ensured by caller */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n}\n\n\n/*\n** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.\n** Handle most typical cases (zero results for commands, one result for\n** expressions, multiple results for tail calls/single parameters)\n** separated.\n*/\nstatic int moveresults (lua_State *L, const TValue *firstResult, StkId res,\n                                      int nres, int wanted) {\n  switch (wanted) {  /* handle typical cases separately */\n    case 0: break;  /* nothing to move */\n    case 1: {  /* one result needed */\n      if (nres == 0)   /* no results? */\n        firstResult = luaO_nilobject;  /* adjust with nil */\n      setobjs2s(L, res, firstResult);  /* move it to proper place */\n      break;\n    }\n    case LUA_MULTRET: {\n      int i;\n      for (i = 0; i < nres; i++)  /* move all results to correct place */\n        setobjs2s(L, res + i, firstResult + i);\n      L->top = res + nres;\n      return 0;  /* wanted == LUA_MULTRET */\n    }\n    default: {\n      int i;\n      if (wanted <= nres) {  /* enough results? */\n        for (i = 0; i < wanted; i++)  /* move wanted results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n      }\n      else {  /* not enough results; use all of them plus nils */\n        for (i = 0; i < nres; i++)  /* move all results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n        for (; i < wanted; i++)  /* complete wanted number of results */\n          setnilvalue(res + i);\n      }\n      break;\n    }\n  }\n  L->top = res + wanted;  /* top points after the last result */\n  return 1;\n}\n\n\n/*\n** Finishes a function call: calls hook if necessary, removes CallInfo,\n** moves current number of results to proper place; returns 0 iff call\n** wanted multiple (variable number of) results.\n*/\nint luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {\n  StkId res;\n  int wanted = ci->nresults;\n  if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {\n    if (L->hookmask & LUA_MASKRET) {\n      ptrdiff_t fr = savestack(L, firstResult);  /* hook may change stack */\n      luaD_hook(L, LUA_HOOKRET, -1);\n      firstResult = restorestack(L, fr);\n    }\n    L->oldpc = ci->previous->u.l.savedpc;  /* 'oldpc' for caller function */\n  }\n  res = ci->func;  /* res == final position of 1st result */\n  L->ci = ci->previous;  /* back to caller */\n  /* move results to proper place */\n  return moveresults(L, firstResult, res, nres, wanted);\n}\n\n\n\n#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))\n\n\n/* macro to check stack size, preserving 'p' */\n#define checkstackp(L,n,p)  \\\n  luaD_checkstackaux(L, n, \\\n    ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \\\n    luaC_checkGC(L),  /* stack grow uses memory */ \\\n    p = restorestack(L, t__))  /* 'pos' part: restore 'p' */\n\n\n/*\n** Prepares a function call: checks the stack, creates a new CallInfo\n** entry, fills in the relevant information, calls hook if needed.\n** If function is a C function, does the call, too. (Otherwise, leave\n** the execution ('luaV_execute') to the caller, to allow stackless\n** calls.) Returns true iff function has been executed (C function).\n*/\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  lua_CFunction f;\n  CallInfo *ci;\n  switch (ttype(func)) {\n    case LUA_TCCL:  /* C closure */\n      f = clCvalue(func)->f;\n      goto Cfunc;\n    case LUA_TLCF:  /* light C function */\n      f = fvalue(func);\n     Cfunc: {\n      int n;  /* number of returns */\n      checkstackp(L, LUA_MINSTACK, func);  /* ensure minimum stack size */\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->top = L->top + LUA_MINSTACK;\n      lua_assert(ci->top <= L->stack_last);\n      ci->callstatus = 0;\n      if (L->hookmask & LUA_MASKCALL)\n        luaD_hook(L, LUA_HOOKCALL, -1);\n      lua_unlock(L);\n      n = (*f)(L);  /* do the actual call */\n      lua_lock(L);\n      api_checknelems(L, n);\n      luaD_poscall(L, ci, L->top - n, n);\n      return 1;\n    }\n    case LUA_TLCL: {  /* Lua function: prepare its call */\n      StkId base;\n      Proto *p = clLvalue(func)->p;\n      int n = cast_int(L->top - func) - 1;  /* number of real arguments */\n      int fsize = p->maxstacksize;  /* frame size */\n      checkstackp(L, fsize, func);\n      if (p->is_vararg)\n        base = adjust_varargs(L, p, n);\n      else {  /* non vararg function */\n        for (; n < p->numparams; n++)\n          setnilvalue(L->top++);  /* complete missing arguments */\n        base = func + 1;\n      }\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->u.l.base = base;\n      L->top = ci->top = base + fsize;\n      lua_assert(ci->top <= L->stack_last);\n      ci->u.l.savedpc = p->code;  /* starting point */\n      ci->callstatus = CIST_LUA;\n      if (L->hookmask & LUA_MASKCALL)\n        callhook(L, ci);\n      return 0;\n    }\n    default: {  /* not a function */\n      checkstackp(L, 1, func);  /* ensure space for metamethod */\n      tryfuncTM(L, func);  /* try to get '__call' metamethod */\n      return luaD_precall(L, func, nresults);  /* now it must be a function */\n    }\n  }\n}\n\n\n/*\n** Check appropriate error for stack overflow (\"regular\" overflow or\n** overflow while handling stack overflow). If 'nCalls' is larger than\n** LUAI_MAXCCALLS (which means it is handling a \"regular\" overflow) but\n** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to\n** allow overflow handling to work)\n*/\nstatic void stackerror (lua_State *L) {\n  if (L->nCcalls == LUAI_MAXCCALLS)\n    luaG_runerror(L, \"C stack overflow\");\n  else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n    luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/\nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS)\n    stackerror(L);\n  if (!luaD_precall(L, func, nResults))  /* is a Lua function? */\n    luaV_execute(L);  /* call it */\n  L->nCcalls--;\n}\n\n\n/*\n** Similar to 'luaD_call', but does not allow yields during the call\n*/\nvoid luaD_callnoyield (lua_State *L, StkId func, int nResults) {\n  L->nny++;\n  luaD_call(L, func, nResults);\n  L->nny--;\n}\n\n\n/*\n** Completes the execution of an interrupted C function, calling its\n** continuation function.\n*/\nstatic void finishCcall (lua_State *L, int status) {\n  CallInfo *ci = L->ci;\n  int n;\n  /* must have a continuation and must be able to call it */\n  lua_assert(ci->u.c.k != NULL && L->nny == 0);\n  /* error status can only happen in a protected call */\n  lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD);\n  if (ci->callstatus & CIST_YPCALL) {  /* was inside a pcall? */\n    ci->callstatus &= ~CIST_YPCALL;  /* continuation is also inside it */\n    L->errfunc = ci->u.c.old_errfunc;  /* with the same error function */\n  }\n  /* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already\n     handled */\n  adjustresults(L, ci->nresults);\n  lua_unlock(L);\n  n = (*ci->u.c.k)(L, status, ci->u.c.ctx);  /* call continuation function */\n  lua_lock(L);\n  api_checknelems(L, n);\n  luaD_poscall(L, ci, L->top - n, n);  /* finish 'luaD_precall' */\n}\n\n\n/*\n** Executes \"full continuation\" (everything in the stack) of a\n** previously interrupted coroutine until the stack is empty (or another\n** interruption long-jumps out of the loop). If the coroutine is\n** recovering from an error, 'ud' points to the error status, which must\n** be passed to the first continuation function (otherwise the default\n** status is LUA_YIELD).\n*/\nstatic void unroll (lua_State *L, void *ud) {\n  if (ud != NULL)  /* error status? */\n    finishCcall(L, *(int *)ud);  /* finish 'lua_pcallk' callee */\n  while (L->ci != &L->base_ci) {  /* something in the stack */\n    if (!isLua(L->ci))  /* C function? */\n      finishCcall(L, LUA_YIELD);  /* complete its execution */\n    else {  /* Lua function */\n      luaV_finishOp(L);  /* finish interrupted instruction */\n      luaV_execute(L);  /* execute down to higher C 'boundary' */\n    }\n  }\n}\n\n\n/*\n** Try to find a suspended protected call (a \"recover point\") for the\n** given thread.\n*/\nstatic CallInfo *findpcall (lua_State *L) {\n  CallInfo *ci;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {  /* search for a pcall */\n    if (ci->callstatus & CIST_YPCALL)\n      return ci;\n  }\n  return NULL;  /* no pending pcall */\n}\n\n\n/*\n** Recovers from an error in a coroutine. Finds a recover point (if\n** there is one) and completes the execution of the interrupted\n** 'luaD_pcall'. If there is no recover point, returns zero.\n*/\nstatic int recover (lua_State *L, int status) {\n  StkId oldtop;\n  CallInfo *ci = findpcall(L);\n  if (ci == NULL) return 0;  /* no recovery point */\n  /* \"finish\" luaD_pcall */\n  oldtop = restorestack(L, ci->extra);\n  luaF_close(L, oldtop);\n  seterrorobj(L, status, oldtop);\n  L->ci = ci;\n  L->allowhook = getoah(ci->callstatus);  /* restore original 'allowhook' */\n  L->nny = 0;  /* should be zero to be yieldable */\n  luaD_shrinkstack(L);\n  L->errfunc = ci->u.c.old_errfunc;\n  return 1;  /* continue running the coroutine */\n}\n\n\n/*\n** Signal an error in the call to 'lua_resume', not in the execution\n** of the coroutine itself. (Such errors should not be handled by any\n** coroutine error handler and should not kill the coroutine.)\n*/\nstatic int resume_error (lua_State *L, const char *msg, int narg) {\n  L->top -= narg;  /* remove args from the stack */\n  setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */\n  api_incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\n/*\n** Do the work for 'lua_resume' in protected mode. Most of the work\n** depends on the status of the coroutine: initial state, suspended\n** inside a hook, or regularly suspended (optionally with a continuation\n** function), plus erroneous cases: non-suspended coroutine or dead\n** coroutine.\n*/\nstatic void resume (lua_State *L, void *ud) {\n  int n = *(cast(int*, ud));  /* number of arguments */\n  StkId firstArg = L->top - n;  /* first argument */\n  CallInfo *ci = L->ci;\n  if (L->status == LUA_OK) {  /* starting a coroutine? */\n    if (!luaD_precall(L, firstArg - 1, LUA_MULTRET))  /* Lua function? */\n      luaV_execute(L);  /* call it */\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = LUA_OK;  /* mark that it is running (again) */\n    ci->func = restorestack(L, ci->extra);\n    if (isLua(ci))  /* yielded inside a hook? */\n      luaV_execute(L);  /* just continue running Lua code */\n    else {  /* 'common' yield */\n      if (ci->u.c.k != NULL) {  /* does it have a continuation function? */\n        lua_unlock(L);\n        n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */\n        lua_lock(L);\n        api_checknelems(L, n);\n        firstArg = L->top - n;  /* yield results come from continuation */\n      }\n      luaD_poscall(L, ci, firstArg, n);  /* finish 'luaD_precall' */\n    }\n    unroll(L, NULL);  /* run continuation */\n  }\n}\n\n\nLUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {\n  int status;\n  unsigned short oldnny = L->nny;  /* save \"number of non-yieldable\" calls */\n  lua_lock(L);\n  if (L->status == LUA_OK) {  /* may be starting a coroutine */\n    if (L->ci != &L->base_ci)  /* not in base level? */\n      return resume_error(L, \"cannot resume non-suspended coroutine\", nargs);\n  }\n  else if (L->status != LUA_YIELD)\n    return resume_error(L, \"cannot resume dead coroutine\", nargs);\n  L->nCcalls = (from) ? from->nCcalls + 1 : 1;\n  if (L->nCcalls >= LUAI_MAXCCALLS)\n    return resume_error(L, \"C stack overflow\", nargs);\n  luai_userstateresume(L, nargs);\n  L->nny = 0;  /* allow yields */\n  api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);\n  status = luaD_rawrunprotected(L, resume, &nargs);\n  if (status == -1)  /* error calling 'lua_resume'? */\n    status = LUA_ERRRUN;\n  else {  /* continue running after recoverable errors */\n    while (errorstatus(status) && recover(L, status)) {\n      /* unroll continuation */\n      status = luaD_rawrunprotected(L, unroll, &status);\n    }\n    if (errorstatus(status)) {  /* unrecoverable error? */\n      L->status = cast_byte(status);  /* mark thread as 'dead' */\n      seterrorobj(L, status, L->top);  /* push error message */\n      L->ci->top = L->top;\n    }\n    else lua_assert(status == L->status);  /* normal end or yield */\n  }\n  L->nny = oldnny;  /* restore 'nny' */\n  L->nCcalls--;\n  lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_isyieldable (lua_State *L) {\n  return (L->nny == 0);\n}\n\n\nLUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,\n                        lua_KFunction k) {\n  CallInfo *ci = L->ci;\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  api_checknelems(L, nresults);\n  if (L->nny > 0) {\n    if (L != G(L)->mainthread)\n      luaG_runerror(L, \"attempt to yield across a C-call boundary\");\n    else\n      luaG_runerror(L, \"attempt to yield from outside a coroutine\");\n  }\n  L->status = LUA_YIELD;\n  ci->extra = savestack(L, ci->func);  /* save current 'func' */\n  if (isLua(ci)) {  /* inside a hook? */\n    api_check(L, k == NULL, \"hooks cannot continue after yielding\");\n  }\n  else {\n    if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */\n      ci->u.c.ctx = ctx;  /* save context */\n    ci->func = L->top - nresults - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n  lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */\n  lua_unlock(L);\n  return 0;  /* return to 'luaD_hook' */\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  CallInfo *old_ci = L->ci;\n  lu_byte old_allowhooks = L->allowhook;\n  unsigned short old_nny = L->nny;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != LUA_OK) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close possible pending closures */\n    seterrorobj(L, status, oldtop);\n    L->ci = old_ci;\n    L->allowhook = old_allowhooks;\n    L->nny = old_nny;\n    luaD_shrinkstack(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to 'f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* dynamic structure used by the scanner */\n  Dyndata dyd;  /* dynamic structures used by the parser */\n  const char *mode;\n  const char *name;\n};\n\n\nstatic void checkmode (lua_State *L, const char *mode, const char *x) {\n  if (mode && strchr(mode, x[0]) == NULL) {\n    luaO_pushfstring(L,\n       \"attempt to load a %s chunk (mode is '%s')\", x, mode);\n    luaD_throw(L, LUA_ERRSYNTAX);\n  }\n}\n\n\nstatic void f_parser (lua_State *L, void *ud) {\n  LClosure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = zgetc(p->z);  /* read first character */\n  if (c == LUA_SIGNATURE[0]) {\n    checkmode(L, p->mode, \"binary\");\n    cl = luaU_undump(L, p->z, p->name);\n  }\n  else {\n    checkmode(L, p->mode, \"text\");\n    cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);\n  }\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luaF_initupvals(L, cl);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                        const char *mode) {\n  struct SParser p;\n  int status;\n  L->nny++;  /* cannot yield during parsing */\n  p.z = z; p.name = name; p.mode = mode;\n  p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;\n  p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;\n  p.dyd.label.arr = NULL; p.dyd.label.size = 0;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);\n  luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);\n  luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);\n  L->nny--;\n  return status;\n}\n\n\n"
  },
  {
    "path": "WebGLPlugins/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n/*\n** Macro to check stack size and grow stack if needed.  Parameters\n** 'pre'/'pos' allow the macro to preserve a pointer into the\n** stack across reallocations, doing the work only when needed.\n** 'condmovestack' is used in heavy tests to force a stack reallocation\n** at every check.\n*/\n#define luaD_checkstackaux(L,n,pre,pos)  \\\n\tif (L->stack_last - L->top <= (n)) \\\n\t  { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }\n\n/* In general, 'pre'/'pos' are empty (nothing to save) */\n#define luaD_checkstack(L,n)\tluaD_checkstackaux(L,n,(void)0,(void)0)\n\n\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n\n/* type of protected functions, to be ran by 'runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                                  const char *mode);\nLUAI_FUNC void luaD_hook (lua_State *L, int event, int line);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,\n                                          int nres);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\nLUAI_FUNC void luaD_shrinkstack (lua_State *L);\nLUAI_FUNC void luaD_inctop (lua_State *L);\n\nLUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\n\ntypedef struct {\n  lua_State *L;\n  lua_Writer writer;\n  void *data;\n  int strip;\n  int status;\n} DumpState;\n\n\n/*\n** All high-level dumps go through DumpVector; you can change it to\n** change the endianness of the result\n*/\n#define DumpVector(v,n,D)\tDumpBlock(v,(n)*sizeof((v)[0]),D)\n\n#define DumpLiteral(s,D)\tDumpBlock(s, sizeof(s) - sizeof(char), D)\n\n\nstatic void DumpBlock (const void *b, size_t size, DumpState *D) {\n  if (D->status == 0 && size > 0) {\n    lua_unlock(D->L);\n    D->status = (*D->writer)(D->L, b, size, D->data);\n    lua_lock(D->L);\n  }\n}\n\n\n#define DumpVar(x,D)\t\tDumpVector(&x,1,D)\n\n\nstatic void DumpByte (int y, DumpState *D) {\n  lu_byte x = (lu_byte)y;\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInt (int x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpNumber (lua_Number x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInteger (lua_Integer x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpString (const TString *s, DumpState *D) {\n  if (s == NULL)\n    DumpByte(0, D);\n  else {\n    size_t size = tsslen(s) + 1;  /* include trailing '\\0' */\n    const char *str = getstr(s);\n    if (size < 0xFF)\n      DumpByte(cast_int(size), D);\n    else {\n      DumpByte(0xFF, D);\n      DumpVar(size, D);\n    }\n    DumpVector(str, size - 1, D);  /* no need to save '\\0' */\n  }\n}\n\n\nstatic void DumpCode (const Proto *f, DumpState *D) {\n  DumpInt(f->sizecode, D);\n  DumpVector(f->code, f->sizecode, D);\n}\n\n\nstatic void DumpFunction(const Proto *f, TString *psource, DumpState *D);\n\nstatic void DumpConstants (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizek;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    const TValue *o = &f->k[i];\n    DumpByte(ttype(o), D);\n    switch (ttype(o)) {\n    case LUA_TNIL:\n      break;\n    case LUA_TBOOLEAN:\n      DumpByte(bvalue(o), D);\n      break;\n    case LUA_TNUMFLT:\n      DumpNumber(fltvalue(o), D);\n      break;\n    case LUA_TNUMINT:\n      DumpInteger(ivalue(o), D);\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      DumpString(tsvalue(o), D);\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void DumpProtos (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizep;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpFunction(f->p[i], f->source, D);\n}\n\n\nstatic void DumpUpvalues (const Proto *f, DumpState *D) {\n  int i, n = f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpByte(f->upvalues[i].instack, D);\n    DumpByte(f->upvalues[i].idx, D);\n  }\n}\n\n\nstatic void DumpDebug (const Proto *f, DumpState *D) {\n  int i, n;\n  n = (D->strip) ? 0 : f->sizelineinfo;\n  DumpInt(n, D);\n  DumpVector(f->lineinfo, n, D);\n  n = (D->strip) ? 0 : f->sizelocvars;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpString(f->locvars[i].varname, D);\n    DumpInt(f->locvars[i].startpc, D);\n    DumpInt(f->locvars[i].endpc, D);\n  }\n  n = (D->strip) ? 0 : f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpString(f->upvalues[i].name, D);\n}\n\n\nstatic void DumpFunction (const Proto *f, TString *psource, DumpState *D) {\n  if (D->strip || f->source == psource)\n    DumpString(NULL, D);  /* no debug info or same source as its parent */\n  else\n    DumpString(f->source, D);\n  DumpInt(f->linedefined, D);\n  DumpInt(f->lastlinedefined, D);\n  DumpByte(f->numparams, D);\n  DumpByte(f->is_vararg, D);\n  DumpByte(f->maxstacksize, D);\n  DumpCode(f, D);\n  DumpConstants(f, D);\n  DumpUpvalues(f, D);\n  DumpProtos(f, D);\n  DumpDebug(f, D);\n}\n\n\nstatic void DumpHeader (DumpState *D) {\n  DumpLiteral(LUA_SIGNATURE, D);\n  DumpByte(LUAC_VERSION, D);\n  DumpByte(LUAC_FORMAT, D);\n  DumpLiteral(LUAC_DATA, D);\n  DumpByte(sizeof(int), D);\n  DumpByte(sizeof(size_t), D);\n  DumpByte(sizeof(Instruction), D);\n  DumpByte(sizeof(lua_Integer), D);\n  DumpByte(sizeof(lua_Number), D);\n  DumpInteger(LUAC_INT, D);\n  DumpNumber(LUAC_NUM, D);\n}\n\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,\n              int strip) {\n  DumpState D;\n  D.L = L;\n  D.writer = w;\n  D.data = data;\n  D.strip = strip;\n  D.status = 0;\n  DumpHeader(&D);\n  DumpByte(f->sizeupvalues, &D);\n  DumpFunction(f, NULL, &D);\n  return D.status;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nCClosure *luaF_newCclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));\n  CClosure *c = gco2ccl(o);\n  c->nupvalues = cast_byte(n);\n  return c;\n}\n\n\nLClosure *luaF_newLclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));\n  LClosure *c = gco2lcl(o);\n  c->p = NULL;\n  c->nupvalues = cast_byte(n);\n  while (n--) c->upvals[n] = NULL;\n  return c;\n}\n\n/*\n** fill a closure with new closed upvalues\n*/\nvoid luaF_initupvals (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = luaM_new(L, UpVal);\n    uv->refcount = 1;\n    uv->v = &uv->u.value;  /* make it closed */\n    setnilvalue(uv->v);\n    cl->upvals[i] = uv;\n  }\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  UpVal **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  lua_assert(isintwups(L) || L->openupval == NULL);\n  while (*pp != NULL && (p = *pp)->v >= level) {\n    lua_assert(upisopen(p));\n    if (p->v == level)  /* found a corresponding upvalue? */\n      return p;  /* return it */\n    pp = &p->u.open.next;\n  }\n  /* not found: create a new upvalue */\n  uv = luaM_new(L, UpVal);\n  uv->refcount = 0;\n  uv->u.open.next = *pp;  /* link it to list of open upvalues */\n  uv->u.open.touched = 1;\n  *pp = uv;\n  uv->v = level;  /* current value lives in the stack */\n  if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */\n    L->twups = G(L)->twups;  /* link it to the list */\n    G(L)->twups = L;\n  }\n  return uv;\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  while (L->openupval != NULL && (uv = L->openupval)->v >= level) {\n    lua_assert(upisopen(uv));\n    L->openupval = uv->u.open.next;  /* remove from 'open' list */\n    if (uv->refcount == 0)  /* no references? */\n      luaM_free(L, uv);  /* free upvalue */\n    else {\n      setobj(L, &uv->u.value, uv->v);  /* move value to upvalue slot */\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_upvalbarrier(L, uv);\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));\n  Proto *f = gco2p(o);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->cache = NULL;\n  f->sizecode = 0;\n  f->lineinfo = NULL;\n  f->sizelineinfo = 0;\n  f->upvalues = NULL;\n  f->sizeupvalues = 0;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->locvars = NULL;\n  f->sizelocvars = 0;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode);\n  luaM_freearray(L, f->p, f->sizep);\n  luaM_freearray(L, f->k, f->sizek);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo);\n  luaM_freearray(L, f->locvars, f->sizelocvars);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues);\n  luaM_free(L, f);\n}\n\n\n/*\n** Look for n-th local variable at line 'line' in function 'func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\n/* test whether thread is in 'twups' list */\n#define isintwups(L)\t(L->twups != L)\n\n\n/*\n** maximum number of upvalues in a closure (both C and Lua). (Value\n** must fit in a VM register.)\n*/\n#define MAXUPVAL\t255\n\n\n/*\n** Upvalues for Lua closures\n*/\nstruct UpVal {\n  TValue *v;  /* points to stack or to its own value */\n  lu_mem refcount;  /* reference counter */\n  union {\n    struct {  /* (when open) */\n      UpVal *next;  /* linked list */\n      int touched;  /* mark to avoid cycles with dead threads */\n    } open;\n    TValue value;  /* the value (when closed) */\n  } u;\n};\n\n#define upisopen(up)\t((up)->v != &(up)->u.value)\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);\nLUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);\nLUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.215 2016/12/22 13:08:50 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n/*\n** internal state for collector while inside the atomic phase. The\n** collector should never be in this state while running regular code.\n*/\n#define GCSinsideatomic\t\t(GCSpause + 1)\n\n/*\n** cost of sweeping one element (the size of a small object divided\n** by some adjust for the sweep speed)\n*/\n#define GCSWEEPCOST\t((sizeof(TString) + 4) / 4)\n\n/* maximum number of elements to sweep in each single step */\n#define GCSWEEPMAX\t(cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))\n\n/* cost of calling one finalizer */\n#define GCFINALIZECOST\tGCSWEEPCOST\n\n\n/*\n** macro to adjust 'stepmul': 'stepmul' is actually used like\n** 'stepmul / STEPMULADJ' (value chosen by tests)\n*/\n#define STEPMULADJ\t\t200\n\n\n/*\n** macro to adjust 'pause': 'pause' is actually used like\n** 'pause / PAUSEADJ' (value chosen by tests)\n*/\n#define PAUSEADJ\t\t100\n\n\n/*\n** 'makewhite' erases all color bits then sets only the current white\n** bit\n*/\n#define maskcolors\t(~(bitmask(BLACKBIT) | WHITEBITS))\n#define makewhite(g,x)\t\\\n (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))\n\n#define white2gray(x)\tresetbits(x->marked, WHITEBITS)\n#define black2gray(x)\tresetbit(x->marked, BLACKBIT)\n\n\n#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))\n\n#define checkdeadkey(n)\tlua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))\n\n\n#define checkconsistency(obj)  \\\n  lua_longassert(!iscollectable(obj) || righttt(obj))\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t)\t{ if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }\n\n/*\n** mark an object that can be NULL (either because it is really optional,\n** or it was stripped as debug info, or inside an uncompleted structure)\n*/\n#define markobjectN(g,t)\t{ if (t) markobject(g,t); }\n\nstatic void reallymarkobject (global_State *g, GCObject *o);\n\n\n/*\n** {======================================================\n** Generic functions\n** =======================================================\n*/\n\n\n/*\n** one after last element in a hash array\n*/\n#define gnodelast(h)\tgnode(h, cast(size_t, sizenode(h)))\n\n\n/*\n** link collectable object 'o' into list pointed by 'p'\n*/\n#define linkgclist(o,p)\t((o)->gclist = (p), (p) = obj2gco(o))\n\n\n/*\n** If key is not marked, mark its entry as dead. This allows key to be\n** collected, but keeps its entry in the table.  A dead node is needed\n** when Lua looks up for a key (it may be part of a chain) and when\n** traversing a weak table (key might be removed from the table during\n** traversal). Other places never manipulate dead keys, because its\n** associated nil value is enough to signal that the entry is logically\n** empty.\n*/\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (valiswhite(gkey(n)))\n    setdeadvalue(wgkey(n));  /* unused and unmarked key; remove it */\n}\n\n\n/*\n** tells whether a key or value can be cleared from a weak\n** table. Non-collectable objects are never removed from weak\n** tables. Strings behave as 'values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for objects\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (global_State *g, const TValue *o) {\n  if (!iscollectable(o)) return 0;\n  else if (ttisstring(o)) {\n    markobject(g, tsvalue(o));  /* strings are 'values', so are never weak */\n    return 0;\n  }\n  else return iswhite(gcvalue(o));\n}\n\n\n/*\n** barrier that moves collector forward, that is, mark the white object\n** being pointed by a black object. (If in sweep phase, clear the black\n** object to white [sweep it] to avoid other barrier calls for this\n** same object.)\n*/\nvoid luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  if (keepinvariant(g))  /* must keep invariant? */\n    reallymarkobject(g, v);  /* restore invariant */\n  else {  /* sweep phase */\n    lua_assert(issweepphase(g));\n    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */\n  }\n}\n\n\n/*\n** barrier that moves collector backward, that is, mark the black object\n** pointing to a white object as gray again.\n*/\nvoid luaC_barrierback_ (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  lua_assert(isblack(t) && !isdead(g, t));\n  black2gray(t);  /* make table gray (again) */\n  linkgclist(t, g->grayagain);\n}\n\n\n/*\n** barrier for assignments to closed upvalues. Because upvalues are\n** shared among closures, it is impossible to know the color of all\n** closures pointing to it. So, we assume that the object being assigned\n** must be marked.\n*/\nvoid luaC_upvalbarrier_ (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = gcvalue(uv->v);\n  lua_assert(!upisopen(uv));  /* ensured by macro luaC_upvalbarrier */\n  if (keepinvariant(g))\n    markobject(g, o);\n}\n\n\nvoid luaC_fix (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(g->allgc == o);  /* object must be 1st in 'allgc' list! */\n  white2gray(o);  /* they will be gray forever */\n  g->allgc = o->next;  /* remove object from 'allgc' list */\n  o->next = g->fixedgc;  /* link it to 'fixedgc' list */\n  g->fixedgc = o;\n}\n\n\n/*\n** create a new collectable object (with given type and size) and link\n** it to 'allgc' list.\n*/\nGCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {\n  global_State *g = G(L);\n  GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));\n  o->marked = luaC_white(g);\n  o->tt = tt;\n  o->next = g->allgc;\n  g->allgc = o;\n  return o;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Mark functions\n** =======================================================\n*/\n\n\n/*\n** mark an object. Userdata, strings, and closed upvalues are visited\n** and turned black here. Other objects are marked gray and added\n** to appropriate list to be visited (and turned black) later. (Open\n** upvalues are already linked in 'headuv' list.)\n*/\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n reentry:\n  white2gray(o);\n  switch (o->tt) {\n    case LUA_TSHRSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->shrlen);\n      break;\n    }\n    case LUA_TLNGSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      TValue uvalue;\n      markobjectN(g, gco2u(o)->metatable);  /* mark its metatable */\n      gray2black(o);\n      g->GCmemtrav += sizeudata(gco2u(o));\n      getuservalue(g->mainthread, gco2u(o), &uvalue);\n      if (valiswhite(&uvalue)) {  /* markvalue(g, &uvalue); */\n        o = gcvalue(&uvalue);\n        goto reentry;\n      }\n      break;\n    }\n    case LUA_TLCL: {\n      linkgclist(gco2lcl(o), g->gray);\n      break;\n    }\n    case LUA_TCCL: {\n      linkgclist(gco2ccl(o), g->gray);\n      break;\n    }\n    case LUA_TTABLE: {\n      linkgclist(gco2t(o), g->gray);\n      break;\n    }\n    case LUA_TTHREAD: {\n      linkgclist(gco2th(o), g->gray);\n      break;\n    }\n    case LUA_TPROTO: {\n      linkgclist(gco2p(o), g->gray);\n      break;\n    }\n    default: lua_assert(0); break;\n  }\n}\n\n\n/*\n** mark metamethods for basic types\n*/\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i < LUA_NUMTAGS; i++)\n    markobjectN(g, g->mt[i]);\n}\n\n\n/*\n** mark all objects in list of being-finalized\n*/\nstatic void markbeingfnz (global_State *g) {\n  GCObject *o;\n  for (o = g->tobefnz; o != NULL; o = o->next)\n    markobject(g, o);\n}\n\n\n/*\n** Mark all values stored in marked open upvalues from non-marked threads.\n** (Values from marked threads were already marked when traversing the\n** thread.) Remove from the list threads that no longer have upvalues and\n** not-marked threads.\n*/\nstatic void remarkupvals (global_State *g) {\n  lua_State *thread;\n  lua_State **p = &g->twups;\n  while ((thread = *p) != NULL) {\n    lua_assert(!isblack(thread));  /* threads are never black */\n    if (isgray(thread) && thread->openupval != NULL)\n      p = &thread->twups;  /* keep marked thread with upvalues in the list */\n    else {  /* thread is not marked or without upvalues */\n      UpVal *uv;\n      *p = thread->twups;  /* remove thread from the list */\n      thread->twups = thread;  /* mark that it is out of list */\n      for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) {\n        if (uv->u.open.touched) {\n          markvalue(g, uv->v);  /* remark upvalue's value */\n          uv->u.open.touched = 0;\n        }\n      }\n    }\n  }\n}\n\n\n/*\n** mark root set and reset all gray lists, to start a new collection\n*/\nstatic void restartcollection (global_State *g) {\n  g->gray = g->grayagain = NULL;\n  g->weak = g->allweak = g->ephemeron = NULL;\n  markobject(g, g->mainthread);\n  markvalue(g, &g->l_registry);\n  markmt(g);\n  markbeingfnz(g);  /* mark any finalizing object left from previous cycle */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Traverse functions\n** =======================================================\n*/\n\n/*\n** Traverse a table with weak values and link it to proper list. During\n** propagate phase, keep it in 'grayagain' list, to be revisited in the\n** atomic phase. In the atomic phase, if table has any white value,\n** put it in 'weak' list, to be cleared.\n*/\nstatic void traverseweakvalue (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  /* if there is array part, assume it may have white values (it is not\n     worth traversing it now just to check) */\n  int hasclears = (h->sizearray > 0);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      if (!hasclears && iscleared(g, gval(n)))  /* is there a white value? */\n        hasclears = 1;  /* table will have to be cleared */\n    }\n  }\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasclears)\n    linkgclist(h, g->weak);  /* has to be cleared later */\n}\n\n\n/*\n** Traverse an ephemeron table and link it to proper list. Returns true\n** iff any object was marked during this traversal (which implies that\n** convergence has to continue). During propagation phase, keep table\n** in 'grayagain' list, to be visited again in the atomic phase. In\n** the atomic phase, if table has any white->white entry, it has to\n** be revisited during ephemeron convergence (as that key may turn\n** black). Otherwise, if it has any white key, table has to be cleared\n** (in the atomic phase).\n*/\nstatic int traverseephemeron (global_State *g, Table *h) {\n  int marked = 0;  /* true if an object is marked in this traversal */\n  int hasclears = 0;  /* true if table has white keys */\n  int hasww = 0;  /* true if table has entry \"white-key -> white-value\" */\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  /* traverse array part */\n  for (i = 0; i < h->sizearray; i++) {\n    if (valiswhite(&h->array[i])) {\n      marked = 1;\n      reallymarkobject(g, gcvalue(&h->array[i]));\n    }\n  }\n  /* traverse hash part */\n  for (n = gnode(h, 0); n < limit; n++) {\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else if (iscleared(g, gkey(n))) {  /* key is not marked (yet)? */\n      hasclears = 1;  /* table must be cleared */\n      if (valiswhite(gval(n)))  /* value not marked yet? */\n        hasww = 1;  /* white-white entry */\n    }\n    else if (valiswhite(gval(n))) {  /* value not marked yet? */\n      marked = 1;\n      reallymarkobject(g, gcvalue(gval(n)));  /* mark it now */\n    }\n  }\n  /* link table into proper list */\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasww)  /* table has white->white entries? */\n    linkgclist(h, g->ephemeron);  /* have to propagate again */\n  else if (hasclears)  /* table has white keys? */\n    linkgclist(h, g->allweak);  /* may have to clean white keys */\n  return marked;\n}\n\n\nstatic void traversestrongtable (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  for (i = 0; i < h->sizearray; i++)  /* traverse array part */\n    markvalue(g, &h->array[i]);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      markvalue(g, gval(n));  /* mark value */\n    }\n  }\n}\n\n\nstatic lu_mem traversetable (global_State *g, Table *h) {\n  const char *weakkey, *weakvalue;\n  const TValue *mode = gfasttm(g, h->metatable, TM_MODE);\n  markobjectN(g, h->metatable);\n  if (mode && ttisstring(mode) &&  /* is there a weak mode? */\n      ((weakkey = strchr(svalue(mode), 'k')),\n       (weakvalue = strchr(svalue(mode), 'v')),\n       (weakkey || weakvalue))) {  /* is really weak? */\n    black2gray(h);  /* keep table gray */\n    if (!weakkey)  /* strong keys? */\n      traverseweakvalue(g, h);\n    else if (!weakvalue)  /* strong values? */\n      traverseephemeron(g, h);\n    else  /* all weak */\n      linkgclist(h, g->allweak);  /* nothing to traverse now */\n  }\n  else  /* not weak */\n    traversestrongtable(g, h);\n  return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                         sizeof(Node) * cast(size_t, allocsizenode(h));\n}\n\n\n/*\n** Traverse a prototype. (While a prototype is being build, its\n** arrays can be larger than needed; the extra slots are filled with\n** NULL, so the use of 'markobjectN')\n*/\nstatic int traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->cache && iswhite(f->cache))\n    f->cache = NULL;  /* allow cache to be collected */\n  markobjectN(g, f->source);\n  for (i = 0; i < f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */\n    markobjectN(g, f->upvalues[i].name);\n  for (i = 0; i < f->sizep; i++)  /* mark nested protos */\n    markobjectN(g, f->p[i]);\n  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */\n    markobjectN(g, f->locvars[i].varname);\n  return sizeof(Proto) + sizeof(Instruction) * f->sizecode +\n                         sizeof(Proto *) * f->sizep +\n                         sizeof(TValue) * f->sizek +\n                         sizeof(int) * f->sizelineinfo +\n                         sizeof(LocVar) * f->sizelocvars +\n                         sizeof(Upvaldesc) * f->sizeupvalues;\n}\n\n\nstatic lu_mem traverseCclosure (global_State *g, CClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++)  /* mark its upvalues */\n    markvalue(g, &cl->upvalue[i]);\n  return sizeCclosure(cl->nupvalues);\n}\n\n/*\n** open upvalues point to values in a thread, so those values should\n** be marked when the thread is traversed except in the atomic phase\n** (because then the value cannot be changed by the thread and the\n** thread may not be traversed again)\n*/\nstatic lu_mem traverseLclosure (global_State *g, LClosure *cl) {\n  int i;\n  markobjectN(g, cl->p);  /* mark its prototype */\n  for (i = 0; i < cl->nupvalues; i++) {  /* mark its upvalues */\n    UpVal *uv = cl->upvals[i];\n    if (uv != NULL) {\n      if (upisopen(uv) && g->gcstate != GCSinsideatomic)\n        uv->u.open.touched = 1;  /* can be marked in 'remarkupvals' */\n      else\n        markvalue(g, uv->v);\n    }\n  }\n  return sizeLclosure(cl->nupvalues);\n}\n\n\nstatic lu_mem traversethread (global_State *g, lua_State *th) {\n  StkId o = th->stack;\n  if (o == NULL)\n    return 1;  /* stack not completely built yet */\n  lua_assert(g->gcstate == GCSinsideatomic ||\n             th->openupval == NULL || isintwups(th));\n  for (; o < th->top; o++)  /* mark live elements in the stack */\n    markvalue(g, o);\n  if (g->gcstate == GCSinsideatomic) {  /* final traversal? */\n    StkId lim = th->stack + th->stacksize;  /* real end of stack */\n    for (; o < lim; o++)  /* clear not-marked stack slice */\n      setnilvalue(o);\n    /* 'remarkupvals' may have removed thread from 'twups' list */\n    if (!isintwups(th) && th->openupval != NULL) {\n      th->twups = g->twups;  /* link it back to the list */\n      g->twups = th;\n    }\n  }\n  else if (g->gckind != KGC_EMERGENCY)\n    luaD_shrinkstack(th); /* do not change stack in emergency cycle */\n  return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n          sizeof(CallInfo) * th->nci);\n}\n\n\n/*\n** traverse one gray object, turning it to black (except for threads,\n** which are always gray).\n*/\nstatic void propagatemark (global_State *g) {\n  lu_mem size;\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2t(o);\n      g->gray = h->gclist;  /* remove from 'gray' list */\n      size = traversetable(g, h);\n      break;\n    }\n    case LUA_TLCL: {\n      LClosure *cl = gco2lcl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseLclosure(g, cl);\n      break;\n    }\n    case LUA_TCCL: {\n      CClosure *cl = gco2ccl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseCclosure(g, cl);\n      break;\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;  /* remove from 'gray' list */\n      linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n      black2gray(o);\n      size = traversethread(g, th);\n      break;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;  /* remove from 'gray' list */\n      size = traverseproto(g, p);\n      break;\n    }\n    default: lua_assert(0); return;\n  }\n  g->GCmemtrav += size;\n}\n\n\nstatic void propagateall (global_State *g) {\n  while (g->gray) propagatemark(g);\n}\n\n\nstatic void convergeephemerons (global_State *g) {\n  int changed;\n  do {\n    GCObject *w;\n    GCObject *next = g->ephemeron;  /* get ephemeron list */\n    g->ephemeron = NULL;  /* tables may return to this list when traversed */\n    changed = 0;\n    while ((w = next) != NULL) {\n      next = gco2t(w)->gclist;\n      if (traverseephemeron(g, gco2t(w))) {  /* traverse marked some value? */\n        propagateall(g);  /* propagate changes */\n        changed = 1;  /* will have to revisit all ephemeron tables */\n      }\n    }\n  } while (changed);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Sweep Functions\n** =======================================================\n*/\n\n\n/*\n** clear entries with unmarked keys from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearkeys (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\n/*\n** clear entries with unmarked values from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearvalues (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    unsigned int i;\n    for (i = 0; i < h->sizearray; i++) {\n      TValue *o = &h->array[i];\n      if (iscleared(g, o))  /* value was collected? */\n        setnilvalue(o);  /* remove value */\n    }\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\nvoid luaC_upvdeccount (lua_State *L, UpVal *uv) {\n  lua_assert(uv->refcount > 0);\n  uv->refcount--;\n  if (uv->refcount == 0 && !upisopen(uv))\n    luaM_free(L, uv);\n}\n\n\nstatic void freeLclosure (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = cl->upvals[i];\n    if (uv)\n      luaC_upvdeccount(L, uv);\n  }\n  luaM_freemem(L, cl, sizeLclosure(cl->nupvalues));\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TLCL: {\n      freeLclosure(L, gco2lcl(o));\n      break;\n    }\n    case LUA_TCCL: {\n      luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));\n      break;\n    }\n    case LUA_TTABLE: luaH_free(L, gco2t(o)); break;\n    case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;\n    case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;\n    case LUA_TSHRSTR:\n      luaS_remove(L, gco2ts(o));  /* remove it from hash table */\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));\n      break;\n    case LUA_TLNGSTR: {\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);\n\n\n/*\n** sweep at most 'count' elements from a list of GCObjects erasing dead\n** objects, where a dead object is one marked with the old (non current)\n** white; change all non-dead objects back to white, preparing for next\n** collection cycle. Return where to continue the traversal or NULL if\n** list is finished.\n*/\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  global_State *g = G(L);\n  int ow = otherwhite(g);\n  int white = luaC_white(g);  /* current white */\n  while (*p != NULL && count-- > 0) {\n    GCObject *curr = *p;\n    int marked = curr->marked;\n    if (isdeadm(ow, marked)) {  /* is 'curr' dead? */\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* change mark to 'white' */\n      curr->marked = cast_byte((marked & maskcolors) | white);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  return (*p == NULL) ? NULL : p;\n}\n\n\n/*\n** sweep a list until a live object (or end of list)\n*/\nstatic GCObject **sweeptolive (lua_State *L, GCObject **p) {\n  GCObject **old = p;\n  do {\n    p = sweeplist(L, p, 1);\n  } while (p == old);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Finalization\n** =======================================================\n*/\n\n/*\n** If possible, shrink string table\n*/\nstatic void checkSizes (lua_State *L, global_State *g) {\n  if (g->gckind != KGC_EMERGENCY) {\n    l_mem olddebt = g->GCdebt;\n    if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */\n      luaS_resize(L, g->strt.size / 2);  /* shrink it a little */\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n  }\n}\n\n\nstatic GCObject *udata2finalize (global_State *g) {\n  GCObject *o = g->tobefnz;  /* get first element */\n  lua_assert(tofinalize(o));\n  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */\n  o->next = g->allgc;  /* return it to 'allgc' list */\n  g->allgc = o;\n  resetbit(o->marked, FINALIZEDBIT);  /* object is \"normal\" again */\n  if (issweepphase(g))\n    makewhite(g, o);  /* \"sweep\" object */\n  return o;\n}\n\n\nstatic void dothecall (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 2, 0);\n}\n\n\nstatic void GCTM (lua_State *L, int propagateerrors) {\n  global_State *g = G(L);\n  const TValue *tm;\n  TValue v;\n  setgcovalue(L, &v, udata2finalize(g));\n  tm = luaT_gettmbyobj(L, &v, TM_GC);\n  if (tm != NULL && ttisfunction(tm)) {  /* is there a finalizer? */\n    int status;\n    lu_byte oldah = L->allowhook;\n    int running  = g->gcrunning;\n    L->allowhook = 0;  /* stop debug hooks during GC metamethod */\n    g->gcrunning = 0;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);  /* push finalizer... */\n    setobj2s(L, L->top + 1, &v);  /* ... and its argument */\n    L->top += 2;  /* and (next line) call the finalizer */\n    L->ci->callstatus |= CIST_FIN;  /* will run a finalizer */\n    status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);\n    L->ci->callstatus &= ~CIST_FIN;  /* not running a finalizer anymore */\n    L->allowhook = oldah;  /* restore hooks */\n    g->gcrunning = running;  /* restore state */\n    if (status != LUA_OK && propagateerrors) {  /* error while running __gc? */\n      if (status == LUA_ERRRUN) {  /* is there an error object? */\n        const char *msg = (ttisstring(L->top - 1))\n                            ? svalue(L->top - 1)\n                            : \"no message\";\n        luaO_pushfstring(L, \"error in __gc metamethod (%s)\", msg);\n        status = LUA_ERRGCMM;  /* error in __gc metamethod */\n      }\n      luaD_throw(L, status);  /* re-throw error */\n    }\n  }\n}\n\n\n/*\n** call a few (up to 'g->gcfinnum') finalizers\n*/\nstatic int runafewfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  unsigned int i;\n  lua_assert(!g->tobefnz || g->gcfinnum > 0);\n  for (i = 0; g->tobefnz && i < g->gcfinnum; i++)\n    GCTM(L, 1);  /* call one finalizer */\n  g->gcfinnum = (!g->tobefnz) ? 0  /* nothing more to finalize? */\n                    : g->gcfinnum * 2;  /* else call a few more next time */\n  return i;\n}\n\n\n/*\n** call all pending finalizers\n*/\nstatic void callallpendingfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  while (g->tobefnz)\n    GCTM(L, 0);\n}\n\n\n/*\n** find last 'next' field in list 'p' list (to add elements in its end)\n*/\nstatic GCObject **findlast (GCObject **p) {\n  while (*p != NULL)\n    p = &(*p)->next;\n  return p;\n}\n\n\n/*\n** move all unreachable objects (or 'all' objects) that need\n** finalization from list 'finobj' to list 'tobefnz' (to be finalized)\n*/\nstatic void separatetobefnz (global_State *g, int all) {\n  GCObject *curr;\n  GCObject **p = &g->finobj;\n  GCObject **lastnext = findlast(&g->tobefnz);\n  while ((curr = *p) != NULL) {  /* traverse all finalizable objects */\n    lua_assert(tofinalize(curr));\n    if (!(iswhite(curr) || all))  /* not being collected? */\n      p = &curr->next;  /* don't bother with it */\n    else {\n      *p = curr->next;  /* remove 'curr' from 'finobj' list */\n      curr->next = *lastnext;  /* link at the end of 'tobefnz' list */\n      *lastnext = curr;\n      lastnext = &curr->next;\n    }\n  }\n}\n\n\n/*\n** if object 'o' has a finalizer, remove it from 'allgc' list (must\n** search the list to find it) and link it in 'finobj' list.\n*/\nvoid luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {\n  global_State *g = G(L);\n  if (tofinalize(o) ||                 /* obj. is already marked... */\n      gfasttm(g, mt, TM_GC) == NULL)   /* or has no finalizer? */\n    return;  /* nothing to be done */\n  else {  /* move 'o' to 'finobj' list */\n    GCObject **p;\n    if (issweepphase(g)) {\n      makewhite(g, o);  /* \"sweep\" object 'o' */\n      if (g->sweepgc == &o->next)  /* should not remove 'sweepgc' object */\n        g->sweepgc = sweeptolive(L, g->sweepgc);  /* change 'sweepgc' */\n    }\n    /* search for pointer pointing to 'o' */\n    for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }\n    *p = o->next;  /* remove 'o' from 'allgc' list */\n    o->next = g->finobj;  /* link it in 'finobj' list */\n    g->finobj = o;\n    l_setbit(o->marked, FINALIZEDBIT);  /* mark it as such */\n  }\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** GC control\n** =======================================================\n*/\n\n\n/*\n** Set a reasonable \"time\" to wait before starting a new GC cycle; cycle\n** will start when memory use hits threshold. (Division by 'estimate'\n** should be OK: it cannot be zero (because Lua cannot even start with\n** less than PAUSEADJ bytes).\n*/\nstatic void setpause (global_State *g) {\n  l_mem threshold, debt;\n  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */\n  lua_assert(estimate > 0);\n  threshold = (g->gcpause < MAX_LMEM / estimate)  /* overflow? */\n            ? estimate * g->gcpause  /* no overflow */\n            : MAX_LMEM;  /* overflow; truncate to maximum */\n  debt = gettotalbytes(g) - threshold;\n  luaE_setdebt(g, debt);\n}\n\n\n/*\n** Enter first sweep phase.\n** The call to 'sweeplist' tries to make pointer point to an object\n** inside the list (instead of to the header), so that the real sweep do\n** not need to skip objects created between \"now\" and the start of the\n** real sweep.\n*/\nstatic void entersweep (lua_State *L) {\n  global_State *g = G(L);\n  g->gcstate = GCSswpallgc;\n  lua_assert(g->sweepgc == NULL);\n  g->sweepgc = sweeplist(L, &g->allgc, 1);\n}\n\n\nvoid luaC_freeallobjects (lua_State *L) {\n  global_State *g = G(L);\n  separatetobefnz(g, 1);  /* separate all objects with finalizers */\n  lua_assert(g->finobj == NULL);\n  callallpendingfinalizers(L);\n  lua_assert(g->tobefnz == NULL);\n  g->currentwhite = WHITEBITS; /* this \"white\" makes all objects look dead */\n  g->gckind = KGC_NORMAL;\n  sweepwholelist(L, &g->finobj);\n  sweepwholelist(L, &g->allgc);\n  sweepwholelist(L, &g->fixedgc);  /* collect fixed objects */\n  lua_assert(g->strt.nuse == 0);\n}\n\n\nstatic l_mem atomic (lua_State *L) {\n  global_State *g = G(L);\n  l_mem work;\n  GCObject *origweak, *origall;\n  GCObject *grayagain = g->grayagain;  /* save original list */\n  lua_assert(g->ephemeron == NULL && g->weak == NULL);\n  lua_assert(!iswhite(g->mainthread));\n  g->gcstate = GCSinsideatomic;\n  g->GCmemtrav = 0;  /* start counting work */\n  markobject(g, L);  /* mark running thread */\n  /* registry and global metatables may be changed by API */\n  markvalue(g, &g->l_registry);\n  markmt(g);  /* mark global metatables */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  propagateall(g);  /* propagate changes */\n  work = g->GCmemtrav;  /* stop counting (do not recount 'grayagain') */\n  g->gray = grayagain;\n  propagateall(g);  /* traverse 'grayagain' list */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all strongly accessible objects are marked. */\n  /* Clear values from weak tables, before checking finalizers */\n  clearvalues(g, g->weak, NULL);\n  clearvalues(g, g->allweak, NULL);\n  origweak = g->weak; origall = g->allweak;\n  work += g->GCmemtrav;  /* stop counting (objects being finalized) */\n  separatetobefnz(g, 0);  /* separate objects to be finalized */\n  g->gcfinnum = 1;  /* there may be objects to be finalized */\n  markbeingfnz(g);  /* mark objects that will be finalized */\n  propagateall(g);  /* remark, to propagate 'resurrection' */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all resurrected objects are marked. */\n  /* remove dead objects from weak tables */\n  clearkeys(g, g->ephemeron, NULL);  /* clear keys from all ephemeron tables */\n  clearkeys(g, g->allweak, NULL);  /* clear keys from all 'allweak' tables */\n  /* clear values from resurrected weak tables */\n  clearvalues(g, g->weak, origweak);\n  clearvalues(g, g->allweak, origall);\n  luaS_clearcache(g);\n  g->currentwhite = cast_byte(otherwhite(g));  /* flip current white */\n  work += g->GCmemtrav;  /* complete counting */\n  return work;  /* estimate of memory marked by 'atomic' */\n}\n\n\nstatic lu_mem sweepstep (lua_State *L, global_State *g,\n                         int nextstate, GCObject **nextlist) {\n  if (g->sweepgc) {\n    l_mem olddebt = g->GCdebt;\n    g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n    if (g->sweepgc)  /* is there still something to sweep? */\n      return (GCSWEEPMAX * GCSWEEPCOST);\n  }\n  /* else enter next state */\n  g->gcstate = nextstate;\n  g->sweepgc = nextlist;\n  return 0;\n}\n\n\nstatic lu_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  switch (g->gcstate) {\n    case GCSpause: {\n      g->GCmemtrav = g->strt.size * sizeof(GCObject*);\n      restartcollection(g);\n      g->gcstate = GCSpropagate;\n      return g->GCmemtrav;\n    }\n    case GCSpropagate: {\n      g->GCmemtrav = 0;\n      lua_assert(g->gray);\n      propagatemark(g);\n       if (g->gray == NULL)  /* no more gray objects? */\n        g->gcstate = GCSatomic;  /* finish propagate phase */\n      return g->GCmemtrav;  /* memory traversed in this step */\n    }\n    case GCSatomic: {\n      lu_mem work;\n      propagateall(g);  /* make sure gray list is empty */\n      work = atomic(L);  /* work is what was traversed by 'atomic' */\n      entersweep(L);\n      g->GCestimate = gettotalbytes(g);  /* first estimate */;\n      return work;\n    }\n    case GCSswpallgc: {  /* sweep \"regular\" objects */\n      return sweepstep(L, g, GCSswpfinobj, &g->finobj);\n    }\n    case GCSswpfinobj: {  /* sweep objects with finalizers */\n      return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);\n    }\n    case GCSswptobefnz: {  /* sweep objects to be finalized */\n      return sweepstep(L, g, GCSswpend, NULL);\n    }\n    case GCSswpend: {  /* finish sweeps */\n      makewhite(g, g->mainthread);  /* sweep main thread */\n      checkSizes(L, g);\n      g->gcstate = GCScallfin;\n      return 0;\n    }\n    case GCScallfin: {  /* call remaining finalizers */\n      if (g->tobefnz && g->gckind != KGC_EMERGENCY) {\n        int n = runafewfinalizers(L);\n        return (n * GCFINALIZECOST);\n      }\n      else {  /* emergency mode or no more finalizers */\n        g->gcstate = GCSpause;  /* finish collection */\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** advances the garbage collector until it reaches a state allowed\n** by 'statemask'\n*/\nvoid luaC_runtilstate (lua_State *L, int statesmask) {\n  global_State *g = G(L);\n  while (!testbit(statesmask, g->gcstate))\n    singlestep(L);\n}\n\n\n/*\n** get GC debt and convert it from Kb to 'work units' (avoid zero debt\n** and overflows)\n*/\nstatic l_mem getdebt (global_State *g) {\n  l_mem debt = g->GCdebt;\n  int stepmul = g->gcstepmul;\n  if (debt <= 0) return 0;  /* minimal debt */\n  else {\n    debt = (debt / STEPMULADJ) + 1;\n    debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;\n    return debt;\n  }\n}\n\n/*\n** performs a basic GC step when collector is running\n*/\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  l_mem debt = getdebt(g);  /* GC deficit (be paid now) */\n  if (!g->gcrunning) {  /* not running? */\n    luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */\n    return;\n  }\n  do {  /* repeat until pause or enough \"credit\" (negative debt) */\n    lu_mem work = singlestep(L);  /* perform one single step */\n    debt -= work;\n  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);\n  if (g->gcstate == GCSpause)\n    setpause(g);  /* pause until next cycle */\n  else {\n    debt = (debt / g->gcstepmul) * STEPMULADJ;  /* convert 'work units' to Kb */\n    luaE_setdebt(g, debt);\n    runafewfinalizers(L);\n  }\n}\n\n\n/*\n** Performs a full GC cycle; if 'isemergency', set a flag to avoid\n** some operations which could change the interpreter state in some\n** unexpected ways (running finalizers and shrinking some structures).\n** Before running the collection, check 'keepinvariant'; if it is true,\n** there may be some objects marked as black, so the collector has\n** to sweep all objects to turn them back to white (as white has not\n** changed, nothing will be collected).\n*/\nvoid luaC_fullgc (lua_State *L, int isemergency) {\n  global_State *g = G(L);\n  lua_assert(g->gckind == KGC_NORMAL);\n  if (isemergency) g->gckind = KGC_EMERGENCY;  /* set flag */\n  if (keepinvariant(g)) {  /* black objects? */\n    entersweep(L); /* sweep everything to turn them back to white */\n  }\n  /* finish any pending sweep phase to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpause));\n  luaC_runtilstate(L, ~bitmask(GCSpause));  /* start new collection */\n  luaC_runtilstate(L, bitmask(GCScallfin));  /* run up to finalizers */\n  /* estimate must be correct after a full GC cycle */\n  lua_assert(g->GCestimate == gettotalbytes(g));\n  luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n  g->gckind = KGC_NORMAL;\n  setpause(g);\n}\n\n/* }====================================================== */\n\n\n"
  },
  {
    "path": "WebGLPlugins/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n/*\n** Collectable objects may have one of three colors: white, which\n** means the object is not marked; gray, which means the\n** object is marked, but its references may be not marked; and\n** black, which means that the object and all its references are marked.\n** The main invariant of the garbage collector, while marking objects,\n** is that a black object can never point to a white one. Moreover,\n** any gray object must be in a \"gray list\" (gray, grayagain, weak,\n** allweak, ephemeron) so that it can be visited again before finishing\n** the collection cycle. These lists have no meaning when the invariant\n** is not being enforced (e.g., sweep phase).\n*/\n\n\n\n/* how much to allocate before next GC step */\n#if !defined(GCSTEPSIZE)\n/* ~100 small strings */\n#define GCSTEPSIZE\t(cast_int(100 * sizeof(TString)))\n#endif\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpropagate\t0\n#define GCSatomic\t1\n#define GCSswpallgc\t2\n#define GCSswpfinobj\t3\n#define GCSswptobefnz\t4\n#define GCSswpend\t5\n#define GCScallfin\t6\n#define GCSpause\t7\n\n\n#define issweepphase(g)  \\\n\t(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)\n\n\n/*\n** macro to tell when main invariant (white objects cannot point to black\n** ones) must be kept. During a collection, the sweep\n** phase may break the invariant, as objects turned white may point to\n** still-black objects. The invariant is restored when sweep ends and\n** all objects are white again.\n*/\n\n#define keepinvariant(g)\t((g)->gcstate <= GCSatomic)\n\n\n/*\n** some useful bit tricks\n*/\n#define resetbits(x,m)\t\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t\t((x) |= (m))\n#define testbits(x,m)\t\t((x) & (m))\n#define bitmask(b)\t\t(1<<(b))\n#define bit2mask(b1,b2)\t\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\t\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\t\tresetbits(x, bitmask(b))\n#define testbit(x,b)\t\ttestbits(x, bitmask(b))\n\n\n/* Layout for bit use in 'marked' field: */\n#define WHITE0BIT\t0  /* object is white (type 0) */\n#define WHITE1BIT\t1  /* object is white (type 1) */\n#define BLACKBIT\t2  /* object is black */\n#define FINALIZEDBIT\t3  /* object has been marked for finalization */\n/* bit 7 is currently used by tests (luaL_checkmemory) */\n\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      testbits((x)->marked, WHITEBITS)\n#define isblack(x)      testbit((x)->marked, BLACKBIT)\n#define isgray(x)  /* neither white nor black */  \\\n\t(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))\n\n#define tofinalize(x)\ttestbit((x)->marked, FINALIZEDBIT)\n\n#define otherwhite(g)\t((g)->currentwhite ^ WHITEBITS)\n#define isdeadm(ow,m)\t(!(((m) ^ WHITEBITS) & (ow)))\n#define isdead(g,v)\tisdeadm(otherwhite(g), (v)->marked)\n\n#define changewhite(x)\t((x)->marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->marked, BLACKBIT)\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n\n/*\n** Does one step of collection when debt becomes positive. 'pre'/'pos'\n** allows some adjustments to be done only when needed. macro\n** 'condchangemem' is used only for heavy tests (forcing a full\n** GC cycle on every opportunity)\n*/\n#define luaC_condGC(L,pre,pos) \\\n\t{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \\\n\t  condchangemem(L,pre,pos); }\n\n/* more often than not, 'pre'/'pos' are empty */\n#define luaC_checkGC(L)\t\tluaC_condGC(L,(void)0,(void)0)\n\n\n#define luaC_barrier(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \\\n\tluaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))\n\n#define luaC_barrierback(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \\\n\tluaC_barrierback_(L,p) : cast_void(0))\n\n#define luaC_objbarrier(L,p,o) (  \\\n\t(isblack(p) && iswhite(o)) ? \\\n\tluaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))\n\n#define luaC_upvalbarrier(L,uv) ( \\\n\t(iscollectable((uv)->v) && !upisopen(uv)) ? \\\n         luaC_upvalbarrier_(L,uv) : cast_void(0))\n\nLUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_freeallobjects (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);\nLUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);\nLUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);\nLUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o);\nLUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);\nLUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $\n** Initialization of libraries for lua.c and other clients\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n/*\n** If you embed Lua in your program and need to open the standard\n** libraries, call luaL_openlibs in your program. If you need a\n** different set of libraries, copy this file to your project and edit\n** it to suit your needs.\n**\n** You can also *preload* libraries, so that a later 'require' can\n** open the library, which is already linked to the application.\n** For that, do the following code:\n**\n**  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n**  lua_pushcfunction(L, luaopen_modname);\n**  lua_setfield(L, -2, modname);\n**  lua_pop(L, 1);  // remove PRELOAD table\n*/\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\n/*\n** these libs are loaded by lua.c and are readily available to any Lua\n** program\n*/\nstatic const luaL_Reg loadedlibs[] = {\n  {\"_G\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_COLIBNAME, luaopen_coroutine},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_UTF8LIBNAME, luaopen_utf8},\n  {LUA_DBLIBNAME, luaopen_debug},\n#if defined(LUA_COMPAT_BITLIB)\n  {LUA_BITLIBNAME, luaopen_bit32},\n#endif\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib;\n  /* \"require\" functions from 'loadedlibs' and set results to global table */\n  for (lib = loadedlibs; lib->func; lib++) {\n    luaL_requiref(L, lib->name, lib->func, 1);\n    lua_pop(L, 1);  /* remove lib */\n  }\n}\n\n"
  },
  {
    "path": "WebGLPlugins/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <locale.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** Change this macro to accept other modes for 'fopen' besides\n** the standard ones.\n*/\n#if !defined(l_checkmode)\n\n/* accepted extensions to 'mode' in 'fopen' */\n#if !defined(L_MODEEXT)\n#define L_MODEEXT\t\"b\"\n#endif\n\n/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */\nstatic int l_checkmode (const char *mode) {\n  return (*mode != '\\0' && strchr(\"rwa\", *(mode++)) != NULL &&\n         (*mode != '+' || (++mode, 1)) &&  /* skip if char is '+' */\n         (strspn(mode, L_MODEEXT) == strlen(mode)));  /* check extensions */\n}\n\n#endif\n\n/*\n** {======================================================\n** l_popen spawns a new process connected to the current\n** one through the file streams.\n** =======================================================\n*/\n\n#if !defined(l_popen)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_popen(L,c,m)\t\t(fflush(NULL), popen(c,m))\n#define l_pclose(L,file)\t(pclose(file))\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#define l_popen(L,c,m)\t\t(_popen(c,m))\n#define l_pclose(L,file)\t(_pclose(file))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_popen(L,c,m)  \\\n\t  ((void)((void)c, m), \\\n\t  luaL_error(L, \"'popen' not supported\"), \\\n\t  (FILE*)0)\n#define l_pclose(L,file)\t\t((void)L, (void)file, -1)\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#if !defined(l_getc)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\n#define l_getc(f)\t\tgetc_unlocked(f)\n#define l_lockfile(f)\t\tflockfile(f)\n#define l_unlockfile(f)\t\tfunlockfile(f)\n#else\n#define l_getc(f)\t\tgetc(f)\n#define l_lockfile(f)\t\t((void)0)\n#define l_unlockfile(f)\t\t((void)0)\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** {======================================================\n** l_fseek: configuration for longer offsets\n** =======================================================\n*/\n\n#if !defined(l_fseek)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <sys/types.h>\n\n#define l_fseek(f,o,w)\t\tfseeko(f,o,w)\n#define l_ftell(f)\t\tftello(f)\n#define l_seeknum\t\toff_t\n\n#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \\\n   && defined(_MSC_VER) && (_MSC_VER >= 1400)\t/* }{ */\n\n/* Windows (but not DDK) and Visual C++ 2005 or higher */\n#define l_fseek(f,o,w)\t\t_fseeki64(f,o,w)\n#define l_ftell(f)\t\t_ftelli64(f)\n#define l_seeknum\t\t__int64\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_fseek(f,o,w)\t\tfseek(f,o,w)\n#define l_ftell(f)\t\tftell(f)\n#define l_seeknum\t\tlong\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#define IO_PREFIX\t\"_IO_\"\n#define IOPREF_LEN\t(sizeof(IO_PREFIX)/sizeof(char) - 1)\n#define IO_INPUT\t(IO_PREFIX \"input\")\n#define IO_OUTPUT\t(IO_PREFIX \"output\")\n\n\ntypedef luaL_Stream LStream;\n\n\n#define tolstream(L)\t((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n#define isclosed(p)\t((p)->closef == NULL)\n\n\nstatic int io_type (lua_State *L) {\n  LStream *p;\n  luaL_checkany(L, 1);\n  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);\n  if (p == NULL)\n    lua_pushnil(L);  /* not a file */\n  else if (isclosed(p))\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic int f_tostring (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", p->f);\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    luaL_error(L, \"attempt to use a closed file\");\n  lua_assert(p->f);\n  return p->f;\n}\n\n\n/*\n** When creating file handles, always creates a 'closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** handle is in a consistent state.\n*/\nstatic LStream *newprefile (lua_State *L) {\n  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));\n  p->closef = NULL;  /* mark file handle as 'closed' */\n  luaL_setmetatable(L, LUA_FILEHANDLE);\n  return p;\n}\n\n\n/*\n** Calls the 'close' function from a file handle. The 'volatile' avoids\n** a bug in some versions of the Clang compiler (e.g., clang 3.0 for\n** 32 bits).\n*/\nstatic int aux_close (lua_State *L) {\n  LStream *p = tolstream(L);\n  volatile lua_CFunction cf = p->closef;\n  p->closef = NULL;  /* mark stream as closed */\n  return (*cf)(L);  /* close it */\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))  /* no argument? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */\n  tofile(L);  /* make sure argument is an open stream */\n  return aux_close(L);\n}\n\n\nstatic int f_gc (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (!isclosed(p) && p->f != NULL)\n    aux_close(L);  /* ignore closed and incompletely open files */\n  return 0;\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  int res = fclose(p->f);\n  return luaL_fileresult(L, (res == 0), NULL);\n}\n\n\nstatic LStream *newfile (lua_State *L) {\n  LStream *p = newprefile(L);\n  p->f = NULL;\n  p->closef = &io_fclose;\n  return p;\n}\n\n\nstatic void opencheck (lua_State *L, const char *fname, const char *mode) {\n  LStream *p = newfile(L);\n  p->f = fopen(fname, mode);\n  if (p->f == NULL)\n    luaL_error(L, \"cannot open file '%s' (%s)\", fname, strerror(errno));\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newfile(L);\n  const char *md = mode;  /* to traverse/check mode */\n  luaL_argcheck(L, l_checkmode(md), 2, \"invalid mode\");\n  p->f = fopen(filename, mode);\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  LStream *p = tolstream(L);\n  return luaL_execresult(L, l_pclose(L, p->f));\n#endif\n}\n\n\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newprefile(L);\n  p->f = l_popen(L, filename, mode);\n  p->closef = &io_pclose;\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  LStream *p = newfile(L);\n  p->f = tmpfile();\n  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, const char *findex) {\n  LStream *p;\n  lua_getfield(L, LUA_REGISTRYINDEX, findex);\n  p = (LStream *)lua_touserdata(L, -1);\n  if (isclosed(p))\n    luaL_error(L, \"standard %s file is closed\", findex + IOPREF_LEN);\n  return p->f;\n}\n\n\nstatic int g_iofile (lua_State *L, const char *f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename)\n      opencheck(L, filename, mode);\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_setfield(L, LUA_REGISTRYINDEX, f);\n  }\n  /* return current value */\n  lua_getfield(L, LUA_REGISTRYINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\n/*\n** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit\n** in the limit for upvalues of a closure)\n*/\n#define MAXARGLINE\t250\n\nstatic void aux_lines (lua_State *L, int toclose) {\n  int n = lua_gettop(L) - 1;  /* number of arguments to read */\n  luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, \"too many arguments\");\n  lua_pushinteger(L, n);  /* number of arguments to read */\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_rotate(L, 2, 2);  /* move 'n' and 'toclose' to their positions */\n  lua_pushcclosure(L, io_readline, 3 + n);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  int toclose;\n  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */\n  if (lua_isnil(L, 1)) {  /* no file name? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */\n    lua_replace(L, 1);  /* put it at index 1 */\n    tofile(L);  /* check that it's a valid file handle */\n    toclose = 0;  /* do not close it after iteration */\n  }\n  else {  /* open a new file */\n    const char *filename = luaL_checkstring(L, 1);\n    opencheck(L, filename, \"r\");\n    lua_replace(L, 1);  /* put file at index 1 */\n    toclose = 1;  /* close it after iteration */\n  }\n  aux_lines(L, toclose);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM     200\n#endif\n\n\n/* auxiliary structure used by 'read_number' */\ntypedef struct {\n  FILE *f;  /* file being read */\n  int c;  /* current character (look ahead) */\n  int n;  /* number of elements in buffer 'buff' */\n  char buff[L_MAXLENNUM + 1];  /* +1 for ending '\\0' */\n} RN;\n\n\n/*\n** Add current char to buffer (if not out of space) and read next one\n*/\nstatic int nextc (RN *rn) {\n  if (rn->n >= L_MAXLENNUM) {  /* buffer overflow? */\n    rn->buff[0] = '\\0';  /* invalidate result */\n    return 0;  /* fail */\n  }\n  else {\n    rn->buff[rn->n++] = rn->c;  /* save current char */\n    rn->c = l_getc(rn->f);  /* read next one */\n    return 1;\n  }\n}\n\n\n/*\n** Accept current char if it is in 'set' (of size 2)\n*/\nstatic int test2 (RN *rn, const char *set) {\n  if (rn->c == set[0] || rn->c == set[1])\n    return nextc(rn);\n  else return 0;\n}\n\n\n/*\n** Read a sequence of (hex)digits\n*/\nstatic int readdigits (RN *rn, int hex) {\n  int count = 0;\n  while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn))\n    count++;\n  return count;\n}\n\n\n/*\n** Read a number: first reads a valid prefix of a numeral into a buffer.\n** Then it calls 'lua_stringtonumber' to check whether the format is\n** correct and to convert it to a Lua number\n*/\nstatic int read_number (lua_State *L, FILE *f) {\n  RN rn;\n  int count = 0;\n  int hex = 0;\n  char decp[2];\n  rn.f = f; rn.n = 0;\n  decp[0] = lua_getlocaledecpoint();  /* get decimal point from locale */\n  decp[1] = '.';  /* always accept a dot */\n  l_lockfile(rn.f);\n  do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */\n  test2(&rn, \"-+\");  /* optional signal */\n  if (test2(&rn, \"00\")) {\n    if (test2(&rn, \"xX\")) hex = 1;  /* numeral is hexadecimal */\n    else count = 1;  /* count initial '0' as a valid digit */\n  }\n  count += readdigits(&rn, hex);  /* integral part */\n  if (test2(&rn, decp))  /* decimal point? */\n    count += readdigits(&rn, hex);  /* fractional part */\n  if (count > 0 && test2(&rn, (hex ? \"pP\" : \"eE\"))) {  /* exponent mark? */\n    test2(&rn, \"-+\");  /* exponent signal */\n    readdigits(&rn, 0);  /* exponent digits */\n  }\n  ungetc(rn.c, rn.f);  /* unread look-ahead char */\n  l_unlockfile(rn.f);\n  rn.buff[rn.n] = '\\0';  /* finish string */\n  if (lua_stringtonumber(L, rn.buff))  /* is this a valid number? */\n    return 1;  /* ok */\n  else {  /* invalid format */\n   lua_pushnil(L);  /* \"result\" to be removed */\n   return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);  /* no-op when c == EOF */\n  lua_pushliteral(L, \"\");\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f, int chop) {\n  luaL_Buffer b;\n  int c = '\\0';\n  luaL_buffinit(L, &b);\n  while (c != EOF && c != '\\n') {  /* repeat until end of line */\n    char *buff = luaL_prepbuffer(&b);  /* preallocate buffer */\n    int i = 0;\n    l_lockfile(f);  /* no memory errors can happen inside the lock */\n    while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')\n      buff[i++] = c;\n    l_unlockfile(f);\n    luaL_addsize(&b, i);\n  }\n  if (!chop && c == '\\n')  /* want a newline and have one? */\n    luaL_addchar(&b, c);  /* add ending newline to result */\n  luaL_pushresult(&b);  /* close buffer */\n  /* return ok if read something (either a newline or something else) */\n  return (c == '\\n' || lua_rawlen(L, -1) > 0);\n}\n\n\nstatic void read_all (lua_State *L, FILE *f) {\n  size_t nr;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */\n    char *p = luaL_prepbuffer(&b);\n    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);\n    luaL_addsize(&b, nr);\n  } while (nr == LUAL_BUFFERSIZE);\n  luaL_pushresult(&b);  /* close buffer */\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t nr;  /* number of chars actually read */\n  char *p;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */\n  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */\n  luaL_addsize(&b, nr);\n  luaL_pushresult(&b);  /* close buffer */\n  return (nr > 0);  /* true iff read something */\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f, 1);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)luaL_checkinteger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = luaL_checkstring(L, n);\n        if (*p == '*') p++;  /* skip optional '*' (for compatibility) */\n        switch (*p) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f, 1);\n            break;\n          case 'L':  /* line with end-of-line */\n            success = read_line(L, f, 0);\n            break;\n          case 'a':  /* file */\n            read_all(L, f);  /* read entire file */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return luaL_fileresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));\n  int i;\n  int n = (int)lua_tointeger(L, lua_upvalueindex(2));\n  if (isclosed(p))  /* file is already closed? */\n    return luaL_error(L, \"file is already closed\");\n  lua_settop(L , 1);\n  luaL_checkstack(L, n, \"too many arguments\");\n  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */\n    lua_pushvalue(L, lua_upvalueindex(3 + i));\n  n = g_read(L, p->f, 2);  /* 'n' is number of results */\n  lua_assert(n > 0);  /* should return at least a nil */\n  if (lua_toboolean(L, -n))  /* read at least one value? */\n    return n;  /* return them */\n  else {  /* first result is nil: EOF or error */\n    if (n > 1) {  /* is there error information? */\n      /* 2nd result is error message */\n      return luaL_error(L, \"%s\", lua_tostring(L, -n + 1));\n    }\n    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - arg;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      int len = lua_isinteger(L, arg)\n                ? fprintf(f, LUA_INTEGER_FMT,\n                             (LUAI_UACINT)lua_tointeger(L, arg))\n                : fprintf(f, LUA_NUMBER_FMT,\n                             (LUAI_UACNUMBER)lua_tonumber(L, arg));\n      status = status && (len > 0);\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  if (status) return 1;  /* file handle already on stack top */\n  else return luaL_fileresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  FILE *f = tofile(L);\n  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */\n  return g_write(L, f, 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  lua_Integer p3 = luaL_optinteger(L, 3, 0);\n  l_seeknum offset = (l_seeknum)p3;\n  luaL_argcheck(L, (lua_Integer)offset == p3, 3,\n                  \"not an integer in proper range\");\n  op = l_fseek(f, offset, mode[op]);\n  if (op)\n    return luaL_fileresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, (lua_Integer)l_ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], (size_t)sz);\n  return luaL_fileresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\n/*\n** functions for 'io' library\n*/\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\n/*\n** methods for file handles\n*/\nstatic const luaL_Reg flib[] = {\n  {\"close\", io_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", f_gc},\n  {\"__tostring\", f_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */\n  lua_pop(L, 1);  /* pop new metatable */\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  p->closef = &io_noclose;  /* keep file opened */\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, const char *k,\n                           const char *fname) {\n  LStream *p = newprefile(L);\n  p->f = f;\n  p->closef = &io_noclose;\n  if (k != NULL) {\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */\n  }\n  lua_setfield(L, -2, fname);  /* add file to module */\n}\n\n\nLUAMOD_API int luaopen_io (lua_State *L) {\n  luaL_newlib(L, iolib);  /* new module */\n  createmeta(L);\n  /* create (and set) default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, NULL, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nstatic const char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"goto\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"//\", \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<<\", \">>\", \"::\", \"<eof>\",\n    \"<number>\", \"<integer>\", \"<name>\", \"<string>\"\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token);\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {\n    size_t newsize;\n    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)\n      lexerror(ls, \"lexical element too long\", 0);\n    newsize = luaZ_sizebuffer(b) * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[luaZ_bufflen(b)++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */\n  luaC_fix(L, obj2gco(e));  /* never collect this name */\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */\n    ts->extra = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {  /* single-byte symbols? */\n    lua_assert(token == cast_uchar(token));\n    return luaO_pushfstring(ls->L, \"'%c'\", token);\n  }\n  else {\n    const char *s = luaX_tokens[token - FIRST_RESERVED];\n    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */\n      return luaO_pushfstring(ls->L, \"'%s'\", s);\n    else  /* names, strings, and numerals */\n      return s;\n  }\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME: case TK_STRING:\n    case TK_FLT: case TK_INT:\n      save(ls, '\\0');\n      return luaO_pushfstring(ls->L, \"'%s'\", luaZ_buffer(ls->buff));\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token) {\n  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near %s\", msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nl_noret luaX_syntaxerror (LexState *ls, const char *msg) {\n  lexerror(ls, msg, ls->t.token);\n}\n\n\n/*\n** creates a new string and anchors it in scanner's table so that\n** it will not be collected until the end of the compilation\n** (by that time it should be anchored somewhere)\n*/\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TValue *o;  /* entry for 'str' */\n  TString *ts = luaS_newlstr(L, str, l);  /* create new string */\n  setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */\n  o = luaH_set(L, ls->h, L->top - 1);\n  if (ttisnil(o)) {  /* not in use yet? */\n    /* boolean value does not need GC barrier;\n       table has no metatable, so it does not need to invalidate cache */\n    setbvalue(o, 1);  /* t[string] = true */\n    luaC_checkGC(L);\n  }\n  else {  /* string already present */\n    ts = tsvalue(keyfromval(o));  /* re-use value previously stored */\n  }\n  L->top--;  /* remove string from stack */\n  return ts;\n}\n\n\n/*\n** increment line number and skips newline sequence (any of\n** \\n, \\r, \\n\\r, or \\r\\n)\n*/\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip '\\n' or '\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip '\\n\\r' or '\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    lexerror(ls, \"chunk has too many lines\", 0);\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,\n                    int firstchar) {\n  ls->t.token = 0;\n  ls->L = L;\n  ls->current = firstchar;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\nstatic int check_next1 (LexState *ls, int c) {\n  if (ls->current == c) {\n    next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check whether current char is in set 'set' (with two chars) and\n** saves it\n*/\nstatic int check_next2 (LexState *ls, const char *set) {\n  lua_assert(set[2] == '\\0');\n  if (ls->current == set[0] || ls->current == set[1]) {\n    save_and_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/* LUA_NUMBER */\n/*\n** this function is quite liberal in what it accepts, as 'luaO_str2num'\n** will reject ill-formed numerals.\n*/\nstatic int read_numeral (LexState *ls, SemInfo *seminfo) {\n  TValue obj;\n  const char *expo = \"Ee\";\n  int first = ls->current;\n  lua_assert(lisdigit(ls->current));\n  save_and_next(ls);\n  if (first == '0' && check_next2(ls, \"xX\"))  /* hexadecimal? */\n    expo = \"Pp\";\n  for (;;) {\n    if (check_next2(ls, expo))  /* exponent part? */\n      check_next2(ls, \"-+\");  /* optional exponent sign */\n    if (lisxdigit(ls->current))\n      save_and_next(ls);\n    else if (ls->current == '.')\n      save_and_next(ls);\n    else break;\n  }\n  save(ls, '\\0');\n  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */\n    lexerror(ls, \"malformed number\", TK_FLT);\n  if (ttisinteger(&obj)) {\n    seminfo->i = ivalue(&obj);\n    return TK_INT;\n  }\n  else {\n    lua_assert(ttisfloat(&obj));\n    seminfo->r = fltvalue(&obj);\n    return TK_FLT;\n  }\n}\n\n\n/*\n** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return\n** its number of '='s; otherwise, return a negative number (-1 iff there\n** are no '='s after initial bracket)\n*/\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int line = ls->linenumber;  /* initial line (for error message) */\n  save_and_next(ls);  /* skip 2nd '[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ: {  /* error */\n        const char *what = (seminfo ? \"string\" : \"comment\");\n        const char *msg = luaO_pushfstring(ls->L,\n                     \"unfinished long %s (starting at line %d)\", what, line);\n        lexerror(ls, msg, TK_EOS);\n        break;  /* to avoid warnings */\n      }\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd ']' */\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n': case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void esccheck (LexState *ls, int c, const char *msg) {\n  if (!c) {\n    if (ls->current != EOZ)\n      save_and_next(ls);  /* add current to buffer for error message */\n    lexerror(ls, msg, TK_STRING);\n  }\n}\n\n\nstatic int gethexa (LexState *ls) {\n  save_and_next(ls);\n  esccheck (ls, lisxdigit(ls->current), \"hexadecimal digit expected\");\n  return luaO_hexavalue(ls->current);\n}\n\n\nstatic int readhexaesc (LexState *ls) {\n  int r = gethexa(ls);\n  r = (r << 4) + gethexa(ls);\n  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic unsigned long readutf8esc (LexState *ls) {\n  unsigned long r;\n  int i = 4;  /* chars to be removed: '\\', 'u', '{', and first digit */\n  save_and_next(ls);  /* skip 'u' */\n  esccheck(ls, ls->current == '{', \"missing '{'\");\n  r = gethexa(ls);  /* must have at least one digit */\n  while ((save_and_next(ls), lisxdigit(ls->current))) {\n    i++;\n    r = (r << 4) + luaO_hexavalue(ls->current);\n    esccheck(ls, r <= 0x10FFFF, \"UTF-8 value too large\");\n  }\n  esccheck(ls, ls->current == '}', \"missing '}'\");\n  next(ls);  /* skip '}' */\n  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic void utf8esc (LexState *ls) {\n  char buff[UTF8BUFFSZ];\n  int n = luaO_utf8esc(buff, readutf8esc(ls));\n  for (; n > 0; n--)  /* add 'buff' to string */\n    save(ls, buff[UTF8BUFFSZ - n]);\n}\n\n\nstatic int readdecesc (LexState *ls) {\n  int i;\n  int r = 0;  /* result accumulator */\n  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */\n    r = 10*r + ls->current - '0';\n    save_and_next(ls);\n  }\n  esccheck(ls, r <= UCHAR_MAX, \"decimal escape too large\");\n  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */\n  return r;\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);  /* keep delimiter (for error messages) */\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        lexerror(ls, \"unfinished string\", TK_EOS);\n        break;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        lexerror(ls, \"unfinished string\", TK_STRING);\n        break;  /* to avoid warnings */\n      case '\\\\': {  /* escape sequences */\n        int c;  /* final character to be saved */\n        save_and_next(ls);  /* keep '\\\\' for error messages */\n        switch (ls->current) {\n          case 'a': c = '\\a'; goto read_save;\n          case 'b': c = '\\b'; goto read_save;\n          case 'f': c = '\\f'; goto read_save;\n          case 'n': c = '\\n'; goto read_save;\n          case 'r': c = '\\r'; goto read_save;\n          case 't': c = '\\t'; goto read_save;\n          case 'v': c = '\\v'; goto read_save;\n          case 'x': c = readhexaesc(ls); goto read_save;\n          case 'u': utf8esc(ls);  goto no_save;\n          case '\\n': case '\\r':\n            inclinenumber(ls); c = '\\n'; goto only_save;\n          case '\\\\': case '\\\"': case '\\'':\n            c = ls->current; goto read_save;\n          case EOZ: goto no_save;  /* will raise an error next loop */\n          case 'z': {  /* zap following span of spaces */\n            luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n            next(ls);  /* skip the 'z' */\n            while (lisspace(ls->current)) {\n              if (currIsNewline(ls)) inclinenumber(ls);\n              else next(ls);\n            }\n            goto no_save;\n          }\n          default: {\n            esccheck(ls, lisdigit(ls->current), \"invalid escape sequence\");\n            c = readdecesc(ls);  /* digital escape '\\ddd' */\n            goto only_save;\n          }\n        }\n       read_save:\n         next(ls);\n         /* go through */\n       only_save:\n         luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n         save(ls, c);\n         /* go through */\n       no_save: break;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n': case '\\r': {  /* line breaks */\n        inclinenumber(ls);\n        break;\n      }\n      case ' ': case '\\f': case '\\t': case '\\v': {  /* spaces */\n        next(ls);\n        break;\n      }\n      case '-': {  /* '-' or '--' (comment) */\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {  /* long comment? */\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* skip long comment */\n            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */\n            break;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);  /* skip until end of line (or end of file) */\n        break;\n      }\n      case '[': {  /* long string or simply '[' */\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep != -1)  /* '[=...' missing second bracket */\n          lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n        return '[';\n      }\n      case '=': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_EQ;\n        else return '=';\n      }\n      case '<': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_LE;\n        else if (check_next1(ls, '<')) return TK_SHL;\n        else return '<';\n      }\n      case '>': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_GE;\n        else if (check_next1(ls, '>')) return TK_SHR;\n        else return '>';\n      }\n      case '/': {\n        next(ls);\n        if (check_next1(ls, '/')) return TK_IDIV;\n        else return '/';\n      }\n      case '~': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_NE;\n        else return '~';\n      }\n      case ':': {\n        next(ls);\n        if (check_next1(ls, ':')) return TK_DBCOLON;\n        else return ':';\n      }\n      case '\"': case '\\'': {  /* short literal strings */\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {  /* '.', '..', '...', or number */\n        save_and_next(ls);\n        if (check_next1(ls, '.')) {\n          if (check_next1(ls, '.'))\n            return TK_DOTS;   /* '...' */\n          else return TK_CONCAT;   /* '..' */\n        }\n        else if (!lisdigit(ls->current)) return '.';\n        else return read_numeral(ls, seminfo);\n      }\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9': {\n        return read_numeral(ls, seminfo);\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (lislalpha(ls->current)) {  /* identifier or reserved word? */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (lislalnum(ls->current));\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          seminfo->ts = ts;\n          if (isreserved(ts))  /* reserved word? */\n            return ts->extra - 1 + FIRST_RESERVED;\n          else {\n            return TK_NAME;\n          }\n        }\n        else {  /* single-char tokens (+ - / ...) */\n          int c = ls->current;\n          next(ls);\n          return c;\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nint luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n  return ls->lookahead.token;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n\n#if !defined(LUA_ENV)\n#define LUA_ENV\t\t\"_ENV\"\n#endif\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,\n  TK_SHL, TK_SHR,\n  TK_DBCOLON, TK_EOS,\n  TK_FLT, TK_INT, TK_NAME, TK_STRING\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\ntypedef union {\n  lua_Number r;\n  lua_Integer i;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\n/* state of the lexer plus state of the parser when shared by all\n   functions */\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token 'consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* current function (parser) */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  Table *h;  /* to avoid collection/reuse strings */\n  struct Dyndata *dyd;  /* dynamic structures used by the parser */\n  TString *source;  /* current source name */\n  TString *envn;  /* environment variable name */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source, int firstchar);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC int luaX_lookahead (LexState *ls);\nLUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $\n** Limits, basic types, and some other 'installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n/*\n** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count\n** the total memory used by Lua (in bytes). Usually, 'size_t' and\n** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.\n*/\n#if defined(LUAI_MEM)\t\t/* { external definitions? */\ntypedef LUAI_UMEM lu_mem;\ntypedef LUAI_MEM l_mem;\n#elif LUAI_BITSINT >= 32\t/* }{ */\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\n#else  /* 16-bit ints */\t/* }{ */\ntypedef unsigned long lu_mem;\ntypedef long l_mem;\n#endif\t\t\t\t/* } */\n\n\n/* chars used as small naturals (so that 'char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n/* maximum size visible for Lua (must be representable in a lua_Integer */\n#define MAX_SIZE\t(sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \\\n                          : (size_t)(LUA_MAXINTEGER))\n\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0))\n\n#define MAX_LMEM\t((l_mem)(MAX_LUMEM >> 1))\n\n\n#define MAX_INT\t\tINT_MAX  /* maximum value of an int */\n\n\n/*\n** conversion of pointer to unsigned integer:\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define point2uint(p)\t((unsigned int)((size_t)(p) & UINT_MAX))\n\n\n\n/* type to ensure maximum alignment */\n#if defined(LUAI_USER_ALIGNMENT_T)\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n#else\ntypedef union {\n  lua_Number n;\n  double u;\n  void *s;\n  lua_Integer i;\n  long l;\n} L_Umaxalign;\n#endif\n\n\n\n/* types of 'usual argument conversions' for lua_Number and lua_Integer */\ntypedef LUAI_UACNUMBER l_uacNumber;\ntypedef LUAI_UACINT l_uacInt;\n\n\n/* internal assertions for in-house debugging */\n#if defined(lua_assert)\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n/* to avoid problems with conditions too long */\n#define lua_longassert(c)\t((c) ? (void)0 : lua_assert(0))\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define lua_longassert(c)\t((void)0)\n#endif\n\n/*\n** assertion for checking API calls\n*/\n#if !defined(luai_apicheck)\n#define luai_apicheck(l,e)\tlua_assert(e)\n#endif\n\n#define api_check(l,e,msg)\tluai_apicheck(l,(e) && msg)\n\n\n/* macro to avoid warnings about unused variables */\n#if !defined(UNUSED)\n#define UNUSED(x)\t((void)(x))\n#endif\n\n\n/* type casts (a macro highlights casts in the code) */\n#define cast(t, exp)\t((t)(exp))\n\n#define cast_void(i)\tcast(void, (i))\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n#define cast_uchar(i)\tcast(unsigned char, (i))\n\n\n/* cast a signed lua_Integer to lua_Unsigned */\n#if !defined(l_castS2U)\n#define l_castS2U(i)\t((lua_Unsigned)(i))\n#endif\n\n/*\n** cast a lua_Unsigned to a signed lua_Integer; this cast is\n** not strict ISO C, but two-complement architectures should\n** work fine.\n*/\n#if !defined(l_castU2S)\n#define l_castU2S(i)\t((lua_Integer)(i))\n#endif\n\n\n/*\n** non-return type\n*/\n#if defined(__GNUC__)\n#define l_noret\t\tvoid __attribute__((noreturn))\n#elif defined(_MSC_VER) && _MSC_VER >= 1200\n#define l_noret\t\tvoid __declspec(noreturn)\n#else\n#define l_noret\t\tvoid\n#endif\n\n\n\n/*\n** maximum depth for nested C calls and syntactical nested non-terminals\n** in a program. (Value must fit in an unsigned short int.)\n*/\n#if !defined(LUAI_MAXCCALLS)\n#define LUAI_MAXCCALLS\t\t200\n#endif\n\n\n\n/*\n** type for virtual-machine instructions;\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\n#if LUAI_BITSINT >= 32\ntypedef unsigned int Instruction;\n#else\ntypedef unsigned long Instruction;\n#endif\n\n\n\n/*\n** Maximum length for short strings, that is, strings that are\n** internalized. (Cannot be smaller than reserved words or tags for\n** metamethods, as these strings must be internalized;\n** #(\"function\") = 8, #(\"__newindex\") = 10.)\n*/\n#if !defined(LUAI_MAXSHORTLEN)\n#define LUAI_MAXSHORTLEN\t40\n#endif\n\n\n/*\n** Initial size for the string table (must be power of 2).\n** The Lua core alone registers ~50 strings (reserved words +\n** metaevent keys + a few others). Libraries would typically add\n** a few dozens more.\n*/\n#if !defined(MINSTRTABSIZE)\n#define MINSTRTABSIZE\t128\n#endif\n\n\n/*\n** Size of cache for strings in the API. 'N' is the number of\n** sets (better be a prime) and \"M\" is the size of each set (M == 1\n** makes a direct cache.)\n*/\n#if !defined(STRCACHE_N)\n#define STRCACHE_N\t\t53\n#define STRCACHE_M\t\t2\n#endif\n\n\n/* minimum size for string buffer */\n#if !defined(LUA_MINBUFFER)\n#define LUA_MINBUFFER\t32\n#endif\n\n\n/*\n** macros that are executed whenever program enters the Lua core\n** ('lua_lock') and leaves the core ('lua_unlock')\n*/\n#if !defined(lua_lock)\n#define lua_lock(L)\t((void) 0)\n#define lua_unlock(L)\t((void) 0)\n#endif\n\n/*\n** macro executed during Lua functions at points where the\n** function can yield.\n*/\n#if !defined(luai_threadyield)\n#define luai_threadyield(L)\t{lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** these macros allow user-specific actions on threads when you defined\n** LUAI_EXTRASPACE and need to do something extra when a thread is\n** created/deleted/resumed/yielded.\n*/\n#if !defined(luai_userstateopen)\n#define luai_userstateopen(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstateclose)\n#define luai_userstateclose(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstatethread)\n#define luai_userstatethread(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstatefree)\n#define luai_userstatefree(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstateresume)\n#define luai_userstateresume(L,n)\t((void)L)\n#endif\n\n#if !defined(luai_userstateyield)\n#define luai_userstateyield(L,n)\t((void)L)\n#endif\n\n\n\n/*\n** The luai_num* macros define the primitive operations over numbers.\n*/\n\n/* floor division (defined as 'floor(a/b)') */\n#if !defined(luai_numidiv)\n#define luai_numidiv(L,a,b)     ((void)L, l_floor(luai_numdiv(L,a,b)))\n#endif\n\n/* float division */\n#if !defined(luai_numdiv)\n#define luai_numdiv(L,a,b)      ((a)/(b))\n#endif\n\n/*\n** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when\n** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of\n** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)\n** ~= floor(a/b)'. That happens when the division has a non-integer\n** negative result, which is equivalent to the test below.\n*/\n#if !defined(luai_nummod)\n#define luai_nummod(L,a,b,m)  \\\n  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }\n#endif\n\n/* exponentiation */\n#if !defined(luai_numpow)\n#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))\n#endif\n\n/* the others are quite standard operations */\n#if !defined(luai_numadd)\n#define luai_numadd(L,a,b)      ((a)+(b))\n#define luai_numsub(L,a,b)      ((a)-(b))\n#define luai_nummul(L,a,b)      ((a)*(b))\n#define luai_numunm(L,a)        (-(a))\n#define luai_numeq(a,b)         ((a)==(b))\n#define luai_numlt(a,b)         ((a)<(b))\n#define luai_numle(a,b)         ((a)<=(b))\n#define luai_numisnan(a)        (!luai_numeq((a), (a)))\n#endif\n\n\n\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/\n#if !defined(HARDSTACKTESTS)\n#define condmovestack(L,pre,pos)\t((void)0)\n#else\n/* realloc stack keeping its size */\n#define condmovestack(L,pre,pos)  \\\n\t{ int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; }\n#endif\n\n#if !defined(HARDMEMTESTS)\n#define condchangemem(L,pre,pos)\t((void)0)\n#else\n#define condchangemem(L,pre,pos)  \\\n\t{ if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }\n#endif\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.119 2016/12/22 13:08:50 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI\t(l_mathop(3.141592653589793238462643383279502884))\n\n\n#if !defined(l_rand)\t\t/* { */\n#if defined(LUA_USE_POSIX)\n#define l_rand()\trandom()\n#define l_srand(x)\tsrandom(x)\n#define L_RANDMAX\t2147483647\t/* (2^31 - 1), following POSIX */\n#else\n#define l_rand()\trand()\n#define l_srand(x)\tsrand(x)\n#define L_RANDMAX\tRAND_MAX\n#endif\n#endif\t\t\t\t/* } */\n\n\nstatic int math_abs (lua_State *L) {\n  if (lua_isinteger(L, 1)) {\n    lua_Integer n = lua_tointeger(L, 1);\n    if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);\n    lua_pushinteger(L, n);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_Number y = luaL_checknumber(L, 1);\n  lua_Number x = luaL_optnumber(L, 2, 1);\n  lua_pushnumber(L, l_mathop(atan2)(y, x));\n  return 1;\n}\n\n\nstatic int math_toint (lua_State *L) {\n  int valid;\n  lua_Integer n = lua_tointegerx(L, 1, &valid);\n  if (valid)\n    lua_pushinteger(L, n);\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);  /* value is not convertible to integer */\n  }\n  return 1;\n}\n\n\nstatic void pushnumint (lua_State *L, lua_Number d) {\n  lua_Integer n;\n  if (lua_numbertointeger(d, &n))  /* does 'd' fit in an integer? */\n    lua_pushinteger(L, n);  /* result is integer */\n  else\n    lua_pushnumber(L, d);  /* result is float */\n}\n\n\nstatic int math_floor (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own floor */\n  else {\n    lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_ceil (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own ceil */\n  else {\n    lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_fmod (lua_State *L) {\n  if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) {\n    lua_Integer d = lua_tointeger(L, 2);\n    if ((lua_Unsigned)d + 1u <= 1u) {  /* special cases: -1 or 0 */\n      luaL_argcheck(L, d != 0, 2, \"zero\");\n      lua_pushinteger(L, 0);  /* avoid overflow with 0x80000... / -1 */\n    }\n    else\n      lua_pushinteger(L, lua_tointeger(L, 1) % d);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),\n                                     luaL_checknumber(L, 2)));\n  return 1;\n}\n\n\n/*\n** next function does not use 'modf', avoiding problems with 'double*'\n** (which is not compatible with 'float*') when lua_Number is not\n** 'double'.\n*/\nstatic int math_modf (lua_State *L) {\n  if (lua_isinteger(L ,1)) {\n    lua_settop(L, 1);  /* number is its own integer part */\n    lua_pushnumber(L, 0);  /* no fractional part */\n  }\n  else {\n    lua_Number n = luaL_checknumber(L, 1);\n    /* integer part (rounds toward zero) */\n    lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);\n    pushnumint(L, ip);\n    /* fractional part (test needed for inf/-inf) */\n    lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));\n  }\n  return 2;\n}\n\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n\nstatic int math_ult (lua_State *L) {\n  lua_Integer a = luaL_checkinteger(L, 1);\n  lua_Integer b = luaL_checkinteger(L, 2);\n  lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b);\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number res;\n  if (lua_isnoneornil(L, 2))\n    res = l_mathop(log)(x);\n  else {\n    lua_Number base = luaL_checknumber(L, 2);\n    if (base == l_mathop(10.0))\n      res = l_mathop(log10)(x);\n    else\n      res = l_mathop(log)(x)/l_mathop(log)(base);\n  }\n  lua_pushnumber(L, res);\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));\n  return 1;\n}\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imin = 1;  /* index of current minimum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, i, imin, LUA_OPLT))\n      imin = i;\n  }\n  lua_pushvalue(L, imin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imax = 1;  /* index of current maximum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, imax, i, LUA_OPLT))\n      imax = i;\n  }\n  lua_pushvalue(L, imax);\n  return 1;\n}\n\n/*\n** This function uses 'double' (instead of 'lua_Number') to ensure that\n** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0'\n** will keep full precision (ensuring that 'r' is always less than 1.0.)\n*/\nstatic int math_random (lua_State *L) {\n  lua_Integer low, up;\n  double r = (double)l_rand() * (1.0 / ((double)L_RANDMAX + 1.0));\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, (lua_Number)r);  /* Number between 0 and 1 */\n      return 1;\n    }\n    case 1: {  /* only upper limit */\n      low = 1;\n      up = luaL_checkinteger(L, 1);\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      low = luaL_checkinteger(L, 1);\n      up = luaL_checkinteger(L, 2);\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  /* random integer in the interval [low, up] */\n  luaL_argcheck(L, low <= up, 1, \"interval is empty\");\n  luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,\n                   \"interval too large\");\n  r *= (double)(up - low) + 1.0;\n  lua_pushinteger(L, (lua_Integer)r + low);\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));\n  (void)l_rand(); /* discard first value to avoid undesirable correlations */\n  return 0;\n}\n\n\nstatic int math_type (lua_State *L) {\n  if (lua_type(L, 1) == LUA_TNUMBER) {\n      if (lua_isinteger(L, 1))\n        lua_pushliteral(L, \"integer\");\n      else\n        lua_pushliteral(L, \"float\");\n  }\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);\n  }\n  return 1;\n}\n\n\n/*\n** {==================================================================\n** Deprecated functions (for compatibility only)\n** ===================================================================\n*/\n#if defined(LUA_COMPAT_MATHLIB)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number y = luaL_checknumber(L, 2);\n  lua_pushnumber(L, l_mathop(pow)(x, y));\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  int ep = (int)luaL_checkinteger(L, 2);\n  lua_pushnumber(L, l_mathop(ldexp)(x, ep));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n#endif\n/* }================================================================== */\n\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"tointeger\", math_toint},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"ult\",   math_ult},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tan\",   math_tan},\n  {\"type\", math_type},\n#if defined(LUA_COMPAT_MATHLIB)\n  {\"atan2\", math_atan},\n  {\"cosh\",   math_cosh},\n  {\"sinh\",   math_sinh},\n  {\"tanh\",   math_tanh},\n  {\"pow\",   math_pow},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n#endif\n  /* placeholders */\n  {\"pi\", NULL},\n  {\"huge\", NULL},\n  {\"maxinteger\", NULL},\n  {\"mininteger\", NULL},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUAMOD_API int luaopen_math (lua_State *L) {\n  luaL_newlib(L, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, (lua_Number)HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n  lua_pushinteger(L, LUA_MAXINTEGER);\n  lua_setfield(L, -2, \"maxinteger\");\n  lua_pushinteger(L, LUA_MININTEGER);\n  lua_setfield(L, -2, \"mininteger\");\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** ('osize' is the old size, 'nsize' is the new size)\n**\n** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no\n** matter 'x').\n**\n** * frealloc(ud, p, x, 0) frees the block 'p'\n** (in this specific case, frealloc must return NULL);\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ISO C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *what) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, \"too many %s (limit is %d)\", what, limit);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nl_noret luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  void *newblock;\n  global_State *g = G(L);\n  size_t realosize = (block) ? osize : 0;\n  lua_assert((realosize == 0) == (block == NULL));\n#if defined(HARDMEMTESTS)\n  if (nsize > realosize && g->gcrunning)\n    luaC_fullgc(L, 1);  /* force a GC whenever possible */\n#endif\n  newblock = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (newblock == NULL && nsize > 0) {\n    lua_assert(nsize > realosize);  /* cannot fail when shrinking a block */\n    if (g->version) {  /* is state fully built? */\n      luaC_fullgc(L, 1);  /* try to free some memory... */\n      newblock = (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */\n    }\n    if (newblock == NULL)\n      luaD_throw(L, LUA_ERRMEM);\n  }\n  lua_assert((nsize == 0) == (newblock == NULL));\n  g->GCdebt = (g->GCdebt + nsize) - realosize;\n  return newblock;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** This macro reallocs a vector 'b' from 'on' to 'n' elements, where\n** each element has size 'e'. In case of arithmetic overflow of the\n** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because\n** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e).\n**\n** (The macro is somewhat complex to avoid warnings:  The 'sizeof'\n** comparison avoids a runtime comparison when overflow cannot occur.\n** The compiler should be able to optimize the real test by itself, but\n** when it does it, it may give a warning about \"comparison is always\n** false due to limited range of data type\"; the +1 tricks the compiler,\n** avoiding this warning but also this optimization.)\n*/\n#define luaM_reallocv(L,b,on,n,e) \\\n  (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \\\n      ? luaM_toobig(L) : cast_void(0)) , \\\n   luaM_realloc_(L, (b), (on)*(e), (n)*(e)))\n\n/*\n** Arrays of chars do not need any test\n*/\n#define luaM_reallocvchar(L,b,on,n)  \\\n    cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n)   luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0)\n\n#define luaM_malloc(L,s)\tluaM_realloc_(L, NULL, 0, (s))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_newobject(L,tag,s)\tluaM_realloc_(L, NULL, tag, (s))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\nLUAI_FUNC l_noret luaM_toobig (lua_State *L);\n\n/* not to be called directly */\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *what);\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** unique key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const int CLIBS = 0;\n\n#define LIB_FAIL\t\"open\"\n\n\n#define setprogdir(L)           ((void)0)\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\n\n#undef setprogdir\n\n\n/*\n** Replace in the path (on the top of the stack) any occurrence\n** of LUA_EXEC_DIR with the executable's path.\n*/\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);  /* get exec. name */\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';  /* cut name on the last '\\\\' to get the path */\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** {==================================================================\n** Set Paths\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR    \"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR   \"LUA_CPATH\"\n#endif\n\n\n#define AUXMARK         \"\\1\"\t/* auxiliary mark */\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\n/*\n** Set a path\n*/\nstatic void setpath (lua_State *L, const char *fieldname,\n                                   const char *envname,\n                                   const char *dft) {\n  const char *nver = lua_pushfstring(L, \"%s%s\", envname, LUA_VERSUFFIX);\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(nver);  /* use versioned name */\n  if (path == NULL)  /* no environment variable? */\n    path = getenv(envname);  /* try unversioned name */\n#endif\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, dft);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,\n                              LUA_PATH_SEP AUXMARK LUA_PATH_SEP);\n    luaL_gsub(L, path, AUXMARK, dft);\n    lua_remove(L, -2); /* remove result from 1st 'gsub' */\n  }\n  setprogdir(L);\n  lua_setfield(L, -3, fieldname);  /* package[fieldname] = path value */\n  lua_pop(L, 1);  /* pop versioned variable name */\n}\n\n/* }================================================================== */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATH_SEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATH_SEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n                                     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file '%s'\", filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"\\n\\tno module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else\n      lua_pop(L, 2);  /* remove both returns */\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, 2, name);  /* LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_pushstring(L, name);  /* pass name as argument to module loader */\n  lua_insert(L, -2);  /* name is 1st argument (before search data) */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* LOADED[name] = returned value */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\n/*\n** changes the environment variable of calling function\n*/\nstatic void set_env (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, \"'module' not called from a Lua function\");\n  lua_pushvalue(L, -2);  /* copy new environment table to top */\n  lua_setupvalue(L, -2, 1);\n  lua_pop(L, 1);  /* remove function */\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    if (lua_isfunction(L, i)) {  /* avoid 'calling' extra info. */\n      lua_pushvalue(L, i);  /* get option (a function) */\n      lua_pushvalue(L, -2);  /* module */\n      lua_call(L, 1, 0);\n    }\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = lua_gettop(L);  /* last parameter */\n  luaL_pushmodule(L, modname, 1);  /* get/create module table */\n  /* check whether table already has a _NAME field */\n  if (lua_getfield(L, -1, \"_NAME\") != LUA_TNIL)\n    lua_pop(L, 1);  /* table is an initialized module */\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  set_env(L);\n  dooptions(L, lastarg);\n  return 1;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushglobaltable(L);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n#endif\n/* }====================================================== */\n\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n#if defined(LUA_COMPAT_MODULE)\n  {\"seeall\", ll_seeall},\n#endif\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n#if defined(LUA_COMPAT_MODULE)\n  {\"module\", ll_module},\n#endif\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if defined(LUA_COMPAT_LOADERS)\n  lua_pushvalue(L, -1);  /* make a copy of 'searchers' table */\n  lua_setfield(L, -3, \"loaders\");  /* put it in field 'loaders' */\n#endif\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  lua_newtable(L);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n  lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set paths */\n  setpath(L, \"path\", LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  setpath(L, \"cpath\", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.113 2016/12/22 13:08:50 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nLUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* exponent */\n  if (x < 8) return x;\n  while (x >= (8 << 4)) {  /* coarse steps */\n    x = (x + 0xf) >> 4;  /* x = ceil(x / 16) */\n    e += 4;\n  }\n  while (x >= (8 << 1)) {  /* fine steps */\n    x = (x + 1) >> 1;  /* x = ceil(x / 2) */\n    e++;\n  }\n  return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);\n}\n\n\n/*\n** Computes ceil(log2(x))\n*/\nint luaO_ceillog2 (unsigned int x) {\n  static const lu_byte log_2[256] = {  /* log_2[i] = ceil(log2(i - 1)) */\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = 0;\n  x--;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n}\n\n\nstatic lua_Integer intarith (lua_State *L, int op, lua_Integer v1,\n                                                   lua_Integer v2) {\n  switch (op) {\n    case LUA_OPADD: return intop(+, v1, v2);\n    case LUA_OPSUB:return intop(-, v1, v2);\n    case LUA_OPMUL:return intop(*, v1, v2);\n    case LUA_OPMOD: return luaV_mod(L, v1, v2);\n    case LUA_OPIDIV: return luaV_div(L, v1, v2);\n    case LUA_OPBAND: return intop(&, v1, v2);\n    case LUA_OPBOR: return intop(|, v1, v2);\n    case LUA_OPBXOR: return intop(^, v1, v2);\n    case LUA_OPSHL: return luaV_shiftl(v1, v2);\n    case LUA_OPSHR: return luaV_shiftl(v1, -v2);\n    case LUA_OPUNM: return intop(-, 0, v1);\n    case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lua_Number numarith (lua_State *L, int op, lua_Number v1,\n                                                  lua_Number v2) {\n  switch (op) {\n    case LUA_OPADD: return luai_numadd(L, v1, v2);\n    case LUA_OPSUB: return luai_numsub(L, v1, v2);\n    case LUA_OPMUL: return luai_nummul(L, v1, v2);\n    case LUA_OPDIV: return luai_numdiv(L, v1, v2);\n    case LUA_OPPOW: return luai_numpow(L, v1, v2);\n    case LUA_OPIDIV: return luai_numidiv(L, v1, v2);\n    case LUA_OPUNM: return luai_numunm(L, v1);\n    case LUA_OPMOD: {\n      lua_Number m;\n      luai_nummod(L, v1, v2, m);\n      return m;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                 TValue *res) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR:\n    case LUA_OPBNOT: {  /* operate only on integers */\n      lua_Integer i1; lua_Integer i2;\n      if (tointeger(p1, &i1) && tointeger(p2, &i2)) {\n        setivalue(res, intarith(L, op, i1, i2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    case LUA_OPDIV: case LUA_OPPOW: {  /* operate only on floats */\n      lua_Number n1; lua_Number n2;\n      if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    default: {  /* other operations */\n      lua_Number n1; lua_Number n2;\n      if (ttisinteger(p1) && ttisinteger(p2)) {\n        setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));\n        return;\n      }\n      else if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n  }\n  /* could not perform raw operation; try metamethod */\n  lua_assert(L != NULL);  /* should not fail when folding (compile time) */\n  luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));\n}\n\n\nint luaO_hexavalue (int c) {\n  if (lisdigit(c)) return c - '0';\n  else return (ltolower(c) - 'a') + 10;\n}\n\n\nstatic int isneg (const char **s) {\n  if (**s == '-') { (*s)++; return 1; }\n  else if (**s == '+') (*s)++;\n  return 0;\n}\n\n\n\n/*\n** {==================================================================\n** Lua's implementation for 'lua_strx2number'\n** ===================================================================\n*/\n\n#if !defined(lua_strx2number)\n\n/* maximum number of significant digits to read (to avoid overflows\n   even with single floats) */\n#define MAXSIGDIG\t30\n\n/*\n** convert an hexadecimal numeric string to a number, following\n** C99 specification for 'strtod'\n*/\nstatic lua_Number lua_strx2number (const char *s, char **endptr) {\n  int dot = lua_getlocaledecpoint();\n  lua_Number r = 0.0;  /* result (accumulator) */\n  int sigdig = 0;  /* number of significant digits */\n  int nosigdig = 0;  /* number of non-significant digits */\n  int e = 0;  /* exponent correction */\n  int neg;  /* 1 if number is negative */\n  int hasdot = 0;  /* true after seen a dot */\n  *endptr = cast(char *, s);  /* nothing is valid yet */\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);  /* check signal */\n  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */\n    return 0.0;  /* invalid format (no '0x') */\n  for (s += 2; ; s++) {  /* skip '0x' and read numeral */\n    if (*s == dot) {\n      if (hasdot) break;  /* second dot? stop loop */\n      else hasdot = 1;\n    }\n    else if (lisxdigit(cast_uchar(*s))) {\n      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */\n        nosigdig++;\n      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */\n          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);\n      else e++; /* too many digits; ignore, but still count for exponent */\n      if (hasdot) e--;  /* decimal digit? correct exponent */\n    }\n    else break;  /* neither a dot nor a digit */\n  }\n  if (nosigdig + sigdig == 0)  /* no digits? */\n    return 0.0;  /* invalid format */\n  *endptr = cast(char *, s);  /* valid up to here */\n  e *= 4;  /* each digit multiplies/divides value by 2^4 */\n  if (*s == 'p' || *s == 'P') {  /* exponent part? */\n    int exp1 = 0;  /* exponent value */\n    int neg1;  /* exponent signal */\n    s++;  /* skip 'p' */\n    neg1 = isneg(&s);  /* signal */\n    if (!lisdigit(cast_uchar(*s)))\n      return 0.0;  /* invalid; must have at least one digit */\n    while (lisdigit(cast_uchar(*s)))  /* read exponent */\n      exp1 = exp1 * 10 + *(s++) - '0';\n    if (neg1) exp1 = -exp1;\n    e += exp1;\n    *endptr = cast(char *, s);  /* valid up to here */\n  }\n  if (neg) r = -r;\n  return l_mathop(ldexp)(r, e);\n}\n\n#endif\n/* }====================================================== */\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM\t200\n#endif\n\nstatic const char *l_str2dloc (const char *s, lua_Number *result, int mode) {\n  char *endptr;\n  *result = (mode == 'x') ? lua_strx2number(s, &endptr)  /* try to convert */\n                          : lua_str2number(s, &endptr);\n  if (endptr == s) return NULL;  /* nothing recognized? */\n  while (lisspace(cast_uchar(*endptr))) endptr++;  /* skip trailing spaces */\n  return (*endptr == '\\0') ? endptr : NULL;  /* OK if no trailing characters */\n}\n\n\n/*\n** Convert string 's' to a Lua number (put in 'result'). Return NULL\n** on fail or the address of the ending '\\0' on success.\n** 'pmode' points to (and 'mode' contains) special things in the string:\n** - 'x'/'X' means an hexadecimal numeral\n** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)\n** - '.' just optimizes the search for the common case (nothing special)\n** This function accepts both the current locale or a dot as the radix\n** mark. If the convertion fails, it may mean number has a dot but\n** locale accepts something else. In that case, the code copies 's'\n** to a buffer (because 's' is read-only), changes the dot to the\n** current locale radix mark, and tries to convert again.\n*/\nstatic const char *l_str2d (const char *s, lua_Number *result) {\n  const char *endptr;\n  const char *pmode = strpbrk(s, \".xXnN\");\n  int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;\n  if (mode == 'n')  /* reject 'inf' and 'nan' */\n    return NULL;\n  endptr = l_str2dloc(s, result, mode);  /* try to convert */\n  if (endptr == NULL) {  /* failed? may be a different locale */\n    char buff[L_MAXLENNUM + 1];\n    const char *pdot = strchr(s, '.');\n    if (strlen(s) > L_MAXLENNUM || pdot == NULL)\n      return NULL;  /* string too long or no dot; fail */\n    strcpy(buff, s);  /* copy string to buffer */\n    buff[pdot - s] = lua_getlocaledecpoint();  /* correct decimal point */\n    endptr = l_str2dloc(buff, result, mode);  /* try again */\n    if (endptr != NULL)\n      endptr = s + (endptr - buff);  /* make relative to 's' */\n  }\n  return endptr;\n}\n\n\n#define MAXBY10\t\tcast(lua_Unsigned, LUA_MAXINTEGER / 10)\n#define MAXLASTD\tcast_int(LUA_MAXINTEGER % 10)\n\nstatic const char *l_str2int (const char *s, lua_Integer *result) {\n  lua_Unsigned a = 0;\n  int empty = 1;\n  int neg;\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);\n  if (s[0] == '0' &&\n      (s[1] == 'x' || s[1] == 'X')) {  /* hex? */\n    s += 2;  /* skip '0x' */\n    for (; lisxdigit(cast_uchar(*s)); s++) {\n      a = a * 16 + luaO_hexavalue(*s);\n      empty = 0;\n    }\n  }\n  else {  /* decimal */\n    for (; lisdigit(cast_uchar(*s)); s++) {\n      int d = *s - '0';\n      if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg))  /* overflow? */\n        return NULL;  /* do not accept it (as integer) */\n      a = a * 10 + d;\n      empty = 0;\n    }\n  }\n  while (lisspace(cast_uchar(*s))) s++;  /* skip trailing spaces */\n  if (empty || *s != '\\0') return NULL;  /* something wrong in the numeral */\n  else {\n    *result = l_castU2S((neg) ? 0u - a : a);\n    return s;\n  }\n}\n\n\nsize_t luaO_str2num (const char *s, TValue *o) {\n  lua_Integer i; lua_Number n;\n  const char *e;\n  if ((e = l_str2int(s, &i)) != NULL) {  /* try as an integer */\n    setivalue(o, i);\n  }\n  else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */\n    setfltvalue(o, n);\n  }\n  else\n    return 0;  /* conversion failed */\n  return (e - s) + 1;  /* success; return string size */\n}\n\n\nint luaO_utf8esc (char *buff, unsigned long x) {\n  int n = 1;  /* number of bytes put in buffer (backwards) */\n  lua_assert(x <= 0x10FFFF);\n  if (x < 0x80)  /* ascii? */\n    buff[UTF8BUFFSZ - 1] = cast(char, x);\n  else {  /* need continuation bytes */\n    unsigned int mfb = 0x3f;  /* maximum that fits in first byte */\n    do {  /* add continuation bytes */\n      buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));\n      x >>= 6;  /* remove added bits */\n      mfb >>= 1;  /* now there is one less bit available in first byte */\n    } while (x > mfb);  /* still needs continuation byte? */\n    buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x);  /* add first byte */\n  }\n  return n;\n}\n\n\n/* maximum length of the conversion of a number to a string */\n#define MAXNUMBER2STR\t50\n\n\n/*\n** Convert a number object to a string\n*/\nvoid luaO_tostring (lua_State *L, StkId obj) {\n  char buff[MAXNUMBER2STR];\n  size_t len;\n  lua_assert(ttisnumber(obj));\n  if (ttisinteger(obj))\n    len = lua_integer2str(buff, sizeof(buff), ivalue(obj));\n  else {\n    len = lua_number2str(buff, sizeof(buff), fltvalue(obj));\n#if !defined(LUA_COMPAT_FLOATSTRING)\n    if (buff[strspn(buff, \"-0123456789\")] == '\\0') {  /* looks like an int? */\n      buff[len++] = lua_getlocaledecpoint();\n      buff[len++] = '0';  /* adds '.0' to result */\n    }\n#endif\n  }\n  setsvalue2s(L, obj, luaS_newlstr(L, buff, len));\n}\n\n\nstatic void pushstr (lua_State *L, const char *str, size_t l) {\n  setsvalue2s(L, L->top, luaS_newlstr(L, str, l));\n  luaD_inctop(L);\n}\n\n\n/*\n** this function handles only '%d', '%c', '%f', '%p', and '%s'\n   conventional formats, plus Lua-specific '%I' and '%U'\n*/\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 0;\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    pushstr(L, fmt, e - fmt);\n    switch (*(e+1)) {\n      case 's': {  /* zero-terminated string */\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s, strlen(s));\n        break;\n      }\n      case 'c': {  /* an 'int' as a character */\n        char buff = cast(char, va_arg(argp, int));\n        if (lisprint(cast_uchar(buff)))\n          pushstr(L, &buff, 1);\n        else  /* non-printable character; print its code */\n          luaO_pushfstring(L, \"<\\\\%d>\", cast_uchar(buff));\n        break;\n      }\n      case 'd': {  /* an 'int' */\n        setivalue(L->top, va_arg(argp, int));\n        goto top2str;\n      }\n      case 'I': {  /* a 'lua_Integer' */\n        setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));\n        goto top2str;\n      }\n      case 'f': {  /* a 'lua_Number' */\n        setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n      top2str:  /* convert the top element to a string */\n        luaD_inctop(L);\n        luaO_tostring(L, L->top - 1);\n        break;\n      }\n      case 'p': {  /* a pointer */\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */\n        int l = l_sprintf(buff, sizeof(buff), \"%p\", va_arg(argp, void *));\n        pushstr(L, buff, l);\n        break;\n      }\n      case 'U': {  /* an 'int' as a UTF-8 sequence */\n        char buff[UTF8BUFFSZ];\n        int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));\n        pushstr(L, buff + UTF8BUFFSZ - l, l);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\", 1);\n        break;\n      }\n      default: {\n        luaG_runerror(L, \"invalid option '%%%c' to 'lua_pushfstring'\",\n                         *(e + 1));\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  luaD_checkstack(L, 1);\n  pushstr(L, fmt, strlen(fmt));\n  if (n > 0) luaV_concat(L, n + 1);\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\n/* number of chars of a literal string without the ending \\0 */\n#define LL(x)\t(sizeof(x)/sizeof(char) - 1)\n\n#define RETS\t\"...\"\n#define PRE\t\"[string \\\"\"\n#define POS\t\"\\\"]\"\n\n#define addstr(a,b,l)\t( memcpy(a,b,(l) * sizeof(char)), a += (l) )\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  size_t l = strlen(source);\n  if (*source == '=') {  /* 'literal' source */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* truncate it */\n      addstr(out, source + 1, bufflen - 1);\n      *out = '\\0';\n    }\n  }\n  else if (*source == '@') {  /* file name */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* add '...' before rest of name */\n      addstr(out, RETS, LL(RETS));\n      bufflen -= LL(RETS);\n      memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));\n    }\n  }\n  else {  /* string; format as [string \"source\"] */\n    const char *nl = strchr(source, '\\n');  /* find first new line (if any) */\n    addstr(out, PRE, LL(PRE));  /* add prefix */\n    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\\0' */\n    if (l < bufflen && nl == NULL) {  /* small one-line source? */\n      addstr(out, source, l);  /* keep it */\n    }\n    else {\n      if (nl != NULL) l = nl - source;  /* stop at first newline */\n      if (l > bufflen) l = bufflen;\n      addstr(out, source, l);\n      addstr(out, RETS, LL(RETS));\n    }\n    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));\n  }\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.117 2016/08/01 19:51:24 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\tLUA_NUMTAGS\t\t/* function prototypes */\n#define LUA_TDEADKEY\t(LUA_NUMTAGS+1)\t\t/* removed keys in tables */\n\n/*\n** number of all possible tags (including LUA_TNONE but excluding DEADKEY)\n*/\n#define LUA_TOTALTAGS\t(LUA_TPROTO + 2)\n\n\n/*\n** tags for Tagged Values have the following use of bits:\n** bits 0-3: actual tag (a LUA_T* value)\n** bits 4-5: variant bits\n** bit 6: whether value is collectable\n*/\n\n\n/*\n** LUA_TFUNCTION variants:\n** 0 - Lua function\n** 1 - light C function\n** 2 - regular C function (closure)\n*/\n\n/* Variant tags for functions */\n#define LUA_TLCL\t(LUA_TFUNCTION | (0 << 4))  /* Lua closure */\n#define LUA_TLCF\t(LUA_TFUNCTION | (1 << 4))  /* light C function */\n#define LUA_TCCL\t(LUA_TFUNCTION | (2 << 4))  /* C closure */\n\n\n/* Variant tags for strings */\n#define LUA_TSHRSTR\t(LUA_TSTRING | (0 << 4))  /* short strings */\n#define LUA_TLNGSTR\t(LUA_TSTRING | (1 << 4))  /* long strings */\n\n\n/* Variant tags for numbers */\n#define LUA_TNUMFLT\t(LUA_TNUMBER | (0 << 4))  /* float numbers */\n#define LUA_TNUMINT\t(LUA_TNUMBER | (1 << 4))  /* integer numbers */\n\n\n/* Bit mark for collectable types */\n#define BIT_ISCOLLECTABLE\t(1 << 6)\n\n/* mark a tag as collectable */\n#define ctb(t)\t\t\t((t) | BIT_ISCOLLECTABLE)\n\n\n/*\n** Common type for all collectable objects\n*/\ntypedef struct GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common type has only the common header\n*/\nstruct GCObject {\n  CommonHeader;\n};\n\n\n\n\n/*\n** Tagged Values. This is the basic representation of values in Lua,\n** an actual value plus a tag with its type.\n*/\n\n/*\n** Union of all Lua values\n*/\ntypedef union Value {\n  GCObject *gc;    /* collectable objects */\n  void *p;         /* light userdata */\n  int b;           /* booleans */\n  lua_CFunction f; /* light C functions */\n  lua_Integer i;   /* integer numbers */\n  lua_Number n;    /* float numbers */\n} Value;\n\n\n#define TValuefields\tValue value_; int tt_\n\n\ntypedef struct lua_TValue {\n  TValuefields;\n} TValue;\n\n\n\n/* macro defining a nil value */\n#define NILCONSTANT\t{NULL}, LUA_TNIL\n\n\n#define val_(o)\t\t((o)->value_)\n\n\n/* raw type tag of a TValue */\n#define rttype(o)\t((o)->tt_)\n\n/* tag with no variants (bits 0-3) */\n#define novariant(x)\t((x) & 0x0F)\n\n/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */\n#define ttype(o)\t(rttype(o) & 0x3F)\n\n/* type tag of a TValue with no variants (bits 0-3) */\n#define ttnov(o)\t(novariant(rttype(o)))\n\n\n/* Macros to test type */\n#define checktag(o,t)\t\t(rttype(o) == (t))\n#define checktype(o,t)\t\t(ttnov(o) == (t))\n#define ttisnumber(o)\t\tchecktype((o), LUA_TNUMBER)\n#define ttisfloat(o)\t\tchecktag((o), LUA_TNUMFLT)\n#define ttisinteger(o)\t\tchecktag((o), LUA_TNUMINT)\n#define ttisnil(o)\t\tchecktag((o), LUA_TNIL)\n#define ttisboolean(o)\t\tchecktag((o), LUA_TBOOLEAN)\n#define ttislightuserdata(o)\tchecktag((o), LUA_TLIGHTUSERDATA)\n#define ttisstring(o)\t\tchecktype((o), LUA_TSTRING)\n#define ttisshrstring(o)\tchecktag((o), ctb(LUA_TSHRSTR))\n#define ttislngstring(o)\tchecktag((o), ctb(LUA_TLNGSTR))\n#define ttistable(o)\t\tchecktag((o), ctb(LUA_TTABLE))\n#define ttisfunction(o)\t\tchecktype(o, LUA_TFUNCTION)\n#define ttisclosure(o)\t\t((rttype(o) & 0x1F) == LUA_TFUNCTION)\n#define ttisCclosure(o)\t\tchecktag((o), ctb(LUA_TCCL))\n#define ttisLclosure(o)\t\tchecktag((o), ctb(LUA_TLCL))\n#define ttislcf(o)\t\tchecktag((o), LUA_TLCF)\n#define ttisfulluserdata(o)\tchecktag((o), ctb(LUA_TUSERDATA))\n#define ttisthread(o)\t\tchecktag((o), ctb(LUA_TTHREAD))\n#define ttisdeadkey(o)\t\tchecktag((o), LUA_TDEADKEY)\n\n\n/* Macros to access values */\n#define ivalue(o)\tcheck_exp(ttisinteger(o), val_(o).i)\n#define fltvalue(o)\tcheck_exp(ttisfloat(o), val_(o).n)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), \\\n\t(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))\n#define gcvalue(o)\tcheck_exp(iscollectable(o), val_(o).gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), val_(o).p)\n#define tsvalue(o)\tcheck_exp(ttisstring(o), gco2ts(val_(o).gc))\n#define uvalue(o)\tcheck_exp(ttisfulluserdata(o), gco2u(val_(o).gc))\n#define clvalue(o)\tcheck_exp(ttisclosure(o), gco2cl(val_(o).gc))\n#define clLvalue(o)\tcheck_exp(ttisLclosure(o), gco2lcl(val_(o).gc))\n#define clCvalue(o)\tcheck_exp(ttisCclosure(o), gco2ccl(val_(o).gc))\n#define fvalue(o)\tcheck_exp(ttislcf(o), val_(o).f)\n#define hvalue(o)\tcheck_exp(ttistable(o), gco2t(val_(o).gc))\n#define bvalue(o)\tcheck_exp(ttisboolean(o), val_(o).b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), gco2th(val_(o).gc))\n/* a dead value may get the 'gc' field, but cannot access its contents */\n#define deadvalue(o)\tcheck_exp(ttisdeadkey(o), cast(void *, val_(o).gc))\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n\n#define iscollectable(o)\t(rttype(o) & BIT_ISCOLLECTABLE)\n\n\n/* Macros for internal tests */\n#define righttt(obj)\t\t(ttype(obj) == gcvalue(obj)->tt)\n\n#define checkliveness(L,obj) \\\n\tlua_longassert(!iscollectable(obj) || \\\n\t\t(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))\n\n\n/* Macros to set values */\n#define settt_(o,t)\t((o)->tt_=(t))\n\n#define setfltvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }\n\n#define chgfltvalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }\n\n#define setivalue(obj,x) \\\n  { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }\n\n#define chgivalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }\n\n#define setnilvalue(obj) settt_(obj, LUA_TNIL)\n\n#define setfvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }\n\n#define setpvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }\n\n#define setbvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }\n\n#define setgcovalue(L,obj,x) \\\n  { TValue *io = (obj); GCObject *i_g=(x); \\\n    val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }\n\n#define setsvalue(L,obj,x) \\\n  { TValue *io = (obj); TString *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \\\n    checkliveness(L,io); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *io = (obj); Udata *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \\\n    checkliveness(L,io); }\n\n#define setthvalue(L,obj,x) \\\n  { TValue *io = (obj); lua_State *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \\\n    checkliveness(L,io); }\n\n#define setclLvalue(L,obj,x) \\\n  { TValue *io = (obj); LClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \\\n    checkliveness(L,io); }\n\n#define setclCvalue(L,obj,x) \\\n  { TValue *io = (obj); CClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \\\n    checkliveness(L,io); }\n\n#define sethvalue(L,obj,x) \\\n  { TValue *io = (obj); Table *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \\\n    checkliveness(L,io); }\n\n#define setdeadvalue(obj)\tsettt_(obj, LUA_TDEADKEY)\n\n\n\n#define setobj(L,obj1,obj2) \\\n\t{ TValue *io1=(obj1); *io1 = *(obj2); \\\n\t  (void)L; checkliveness(L,io1); }\n\n\n/*\n** different types of assignments, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n/* to table (define it as an expression to be used in macros) */\n#define setobj2t(L,o1,o2)  ((void)L, *(o1)=*(o2), checkliveness(L,(o1)))\n\n\n\n\n/*\n** {======================================================\n** types and prototypes\n** =======================================================\n*/\n\n\ntypedef TValue *StkId;  /* index to stack elements */\n\n\n\n\n/*\n** Header for string value; string bytes follow the end of this structure\n** (aligned according to 'UTString'; see next).\n*/\ntypedef struct TString {\n  CommonHeader;\n  lu_byte extra;  /* reserved words for short strings; \"has hash\" for longs */\n  lu_byte shrlen;  /* length for short strings */\n  unsigned int hash;\n  union {\n    size_t lnglen;  /* length for long strings */\n    struct TString *hnext;  /* linked list for hash table */\n  } u;\n} TString;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UTString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  TString tsv;\n} UTString;\n\n\n/*\n** Get the actual string (array of bytes) from a 'TString'.\n** (Access to 'extra' ensures that value is really a 'TString'.)\n*/\n#define getstr(ts)  \\\n  check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))\n\n\n/* get the actual string (array of bytes) from a Lua value */\n#define svalue(o)       getstr(tsvalue(o))\n\n/* get string length from 'TString *s' */\n#define tsslen(s)\t((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)\n\n/* get string length from 'TValue *o' */\n#define vslen(o)\ttsslen(tsvalue(o))\n\n\n/*\n** Header for userdata; memory area follows the end of this structure\n** (aligned according to 'UUdata'; see next).\n*/\ntypedef struct Udata {\n  CommonHeader;\n  lu_byte ttuv_;  /* user value's tag */\n  struct Table *metatable;\n  size_t len;  /* number of bytes */\n  union Value user_;  /* user value */\n} Udata;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UUdata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for 'local' udata */\n  Udata uv;\n} UUdata;\n\n\n/*\n**  Get the address of memory block inside 'Udata'.\n** (Access to 'ttuv_' ensures that value is really a 'Udata'.)\n*/\n#define getudatamem(u)  \\\n  check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata)))\n\n#define setuservalue(L,u,o) \\\n\t{ const TValue *io=(o); Udata *iu = (u); \\\n\t  iu->user_ = io->value_; iu->ttuv_ = rttype(io); \\\n\t  checkliveness(L,io); }\n\n\n#define getuservalue(L,u,o) \\\n\t{ TValue *io=(o); const Udata *iu = (u); \\\n\t  io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n\t  checkliveness(L,io); }\n\n\n/*\n** Description of an upvalue for function prototypes\n*/\ntypedef struct Upvaldesc {\n  TString *name;  /* upvalue name (for debug information) */\n  lu_byte instack;  /* whether it is in stack (register) */\n  lu_byte idx;  /* index of upvalue (in stack or in outer function's list) */\n} Upvaldesc;\n\n\n/*\n** Description of a local variable for function prototypes\n** (used for debug information)\n*/\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  lu_byte numparams;  /* number of fixed parameters */\n  lu_byte is_vararg;\n  lu_byte maxstacksize;  /* number of registers needed by this function */\n  int sizeupvalues;  /* size of 'upvalues' */\n  int sizek;  /* size of 'k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of 'p' */\n  int sizelocvars;\n  int linedefined;  /* debug information  */\n  int lastlinedefined;  /* debug information  */\n  TValue *k;  /* constants used by the function */\n  Instruction *code;  /* opcodes */\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines (debug information) */\n  LocVar *locvars;  /* information about local variables (debug information) */\n  Upvaldesc *upvalues;  /* upvalue information */\n  struct LClosure *cache;  /* last-created closure with this prototype */\n  TString  *source;  /* used for debug information */\n  GCObject *gclist;\n} Proto;\n\n\n\n/*\n** Lua Upvalues\n*/\ntypedef struct UpVal UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte nupvalues; GCObject *gclist\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];  /* list of upvalues */\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];  /* list of upvalues */\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define isLfunction(o)\tttisLclosure(o)\n\n#define getproto(o)\t(clLvalue(o)->p)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    int next;  /* for chaining (offset for next node) */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\n/* copy a value into a key without messing up field 'next' */\n#define setnodekey(L,key,obj) \\\n\t{ TKey *k_=(key); const TValue *io_=(obj); \\\n\t  k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \\\n\t  (void)L; checkliveness(L,io_); }\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */\n  lu_byte lsizenode;  /* log2 of size of 'node' array */\n  unsigned int sizearray;  /* size of 'array' array */\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  struct Table *metatable;\n  GCObject *gclist;\n} Table;\n\n\n\n/*\n** 'module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n/*\n** (address of) a fixed nil value\n*/\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\n\nLUAI_DDEC const TValue luaO_nilobject_;\n\n/* size of buffer for 'luaO_utf8esc' function */\n#define UTF8BUFFSZ\t8\n\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);\nLUAI_FUNC int luaO_ceillog2 (unsigned int x);\nLUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,\n                           const TValue *p2, TValue *res);\nLUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);\nLUAI_FUNC int luaO_hexavalue (int c);\nLUAI_FUNC void luaO_tostring (lua_State *L, StkId obj);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lopcodes_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nLUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADKX\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETTABUP\",\n  \"GETTABLE\",\n  \"SETTABUP\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"MOD\",\n  \"POW\",\n  \"DIV\",\n  \"IDIV\",\n  \"BAND\",\n  \"BOR\",\n  \"BXOR\",\n  \"SHL\",\n  \"SHR\",\n  \"UNM\",\n  \"BNOT\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORCALL\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSURE\",\n  \"VARARG\",\n  \"EXTRAARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nLUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgN, OpArgN, iABx)\t\t/* OP_LOADKX */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgU, OpArgK, iABC)\t\t/* OP_GETTABUP */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABUP */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_IDIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BAND */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BXOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHR */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_BNOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(0, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORCALL */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n ,opmode(0, 0, OpArgU, OpArgU, iAx)\t\t/* OP_EXTRAARG */\n};\n\n"
  },
  {
    "path": "WebGLPlugins/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t'A' : 8 bits\n\t'B' : 9 bits\n\t'C' : 9 bits\n\t'Ax' : 26 bits ('A', 'B', and 'C' together)\n\t'Bx' : 18 bits ('B' and 'C' together)\n\t'sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx, iAx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n#define SIZE_Ax\t\t(SIZE_C + SIZE_B + SIZE_A)\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n#define POS_Ax\t\tPOS_A\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* 'sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n#if SIZE_Ax < LUAI_BITSINT-1\n#define MAXARG_Ax\t((1<<SIZE_Ax)-1)\n#else\n#define MAXARG_Ax\tMAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with 'n' 1 bits at position 'p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<(n)))<<(p))\n\n/* creates a mask with 'n' 0 bits at position 'p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define getarg(i,pos,size)\t(cast(int, ((i)>>pos) & MASK1(size,0)))\n#define setarg(i,v,pos,size)\t((i) = (((i)&MASK0(size,pos)) | \\\n                ((cast(Instruction, v)<<pos)&MASK1(size,pos))))\n\n#define GETARG_A(i)\tgetarg(i, POS_A, SIZE_A)\n#define SETARG_A(i,v)\tsetarg(i, v, POS_A, SIZE_A)\n\n#define GETARG_B(i)\tgetarg(i, POS_B, SIZE_B)\n#define SETARG_B(i,v)\tsetarg(i, v, POS_B, SIZE_B)\n\n#define GETARG_C(i)\tgetarg(i, POS_C, SIZE_C)\n#define SETARG_C(i,v)\tsetarg(i, v, POS_C, SIZE_C)\n\n#define GETARG_Bx(i)\tgetarg(i, POS_Bx, SIZE_Bx)\n#define SETARG_Bx(i,v)\tsetarg(i, v, POS_Bx, SIZE_Bx)\n\n#define GETARG_Ax(i)\tgetarg(i, POS_Ax, SIZE_Ax)\n#define SETARG_Ax(i,v)\tsetarg(i, v, POS_Ax, SIZE_Ax)\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n#define CREATE_Ax(o,a)\t\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_Ax))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#if !defined(MAXINDEXRK)  /* (for debugging only) */\n#define MAXINDEXRK\t(BITRK - 1)\n#endif\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADKX,/*\tA \tR(A) := Kst(extra arg)\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A), R(A+1), ..., R(A+B) := nil\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETTABUP,/*\tA B C\tR(A) := UpValue[B][RK(C)]\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETTABUP,/*\tA B C\tUpValue[A][RK(B)] := RK(C)\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_IDIV,/*\tA B C\tR(A) := RK(B) // RK(C)\t\t\t\t*/\nOP_BAND,/*\tA B C\tR(A) := RK(B) & RK(C)\t\t\t\t*/\nOP_BOR,/*\tA B C\tR(A) := RK(B) | RK(C)\t\t\t\t*/\nOP_BXOR,/*\tA B C\tR(A) := RK(B) ~ RK(C)\t\t\t\t*/\nOP_SHL,/*\tA B C\tR(A) := RK(B) << RK(C)\t\t\t\t*/\nOP_SHR,/*\tA B C\tR(A) := RK(B) >> RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_BNOT,/*\tA B\tR(A) := ~R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tA sBx\tpc+=sBx; if (A) close all upvalues >= R(A - 1)\t*/\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++\t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++\t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/\nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/\n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORCALL,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));\t*/\nOP_TFORLOOP,/*\tA sBx\tif R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/\n\nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx])\t\t\t*/\n\nOP_VARARG,/*\tA B\tR(A), R(A+1), ..., R(A+B-2) = vararg\t\t*/\n\nOP_EXTRAARG/*\tAx\textra (larger) argument for previous opcode\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_EXTRAARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is\n  set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,\n  OP_SETLIST) may use 'top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n  set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to 'top'.\n\n  (*) In OP_SETLIST, if (B == 0) then B = 'top'; if (C == 0) then next\n  'instruction' is EXTRAARG(real C).\n\n  (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.\n\n  (*) For comparisons, A specifies what condition the test should accept\n  (true or false).\n\n  (*) All 'skips' (pc++) assume that next instruction is a jump.\n\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test (next instruction must be a jump)\n*/\n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.65 2016/07/18 17:58:58 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** {==================================================================\n** List of valid conversion specifiers for the 'strftime' function;\n** options are grouped by length; group of length 2 start with '||'.\n** ===================================================================\n*/\n#if !defined(LUA_STRFTIMEOPTIONS)\t/* { */\n\n/* options for ANSI C 89 (only 1-char options) */\n#define L_STRFTIMEC89\t\t\"aAbBcdHIjmMpSUwWxXyYZ%\"\n\n/* options for ISO C 99 and POSIX */\n#define L_STRFTIMEC99 \"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%\" \\\n    \"||\" \"EcECExEXEyEY\" \"OdOeOHOIOmOMOSOuOUOVOwOWOy\"  /* two-char options */\n\n/* options for Windows */\n#define L_STRFTIMEWIN \"aAbBcdHIjmMpSUwWxXyYzZ%\" \\\n    \"||\" \"#c#x#d#H#I#j#m#M#S#U#w#W#y#Y\"  /* two-char options */\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEWIN\n#elif defined(LUA_USE_C89)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC89\n#else  /* C99 specification */\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC99\n#endif\n\n#endif\t\t\t\t\t/* } */\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for time-related stuff\n** ===================================================================\n*/\n\n#if !defined(l_time_t)\t\t/* { */\n/*\n** type to represent time_t in Lua\n*/\n#define l_timet\t\t\tlua_Integer\n#define l_pushtime(L,t)\t\tlua_pushinteger(L,(lua_Integer)(t))\n\nstatic time_t l_checktime (lua_State *L, int arg) {\n  lua_Integer t = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, (time_t)t == t, arg, \"time out-of-bounds\");\n  return (time_t)t;\n}\n\n#endif\t\t\t\t/* } */\n\n\n#if !defined(l_gmtime)\t\t/* { */\n/*\n** By default, Lua uses gmtime/localtime, except when POSIX is available,\n** where it uses gmtime_r/localtime_r\n*/\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_gmtime(t,r)\t\tgmtime_r(t,r)\n#define l_localtime(t,r)\tlocaltime_r(t,r)\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_gmtime(t,r)\t\t((void)(r)->tm_sec, gmtime(t))\n#define l_localtime(t,r)  \t((void)(r)->tm_sec, localtime(t))\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for 'tmpnam':\n** By default, Lua uses tmpnam except when POSIX is available, where\n** it uses mkstemp.\n** ===================================================================\n*/\n#if !defined(lua_tmpnam)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n\n#define LUA_TMPNAMBUFSIZE\t32\n\n#if !defined(LUA_TMPNAMTEMPLATE)\n#define LUA_TMPNAMTEMPLATE\t\"/tmp/lua_XXXXXX\"\n#endif\n\n#define lua_tmpnam(b,e) { \\\n        strcpy(b, LUA_TMPNAMTEMPLATE); \\\n        e = mkstemp(b); \\\n        if (e != -1) close(e); \\\n        e = (e == -1); }\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n/* }================================================================== */\n\n\n\n\nstatic int os_execute (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *cmd = luaL_optstring(L, 1, NULL);\n  int stat = system(cmd);\n  if (cmd != NULL)\n    return luaL_execresult(L, stat);\n  else {\n    lua_pushboolean(L, stat);  /* true if there is a shell */\n    return 1;\n  }\n#endif\n}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\n\n/*\n** Set all fields from structure 'tm' in the table on top of the stack\n*/\nstatic void setallfields (lua_State *L, struct tm *stm) {\n  setfield(L, \"sec\", stm->tm_sec);\n  setfield(L, \"min\", stm->tm_min);\n  setfield(L, \"hour\", stm->tm_hour);\n  setfield(L, \"day\", stm->tm_mday);\n  setfield(L, \"month\", stm->tm_mon + 1);\n  setfield(L, \"year\", stm->tm_year + 1900);\n  setfield(L, \"wday\", stm->tm_wday + 1);\n  setfield(L, \"yday\", stm->tm_yday + 1);\n  setboolfield(L, \"isdst\", stm->tm_isdst);\n}\n\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\n/* maximum value for date fields (to avoid arithmetic overflows with 'int') */\n#if !defined(L_MAXDATEFIELD)\n#define L_MAXDATEFIELD\t(INT_MAX / 2)\n#endif\n\nstatic int getfield (lua_State *L, const char *key, int d, int delta) {\n  int isnum;\n  int t = lua_getfield(L, -1, key);  /* get field and its type */\n  lua_Integer res = lua_tointegerx(L, -1, &isnum);\n  if (!isnum) {  /* field is not an integer? */\n    if (t != LUA_TNIL)  /* some other value? */\n      return luaL_error(L, \"field '%s' is not an integer\", key);\n    else if (d < 0)  /* absent field; no default? */\n      return luaL_error(L, \"field '%s' missing in date table\", key);\n    res = d;\n  }\n  else {\n    if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))\n      return luaL_error(L, \"field '%s' is out-of-bound\", key);\n    res -= delta;\n  }\n  lua_pop(L, 1);\n  return (int)res;\n}\n\n\nstatic const char *checkoption (lua_State *L, const char *conv,\n                                ptrdiff_t convlen, char *buff) {\n  const char *option = LUA_STRFTIMEOPTIONS;\n  int oplen = 1;  /* length of options being checked */\n  for (; *option != '\\0' && oplen <= convlen; option += oplen) {\n    if (*option == '|')  /* next block? */\n      oplen++;  /* will check options with next length (+1) */\n    else if (memcmp(conv, option, oplen) == 0) {  /* match? */\n      memcpy(buff, conv, oplen);  /* copy valid option to buffer */\n      buff[oplen] = '\\0';\n      return conv + oplen;  /* return next item */\n    }\n  }\n  luaL_argerror(L, 1,\n    lua_pushfstring(L, \"invalid conversion specifier '%%%s'\", conv));\n  return conv;  /* to avoid warnings */\n}\n\n\n/* maximum size for an individual 'strftime' item */\n#define SIZETIMEFMT\t250\n\n\nstatic int os_date (lua_State *L) {\n  size_t slen;\n  const char *s = luaL_optlstring(L, 1, \"%c\", &slen);\n  time_t t = luaL_opt(L, l_checktime, 2, time(NULL));\n  const char *se = s + slen;  /* 's' end */\n  struct tm tmr, *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = l_gmtime(&t, &tmr);\n    s++;  /* skip '!' */\n  }\n  else\n    stm = l_localtime(&t, &tmr);\n  if (stm == NULL)  /* invalid date? */\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setallfields(L, stm);\n  }\n  else {\n    char cc[4];  /* buffer for individual conversion specifiers */\n    luaL_Buffer b;\n    cc[0] = '%';\n    luaL_buffinit(L, &b);\n    while (s < se) {\n      if (*s != '%')  /* not a conversion specifier? */\n        luaL_addchar(&b, *s++);\n      else {\n        size_t reslen;\n        char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);\n        s++;  /* skip '%' */\n        s = checkoption(L, s, se - s, cc + 1);  /* copy specifier to 'cc' */\n        reslen = strftime(buff, SIZETIMEFMT, cc, stm);\n        luaL_addsize(&b, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0, 0);\n    ts.tm_min = getfield(L, \"min\", 0, 0);\n    ts.tm_hour = getfield(L, \"hour\", 12, 0);\n    ts.tm_mday = getfield(L, \"day\", -1, 0);\n    ts.tm_mon = getfield(L, \"month\", -1, 1);\n    ts.tm_year = getfield(L, \"year\", -1, 1900);\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n    setallfields(L, &ts);  /* update fields with normalized values */\n  }\n  if (t != (time_t)(l_timet)t || t == (time_t)(-1))\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  l_pushtime(L, t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  time_t t1 = l_checktime(L, 1);\n  time_t t2 = l_checktime(L, 2);\n  lua_pushnumber(L, (lua_Number)difftime(t1, t2));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  int status;\n  if (lua_isboolean(L, 1))\n    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);\n  else\n    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);\n  if (lua_toboolean(L, 2))\n    lua_close(L);\n  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */\n  return 0;\n}\n\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  {\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUAMOD_API int luaopen_os (lua_State *L) {\n  luaL_newlib(L, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.155 2016/08/01 19:51:24 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n/* maximum number of local variables per function (must be smaller\n   than 250, due to the bytecode format) */\n#define MAXVARS\t\t200\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n\n/* because all strings are unified by the scanner, the parser\n   can use pointer equality for string equality */\n#define eqstr(a,b)\t((a) == (b))\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int firstlabel;  /* index of first label in this block */\n  int firstgoto;  /* index of first pending goto in this block */\n  lu_byte nactvar;  /* # active locals outside the block */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isloop;  /* true if 'block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void statement (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\n/* semantic error */\nstatic l_noret semerror (LexState *ls, const char *msg) {\n  ls->t.token = 0;  /* remove \"near <token>\" from final message */\n  luaX_syntaxerror(ls, msg);\n}\n\n\nstatic l_noret error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, \"%s expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic l_noret errorlimit (FuncState *fs, int limit, const char *what) {\n  lua_State *L = fs->ls->L;\n  const char *msg;\n  int line = fs->f->linedefined;\n  const char *where = (line == 0)\n                      ? \"main function\"\n                      : luaO_pushfstring(L, \"function at line %d\", line);\n  msg = luaO_pushfstring(L, \"too many %s (limit is %d) in %s\",\n                             what, limit, where);\n  luaX_syntaxerror(fs->ls, msg);\n}\n\n\nstatic void checklimit (FuncState *fs, int v, int l, const char *what) {\n  if (v > l) errorlimit(fs, l, what);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             \"%s expected (to close %s at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname (LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"local variables\");\n  while (oldsize < f->sizelocvars)\n    f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\nstatic void new_localvar (LexState *ls, TString *name) {\n  FuncState *fs = ls->fs;\n  Dyndata *dyd = ls->dyd;\n  int reg = registerlocalvar(ls, name);\n  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,\n                  MAXVARS, \"local variables\");\n  luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,\n                  dyd->actvar.size, Vardesc, MAX_INT, \"local variables\");\n  dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);\n}\n\n\nstatic void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {\n  new_localvar(ls, luaX_newstring(ls, name, sz));\n}\n\n#define new_localvarliteral(ls,v) \\\n\tnew_localvarliteral_(ls, \"\" v, (sizeof(v)/sizeof(char))-1)\n\n\nstatic LocVar *getlocvar (FuncState *fs, int i) {\n  int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;\n  lua_assert(idx < fs->nlocvars);\n  return &fs->f->locvars[idx];\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (FuncState *fs, int tolevel) {\n  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar)->endpc = fs->pc;\n}\n\n\nstatic int searchupvalue (FuncState *fs, TString *name) {\n  int i;\n  Upvaldesc *up = fs->f->upvalues;\n  for (i = 0; i < fs->nups; i++) {\n    if (eqstr(up[i].name, name)) return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic int newupvalue (FuncState *fs, TString *name, expdesc *v) {\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  checklimit(fs, fs->nups + 1, MAXUPVAL, \"upvalues\");\n  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,\n                  Upvaldesc, MAXUPVAL, \"upvalues\");\n  while (oldsize < f->sizeupvalues)\n    f->upvalues[oldsize++].name = NULL;\n  f->upvalues[fs->nups].instack = (v->k == VLOCAL);\n  f->upvalues[fs->nups].idx = cast_byte(v->u.info);\n  f->upvalues[fs->nups].name = name;\n  luaC_objbarrier(fs->ls->L, f, name);\n  return fs->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {\n    if (eqstr(n, getlocvar(fs, i)->varname))\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\n/*\n  Mark block where variable at given level was defined\n  (to emit close instructions later).\n*/\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl->nactvar > level)\n    bl = bl->previous;\n  bl->upval = 1;\n}\n\n\n/*\n  Find variable with given name 'n'. If it is an upvalue, add this\n  upvalue into all intermediate functions.\n*/\nstatic void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL)  /* no more levels? */\n    init_exp(var, VVOID, 0);  /* default is global */\n  else {\n    int v = searchvar(fs, n);  /* look up locals at current level */\n    if (v >= 0) {  /* found? */\n      init_exp(var, VLOCAL, v);  /* variable is local */\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n    }\n    else {  /* not found as local at current level; try upvalues */\n      int idx = searchupvalue(fs, n);  /* try existing upvalues */\n      if (idx < 0) {  /* not found? */\n        singlevaraux(fs->prev, n, var, 0);  /* try upper levels */\n        if (var->k == VVOID)  /* not found? */\n          return;  /* it is a global */\n        /* else was LOCAL or UPVAL */\n        idx  = newupvalue(fs, n, var);  /* will be a new upvalue */\n      }\n      init_exp(var, VUPVAL, idx);  /* new or old upvalue */\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  singlevaraux(fs, varname, var, 1);\n  if (var->k == VVOID) {  /* global name? */\n    expdesc key;\n    singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */\n    lua_assert(var->k != VVOID);  /* this one must exist */\n    codestring(ls, &key, varname);  /* key is variable name */\n    luaK_indexed(fs, var, &key);  /* env[varname] */\n  }\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n  if (nexps > nvars)\n    ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  lua_State *L = ls->L;\n  ++L->nCcalls;\n  checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, \"C levels\");\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void closegoto (LexState *ls, int g, Labeldesc *label) {\n  int i;\n  FuncState *fs = ls->fs;\n  Labellist *gl = &ls->dyd->gt;\n  Labeldesc *gt = &gl->arr[g];\n  lua_assert(eqstr(gt->name, label->name));\n  if (gt->nactvar < label->nactvar) {\n    TString *vname = getlocvar(fs, gt->nactvar)->varname;\n    const char *msg = luaO_pushfstring(ls->L,\n      \"<goto %s> at line %d jumps into the scope of local '%s'\",\n      getstr(gt->name), gt->line, getstr(vname));\n    semerror(ls, msg);\n  }\n  luaK_patchlist(fs, gt->pc, label->pc);\n  /* remove goto from pending list */\n  for (i = g; i < gl->n - 1; i++)\n    gl->arr[i] = gl->arr[i + 1];\n  gl->n--;\n}\n\n\n/*\n** try to close a goto with existing labels; this solves backward jumps\n*/\nstatic int findlabel (LexState *ls, int g) {\n  int i;\n  BlockCnt *bl = ls->fs->bl;\n  Dyndata *dyd = ls->dyd;\n  Labeldesc *gt = &dyd->gt.arr[g];\n  /* check labels in current block for a match */\n  for (i = bl->firstlabel; i < dyd->label.n; i++) {\n    Labeldesc *lb = &dyd->label.arr[i];\n    if (eqstr(lb->name, gt->name)) {  /* correct label? */\n      if (gt->nactvar > lb->nactvar &&\n          (bl->upval || dyd->label.n > bl->firstlabel))\n        luaK_patchclose(ls->fs, gt->pc, lb->nactvar);\n      closegoto(ls, g, lb);  /* close it */\n      return 1;\n    }\n  }\n  return 0;  /* label not found; cannot close goto */\n}\n\n\nstatic int newlabelentry (LexState *ls, Labellist *l, TString *name,\n                          int line, int pc) {\n  int n = l->n;\n  luaM_growvector(ls->L, l->arr, n, l->size,\n                  Labeldesc, SHRT_MAX, \"labels/gotos\");\n  l->arr[n].name = name;\n  l->arr[n].line = line;\n  l->arr[n].nactvar = ls->fs->nactvar;\n  l->arr[n].pc = pc;\n  l->n = n + 1;\n  return n;\n}\n\n\n/*\n** check whether new label 'lb' matches any pending gotos in current\n** block; solves forward jumps\n*/\nstatic void findgotos (LexState *ls, Labeldesc *lb) {\n  Labellist *gl = &ls->dyd->gt;\n  int i = ls->fs->bl->firstgoto;\n  while (i < gl->n) {\n    if (eqstr(gl->arr[i].name, lb->name))\n      closegoto(ls, i, lb);\n    else\n      i++;\n  }\n}\n\n\n/*\n** export pending gotos to outer level, to check them against\n** outer labels; if the block being exited has upvalues, and\n** the goto exits the scope of any variable (which can be the\n** upvalue), close those variables being exited.\n*/\nstatic void movegotosout (FuncState *fs, BlockCnt *bl) {\n  int i = bl->firstgoto;\n  Labellist *gl = &fs->ls->dyd->gt;\n  /* correct pending gotos to current block and try to close it\n     with visible labels */\n  while (i < gl->n) {\n    Labeldesc *gt = &gl->arr[i];\n    if (gt->nactvar > bl->nactvar) {\n      if (bl->upval)\n        luaK_patchclose(fs, gt->pc, bl->nactvar);\n      gt->nactvar = bl->nactvar;\n    }\n    if (!findlabel(fs->ls, i))\n      i++;  /* move to next one */\n  }\n}\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {\n  bl->isloop = isloop;\n  bl->nactvar = fs->nactvar;\n  bl->firstlabel = fs->ls->dyd->label.n;\n  bl->firstgoto = fs->ls->dyd->gt.n;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\n/*\n** create a label named 'break' to resolve break statements\n*/\nstatic void breaklabel (LexState *ls) {\n  TString *n = luaS_new(ls->L, \"break\");\n  int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);\n  findgotos(ls, &ls->dyd->label.arr[l]);\n}\n\n/*\n** generates an error for an undefined 'goto'; choose appropriate\n** message when label name is a reserved word (which can only be 'break')\n*/\nstatic l_noret undefgoto (LexState *ls, Labeldesc *gt) {\n  const char *msg = isreserved(gt->name)\n                    ? \"<%s> at line %d not inside a loop\"\n                    : \"no visible label '%s' for <goto> at line %d\";\n  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);\n  semerror(ls, msg);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  LexState *ls = fs->ls;\n  if (bl->previous && bl->upval) {\n    /* create a 'jump to here' to close upvalues */\n    int j = luaK_jump(fs);\n    luaK_patchclose(fs, j, bl->nactvar);\n    luaK_patchtohere(fs, j);\n  }\n  if (bl->isloop)\n    breaklabel(ls);  /* close pending breaks */\n  fs->bl = bl->previous;\n  removevars(fs, bl->nactvar);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  ls->dyd->label.n = bl->firstlabel;  /* remove local labels */\n  if (bl->previous)  /* inner block? */\n    movegotosout(fs, bl);  /* update pending gotos to outer block */\n  else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */\n    undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */\n}\n\n\n/*\n** adds a new prototype into list of prototypes\n*/\nstatic Proto *addprototype (LexState *ls) {\n  Proto *clp;\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;  /* prototype of current function */\n  if (fs->np >= f->sizep) {\n    int oldsize = f->sizep;\n    luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, \"functions\");\n    while (oldsize < f->sizep)\n      f->p[oldsize++] = NULL;\n  }\n  f->p[fs->np++] = clp = luaF_newproto(L);\n  luaC_objbarrier(L, f, clp);\n  return clp;\n}\n\n\n/*\n** codes instruction to create new closure in parent function.\n** The OP_CLOSURE instruction must use the last available register,\n** so that, if it invokes the GC, the GC knows which registers\n** are in use at that time.\n*/\nstatic void codeclosure (LexState *ls, expdesc *v) {\n  FuncState *fs = ls->fs->prev;\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));\n  luaK_exp2nextreg(fs, v);  /* fix it at the last register */\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {\n  Proto *f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nups = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->firstlocal = ls->dyd->actvar.n;\n  fs->bl = NULL;\n  f = fs->f;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  enterblock(fs, bl, 0);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  luaK_ret(fs, 0, 0);  /* final return */\n  leaveblock(fs);\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);\n  f->sizeupvalues = fs->nups;\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  luaC_checkGC(L);\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\n/*\n** check whether current token is in the follow set of a block.\n** 'until' closes syntactical blocks, but do not close scope,\n** so it is handled in separate.\n*/\nstatic int block_follow (LexState *ls, int withuntil) {\n  switch (ls->t.token) {\n    case TK_ELSE: case TK_ELSEIF:\n    case TK_END: case TK_EOS:\n      return 1;\n    case TK_UNTIL: return withuntil;\n    default: return 0;\n  }\n}\n\n\nstatic void statlist (LexState *ls) {\n  /* statlist -> { stat [';'] } */\n  while (!block_follow(ls, 1)) {\n    if (ls->t.token == TK_RETURN) {\n      statement(ls);\n      return;  /* 'return' must be last statement */\n    }\n    statement(ls);\n  }\n}\n\n\nstatic void fieldsel (LexState *ls, expdesc *v) {\n  /* fieldsel -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyregup(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of 'record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | '['exp1']') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  /* listfield -> exp */\n  expr(ls, &cc->v);\n  checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void field (LexState *ls, struct ConsControl *cc) {\n  /* field -> listfield | recfield */\n  switch(ls->t.token) {\n    case TK_NAME: {  /* may be 'listfield' or 'recfield' */\n      if (luaX_lookahead(ls) != '=')  /* expression? */\n        listfield(ls, cc);\n      else\n        recfield(ls, cc);\n      break;\n    }\n    case '[': {\n      recfield(ls, cc);\n      break;\n    }\n    default: {\n      listfield(ls, cc);\n      break;\n    }\n  }\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> '{' [ field { sep field } [sep] ] '}'\n     sep -> ',' | ';' */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    field(ls, &cc);\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { ',' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is 'parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls));\n          nparams++;\n          break;\n        }\n        case TK_DOTS: {  /* param -> '...' */\n          luaX_next(ls);\n          f->is_vararg = 1;  /* declared vararg */\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or '...' expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar);\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int ismethod, int line) {\n  /* body ->  '(' parlist ')' block END */\n  FuncState new_fs;\n  BlockCnt bl;\n  new_fs.f = addprototype(ls);\n  new_fs.f->linedefined = line;\n  open_func(ls, &new_fs, &bl);\n  checknext(ls, '(');\n  if (ismethod) {\n    new_localvarliteral(ls, \"self\");  /* create 'self' parameter */\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  statlist(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  codeclosure(ls, e);\n  close_func(ls);\n}\n\n\nstatic int explist (LexState *ls, expdesc *v) {\n  /* explist -> expr { ',' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f, int line) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> '(' [ explist ] ')' */\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use 'seminfo' before 'next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n    }\n  }\n}\n\n\nstatic void suffixedexp (LexState *ls, expdesc *v) {\n  /* suffixedexp ->\n       primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  primaryexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* fieldsel */\n        fieldsel(ls, v);\n        break;\n      }\n      case '[': {  /* '[' exp1 ']' */\n        expdesc key;\n        luaK_exp2anyregup(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* ':' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v, line);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v, line);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |\n                  constructor | FUNCTION body | suffixedexp */\n  switch (ls->t.token) {\n    case TK_FLT: {\n      init_exp(v, VKFLT, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_INT: {\n      init_exp(v, VKINT, 0);\n      v->u.ival = ls->t.seminfo.i;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use '...' outside a vararg function\");\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      suffixedexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '~': return OPR_BNOT;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case '/': return OPR_DIV;\n    case TK_IDIV: return OPR_IDIV;\n    case '&': return OPR_BAND;\n    case '|': return OPR_BOR;\n    case '~': return OPR_BXOR;\n    case TK_SHL: return OPR_SHL;\n    case TK_SHR: return OPR_SHR;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {10, 10}, {10, 10},           /* '+' '-' */\n   {11, 11}, {11, 11},           /* '*' '%' */\n   {14, 13},                  /* '^' (right associative) */\n   {11, 11}, {11, 11},           /* '/' '//' */\n   {6, 6}, {4, 4}, {5, 5},   /* '&' '|' '~' */\n   {7, 7}, {7, 7},           /* '<<' '>>' */\n   {9, 8},                   /* '..' (right associative) */\n   {3, 3}, {3, 3}, {3, 3},   /* ==, <, <= */\n   {3, 3}, {3, 3}, {3, 3},   /* ~=, >, >= */\n   {2, 2}, {1, 1}            /* and, or */\n};\n\n#define UNARY_PRIORITY\t12  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where 'binop' is any binary operator with a priority higher than 'limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    int line = ls->linenumber;\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v, line);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than 'limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    int line = ls->linenumber;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2, line);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic void block (LexState *ls) {\n  /* block -> statlist */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  statlist(ls);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to an upvalue/local variable, the\n** upvalue/local variable is begin used in a previous assignment to a\n** table. If so, save original upvalue/local value in a safe place and\n** use this safe copy in the previous assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {  /* check all previous assignments */\n    if (lh->v.k == VINDEXED) {  /* assigning to a table? */\n      /* table is the upvalue/local being assigned now? */\n      if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.vt = VLOCAL;\n        lh->v.u.ind.t = extra;  /* previous assignment will use safe copy */\n      }\n      /* index is the local being assigned? (index cannot be upvalue) */\n      if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.idx = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    /* copy upvalue/local value to a temporary (in position 'extra') */\n    OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, op, extra, v->u.info, 0);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, vkisvar(lh->v.k), \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> ',' suffixedexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    suffixedexp(ls, &nv.v);\n    if (nv.v.k != VINDEXED)\n      check_conflict(ls, lh, &nv.v);\n    checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,\n                    \"C levels\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> '=' explist */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist(ls, &e);\n    if (nexps != nvars)\n      adjust_assign(ls, nvars, nexps, &e);\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* 'falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void gotostat (LexState *ls, int pc) {\n  int line = ls->linenumber;\n  TString *label;\n  int g;\n  if (testnext(ls, TK_GOTO))\n    label = str_checkname(ls);\n  else {\n    luaX_next(ls);  /* skip break */\n    label = luaS_new(ls->L, \"break\");\n  }\n  g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);\n  findlabel(ls, g);  /* close it if label already defined */\n}\n\n\n/* check for repeated labels on the same block */\nstatic void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {\n  int i;\n  for (i = fs->bl->firstlabel; i < ll->n; i++) {\n    if (eqstr(label, ll->arr[i].name)) {\n      const char *msg = luaO_pushfstring(fs->ls->L,\n                          \"label '%s' already defined on line %d\",\n                          getstr(label), ll->arr[i].line);\n      semerror(fs->ls, msg);\n    }\n  }\n}\n\n\n/* skip no-op statements */\nstatic void skipnoopstat (LexState *ls) {\n  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)\n    statement(ls);\n}\n\n\nstatic void labelstat (LexState *ls, TString *label, int line) {\n  /* label -> '::' NAME '::' */\n  FuncState *fs = ls->fs;\n  Labellist *ll = &ls->dyd->label;\n  int l;  /* index of new label being created */\n  checkrepeated(fs, ll, label);  /* check for repeated labels */\n  checknext(ls, TK_DBCOLON);  /* skip double colon */\n  /* create new entry for this label */\n  l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));\n  skipnoopstat(ls);  /* skip other no-op statements */\n  if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */\n    /* assume that locals are already out of scope */\n    ll->arr[l].nactvar = fs->bl->nactvar;\n  }\n  findgotos(ls, &ll->arr[l]);\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_jumpto(fs, whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  statlist(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (bl2.upval)  /* upvalues? */\n    luaK_patchclose(fs, condexit, bl2.nactvar);\n  leaveblock(fs);  /* finish scope */\n  luaK_patchlist(fs, condexit, repeat_init);  /* close the loop */\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int reg;\n  expr(ls, &e);\n  luaK_exp2nextreg(ls->fs, &e);\n  lua_assert(e.k == VNONRELOC);\n  reg = e.u.info;\n  return reg;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  if (isnum)  /* numeric for? */\n    endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);\n  else {  /* generic for */\n    luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);\n    luaK_fixline(fs, line);\n    endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);\n  }\n  luaK_patchlist(fs, endfor, prep + 1);\n  luaK_fixline(fs, line);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\");\n  new_localvarliteral(ls, \"(for limit)\");\n  new_localvarliteral(ls, \"(for step)\");\n  new_localvar(ls, varname);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codek(fs, fs->freereg, luaK_intK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 4;  /* gen, state, control, plus at least one declared var */\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for control)\");\n  /* create declared variables */\n  new_localvar(ls, indexname);\n  while (testnext(ls, ',')) {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  }\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip 'for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, \"'=' or 'in' expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope ('break' jumps to this point) */\n}\n\n\nstatic void test_then_block (LexState *ls, int *escapelist) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  expdesc v;\n  int jf;  /* instruction to skip 'then' code (if condition is false) */\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  expr(ls, &v);  /* read condition */\n  checknext(ls, TK_THEN);\n  if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {\n    luaK_goiffalse(ls->fs, &v);  /* will jump to label if condition is true */\n    enterblock(fs, &bl, 0);  /* must enter block before 'goto' */\n    gotostat(ls, v.t);  /* handle goto/break */\n    skipnoopstat(ls);  /* skip other no-op statements */\n    if (block_follow(ls, 0)) {  /* 'goto' is the entire block? */\n      leaveblock(fs);\n      return;  /* and that is it */\n    }\n    else  /* must skip over 'then' part if condition is false */\n      jf = luaK_jump(fs);\n  }\n  else {  /* regular case (not goto/break) */\n    luaK_goiftrue(ls->fs, &v);  /* skip over block if condition is false */\n    enterblock(fs, &bl, 0);\n    jf = v.f;\n  }\n  statlist(ls);  /* 'then' part */\n  leaveblock(fs);\n  if (ls->t.token == TK_ELSE ||\n      ls->t.token == TK_ELSEIF)  /* followed by 'else'/'elseif'? */\n    luaK_concat(fs, escapelist, luaK_jump(fs));  /* must jump over it */\n  luaK_patchtohere(fs, jf);\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int escapelist = NO_JUMP;  /* exit list for finished parts */\n  test_then_block(ls, &escapelist);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF)\n    test_then_block(ls, &escapelist);  /* ELSEIF cond THEN block */\n  if (testnext(ls, TK_ELSE))\n    block(ls);  /* 'else' part */\n  check_match(ls, TK_END, TK_IF, line);\n  luaK_patchtohere(fs, escapelist);  /* patch escape list to 'if' end */\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls));  /* new local variable */\n  adjustlocalvars(ls, 1);  /* enter its scope */\n  body(ls, &b, 0, ls->linenumber);  /* function created in next register */\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, b.u.info)->startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {',' NAME} ['=' explist] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {fieldsel} [':' NAME] */\n  int ismethod = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    fieldsel(ls, v);\n  if (ls->t.token == ':') {\n    ismethod = 1;\n    fieldsel(ls, v);\n  }\n  return ismethod;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int ismethod;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  ismethod = funcname(ls, &v);\n  body(ls, &b, ismethod, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition \"happens\" in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  suffixedexp(ls, &v.v);\n  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n  else {  /* stat -> func */\n    check_condition(ls, v.v.k == VCALL, \"syntax error\");\n    SETARG_C(getinstruction(fs, &v.v), 1);  /* call statement uses no results */\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN [explist] [';'] */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  if (block_follow(ls, 1) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the stack */\n        first = fs->nactvar;  /* return all active values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n  testnext(ls, ';');  /* skip optional semicolon */\n}\n\n\nstatic void statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  enterlevel(ls);\n  switch (ls->t.token) {\n    case ';': {  /* stat -> ';' (empty statement) */\n      luaX_next(ls);  /* skip ';' */\n      break;\n    }\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      break;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      break;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      break;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      break;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      break;\n    }\n    case TK_FUNCTION: {  /* stat -> funcstat */\n      funcstat(ls, line);\n      break;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      break;\n    }\n    case TK_DBCOLON: {  /* stat -> label */\n      luaX_next(ls);  /* skip double colon */\n      labelstat(ls, str_checkname(ls), line);\n      break;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      luaX_next(ls);  /* skip RETURN */\n      retstat(ls);\n      break;\n    }\n    case TK_BREAK:   /* stat -> breakstat */\n    case TK_GOTO: {  /* stat -> 'goto' NAME */\n      gotostat(ls, luaK_jump(ls->fs));\n      break;\n    }\n    default: {  /* stat -> func | assignment */\n      exprstat(ls);\n      break;\n    }\n  }\n  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n             ls->fs->freereg >= ls->fs->nactvar);\n  ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n\n\n/*\n** compiles the main function, which is a regular vararg function with an\n** upvalue named LUA_ENV\n*/\nstatic void mainfunc (LexState *ls, FuncState *fs) {\n  BlockCnt bl;\n  expdesc v;\n  open_func(ls, fs, &bl);\n  fs->f->is_vararg = 1;  /* main function is always declared vararg */\n  init_exp(&v, VLOCAL, 0);  /* create and... */\n  newupvalue(fs, ls->envn, &v);  /* ...set environment upvalue */\n  luaX_next(ls);  /* read first token */\n  statlist(ls);  /* parse main body */\n  check(ls, TK_EOS);\n  close_func(ls);\n}\n\n\nLClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                       Dyndata *dyd, const char *name, int firstchar) {\n  LexState lexstate;\n  FuncState funcstate;\n  LClosure *cl = luaF_newLclosure(L, 1);  /* create main closure */\n  setclLvalue(L, L->top, cl);  /* anchor it (to avoid being collected) */\n  luaD_inctop(L);\n  lexstate.h = luaH_new(L);  /* create table for scanner */\n  sethvalue(L, L->top, lexstate.h);  /* anchor it */\n  luaD_inctop(L);\n  funcstate.f = cl->p = luaF_newproto(L);\n  funcstate.f->source = luaS_new(L, name);  /* create and anchor TString */\n  lua_assert(iswhite(funcstate.f));  /* do not need barrier here */\n  lexstate.buff = buff;\n  lexstate.dyd = dyd;\n  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;\n  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);\n  mainfunc(&lexstate, &funcstate);\n  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);\n  /* all scopes should be correctly finished */\n  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);\n  L->top--;  /* remove scanner's table */\n  return cl;  /* closure is on the stack, too */\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression and variable descriptor.\n** Code generation for variables and expressions can be delayed to allow\n** optimizations; An 'expdesc' structure describes a potentially-delayed\n** variable/expression. It has a description of its \"main\" value plus a\n** list of conditional jumps that can also produce its value (generated\n** by short-circuit operators 'and'/'or').\n*/\n\n/* kinds of variables/expressions */\ntypedef enum {\n  VVOID,  /* when 'expdesc' describes the last expression a list,\n             this kind means an empty list (so, no expression) */\n  VNIL,  /* constant nil */\n  VTRUE,  /* constant true */\n  VFALSE,  /* constant false */\n  VK,  /* constant in 'k'; info = index of constant in 'k' */\n  VKFLT,  /* floating constant; nval = numerical float value */\n  VKINT,  /* integer constant; nval = numerical integer value */\n  VNONRELOC,  /* expression has its value in a fixed register;\n                 info = result register */\n  VLOCAL,  /* local variable; info = local register */\n  VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */\n  VINDEXED,  /* indexed variable;\n                ind.vt = whether 't' is register or upvalue;\n                ind.t = table register or upvalue;\n                ind.idx = key's R/K index */\n  VJMP,  /* expression is a test/comparison;\n            info = pc of corresponding jump instruction */\n  VRELOCABLE,  /* expression can put result in any register;\n                  info = instruction pc */\n  VCALL,  /* expression is a function call; info = instruction pc */\n  VVARARG  /* vararg expression; info = instruction pc */\n} expkind;\n\n\n#define vkisvar(k)\t(VLOCAL <= (k) && (k) <= VINDEXED)\n#define vkisinreg(k)\t((k) == VNONRELOC || (k) == VLOCAL)\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    lua_Integer ival;    /* for VKINT */\n    lua_Number nval;  /* for VKFLT */\n    int info;  /* for generic use */\n    struct {  /* for indexed variables (VINDEXED) */\n      short idx;  /* index (R/K) */\n      lu_byte t;  /* table (register or upvalue) */\n      lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */\n    } ind;\n  } u;\n  int t;  /* patch list of 'exit when true' */\n  int f;  /* patch list of 'exit when false' */\n} expdesc;\n\n\n/* description of active local variable */\ntypedef struct Vardesc {\n  short idx;  /* variable index in stack */\n} Vardesc;\n\n\n/* description of pending goto statements and label statements */\ntypedef struct Labeldesc {\n  TString *name;  /* label identifier */\n  int pc;  /* position in code */\n  int line;  /* line where it appeared */\n  lu_byte nactvar;  /* local level where it appears in current block */\n} Labeldesc;\n\n\n/* list of labels or gotos */\ntypedef struct Labellist {\n  Labeldesc *arr;  /* array */\n  int n;  /* number of entries in use */\n  int size;  /* array size */\n} Labellist;\n\n\n/* dynamic structures used by the parser */\ntypedef struct Dyndata {\n  struct {  /* list of active local variables */\n    Vardesc *arr;\n    int n;\n    int size;\n  } actvar;\n  Labellist gt;  /* list of pending gotos */\n  Labellist label;   /* list of active labels */\n} Dyndata;\n\n\n/* control of blocks */\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to 'ncode') */\n  int lasttarget;   /* 'label' of last 'jump label' */\n  int jpc;  /* list of pending jumps to 'pc' */\n  int nk;  /* number of elements in 'k' */\n  int np;  /* number of elements in 'p' */\n  int firstlocal;  /* index of first local var (in Dyndata array) */\n  short nlocvars;  /* number of elements in 'f->locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  lu_byte nups;  /* number of upvalues */\n  lu_byte freereg;  /* first free register */\n} FuncState;\n\n\nLUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                 Dyndata *dyd, const char *name, int firstchar);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lprefix.h",
    "content": "/*\n** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $\n** Definitions for Lua code that must come before any other header file\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lprefix_h\n#define lprefix_h\n\n\n/*\n** Allows POSIX/XSI stuff\n*/\n#if !defined(LUA_USE_C89)\t/* { */\n\n#if !defined(_XOPEN_SOURCE)\n#define _XOPEN_SOURCE           600\n#elif _XOPEN_SOURCE == 0\n#undef _XOPEN_SOURCE  /* use -D_XOPEN_SOURCE=0 to undefine it */\n#endif\n\n/*\n** Allows manipulation of large files in gcc and some other compilers\n*/\n#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)\n#define _LARGEFILE_SOURCE       1\n#define _FILE_OFFSET_BITS       64\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Windows stuff\n*/\n#if defined(_WIN32) \t/* { */\n\n#if !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS  /* avoid warnings about ISO C functions */\n#endif\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUAI_GCPAUSE)\n#define LUAI_GCPAUSE\t200  /* 200% */\n#endif\n\n#if !defined(LUAI_GCMUL)\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n#endif\n\n\n/*\n** a macro to help the creation of a unique random seed when a state is\n** created; the seed is used to randomize hashes.\n*/\n#if !defined(luai_makeseed)\n#include <time.h>\n#define luai_makeseed()\t\tcast(unsigned int, time(NULL))\n#endif\n\n\n\n/*\n** thread state + extra space\n*/\ntypedef struct LX {\n  lu_byte extra_[LUA_EXTRASPACE];\n  lua_State l;\n} LX;\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  LX l;\n  global_State g;\n} LG;\n\n\n\n#define fromstate(L)\t(cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))\n\n\n/*\n** Compute an initial seed as random as possible. Rely on Address Space\n** Layout Randomization (if present) to increase randomness..\n*/\n#define addbuff(b,p,e) \\\n  { size_t t = cast(size_t, e); \\\n    memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }\n\nstatic unsigned int makeseed (lua_State *L) {\n  char buff[4 * sizeof(size_t)];\n  unsigned int h = luai_makeseed();\n  int p = 0;\n  addbuff(buff, p, L);  /* heap variable */\n  addbuff(buff, p, &h);  /* local variable */\n  addbuff(buff, p, luaO_nilobject);  /* global variable */\n  addbuff(buff, p, &lua_newstate);  /* public function */\n  lua_assert(p == sizeof(buff));\n  return luaS_hash(buff, p, h);\n}\n\n\n/*\n** set GCdebt to a new value keeping the value (totalbytes + GCdebt)\n** invariant (and avoiding underflows in 'totalbytes')\n*/\nvoid luaE_setdebt (global_State *g, l_mem debt) {\n  l_mem tb = gettotalbytes(g);\n  lua_assert(tb > 0);\n  if (debt < tb - MAX_LMEM)\n    debt = tb - MAX_LMEM;  /* will make 'totalbytes == MAX_LMEM' */\n  g->totalbytes = tb - debt;\n  g->GCdebt = debt;\n}\n\n\nCallInfo *luaE_extendCI (lua_State *L) {\n  CallInfo *ci = luaM_new(L, CallInfo);\n  lua_assert(L->ci->next == NULL);\n  L->ci->next = ci;\n  ci->previous = L->ci;\n  ci->next = NULL;\n  L->nci++;\n  return ci;\n}\n\n\n/*\n** free all CallInfo structures not in use by a thread\n*/\nvoid luaE_freeCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next = ci->next;\n  ci->next = NULL;\n  while ((ci = next) != NULL) {\n    next = ci->next;\n    luaM_free(L, ci);\n    L->nci--;\n  }\n}\n\n\n/*\n** free half of the CallInfo structures not in use by a thread\n*/\nvoid luaE_shrinkCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next2;  /* next's next */\n  /* while there are two nexts */\n  while (ci->next != NULL && (next2 = ci->next->next) != NULL) {\n    luaM_free(L, ci->next);  /* free next */\n    L->nci--;\n    ci->next = next2;  /* remove 'next' from the list */\n    next2->previous = ci;\n    ci = next2;  /* keep next's next */\n  }\n}\n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  int i; CallInfo *ci;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);\n  L1->stacksize = BASIC_STACK_SIZE;\n  for (i = 0; i < BASIC_STACK_SIZE; i++)\n    setnilvalue(L1->stack + i);  /* erase new stack */\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;\n  /* initialize first ci */\n  ci = &L1->base_ci;\n  ci->next = ci->previous = NULL;\n  ci->callstatus = 0;\n  ci->func = L1->top;\n  setnilvalue(L1->top++);  /* 'function' entry for this 'ci' */\n  ci->top = L1->top + LUA_MINSTACK;\n  L1->ci = ci;\n}\n\n\nstatic void freestack (lua_State *L) {\n  if (L->stack == NULL)\n    return;  /* stack not completely built yet */\n  L->ci = &L->base_ci;  /* free the entire 'ci' list */\n  luaE_freeCI(L);\n  lua_assert(L->nci == 0);\n  luaM_freearray(L, L->stack, L->stacksize);  /* free stack array */\n}\n\n\n/*\n** Create registry table and its predefined values\n*/\nstatic void init_registry (lua_State *L, global_State *g) {\n  TValue temp;\n  /* create registry */\n  Table *registry = luaH_new(L);\n  sethvalue(L, &g->l_registry, registry);\n  luaH_resize(L, registry, LUA_RIDX_LAST, 0);\n  /* registry[LUA_RIDX_MAINTHREAD] = L */\n  setthvalue(L, &temp, L);  /* temp = L */\n  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);\n  /* registry[LUA_RIDX_GLOBALS] = table of globals */\n  sethvalue(L, &temp, luaH_new(L));  /* temp = new table (global table) */\n  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);\n}\n\n\n/*\n** open parts of the state that may cause memory-allocation errors.\n** ('g->version' != NULL flags that the state was completely build)\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  init_registry(L, g);\n  luaS_init(L);\n  luaT_init(L);\n  luaX_init(L);\n  g->gcrunning = 1;  /* allow gc */\n  g->version = lua_version(NULL);\n  luai_userstateopen(L);\n}\n\n\n/*\n** preinitialize a thread with consistent values without allocating\n** any memory (to avoid errors)\n*/\nstatic void preinit_thread (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->ci = NULL;\n  L->nci = 0;\n  L->stacksize = 0;\n  L->twups = L;  /* thread has no upvalues */\n  L->errorJmp = NULL;\n  L->nCcalls = 0;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->nny = 1;\n  L->status = LUA_OK;\n  L->errfunc = 0;\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeallobjects(L);  /* collect all objects */\n  if (g->version)  /* closing a fully built state? */\n    luai_userstateclose(L);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);\n  freestack(L);\n  lua_assert(gettotalbytes(g) == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);  /* free main block */\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  global_State *g = G(L);\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  /* create new thread */\n  L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;\n  L1->marked = luaC_white(g);\n  L1->tt = LUA_TTHREAD;\n  /* link it on list 'allgc' */\n  L1->next = g->allgc;\n  g->allgc = obj2gco(L1);\n  /* anchor it on L stack */\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  preinit_thread(L1, g);\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  /* initialize L1 extra space */\n  memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread),\n         LUA_EXTRASPACE);\n  luai_userstatethread(L, L1);\n  stack_init(L1, L);  /* init stack */\n  lua_unlock(L);\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  LX *l = fromstate(L1);\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L, L1);\n  freestack(L1);\n  luaM_free(L, l);\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));\n  if (l == NULL) return NULL;\n  L = &l->l.l;\n  g = &l->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bitmask(WHITE0BIT);\n  L->marked = luaC_white(g);\n  preinit_thread(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->seed = makeseed(L);\n  g->gcrunning = 0;  /* no GC while building state */\n  g->GCestimate = 0;\n  g->strt.size = g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(&g->l_registry);\n  g->panic = NULL;\n  g->version = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_NORMAL;\n  g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL;\n  g->sweepgc = NULL;\n  g->gray = g->grayagain = NULL;\n  g->weak = g->ephemeron = g->allweak = NULL;\n  g->twups = NULL;\n  g->totalbytes = sizeof(LG);\n  g->GCdebt = 0;\n  g->gcfinnum = 0;\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  return L;\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  close_state(L);\n}\n\n\n"
  },
  {
    "path": "WebGLPlugins/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.133 2016/12/22 13:08:50 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n/*\n\n** Some notes about garbage-collected objects: All objects in Lua must\n** be kept somehow accessible until being freed, so all objects always\n** belong to one (and only one) of these lists, using field 'next' of\n** the 'CommonHeader' for the link:\n**\n** 'allgc': all objects not marked for finalization;\n** 'finobj': all objects marked for finalization;\n** 'tobefnz': all objects ready to be finalized;\n** 'fixedgc': all objects that are not to be collected (currently\n** only small strings, such as reserved words).\n\n*/\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/*\n** Atomic type (relative to signals) to better ensure that 'lua_sethook'\n** is thread safe\n*/\n#if !defined(l_signalT)\n#include <signal.h>\n#define l_signalT\tsig_atomic_t\n#endif\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n/* kinds of Garbage Collection */\n#define KGC_NORMAL\t0\n#define KGC_EMERGENCY\t1\t/* gc was forced by an allocation failure */\n\n\ntypedef struct stringtable {\n  TString **hash;\n  int nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** Information about a call.\n** When a thread yields, 'func' is adjusted to pretend that the\n** top function has only the yielded values in its stack; in that\n** case, the actual 'func' value is saved in field 'extra'.\n** When a function calls another with a continuation, 'extra' keeps\n** the function index so that, in case of errors, the continuation\n** function can be called with the correct top.\n*/\ntypedef struct CallInfo {\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  struct CallInfo *previous, *next;  /* dynamic call link */\n  union {\n    struct {  /* only for Lua functions */\n      StkId base;  /* base for this function */\n      const Instruction *savedpc;\n    } l;\n    struct {  /* only for C functions */\n      lua_KFunction k;  /* continuation in case of yields */\n      ptrdiff_t old_errfunc;\n      lua_KContext ctx;  /* context info. in case of yields */\n    } c;\n  } u;\n  ptrdiff_t extra;\n  short nresults;  /* expected number of results from this function */\n  unsigned short callstatus;\n} CallInfo;\n\n\n/*\n** Bits in CallInfo status\n*/\n#define CIST_OAH\t(1<<0)\t/* original value of 'allowhook' */\n#define CIST_LUA\t(1<<1)\t/* call is running a Lua function */\n#define CIST_HOOKED\t(1<<2)\t/* call is running a debug hook */\n#define CIST_FRESH\t(1<<3)\t/* call is running on a fresh invocation\n                                   of luaV_execute */\n#define CIST_YPCALL\t(1<<4)\t/* call is a yieldable protected call */\n#define CIST_TAIL\t(1<<5)\t/* call was tail called */\n#define CIST_HOOKYIELD\t(1<<6)\t/* last hook called yielded */\n#define CIST_LEQ\t(1<<7)  /* using __lt for __le */\n#define CIST_FIN\t(1<<8)  /* call is running a finalizer */\n\n#define isLua(ci)\t((ci)->callstatus & CIST_LUA)\n\n/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */\n#define setoah(st,v)\t((st) = ((st) & ~CIST_OAH) | (v))\n#define getoah(st)\t((st) & CIST_OAH)\n\n\n/*\n** 'global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to 'frealloc' */\n  l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */\n  l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */\n  lu_mem GCmemtrav;  /* memory traversed by the GC */\n  lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */\n  stringtable strt;  /* hash table for strings */\n  TValue l_registry;\n  unsigned int seed;  /* randomized seed for hashes */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gckind;  /* kind of GC running */\n  lu_byte gcrunning;  /* true if GC is running */\n  GCObject *allgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* current position of sweep in list */\n  GCObject *finobj;  /* list of collectable objects with finalizers */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of tables with weak values */\n  GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */\n  GCObject *allweak;  /* list of all-weak tables */\n  GCObject *tobefnz;  /* list of userdata to be GC */\n  GCObject *fixedgc;  /* list of objects not to be collected */\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  unsigned int gcfinnum;  /* number of finalizers to call in each GC step */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC 'granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  struct lua_State *mainthread;\n  const lua_Number *version;  /* pointer to version number */\n  TString *memerrmsg;  /* memory-error message */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */\n  TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */\n} global_State;\n\n\n/*\n** 'per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  unsigned short nci;  /* number of items in 'ci' list */\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *oldpc;  /* last pc traced */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  UpVal *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */\n  volatile lua_Hook hook;\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n  int stacksize;\n  int basehookcount;\n  int hookcount;\n  unsigned short nny;  /* number of non-yieldable calls in stack */\n  unsigned short nCcalls;  /* number of nested C calls */\n  l_signalT hookmask;\n  lu_byte allowhook;\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects (only for conversions)\n*/\nunion GCUnion {\n  GCObject gc;  /* common header */\n  struct TString ts;\n  struct Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct lua_State th;  /* thread */\n};\n\n\n#define cast_u(o)\tcast(union GCUnion *, (o))\n\n/* macros to convert a GCObject into a specific value */\n#define gco2ts(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))\n#define gco2u(o)  check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))\n#define gco2lcl(o)  check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))\n#define gco2ccl(o)  check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))\n#define gco2cl(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))\n#define gco2t(o)  check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))\n#define gco2p(o)  check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))\n#define gco2th(o)  check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))\n\n\n/* macro to convert a Lua object into a GCObject */\n#define obj2gco(v) \\\n\tcheck_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))\n\n\n/* actual number of total bytes allocated */\n#define gettotalbytes(g)\tcast(lu_mem, (g)->totalbytes + (g)->GCdebt)\n\nLUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\nLUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);\nLUAI_FUNC void luaE_freeCI (lua_State *L);\nLUAI_FUNC void luaE_shrinkCI (lua_State *L);\n\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n#define MEMERRMSG       \"not enough memory\"\n\n\n/*\n** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to\n** compute its hash\n*/\n#if !defined(LUAI_HASHLIMIT)\n#define LUAI_HASHLIMIT\t\t5\n#endif\n\n\n/*\n** equality for long strings\n*/\nint luaS_eqlngstr (TString *a, TString *b) {\n  size_t len = a->u.lnglen;\n  lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);\n  return (a == b) ||  /* same instance or... */\n    ((len == b->u.lnglen) &&  /* equal length and ... */\n     (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */\n}\n\n\nunsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {\n  unsigned int h = seed ^ cast(unsigned int, l);\n  size_t step = (l >> LUAI_HASHLIMIT) + 1;\n  for (; l >= step; l -= step)\n    h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));\n  return h;\n}\n\n\nunsigned int luaS_hashlongstr (TString *ts) {\n  lua_assert(ts->tt == LUA_TLNGSTR);\n  if (ts->extra == 0) {  /* no hash? */\n    ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);\n    ts->extra = 1;  /* now it has its hash */\n  }\n  return ts->hash;\n}\n\n\n/*\n** resizes the string table\n*/\nvoid luaS_resize (lua_State *L, int newsize) {\n  int i;\n  stringtable *tb = &G(L)->strt;\n  if (newsize > tb->size) {  /* grow table if needed */\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n    for (i = tb->size; i < newsize; i++)\n      tb->hash[i] = NULL;\n  }\n  for (i = 0; i < tb->size; i++) {  /* rehash */\n    TString *p = tb->hash[i];\n    tb->hash[i] = NULL;\n    while (p) {  /* for each node in the list */\n      TString *hnext = p->u.hnext;  /* save next */\n      unsigned int h = lmod(p->hash, newsize);  /* new position */\n      p->u.hnext = tb->hash[h];  /* chain it */\n      tb->hash[h] = p;\n      p = hnext;\n    }\n  }\n  if (newsize < tb->size) {  /* shrink table if needed */\n    /* vanishing slice should be empty */\n    lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n  }\n  tb->size = newsize;\n}\n\n\n/*\n** Clear API string cache. (Entries cannot be empty, so fill them with\n** a non-collectable string.)\n*/\nvoid luaS_clearcache (global_State *g) {\n  int i, j;\n  for (i = 0; i < STRCACHE_N; i++)\n    for (j = 0; j < STRCACHE_M; j++) {\n    if (iswhite(g->strcache[i][j]))  /* will entry be collected? */\n      g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */\n    }\n}\n\n\n/*\n** Initialize the string table and the string cache\n*/\nvoid luaS_init (lua_State *L) {\n  global_State *g = G(L);\n  int i, j;\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  /* pre-create memory-error message */\n  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);\n  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */\n  for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */\n    for (j = 0; j < STRCACHE_M; j++)\n      g->strcache[i][j] = g->memerrmsg;\n}\n\n\n\n/*\n** creates a new string object\n*/\nstatic TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {\n  TString *ts;\n  GCObject *o;\n  size_t totalsize;  /* total size of TString object */\n  totalsize = sizelstring(l);\n  o = luaC_newobj(L, tag, totalsize);\n  ts = gco2ts(o);\n  ts->hash = h;\n  ts->extra = 0;\n  getstr(ts)[l] = '\\0';  /* ending 0 */\n  return ts;\n}\n\n\nTString *luaS_createlngstrobj (lua_State *L, size_t l) {\n  TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);\n  ts->u.lnglen = l;\n  return ts;\n}\n\n\nvoid luaS_remove (lua_State *L, TString *ts) {\n  stringtable *tb = &G(L)->strt;\n  TString **p = &tb->hash[lmod(ts->hash, tb->size)];\n  while (*p != ts)  /* find previous element */\n    p = &(*p)->u.hnext;\n  *p = (*p)->u.hnext;  /* remove element from its list */\n  tb->nuse--;\n}\n\n\n/*\n** checks whether short string exists and reuses it or creates a new one\n*/\nstatic TString *internshrstr (lua_State *L, const char *str, size_t l) {\n  TString *ts;\n  global_State *g = G(L);\n  unsigned int h = luaS_hash(str, l, g->seed);\n  TString **list = &g->strt.hash[lmod(h, g->strt.size)];\n  lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */\n  for (ts = *list; ts != NULL; ts = ts->u.hnext) {\n    if (l == ts->shrlen &&\n        (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {\n      /* found! */\n      if (isdead(g, ts))  /* dead (but not collected yet)? */\n        changewhite(ts);  /* resurrect it */\n      return ts;\n    }\n  }\n  if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {\n    luaS_resize(L, g->strt.size * 2);\n    list = &g->strt.hash[lmod(h, g->strt.size)];  /* recompute with new size */\n  }\n  ts = createstrobj(L, l, LUA_TSHRSTR, h);\n  memcpy(getstr(ts), str, l * sizeof(char));\n  ts->shrlen = cast_byte(l);\n  ts->u.hnext = *list;\n  *list = ts;\n  g->strt.nuse++;\n  return ts;\n}\n\n\n/*\n** new string (with explicit length)\n*/\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  if (l <= LUAI_MAXSHORTLEN)  /* short string? */\n    return internshrstr(L, str, l);\n  else {\n    TString *ts;\n    if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char))\n      luaM_toobig(L);\n    ts = luaS_createlngstrobj(L, l);\n    memcpy(getstr(ts), str, l * sizeof(char));\n    return ts;\n  }\n}\n\n\n/*\n** Create or reuse a zero-terminated string, first checking in the\n** cache (using the string address as a key). The cache can contain\n** only zero-terminated strings, so it is safe to use 'strcmp' to\n** check hits.\n*/\nTString *luaS_new (lua_State *L, const char *str) {\n  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */\n  int j;\n  TString **p = G(L)->strcache[i];\n  for (j = 0; j < STRCACHE_M; j++) {\n    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */\n      return p[j];  /* that is it */\n  }\n  /* normal route */\n  for (j = STRCACHE_M - 1; j > 0; j--)\n    p[j] = p[j - 1];  /* move out last element */\n  /* new element is first in the list */\n  p[0] = luaS_newlstr(L, str, strlen(str));\n  return p[0];\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s) {\n  Udata *u;\n  GCObject *o;\n  if (s > MAX_SIZE - sizeof(Udata))\n    luaM_toobig(L);\n  o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s));\n  u = gco2u(o);\n  u->len = s;\n  u->metatable = NULL;\n  setuservalue(L, u, luaO_nilobject);\n  return u;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizelstring(l)  (sizeof(union UTString) + ((l) + 1) * sizeof(char))\n\n#define sizeludata(l)\t(sizeof(union UUdata) + (l))\n#define sizeudata(u)\tsizeludata((u)->len)\n\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n\n/*\n** test whether a string is a reserved word\n*/\n#define isreserved(s)\t((s)->tt == LUA_TSHRSTR && (s)->extra > 0)\n\n\n/*\n** equality for short strings, which are always internalized\n*/\n#define eqshrstr(a,b)\tcheck_exp((a)->tt == LUA_TSHRSTR, (a) == (b))\n\n\nLUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);\nLUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);\nLUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC void luaS_clearcache (global_State *g);\nLUAI_FUNC void luaS_init (lua_State *L);\nLUAI_FUNC void luaS_remove (lua_State *L, TString *ts);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\nLUAI_FUNC TString *luaS_new (lua_State *L, const char *str);\nLUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <float.h>\n#include <limits.h>\n#include <locale.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** maximum number of captures that a pattern can do during\n** pattern-matching. This limit is arbitrary, but must fit in\n** an unsigned char.\n*/\n#if !defined(LUA_MAXCAPTURES)\n#define LUA_MAXCAPTURES\t\t32\n#endif\n\n\n/* macro to 'unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n\n/*\n** Some sizes are better limited to fit in 'int', but must also fit in\n** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)\n*/\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n#define MAXSIZE  \\\n\t(sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))\n\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, (lua_Integer)l);\n  return 1;\n}\n\n\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer start = posrelat(luaL_checkinteger(L, 2), l);\n  lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (lua_Integer)l) end = l;\n  if (start <= end)\n    lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l, i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i = 0; i < l; i++)\n    p[i] = s[l - i - 1];\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = tolower(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = toupper(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_rep (lua_State *L) {\n  size_t l, lsep;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer n = luaL_checkinteger(L, 2);\n  const char *sep = luaL_optlstring(L, 3, \"\", &lsep);\n  if (n <= 0) lua_pushliteral(L, \"\");\n  else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */\n    return luaL_error(L, \"resulting string too large\");\n  else {\n    size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;\n    luaL_Buffer b;\n    char *p = luaL_buffinitsize(L, &b, totallen);\n    while (n-- > 1) {  /* first n-1 copies (followed by separator) */\n      memcpy(p, s, l * sizeof(char)); p += l;\n      if (lsep > 0) {  /* empty 'memcpy' is not that cheap */\n        memcpy(p, sep, lsep * sizeof(char));\n        p += lsep;\n      }\n    }\n    memcpy(p, s, l * sizeof(char));  /* last copy (not followed by separator) */\n    luaL_pushresultsize(&b, totallen);\n  }\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi < 1) posi = 1;\n  if (pose > (lua_Integer)l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* arithmetic overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  char *p = luaL_buffinitsize(L, &b, n);\n  for (i=1; i<=n; i++) {\n    lua_Integer c = luaL_checkinteger(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"value out of range\");\n    p[i - 1] = uchar(c);\n  }\n  luaL_pushresultsize(&b, n);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void *b, size_t size, void *B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer *) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  int strip = lua_toboolean(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b, strip) != 0)\n    return luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end ('\\0') of source string */\n  const char *p_end;  /* end ('\\0') of pattern */\n  lua_State *L;\n  int matchdepth;  /* control for recursive depth (to avoid C stack overflow) */\n  unsigned char level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n/* recursive function */\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\n/* maximum recursion depth for 'match' */\n#if !defined(MAXCCALLS)\n#define MAXCCALLS\t200\n#endif\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index %%%d\", l + 1);\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (p == ms->p_end)\n        luaL_error(ms->L, \"malformed pattern (ends with '%%')\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a ']' */\n        if (p == ms->p_end)\n          luaL_error(ms->L, \"malformed pattern (missing ']')\");\n        if (*(p++) == L_ESC && p < ms->p_end)\n          p++;  /* skip escapes (e.g. '%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'g' : res = isgraph(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;  /* deprecated option */\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the '^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (MatchState *ms, const char *s, const char *p,\n                        const char *ep) {\n  if (s >= ms->src_end)\n    return 0;\n  else {\n    int c = uchar(*s);\n    switch (*p) {\n      case '.': return 1;  /* matches any char */\n      case L_ESC: return match_class(c, uchar(*(p+1)));\n      case '[': return matchbracketclass(c, p, ep-1);\n      default:  return (uchar(*p) == c);\n    }\n  }\n}\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (p >= ms->p_end - 1)\n    luaL_error(ms->L, \"malformed pattern (missing arguments to '%%b')\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while (singlematch(ms, s + i, p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (singlematch(ms, s, p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  if (ms->matchdepth-- == 0)\n    luaL_error(ms->L, \"pattern too complex\");\n  init: /* using goto's to optimize tail recursion */\n  if (p != ms->p_end) {  /* end of pattern? */\n    switch (*p) {\n      case '(': {  /* start capture */\n        if (*(p + 1) == ')')  /* position capture? */\n          s = start_capture(ms, s, p + 2, CAP_POSITION);\n        else\n          s = start_capture(ms, s, p + 1, CAP_UNFINISHED);\n        break;\n      }\n      case ')': {  /* end capture */\n        s = end_capture(ms, s, p + 1);\n        break;\n      }\n      case '$': {\n        if ((p + 1) != ms->p_end)  /* is the '$' the last char in pattern? */\n          goto dflt;  /* no; go to default */\n        s = (s == ms->src_end) ? s : NULL;  /* check end of string */\n        break;\n      }\n      case L_ESC: {  /* escaped sequences not in the format class[*+?-]? */\n        switch (*(p + 1)) {\n          case 'b': {  /* balanced string? */\n            s = matchbalance(ms, s, p + 2);\n            if (s != NULL) {\n              p += 4; goto init;  /* return match(ms, s, p + 4); */\n            }  /* else fail (s == NULL) */\n            break;\n          }\n          case 'f': {  /* frontier? */\n            const char *ep; char previous;\n            p += 2;\n            if (*p != '[')\n              luaL_error(ms->L, \"missing '[' after '%%f' in pattern\");\n            ep = classend(ms, p);  /* points to what is next */\n            previous = (s == ms->src_init) ? '\\0' : *(s - 1);\n            if (!matchbracketclass(uchar(previous), p, ep - 1) &&\n               matchbracketclass(uchar(*s), p, ep - 1)) {\n              p = ep; goto init;  /* return match(ms, s, ep); */\n            }\n            s = NULL;  /* match failed */\n            break;\n          }\n          case '0': case '1': case '2': case '3':\n          case '4': case '5': case '6': case '7':\n          case '8': case '9': {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p + 1)));\n            if (s != NULL) {\n              p += 2; goto init;  /* return match(ms, s, p + 2) */\n            }\n            break;\n          }\n          default: goto dflt;\n        }\n        break;\n      }\n      default: dflt: {  /* pattern class plus optional suffix */\n        const char *ep = classend(ms, p);  /* points to optional suffix */\n        /* does not match at least once? */\n        if (!singlematch(ms, s, p, ep)) {\n          if (*ep == '*' || *ep == '?' || *ep == '-') {  /* accept empty? */\n            p = ep + 1; goto init;  /* return match(ms, s, ep + 1); */\n          }\n          else  /* '+' or no suffix */\n            s = NULL;  /* fail */\n        }\n        else {  /* matched once */\n          switch (*ep) {  /* handle optional suffix */\n            case '?': {  /* optional */\n              const char *res;\n              if ((res = match(ms, s + 1, ep + 1)) != NULL)\n                s = res;\n              else {\n                p = ep + 1; goto init;  /* else return match(ms, s, ep + 1); */\n              }\n              break;\n            }\n            case '+':  /* 1 or more repetitions */\n              s++;  /* 1 match already done */\n              /* FALLTHROUGH */\n            case '*':  /* 0 or more repetitions */\n              s = max_expand(ms, s, p, ep);\n              break;\n            case '-':  /* 0 or more repetitions (minimum) */\n              s = min_expand(ms, s, p, ep);\n              break;\n            default:  /* no suffix */\n              s++; p = ep; goto init;  /* return match(ms, s + 1, ep); */\n          }\n        }\n        break;\n      }\n    }\n  }\n  ms->matchdepth++;\n  return s;\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative 'l1' */\n  else {\n    const char *init;  /* to search for a '*s2' inside 's1' */\n    l2--;  /* 1st char will be checked by 'memchr' */\n    l1 = l1-l2;  /* 's2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct 'l1' and 's1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index %%%d\", i + 1);\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\n/* check whether pattern has no special characters */\nstatic int nospecials (const char *p, size_t l) {\n  size_t upto = 0;\n  do {\n    if (strpbrk(p + upto, SPECIALS))\n      return 0;  /* pattern has a special character */\n    upto += strlen(p + upto) + 1;  /* may have more after \\0 */\n  } while (upto <= l);\n  return 1;  /* no special chars found */\n}\n\n\nstatic void prepstate (MatchState *ms, lua_State *L,\n                       const char *s, size_t ls, const char *p, size_t lp) {\n  ms->L = L;\n  ms->matchdepth = MAXCCALLS;\n  ms->src_init = s;\n  ms->src_end = s + ls;\n  ms->p_end = p + lp;\n}\n\n\nstatic void reprepstate (MatchState *ms) {\n  ms->level = 0;\n  lua_assert(ms->matchdepth == MAXCCALLS);\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);\n  if (init < 1) init = 1;\n  else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */\n    lua_pushnil(L);  /* cannot find anything */\n    return 1;\n  }\n  /* explicit request or no special characters? */\n  if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {\n    /* do a plain search */\n    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);\n    if (s2) {\n      lua_pushinteger(L, (s2 - s) + 1);\n      lua_pushinteger(L, (s2 - s) + lp);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    const char *s1 = s + init - 1;\n    int anchor = (*p == '^');\n    if (anchor) {\n      p++; lp--;  /* skip anchor character */\n    }\n    prepstate(&ms, L, s, ls, p, lp);\n    do {\n      const char *res;\n      reprepstate(&ms);\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, (s1 - s) + 1);  /* start */\n          lua_pushinteger(L, res - s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\n/* state for 'gmatch' */\ntypedef struct GMatchState {\n  const char *src;  /* current position */\n  const char *p;  /* pattern */\n  const char *lastmatch;  /* end of last match */\n  MatchState ms;  /* match state */\n} GMatchState;\n\n\nstatic int gmatch_aux (lua_State *L) {\n  GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));\n  const char *src;\n  gm->ms.L = L;\n  for (src = gm->src; src <= gm->ms.src_end; src++) {\n    const char *e;\n    reprepstate(&gm->ms);\n    if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {\n      gm->src = gm->lastmatch = e;\n      return push_captures(&gm->ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  GMatchState *gm;\n  lua_settop(L, 2);  /* keep them on closure to avoid being collected */\n  gm = (GMatchState *)lua_newuserdata(L, sizeof(GMatchState));\n  prepstate(&gm->ms, L, s, ls, p, lp);\n  gm->src = s; gm->p = p; gm->lastmatch = NULL;\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  lua_State *L = ms->L;\n  const char *news = lua_tolstring(L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i]))) {\n        if (news[i] != L_ESC)\n          luaL_error(L, \"invalid use of '%c' in replacement string\", L_ESC);\n        luaL_addchar(b, news[i]);\n      }\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_tolstring(L, -1, NULL);  /* if number, convert it to string */\n        lua_remove(L, -2);  /* remove original value */\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                       const char *e, int tr) {\n  lua_State *L = ms->L;\n  switch (tr) {\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n    default: {  /* LUA_TNUMBER or LUA_TSTRING */\n      add_s(ms, b, s, e);\n      return;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1));\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl, lp;\n  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */\n  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */\n  const char *lastmatch = NULL;  /* end of last match */\n  int tr = lua_type(L, 3);  /* replacement type */\n  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */\n  int anchor = (*p == '^');\n  lua_Integer n = 0;  /* replacement count */\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  if (anchor) {\n    p++; lp--;  /* skip anchor character */\n  }\n  prepstate(&ms, L, src, srcl, p, lp);\n  while (n < max_s) {\n    const char *e;\n    reprepstate(&ms);  /* (re)prepare state for new match */\n    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */\n      n++;\n      add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */\n      src = lastmatch = e;\n    }\n    else if (src < ms.src_end)  /* otherwise, skip one character */\n      luaL_addchar(&b, *src++);\n    else break;  /* end of subject */\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** STRING FORMAT\n** =======================================================\n*/\n\n#if !defined(lua_number2strx)\t/* { */\n\n/*\n** Hexadecimal floating-point formatter\n*/\n\n#include <math.h>\n\n#define SIZELENMOD\t(sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))\n\n\n/*\n** Number of bits that goes into the first digit. It can be any value\n** between 1 and 4; the following definition tries to align the number\n** to nibble boundaries by making what is left after that first digit a\n** multiple of 4.\n*/\n#define L_NBFD\t\t((l_mathlim(MANT_DIG) - 1)%4 + 1)\n\n\n/*\n** Add integer part of 'x' to buffer and return new 'x'\n*/\nstatic lua_Number adddigit (char *buff, int n, lua_Number x) {\n  lua_Number dd = l_mathop(floor)(x);  /* get integer part from 'x' */\n  int d = (int)dd;\n  buff[n] = (d < 10 ? d + '0' : d - 10 + 'a');  /* add to buffer */\n  return x - dd;  /* return what is left */\n}\n\n\nstatic int num2straux (char *buff, int sz, lua_Number x) {\n  /* if 'inf' or 'NaN', format it like '%g' */\n  if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);\n  else if (x == 0) {  /* can be -0... */\n    /* create \"0\" or \"-0\" followed by exponent */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT \"x0p+0\", (LUAI_UACNUMBER)x);\n  }\n  else {\n    int e;\n    lua_Number m = l_mathop(frexp)(x, &e);  /* 'x' fraction and exponent */\n    int n = 0;  /* character count */\n    if (m < 0) {  /* is number negative? */\n      buff[n++] = '-';  /* add signal */\n      m = -m;  /* make it positive */\n    }\n    buff[n++] = '0'; buff[n++] = 'x';  /* add \"0x\" */\n    m = adddigit(buff, n++, m * (1 << L_NBFD));  /* add first digit */\n    e -= L_NBFD;  /* this digit goes before the radix point */\n    if (m > 0) {  /* more digits? */\n      buff[n++] = lua_getlocaledecpoint();  /* add radix point */\n      do {  /* add as many digits as needed */\n        m = adddigit(buff, n++, m * 16);\n      } while (m > 0);\n    }\n    n += l_sprintf(buff + n, sz - n, \"p%+d\", e);  /* add exponent */\n    lua_assert(n < sz);\n    return n;\n  }\n}\n\n\nstatic int lua_number2strx (lua_State *L, char *buff, int sz,\n                            const char *fmt, lua_Number x) {\n  int n = num2straux(buff, sz, x);\n  if (fmt[SIZELENMOD] == 'A') {\n    int i;\n    for (i = 0; i < n; i++)\n      buff[i] = toupper(uchar(buff[i]));\n  }\n  else if (fmt[SIZELENMOD] != 'a')\n    luaL_error(L, \"modifiers for format '%%a'/'%%A' not implemented\");\n  return n;\n}\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Maximum size of each formatted item. This maximum size is produced\n** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',\n** and '\\0') + number of decimal digits to represent maxfloat (which\n** is maximum exponent + 1). (99+3+1 then rounded to 120 for \"extra\n** expenses\", such as locale-dependent stuff)\n*/\n#define MAX_ITEM        (120 + l_mathlim(MAX_10_EXP))\n\n\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n\n/*\n** maximum size of each format specification (such as \"%-099.99d\")\n*/\n#define MAX_FORMAT\t32\n\n\nstatic void addquoted (luaL_Buffer *b, const char *s, size_t len) {\n  luaL_addchar(b, '\"');\n  while (len--) {\n    if (*s == '\"' || *s == '\\\\' || *s == '\\n') {\n      luaL_addchar(b, '\\\\');\n      luaL_addchar(b, *s);\n    }\n    else if (iscntrl(uchar(*s))) {\n      char buff[10];\n      if (!isdigit(uchar(*(s+1))))\n        l_sprintf(buff, sizeof(buff), \"\\\\%d\", (int)uchar(*s));\n      else\n        l_sprintf(buff, sizeof(buff), \"\\\\%03d\", (int)uchar(*s));\n      luaL_addstring(b, buff);\n    }\n    else\n      luaL_addchar(b, *s);\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\n\n/*\n** Ensures the 'buff' string uses a dot as the radix character.\n*/\nstatic void checkdp (char *buff, int nb) {\n  if (memchr(buff, '.', nb) == NULL) {  /* no dot? */\n    char point = lua_getlocaledecpoint();  /* try locale point */\n    char *ppoint = (char *)memchr(buff, point, nb);\n    if (ppoint) *ppoint = '.';  /* change it to a dot */\n  }\n}\n\n\nstatic void addliteral (lua_State *L, luaL_Buffer *b, int arg) {\n  switch (lua_type(L, arg)) {\n    case LUA_TSTRING: {\n      size_t len;\n      const char *s = lua_tolstring(L, arg, &len);\n      addquoted(b, s, len);\n      break;\n    }\n    case LUA_TNUMBER: {\n      char *buff = luaL_prepbuffsize(b, MAX_ITEM);\n      int nb;\n      if (!lua_isinteger(L, arg)) {  /* float? */\n        lua_Number n = lua_tonumber(L, arg);  /* write as hexa ('%a') */\n        nb = lua_number2strx(L, buff, MAX_ITEM, \"%\" LUA_NUMBER_FRMLEN \"a\", n);\n        checkdp(buff, nb);  /* ensure it uses a dot */\n      }\n      else {  /* integers */\n        lua_Integer n = lua_tointeger(L, arg);\n        const char *format = (n == LUA_MININTEGER)  /* corner case? */\n                           ? \"0x%\" LUA_INTEGER_FRMLEN \"x\"  /* use hexa */\n                           : LUA_INTEGER_FMT;  /* else use default format */\n        nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);\n      }\n      luaL_addsize(b, nb);\n      break;\n    }\n    case LUA_TNIL: case LUA_TBOOLEAN: {\n      luaL_tolstring(L, arg, NULL);\n      luaL_addvalue(b);\n      break;\n    }\n    default: {\n      luaL_argerror(L, arg, \"value has no literal form\");\n    }\n  }\n}\n\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));\n  form += (p - strfrmt) + 1;\n  *form = '\\0';\n  return p;\n}\n\n\n/*\n** add length modifier into formats\n*/\nstatic void addlenmod (char *form, const char *lenmod) {\n  size_t l = strlen(form);\n  size_t lm = strlen(lenmod);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, lenmod);\n  form[l + lm - 1] = spec;\n  form[l + lm] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format ('%...') */\n      char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */\n      int nb = 0;  /* number of bytes in added item */\n      if (++arg > top)\n        luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));\n          break;\n        }\n        case 'd': case 'i':\n        case 'o': case 'u': case 'x': case 'X': {\n          lua_Integer n = luaL_checkinteger(L, arg);\n          addlenmod(form, LUA_INTEGER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);\n          break;\n        }\n        case 'a': case 'A':\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = lua_number2strx(L, buff, MAX_ITEM, form,\n                                  luaL_checknumber(L, arg));\n          break;\n        case 'e': case 'E': case 'f':\n        case 'g': case 'G': {\n          lua_Number n = luaL_checknumber(L, arg);\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);\n          break;\n        }\n        case 'q': {\n          addliteral(L, &b, arg);\n          break;\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_tolstring(L, arg, &l);\n          if (form[2] == '\\0')  /* no modifiers? */\n            luaL_addvalue(&b);  /* keep entire string */\n          else {\n            luaL_argcheck(L, l == strlen(s), arg, \"string contains zeros\");\n            if (!strchr(form, '.') && l >= 100) {\n              /* no precision and string is too long to be formatted */\n              luaL_addvalue(&b);  /* keep entire string */\n            }\n            else {  /* format the string into 'buff' */\n              nb = l_sprintf(buff, MAX_ITEM, form, s);\n              lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */\n            }\n          }\n          break;\n        }\n        default: {  /* also treat cases 'pnLlh' */\n          return luaL_error(L, \"invalid option '%%%c' to 'format'\",\n                               *(strfrmt - 1));\n        }\n      }\n      lua_assert(nb < MAX_ITEM);\n      luaL_addsize(&b, nb);\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** PACK/UNPACK\n** =======================================================\n*/\n\n\n/* value used for padding */\n#if !defined(LUAL_PACKPADBYTE)\n#define LUAL_PACKPADBYTE\t\t0x00\n#endif\n\n/* maximum size for the binary representation of an integer */\n#define MAXINTSIZE\t16\n\n/* number of bits in a character */\n#define NB\tCHAR_BIT\n\n/* mask for one character (NB 1's) */\n#define MC\t((1 << NB) - 1)\n\n/* size of a lua_Integer */\n#define SZINT\t((int)sizeof(lua_Integer))\n\n\n/* dummy union to get native endianness */\nstatic const union {\n  int dummy;\n  char little;  /* true iff machine is little endian */\n} nativeendian = {1};\n\n\n/* dummy structure to get native alignment requirements */\nstruct cD {\n  char c;\n  union { double d; void *p; lua_Integer i; lua_Number n; } u;\n};\n\n#define MAXALIGN\t(offsetof(struct cD, u))\n\n\n/*\n** Union for serializing floats\n*/\ntypedef union Ftypes {\n  float f;\n  double d;\n  lua_Number n;\n  char buff[5 * sizeof(lua_Number)];  /* enough for any float type */\n} Ftypes;\n\n\n/*\n** information to pack/unpack stuff\n*/\ntypedef struct Header {\n  lua_State *L;\n  int islittle;\n  int maxalign;\n} Header;\n\n\n/*\n** options for pack/unpack\n*/\ntypedef enum KOption {\n  Kint,\t\t/* signed integers */\n  Kuint,\t/* unsigned integers */\n  Kfloat,\t/* floating-point numbers */\n  Kchar,\t/* fixed-length strings */\n  Kstring,\t/* strings with prefixed length */\n  Kzstr,\t/* zero-terminated strings */\n  Kpadding,\t/* padding */\n  Kpaddalign,\t/* padding for alignment */\n  Knop\t\t/* no-op (configuration or spaces) */\n} KOption;\n\n\n/*\n** Read an integer numeral from string 'fmt' or return 'df' if\n** there is no numeral\n*/\nstatic int digit (int c) { return '0' <= c && c <= '9'; }\n\nstatic int getnum (const char **fmt, int df) {\n  if (!digit(**fmt))  /* no number? */\n    return df;  /* return default value */\n  else {\n    int a = 0;\n    do {\n      a = a*10 + (*((*fmt)++) - '0');\n    } while (digit(**fmt) && a <= ((int)MAXSIZE - 9)/10);\n    return a;\n  }\n}\n\n\n/*\n** Read an integer numeral and raises an error if it is larger\n** than the maximum size for integers.\n*/\nstatic int getnumlimit (Header *h, const char **fmt, int df) {\n  int sz = getnum(fmt, df);\n  if (sz > MAXINTSIZE || sz <= 0)\n    luaL_error(h->L, \"integral size (%d) out of limits [1,%d]\",\n                     sz, MAXINTSIZE);\n  return sz;\n}\n\n\n/*\n** Initialize Header\n*/\nstatic void initheader (lua_State *L, Header *h) {\n  h->L = L;\n  h->islittle = nativeendian.little;\n  h->maxalign = 1;\n}\n\n\n/*\n** Read and classify next option. 'size' is filled with option's size.\n*/\nstatic KOption getoption (Header *h, const char **fmt, int *size) {\n  int opt = *((*fmt)++);\n  *size = 0;  /* default */\n  switch (opt) {\n    case 'b': *size = sizeof(char); return Kint;\n    case 'B': *size = sizeof(char); return Kuint;\n    case 'h': *size = sizeof(short); return Kint;\n    case 'H': *size = sizeof(short); return Kuint;\n    case 'l': *size = sizeof(long); return Kint;\n    case 'L': *size = sizeof(long); return Kuint;\n    case 'j': *size = sizeof(lua_Integer); return Kint;\n    case 'J': *size = sizeof(lua_Integer); return Kuint;\n    case 'T': *size = sizeof(size_t); return Kuint;\n    case 'f': *size = sizeof(float); return Kfloat;\n    case 'd': *size = sizeof(double); return Kfloat;\n    case 'n': *size = sizeof(lua_Number); return Kfloat;\n    case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;\n    case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;\n    case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;\n    case 'c':\n      *size = getnum(fmt, -1);\n      if (*size == -1)\n        luaL_error(h->L, \"missing size for format option 'c'\");\n      return Kchar;\n    case 'z': return Kzstr;\n    case 'x': *size = 1; return Kpadding;\n    case 'X': return Kpaddalign;\n    case ' ': break;\n    case '<': h->islittle = 1; break;\n    case '>': h->islittle = 0; break;\n    case '=': h->islittle = nativeendian.little; break;\n    case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break;\n    default: luaL_error(h->L, \"invalid format option '%c'\", opt);\n  }\n  return Knop;\n}\n\n\n/*\n** Read, classify, and fill other details about the next option.\n** 'psize' is filled with option's size, 'notoalign' with its\n** alignment requirements.\n** Local variable 'size' gets the size to be aligned. (Kpadal option\n** always gets its full alignment, other options are limited by\n** the maximum alignment ('maxalign'). Kchar option needs no alignment\n** despite its size.\n*/\nstatic KOption getdetails (Header *h, size_t totalsize,\n                           const char **fmt, int *psize, int *ntoalign) {\n  KOption opt = getoption(h, fmt, psize);\n  int align = *psize;  /* usually, alignment follows size */\n  if (opt == Kpaddalign) {  /* 'X' gets alignment from following option */\n    if (**fmt == '\\0' || getoption(h, fmt, &align) == Kchar || align == 0)\n      luaL_argerror(h->L, 1, \"invalid next option for option 'X'\");\n  }\n  if (align <= 1 || opt == Kchar)  /* need no alignment? */\n    *ntoalign = 0;\n  else {\n    if (align > h->maxalign)  /* enforce maximum alignment */\n      align = h->maxalign;\n    if ((align & (align - 1)) != 0)  /* is 'align' not a power of 2? */\n      luaL_argerror(h->L, 1, \"format asks for alignment not power of 2\");\n    *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1);\n  }\n  return opt;\n}\n\n\n/*\n** Pack integer 'n' with 'size' bytes and 'islittle' endianness.\n** The final 'if' handles the case when 'size' is larger than\n** the size of a Lua integer, correcting the extra sign-extension\n** bytes if necessary (by default they would be zeros).\n*/\nstatic void packint (luaL_Buffer *b, lua_Unsigned n,\n                     int islittle, int size, int neg) {\n  char *buff = luaL_prepbuffsize(b, size);\n  int i;\n  buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */\n  for (i = 1; i < size; i++) {\n    n >>= NB;\n    buff[islittle ? i : size - 1 - i] = (char)(n & MC);\n  }\n  if (neg && size > SZINT) {  /* negative number need sign extension? */\n    for (i = SZINT; i < size; i++)  /* correct extra bytes */\n      buff[islittle ? i : size - 1 - i] = (char)MC;\n  }\n  luaL_addsize(b, size);  /* add result to buffer */\n}\n\n\n/*\n** Copy 'size' bytes from 'src' to 'dest', correcting endianness if\n** given 'islittle' is different from native endianness.\n*/\nstatic void copywithendian (volatile char *dest, volatile const char *src,\n                            int size, int islittle) {\n  if (islittle == nativeendian.little) {\n    while (size-- != 0)\n      *(dest++) = *(src++);\n  }\n  else {\n    dest += size - 1;\n    while (size-- != 0)\n      *(dest--) = *(src++);\n  }\n}\n\n\nstatic int str_pack (lua_State *L) {\n  luaL_Buffer b;\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  int arg = 1;  /* current argument to pack */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  lua_pushnil(L);  /* mark to separate arguments from string buffer */\n  luaL_buffinit(L, &b);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    totalsize += ntoalign + size;\n    while (ntoalign-- > 0)\n     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */\n    arg++;\n    switch (opt) {\n      case Kint: {  /* signed integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT) {  /* need overflow check? */\n          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);\n          luaL_argcheck(L, -lim <= n && n < lim, arg, \"integer overflow\");\n        }\n        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));\n        break;\n      }\n      case Kuint: {  /* unsigned integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT)  /* need overflow check? */\n          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),\n                           arg, \"unsigned overflow\");\n        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);\n        break;\n      }\n      case Kfloat: {  /* floating-point options */\n        volatile Ftypes u;\n        char *buff = luaL_prepbuffsize(&b, size);\n        lua_Number n = luaL_checknumber(L, arg);  /* get argument */\n        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */\n        else if (size == sizeof(u.d)) u.d = (double)n;\n        else u.n = n;\n        /* move 'u' to final result, correcting endianness if needed */\n        copywithendian(buff, u.buff, size, h.islittle);\n        luaL_addsize(&b, size);\n        break;\n      }\n      case Kchar: {  /* fixed-size string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, len <= (size_t)size, arg,\n                         \"string longer than given size\");\n        luaL_addlstring(&b, s, len);  /* add string */\n        while (len++ < (size_t)size)  /* pad extra space */\n          luaL_addchar(&b, LUAL_PACKPADBYTE);\n        break;\n      }\n      case Kstring: {  /* strings with length count */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, size >= (int)sizeof(size_t) ||\n                         len < ((size_t)1 << (size * NB)),\n                         arg, \"string length does not fit in given size\");\n        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */\n        luaL_addlstring(&b, s, len);\n        totalsize += len;\n        break;\n      }\n      case Kzstr: {  /* zero-terminated string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, strlen(s) == len, arg, \"string contains zeros\");\n        luaL_addlstring(&b, s, len);\n        luaL_addchar(&b, '\\0');  /* add zero at the end */\n        totalsize += len + 1;\n        break;\n      }\n      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */\n      case Kpaddalign: case Knop:\n        arg--;  /* undo increment */\n        break;\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_packsize (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    size += ntoalign;  /* total space used by option */\n    luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,\n                     \"format result too large\");\n    totalsize += size;\n    switch (opt) {\n      case Kstring:  /* strings with length count */\n      case Kzstr:    /* zero-terminated string */\n        luaL_argerror(L, 1, \"variable-length format\");\n        /* call never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:  break;\n    }\n  }\n  lua_pushinteger(L, (lua_Integer)totalsize);\n  return 1;\n}\n\n\n/*\n** Unpack an integer with 'size' bytes and 'islittle' endianness.\n** If size is smaller than the size of a Lua integer and integer\n** is signed, must do sign extension (propagating the sign to the\n** higher bits); if size is larger than the size of a Lua integer,\n** it must check the unread bytes to see whether they do not cause an\n** overflow.\n*/\nstatic lua_Integer unpackint (lua_State *L, const char *str,\n                              int islittle, int size, int issigned) {\n  lua_Unsigned res = 0;\n  int i;\n  int limit = (size  <= SZINT) ? size : SZINT;\n  for (i = limit - 1; i >= 0; i--) {\n    res <<= NB;\n    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];\n  }\n  if (size < SZINT) {  /* real size smaller than lua_Integer? */\n    if (issigned) {  /* needs sign extension? */\n      lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);\n      res = ((res ^ mask) - mask);  /* do sign extension */\n    }\n  }\n  else if (size > SZINT) {  /* must check unread bytes */\n    int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;\n    for (i = limit; i < size; i++) {\n      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)\n        luaL_error(L, \"%d-byte integer does not fit into Lua Integer\", size);\n    }\n  }\n  return (lua_Integer)res;\n}\n\n\nstatic int str_unpack (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);\n  size_t ld;\n  const char *data = luaL_checklstring(L, 2, &ld);\n  size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;\n  int n = 0;  /* number of results */\n  luaL_argcheck(L, pos <= ld, 3, \"initial position out of string\");\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);\n    if ((size_t)ntoalign + size > ~pos || pos + ntoalign + size > ld)\n      luaL_argerror(L, 2, \"data string too short\");\n    pos += ntoalign;  /* skip alignment */\n    /* stack space for item + next position */\n    luaL_checkstack(L, 2, \"too many results\");\n    n++;\n    switch (opt) {\n      case Kint:\n      case Kuint: {\n        lua_Integer res = unpackint(L, data + pos, h.islittle, size,\n                                       (opt == Kint));\n        lua_pushinteger(L, res);\n        break;\n      }\n      case Kfloat: {\n        volatile Ftypes u;\n        lua_Number num;\n        copywithendian(u.buff, data + pos, size, h.islittle);\n        if (size == sizeof(u.f)) num = (lua_Number)u.f;\n        else if (size == sizeof(u.d)) num = (lua_Number)u.d;\n        else num = u.n;\n        lua_pushnumber(L, num);\n        break;\n      }\n      case Kchar: {\n        lua_pushlstring(L, data + pos, size);\n        break;\n      }\n      case Kstring: {\n        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);\n        luaL_argcheck(L, pos + len + size <= ld, 2, \"data string too short\");\n        lua_pushlstring(L, data + pos + size, len);\n        pos += len;  /* skip string */\n        break;\n      }\n      case Kzstr: {\n        size_t len = (int)strlen(data + pos);\n        lua_pushlstring(L, data + pos, len);\n        pos += len + 1;  /* skip string plus final '\\0' */\n        break;\n      }\n      case Kpaddalign: case Kpadding: case Knop:\n        n--;  /* undo increment */\n        break;\n    }\n    pos += size;\n  }\n  lua_pushinteger(L, pos + 1);  /* next position */\n  return n + 1;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {\"pack\", str_pack},\n  {\"packsize\", str_packsize},\n  {\"unpack\", str_unpack},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* table to be metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);  /* copy table */\n  lua_setmetatable(L, -2);  /* set table as metatable for strings */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* get string library */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = string */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUAMOD_API int luaopen_string (lua_State *L) {\n  luaL_newlib(L, strlib);\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.118 2016/11/07 12:38:35 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest 'n' such that\n** more than half the slots between 1 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the 'original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <limits.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/*\n** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is\n** the largest integer such that MAXASIZE fits in an unsigned int.\n*/\n#define MAXABITS\tcast_int(sizeof(int) * CHAR_BIT - 1)\n#define MAXASIZE\t(1u << MAXABITS)\n\n/*\n** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest\n** integer such that 2^MAXHBITS fits in a signed int. (Note that the\n** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still\n** fits comfortably in an unsigned int.)\n*/\n#define MAXHBITS\t(MAXABITS - 1)\n\n\n#define hashpow2(t,n)\t\t(gnode(t, lmod((n), sizenode(t))))\n\n#define hashstr(t,str)\t\thashpow2(t, (str)->hash)\n#define hashboolean(t,p)\thashpow2(t, p)\n#define hashint(t,i)\t\thashpow2(t, i)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, point2uint(p))\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {NILCONSTANT},  /* value */\n  {{NILCONSTANT, 0}}  /* key */\n};\n\n\n/*\n** Hash for floating-point numbers.\n** The main computation should be just\n**     n = frexp(n, &i); return (n * INT_MAX) + i\n** but there are some numerical subtleties.\n** In a two-complement representation, INT_MAX does not has an exact\n** representation as a float, but INT_MIN does; because the absolute\n** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the\n** absolute value of the product 'frexp * -INT_MIN' is smaller or equal\n** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when\n** adding 'i'; the use of '~u' (instead of '-u') avoids problems with\n** INT_MIN.\n*/\n#if !defined(l_hashfloat)\nstatic int l_hashfloat (lua_Number n) {\n  int i;\n  lua_Integer ni;\n  n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);\n  if (!lua_numbertointeger(n, &ni)) {  /* is 'n' inf/-inf/NaN? */\n    lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));\n    return 0;\n  }\n  else {  /* normal case */\n    unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);\n    return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);\n  }\n}\n#endif\n\n\n/*\n** returns the 'main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMINT:\n      return hashint(t, ivalue(key));\n    case LUA_TNUMFLT:\n      return hashmod(t, l_hashfloat(fltvalue(key)));\n    case LUA_TSHRSTR:\n      return hashstr(t, tsvalue(key));\n    case LUA_TLNGSTR:\n      return hashpow2(t, luaS_hashlongstr(tsvalue(key)));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    case LUA_TLCF:\n      return hashpointer(t, fvalue(key));\n    default:\n      lua_assert(!ttisdeadkey(key));\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for 'key' if 'key' is an appropriate key to live in\n** the array part of the table, 0 otherwise.\n*/\nstatic unsigned int arrayindex (const TValue *key) {\n  if (ttisinteger(key)) {\n    lua_Integer k = ivalue(key);\n    if (0 < k && (lua_Unsigned)k <= MAXASIZE)\n      return cast(unsigned int, k);  /* 'key' is an appropriate array index */\n  }\n  return 0;  /* 'key' did not match some condition */\n}\n\n\n/*\n** returns the index of a 'key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signaled by 0.\n*/\nstatic unsigned int findindex (lua_State *L, Table *t, StkId key) {\n  unsigned int i;\n  if (ttisnil(key)) return 0;  /* first iteration */\n  i = arrayindex(key);\n  if (i != 0 && i <= t->sizearray)  /* is 'key' inside array part? */\n    return i;  /* yes; that's the index */\n  else {\n    int nx;\n    Node *n = mainposition(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in 'next' */\n      if (luaV_rawequalobj(gkey(n), key) ||\n            (ttisdeadkey(gkey(n)) && iscollectable(key) &&\n             deadvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return (i + 1) + t->sizearray;\n      }\n      nx = gnext(n);\n      if (nx == 0)\n        luaG_runerror(L, \"invalid key to 'next'\");  /* key not found */\n      else n += nx;\n    }\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  unsigned int i = findindex(L, t, key);  /* find original element */\n  for (; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setivalue(key, i + 1);\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) {  /* hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, gkey(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n/*\n** Compute the optimal size for the array part of table 't'. 'nums' is a\n** \"count array\" where 'nums[i]' is the number of integers in the table\n** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of\n** integer keys in the table and leaves with the number of keys that\n** will go to the array part; return the optimal size.\n*/\nstatic unsigned int computesizes (unsigned int nums[], unsigned int *pna) {\n  int i;\n  unsigned int twotoi;  /* 2^i (candidate for optimal size) */\n  unsigned int a = 0;  /* number of elements smaller than 2^i */\n  unsigned int na = 0;  /* number of elements to go to array part */\n  unsigned int optimal = 0;  /* optimal size for array part */\n  /* loop while keys can fill more than half of total size */\n  for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        optimal = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements up to 'optimal' will go to array part */\n      }\n    }\n  }\n  lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);\n  *pna = na;\n  return optimal;\n}\n\n\nstatic int countint (const TValue *key, unsigned int *nums) {\n  unsigned int k = arrayindex(key);\n  if (k != 0) {  /* is 'key' an appropriate array index? */\n    nums[luaO_ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Count keys in array part of table 't': Fill 'nums[i]' with\n** number of keys that will go into corresponding slice and return\n** total number of non-nil keys.\n*/\nstatic unsigned int numusearray (const Table *t, unsigned int *nums) {\n  int lg;\n  unsigned int ttlg;  /* 2^lg */\n  unsigned int ause = 0;  /* summation of 'nums' */\n  unsigned int i = 1;  /* count to traverse all array keys */\n  /* traverse each slice */\n  for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {\n    unsigned int lc = 0;  /* counter */\n    unsigned int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg - 1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* elements added to 'nums' (can go to array part) */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(gkey(n), nums);\n      totaluse++;\n    }\n  }\n  *pna += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, unsigned int size) {\n  unsigned int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic void setnodevector (lua_State *L, Table *t, unsigned int size) {\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common 'dummynode' */\n    t->lsizenode = 0;\n    t->lastfree = NULL;  /* signal that it is using dummy node */\n  }\n  else {\n    int i;\n    int lsize = luaO_ceillog2(size);\n    if (lsize > MAXHBITS)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i = 0; i < (int)size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = 0;\n      setnilvalue(wgkey(n));\n      setnilvalue(gval(n));\n    }\n    t->lsizenode = cast_byte(lsize);\n    t->lastfree = gnode(t, size);  /* all positions are free */\n  }\n}\n\n\nvoid luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                          unsigned int nhsize) {\n  unsigned int i;\n  int j;\n  unsigned int oldasize = t->sizearray;\n  int oldhsize = allocsizenode(t);\n  Node *nold = t->node;  /* save old hash ... */\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  /* create new hash part with appropriate size */\n  setnodevector(L, t, nhsize);\n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        luaH_setint(L, t, i + 1, &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n  /* re-insert elements from hash part */\n  for (j = oldhsize - 1; j >= 0; j--) {\n    Node *old = nold + j;\n    if (!ttisnil(gval(old))) {\n      /* doesn't need barrier/invalidate cache, as entry was\n         already present in the table */\n      setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));\n    }\n  }\n  if (oldhsize > 0)  /* not the dummy node? */\n    luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {\n  int nsize = allocsizenode(t);\n  luaH_resize(L, t, nasize, nsize);\n}\n\n/*\n** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i\n*/\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  unsigned int asize;  /* optimal size for array part */\n  unsigned int na;  /* number of keys in the array part */\n  unsigned int nums[MAXABITS + 1];\n  int i;\n  int totaluse;\n  for (i = 0; i <= MAXABITS; i++) nums[i] = 0;  /* reset counts */\n  na = numusearray(t, nums);  /* count keys in array part */\n  totaluse = na;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &na);  /* count keys in hash part */\n  /* count extra key */\n  na += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  asize = computesizes(nums, &na);\n  /* resize the table to new computed sizes */\n  luaH_resize(L, t, asize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));\n  Table *t = gco2t(o);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  t->array = NULL;\n  t->sizearray = 0;\n  setnodevector(L, t, 0);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (!isdummy(t))\n    luaM_freearray(L, t->node, cast(size_t, sizenode(t)));\n  luaM_freearray(L, t->array, t->sizearray);\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  if (!isdummy(t)) {\n    while (t->lastfree > t->node) {\n      t->lastfree--;\n      if (ttisnil(gkey(t->lastfree)))\n        return t->lastfree;\n    }\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main\n** position is free. If not, check whether colliding node is in its main\n** position or not: if it is not, move colliding node to an empty place and\n** put new key in its main position; otherwise (colliding node is in its main\n** position), new key goes to an empty position.\n*/\nTValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp;\n  TValue aux;\n  if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n  else if (ttisfloat(key)) {\n    lua_Integer k;\n    if (luaV_tointeger(key, &k, 0)) {  /* does index fit in an integer? */\n      setivalue(&aux, k);\n      key = &aux;  /* insert it as an integer */\n    }\n    else if (luai_numisnan(fltvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n  }\n  mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || isdummy(t)) {  /* main position is taken? */\n    Node *othern;\n    Node *f = getfreepos(t);  /* get a free place */\n    if (f == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      /* whatever called 'newkey' takes care of TM cache */\n      return luaH_set(L, t, key);  /* insert key into grown table */\n    }\n    lua_assert(!isdummy(t));\n    othern = mainposition(t, gkey(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (othern + gnext(othern) != mp)  /* find previous */\n        othern += gnext(othern);\n      gnext(othern) = cast_int(f - othern);  /* rechain to point to 'f' */\n      *f = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      if (gnext(mp) != 0) {\n        gnext(f) += cast_int(mp - f);  /* correct 'next' */\n        gnext(mp) = 0;  /* now 'mp' is free */\n      }\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      if (gnext(mp) != 0)\n        gnext(f) = cast_int((mp + gnext(mp)) - f);  /* chain new position */\n      else lua_assert(gnext(f) == 0);\n      gnext(mp) = cast_int(f - mp);\n      mp = f;\n    }\n  }\n  setnodekey(L, &mp->i_key, key);\n  luaC_barrierback(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getint (Table *t, lua_Integer key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (l_castS2U(key) - 1 < t->sizearray)\n    return &t->array[key - 1];\n  else {\n    Node *n = hashint(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)\n        return gval(n);  /* that's it */\n      else {\n        int nx = gnext(n);\n        if (nx == 0) break;\n        n += nx;\n      }\n    }\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for short strings\n*/\nconst TValue *luaH_getshortstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  lua_assert(key->tt == LUA_TSHRSTR);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    const TValue *k = gkey(n);\n    if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\n/*\n** \"Generic\" get version. (Not that generic: not valid for integers,\n** which may be in array part, nor for floats with integral values.)\n*/\nstatic const TValue *getgeneric (Table *t, const TValue *key) {\n  Node *n = mainposition(t, key);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (luaV_rawequalobj(gkey(n), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  if (key->tt == LUA_TSHRSTR)\n    return luaH_getshortstr(t, key);\n  else {  /* for long strings, use generic case */\n    TValue ko;\n    setsvalue(cast(lua_State *, NULL), &ko, key);\n    return getgeneric(t, &ko);\n  }\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));\n    case LUA_TNUMINT: return luaH_getint(t, ivalue(key));\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TNUMFLT: {\n      lua_Integer k;\n      if (luaV_tointeger(key, &k, 0)) /* index is int? */\n        return luaH_getint(t, k);  /* use specialized version */\n      /* else... */\n    }  /* FALLTHROUGH */\n    default:\n      return getgeneric(t, key);\n  }\n}\n\n\n/*\n** beware: when using this function you probably need to check a GC\n** barrier and invalidate the TM cache.\n*/\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else return luaH_newkey(L, t, key);\n}\n\n\nvoid luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {\n  const TValue *p = luaH_getint(t, key);\n  TValue *cell;\n  if (p != luaO_nilobject)\n    cell = cast(TValue *, p);\n  else {\n    TValue k;\n    setivalue(&k, key);\n    cell = luaH_newkey(L, t, &k);\n  }\n  setobj2t(L, cell, value);\n}\n\n\nstatic int unbound_search (Table *t, unsigned int j) {\n  unsigned int i = j;  /* i is zero or a present index */\n  j++;\n  /* find 'i' and 'j' such that i is present and j is not */\n  while (!ttisnil(luaH_getint(t, j))) {\n    i = j;\n    if (j > cast(unsigned int, MAX_INT)/2) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getint(t, i))) i++;\n      return i - 1;\n    }\n    j *= 2;\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    unsigned int m = (i+j)/2;\n    if (ttisnil(luaH_getint(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table 't'. A 'boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nint luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (isdummy(t))  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (const Table *t) { return isdummy(t); }\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n\n/* 'const' to avoid wrong writings that can mess up field 'next' */\n#define gkey(n)\t\tcast(const TValue*, (&(n)->i_key.tvk))\n\n/*\n** writable version of 'gkey'; allows updates to individual fields,\n** but not to the whole (which has incompatible type)\n*/\n#define wgkey(n)\t\t(&(n)->i_key.nk)\n\n#define invalidateTMcache(t)\t((t)->flags = 0)\n\n\n/* true when 't' is using 'dummynode' as its hash part */\n#define isdummy(t)\t\t((t)->lastfree == NULL)\n\n\n/* allocated size for hash nodes */\n#define allocsizenode(t)\t(isdummy(t) ? 0 : sizenode(t))\n\n\n/* returns the key, given the value of a table entry */\n#define keyfromval(v) \\\n  (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))\n\n\nLUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);\nLUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,\n                                                    TValue *value);\nLUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L);\nLUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                                    unsigned int nhsize);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC int luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (const Table *t);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** Operations that an object must define to mimic a table\n** (some functions only need some of them)\n*/\n#define TAB_R\t1\t\t\t/* read */\n#define TAB_W\t2\t\t\t/* write */\n#define TAB_L\t4\t\t\t/* length */\n#define TAB_RW\t(TAB_R | TAB_W)\t\t/* read/write */\n\n\n#define aux_getn(L,n,w)\t(checktab(L, n, (w) | TAB_L), luaL_len(L, n))\n\n\nstatic int checkfield (lua_State *L, const char *key, int n) {\n  lua_pushstring(L, key);\n  return (lua_rawget(L, -n) != LUA_TNIL);\n}\n\n\n/*\n** Check that 'arg' either is a table or can behave like one (that is,\n** has a metatable with the required metamethods)\n*/\nstatic void checktab (lua_State *L, int arg, int what) {\n  if (lua_type(L, arg) != LUA_TTABLE) {  /* is it not a table? */\n    int n = 1;  /* number of elements to pop */\n    if (lua_getmetatable(L, arg) &&  /* must have metatable */\n        (!(what & TAB_R) || checkfield(L, \"__index\", ++n)) &&\n        (!(what & TAB_W) || checkfield(L, \"__newindex\", ++n)) &&\n        (!(what & TAB_L) || checkfield(L, \"__len\", ++n))) {\n      lua_pop(L, n);  /* pop metatable and tested metamethods */\n    }\n    else\n      luaL_checktype(L, arg, LUA_TTABLE);  /* force an error */\n  }\n}\n\n\n#if defined(LUA_COMPAT_MAXN)\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n#endif\n\n\nstatic int tinsert (lua_State *L) {\n  lua_Integer e = aux_getn(L, 1, TAB_RW) + 1;  /* first empty element */\n  lua_Integer pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      lua_Integer i;\n      pos = luaL_checkinteger(L, 2);  /* 2nd argument is the position */\n      luaL_argcheck(L, 1 <= pos && pos <= e, 2, \"position out of bounds\");\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_geti(L, 1, i - 1);\n        lua_seti(L, 1, i);  /* t[i] = t[i - 1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to 'insert'\");\n    }\n  }\n  lua_seti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  lua_Integer size = aux_getn(L, 1, TAB_RW);\n  lua_Integer pos = luaL_optinteger(L, 2, size);\n  if (pos != size)  /* validate 'pos' if given */\n    luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, \"position out of bounds\");\n  lua_geti(L, 1, pos);  /* result = t[pos] */\n  for ( ; pos < size; pos++) {\n    lua_geti(L, 1, pos + 1);\n    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */\n  }\n  lua_pushnil(L);\n  lua_seti(L, 1, pos);  /* t[pos] = nil */\n  return 1;\n}\n\n\n/*\n** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever\n** possible, copy in increasing order, which is better for rehashing.\n** \"possible\" means destination after original range, or smaller\n** than origin, or copying to another table.\n*/\nstatic int tmove (lua_State *L) {\n  lua_Integer f = luaL_checkinteger(L, 2);\n  lua_Integer e = luaL_checkinteger(L, 3);\n  lua_Integer t = luaL_checkinteger(L, 4);\n  int tt = !lua_isnoneornil(L, 5) ? 5 : 1;  /* destination table */\n  checktab(L, 1, TAB_R);\n  checktab(L, tt, TAB_W);\n  if (e >= f) {  /* otherwise, nothing to move */\n    lua_Integer n, i;\n    luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,\n                  \"too many elements to move\");\n    n = e - f + 1;  /* number of elements to move */\n    luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,\n                  \"destination wrap around\");\n    if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {\n      for (i = 0; i < n; i++) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n    else {\n      for (i = n - 1; i >= 0; i--) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n  }\n  lua_pushvalue(L, tt);  /* return destination table */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {\n  lua_geti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for 'concat'\",\n                  luaL_typename(L, -1), i);\n  luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  lua_Integer last = aux_getn(L, 1, TAB_R);\n  size_t lsep;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  lua_Integer i = luaL_optinteger(L, 3, 1);\n  last = luaL_optinteger(L, 4, last);\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Pack/unpack\n** =======================================================\n*/\n\nstatic int pack (lua_State *L) {\n  int i;\n  int n = lua_gettop(L);  /* number of elements to pack */\n  lua_createtable(L, n, 1);  /* create result table */\n  lua_insert(L, 1);  /* put it at index 1 */\n  for (i = n; i >= 1; i--)  /* assign elements */\n    lua_seti(L, 1, i);\n  lua_pushinteger(L, n);\n  lua_setfield(L, 1, \"n\");  /* t.n = number of elements */\n  return 1;  /* return table */\n}\n\n\nstatic int unpack (lua_State *L) {\n  lua_Unsigned n;\n  lua_Integer i = luaL_optinteger(L, 2, 1);\n  lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */\n  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, (int)(++n)))\n    return luaL_error(L, \"too many results to unpack\");\n  for (; i < e; i++) {  /* push arg[i..e - 1] (to avoid overflows) */\n    lua_geti(L, 1, i);\n  }\n  lua_geti(L, 1, e);  /* push last element */\n  return (int)n;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on 'Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n** =======================================================\n*/\n\n\n/* type for array indices */\ntypedef unsigned int IdxT;\n\n\n/*\n** Produce a \"random\" 'unsigned int' to randomize pivot choice. This\n** macro is used only when 'sort' detects a big imbalance in the result\n** of a partition. (If you don't want/need this \"randomness\", ~0 is a\n** good choice.)\n*/\n#if !defined(l_randomizePivot)\t\t/* { */\n\n#include <time.h>\n\n/* size of 'e' measured in number of 'unsigned int's */\n#define sof(e)\t\t(sizeof(e) / sizeof(unsigned int))\n\n/*\n** Use 'time' and 'clock' as sources of \"randomness\". Because we don't\n** know the types 'clock_t' and 'time_t', we cannot cast them to\n** anything without risking overflows. A safe way to use their values\n** is to copy them to an array of a known type and use the array values.\n*/\nstatic unsigned int l_randomizePivot (void) {\n  clock_t c = clock();\n  time_t t = time(NULL);\n  unsigned int buff[sof(c) + sof(t)];\n  unsigned int i, rnd = 0;\n  memcpy(buff, &c, sof(c) * sizeof(unsigned int));\n  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));\n  for (i = 0; i < sof(buff); i++)\n    rnd += buff[i];\n  return rnd;\n}\n\n#endif\t\t\t\t\t/* } */\n\n\n/* arrays larger than 'RANLIMIT' may use randomized pivots */\n#define RANLIMIT\t100u\n\n\nstatic void set2 (lua_State *L, IdxT i, IdxT j) {\n  lua_seti(L, 1, i);\n  lua_seti(L, 1, j);\n}\n\n\n/*\n** Return true iff value at stack index 'a' is less than the value at\n** index 'b' (according to the order of the sort).\n*/\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (lua_isnil(L, 2))  /* no function? */\n    return lua_compare(L, a, b, LUA_OPLT);  /* a < b */\n  else {  /* function */\n    int res;\n    lua_pushvalue(L, 2);    /* push function */\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and 'a' */\n    lua_call(L, 2, 1);      /* call function */\n    res = lua_toboolean(L, -1);  /* get result */\n    lua_pop(L, 1);          /* pop result */\n    return res;\n  }\n}\n\n\n/*\n** Does the partition: Pivot P is at the top of the stack.\n** precondition: a[lo] <= P == a[up-1] <= a[up],\n** so it only needs to do the partition from lo + 1 to up - 2.\n** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]\n** returns 'i'.\n*/\nstatic IdxT partition (lua_State *L, IdxT lo, IdxT up) {\n  IdxT i = lo;  /* will be incremented before first use */\n  IdxT j = up - 1;  /* will be decremented before first use */\n  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */\n  for (;;) {\n    /* next loop: repeat ++i while a[i] < P */\n    while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {\n      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[i] */\n    }\n    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */\n    /* next loop: repeat --j while P < a[j] */\n    while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {\n      if (j < i)  /* j < i  but  a[j] > P ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[j] */\n    }\n    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */\n    if (j < i) {  /* no elements out of place? */\n      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */\n      lua_pop(L, 1);  /* pop a[j] */\n      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */\n      set2(L, up - 1, i);\n      return i;\n    }\n    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */\n    set2(L, i, j);\n  }\n}\n\n\n/*\n** Choose an element in the middle (2nd-3th quarters) of [lo,up]\n** \"randomized\" by 'rnd'\n*/\nstatic IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {\n  IdxT r4 = (up - lo) / 4;  /* range/4 */\n  IdxT p = rnd % (r4 * 2) + (lo + r4);\n  lua_assert(lo + r4 <= p && p <= up - r4);\n  return p;\n}\n\n\n/*\n** QuickSort algorithm (recursive function)\n*/\nstatic void auxsort (lua_State *L, IdxT lo, IdxT up,\n                                   unsigned int rnd) {\n  while (lo < up) {  /* loop for tail recursion */\n    IdxT p;  /* Pivot index */\n    IdxT n;  /* to be used later */\n    /* sort elements 'lo', 'p', and 'up' */\n    lua_geti(L, 1, lo);\n    lua_geti(L, 1, up);\n    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */\n      set2(L, lo, up);  /* swap a[lo] - a[up] */\n    else\n      lua_pop(L, 2);  /* remove both values */\n    if (up - lo == 1)  /* only 2 elements? */\n      return;  /* already sorted */\n    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */\n      p = (lo + up)/2;  /* middle element is a good pivot */\n    else  /* for larger intervals, it is worth a random pivot */\n      p = choosePivot(lo, up, rnd);\n    lua_geti(L, 1, p);\n    lua_geti(L, 1, lo);\n    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */\n      set2(L, p, lo);  /* swap a[p] - a[lo] */\n    else {\n      lua_pop(L, 1);  /* remove a[lo] */\n      lua_geti(L, 1, up);\n      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */\n        set2(L, p, up);  /* swap a[up] - a[p] */\n      else\n        lua_pop(L, 2);\n    }\n    if (up - lo == 2)  /* only 3 elements? */\n      return;  /* already sorted */\n    lua_geti(L, 1, p);  /* get middle element (Pivot) */\n    lua_pushvalue(L, -1);  /* push Pivot */\n    lua_geti(L, 1, up - 1);  /* push a[up - 1] */\n    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */\n    p = partition(L, lo, up);\n    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */\n    if (p - lo < up - p) {  /* lower interval is smaller? */\n      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */\n      n = p - lo;  /* size of smaller interval */\n      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */\n    }\n    else {\n      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */\n      n = up - p;  /* size of smaller interval */\n      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */\n    }\n    if ((up - lo) / 128 > n) /* partition too imbalanced? */\n      rnd = l_randomizePivot();  /* try a new randomization */\n  }  /* tail call auxsort(L, lo, up, rnd) */\n}\n\n\nstatic int sort (lua_State *L) {\n  lua_Integer n = aux_getn(L, 1, TAB_RW);\n  if (n > 1) {  /* non-trivial interval? */\n    luaL_argcheck(L, n < INT_MAX, 1, \"array too big\");\n    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */\n    lua_settop(L, 2);  /* make sure there are two arguments */\n    auxsort(L, 1, (IdxT)n, 0);\n  }\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n#if defined(LUA_COMPAT_MAXN)\n  {\"maxn\", maxn},\n#endif\n  {\"insert\", tinsert},\n  {\"pack\", pack},\n  {\"unpack\", unpack},\n  {\"remove\", tremove},\n  {\"move\", tmove},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_table (lua_State *L) {\n  luaL_newlib(L, tab_funcs);\n#if defined(LUA_COMPAT_UNPACK)\n  /* _G.unpack = table.unpack */\n  lua_getfield(L, -1, \"unpack\");\n  lua_setglobal(L, \"unpack\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.38 2016/12/22 13:08:50 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\nstatic const char udatatypename[] = \"userdata\";\n\nLUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {\n  \"no value\",\n  \"nil\", \"boolean\", udatatypename, \"number\",\n  \"string\", \"table\", \"function\", udatatypename, \"thread\",\n  \"proto\" /* this last case is used for tests only */\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__len\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__mod\", \"__pow\",\n    \"__div\", \"__idiv\",\n    \"__band\", \"__bor\", \"__bxor\", \"__shl\", \"__shr\",\n    \"__unm\", \"__bnot\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaC_fix(L, obj2gco(G(L)->tmname[i]));  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getshortstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttnov(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(o)];\n  }\n  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n\n/*\n** Return the name of the type of an object. For tables and userdata\n** with metatable, use their '__name' metafield, if present.\n*/\nconst char *luaT_objtypename (lua_State *L, const TValue *o) {\n  Table *mt;\n  if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||\n      (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {\n    const TValue *name = luaH_getshortstr(mt, luaS_new(L, \"__name\"));\n    if (ttisstring(name))  /* is '__name' a string? */\n      return getstr(tsvalue(name));  /* use it as type name */\n  }\n  return ttypename(ttnov(o));  /* else use standard type name */\n}\n\n\nvoid luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                  const TValue *p2, TValue *p3, int hasres) {\n  ptrdiff_t result = savestack(L, p3);\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  L->top += 3;\n  if (!hasres)  /* no result? 'p3' is third argument */\n    setobj2s(L, L->top++, p3);  /* 3rd argument */\n  /* metamethod may yield only when called from Lua code */\n  if (isLua(L->ci))\n    luaD_call(L, func, hasres);\n  else\n    luaD_callnoyield(L, func, hasres);\n  if (hasres) {  /* if has result, move it to its place */\n    p3 = restorestack(L, result);\n    setobjs2s(L, p3, --L->top);\n  }\n}\n\n\nint luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  luaT_callTM(L, tm, p1, p2, res, 1);\n  return 1;\n}\n\n\nvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, res, event)) {\n    switch (event) {\n      case TM_CONCAT:\n        luaG_concaterror(L, p1, p2);\n      /* call never returns, but to avoid warnings: *//* FALLTHROUGH */\n      case TM_BAND: case TM_BOR: case TM_BXOR:\n      case TM_SHL: case TM_SHR: case TM_BNOT: {\n        lua_Number dummy;\n        if (tonumber(p1, &dummy) && tonumber(p2, &dummy))\n          luaG_tointerror(L, p1, p2);\n        else\n          luaG_opinterror(L, p1, p2, \"perform bitwise operation on\");\n      }\n      /* calls never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:\n        luaG_opinterror(L, p1, p2, \"perform arithmetic on\");\n    }\n  }\n}\n\n\nint luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, L->top, event))\n    return -1;  /* no metamethod */\n  else\n    return !l_isfalse(L->top);\n}\n\n"
  },
  {
    "path": "WebGLPlugins/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\" and \"ORDER OP\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_LEN,\n  TM_EQ,  /* last tag method with fast access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_MOD,\n  TM_POW,\n  TM_DIV,\n  TM_IDIV,\n  TM_BAND,\n  TM_BOR,\n  TM_BXOR,\n  TM_SHL,\n  TM_SHR,\n  TM_UNM,\n  TM_BNOT,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\n#define ttypename(x)\tluaT_typenames_[(x) + 1]\n\nLUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];\n\n\nLUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\nLUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                            const TValue *p2, TValue *p3, int hasres);\nLUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,\n                                const TValue *p2, TMS event);\n\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.230 2017/01/12 17:14:26 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n#define lua_c\n\n#include \"lprefix.h\"\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n#if !defined(LUA_PROMPT)\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n#endif\n\n#if !defined(LUA_PROGNAME)\n#define LUA_PROGNAME\t\t\"lua\"\n#endif\n\n#if !defined(LUA_MAXINPUT)\n#define LUA_MAXINPUT\t\t512\n#endif\n\n#if !defined(LUA_INIT_VAR)\n#define LUA_INIT_VAR\t\t\"LUA_INIT\"\n#endif\n\n#define LUA_INITVARVERSION\tLUA_INIT_VAR LUA_VERSUFFIX\n\n\n/*\n** lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n** is, whether we're running lua interactively).\n*/\n#if !defined(lua_stdin_is_tty)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#include <io.h>\n#include <windows.h>\n\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definition */\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** lua_readline defines how to show a prompt and then read a line from\n** the standard input.\n** lua_saveline defines how to \"save\" a read line in a \"history\".\n** lua_freeline defines how to free a line read by lua_readline.\n*/\n#if !defined(lua_readline)\t/* { */\n\n#if defined(LUA_USE_READLINE)\t/* { */\n\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,line)\t((void)L, add_history(line))\n#define lua_freeline(L,b)\t((void)L, free(b))\n\n#else\t\t\t\t/* }{ */\n\n#define lua_readline(L,b,p) \\\n        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,line)\t{ (void)L; (void)line; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n/*\n** Hook set by signal function to stop the interpreter.\n*/\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);  /* reset hook */\n  luaL_error(L, \"interrupted!\");\n}\n\n\n/*\n** Function to be called at a C signal. Because a C signal cannot\n** just change a Lua state (as there is no proper synchronization),\n** this function only sets a hook that, when called, will stop the\n** interpreter.\n*/\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (const char *badoption) {\n  lua_writestringerror(\"%s: \", progname);\n  if (badoption[1] == 'e' || badoption[1] == 'l')\n    lua_writestringerror(\"'%s' needs argument\\n\", badoption);\n  else\n    lua_writestringerror(\"unrecognized option '%s'\\n\", badoption);\n  lua_writestringerror(\n  \"usage: %s [options] [script [args]]\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string 'stat'\\n\"\n  \"  -i       enter interactive mode after executing 'script'\\n\"\n  \"  -l name  require library 'name'\\n\"\n  \"  -v       show version information\\n\"\n  \"  -E       ignore environment variables\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and execute stdin\\n\"\n  ,\n  progname);\n}\n\n\n/*\n** Prints an error message, adding the program name in front of it\n** (if present)\n*/\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) lua_writestringerror(\"%s: \", pname);\n  lua_writestringerror(\"%s\\n\", msg);\n}\n\n\n/*\n** Check whether 'status' is not OK and, if so, prints the error\n** message on the top of the stack. It assumes that the error object\n** is a string, as it was either generated by Lua or by 'msghandler'.\n*/\nstatic int report (lua_State *L, int status) {\n  if (status != LUA_OK) {\n    const char *msg = lua_tostring(L, -1);\n    l_message(progname, msg);\n    lua_pop(L, 1);  /* remove message */\n  }\n  return status;\n}\n\n\n/*\n** Message handler used to run all chunks\n*/\nstatic int msghandler (lua_State *L) {\n  const char *msg = lua_tostring(L, 1);\n  if (msg == NULL) {  /* is error object not a string? */\n    if (luaL_callmeta(L, 1, \"__tostring\") &&  /* does it have a metamethod */\n        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */\n      return 1;  /* that is the message */\n    else\n      msg = lua_pushfstring(L, \"(error object is a %s value)\",\n                               luaL_typename(L, 1));\n  }\n  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */\n  return 1;  /* return the traceback */\n}\n\n\n/*\n** Interface to 'lua_pcall', which sets appropriate message function\n** and C-signal handler. Used to run all chunks.\n*/\nstatic int docall (lua_State *L, int narg, int nres) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, msghandler);  /* push message handler */\n  lua_insert(L, base);  /* put it under function and args */\n  globalL = L;  /* to be available to 'laction' */\n  signal(SIGINT, laction);  /* set C-signal handler */\n  status = lua_pcall(L, narg, nres, base);\n  signal(SIGINT, SIG_DFL); /* reset C-signal handler */\n  lua_remove(L, base);  /* remove message handler from the stack */\n  return status;\n}\n\n\nstatic void print_version (void) {\n  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));\n  lua_writeline();\n}\n\n\n/*\n** Create the 'arg' table, which stores all arguments from the\n** command line ('argv'). It should be aligned so that, at index 0,\n** it has 'argv[script]', which is the script name. The arguments\n** to the script (everything after 'script') go to positive indices;\n** other arguments (before the script name) go to negative indices.\n** If there is no script name, assume interpreter's name as base.\n*/\nstatic void createargtable (lua_State *L, char **argv, int argc, int script) {\n  int i, narg;\n  if (script == argc) script = 0;  /* no script name? */\n  narg = argc - (script + 1);  /* number of positive indices */\n  lua_createtable(L, narg, script + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - script);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\n\nstatic int dochunk (lua_State *L, int status) {\n  if (status == LUA_OK) status = docall(L, 0, 0);\n  return report(L, status);\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  return dochunk(L, luaL_loadfile(L, name));\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));\n}\n\n\n/*\n** Calls 'require(name)' and stores the result in a global variable\n** with the given name.\n*/\nstatic int dolibrary (lua_State *L, const char *name) {\n  int status;\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  status = docall(L, 1, 1);  /* call 'require(name)' */\n  if (status == LUA_OK)\n    lua_setglobal(L, name);  /* global[name] = require return */\n  return report(L, status);\n}\n\n\n/*\n** Returns the string to be used as a prompt by the interpreter.\n*/\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getglobal(L, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  return p;\n}\n\n/* mark in error messages for incomplete statements */\n#define EOFMARK\t\t\"<eof>\"\n#define marklen\t\t(sizeof(EOFMARK)/sizeof(char) - 1)\n\n\n/*\n** Check whether 'status' signals a syntax error and the error\n** message at the top of the stack ends with the above mark for\n** incomplete statements.\n*/\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\n/*\n** Prompt the user, read a line, and push it into the Lua stack.\n*/\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  int readstatus = lua_readline(L, b, prmt);\n  if (readstatus == 0)\n    return 0;  /* no input (prompt will be popped by caller) */\n  lua_pop(L, 1);  /* remove prompt */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[--l] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */\n    lua_pushfstring(L, \"return %s\", b + 1);  /* change '=' to 'return' */\n  else\n    lua_pushlstring(L, b, l);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\n/*\n** Try to compile line on the stack as 'return <line>;'; on return, stack\n** has either compiled chunk or original line (if compilation failed).\n*/\nstatic int addreturn (lua_State *L) {\n  const char *line = lua_tostring(L, -1);  /* original line */\n  const char *retline = lua_pushfstring(L, \"return %s;\", line);\n  int status = luaL_loadbuffer(L, retline, strlen(retline), \"=stdin\");\n  if (status == LUA_OK) {\n    lua_remove(L, -2);  /* remove modified line */\n    if (line[0] != '\\0')  /* non empty? */\n      lua_saveline(L, line);  /* keep history */\n  }\n  else\n    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */\n  return status;\n}\n\n\n/*\n** Read multiple lines until a complete Lua statement\n*/\nstatic int multiline (lua_State *L) {\n  for (;;) {  /* repeat until gets a complete statement */\n    size_t len;\n    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */\n    int status = luaL_loadbuffer(L, line, len, \"=stdin\");  /* try it */\n    if (!incomplete(L, status) || !pushline(L, 0)) {\n      lua_saveline(L, line);  /* keep history */\n      return status;  /* cannot or should not try to add continuation line */\n    }\n    lua_pushliteral(L, \"\\n\");  /* add newline... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n}\n\n\n/*\n** Read a line and try to load (compile) it first as an expression (by\n** adding \"return \" in front of it) and second as a statement. Return\n** the final status of load/call with the resulting function (if any)\n** in the top of the stack.\n*/\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */\n    status = multiline(L);  /* try as command, maybe with continuation lines */\n  lua_remove(L, 1);  /* remove line from the stack */\n  lua_assert(lua_gettop(L) == 1);\n  return status;\n}\n\n\n/*\n** Prints (calling the Lua 'print' function) any values on the stack\n*/\nstatic void l_print (lua_State *L) {\n  int n = lua_gettop(L);\n  if (n > 0) {  /* any result to be printed? */\n    luaL_checkstack(L, LUA_MINSTACK, \"too many results to print\");\n    lua_getglobal(L, \"print\");\n    lua_insert(L, 1);\n    if (lua_pcall(L, n, 0, 0) != LUA_OK)\n      l_message(progname, lua_pushfstring(L, \"error calling 'print' (%s)\",\n                                             lua_tostring(L, -1)));\n  }\n}\n\n\n/*\n** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and\n** print any results.\n*/\nstatic void doREPL (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;  /* no 'progname' on errors in interactive mode */\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK)\n      status = docall(L, 0, LUA_MULTRET);\n    if (status == LUA_OK) l_print(L);\n    else report(L, status);\n  }\n  lua_settop(L, 0);  /* clear stack */\n  lua_writeline();\n  progname = oldprogname;\n}\n\n\n/*\n** Push on the stack the contents of table 'arg' from 1 to #arg\n*/\nstatic int pushargs (lua_State *L) {\n  int i, n;\n  if (lua_getglobal(L, \"arg\") != LUA_TTABLE)\n    luaL_error(L, \"'arg' is not a table\");\n  n = (int)luaL_len(L, -1);\n  luaL_checkstack(L, n + 3, \"too many arguments to script\");\n  for (i = 1; i <= n; i++)\n    lua_rawgeti(L, -i, i);\n  lua_remove(L, -i);  /* remove table from the stack */\n  return n;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv) {\n  int status;\n  const char *fname = argv[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    int n = pushargs(L);  /* push arguments to script */\n    status = docall(L, n, LUA_MULTRET);\n  }\n  return report(L, status);\n}\n\n\n\n/* bits of various argument indicators in 'args' */\n#define has_error\t1\t/* bad option */\n#define has_i\t\t2\t/* -i */\n#define has_v\t\t4\t/* -v */\n#define has_e\t\t8\t/* -e */\n#define has_E\t\t16\t/* -E */\n\n/*\n** Traverses all arguments from 'argv', returning a mask with those\n** needed before running any Lua code (or an error code if it finds\n** any invalid argument). 'first' returns the first not-handled argument\n** (either the script name or a bad argument in case of error).\n*/\nstatic int collectargs (char **argv, int *first) {\n  int args = 0;\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    *first = i;\n    if (argv[i][0] != '-')  /* not an option? */\n        return args;  /* stop handling options */\n    switch (argv[i][1]) {  /* else check option */\n      case '-':  /* '--' */\n        if (argv[i][2] != '\\0')  /* extra characters after '--'? */\n          return has_error;  /* invalid option */\n        *first = i + 1;\n        return args;\n      case '\\0':  /* '-' */\n        return args;  /* script \"name\" is '-' */\n      case 'E':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_E;\n        break;\n      case 'i':\n        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */\n      case 'v':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_v;\n        break;\n      case 'e':\n        args |= has_e;  /* FALLTHROUGH */\n      case 'l':  /* both options need an argument */\n        if (argv[i][2] == '\\0') {  /* no concatenated argument? */\n          i++;  /* try next 'argv' */\n          if (argv[i] == NULL || argv[i][0] == '-')\n            return has_error;  /* no next argument or it is another option */\n        }\n        break;\n      default:  /* invalid option */\n        return has_error;\n    }\n  }\n  *first = i;  /* no script name */\n  return args;\n}\n\n\n/*\n** Processes options 'e' and 'l', which involve running Lua code.\n** Returns 0 if some code raises an error.\n*/\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    int option = argv[i][1];\n    lua_assert(argv[i][0] == '-');  /* already checked */\n    if (option == 'e' || option == 'l') {\n      int status;\n      const char *extra = argv[i] + 2;  /* both options need an argument */\n      if (*extra == '\\0') extra = argv[++i];\n      lua_assert(extra != NULL);\n      status = (option == 'e')\n               ? dostring(L, extra, \"=(command line)\")\n               : dolibrary(L, extra);\n      if (status != LUA_OK) return 0;\n    }\n  }\n  return 1;\n}\n\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *name = \"=\" LUA_INITVARVERSION;\n  const char *init = getenv(name + 1);\n  if (init == NULL) {\n    name = \"=\" LUA_INIT_VAR;\n    init = getenv(name + 1);  /* try alternative name */\n  }\n  if (init == NULL) return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, name);\n}\n\n\n/*\n** Main body of stand-alone interpreter (to be called in protected mode).\n** Reads the options and handles them all.\n*/\nstatic int pmain (lua_State *L) {\n  int argc = (int)lua_tointeger(L, 1);\n  char **argv = (char **)lua_touserdata(L, 2);\n  int script;\n  int args = collectargs(argv, &script);\n  luaL_checkversion(L);  /* check that interpreter has correct version */\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  if (args == has_error) {  /* bad arg? */\n    print_usage(argv[script]);  /* 'script' has index of bad arg. */\n    return 0;\n  }\n  if (args & has_v)  /* option '-v'? */\n    print_version();\n  if (args & has_E) {  /* option '-E'? */\n    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  luaL_openlibs(L);  /* open standard libraries */\n  createargtable(L, argv, argc, script);  /* create table 'arg' */\n  if (!(args & has_E)) {  /* no option '-E'? */\n    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */\n      return 0;  /* error running LUA_INIT */\n  }\n  if (!runargs(L, argv, script))  /* execute arguments -e and -l */\n    return 0;  /* something failed */\n  if (script < argc &&  /* execute main script (if there is one) */\n      handle_script(L, argv + script) != LUA_OK)\n    return 0;\n  if (args & has_i)  /* -i option? */\n    doREPL(L);  /* do read-eval-print loop */\n  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */\n    if (lua_stdin_is_tty()) {  /* running in interactive mode? */\n      print_version();\n      doREPL(L);  /* do read-eval-print loop */\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  lua_pushboolean(L, 1);  /* signal no errors */\n  return 1;\n}\n\n\nint main (int argc, char **argv) {\n  int status, result;\n  lua_State *L = luaL_newstate();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */\n  lua_pushinteger(L, argc);  /* 1st argument */\n  lua_pushlightuserdata(L, argv); /* 2nd argument */\n  status = lua_pcall(L, 2, 1, 0);  /* do the call */\n  result = lua_toboolean(L, -1);  /* get result */\n  report(L, status);\n  lua_close(L);\n  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.332 2016/12/22 15:51:20 roberto Exp $\n** Lua - A Scripting Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION_MAJOR\t\"5\"\n#define LUA_VERSION_MINOR\t\"3\"\n#define LUA_VERSION_NUM\t\t503\n#define LUA_VERSION_RELEASE\t\"4\"\n\n#define LUA_VERSION\t\"Lua \" LUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#define LUA_RELEASE\tLUA_VERSION \".\" LUA_VERSION_RELEASE\n#define LUA_COPYRIGHT\tLUA_RELEASE \"  Copyright (C) 1994-2017 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo, W. Celes\"\n\n\n/* mark for precompiled code ('<esc>Lua') */\n#define LUA_SIGNATURE\t\"\\x1bLua\"\n\n/* option for multiple returns in 'lua_pcall' and 'lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** Pseudo-indices\n** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty\n** space after that to help overflow detection)\n*/\n#define LUA_REGISTRYINDEX\t(-LUAI_MAXSTACK - 1000)\n#define lua_upvalueindex(i)\t(LUA_REGISTRYINDEX - (i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRGCMM\t5\n#define LUA_ERRERR\t6\n\n\ntypedef struct lua_State lua_State;\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n#define LUA_NUMTAGS\t\t9\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/* predefined values in the registry */\n#define LUA_RIDX_MAINTHREAD\t1\n#define LUA_RIDX_GLOBALS\t2\n#define LUA_RIDX_LAST\t\tLUA_RIDX_GLOBALS\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n/* unsigned integer type */\ntypedef LUA_UNSIGNED lua_Unsigned;\n\n/* type for continuation-function contexts */\ntypedef LUA_KCONTEXT lua_KContext;\n\n\n/*\n** Type for C functions registered with Lua\n*/\ntypedef int (*lua_CFunction) (lua_State *L);\n\n/*\n** Type for continuation functions\n*/\ntypedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);\n\n\n/*\n** Type for functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);\n\n\n/*\n** Type for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/*\n** RCS ident string\n*/\nextern const char lua_ident[];\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\nLUA_API const lua_Number *(lua_version) (lua_State *L);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_absindex) (lua_State *L, int idx);\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_rotate) (lua_State *L, int idx, int n);\nLUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);\nLUA_API int   (lua_checkstack) (lua_State *L, int n);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isinteger) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_rawlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** Comparison and arithmetic functions\n*/\n\n#define LUA_OPADD\t0\t/* ORDER TM, ORDER OP */\n#define LUA_OPSUB\t1\n#define LUA_OPMUL\t2\n#define LUA_OPMOD\t3\n#define LUA_OPPOW\t4\n#define LUA_OPDIV\t5\n#define LUA_OPIDIV\t6\n#define LUA_OPBAND\t7\n#define LUA_OPBOR\t8\n#define LUA_OPBXOR\t9\n#define LUA_OPSHL\t10\n#define LUA_OPSHR\t11\n#define LUA_OPUNM\t12\n#define LUA_OPBNOT\t13\n\nLUA_API void  (lua_arith) (lua_State *L, int op);\n\n#define LUA_OPEQ\t0\n#define LUA_OPLT\t1\n#define LUA_OPLE\t2\n\nLUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void        (lua_pushnil) (lua_State *L);\nLUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);\nLUA_API const char *(lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API int (lua_getglobal) (lua_State *L, const char *name);\nLUA_API int (lua_gettable) (lua_State *L, int idx);\nLUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawget) (lua_State *L, int idx);\nLUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);\n\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API int  (lua_getuservalue) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_setglobal) (lua_State *L, const char *name);\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_seti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_setuservalue) (lua_State *L, int idx);\n\n\n/*\n** 'load' and 'call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,\n                           lua_KContext ctx, lua_KFunction k);\n#define lua_call(L,n,r)\t\tlua_callk(L, (n), (r), 0, NULL)\n\nLUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,\n                            lua_KContext ctx, lua_KFunction k);\n#define lua_pcall(L,n,r,f)\tlua_pcallk(L, (n), (r), (f), 0, NULL)\n\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                          const char *chunkname, const char *mode);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yieldk)     (lua_State *L, int nresults, lua_KContext ctx,\n                               lua_KFunction k);\nLUA_API int  (lua_resume)     (lua_State *L, lua_State *from, int narg);\nLUA_API int  (lua_status)     (lua_State *L);\nLUA_API int (lua_isyieldable) (lua_State *L);\n\n#define lua_yield(L,n)\t\tlua_yieldk(L, (n), 0, NULL)\n\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\nLUA_API void  (lua_len)    (lua_State *L, int idx);\n\nLUA_API size_t   (lua_stringtonumber) (lua_State *L, const char *s);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** {==============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_getextraspace(L)\t((void *)((char *)(L) - LUA_EXTRASPACE))\n\n#define lua_tonumber(L,i)\tlua_tonumberx(L,(i),NULL)\n#define lua_tointeger(L,i)\tlua_tointegerx(L,(i),NULL)\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\tlua_pushstring(L, \"\" s)\n\n#define lua_pushglobaltable(L)  \\\n\t((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n#define lua_insert(L,idx)\tlua_rotate(L, (idx), 1)\n\n#define lua_remove(L,idx)\t(lua_rotate(L, (idx), -1), lua_pop(L, 1))\n\n#define lua_replace(L,idx)\t(lua_copy(L, -1, (idx)), lua_pop(L, 1))\n\n/* }============================================================== */\n\n\n/*\n** {==============================================================\n** compatibility macros for unsigned conversions\n** ===============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define lua_pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define lua_tounsignedx(L,i,is)\t((lua_Unsigned)lua_tointegerx(L,i,is))\n#define lua_tounsigned(L,i)\tlua_tounsignedx(L,(i),NULL)\n\n#endif\n/* }============================================================== */\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILCALL 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debugger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);\nLUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);\nLUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);\n\nLUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);\nLUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,\n                                               int fidx2, int n2);\n\nLUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook (lua_gethook) (lua_State *L);\nLUA_API int (lua_gethookmask) (lua_State *L);\nLUA_API int (lua_gethookcount) (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) 'global', 'local', 'field', 'method' */\n  const char *what;\t/* (S) 'Lua', 'C', 'main', 'tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  unsigned char nups;\t/* (u) number of upvalues */\n  unsigned char nparams;/* (u) number of parameters */\n  char isvararg;        /* (u) */\n  char istailcall;\t/* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  struct CallInfo *i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2017 Lua.org, PUC-Rio.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "WebGLPlugins/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** Lua compiler (saves bytecodes to files; also lists bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\nstatic void PrintFunction(const Proto* f, int full);\n#define luaU_print\tPrintFunction\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define OUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option '%s'\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n  \"usage: %s [options] [filenames]\\n\"\n  \"Available options are:\\n\"\n  \"  -l       list (use -l -l for full listing)\\n\"\n  \"  -o name  output to file 'name' (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and process stdin\\n\"\n  ,progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define IS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))\n    usage(\"'-o' needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s\\n\",LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define FUNCTION \"(function()end)();\"\n\nstatic const char* reader(lua_State *L, void *ud, size_t *size)\n{\n UNUSED(L);\n if ((*(int*)ud)--)\n {\n  *size=sizeof(FUNCTION)-1;\n  return FUNCTION;\n }\n else\n {\n  *size=0;\n  return NULL;\n }\n}\n\n#define toproto(L,i) getproto(L->top+(i))\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  Proto* f;\n  int i=n;\n  if (lua_load(L,reader,&i,\"=(\" PROGNAME \")\",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));\n  f=toproto(L,-1);\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;\n  }\n  f->sizelineinfo=0;\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstatic int pmain(lua_State* L)\n{\n int argc=(int)lua_tointeger(L,1);\n char** argv=(char**)lua_touserdata(L,2);\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=luaL_newstate();\n if (L==NULL) fatal(\"cannot create state: not enough memory\");\n lua_pushcfunction(L,&pmain);\n lua_pushinteger(L,argc);\n lua_pushlightuserdata(L,argv);\n if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n\n/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=tsslen(ts);\n printf(\"%c\",'\"');\n for (i=0; i<n; i++)\n {\n  int c=(int)(unsigned char)s[i];\n  switch (c)\n  {\n   case '\"':  printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint(c))\n   \t\t\tprintf(\"%c\",c);\n\t\telse\n\t\t\tprintf(\"\\\\%03d\",c);\n  }\n }\n printf(\"%c\",'\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMFLT:\n\t{\n\tchar buff[100];\n\tsprintf(buff,LUA_NUMBER_FMT,fltvalue(o));\n\tprintf(\"%s\",buff);\n\tif (buff[strspn(buff,\"-0123456789\")]=='\\0') printf(\".0\");\n\tbreak;\n\t}\n  case LUA_TNUMINT:\n\tprintf(LUA_INTEGER_FMT,ivalue(o));\n\tbreak;\n  case LUA_TSHRSTR: case LUA_TLNGSTR:\n\tPrintString(tsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\n#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : \"-\")\n#define MYK(x)\t\t(-1-(x))\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int ax=GETARG_Ax(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getfuncline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (MYK(INDEXK(b))) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (MYK(INDEXK(c))) : c);\n    break;\n   case iABx:\n    printf(\"%d\",a);\n    if (getBMode(o)==OpArgK) printf(\" %d\",MYK(bx));\n    if (getBMode(o)==OpArgU) printf(\" %d\",bx);\n    break;\n   case iAsBx:\n    printf(\"%d %d\",a,sbx);\n    break;\n   case iAx:\n    printf(\"%d\",MYK(ax));\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    break;\n   case OP_GETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(a));\n    if (ISK(b)) { printf(\" \"); PrintConstant(f,INDEXK(b)); }\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_POW:\n   case OP_DIV:\n   case OP_IDIV:\n   case OP_BAND:\n   case OP_BOR:\n   case OP_BXOR:\n   case OP_SHL:\n   case OP_SHR:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n   case OP_TFORLOOP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]); else printf(\"\\t; %d\",c);\n    break;\n   case OP_EXTRAARG:\n    printf(\"\\t; \"); PrintConstant(f,ax);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t((x==1)?\"\":\"s\")\n#define S(x)\t(int)(x),SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=f->source ? getstr(f->source) : \"=?\";\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\t(int)(f->numparams),f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->sizeupvalues));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintDebug(const Proto* f)\n{\n int i,n;\n n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);\n }\n}\n\nstatic void PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full) PrintDebug(f);\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "WebGLPlugins/luaconf.h",
    "content": "/*\n** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ===================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n** {====================================================================\n** System Configuration: macros to adapt (if needed) Lua to some\n** particular platform, for instance compiling it with 32-bit numbers or\n** restricting it to C89.\n** =====================================================================\n*/\n\n/*\n@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You\n** can also define LUA_32BITS in the make file, but changing here you\n** ensure that all software connected to Lua will be compiled with the\n** same configuration.\n*/\n/* #define LUA_32BITS */\n\n\n/*\n@@ LUA_USE_C89 controls the use of non-ISO-C89 features.\n** Define it if you want Lua to avoid the use of a few C99 features\n** or Windows-specific features on Windows.\n*/\n/* #define LUA_USE_C89 */\n\n\n/*\n** By default, Lua on Windows use (some) specific Windows features\n*/\n#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)\n#define LUA_USE_WINDOWS  /* enable goodies for regular Windows */\n#endif\n\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_DL_DLL\t/* enable support for DLL */\n#define LUA_USE_C89\t/* broadly, Windows is C89 */\n#endif\n\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* MacOS does not need -ldl */\n#define LUA_USE_READLINE\t/* needs an extra library: -lreadline */\n#endif\n\n\n/*\n@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for\n** C89 ('long' and 'double'); Windows always has '__int64', so it does\n** not need to use this case.\n*/\n#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)\n#define LUA_C89_NUMBERS\n#endif\n\n\n\n/*\n@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.\n*/\n/* avoid undefined shifts */\n#if ((INT_MAX >> 15) >> 15) >= 1\n#define LUAI_BITSINT\t32\n#else\n/* 'int' always must have at least 16 bits */\n#define LUAI_BITSINT\t16\n#endif\n\n\n/*\n@@ LUA_INT_TYPE defines the type for Lua integers.\n@@ LUA_FLOAT_TYPE defines the type for Lua floats.\n** Lua should work fine with any mix of these options (if supported\n** by your C compiler). The usual configurations are 64-bit integers\n** and 'double' (the default), 32-bit integers and 'float' (for\n** restricted platforms), and 'long'/'double' (for C compilers not\n** compliant with C99, which may not have support for 'long long').\n*/\n\n/* predefined options for LUA_INT_TYPE */\n#define LUA_INT_INT\t\t1\n#define LUA_INT_LONG\t\t2\n#define LUA_INT_LONGLONG\t3\n\n/* predefined options for LUA_FLOAT_TYPE */\n#define LUA_FLOAT_FLOAT\t\t1\n#define LUA_FLOAT_DOUBLE\t2\n#define LUA_FLOAT_LONGDOUBLE\t3\n\n#if defined(LUA_32BITS)\t\t/* { */\n/*\n** 32-bit integers and 'float'\n*/\n#if LUAI_BITSINT >= 32  /* use 'int' if big enough */\n#define LUA_INT_TYPE\tLUA_INT_INT\n#else  /* otherwise use 'long' */\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#endif\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT\n\n#elif defined(LUA_C89_NUMBERS)\t/* }{ */\n/*\n** largest types available for C89 ('long' and 'double')\n*/\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** default configuration for 64-bit Lua ('long long' and 'double')\n*/\n#if !defined(LUA_INT_TYPE)\n#define LUA_INT_TYPE\tLUA_INT_LONGLONG\n#endif\n\n#if !defined(LUA_FLOAT_TYPE)\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n#endif\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n** Configuration for Paths.\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n*/\n#define LUA_PATH_SEP            \";\"\n#define LUA_PATH_MARK           \"?\"\n#define LUA_EXEC_DIR            \"!\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n** Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n** C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#define LUA_VDIR\tLUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#if defined(_WIN32)\t/* { */\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_SHRDIR\t\"!\\\\..\\\\share\\\\lua\\\\\" LUA_VDIR \"\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua;\" \\\n\t\tLUA_SHRDIR\"?.lua;\" LUA_SHRDIR\"?\\\\init.lua;\" \\\n\t\t\".\\\\?.lua;\" \".\\\\?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.dll;\" \\\n\t\tLUA_CDIR\"..\\\\lib\\\\lua\\\\\" LUA_VDIR \"\\\\?.dll;\" \\\n\t\tLUA_CDIR\"loadall.dll;\" \".\\\\?.dll\"\n\n#else\t\t\t/* }{ */\n\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/\" LUA_VDIR \"/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/\" LUA_VDIR \"/\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua;\" \\\n\t\t\"./?.lua;\" \"./?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so;\" \"./?.so\"\n#endif\t\t\t/* } */\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Marks for exported symbols in the C code\n** ===================================================================\n*/\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all auxiliary library functions.\n@@ LUAMOD_API is a mark for all standard library opening functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\t/* { */\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\t/* { */\n#define LUA_API __declspec(dllexport)\n#else\t\t\t\t\t\t/* }{ */\n#define LUA_API __declspec(dllimport)\n#endif\t\t\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#define LUA_API\t\textern\n\n#endif\t\t\t\t/* } */\n\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n#define LUAMOD_API\tLUALIB_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n** exported to outside modules.\n@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables\n** that are not to be exported to outside modules (LUAI_DDEF for\n** definitions and LUAI_DDEC for declarations).\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library. Not all elf targets support\n** this attribute. Unfortunately, gcc does not offer a way to check\n** whether the target offers that support, and those without support\n** give a warning about it. To avoid these warnings, change to the\n** default definition.\n*/\n#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n    defined(__ELF__)\t\t/* { */\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#else\t\t\t\t/* }{ */\n#define LUAI_FUNC\textern\n#endif\t\t\t\t/* } */\n\n#define LUAI_DDEC\tLUAI_FUNC\n#define LUAI_DDEF\t/* empty */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Compatibility with previous versions\n** ===================================================================\n*/\n\n/*\n@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.\n@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.\n** You can define it to get all options, or change specific options\n** to fit your specific needs.\n*/\n#if defined(LUA_COMPAT_5_2)\t/* { */\n\n/*\n@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated\n** functions in the mathematical library.\n*/\n#define LUA_COMPAT_MATHLIB\n\n/*\n@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.\n*/\n#define LUA_COMPAT_BITLIB\n\n/*\n@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.\n*/\n#define LUA_COMPAT_IPAIRS\n\n/*\n@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for\n** manipulating other integer types (lua_pushunsigned, lua_tounsigned,\n** luaL_checkint, luaL_checklong, etc.)\n*/\n#define LUA_COMPAT_APIINTCASTS\n\n#endif\t\t\t\t/* } */\n\n\n#if defined(LUA_COMPAT_5_1)\t/* { */\n\n/* Incompatibilities from 5.2 -> 5.3 */\n#define LUA_COMPAT_MATHLIB\n#define LUA_COMPAT_APIINTCASTS\n\n/*\n@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.\n** You can replace it with 'table.unpack'.\n*/\n#define LUA_COMPAT_UNPACK\n\n/*\n@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.\n** You can replace it with 'package.searchers'.\n*/\n#define LUA_COMPAT_LOADERS\n\n/*\n@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.\n** You can call your C function directly (with light C functions).\n*/\n#define lua_cpcall(L,f,u)  \\\n\t(lua_pushcfunction(L, (f)), \\\n\t lua_pushlightuserdata(L,(u)), \\\n\t lua_pcall(L,1,0,0))\n\n\n/*\n@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.\n** You can rewrite 'log10(x)' as 'log(x, 10)'.\n*/\n#define LUA_COMPAT_LOG10\n\n/*\n@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base\n** library. You can rewrite 'loadstring(s)' as 'load(s)'.\n*/\n#define LUA_COMPAT_LOADSTRING\n\n/*\n@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.\n*/\n#define LUA_COMPAT_MAXN\n\n/*\n@@ The following macros supply trivial compatibility for some\n** changes in the API. The macros themselves document how to\n** change your code to avoid using them.\n*/\n#define lua_strlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_equal(L,idx1,idx2)\t\tlua_compare(L,(idx1),(idx2),LUA_OPEQ)\n#define lua_lessthan(L,idx1,idx2)\tlua_compare(L,(idx1),(idx2),LUA_OPLT)\n\n/*\n@@ LUA_COMPAT_MODULE controls compatibility with previous\n** module functions 'module' (Lua) and 'luaL_register' (C).\n*/\n#define LUA_COMPAT_MODULE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a\n@@ a float mark ('.0').\n** This macro is not on by default even in compatibility mode,\n** because this is not really an incompatibility.\n*/\n/* #define LUA_COMPAT_FLOATSTRING */\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Numbers.\n** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*\n** satisfy your needs.\n** ===================================================================\n*/\n\n/*\n@@ LUA_NUMBER is the floating-point type used by Lua.\n@@ LUAI_UACNUMBER is the result of a 'default argument promotion'\n@@ over a floating number.\n@@ l_mathlim(x) corrects limit name 'x' to the proper float type\n** by prefixing it with one of FLT/DBL/LDBL.\n@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.\n@@ LUA_NUMBER_FMT is the format for writing floats.\n@@ lua_number2str converts a float to a string.\n@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.\n@@ l_floor takes the floor of a float.\n@@ lua_str2number converts a decimal numeric string to a number.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define l_floor(x)\t\t(l_mathop(floor)(x))\n\n#define lua_number2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))\n\n/*\n@@ lua_numbertointeger converts a float number to an integer, or\n** returns 0 if float is not within the range of a lua_Integer.\n** (The range comparisons are tricky because of rounding. The tests\n** here assume a two-complement representation, where MININTEGER always\n** has an exact representation as a float; MAXINTEGER may not have one,\n** and therefore its conversion to float may have an ill-defined value.)\n*/\n#define lua_numbertointeger(n,p) \\\n  ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \\\n   (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \\\n      (*(p) = (LUA_INTEGER)(n), 1))\n\n\n/* now the variable definitions */\n\n#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT\t\t/* { single float */\n\n#define LUA_NUMBER\tfloat\n\n#define l_mathlim(n)\t\t(FLT_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.7g\"\n\n#define l_mathop(op)\t\top##f\n\n#define lua_str2number(s,p)\tstrtof((s), (p))\n\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\t/* }{ long double */\n\n#define LUA_NUMBER\tlong double\n\n#define l_mathlim(n)\t\t(LDBL_##n)\n\n#define LUAI_UACNUMBER\tlong double\n\n#define LUA_NUMBER_FRMLEN\t\"L\"\n#define LUA_NUMBER_FMT\t\t\"%.19Lg\"\n\n#define l_mathop(op)\t\top##l\n\n#define lua_str2number(s,p)\tstrtold((s), (p))\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE\t/* }{ double */\n\n#define LUA_NUMBER\tdouble\n\n#define l_mathlim(n)\t\t(DBL_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n\n#define l_mathop(op)\t\top\n\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n#else\t\t\t\t\t\t/* }{ */\n\n#error \"numeric float type not defined\"\n\n#endif\t\t\t\t\t/* } */\n\n\n\n/*\n@@ LUA_INTEGER is the integer type used by Lua.\n**\n@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.\n**\n@@ LUAI_UACINT is the result of a 'default argument promotion'\n@@ over a lUA_INTEGER.\n@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.\n@@ LUA_INTEGER_FMT is the format for writing integers.\n@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.\n@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.\n@@ lua_integer2str converts an integer to a string.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define LUA_INTEGER_FMT\t\t\"%\" LUA_INTEGER_FRMLEN \"d\"\n\n#define LUAI_UACINT\t\tLUA_INTEGER\n\n#define lua_integer2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))\n\n/*\n** use LUAI_UACINT here to avoid problems with promotions (which\n** can turn a comparison between unsigneds into a signed comparison)\n*/\n#define LUA_UNSIGNED\t\tunsigned LUAI_UACINT\n\n\n/* now the variable definitions */\n\n#if LUA_INT_TYPE == LUA_INT_INT\t\t/* { int */\n\n#define LUA_INTEGER\t\tint\n#define LUA_INTEGER_FRMLEN\t\"\"\n\n#define LUA_MAXINTEGER\t\tINT_MAX\n#define LUA_MININTEGER\t\tINT_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONG\t/* }{ long */\n\n#define LUA_INTEGER\t\tlong\n#define LUA_INTEGER_FRMLEN\t\"l\"\n\n#define LUA_MAXINTEGER\t\tLONG_MAX\n#define LUA_MININTEGER\t\tLONG_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONGLONG\t/* }{ long long */\n\n/* use presence of macro LLONG_MAX as proxy for C99 compliance */\n#if defined(LLONG_MAX)\t\t/* { */\n/* use ISO C99 stuff */\n\n#define LUA_INTEGER\t\tlong long\n#define LUA_INTEGER_FRMLEN\t\"ll\"\n\n#define LUA_MAXINTEGER\t\tLLONG_MAX\n#define LUA_MININTEGER\t\tLLONG_MIN\n\n#elif defined(LUA_USE_WINDOWS) /* }{ */\n/* in Windows, can use specific Windows types */\n\n#define LUA_INTEGER\t\t__int64\n#define LUA_INTEGER_FRMLEN\t\"I64\"\n\n#define LUA_MAXINTEGER\t\t_I64_MAX\n#define LUA_MININTEGER\t\t_I64_MIN\n\n#else\t\t\t\t/* }{ */\n\n#error \"Compiler does not support 'long long'. Use option '-DLUA_32BITS' \\\n  or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)\"\n\n#endif\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#error \"numeric integer type not defined\"\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Dependencies with C99 and other C details\n** ===================================================================\n*/\n\n/*\n@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.\n** (All uses in Lua have only one format item.)\n*/\n#if !defined(LUA_USE_C89)\n#define l_sprintf(s,sz,f,i)\tsnprintf(s,sz,f,i)\n#else\n#define l_sprintf(s,sz,f,i)\t((void)(sz), sprintf(s,f,i))\n#endif\n\n\n/*\n@@ lua_strx2number converts an hexadecimal numeric string to a number.\n** In C99, 'strtod' does that conversion. Otherwise, you can\n** leave 'lua_strx2number' undefined and Lua will provide its own\n** implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_strx2number(s,p)\t\tlua_str2number(s,p)\n#endif\n\n\n/*\n@@ lua_number2strx converts a float to an hexadecimal numeric string.\n** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.\n** Otherwise, you can leave 'lua_number2strx' undefined and Lua will\n** provide its own implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_number2strx(L,b,sz,f,n)  \\\n\t((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))\n#endif\n\n\n/*\n** 'strtof' and 'opf' variants for math functions are not valid in\n** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the\n** availability of these variants. ('math.h' is already included in\n** all files that use these macros.)\n*/\n#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))\n#undef l_mathop  /* variants not available */\n#undef lua_str2number\n#define l_mathop(op)\t\t(lua_Number)op  /* no variant */\n#define lua_str2number(s,p)\t((lua_Number)strtod((s), (p)))\n#endif\n\n\n/*\n@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation\n** functions.  It must be a numerical type; Lua will use 'intptr_t' if\n** available, otherwise it will use 'ptrdiff_t' (the nearest thing to\n** 'intptr_t' in C89)\n*/\n#define LUA_KCONTEXT\tptrdiff_t\n\n#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \\\n    __STDC_VERSION__ >= 199901L\n#include <stdint.h>\n#if defined(INTPTR_MAX)  /* even in C99 this type is optional */\n#undef LUA_KCONTEXT\n#define LUA_KCONTEXT\tintptr_t\n#endif\n#endif\n\n\n/*\n@@ lua_getlocaledecpoint gets the locale \"radix character\" (decimal point).\n** Change that if you do not want to use C locales. (Code using this\n** macro must include header 'locale.h'.)\n*/\n#if !defined(lua_getlocaledecpoint)\n#define lua_getlocaledecpoint()\t\t(localeconv()->decimal_point[0])\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Language Variations\n** =====================================================================\n*/\n\n/*\n@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some\n** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from\n** numbers to strings. Define LUA_NOCVTS2N to turn off automatic\n** coercion from strings to numbers.\n*/\n/* #define LUA_NOCVTN2S */\n/* #define LUA_NOCVTS2N */\n\n\n/*\n@@ LUA_USE_APICHECK turns on several consistency checks on the C API.\n** Define it as a help when debugging C code.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(l,e)\tassert(e)\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Macros that affect the API and must be stable (that is, must be the\n** same when you compile Lua and when you compile code that links to\n** Lua). You probably do not want/need to change them.\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXSTACK limits the size of the Lua stack.\n** CHANGE it if you need a different limit. This limit is arbitrary;\n** its only purpose is to stop Lua from consuming unlimited stack\n** space (and to reserve some numbers for pseudo-indices).\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_MAXSTACK\t\t1000000\n#else\n#define LUAI_MAXSTACK\t\t15000\n#endif\n\n\n/*\n@@ LUA_EXTRASPACE defines the size of a raw memory area associated with\n** a Lua state with very fast access.\n** CHANGE it if you need a different size.\n*/\n#define LUA_EXTRASPACE\t\t(sizeof(void *))\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@@ of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#define LUA_IDSIZE\t60\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n** CHANGE it if it uses too much C-stack space. (For long double,\n** 'string.format(\"%.99f\", -1e4932)' needs 5034 bytes, so a\n** smaller buffer would force a memory allocation for each call to\n** 'string.format'.)\n*/\n#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\n#define LUAL_BUFFERSIZE\t\t8192\n#else\n#define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** Lua does not use these macros anymore; they are here for\n** compatibility only.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "WebGLPlugins/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* version suffix for environment variable names */\n#define LUA_VERSUFFIX          \"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n\nLUAMOD_API int (luaopen_base) (lua_State *L);\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUAMOD_API int (luaopen_coroutine) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUAMOD_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUAMOD_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUAMOD_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUAMOD_API int (luaopen_string) (lua_State *L);\n\n#define LUA_UTF8LIBNAME\t\"utf8\"\nLUAMOD_API int (luaopen_utf8) (lua_State *L);\n\n#define LUA_BITLIBNAME\t\"bit32\"\nLUAMOD_API int (luaopen_bit32) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUAMOD_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUAMOD_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUAMOD_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L);\n\n\n\n#if !defined(lua_assert)\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\n\n#if !defined(luai_verifycode)\n#define luai_verifycode(L,b,f)  /* empty */\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  ZIO *Z;\n  const char *name;\n} LoadState;\n\n\nstatic l_noret error(LoadState *S, const char *why) {\n  luaO_pushfstring(S->L, \"%s: %s precompiled chunk\", S->name, why);\n  luaD_throw(S->L, LUA_ERRSYNTAX);\n}\n\n\n/*\n** All high-level loads go through LoadVector; you can change it to\n** adapt to the endianness of the input\n*/\n#define LoadVector(S,b,n)\tLoadBlock(S,b,(n)*sizeof((b)[0]))\n\nstatic void LoadBlock (LoadState *S, void *b, size_t size) {\n  if (luaZ_read(S->Z, b, size) != 0)\n    error(S, \"truncated\");\n}\n\n\n#define LoadVar(S,x)\t\tLoadVector(S,&x,1)\n\n\nstatic lu_byte LoadByte (LoadState *S) {\n  lu_byte x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic int LoadInt (LoadState *S) {\n  int x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Number LoadNumber (LoadState *S) {\n  lua_Number x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Integer LoadInteger (LoadState *S) {\n  lua_Integer x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic TString *LoadString (LoadState *S) {\n  size_t size = LoadByte(S);\n  if (size == 0xFF)\n    LoadVar(S, size);\n  if (size == 0)\n    return NULL;\n  else if (--size <= LUAI_MAXSHORTLEN) {  /* short string? */\n    char buff[LUAI_MAXSHORTLEN];\n    LoadVector(S, buff, size);\n    return luaS_newlstr(S->L, buff, size);\n  }\n  else {  /* long string */\n    TString *ts = luaS_createlngstrobj(S->L, size);\n    LoadVector(S, getstr(ts), size);  /* load directly in final place */\n    return ts;\n  }\n}\n\n\nstatic void LoadCode (LoadState *S, Proto *f) {\n  int n = LoadInt(S);\n  f->code = luaM_newvector(S->L, n, Instruction);\n  f->sizecode = n;\n  LoadVector(S, f->code, n);\n}\n\n\nstatic void LoadFunction(LoadState *S, Proto *f, TString *psource);\n\n\nstatic void LoadConstants (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->k = luaM_newvector(S->L, n, TValue);\n  f->sizek = n;\n  for (i = 0; i < n; i++)\n    setnilvalue(&f->k[i]);\n  for (i = 0; i < n; i++) {\n    TValue *o = &f->k[i];\n    int t = LoadByte(S);\n    switch (t) {\n    case LUA_TNIL:\n      setnilvalue(o);\n      break;\n    case LUA_TBOOLEAN:\n      setbvalue(o, LoadByte(S));\n      break;\n    case LUA_TNUMFLT:\n      setfltvalue(o, LoadNumber(S));\n      break;\n    case LUA_TNUMINT:\n      setivalue(o, LoadInteger(S));\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      setsvalue2n(S->L, o, LoadString(S));\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void LoadProtos (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->p = luaM_newvector(S->L, n, Proto *);\n  f->sizep = n;\n  for (i = 0; i < n; i++)\n    f->p[i] = NULL;\n  for (i = 0; i < n; i++) {\n    f->p[i] = luaF_newproto(S->L);\n    LoadFunction(S, f->p[i], f->source);\n  }\n}\n\n\nstatic void LoadUpvalues (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->upvalues = luaM_newvector(S->L, n, Upvaldesc);\n  f->sizeupvalues = n;\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = NULL;\n  for (i = 0; i < n; i++) {\n    f->upvalues[i].instack = LoadByte(S);\n    f->upvalues[i].idx = LoadByte(S);\n  }\n}\n\n\nstatic void LoadDebug (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->lineinfo = luaM_newvector(S->L, n, int);\n  f->sizelineinfo = n;\n  LoadVector(S, f->lineinfo, n);\n  n = LoadInt(S);\n  f->locvars = luaM_newvector(S->L, n, LocVar);\n  f->sizelocvars = n;\n  for (i = 0; i < n; i++)\n    f->locvars[i].varname = NULL;\n  for (i = 0; i < n; i++) {\n    f->locvars[i].varname = LoadString(S);\n    f->locvars[i].startpc = LoadInt(S);\n    f->locvars[i].endpc = LoadInt(S);\n  }\n  n = LoadInt(S);\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = LoadString(S);\n}\n\n\nstatic void LoadFunction (LoadState *S, Proto *f, TString *psource) {\n  f->source = LoadString(S);\n  if (f->source == NULL)  /* no source in dump? */\n    f->source = psource;  /* reuse parent's source */\n  f->linedefined = LoadInt(S);\n  f->lastlinedefined = LoadInt(S);\n  f->numparams = LoadByte(S);\n  f->is_vararg = LoadByte(S);\n  f->maxstacksize = LoadByte(S);\n  LoadCode(S, f);\n  LoadConstants(S, f);\n  LoadUpvalues(S, f);\n  LoadProtos(S, f);\n  LoadDebug(S, f);\n}\n\n\nstatic void checkliteral (LoadState *S, const char *s, const char *msg) {\n  char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */\n  size_t len = strlen(s);\n  LoadVector(S, buff, len);\n  if (memcmp(s, buff, len) != 0)\n    error(S, msg);\n}\n\n\nstatic void fchecksize (LoadState *S, size_t size, const char *tname) {\n  if (LoadByte(S) != size)\n    error(S, luaO_pushfstring(S->L, \"%s size mismatch in\", tname));\n}\n\n\n#define checksize(S,t)\tfchecksize(S,sizeof(t),#t)\n\nstatic void checkHeader (LoadState *S) {\n  checkliteral(S, LUA_SIGNATURE + 1, \"not a\");  /* 1st char already checked */\n  if (LoadByte(S) != LUAC_VERSION)\n    error(S, \"version mismatch in\");\n  if (LoadByte(S) != LUAC_FORMAT)\n    error(S, \"format mismatch in\");\n  checkliteral(S, LUAC_DATA, \"corrupted\");\n  checksize(S, int);\n  checksize(S, size_t);\n  checksize(S, Instruction);\n  checksize(S, lua_Integer);\n  checksize(S, lua_Number);\n  if (LoadInteger(S) != LUAC_INT)\n    error(S, \"endianness mismatch in\");\n  if (LoadNumber(S) != LUAC_NUM)\n    error(S, \"float format mismatch in\");\n}\n\n\n/*\n** load precompiled chunk\n*/\nLClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {\n  LoadState S;\n  LClosure *cl;\n  if (*name == '@' || *name == '=')\n    S.name = name + 1;\n  else if (*name == LUA_SIGNATURE[0])\n    S.name = \"binary string\";\n  else\n    S.name = name;\n  S.L = L;\n  S.Z = Z;\n  checkHeader(&S);\n  cl = luaF_newLclosure(L, LoadByte(&S));\n  setclLvalue(L, L->top, cl);\n  luaD_inctop(L);\n  cl->p = luaF_newproto(L);\n  LoadFunction(&S, cl->p, NULL);\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luai_verifycode(L, buff, cl->p);\n  return cl;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/* data to catch conversion errors */\n#define LUAC_DATA\t\"\\x19\\x93\\r\\n\\x1a\\n\"\n\n#define LUAC_INT\t0x5678\n#define LUAC_NUM\tcast_num(370.5)\n\n#define MYINT(s)\t(s[0]-'0')\n#define LUAC_VERSION\t(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))\n#define LUAC_FORMAT\t0\t/* this is the official format */\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,\n                         void* data, int strip);\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lutf8lib.c",
    "content": "/*\n** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $\n** Standard library for UTF-8 manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define lutf8lib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <assert.h>\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#define MAXUNICODE\t0x10FFFF\n\n#define iscont(p)\t((*(p) & 0xC0) == 0x80)\n\n\n/* from strlib */\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer u_posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\n/*\n** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.\n*/\nstatic const char *utf8_decode (const char *o, int *val) {\n  static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};\n  const unsigned char *s = (const unsigned char *)o;\n  unsigned int c = s[0];\n  unsigned int res = 0;  /* final result */\n  if (c < 0x80)  /* ascii? */\n    res = c;\n  else {\n    int count = 0;  /* to count number of continuation bytes */\n    while (c & 0x40) {  /* still have continuation bytes? */\n      int cc = s[++count];  /* read next byte */\n      if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */\n        return NULL;  /* invalid byte sequence */\n      res = (res << 6) | (cc & 0x3F);  /* add lower 6 bits from cont. byte */\n      c <<= 1;  /* to test next bit */\n    }\n    res |= ((c & 0x7F) << (count * 5));  /* add first byte */\n    if (count > 3 || res > MAXUNICODE || res <= limits[count])\n      return NULL;  /* invalid byte sequence */\n    s += count;  /* skip continuation bytes read */\n  }\n  if (val) *val = res;\n  return (const char *)s + 1;  /* +1 to include first byte */\n}\n\n\n/*\n** utf8len(s [, i [, j]]) --> number of characters that start in the\n** range [i,j], or nil + current position if 's' is not well formed in\n** that interval\n*/\nstatic int utflen (lua_State *L) {\n  int n = 0;\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,\n                   \"initial position out of string\");\n  luaL_argcheck(L, --posj < (lua_Integer)len, 3,\n                   \"final position out of string\");\n  while (posi <= posj) {\n    const char *s1 = utf8_decode(s + posi, NULL);\n    if (s1 == NULL) {  /* conversion error? */\n      lua_pushnil(L);  /* return nil ... */\n      lua_pushinteger(L, posi + 1);  /* ... and current position */\n      return 2;\n    }\n    posi = s1 - s;\n    n++;\n  }\n  lua_pushinteger(L, n);\n  return 1;\n}\n\n\n/*\n** codepoint(s, [i, [j]])  -> returns codepoints for all characters\n** that start in the range [i,j]\n*/\nstatic int codepoint (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  int n;\n  const char *se;\n  luaL_argcheck(L, posi >= 1, 2, \"out of range\");\n  luaL_argcheck(L, pose <= (lua_Integer)len, 3, \"out of range\");\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  n = 0;\n  se = s + pose;\n  for (s += posi - 1; s < se;) {\n    int code;\n    s = utf8_decode(s, &code);\n    if (s == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, code);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void pushutfchar (lua_State *L, int arg) {\n  lua_Integer code = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, \"value out of range\");\n  lua_pushfstring(L, \"%U\", (long)code);\n}\n\n\n/*\n** utfchar(n1, n2, ...)  -> char(n1)..char(n2)...\n*/\nstatic int utfchar (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  if (n == 1)  /* optimize common case of single char */\n    pushutfchar(L, 1);\n  else {\n    int i;\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    for (i = 1; i <= n; i++) {\n      pushutfchar(L, i);\n      luaL_addvalue(&b);\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\n/*\n** offset(s, n, [i])  -> index where n-th character counting from\n**   position 'i' starts; 0 means character at 'i'.\n*/\nstatic int byteoffset (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n  = luaL_checkinteger(L, 2);\n  lua_Integer posi = (n >= 0) ? 1 : len + 1;\n  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,\n                   \"position out of range\");\n  if (n == 0) {\n    /* find beginning of current byte sequence */\n    while (posi > 0 && iscont(s + posi)) posi--;\n  }\n  else {\n    if (iscont(s + posi))\n      luaL_error(L, \"initial position is a continuation byte\");\n    if (n < 0) {\n       while (n < 0 && posi > 0) {  /* move back */\n         do {  /* find beginning of previous character */\n           posi--;\n         } while (posi > 0 && iscont(s + posi));\n         n++;\n       }\n     }\n     else {\n       n--;  /* do not move for 1st character */\n       while (n > 0 && posi < (lua_Integer)len) {\n         do {  /* find beginning of next character */\n           posi++;\n         } while (iscont(s + posi));  /* (cannot pass final '\\0') */\n         n--;\n       }\n     }\n  }\n  if (n == 0)  /* did it find given character? */\n    lua_pushinteger(L, posi + 1);\n  else  /* no such character */\n    lua_pushnil(L);\n  return 1;\n}\n\n\nstatic int iter_aux (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n = lua_tointeger(L, 2) - 1;\n  if (n < 0)  /* first iteration? */\n    n = 0;  /* start from here */\n  else if (n < (lua_Integer)len) {\n    n++;  /* skip current byte */\n    while (iscont(s + n)) n++;  /* and its continuations */\n  }\n  if (n >= (lua_Integer)len)\n    return 0;  /* no more codepoints */\n  else {\n    int code;\n    const char *next = utf8_decode(s + n, &code);\n    if (next == NULL || iscont(next))\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, n + 1);\n    lua_pushinteger(L, code);\n    return 2;\n  }\n}\n\n\nstatic int iter_codes (lua_State *L) {\n  luaL_checkstring(L, 1);\n  lua_pushcfunction(L, iter_aux);\n  lua_pushvalue(L, 1);\n  lua_pushinteger(L, 0);\n  return 3;\n}\n\n\n/* pattern to match a single UTF-8 character */\n#define UTF8PATT\t\"[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*\"\n\n\nstatic const luaL_Reg funcs[] = {\n  {\"offset\", byteoffset},\n  {\"codepoint\", codepoint},\n  {\"char\", utfchar},\n  {\"len\", utflen},\n  {\"codes\", iter_codes},\n  /* placeholders */\n  {\"charpattern\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_utf8 (lua_State *L) {\n  luaL_newlib(L, funcs);\n  lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);\n  lua_setfield(L, -2, \"charpattern\");\n  return 1;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.268 2016/02/05 19:59:14 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t2000\n\n\n\n/*\n** 'l_intfitsf' checks whether a given integer can be converted to a\n** float without rounding. Used in comparisons. Left undefined if\n** all integers fit in a float precisely.\n*/\n#if !defined(l_intfitsf)\n\n/* number of bits in the mantissa of a float */\n#define NBM\t\t(l_mathlim(MANT_DIG))\n\n/*\n** Check whether some integers may not fit in a float, that is, whether\n** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).\n** (The shifts are done in parts to avoid shifting by more than the size\n** of an integer. In a worst case, NBM == 113 for long double and\n** sizeof(integer) == 32.)\n*/\n#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \\\n\t>> (NBM - (3 * (NBM / 4))))  >  0\n\n#define l_intfitsf(i)  \\\n  (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM))\n\n#endif\n\n#endif\n\n\n\n/*\n** Try to convert a value to a float. The float case is already handled\n** by the macro 'tonumber'.\n*/\nint luaV_tonumber_ (const TValue *obj, lua_Number *n) {\n  TValue v;\n  if (ttisinteger(obj)) {\n    *n = cast_num(ivalue(obj));\n    return 1;\n  }\n  else if (cvt2num(obj) &&  /* string convertible to number? */\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */\n    return 1;\n  }\n  else\n    return 0;  /* conversion failed */\n}\n\n\n/*\n** try to convert a value to an integer, rounding according to 'mode':\n** mode == 0: accepts only integral values\n** mode == 1: takes the floor of the number\n** mode == 2: takes the ceil of the number\n*/\nint luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {\n  TValue v;\n again:\n  if (ttisfloat(obj)) {\n    lua_Number n = fltvalue(obj);\n    lua_Number f = l_floor(n);\n    if (n != f) {  /* not an integral value? */\n      if (mode == 0) return 0;  /* fails if mode demands integral value */\n      else if (mode > 1)  /* needs ceil? */\n        f += 1;  /* convert floor to ceil (remember: n != f) */\n    }\n    return lua_numbertointeger(f, p);\n  }\n  else if (ttisinteger(obj)) {\n    *p = ivalue(obj);\n    return 1;\n  }\n  else if (cvt2num(obj) &&\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    obj = &v;\n    goto again;  /* convert result from 'luaO_str2num' to an integer */\n  }\n  return 0;  /* conversion failed */\n}\n\n\n/*\n** Try to convert a 'for' limit to an integer, preserving the\n** semantics of the loop.\n** (The following explanation assumes a non-negative step; it is valid\n** for negative steps mutatis mutandis.)\n** If the limit can be converted to an integer, rounding down, that is\n** it.\n** Otherwise, check whether the limit can be converted to a number.  If\n** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,\n** which means no limit.  If the number is too negative, the loop\n** should not run, because any initial integer value is larger than the\n** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects\n** the extreme case when the initial value is LUA_MININTEGER, in which\n** case the LUA_MININTEGER limit would still run the loop once.\n*/\nstatic int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,\n                     int *stopnow) {\n  *stopnow = 0;  /* usually, let loops run */\n  if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) {  /* not fit in integer? */\n    lua_Number n;  /* try to convert to float */\n    if (!tonumber(obj, &n)) /* cannot convert to float? */\n      return 0;  /* not a number */\n    if (luai_numlt(0, n)) {  /* if true, float is larger than max integer */\n      *p = LUA_MAXINTEGER;\n      if (step < 0) *stopnow = 1;\n    }\n    else {  /* float is smaller than min integer */\n      *p = LUA_MININTEGER;\n      if (step >= 0) *stopnow = 1;\n    }\n  }\n  return 1;\n}\n\n\n/*\n** Finish the table access 'val = t[key]'.\n** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to\n** t[k] entry (which must be nil).\n*/\nvoid luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,\n                      const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  const TValue *tm;  /* metamethod */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    if (slot == NULL) {  /* 't' is not a table? */\n      lua_assert(!ttistable(t));\n      tm = luaT_gettmbyobj(L, t, TM_INDEX);\n      if (ttisnil(tm))\n        luaG_typeerror(L, t, \"index\");  /* no metamethod */\n      /* else will try the metamethod */\n    }\n    else {  /* 't' is a table */\n      lua_assert(ttisnil(slot));\n      tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        setnilvalue(val);  /* result is nil */\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    if (ttisfunction(tm)) {  /* is metamethod a function? */\n      luaT_callTM(L, tm, t, key, val, 1);  /* call it */\n      return;\n    }\n    t = tm;  /* else try to access 'tm[key]' */\n    if (luaV_fastget(L,t,key,slot,luaH_get)) {  /* fast track? */\n      setobj2s(L, val, slot);  /* done */\n      return;\n    }\n    /* else repeat (tail call 'luaV_finishget') */\n  }\n  luaG_runerror(L, \"'__index' chain too long; possible loop\");\n}\n\n\n/*\n** Finish a table assignment 't[key] = val'.\n** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points\n** to the entry 't[key]', or to 'luaO_nilobject' if there is no such\n** entry.  (The value at 'slot' must be nil, otherwise 'luaV_fastset'\n** would have done the job.)\n*/\nvoid luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                     StkId val, const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;  /* '__newindex' metamethod */\n    if (slot != NULL) {  /* is 't' a table? */\n      Table *h = hvalue(t);  /* save 't' table */\n      lua_assert(ttisnil(slot));  /* old value must be nil */\n      tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        if (slot == luaO_nilobject)  /* no previous entry? */\n          slot = luaH_newkey(L, h, key);  /* create one */\n        /* no metamethod and (now) there is an entry with given key */\n        setobj2t(L, cast(TValue *, slot), val);  /* set its new value */\n        invalidateTMcache(h);\n        luaC_barrierback(L, h, val);\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    else {  /* not a table; check metamethod */\n      if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n        luaG_typeerror(L, t, \"index\");\n    }\n    /* try the metamethod */\n    if (ttisfunction(tm)) {\n      luaT_callTM(L, tm, t, key, val, 0);\n      return;\n    }\n    t = tm;  /* else repeat assignment over 'tm' */\n    if (luaV_fastset(L, t, key, slot, luaH_get, val))\n      return;  /* done */\n    /* else loop */\n  }\n  luaG_runerror(L, \"'__newindex' chain too long; possible loop\");\n}\n\n\n/*\n** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-\n** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.\n** The code is a little tricky because it allows '\\0' in the strings\n** and it uses 'strcoll' (to respect locales) for each segments\n** of the strings.\n*/\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = tsslen(ls);\n  const char *r = getstr(rs);\n  size_t lr = tsslen(rs);\n  for (;;) {  /* for each segment */\n    int temp = strcoll(l, r);\n    if (temp != 0)  /* not equal? */\n      return temp;  /* done */\n    else {  /* strings are equal up to a '\\0' */\n      size_t len = strlen(l);  /* index of first '\\0' in both strings */\n      if (len == lr)  /* 'rs' is finished? */\n        return (len == ll) ? 0 : 1;  /* check 'ls' */\n      else if (len == ll)  /* 'ls' is finished? */\n        return -1;  /* 'ls' is smaller than 'rs' ('rs' is not finished) */\n      /* both strings longer than 'len'; go on comparing after the '\\0' */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than float 'f'. If 'i' has an\n** exact representation as a float ('l_intfitsf'), compare numbers as\n** floats. Otherwise, if 'f' is outside the range for integers, result\n** is trivial. Otherwise, compare them as integers. (When 'i' has no\n** float representation, either 'f' is \"far away\" from 'i' or 'f' has\n** no precision left for a fractional part; either way, how 'f' is\n** truncated is irrelevant.) When 'f' is NaN, comparisons must result\n** in false.\n*/\nstatic int LTintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f > cast_num(LUA_MININTEGER))  /* minint < f <= maxint ? */\n      return (i < cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f <= minint <= i (or 'f' is NaN)  -->  not(i < f) */\n      return 0;\n  }\n#endif\n  return luai_numlt(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Check whether integer 'i' is less than or equal to float 'f'.\n** See comments on previous function.\n*/\nstatic int LEintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f >= cast_num(LUA_MININTEGER))  /* minint <= f <= maxint ? */\n      return (i <= cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f < minint <= i (or 'f' is NaN)  -->  not(i <= f) */\n      return 0;\n  }\n#endif\n  return luai_numle(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Return 'l < r', for numbers.\n*/\nstatic int LTnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li < ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LTintfloat(li, fltvalue(r));  /* l < r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numlt(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /* NaN < i is always false */\n    else  /* without NaN, (l < r)  <-->  not(r <= l) */\n      return !LEintfloat(ivalue(r), lf);  /* not (r <= l) ? */\n  }\n}\n\n\n/*\n** Return 'l <= r', for numbers.\n*/\nstatic int LEnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li <= ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LEintfloat(li, fltvalue(r));  /* l <= r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numle(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /*  NaN <= i is always false */\n    else  /* without NaN, (l <= r)  <-->  not(r < l) */\n      return !LTintfloat(ivalue(r), lf);  /* not (r < l) ? */\n  }\n}\n\n\n/*\n** Main operation less than; return 'l < r'.\n*/\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LTnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) < 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0)  /* no metamethod? */\n    luaG_ordererror(L, l, r);  /* error */\n  return res;\n}\n\n\n/*\n** Main operation less than or equal to; return 'l <= r'. If it needs\n** a metamethod and there is no '__le', try '__lt', based on\n** l <= r iff !(r < l) (assuming a total order). If the metamethod\n** yields during this substitution, the continuation has to know\n** about it (to negate the result of r<l); bit CIST_LEQ in the call\n** status keeps that information.\n*/\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LEnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0)  /* try 'le' */\n    return res;\n  else {  /* try 'lt': */\n    L->ci->callstatus |= CIST_LEQ;  /* mark it is doing 'lt' for 'le' */\n    res = luaT_callorderTM(L, r, l, TM_LT);\n    L->ci->callstatus ^= CIST_LEQ;  /* clear mark */\n    if (res < 0)\n      luaG_ordererror(L, l, r);\n    return !res;  /* result is negated */\n  }\n}\n\n\n/*\n** Main operation for equality of Lua values; return 't1 == t2'.\n** L == NULL means raw equality (no metamethods)\n*/\nint luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  if (ttype(t1) != ttype(t2)) {  /* not the same variant? */\n    if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)\n      return 0;  /* only numbers can be equal with different variants */\n    else {  /* two numbers with different variants */\n      lua_Integer i1, i2;  /* compare them as integers */\n      return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);\n    }\n  }\n  /* values have same type and same variant */\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));\n    case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TLCF: return fvalue(t1) == fvalue(t2);\n    case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default:\n      return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL)  /* no TM? */\n    return 0;  /* objects are different */\n  luaT_callTM(L, tm, t1, t2, L->top, 1);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\n/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */\n#define tostring(L,o)  \\\n\t(ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))\n\n#define isemptystr(o)\t(ttisshrstring(o) && tsvalue(o)->shrlen == 0)\n\n/* copy strings in stack from top - n up to top - 1 to buffer */\nstatic void copy2buff (StkId top, int n, char *buff) {\n  size_t tl = 0;  /* size already copied */\n  do {\n    size_t l = vslen(top - n);  /* length of string being copied */\n    memcpy(buff + tl, svalue(top - n), l * sizeof(char));\n    tl += l;\n  } while (--n > 0);\n}\n\n\n/*\n** Main operation for concatenation: concat 'total' values in the stack,\n** from 'L->top - total' up to 'L->top - 1'.\n*/\nvoid luaV_concat (lua_State *L, int total) {\n  lua_assert(total >= 2);\n  do {\n    StkId top = L->top;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1))\n      luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT);\n    else if (isemptystr(top - 1))  /* second operand is empty? */\n      cast_void(tostring(L, top - 2));  /* result is first operand */\n    else if (isemptystr(top - 2)) {  /* first operand is an empty string? */\n      setobjs2s(L, top - 2, top - 1);  /* result is second op. */\n    }\n    else {\n      /* at least two non-empty string values; get as many as possible */\n      size_t tl = vslen(top - 1);\n      TString *ts;\n      /* collect total length and number of strings */\n      for (n = 1; n < total && tostring(L, top - n - 1); n++) {\n        size_t l = vslen(top - n - 1);\n        if (l >= (MAX_SIZE/sizeof(char)) - tl)\n          luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */\n        char buff[LUAI_MAXSHORTLEN];\n        copy2buff(top, n, buff);  /* copy strings to buffer */\n        ts = luaS_newlstr(L, buff, tl);\n      }\n      else {  /* long string; copy strings directly to final result */\n        ts = luaS_createlngstrobj(L, tl);\n        copy2buff(top, n, getstr(ts));\n      }\n      setsvalue2s(L, top - n, ts);  /* create result */\n    }\n    total -= n-1;  /* got 'n' strings to create 1 new */\n    L->top -= n-1;  /* popped 'n' strings and pushed one */\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\n/*\n** Main operation 'ra' = #rb'.\n*/\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n  const TValue *tm;\n  switch (ttype(rb)) {\n    case LUA_TTABLE: {\n      Table *h = hvalue(rb);\n      tm = fasttm(L, h->metatable, TM_LEN);\n      if (tm) break;  /* metamethod? break switch to call it */\n      setivalue(ra, luaH_getn(h));  /* else primitive len */\n      return;\n    }\n    case LUA_TSHRSTR: {\n      setivalue(ra, tsvalue(rb)->shrlen);\n      return;\n    }\n    case LUA_TLNGSTR: {\n      setivalue(ra, tsvalue(rb)->u.lnglen);\n      return;\n    }\n    default: {  /* try metamethod */\n      tm = luaT_gettmbyobj(L, rb, TM_LEN);\n      if (ttisnil(tm))  /* no metamethod? */\n        luaG_typeerror(L, rb, \"get length of\");\n      break;\n    }\n  }\n  luaT_callTM(L, tm, rb, rb, ra, 1);\n}\n\n\n/*\n** Integer division; return 'm // n', that is, floor(m/n).\n** C division truncates its result (rounds towards zero).\n** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,\n** otherwise 'floor(q) == trunc(q) - 1'.\n*/\nlua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to divide by zero\");\n    return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */\n  }\n  else {\n    lua_Integer q = m / n;  /* perform C division */\n    if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */\n      q -= 1;  /* correct result for different rounding */\n    return q;\n  }\n}\n\n\n/*\n** Integer modulus; return 'm % n'. (Assume that C '%' with\n** negative operands follows C99 behavior. See previous comment\n** about luaV_div.)\n*/\nlua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to perform 'n%%0'\");\n    return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */\n  }\n  else {\n    lua_Integer r = m % n;\n    if (r != 0 && (m ^ n) < 0)  /* 'm/n' would be non-integer negative? */\n      r += n;  /* correct result for different rounding */\n    return r;\n  }\n}\n\n\n/* number of bits in an integer */\n#define NBITS\tcast_int(sizeof(lua_Integer) * CHAR_BIT)\n\n/*\n** Shift left operation. (Shift right just negates 'y'.)\n*/\nlua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {\n  if (y < 0) {  /* shift right? */\n    if (y <= -NBITS) return 0;\n    else return intop(>>, x, -y);\n  }\n  else {  /* shift left */\n    if (y >= NBITS) return 0;\n    else return intop(<<, x, y);\n  }\n}\n\n\n/*\n** check whether cached closure in prototype 'p' may be reused, that is,\n** whether there is a cached closure with the same upvalues needed by\n** new closure to be created.\n*/\nstatic LClosure *getcached (Proto *p, UpVal **encup, StkId base) {\n  LClosure *c = p->cache;\n  if (c != NULL) {  /* is there a cached closure? */\n    int nup = p->sizeupvalues;\n    Upvaldesc *uv = p->upvalues;\n    int i;\n    for (i = 0; i < nup; i++) {  /* check whether it has right upvalues */\n      TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;\n      if (c->upvals[i]->v != v)\n        return NULL;  /* wrong upvalue; cannot reuse closure */\n    }\n  }\n  return c;  /* return cached closure (or NULL if no cached closure) */\n}\n\n\n/*\n** create a new Lua closure, push it in the stack, and initialize\n** its upvalues. Note that the closure is not cached if prototype is\n** already black (which means that 'cache' was already cleared by the\n** GC).\n*/\nstatic void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,\n                         StkId ra) {\n  int nup = p->sizeupvalues;\n  Upvaldesc *uv = p->upvalues;\n  int i;\n  LClosure *ncl = luaF_newLclosure(L, nup);\n  ncl->p = p;\n  setclLvalue(L, ra, ncl);  /* anchor new closure in stack */\n  for (i = 0; i < nup; i++) {  /* fill in its upvalues */\n    if (uv[i].instack)  /* upvalue refers to local variable? */\n      ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);\n    else  /* get upvalue from enclosing function */\n      ncl->upvals[i] = encup[uv[i].idx];\n    ncl->upvals[i]->refcount++;\n    /* new closure is white, so we do not need a barrier here */\n  }\n  if (!isblack(p))  /* cache will not break GC invariant? */\n    p->cache = ncl;  /* save it on cache for reuse */\n}\n\n\n/*\n** finish execution of an opcode interrupted by an yield\n*/\nvoid luaV_finishOp (lua_State *L) {\n  CallInfo *ci = L->ci;\n  StkId base = ci->u.l.base;\n  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */\n  OpCode op = GET_OPCODE(inst);\n  switch (op) {  /* finish its execution */\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV:\n    case OP_BAND: case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR:\n    case OP_MOD: case OP_POW:\n    case OP_UNM: case OP_BNOT: case OP_LEN:\n    case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {\n      setobjs2s(L, base + GETARG_A(inst), --L->top);\n      break;\n    }\n    case OP_LE: case OP_LT: case OP_EQ: {\n      int res = !l_isfalse(L->top - 1);\n      L->top--;\n      if (ci->callstatus & CIST_LEQ) {  /* \"<=\" using \"<\" instead? */\n        lua_assert(op == OP_LE);\n        ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        res = !res;  /* negate result */\n      }\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);\n      if (res != GETARG_A(inst))  /* condition failed? */\n        ci->u.l.savedpc++;  /* skip jump instruction */\n      break;\n    }\n    case OP_CONCAT: {\n      StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */\n      int b = GETARG_B(inst);      /* first element to concatenate */\n      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */\n      setobj2s(L, top - 2, top);  /* put TM result in proper position */\n      if (total > 1) {  /* are there elements to concat? */\n        L->top = top - 1;  /* top is one after last element (at top-2) */\n        luaV_concat(L, total);  /* concat them (may yield again) */\n      }\n      /* move final result to final position */\n      setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);\n      L->top = ci->top;  /* restore top */\n      break;\n    }\n    case OP_TFORCALL: {\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);\n      L->top = ci->top;  /* correct top */\n      break;\n    }\n    case OP_CALL: {\n      if (GETARG_C(inst) - 1 >= 0)  /* nresults >= 0? */\n        L->top = ci->top;  /* adjust results */\n      break;\n    }\n    case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n\n\n/*\n** {==================================================================\n** Function 'luaV_execute': main interpreter loop\n** ===================================================================\n*/\n\n\n/*\n** some macros for common tasks in 'luaV_execute'\n*/\n\n\n#define RA(i)\t(base+GETARG_A(i))\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n\n\n/* execute a jump instruction */\n#define dojump(ci,i,e) \\\n  { int a = GETARG_A(i); \\\n    if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \\\n    ci->u.l.savedpc += GETARG_sBx(i) + e; }\n\n/* for test instructions, execute the jump instruction that follows it */\n#define donextjump(ci)\t{ i = *ci->u.l.savedpc; dojump(ci, i, 1); }\n\n\n#define Protect(x)\t{ {x;}; base = ci->u.l.base; }\n\n#define checkGC(L,c)  \\\n\t{ luaC_condGC(L, L->top = (c),  /* limit of live values */ \\\n                         Protect(L->top = ci->top));  /* restore top */ \\\n           luai_threadyield(L); }\n\n\n/* fetch an instruction and prepare its execution */\n#define vmfetch()\t{ \\\n  i = *(ci->u.l.savedpc++); \\\n  if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) \\\n    Protect(luaG_traceexec(L)); \\\n  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \\\n  lua_assert(base == ci->u.l.base); \\\n  lua_assert(base <= L->top && L->top < L->stack + L->stacksize); \\\n}\n\n#define vmdispatch(o)\tswitch(o)\n#define vmcase(l)\tcase l:\n#define vmbreak\t\tbreak\n\n\n/*\n** copy of 'luaV_gettable', but protecting the call to potential\n** metamethod (which can reallocate the stack)\n*/\n#define gettableProtected(L,t,k,v)  { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else Protect(luaV_finishget(L,t,k,v,slot)); }\n\n\n/* same for 'luaV_settable' */\n#define settableProtected(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    Protect(luaV_finishset(L,t,k,v,slot)); }\n\n\n\nvoid luaV_execute (lua_State *L) {\n  CallInfo *ci = L->ci;\n  LClosure *cl;\n  TValue *k;\n  StkId base;\n  ci->callstatus |= CIST_FRESH;  /* fresh invocation of 'luaV_execute\" */\n newframe:  /* reentry point when frame changes (call/return) */\n  lua_assert(ci == L->ci);\n  cl = clLvalue(ci->func);  /* local reference to function's closure */\n  k = cl->p->k;  /* local reference to function's constant table */\n  base = ci->u.l.base;  /* local copy of function's base */\n  /* main loop of interpreter */\n  for (;;) {\n    Instruction i;\n    StkId ra;\n    vmfetch();\n    vmdispatch (GET_OPCODE(i)) {\n      vmcase(OP_MOVE) {\n        setobjs2s(L, ra, RB(i));\n        vmbreak;\n      }\n      vmcase(OP_LOADK) {\n        TValue *rb = k + GETARG_Bx(i);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADKX) {\n        TValue *rb;\n        lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n        rb = k + GETARG_Ax(*ci->u.l.savedpc++);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADBOOL) {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) ci->u.l.savedpc++;  /* skip next instruction (if C) */\n        vmbreak;\n      }\n      vmcase(OP_LOADNIL) {\n        int b = GETARG_B(i);\n        do {\n          setnilvalue(ra++);\n        } while (b--);\n        vmbreak;\n      }\n      vmcase(OP_GETUPVAL) {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        vmbreak;\n      }\n      vmcase(OP_GETTABUP) {\n        TValue *upval = cl->upvals[GETARG_B(i)]->v;\n        TValue *rc = RKC(i);\n        gettableProtected(L, upval, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_GETTABLE) {\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        gettableProtected(L, rb, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_SETTABUP) {\n        TValue *upval = cl->upvals[GETARG_A(i)]->v;\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, upval, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_SETUPVAL) {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_upvalbarrier(L, uv);\n        vmbreak;\n      }\n      vmcase(OP_SETTABLE) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, ra, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_NEWTABLE) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Table *t = luaH_new(L);\n        sethvalue(L, ra, t);\n        if (b != 0 || c != 0)\n          luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_SELF) {\n        const TValue *aux;\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        setobjs2s(L, ra + 1, rb);\n        if (luaV_fastget(L, rb, key, aux, luaH_getstr)) {\n          setobj2s(L, ra, aux);\n        }\n        else Protect(luaV_finishget(L, rb, rc, ra, aux));\n        vmbreak;\n      }\n      vmcase(OP_ADD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(+, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numadd(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); }\n        vmbreak;\n      }\n      vmcase(OP_SUB) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(-, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numsub(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); }\n        vmbreak;\n      }\n      vmcase(OP_MUL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(*, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_nummul(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); }\n        vmbreak;\n      }\n      vmcase(OP_DIV) {  /* float division (always with floats) */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numdiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); }\n        vmbreak;\n      }\n      vmcase(OP_BAND) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(&, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); }\n        vmbreak;\n      }\n      vmcase(OP_BOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(|, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); }\n        vmbreak;\n      }\n      vmcase(OP_BXOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(^, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); }\n        vmbreak;\n      }\n      vmcase(OP_SHL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); }\n        vmbreak;\n      }\n      vmcase(OP_SHR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, -ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); }\n        vmbreak;\n      }\n      vmcase(OP_MOD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_mod(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          lua_Number m;\n          luai_nummod(L, nb, nc, m);\n          setfltvalue(ra, m);\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); }\n        vmbreak;\n      }\n      vmcase(OP_IDIV) {  /* floor division */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_div(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numidiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); }\n        vmbreak;\n      }\n      vmcase(OP_POW) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numpow(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); }\n        vmbreak;\n      }\n      vmcase(OP_UNM) {\n        TValue *rb = RB(i);\n        lua_Number nb;\n        if (ttisinteger(rb)) {\n          lua_Integer ib = ivalue(rb);\n          setivalue(ra, intop(-, 0, ib));\n        }\n        else if (tonumber(rb, &nb)) {\n          setfltvalue(ra, luai_numunm(L, nb));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));\n        }\n        vmbreak;\n      }\n      vmcase(OP_BNOT) {\n        TValue *rb = RB(i);\n        lua_Integer ib;\n        if (tointeger(rb, &ib)) {\n          setivalue(ra, intop(^, ~l_castS2U(0), ib));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));\n        }\n        vmbreak;\n      }\n      vmcase(OP_NOT) {\n        TValue *rb = RB(i);\n        int res = l_isfalse(rb);  /* next assignment may change this value */\n        setbvalue(ra, res);\n        vmbreak;\n      }\n      vmcase(OP_LEN) {\n        Protect(luaV_objlen(L, ra, RB(i)));\n        vmbreak;\n      }\n      vmcase(OP_CONCAT) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        StkId rb;\n        L->top = base + c + 1;  /* mark the end of concat operands */\n        Protect(luaV_concat(L, c - b + 1));\n        ra = RA(i);  /* 'luaV_concat' may invoke TMs and move the stack */\n        rb = base + b;\n        setobjs2s(L, ra, rb);\n        checkGC(L, (ra >= rb ? ra + 1 : rb));\n        L->top = ci->top;  /* restore top */\n        vmbreak;\n      }\n      vmcase(OP_JMP) {\n        dojump(ci, i, 0);\n        vmbreak;\n      }\n      vmcase(OP_EQ) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (luaV_equalobj(L, rb, rc) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LT) {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LE) {\n        Protect(\n          if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_TEST) {\n        if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))\n            ci->u.l.savedpc++;\n          else\n          donextjump(ci);\n        vmbreak;\n      }\n      vmcase(OP_TESTSET) {\n        TValue *rb = RB(i);\n        if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))\n          ci->u.l.savedpc++;\n        else {\n          setobjs2s(L, ra, rb);\n          donextjump(ci);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CALL) {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        if (luaD_precall(L, ra, nresults)) {  /* C function? */\n          if (nresults >= 0)\n            L->top = ci->top;  /* adjust results */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {  /* Lua function */\n          ci = L->ci;\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_TAILCALL) {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        if (luaD_precall(L, ra, LUA_MULTRET)) {  /* C function? */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {\n          /* tail call: put called frame (n) in place of caller one (o) */\n          CallInfo *nci = L->ci;  /* called frame */\n          CallInfo *oci = nci->previous;  /* caller frame */\n          StkId nfunc = nci->func;  /* called function */\n          StkId ofunc = oci->func;  /* caller function */\n          /* last stack slot filled by 'precall' */\n          StkId lim = nci->u.l.base + getproto(nfunc)->numparams;\n          int aux;\n          /* close all upvalues from previous call */\n          if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);\n          /* move new frame into old one */\n          for (aux = 0; nfunc + aux < lim; aux++)\n            setobjs2s(L, ofunc + aux, nfunc + aux);\n          oci->u.l.base = ofunc + (nci->u.l.base - nfunc);  /* correct base */\n          oci->top = L->top = ofunc + (L->top - nfunc);  /* correct top */\n          oci->u.l.savedpc = nci->u.l.savedpc;\n          oci->callstatus |= CIST_TAIL;  /* function was tail called */\n          ci = L->ci = oci;  /* remove new frame */\n          lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_RETURN) {\n        int b = GETARG_B(i);\n        if (cl->p->sizep > 0) luaF_close(L, base);\n        b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));\n        if (ci->callstatus & CIST_FRESH)  /* local 'ci' still from callee */\n          return;  /* external invocation: return */\n        else {  /* invocation via reentry: continue execution */\n          ci = L->ci;\n          if (b) L->top = ci->top;\n          lua_assert(isLua(ci));\n          lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n      }\n      vmcase(OP_FORLOOP) {\n        if (ttisinteger(ra)) {  /* integer loop? */\n          lua_Integer step = ivalue(ra + 2);\n          lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */\n          lua_Integer limit = ivalue(ra + 1);\n          if ((0 < step) ? (idx <= limit) : (limit <= idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgivalue(ra, idx);  /* update internal index... */\n            setivalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        else {  /* floating loop */\n          lua_Number step = fltvalue(ra + 2);\n          lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */\n          lua_Number limit = fltvalue(ra + 1);\n          if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                  : luai_numle(limit, idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgfltvalue(ra, idx);  /* update internal index... */\n            setfltvalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        vmbreak;\n      }\n      vmcase(OP_FORPREP) {\n        TValue *init = ra;\n        TValue *plimit = ra + 1;\n        TValue *pstep = ra + 2;\n        lua_Integer ilimit;\n        int stopnow;\n        if (ttisinteger(init) && ttisinteger(pstep) &&\n            forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {\n          /* all values are integer */\n          lua_Integer initv = (stopnow ? 0 : ivalue(init));\n          setivalue(plimit, ilimit);\n          setivalue(init, intop(-, initv, ivalue(pstep)));\n        }\n        else {  /* try making all values floats */\n          lua_Number ninit; lua_Number nlimit; lua_Number nstep;\n          if (!tonumber(plimit, &nlimit))\n            luaG_runerror(L, \"'for' limit must be a number\");\n          setfltvalue(plimit, nlimit);\n          if (!tonumber(pstep, &nstep))\n            luaG_runerror(L, \"'for' step must be a number\");\n          setfltvalue(pstep, nstep);\n          if (!tonumber(init, &ninit))\n            luaG_runerror(L, \"'for' initial value must be a number\");\n          setfltvalue(init, luai_numsub(L, ninit, nstep));\n        }\n        ci->u.l.savedpc += GETARG_sBx(i);\n        vmbreak;\n      }\n      vmcase(OP_TFORCALL) {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb + 3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = ci->top;\n        i = *(ci->u.l.savedpc++);  /* go to next instruction */\n        ra = RA(i);\n        lua_assert(GET_OPCODE(i) == OP_TFORLOOP);\n        goto l_tforloop;\n      }\n      vmcase(OP_TFORLOOP) {\n        l_tforloop:\n        if (!ttisnil(ra + 1)) {  /* continue loop? */\n          setobjs2s(L, ra, ra + 1);  /* save control variable */\n           ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETLIST) {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        unsigned int last;\n        Table *h;\n        if (n == 0) n = cast_int(L->top - ra) - 1;\n        if (c == 0) {\n          lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n          c = GETARG_Ax(*ci->u.l.savedpc++);\n        }\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* preallocate it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          luaH_setint(L, h, last--, val);\n          luaC_barrierback(L, h, val);\n        }\n        L->top = ci->top;  /* correct top (in case of previous open call) */\n        vmbreak;\n      }\n      vmcase(OP_CLOSURE) {\n        Proto *p = cl->p->p[GETARG_Bx(i)];\n        LClosure *ncl = getcached(p, cl->upvals, base);  /* cached closure */\n        if (ncl == NULL)  /* no match? */\n          pushclosure(L, p, cl->upvals, base, ra);  /* create a new one */\n        else\n          setclLvalue(L, ra, ncl);  /* push cashed closure */\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_VARARG) {\n        int b = GETARG_B(i) - 1;  /* required results */\n        int j;\n        int n = cast_int(base - ci->func) - cl->p->numparams - 1;\n        if (n < 0)  /* less arguments than parameters? */\n          n = 0;  /* no vararg arguments */\n        if (b < 0) {  /* B == 0? */\n          b = n;  /* get all var. arguments */\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          L->top = ra + n;\n        }\n        for (j = 0; j < b && j < n; j++)\n          setobjs2s(L, ra + j, base - n + j);\n        for (; j < b; j++)  /* complete required results with nil */\n          setnilvalue(ra + j);\n        vmbreak;\n      }\n      vmcase(OP_EXTRAARG) {\n        lua_assert(0);\n        vmbreak;\n      }\n    }\n  }\n}\n\n/* }================================================================== */\n\n"
  },
  {
    "path": "WebGLPlugins/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUA_NOCVTN2S)\n#define cvt2str(o)\tttisnumber(o)\n#else\n#define cvt2str(o)\t0\t/* no conversion from numbers to strings */\n#endif\n\n\n#if !defined(LUA_NOCVTS2N)\n#define cvt2num(o)\tttisstring(o)\n#else\n#define cvt2num(o)\t0\t/* no conversion from strings to numbers */\n#endif\n\n\n/*\n** You can define LUA_FLOORN2I if you want to convert floats to integers\n** by flooring them (instead of raising an error if they are not\n** integral values)\n*/\n#if !defined(LUA_FLOORN2I)\n#define LUA_FLOORN2I\t\t0\n#endif\n\n\n#define tonumber(o,n) \\\n\t(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))\n\n#define tointeger(o,i) \\\n    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n\n#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))\n\n#define luaV_rawequalobj(t1,t2)\t\tluaV_equalobj(NULL,t1,t2)\n\n\n/*\n** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,\n** return 1 with 'slot' pointing to 't[k]' (final result).  Otherwise,\n** return 0 (meaning it will have to check metamethod) with 'slot'\n** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).\n** 'f' is the raw get function to use.\n*/\n#define luaV_fastget(L,t,k,slot,f) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = f(hvalue(t), k),  /* else, do raw access */  \\\n      !ttisnil(slot)))  /* result not nil? */\n\n/*\n** standard implementation for 'gettable'\n*/\n#define luaV_gettable(L,t,k,v) { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else luaV_finishget(L,t,k,v,slot); }\n\n\n/*\n** Fast track for set table. If 't' is a table and 't[k]' is not nil,\n** call GC barrier, do a raw 't[k]=v', and return true; otherwise,\n** return false with 'slot' equal to NULL (if 't' is not a table) or\n** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro\n** returns true, there is no need to 'invalidateTMcache', because the\n** call is not creating a new entry.\n*/\n#define luaV_fastset(L,t,k,slot,f,v) \\\n  (!ttistable(t) \\\n   ? (slot = NULL, 0) \\\n   : (slot = f(hvalue(t), k), \\\n     ttisnil(slot) ? 0 \\\n     : (luaC_barrierback(L, hvalue(t), v), \\\n        setobj2t(L, cast(TValue *,slot), v), \\\n        1)))\n\n\n#define luaV_settable(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    luaV_finishset(L,t,k,v,slot); }\n\n\n\nLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);\nLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);\nLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishOp (lua_State *L);\nLUAI_FUNC void luaV_execute (lua_State *L);\nLUAI_FUNC void luaV_concat (lua_State *L, int total);\nLUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);\nLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0)\n    return EOZ;\n  z->n = size - 1;  /* discount char being returned */\n  z->p = buff;\n  return cast_uchar(*(z->p++));\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (z->n == 0) {  /* no bytes in buffer? */\n      if (luaZ_fill(z) == EOZ)  /* try to read more */\n        return n;  /* no more input; return number of missing bytes */\n      else {\n        z->n++;  /* luaZ_fill consumed first byte; put it back */\n        z->p--;\n      }\n    }\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n"
  },
  {
    "path": "WebGLPlugins/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))\n\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_buffremove(buff,i)\t((buff)->n -= (i))\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \\\n\t\t\t\t(buff)->buffsize, size), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);\t/* read next n bytes */\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\t\t/* reader function */\n  void *data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "WebGLPlugins/perflib.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include <stdio.h>\n#include <string.h>\n\n#define ROOT_TABLE 1\n#define MARKED_TABLE 2\n\n#define RT_GLOBAL 1\n#define RT_REGISTRY 2\n#define RT_UPVALUE 3\n#define RT_LOCAL 4\n\n#if defined(_MSC_VER) && _MSC_VER < 1900\n\n#define snprintf c99_snprintf\n#define vsnprintf c99_vsnprintf\n\n__inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)\n{\n    int count = -1;\n\n    if (size != 0)\n        count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);\n    if (count == -1)\n        count = _vscprintf(format, ap);\n\n    return count;\n}\n\n__inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)\n{\n    int count;\n    va_list ap;\n\n    va_start(ap, format);\n    count = c99_vsnprintf(outBuf, size, format, ap);\n    va_end(ap);\n\n    return count;\n}\n\n#endif\n\n#if LUA_VERSION_NUM == 501\nstatic void lua_rawsetp(lua_State *L, int idx, const void *p) {\n\tif (idx < 0) {\n\t\tidx += lua_gettop(L) + 1;\n\t}\n\tlua_pushlightuserdata(L, (void *)p);\n\tlua_insert(L, -2);\n\tlua_rawset(L, idx);\n}\n\nstatic void lua_rawgetp(lua_State *L, int idx, const void *p) {\n\tif (idx < 0) {\n\t\tidx += lua_gettop(L) + 1;\n\t}\n\tlua_pushlightuserdata(L, (void *)p);\n\tlua_rawget(L, idx);\n}\n\n#endif\n\n#if LUA_VERSION_NUM == 503\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n#endif\n\nstatic void make_root(lua_State *L, const void *p, const char *name, int type, const char *used_in, int need_stat) {\n\tlua_rawgetp(L, ROOT_TABLE, p);\n\tif (lua_isnil(L, -1)) {\n\t\tlua_pop(L, 1);\n\t\tlua_newtable(L); // -- root\n\t\tlua_newtable(L); // root.used_in\n\t\tif (used_in != NULL) {\n\t\t\tlua_pushboolean(L, 1);\n\t\t\tlua_setfield(L, -2, used_in);\n\t\t}\n\t\tlua_setfield(L, -2, \"used_in\");\n\t\tif (need_stat) {\n\t\t    lua_pushstring(L, name);\n\t\t    lua_setfield(L, -2, \"name\");\n\t\t    lua_pushnumber(L, type);\n\t\t    lua_setfield(L, -2, \"type\");\n\t\t}\n\t\t\n\t\tlua_pushvalue(L, -1);\n\t\tlua_rawsetp(L, ROOT_TABLE, p); //ROOT_TABLE[p] = root\n\t} else {\n\t\tif (used_in != NULL) {\n\t\t\tlua_getfield(L, -1, \"used_in\");\n\t\t\tlua_pushboolean(L, 1);\n\t\t\tlua_setfield(L, -2, used_in);\n\t\t\tlua_pop(L, 1);\n\t\t}\n\t}\n}\n\n//static void print_top(lua_State *L) {\n//\tlua_getglobal(L, \"print\");\n//\tlua_pushvalue(L, -2);\n//\tlua_call(L, 1, 0);\n//}\n//\n//static void print_str(lua_State *L, const char *str) {\n//\tlua_getglobal(L, \"print\");\n//\tlua_pushstring(L, str);\n//\tlua_call(L, 1, 0);\n//}\n\nstatic int is_marked(lua_State *L, const void *p) {\n\tlua_rawgetp(L, MARKED_TABLE, p);\n\tif (lua_isnil(L, -1)) {\n\t\tlua_pop(L, 1);\n\t\treturn 0;\n\t} else {\n\t\tlua_pop(L, 1);\n\t\treturn 1;\n\t}\n}\n\nstatic void marked(lua_State *L, const void *p, int len) {\n\tlua_pushnumber(L, len);\n    lua_rawsetp(L, MARKED_TABLE, p);\n}\n\nstatic void mark_object(lua_State *L, lua_State *dL);\n\nstatic void mark_table(lua_State *L, lua_State *dL) {\n\tconst void *p = lua_topointer(L, -1);\n\tint len = 0;\n\t\n\tif (!is_marked(dL, p)) {\n\t\tmarked(dL, p, 0);\n\n\t\tlua_pushnil(L);\n\t\twhile (lua_next(L, -2) != 0) {\n\t\t\t++len;\n\t\t\tmark_object(L, dL);\n\t\t\tlua_pop(L, 1);\n\t\t\tmark_object(L, dL);\n\t\t}\n\t\t\n\t\tmarked(dL, p, len);\n\t}\n}\n\nstatic void mark_function(lua_State *L, lua_State *dL) {\n\tconst void *p = lua_topointer(L, -1);\n\tint i;\n\tlua_Debug ar;\n\tchar used_in[128];\n\tconst char *name;\n\t\n\t\n\tif (!is_marked(dL, p)) {\n\t\tmarked(dL, p, 0); //已经在table里头算了\n\t\t\n\t\tlua_pushvalue(L, -1);\n\t\tlua_getinfo(L, \">S\", &ar);\n\t\tsnprintf(used_in, sizeof(used_in) - 1, \"%s:%d~%d\", ar.short_src, ar.linedefined, ar.lastlinedefined);\n\t\tused_in[sizeof(used_in) - 1] = 0;\n\t\t\n\t\tfor (i=1;;i++) {\n\t\t\tname = lua_getupvalue(L,-1,i);\n\t\t\tif (name == NULL)\n\t\t\t\tbreak;\n\t\t\tp = lua_topointer(L, -1);\n\t\t\t\n\t\t\tif (*name != '\\0' && LUA_TTABLE == lua_type(L, -1)) {\n\t\t\t\tmake_root(dL, p, name, RT_UPVALUE, used_in, 1);\n\t\t\t\tlua_insert(dL, MARKED_TABLE);\n\t\t\t\tmark_object(L, dL);\n\t\t\t\tlua_remove(dL, MARKED_TABLE);\n\t\t\t} else if (LUA_TFUNCTION == lua_type(L, -1)) {\n\t\t\t\tmark_function(L, dL);\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t}\n\t}\n}\n\nstatic void mark_object(lua_State *L, lua_State *dL) {\n\tswitch (lua_type(L, -1)) {\n\tcase LUA_TTABLE:\n\t\tmark_table(L, dL);\n\t\tbreak;\n\tcase LUA_TFUNCTION:\n\t\tmark_function(L, dL);\n\t\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n}\n\nstatic void make_report(lua_State* L, lua_State* dL) {\n\tint size = 0;\n\tint i = 0;\n\tluaL_Buffer b;\n\t\n\tlua_newtable(L);\n\t\n\tlua_pushnil(dL);\n\twhile (lua_next(dL, ROOT_TABLE) != 0) {\n\t\tlua_getfield(dL, -1, \"name\");\n\t\tif (lua_isnil(dL, -1)) {\n\t\t\tlua_pop(dL, 2);\n\t\t\tcontinue;\n\t\t} else {\n\t\t\tlua_pop(dL, 1);\n\t\t}\n\t\t\n\t\tlua_newtable(L);\n\t\tsize = 0;\n\t\t\n\t\tlua_pushnil(dL);\n\t\twhile (lua_next(dL, -2) != 0) {\n\t\t\tif (LUA_TLIGHTUSERDATA == lua_type(dL, -2)) { \n\t\t\t\tsize += (int)lua_tointeger(dL, -1);\n\t\t\t} \n\t\t\t\n\t\t\tlua_pop(dL, 1);\n\t\t}\n\t\tlua_pushnumber(L, size);\n\t\tlua_setfield(L, -2, \"size\");\n\t\t\n\t\tlua_pushfstring(L, \"%p\", lua_touserdata(dL, -2));\n\t\tlua_setfield(L, -2, \"pointer\");\n\t\t\n\t\tlua_getfield(dL, -1, \"name\");\n\t\tlua_pushstring(L, lua_tostring(dL, -1));\n\t\tlua_pop(dL, 1);\n\t\tlua_setfield(L, -2, \"name\");\n\t\t\n\t\tlua_getfield(dL, -1, \"type\");\n\t\tlua_pushnumber(L, lua_tonumber(dL, -1));\n\t\tlua_pop(dL, 1);\n\t\tlua_setfield(L, -2, \"type\");\n\t\t\n\t\tlua_getfield(dL, -1, \"used_in\");\n\t\tluaL_buffinit(L, &b);\n\t\tlua_pushnil(dL);\n\t\twhile (lua_next(dL, -2) != 0) {\n\t\t\tlua_pop(dL, 1);\n\t\t\tluaL_addstring(&b, lua_tostring(dL, -1));\n\t\t\tluaL_addchar(&b, ';');\n\t\t}\n\t\tluaL_pushresult(&b);\n\t\tlua_pop(dL, 1);\n\t\tlua_setfield(L, -2, \"used_in\");\n\t\t\n\t\t++i;\n\t\tlua_rawseti(L, -2, i);\n\t\t\n\t\tlua_pop(dL, 1);\n\t}\n}\n\nstatic int mark_root_table(lua_State* L, lua_State* dL, int type) {\n\tint len = 0;\n\t\n\tlua_pushnil(L);\n\twhile (lua_next(L, -2) != 0) {\n\t\t++len;\n\t\tif (LUA_TTABLE == lua_type(L, -1)) {\n\t\t\tlua_pushvalue(L, -2);\n\t\t\t\n\t\t\tmake_root(dL, lua_topointer(L, -2), lua_tostring(L, -1), type, NULL, 1);\n\t\t\tlua_pop(L, 1);\n\t\t\tmark_table(L, dL);\n\t\t\tlua_pop(dL, 1);\n\t\t} else {\n\t\t    make_root(dL, lua_topointer(L, -1), \"FUNCTION\", type, NULL, 0);\n\t\t\tmark_object(L, dL);\n\t\t\tlua_pop(dL, 1);\n\t\t}\n\t\tlua_pop(L, 1);\n\t\t\n\t\tmake_root(dL, lua_topointer(L, -1), \"[KEY]\", type, NULL, LUA_TTABLE == lua_type(L, -1));\n\t\tmark_object(L, dL);\n\t\tlua_pop(dL, 1);\n\t}\n\t\n\treturn len;\n}\n\nstatic int snapshot(lua_State* L) {\n\tlua_State *dL = luaL_newstate();\n\tint len;\n\tconst void * p;\n\tlua_newtable(dL);\n\t\n#if LUA_VERSION_NUM == 503\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);\n#else\n\tlua_pushvalue(L, LUA_GLOBALSINDEX);\n#endif\n\tmark_root_table(L, dL, RT_GLOBAL);\n\tlua_pop(L, 1);\n\t\n\tlua_pushvalue(L, LUA_REGISTRYINDEX);\n\tp = lua_topointer(L, -1);\n\tlen = mark_root_table(L, dL, RT_REGISTRY);\n\tlua_pop(L, 1);\n\t\n\tmake_report(L, dL);\n\t\n\tlua_newtable(L);\n\tlua_pushstring(L, \"[REGISTRY Level 1]\");\n\tlua_setfield(L, -2, \"name\");\n\tlua_pushnumber(L, RT_REGISTRY);\n\tlua_setfield(L, -2, \"type\");\n\tlua_pushnumber(L, len);\n\tlua_setfield(L, -2, \"size\");\n\tlua_pushfstring(L, \"%p\", p);\n\tlua_setfield(L, -2, \"pointer\");\n\tlua_pushstring(L, \"\");\n\tlua_setfield(L, -2, \"used_in\");\n\tlua_rawseti(L, -2, lua_objlen(L, -2) + 1);\n\t\n\tlua_close(dL);\n\t\n\treturn 1;\n}\n\nstatic const luaL_Reg preflib[] = {\n\t{\"snapshot\", snapshot},\n\t{NULL, NULL}\n};\n\nLUALIB_API int luaopen_perflib(lua_State* L)\n{\n#if LUA_VERSION_NUM == 503\n\tluaL_newlib(L, preflib);\n\tlua_setglobal(L, \"perf\");\n#else\n\tluaL_register(L, \"perf\", preflib);\n    lua_pop(L, 1);\n#endif\n\treturn 0;\n}\n"
  },
  {
    "path": "WebGLPlugins/xlua.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n#include <string.h>\n#include <stdint.h>\n#include \"i64lib.h\"\n\n#if USING_LUAJIT\n#include \"lj_obj.h\"\n#else\n#include \"lstate.h\"\n#endif\n\n/*\n** stdcall C function support\n*/\n\nstatic int tag = 0;\nstatic const char *const hooknames[] = {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\nstatic int hook_index = -1;\n\nLUA_API void *xlua_tag () \n{\n\treturn &tag;\n}\n\nLUA_API int xlua_get_registry_index() {\n\treturn LUA_REGISTRYINDEX;\n}\n\nLUA_API int xlua_get_lib_version() {\n\treturn 105;\n}\n\nLUA_API int xlua_tocsobj_safe(lua_State *L,int index) {\n\tint *udata = (int *)lua_touserdata (L,index);\n\tif (udata != NULL) {\n\t\tif (lua_getmetatable(L,index)) {\n\t\t    lua_pushlightuserdata(L, &tag);\n\t\t\tlua_rawget(L,-2);\n\t\t\tif (!lua_isnil (L,-1)) {\n\t\t\t\tlua_pop (L, 2);\n\t\t\t\treturn *udata;\n\t\t\t}\n\t\t\tlua_pop (L, 2);\n\t\t}\n\t}\n\treturn -1;\n}\n\nLUA_API int xlua_tocsobj_fast (lua_State *L,int index) {\n\tint *udata = (int *)lua_touserdata (L,index);\n\n\tif(udata!=NULL) \n\t\treturn *udata;\n\treturn -1;\n}\n\n#if LUA_VERSION_NUM == 501\n#undef lua_getglobal\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n\tlua_getfield(L, LUA_GLOBALSINDEX, name);\n\treturn 0;\n}\n\n#undef lua_setglobal\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n\tlua_setfield(L, LUA_GLOBALSINDEX, name);\n}\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n\treturn 0;\n}\n\nLUA_API uint32_t xlua_objlen (lua_State *L, int idx) {\n\treturn lua_objlen (L, idx);\n}\n\nLUA_API uint32_t xlua_touint (lua_State *L, int idx) {\n\treturn (uint32_t)lua_tonumber(L, idx);\n}\n\nLUA_API void xlua_pushuint (lua_State *L, uint32_t n) {\n\tlua_pushnumber(L, n);\n}\n#endif\n\n#if LUA_VERSION_NUM ==503\nLUA_API int lua_setfenv(lua_State *L, int idx)\n{\n    int type = lua_type(L, idx);\n    if(type == LUA_TUSERDATA || type == LUA_TFUNCTION)\n    {\n        lua_setupvalue(L, idx, 1);\n        return 1;\n    }\n    else\n    {\n        return 0;\n    }\n}\n\nLUA_API uint32_t xlua_objlen (lua_State *L, int idx) {\n\treturn (uint32_t)lua_rawlen (L, idx);\n}\n\nLUA_API uint32_t xlua_touint (lua_State *L, int idx) {\n\treturn lua_isinteger(L, idx) ? (uint32_t)lua_tointeger(L, idx) : (uint32_t) lua_tonumber(L, idx);\n}\n\nLUA_API void xlua_pushuint (lua_State *L, uint32_t n) {\n\tlua_pushinteger(L, n);\n}\n\n#undef lua_insert\nLUA_API void lua_insert (lua_State *L, int idx) {\n    lua_rotate(L, idx, 1);\n}\n\n#undef lua_remove\nLUA_API void lua_remove (lua_State *L, int idx) {\n\tlua_rotate(L, idx, -1);\n\tlua_pop(L, 1);\n}\n\n#undef lua_replace\nLUA_API void lua_replace (lua_State *L, int idx) {\n\tlua_copy(L, -1, idx);\n\tlua_pop(L, 1);\n}\n\n#undef lua_pcall\nLUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {\n\treturn lua_pcallk(L, nargs, nresults, errfunc, 0, NULL);\n}\n\n#undef lua_tonumber\nLUA_API lua_Number lua_tonumber (lua_State *L, int idx) {\n\treturn lua_tonumberx(L, idx, NULL);\n}\n\n#endif\n\n#if LUA_VERSION_NUM < 503\n#define lua_absindex(L, index) ((index > 0 || index <= LUA_REGISTRYINDEX) ? index : lua_gettop(L) + index + 1)\n#endif\n\nLUA_API void xlua_getloaders (lua_State *L) {\n\tlua_getglobal(L, \"package\");\n#if LUA_VERSION_NUM == 501\n    lua_getfield(L, -1, \"loaders\");\n#else\n\tlua_getfield(L, -1, \"searchers\");\n#endif\n\tlua_remove(L, -2);\n}\n\nLUA_API void xlua_rawgeti (lua_State *L, int idx, int64_t n) {\n\tlua_rawgeti(L, idx, (lua_Integer)n);\n}\n\nLUA_API void xlua_rawseti (lua_State *L, int idx, int64_t n) {\n\tlua_rawseti(L, idx, (lua_Integer)n);\n}\n\nLUA_API int xlua_ref_indirect(lua_State *L, int indirectRef) {\n\tint ret = 0;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, indirectRef);\n\tlua_pushvalue(L, -2);\n\tret = luaL_ref(L, -2);\n\tlua_pop(L, 2);\n\treturn ret;\n}\n\nLUA_API void xlua_getref_indirect(lua_State *L, int indirectRef, int reference) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, indirectRef);\n\tlua_rawgeti(L, -1, reference);\n\tlua_remove(L, -2);\n}\n\nLUA_API int xlua_tointeger (lua_State *L, int idx) {\n\treturn (int)lua_tointeger(L, idx);\n}\n\nLUA_API void xlua_pushinteger (lua_State *L, int n) {\n\tlua_pushinteger(L, n);\n}\n\nLUA_API void xlua_pushlstring (lua_State *L, const char *s, int len) {\n\tlua_pushlstring(L, s, len);\n}\n\nLUALIB_API int xluaL_loadbuffer (lua_State *L, const char *buff, int size,\n                                const char *name) {\n\treturn luaL_loadbuffer(L, buff, size, name);\n}\n\nstatic int c_lua_gettable(lua_State* L) {    \n    lua_gettable(L, 1);    \n    return 1;\n}\n\nLUA_API int xlua_pgettable(lua_State* L, int idx) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_gettable);\n    lua_pushvalue(L, idx);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    return lua_pcall(L, 2, 1, 0);\n}\n\nstatic int c_lua_gettable_bypath(lua_State* L) {\n\tsize_t len = 0;\n\tconst char * pos = NULL;\n\tconst char * path = lua_tolstring(L, 2, &len);\n\tlua_pushvalue(L, 1);\n\tdo {\n\t\tpos = strchr(path, '.');\n\t\tif (NULL == pos) {\n\t\t\tlua_pushlstring(L, path, len);\n\t\t} else {\n\t\t\tlua_pushlstring(L, path, pos - path);\n\t\t\tlen = len - (pos - path + 1);\n\t\t\tpath = pos + 1;\n\t\t}\n\t\tlua_gettable(L, -2);\n\t\tif (lua_type(L, -1) != LUA_TTABLE) {\n\t\t\tif (NULL != pos) { // not found in path\n\t\t\t\tlua_pushnil(L);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tlua_remove(L, -2);\n\t} while(pos);\n    return 1;\n}\n\nLUA_API int xlua_pgettable_bypath(lua_State* L, int idx, const char *path) {\n\tidx = lua_absindex(L, idx);\n\tlua_pushcfunction(L, c_lua_gettable_bypath);\n\tlua_pushvalue(L, idx);\n\tlua_pushstring(L, path);\n\treturn lua_pcall(L, 2, 1, 0);\n}\n\nstatic int c_lua_settable(lua_State* L) {\n    lua_settable(L, 1);\n    return 0;\n}\n\nLUA_API int xlua_psettable(lua_State* L, int idx) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_settable);\n    lua_pushvalue(L, idx);\n    lua_pushvalue(L, top - 1);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    lua_remove(L, top - 1);\n    return lua_pcall(L, 3, 0, 0);\n}\n\nstatic int c_lua_settable_bypath(lua_State* L) {\n    size_t len = 0;\n\tconst char * pos = NULL;\n\tconst char * path = lua_tolstring(L, 2, &len);\n\tlua_pushvalue(L, 1);\n\tdo {\n\t\tpos = strchr(path, '.');\n\t\tif (NULL == pos) { // last\n\t\t\tlua_pushlstring(L, path, len);\n\t\t\tlua_pushvalue(L, 3);\n\t\t\tlua_settable(L, -3);\n\t\t\tlua_pop(L, 1);\n\t\t\tbreak;\n\t\t} else {\n\t\t\tlua_pushlstring(L, path, pos - path);\n\t\t\tlen = len - (pos - path + 1);\n\t\t\tpath = pos + 1;\n\t\t}\n\t\tlua_gettable(L, -2);\n\t\tif (lua_type(L, -1) != LUA_TTABLE) {\n\t\t\treturn luaL_error(L, \"can not set value to %s\", lua_tostring(L, 2));\n\t\t}\n\t\tlua_remove(L, -2);\n\t} while(pos);\n    return 0;\n}\n\nLUA_API int xlua_psettable_bypath(lua_State* L, int idx, const char *path) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_settable_bypath);\n    lua_pushvalue(L, idx);\n    lua_pushstring(L, path);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    return lua_pcall(L, 3, 0, 0);\n}\n\nstatic int c_lua_getglobal(lua_State* L) {\n\tlua_getglobal(L, lua_tostring(L, 1));\n\treturn 1;\n}\n\nLUA_API int xlua_getglobal (lua_State *L, const char *name) {\n\tlua_pushcfunction(L, c_lua_getglobal);\n\tlua_pushstring(L, name);\n\treturn lua_pcall(L, 1, 1, 0);\n}\n\nstatic int c_lua_setglobal(lua_State* L) {\n\tlua_setglobal(L, lua_tostring(L, 1));\n\treturn 0;\n}\n\nLUA_API int xlua_setglobal (lua_State *L, const char *name) {\n\tint top = lua_gettop(L);\n\tlua_pushcfunction(L, c_lua_setglobal);\n\tlua_pushstring(L, name);\n\tlua_pushvalue(L, top);\n\tlua_remove(L, top);\n\treturn lua_pcall(L, 2, 0, 0);\n}\n\nLUA_API int xlua_tryget_cachedud(lua_State *L, int key, int cache_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);\n\tlua_rawgeti(L, -1, key);\n\tif (!lua_isnil(L, -1))\n\t{\n\t\tlua_remove(L, -2);\n\t\treturn 1;\n\t}\n\tlua_pop(L, 2);\n\treturn 0;\n}\n\nstatic void cacheud(lua_State *L, int key, int cache_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);\n\tlua_pushvalue(L, -2);\n\tlua_rawseti(L, -2, key);\n\tlua_pop(L, 1);\n}\n\n\nLUA_API void xlua_pushcsobj(lua_State *L, int key, int meta_ref, int need_cache, int cache_ref) {\n\tint* pointer = (int*)lua_newuserdata(L, sizeof(int));\n\t*pointer = key;\n\t\n\tif (need_cache) cacheud(L, key, cache_ref);\n\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\n\tlua_setmetatable(L, -2);\n}\n\nvoid print_top(lua_State *L) {\n\tlua_getglobal(L, \"print\");\n\tlua_pushvalue(L, -2);\n\tlua_call(L, 1, 0);\n}\n\nvoid print_str(lua_State *L, char *str) {\n\tlua_getglobal(L, \"print\");\n\tlua_pushstring(L, str);\n\tlua_call(L, 1, 0);\n}\n\nvoid print_value(lua_State *L,  char *str, int idx) {\n\tidx = lua_absindex(L, idx);\n\tlua_getglobal(L, \"print\");\n\tlua_pushstring(L, str);\n\tlua_pushvalue(L, idx);\n\tlua_call(L, 2, 0);\n}\n\n//upvalue --- [1]: methods, [2]:getters, [3]:csindexer, [4]:base, [5]:indexfuncs, [6]:arrayindexer, [7]:baseindex\n//param   --- [1]: obj, [2]: key\nLUA_API int obj_indexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has method\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(2));\n\t\tif (!lua_isnil(L, -1)) {//has getter\n\t\t\tlua_pushvalue(L, 1);\n\t\t\tlua_call(L, 1, 1);\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(6)) && lua_type(L, 2) == LUA_TNUMBER) {\n\t\tlua_pushvalue(L, lua_upvalueindex(6));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_call(L, 2, 2);\n\t\tif (lua_toboolean(L, -2)) {\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 2);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(4))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(4));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(5));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(7)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(4));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(7))) {\n\t\tlua_settop(L, 2);\n\t\tlua_pushvalue(L, lua_upvalueindex(7));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n\nLUA_API int gen_obj_indexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, obj_indexer, 7);\n\treturn 0;\n}\n\n//upvalue --- [1]:setters, [2]:csnewindexer, [3]:base, [4]:newindexfuncs, [5]:arrayindexer, [6]:basenewindex\n//param   --- [1]: obj, [2]: key, [3]: value\nLUA_API int obj_newindexer(lua_State *L) {\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has setter\n\t\t\tlua_pushvalue(L, 1);\n\t\t\tlua_pushvalue(L, 3);\n\t\t\tlua_call(L, 2, 0);\n\t\t\treturn 0;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(2));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_pushvalue(L, 3);\n\t\tlua_call(L, 3, 1);\n\t\tif (lua_toboolean(L, -1)) {\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(5)) && lua_type(L, 2) == LUA_TNUMBER) {\n\t\tlua_pushvalue(L, lua_upvalueindex(5));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_pushvalue(L, 3);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(4));\n\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(6)); //basenewindex = newindexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(3));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(6))) {\n\t\tlua_settop(L, 3);\n\t\tlua_pushvalue(L, lua_upvalueindex(6));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t} else {\n\t\treturn luaL_error(L, \"cannot set %s, no such field\", lua_tostring(L, 2));\n\t}\n}\n\nLUA_API int gen_obj_newindexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, obj_newindexer, 6);\n\treturn 0;\n}\n\n//upvalue --- [1]:getters, [2]:feilds, [3]:base, [4]:indexfuncs, [5]:baseindex\n//param   --- [1]: obj, [2]: key\nLUA_API int cls_indexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has getter\n\t\t\tlua_call(L, 0, 1);\n\t\t\treturn 1;\n\t\t}\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_rawget(L, lua_upvalueindex(2));\n\t\tif (!lua_isnil(L, -1)) {//has feild\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(4));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(5)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(3));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(5))) {\n\t\tlua_settop(L, 2);\n\t\tlua_pushvalue(L, lua_upvalueindex(5));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t} else {\n\t\tlua_pushnil(L);\n\t\treturn 1;\n\t}\n}\n\nLUA_API int gen_cls_indexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, cls_indexer, 5);\n\treturn 0;\n}\n\n//upvalue --- [1]:setters, [2]:base, [3]:indexfuncs, [4]:baseindex\n//param   --- [1]: obj, [2]: key, [3]: value\nLUA_API int cls_newindexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has setter\n\t\t    lua_pushvalue(L, 3);\n\t\t\tlua_call(L, 1, 0);\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(2));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(3));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(4)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(2));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(4))) {\n\t\tlua_settop(L, 3);\n\t\tlua_pushvalue(L, lua_upvalueindex(4));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t} else {\n\t\treturn luaL_error(L, \"no static field %s\", lua_tostring(L, 2));\n\t}\n}\n\nLUA_API int gen_cls_newindexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, cls_newindexer, 4);\n\treturn 0;\n}\n\nLUA_API int errorfunc(lua_State *L) {\n\tlua_getglobal(L, \"debug\");\n\tlua_getfield(L, -1, \"traceback\");\n\tlua_remove(L, -2);\n\tlua_pushvalue(L, 1);\n\tlua_pushnumber(L, 2);\n\tlua_call(L, 2, 1);\n    return 1;\n}\n\nLUA_API int get_error_func_ref(lua_State *L) {\n\tlua_pushcclosure(L, errorfunc, 0);\n\treturn luaL_ref(L, LUA_REGISTRYINDEX);\n}\n\nLUA_API int load_error_func(lua_State *L, int ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, ref);\n\treturn lua_gettop(L);\n}\n\nLUA_API int pcall_prepare(lua_State *L, int error_func_ref, int func_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, error_func_ref);\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, func_ref);\n\treturn lua_gettop(L) - 1;\n}\n\nstatic void hook(lua_State *L, lua_Debug *ar)\n{\n\tint event;\n\t\n\tlua_pushlightuserdata(L, &hook_index);\n\tlua_rawget(L, LUA_REGISTRYINDEX);\n\n\tevent = ar->event;\n\tlua_pushstring(L, hooknames[event]);\n  \n\tlua_getinfo(L, \"nS\", ar);\n\tif (*(ar->what) == 'C') {\n\t\tlua_pushfstring(L, \"[?%s]\", ar->name);\n\t} else {\n\t\tlua_pushfstring(L, \"%s:%d\", ar->short_src, ar->linedefined > 0 ? ar->linedefined : 0);\n\t}\n\n\tlua_call(L, 2, 0);\n}\n\nstatic void call_ret_hook(lua_State *L) {\n\tlua_Debug ar;\n\t\n\tif (lua_gethook(L)) {\n\t\tlua_getstack(L, 0, &ar);\n\t\tlua_getinfo(L, \"n\", &ar);\n\t\t\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_rawget(L, LUA_REGISTRYINDEX);\n\t\t\n\t\tif (lua_type(L, -1) != LUA_TFUNCTION){\n\t\t\tlua_pop(L, 1);\n\t\t\treturn;\n        }\n\t\t\n\t\tlua_pushliteral(L, \"return\");\n\t\tlua_pushfstring(L, \"[?%s]\", ar.name);\n\t\tlua_pushliteral(L, \"[C#]\");\n\t\t\n\t\tlua_sethook(L, 0, 0, 0);\n\t\tlua_call(L, 3, 0);\n\t\tlua_sethook(L, hook, LUA_MASKCALL | LUA_MASKRET, 0);\n\t}\n}\n\nstatic int profiler_set_hook(lua_State *L) {\n\tif (lua_isnoneornil(L, 1)) {\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_pushnil(L);\n\t\tlua_rawset(L, LUA_REGISTRYINDEX);\n\t\t\t\n\t\tlua_sethook(L, 0, 0, 0);\n\t} else {\n\t\tluaL_checktype(L, 1, LUA_TFUNCTION);\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_pushvalue(L, 1);\n\t\tlua_rawset(L, LUA_REGISTRYINDEX);\n\t\tlua_sethook(L, hook, LUA_MASKCALL | LUA_MASKRET, 0);\n\t}\n\treturn 0;\n}\n\nstatic int csharp_function_wrap(lua_State *L) {\n\tlua_CFunction fn = (lua_CFunction)lua_tocfunction(L, lua_upvalueindex(1));\n    int ret = fn(L);    \n    \n    if (lua_toboolean(L, lua_upvalueindex(2)))\n    {\n        lua_pushboolean(L, 0);\n        lua_replace(L, lua_upvalueindex(2));\n        return lua_error(L);\n    }\n    \n\tif (lua_gethook(L)) {\n\t\tcall_ret_hook(L);\n\t}\n\t\n    return ret;\n}\n\nLUA_API void xlua_push_csharp_function(lua_State* L, lua_CFunction fn, int n)\n{ \n    lua_pushcfunction(L, fn);\n\tif (n > 0) {\n\t\tlua_insert(L, -1 - n);\n\t}\n\tlua_pushboolean(L, 0);\n\tif (n > 0) {\n\t\tlua_insert(L, -1 - n);\n\t}\n    lua_pushcclosure(L, csharp_function_wrap, 2 + (n > 0 ? n : 0));\n}\n\ntypedef int (*lua_CSWrapperCaller) (lua_State *L, int wrapperid, int top);\n\nstatic lua_CSWrapperCaller g_csharp_wrapper_caller = NULL;\n\nLUA_API void xlua_set_csharp_wrapper_caller(lua_CSWrapperCaller wrapper_caller)\n{\n\tg_csharp_wrapper_caller = wrapper_caller;\n}\n\nstatic int csharp_function_wrapper_wrapper(lua_State *L) {\n    int ret = 0;\n\t\n\tif (g_csharp_wrapper_caller == NULL) {\n\t\treturn luaL_error(L, \"g_csharp_wrapper_caller not set\");\n\t}\n\t\n\tret = g_csharp_wrapper_caller(L, xlua_tointeger(L, lua_upvalueindex(1)), lua_gettop(L));    \n    \n    if (lua_toboolean(L, lua_upvalueindex(2)))\n    {\n        lua_pushboolean(L, 0);\n        lua_replace(L, lua_upvalueindex(2));\n        return lua_error(L);\n    }\n    \n\tif (lua_gethook(L)) {\n\t\tcall_ret_hook(L);\n\t}\n\t\n    return ret;\n}\n\nLUA_API void xlua_push_csharp_wrapper(lua_State* L, int wrapperid)\n{ \n\tlua_pushinteger(L, wrapperid);\n\tlua_pushboolean(L, 0);\n    lua_pushcclosure(L, csharp_function_wrapper_wrapper, 2);\n}\n\nLUALIB_API int xlua_upvalueindex(int n) {\n\treturn lua_upvalueindex(2 + n);\n}\n\nLUALIB_API int xlua_csharp_str_error(lua_State* L, const char* msg)\n{\n    lua_pushboolean(L, 1);\n    lua_replace(L, lua_upvalueindex(2));\n    lua_pushstring(L, msg);\n    return 1;\n}\n\nLUALIB_API int xlua_csharp_error(lua_State* L)\n{\n    lua_pushboolean(L, 1);\n    lua_replace(L, lua_upvalueindex(2));\n    return 1;\n}\n\ntypedef struct {\n\tint fake_id;\n    unsigned int len;\n\tchar data[1];\n} CSharpStruct;\n\nLUA_API void *xlua_pushstruct(lua_State *L, unsigned int size, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_newuserdata(L, size + sizeof(int) + sizeof(unsigned int));\n\tcss->fake_id = -1;\n\tcss->len = size;\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n\treturn css;\n}\n\nLUA_API void xlua_pushcstable(lua_State *L, unsigned int size, int meta_ref) {\n\tlua_createtable(L, 0, size);\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n}\n\nLUA_API void *xlua_newstruct(lua_State *L, int size, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_newuserdata(L, size + sizeof(int) + sizeof(unsigned int));\n\tcss->fake_id = -1;\n\tcss->len = size;\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n\treturn css->data;\n}\n\nLUA_API void *xlua_tostruct(lua_State *L, int idx, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, idx);\n\tif (NULL != css) {\n\t\tif (lua_getmetatable (L, idx)) {\n\t\t\tlua_rawgeti(L, -1, 1);\n\t\t\tif (lua_type(L, -1) == LUA_TNUMBER && (int)lua_tointeger(L, -1) == meta_ref) {\n\t\t\t\tlua_pop(L, 2);\n\t\t\t\treturn css->data; \n\t\t\t}\n\t\t\tlua_pop(L, 2);\n\t\t}\n\t}\n\treturn NULL;\n}\n\nLUA_API int xlua_gettypeid(lua_State *L, int idx) {\n\tint type_id = -1;\n\tif (lua_type(L, idx) == LUA_TUSERDATA) {\n\t\tif (lua_getmetatable (L, idx)) {\n\t\t\tlua_rawgeti(L, -1, 1);\n\t\t\tif (lua_type(L, -1) == LUA_TNUMBER) {\n\t\t\t\ttype_id = (int)lua_tointeger(L, -1);\n\t\t\t}\n\t\t\tlua_pop(L, 2);\n\t\t}\n\t}\n\treturn type_id;\n}\n\n#define PACK_UNPACK_OF(type) \\\nLUALIB_API int xlua_pack_##type(void *p, int offset, type field) {\\\n\tCSharpStruct *css = (CSharpStruct *)p;\\\n\tif (css->fake_id != -1 || css->len < offset + sizeof(field)) {\\\n\t\treturn 0;\\\n\t} else {\\\n\t\tmemcpy((&(css->data[0]) + offset), &field, sizeof(field));\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\\\nLUALIB_API int xlua_unpack_##type(void *p, int offset, type *pfield) { \\\n\tCSharpStruct *css = (CSharpStruct *)p;\\\n\tif (css->fake_id != -1 || css->len < offset + sizeof(*pfield)) {\\\n\t\treturn 0;\\\n\t} else {\\\n\t\tmemcpy(pfield, (&(css->data[0]) + offset), sizeof(*pfield));\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\nPACK_UNPACK_OF(int8_t);\nPACK_UNPACK_OF(int16_t);\nPACK_UNPACK_OF(int32_t);\nPACK_UNPACK_OF(int64_t);\nPACK_UNPACK_OF(float);\nPACK_UNPACK_OF(double);\n\nLUALIB_API int xlua_pack_float2(void *p, int offset, float f1, float f2) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 2) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float2(void *p, int offset, float *f1, float *f2) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 2) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float3(void *p, int offset, float f1, float f2, float f3) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 3) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float3(void *p, int offset, float *f1, float *f2, float *f3) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 3) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float4(void *p, int offset, float f1, float f2, float f3, float f4) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float4(void *p, int offset, float *f1, float *f2, float *f3, float *f4) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float5(void *p, int offset, float f1, float f2, float f3, float f4, float f5) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 5) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\tpos[4] = f5;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float5(void *p, int offset, float *f1, float *f2, float *f3, float *f4, float *f5) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 5) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\t*f5 = pos[4];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float6(void *p, int offset, float f1, float f2, float f3, float f4, float f5, float f6) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 6) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\tpos[4] = f5;\n\t\tpos[5] = f6;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float6(void *p, int offset, float *f1, float *f2, float *f3, float *f4, float *f5, float *f6) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 6) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\t*f5 = pos[4];\n\t\t*f6 = pos[5];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_decimal(void *p, int offset, const int * decimal) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < sizeof(int) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tint *pos = (int *)(&(css->data[0]) + offset);\n\t\tpos[0] = decimal[0];\n\t\tpos[1] = decimal[1];\n\t\tpos[2] = decimal[2];\n\t\tpos[3] = decimal[3];\n\t\treturn 1;\n\t}\n}\n\ntypedef struct tagDEC {\n    uint16_t    wReserved;\n    uint8_t     scale;\n    uint8_t     sign;\n    int         Hi32;\n    uint64_t    Lo64;\n} DECIMAL;\n\nLUALIB_API int xlua_unpack_decimal(void *p, int offset, uint8_t *scale, uint8_t *sign, int *hi32, uint64_t *lo64) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < sizeof(int) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tDECIMAL *dec = (DECIMAL *)(&(css->data[0]) + offset);\n\t\t*scale = dec->scale;\n\t\t*sign = dec->sign;\n\t\t*hi32 = dec->Hi32;\n\t\t*lo64 = dec->Lo64;\n\t\treturn 1;\n\t}\n}\n\nLUA_API int xlua_is_eq_str(lua_State *L, int idx, const char* str, int str_len) {\n\tsize_t lmsg;\n    const char *msg;\n\tif (lua_type(L, idx) == LUA_TSTRING) {\n        msg = lua_tolstring(L, idx, &lmsg);\n\t\treturn (lmsg == str_len) && (memcmp(msg, str, lmsg) == 0);\n\t} else {\n\t\treturn 0;\n\t}\n}\n\n#define T_INT8   0\n#define T_UINT8  1\n#define T_INT16  2\n#define T_UINT16 3\n#define T_INT32  4\n#define T_UINT32 5\n#define T_INT64  6\n#define T_UINT64 7\n#define T_FLOAT  8\n#define T_DOUBLE 9\n\n#define DIRECT_ACCESS(type, push_func, to_func) \\\nint xlua_struct_get_##type(lua_State *L) {\\\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, 1);\\\n\tint offset = xlua_tointeger(L, lua_upvalueindex(1));\\\n\ttype val;\\\n\tif (css == NULL || css->fake_id != -1 || css->len < offset + sizeof(type)) {\\\n\t\treturn luaL_error(L, \"invalid c# struct!\");\\\n\t} else {\\\n\t\tmemcpy(&val, (&(css->data[0]) + offset), sizeof(type));\\\n\t\tpush_func(L, val);\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\\\nint xlua_struct_set_##type(lua_State *L) { \\\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, 1);\\\n\tint offset = xlua_tointeger(L, lua_upvalueindex(1));\\\n\ttype val;\\\n\tif (css == NULL || css->fake_id != -1 || css->len < offset + sizeof(type)) {\\\n\t\treturn luaL_error(L, \"invalid c# struct!\");\\\n\t} else {\\\n\t    val = (type)to_func(L, 2);\\\n\t\tmemcpy((&(css->data[0]) + offset), &val, sizeof(type));\\\n\t\treturn 0;\\\n\t}\\\n}\\\n\nDIRECT_ACCESS(int8_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint8_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(int16_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint16_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(int32_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint32_t, xlua_pushuint, xlua_touint);\nDIRECT_ACCESS(int64_t, lua_pushint64, lua_toint64);\nDIRECT_ACCESS(uint64_t, lua_pushuint64, lua_touint64);\nDIRECT_ACCESS(float, lua_pushnumber, lua_tonumber);\nDIRECT_ACCESS(double, lua_pushnumber, lua_tonumber);\n\nstatic const lua_CFunction direct_getters[10] = {\n\txlua_struct_get_int8_t,\n\txlua_struct_get_uint8_t,\n\txlua_struct_get_int16_t,\n\txlua_struct_get_uint16_t,\n\txlua_struct_get_int32_t,\n\txlua_struct_get_uint32_t,\n\txlua_struct_get_int64_t,\n\txlua_struct_get_uint64_t,\n\txlua_struct_get_float,\n\txlua_struct_get_double\n};\n\nstatic const lua_CFunction direct_setters[10] = {\n\txlua_struct_set_int8_t,\n\txlua_struct_set_uint8_t,\n\txlua_struct_set_int16_t,\n\txlua_struct_set_uint16_t,\n\txlua_struct_set_int32_t,\n\txlua_struct_set_uint32_t,\n\txlua_struct_set_int64_t,\n\txlua_struct_set_uint64_t,\n\txlua_struct_set_float,\n\txlua_struct_set_double\n};\n\nint nop(lua_State *L) {\n\treturn 0;\n}\n\nLUA_API int gen_css_access(lua_State *L) {\n\tint offset = xlua_tointeger(L, 1);\n\tint type = xlua_tointeger(L, 2);\n\tif (offset < 0) {\n\t\treturn luaL_error(L, \"offset must larger than 0\");\n\t}\n\tif (type < T_INT8 || type > T_DOUBLE) {\n\t\treturn luaL_error(L, \"unknow tag[%d]\", type);\n\t}\n\tlua_pushvalue(L, 1);\n\tlua_pushcclosure(L, direct_getters[type], 1);\n\tlua_pushvalue(L, 1);\n\tlua_pushcclosure(L, direct_setters[type], 1);\n\tlua_pushcclosure(L, nop, 0);\n\treturn 3;\n}\n\nstatic int is_cs_data(lua_State *L, int idx) {\n\tif (LUA_TUSERDATA == lua_type(L, idx) && lua_getmetatable(L, idx)) {\n\t\tlua_pushlightuserdata(L, &tag);\n\t\tlua_rawget(L,-2);\n\t\tif (!lua_isnil (L,-1)) {\n\t\t\tlua_pop (L, 2);\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop (L, 2);\n\t}\n\treturn 0;\n}\n\nLUA_API int css_clone(lua_State *L) {\n\tCSharpStruct *from = (CSharpStruct *)lua_touserdata(L, 1);\n\tCSharpStruct *to = NULL;\n\tif (!is_cs_data(L, 1) || from->fake_id != -1) {\n\t\treturn luaL_error(L, \"invalid c# struct!\");\n\t}\n\t\n\tto = (CSharpStruct *)lua_newuserdata(L, from->len + sizeof(int) + sizeof(unsigned int));\n\tto->fake_id = -1;\n\tto->len = from->len;\n\tmemcpy(&(to->data[0]), &(from->data[0]), from->len);\n    lua_getmetatable(L, 1);\n\tlua_setmetatable(L, -2);\n\treturn 1;\n}\n\nLUA_API void* xlua_gl(lua_State *L) {\n\treturn G(L);\n}\n\nstatic const luaL_Reg xlualib[] = {\n\t{\"sethook\", profiler_set_hook},\n\t{\"genaccessor\", gen_css_access},\n\t{\"structclone\", css_clone},\n\t{NULL, NULL}\n};\n\nLUA_API void luaopen_xlua(lua_State *L) {\n\tluaL_openlibs(L);\n\t\n#if LUA_VERSION_NUM == 503\n\tluaL_newlib(L, xlualib);\n\tlua_setglobal(L, \"xlua\");\n#else\n\tluaL_register(L, \"xlua\", xlualib);\n    lua_pop(L, 1);\n#endif\n}\n\n"
  },
  {
    "path": "build/CMakeLists.txt",
    "content": "# Tencent is pleased to support the open source community by making xLua available.\n# Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n# Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n# http://opensource.org/licenses/MIT\n# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\ncmake_minimum_required(VERSION 3.5)\n\nif ( WIN32 AND NOT CYGWIN AND NOT ( CMAKE_SYSTEM_NAME STREQUAL \"WindowsStore\" ) AND NOT ANDROID)\n\tset(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE} /MT\" CACHE STRING \"\")\n\tset(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG} /MTd\" CACHE STRING \"\")\n\tset(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} /MT\" CACHE STRING \"\")\n\tset(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} /MTd\" CACHE STRING \"\")\nendif ()\n\nproject(XLua)\n\nif ( IOS )\n        set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -fembed-bitcode\")\n        set(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} -fembed-bitcode\")\nendif ()\n\noption ( UINT_ESPECIALLY \"using custom ulong\" OFF )\noption ( USING_LUAJIT \"using luajit\" OFF )\noption ( GC64 \"using gc64\" OFF )\noption ( LUAC_COMPATIBLE_FORMAT \"compatible format\" OFF )\n\nfind_path(XLUA_PROJECT_DIR NAMES SConstruct\n    PATHS \n    ${CMAKE_SOURCE_DIR}\n    NO_DEFAULT_PATH\n    )\n\nMARK_AS_ADVANCED(XLUA_PROJECT_DIR)\n\nif (NOT LUA_VERSION)\n    set(LUA_VERSION \"5.3.5\")\nendif()\n\nset(LUA_SRC_PATH lua-${LUA_VERSION}/src)\nset(LUAJIT_SRC_PATH luajit-2.1.0b3/src)\n\nif (USING_LUAJIT)\n\t\n    if (APPLE AND NOT IOS AND NOT ANDROID)\n\t    include_directories(\n\t\t  ${CMAKE_SOURCE_DIR}\n\t\t  lua-5.1.5/src\n\t\t  lua-5.1.5/etc\n\t\t  ${CMAKE_CURRENT_BINARY_DIR}\n\t\t  ${THIRDPART_INC}\n\t    )\n\t    set ( LUA_CORE lua-5.1.5/src/lapi.c lua-5.1.5/src/lcode.c lua-5.1.5/src/ldebug.c lua-5.1.5/src/ldo.c lua-5.1.5/src/ldump.c lua-5.1.5/src/lfunc.c \n          lua-5.1.5/src/lgc.c lua-5.1.5/src/llex.c lua-5.1.5/src/lmem.c lua-5.1.5/src/lobject.c lua-5.1.5/src/lopcodes.c lua-5.1.5/src/lparser.c lua-5.1.5/src/lstate.c \n          lua-5.1.5/src/lstring.c lua-5.1.5/src/ltable.c lua-5.1.5/src/ltm.c lua-5.1.5/src/lundump.c lua-5.1.5/src/lvm.c lua-5.1.5/src/lzio.c lua-5.1.5/src/lauxlib.c \n          lua-5.1.5/src/lbaselib.c lua-5.1.5/src/ldblib.c lua-5.1.5/src/liolib.c lua-5.1.5/src/lmathlib.c lua-5.1.5/src/loslib.c lua-5.1.5/src/ltablib.c \n          lua-5.1.5/src/lstrlib.c lua-5.1.5/src/linit.c lua-5.1.5/src/loadlib.c)\n\telse ()\n\t    include_directories(\n\t\t  ${CMAKE_SOURCE_DIR}\n\t\t  ${LUAJIT_SRC_PATH}\n\t\t  ${CMAKE_CURRENT_BINARY_DIR}\n\t\t  ${THIRDPART_INC}\n\t    )\n\n\t    set ( LUA_CORE )\n\t    set_property( SOURCE xlua.c APPEND PROPERTY COMPILE_DEFINITIONS USING_LUAJIT )\n    endif ()\n\tset ( LUA_LIB )\nelse ()\n\tset ( LUA_IDSIZE 120 CACHE STRING \"gives the maximum size for the description of the source.\" )\n\n\tconfigure_file ( ${LUA_SRC_PATH}/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )\n\n\tinclude_directories(\n\t    ${CMAKE_SOURCE_DIR}\n\t\t${LUA_SRC_PATH}\n\t\t${CMAKE_CURRENT_BINARY_DIR}\n\t\t${THIRDPART_INC}\n\t)\n\n    aux_source_directory(${LUA_SRC_PATH} LUA_CORE)\n    list(REMOVE_ITEM LUA_CORE ${LUA_SRC_PATH}/lua.c ${LUA_SRC_PATH}/luac.c)\n\tset ( LUA_LIB )\n\n\t# set ( LUA_CORE ${LUA_SRC_PATH}/lapi.c ${LUA_SRC_PATH}/lcode.c ${LUA_SRC_PATH}/lctype.c ${LUA_SRC_PATH}/ldebug.c ${LUA_SRC_PATH}/ldo.c ${LUA_SRC_PATH}/ldump.c\n\t#   ${LUA_SRC_PATH}/lfunc.c ${LUA_SRC_PATH}/lgc.c ${LUA_SRC_PATH}/llex.c ${LUA_SRC_PATH}/lmem.c ${LUA_SRC_PATH}/lobject.c ${LUA_SRC_PATH}/lopcodes.c ${LUA_SRC_PATH}/lparser.c\n\t#   ${LUA_SRC_PATH}/lstate.c ${LUA_SRC_PATH}/lstring.c ${LUA_SRC_PATH}/ltable.c ${LUA_SRC_PATH}/ltm.c ${LUA_SRC_PATH}/lundump.c ${LUA_SRC_PATH}/lvm.c ${LUA_SRC_PATH}/lzio.c )\n\t# set ( LUA_LIB ${LUA_SRC_PATH}/lauxlib.c ${LUA_SRC_PATH}/lbaselib.c ${LUA_SRC_PATH}/lbitlib.c ${LUA_SRC_PATH}/lcorolib.c ${LUA_SRC_PATH}/ldblib.c\n\t#   ${LUA_SRC_PATH}/liolib.c ${LUA_SRC_PATH}/lmathlib.c ${LUA_SRC_PATH}/loslib.c ${LUA_SRC_PATH}/lstrlib.c ${LUA_SRC_PATH}/ltablib.c ${LUA_SRC_PATH}/linit.c\n\t#   ${LUA_SRC_PATH}/lutf8lib.c ${LUA_SRC_PATH}/loadlib.c )\nendif ()\n\nset ( LUA_SOCKET\n    luasocket/auxiliar.c\n    luasocket/buffer.c\n    luasocket/except.c\n    luasocket/inet.c\n    luasocket/io.c\n    luasocket/luasocket.c\n    luasocket/mime.c\n    luasocket/options.c\n    luasocket/select.c\n    luasocket/tcp.c\n    luasocket/timeout.c\n    luasocket/udp.c \n)\n\nif ( WIN32 AND NOT CYGWIN )\n    list (APPEND LUA_SOCKET luasocket/wsocket.c)\nelse ( )\n    list (APPEND LUA_SOCKET luasocket/usocket.c)\nendif ( )\n\nset ( XLUA_CORE\n    i64lib.c\n    xlua.c\n)\n\nif (NOT USING_LUAJIT)\n    list (APPEND XLUA_CORE memory_leak_checker.c)\nendif ( )\n\nmacro(source_group_by_dir proj_dir source_files)\n    if(MSVC OR APPLE)\n        get_filename_component(sgbd_cur_dir ${proj_dir} ABSOLUTE)\n        foreach(sgbd_file ${${source_files}})\n\t\t\tget_filename_component(sgbd_abs_file ${sgbd_file} ABSOLUTE)\n            file(RELATIVE_PATH sgbd_fpath ${sgbd_cur_dir} ${sgbd_abs_file})\n            string(REGEX REPLACE \"\\(.*\\)/.*\" \\\\1 sgbd_group_name ${sgbd_fpath})\n            string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)\n            string(REPLACE \"/\" \"\\\\\" sgbd_group_name ${sgbd_group_name})\n            if(sgbd_nogroup)\n                set(sgbd_group_name \"\\\\\")\n            endif(sgbd_nogroup)\n            source_group(${sgbd_group_name} FILES ${sgbd_file})\n        endforeach(sgbd_file)\n    endif(MSVC OR APPLE)\nendmacro(source_group_by_dir)\n\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUA_SOCKET)\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUA_CORE)\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUA_LIB)\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} XLUA_CORE)\n\nif (APPLE)\n    if (IOS)\n        ADD_DEFINITIONS(-DLUA_USE_IOS) # Despite claiming to be ISO C, iOS does not implement 'system'.(iOS11)\n        set(CMAKE_OSX_ARCHITECTURES \"$(ARCHS_STANDARD)\")\n        add_library(xlua STATIC\n           ${LUA_CORE}\n           ${LUA_LIB}\n           ${LUA_SOCKET}\n           ${XLUA_CORE}\n           ${THIRDPART_SRC}\n        )\n\t\tset_xcode_property (xlua IPHONEOS_DEPLOYMENT_TARGET \"7.0\" \"all\")\n    else ()\n        ADD_DEFINITIONS(-DLUA_USE_MACOSX) #osx platform emmylua debugger must have this option or can not load cpath\n        if (BUILD_SILICON)\n           set(CMAKE_OSX_ARCHITECTURES arm64)\n\n            add_library(xlua SHARED\n                ${LUA_CORE}\n                ${LUA_LIB}\n                ${LUA_SOCKET}\n                ${XLUA_CORE}\n                ${THIRDPART_SRC}\n            )\n        else ()\n            set(CMAKE_OSX_ARCHITECTURES \"$(ARCHS_STANDARD_64_BIT)\")\n            add_library(xlua MODULE\n                ${LUA_CORE}\n                ${LUA_LIB}\n                ${LUA_SOCKET}\n                ${XLUA_CORE}\n                ${THIRDPART_SRC}\n            )\n            set_target_properties ( xlua PROPERTIES BUNDLE TRUE )\n            #set_target_properties ( xlua PROPERTIES FRAMEWORK TRUE )\n            #set_target_properties ( xlua PROPERTIES MACOSX_RPATH TRUE )\n        endif ()\n    endif ()\nelseif (\"${CMAKE_SYSTEM_NAME}\" STREQUAL \"Switch\")\n    add_library(xlua STATIC\n        ${LUA_CORE}\n        ${LUA_LIB}\n        ${XLUA_CORE}\n        ${THIRDPART_SRC}\n    )\n    target_compile_options(xlua PRIVATE -m64 -mcpu=cortex-a57+fp+simd+crypto+crc -fno-common -fno-short-enums -ffunction-sections -fdata-sections -fPIC -fms-extensions)\nelse ( )\n    add_library(xlua SHARED\n        ${LUA_CORE}\n        ${LUA_LIB}\n        ${LUA_SOCKET}\n        ${XLUA_CORE}\n        ${THIRDPART_SRC}\n    )\nendif ( )\n\nif ( WIN32 AND NOT CYGWIN )\n    target_compile_definitions (xlua PRIVATE LUA_BUILD_AS_DLL)\nendif ( )\n\nif (GC64 AND USING_LUAJIT)\n    target_compile_definitions (xlua PRIVATE LUAJIT_ENABLE_GC64)\nendif ()\n\nif (LUAC_COMPATIBLE_FORMAT AND NOT USING_LUAJIT)\n    target_compile_definitions (xlua PRIVATE LUAC_COMPATIBLE_FORMAT)\nendif ()\n\nset_property(\n\tSOURCE ${LUA_SOCKET}\n\tAPPEND\n\tPROPERTY COMPILE_DEFINITIONS\n\tLUA_COMPAT_APIINTCASTS LUA_LIB _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS\n)\n\nif(UINT_ESPECIALLY)\n    ADD_DEFINITIONS(-DUINT_ESPECIALLY)\nendif()\n\t\nif ( WIN32 AND NOT CYGWIN )\n    if (USING_LUAJIT)\n        target_link_libraries(xlua\n            ${CMAKE_SOURCE_DIR}/${LUAJIT_SRC_PATH}/lua51.lib\n            ws2_32\n            ${THIRDPART_LIB} \n        )\n    else ()\n        target_link_libraries(xlua\n            ws2_32\n            ${THIRDPART_LIB} \n        )\n    endif()\nelse ( )\n    if (USING_LUAJIT AND NOT APPLE)\n\t\ttarget_link_libraries(xlua\n\t\t\t${CMAKE_SOURCE_DIR}/${LUAJIT_SRC_PATH}/libluajit.a\n\t\t\tm\n            ${THIRDPART_LIB} \n\t\t)\n    else ()\n        target_link_libraries(xlua\n            m\n            ${THIRDPART_LIB} \n        )\n    endif()\nendif ( )\n\nif ( ANDROID )\n    target_link_options(xlua PRIVATE -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384) # android 16K Pagesize\nendif ( )"
  },
  {
    "path": "build/cmake/android.toolchain.cmake",
    "content": "# Copyright (c) 2010-2011, Ethan Rublee\n# Copyright (c) 2011-2014, Andrey Kamaev\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are met:\n#\n# 1.  Redistributions of source code must retain the above copyright notice,\n#     this list of conditions and the following disclaimer.\n#\n# 2.  Redistributions in binary form must reproduce the above copyright notice,\n#     this list of conditions and the following disclaimer in the documentation\n#     and/or other materials provided with the distribution.\n#\n# 3.  Neither the name of the copyright holder nor the names of its\n#     contributors may be used to endorse or promote products derived from this\n#     software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n# POSSIBILITY OF SUCH DAMAGE.\n\n# ------------------------------------------------------------------------------\n#  Android CMake toolchain file, for use with the Android NDK r5-r10d\n#  Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended).\n#  See home page: https://github.com/taka-no-me/android-cmake\n#\n#  Usage Linux:\n#   $ export ANDROID_NDK=/absolute/path/to/the/android-ndk\n#   $ mkdir build && cd build\n#   $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..\n#   $ make -j8\n#\n#  Usage Windows:\n#     You need native port of make to build your project.\n#     Android NDK r7 (and newer) already has make.exe on board.\n#     For older NDK you have to install it separately.\n#     For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm\n#\n#   $ SET ANDROID_NDK=C:\\absolute\\path\\to\\the\\android-ndk\n#   $ mkdir build && cd build\n#   $ cmake.exe -G\"MinGW Makefiles\"\n#       -DCMAKE_TOOLCHAIN_FILE=path\\to\\the\\android.toolchain.cmake\n#       -DCMAKE_MAKE_PROGRAM=\"%ANDROID_NDK%\\prebuilt\\windows\\bin\\make.exe\" ..\n#   $ cmake.exe --build .\n#\n#\n#  Options (can be set as cmake parameters: -D<option_name>=<value>):\n#    ANDROID_NDK=/opt/android-ndk - path to the NDK root.\n#      Can be set as environment variable. Can be set only at first cmake run.\n#\n#    ANDROID_ABI=armeabi-v7a - specifies the target Application Binary\n#      Interface (ABI). This option nearly matches to the APP_ABI variable\n#      used by ndk-build tool from Android NDK.\n#\n#      Possible targets are:\n#        \"armeabi\" - ARMv5TE based CPU with software floating point operations\n#        \"armeabi-v7a\" - ARMv7 based devices with hardware FPU instructions\n#            this ABI target is used by default\n#        \"armeabi-v7a with NEON\" - same as armeabi-v7a, but\n#            sets NEON as floating-point unit\n#        \"armeabi-v7a with VFPV3\" - same as armeabi-v7a, but\n#            sets VFPV3 as floating-point unit (has 32 registers instead of 16)\n#        \"armeabi-v6 with VFP\" - tuned for ARMv6 processors having VFP\n#        \"x86\" - IA-32 instruction set\n#        \"mips\" - MIPS32 instruction set\n#\n#      64-bit ABIs for NDK r10 and newer:\n#        \"arm64-v8a\" - ARMv8 AArch64 instruction set\n#        \"x86_64\" - Intel64 instruction set (r1)\n#        \"mips64\" - MIPS64 instruction set (r6)\n#\n#    ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.\n#      Option is read-only when standalone toolchain is used.\n#      Note: building for \"android-L\" requires explicit configuration.\n#\n#    ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler\n#      toolchain to be used. The list of possible values depends on the NDK\n#      version. For NDK r10c the possible values are:\n#\n#        * aarch64-linux-android-4.9\n#        * aarch64-linux-android-clang3.4\n#        * aarch64-linux-android-clang3.5\n#        * arm-linux-androideabi-4.6\n#        * arm-linux-androideabi-4.8\n#        * arm-linux-androideabi-4.9 (default)\n#        * arm-linux-androideabi-clang3.4\n#        * arm-linux-androideabi-clang3.5\n#        * mips64el-linux-android-4.9\n#        * mips64el-linux-android-clang3.4\n#        * mips64el-linux-android-clang3.5\n#        * mipsel-linux-android-4.6\n#        * mipsel-linux-android-4.8\n#        * mipsel-linux-android-4.9\n#        * mipsel-linux-android-clang3.4\n#        * mipsel-linux-android-clang3.5\n#        * x86-4.6\n#        * x86-4.8\n#        * x86-4.9\n#        * x86-clang3.4\n#        * x86-clang3.5\n#        * x86_64-4.9\n#        * x86_64-clang3.4\n#        * x86_64-clang3.5\n#\n#    ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions\n#      instead of Thumb. Is not available for \"armeabi-v6 with VFP\"\n#      (is forced to be ON) ABI.\n#\n#    ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker\n#      errors even if they are not used.\n#\n#    ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared\n#      libraries. Automatically turned for NDK r5x and r6x due to GLESv2\n#      problems.\n#\n#    ANDROID_STL=gnustl_static - specify the runtime to use.\n#\n#      Possible values are:\n#        none           -> Do not configure the runtime.\n#        system         -> Use the default minimal system C++ runtime library.\n#                          Implies -fno-rtti -fno-exceptions.\n#                          Is not available for standalone toolchain.\n#        system_re      -> Use the default minimal system C++ runtime library.\n#                          Implies -frtti -fexceptions.\n#                          Is not available for standalone toolchain.\n#        gabi++_static  -> Use the GAbi++ runtime as a static library.\n#                          Implies -frtti -fno-exceptions.\n#                          Available for NDK r7 and newer.\n#                          Is not available for standalone toolchain.\n#        gabi++_shared  -> Use the GAbi++ runtime as a shared library.\n#                          Implies -frtti -fno-exceptions.\n#                          Available for NDK r7 and newer.\n#                          Is not available for standalone toolchain.\n#        stlport_static -> Use the STLport runtime as a static library.\n#                          Implies -fno-rtti -fno-exceptions for NDK before r7.\n#                          Implies -frtti -fno-exceptions for NDK r7 and newer.\n#                          Is not available for standalone toolchain.\n#        stlport_shared -> Use the STLport runtime as a shared library.\n#                          Implies -fno-rtti -fno-exceptions for NDK before r7.\n#                          Implies -frtti -fno-exceptions for NDK r7 and newer.\n#                          Is not available for standalone toolchain.\n#        gnustl_static  -> Use the GNU STL as a static library.\n#                          Implies -frtti -fexceptions.\n#        gnustl_shared  -> Use the GNU STL as a shared library.\n#                          Implies -frtti -fno-exceptions.\n#                          Available for NDK r7b and newer.\n#                          Silently degrades to gnustl_static if not available.\n#\n#    ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on\n#      chosen runtime. If disabled, then the user is responsible for settings\n#      these options.\n#\n#  What?:\n#    android-cmake toolchain searches for NDK/toolchain in the following order:\n#      ANDROID_NDK - cmake parameter\n#      ANDROID_NDK - environment variable\n#      ANDROID_STANDALONE_TOOLCHAIN - cmake parameter\n#      ANDROID_STANDALONE_TOOLCHAIN - environment variable\n#      ANDROID_NDK - default locations\n#      ANDROID_STANDALONE_TOOLCHAIN - default locations\n#\n#    Make sure to do the following in your scripts:\n#      SET( CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} ${my_cxx_flags}\" )\n#      SET( CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} ${my_cxx_flags}\" )\n#    The flags will be prepopulated with critical flags, so don't loose them.\n#    Also be aware that toolchain also sets configuration-specific compiler\n#    flags and linker flags.\n#\n#    ANDROID and BUILD_ANDROID will be set to true, you may test any of these\n#    variables to make necessary Android-specific configuration changes.\n#\n#    Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64\n#    will be set true, mutually exclusive. NEON option will be set true\n#    if VFP is set to NEON.\n#\n# ------------------------------------------------------------------------------\n\ncmake_minimum_required( VERSION 2.6.3 )\n\nif( DEFINED CMAKE_CROSSCOMPILING )\n # subsequent toolchain loading is not really needed\n return()\nendif()\n\nif( CMAKE_TOOLCHAIN_FILE )\n # touch toolchain variable to suppress \"unused variable\" warning\nendif()\n\n# inherit settings in recursive loads\nget_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )\nif( _CMAKE_IN_TRY_COMPILE )\n include( \"${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake\" OPTIONAL )\nendif()\n\n# this one is important\nif( CMAKE_VERSION VERSION_GREATER \"3.0.99\" )\n set( CMAKE_SYSTEM_NAME Android )\nelse()\n set( CMAKE_SYSTEM_NAME Linux )\nendif()\n\n# this one not so much\nset( CMAKE_SYSTEM_VERSION 1 )\n\n# rpath makes low sense for Android\nset( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG \"\" )\nset( CMAKE_SKIP_RPATH TRUE CACHE BOOL \"If set, runtime paths are not added when using shared libraries.\" )\n\n# NDK search paths\nset( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 \"\" )\nif( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )\n if( CMAKE_HOST_WIN32 )\n  file( TO_CMAKE_PATH \"$ENV{PROGRAMFILES}\" ANDROID_NDK_SEARCH_PATHS )\n  set( ANDROID_NDK_SEARCH_PATHS \"${ANDROID_NDK_SEARCH_PATHS}\" \"$ENV{SystemDrive}/NVPACK\" )\n else()\n  file( TO_CMAKE_PATH \"$ENV{HOME}\" ANDROID_NDK_SEARCH_PATHS )\n  set( ANDROID_NDK_SEARCH_PATHS /opt \"${ANDROID_NDK_SEARCH_PATHS}/NVPACK\" )\n endif()\nendif()\nif( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )\n set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )\nendif()\n\n# known ABIs\nset( ANDROID_SUPPORTED_ABIS_arm \"armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP\" )\nset( ANDROID_SUPPORTED_ABIS_arm64 \"arm64-v8a\" )\nset( ANDROID_SUPPORTED_ABIS_x86 \"x86\" )\nset( ANDROID_SUPPORTED_ABIS_x86_64 \"x86_64\" )\nset( ANDROID_SUPPORTED_ABIS_mips \"mips\" )\nset( ANDROID_SUPPORTED_ABIS_mips64 \"mips64\" )\n\n# API level defaults\nset( ANDROID_DEFAULT_NDK_API_LEVEL 8 )\nset( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 )\nset( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )\nset( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 )\nset( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )\nset( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 )\n\n\nmacro( __LIST_FILTER listvar regex )\n  if( ${listvar} )\n    foreach( __val ${${listvar}} )\n      if( __val MATCHES \"${regex}\" )\n        list( REMOVE_ITEM ${listvar} \"${__val}\" )\n      endif()\n    endforeach()\n  endif()\nendmacro()\n\nmacro( __INIT_VARIABLE var_name )\n  set( __test_path 0 )\n  foreach( __var ${ARGN} )\n    if( __var STREQUAL \"PATH\" )\n      set( __test_path 1 )\n      break()\n    endif()\n  endforeach()\n\n  if( __test_path AND NOT EXISTS \"${${var_name}}\" )\n    unset( ${var_name} CACHE )\n  endif()\n\n  if( \" ${${var_name}}\" STREQUAL \" \" )\n    set( __values 0 )\n    foreach( __var ${ARGN} )\n      if( __var STREQUAL \"VALUES\" )\n        set( __values 1 )\n      elseif( NOT __var STREQUAL \"PATH\" )\n        if( __var MATCHES \"^ENV_.*$\" )\n          string( REPLACE \"ENV_\" \"\" __var \"${__var}\" )\n          set( __value \"$ENV{${__var}}\" )\n        elseif( DEFINED ${__var} )\n          set( __value \"${${__var}}\" )\n        elseif( __values )\n          set( __value \"${__var}\" )\n        else()\n          set( __value \"\" )\n        endif()\n\n        if( NOT \" ${__value}\" STREQUAL \" \" AND (NOT __test_path OR EXISTS \"${__value}\") )\n          set( ${var_name} \"${__value}\" )\n          break()\n        endif()\n      endif()\n    endforeach()\n    unset( __value )\n    unset( __values )\n  endif()\n\n  if( __test_path )\n    file( TO_CMAKE_PATH \"${${var_name}}\" ${var_name} )\n  endif()\n  unset( __test_path )\nendmacro()\n\nmacro( __DETECT_NATIVE_API_LEVEL _var _path )\n  set( __ndkApiLevelRegex \"^[\\t ]*#define[\\t ]+__ANDROID_API__[\\t ]+([0-9]+)[\\t ]*.*$\" )\n  file( STRINGS ${_path} __apiFileContent REGEX \"${__ndkApiLevelRegex}\" )\n  if( NOT __apiFileContent )\n    message( SEND_ERROR \"Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken.\" )\n  endif()\n  string( REGEX REPLACE \"${__ndkApiLevelRegex}\" \"\\\\1\" ${_var} \"${__apiFileContent}\" )\n  unset( __apiFileContent )\n  unset( __ndkApiLevelRegex )\nendmacro()\n\nmacro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )\n if( EXISTS \"${_root}\" )\n    file( GLOB __gccExePath RELATIVE \"${_root}/bin/\" \"${_root}/bin/*-gcc${TOOL_OS_SUFFIX}\" )\n    __LIST_FILTER( __gccExePath \"^[.].*\" )\n    list( LENGTH __gccExePath __gccExePathsCount )\n    if( NOT __gccExePathsCount EQUAL 1  AND NOT _CMAKE_IN_TRY_COMPILE )\n      message( WARNING \"Could not determine machine name for compiler from ${_root}\" )\n      set( ${_var} \"\" )\n    else()\n      get_filename_component( __gccExeName \"${__gccExePath}\" NAME_WE )\n      string( REPLACE \"-gcc\" \"\" ${_var} \"${__gccExeName}\" )\n    endif()\n    unset( __gccExePath )\n    unset( __gccExePathsCount )\n    unset( __gccExeName )\n  else()\n    set( ${_var} \"\" )\n  endif()\nendmacro()\n\n\n# fight against cygwin\nset( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL \"Prevent cmake from working under cygwin and using cygwin tools\")\nmark_as_advanced( ANDROID_FORBID_SYGWIN )\nif( ANDROID_FORBID_SYGWIN )\n if( CYGWIN )\n  message( FATAL_ERROR \"Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake.\" )\n endif()\n\n if( CMAKE_HOST_WIN32 )\n  # remove cygwin from PATH\n  set( __new_path \"$ENV{PATH}\")\n  __LIST_FILTER( __new_path \"cygwin\" )\n  set(ENV{PATH} \"${__new_path}\")\n  unset(__new_path)\n endif()\nendif()\n\n\n# detect current host platform\nif( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES \"amd64|x86_64|AMD64\" OR CMAKE_HOST_APPLE) )\n set( ANDROID_NDK_HOST_X64 1 CACHE BOOL \"Try to use 64-bit compiler toolchain\" )\n mark_as_advanced( ANDROID_NDK_HOST_X64 )\nendif()\n\nset( TOOL_OS_SUFFIX \"\" )\nif( CMAKE_HOST_APPLE )\n set( ANDROID_NDK_HOST_SYSTEM_NAME \"darwin-x86_64\" )\n set( ANDROID_NDK_HOST_SYSTEM_NAME2 \"darwin-x86\" )\nelseif( CMAKE_HOST_WIN32 )\n set( ANDROID_NDK_HOST_SYSTEM_NAME \"windows-x86_64\" )\n set( ANDROID_NDK_HOST_SYSTEM_NAME2 \"windows\" )\n set( TOOL_OS_SUFFIX \".exe\" )\nelseif( CMAKE_HOST_UNIX )\n set( ANDROID_NDK_HOST_SYSTEM_NAME \"linux-x86_64\" )\n set( ANDROID_NDK_HOST_SYSTEM_NAME2 \"linux-x86\" )\nelse()\n message( FATAL_ERROR \"Cross-compilation on your platform is not supported by this cmake toolchain\" )\nendif()\n\nif( NOT ANDROID_NDK_HOST_X64 )\n set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} )\nendif()\n\n# see if we have path to Android NDK\nif( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN )\n  __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )\nendif()\nif( NOT ANDROID_NDK )\n # see if we have path to Android standalone toolchain\n __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN )\n\n if( NOT ANDROID_STANDALONE_TOOLCHAIN )\n  #try to find Android NDK in one of the the default locations\n  set( __ndkSearchPaths )\n  foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} )\n   foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} )\n    list( APPEND __ndkSearchPaths \"${__ndkSearchPath}/android-ndk${suffix}\" )\n   endforeach()\n  endforeach()\n  __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} )\n  unset( __ndkSearchPaths )\n\n  if( ANDROID_NDK )\n   message( STATUS \"Using default path for Android NDK: ${ANDROID_NDK}\" )\n   message( STATUS \"  If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK\" )\n  else()\n   #try to find Android standalone toolchain in one of the the default locations\n   __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )\n\n   if( ANDROID_STANDALONE_TOOLCHAIN )\n    message( STATUS \"Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}\" )\n    message( STATUS \"  If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN\" )\n   endif( ANDROID_STANDALONE_TOOLCHAIN )\n  endif( ANDROID_NDK )\n endif( NOT ANDROID_STANDALONE_TOOLCHAIN )\nendif( NOT ANDROID_NDK )\n\n# remember found paths\nif( ANDROID_NDK )\n get_filename_component( ANDROID_NDK \"${ANDROID_NDK}\" ABSOLUTE )\n set( ANDROID_NDK \"${ANDROID_NDK}\" CACHE INTERNAL \"Path of the Android NDK\" FORCE )\n set( BUILD_WITH_ANDROID_NDK True )\n if( EXISTS \"${ANDROID_NDK}/RELEASE.TXT\" )\n  file( STRINGS \"${ANDROID_NDK}/RELEASE.TXT\" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX \"r[0-9]+[a-z]?\" )\n  string( REGEX MATCH \"r([0-9]+)([a-z]?)\" ANDROID_NDK_RELEASE \"${ANDROID_NDK_RELEASE_FULL}\" )\n else()\n  set( ANDROID_NDK_RELEASE \"r1x\" )\n  set( ANDROID_NDK_RELEASE_FULL \"unreleased\" )\n endif()\n string( REGEX REPLACE \"r([0-9]+)([a-z]?)\" \"\\\\1*1000\" ANDROID_NDK_RELEASE_NUM \"${ANDROID_NDK_RELEASE}\" )\n string( FIND \" abcdefghijklmnopqastuvwxyz\" \"${CMAKE_MATCH_2}\" __ndkReleaseLetterNum )\n math( EXPR ANDROID_NDK_RELEASE_NUM \"${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}\" )\nelseif( ANDROID_STANDALONE_TOOLCHAIN )\n get_filename_component( ANDROID_STANDALONE_TOOLCHAIN \"${ANDROID_STANDALONE_TOOLCHAIN}\" ABSOLUTE )\n # try to detect change\n if( CMAKE_AR )\n  string( LENGTH \"${ANDROID_STANDALONE_TOOLCHAIN}\" __length )\n  string( SUBSTRING \"${CMAKE_AR}\" 0 ${__length} __androidStandaloneToolchainPreviousPath )\n  if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )\n   message( FATAL_ERROR \"It is not possible to change path to the Android standalone toolchain on subsequent run.\" )\n  endif()\n  unset( __androidStandaloneToolchainPreviousPath )\n  unset( __length )\n endif()\n set( ANDROID_STANDALONE_TOOLCHAIN \"${ANDROID_STANDALONE_TOOLCHAIN}\" CACHE INTERNAL \"Path of the Android standalone toolchain\" FORCE )\n set( BUILD_WITH_STANDALONE_TOOLCHAIN True )\nelse()\n list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH)\n message( FATAL_ERROR \"Could not find neither Android NDK nor Android standalone toolchain.\n    You should either set an environment variable:\n      export ANDROID_NDK=~/my-android-ndk\n    or\n      export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain\n    or put the toolchain or NDK in the default path:\n      sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk\n      sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}\" )\nendif()\n\n# android NDK layout\nif( BUILD_WITH_ANDROID_NDK )\n if( NOT DEFINED ANDROID_NDK_LAYOUT )\n  # try to automatically detect the layout\n  if( EXISTS \"${ANDROID_NDK}/RELEASE.TXT\")\n   set( ANDROID_NDK_LAYOUT \"RELEASE\" )\n  elseif( EXISTS \"${ANDROID_NDK}/../../linux-x86/toolchain/\" )\n   set( ANDROID_NDK_LAYOUT \"LINARO\" )\n  elseif( EXISTS \"${ANDROID_NDK}/../../gcc/\" )\n   set( ANDROID_NDK_LAYOUT \"ANDROID\" )\n  endif()\n endif()\n set( ANDROID_NDK_LAYOUT \"${ANDROID_NDK_LAYOUT}\" CACHE STRING \"The inner layout of NDK\" )\n mark_as_advanced( ANDROID_NDK_LAYOUT )\n if( ANDROID_NDK_LAYOUT STREQUAL \"LINARO\" )\n  set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment\n  set( ANDROID_NDK_TOOLCHAINS_PATH \"${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH  \"\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 \"\" )\n elseif( ANDROID_NDK_LAYOUT STREQUAL \"ANDROID\" )\n  set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment\n  set( ANDROID_NDK_TOOLCHAINS_PATH \"${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH  \"\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 \"\" )\n else() # ANDROID_NDK_LAYOUT STREQUAL \"RELEASE\"\n  set( ANDROID_NDK_TOOLCHAINS_PATH \"${ANDROID_NDK}/toolchains\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH  \"/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}\" )\n  set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 \"/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}\" )\n endif()\n get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH \"${ANDROID_NDK_TOOLCHAINS_PATH}\" ABSOLUTE )\n\n # try to detect change of NDK\n if( CMAKE_AR )\n  string( LENGTH \"${ANDROID_NDK_TOOLCHAINS_PATH}\" __length )\n  string( SUBSTRING \"${CMAKE_AR}\" 0 ${__length} __androidNdkPreviousPath )\n  if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH )\n   message( FATAL_ERROR \"It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first.\n   \" )\n  endif()\n  unset( __androidNdkPreviousPath )\n  unset( __length )\n endif()\nendif()\n\n\n# get all the details about standalone toolchain\nif( BUILD_WITH_STANDALONE_TOOLCHAIN )\n __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS \"${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h\" )\n set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )\n set( __availableToolchains \"standalone\" )\n __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines \"${ANDROID_STANDALONE_TOOLCHAIN}\" )\n if( NOT __availableToolchainMachines )\n  message( FATAL_ERROR \"Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken.\" )\n endif()\n if( __availableToolchainMachines MATCHES x86_64 )\n  set( __availableToolchainArchs \"x86_64\" )\n elseif( __availableToolchainMachines MATCHES i686 )\n  set( __availableToolchainArchs \"x86\" )\n elseif( __availableToolchainMachines MATCHES aarch64 )\n  set( __availableToolchainArchs \"arm64\" )\n elseif( __availableToolchainMachines MATCHES arm )\n  set( __availableToolchainArchs \"arm\" )\n elseif( __availableToolchainMachines MATCHES mips64el )\n  set( __availableToolchainArchs \"mips64\" )\n elseif( __availableToolchainMachines MATCHES mipsel )\n  set( __availableToolchainArchs \"mips\" )\n endif()\n execute_process( COMMAND \"${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}\" -dumpversion\n                  OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE )\n string( REGEX MATCH \"[0-9]+[.][0-9]+([.][0-9]+)?\" __availableToolchainCompilerVersions \"${__availableToolchainCompilerVersions}\" )\n if( EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}\" )\n  list( APPEND __availableToolchains \"standalone-clang\" )\n  list( APPEND __availableToolchainMachines ${__availableToolchainMachines} )\n  list( APPEND __availableToolchainArchs ${__availableToolchainArchs} )\n  list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} )\n endif()\nendif()\n\nmacro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath )\n foreach( __toolchain ${${__availableToolchainsLst}} )\n  if( \"${__toolchain}\" MATCHES \"-clang3[.][0-9]$\" AND NOT EXISTS \"${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}\" )\n   SET( __toolchainVersionRegex \"^TOOLCHAIN_VERSION[\\t ]+:=[\\t ]+(.*)$\" )\n   FILE( STRINGS \"${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk\" __toolchainVersionStr REGEX \"${__toolchainVersionRegex}\" )\n   if( __toolchainVersionStr )\n    string( REGEX REPLACE \"${__toolchainVersionRegex}\" \"\\\\1\" __toolchainVersionStr \"${__toolchainVersionStr}\" )\n    string( REGEX REPLACE \"-clang3[.][0-9]$\" \"-${__toolchainVersionStr}\" __gcc_toolchain \"${__toolchain}\" )\n   else()\n    string( REGEX REPLACE \"-clang3[.][0-9]$\" \"-4.6\" __gcc_toolchain \"${__toolchain}\" )\n   endif()\n   unset( __toolchainVersionStr )\n   unset( __toolchainVersionRegex )\n  else()\n   set( __gcc_toolchain \"${__toolchain}\" )\n  endif()\n  __DETECT_TOOLCHAIN_MACHINE_NAME( __machine \"${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}\" )\n  if( __machine )\n   string( REGEX MATCH \"[0-9]+[.][0-9]+([.][0-9x]+)?$\" __version \"${__gcc_toolchain}\" )\n   if( __machine MATCHES x86_64 )\n    set( __arch \"x86_64\" )\n   elseif( __machine MATCHES i686 )\n    set( __arch \"x86\" )\n   elseif( __machine MATCHES aarch64 )\n    set( __arch \"arm64\" )\n   elseif( __machine MATCHES arm )\n    set( __arch \"arm\" )\n   elseif( __machine MATCHES mips64el )\n    set( __arch \"mips64\" )\n   elseif( __machine MATCHES mipsel )\n    set( __arch \"mips\" )\n   else()\n    set( __arch \"\" )\n   endif()\n   #message(\"machine: !${__machine}!\\narch: !${__arch}!\\nversion: !${__version}!\\ntoolchain: !${__toolchain}!\\n\")\n   if (__arch)\n    list( APPEND __availableToolchainMachines \"${__machine}\" )\n    list( APPEND __availableToolchainArchs \"${__arch}\" )\n    list( APPEND __availableToolchainCompilerVersions \"${__version}\" )\n    list( APPEND ${__availableToolchainsVar} \"${__toolchain}\" )\n   endif()\n  endif()\n  unset( __gcc_toolchain )\n endforeach()\nendmacro()\n\n# get all the details about NDK\nif( BUILD_WITH_ANDROID_NDK )\n file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE \"${ANDROID_NDK}/platforms\" \"${ANDROID_NDK}/platforms/android-*\" )\n string( REPLACE \"android-\" \"\" ANDROID_SUPPORTED_NATIVE_API_LEVELS \"${ANDROID_SUPPORTED_NATIVE_API_LEVELS}\" )\n set( __availableToolchains \"\" )\n set( __availableToolchainMachines \"\" )\n set( __availableToolchainArchs \"\" )\n set( __availableToolchainCompilerVersions \"\" )\n if( ANDROID_TOOLCHAIN_NAME AND EXISTS \"${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/\" )\n  # do not go through all toolchains if we know the name\n  set( __availableToolchainsLst \"${ANDROID_TOOLCHAIN_NAME}\" )\n  __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst \"${ANDROID_NDK_TOOLCHAINS_SUBPATH}\" )\n  if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )\n   __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst \"${ANDROID_NDK_TOOLCHAINS_SUBPATH2}\" )\n   if( __availableToolchains )\n    set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )\n   endif()\n  endif()\n endif()\n if( NOT __availableToolchains )\n  file( GLOB __availableToolchainsLst RELATIVE \"${ANDROID_NDK_TOOLCHAINS_PATH}\" \"${ANDROID_NDK_TOOLCHAINS_PATH}/*\" )\n  if( __availableToolchainsLst )\n   list(SORT __availableToolchainsLst) # we need clang to go after gcc\n  endif()\n  __LIST_FILTER( __availableToolchainsLst \"^[.]\" )\n  __LIST_FILTER( __availableToolchainsLst \"llvm\" )\n  __LIST_FILTER( __availableToolchainsLst \"renderscript\" )\n  __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst \"${ANDROID_NDK_TOOLCHAINS_SUBPATH}\" )\n  if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )\n   __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst \"${ANDROID_NDK_TOOLCHAINS_SUBPATH2}\" )\n   if( __availableToolchains )\n    set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )\n   endif()\n  endif()\n endif()\n if( NOT __availableToolchains )\n  message( FATAL_ERROR \"Could not find any working toolchain in the NDK. Probably your Android NDK is broken.\" )\n endif()\nendif()\n\n# build list of available ABIs\nset( ANDROID_SUPPORTED_ABIS \"\" )\nset( __uniqToolchainArchNames ${__availableToolchainArchs} )\nlist( REMOVE_DUPLICATES __uniqToolchainArchNames )\nlist( SORT __uniqToolchainArchNames )\nforeach( __arch ${__uniqToolchainArchNames} )\n list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} )\nendforeach()\nunset( __uniqToolchainArchNames )\nif( NOT ANDROID_SUPPORTED_ABIS )\n message( FATAL_ERROR \"No one of known Android ABIs is supported by this cmake toolchain.\" )\nendif()\n\n# choose target ABI\n__INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} )\n# verify that target ABI is supported\nlist( FIND ANDROID_SUPPORTED_ABIS \"${ANDROID_ABI}\" __androidAbiIdx )\nif( __androidAbiIdx EQUAL -1 )\n string( REPLACE \";\" \"\\\", \\\"\" PRINTABLE_ANDROID_SUPPORTED_ABIS  \"${ANDROID_SUPPORTED_ABIS}\" )\n message( FATAL_ERROR \"Specified ANDROID_ABI = \\\"${ANDROID_ABI}\\\" is not supported by this cmake toolchain or your NDK/toolchain.\n   Supported values are: \\\"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\\\"\n   \" )\nendif()\nunset( __androidAbiIdx )\n\n# set target ABI options\nif( ANDROID_ABI STREQUAL \"x86\" )\n set( X86 true )\n set( ANDROID_NDK_ABI_NAME \"x86\" )\n set( ANDROID_ARCH_NAME \"x86\" )\n set( ANDROID_LLVM_TRIPLE \"i686-none-linux-android\" )\n set( CMAKE_SYSTEM_PROCESSOR \"i686\" )\nelseif( ANDROID_ABI STREQUAL \"x86_64\" )\n set( X86 true )\n set( X86_64 true )\n set( ANDROID_NDK_ABI_NAME \"x86_64\" )\n set( ANDROID_ARCH_NAME \"x86_64\" )\n set( CMAKE_SYSTEM_PROCESSOR \"x86_64\" )\n set( ANDROID_LLVM_TRIPLE \"x86_64-none-linux-android\" )\nelseif( ANDROID_ABI STREQUAL \"mips64\" )\n set( MIPS64 true )\n set( ANDROID_NDK_ABI_NAME \"mips64\" )\n set( ANDROID_ARCH_NAME \"mips64\" )\n set( ANDROID_LLVM_TRIPLE \"mips64el-none-linux-android\" )\n set( CMAKE_SYSTEM_PROCESSOR \"mips64\" )\nelseif( ANDROID_ABI STREQUAL \"mips\" )\n set( MIPS true )\n set( ANDROID_NDK_ABI_NAME \"mips\" )\n set( ANDROID_ARCH_NAME \"mips\" )\n set( ANDROID_LLVM_TRIPLE \"mipsel-none-linux-android\" )\n set( CMAKE_SYSTEM_PROCESSOR \"mips\" )\nelseif( ANDROID_ABI STREQUAL \"arm64-v8a\" )\n set( ARM64_V8A true )\n set( ANDROID_NDK_ABI_NAME \"arm64-v8a\" )\n set( ANDROID_ARCH_NAME \"arm64\" )\n set( ANDROID_LLVM_TRIPLE \"aarch64-none-linux-android\" )\n set( CMAKE_SYSTEM_PROCESSOR \"aarch64\" )\n set( VFPV3 true )\n set( NEON true )\nelseif( ANDROID_ABI STREQUAL \"armeabi\" )\n set( ARMEABI true )\n set( ANDROID_NDK_ABI_NAME \"armeabi\" )\n set( ANDROID_ARCH_NAME \"arm\" )\n set( ANDROID_LLVM_TRIPLE \"armv5te-none-linux-androideabi\" )\n set( CMAKE_SYSTEM_PROCESSOR \"armv5te\" )\nelseif( ANDROID_ABI STREQUAL \"armeabi-v6 with VFP\" )\n set( ARMEABI_V6 true )\n set( ANDROID_NDK_ABI_NAME \"armeabi\" )\n set( ANDROID_ARCH_NAME \"arm\" )\n set( ANDROID_LLVM_TRIPLE \"armv5te-none-linux-androideabi\" )\n set( CMAKE_SYSTEM_PROCESSOR \"armv6\" )\n # need always fallback to older platform\n set( ARMEABI true )\nelseif( ANDROID_ABI STREQUAL \"armeabi-v7a\")\n set( ARMEABI_V7A true )\n set( ANDROID_NDK_ABI_NAME \"armeabi-v7a\" )\n set( ANDROID_ARCH_NAME \"arm\" )\n set( ANDROID_LLVM_TRIPLE \"armv7-none-linux-androideabi\" )\n set( CMAKE_SYSTEM_PROCESSOR \"armv7-a\" )\nelseif( ANDROID_ABI STREQUAL \"armeabi-v7a with VFPV3\" )\n set( ARMEABI_V7A true )\n set( ANDROID_NDK_ABI_NAME \"armeabi-v7a\" )\n set( ANDROID_ARCH_NAME \"arm\" )\n set( ANDROID_LLVM_TRIPLE \"armv7-none-linux-androideabi\" )\n set( CMAKE_SYSTEM_PROCESSOR \"armv7-a\" )\n set( VFPV3 true )\nelseif( ANDROID_ABI STREQUAL \"armeabi-v7a with NEON\" )\n set( ARMEABI_V7A true )\n set( ANDROID_NDK_ABI_NAME \"armeabi-v7a\" )\n set( ANDROID_ARCH_NAME \"arm\" )\n set( ANDROID_LLVM_TRIPLE \"armv7-none-linux-androideabi\" )\n set( CMAKE_SYSTEM_PROCESSOR \"armv7-a\" )\n set( VFPV3 true )\n set( NEON true )\nelse()\n message( SEND_ERROR \"Unknown ANDROID_ABI=\\\"${ANDROID_ABI}\\\" is specified.\" )\nendif()\n\nif( CMAKE_BINARY_DIR AND EXISTS \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake\" )\n # really dirty hack\n # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...\n file( APPEND \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake\" \"SET(CMAKE_SYSTEM_PROCESSOR \\\"${CMAKE_SYSTEM_PROCESSOR}\\\")\\n\" )\nendif()\n\nif( ANDROID_ARCH_NAME STREQUAL \"arm\" AND NOT ARMEABI_V6 )\n __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF )\n set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL \"Use 32-bit ARM instructions instead of Thumb-1\" FORCE )\n mark_as_advanced( ANDROID_FORCE_ARM_BUILD )\nelse()\n unset( ANDROID_FORCE_ARM_BUILD CACHE )\nendif()\n\n# choose toolchain\nif( ANDROID_TOOLCHAIN_NAME )\n list( FIND __availableToolchains \"${ANDROID_TOOLCHAIN_NAME}\" __toolchainIdx )\n if( __toolchainIdx EQUAL -1 )\n  list( SORT __availableToolchains )\n  string( REPLACE \";\" \"\\n  * \" toolchains_list \"${__availableToolchains}\" )\n  set( toolchains_list \"  * ${toolchains_list}\")\n  message( FATAL_ERROR \"Specified toolchain \\\"${ANDROID_TOOLCHAIN_NAME}\\\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain.\nTo configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\\n${toolchains_list}\\n\" )\n endif()\n list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch )\n if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME )\n  message( SEND_ERROR \"Selected toolchain \\\"${ANDROID_TOOLCHAIN_NAME}\\\" is not able to compile binaries for the \\\"${ANDROID_ARCH_NAME}\\\" platform.\" )\n endif()\nelse()\n set( __toolchainIdx -1 )\n set( __applicableToolchains \"\" )\n set( __toolchainMaxVersion \"0.0.0\" )\n list( LENGTH __availableToolchains __availableToolchainsCount )\n math( EXPR __availableToolchainsCount \"${__availableToolchainsCount}-1\" )\n foreach( __idx RANGE ${__availableToolchainsCount} )\n  list( GET __availableToolchainArchs ${__idx} __toolchainArch )\n  if( __toolchainArch STREQUAL ANDROID_ARCH_NAME )\n   list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion )\n   string( REPLACE \"x\" \"99\" __toolchainVersion \"${__toolchainVersion}\")\n   if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )\n    set( __toolchainMaxVersion \"${__toolchainVersion}\" )\n    set( __toolchainIdx ${__idx} )\n   endif()\n  endif()\n endforeach()\n unset( __availableToolchainsCount )\n unset( __toolchainMaxVersion )\n unset( __toolchainVersion )\nendif()\nunset( __toolchainArch )\nif( __toolchainIdx EQUAL -1 )\n message( FATAL_ERROR \"No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform.\" )\nendif()\nlist( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME )\nlist( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME )\nlist( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION )\n\nunset( __toolchainIdx )\nunset( __availableToolchains )\nunset( __availableToolchainMachines )\nunset( __availableToolchainArchs )\nunset( __availableToolchainCompilerVersions )\n\n# choose native API level\n__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL )\nstring( REPLACE \"android-\" \"\" ANDROID_NATIVE_API_LEVEL \"${ANDROID_NATIVE_API_LEVEL}\" )\nstring( STRIP \"${ANDROID_NATIVE_API_LEVEL}\" ANDROID_NATIVE_API_LEVEL )\n# adjust API level\nset( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} )\nforeach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )\n if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level )\n  set( __real_api_level ${__level} )\n endif()\nendforeach()\nif( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level )\n message( STATUS \"Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'\")\n set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} )\nendif()\nunset(__real_api_level)\n# validate\nlist( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS \"${ANDROID_NATIVE_API_LEVEL}\" __levelIdx )\nif( __levelIdx EQUAL -1 )\n message( SEND_ERROR \"Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain.\" )\nelse()\n if( BUILD_WITH_ANDROID_NDK )\n  __DETECT_NATIVE_API_LEVEL( __realApiLevel \"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h\" )\n  if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 )\n   message( SEND_ERROR \"Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken.\" )\n  endif()\n  unset( __realApiLevel )\n endif()\n set( ANDROID_NATIVE_API_LEVEL \"${ANDROID_NATIVE_API_LEVEL}\" CACHE STRING \"Android API level for native code\" FORCE )\n set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} )\n if( CMAKE_VERSION VERSION_GREATER \"2.8\" )\n  list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )\n  set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )\n endif()\nendif()\nunset( __levelIdx )\n\n\n# remember target ABI\nset( ANDROID_ABI \"${ANDROID_ABI}\" CACHE STRING \"The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point.\" FORCE )\nif( CMAKE_VERSION VERSION_GREATER \"2.8\" )\n list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} )\n set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} )\nendif()\n\n\n# runtime choice (STL, rtti, exceptions)\nif( NOT ANDROID_STL )\n  set( ANDROID_STL gnustl_static )\nendif()\nset( ANDROID_STL \"${ANDROID_STL}\" CACHE STRING \"C++ runtime\" )\nset( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL \"automatically configure rtti and exceptions support based on C++ runtime\" )\nmark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES )\n\nif( BUILD_WITH_ANDROID_NDK )\n if( NOT \"${ANDROID_STL}\" MATCHES \"^(none|system|system_re|gabi\\\\+\\\\+_static|gabi\\\\+\\\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared|c\\\\+\\\\+_shared|c\\\\+\\\\+_static)$\")\n  message( FATAL_ERROR \"ANDROID_STL is set to invalid value \\\"${ANDROID_STL}\\\".\nThe possible values are:\n  none           -> Do not configure the runtime.\n  system         -> Use the default minimal system C++ runtime library.\n  system_re      -> Same as system but with rtti and exceptions.\n  gabi++_static  -> Use the GAbi++ runtime as a static library.\n  gabi++_shared  -> Use the GAbi++ runtime as a shared library.\n  stlport_static -> Use the STLport runtime as a static library.\n  stlport_shared -> Use the STLport runtime as a shared library.\n  gnustl_static  -> (default) Use the GNU STL as a static library.\n  gnustl_shared  -> Use the GNU STL as a shared library.\n  c++_shared     -> Use the LLVM STL as a shared library.\n  c++_static     -> Use the LLVM STL as a static library.\n\" )\n endif()\nelseif( BUILD_WITH_STANDALONE_TOOLCHAIN )\n if( NOT \"${ANDROID_STL}\" MATCHES \"^(none|gnustl_static|gnustl_shared)$\")\n  message( FATAL_ERROR \"ANDROID_STL is set to invalid value \\\"${ANDROID_STL}\\\".\nThe possible values are:\n  none           -> Do not configure the runtime.\n  gnustl_static  -> (default) Use the GNU STL as a static library.\n  gnustl_shared  -> Use the GNU STL as a shared library.\n\" )\n endif()\nendif()\n\nunset( ANDROID_RTTI )\nunset( ANDROID_EXCEPTIONS )\nunset( ANDROID_STL_INCLUDE_DIRS )\nunset( __libstl )\nunset( __libsupcxx )\n\nif( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL \"r7b\" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES \"gnustl\" )\n message( WARNING  \"The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf).\nYou are strongly recommended to switch to another NDK release.\n\" )\nendif()\n\nif( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES \"gnustl\" AND ANDROID_NDK_RELEASE STREQUAL \"r6\" )\n  message( WARNING  \"The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header:\nSee https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2\n  diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h\n  index 5e28c64..65892a1 100644\n  --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h\n  +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h\n  @@ -51,7 +51,11 @@ typedef long int       ssize_t;\n   #endif\n   #ifndef _PTRDIFF_T\n   #define _PTRDIFF_T\n  -typedef long           ptrdiff_t;\n  +#  ifdef __ANDROID__\n  +     typedef int            ptrdiff_t;\n  +#  else\n  +     typedef long           ptrdiff_t;\n  +#  endif\n   #endif\n\" )\nendif()\n\n\n# setup paths and STL for standalone toolchain\nif( BUILD_WITH_STANDALONE_TOOLCHAIN )\n set( ANDROID_TOOLCHAIN_ROOT \"${ANDROID_STANDALONE_TOOLCHAIN}\" )\n set( ANDROID_CLANG_TOOLCHAIN_ROOT \"${ANDROID_STANDALONE_TOOLCHAIN}\" )\n set( ANDROID_SYSROOT \"${ANDROID_STANDALONE_TOOLCHAIN}/sysroot\" )\n\n if( NOT ANDROID_STL STREQUAL \"none\" )\n  set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}\" )\n  if( NOT EXISTS \"${ANDROID_STL_INCLUDE_DIRS}\" )\n   # old location ( pre r8c )\n   set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}\" )\n  endif()\n  if( ARMEABI_V7A AND EXISTS \"${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits\" )\n   list( APPEND ANDROID_STL_INCLUDE_DIRS \"${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}\" )\n  elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS \"${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits\" )\n   list( APPEND ANDROID_STL_INCLUDE_DIRS \"${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb\" )\n  else()\n   list( APPEND ANDROID_STL_INCLUDE_DIRS \"${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}\" )\n  endif()\n  # always search static GNU STL to get the location of libsupc++.a\n  if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a\" )\n   set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb\" )\n  elseif( ARMEABI_V7A AND EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a\" )\n   set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}\" )\n  elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a\" )\n   set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb\" )\n  elseif( EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a\" )\n   set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib\" )\n  endif()\n  if( __libstl )\n   set( __libsupcxx \"${__libstl}/libsupc++.a\" )\n   set( __libstl    \"${__libstl}/libstdc++.a\" )\n  endif()\n  if( NOT EXISTS \"${__libsupcxx}\" )\n   message( FATAL_ERROR \"The required libstdsupc++.a is missing in your standalone toolchain.\n Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c.\n You need to either upgrade to newer NDK or manually copy\n     $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a\n to\n     ${__libsupcxx}\n   \" )\n  endif()\n  if( ANDROID_STL STREQUAL \"gnustl_shared\" )\n   if( ARMEABI_V7A AND EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so\" )\n    set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so\" )\n   elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so\" )\n    set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so\" )\n   elseif( EXISTS \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so\" )\n    set( __libstl \"${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so\" )\n   endif()\n   elseif( ANDROID_STL STREQUAL \"c\\\\+\\\\+_shared\" )\n    set( __libstl \"${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${TARGET_ARCH}/libc++_shared.so\" )\n   endif()\n endif()\nendif()\n\n# clang\nif( \"${ANDROID_TOOLCHAIN_NAME}\" STREQUAL \"standalone-clang\" )\n set( ANDROID_COMPILER_IS_CLANG 1 )\n execute_process( COMMAND \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}\" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )\n string( REGEX MATCH \"[0-9]+[.][0-9]+\" ANDROID_CLANG_VERSION \"${ANDROID_CLANG_VERSION}\")\nelseif( \"${ANDROID_TOOLCHAIN_NAME}\" MATCHES \"-clang3[.][0-9]?$\" )\n string( REGEX MATCH \"3[.][0-9]$\" ANDROID_CLANG_VERSION \"${ANDROID_TOOLCHAIN_NAME}\")\n string( REGEX REPLACE \"-clang${ANDROID_CLANG_VERSION}$\" \"-${ANDROID_COMPILER_VERSION}\" ANDROID_GCC_TOOLCHAIN_NAME \"${ANDROID_TOOLCHAIN_NAME}\" )\n if( NOT EXISTS \"${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}\" )\n  message( FATAL_ERROR \"Could not find the Clang compiler driver\" )\n endif()\n set( ANDROID_COMPILER_IS_CLANG 1 )\n set( ANDROID_CLANG_TOOLCHAIN_ROOT \"${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}\" )\nelse()\n set( ANDROID_GCC_TOOLCHAIN_NAME \"${ANDROID_TOOLCHAIN_NAME}\" )\n unset( ANDROID_COMPILER_IS_CLANG CACHE )\nendif()\n\nstring( REPLACE \".\" \"\" _clang_name \"clang${ANDROID_CLANG_VERSION}\" )\nif( NOT EXISTS \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}\" )\n set( _clang_name \"clang\" )\nendif()\n\n\n# setup paths and STL for NDK\nif( BUILD_WITH_ANDROID_NDK )\n set( ANDROID_TOOLCHAIN_ROOT \"${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}\" )\n set( ANDROID_SYSROOT \"${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}\" )\n\n if( ANDROID_STL STREQUAL \"none\" )\n  # do nothing\n elseif( ANDROID_STL STREQUAL \"system\" )\n  set( ANDROID_RTTI             OFF )\n  set( ANDROID_EXCEPTIONS       OFF )\n  set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_NDK}/sources/cxx-stl/system/include\" )\n elseif( ANDROID_STL STREQUAL \"system_re\" )\n  set( ANDROID_RTTI             ON )\n  set( ANDROID_EXCEPTIONS       ON )\n  set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_NDK}/sources/cxx-stl/system/include\" )\n elseif( ANDROID_STL MATCHES \"gabi\" )\n  if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7\n   message( FATAL_ERROR \"gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.\")\n  endif()\n  set( ANDROID_RTTI             ON )\n  set( ANDROID_EXCEPTIONS       OFF )\n  set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_NDK}/sources/cxx-stl/gabi++/include\" )\n  set( __libstl                 \"${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a\" )\n elseif( ANDROID_STL MATCHES \"stlport\" )\n  if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d\n   set( ANDROID_EXCEPTIONS       ON )\n  else()\n   set( ANDROID_EXCEPTIONS       OFF )\n  endif()\n  if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7\n   set( ANDROID_RTTI            OFF )\n  else()\n   set( ANDROID_RTTI            ON )\n  endif()\n  set( ANDROID_STL_INCLUDE_DIRS \"${ANDROID_NDK}/sources/cxx-stl/stlport/stlport\" )\n  set( __libstl                 \"${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a\" )\n elseif( ANDROID_STL MATCHES \"gnustl\" )\n  set( ANDROID_EXCEPTIONS       ON )\n  set( ANDROID_RTTI             ON )\n  if( EXISTS \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}\" )\n   if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL \"4.7\" AND ANDROID_NDK_RELEASE STREQUAL \"r8d\" )\n    # gnustl binary for 4.7 compiler is buggy :(\n    # TODO: look for right fix\n    set( __libstl                \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6\" )\n   else()\n    set( __libstl                \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}\" )\n   endif()\n  else()\n   set( __libstl                \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++\" )\n  endif()\n  set( ANDROID_STL_INCLUDE_DIRS \"${__libstl}/include\" \"${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include\" \"${__libstl}/include/backward\" )\n  if( EXISTS \"${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a\" )\n   set( __libstl                \"${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a\" )\n  else()\n   set( __libstl                \"${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a\" )\n  endif()\n elseif( ANDROID_STL MATCHES \"c\\\\+\\\\+_shared\" )\n    set( ANDROID_EXCEPTIONS       ON )\n    set( ANDROID_RTTI             ON )\n    set( ANDROID_CXX_ROOT     \"${ANDROID_NDK}/sources/cxx-stl/\" )\n    set( ANDROID_LLVM_ROOT    \"${ANDROID_CXX_ROOT}/llvm-libc++\" )\n    if( X86 ) \n        set( ANDROID_ABI_INCLUDE_DIRS \"${ANDROID_CXX_ROOT}/gabi++/include\" )\n    else()\n        set( ANDROID_ABI_INCLUDE_DIRS \"${ANDROID_CXX_ROOT}/llvm-libc++abi/libcxxabi/include\" )\n    endif()\n    set( ANDROID_STL_INCLUDE_DIRS     \"${ANDROID_LLVM_ROOT}/libcxx/include\" \"${ANDROID_ABI_INCLUDE_DIRS}\" )\n    # android support sfiles\n    include_directories ( SYSTEM ${ANDROID_NDK}/sources/android/support/include )\n    if( EXISTS \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so\" )\n        set( __libstl                           \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so\" )\n    else()\n        message( \"c++ shared library doesn't exist\" )\n    endif()\n elseif( ANDROID_STL MATCHES \"c\\\\+\\\\+_static\" )\n    set( ANDROID_EXCEPTIONS       ON )\n    set( ANDROID_RTTI             ON )\n    set( ANDROID_CXX_ROOT     \"${ANDROID_NDK}/sources/cxx-stl/\" )\n    set( ANDROID_LLVM_ROOT    \"${ANDROID_CXX_ROOT}/llvm-libc++\" )\n    if( X86 ) \n        set( ANDROID_ABI_INCLUDE_DIRS \"${ANDROID_CXX_ROOT}/gabi++/include\" )\n    else()\n        set( ANDROID_ABI_INCLUDE_DIRS \"${ANDROID_CXX_ROOT}/llvm-libc++abi/libcxxabi/include\" )\n    endif()\n    set( ANDROID_STL_INCLUDE_DIRS     \"${ANDROID_LLVM_ROOT}/libcxx/include\" \"${ANDROID_ABI_INCLUDE_DIRS}\" )\n    # android support sfiles\n    include_directories ( SYSTEM ${ANDROID_NDK}/sources/android/support/include )\n    if( NOT ANDROID_FORCE_ARM_BUILD )\n        if( EXISTS \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/thumb/libc++_static.a\" )\n            set( __libstl                           \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/thumb/libc++_static.a\" )\n        else()\n            message( \"c++ static library doesn't exist\" )\n        endif()\n    else()\n        if( EXISTS \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_static.a\" )\n            set( __libstl                           \"${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_static.a\" )\n        else()\n            message( \"c++ static library doesn't exist\" )\n        endif()\n    endif()\n else()\n  message( FATAL_ERROR \"Unknown runtime: ${ANDROID_STL}\" )\n endif()\n # find libsupc++.a - rtti & exceptions\n if( ANDROID_STL STREQUAL \"system_re\" OR ANDROID_STL MATCHES \"gnustl\" )\n  set( __libsupcxx \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a\" ) # r8b or newer\n  if( NOT EXISTS \"${__libsupcxx}\" )\n   set( __libsupcxx \"${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a\" ) # r7-r8\n  endif()\n  if( NOT EXISTS \"${__libsupcxx}\" ) # before r7\n   if( ARMEABI_V7A )\n    if( ANDROID_FORCE_ARM_BUILD )\n     set( __libsupcxx \"${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a\" )\n    else()\n     set( __libsupcxx \"${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a\" )\n    endif()\n   elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD )\n    set( __libsupcxx \"${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a\" )\n   else()\n    set( __libsupcxx \"${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a\" )\n   endif()\n  endif()\n  if( NOT EXISTS \"${__libsupcxx}\")\n   message( ERROR \"Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.\")\n  endif()\n endif()\nendif()\n\n\n# case of shared STL linkage\nif( ANDROID_STL MATCHES \"shared\" AND DEFINED __libstl )\n string( REPLACE \"_static.a\" \"_shared.so\" __libstl \"${__libstl}\" )\n # TODO: check if .so file exists before the renaming\nendif()\n\n\n# ccache support\n__INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE )\nif( _ndk_ccache )\n if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE )\n  unset( NDK_CCACHE CACHE )\n endif()\n find_program( NDK_CCACHE \"${_ndk_ccache}\" DOC \"The path to ccache binary\")\nelse()\n unset( NDK_CCACHE CACHE )\nendif()\nunset( _ndk_ccache )\n\n\n# setup the cross-compiler\nif( NOT CMAKE_C_COMPILER )\n if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES \"[ ;\\\"]\" )\n  set( CMAKE_C_COMPILER   \"${NDK_CCACHE}\" CACHE PATH \"ccache as C compiler\" )\n  set( CMAKE_CXX_COMPILER \"${NDK_CCACHE}\" CACHE PATH \"ccache as C++ compiler\" )\n  if( ANDROID_COMPILER_IS_CLANG )\n   set( CMAKE_C_COMPILER_ARG1   \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}\"   CACHE PATH \"C compiler\")\n   set( CMAKE_CXX_COMPILER_ARG1 \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}\" CACHE PATH \"C++ compiler\")\n  else()\n   set( CMAKE_C_COMPILER_ARG1   \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}\" CACHE PATH \"C compiler\")\n   set( CMAKE_CXX_COMPILER_ARG1 \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}\" CACHE PATH \"C++ compiler\")\n  endif()\n else()\n  if( ANDROID_COMPILER_IS_CLANG )\n   set( CMAKE_C_COMPILER   \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}\"   CACHE PATH \"C compiler\")\n   set( CMAKE_CXX_COMPILER \"${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}\" CACHE PATH \"C++ compiler\")\n  else()\n   set( CMAKE_C_COMPILER   \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}\"    CACHE PATH \"C compiler\" )\n   set( CMAKE_CXX_COMPILER \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}\"    CACHE PATH \"C++ compiler\" )\n  endif()\n endif()\n set( CMAKE_ASM_COMPILER \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}\"     CACHE PATH \"assembler\" )\n set( CMAKE_STRIP        \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}\"   CACHE PATH \"strip\" )\n set( CMAKE_AR           \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}\"      CACHE PATH \"archive\" )\n if( EXISTS \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}\" )\n  # Use gcc-ar if we have it for better LTO support.\n  set( CMAKE_AR           \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}\"      CACHE PATH \"archive\" )\n else()\n  set( CMAKE_AR           \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}\"      CACHE PATH \"archive\" )\n endif()\n set( CMAKE_LINKER       \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}\"      CACHE PATH \"linker\" )\n set( CMAKE_NM           \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}\"      CACHE PATH \"nm\" )\n set( CMAKE_OBJCOPY      \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}\" CACHE PATH \"objcopy\" )\n set( CMAKE_OBJDUMP      \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}\" CACHE PATH \"objdump\" )\n set( CMAKE_RANLIB       \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}\"  CACHE PATH \"ranlib\" )\nendif()\n\nset( _CMAKE_TOOLCHAIN_PREFIX \"${ANDROID_TOOLCHAIN_MACHINE_NAME}-\" )\nif( CMAKE_VERSION VERSION_LESS 2.8.5 )\n set( CMAKE_ASM_COMPILER_ARG1 \"-c\" )\nendif()\nif( APPLE )\n find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )\n if( NOT CMAKE_INSTALL_NAME_TOOL )\n  message( FATAL_ERROR \"Could not find install_name_tool, please check your installation.\" )\n endif()\n mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )\nendif()\n\n# Force set compilers because standard identification works badly for us\ninclude( CMakeForceCompiler )\nCMAKE_FORCE_C_COMPILER( \"${CMAKE_C_COMPILER}\" GNU )\nif( ANDROID_COMPILER_IS_CLANG )\n set( CMAKE_C_COMPILER_ID Clang )\nendif()\nset( CMAKE_C_PLATFORM_ID Linux )\nif( X86_64 OR MIPS64 OR ARM64_V8A )\n set( CMAKE_C_SIZEOF_DATA_PTR 8 )\nelse()\n set( CMAKE_C_SIZEOF_DATA_PTR 4 )\nendif()\nset( CMAKE_C_HAS_ISYSROOT 1 )\nset( CMAKE_C_COMPILER_ABI ELF )\nCMAKE_FORCE_CXX_COMPILER( \"${CMAKE_CXX_COMPILER}\" GNU )\nif( ANDROID_COMPILER_IS_CLANG )\n set( CMAKE_CXX_COMPILER_ID Clang)\nendif()\nset( CMAKE_CXX_PLATFORM_ID Linux )\nset( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} )\nset( CMAKE_CXX_HAS_ISYSROOT 1 )\nset( CMAKE_CXX_COMPILER_ABI ELF )\nset( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C )\n# force ASM compiler (required for CMake < 2.8.5)\nset( CMAKE_ASM_COMPILER_ID_RUN TRUE )\nset( CMAKE_ASM_COMPILER_ID GNU )\nset( CMAKE_ASM_COMPILER_WORKS TRUE )\nset( CMAKE_ASM_COMPILER_FORCED TRUE )\nset( CMAKE_COMPILER_IS_GNUASM 1)\nset( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm )\n\nforeach( lang C CXX ASM )\n if( ANDROID_COMPILER_IS_CLANG )\n  set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_CLANG_VERSION} )\n else()\n  set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_COMPILER_VERSION} )\n endif()\nendforeach()\n\n# flags and definitions\nremove_definitions( -DANDROID )\nadd_definitions( -DANDROID )\n\nif( ANDROID_SYSROOT MATCHES \"[ ;\\\"]\" )\n if( CMAKE_HOST_WIN32 )\n  # try to convert path to 8.3 form\n  file( WRITE \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd\" \"@echo %~s1\" )\n  execute_process( COMMAND \"$ENV{ComSpec}\" /c \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd\" \"${ANDROID_SYSROOT}\"\n                   OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE\n                   RESULT_VARIABLE __result ERROR_QUIET )\n  if( __result EQUAL 0 )\n   file( TO_CMAKE_PATH \"${__path}\" ANDROID_SYSROOT )\n   set( ANDROID_CXX_FLAGS \"--sysroot=${ANDROID_SYSROOT}\" )\n  else()\n   set( ANDROID_CXX_FLAGS \"--sysroot=\\\"${ANDROID_SYSROOT}\\\"\" )\n  endif()\n else()\n  set( ANDROID_CXX_FLAGS \"'--sysroot=${ANDROID_SYSROOT}'\" )\n endif()\n if( NOT _CMAKE_IN_TRY_COMPILE )\n  # quotes can break try_compile and compiler identification\n  message(WARNING \"Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\\nThe build might be broken.\\n\")\n endif()\nelse()\n set( ANDROID_CXX_FLAGS \"--sysroot=${ANDROID_SYSROOT}\" )\nendif()\nset( CMAKE_REQUIRED_FLAGS \"${CMAKE_REQUIRED_FLAGS} ${ANDROID_CXX_FLAGS}\" )\n\n# NDK flags\nif (ARM64_V8A )\n set( ANDROID_CXX_FLAGS         \"${ANDROID_CXX_FLAGS} -funwind-tables\" )\n set( ANDROID_CXX_FLAGS_RELEASE \"-fomit-frame-pointer -fstrict-aliasing\" )\n set( ANDROID_CXX_FLAGS_DEBUG   \"-fno-omit-frame-pointer -fno-strict-aliasing\" )\n if( NOT ANDROID_COMPILER_IS_CLANG )\n  set( ANDROID_CXX_FLAGS_RELEASE \"${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300\" )\n endif()\nelseif( ARMEABI OR ARMEABI_V7A)\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -funwind-tables\" )\n if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )\n  set( ANDROID_CXX_FLAGS_RELEASE \"-mthumb -fomit-frame-pointer -fno-strict-aliasing\" )\n  set( ANDROID_CXX_FLAGS_DEBUG   \"-marm -fno-omit-frame-pointer -fno-strict-aliasing\" )\n  if( NOT ANDROID_COMPILER_IS_CLANG )\n   set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -finline-limit=64\" )\n  endif()\n else()\n  # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI\n  set( ANDROID_CXX_FLAGS_RELEASE \"-marm -fomit-frame-pointer -fstrict-aliasing\" )\n  set( ANDROID_CXX_FLAGS_DEBUG   \"-marm -fno-omit-frame-pointer -fno-strict-aliasing\" )\n  if( NOT ANDROID_COMPILER_IS_CLANG )\n   set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300\" )\n  endif()\n endif()\nelseif( X86 OR X86_64 )\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -funwind-tables\" )\n if( NOT ANDROID_COMPILER_IS_CLANG )\n  set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300\" )\n endif()\n set( ANDROID_CXX_FLAGS_RELEASE \"-fomit-frame-pointer -fstrict-aliasing\" )\n set( ANDROID_CXX_FLAGS_DEBUG   \"-fno-omit-frame-pointer -fno-strict-aliasing\" )\nelseif( MIPS OR MIPS64 )\n set( ANDROID_CXX_FLAGS         \"${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0\" )\n set( ANDROID_CXX_FLAGS_RELEASE \"-fomit-frame-pointer\" )\n set( ANDROID_CXX_FLAGS_DEBUG   \"-fno-omit-frame-pointer\" )\n if( NOT ANDROID_COMPILER_IS_CLANG )\n  set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers\" )\n  set( ANDROID_CXX_FLAGS_RELEASE \"${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300\" )\n endif()\nelseif()\n set( ANDROID_CXX_FLAGS_RELEASE \"\" )\n set( ANDROID_CXX_FLAGS_DEBUG   \"\" )\nendif()\n\nset( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -fsigned-char\" ) # good/necessary when porting desktop libraries\n\nif( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG )\n set( ANDROID_CXX_FLAGS \"-Wno-psabi ${ANDROID_CXX_FLAGS}\" )\nendif()\n\nif( NOT ANDROID_COMPILER_VERSION VERSION_LESS \"4.6\" )\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -no-canonical-prefixes\" ) # see https://android-review.googlesource.com/#/c/47564/\nendif()\n\n# ABI-specific flags\nif( ARMEABI_V7A )\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp\" )\n if( NEON )\n  set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -mfpu=neon\" )\n elseif( VFPV3 )\n  set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -mfpu=vfpv3\" )\n else()\n  set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16\" )\n endif()\nelseif( ARMEABI_V6 )\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp\" ) # vfp == vfpv2\nelseif( ARMEABI )\n set( ANDROID_CXX_FLAGS \"${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float\" )\nendif()\n\nif( ANDROID_STL MATCHES \"gnustl\" AND (EXISTS \"${__libstl}\" OR EXISTS \"${__libsupcxx}\") )\n set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n set( CMAKE_CXX_CREATE_SHARED_MODULE  \"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n set( CMAKE_CXX_LINK_EXECUTABLE       \"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>\" )\nelse()\n set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n set( CMAKE_CXX_CREATE_SHARED_MODULE  \"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n set( CMAKE_CXX_LINK_EXECUTABLE       \"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>\" )\nendif()\n\n# STL\nif( EXISTS \"${__libstl}\" OR EXISTS \"${__libsupcxx}\" )\n if( EXISTS \"${__libstl}\" )\n  set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"${CMAKE_CXX_CREATE_SHARED_LIBRARY} \\\"${__libstl}\\\"\" )\n  set( CMAKE_CXX_CREATE_SHARED_MODULE  \"${CMAKE_CXX_CREATE_SHARED_MODULE} \\\"${__libstl}\\\"\" )\n  set( CMAKE_CXX_LINK_EXECUTABLE       \"${CMAKE_CXX_LINK_EXECUTABLE} \\\"${__libstl}\\\"\" )\n endif()\n if( EXISTS \"${__libsupcxx}\" )\n  set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"${CMAKE_CXX_CREATE_SHARED_LIBRARY} \\\"${__libsupcxx}\\\"\" )\n  set( CMAKE_CXX_CREATE_SHARED_MODULE  \"${CMAKE_CXX_CREATE_SHARED_MODULE} \\\"${__libsupcxx}\\\"\" )\n  set( CMAKE_CXX_LINK_EXECUTABLE       \"${CMAKE_CXX_LINK_EXECUTABLE} \\\"${__libsupcxx}\\\"\" )\n  # C objects:\n  set( CMAKE_C_CREATE_SHARED_LIBRARY \"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n  set( CMAKE_C_CREATE_SHARED_MODULE  \"<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>\" )\n  set( CMAKE_C_LINK_EXECUTABLE       \"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>\" )\n  set( CMAKE_C_CREATE_SHARED_LIBRARY \"${CMAKE_C_CREATE_SHARED_LIBRARY} \\\"${__libsupcxx}\\\"\" )\n  set( CMAKE_C_CREATE_SHARED_MODULE  \"${CMAKE_C_CREATE_SHARED_MODULE} \\\"${__libsupcxx}\\\"\" )\n  set( CMAKE_C_LINK_EXECUTABLE       \"${CMAKE_C_LINK_EXECUTABLE} \\\"${__libsupcxx}\\\"\" )\n endif()\n if( ANDROID_STL MATCHES \"gnustl\" )\n  if( NOT EXISTS \"${ANDROID_LIBM_PATH}\" )\n   set( ANDROID_LIBM_PATH -lm )\n  endif()\n  set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}\" )\n  set( CMAKE_CXX_CREATE_SHARED_MODULE  \"${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}\" )\n  set( CMAKE_CXX_LINK_EXECUTABLE       \"${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}\" )\n endif()\nendif()\n\n# variables controlling optional build flags\nif( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7\n # libGLESv2.so in NDK's prior to r7 refers to missing external symbols.\n # So this flag option is required for all projects using OpenGL from native.\n __INIT_VARIABLE( ANDROID_SO_UNDEFINED                      VALUES ON )\nelse()\n __INIT_VARIABLE( ANDROID_SO_UNDEFINED                      VALUES OFF )\nendif()\n__INIT_VARIABLE( ANDROID_NO_UNDEFINED                       VALUES ON )\n__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING             VALUES ON )\n__INIT_VARIABLE( ANDROID_GOLD_LINKER                        VALUES ON )\n__INIT_VARIABLE( ANDROID_NOEXECSTACK                        VALUES ON )\n__INIT_VARIABLE( ANDROID_RELRO                              VALUES ON )\n\nset( ANDROID_NO_UNDEFINED           ${ANDROID_NO_UNDEFINED}           CACHE BOOL \"Show all undefined symbols as linker errors\" )\nset( ANDROID_SO_UNDEFINED           ${ANDROID_SO_UNDEFINED}           CACHE BOOL \"Allows or disallows undefined symbols in shared libraries\" )\nset( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL \"Put each function in separate section and enable garbage collection of unused input sections at link time\" )\nset( ANDROID_GOLD_LINKER            ${ANDROID_GOLD_LINKER}            CACHE BOOL \"Enables gold linker\" )\nset( ANDROID_NOEXECSTACK            ${ANDROID_NOEXECSTACK}            CACHE BOOL \"Allows or disallows undefined symbols in shared libraries\" )\nset( ANDROID_RELRO                  ${ANDROID_RELRO}                  CACHE BOOL \"Enables RELRO - a memory corruption mitigation technique\" )\nmark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO )\n\n# linker flags\nset( ANDROID_LINKER_FLAGS \"\" )\n\nif( ARMEABI_V7A )\n # this is *required* to use the following linker flags that routes around\n # a CPU bug in some Cortex-A8 implementations:\n set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8\" )\nendif()\n\nif( ANDROID_NO_UNDEFINED )\n if( MIPS )\n  # there is some sysroot-related problem in mips linker...\n  if( NOT ANDROID_SYSROOT MATCHES \"[ ;\\\"]\" )\n   set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib\" )\n  endif()\n else()\n  set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,--no-undefined\" )\n endif()\nendif()\n\nif( ANDROID_SO_UNDEFINED )\n set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined\" )\nendif()\n\nif( ANDROID_FUNCTION_LEVEL_LINKING )\n set( ANDROID_CXX_FLAGS    \"${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections\" )\n set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,--gc-sections\" )\nendif()\n\nif( ANDROID_COMPILER_VERSION VERSION_EQUAL \"4.6\" )\n if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) )\n  set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -fuse-ld=gold\" )\n elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b\n  set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -fuse-ld=bfd\" )\n elseif( ANDROID_NDK_RELEASE STREQUAL \"r8b\" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE )\n  message( WARNING \"The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342\n  On Linux and OS X host platform you can workaround this problem using gold linker (default).\n  Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems.\n\" )\n endif()\nendif() # version 4.6\n\nif( ANDROID_NOEXECSTACK )\n if( ANDROID_COMPILER_IS_CLANG )\n  set( ANDROID_CXX_FLAGS    \"${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack\" )\n else()\n  set( ANDROID_CXX_FLAGS    \"${ANDROID_CXX_FLAGS} -Wa,--noexecstack\" )\n endif()\n set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack\" )\nendif()\n\nif( ANDROID_RELRO )\n set( ANDROID_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now\" )\nendif()\n\nif( ANDROID_COMPILER_IS_CLANG )\n set( ANDROID_CXX_FLAGS \"-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}\" )\n if( BUILD_WITH_ANDROID_NDK )\n  set( ANDROID_CXX_FLAGS \"-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}\" )\n endif()\nendif()\n\n# cache flags\nset( CMAKE_CXX_FLAGS           \"\"                        CACHE STRING \"c++ flags\" )\nset( CMAKE_C_FLAGS             \"\"                        CACHE STRING \"c flags\" )\nset( CMAKE_CXX_FLAGS_RELEASE   \"-O3 -DNDEBUG\"            CACHE STRING \"c++ Release flags\" )\nset( CMAKE_C_FLAGS_RELEASE     \"-O3 -DNDEBUG\"            CACHE STRING \"c Release flags\" )\nset( CMAKE_CXX_FLAGS_DEBUG     \"-O0 -g -DDEBUG -D_DEBUG\" CACHE STRING \"c++ Debug flags\" )\nset( CMAKE_C_FLAGS_DEBUG       \"-O0 -g -DDEBUG -D_DEBUG\" CACHE STRING \"c Debug flags\" )\nset( CMAKE_SHARED_LINKER_FLAGS \"\"                        CACHE STRING \"shared linker flags\" )\nset( CMAKE_MODULE_LINKER_FLAGS \"\"                        CACHE STRING \"module linker flags\" )\nset( CMAKE_EXE_LINKER_FLAGS    \"-Wl,-z,nocopyreloc\"      CACHE STRING \"executable linker flags\" )\n\n# put flags to cache (for debug purpose only)\nset( ANDROID_CXX_FLAGS         \"${ANDROID_CXX_FLAGS}\"         CACHE INTERNAL \"Android specific c/c++ flags\" )\nset( ANDROID_CXX_FLAGS_RELEASE \"${ANDROID_CXX_FLAGS_RELEASE}\" CACHE INTERNAL \"Android specific c/c++ Release flags\" )\nset( ANDROID_CXX_FLAGS_DEBUG   \"${ANDROID_CXX_FLAGS_DEBUG}\"   CACHE INTERNAL \"Android specific c/c++ Debug flags\" )\nset( ANDROID_LINKER_FLAGS      \"${ANDROID_LINKER_FLAGS}\"      CACHE INTERNAL \"Android specific c/c++ linker flags\" )\n\n# finish flags\nset( CMAKE_CXX_FLAGS           \"${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}\" )\nset( CMAKE_C_FLAGS             \"${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}\" )\nset( CMAKE_CXX_FLAGS_RELEASE   \"${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}\" )\nset( CMAKE_C_FLAGS_RELEASE     \"${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}\" )\nset( CMAKE_CXX_FLAGS_DEBUG     \"${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}\" )\nset( CMAKE_C_FLAGS_DEBUG       \"${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}\" )\nset( CMAKE_SHARED_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}\" )\nset( CMAKE_MODULE_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}\" )\nset( CMAKE_EXE_LINKER_FLAGS    \"${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}\" )\n\nif( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL \"r8\" )\n set( CMAKE_SHARED_LINKER_FLAGS \"-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}\" )\n set( CMAKE_MODULE_LINKER_FLAGS \"-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}\" )\n set( CMAKE_EXE_LINKER_FLAGS    \"-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}\" )\nendif()\n\n# pie/pic\nif( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) )\n set( CMAKE_POSITION_INDEPENDENT_CODE TRUE )\n set( CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie\")\nelse()\n set( CMAKE_POSITION_INDEPENDENT_CODE FALSE )\n set( CMAKE_CXX_FLAGS \"-fpic ${CMAKE_CXX_FLAGS}\" )\n set( CMAKE_C_FLAGS   \"-fpic ${CMAKE_C_FLAGS}\" )\nendif()\n\n# configure rtti\nif( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES )\n if( ANDROID_RTTI )\n  set( CMAKE_CXX_FLAGS \"-frtti ${CMAKE_CXX_FLAGS}\" )\n else()\n  set( CMAKE_CXX_FLAGS \"-fno-rtti ${CMAKE_CXX_FLAGS}\" )\n endif()\nendif()\n\n# configure exceptios\nif( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )\n if( ANDROID_EXCEPTIONS )\n  set( CMAKE_CXX_FLAGS \"-fexceptions ${CMAKE_CXX_FLAGS}\" )\n  set( CMAKE_C_FLAGS \"-fexceptions ${CMAKE_C_FLAGS}\" )\n else()\n  set( CMAKE_CXX_FLAGS \"-fno-exceptions ${CMAKE_CXX_FLAGS}\" )\n  set( CMAKE_C_FLAGS \"-fno-exceptions ${CMAKE_C_FLAGS}\" )\n endif()\nendif()\n\n# global includes and link directories\ninclude_directories( SYSTEM \"${ANDROID_SYSROOT}/usr/include\" ${ANDROID_STL_INCLUDE_DIRS} )\nget_filename_component(__android_install_path \"${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}\" ABSOLUTE) # avoid CMP0015 policy warning\nlink_directories( \"${__android_install_path}\" )\n\n# detect if need link crtbegin_so.o explicitly\nif( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK )\n set( __cmd \"${CMAKE_CXX_CREATE_SHARED_LIBRARY}\" )\n string( REPLACE \"<CMAKE_CXX_COMPILER>\" \"${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}\" __cmd \"${__cmd}\" )\n string( REPLACE \"<CMAKE_C_COMPILER>\"   \"${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}\"   __cmd \"${__cmd}\" )\n string( REPLACE \"<CMAKE_SHARED_LIBRARY_CXX_FLAGS>\" \"${CMAKE_CXX_FLAGS}\" __cmd \"${__cmd}\" )\n string( REPLACE \"<LANGUAGE_COMPILE_FLAGS>\" \"\" __cmd \"${__cmd}\" )\n string( REPLACE \"<LINK_FLAGS>\" \"${CMAKE_SHARED_LINKER_FLAGS}\" __cmd \"${__cmd}\" )\n string( REPLACE \"<CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>\" \"-shared\" __cmd \"${__cmd}\" )\n string( REPLACE \"<CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG>\" \"\" __cmd \"${__cmd}\" )\n string( REPLACE \"<TARGET_SONAME>\" \"\" __cmd \"${__cmd}\" )\n string( REPLACE \"<TARGET>\" \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so\" __cmd \"${__cmd}\" )\n string( REPLACE \"<OBJECTS>\" \"\\\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\\\"\" __cmd \"${__cmd}\" )\n string( REPLACE \"<LINK_LIBRARIES>\" \"\" __cmd \"${__cmd}\" )\n separate_arguments( __cmd )\n foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN )\n  if( ${__var} )\n   set( __tmp \"${${__var}}\" )\n   separate_arguments( __tmp )\n   string( REPLACE \"${__tmp}\" \"${${__var}}\" __cmd \"${__cmd}\")\n  endif()\n endforeach()\n string( REPLACE \"'\" \"\" __cmd \"${__cmd}\" )\n string( REPLACE \"\\\"\" \"\" __cmd \"${__cmd}\" )\n execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET )\n if( __cmd_result EQUAL 0 )\n  set( ANDROID_EXPLICIT_CRT_LINK ON )\n else()\n  set( ANDROID_EXPLICIT_CRT_LINK OFF )\n endif()\nendif()\n\nif( ANDROID_EXPLICIT_CRT_LINK )\n set( CMAKE_CXX_CREATE_SHARED_LIBRARY \"${CMAKE_CXX_CREATE_SHARED_LIBRARY} \\\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\\\"\" )\n set( CMAKE_CXX_CREATE_SHARED_MODULE  \"${CMAKE_CXX_CREATE_SHARED_MODULE} \\\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\\\"\" )\nendif()\n\n# setup output directories\nset( CMAKE_INSTALL_PREFIX \"${ANDROID_TOOLCHAIN_ROOT}/user\" CACHE STRING \"path for installing\" )\n\nif( DEFINED LIBRARY_OUTPUT_PATH_ROOT\n      OR EXISTS \"${CMAKE_SOURCE_DIR}/android/AndroidManifest.xml\"\n      OR (EXISTS \"${CMAKE_SOURCE_DIR}/../AndroidManifest.xml\" AND EXISTS \"${CMAKE_SOURCE_DIR}/../jni/\") )\n  set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR}/android CACHE PATH \"Root for binaries output, set this to change where Android libs are installed to\" )\n  if( NOT _CMAKE_IN_TRY_COMPILE )\n    if( EXISTS \"${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt\" )\n      set( EXECUTABLE_OUTPUT_PATH \"${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}\" CACHE PATH \"Output directory for applications\" )\n    else()\n      set( EXECUTABLE_OUTPUT_PATH \"${LIBRARY_OUTPUT_PATH_ROOT}/bin\" CACHE PATH \"Output directory for applications\" )\n    endif()\n    set( LIBRARY_OUTPUT_PATH \"${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}\" CACHE PATH \"Output directory for Android libs\" )\n  endif()\nendif()\n\n# copy shaed stl library to build directory\nif( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES \"[.]so$\" AND DEFINED LIBRARY_OUTPUT_PATH )\n  get_filename_component( __libstlname \"${__libstl}\" NAME )\n  execute_process( COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different \"${__libstl}\" \"${LIBRARY_OUTPUT_PATH}/${__libstlname}\" RESULT_VARIABLE __fileCopyProcess )\n  if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS \"${LIBRARY_OUTPUT_PATH}/${__libstlname}\")\n    message( SEND_ERROR \"Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}\" )\n  endif()\n  unset( __fileCopyProcess )\n  unset( __libstlname )\nendif()\n\n\n# set these global flags for cmake client scripts to change behavior\nset( ANDROID True )\nset( BUILD_ANDROID True )\n\n# where is the target environment\n# http://www.vtk.org/Wiki/CMake_Cross_Compiling\n# we need to use find_path in our custorm modules, so disable it.\n# set( CMAKE_FIND_ROOT_PATH \"${ANDROID_TOOLCHAIN_ROOT}/bin\" \"${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}\" \"${ANDROID_SYSROOT}\" \"${CMAKE_INSTALL_PREFIX}\" \"${CMAKE_INSTALL_PREFIX}/share\" )\n\n# only search for libraries and includes in the ndk toolchain\nset( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )\nset( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )\nset( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )\n\n\n# macro to find packages on the host OS\nmacro( find_host_package )\n set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )\n set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )\n set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )\n if( CMAKE_HOST_WIN32 )\n  SET( WIN32 1 )\n  SET( UNIX )\n elseif( CMAKE_HOST_APPLE )\n  SET( APPLE 1 )\n  SET( UNIX )\n endif()\n find_package( ${ARGN} )\n SET( WIN32 )\n SET( APPLE )\n SET( UNIX 1 )\n set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )\n set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )\n set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )\nendmacro()\n\n\n# macro to find programs on the host OS\nmacro( find_host_program )\n set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )\n set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )\n set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )\n if( CMAKE_HOST_WIN32 )\n  SET( WIN32 1 )\n  SET( UNIX )\n elseif( CMAKE_HOST_APPLE )\n  SET( APPLE 1 )\n  SET( UNIX )\n endif()\n find_program( ${ARGN} )\n SET( WIN32 )\n SET( APPLE )\n SET( UNIX 1 )\n set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )\n set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )\n set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )\nendmacro()\n\n\n# export toolchain settings for the try_compile() command\nif( NOT _CMAKE_IN_TRY_COMPILE )\n set( __toolchain_config \"\")\n foreach( __var NDK_CCACHE  LIBRARY_OUTPUT_PATH_ROOT  ANDROID_FORBID_SYGWIN\n                ANDROID_NDK_HOST_X64\n                ANDROID_NDK\n                ANDROID_NDK_LAYOUT\n                ANDROID_STANDALONE_TOOLCHAIN\n                ANDROID_TOOLCHAIN_NAME\n                ANDROID_ABI\n                ANDROID_NATIVE_API_LEVEL\n                ANDROID_STL\n                ANDROID_STL_FORCE_FEATURES\n                ANDROID_FORCE_ARM_BUILD\n                ANDROID_NO_UNDEFINED\n                ANDROID_SO_UNDEFINED\n                ANDROID_FUNCTION_LEVEL_LINKING\n                ANDROID_GOLD_LINKER\n                ANDROID_NOEXECSTACK\n                ANDROID_RELRO\n                ANDROID_LIBM_PATH\n                ANDROID_EXPLICIT_CRT_LINK\n                ANDROID_APP_PIE\n                )\n  if( DEFINED ${__var} )\n   if( ${__var} MATCHES \" \")\n    set( __toolchain_config \"${__toolchain_config}set( ${__var} \\\"${${__var}}\\\" CACHE INTERNAL \\\"\\\" )\\n\" )\n   else()\n    set( __toolchain_config \"${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \\\"\\\" )\\n\" )\n   endif()\n  endif()\n endforeach()\n file( WRITE \"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake\" \"${__toolchain_config}\" )\n unset( __toolchain_config )\nendif()\n\n\n# force cmake to produce / instead of \\ in build commands for Ninja generator\nif( CMAKE_GENERATOR MATCHES \"Ninja\" AND CMAKE_HOST_WIN32 )\n # it is a bad hack after all\n # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW\n set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW\n set( CMAKE_CROSSCOMPILING TRUE )    # stop recursion\n enable_language( C )\n enable_language( CXX )\n # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it\n unset( MINGW )\nendif()\n\n\n# Variables controlling behavior or set by cmake toolchain:\n#   ANDROID_ABI : \"armeabi-v7a\" (default), \"armeabi\", \"armeabi-v7a with NEON\", \"armeabi-v7a with VFPV3\", \"armeabi-v6 with VFP\", \"x86\", \"mips\", \"arm64-v8a\", \"x86_64\", \"mips64\"\n#   ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version)\n#   ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none\n#   ANDROID_FORBID_SYGWIN : ON/OFF\n#   ANDROID_NO_UNDEFINED : ON/OFF\n#   ANDROID_SO_UNDEFINED : OFF/ON  (default depends on NDK version)\n#   ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF\n#   ANDROID_GOLD_LINKER : ON/OFF\n#   ANDROID_NOEXECSTACK : ON/OFF\n#   ANDROID_RELRO : ON/OFF\n#   ANDROID_FORCE_ARM_BUILD : ON/OFF\n#   ANDROID_STL_FORCE_FEATURES : ON/OFF\n#   ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product/<product_name>/obj/lib/libm.so) to workaround unresolved `sincos`\n# Can be set only at the first run:\n#   ANDROID_NDK : path to your NDK install\n#   NDK_CCACHE : path to your ccache executable\n#   ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain\n#   ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems)\n#   ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID)\n#   LIBRARY_OUTPUT_PATH_ROOT : <any valid path>\n#   ANDROID_STANDALONE_TOOLCHAIN\n#\n# Primary read-only variables:\n#   ANDROID : always TRUE\n#   ARMEABI : TRUE for arm v6 and older devices\n#   ARMEABI_V6 : TRUE for arm v6\n#   ARMEABI_V7A : TRUE for arm v7a\n#   ARM64_V8A : TRUE for arm64-v8a\n#   NEON : TRUE if NEON unit is enabled\n#   VFPV3 : TRUE if VFP version 3 is enabled\n#   X86 : TRUE if configured for x86\n#   X86_64 : TRUE if configured for x86_64\n#   MIPS : TRUE if configured for mips\n#   MIPS64 : TRUE if configured for mips64\n#   BUILD_WITH_ANDROID_NDK : TRUE if NDK is used\n#   BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used\n#   ANDROID_NDK_HOST_SYSTEM_NAME : \"windows\", \"linux-x86\" or \"darwin-x86\" depending on host platform\n#   ANDROID_NDK_ABI_NAME : \"armeabi\", \"armeabi-v7a\", \"x86\", \"mips\", \"arm64-v8a\", \"x86_64\", \"mips64\" depending on ANDROID_ABI\n#   ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK\n#   ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor)\n#   ANDROID_ARCH_NAME : \"arm\", \"x86\", \"mips\", \"arm64\", \"x86_64\", \"mips64\" depending on ANDROID_ABI\n#   ANDROID_SYSROOT : path to the compiler sysroot\n#   TOOL_OS_SUFFIX : \"\" or \".exe\" depending on host platform\n#   ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used\n#\n# Secondary (less stable) read-only variables:\n#   ANDROID_COMPILER_VERSION : GCC version used (not Clang version)\n#   ANDROID_CLANG_VERSION : version of clang compiler if clang is used\n#   ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform\n#   ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI\n#   ANDROID_TOOLCHAIN_MACHINE_NAME : \"arm-linux-androideabi\", \"arm-eabi\" or \"i686-android-linux\"\n#   ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)\n#   ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools\n#   ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK\n#   ANDROID_STL_INCLUDE_DIRS : stl include paths\n#   ANDROID_RTTI : if rtti is enabled by the runtime\n#   ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime\n#   ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used\n#\n# Defaults:\n#   ANDROID_DEFAULT_NDK_API_LEVEL\n#   ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}\n#   ANDROID_NDK_SEARCH_PATHS\n#   ANDROID_SUPPORTED_ABIS_${ARCH}\n#   ANDROID_SUPPORTED_NDK_VERSIONS\n"
  },
  {
    "path": "build/cmake/android.windows.toolchain.cmake",
    "content": "cmake_minimum_required(VERSION 3.6)\n\nmacro(Highlight_Error error_msg)\n\tmessage(\"==================\")\n\tmessage(\"Error: ${error_msg}\")\n\tmessage(\"==================\")\n\tmessage(FATAL_ERROR \"\")\nendmacro()\n\nif(NOT DEFINED ENV{ANDROID_NDK})\n\tHighlight_Error(\"not defined environment variable %ANDROID_NDK%\")\nelse()\n\tset(ANDROID_NDK $ENV{ANDROID_NDK})\nendif()\nfile(TO_CMAKE_PATH \"${ANDROID_NDK}\" ANDROID_NDK)\n\nif(ANDROID_TOOLCHAIN_NAME AND NOT ANDROID_TOOLCHAIN)\n\tif(ANDROID_TOOLCHAIN_NAME MATCHES \"-clang([0-9].[0-9])?$\")\n\t\tset(ANDROID_TOOLCHAIN clang)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"-[0-9].[0-9]$\")\n\t\tset(ANDROID_TOOLCHAIN gcc)\n\tendif()\nendif()\n\nif(ANDROID_ABI STREQUAL \"armeabi-v7a with NEON\")\n\tset(ANDROID_ABI armeabi-v7a)\n\tset(ANDROID_ARM_NEON TRUE)\nelseif(ANDROID_TOOLCHAIN_NAME AND NOT ANDROID_ABI)\n\tif(ANDROID_TOOLCHAIN_NAME MATCHES \"^arm-linux-androideabi-\")\n\t\tset(ANDROID_ABI armeabi-v7a)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"^aarch64-linux-android-\")\n\t\tset(ANDROID_ABI arm64-v8a)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"^x86-\")\n\t\tset(ANDROID_ABI x86)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"^x86_64-\")\n\t\tset(ANDROID_ABI x86_64)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"^mipsel-linux-android-\")\n\t\tset(ANDROID_ABI mips)\n\telseif(ANDROID_TOOLCHAIN_NAME MATCHES \"^mips64el-linux-android-\")\n\t\tset(ANDROID_ABI mips64)\n\tendif()\nendif()\nif(ANDROID_NATIVE_API_LEVEL AND NOT ANDROID_PLATFORM)\n\tif(ANDROID_NATIVE_API_LEVEL MATCHES \"^android-[0-9]+$\")\n\t\tset(ANDROID_PLATFORM ${ANDROID_NATIVE_API_LEVEL})\n\telseif(ANDROID_NATIVE_API_LEVEL MATCHES \"^[0-9]+$\")\n\t\tset(ANDROID_PLATFORM android-${ANDROID_NATIVE_API_LEVEL})\n\tendif()\nendif()\nif(DEFINED ANDROID_APP_PIE AND NOT DEFINED ANDROID_PIE)\n\tset(ANDROID_PIE \"${ANDROID_APP_PIE}\")\nendif()\nif(ANDROID_STL_FORCE_FEATURES AND NOT DEFINED ANDROID_CPP_FEATURES)\n\tset(ANDROID_CPP_FEATURES \"rtti exceptions\")\nendif()\nif(DEFINED ANDROID_NO_UNDEFINED AND NOT DEFINED ANDROID_ALLOW_UNDEFINED_SYMBOLS)\n\tif(ANDROID_NO_UNDEFINED)\n\t\tset(ANDROID_ALLOW_UNDEFINED_SYMBOLS FALSE)\n\telse()\n\t\tset(ANDROID_ALLOW_UNDEFINED_SYMBOLS TRUE)\n\tendif()\nendif()\nif(DEFINED ANDROID_SO_UNDEFINED AND NOT DEFINED ANDROID_ALLOW_UNDEFINED_SYMBOLS)\n\tset(ANDROID_ALLOW_UNDEFINED_SYMBOLS \"${ANDROID_SO_UNDEFINED}\")\nendif()\nif(DEFINED ANDROID_FORCE_ARM_BUILD AND NOT ANDROID_ARM_MODE)\n\tif(ANDROID_FORCE_ARM_BUILD)\n\t\tset(ANDROID_ARM_MODE arm)\n\telse()\n\t\tset(ANDROID_ARM_MODE thumb)\n\tendif()\nendif()\nif(DEFINED ANDROID_NOEXECSTACK AND NOT DEFINED ANDROID_DISABLE_NO_EXECUTE)\n\tif(ANDROID_NOEXECSTACK)\n\t\tset(ANDROID_DISABLE_NO_EXECUTE FALSE)\n\telse()\n\t\tset(ANDROID_DISABLE_NO_EXECUTE TRUE)\n\tendif()\nendif()\nif(DEFINED ANDROID_RELRO AND NOT DEFINED ANDROID_DISABLE_RELRO)\n\tif(ANDROID_RELRO)\n\t\tset(ANDROID_DISABLE_RELRO FALSE)\n\telse()\n\t\tset(ANDROID_DISABLE_RELRO TRUE)\n\tendif()\nendif()\nif(NDK_CCACHE AND NOT ANDROID_CCACHE)\n\tset(ANDROID_CCACHE \"${NDK_CCACHE}\")\nendif()\n\n# Default values for configurable variables.\nif(NOT ANDROID_TOOLCHAIN)\n\tset(ANDROID_TOOLCHAIN clang)\nendif()\nif(NOT ANDROID_ABI)\n\tset(ANDROID_ABI armeabi-v7a)\nendif()\nif(ANDROID_PLATFORM MATCHES \"^android-([0-8]|10|11)$\")\n\tset(ANDROID_PLATFORM android-9)\nelseif(ANDROID_PLATFORM STREQUAL android-20)\n\tset(ANDROID_PLATFORM android-19)\nelseif(NOT ANDROID_PLATFORM)\n\tset(ANDROID_PLATFORM android-9)\nendif()\nstring(REPLACE \"android-\" \"\" ANDROID_PLATFORM_LEVEL ${ANDROID_PLATFORM})\nif(ANDROID_ABI MATCHES \"64(-v8a)?$\" AND ANDROID_PLATFORM_LEVEL LESS 21)\n\tset(ANDROID_PLATFORM android-21)\n\tset(ANDROID_PLATFORM_LEVEL 21)\nendif()\nif(NOT ANDROID_STL)\n\tset(ANDROID_STL gnustl_static)\nendif()\nif(NOT DEFINED ANDROID_PIE)\n\tif(ANDROID_PLATFORM_LEVEL LESS 16)\n\t\tset(ANDROID_PIE FALSE)\n\telse()\n\t\tset(ANDROID_PIE TRUE)\n\tendif()\nendif()\nif(NOT ANDROID_ARM_MODE)\n\tset(ANDROID_ARM_MODE thumb)\nendif()\n\n# Export configurable variables for the try_compile() command.\nset(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES\n\tANDROID_TOOLCHAIN\n\tANDROID_ABI\n\tANDROID_PLATFORM\n\tANDROID_STL\n\tANDROID_PIE\n\tANDROID_CPP_FEATURES\n\tANDROID_ALLOW_UNDEFINED_SYMBOLS\n\tANDROID_ARM_MODE\n\tANDROID_ARM_NEON\n\tANDROID_DISABLE_NO_EXECUTE\n\tANDROID_DISABLE_RELRO\n\tANDROID_DISABLE_FORMAT_STRING_CHECKS\n\tANDROID_CCACHE)\n\n# Standard cross-compiling stuff.\nset(ANDROID TRUE)\nset(CMAKE_SYSTEM_NAME Android)\nset(CMAKE_SYSTEM_VERSION ${ANDROID_PLATFORM_LEVEL})\nset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\nset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\nset(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\nset(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)\n\n# ABI.\nset(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI})\nif(ANDROID_ABI MATCHES \"^armeabi(-v7a)?$\")\n\tset(ANDROID_SYSROOT_ABI arm)\n\tset(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME})\n\tif(ANDROID_ABI STREQUAL armeabi)\n\t\tset(CMAKE_SYSTEM_PROCESSOR armv5te)\n\t\tset(ANDROID_LLVM_TRIPLE armv5te-none-linux-androideabi)\n\telseif(ANDROID_ABI STREQUAL armeabi-v7a)\n\t\tset(CMAKE_SYSTEM_PROCESSOR armv7-a)\n\t\tset(ANDROID_LLVM_TRIPLE armv7-none-linux-androideabi)\n\tendif()\nelseif(ANDROID_ABI STREQUAL arm64-v8a)\n\tset(ANDROID_SYSROOT_ABI arm64)\n\tset(CMAKE_SYSTEM_PROCESSOR aarch64)\n\tset(ANDROID_TOOLCHAIN_NAME aarch64-linux-android)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME})\n\tset(ANDROID_LLVM_TRIPLE aarch64-none-linux-android)\nelseif(ANDROID_ABI STREQUAL x86)\n\tset(ANDROID_SYSROOT_ABI x86)\n\tset(CMAKE_SYSTEM_PROCESSOR i686)\n\tset(ANDROID_TOOLCHAIN_NAME i686-linux-android)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI})\n\tset(ANDROID_LLVM_TRIPLE i686-none-linux-android)\nelseif(ANDROID_ABI STREQUAL x86_64)\n\tset(ANDROID_SYSROOT_ABI x86_64)\n\tset(CMAKE_SYSTEM_PROCESSOR x86_64)\n\tset(ANDROID_TOOLCHAIN_NAME x86_64-linux-android)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_ABI})\n\tset(ANDROID_LLVM_TRIPLE x86_64-none-linux-android)\nelseif(ANDROID_ABI STREQUAL mips)\n\tset(ANDROID_SYSROOT_ABI mips)\n\tset(CMAKE_SYSTEM_PROCESSOR mips)\n\tset(ANDROID_TOOLCHAIN_NAME mipsel-linux-android)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME})\n\tset(ANDROID_LLVM_TRIPLE mipsel-none-linux-android)\nelseif(ANDROID_ABI STREQUAL mips64)\n\tset(ANDROID_SYSROOT_ABI mips64)\n\tset(CMAKE_SYSTEM_PROCESSOR mips64)\n\tset(ANDROID_TOOLCHAIN_NAME mips64el-linux-android)\n\tset(ANDROID_TOOLCHAIN_ROOT ${ANDROID_TOOLCHAIN_NAME})\n\tset(ANDROID_LLVM_TRIPLE mips64el-none-linux-android)\nelse()\n\tmessage(FATAL_ERROR \"Invalid Android ABI: ${ANDROID_ABI}.\")\nendif()\n\n# STL.\nset(ANDROID_STL_STATIC_LIBRARIES)\nset(ANDROID_STL_SHARED_LIBRARIES)\nif(ANDROID_STL STREQUAL system)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tsupc++)\nelseif(ANDROID_STL STREQUAL stlport_static)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tstlport_static)\nelseif(ANDROID_STL STREQUAL stlport_shared)\n\tset(ANDROID_STL_SHARED_LIBRARIES\n\t\tstlport_shared)\nelseif(ANDROID_STL STREQUAL gnustl_static)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tgnustl_static)\nelseif(ANDROID_STL STREQUAL gnustl_shared)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tsupc++)\n\tset(ANDROID_STL_SHARED_LIBRARIES\n\t\tgnustl_shared)\nelseif(ANDROID_STL STREQUAL c++_static)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tc++_static\n\t\tc++abi\n\t\tunwind\n\t\tandroid_support)\nelseif(ANDROID_STL STREQUAL c++_shared)\n\tset(ANDROID_STL_STATIC_LIBRARIES\n\t\tunwind)\n\tset(ANDROID_STL_SHARED_LIBRARIES\n\t\tc++_shared)\nelseif(ANDROID_STL STREQUAL none)\nelse()\n\tmessage(FATAL_ERROR \"Invalid Android STL: ${ANDROID_STL}.\")\nendif()\n\n# Sysroot.\nset(CMAKE_SYSROOT \"${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_SYSROOT_ABI}\")\n\n# Toolchain.\nif(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)\n\tset(ANDROID_HOST_TAG linux-x86_64)\nelseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)\n\tset(ANDROID_HOST_TAG darwin-x86_64)\nelseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)\n\tset(ANDROID_HOST_TAG windows-x86_64)\nendif()\nset(ANDROID_TOOLCHAIN_ROOT \"${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_ROOT}-4.9/prebuilt/${ANDROID_HOST_TAG}\")\nset(ANDROID_TOOLCHAIN_PREFIX \"${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-\")\nif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)\n\tset(ANDROID_TOOLCHAIN_SUFFIX .exe)\nendif()\nif(ANDROID_TOOLCHAIN STREQUAL clang)\n\tset(ANDROID_LLVM_TOOLCHAIN_PREFIX \"${ANDROID_NDK}/toolchains/llvm-3.6/prebuilt/${ANDROID_HOST_TAG}/bin/\")\n\tset(ANDROID_C_COMPILER   \"${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang${ANDROID_TOOLCHAIN_SUFFIX}\")\n\tset(ANDROID_CXX_COMPILER \"${ANDROID_LLVM_TOOLCHAIN_PREFIX}clang++${ANDROID_TOOLCHAIN_SUFFIX}\")\n\t# Clang can fail to compile if CMake doesn't correctly supply the target and\n\t# external toolchain, but to do so, CMake needs to already know that the\n\t# compiler is clang. Tell CMake that the compiler is really clang, but don't\n\t# use CMakeForceCompiler, since we still want compile checks. We only want\n\t# to skip the compiler ID detection step.\n\tset(CMAKE_C_COMPILER_ID_RUN TRUE)\n\tset(CMAKE_CXX_COMPILER_ID_RUN TRUE)\n\tset(CMAKE_C_COMPILER_ID Clang)\n\tset(CMAKE_CXX_COMPILER_ID Clang)\n\tset(CMAKE_C_COMPILER_TARGET   ${ANDROID_LLVM_TRIPLE})\n\tset(CMAKE_CXX_COMPILER_TARGET ${ANDROID_LLVM_TRIPLE})\n\tset(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN   \"${ANDROID_TOOLCHAIN_ROOT}\")\n\tset(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN \"${ANDROID_TOOLCHAIN_ROOT}\")\nelseif(ANDROID_TOOLCHAIN STREQUAL gcc)\n\tset(ANDROID_C_COMPILER   \"${ANDROID_TOOLCHAIN_PREFIX}gcc${ANDROID_TOOLCHAIN_SUFFIX}\")\n\tset(ANDROID_CXX_COMPILER \"${ANDROID_TOOLCHAIN_PREFIX}g++${ANDROID_TOOLCHAIN_SUFFIX}\")\nelse()\n\tmessage(FATAL_ERROR \"Invalid Android toolchain: ${ANDROID_TOOLCHAIN}.\")\nendif()\n\nif(NOT IS_DIRECTORY \"${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}\")\n\tmessage(\"${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}\")\n\tmessage(FATAL_ERROR \"Invalid Android platform: ${ANDROID_PLATFORM}.\")\nelseif(NOT IS_DIRECTORY \"${CMAKE_SYSROOT}\")\n\tmessage(FATAL_ERROR \"Invalid Android sysroot: ${CMAKE_SYSROOT}.\")\nendif()\n\nset(ANDROID_COMPILER_FLAGS)\nset(ANDROID_COMPILER_FLAGS_CXX)\nset(ANDROID_COMPILER_FLAGS_DEBUG)\nset(ANDROID_COMPILER_FLAGS_RELEASE)\nset(ANDROID_LINKER_FLAGS)\nset(ANDROID_LINKER_FLAGS_EXE)\n\n# Generic flags.\nlist(APPEND ANDROID_COMPILER_FLAGS\n\t-g\n\t-DANDROID\n\t-ffunction-sections\n\t-funwind-tables\n\t-fstack-protector-strong\n\t-no-canonical-prefixes)\nlist(APPEND ANDROID_COMPILER_FLAGS_CXX\n\t-fno-exceptions\n\t-fno-rtti)\nlist(APPEND ANDROID_LINKER_FLAGS\n\t-Wl,--build-id\n\t-Wl,--warn-shared-textrel\n\t-Wl,--fatal-warnings)\nlist(APPEND ANDROID_LINKER_FLAGS_EXE\n\t-Wl,--gc-sections\n\t-Wl,-z,nocopyreloc)\n\n# Debug and release flags.\nlist(APPEND ANDROID_COMPILER_FLAGS_DEBUG\n\t-O0)\nif(ANDROID_ABI MATCHES \"^armeabi\")\n\tlist(APPEND ANDROID_COMPILER_FLAGS_RELEASE\n\t\t-Os)\nelse()\n\tlist(APPEND ANDROID_COMPILER_FLAGS_RELEASE\n\t\t-O2)\nendif()\nlist(APPEND ANDROID_COMPILER_FLAGS_RELEASE\n\t-DNDEBUG)\nif(ANDROID_TOOLCHAIN STREQUAL clang)\n\tlist(APPEND ANDROID_COMPILER_FLAGS_DEBUG\n\t\t-fno-limit-debug-info)\nendif()\n\n# Toolchain and ABI specific flags.\nif(ANDROID_ABI STREQUAL armeabi)\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-march=armv5te\n\t\t-mtune=xscale\n\t\t-msoft-float)\nendif()\nif(ANDROID_ABI STREQUAL armeabi-v7a)\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-march=armv7-a\n\t\t-mfloat-abi=softfp\n\t\t-mfpu=vfpv3-d16)\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,--fix-cortex-a8)\nendif()\nif(ANDROID_ABI MATCHES \"^armeabi\" AND ANDROID_TOOLCHAIN STREQUAL clang)\n\t# Disable integrated-as for better compatibility.\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-fno-integrated-as)\nendif()\nif(ANDROID_ABI STREQUAL mips AND ANDROID_TOOLCHAIN STREQUAL clang)\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-mips32)\nendif()\n\n# STL specific flags.\nif(ANDROID_STL STREQUAL system)\n\tset(ANDROID_STL_PREFIX gnu-libstdc++/4.9)\n\tset(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/system/include\")\nelseif(ANDROID_STL MATCHES \"^stlport_\")\n\tset(ANDROID_STL_PREFIX stlport)\n\tset(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/stlport\"\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/gabi++/include\")\nelseif(ANDROID_STL MATCHES \"^gnustl_\")\n\tset(ANDROID_STL_PREFIX gnu-libstdc++/4.9)\n\tset(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include\"\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/include\"\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include/backward\")\nelseif(ANDROID_STL MATCHES \"^c\\\\+\\\\+_\")\n\tset(ANDROID_STL_PREFIX llvm-libc++)\n\tif(ANDROID_ABI MATCHES \"^armeabi\")\n\t\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t\t-Wl,--exclude-libs,libunwind.a)\n\telse()\n\t\tlist(REMOVE_ITEM ANDROID_STL_STATIC_LIBRARIES\n\t\t\tunwind)\n\tendif()\n\tlist(APPEND ANDROID_COMPILER_FLAGS_CXX\n\t\t-std=c++11)\n\tif(ANDROID_TOOLCHAIN STREQUAL gcc)\n\t\tlist(APPEND ANDROID_COMPILER_FLAGS_CXX\n\t\t\t-fno-strict-aliasing)\n\tendif()\n\tset(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/include\"\n\t\t\"${ANDROID_NDK}/sources/android/support/include\"\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}abi/include\")\nendif()\nset(ANDROID_CXX_STANDARD_LIBRARIES)\nforeach(library ${ANDROID_STL_STATIC_LIBRARIES})\n\tlist(APPEND ANDROID_CXX_STANDARD_LIBRARIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${library}.a\")\nendforeach()\nforeach(library ${ANDROID_STL_SHARED_LIBRARIES})\n\tlist(APPEND ANDROID_CXX_STANDARD_LIBRARIES\n\t\t\"${ANDROID_NDK}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${library}.so\")\nendforeach()\nif(ANDROID_ABI STREQUAL armeabi AND NOT ANDROID_STL MATCHES \"^(none|system)$\")\n\tlist(APPEND ANDROID_CXX_STANDARD_LIBRARIES\n\t\t-latomic)\nendif()\nset(CMAKE_C_STANDARD_LIBRARIES_INIT \"-lm\")\nset(CMAKE_CXX_STANDARD_LIBRARIES_INIT \"${CMAKE_C_STANDARD_LIBRARIES_INIT}\")\nif(ANDROID_CXX_STANDARD_LIBRARIES)\n\tstring(REPLACE \";\" \"\\\" \\\"\" ANDROID_CXX_STANDARD_LIBRARIES \"\\\"${ANDROID_CXX_STANDARD_LIBRARIES}\\\"\")\n\tset(CMAKE_CXX_STANDARD_LIBRARIES_INIT \"${CMAKE_CXX_STANDARD_LIBRARIES_INIT} ${ANDROID_CXX_STANDARD_LIBRARIES}\")\nendif()\n\n# Configuration specific flags.\nif(ANDROID_PIE)\n\tset(CMAKE_POSITION_INDEPENDENT_CODE TRUE)\n\tlist(APPEND ANDROID_LINKER_FLAGS_EXE\n\t\t-pie\n\t\t-fPIE)\nendif()\nif(ANDROID_CPP_FEATURES)\n\tseparate_arguments(ANDROID_CPP_FEATURES)\n\tforeach(feature ${ANDROID_CPP_FEATURES})\n\t\tif(NOT ${feature} MATCHES \"^(rtti|exceptions)$\")\n\t\t\tmessage(FATAL_ERROR \"Invalid Android C++ feature: ${feature}.\")\n\t\tendif()\n\t\tlist(APPEND ANDROID_COMPILER_FLAGS_CXX\n\t\t\t-f${feature})\n\tendforeach()\n\tstring(REPLACE \";\" \" \" ANDROID_CPP_FEATURES \"${ANDROID_CPP_FEATURES}\")\nendif()\nif(NOT ANDROID_ALLOW_UNDEFINED_SYMBOLS)\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,--no-undefined)\nendif()\nif(ANDROID_ABI MATCHES \"armeabi\")\n\tif(ANDROID_ARM_MODE STREQUAL thumb)\n\t\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t\t-mthumb)\n\telseif(ANDROID_ARM_MODE STREQUAL arm)\n\t\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t\t-marm)\n\telse()\n\t\tmessage(FATAL_ERROR \"Invalid Android ARM mode: ${ANDROID_ARM_MODE}.\")\n\tendif()\n\tif(ANDROID_ABI STREQUAL armeabi-v7a AND ANDROID_ARM_NEON)\n\t\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t\t-mfpu=neon)\n\tendif()\nendif()\nif(ANDROID_DISABLE_NO_EXECUTE)\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-Wa,--execstack)\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,-z,execstack)\nelse()\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-Wa,--noexecstack)\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,-z,noexecstack)\nendif()\nif(ANDROID_TOOLCHAIN STREQUAL clang)\n\t# CMake automatically forwards all compiler flags to the linker,\n\t# and clang doesn't like having -Wa flags being used for linking.\n\t# To prevent CMake from doing this would require meddling with\n\t# the CMAKE_<LANG>_COMPILE_OBJECT rules, which would get quite messy.\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Qunused-arguments)\nendif()\nif(ANDROID_DISABLE_RELRO)\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,-z,norelro -Wl,-z,lazy)\nelse()\n\tlist(APPEND ANDROID_LINKER_FLAGS\n\t\t-Wl,-z,relro -Wl,-z,now)\nendif()\nif(ANDROID_DISABLE_FORMAT_STRING_CHECKS)\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-Wno-error=format-security)\nelse()\n\tlist(APPEND ANDROID_COMPILER_FLAGS\n\t\t-Wformat -Werror=format-security)\nendif()\n\n# Convert these lists into strings.\nstring(REPLACE \";\" \" \" ANDROID_COMPILER_FLAGS         \"${ANDROID_COMPILER_FLAGS}\")\nstring(REPLACE \";\" \" \" ANDROID_COMPILER_FLAGS_CXX     \"${ANDROID_COMPILER_FLAGS_CXX}\")\nstring(REPLACE \";\" \" \" ANDROID_COMPILER_FLAGS_DEBUG   \"${ANDROID_COMPILER_FLAGS_DEBUG}\")\nstring(REPLACE \";\" \" \" ANDROID_COMPILER_FLAGS_RELEASE \"${ANDROID_COMPILER_FLAGS_RELEASE}\")\nstring(REPLACE \";\" \" \" ANDROID_LINKER_FLAGS           \"${ANDROID_LINKER_FLAGS}\")\nstring(REPLACE \";\" \" \" ANDROID_LINKER_FLAGS_EXE       \"${ANDROID_LINKER_FLAGS_EXE}\")\n\nif(ANDROID_CCACHE)\n\tset(CMAKE_C_COMPILER_LAUNCHER   \"${ANDROID_CCACHE}\")\n\tset(CMAKE_CXX_COMPILER_LAUNCHER \"${ANDROID_CCACHE}\")\nendif()\nset(CMAKE_C_COMPILER        \"${ANDROID_C_COMPILER}\")\nset(CMAKE_CXX_COMPILER      \"${ANDROID_CXX_COMPILER}\")\nset(_CMAKE_TOOLCHAIN_PREFIX \"${ANDROID_TOOLCHAIN_PREFIX}\")\n\n# Set or retrieve the cached flags.\n# This is necessary in case the user sets/changes flags in subsequent\n# configures. If we included the Android flags in here, they would get\n# overwritten.\nset(CMAKE_C_FLAGS \"\"\n\tCACHE STRING \"Flags used by the compiler during all build types.\")\nset(CMAKE_CXX_FLAGS \"\"\n\tCACHE STRING \"Flags used by the compiler during all build types.\")\nset(CMAKE_C_FLAGS_DEBUG \"\"\n\tCACHE STRING \"Flags used by the compiler during debug builds.\")\nset(CMAKE_CXX_FLAGS_DEBUG \"\"\n\tCACHE STRING \"Flags used by the compiler during debug builds.\")\nset(CMAKE_C_FLAGS_RELEASE \"\"\n\tCACHE STRING \"Flags used by the compiler during release builds.\")\nset(CMAKE_CXX_FLAGS_RELEASE \"\"\n\tCACHE STRING \"Flags used by the compiler during release builds.\")\nset(CMAKE_MODULE_LINKER_FLAGS \"\"\n\tCACHE STRING \"Flags used by the linker during the creation of modules.\")\nset(CMAKE_SHARED_LINKER_FLAGS \"\"\n\tCACHE STRING \"Flags used by the linker during the creation of dll's.\")\nset(CMAKE_EXE_LINKER_FLAGS \"\"\n\tCACHE STRING \"Flags used by the linker.\")\n\nset(CMAKE_C_FLAGS             \"${ANDROID_COMPILER_FLAGS} ${CMAKE_C_FLAGS}\")\nset(CMAKE_CXX_FLAGS           \"${ANDROID_COMPILER_FLAGS} ${ANDROID_COMPILER_FLAGS_CXX} ${CMAKE_CXX_FLAGS}\")\nset(CMAKE_C_FLAGS_DEBUG       \"${ANDROID_COMPILER_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}\")\nset(CMAKE_CXX_FLAGS_DEBUG     \"${ANDROID_COMPILER_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}\")\nset(CMAKE_C_FLAGS_RELEASE     \"${ANDROID_COMPILER_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}\")\nset(CMAKE_CXX_FLAGS_RELEASE   \"${ANDROID_COMPILER_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}\")\nset(CMAKE_SHARED_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}\")\nset(CMAKE_MODULE_LINKER_FLAGS \"${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}\")\nset(CMAKE_EXE_LINKER_FLAGS    \"${ANDROID_LINKER_FLAGS} ${ANDROID_LINKER_FLAGS_EXE} ${CMAKE_EXE_LINKER_FLAGS}\")\n\nif(CMAKE_C_FLAGS)\n\tmessage(\"CMAKE_C_FLAGS = ${CMAKE_C_FlAGS}\")\nendif()\nif(CMAKE_CXX_FLAGS)\n\tmessage(\"CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}\")\nendif()\nif(CMAKE_C_FLAGS_DEBUG)\n\tmessage(\"CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}\")\nendif()\nif(CMAKE_CXX_FLAGS_DEBUG)\n\tmessage(\"CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}\")\nendif()\nif(CMAKE_SHARED_LINKER_FLAGS)\n\tmessage(\"CMAKE_SHARED_LINKDER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}\")\nendif()\nif(CMAKE_MODULE_LINKER_FLAGS)\n\tmessage(\"CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}\")\nendif()\nif(CMAKE_EXE_LINKER_FLAGS)\n\tmessage(\"CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}\")\nendif()\n\n# Compatibility for read-only variables.\n# Read-only variables for compatibility with the other toolchain file.\n# We'll keep these around for the existing projects that still use them.\n# TODO: All of the variables here have equivalents in our standard set of\n# configurable variables, so we can remove these once most of our users migrate\n# to those variables.\nset(ANDROID_NATIVE_API_LEVEL ${ANDROID_PLATFORM_LEVEL})\nif(ANDROID_ALLOW_UNDEFINED_SYMBOLS)\n\tset(ANDROID_SO_UNDEFINED TRUE)\nelse()\n\tset(ANDROID_NO_UNDEFINED TRUE)\nendif()\nset(ANDROID_FUNCTION_LEVEL_LINKING TRUE)\nset(ANDROID_GOLD_LINKER TRUE)\nif(NOT ANDROID_DISABLE_NO_EXECUTE)\n\tset(ANDROID_NOEXECSTACK TRUE)\nendif()\nif(NOT ANDROID_DISABLE_RELRO)\n\tset(ANDROID_RELRO TRUE)\nendif()\nif(ANDROID_ARM_MODE STREQUAL arm)\n\tset(ANDROID_FORCE_ARM_BUILD TRUE)\nendif()\nif(ANDROID_CPP_FEATURES MATCHES \"rtti\"\n\t\tAND ANDROID_CPP_FEATURES MATCHES \"exceptions\")\n\tset(ANDROID_STL_FORCE_FEATURES TRUE)\nendif()\nif(ANDROID_CCACHE)\n\tset(NDK_CCACHE \"${ANDROID_CCACHE}\")\nendif()\nif(ANDROID_TOOLCHAIN STREQUAL clang)\n\tset(ANDROID_TOOLCHAIN_NAME ${ANDROID_TOOLCHAIN_NAME}-clang)\nelse()\n\tset(ANDROID_TOOLCHAIN_NAME ${ANDROID_TOOLCHAIN_NAME}-4.9)\nendif()\nset(ANDROID_NDK_HOST_X64 TRUE)\nset(ANDROID_NDK_LAYOUT RELEASE)\nif(ANDROID_ABI STREQUAL armeabi)\n\tset(ARMEABI TRUE)\nelseif(ANDROID_ABI STREQUAL armeabi-v7a)\n\tset(ARMEABI_V7A TRUE)\n\tif(ANDROID_ARM_NEON)\n\t\tset(NEON TRUE)\n\tendif()\nelseif(ANDROID_ABI STREQUAL arm64-v8a)\n\tset(ARM64_V8A TRUE)\nelseif(ANDROID_ABI STREQUAL x86)\n\tset(X86 TRUE)\nelseif(ANDROID_ABI STREQUAL x86_64)\n\tset(X86_64 TRUE)\nelseif(ANDROID_ABI STREQUAL mips)\n\tset(MIPS TRUE)\nelseif(ANDROID_ABI STREQUAL MIPS64)\n\tset(MIPS64 TRUE)\nendif()\nset(ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_HOST_TAG})\nset(ANDROID_NDK_ABI_NAME ${ANDROID_ABI})\nset(ANDROID_ARCH_NAME ${ANDROID_SYSROOT_ABI})\nset(ANDROID_SYSROOT \"${CMAKE_SYSROOT}\")\nset(TOOL_OS_SUFFIX ${ANDROID_TOOLCHAIN_SUFFIX})\nif(ANDROID_TOOLCHAIN STREQUAL clang)\n\tset(ANDROID_COMPILER_IS_CLANG TRUE)\nendif()\n"
  },
  {
    "path": "build/cmake/iOS.cmake",
    "content": "# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake\n# files which are included with CMake 2.8.4\n# It has been altered for iOS development\n\n# Options:\n#\n# IOS_PLATFORM = OS (default) or SIMULATOR\n#   This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders\n#   OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.\n#   SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.\n#\n# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder\n#   By default this location is automatcially chosen based on the IOS_PLATFORM value above.\n#   If set manually, it will override the default location and force the user of a particular Developer Platform\n#\n# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder\n#   By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.\n#   In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.\n#   If set manually, this will force the use of a specific SDK version\n\n# Macros:\n#\n# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)\n#  A convenience macro for setting xcode specific properties on targets\n#  example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET \"3.1\")\n#\n# find_host_package (PROGRAM ARGS)\n#  A macro used to find executable programs on the host system, not within the iOS environment.\n#  Thanks to the android-cmake project for providing the command\n\n# Standard settings\nset (CMAKE_SYSTEM_NAME Darwin)\nset (CMAKE_SYSTEM_VERSION 1)\nset (UNIX True)\nset (APPLE True)\nset (IOS True)\n\n# Required as of cmake 2.8.10\nset (CMAKE_OSX_DEPLOYMENT_TARGET \"\" CACHE STRING \"Force unset of the deployment target for iOS\" FORCE)\n\n# Determine the cmake host system version so we know where to find the iOS SDKs\nfind_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)\nif (CMAKE_UNAME)\n\texec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)\n\tstring (REGEX REPLACE \"^([0-9]+)\\\\.([0-9]+).*$\" \"\\\\1\" DARWIN_MAJOR_VERSION \"${CMAKE_HOST_SYSTEM_VERSION}\")\nendif (CMAKE_UNAME)\n\n# Force the compilers to gcc for iOS\n#include (CMakeForceCompiler)\n#CMAKE_FORCE_C_COMPILER (/usr/bin/clang Apple)\n#CMAKE_FORCE_CXX_COMPILER (/usr/bin/clang++ Apple)\n#set(CMAKE_AR ar CACHE FILEPATH \"\" FORCE)\n\n# Skip the platform compiler checks for cross compiling\nset (CMAKE_CXX_COMPILER_WORKS TRUE)\nset (CMAKE_C_COMPILER_WORKS TRUE)\n\n# All iOS/Darwin specific settings - some may be redundant\nset (CMAKE_SHARED_LIBRARY_PREFIX \"lib\")\nset (CMAKE_SHARED_LIBRARY_SUFFIX \".dylib\")\nset (CMAKE_SHARED_MODULE_PREFIX \"lib\")\nset (CMAKE_SHARED_MODULE_SUFFIX \".so\")\nset (CMAKE_MODULE_EXISTS 1)\nset (CMAKE_DL_LIBS \"\")\n\nset (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG \"-compatibility_version \")\nset (CMAKE_C_OSX_CURRENT_VERSION_FLAG \"-current_version \")\nset (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG \"${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}\")\nset (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG \"${CMAKE_C_OSX_CURRENT_VERSION_FLAG}\")\n\n# Hidden visibilty is required for cxx on iOS \nset (CMAKE_C_FLAGS_INIT \"\")\nset (CMAKE_CXX_FLAGS_INIT \"-fvisibility=hidden -fvisibility-inlines-hidden -isysroot ${CMAKE_OSX_SYSROOT}\")\n\nset (CMAKE_C_LINK_FLAGS \"-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}\")\nset (CMAKE_CXX_LINK_FLAGS \"-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}\")\n\nset (CMAKE_PLATFORM_HAS_INSTALLNAME 1)\nset (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS \"-dynamiclib -headerpad_max_install_names\")\nset (CMAKE_SHARED_MODULE_CREATE_C_FLAGS \"-bundle -headerpad_max_install_names\")\nset (CMAKE_SHARED_MODULE_LOADER_C_FLAG \"-Wl,-bundle_loader,\")\nset (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG \"-Wl,-bundle_loader,\")\nset (CMAKE_FIND_LIBRARY_SUFFIXES \".dylib\" \".so\" \".a\")\n\n# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree\n# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache\n# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)\n# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex\nif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)\n\tfind_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)\nendif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)\n\n# Setup iOS platform unless specified manually with IOS_PLATFORM\nif (NOT DEFINED IOS_PLATFORM)\n\tset (IOS_PLATFORM \"OS\")\nendif (NOT DEFINED IOS_PLATFORM)\nset (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING \"Type of iOS Platform\")\n\n# Check the platform selection and setup for developer root\nif (${IOS_PLATFORM} STREQUAL \"OS\")\n\tset (IOS_PLATFORM_LOCATION \"iPhoneOS.platform\")\n\n\t# This causes the installers to properly locate the output libraries\n\tset (CMAKE_XCODE_EFFECTIVE_PLATFORMS \"-iphoneos\")\nelseif (${IOS_PLATFORM} STREQUAL \"SIMULATOR\")\n\tset (IOS_PLATFORM_LOCATION \"iPhoneSimulator.platform\")\n\n\t# This causes the installers to properly locate the output libraries\n\tset (CMAKE_XCODE_EFFECTIVE_PLATFORMS \"-iphonesimulator\")\nelse (${IOS_PLATFORM} STREQUAL \"OS\")\n\tmessage (FATAL_ERROR \"Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR\")\nendif (${IOS_PLATFORM} STREQUAL \"OS\")\n\n# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT\n# Note Xcode 4.3 changed the installation location, choose the most recent one available\nset (XCODE_POST_43_ROOT \"/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer\")\nset (XCODE_PRE_43_ROOT \"/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer\")\nif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)\n\tif (EXISTS ${XCODE_POST_43_ROOT})\n\t\tset (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})\n\telseif(EXISTS ${XCODE_PRE_43_ROOT})\n\t\tset (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})\n\tendif (EXISTS ${XCODE_POST_43_ROOT})\nendif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)\nset (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH \"Location of iOS Platform\")\n\n# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT\nif (NOT DEFINED CMAKE_IOS_SDK_ROOT)\n\tfile (GLOB _CMAKE_IOS_SDKS \"${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*\")\n\tif (_CMAKE_IOS_SDKS) \n\t\tlist (SORT _CMAKE_IOS_SDKS)\n\t\tlist (REVERSE _CMAKE_IOS_SDKS)\n\t\tlist (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)\n\telse (_CMAKE_IOS_SDKS)\n\t\tmessage (FATAL_ERROR \"No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.\")\n\tendif (_CMAKE_IOS_SDKS)\n\tmessage (STATUS \"Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}\")\nendif (NOT DEFINED CMAKE_IOS_SDK_ROOT)\nset (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH \"Location of the selected iOS SDK\")\n\n# Set the sysroot default to the most recent SDK\nset (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH \"Sysroot used for iOS support\")\n\n# set the architecture for iOS \n# NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually\nif (${IOS_PLATFORM} STREQUAL \"OS\")\n\tset (IOS_ARCH armv7)\nelse (${IOS_PLATFORM} STREQUAL \"OS\")\n\tset (IOS_ARCH i386)\nendif (${IOS_PLATFORM} STREQUAL \"OS\")\n\nset (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string  \"Build architecture for iOS\")\n\n# Set the find root to the iOS developer roots and to user defined paths\nset (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string  \"iOS find search path root\")\n\n# default to searching for frameworks first\nset (CMAKE_FIND_FRAMEWORK FIRST)\n\n# set up the default search directories for frameworks\nset (CMAKE_SYSTEM_FRAMEWORK_PATH\n\t${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks\n\t${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks\n\t${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks\n)\n\n# only search the iOS sdks, not the remainder of the host filesystem\n#set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)\n#set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n#set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n\n\n# This little macro lets you set any XCode specific property\nmacro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)\n\tset_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})\nendmacro (set_xcode_property)\n\n\n# This macro lets you find executable programs on the host system\nmacro (find_host_package)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)\n\tset (IOS FALSE)\n\n\tfind_package(${ARGN})\n\n\tset (IOS TRUE)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n\tset (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\nendmacro (find_host_package)\n\nmacro(ADD_FRAMEWORK fwname frameworks)\n    find_library(FRAMEWORK_${fwname}\n        NAMES ${fwname}\n        )\n    if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)\n        MESSAGE(ERROR \": Framework ${fwname} not found\")\n    else()\n        list(APPEND ${frameworks} ${FRAMEWORK_${fwname}})\n        MESSAGE(STATUS \"Framework ${fwname} found at ${FRAMEWORK_${fwname}}\")\n    endif()\nendmacro(ADD_FRAMEWORK)\n\n# http://stackoverflow.com/questions/14171740/cmake-with-ios-toolchain-cant-find-threads\n# http://public.kitware.com/Bug/view.php?id=12288\n# Fix for try_compile\nSET(CMAKE_MACOSX_BUNDLE YES)\nSET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY \"iPhone Developer\")\nSET(MACOSX_BUNDLE_GUI_IDENTIFIER \"org.racing\")\n# http://stackoverflow.com/questions/11198878/how-do-you-specify-a-universal-ios-application-when-building-through-cmake\nSET(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY \"1,2\")\n"
  },
  {
    "path": "build/cmake/ios.toolchain.cmake",
    "content": "# This file is part of the ios-cmake project. It was retrieved from\n# https://github.com/cristeab/ios-cmake.git, which is a fork of\n# https://code.google.com/p/ios-cmake/. Which in turn is based off of\n# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which\n# are included with CMake 2.8.4\n#\n# The ios-cmake project is licensed under the new BSD license.\n#\n# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software,\n# Kitware, Inc., Insight Software Consortium.  All rights reserved.\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n# 1. Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n#\n# 2. Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n#\n# 3. Neither the name of the copyright holder nor the names of its\n# contributors may be used to endorse or promote products derived from\n# this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\n# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\n# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n# POSSIBILITY OF SUCH DAMAGE.\n#\n# This file is based off of the Platform/Darwin.cmake and\n# Platform/UnixPaths.cmake files which are included with CMake 2.8.4\n# It has been altered for iOS development.\n#\n# Updated by Alex Stewart (alexs.mac@gmail.com)\n#\n# *****************************************************************************\n#      Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com)\n#                      under the BSD-3-Clause license\n#                   https://github.com/leetal/ios-cmake\n# *****************************************************************************\n#\n#                           INFORMATION / HELP\n#\n# The following arguments control the behaviour of this toolchain:\n#\n# PLATFORM: (default \"OS\")\n#    OS = Build for iPhoneOS.\n#    OS64 = Build for arm64 iphoneOS.\n#    OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith \"-G Xcode\" argument ONLY)\n#    SIMULATOR = Build for x86 i386 iphoneOS Simulator.\n#    SIMULATOR64 = Build for x86_64 iphoneOS Simulator.\n#    TVOS = Build for arm64 tvOS.\n#    TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with \"-G Xcode\" argument ONLY)\n#    SIMULATOR_TVOS = Build for x86_64 tvOS Simulator.\n#    WATCHOS = Build for armv7k arm64_32 for watchOS.\n#    WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with \"-G Xcode\" argument ONLY)\n#    SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator.\n#\n# CMAKE_OSX_SYSROOT: Path to the SDK to use.  By default this is\n#    automatically determined from PLATFORM and xcodebuild, but\n#    can also be manually specified (although this should not be required).\n#\n# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform\n#    being compiled for.  By default this is automatically determined from\n#    CMAKE_OSX_SYSROOT, but can also be manually specified (although this should\n#    not be required).\n#\n# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS\n#\n# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true)\n#\n# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default)\n#\n# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default)\n#\n# ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker\n#    to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY)\n#\n# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM\n#    OS = armv7 armv7s arm64 (if applicable)\n#    OS64 = arm64 (if applicable)\n#    SIMULATOR = i386\n#    SIMULATOR64 = x86_64\n#    TVOS = arm64\n#    SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated)\n#    WATCHOS = armv7k arm64_32 (if applicable)\n#    SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated)\n#\n# This toolchain defines the following variables for use externally:\n#\n# XCODE_VERSION: Version number (not including Build version) of Xcode detected.\n# SDK_VERSION: Version of SDK being used.\n# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM).\n#\n# This toolchain defines the following macros for use externally:\n#\n# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT)\n#   A convenience macro for setting xcode specific properties on targets.\n#   Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel\n#   example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET \"3.1\" \"all\").\n#\n# find_host_package (PROGRAM ARGS)\n#   A macro used to find executable programs on the host system, not within the\n#   environment.  Thanks to the android-cmake project for providing the\n#   command.\n#\n# ******************************** DEPRECATIONS *******************************\n#\n# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET\n# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT\n# IOS_PLATFORM: (Deprecated) Alias to PLATFORM\n# IOS_ARCH: (Deprecated) Alias to ARCHS\n#\n# *****************************************************************************\n#\n\n# Fix for PThread library not in path\nset(CMAKE_THREAD_LIBS_INIT \"-lpthread\")\nset(CMAKE_HAVE_THREADS_LIBRARY 1)\nset(CMAKE_USE_WIN32_THREADS_INIT 0)\nset(CMAKE_USE_PTHREADS_INIT 1)\n\n# Cache what generator is used\nset(USED_CMAKE_GENERATOR \"${CMAKE_GENERATOR}\" CACHE STRING \"Expose CMAKE_GENERATOR\" FORCE)\n\nif(${CMAKE_VERSION} VERSION_GREATER_EQUAL \"3.14\")\n  set(MODERN_CMAKE YES)\n  message(STATUS \"Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!\")\nendif()\n\n# Get the Xcode version being used.\nexecute_process(COMMAND xcodebuild -version\n  OUTPUT_VARIABLE XCODE_VERSION\n  ERROR_QUIET\n  OUTPUT_STRIP_TRAILING_WHITESPACE)\nstring(REGEX MATCH \"Xcode [0-9\\\\.]+\" XCODE_VERSION \"${XCODE_VERSION}\")\nstring(REGEX REPLACE \"Xcode ([0-9\\\\.]+)\" \"\\\\1\" XCODE_VERSION \"${XCODE_VERSION}\")\nmessage(STATUS \"Building with Xcode version: ${XCODE_VERSION}\")\n\n######## ALIASES (DEPRECATION WARNINGS)\n\nif(DEFINED IOS_PLATFORM)\n  set(PLATFORM ${IOS_PLATFORM})\n  message(DEPRECATION \"IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.\")\nendif()\n\nif(DEFINED IOS_DEPLOYMENT_TARGET)\n  set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET})\n  message(DEPRECATION \"IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.\")\nendif()\n\nif(DEFINED CMAKE_IOS_DEVELOPER_ROOT)\n  set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT})\n  message(DEPRECATION \"CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.\")\nendif()\n\nif(DEFINED IOS_ARCH)\n  set(ARCHS ${IOS_ARCH})\n  message(DEPRECATION \"IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.\")\nendif()\n\n######## END ALIASES\n\n# Unset the FORCE on cache variables if in try_compile()\nset(FORCE_CACHE FORCE)\nget_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)\nif(_CMAKE_IN_TRY_COMPILE)\n  unset(FORCE_CACHE)\nendif()\n\n# Default to building for iPhoneOS if not specified otherwise, and we cannot\n# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use\n# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly\n# determine the value of PLATFORM from the root project, as\n# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.\nif(NOT DEFINED PLATFORM)\n  if (CMAKE_OSX_ARCHITECTURES)\n    if(CMAKE_OSX_ARCHITECTURES MATCHES \".*arm.*\" AND CMAKE_OSX_SYSROOT MATCHES \".*iphoneos.*\")\n      set(PLATFORM \"OS\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \"i386\" AND CMAKE_OSX_SYSROOT MATCHES \".*iphonesimulator.*\")\n      set(PLATFORM \"SIMULATOR\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \"x86_64\" AND CMAKE_OSX_SYSROOT MATCHES \".*iphonesimulator.*\")\n      set(PLATFORM \"SIMULATOR64\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \"arm64\" AND CMAKE_OSX_SYSROOT MATCHES \".*appletvos.*\")\n      set(PLATFORM \"TVOS\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \"x86_64\" AND CMAKE_OSX_SYSROOT MATCHES \".*appletvsimulator.*\")\n      set(PLATFORM \"SIMULATOR_TVOS\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \".*armv7k.*\" AND CMAKE_OSX_SYSROOT MATCHES \".*watchos.*\")\n      set(PLATFORM \"WATCHOS\")\n    elseif(CMAKE_OSX_ARCHITECTURES MATCHES \"i386\" AND CMAKE_OSX_SYSROOT MATCHES \".*watchsimulator.*\")\n      set(PLATFORM \"SIMULATOR_WATCHOS\")\n    endif()\n  endif()\n  if (NOT PLATFORM)\n    set(PLATFORM \"OS\")\n  endif()\nendif()\n\nset(PLATFORM_INT \"${PLATFORM}\" CACHE STRING \"Type of platform for which the build targets.\")\n\n# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially)\nif(PLATFORM_INT STREQUAL \"OS\" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)\n  set(PLATFORM_INT \"OS64\")\n  message(STATUS \"Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.\")\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR\" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)\n  set(PLATFORM_INT \"SIMULATOR64\")\n  message(STATUS \"Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.\")\nendif()\n\n# Determine the platform name and architectures for use in xcodebuild commands\n# from the specified PLATFORM name.\nif(PLATFORM_INT STREQUAL \"OS\")\n  set(SDK_NAME iphoneos)\n  if(NOT ARCHS)\n    set(ARCHS armv7 armv7s arm64)\n  endif()\nelseif(PLATFORM_INT STREQUAL \"OS64\")\n  set(SDK_NAME iphoneos)\n  if(NOT ARCHS)\n    if (XCODE_VERSION VERSION_GREATER 10.0)\n      set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example\n    else()\n      set(ARCHS arm64)\n    endif()\n  endif()\nelseif(PLATFORM_INT STREQUAL \"OS64COMBINED\")\n  set(SDK_NAME iphoneos)\n  if(MODERN_CMAKE)\n    if(NOT ARCHS)\n      if (XCODE_VERSION VERSION_GREATER 10.0)\n        set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example\n      else()\n        set(ARCHS arm64 x86_64)\n      endif()\n    endif()\n  else()\n    message(FATAL_ERROR \"Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work\")\n  endif()\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR\")\n  set(SDK_NAME iphonesimulator)\n  if(NOT ARCHS)\n    set(ARCHS i386)\n  endif()\n  message(DEPRECATION \"SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.\")\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR64\")\n  set(SDK_NAME iphonesimulator)\n  if(NOT ARCHS)\n    set(ARCHS x86_64)\n  endif()\nelseif(PLATFORM_INT STREQUAL \"TVOS\")\n  set(SDK_NAME appletvos)\n  if(NOT ARCHS)\n    set(ARCHS arm64)\n  endif()\nelseif (PLATFORM_INT STREQUAL \"TVOSCOMBINED\")\n  set(SDK_NAME appletvos)\n  if(MODERN_CMAKE)\n    if(NOT ARCHS)\n      set(ARCHS arm64 x86_64)\n    endif()\n  else()\n    message(FATAL_ERROR \"Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work\")\n  endif()\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR_TVOS\")\n  set(SDK_NAME appletvsimulator)\n  if(NOT ARCHS)\n    set(ARCHS x86_64)\n  endif()\nelseif(PLATFORM_INT STREQUAL \"WATCHOS\")\n  set(SDK_NAME watchos)\n  if(NOT ARCHS)\n    if (XCODE_VERSION VERSION_GREATER 10.0)\n      set(ARCHS armv7k arm64_32)\n    else()\n      set(ARCHS armv7k)\n    endif()\n  endif()\nelseif(PLATFORM_INT STREQUAL \"WATCHOSCOMBINED\")\n  set(SDK_NAME watchos)\n  if(MODERN_CMAKE)\n    if(NOT ARCHS)\n      if (XCODE_VERSION VERSION_GREATER 10.0)\n        set(ARCHS armv7k arm64_32 i386)\n      else()\n        set(ARCHS armv7k i386)\n      endif()\n    endif()\n  else()\n    message(FATAL_ERROR \"Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work\")\n  endif()\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR_WATCHOS\")\n  set(SDK_NAME watchsimulator)\n  if(NOT ARCHS)\n    set(ARCHS i386)\n  endif()\nelse()\n  message(FATAL_ERROR \"Invalid PLATFORM: ${PLATFORM_INT}\")\nendif()\nmessage(STATUS \"Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}\")\n\nif(MODERN_CMAKE AND PLATFORM_INT MATCHES \".*COMBINED\" AND NOT USED_CMAKE_GENERATOR MATCHES \"Xcode\")\n  message(FATAL_ERROR \"The COMBINED options only work with Xcode generator, -G Xcode\")\nendif()\n\n# If user did not specify the SDK root to use, then query xcodebuild for it.\nexecute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path\n    OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT\n    ERROR_QUIET\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\nif (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT)\n  message(SEND_ERROR \"Please make sure that Xcode is installed and that the toolchain\"\n  \"is pointing to the correct path. Please run:\"\n  \"sudo xcode-select -s /Applications/Xcode.app/Contents/Developer\"\n  \"and see if that fixes the problem for you.\")\n  message(FATAL_ERROR \"Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} \"\n  \"does not exist.\")\nelseif(DEFINED CMAKE_OSX_SYSROOT)\n  message(STATUS \"Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} when checking compatibility\")\nelseif(DEFINED CMAKE_OSX_SYSROOT_INT)\n   message(STATUS \"Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT}\")\n   set(CMAKE_OSX_SYSROOT \"${CMAKE_OSX_SYSROOT_INT}\" CACHE INTERNAL \"\")\nendif()\n\n# Set Xcode property for SDKROOT as well if Xcode generator is used\nif(USED_CMAKE_GENERATOR MATCHES \"Xcode\")\n  set(CMAKE_OSX_SYSROOT \"${SDK_NAME}\" CACHE INTERNAL \"\")\n  if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)\n    set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM 123456789A CACHE INTERNAL \"\")\n  endif()\nendif()\n\n# Specify minimum version of deployment target.\nif(NOT DEFINED DEPLOYMENT_TARGET)\n  if (PLATFORM_INT STREQUAL \"WATCHOS\" OR PLATFORM_INT STREQUAL \"SIMULATOR_WATCHOS\")\n    # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS).\n    set(DEPLOYMENT_TARGET \"2.0\"\n            CACHE STRING \"Minimum SDK version to build for.\" )\n  else()\n    # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS).\n    set(DEPLOYMENT_TARGET \"9.0\"\n            CACHE STRING \"Minimum SDK version to build for.\" )\n  endif()\n  message(STATUS \"Using the default min-version since DEPLOYMENT_TARGET not provided!\")\nendif()\n# Use bitcode or not\nif(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES \"((^|;|, )(i386|x86_64))+\")\n  # Unless specified, enable bitcode support by default\n  message(STATUS \"Enabling bitcode support by default. ENABLE_BITCODE not provided!\")\n  set(ENABLE_BITCODE TRUE)\nelseif(NOT DEFINED ENABLE_BITCODE)\n  message(STATUS \"Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!\")\n  set(ENABLE_BITCODE FALSE)\nendif()\nset(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL \"Whether or not to enable bitcode\" ${FORCE_CACHE})\n# Use ARC or not\nif(NOT DEFINED ENABLE_ARC)\n  # Unless specified, enable ARC support by default\n  set(ENABLE_ARC TRUE)\n  message(STATUS \"Enabling ARC support by default. ENABLE_ARC not provided!\")\nendif()\nset(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL \"Whether or not to enable ARC\" ${FORCE_CACHE})\n# Use hidden visibility or not\nif(NOT DEFINED ENABLE_VISIBILITY)\n  # Unless specified, disable symbols visibility by default\n  set(ENABLE_VISIBILITY FALSE)\n  message(STATUS \"Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!\")\nendif()\nset(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL \"Whether or not to hide symbols (-fvisibility=hidden)\" ${FORCE_CACHE})\n# Set strict compiler checks or not\nif(NOT DEFINED ENABLE_STRICT_TRY_COMPILE)\n  # Unless specified, disable strict try_compile()\n  set(ENABLE_STRICT_TRY_COMPILE FALSE)\n  message(STATUS \"Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!\")\nendif()\nset(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL \"Whether or not to use strict compiler checks\" ${FORCE_CACHE})\n# Get the SDK version information.\nexecute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion\n  OUTPUT_VARIABLE SDK_VERSION\n  ERROR_QUIET\n  OUTPUT_STRIP_TRAILING_WHITESPACE)\n\n# Find the Developer root for the specific iOS platform being compiled for\n# from CMAKE_OSX_SYSROOT.  Should be ../../ from SDK specified in\n# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain\n# this information from xcrun or xcodebuild.\nif (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES \"Xcode\")\n  get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH)\n  get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH)\n\n  if (NOT DEFINED CMAKE_DEVELOPER_ROOT)\n    message(FATAL_ERROR \"Invalid CMAKE_DEVELOPER_ROOT: \"\n      \"${CMAKE_DEVELOPER_ROOT} does not exist.\")\n  endif()\nendif()\n# Find the C & C++ compilers for the specified SDK.\nif(NOT CMAKE_C_COMPILER)\n  execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang\n    OUTPUT_VARIABLE CMAKE_C_COMPILER\n    ERROR_QUIET\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n  message(STATUS \"Using C compiler: ${CMAKE_C_COMPILER}\")\nendif()\nif(NOT CMAKE_CXX_COMPILER)\n  execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++\n    OUTPUT_VARIABLE CMAKE_CXX_COMPILER\n    ERROR_QUIET\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n  message(STATUS \"Using CXX compiler: ${CMAKE_CXX_COMPILER}\")\nendif()\n# Find (Apple's) libtool.\nexecute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool\n  OUTPUT_VARIABLE BUILD_LIBTOOL\n  ERROR_QUIET\n  OUTPUT_STRIP_TRAILING_WHITESPACE)\nmessage(STATUS \"Using libtool: ${BUILD_LIBTOOL}\")\n# Configure libtool to be used instead of ar + ranlib to build static libraries.\n# This is required on Xcode 7+, but should also work on previous versions of\n# Xcode.\nset(CMAKE_C_CREATE_STATIC_LIBRARY\n  \"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> \")\nset(CMAKE_CXX_CREATE_STATIC_LIBRARY\n  \"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> \")\n# Find the toolchain's provided install_name_tool if none is found on the host\nif(NOT CMAKE_INSTALL_NAME_TOOL)\n  execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool\n      OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT\n      ERROR_QUIET\n      OUTPUT_STRIP_TRAILING_WHITESPACE)\n  set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING \"\" ${FORCE_CACHE})\n  message(STATUS \"Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}\")\nendif()\n# Get the version of Darwin (OS X) of the host.\nexecute_process(COMMAND uname -r\n  OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION\n  ERROR_QUIET\n  OUTPUT_STRIP_TRAILING_WHITESPACE)\n# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.\nif(MODERN_CMAKE)\n  if(SDK_NAME MATCHES \"iphone\")\n    set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL \"\" ${FORCE_CACHE})\n  elseif(SDK_NAME MATCHES \"appletv\")\n    set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL \"\" ${FORCE_CACHE})\n  elseif(SDK_NAME MATCHES \"watch\")\n    set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL \"\" ${FORCE_CACHE})\n  endif()\n\n  # Provide flags for a combined FAT library build on newer CMake versions\n  if(PLATFORM_INT MATCHES \".*COMBINED\")\n    set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL \"\" ${FORCE_CACHE})\n    set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL \"\" ${FORCE_CACHE})\n    message(STATUS \"Will combine built (static) artifacts into FAT lib...\")\n  endif()\nelse()\n  # Legacy code path prior to CMake 3.14\n  set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL \"\" ${FORCE_CACHE})\nendif()\n# Standard settings.\nset(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL \"\")\nset(UNIX TRUE CACHE BOOL \"\")\nset(APPLE TRUE CACHE BOOL \"\")\nset(IOS TRUE CACHE BOOL \"\")\nset(CMAKE_AR ar CACHE FILEPATH \"\" FORCE)\nset(CMAKE_RANLIB ranlib CACHE FILEPATH \"\" FORCE)\nset(CMAKE_STRIP strip CACHE FILEPATH \"\" FORCE)\n# Set the architectures for which to build.\nset(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING \"Build architecture for iOS\")\n# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks\nif(ENABLE_STRICT_TRY_COMPILE_INT)\n  message(STATUS \"Using strict compiler checks (default in CMake).\")\nelse()\n  set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)\nendif()\n# All iOS/Darwin specific settings - some may be redundant.\nset(CMAKE_SHARED_LIBRARY_PREFIX \"lib\")\nset(CMAKE_SHARED_LIBRARY_SUFFIX \".dylib\")\nset(CMAKE_SHARED_MODULE_PREFIX \"lib\")\nset(CMAKE_SHARED_MODULE_SUFFIX \".so\")\nset(CMAKE_C_COMPILER_ABI ELF)\nset(CMAKE_CXX_COMPILER_ABI ELF)\nset(CMAKE_C_HAS_ISYSROOT 1)\nset(CMAKE_CXX_HAS_ISYSROOT 1)\nset(CMAKE_MODULE_EXISTS 1)\nset(CMAKE_DL_LIBS \"\")\nset(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG \"-compatibility_version \")\nset(CMAKE_C_OSX_CURRENT_VERSION_FLAG \"-current_version \")\nset(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG \"${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}\")\nset(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG \"${CMAKE_C_OSX_CURRENT_VERSION_FLAG}\")\n\nif(ARCHS MATCHES \"((^|;|, )(arm64|arm64e|x86_64))+\")\n  set(CMAKE_C_SIZEOF_DATA_PTR 8)\n  set(CMAKE_CXX_SIZEOF_DATA_PTR 8)\n  if(ARCHS MATCHES \"((^|;|, )(arm64|arm64e))+\")\n    set(CMAKE_SYSTEM_PROCESSOR \"aarch64\")\n  else()\n    set(CMAKE_SYSTEM_PROCESSOR \"x86_64\")\n  endif()\n  message(STATUS \"Using a data_ptr size of 8\")\nelse()\n  set(CMAKE_C_SIZEOF_DATA_PTR 4)\n  set(CMAKE_CXX_SIZEOF_DATA_PTR 4)\n  set(CMAKE_SYSTEM_PROCESSOR \"arm\")\n  message(STATUS \"Using a data_ptr size of 4\")\nendif()\n\nmessage(STATUS \"Building for minimum ${SDK_NAME} version: ${DEPLOYMENT_TARGET}\"\n               \" (SDK version: ${SDK_VERSION})\")\n# Note that only Xcode 7+ supports the newer more specific:\n# -m${SDK_NAME}-version-min flags, older versions of Xcode use:\n# -m(ios/ios-simulator)-version-min instead.\nif(PLATFORM_INT STREQUAL \"OS\" OR PLATFORM_INT STREQUAL \"OS64\")\n  if(XCODE_VERSION VERSION_LESS 7.0)\n    set(SDK_NAME_VERSION_FLAGS\n      \"-mios-version-min=${DEPLOYMENT_TARGET}\")\n  else()\n    # Xcode 7.0+ uses flags we can build directly from SDK_NAME.\n    set(SDK_NAME_VERSION_FLAGS\n      \"-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}\")\n  endif()\nelseif(PLATFORM_INT STREQUAL \"TVOS\")\n  set(SDK_NAME_VERSION_FLAGS\n    \"-mtvos-version-min=${DEPLOYMENT_TARGET}\")\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR_TVOS\")\n  set(SDK_NAME_VERSION_FLAGS\n    \"-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}\")\nelseif(PLATFORM_INT STREQUAL \"WATCHOS\")\n  set(SDK_NAME_VERSION_FLAGS\n    \"-mwatchos-version-min=${DEPLOYMENT_TARGET}\")\nelseif(PLATFORM_INT STREQUAL \"SIMULATOR_WATCHOS\")\n  set(SDK_NAME_VERSION_FLAGS\n    \"-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}\")\nelse()\n  # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min.\n  set(SDK_NAME_VERSION_FLAGS\n    \"-mios-simulator-version-min=${DEPLOYMENT_TARGET}\")\nendif()\nmessage(STATUS \"Version flags set to: ${SDK_NAME_VERSION_FLAGS}\")\nset(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING\n    \"Set CMake deployment target\" ${FORCE_CACHE})\n\nif(ENABLE_BITCODE_INT)\n  set(BITCODE \"-fembed-bitcode\")\n  set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL \"\")\n  message(STATUS \"Enabling bitcode support.\")\nelse()\n  set(BITCODE \"\")\n  set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL \"\")\n  message(STATUS \"Disabling bitcode support.\")\nendif()\n\nif(ENABLE_ARC_INT)\n  set(FOBJC_ARC \"-fobjc-arc\")\n  set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES CACHE INTERNAL \"\")\n  message(STATUS \"Enabling ARC support.\")\nelse()\n  set(FOBJC_ARC \"-fno-objc-arc\")\n  set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO CACHE INTERNAL \"\")\n  message(STATUS \"Disabling ARC support.\")\nendif()\n\nif(NOT ENABLE_VISIBILITY_INT)\n  set(VISIBILITY \"-fvisibility=hidden\")\n  set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES CACHE INTERNAL \"\")\n  message(STATUS \"Hiding symbols (-fvisibility=hidden).\")\nelse()\n  set(VISIBILITY \"\")\n  set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN NO CACHE INTERNAL \"\")\nendif()\n\n#Check if Xcode generator is used, since that will handle these flags automagically\nif(USED_CMAKE_GENERATOR MATCHES \"Xcode\")\n  message(STATUS \"Not setting any manual command-line buildflags, since Xcode is selected as generator.\")\nelse()\n  set(CMAKE_C_FLAGS\n  \"${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}\")\n  # Hidden visibilty is required for C++ on iOS.\n  set(CMAKE_CXX_FLAGS\n  \"${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}\")\n  set(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}\")\n  set(CMAKE_CXX_FLAGS_MINSIZEREL \"${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}\")\n  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO \"${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}\")\n  set(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}\")\n  set(CMAKE_C_LINK_FLAGS \"${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}\")\n  set(CMAKE_CXX_LINK_FLAGS \"${SDK_NAME_VERSION_FLAGS}  -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}\")\n\n  # In order to ensure that the updated compiler flags are used in try_compile()\n  # tests, we have to forcibly set them in the CMake cache, not merely set them\n  # in the local scope.\n  list(APPEND VARS_TO_FORCE_IN_CACHE\n    CMAKE_C_FLAGS\n    CMAKE_CXX_FLAGS\n    CMAKE_CXX_FLAGS_DEBUG\n    CMAKE_CXX_FLAGS_RELWITHDEBINFO\n    CMAKE_CXX_FLAGS_MINSIZEREL\n    CMAKE_CXX_FLAGS_RELEASE\n    CMAKE_C_LINK_FLAGS\n    CMAKE_CXX_LINK_FLAGS)\n  foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE})\n    set(${VAR_TO_FORCE} \"${${VAR_TO_FORCE}}\" CACHE STRING \"\")\n  endforeach()\nendif()\n\nset(CMAKE_PLATFORM_HAS_INSTALLNAME 1)\nset(CMAKE_SHARED_LINKER_FLAGS \"-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks\")\nset(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS \"-dynamiclib -Wl,-headerpad_max_install_names\")\nset(CMAKE_SHARED_MODULE_CREATE_C_FLAGS \"-bundle -Wl,-headerpad_max_install_names\")\nset(CMAKE_SHARED_MODULE_LOADER_C_FLAG \"-Wl,-bundle_loader,\")\nset(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG \"-Wl,-bundle_loader,\")\nset(CMAKE_FIND_LIBRARY_SUFFIXES \".tbd\" \".dylib\" \".so\" \".a\")\nset(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG \"-install_name\")\n\n# Set the find root to the iOS developer roots and to user defined paths.\nset(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING \"Root path that will be prepended\n to all search paths\")\n# Default to searching for frameworks first.\nset(CMAKE_FIND_FRAMEWORK FIRST)\n# Set up the default search directories for frameworks.\nset(CMAKE_FRAMEWORK_PATH\n  ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks\n  ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks\n  ${CMAKE_FRAMEWORK_PATH} CACHE STRING \"Frameworks search paths\" ${FORCE_CACHE})\n\n# By default, search both the specified iOS SDK and the remainder of the host filesystem.\nif(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING \"\" ${FORCE_CACHE})\nendif()\nif(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)\n  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE STRING \"\" ${FORCE_CACHE})\nendif()\nif(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)\n  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE STRING \"\" ${FORCE_CACHE})\nendif()\nif(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE STRING \"\" ${FORCE_CACHE})\nendif()\n\n#\n# Some helper-macros below to simplify and beautify the CMakeFile\n#\n\n# This little macro lets you set any Xcode specific property.\nmacro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION)\n  set(XCODE_RELVERSION_I \"${XCODE_RELVERSION}\")\n  if(XCODE_RELVERSION_I STREQUAL \"All\")\n    set_property(TARGET ${TARGET} PROPERTY\n    XCODE_ATTRIBUTE_${XCODE_PROPERTY} \"${XCODE_VALUE}\")\n  else()\n    set_property(TARGET ${TARGET} PROPERTY\n    XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] \"${XCODE_VALUE}\")\n  endif()\nendmacro(set_xcode_property)\n# This macro lets you find executable programs on the host system.\nmacro(find_host_package)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)\n  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)\n  set(IOS FALSE)\n  find_package(${ARGN})\n  set(IOS TRUE)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)\n  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)\n  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)\n  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)\nendmacro(find_host_package)\n"
  },
  {
    "path": "build/i64lib.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"i64lib.h\"\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n\n#if ( defined (_WIN32) ||  defined (_WIN64) ) && !defined (__MINGW32__) && !defined (__MINGW64__)\n\n#if !defined(PRId64)\n# if __WORDSIZE == 64  \n#  define PRId64    \"ld\"   \n# else  \n#  define PRId64    \"lld\"  \n# endif \n#endif\n\n#if !defined(PRIu64)\n# if __WORDSIZE == 64  \n#  define PRIu64    \"lu\"   \n# else  \n#  define PRIu64    \"llu\"  \n# endif\n#endif\n\n#else\n#include <inttypes.h>\n#endif\n\n#if LUA_VERSION_NUM == 501\n\n#define INT64_META_REF 8\n\nenum IntegerType {\n\tInt,\n\tUInt,\n\tNum\n};\n\ntypedef struct {\n\tint fake_id;\n\tint8_t type;\n    union {\n\t\tint64_t i64;\n\t\tuint64_t u64;\n\t} data;\n} Integer64;\n\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n) {\n\tInteger64* p = (Integer64*)lua_newuserdata(L, sizeof(Integer64));\n\tp->fake_id = -1;\n\tp->data.i64 = n;\n\tp->type = Int;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n\tlua_setmetatable(L, -2);            \n}\n\nLUALIB_API int lua_isint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal && (p->type == Int);\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API int lua_isint64_or_uint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal;\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos) {\n    int64_t n = 0;\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n = (int64_t)lua_tonumber(L, pos);\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isint64_or_uint64(L, pos)) {\n\t\t\t\tn = ((Integer64*)lua_touserdata(L, pos))->data.i64;\n\t\t\t}\n\t\t\tbreak;\n        default:\n            break;\n    }\n    \n    return n;\n}\n\n#if defined(UINT_ESPECIALLY)\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tInteger64* p = (Integer64*)lua_newuserdata(L, sizeof(Integer64));\n\tp->fake_id = -1;\n\tp->data.u64 = n;\n\tp->type = UInt;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n\tlua_setmetatable(L, -2);            \n}\n\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal && (p->type == UInt);\n        }\n    }\n\n    return 0;\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n    uint64_t n = 0;\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n = (int64_t)lua_tonumber(L, pos);\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isint64_or_uint64(L, pos)) {\n\t\t\t\tn = ((Integer64*)lua_touserdata(L, pos))->data.u64;\n\t\t\t}\n\t\t\tbreak;\n        default:\n            break;\n    }\n    \n    return n;\n}\n#else\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tlua_pushint64(L, (int64_t)n);\n}\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n    return lua_isint64(L, pos);\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n    return (uint64_t)lua_toint64(L, pos);\n}\n#endif\n\nLUALIB_API int lua_isinteger64(lua_State* L, int pos) {\n\tint equal;\n    Integer64* p = (Integer64*)lua_touserdata(L, pos);\n\n    if (p != NULL) {\n        if (lua_getmetatable(L, pos)) {            \n\t\t\tlua_rawgeti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n            equal = lua_rawequal(L, -1, -2);\n            lua_pop(L, 2);  \n\n            return equal;\n        }\n    }\n\n    return 0;\n}\n\nstatic Integer64 lua_checkinteger64(lua_State* L, int pos) {\n    Integer64 n = {0};\n    int type = lua_type(L, pos);\n    \n    switch(type) {\n        case LUA_TNUMBER:\n            n.data.i64 = (int64_t)lua_tonumber(L, pos);\n\t\t\tn.type = Num;\n            break;\n        case LUA_TUSERDATA:\n\t\t    if (lua_isinteger64(L, pos)) {\n\t\t\t\tn = *(Integer64*)lua_touserdata(L, pos);\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tluaL_typerror(L, pos, \"Integer64\");\n\t\t\t\treturn n;\n\t\t\t}\n        default:\n            luaL_typerror(L, pos, \"Integer64\");\n\t\t\treturn n;\n    }\n    \n    return n;\n}\n\nstatic int int64_add(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 + rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 + rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_sub(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 - rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 - rhs.data.i64);\n\t}\n    return 1;\n}\n\n\nstatic int int64_mul(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 * rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 * rhs.data.i64);\n\t}\n    return 1;    \n}\n\nstatic int int64_div(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (rhs.data.i64 == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\t\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 / rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 / rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_mod(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\n    if (rhs.data.i64 == 0) {\n        return luaL_error(L, \"mod by zero\");\n    }\n\n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, lhs.data.u64 % rhs.data.u64);\n\t} else {\n\t\tlua_pushint64(L, lhs.data.i64 % rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_unm(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1); \n    lua_pushint64(L, -lhs.data.i64);\n    return 1;\n}\n\nstatic int int64_pow(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);    \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushuint64(L, pow(lhs.data.u64, rhs.data.u64));\n\t} else {\n\t\tlua_pushint64(L, pow(lhs.data.i64, rhs.data.i64));\n\t}\n    return 1;\n}\n\nstatic int int64_eq(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1);     \n    Integer64 rhs = lua_checkinteger64(L, 2); \n    \n    if (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 == rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 == rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_lt(lua_State* L) {\n    Integer64 lhs = lua_checkinteger64(L, 1); \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 < rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 < rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_le(lua_State* L) {\n\tInteger64 lhs = lua_checkinteger64(L, 1); \n    Integer64 rhs = lua_checkinteger64(L, 2);\n\t\n\tif (lhs.type != rhs.type && lhs.type != Num && rhs.type != Num) {\n\t\treturn luaL_error(L, \"type not match, lhs is %s, rhs is %s\", lhs.type == Int ? \"Int64\" : \"UInt64\", rhs.type == Int ? \"Int64\" : \"UInt64\");\n\t} else if (lhs.type == UInt || rhs.type == UInt) {\n\t\tlua_pushboolean(L, lhs.data.u64 <= rhs.data.u64);\n\t} else {\n\t\tlua_pushboolean(L, lhs.data.i64 <= rhs.data.i64);\n\t}\n    return 1;\n}\n\nstatic int int64_tostring(lua_State* L) { \n    char temp[72];\n\tInteger64 lhs = lua_checkinteger64(L, 1); \n\tif (lhs.type == UInt) {\n\t\tsprintf(temp, \"%\"PRIu64\"U\", lhs.data.u64);\n\t} else {\n\t\tsprintf(temp, \"%\"PRId64, lhs.data.i64);\n\t}\t\t\n    lua_pushstring(L, temp);\n    return 1;\n}\n\n#endif\n\n#if LUA_VERSION_NUM >= 503\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n) {\n\tlua_pushinteger(L, n);\n}\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n) {\n\tlua_pushinteger(L, n);\n}\n\nLUALIB_API int lua_isint64(lua_State* L, int pos) {\n\treturn lua_isinteger(L, pos);\n}\n\nLUALIB_API int lua_isuint64(lua_State* L, int pos) {\n\treturn lua_isinteger(L, pos);\n}\n\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos) {\n\treturn lua_tointeger(L, pos);\n}\n\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos) {\n\treturn lua_tointeger(L, pos);\n}\n#endif\n\nstatic int uint64_tostring(lua_State* L) {\n\tchar temp[72];\n\tuint64_t n = lua_touint64(L, 1);\n#if ( defined (_WIN32) ||  defined (_WIN64) ) && !defined (__MINGW32__) && !defined (__MINGW64__)\n\tsprintf_s(temp, sizeof(temp), \"%\"PRIu64, n);\n#else\n\tsnprintf(temp, sizeof(temp), \"%\"PRIu64, n);\n#endif\n\t\n\tlua_pushstring(L, temp);\n\t\n\treturn 1;\n}\n\nstatic int uint64_compare(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tlua_pushinteger(L, lhs == rhs ? 0 : (lhs < rhs ? -1 : 1));\n\treturn 1;\n}\n\nstatic int uint64_divide(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tif (rhs == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\tlua_pushuint64(L, lhs / rhs);\n\treturn 1;\n}\n\nstatic int uint64_remainder(lua_State* L) {\n\tuint64_t lhs = lua_touint64(L, 1);\n\tuint64_t rhs = lua_touint64(L, 2);\n\tif (rhs == 0) {\n        return luaL_error(L, \"div by zero\");\n    }\n\tlua_pushuint64(L, lhs % rhs);\n\treturn 1;\n}\n\nLUALIB_API int uint64_parse(lua_State* L)\n{\n    const char* str = lua_tostring(L, 1);\n    lua_pushuint64(L, strtoull(str, NULL, 0));\n    return 1;\n}\n\nLUALIB_API int luaopen_i64lib(lua_State* L)\n{\n#if LUA_VERSION_NUM == 501\n    lua_newtable(L);\n\t\n    lua_pushcfunction(L, int64_add);\n    lua_setfield(L, -2, \"__add\");\n\n    lua_pushcfunction(L, int64_sub);\n    lua_setfield(L, -2, \"__sub\");\n\n    lua_pushcfunction(L, int64_mul);\n    lua_setfield(L, -2, \"__mul\");\n\n    lua_pushcfunction(L, int64_div);\n    lua_setfield(L, -2, \"__div\");\n\n    lua_pushcfunction(L, int64_mod);\n    lua_setfield(L, -2, \"__mod\");\n\n    lua_pushcfunction(L, int64_unm);\n    lua_setfield(L, -2, \"__unm\");\n\n    lua_pushcfunction(L, int64_pow);\n    lua_setfield(L, -2, \"__pow\");    \n\n    lua_pushcfunction(L, int64_tostring);\n    lua_setfield(L, -2, \"__tostring\");        \n\n    lua_pushcfunction(L, int64_eq);\n    lua_setfield(L, -2, \"__eq\");  \n\n    lua_pushcfunction(L, int64_lt);\n    lua_setfield(L, -2, \"__lt\"); \n\n    lua_pushcfunction(L, int64_le);\n    lua_setfield(L, -2, \"__le\");\n\t\n\tlua_rawseti(L, LUA_REGISTRYINDEX, INT64_META_REF);\n#endif\n    lua_newtable(L);\n\t\n\tlua_pushcfunction(L, uint64_tostring);\n\tlua_setfield(L, -2, \"tostring\");\n\t\n\tlua_pushcfunction(L, uint64_compare);\n\tlua_setfield(L, -2, \"compare\");\n\t\n\tlua_pushcfunction(L, uint64_divide);\n\tlua_setfield(L, -2, \"divide\");\n\t\n\tlua_pushcfunction(L, uint64_remainder);\n\tlua_setfield(L, -2, \"remainder\");\n\t\n\tlua_pushcfunction(L, uint64_parse);\n\tlua_setfield(L, -2, \"parse\");\n\t\n\tlua_setglobal(L, \"uint64\");\n\treturn 0;\n}\n\n"
  },
  {
    "path": "build/i64lib.h",
    "content": "/*\r\n *Tencent is pleased to support the open source community by making xLua available.\r\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n *http://opensource.org/licenses/MIT\r\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n*/\r\n\r\n#ifndef I64LIB_H\r\n#define I64LIB_H\r\n\r\n#include <stdint.h>\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n#include \"lualib.h\"\r\n\r\n#ifdef __cplusplus\r\n#if __cplusplus\r\nextern \"C\"{\r\n#endif\r\n#endif /* __cplusplus */\r\n\r\nLUALIB_API void lua_pushint64(lua_State* L, int64_t n);\r\nLUALIB_API void lua_pushuint64(lua_State* L, uint64_t n);\r\n\r\nLUALIB_API int lua_isint64(lua_State* L, int pos);\r\nLUALIB_API int lua_isuint64(lua_State* L, int pos);\r\n\r\nLUALIB_API int64_t lua_toint64(lua_State* L, int pos);\r\nLUALIB_API uint64_t lua_touint64(lua_State* L, int pos);\r\n\r\n#ifdef __cplusplus\r\n#if __cplusplus\r\n}\r\n#endif\r\n#endif /* __cplusplus */ \r\n\r\n\r\n#endif"
  },
  {
    "path": "build/lua-5.1.5/COPYRIGHT",
    "content": "Lua License\n-----------\n\nLua is licensed under the terms of the MIT license reproduced below.\nThis means that Lua is free software and can be used for both academic\nand commercial purposes at absolutely no cost.\n\nFor details and rationale, see http://www.lua.org/license.html .\n\n===============================================================================\n\nCopyright (C) 1994-2012 Lua.org, PUC-Rio.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n===============================================================================\n\n(end of COPYRIGHT)\n"
  },
  {
    "path": "build/lua-5.1.5/HISTORY",
    "content": "HISTORY for Lua 5.1\n\n* Changes from version 5.0 to 5.1\n  -------------------------------\n  Language:\n  + new module system.\n  + new semantics for control variables of fors.\n  + new semantics for setn/getn.\n  + new syntax/semantics for varargs.\n  + new long strings and comments.\n  + new `mod' operator (`%')\n  + new length operator #t\n  + metatables for all types\n  API:\n  + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer.\n  + user supplies memory allocator (lua_open becomes lua_newstate).\n  + luaopen_* functions must be called through Lua.\n  Implementation:\n  + new configuration scheme via luaconf.h.\n  + incremental garbage collection.\n  + better handling of end-of-line in the lexer.\n  + fully reentrant parser (new Lua function `load')\n  + better support for 64-bit machines.\n  + native loadlib support for Mac OS X.\n  + standard distribution in only one library (lualib.a merged into lua.a)\n\n* Changes from version 4.0 to 5.0\n  -------------------------------\n  Language:\n  + lexical scoping.\n  + Lua coroutines.\n  + standard libraries now packaged in tables.\n  + tags replaced by metatables and tag methods replaced by metamethods,\n    stored in metatables.\n  + proper tail calls.\n  + each function can have its own global table, which can be shared.\n  + new __newindex metamethod, called when we insert a new key into a table.\n  + new block comments: --[[ ... ]].\n  + new generic for.\n  + new weak tables.\n  + new boolean type.\n  + new syntax \"local function\".\n  + (f()) returns the first value returned by f.\n  + {f()} fills a table with all values returned by f.\n  + \\n ignored in [[\\n .\n  + fixed and-or priorities.\n  + more general syntax for function definition (e.g. function a.x.y:f()...end).\n  + more general syntax for function calls (e.g. (print or write)(9)).\n  + new functions (time/date, tmpfile, unpack, require, load*, etc.).\n  API:\n  + chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer.\n  + introduced lightweight userdata, a simple \"void*\" without a metatable.\n  + new error handling protocol: the core no longer prints error messages;\n    all errors are reported to the caller on the stack.\n  + new lua_atpanic for host cleanup.\n  + new, signal-safe, hook scheme.\n  Implementation:\n  + new license: MIT.\n  + new, faster, register-based virtual machine.\n  + support for external multithreading and coroutines.\n  + new and consistent error message format.\n  + the core no longer needs \"stdio.h\" for anything (except for a single\n    use of sprintf to convert numbers to strings).\n  + lua.c now runs the environment variable LUA_INIT, if present. It can\n    be \"@filename\", to run a file, or the chunk itself.\n  + support for user extensions in lua.c.\n    sample implementation given for command line editing.\n  + new dynamic loading library, active by default on several platforms.\n  + safe garbage-collector metamethods.\n  + precompiled bytecodes checked for integrity (secure binary dostring).\n  + strings are fully aligned.\n  + position capture in string.find.\n  + read('*l') can read lines with embedded zeros.\n\n* Changes from version 3.2 to 4.0\n  -------------------------------\n  Language:\n  + new \"break\" and \"for\" statements (both numerical and for tables).\n  + uniform treatment of globals: globals are now stored in a Lua table.\n  + improved error messages.\n  + no more '$debug': full speed *and* full debug information.\n  + new read form: read(N) for next N bytes.\n  + general read patterns now deprecated.\n    (still available with -DCOMPAT_READPATTERNS.)\n  + all return values are passed as arguments for the last function\n    (old semantics still available with -DLUA_COMPAT_ARGRET)\n  + garbage collection tag methods for tables now deprecated.\n  + there is now only one tag method for order.\n  API:\n  + New API: fully re-entrant, simpler, and more efficient.\n  + New debug API.\n  Implementation:\n  + faster than ever: cleaner virtual machine and new hashing algorithm.\n  + non-recursive garbage-collector algorithm.\n  + reduced memory usage for programs with many strings.\n  + improved treatment for memory allocation errors.\n  + improved support for 16-bit machines (we hope).\n  + code now compiles unmodified as both ANSI C and C++.\n  + numbers in bases other than 10 are converted using strtoul.\n  + new -f option in Lua to support #! scripts.\n  + luac can now combine text and binaries.\n\n* Changes from version 3.1 to 3.2\n  -------------------------------\n  + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT.\n  + increased limit on the number of constants and globals per function\n    (from 2^16 to 2^24).\n  + debugging info (lua_debug and hooks) moved into lua_state and new API\n    functions provided to get and set this info.\n  + new debug lib gives full debugging access within Lua.\n  + new table functions \"foreachi\", \"sort\", \"tinsert\", \"tremove\", \"getn\".\n  + new io functions \"flush\", \"seek\".\n\n* Changes from version 3.0 to 3.1\n  -------------------------------\n  + NEW FEATURE: anonymous functions with closures (via \"upvalues\").\n  + new syntax:\n    - local variables in chunks.\n    - better scope control with DO block END.\n    - constructors can now be also written: { record-part; list-part }.\n    - more general syntax for function calls and lvalues, e.g.:\n      f(x).y=1\n      o:f(x,y):g(z)\n      f\"string\" is sugar for f(\"string\")\n  + strings may now contain arbitrary binary data (e.g., embedded zeros).\n  + major code re-organization and clean-up; reduced module interdependecies.\n  + no arbitrary limits on the total number of constants and globals.\n  + support for multiple global contexts.\n  + better syntax error messages.\n  + new traversal functions \"foreach\" and \"foreachvar\".\n  + the default for numbers is now double.\n    changing it to use floats or longs is easy.\n  + complete debug information stored in pre-compiled chunks.\n  + sample interpreter now prompts user when run interactively, and also\n    handles control-C interruptions gracefully.\n\n* Changes from version 2.5 to 3.0\n  -------------------------------\n  + NEW CONCEPT: \"tag methods\".\n    Tag methods replace fallbacks as the meta-mechanism for extending the\n    semantics of Lua. Whereas fallbacks had a global nature, tag methods\n    work on objects having the same tag (e.g., groups of tables).\n    Existing code that uses fallbacks should work without change.\n  + new, general syntax for constructors {[exp] = exp, ... }.\n  + support for handling variable number of arguments in functions (varargs).\n  + support for conditional compilation ($if ... $else ... $end).\n  + cleaner semantics in API simplifies host code.\n  + better support for writing libraries (auxlib.h).\n  + better type checking and error messages in the standard library.\n  + luac can now also undump.\n\n* Changes from version 2.4 to 2.5\n  -------------------------------\n  + io and string libraries are now based on pattern matching;\n    the old libraries are still available for compatibility\n  + dofile and dostring can now return values (via return statement)\n  + better support for 16- and 64-bit machines\n  + expanded documentation, with more examples\n\n* Changes from version 2.2 to 2.4\n  -------------------------------\n  + external compiler creates portable binary files that can be loaded faster\n  + interface for debugging and profiling\n  + new \"getglobal\" fallback\n  + new functions for handling references to Lua objects\n  + new functions in standard lib\n  + only one copy of each string is stored\n  + expanded documentation, with more examples\n\n* Changes from version 2.1 to 2.2\n  -------------------------------\n  + functions now may be declared with any \"lvalue\" as a name\n  + garbage collection of functions\n  + support for pipes\n\n* Changes from version 1.1 to 2.1\n  -------------------------------\n  + object-oriented support\n  + fallbacks\n  + simplified syntax for tables\n  + many internal improvements\n\n(end of HISTORY)\n"
  },
  {
    "path": "build/lua-5.1.5/INSTALL",
    "content": "INSTALL for Lua 5.1\n\n* Building Lua\n  ------------\n  Lua is built in the src directory, but the build process can be\n  controlled from the top-level Makefile.\n\n  Building Lua on Unix systems should be very easy. First do \"make\" and\n  see if your platform is listed. If so, just do \"make xxx\", where xxx\n  is your platform name. The platforms currently supported are:\n    aix ansi bsd freebsd generic linux macosx mingw posix solaris\n\n  If your platform is not listed, try the closest one or posix, generic,\n  ansi, in this order.\n\n  See below for customization instructions and for instructions on how\n  to build with other Windows compilers.\n\n  If you want to check that Lua has been built correctly, do \"make test\"\n  after building Lua. Also, have a look at the example programs in test.\n\n* Installing Lua\n  --------------\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"make install\". The official\n  place and the way to install files are defined in Makefile. You must\n  have the right permissions to install files.\n\n  If you want to build and install Lua in one step, do \"make xxx install\",\n  where xxx is your platform name.\n\n  If you want to install Lua locally, then do \"make local\". This will\n  create directories bin, include, lib, man, and install Lua there as\n  follows:\n\n    bin:\tlua luac\n    include:\tlua.h luaconf.h lualib.h lauxlib.h lua.hpp\n    lib:\tliblua.a\n    man/man1:\tlua.1 luac.1\n\n  These are the only directories you need for development.\n\n  There are man pages for lua and luac, in both nroff and html, and a\n  reference manual in html in doc, some sample code in test, and some\n  useful stuff in etc. You don't need these directories for development.\n\n  If you want to install Lua locally, but in some other directory, do\n  \"make install INSTALL_TOP=xxx\", where xxx is your chosen directory.\n\n  See below for instructions for Windows and other systems.\n\n* Customization\n  -------------\n  Three things can be customized by editing a file:\n    - Where and how to install Lua -- edit Makefile.\n    - How to build Lua -- edit src/Makefile.\n    - Lua features -- edit src/luaconf.h.\n\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables when invoking make.\n\n  On the other hand, if you need to select some Lua features, you'll need\n  to edit src/luaconf.h. The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n\n  We strongly recommend that you enable dynamic loading. This is done\n  automatically for all platforms listed above that have this feature\n  (and also Windows). See src/luaconf.h and also src/Makefile.\n\n* Building Lua on Windows and other systems\n  -----------------------------------------\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n  library:\tlapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c\n\t\tlmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c\n\t\tltable.c ltm.c lundump.c lvm.c lzio.c\n\t\tlauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c\n\t\tltablib.c lstrlib.c loadlib.c linit.c\n\n  interpreter:\tlibrary, lua.c\n\n  compiler:\tlibrary, luac.c print.c\n\n  If you use Visual Studio .NET, you can use etc/luavs.bat in its\n  \"Command Prompt\".\n\n  If all you want is to build the Lua interpreter, you may put all .c files\n  in a single project, except for luac.c and print.c. Or just use etc/all.c.\n\n  To use Lua as a library in your own programs, you'll need to know how to\n  create and use libraries with your compiler.\n\n  As mentioned above, you may edit luaconf.h to select some features before\n  building Lua.\n\n(end of INSTALL)\n"
  },
  {
    "path": "build/lua-5.1.5/Makefile",
    "content": "# makefile for installing Lua\n# see INSTALL for installation instructions\n# see src/Makefile and src/luaconf.h for further customization\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\n# Where to install. The installation starts in the src and doc directories,\n# so take care if INSTALL_TOP is not an absolute path.\nINSTALL_TOP= /usr/local\nINSTALL_BIN= $(INSTALL_TOP)/bin\nINSTALL_INC= $(INSTALL_TOP)/include\nINSTALL_LIB= $(INSTALL_TOP)/lib\nINSTALL_MAN= $(INSTALL_TOP)/man/man1\n#\n# You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with\n# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc).\nINSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V\nINSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V\n\n# How to install. If your install program does not support \"-p\", then you\n# may have to run ranlib on the installed liblua.a (do \"make ranlib\").\nINSTALL= install -p\nINSTALL_EXEC= $(INSTALL) -m 0755\nINSTALL_DATA= $(INSTALL) -m 0644\n#\n# If you don't have install you can use cp instead.\n# INSTALL= cp -p\n# INSTALL_EXEC= $(INSTALL)\n# INSTALL_DATA= $(INSTALL)\n\n# Utilities.\nMKDIR= mkdir -p\nRANLIB= ranlib\n\n# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========\n\n# Convenience platforms targets.\nPLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris\n\n# What to install.\nTO_BIN= lua luac\nTO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp\nTO_LIB= liblua.a\nTO_MAN= lua.1 luac.1\n\n# Lua version and release.\nV= 5.1\nR= 5.1.5\n\nall:\t$(PLAT)\n\n$(PLATS) clean:\n\tcd src && $(MAKE) $@\n\ntest:\tdummy\n\tsrc/lua test/hello.lua\n\ninstall: dummy\n\tcd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)\n\tcd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)\n\tcd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)\n\tcd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)\n\tcd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)\n\nranlib:\n\tcd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB)\n\nlocal:\n\t$(MAKE) install INSTALL_TOP=..\n\nnone:\n\t@echo \"Please do\"\n\t@echo \"   make PLATFORM\"\n\t@echo \"where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\t@echo \"See INSTALL for complete instructions.\"\n\n# make may get confused with test/ and INSTALL in a case-insensitive OS\ndummy:\n\n# echo config parameters\necho:\n\t@echo \"\"\n\t@echo \"These are the parameters currently set in src/Makefile to build Lua $R:\"\n\t@echo \"\"\n\t@cd src && $(MAKE) -s echo\n\t@echo \"\"\n\t@echo \"These are the parameters currently set in Makefile to install Lua $R:\"\n\t@echo \"\"\n\t@echo \"PLAT = $(PLAT)\"\n\t@echo \"INSTALL_TOP = $(INSTALL_TOP)\"\n\t@echo \"INSTALL_BIN = $(INSTALL_BIN)\"\n\t@echo \"INSTALL_INC = $(INSTALL_INC)\"\n\t@echo \"INSTALL_LIB = $(INSTALL_LIB)\"\n\t@echo \"INSTALL_MAN = $(INSTALL_MAN)\"\n\t@echo \"INSTALL_LMOD = $(INSTALL_LMOD)\"\n\t@echo \"INSTALL_CMOD = $(INSTALL_CMOD)\"\n\t@echo \"INSTALL_EXEC = $(INSTALL_EXEC)\"\n\t@echo \"INSTALL_DATA = $(INSTALL_DATA)\"\n\t@echo \"\"\n\t@echo \"See also src/luaconf.h .\"\n\t@echo \"\"\n\n# echo private config parameters\npecho:\n\t@echo \"V = $(V)\"\n\t@echo \"R = $(R)\"\n\t@echo \"TO_BIN = $(TO_BIN)\"\n\t@echo \"TO_INC = $(TO_INC)\"\n\t@echo \"TO_LIB = $(TO_LIB)\"\n\t@echo \"TO_MAN = $(TO_MAN)\"\n\n# echo config parameters as Lua code\n# uncomment the last sed expression if you want nil instead of empty strings\nlecho:\n\t@echo \"-- installation parameters for Lua $R\"\n\t@echo \"VERSION = '$V'\"\n\t@echo \"RELEASE = '$R'\"\n\t@$(MAKE) echo | grep = | sed -e 's/= /= \"/' -e 's/$$/\"/' #-e 's/\"\"/nil/'\n\t@echo \"-- EOF\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.1.5/README",
    "content": "README for Lua 5.1\n\nSee INSTALL for installation instructions.\nSee HISTORY for a summary of changes since the last released version.\n\n* What is Lua?\n  ------------\n  Lua is a powerful, light-weight programming language designed for extending\n  applications. Lua is also frequently used as a general-purpose, stand-alone\n  language. Lua is free software.\n\n  For complete information, visit Lua's web site at http://www.lua.org/ .\n  For an executive summary, see http://www.lua.org/about.html .\n\n  Lua has been used in many different projects around the world.\n  For a short list, see http://www.lua.org/uses.html .\n\n* Availability\n  ------------\n  Lua is freely available for both academic and commercial purposes.\n  See COPYRIGHT and http://www.lua.org/license.html for details.\n  Lua can be downloaded at http://www.lua.org/download.html .\n\n* Installation\n  ------------\n  Lua is implemented in pure ANSI C, and compiles unmodified in all known\n  platforms that have an ANSI C compiler. In most Unix-like platforms, simply\n  do \"make\" with a suitable target. See INSTALL for detailed instructions.\n\n* Origin\n  ------\n  Lua is developed at Lua.org, a laboratory of the Department of Computer\n  Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro\n  in Brazil).\n  For more information about the authors, see http://www.lua.org/authors.html .\n\n(end of README)\n"
  },
  {
    "path": "build/lua-5.1.5/doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.1 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=utf-8\">\n<STYLE TYPE=\"text/css\">\nul {\n\tlist-style-type: none ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<HR>\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"\" BORDER=0></A>\nLua 5.1 Reference Manual\n</H1>\n\n<P>\nThe reference manual is the official definition of the Lua language.\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/docs.html#pil\">Programming in Lua</A>.\n\n<P>\nThis manual is also available as a book:\n<BLOCKQUOTE>\n<A HREF=\"http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20\">\n<IMG SRC=\"cover.png\" ALT=\"\" TITLE=\"buy from Amazon\" BORDER=1 ALIGN=\"left\" HSPACE=12>\n</A>\n<B>Lua 5.1 Reference Manual</B>\n<BR>by R. Ierusalimschy, L. H. de Figueiredo, W. Celes\n<BR>Lua.org, August 2006\n<BR>ISBN 85-903798-3-3\n<BR CLEAR=\"all\">\n</BLOCKQUOTE>\n\n<P>\n<A HREF=\"http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20\">Buy a copy</A>\nof this book and\n<A HREF=\"http://www.lua.org/donations.html\">help to support</A>\nthe Lua project.\n\n<P>\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n<HR>\n<SMALL>\nCopyright &copy; 2006&ndash;2012 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<A HREF=\"http://www.lua.org/license.html\">Lua license</A>.\n</SMALL>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL style=\"padding: 0\">\n<LI><A HREF=\"manual.html\">1 &ndash; Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 &ndash; The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 &ndash; Lexical Conventions</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 &ndash; Values and Types</A>\n<UL>\n<LI><A HREF=\"manual.html#2.2.1\">2.2.1 &ndash; Coercion</A>\n</UL>\n<LI><A HREF=\"manual.html#2.3\">2.3 &ndash; Variables</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 &ndash; Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#2.4.1\">2.4.1 &ndash; Chunks</A>\n<LI><A HREF=\"manual.html#2.4.2\">2.4.2 &ndash; Blocks</A>\n<LI><A HREF=\"manual.html#2.4.3\">2.4.3 &ndash; Assignment</A>\n<LI><A HREF=\"manual.html#2.4.4\">2.4.4 &ndash; Control Structures</A>\n<LI><A HREF=\"manual.html#2.4.5\">2.4.5 &ndash; For Statement</A>\n<LI><A HREF=\"manual.html#2.4.6\">2.4.6 &ndash; Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#2.4.7\">2.4.7 &ndash; Local Declarations</A>\n</UL>\n<LI><A HREF=\"manual.html#2.5\">2.5 &ndash; Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 &ndash; Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 &ndash; Relational Operators</A>\n<LI><A HREF=\"manual.html#2.5.3\">2.5.3 &ndash; Logical Operators</A>\n<LI><A HREF=\"manual.html#2.5.4\">2.5.4 &ndash; Concatenation</A>\n<LI><A HREF=\"manual.html#2.5.5\">2.5.5 &ndash; The Length Operator</A>\n<LI><A HREF=\"manual.html#2.5.6\">2.5.6 &ndash; Precedence</A>\n<LI><A HREF=\"manual.html#2.5.7\">2.5.7 &ndash; Table Constructors</A>\n<LI><A HREF=\"manual.html#2.5.8\">2.5.8 &ndash; Function Calls</A>\n<LI><A HREF=\"manual.html#2.5.9\">2.5.9 &ndash; Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 &ndash; Visibility Rules</A>\n<LI><A HREF=\"manual.html#2.7\">2.7 &ndash; Error Handling</A>\n<LI><A HREF=\"manual.html#2.8\">2.8 &ndash; Metatables</A>\n<LI><A HREF=\"manual.html#2.9\">2.9 &ndash; Environments</A>\n<LI><A HREF=\"manual.html#2.10\">2.10 &ndash; Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.10.1\">2.10.1 &ndash; Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.10.2\">2.10.2 &ndash; Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.11\">2.11 &ndash; Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 &ndash; The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 &ndash; The Stack</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 &ndash; Stack Size</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 &ndash; Pseudo-Indices</A>\n<LI><A HREF=\"manual.html#3.4\">3.4 &ndash; C Closures</A>\n<LI><A HREF=\"manual.html#3.5\">3.5 &ndash; Registry</A>\n<LI><A HREF=\"manual.html#3.6\">3.6 &ndash; Error Handling in C</A>\n<LI><A HREF=\"manual.html#3.7\">3.7 &ndash; Functions and Types</A>\n<LI><A HREF=\"manual.html#3.8\">3.8 &ndash; The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 &ndash; The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 &ndash; Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 &ndash; Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 &ndash; Basic Functions</A>\n<LI><A HREF=\"manual.html#5.2\">5.2 &ndash; Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#5.3\">5.3 &ndash; Modules</A>\n<LI><A HREF=\"manual.html#5.4\">5.4 &ndash; String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#5.4.1\">5.4.1 &ndash; Patterns</A>\n</UL>\n<LI><A HREF=\"manual.html#5.5\">5.5 &ndash; Table Manipulation</A>\n<LI><A HREF=\"manual.html#5.6\">5.6 &ndash; Mathematical Functions</A>\n<LI><A HREF=\"manual.html#5.7\">5.7 &ndash; Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#5.8\">5.8 &ndash; Operating System Facilities</A>\n<LI><A HREF=\"manual.html#5.9\">5.9 &ndash; The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 &ndash; Lua Stand-alone</A>\n<P>\n<LI><A HREF=\"manual.html#7\">7 &ndash; Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#7.1\">7.1 &ndash; Changes in the Language</A>\n<LI><A HREF=\"manual.html#7.2\">7.2 &ndash; Changes in the Libraries</A>\n<LI><A HREF=\"manual.html#7.3\">7.3 &ndash; Changes in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#8\">8 &ndash; The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE WIDTH=\"100%\">\n<TR VALIGN=\"top\">\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getfenv\">getfenv</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-loadstring\">loadstring</A><BR>\n<A HREF=\"manual.html#pdf-module\">module</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setfenv\">setfenv</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-unpack\">unpack</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.getfenv\">debug.getfenv</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setfenv\">debug.setfenv</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.atan2\">math.atan2</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.cosh\">math.cosh</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.frexp\">math.frexp</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.ldexp\">math.ldexp</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.log10\">math.log10</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.pow\">math.pow</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sinh\">math.sinh</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tanh\">math.tanh</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loaders\">package.loaders</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.seeall\">package.seeall</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.maxn\">table.maxn</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n\n</TD>\n<TD>\n<H3>C API</H3>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n<P>\n\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_cpcall\">lua_cpcall</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_equal\">lua_equal</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getfenv\">lua_getfenv</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_lessthan\">lua_lessthan</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdata\">lua_newuserdata</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_objlen\">lua_objlen</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setfenv\">lua_setfenv</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n\n</TD>\n<TD>\n<H3>auxiliary library</H3>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<P>\n\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkint\">luaL_checkint</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklong\">luaL_checklong</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_optint\">luaL_optint</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlong\">luaL_optlong</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_register\">luaL_register</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_typerror\">luaL_typerror</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n<P>\n\n<HR>\n<SMALL CLASS=\"footer\">\nLast update:\nMon Feb 13 18:53:32 BRST 2012\n</SMALL>\n<!--\nLast change: revised for Lua 5.1.5\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.1.5/doc/lua.1",
    "content": ".\\\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $\n.TH LUA 1 \"$Date: 2006/01/06 16:03:34 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the stand-alone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nThe given\n.I options\n(see below)\nare executed and then\nthe Lua program in file\n.I script\nis loaded and executed.\nThe given\n.I args\nare available to\n.I script\nas strings in a global table named\n.BR arg .\nIf these arguments contain spaces or other characters special to the shell,\nthen they should be quoted\n(but note that the quotes will be removed by the shell).\nThe arguments in\n.B arg\nstart at 0,\nwhich contains the string\n.RI ' script '.\nThe index of the last argument is stored in\n.BR arg.n .\nThe arguments given in the command line before\n.IR script ,\nincluding the name of the interpreter,\nare available in negative indices in\n.BR arg .\n.LP\nAt the very start,\nbefore even handling the command line,\n.B lua\nexecutes the contents of the environment variable\n.BR LUA_INIT ,\nif it is defined.\nIf the value of\n.B LUA_INIT\nis of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n.LP\nOptions start with\n.B '\\-'\nand are described below.\nYou can use\n.B \"'\\--'\"\nto signal the end of options.\n.LP\nIf no arguments are given,\nthen\n.B \"\\-v \\-i\"\nis assumed when the standard input is a terminal;\notherwise,\n.B \"\\-\"\nis assumed.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\nSo, one way to interrupt the reading of an incomplete statement is\nto force a syntax error:\nadding a\n.B ';' \nin the middle of a statement is a sure way of forcing a syntax error\n(except inside multiline strings and comments; these must be closed explicitly).\nIf a line starts with\n.BR '=' ,\nthen\n.B lua\ndisplays the values of all the expressions in the remainder of the\nline. The expressions must be separated by commas.\nThe primary prompt is the value of the global variable\n.BR _PROMPT ,\nif this value is a string;\notherwise, the default prompt is used.\nSimilarly, the secondary prompt is the value of the global variable\n.BR _PROMPT2 .\nSo,\nto change the prompts,\nset the corresponding variable to a string of your choice.\nYou can do that after calling the interpreter\nor on the command line\n(but in this case you have to be careful with quotes\nif the prompt string contains a space; otherwise you may confuse the shell.)\nThe default prompts are \"> \" and \">> \".\n.SH OPTIONS\n.TP\n.B \\-\nload and execute the standard input as a file,\nthat is,\nnot interactively,\neven when the standard input is a terminal.\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\nYou need to quote\n.I stat \nif it contains spaces, quotes,\nor other characters special to the shell.\n.TP\n.B \\-i\nenter interactive mode after\n.I script\nis executed.\n.TP\n.BI \\-l \" name\"\ncall\n.BI require(' name ')\nbefore executing\n.IR script .\nTypically used to load libraries.\n.TP\n.B \\-v\nshow version information.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nhttp://www.lua.org/\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nand\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.1.5/doc/lua.css",
    "content": "body {\n\tcolor: #000000 ;\n\tbackground-color: #FFFFFF ;\n\tfont-family: Helvetica, Arial, sans-serif ;\n\ttext-align: justify ;\n\tmargin-right: 30px ;\n\tmargin-left: 30px ;\n}\n\nh1, h2, h3, h4 {\n\tfont-family: Verdana, Geneva, sans-serif ;\n\tfont-weight: normal ;\n\tfont-style: italic ;\n}\n\nh2 {\n\tpadding-top: 0.4em ;\n\tpadding-bottom: 0.4em ;\n\tpadding-left: 30px ;\n\tpadding-right: 30px ;\n\tmargin-left: -30px ;\n\tbackground-color: #E0E0FF ;\n}\n\nh3 {\n\tpadding-left: 0.5em ;\n\tborder-left: solid #E0E0FF 1em ;\n}\n\ntable h3 {\n\tpadding-left: 0px ;\n\tborder-left: none ;\n}\n\na:link {\n\tcolor: #000080 ;\n\tbackground-color: inherit ;\n\ttext-decoration: none ;\n}\n\na:visited {\n\tbackground-color: inherit ;\n\ttext-decoration: none ;\n}\n\na:link:hover, a:visited:hover {\n\tcolor: #000080 ;\n\tbackground-color: #E0E0FF ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\nhr {\n\tborder: 0 ;\n\theight: 1px ;\n\tcolor: #a0a0a0 ;\n\tbackground-color: #a0a0a0 ;\n}\n\n:target {\n\tbackground-color: #F8F8F8 ;\n\tpadding: 8px ;\n\tborder: solid #a0a0a0 2px ;\n}\n\n.footer {\n\tcolor: gray ;\n\tfont-size: small ;\n}\n\ninput[type=text] {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 2em ;\n\t-moz-border-radius: 2em ;\n\tbackground-image: url('images/search.png') ;\n\tbackground-repeat: no-repeat;\n\tbackground-position: 4px center ;\n\tpadding-left: 20px ;\n\theight: 2em ;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/doc/lua.html",
    "content": "<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -->\n<HTML>\n<HEAD>\n<TITLE>LUA man page</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY BGCOLOR=\"#FFFFFF\">\n\n<H2>NAME</H2>\nlua - Lua interpreter\n<H2>SYNOPSIS</H2>\n<B>lua</B>\n[\n<I>options</I>\n]\n[\n<I>script</I>\n[\n<I>args</I>\n]\n]\n<H2>DESCRIPTION</H2>\n<B>lua</B>\nis the stand-alone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n<B>luac</B>,\nthe Lua compiler.)\n<B>lua</B>\ncan be used as a batch interpreter and also interactively.\n<P>\nThe given\n<I>options</I>\n(see below)\nare executed and then\nthe Lua program in file\n<I>script</I>\nis loaded and executed.\nThe given\n<I>args</I>\nare available to\n<I>script</I>\nas strings in a global table named\n<B>arg</B>.\nIf these arguments contain spaces or other characters special to the shell,\nthen they should be quoted\n(but note that the quotes will be removed by the shell).\nThe arguments in\n<B>arg</B>\nstart at 0,\nwhich contains the string\n'<I>script</I>'.\nThe index of the last argument is stored in\n<B>arg.n</B>.\nThe arguments given in the command line before\n<I>script</I>,\nincluding the name of the interpreter,\nare available in negative indices in\n<B>arg</B>.\n<P>\nAt the very start,\nbefore even handling the command line,\n<B>lua</B>\nexecutes the contents of the environment variable\n<B>LUA_INIT</B>,\nif it is defined.\nIf the value of\n<B>LUA_INIT</B>\nis of the form\n'@<I>filename</I>',\nthen\n<I>filename</I>\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n<P>\nOptions start with\n<B>'-'</B>\nand are described below.\nYou can use\n<B>'--'</B>\nto signal the end of options.\n<P>\nIf no arguments are given,\nthen\n<B>\"-v -i\"</B>\nis assumed when the standard input is a terminal;\notherwise,\n<B>\"-\"</B>\nis assumed.\n<P>\nIn interactive mode,\n<B>lua</B>\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\nSo, one way to interrupt the reading of an incomplete statement is\nto force a syntax error:\nadding a\n<B>';'</B>\nin the middle of a statement is a sure way of forcing a syntax error\n(except inside multiline strings and comments; these must be closed explicitly).\nIf a line starts with\n<B>'='</B>,\nthen\n<B>lua</B>\ndisplays the values of all the expressions in the remainder of the\nline. The expressions must be separated by commas.\nThe primary prompt is the value of the global variable\n<B>_PROMPT</B>,\nif this value is a string;\notherwise, the default prompt is used.\nSimilarly, the secondary prompt is the value of the global variable\n<B>_PROMPT2</B>.\nSo,\nto change the prompts,\nset the corresponding variable to a string of your choice.\nYou can do that after calling the interpreter\nor on the command line\n(but in this case you have to be careful with quotes\nif the prompt string contains a space; otherwise you may confuse the shell.)\nThe default prompts are \"&gt; \" and \"&gt;&gt; \".\n<H2>OPTIONS</H2>\n<P>\n<B>-</B>\nload and execute the standard input as a file,\nthat is,\nnot interactively,\neven when the standard input is a terminal.\n<P>\n<B>-e </B><I>stat</I>\nexecute statement\n<I>stat</I>.\nYou need to quote\n<I>stat </I>\nif it contains spaces, quotes,\nor other characters special to the shell.\n<P>\n<B>-i</B>\nenter interactive mode after\n<I>script</I>\nis executed.\n<P>\n<B>-l </B><I>name</I>\ncall\n<B>require</B>('<I>name</I>')\nbefore executing\n<I>script</I>.\nTypically used to load libraries.\n<P>\n<B>-v</B>\nshow version information.\n<H2>SEE ALSO</H2>\n<B>luac</B>(1)\n<BR>\n<A HREF=\"http://www.lua.org/\">http://www.lua.org/</A>\n<H2>DIAGNOSTICS</H2>\nError messages should be self explanatory.\n<H2>AUTHORS</H2>\nR. Ierusalimschy,\nL. H. de Figueiredo,\nand\nW. Celes\n<!-- EOF -->\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.1.5/doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $\n.TH LUAC 1 \"$Date: 2006/01/06 16:03:34 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files that can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\n.LP\nPre-compiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\n.LP\nPre-compiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in pre-compiling is faster loading.\n.LP\nThe binary files created by\n.B luac\nare portable only among architectures with the same word size and byte order.\n.LP\n.B luac\nproduces a single output file containing the bytecodes\nfor all source files given.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\nThis is useful to combine several precompiled chunks,\neven from different (but compatible) platforms,\ninto a single precompiled chunk.\n.LP\nYou can use\n.B \"'\\-'\"\nto indicate the standard input as a source file\nand\n.B \"'\\--'\"\nto signal the end of options\n(that is,\nall remaining arguments will be treated as files even if they start with\n.BR \"'\\-'\" ).\n.LP\nThe internal format of the binary files produced by\n.B luac\nis likely to change when a new version of Lua is released.\nSo,\nsave the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\nOptions must be separate.\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be a source file because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nLua always performs a thorough integrity test on precompiled chunks.\nBytecode that passes this test is completely safe,\nin the sense that it will not break the interpreter.\nHowever,\nthere is no guarantee that such code does anything sensible.\n(None can be given, because the halting problem is unsolvable.)\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file passes the integrity test.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nFor instance,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.SH FILES\n.TP 15\n.B luac.out\ndefault output file\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nhttp://www.lua.org/\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nL. H. de Figueiredo,\nR. Ierusalimschy and\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.1.5/doc/luac.html",
    "content": "<!-- $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ -->\n<HTML>\n<HEAD>\n<TITLE>LUAC man page</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY BGCOLOR=\"#FFFFFF\">\n\n<H2>NAME</H2>\nluac - Lua compiler\n<H2>SYNOPSIS</H2>\n<B>luac</B>\n[\n<I>options</I>\n] [\n<I>filenames</I>\n]\n<H2>DESCRIPTION</H2>\n<B>luac</B>\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files that can be later loaded and executed.\n<P>\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\n<P>\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n<B>luac</B>\nsimply allows those bytecodes to be saved in a file for later execution.\n<P>\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n<P>\nThe binary files created by\n<B>luac</B>\nare portable only among architectures with the same word size and byte order.\n<P>\n<B>luac</B>\nproduces a single output file containing the bytecodes\nfor all source files given.\nBy default,\nthe output file is named\n<B>luac.out</B>,\nbut you can change this with the\n<B>-o</B>\noption.\n<P>\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\nThis is useful because several precompiled chunks,\neven from different (but compatible) platforms,\ncan be combined into a single precompiled chunk.\n<P>\nYou can use\n<B>'-'</B>\nto indicate the standard input as a source file\nand\n<B>'--'</B>\nto signal the end of options\n(that is,\nall remaining arguments will be treated as files even if they start with\n<B>'-'</B>).\n<P>\nThe internal format of the binary files produced by\n<B>luac</B>\nis likely to change when a new version of Lua is released.\nSo,\nsave the source files of all Lua programs that you precompile.\n<P>\n<H2>OPTIONS</H2>\nOptions must be separate.\n<P>\n<B>-l</B>\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n<B>luac</B>\nloads\n<B>luac.out</B>\nand lists its contents.\n<P>\n<B>-o </B><I>file</I>\noutput to\n<I>file</I>,\ninstead of the default\n<B>luac.out</B>.\n(You can use\n<B>'-'</B>\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be a source file because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n<P>\n<B>-p</B>\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nLua always performs a thorough integrity test on precompiled chunks.\nBytecode that passes this test is completely safe,\nin the sense that it will not break the interpreter.\nHowever,\nthere is no guarantee that such code does anything sensible.\n(None can be given, because the halting problem is unsolvable.)\nIf no files are given, then\n<B>luac</B>\nloads\n<B>luac.out</B>\nand tests its contents.\nNo messages are displayed if the file passes the integrity test.\n<P>\n<B>-s</B>\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nFor instance,\nline numbers and names of local variables are lost.\n<P>\n<B>-v</B>\nshow version information.\n<H2>FILES</H2>\n<P>\n<B>luac.out</B>\ndefault output file\n<H2>SEE ALSO</H2>\n<B>lua</B>(1)\n<BR>\n<A HREF=\"http://www.lua.org/\">http://www.lua.org/</A>\n<H2>DIAGNOSTICS</H2>\nError messages should be self explanatory.\n<H2>AUTHORS</H2>\nL. H. de Figueiredo,\nR. Ierusalimschy and\nW. Celes\n<!-- EOF -->\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.1.5/doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n\tfont-size: inherit ;\n}\n\npre, code {\n\tfont-size: 12pt ;\n}\n\nspan.apii {\n\tfloat: right ;\n\tfont-family: inherit ;\n\tfont-style: normal ;\n\tfont-size: small ;\n\tcolor: gray ;\n}\n\np+h1, ul+h1 {\n\tpadding-top: 0.4em ;\n\tpadding-bottom: 0.4em ;\n\tpadding-left: 30px ;\n\tmargin-left: -30px ;\n\tbackground-color: #E0E0FF ;\n}\n"
  },
  {
    "path": "build/lua-5.1.5/doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\n\n<head>\n<title>Lua 5.1 Reference Manual</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"lua.css\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</head>\n\n<body>\n\n<hr>\n<h1>\n<a href=\"http://www.lua.org/\"><img src=\"logo.gif\" alt=\"\" border=\"0\"></a>\nLua 5.1 Reference Manual\n</h1>\n\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n<p>\n<small>\nCopyright &copy; 2006&ndash;2012 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html\">Lua license</a>.\n</small>\n<hr>\n<p>\n\n<a href=\"contents.html#contents\">contents</A>\n&middot;\n<a href=\"contents.html#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of,v 1.49.1.2 2012/01/13 20:23:26 roberto Exp $ -->\n\n\n\n\n<h1>1 - <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is an extension programming language designed to support\ngeneral procedural programming with data description\nfacilities.\nIt also offers good support for object-oriented programming,\nfunctional programming, and data-driven programming.\nLua is intended to be used as a powerful, light-weight\nscripting language for any program that needs one.\nLua is implemented as a library, written in <em>clean</em> C\n(that is, in the common subset of ANSI&nbsp;C and C++).\n\n\n<p>\nBeing an extension language, Lua has no notion of a \"main\" program:\nit only works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\nThis host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\nThe Lua distribution includes a sample host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete, stand-alone Lua interpreter.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua (Second Edition)</em>.\n\n\n\n<h1>2 - <a name=\"2\">The Language</a></h1>\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nThe language constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like `<b>=</b>&acute;.\nThe complete syntax of Lua can be found in <a href=\"#8\">&sect;8</a>\nat the end of this manual.\n\n\n\n<h2>2.1 - <a name=\"2.1\">Lexical Conventions</a></h2>\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of letters,\ndigits, and underscores,\nnot beginning with a digit.\nThis coincides with the definition of names in most languages.\n(The definition of letter depends on the current locale:\nany character considered alphabetic by the current locale\ncan be used in an identifier.)\nIdentifiers are used to name variables and table fields.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif\n     end       false     for       function  if\n     in        local     nil       not       or\n     repeat    return    then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention, names starting with an underscore followed by\nuppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>)\nare reserved for internal global variables used by Lua.\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\n<em>Literal strings</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nMoreover, a backslash followed by a real newline\nresults in a newline in the string.\nA character in a string can also be specified by its numerical value\nusing the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a numerical escape is to be followed by a digit,\nit must be expressed using exactly three digits.)\nStrings in Lua can contain any 8-bit value, including embedded zeros,\nwhich can be specified as '<code>\\0</code>'.\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>,\nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>,\nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance, a closing long bracket of level&nbsp;4 is written as <code>]====]</code>.\nA long string starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nThey can contain anything except a closing bracket of the proper level.\n\n\n<p>\nFor convenience,\nwhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nA <em>numerical constant</em> can be written with an optional decimal part\nand an optional decimal exponent.\nLua also accepts integer hexadecimal constants,\nby prefixing them with <code>0x</code>.\nExamples of valid numerical constants are\n\n<pre>\n     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\nLong comments are frequently used to disable code temporarily.\n\n\n\n\n\n<h2>2.2 - <a name=\"2.2\">Values and Types</a></h2>\n\n<p>\nLua is a <em>dynamically typed language</em>.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are <em>first-class values</em>.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\n<em>Nil</em> is the type of the value <b>nil</b>,\nwhose main property is to be different from any other value;\nit usually represents the absence of a useful value.\n<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nany other value makes it true.\n<em>Number</em> represents real (double-precision floating-point) numbers.\n(It is easy to build Lua interpreters that use other\ninternal representations for numbers,\nsuch as single-precision float or long integers;\nsee file <code>luaconf.h</code>.)\n<em>String</em> represents arrays of characters.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit character,\nincluding embedded zeros ('<code>\\0</code>') (see <a href=\"#2.1\">&sect;2.1</a>).\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C\n(see <a href=\"#2.5.8\">&sect;2.5.8</a>).\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nThis type corresponds to a block of raw memory\nand has no pre-defined operations in Lua,\nexcept assignment and identity test.\nHowever, by using <em>metatables</em>,\nthe programmer can define operations for userdata values\n(see <a href=\"#2.8\">&sect;2.8</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by the host program.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.11\">&sect;2.11</a>).\nDo not confuse Lua threads with operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can be indexed not only with numbers,\nbut with any value (except <b>nil</b>).\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nTables are the sole data structuring mechanism in Lua;\nthey can be used to represent ordinary arrays,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#2.5.7\">&sect;2.5.7</a>).\n\n\n<p>\nLike indices,\nthe value of a table field can be of any type (except <b>nil</b>).\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#2.5.9\">&sect;2.5.9</a>).\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value.\n\n\n\n<h3>2.2.1 - <a name=\"2.2.1\">Coercion</a></h3>\n\n<p>\nLua provides automatic conversion between\nstring and number values at run time.\nAny arithmetic operation applied to a string tries to convert\nthis string to a number, following the usual conversion rules.\nConversely, whenever a number is used where a string is expected,\nthe number is converted to a string, in a reasonable format.\nFor complete control over how numbers are converted to strings,\nuse the <code>format</code> function from the string library\n(see <a href=\"#pdf-string.format\"><code>string.format</code></a>).\n\n\n\n\n\n\n\n<h2>2.3 - <a name=\"2.3\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\n\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers, as defined in <a href=\"#2.1\">&sect;2.1</a>.\n\n\n<p>\nAny variable is assumed to be global unless explicitly declared\nas a local (see <a href=\"#2.4.7\">&sect;2.4.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#2.6\">&sect;2.6</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute;\n</pre><p>\nThe meaning of accesses to global variables \nand table fields can be changed via metatables.\nAn access to an indexed variable <code>t[i]</code> is equivalent to\na call <code>gettable_event(t,i)</code>.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp `<b>.</b>&acute; Name\n</pre>\n\n<p>\nAll global variables live as fields in ordinary Lua tables,\ncalled <em>environment tables</em> or simply\n<em>environments</em> (see <a href=\"#2.9\">&sect;2.9</a>).\nEach function has its own reference to an environment,\nso that all global variables in this function\nwill refer to this environment table.\nWhen a function is created,\nit inherits the environment from the function that created it.\nTo get the environment table of a Lua function,\nyou call <a href=\"#pdf-getfenv\"><code>getfenv</code></a>.\nTo replace it,\nyou call <a href=\"#pdf-setfenv\"><code>setfenv</code></a>.\n(You can only manipulate the environment of C&nbsp;functions\nthrough the debug library; (see <a href=\"#5.9\">&sect;5.9</a>).)\n\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_env.x</code>,\nwhich in turn is equivalent to\n\n<pre>\n     gettable_event(_env, \"x\")\n</pre><p>\nwhere <code>_env</code> is the environment of the running function.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nSimilarly, the <code>_env</code> variable is not defined in Lua.\nWe use them here only for explanatory purposes.)\n\n\n\n\n\n<h2>2.4 - <a name=\"2.4\">Statements</a></h2>\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in Pascal or C.\nThis set includes\nassignments, control structures, function calls,\nand variable declarations.\n\n\n\n<h3>2.4.1 - <a name=\"2.4.1\">Chunks</a></h3>\n\n<p>\nThe unit of execution of Lua is called a <em>chunk</em>.\nA chunk is simply a sequence of statements,\nwhich are executed sequentially.\nEach statement can be optionally followed by a semicolon:\n\n<pre>\n\tchunk ::= {stat [`<b>;</b>&acute;]}\n</pre><p>\nThere are no empty statements and thus '<code>;;</code>' is not legal.\n\n\n<p>\nLua handles a chunk as the body of an anonymous function \nwith a variable number of arguments\n(see <a href=\"#2.5.9\">&sect;2.5.9</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first pre-compiles the chunk into instructions for a virtual machine,\nand then it executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be pre-compiled into binary form;\nsee program <code>luac</code> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly.\n\n\n\n\n\n\n<h3>2.4.2 - <a name=\"2.4.2\">Blocks</a></h3><p>\nA block is a list of statements;\nsyntactically, a block is the same as a chunk:\n\n<pre>\n\tblock ::= chunk\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> or <b>break</b> statement in the middle\nof another block (see <a href=\"#2.4.4\">&sect;2.4.4</a>).\n\n\n\n\n\n<h3>2.4.3 - <a name=\"2.4.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist `<b>=</b>&acute; explist\n\tvarlist ::= var {`<b>,</b>&acute; var}\n\texplist ::= exp {`<b>,</b>&acute; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#2.5\">&sect;2.5</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with as many  <b>nil</b>'s as needed.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then are the assignments performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nThe meaning of assignments to global variables\nand table fields can be changed via metatables.\nAn assignment to an indexed variable <code>t[i] = val</code> is equivalent to\n<code>settable_event(t,i,val)</code>.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>settable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nAn assignment to a global variable <code>x = val</code>\nis equivalent to the assignment\n<code>_env.x = val</code>,\nwhich in turn is equivalent to\n\n<pre>\n     settable_event(_env, \"x\", val)\n</pre><p>\nwhere <code>_env</code> is the environment of the running function.\n(The <code>_env</code> variable is not defined in Lua.\nWe use it here only for explanatory purposes.)\n\n\n\n\n\n<h3>2.4.4 - <a name=\"2.4.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#2.4.5\">&sect;2.4.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> are considered false.\nAll values different from <b>nil</b> and <b>false</b> are considered true\n(in particular, the number 0 and the empty string are also true).\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk (which is just a function).\n\nFunctions and chunks can return more than one value,\nand so the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist]\n</pre>\n\n<p>\nThe <b>break</b> statement is used to terminate the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> and <b>break</b>\nstatements can only be written as the <em>last</em> statement of a block.\nIf it is really necessary to <b>return</b> or <b>break</b> in the\nmiddle of a block,\nthen an explicit inner block can be used,\nas in the idioms\n<code>do return end</code> and <code>do break end</code>,\nbecause now <b>return</b> and <b>break</b> are the last statements in\ntheir (inner) blocks.\n\n\n\n\n\n<h3>2.4.5 - <a name=\"2.4.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numeric and one generic.\n\n\n<p>\nThe numeric <b>for</b> loop repeats a block of code while a\ncontrol variable runs through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe <em>block</em> is repeated for <em>name</em> starting at the value of\nthe first <em>exp</em>, until it passes the second <em>exp</em> by steps of the\nthird <em>exp</em>.\nMore precisely, a <b>for</b> statement like\n\n<pre>\n     for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)\n       if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end\n       while (<em>step</em> &gt; 0 and <em>var</em> &lt;= <em>limit</em>) or (<em>step</em> &lt;= 0 and <em>var</em> &gt;= <em>limit</em>) do\n         local v = <em>var</em>\n         <em>block</em>\n         <em>var</em> = <em>var</em> + <em>step</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\nAll three control expressions are evaluated only once,\nbefore the loop starts.\nThey must all result in numbers.\n</li>\n\n<li>\n<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.\nThe names shown here are for explanatory purposes only.\n</li>\n\n<li>\nIf the third expression (the step) is absent,\nthen a step of&nbsp;1 is used.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variable <code>v</code> is local to the loop;\nyou cannot use its value after the <b>for</b> ends or is broken.\nIf you need this value,\nassign it to another variable before breaking or exiting the loop.\n</li>\n\n</ul>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {`<b>,</b>&acute; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>\n       while true do\n         local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)\n         <em>var</em> = <em>var_1</em>\n         if <em>var</em> == nil then break end\n         <em>block</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\n<code><em>explist</em></code> is evaluated only once.\nIts results are an <em>iterator</em> function,\na <em>state</em>,\nand an initial value for the first <em>iterator variable</em>.\n</li>\n\n<li>\n<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.\nThe names are here for explanatory purposes only.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variables <code><em>var_i</em></code> are local to the loop;\nyou cannot use their values after the <b>for</b> ends.\nIf you need these values,\nthen assign them to other variables before breaking or exiting the loop.\n</li>\n\n</ul>\n\n\n\n\n<h3>2.4.6 - <a name=\"2.4.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#2.5.8\">&sect;2.5.8</a>.\n\n\n\n\n\n<h3>2.4.7 - <a name=\"2.4.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initial assignment:\n\n<pre>\n\tstat ::= <b>local</b> namelist [`<b>=</b>&acute; explist]\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#2.4.3\">&sect;2.4.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nA chunk is also a block (see <a href=\"#2.4.1\">&sect;2.4.1</a>),\nand so local variables can be declared in a chunk outside any explicit block.\nThe scope of such local variables extends until the end of the chunk.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#2.6\">&sect;2.6</a>.\n\n\n\n\n\n\n\n<h2>2.5 - <a name=\"2.5\">Expressions</a></h2>\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Number\n\texp ::= String\n\texp ::= function\n\texp ::= tableconstructor\n\texp ::= `<b>...</b>&acute;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;\n</pre>\n\n<p>\nNumbers and literal strings are explained in <a href=\"#2.1\">&sect;2.1</a>;\nvariables are explained in <a href=\"#2.3\">&sect;2.3</a>;\nfunction definitions are explained in <a href=\"#2.5.9\">&sect;2.5.9</a>;\nfunction calls are explained in <a href=\"#2.5.8\">&sect;2.5.8</a>;\ntable constructors are explained in <a href=\"#2.5.7\">&sect;2.5.7</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#2.5.9\">&sect;2.5.9</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#2.5.1\">&sect;2.5.1</a>),\nrelational operators (see <a href=\"#2.5.2\">&sect;2.5.2</a>), logical operators (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nand the concatenation operator (see <a href=\"#2.5.4\">&sect;2.5.4</a>).\nUnary operators comprise the unary minus (see <a href=\"#2.5.1\">&sect;2.5.1</a>),\nthe unary <b>not</b> (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nand the unary <em>length operator</em> (see <a href=\"#2.5.5\">&sect;2.5.5</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf an expression is used as a statement\n(only possible for function calls (see <a href=\"#2.4.6\">&sect;2.4.6</a>)),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the call is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\ndiscarding all values except the first one.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg parameter, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg parameter)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg parameters\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg parameters\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n<h3>2.5.1 - <a name=\"2.5.1\">Arithmetic Operators</a></h3><p>\nLua supports the usual arithmetic operators:\nthe binary <code>+</code> (addition),\n<code>-</code> (subtraction), <code>*</code> (multiplication),\n<code>/</code> (division), <code>%</code> (modulo), and <code>^</code> (exponentiation);\nand unary <code>-</code> (negation).\nIf the operands are numbers, or strings that can be converted to\nnumbers (see <a href=\"#2.2.1\">&sect;2.2.1</a>),\nthen all operations have the usual meaning.\nExponentiation works for any exponent.\nFor instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>.\nModulo is defined as\n\n<pre>\n     a % b == a - math.floor(a/b)*b\n</pre><p>\nThat is, it is the remainder of a division that rounds\nthe quotient towards minus infinity.\n\n\n\n\n\n<h3>2.5.2 - <a name=\"2.5.2\">Relational Operators</a></h3><p>\nThe relational operators in Lua are\n\n<pre>\n     ==    ~=    &lt;     &gt;     &lt;=    &gt;=\n</pre><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nNumbers and strings are compared in the usual way.\nObjects (tables, userdata, threads, and functions)\nare compared by <em>reference</em>:\ntwo objects are considered equal only if they are the <em>same</em> object.\nEvery time you create a new object\n(a table, userdata, thread, or function),\nthis new object is different from any previously existing object.\n\n\n<p>\nYou can change the way that Lua compares tables and userdata \nby using the \"eq\" metamethod (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n<p>\nThe conversion rules of <a href=\"#2.2.1\">&sect;2.2.1</a>\n<em>do not</em> apply to equality comparisons.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers, then they are compared as such.\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the \"lt\" or the \"le\"\nmetamethod (see <a href=\"#2.8\">&sect;2.8</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n\n\n\n<h3>2.5.3 - <a name=\"2.5.3\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#2.4.4\">&sect;2.4.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-cut evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre><p>\n(In this manual,\n<code>--&gt;</code> indicates the result of the preceding expression.)\n\n\n\n\n\n<h3>2.5.4 - <a name=\"2.5.4\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers, then they are converted to\nstrings according to the rules mentioned in <a href=\"#2.2.1\">&sect;2.2.1</a>.\nOtherwise, the \"concat\" metamethod is called (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<h3>2.5.5 - <a name=\"2.5.5\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary operator <code>#</code>.\nThe length of a string is its number of bytes\n(that is, the usual meaning of string length when each\ncharacter is one byte).\n\n\n<p>\nThe length of a table <code>t</code> is defined to be any\ninteger index <code>n</code>\nsuch that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;\nmoreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> can be zero.\nFor a regular array, with non-nil values from 1 to a given <code>n</code>,\nits length is exactly that <code>n</code>,\nthe index of its last value.\nIf the array has \"holes\"\n(that is, <b>nil</b> values between other non-nil values),\nthen <code>#t</code> can be any of the indices that\ndirectly precedes a <b>nil</b> value\n(that is, it may consider any such <b>nil</b> value as the end of\nthe array). \n\n\n\n\n\n<h3>2.5.6 - <a name=\"2.5.6\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     ..\n     +     -\n     *     /     %\n     not   #     - (unary)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>2.5.7 - <a name=\"2.5.7\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp\n\tfieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFinally, fields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive numerical integers,\nstarting with 1.\nFields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#2.5.8\">&sect;2.5.8</a>).\nTo avoid this,\nenclose the function call or the vararg expression\nin parentheses (see <a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>2.5.8 - <a name=\"2.5.8\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, the prefixexp \"call\" metamethod is called,\nhaving as first parameter the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp `<b>:</b>&acute; Name args\n</pre><p>\ncan be used to call \"methods\".\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= `<b>(</b>&acute; [explist] `<b>)</b>&acute;\n\targs ::= tableconstructor\n\targs ::= String\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nAs an exception to the free-format syntax of Lua,\nyou cannot put a line break before the '<code>(</code>' in a function call.\nThis restriction avoids some ambiguities in the language.\nIf you write\n\n<pre>\n     a = f\n     (g).x(a)\n</pre><p>\nLua would see that as a single statement, <code>a = f(g).x(a)</code>.\nSo, if you want two statements, you must add a semi-colon between them.\nIf you actually want to call <code>f</code>,\nyou must remove the line break before <code>(g)</code>.\n\n\n<p>\nA call of the form <code>return</code> <em>functioncall</em> is called\na <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument;\nthis syntax makes the calling function return exactly\nthe returns of the called function.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>2.5.9 - <a name=\"2.5.9\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunction ::= <b>function</b> funcbody\n\tfuncbody ::= `<b>(</b>&acute; [parlist] `<b>)</b>&acute; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\n<em>not</em> to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua pre-compiles a chunk,\nall its function bodies are pre-compiled too.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance (or <em>closure</em>)\nis the final value of the expression.\nDifferent instances of the same function\ncan refer to different  external local variables\nand can have different environment tables.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;\n</pre><p>\nWhen a function is called,\nthe list of arguments is adjusted to\nthe length of the list of parameters,\nunless the function is a variadic or <em>vararg function</em>,\nwhich is\nindicated by three dots ('<code>...</code>') at the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL            PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#2.4.4\">&sect;2.4.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\nThe <em>colon</em> syntax\nis used for defining <em>methods</em>,\nthat is, functions that have an implicit extra parameter <code>self</code>.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>2.6 - <a name=\"2.6\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of variables begins at the first statement <em>after</em>\ntheir declaration and lasts until the end of the innermost block that\nincludes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called\nan <em>upvalue</em>, or <em>external local variable</em>,\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i=1,10 do\n       local y = 0\n       a[i] = function () y=y+1; return x+y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h2>2.7 - <a name=\"2.7\">Error Handling</a></h2>\n\n<p>\nBecause Lua is an embedded extension language,\nall Lua actions start from C&nbsp;code in the host program\ncalling a function from the Lua library (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\nWhenever an error occurs during Lua compilation or execution,\ncontrol returns to C,\nwhich can take appropriate measures\n(such as printing an error message).\n\n\n<p>\nLua code can explicitly generate an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\nIf you need to catch errors in Lua,\nyou can use the <a href=\"#pdf-pcall\"><code>pcall</code></a> function.\n\n\n\n\n\n<h2>2.8 - <a name=\"2.8\">Metatables</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain special operations.\nYou can change several aspects of the behavior\nof operations over a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field <code>\"__add\"</code> in its metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nWe call the keys in a metatable <em>events</em>\nand the values <em>metamethods</em>.\nIn the previous example, the event is <code>\"add\"</code> \nand the metamethod is the function that performs the addition.\n\n\n<p>\nYou can query the metatable of any value\nthrough the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\n\n\n<p>\nYou can replace the metatable of tables\nthrough the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a>\nfunction.\nYou cannot change the metatable of other types from Lua\n(except by using the debug library);\nyou must use the C&nbsp;API for that.\n\n\n<p>\nTables and full userdata have individual metatables\n(although multiple tables and userdata can share their metatables).\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\n\n\n<p>\nA metatable controls how an object behaves in arithmetic operations,\norder comparisons, concatenation, length operation, and indexing.\nA metatable also can define a function to be called when a userdata\nis garbage collected.\nFor each of these operations Lua associates a specific key\ncalled an <em>event</em>.\nWhen Lua performs one of these operations over a value,\nit checks whether this value has a metatable with the corresponding event.\nIf so, the value associated with that key (the metamethod)\ncontrols how Lua will perform the operation.\n\n\n<p>\nMetatables control the operations listed next.\nEach operation is identified by its corresponding name.\nThe key for each operation is a string with its name prefixed by\ntwo underscores, '<code>__</code>';\nfor instance, the key for operation \"add\" is the\nstring <code>\"__add\"</code>.\nThe semantics of these operations is better explained by a Lua function\ndescribing how the interpreter executes the operation.\n\n\n<p>\nThe code shown here in Lua is only illustrative;\nthe real behavior is hard coded in the interpreter\nand it is much more efficient than this simulation.\nAll functions used in these descriptions\n(<a href=\"#pdf-rawget\"><code>rawget</code></a>, <a href=\"#pdf-tonumber\"><code>tonumber</code></a>, etc.)\nare described in <a href=\"#5.1\">&sect;5.1</a>.\nIn particular, to retrieve the metamethod of a given object,\nwe use the expression\n\n<pre>\n     metatable(obj)[event]\n</pre><p>\nThis should be read as\n\n<pre>\n     rawget(getmetatable(obj) or {}, event)\n</pre><p>\n\nThat is, the access to a metamethod does not invoke other metamethods,\nand the access to objects with no metatables does not fail\n(it simply results in <b>nil</b>).\n\n\n\n<ul>\n\n<li><b>\"add\":</b>\nthe <code>+</code> operation.\n\n\n\n<p>\nThe function <code>getbinhandler</code> below defines how Lua chooses a handler\nfor a binary operation.\nFirst, Lua tries the first operand.\nIf its type does not define a handler for the operation,\nthen Lua tries the second operand.\n\n<pre>\n     function getbinhandler (op1, op2, event)\n       return metatable(op1)[event] or metatable(op2)[event]\n     end\n</pre><p>\nBy using this function,\nthe behavior of the <code>op1 + op2</code> is\n\n<pre>\n     function add_event (op1, op2)\n       local o1, o2 = tonumber(op1), tonumber(op2)\n       if o1 and o2 then  -- both operands are numeric?\n         return o1 + o2   -- '+' here is the primitive 'add'\n       else  -- at least one of the operands is not numeric\n         local h = getbinhandler(op1, op2, \"__add\")\n         if h then\n           -- call the handler with both operands\n           return (h(op1, op2))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"sub\":</b>\nthe <code>-</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"mul\":</b>\nthe <code>*</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"div\":</b>\nthe <code>/</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"mod\":</b>\nthe <code>%</code> operation.\n\nBehavior similar to the \"add\" operation,\nwith the operation\n<code>o1 - floor(o1/o2)*o2</code> as the primitive operation.\n</li>\n\n<li><b>\"pow\":</b>\nthe <code>^</code> (exponentiation) operation.\n\nBehavior similar to the \"add\" operation,\nwith the function <code>pow</code> (from the C&nbsp;math library)\nas the primitive operation.\n</li>\n\n<li><b>\"unm\":</b>\nthe unary <code>-</code> operation.\n\n\n<pre>\n     function unm_event (op)\n       local o = tonumber(op)\n       if o then  -- operand is numeric?\n         return -o  -- '-' here is the primitive 'unm'\n       else  -- the operand is not numeric.\n         -- Try to get a handler from the operand\n         local h = metatable(op).__unm\n         if h then\n           -- call the handler with the operand\n           return (h(op))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"concat\":</b>\nthe <code>..</code> (concatenation) operation.\n\n\n<pre>\n     function concat_event (op1, op2)\n       if (type(op1) == \"string\" or type(op1) == \"number\") and\n          (type(op2) == \"string\" or type(op2) == \"number\") then\n         return op1 .. op2  -- primitive string concatenation\n       else\n         local h = getbinhandler(op1, op2, \"__concat\")\n         if h then\n           return (h(op1, op2))\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"len\":</b>\nthe <code>#</code> operation.\n\n\n<pre>\n     function len_event (op)\n       if type(op) == \"string\" then\n         return strlen(op)         -- primitive string length\n       elseif type(op) == \"table\" then\n         return #op                -- primitive table length\n       else\n         local h = metatable(op).__len\n         if h then\n           -- call the handler with the operand\n           return (h(op))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\nSee <a href=\"#2.5.5\">&sect;2.5.5</a> for a description of the length of a table.\n</li>\n\n<li><b>\"eq\":</b>\nthe <code>==</code> operation.\n\nThe function <code>getcomphandler</code> defines how Lua chooses a metamethod\nfor comparison operators.\nA metamethod only is selected when both objects\nbeing compared have the same type\nand the same metamethod for the selected operation.\n\n<pre>\n     function getcomphandler (op1, op2, event)\n       if type(op1) ~= type(op2) then return nil end\n       local mm1 = metatable(op1)[event]\n       local mm2 = metatable(op2)[event]\n       if mm1 == mm2 then return mm1 else return nil end\n     end\n</pre><p>\nThe \"eq\" event is defined as follows:\n\n<pre>\n     function eq_event (op1, op2)\n       if type(op1) ~= type(op2) then  -- different types?\n         return false   -- different objects\n       end\n       if op1 == op2 then   -- primitive equal?\n         return true   -- objects are equal\n       end\n       -- try metamethod\n       local h = getcomphandler(op1, op2, \"__eq\")\n       if h then\n         return (h(op1, op2))\n       else\n         return false\n       end\n     end\n</pre><p>\n<code>a ~= b</code> is equivalent to <code>not (a == b)</code>.\n</li>\n\n<li><b>\"lt\":</b>\nthe <code>&lt;</code> operation.\n\n\n<pre>\n     function lt_event (op1, op2)\n       if type(op1) == \"number\" and type(op2) == \"number\" then\n         return op1 &lt; op2   -- numeric comparison\n       elseif type(op1) == \"string\" and type(op2) == \"string\" then\n         return op1 &lt; op2   -- lexicographic comparison\n       else\n         local h = getcomphandler(op1, op2, \"__lt\")\n         if h then\n           return (h(op1, op2))\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n<code>a &gt; b</code> is equivalent to <code>b &lt; a</code>.\n</li>\n\n<li><b>\"le\":</b>\nthe <code>&lt;=</code> operation.\n\n\n<pre>\n     function le_event (op1, op2)\n       if type(op1) == \"number\" and type(op2) == \"number\" then\n         return op1 &lt;= op2   -- numeric comparison\n       elseif type(op1) == \"string\" and type(op2) == \"string\" then\n         return op1 &lt;= op2   -- lexicographic comparison\n       else\n         local h = getcomphandler(op1, op2, \"__le\")\n         if h then\n           return (h(op1, op2))\n         else\n           h = getcomphandler(op1, op2, \"__lt\")\n           if h then\n             return not h(op2, op1)\n           else\n             error(&middot;&middot;&middot;)\n           end\n         end\n       end\n     end\n</pre><p>\n<code>a &gt;= b</code> is equivalent to <code>b &lt;= a</code>.\nNote that, in the absence of a \"le\" metamethod,\nLua tries the \"lt\", assuming that <code>a &lt;= b</code> is\nequivalent to <code>not (b &lt; a)</code>.\n</li>\n\n<li><b>\"index\":</b>\nThe indexing access <code>table[key]</code>.\n\n\n<pre>\n     function gettable_event (table, key)\n       local h\n       if type(table) == \"table\" then\n         local v = rawget(table, key)\n         if v ~= nil then return v end\n         h = metatable(table).__index\n         if h == nil then return nil end\n       else\n         h = metatable(table).__index\n         if h == nil then\n           error(&middot;&middot;&middot;)\n         end\n       end\n       if type(h) == \"function\" then\n         return (h(table, key))     -- call the handler\n       else return h[key]           -- or repeat operation on it\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"newindex\":</b>\nThe indexing assignment <code>table[key] = value</code>.\n\n\n<pre>\n     function settable_event (table, key, value)\n       local h\n       if type(table) == \"table\" then\n         local v = rawget(table, key)\n         if v ~= nil then rawset(table, key, value); return end\n         h = metatable(table).__newindex\n         if h == nil then rawset(table, key, value); return end\n       else\n         h = metatable(table).__newindex\n         if h == nil then\n           error(&middot;&middot;&middot;)\n         end\n       end\n       if type(h) == \"function\" then\n         h(table, key,value)           -- call the handler\n       else h[key] = value             -- or repeat operation on it\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"call\":</b>\ncalled when Lua calls a value.\n\n\n<pre>\n     function function_event (func, ...)\n       if type(func) == \"function\" then\n         return func(...)   -- primitive call\n       else\n         local h = metatable(func).__call\n         if h then\n           return h(func, ...)\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n</ul>\n\n\n\n\n<h2>2.9 - <a name=\"2.9\">Environments</a></h2>\n\n<p>\nBesides metatables,\nobjects of types thread, function, and userdata\nhave another table associated with them,\ncalled their <em>environment</em>.\nLike metatables, environments are regular tables and\nmultiple objects can share the same environment.\n\n\n<p>\nThreads are created sharing the environment of the creating thread.\nUserdata and C&nbsp;functions are created sharing the environment\nof the creating C&nbsp;function.\nNon-nested Lua functions\n(created by <a href=\"#pdf-loadfile\"><code>loadfile</code></a>, <a href=\"#pdf-loadstring\"><code>loadstring</code></a> or <a href=\"#pdf-load\"><code>load</code></a>)\nare created sharing the environment of the creating thread.\nNested Lua functions are created sharing the environment of\nthe creating Lua function.\n\n\n<p>\nEnvironments associated with userdata have no meaning for Lua.\nIt is only a convenience feature for programmers to associate a table to\na userdata.\n\n\n<p>\nEnvironments associated with threads are called\n<em>global environments</em>.\nThey are used as the default environment for threads and\nnon-nested Lua functions created by the thread\nand can be directly accessed by C&nbsp;code (see <a href=\"#3.3\">&sect;3.3</a>).\n\n\n<p>\nThe environment associated with a C&nbsp;function can be directly\naccessed by C&nbsp;code (see <a href=\"#3.3\">&sect;3.3</a>).\nIt is used as the default environment for other C&nbsp;functions\nand userdata created by the function.\n\n\n<p>\nEnvironments associated with Lua functions are used to resolve\nall accesses to global variables within the function (see <a href=\"#2.3\">&sect;2.3</a>).\nThey are used as the default environment for nested Lua functions\ncreated by the function.\n\n\n<p>\nYou can change the environment of a Lua function or the\nrunning thread by calling <a href=\"#pdf-setfenv\"><code>setfenv</code></a>.\nYou can get the environment of a Lua function or the running thread\nby calling <a href=\"#pdf-getfenv\"><code>getfenv</code></a>.\nTo manipulate the environment of other objects\n(userdata, C&nbsp;functions, other threads) you must\nuse the C&nbsp;API.\n\n\n\n\n\n<h2>2.10 - <a name=\"2.10\">Garbage Collection</a></h2>\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou have to worry neither about allocating memory for new objects\nnor about freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> from time to time\nto collect all <em>dead objects</em>\n(that is, objects that are no longer accessible from Lua).\nAll memory used by Lua is subject to automatic management:\ntables, userdata, functions, threads, strings, etc.\n\n\n<p>\nLua implements an incremental mark-and-sweep collector.\nIt uses two numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em> and\nthe <em>garbage-collector step multiplier</em>.\nBoth use percentage points as units\n(so that a value of 100 means an internal value of 1).\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nLarger values make the collector less aggressive.\nValues smaller than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\n\n\n<p>\nThe step multiplier\ncontrols the relative speed of the collector relative to\nmemory allocation.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nValues smaller than 100 make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default, 200, means that the collector runs at \"twice\"\nthe speed of memory allocation.\n\n\n<p>\nYou can change these numbers by calling <a href=\"#lua_gc\"><code>lua_gc</code></a> in C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nWith these functions you can also control \nthe collector directly (e.g., stop and restart it).\n\n\n\n<h3>2.10.1 - <a name=\"2.10.1\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nUsing the C&nbsp;API,\nyou can set garbage-collector metamethods for userdata (see <a href=\"#2.8\">&sect;2.8</a>).\nThese metamethods are also called <em>finalizers</em>.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management\n(such as closing files, network or database connections,\nor freeing your own memory).\n\n\n<p>\nGarbage userdata with a field <code>__gc</code> in their metatables are not\ncollected immediately by the garbage collector.\nInstead, Lua puts them in a list.\nAfter the collection,\nLua does the equivalent of the following function\nfor each userdata in that list:\n\n<pre>\n     function gc_event (udata)\n       local h = metatable(udata).__gc\n       if h then\n         h(udata)\n       end\n     end\n</pre>\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers for userdata are called in <em>reverse</em>\norder of their creation,\namong those collected in that cycle.\nThat is, the first finalizer to be called is the one associated\nwith the userdata created last in the program.\nThe userdata itself is freed only in the next garbage-collection cycle.\n\n\n\n\n\n<h3>2.10.2 - <a name=\"2.10.2\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect this object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak keys allows the collection of its keys,\nbut prevents the collection of its values.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nIf the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',\nthe keys in the table are weak.\nIf <code>__mode</code> contains '<code>v</code>',\nthe values in the table are weak.\n\n\n<p>\nAfter you use a table as a metatable,\nyou should not change the value of its <code>__mode</code> field.\nOtherwise, the weak behavior of the tables controlled by this\nmetatable is undefined.\n\n\n\n\n\n\n\n<h2>2.11 - <a name=\"2.11\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine with a call to <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine execution.\n\n\n<p>\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution,\nat the first line of its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed on\nto the coroutine main function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn the first case, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus an error message.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> does not catch errors;\nany error is propagated to the caller.\n\n\n<p>\nAs an example,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n            \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     \n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n\n\n\n<h1>3 - <a name=\"3\">The Application Program Interface</a></h1>\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nAll such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments for validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith a proper definition for the macro <a name=\"pdf-luai_apicheck\"><code>luai_apicheck</code></a>,\nin file <code>luaconf.h</code>.\n\n\n\n<h2>3.1 - <a name=\"3.1\">The Stack</a></h2>\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function pushes its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an <em>absolute</em> stack position\n(starting at&nbsp;1);\na negative index represents an <em>offset</em> relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\nWe say that an index is <em>valid</em>\nif it lies between&nbsp;1 and the stack top\n(that is, if <code>1 &le; abs(index) &le; top</code>).\n \n\n\n\n\n\n<h2>3.2 - <a name=\"3.2\">Stack Size</a></h2>\n\n<p>\nWhen you interact with Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto grow the stack size.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that at least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> stack positions are available.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nMost query functions accept as indices any value inside the\navailable stack space, that is, indices up to the maximum stack size\nyou have set through <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\nSuch indices are called <em>acceptable indices</em>.\nMore formally, we define an <em>acceptable index</em>\nas follows:\n\n<pre>\n     (index &lt; 0 &amp;&amp; abs(index) &lt;= top) ||\n     (index &gt; 0 &amp;&amp; index &lt;= stackspace)\n</pre><p>\nNote that 0 is never an acceptable index.\n\n\n\n\n\n<h2>3.3 - <a name=\"3.3\">Pseudo-Indices</a></h2>\n\n<p>\nUnless otherwise noted,\nany function that accepts valid indices can also be called with\n<em>pseudo-indices</em>,\nwhich represent some Lua values that are accessible to C&nbsp;code\nbut which are not in the stack.\nPseudo-indices are used to access the thread environment,\nthe function environment,\nthe registry,\nand the upvalues of a C&nbsp;function (see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe thread environment (where global variables live) is\nalways at pseudo-index <a name=\"pdf-LUA_GLOBALSINDEX\"><code>LUA_GLOBALSINDEX</code></a>.\nThe environment of the running C&nbsp;function is always\nat pseudo-index <a name=\"pdf-LUA_ENVIRONINDEX\"><code>LUA_ENVIRONINDEX</code></a>.\n\n\n<p>\nTo access and change the value of global variables,\nyou can use regular table operations over an environment table.\nFor instance, to access the value of a global variable, do\n\n<pre>\n     lua_getfield(L, LUA_GLOBALSINDEX, varname);\n</pre>\n\n\n\n\n<h2>3.4 - <a name=\"3.4\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>;\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>).\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first value associated with a function is at position\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function (but not greater than 256),\nproduces an acceptable (but invalid) index.\n\n\n\n\n\n<h2>3.5 - <a name=\"3.5\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na pre-defined table that can be used by any C&nbsp;code to\nstore whatever Lua value it needs to store.\nThis table is always located at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it should take care to choose keys different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name\nor a light userdata with the address of a C&nbsp;object in your code.\n\n\n<p>\nThe integer keys in the registry are used by the reference mechanism,\nimplemented by the auxiliary library,\nand therefore should not be used for other purposes.\n\n\n\n\n\n<h2>3.6 - <a name=\"3.6\">Error Handling in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(You can also choose to use exceptions if you use C++;\nsee file <code>luaconf.h</code>.)\nWhen Lua faces any error\n(such as memory allocation errors, type errors, syntax errors,\nand runtime errors)\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recover point;\nany error jumps to the most recent active recover point.\n\n\n<p>\nMost functions in the API can throw an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can throw errors.\n\n\n<p>\nInside a C&nbsp;function you can throw an error by calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n\n\n\n<h2>3.7 - <a name=\"3.7\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments\n(e.g., they may depend on what is on the stack).\nThe third field, <code>x</code>,\ntells whether the function may throw errors:\n'<code>-</code>' means the function never throws any error;\n'<code>m</code>' means the function may throw an error\nonly due to not enough memory;\n'<code>e</code>' means the function may throw other kinds of errors;\n'<code>v</code>' means the function may throw an error on purpose.\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block;\n<code>nsize</code>, the new size of the block.\n<code>ptr</code> is <code>NULL</code> if and only if <code>osize</code> is zero.\nWhen <code>nsize</code> is zero, the allocator must return <code>NULL</code>;\nif <code>osize</code> is not zero,\nit should free the block pointed to by <code>ptr</code>.\nWhen <code>nsize</code> is not zero, the allocator returns <code>NULL</code>\nif and only if it cannot fill the request.\nWhen <code>nsize</code> is not zero and <code>osize</code> is zero,\nthe allocator should behave like <code>malloc</code>.\nWhen <code>nsize</code> and <code>osize</code> are not zero,\nthe allocator behaves like <code>realloc</code>.\nLua assumes that the allocator never fails when\n<code>osize &gt;= nsize</code>.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nThis code assumes\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.\nANSI&nbsp;C ensures both behaviors.\n\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em>\nand then calls <code>exit(EXIT_FAILURE)</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning (e.g., doing a long jump).\n\n\n<p>\nThe panic function can access the error message at the top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\n\n\n<p>\nTo call a function you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the function are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nAll arguments and the function value are popped from the stack\nwhen the function is called.\nThe function results are pushed onto the stack when the function returns.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, <em>all</em> results from the function are pushed.\nLua takes care that the returned values fit into the stack space.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error inside the called function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getfield(L, LUA_GLOBALSINDEX, \"f\"); /* function to be called */\n     lua_pushstring(L, \"how\");                        /* 1st argument */\n     lua_getfield(L, LUA_GLOBALSINDEX, \"t\");   /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setfield(L, LUA_GLOBALSINDEX, \"a\");        /* set global 'a' */\n</pre><p>\nNote that the code above is \"balanced\":\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numerical arguments and returns their average and sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushstring(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_checkstack (lua_State *L, int extra);</pre>\n\n<p>\nEnsures that there are at least <code>extra</code> free stack slots in the stack.\nIt returns false if it cannot grow the stack to that size.\nThis function never shrinks the stack;\nif the stack is already larger than the new size,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nDestroys all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any)\nand frees all dynamic memory used by this state.\nOn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs,\nsuch as a daemon or a web server,\nmight need to release states as soon as they are not needed,\nto avoid growing too large.\n\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result at the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#2.5.4\">&sect;2.5.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_cpcall\"><code>lua_cpcall</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);</pre>\n\n<p>\nCalls the C&nbsp;function <code>func</code> in protected mode.\n<code>func</code> starts with only one element in its stack,\na light userdata containing <code>ud</code>.\nIn case of errors,\n<a href=\"#lua_cpcall\"><code>lua_cpcall</code></a> returns the same error codes as <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nplus the error object on the top of the stack;\notherwise, it returns zero, and does not change the stack.\nAll values returned by <code>func</code> are discarded.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nThe new table has space pre-allocated\nfor <code>narr</code> array elements and <code>nrec</code> non-array elements.\nThis pre-allocation is useful when you know exactly how many elements\nthe table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_equal\"><code>lua_equal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_equal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in acceptable indices <code>index1</code> and\n<code>index2</code> are equal,\nfollowing the semantics of the Lua <code>==</code> operator\n(that is, may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nGenerates a Lua error.\nThe error message (which can actually be a Lua value of any type)\nmust be on the stack top.\nThis function does a long jump,\nand therefore never returns.\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_gc (lua_State *L, int what, int data);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>:\n\n<ul>\n\n<li><b><code>LUA_GCSTOP</code>:</b>\nstops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>:</b>\nrestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOLLECT</code>:</b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>:</b>\nreturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>:</b>\nreturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code>:</b>\nperforms an incremental step of garbage collection.\nThe step \"size\" is controlled by <code>data</code>\n(larger values mean more steps) in a non-specified way.\nIf you want to control the step size\nyou must experimentally tune the value of <code>data</code>.\nThe function returns 1 if the step finished a\ngarbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCSETPAUSE</code>:</b>\nsets <code>data</code> as the new value\nfor the <em>pause</em> of the collector (see <a href=\"#2.10\">&sect;2.10</a>).\nThe function returns the previous value of the pause.\n</li>\n\n<li><b><code>LUA_GCSETSTEPMUL</code>:</b>\nsets <code>data</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nThe function returns the previous value of the step multiplier.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfenv\"><code>lua_getfenv</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_getfenv (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the environment table of\nthe value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given valid index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_getglobal(L,s)  lua_getfield(L, LUA_GLOBALSINDEX, s)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the metatable of the value at the given\nacceptable index.\nIf the index is not valid,\nor if the value does not have a metatable,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>void lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>k</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the key from the stack\n(putting the resulting value in its place).\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack\n(and so 0&nbsp;means an empty stack).\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>-</em>]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nCannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ptrdiff_t lua_Integer;</pre>\n\n<p>\nThe type used by the Lua API to represent integral values.\n\n\n<p>\nBy default it is a <code>ptrdiff_t</code>,\nwhich is usually the largest signed integral type the machine handles\n\"comfortably\".\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index has type boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given acceptable index is not valid\n(that is, it refers to an element outside the current stack),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given acceptable index is not valid\n(that is, it refers to an element outside the current stack)\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_lessthan\"><code>lua_lessthan</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_lessthan (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the value at acceptable index <code>index1</code> is smaller\nthan the value at acceptable index <code>index2</code>,\nfollowing the semantics of the Lua <code>&lt;</code> operator\n(that is, may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname);</pre>\n\n<p>\nLoads a Lua chunk.\nIf there are no errors,\n<a href=\"#lua_load\"><code>lua_load</code></a> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\nThe return values of <a href=\"#lua_load\"><code>lua_load</code></a> are:\n\n<ul>\n\n<li><b>0:</b> no errors;</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>:</b>\nsyntax error during pre-compilation;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>:</b>\nmemory allocation error.</li>\n\n</ul>\n\n<p>\nThis function only loads a chunk;\nit does not run it.\n\n\n<p>\n<a href=\"#lua_load\"><code>lua_load</code></a> automatically detects whether the chunk is text or binary,\nand loads it accordingly (see program <code>luac</code>).\n\n\n<p>\nThe <a href=\"#lua_load\"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#3.8\">&sect;3.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new, independent state.\nReturns <code>NULL</code> if cannot create the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua does all memory allocation for this state through this function.\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\nsimply passes to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new state returned by this function shares with the original state\nall global objects (such as tables),\nbut has an independent execution stack.\n\n\n<p>\nThere is no explicit function to close or to destroy a thread.\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdata\"><code>lua_newuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>\n\n<p>\nThis function allocates a new block of memory with the given size,\npushes onto the stack a new full userdata with the block address,\nand returns this address.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>full userdata</em> represents a block of memory.\nIt is an object (like a table):\nyou must create it, it can have its own metatable,\nand you can detect when it is being collected.\nA full userdata is only equal to itself (under raw equality).\n\n\n<p>\nWhen Lua collects a full userdata with a <code>gc</code> metamethod,\nLua calls the metamethod and marks the userdata as finalized.\nWhen this userdata is collected again then\nLua frees its corresponding memory.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>e</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key-value pair from the table at the given index\n(the \"next\" pair after the given key).\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 (and pushes nothing).\n\n\n<p>\nA typical traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\ndo not call <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> <em>changes</em>\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef double lua_Number;</pre>\n\n<p>\nThe type of numbers in Lua.\nBy default, it is double, but that can be changed in <code>luaconf.h</code>.\n\n\n<p>\nThrough the configuration file you can change\nLua to operate with another type for numbers (e.g., float or long).\n\n\n\n\n\n<hr><h3><a name=\"lua_objlen\"><code>lua_objlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>size_t lua_objlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given acceptable index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>');\nfor userdata, this is the size of the block of memory allocated\nfor the userdata;\nfor other values, it is&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), <em>-</em>]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>\n\n<p>\nCalls a function in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error message),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>errfunc</code> is 0,\nthen the error message returned on the stack\nis exactly the original error message.\nOtherwise, <code>errfunc</code> is the stack index of an\n<em>error handler function</em>.\n(In the current implementation, this index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis function will be called with the error message\nand its return value will be the message returned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the error handler function is used to add more debug\ninformation to the error message, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns 0 in case of success\nor one of the following error codes\n(defined in <code>lua.h</code>):\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>:</b>\na runtime error.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>:</b>\nmemory allocation error.\nFor such errors, Lua does not call the error handler function.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>:</b>\nerror while running the error handler function.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, <em>-</em>]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a C&nbsp;closure (see <a href=\"#3.4\">&sect;3.4</a>);\nthese values are then accessible to the function whenever it is called.\nTo associate values with a C&nbsp;function,\nfirst these values should be pushed onto the stack\n(when there are multiple values, the first value is pushed first).\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values should be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function receives a pointer to a C function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\n\n\n<p>\nAny function to be registered in Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\n<code>lua_pushcfunction</code> is defined as a macro:\n\n<pre>\n     #define lua_pushcfunction(L,f)  lua_pushcclosure(L,f,0)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string.\nIt is similar to the C&nbsp;function <code>sprintf</code>,\nbut has some important differences:\n\n<ul>\n\n<li>\nYou do not have to allocate space for the result:\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\n</li>\n\n<li>\nThe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts a '<code>%</code>' in the string),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%p</code>' (inserts a pointer as a hexadecimal numeral),\n'<code>%d</code>' (inserts an <code>int</code>), and\n'<code>%c</code>' (inserts an <code>int</code> as a character).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes a number with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushlstring\"><code>lua_pushlstring</code></a>,\nbut can be used only when <code>s</code> is a literal string.\nIn these cases, it automatically provides the string length.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a number with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string cannot contain embedded zeros;\nit is assumed to end at the first zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given valid index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in acceptable indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, without calling metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>-</em>]</span>\n<pre>void lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_rawgeti (lua_State *L, int index, int n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the value at the given valid index.\nThe access is raw;\nthat is, it does not invoke metamethods.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, int n);</pre>\n\n<p>\nDoes the equivalent of <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw;\nthat is, it does not invoke metamethods.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time it needs another piece of the chunk,\n<a href=\"#lua_load\"><code>lua_load</code></a> calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L,\n                   const char *name,\n                   lua_CFunction f);</pre>\n\n<p>\nSets the C function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nCannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given position (and pops it),\nwithout shifting any element\n(therefore replacing the value at the given position).\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>int lua_resume (lua_State *L, int narg);</pre>\n\n<p>\nStarts and resumes a coroutine in a given thread.\n\n\n<p>\nTo start a coroutine, you first create a new thread\n(see <a href=\"#lua_newthread\"><code>lua_newthread</code></a>);\nthen you push onto its stack the main function plus any arguments;\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>narg</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns, the stack contains all values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nor all values returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n0 if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\nIn case of errors,\nthe stack is not unwound,\nso you can use the debug API over it.\nThe error message is on the top of the stack.\nTo restart a coroutine, you put on its stack only the values to\nbe passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfenv\"><code>lua_setfenv</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>int lua_setfenv (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and sets it as\nthe new environment for the value at the given index.\nIf the value at the given index is\nneither a function nor a thread nor a userdata,\n<a href=\"#lua_setfenv\"><code>lua_setfenv</code></a> returns 0.\nOtherwise it returns 1.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_setglobal(L,s)   lua_setfield(L, LUA_GLOBALSINDEX, s)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>int lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and\nsets it as the new metatable for the value at the given\nacceptable index.\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given valid index,\n<code>v</code> is the value at the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any acceptable index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is larger than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nOpaque structure that keeps the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is kept in this structure.\n\n\n<p>\nA pointer to this state must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be 0 for a normal thread,\nan error code if the thread finished its execution with an error,\nor <a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns 1 for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns 0.\nIt also returns 0 when called with a non-valid index.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given acceptable index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#2.2.1\">&sect;2.2.1</a>);\notherwise, <a href=\"#lua_tointeger\"><code>lua_tointeger</code></a> returns&nbsp;0.\n\n\n<p>\nIf the number is not an integer,\nit is truncated in some non-specified way.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit also sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> is applied to keys during a table traversal.)\n\n\n<p>\n<a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> returns a fully aligned pointer\nto a string inside the Lua state.\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\nBecause Lua has garbage collection,\nthere is no guarantee that the pointer returned by <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a>\nwill be valid after the corresponding value is removed from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#2.2.1\">&sect;2.2.1</a>);\notherwise, <a href=\"#lua_tonumber\"><code>lua_tonumber</code></a> returns&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given acceptable index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, or a function;\notherwise, <a href=\"#lua_topointer\"><code>lua_topointer</code></a> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given acceptable index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given acceptable index is a full userdata,\nreturns its block address.\nIf the value is a light userdata,\nreturns its pointer.\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given acceptable index,\nor <code>LUA_TNONE</code> for a non-valid index\n(that is, an index to an \"empty\" stack position).\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<code>LUA_TNIL</code>,\n<code>LUA_TNUMBER</code>,\n<code>LUA_TBOOLEAN</code>,\n<code>LUA_TSTRING</code>,\n<code>LUA_TTABLE</code>,\n<code>LUA_TFUNCTION</code>,\n<code>LUA_TUSERDATA</code>,\n<code>LUA_TTHREAD</code>,\nand\n<code>LUA_TLIGHTUSERDATA</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const char *lua_typename  (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time it produces another piece of chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>data</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the <em>same</em> global state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>int lua_yield  (lua_State *L, int nresults);</pre>\n\n<p>\nYields a coroutine.\n\n\n<p>\nThis function should only be called as the\nreturn expression of a C&nbsp;function, as follows:\n\n<pre>\n     return lua_yield (L, nresults);\n</pre><p>\nWhen a C&nbsp;function calls <a href=\"#lua_yield\"><code>lua_yield</code></a> in that way,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat are passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n\n\n\n\n\n<h2>3.8 - <a name=\"3.8\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  int currentline;            /* (l) */\n  int nups;                   /* (u) number of upvalues */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about an active function.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\ncall <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>:</b>\nIf the function was defined in a string,\nthen <code>source</code> is that string.\nIf the function was defined in a file,\nthen <code>source</code> starts with a '<code>@</code>' followed by the file name.\n</li>\n\n<li><b><code>short_src</code>:</b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>:</b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>:</b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>:</b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk,\nand <code>\"tail\"</code> if it was a function that did a tail call.\nIn the latter case,\nLua has no other information about the function.\n</li>\n\n<li><b><code>currentline</code>:</b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>:</b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>:</b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>nups</code>:</b>\nthe number of upvalues of the function.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>m</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nReturns information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function in the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getfield(L, LUA_GLOBALSINDEX, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>':</b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>':</b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>u</code>':</b> fills in the field <code>nups</code>;\n</li>\n\n<li><b>'<code>f</code>':</b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>':</b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 on error\n(for instance, an invalid option in <code>what</code>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable of a given activation record.\nThe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect\n(1 is the first parameter or active local variable, and so on,\nuntil the last active local variable).\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parentheses)\nrepresent internal variables\n(loop control variables, temporaries, and C&nbsp;function locals).\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGet information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>.\nWhen there are no errors, <a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 1;\nwhen called with a level greater than the stack depth,\nit returns 0.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about a closure's upvalue.\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n<a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a> gets the index <code>n</code> of an upvalue,\npushes the upvalue's value onto the stack,\nand returns its name.\n<code>funcindex</code> points to the closure in the stack.\n(Upvalues have no particular order,\nas they are active through the whole function.\nSo, they are numbered in an arbitrary order.)\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than the number of upvalues.\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILRET\"><code>LUA_HOOKTAILRET</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\nFor return events, <code>event</code> can be <code>LUA_HOOKRET</code>,\nthe normal value, or <code>LUA_HOOKTAILRET</code>.\nIn the latter case, Lua is simulating a return from\na function that did a tail call;\nin this case, it is useless to call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise or of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook:</b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function,\nbefore the function gets its arguments.\n</li>\n\n<li><b>The return hook:</b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\nYou have no access to the values to be returned by the function.\n</li>\n\n<li><b>The line hook:</b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n<li><b>The count hook:</b> is called after the interpreter executes every\n<code>count</code> instructions.\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n</ul>\n\n<p>\nA hook is disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, <em>-</em>]</span>\n<pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nParameters <code>ar</code> and <code>n</code> are as in <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>\n(see <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>).\n<a href=\"#lua_setlocal\"><code>lua_setlocal</code></a> assigns the value at the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, <em>-</em>]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value at the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\nParameters <code>funcindex</code> and <code>n</code> are as in the <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>\n(see <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>).\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than the number of upvalues.\n\n\n\n\n\n\n\n<h1>4 - <a name=\"4\">The Auxiliary Library</a></h1>\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all \ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with this API.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nTheir names are always <code>luaL_check*</code> or <code>luaL_opt*</code>.\nAll of these functions throw an error if the check is not satisfied.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n\n<h2>4.1 - <a name=\"4.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the character <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string may contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>)\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string may not contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value at the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int narg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf not, raises an error with the following message,\nwhere <code>func</code> is retrieved from the call stack:\n\n<pre>\n     bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)\n</pre>\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre>\n\n<p>\nRaises an error with the following message,\nwhere <code>func</code> is retrieved from the call stack:\n\n<pre>\n     bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)\n</pre>\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_argerror(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First you declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then you initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen you add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nYou finish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a> the stack is back to its\nlevel when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>.\nThis function does not allocate any space;\nthe buffer must be declared as a variable\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field and passes the object as its only argument.\nIn this case this function returns 1 and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns 0 (without pushing any value on the stack).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>narg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkint\"><code>luaL_checkint</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkint (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to an <code>int</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklong\"><code>luaL_checklong</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>long luaL_checklong (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to a <code>long</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int narg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills <code>*l</code>\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int narg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>narg</code> or if this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int narg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int narg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>m</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns 0 if there are no errors\nor 1 in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>m</em>]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns 0 if there are no errors\nor 1 in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code>.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\nreturns 0 and pushes nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code> by replacing\nany occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>,\nbut it has an extra error code <a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>\nif it cannot open/read the file.\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds it to the registry with key <code>tname</code>,\nand returns 1.\n\n\n<p>\nIn both cases pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C <code>realloc</code> function\nand then sets a panic function (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>) that prints\nan error message to the standard error output in case of fatal\nerrors.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optint\"><code>luaL_optint</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_optint (lua_State *L, int narg, int d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to an <code>int</code>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int narg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlong\"><code>luaL_optlong</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>long luaL_optlong (lua_State *L, int narg, long d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to a <code>long</code>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int narg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills the position <code>*l</code> with the results's length.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int narg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nReturns an address to a space of size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add \nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object at the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nFunction <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference and its associated object.\n\n\n<p>\nIf the object at the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_register\"><code>luaL_register</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with an sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_register\"><code>luaL_register</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +1, <em>m</em>]</span>\n<pre>void luaL_register (lua_State *L,\n                    const char *libname,\n                    const luaL_Reg *l);</pre>\n\n<p>\nOpens a library.\n\n\n<p>\nWhen called with <code>libname</code> equal to <code>NULL</code>,\nit simply registers all functions in the list <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack.\n\n\n<p>\nWhen called with a non-null <code>libname</code>,\n<code>luaL_register</code> creates a new table <code>t</code>,\nsets it as the value of the global variable <code>libname</code>,\nsets it as the value of <code>package.loaded[libname]</code>,\nand registers on it all functions in the list <code>l</code>.\nIf there is a table in <code>package.loaded[libname]</code> or in\nvariable <code>libname</code>,\nreuses this table instead of creating a new one.\n\n\n<p>\nIn any case the function leaves the table\non the top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typerror\"><code>luaL_typerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>\n\n<p>\nGenerates an error with a message like the following:\n\n<pre>\n     <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)\n</pre><p>\nwhere <code><em>location</em></code> is produced by <a href=\"#luaL_where\"><code>luaL_where</code></a>,\n<code><em>func</em></code> is the name of the current function,\nand <code><em>rt</em></code> is the type name of the actual argument.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>5 - <a name=\"5\">Standard Libraries</a></h1>\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented directly through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to \"outside\" services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut are quite useful or have critical performance requirements that\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library, which includes the coroutine sub-library;</li>\n\n<li>package library;</li>\n\n<li>string manipulation;</li>\n\n<li>table manipulation;</li>\n\n<li>mathematical functions (sin, log, etc.);</li>\n\n<li>input and output;</li>\n\n<li>operating system facilities;</li>\n\n<li>debug facilities.</li>\n\n</ul><p>\nExcept for the basic and package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nit can open them individually by calling\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the Operating System library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>\nand should not be called directly:\nyou must call them like any other Lua C&nbsp;function,\ne.g., by using <a href=\"#lua_call\"><code>lua_call</code></a>.\n\n\n\n<h2>5.1 - <a name=\"5.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides some core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide \nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\nIssues an  error when\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\n<code>message</code> is an error message;\nwhen absent, it defaults to \"assertion failed!\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage ([opt [, arg]])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"collect\":</b>\nperforms a full garbage-collection cycle.\nThis is the default option.\n</li>\n\n<li><b>\"stop\":</b>\nstops the garbage collector.\n</li>\n\n<li><b>\"restart\":</b>\nrestarts the garbage collector.\n</li>\n\n<li><b>\"count\":</b>\nreturns the total memory in use by Lua (in Kbytes).\n</li>\n\n<li><b>\"step\":</b>\nperforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>\n(larger values mean more steps) in a non-specified way.\nIf you want to control the step size\nyou must experimentally tune the value of <code>arg</code>.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"setpause\":</b>\nsets <code>arg</code> as the new value for the <em>pause</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nReturns the previous value for <em>pause</em>.\n</li>\n\n<li><b>\"setstepmul\":</b>\nsets <code>arg</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nReturns the previous value for <em>step</em>.\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile ([filename])</code></a></h3>\nOpens the named file and executes its contents as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller (that is, <code>dofile</code> does not run in protected mode).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nTerminates the last protected function called\nand returns <code>message</code> as the error message.\nFunction <code>error</code> never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (that is, <code>_G._G = _G</code>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice-versa.\n(Use <a href=\"#pdf-setfenv\"><code>setfenv</code></a> to change environments.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getfenv\"><code>getfenv ([f])</code></a></h3>\nReturns the current environment in use by the function.\n<code>f</code> can be a Lua function or a number\nthat specifies the function at that stack level:\nLevel&nbsp;1 is the function calling <code>getfenv</code>.\nIf the given function is not a Lua function,\nor if <code>f</code> is 0,\n<code>getfenv</code> returns the global environment.\nThe default for <code>f</code> is 1.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>\"__metatable\"</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values: an iterator function, the table <code>t</code>, and 0,\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middot;&middot;&middot;,\nup to the first integer key absent from the table.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (func [, chunkname])</code></a></h3>\n\n\n<p>\nLoads a chunk using function <code>func</code> to get its pieces.\nEach call to <code>func</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no errors, \nreturns the compiled chunk as a function;\notherwise, returns <b>nil</b> plus the error message.\nThe environment of the returned function is the global environment.\n\n\n<p>\n<code>chunkname</code> is used as the chunk name for error messages\nand debug information.\nWhen absent,\nit defaults to \"<code>=(load)</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadstring\"><code>loadstring (string [, chunkname])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from the given string.\n\n\n<p>\nTo load and run a given string, use the idiom\n\n<pre>\n     assert(loadstring(s))()\n</pre>\n\n<p>\nWhen absent,\n<code>chunkname</code> defaults to the given string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\n<code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numeric order,\nuse a numerical <b>for</b> or the <a href=\"#pdf-ipairs\"><code>ipairs</code></a> function.)\n\n\n<p>\nThe behavior of <code>next</code> is <em>undefined</em> if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may clear existing fields.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nReturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f, arg1, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nCalls function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments,\nand prints their values to <code>stdout</code>,\nusing the <a href=\"#pdf-tostring\"><code>tostring</code></a> function to convert them to strings.\n<code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\ntypically for debugging.\nFor formatted output, use <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking any metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout invoking any metamethod.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout invoking any metamethod.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b>,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>.\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setfenv\"><code>setfenv (f, table)</code></a></h3>\n\n\n<p>\nSets the environment to be used by the given function.\n<code>f</code> can be a Lua function or a number\nthat specifies the function at that stack level:\nLevel&nbsp;1 is the function calling <code>setfenv</code>.\n<code>setfenv</code> returns the given function.\n\n\n<p>\nAs a special case, when <code>f</code> is 0 <code>setfenv</code> changes\nthe environment of the running thread.\nIn this case, <code>setfenv</code> returns no values.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\n(You cannot change the metatable of other types from Lua, only from&nbsp;C.)\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>\"__metatable\"</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\nTries to convert its argument to a number.\nIf the argument is already a number or a string convertible\nto a number, then <code>tonumber</code> returns this number;\notherwise, it returns <b>nil</b>.\n\n\n<p>\nAn optional argument specifies the base to interpret the numeral.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIn base 10 (the default), the number can have a decimal part,\nas well as an optional exponent part (see <a href=\"#2.1\">&sect;2.1</a>).\nIn other bases, only unsigned integers are accepted.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (e)</code></a></h3>\nReceives an argument of any type and\nconverts it to a string in a reasonable format.\nFor complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n<p>\nIf the metatable of <code>e</code> has a <code>\"__tostring\"</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>e</code> as argument,\nand uses the result of the call as its result.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-unpack\"><code>unpack (list [, i [, j]])</code></a></h3>\nReturns the elements from the given table.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nexcept that the above code can be written only for a fixed number\nof elements.\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is the length of the list,\nas defined by the length operator (see <a href=\"#2.5.5\">&sect;2.5.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\nA global variable (not a function) that\nholds a string containing the current interpreter version.\nThe current contents of this variable is \"<code>Lua 5.1</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, err)</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that you can set a new error handler.\n\n\n<p>\n<code>xpcall</code> calls function <code>f</code> in protected mode,\nusing <code>err</code> as the error handler.\nAny error inside <code>f</code> is not propagated;\ninstead, <code>xpcall</code> catches the error,\ncalls the <code>err</code> function with the original error object,\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn this case, <code>xpcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error,\n<code>xpcall</code> returns <b>false</b> plus the result from <code>err</code>.\n\n\n\n\n\n\n\n<h2>5.2 - <a name=\"5.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThe operations related to coroutines comprise a sub-library of\nthe basic library and come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.11\">&sect;2.11</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a Lua function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, &middot;&middot;&middot; are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, &middot;&middot;&middot; are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(if the coroutine yields) or any values returned by the body function\n(if the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine,\nor <b>nil</b> when called by the main thread.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running (that is, it called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a Lua function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to the function behave as the\nextra arguments to <code>resume</code>.\nReturns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error, propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nThe coroutine cannot be running a C&nbsp;function,\na metamethod, or an iterator.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>5.3 - <a name=\"5.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading and building modules in Lua.\nIt exports two of its functions directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a> and <a href=\"#pdf-module\"><code>module</code></a>.\nEverything else is exported in a table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-module\"><code>module (name [, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCreates a module.\nIf there is a table in <code>package.loaded[name]</code>,\nthis table is the module.\nOtherwise, if there is a global table <code>t</code> with the given name,\nthis table is the module.\nOtherwise creates a new table <code>t</code> and\nsets it as the value of the global <code>name</code> and\nthe value of <code>package.loaded[name]</code>.\nThis function also initializes <code>t._NAME</code> with the given name,\n<code>t._M</code> with the module (<code>t</code> itself),\nand <code>t._PACKAGE</code> with the package name\n(the full module name minus last component; see below).\nFinally, <code>module</code> sets <code>t</code> as the new environment\nof the current function and the new value of <code>package.loaded[name]</code>,\nso that <a href=\"#pdf-require\"><code>require</code></a> returns <code>t</code>.\n\n\n<p>\nIf <code>name</code> is a compound name\n(that is, one with components separated by dots),\n<code>module</code> creates (or reuses, if they already exist)\ntables for each component.\nFor instance, if <code>name</code> is <code>a.b.c</code>,\nthen <code>module</code> stores the module table in field <code>c</code> of\nfield <code>b</code> of global <code>a</code>.\n\n\n<p>\nThis function can receive optional <em>options</em> after\nthe module name,\nwhere each option is a function to be applied over the module.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a> array.\nBy changing this array,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which should be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with a single argument, <code>modname</code>.\nIf the loader returns any value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader returns no value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> signals an error. \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaders\"><code>package.loaders</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to load modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole parameter.\nThe function can return another function (the module <em>loader</em>)\nor a string explaining why it did not find that module\n(or <b>nil</b> if it has nothing to say).\nLua initializes this table with four functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nA path is a sequence of <em>templates</em> separated by semicolons.\nFor each template,\nthe searcher will change each interrogation\nmark in the template by <code>filename</code>,\nwhich is the module name with each dot replaced by a\n\"directory separator\" (such as \"<code>/</code>\" in Unix);\nthen it will try to open the resulting file name.\nSo, for instance, if the Lua path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for a Lua file for module <code>foo</code>\nwill try to open the files\n<code>./foo.lua</code>, <code>./foo.lc</code>, and\n<code>/usr/local/foo/init.lua</code>, in that order.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits prefix up to (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.v1-b.c</code>,\nthe function name will be <code>luaopen_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\nInside this library, looks for a function <code>funcname</code>\nand returns this function as a C&nbsp;function.\n(So, <code>funcname</code> must follow the protocol (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>)).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by ANSI C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif the environment variable is not defined.\nAny \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.seeall\"><code>package.seeall (module)</code></a></h3>\n\n\n<p>\nSets a metatable for <code>module</code> with\nits <code>__index</code> field referring to the global environment,\nso that this module inherits values\nfrom the global environment.\nTo be used as an option to function <a href=\"#pdf-module\"><code>module</code></a>.\n\n\n\n\n\n\n\n<h2>5.4 - <a name=\"5.4\">String Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s, i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numerical codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, &middot;&middot;&middot;, <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\n\n\n<p>\nNote that numerical codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numerical code equal\nto its corresponding argument.\n\n\n<p>\nNote that numerical codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function)</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation of the given function,\nso that a later <a href=\"#pdf-loadstring\"><code>loadstring</code></a> on this string returns\na copy of the function.\n<code>function</code> must be a Lua function without upvalues.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\nLooks for the first match of\n<code>pattern</code> in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>nil</b>.\nA third, optional numerical argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered \"magic\".\nNote that if <code>plain</code> is given, then <code>init</code> must be given as well.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument (which must be a string).\nThe format string follows the same rules as the <code>printf</code> family of\nstandard C&nbsp;functions.\nThe only differences are that the options/modifiers\n<code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,\nand <code>h</code> are not supported\nand that there is an extra option, <code>q</code>.\nThe <code>q</code> option formats a string in a form suitable to be safely read\nback by the Lua interpreter:\nthe string is written between double quotes,\nand all double quotes, newlines, embedded zeros,\nand backslashes in the string\nare correctly escaped when written.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nwill produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre>\n\n<p>\nThe options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all\nexpect a number as argument,\nwhereas <code>q</code> and <code>s</code> expect a string.\n\n\n<p>\nThis function does not accept string values\ncontaining embedded zeros,\nexcept as arguments to the <code>q</code> option.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern)</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> over string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\n\n\n<p>\nAs an example, the following loop\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nwill iterate over all the words from string <code>s</code>,\nprinting one per line.\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>n</em></code>,\nwith <em>n</em> between 1 and 9,\nstands for the value of the <em>n</em>-th captured substring (see below).\nThe sequence <code>%0</code> stands for the whole match.\nThe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key;\nif the pattern specifies no captures,\nthen the whole match is used as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order;\nif the pattern specifies no captures,\nthen the whole match is passed as a sole argument.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return loadstring(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.1\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.1.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\nLooks for the first <em>match</em> of\n<code>pattern</code> in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>nil</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numerical argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n)</code></a></h3>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n<h3>5.4.1 - <a name=\"5.4.1\">Patterns</a></h3>\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>:</b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>:</b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>:</b> represents all letters.</li>\n\n<li><b><code>%c</code>:</b> represents all control characters.</li>\n\n<li><b><code>%d</code>:</b> represents all digits.</li>\n\n<li><b><code>%l</code>:</b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>:</b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>:</b> represents all space characters.</li>\n\n<li><b><code>%u</code>:</b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>:</b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>:</b> represents all hexadecimal digits.</li>\n\n<li><b><code>%z</code>:</b> represents the character with representation 0.</li>\n\n<li><b><code>%<em>x</em></code>:</b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny punctuation character (even the non magic)\ncan be preceded by a '<code>%</code>'\nwhen used to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>:</b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>:</b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches 0 or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches 1 or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches 0 or more repetitions of characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the <em>shortest</em> possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches 0 or 1 occurrence of a character in the class;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture (and therefore has number&nbsp;1);\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the empty capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n<p>\nA pattern cannot contain embedded zeros.  Use <code>%z</code> instead.\n\n\n\n\n\n\n\n\n\n\n\n<h2>5.5 - <a name=\"5.5\">Table Manipulation</a></h2><p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nMost functions in the table library assume that the table\nrepresents an array or a list.\nFor these functions, when we talk about the \"length\" of a table\nwe mean the result of the length operator.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>\nGiven an array where all elements are strings or numbers,\nreturns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is the length of the table.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (table, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>table</code>,\nshifting up other elements to open space, if necessary.\nThe default value for <code>pos</code> is <code>n+1</code>,\nwhere <code>n</code> is the length of the table (see <a href=\"#2.5.5\">&sect;2.5.5</a>),\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof table <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.maxn\"><code>table.maxn (table)</code></a></h3>\n\n\n<p>\nReturns the largest positive numerical index of the given table,\nor zero if the table has no positive numerical indices.\n(To do its job this function does a linear traversal of\nthe whole table.) \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (table [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>table</code> the element at position <code>pos</code>,\nshifting down other elements to close the space, if necessary.\nReturns the value of the removed element.\nThe default value for <code>pos</code> is <code>n</code>,\nwhere <code>n</code> is the length of the table,\nso that a call <code>table.remove(t)</code> removes the last element\nof table <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (table [, comp])</code></a></h3>\nSorts table elements in a given order, <em>in-place</em>,\nfrom <code>table[1]</code> to <code>table[n]</code>,\nwhere <code>n</code> is the length of the table.\nIf <code>comp</code> is given,\nthen it must be a function that receives two table elements,\nand returns true\nwhen the first is less than the second\n(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nThe sort algorithm is not stable;\nthat is, elements considered equal by the given order\nmay have their relative positions changed by the sort.\n\n\n\n\n\n\n\n<h2>5.6 - <a name=\"5.6\">Mathematical Functions</a></h2>\n\n<p>\nThis library is an interface to the standard C&nbsp;math library.\nIt provides all its functions inside the table <a name=\"pdf-math\"><code>math</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the absolute value of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (x)</code></a></h3>\n\n\n<p>\nReturns the arc tangent of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan2\"><code>math.atan2 (y, x)</code></a></h3>\n\n\n<p>\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both parameters to find the\nquadrant of the result.\n(It also handles correctly the case of <code>x</code> being zero.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integer larger than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cosh\"><code>math.cosh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic cosine of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nReturns the angle <code>x</code> (given in radians) in degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integer smaller than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.frexp\"><code>math.frexp (x)</code></a></h3>\n\n\n<p>\nReturns <code>m</code> and <code>e</code> such that <em>x = m2<sup>e</sup></em>,\n<code>e</code> is an integer and the absolute value of <code>m</code> is\nin the range <em>[0.5, 1)</em>\n(or zero when <code>x</code> is zero).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe value <code>HUGE_VAL</code>,\na value larger than or equal to any other numerical value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ldexp\"><code>math.ldexp (m, e)</code></a></h3>\n\n\n<p>\nReturns <em>m2<sup>e</sup></em> (<code>e</code> should be an integer).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x)</code></a></h3>\n\n\n<p>\nReturns the natural logarithm of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log10\"><code>math.log10 (x)</code></a></h3>\n\n\n<p>\nReturns the base-10 logarithm of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the maximum value among its arguments.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the minimum value among its arguments.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns two numbers,\nthe integral part of <code>x</code> and the fractional part of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>pi</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pow\"><code>math.pow (x, y)</code></a></h3>\n\n\n<p>\nReturns <em>x<sup>y</sup></em>.\n(You can also use the expression <code>x^y</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nReturns the angle <code>x</code> (given in degrees) in radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nThis function is an interface to the simple\npseudo-random generator function <code>rand</code> provided by ANSI&nbsp;C.\n(No guarantees can be given for its statistical properties.)\n\n\n<p>\nWhen called without arguments,\nreturns a uniform pseudo-random real number\nin the range <em>[0,1)</em>.  \nWhen called with an integer number <code>m</code>,\n<code>math.random</code> returns\na uniform pseudo-random integer in the range <em>[1, m]</em>.\nWhen called with two integer numbers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a uniform pseudo-random\ninteger in the range <em>[m, n]</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed (x)</code></a></h3>\n\n\n<p>\nSets <code>x</code> as the \"seed\"\nfor the pseudo-random generator:\nequal seeds produce equal sequences of numbers.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sinh\"><code>math.sinh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic sine of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tanh\"><code>math.tanh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic tangent of <code>x</code>.\n\n\n\n\n\n\n\n<h2>5.7 - <a name=\"5.7\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file descriptors;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are over these default files.\nThe second style uses explicit file descriptors.\n\n\n<p>\nWhen using implicit file descriptors,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file descriptors,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file descriptor\nand then all operations are supplied as methods of the file descriptor.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file descriptors with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>nil</b> on failure\n(plus an error message as a second result and\na system-dependent error code as a third result)\nand some value different from <b>nil</b> on success.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:flush</code> over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without parameters,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that,\neach time it is called,\nreturns a new line from the file.\nTherefore, the construction\n\n<pre>\n     for line in io.lines(filename) do <em>body</em> end\n</pre><p>\nwill iterate over all lines of the file.\nWhen the iterator function detects the end of file,\nit returns <b>nil</b> (to finish the loop) and automatically closes the file.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines()</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case it does not close the file when the loop ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIt returns a new file handle,\nor, in case of errors, <b>nil</b> plus an error message.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"r\":</b> read mode (the default);</li>\n<li><b>\"w\":</b> write mode;</li>\n<li><b>\"a\":</b> append mode;</li>\n<li><b>\"r+\":</b> update mode, all previous data is preserved;</li>\n<li><b>\"w+\":</b> update mode, all previous data is erased;</li>\n<li><b>\"a+\":</b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\nThis string is exactly what is used in the\nstandard&nbsp;C function <code>fopen</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nStarts program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nReturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>nil</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines ()</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreturns a new line from the file.\nTherefore, the construction\n\n<pre>\n     for line in file:lines() do <em>body</em> end\n</pre><p>\nwill iterate over all lines of the file.\n(Unlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string (or a number) with the characters read,\nor <b>nil</b> if it cannot read data with the specified format.\nWhen called without formats,\nit uses a default format that reads the entire next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"*n\":</b>\nreads a number;\nthis is the only format that returns a number instead of a string.\n</li>\n\n<li><b>\"*a\":</b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string.\n</li>\n\n<li><b>\"*l\":</b>\nreads the next line (skipping the end of line),\nreturning <b>nil</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b><em>number</em>:</b>\nreads a string with up to this number of characters,\nreturning <b>nil</b> on end of file.\nIf number is zero,\nit reads nothing and returns an empty string,\nor <b>nil</b> on end of file.\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence] [, offset])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"set\":</b> base is position 0 (beginning of the file);</li>\n<li><b>\"cur\":</b> base is current position;</li>\n<li><b>\"end\":</b> base is end of file;</li>\n</ul><p>\nIn case of success, function <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for an output file.\nThere are three available modes:\n\n<ul>\n\n<li><b>\"no\":</b>\nno buffering; the result of any output operation appears immediately.\n</li>\n\n<li><b>\"full\":</b>\nfull buffering; output operation is performed only\nwhen the buffer is full (or when you explicitly <code>flush</code> the file\n(see <a href=\"#pdf-io.flush\"><code>io.flush</code></a>)).\n</li>\n\n<li><b>\"line\":</b>\nline buffering; output is buffered until a newline is output\nor there is any input from some special files\n(such as a terminal device).\n</li>\n\n</ul><p>\nFor the last two cases, <code>size</code>\nspecifies the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to\nthe <code>file</code>.\nThe arguments must be strings or numbers.\nTo write other values,\nuse <a href=\"#pdf-tostring\"><code>tostring</code></a> or <a href=\"#pdf-string.format\"><code>string.format</code></a> before <code>write</code>.\n\n\n\n\n\n\n\n<h2>5.8 - <a name=\"5.8\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),\n<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),\n<code>wday</code> (weekday, Sunday is&nbsp;1),\n<code>yday</code> (day of the year),\nand <code>isdst</code> (daylight saving flag, a boolean).\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the C&nbsp;function <code>strftime</code>.\n\n\n<p>\nWhen called without arguments,\n<code>date</code> returns a reasonable date and time representation that depends on\nthe host system and on the current locale\n(that is, <code>os.date()</code> is equivalent to <code>os.date(\"%c\")</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the number of seconds from time <code>t1</code> to time <code>t2</code>.\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the C&nbsp;function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIt returns a status code, which is system-dependent.\nIf <code>command</code> is absent, then it returns nonzero if a shell is available\nand zero otherwise.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code])</code></a></h3>\n\n\n<p>\nCalls the C&nbsp;function <code>exit</code>,\nwith an optional <code>code</code>,\nto terminate the host program.\nThe default value for <code>code</code> is the success code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>,\nor <b>nil</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file or directory with the given name.\nDirectories must be empty to be removed.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>nil</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields <code>hour</code>, <code>min</code>, <code>sec</code>, and <code>isdst</code>\n(for a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function).\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems, this number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<code>date</code> and <code>difftime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nOn some systems (POSIX),\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>5.9 - <a name=\"5.9\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface to Lua programs.\nYou should exert care when using this library.\nThe functions provided here should be used exclusively for debugging\nand similar tasks, such as profiling.\nPlease resist the temptation to use them as a\nusual programming tool:\nthey can be very slow.\nMoreover, several of these functions\nviolate some assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside or\nthat userdata metatables cannot be changed by Lua code)\nand therefore can compromise otherwise secure code.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function, and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getfenv\"><code>debug.getfenv (o)</code></a></h3>\nReturns the environment of object <code>o</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count\n(as set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] function [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly,\nor you can give a number as the value of <code>function</code>,\nwhich means the function running at level <code>function</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>;\nand so on.\nIf <code>function</code> is a number larger than the number of active functions,\nthen <code>getinfo</code> returns <b>nil</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na table with a name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] level, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\n(The first parameter or local variable has index&nbsp;1, and so on,\nuntil the last active local variable.)\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parentheses)\nrepresent internal variables\n(loop control variables, temporaries, and C&nbsp;function locals).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (object)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>object</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (func, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>func</code>.\nThe function returns <b>nil</b> if there is no upvalue with the given index.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setfenv\"><code>debug.setfenv (object, table)</code></a></h3>\n\n\n<p>\nSets the environment of the given <code>object</code> to the given <code>table</code>.\nReturns <code>object</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as a hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have the following characters,\nwith the given meaning:\n\n<ul>\n<li><b><code>\"c\"</code>:</b> the hook is called every time Lua calls a function;</li>\n<li><b><code>\"r\"</code>:</b> the hook is called every time Lua returns from a function;</li>\n<li><b><code>\"l\"</code>:</b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nWith a <code>count</code> different from zero,\nthe hook is called after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first parameter is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code>, <code>\"return\"</code> (or <code>\"tail return\"</code>,\nwhen simulating a return from a tail call),\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function\n(level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function),\nunless the event is <code>\"tail return\"</code>.\nIn this case, Lua is only simulating the return,\nand a call to <code>getinfo</code> will return invalid data.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (object, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>object</code> to the given <code>table</code>\n(which can be <b>nil</b>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (func, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>func</code>.\nThe function returns <b>nil</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>\n\n\n<p>\nReturns a string with a traceback of the call stack.\nAn optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n\n\n\n<h1>6 - <a name=\"6\">Lua Stand-alone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a stand-alone language.\nAn interpreter for Lua as a stand-alone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe stand-alone interpreter includes\nall standard libraries, including the debug library.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>:</b> executes string <em>stat</em>;</li>\n<li><b><code>-l <em>mod</em></code>:</b> \"requires\" <em>mod</em>;</li>\n<li><b><code>-i</code>:</b> enters interactive mode after running <em>script</em>;</li>\n<li><b><code>-v</code>:</b> prints version information;</li>\n<li><b><code>--</code>:</b> stops handling options;</li>\n<li><b><code>-</code>:</b> executes <code>stdin</code> as a file and stops handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>,\npassing to it the given <em>args</em> as string arguments.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nBefore running any argument,\nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a>.\nIf its format is <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nAll options are handled in order, except <code>-i</code>.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e'a=1' -e 'print(a)' script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then print the value of <code>a</code> (which is '<code>1</code>'),\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore starting to run the script,\n<code>lua</code> collects all arguments in the command line\nin a global table called <code>arg</code>.\nThe script name is stored at index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus the options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe interpreter first runs the file <code>a.lua</code>,\nthen creates a table\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nand finally runs the file <code>b.lua</code>.\nThe script is called with <code>arg[1]</code>, <code>arg[2]</code>, &middot;&middot;&middot;\nas arguments;\nit can also access these arguments with the vararg expression '<code>...</code>'.\n\n\n<p>\nIn interactive mode,\nif you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\nTherefore, both prompts can be changed directly on the command line\nor in any Lua programs by assigning to <code>_PROMPT</code>.\nSee the next example:\n\n<pre>\n     $ lua -e\"_PROMPT='myprompt&gt; '\" -i\n</pre><p>\n(The outer pair of quotes is for the shell,\nthe inner pair is for Lua.)\nNote the use of <code>-i</code> to enter interactive mode;\notherwise,\nthe program would just end silently\nright after the assignment to <code>_PROMPT</code>.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nthe stand-alone interpreter skips\nthe first line of a chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\n(Of course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen \n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.) \n\n\n\n<h1>7 - <a name=\"7\">Incompatibilities with the Previous Version</a></h1>\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.0 to Lua&nbsp;5.1.\nYou can avoid most of the incompatibilities compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the next version of Lua.\n\n\n\n<h2>7.1 - <a name=\"7.1\">Changes in the Language</a></h2>\n<ul>\n\n<li>\nThe vararg system changed from the pseudo-argument <code>arg</code> with a\ntable with the extra arguments to the vararg expression.\n(See compile-time option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nThere was a subtle change in the scope of the implicit\nvariables of the <b>for</b> statement and for the <b>repeat</b> statement.\n</li>\n\n<li>\nThe long string/long comment syntax (<code>[[<em>string</em>]]</code>)\ndoes not allow nesting.\nYou can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.\n(See compile-time option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)\n</li>\n\n</ul>\n\n\n\n\n<h2>7.2 - <a name=\"7.2\">Changes in the Libraries</a></h2>\n<ul>\n\n<li>\nFunction <code>string.gfind</code> was renamed <a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>.\n(See compile-time option <code>LUA_COMPAT_GFIND</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nWhen <a href=\"#pdf-string.gsub\"><code>string.gsub</code></a> is called with a function as its\nthird argument,\nwhenever this function returns <b>nil</b> or <b>false</b> the\nreplacement string is the whole match,\ninstead of the empty string.\n</li>\n\n<li>\nFunction <code>table.setn</code> was deprecated.\nFunction <code>table.getn</code> corresponds\nto the new length operator (<code>#</code>);\nuse the operator instead of the function.\n(See compile-time option <code>LUA_COMPAT_GETN</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunction <code>loadlib</code> was renamed <a href=\"#pdf-package.loadlib\"><code>package.loadlib</code></a>.\n(See compile-time option <code>LUA_COMPAT_LOADLIB</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunction <code>math.mod</code> was renamed <a href=\"#pdf-math.fmod\"><code>math.fmod</code></a>.\n(See compile-time option <code>LUA_COMPAT_MOD</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunctions <code>table.foreach</code> and <code>table.foreachi</code> are deprecated.\nYou can use a for loop with <code>pairs</code> or <code>ipairs</code> instead.\n</li>\n\n<li>\nThere were substantial changes in function <a href=\"#pdf-require\"><code>require</code></a> due to\nthe new module system.\nHowever, the new behavior is mostly compatible with the old,\nbut <code>require</code> gets the path from <a href=\"#pdf-package.path\"><code>package.path</code></a> instead\nof from <code>LUA_PATH</code>.\n</li>\n\n<li>\nFunction <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> has different arguments.\nFunction <code>gcinfo</code> is deprecated;\nuse <code>collectgarbage(\"count\")</code> instead.\n</li>\n\n</ul>\n\n\n\n\n<h2>7.3 - <a name=\"7.3\">Changes in the API</a></h2>\n<ul>\n\n<li>\nThe <code>luaopen_*</code> functions (to open libraries)\ncannot be called directly,\nlike a regular C function.\nThey must be called through Lua,\nlike a Lua function.\n</li>\n\n<li>\nFunction <code>lua_open</code> was replaced by <a href=\"#lua_newstate\"><code>lua_newstate</code></a> to\nallow the user to set a memory-allocation function.\nYou can use <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a> from the standard library to\ncreate a state with a standard allocation function\n(based on <code>realloc</code>).\n</li>\n\n<li>\nFunctions <code>luaL_getn</code> and <code>luaL_setn</code>\n(from the auxiliary library) are deprecated.\nUse <a href=\"#lua_objlen\"><code>lua_objlen</code></a> instead of <code>luaL_getn</code>\nand nothing instead of <code>luaL_setn</code>.\n</li>\n\n<li>\nFunction <code>luaL_openlib</code> was replaced by <a href=\"#luaL_register\"><code>luaL_register</code></a>.\n</li>\n\n<li>\nFunction <code>luaL_checkudata</code> now throws an error when the given value\nis not a userdata of the expected type.\n(In Lua&nbsp;5.0 it returned <code>NULL</code>.)\n</li>\n\n</ul>\n\n\n\n\n<h1>8 - <a name=\"8\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\n(It does not describe operator precedences.)\n\n\n\n\n<pre>\n\n\tchunk ::= {stat [`<b>;</b>&acute;]} [laststat [`<b>;</b>&acute;]]\n\n\tblock ::= chunk\n\n\tstat ::=  varlist `<b>=</b>&acute; explist | \n\t\t functioncall | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> namelist [`<b>=</b>&acute; explist] \n\n\tlaststat ::= <b>return</b> [explist] | <b>break</b>\n\n\tfuncname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]\n\n\tvarlist ::= var {`<b>,</b>&acute; var}\n\n\tvar ::=  Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name \n\n\tnamelist ::= Name {`<b>,</b>&acute; Name}\n\n\texplist ::= {exp `<b>,</b>&acute;} exp\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | `<b>...</b>&acute; | function | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;\n\n\tfunctioncall ::=  prefixexp args | prefixexp `<b>:</b>&acute; Name args \n\n\targs ::=  `<b>(</b>&acute; [explist] `<b>)</b>&acute; | tableconstructor | String \n\n\tfunction ::= <b>function</b> funcbody\n\n\tfuncbody ::= `<b>(</b>&acute; [parlist] `<b>)</b>&acute; block <b>end</b>\n\n\tparlist ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;\n\n\ttableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp\n\n\tfieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;\n\n\tbinop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; | \n\t\t `<b>&lt;</b>&acute; | `<b>&lt;=</b>&acute; | `<b>&gt;</b>&acute; | `<b>&gt;=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n<HR>\n<SMALL CLASS=\"footer\">\nLast update:\nMon Feb 13 18:54:19 BRST 2012\n</SMALL>\n<!--\nLast change: revised for Lua 5.1.5\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "build/lua-5.1.5/doc/readme.html",
    "content": "<HTML>\n<HEAD>\n<TITLE>Lua documentation</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY>\n\n<HR>\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\" BORDER=0></A>\nDocumentation\n</H1>\n\nThis is the documentation included in the source distribution of Lua 5.1.5.\n\n<UL>\n<LI><A HREF=\"contents.html\">Reference manual</A>\n<LI><A HREF=\"lua.html\">lua man page</A>\n<LI><A HREF=\"luac.html\">luac man page</A>\n<LI><A HREF=\"../README\">lua/README</A>\n<LI><A HREF=\"../etc/README\">lua/etc/README</A>\n<LI><A HREF=\"../test/README\">lua/test/README</A>\n</UL>\n\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\ncontains updated documentation,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.1/\">reference manual</A>.\n<P>\n\n<HR>\n<SMALL>\nLast update:\nFri Feb  3 09:44:42 BRST 2012\n</SMALL>\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.1.5/etc/Makefile",
    "content": "# makefile for Lua etc\n\nTOP= ..\nLIB= $(TOP)/src\nINC= $(TOP)/src\nBIN= $(TOP)/src\nSRC= $(TOP)/src\nTST= $(TOP)/test\n\nCC= gcc\nCFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS)\nMYCFLAGS= \nMYLDFLAGS= -Wl,-E\nMYLIBS= -lm\n#MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses\nRM= rm -f\n\ndefault:\n\t@echo 'Please choose a target: min noparser one strict clean'\n\nmin:\tmin.c\n\t$(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS)\n\techo 'print\"Hello there!\"' | ./a.out\n\nnoparser: noparser.o\n\t$(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS)\n\t$(BIN)/luac $(TST)/hello.lua\n\t-./a.out luac.out\n\t-./a.out -e'a=1'\n\none:\n\t$(CC) $(CFLAGS) all.c $(MYLIBS)\n\t./a.out $(TST)/hello.lua\n\nstrict:\n\t-$(BIN)/lua -e 'print(a);b=2'\n\t-$(BIN)/lua -lstrict -e 'print(a)'\n\t-$(BIN)/lua -e 'function f() b=2 end f()'\n\t-$(BIN)/lua -lstrict -e 'function f() b=2 end f()'\n\nclean:\n\t$(RM) a.out core core.* *.o luac.out\n\n.PHONY:\tdefault min noparser one strict clean\n"
  },
  {
    "path": "build/lua-5.1.5/etc/README",
    "content": "This directory contains some useful files and code.\nUnlike the code in ../src, everything here is in the public domain.\n\nIf any of the makes fail, you're probably not using the same libraries\nused to build Lua. Set MYLIBS in Makefile accordingly.\n\nall.c\n\tFull Lua interpreter in a single file.\n\tDo \"make one\" for a demo.\n\nlua.hpp\n\tLua header files for C++ using 'extern \"C\"'.\n\nlua.ico\n\tA Lua icon for Windows (and web sites: save as favicon.ico).\n\tDrawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.\n\nlua.pc\n\tpkg-config data for Lua\n\nluavs.bat\n\tScript to build Lua under \"Visual Studio .NET Command Prompt\".\n\tRun it from the toplevel as etc\\luavs.bat.\n\nmin.c\n\tA minimal Lua interpreter.\n\tGood for learning and for starting your own.\n\tDo \"make min\" for a demo.\n\nnoparser.c\n\tLinking with noparser.o avoids loading the parsing modules in lualib.a.\n\tDo \"make noparser\" for a demo.\n\nstrict.lua\n\tTraps uses of undeclared global variables.\n\tDo \"make strict\" for a demo.\n\n"
  },
  {
    "path": "build/lua-5.1.5/etc/all.c",
    "content": "/*\n* all.c -- Lua core, libraries and interpreter in a single file\n*/\n\n#define luaall_c\n\n#include \"lapi.c\"\n#include \"lcode.c\"\n#include \"ldebug.c\"\n#include \"ldo.c\"\n#include \"ldump.c\"\n#include \"lfunc.c\"\n#include \"lgc.c\"\n#include \"llex.c\"\n#include \"lmem.c\"\n#include \"lobject.c\"\n#include \"lopcodes.c\"\n#include \"lparser.c\"\n#include \"lstate.c\"\n#include \"lstring.c\"\n#include \"ltable.c\"\n#include \"ltm.c\"\n#include \"lundump.c\"\n#include \"lvm.c\"\n#include \"lzio.c\"\n\n#include \"lauxlib.c\"\n#include \"lbaselib.c\"\n#include \"ldblib.c\"\n#include \"liolib.c\"\n#include \"linit.c\"\n#include \"lmathlib.c\"\n#include \"loadlib.c\"\n#include \"loslib.c\"\n#include \"lstrlib.c\"\n#include \"ltablib.c\"\n\n#include \"lua.c\"\n"
  },
  {
    "path": "build/lua-5.1.5/etc/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "build/lua-5.1.5/etc/lua.pc",
    "content": "# lua.pc -- pkg-config data for Lua\n\n# vars from install Makefile\n\n# grep '^V=' ../Makefile\nV= 5.1\n# grep '^R=' ../Makefile\nR= 5.1.5\n\n# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'\nprefix= /usr/local\nINSTALL_BIN= ${prefix}/bin\nINSTALL_INC= ${prefix}/include\nINSTALL_LIB= ${prefix}/lib\nINSTALL_MAN= ${prefix}/man/man1\nINSTALL_LMOD= ${prefix}/share/lua/${V}\nINSTALL_CMOD= ${prefix}/lib/lua/${V}\n\n# canonical vars\nexec_prefix=${prefix}\nlibdir=${exec_prefix}/lib\nincludedir=${prefix}/include\n\nName: Lua\nDescription: An Extensible Extension Language\nVersion: ${R}\nRequires: \nLibs: -L${libdir} -llua -lm\nCflags: -I${includedir}\n\n# (end of lua.pc)\n"
  },
  {
    "path": "build/lua-5.1.5/etc/luavs.bat",
    "content": "@rem Script to build Lua under \"Visual Studio .NET Command Prompt\".\n@rem Do not run from this directory; run it from the toplevel: etc\\luavs.bat .\n@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.\n@rem (contributed by David Manura and Mike Pall)\n\n@setlocal\n@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE\n@set MYLINK=link /nologo\n@set MYMT=mt /nologo\n\ncd src\n%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c\ndel lua.obj luac.obj\n%MYLINK% /DLL /out:lua51.dll l*.obj\nif exist lua51.dll.manifest^\n  %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2\n%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c\n%MYLINK% /out:lua.exe lua.obj lua51.lib\nif exist lua.exe.manifest^\n  %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe\n%MYCOMPILE% l*.c print.c\ndel lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^\n    loslib.obj ltablib.obj lstrlib.obj loadlib.obj\n%MYLINK% /out:luac.exe *.obj\nif exist luac.exe.manifest^\n  %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe\ndel *.obj *.manifest\ncd ..\n"
  },
  {
    "path": "build/lua-5.1.5/etc/min.c",
    "content": "/*\n* min.c -- a minimal Lua interpreter\n* loads stdin only with minimal error handling.\n* no interaction, and no standard library, only a \"print\" function.\n*/\n\n#include <stdio.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\nstatic int print(lua_State *L)\n{\n int n=lua_gettop(L);\n int i;\n for (i=1; i<=n; i++)\n {\n  if (i>1) printf(\"\\t\");\n  if (lua_isstring(L,i))\n   printf(\"%s\",lua_tostring(L,i));\n  else if (lua_isnil(L,i))\n   printf(\"%s\",\"nil\");\n  else if (lua_isboolean(L,i))\n   printf(\"%s\",lua_toboolean(L,i) ? \"true\" : \"false\");\n  else\n   printf(\"%s:%p\",luaL_typename(L,i),lua_topointer(L,i));\n }\n printf(\"\\n\");\n return 0;\n}\n\nint main(void)\n{\n lua_State *L=lua_open();\n lua_register(L,\"print\",print);\n if (luaL_dofile(L,NULL)!=0) fprintf(stderr,\"%s\\n\",lua_tostring(L,-1));\n lua_close(L);\n return 0;\n}\n"
  },
  {
    "path": "build/lua-5.1.5/etc/noparser.c",
    "content": "/*\n* The code below can be used to make a Lua core that does not contain the\n* parsing modules (lcode, llex, lparser), which represent 35% of the total core.\n* You'll only be able to load binary files and strings, precompiled with luac.\n* (Of course, you'll have to build luac with the original parsing modules!)\n*\n* To use this module, simply compile it (\"make noparser\" does that) and list\n* its object file before the Lua libraries. The linker should then not load\n* the parsing modules. To try it, do \"make luab\".\n*\n* If you also want to avoid the dump module (ldump.o), define NODUMP.\n* #define NODUMP\n*/\n\n#define LUA_CORE\n\n#include \"llex.h\"\n#include \"lparser.h\"\n#include \"lzio.h\"\n\nLUAI_FUNC void luaX_init (lua_State *L) {\n  UNUSED(L);\n}\n\nLUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {\n  UNUSED(z);\n  UNUSED(buff);\n  UNUSED(name);\n  lua_pushliteral(L,\"parser not loaded\");\n  lua_error(L);\n  return NULL;\n}\n\n#ifdef NODUMP\n#include \"lundump.h\"\n\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {\n  UNUSED(f);\n  UNUSED(w);\n  UNUSED(data);\n  UNUSED(strip);\n#if 1\n  UNUSED(L);\n  return 0;\n#else\n  lua_pushliteral(L,\"dumper not loaded\");\n  lua_error(L);\n#endif\n}\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/etc/strict.lua",
    "content": "--\n-- strict.lua\n-- checks uses of undeclared global variables\n-- All global variables must be 'declared' through a regular assignment\n-- (even assigning nil will do) in a main chunk before being used\n-- anywhere or assigned to inside a function.\n--\n\nlocal getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget\n\nlocal mt = getmetatable(_G)\nif mt == nil then\n  mt = {}\n  setmetatable(_G, mt)\nend\n\nmt.__declared = {}\n\nlocal function what ()\n  local d = getinfo(3, \"S\")\n  return d and d.what or \"C\"\nend\n\nmt.__newindex = function (t, n, v)\n  if not mt.__declared[n] then\n    local w = what()\n    if w ~= \"main\" and w ~= \"C\" then\n      error(\"assign to undeclared variable '\"..n..\"'\", 2)\n    end\n    mt.__declared[n] = true\n  end\n  rawset(t, n, v)\nend\n  \nmt.__index = function (t, n)\n  if not mt.__declared[n] and what() ~= \"C\" then\n    error(\"variable '\"..n..\"' is not declared\", 2)\n  end\n  return rawget(t, n)\nend\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/Makefile",
    "content": "# makefile for building Lua\n# see ../INSTALL for installation instructions\n# see ../Makefile and luaconf.h for further customization\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\nCC= gcc\nCFLAGS= -O2 -Wall $(MYCFLAGS)\nAR= ar rcu\nRANLIB= ranlib\nRM= rm -f\nLIBS= -lm $(MYLIBS)\n\nMYCFLAGS=\nMYLDFLAGS=\nMYLIBS=\n\n# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========\n\nPLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris\n\nLUA_A=\tliblua.a\nCORE_O=\tlapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \\\n\tlobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o  \\\n\tlundump.o lvm.o lzio.o\nLIB_O=\tlauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \\\n\tlstrlib.o loadlib.o linit.o\n\nLUA_T=\tlua\nLUA_O=\tlua.o\n\nLUAC_T=\tluac\nLUAC_O=\tluac.o print.o\n\nALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)\nALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)\nALL_A= $(LUA_A)\n\ndefault: $(PLAT)\n\nall:\t$(ALL_T)\n\no:\t$(ALL_O)\n\na:\t$(ALL_A)\n\n$(LUA_A): $(CORE_O) $(LIB_O)\n\t$(AR) $@ $(CORE_O) $(LIB_O)\t# DLL needs all object files\n\t$(RANLIB) $@\n\n$(LUA_T): $(LUA_O) $(LUA_A)\n\t$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)\n\n$(LUAC_T): $(LUAC_O) $(LUA_A)\n\t$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)\n\nclean:\n\t$(RM) $(ALL_T) $(ALL_O)\n\ndepend:\n\t@$(CC) $(CFLAGS) -MM l*.c print.c\n\necho:\n\t@echo \"PLAT = $(PLAT)\"\n\t@echo \"CC = $(CC)\"\n\t@echo \"CFLAGS = $(CFLAGS)\"\n\t@echo \"AR = $(AR)\"\n\t@echo \"RANLIB = $(RANLIB)\"\n\t@echo \"RM = $(RM)\"\n\t@echo \"MYCFLAGS = $(MYCFLAGS)\"\n\t@echo \"MYLDFLAGS = $(MYLDFLAGS)\"\n\t@echo \"MYLIBS = $(MYLIBS)\"\n\n# convenience targets for popular platforms\n\nnone:\n\t@echo \"Please choose a platform:\"\n\t@echo \"   $(PLATS)\"\n\naix:\n\t$(MAKE) all CC=\"xlc\" CFLAGS=\"-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN\" MYLIBS=\"-ldl\" MYLDFLAGS=\"-brtl -bexpall\"\n\nansi:\n\t$(MAKE) all MYCFLAGS=-DLUA_ANSI\n\nbsd:\n\t$(MAKE) all MYCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" MYLIBS=\"-Wl,-E\"\n\nfreebsd:\n\t$(MAKE) all MYCFLAGS=\"-DLUA_USE_LINUX\" MYLIBS=\"-Wl,-E -lreadline\"\n\ngeneric:\n\t$(MAKE) all MYCFLAGS=\n\nlinux:\n\t$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS=\"-Wl,-E -ldl -lreadline -lhistory -lncurses\"\n\nmacosx:\n\t$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS=\"-lreadline\"\n# use this on Mac OS X 10.3-\n#\t$(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX\n\nmingw:\n\t$(MAKE) \"LUA_A=lua51.dll\" \"LUA_T=lua.exe\" \\\n\t\"AR=$(CC) -shared -o\" \"RANLIB=strip --strip-unneeded\" \\\n\t\"MYCFLAGS=-DLUA_BUILD_AS_DLL\" \"MYLIBS=\" \"MYLDFLAGS=-s\" lua.exe\n\t$(MAKE) \"LUAC_T=luac.exe\" luac.exe\n\nposix:\n\t$(MAKE) all MYCFLAGS=-DLUA_USE_POSIX\n\nsolaris:\n\t$(MAKE) all MYCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" MYLIBS=\"-ldl\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) default o a clean depend echo none\n\n# DO NOT DELETE\n\nlapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \\\n  lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \\\n  lundump.h lvm.h\nlauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h\nlbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h\nlcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \\\n  lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \\\n  ltable.h\nldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h\nldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \\\n  llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \\\n  lfunc.h lstring.h lgc.h ltable.h lvm.h\nldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \\\n  lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \\\n  ltable.h lundump.h lvm.h\nldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \\\n  lzio.h lmem.h lundump.h\nlfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \\\n  lstate.h ltm.h lzio.h\nlgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \\\n  lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h\nlinit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h\nliolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h\nllex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \\\n  lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h\nlmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h\nlmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \\\n  ltm.h lzio.h lmem.h ldo.h\nloadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h\nlobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \\\n  ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h\nlopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h\nloslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h\nlparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \\\n  lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \\\n  lfunc.h lstring.h lgc.h ltable.h\nlstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \\\n  ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h\nlstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \\\n  ltm.h lzio.h lstring.h lgc.h\nlstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h\nltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \\\n  ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h\nltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h\nltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \\\n  lmem.h lstring.h lgc.h ltable.h\nlua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h\nluac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \\\n  lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \\\n  lundump.h\nlundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n  llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h\nlvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \\\n  lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h\nlzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \\\n  lzio.h\nprint.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \\\n  ltm.h lzio.h lmem.h lopcodes.h lundump.h\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.1.5/src/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n\n#include <assert.h>\n#include <math.h>\n#include <stdarg.h>\n#include <string.h>\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$Lua: \" LUA_RELEASE \" \" LUA_COPYRIGHT \" $\\n\"\n  \"$Authors: \" LUA_AUTHORS \" $\\n\"\n  \"$URL: www.lua.org $\\n\";\n\n\n\n#define api_checknelems(L, n)\tapi_check(L, (n) <= (L->top - L->base))\n\n#define api_checkvalidindex(L, i)\tapi_check(L, (i) != luaO_nilobject)\n\n#define api_incr_top(L)   {api_check(L, L->top < L->ci->top); L->top++;}\n\n\n\nstatic TValue *index2adr (lua_State *L, int idx) {\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    api_check(L, idx <= L->ci->top - L->base);\n    if (o >= L->top) return cast(TValue *, luaO_nilobject);\n    else return o;\n  }\n  else if (idx > LUA_REGISTRYINDEX) {\n    api_check(L, idx != 0 && -idx <= L->top - L->base);\n    return L->top + idx;\n  }\n  else switch (idx) {  /* pseudo-indices */\n    case LUA_REGISTRYINDEX: return registry(L);\n    case LUA_ENVIRONINDEX: {\n      Closure *func = curr_func(L);\n      sethvalue(L, &L->env, func->c.env);\n      return &L->env;\n    }\n    case LUA_GLOBALSINDEX: return gt(L);\n    default: {\n      Closure *func = curr_func(L);\n      idx = LUA_GLOBALSINDEX - idx;\n      return (idx <= func->c.nupvalues)\n                ? &func->c.upvalue[idx-1]\n                : cast(TValue *, luaO_nilobject);\n    }\n  }\n}\n\n\nstatic Table *getcurrenv (lua_State *L) {\n  if (L->ci == L->base_ci)  /* no enclosing function? */\n    return hvalue(gt(L));  /* use global table as environment */\n  else {\n    Closure *func = curr_func(L);\n    return func->c.env;\n  }\n}\n\n\nvoid luaA_pushobject (lua_State *L, const TValue *o) {\n  setobj2s(L, L->top, o);\n  api_incr_top(L);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int size) {\n  int res = 1;\n  lua_lock(L);\n  if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)\n    res = 0;  /* stack overflow */\n  else if (size > 0) {\n    luaD_checkstack(L, size);\n    if (L->ci->top < L->top + size)\n      L->ci->top = L->top + size;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to));\n  api_check(from, to->ci->top - to->top >= n);\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobj2s(to, to->top++, from->top + i);\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API void lua_setlevel (lua_State *from, lua_State *to) {\n  to->nCcalls = from->nCcalls;\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  L1 = luaE_newthread(L);\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  lua_unlock(L);\n  luai_userstatethread(L, L1);\n  return L1;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - L->base);\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - L->base);\n    while (L->top < L->base + idx)\n      setnilvalue(L->top++);\n    L->top = L->base + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - L->base));\n    L->top += idx+1;  /* `subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_remove (lua_State *L, int idx) {\n  StkId p;\n  lua_lock(L);\n  p = index2adr(L, idx);\n  api_checkvalidindex(L, p);\n  while (++p < L->top) setobjs2s(L, p-1, p);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_insert (lua_State *L, int idx) {\n  StkId p;\n  StkId q;\n  lua_lock(L);\n  p = index2adr(L, idx);\n  api_checkvalidindex(L, p);\n  for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);\n  setobjs2s(L, p, L->top);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_replace (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  /* explicit test for incompatible code */\n  if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)\n    luaG_runerror(L, \"no calling environment\");\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  if (idx == LUA_ENVIRONINDEX) {\n    Closure *func = curr_func(L);\n    api_check(L, ttistable(L->top - 1)); \n    func->c.env = hvalue(L->top - 1);\n    luaC_barrier(L, func, L->top - 1);\n  }\n  else {\n    setobj(L, o, L->top - 1);\n    if (idx < LUA_GLOBALSINDEX)  /* function upvalue? */\n      luaC_barrier(L, curr_func(L), L->top - 1);\n  }\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2adr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  return (t == LUA_TNONE) ? \"no value\" : luaT_typenames[t];\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return iscfunction(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  int t = lua_type(L, idx);\n  return (t == LUA_TSTRING || t == LUA_TNUMBER);\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2adr(L, idx);\n  return (ttisuserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2adr(L, index1);\n  StkId o2 = index2adr(L, index2);\n  return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0\n         : luaO_rawequalObj(o1, o2);\n}\n\n\nLUA_API int lua_equal (lua_State *L, int index1, int index2) {\n  StkId o1, o2;\n  int i;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2adr(L, index1);\n  o2 = index2adr(L, index2);\n  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API int lua_lessthan (lua_State *L, int index1, int index2) {\n  StkId o1, o2;\n  int i;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2adr(L, index1);\n  o2 = index2adr(L, index2);\n  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0\n       : luaV_lessthan(L, o1, o2);\n  lua_unlock(L);\n  return i;\n}\n\n\n\nLUA_API lua_Number lua_tonumber (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  if (tonumber(o, &n))\n    return nvalue(o);\n  else\n    return 0;\n}\n\n\nLUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  if (tonumber(o, &n)) {\n    lua_Integer res;\n    lua_Number num = nvalue(o);\n    lua_number2integer(res, num);\n    return res;\n  }\n  else\n    return 0;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2adr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2adr(L, idx);\n  if (!ttisstring(o)) {\n    lua_lock(L);  /* `luaV_tostring' may create a new string */\n    if (!luaV_tostring(L, o)) {  /* conversion failed? */\n      if (len != NULL) *len = 0;\n      lua_unlock(L);\n      return NULL;\n    }\n    luaC_checkGC(L);\n    o = index2adr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL) *len = tsvalue(o)->len;\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_objlen (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSTRING: return tsvalue(o)->len;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    case LUA_TNUMBER: {\n      size_t l;\n      lua_lock(L);  /* `luaV_tostring' may create a new string */\n      l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);\n      lua_unlock(L);\n      return l;\n    }\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TUSERDATA: return (rawuvalue(o) + 1);\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TFUNCTION: return clvalue(o);\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA:\n    case LUA_TLIGHTUSERDATA:\n      return lua_touserdata(L, idx);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setnvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setnvalue(L->top, cast_num(n));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  lua_lock(L);\n  luaC_checkGC(L);\n  setsvalue2s(L, L->top, luaS_newlstr(L, s, len));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushstring (lua_State *L, const char *s) {\n  if (s == NULL)\n    lua_pushnil(L);\n  else\n    lua_pushlstring(L, s, strlen(s));\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  luaC_checkGC(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  luaC_checkGC(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  Closure *cl;\n  lua_lock(L);\n  luaC_checkGC(L);\n  api_checknelems(L, n);\n  cl = luaF_newCclosure(L, n, getcurrenv(L));\n  cl->c.f = fn;\n  L->top -= n;\n  while (n--)\n    setobj2n(L, &cl->c.upvalue[n], L->top+n);\n  setclvalue(L, L->top, cl);\n  lua_assert(iswhite(obj2gco(cl)));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(L->top, p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nLUA_API void lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_getfield (lua_State *L, int idx, const char *k) {\n  StkId t;\n  TValue key;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  setsvalue(L, &key, luaS_new(L, k));\n  luaV_gettable(L, t, &key, L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawgeti (lua_State *L, int idx, int n) {\n  StkId o;\n  lua_lock(L);\n  o = index2adr(L, idx);\n  api_check(L, ttistable(o));\n  setobj2s(L, L->top, luaH_getnum(hvalue(o), n));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  lua_lock(L);\n  luaC_checkGC(L);\n  sethvalue(L, L->top, luaH_new(L, narray, nrec));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt = NULL;\n  int res;\n  lua_lock(L);\n  obj = index2adr(L, objindex);\n  switch (ttype(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(obj)];\n      break;\n  }\n  if (mt == NULL)\n    res = 0;\n  else {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_getfenv (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  switch (ttype(o)) {\n    case LUA_TFUNCTION:\n      sethvalue(L, L->top, clvalue(o)->c.env);\n      break;\n    case LUA_TUSERDATA:\n      sethvalue(L, L->top, uvalue(o)->env);\n      break;\n    case LUA_TTHREAD:\n      setobj2s(L, L->top,  gt(thvalue(o)));\n      break;\n    default:\n      setnilvalue(L->top);\n      break;\n  }\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  StkId t;\n  TValue key;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  setsvalue(L, &key, luaS_new(L, k));\n  luaV_settable(L, t, &key, L->top - 1);\n  L->top--;  /* pop value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);\n  luaC_barriert(L, hvalue(t), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, int n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_check(L, ttistable(o));\n  setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);\n  luaC_barriert(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2adr(L, objindex);\n  api_checkvalidindex(L, obj);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1));\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttype(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt)\n        luaC_objbarriert(L, hvalue(obj), mt);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt)\n        luaC_objbarrier(L, rawuvalue(obj), mt);\n      break;\n    }\n    default: {\n      G(L)->mt[ttype(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API int lua_setfenv (lua_State *L, int idx) {\n  StkId o;\n  int res = 1;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  api_check(L, ttistable(L->top - 1));\n  switch (ttype(o)) {\n    case LUA_TFUNCTION:\n      clvalue(o)->c.env = hvalue(L->top - 1);\n      break;\n    case LUA_TUSERDATA:\n      uvalue(o)->env = hvalue(L->top - 1);\n      break;\n    case LUA_TTHREAD:\n      sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));\n      break;\n    default:\n      res = 0;\n      break;\n  }\n  if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));\n  L->top--;\n  lua_unlock(L);\n  return res;\n}\n\n\n/*\n** `load' and `call' functions (run Lua code)\n*/\n\n\n#define adjustresults(L,nres) \\\n    { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))\n\t\n\nLUA_API void lua_call (lua_State *L, int nargs, int nresults) {\n  StkId func;\n  lua_lock(L);\n  api_checknelems(L, nargs+1);\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  luaD_call(L, func, nresults);\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to `f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_call(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_checknelems(L, nargs+1);\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2adr(L, errfunc);\n    api_checkvalidindex(L, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  c.nresults = nresults;\n  status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** Execute a protected C call.\n*/\nstruct CCallS {  /* data to `f_Ccall' */\n  lua_CFunction func;\n  void *ud;\n};\n\n\nstatic void f_Ccall (lua_State *L, void *ud) {\n  struct CCallS *c = cast(struct CCallS *, ud);\n  Closure *cl;\n  cl = luaF_newCclosure(L, 0, getcurrenv(L));\n  cl->c.f = c->func;\n  setclvalue(L, L->top, cl);  /* push function */\n  api_incr_top(L);\n  setpvalue(L->top, c->ud);  /* push only argument */\n  api_incr_top(L);\n  luaD_call(L, L->top - 2, 0);\n}\n\n\nLUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {\n  struct CCallS c;\n  int status;\n  lua_lock(L);\n  c.func = func;\n  c.ud = ud;\n  status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int  lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->GCthreshold = MAX_LUMEM;\n      break;\n    }\n    case LUA_GCRESTART: {\n      g->GCthreshold = g->totalbytes;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(g->totalbytes >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(g->totalbytes & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      lu_mem a = (cast(lu_mem, data) << 10);\n      if (a <= g->totalbytes)\n        g->GCthreshold = g->totalbytes - a;\n      else\n        g->GCthreshold = 0;\n      while (g->GCthreshold <= g->totalbytes) {\n        luaC_step(L);\n        if (g->gcstate == GCSpause) {  /* end of cycle? */\n          res = 1;  /* signal it */\n          break;\n        }\n      }\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      g->gcstepmul = data;\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  lua_unlock(L);\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaC_checkGC(L);\n    luaV_concat(L, n, cast_int(L->top - L->base) - 1);\n    L->top -= (n-1);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  luaC_checkGC(L);\n  u = luaS_newudata(L, size, getcurrenv(L));\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  lua_unlock(L);\n  return u + 1;\n}\n\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val) {\n  Closure *f;\n  if (!ttisfunction(fi)) return NULL;\n  f = clvalue(fi);\n  if (f->c.isC) {\n    if (!(1 <= n && n <= f->c.nupvalues)) return NULL;\n    *val = &f->c.upvalue[n-1];\n    return \"\";\n  }\n  else {\n    Proto *p = f->l.p;\n    if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n    *val = f->l.upvals[n-1]->v;\n    return getstr(p->upvalues[n-1]);\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val;\n  lua_lock(L);\n  name = aux_upvalue(index2adr(L, funcindex), n, &val);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val;\n  StkId fi;\n  lua_lock(L);\n  fi = index2adr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    luaC_barrier(L, clvalue(fi), L->top);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"lobject.h\"\n\n\nLUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/* This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n#define FREELIST_REF\t0\t/* free list of references */\n\n\n/* convert a stack index to positive */\n#define abs_index(L, i)\t\t((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \\\n\t\t\t\t\tlua_gettop(L) + (i) + 1)\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\n\nLUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", narg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    narg--;  /* do not count `self' */\n    if (narg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling \" LUA_QS \" on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = \"?\";\n  return luaL_error(L, \"bad argument #%d to \" LUA_QS \" (%s)\",\n                        narg, ar.name, extramsg);\n}\n\n\nLUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {\n  const char *msg = lua_pushfstring(L, \"%s expected, got %s\",\n                                    tname, luaL_typename(L, narg));\n  return luaL_argerror(L, narg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int narg, int tag) {\n  luaL_typerror(L, narg, lua_typename(L, tag));\n}\n\n\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushliteral(L, \"\");  /* else, no information available... */\n}\n\n\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n/* }====================================================== */\n\n\nLUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, narg, def) :\n                             luaL_checkstring(L, narg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, narg,\n                       lua_pushfstring(L, \"invalid option \" LUA_QS, name));\n}\n\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get registry.name */\n  if (!lua_isnil(L, -1))  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_newtable(L);  /* create metatable */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */\n      if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */\n        lua_pop(L, 2);  /* remove both metatables */\n        return p;\n      }\n    }\n  }\n  luaL_typerror(L, ud, tname);  /* else error */\n  return NULL;  /* to avoid warnings */\n}\n\n\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {\n  if (!lua_checkstack(L, space))\n    luaL_error(L, \"stack overflow (%s)\", mes);\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {\n  if (lua_type(L, narg) != t)\n    tag_error(L, narg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int narg) {\n  if (lua_type(L, narg) == LUA_TNONE)\n    luaL_argerror(L, narg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {\n  const char *s = lua_tolstring(L, narg, len);\n  if (!s) tag_error(L, narg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int narg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, narg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, narg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {\n  lua_Number d = lua_tonumber(L, narg);\n  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */\n    tag_error(L, narg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, narg, def);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {\n  lua_Integer d = lua_tointeger(L, narg);\n  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */\n    tag_error(L, narg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, narg, def);\n}\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return 0;\n  lua_pushstring(L, event);\n  lua_rawget(L, -2);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 2);  /* remove metatable and metafield */\n    return 0;\n  }\n  else {\n    lua_remove(L, -2);  /* remove only metatable */\n    return 1;\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = abs_index(L, obj);\n  if (!luaL_getmetafield(L, obj, event))  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l) {\n  luaI_openlib(L, libname, l, 0);\n}\n\n\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l->name; l++) size++;\n  return size;\n}\n\n\nLUALIB_API void luaI_openlib (lua_State *L, const char *libname,\n                              const luaL_Reg *l, int nup) {\n  if (libname) {\n    int size = libsize(l);\n    /* check whether lib already exists */\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 1);\n    lua_getfield(L, -1, libname);  /* get _LOADED[libname] */\n    if (!lua_istable(L, -1)) {  /* not found? */\n      lua_pop(L, 1);  /* remove previous result */\n      /* try global variable (and create one if it does not exist) */\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)\n        luaL_error(L, \"name conflict for module \" LUA_QS, libname);\n      lua_pushvalue(L, -1);\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    lua_remove(L, -2);  /* remove _LOADED table */\n    lua_insert(L, -(nup+1));  /* move library table to below upvalues */\n  }\n  for (; l->name; l++) {\n    int i;\n    for (i=0; i<nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);\n    lua_setfield(L, -(nup+2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n\n/*\n** {======================================================\n** getn-setn: size for arrays\n** =======================================================\n*/\n\n#if defined(LUA_COMPAT_GETN)\n\nstatic int checkint (lua_State *L, int topop) {\n  int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;\n  lua_pop(L, topop);\n  return n;\n}\n\n\nstatic void getsizes (lua_State *L) {\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_SIZES\");\n  if (lua_isnil(L, -1)) {  /* no `size' table? */\n    lua_pop(L, 1);  /* remove nil */\n    lua_newtable(L);  /* create it */\n    lua_pushvalue(L, -1);  /* `size' will be its own metatable */\n    lua_setmetatable(L, -2);\n    lua_pushliteral(L, \"kv\");\n    lua_setfield(L, -2, \"__mode\");  /* metatable(N).__mode = \"kv\" */\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_SIZES\");  /* store in register */\n  }\n}\n\n\nLUALIB_API void luaL_setn (lua_State *L, int t, int n) {\n  t = abs_index(L, t);\n  lua_pushliteral(L, \"n\");\n  lua_rawget(L, t);\n  if (checkint(L, 1) >= 0) {  /* is there a numeric field `n'? */\n    lua_pushliteral(L, \"n\");  /* use it */\n    lua_pushinteger(L, n);\n    lua_rawset(L, t);\n  }\n  else {  /* use `sizes' */\n    getsizes(L);\n    lua_pushvalue(L, t);\n    lua_pushinteger(L, n);\n    lua_rawset(L, -3);  /* sizes[t] = n */\n    lua_pop(L, 1);  /* remove `sizes' */\n  }\n}\n\n\nLUALIB_API int luaL_getn (lua_State *L, int t) {\n  int n;\n  t = abs_index(L, t);\n  lua_pushliteral(L, \"n\");  /* try t.n */\n  lua_rawget(L, t);\n  if ((n = checkint(L, 1)) >= 0) return n;\n  getsizes(L);  /* else try sizes[t] */\n  lua_pushvalue(L, t);\n  lua_rawget(L, -2);\n  if ((n = checkint(L, 2)) >= 0) return n;\n  return (int)lua_objlen(L, t);\n}\n\n#endif\n\n/* }====================================================== */\n\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after `p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nLUALIB_API const char *luaL_findtable (lua_State *L, int idx,\n                                       const char *fname, int szhint) {\n  const char *e;\n  lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    lua_rawget(L, -2);\n    if (lua_isnil(L, -1)) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n#define bufflen(B)\t((B)->p - (B)->buffer)\n#define bufffree(B)\t((size_t)(LUAL_BUFFERSIZE - bufflen(B)))\n\n#define LIMIT\t(LUA_MINSTACK/2)\n\n\nstatic int emptybuffer (luaL_Buffer *B) {\n  size_t l = bufflen(B);\n  if (l == 0) return 0;  /* put nothing on stack */\n  else {\n    lua_pushlstring(B->L, B->buffer, l);\n    B->p = B->buffer;\n    B->lvl++;\n    return 1;\n  }\n}\n\n\nstatic void adjuststack (luaL_Buffer *B) {\n  if (B->lvl > 1) {\n    lua_State *L = B->L;\n    int toget = 1;  /* number of levels to concat */\n    size_t toplen = lua_strlen(L, -1);\n    do {\n      size_t l = lua_strlen(L, -(toget+1));\n      if (B->lvl - toget + 1 >= LIMIT || toplen > l) {\n        toplen += l;\n        toget++;\n      }\n      else break;\n    } while (toget < B->lvl);\n    lua_concat(L, toget);\n    B->lvl = B->lvl - toget + 1;\n  }\n}\n\n\nLUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {\n  if (emptybuffer(B))\n    adjuststack(B);\n  return B->buffer;\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  while (l--)\n    luaL_addchar(B, *s++);\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  emptybuffer(B);\n  lua_concat(B->L, B->lvl);\n  B->lvl = 1;\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t vl;\n  const char *s = lua_tolstring(L, -1, &vl);\n  if (vl <= bufffree(B)) {  /* fit into buffer? */\n    memcpy(B->p, s, vl);  /* put it there */\n    B->p += vl;\n    lua_pop(L, 1);  /* remove from stack */\n  }\n  else {\n    if (emptybuffer(B))\n      lua_insert(L, -2);  /* put buffer before new value */\n    B->lvl++;  /* add new value into B stack */\n    adjuststack(B);\n  }\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->p = B->buffer;\n  B->lvl = 0;\n}\n\n/* }====================================================== */\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  t = abs_index(L, t);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* `nil' has a unique fixed reference */\n  }\n  lua_rawgeti(L, t, FREELIST_REF);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[FREELIST_REF] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, FREELIST_REF);  /* (t[FREELIST_REF] = t[ref]) */\n  }\n  else {  /* no free elements */\n    ref = (int)lua_objlen(L, t);\n    ref++;  /* create new reference */\n  }\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = abs_index(L, t);\n    lua_rawgeti(L, t, FREELIST_REF);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */\n  }\n}\n\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int extraline;\n  FILE *f;\n  char buff[LUAL_BUFFERSIZE];\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;\n  if (lf->extraline) {\n    lf->extraline = 0;\n    *size = 1;\n    return \"\\n\";\n  }\n  if (feof(lf->f)) return NULL;\n  *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);\n  return (*size > 0) ? lf->buff : NULL;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nLUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  lf.extraline = 0;\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  c = getc(lf.f);\n  if (c == '#') {  /* Unix exec. file? */\n    lf.extraline = 1;\n    while ((c = getc(lf.f)) != EOF && c != '\\n') ;  /* skip first line */\n    if (c == '\\n') c = getc(lf.f);\n  }\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    /* skip eventual `#!...' */\n   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;\n    lf.extraline = 0;\n  }\n  ungetc(c, lf.f);\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1));\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from `lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,\n                                const char *name) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name);\n}\n\n\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n\n\n/* }====================================================== */\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud;\n  (void)osize;\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  (void)L;  /* to avoid warnings */\n  fprintf(stderr, \"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                   lua_tostring(L, -1));\n  return 0;\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n#if defined(LUA_COMPAT_GETN)\nLUALIB_API int (luaL_getn) (lua_State *L, int t);\nLUALIB_API void (luaL_setn) (lua_State *L, int t, int n);\n#else\n#define luaL_getn(L,i)          ((int)lua_objlen(L, i))\n#define luaL_setn(L,i,j)        ((void)0)  /* no op! */\n#endif\n\n#if defined(LUA_COMPAT_OPENLIB)\n#define luaI_openlib\tluaL_openlib\n#endif\n\n\n/* extra error code for `luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n\nLUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l);\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);\nLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int narg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);\nLUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,\n                                  const char *name);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,\n                                         const char *fname, int szhint);\n\n\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define luaL_argcheck(L, cond,numarg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n\ntypedef struct luaL_Buffer {\n  char *p;\t\t\t/* current position in buffer */\n  int lvl;  /* number of strings in the stack (level) */\n  lua_State *L;\n  char buffer[LUAL_BUFFERSIZE];\n} luaL_Buffer;\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \\\n   (*(B)->p++ = (char)(c)))\n\n/* compatibility only */\n#define luaL_putchar(B,c)\tluaL_addchar(B,c)\n\n#define luaL_addsize(B,n)\t((B)->p += (n))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\n\n\n/* }====================================================== */\n\n\n/* compatibility with ref system */\n\n/* pre-defined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\n#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \\\n      (lua_pushstring(L, \"unlocked references are obsolete\"), lua_error(L), 0))\n\n#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))\n\n#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))\n\n\n#define luaL_reg\tluaL_Reg\n\n#endif\n\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** If your system does not support `stdout', you can just remove this function.\n** If you need, you can define your own `print' function, following this\n** model but changing `fputs' to put the strings at a proper place\n** (a console window or a log file, for instance).\n*/\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tostring(L, -1);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, LUA_QL(\"tostring\") \" must return a string to \"\n                           LUA_QL(\"print\"));\n    if (i>1) fputs(\"\\t\", stdout);\n    fputs(s, stdout);\n    lua_pop(L, 1);  /* pop result */\n  }\n  fputs(\"\\n\", stdout);\n  return 0;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  int base = luaL_optint(L, 2, 10);\n  if (base == 10) {  /* standard conversion */\n    luaL_checkany(L, 1);\n    if (lua_isnumber(L, 1)) {\n      lua_pushnumber(L, lua_tonumber(L, 1));\n      return 1;\n    }\n  }\n  else {\n    const char *s1 = luaL_checkstring(L, 1);\n    char *s2;\n    unsigned long n;\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    n = strtoul(s1, &s2, base);\n    if (s1 != s2) {  /* at least one valid digit? */\n      while (isspace((unsigned char)(*s2))) s2++;  /* skip trailing spaces */\n      if (*s2 == '\\0') {  /* no invalid trailing characters? */\n        lua_pushnumber(L, (lua_Number)n);\n        return 1;\n      }\n    }\n  }\n  lua_pushnil(L);  /* else not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = luaL_optint(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_isstring(L, 1) && level > 0) {  /* add extra information? */\n    luaL_where(L, level);\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\"))\n    luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic void getfunc (lua_State *L, int opt) {\n  if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);\n  else {\n    lua_Debug ar;\n    int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);\n    luaL_argcheck(L, level >= 0, 1, \"level must be non-negative\");\n    if (lua_getstack(L, level, &ar) == 0)\n      luaL_argerror(L, 1, \"invalid level\");\n    lua_getinfo(L, \"f\", &ar);\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"no function environment for tail call at level %d\",\n                    level);\n  }\n}\n\n\nstatic int luaB_getfenv (lua_State *L) {\n  getfunc(L, 1);\n  if (lua_iscfunction(L, -1))  /* is a C function? */\n    lua_pushvalue(L, LUA_GLOBALSINDEX);  /* return the thread's global env. */\n  else\n    lua_getfenv(L, -1);\n  return 1;\n}\n\n\nstatic int luaB_setfenv (lua_State *L) {\n  luaL_checktype(L, 2, LUA_TTABLE);\n  getfunc(L, 0);\n  lua_pushvalue(L, 2);\n  if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {\n    /* change environment of current thread */\n    lua_pushthread(L);\n    lua_insert(L, -2);\n    lua_setfenv(L, -2);\n    return 0;\n  }\n  else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)\n    luaL_error(L,\n          LUA_QL(\"setfenv\") \" cannot change environment of given object\");\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_gcinfo (lua_State *L) {\n  lua_pushinteger(L, lua_getgccount(L));\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};\n  int o = luaL_checkoption(L, 1, \"collect\", opts);\n  int ex = luaL_optint(L, 2, 0);\n  int res = lua_gc(L, optsnum[o], ex);\n  switch (optsnum[o]) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushnumber(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  luaL_checkany(L, 1);\n  lua_pushstring(L, luaL_typename(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */\n  lua_pushvalue(L, 1);  /* state, */\n  lua_pushnil(L);  /* and initial value */\n  return 3;\n}\n\n\nstatic int ipairsaux (lua_State *L) {\n  int i = luaL_checkint(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i++;  /* next value */\n  lua_pushinteger(L, i);\n  lua_rawgeti(L, 1, i);\n  return (lua_isnil(L, -1)) ? 0 : 2;\n}\n\n\nstatic int luaB_ipairs (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */\n  lua_pushvalue(L, 1);  /* state, */\n  lua_pushinteger(L, 0);  /* and initial value */\n  return 3;\n}\n\n\nstatic int load_aux (lua_State *L, int status) {\n  if (status == 0)  /* OK? */\n    return 1;\n  else {\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadstring (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  const char *chunkname = luaL_optstring(L, 2, s);\n  return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  return load_aux(L, luaL_loadfile(L, fname));\n}\n\n\n/*\n** Reader for generic `load' function: `lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)ud;  /* to avoid warnings */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    *size = 0;\n    return NULL;\n  }\n  else if (lua_isstring(L, -1)) {\n    lua_replace(L, 3);  /* save string in a reserved stack slot */\n    return lua_tolstring(L, 3, size);\n  }\n  else luaL_error(L, \"reader function must return a string\");\n  return NULL;  /* to avoid warnings */\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  const char *cname = luaL_optstring(L, 2, \"=(load)\");\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 3);  /* function, eventual name, plus one reserved slot */\n  status = lua_load(L, generic_reader, NULL, cname);\n  return load_aux(L, status);\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  int n = lua_gettop(L);\n  if (luaL_loadfile(L, fname) != 0) lua_error(L);\n  lua_call(L, 0, LUA_MULTRET);\n  return lua_gettop(L) - n;\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_toboolean(L, 1))\n    return luaL_error(L, \"%s\", luaL_optstring(L, 2, \"assertion failed!\"));\n  return lua_gettop(L);\n}\n\n\nstatic int luaB_unpack (lua_State *L) {\n  int i, e, n;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i = luaL_optint(L, 2, 1);\n  e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = e - i + 1;  /* number of elements */\n  if (n <= 0 || !lua_checkstack(L, n))  /* n <= 0 means arith. overflow */\n    return luaL_error(L, \"too many results to unpack\");\n  lua_rawgeti(L, 1, i);  /* push arg[i] (avoiding overflow problems) */\n  while (i++ < e)  /* push arg[i + 1...e] */\n    lua_rawgeti(L, 1, i);\n  return n;\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    int i = luaL_checkint(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - i;\n  }\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);\n  lua_pushboolean(L, (status == 0));\n  lua_insert(L, 1);\n  return lua_gettop(L);  /* return status + all results */\n}\n\n\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_insert(L, 1);  /* put error function under function to be called */\n  status = lua_pcall(L, 0, LUA_MULTRET, 1);\n  lua_pushboolean(L, (status == 0));\n  lua_replace(L, 1);\n  return lua_gettop(L);  /* return status + all results */\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (luaL_callmeta(L, 1, \"__tostring\"))  /* is there a metafield? */\n    return 1;  /* use its value */\n  switch (lua_type(L, 1)) {\n    case LUA_TNUMBER:\n      lua_pushstring(L, lua_tostring(L, 1));\n      break;\n    case LUA_TSTRING:\n      lua_pushvalue(L, 1);\n      break;\n    case LUA_TBOOLEAN:\n      lua_pushstring(L, (lua_toboolean(L, 1) ? \"true\" : \"false\"));\n      break;\n    case LUA_TNIL:\n      lua_pushliteral(L, \"nil\");\n      break;\n    default:\n      lua_pushfstring(L, \"%s: %p\", luaL_typename(L, 1), lua_topointer(L, 1));\n      break;\n  }\n  return 1;\n}\n\n\nstatic int luaB_newproxy (lua_State *L) {\n  lua_settop(L, 1);\n  lua_newuserdata(L, 0);  /* create proxy */\n  if (lua_toboolean(L, 1) == 0)\n    return 1;  /* no metatable */\n  else if (lua_isboolean(L, 1)) {\n    lua_newtable(L);  /* create a new metatable `m' ... */\n    lua_pushvalue(L, -1);  /* ... and mark `m' as a valid metatable */\n    lua_pushboolean(L, 1);\n    lua_rawset(L, lua_upvalueindex(1));  /* weaktable[m] = true */\n  }\n  else {\n    int validproxy = 0;  /* to check if weaktable[metatable(u)] == true */\n    if (lua_getmetatable(L, 1)) {\n      lua_rawget(L, lua_upvalueindex(1));\n      validproxy = lua_toboolean(L, -1);\n      lua_pop(L, 1);  /* remove value */\n    }\n    luaL_argcheck(L, validproxy, 1, \"boolean or proxy expected\");\n    lua_getmetatable(L, 1);  /* metatable is valid; get it */\n  }\n  lua_setmetatable(L, 2);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"gcinfo\", luaB_gcinfo},\n  {\"getfenv\", luaB_getfenv},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n  {\"loadstring\", luaB_loadstring},\n  {\"next\", luaB_next},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setfenv\", luaB_setfenv},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"unpack\", luaB_unpack},\n  {\"xpcall\", luaB_xpcall},\n  {NULL, NULL}\n};\n\n\n/*\n** {======================================================\n** Coroutine library\n** =======================================================\n*/\n\n#define CO_RUN\t0\t/* running */\n#define CO_SUS\t1\t/* suspended */\n#define CO_NOR\t2\t/* 'normal' (it resumed another coroutine) */\n#define CO_DEAD\t3\n\nstatic const char *const statnames[] =\n    {\"running\", \"suspended\", \"normal\", \"dead\"};\n\nstatic int costatus (lua_State *L, lua_State *co) {\n  if (L == co) return CO_RUN;\n  switch (lua_status(co)) {\n    case LUA_YIELD:\n      return CO_SUS;\n    case 0: {\n      lua_Debug ar;\n      if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n        return CO_NOR;  /* it is running */\n      else if (lua_gettop(co) == 0)\n          return CO_DEAD;\n      else\n        return CO_SUS;  /* initial state */\n    }\n    default:  /* some error occured */\n      return CO_DEAD;\n  }\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"coroutine expected\");\n  lua_pushstring(L, statnames[costatus(L, co)]);\n  return 1;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status = costatus(L, co);\n  if (!lua_checkstack(co, narg))\n    luaL_error(L, \"too many arguments to resume\");\n  if (status != CO_SUS) {\n    lua_pushfstring(L, \"cannot resume %s coroutine\", statnames[status]);\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  lua_setlevel(L, co);\n  status = lua_resume(co, narg);\n  if (status == 0 || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1))\n      luaL_error(L, \"too many results to resume\");\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  int r;\n  luaL_argcheck(L, co, 1, \"coroutine expected\");\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + `resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_isstring(L, -1)) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL = lua_newthread(L);\n  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,\n    \"Lua function expected\");\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  if (lua_pushthread(L))\n    lua_pushnil(L);  /* main thread is not a coroutine */\n  return 1;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\nstatic void auxopen (lua_State *L, const char *name,\n                     lua_CFunction f, lua_CFunction u) {\n  lua_pushcfunction(L, u);\n  lua_pushcclosure(L, f, 1);\n  lua_setfield(L, -2, name);\n}\n\n\nstatic void base_open (lua_State *L) {\n  /* set global _G */\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setglobal(L, \"_G\");\n  /* open lib into global table */\n  luaL_register(L, \"_G\", base_funcs);\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setglobal(L, \"_VERSION\");  /* set global _VERSION */\n  /* `ipairs' and `pairs' need auxiliary functions as upvalues */\n  auxopen(L, \"ipairs\", luaB_ipairs, ipairsaux);\n  auxopen(L, \"pairs\", luaB_pairs, luaB_next);\n  /* `newproxy' needs a weaktable as upvalue */\n  lua_createtable(L, 0, 1);  /* new table `w' */\n  lua_pushvalue(L, -1);  /* `w' will be its own metatable */\n  lua_setmetatable(L, -2);\n  lua_pushliteral(L, \"kv\");\n  lua_setfield(L, -2, \"__mode\");  /* metatable(w).__mode = \"kv\" */\n  lua_pushcclosure(L, luaB_newproxy, 1);\n  lua_setglobal(L, \"newproxy\");  /* set global `newproxy' */\n}\n\n\nLUALIB_API int luaopen_base (lua_State *L) {\n  base_open(L);\n  luaL_register(L, LUA_COLIBNAME, co_funcs);\n  return 2;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.25.1.5 2011/01/31 14:53:16 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdlib.h>\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"ltable.h\"\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\nstatic int isnumeral(expdesc *e) {\n  return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);\n}\n\n\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    if (fs->pc == 0) {  /* function start? */\n      if (from >= fs->nactvar)\n        return;  /* positions are already clean */\n    }\n    else {\n      previous = &fs->f->code[fs->pc-1];\n      if (GET_OPCODE(*previous) == OP_LOADNIL) {\n        int pfrom = GETARG_A(*previous);\n        int pto = GETARG_B(*previous);\n        if (pfrom <= from && from <= pto+1) {  /* can connect both? */\n          if (from+n-1 > pto)\n            SETARG_B(*previous, from+n-1);\n          return;\n        }\n      }\n    }\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0);  /* else no optimization */\n}\n\n\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest-(pc+1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** returns current `pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** (or produce an inverted value)\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else  /* no register to put value or register already has the value */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n\n  return 1;\n}\n\n\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)\n    luaK_patchtohere(fs, list);\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;\n  else if (*l1 == NO_JUMP)\n    *l1 = l2;\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);\n  }\n}\n\n\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXSTACK)\n      luaX_syntaxerror(fs->ls, \"function or expression too complex\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.s.info);\n}\n\n\nstatic int addk (FuncState *fs, TValue *k, TValue *v) {\n  lua_State *L = fs->L;\n  TValue *idx = luaH_set(L, fs->h, k);\n  Proto *f = fs->f;\n  int oldsize = f->sizek;\n  if (ttisnumber(idx)) {\n    lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));\n    return cast_int(nvalue(idx));\n  }\n  else {  /* constant not found; create a new entry */\n    setnvalue(idx, cast_num(fs->nk));\n    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,\n                    MAXARG_Bx, \"constant table overflow\");\n    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n    setobj(L, &f->k[fs->nk], v);\n    luaC_barrier(L, f, v);\n    return fs->nk++;\n  }\n}\n\n\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->L, &o, s);\n  return addk(fs, &o, &o);\n}\n\n\nint luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setnvalue(&o, r);\n  return addk(fs, &o, &o);\n}\n\n\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);\n}\n\n\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->L, &k, fs->h);\n  return addk(fs, &k, &v);\n}\n\n\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getcode(fs, e), nresults+1);\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getcode(fs, e), nresults+1);\n    SETARG_A(getcode(fs, e), fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    e->k = VNONRELOC;\n    e->u.s.info = GETARG_A(getcode(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getcode(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {\n      e->k = VNONRELOC;\n      break;\n    }\n    case VUPVAL: {\n      e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VGLOBAL: {\n      e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      freereg(fs, e->u.s.aux);\n      freereg(fs, e->u.s.info);\n      e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG:\n    case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\nstatic int code_label (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE:  case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);\n      break;\n    }\n    case VKNUM: {\n      luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getcode(fs, e);\n      SETARG_A(*pc, reg);\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.s.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VVOID || e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {\n    luaK_reserveregs(fs, 1);\n    discharge2reg(fs, e, fs->freereg-1);\n  }\n}\n\n\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)\n    luaK_concat(fs, &e->t, e->u.s.info);  /* put this jump in `t' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_label(fs, reg, 0, 1);\n      p_t = code_label(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {\n    if (!hasjumps(e)) return e->u.s.info;  /* exp is already in a register */\n    if (e->u.s.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.s.info);  /* put value on it */\n      return e->u.s.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* default */\n  return e->u.s.info;\n}\n\n\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {\n    case VKNUM:\n    case VTRUE:\n    case VFALSE:\n    case VNIL: {\n      if (fs->nk <= MAXINDEXRK) {  /* constant fit in RK operand? */\n        e->u.s.info = (e->k == VNIL)  ? nilK(fs) :\n                      (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :\n                                        boolK(fs, (e->k == VTRUE));\n        e->k = VK;\n        return RKASK(e->u.s.info);\n      }\n      else break;\n    }\n    case VK: {\n      if (e->u.s.info <= MAXINDEXRK)  /* constant fit in argC? */\n        return RKASK(e->u.s.info);\n      else break;\n    }\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.s.info);\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);\n      break;\n    }\n    case VGLOBAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);\n      break;\n    }\n    case VINDEXED: {\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);\n      break;\n    }\n    default: {\n      lua_assert(0);  /* invalid var kind to store */\n      break;\n    }\n  }\n  freeexp(fs, ex);\n}\n\n\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int func;\n  luaK_exp2anyreg(fs, e);\n  freeexp(fs, e);\n  func = fs->freereg;\n  luaK_reserveregs(fs, 2);\n  luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n  e->u.s.info = func;\n  e->k = VNONRELOC;\n}\n\n\nstatic void invertjump (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.s.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getcode(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);\n}\n\n\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of last jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VK: case VKNUM: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    case VJMP: {\n      invertjump(fs, e);\n      pc = e->u.s.info;\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */\n  luaK_patchtohere(fs, e->t);\n  e->t = NO_JUMP;\n}\n\n\nstatic void luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of last jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    case VJMP: {\n      pc = e->u.s.info;\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */\n  luaK_patchtohere(fs, e->f);\n  e->f = NO_JUMP;\n}\n\n\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;\n      break;\n    }\n    case VK: case VKNUM: case VTRUE: {\n      e->k = VFALSE;\n      break;\n    }\n    case VJMP: {\n      invertjump(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: {\n      lua_assert(0);  /* cannot happen */\n      break;\n    }\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);\n  removevalues(fs, e->t);\n}\n\n\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  t->u.s.aux = luaK_exp2RK(fs, k);\n  t->k = VINDEXED;\n}\n\n\nstatic int constfolding (OpCode op, expdesc *e1, expdesc *e2) {\n  lua_Number v1, v2, r;\n  if (!isnumeral(e1) || !isnumeral(e2)) return 0;\n  v1 = e1->u.nval;\n  v2 = e2->u.nval;\n  switch (op) {\n    case OP_ADD: r = luai_numadd(v1, v2); break;\n    case OP_SUB: r = luai_numsub(v1, v2); break;\n    case OP_MUL: r = luai_nummul(v1, v2); break;\n    case OP_DIV:\n      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */\n      r = luai_numdiv(v1, v2); break;\n    case OP_MOD:\n      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */\n      r = luai_nummod(v1, v2); break;\n    case OP_POW: r = luai_numpow(v1, v2); break;\n    case OP_UNM: r = luai_numunm(v1); break;\n    case OP_LEN: return 0;  /* no constant folding for 'len' */\n    default: lua_assert(0); r = 0; break;\n  }\n  if (luai_numisnan(r)) return 0;  /* do not attempt to produce NaN */\n  e1->u.nval = r;\n  return 1;\n}\n\n\nstatic void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {\n  if (constfolding(op, e1, e2))\n    return;\n  else {\n    int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;\n    int o1 = luaK_exp2RK(fs, e1);\n    if (o1 > o2) {\n      freeexp(fs, e1);\n      freeexp(fs, e2);\n    }\n    else {\n      freeexp(fs, e2);\n      freeexp(fs, e1);\n    }\n    e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);\n    e1->k = VRELOCABLE;\n  }\n}\n\n\nstatic void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,\n                                                          expdesc *e2) {\n  int o1 = luaK_exp2RK(fs, e1);\n  int o2 = luaK_exp2RK(fs, e2);\n  freeexp(fs, e2);\n  freeexp(fs, e1);\n  if (cond == 0 && op != OP_EQ) {\n    int temp;  /* exchange args to replace by `<' or `<=' */\n    temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */\n    cond = 1;\n  }\n  e1->u.s.info = condjump(fs, op, cond, o1, o2);\n  e1->k = VJMP;\n}\n\n\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {\n  expdesc e2;\n  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;\n  switch (op) {\n    case OPR_MINUS: {\n      if (!isnumeral(e))\n        luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */\n      codearith(fs, OP_UNM, e, &e2);\n      break;\n    }\n    case OPR_NOT: codenot(fs, e); break;\n    case OPR_LEN: {\n      luaK_exp2anyreg(fs, e);  /* cannot operate on constants */\n      codearith(fs, OP_LEN, e, &e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_MOD: case OPR_POW: {\n      if (!isnumeral(v)) luaK_exp2RK(fs, v);\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\nvoid luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list must be closed */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list must be closed */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getcode(fs, e2), e1->u.s.info);\n        e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codearith(fs, OP_CONCAT, e1, e2);\n      }\n      break;\n    }\n    case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;\n    case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;\n    case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;\n    case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;\n    case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;\n    case OPR_POW: codearith(fs, OP_POW, e1, e2); break;\n    case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;\n    case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;\n    case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;\n    case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;\n    case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;\n    case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;\n    default: lua_assert(0);\n  }\n}\n\n\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\nstatic int luaK_code (FuncState *fs, Instruction i, int line) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* `pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"code size overflow\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"code size overflow\");\n  f->lineinfo[fs->pc] = line;\n  return fs->pc++;\n}\n\n\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);\n}\n\n\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);\n}\n\n\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    luaK_code(fs, cast(Instruction, c), fs->ls->lastline);\n  }\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,\n  OPR_CONCAT,\n  OPR_NE, OPR_EQ,\n  OPR_LT, OPR_LE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n#define getcode(fs,e)\t((fs)->f->code[(e)->u.s.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.104.1.4 2009/08/04 18:50:18 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_pushboolean(L, lua_setmetatable(L, 1));\n  return 1;\n}\n\n\nstatic int db_getfenv (lua_State *L) {\n  luaL_checkany(L, 1);\n  lua_getfenv(L, 1);\n  return 1;\n}\n\n\nstatic int db_setfenv (lua_State *L) {\n  luaL_checktype(L, 2, LUA_TTABLE);\n  lua_settop(L, 2);\n  if (lua_setfenv(L, 1) == 0)\n    luaL_error(L, LUA_QL(\"setfenv\")\n                  \" cannot change environment of given object\");\n  return 1;\n}\n\n\nstatic void settabss (lua_State *L, const char *i, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, i);\n}\n\n\nstatic void settabsi (lua_State *L, const char *i, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, i);\n}\n\n\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;\n  }\n}\n\n\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1) {\n    lua_pushvalue(L, -2);\n    lua_remove(L, -3);\n  }\n  else\n    lua_xmove(L1, L, 1);\n  lua_setfield(L, -2, fname);\n}\n\n\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnSu\");\n  if (lua_isnumber(L, arg+1)) {\n    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  else if (lua_isfunction(L, arg+1)) {\n    lua_pushfstring(L, \">%s\", options);\n    options = lua_tostring(L, -1);\n    lua_pushvalue(L, arg+1);\n    lua_xmove(L, L1, 1);\n  }\n  else\n    return luaL_argerror(L, arg+1, \"function or level expected\");\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_createtable(L, 0, 2);\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u'))\n    settabsi(L, \"nups\", ar.nups);\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n    \n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2));\n  if (name) {\n    lua_xmove(L1, L, 1);\n    lua_pushstring(L, name);\n    lua_pushvalue(L, -2);\n    return 2;\n  }\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  lua_xmove(L, L1, 1);\n  lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));\n  return 1;\n}\n\n\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = luaL_checkint(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  if (lua_iscfunction(L, 1)) return 0;  /* cannot touch C upvalues from Lua */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n\nstatic const char KEY_HOOK = 'h';\n\n\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  lua_pushlightuserdata(L, L);\n  lua_rawget(L, -2);\n  if (lua_isfunction(L, -1)) {\n    lua_pushstring(L, hooknames[(int)ar->event]);\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);\n  }\n}\n\n\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic void gethooktable (lua_State *L) {\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    lua_createtable(L, 0, 1);\n    lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n    lua_pushvalue(L, -2);\n    lua_rawset(L, LUA_REGISTRYINDEX);\n  }\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = luaL_optint(L, arg+3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  gethooktable(L);\n  lua_pushlightuserdata(L, L1);\n  lua_pushvalue(L, arg+1);\n  lua_rawset(L, -3);  /* set new hook */\n  lua_pop(L, 1);  /* remove hook table */\n  lua_sethook(L1, func, mask, count);  /* set hooks */\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook != NULL && hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {\n    gethooktable(L);\n    lua_pushlightuserdata(L, L1);\n    lua_rawget(L, -2);   /* get hook */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));\n  lua_pushinteger(L, lua_gethookcount(L1));\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    fputs(\"lua_debug> \", stderr);\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0)) {\n      fputs(lua_tostring(L, -1), stderr);\n      fputs(\"\\n\", stderr);\n    }\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\n#define LEVELS1\t12\t/* size of the first part of the stack */\n#define LEVELS2\t10\t/* size of the second part of the stack */\n\nstatic int db_errorfb (lua_State *L) {\n  int level;\n  int firstpart = 1;  /* still before eventual `...' */\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  if (lua_isnumber(L, arg+2)) {\n    level = (int)lua_tointeger(L, arg+2);\n    lua_pop(L, 1);\n  }\n  else\n    level = (L == L1) ? 1 : 0;  /* level 0 may be this own function */\n  if (lua_gettop(L) == arg)\n    lua_pushliteral(L, \"\");\n  else if (!lua_isstring(L, arg+1)) return 1;  /* message is not a string */\n  else lua_pushliteral(L, \"\\n\");\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (level > LEVELS1 && firstpart) {\n      /* no more than `LEVELS2' more levels? */\n      if (!lua_getstack(L1, level+LEVELS2, &ar))\n        level--;  /* keep going */\n      else {\n        lua_pushliteral(L, \"\\n\\t...\");  /* too many levels */\n        while (lua_getstack(L1, level+LEVELS2, &ar))  /* find last levels */\n          level++;\n      }\n      firstpart = 0;\n      continue;\n    }\n    lua_pushliteral(L, \"\\n\\t\");\n    lua_getinfo(L1, \"Snl\", &ar);\n    lua_pushfstring(L, \"%s:\", ar.short_src);\n    if (ar.currentline > 0)\n      lua_pushfstring(L, \"%d:\", ar.currentline);\n    if (*ar.namewhat != '\\0')  /* is there a name? */\n        lua_pushfstring(L, \" in function \" LUA_QS, ar.name);\n    else {\n      if (*ar.what == 'm')  /* main? */\n        lua_pushfstring(L, \" in main chunk\");\n      else if (*ar.what == 'C' || *ar.what == 't')\n        lua_pushliteral(L, \" ?\");  /* C function or tail call */\n      else\n        lua_pushfstring(L, \" in function <%s:%d>\",\n                           ar.short_src, ar.linedefined);\n    }\n    lua_concat(L, lua_gettop(L) - arg);\n  }\n  lua_concat(L, lua_gettop(L) - arg);\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getfenv\", db_getfenv},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"setfenv\", db_setfenv},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_errorfb},\n  {NULL, NULL}\n};\n\n\nLUALIB_API int luaopen_debug (lua_State *L) {\n  luaL_register(L, LUA_DBLIBNAME, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);\n\n\nstatic int currentpc (lua_State *L, CallInfo *ci) {\n  if (!isLua(ci)) return -1;  /* function is not a Lua function? */\n  if (ci == L->ci)\n    ci->savedpc = L->savedpc;\n  return pcRel(ci->savedpc, ci_func(ci)->l.p);\n}\n\n\nstatic int currentline (lua_State *L, CallInfo *ci) {\n  int pc = currentpc(L, ci);\n  if (pc < 0)\n    return -1;  /* only active lua functions have current-line information */\n  else\n    return getline(ci_func(ci)->l.p, pc);\n}\n\n\n/*\n** this function can be called asynchronous (e.g. during a signal)\n*/\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n  return 1;\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {\n    level--;\n    if (f_isLua(ci))  /* Lua function? */\n      level -= ci->tailcalls;  /* skip lost tail calls */\n  }\n  if (level == 0 && ci > L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = cast_int(ci - L->base_ci);\n  }\n  else if (level < 0) {  /* level is of a lost tail call? */\n    status = 1;\n    ar->i_ci = 0;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic Proto *getluaproto (CallInfo *ci) {\n  return (isLua(ci) ? ci_func(ci)->l.p : NULL);\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n) {\n  const char *name;\n  Proto *fp = getluaproto(ci);\n  if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)\n    return name;  /* is a local variable in a Lua function */\n  else {\n    StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;\n    if (limit - ci->base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      return \"(*temporary)\";\n    else\n      return NULL;\n  }\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  CallInfo *ci = L->base_ci + ar->i_ci;\n  const char *name = findlocal(L, ci, n);\n  lua_lock(L);\n  if (name)\n      luaA_pushobject(L, ci->base + (n - 1));\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  CallInfo *ci = L->base_ci + ar->i_ci;\n  const char *name = findlocal(L, ci, n);\n  lua_lock(L);\n  if (name)\n      setobjs2s(L, ci->base + (n - 1), L->top - 1);\n  L->top--;  /* pop value */\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (cl->c.isC) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    ar->source = getstr(cl->l.p->source);\n    ar->linedefined = cl->l.p->linedefined;\n    ar->lastlinedefined = cl->l.p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void info_tailcall (lua_Debug *ar) {\n  ar->name = ar->namewhat = \"\";\n  ar->what = \"tail\";\n  ar->lastlinedefined = ar->linedefined = ar->currentline = -1;\n  ar->source = \"=(tail call)\";\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n  ar->nups = 0;\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (f == NULL || f->c.isC) {\n    setnilvalue(L->top);\n  }\n  else {\n    Table *t = luaH_new(L, 0, 0);\n    int *lineinfo = f->l.p->lineinfo;\n    int i;\n    for (i=0; i<f->l.p->sizelineinfo; i++)\n      setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);\n    sethvalue(L, L->top, t); \n  }\n  incr_top(L);\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                    Closure *f, CallInfo *ci) {\n  int status = 1;\n  if (f == NULL) {\n    info_tailcall(ar);\n    return status;\n  }\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci) ? currentline(L, ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = f->c.nupvalues;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *f = NULL;\n  CallInfo *ci = NULL;\n  lua_lock(L);\n  if (*what == '>') {\n    StkId func = L->top - 1;\n    luai_apicheck(L, ttisfunction(func));\n    what++;  /* skip the '>' */\n    f = clvalue(func);\n    L->top--;  /* pop function */\n  }\n  else if (ar->i_ci != 0) {  /* no tail call? */\n    ci = L->base_ci + ar->i_ci;\n    lua_assert(ttisfunction(ci->func));\n    f = clvalue(ci->func);\n  }\n  status = auxgetinfo(L, what, ar, f, ci);\n  if (strchr(what, 'f')) {\n    if (f == NULL) setnilvalue(L->top);\n    else setclvalue(L, L->top, f);\n    incr_top(L);\n  }\n  if (strchr(what, 'L'))\n    collectvalidlines(L, f);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution and code checker\n** =======================================================\n*/\n\n#define check(x)\t\tif (!(x)) return 0;\n\n#define checkjump(pt,pc)\tcheck(0 <= pc && pc < pt->sizecode)\n\n#define checkreg(pt,reg)\tcheck((reg) < (pt)->maxstacksize)\n\n\n\nstatic int precheck (const Proto *pt) {\n  check(pt->maxstacksize <= MAXSTACK);\n  check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);\n  check(!(pt->is_vararg & VARARG_NEEDSARG) ||\n              (pt->is_vararg & VARARG_HASARG));\n  check(pt->sizeupvalues <= pt->nups);\n  check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);\n  check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);\n  return 1;\n}\n\n\n#define checkopenop(pt,pc)\tluaG_checkopenop((pt)->code[(pc)+1])\n\nint luaG_checkopenop (Instruction i) {\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n    case OP_RETURN:\n    case OP_SETLIST: {\n      check(GETARG_B(i) == 0);\n      return 1;\n    }\n    default: return 0;  /* invalid instruction after an open call */\n  }\n}\n\n\nstatic int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) {\n  switch (mode) {\n    case OpArgN: check(r == 0); break;\n    case OpArgU: break;\n    case OpArgR: checkreg(pt, r); break;\n    case OpArgK:\n      check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize);\n      break;\n  }\n  return 1;\n}\n\n\nstatic Instruction symbexec (const Proto *pt, int lastpc, int reg) {\n  int pc;\n  int last;  /* stores position of last instruction that changed `reg' */\n  last = pt->sizecode-1;  /* points to final return (a `neutral' instruction) */\n  check(precheck(pt));\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = pt->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    int b = 0;\n    int c = 0;\n    check(op < NUM_OPCODES);\n    checkreg(pt, a);\n    switch (getOpMode(op)) {\n      case iABC: {\n        b = GETARG_B(i);\n        c = GETARG_C(i);\n        check(checkArgMode(pt, b, getBMode(op)));\n        check(checkArgMode(pt, c, getCMode(op)));\n        break;\n      }\n      case iABx: {\n        b = GETARG_Bx(i);\n        if (getBMode(op) == OpArgK) check(b < pt->sizek);\n        break;\n      }\n      case iAsBx: {\n        b = GETARG_sBx(i);\n        if (getBMode(op) == OpArgR) {\n          int dest = pc+1+b;\n          check(0 <= dest && dest < pt->sizecode);\n          if (dest > 0) {\n            int j;\n            /* check that it does not jump to a setlist count; this\n               is tricky, because the count from a previous setlist may\n               have the same value of an invalid setlist; so, we must\n               go all the way back to the first of them (if any) */\n            for (j = 0; j < dest; j++) {\n              Instruction d = pt->code[dest-1-j];\n              if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;\n            }\n            /* if 'j' is even, previous value is not a setlist (even if\n               it looks like one) */\n            check((j&1) == 0);\n          }\n        }\n        break;\n      }\n    }\n    if (testAMode(op)) {\n      if (a == reg) last = pc;  /* change register `a' */\n    }\n    if (testTMode(op)) {\n      check(pc+2 < pt->sizecode);  /* check skip */\n      check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);\n    }\n    switch (op) {\n      case OP_LOADBOOL: {\n        if (c == 1) {  /* does it jump? */\n          check(pc+2 < pt->sizecode);  /* check its jump */\n          check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||\n                GETARG_C(pt->code[pc+1]) != 0);\n        }\n        break;\n      }\n      case OP_LOADNIL: {\n        if (a <= reg && reg <= b)\n          last = pc;  /* set registers from `a' to `b' */\n        break;\n      }\n      case OP_GETUPVAL:\n      case OP_SETUPVAL: {\n        check(b < pt->nups);\n        break;\n      }\n      case OP_GETGLOBAL:\n      case OP_SETGLOBAL: {\n        check(ttisstring(&pt->k[b]));\n        break;\n      }\n      case OP_SELF: {\n        checkreg(pt, a+1);\n        if (reg == a+1) last = pc;\n        break;\n      }\n      case OP_CONCAT: {\n        check(b < c);  /* at least two operands */\n        break;\n      }\n      case OP_TFORLOOP: {\n        check(c >= 1);  /* at least one result (control variable) */\n        checkreg(pt, a+2+c);  /* space for results */\n        if (reg >= a+2) last = pc;  /* affect all regs above its base */\n        break;\n      }\n      case OP_FORLOOP:\n      case OP_FORPREP:\n        checkreg(pt, a+3);\n        /* go through */\n      case OP_JMP: {\n        int dest = pc+1+b;\n        /* not full check and jump is forward and do not skip `lastpc'? */\n        if (reg != NO_REG && pc < dest && dest <= lastpc)\n          pc += b;  /* do the jump */\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (b != 0) {\n          checkreg(pt, a+b-1);\n        }\n        c--;  /* c = num. returns */\n        if (c == LUA_MULTRET) {\n          check(checkopenop(pt, pc));\n        }\n        else if (c != 0)\n          checkreg(pt, a+c-1);\n        if (reg >= a) last = pc;  /* affect all registers above base */\n        break;\n      }\n      case OP_RETURN: {\n        b--;  /* b = num. returns */\n        if (b > 0) checkreg(pt, a+b-1);\n        break;\n      }\n      case OP_SETLIST: {\n        if (b > 0) checkreg(pt, a + b);\n        if (c == 0) {\n          pc++;\n          check(pc < pt->sizecode - 1);\n        }\n        break;\n      }\n      case OP_CLOSURE: {\n        int nup, j;\n        check(b < pt->sizep);\n        nup = pt->p[b]->nups;\n        check(pc + nup < pt->sizecode);\n        for (j = 1; j <= nup; j++) {\n          OpCode op1 = GET_OPCODE(pt->code[pc + j]);\n          check(op1 == OP_GETUPVAL || op1 == OP_MOVE);\n        }\n        if (reg != NO_REG)  /* tracing? */\n          pc += nup;  /* do not 'execute' these pseudo-instructions */\n        break;\n      }\n      case OP_VARARG: {\n        check((pt->is_vararg & VARARG_ISVARARG) &&\n             !(pt->is_vararg & VARARG_NEEDSARG));\n        b--;\n        if (b == LUA_MULTRET) check(checkopenop(pt, pc));\n        checkreg(pt, a+b-1);\n        break;\n      }\n      default: break;\n    }\n  }\n  return pt->code[last];\n}\n\n#undef check\n#undef checkjump\n#undef checkreg\n\n/* }====================================================== */\n\n\nint luaG_checkcode (const Proto *pt) {\n  return (symbexec(pt, pt->sizecode, NO_REG) != 0);\n}\n\n\nstatic const char *kname (Proto *p, int c) {\n  if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))\n    return svalue(&p->k[INDEXK(c)]);\n  else\n    return \"?\";\n}\n\n\nstatic const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,\n                               const char **name) {\n  if (isLua(ci)) {  /* a Lua function? */\n    Proto *p = ci_func(ci)->l.p;\n    int pc = currentpc(L, ci);\n    Instruction i;\n    *name = luaF_getlocalname(p, stackpos+1, pc);\n    if (*name)  /* is a local? */\n      return \"local\";\n    i = symbexec(p, pc, stackpos);  /* try symbolic execution */\n    lua_assert(pc != -1);\n    switch (GET_OPCODE(i)) {\n      case OP_GETGLOBAL: {\n        int g = GETARG_Bx(i);  /* global index */\n        lua_assert(ttisstring(&p->k[g]));\n        *name = svalue(&p->k[g]);\n        return \"global\";\n      }\n      case OP_MOVE: {\n        int a = GETARG_A(i);\n        int b = GETARG_B(i);  /* move from `b' to `a' */\n        if (b < a)\n          return getobjname(L, ci, b, name);  /* get name for `b' */\n        break;\n      }\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        *name = kname(p, k);\n        return \"field\";\n      }\n      case OP_GETUPVAL: {\n        int u = GETARG_B(i);  /* upvalue index */\n        *name = p->upvalues ? getstr(p->upvalues[u]) : \"?\";\n        return \"upvalue\";\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        *name = kname(p, k);\n        return \"method\";\n      }\n      default: break;\n    }\n  }\n  return NULL;  /* no useful name found */\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  Instruction i;\n  if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))\n    return NULL;  /* calling function is not Lua (or is unknown) */\n  ci--;  /* calling function */\n  i = ci_func(ci)->l.p->code[currentpc(L, ci)];\n  if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||\n      GET_OPCODE(i) == OP_TFORLOOP)\n    return getobjname(L, ci, GETARG_A(i), name);\n  else\n    return NULL;  /* no useful name can be found */\n}\n\n\n/* only ANSI way to check whether a pointer points to an array */\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  StkId p;\n  for (p = ci->base; p < ci->top; p++)\n    if (o == p) return 1;\n  return 0;\n}\n\n\nvoid luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *name = NULL;\n  const char *t = luaT_typenames[ttype(o)];\n  const char *kind = (isinstack(L->ci, o)) ?\n                         getobjname(L, L->ci, cast_int(o - L->base), &name) :\n                         NULL;\n  if (kind)\n    luaG_runerror(L, \"attempt to %s %s \" LUA_QS \" (a %s value)\",\n                op, kind, name, t);\n  else\n    luaG_runerror(L, \"attempt to %s a %s value\", op, t);\n}\n\n\nvoid luaG_concaterror (lua_State *L, StkId p1, StkId p2) {\n  if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;\n  lua_assert(!ttisstring(p1) && !ttisnumber(p1));\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nvoid luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {\n  TValue temp;\n  if (luaV_tonumber(p1, &temp) == NULL)\n    p2 = p1;  /* first operand is wrong */\n  luaG_typeerror(L, p2, \"perform arithmetic on\");\n}\n\n\nint luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_typenames[ttype(p1)];\n  const char *t2 = luaT_typenames[ttype(p2)];\n  if (t1[2] == t2[2])\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n  return 0;\n}\n\n\nstatic void addinfo (lua_State *L, const char *msg) {\n  CallInfo *ci = L->ci;\n  if (isLua(ci)) {  /* is Lua code? */\n    char buff[LUA_IDSIZE];  /* add file:line information */\n    int line = currentline(L, ci);\n    luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);\n    luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n  }\n}\n\n\nvoid luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    incr_top(L);\n    luaD_call(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nvoid luaG_runerror (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  addinfo(L, luaO_pushvfstring(L, fmt, argp));\n  va_end(argp);\n  luaG_errormsg(L);\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getline(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : 0)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,\n                                             const char *opname);\nLUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);\nLUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,\n                                              const TValue *p2);\nLUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,\n                                             const TValue *p2);\nLUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaG_errormsg (lua_State *L);\nLUAI_FUNC int luaG_checkcode (const Proto *pt);\nLUAI_FUNC int luaG_checkopenop (Instruction i);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.38.1.4 2012/01/18 02:27:10 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nvoid luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    case LUA_ERRSYNTAX:\n    case LUA_ERRRUN: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nstatic void restore_stack_limit (lua_State *L) {\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);\n  if (L->size_ci > LUAI_MAXCALLS) {  /* there was an overflow? */\n    int inuse = cast_int(L->ci - L->base_ci);\n    if (inuse + 1 < LUAI_MAXCALLS)  /* can `undo' overflow? */\n      luaD_reallocCI(L, LUAI_MAXCALLS);\n  }\n}\n\n\nstatic void resetstack (lua_State *L, int status) {\n  L->ci = L->base_ci;\n  L->base = L->ci->base;\n  luaF_close(L, L->base);  /* close eventual pending closures */\n  luaD_seterrorobj(L, status, L->base);\n  L->nCcalls = L->baseCcalls;\n  L->allowhook = 1;\n  restore_stack_limit(L);\n  L->errfunc = 0;\n  L->errorJmp = NULL;\n}\n\n\nvoid luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {\n    L->errorJmp->status = errcode;\n    LUAI_THROW(L, L->errorJmp);\n  }\n  else {\n    L->status = cast_byte(errcode);\n    if (G(L)->panic) {\n      resetstack(L, errcode);\n      lua_unlock(L);\n      G(L)->panic(L);\n    }\n    exit(EXIT_FAILURE);\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  struct lua_longjmp lj;\n  lj.status = 0;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  GCObject *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->gch.next)\n    gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;\n  for (ci = L->base_ci; ci <= L->ci; ci++) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->base = (ci->base - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n  }\n  L->base = (L->base - oldstack) + L->stack;\n}\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int realsize = newsize + 1 + EXTRA_STACK;\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);\n  luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);\n  L->stacksize = realsize;\n  L->stack_last = L->stack+newsize;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_reallocCI (lua_State *L, int newsize) {\n  CallInfo *oldci = L->base_ci;\n  luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);\n  L->size_ci = newsize;\n  L->ci = (L->ci - oldci) + L->base_ci;\n  L->end_ci = L->base_ci + L->size_ci - 1;\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  if (n <= L->stacksize)  /* double size is enough? */\n    luaD_reallocstack(L, 2*L->stacksize);\n  else\n    luaD_reallocstack(L, L->stacksize + n);\n}\n\n\nstatic CallInfo *growCI (lua_State *L) {\n  if (L->size_ci > LUAI_MAXCALLS)  /* overflow while handling overflow? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    luaD_reallocCI(L, 2*L->size_ci);\n    if (L->size_ci > LUAI_MAXCALLS)\n      luaG_runerror(L, \"stack overflow\");\n  }\n  return ++L->ci;\n}\n\n\nvoid luaD_callhook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, L->ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    if (event == LUA_HOOKTAILRET)\n      ar.i_ci = 0;  /* tail call; no debug information about it */\n    else\n      ar.i_ci = cast_int(L->ci - L->base_ci);\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    L->ci->top = L->top + LUA_MINSTACK;\n    lua_assert(L->ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    L->ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n  }\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n  Table *htab = NULL;\n  StkId base, fixed;\n  for (; actual < nfixargs; ++actual)\n    setnilvalue(L->top++);\n#if defined(LUA_COMPAT_VARARG)\n  if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */\n    int nvar = actual - nfixargs;  /* number of extra arguments */\n    lua_assert(p->is_vararg & VARARG_HASARG);\n    luaC_checkGC(L);\n    luaD_checkstack(L, p->maxstacksize);\n    htab = luaH_new(L, nvar, 1);  /* create `arg' table */\n    for (i=0; i<nvar; i++)  /* put extra arguments into `arg' table */\n      setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i);\n    /* store counter in field `n' */\n    setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, \"n\")), cast_num(nvar));\n  }\n#endif\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i=0; i<nfixargs; i++) {\n    setobjs2s(L, L->top++, fixed+i);\n    setnilvalue(fixed+i);\n  }\n  /* add `arg' parameter */\n  if (htab) {\n    sethvalue(L, L->top++, htab);\n    lua_assert(iswhite(obj2gco(htab)));\n  }\n  return base;\n}\n\n\nstatic StkId tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  ptrdiff_t funcr = savestack(L, func);\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at `func' */\n  for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);\n  incr_top(L);\n  func = restorestack(L, funcr);  /* previous call may change stack */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n  return func;\n}\n\n\n\n#define inc_ci(L) \\\n  ((L->ci == L->end_ci) ? growCI(L) : \\\n   (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))\n\n\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  LClosure *cl;\n  ptrdiff_t funcr;\n  if (!ttisfunction(func)) /* `func' is not a function? */\n    func = tryfuncTM(L, func);  /* check the `function' tag method */\n  funcr = savestack(L, func);\n  cl = &clvalue(func)->l;\n  L->ci->savedpc = L->savedpc;\n  if (!cl->isC) {  /* Lua function? prepare its call */\n    CallInfo *ci;\n    StkId st, base;\n    Proto *p = cl->p;\n    luaD_checkstack(L, p->maxstacksize);\n    func = restorestack(L, funcr);\n    if (!p->is_vararg) {  /* no varargs? */\n      base = func + 1;\n      if (L->top > base + p->numparams)\n        L->top = base + p->numparams;\n    }\n    else {  /* vararg function */\n      int nargs = cast_int(L->top - func) - 1;\n      base = adjust_varargs(L, p, nargs);\n      func = restorestack(L, funcr);  /* previous call may change the stack */\n    }\n    ci = inc_ci(L);  /* now `enter' new function */\n    ci->func = func;\n    L->base = ci->base = base;\n    ci->top = L->base + p->maxstacksize;\n    lua_assert(ci->top <= L->stack_last);\n    L->savedpc = p->code;  /* starting point */\n    ci->tailcalls = 0;\n    ci->nresults = nresults;\n    for (st = L->top; st < ci->top; st++)\n      setnilvalue(st);\n    L->top = ci->top;\n    if (L->hookmask & LUA_MASKCALL) {\n      L->savedpc++;  /* hooks assume 'pc' is already incremented */\n      luaD_callhook(L, LUA_HOOKCALL, -1);\n      L->savedpc--;  /* correct 'pc' */\n    }\n    return PCRLUA;\n  }\n  else {  /* if is a C function, call it */\n    CallInfo *ci;\n    int n;\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    ci = inc_ci(L);  /* now `enter' new function */\n    ci->func = restorestack(L, funcr);\n    L->base = ci->base = ci->func + 1;\n    ci->top = L->top + LUA_MINSTACK;\n    lua_assert(ci->top <= L->stack_last);\n    ci->nresults = nresults;\n    if (L->hookmask & LUA_MASKCALL)\n      luaD_callhook(L, LUA_HOOKCALL, -1);\n    lua_unlock(L);\n    n = (*curr_func(L)->c.f)(L);  /* do the actual call */\n    lua_lock(L);\n    if (n < 0)  /* yielding? */\n      return PCRYIELD;\n    else {\n      luaD_poscall(L, L->top - n);\n      return PCRC;\n    }\n  }\n}\n\n\nstatic StkId callrethooks (lua_State *L, StkId firstResult) {\n  ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */\n  luaD_callhook(L, LUA_HOOKRET, -1);\n  if (f_isLua(L->ci)) {  /* Lua function? */\n    while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */\n      luaD_callhook(L, LUA_HOOKTAILRET, -1);\n  }\n  return restorestack(L, fr);\n}\n\n\nint luaD_poscall (lua_State *L, StkId firstResult) {\n  StkId res;\n  int wanted, i;\n  CallInfo *ci;\n  if (L->hookmask & LUA_MASKRET)\n    firstResult = callrethooks(L, firstResult);\n  ci = L->ci--;\n  res = ci->func;  /* res == final position of 1st result */\n  wanted = ci->nresults;\n  L->base = (ci - 1)->base;  /* restore base */\n  L->savedpc = (ci - 1)->savedpc;  /* restore savedpc */\n  /* move results to correct place */\n  for (i = wanted; i != 0 && firstResult < L->top; i--)\n    setobjs2s(L, res++, firstResult++);\n  while (i-- > 0)\n    setnilvalue(res++);\n  L->top = res;\n  return (wanted - LUA_MULTRET);  /* 0 iff wanted == LUA_MULTRET */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/ \nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS) {\n    if (L->nCcalls == LUAI_MAXCCALLS)\n      luaG_runerror(L, \"C stack overflow\");\n    else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n      luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n  }\n  if (luaD_precall(L, func, nResults) == PCRLUA)  /* is a Lua function? */\n    luaV_execute(L, 1);  /* call it */\n  L->nCcalls--;\n  luaC_checkGC(L);\n}\n\n\nstatic void resume (lua_State *L, void *ud) {\n  StkId firstArg = cast(StkId, ud);\n  CallInfo *ci = L->ci;\n  if (L->status == 0) {  /* start coroutine? */\n    lua_assert(ci == L->base_ci && firstArg > L->base);\n    if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)\n      return;\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = 0;\n    if (!f_isLua(ci)) {  /* `common' yield? */\n      /* finish interrupted execution of `OP_CALL' */\n      lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||\n                 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);\n      if (luaD_poscall(L, firstArg))  /* complete it... */\n        L->top = L->ci->top;  /* and correct top if not multiple results */\n    }\n    else  /* yielded inside a hook: just continue its execution */\n      L->base = L->ci->base;\n  }\n  luaV_execute(L, cast_int(L->ci - L->base_ci));\n}\n\n\nstatic int resume_error (lua_State *L, const char *msg) {\n  L->top = L->ci->base;\n  setsvalue2s(L, L->top, luaS_new(L, msg));\n  incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\nLUA_API int lua_resume (lua_State *L, int nargs) {\n  int status;\n  lua_lock(L);\n  if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))\n      return resume_error(L, \"cannot resume non-suspended coroutine\");\n  if (L->nCcalls >= LUAI_MAXCCALLS)\n    return resume_error(L, \"C stack overflow\");\n  luai_userstateresume(L, nargs);\n  lua_assert(L->errfunc == 0);\n  L->baseCcalls = ++L->nCcalls;\n  status = luaD_rawrunprotected(L, resume, L->top - nargs);\n  if (status != 0) {  /* error? */\n    L->status = cast_byte(status);  /* mark thread as `dead' */\n    luaD_seterrorobj(L, status, L->top);\n    L->ci->top = L->top;\n  }\n  else {\n    lua_assert(L->nCcalls == L->baseCcalls);\n    status = L->status;\n  }\n  --L->nCcalls;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_yield (lua_State *L, int nresults) {\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  if (L->nCcalls > L->baseCcalls)\n    luaG_runerror(L, \"attempt to yield across metamethod/C-call boundary\");\n  L->base = L->top - nresults;  /* protect stack slots below */\n  L->status = LUA_YIELD;\n  lua_unlock(L);\n  return -1;\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  unsigned short oldnCcalls = L->nCcalls;\n  ptrdiff_t old_ci = saveci(L, L->ci);\n  lu_byte old_allowhooks = L->allowhook;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != 0) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close eventual pending closures */\n    luaD_seterrorobj(L, status, oldtop);\n    L->nCcalls = oldnCcalls;\n    L->ci = restoreci(L, old_ci);\n    L->base = L->ci->base;\n    L->savedpc = L->ci->savedpc;\n    L->allowhook = old_allowhooks;\n    restore_stack_limit(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to `f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* buffer to be used by the scanner */\n  const char *name;\n};\n\nstatic void f_parser (lua_State *L, void *ud) {\n  int i;\n  Proto *tf;\n  Closure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = luaZ_lookahead(p->z);\n  luaC_checkGC(L);\n  tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,\n                                                             &p->buff, p->name);\n  cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));\n  cl->l.p = tf;\n  for (i = 0; i < tf->nups; i++)  /* initialize eventual upvalues */\n    cl->l.upvals[i] = luaF_newupval(L);\n  setclvalue(L, L->top, cl);\n  incr_top(L);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {\n  struct SParser p;\n  int status;\n  p.z = z; p.name = name;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  return status;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n#define luaD_checkstack(L,n)\t\\\n  if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \\\n    luaD_growstack(L, n); \\\n  else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));\n\n\n#define incr_top(L) {luaD_checkstack(L,1); L->top++;}\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n#define saveci(L,p)\t\t((char *)(p) - (char *)L->base_ci)\n#define restoreci(L,n)\t\t((CallInfo *)((char *)L->base_ci + (n)))\n\n\n/* results from luaD_precall */\n#define PCRLUA\t\t0\t/* initiated a call to a Lua function */\n#define PCRC\t\t1\t/* did a call to a C function */\n#define PCRYIELD\t2\t/* C funtion yielded */\n\n\n/* type of protected functions, to be ran by `runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);\nLUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);\nLUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\n\nLUAI_FUNC void luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\nLUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#include <stddef.h>\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\ntypedef struct {\n lua_State* L;\n lua_Writer writer;\n void* data;\n int strip;\n int status;\n} DumpState;\n\n#define DumpMem(b,n,size,D)\tDumpBlock(b,(n)*(size),D)\n#define DumpVar(x,D)\t \tDumpMem(&x,1,sizeof(x),D)\n\nstatic void DumpBlock(const void* b, size_t size, DumpState* D)\n{\n if (D->status==0)\n {\n  lua_unlock(D->L);\n  D->status=(*D->writer)(D->L,b,size,D->data);\n  lua_lock(D->L);\n }\n}\n\nstatic void DumpChar(int y, DumpState* D)\n{\n char x=(char)y;\n DumpVar(x,D);\n}\n\nstatic void DumpInt(int x, DumpState* D)\n{\n DumpVar(x,D);\n}\n\nstatic void DumpNumber(lua_Number x, DumpState* D)\n{\n DumpVar(x,D);\n}\n\nstatic void DumpVector(const void* b, int n, size_t size, DumpState* D)\n{\n DumpInt(n,D);\n DumpMem(b,n,size,D);\n}\n\nstatic void DumpString(const TString* s, DumpState* D)\n{\n if (s==NULL || getstr(s)==NULL)\n {\n  size_t size=0;\n  DumpVar(size,D);\n }\n else\n {\n  size_t size=s->tsv.len+1;\t\t/* include trailing '\\0' */\n  DumpVar(size,D);\n  DumpBlock(getstr(s),size,D);\n }\n}\n\n#define DumpCode(f,D)\t DumpVector(f->code,f->sizecode,sizeof(Instruction),D)\n\nstatic void DumpFunction(const Proto* f, const TString* p, DumpState* D);\n\nstatic void DumpConstants(const Proto* f, DumpState* D)\n{\n int i,n=f->sizek;\n DumpInt(n,D);\n for (i=0; i<n; i++)\n {\n  const TValue* o=&f->k[i];\n  DumpChar(ttype(o),D);\n  switch (ttype(o))\n  {\n   case LUA_TNIL:\n\tbreak;\n   case LUA_TBOOLEAN:\n\tDumpChar(bvalue(o),D);\n\tbreak;\n   case LUA_TNUMBER:\n\tDumpNumber(nvalue(o),D);\n\tbreak;\n   case LUA_TSTRING:\n\tDumpString(rawtsvalue(o),D);\n\tbreak;\n   default:\n\tlua_assert(0);\t\t\t/* cannot happen */\n\tbreak;\n  }\n }\n n=f->sizep;\n DumpInt(n,D);\n for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);\n}\n\nstatic void DumpDebug(const Proto* f, DumpState* D)\n{\n int i,n;\n n= (D->strip) ? 0 : f->sizelineinfo;\n DumpVector(f->lineinfo,n,sizeof(int),D);\n n= (D->strip) ? 0 : f->sizelocvars;\n DumpInt(n,D);\n for (i=0; i<n; i++)\n {\n  DumpString(f->locvars[i].varname,D);\n  DumpInt(f->locvars[i].startpc,D);\n  DumpInt(f->locvars[i].endpc,D);\n }\n n= (D->strip) ? 0 : f->sizeupvalues;\n DumpInt(n,D);\n for (i=0; i<n; i++) DumpString(f->upvalues[i],D);\n}\n\nstatic void DumpFunction(const Proto* f, const TString* p, DumpState* D)\n{\n DumpString((f->source==p || D->strip) ? NULL : f->source,D);\n DumpInt(f->linedefined,D);\n DumpInt(f->lastlinedefined,D);\n DumpChar(f->nups,D);\n DumpChar(f->numparams,D);\n DumpChar(f->is_vararg,D);\n DumpChar(f->maxstacksize,D);\n DumpCode(f,D);\n DumpConstants(f,D);\n DumpDebug(f,D);\n}\n\nstatic void DumpHeader(DumpState* D)\n{\n char h[LUAC_HEADERSIZE];\n luaU_header(h);\n DumpBlock(h,LUAC_HEADERSIZE,D);\n}\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)\n{\n DumpState D;\n D.L=L;\n D.writer=w;\n D.data=data;\n D.strip=strip;\n D.status=0;\n DumpHeader(&D);\n DumpFunction(f,NULL,&D);\n return D.status;\n}\n"
  },
  {
    "path": "build/lua-5.1.5/src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nClosure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {\n  Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));\n  luaC_link(L, obj2gco(c), LUA_TFUNCTION);\n  c->c.isC = 1;\n  c->c.env = e;\n  c->c.nupvalues = cast_byte(nelems);\n  return c;\n}\n\n\nClosure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {\n  Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));\n  luaC_link(L, obj2gco(c), LUA_TFUNCTION);\n  c->l.isC = 0;\n  c->l.env = e;\n  c->l.nupvalues = cast_byte(nelems);\n  while (nelems--) c->l.upvals[nelems] = NULL;\n  return c;\n}\n\n\nUpVal *luaF_newupval (lua_State *L) {\n  UpVal *uv = luaM_new(L, UpVal);\n  luaC_link(L, obj2gco(uv), LUA_TUPVAL);\n  uv->v = &uv->u.value;\n  setnilvalue(uv->v);\n  return uv;\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  global_State *g = G(L);\n  GCObject **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {\n    lua_assert(p->v != &p->u.value);\n    if (p->v == level) {  /* found a corresponding upvalue? */\n      if (isdead(g, obj2gco(p)))  /* is it dead? */\n        changewhite(obj2gco(p));  /* ressurect it */\n      return p;\n    }\n    pp = &p->next;\n  }\n  uv = luaM_new(L, UpVal);  /* not found: create a new one */\n  uv->tt = LUA_TUPVAL;\n  uv->marked = luaC_white(g);\n  uv->v = level;  /* current value lives in the stack */\n  uv->next = *pp;  /* chain it in the proper position */\n  *pp = obj2gco(uv);\n  uv->u.l.prev = &g->uvhead;  /* double link it in `uvhead' list */\n  uv->u.l.next = g->uvhead.u.l.next;\n  uv->u.l.next->u.l.prev = uv;\n  g->uvhead.u.l.next = uv;\n  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n  return uv;\n}\n\n\nstatic void unlinkupval (UpVal *uv) {\n  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n  uv->u.l.next->u.l.prev = uv->u.l.prev;  /* remove from `uvhead' list */\n  uv->u.l.prev->u.l.next = uv->u.l.next;\n}\n\n\nvoid luaF_freeupval (lua_State *L, UpVal *uv) {\n  if (uv->v != &uv->u.value)  /* is it open? */\n    unlinkupval(uv);  /* remove from open list */\n  luaM_free(L, uv);  /* free upvalue */\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  global_State *g = G(L);\n  while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {\n    GCObject *o = obj2gco(uv);\n    lua_assert(!isblack(o) && uv->v != &uv->u.value);\n    L->openupval = uv->next;  /* remove from `open' list */\n    if (isdead(g, o))\n      luaF_freeupval(L, uv);  /* free upvalue */\n    else {\n      unlinkupval(uv);\n      setobj(L, &uv->u.value, uv->v);\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_linkupval(L, uv);  /* link upvalue into `gcroot' list */\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  Proto *f = luaM_new(L, Proto);\n  luaC_link(L, obj2gco(f), LUA_TPROTO);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->sizecode = 0;\n  f->sizelineinfo = 0;\n  f->sizeupvalues = 0;\n  f->nups = 0;\n  f->upvalues = NULL;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->lineinfo = NULL;\n  f->sizelocvars = 0;\n  f->locvars = NULL;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode, Instruction);\n  luaM_freearray(L, f->p, f->sizep, Proto *);\n  luaM_freearray(L, f->k, f->sizek, TValue);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);\n  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);\n  luaM_free(L, f);\n}\n\n\nvoid luaF_freeclosure (lua_State *L, Closure *c) {\n  int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :\n                          sizeLclosure(c->l.nupvalues);\n  luaM_freemem(L, c, size);\n}\n\n\n/*\n** Look for n-th local variable at line `line' in function `func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);\nLUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);\nLUAI_FUNC UpVal *luaF_newupval (lua_State *L);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);\nLUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.38.1.2 2011/03/18 18:05:38 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#include <string.h>\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#define GCSTEPSIZE\t1024u\n#define GCSWEEPMAX\t40\n#define GCSWEEPCOST\t10\n#define GCFINALIZECOST\t100\n\n\n#define maskmarks\tcast_byte(~(bitmask(BLACKBIT)|WHITEBITS))\n\n#define makewhite(g,x)\t\\\n   ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))\n\n#define white2gray(x)\treset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)\n#define black2gray(x)\tresetbit((x)->gch.marked, BLACKBIT)\n\n#define stringmark(s)\treset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)\n\n\n#define isfinalized(u)\t\ttestbit((u)->marked, FINALIZEDBIT)\n#define markfinalized(u)\tl_setbit((u)->marked, FINALIZEDBIT)\n\n\n#define KEYWEAK         bitmask(KEYWEAKBIT)\n#define VALUEWEAK       bitmask(VALUEWEAKBIT)\n\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t) { if (iswhite(obj2gco(t))) \\\n\t\treallymarkobject(g, obj2gco(t)); }\n\n\n#define setthreshold(g)  (g->GCthreshold = (g->estimate/100) * g->gcpause)\n\n\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (iscollectable(gkey(n)))\n    setttype(gkey(n), LUA_TDEADKEY);  /* dead key; remove it */\n}\n\n\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n  lua_assert(iswhite(o) && !isdead(g, o));\n  white2gray(o);\n  switch (o->gch.tt) {\n    case LUA_TSTRING: {\n      return;\n    }\n    case LUA_TUSERDATA: {\n      Table *mt = gco2u(o)->metatable;\n      gray2black(o);  /* udata are never gray */\n      if (mt) markobject(g, mt);\n      markobject(g, gco2u(o)->env);\n      return;\n    }\n    case LUA_TUPVAL: {\n      UpVal *uv = gco2uv(o);\n      markvalue(g, uv->v);\n      if (uv->v == &uv->u.value)  /* closed? */\n        gray2black(o);  /* open upvalues are never black */\n      return;\n    }\n    case LUA_TFUNCTION: {\n      gco2cl(o)->c.gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TTABLE: {\n      gco2h(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TTHREAD: {\n      gco2th(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TPROTO: {\n      gco2p(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\nstatic void marktmu (global_State *g) {\n  GCObject *u = g->tmudata;\n  if (u) {\n    do {\n      u = u->gch.next;\n      makewhite(g, u);  /* may be marked, if left from previous GC */\n      reallymarkobject(g, u);\n    } while (u != g->tmudata);\n  }\n}\n\n\n/* move `dead' udata that need finalization to list `tmudata' */\nsize_t luaC_separateudata (lua_State *L, int all) {\n  global_State *g = G(L);\n  size_t deadmem = 0;\n  GCObject **p = &g->mainthread->next;\n  GCObject *curr;\n  while ((curr = *p) != NULL) {\n    if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))\n      p = &curr->gch.next;  /* don't bother with them */\n    else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {\n      markfinalized(gco2u(curr));  /* don't need finalization */\n      p = &curr->gch.next;\n    }\n    else {  /* must call its gc method */\n      deadmem += sizeudata(gco2u(curr));\n      markfinalized(gco2u(curr));\n      *p = curr->gch.next;\n      /* link `curr' at the end of `tmudata' list */\n      if (g->tmudata == NULL)  /* list is empty? */\n        g->tmudata = curr->gch.next = curr;  /* creates a circular list */\n      else {\n        curr->gch.next = g->tmudata->gch.next;\n        g->tmudata->gch.next = curr;\n        g->tmudata = curr;\n      }\n    }\n  }\n  return deadmem;\n}\n\n\nstatic int traversetable (global_State *g, Table *h) {\n  int i;\n  int weakkey = 0;\n  int weakvalue = 0;\n  const TValue *mode;\n  if (h->metatable)\n    markobject(g, h->metatable);\n  mode = gfasttm(g, h->metatable, TM_MODE);\n  if (mode && ttisstring(mode)) {  /* is there a weak mode? */\n    weakkey = (strchr(svalue(mode), 'k') != NULL);\n    weakvalue = (strchr(svalue(mode), 'v') != NULL);\n    if (weakkey || weakvalue) {  /* is really weak? */\n      h->marked &= ~(KEYWEAK | VALUEWEAK);  /* clear bits */\n      h->marked |= cast_byte((weakkey << KEYWEAKBIT) |\n                             (weakvalue << VALUEWEAKBIT));\n      h->gclist = g->weak;  /* must be cleared after GC, ... */\n      g->weak = obj2gco(h);  /* ... so put in the appropriate list */\n    }\n  }\n  if (weakkey && weakvalue) return 1;\n  if (!weakvalue) {\n    i = h->sizearray;\n    while (i--)\n      markvalue(g, &h->array[i]);\n  }\n  i = sizenode(h);\n  while (i--) {\n    Node *n = gnode(h, i);\n    lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));\n    if (ttisnil(gval(n)))\n      removeentry(n);  /* remove empty entries */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      if (!weakkey) markvalue(g, gkey(n));\n      if (!weakvalue) markvalue(g, gval(n));\n    }\n  }\n  return weakkey || weakvalue;\n}\n\n\n/*\n** All marks are conditional because a GC may happen while the\n** prototype is still being created\n*/\nstatic void traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->source) stringmark(f->source);\n  for (i=0; i<f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i=0; i<f->sizeupvalues; i++) {  /* mark upvalue names */\n    if (f->upvalues[i])\n      stringmark(f->upvalues[i]);\n  }\n  for (i=0; i<f->sizep; i++) {  /* mark nested protos */\n    if (f->p[i])\n      markobject(g, f->p[i]);\n  }\n  for (i=0; i<f->sizelocvars; i++) {  /* mark local-variable names */\n    if (f->locvars[i].varname)\n      stringmark(f->locvars[i].varname);\n  }\n}\n\n\n\nstatic void traverseclosure (global_State *g, Closure *cl) {\n  markobject(g, cl->c.env);\n  if (cl->c.isC) {\n    int i;\n    for (i=0; i<cl->c.nupvalues; i++)  /* mark its upvalues */\n      markvalue(g, &cl->c.upvalue[i]);\n  }\n  else {\n    int i;\n    lua_assert(cl->l.nupvalues == cl->l.p->nups);\n    markobject(g, cl->l.p);\n    for (i=0; i<cl->l.nupvalues; i++)  /* mark its upvalues */\n      markobject(g, cl->l.upvals[i]);\n  }\n}\n\n\nstatic void checkstacksizes (lua_State *L, StkId max) {\n  int ci_used = cast_int(L->ci - L->base_ci);  /* number of `ci' in use */\n  int s_used = cast_int(max - L->stack);  /* part of stack in use */\n  if (L->size_ci > LUAI_MAXCALLS)  /* handling overflow? */\n    return;  /* do not touch the stacks */\n  if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)\n    luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */\n  condhardstacktests(luaD_reallocCI(L, ci_used + 1));\n  if (4*s_used < L->stacksize &&\n      2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)\n    luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */\n  condhardstacktests(luaD_reallocstack(L, s_used));\n}\n\n\nstatic void traversestack (global_State *g, lua_State *l) {\n  StkId o, lim;\n  CallInfo *ci;\n  markvalue(g, gt(l));\n  lim = l->top;\n  for (ci = l->base_ci; ci <= l->ci; ci++) {\n    lua_assert(ci->top <= l->stack_last);\n    if (lim < ci->top) lim = ci->top;\n  }\n  for (o = l->stack; o < l->top; o++)\n    markvalue(g, o);\n  for (; o <= lim; o++)\n    setnilvalue(o);\n  checkstacksizes(l, lim);\n}\n\n\n/*\n** traverse one gray object, turning it to black.\n** Returns `quantity' traversed.\n*/\nstatic l_mem propagatemark (global_State *g) {\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->gch.tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2h(o);\n      g->gray = h->gclist;\n      if (traversetable(g, h))  /* table is weak? */\n        black2gray(o);  /* keep it gray */\n      return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                             sizeof(Node) * sizenode(h);\n    }\n    case LUA_TFUNCTION: {\n      Closure *cl = gco2cl(o);\n      g->gray = cl->c.gclist;\n      traverseclosure(g, cl);\n      return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :\n                           sizeLclosure(cl->l.nupvalues);\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;\n      th->gclist = g->grayagain;\n      g->grayagain = o;\n      black2gray(o);\n      traversestack(g, th);\n      return sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n                                 sizeof(CallInfo) * th->size_ci;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;\n      traverseproto(g, p);\n      return sizeof(Proto) + sizeof(Instruction) * p->sizecode +\n                             sizeof(Proto *) * p->sizep +\n                             sizeof(TValue) * p->sizek + \n                             sizeof(int) * p->sizelineinfo +\n                             sizeof(LocVar) * p->sizelocvars +\n                             sizeof(TString *) * p->sizeupvalues;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic size_t propagateall (global_State *g) {\n  size_t m = 0;\n  while (g->gray) m += propagatemark(g);\n  return m;\n}\n\n\n/*\n** The next function tells whether a key or value can be cleared from\n** a weak table. Non-collectable objects are never removed from weak\n** tables. Strings behave as `values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for userdata\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (const TValue *o, int iskey) {\n  if (!iscollectable(o)) return 0;\n  if (ttisstring(o)) {\n    stringmark(rawtsvalue(o));  /* strings are `values', so are never weak */\n    return 0;\n  }\n  return iswhite(gcvalue(o)) ||\n    (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));\n}\n\n\n/*\n** clear collected entries from weaktables\n*/\nstatic void cleartable (GCObject *l) {\n  while (l) {\n    Table *h = gco2h(l);\n    int i = h->sizearray;\n    lua_assert(testbit(h->marked, VALUEWEAKBIT) ||\n               testbit(h->marked, KEYWEAKBIT));\n    if (testbit(h->marked, VALUEWEAKBIT)) {\n      while (i--) {\n        TValue *o = &h->array[i];\n        if (iscleared(o, 0))  /* value was collected? */\n          setnilvalue(o);  /* remove value */\n      }\n    }\n    i = sizenode(h);\n    while (i--) {\n      Node *n = gnode(h, i);\n      if (!ttisnil(gval(n)) &&  /* non-empty entry? */\n          (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* remove entry from table */\n      }\n    }\n    l = h->gclist;\n  }\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->gch.tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;\n    case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;\n    case LUA_TTABLE: luaH_free(L, gco2h(o)); break;\n    case LUA_TTHREAD: {\n      lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);\n      luaE_freethread(L, gco2th(o));\n      break;\n    }\n    case LUA_TSTRING: {\n      G(L)->strt.nuse--;\n      luaM_freemem(L, o, sizestring(gco2ts(o)));\n      break;\n    }\n    case LUA_TUSERDATA: {\n      luaM_freemem(L, o, sizeudata(gco2u(o)));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\n\n\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  GCObject *curr;\n  global_State *g = G(L);\n  int deadmask = otherwhite(g);\n  while ((curr = *p) != NULL && count-- > 0) {\n    if (curr->gch.tt == LUA_TTHREAD)  /* sweep open upvalues of each thread */\n      sweepwholelist(L, &gco2th(curr)->openupval);\n    if ((curr->gch.marked ^ WHITEBITS) & deadmask) {  /* not dead? */\n      lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT));\n      makewhite(g, curr);  /* make it white (for next cycle) */\n      p = &curr->gch.next;\n    }\n    else {  /* must erase `curr' */\n      lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT));\n      *p = curr->gch.next;\n      if (curr == g->rootgc)  /* is the first element of the list? */\n        g->rootgc = curr->gch.next;  /* adjust first */\n      freeobj(L, curr);\n    }\n  }\n  return p;\n}\n\n\nstatic void checkSizes (lua_State *L) {\n  global_State *g = G(L);\n  /* check size of string hash */\n  if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&\n      g->strt.size > MINSTRTABSIZE*2)\n    luaS_resize(L, g->strt.size/2);  /* table is too big */\n  /* check size of buffer */\n  if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) {  /* buffer too big? */\n    size_t newsize = luaZ_sizebuffer(&g->buff) / 2;\n    luaZ_resizebuffer(L, &g->buff, newsize);\n  }\n}\n\n\nstatic void GCTM (lua_State *L) {\n  global_State *g = G(L);\n  GCObject *o = g->tmudata->gch.next;  /* get first element */\n  Udata *udata = rawgco2u(o);\n  const TValue *tm;\n  /* remove udata from `tmudata' */\n  if (o == g->tmudata)  /* last element? */\n    g->tmudata = NULL;\n  else\n    g->tmudata->gch.next = udata->uv.next;\n  udata->uv.next = g->mainthread->next;  /* return it to `root' list */\n  g->mainthread->next = o;\n  makewhite(g, o);\n  tm = fasttm(L, udata->uv.metatable, TM_GC);\n  if (tm != NULL) {\n    lu_byte oldah = L->allowhook;\n    lu_mem oldt = g->GCthreshold;\n    L->allowhook = 0;  /* stop debug hooks during GC tag method */\n    g->GCthreshold = 2*g->totalbytes;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);\n    setuvalue(L, L->top+1, udata);\n    L->top += 2;\n    luaD_call(L, L->top - 2, 0);\n    L->allowhook = oldah;  /* restore hooks */\n    g->GCthreshold = oldt;  /* restore threshold */\n  }\n}\n\n\n/*\n** Call all GC tag methods\n*/\nvoid luaC_callGCTM (lua_State *L) {\n  while (G(L)->tmudata)\n    GCTM(L);\n}\n\n\nvoid luaC_freeall (lua_State *L) {\n  global_State *g = G(L);\n  int i;\n  g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT);  /* mask to collect all elements */\n  sweepwholelist(L, &g->rootgc);\n  for (i = 0; i < g->strt.size; i++)  /* free all string lists */\n    sweepwholelist(L, &g->strt.hash[i]);\n}\n\n\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i<NUM_TAGS; i++)\n    if (g->mt[i]) markobject(g, g->mt[i]);\n}\n\n\n/* mark root set */\nstatic void markroot (lua_State *L) {\n  global_State *g = G(L);\n  g->gray = NULL;\n  g->grayagain = NULL;\n  g->weak = NULL;\n  markobject(g, g->mainthread);\n  /* make global table be traversed before main stack */\n  markvalue(g, gt(g->mainthread));\n  markvalue(g, registry(L));\n  markmt(g);\n  g->gcstate = GCSpropagate;\n}\n\n\nstatic void remarkupvals (global_State *g) {\n  UpVal *uv;\n  for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {\n    lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n    if (isgray(obj2gco(uv)))\n      markvalue(g, uv->v);\n  }\n}\n\n\nstatic void atomic (lua_State *L) {\n  global_State *g = G(L);\n  size_t udsize;  /* total size of userdata to be finalized */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  /* traverse objects cautch by write barrier and by 'remarkupvals' */\n  propagateall(g);\n  /* remark weak tables */\n  g->gray = g->weak;\n  g->weak = NULL;\n  lua_assert(!iswhite(obj2gco(g->mainthread)));\n  markobject(g, L);  /* mark running thread */\n  markmt(g);  /* mark basic metatables (again) */\n  propagateall(g);\n  /* remark gray again */\n  g->gray = g->grayagain;\n  g->grayagain = NULL;\n  propagateall(g);\n  udsize = luaC_separateudata(L, 0);  /* separate userdata to be finalized */\n  marktmu(g);  /* mark `preserved' userdata */\n  udsize += propagateall(g);  /* remark, to propagate `preserveness' */\n  cleartable(g->weak);  /* remove collected objects from weak tables */\n  /* flip current white */\n  g->currentwhite = cast_byte(otherwhite(g));\n  g->sweepstrgc = 0;\n  g->sweepgc = &g->rootgc;\n  g->gcstate = GCSsweepstring;\n  g->estimate = g->totalbytes - udsize;  /* first estimate */\n}\n\n\nstatic l_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  /*lua_checkmemory(L);*/\n  switch (g->gcstate) {\n    case GCSpause: {\n      markroot(L);  /* start a new collection */\n      return 0;\n    }\n    case GCSpropagate: {\n      if (g->gray)\n        return propagatemark(g);\n      else {  /* no more `gray' objects */\n        atomic(L);  /* finish mark phase */\n        return 0;\n      }\n    }\n    case GCSsweepstring: {\n      lu_mem old = g->totalbytes;\n      sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);\n      if (g->sweepstrgc >= g->strt.size)  /* nothing more to sweep? */\n        g->gcstate = GCSsweep;  /* end sweep-string phase */\n      lua_assert(old >= g->totalbytes);\n      g->estimate -= old - g->totalbytes;\n      return GCSWEEPCOST;\n    }\n    case GCSsweep: {\n      lu_mem old = g->totalbytes;\n      g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n      if (*g->sweepgc == NULL) {  /* nothing more to sweep? */\n        checkSizes(L);\n        g->gcstate = GCSfinalize;  /* end sweep phase */\n      }\n      lua_assert(old >= g->totalbytes);\n      g->estimate -= old - g->totalbytes;\n      return GCSWEEPMAX*GCSWEEPCOST;\n    }\n    case GCSfinalize: {\n      if (g->tmudata) {\n        GCTM(L);\n        if (g->estimate > GCFINALIZECOST)\n          g->estimate -= GCFINALIZECOST;\n        return GCFINALIZECOST;\n      }\n      else {\n        g->gcstate = GCSpause;  /* end collection */\n        g->gcdept = 0;\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;\n  if (lim == 0)\n    lim = (MAX_LUMEM-1)/2;  /* no limit */\n  g->gcdept += g->totalbytes - g->GCthreshold;\n  do {\n    lim -= singlestep(L);\n    if (g->gcstate == GCSpause)\n      break;\n  } while (lim > 0);\n  if (g->gcstate != GCSpause) {\n    if (g->gcdept < GCSTEPSIZE)\n      g->GCthreshold = g->totalbytes + GCSTEPSIZE;  /* - lim/g->gcstepmul;*/\n    else {\n      g->gcdept -= GCSTEPSIZE;\n      g->GCthreshold = g->totalbytes;\n    }\n  }\n  else {\n    setthreshold(g);\n  }\n}\n\n\nvoid luaC_fullgc (lua_State *L) {\n  global_State *g = G(L);\n  if (g->gcstate <= GCSpropagate) {\n    /* reset sweep marks to sweep all elements (returning them to white) */\n    g->sweepstrgc = 0;\n    g->sweepgc = &g->rootgc;\n    /* reset other collector lists */\n    g->gray = NULL;\n    g->grayagain = NULL;\n    g->weak = NULL;\n    g->gcstate = GCSsweepstring;\n  }\n  lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate);\n  /* finish any pending sweep phase */\n  while (g->gcstate != GCSfinalize) {\n    lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep);\n    singlestep(L);\n  }\n  markroot(L);\n  while (g->gcstate != GCSpause) {\n    singlestep(L);\n  }\n  setthreshold(g);\n}\n\n\nvoid luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n  lua_assert(ttype(&o->gch) != LUA_TTABLE);\n  /* must keep invariant? */\n  if (g->gcstate == GCSpropagate)\n    reallymarkobject(g, v);  /* restore invariant */\n  else  /* don't mind */\n    makewhite(g, o);  /* mark as white just to avoid other barriers */\n}\n\n\nvoid luaC_barrierback (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  GCObject *o = obj2gco(t);\n  lua_assert(isblack(o) && !isdead(g, o));\n  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n  black2gray(o);  /* make table gray (again) */\n  t->gclist = g->grayagain;\n  g->grayagain = o;\n}\n\n\nvoid luaC_link (lua_State *L, GCObject *o, lu_byte tt) {\n  global_State *g = G(L);\n  o->gch.next = g->rootgc;\n  g->rootgc = o;\n  o->gch.marked = luaC_white(g);\n  o->gch.tt = tt;\n}\n\n\nvoid luaC_linkupval (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = obj2gco(uv);\n  o->gch.next = g->rootgc;  /* link upvalue into `rootgc' list */\n  g->rootgc = o;\n  if (isgray(o)) { \n    if (g->gcstate == GCSpropagate) {\n      gray2black(o);  /* closed upvalues need barrier */\n      luaC_barrier(L, uv, uv->v);\n    }\n    else {  /* sweep phase: sweep it (turning it into white) */\n      makewhite(g, o);\n      lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n    }\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpause\t0\n#define GCSpropagate\t1\n#define GCSsweepstring\t2\n#define GCSsweep\t3\n#define GCSfinalize\t4\n\n\n/*\n** some userful bit tricks\n*/\n#define resetbits(x,m)\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t((x) |= (m))\n#define testbits(x,m)\t((x) & (m))\n#define bitmask(b)\t(1<<(b))\n#define bit2mask(b1,b2)\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\tresetbits(x, bitmask(b))\n#define testbit(x,b)\ttestbits(x, bitmask(b))\n#define set2bits(x,b1,b2)\tsetbits(x, (bit2mask(b1, b2)))\n#define reset2bits(x,b1,b2)\tresetbits(x, (bit2mask(b1, b2)))\n#define test2bits(x,b1,b2)\ttestbits(x, (bit2mask(b1, b2)))\n\n\n\n/*\n** Layout for bit use in `marked' field:\n** bit 0 - object is white (type 0)\n** bit 1 - object is white (type 1)\n** bit 2 - object is black\n** bit 3 - for userdata: has been finalized\n** bit 3 - for tables: has weak keys\n** bit 4 - for tables: has weak values\n** bit 5 - object is fixed (should not be collected)\n** bit 6 - object is \"super\" fixed (only the main thread)\n*/\n\n\n#define WHITE0BIT\t0\n#define WHITE1BIT\t1\n#define BLACKBIT\t2\n#define FINALIZEDBIT\t3\n#define KEYWEAKBIT\t3\n#define VALUEWEAKBIT\t4\n#define FIXEDBIT\t5\n#define SFIXEDBIT\t6\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)\n#define isblack(x)      testbit((x)->gch.marked, BLACKBIT)\n#define isgray(x)\t(!isblack(x) && !iswhite(x))\n\n#define otherwhite(g)\t(g->currentwhite ^ WHITEBITS)\n#define isdead(g,v)\t((v)->gch.marked & otherwhite(g) & WHITEBITS)\n\n#define changewhite(x)\t((x)->gch.marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->gch.marked, BLACKBIT)\n\n#define valiswhite(x)\t(iscollectable(x) && iswhite(gcvalue(x)))\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n\n#define luaC_checkGC(L) { \\\n  condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \\\n  if (G(L)->totalbytes >= G(L)->GCthreshold) \\\n\tluaC_step(L); }\n\n\n#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \\\n\tluaC_barrierf(L,obj2gco(p),gcvalue(v)); }\n\n#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \\\n\tluaC_barrierback(L,t); }\n\n#define luaC_objbarrier(L,p,o)  \\\n\t{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \\\n\t\tluaC_barrierf(L,obj2gco(p),obj2gco(o)); }\n\n#define luaC_objbarriert(L,t,o)  \\\n   { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }\n\nLUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);\nLUAI_FUNC void luaC_callGCTM (lua_State *L);\nLUAI_FUNC void luaC_freeall (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_fullgc (lua_State *L);\nLUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);\nLUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $\n** Initialization of libraries for lua.c\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\nstatic const luaL_Reg lualibs[] = {\n  {\"\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_DBLIBNAME, luaopen_debug},\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib = lualibs;\n  for (; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_pushstring(L, lib->name);\n    lua_call(L, 1, 0);\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.73.1.4 2010/05/14 15:33:51 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n#define IO_INPUT\t1\n#define IO_OUTPUT\t2\n\n\nstatic const char *const fnames[] = {\"input\", \"output\"};\n\n\nstatic int pushresult (lua_State *L, int i, const char *filename) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (i) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (filename)\n      lua_pushfstring(L, \"%s: %s\", filename, strerror(en));\n    else\n      lua_pushfstring(L, \"%s\", strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\nstatic void fileerror (lua_State *L, int arg, const char *filename) {\n  lua_pushfstring(L, \"%s: %s\", filename, strerror(errno));\n  luaL_argerror(L, arg, lua_tostring(L, -1));\n}\n\n\n#define tofilep(L)\t((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n\nstatic int io_type (lua_State *L) {\n  void *ud;\n  luaL_checkany(L, 1);\n  ud = lua_touserdata(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);\n  if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))\n    lua_pushnil(L);  /* not a file */\n  else if (*((FILE **)ud) == NULL)\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  FILE **f = tofilep(L);\n  if (*f == NULL)\n    luaL_error(L, \"attempt to use a closed file\");\n  return *f;\n}\n\n\n\n/*\n** When creating file handles, always creates a `closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** file is not left opened.\n*/\nstatic FILE **newfile (lua_State *L) {\n  FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));\n  *pf = NULL;  /* file handle is currently `closed' */\n  luaL_getmetatable(L, LUA_FILEHANDLE);\n  lua_setmetatable(L, -2);\n  return pf;\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  FILE **p = tofilep(L);\n  int ok = lua_pclose(L, *p);\n  *p = NULL;\n  return pushresult(L, ok, NULL);\n#endif\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  FILE **p = tofilep(L);\n  int ok = (fclose(*p) == 0);\n  *p = NULL;\n  return pushresult(L, ok, NULL);\n}\n\n\nstatic int aux_close (lua_State *L) {\n  lua_getfenv(L, 1);\n  lua_getfield(L, -1, \"__close\");\n  return (lua_tocfunction(L, -1))(L);\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))\n    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);\n  tofile(L);  /* make sure argument is a file */\n  return aux_close(L);\n}\n\n\nstatic int io_gc (lua_State *L) {\n  FILE *f = *tofilep(L);\n  /* ignore closed files */\n  if (f != NULL)\n    aux_close(L);\n  return 0;\n}\n\n\nstatic int io_tostring (lua_State *L) {\n  FILE *f = *tofilep(L);\n  if (f == NULL)\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", f);\n  return 1;\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  FILE **pf = newfile(L);\n  *pf = fopen(filename, mode);\n  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;\n}\n\n\n/*\n** this function has a separated environment, which defines the\n** correct __close for 'popen' files\n*/\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  FILE **pf = newfile(L);\n  *pf = lua_popen(L, filename, mode);\n  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  FILE **pf = newfile(L);\n  *pf = tmpfile();\n  return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, int findex) {\n  FILE *f;\n  lua_rawgeti(L, LUA_ENVIRONINDEX, findex);\n  f = *(FILE **)lua_touserdata(L, -1);\n  if (f == NULL)\n    luaL_error(L, \"standard %s file is closed\", fnames[findex - 1]);\n  return f;\n}\n\n\nstatic int g_iofile (lua_State *L, int f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename) {\n      FILE **pf = newfile(L);\n      *pf = fopen(filename, mode);\n      if (*pf == NULL)\n        fileerror(L, 1, filename);\n    }\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_rawseti(L, LUA_ENVIRONINDEX, f);\n  }\n  /* return current value */\n  lua_rawgeti(L, LUA_ENVIRONINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\nstatic void aux_lines (lua_State *L, int idx, int toclose) {\n  lua_pushvalue(L, idx);\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_pushcclosure(L, io_readline, 2);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 1, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  if (lua_isnoneornil(L, 1)) {  /* no arguments? */\n    /* will iterate over default input */\n    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);\n    return f_lines(L);\n  }\n  else {\n    const char *filename = luaL_checkstring(L, 1);\n    FILE **pf = newfile(L);\n    *pf = fopen(filename, \"r\");\n    if (*pf == NULL)\n      fileerror(L, 1, filename);\n    aux_lines(L, lua_gettop(L), 1);\n    return 1;\n  }\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\nstatic int read_number (lua_State *L, FILE *f) {\n  lua_Number d;\n  if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {\n    lua_pushnumber(L, d);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);  /* \"result\" to be removed */\n    return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);\n  lua_pushlstring(L, NULL, 0);\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f) {\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  for (;;) {\n    size_t l;\n    char *p = luaL_prepbuffer(&b);\n    if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) {  /* eof? */\n      luaL_pushresult(&b);  /* close buffer */\n      return (lua_objlen(L, -1) > 0);  /* check whether read something */\n    }\n    l = strlen(p);\n    if (l == 0 || p[l-1] != '\\n')\n      luaL_addsize(&b, l);\n    else {\n      luaL_addsize(&b, l - 1);  /* do not include `eol' */\n      luaL_pushresult(&b);  /* close buffer */\n      return 1;  /* read at least an `eol' */\n    }\n  }\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t rlen;  /* how much to read */\n  size_t nr;  /* number of chars actually read */\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  rlen = LUAL_BUFFERSIZE;  /* try to read that much each time */\n  do {\n    char *p = luaL_prepbuffer(&b);\n    if (rlen > n) rlen = n;  /* cannot read more than asked */\n    nr = fread(p, sizeof(char), rlen, f);\n    luaL_addsize(&b, nr);\n    n -= nr;  /* still have to read `n' chars */\n  } while (n > 0 && nr == rlen);  /* until end of count or eof */\n  luaL_pushresult(&b);  /* close buffer */\n  return (n == 0 || lua_objlen(L, -1) > 0);\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)lua_tointeger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = lua_tostring(L, n);\n        luaL_argcheck(L, p && p[0] == '*', n, \"invalid option\");\n        switch (p[1]) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f);\n            break;\n          case 'a':  /* file */\n            read_chars(L, f, ~((size_t)0));  /* read MAX_SIZE_T chars */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return pushresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));\n  int sucess;\n  if (f == NULL)  /* file is already closed? */\n    luaL_error(L, \"file is already closed\");\n  sucess = read_line(L, f);\n  if (ferror(f))\n    return luaL_error(L, \"%s\", strerror(errno));\n  if (sucess) return 1;\n  else {  /* EOF */\n    if (lua_toboolean(L, lua_upvalueindex(2))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - 1;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      status = status &&\n          fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  return pushresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  return g_write(L, tofile(L), 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  long offset = luaL_optlong(L, 3, 0);\n  op = fseek(f, offset, mode[op]);\n  if (op)\n    return pushresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], sz);\n  return pushresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return pushresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg flib[] = {\n  {\"close\", io_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", io_gc},\n  {\"__tostring\", io_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_register(L, NULL, flib);  /* file methods */\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {\n  *newfile(L) = f;\n  if (k > 0) {\n    lua_pushvalue(L, -1);\n    lua_rawseti(L, LUA_ENVIRONINDEX, k);\n  }\n  lua_pushvalue(L, -2);  /* copy environment */\n  lua_setfenv(L, -2);  /* set it */\n  lua_setfield(L, -3, fname);\n}\n\n\nstatic void newfenv (lua_State *L, lua_CFunction cls) {\n  lua_createtable(L, 0, 1);\n  lua_pushcfunction(L, cls);\n  lua_setfield(L, -2, \"__close\");\n}\n\n\nLUALIB_API int luaopen_io (lua_State *L) {\n  createmeta(L);\n  /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */\n  newfenv(L, io_fclose);\n  lua_replace(L, LUA_ENVIRONINDEX);\n  /* open library */\n  luaL_register(L, LUA_IOLIBNAME, iolib);\n  /* create (and set) default files */\n  newfenv(L, io_noclose);  /* close function for default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, 0, \"stderr\");\n  lua_pop(L, 1);  /* pop environment for default files */\n  lua_getfield(L, -1, \"popen\");\n  newfenv(L, io_pclose);  /* create environment for 'popen' */\n  lua_setfenv(L, -2);  /* set fenv for 'popen' */\n  lua_pop(L, 1);  /* pop 'popen' */\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.20.1.2 2009/11/23 14:58:22 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <locale.h>\n#include <string.h>\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldo.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nconst char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<number>\", \"<name>\", \"<string>\", \"<eof>\",\n    NULL\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (b->n + 1 > b->buffsize) {\n    size_t newsize;\n    if (b->buffsize >= MAX_SIZET/2)\n      luaX_lexerror(ls, \"lexical element too long\", 0);\n    newsize = b->buffsize * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[b->n++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaS_fix(ts);  /* reserved words are never collected */\n    lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);\n    ts->tsv.reserved = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\n#define MAXSRC          80\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {\n    lua_assert(token == cast(unsigned char, token));\n    return (iscntrl(token)) ? luaO_pushfstring(ls->L, \"char(%d)\", token) :\n                              luaO_pushfstring(ls->L, \"%c\", token);\n  }\n  else\n    return luaX_tokens[token-FIRST_RESERVED];\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME:\n    case TK_STRING:\n    case TK_NUMBER:\n      save(ls, '\\0');\n      return luaZ_buffer(ls->buff);\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nvoid luaX_lexerror (LexState *ls, const char *msg, int token) {\n  char buff[MAXSRC];\n  luaO_chunkid(buff, getstr(ls->source), MAXSRC);\n  msg = luaO_pushfstring(ls->L, \"%s:%d: %s\", buff, ls->linenumber, msg);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near \" LUA_QS, msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nvoid luaX_syntaxerror (LexState *ls, const char *msg) {\n  luaX_lexerror(ls, msg, ls->t.token);\n}\n\n\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TString *ts = luaS_newlstr(L, str, l);\n  TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */\n  if (ttisnil(o)) {\n    setbvalue(o, 1);  /* make sure `str' will not be collected */\n    luaC_checkGC(L);\n  }\n  return ts;\n}\n\n\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip `\\n' or `\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip `\\n\\r' or `\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    luaX_syntaxerror(ls, \"chunk has too many lines\");\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {\n  ls->decpoint = '.';\n  ls->L = L;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n  next(ls);  /* read first char */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\n\nstatic int check_next (LexState *ls, const char *set) {\n  if (!strchr(set, ls->current))\n    return 0;\n  save_and_next(ls);\n  return 1;\n}\n\n\nstatic void buffreplace (LexState *ls, char from, char to) {\n  size_t n = luaZ_bufflen(ls->buff);\n  char *p = luaZ_buffer(ls->buff);\n  while (n--)\n    if (p[n] == from) p[n] = to;\n}\n\n\nstatic void trydecpoint (LexState *ls, SemInfo *seminfo) {\n  /* format error: try to update decimal point separator */\n  char old = ls->decpoint;\n#ifdef __ANDROID__\n  ls->decpoint = '.';\n#else\n  struct lconv *cv = localeconv();\n  ls->decpoint = (cv ? cv->decimal_point[0] : '.');\n#endif\n  buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */\n  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {\n    /* format error with correct decimal point: no more options */\n    buffreplace(ls, ls->decpoint, '.');  /* undo change (for error message) */\n    luaX_lexerror(ls, \"malformed number\", TK_NUMBER);\n  }\n}\n\n\n/* LUA_NUMBER */\nstatic void read_numeral (LexState *ls, SemInfo *seminfo) {\n  lua_assert(isdigit(ls->current));\n  do {\n    save_and_next(ls);\n  } while (isdigit(ls->current) || ls->current == '.');\n  if (check_next(ls, \"Ee\"))  /* `E'? */\n    check_next(ls, \"+-\");  /* optional exponent sign */\n  while (isalnum(ls->current) || ls->current == '_')\n    save_and_next(ls);\n  save(ls, '\\0');\n  buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */\n  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */\n    trydecpoint(ls, seminfo); /* try to update decimal point separator */\n}\n\n\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int cont = 0;\n  (void)(cont);  /* avoid warnings when `cont' is not used */\n  save_and_next(ls);  /* skip 2nd `[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ:\n        luaX_lexerror(ls, (seminfo) ? \"unfinished long string\" :\n                                   \"unfinished long comment\", TK_EOS);\n        break;  /* to avoid warnings */\n#if defined(LUA_COMPAT_LSTR)\n      case '[': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd `[' */\n          cont++;\n#if LUA_COMPAT_LSTR == 1\n          if (sep == 0)\n            luaX_lexerror(ls, \"nesting of [[...]] is deprecated\", '[');\n#endif\n        }\n        break;\n      }\n#endif\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd `]' */\n#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2\n          cont--;\n          if (sep == 0 && cont >= 0) break;\n#endif\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n':\n      case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        luaX_lexerror(ls, \"unfinished string\", TK_EOS);\n        continue;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        luaX_lexerror(ls, \"unfinished string\", TK_STRING);\n        continue;  /* to avoid warnings */\n      case '\\\\': {\n        int c;\n        next(ls);  /* do not save the `\\' */\n        switch (ls->current) {\n          case 'a': c = '\\a'; break;\n          case 'b': c = '\\b'; break;\n          case 'f': c = '\\f'; break;\n          case 'n': c = '\\n'; break;\n          case 'r': c = '\\r'; break;\n          case 't': c = '\\t'; break;\n          case 'v': c = '\\v'; break;\n          case '\\n':  /* go through */\n          case '\\r': save(ls, '\\n'); inclinenumber(ls); continue;\n          case EOZ: continue;  /* will raise an error next loop */\n          default: {\n            if (!isdigit(ls->current))\n              save_and_next(ls);  /* handles \\\\, \\\", \\', and \\? */\n            else {  /* \\xxx */\n              int i = 0;\n              c = 0;\n              do {\n                c = 10*c + (ls->current-'0');\n                next(ls);\n              } while (++i<3 && isdigit(ls->current));\n              if (c > UCHAR_MAX)\n                luaX_lexerror(ls, \"escape sequence too large\", TK_STRING);\n              save(ls, c);\n            }\n            continue;\n          }\n        }\n        save(ls, c);\n        next(ls);\n        continue;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n':\n      case '\\r': {\n        inclinenumber(ls);\n        continue;\n      }\n      case '-': {\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* `skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* long comment */\n            luaZ_resetbuffer(ls->buff);\n            continue;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);\n        continue;\n      }\n      case '[': {\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep == -1) return '[';\n        else luaX_lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n      }\n      case '=': {\n        next(ls);\n        if (ls->current != '=') return '=';\n        else { next(ls); return TK_EQ; }\n      }\n      case '<': {\n        next(ls);\n        if (ls->current != '=') return '<';\n        else { next(ls); return TK_LE; }\n      }\n      case '>': {\n        next(ls);\n        if (ls->current != '=') return '>';\n        else { next(ls); return TK_GE; }\n      }\n      case '~': {\n        next(ls);\n        if (ls->current != '=') return '~';\n        else { next(ls); return TK_NE; }\n      }\n      case '\"':\n      case '\\'': {\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {\n        save_and_next(ls);\n        if (check_next(ls, \".\")) {\n          if (check_next(ls, \".\"))\n            return TK_DOTS;   /* ... */\n          else return TK_CONCAT;   /* .. */\n        }\n        else if (!isdigit(ls->current)) return '.';\n        else {\n          read_numeral(ls, seminfo);\n          return TK_NUMBER;\n        }\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (isspace(ls->current)) {\n          lua_assert(!currIsNewline(ls));\n          next(ls);\n          continue;\n        }\n        else if (isdigit(ls->current)) {\n          read_numeral(ls, seminfo);\n          return TK_NUMBER;\n        }\n        else if (isalpha(ls->current) || ls->current == '_') {\n          /* identifier or reserved word */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (isalnum(ls->current) || ls->current == '_');\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          if (ts->tsv.reserved > 0)  /* reserved word? */\n            return ts->tsv.reserved - 1 + FIRST_RESERVED;\n          else {\n            seminfo->ts = ts;\n            return TK_NAME;\n          }\n        }\n        else {\n          int c = ls->current;\n          next(ls);\n          return c;  /* single-char tokens (+ - / ...) */\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nvoid luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n/* maximum length of a reserved word */\n#define TOKEN_LEN\t(sizeof(\"function\")/sizeof(char))\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,\n  TK_NAME, TK_STRING, TK_EOS\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\n/* array with token `names' */\nLUAI_DATA const char *const luaX_tokens [];\n\n\ntypedef union {\n  lua_Number r;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token `consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* `FuncState' is private to the parser */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  TString *source;  /* current source name */\n  char decpoint;  /* locale decimal point */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC void luaX_lookahead (LexState *ls);\nLUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);\nLUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $\n** Limits, basic types, and some other `installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n\ntypedef LUAI_UINT32 lu_int32;\n\ntypedef LUAI_UMEM lu_mem;\n\ntypedef LUAI_MEM l_mem;\n\n\n\n/* chars used as small naturals (so that `char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n#define MAX_SIZET\t((size_t)(~(size_t)0)-2)\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0)-2)\n\n\n#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */\n\n/*\n** conversion of pointer to integer\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define IntPoint(p)  ((unsigned int)(lu_mem)(p))\n\n\n\n/* type to ensure maximum alignment */\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n\n\n/* result of a `usual argument conversion' over lua_Number */\ntypedef LUAI_UACNUMBER l_uacNumber;\n\n\n/* internal assertions for in-house debugging */\n#ifdef lua_assert\n\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n#define api_check(l,e)\t\tlua_assert(e)\n\n#else\n\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define api_check\t\tluai_apicheck\n\n#endif\n\n\n#ifndef UNUSED\n#define UNUSED(x)\t((void)(x))\t/* to avoid warnings */\n#endif\n\n\n#ifndef cast\n#define cast(t, exp)\t((t)(exp))\n#endif\n\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n\n\n\n/*\n** type for virtual-machine instructions\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\ntypedef lu_int32 Instruction;\n\n\n\n/* maximum stack for a Lua function */\n#define MAXSTACK\t250\n\n\n\n/* minimum size for the string table (must be power of 2) */\n#ifndef MINSTRTABSIZE\n#define MINSTRTABSIZE\t32\n#endif\n\n\n/* minimum size for string buffer */\n#ifndef LUA_MINBUFFER\n#define LUA_MINBUFFER\t32\n#endif\n\n\n#ifndef lua_lock\n#define lua_lock(L)     ((void) 0) \n#define lua_unlock(L)   ((void) 0)\n#endif\n\n#ifndef luai_threadyield\n#define luai_threadyield(L)     {lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/ \n#ifndef HARDSTACKTESTS\n#define condhardstacktests(x)\t((void)0)\n#else\n#define condhardstacktests(x)\tx\n#endif\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI (3.14159265358979323846)\n#define RADIANS_PER_DEGREE (PI/180.0)\n\n\n\nstatic int math_abs (lua_State *L) {\n  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, sin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, cos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, tan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, asin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, acos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_pushnumber(L, atan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan2 (lua_State *L) {\n  lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_ceil (lua_State *L) {\n  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_floor (lua_State *L) {\n  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_fmod (lua_State *L) {\n  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_modf (lua_State *L) {\n  double ip;\n  double fp = modf(luaL_checknumber(L, 1), &ip);\n  lua_pushnumber(L, ip);\n  lua_pushnumber(L, fp);\n  return 2;\n}\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_pushnumber(L, log(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));\n  return 1;\n}\n\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmin = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d < dmin)\n      dmin = d;\n  }\n  lua_pushnumber(L, dmin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmax = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d > dmax)\n      dmax = d;\n  }\n  lua_pushnumber(L, dmax);\n  return 1;\n}\n\n\nstatic int math_random (lua_State *L) {\n  /* the `%' avoids the (rare) case of r==1, and is needed also because on\n     some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */\n  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, r);  /* Number between 0 and 1 */\n      break;\n    }\n    case 1: {  /* only upper limit */\n      int u = luaL_checkint(L, 1);\n      luaL_argcheck(L, 1<=u, 1, \"interval is empty\");\n      lua_pushnumber(L, floor(r*u)+1);  /* int between 1 and `u' */\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      int l = luaL_checkint(L, 1);\n      int u = luaL_checkint(L, 2);\n      luaL_argcheck(L, l<=u, 2, \"interval is empty\");\n      lua_pushnumber(L, floor(r*(u-l+1))+l);  /* int between `l' and `u' */\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  srand(luaL_checkint(L, 1));\n  return 0;\n}\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan2\", math_atan2},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cosh\",   math_cosh},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"pow\",   math_pow},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sinh\",   math_sinh},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tanh\",   math_tanh},\n  {\"tan\",   math_tan},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUALIB_API int luaopen_math (lua_State *L) {\n  luaL_register(L, LUA_MATHLIBNAME, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n#if defined(LUA_COMPAT_MOD)\n  lua_getfield(L, -1, \"fmod\");\n  lua_setfield(L, -2, \"mod\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** (`osize' is the old size, `nsize' is the new size)\n**\n** Lua ensures that (ptr == NULL) iff (osize == 0).\n**\n** * frealloc(ud, NULL, 0, x) creates a new block of size `x'\n**\n** * frealloc(ud, p, x, 0) frees the block `p'\n** (in this specific case, frealloc must return NULL).\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ANSI C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *errormsg) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, errormsg);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nvoid *luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n  return NULL;  /* to avoid warnings */\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  global_State *g = G(L);\n  lua_assert((osize == 0) == (block == NULL));\n  block = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (block == NULL && nsize > 0)\n    luaD_throw(L, LUA_ERRMEM);\n  lua_assert((nsize == 0) == (block == NULL));\n  g->totalbytes = (g->totalbytes - osize) + nsize;\n  return block;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n#define MEMERRMSG\t\"not enough memory\"\n\n\n#define luaM_reallocv(L,b,on,n,e) \\\n\t((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \\\n\t\tluaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \\\n\t\tluaM_toobig(L))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))\n\n#define luaM_malloc(L,t)\tluaM_realloc_(L, NULL, 0, (t))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\n\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_toobig (lua_State *L);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *errormsg);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.52.1.4 2009/09/09 13:17:16 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Darwin (Mac OS X), an\n** implementation for Windows, and a stub for other systems.\n*/\n\n\n#include <stdlib.h>\n#include <string.h>\n\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n#define LIBPREFIX\t\"LOADLIB: \"\n\n#define POF\t\tLUA_POF\n#define LIB_FAIL\t\"open\"\n\n\n/* error codes for ll_loadfunc */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n#define setprogdir(L)\t\t((void)0)\n\n\nstatic void ll_unloadlib (void *lib);\nstatic void *ll_load (lua_State *L, const char *path);\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n#if defined(LUA_DL_DLOPEN)\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\nstatic void ll_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  void *lib = dlopen(path, RTLD_NOW);\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)dlsym(lib, sym);\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n#undef setprogdir\n\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void ll_unloadlib (void *lib) {\n  FreeLibrary((HINSTANCE)lib);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  HINSTANCE lib = LoadLibraryA(path);\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DYLD)\n/*\n** {======================================================================\n** Native Mac OS X / Darwin Implementation\n** =======================================================================\n*/\n\n#include <mach-o/dyld.h>\n\n\n/* Mac appends a `_' before C function names */\n#undef POF\n#define POF\t\"_\" LUA_POF\n\n\nstatic void pusherror (lua_State *L) {\n  const char *err_str;\n  const char *err_file;\n  NSLinkEditErrors err;\n  int err_num;\n  NSLinkEditError(&err, &err_num, &err_file, &err_str);\n  lua_pushstring(L, err_str);\n}\n\n\nstatic const char *errorfromcode (NSObjectFileImageReturnCode ret) {\n  switch (ret) {\n    case NSObjectFileImageInappropriateFile:\n      return \"file is not a bundle\";\n    case NSObjectFileImageArch:\n      return \"library is for wrong CPU type\";\n    case NSObjectFileImageFormat:\n      return \"bad format\";\n    case NSObjectFileImageAccess:\n      return \"cannot access file\";\n    case NSObjectFileImageFailure:\n    default:\n      return \"unable to load library\";\n  }\n}\n\n\nstatic void ll_unloadlib (void *lib) {\n  NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  NSObjectFileImage img;\n  NSObjectFileImageReturnCode ret;\n  /* this would be a rare case, but prevents crashing if it happens */\n  if(!_dyld_present()) {\n    lua_pushliteral(L, \"dyld not present\");\n    return NULL;\n  }\n  ret = NSCreateObjectFileImageFromFile(path, &img);\n  if (ret == NSObjectFileImageSuccess) {\n    NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE |\n                       NSLINKMODULE_OPTION_RETURN_ON_ERROR);\n    NSDestroyObjectFileImage(img);\n    if (mod == NULL) pusherror(L);\n    return mod;\n  }\n  lua_pushstring(L, errorfromcode(ret));\n  return NULL;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);\n  if (nss == NULL) {\n    lua_pushfstring(L, \"symbol \" LUA_QS \" not found\", sym);\n    return NULL;\n  }\n  return (lua_CFunction)NSAddressOfSymbol(nss);\n}\n\n/* }====================================================== */\n\n\n\n#else\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void ll_unloadlib (void *lib) {\n  (void)lib;  /* to avoid warnings */\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  (void)path;  /* to avoid warnings */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  (void)lib; (void)sym;  /* to avoid warnings */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\n\n\n\nstatic void **ll_register (lua_State *L, const char *path) {\n  void **plib;\n  lua_pushfstring(L, \"%s%s\", LIBPREFIX, path);\n  lua_gettable(L, LUA_REGISTRYINDEX);  /* check library in registry? */\n  if (!lua_isnil(L, -1))  /* is there an entry? */\n    plib = (void **)lua_touserdata(L, -1);\n  else {  /* no entry yet; create one */\n    lua_pop(L, 1);\n    plib = (void **)lua_newuserdata(L, sizeof(const void *));\n    *plib = NULL;\n    luaL_getmetatable(L, \"_LOADLIB\");\n    lua_setmetatable(L, -2);\n    lua_pushfstring(L, \"%s%s\", LIBPREFIX, path);\n    lua_pushvalue(L, -2);\n    lua_settable(L, LUA_REGISTRYINDEX);\n  }\n  return plib;\n}\n\n\n/*\n** __gc tag method: calls library's `ll_unloadlib' function with the lib\n** handle\n*/\nstatic int gctm (lua_State *L) {\n  void **lib = (void **)luaL_checkudata(L, 1, \"_LOADLIB\");\n  if (*lib) ll_unloadlib(*lib);\n  *lib = NULL;  /* mark library as closed */\n  return 0;\n}\n\n\nstatic int ll_loadfunc (lua_State *L, const char *path, const char *sym) {\n  void **reg = ll_register(L, path);\n  if (*reg == NULL) *reg = ll_load(L, path);\n  if (*reg == NULL)\n    return ERRLIB;  /* unable to load library */\n  else {\n    lua_CFunction f = ll_sym(L, *reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);\n    return 0;  /* return function */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = ll_loadfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATHSEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATHSEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname) {\n  const char *path;\n  name = luaL_gsub(L, name, \".\", LUA_DIRSEP);\n  lua_getfield(L, LUA_ENVIRONINDEX, pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, LUA_QL(\"package.%s\") \" must be a string\", pname);\n  lua_pushliteral(L, \"\");  /* error accumulator */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename;\n    filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file \" LUA_QS, filename);\n    lua_remove(L, -2);  /* remove file name */\n    lua_concat(L, 2);  /* add entry to possible error message */\n  }\n  return NULL;  /* not found */\n}\n\n\nstatic void loaderror (lua_State *L, const char *filename) {\n  luaL_error(L, \"error loading module \" LUA_QS \" from file \" LUA_QS \":\\n\\t%s\",\n                lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int loader_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (luaL_loadfile(L, filename) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\n\nstatic const char *mkfuncname (lua_State *L, const char *modname) {\n  const char *funcname;\n  const char *mark = strchr(modname, *LUA_IGMARK);\n  if (mark) modname = mark + 1;\n  funcname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  funcname = lua_pushfstring(L, POF\"%s\", funcname);\n  lua_remove(L, -2);  /* remove 'gsub' result */\n  return funcname;\n}\n\n\nstatic int loader_C (lua_State *L) {\n  const char *funcname;\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  funcname = mkfuncname(L, name);\n  if (ll_loadfunc(L, filename, funcname) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\n\nstatic int loader_Croot (lua_State *L) {\n  const char *funcname;\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\");\n  if (filename == NULL) return 1;  /* root not found */\n  funcname = mkfuncname(L, name);\n  if ((stat = ll_loadfunc(L, filename, funcname)) != 0) {\n    if (stat != ERRFUNC) loaderror(L, filename);  /* real error */\n    lua_pushfstring(L, \"\\n\\tno module \" LUA_QS \" in file \" LUA_QS,\n                       name, filename);\n    return 1;  /* function not found */\n  }\n  return 1;\n}\n\n\nstatic int loader_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_ENVIRONINDEX, \"preload\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.preload\") \" must be a table\");\n  lua_getfield(L, -1, name);\n  if (lua_isnil(L, -1))  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic const int sentinel_ = 0;\n#define sentinel\t((void *)&sentinel_)\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  int i;\n  lua_settop(L, 1);  /* _LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, 2, name);\n  if (lua_toboolean(L, -1)) {  /* is it there? */\n    if (lua_touserdata(L, -1) == sentinel)  /* check loops */\n      luaL_error(L, \"loop or previous error loading module \" LUA_QS, name);\n    return 1;  /* package is already loaded */\n  }\n  /* else must load it; iterate over available loaders */\n  lua_getfield(L, LUA_ENVIRONINDEX, \"loaders\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.loaders\") \" must be a table\");\n  lua_pushliteral(L, \"\");  /* error message accumulator */\n  for (i=1; ; i++) {\n    lua_rawgeti(L, -2, i);  /* get a loader */\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"module \" LUA_QS \" not found:%s\",\n                    name, lua_tostring(L, -2));\n    lua_pushstring(L, name);\n    lua_call(L, 1, 1);  /* call it */\n    if (lua_isfunction(L, -1))  /* did it find module? */\n      break;  /* module loaded successfully */\n    else if (lua_isstring(L, -1))  /* loader returned error message? */\n      lua_concat(L, 2);  /* accumulate it */\n    else\n      lua_pop(L, 1);\n  }\n  lua_pushlightuserdata(L, sentinel);\n  lua_setfield(L, 2, name);  /* _LOADED[name] = sentinel */\n  lua_pushstring(L, name);  /* pass name as argument to module */\n  lua_call(L, 1, 1);  /* run loaded module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  lua_getfield(L, 2, name);\n  if (lua_touserdata(L, -1) == sentinel) {   /* module did not set a value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n  \n\nstatic void setfenv (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, LUA_QL(\"module\") \" not called from a Lua function\");\n  lua_pushvalue(L, -2);\n  lua_setfenv(L, -2);\n  lua_pop(L, 1);\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    lua_pushvalue(L, i);  /* get option (a function) */\n    lua_pushvalue(L, -2);  /* module */\n    lua_call(L, 1, 0);\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int loaded = lua_gettop(L) + 1;  /* index of _LOADED table */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, loaded, modname);  /* get _LOADED[modname] */\n  if (!lua_istable(L, -1)) {  /* not found? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)\n      return luaL_error(L, \"name conflict for module \" LUA_QS, modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, loaded, modname);  /* _LOADED[modname] = new table */\n  }\n  /* check whether table already has a _NAME field */\n  lua_getfield(L, -1, \"_NAME\");\n  if (!lua_isnil(L, -1))  /* is table an initialized module? */\n    lua_pop(L, 1);\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  setfenv(L);\n  dooptions(L, loaded - 1);\n  return 0;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n\n/* }====================================================== */\n\n\n\n/* auxiliary mark (for internal use) */\n#define AUXMARK\t\t\"\\1\"\n\nstatic void setpath (lua_State *L, const char *fieldname, const char *envname,\n                                   const char *def) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(envname);\n#endif\n  if (path == NULL)  /* no environment variable? */\n    lua_pushstring(L, def);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,\n                              LUA_PATHSEP AUXMARK LUA_PATHSEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"seeall\", ll_seeall},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n  {\"module\", ll_module},\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic const lua_CFunction loaders[] =\n  {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};\n\n\nLUALIB_API int luaopen_package (lua_State *L) {\n  int i;\n  /* create new type _LOADLIB */\n  luaL_newmetatable(L, \"_LOADLIB\");\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");\n  /* create `package' table */\n  luaL_register(L, LUA_LOADLIBNAME, pk_funcs);\n#if defined(LUA_COMPAT_LOADLIB) \n  lua_getfield(L, -1, \"loadlib\");\n  lua_setfield(L, LUA_GLOBALSINDEX, \"loadlib\");\n#endif\n  lua_pushvalue(L, -1);\n  lua_replace(L, LUA_ENVIRONINDEX);\n  /* create `loaders' table */\n  lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);\n  /* fill it with pre-defined loaders */\n  for (i=0; loaders[i] != NULL; i++) {\n    lua_pushcfunction(L, loaders[i]);\n    lua_rawseti(L, -2, i+1);\n  }\n  lua_setfield(L, -2, \"loaders\");  /* put it in field `loaders' */\n  setpath(L, \"path\", LUA_PATH, LUA_PATH_DEFAULT);  /* set field `path' */\n  setpath(L, \"cpath\", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATHSEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXECDIR \"\\n\" LUA_IGMARK);\n  lua_setfield(L, -2, \"config\");\n  /* set field `loaded' */\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 2);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field `preload' */\n  lua_newtable(L);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  luaL_register(L, NULL, ll_funcs);  /* open lib into global table */\n  lua_pop(L, 1);\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nconst TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* expoent */\n  while (x >= 16) {\n    x = (x+1) >> 1;\n    e++;\n  }\n  if (x < 8) return x;\n  else return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  int e = (x >> 3) & 31;\n  if (e == 0) return x;\n  else return ((x & 7)+8) << (e - 1);\n}\n\n\nint luaO_log2 (unsigned int x) {\n  static const lu_byte log_2[256] = {\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = -1;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n\n}\n\n\nint luaO_rawequalObj (const TValue *t1, const TValue *t2) {\n  if (ttype(t1) != ttype(t2)) return 0;\n  else switch (ttype(t1)) {\n    case LUA_TNIL:\n      return 1;\n    case LUA_TNUMBER:\n      return luai_numeq(nvalue(t1), nvalue(t2));\n    case LUA_TBOOLEAN:\n      return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */\n    case LUA_TLIGHTUSERDATA:\n      return pvalue(t1) == pvalue(t2);\n    default:\n      lua_assert(iscollectable(t1));\n      return gcvalue(t1) == gcvalue(t2);\n  }\n}\n\n\nint luaO_str2d (const char *s, lua_Number *result) {\n  char *endptr;\n  *result = lua_str2number(s, &endptr);\n  if (endptr == s) return 0;  /* conversion failed */\n  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */\n    *result = cast_num(strtoul(s, &endptr, 16));\n  if (*endptr == '\\0') return 1;  /* most common case */\n  while (isspace(cast(unsigned char, *endptr))) endptr++;\n  if (*endptr != '\\0') return 0;  /* invalid trailing characters? */\n  return 1;\n}\n\n\n\nstatic void pushstr (lua_State *L, const char *str) {\n  setsvalue2s(L, L->top, luaS_new(L, str));\n  incr_top(L);\n}\n\n\n/* this function handles only `%d', `%c', %f, %p, and `%s' formats */\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 1;\n  pushstr(L, \"\");\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));\n    incr_top(L);\n    switch (*(e+1)) {\n      case 's': {\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s);\n        break;\n      }\n      case 'c': {\n        char buff[2];\n        buff[0] = cast(char, va_arg(argp, int));\n        buff[1] = '\\0';\n        pushstr(L, buff);\n        break;\n      }\n      case 'd': {\n        setnvalue(L->top, cast_num(va_arg(argp, int)));\n        incr_top(L);\n        break;\n      }\n      case 'f': {\n        setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n        incr_top(L);\n        break;\n      }\n      case 'p': {\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */\n        sprintf(buff, \"%p\", va_arg(argp, void *));\n        pushstr(L, buff);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\");\n        break;\n      }\n      default: {\n        char buff[3];\n        buff[0] = '%';\n        buff[1] = *(e+1);\n        buff[2] = '\\0';\n        pushstr(L, buff);\n        break;\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  pushstr(L, fmt);\n  luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);\n  L->top -= n;\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  if (*source == '=') {\n    strncpy(out, source+1, bufflen);  /* remove first char */\n    out[bufflen-1] = '\\0';  /* ensures null termination */\n  }\n  else {  /* out = \"source\", or \"...source\" */\n    if (*source == '@') {\n      size_t l;\n      source++;  /* skip the `@' */\n      bufflen -= sizeof(\" '...' \");\n      l = strlen(source);\n      strcpy(out, \"\");\n      if (l > bufflen) {\n        source += (l-bufflen);  /* get last part of file name */\n        strcat(out, \"...\");\n      }\n      strcat(out, source);\n    }\n    else {  /* out = [string \"string\"] */\n      size_t len = strcspn(source, \"\\n\\r\");  /* stop at first newline */\n      bufflen -= sizeof(\" [string \\\"...\\\"] \");\n      if (len > bufflen) len = bufflen;\n      strcpy(out, \"[string \\\"\");\n      if (source[len] != '\\0') {  /* must truncate? */\n        strncat(out, source, len);\n        strcat(out, \"...\");\n      }\n      else\n        strcat(out, source);\n      strcat(out, \"\\\"]\");\n    }\n  }\n}\n"
  },
  {
    "path": "build/lua-5.1.5/src/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/* tags for values visible from Lua */\n#define LAST_TAG\tLUA_TTHREAD\n\n#define NUM_TAGS\t(LAST_TAG+1)\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\t(LAST_TAG+1)\n#define LUA_TUPVAL\t(LAST_TAG+2)\n#define LUA_TDEADKEY\t(LAST_TAG+3)\n\n\n/*\n** Union of all collectable objects\n*/\ntypedef union GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common header in struct form\n*/\ntypedef struct GCheader {\n  CommonHeader;\n} GCheader;\n\n\n\n\n/*\n** Union of all Lua values\n*/\ntypedef union {\n  GCObject *gc;\n  void *p;\n  lua_Number n;\n  int b;\n} Value;\n\n\n/*\n** Tagged Values\n*/\n\n#define TValuefields\tValue value; int tt\n\ntypedef struct lua_TValue {\n  TValuefields;\n} TValue;\n\n\n/* Macros to test type */\n#define ttisnil(o)\t(ttype(o) == LUA_TNIL)\n#define ttisnumber(o)\t(ttype(o) == LUA_TNUMBER)\n#define ttisstring(o)\t(ttype(o) == LUA_TSTRING)\n#define ttistable(o)\t(ttype(o) == LUA_TTABLE)\n#define ttisfunction(o)\t(ttype(o) == LUA_TFUNCTION)\n#define ttisboolean(o)\t(ttype(o) == LUA_TBOOLEAN)\n#define ttisuserdata(o)\t(ttype(o) == LUA_TUSERDATA)\n#define ttisthread(o)\t(ttype(o) == LUA_TTHREAD)\n#define ttislightuserdata(o)\t(ttype(o) == LUA_TLIGHTUSERDATA)\n\n/* Macros to access values */\n#define ttype(o)\t((o)->tt)\n#define gcvalue(o)\tcheck_exp(iscollectable(o), (o)->value.gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), (o)->value.p)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), (o)->value.n)\n#define rawtsvalue(o)\tcheck_exp(ttisstring(o), &(o)->value.gc->ts)\n#define tsvalue(o)\t(&rawtsvalue(o)->tsv)\n#define rawuvalue(o)\tcheck_exp(ttisuserdata(o), &(o)->value.gc->u)\n#define uvalue(o)\t(&rawuvalue(o)->uv)\n#define clvalue(o)\tcheck_exp(ttisfunction(o), &(o)->value.gc->cl)\n#define hvalue(o)\tcheck_exp(ttistable(o), &(o)->value.gc->h)\n#define bvalue(o)\tcheck_exp(ttisboolean(o), (o)->value.b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), &(o)->value.gc->th)\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n/*\n** for internal debug only\n*/\n#define checkconsistency(obj) \\\n  lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))\n\n#define checkliveness(g,obj) \\\n  lua_assert(!iscollectable(obj) || \\\n  ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))\n\n\n/* Macros to set values */\n#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)\n\n#define setnvalue(obj,x) \\\n  { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }\n\n#define setpvalue(obj,x) \\\n  { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }\n\n#define setbvalue(obj,x) \\\n  { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }\n\n#define setsvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \\\n    checkliveness(G(L),i_o); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \\\n    checkliveness(G(L),i_o); }\n\n#define setthvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \\\n    checkliveness(G(L),i_o); }\n\n#define setclvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \\\n    checkliveness(G(L),i_o); }\n\n#define sethvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \\\n    checkliveness(G(L),i_o); }\n\n#define setptvalue(L,obj,x) \\\n  { TValue *i_o=(obj); \\\n    i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \\\n    checkliveness(G(L),i_o); }\n\n\n\n\n#define setobj(L,obj1,obj2) \\\n  { const TValue *o2=(obj2); TValue *o1=(obj1); \\\n    o1->value = o2->value; o1->tt=o2->tt; \\\n    checkliveness(G(L),o1); }\n\n\n/*\n** different types of sets, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to table */\n#define setobj2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n#define setttype(obj, tt) (ttype(obj) = (tt))\n\n\n#define iscollectable(o)\t(ttype(o) >= LUA_TSTRING)\n\n\n\ntypedef TValue *StkId;  /* index to stack elements */\n\n\n/*\n** String headers for string table\n*/\ntypedef union TString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  struct {\n    CommonHeader;\n    lu_byte reserved;\n    unsigned int hash;\n    size_t len;\n  } tsv;\n} TString;\n\n\n#define getstr(ts)\tcast(const char *, (ts) + 1)\n#define svalue(o)       getstr(rawtsvalue(o))\n\n\n\ntypedef union Udata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for `local' udata */\n  struct {\n    CommonHeader;\n    struct Table *metatable;\n    struct Table *env;\n    size_t len;\n  } uv;\n} Udata;\n\n\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  TValue *k;  /* constants used by the function */\n  Instruction *code;\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines */\n  struct LocVar *locvars;  /* information about local variables */\n  TString **upvalues;  /* upvalue names */\n  TString  *source;\n  int sizeupvalues;\n  int sizek;  /* size of `k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of `p' */\n  int sizelocvars;\n  int linedefined;\n  int lastlinedefined;\n  GCObject *gclist;\n  lu_byte nups;  /* number of upvalues */\n  lu_byte numparams;\n  lu_byte is_vararg;\n  lu_byte maxstacksize;\n} Proto;\n\n\n/* masks for new-style vararg */\n#define VARARG_HASARG\t\t1\n#define VARARG_ISVARARG\t\t2\n#define VARARG_NEEDSARG\t\t4\n\n\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n\n/*\n** Upvalues\n*/\n\ntypedef struct UpVal {\n  CommonHeader;\n  TValue *v;  /* points to stack or to its own value */\n  union {\n    TValue value;  /* the value (when closed) */\n    struct {  /* double linked list (when open) */\n      struct UpVal *prev;\n      struct UpVal *next;\n    } l;\n  } u;\n} UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \\\n\tstruct Table *env\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define iscfunction(o)\t(ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)\n#define isLfunction(o)\t(ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    struct Node *next;  /* for chaining */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */ \n  lu_byte lsizenode;  /* log2 of size of `node' array */\n  struct Table *metatable;\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  GCObject *gclist;\n  int sizearray;  /* size of `array' array */\n} Table;\n\n\n\n/*\n** `module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\nLUAI_DATA const TValue luaO_nilobject_;\n\n#define ceillog2(x)\t(luaO_log2((x)-1) + 1)\n\nLUAI_FUNC int luaO_log2 (unsigned int x);\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $\n** See Copyright Notice in lua.h\n*/\n\n\n#define lopcodes_c\n#define LUA_CORE\n\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nconst char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETGLOBAL\",\n  \"GETTABLE\",\n  \"SETGLOBAL\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"DIV\",\n  \"MOD\",\n  \"POW\",\n  \"UNM\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSE\",\n  \"CLOSURE\",\n  \"VARARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nconst lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC) \t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_GETGLOBAL */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgN, iABx)\t\t/* OP_SETGLOBAL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 0, OpArgN, OpArgN, iABC)\t\t/* OP_CLOSE */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n};\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t`A' : 8 bits\n\t`B' : 9 bits\n\t`C' : 9 bits\n\t`Bx' : 18 bits (`B' and `C' together)\n\t`sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* `sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with `n' 1 bits at position `p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<n))<<p)\n\n/* creates a mask with `n' 0 bits at position `p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define GETARG_A(i)\t(cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))\n#define SETARG_A(i,u)\t((i) = (((i)&MASK0(SIZE_A,POS_A)) | \\\n\t\t((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))\n\n#define GETARG_B(i)\t(cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))\n#define SETARG_B(i,b)\t((i) = (((i)&MASK0(SIZE_B,POS_B)) | \\\n\t\t((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))\n\n#define GETARG_C(i)\t(cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))\n#define SETARG_C(i,b)\t((i) = (((i)&MASK0(SIZE_C,POS_C)) | \\\n\t\t((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))\n\n#define GETARG_Bx(i)\t(cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))\n#define SETARG_Bx(i,b)\t((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \\\n\t\t((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#define MAXINDEXRK\t(BITRK - 1)\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A) := ... := R(B) := nil\t\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETGLOBAL,/*\tA Bx\tR(A) := Gbl[Kst(Bx)]\t\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETGLOBAL,/*\tA Bx\tGbl[Kst(Bx)] := R(A)\t\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tsBx\tpc+=sBx\t\t\t\t\t*/\n\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++  \t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++  \t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/ \nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/ \n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORLOOP,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); \n                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++\t*/ \nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSE,/*\tA \tclose all variables in the stack up to (>=) R(A)*/\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))\t*/\n\nOP_VARARG/*\tA B\tR(A), R(A+1), ..., R(A+B-1) = vararg\t\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_VARARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,\n      and can be 0: OP_CALL then sets `top' to last_result+1, so\n      next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n      set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to `top'\n\n  (*) In OP_SETLIST, if (B == 0) then B = `top';\n      if (C == 0) then next `instruction' is real C\n\n  (*) For comparisons, A specifies what condition the test should accept\n      (true or false).\n\n  (*) All `skips' (pc++) assume that next instruction is a jump\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test\n*/  \n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int os_pushresult (lua_State *L, int i, const char *filename) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (i) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    lua_pushfstring(L, \"%s: %s\", filename, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n//static int os_execute (lua_State *L) {\n//  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));\n//  return 1;\n//}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return os_pushresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return os_pushresult(L, rename(fromname, toname) == 0, fromname);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  lua_getfield(L, -1, key);\n  res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\nstatic int getfield (lua_State *L, const char *key, int d) {\n  int res;\n  lua_getfield(L, -1, key);\n  if (lua_isnumber(L, -1))\n    res = (int)lua_tointeger(L, -1);\n  else {\n    if (d < 0)\n      return luaL_error(L, \"field \" LUA_QS \" missing in date table\", key);\n    res = d;\n  }\n  lua_pop(L, 1);\n  return res;\n}\n\n\nstatic int os_date (lua_State *L) {\n  const char *s = luaL_optstring(L, 1, \"%c\");\n  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));\n  struct tm *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = gmtime(&t);\n    s++;  /* skip `!' */\n  }\n  else\n    stm = localtime(&t);\n  if (stm == NULL)  /* invalid date? */\n    lua_pushnil(L);\n  else if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setfield(L, \"sec\", stm->tm_sec);\n    setfield(L, \"min\", stm->tm_min);\n    setfield(L, \"hour\", stm->tm_hour);\n    setfield(L, \"day\", stm->tm_mday);\n    setfield(L, \"month\", stm->tm_mon+1);\n    setfield(L, \"year\", stm->tm_year+1900);\n    setfield(L, \"wday\", stm->tm_wday+1);\n    setfield(L, \"yday\", stm->tm_yday+1);\n    setboolfield(L, \"isdst\", stm->tm_isdst);\n  }\n  else {\n    char cc[3];\n    luaL_Buffer b;\n    cc[0] = '%'; cc[2] = '\\0';\n    luaL_buffinit(L, &b);\n    for (; *s; s++) {\n      if (*s != '%' || *(s + 1) == '\\0')  /* no conversion specifier? */\n        luaL_addchar(&b, *s);\n      else {\n        size_t reslen;\n        char buff[200];  /* should be big enough for any conversion result */\n        cc[1] = *(++s);\n        reslen = strftime(buff, sizeof(buff), cc, stm);\n        luaL_addlstring(&b, buff, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0);\n    ts.tm_min = getfield(L, \"min\", 0);\n    ts.tm_hour = getfield(L, \"hour\", 12);\n    ts.tm_mday = getfield(L, \"day\", -1);\n    ts.tm_mon = getfield(L, \"month\", -1) - 1;\n    ts.tm_year = getfield(L, \"year\", -1) - 1900;\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n  }\n  if (t == (time_t)(-1))\n    lua_pushnil(L);\n  else\n    lua_pushnumber(L, (lua_Number)t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),\n                             (time_t)(luaL_optnumber(L, 2, 0))));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  exit(luaL_optint(L, 1, EXIT_SUCCESS));\n}\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  //{\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaopen_os (lua_State *L) {\n  luaL_register(L, LUA_OSLIBNAME, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.42.1.4 2011/10/21 19:31:42 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n#define getlocvar(fs, i)\t((fs)->f->locvars[(fs)->actvar[i]])\n\n#define luaY_checklimit(fs,v,l,m)\tif ((v)>(l)) errorlimit(fs,l,m)\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int breaklist;  /* list of jumps out of this loop */\n  lu_byte nactvar;  /* # active locals outside the breakable structure */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isbreakable;  /* true if `block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void chunk (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\nstatic void anchor_token (LexState *ls) {\n  if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {\n    TString *ts = ls->t.seminfo.ts;\n    luaX_newstring(ls, getstr(ts), ts->tsv.len);\n  }\n}\n\n\nstatic void error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, LUA_QS \" expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic void errorlimit (FuncState *fs, int limit, const char *what) {\n  const char *msg = (fs->f->linedefined == 0) ?\n    luaO_pushfstring(fs->L, \"main function has more than %d %s\", limit, what) :\n    luaO_pushfstring(fs->L, \"function at line %d has more than %d %s\",\n                            fs->f->linedefined, limit, what);\n  luaX_lexerror(fs->ls, msg, 0);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             LUA_QS \" expected (to close \" LUA_QS \" at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.s.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname(LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"too many local variables\");\n  while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\n#define new_localvarliteral(ls,v,n) \\\n  new_localvar(ls, luaX_newstring(ls, \"\" v, (sizeof(v)/sizeof(char))-1), n)\n\n\nstatic void new_localvar (LexState *ls, TString *name, int n) {\n  FuncState *fs = ls->fs;\n  luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, \"local variables\");\n  fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (LexState *ls, int tolevel) {\n  FuncState *fs = ls->fs;\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar).endpc = fs->pc;\n}\n\n\nstatic int indexupvalue (FuncState *fs, TString *name, expdesc *v) {\n  int i;\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  for (i=0; i<f->nups; i++) {\n    if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {\n      lua_assert(f->upvalues[i] == name);\n      return i;\n    }\n  }\n  /* new one */\n  luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, \"upvalues\");\n  luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues,\n                  TString *, MAX_INT, \"\");\n  while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;\n  f->upvalues[f->nups] = name;\n  luaC_objbarrier(fs->L, f, name);\n  lua_assert(v->k == VLOCAL || v->k == VUPVAL);\n  fs->upvalues[f->nups].k = cast_byte(v->k);\n  fs->upvalues[f->nups].info = cast_byte(v->u.s.info);\n  return f->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i=fs->nactvar-1; i >= 0; i--) {\n    if (n == getlocvar(fs, i).varname)\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl && bl->nactvar > level) bl = bl->previous;\n  if (bl) bl->upval = 1;\n}\n\n\nstatic int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL) {  /* no more levels? */\n    init_exp(var, VGLOBAL, NO_REG);  /* default is global variable */\n    return VGLOBAL;\n  }\n  else {\n    int v = searchvar(fs, n);  /* look up at current level */\n    if (v >= 0) {\n      init_exp(var, VLOCAL, v);\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n      return VLOCAL;\n    }\n    else {  /* not found at current level; try upper one */\n      if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)\n        return VGLOBAL;\n      var->u.s.info = indexupvalue(fs, n, var);  /* else was LOCAL or UPVAL */\n      var->k = VUPVAL;  /* upvalue in this level */\n      return VUPVAL;\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  if (singlevaraux(fs, varname, var, 1) == VGLOBAL)\n    var->u.s.info = luaK_stringK(fs, varname);  /* info points to global name */\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  if (++ls->L->nCcalls > LUAI_MAXCCALLS)\n\tluaX_lexerror(ls, \"chunk has too many syntax levels\", 0);\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) {\n  bl->breaklist = NO_JUMP;\n  bl->isbreakable = isbreakable;\n  bl->nactvar = fs->nactvar;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  fs->bl = bl->previous;\n  removevars(fs->ls, bl->nactvar);\n  if (bl->upval)\n    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);\n  /* a block either controls scope or breaks (never both) */\n  lua_assert(!bl->isbreakable || !bl->upval);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  luaK_patchtohere(fs, bl->breaklist);\n}\n\n\nstatic void pushclosure (LexState *ls, FuncState *func, expdesc *v) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizep;\n  int i;\n  luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,\n                  MAXARG_Bx, \"constant table overflow\");\n  while (oldsize < f->sizep) f->p[oldsize++] = NULL;\n  f->p[fs->np++] = func->f;\n  luaC_objbarrier(ls->L, f, func->f);\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));\n  for (i=0; i<func->f->nups; i++) {\n    OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);\n  }\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs) {\n  lua_State *L = ls->L;\n  Proto *f = luaF_newproto(L);\n  fs->f = f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  fs->L = L;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = -1;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->bl = NULL;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  fs->h = luaH_new(L, 0, 0);\n  /* anchor table of constants and prototype (to avoid being collected) */\n  sethvalue2s(L, L->top, fs->h);\n  incr_top(L);\n  setptvalue2s(L, L->top, f);\n  incr_top(L);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  removevars(ls, 0);\n  luaK_ret(fs, 0, 0);  /* final return */\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);\n  f->sizeupvalues = f->nups;\n  lua_assert(luaG_checkcode(f));\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  /* last token read was anchored in defunct function; must reanchor it */\n  if (fs) anchor_token(ls);\n  L->top -= 2;  /* remove table and prototype from the stack */\n}\n\n\nProto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {\n  struct LexState lexstate;\n  struct FuncState funcstate;\n  lexstate.buff = buff;\n  luaX_setinput(L, &lexstate, z, luaS_new(L, name));\n  open_func(&lexstate, &funcstate);\n  funcstate.f->is_vararg = VARARG_ISVARARG;  /* main func. is always vararg */\n  luaX_next(&lexstate);  /* read first token */\n  chunk(&lexstate);\n  check(&lexstate, TK_EOS);\n  close_func(&lexstate);\n  lua_assert(funcstate.prev == NULL);\n  lua_assert(funcstate.f->nups == 0);\n  lua_assert(lexstate.fs == NULL);\n  return funcstate.f;\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\nstatic void field (LexState *ls, expdesc *v) {\n  /* field -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyreg(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of `record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | `['exp1`]') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    luaY_checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  expr(ls, &cc->v);\n  luaY_checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> ?? */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top (for gc) */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    switch(ls->t.token) {\n      case TK_NAME: {  /* may be listfields or recfields */\n        luaX_lookahead(ls);\n        if (ls->lookahead.token != '=')  /* expression? */\n          listfield(ls, &cc);\n        else\n          recfield(ls, &cc);\n        break;\n      }\n      case '[': {  /* constructor_item -> recfield */\n        recfield(ls, &cc);\n        break;\n      }\n      default: {  /* constructor_part -> listfield */\n        listfield(ls, &cc);\n        break;\n      }\n    }\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { `,' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is `parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls), nparams++);\n          break;\n        }\n        case TK_DOTS: {  /* param -> `...' */\n          luaX_next(ls);\n#if defined(LUA_COMPAT_VARARG)\n          /* use `arg' as default name */\n          new_localvarliteral(ls, \"arg\", nparams++);\n          f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG;\n#endif\n          f->is_vararg |= VARARG_ISVARARG;\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or \" LUA_QL(\"...\") \" expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int needself, int line) {\n  /* body ->  `(' parlist `)' chunk END */\n  FuncState new_fs;\n  open_func(ls, &new_fs);\n  new_fs.f->linedefined = line;\n  checknext(ls, '(');\n  if (needself) {\n    new_localvarliteral(ls, \"self\", 0);\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  chunk(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  close_func(ls);\n  pushclosure(ls, &new_fs, e);\n}\n\n\nstatic int explist1 (LexState *ls, expdesc *v) {\n  /* explist1 -> expr { `,' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  int line = ls->linenumber;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> `(' [ explist1 ] `)' */\n      if (line != ls->lastline)\n        luaX_syntaxerror(ls,\"ambiguous syntax (function call x new statement)\");\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist1(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use `seminfo' before `next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n      return;\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.s.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void prefixexp (LexState *ls, expdesc *v) {\n  /* prefixexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n      return;\n    }\n  }\n}\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp ->\n        prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  prefixexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* field */\n        field(ls, v);\n        break;\n      }\n      case '[': {  /* `[' exp1 `]' */\n        expdesc key;\n        luaK_exp2anyreg(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* `:' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |\n                  constructor | FUNCTION body | primaryexp */\n  switch (ls->t.token) {\n    case TK_NUMBER: {\n      init_exp(v, VKNUM, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use \" LUA_QL(\"...\") \" outside a vararg function\");\n      fs->f->is_vararg &= ~VARARG_NEEDSARG;  /* don't need 'arg' */\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      primaryexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '/': return OPR_DIV;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},  /* `+' `-' `/' `%' */\n   {10, 9}, {5, 4},                 /* power and concat (right associative) */\n   {3, 3}, {3, 3},                  /* equality and inequality */\n   {3, 3}, {3, 3}, {3, 3}, {3, 3},  /* order */\n   {2, 2}, {1, 1}                   /* logical (and/or) */\n};\n\n#define UNARY_PRIORITY\t8  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where `binop' is any binary operator with a priority higher than `limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than `limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic int block_follow (int token) {\n  switch (token) {\n    case TK_ELSE: case TK_ELSEIF: case TK_END:\n    case TK_UNTIL: case TK_EOS:\n      return 1;\n    default: return 0;\n  }\n}\n\n\nstatic void block (LexState *ls) {\n  /* block -> chunk */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  chunk(ls);\n  lua_assert(bl.breaklist == NO_JUMP);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to a local variable, the local variable\n** is needed in a previous assignment (to a table). If so, save original\n** local value in a safe place and use this safe copy in the previous\n** assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {\n    if (lh->v.k == VINDEXED) {\n      if (lh->v.u.s.info == v->u.s.info) {  /* conflict? */\n        conflict = 1;\n        lh->v.u.s.info = extra;  /* previous assignment will use safe copy */\n      }\n      if (lh->v.u.s.aux == v->u.s.info) {  /* conflict? */\n        conflict = 1;\n        lh->v.u.s.aux = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0);  /* make copy */\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,\n                      \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    primaryexp(ls, &nv.v);\n    if (nv.v.k == VLOCAL)\n      check_conflict(ls, lh, &nv.v);\n    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,\n                    \"variables in assignment\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> `=' explist1 */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist1(ls, &e);\n    if (nexps != nvars) {\n      adjust_assign(ls, nvars, nexps, &e);\n      if (nexps > nvars)\n        ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n    }\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* `falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void breakstat (LexState *ls) {\n  FuncState *fs = ls->fs;\n  BlockCnt *bl = fs->bl;\n  int upval = 0;\n  while (bl && !bl->isbreakable) {\n    upval |= bl->upval;\n    bl = bl->previous;\n  }\n  if (!bl)\n    luaX_syntaxerror(ls, \"no loop to break\");\n  if (upval)\n    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);\n  luaK_concat(fs, &bl->breaklist, luaK_jump(fs));\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_patchlist(fs, luaK_jump(fs), whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  chunk(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (!bl2.upval) {  /* no upvalues? */\n    leaveblock(fs);  /* finish scope */\n    luaK_patchlist(ls->fs, condexit, repeat_init);  /* close the loop */\n  }\n  else {  /* complete semantics when there are upvalues */\n    breakstat(ls);  /* if condition then break */\n    luaK_patchtohere(ls->fs, condexit);  /* else... */\n    leaveblock(fs);  /* finish scope... */\n    luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init);  /* and repeat */\n  }\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int k;\n  expr(ls, &e);\n  k = e.k;\n  luaK_exp2nextreg(ls->fs, &e);\n  return k;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :\n                     luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);\n  luaK_fixline(fs, line);  /* pretend that `OP_FOR' starts the loop */\n  luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\", 0);\n  new_localvarliteral(ls, \"(for limit)\", 1);\n  new_localvarliteral(ls, \"(for step)\", 2);\n  new_localvar(ls, varname, 3);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist1 forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 0;\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\", nvars++);\n  new_localvarliteral(ls, \"(for state)\", nvars++);\n  new_localvarliteral(ls, \"(for control)\", nvars++);\n  /* create declared variables */\n  new_localvar(ls, indexname, nvars++);\n  while (testnext(ls, ','))\n    new_localvar(ls, str_checkname(ls), nvars++);\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist1(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip `for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, LUA_QL(\"=\") \" or \" LUA_QL(\"in\") \" expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope (`break' jumps to this point) */\n}\n\n\nstatic int test_then_block (LexState *ls) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  int condexit;\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  condexit = cond(ls);\n  checknext(ls, TK_THEN);\n  block(ls);  /* `then' part */\n  return condexit;\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int flist;\n  int escapelist = NO_JUMP;\n  flist = test_then_block(ls);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF) {\n    luaK_concat(fs, &escapelist, luaK_jump(fs));\n    luaK_patchtohere(fs, flist);\n    flist = test_then_block(ls);  /* ELSEIF cond THEN block */\n  }\n  if (ls->t.token == TK_ELSE) {\n    luaK_concat(fs, &escapelist, luaK_jump(fs));\n    luaK_patchtohere(fs, flist);\n    luaX_next(ls);  /* skip ELSE (after patch, for correct line info) */\n    block(ls);  /* `else' part */\n  }\n  else\n    luaK_concat(fs, &escapelist, flist);\n  luaK_patchtohere(fs, escapelist);\n  check_match(ls, TK_END, TK_IF, line);\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc v, b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls), 0);\n  init_exp(&v, VLOCAL, fs->freereg);\n  luaK_reserveregs(fs, 1);\n  adjustlocalvars(ls, 1);\n  body(ls, &b, 0, ls->linenumber);\n  luaK_storevar(fs, &v, &b);\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls), nvars++);\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist1(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {field} [`:' NAME] */\n  int needself = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    field(ls, v);\n  if (ls->t.token == ':') {\n    needself = 1;\n    field(ls, v);\n  }\n  return needself;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int needself;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  needself = funcname(ls, &v);\n  body(ls, &b, needself, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition `happens' in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  primaryexp(ls, &v.v);\n  if (v.v.k == VCALL)  /* stat -> func */\n    SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */\n  else {  /* stat -> assignment */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN explist */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  luaX_next(ls);  /* skip RETURN */\n  if (block_follow(ls->t.token) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist1(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getcode(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the `stack' */\n        first = fs->nactvar;  /* return all `active' values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n}\n\n\nstatic int statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  switch (ls->t.token) {\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      return 0;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      return 0;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      return 0;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      return 0;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      return 0;\n    }\n    case TK_FUNCTION: {\n      funcstat(ls, line);  /* stat -> funcstat */\n      return 0;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      return 0;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      retstat(ls);\n      return 1;  /* must be last statement */\n    }\n    case TK_BREAK: {  /* stat -> breakstat */\n      luaX_next(ls);  /* skip BREAK */\n      breakstat(ls);\n      return 1;  /* must be last statement */\n    }\n    default: {\n      exprstat(ls);\n      return 0;  /* to avoid warnings */\n    }\n  }\n}\n\n\nstatic void chunk (LexState *ls) {\n  /* chunk -> { stat [`;'] } */\n  int islast = 0;\n  enterlevel(ls);\n  while (!islast && !block_follow(ls->t.token)) {\n    islast = statement(ls);\n    testnext(ls, ';');\n    lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n               ls->fs->freereg >= ls->fs->nactvar);\n    ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  }\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n"
  },
  {
    "path": "build/lua-5.1.5/src/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression descriptor\n*/\n\ntypedef enum {\n  VVOID,\t/* no value */\n  VNIL,\n  VTRUE,\n  VFALSE,\n  VK,\t\t/* info = index of constant in `k' */\n  VKNUM,\t/* nval = numerical value */\n  VLOCAL,\t/* info = local register */\n  VUPVAL,       /* info = index of upvalue in `upvalues' */\n  VGLOBAL,\t/* info = index of table; aux = index of global name in `k' */\n  VINDEXED,\t/* info = table register; aux = index register (or `k') */\n  VJMP,\t\t/* info = instruction pc */\n  VRELOCABLE,\t/* info = instruction pc */\n  VNONRELOC,\t/* info = result register */\n  VCALL,\t/* info = instruction pc */\n  VVARARG\t/* info = instruction pc */\n} expkind;\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    struct { int info, aux; } s;\n    lua_Number nval;\n  } u;\n  int t;  /* patch list of `exit when true' */\n  int f;  /* patch list of `exit when false' */\n} expdesc;\n\n\ntypedef struct upvaldesc {\n  lu_byte k;\n  lu_byte info;\n} upvaldesc;\n\n\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  Table *h;  /* table to find (and reuse) elements in `k' */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct lua_State *L;  /* copy of the Lua state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to `ncode') */\n  int lasttarget;   /* `pc' of last `jump target' */\n  int jpc;  /* list of pending jumps to `pc' */\n  int freereg;  /* first free register */\n  int nk;  /* number of elements in `k' */\n  int np;  /* number of elements in `p' */\n  short nlocvars;  /* number of elements in `locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  upvaldesc upvalues[LUAI_MAXUPVALUES];  /* upvalues */\n  unsigned short actvar[LUAI_MAXVARS];  /* declared-variable stack */\n} FuncState;\n\n\nLUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                            const char *name);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#define state_size(x)\t(sizeof(x) + LUAI_EXTRASPACE)\n#define fromstate(l)\t(cast(lu_byte *, (l)) - LUAI_EXTRASPACE)\n#define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  lua_State l;\n  global_State g;\n} LG;\n  \n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  /* initialize CallInfo array */\n  L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);\n  L1->ci = L1->base_ci;\n  L1->size_ci = BASIC_CI_SIZE;\n  L1->end_ci = L1->base_ci + L1->size_ci - 1;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);\n  L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;\n  /* initialize first ci */\n  L1->ci->func = L1->top;\n  setnilvalue(L1->top++);  /* `function' entry for this `ci' */\n  L1->base = L1->ci->base = L1->top;\n  L1->ci->top = L1->top + LUA_MINSTACK;\n}\n\n\nstatic void freestack (lua_State *L, lua_State *L1) {\n  luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);\n  luaM_freearray(L, L1->stack, L1->stacksize, TValue);\n}\n\n\n/*\n** open parts that may cause memory-allocation errors\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  sethvalue(L, gt(L), luaH_new(L, 0, 2));  /* table of globals */\n  sethvalue(L, registry(L), luaH_new(L, 0, 2));  /* registry */\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  luaT_init(L);\n  luaX_init(L);\n  luaS_fix(luaS_newliteral(L, MEMERRMSG));\n  g->GCthreshold = 4*g->totalbytes;\n}\n\n\nstatic void preinit_state (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->stacksize = 0;\n  L->errorJmp = NULL;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->size_ci = 0;\n  L->nCcalls = L->baseCcalls = 0;\n  L->status = 0;\n  L->base_ci = L->ci = NULL;\n  L->savedpc = NULL;\n  L->errfunc = 0;\n  setnilvalue(gt(L));\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeall(L);  /* collect all objects */\n  lua_assert(g->rootgc == obj2gco(L));\n  lua_assert(g->strt.nuse == 0);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);\n  luaZ_freebuffer(L, &g->buff);\n  freestack(L, L);\n  lua_assert(g->totalbytes == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);\n}\n\n\nlua_State *luaE_newthread (lua_State *L) {\n  lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));\n  luaC_link(L, obj2gco(L1), LUA_TTHREAD);\n  preinit_state(L1, G(L));\n  stack_init(L1, L);  /* init stack */\n  setobj2n(L, gt(L1), gt(L));  /* share table of globals */\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  lua_assert(iswhite(obj2gco(L1)));\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L1);\n  freestack(L, L1);\n  luaM_freemem(L, fromstate(L1), state_size(lua_State));\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  void *l = (*f)(ud, NULL, 0, state_size(LG));\n  if (l == NULL) return NULL;\n  L = tostate(l);\n  g = &((LG *)L)->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);\n  L->marked = luaC_white(g);\n  set2bits(L->marked, FIXEDBIT, SFIXEDBIT);\n  preinit_state(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->uvhead.u.l.prev = &g->uvhead;\n  g->uvhead.u.l.next = &g->uvhead;\n  g->GCthreshold = 0;  /* mark it as unfinished state */\n  g->strt.size = 0;\n  g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(registry(L));\n  luaZ_initbuffer(L, &g->buff);\n  g->panic = NULL;\n  g->gcstate = GCSpause;\n  g->rootgc = obj2gco(L);\n  g->sweepstrgc = 0;\n  g->sweepgc = &g->rootgc;\n  g->gray = NULL;\n  g->grayagain = NULL;\n  g->weak = NULL;\n  g->tmudata = NULL;\n  g->totalbytes = sizeof(LG);\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  g->gcdept = 0;\n  for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  else\n    luai_userstateopen(L);\n  return L;\n}\n\n\nstatic void callallgcTM (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaC_callGCTM(L);  /* call GC metamethods for all udata */\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_separateudata(L, 1);  /* separate udata that have GC metamethods */\n  L->errfunc = 0;  /* no error function during GC metamethods */\n  do {  /* repeat until no more errors */\n    L->ci = L->base_ci;\n    L->base = L->top = L->ci->base;\n    L->nCcalls = L->baseCcalls = 0;\n  } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);\n  lua_assert(G(L)->tmudata == NULL);\n  luai_userstateclose(L);\n  close_state(L);\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/* table of globals */\n#define gt(L)\t(&L->l_gt)\n\n/* registry */\n#define registry(L)\t(&G(L)->l_registry)\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_CI_SIZE           8\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n\ntypedef struct stringtable {\n  GCObject **hash;\n  lu_int32 nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** informations about a call\n*/\ntypedef struct CallInfo {\n  StkId base;  /* base for this function */\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  const Instruction *savedpc;\n  int nresults;  /* expected number of results from this function */\n  int tailcalls;  /* number of tail calls lost under this entry */\n} CallInfo;\n\n\n\n#define curr_func(L)\t(clvalue(L->ci->func))\n#define ci_func(ci)\t(clvalue((ci)->func))\n#define f_isLua(ci)\t(!ci_func(ci)->c.isC)\n#define isLua(ci)\t(ttisfunction((ci)->func) && f_isLua(ci))\n\n\n/*\n** `global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  stringtable strt;  /* hash table for strings */\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to `frealloc' */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  int sweepstrgc;  /* position of sweep in `strt' */\n  GCObject *rootgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* position of sweep in `rootgc' */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of weak tables (to be cleared) */\n  GCObject *tmudata;  /* last element of list of userdata to be GC */\n  Mbuffer buff;  /* temporary buffer for string concatentation */\n  lu_mem GCthreshold;\n  lu_mem totalbytes;  /* number of bytes currently allocated */\n  lu_mem estimate;  /* an estimate of number of bytes actually in use */\n  lu_mem gcdept;  /* how much GC is `behind schedule' */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC `granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  TValue l_registry;\n  struct lua_State *mainthread;\n  UpVal uvhead;  /* head of double-linked list of all open upvalues */\n  struct Table *mt[NUM_TAGS];  /* metatables for basic types */\n  TString *tmname[TM_N];  /* array with tag-method names */\n} global_State;\n\n\n/*\n** `per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  StkId base;  /* base of current function */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *savedpc;  /* `savedpc' of current function */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  CallInfo *end_ci;  /* points after end of ci array*/\n  CallInfo *base_ci;  /* array of CallInfo's */\n  int stacksize;\n  int size_ci;  /* size of array `base_ci' */\n  unsigned short nCcalls;  /* number of nested C calls */\n  unsigned short baseCcalls;  /* nested C calls when resuming coroutine */\n  lu_byte hookmask;\n  lu_byte allowhook;\n  int basehookcount;\n  int hookcount;\n  lua_Hook hook;\n  TValue l_gt;  /* table of globals */\n  TValue env;  /* temporary place for environments */\n  GCObject *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects\n*/\nunion GCObject {\n  GCheader gch;\n  union TString ts;\n  union Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct UpVal uv;\n  struct lua_State th;  /* thread */\n};\n\n\n/* macros to convert a GCObject into a specific value */\n#define rawgco2ts(o)\tcheck_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))\n#define gco2ts(o)\t(&rawgco2ts(o)->tsv)\n#define rawgco2u(o)\tcheck_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))\n#define gco2u(o)\t(&rawgco2u(o)->uv)\n#define gco2cl(o)\tcheck_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))\n#define gco2h(o)\tcheck_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))\n#define gco2p(o)\tcheck_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))\n#define gco2uv(o)\tcheck_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))\n#define ngcotouv(o) \\\n\tcheck_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))\n#define gco2th(o)\tcheck_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))\n\n/* macro to convert any Lua object into a GCObject */\n#define obj2gco(v)\t(cast(GCObject *, (v)))\n\n\nLUAI_FUNC lua_State *luaE_newthread (lua_State *L);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n\nvoid luaS_resize (lua_State *L, int newsize) {\n  GCObject **newhash;\n  stringtable *tb;\n  int i;\n  if (G(L)->gcstate == GCSsweepstring)\n    return;  /* cannot resize during GC traverse */\n  newhash = luaM_newvector(L, newsize, GCObject *);\n  tb = &G(L)->strt;\n  for (i=0; i<newsize; i++) newhash[i] = NULL;\n  /* rehash */\n  for (i=0; i<tb->size; i++) {\n    GCObject *p = tb->hash[i];\n    while (p) {  /* for each node in the list */\n      GCObject *next = p->gch.next;  /* save next */\n      unsigned int h = gco2ts(p)->hash;\n      int h1 = lmod(h, newsize);  /* new position */\n      lua_assert(cast_int(h%newsize) == lmod(h, newsize));\n      p->gch.next = newhash[h1];  /* chain it */\n      newhash[h1] = p;\n      p = next;\n    }\n  }\n  luaM_freearray(L, tb->hash, tb->size, TString *);\n  tb->size = newsize;\n  tb->hash = newhash;\n}\n\n\nstatic TString *newlstr (lua_State *L, const char *str, size_t l,\n                                       unsigned int h) {\n  TString *ts;\n  stringtable *tb;\n  if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))\n    luaM_toobig(L);\n  ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));\n  ts->tsv.len = l;\n  ts->tsv.hash = h;\n  ts->tsv.marked = luaC_white(G(L));\n  ts->tsv.tt = LUA_TSTRING;\n  ts->tsv.reserved = 0;\n  memcpy(ts+1, str, l*sizeof(char));\n  ((char *)(ts+1))[l] = '\\0';  /* ending 0 */\n  tb = &G(L)->strt;\n  h = lmod(h, tb->size);\n  ts->tsv.next = tb->hash[h];  /* chain new entry */\n  tb->hash[h] = obj2gco(ts);\n  tb->nuse++;\n  if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)\n    luaS_resize(L, tb->size*2);  /* too crowded */\n  return ts;\n}\n\n\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  GCObject *o;\n  unsigned int h = cast(unsigned int, l);  /* seed */\n  size_t step = (l>>5)+1;  /* if string is too long, don't hash all its chars */\n  size_t l1;\n  for (l1=l; l1>=step; l1-=step)  /* compute hash */\n    h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));\n  for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];\n       o != NULL;\n       o = o->gch.next) {\n    TString *ts = rawgco2ts(o);\n    if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {\n      /* string may be dead */\n      if (isdead(G(L), o)) changewhite(o);\n      return ts;\n    }\n  }\n  return newlstr(L, str, l, h);  /* not found */\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s, Table *e) {\n  Udata *u;\n  if (s > MAX_SIZET - sizeof(Udata))\n    luaM_toobig(L);\n  u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));\n  u->uv.marked = luaC_white(G(L));  /* is not finalized */\n  u->uv.tt = LUA_TUSERDATA;\n  u->uv.len = s;\n  u->uv.metatable = NULL;\n  u->uv.env = e;\n  /* chain it on udata list (after main thread) */\n  u->uv.next = G(L)->mainthread->next;\n  G(L)->mainthread->next = obj2gco(u);\n  return u;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizestring(s)\t(sizeof(union TString)+((s)->len+1)*sizeof(char))\n\n#define sizeudata(u)\t(sizeof(union Udata)+(u)->len)\n\n#define luaS_new(L, s)\t(luaS_newlstr(L, s, strlen(s)))\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n#define luaS_fix(s)\tl_setbit((s)->tsv.marked, FIXEDBIT)\n\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.132.1.5 2010/05/14 15:34:19 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/* macro to `unsign' a character */\n#define uchar(c)        ((unsigned char)(c))\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, l);\n  return 1;\n}\n\n\nstatic ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {\n  /* relative string position: negative means back from end */\n  if (pos < 0) pos += (ptrdiff_t)len + 1;\n  return (pos >= 0) ? pos : 0;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);\n  ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;\n  if (start <= end)\n    lua_pushlstring(L, s+start-1, end-start+1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  while (l--) luaL_addchar(&b, s[l]);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  for (i=0; i<l; i++)\n    luaL_addchar(&b, tolower(uchar(s[i])));\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  for (i=0; i<l; i++)\n    luaL_addchar(&b, toupper(uchar(s[i])));\n  luaL_pushresult(&b);\n  return 1;\n}\n\nstatic int str_rep (lua_State *L) {\n  size_t l;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  int n = luaL_checkint(L, 2);\n  luaL_buffinit(L, &b);\n  while (n-- > 0)\n    luaL_addlstring(&b, s, l);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi <= 0) posi = 1;\n  if ((size_t)pose > l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  n = (int)(pose -  posi + 1);\n  if (posi + n <= pose)  /* overflow? */\n    luaL_error(L, \"string slice too long\");\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  for (i=1; i<=n; i++) {\n    int c = luaL_checkint(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"invalid value\");\n    luaL_addchar(&b, uchar(c));\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void* b, size_t size, void* B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b) != 0)\n    luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end (`\\0') of source string */\n  lua_State *L;\n  int level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index\");\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (*p == '\\0')\n        luaL_error(ms->L, \"malformed pattern (ends with \" LUA_QL(\"%%\") \")\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a `]' */\n        if (*p == '\\0')\n          luaL_error(ms->L, \"malformed pattern (missing \" LUA_QL(\"]\") \")\");\n        if (*(p++) == L_ESC && *p != '\\0')\n          p++;  /* skip escapes (e.g. `%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the `^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (int c, const char *p, const char *ep) {\n  switch (*p) {\n    case '.': return 1;  /* matches any char */\n    case L_ESC: return match_class(c, uchar(*(p+1)));\n    case '[': return matchbracketclass(c, p, ep-1);\n    default:  return (uchar(*p) == c);\n  }\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (*p == 0 || *(p+1) == 0)\n    luaL_error(ms->L, \"unbalanced pattern\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (s<ms->src_end && singlematch(uchar(*s), p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  init: /* using goto's to optimize tail recursion */\n  switch (*p) {\n    case '(': {  /* start capture */\n      if (*(p+1) == ')')  /* position capture? */\n        return start_capture(ms, s, p+2, CAP_POSITION);\n      else\n        return start_capture(ms, s, p+1, CAP_UNFINISHED);\n    }\n    case ')': {  /* end capture */\n      return end_capture(ms, s, p+1);\n    }\n    case L_ESC: {\n      switch (*(p+1)) {\n        case 'b': {  /* balanced string? */\n          s = matchbalance(ms, s, p+2);\n          if (s == NULL) return NULL;\n          p+=4; goto init;  /* else return match(ms, s, p+4); */\n        }\n        case 'f': {  /* frontier? */\n          const char *ep; char previous;\n          p += 2;\n          if (*p != '[')\n            luaL_error(ms->L, \"missing \" LUA_QL(\"[\") \" after \"\n                               LUA_QL(\"%%f\") \" in pattern\");\n          ep = classend(ms, p);  /* points to what is next */\n          previous = (s == ms->src_init) ? '\\0' : *(s-1);\n          if (matchbracketclass(uchar(previous), p, ep-1) ||\n             !matchbracketclass(uchar(*s), p, ep-1)) return NULL;\n          p=ep; goto init;  /* else return match(ms, s, ep); */\n        }\n        default: {\n          if (isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p+1)));\n            if (s == NULL) return NULL;\n            p+=2; goto init;  /* else return match(ms, s, p+2) */\n          }\n          goto dflt;  /* case default */\n        }\n      }\n    }\n    case '\\0': {  /* end of pattern */\n      return s;  /* match succeeded */\n    }\n    case '$': {\n      if (*(p+1) == '\\0')  /* is the `$' the last char in pattern? */\n        return (s == ms->src_end) ? s : NULL;  /* check end of string */\n      else goto dflt;\n    }\n    default: dflt: {  /* it is a pattern item */\n      const char *ep = classend(ms, p);  /* points to what is next */\n      int m = s<ms->src_end && singlematch(uchar(*s), p, ep);\n      switch (*ep) {\n        case '?': {  /* optional */\n          const char *res;\n          if (m && ((res=match(ms, s+1, ep+1)) != NULL))\n            return res;\n          p=ep+1; goto init;  /* else return match(ms, s, ep+1); */\n        }\n        case '*': {  /* 0 or more repetitions */\n          return max_expand(ms, s, p, ep);\n        }\n        case '+': {  /* 1 or more repetitions */\n          return (m ? max_expand(ms, s+1, p, ep) : NULL);\n        }\n        case '-': {  /* 0 or more repetitions (minimum) */\n          return min_expand(ms, s, p, ep);\n        }\n        default: {\n          if (!m) return NULL;\n          s++; p=ep; goto init;  /* else return match(ms, s+1, ep); */\n        }\n      }\n    }\n  }\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative `l1' */\n  else {\n    const char *init;  /* to search for a `*s2' inside `s1' */\n    l2--;  /* 1st char will be checked by `memchr' */\n    l1 = l1-l2;  /* `s2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct `l1' and `s1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index\");\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t l1, l2;\n  const char *s = luaL_checklstring(L, 1, &l1);\n  const char *p = luaL_checklstring(L, 2, &l2);\n  ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;\n  if (init < 0) init = 0;\n  else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;\n  if (find && (lua_toboolean(L, 4) ||  /* explicit request? */\n      strpbrk(p, SPECIALS) == NULL)) {  /* or no special characters? */\n    /* do a plain search */\n    const char *s2 = lmemfind(s+init, l1-init, p, l2);\n    if (s2) {\n      lua_pushinteger(L, s2-s+1);\n      lua_pushinteger(L, s2-s+l2);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    int anchor = (*p == '^') ? (p++, 1) : 0;\n    const char *s1=s+init;\n    ms.L = L;\n    ms.src_init = s;\n    ms.src_end = s+l1;\n    do {\n      const char *res;\n      ms.level = 0;\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, s1-s+1);  /* start */\n          lua_pushinteger(L, res-s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\nstatic int gmatch_aux (lua_State *L) {\n  MatchState ms;\n  size_t ls;\n  const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);\n  const char *p = lua_tostring(L, lua_upvalueindex(2));\n  const char *src;\n  ms.L = L;\n  ms.src_init = s;\n  ms.src_end = s+ls;\n  for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));\n       src <= ms.src_end;\n       src++) {\n    const char *e;\n    ms.level = 0;\n    if ((e = match(&ms, src, p)) != NULL) {\n      lua_Integer newstart = e-s;\n      if (e == src) newstart++;  /* empty match? go at least one position */\n      lua_pushinteger(L, newstart);\n      lua_replace(L, lua_upvalueindex(3));\n      return push_captures(&ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  luaL_checkstring(L, 1);\n  luaL_checkstring(L, 2);\n  lua_settop(L, 2);\n  lua_pushinteger(L, 0);\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic int gfind_nodef (lua_State *L) {\n  return luaL_error(L, LUA_QL(\"string.gfind\") \" was renamed to \"\n                       LUA_QL(\"string.gmatch\"));\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  const char *news = lua_tolstring(ms->L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i])))\n        luaL_addchar(b, news[i]);\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                       const char *e) {\n  lua_State *L = ms->L;\n  switch (lua_type(L, 3)) {\n    case LUA_TNUMBER:\n    case LUA_TSTRING: {\n      add_s(ms, b, s, e);\n      return;\n    }\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1)); \n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl;\n  const char *src = luaL_checklstring(L, 1, &srcl);\n  const char *p = luaL_checkstring(L, 2);\n  int  tr = lua_type(L, 3);\n  int max_s = luaL_optint(L, 4, srcl+1);\n  int anchor = (*p == '^') ? (p++, 1) : 0;\n  int n = 0;\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  ms.L = L;\n  ms.src_init = src;\n  ms.src_end = src+srcl;\n  while (n < max_s) {\n    const char *e;\n    ms.level = 0;\n    e = match(&ms, src, p);\n    if (e) {\n      n++;\n      add_value(&ms, &b, src, e);\n    }\n    if (e && e>src) /* non empty match? */\n      src = e;  /* skip it */\n    else if (src < ms.src_end)\n      luaL_addchar(&b, *src++);\n    else break;\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */\n#define MAX_ITEM\t512\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n/*\n** maximum size of each format specification (such as '%-099.99d')\n** (+10 accounts for %99.99x plus margin of error)\n*/\n#define MAX_FORMAT\t(sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)\n\n\nstatic void addquoted (lua_State *L, luaL_Buffer *b, int arg) {\n  size_t l;\n  const char *s = luaL_checklstring(L, arg, &l);\n  luaL_addchar(b, '\"');\n  while (l--) {\n    switch (*s) {\n      case '\"': case '\\\\': case '\\n': {\n        luaL_addchar(b, '\\\\');\n        luaL_addchar(b, *s);\n        break;\n      }\n      case '\\r': {\n        luaL_addlstring(b, \"\\\\r\", 2);\n        break;\n      }\n      case '\\0': {\n        luaL_addlstring(b, \"\\\\000\", 4);\n        break;\n      }\n      default: {\n        luaL_addchar(b, *s);\n        break;\n      }\n    }\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  strncpy(form, strfrmt, p - strfrmt + 1);\n  form += p - strfrmt + 1;\n  *form = '\\0';\n  return p;\n}\n\n\nstatic void addintlen (char *form) {\n  size_t l = strlen(form);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, LUA_INTFRMLEN);\n  form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;\n  form[l + sizeof(LUA_INTFRMLEN) - 1] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format (`%...') */\n      char buff[MAX_ITEM];  /* to store the formatted item */\n      if (++arg > top)\n        luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          sprintf(buff, form, (int)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'd':  case 'i': {\n          addintlen(form);\n          sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'o':  case 'u':  case 'x':  case 'X': {\n          addintlen(form);\n          sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'e':  case 'E': case 'f':\n        case 'g': case 'G': {\n          sprintf(buff, form, (double)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'q': {\n          addquoted(L, &b, arg);\n          continue;  /* skip the 'addsize' at the end */\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_checklstring(L, arg, &l);\n          if (!strchr(form, '.') && l >= 100) {\n            /* no precision and string is too long to be formatted;\n               keep original string */\n            lua_pushvalue(L, arg);\n            luaL_addvalue(&b);\n            continue;  /* skip the `addsize' at the end */\n          }\n          else {\n            sprintf(buff, form, s);\n            break;\n          }\n        }\n        default: {  /* also treat cases `pnLlh' */\n          return luaL_error(L, \"invalid option \" LUA_QL(\"%%%c\") \" to \"\n                               LUA_QL(\"format\"), *(strfrmt - 1));\n        }\n      }\n      luaL_addlstring(&b, buff, strlen(buff));\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gfind\", gfind_nodef},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* create metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);\n  lua_setmetatable(L, -2);  /* set string metatable */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* string library... */\n  lua_setfield(L, -2, \"__index\");  /* ...is the __index metamethod */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUALIB_API int luaopen_string (lua_State *L) {\n  luaL_register(L, LUA_STRLIBNAME, strlib);\n#if defined(LUA_COMPAT_GFIND)\n  lua_getfield(L, -1, \"gmatch\");\n  lua_setfield(L, -2, \"gfind\");\n#endif\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest `n' such that at\n** least half the slots between 0 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the `original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <string.h>\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"ltable.h\"\n\n\n/*\n** max size of array part is 2^MAXBITS\n*/\n#if LUAI_BITSINT > 26\n#define MAXBITS\t\t26\n#else\n#define MAXBITS\t\t(LUAI_BITSINT-2)\n#endif\n\n#define MAXASIZE\t(1 << MAXBITS)\n\n\n#define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))\n  \n#define hashstr(t,str)  hashpow2(t, (str)->tsv.hash)\n#define hashboolean(t,p)        hashpow2(t, p)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, IntPoint(p))\n\n\n/*\n** number of ints inside a lua_Number\n*/\n#define numints\t\tcast_int(sizeof(lua_Number)/sizeof(int))\n\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {{NULL}, LUA_TNIL},  /* value */\n  {{{NULL}, LUA_TNIL, NULL}}  /* key */\n};\n\n\n/*\n** hash for lua_Numbers\n*/\nstatic Node *hashnum (const Table *t, lua_Number n) {\n  unsigned int a[numints];\n  int i;\n  if (luai_numeq(n, 0))  /* avoid problems with -0 */\n    return gnode(t, 0);\n  memcpy(a, &n, sizeof(a));\n  for (i = 1; i < numints; i++) a[0] += a[i];\n  return hashmod(t, a[0]);\n}\n\n\n\n/*\n** returns the `main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMBER:\n      return hashnum(t, nvalue(key));\n    case LUA_TSTRING:\n      return hashstr(t, rawtsvalue(key));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    default:\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for `key' if `key' is an appropriate key to live in\n** the array part of the table, -1 otherwise.\n*/\nstatic int arrayindex (const TValue *key) {\n  if (ttisnumber(key)) {\n    lua_Number n = nvalue(key);\n    int k;\n    lua_number2int(k, n);\n    if (luai_numeq(cast_num(k), n))\n      return k;\n  }\n  return -1;  /* `key' did not match some condition */\n}\n\n\n/*\n** returns the index of a `key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signalled by -1.\n*/\nstatic int findindex (lua_State *L, Table *t, StkId key) {\n  int i;\n  if (ttisnil(key)) return -1;  /* first iteration */\n  i = arrayindex(key);\n  if (0 < i && i <= t->sizearray)  /* is `key' inside array part? */\n    return i-1;  /* yes; that's the index (corrected to C) */\n  else {\n    Node *n = mainposition(t, key);\n    do {  /* check whether `key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in `next' */\n      if (luaO_rawequalObj(key2tval(n), key) ||\n            (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&\n             gcvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return i + t->sizearray;\n      }\n      else n = gnext(n);\n    } while (n);\n    luaG_runerror(L, \"invalid key to \" LUA_QL(\"next\"));  /* key not found */\n    return 0;  /* to avoid warnings */\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  int i = findindex(L, t, key);  /* find original element */\n  for (i++; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setnvalue(key, cast_num(i+1));\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; i < sizenode(t); i++) {  /* then hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, key2tval(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n\nstatic int computesizes (int nums[], int *narray) {\n  int i;\n  int twotoi;  /* 2^i */\n  int a = 0;  /* number of elements smaller than 2^i */\n  int na = 0;  /* number of elements to go to array part */\n  int n = 0;  /* optimal size for array part */\n  for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        n = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements smaller than n will go to array part */\n      }\n    }\n    if (a == *narray) break;  /* all elements already counted */\n  }\n  *narray = n;\n  lua_assert(*narray/2 <= na && na <= *narray);\n  return na;\n}\n\n\nstatic int countint (const TValue *key, int *nums) {\n  int k = arrayindex(key);\n  if (0 < k && k <= MAXASIZE) {  /* is `key' an appropriate array index? */\n    nums[ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\nstatic int numusearray (const Table *t, int *nums) {\n  int lg;\n  int ttlg;  /* 2^lg */\n  int ause = 0;  /* summation of `nums' */\n  int i = 1;  /* count to traverse all array keys */\n  for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) {  /* for each slice */\n    int lc = 0;  /* counter */\n    int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg-1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, int *nums, int *pnasize) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* summation of `nums' */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(key2tval(n), nums);\n      totaluse++;\n    }\n  }\n  *pnasize += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, int size) {\n  int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic void setnodevector (lua_State *L, Table *t, int size) {\n  int lsize;\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common `dummynode' */\n    lsize = 0;\n  }\n  else {\n    int i;\n    lsize = ceillog2(size);\n    if (lsize > MAXBITS)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i=0; i<size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = NULL;\n      setnilvalue(gkey(n));\n      setnilvalue(gval(n));\n    }\n  }\n  t->lsizenode = cast_byte(lsize);\n  t->lastfree = gnode(t, size);  /* all positions are free */\n}\n\n\nstatic void resize (lua_State *L, Table *t, int nasize, int nhsize) {\n  int i;\n  int oldasize = t->sizearray;\n  int oldhsize = t->lsizenode;\n  Node *nold = t->node;  /* save old hash ... */\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  /* create new hash part with appropriate size */\n  setnodevector(L, t, nhsize);  \n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n  /* re-insert elements from hash part */\n  for (i = twoto(oldhsize) - 1; i >= 0; i--) {\n    Node *old = nold+i;\n    if (!ttisnil(gval(old)))\n      setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old));\n  }\n  if (nold != dummynode)\n    luaM_freearray(L, nold, twoto(oldhsize), Node);  /* free old array */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, int nasize) {\n  int nsize = (t->node == dummynode) ? 0 : sizenode(t);\n  resize(L, t, nasize, nsize);\n}\n\n\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  int nasize, na;\n  int nums[MAXBITS+1];  /* nums[i] = number of keys between 2^(i-1) and 2^i */\n  int i;\n  int totaluse;\n  for (i=0; i<=MAXBITS; i++) nums[i] = 0;  /* reset counts */\n  nasize = numusearray(t, nums);  /* count keys in array part */\n  totaluse = nasize;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &nasize);  /* count keys in hash part */\n  /* count extra key */\n  nasize += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  na = computesizes(nums, &nasize);\n  /* resize the table to new computed sizes */\n  resize(L, t, nasize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L, int narray, int nhash) {\n  Table *t = luaM_new(L, Table);\n  luaC_link(L, obj2gco(t), LUA_TTABLE);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  /* temporary values (kept only if some malloc fails) */\n  t->array = NULL;\n  t->sizearray = 0;\n  t->lsizenode = 0;\n  t->node = cast(Node *, dummynode);\n  setarrayvector(L, t, narray);\n  setnodevector(L, t, nhash);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (t->node != dummynode)\n    luaM_freearray(L, t->node, sizenode(t), Node);\n  luaM_freearray(L, t->array, t->sizearray, TValue);\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  while (t->lastfree-- > t->node) {\n    if (ttisnil(gkey(t->lastfree)))\n      return t->lastfree;\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main \n** position is free. If not, check whether colliding node is in its main \n** position or not: if it is not, move colliding node to an empty place and \n** put new key in its main position; otherwise (colliding node is in its main \n** position), new key goes to an empty position. \n*/\nstatic TValue *newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || mp == dummynode) {\n    Node *othern;\n    Node *n = getfreepos(t);  /* get a free place */\n    if (n == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      return luaH_set(L, t, key);  /* re-insert key into grown table */\n    }\n    lua_assert(n != dummynode);\n    othern = mainposition(t, key2tval(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (gnext(othern) != mp) othern = gnext(othern);  /* find previous */\n      gnext(othern) = n;  /* redo the chain with `n' in place of `mp' */\n      *n = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      gnext(mp) = NULL;  /* now `mp' is free */\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      gnext(n) = gnext(mp);  /* chain new position */\n      gnext(mp) = n;\n      mp = n;\n    }\n  }\n  gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;\n  luaC_barriert(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getnum (Table *t, int key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))\n    return &t->array[key-1];\n  else {\n    lua_Number nk = cast_num(key);\n    Node *n = hashnum(t, nk);\n    do {  /* check whether `key' is somewhere in the chain */\n      if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))\n        return gval(n);  /* that's it */\n      else n = gnext(n);\n    } while (n);\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for strings\n*/\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  do {  /* check whether `key' is somewhere in the chain */\n    if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)\n      return gval(n);  /* that's it */\n    else n = gnext(n);\n  } while (n);\n  return luaO_nilobject;\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));\n    case LUA_TNUMBER: {\n      int k;\n      lua_Number n = nvalue(key);\n      lua_number2int(k, n);\n      if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */\n        return luaH_getnum(t, k);  /* use specialized version */\n      /* else go through */\n    }\n    default: {\n      Node *n = mainposition(t, key);\n      do {  /* check whether `key' is somewhere in the chain */\n        if (luaO_rawequalObj(key2tval(n), key))\n          return gval(n);  /* that's it */\n        else n = gnext(n);\n      } while (n);\n      return luaO_nilobject;\n    }\n  }\n}\n\n\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  t->flags = 0;\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n    else if (ttisnumber(key) && luai_numisnan(nvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n    return newkey(L, t, key);\n  }\n}\n\n\nTValue *luaH_setnum (lua_State *L, Table *t, int key) {\n  const TValue *p = luaH_getnum(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    TValue k;\n    setnvalue(&k, cast_num(key));\n    return newkey(L, t, &k);\n  }\n}\n\n\nTValue *luaH_setstr (lua_State *L, Table *t, TString *key) {\n  const TValue *p = luaH_getstr(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    TValue k;\n    setsvalue(L, &k, key);\n    return newkey(L, t, &k);\n  }\n}\n\n\nstatic int unbound_search (Table *t, unsigned int j) {\n  unsigned int i = j;  /* i is zero or a present index */\n  j++;\n  /* find `i' and `j' such that i is present and j is not */\n  while (!ttisnil(luaH_getnum(t, j))) {\n    i = j;\n    j *= 2;\n    if (j > cast(unsigned int, MAX_INT)) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getnum(t, i))) i++;\n      return i - 1;\n    }\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    unsigned int m = (i+j)/2;\n    if (ttisnil(luaH_getnum(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table `t'. A `boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nint luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (t->node == dummynode)  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (Node *n) { return n == dummynode; }\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gkey(n)\t\t(&(n)->i_key.nk)\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n#define key2tval(n)\t(&(n)->i_key.tvk)\n\n\nLUAI_FUNC const TValue *luaH_getnum (Table *t, int key);\nLUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC int luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (Node *n);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#define aux_getn(L,n)\t(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))\n\n\nstatic int foreachi (lua_State *L) {\n  int i;\n  int n = aux_getn(L, 1);\n  luaL_checktype(L, 2, LUA_TFUNCTION);\n  for (i=1; i <= n; i++) {\n    lua_pushvalue(L, 2);  /* function */\n    lua_pushinteger(L, i);  /* 1st argument */\n    lua_rawgeti(L, 1, i);  /* 2nd argument */\n    lua_call(L, 2, 1);\n    if (!lua_isnil(L, -1))\n      return 1;\n    lua_pop(L, 1);  /* remove nil result */\n  }\n  return 0;\n}\n\n\nstatic int foreach (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checktype(L, 2, LUA_TFUNCTION);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pushvalue(L, 2);  /* function */\n    lua_pushvalue(L, -3);  /* key */\n    lua_pushvalue(L, -3);  /* value */\n    lua_call(L, 2, 1);\n    if (!lua_isnil(L, -1))\n      return 1;\n    lua_pop(L, 2);  /* remove value and result */\n  }\n  return 0;\n}\n\n\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n\n\nstatic int getn (lua_State *L) {\n  lua_pushinteger(L, aux_getn(L, 1));\n  return 1;\n}\n\n\nstatic int setn (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n#ifndef luaL_setn\n  luaL_setn(L, 1, luaL_checkint(L, 2));\n#else\n  luaL_error(L, LUA_QL(\"setn\") \" is obsolete\");\n#endif\n  lua_pushvalue(L, 1);\n  return 1;\n}\n\n\nstatic int tinsert (lua_State *L) {\n  int e = aux_getn(L, 1) + 1;  /* first empty element */\n  int pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      int i;\n      pos = luaL_checkint(L, 2);  /* 2nd argument is the position */\n      if (pos > e) e = pos;  /* `grow' array if necessary */\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_rawgeti(L, 1, i-1);\n        lua_rawseti(L, 1, i);  /* t[i] = t[i-1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to \" LUA_QL(\"insert\"));\n    }\n  }\n  luaL_setn(L, 1, e);  /* new size */\n  lua_rawseti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  int e = aux_getn(L, 1);\n  int pos = luaL_optint(L, 2, e);\n  if (!(1 <= pos && pos <= e))  /* position is outside bounds? */\n   return 0;  /* nothing to remove */\n  luaL_setn(L, 1, e - 1);  /* t.n = n-1 */\n  lua_rawgeti(L, 1, pos);  /* result = t[pos] */\n  for ( ;pos<e; pos++) {\n    lua_rawgeti(L, 1, pos+1);\n    lua_rawseti(L, 1, pos);  /* t[pos] = t[pos+1] */\n  }\n  lua_pushnil(L);\n  lua_rawseti(L, 1, e);  /* t[e] = nil */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, int i) {\n  lua_rawgeti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for \"\n                  LUA_QL(\"concat\"), luaL_typename(L, -1), i);\n    luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  size_t lsep;\n  int i, last;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i = luaL_optint(L, 3, 1);\n  last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on `Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n*/\n\n\nstatic void set2 (lua_State *L, int i, int j) {\n  lua_rawseti(L, 1, i);\n  lua_rawseti(L, 1, j);\n}\n\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (!lua_isnil(L, 2)) {  /* function? */\n    int res;\n    lua_pushvalue(L, 2);\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */\n    lua_call(L, 2, 1);\n    res = lua_toboolean(L, -1);\n    lua_pop(L, 1);\n    return res;\n  }\n  else  /* a < b? */\n    return lua_lessthan(L, a, b);\n}\n\nstatic void auxsort (lua_State *L, int l, int u) {\n  while (l < u) {  /* for tail recursion */\n    int i, j;\n    /* sort elements a[l], a[(l+u)/2] and a[u] */\n    lua_rawgeti(L, 1, l);\n    lua_rawgeti(L, 1, u);\n    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */\n      set2(L, l, u);  /* swap a[l] - a[u] */\n    else\n      lua_pop(L, 2);\n    if (u-l == 1) break;  /* only 2 elements */\n    i = (l+u)/2;\n    lua_rawgeti(L, 1, i);\n    lua_rawgeti(L, 1, l);\n    if (sort_comp(L, -2, -1))  /* a[i]<a[l]? */\n      set2(L, i, l);\n    else {\n      lua_pop(L, 1);  /* remove a[l] */\n      lua_rawgeti(L, 1, u);\n      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */\n        set2(L, i, u);\n      else\n        lua_pop(L, 2);\n    }\n    if (u-l == 2) break;  /* only 3 elements */\n    lua_rawgeti(L, 1, i);  /* Pivot */\n    lua_pushvalue(L, -1);\n    lua_rawgeti(L, 1, u-1);\n    set2(L, i, u-1);\n    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */\n    i = l; j = u-1;\n    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */\n      /* repeat ++i until a[i] >= P */\n      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {\n        if (i>u) luaL_error(L, \"invalid order function for sorting\");\n        lua_pop(L, 1);  /* remove a[i] */\n      }\n      /* repeat --j until a[j] <= P */\n      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {\n        if (j<l) luaL_error(L, \"invalid order function for sorting\");\n        lua_pop(L, 1);  /* remove a[j] */\n      }\n      if (j<i) {\n        lua_pop(L, 3);  /* pop pivot, a[i], a[j] */\n        break;\n      }\n      set2(L, i, j);\n    }\n    lua_rawgeti(L, 1, u-1);\n    lua_rawgeti(L, 1, i);\n    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */\n    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */\n    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */\n    if (i-l < u-i) {\n      j=l; i=i-1; l=i+2;\n    }\n    else {\n      j=i+1; i=u; u=j-2;\n    }\n    auxsort(L, j, i);  /* call recursively the smaller one */\n  }  /* repeat the routine for the larger one */\n}\n\nstatic int sort (lua_State *L) {\n  int n = aux_getn(L, 1);\n  luaL_checkstack(L, 40, \"\");  /* assume array is smaller than 2^40 */\n  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n    luaL_checktype(L, 2, LUA_TFUNCTION);\n  lua_settop(L, 2);  /* make sure there is two arguments */\n  auxsort(L, 1, n);\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n  {\"foreach\", foreach},\n  {\"foreachi\", foreachi},\n  {\"getn\", getn},\n  {\"maxn\", maxn},\n  {\"insert\", tinsert},\n  {\"remove\", tremove},\n  {\"setn\", setn},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUALIB_API int luaopen_table (lua_State *L) {\n  luaL_register(L, LUA_TABLIBNAME, tab_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n\nconst char *const luaT_typenames[] = {\n  \"nil\", \"boolean\", \"userdata\", \"number\",\n  \"string\", \"table\", \"function\", \"userdata\", \"thread\",\n  \"proto\", \"upval\"\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__div\", \"__mod\",\n    \"__pow\", \"__unm\", \"__len\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaS_fix(G(L)->tmname[i]);  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttype(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(o)];\n  }\n  return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_EQ,  /* last tag method with `fast' access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_DIV,\n  TM_MOD,\n  TM_POW,\n  TM_UNM,\n  TM_LEN,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\nLUAI_DATA const char *const luaT_typenames[];\n\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lua_c\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);\n  luaL_error(L, \"interrupted!\");\n}\n\n\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,\n                              terminate process (default action) */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (void) {\n  fprintf(stderr,\n  \"usage: %s [options] [script [args]].\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string \" LUA_QL(\"stat\") \"\\n\"\n  \"  -l name  require library \" LUA_QL(\"name\") \"\\n\"\n  \"  -i       enter interactive mode after executing \" LUA_QL(\"script\") \"\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        execute stdin and stop handling options\\n\"\n  ,\n  progname);\n  fflush(stderr);\n}\n\n\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) fprintf(stderr, \"%s: \", pname);\n  fprintf(stderr, \"%s\\n\", msg);\n  fflush(stderr);\n}\n\n\nstatic int report (lua_State *L, int status) {\n  if (status && !lua_isnil(L, -1)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg == NULL) msg = \"(error object is not a string)\";\n    l_message(progname, msg);\n    lua_pop(L, 1);\n  }\n  return status;\n}\n\n\nstatic int traceback (lua_State *L) {\n  if (!lua_isstring(L, 1))  /* 'message' not a string? */\n    return 1;  /* keep it intact */\n  lua_getfield(L, LUA_GLOBALSINDEX, \"debug\");\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    return 1;\n  }\n  lua_getfield(L, -1, \"traceback\");\n  if (!lua_isfunction(L, -1)) {\n    lua_pop(L, 2);\n    return 1;\n  }\n  lua_pushvalue(L, 1);  /* pass error message */\n  lua_pushinteger(L, 2);  /* skip this function and traceback */\n  lua_call(L, 2, 1);  /* call debug.traceback */\n  return 1;\n}\n\n\nstatic int docall (lua_State *L, int narg, int clear) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, traceback);  /* push traceback function */\n  lua_insert(L, base);  /* put it under chunk and args */\n  signal(SIGINT, laction);\n  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n  signal(SIGINT, SIG_DFL);\n  lua_remove(L, base);  /* remove traceback function */\n  /* force a complete garbage collection in case of errors */\n  if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);\n  return status;\n}\n\n\nstatic void print_version (void) {\n  l_message(NULL, LUA_RELEASE \"  \" LUA_COPYRIGHT);\n}\n\n\nstatic int getargs (lua_State *L, char **argv, int n) {\n  int narg;\n  int i;\n  int argc = 0;\n  while (argv[argc]) argc++;  /* count total number of arguments */\n  narg = argc - (n + 1);  /* number of arguments to the script */\n  luaL_checkstack(L, narg + 3, \"too many arguments to script\");\n  for (i=n+1; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  lua_createtable(L, narg, n + 1);\n  for (i=0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - n);\n  }\n  return narg;\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  int status = luaL_loadfile(L, name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\n\nstatic int dolibrary (lua_State *L, const char *name) {\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  return report(L, docall(L, 1, 1));\n}\n\n\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getfield(L, LUA_GLOBALSINDEX, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  lua_pop(L, 1);  /* remove global */\n  return p;\n}\n\n\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    const char *tp = msg + lmsg - (sizeof(LUA_QL(\"<eof>\")) - 1);\n    if (strstr(msg, LUA_QL(\"<eof>\")) == tp) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  if (lua_readline(L, b, prmt) == 0)\n    return 0;  /* no input */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[l-1] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* first line starts with `=' ? */\n    lua_pushfstring(L, \"return %s\", b+1);  /* change it to `return' */\n  else\n    lua_pushstring(L, b);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  for (;;) {  /* repeat until gets a complete line */\n    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), \"=stdin\");\n    if (!incomplete(L, status)) break;  /* cannot try to add lines? */\n    if (!pushline(L, 0))  /* no more input? */\n      return -1;\n    lua_pushliteral(L, \"\\n\");  /* add a new line... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n  lua_saveline(L, 1);\n  lua_remove(L, 1);  /* remove line */\n  return status;\n}\n\n\nstatic void dotty (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;\n  while ((status = loadline(L)) != -1) {\n    if (status == 0) status = docall(L, 0, 0);\n    report(L, status);\n    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */\n      lua_getglobal(L, \"print\");\n      lua_insert(L, 1);\n      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)\n        l_message(progname, lua_pushfstring(L,\n                               \"error calling \" LUA_QL(\"print\") \" (%s)\",\n                               lua_tostring(L, -1)));\n    }\n  }\n  lua_settop(L, 0);  /* clear stack */\n  fputs(\"\\n\", stdout);\n  fflush(stdout);\n  progname = oldprogname;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv, int n) {\n  int status;\n  const char *fname;\n  int narg = getargs(L, argv, n);  /* collect arguments */\n  lua_setglobal(L, \"arg\");\n  fname = argv[n];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[n-1], \"--\") != 0) \n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  lua_insert(L, -(narg+1));\n  if (status == 0)\n    status = docall(L, narg, 0);\n  else\n    lua_pop(L, narg);      \n  return report(L, status);\n}\n\n\n/* check that argument has no extra characters at the end */\n#define notail(x)\t{if ((x)[2] != '\\0') return -1;}\n\n\nstatic int collectargs (char **argv, int *pi, int *pv, int *pe) {\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    if (argv[i][0] != '-')  /* not an option? */\n        return i;\n    switch (argv[i][1]) {  /* option */\n      case '-':\n        notail(argv[i]);\n        return (argv[i+1] != NULL ? i+1 : 0);\n      case '\\0':\n        return i;\n      case 'i':\n        notail(argv[i]);\n        *pi = 1;  /* go through */\n      case 'v':\n        notail(argv[i]);\n        *pv = 1;\n        break;\n      case 'e':\n        *pe = 1;  /* go through */\n      case 'l':\n        if (argv[i][2] == '\\0') {\n          i++;\n          if (argv[i] == NULL) return -1;\n        }\n        break;\n      default: return -1;  /* invalid option */\n    }\n  }\n  return 0;\n}\n\n\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    if (argv[i] == NULL) continue;\n    lua_assert(argv[i][0] == '-');\n    switch (argv[i][1]) {  /* option */\n      case 'e': {\n        const char *chunk = argv[i] + 2;\n        if (*chunk == '\\0') chunk = argv[++i];\n        lua_assert(chunk != NULL);\n        if (dostring(L, chunk, \"=(command line)\") != 0)\n          return 1;\n        break;\n      }\n      case 'l': {\n        const char *filename = argv[i] + 2;\n        if (*filename == '\\0') filename = argv[++i];\n        lua_assert(filename != NULL);\n        if (dolibrary(L, filename))\n          return 1;  /* stop if file fails */\n        break;\n      }\n      default: break;\n    }\n  }\n  return 0;\n}\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *init = getenv(LUA_INIT);\n  if (init == NULL) return 0;  /* status OK */\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, \"=\" LUA_INIT);\n}\n\n\nstruct Smain {\n  int argc;\n  char **argv;\n  int status;\n};\n\n\nstatic int pmain (lua_State *L) {\n  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);\n  char **argv = s->argv;\n  int script;\n  int has_i = 0, has_v = 0, has_e = 0;\n  globalL = L;\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */\n  luaL_openlibs(L);  /* open libraries */\n  lua_gc(L, LUA_GCRESTART, 0);\n  s->status = handle_luainit(L);\n  if (s->status != 0) return 0;\n  script = collectargs(argv, &has_i, &has_v, &has_e);\n  if (script < 0) {  /* invalid args? */\n    print_usage();\n    s->status = 1;\n    return 0;\n  }\n  if (has_v) print_version();\n  s->status = runargs(L, argv, (script > 0) ? script : s->argc);\n  if (s->status != 0) return 0;\n  if (script)\n    s->status = handle_script(L, argv, script);\n  if (s->status != 0) return 0;\n  if (has_i)\n    dotty(L);\n  else if (script == 0 && !has_e && !has_v) {\n    if (lua_stdin_is_tty()) {\n      print_version();\n      dotty(L);\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  return 0;\n}\n\n\nint main (int argc, char **argv) {\n  int status;\n  struct Smain s;\n  lua_State *L = lua_open();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  s.argc = argc;\n  s.argv = argv;\n  status = lua_cpcall(L, &pmain, &s);\n  report(L, status);\n  lua_close(L);\n  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $\n** Lua - An Extensible Extension Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION\t\"Lua 5.1\"\n#define LUA_RELEASE\t\"Lua 5.1.5\"\n#define LUA_VERSION_NUM\t501\n#define LUA_COPYRIGHT\t\"Copyright (C) 1994-2012 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS \t\"R. Ierusalimschy, L. H. de Figueiredo & W. Celes\"\n\n\n/* mark for precompiled code (`<esc>Lua') */\n#define\tLUA_SIGNATURE\t\"\\033Lua\"\n\n/* option for multiple returns in `lua_pcall' and `lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** pseudo-indices\n*/\n#define LUA_REGISTRYINDEX\t(-10000)\n#define LUA_ENVIRONINDEX\t(-10001)\n#define LUA_GLOBALSINDEX\t(-10002)\n#define lua_upvalueindex(i)\t(LUA_GLOBALSINDEX-(i))\n\n\n/* thread status; 0 is OK */\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\n\ntypedef int (*lua_CFunction) (lua_State *L);\n\n\n/*\n** functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);\n\n\n/*\n** prototype for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_remove) (lua_State *L, int idx);\nLUA_API void  (lua_insert) (lua_State *L, int idx);\nLUA_API void  (lua_replace) (lua_State *L, int idx);\nLUA_API int   (lua_checkstack) (lua_State *L, int sz);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);\n\nLUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);\nLUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_objlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void  (lua_pushnil) (lua_State *L);\nLUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);\nLUA_API void  (lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API void  (lua_gettable) (lua_State *L, int idx);\nLUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawget) (lua_State *L, int idx);\nLUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_getfenv) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setfenv) (lua_State *L, int idx);\n\n\n/*\n** `load' and `call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);\nLUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);\nLUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                                        const char *chunkname);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yield) (lua_State *L, int nresults);\nLUA_API int  (lua_resume) (lua_State *L, int narg);\nLUA_API int  (lua_status) (lua_State *L);\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/* \n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_strlen(L,i)\t\tlua_objlen(L, (i))\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\t\\\n\tlua_pushlstring(L, \"\" s, (sizeof(s)/sizeof(char))-1)\n\n#define lua_setglobal(L,s)\tlua_setfield(L, LUA_GLOBALSINDEX, (s))\n#define lua_getglobal(L,s)\tlua_getfield(L, LUA_GLOBALSINDEX, (s))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n\n/*\n** compatibility macros and functions\n*/\n\n#define lua_open()\tluaL_newstate()\n\n#define lua_getregistry(L)\tlua_pushvalue(L, LUA_REGISTRYINDEX)\n\n#define lua_getgccount(L)\tlua_gc(L, LUA_GCCOUNT, 0)\n\n#define lua_Chunkreader\t\tlua_Reader\n#define lua_Chunkwriter\t\tlua_Writer\n\n\n/* hack */\nLUA_API void lua_setlevel\t(lua_State *from, lua_State *to);\n\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILRET 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debuger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);\n\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook lua_gethook (lua_State *L);\nLUA_API int lua_gethookmask (lua_State *L);\nLUA_API int lua_gethookcount (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) `global', `local', `field', `method' */\n  const char *what;\t/* (S) `Lua', `C', `main', `tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int nups;\t\t/* (u) number of upvalues */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  int i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2012 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $\n** Lua compiler (saves bytecodes to files; also list bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define\tOUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option \" LUA_QS \"\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n \"usage: %s [options] [filenames].\\n\"\n \"Available options are:\\n\"\n \"  -        process stdin\\n\"\n \"  -l       list\\n\"\n \"  -o name  output to file \" LUA_QL(\"name\") \" (default is \\\"%s\\\")\\n\"\n \"  -p       parse only\\n\"\n \"  -s       strip debug information\\n\"\n \"  -v       show version information\\n\"\n \"  --       stop handling options\\n\",\n progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define\tIS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0) usage(LUA_QL(\"-o\") \" needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s  %s\\n\",LUA_RELEASE,LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define toproto(L,i) (clvalue(L->top+(i))->l.p)\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  int i,pc;\n  Proto* f=luaF_newproto(L);\n  setptvalue2s(L,L->top,f); incr_top(L);\n  f->source=luaS_newliteral(L,\"=(\" PROGNAME \")\");\n  f->maxstacksize=1;\n  pc=2*n+1;\n  f->code=luaM_newvector(L,pc,Instruction);\n  f->sizecode=pc;\n  f->p=luaM_newvector(L,n,Proto*);\n  f->sizep=n;\n  pc=0;\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);\n   f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);\n  }\n  f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstruct Smain {\n int argc;\n char** argv;\n};\n\nstatic int pmain(lua_State* L)\n{\n struct Smain* s = (struct Smain*)lua_touserdata(L, 1);\n int argc=s->argc;\n char** argv=s->argv;\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n struct Smain s;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=lua_open();\n if (L==NULL) fatal(\"not enough memory for state\");\n s.argc=argc;\n s.argv=argv;\n if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "build/lua-5.1.5/src/luaconf.h",
    "content": "/*\n** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lconfig_h\n#define lconfig_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ==================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n@@ LUA_ANSI controls the use of non-ansi features.\n** CHANGE it (define it) if you want Lua to avoid the use of any\n** non-ansi feature or library.\n*/\n#if defined(__STRICT_ANSI__)\n#define LUA_ANSI\n#endif\n\n\n#if !defined(LUA_ANSI) && defined(_WIN32)\n#define LUA_WIN\n#endif\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_DL_DYLD\t\t/* does not need extra library */\n#endif\n\n\n\n/*\n@@ LUA_USE_POSIX includes all functionallity listed as X/Open System\n@* Interfaces Extension (XSI).\n** CHANGE it (define it) if your system is XSI compatible.\n*/\n#if defined(LUA_USE_POSIX)\n#define LUA_USE_MKSTEMP\n#define LUA_USE_ISATTY\n#define LUA_USE_POPEN\n#define LUA_USE_ULONGJMP\n#endif\n\n\n/*\n@@ LUA_PATH and LUA_CPATH are the names of the environment variables that\n@* Lua check to set its paths.\n@@ LUA_INIT is the name of the environment variable that Lua\n@* checks for initialization code.\n** CHANGE them if you want different names.\n*/\n#define LUA_PATH        \"LUA_PATH\"\n#define LUA_CPATH       \"LUA_CPATH\"\n#define LUA_INIT\t\"LUA_INIT\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n@* Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n@* C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#if defined(_WIN32)\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\".\\\\?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\t             LUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\".\\\\?.dll;\"  LUA_CDIR\"?.dll;\" LUA_CDIR\"loadall.dll\"\n\n#else\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/5.1/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/5.1/\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\"./?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\t            LUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\"./?.so;\"  LUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so\"\n#endif\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n\n/*\n@@ LUA_PATHSEP is the character that separates templates in a path.\n@@ LUA_PATH_MARK is the string that marks the substitution points in a\n@* template.\n@@ LUA_EXECDIR in a Windows path is replaced by the executable's\n@* directory.\n@@ LUA_IGMARK is a mark to ignore all before it when bulding the\n@* luaopen_ function name.\n** CHANGE them if for some reason your system cannot use those\n** characters. (E.g., if one of those characters is a common character\n** in file/directory names.) Probably you do not need to change them.\n*/\n#define LUA_PATHSEP\t\";\"\n#define LUA_PATH_MARK\t\"?\"\n#define LUA_EXECDIR\t\"!\"\n#define LUA_IGMARK\t\"-\"\n\n\n/*\n@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.\n** CHANGE that if ptrdiff_t is not adequate on your machine. (On most\n** machines, ptrdiff_t gives a good choice between int or long.)\n*/\n#define LUA_INTEGER\tptrdiff_t\n\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all standard library functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\n#define LUA_API __declspec(dllexport)\n#else\n#define LUA_API __declspec(dllimport)\n#endif\n\n#else\n\n#define LUA_API\t\textern\n\n#endif\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n@* exported to outside modules.\n@@ LUAI_DATA is a mark for all extern (const) variables that are not to\n@* be exported to outside modules.\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library.\n*/\n#if defined(luaall_c)\n#define LUAI_FUNC\tstatic\n#define LUAI_DATA\t/* empty */\n\n#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n      defined(__ELF__)\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#define LUAI_DATA\tLUAI_FUNC\n\n#else\n#define LUAI_FUNC\textern\n#define LUAI_DATA\textern\n#endif\n\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** CHANGE it if you want a different appearance.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@* of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#define LUA_IDSIZE\t150\n\n\n/*\n** {==================================================================\n** Stand-alone configuration\n** ===================================================================\n*/\n\n#if defined(lua_c) || defined(luaall_c)\n\n/*\n@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n@* is, whether we're running lua interactively).\n** CHANGE it if you have a better definition for non-POSIX/non-Windows\n** systems.\n*/\n#if defined(LUA_USE_ISATTY)\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n#elif defined(LUA_WIN)\n#include <io.h>\n#include <stdio.h>\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n#else\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n#endif\n\n\n/*\n@@ LUA_PROMPT is the default prompt used by stand-alone Lua.\n@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.\n** CHANGE them if you want different prompts. (You can also change the\n** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)\n*/\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n\n\n/*\n@@ LUA_PROGNAME is the default name for the stand-alone Lua program.\n** CHANGE it if your stand-alone interpreter has a different name and\n** your system is not able to detect that name automatically.\n*/\n#define LUA_PROGNAME\t\t\"lua\"\n\n\n/*\n@@ LUA_MAXINPUT is the maximum length for an input line in the\n@* stand-alone interpreter.\n** CHANGE it if you need longer lines.\n*/\n#define LUA_MAXINPUT\t512\n\n\n/*\n@@ lua_readline defines how to show a prompt and then read a line from\n@* the standard input.\n@@ lua_saveline defines how to \"save\" a read line in a \"history\".\n@@ lua_freeline defines how to free a line read by lua_readline.\n** CHANGE them if you want to improve this functionality (e.g., by using\n** GNU readline and history facilities).\n*/\n#if defined(LUA_USE_READLINE)\n#include <stdio.h>\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,idx) \\\n\tif (lua_strlen(L,idx) > 0)  /* non-empty line? */ \\\n\t  add_history(lua_tostring(L, idx));  /* add it to history */\n#define lua_freeline(L,b)\t((void)L, free(b))\n#else\n#define lua_readline(L,b,p)\t\\\n\t((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n\tfgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,idx)\t{ (void)L; (void)idx; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n#endif\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles\n@* as a percentage.\n** CHANGE it if you want the GC to run faster or slower (higher values\n** mean larger pauses which mean slower collection.) You can also change\n** this value dynamically.\n*/\n#define LUAI_GCPAUSE\t200  /* 200% (wait memory to double before next GC) */\n\n\n/*\n@@ LUAI_GCMUL defines the default speed of garbage collection relative to\n@* memory allocation as a percentage.\n** CHANGE it if you want to change the granularity of the garbage\n** collection. (Higher values mean coarser collections. 0 represents\n** infinity, where each step performs a full collection.) You can also\n** change this value dynamically.\n*/\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n\n\n\n/*\n@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.\n** CHANGE it (define it) if you want exact compatibility with the\n** behavior of setn/getn in Lua 5.0.\n*/\n#undef LUA_COMPAT_GETN\n\n/*\n@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.\n** CHANGE it to undefined as soon as you do not need a global 'loadlib'\n** function (the function is still available as 'package.loadlib').\n*/\n#undef LUA_COMPAT_LOADLIB\n\n/*\n@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.\n** CHANGE it to undefined as soon as your programs use only '...' to\n** access vararg parameters (instead of the old 'arg' table).\n*/\n#define LUA_COMPAT_VARARG\n\n/*\n@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.\n** CHANGE it to undefined as soon as your programs use 'math.fmod' or\n** the new '%' operator instead of 'math.mod'.\n*/\n#define LUA_COMPAT_MOD\n\n/*\n@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting\n@* facility.\n** CHANGE it to 2 if you want the old behaviour, or undefine it to turn\n** off the advisory error when nesting [[...]].\n*/\n#define LUA_COMPAT_LSTR\t\t1\n\n/*\n@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.\n** CHANGE it to undefined as soon as you rename 'string.gfind' to\n** 'string.gmatch'.\n*/\n#define LUA_COMPAT_GFIND\n\n/*\n@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'\n@* behavior.\n** CHANGE it to undefined as soon as you replace to 'luaL_register'\n** your uses of 'luaL_openlib'\n*/\n#define LUA_COMPAT_OPENLIB\n\n\n\n/*\n@@ luai_apicheck is the assert macro used by the Lua-C API.\n** CHANGE luai_apicheck if you want Lua to perform some checks in the\n** parameters it gets from API calls. This may slow down the interpreter\n** a bit, but may be quite useful when debugging C code that interfaces\n** with Lua. A useful redefinition is to use assert.h.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(L,o)\t{ (void)L; assert(o); }\n#else\n#define luai_apicheck(L,o)\t{ (void)L; }\n#endif\n\n\n/*\n@@ LUAI_BITSINT defines the number of bits in an int.\n** CHANGE here if Lua cannot automatically detect the number of bits of\n** your machine. Probably you do not need to change this.\n*/\n/* avoid overflows in comparison */\n#if INT_MAX-20 < 32760\n#define LUAI_BITSINT\t16\n#elif INT_MAX > 2147483640L\n/* int has at least 32 bits */\n#define LUAI_BITSINT\t32\n#else\n#error \"you must define LUA_BITSINT with number of bits in an integer\"\n#endif\n\n\n/*\n@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.\n@@ LUAI_INT32 is an signed integer with at least 32 bits.\n@@ LUAI_UMEM is an unsigned integer big enough to count the total\n@* memory used by Lua.\n@@ LUAI_MEM is a signed integer big enough to count the total memory\n@* used by Lua.\n** CHANGE here if for some weird reason the default definitions are not\n** good enough for your machine. (The definitions in the 'else'\n** part always works, but may waste space on machines with 64-bit\n** longs.) Probably you do not need to change this.\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_UINT32\tunsigned int\n#define LUAI_INT32\tint\n#define LUAI_MAXINT32\tINT_MAX\n#define LUAI_UMEM\tsize_t\n#define LUAI_MEM\tptrdiff_t\n#else\n/* 16-bit ints */\n#define LUAI_UINT32\tunsigned long\n#define LUAI_INT32\tlong\n#define LUAI_MAXINT32\tLONG_MAX\n#define LUAI_UMEM\tunsigned long\n#define LUAI_MEM\tlong\n#endif\n\n\n/*\n@@ LUAI_MAXCALLS limits the number of nested calls.\n** CHANGE it if you need really deep recursive calls. This limit is\n** arbitrary; its only purpose is to stop infinite recursion before\n** exhausting memory.\n*/\n#define LUAI_MAXCALLS\t20000\n\n\n/*\n@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function\n@* can use.\n** CHANGE it if you need lots of (Lua) stack space for your C\n** functions. This limit is arbitrary; its only purpose is to stop C\n** functions to consume unlimited stack space. (must be smaller than\n** -LUA_REGISTRYINDEX)\n*/\n#define LUAI_MAXCSTACK\t8000\n\n\n\n/*\n** {==================================================================\n** CHANGE (to smaller values) the following definitions if your system\n** has a small C stack. (Or you may want to change them to larger\n** values if your system has a large C stack and these limits are\n** too rigid for you.) Some of these constants control the size of\n** stack-allocated arrays used by the compiler or the interpreter, while\n** others limit the maximum number of recursive calls that the compiler\n** or the interpreter can perform. Values too large may cause a C stack\n** overflow for some forms of deep constructs.\n** ===================================================================\n*/\n\n\n/*\n@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and\n@* syntactical nested non-terminals in a program.\n*/\n#define LUAI_MAXCCALLS\t\t200\n\n\n/*\n@@ LUAI_MAXVARS is the maximum number of local variables per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXVARS\t\t200\n\n\n/*\n@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXUPVALUES\t60\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n*/\n#define LUAL_BUFFERSIZE\t\tBUFSIZ\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n@@ LUA_NUMBER is the type of numbers in Lua.\n** CHANGE the following definitions only if you want to build Lua\n** with a number type different from double. You may also need to\n** change lua_number2int & lua_number2integer.\n** ===================================================================\n*/\n\n#define LUA_NUMBER_DOUBLE\n#define LUA_NUMBER\tdouble\n\n/*\n@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'\n@* over a number.\n*/\n#define LUAI_UACNUMBER\tdouble\n\n\n/*\n@@ LUA_NUMBER_SCAN is the format for reading numbers.\n@@ LUA_NUMBER_FMT is the format for writing numbers.\n@@ lua_number2str converts a number to a string.\n@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.\n@@ lua_str2number converts a string to a number.\n*/\n#define LUA_NUMBER_SCAN\t\t\"%lf\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n#define lua_number2str(s,n)\tsprintf((s), LUA_NUMBER_FMT, (n))\n#define LUAI_MAXNUMBER2STR\t32 /* 16 digits, sign, point, and \\0 */\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n\n/*\n@@ The luai_num* macros define the primitive operations over numbers.\n*/\n#if defined(LUA_CORE)\n#include <math.h>\n#define luai_numadd(a,b)\t((a)+(b))\n#define luai_numsub(a,b)\t((a)-(b))\n#define luai_nummul(a,b)\t((a)*(b))\n#define luai_numdiv(a,b)\t((a)/(b))\n#define luai_nummod(a,b)\t((a) - floor((a)/(b))*(b))\n#define luai_numpow(a,b)\t(pow(a,b))\n#define luai_numunm(a)\t\t(-(a))\n#define luai_numeq(a,b)\t\t((a)==(b))\n#define luai_numlt(a,b)\t\t((a)<(b))\n#define luai_numle(a,b)\t\t((a)<=(b))\n#define luai_numisnan(a)\t(!luai_numeq((a), (a)))\n#endif\n\n\n/*\n@@ lua_number2int is a macro to convert lua_Number to int.\n@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.\n** CHANGE them if you know a faster way to convert a lua_Number to\n** int (with any rounding method and without throwing errors) in your\n** system. In Pentium machines, a naive typecast from double to int\n** in C is extremely slow, so any alternative is worth trying.\n*/\n\n/* On a Pentium, resort to a trick */\n#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \\\n    (defined(__i386) || defined (_M_IX86) || defined(__i386__))\n\n/* On a Microsoft compiler, use assembler */\n#if defined(_MSC_VER)\n\n#define lua_number2int(i,d)   __asm fld d   __asm fistp i\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n/* the next trick should work on any Pentium, but sometimes clashes\n   with a DirectX idiosyncrasy */\n#else\n\nunion luai_Cast { double l_d; long l_l; };\n#define lua_number2int(i,d) \\\n  { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n#endif\n\n\n/* this option always works, but may be slow */\n#else\n#define lua_number2int(i,d)\t((i)=(int)(d))\n#define lua_number2integer(i,d)\t((i)=(lua_Integer)(d))\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.\n** CHANGE it if your system requires alignments larger than double. (For\n** instance, if your system supports long doubles and they must be\n** aligned in 16-byte boundaries, then you should add long double in the\n** union.) Probably you do not need to change this.\n*/\n#define LUAI_USER_ALIGNMENT_T\tunion { double u; void *s; long l; }\n\n\n/*\n@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.\n** CHANGE them if you prefer to use longjmp/setjmp even with C++\n** or if want/don't to use _longjmp/_setjmp instead of regular\n** longjmp/setjmp. By default, Lua handles errors with exceptions when\n** compiling as C++ code, with _longjmp/_setjmp when asked to use them,\n** and with longjmp/setjmp otherwise.\n*/\n#if defined(__cplusplus)\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\tthrow(c)\n#define LUAI_TRY(L,c,a)\ttry { a } catch(...) \\\n\t{ if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\tint  /* dummy variable */\n\n#elif defined(LUA_USE_ULONGJMP)\n/* in Unix, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#else\n/* default handling with long jumps */\n#define LUAI_THROW(L,c)\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#endif\n\n\n/*\n@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern\n@* can do during pattern-matching.\n** CHANGE it if you need more captures. This limit is arbitrary.\n*/\n#define LUA_MAXCAPTURES\t\t32\n\n\n/*\n@@ lua_tmpnam is the function that the OS library uses to create a\n@* temporary name.\n@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.\n** CHANGE them if you have an alternative to tmpnam (which is considered\n** insecure) or if you want the original tmpnam anyway.  By default, Lua\n** uses tmpnam except when POSIX is available, where it uses mkstemp.\n*/\n#if defined(loslib_c) || defined(luaall_c)\n\n#if defined(LUA_USE_MKSTEMP)\n#include <unistd.h>\n#define LUA_TMPNAMBUFSIZE\t32\n#define lua_tmpnam(b,e)\t{ \\\n\tstrcpy(b, \"/tmp/lua_XXXXXX\"); \\\n\te = mkstemp(b); \\\n\tif (e != -1) close(e); \\\n\te = (e == -1); }\n\n#else\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n#endif\n\n#endif\n\n\n/*\n@@ lua_popen spawns a new process connected to the current one through\n@* the file streams.\n** CHANGE it if you have a way to implement it in your system.\n*/\n#if defined(LUA_USE_POPEN)\n\n#define lua_popen(L,c,m)\t((void)L, fflush(NULL), popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (pclose(file) != -1))\n\n#elif defined(LUA_WIN)\n\n#define lua_popen(L,c,m)\t((void)L, _popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (_pclose(file) != -1))\n\n#else\n\n#define lua_popen(L,c,m)\t((void)((void)c, m),  \\\n\t\tluaL_error(L, LUA_QL(\"popen\") \" not supported\"), (FILE*)0)\n#define lua_pclose(L,file)\t\t((void)((void)L, file), 0)\n\n#endif\n\n/*\n@@ LUA_DL_* define which dynamic-library system Lua should use.\n** CHANGE here if Lua has problems choosing the appropriate\n** dynamic-library system for your platform (either Windows' DLL, Mac's\n** dyld, or Unix's dlopen). If your system is some kind of Unix, there\n** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for\n** it.  To use dlopen you also need to adapt the src/Makefile (probably\n** adding -ldl to the linker options), so Lua does not select it\n** automatically.  (When you change the makefile to add -ldl, you must\n** also add -DLUA_USE_DLOPEN.)\n** If you do not want any kind of dynamic library, undefine all these\n** options.\n** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.\n*/\n#if defined(LUA_USE_DLOPEN)\n#define LUA_DL_DLOPEN\n#endif\n\n#if defined(LUA_WIN)\n#define LUA_DL_DLL\n#endif\n\n\n/*\n@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State\n@* (the data goes just *before* the lua_State pointer).\n** CHANGE (define) this if you really need that. This value must be\n** a multiple of the maximum alignment required for your machine.\n*/\n#define LUAI_EXTRASPACE\t\t0\n\n\n/*\n@@ luai_userstate* allow user-specific actions on threads.\n** CHANGE them if you defined LUAI_EXTRASPACE and need to do something\n** extra when a thread is created/deleted/resumed/yielded.\n*/\n#define luai_userstateopen(L)\t\t((void)L)\n#define luai_userstateclose(L)\t\t((void)L)\n#define luai_userstatethread(L,L1)\t((void)L)\n#define luai_userstatefree(L)\t\t((void)L)\n#define luai_userstateresume(L,n)\t((void)L)\n#define luai_userstateyield(L,n)\t((void)L)\n\n\n/*\n@@ LUA_INTFRMLEN is the length modifier for integer conversions\n@* in 'string.format'.\n@@ LUA_INTFRM_T is the integer type correspoding to the previous length\n@* modifier.\n** CHANGE them if your system supports long long or does not support long.\n*/\n\n#if defined(LUA_USELONGLONG)\n\n#define LUA_INTFRMLEN\t\t\"ll\"\n#define LUA_INTFRM_T\t\tlong long\n\n#else\n\n#define LUA_INTFRMLEN\t\t\"l\"\n#define LUA_INTFRM_T\t\tlong\n\n#endif\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* Key to file-handle type */\n#define LUA_FILEHANDLE\t\t\"FILE*\"\n\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUALIB_API int (luaopen_base) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUALIB_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUALIB_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUALIB_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUALIB_API int (luaopen_string) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUALIB_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUALIB_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUALIB_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L); \n\n\n\n#ifndef lua_assert\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#include <string.h>\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\ntypedef struct {\n lua_State* L;\n ZIO* Z;\n Mbuffer* b;\n const char* name;\n} LoadState;\n\n#ifdef LUAC_TRUST_BINARIES\n#define IF(c,s)\n#define error(S,s)\n#else\n#define IF(c,s)\t\tif (c) error(S,s)\n\nstatic void error(LoadState* S, const char* why)\n{\n luaO_pushfstring(S->L,\"%s: %s in precompiled chunk\",S->name,why);\n luaD_throw(S->L,LUA_ERRSYNTAX);\n}\n#endif\n\n#define LoadMem(S,b,n,size)\tLoadBlock(S,b,(n)*(size))\n#define\tLoadByte(S)\t\t(lu_byte)LoadChar(S)\n#define LoadVar(S,x)\t\tLoadMem(S,&x,1,sizeof(x))\n#define LoadVector(S,b,n,size)\tLoadMem(S,b,n,size)\n\nstatic void LoadBlock(LoadState* S, void* b, size_t size)\n{\n size_t r=luaZ_read(S->Z,b,size);\n IF (r!=0, \"unexpected end\");\n}\n\nstatic int LoadChar(LoadState* S)\n{\n char x;\n LoadVar(S,x);\n return x;\n}\n\nstatic int LoadInt(LoadState* S)\n{\n int x;\n LoadVar(S,x);\n IF (x<0, \"bad integer\");\n return x;\n}\n\nstatic lua_Number LoadNumber(LoadState* S)\n{\n lua_Number x;\n LoadVar(S,x);\n return x;\n}\n\nstatic TString* LoadString(LoadState* S)\n{\n size_t size;\n LoadVar(S,size);\n if (size==0)\n  return NULL;\n else\n {\n  char* s=luaZ_openspace(S->L,S->b,size);\n  LoadBlock(S,s,size);\n  return luaS_newlstr(S->L,s,size-1);\t\t/* remove trailing '\\0' */\n }\n}\n\nstatic void LoadCode(LoadState* S, Proto* f)\n{\n int n=LoadInt(S);\n f->code=luaM_newvector(S->L,n,Instruction);\n f->sizecode=n;\n LoadVector(S,f->code,n,sizeof(Instruction));\n}\n\nstatic Proto* LoadFunction(LoadState* S, TString* p);\n\nstatic void LoadConstants(LoadState* S, Proto* f)\n{\n int i,n;\n n=LoadInt(S);\n f->k=luaM_newvector(S->L,n,TValue);\n f->sizek=n;\n for (i=0; i<n; i++) setnilvalue(&f->k[i]);\n for (i=0; i<n; i++)\n {\n  TValue* o=&f->k[i];\n  int t=LoadChar(S);\n  switch (t)\n  {\n   case LUA_TNIL:\n   \tsetnilvalue(o);\n\tbreak;\n   case LUA_TBOOLEAN:\n   \tsetbvalue(o,LoadChar(S)!=0);\n\tbreak;\n   case LUA_TNUMBER:\n\tsetnvalue(o,LoadNumber(S));\n\tbreak;\n   case LUA_TSTRING:\n\tsetsvalue2n(S->L,o,LoadString(S));\n\tbreak;\n   default:\n\terror(S,\"bad constant\");\n\tbreak;\n  }\n }\n n=LoadInt(S);\n f->p=luaM_newvector(S->L,n,Proto*);\n f->sizep=n;\n for (i=0; i<n; i++) f->p[i]=NULL;\n for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);\n}\n\nstatic void LoadDebug(LoadState* S, Proto* f)\n{\n int i,n;\n n=LoadInt(S);\n f->lineinfo=luaM_newvector(S->L,n,int);\n f->sizelineinfo=n;\n LoadVector(S,f->lineinfo,n,sizeof(int));\n n=LoadInt(S);\n f->locvars=luaM_newvector(S->L,n,LocVar);\n f->sizelocvars=n;\n for (i=0; i<n; i++) f->locvars[i].varname=NULL;\n for (i=0; i<n; i++)\n {\n  f->locvars[i].varname=LoadString(S);\n  f->locvars[i].startpc=LoadInt(S);\n  f->locvars[i].endpc=LoadInt(S);\n }\n n=LoadInt(S);\n f->upvalues=luaM_newvector(S->L,n,TString*);\n f->sizeupvalues=n;\n for (i=0; i<n; i++) f->upvalues[i]=NULL;\n for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);\n}\n\nstatic Proto* LoadFunction(LoadState* S, TString* p)\n{\n Proto* f;\n if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,\"code too deep\");\n f=luaF_newproto(S->L);\n setptvalue2s(S->L,S->L->top,f); incr_top(S->L);\n f->source=LoadString(S); if (f->source==NULL) f->source=p;\n f->linedefined=LoadInt(S);\n f->lastlinedefined=LoadInt(S);\n f->nups=LoadByte(S);\n f->numparams=LoadByte(S);\n f->is_vararg=LoadByte(S);\n f->maxstacksize=LoadByte(S);\n LoadCode(S,f);\n LoadConstants(S,f);\n LoadDebug(S,f);\n IF (!luaG_checkcode(f), \"bad code\");\n S->L->top--;\n S->L->nCcalls--;\n return f;\n}\n\nstatic void LoadHeader(LoadState* S)\n{\n char h[LUAC_HEADERSIZE];\n char s[LUAC_HEADERSIZE];\n luaU_header(h);\n LoadBlock(S,s,LUAC_HEADERSIZE);\n IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, \"bad header\");\n}\n\n/*\n** load precompiled chunk\n*/\nProto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)\n{\n LoadState S;\n if (*name=='@' || *name=='=')\n  S.name=name+1;\n else if (*name==LUA_SIGNATURE[0])\n  S.name=\"binary string\";\n else\n  S.name=name;\n S.L=L;\n S.Z=Z;\n S.b=buff;\n LoadHeader(&S);\n return LoadFunction(&S,luaS_newliteral(L,\"=?\"));\n}\n\n/*\n* make header\n*/\nvoid luaU_header (char* h)\n{\n int x=1;\n memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);\n h+=sizeof(LUA_SIGNATURE)-1;\n *h++=(char)LUAC_VERSION;\n *h++=(char)LUAC_FORMAT;\n *h++=(char)*(char*)&x;\t\t\t\t/* endianness */\n *h++=(char)sizeof(int);\n *h++=(char)sizeof(size_t);\n *h++=(char)sizeof(Instruction);\n *h++=(char)sizeof(lua_Number);\n *h++=(char)(((lua_Number)0.5)==0);\t\t/* is lua_Number integral? */\n}\n"
  },
  {
    "path": "build/lua-5.1.5/src/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);\n\n/* make header; from lundump.c */\nLUAI_FUNC void luaU_header (char* h);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);\n\n#ifdef luac_c\n/* print one chunk; from print.c */\nLUAI_FUNC void luaU_print (const Proto* f, int full);\n#endif\n\n/* for header of binary files -- this is Lua 5.1 */\n#define LUAC_VERSION\t\t0x51\n\n/* for header of binary files -- this is the official format */\n#define LUAC_FORMAT\t\t0\n\n/* size of header of binary files */\n#define LUAC_HEADERSIZE\t\t12\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.63.1.5 2011/08/17 20:43:11 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t100\n\n\nconst TValue *luaV_tonumber (const TValue *obj, TValue *n) {\n  lua_Number num;\n  if (ttisnumber(obj)) return obj;\n  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {\n    setnvalue(n, num);\n    return n;\n  }\n  else\n    return NULL;\n}\n\n\nint luaV_tostring (lua_State *L, StkId obj) {\n  if (!ttisnumber(obj))\n    return 0;\n  else {\n    char s[LUAI_MAXNUMBER2STR];\n    lua_Number n = nvalue(obj);\n    lua_number2str(s, n);\n    setsvalue2s(L, obj, luaS_new(L, s));\n    return 1;\n  }\n}\n\n\nstatic void traceexec (lua_State *L, const Instruction *pc) {\n  lu_byte mask = L->hookmask;\n  const Instruction *oldpc = L->savedpc;\n  L->savedpc = pc;\n  if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {\n    resethookcount(L);\n    luaD_callhook(L, LUA_HOOKCOUNT, -1);\n  }\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(L->ci)->l.p;\n    int npc = pcRel(pc, p);\n    int newline = getline(p, npc);\n    /* call linehook when enter a new function, when jump back (loop),\n       or when enter a new line */\n    if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p)))\n      luaD_callhook(L, LUA_HOOKLINE, newline);\n  }\n}\n\n\nstatic void callTMres (lua_State *L, StkId res, const TValue *f,\n                        const TValue *p1, const TValue *p2) {\n  ptrdiff_t result = savestack(L, res);\n  setobj2s(L, L->top, f);  /* push function */\n  setobj2s(L, L->top+1, p1);  /* 1st argument */\n  setobj2s(L, L->top+2, p2);  /* 2nd argument */\n  luaD_checkstack(L, 3);\n  L->top += 3;\n  luaD_call(L, L->top - 3, 1);\n  res = restorestack(L, result);\n  L->top--;\n  setobjs2s(L, res, L->top);\n}\n\n\n\nstatic void callTM (lua_State *L, const TValue *f, const TValue *p1,\n                    const TValue *p2, const TValue *p3) {\n  setobj2s(L, L->top, f);  /* push function */\n  setobj2s(L, L->top+1, p1);  /* 1st argument */\n  setobj2s(L, L->top+2, p2);  /* 2nd argument */\n  setobj2s(L, L->top+3, p3);  /* 3th argument */\n  luaD_checkstack(L, 4);\n  L->top += 4;\n  luaD_call(L, L->top - 4, 0);\n}\n\n\nvoid luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {\n  int loop;\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;\n    if (ttistable(t)) {  /* `t' is a table? */\n      Table *h = hvalue(t);\n      const TValue *res = luaH_get(h, key); /* do a primitive get */\n      if (!ttisnil(res) ||  /* result is no nil? */\n          (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */\n        setobj2s(L, val, res);\n        return;\n      }\n      /* else will try the tag method */\n    }\n    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))\n      luaG_typeerror(L, t, \"index\");\n    if (ttisfunction(tm)) {\n      callTMres(L, val, tm, t, key);\n      return;\n    }\n    t = tm;  /* else repeat with `tm' */ \n  }\n  luaG_runerror(L, \"loop in gettable\");\n}\n\n\nvoid luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {\n  int loop;\n  TValue temp;\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;\n    if (ttistable(t)) {  /* `t' is a table? */\n      Table *h = hvalue(t);\n      TValue *oldval = luaH_set(L, h, key); /* do a primitive set */\n      if (!ttisnil(oldval) ||  /* result is no nil? */\n          (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */\n        setobj2t(L, oldval, val);\n        h->flags = 0;\n        luaC_barriert(L, h, val);\n        return;\n      }\n      /* else will try the tag method */\n    }\n    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n      luaG_typeerror(L, t, \"index\");\n    if (ttisfunction(tm)) {\n      callTM(L, tm, t, key, val);\n      return;\n    }\n    /* else repeat with `tm' */\n    setobj(L, &temp, tm);  /* avoid pointing inside table (may rehash) */\n    t = &temp;\n  }\n  luaG_runerror(L, \"loop in settable\");\n}\n\n\nstatic int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,\n                       StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  callTMres(L, res, tm, p1, p2);\n  return 1;\n}\n\n\nstatic const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,\n                                  TMS event) {\n  const TValue *tm1 = fasttm(L, mt1, event);\n  const TValue *tm2;\n  if (tm1 == NULL) return NULL;  /* no metamethod */\n  if (mt1 == mt2) return tm1;  /* same metatables => same metamethods */\n  tm2 = fasttm(L, mt2, event);\n  if (tm2 == NULL) return NULL;  /* no metamethod */\n  if (luaO_rawequalObj(tm1, tm2))  /* same metamethods? */\n    return tm1;\n  return NULL;\n}\n\n\nstatic int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                         TMS event) {\n  const TValue *tm1 = luaT_gettmbyobj(L, p1, event);\n  const TValue *tm2;\n  if (ttisnil(tm1)) return -1;  /* no metamethod? */\n  tm2 = luaT_gettmbyobj(L, p2, event);\n  if (!luaO_rawequalObj(tm1, tm2))  /* different metamethods? */\n    return -1;\n  callTMres(L, L->top, tm1, p1, p2);\n  return !l_isfalse(L->top);\n}\n\n\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = ls->tsv.len;\n  const char *r = getstr(rs);\n  size_t lr = rs->tsv.len;\n  for (;;) {\n    int temp = strcoll(l, r);\n    if (temp != 0) return temp;\n    else {  /* strings are equal up to a `\\0' */\n      size_t len = strlen(l);  /* index of first `\\0' in both strings */\n      if (len == lr)  /* r is finished? */\n        return (len == ll) ? 0 : 1;\n      else if (len == ll)  /* l is finished? */\n        return -1;  /* l is smaller than r (because r is not finished) */\n      /* both strings longer than `len'; go on comparing (after the `\\0') */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttype(l) != ttype(r))\n    return luaG_ordererror(L, l, r);\n  else if (ttisnumber(l))\n    return luai_numlt(nvalue(l), nvalue(r));\n  else if (ttisstring(l))\n    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;\n  else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)\n    return res;\n  return luaG_ordererror(L, l, r);\n}\n\n\nstatic int lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttype(l) != ttype(r))\n    return luaG_ordererror(L, l, r);\n  else if (ttisnumber(l))\n    return luai_numle(nvalue(l), nvalue(r));\n  else if (ttisstring(l))\n    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;\n  else if ((res = call_orderTM(L, l, r, TM_LE)) != -1)  /* first try `le' */\n    return res;\n  else if ((res = call_orderTM(L, r, l, TM_LT)) != -1)  /* else try `lt' */\n    return !res;\n  return luaG_ordererror(L, l, r);\n}\n\n\nint luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  lua_assert(ttype(t1) == ttype(t2));\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,\n                         TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default: return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL) return 0;  /* no TM? */\n  callTMres(L, L->top, tm, t1, t2);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\nvoid luaV_concat (lua_State *L, int total, int last) {\n  do {\n    StkId top = L->base + last + 1;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {\n      if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))\n        luaG_concaterror(L, top-2, top-1);\n    } else if (tsvalue(top-1)->len == 0)  /* second op is empty? */\n      (void)tostring(L, top - 2);  /* result is first op (as string) */\n    else {\n      /* at least two string values; get as many as possible */\n      size_t tl = tsvalue(top-1)->len;\n      char *buffer;\n      int i;\n      /* collect total length */\n      for (n = 1; n < total && tostring(L, top-n-1); n++) {\n        size_t l = tsvalue(top-n-1)->len;\n        if (l >= MAX_SIZET - tl) luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      buffer = luaZ_openspace(L, &G(L)->buff, tl);\n      tl = 0;\n      for (i=n; i>0; i--) {  /* concat all strings */\n        size_t l = tsvalue(top-i)->len;\n        memcpy(buffer+tl, svalue(top-i), l);\n        tl += l;\n      }\n      setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));\n    }\n    total -= n-1;  /* got `n' strings to create 1 new */\n    last -= n-1;\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\nstatic void Arith (lua_State *L, StkId ra, const TValue *rb,\n                   const TValue *rc, TMS op) {\n  TValue tempb, tempc;\n  const TValue *b, *c;\n  if ((b = luaV_tonumber(rb, &tempb)) != NULL &&\n      (c = luaV_tonumber(rc, &tempc)) != NULL) {\n    lua_Number nb = nvalue(b), nc = nvalue(c);\n    switch (op) {\n      case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;\n      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;\n      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;\n      case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;\n      case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;\n      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;\n      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;\n      default: lua_assert(0); break;\n    }\n  }\n  else if (!call_binTM(L, rb, rc, ra, op))\n    luaG_aritherror(L, rb, rc);\n}\n\n\n\n/*\n** some macros for common tasks in `luaV_execute'\n*/\n\n#define runtime_check(L, c)\t{ if (!(c)) break; }\n\n#define RA(i)\t(base+GETARG_A(i))\n/* to be used after possible stack reallocation */\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n#define KBx(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))\n\n\n#define dojump(L,pc,i)\t{(pc) += (i); luai_threadyield(L);}\n\n\n#define Protect(x)\t{ L->savedpc = pc; {x;}; base = L->base; }\n\n\n#define arith_op(op,tm) { \\\n        TValue *rb = RKB(i); \\\n        TValue *rc = RKC(i); \\\n        if (ttisnumber(rb) && ttisnumber(rc)) { \\\n          lua_Number nb = nvalue(rb), nc = nvalue(rc); \\\n          setnvalue(ra, op(nb, nc)); \\\n        } \\\n        else \\\n          Protect(Arith(L, ra, rb, rc, tm)); \\\n      }\n\n\n\nvoid luaV_execute (lua_State *L, int nexeccalls) {\n  LClosure *cl;\n  StkId base;\n  TValue *k;\n  const Instruction *pc;\n reentry:  /* entry point */\n  lua_assert(isLua(L->ci));\n  pc = L->savedpc;\n  cl = &clvalue(L->ci->func)->l;\n  base = L->base;\n  k = cl->p->k;\n  /* main loop of interpreter */\n  for (;;) {\n    const Instruction i = *pc++;\n    StkId ra;\n    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&\n        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {\n      traceexec(L, pc);\n      if (L->status == LUA_YIELD) {  /* did hook yield? */\n        L->savedpc = pc - 1;\n        return;\n      }\n      base = L->base;\n    }\n    /* warning!! several calls may realloc the stack and invalidate `ra' */\n    ra = RA(i);\n    lua_assert(base == L->base && L->base == L->ci->base);\n    lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);\n    lua_assert(L->top == L->ci->top || luaG_checkopenop(i));\n    switch (GET_OPCODE(i)) {\n      case OP_MOVE: {\n        setobjs2s(L, ra, RB(i));\n        continue;\n      }\n      case OP_LOADK: {\n        setobj2s(L, ra, KBx(i));\n        continue;\n      }\n      case OP_LOADBOOL: {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) pc++;  /* skip next instruction (if C) */\n        continue;\n      }\n      case OP_LOADNIL: {\n        TValue *rb = RB(i);\n        do {\n          setnilvalue(rb--);\n        } while (rb >= ra);\n        continue;\n      }\n      case OP_GETUPVAL: {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        continue;\n      }\n      case OP_GETGLOBAL: {\n        TValue g;\n        TValue *rb = KBx(i);\n        sethvalue(L, &g, cl->env);\n        lua_assert(ttisstring(rb));\n        Protect(luaV_gettable(L, &g, rb, ra));\n        continue;\n      }\n      case OP_GETTABLE: {\n        Protect(luaV_gettable(L, RB(i), RKC(i), ra));\n        continue;\n      }\n      case OP_SETGLOBAL: {\n        TValue g;\n        sethvalue(L, &g, cl->env);\n        lua_assert(ttisstring(KBx(i)));\n        Protect(luaV_settable(L, &g, KBx(i), ra));\n        continue;\n      }\n      case OP_SETUPVAL: {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_barrier(L, uv, ra);\n        continue;\n      }\n      case OP_SETTABLE: {\n        Protect(luaV_settable(L, ra, RKB(i), RKC(i)));\n        continue;\n      }\n      case OP_NEWTABLE: {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));\n        Protect(luaC_checkGC(L));\n        continue;\n      }\n      case OP_SELF: {\n        StkId rb = RB(i);\n        setobjs2s(L, ra+1, rb);\n        Protect(luaV_gettable(L, rb, RKC(i), ra));\n        continue;\n      }\n      case OP_ADD: {\n        arith_op(luai_numadd, TM_ADD);\n        continue;\n      }\n      case OP_SUB: {\n        arith_op(luai_numsub, TM_SUB);\n        continue;\n      }\n      case OP_MUL: {\n        arith_op(luai_nummul, TM_MUL);\n        continue;\n      }\n      case OP_DIV: {\n        arith_op(luai_numdiv, TM_DIV);\n        continue;\n      }\n      case OP_MOD: {\n        arith_op(luai_nummod, TM_MOD);\n        continue;\n      }\n      case OP_POW: {\n        arith_op(luai_numpow, TM_POW);\n        continue;\n      }\n      case OP_UNM: {\n        TValue *rb = RB(i);\n        if (ttisnumber(rb)) {\n          lua_Number nb = nvalue(rb);\n          setnvalue(ra, luai_numunm(nb));\n        }\n        else {\n          Protect(Arith(L, ra, rb, rb, TM_UNM));\n        }\n        continue;\n      }\n      case OP_NOT: {\n        int res = l_isfalse(RB(i));  /* next assignment may change this value */\n        setbvalue(ra, res);\n        continue;\n      }\n      case OP_LEN: {\n        const TValue *rb = RB(i);\n        switch (ttype(rb)) {\n          case LUA_TTABLE: {\n            setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));\n            break;\n          }\n          case LUA_TSTRING: {\n            setnvalue(ra, cast_num(tsvalue(rb)->len));\n            break;\n          }\n          default: {  /* try metamethod */\n            Protect(\n              if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))\n                luaG_typeerror(L, rb, \"get length of\");\n            )\n          }\n        }\n        continue;\n      }\n      case OP_CONCAT: {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));\n        setobjs2s(L, RA(i), base+b);\n        continue;\n      }\n      case OP_JMP: {\n        dojump(L, pc, GETARG_sBx(i));\n        continue;\n      }\n      case OP_EQ: {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (equalobj(L, rb, rc) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_LT: {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_LE: {\n        Protect(\n          if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_TEST: {\n        if (l_isfalse(ra) != GETARG_C(i))\n          dojump(L, pc, GETARG_sBx(*pc));\n        pc++;\n        continue;\n      }\n      case OP_TESTSET: {\n        TValue *rb = RB(i);\n        if (l_isfalse(rb) != GETARG_C(i)) {\n          setobjs2s(L, ra, rb);\n          dojump(L, pc, GETARG_sBx(*pc));\n        }\n        pc++;\n        continue;\n      }\n      case OP_CALL: {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        L->savedpc = pc;\n        switch (luaD_precall(L, ra, nresults)) {\n          case PCRLUA: {\n            nexeccalls++;\n            goto reentry;  /* restart luaV_execute over new Lua function */\n          }\n          case PCRC: {\n            /* it was a C function (`precall' called it); adjust results */\n            if (nresults >= 0) L->top = L->ci->top;\n            base = L->base;\n            continue;\n          }\n          default: {\n            return;  /* yield */\n          }\n        }\n      }\n      case OP_TAILCALL: {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        L->savedpc = pc;\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        switch (luaD_precall(L, ra, LUA_MULTRET)) {\n          case PCRLUA: {\n            /* tail call: put new frame in place of previous one */\n            CallInfo *ci = L->ci - 1;  /* previous frame */\n            int aux;\n            StkId func = ci->func;\n            StkId pfunc = (ci+1)->func;  /* previous function index */\n            if (L->openupval) luaF_close(L, ci->base);\n            L->base = ci->base = ci->func + ((ci+1)->base - pfunc);\n            for (aux = 0; pfunc+aux < L->top; aux++)  /* move frame down */\n              setobjs2s(L, func+aux, pfunc+aux);\n            ci->top = L->top = func+aux;  /* correct top */\n            lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);\n            ci->savedpc = L->savedpc;\n            ci->tailcalls++;  /* one more call lost */\n            L->ci--;  /* remove new frame */\n            goto reentry;\n          }\n          case PCRC: {  /* it was a C function (`precall' called it) */\n            base = L->base;\n            continue;\n          }\n          default: {\n            return;  /* yield */\n          }\n        }\n      }\n      case OP_RETURN: {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b-1;\n        if (L->openupval) luaF_close(L, base);\n        L->savedpc = pc;\n        b = luaD_poscall(L, ra);\n        if (--nexeccalls == 0)  /* was previous function running `here'? */\n          return;  /* no: return */\n        else {  /* yes: continue its execution */\n          if (b) L->top = L->ci->top;\n          lua_assert(isLua(L->ci));\n          lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);\n          goto reentry;\n        }\n      }\n      case OP_FORLOOP: {\n        lua_Number step = nvalue(ra+2);\n        lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */\n        lua_Number limit = nvalue(ra+1);\n        if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                : luai_numle(limit, idx)) {\n          dojump(L, pc, GETARG_sBx(i));  /* jump back */\n          setnvalue(ra, idx);  /* update internal index... */\n          setnvalue(ra+3, idx);  /* ...and external index */\n        }\n        continue;\n      }\n      case OP_FORPREP: {\n        const TValue *init = ra;\n        const TValue *plimit = ra+1;\n        const TValue *pstep = ra+2;\n        L->savedpc = pc;  /* next steps may throw errors */\n        if (!tonumber(init, ra))\n          luaG_runerror(L, LUA_QL(\"for\") \" initial value must be a number\");\n        else if (!tonumber(plimit, ra+1))\n          luaG_runerror(L, LUA_QL(\"for\") \" limit must be a number\");\n        else if (!tonumber(pstep, ra+2))\n          luaG_runerror(L, LUA_QL(\"for\") \" step must be a number\");\n        setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));\n        dojump(L, pc, GETARG_sBx(i));\n        continue;\n      }\n      case OP_TFORLOOP: {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb+3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = L->ci->top;\n        cb = RA(i) + 3;  /* previous call may change the stack */\n        if (!ttisnil(cb)) {  /* continue loop? */\n          setobjs2s(L, cb-1, cb);  /* save control variable */\n          dojump(L, pc, GETARG_sBx(*pc));  /* jump back */\n        }\n        pc++;\n        continue;\n      }\n      case OP_SETLIST: {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        int last;\n        Table *h;\n        if (n == 0) {\n          n = cast_int(L->top - ra) - 1;\n          L->top = L->ci->top;\n        }\n        if (c == 0) c = cast_int(*pc++);\n        runtime_check(L, ttistable(ra));\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* pre-alloc it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          setobj2t(L, luaH_setnum(L, h, last--), val);\n          luaC_barriert(L, h, val);\n        }\n        continue;\n      }\n      case OP_CLOSE: {\n        luaF_close(L, ra);\n        continue;\n      }\n      case OP_CLOSURE: {\n        Proto *p;\n        Closure *ncl;\n        int nup, j;\n        p = cl->p->p[GETARG_Bx(i)];\n        nup = p->nups;\n        ncl = luaF_newLclosure(L, nup, cl->env);\n        ncl->l.p = p;\n        for (j=0; j<nup; j++, pc++) {\n          if (GET_OPCODE(*pc) == OP_GETUPVAL)\n            ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];\n          else {\n            lua_assert(GET_OPCODE(*pc) == OP_MOVE);\n            ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));\n          }\n        }\n        setclvalue(L, ra, ncl);\n        Protect(luaC_checkGC(L));\n        continue;\n      }\n      case OP_VARARG: {\n        int b = GETARG_B(i) - 1;\n        int j;\n        CallInfo *ci = L->ci;\n        int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;\n        if (b == LUA_MULTRET) {\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          b = n;\n          L->top = ra + n;\n        }\n        for (j = 0; j < b; j++) {\n          if (j < n) {\n            setobjs2s(L, ra + j, ci->base - n + j);\n          }\n          else {\n            setnilvalue(ra + j);\n          }\n        }\n        continue;\n      }\n    }\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))\n\n#define tonumber(o,n)\t(ttype(o) == LUA_TNUMBER || \\\n                         (((o) = luaV_tonumber(o,n)) != NULL))\n\n#define equalobj(L,o1,o2) \\\n\t(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))\n\n\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);\nLUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);\nLUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,\n                                            StkId val);\nLUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,\n                                            StkId val);\nLUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);\nLUAI_FUNC void luaV_concat (lua_State *L, int total, int last);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $\n** a generic input stream interface\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0) return EOZ;\n  z->n = size - 1;\n  z->p = buff;\n  return char2int(*(z->p++));\n}\n\n\nint luaZ_lookahead (ZIO *z) {\n  if (z->n == 0) {\n    if (luaZ_fill(z) == EOZ)\n      return EOZ;\n    else {\n      z->n++;  /* luaZ_fill removed first byte; put back it */\n      z->p--;\n    }\n  }\n  return char2int(*z->p);\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (luaZ_lookahead(z) == EOZ)\n      return n;  /* return number of missing bytes */\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\nchar *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {\n  if (n > buff->buffsize) {\n    if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;\n    luaZ_resizebuffer(L, buff, n);\n  }\n  return buff->buffer;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.1.5/src/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define char2int(c)\tcast(int, cast(unsigned char, (c)))\n\n#define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);\t/* read next n bytes */\nLUAI_FUNC int luaZ_lookahead (ZIO *z);\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\n  void* data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.1.5/src/print.c",
    "content": "/*\n** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lundump.h\"\n\n#define PrintFunction\tluaU_print\n\n#define Sizeof(x)\t((int)sizeof(x))\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=ts->tsv.len;\n putchar('\"');\n for (i=0; i<n; i++)\n {\n  int c=s[i];\n  switch (c)\n  {\n   case '\"': printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint((unsigned char)c))\n   \t\t\tputchar(c);\n\t\telse\n\t\t\tprintf(\"\\\\%03u\",(unsigned char)c);\n  }\n }\n putchar('\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMBER:\n\tprintf(LUA_NUMBER_FMT,nvalue(o));\n\tbreak;\n  case LUA_TSTRING:\n\tPrintString(rawtsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (-1-INDEXK(b)) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (-1-INDEXK(c)) : c);\n    break;\n   case iABx:\n    if (getBMode(o)==OpArgK) printf(\"%d %d\",a,-1-bx); else printf(\"%d %d\",a,bx);\n    break;\n   case iAsBx:\n    if (o==OP_JMP) printf(\"%d\",sbx); else printf(\"%d %d\",a,sbx);\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : \"-\");\n    break;\n   case OP_GETGLOBAL:\n   case OP_SETGLOBAL:\n    printf(\"\\t; %s\",svalue(&f->k[bx]));\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_DIV:\n   case OP_POW:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]);\n    else printf(\"\\t; %d\",c);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t(x==1)?\"\":\"s\"\n#define S(x)\tx,SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=getstr(f->source);\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\tf->numparams,f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->nups));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintConstants(const Proto* f)\n{\n int i,n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n}\n\nstatic void PrintLocals(const Proto* f)\n{\n int i,n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n}\n\nstatic void PrintUpvalues(const Proto* f)\n{\n int i,n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n if (f->upvalues==NULL) return;\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\n\",i,getstr(f->upvalues[i]));\n }\n}\n\nvoid PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full)\n {\n  PrintConstants(f);\n  PrintLocals(f);\n  PrintUpvalues(f);\n }\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "build/lua-5.3.3/CMakeLists.txt",
    "content": "# Copyright (C) 2007-2015 LuaDist.\n# Created by Peter Drahoš, Peter Kapec\n# Redistribution and use of this file is allowed according to the terms of the MIT license.\n# For details see the COPYRIGHT file distributed with LuaDist.\n# Please note that the package source code is licensed under its own license.\n\nproject ( lua C )\ncmake_minimum_required ( VERSION 2.8 )\ninclude ( cmake/dist.cmake )\n\n## CONFIGURATION\n# Default configuration (we assume POSIX by default)\nset ( LUA_PATH \"LUA_PATH\" CACHE STRING \"Environment variable to use as package.path.\" )\nset ( LUA_CPATH \"LUA_CPATH\" CACHE STRING \"Environment variable to use as package.cpath.\" )\nset ( LUA_INIT \"LUA_INIT\" CACHE STRING \"Environment variable for initial script.\" )\n\nset ( LUA_IDSIZE 120 CACHE NUMBER \"gives the maximum size for the description of the source.\" )\n\noption ( LUA_USE_C89 \"Use only C89 features.\" OFF )\noption ( LUA_USE_RELATIVE_LOADLIB \"Use modified loadlib.c with support for relative paths on posix systems.\" ON )\n\noption ( LUA_COMPAT_5_1 \"Enable backwards compatibility options with lua-5.1.\" ON )\noption ( LUA_COMPAT_5_2 \"Enable backwards compatibility options with lua-5.2.\" ON )\n\n#2DO: LUAI_* and LUAL_* settings, for now defaults are used.\nset ( LUA_DIRSEP \"/\" )\nset ( LUA_MODULE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} )\nset ( LUA_LDIR ${INSTALL_LMOD} )\nset ( LUA_CDIR ${INSTALL_CMOD} )\n\nif ( LUA_USE_RELATIVE_LOADLIB )\n  # This will set up relative paths to lib\n  string ( REGEX REPLACE \"[^!/]+\" \"..\" LUA_DIR \"!/${INSTALL_BIN}/\" )\nelse ( )\n  # Direct path to installation\n  set ( LUA_DIR ${CMAKE_INSTALL_PREFIX} CACHE STRING \"Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD.\" )\nendif ( )\n\nset ( LUA_PATH_DEFAULT \"./?.lua;${LUA_DIR}${LUA_LDIR}/?.lua;${LUA_DIR}${LUA_LDIR}/?/init.lua\" )\nset ( LUA_CPATH_DEFAULT \"./?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/loadall${LUA_MODULE_SUFFIX}\" )\n\nif ( WIN32 AND NOT CYGWIN )\n  # Windows systems\n  option ( LUA_USE_WINDOWS \"Windows specific build.\" ON )\n  option ( LUA_BUILD_WLUA \"Build wLua interpretter without console output.\" ON )\n  option ( LUA_BUILD_AS_DLL \"Build Lua library as Dll.\" ${BUILD_SHARED_LIBS} )\n\n  # Paths (Double escapes needed)\n  set ( LUA_DIRSEP \"\\\\\\\\\" )\n  string ( REPLACE \" /\" ${LUA_DIRSEP} LUA_DIR \"${LUA_DIR}\" )\n  string ( REPLACE \"/\" ${LUA_DIRSEP} LUA_LDIR \"${LUA_LDIR}\" )\n  string ( REPLACE \"/\" ${LUA_DIRSEP} LUA_CDIR \"${LUA_CDIR}\" )\n  string ( REPLACE \"/\" ${LUA_DIRSEP} LUA_PATH_DEFAULT \"${LUA_PATH_DEFAULT}\" )\n  string ( REPLACE \"/\" ${LUA_DIRSEP} LUA_CPATH_DEFAULT \"${LUA_CPATH_DEFAULT}\" )\nelse ( )\n  # Posix systems (incl. Cygwin)\n  option ( LUA_USE_POSIX \"Use POSIX features.\" ON )\n  option ( LUA_USE_DLOPEN \"Use dynamic linker to load modules.\" ON )\n  # Apple and Linux specific\n  if ( LINUX OR APPLE )\n    option ( LUA_USE_AFORMAT \"Assume 'printf' handles 'aA' specifiers\" ON )\n  endif ( )\nendif ( )\n\n## SETUP\n# Optional libraries\nfind_package ( Readline )\nif ( READLINE_FOUND )\n  option ( LUA_USE_READLINE \"Use readline in the Lua CLI.\" ON )\nendif ( )\n\n# Setup needed variables and libraries\nif ( LUA_USE_POSIX )\n  # On POSIX Lua links to standard math library \"m\"\n  list ( APPEND LIBS m )\nendif ( )\n\nif ( LUA_USE_DLOPEN )\n  # Link to dynamic linker library \"dl\"\n\tfind_library ( DL_LIBRARY NAMES dl )\n\tif ( DL_LIBRARY )\n    list ( APPEND LIBS ${DL_LIBRARY} )\n\tendif ( )\nendif ( )\n\nif ( LUA_USE_READLINE )\n  # Add readline\n  include_directories ( ${READLINE_INCLUDE_DIR} )\n  list ( APPEND LIBS ${READLINE_LIBRARY} )\nendif ( )\n\n## SOURCES\n# Generate luaconf.h\nconfigure_file ( src/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )\n\n# Sources and headers\ninclude_directories ( src ${CMAKE_CURRENT_BINARY_DIR} )\nset ( SRC_CORE src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c\n  src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c\n  src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c src/lvm.c src/lzio.c )\nset ( SRC_LIB src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c\n  src/liolib.c src/lmathlib.c src/loslib.c src/lstrlib.c src/ltablib.c src/linit.c\n  src/lutf8lib.c )\nset ( SRC_LUA src/lua.c )\nset ( SRC_LUAC src/luac.c )\n\nif ( LUA_USE_RELATIVE_LOADLIB )\n  # Use modified loadlib\n  list ( APPEND SRC_LIB src/loadlib_rel.c )\nelse ( )\n  list ( APPEND SRC_LIB src/loadlib.c )\nendif ( )\n\n## BUILD\n# Create lua library\nadd_library ( liblua ${SRC_CORE} ${SRC_LIB} ${LUA_DLL_RC} )\ntarget_link_libraries ( liblua ${LIBS} )\nset_target_properties ( liblua PROPERTIES OUTPUT_NAME lua CLEAN_DIRECT_OUTPUT 1 )\nif ( LUA_BUILD_AS_DLL )\n  set_target_properties ( liblua PROPERTIES COMPILE_DEFINITIONS LUA_BUILD_AS_DLL )\nendif ()\n\n# Create static library, this is needed to compile luac in the 5.1.x Lua series\nadd_library ( liblua_static STATIC ${SRC_CORE} ${SRC_LIB} )\ntarget_link_libraries ( liblua_static ${LIBS} )\n\nadd_executable ( lua ${SRC_LUA} src/lua.rc )\ntarget_link_libraries ( lua liblua )\n\nadd_executable ( luac ${SRC_CORE} ${SRC_LIB} ${SRC_LUAC} src/luac.rc )\ntarget_link_libraries ( luac ${LIBS} )\n\n# On windows a variant of the lua interpreter without console output needs to be built\nif ( LUA_BUILD_WLUA )\n  add_executable ( wlua WIN32 src/wmain.c ${SRC_LUA} src/lua.rc )\n  target_link_libraries ( wlua liblua )\n  install_executable ( wlua )\nendif ( )\n\ninstall_executable ( lua luac )\ninstall_library ( liblua )\ninstall_data ( README.md )\n#install_lua_module ( strict etc/strict.lua )\ninstall_header ( src/lua.h src/lualib.h src/lauxlib.h src/lua.hpp ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )\ninstall_doc ( doc/ )\ninstall_foo ( etc/ )\n#install_test ( test/ )\n"
  },
  {
    "path": "build/lua-5.3.3/Makefile",
    "content": "# Makefile for installing Lua\n# See doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\n# Where to install. The installation starts in the src and doc directories,\n# so take care if INSTALL_TOP is not an absolute path. See the local target.\n# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with\n# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.\nINSTALL_TOP= /usr/local\nINSTALL_BIN= $(INSTALL_TOP)/bin\nINSTALL_INC= $(INSTALL_TOP)/include\nINSTALL_LIB= $(INSTALL_TOP)/lib\nINSTALL_MAN= $(INSTALL_TOP)/man/man1\nINSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V\nINSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V\n\n# How to install. If your install program does not support \"-p\", then\n# you may have to run ranlib on the installed liblua.a.\nINSTALL= install -p\nINSTALL_EXEC= $(INSTALL) -m 0755\nINSTALL_DATA= $(INSTALL) -m 0644\n#\n# If you don't have \"install\" you can use \"cp\" instead.\n# INSTALL= cp -p\n# INSTALL_EXEC= $(INSTALL)\n# INSTALL_DATA= $(INSTALL)\n\n# Other utilities.\nMKDIR= mkdir -p\nRM= rm -f\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\n# Convenience platforms targets.\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\n# What to install.\nTO_BIN= lua luac\nTO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp\nTO_LIB= liblua.a\nTO_MAN= lua.1 luac.1\n\n# Lua version and release.\nV= 5.3\nR= $V.3\n\n# Targets start here.\nall:\t$(PLAT)\n\n$(PLATS) clean:\n\tcd src && $(MAKE) $@\n\ntest:\tdummy\n\tsrc/lua -v\n\ninstall: dummy\n\tcd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)\n\tcd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)\n\tcd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)\n\tcd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)\n\tcd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)\n\nuninstall:\n\tcd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)\n\tcd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)\n\tcd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)\n\tcd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)\n\nlocal:\n\t$(MAKE) install INSTALL_TOP=../install\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\t@echo \"See doc/readme.html for complete instructions.\"\n\n# make may get confused with test/ and install/\ndummy:\n\n# echo config parameters\necho:\n\t@cd src && $(MAKE) -s echo\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"V= $V\"\n\t@echo \"R= $R\"\n\t@echo \"TO_BIN= $(TO_BIN)\"\n\t@echo \"TO_INC= $(TO_INC)\"\n\t@echo \"TO_LIB= $(TO_LIB)\"\n\t@echo \"TO_MAN= $(TO_MAN)\"\n\t@echo \"INSTALL_TOP= $(INSTALL_TOP)\"\n\t@echo \"INSTALL_BIN= $(INSTALL_BIN)\"\n\t@echo \"INSTALL_INC= $(INSTALL_INC)\"\n\t@echo \"INSTALL_LIB= $(INSTALL_LIB)\"\n\t@echo \"INSTALL_MAN= $(INSTALL_MAN)\"\n\t@echo \"INSTALL_LMOD= $(INSTALL_LMOD)\"\n\t@echo \"INSTALL_CMOD= $(INSTALL_CMOD)\"\n\t@echo \"INSTALL_EXEC= $(INSTALL_EXEC)\"\n\t@echo \"INSTALL_DATA= $(INSTALL_DATA)\"\n\n# echo pkg-config data\npc:\n\t@echo \"version=$R\"\n\t@echo \"prefix=$(INSTALL_TOP)\"\n\t@echo \"libdir=$(INSTALL_LIB)\"\n\t@echo \"includedir=$(INSTALL_INC)\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.3/README",
    "content": "\nThis is Lua 5.3.3, released on 30 May 2016.\n\nFor installation instructions, license details, and\nfurther information about Lua, see doc/readme.html.\n\n"
  },
  {
    "path": "build/lua-5.3.3/cmake/FindLua.cmake",
    "content": "# Locate Lua library\n# This module defines\n#  LUA_EXECUTABLE, if found\n#  LUA_FOUND, if false, do not try to link to Lua \n#  LUA_LIBRARIES\n#  LUA_INCLUDE_DIR, where to find lua.h\n#  LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)\n#\n# Note that the expected include convention is\n#  #include \"lua.h\"\n# and not\n#  #include <lua/lua.h>\n# This is because, the lua location is not standardized and may exist\n# in locations other than lua/\n\n#=============================================================================\n# Copyright 2007-2009 Kitware, Inc.\n# Modified to support Lua 5.2 by LuaDist 2012\n#\n# Distributed under the OSI-approved BSD License (the \"License\");\n# see accompanying file Copyright.txt for details.\n#\n# This software is distributed WITHOUT ANY WARRANTY; without even the\n# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n# See the License for more information.\n#=============================================================================\n# (To distribute this file outside of CMake, substitute the full\n#  License text for the above reference.)\n#\n# The required version of Lua can be specified using the\n# standard syntax, e.g. FIND_PACKAGE(Lua 5.1)\n# Otherwise the module will search for any available Lua implementation\n\n# Always search for non-versioned lua first (recommended)\nSET(_POSSIBLE_LUA_INCLUDE include include/lua)\nSET(_POSSIBLE_LUA_EXECUTABLE lua)\nSET(_POSSIBLE_LUA_LIBRARY lua)\n\n# Determine possible naming suffixes (there is no standard for this)\nIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)\n  SET(_POSSIBLE_SUFFIXES \"${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}\" \"${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}\" \"-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}\")\nELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)\n  SET(_POSSIBLE_SUFFIXES \"52\" \"5.2\" \"-5.2\" \"51\" \"5.1\" \"-5.1\")\nENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)\n\n# Set up possible search names and locations\nFOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})\n  LIST(APPEND _POSSIBLE_LUA_INCLUDE \"include/lua${_SUFFIX}\")\n  LIST(APPEND _POSSIBLE_LUA_EXECUTABLE \"lua${_SUFFIX}\")\n  LIST(APPEND _POSSIBLE_LUA_LIBRARY \"lua${_SUFFIX}\")\nENDFOREACH(_SUFFIX)\n\n# Find the lua executable\nFIND_PROGRAM(LUA_EXECUTABLE\n  NAMES ${_POSSIBLE_LUA_EXECUTABLE}\n)\n\n# Find the lua header\nFIND_PATH(LUA_INCLUDE_DIR lua.h\n  HINTS\n  $ENV{LUA_DIR}\n  PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}\n  PATHS\n  ~/Library/Frameworks\n  /Library/Frameworks\n  /usr/local\n  /usr\n  /sw # Fink\n  /opt/local # DarwinPorts\n  /opt/csw # Blastwave\n  /opt\n)\n\n# Find the lua library\nFIND_LIBRARY(LUA_LIBRARY \n  NAMES ${_POSSIBLE_LUA_LIBRARY}\n  HINTS\n  $ENV{LUA_DIR}\n  PATH_SUFFIXES lib64 lib\n  PATHS\n  ~/Library/Frameworks\n  /Library/Frameworks\n  /usr/local\n  /usr\n  /sw\n  /opt/local\n  /opt/csw\n  /opt\n)\n\nIF(LUA_LIBRARY)\n  # include the math library for Unix\n  IF(UNIX AND NOT APPLE)\n    FIND_LIBRARY(LUA_MATH_LIBRARY m)\n    SET( LUA_LIBRARIES \"${LUA_LIBRARY};${LUA_MATH_LIBRARY}\" CACHE STRING \"Lua Libraries\")\n  # For Windows and Mac, don't need to explicitly include the math library\n  ELSE(UNIX AND NOT APPLE)\n    SET( LUA_LIBRARIES \"${LUA_LIBRARY}\" CACHE STRING \"Lua Libraries\")\n  ENDIF(UNIX AND NOT APPLE)\nENDIF(LUA_LIBRARY)\n\n# Determine Lua version\nIF(LUA_INCLUDE_DIR AND EXISTS \"${LUA_INCLUDE_DIR}/lua.h\")\n  FILE(STRINGS \"${LUA_INCLUDE_DIR}/lua.h\" lua_version_str REGEX \"^#define[ \\t]+LUA_RELEASE[ \\t]+\\\"Lua .+\\\"\")\n\n  STRING(REGEX REPLACE \"^#define[ \\t]+LUA_RELEASE[ \\t]+\\\"Lua ([^\\\"]+)\\\".*\" \"\\\\1\" LUA_VERSION_STRING \"${lua_version_str}\")\n  UNSET(lua_version_str)\nENDIF()\n\nINCLUDE(FindPackageHandleStandardArgs)\n# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if \n# all listed variables are TRUE\nFIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua\n                                  REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR\n                                  VERSION_VAR LUA_VERSION_STRING)\n\nMARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)\n\n"
  },
  {
    "path": "build/lua-5.3.3/cmake/FindReadline.cmake",
    "content": "# - Try to find Readline\n# Once done this will define\n#  READLINE_FOUND - System has readline\n#  READLINE_INCLUDE_DIRS - The readline include directories\n#  READLINE_LIBRARIES - The libraries needed to use readline\n#  READLINE_DEFINITIONS - Compiler switches required for using readline\n\nfind_package ( PkgConfig )\npkg_check_modules ( PC_READLINE QUIET readline )\nset ( READLINE_DEFINITIONS ${PC_READLINE_CFLAGS_OTHER} )\n\nfind_path ( READLINE_INCLUDE_DIR readline/readline.h\n      HINTS ${PC_READLINE_INCLUDEDIR} ${PC_READLINE_INCLUDE_DIRS}\n      PATH_SUFFIXES readline )\n\nfind_library ( READLINE_LIBRARY NAMES readline\n      HINTS ${PC_READLINE_LIBDIR} ${PC_READLINE_LIBRARY_DIRS} )\n\nset ( READLINE_LIBRARIES ${READLINE_LIBRARY} )\nset ( READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR} )\n\ninclude ( FindPackageHandleStandardArgs )\n# handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE\n# if all listed variables are TRUE\nfind_package_handle_standard_args ( readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR )\n"
  },
  {
    "path": "build/lua-5.3.3/cmake/dist.cmake",
    "content": "# LuaDist CMake utility library.\n# Provides sane project defaults and macros common to LuaDist CMake builds.\n# \n# Copyright (C) 2007-2012 LuaDist.\n# by David Manura, Peter Drahoš\n# Redistribution and use of this file is allowed according to the terms of the MIT license.\n# For details see the COPYRIGHT file distributed with LuaDist.\n# Please note that the package source code is licensed under its own license.\n\n## Extract information from dist.info\nif ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info )\n  message ( FATAL_ERROR\n    \"Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info).\" )\nendif ()\nfile ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO )\nif ( \"${DIST_INFO}\" STREQUAL \"\" )\n  message ( FATAL_ERROR \"Failed to load dist.info.\" )\nendif ()\n# Reads field `name` from dist.info string `DIST_INFO` into variable `var`.\nmacro ( _parse_dist_field name var )\n  string ( REGEX REPLACE \".*${name}[ \\t]?=[ \\t]?[\\\"']([^\\\"']+)[\\\"'].*\" \"\\\\1\"\n           ${var} \"${DIST_INFO}\" )\n  if ( ${var} STREQUAL DIST_INFO )\n    message ( FATAL_ERROR \"Failed to extract \\\"${var}\\\" from dist.info\" )\n  endif ()\nendmacro ()\n#\n_parse_dist_field ( name DIST_NAME )\n_parse_dist_field ( version DIST_VERSION )\n_parse_dist_field ( license DIST_LICENSE )\n_parse_dist_field ( author DIST_AUTHOR )\n_parse_dist_field ( maintainer DIST_MAINTAINER )\n_parse_dist_field ( url DIST_URL )\n_parse_dist_field ( desc DIST_DESC )\nmessage ( \"DIST_NAME: ${DIST_NAME}\")\nmessage ( \"DIST_VERSION: ${DIST_VERSION}\")\nmessage ( \"DIST_LICENSE: ${DIST_LICENSE}\")\nmessage ( \"DIST_AUTHOR: ${DIST_AUTHOR}\")\nmessage ( \"DIST_MAINTAINER: ${DIST_MAINTAINER}\")\nmessage ( \"DIST_URL: ${DIST_URL}\")\nmessage ( \"DIST_DESC: ${DIST_DESC}\")\nstring ( REGEX REPLACE \".*depends[ \\t]?=[ \\t]?[\\\"']([^\\\"']+)[\\\"'].*\" \"\\\\1\"\n         DIST_DEPENDS ${DIST_INFO} )\nif ( DIST_DEPENDS STREQUAL DIST_INFO )\n  set ( DIST_DEPENDS \"\" )\nendif ()\nmessage ( \"DIST_DEPENDS: ${DIST_DEPENDS}\")\n## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add\n\n\n## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX)\n# Primary paths\nset ( INSTALL_BIN bin CACHE PATH \"Where to install binaries to.\" )\nset ( INSTALL_LIB lib CACHE PATH \"Where to install libraries to.\" )\nset ( INSTALL_INC include CACHE PATH \"Where to install headers to.\" )\nset ( INSTALL_ETC etc CACHE PATH \"Where to store configuration files\" )\nset ( INSTALL_SHARE share CACHE PATH \"Directory for shared data.\" )\n\n# Secondary paths\noption ( INSTALL_VERSION\n      \"Install runtime libraries and executables with version information.\" OFF)\nset ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH\n      \"Directory the package can store documentation, tests or other data in.\")  \nset ( INSTALL_DOC  ${INSTALL_DATA}/doc CACHE PATH\n      \"Recommended directory to install documentation into.\")\nset ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH\n      \"Recommended directory to install examples into.\")\nset ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH\n      \"Recommended directory to install tests into.\")\nset ( INSTALL_FOO  ${INSTALL_DATA}/etc CACHE PATH\n      \"Where to install additional files\")\n\n# Tweaks and other defaults\n# Setting CMAKE to use loose block and search for find modules in source directory\nset ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )\nset ( CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake\" ${CMAKE_MODULE_PATH} )\noption ( BUILD_SHARED_LIBS \"Build shared libraries\" ON )\n\n# In MSVC, prevent warnings that can occur when using standard libraries.\nif ( MSVC )\n  add_definitions ( -D_CRT_SECURE_NO_WARNINGS )\nendif ()\n\n# RPath and relative linking\noption ( USE_RPATH \"Use relative linking.\" ON)\nif ( USE_RPATH )\n  string ( REGEX REPLACE \"[^!/]+\" \"..\" UP_DIR ${INSTALL_BIN} )\n  set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING \"\" FORCE )\n  set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING \"\" FORCE )\n  set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB}\n        CACHE STRING \"\" FORCE )\n  set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING \"\" FORCE )\n  set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB}\n        CACHE STRING \"\" FORCE )\nendif ()\n\n## MACROS\n# Parser macro\nmacro ( parse_arguments prefix arg_names option_names)\n  set ( DEFAULT_ARGS )\n  foreach ( arg_name ${arg_names} )\n    set ( ${prefix}_${arg_name} )\n  endforeach ()\n  foreach ( option ${option_names} )\n    set ( ${prefix}_${option} FALSE )\n  endforeach ()\n\n  set ( current_arg_name DEFAULT_ARGS )\n  set ( current_arg_list )\n  foreach ( arg ${ARGN} )            \n    set ( larg_names ${arg_names} )    \n    list ( FIND larg_names \"${arg}\" is_arg_name )                   \n    if ( is_arg_name GREATER -1 )\n      set ( ${prefix}_${current_arg_name} ${current_arg_list} )\n      set ( current_arg_name ${arg} )\n      set ( current_arg_list )\n    else ()\n      set ( loption_names ${option_names} )    \n      list ( FIND loption_names \"${arg}\" is_option )            \n      if ( is_option GREATER -1 )\n        set ( ${prefix}_${arg} TRUE )\n      else ()\n        set ( current_arg_list ${current_arg_list} ${arg} )\n      endif ()\n    endif ()\n  endforeach ()\n  set ( ${prefix}_${current_arg_name} ${current_arg_list} )\nendmacro ()\n\n\n# install_executable ( executable_targets )\n# Installs any executables generated using \"add_executable\".\n# USE: install_executable ( lua )\n# NOTE: subdirectories are NOT supported\nset ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME \"${DIST_NAME} Runtime\" )\nset ( CPACK_COMPONENT_RUNTIME_DESCRIPTION\n      \"Executables and runtime libraries. Installed into ${INSTALL_BIN}.\" )\nmacro ( install_executable )\n  foreach ( _file ${ARGN} )\n    if ( INSTALL_VERSION )\n      set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}\n                              SOVERSION ${DIST_VERSION} )\n    endif ()\n    install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN}\n              COMPONENT Runtime )\n  endforeach()\nendmacro ()\n\n# install_library ( library_targets )\n# Installs any libraries generated using \"add_library\" into apropriate places.\n# USE: install_library ( libexpat )\n# NOTE: subdirectories are NOT supported\nset ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME \"${DIST_NAME} Development Libraries\" )\nset ( CPACK_COMPONENT_LIBRARY_DESCRIPTION\n  \"Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}.\" )\nmacro ( install_library )\n  foreach ( _file ${ARGN} )\n    if ( INSTALL_VERSION )\n      set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}\n                              SOVERSION ${DIST_VERSION} )\n    endif ()\n    install ( TARGETS ${_file}\n              RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime\n              LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime \n              ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library )\n  endforeach()\nendmacro ()\n\n# helper function for various install_* functions, for PATTERN/REGEX args.\nmacro ( _complete_install_args )\n  if ( NOT(\"${_ARG_PATTERN}\" STREQUAL \"\") )\n    set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} )\n  endif ()\n  if ( NOT(\"${_ARG_REGEX}\" STREQUAL \"\") )\n    set ( _ARG_REGEX REGEX ${_ARG_REGEX} )\n  endif ()\nendmacro ()\n\n# install_header ( files/directories [INTO destination] )\n# Install a directories or files into header destination.\n# USE: install_header ( lua.h luaconf.h ) or install_header ( GL )\n# USE: install_header ( mylib.h INTO mylib )\n# For directories, supports optional PATTERN/REGEX arguments like install().\nset ( CPACK_COMPONENT_HEADER_DISPLAY_NAME \"${DIST_NAME} Development Headers\" )\nset ( CPACK_COMPONENT_HEADER_DESCRIPTION\n      \"Headers needed for development. Installed into ${INSTALL_INC}.\" )\nmacro ( install_header )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}\n                COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}\n                COMPONENT Header )\n    endif ()\n  endforeach()\nendmacro ()\n\n# install_data ( files/directories [INTO destination] )\n# This installs additional data files or directories.\n# USE: install_data ( extra data.dat )\n# USE: install_data ( image1.png image2.png INTO images )\n# For directories, supports optional PATTERN/REGEX arguments like install().\nset ( CPACK_COMPONENT_DATA_DISPLAY_NAME \"${DIST_NAME} Data\" )\nset ( CPACK_COMPONENT_DATA_DESCRIPTION\n      \"Application data. Installed into ${INSTALL_DATA}.\" )\nmacro ( install_data )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file}\n                DESTINATION ${INSTALL_DATA}/${_ARG_INTO}\n                COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO}\n                COMPONENT Data )\n    endif ()\n  endforeach()\nendmacro ()\n\n# INSTALL_DOC ( files/directories [INTO destination] )\n# This installs documentation content\n# USE: install_doc ( doc/ doc.pdf )\n# USE: install_doc ( index.html INTO html )\n# For directories, supports optional PATTERN/REGEX arguments like install().\nset ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME \"${DIST_NAME} Documentation\" )\nset ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION\n      \"Application documentation. Installed into ${INSTALL_DOC}.\" )\nmacro ( install_doc )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}\n                COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}\n                COMPONENT Documentation )\n    endif ()\n  endforeach()\nendmacro ()\n\n# install_example ( files/directories [INTO destination]  )\n# This installs additional examples\n# USE: install_example ( examples/ exampleA )\n# USE: install_example ( super_example super_data INTO super)\n# For directories, supports optional PATTERN/REGEX argument like install().\nset ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME \"${DIST_NAME} Examples\" )\nset ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION\n    \"Examples and their associated data. Installed into ${INSTALL_EXAMPLE}.\" )\nmacro ( install_example )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}\n                COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}\n                COMPONENT Example )\n    endif ()\n  endforeach()\nendmacro ()\n\n# install_test ( files/directories [INTO destination] )\n# This installs tests and test files, DOES NOT EXECUTE TESTS\n# USE: install_test ( my_test data.sql )\n# USE: install_test ( feature_x_test INTO x )\n# For directories, supports optional PATTERN/REGEX argument like install().\nset ( CPACK_COMPONENT_TEST_DISPLAY_NAME \"${DIST_NAME} Tests\" )\nset ( CPACK_COMPONENT_TEST_DESCRIPTION\n      \"Tests and associated data. Installed into ${INSTALL_TEST}.\" )\nmacro ( install_test )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}\n                COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}\n                COMPONENT Test )\n    endif ()\n  endforeach()\nendmacro ()\n\n# install_foo ( files/directories [INTO destination] )\n# This installs optional or otherwise unneeded content\n# USE: install_foo ( etc/ example.doc )\n# USE: install_foo ( icon.png logo.png INTO icons)\n# For directories, supports optional PATTERN/REGEX argument like install().\nset ( CPACK_COMPONENT_OTHER_DISPLAY_NAME \"${DIST_NAME} Unspecified Content\" )\nset ( CPACK_COMPONENT_OTHER_DESCRIPTION\n      \"Other unspecified content. Installed into ${INSTALL_FOO}.\" )\nmacro ( install_foo )\n  parse_arguments ( _ARG \"INTO;PATTERN;REGEX\" \"\" ${ARGN} )\n  _complete_install_args()\n  foreach ( _file ${_ARG_DEFAULT_ARGS} )\n    if ( IS_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}/${_file}\" )\n      install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}\n                COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} )\n    else ()\n      install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}\n                COMPONENT Other )\n    endif ()\n  endforeach()\nendmacro ()\n\n## CTest defaults\n\n## CPack defaults\nset ( CPACK_GENERATOR \"ZIP\" )\nset ( CPACK_STRIP_FILES TRUE )\nset ( CPACK_PACKAGE_NAME \"${DIST_NAME}\" )\nset ( CPACK_PACKAGE_VERSION \"${DIST_VERSION}\")\nset ( CPACK_PACKAGE_VENDOR \"LuaDist\" )\nset ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )\ninclude ( CPack )\n"
  },
  {
    "path": "build/lua-5.3.3/cmake/lua.cmake",
    "content": "# LuaDist CMake utility library for Lua.\n# \n# Copyright (C) 2007-2012 LuaDist.\n# by David Manura, Peter Drahos\n# Redistribution and use of this file is allowed according to the terms of the MIT license.\n# For details see the COPYRIGHT file distributed with LuaDist.\n# Please note that the package source code is licensed under its own license.\n\nset ( INSTALL_LMOD ${INSTALL_LIB}/lua\n      CACHE PATH \"Directory to install Lua modules.\" )\nset ( INSTALL_CMOD ${INSTALL_LIB}/lua\n      CACHE PATH \"Directory to install Lua binary modules.\" )\n\noption ( SKIP_LUA_WRAPPER\n         \"Do not build and install Lua executable wrappers.\" OFF)\n\n# List of (Lua module name, file path) pairs.\n# Used internally by add_lua_test.  Built by add_lua_module.\nset ( _lua_modules )\n\n# utility function: appends path `path` to path `basepath`, properly\n# handling cases when `path` may be relative or absolute.\nmacro ( _append_path basepath path result )\n  if ( IS_ABSOLUTE \"${path}\" )\n    set ( ${result} \"${path}\" )\n  else ()\n    set ( ${result} \"${basepath}/${path}\" )\n  endif ()\nendmacro ()\n\n# install_lua_executable ( target source )\n# Automatically generate a binary wrapper for lua application and install it\n# The wrapper and the source of the application will be placed into /bin\n# If the application source did not have .lua suffix then it will be added\n# USE: lua_executable ( sputnik src/sputnik.lua )\nmacro ( install_lua_executable _name _source )\n  get_filename_component ( _source_name ${_source} NAME_WE )\n  if ( NOT SKIP_LUA_WRAPPER )\n    enable_language ( C )\n  \n    find_package ( Lua REQUIRED )\n    include_directories ( ${LUA_INCLUDE_DIR} )\n\n    set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c )\n    set ( _code \n\"// Not so simple executable wrapper for Lua apps\n#include <stdio.h>\n#include <signal.h>\n#include <lua.h>\n#include <lauxlib.h>\n#include <lualib.h>\n\nlua_State *L\\;\n\nstatic int getargs (lua_State *L, char **argv, int n) {\nint narg\\;\nint i\\;\nint argc = 0\\;\nwhile (argv[argc]) argc++\\;\nnarg = argc - (n + 1)\\;\nluaL_checkstack(L, narg + 3, \\\"too many arguments to script\\\")\\;\nfor (i=n+1\\; i < argc\\; i++)\n  lua_pushstring(L, argv[i])\\;\nlua_createtable(L, narg, n + 1)\\;\nfor (i=0\\; i < argc\\; i++) {\n  lua_pushstring(L, argv[i])\\;\n  lua_rawseti(L, -2, i - n)\\;\n}\nreturn narg\\;\n}\n\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n(void)ar\\;\nlua_sethook(L, NULL, 0, 0)\\;\nluaL_error(L, \\\"interrupted!\\\")\\;\n}\n\nstatic void laction (int i) {\nsignal(i, SIG_DFL)\\;\nlua_sethook(L, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1)\\;\n}\n\nstatic void l_message (const char *pname, const char *msg) {\nif (pname) fprintf(stderr, \\\"%s: \\\", pname)\\;\nfprintf(stderr, \\\"%s\\\\n\\\", msg)\\;\nfflush(stderr)\\;\n}\n\nstatic int report (lua_State *L, int status) {\nif (status && !lua_isnil(L, -1)) {\n  const char *msg = lua_tostring(L, -1)\\;\n  if (msg == NULL) msg = \\\"(error object is not a string)\\\"\\;\n  l_message(\\\"${_source_name}\\\", msg)\\;\n  lua_pop(L, 1)\\;\n}\nreturn status\\;\n}\n\nstatic int traceback (lua_State *L) {\nif (!lua_isstring(L, 1))\n  return 1\\;\nlua_getfield(L, LUA_GLOBALSINDEX, \\\"debug\\\")\\;\nif (!lua_istable(L, -1)) {\n  lua_pop(L, 1)\\;\n  return 1\\;\n}\nlua_getfield(L, -1, \\\"traceback\\\")\\;\nif (!lua_isfunction(L, -1)) {\n  lua_pop(L, 2)\\;\n  return 1\\;\n}\nlua_pushvalue(L, 1)\\; \nlua_pushinteger(L, 2)\\;\nlua_call(L, 2, 1)\\;\nreturn 1\\;\n}\n\nstatic int docall (lua_State *L, int narg, int clear) {\nint status\\;\nint base = lua_gettop(L) - narg\\;\nlua_pushcfunction(L, traceback)\\;\nlua_insert(L, base)\\;\nsignal(SIGINT, laction)\\;\nstatus = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base)\\;\nsignal(SIGINT, SIG_DFL)\\;\nlua_remove(L, base)\\;\nif (status != 0) lua_gc(L, LUA_GCCOLLECT, 0)\\;\nreturn status\\;\n}\n\nint main (int argc, char **argv) {\nL=lua_open()\\;\nlua_gc(L, LUA_GCSTOP, 0)\\;\nluaL_openlibs(L)\\;\nlua_gc(L, LUA_GCRESTART, 0)\\;\nint narg = getargs(L, argv, 0)\\;\nlua_setglobal(L, \\\"arg\\\")\\;\n\n// Script\nchar script[500] = \\\"./${_source_name}.lua\\\"\\;\nlua_getglobal(L, \\\"_PROGDIR\\\")\\;\nif (lua_isstring(L, -1)) {\n  sprintf( script, \\\"%s/${_source_name}.lua\\\", lua_tostring(L, -1))\\;\n} \nlua_pop(L, 1)\\;\n\n// Run\nint status = luaL_loadfile(L, script)\\;\nlua_insert(L, -(narg+1))\\;\nif (status == 0)\n  status = docall(L, narg, 0)\\;\nelse\n  lua_pop(L, narg)\\;\n\nreport(L, status)\\;\nlua_close(L)\\;\nreturn status\\;\n};\n\")\n    file ( WRITE ${_wrapper} ${_code} )\n    add_executable ( ${_name} ${_wrapper} )\n    target_link_libraries ( ${_name} ${LUA_LIBRARY} )\n    install ( TARGETS ${_name} DESTINATION ${INSTALL_BIN} )\n  endif()\n  install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN}\n            RENAME ${_source_name}.lua )\nendmacro ()\n\nmacro ( _lua_module_helper is_install _name ) \n  parse_arguments ( _MODULE \"LINK;ALL_IN_ONE\" \"\" ${ARGN} )\n  # _target is CMake-compatible target name for module (e.g. socket_core).\n  # _module is relative path of target (e.g. socket/core),\n  #   without extension (e.g. .lua/.so/.dll).\n  # _MODULE_SRC is list of module source files (e.g. .lua and .c files).\n  # _MODULE_NAMES is list of module names (e.g. socket.core).\n  if ( _MODULE_ALL_IN_ONE )\n    string ( REGEX REPLACE \"\\\\..*\" \"\" _target \"${_name}\" )\n    string ( REGEX REPLACE \"\\\\..*\" \"\" _module \"${_name}\" )\n    set ( _target \"${_target}_all_in_one\")\n    set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} )\n    set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} )\n  else ()\n    string ( REPLACE \".\" \"_\" _target \"${_name}\" )\n    string ( REPLACE \".\" \"/\" _module \"${_name}\" )\n    set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} )\n    set ( _MODULE_NAMES ${_name} )\n  endif ()\n  if ( NOT _MODULE_SRC )\n    message ( FATAL_ERROR \"no module sources specified\" )\n  endif ()\n  list ( GET _MODULE_SRC 0 _first_source )\n  \n  get_filename_component ( _ext ${_first_source} EXT )\n  if ( _ext STREQUAL \".lua\" )  # Lua source module\n    list ( LENGTH _MODULE_SRC _len )\n    if ( _len GREATER 1 )\n      message ( FATAL_ERROR \"more than one source file specified\" )\n    endif ()\n  \n    set ( _module \"${_module}.lua\" )\n\n    get_filename_component ( _module_dir ${_module} PATH )\n    get_filename_component ( _module_filename ${_module} NAME )\n    _append_path ( \"${CMAKE_CURRENT_SOURCE_DIR}\" \"${_first_source}\" _module_path )\n    list ( APPEND _lua_modules \"${_name}\" \"${_module_path}\" )\n\n    if ( ${is_install} )\n      install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir}\n                RENAME ${_module_filename} )\n    endif ()\n  else ()  # Lua C binary module\n    enable_language ( C )\n    find_package ( Lua REQUIRED )\n    include_directories ( ${LUA_INCLUDE_DIR} )\n\n    set ( _module \"${_module}${CMAKE_SHARED_MODULE_SUFFIX}\" )\n\n    get_filename_component ( _module_dir ${_module} PATH )\n    get_filename_component ( _module_filenamebase ${_module} NAME_WE )\n    foreach ( _thisname ${_MODULE_NAMES} )\n      list ( APPEND _lua_modules \"${_thisname}\"\n             \"${CMAKE_CURRENT_BINARY_DIR}/\\${CMAKE_CFG_INTDIR}/${_module}\" )\n    endforeach ()\n   \n    add_library( ${_target} MODULE ${_MODULE_SRC})\n    target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} )\n    set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY\n                \"${_module_dir}\" PREFIX \"\" OUTPUT_NAME \"${_module_filenamebase}\" )\n    if ( ${is_install} )\n      install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir})\n    endif ()\n  endif ()\nendmacro ()\n\n# add_lua_module\n# Builds a Lua source module into a destination locatable by Lua\n# require syntax.\n# Binary modules are also supported where this function takes sources and\n# libraries to compile separated by LINK keyword.\n# USE: add_lua_module ( socket.http src/http.lua )\n# USE2: add_lua_module ( mime.core src/mime.c )\n# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )\n# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c )\n#   This form builds an \"all-in-one\" module (e.g. ssl.so or ssl.dll containing\n#   both modules ssl.context and ssl.core).  The CMake target name will be\n#   ssl_all_in_one.\n# Also sets variable _module_path (relative path where module typically\n# would be installed).\nmacro ( add_lua_module )\n  _lua_module_helper ( 0 ${ARGN} )\nendmacro ()\n\n\n# install_lua_module\n# This is the same as `add_lua_module` but also installs the module.\n# USE: install_lua_module ( socket.http src/http.lua )\n# USE2: install_lua_module ( mime.core src/mime.c )\n# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )\nmacro ( install_lua_module )\n  _lua_module_helper ( 1 ${ARGN} )\nendmacro ()\n\n# Builds string representing Lua table mapping Lua modules names to file\n# paths.  Used internally.\nmacro ( _make_module_table _outvar )\n  set ( ${_outvar} )\n  list ( LENGTH _lua_modules _n )\n  if ( ${_n} GREATER 0 ) # avoids cmake complaint\n  foreach ( _i RANGE 1 ${_n} 2 )\n    list ( GET _lua_modules ${_i} _path )\n    math ( EXPR _ii ${_i}-1 )\n    list ( GET _lua_modules ${_ii} _name )\n    set ( ${_outvar} \"${_table}  ['${_name}'] = '${_path}'\\;\\n\")\n  endforeach ()\n  endif ()\n  set ( ${_outvar}\n\"local modules = {\n${_table}}\" )\nendmacro ()\n\n# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] )\n# Runs Lua script `_testfile` under CTest tester.\n# Optional named argument `WORKING_DIRECTORY` is current working directory to\n# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}).\n# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}.\n# Any modules previously defined with install_lua_module are automatically\n# preloaded (via package.preload) prior to running the test script.\n# Under LuaDist, set test=true in config.lua to enable testing.\n# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir])\nmacro ( add_lua_test _testfile )\n  if ( NOT SKIP_TESTING )\n    parse_arguments ( _ARG \"WORKING_DIRECTORY\" \"\" ${ARGN} )\n    include ( CTest )\n    find_program ( LUA NAMES lua lua.bat )\n    get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE )\n    get_filename_component ( TESTFILENAME ${_testfile} NAME )\n    get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE )\n\n    # Write wrapper script.\n    # Note: One simple way to allow the script to find modules is\n    # to just put them in package.preload.\n    set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} )\n    _make_module_table ( _table )\n    set ( TESTWRAPPERSOURCE\n\"local CMAKE_CFG_INTDIR = ... or '.'\n${_table}\nlocal function preload_modules(modules)\n  for name, path in pairs(modules) do\n    if path:match'%.lua' then\n      package.preload[name] = assert(loadfile(path))\n    else\n      local name = name:gsub('.*%-', '') -- remove any hyphen prefix\n      local symbol = 'luaopen_' .. name:gsub('%.', '_')\n          --improve: generalize to support all-in-one loader?\n      local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR)\n      package.preload[name] = assert(package.loadlib(path, symbol))\n    end\n  end\nend\npreload_modules(modules)\narg[0] = '${TESTFILEABS}'\ntable.remove(arg, 1)\nreturn assert(loadfile '${TESTFILEABS}')(unpack(arg))\n\"    )\n    if ( _ARG_WORKING_DIRECTORY )\n      get_filename_component (\n         TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE )\n      # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.\n      set ( _pre ${CMAKE_COMMAND} -E chdir \"${TESTCURRENTDIRABS}\" )\n    endif ()\n    file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})\n    add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA}\n               ${TESTWRAPPER} \"${CMAKE_CFG_INTDIR}\"\n               ${_ARG_DEFAULT_ARGS} )\n  endif ()\n  # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake\n  # Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper\n  # expansion by the native build tool.\nendmacro ()\n\n\n# Converts Lua source file `_source` to binary string embedded in C source\n# file `_target`.  Optionally compiles Lua source to byte code (not available\n# under LuaJIT2, which doesn't have a bytecode loader).  Additionally, Lua\n# versions of bin2c [1] and luac [2] may be passed respectively as additional\n# arguments.\n#\n# [1] http://lua-users.org/wiki/BinToCee\n# [2] http://lua-users.org/wiki/LuaCompilerInLua\nfunction ( add_lua_bin2c _target _source )\n  find_program ( LUA NAMES lua lua.bat )\n  execute_process ( COMMAND ${LUA} -e \"string.dump(function()end)\"\n                    RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET )\n  if ( NOT ${_LUA_DUMP_RESULT} )\n    SET ( HAVE_LUA_DUMP true )\n  endif ()\n  message ( \"-- string.dump=${HAVE_LUA_DUMP}\" )\n\n  if ( ARGV2 )\n    get_filename_component ( BIN2C ${ARGV2} ABSOLUTE )\n    set ( BIN2C ${LUA} ${BIN2C} )\n  else ()\n    find_program ( BIN2C NAMES bin2c bin2c.bat )\n  endif ()\n  if ( HAVE_LUA_DUMP )\n    if ( ARGV3 )\n      get_filename_component ( LUAC ${ARGV3} ABSOLUTE )\n      set ( LUAC ${LUA} ${LUAC} )\n    else ()\n      find_program ( LUAC NAMES luac luac.bat )\n    endif ()\n  endif ( HAVE_LUA_DUMP )\n  message ( \"-- bin2c=${BIN2C}\" )\n  message ( \"-- luac=${LUAC}\" )\n\n  get_filename_component ( SOURCEABS ${_source} ABSOLUTE )\n  if ( HAVE_LUA_DUMP )\n    get_filename_component ( SOURCEBASE ${_source} NAME_WE )\n    add_custom_command (\n      OUTPUT  ${_target} DEPENDS ${_source}\n      COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo\n              ${SOURCEABS}\n      COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo\n              \">${_target}\" )\n  else ()\n    add_custom_command (\n      OUTPUT  ${_target} DEPENDS ${SOURCEABS}\n      COMMAND ${BIN2C} ${_source} \">${_target}\" )\n  endif ()\nendfunction()\n"
  },
  {
    "path": "build/lua-5.3.3/dist.info",
    "content": "--- This file is part of LuaDist project\n\nname = \"lua\"\nversion = \"5.3.2\"\n\ndesc = \"Lua is a powerful, fast, light-weight, embeddable scripting language.\"\nauthor = \"Roberto Ierusalimschy, Waldemar Celes, Luiz Henrique de Figueiredo\"\nlicense = \"MIT/X11\"\nurl = \"http://www.lua.org\"\nmaintainer = \"Peter Drahoš\"\n\n"
  },
  {
    "path": "build/lua-5.3.3/doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"index.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nThe reference manual is the official definition of the Lua language.\n<BR>\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/pil/\">Programming in Lua</A>.\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2016 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<A HREF=\"http://www.lua.org/license.html\">Lua license</A>.\n</SMALL>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL CLASS=\"contents menubar\">\n<LI><A HREF=\"manual.html\">1 &ndash; Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 &ndash; Basic Concepts</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 &ndash; Values and Types</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 &ndash; Environments and the Global Environment</A>\n<LI><A HREF=\"manual.html#2.3\">2.3 &ndash; Error Handling</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 &ndash; Metatables and Metamethods</A>\n<LI><A HREF=\"manual.html#2.5\">2.5 &ndash; Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 &ndash; Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 &ndash; Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 &ndash; Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 &ndash; The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 &ndash; Lexical Conventions</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 &ndash; Variables</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 &ndash; Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#3.3.1\">3.3.1 &ndash; Blocks</A>\n<LI><A HREF=\"manual.html#3.3.2\">3.3.2 &ndash; Chunks</A>\n<LI><A HREF=\"manual.html#3.3.3\">3.3.3 &ndash; Assignment</A>\n<LI><A HREF=\"manual.html#3.3.4\">3.3.4 &ndash; Control Structures</A>\n<LI><A HREF=\"manual.html#3.3.5\">3.3.5 &ndash; For Statement</A>\n<LI><A HREF=\"manual.html#3.3.6\">3.3.6 &ndash; Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#3.3.7\">3.3.7 &ndash; Local Declarations</A>\n</UL>\n<LI><A HREF=\"manual.html#3.4\">3.4 &ndash; Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#3.4.1\">3.4.1 &ndash; Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#3.4.2\">3.4.2 &ndash; Bitwise Operators</A>\n<LI><A HREF=\"manual.html#3.4.3\">3.4.3 &ndash; Coercions and Conversions</A>\n<LI><A HREF=\"manual.html#3.4.4\">3.4.4 &ndash; Relational Operators</A>\n<LI><A HREF=\"manual.html#3.4.5\">3.4.5 &ndash; Logical Operators</A>\n<LI><A HREF=\"manual.html#3.4.6\">3.4.6 &ndash; Concatenation</A>\n<LI><A HREF=\"manual.html#3.4.7\">3.4.7 &ndash; The Length Operator</A>\n<LI><A HREF=\"manual.html#3.4.8\">3.4.8 &ndash; Precedence</A>\n<LI><A HREF=\"manual.html#3.4.9\">3.4.9 &ndash; Table Constructors</A>\n<LI><A HREF=\"manual.html#3.4.10\">3.4.10 &ndash; Function Calls</A>\n<LI><A HREF=\"manual.html#3.4.11\">3.4.11 &ndash; Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#3.5\">3.5 &ndash; Visibility Rules</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 &ndash; The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 &ndash; The Stack</A>\n<LI><A HREF=\"manual.html#4.2\">4.2 &ndash; Stack Size</A>\n<LI><A HREF=\"manual.html#4.3\">4.3 &ndash; Valid and Acceptable Indices</A>\n<LI><A HREF=\"manual.html#4.4\">4.4 &ndash; C Closures</A>\n<LI><A HREF=\"manual.html#4.5\">4.5 &ndash; Registry</A>\n<LI><A HREF=\"manual.html#4.6\">4.6 &ndash; Error Handling in C</A>\n<LI><A HREF=\"manual.html#4.7\">4.7 &ndash; Handling Yields in C</A>\n<LI><A HREF=\"manual.html#4.8\">4.8 &ndash; Functions and Types</A>\n<LI><A HREF=\"manual.html#4.9\">4.9 &ndash; The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 &ndash; The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 &ndash; Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 &ndash; Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#6.1\">6.1 &ndash; Basic Functions</A>\n<LI><A HREF=\"manual.html#6.2\">6.2 &ndash; Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#6.3\">6.3 &ndash; Modules</A>\n<LI><A HREF=\"manual.html#6.4\">6.4 &ndash; String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#6.4.1\">6.4.1 &ndash; Patterns</A>\n<LI><A HREF=\"manual.html#6.4.2\">6.4.2 &ndash; Format Strings for Pack and Unpack</A>\n</UL>\n<LI><A HREF=\"manual.html#6.5\">6.5 &ndash; UTF-8 Support</A>\n<LI><A HREF=\"manual.html#6.6\">6.6 &ndash; Table Manipulation</A>\n<LI><A HREF=\"manual.html#6.7\">6.7 &ndash; Mathematical Functions</A>\n<LI><A HREF=\"manual.html#6.8\">6.8 &ndash; Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#6.9\">6.9 &ndash; Operating System Facilities</A>\n<LI><A HREF=\"manual.html#6.10\">6.10 &ndash; The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#7\">7 &ndash; Lua Standalone</A>\n<P>\n<LI><A HREF=\"manual.html#8\">8 &ndash; Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#8.1\">8.1 &ndash; Changes in the Language</A>\n<LI><A HREF=\"manual.html#8.2\">8.2 &ndash; Changes in the Libraries</A>\n<LI><A HREF=\"manual.html#8.3\">8.3 &ndash; Changes in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#9\">9 &ndash; The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE CLASS=\"menubar\" WIDTH=\"100%\">\n<TR>\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<P>\n<A HREF=\"manual.html#6.1\">basic</A><BR>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawlen\">rawlen</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.2\">coroutine</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.isyieldable\">coroutine.isyieldable</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.10\">debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.getuservalue\">debug.getuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setuservalue\">debug.setuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvalueid\">debug.upvalueid</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvaluejoin\">debug.upvaluejoin</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.8\">io</A><BR>\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<P>\n<A HREF=\"manual.html#6.7\">math</A><BR>\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.maxinteger\">math.maxinteger</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.mininteger\">math.mininteger</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tointeger\">math.tointeger</A><BR>\n<A HREF=\"manual.html#pdf-math.type\">math.type</A><BR>\n<A HREF=\"manual.html#pdf-math.ult\">math.ult</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.9\">os</A><BR>\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.3\">package</A><BR>\n<A HREF=\"manual.html#pdf-package.config\">package.config</A><BR>\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.searchers\">package.searchers</A><BR>\n<A HREF=\"manual.html#pdf-package.searchpath\">package.searchpath</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.4\">string</A><BR>\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.pack\">string.pack</A><BR>\n<A HREF=\"manual.html#pdf-string.packsize\">string.packsize</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.unpack\">string.unpack</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.6\">table</A><BR>\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.move\">table.move</A><BR>\n<A HREF=\"manual.html#pdf-table.pack\">table.pack</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n<A HREF=\"manual.html#pdf-table.unpack\">table.unpack</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.5\">utf8</A><BR>\n<A HREF=\"manual.html#pdf-utf8.char\">utf8.char</A><BR>\n<A HREF=\"manual.html#pdf-utf8.charpattern\">utf8.charpattern</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codepoint\">utf8.codepoint</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codes\">utf8.codes</A><BR>\n<A HREF=\"manual.html#pdf-utf8.len\">utf8.len</A><BR>\n<A HREF=\"manual.html#pdf-utf8.offset\">utf8.offset</A><BR>\n\n<H3><A NAME=\"env\">environment<BR>variables</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_CPATH\">LUA_CPATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_CPATH_5_3\">LUA_CPATH_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT\">LUA_INIT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT_5_3\">LUA_INIT_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH\">LUA_PATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH_5_3\">LUA_PATH_5_3</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"api\">C API</A></H3>\n<P>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_KContext\">lua_KContext</A><BR>\n<A HREF=\"manual.html#lua_KFunction\">lua_KFunction</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Unsigned\">lua_Unsigned</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n\n<P>\n<A HREF=\"manual.html#lua_absindex\">lua_absindex</A><BR>\n<A HREF=\"manual.html#lua_arith\">lua_arith</A><BR>\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_callk\">lua_callk</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_compare\">lua_compare</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_copy\">lua_copy</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getextraspace\">lua_getextraspace</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_geti\">lua_geti</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_getuservalue\">lua_getuservalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_isinteger\">lua_isinteger</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_isyieldable\">lua_isyieldable</A><BR>\n<A HREF=\"manual.html#lua_len\">lua_len</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdata\">lua_newuserdata</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_numbertointeger\">lua_numbertointeger</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pcallk\">lua_pcallk</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushglobaltable\">lua_pushglobaltable</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawgetp\">lua_rawgetp</A><BR>\n<A HREF=\"manual.html#lua_rawlen\">lua_rawlen</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_rawsetp\">lua_rawsetp</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_rotate\">lua_rotate</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_seti\">lua_seti</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_setuservalue\">lua_setuservalue</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_stringtonumber\">lua_stringtonumber</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tointegerx\">lua_tointegerx</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_tonumberx\">lua_tonumberx</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueid\">lua_upvalueid</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_upvaluejoin\">lua_upvaluejoin</A><BR>\n<A HREF=\"manual.html#lua_version\">lua_version</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n<A HREF=\"manual.html#lua_yieldk\">lua_yieldk</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"auxlib\">auxiliary library</A></H3>\n<P>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<A HREF=\"manual.html#luaL_Stream\">luaL_Stream</A><BR>\n\n<P>\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_buffinitsize\">luaL_buffinitsize</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_checkversion\">luaL_checkversion</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_execresult\">luaL_execresult</A><BR>\n<A HREF=\"manual.html#luaL_fileresult\">luaL_fileresult</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_getsubtable\">luaL_getsubtable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_len\">luaL_len</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadbufferx\">luaL_loadbufferx</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadfilex\">luaL_loadfilex</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newlib\">luaL_newlib</A><BR>\n<A HREF=\"manual.html#luaL_newlibtable\">luaL_newlibtable</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffsize\">luaL_prepbuffsize</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_pushresultsize\">luaL_pushresultsize</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_requiref\">luaL_requiref</A><BR>\n<A HREF=\"manual.html#luaL_setfuncs\">luaL_setfuncs</A><BR>\n<A HREF=\"manual.html#luaL_setmetatable\">luaL_setmetatable</A><BR>\n<A HREF=\"manual.html#luaL_testudata\">luaL_testudata</A><BR>\n<A HREF=\"manual.html#luaL_tolstring\">luaL_tolstring</A><BR>\n<A HREF=\"manual.html#luaL_traceback\">luaL_traceback</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n<H3><A NAME=\"library\">standard library</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-luaopen_base\">luaopen_base</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_coroutine\">luaopen_coroutine</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_debug\">luaopen_debug</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_io\">luaopen_io</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_math\">luaopen_math</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_os\">luaopen_os</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_package\">luaopen_package</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_string\">luaopen_string</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_table\">luaopen_table</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_utf8\">luaopen_utf8</A><BR>\n\n<H3><A NAME=\"constants\">constants</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_ERRERR\">LUA_ERRERR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRFILE\">LUA_ERRFILE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRGCMM\">LUA_ERRGCMM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRMEM\">LUA_ERRMEM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRRUN\">LUA_ERRRUN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRSYNTAX\">LUA_ERRSYNTAX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCALL\">LUA_HOOKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCOUNT\">LUA_HOOKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKLINE\">LUA_HOOKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKRET\">LUA_HOOKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKTAILCALL\">LUA_HOOKTAILCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCALL\">LUA_MASKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCOUNT\">LUA_MASKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKLINE\">LUA_MASKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKRET\">LUA_MASKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MAXINTEGER\">LUA_MAXINTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MININTEGER\">LUA_MININTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MINSTACK\">LUA_MINSTACK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MULTRET\">LUA_MULTRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_NOREF\">LUA_NOREF</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OK\">LUA_OK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPADD\">LUA_OPADD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBAND\">LUA_OPBAND</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBNOT\">LUA_OPBNOT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBOR\">LUA_OPBOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBXOR\">LUA_OPBXOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPDIV\">LUA_OPDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPEQ\">LUA_OPEQ</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPIDIV\">LUA_OPIDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLE\">LUA_OPLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLT\">LUA_OPLT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMOD\">LUA_OPMOD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMUL\">LUA_OPMUL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPPOW\">LUA_OPPOW</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHL\">LUA_OPSHL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHR\">LUA_OPSHR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSUB\">LUA_OPSUB</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPUNM\">LUA_OPUNM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REFNIL\">LUA_REFNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REGISTRYINDEX\">LUA_REGISTRYINDEX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_GLOBALS\">LUA_RIDX_GLOBALS</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_MAINTHREAD\">LUA_RIDX_MAINTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TBOOLEAN\">LUA_TBOOLEAN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TFUNCTION\">LUA_TFUNCTION</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TLIGHTUSERDATA\">LUA_TLIGHTUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNIL\">LUA_TNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNONE\">LUA_TNONE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNUMBER\">LUA_TNUMBER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TSTRING\">LUA_TSTRING</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTABLE\">LUA_TTABLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTHREAD\">LUA_TTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TUSERDATA\">LUA_TUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_USE_APICHECK\">LUA_USE_APICHECK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_YIELD\">LUA_YIELD</A><BR>\n<A HREF=\"manual.html#pdf-LUAL_BUFFERSIZE\">LUAL_BUFFERSIZE</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n\n<P CLASS=\"footer\">\nLast update:\nThu Jan 14 10:14:28 BRST 2016\n</P>\n<!--\nLast change: revised for Lua 5.3.3\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.3/doc/index.css",
    "content": "ul {\n\tlist-style-type: none ;\n}\n\nul.contents {\n\tpadding: 0 ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\ttext-align: left ;\n\tline-height: 1.25 ;\n\twidth: 15% ;\n}\n"
  },
  {
    "path": "build/lua-5.3.3/doc/lua.1",
    "content": ".TH LUA 1 \"$Date: 2014/12/10 15:55:45 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the standalone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nThe given\n.I options\nare handled in order and then\nthe Lua program in file\n.I script\nis loaded and executed.\nThe given\n.I args\nare available to\n.I script\nas strings in a global table named\n.BR arg .\nIf no options or arguments are given,\nthen\n.B \"\\-v \\-i\"\nis assumed when the standard input is a terminal;\notherwise,\n.B \"\\-\"\nis assumed.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf the line contains an expression or list of expressions,\nthen the line is evaluated and the results are printed.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\n.LP\nAt the very start,\nbefore even handling the command line,\n.B lua\nchecks the contents of the environment variables\n.B LUA_INIT_5_3\nor\n.BR LUA_INIT ,\nin that order.\nIf the contents is of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n.SH OPTIONS\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\n.TP\n.B \\-i\nenter interactive mode after executing\n.IR script .\n.TP\n.BI \\-l \" name\"\nexecute the equivalent of\n.IB name =require(' name ')\nbefore executing\n.IR script .\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-E\nignore environment variables.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and execute the standard input as a file.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nThe documentation at lua.org,\nespecially section 7 of the reference manual.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.3/doc/lua.css",
    "content": "html {\n\tbackground-color: #F8F8F8 ;\n}\n\nbody {\n\tbackground-color: #FFFFFF ;\n\tcolor: #000000 ;\n\tfont-family: Helvetica, Arial, sans-serif ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n\tmargin: 16px auto ;\n\tpadding: 32px ;\n\tborder: solid #a0a0a0 1px ;\n\tborder-radius: 20px ;\n\tmax-width: 70em ;\n\twidth: 90% ;\n}\n\nh1, h2, h3, h4 {\n\tcolor: #000080 ;\n\tfont-family: Verdana, Geneva, sans-serif ;\n\tfont-weight: normal ;\n\tfont-style: normal ;\n\ttext-align: left ;\n}\n\nh1 {\n\tfont-size: 28pt ;\n}\n\nh1 img {\n\tvertical-align: text-bottom ;\n}\n\nh2:before {\n\tcontent: \"\\2756\" ;\n\tpadding-right: 0.5em ;\n}\n\na {\n\ttext-decoration: none ;\n}\n\na:link {\n\tcolor: #000080 ;\n}\n\na:link:hover, a:visited:hover {\n\tbackground-color: #D0D0FF ;\n\tcolor: #000080 ;\n\tborder-radius: 4px ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\ndiv.menubar {\n\tpadding-bottom: 0.5em ;\n}\n\np.menubar {\n\tmargin-left: 2.5em ;\n}\n\n.menubar a:hover  {\n\tmargin: -3px -3px -3px -3px ;\n\tpadding: 3px  3px  3px  3px ;\n\tborder-radius: 4px ;\n}\n\n:target {\n\tbackground-color: #F0F0F0 ;\n\tmargin: -8px ;\n\tpadding: 8px ;\n\tborder-radius: 8px ;\n\toutline: none ;\n}\n\nhr {\n\tdisplay: none ;\n}\n\ntable hr {\n\tbackground-color: #a0a0a0 ;\n\tcolor: #a0a0a0 ;\n\tborder: 0 ;\n\theight: 1px ;\n\tdisplay: block ;\n}\n\n.footer {\n\tcolor: gray ;\n\tfont-size: x-small ;\n\ttext-transform: lowercase ;\n}\n\ninput[type=text] {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 2em ;\n\tbackground-image: url('images/search.png') ;\n\tbackground-repeat: no-repeat ;\n\tbackground-position: 4px center ;\n\tpadding-left: 20px ;\n\theight: 2em ;\n}\n\npre.session {\n\tbackground-color: #F8F8F8 ;\n\tpadding: 1em ;\n\tborder-radius: 8px ;\n}\n\ntd.gutter {\n\twidth: 4% ;\n}\n\ntable.columns {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntable.columns td {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\tpadding-bottom: 1em ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n}\n\np.logos a:link:hover, p.logos a:visited:hover {\n\tbackground-color: inherit ;\n}\n\ntable.book {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntable.book td {\n\tpadding: 0 ;\n\tvertical-align: top ;\n}\n\ntable.book td.cover {\n\tpadding-right: 1em ;\n}\n\ntable.book img {\n\tborder: solid #000080 1px ;\n}\n\ntable.book span {\n\tfont-size: small ;\n\ttext-align: left ;\n\tdisplay: block ;\n\tmargin-top: 0.25em ;\n}\n\nimg {\n\tbackground-color: white ;\n}\n"
  },
  {
    "path": "build/lua-5.3.3/doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $\n.TH LUAC 1 \"$Date: 2011/11/16 13:53:40 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files containing precompiled chunks\nthat can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\n.B luac\nproduces a single output file containing the combined bytecodes\nfor all files given.\nExecuting the combined file is equivalent to executing the given files.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nPrecompiled chunks are\n.I not\nportable across different architectures.\nMoreover,\nthe internal format of precompiled chunks\nis likely to change when a new version of Lua is released.\nMake sure you save the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\nUse\n.B \\-l \\-l\nfor a full listing.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be one of the given files because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file loads without errors.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nIn particular,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and process standard input.\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nThe documentation at lua.org.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.3/doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n\tfont-size: inherit ;\n}\n\npre, code {\n\tfont-size: 12pt ;\n}\n\nspan.apii {\n\tcolor: gray ;\n\tfloat: right ;\n\tfont-family: inherit ;\n\tfont-style: normal ;\n\tfont-size: small ;\n}\n\nh2:before {\n\tcontent: \"\" ;\n\tpadding-right: 0em ;\n}\n"
  },
  {
    "path": "build/lua-5.3.3/doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2016 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html\">Lua license</a>.\n</SMALL>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"contents.html#contents\">contents</A>\n&middot;\n<A HREF=\"contents.html#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of,v 1.162 2016/05/30 15:57:03 roberto Exp $ -->\n\n\n\n\n<h1>1 &ndash; <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is a powerful, efficient, lightweight, embeddable scripting language.\nIt supports procedural programming,\nobject-oriented programming, functional programming,\ndata-driven programming, and data description.\n\n\n<p>\nLua combines simple procedural syntax with powerful data description\nconstructs based on associative arrays and extensible semantics.\nLua is dynamically typed,\nruns by interpreting bytecode with a register-based\nvirtual machine,\nand has automatic memory management with\nincremental garbage collection,\nmaking it ideal for configuration, scripting,\nand rapid prototyping.\n\n\n<p>\nLua is implemented as a library, written in <em>clean C</em>,\nthe common subset of Standard&nbsp;C and C++.\nThe Lua distribution includes a host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete,\nstandalone Lua interpreter,\nfor interactive or batch use.\nLua is intended to be used both as a powerful, lightweight,\nembeddable scripting language for any program that needs one,\nand as a powerful but lightweight and efficient stand-alone language.\n\n\n<p>\nAs an extension language, Lua has no notion of a \"main\" program:\nit works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\n(Frequently, this host is the stand-alone <code>lua</code> program.)\nThe host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua</em>.\n\n\n\n<h1>2 &ndash; <a name=\"2\">Basic Concepts</a></h1>\n\n<p>\nThis section describes the basic concepts of the language.\n\n\n\n<h2>2.1 &ndash; <a name=\"2.1\">Values and Types</a></h2>\n\n<p>\nLua is a <em>dynamically typed language</em>.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are <em>first-class values</em>.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\nThe type <em>nil</em> has one single value, <b>nil</b>,\nwhose main property is to be different from any other value;\nit usually represents the absence of a useful value.\nThe type <em>boolean</em> has two values, <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nany other value makes it true.\nThe type <em>number</em> represents both\ninteger numbers and real (floating-point) numbers.\nThe type <em>string</em> represents immutable sequences of bytes.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit value,\nincluding embedded zeros ('<code>\\0</code>').\nLua is also encoding-agnostic;\nit makes no assumptions about the contents of a string.\n\n\n<p>\nThe type <em>number</em> uses two internal representations,\nor two subtypes,\none called <em>integer</em> and the other called <em>float</em>.\nLua has explicit rules about when each representation is used,\nbut it also converts between them automatically as needed (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\nTherefore,\nthe programmer may choose to mostly ignore the difference\nbetween integers and floats\nor to assume complete control over the representation of each number.\nStandard Lua uses 64-bit integers and double-precision (64-bit) floats,\nbut you can also compile Lua so that it\nuses 32-bit integers and/or single-precision (32-bit) floats.\nThe option with 32 bits for both integers and floats\nis particularly attractive\nfor small machines and embedded systems.\n(See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C (see <a href=\"#3.4.10\">&sect;3.4.10</a>).\nBoth are represented by the type <em>function</em>.\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nA userdata value represents a block of raw memory.\nThere are two kinds of userdata:\n<em>full userdata</em>,\nwhich is an object with a block of memory managed by Lua,\nand <em>light userdata</em>,\nwhich is simply a C&nbsp;pointer value.\nUserdata has no predefined operations in Lua,\nexcept assignment and identity test.\nBy using <em>metatables</em>,\nthe programmer can define operations for full userdata values\n(see <a href=\"#2.4\">&sect;2.4</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by the host program.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.6\">&sect;2.6</a>).\nLua threads are not related to operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads natively.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can be indexed not only with numbers,\nbut with any Lua value except <b>nil</b> and NaN.\n(<em>Not a Number</em> is a special value used to represent\nundefined or unrepresentable numerical results, such as <code>0/0</code>.)\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nAny key with value <b>nil</b> is not considered part of the table.\nConversely, any key that is not part of a table has\nan associated value <b>nil</b>.\n\n\n<p>\nTables are the sole data-structuring mechanism in Lua;\nthey can be used to represent ordinary arrays, sequences,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#3.4.9\">&sect;3.4.9</a>).\n\n\n<p>\nWe use the term <em>sequence</em> to denote a table where\nthe set of all positive numeric keys is equal to {1..<em>n</em>}\nfor some non-negative integer <em>n</em>,\nwhich is called the length of the sequence (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\n\n\n<p>\nLike indices,\nthe values of table fields can be of any type.\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#3.4.11\">&sect;3.4.11</a>).\n\n\n<p>\nThe indexing of tables follows\nthe definition of raw equality in the language.\nThe expressions <code>a[i]</code> and <code>a[j]</code>\ndenote the same table element\nif and only if <code>i</code> and <code>j</code> are raw equal\n(that is, equal without metamethods).\nIn particular, floats with integral values\nare equal to their respective integers\n(e.g., <code>1.0 == 1</code>).\nTo avoid ambiguities,\nany float with integral value used as a key\nis converted to its respective integer.\nFor instance, if you write <code>a[2.0] = true</code>,\nthe actual key inserted into the table will be the\ninteger <code>2</code>.\n(On the other hand,\n2 and \"<code>2</code>\" are different Lua values and therefore\ndenote different table entries.)\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value (see <a href=\"#6.1\">&sect;6.1</a>).\n\n\n\n\n\n<h2>2.2 &ndash; <a name=\"2.2\">Environments and the Global Environment</a></h2>\n\n<p>\nAs will be discussed in <a href=\"#3.2\">&sect;3.2</a> and <a href=\"#3.3.3\">&sect;3.3.3</a>,\nany reference to a free name\n(that is, a name not bound to any declaration) <code>var</code>\nis syntactically translated to <code>_ENV.var</code>.\nMoreover, every chunk is compiled in the scope of\nan external local variable named <code>_ENV</code> (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nso <code>_ENV</code> itself is never a free name in a chunk.\n\n\n<p>\nDespite the existence of this external <code>_ENV</code> variable and\nthe translation of free names,\n<code>_ENV</code> is a completely regular name.\nIn particular,\nyou can define new variables and parameters with that name.\nEach reference to a free name uses the <code>_ENV</code> that is\nvisible at that point in the program,\nfollowing the usual visibility rules of Lua (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nAny table used as the value of <code>_ENV</code> is called an <em>environment</em>.\n\n\n<p>\nLua keeps a distinguished environment called the <em>global environment</em>.\nThis value is kept at a special index in the C registry (see <a href=\"#4.5\">&sect;4.5</a>).\nIn Lua, the global variable <a href=\"#pdf-_G\"><code>_G</code></a> is initialized with this same value.\n(<a href=\"#pdf-_G\"><code>_G</code></a> is never used internally.)\n\n\n<p>\nWhen Lua loads a chunk,\nthe default value for its <code>_ENV</code> upvalue\nis the global environment (see <a href=\"#pdf-load\"><code>load</code></a>).\nTherefore, by default,\nfree names in Lua code refer to entries in the global environment\n(and, therefore, they are also called <em>global variables</em>).\nMoreover, all standard libraries are loaded in the global environment\nand some functions there operate on that environment.\nYou can use <a href=\"#pdf-load\"><code>load</code></a> (or <a href=\"#pdf-loadfile\"><code>loadfile</code></a>)\nto load a chunk with a different environment.\n(In C, you have to load the chunk and then change the value\nof its first upvalue.)\n\n\n\n\n\n<h2>2.3 &ndash; <a name=\"2.3\">Error Handling</a></h2>\n\n<p>\nBecause Lua is an embedded extension language,\nall Lua actions start from C&nbsp;code in the host program\ncalling a function from the Lua library.\n(When you use Lua standalone,\nthe <code>lua</code> application is the host program.)\nWhenever an error occurs during\nthe compilation or execution of a Lua chunk,\ncontrol returns to the host,\nwhich can take appropriate measures\n(such as printing an error message).\n\n\n<p>\nLua code can explicitly generate an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\nIf you need to catch errors in Lua,\nyou can use <a href=\"#pdf-pcall\"><code>pcall</code></a> or <a href=\"#pdf-xpcall\"><code>xpcall</code></a>\nto call a given function in <em>protected mode</em>.\n\n\n<p>\nWhenever there is an error,\nan <em>error object</em> (also called an <em>error message</em>)\nis propagated with information about the error.\nLua itself only generates errors whose error object is a string,\nbut programs may generate errors with\nany value as the error object.\nIt is up to the Lua program or its host to handle such error objects.\n\n\n<p>\nWhen you use <a href=\"#pdf-xpcall\"><code>xpcall</code></a> or <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nyou may give a <em>message handler</em>\nto be called in case of errors.\nThis function is called with the original error object\nand returns a new error object.\nIt is called before the error unwinds the stack,\nso that it can gather more information about the error,\nfor instance by inspecting the stack and creating a stack traceback.\nThis message handler is still protected by the protected call;\nso, an error inside the message handler\nwill call the message handler again.\nIf this loop goes on for too long,\nLua breaks it and returns an appropriate message.\n\n\n\n\n\n<h2>2.4 &ndash; <a name=\"2.4\">Metatables and Metamethods</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain special operations.\nYou can change several aspects of the behavior\nof operations over a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field \"<code>__add</code>\" of the value's metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nThe key for each event in a metatable is a string\nwith the event name prefixed by two underscores;\nthe corresponding values are called <em>metamethods</em>.\nIn the previous example, the key is \"<code>__add</code>\"\nand the metamethod is the function that performs the addition.\n\n\n<p>\nYou can query the metatable of any value\nusing the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\nLua queries metamethods in metatables using a raw access (see <a href=\"#pdf-rawget\"><code>rawget</code></a>).\nSo, to retrieve the metamethod for event <code>ev</code> in object <code>o</code>,\nLua does the equivalent to the following code:\n\n<pre>\n     rawget(getmetatable(<em>o</em>) or {}, \"__<em>ev</em>\")\n</pre>\n\n<p>\nYou can replace the metatable of tables\nusing the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a> function.\nYou cannot change the metatable of other types from Lua code\n(except by using the debug library (<a href=\"#6.10\">&sect;6.10</a>));\nyou should use the C&nbsp;API for that.\n\n\n<p>\nTables and full userdata have individual metatables\n(although multiple tables and userdata can share their metatables).\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\nBy default, a value has no metatable,\nbut the string library sets a metatable for the string type (see <a href=\"#6.4\">&sect;6.4</a>).\n\n\n<p>\nA metatable controls how an object behaves in\narithmetic operations, bitwise operations,\norder comparisons, concatenation, length operation, calls, and indexing.\nA metatable also can define a function to be called\nwhen a userdata or a table is garbage collected (<a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nFor the unary operators (negation, length, and bitwise NOT),\nthe metamethod is computed and called with a dummy second operand,\nequal to the first one.\nThis extra operand is only to simplify Lua's internals\n(by making these operators behave like a binary operation)\nand may be removed in future versions.\n(For most uses this extra operand is irrelevant.)\n\n\n<p>\nA detailed list of events controlled by metatables is given next.\nEach operation is identified by its corresponding key.\n\n\n\n<ul>\n\n<li><b><code>__add</code>: </b>\nthe addition (<code>+</code>) operation.\nIf any operand for an addition is not a number\n(nor a string coercible to a number),\nLua will try to call a metamethod.\nFirst, Lua will check the first operand (even if it is valid).\nIf that operand does not define a metamethod for <code>__add</code>,\nthen Lua will check the second operand.\nIf Lua can find a metamethod,\nit calls the metamethod with the two operands as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nOtherwise,\nit raises an error.\n</li>\n\n<li><b><code>__sub</code>: </b>\nthe subtraction (<code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mul</code>: </b>\nthe multiplication (<code>*</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__div</code>: </b>\nthe division (<code>/</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mod</code>: </b>\nthe modulo (<code>%</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__pow</code>: </b>\nthe exponentiation (<code>^</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__unm</code>: </b>\nthe negation (unary <code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__idiv</code>: </b>\nthe floor division (<code>//</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__band</code>: </b>\nthe bitwise AND (<code>&amp;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither an integer\nnor a value coercible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\n</li>\n\n<li><b><code>__bor</code>: </b>\nthe bitwise OR (<code>|</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bxor</code>: </b>\nthe bitwise exclusive OR (binary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bnot</code>: </b>\nthe bitwise NOT (unary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shl</code>: </b>\nthe bitwise left shift (<code>&lt;&lt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shr</code>: </b>\nthe bitwise right shift (<code>&gt;&gt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__concat</code>: </b>\nthe concatenation (<code>..</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither a string nor a number\n(which is always coercible to a string).\n</li>\n\n<li><b><code>__len</code>: </b>\nthe length (<code>#</code>) operation.\nIf the object is not a string,\nLua will try its metamethod.\nIf there is a metamethod,\nLua calls it with the object as argument,\nand the result of the call\n(always adjusted to one value)\nis the result of the operation.\nIf there is no metamethod but the object is a table,\nthen Lua uses the table length operation (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nOtherwise, Lua raises an error.\n</li>\n\n<li><b><code>__eq</code>: </b>\nthe equal (<code>==</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are either both tables or both full userdata\nand they are not primitively equal.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__lt</code>: </b>\nthe less than (<code>&lt;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are neither both numbers nor both strings.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__le</code>: </b>\nthe less equal (<code>&lt;=</code>) operation.\nUnlike other operations,\nthe less-equal operation can use two different events.\nFirst, Lua looks for the <code>__le</code> metamethod in both operands,\nlike in the less than operation.\nIf it cannot find such a metamethod,\nthen it will try the <code>__lt</code> metamethod,\nassuming that <code>a &lt;= b</code> is equivalent to <code>not (b &lt; a)</code>.\nAs with the other comparison operators,\nthe result is always a boolean.\n(This use of the <code>__lt</code> event can be removed in future versions;\nit is also slower than a real <code>__le</code> metamethod.)\n</li>\n\n<li><b><code>__index</code>: </b>\nThe indexing access <code>table[key]</code>.\nThis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nDespite the name,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code> and <code>key</code> as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nIf it is a table,\nthe final result is the result of indexing this table with <code>key</code>.\n(This indexing is regular, not raw,\nand therefore can trigger another metamethod.)\n</li>\n\n<li><b><code>__newindex</code>: </b>\nThe indexing assignment <code>table[key] = value</code>.\nLike the index event,\nthis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nLike with indexing,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.\nIf it is a table,\nLua does an indexing assignment to this table with the same key and value.\n(This assignment is regular, not raw,\nand therefore can trigger another metamethod.)\n\n\n<p>\nWhenever there is a <code>__newindex</code> metamethod,\nLua does not perform the primitive assignment.\n(If necessary,\nthe metamethod itself can call <a href=\"#pdf-rawset\"><code>rawset</code></a>\nto do the assignment.)\n</li>\n\n<li><b><code>__call</code>: </b>\nThe call operation <code>func(args)</code>.\nThis event happens when Lua tries to call a non-function value\n(that is, <code>func</code> is not a function).\nThe metamethod is looked up in <code>func</code>.\nIf present,\nthe metamethod is called with <code>func</code> as its first argument,\nfollowed by the arguments of the original call (<code>args</code>).\nAll results of the call\nare the result of the operation.\n(This is the only metamethod that allows multiple results.)\n</li>\n\n</ul>\n\n<p>\nIt is a good practice to add all needed metamethods to a table\nbefore setting it as a metatable of some object.\nIn particular, the <code>__gc</code> metamethod works only when this order\nis followed (see <a href=\"#2.5.1\">&sect;2.5.1</a>).\n\n\n<p>\nBecause metatables are regular tables,\nthey can contain arbitrary fields,\nnot only the event names defined above.\nSome functions in the standard library\n(e.g., <a href=\"#pdf-tostring\"><code>tostring</code></a>)\nuse other fields in metatables for their own purposes.\n\n\n\n\n\n<h2>2.5 &ndash; <a name=\"2.5\">Garbage Collection</a></h2>\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou do not have to worry about allocating memory for new objects\nor freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> to collect all <em>dead objects</em>\n(that is, objects that are no longer accessible from Lua).\nAll memory used by Lua is subject to automatic management:\nstrings, tables, userdata, functions, threads, internal structures, etc.\n\n\n<p>\nLua implements an incremental mark-and-sweep collector.\nIt uses two numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em> and\nthe <em>garbage-collector step multiplier</em>.\nBoth use percentage points as units\n(e.g., a value of 100 means an internal value of 1).\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nLarger values make the collector less aggressive.\nValues smaller than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\n\n\n<p>\nThe garbage-collector step multiplier\ncontrols the relative speed of the collector relative to\nmemory allocation.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nYou should not use values smaller than 100,\nbecause they make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default is 200,\nwhich means that the collector runs at \"twice\"\nthe speed of memory allocation.\n\n\n<p>\nIf you set the step multiplier to a very large number\n(larger than 10% of the maximum number of\nbytes that the program may use),\nthe collector behaves like a stop-the-world collector.\nIf you then set the pause to 200,\nthe collector behaves as in old Lua versions,\ndoing a complete collection every time Lua doubles its\nmemory usage.\n\n\n<p>\nYou can change these numbers by calling <a href=\"#lua_gc\"><code>lua_gc</code></a> in C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nYou can also use these functions to control\nthe collector directly (e.g., stop and restart it).\n\n\n\n<h3>2.5.1 &ndash; <a name=\"2.5.1\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nYou can set garbage-collector metamethods for tables\nand, using the C&nbsp;API,\nfor full userdata (see <a href=\"#2.4\">&sect;2.4</a>).\nThese metamethods are also called <em>finalizers</em>.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management\n(such as closing files, network or database connections,\nor freeing your own memory).\n\n\n<p>\nFor an object (table or userdata) to be finalized when collected,\nyou must <em>mark</em> it for finalization.\n\nYou mark an object for finalization when you set its metatable\nand the metatable has a field indexed by the string \"<code>__gc</code>\".\nNote that if you set a metatable without a <code>__gc</code> field\nand later create that field in the metatable,\nthe object will not be marked for finalization.\n\n\n<p>\nWhen a marked object becomes garbage,\nit is not collected immediately by the garbage collector.\nInstead, Lua puts it in a list.\nAfter the collection,\nLua goes through that list.\nFor each object in the list,\nit checks the object's <code>__gc</code> metamethod:\nIf it is a function,\nLua calls it with the object as its single argument;\nif the metamethod is not a function,\nLua simply ignores it.\n\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers for objects are called in\nthe reverse order that the objects were marked for finalization,\namong those collected in that cycle;\nthat is, the first finalizer to be called is the one associated\nwith the object marked last in the program.\nThe execution of each finalizer may occur at any point during\nthe execution of the regular code.\n\n\n<p>\nBecause the object being collected must still be used by the finalizer,\nthat object (and other objects accessible only through it)\nmust be <em>resurrected</em> by Lua.\nUsually, this resurrection is transient,\nand the object memory is freed in the next garbage-collection cycle.\nHowever, if the finalizer stores the object in some global place\n(e.g., a global variable),\nthen the resurrection is permanent.\nMoreover, if the finalizer marks a finalizing object for finalization again,\nits finalizer will be called again in the next cycle where the\nobject is unreachable.\nIn any case,\nthe object memory is freed only in a GC cycle where\nthe object is unreachable and not marked for finalization.\n\n\n<p>\nWhen you close a state (see <a href=\"#lua_close\"><code>lua_close</code></a>),\nLua calls the finalizers of all objects marked for finalization,\nfollowing the reverse order that they were marked.\nIf any finalizer marks objects for collection during that phase,\nthese marks have no effect.\n\n\n\n\n\n<h3>2.5.2 &ndash; <a name=\"2.5.2\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect that object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak values allows the collection of its values,\nbut prevents the collection of its keys.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nIf the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',\nthe keys in the table are weak.\nIf <code>__mode</code> contains '<code>v</code>',\nthe values in the table are weak.\n\n\n<p>\nA table with weak keys and strong values\nis also called an <em>ephemeron table</em>.\nIn an ephemeron table,\na value is considered reachable only if its key is reachable.\nIn particular,\nif the only reference to a key comes through its value,\nthe pair is removed.\n\n\n<p>\nAny change in the weakness of a table may take effect only\nat the next collect cycle.\nIn particular, if you change the weakness to a stronger mode,\nLua may still collect some items from that table\nbefore the change takes effect.\n\n\n<p>\nOnly objects that have an explicit construction\nare removed from weak tables.\nValues, such as numbers and light C functions,\nare not subject to garbage collection,\nand therefore are not removed from weak tables\n(unless their associated values are collected).\nAlthough strings are subject to garbage collection,\nthey do not have an explicit construction,\nand therefore are not removed from weak tables.\n\n\n<p>\nResurrected objects\n(that is, objects being finalized\nand objects accessible only through objects being finalized)\nhave a special behavior in weak tables.\nThey are removed from weak values before running their finalizers,\nbut are removed from weak keys only in the next collection\nafter running their finalizers, when such objects are actually freed.\nThis behavior allows the finalizer to access properties\nassociated with the object through weak tables.\n\n\n<p>\nIf a weak table is among the resurrected objects in a collection cycle,\nit may not be properly cleared until the next cycle.\n\n\n\n\n\n\n\n<h2>2.6 &ndash; <a name=\"2.6\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine by calling <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine.\n\n\n<p>\nYou execute a coroutine by calling <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution by\ncalling its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed\nas arguments to that function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn case of normal termination,\n<a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus an error object.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> does not catch errors;\nany error is propagated to the caller.\n\n\n<p>\nAs an example of how coroutines work,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n     \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n<p>\nYou can also create and manipulate coroutines through the C API:\nsee functions <a href=\"#lua_newthread\"><code>lua_newthread</code></a>, <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nand <a href=\"#lua_yield\"><code>lua_yield</code></a>.\n\n\n\n\n\n<h1>3 &ndash; <a name=\"3\">The Language</a></h1>\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nLanguage constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.\nThe complete syntax of Lua can be found in <a href=\"#9\">&sect;9</a>\nat the end of this manual.\n\n\n\n<h2>3.1 &ndash; <a name=\"3.1\">Lexical Conventions</a></h2>\n\n<p>\nLua is a free-form language.\nIt ignores spaces (including new lines) and comments\nbetween lexical elements (tokens),\nexcept as delimiters between names and keywords.\n\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of letters,\ndigits, and underscores,\nnot beginning with a digit and\nnot being a reserved word.\nIdentifiers are used to name variables, table fields, and labels.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif    end\n     false     for       function  goto      if        in\n     local     nil       not       or        repeat    return\n     then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention,\nprograms should avoid creating \nnames that start with an underscore followed by\none or more uppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>).\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     &amp;     ~     |     &lt;&lt;    &gt;&gt;    //\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]     ::\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\n<em>Literal strings</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nA backslash followed by a real newline\nresults in a newline in the string.\nThe escape sequence '<code>\\z</code>' skips the following span\nof white-space characters,\nincluding line breaks;\nit is particularly useful to break and indent a long literal string\ninto multiple lines without adding the newlines and spaces\ninto the string contents.\n\n\n<p>\nStrings in Lua can contain any 8-bit value, including embedded zeros,\nwhich can be specified as '<code>\\0</code>'.\nMore generally,\nwe can specify any byte in a literal string by its numeric value.\nThis can be done\nwith the escape sequence <code>\\x<em>XX</em></code>,\nwhere <em>XX</em> is a sequence of exactly two hexadecimal digits,\nor with the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a decimal escape sequence is to be followed by a digit,\nit must be expressed using exactly three digits.)\n\n\n<p>\nThe UTF-8 encoding of a Unicode character\ncan be inserted in a literal string with\nthe escape sequence <code>\\u{<em>XXX</em>}</code>\n(note the mandatory enclosing brackets),\nwhere <em>XXX</em> is a sequence of one or more hexadecimal digits\nrepresenting the character code point.\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>, \nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>, \nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance,\na closing long bracket of level&nbsp;4 is written as  <code>]====]</code>.\nA <em>long literal</em> starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nIt can contain any text except a closing bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nAny kind of end-of-line sequence\n(carriage return, newline, carriage return followed by newline,\nor newline followed by carriage return)\nis converted to a simple newline.\n\n\n<p>\nAny byte in a literal string not\nexplicitly affected by the previous rules represents itself.\nHowever, Lua opens files for parsing in text mode,\nand the system file functions may have problems with\nsome control characters.\nSo, it is safer to represent\nnon-text data as a quoted literal with\nexplicit escape sequences for the non-text characters.\n\n\n<p>\nFor convenience,\nwhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nA <em>numeric constant</em> (or <em>numeral</em>)\ncan be written with an optional fractional part\nand an optional decimal exponent,\nmarked by a letter '<code>e</code>' or '<code>E</code>'.\nLua also accepts hexadecimal constants,\nwhich start with <code>0x</code> or <code>0X</code>.\nHexadecimal constants also accept an optional fractional part\nplus an optional binary exponent,\nmarked by a letter '<code>p</code>' or '<code>P</code>'.\nA numeric constant with a radix point or an exponent \ndenotes a float;\notherwise,\nif its value fits in an integer,\nit denotes an integer.\nExamples of valid integer constants are\n\n<pre>\n     3   345   0xff   0xBEBADA\n</pre><p>\nExamples of valid float constants are\n\n<pre>\n     3.0     3.1416     314.16e-2     0.31416E1     34e1\n     0x0.1E  0xA23p-4   0X1.921FB54442D18P+1\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\nLong comments are frequently used to disable code temporarily.\n\n\n\n\n\n<h2>3.2 &ndash; <a name=\"3.2\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers, as defined in <a href=\"#3.1\">&sect;3.1</a>.\n\n\n<p>\nAny variable name is assumed to be global unless explicitly declared\nas a local (see <a href=\"#3.3.7\">&sect;3.3.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;\n</pre><p>\nThe meaning of accesses to table fields can be changed via metatables.\nAn access to an indexed variable <code>t[i]</code> is equivalent to\na call <code>gettable_event(t,i)</code>.\n(See <a href=\"#2.4\">&sect;2.4</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>.</b>&rsquo; Name\n</pre>\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_ENV.x</code>.\nDue to the way that chunks are compiled,\n<code>_ENV</code> is never a global name (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h2>3.3 &ndash; <a name=\"3.3\">Statements</a></h2>\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in Pascal or C.\nThis set includes\nassignments, control structures, function calls,\nand variable declarations.\n\n\n\n<h3>3.3.1 &ndash; <a name=\"3.3.1\">Blocks</a></h3>\n\n<p>\nA block is a list of statements,\nwhich are executed sequentially:\n\n<pre>\n\tblock ::= {stat}\n</pre><p>\nLua has <em>empty statements</em>\nthat allow you to separate statements with semicolons,\nstart a block with a semicolon\nor write two semicolons in sequence:\n\n<pre>\n\tstat ::= &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nFunction calls and assignments\ncan start with an open parenthesis.\nThis possibility leads to an ambiguity in Lua's grammar.\nConsider the following fragment:\n\n<pre>\n     a = b + c\n     (print or io.write)('done')\n</pre><p>\nThe grammar could see it in two ways:\n\n<pre>\n     a = b + c(print or io.write)('done')\n     \n     a = b + c; (print or io.write)('done')\n</pre><p>\nThe current parser always sees such constructions\nin the first way,\ninterpreting the open parenthesis\nas the start of the arguments to a call.\nTo avoid this ambiguity,\nit is a good practice to always precede with a semicolon\nstatements that start with a parenthesis:\n\n<pre>\n     ;(print or io.write)('done')\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> statement in the middle\nof another block (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\n\n\n\n\n\n<h3>3.3.2 &ndash; <a name=\"3.3.2\">Chunks</a></h3>\n\n<p>\nThe unit of compilation of Lua is called a <em>chunk</em>.\nSyntactically,\na chunk is simply a block:\n\n<pre>\n\tchunk ::= block\n</pre>\n\n<p>\nLua handles a chunk as the body of an anonymous function\nwith a variable number of arguments\n(see <a href=\"#3.4.11\">&sect;3.4.11</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\nMoreover, such anonymous function is compiled as in the\nscope of an external local variable called <code>_ENV</code> (see <a href=\"#2.2\">&sect;2.2</a>).\nThe resulting function always has <code>_ENV</code> as its only upvalue,\neven if it does not use that variable.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first <em>loads</em> it,\nprecompiling the chunk's code into instructions for a virtual machine,\nand then Lua executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be precompiled into binary form;\nsee program <code>luac</code> and function <a href=\"#pdf-string.dump\"><code>string.dump</code></a> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly (see <a href=\"#pdf-load\"><code>load</code></a>).\n\n\n\n\n\n<h3>3.3.3 &ndash; <a name=\"3.3.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist &lsquo;<b>=</b>&rsquo; explist\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#3.4\">&sect;3.4</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with as many  <b>nil</b>'s as needed.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then the assignments are performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nThe meaning of assignments to global variables\nand table fields can be changed via metatables.\nAn assignment to an indexed variable <code>t[i] = val</code> is equivalent to\n<code>settable_event(t,i,val)</code>.\n(See <a href=\"#2.4\">&sect;2.4</a> for a complete description of the\n<code>settable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nAn assignment to a global name <code>x = val</code>\nis equivalent to the assignment\n<code>_ENV.x = val</code> (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h3>3.3.4 &ndash; <a name=\"3.3.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#3.3.5\">&sect;3.3.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> are considered false.\nAll values different from <b>nil</b> and <b>false</b> are considered true\n(in particular, the number 0 and the empty string are also true).\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>goto</b> statement transfers the program control to a label.\nFor syntactical reasons,\nlabels in Lua are considered statements too:\n\n\n\n<pre>\n\tstat ::= <b>goto</b> Name\n\tstat ::= label\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n</pre>\n\n<p>\nA label is visible in the entire block where it is defined,\nexcept\ninside nested blocks where a label with the same name is defined and\ninside nested functions.\nA goto may jump to any visible label as long as it does not\nenter into the scope of a local variable.\n\n\n<p>\nLabels and empty statements are called <em>void statements</em>,\nas they perform no actions.\n\n\n<p>\nThe <b>break</b> statement terminates the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk\n(which is an anonymous function).\n\nFunctions can return more than one value,\nso the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n</pre>\n\n<p>\nThe <b>return</b> statement can only be written\nas the last statement of a block.\nIf it is really necessary to <b>return</b> in the middle of a block,\nthen an explicit inner block can be used,\nas in the idiom <code>do return end</code>,\nbecause now <b>return</b> is the last statement in its (inner) block.\n\n\n\n\n\n<h3>3.3.5 &ndash; <a name=\"3.3.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numerical and one generic.\n\n\n<p>\nThe numerical <b>for</b> loop repeats a block of code while a\ncontrol variable runs through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe <em>block</em> is repeated for <em>name</em> starting at the value of\nthe first <em>exp</em>, until it passes the second <em>exp</em> by steps of the\nthird <em>exp</em>.\nMore precisely, a <b>for</b> statement like\n\n<pre>\n     for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)\n       if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end\n       <em>var</em> = <em>var</em> - <em>step</em>\n       while true do\n         <em>var</em> = <em>var</em> + <em>step</em>\n         if (<em>step</em> &gt;= 0 and <em>var</em> &gt; <em>limit</em>) or (<em>step</em> &lt; 0 and <em>var</em> &lt; <em>limit</em>) then\n           break\n         end\n         local v = <em>var</em>\n         <em>block</em>\n       end\n     end\n</pre>\n\n<p>\nNote the following:\n\n<ul>\n\n<li>\nAll three control expressions are evaluated only once,\nbefore the loop starts.\nThey must all result in numbers.\n</li>\n\n<li>\n<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.\nThe names shown here are for explanatory purposes only.\n</li>\n\n<li>\nIf the third expression (the step) is absent,\nthen a step of&nbsp;1 is used.\n</li>\n\n<li>\nYou can use <b>break</b> and <b>goto</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variable <code>v</code> is local to the loop body.\nIf you need its value after the loop,\nassign it to another variable before exiting the loop.\n</li>\n\n</ul>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>\n       while true do\n         local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)\n         if <em>var_1</em> == nil then break end\n         <em>var</em> = <em>var_1</em>\n         <em>block</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\n<code><em>explist</em></code> is evaluated only once.\nIts results are an <em>iterator</em> function,\na <em>state</em>,\nand an initial value for the first <em>iterator variable</em>.\n</li>\n\n<li>\n<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.\nThe names are here for explanatory purposes only.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variables <code><em>var_i</em></code> are local to the loop;\nyou cannot use their values after the <b>for</b> ends.\nIf you need these values,\nthen assign them to other variables before breaking or exiting the loop.\n</li>\n\n</ul>\n\n\n\n\n<h3>3.3.6 &ndash; <a name=\"3.3.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>.\n\n\n\n\n\n<h3>3.3.7 &ndash; <a name=\"3.3.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initial assignment:\n\n<pre>\n\tstat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#3.3.3\">&sect;3.3.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nA chunk is also a block (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nand so local variables can be declared in a chunk outside any explicit block.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#3.5\">&sect;3.5</a>.\n\n\n\n\n\n\n\n<h2>3.4 &ndash; <a name=\"3.4\">Expressions</a></h2>\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Numeral\n\texp ::= LiteralString\n\texp ::= functiondef\n\texp ::= tableconstructor\n\texp ::= &lsquo;<b>...</b>&rsquo;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n</pre>\n\n<p>\nNumerals and literal strings are explained in <a href=\"#3.1\">&sect;3.1</a>;\nvariables are explained in <a href=\"#3.2\">&sect;3.2</a>;\nfunction definitions are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>;\nfunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>;\ntable constructors are explained in <a href=\"#3.4.9\">&sect;3.4.9</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nbitwise operators (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nrelational operators (see <a href=\"#3.4.4\">&sect;3.4.4</a>), logical operators (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the concatenation operator (see <a href=\"#3.4.6\">&sect;3.4.6</a>).\nUnary operators comprise the unary minus (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nthe unary bitwise NOT (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nthe unary logical <b>not</b> (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the unary <em>length operator</em> (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf a function call is used as a statement (see <a href=\"#3.3.6\">&sect;3.3.6</a>),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the expression is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\neither discarding all values except the first one\nor adding a single <b>nil</b> if there are no values.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg parameter, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg parameter)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg parameters\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg parameters\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n<h3>3.4.1 &ndash; <a name=\"3.4.1\">Arithmetic Operators</a></h3><p>\nLua supports the following arithmetic operators:\n\n<ul>\n<li><b><code>+</code>: </b>addition</li>\n<li><b><code>-</code>: </b>subtraction</li>\n<li><b><code>*</code>: </b>multiplication</li>\n<li><b><code>/</code>: </b>float division</li>\n<li><b><code>//</code>: </b>floor division</li>\n<li><b><code>%</code>: </b>modulo</li>\n<li><b><code>^</code>: </b>exponentiation</li>\n<li><b><code>-</code>: </b>unary minus</li>\n</ul>\n\n<p>\nWith the exception of exponentiation and float division,\nthe arithmetic operators work as follows:\nIf both operands are integers,\nthe operation is performed over integers and the result is an integer.\nOtherwise, if both operands are numbers\nor strings that can be converted to\nnumbers (see <a href=\"#3.4.3\">&sect;3.4.3</a>),\nthen they are converted to floats,\nthe operation is performed following the usual rules\nfor floating-point arithmetic\n(usually the IEEE 754 standard),\nand the result is a float.\n\n\n<p>\nExponentiation and float division (<code>/</code>)\nalways convert their operands to floats\nand the result is always a float.\nExponentiation uses the ISO&nbsp;C function <code>pow</code>,\nso that it works for non-integer exponents too.\n\n\n<p>\nFloor division (<code>//</code>) is a division \nthat rounds the quotient towards minus infinity,\nthat is, the floor of the division of its operands.\n\n\n<p>\nModulo is defined as the remainder of a division\nthat rounds the quotient towards minus infinity (floor division).\n\n\n<p>\nIn case of overflows in integer arithmetic,\nall operations <em>wrap around</em>,\naccording to the usual rules of two-complement arithmetic.\n(In other words,\nthey return the unique representable integer\nthat is equal modulo <em>2<sup>64</sup></em> to the mathematical result.)\n\n\n\n<h3>3.4.2 &ndash; <a name=\"3.4.2\">Bitwise Operators</a></h3><p>\nLua supports the following bitwise operators:\n\n<ul>\n<li><b><code>&amp;</code>: </b>bitwise AND</li>\n<li><b><code>&#124;</code>: </b>bitwise OR</li>\n<li><b><code>~</code>: </b>bitwise exclusive OR</li>\n<li><b><code>&gt;&gt;</code>: </b>right shift</li>\n<li><b><code>&lt;&lt;</code>: </b>left shift</li>\n<li><b><code>~</code>: </b>unary bitwise NOT</li>\n</ul>\n\n<p>\nAll bitwise operations convert its operands to integers\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>),\noperate on all bits of those integers,\nand result in an integer.\n\n\n<p>\nBoth right and left shifts fill the vacant bits with zeros.\nNegative displacements shift to the other direction;\ndisplacements with absolute values equal to or higher than\nthe number of bits in an integer\nresult in zero (as all bits are shifted out).\n\n\n\n\n\n<h3>3.4.3 &ndash; <a name=\"3.4.3\">Coercions and Conversions</a></h3><p>\nLua provides some automatic conversions between some\ntypes and representations at run time.\nBitwise operators always convert float operands to integers.\nExponentiation and float division\nalways convert integer operands to floats.\nAll other arithmetic operations applied to mixed numbers\n(integers and floats) convert the integer operand to a float;\nthis is called the <em>usual rule</em>.\nThe C API also converts both integers to floats and\nfloats to integers, as needed.\nMoreover, string concatenation accepts numbers as arguments,\nbesides strings. \n\n\n<p>\nLua also converts strings to numbers,\nwhenever a number is expected.\n\n\n<p>\nIn a conversion from integer to float,\nif the integer value has an exact representation as a float,\nthat is the result.\nOtherwise,\nthe conversion gets the nearest higher or\nthe nearest lower representable value.\nThis kind of conversion never fails.\n\n\n<p>\nThe conversion from float to integer\nchecks whether the float has an exact representation as an integer\n(that is, the float has an integral value and\nit is in the range of integer representation).\nIf it does, that representation is the result.\nOtherwise, the conversion fails.\n\n\n<p>\nThe conversion from strings to numbers goes as follows:\nFirst, the string is converted to an integer or a float,\nfollowing its syntax and the rules of the Lua lexer.\n(The string may have also leading and trailing spaces and a sign.)\nThen, the resulting number (float or integer)\nis converted to the type (float or integer) required by the context\n(e.g., the operation that forced the conversion).\n\n\n<p>\nAll conversions from strings to numbers \naccept both a dot and the current locale mark\nas the radix character.\n(The Lua lexer, however, accepts only a dot.)\n\n\n<p>\nThe conversion from numbers to strings uses a\nnon-specified human-readable format.\nFor complete control over how numbers are converted to strings,\nuse the <code>format</code> function from the string library\n(see <a href=\"#pdf-string.format\"><code>string.format</code></a>).\n\n\n\n\n\n<h3>3.4.4 &ndash; <a name=\"3.4.4\">Relational Operators</a></h3><p>\nLua supports the following relational operators:\n\n<ul>\n<li><b><code>==</code>: </b>equality</li>\n<li><b><code>~=</code>: </b>inequality</li>\n<li><b><code>&lt;</code>: </b>less than</li>\n<li><b><code>&gt;</code>: </b>greater than</li>\n<li><b><code>&lt;=</code>: </b>less or equal</li>\n<li><b><code>&gt;=</code>: </b>greater or equal</li>\n</ul><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nStrings are compared in the obvious way.\nNumbers are equal if they denote the same mathematical value.\n\n\n<p>\nTables, userdata, and threads\nare compared by reference:\ntwo objects are considered equal only if they are the same object.\nEvery time you create a new object\n(a table, userdata, or thread),\nthis new object is different from any previously existing object.\nClosures with the same reference are always equal.\nClosures with any detectable difference\n(different behavior, different definition) are always different.\n\n\n<p>\nYou can change the way that Lua compares tables and userdata\nby using the \"eq\" metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nEquality comparisons do not convert strings to numbers\nor vice versa.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers,\nthen they are compared according to their mathematical values\n(regardless of their subtypes).\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the \"lt\" or the \"le\"\nmetamethod (see <a href=\"#2.4\">&sect;2.4</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n<p>\nFollowing the IEEE 754 standard,\nNaN is considered neither smaller than,\nnor equal to, nor greater than any value (including itself).\n\n\n\n\n\n<h3>3.4.5 &ndash; <a name=\"3.4.5\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#3.3.4\">&sect;3.3.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-circuit evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre><p>\n(In this manual,\n<code>--&gt;</code> indicates the result of the preceding expression.)\n\n\n\n\n\n<h3>3.4.6 &ndash; <a name=\"3.4.6\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers, then they are converted to\nstrings according to the rules described in <a href=\"#3.4.3\">&sect;3.4.3</a>.\nOtherwise, the <code>__concat</code> metamethod is called (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.7 &ndash; <a name=\"3.4.7\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary prefix operator <code>#</code>.\nThe length of a string is its number of bytes\n(that is, the usual meaning of string length when each\ncharacter is one byte).\n\n\n<p>\nA program can modify the behavior of the length operator for\nany value but strings through the <code>__len</code> metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nUnless a <code>__len</code> metamethod is given,\nthe length of a table <code>t</code> is only defined if the\ntable is a <em>sequence</em>,\nthat is,\nthe set of its positive numeric keys is equal to <em>{1..n}</em>\nfor some non-negative integer <em>n</em>.\nIn that case, <em>n</em> is its length.\nNote that a table like\n\n<pre>\n     {10, 20, nil, 40}\n</pre><p>\nis not a sequence, because it has the key <code>4</code>\nbut does not have the key <code>3</code>.\n(So, there is no <em>n</em> such that the set <em>{1..n}</em> is equal\nto the set of positive numeric keys of that table.)\nNote, however, that non-numeric keys do not interfere\nwith whether a table is a sequence.\n\n\n\n\n\n<h3>3.4.8 &ndash; <a name=\"3.4.8\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     |\n     ~\n     &amp;\n     &lt;&lt;    &gt;&gt;\n     ..\n     +     -\n     *     /     //    %\n     unary operators (not   #     -     ~)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>3.4.9 &ndash; <a name=\"3.4.9\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFinally, fields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive integers\nstarting with 1.\nFields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nThe order of the assignments in a constructor is undefined.\n(This order would be relevant only when there are repeated keys.)\n\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#3.4.10\">&sect;3.4.10</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>3.4.10 &ndash; <a name=\"3.4.10\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, the prefixexp \"call\" metamethod is called,\nhaving as first parameter the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp &lsquo;<b>:</b>&rsquo; Name args\n</pre><p>\ncan be used to call \"methods\".\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;\n\targs ::= tableconstructor\n\targs ::= LiteralString\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nA call of the form <code>return <em>functioncall</em></code> is called\na <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument;\nthis syntax makes the calling function return exactly\nthe returns of the called function.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>3.4.11 &ndash; <a name=\"3.4.11\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunctiondef ::= <b>function</b> funcbody\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\nnot to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua precompiles a chunk,\nall its function bodies are precompiled too.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance (or <em>closure</em>)\nis the final value of the expression.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n</pre><p>\nWhen a function is called,\nthe list of arguments is adjusted to\nthe length of the list of parameters,\nunless the function is a <em>vararg function</em>,\nwhich is indicated by three dots ('<code>...</code>')\nat the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL            PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\n\nThere is a system-dependent limit on the number of values\nthat a function may return.\nThis limit is guaranteed to be larger than 1000.\n\n\n<p>\nThe <em>colon</em> syntax\nis used for defining <em>methods</em>,\nthat is, functions that have an implicit extra parameter <code>self</code>.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>3.5 &ndash; <a name=\"3.5\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of a local variable begins at the first statement after\nits declaration and lasts until the last non-void statement\nof the innermost block that includes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called\nan <em>upvalue</em>, or <em>external local variable</em>,\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i=1,10 do\n       local y = 0\n       a[i] = function () y=y+1; return x+y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h1>4 &ndash; <a name=\"4\">The Application Program Interface</a></h1>\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nExcept where stated otherwise,\nall such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments for validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith the macro <a name=\"pdf-LUA_USE_APICHECK\"><code>LUA_USE_APICHECK</code></a> defined.\n\n\n\n<h2>4.1 &ndash; <a name=\"4.1\">The Stack</a></h2>\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function pushes its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an absolute stack position\n(starting at&nbsp;1);\na negative index represents an offset relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\n\n\n\n\n\n<h2>4.2 &ndash; <a name=\"4.2\">Stack Size</a></h2>\n\n<p>\nWhen you interact with the Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto ensure that the stack has enough space for pushing new elements.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that the stack has space for\nat least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> extra slots.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nWhen you call a Lua function\nwithout a fixed number of results (see <a href=\"#lua_call\"><code>lua_call</code></a>),\nLua ensures that the stack has enough space for all results,\nbut it does not ensure any extra space.\nSo, before pushing anything in the stack after such a call\nyou should use <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\n\n\n\n\n\n<h2>4.3 &ndash; <a name=\"4.3\">Valid and Acceptable Indices</a></h2>\n\n<p>\nAny function in the API that receives stack indices\nworks only with <em>valid indices</em> or <em>acceptable indices</em>.\n\n\n<p>\nA <em>valid index</em> is an index that refers to a\nposition that stores a modifiable Lua value.\nIt comprises stack indices between&nbsp;1 and the stack top\n(<code>1 &le; abs(index) &le; top</code>)\n\nplus <em>pseudo-indices</em>,\nwhich represent some positions that are accessible to C&nbsp;code\nbut that are not in the stack.\nPseudo-indices are used to access the registry (see <a href=\"#4.5\">&sect;4.5</a>)\nand the upvalues of a C&nbsp;function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n<p>\nFunctions that do not need a specific mutable position,\nbut only a value (e.g., query functions),\ncan be called with acceptable indices.\nAn <em>acceptable index</em> can be any valid index,\nbut it also can be any positive index after the stack top\nwithin the space allocated for the stack,\nthat is, indices up to the stack size.\n(Note that 0 is never an acceptable index.)\nExcept when noted otherwise,\nfunctions in the API work with acceptable indices.\n\n\n<p>\nAcceptable indices serve to avoid extra tests\nagainst the stack top when querying the stack.\nFor instance, a C&nbsp;function can query its third argument\nwithout the need to first check whether there is a third argument,\nthat is, without the need to check whether 3 is a valid index.\n\n\n<p>\nFor functions that can be called with acceptable indices,\nany non-valid index is treated as if it\ncontains a value of a virtual type <a name=\"pdf-LUA_TNONE\"><code>LUA_TNONE</code></a>,\nwhich behaves like a nil value.\n\n\n\n\n\n<h2>4.4 &ndash; <a name=\"4.4\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>);\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called.\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a href=\"#lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first upvalue associated with a function is at index\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function\n(but not greater than 256,\nwhich is one plus the maximum number of upvalues in a closure),\nproduces an acceptable but invalid index.\n\n\n\n\n\n<h2>4.5 &ndash; <a name=\"4.5\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na predefined table that can be used by any C&nbsp;code to\nstore whatever Lua values it needs to store.\nThe registry table is always located at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it must take care to choose keys\nthat are different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name,\nor a light userdata with the address of a C&nbsp;object in your code,\nor any Lua object created by your code.\nAs with variable names,\nstring keys starting with an underscore followed by\nuppercase letters are reserved for Lua.\n\n\n<p>\nThe integer keys in the registry are used\nby the reference mechanism (see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>)\nand by some predefined values.\nTherefore, integer keys must not be used for other purposes.\n\n\n<p>\nWhen you create a new Lua state,\nits registry comes with some predefined values.\nThese predefined values are indexed with integer keys\ndefined as constants in <code>lua.h</code>.\nThe following constants are defined:\n\n<ul>\n<li><b><a name=\"pdf-LUA_RIDX_MAINTHREAD\"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has\nthe main thread of the state.\n(The main thread is the one created together with the state.)\n</li>\n\n<li><b><a name=\"pdf-LUA_RIDX_GLOBALS\"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has\nthe global environment.\n</li>\n</ul>\n\n\n\n\n<h2>4.6 &ndash; <a name=\"4.6\">Error Handling in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(Lua will use exceptions if you compile it as C++;\nsearch for <code>LUAI_THROW</code> in the source code for details.)\nWhen Lua faces any error\n(such as a memory allocation error, type errors, syntax errors,\nand runtime errors)\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recovery point;\nany error jumps to the most recent active recovery point.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em> (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>)\nand then calls <code>abort</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning\n(e.g., doing a long jump to your own recovery point outside Lua).\n\n\n<p>\nThe panic function runs as if it were a message handler (see <a href=\"#2.3\">&sect;2.3</a>);\nin particular, the error object is at the top of the stack.\nHowever, there is no guarantee about stack space.\nTo push anything on the stack,\nthe panic function must first check the available space (see <a href=\"#4.2\">&sect;4.2</a>).\n\n\n<p>\nMost functions in the API can raise an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can raise errors.\n\n\n<p>\nInside a C&nbsp;function you can raise an error by calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n\n\n\n<h2>4.7 &ndash; <a name=\"4.7\">Handling Yields in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.\nTherefore, if a C function <code>foo</code> calls an API function\nand this API function yields\n(directly or indirectly by calling another function that yields),\nLua cannot return to <code>foo</code> any more,\nbecause the <code>longjmp</code> removes its frame from the C stack.\n\n\n<p>\nTo avoid this kind of problem,\nLua raises an error whenever it tries to yield across an API call,\nexcept for three functions:\n<a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, <a href=\"#lua_callk\"><code>lua_callk</code></a>, and <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\nAll those functions receive a <em>continuation function</em>\n(as a parameter named <code>k</code>) to continue execution after a yield.\n\n\n<p>\nWe need to set some terminology to explain continuations.\nWe have a C function called from Lua which we will call\nthe <em>original function</em>.\nThis original function then calls one of those three functions in the C API,\nwhich we will call the <em>callee function</em>,\nthat then yields the current thread.\n(This can happen when the callee function is <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nor when the callee function is either <a href=\"#lua_callk\"><code>lua_callk</code></a> or <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>\nand the function called by them yields.)\n\n\n<p>\nSuppose the running thread yields while executing the callee function.\nAfter the thread resumes,\nit eventually will finish running the callee function.\nHowever,\nthe callee function cannot return to the original function,\nbecause its frame in the C stack was destroyed by the yield.\nInstead, Lua calls a <em>continuation function</em>,\nwhich was given as an argument to the callee function.\nAs the name implies,\nthe continuation function should continue the task\nof the original function.\n\n\n<p>\nAs an illustration, consider the following function:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       status = lua_pcall(L, n, m, h);  /* calls Lua */\n       ...     /* code 2 */\n     }\n</pre><p>\nNow we want to allow\nthe Lua code being run by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> to yield.\nFirst, we can rewrite our function like here:\n\n<pre>\n     int k (lua_State *L, int status, lua_KContext ctx) {\n       ...  /* code 2 */\n     }\n     \n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcall(L, n, m, h), ctx);\n     }\n</pre><p>\nIn the above code,\nthe new function <code>k</code> is a\n<em>continuation function</em> (with type <a href=\"#lua_KFunction\"><code>lua_KFunction</code></a>),\nwhich should do all the work that the original function\nwas doing after calling <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\nNow, we must inform Lua that it must call <code>k</code> if the Lua code\nbeing executed by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> gets interrupted in some way\n(errors or yielding),\nso we rewrite the code as here,\nreplacing <a href=\"#lua_pcall\"><code>lua_pcall</code></a> by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);\n     }\n</pre><p>\nNote the external, explicit call to the continuation:\nLua will call the continuation only if needed, that is,\nin case of errors or resuming after a yield.\nIf the called function returns normally without ever yielding,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a> (and <a href=\"#lua_callk\"><code>lua_callk</code></a>) will also return normally.\n(Of course, instead of calling the continuation in that case,\nyou can do the equivalent work directly inside the original function.)\n\n\n<p>\nBesides the Lua state,\nthe continuation function has two other parameters:\nthe final status of the call plus the context value (<code>ctx</code>) that\nwas passed originally to <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\n(Lua does not use this context value;\nit only passes this value from the original function to the\ncontinuation function.)\nFor <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nthe status is the same value that would be returned by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nexcept that it is <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when being executed after a yield\n(instead of <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>).\nFor <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> and <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nthe status is always <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when Lua calls the continuation.\n(For these two functions,\nLua will not call the continuation in case of errors,\nbecause they do not handle errors.)\nSimilarly, when using <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nyou should call the continuation function\nwith <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> as the status.\n(For <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, there is not much point in calling\ndirectly the continuation function,\nbecause <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> usually does not return.)\n\n\n<p>\nLua treats the continuation function as if it were the original function.\nThe continuation function receives the same Lua stack\nfrom the original function,\nin the same state it would be if the callee function had returned.\n(For instance,\nafter a <a href=\"#lua_callk\"><code>lua_callk</code></a> the function and its arguments are\nremoved from the stack and replaced by the results from the call.)\nIt also has the same upvalues.\nWhatever it returns is handled by Lua as if it were the return\nof the original function.\n\n\n\n\n\n<h2>4.8 &ndash; <a name=\"4.8\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments\n(e.g., they may depend on what is on the stack).\nThe third field, <code>x</code>,\ntells whether the function may raise errors:\n'<code>-</code>' means the function never raises any error;\n'<code>m</code>' means the function may raise out-of-memory errors\nand errors running a <code>__gc</code> metamethod;\n'<code>e</code>' means the function may raise any errors\n(it can run arbitrary Lua code,\neither directly or through metamethods);\n'<code>v</code>' means the function may raise an error on purpose.\n\n\n\n<hr><h3><a name=\"lua_absindex\"><code>lua_absindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_absindex (lua_State *L, int idx);</pre>\n\n<p>\nConverts the acceptable index <code>idx</code>\ninto an equivalent absolute index\n(that is, one that does not depend on the stack top).\n\n\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block or some code about what\nis being allocated;\nand <code>nsize</code>, the new size of the block.\n\n\n<p>\nWhen <code>ptr</code> is not <code>NULL</code>,\n<code>osize</code> is the size of the block pointed by <code>ptr</code>,\nthat is, the size given when it was allocated or reallocated.\n\n\n<p>\nWhen <code>ptr</code> is <code>NULL</code>,\n<code>osize</code> encodes the kind of object that Lua is allocating.\n<code>osize</code> is any of\n<a href=\"#pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>, <a href=\"#pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>, <a href=\"#pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a href=\"#pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>, or <a href=\"#pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a> when (and only when)\nLua is creating a new object of that type.\nWhen <code>osize</code> is some other value,\nLua is allocating memory for something else.\n\n\n<p>\nLua assumes the following behavior from the allocator function:\n\n\n<p>\nWhen <code>nsize</code> is zero,\nthe allocator must behave like <code>free</code>\nand return <code>NULL</code>.\n\n\n<p>\nWhen <code>nsize</code> is not zero,\nthe allocator must behave like <code>realloc</code>.\nThe allocator returns <code>NULL</code>\nif and only if it cannot fulfill the request.\nLua assumes that the allocator never fails when\n<code>osize &gt;= nsize</code>.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nNote that Standard&nbsp;C ensures\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.\nThis code assumes that <code>realloc</code> does not fail when shrinking a block.\n(Although Standard&nbsp;C does not ensure this behavior,\nit seems to be a safe assumption.)\n\n\n\n\n\n<hr><h3><a name=\"lua_arith\"><code>lua_arith</code></a></h3><p>\n<span class=\"apii\">[-(2|1), +1, <em>e</em>]</span>\n<pre>void lua_arith (lua_State *L, int op);</pre>\n\n<p>\nPerforms an arithmetic or bitwise operation over the two values\n(or one, in the case of negations)\nat the top of the stack,\nwith the value at the top being the second operand,\npops these values, and pushes the result of the operation.\nThe function follows the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPADD\"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSUB\"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMUL\"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>\n<li><b><a name=\"pdf-LUA_OPDIV\"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</code>)</li>\n<li><b><a name=\"pdf-LUA_OPIDIV\"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMOD\"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>\n<li><b><a name=\"pdf-LUA_OPPOW\"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>\n<li><b><a name=\"pdf-LUA_OPUNM\"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBNOT\"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBAND\"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&amp;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBOR\"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBXOR\"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHL\"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code>&lt;&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHR\"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>&gt;&gt;</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one (see <a href=\"#4.6\">&sect;4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs+1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\n\n\n<p>\nTo call a function you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the function are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nAll arguments and the function value are popped from the stack\nwhen the function is called.\nThe function results are pushed onto the stack when the function returns.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, all results from the function are pushed.\nLua takes care that the returned values fit into the stack space,\nbut it does not ensure any extra space in the stack.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error inside the called function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getglobal(L, \"f\");                  /* function to be called */\n     lua_pushliteral(L, \"how\");                       /* 1st argument */\n     lua_getglobal(L, \"t\");                    /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setglobal(L, \"a\");                         /* set global 'a' */\n</pre><p>\nNote that the code above is <em>balanced</em>:\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_callk\"><code>lua_callk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_callk (lua_State *L,\n                int nargs,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numeric arguments and returns their average and their sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0.0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushliteral(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_checkstack (lua_State *L, int n);</pre>\n\n<p>\nEnsures that the stack has space for at least <code>n</code> extra slots\n(that is, that you can safely push up to <code>n</code> values into it).\nIt returns false if it cannot fulfill the request,\neither because it would cause the stack\nto be larger than a fixed maximum size\n(typically at least several thousand elements) or\nbecause it cannot allocate memory for the extra space.\nThis function never shrinks the stack;\nif the stack already has space for the extra slots,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nDestroys all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any)\nand frees all dynamic memory used by this state.\nOn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs that create multiple states,\nsuch as daemons or web servers,\nwill probably need to close states as soon as they are not needed.\n\n\n\n\n\n<hr><h3><a name=\"lua_compare\"><code>lua_compare</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>\n\n<p>\nCompares two Lua values.\nReturns 1 if the value at index <code>index1</code> satisfies <code>op</code>\nwhen compared with the value at index <code>index2</code>,\nfollowing the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is not valid.\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPEQ\"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLT\"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLE\"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result at the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#3.4.6\">&sect;3.4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_copy\"><code>lua_copy</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>\n\n<p>\nCopies the element at index <code>fromidx</code>\ninto the valid index <code>toidx</code>,\nreplacing the value at that position.\nValues at other positions are not affected.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nParameter <code>narr</code> is a hint for how many elements the table\nwill have as a sequence;\nparameter <code>nrec</code> is a hint for how many other elements\nthe table will have.\nLua may use these hints to preallocate memory for the new table.\nThis preallocation is useful for performance when you know in advance\nhow many elements the table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_dump (lua_State *L,\n                        lua_Writer writer,\n                        void *data,\n                        int strip);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nIf <code>strip</code> is true,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nGenerates a Lua error,\nusing the value at the top of the stack as the error object.\nThis function does a long jump,\nand therefore never returns\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_gc (lua_State *L, int what, int data);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>:\n\n<ul>\n\n<li><b><code>LUA_GCSTOP</code>: </b>\nstops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>: </b>\nrestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOLLECT</code>: </b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>: </b>\nreturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>: </b>\nreturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code>: </b>\nperforms an incremental step of garbage collection.\n</li>\n\n<li><b><code>LUA_GCSETPAUSE</code>: </b>\nsets <code>data</code> as the new value\nfor the <em>pause</em> of the collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the pause.\n</li>\n\n<li><b><code>LUA_GCSETSTEPMUL</code>: </b>\nsets <code>data</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the step multiplier.\n</li>\n\n<li><b><code>LUA_GCISRUNNING</code>: </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n<p>\nFor more details about these options,\nsee <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer given when the memory-allocator function was set.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getextraspace\"><code>lua_getextraspace</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_getextraspace (lua_State *L);</pre>\n\n<p>\nReturns a pointer to a raw memory area associated with the\ngiven Lua state.\nThe application can use this area for any purpose;\nLua does not use it for anything.\n\n\n<p>\nEach new thread has this area initialized with a copy\nof the area of the main thread.\n\n\n<p>\nBy default, this area has the size of a pointer to void,\nbut you can recompile Lua with a different size for this area.\n(See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nReturns the type of that value.\n\n\n\n\n\n<hr><h3><a name=\"lua_geti\"><code>lua_geti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_geti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nPushes onto the stack the value <code>t[i]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index has a metatable,\nthe function pushes that metatable onto the stack and returns&nbsp;1.\nOtherwise,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>int lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index\nand <code>k</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the key from the stack,\npushing the resulting value in its place.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack;\nin particular, 0&nbsp;means an empty stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_getuservalue\"><code>lua_getuservalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_getuservalue (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the Lua value associated with the userdata\nat the given index.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ... lua_Integer;</pre>\n\n<p>\nThe type of integers in Lua.\n\n\n<p>\nBy default this type is <code>long long</code>,\n(usually a 64-bit two-complement integer),\nbut that can be changed to <code>long</code> or <code>int</code>\n(usually a 32-bit two-complement integer).\n(See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n<p>\nLua also defines the constants\n<a name=\"pdf-LUA_MININTEGER\"><code>LUA_MININTEGER</code></a> and <a name=\"pdf-LUA_MAXINTEGER\"><code>LUA_MAXINTEGER</code></a>,\nwith the minimum and the maximum values that fit in this type.\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isinteger\"><code>lua_isinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isinteger (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is an integer\n(that is, the value is a number and is represented as an integer),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isyieldable\"><code>lua_isyieldable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isyieldable (lua_State *L);</pre>\n\n<p>\nReturns 1 if the given coroutine can yield,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_KContext\"><code>lua_KContext</code></a></h3>\n<pre>typedef ... lua_KContext;</pre>\n\n<p>\nThe type for continuation-function contexts.\nIt must be a numeric type.\nThis type is defined as <code>intptr_t</code>\nwhen <code>intptr_t</code> is available,\nso that it can store pointers too.\nOtherwise, it is defined as <code>ptrdiff_t</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_KFunction\"><code>lua_KFunction</code></a></h3>\n<pre>typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);</pre>\n\n<p>\nType for continuation functions (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_len\"><code>lua_len</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the length of the value at the given index.\nIt is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>) and\nmay trigger a metamethod for the \"length\" event (see <a href=\"#2.4\">&sect;2.4</a>).\nThe result is pushed on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname,\n              const char *mode);</pre>\n\n<p>\nLoads a Lua chunk without running it.\nIf there are no errors,\n<code>lua_load</code> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\n\n\n<p>\nThe return values of <code>lua_load</code> are:\n\n<ul>\n\n<li><b><a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>: </b> no errors;</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>: </b>\nsyntax error during precompilation;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation (out-of-memory) error;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\n(This error has no relation with the chunk being loaded.\nIt is generated by the garbage collector.)\n</li>\n\n</ul>\n\n<p>\nThe <code>lua_load</code> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#4.9\">&sect;4.9</a>).\n\n\n<p>\n<code>lua_load</code> automatically detects whether the chunk is text or binary\nand loads it accordingly (see program <code>luac</code>).\nThe string <code>mode</code> works as in function <a href=\"#pdf-load\"><code>load</code></a>,\nwith the addition that\na <code>NULL</code> value is equivalent to the string \"<code>bt</code>\".\n\n\n<p>\n<code>lua_load</code> uses the stack internally,\nso the reader function must always leave the stack\nunmodified when returning.\n\n\n<p>\nIf the resulting function has upvalues,\nits first upvalue is set to the value of the global environment\nstored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href=\"#4.5\">&sect;4.5</a>).\nWhen loading main chunks,\nthis upvalue will be the <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nOther upvalues are initialized with <b>nil</b>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new thread running in a new, independent state.\nReturns <code>NULL</code> if it cannot create the thread or the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua does all memory allocation for this state through this function.\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\npasses to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new thread returned by this function shares with the original thread\nits global environment,\nbut has an independent execution stack.\n\n\n<p>\nThere is no explicit function to close or to destroy a thread.\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdata\"><code>lua_newuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>\n\n<p>\nThis function allocates a new block of memory with the given size,\npushes onto the stack a new full userdata with the block address,\nand returns this address.\nThe host program can freely use this memory.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>e</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key&ndash;value pair from the table at the given index\n(the \"next\" pair after the given key).\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 (and pushes nothing).\n\n\n<p>\nA typical traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\ndo not call <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> may change\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef ... lua_Number;</pre>\n\n<p>\nThe type of floats in Lua.\n\n\n<p>\nBy default this type is double,\nbut that can be changed to a single float or a long double.\n(See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_numbertointeger\"><code>lua_numbertointeger</code></a></h3>\n<pre>int lua_numbertointeger (lua_Number n, lua_Integer *p);</pre>\n\n<p>\nConverts a Lua float to a Lua integer.\nThis macro assumes that <code>n</code> has an integral value.\nIf that value is within the range of Lua integers,\nit is converted to an integer and assigned to <code>*p</code>.\nThe macro results in a boolean indicating whether the\nconversion was successful.\n(Note that this range test can be tricky to do\ncorrectly without this macro,\ndue to roundings.)\n\n\n<p>\nThis macro may evaluate its arguments more than once.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>\n\n<p>\nCalls a function in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error object),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>msgh</code> is 0,\nthen the error object returned on the stack\nis exactly the original error object.\nOtherwise, <code>msgh</code> is the stack index of a\n<em>message handler</em>.\n(This index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis function will be called with the error object\nand its return value will be the object\nreturned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the message handler is used to add more debug\ninformation to the error object, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns one of the following constants\n(defined in <code>lua.h</code>):\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OK\"><code>LUA_OK</code></a> (0): </b>\nsuccess.</li>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>: </b>\na runtime error.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation error.\nFor such errors, Lua does not call the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>: </b>\nerror while running the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\n(This error typically has no relation with the function being called.)\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pcallk\"><code>lua_pcallk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcallk (lua_State *L,\n                int nargs,\n                int nresults,\n                int msgh,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, &ndash;]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a C&nbsp;closure (see <a href=\"#4.4\">&sect;4.4</a>);\nthese values are then accessible to the function whenever it is called.\nTo associate values with a C&nbsp;function,\nfirst these values must be pushed onto the stack\n(when there are multiple values, the first value is pushed first).\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values will be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n<p>\nWhen <code>n</code> is zero,\nthis function creates a <em>light C function</em>,\nwhich is just a pointer to the C&nbsp;function.\nIn that case, it never raises a memory error.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function receives a pointer to a C function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\n\n\n<p>\nAny function to be callable by Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string.\nIt is similar to the ISO&nbsp;C function <code>sprintf</code>,\nbut has some important differences:\n\n<ul>\n\n<li>\nYou do not have to allocate space for the result:\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\n</li>\n\n<li>\nThe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts the character '<code>%</code>'),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%I</code>' (inserts a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>),\n'<code>%p</code>' (inserts a pointer as a hexadecimal numeral),\n'<code>%d</code>' (inserts an <code>int</code>),\n'<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and\n'<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).\n</li>\n\n</ul>\n\n<p>\nUnlike other push functions,\nthis function checks for the stack space it needs,\nincluding the slot for its result.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushglobaltable\"><code>lua_pushglobaltable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushglobaltable (lua_State *L);</pre>\n\n<p>\nPushes the global environment onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes an integer with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer, a <code>void*</code>.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushstring\"><code>lua_pushstring</code></a>,\nbut should be used only when <code>s</code> is a literal string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain any binary data,\nincluding embedded zeros.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a float with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n<p>\nIf <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, without calling the <code>__eq</code> metamethod).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are not valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>int lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgeti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the table at the given index.\nThe access is raw,\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgetp\"><code>lua_rawgetp</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the table at the given index and\n<code>k</code> is the pointer <code>p</code> represented as a light userdata.\nThe access is raw;\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawlen\"><code>lua_rawlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>size_t lua_rawlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the raw \"length\" of the value at the given index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>')\nwith no metamethods;\nfor userdata, this is the size of the block of memory allocated\nfor the userdata;\nfor other values, it is&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nDoes the equivalent of <code>t[i] = v</code>,\nwhere <code>t</code> is the table at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke the <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawsetp\"><code>lua_rawsetp</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nDoes the equivalent of <code>t[p] = v</code>,\nwhere <code>t</code> is the table at the given index,\n<code>p</code> is encoded as a light userdata,\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time it needs another piece of the chunk,\n<a href=\"#lua_load\"><code>lua_load</code></a> calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>\n\n<p>\nSets the C function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index\nwithout shifting any element\n(therefore replacing the value at that given index),\nand then pops the top element.\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>int lua_resume (lua_State *L, lua_State *from, int nargs);</pre>\n\n<p>\nStarts and resumes a coroutine in the given thread <code>L</code>.\n\n\n<p>\nTo start a coroutine,\nyou push onto the thread stack the main function plus any arguments;\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>nargs</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns, the stack contains all values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nor all values returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\n\n\n<p>\nIn case of errors,\nthe stack is not unwound,\nso you can use the debug API over it.\nThe error object is on the top of the stack.\n\n\n<p>\nTo resume a coroutine,\nyou remove any results from the last <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nput on its stack only the values to\nbe passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nThe parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.\nIf there is no such coroutine,\nthis parameter can be <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_rotate\"><code>lua_rotate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_rotate (lua_State *L, int idx, int n);</pre>\n\n<p>\nRotates the stack elements between the valid index <code>idx</code>\nand the top of the stack.\nThe elements are rotated <code>n</code> positions in the direction of the top,\nfor a positive <code>n</code>,\nor <code>-n</code> positions in the direction of the bottom,\nfor a negative <code>n</code>.\nThe absolute value of <code>n</code> must not be greater than the size\nof the slice being rotated.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_seti\"><code>lua_seti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_seti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nDoes the equivalent to <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and\nsets it as the new metatable for the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index,\n<code>v</code> is the value at the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is larger than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_setuservalue\"><code>lua_setuservalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setuservalue (lua_State *L, int index);</pre>\n\n<p>\nPops a value from the stack and sets it as\nthe new value associated to the userdata at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nAn opaque structure that points to a thread and indirectly\n(through the thread) to the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is accessible through this structure.\n\n\n<p>\nA pointer to this structure must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be 0 (<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>) for a normal thread,\nan error code if the thread finished the execution\nof a <a href=\"#lua_resume\"><code>lua_resume</code></a> with an error,\nor <a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n<p>\nYou can only call functions in threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>.\nYou can resume threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>\n(to start a new coroutine) or <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a>\n(to resume a coroutine).\n\n\n\n\n\n<hr><h3><a name=\"lua_stringtonumber\"><code>lua_stringtonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>size_t lua_stringtonumber (lua_State *L, const char *s);</pre>\n\n<p>\nConverts the zero-terminated string <code>s</code> to a number,\npushes that number into the stack,\nand returns the total size of the string,\nthat is, its length plus one.\nThe conversion can result in an integer or a float,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\nThe string may have leading and trailing spaces and a sign.\nIf the string is not a valid numeral,\nreturns 0 and pushes nothing.\n(Note that the result can be used as a boolean,\ntrue if the conversion succeeds.)\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns true for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns false.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tointegerx\"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointegerx\"><code>lua_tointegerx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be an integer,\nor a number or string convertible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <code>lua_tointegerx</code> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <code>lua_tolstring</code> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <code>lua_tolstring</code> is applied to keys during a table traversal.)\n\n\n<p>\n<code>lua_tolstring</code> returns a pointer\nto a string inside the Lua state.\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\n\n\n<p>\nBecause Lua has garbage collection,\nthere is no guarantee that the pointer returned by <code>lua_tolstring</code>\nwill be valid after the corresponding Lua value is removed from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumberx\"><code>lua_tonumberx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, or a function;\notherwise, <code>lua_topointer</code> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for hashing and debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index is a full userdata,\nreturns its block address.\nIf the value is a light userdata,\nreturns its pointer.\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given valid index,\nor <code>LUA_TNONE</code> for a non-valid (but acceptable) index.\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<a name=\"pdf-LUA_TNIL\"><code>LUA_TNIL</code></a> (0),\n<a name=\"pdf-LUA_TNUMBER\"><code>LUA_TNUMBER</code></a>,\n<a name=\"pdf-LUA_TBOOLEAN\"><code>LUA_TBOOLEAN</code></a>,\n<a name=\"pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>,\n<a name=\"pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>,\n<a name=\"pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a name=\"pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>,\n<a name=\"pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a>,\nand\n<a name=\"pdf-LUA_TLIGHTUSERDATA\"><code>LUA_TLIGHTUSERDATA</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *lua_typename (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Unsigned\"><code>lua_Unsigned</code></a></h3>\n<pre>typedef ... lua_Unsigned;</pre>\n\n<p>\nThe unsigned version of <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_upvalueindex (int i);</pre>\n\n<p>\nReturns the pseudo-index that represents the <code>i</code>-th upvalue of\nthe running function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_version\"><code>lua_version</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const lua_Number *lua_version (lua_State *L);</pre>\n\n<p>\nReturns the address of the version number\n(a C static variable)\nstored in the Lua core.\nWhen called with a valid <a href=\"#lua_State\"><code>lua_State</code></a>,\nreturns the address of the version used to create that state.\nWhen called with <code>NULL</code>,\nreturns the address of the version running the call.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time it produces another piece of chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>data</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the same state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yield (lua_State *L, int nresults);</pre>\n\n<p>\nThis function is equivalent to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nbut it has no continuation (see <a href=\"#4.7\">&sect;4.7</a>).\nTherefore, when the thread resumes,\nit continues the function that called\nthe function calling <code>lua_yield</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yieldk\"><code>lua_yieldk</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yieldk (lua_State *L,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nYields a coroutine (thread).\n\n\n<p>\nWhen a C&nbsp;function calls <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat will be passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nWhen the coroutine is resumed again,\nLua calls the given continuation function <code>k</code> to continue\nthe execution of the C function that yielded (see <a href=\"#4.7\">&sect;4.7</a>).\nThis continuation function receives the same stack\nfrom the previous function,\nwith the <code>n</code> results removed and\nreplaced by the arguments passed to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\nMoreover,\nthe continuation function receives the value <code>ctx</code>\nthat was passed to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>.\n\n\n<p>\nUsually, this function does not return;\nwhen the coroutine eventually resumes,\nit continues executing the continuation function.\nHowever, there is one special case,\nwhich is when this function is called\nfrom inside a line or a count hook (see <a href=\"#4.9\">&sect;4.9</a>).\nIn that case, <code>lua_yieldk</code> should be called with no continuation\n(probably in the form of <a href=\"#lua_yield\"><code>lua_yield</code></a>) and no results,\nand the hook should return immediately after the call.\nLua will yield and,\nwhen the coroutine resumes again,\nit will continue the normal execution\nof the (Lua) function that triggered the hook.\n\n\n<p>\nThis function can raise an error if it is called from a thread\nwith a pending C call with no continuation function,\nor it is called from a thread that is not running inside a resume\n(e.g., the main thread).\n\n\n\n\n\n\n\n<h2>4.9 &ndash; <a name=\"4.9\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  int currentline;            /* (l) */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  unsigned char nups;         /* (u) number of upvalues */\n  unsigned char nparams;      /* (u) number of parameters */\n  char isvararg;              /* (u) */\n  char istailcall;            /* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about a function or an activation record.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\ncall <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>: </b>\nthe name of the chunk that created the function.\nIf <code>source</code> starts with a '<code>@</code>',\nit means that the function was defined in a file where\nthe file name follows the '<code>@</code>'.\nIf <code>source</code> starts with a '<code>=</code>',\nthe remainder of its contents describe the source in a user-dependent manner.\nOtherwise,\nthe function was defined in a string where\n<code>source</code> is that string.\n</li>\n\n<li><b><code>short_src</code>: </b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>: </b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>: </b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>: </b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk.\n</li>\n\n<li><b><code>currentline</code>: </b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>: </b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>: </b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>istailcall</code>: </b>\ntrue if this function invocation was called by a tail call.\nIn this case, the caller of this level is not in the stack.\n</li>\n\n<li><b><code>nups</code>: </b>\nthe number of upvalues of the function.\n</li>\n\n<li><b><code>nparams</code>: </b>\nthe number of fixed parameters of the function\n(always 0&nbsp;for C&nbsp;functions).\n</li>\n\n<li><b><code>isvararg</code>: </b>\ntrue if the function is a vararg function\n(always true for C&nbsp;functions).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>e</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nGets information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function from the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getglobal(L, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>': </b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;\n</li>\n\n<li><b>'<code>u</code>': </b> fills in the fields\n<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;\n</li>\n\n<li><b>'<code>f</code>': </b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>': </b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n\n\n<p>\nIf this option is given together with option '<code>f</code>',\nits table is pushed after the function.\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 on error\n(for instance, an invalid option in <code>what</code>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable of\na given activation record or a given function.\n\n\n<p>\nIn the first case,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect;\nsee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for details about variable indices\nand names.\n\n\n<p>\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nIn the second case, <code>ar</code> must be <code>NULL</code> and the function\nto be inspected must be at the top of the stack.\nIn this case, only parameters of Lua functions are visible\n(as there is no information about what variables are active)\nand no values are pushed onto the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGets information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>\n(except for tail calls, which do not count on the stack).\nWhen there are no errors, <a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 1;\nwhen called with a level greater than the stack depth,\nit returns 0.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about the <code>n</code>-th upvalue\nof the closure at index <code>funcindex</code>.\nIt pushes the upvalue's value onto the stack\nand returns its name.\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n\n\n<p>\nUpvalues have no particular order,\nas they are active through the whole function.\nThey are numbered in an arbitrary order.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILCALL\"><code>LUA_HOOKTAILCALL</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nFor call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,\nthe normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;\nin this case, there will be no corresponding return event.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n<p>\nHook functions cannot have continuations,\nthat is, they cannot call <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>, or <a href=\"#lua_callk\"><code>lua_callk</code></a> with a non-null <code>k</code>.\n\n\n<p>\nHook functions can yield under the following conditions:\nOnly count and line events can yield;\nto yield, a hook function must finish its execution\ncalling <a href=\"#lua_yield\"><code>lua_yield</code></a> with <code>nresults</code> equal to zero\n(that is, with no values).\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise OR of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook: </b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function,\nbefore the function gets its arguments.\n</li>\n\n<li><b>The return hook: </b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\nThere is no standard way to access the values\nto be returned by the function.\n</li>\n\n<li><b>The line hook: </b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n<li><b>The count hook: </b> is called after the interpreter executes every\n<code>count</code> instructions.\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n</ul>\n\n<p>\nA hook is disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nIt assigns the value at the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n<p>\nParameters <code>ar</code> and <code>n</code> are as in function <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value at the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueid\"><code>lua_upvalueid</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nReturns a unique identifier for the upvalue numbered <code>n</code>\nfrom the closure at index <code>funcindex</code>.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>,\nbut <code>n</code> cannot be greater than the number of upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvaluejoin\"><code>lua_upvaluejoin</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,\n                                    int funcindex2, int n2);</pre>\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.\n\n\n\n\n\n\n\n<h1>5 &ndash; <a name=\"5\">The Auxiliary Library</a></h1>\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all\ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions and types from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with that API.\nNevertheless, the use of the auxiliary library ensures\nmore consistency to your code.\n\n\n<p>\nSeveral functions in the auxiliary library use internally some\nextra stack slots.\nWhen a function in the auxiliary library uses less than five slots,\nit does not check the stack size;\nit simply assumes that there are enough slots.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n<p>\nFunctions called <code>luaL_check*</code>\nalways raise an error if the check is not satisfied.\n\n\n\n<h2>5.1 &ndash; <a name=\"5.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the byte <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>)\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +?, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value at the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int arg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf it is not, raises an error with a standard message (see <a href=\"#luaL_argerror\"><code>luaL_argerror</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre>\n\n<p>\nRaises an error reporting a problem with argument <code>arg</code>\nof the C function that called it,\nusing a standard message\nthat includes <code>extramsg</code> as a comment:\n\n<pre>\n     bad argument #<em>arg</em> to '<em>funcname</em>' (<em>extramsg</em>)\n</pre><p>\nThis function never returns.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nFinish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nIf you know beforehand the total size of the resulting string,\nyou can use the buffer like this:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it and preallocate a space of\nsize <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>\n\n<li>Then copy the string into that space.</li>\n\n<li>\nFinish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,\nwhere <code>sz</code> is the total size of the resulting string\ncopied into that space.\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a> the stack is back to its\nlevel when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>.\nThis function does not allocate any space;\nthe buffer must be declared as a variable\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinitsize\"><code>luaL_buffinitsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence\n<a href=\"#luaL_buffinit\"><code>luaL_buffinit</code></a>, <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field passing the object as its only argument.\nIn this case this function returns true and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns false (without pushing any value on the stack).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>arg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is an integer\n(or can be converted to an integer)\nand returns this integer cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills <code>*l</code>\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a number\nand returns this number.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int arg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>arg</code> or when this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message\n(or <code>NULL</code> for no additional text).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int arg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>) and\nreturns the userdata address (see <a href=\"#lua_touserdata\"><code>lua_touserdata</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkversion\"><code>luaL_checkversion</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkversion (lua_State *L);</pre>\n\n<p>\nChecks whether the core running the call,\nthe core that created the Lua state,\nand the code making the call are all using the same version of Lua.\nAlso checks whether the core running the call\nand the core that created the Lua state\nare using the same address space.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>e</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, &ndash;]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_execresult\"><code>luaL_execresult</code></a></h3><p>\n<span class=\"apii\">[-0, +3, <em>m</em>]</span>\n<pre>int luaL_execresult (lua_State *L, int stat);</pre>\n\n<p>\nThis function produces the return values for\nprocess-related functions in the standard library\n(<a href=\"#pdf-os.execute\"><code>os.execute</code></a> and <a href=\"#pdf-io.close\"><code>io.close</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_fileresult\"><code>luaL_fileresult</code></a></h3><p>\n<span class=\"apii\">[-0, +(1|3), <em>m</em>]</span>\n<pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre>\n\n<p>\nThis function produces the return values for\nfile-related functions in the standard library\n(<a href=\"#pdf-io.open\"><code>io.open</code></a>, <a href=\"#pdf-os.rename\"><code>os.rename</code></a>, <a href=\"#pdf-file:seek\"><code>file:seek</code></a>, etc.).\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code> and returns the type of pushed value.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\npushes nothing and returns <code>LUA_TNIL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>)\n(<b>nil</b> if there is no metatable associated with that name).\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getsubtable\"><code>luaL_getsubtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre>\n\n<p>\nEnsures that the value <code>t[fname]</code>,\nwhere <code>t</code> is the value at index <code>idx</code>,\nis a table,\nand pushes that table onto the stack.\nReturns true if it finds a previous table there\nand false if it creates a new table.\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code> by replacing\nany occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_len\"><code>luaL_len</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>lua_Integer luaL_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given index\nas a number;\nit is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nRaises an error if the result of the operation is not an integer.\n(This case only can happen through metamethods.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadbufferx\"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbufferx\"><code>luaL_loadbufferx</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbufferx (lua_State *L,\n                      const char *buff,\n                      size_t sz,\n                      const char *name,\n                      const char *mode);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadfilex\"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfilex\"><code>luaL_loadfilex</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfilex (lua_State *L, const char *filename,\n                                            const char *mode);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>,\nbut it has an extra error code <a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>\nif it cannot open/read the file or the file has a wrong mode.\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlib\"><code>luaL_newlib</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlib (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table and registers there\nthe functions in list <code>l</code>.\n\n\n<p>\nIt is implemented as the following macro:\n\n<pre>\n     (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n</pre><p>\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlibtable\"><code>luaL_newlibtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table with a size optimized\nto store all entries in the array <code>l</code>\n(but does not actually store them).\nIt is intended to be used in conjunction with <a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>\n(see <a href=\"#luaL_newlib\"><code>luaL_newlib</code></a>).\n\n\n<p>\nIt is implemented as a macro.\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds to this new table the pair <code>__name = tname</code>,\nadds to the registry the pair <code>[tname] = new table</code>,\nand returns 1.\n(The entry <code>__name</code> is used by some error-reporting functions.)\n\n\n<p>\nIn both cases pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C <code>realloc</code> function\nand then sets a panic function (see <a href=\"#4.6\">&sect;4.6</a>) that prints\nan error message to the standard error output in case of fatal\nerrors.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_opt\"><code>luaL_opt</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>T luaL_opt (L, func, arg, dflt);</pre>\n\n<p>\nThis macro is defined as follows:\n\n<pre>\n     (lua_isnoneornil(L,(arg)) ? (dflt) : func(L,(arg)))\n</pre><p>\nIn words, if the argument <code>arg</code> is nil or absent,\nthe macro results in the default <code>dflt</code>.\nOtherwise, it results in the result of calling <code>func</code>\nwith the state <code>L</code> and the argument index <code>arg</code> as\nparameters.\nNote that it evaluates the expression <code>dflt</code> only if needed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int arg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is an integer\n(or convertible to an integer),\nreturns this integer.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int arg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills the position <code>*l</code> with the result's length.\nIf the result is <code>NULL</code>\n(only possible when returning <code>d</code> and <code>d == NULL</code>),\nits length is considered zero.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a number,\nreturns this number.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int arg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>\nwith the predefined size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nReturns an address to a space of size <code>sz</code>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add\nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresultsize\"><code>luaL_pushresultsize</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence <a href=\"#luaL_addsize\"><code>luaL_addsize</code></a>, <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object at the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nFunction <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference and its associated object.\n\n\n<p>\nIf the object at the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with a sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_requiref\"><code>luaL_requiref</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void luaL_requiref (lua_State *L, const char *modname,\n                    lua_CFunction openf, int glb);</pre>\n\n<p>\nIf <code>modname</code> is not already present in <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a>,\ncalls function <code>openf</code> with string <code>modname</code> as an argument\nand sets the call result in <code>package.loaded[modname]</code>,\nas if that function has been called through <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n<p>\nIf <code>glb</code> is true,\nalso stores the module into global <code>modname</code>.\n\n\n<p>\nLeaves a copy of the module on the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setfuncs\"><code>luaL_setfuncs</code></a></h3><p>\n<span class=\"apii\">[-nup, +0, <em>m</em>]</span>\n<pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>\n\n<p>\nRegisters all functions in the array <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack\n(below optional upvalues, see next).\n\n\n<p>\nWhen <code>nup</code> is not zero,\nall functions are created sharing <code>nup</code> upvalues,\nwhich must be previously pushed on the stack\non top of the library table.\nThese values are popped from the stack after the registration.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setmetatable\"><code>luaL_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nSets the metatable of the object at the top of the stack\nas the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_Stream\"><code>luaL_Stream</code></a></h3>\n<pre>typedef struct luaL_Stream {\n  FILE *f;\n  lua_CFunction closef;\n} luaL_Stream;</pre>\n\n<p>\nThe standard representation for file handles,\nwhich is used by the standard I/O library.\n\n\n<p>\nA file handle is implemented as a full userdata,\nwith a metatable called <code>LUA_FILEHANDLE</code>\n(where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).\nThe metatable is created by the I/O library\n(see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n<p>\nThis userdata must start with the structure <code>luaL_Stream</code>;\nit can contain other data after this initial structure.\nField <code>f</code> points to the corresponding C stream\n(or it can be <code>NULL</code> to indicate an incompletely created handle).\nField <code>closef</code> points to a Lua function\nthat will be called to close the stream\nwhen the handle is closed or collected;\nthis function receives the file handle as its sole argument and\nmust return either <b>true</b> (in case of success)\nor <b>nil</b> plus an error message (in case of error).\nOnce Lua calls this field,\nit changes the field value to <code>NULL</code>\nto signal that the handle is closed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_testudata\"><code>luaL_testudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nThis function works like <a href=\"#luaL_checkudata\"><code>luaL_checkudata</code></a>,\nexcept that, when the test fails,\nit returns <code>NULL</code> instead of raising an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_tolstring\"><code>luaL_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre>\n\n<p>\nConverts any Lua value at the given index to a C&nbsp;string\nin a reasonable format.\nThe resulting string is pushed onto the stack and also\nreturned by the function.\nIf <code>len</code> is not <code>NULL</code>,\nthe function also sets <code>*len</code> with the string length.\n\n\n<p>\nIf the value has a metatable with a <code>__tostring</code> field,\nthen <code>luaL_tolstring</code> calls the corresponding metamethod\nwith the value as argument,\nand uses the result of the call as its result.\n\n\n\n\n\n<hr><h3><a name=\"luaL_traceback\"><code>luaL_traceback</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n                     int level);</pre>\n\n<p>\nCreates and pushes a traceback of the stack <code>L1</code>.\nIf <code>msg</code> is not <code>NULL</code> it is appended\nat the beginning of the traceback.\nThe <code>level</code> parameter tells at which level\nto start the traceback.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>6 &ndash; <a name=\"6\">Standard Libraries</a></h1>\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented directly through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to \"outside\" services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut are quite useful or have critical performance requirements that\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library (<a href=\"#6.1\">&sect;6.1</a>);</li>\n\n<li>coroutine library (<a href=\"#6.2\">&sect;6.2</a>);</li>\n\n<li>package library (<a href=\"#6.3\">&sect;6.3</a>);</li>\n\n<li>string manipulation (<a href=\"#6.4\">&sect;6.4</a>);</li>\n\n<li>basic UTF-8 support (<a href=\"#6.5\">&sect;6.5</a>);</li>\n\n<li>table manipulation (<a href=\"#6.6\">&sect;6.6</a>);</li>\n\n<li>mathematical functions (<a href=\"#6.7\">&sect;6.7</a>) (sin, log, etc.);</li>\n\n<li>input and output (<a href=\"#6.8\">&sect;6.8</a>);</li>\n\n<li>operating system facilities (<a href=\"#6.9\">&sect;6.9</a>);</li>\n\n<li>debug facilities (<a href=\"#6.10\">&sect;6.10</a>).</li>\n\n</ul><p>\nExcept for the basic and the package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nthe host program can open them individually by using\n<a href=\"#luaL_requiref\"><code>luaL_requiref</code></a> to call\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_coroutine\"><code>luaopen_coroutine</code></a> (for the coroutine library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_utf8\"><code>luaopen_utf8</code></a> (for the UTF8 library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the operating system library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>.\n\n\n\n<h2>6.1 &ndash; <a name=\"6.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide\nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\n\n\n<p>\nCalls <a href=\"#pdf-error\"><code>error</code></a> if\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\nIn case of error,\n<code>message</code> is the error object;\nwhen absent, it defaults to \"<code>assertion failed!</code>\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage ([opt [, arg]])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"<code>collect</code>\": </b>\nperforms a full garbage-collection cycle.\nThis is the default option.\n</li>\n\n<li><b>\"<code>stop</code>\": </b>\nstops automatic execution of the garbage collector.\nThe collector will run only when explicitly invoked,\nuntil a call to restart it.\n</li>\n\n<li><b>\"<code>restart</code>\": </b>\nrestarts automatic execution of the garbage collector.\n</li>\n\n<li><b>\"<code>count</code>\": </b>\nreturns the total memory in use by Lua in Kbytes.\nThe value has a fractional part,\nso that it multiplied by 1024\ngives the exact number of bytes in use by Lua\n(except for overflows).\n</li>\n\n<li><b>\"<code>step</code>\": </b>\nperforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>.\nWith a zero value,\nthe collector will perform one basic (indivisible) step.\nFor non-zero values,\nthe collector will perform as if that amount of memory\n(in KBytes) had been allocated by Lua.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"<code>setpause</code>\": </b>\nsets <code>arg</code> as the new value for the <em>pause</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>pause</em>.\n</li>\n\n<li><b>\"<code>setstepmul</code>\": </b>\nsets <code>arg</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>step</em>.\n</li>\n\n<li><b>\"<code>isrunning</code>\": </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile ([filename])</code></a></h3>\nOpens the named file and executes its contents as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller (that is, <code>dofile</code> does not run in protected mode).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nTerminates the last protected function called\nand returns <code>message</code> as the error object.\nFunction <code>error</code> never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message, if the message is a string.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (see <a href=\"#2.2\">&sect;2.2</a>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice versa.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>__metatable</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values (an iterator function, the table <code>t</code>, and 0)\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the key&ndash;value pairs\n(<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,\nup to the first nil value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>\n\n\n<p>\nLoads a chunk.\n\n\n<p>\nIf <code>chunk</code> is a string, the chunk is this string.\nIf <code>chunk</code> is a function,\n<code>load</code> calls it repeatedly to get the chunk pieces.\nEach call to <code>chunk</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no syntactic errors,\nreturns the compiled chunk as a function;\notherwise, returns <b>nil</b> plus the error message.\n\n\n<p>\nIf the resulting function has upvalues,\nthe first upvalue is set to the value of <code>env</code>,\nif that parameter is given,\nor to the value of the global environment.\nOther upvalues are initialized with <b>nil</b>.\n(When you load a main chunk,\nthe resulting function will always have exactly one upvalue,\nthe <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nHowever,\nwhen you load a binary chunk created from a function (see <a href=\"#pdf-string.dump\"><code>string.dump</code></a>),\nthe resulting function can have an arbitrary number of upvalues.)\nAll upvalues are fresh, that is,\nthey are not shared with any other function.\n\n\n<p>\n<code>chunkname</code> is used as the name of the chunk for error messages\nand debug information (see <a href=\"#4.9\">&sect;4.9</a>).\nWhen absent,\nit defaults to <code>chunk</code>, if <code>chunk</code> is a string,\nor to \"<code>=(load)</code>\" otherwise.\n\n\n<p>\nThe string <code>mode</code> controls whether the chunk can be text or binary\n(that is, a precompiled chunk).\nIt may be the string \"<code>b</code>\" (only binary chunks),\n\"<code>t</code>\" (only text chunks),\nor \"<code>bt</code>\" (both binary and text).\nThe default is \"<code>bt</code>\".\n\n\n<p>\nLua does not check the consistency of binary chunks.\nMaliciously crafted binary chunks can crash\nthe interpreter.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\n<code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numerical order,\nuse a numerical <b>for</b>.)\n\n\n<p>\nThe behavior of <code>next</code> is undefined if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may clear existing fields.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nIf <code>t</code> has a metamethod <code>__pairs</code>,\ncalls it with <code>t</code> as argument and returns the first three\nresults from the call.\n\n\n<p>\nOtherwise,\nreturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCalls function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments\nand prints their values to <code>stdout</code>,\nusing the <a href=\"#pdf-tostring\"><code>tostring</code></a> function to convert each argument to a string.\n<code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\nfor instance for debugging.\nFor complete control over the output,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a> and <a href=\"#pdf-io.write\"><code>io.write</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking the <code>__eq</code> metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout invoking the <code>__index</code> metamethod.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawlen\"><code>rawlen (v)</code></a></h3>\nReturns the length of the object <code>v</code>,\nwhich must be a table or a string,\nwithout invoking the <code>__len</code> metamethod.\nReturns an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout invoking the <code>__newindex</code> metamethod.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b> and NaN,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>;\na negative number indexes from the end (-1 is the last argument).\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\n(To change the metatable of other types from Lua code,\nyou must use the debug library (<a href=\"#6.10\">&sect;6.10</a>).)\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>__metatable</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\n\n\n<p>\nWhen called with no <code>base</code>,\n<code>tonumber</code> tries to convert its argument to a number.\nIf the argument is already a number or\na string convertible to a number,\nthen <code>tonumber</code> returns this number;\notherwise, it returns <b>nil</b>.\n\n\n<p>\nThe conversion of strings can result in integers or floats,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\n(The string may have leading and trailing spaces and a sign.)\n\n\n<p>\nWhen called with <code>base</code>,\nthen <code>e</code> must be a string to be interpreted as\nan integer numeral in that base.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIf the string <code>e</code> is not a valid numeral in the given base,\nthe function returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (v)</code></a></h3>\nReceives a value of any type and\nconverts it to a string in a human-readable format.\n(For complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.)\n\n\n<p>\nIf the metatable of <code>v</code> has a <code>__tostring</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>v</code> as argument,\nand uses the result of the call as its result.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\n\n\n<p>\nA global variable (not a function) that\nholds a string containing the running Lua version.\nThe current value of this variable is \"<code>Lua 5.3</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that it sets a new message handler <code>msgh</code>.\n\n\n\n\n\n\n\n<h2>6.2 &ndash; <a name=\"6.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThis library comprises the operations to manipulate coroutines,\nwhich come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.6\">&sect;2.6</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.isyieldable\"><code>coroutine.isyieldable ()</code></a></h3>\n\n\n<p>\nReturns true when the running coroutine can yield.\n\n\n<p>\nA running coroutine is yieldable if it is not the main thread and\nit is not inside a non-yieldable C function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, ... are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, ... are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(when the coroutine yields) or any values returned by the body function\n(when the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine plus a boolean,\ntrue when the running coroutine is the main one.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running (that is, it called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to the function behave as the\nextra arguments to <code>resume</code>.\nReturns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error, propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>6.3 &ndash; <a name=\"6.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading modules in Lua.\nIt exports one function directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a>.\nEverything else is exported in a table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a> sequence.\nBy changing this sequence,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which must be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with two arguments:\n<code>modname</code> and an extra value dependent on how it got the loader.\n(If the loader came from a file,\nthis extra value is the file name.)\nIf the loader returns any non-nil value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader does not return a non-nil value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> raises an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.config\"><code>package.config</code></a></h3>\n\n\n<p>\nA string describing some compile-time configurations for packages.\nThis string is a sequence of lines:\n\n<ul>\n\n<li>The first line is the directory separator string.\nDefault is '<code>\\</code>' for Windows and '<code>/</code>' for all other systems.</li>\n\n<li>The second line is the character that separates templates in a path.\nDefault is '<code>;</code>'.</li>\n\n<li>The third line is the string that marks the\nsubstitution points in a template.\nDefault is '<code>?</code>'.</li>\n\n<li>The fourth line is a string that, in a path in Windows,\nis replaced by the executable's directory.\nDefault is '<code>!</code>'.</li>\n\n<li>The fifth line is a mark to ignore all text after it\nwhen building the <code>luaopen_</code> function name.\nDefault is '<code>-</code>'.</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH_5_3\"><code>LUA_CPATH_5_3</code></a>\nor the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\n\n\n<p>\nIf <code>funcname</code> is \"<code>*</code>\",\nthen it only links with the library,\nmaking the symbols exported by the library\navailable to other dynamically linked libraries.\nOtherwise,\nit looks for a function <code>funcname</code> inside the library\nand returns this function as a C&nbsp;function.\nSo, <code>funcname</code> must follow the <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a> prototype\n(see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and an extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by Standard&nbsp;C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH_5_3\"><code>LUA_PATH_5_3</code></a> or\nthe environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif those environment variables are not defined.\nAny \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchers\"><code>package.searchers</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to load modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole parameter.\nThe function can return another function (the module <em>loader</em>)\nplus an extra value that will be passed to that loader,\nor a string explaining why it did not find that module\n(or <b>nil</b> if it has nothing to say).\n\n\n<p>\nLua initializes this table with four searcher functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nThe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nAgain,\nthe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits suffix after (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.b.c-v2.1</code>,\nthe function name will be <code>luaopen_a_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n<p>\nAll searchers except the first one (preload) return as the extra value\nthe file name where the module was found,\nas returned by <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nThe first searcher returns no extra value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchpath\"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3>\n\n\n<p>\nSearches for the given <code>name</code> in the given <code>path</code>.\n\n\n<p>\nA path is a string containing a sequence of\n<em>templates</em> separated by semicolons.\nFor each template,\nthe function replaces each interrogation mark (if any)\nin the template with a copy of <code>name</code>\nwherein all occurrences of <code>sep</code>\n(a dot, by default)\nwere replaced by <code>rep</code>\n(the system's directory separator, by default),\nand then tries to open the resulting file name.\n\n\n<p>\nFor instance, if the path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for the name <code>foo.a</code>\nwill try to open the files\n<code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and\n<code>/usr/local/foo/a/init.lua</code>, in that order.\n\n\n<p>\nReturns the resulting name of the first file that it can\nopen in read mode (after closing the file),\nor <b>nil</b> plus an error message if none succeeds.\n(This error message lists all file names it tried to open.)\n\n\n\n\n\n\n\n<h2>6.4 &ndash; <a name=\"6.4\">String Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s,i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numeric codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, ..., <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\nThese indices are corrected\nfollowing the same rules of function <a href=\"#pdf-string.sub\"><code>string.sub</code></a>.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numeric code equal\nto its corresponding argument.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function [, strip])</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation\n(a <em>binary chunk</em>)\nof the given function,\nso that a later <a href=\"#pdf-load\"><code>load</code></a> on this string returns\na copy of the function (but with new upvalues).\nIf <code>strip</code> is a true value,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nFunctions with upvalues have only their number of upvalues saved.\nWhen (re)loaded,\nthose upvalues receive fresh instances containing <b>nil</b>.\n(You can use the debug library to serialize\nand reload the upvalues of a function\nin a way adequate to your needs.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\n\n\n<p>\nLooks for the first match of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>nil</b>.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered magic.\nNote that if <code>plain</code> is given, then <code>init</code> must be given as well.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument (which must be a string).\nThe format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.\nThe only differences are that the options/modifiers\n<code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>,\nand <code>p</code> are not supported\nand that there is an extra option, <code>q</code>.\n\n\n<p>\nThe <code>q</code> option formats a string between double quotes,\nusing escape sequences when necessary to ensure that\nit can safely be read back by the Lua interpreter.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nmay produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre>\n\n<p>\nOptions\n<code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>G</code>, and <code>g</code> all expect a number as argument.\nOptions <code>c</code>, <code>d</code>,\n<code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>\nexpect an integer.\nWhen Lua is compiled with a C89 compiler,\noptions <code>A</code> and <code>a</code> (hexadecimal floats)\ndo not support any modifier (flags, width, length).\n\n\n<p>\nOption <code>s</code> expects a string;\nif its argument is not a string,\nit is converted to one following the same rules of <a href=\"#pdf-tostring\"><code>tostring</code></a>.\nIf the option has any modifier (flags, width, length),\nthe string argument should not contain embedded zeros.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern)</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>)\nover the string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\n\n\n<p>\nAs an example, the following loop\nwill iterate over all the words from string <code>s</code>,\nprinting one per line:\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a caret '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\nThe name <code>gsub</code> comes from <em>Global SUBstitution</em>.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>d</em></code>,\nwith <em>d</em> between 1 and 9,\nstands for the value of the <em>d</em>-th captured substring.\nThe sequence <code>%0</code> stands for the whole match.\nThe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order.\n\n\n<p>\nIn any case,\nif the pattern specifies no captures,\nthen it behaves as if the whole pattern was inside a capture.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return load(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.3\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.3.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\nLooks for the first <em>match</em> of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>nil</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.pack\"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.\npacked (that is, serialized in binary form)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>). \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.packsize\"><code>string.packsize (fmt)</code></a></h3>\n\n\n<p>\nReturns the size of a string resulting from <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nwith the given format.\nThe format string cannot have the variable-length options\n'<code>s</code>' or '<code>z</code>' (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n [, sep])</code></a></h3>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code> separated by the string <code>sep</code>.\nThe default value for <code>sep</code> is the empty string\n(that is, no separator).\nReturns the empty string if <code>n</code> is not positive.\n\n\n<p>\n(Note that it is very easy to exhaust the memory of your machine\nwith a single call to this function.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n<p>\nIf, after the translation of negative indices,\n<code>i</code> is less than 1,\nit is corrected to 1.\nIf <code>j</code> is greater than the string length,\nit is corrected to that length.\nIf, after these corrections,\n<code>i</code> is greater than <code>j</code>,\nthe function returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.unpack\"><code>string.unpack (fmt, s [, pos])</code></a></h3>\n\n\n<p>\nReturns the values packed in string <code>s</code> (see <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\nAn optional <code>pos</code> marks where\nto start reading in <code>s</code> (default is 1).\nAfter the read values,\nthis function also returns the index of the first unread byte in <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n\n\n<h3>6.4.1 &ndash; <a name=\"6.4.1\">Patterns</a></h3>\n\n<p>\nPatterns in Lua are described by regular strings,\nwhich are interpreted as patterns by the pattern-matching functions\n<a href=\"#pdf-string.find\"><code>string.find</code></a>,\n<a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>,\n<a href=\"#pdf-string.gsub\"><code>string.gsub</code></a>,\nand <a href=\"#pdf-string.match\"><code>string.match</code></a>.\nThis section describes the syntax and the meaning\n(that is, what they match) of these strings.\n\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>: </b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>: </b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>: </b> represents all letters.</li>\n\n<li><b><code>%c</code>: </b> represents all control characters.</li>\n\n<li><b><code>%d</code>: </b> represents all digits.</li>\n\n<li><b><code>%g</code>: </b> represents all printable characters except space.</li>\n\n<li><b><code>%l</code>: </b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>: </b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>: </b> represents all space characters.</li>\n\n<li><b><code>%u</code>: </b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>\n\n<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny non-alphanumeric character\n(including all punctuation characters, even the non-magical)\ncan be preceded by a '<code>%</code>'\nwhen used to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>: </b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range,\nin ascending order, with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nYou can put a closing square bracket in a set\nby positioning it as the first character in the set.\nYou can put an hyphen in a set\nby positioning it as the first or the last character in the set.\n(You can also use an escape for both cases.)\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>: </b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches zero or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches one or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches zero or more repetitions of characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the shortest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches zero or one occurrence of a character in the class.\nIt always matches one occurrence if possible;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n<li>\n<code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;\nsuch item matches an empty string at any position such that\nthe next character belongs to <em>set</em>\nand the previous character does not belong to <em>set</em>.\nThe set <em>set</em> is interpreted as previously described.\nThe beginning and the end of the subject are handled as if\nthey were the character '<code>\\0</code>'.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA caret '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture (and therefore has number&nbsp;1);\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the empty capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n\n\n\n\n\n<h3>6.4.2 &ndash; <a name=\"6.4.2\">Format Strings for Pack and Unpack</a></h3>\n\n<p>\nThe first argument to <a href=\"#pdf-string.pack\"><code>string.pack</code></a>,\n<a href=\"#pdf-string.packsize\"><code>string.packsize</code></a>, and <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>\nis a format string,\nwhich describes the layout of the structure being created or read.\n\n\n<p>\nA format string is a sequence of conversion options.\nThe conversion options are as follows:\n\n<ul>\n<li><b><code>&lt;</code>: </b>sets little endian</li>\n<li><b><code>&gt;</code>: </b>sets big endian</li>\n<li><b><code>=</code>: </b>sets native endian</li>\n<li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>\n(default is native alignment)</li>\n<li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>\n<li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>\n<li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>\n<li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>\n<li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>\n<li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>\n<li><b><code>j</code>: </b>a <code>lua_Integer</code></li>\n<li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>\n<li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>\n<li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>f</code>: </b>a <code>float</code> (native size)</li>\n<li><b><code>d</code>: </b>a <code>double</code> (native size)</li>\n<li><b><code>n</code>: </b>a <code>lua_Number</code></li>\n<li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>\n<li><b><code>z</code>: </b>a zero-terminated string</li>\n<li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length\ncoded as an unsigned integer with <code>n</code> bytes\n(default is a <code>size_t</code>)</li>\n<li><b><code>x</code>: </b>one byte of padding</li>\n<li><b><code>X<em>op</em></code>: </b>an empty item that aligns\naccording to option <code>op</code>\n(which is otherwise ignored)</li>\n<li><b>'<code> </code>': </b>(empty space) ignored</li>\n</ul><p>\n(A \"<code>[<em>n</em>]</code>\" means an optional integral numeral.)\nExcept for padding, spaces, and configurations\n(options \"<code>xX &lt;=&gt;!</code>\"),\neach option corresponds to an argument (in <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\nor a result (in <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n<p>\nFor options \"<code>!<em>n</em></code>\", \"<code>s<em>n</em></code>\", \"<code>i<em>n</em></code>\", and \"<code>I<em>n</em></code>\",\n<code>n</code> can be any integer between 1 and 16.\nAll integral options check overflows;\n<a href=\"#pdf-string.pack\"><code>string.pack</code></a> checks whether the given value fits in the given size;\n<a href=\"#pdf-string.unpack\"><code>string.unpack</code></a> checks whether the read value fits in a Lua integer.\n\n\n<p>\nAny format string starts as if prefixed by \"<code>!1=</code>\",\nthat is,\nwith maximum alignment of 1 (no alignment)\nand native endianness.\n\n\n<p>\nAlignment works as follows:\nFor each option,\nthe format gets extra padding until the data starts\nat an offset that is a multiple of the minimum between the\noption size and the maximum alignment;\nthis minimum must be a power of 2.\nOptions \"<code>c</code>\" and \"<code>z</code>\" are not aligned;\noption \"<code>s</code>\" follows the alignment of its starting integer.\n\n\n<p>\nAll padding is filled with zeros by <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\n(and ignored by <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n\n\n\n\n\n<h2>6.5 &ndash; <a name=\"6.5\">UTF-8 Support</a></h2>\n\n<p>\nThis library provides basic support for UTF-8 encoding.\nIt provides all its functions inside the table <a name=\"pdf-utf8\"><code>utf8</code></a>.\nThis library does not provide any support for Unicode other\nthan the handling of the encoding.\nAny operation that needs the meaning of a character,\nsuch as character classification, is outside its scope.\n\n\n<p>\nUnless stated otherwise,\nall functions that expect a byte position as a parameter\nassume that the given position is either the start of a byte sequence\nor one plus the length of the subject string.\nAs in the string library,\nnegative indices count from the end of the string.\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.char\"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers,\nconverts each one to its corresponding UTF-8 byte sequence\nand returns a string with the concatenation of all these sequences.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.charpattern\"><code>utf8.charpattern</code></a></h3>\nThe pattern (a string, not a function) \"<code>[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*</code>\"\n(see <a href=\"#6.4.1\">&sect;6.4.1</a>),\nwhich matches exactly one UTF-8 byte sequence,\nassuming that the subject is a valid UTF-8 string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codes\"><code>utf8.codes (s)</code></a></h3>\n\n\n<p>\nReturns values so that the construction\n\n<pre>\n     for p, c in utf8.codes(s) do <em>body</em> end\n</pre><p>\nwill iterate over all characters in string <code>s</code>,\nwith <code>p</code> being the position (in bytes) and <code>c</code> the code point\nof each character.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codepoint\"><code>utf8.codepoint (s [, i [, j]])</code></a></h3>\nReturns the codepoints (as integers) from all characters in <code>s</code>\nthat start between byte position <code>i</code> and <code>j</code> (both included).\nThe default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.len\"><code>utf8.len (s [, i [, j]])</code></a></h3>\nReturns the number of UTF-8 characters in string <code>s</code>\nthat start between positions <code>i</code> and <code>j</code> (both inclusive).\nThe default for <code>i</code> is 1 and for <code>j</code> is -1.\nIf it finds any invalid byte sequence,\nreturns a false value plus the position of the first invalid byte. \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.offset\"><code>utf8.offset (s, n [, i])</code></a></h3>\nReturns the position (in bytes) where the encoding of the\n<code>n</code>-th character of <code>s</code>\n(counting from position <code>i</code>) starts.\nA negative <code>n</code> gets characters before position <code>i</code>.\nThe default for <code>i</code> is 1 when <code>n</code> is non-negative\nand <code>#s + 1</code> otherwise,\nso that <code>utf8.offset(s, -n)</code> gets the offset of the\n<code>n</code>-th character from the end of the string.\nIf the specified character is neither in the subject\nnor right after its end,\nthe function returns <b>nil</b>.\n\n\n<p>\nAs a special case,\nwhen <code>n</code> is 0 the function returns the start of the encoding\nof the character that contains the <code>i</code>-th byte of <code>s</code>.\n\n\n<p>\nThis function assumes that <code>s</code> is a valid UTF-8 string.\n\n\n\n\n\n\n\n<h2>6.6 &ndash; <a name=\"6.6\">Table Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nRemember that, whenever an operation needs the length of a table,\nthe table must be a proper sequence\nor have a <code>__len</code> metamethod (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nAll functions ignore non-numeric keys\nin the tables given as arguments.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>\n\n\n<p>\nGiven a list where all elements are strings or numbers,\nreturns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is <code>#list</code>.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (list, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>list</code>,\nshifting up the elements\n<code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.\nThe default value for <code>pos</code> is <code>#list+1</code>,\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof list <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.move\"><code>table.move (a1, f, e, t [,a2])</code></a></h3>\n\n\n<p>\nMoves elements from table <code>a1</code> to table <code>a2</code>,\nperforming the equivalent to the following\nmultiple assignment:\n<code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.\nThe default for <code>a2</code> is <code>a1</code>.\nThe destination range can overlap with the source range.\nThe number of elements to be moved must fit in a Lua integer.\n\n\n<p>\nReturns the destination table <code>a2</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.pack\"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a new table with all parameters stored into keys 1, 2, etc.\nand with a field \"<code>n</code>\" with the total number of parameters.\nNote that the resulting table may not be a sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (list [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>list</code> the element at position <code>pos</code>,\nreturning the value of the removed element.\nWhen <code>pos</code> is an integer between 1 and <code>#list</code>,\nit shifts down the elements\n<code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>\nand erases element <code>list[#list]</code>;\nThe index <code>pos</code> can also be 0 when <code>#list</code> is 0,\nor <code>#list + 1</code>;\nin those cases, the function erases the element <code>list[pos]</code>.\n\n\n<p>\nThe default value for <code>pos</code> is <code>#list</code>,\nso that a call <code>table.remove(l)</code> removes the last element\nof list <code>l</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (list [, comp])</code></a></h3>\n\n\n<p>\nSorts list elements in a given order, <em>in-place</em>,\nfrom <code>list[1]</code> to <code>list[#list]</code>.\nIf <code>comp</code> is given,\nthen it must be a function that receives two list elements\nand returns true when the first element must come\nbefore the second in the final order\n(so that, after the sort,\n<code>i &lt; j</code> implies <code>not comp(list[j],list[i])</code>).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nNote that the <code>comp</code> function must define\na strict partial order over the elements in the list;\nthat is, it must be asymmetric and transitive.\nOtherwise, no valid sort may be possible.\n\n\n<p>\nThe sort algorithm is not stable;\nthat is, elements not comparable by the given order\n(e.g., equal elements)\nmay have their relative positions changed by the sort.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.unpack\"><code>table.unpack (list [, i [, j]])</code></a></h3>\n\n\n<p>\nReturns the elements from the given list.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.\n\n\n\n\n\n\n\n<h2>6.7 &ndash; <a name=\"6.7\">Mathematical Functions</a></h2>\n\n<p>\nThis library provides basic mathematical functions.\nIt provides all its functions and constants inside the table <a name=\"pdf-math\"><code>math</code></a>.\nFunctions with the annotation \"<code>integer/float</code>\" give\ninteger results for integer arguments\nand float results for float (or mixed) arguments.\nRounding functions\n(<a href=\"#pdf-math.ceil\"><code>math.ceil</code></a>, <a href=\"#pdf-math.floor\"><code>math.floor</code></a>, and <a href=\"#pdf-math.modf\"><code>math.modf</code></a>)\nreturn an integer when the result fits in the range of an integer,\nor a float otherwise.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the absolute value of <code>x</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (y [, x])</code></a></h3>\n\n\n<p>\n\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both parameters to find the\nquadrant of the result.\n(It also handles correctly the case of <code>x</code> being zero.)\n\n\n<p>\nThe default value for <code>x</code> is 1,\nso that the call <code>math.atan(y)</code>\nreturns the arc tangent of <code>y</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integral value larger than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from radians to degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>\n(where <code>e</code> is the base of natural logarithms).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integral value smaller than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe float value <code>HUGE_VAL</code>,\na value larger than any other numeric value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x [, base])</code></a></h3>\n\n\n<p>\nReturns the logarithm of <code>x</code> in the given base.\nThe default for <code>base</code> is <em>e</em>\n(so that the function returns the natural logarithm of <code>x</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the maximum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.maxinteger\"><code>math.maxinteger</code></a></h3>\nAn integer with the maximum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the minimum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.mininteger\"><code>math.mininteger</code></a></h3>\nAn integer with the minimum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns the integral part of <code>x</code> and the fractional part of <code>x</code>.\nIts second result is always a float.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>&pi;</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from degrees to radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nWhen called without arguments,\nreturns a pseudo-random float with uniform distribution\nin the range  <em>[0,1)</em>.  \nWhen called with two integers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a pseudo-random integer\nwith uniform distribution in the range <em>[m, n]</em>.\n(The value <em>n-m</em> cannot be negative and must fit in a Lua integer.)\nThe call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>.\n\n\n<p>\nThis function is an interface to the underling\npseudo-random generator function provided by C.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed (x)</code></a></h3>\n\n\n<p>\nSets <code>x</code> as the \"seed\"\nfor the pseudo-random generator:\nequal seeds produce equal sequences of numbers.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tointeger\"><code>math.tointeger (x)</code></a></h3>\n\n\n<p>\nIf the value <code>x</code> is convertible to an integer,\nreturns that integer.\nOtherwise, returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.type\"><code>math.type (x)</code></a></h3>\n\n\n<p>\nReturns \"<code>integer</code>\" if <code>x</code> is an integer,\n\"<code>float</code>\" if it is a float,\nor <b>nil</b> if <code>x</code> is not a number.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ult\"><code>math.ult (m, n)</code></a></h3>\n\n\n<p>\nReturns a boolean,\ntrue if integer <code>m</code> is below integer <code>n</code> when\nthey are compared as unsigned integers.\n\n\n\n\n\n\n\n<h2>6.8 &ndash; <a name=\"6.8\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file handles;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are over these default files.\nThe second style uses explicit file handles.\n\n\n<p>\nWhen using implicit file handles,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file handles,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file handle\nand then all operations are supplied as methods of the file handle.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file handles with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>nil</b> on failure\n(plus an error message as a second result and\na system-dependent error code as a third result)\nand some value different from <b>nil</b> on success.\nOn non-POSIX systems,\nthe computation of the error message and error code\nin case of errors\nmay be not thread safe,\nbecause they rely on the global C variable <code>errno</code>.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():flush()</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without parameters,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that\nworks like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.\nWhen the iterator function detects the end of file,\nit returns no values (to finish the loop) and automatically closes the file.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines(\"*l\")</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case it does not close the file when the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIn case of success,\nit returns a new file handle.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"<code>r</code>\": </b> read mode (the default);</li>\n<li><b>\"<code>w</code>\": </b> write mode;</li>\n<li><b>\"<code>a</code>\": </b> append mode;</li>\n<li><b>\"<code>r+</code>\": </b> update mode, all previous data is preserved;</li>\n<li><b>\"<code>w+</code>\": </b> update mode, all previous data is erased;</li>\n<li><b>\"<code>a+</code>\": </b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n<p>\nStarts program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nIn case of success,\nreturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>nil</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n<p>\nWhen closing a file handle created with <a href=\"#pdf-io.popen\"><code>io.popen</code></a>,\n<a href=\"#pdf-file:close\"><code>file:close</code></a> returns the same values\nreturned by <a href=\"#pdf-os.execute\"><code>os.execute</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreads the file according to the given formats.\nWhen no format is given,\nuses \"<code>l</code>\" as a default.\nAs an example, the construction\n\n<pre>\n     for c in file:lines(1) do <em>body</em> end\n</pre><p>\nwill iterate over all characters of the file,\nstarting at the current position.\nUnlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string or a number with the characters read,\nor <b>nil</b> if it cannot read data with the specified format.\n(In this latter case,\nthe function does not read subsequent formats.)\nWhen called without formats,\nit uses a default format that reads the next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"<code>n</code>\": </b>\nreads a numeral and returns it as a float or an integer,\nfollowing the lexical conventions of Lua.\n(The numeral may have leading spaces and a sign.)\nThis format always reads the longest input sequence that\nis a valid prefix for a numeral;\nif that prefix does not form a valid numeral\n(e.g., an empty string, \"<code>0x</code>\", or \"<code>3.4e-</code>\"),\nit is discarded and the function returns <b>nil</b>.\n</li>\n\n<li><b>\"<code>a</code>\": </b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string.\n</li>\n\n<li><b>\"<code>l</code>\": </b>\nreads the next line skipping the end of line,\nreturning <b>nil</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b>\"<code>L</code>\": </b>\nreads the next line keeping the end-of-line character (if present),\nreturning <b>nil</b> on end of file.\n</li>\n\n<li><b><em>number</em>: </b>\nreads a string with up to this number of bytes,\nreturning <b>nil</b> on end of file.\nIf <code>number</code> is zero,\nit reads nothing and returns an empty string,\nor <b>nil</b> on end of file.\n</li>\n\n</ul><p>\nThe formats \"<code>l</code>\" and \"<code>L</code>\" should be used only for text files.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence [, offset]])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"<code>set</code>\": </b> base is position 0 (beginning of the file);</li>\n<li><b>\"<code>cur</code>\": </b> base is current position;</li>\n<li><b>\"<code>end</code>\": </b> base is end of file;</li>\n</ul><p>\nIn case of success, <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf <code>seek</code> fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for an output file.\nThere are three available modes:\n\n<ul>\n\n<li><b>\"<code>no</code>\": </b>\nno buffering; the result of any output operation appears immediately.\n</li>\n\n<li><b>\"<code>full</code>\": </b>\nfull buffering; output operation is performed only\nwhen the buffer is full or when\nyou explicitly <code>flush</code> the file (see <a href=\"#pdf-io.flush\"><code>io.flush</code></a>).\n</li>\n\n<li><b>\"<code>line</code>\": </b>\nline buffering; output is buffered until a newline is output\nor there is any input from some special files\n(such as a terminal device).\n</li>\n\n</ul><p>\nFor the last two cases, <code>size</code>\nspecifies the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to <code>file</code>.\nThe arguments must be strings or numbers.\n\n\n<p>\nIn case of success, this function returns <code>file</code>.\nOtherwise it returns <b>nil</b> plus a string describing the error.\n\n\n\n\n\n\n\n<h2>6.9 &ndash; <a name=\"6.9\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),\n<code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),\n<code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),\n<code>yday</code> (day of the year, 1&ndash;366),\nand <code>isdst</code> (daylight saving flag, a boolean).\nThis last field may be absent\nif the information is not available.\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.\n\n\n<p>\nWhen called without arguments,\n<code>date</code> returns a reasonable date and time representation that depends on\nthe host system and on the current locale.\n(More specifically, <code>os.date()</code> is equivalent to <code>os.date(\"%c\")</code>.)\n\n\n<p>\nOn non-POSIX systems,\nthis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the difference, in seconds,\nfrom time <code>t1</code> to time <code>t2</code>\n(where the times are values returned by <a href=\"#pdf-os.time\"><code>os.time</code></a>).\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the ISO&nbsp;C function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIts first result is <b>true</b>\nif the command terminated successfully,\nor <b>nil</b> otherwise.\nAfter this first result\nthe function returns a string plus a number,\nas follows:\n\n<ul>\n\n<li><b>\"<code>exit</code>\": </b>\nthe command terminated normally;\nthe following number is the exit status of the command.\n</li>\n\n<li><b>\"<code>signal</code>\": </b>\nthe command was terminated by a signal;\nthe following number is the signal that terminated the command.\n</li>\n\n</ul>\n\n<p>\nWhen called without a <code>command</code>,\n<code>os.execute</code> returns a boolean that is true if a shell is available.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code [, close]])</code></a></h3>\n\n\n<p>\nCalls the ISO&nbsp;C function <code>exit</code> to terminate the host program.\nIf <code>code</code> is <b>true</b>,\nthe returned status is <code>EXIT_SUCCESS</code>;\nif <code>code</code> is <b>false</b>,\nthe returned status is <code>EXIT_FAILURE</code>;\nif <code>code</code> is a number,\nthe returned status is this number.\nThe default value for <code>code</code> is <b>true</b>.\n\n\n<p>\nIf the optional second argument <code>close</code> is true,\ncloses the Lua state before exiting.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>,\nor <b>nil</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file (or empty directory, on POSIX systems)\nwith the given name.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a system-dependent string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>nil</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n<p>\nThis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>setlocale</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the local date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields\n<code>hour</code> (default is 12),\n<code>min</code> (default is 0),\n<code>sec</code> (default is 0),\nand <code>isdst</code> (default is <b>nil</b>).\nOther fields are ignored.\nFor a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function.\n\n\n<p>\nThe values in these fields do not need to be inside their valid ranges.\nFor instance, if <code>sec</code> is -10,\nit means -10 seconds from the time specified by the other fields;\nif <code>hour</code> is 1000,\nit means +1000 hours from the time specified by the other fields.\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems,\nthis number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<a href=\"#pdf-os.date\"><code>os.date</code></a> and <a href=\"#pdf-os.difftime\"><code>os.difftime</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nOn POSIX systems,\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>6.10 &ndash; <a name=\"6.10\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface (<a href=\"#4.9\">&sect;4.9</a>) to Lua programs.\nYou should exert care when using this library.\nSeveral of its functions\nviolate basic assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside;\nthat userdata metatables cannot be changed by Lua code;\nthat Lua programs do not crash)\nand therefore can compromise otherwise secure code.\nMoreover, some functions in this library may be slow.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count\n(as set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly\nor you can give a number as the value of <code>f</code>,\nwhich means the function running at level <code>f</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>\n(except for tail calls, which do not count on the stack);\nand so on.\nIf <code>f</code> is a number larger than the number of active functions,\nthen <code>getinfo</code> returns <b>nil</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] f, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>f</code> of the stack.\nThis function accesses not only explicit local variables,\nbut also parameters, temporaries, etc.\n\n\n<p>\nThe first parameter or local variable has index&nbsp;1, and so on,\nfollowing the order that they are declared in the code,\ncounting only the variables that are active\nin the current scope of the function.\nNegative indices refer to vararg parameters;\n-1 is the first vararg parameter.\nThe function returns <b>nil</b> if there is no variable with the given index,\nand raises an error when called with a level out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(internal variables such as loop control variables,\nand variables from chunks saved without debug information).\n\n\n<p>\nThe parameter <code>f</code> may also be a function.\nIn that case, <code>getlocal</code> returns only the name of function parameters.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (value)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>value</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (f, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue with the given index.\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(variables from chunks saved without debug information).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getuservalue\"><code>debug.getuservalue (u)</code></a></h3>\n\n\n<p>\nReturns the Lua value associated to <code>u</code>.\nIf <code>u</code> is not a userdata,\nreturns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as a hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have any combination of the following characters,\nwith the given meaning:\n\n<ul>\n<li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>\n<li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>\n<li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nMoreover,\nwith a <code>count</code> different from zero,\nthe hook is called also after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first parameter is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code> (or <code>\"tail call\"</code>),\n<code>\"return\"</code>,\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function\n(level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n<p>\nSee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for more information about\nvariable indices and names.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (value, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>value</code> to the given <code>table</code>\n(which can be <b>nil</b>).\nReturns <code>value</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (f, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setuservalue\"><code>debug.setuservalue (udata, value)</code></a></h3>\n\n\n<p>\nSets the given <code>value</code> as\nthe Lua value associated to the given <code>udata</code>.\n<code>udata</code> must be a full userdata.\n\n\n<p>\nReturns <code>udata</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>\n\n\n<p>\nIf <code>message</code> is present but is neither a string nor <b>nil</b>,\nthis function returns <code>message</code> without further processing.\nOtherwise,\nit returns a string with a traceback of the call stack.\nThe optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvalueid\"><code>debug.upvalueid (f, n)</code></a></h3>\n\n\n<p>\nReturns a unique identifier (as a light userdata)\nfor the upvalue numbered <code>n</code>\nfrom the given function.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvaluejoin\"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>\n\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.\n\n\n\n\n\n\n\n<h1>7 &ndash; <a name=\"7\">Lua Standalone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a standalone language.\nAn interpreter for Lua as a standalone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe standalone interpreter includes\nall standard libraries, including the debug library.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li>\n<li><b><code>-l <em>mod</em></code>: </b> \"requires\" <em>mod</em>;</li>\n<li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li>\n<li><b><code>-v</code>: </b> prints version information;</li>\n<li><b><code>-E</code>: </b> ignores environment variables;</li>\n<li><b><code>--</code>: </b> stops handling options;</li>\n<li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nWhen called without option <code>-E</code>, \nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT_5_3\"><code>LUA_INIT_5_3</code></a>\n(or <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a> if the versioned name is not defined)\nbefore running any argument.\nIf the variable content has the format <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nWhen called with option <code>-E</code>,\nbesides ignoring <code>LUA_INIT</code>,\nLua also ignores\nthe values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>,\nsetting the values of\n<a href=\"#pdf-package.path\"><code>package.path</code></a> and <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>\nwith the default paths defined in <code>luaconf.h</code>.\n\n\n<p>\nAll options are handled in order, except <code>-i</code> and <code>-E</code>.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e'a=1' -e 'print(a)' script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then print the value of <code>a</code>,\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore running any code,\n<code>lua</code> collects all command-line arguments\nin a global table called <code>arg</code>.\nThe script name goes to index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus its options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe table is like this:\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nIf there is no script in the call,\nthe interpreter name goes to index 0,\nfollowed by the other arguments.\nFor instance, the call\n\n<pre>\n     $ lua -e \"print(arg[1])\"\n</pre><p>\nwill print \"<code>-e</code>\".\nIf there is a script,\nthe script is called with parameters\n<code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.\n(Like all chunks in Lua,\nthe script is compiled as a vararg function.)\n\n\n<p>\nIn interactive mode,\nLua repeatedly prompts and waits for a line.\nAfter reading a line,\nLua first try to interpret the line as an expression.\nIf it succeeds, it prints its value.\nOtherwise, it interprets the line as a statement.\nIf you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\n\n\n<p>\nIn case of unprotected errors in the script,\nthe interpreter reports the error to the standard error stream.\nIf the error object is not a string but \nhas a metamethod <code>__tostring</code>,\nthe interpreter calls this metamethod to produce the final message.\nOtherwise, the interpreter converts the error object to a string\nand adds a stack traceback to it.\n\n\n<p>\nWhen finishing normally,\nthe interpreter closes its main Lua state\n(see <a href=\"#lua_close\"><code>lua_close</code></a>).\nThe script can avoid this step by\ncalling <a href=\"#pdf-os.exit\"><code>os.exit</code></a> to terminate.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nthe standalone interpreter skips\nthe first line of a chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\n(Of course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen\n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.)\n\n\n\n<h1>8 &ndash; <a name=\"8\">Incompatibilities with the Previous Version</a></h1>\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.2 to Lua&nbsp;5.3.\nYou can avoid some incompatibilities by compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the future.\n\n\n<p>\nLua versions can always change the C API in ways that\ndo not imply source-code changes in a program,\nsuch as the numeric values for constants\nor the implementation of functions as macros.\nTherefore,\nyou should not assume that binaries are compatible between\ndifferent Lua versions.\nAlways recompile clients of the Lua API when\nusing a new version.\n\n\n<p>\nSimilarly, Lua versions can always change the internal representation\nof precompiled chunks;\nprecompiled chunks are not compatible between different Lua versions.\n\n\n<p>\nThe standard paths in the official distribution may\nchange between versions.\n\n\n\n<h2>8.1 &ndash; <a name=\"8.1\">Changes in the Language</a></h2>\n<ul>\n\n<li>\nThe main difference between Lua&nbsp;5.2 and Lua&nbsp;5.3 is the\nintroduction of an integer subtype for numbers.\nAlthough this change should not affect \"normal\" computations,\nsome computations\n(mainly those that involve some kind of overflow)\ncan give different results.\n\n\n<p>\nYou can fix these differences by forcing a number to be a float\n(in Lua&nbsp;5.2 all numbers were float),\nin particular writing constants with an ending <code>.0</code>\nor using <code>x = x + 0.0</code> to convert a variable.\n(This recommendation is only for a quick fix\nfor an occasional incompatibility;\nit is not a general guideline for good programming.\nFor good programming,\nuse floats where you need floats\nand integers where you need integers.)\n</li>\n\n<li>\nThe conversion of a float to a string now adds a <code>.0</code> suffix\nto the result if it looks like an integer.\n(For instance, the float 2.0 will be printed as <code>2.0</code>,\nnot as <code>2</code>.)\nYou should always use an explicit format\nwhen you need a specific format for numbers.\n\n\n<p>\n(Formally this is not an incompatibility,\nbecause Lua does not specify how numbers are formatted as strings,\nbut some programs assumed a specific format.)\n</li>\n\n<li>\nThe generational mode for the garbage collector was removed.\n(It was an experimental feature in Lua&nbsp;5.2.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.2 &ndash; <a name=\"8.2\">Changes in the Libraries</a></h2>\n<ul>\n\n<li>\nThe <code>bit32</code> library has been deprecated.\nIt is easy to require a compatible external library or,\nbetter yet, to replace its functions with appropriate bitwise operations.\n(Keep in mind that <code>bit32</code> operates on 32-bit integers,\nwhile the bitwise operators in Lua&nbsp;5.3 operate on Lua integers,\nwhich by default have 64&nbsp;bits.)\n</li>\n\n<li>\nThe Table library now respects metamethods\nfor setting and getting elements.\n</li>\n\n<li>\nThe <a href=\"#pdf-ipairs\"><code>ipairs</code></a> iterator now respects metamethods and\nits <code>__ipairs</code> metamethod has been deprecated.\n</li>\n\n<li>\nOption names in <a href=\"#pdf-io.read\"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore.\nFor compatibility, Lua will continue to accept (and ignore) this character.\n</li>\n\n<li>\nThe following functions were deprecated in the mathematical library:\n<code>atan2</code>, <code>cosh</code>, <code>sinh</code>, <code>tanh</code>, <code>pow</code>,\n<code>frexp</code>, and <code>ldexp</code>.\nYou can replace <code>math.pow(x,y)</code> with <code>x^y</code>;\nyou can replace <code>math.atan2</code> with <code>math.atan</code>,\nwhich now accepts one or two parameters;\nyou can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>.\nFor the other operations,\nyou can either use an external library or\nimplement them in Lua.\n</li>\n\n<li>\nThe searcher for C loaders used by <a href=\"#pdf-require\"><code>require</code></a>\nchanged the way it handles versioned names.\nNow, the version should come after the module name\n(as is usual in most other tools).\nFor compatibility, that searcher still tries the old format\nif it cannot find an open function according to the new style.\n(Lua&nbsp;5.2 already worked that way,\nbut it did not document the change.)\n</li>\n\n<li>\nThe call <code>collectgarbage(\"count\")</code> now returns only one result.\n(You can compute that second result from the fractional part\nof the first result.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.3 &ndash; <a name=\"8.3\">Changes in the API</a></h2>\n\n\n<ul>\n\n<li>\nContinuation functions now receive as parameters what they needed\nto get through <code>lua_getctx</code>,\nso <code>lua_getctx</code> has been removed.\nAdapt your code accordingly.\n</li>\n\n<li>\nFunction <a href=\"#lua_dump\"><code>lua_dump</code></a> has an extra parameter, <code>strip</code>.\nUse 0 as the value of this parameter to get the old behavior.\n</li>\n\n<li>\nFunctions to inject/project unsigned integers\n(<code>lua_pushunsigned</code>, <code>lua_tounsigned</code>, <code>lua_tounsignedx</code>,\n<code>luaL_checkunsigned</code>, <code>luaL_optunsigned</code>)\nwere deprecated.\nUse their signed equivalents with a type cast.\n</li>\n\n<li>\nMacros to project non-default integer types\n(<code>luaL_checkint</code>, <code>luaL_optint</code>, <code>luaL_checklong</code>, <code>luaL_optlong</code>)\nwere deprecated.\nUse their equivalent over <a href=\"#lua_Integer\"><code>lua_Integer</code></a> with a type cast\n(or, when possible, use <a href=\"#lua_Integer\"><code>lua_Integer</code></a> in your code).\n</li>\n\n</ul>\n\n\n\n\n<h1>9 &ndash; <a name=\"9\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\nAs usual in extended BNF,\n{A} means 0 or more As,\nand [A] means an optional A.\n(For operator precedences, see <a href=\"#3.4.8\">&sect;3.4.8</a>;\nfor a description of the terminals\nName, Numeral,\nand LiteralString, see <a href=\"#3.1\">&sect;3.1</a>.)\n\n\n\n\n<pre>\n\n\tchunk ::= block\n\n\tblock ::= {stat} [retstat]\n\n\tstat ::=  &lsquo;<b>;</b>&rsquo; | \n\t\t varlist &lsquo;<b>=</b>&rsquo; explist | \n\t\t functioncall | \n\t\t label | \n\t\t <b>break</b> | \n\t\t <b>goto</b> Name | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] \n\n\tretstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\n\tvar ::=  Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name \n\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | &lsquo;<b>...</b>&rsquo; | functiondef | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n\n\tfunctioncall ::=  prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args \n\n\targs ::=  &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | LiteralString \n\n\tfunctiondef ::= <b>function</b> funcbody\n\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n\n\tbinop ::=  &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>//</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; | \n\t\t &lsquo;<b>&amp;</b>&rsquo; | &lsquo;<b>~</b>&rsquo; | &lsquo;<b>|</b>&rsquo; | &lsquo;<b>&gt;&gt;</b>&rsquo; | &lsquo;<b>&lt;&lt;</b>&rsquo; | &lsquo;<b>..</b>&rsquo; | \n\t\t &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo; | &lsquo;<b>~</b>&rsquo;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n\n<P CLASS=\"footer\">\nLast update:\nMon May 30 13:11:08 BRT 2016\n</P>\n<!--\nLast change: revised for Lua 5.3.3\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "build/lua-5.3.3/doc/readme.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 readme</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<STYLE TYPE=\"text/css\">\nblockquote, .display {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 8px ;\n\tpadding: 1em ;\n\tmargin: 0px ;\n}\n\n.display {\n\tword-spacing: 0.25em ;\n}\n\ndl.display dd {\n\tpadding-bottom: 0.2em ;\n}\n\ntt, kbd, code {\n\tfont-size: 12pt ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nWelcome to Lua 5.3\n</H1>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"#about\">about</A>\n&middot;\n<A HREF=\"#install\">installation</A>\n&middot;\n<A HREF=\"#changes\">changes</A>\n&middot;\n<A HREF=\"#license\">license</A>\n&middot;\n<A HREF=\"contents.html\">reference manual</A>\n</DIV>\n\n<H2><A NAME=\"about\">About Lua</A></H2>\n<P>\nLua is a powerful, fast, lightweight, embeddable scripting language\ndeveloped by a\n<A HREF=\"http://www.lua.org/authors.html\">team</A>\nat\n<A HREF=\"http://www.puc-rio.br/\">PUC-Rio</A>,\nthe Pontifical Catholic University of Rio de Janeiro in Brazil.\nLua is\n<A HREF=\"#license\">free software</A>\nused in many products and projects around the world.\n\n<P>\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\nprovides complete information\nabout Lua,\nincluding\nan\n<A HREF=\"http://www.lua.org/about.html\">executive summary</A>\nand\nupdated\n<A HREF=\"http://www.lua.org/docs.html\">documentation</A>,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.3/\">reference manual</A>,\nwhich may differ slightly from the\n<A HREF=\"contents.html\">local copy</A>\ndistributed in this package.\n\n<H2><A NAME=\"install\">Installing Lua</A></H2>\n<P>\nLua is distributed in\n<A HREF=\"http://www.lua.org/ftp/\">source</A>\nform.\nYou need to build it before using it.\nBuilding Lua should be straightforward\nbecause\nLua is implemented in pure ANSI C and compiles unmodified in all known\nplatforms that have an ANSI C compiler.\nLua also compiles unmodified as C++.\nThe instructions given below for building Lua are for Unix-like platforms.\nSee also\n<A HREF=\"#other\">instructions for other systems</A>\nand\n<A HREF=\"#customization\">customization options</A>.\n\n<P>\nIf you don't have the time or the inclination to compile Lua yourself,\nget a binary from\n<A HREF=\"http://lua-users.org/wiki/LuaBinaries\">LuaBinaries</A>.\nTry also\n<A HREF=\"http://luadist.org/\">LuaDist</A>,\na multi-platform distribution of Lua that includes batteries.\n\n<H3>Building Lua</H3>\n<P>\nIn most Unix-like platforms, simply do \"<KBD>make</KBD>\" with a suitable target.\nHere are the details.\n\n<OL>\n<LI>\nOpen a terminal window and move to\nthe top-level directory, which is named <TT>lua-5.3.x</TT>.\nThe <TT>Makefile</TT> there controls both the build process and the installation process.\n<P>\n<LI>\n  Do \"<KBD>make</KBD>\" and see if your platform is listed.\n  The platforms currently supported are:\n<P>\n<P CLASS=\"display\">\n   aix bsd c89 freebsd generic linux macosx mingw posix solaris\n</P>\n<P>\n  If your platform is listed, just do \"<KBD>make xxx</KBD>\", where xxx\n  is your platform name.\n<P>\n  If your platform is not listed, try the closest one or posix, generic,\n  c89, in this order.\n<P>\n<LI>\nThe compilation takes only a few moments\nand produces three files in the <TT>src</TT> directory:\nlua (the interpreter),\nluac (the compiler),\nand liblua.a (the library).\n<P>\n<LI>\n  To check that Lua has been built correctly, do \"<KBD>make test</KBD>\"\n  after building Lua. This will run the interpreter and print its version.\n</OL>\n<P>\nIf you're running Linux and get compilation errors,\nmake sure you have installed the <TT>readline</TT> development package\n(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).\nIf you get link errors after that,\nthen try \"<KBD>make linux MYLIBS=-ltermcap</KBD>\".\n\n<H3>Installing Lua</H3>\n<P>\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"<KBD>make install</KBD>\". The official\n  place and the way to install files are defined in the <TT>Makefile</TT>. You'll\n  probably need the right permissions to install files.\n\n<P>\n  To build and install Lua in one step, do \"<KBD>make xxx install</KBD>\",\n  where xxx is your platform name.\n\n<P>\n  To install Lua locally, do \"<KBD>make local</KBD>\".\n  This will create a directory <TT>install</TT> with subdirectories\n  <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,\n  and install Lua as listed below.\n\n  To install Lua locally, but in some other directory, do\n  \"<KBD>make install INSTALL_TOP=xxx</KBD>\", where xxx is your chosen directory.\n  The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,\n  so take care if <TT>INSTALL_TOP</TT> is not an absolute path.\n\n<DL CLASS=\"display\">\n<DT>\n    bin:\n<DD>\n    lua luac\n<DT>\n    include:\n<DD>\n    lua.h luaconf.h lualib.h lauxlib.h lua.hpp\n<DT>\n    lib:\n<DD>\n    liblua.a\n<DT>\n    man/man1:\n<DD>\n    lua.1 luac.1\n</DL>\n\n<P>\n  These are the only directories you need for development.\n  If you only want to run Lua programs,\n  you only need the files in <TT>bin</TT> and <TT>man</TT>.\n  The files in <TT>include</TT> and <TT>lib</TT> are needed for\n  embedding Lua in C or C++ programs.\n\n<H3><A NAME=\"customization\">Customization</A></H3>\n<P>\n  Three kinds of things can be customized by editing a file:\n<UL>\n    <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.\n    <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.\n    <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.\n</UL>\n\n<P>\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables in the command line when invoking make.\n  Nevertheless, it's probably best to edit and save the Makefiles to\n  record the changes you've made.\n\n<P>\n  On the other hand, if you need to customize some Lua features, you'll need\n  to edit <TT>src/luaconf.h</TT> before building and installing Lua.\n  The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n  Further customization is available to experts by editing the Lua sources.\n\n<H3><A NAME=\"other\">Building Lua on other systems</A></H3>\n<P>\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n<DL CLASS=\"display\">\n<DT>\nlibrary:\n<DD>\nlapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c\nlmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c\nltm.c lundump.c lvm.c lzio.c\nlauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c\nlmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c\n<DT>\ninterpreter:\n<DD>\n  library, lua.c\n<DT>\ncompiler:\n<DD>\n  library, luac.c\n</DL>\n\n<P>\n  To use Lua as a library in your own programs you'll need to know how to\n  create and use libraries with your compiler. Moreover, to dynamically load\n  C libraries for Lua you'll need to know how to create dynamic libraries\n  and you'll need to make sure that the Lua API functions are accessible to\n  those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library\n  into each dynamic library. For Unix, we recommend that the Lua library\n  be linked statically into the host program and its symbols exported for\n  dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.\n  For Windows, we recommend that the Lua library be a DLL.\n  In all cases, the compiler luac should be linked statically.\n\n<P>\n  As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize\n  some features before building Lua.\n\n<H2><A NAME=\"changes\">Changes since Lua 5.2</A></H2>\n<P>\nHere are the main changes introduced in Lua 5.3.\nThe\n<A HREF=\"contents.html\">reference manual</A>\nlists the\n<A HREF=\"manual.html#8\">incompatibilities</A> that had to be introduced.\n\n<H3>Main changes</H3>\n<UL>\n<LI> integers (64-bit by default)\n<LI> official support for 32-bit numbers\n<LI> bitwise operators\n<LI> basic utf-8 support\n<LI> functions for packing and unpacking values\n\n</UL>\n\nHere are the other changes introduced in Lua 5.3:\n<H3>Language</H3>\n<UL>\n<LI> userdata can have any Lua value as uservalue\n<LI> floor division\n<LI> more flexible rules for some metamethods\n</UL>\n\n<H3>Libraries</H3>\n<UL>\n<LI> <CODE>ipairs</CODE> and the table library respect metamethods\n<LI> strip option in <CODE>string.dump</CODE>\n<LI> table library respects metamethods\n<LI> new function <CODE>table.move</CODE>\n<LI> new function <CODE>string.pack</CODE>\n<LI> new function <CODE>string.unpack</CODE>\n<LI> new function <CODE>string.packsize</CODE>\n</UL>\n\n<H3>C API</H3>\n<UL>\n<LI> simpler API for continuation functions in C\n<LI> <CODE>lua_gettable</CODE> and similar functions return type of resulted value\n<LI> strip option in <CODE>lua_dump</CODE>\n<LI> new function: <CODE>lua_geti</CODE>\n<LI> new function: <CODE>lua_seti</CODE>\n<LI> new function: <CODE>lua_isyieldable</CODE>\n<LI> new function: <CODE>lua_numbertointeger</CODE>\n<LI> new function: <CODE>lua_rotate</CODE>\n<LI> new function: <CODE>lua_stringtonumber</CODE>\n</UL>\n\n<H3>Lua standalone interpreter</H3>\n<UL>\n<LI> can be used as calculator; no need to prefix with '='\n<LI> <CODE>arg</CODE> table available to all code\n</UL>\n\n<H2><A NAME=\"license\">License</A></H2>\n<P>\n<A HREF=\"http://www.opensource.org/docs/definition.php\">\n<IMG SRC=\"osi-certified-72x60.png\" ALIGN=\"right\" ALT=\"[osi certified]\" STYLE=\"padding-left: 30px ;\">\n</A>\nLua is free software distributed under the terms of the\n<A HREF=\"http://www.opensource.org/licenses/mit-license.html\">MIT license</A>\nreproduced below;\nit may be used for any purpose, including commercial purposes,\nat absolutely no cost without having to ask us.\n\nThe only requirement is that if you do use Lua,\nthen you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.\n\nFor details, see\n<A HREF=\"http://www.lua.org/license.html\">this</A>.\n\n<BLOCKQUOTE STYLE=\"padding-bottom: 0em\">\nCopyright &copy; 1994&ndash;2016 Lua.org, PUC-Rio.\n\n<P>\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n<P>\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n<P>\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n</BLOCKQUOTE>\n<P>\n\n<P CLASS=\"footer\">\nLast update:\nTue Feb  2 22:25:27 BRST 2016\n</P>\n<!--\nLast change: revised for Lua 5.3.3\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.3/etc/lua.pc",
    "content": "# lua.pc -- pkg-config data for Lua\r\n\r\n# vars from install Makefile\r\n\r\n# grep '^V=' ../Makefile\r\nV= 5.1\r\n# grep '^R=' ../Makefile\r\nR= 5.1.5\r\n\r\n# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'\r\nprefix= /usr/local\r\nINSTALL_BIN= ${prefix}/bin\r\nINSTALL_INC= ${prefix}/include\r\nINSTALL_LIB= ${prefix}/lib\r\nINSTALL_MAN= ${prefix}/man/man1\r\nINSTALL_LMOD= ${prefix}/share/lua/${V}\r\nINSTALL_CMOD= ${prefix}/lib/lua/${V}\r\n\r\n# canonical vars\r\nexec_prefix=${prefix}\r\nlibdir=${exec_prefix}/lib\r\nincludedir=${prefix}/include\r\n\r\nName: Lua\r\nDescription: An Extensible Extension Language\r\nVersion: ${R}\r\nRequires: \r\nLibs: -L${libdir} -llua -lm\r\nCflags: -I${includedir}\r\n\r\n# (end of lua.pc)\r\n"
  },
  {
    "path": "build/lua-5.3.3/src/Makefile",
    "content": "# Makefile for building Lua\n# See ../doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\nCC= gcc -std=gnu99\nCFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)\nLDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)\nLIBS= -lm $(SYSLIBS) $(MYLIBS)\n\nAR= ar rcu\nRANLIB= ranlib\nRM= rm -f\n\nSYSCFLAGS=\nSYSLDFLAGS=\nSYSLIBS=\n\nMYCFLAGS=\nMYLDFLAGS=\nMYLIBS=\nMYOBJS=\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\nLUA_A=\tliblua.a\nCORE_O=\tlapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \\\n\tlmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \\\n\tltm.o lundump.o lvm.o lzio.o\nLIB_O=\tlauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \\\n\tlmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o\nBASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)\n\nLUA_T=\tlua\nLUA_O=\tlua.o\n\nLUAC_T=\tluac\nLUAC_O=\tluac.o\n\nALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)\nALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)\nALL_A= $(LUA_A)\n\n# Targets start here.\ndefault: $(PLAT)\n\nall:\t$(ALL_T)\n\no:\t$(ALL_O)\n\na:\t$(ALL_A)\n\n$(LUA_A): $(BASE_O)\n\t$(AR) $@ $(BASE_O)\n\t$(RANLIB) $@\n\n$(LUA_T): $(LUA_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)\n\n$(LUAC_T): $(LUAC_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)\n\nclean:\n\t$(RM) $(ALL_T) $(ALL_O)\n\ndepend:\n\t@$(CC) $(CFLAGS) -MM l*.c\n\necho:\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"CC= $(CC)\"\n\t@echo \"CFLAGS= $(CFLAGS)\"\n\t@echo \"LDFLAGS= $(SYSLDFLAGS)\"\n\t@echo \"LIBS= $(LIBS)\"\n\t@echo \"AR= $(AR)\"\n\t@echo \"RANLIB= $(RANLIB)\"\n\t@echo \"RM= $(RM)\"\n\n# Convenience targets for popular platforms\nALL= all\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\naix:\n\t$(MAKE) $(ALL) CC=\"xlc\" CFLAGS=\"-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-ldl\" SYSLDFLAGS=\"-brtl -bexpall\"\n\nbsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-Wl,-E\"\n\nc89:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_C89\" CC=\"gcc -std=c89\"\n\t@echo ''\n\t@echo '*** C89 does not guarantee 64-bit integers for Lua.'\n\t@echo ''\n\n\nfreebsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -lreadline\"\n\ngeneric: $(ALL)\n\nlinux:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -ldl -lreadline\"\n\nmacosx:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_MACOSX\" SYSLIBS=\"-lreadline\" CC=cc\n\nmingw:\n\t$(MAKE) \"LUA_A=lua53.dll\" \"LUA_T=lua.exe\" \\\n\t\"AR=$(CC) -shared -o\" \"RANLIB=strip --strip-unneeded\" \\\n\t\"SYSCFLAGS=-DLUA_BUILD_AS_DLL\" \"SYSLIBS=\" \"SYSLDFLAGS=-s\" lua.exe\n\t$(MAKE) \"LUAC_T=luac.exe\" luac.exe\n\nposix:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX\"\n\nsolaris:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT\" SYSLIBS=\"-ldl\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) default o a clean depend echo none\n\n# DO NOT DELETE\n\nlapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \\\n ltable.h lundump.h lvm.h\nlauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h\nlbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lgc.h lstring.h ltable.h lvm.h\nlcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h\nldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \\\n ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h\nldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \\\n lparser.h lstring.h ltable.h lundump.h lvm.h\nldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \\\n ltm.h lzio.h lmem.h lundump.h\nlfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \\\n lgc.h lstate.h ltm.h lzio.h lmem.h\nlgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h\nlinit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h\nliolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nllex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \\\n lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \\\n lstring.h ltable.h\nlmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h\nloadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \\\n ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \\\n lvm.h\nlopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h\nloslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lfunc.h lstring.h lgc.h ltable.h\nlstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \\\n lstring.h ltable.h\nlstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h\nlstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h\nltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h\nlua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nluac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \\\n lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h\nlundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \\\n lundump.h\nlutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \\\n ltable.h lvm.h\nlzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \\\n lobject.h ltm.h lzio.h\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.3/src/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$LuaVersion: \" LUA_COPYRIGHT \" $\"\n  \"$LuaAuthors: \" LUA_AUTHORS \" $\";\n\n\n/* value at a non-valid index */\n#define NONVALIDVALUE\t\tcast(TValue *, luaO_nilobject)\n\n/* corresponding test */\n#define isvalid(o)\t((o) != luaO_nilobject)\n\n/* test for pseudo index */\n#define ispseudo(i)\t\t((i) <= LUA_REGISTRYINDEX)\n\n/* test for upvalue */\n#define isupvalue(i)\t\t((i) < LUA_REGISTRYINDEX)\n\n/* test for valid but not pseudo index */\n#define isstackindex(i, o)\t(isvalid(o) && !ispseudo(i))\n\n#define api_checkvalidindex(l,o)  api_check(l, isvalid(o), \"invalid index\")\n\n#define api_checkstackindex(l, i, o)  \\\n\tapi_check(l, isstackindex(i, o), \"index not in the stack\")\n\n\nstatic TValue *index2addr (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    TValue *o = ci->func + idx;\n    api_check(L, idx <= ci->top - (ci->func + 1), \"unacceptable index\");\n    if (o >= L->top) return NONVALIDVALUE;\n    else return o;\n  }\n  else if (!ispseudo(idx)) {  /* negative index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    return L->top + idx;\n  }\n  else if (idx == LUA_REGISTRYINDEX)\n    return &G(L)->l_registry;\n  else {  /* upvalues */\n    idx = LUA_REGISTRYINDEX - idx;\n    api_check(L, idx <= MAXUPVAL + 1, \"upvalue index too large\");\n    if (ttislcf(ci->func))  /* light C function? */\n      return NONVALIDVALUE;  /* it has no upvalues */\n    else {\n      CClosure *func = clCvalue(ci->func);\n      return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;\n    }\n  }\n}\n\n\n/*\n** to be called by 'lua_checkstack' in protected mode, to grow stack\n** capturing memory errors\n*/\nstatic void growstack (lua_State *L, void *ud) {\n  int size = *(int *)ud;\n  luaD_growstack(L, size);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int n) {\n  int res;\n  CallInfo *ci = L->ci;\n  lua_lock(L);\n  api_check(L, n >= 0, \"negative 'n'\");\n  if (L->stack_last - L->top > n)  /* stack large enough? */\n    res = 1;  /* yes; check is OK */\n  else {  /* no; need to grow stack */\n    int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;\n    if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */\n      res = 0;  /* no */\n    else  /* try to grow stack */\n      res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK);\n  }\n  if (res && ci->top < L->top + n)\n    ci->top = L->top + n;  /* adjust frame top */\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to), \"moving among independent states\");\n  api_check(from, to->ci->top - to->top >= n, \"stack overflow\");\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobj2s(to, to->top, from->top + i);\n    to->top++;  /* stack already checked by previous 'api_check' */\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API const lua_Number *lua_version (lua_State *L) {\n  static const lua_Number version = LUA_VERSION_NUM;\n  if (L == NULL) return &version;\n  else return G(L)->version;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\n/*\n** convert an acceptable stack index into an absolute index\n*/\nLUA_API int lua_absindex (lua_State *L, int idx) {\n  return (idx > 0 || ispseudo(idx))\n         ? idx\n         : cast_int(L->top - L->ci->func) + idx;\n}\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - (L->ci->func + 1));\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  StkId func = L->ci->func;\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - (func + 1), \"new top too large\");\n    while (L->top < (func + 1) + idx)\n      setnilvalue(L->top++);\n    L->top = (func + 1) + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - (func + 1)), \"invalid new top\");\n    L->top += idx+1;  /* 'subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\n/*\n** Reverse the stack segment from 'from' to 'to'\n** (auxiliary to 'lua_rotate')\n*/\nstatic void reverse (lua_State *L, StkId from, StkId to) {\n  for (; from < to; from++, to--) {\n    TValue temp;\n    setobj(L, &temp, from);\n    setobjs2s(L, from, to);\n    setobj2s(L, to, &temp);\n  }\n}\n\n\n/*\n** Let x = AB, where A is a prefix of length 'n'. Then,\n** rotate x n == BA. But BA == (A^r . B^r)^r.\n*/\nLUA_API void lua_rotate (lua_State *L, int idx, int n) {\n  StkId p, t, m;\n  lua_lock(L);\n  t = L->top - 1;  /* end of stack segment being rotated */\n  p = index2addr(L, idx);  /* start of segment */\n  api_checkstackindex(L, idx, p);\n  api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), \"invalid 'n'\");\n  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */\n  reverse(L, p, m);  /* reverse the prefix with length 'n' */\n  reverse(L, m + 1, t);  /* reverse the suffix */\n  reverse(L, p, t);  /* reverse the entire segment */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {\n  TValue *fr, *to;\n  lua_lock(L);\n  fr = index2addr(L, fromidx);\n  to = index2addr(L, toidx);\n  api_checkvalidindex(L, to);\n  setobj(L, to, fr);\n  if (isupvalue(toidx))  /* function upvalue? */\n    luaC_barrier(L, clCvalue(L->ci->func), fr);\n  /* LUA_REGISTRYINDEX does not need gc barrier\n     (collector revisits it before finishing collection) */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2addr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (isvalid(o) ? ttnov(o) : LUA_TNONE);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, \"invalid tag\");\n  return ttypename(t);\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (ttislcf(o) || (ttisCclosure(o)));\n}\n\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return ttisinteger(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisstring(o) || cvt2str(o));\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisfulluserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2addr(L, index1);\n  StkId o2 = index2addr(L, index2);\n  return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;\n}\n\n\nLUA_API void lua_arith (lua_State *L, int op) {\n  lua_lock(L);\n  if (op != LUA_OPUNM && op != LUA_OPBNOT)\n    api_checknelems(L, 2);  /* all other operations expect two operands */\n  else {  /* for unary operations, add fake 2nd operand */\n    api_checknelems(L, 1);\n    setobjs2s(L, L->top, L->top - 1);\n    api_incr_top(L);\n  }\n  /* first operand at top - 2, second at top - 1; result go to top - 2 */\n  luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2);\n  L->top--;  /* remove second operand */\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {\n  StkId o1, o2;\n  int i = 0;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2addr(L, index1);\n  o2 = index2addr(L, index2);\n  if (isvalid(o1) && isvalid(o2)) {\n    switch (op) {\n      case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;\n      case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;\n      case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;\n      default: api_check(L, 0, \"invalid option\");\n    }\n  }\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {\n  size_t sz = luaO_str2num(s, L->top);\n  if (sz != 0)\n    api_incr_top(L);\n  return sz;\n}\n\n\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tonumber(o, &n);\n  if (!isnum)\n    n = 0;  /* call to 'tonumber' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return n;\n}\n\n\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {\n  lua_Integer res;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tointeger(o, &res);\n  if (!isnum)\n    res = 0;  /* call to 'tointeger' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return res;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2addr(L, idx);\n  if (!ttisstring(o)) {\n    if (!cvt2str(o)) {  /* not convertible? */\n      if (len != NULL) *len = 0;\n      return NULL;\n    }\n    lua_lock(L);  /* 'luaO_tostring' may create a new string */\n    luaO_tostring(L, o);\n    luaC_checkGC(L);\n    o = index2addr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL)\n    *len = vslen(o);\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_rawlen (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSHRSTR: return tsvalue(o)->shrlen;\n    case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  if (ttislcf(o)) return fvalue(o);\n  else if (ttisCclosure(o))\n    return clCvalue(o)->f;\n  else return NULL;  /* not a C function */\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttnov(o)) {\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TLCL: return clLvalue(o);\n    case LUA_TCCL: return clCvalue(o);\n    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setfltvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setivalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** Pushes on the stack a string with given length. Avoid using 's' when\n** 'len' == 0 (as 's' can be NULL in that case), due to later use of\n** 'memcmp' and 'memcpy'.\n*/\nLUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  TString *ts;\n  lua_lock(L);\n  ts = (len == 0) ? luaS_new(L, \"\") : luaS_newlstr(L, s, len);\n  setsvalue2s(L, L->top, ts);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getstr(ts);\n}\n\n\nLUA_API const char *lua_pushstring (lua_State *L, const char *s) {\n  lua_lock(L);\n  if (s == NULL)\n    setnilvalue(L->top);\n  else {\n    TString *ts;\n    ts = luaS_new(L, s);\n    setsvalue2s(L, L->top, ts);\n    s = getstr(ts);  /* internal copy's address */\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return s;\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  lua_lock(L);\n  if (n == 0) {\n    setfvalue(L->top, fn);\n  }\n  else {\n    CClosure *cl;\n    api_checknelems(L, n);\n    api_check(L, n <= MAXUPVAL, \"upvalue index too large\");\n    cl = luaF_newCclosure(L, n);\n    cl->f = fn;\n    L->top -= n;\n    while (n--) {\n      setobj2n(L, &cl->upvalue[n], L->top + n);\n      /* does not need barrier because closure is white */\n    }\n    setclCvalue(L, L->top, cl);\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(L->top, p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nstatic int auxgetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setsvalue2s(L, L->top, str);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);\n  return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API int lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);\n  return auxgetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  if (luaV_fastget(L, t, n, slot, luaH_getint)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top, luaH_getint(hvalue(t), n));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {\n  StkId t;\n  TValue k;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  setobj2s(L, L->top, luaH_get(hvalue(t), &k));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  Table *t;\n  lua_lock(L);\n  t = luaH_new(L);\n  sethvalue(L, L->top, t);\n  api_incr_top(L);\n  if (narray > 0 || nrec > 0)\n    luaH_resize(L, t, narray, nrec);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt;\n  int res = 0;\n  lua_lock(L);\n  obj = index2addr(L, objindex);\n  switch (ttnov(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(obj)];\n      break;\n  }\n  if (mt != NULL) {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API int lua_getuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  getuservalue(L, uvalue(o), L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n/*\n** t[k] = value at the top of the stack (where 'k' is a string)\n*/\nstatic void auxsetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  api_checknelems(L, 1);\n  if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);  /* lock done by caller */\n}\n\n\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2addr(L, idx);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2addr(L, idx);\n  if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId o;\n  TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  slot = luaH_set(L, hvalue(o), L->top - 2);\n  setobj2t(L, slot, L->top - 1);\n  invalidateTMcache(hvalue(o));\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  luaH_setint(L, hvalue(o), n, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {\n  StkId o;\n  TValue k, *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  slot = luaH_set(L, hvalue(o), &k);\n  setobj2t(L, slot, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2addr(L, objindex);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1), \"table expected\");\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttnov(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, gcvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, uvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    default: {\n      G(L)->mt[ttnov(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API void lua_setuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  setuservalue(L, uvalue(o), L->top - 1);\n  luaC_barrier(L, gcvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\n/*\n** 'load' and 'call' functions (run Lua code)\n*/\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \\\n\t\"results from function overflow current stack size\")\n\n\nLUA_API void lua_callk (lua_State *L, int nargs, int nresults,\n                        lua_KContext ctx, lua_KFunction k) {\n  StkId func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  if (k != NULL && L->nny == 0) {  /* need to prepare continuation? */\n    L->ci->u.c.k = k;  /* save continuation */\n    L->ci->u.c.ctx = ctx;  /* save context */\n    luaD_call(L, func, nresults);  /* do the call */\n  }\n  else  /* no continuation or no yieldable */\n    luaD_callnoyield(L, func, nresults);  /* just do the call */\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to 'f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_callnoyield(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,\n                        lua_KContext ctx, lua_KFunction k) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2addr(L, errfunc);\n    api_checkstackindex(L, errfunc, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  if (k == NULL || L->nny > 0) {  /* no continuation or no yieldable? */\n    c.nresults = nresults;  /* do a 'conventional' protected call */\n    status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  }\n  else {  /* prepare continuation (call is already protected by 'resume') */\n    CallInfo *ci = L->ci;\n    ci->u.c.k = k;  /* save continuation */\n    ci->u.c.ctx = ctx;  /* save context */\n    /* save information for error recovery */\n    ci->extra = savestack(L, c.func);\n    ci->u.c.old_errfunc = L->errfunc;\n    L->errfunc = func;\n    setoah(ci->callstatus, L->allowhook);  /* save value of 'allowhook' */\n    ci->callstatus |= CIST_YPCALL;  /* function can do error recovery */\n    luaD_call(L, c.func, nresults);  /* do the call */\n    ci->callstatus &= ~CIST_YPCALL;\n    L->errfunc = ci->u.c.old_errfunc;\n    status = LUA_OK;  /* if it is here, there were no errors */\n  }\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname, const char *mode) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname, mode);\n  if (status == LUA_OK) {  /* no errors? */\n    LClosure *f = clLvalue(L->top - 1);  /* get newly created function */\n    if (f->nupvalues >= 1) {  /* does it have an upvalue? */\n      /* get global table from registry */\n      Table *reg = hvalue(&G(L)->l_registry);\n      const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);\n      /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */\n      setobj(L, f->upvals[0]->v, gt);\n      luaC_upvalbarrier(L, f->upvals[0]);\n    }\n  }\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, getproto(o), writer, data, strip);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->gcrunning = 0;\n      break;\n    }\n    case LUA_GCRESTART: {\n      luaE_setdebt(g, 0);\n      g->gcrunning = 1;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L, 0);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(gettotalbytes(g) >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(gettotalbytes(g) & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      l_mem debt = 1;  /* =1 to signal that it did an actual step */\n      lu_byte oldrunning = g->gcrunning;\n      g->gcrunning = 1;  /* allow GC to run */\n      if (data == 0) {\n        luaE_setdebt(g, -GCSTEPSIZE);  /* to do a \"small\" step */\n        luaC_step(L);\n      }\n      else {  /* add 'data' to total debt */\n        debt = cast(l_mem, data) * 1024 + g->GCdebt;\n        luaE_setdebt(g, debt);\n        luaC_checkGC(L);\n      }\n      g->gcrunning = oldrunning;  /* restore previous state */\n      if (debt > 0 && g->gcstate == GCSpause)  /* end of cycle? */\n        res = 1;  /* signal it */\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      if (data < 40) data = 40;  /* avoid ridiculous low values (and 0) */\n      g->gcstepmul = data;\n      break;\n    }\n    case LUA_GCISRUNNING: {\n      res = g->gcrunning;\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  /* code unreachable; will unlock when control actually leaves the kernel */\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaV_concat(L, n);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_len (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_objlen(L, L->top, t);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  u = luaS_newudata(L, size);\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getudatamem(u);\n}\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val,\n                                CClosure **owner, UpVal **uv) {\n  switch (ttype(fi)) {\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      if (!(1 <= n && n <= f->nupvalues)) return NULL;\n      *val = &f->upvalue[n-1];\n      if (owner) *owner = f;\n      return \"\";\n    }\n    case LUA_TLCL: {  /* Lua closure */\n      LClosure *f = clLvalue(fi);\n      TString *name;\n      Proto *p = f->p;\n      if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n      *val = f->upvals[n-1]->v;\n      if (uv) *uv = f->upvals[n - 1];\n      name = p->upvalues[n-1].name;\n      return (name == NULL) ? \"(*no name)\" : getstr(name);\n    }\n    default: return NULL;  /* not a closure */\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  lua_lock(L);\n  name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  CClosure *owner = NULL;\n  UpVal *uv = NULL;\n  StkId fi;\n  lua_lock(L);\n  fi = index2addr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val, &owner, &uv);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    if (owner) { luaC_barrier(L, owner, L->top); }\n    else if (uv) { luaC_upvalbarrier(L, uv); }\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {\n  LClosure *f;\n  StkId fi = index2addr(L, fidx);\n  api_check(L, ttisLclosure(fi), \"Lua function expected\");\n  f = clLvalue(fi);\n  api_check(L, (1 <= n && n <= f->p->sizeupvalues), \"invalid upvalue index\");\n  if (pf) *pf = f;\n  return &f->upvals[n - 1];  /* get its upvalue pointer */\n}\n\n\nLUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {\n  StkId fi = index2addr(L, fidx);\n  switch (ttype(fi)) {\n    case LUA_TLCL: {  /* lua closure */\n      return *getupvalref(L, fidx, n, NULL);\n    }\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      api_check(L, 1 <= n && n <= f->nupvalues, \"invalid upvalue index\");\n      return &f->upvalue[n - 1];\n    }\n    default: {\n      api_check(L, 0, \"closure expected\");\n      return NULL;\n    }\n  }\n}\n\n\nLUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,\n                                            int fidx2, int n2) {\n  LClosure *f1;\n  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);\n  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);\n  luaC_upvdeccount(L, *up1);\n  *up1 = *up2;\n  (*up1)->refcount++;\n  if (upisopen(*up1)) (*up1)->u.open.touched = 1;\n  luaC_upvalbarrier(L, *up1);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"llimits.h\"\n#include \"lstate.h\"\n\n#define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \\\n\t\t\t\t\"stack overflow\");}\n\n#define adjustresults(L,nres) \\\n    { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }\n\n#define api_checknelems(L,n)\tapi_check(L, (n) < (L->top - L->ci->func), \\\n\t\t\t\t  \"not enough elements in the stack\")\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.286 2016/01/08 15:33:09 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/*\n** This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n/*\n** {======================================================\n** Traceback\n** =======================================================\n*/\n\n\n#define LEVELS1\t10\t/* size of the first part of the stack */\n#define LEVELS2\t11\t/* size of the second part of the stack */\n\n\n\n/*\n** search for 'objidx' in table at index -1.\n** return 1 + string at top if find a good name.\n*/\nstatic int findfield (lua_State *L, int objidx, int level) {\n  if (level == 0 || !lua_istable(L, -1))\n    return 0;  /* not found */\n  lua_pushnil(L);  /* start 'next' loop */\n  while (lua_next(L, -2)) {  /* for each pair in table */\n    if (lua_type(L, -2) == LUA_TSTRING) {  /* ignore non-string keys */\n      if (lua_rawequal(L, objidx, -1)) {  /* found object? */\n        lua_pop(L, 1);  /* remove value (but keep name) */\n        return 1;\n      }\n      else if (findfield(L, objidx, level - 1)) {  /* try recursively */\n        lua_remove(L, -2);  /* remove table (but keep name) */\n        lua_pushliteral(L, \".\");\n        lua_insert(L, -2);  /* place '.' between the two names */\n        lua_concat(L, 3);\n        return 1;\n      }\n    }\n    lua_pop(L, 1);  /* remove value */\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Search for a name for a function in all loaded modules\n** (registry._LOADED).\n*/\nstatic int pushglobalfuncname (lua_State *L, lua_Debug *ar) {\n  int top = lua_gettop(L);\n  lua_getinfo(L, \"f\", ar);  /* push function */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  if (findfield(L, top + 1, 2)) {\n    const char *name = lua_tostring(L, -1);\n    if (strncmp(name, \"_G.\", 3) == 0) {  /* name start with '_G.'? */\n      lua_pushstring(L, name + 3);  /* push name without prefix */\n      lua_remove(L, -2);  /* remove original name */\n    }\n    lua_copy(L, -1, top + 1);  /* move name to proper place */\n    lua_pop(L, 2);  /* remove pushed values */\n    return 1;\n  }\n  else {\n    lua_settop(L, top);  /* remove function and global table */\n    return 0;\n  }\n}\n\n\nstatic void pushfuncname (lua_State *L, lua_Debug *ar) {\n  if (pushglobalfuncname(L, ar)) {  /* try first a global name */\n    lua_pushfstring(L, \"function '%s'\", lua_tostring(L, -1));\n    lua_remove(L, -2);  /* remove name */\n  }\n  else if (*ar->namewhat != '\\0')  /* is there a name from code? */\n    lua_pushfstring(L, \"%s '%s'\", ar->namewhat, ar->name);  /* use it */\n  else if (*ar->what == 'm')  /* main? */\n      lua_pushliteral(L, \"main chunk\");\n  else if (*ar->what != 'C')  /* for Lua functions, use <file:line> */\n    lua_pushfstring(L, \"function <%s:%d>\", ar->short_src, ar->linedefined);\n  else  /* nothing left... */\n    lua_pushliteral(L, \"?\");\n}\n\n\nstatic int lastlevel (lua_State *L) {\n  lua_Debug ar;\n  int li = 1, le = 1;\n  /* find an upper bound */\n  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }\n  /* do a binary search */\n  while (li < le) {\n    int m = (li + le)/2;\n    if (lua_getstack(L, m, &ar)) li = m + 1;\n    else le = m;\n  }\n  return le - 1;\n}\n\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,\n                                const char *msg, int level) {\n  lua_Debug ar;\n  int top = lua_gettop(L);\n  int last = lastlevel(L1);\n  int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;\n  if (msg)\n    lua_pushfstring(L, \"%s\\n\", msg);\n  luaL_checkstack(L, 10, NULL);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (n1-- == 0) {  /* too many levels? */\n      lua_pushliteral(L, \"\\n\\t...\");  /* add a '...' */\n      level = last - LEVELS2 + 1;  /* and skip to last ones */\n    }\n    else {\n      lua_getinfo(L1, \"Slnt\", &ar);\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n      if (ar.currentline > 0)\n        lua_pushfstring(L, \"%d:\", ar.currentline);\n      lua_pushliteral(L, \" in \");\n      pushfuncname(L, &ar);\n      if (ar.istailcall)\n        lua_pushliteral(L, \"\\n\\t(...tail calls...)\");\n      lua_concat(L, lua_gettop(L) - top);\n    }\n  }\n  lua_concat(L, lua_gettop(L) - top);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", arg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    arg--;  /* do not count 'self' */\n    if (arg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling '%s' on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : \"?\";\n  return luaL_error(L, \"bad argument #%d to '%s' (%s)\",\n                        arg, ar.name, extramsg);\n}\n\n\nstatic int typeerror (lua_State *L, int arg, const char *tname) {\n  const char *msg;\n  const char *typearg;  /* name for the type of the actual argument */\n  if (luaL_getmetafield(L, arg, \"__name\") == LUA_TSTRING)\n    typearg = lua_tostring(L, -1);  /* use the given type name */\n  else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)\n    typearg = \"light userdata\";  /* special name for messages */\n  else\n    typearg = luaL_typename(L, arg);  /* standard name */\n  msg = lua_pushfstring(L, \"%s expected, got %s\", tname, typearg);\n  return luaL_argerror(L, arg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int arg, int tag) {\n  typeerror(L, arg, lua_typename(L, tag));\n}\n\n\n/*\n** The use of 'lua_pushfstring' ensures this function does not\n** need reserved stack space when called.\n*/\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushfstring(L, \"\");  /* else, no information available... */\n}\n\n\n/*\n** Again, the use of 'lua_pushvfstring' ensures this function does\n** not need reserved stack space when called. (At worst, it generates\n** an error with \"stack overflow\" instead of the given message.)\n*/\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n\nLUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (stat) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushstring(L, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n#if !defined(l_inspectstat)\t/* { */\n\n#if defined(LUA_USE_POSIX)\n\n#include <sys/wait.h>\n\n/*\n** use appropriate macros to interpret 'pclose' return status\n*/\n#define l_inspectstat(stat,what)  \\\n   if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \\\n   else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = \"signal\"; }\n\n#else\n\n#define l_inspectstat(stat,what)  /* no op */\n\n#endif\n\n#endif\t\t\t\t/* } */\n\n\nLUALIB_API int luaL_execresult (lua_State *L, int stat) {\n  const char *what = \"exit\";  /* type of termination */\n  if (stat == -1)  /* error? */\n    return luaL_fileresult(L, 0, NULL);\n  else {\n    l_inspectstat(stat, what);  /* interpret result */\n    if (*what == 'e' && stat == 0)  /* successful termination? */\n      lua_pushboolean(L, 1);\n    else\n      lua_pushnil(L);\n    lua_pushstring(L, what);\n    lua_pushinteger(L, stat);\n    return 3;  /* return true/nil,what,code */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Userdata's metatable manipulation\n** =======================================================\n*/\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  if (luaL_getmetatable(L, tname) != LUA_TNIL)  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_createtable(L, 0, 2);  /* create metatable */\n  lua_pushstring(L, tname);\n  lua_setfield(L, -2, \"__name\");  /* metatable.__name = tname */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {\n  luaL_getmetatable(L, tname);\n  lua_setmetatable(L, -2);\n}\n\n\nLUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      luaL_getmetatable(L, tname);  /* get correct metatable */\n      if (!lua_rawequal(L, -1, -2))  /* not the same? */\n        p = NULL;  /* value is a userdata with wrong metatable */\n      lua_pop(L, 2);  /* remove both metatables */\n      return p;\n    }\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = luaL_testudata(L, ud, tname);\n  if (p == NULL) typeerror(L, ud, tname);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Argument check functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, arg, def) :\n                             luaL_checkstring(L, arg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, arg,\n                       lua_pushfstring(L, \"invalid option '%s'\", name));\n}\n\n\n/*\n** Ensures the stack has at least 'space' extra slots, raising an error\n** if it cannot fulfill the request. (The error handling needs a few\n** extra slots to format the error message. In case of an error without\n** this extra space, Lua will generate the same 'stack overflow' error,\n** but without 'msg'.)\n*/\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {\n  if (!lua_checkstack(L, space)) {\n    if (msg)\n      luaL_error(L, \"stack overflow (%s)\", msg);\n    else\n      luaL_error(L, \"stack overflow\");\n  }\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int arg, int t) {\n  if (lua_type(L, arg) != t)\n    tag_error(L, arg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNONE)\n    luaL_argerror(L, arg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) {\n  const char *s = lua_tolstring(L, arg, len);\n  if (!s) tag_error(L, arg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int arg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, arg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, arg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) {\n  int isnum;\n  lua_Number d = lua_tonumberx(L, arg, &isnum);\n  if (!isnum)\n    tag_error(L, arg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, arg, def);\n}\n\n\nstatic void interror (lua_State *L, int arg) {\n  if (lua_isnumber(L, arg))\n    luaL_argerror(L, arg, \"number has no integer representation\");\n  else\n    tag_error(L, arg, LUA_TNUMBER);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {\n  int isnum;\n  lua_Integer d = lua_tointegerx(L, arg, &isnum);\n  if (!isnum) {\n    interror(L, arg);\n  }\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, arg, def);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n/* userdata to box arbitrary data */\ntypedef struct UBox {\n  void *box;\n  size_t bsize;\n} UBox;\n\n\nstatic void *resizebox (lua_State *L, int idx, size_t newsize) {\n  void *ud;\n  lua_Alloc allocf = lua_getallocf(L, &ud);\n  UBox *box = (UBox *)lua_touserdata(L, idx);\n  void *temp = allocf(ud, box->box, box->bsize, newsize);\n  if (temp == NULL && newsize > 0) {  /* allocation error? */\n    resizebox(L, idx, 0);  /* free buffer */\n    luaL_error(L, \"not enough memory for buffer allocation\");\n  }\n  box->box = temp;\n  box->bsize = newsize;\n  return temp;\n}\n\n\nstatic int boxgc (lua_State *L) {\n  resizebox(L, 1, 0);\n  return 0;\n}\n\n\nstatic void *newbox (lua_State *L, size_t newsize) {\n  UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));\n  box->box = NULL;\n  box->bsize = 0;\n  if (luaL_newmetatable(L, \"LUABOX\")) {  /* creating metatable? */\n    lua_pushcfunction(L, boxgc);\n    lua_setfield(L, -2, \"__gc\");  /* metatable.__gc = boxgc */\n  }\n  lua_setmetatable(L, -2);\n  return resizebox(L, -1, newsize);\n}\n\n\n/*\n** check whether buffer is using a userdata on the stack as a temporary\n** buffer\n*/\n#define buffonstack(B)\t((B)->b != (B)->initb)\n\n\n/*\n** returns a pointer to a free area with at least 'sz' bytes\n*/\nLUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {\n  lua_State *L = B->L;\n  if (B->size - B->n < sz) {  /* not enough space? */\n    char *newbuff;\n    size_t newsize = B->size * 2;  /* double buffer size */\n    if (newsize - B->n < sz)  /* not big enough? */\n      newsize = B->n + sz;\n    if (newsize < B->n || newsize - B->n < sz)\n      luaL_error(L, \"buffer too large\");\n    /* create larger buffer */\n    if (buffonstack(B))\n      newbuff = (char *)resizebox(L, -1, newsize);\n    else {  /* no buffer yet */\n      newbuff = (char *)newbox(L, newsize);\n      memcpy(newbuff, B->b, B->n * sizeof(char));  /* copy original content */\n    }\n    B->b = newbuff;\n    B->size = newsize;\n  }\n  return &B->b[B->n];\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */\n    char *b = luaL_prepbuffsize(B, l);\n    memcpy(b, s, l * sizeof(char));\n    luaL_addsize(B, l);\n  }\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  lua_pushlstring(L, B->b, B->n);\n  if (buffonstack(B)) {\n    resizebox(L, -2, 0);  /* delete old buffer */\n    lua_remove(L, -2);  /* remove its header from the stack */\n  }\n}\n\n\nLUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {\n  luaL_addsize(B, sz);\n  luaL_pushresult(B);\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t l;\n  const char *s = lua_tolstring(L, -1, &l);\n  if (buffonstack(B))\n    lua_insert(L, -2);  /* put value below buffer */\n  luaL_addlstring(B, s, l);\n  lua_remove(L, (buffonstack(B)) ? -2 : -1);  /* remove value */\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->b = B->initb;\n  B->n = 0;\n  B->size = LUAL_BUFFERSIZE;\n}\n\n\nLUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {\n  luaL_buffinit(L, B);\n  return luaL_prepbuffsize(B, sz);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Reference system\n** =======================================================\n*/\n\n/* index of free-list header */\n#define freelist\t0\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* 'nil' has a unique fixed reference */\n  }\n  t = lua_absindex(L, t);\n  lua_rawgeti(L, t, freelist);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[freelist] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, freelist);  /* (t[freelist] = t[ref]) */\n  }\n  else  /* no free elements */\n    ref = (int)lua_rawlen(L, t) + 1;  /* get a new reference */\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = lua_absindex(L, t);\n    lua_rawgeti(L, t, freelist);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[freelist] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, freelist);  /* t[freelist] = ref */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int n;  /* number of pre-read characters */\n  FILE *f;  /* file being read */\n  char buff[BUFSIZ];  /* area for reading file */\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;  /* not used */\n  if (lf->n > 0) {  /* are there pre-read characters to be read? */\n    *size = lf->n;  /* return them (chars already in buffer) */\n    lf->n = 0;  /* no more pre-read characters */\n  }\n  else {  /* read a block from file */\n    /* 'fread' can return > 0 *and* set the EOF flag. If next call to\n       'getF' called 'fread', it might still wait for user input.\n       The next check avoids this problem. */\n    if (feof(lf->f)) return NULL;\n    *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */\n  }\n  return lf->buff;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nstatic int skipBOM (LoadF *lf) {\n  const char *p = \"\\xEF\\xBB\\xBF\";  /* UTF-8 BOM mark */\n  int c;\n  lf->n = 0;\n  do {\n    c = getc(lf->f);\n    if (c == EOF || c != *(const unsigned char *)p++) return c;\n    lf->buff[lf->n++] = c;  /* to be read by the parser */\n  } while (*p != '\\0');\n  lf->n = 0;  /* prefix matched; discard it */\n  return getc(lf->f);  /* return next character */\n}\n\n\n/*\n** reads the first character of file 'f' and skips an optional BOM mark\n** in its beginning plus its first line if it starts with '#'. Returns\n** true if it skipped the first line.  In any case, '*cp' has the\n** first \"valid\" character of the file (after the optional BOM and\n** a first-line comment).\n*/\nstatic int skipcomment (LoadF *lf, int *cp) {\n  int c = *cp = skipBOM(lf);\n  if (c == '#') {  /* first line is a comment (Unix exec. file)? */\n    do {  /* skip first line */\n      c = getc(lf->f);\n    } while (c != EOF && c != '\\n');\n    *cp = getc(lf->f);  /* skip end-of-line, if present */\n    return 1;  /* there was a comment */\n  }\n  else return 0;  /* no comment */\n}\n\n\nLUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,\n                                             const char *mode) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  if (skipcomment(&lf, &c))  /* read initial portion */\n    lf.buff[lf.n++] = '\\n';  /* add line to correct line numbers */\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    skipcomment(&lf, &c);  /* re-read initial portion */\n  }\n  if (c != EOF)\n    lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;  /* not used */\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,\n                                 const char *name, const char *mode) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name, mode);\n}\n\n\nLUALIB_API int luaL_loadstring (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return LUA_TNIL;\n  else {\n    int tt;\n    lua_pushstring(L, event);\n    tt = lua_rawget(L, -2);\n    if (tt == LUA_TNIL)  /* is metafield nil? */\n      lua_pop(L, 2);  /* remove metatable and metafield */\n    else\n      lua_remove(L, -2);  /* remove only metatable */\n    return tt;  /* return metafield type */\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = lua_absindex(L, obj);\n  if (luaL_getmetafield(L, obj, event) == LUA_TNIL)  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {\n  lua_Integer l;\n  int isnum;\n  lua_len(L, idx);\n  l = lua_tointegerx(L, -1, &isnum);\n  if (!isnum)\n    luaL_error(L, \"object length is not an integer\");\n  lua_pop(L, 1);  /* remove object */\n  return l;\n}\n\n\nLUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {\n  if (!luaL_callmeta(L, idx, \"__tostring\")) {  /* no metafield? */\n    switch (lua_type(L, idx)) {\n      case LUA_TNUMBER: {\n        if (lua_isinteger(L, idx))\n          lua_pushfstring(L, \"%I\", lua_tointeger(L, idx));\n        else\n          lua_pushfstring(L, \"%f\", lua_tonumber(L, idx));\n        break;\n      }\n      case LUA_TSTRING:\n        lua_pushvalue(L, idx);\n        break;\n      case LUA_TBOOLEAN:\n        lua_pushstring(L, (lua_toboolean(L, idx) ? \"true\" : \"false\"));\n        break;\n      case LUA_TNIL:\n        lua_pushliteral(L, \"nil\");\n        break;\n      default:\n        lua_pushfstring(L, \"%s: %p\", luaL_typename(L, idx),\n                                            lua_topointer(L, idx));\n        break;\n    }\n  }\n  return lua_tolstring(L, -1, len);\n}\n\n\n/*\n** {======================================================\n** Compatibility with 5.1 module functions\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\nstatic const char *luaL_findtable (lua_State *L, int idx,\n                                   const char *fname, int szhint) {\n  const char *e;\n  if (idx) lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    if (lua_rawget(L, -2) == LUA_TNIL) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n/*\n** Count number of elements in a luaL_Reg list.\n*/\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l && l->name; l++) size++;\n  return size;\n}\n\n\n/*\n** Find or create a module table with a given name. The function\n** first looks at the _LOADED table and, if that fails, try a\n** global variable with that name. In any case, leaves on the stack\n** the module table.\n*/\nLUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,\n                                 int sizehint) {\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 1);  /* get _LOADED table */\n  if (lua_getfield(L, -1, modname) != LUA_TTABLE) {  /* no _LOADED[modname]? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    lua_pushglobaltable(L);\n    if (luaL_findtable(L, 0, modname, sizehint) != NULL)\n      luaL_error(L, \"name conflict for module '%s'\", modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, -3, modname);  /* _LOADED[modname] = new table */\n  }\n  lua_remove(L, -2);  /* remove _LOADED table */\n}\n\n\nLUALIB_API void luaL_openlib (lua_State *L, const char *libname,\n                               const luaL_Reg *l, int nup) {\n  luaL_checkversion(L);\n  if (libname) {\n    luaL_pushmodule(L, libname, libsize(l));  /* get/create library table */\n    lua_insert(L, -(nup + 1));  /* move library table to below upvalues */\n  }\n  if (l)\n    luaL_setfuncs(L, l, nup);\n  else\n    lua_pop(L, nup);  /* remove upvalues */\n}\n\n#endif\n/* }====================================================== */\n\n/*\n** set functions from list 'l' into table at top - 'nup'; each\n** function gets the 'nup' elements at the top as upvalues.\n** Returns with only the table at the stack.\n*/\nLUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name != NULL; l++) {  /* fill the table with given functions */\n    int i;\n    for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** ensure that stack[idx][fname] has a table and push that table\n** into the stack\n*/\nLUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {\n  if (lua_getfield(L, idx, fname) == LUA_TTABLE)\n    return 1;  /* table already there */\n  else {\n    lua_pop(L, 1);  /* remove previous result */\n    idx = lua_absindex(L, idx);\n    lua_newtable(L);\n    lua_pushvalue(L, -1);  /* copy to be left at top */\n    lua_setfield(L, idx, fname);  /* assign new table to field */\n    return 0;  /* false, because did not find table there */\n  }\n}\n\n\n/*\n** Stripped-down 'require': After checking \"loaded\" table, calls 'openf'\n** to open a module, registers the result in 'package.loaded' table and,\n** if 'glb' is true, also registers the result in the global table.\n** Leaves resulting module on the top.\n*/\nLUALIB_API void luaL_requiref (lua_State *L, const char *modname,\n                               lua_CFunction openf, int glb) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, modname);  /* _LOADED[modname] */\n  if (!lua_toboolean(L, -1)) {  /* package not already loaded? */\n    lua_pop(L, 1);  /* remove field */\n    lua_pushcfunction(L, openf);\n    lua_pushstring(L, modname);  /* argument to open function */\n    lua_call(L, 1, 1);  /* call 'openf' to open module */\n    lua_pushvalue(L, -1);  /* make copy of module (call result) */\n    lua_setfield(L, -3, modname);  /* _LOADED[modname] = module */\n  }\n  lua_remove(L, -2);  /* remove _LOADED table */\n  if (glb) {\n    lua_pushvalue(L, -1);  /* copy of module */\n    lua_setglobal(L, modname);  /* _G[modname] = module */\n  }\n}\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after 'p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud; (void)osize;  /* not used */\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  lua_writestringerror(\"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                        lua_tostring(L, -1));\n  return 0;  /* return to Lua to abort */\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n\nLUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {\n  const lua_Number *v = lua_version(L);\n  if (sz != LUAL_NUMSIZES)  /* check numeric types */\n    luaL_error(L, \"core and library have incompatible numeric types\");\n  if (v != lua_version(NULL))\n    luaL_error(L, \"multiple Lua VMs detected\");\n  else if (*v != ver)\n    luaL_error(L, \"version mismatch: app. needs %f, Lua core provides %f\",\n                  ver, *v);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n\n/* extra error code for 'luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n#define LUAL_NUMSIZES\t(sizeof(lua_Integer)*16 + sizeof(lua_Number))\n\nLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);\n#define luaL_checkversion(L)  \\\n\t  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)\n\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\nLUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int arg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void  (luaL_setmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\nLUALIB_API int (luaL_execresult) (lua_State *L, int stat);\n\n/* predefined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n                                               const char *mode);\n\n#define luaL_loadfile(L,f)\tluaL_loadfilex(L,f,NULL)\n\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n                                   const char *name, const char *mode);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\nLUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\n\nLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\n\nLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\n                                  const char *msg, int level);\n\nLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\n                                 lua_CFunction openf, int glb);\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n\n#define luaL_newlibtable(L,l)\t\\\n  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n\n#define luaL_newlib(L,l)  \\\n  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n\n#define luaL_argcheck(L, cond,arg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (arg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n#define luaL_loadbuffer(L,s,sz,n)\tluaL_loadbufferx(L,s,sz,n,NULL)\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\ntypedef struct luaL_Buffer {\n  char *b;  /* buffer address */\n  size_t size;  /* buffer size */\n  size_t n;  /* number of characters in buffer */\n  lua_State *L;\n  char initb[LUAL_BUFFERSIZE];  /* initial buffer */\n} luaL_Buffer;\n\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\\n   ((B)->b[(B)->n++] = (c)))\n\n#define luaL_addsize(B,s)\t((B)->n += (s))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\n\n#define luaL_prepbuffer(B)\tluaL_prepbuffsize(B, LUAL_BUFFERSIZE)\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** File handles for IO library\n** =======================================================\n*/\n\n/*\n** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\n** initial structure 'luaL_Stream' (it may contain other fields\n** after that initial structure).\n*/\n\n#define LUA_FILEHANDLE          \"FILE*\"\n\n\ntypedef struct luaL_Stream {\n  FILE *f;  /* stream (NULL for incompletely created streams) */\n  lua_CFunction closef;  /* to close stream (NULL for closed streams) */\n} luaL_Stream;\n\n/* }====================================================== */\n\n\n\n/* compatibility with old module system */\n#if defined(LUA_COMPAT_MODULE)\n\nLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\n                                   int sizehint);\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\n\n#define luaL_register(L,n,l)\t(luaL_openlib(L,(n),(l),0))\n\n#endif\n\n\n/*\n** {==================================================================\n** \"Abstraction Layer\" for basic report of messages and errors\n** ===================================================================\n*/\n\n/* print a string */\n#if !defined(lua_writestring)\n#define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)\n#endif\n\n/* print a newline and flush the output */\n#if !defined(lua_writeline)\n#define lua_writeline()        (lua_writestring(\"\\n\", 1), fflush(stdout))\n#endif\n\n/* print an error message */\n#if !defined(lua_writestringerror)\n#define lua_writestringerror(s,p) \\\n        (fprintf(stderr, (s), (p)), fflush(stderr))\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {============================================================\n** Compatibility with deprecated conversions\n** =============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define luaL_checkunsigned(L,a)\t((lua_Unsigned)luaL_checkinteger(L,a))\n#define luaL_optunsigned(L,a,d)\t\\\n\t((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))\n\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#endif\n/* }============================================================ */\n\n\n\n#endif\n\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.313 2016/04/11 19:18:40 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    size_t l;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tolstring(L, -1, &l);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, \"'tostring' must return a string to 'print'\");\n    if (i>1) lua_writestring(\"\\t\", 1);\n    lua_writestring(s, l);\n    lua_pop(L, 1);  /* pop result */\n  }\n  lua_writeline();\n  return 0;\n}\n\n\n#define SPACECHARS\t\" \\f\\n\\r\\t\\v\"\n\nstatic const char *b_str2int (const char *s, int base, lua_Integer *pn) {\n  lua_Unsigned n = 0;\n  int neg = 0;\n  s += strspn(s, SPACECHARS);  /* skip initial spaces */\n  if (*s == '-') { s++; neg = 1; }  /* handle signal */\n  else if (*s == '+') s++;\n  if (!isalnum((unsigned char)*s))  /* no digit? */\n    return NULL;\n  do {\n    int digit = (isdigit((unsigned char)*s)) ? *s - '0'\n                   : (toupper((unsigned char)*s) - 'A') + 10;\n    if (digit >= base) return NULL;  /* invalid numeral */\n    n = n * base + digit;\n    s++;\n  } while (isalnum((unsigned char)*s));\n  s += strspn(s, SPACECHARS);  /* skip trailing spaces */\n  *pn = (lua_Integer)((neg) ? (0u - n) : n);\n  return s;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */\n    luaL_checkany(L, 1);\n    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */\n      lua_settop(L, 1);  /* yes; return it */\n      return 1;\n    }\n    else {\n      size_t l;\n      const char *s = lua_tolstring(L, 1, &l);\n      if (s != NULL && lua_stringtonumber(L, s) == l + 1)\n        return 1;  /* successful conversion to number */\n      /* else not a number */\n    }\n  }\n  else {\n    size_t l;\n    const char *s;\n    lua_Integer n = 0;  /* to avoid warnings */\n    lua_Integer base = luaL_checkinteger(L, 2);\n    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */\n    s = lua_tolstring(L, 1, &l);\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    if (b_str2int(s, (int)base, &n) == s + l) {\n      lua_pushinteger(L, n);\n      return 1;\n    }  /* else not a number */\n  }  /* else not a number */\n  lua_pushnil(L);  /* not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = (int)luaL_optinteger(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {\n    luaL_where(L, level);   /* add extra information */\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\") != LUA_TNIL)\n    return luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawlen (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,\n                   \"table or string expected\");\n  lua_pushinteger(L, lua_rawlen(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\n    \"isrunning\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n    LUA_GCISRUNNING};\n  int o = optsnum[luaL_checkoption(L, 1, \"collect\", opts)];\n  int ex = (int)luaL_optinteger(L, 2, 0);\n  int res = lua_gc(L, o, ex);\n  switch (o) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: case LUA_GCISRUNNING: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushinteger(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t != LUA_TNONE, 1, \"value expected\");\n  lua_pushstring(L, lua_typename(L, t));\n  return 1;\n}\n\n\nstatic int pairsmeta (lua_State *L, const char *method, int iszero,\n                      lua_CFunction iter) {\n  if (luaL_getmetafield(L, 1, method) == LUA_TNIL) {  /* no metamethod? */\n    luaL_checktype(L, 1, LUA_TTABLE);  /* argument must be a table */\n    lua_pushcfunction(L, iter);  /* will return generator, */\n    lua_pushvalue(L, 1);  /* state, */\n    if (iszero) lua_pushinteger(L, 0);  /* and initial value */\n    else lua_pushnil(L);\n  }\n  else {\n    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */\n    lua_call(L, 1, 3);  /* get 3 values from metamethod */\n  }\n  return 3;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  return pairsmeta(L, \"__pairs\", 0, luaB_next);\n}\n\n\n/*\n** Traversal function for 'ipairs'\n*/\nstatic int ipairsaux (lua_State *L) {\n  lua_Integer i = luaL_checkinteger(L, 2) + 1;\n  lua_pushinteger(L, i);\n  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;\n}\n\n\n/*\n** 'ipairs' function. Returns 'ipairsaux', given \"table\", 0.\n** (The given \"table\" may not be a table.)\n*/\nstatic int luaB_ipairs (lua_State *L) {\n#if defined(LUA_COMPAT_IPAIRS)\n  return pairsmeta(L, \"__ipairs\", 1, ipairsaux);\n#else\n  luaL_checkany(L, 1);\n  lua_pushcfunction(L, ipairsaux);  /* iteration function */\n  lua_pushvalue(L, 1);  /* state */\n  lua_pushinteger(L, 0);  /* initial value */\n  return 3;\n#endif\n}\n\n\nstatic int load_aux (lua_State *L, int status, int envidx) {\n  if (status == LUA_OK) {\n    if (envidx != 0) {  /* 'env' parameter? */\n      lua_pushvalue(L, envidx);  /* environment for loaded function */\n      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */\n        lua_pop(L, 1);  /* remove 'env' if not used by previous call */\n    }\n    return 1;\n  }\n  else {  /* error (message is on top of the stack) */\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  const char *mode = luaL_optstring(L, 2, NULL);\n  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */\n  int status = luaL_loadfilex(L, fname, mode);\n  return load_aux(L, status, env);\n}\n\n\n/*\n** {======================================================\n** Generic Read function\n** =======================================================\n*/\n\n\n/*\n** reserved slot, above all arguments, to hold a copy of the returned\n** string to avoid it being collected while parsed. 'load' has four\n** optional arguments (chunk, source name, mode, and environment).\n*/\n#define RESERVEDSLOT\t5\n\n\n/*\n** Reader for generic 'load' function: 'lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)(ud);  /* not used */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* pop result */\n    *size = 0;\n    return NULL;\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"reader function must return a string\");\n  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */\n  return lua_tolstring(L, RESERVEDSLOT, size);\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  size_t l;\n  const char *s = lua_tolstring(L, 1, &l);\n  const char *mode = luaL_optstring(L, 3, \"bt\");\n  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */\n  if (s != NULL) {  /* loading a string? */\n    const char *chunkname = luaL_optstring(L, 2, s);\n    status = luaL_loadbufferx(L, s, l, chunkname, mode);\n  }\n  else {  /* loading from a reader function */\n    const char *chunkname = luaL_optstring(L, 2, \"=(load)\");\n    luaL_checktype(L, 1, LUA_TFUNCTION);\n    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */\n    status = lua_load(L, generic_reader, NULL, chunkname, mode);\n  }\n  return load_aux(L, status, env);\n}\n\n/* }====================================================== */\n\n\nstatic int dofilecont (lua_State *L, int d1, lua_KContext d2) {\n  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */\n  return lua_gettop(L) - 1;\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  lua_settop(L, 1);\n  if (luaL_loadfile(L, fname) != LUA_OK)\n    return lua_error(L);\n  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);\n  return dofilecont(L, 0, 0);\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  if (lua_toboolean(L, 1))  /* condition is true? */\n    return lua_gettop(L);  /* return all arguments */\n  else {  /* error */\n    luaL_checkany(L, 1);  /* there must be a condition */\n    lua_remove(L, 1);  /* remove it */\n    lua_pushliteral(L, \"assertion failed!\");  /* default message */\n    lua_settop(L, 1);  /* leave only message (default if no other one) */\n    return luaB_error(L);  /* call 'error' */\n  }\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    lua_Integer i = luaL_checkinteger(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - (int)i;\n  }\n}\n\n\n/*\n** Continuation function for 'pcall' and 'xpcall'. Both functions\n** already pushed a 'true' before doing the call, so in case of success\n** 'finishpcall' only has to return everything in the stack minus\n** 'extra' values (where 'extra' is exactly the number of items to be\n** ignored).\n*/\nstatic int finishpcall (lua_State *L, int status, lua_KContext extra) {\n  if (status != LUA_OK && status != LUA_YIELD) {  /* error? */\n    lua_pushboolean(L, 0);  /* first result (false) */\n    lua_pushvalue(L, -2);  /* error message */\n    return 2;  /* return false, msg */\n  }\n  else\n    return lua_gettop(L) - (int)extra;  /* return all results */\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  lua_pushboolean(L, 1);  /* first result if no errors */\n  lua_insert(L, 1);  /* put it in place */\n  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);\n  return finishpcall(L, status, 0);\n}\n\n\n/*\n** Do a protected call with error handling. After 'lua_rotate', the\n** stack will have <f, err, true, f, [args...]>; so, the function passes\n** 2 to 'finishpcall' to skip the 2 first values when returning results.\n*/\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  int n = lua_gettop(L);\n  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */\n  lua_pushboolean(L, 1);  /* first result */\n  lua_pushvalue(L, 1);  /* function */\n  lua_rotate(L, 3, 2);  /* move them below function's arguments */\n  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);\n  return finishpcall(L, status, 2);\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_tolstring(L, 1, NULL);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"ipairs\", luaB_ipairs},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n#if defined(LUA_COMPAT_LOADSTRING)\n  {\"loadstring\", luaB_load},\n#endif\n  {\"next\", luaB_next},\n  {\"pairs\", luaB_pairs},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawlen\", luaB_rawlen},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"xpcall\", luaB_xpcall},\n  /* placeholders */\n  {\"_G\", NULL},\n  {\"_VERSION\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_base (lua_State *L) {\n  /* open lib into global table */\n  lua_pushglobaltable(L);\n  luaL_setfuncs(L, base_funcs, 0);\n  /* set global _G */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_G\");\n  /* set global _VERSION */\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setfield(L, -2, \"_VERSION\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lbitlib.c",
    "content": "/*\n** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $\n** Standard library for bitwise operations\n** See Copyright Notice in lua.h\n*/\n\n#define lbitlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if defined(LUA_COMPAT_BITLIB)\t\t/* { */\n\n\n#define pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define checkunsigned(L,i)\t((lua_Unsigned)luaL_checkinteger(L,i))\n\n\n/* number of bits to consider in a number */\n#if !defined(LUA_NBITS)\n#define LUA_NBITS\t32\n#endif\n\n\n/*\n** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must\n** be made in two parts to avoid problems when LUA_NBITS is equal to the\n** number of bits in a lua_Unsigned.)\n*/\n#define ALLONES\t\t(~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))\n\n\n/* macro to trim extra bits */\n#define trim(x)\t\t((x) & ALLONES)\n\n\n/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */\n#define mask(n)\t\t(~((ALLONES << 1) << ((n) - 1)))\n\n\n\nstatic lua_Unsigned andaux (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = ~(lua_Unsigned)0;\n  for (i = 1; i <= n; i++)\n    r &= checkunsigned(L, i);\n  return trim(r);\n}\n\n\nstatic int b_and (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_test (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  lua_pushboolean(L, r != 0);\n  return 1;\n}\n\n\nstatic int b_or (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r |= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_xor (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r ^= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_not (lua_State *L) {\n  lua_Unsigned r = ~checkunsigned(L, 1);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) {\n  if (i < 0) {  /* shift right? */\n    i = -i;\n    r = trim(r);\n    if (i >= LUA_NBITS) r = 0;\n    else r >>= i;\n  }\n  else {  /* shift left */\n    if (i >= LUA_NBITS) r = 0;\n    else r <<= i;\n    r = trim(r);\n  }\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_lshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_arshift (lua_State *L) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  lua_Integer i = luaL_checkinteger(L, 2);\n  if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1))))\n    return b_shift(L, r, -i);\n  else {  /* arithmetic shift for 'negative' number */\n    if (i >= LUA_NBITS) r = ALLONES;\n    else\n      r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i));  /* add signal bit */\n    pushunsigned(L, r);\n    return 1;\n  }\n}\n\n\nstatic int b_rot (lua_State *L, lua_Integer d) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  int i = d & (LUA_NBITS - 1);  /* i = d % NBITS */\n  r = trim(r);\n  if (i != 0)  /* avoid undefined shift of LUA_NBITS when i == 0 */\n    r = (r << i) | (r >> (LUA_NBITS - i));\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_lrot (lua_State *L) {\n  return b_rot(L, luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rrot (lua_State *L) {\n  return b_rot(L, -luaL_checkinteger(L, 2));\n}\n\n\n/*\n** get field and width arguments for field-manipulation functions,\n** checking whether they are valid.\n** ('luaL_error' called without 'return' to avoid later warnings about\n** 'width' being used uninitialized.)\n*/\nstatic int fieldargs (lua_State *L, int farg, int *width) {\n  lua_Integer f = luaL_checkinteger(L, farg);\n  lua_Integer w = luaL_optinteger(L, farg + 1, 1);\n  luaL_argcheck(L, 0 <= f, farg, \"field cannot be negative\");\n  luaL_argcheck(L, 0 < w, farg + 1, \"width must be positive\");\n  if (f + w > LUA_NBITS)\n    luaL_error(L, \"trying to access non-existent bits\");\n  *width = (int)w;\n  return (int)f;\n}\n\n\nstatic int b_extract (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  int f = fieldargs(L, 2, &w);\n  r = (r >> f) & mask(w);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_replace (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  lua_Unsigned v = trim(checkunsigned(L, 2));\n  int f = fieldargs(L, 3, &w);\n  lua_Unsigned m = mask(w);\n  r = (r & ~(m << f)) | ((v & m) << f);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic const luaL_Reg bitlib[] = {\n  {\"arshift\", b_arshift},\n  {\"band\", b_and},\n  {\"bnot\", b_not},\n  {\"bor\", b_or},\n  {\"bxor\", b_xor},\n  {\"btest\", b_test},\n  {\"extract\", b_extract},\n  {\"lrotate\", b_lrot},\n  {\"lshift\", b_lshift},\n  {\"replace\", b_replace},\n  {\"rrotate\", b_rrot},\n  {\"rshift\", b_rshift},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  luaL_newlib(L, bitlib);\n  return 1;\n}\n\n\n#else\t\t\t\t\t/* }{ */\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  return luaL_error(L, \"library 'bit32' has been deprecated\");\n}\n\n#endif\t\t\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.3/src/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <math.h>\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/* Maximum number of registers in a Lua function (must fit in 8 bits) */\n#define MAXREGS\t\t255\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\n/*\n** If expression is a numeric constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nstatic int tonumeral(expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a numeral */\n  switch (e->k) {\n    case VKINT:\n      if (v) setivalue(v, e->u.ival);\n      return 1;\n    case VKFLT:\n      if (v) setfltvalue(v, e->u.nval);\n      return 1;\n    default: return 0;\n  }\n}\n\n\n/*\n** Create a OP_LOADNIL instruction, but try to optimize: if the previous\n** instruction is also OP_LOADNIL and ranges are compatible, adjust\n** range of previous instruction instead of emitting a new one. (For\n** instance, 'local a; local b' will generate a single opcode.)\n*/\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  int l = from + n - 1;  /* last register to set nil */\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    previous = &fs->f->code[fs->pc-1];\n    if (GET_OPCODE(*previous) == OP_LOADNIL) {  /* previous is LOADNIL? */\n      int pfrom = GETARG_A(*previous);  /* get previous range */\n      int pl = pfrom + GETARG_B(*previous);\n      if ((pfrom <= from && from <= pl + 1) ||\n          (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */\n        if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */\n        if (pl > l) l = pl;  /* l = max(l, pl) */\n        SETARG_A(*previous, from);\n        SETARG_B(*previous, l - from);\n        return;\n      }\n    }  /* else go through */\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */\n}\n\n\n/*\n** Gets the destination address of a jump instruction. Used to traverse\n** a list of jumps.\n*/ \nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\n/*\n** Fix jump instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua)\n*/\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** Concatenate jump-list 'l2' into jump-list 'l1'\n*/\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;  /* nothing to concatenate? */\n  else if (*l1 == NO_JUMP)  /* no original list? */\n    *l1 = l2;  /* 'l1' points to 'l2' */\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);  /* last element links to 'l2' */\n  }\n}\n\n\n/*\n** Create a jump instruction and return its position, so its destination\n** can be fixed later (with 'fixjump'). If there are jumps to\n** this position (kept in 'jpc'), link them all together so that\n** 'patchlistaux' will fix all them directly to the final destination.\n*/\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;  /* no more jumps to here */\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\n/*\n** Code a 'return' instruction\n*/\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\n/*\n** Code a \"conditional jump\", that is, a test or comparison opcode\n** followed by a jump. Return jump position.\n*/\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\n/*\n** returns current 'pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\n/*\n** Returns the position of the instruction \"controlling\" a given\n** jump (that is, its condition), or the jump itself if it is\n** unconditional.\n*/\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** Patch destination register for a TESTSET instruction.\n** If instruction in position 'node' is not a TESTSET, return 0 (\"fails\").\n** Otherwise, if 'reg' is not 'NO_REG', set it as the destination\n** register. Otherwise, change instruction to a simple 'TEST' (produces\n** no register value)\n*/\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else {\n     /* no register to put value or register already has the value;\n        change instruction to simple test */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n  }\n  return 1;\n}\n\n\n/*\n** Traverse a list of tests ensuring no one produces a value\n*/\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\n/*\n** Traverse a list of tests, patching their destination address and\n** registers: tests producing values jump to 'vtarget' (and put their\n** values in 'reg'), other tests jump to 'dtarget'.\n*/\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\n/*\n** Ensure all pending jumps to current position are fixed (jumping\n** to current position with no values) and reset list of pending\n** jumps\n*/\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\n/*\n** Add elements in 'list' to list of pending jumps to \"here\"\n** (current position)\n*/\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);  /* mark \"here\" as a jump target */\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\n/*\n** Path all jumps in 'list' to jump to 'target'.\n** (The assert means that we cannot fix a jump to a forward address\n** because we only know addresses once code is generated.)\n*/\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)  /* 'target' is current position? */\n    luaK_patchtohere(fs, list);  /* add list to pending jumps */\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\n/*\n** Path all jumps in 'list' to close upvalues up to given 'level'\n** (The assertion checks that jumps either were closing nothing\n** or were closing higher levels, from inner blocks.)\n*/\nvoid luaK_patchclose (FuncState *fs, int list, int level) {\n  level++;  /* argument is +1 to reserve 0 as non-op */\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&\n                (GETARG_A(fs->f->code[list]) == 0 ||\n                 GETARG_A(fs->f->code[list]) >= level));\n    SETARG_A(fs->f->code[list], level);\n  }\n}\n\n\n/*\n** Emit instruction 'i', checking for array sizes and saving also its\n** line information. Return 'i' position.\n*/\nstatic int luaK_code (FuncState *fs, Instruction i) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* 'pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"opcodes\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"opcodes\");\n  f->lineinfo[fs->pc] = fs->ls->lastline;\n  return fs->pc++;\n}\n\n\n/*\n** Format and emit an 'iABC' instruction. (Assertions check consistency\n** of parameters versus opcode.)\n*/\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c));\n}\n\n\n/*\n** Format and emit an 'iABx' instruction.\n*/\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, bc));\n}\n\n\n/*\n** Emit an \"extra argument\" instruction (format 'iAx')\n*/\nstatic int codeextraarg (FuncState *fs, int a) {\n  lua_assert(a <= MAXARG_Ax);\n  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));\n}\n\n\n/*\n** Emit a \"load constant\" instruction, using either 'OP_LOADK'\n** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'\n** instruction with \"extra argument\".\n*/\nint luaK_codek (FuncState *fs, int reg, int k) {\n  if (k <= MAXARG_Bx)\n    return luaK_codeABx(fs, OP_LOADK, reg, k);\n  else {\n    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);\n    codeextraarg(fs, k);\n    return p;\n  }\n}\n\n\n/*\n** Check register-stack level, keeping track of its maximum size\n** in field 'maxstacksize'\n*/\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXREGS)\n      luaX_syntaxerror(fs->ls,\n        \"function or expression needs too many registers\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\n/*\n** Reserve 'n' registers in register stack\n*/\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\n/*\n** Free register 'reg', if it is neither a constant index nor\n** a local variable.\n)\n*/\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\n/*\n** Free register used by expression 'e' (if any)\n*/\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.info);\n}\n\n\n/*\n** Free registers used by expressions 'e1' and 'e2' (if any) in proper\n** order.\n*/\nstatic void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {\n  int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;\n  int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;\n  if (r1 > r2) {\n    freereg(fs, r1);\n    freereg(fs, r2);\n  }\n  else {\n    freereg(fs, r2);\n    freereg(fs, r1);\n  }\n}\n\n\n/*\n** Add constant 'v' to prototype's list of constants (field 'k').\n** Use scanner's table to cache position of constants in constant list\n** and try to reuse constants. Because some values should not be used\n** as keys (nil cannot be a key, integer keys can collapse with float\n** keys), the caller must provide a useful 'key' for indexing the cache.\n*/\nstatic int addk (FuncState *fs, TValue *key, TValue *v) {\n  lua_State *L = fs->ls->L;\n  Proto *f = fs->f;\n  TValue *idx = luaH_set(L, fs->ls->h, key);  /* index scanner table */\n  int k, oldsize;\n  if (ttisinteger(idx)) {  /* is there an index there? */\n    k = cast_int(ivalue(idx));\n    /* correct value? (warning: must distinguish floats from integers!) */\n    if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&\n                      luaV_rawequalobj(&f->k[k], v))\n      return k;  /* reuse index */\n  }\n  /* constant not found; create a new entry */\n  oldsize = f->sizek;\n  k = fs->nk;\n  /* numerical value does not need GC barrier;\n     table has no metatable, so it does not need to invalidate cache */\n  setivalue(idx, k);\n  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, \"constants\");\n  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n  setobj(L, &f->k[k], v);\n  fs->nk++;\n  luaC_barrier(L, f, v);\n  return k;\n}\n\n\n/*\n** Add a string to list of constants and return its index.\n*/\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->ls->L, &o, s);\n  return addk(fs, &o, &o);  /* use string itself as key */\n}\n\n\n/*\n** Add an integer to list of constants and return its index.\n** Integers use userdata as keys to avoid collision with floats with\n** same value; conversion to 'void*' is used only for hashing, so there\n** are no \"precision\" problems.\n*/\nint luaK_intK (FuncState *fs, lua_Integer n) {\n  TValue k, o;\n  setpvalue(&k, cast(void*, cast(size_t, n)));\n  setivalue(&o, n);\n  return addk(fs, &k, &o);\n}\n\n/*\n** Add a float to list of constants and return its index.\n*/\nstatic int luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setfltvalue(&o, r);\n  return addk(fs, &o, &o);  /* use number itself as key */\n}\n\n\n/*\n** Add a boolean to list of constants and return its index.\n*/\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add nil to list of constants and return its index.\n*/\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->ls->L, &k, fs->ls->h);\n  return addk(fs, &k, &v);\n}\n\n\n/*\n** Fix an expression to return the number of results 'nresults'.\n** Either 'e' is a multi-ret expression (function call or vararg)\n** or 'nresults' is LUA_MULTRET (as any expression can satisfy that).\n*/\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getinstruction(fs, e), nresults + 1);\n  }\n  else if (e->k == VVARARG) {\n    Instruction *pc = &getinstruction(fs, e);\n    SETARG_B(*pc, nresults + 1);\n    SETARG_A(*pc, fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n  else lua_assert(nresults == LUA_MULTRET);\n}\n\n\n/*\n** Fix an expression to return one result.\n** If expression is not a multi-ret expression (function call or\n** vararg), it already returns one result, so nothing needs to be done.\n** Function calls become VNONRELOC expressions (as its result comes\n** fixed in the base register of the call), while vararg expressions\n** become VRELOCABLE (as OP_VARARG puts its results where it wants).\n** (Calls are created returning one result, so that does not need\n** to be fixed.)\n*/\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    /* already returns 1 value */\n    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);\n    e->k = VNONRELOC;  /* result has fixed position */\n    e->u.info = GETARG_A(getinstruction(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getinstruction(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\n/*\n** Ensure that expression 'e' is not a variable.\n*/\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {  /* already in a register */\n      e->k = VNONRELOC;  /* becomes a non-relocatable value */\n      break;\n    }\n    case VUPVAL: {  /* move value to some (pending) register */\n      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      OpCode op;\n      freereg(fs, e->u.ind.idx);\n      if (e->u.ind.vt == VLOCAL) {  /* is 't' in a register? */\n        freereg(fs, e->u.ind.t);\n        op = OP_GETTABLE;\n      }\n      else {\n        lua_assert(e->u.ind.vt == VUPVAL);\n        op = OP_GETTABUP;  /* 't' is in an upvalue */\n      }\n      e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG: case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\n/*\n** Ensures expression value is in register 'reg' (and therefore\n** 'e' will become a non-relocatable expression).\n*/\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE: case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codek(fs, reg, e->u.info);\n      break;\n    }\n    case VKFLT: {\n      luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VKINT: {\n      luaK_codek(fs, reg, luaK_intK(fs, e->u.ival));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getinstruction(fs, e);\n      SETARG_A(*pc, reg);  /* instruction will put result in 'reg' */\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures expression value is in any register.\n*/\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {  /* no fixed register yet? */\n    luaK_reserveregs(fs, 1);  /* get a register */\n    discharge2reg(fs, e, fs->freereg-1);  /* put value there */\n  }\n}\n\n\nstatic int code_loadbool (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** or produce an inverted value\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in register 'reg'.\n** If expression has jumps, need to patch these jumps either to\n** its final position or to \"load\" instructions (for those tests\n** that do not produce values).\n*/\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)  /* expression itself is a test? */\n    luaK_concat(fs, &e->t, e->u.info);  /* put this jump in 't' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_loadbool(fs, reg, 0, 1);\n      p_t = code_loadbool(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in next available register.\n*/\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in some (any) register and return that register.\n*/\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {  /* expression already has a register? */\n    if (!hasjumps(e))  /* no jumps? */\n      return e->u.info;  /* result is already in a register */\n    if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.info);  /* put final result in it */\n      return e->u.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* otherwise, use next available register */\n  return e->u.info;\n}\n\n\n/*\n** Ensures final expression result is either in a register or in an\n** upvalue.\n*/\nvoid luaK_exp2anyregup (FuncState *fs, expdesc *e) {\n  if (e->k != VUPVAL || hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Ensures final expression result is either in a register or it is\n** a constant.\n*/\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\n/*\n** Ensures final expression result is in a valid R/K index\n** (that is, it is either in a register or in 'k' with an index\n** in the range of R/K indices).\n** Returns R/K index.\n*/  \nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {  /* move constants to 'k' */\n    case VTRUE: e->u.info = boolK(fs, 1); goto vk;\n    case VFALSE: e->u.info = boolK(fs, 0); goto vk;\n    case VNIL: e->u.info = nilK(fs); goto vk;\n    case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;\n    case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;\n    case VK:\n     vk:\n      e->k = VK;\n      if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */\n        return RKASK(e->u.info);\n      else break;\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Generate code to store result of expression 'ex' into variable 'var'.\n*/\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.info);  /* compute 'ex' into proper place */\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);\n      break;\n    }\n    case VINDEXED: {\n      OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);\n      break;\n    }\n    default: lua_assert(0);  /* invalid var kind to store */\n  }\n  freeexp(fs, ex);\n}\n\n\n/*\n** Emit SELF instruction (convert expression 'e' into 'e:key(e,').\n*/\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int ereg;\n  luaK_exp2anyreg(fs, e);\n  ereg = e->u.info;  /* register where 'e' was placed */\n  freeexp(fs, e);\n  e->u.info = fs->freereg;  /* base register for op_self */\n  e->k = VNONRELOC;  /* self expression has a fixed register */\n  luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */\n  luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n}\n\n\n/*\n** Negate condition 'e' (where 'e' is a comparison).\n*/\nstatic void negatecondition (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\n/*\n** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'\n** is true, code will jump if 'e' is true.) Return jump position.\n** Optimize when 'e' is 'not' something, inverting the condition\n** and removing the 'not'.\n*/\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getinstruction(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);\n}\n\n\n/*\n** Emit code to go through if 'e' is true, jump otherwise.\n*/\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {  /* condition? */\n      negatecondition(fs, e);  /* jump when it is false */\n      pc = e->u.info;  /* save jump position */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);  /* jump when false */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert new jump in false list */\n  luaK_patchtohere(fs, e->t);  /* true list jumps to here (to go through) */\n  e->t = NO_JUMP;\n}\n\n\n/*\n** Emit code to go through if 'e' is false, jump otherwise.\n*/\nvoid luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {\n      pc = e->u.info;  /* already jump if true */\n      break;\n    }\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);  /* jump if true */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert new jump in 't' list */\n  luaK_patchtohere(fs, e->f);  /* false list jumps to here (to go through) */\n  e->f = NO_JUMP;\n}\n\n\n/*\n** Code 'not e', doing constant folding.\n*/\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;  /* true == not nil == not false */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      e->k = VFALSE;  /* false == not \"x\" == not 0.5 == not 1 == not true */\n      break;\n    }\n    case VJMP: {\n      negatecondition(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: lua_assert(0);  /* cannot happen */\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);  /* values are useless when negated */\n  removevalues(fs, e->t);\n}\n\n\n/*\n** Create expression 't[k]'. 't' must have its final result already in a\n** register or upvalue.\n*/\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));\n  t->u.ind.t = t->u.info;  /* register or upvalue index */\n  t->u.ind.idx = luaK_exp2RK(fs, k);  /* R/K index for key */\n  t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL;\n  t->k = VINDEXED;\n}\n\n\n/*\n** Return false if folding can raise an error.\n** Bitwise operations need operands convertible to integers; division\n** operations cannot have 0 as divisor.\n*/\nstatic int validop (int op, TValue *v1, TValue *v2) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: {  /* conversion errors */\n      lua_Integer i;\n      return (tointeger(v1, &i) && tointeger(v2, &i));\n    }\n    case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD:  /* division by 0 */\n      return (nvalue(v2) != 0);\n    default: return 1;  /* everything else is valid */\n  }\n}\n\n\n/*\n** Try to \"constant-fold\" an operation; return 1 iff successful.\n** (In this case, 'e1' has the final result.)\n*/\nstatic int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) {\n  TValue v1, v2, res;\n  if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))\n    return 0;  /* non-numeric operands or not safe to fold */\n  luaO_arith(fs->ls->L, op, &v1, &v2, &res);  /* does operation */\n  if (ttisinteger(&res)) {\n    e1->k = VKINT;\n    e1->u.ival = ivalue(&res);\n  }\n  else {  /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */\n    lua_Number n = fltvalue(&res);\n    if (luai_numisnan(n) || n == 0)\n      return 0;\n    e1->k = VKFLT;\n    e1->u.nval = n;\n  }\n  return 1;\n}\n\n\n/*\n** Emit code for unary expressions that \"produce values\"\n** (everything but 'not').\n** Expression to produce final result will be encoded in 'e'.\n*/\nstatic void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {\n  int r = luaK_exp2anyreg(fs, e);  /* opcodes operate only on registers */\n  freeexp(fs, e);\n  e->u.info = luaK_codeABC(fs, op, 0, r, 0);  /* generate opcode */\n  e->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\"\n** (everything but logical operators 'and'/'or' and comparison\n** operators).\n** Expression to produce final result will be encoded in 'e1'.\n*/\nstatic void codebinexpval (FuncState *fs, OpCode op,\n                           expdesc *e1, expdesc *e2, int line) {\n  int rk1 = luaK_exp2RK(fs, e1);  /* both operands are \"RK\" */\n  int rk2 = luaK_exp2RK(fs, e2);\n  freeexps(fs, e1, e2);\n  e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2);  /* generate opcode */\n  e1->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for comparisons.\n** 'e1' was already put in R/K form by 'luaK_infix'.\n*/\nstatic void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {\n  int rk1 = (e1->k == VK) ? RKASK(e1->u.info)\n                          : check_exp(e1->k == VNONRELOC, e1->u.info);\n  int rk2 = luaK_exp2RK(fs, e2);\n  freeexps(fs, e1, e2);\n  switch (opr) {\n    case OPR_NE: {  /* '(a ~= b)' ==> 'not (a == b)' */\n      e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2);\n      break;\n    }\n    case OPR_GT: case OPR_GE: {\n      /* '(a > b)' ==> '(b < a)';  '(a >= b)' ==> '(b <= a)' */\n      OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk2, rk1);  /* invert operands */\n      break;\n    }\n    default: {  /* '==', '<', '<=' use their own opcodes */\n      OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk1, rk2);\n      break;\n    }\n  }\n  e1->k = VJMP;\n}\n\n\n/*\n** Aplly prefix operation 'op' to expression 'e'.\n*/\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {\n  static expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};  /* fake 2nd operand */\n  switch (op) {\n    case OPR_MINUS: case OPR_BNOT:\n      if (constfolding(fs, op + LUA_OPUNM, e, &ef))\n        break;\n      /* FALLTHROUGH */\n    case OPR_LEN:\n      codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);\n      break;\n    case OPR_NOT: codenot(fs, e); break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Process 1st operand 'v' of binary operation 'op' before reading\n** 2nd operand.\n*/\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);  /* go ahead only if 'v' is true */\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);  /* go ahead only if 'v' is false */\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the 'stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB:\n    case OPR_MUL: case OPR_DIV: case OPR_IDIV:\n    case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2RK(fs, v);\n      /* else keep numeral, which may be folded with 2nd operand */\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\n/*\n** Finalize code for binary operation, after reading 2nd operand.\n** For '(a .. b .. c)' (which is '(a .. (b .. c))', because\n** concatenation is right associative), merge second CONCAT into first\n** one.\n*/\nvoid luaK_posfix (FuncState *fs, BinOpr op,\n                  expdesc *e1, expdesc *e2, int line) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE &&\n          GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getinstruction(fs, e2), e1->u.info);\n        e1->k = VRELOCABLE; e1->u.info = e2->u.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codebinexpval(fs, OP_CONCAT, e1, e2, line);\n      }\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_IDIV: case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!constfolding(fs, op + LUA_OPADD, e1, e2))\n        codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);\n      break;\n    }\n    case OPR_EQ: case OPR_LT: case OPR_LE:\n    case OPR_NE: case OPR_GT: case OPR_GE: {\n      codecomp(fs, op, e1, e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Change line information associated with current position.\n*/\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\n/*\n** Emit a SETLIST instruction.\n** 'base' is register that keeps table;\n** 'nelems' is #table plus those to be stored now;\n** 'tostore' is number of values (in registers 'base + 1',...) to add to\n** table (or LUA_MULTRET to add up to stack top).\n*/\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else if (c <= MAXARG_Ax) {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    codeextraarg(fs, c);\n  }\n  else\n    luaX_syntaxerror(fs->ls, \"constructor too long\");\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums  (ORDER OP)\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,\n  OPR_DIV,\n  OPR_IDIV,\n  OPR_BAND, OPR_BOR, OPR_BXOR,\n  OPR_SHL, OPR_SHR,\n  OPR_CONCAT,\n  OPR_EQ, OPR_LT, OPR_LE,\n  OPR_NE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n/* get (pointer to) instruction of given 'expdesc' */\n#define getinstruction(fs,e)\t((fs)->f->code[(e)->u.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\n#define luaK_jumpto(fs,t)\tluaK_patchlist(fs, luaK_jump(fs), t)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,\n                            expdesc *v2, int line);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lcorolib.c",
    "content": "/*\n** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $\n** Coroutine Library\n** See Copyright Notice in lua.h\n*/\n\n#define lcorolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic lua_State *getco (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"thread expected\");\n  return co;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status;\n  if (!lua_checkstack(co, narg)) {\n    lua_pushliteral(L, \"too many arguments to resume\");\n    return -1;  /* error flag */\n  }\n  if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {\n    lua_pushliteral(L, \"cannot resume dead coroutine\");\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, L, narg);\n  if (status == LUA_OK || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1)) {\n      lua_pop(co, nres);  /* remove results anyway */\n      lua_pushliteral(L, \"too many results to resume\");\n      return -1;  /* error flag */\n    }\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = getco(L);\n  int r;\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + 'resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_type(L, -1) == LUA_TSTRING) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    return lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  NL = lua_newthread(L);\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = getco(L);\n  if (L == co) lua_pushliteral(L, \"running\");\n  else {\n    switch (lua_status(co)) {\n      case LUA_YIELD:\n        lua_pushliteral(L, \"suspended\");\n        break;\n      case LUA_OK: {\n        lua_Debug ar;\n        if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n          lua_pushliteral(L, \"normal\");  /* it is running */\n        else if (lua_gettop(co) == 0)\n            lua_pushliteral(L, \"dead\");\n        else\n          lua_pushliteral(L, \"suspended\");  /* initial state */\n        break;\n      }\n      default:  /* some error occurred */\n        lua_pushliteral(L, \"dead\");\n        break;\n    }\n  }\n  return 1;\n}\n\n\nstatic int luaB_yieldable (lua_State *L) {\n  lua_pushboolean(L, lua_isyieldable(L));\n  return 1;\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  int ismain = lua_pushthread(L);\n  lua_pushboolean(L, ismain);\n  return 2;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {\"isyieldable\", luaB_yieldable},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_coroutine (lua_State *L) {\n  luaL_newlib(L, co_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lctype.c",
    "content": "/*\n** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lctype_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lctype.h\"\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\nLUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {\n  0x00,  /* EOZ */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 0. */\n  0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 1. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\t/* 2. */\n  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,\t/* 3. */\n  0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 4. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 5. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 6. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 7. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 8. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 9. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* a. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* b. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* c. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* d. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* e. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* f. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n};\n\n#endif\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.3/src/lctype.h",
    "content": "/*\n** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lctype_h\n#define lctype_h\n\n#include \"lua.h\"\n\n\n/*\n** WARNING: the functions defined here do not necessarily correspond\n** to the similar functions in the standard C ctype.h. They are\n** optimized for the specific needs of Lua\n*/\n\n#if !defined(LUA_USE_CTYPE)\n\n#if 'A' == 65 && '0' == 48\n/* ASCII case: can use its own tables; faster and fixed */\n#define LUA_USE_CTYPE\t0\n#else\n/* must use standard C ctype */\n#define LUA_USE_CTYPE\t1\n#endif\n\n#endif\n\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n#include \"llimits.h\"\n\n\n#define ALPHABIT\t0\n#define DIGITBIT\t1\n#define PRINTBIT\t2\n#define SPACEBIT\t3\n#define XDIGITBIT\t4\n\n\n#define MASK(B)\t\t(1 << (B))\n\n\n/*\n** add 1 to char to allow index -1 (EOZ)\n*/\n#define testprop(c,p)\t(luai_ctype_[(c)+1] & (p))\n\n/*\n** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'\n*/\n#define lislalpha(c)\ttestprop(c, MASK(ALPHABIT))\n#define lislalnum(c)\ttestprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))\n#define lisdigit(c)\ttestprop(c, MASK(DIGITBIT))\n#define lisspace(c)\ttestprop(c, MASK(SPACEBIT))\n#define lisprint(c)\ttestprop(c, MASK(PRINTBIT))\n#define lisxdigit(c)\ttestprop(c, MASK(XDIGITBIT))\n\n/*\n** this 'ltolower' only works for alphabetic characters\n*/\n#define ltolower(c)\t((c) | ('A' ^ 'a'))\n\n\n/* two more entries for 0 and -1 (EOZ) */\nLUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];\n\n\n#else\t\t\t/* }{ */\n\n/*\n** use standard C ctypes\n*/\n\n#include <ctype.h>\n\n\n#define lislalpha(c)\t(isalpha(c) || (c) == '_')\n#define lislalnum(c)\t(isalnum(c) || (c) == '_')\n#define lisdigit(c)\t(isdigit(c))\n#define lisspace(c)\t(isspace(c))\n#define lisprint(c)\t(isprint(c))\n#define lisxdigit(c)\t(isxdigit(c))\n\n#define ltolower(c)\t(tolower(c))\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** The hook table at registry[&HOOKKEY] maps threads to their current\n** hook function. (We only need the unique address of 'HOOKKEY'.)\n*/\nstatic const int HOOKKEY = 0;\n\n\n/*\n** If L1 != L, L1 can be in any state, and therefore there are no\n** guarantees about its stack space; any push in L1 must be\n** checked.\n*/\nstatic void checkstack (lua_State *L, lua_State *L1, int n) {\n  if (L != L1 && !lua_checkstack(L1, n))\n    luaL_error(L, \"stack overflow\");\n}\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;  /* return 1st argument */\n}\n\n\nstatic int db_getuservalue (lua_State *L) {\n  if (lua_type(L, 1) != LUA_TUSERDATA)\n    lua_pushnil(L);\n  else\n    lua_getuservalue(L, 1);\n  return 1;\n}\n\n\nstatic int db_setuservalue (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TUSERDATA);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_setuservalue(L, 1);\n  return 1;\n}\n\n\n/*\n** Auxiliary function used by several library functions: check for\n** an optional thread as function's first argument and set 'arg' with\n** 1 if this argument is present (so that functions can skip it to\n** access their other arguments)\n*/\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;  /* function will operate over current thread */\n  }\n}\n\n\n/*\n** Variations of 'lua_settable', used by 'db_getinfo' to put results\n** from 'lua_getinfo' into result table. Key is always a string;\n** value can be a string, an int, or a boolean.\n*/\nstatic void settabss (lua_State *L, const char *k, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsi (lua_State *L, const char *k, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsb (lua_State *L, const char *k, int v) {\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, k);\n}\n\n\n/*\n** In function 'db_getinfo', the call to 'lua_getinfo' may push\n** results on the stack; later it creates the result table to put\n** these objects. Function 'treatstackoption' puts the result from\n** 'lua_getinfo' on top of the result table so that it can call\n** 'lua_setfield'.\n*/\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1)\n    lua_rotate(L, -2, 1);  /* exchange object and table */\n  else\n    lua_xmove(L1, L, 1);  /* move object to the \"main\" stack */\n  lua_setfield(L, -2, fname);  /* put object into table */\n}\n\n\n/*\n** Calls 'lua_getinfo' and collects all results in a new table.\n** L1 needs stack space for an optional input (function) plus\n** two optional outputs (function and line table) from function\n** 'lua_getinfo'.\n*/\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnStu\");\n  checkstack(L, L1, 3);\n  if (lua_isfunction(L, arg + 1)) {  /* info about a function? */\n    options = lua_pushfstring(L, \">%s\", options);  /* add '>' to 'options' */\n    lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */\n    lua_xmove(L, L1, 1);\n  }\n  else {  /* stack level */\n    if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_newtable(L);  /* table to collect results */\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u')) {\n    settabsi(L, \"nups\", ar.nups);\n    settabsi(L, \"nparams\", ar.nparams);\n    settabsb(L, \"isvararg\", ar.isvararg);\n  }\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 't'))\n    settabsb(L, \"istailcall\", ar.istailcall);\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n\n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */\n  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\n    lua_pushvalue(L, arg + 1);  /* push function */\n    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\n    return 1;  /* return only name (there is no value) */\n  }\n  else {  /* stack-level argument */\n    int level = (int)luaL_checkinteger(L, arg + 1);\n    if (!lua_getstack(L1, level, &ar))  /* out of range? */\n      return luaL_argerror(L, arg+1, \"level out of range\");\n    checkstack(L, L1, 1);\n    name = lua_getlocal(L1, &ar, nvar);\n    if (name) {\n      lua_xmove(L1, L, 1);  /* move local value */\n      lua_pushstring(L, name);  /* push name */\n      lua_rotate(L, -2, 1);  /* re-order */\n      return 2;\n    }\n    else {\n      lua_pushnil(L);  /* no name (nor value) */\n      return 1;\n    }\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  const char *name;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  int level = (int)luaL_checkinteger(L, arg + 1);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);\n  if (!lua_getstack(L1, level, &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  checkstack(L, L1, 1);\n  lua_xmove(L, L1, 1);\n  name = lua_setlocal(L1, &ar, nvar);\n  if (name == NULL)\n    lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */\n  lua_pushstring(L, name);\n  return 1;\n}\n\n\n/*\n** get (if 'get' is true) or set an upvalue from a closure\n*/\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */\n  luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));  /* no-op if get is false */\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n/*\n** Check whether a given upvalue from a given closure exists and\n** returns its index\n*/\nstatic int checkupval (lua_State *L, int argf, int argnup) {\n  int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */\n  luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */\n  luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup,\n                   \"invalid upvalue index\");\n  return nup;\n}\n\n\nstatic int db_upvalueid (lua_State *L) {\n  int n = checkupval(L, 1, 2);\n  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\n  return 1;\n}\n\n\nstatic int db_upvaluejoin (lua_State *L) {\n  int n1 = checkupval(L, 1, 2);\n  int n2 = checkupval(L, 3, 4);\n  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, \"Lua function expected\");\n  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, \"Lua function expected\");\n  lua_upvaluejoin(L, 1, n1, 3, n2);\n  return 0;\n}\n\n\n/*\n** Call hook function registered at hook table for the current\n** thread (if there is one)\n*/\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail call\"};\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n  lua_pushthread(L);\n  if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */\n    lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);  /* push current line */\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);  /* call hook function */\n  }\n}\n\n\n/*\n** Convert a string mask (for 'sethook') into a bit mask\n*/\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\n/*\n** Convert a bit mask (for 'gethook') into a string mask\n*/\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = (int)luaL_optinteger(L, arg + 3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {\n    lua_createtable(L, 0, 2);  /* create a hook table */\n    lua_pushvalue(L, -1);\n    lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */\n    lua_pushstring(L, \"k\");\n    lua_setfield(L, -2, \"__mode\");  /** hooktable.__mode = \"k\" */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */\n  }\n  checkstack(L, L1, 1);\n  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */\n  lua_pushvalue(L, arg + 1);  /* value (hook function) */\n  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */\n  lua_sethook(L1, func, mask, count);\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook == NULL)  /* no hook? */\n    lua_pushnil(L);\n  else if (hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {  /* hook table must exist */\n    lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n    checkstack(L, L1, 1);\n    lua_pushthread(L1); lua_xmove(L1, L, 1);\n    lua_rawget(L, -2);   /* 1st result = hooktable[L1] */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */\n  lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    lua_writestringerror(\"%s\", \"lua_debug> \");\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0))\n      lua_writestringerror(\"%s\\n\", lua_tostring(L, -1));\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\nstatic int db_traceback (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg + 1);\n  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\n    lua_pushvalue(L, arg + 1);  /* return it untouched */\n  else {\n    int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);\n    luaL_traceback(L, L1, msg, level);\n  }\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getuservalue\", db_getuservalue},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"upvaluejoin\", db_upvaluejoin},\n  {\"upvalueid\", db_upvalueid},\n  {\"setuservalue\", db_setuservalue},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_traceback},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_debug (lua_State *L) {\n  luaL_newlib(L, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.120 2016/03/31 19:01:21 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n#define noLuaClosure(f)\t\t((f) == NULL || (f)->c.tt == LUA_TCCL)\n\n\n/* Active Lua function (given call info) */\n#define ci_func(ci)\t\t(clLvalue((ci)->func))\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);\n\n\nstatic int currentpc (CallInfo *ci) {\n  lua_assert(isLua(ci));\n  return pcRel(ci->u.l.savedpc, ci_func(ci)->p);\n}\n\n\nstatic int currentline (CallInfo *ci) {\n  return getfuncline(ci_func(ci)->p, currentpc(ci));\n}\n\n\n/*\n** If function yielded, its 'func' can be in the 'extra' field. The\n** next function restores 'func' to its correct value for debugging\n** purposes. (It exchanges 'func' and 'extra'; so, when called again,\n** after debugging, it also \"re-restores\" ** 'func' to its altered value.\n*/\nstatic void swapextra (lua_State *L) {\n  if (L->status == LUA_YIELD) {\n    CallInfo *ci = L->ci;  /* get function that yielded */\n    StkId temp = ci->func;  /* exchange its 'func' and 'extra' values */\n    ci->func = restorestack(L, ci->extra);\n    ci->extra = savestack(L, temp);\n  }\n}\n\n\n/*\n** This function can be called asynchronously (e.g. during a signal).\n** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by\n** 'resethookcount') are for debug only, and it is no problem if they\n** get arbitrary values (causes at most one wrong hook call). 'hookmask'\n** is an atomic value. We assume that pointers are atomic too (e.g., gcc\n** ensures that for all platforms where it runs). Moreover, 'hook' is\n** always checked before being called (see 'luaD_hook').\n*/\nLUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  if (isLua(L->ci))\n    L->oldpc = L->ci->u.l.savedpc;\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  if (level < 0) return 0;  /* invalid (negative) level */\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)\n    level--;\n  if (level == 0 && ci != &L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = ci;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic const char *upvalname (Proto *p, int uv) {\n  TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);\n  if (s == NULL) return \"?\";\n  else return getstr(s);\n}\n\n\nstatic const char *findvararg (CallInfo *ci, int n, StkId *pos) {\n  int nparams = clLvalue(ci->func)->p->numparams;\n  if (n >= cast_int(ci->u.l.base - ci->func) - nparams)\n    return NULL;  /* no such vararg */\n  else {\n    *pos = ci->func + nparams + n;\n    return \"(*vararg)\";  /* generic name for any vararg */\n  }\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n,\n                              StkId *pos) {\n  const char *name = NULL;\n  StkId base;\n  if (isLua(ci)) {\n    if (n < 0)  /* access to vararg values? */\n      return findvararg(ci, -n, pos);\n    else {\n      base = ci->u.l.base;\n      name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));\n    }\n  }\n  else\n    base = ci->func + 1;\n  if (name == NULL) {  /* no 'standard' name? */\n    StkId limit = (ci == L->ci) ? L->top : ci->next->func;\n    if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      name = \"(*temporary)\";  /* generic name for any valid slot */\n    else\n      return NULL;  /* no name */\n  }\n  *pos = base + (n - 1);\n  return name;\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  if (ar == NULL) {  /* information about non-active function? */\n    if (!isLfunction(L->top - 1))  /* not a Lua function? */\n      name = NULL;\n    else  /* consider live variables at function start (parameters) */\n      name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);\n  }\n  else {  /* active function; get information through 'ar' */\n    StkId pos = NULL;  /* to avoid warnings */\n    name = findlocal(L, ar->i_ci, n, &pos);\n    if (name) {\n      setobj2s(L, L->top, pos);\n      api_incr_top(L);\n    }\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  StkId pos = NULL;  /* to avoid warnings */\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  name = findlocal(L, ar->i_ci, n, &pos);\n  if (name) {\n    setobjs2s(L, pos, L->top - 1);\n    L->top--;  /* pop value */\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (noLuaClosure(cl)) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    Proto *p = cl->l.p;\n    ar->source = p->source ? getstr(p->source) : \"=?\";\n    ar->linedefined = p->linedefined;\n    ar->lastlinedefined = p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (noLuaClosure(f)) {\n    setnilvalue(L->top);\n    api_incr_top(L);\n  }\n  else {\n    int i;\n    TValue v;\n    int *lineinfo = f->l.p->lineinfo;\n    Table *t = luaH_new(L);  /* new table to store active lines */\n    sethvalue(L, L->top, t);  /* push it on stack */\n    api_incr_top(L);\n    setbvalue(&v, 1);  /* boolean 'true' to be the value of all indices */\n    for (i = 0; i < f->l.p->sizelineinfo; i++)  /* for all lines with code */\n      luaH_setint(L, t, lineinfo[i], &v);  /* table[line] = true */\n  }\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                       Closure *f, CallInfo *ci) {\n  int status = 1;\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = (f == NULL) ? 0 : f->c.nupvalues;\n        if (noLuaClosure(f)) {\n          ar->isvararg = 1;\n          ar->nparams = 0;\n        }\n        else {\n          ar->isvararg = f->l.p->is_vararg;\n          ar->nparams = f->l.p->numparams;\n        }\n        break;\n      }\n      case 't': {\n        ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;\n        break;\n      }\n      case 'n': {\n        /* calling function is a known Lua function? */\n        if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous))\n          ar->namewhat = getfuncname(L, ci->previous, &ar->name);\n        else\n          ar->namewhat = NULL;\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *cl;\n  CallInfo *ci;\n  StkId func;\n  lua_lock(L);\n  swapextra(L);\n  if (*what == '>') {\n    ci = NULL;\n    func = L->top - 1;\n    api_check(L, ttisfunction(func), \"function expected\");\n    what++;  /* skip the '>' */\n    L->top--;  /* pop function */\n  }\n  else {\n    ci = ar->i_ci;\n    func = ci->func;\n    lua_assert(ttisfunction(ci->func));\n  }\n  cl = ttisclosure(func) ? clvalue(func) : NULL;\n  status = auxgetinfo(L, what, ar, cl, ci);\n  if (strchr(what, 'f')) {\n    setobjs2s(L, L->top, func);\n    api_incr_top(L);\n  }\n  swapextra(L);  /* correct before option 'L', which can raise a mem. error */\n  if (strchr(what, 'L'))\n    collectvalidlines(L, cl);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution\n** =======================================================\n*/\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name);\n\n\n/*\n** find a \"name\" for the RK value 'c'\n*/\nstatic void kname (Proto *p, int pc, int c, const char **name) {\n  if (ISK(c)) {  /* is 'c' a constant? */\n    TValue *kvalue = &p->k[INDEXK(c)];\n    if (ttisstring(kvalue)) {  /* literal constant? */\n      *name = svalue(kvalue);  /* it is its own name */\n      return;\n    }\n    /* else no reasonable name found */\n  }\n  else {  /* 'c' is a register */\n    const char *what = getobjname(p, pc, c, name); /* search for 'c' */\n    if (what && *what == 'c') {  /* found a constant name? */\n      return;  /* 'name' already filled */\n    }\n    /* else no reasonable name found */\n  }\n  *name = \"?\";  /* no reasonable name found */\n}\n\n\nstatic int filterpc (int pc, int jmptarget) {\n  if (pc < jmptarget)  /* is code conditional (inside a jump)? */\n    return -1;  /* cannot know who sets that register */\n  else return pc;  /* current position sets that register */\n}\n\n\n/*\n** try to find last instruction before 'lastpc' that modified register 'reg'\n*/\nstatic int findsetreg (Proto *p, int lastpc, int reg) {\n  int pc;\n  int setreg = -1;  /* keep last instruction that changed 'reg' */\n  int jmptarget = 0;  /* any code before this address is conditional */\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    switch (op) {\n      case OP_LOADNIL: {\n        int b = GETARG_B(i);\n        if (a <= reg && reg <= a + b)  /* set registers from 'a' to 'a+b' */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_TFORCALL: {\n        if (reg >= a + 2)  /* affect all regs above its base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (reg >= a)  /* affect all registers above base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_JMP: {\n        int b = GETARG_sBx(i);\n        int dest = pc + 1 + b;\n        /* jump is forward and do not skip 'lastpc'? */\n        if (pc < dest && dest <= lastpc) {\n          if (dest > jmptarget)\n            jmptarget = dest;  /* update 'jmptarget' */\n        }\n        break;\n      }\n      default:\n        if (testAMode(op) && reg == a)  /* any instruction that set A */\n          setreg = filterpc(pc, jmptarget);\n        break;\n    }\n  }\n  return setreg;\n}\n\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name) {\n  int pc;\n  *name = luaF_getlocalname(p, reg + 1, lastpc);\n  if (*name)  /* is a local? */\n    return \"local\";\n  /* else try symbolic execution */\n  pc = findsetreg(p, lastpc, reg);\n  if (pc != -1) {  /* could find instruction? */\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    switch (op) {\n      case OP_MOVE: {\n        int b = GETARG_B(i);  /* move from 'b' to 'a' */\n        if (b < GETARG_A(i))\n          return getobjname(p, pc, b, name);  /* get name for 'b' */\n        break;\n      }\n      case OP_GETTABUP:\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        int t = GETARG_B(i);  /* table index */\n        const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */\n                         ? luaF_getlocalname(p, t + 1, pc)\n                         : upvalname(p, t);\n        kname(p, pc, k, name);\n        return (vn && strcmp(vn, LUA_ENV) == 0) ? \"global\" : \"field\";\n      }\n      case OP_GETUPVAL: {\n        *name = upvalname(p, GETARG_B(i));\n        return \"upvalue\";\n      }\n      case OP_LOADK:\n      case OP_LOADKX: {\n        int b = (op == OP_LOADK) ? GETARG_Bx(i)\n                                 : GETARG_Ax(p->code[pc + 1]);\n        if (ttisstring(&p->k[b])) {\n          *name = svalue(&p->k[b]);\n          return \"constant\";\n        }\n        break;\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, pc, k, name);\n        return \"method\";\n      }\n      default: break;  /* go through to return NULL */\n    }\n  }\n  return NULL;  /* could not find reasonable name */\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  TMS tm = (TMS)0;  /* to avoid warnings */\n  Proto *p = ci_func(ci)->p;  /* calling function */\n  int pc = currentpc(ci);  /* calling instruction index */\n  Instruction i = p->code[pc];  /* calling instruction */\n  if (ci->callstatus & CIST_HOOKED) {  /* was it called inside a hook? */\n    *name = \"?\";\n    return \"hook\";\n  }\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:  /* get function name */\n      return getobjname(p, pc, GETARG_A(i), name);\n    case OP_TFORCALL: {  /* for iterator */\n      *name = \"for iterator\";\n       return \"for iterator\";\n    }\n    /* all other instructions can call only through metamethods */\n    case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:\n      tm = TM_INDEX;\n      break;\n    case OP_SETTABUP: case OP_SETTABLE:\n      tm = TM_NEWINDEX;\n      break;\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:\n    case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:\n    case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {\n      int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD);  /* ORDER OP */\n      tm = cast(TMS, offset + cast_int(TM_ADD));  /* ORDER TM */\n      break;\n    }\n    case OP_UNM: tm = TM_UNM; break;\n    case OP_BNOT: tm = TM_BNOT; break;\n    case OP_LEN: tm = TM_LEN; break;\n    case OP_CONCAT: tm = TM_CONCAT; break;\n    case OP_EQ: tm = TM_EQ; break;\n    case OP_LT: tm = TM_LT; break;\n    case OP_LE: tm = TM_LE; break;\n    default: lua_assert(0);  /* other instructions cannot call a function */\n  }\n  *name = getstr(G(L)->tmname[tm]);\n  return \"metamethod\";\n}\n\n/* }====================================================== */\n\n\n\n/*\n** The subtraction of two potentially unrelated pointers is\n** not ISO C, but it should not crash a program; the subsequent\n** checks are ISO C and ensure a correct result.\n*/\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  ptrdiff_t i = o - ci->u.l.base;\n  return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);\n}\n\n\n/*\n** Checks whether value 'o' came from an upvalue. (That can only happen\n** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on\n** upvalues.)\n*/\nstatic const char *getupvalname (CallInfo *ci, const TValue *o,\n                                 const char **name) {\n  LClosure *c = ci_func(ci);\n  int i;\n  for (i = 0; i < c->nupvalues; i++) {\n    if (c->upvals[i]->v == o) {\n      *name = upvalname(c->p, i);\n      return \"upvalue\";\n    }\n  }\n  return NULL;\n}\n\n\nstatic const char *varinfo (lua_State *L, const TValue *o) {\n  const char *name = NULL;  /* to avoid warnings */\n  CallInfo *ci = L->ci;\n  const char *kind = NULL;\n  if (isLua(ci)) {\n    kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */\n    if (!kind && isinstack(ci, o))  /* no? try a register */\n      kind = getobjname(ci_func(ci)->p, currentpc(ci),\n                        cast_int(o - ci->u.l.base), &name);\n  }\n  return (kind) ? luaO_pushfstring(L, \" (%s '%s')\", kind, name) : \"\";\n}\n\n\nl_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *t = luaT_objtypename(L, o);\n  luaG_runerror(L, \"attempt to %s a %s value%s\", op, t, varinfo(L, o));\n}\n\n\nl_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {\n  if (ttisstring(p1) || cvt2str(p1)) p1 = p2;\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nl_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                         const TValue *p2, const char *msg) {\n  lua_Number temp;\n  if (!tonumber(p1, &temp))  /* first operand is wrong? */\n    p2 = p1;  /* now second is wrong */\n  luaG_typeerror(L, p2, msg);\n}\n\n\n/*\n** Error when both values are convertible to numbers, but not to integers\n*/\nl_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {\n  lua_Integer temp;\n  if (!tointeger(p1, &temp))\n    p2 = p1;\n  luaG_runerror(L, \"number%s has no integer representation\", varinfo(L, p2));\n}\n\n\nl_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_objtypename(L, p1);\n  const char *t2 = luaT_objtypename(L, p2);\n  if (strcmp(t1, t2) == 0)\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n}\n\n\n/* add src:line information to 'msg' */\nconst char *luaG_addinfo (lua_State *L, const char *msg, TString *src,\n                                        int line) {\n  char buff[LUA_IDSIZE];\n  if (src)\n    luaO_chunkid(buff, getstr(src), LUA_IDSIZE);\n  else {  /* no source available; use \"?\" instead */\n    buff[0] = '?'; buff[1] = '\\0';\n  }\n  return luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n}\n\n\nl_noret luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    L->top++;  /* assume EXTRA_STACK */\n    luaD_callnoyield(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nl_noret luaG_runerror (lua_State *L, const char *fmt, ...) {\n  CallInfo *ci = L->ci;\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);  /* format message */\n  va_end(argp);\n  if (isLua(ci))  /* if Lua function, add source:line information */\n    luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));\n  luaG_errormsg(L);\n}\n\n\nvoid luaG_traceexec (lua_State *L) {\n  CallInfo *ci = L->ci;\n  lu_byte mask = L->hookmask;\n  int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));\n  if (counthook)\n    resethookcount(L);  /* reset count */\n  else if (!(mask & LUA_MASKLINE))\n    return;  /* no line hook and count != 0; nothing to be done */\n  if (ci->callstatus & CIST_HOOKYIELD) {  /* called hook last time? */\n    ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */\n    return;  /* do not call hook again (VM yielded, so it did not move) */\n  }\n  if (counthook)\n    luaD_hook(L, LUA_HOOKCOUNT, -1);  /* call count hook */\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(ci)->p;\n    int npc = pcRel(ci->u.l.savedpc, p);\n    int newline = getfuncline(p, npc);\n    if (npc == 0 ||  /* call linehook when enter a new function, */\n        ci->u.l.savedpc <= L->oldpc ||  /* when jump back (loop), or when */\n        newline != getfuncline(p, pcRel(L->oldpc, p)))  /* enter a new line */\n      luaD_hook(L, LUA_HOOKLINE, newline);  /* call line hook */\n  }\n  L->oldpc = ci->u.l.savedpc;\n  if (L->status == LUA_YIELD) {  /* did hook yield? */\n    if (counthook)\n      L->hookcount = 1;  /* undo decrement to zero */\n    ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */\n    ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */\n    ci->func = L->top - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getfuncline(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : -1)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,\n                                                const char *opname);\nLUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,\n                                                  const TValue *p2);\nLUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2,\n                                                 const char *msg);\nLUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,\n                                                  TString *src, int line);\nLUAI_FUNC l_noret luaG_errormsg (lua_State *L);\nLUAI_FUNC void luaG_traceexec (lua_State *L);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.151 2015/12/16 16:40:07 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n#define errorstatus(s)\t((s) > LUA_YIELD)\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n/*\n** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By\n** default, Lua handles errors with exceptions when compiling as\n** C++ code, with _longjmp/_setjmp when asked to use them, and with\n** longjmp/setjmp otherwise.\n*/\n#if !defined(LUAI_THROW)\t\t\t\t/* { */\n\n#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)\t/* { */\n\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\t\tthrow(c)\n#define LUAI_TRY(L,c,a) \\\n\ttry { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\t\tint  /* dummy variable */\n\n#elif defined(LUA_USE_POSIX)\t\t\t\t/* }{ */\n\n/* in POSIX, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#else\t\t\t\t\t\t\t/* }{ */\n\n/* ISO C handling with long jumps */\n#define LUAI_THROW(L,c)\t\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#endif\t\t\t\t\t\t\t/* } */\n\n#endif\t\t\t\t\t\t\t/* } */\n\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nstatic void seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {  /* memory error? */\n      setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    default: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nl_noret luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {  /* thread has an error handler? */\n    L->errorJmp->status = errcode;  /* set status */\n    LUAI_THROW(L, L->errorJmp);  /* jump to it */\n  }\n  else {  /* thread has no error handler */\n    global_State *g = G(L);\n    L->status = cast_byte(errcode);  /* mark it as dead */\n    if (g->mainthread->errorJmp) {  /* main thread has a handler? */\n      setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */\n      luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */\n    }\n    else {  /* no handler at all; abort */\n      if (g->panic) {  /* panic function? */\n        seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */\n        if (L->ci->top < L->top)\n          L->ci->top = L->top;  /* pushing msg. can break this invariant */\n        lua_unlock(L);\n        g->panic(L);  /* call panic function (last chance to jump out) */\n      }\n      abort();\n    }\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  unsigned short oldnCcalls = L->nCcalls;\n  struct lua_longjmp lj;\n  lj.status = LUA_OK;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  L->nCcalls = oldnCcalls;\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\n/*\n** {==================================================================\n** Stack reallocation\n** ===================================================================\n*/\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  UpVal *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->u.open.next)\n    up->v = (up->v - oldstack) + L->stack;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n    if (isLua(ci))\n      ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;\n  }\n}\n\n\n/* some space for error handling */\n#define ERRORSTACKSIZE\t(LUAI_MAXSTACK + 200)\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int lim = L->stacksize;\n  lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);\n  luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);\n  for (; lim < newsize; lim++)\n    setnilvalue(L->stack + lim); /* erase new segment */\n  L->stacksize = newsize;\n  L->stack_last = L->stack + newsize - EXTRA_STACK;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  int size = L->stacksize;\n  if (size > LUAI_MAXSTACK)  /* error after extra size? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;\n    int newsize = 2 * size;\n    if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;\n    if (newsize < needed) newsize = needed;\n    if (newsize > LUAI_MAXSTACK) {  /* stack overflow? */\n      luaD_reallocstack(L, ERRORSTACKSIZE);\n      luaG_runerror(L, \"stack overflow\");\n    }\n    else\n      luaD_reallocstack(L, newsize);\n  }\n}\n\n\nstatic int stackinuse (lua_State *L) {\n  CallInfo *ci;\n  StkId lim = L->top;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    lua_assert(ci->top <= L->stack_last);\n    if (lim < ci->top) lim = ci->top;\n  }\n  return cast_int(lim - L->stack) + 1;  /* part of stack in use */\n}\n\n\nvoid luaD_shrinkstack (lua_State *L) {\n  int inuse = stackinuse(L);\n  int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;\n  if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK;\n  if (L->stacksize > LUAI_MAXSTACK)  /* was handling stack overflow? */\n    luaE_freeCI(L);  /* free all CIs (list grew because of an error) */\n  else\n    luaE_shrinkCI(L);  /* shrink list */\n  if (inuse <= LUAI_MAXSTACK &&  /* not handling stack overflow? */\n      goodsize < L->stacksize)  /* trying to shrink? */\n    luaD_reallocstack(L, goodsize);  /* shrink it */\n  else\n    condmovestack(L,,);  /* don't change stack (change only for debugging) */\n}\n\n\nvoid luaD_inctop (lua_State *L) {\n  luaD_checkstack(L, 1);\n  L->top++;\n}\n\n/* }================================================================== */\n\n\n/*\n** Call a hook for the given event. Make sure there is a hook to be\n** called. (Both 'L->hook' and 'L->hookmask', which triggers this\n** function, can be changed asynchronously by signals.)\n*/\nvoid luaD_hook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {  /* make sure there is a hook */\n    CallInfo *ci = L->ci;\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    ar.i_ci = ci;\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    ci->top = L->top + LUA_MINSTACK;\n    lua_assert(ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    ci->callstatus |= CIST_HOOKED;\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n    ci->callstatus &= ~CIST_HOOKED;\n  }\n}\n\n\nstatic void callhook (lua_State *L, CallInfo *ci) {\n  int hook = LUA_HOOKCALL;\n  ci->u.l.savedpc++;  /* hooks assume 'pc' is already incremented */\n  if (isLua(ci->previous) &&\n      GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {\n    ci->callstatus |= CIST_TAIL;\n    hook = LUA_HOOKTAILCALL;\n  }\n  luaD_hook(L, hook, -1);\n  ci->u.l.savedpc--;  /* correct 'pc' */\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n  StkId base, fixed;\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i = 0; i < nfixargs && i < actual; i++) {\n    setobjs2s(L, L->top++, fixed + i);\n    setnilvalue(fixed + i);  /* erase original copy (for GC) */\n  }\n  for (; i < nfixargs; i++)\n    setnilvalue(L->top++);  /* complete missing arguments */\n  return base;\n}\n\n\n/*\n** Check whether __call metafield of 'func' is a function. If so, put\n** it in stack below original 'func' so that 'luaD_precall' can call\n** it. Raise an error if __call metafield is not a function.\n*/\nstatic void tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at 'func' */\n  for (p = L->top; p > func; p--)\n    setobjs2s(L, p, p-1);\n  L->top++;  /* slot ensured by caller */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n}\n\n\n\n#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))\n\n\n/* macro to check stack size, preserving 'p' */\n#define checkstackp(L,n,p)  \\\n  luaD_checkstackaux(L, n, \\\n    ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \\\n    luaC_checkGC(L),  /* stack grow uses memory */ \\\n    p = restorestack(L, t__))  /* 'pos' part: restore 'p' */\n\n\n/*\n** Prepares a function call: checks the stack, creates a new CallInfo\n** entry, fills in the relevant information, calls hook if needed.\n** If function is a C function, does the call, too. (Otherwise, leave\n** the execution ('luaV_execute') to the caller, to allow stackless\n** calls.) Returns true iff function has been executed (C function).\n*/\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  lua_CFunction f;\n  CallInfo *ci;\n  switch (ttype(func)) {\n    case LUA_TCCL:  /* C closure */\n      f = clCvalue(func)->f;\n      goto Cfunc;\n    case LUA_TLCF:  /* light C function */\n      f = fvalue(func);\n     Cfunc: {\n      int n;  /* number of returns */\n      checkstackp(L, LUA_MINSTACK, func);  /* ensure minimum stack size */\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->top = L->top + LUA_MINSTACK;\n      lua_assert(ci->top <= L->stack_last);\n      ci->callstatus = 0;\n      if (L->hookmask & LUA_MASKCALL)\n        luaD_hook(L, LUA_HOOKCALL, -1);\n      lua_unlock(L);\n      n = (*f)(L);  /* do the actual call */\n      lua_lock(L);\n      api_checknelems(L, n);\n      luaD_poscall(L, ci, L->top - n, n);\n      return 1;\n    }\n    case LUA_TLCL: {  /* Lua function: prepare its call */\n      StkId base;\n      Proto *p = clLvalue(func)->p;\n      int n = cast_int(L->top - func) - 1;  /* number of real arguments */\n      int fsize = p->maxstacksize;  /* frame size */\n      checkstackp(L, fsize, func);\n      if (p->is_vararg != 1) {  /* do not use vararg? */\n        for (; n < p->numparams; n++)\n          setnilvalue(L->top++);  /* complete missing arguments */\n        base = func + 1;\n      }\n      else\n        base = adjust_varargs(L, p, n);\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->u.l.base = base;\n      L->top = ci->top = base + fsize;\n      lua_assert(ci->top <= L->stack_last);\n      ci->u.l.savedpc = p->code;  /* starting point */\n      ci->callstatus = CIST_LUA;\n      if (L->hookmask & LUA_MASKCALL)\n        callhook(L, ci);\n      return 0;\n    }\n    default: {  /* not a function */\n      checkstackp(L, 1, func);  /* ensure space for metamethod */\n      tryfuncTM(L, func);  /* try to get '__call' metamethod */\n      return luaD_precall(L, func, nresults);  /* now it must be a function */\n    }\n  }\n}\n\n\n/*\n** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.\n** Handle most typical cases (zero results for commands, one result for\n** expressions, multiple results for tail calls/single parameters)\n** separated.\n*/\nstatic int moveresults (lua_State *L, const TValue *firstResult, StkId res,\n                                      int nres, int wanted) {\n  switch (wanted) {  /* handle typical cases separately */\n    case 0: break;  /* nothing to move */\n    case 1: {  /* one result needed */\n      if (nres == 0)   /* no results? */\n        firstResult = luaO_nilobject;  /* adjust with nil */\n      setobjs2s(L, res, firstResult);  /* move it to proper place */\n      break;\n    }\n    case LUA_MULTRET: {\n      int i;\n      for (i = 0; i < nres; i++)  /* move all results to correct place */\n        setobjs2s(L, res + i, firstResult + i);\n      L->top = res + nres;\n      return 0;  /* wanted == LUA_MULTRET */\n    }\n    default: {\n      int i;\n      if (wanted <= nres) {  /* enough results? */\n        for (i = 0; i < wanted; i++)  /* move wanted results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n      }\n      else {  /* not enough results; use all of them plus nils */\n        for (i = 0; i < nres; i++)  /* move all results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n        for (; i < wanted; i++)  /* complete wanted number of results */\n          setnilvalue(res + i);\n      }\n      break;\n    }\n  }\n  L->top = res + wanted;  /* top points after the last result */\n  return 1;\n}\n\n\n/*\n** Finishes a function call: calls hook if necessary, removes CallInfo,\n** moves current number of results to proper place; returns 0 iff call\n** wanted multiple (variable number of) results.\n*/\nint luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {\n  StkId res;\n  int wanted = ci->nresults;\n  if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {\n    if (L->hookmask & LUA_MASKRET) {\n      ptrdiff_t fr = savestack(L, firstResult);  /* hook may change stack */\n      luaD_hook(L, LUA_HOOKRET, -1);\n      firstResult = restorestack(L, fr);\n    }\n    L->oldpc = ci->previous->u.l.savedpc;  /* 'oldpc' for caller function */\n  }\n  res = ci->func;  /* res == final position of 1st result */\n  L->ci = ci->previous;  /* back to caller */\n  /* move results to proper place */\n  return moveresults(L, firstResult, res, nres, wanted);\n}\n\n\n/*\n** Check appropriate error for stack overflow (\"regular\" overflow or\n** overflow while handling stack overflow). If 'nCalls' is larger than\n** LUAI_MAXCCALLS (which means it is handling a \"regular\" overflow) but\n** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to\n** allow overflow handling to work)\n*/\nstatic void stackerror (lua_State *L) {\n  if (L->nCcalls == LUAI_MAXCCALLS)\n    luaG_runerror(L, \"C stack overflow\");\n  else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n    luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/\nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS)\n    stackerror(L);\n  if (!luaD_precall(L, func, nResults))  /* is a Lua function? */\n    luaV_execute(L);  /* call it */\n  L->nCcalls--;\n}\n\n\n/*\n** Similar to 'luaD_call', but does not allow yields during the call\n*/\nvoid luaD_callnoyield (lua_State *L, StkId func, int nResults) {\n  L->nny++;\n  luaD_call(L, func, nResults);\n  L->nny--;\n}\n\n\n/*\n** Completes the execution of an interrupted C function, calling its\n** continuation function.\n*/\nstatic void finishCcall (lua_State *L, int status) {\n  CallInfo *ci = L->ci;\n  int n;\n  /* must have a continuation and must be able to call it */\n  lua_assert(ci->u.c.k != NULL && L->nny == 0);\n  /* error status can only happen in a protected call */\n  lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD);\n  if (ci->callstatus & CIST_YPCALL) {  /* was inside a pcall? */\n    ci->callstatus &= ~CIST_YPCALL;  /* finish 'lua_pcall' */\n    L->errfunc = ci->u.c.old_errfunc;\n  }\n  /* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already\n     handled */\n  adjustresults(L, ci->nresults);\n  /* call continuation function */\n  lua_unlock(L);\n  n = (*ci->u.c.k)(L, status, ci->u.c.ctx);\n  lua_lock(L);\n  api_checknelems(L, n);\n  /* finish 'luaD_precall' */\n  luaD_poscall(L, ci, L->top - n, n);\n}\n\n\n/*\n** Executes \"full continuation\" (everything in the stack) of a\n** previously interrupted coroutine until the stack is empty (or another\n** interruption long-jumps out of the loop). If the coroutine is\n** recovering from an error, 'ud' points to the error status, which must\n** be passed to the first continuation function (otherwise the default\n** status is LUA_YIELD).\n*/\nstatic void unroll (lua_State *L, void *ud) {\n  if (ud != NULL)  /* error status? */\n    finishCcall(L, *(int *)ud);  /* finish 'lua_pcallk' callee */\n  while (L->ci != &L->base_ci) {  /* something in the stack */\n    if (!isLua(L->ci))  /* C function? */\n      finishCcall(L, LUA_YIELD);  /* complete its execution */\n    else {  /* Lua function */\n      luaV_finishOp(L);  /* finish interrupted instruction */\n      luaV_execute(L);  /* execute down to higher C 'boundary' */\n    }\n  }\n}\n\n\n/*\n** Try to find a suspended protected call (a \"recover point\") for the\n** given thread.\n*/\nstatic CallInfo *findpcall (lua_State *L) {\n  CallInfo *ci;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {  /* search for a pcall */\n    if (ci->callstatus & CIST_YPCALL)\n      return ci;\n  }\n  return NULL;  /* no pending pcall */\n}\n\n\n/*\n** Recovers from an error in a coroutine. Finds a recover point (if\n** there is one) and completes the execution of the interrupted\n** 'luaD_pcall'. If there is no recover point, returns zero.\n*/\nstatic int recover (lua_State *L, int status) {\n  StkId oldtop;\n  CallInfo *ci = findpcall(L);\n  if (ci == NULL) return 0;  /* no recovery point */\n  /* \"finish\" luaD_pcall */\n  oldtop = restorestack(L, ci->extra);\n  luaF_close(L, oldtop);\n  seterrorobj(L, status, oldtop);\n  L->ci = ci;\n  L->allowhook = getoah(ci->callstatus);  /* restore original 'allowhook' */\n  L->nny = 0;  /* should be zero to be yieldable */\n  luaD_shrinkstack(L);\n  L->errfunc = ci->u.c.old_errfunc;\n  return 1;  /* continue running the coroutine */\n}\n\n\n/*\n** signal an error in the call to 'resume', not in the execution of the\n** coroutine itself. (Such errors should not be handled by any coroutine\n** error handler and should not kill the coroutine.)\n*/\nstatic l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {\n  L->top = firstArg;  /* remove args from the stack */\n  setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */\n  api_incr_top(L);\n  luaD_throw(L, -1);  /* jump back to 'lua_resume' */\n}\n\n\n/*\n** Do the work for 'lua_resume' in protected mode. Most of the work\n** depends on the status of the coroutine: initial state, suspended\n** inside a hook, or regularly suspended (optionally with a continuation\n** function), plus erroneous cases: non-suspended coroutine or dead\n** coroutine.\n*/\nstatic void resume (lua_State *L, void *ud) {\n  int nCcalls = L->nCcalls;\n  int n = *(cast(int*, ud));  /* number of arguments */\n  StkId firstArg = L->top - n;  /* first argument */\n  CallInfo *ci = L->ci;\n  if (nCcalls >= LUAI_MAXCCALLS)\n    resume_error(L, \"C stack overflow\", firstArg);\n  if (L->status == LUA_OK) {  /* may be starting a coroutine */\n    if (ci != &L->base_ci)  /* not in base level? */\n      resume_error(L, \"cannot resume non-suspended coroutine\", firstArg);\n    /* coroutine is in base level; start running it */\n    if (!luaD_precall(L, firstArg - 1, LUA_MULTRET))  /* Lua function? */\n      luaV_execute(L);  /* call it */\n  }\n  else if (L->status != LUA_YIELD)\n    resume_error(L, \"cannot resume dead coroutine\", firstArg);\n  else {  /* resuming from previous yield */\n    L->status = LUA_OK;  /* mark that it is running (again) */\n    ci->func = restorestack(L, ci->extra);\n    if (isLua(ci))  /* yielded inside a hook? */\n      luaV_execute(L);  /* just continue running Lua code */\n    else {  /* 'common' yield */\n      if (ci->u.c.k != NULL) {  /* does it have a continuation function? */\n        lua_unlock(L);\n        n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */\n        lua_lock(L);\n        api_checknelems(L, n);\n        firstArg = L->top - n;  /* yield results come from continuation */\n      }\n      luaD_poscall(L, ci, firstArg, n);  /* finish 'luaD_precall' */\n    }\n    unroll(L, NULL);  /* run continuation */\n  }\n  lua_assert(nCcalls == L->nCcalls);\n}\n\n\nLUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {\n  int status;\n  unsigned short oldnny = L->nny;  /* save \"number of non-yieldable\" calls */\n  lua_lock(L);\n  luai_userstateresume(L, nargs);\n  L->nCcalls = (from) ? from->nCcalls + 1 : 1;\n  L->nny = 0;  /* allow yields */\n  api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);\n  status = luaD_rawrunprotected(L, resume, &nargs);\n  if (status == -1)  /* error calling 'lua_resume'? */\n    status = LUA_ERRRUN;\n  else {  /* continue running after recoverable errors */\n    while (errorstatus(status) && recover(L, status)) {\n      /* unroll continuation */\n      status = luaD_rawrunprotected(L, unroll, &status);\n    }\n    if (errorstatus(status)) {  /* unrecoverable error? */\n      L->status = cast_byte(status);  /* mark thread as 'dead' */\n      seterrorobj(L, status, L->top);  /* push error message */\n      L->ci->top = L->top;\n    }\n    else lua_assert(status == L->status);  /* normal end or yield */\n  }\n  L->nny = oldnny;  /* restore 'nny' */\n  L->nCcalls--;\n  lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_isyieldable (lua_State *L) {\n  return (L->nny == 0);\n}\n\n\nLUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,\n                        lua_KFunction k) {\n  CallInfo *ci = L->ci;\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  api_checknelems(L, nresults);\n  if (L->nny > 0) {\n    if (L != G(L)->mainthread)\n      luaG_runerror(L, \"attempt to yield across a C-call boundary\");\n    else\n      luaG_runerror(L, \"attempt to yield from outside a coroutine\");\n  }\n  L->status = LUA_YIELD;\n  ci->extra = savestack(L, ci->func);  /* save current 'func' */\n  if (isLua(ci)) {  /* inside a hook? */\n    api_check(L, k == NULL, \"hooks cannot continue after yielding\");\n  }\n  else {\n    if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */\n      ci->u.c.ctx = ctx;  /* save context */\n    ci->func = L->top - nresults - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n  lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */\n  lua_unlock(L);\n  return 0;  /* return to 'luaD_hook' */\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  CallInfo *old_ci = L->ci;\n  lu_byte old_allowhooks = L->allowhook;\n  unsigned short old_nny = L->nny;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != LUA_OK) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close possible pending closures */\n    seterrorobj(L, status, oldtop);\n    L->ci = old_ci;\n    L->allowhook = old_allowhooks;\n    L->nny = old_nny;\n    luaD_shrinkstack(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to 'f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* dynamic structure used by the scanner */\n  Dyndata dyd;  /* dynamic structures used by the parser */\n  const char *mode;\n  const char *name;\n};\n\n\nstatic void checkmode (lua_State *L, const char *mode, const char *x) {\n  if (mode && strchr(mode, x[0]) == NULL) {\n    luaO_pushfstring(L,\n       \"attempt to load a %s chunk (mode is '%s')\", x, mode);\n    luaD_throw(L, LUA_ERRSYNTAX);\n  }\n}\n\n\nstatic void f_parser (lua_State *L, void *ud) {\n  LClosure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = zgetc(p->z);  /* read first character */\n  if (c == LUA_SIGNATURE[0]) {\n    checkmode(L, p->mode, \"binary\");\n    cl = luaU_undump(L, p->z, p->name);\n  }\n  else {\n    checkmode(L, p->mode, \"text\");\n    cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);\n  }\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luaF_initupvals(L, cl);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                        const char *mode) {\n  struct SParser p;\n  int status;\n  L->nny++;  /* cannot yield during parsing */\n  p.z = z; p.name = name; p.mode = mode;\n  p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;\n  p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;\n  p.dyd.label.arr = NULL; p.dyd.label.size = 0;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);\n  luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);\n  luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);\n  L->nny--;\n  return status;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n/*\n** Macro to check stack size and grow stack if needed.  Parameters\n** 'pre'/'pos' allow the macro to preserve a pointer into the\n** stack across reallocations, doing the work only when needed.\n** 'condmovestack' is used in heavy tests to force a stack reallocation\n** at every check.\n*/\n#define luaD_checkstackaux(L,n,pre,pos)  \\\n\tif (L->stack_last - L->top <= (n)) \\\n\t  { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }\n\n/* In general, 'pre'/'pos' are empty (nothing to save) */\n#define luaD_checkstack(L,n)\tluaD_checkstackaux(L,n,(void)0,(void)0)\n\n\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n\n/* type of protected functions, to be ran by 'runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                                  const char *mode);\nLUAI_FUNC void luaD_hook (lua_State *L, int event, int line);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,\n                                          int nres);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\nLUAI_FUNC void luaD_shrinkstack (lua_State *L);\nLUAI_FUNC void luaD_inctop (lua_State *L);\n\nLUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\n\ntypedef struct {\n  lua_State *L;\n  lua_Writer writer;\n  void *data;\n  int strip;\n  int status;\n} DumpState;\n\n\n/*\n** All high-level dumps go through DumpVector; you can change it to\n** change the endianness of the result\n*/\n#define DumpVector(v,n,D)\tDumpBlock(v,(n)*sizeof((v)[0]),D)\n\n#define DumpLiteral(s,D)\tDumpBlock(s, sizeof(s) - sizeof(char), D)\n\n\nstatic void DumpBlock (const void *b, size_t size, DumpState *D) {\n  if (D->status == 0 && size > 0) {\n    lua_unlock(D->L);\n    D->status = (*D->writer)(D->L, b, size, D->data);\n    lua_lock(D->L);\n  }\n}\n\n\n#define DumpVar(x,D)\t\tDumpVector(&x,1,D)\n\n\nstatic void DumpByte (int y, DumpState *D) {\n  lu_byte x = (lu_byte)y;\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInt (int x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpNumber (lua_Number x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInteger (lua_Integer x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpString (const TString *s, DumpState *D) {\n  if (s == NULL)\n    DumpByte(0, D);\n  else {\n    size_t size = tsslen(s) + 1;  /* include trailing '\\0' */\n    const char *str = getstr(s);\n    if (size < 0xFF)\n      DumpByte(cast_int(size), D);\n    else {\n      DumpByte(0xFF, D);\n      DumpVar(size, D);\n    }\n    DumpVector(str, size - 1, D);  /* no need to save '\\0' */\n  }\n}\n\n\nstatic void DumpCode (const Proto *f, DumpState *D) {\n  DumpInt(f->sizecode, D);\n  DumpVector(f->code, f->sizecode, D);\n}\n\n\nstatic void DumpFunction(const Proto *f, TString *psource, DumpState *D);\n\nstatic void DumpConstants (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizek;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    const TValue *o = &f->k[i];\n    DumpByte(ttype(o), D);\n    switch (ttype(o)) {\n    case LUA_TNIL:\n      break;\n    case LUA_TBOOLEAN:\n      DumpByte(bvalue(o), D);\n      break;\n    case LUA_TNUMFLT:\n      DumpNumber(fltvalue(o), D);\n      break;\n    case LUA_TNUMINT:\n      DumpInteger(ivalue(o), D);\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      DumpString(tsvalue(o), D);\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void DumpProtos (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizep;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpFunction(f->p[i], f->source, D);\n}\n\n\nstatic void DumpUpvalues (const Proto *f, DumpState *D) {\n  int i, n = f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpByte(f->upvalues[i].instack, D);\n    DumpByte(f->upvalues[i].idx, D);\n  }\n}\n\n\nstatic void DumpDebug (const Proto *f, DumpState *D) {\n  int i, n;\n  n = (D->strip) ? 0 : f->sizelineinfo;\n  DumpInt(n, D);\n  DumpVector(f->lineinfo, n, D);\n  n = (D->strip) ? 0 : f->sizelocvars;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpString(f->locvars[i].varname, D);\n    DumpInt(f->locvars[i].startpc, D);\n    DumpInt(f->locvars[i].endpc, D);\n  }\n  n = (D->strip) ? 0 : f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpString(f->upvalues[i].name, D);\n}\n\n\nstatic void DumpFunction (const Proto *f, TString *psource, DumpState *D) {\n  if (D->strip || f->source == psource)\n    DumpString(NULL, D);  /* no debug info or same source as its parent */\n  else\n    DumpString(f->source, D);\n  DumpInt(f->linedefined, D);\n  DumpInt(f->lastlinedefined, D);\n  DumpByte(f->numparams, D);\n  DumpByte(f->is_vararg, D);\n  DumpByte(f->maxstacksize, D);\n  DumpCode(f, D);\n  DumpConstants(f, D);\n  DumpUpvalues(f, D);\n  DumpProtos(f, D);\n  DumpDebug(f, D);\n}\n\n\nstatic void DumpHeader (DumpState *D) {\n  DumpLiteral(LUA_SIGNATURE, D);\n  DumpByte(LUAC_VERSION, D);\n  DumpByte(LUAC_FORMAT, D);\n  DumpLiteral(LUAC_DATA, D);\n  DumpByte(sizeof(int), D);\n  DumpByte(sizeof(size_t), D);\n  DumpByte(sizeof(Instruction), D);\n  DumpByte(sizeof(lua_Integer), D);\n  DumpByte(sizeof(lua_Number), D);\n  DumpInteger(LUAC_INT, D);\n  DumpNumber(LUAC_NUM, D);\n}\n\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,\n              int strip) {\n  DumpState D;\n  D.L = L;\n  D.writer = w;\n  D.data = data;\n  D.strip = strip;\n  D.status = 0;\n  DumpHeader(&D);\n  DumpByte(f->sizeupvalues, &D);\n  DumpFunction(f, NULL, &D);\n  return D.status;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nCClosure *luaF_newCclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));\n  CClosure *c = gco2ccl(o);\n  c->nupvalues = cast_byte(n);\n  return c;\n}\n\n\nLClosure *luaF_newLclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));\n  LClosure *c = gco2lcl(o);\n  c->p = NULL;\n  c->nupvalues = cast_byte(n);\n  while (n--) c->upvals[n] = NULL;\n  return c;\n}\n\n/*\n** fill a closure with new closed upvalues\n*/\nvoid luaF_initupvals (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = luaM_new(L, UpVal);\n    uv->refcount = 1;\n    uv->v = &uv->u.value;  /* make it closed */\n    setnilvalue(uv->v);\n    cl->upvals[i] = uv;\n  }\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  UpVal **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  lua_assert(isintwups(L) || L->openupval == NULL);\n  while (*pp != NULL && (p = *pp)->v >= level) {\n    lua_assert(upisopen(p));\n    if (p->v == level)  /* found a corresponding upvalue? */\n      return p;  /* return it */\n    pp = &p->u.open.next;\n  }\n  /* not found: create a new upvalue */\n  uv = luaM_new(L, UpVal);\n  uv->refcount = 0;\n  uv->u.open.next = *pp;  /* link it to list of open upvalues */\n  uv->u.open.touched = 1;\n  *pp = uv;\n  uv->v = level;  /* current value lives in the stack */\n  if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */\n    L->twups = G(L)->twups;  /* link it to the list */\n    G(L)->twups = L;\n  }\n  return uv;\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  while (L->openupval != NULL && (uv = L->openupval)->v >= level) {\n    lua_assert(upisopen(uv));\n    L->openupval = uv->u.open.next;  /* remove from 'open' list */\n    if (uv->refcount == 0)  /* no references? */\n      luaM_free(L, uv);  /* free upvalue */\n    else {\n      setobj(L, &uv->u.value, uv->v);  /* move value to upvalue slot */\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_upvalbarrier(L, uv);\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));\n  Proto *f = gco2p(o);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->cache = NULL;\n  f->sizecode = 0;\n  f->lineinfo = NULL;\n  f->sizelineinfo = 0;\n  f->upvalues = NULL;\n  f->sizeupvalues = 0;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->locvars = NULL;\n  f->sizelocvars = 0;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode);\n  luaM_freearray(L, f->p, f->sizep);\n  luaM_freearray(L, f->k, f->sizek);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo);\n  luaM_freearray(L, f->locvars, f->sizelocvars);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues);\n  luaM_free(L, f);\n}\n\n\n/*\n** Look for n-th local variable at line 'line' in function 'func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\n/* test whether thread is in 'twups' list */\n#define isintwups(L)\t(L->twups != L)\n\n\n/*\n** maximum number of upvalues in a closure (both C and Lua). (Value\n** must fit in a VM register.)\n*/\n#define MAXUPVAL\t255\n\n\n/*\n** Upvalues for Lua closures\n*/\nstruct UpVal {\n  TValue *v;  /* points to stack or to its own value */\n  lu_mem refcount;  /* reference counter */\n  union {\n    struct {  /* (when open) */\n      UpVal *next;  /* linked list */\n      int touched;  /* mark to avoid cycles with dead threads */\n    } open;\n    TValue value;  /* the value (when closed) */\n  } u;\n};\n\n#define upisopen(up)\t((up)->v != &(up)->u.value)\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);\nLUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);\nLUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.212 2016/03/31 19:02:03 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n/*\n** internal state for collector while inside the atomic phase. The\n** collector should never be in this state while running regular code.\n*/\n#define GCSinsideatomic\t\t(GCSpause + 1)\n\n/*\n** cost of sweeping one element (the size of a small object divided\n** by some adjust for the sweep speed)\n*/\n#define GCSWEEPCOST\t((sizeof(TString) + 4) / 4)\n\n/* maximum number of elements to sweep in each single step */\n#define GCSWEEPMAX\t(cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))\n\n/* cost of calling one finalizer */\n#define GCFINALIZECOST\tGCSWEEPCOST\n\n\n/*\n** macro to adjust 'stepmul': 'stepmul' is actually used like\n** 'stepmul / STEPMULADJ' (value chosen by tests)\n*/\n#define STEPMULADJ\t\t200\n\n\n/*\n** macro to adjust 'pause': 'pause' is actually used like\n** 'pause / PAUSEADJ' (value chosen by tests)\n*/\n#define PAUSEADJ\t\t100\n\n\n/*\n** 'makewhite' erases all color bits then sets only the current white\n** bit\n*/\n#define maskcolors\t(~(bitmask(BLACKBIT) | WHITEBITS))\n#define makewhite(g,x)\t\\\n (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))\n\n#define white2gray(x)\tresetbits(x->marked, WHITEBITS)\n#define black2gray(x)\tresetbit(x->marked, BLACKBIT)\n\n\n#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))\n\n#define checkdeadkey(n)\tlua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))\n\n\n#define checkconsistency(obj)  \\\n  lua_longassert(!iscollectable(obj) || righttt(obj))\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t)\t{ if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }\n\n/*\n** mark an object that can be NULL (either because it is really optional,\n** or it was stripped as debug info, or inside an uncompleted structure)\n*/\n#define markobjectN(g,t)\t{ if (t) markobject(g,t); }\n\nstatic void reallymarkobject (global_State *g, GCObject *o);\n\n\n/*\n** {======================================================\n** Generic functions\n** =======================================================\n*/\n\n\n/*\n** one after last element in a hash array\n*/\n#define gnodelast(h)\tgnode(h, cast(size_t, sizenode(h)))\n\n\n/*\n** link collectable object 'o' into list pointed by 'p'\n*/\n#define linkgclist(o,p)\t((o)->gclist = (p), (p) = obj2gco(o))\n\n\n/*\n** If key is not marked, mark its entry as dead. This allows key to be\n** collected, but keeps its entry in the table.  A dead node is needed\n** when Lua looks up for a key (it may be part of a chain) and when\n** traversing a weak table (key might be removed from the table during\n** traversal). Other places never manipulate dead keys, because its\n** associated nil value is enough to signal that the entry is logically\n** empty.\n*/\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (valiswhite(gkey(n)))\n    setdeadvalue(wgkey(n));  /* unused and unmarked key; remove it */\n}\n\n\n/*\n** tells whether a key or value can be cleared from a weak\n** table. Non-collectable objects are never removed from weak\n** tables. Strings behave as 'values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for objects\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (global_State *g, const TValue *o) {\n  if (!iscollectable(o)) return 0;\n  else if (ttisstring(o)) {\n    markobject(g, tsvalue(o));  /* strings are 'values', so are never weak */\n    return 0;\n  }\n  else return iswhite(gcvalue(o));\n}\n\n\n/*\n** barrier that moves collector forward, that is, mark the white object\n** being pointed by a black object. (If in sweep phase, clear the black\n** object to white [sweep it] to avoid other barrier calls for this\n** same object.)\n*/\nvoid luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  if (keepinvariant(g))  /* must keep invariant? */\n    reallymarkobject(g, v);  /* restore invariant */\n  else {  /* sweep phase */\n    lua_assert(issweepphase(g));\n    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */\n  }\n}\n\n\n/*\n** barrier that moves collector backward, that is, mark the black object\n** pointing to a white object as gray again.\n*/\nvoid luaC_barrierback_ (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  lua_assert(isblack(t) && !isdead(g, t));\n  black2gray(t);  /* make table gray (again) */\n  linkgclist(t, g->grayagain);\n}\n\n\n/*\n** barrier for assignments to closed upvalues. Because upvalues are\n** shared among closures, it is impossible to know the color of all\n** closures pointing to it. So, we assume that the object being assigned\n** must be marked.\n*/\nvoid luaC_upvalbarrier_ (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = gcvalue(uv->v);\n  lua_assert(!upisopen(uv));  /* ensured by macro luaC_upvalbarrier */\n  if (keepinvariant(g))\n    markobject(g, o);\n}\n\n\nvoid luaC_fix (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(g->allgc == o);  /* object must be 1st in 'allgc' list! */\n  white2gray(o);  /* they will be gray forever */\n  g->allgc = o->next;  /* remove object from 'allgc' list */\n  o->next = g->fixedgc;  /* link it to 'fixedgc' list */\n  g->fixedgc = o;\n}\n\n\n/*\n** create a new collectable object (with given type and size) and link\n** it to 'allgc' list.\n*/\nGCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {\n  global_State *g = G(L);\n  GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));\n  o->marked = luaC_white(g);\n  o->tt = tt;\n  o->next = g->allgc;\n  g->allgc = o;\n  return o;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Mark functions\n** =======================================================\n*/\n\n\n/*\n** mark an object. Userdata, strings, and closed upvalues are visited\n** and turned black here. Other objects are marked gray and added\n** to appropriate list to be visited (and turned black) later. (Open\n** upvalues are already linked in 'headuv' list.)\n*/\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n reentry:\n  white2gray(o);\n  switch (o->tt) {\n    case LUA_TSHRSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->shrlen);\n      break;\n    }\n    case LUA_TLNGSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      TValue uvalue;\n      markobjectN(g, gco2u(o)->metatable);  /* mark its metatable */\n      gray2black(o);\n      g->GCmemtrav += sizeudata(gco2u(o));\n      getuservalue(g->mainthread, gco2u(o), &uvalue);\n      if (valiswhite(&uvalue)) {  /* markvalue(g, &uvalue); */\n        o = gcvalue(&uvalue);\n        goto reentry;\n      }\n      break;\n    }\n    case LUA_TLCL: {\n      linkgclist(gco2lcl(o), g->gray);\n      break;\n    }\n    case LUA_TCCL: {\n      linkgclist(gco2ccl(o), g->gray);\n      break;\n    }\n    case LUA_TTABLE: {\n      linkgclist(gco2t(o), g->gray);\n      break;\n    }\n    case LUA_TTHREAD: {\n      linkgclist(gco2th(o), g->gray);\n      break;\n    }\n    case LUA_TPROTO: {\n      linkgclist(gco2p(o), g->gray);\n      break;\n    }\n    default: lua_assert(0); break;\n  }\n}\n\n\n/*\n** mark metamethods for basic types\n*/\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i < LUA_NUMTAGS; i++)\n    markobjectN(g, g->mt[i]);\n}\n\n\n/*\n** mark all objects in list of being-finalized\n*/\nstatic void markbeingfnz (global_State *g) {\n  GCObject *o;\n  for (o = g->tobefnz; o != NULL; o = o->next)\n    markobject(g, o);\n}\n\n\n/*\n** Mark all values stored in marked open upvalues from non-marked threads.\n** (Values from marked threads were already marked when traversing the\n** thread.) Remove from the list threads that no longer have upvalues and\n** not-marked threads.\n*/\nstatic void remarkupvals (global_State *g) {\n  lua_State *thread;\n  lua_State **p = &g->twups;\n  while ((thread = *p) != NULL) {\n    lua_assert(!isblack(thread));  /* threads are never black */\n    if (isgray(thread) && thread->openupval != NULL)\n      p = &thread->twups;  /* keep marked thread with upvalues in the list */\n    else {  /* thread is not marked or without upvalues */\n      UpVal *uv;\n      *p = thread->twups;  /* remove thread from the list */\n      thread->twups = thread;  /* mark that it is out of list */\n      for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) {\n        if (uv->u.open.touched) {\n          markvalue(g, uv->v);  /* remark upvalue's value */\n          uv->u.open.touched = 0;\n        }\n      }\n    }\n  }\n}\n\n\n/*\n** mark root set and reset all gray lists, to start a new collection\n*/\nstatic void restartcollection (global_State *g) {\n  g->gray = g->grayagain = NULL;\n  g->weak = g->allweak = g->ephemeron = NULL;\n  markobject(g, g->mainthread);\n  markvalue(g, &g->l_registry);\n  markmt(g);\n  markbeingfnz(g);  /* mark any finalizing object left from previous cycle */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Traverse functions\n** =======================================================\n*/\n\n/*\n** Traverse a table with weak values and link it to proper list. During\n** propagate phase, keep it in 'grayagain' list, to be revisited in the\n** atomic phase. In the atomic phase, if table has any white value,\n** put it in 'weak' list, to be cleared.\n*/\nstatic void traverseweakvalue (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  /* if there is array part, assume it may have white values (it is not\n     worth traversing it now just to check) */\n  int hasclears = (h->sizearray > 0);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      if (!hasclears && iscleared(g, gval(n)))  /* is there a white value? */\n        hasclears = 1;  /* table will have to be cleared */\n    }\n  }\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasclears)\n    linkgclist(h, g->weak);  /* has to be cleared later */\n}\n\n\n/*\n** Traverse an ephemeron table and link it to proper list. Returns true\n** iff any object was marked during this traversal (which implies that\n** convergence has to continue). During propagation phase, keep table\n** in 'grayagain' list, to be visited again in the atomic phase. In\n** the atomic phase, if table has any white->white entry, it has to\n** be revisited during ephemeron convergence (as that key may turn\n** black). Otherwise, if it has any white key, table has to be cleared\n** (in the atomic phase).\n*/\nstatic int traverseephemeron (global_State *g, Table *h) {\n  int marked = 0;  /* true if an object is marked in this traversal */\n  int hasclears = 0;  /* true if table has white keys */\n  int hasww = 0;  /* true if table has entry \"white-key -> white-value\" */\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  /* traverse array part */\n  for (i = 0; i < h->sizearray; i++) {\n    if (valiswhite(&h->array[i])) {\n      marked = 1;\n      reallymarkobject(g, gcvalue(&h->array[i]));\n    }\n  }\n  /* traverse hash part */\n  for (n = gnode(h, 0); n < limit; n++) {\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else if (iscleared(g, gkey(n))) {  /* key is not marked (yet)? */\n      hasclears = 1;  /* table must be cleared */\n      if (valiswhite(gval(n)))  /* value not marked yet? */\n        hasww = 1;  /* white-white entry */\n    }\n    else if (valiswhite(gval(n))) {  /* value not marked yet? */\n      marked = 1;\n      reallymarkobject(g, gcvalue(gval(n)));  /* mark it now */\n    }\n  }\n  /* link table into proper list */\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasww)  /* table has white->white entries? */\n    linkgclist(h, g->ephemeron);  /* have to propagate again */\n  else if (hasclears)  /* table has white keys? */\n    linkgclist(h, g->allweak);  /* may have to clean white keys */\n  return marked;\n}\n\n\nstatic void traversestrongtable (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  for (i = 0; i < h->sizearray; i++)  /* traverse array part */\n    markvalue(g, &h->array[i]);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      markvalue(g, gval(n));  /* mark value */\n    }\n  }\n}\n\n\nstatic lu_mem traversetable (global_State *g, Table *h) {\n  const char *weakkey, *weakvalue;\n  const TValue *mode = gfasttm(g, h->metatable, TM_MODE);\n  markobjectN(g, h->metatable);\n  if (mode && ttisstring(mode) &&  /* is there a weak mode? */\n      ((weakkey = strchr(svalue(mode), 'k')),\n       (weakvalue = strchr(svalue(mode), 'v')),\n       (weakkey || weakvalue))) {  /* is really weak? */\n    black2gray(h);  /* keep table gray */\n    if (!weakkey)  /* strong keys? */\n      traverseweakvalue(g, h);\n    else if (!weakvalue)  /* strong values? */\n      traverseephemeron(g, h);\n    else  /* all weak */\n      linkgclist(h, g->allweak);  /* nothing to traverse now */\n  }\n  else  /* not weak */\n    traversestrongtable(g, h);\n  return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                         sizeof(Node) * cast(size_t, sizenode(h));\n}\n\n\n/*\n** Traverse a prototype. (While a prototype is being build, its\n** arrays can be larger than needed; the extra slots are filled with\n** NULL, so the use of 'markobjectN')\n*/\nstatic int traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->cache && iswhite(f->cache))\n    f->cache = NULL;  /* allow cache to be collected */\n  markobjectN(g, f->source);\n  for (i = 0; i < f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */\n    markobjectN(g, f->upvalues[i].name);\n  for (i = 0; i < f->sizep; i++)  /* mark nested protos */\n    markobjectN(g, f->p[i]);\n  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */\n    markobjectN(g, f->locvars[i].varname);\n  return sizeof(Proto) + sizeof(Instruction) * f->sizecode +\n                         sizeof(Proto *) * f->sizep +\n                         sizeof(TValue) * f->sizek +\n                         sizeof(int) * f->sizelineinfo +\n                         sizeof(LocVar) * f->sizelocvars +\n                         sizeof(Upvaldesc) * f->sizeupvalues;\n}\n\n\nstatic lu_mem traverseCclosure (global_State *g, CClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++)  /* mark its upvalues */\n    markvalue(g, &cl->upvalue[i]);\n  return sizeCclosure(cl->nupvalues);\n}\n\n/*\n** open upvalues point to values in a thread, so those values should\n** be marked when the thread is traversed except in the atomic phase\n** (because then the value cannot be changed by the thread and the\n** thread may not be traversed again)\n*/\nstatic lu_mem traverseLclosure (global_State *g, LClosure *cl) {\n  int i;\n  markobjectN(g, cl->p);  /* mark its prototype */\n  for (i = 0; i < cl->nupvalues; i++) {  /* mark its upvalues */\n    UpVal *uv = cl->upvals[i];\n    if (uv != NULL) {\n      if (upisopen(uv) && g->gcstate != GCSinsideatomic)\n        uv->u.open.touched = 1;  /* can be marked in 'remarkupvals' */\n      else\n        markvalue(g, uv->v);\n    }\n  }\n  return sizeLclosure(cl->nupvalues);\n}\n\n\nstatic lu_mem traversethread (global_State *g, lua_State *th) {\n  StkId o = th->stack;\n  if (o == NULL)\n    return 1;  /* stack not completely built yet */\n  lua_assert(g->gcstate == GCSinsideatomic ||\n             th->openupval == NULL || isintwups(th));\n  for (; o < th->top; o++)  /* mark live elements in the stack */\n    markvalue(g, o);\n  if (g->gcstate == GCSinsideatomic) {  /* final traversal? */\n    StkId lim = th->stack + th->stacksize;  /* real end of stack */\n    for (; o < lim; o++)  /* clear not-marked stack slice */\n      setnilvalue(o);\n    /* 'remarkupvals' may have removed thread from 'twups' list */ \n    if (!isintwups(th) && th->openupval != NULL) {\n      th->twups = g->twups;  /* link it back to the list */\n      g->twups = th;\n    }\n  }\n  else if (g->gckind != KGC_EMERGENCY)\n    luaD_shrinkstack(th); /* do not change stack in emergency cycle */\n  return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n          sizeof(CallInfo) * th->nci);\n}\n\n\n/*\n** traverse one gray object, turning it to black (except for threads,\n** which are always gray).\n*/\nstatic void propagatemark (global_State *g) {\n  lu_mem size;\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2t(o);\n      g->gray = h->gclist;  /* remove from 'gray' list */\n      size = traversetable(g, h);\n      break;\n    }\n    case LUA_TLCL: {\n      LClosure *cl = gco2lcl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseLclosure(g, cl);\n      break;\n    }\n    case LUA_TCCL: {\n      CClosure *cl = gco2ccl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseCclosure(g, cl);\n      break;\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;  /* remove from 'gray' list */\n      linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n      black2gray(o);\n      size = traversethread(g, th);\n      break;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;  /* remove from 'gray' list */\n      size = traverseproto(g, p);\n      break;\n    }\n    default: lua_assert(0); return;\n  }\n  g->GCmemtrav += size;\n}\n\n\nstatic void propagateall (global_State *g) {\n  while (g->gray) propagatemark(g);\n}\n\n\nstatic void convergeephemerons (global_State *g) {\n  int changed;\n  do {\n    GCObject *w;\n    GCObject *next = g->ephemeron;  /* get ephemeron list */\n    g->ephemeron = NULL;  /* tables may return to this list when traversed */\n    changed = 0;\n    while ((w = next) != NULL) {\n      next = gco2t(w)->gclist;\n      if (traverseephemeron(g, gco2t(w))) {  /* traverse marked some value? */\n        propagateall(g);  /* propagate changes */\n        changed = 1;  /* will have to revisit all ephemeron tables */\n      }\n    }\n  } while (changed);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Sweep Functions\n** =======================================================\n*/\n\n\n/*\n** clear entries with unmarked keys from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearkeys (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\n/*\n** clear entries with unmarked values from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearvalues (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    unsigned int i;\n    for (i = 0; i < h->sizearray; i++) {\n      TValue *o = &h->array[i];\n      if (iscleared(g, o))  /* value was collected? */\n        setnilvalue(o);  /* remove value */\n    }\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\nvoid luaC_upvdeccount (lua_State *L, UpVal *uv) {\n  lua_assert(uv->refcount > 0);\n  uv->refcount--;\n  if (uv->refcount == 0 && !upisopen(uv))\n    luaM_free(L, uv);\n}\n\n\nstatic void freeLclosure (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = cl->upvals[i];\n    if (uv)\n      luaC_upvdeccount(L, uv);\n  }\n  luaM_freemem(L, cl, sizeLclosure(cl->nupvalues));\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TLCL: {\n      freeLclosure(L, gco2lcl(o));\n      break;\n    }\n    case LUA_TCCL: {\n      luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));\n      break;\n    }\n    case LUA_TTABLE: luaH_free(L, gco2t(o)); break;\n    case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;\n    case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;\n    case LUA_TSHRSTR:\n      luaS_remove(L, gco2ts(o));  /* remove it from hash table */\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));\n      break;\n    case LUA_TLNGSTR: {\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);\n\n\n/*\n** sweep at most 'count' elements from a list of GCObjects erasing dead\n** objects, where a dead object is one marked with the old (non current)\n** white; change all non-dead objects back to white, preparing for next\n** collection cycle. Return where to continue the traversal or NULL if\n** list is finished.\n*/\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  global_State *g = G(L);\n  int ow = otherwhite(g);\n  int white = luaC_white(g);  /* current white */\n  while (*p != NULL && count-- > 0) {\n    GCObject *curr = *p;\n    int marked = curr->marked;\n    if (isdeadm(ow, marked)) {  /* is 'curr' dead? */\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* change mark to 'white' */\n      curr->marked = cast_byte((marked & maskcolors) | white);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  return (*p == NULL) ? NULL : p;\n}\n\n\n/*\n** sweep a list until a live object (or end of list)\n*/\nstatic GCObject **sweeptolive (lua_State *L, GCObject **p) {\n  GCObject **old = p;\n  do {\n    p = sweeplist(L, p, 1);\n  } while (p == old);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Finalization\n** =======================================================\n*/\n\n/*\n** If possible, shrink string table\n*/\nstatic void checkSizes (lua_State *L, global_State *g) {\n  if (g->gckind != KGC_EMERGENCY) {\n    l_mem olddebt = g->GCdebt;\n    if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */\n      luaS_resize(L, g->strt.size / 2);  /* shrink it a little */\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n  }\n}\n\n\nstatic GCObject *udata2finalize (global_State *g) {\n  GCObject *o = g->tobefnz;  /* get first element */\n  lua_assert(tofinalize(o));\n  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */\n  o->next = g->allgc;  /* return it to 'allgc' list */\n  g->allgc = o;\n  resetbit(o->marked, FINALIZEDBIT);  /* object is \"normal\" again */\n  if (issweepphase(g))\n    makewhite(g, o);  /* \"sweep\" object */\n  return o;\n}\n\n\nstatic void dothecall (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 2, 0);\n}\n\n\nstatic void GCTM (lua_State *L, int propagateerrors) {\n  global_State *g = G(L);\n  const TValue *tm;\n  TValue v;\n  setgcovalue(L, &v, udata2finalize(g));\n  tm = luaT_gettmbyobj(L, &v, TM_GC);\n  if (tm != NULL && ttisfunction(tm)) {  /* is there a finalizer? */\n    int status;\n    lu_byte oldah = L->allowhook;\n    int running  = g->gcrunning;\n    L->allowhook = 0;  /* stop debug hooks during GC metamethod */\n    g->gcrunning = 0;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);  /* push finalizer... */\n    setobj2s(L, L->top + 1, &v);  /* ... and its argument */\n    L->top += 2;  /* and (next line) call the finalizer */\n    status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);\n    L->allowhook = oldah;  /* restore hooks */\n    g->gcrunning = running;  /* restore state */\n    if (status != LUA_OK && propagateerrors) {  /* error while running __gc? */\n      if (status == LUA_ERRRUN) {  /* is there an error object? */\n        const char *msg = (ttisstring(L->top - 1))\n                            ? svalue(L->top - 1)\n                            : \"no message\";\n        luaO_pushfstring(L, \"error in __gc metamethod (%s)\", msg);\n        status = LUA_ERRGCMM;  /* error in __gc metamethod */\n      }\n      luaD_throw(L, status);  /* re-throw error */\n    }\n  }\n}\n\n\n/*\n** call a few (up to 'g->gcfinnum') finalizers\n*/\nstatic int runafewfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  unsigned int i;\n  lua_assert(!g->tobefnz || g->gcfinnum > 0);\n  for (i = 0; g->tobefnz && i < g->gcfinnum; i++)\n    GCTM(L, 1);  /* call one finalizer */\n  g->gcfinnum = (!g->tobefnz) ? 0  /* nothing more to finalize? */\n                    : g->gcfinnum * 2;  /* else call a few more next time */\n  return i;\n}\n\n\n/*\n** call all pending finalizers\n*/\nstatic void callallpendingfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  while (g->tobefnz)\n    GCTM(L, 0);\n}\n\n\n/*\n** find last 'next' field in list 'p' list (to add elements in its end)\n*/\nstatic GCObject **findlast (GCObject **p) {\n  while (*p != NULL)\n    p = &(*p)->next;\n  return p;\n}\n\n\n/*\n** move all unreachable objects (or 'all' objects) that need\n** finalization from list 'finobj' to list 'tobefnz' (to be finalized)\n*/\nstatic void separatetobefnz (global_State *g, int all) {\n  GCObject *curr;\n  GCObject **p = &g->finobj;\n  GCObject **lastnext = findlast(&g->tobefnz);\n  while ((curr = *p) != NULL) {  /* traverse all finalizable objects */\n    lua_assert(tofinalize(curr));\n    if (!(iswhite(curr) || all))  /* not being collected? */\n      p = &curr->next;  /* don't bother with it */\n    else {\n      *p = curr->next;  /* remove 'curr' from 'finobj' list */\n      curr->next = *lastnext;  /* link at the end of 'tobefnz' list */\n      *lastnext = curr;\n      lastnext = &curr->next;\n    }\n  }\n}\n\n\n/*\n** if object 'o' has a finalizer, remove it from 'allgc' list (must\n** search the list to find it) and link it in 'finobj' list.\n*/\nvoid luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {\n  global_State *g = G(L);\n  if (tofinalize(o) ||                 /* obj. is already marked... */\n      gfasttm(g, mt, TM_GC) == NULL)   /* or has no finalizer? */\n    return;  /* nothing to be done */\n  else {  /* move 'o' to 'finobj' list */\n    GCObject **p;\n    if (issweepphase(g)) {\n      makewhite(g, o);  /* \"sweep\" object 'o' */\n      if (g->sweepgc == &o->next)  /* should not remove 'sweepgc' object */\n        g->sweepgc = sweeptolive(L, g->sweepgc);  /* change 'sweepgc' */\n    }\n    /* search for pointer pointing to 'o' */\n    for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }\n    *p = o->next;  /* remove 'o' from 'allgc' list */\n    o->next = g->finobj;  /* link it in 'finobj' list */\n    g->finobj = o;\n    l_setbit(o->marked, FINALIZEDBIT);  /* mark it as such */\n  }\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** GC control\n** =======================================================\n*/\n\n\n/*\n** Set a reasonable \"time\" to wait before starting a new GC cycle; cycle\n** will start when memory use hits threshold. (Division by 'estimate'\n** should be OK: it cannot be zero (because Lua cannot even start with\n** less than PAUSEADJ bytes).\n*/\nstatic void setpause (global_State *g) {\n  l_mem threshold, debt;\n  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */\n  lua_assert(estimate > 0);\n  threshold = (g->gcpause < MAX_LMEM / estimate)  /* overflow? */\n            ? estimate * g->gcpause  /* no overflow */\n            : MAX_LMEM;  /* overflow; truncate to maximum */\n  debt = gettotalbytes(g) - threshold;\n  luaE_setdebt(g, debt);\n}\n\n\n/*\n** Enter first sweep phase.\n** The call to 'sweeplist' tries to make pointer point to an object\n** inside the list (instead of to the header), so that the real sweep do\n** not need to skip objects created between \"now\" and the start of the\n** real sweep.\n*/\nstatic void entersweep (lua_State *L) {\n  global_State *g = G(L);\n  g->gcstate = GCSswpallgc;\n  lua_assert(g->sweepgc == NULL);\n  g->sweepgc = sweeplist(L, &g->allgc, 1);\n}\n\n\nvoid luaC_freeallobjects (lua_State *L) {\n  global_State *g = G(L);\n  separatetobefnz(g, 1);  /* separate all objects with finalizers */\n  lua_assert(g->finobj == NULL);\n  callallpendingfinalizers(L);\n  lua_assert(g->tobefnz == NULL);\n  g->currentwhite = WHITEBITS; /* this \"white\" makes all objects look dead */\n  g->gckind = KGC_NORMAL;\n  sweepwholelist(L, &g->finobj);\n  sweepwholelist(L, &g->allgc);\n  sweepwholelist(L, &g->fixedgc);  /* collect fixed objects */\n  lua_assert(g->strt.nuse == 0);\n}\n\n\nstatic l_mem atomic (lua_State *L) {\n  global_State *g = G(L);\n  l_mem work;\n  GCObject *origweak, *origall;\n  GCObject *grayagain = g->grayagain;  /* save original list */\n  lua_assert(g->ephemeron == NULL && g->weak == NULL);\n  lua_assert(!iswhite(g->mainthread));\n  g->gcstate = GCSinsideatomic;\n  g->GCmemtrav = 0;  /* start counting work */\n  markobject(g, L);  /* mark running thread */\n  /* registry and global metatables may be changed by API */\n  markvalue(g, &g->l_registry);\n  markmt(g);  /* mark global metatables */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  propagateall(g);  /* propagate changes */\n  work = g->GCmemtrav;  /* stop counting (do not recount 'grayagain') */\n  g->gray = grayagain;\n  propagateall(g);  /* traverse 'grayagain' list */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all strongly accessible objects are marked. */\n  /* Clear values from weak tables, before checking finalizers */\n  clearvalues(g, g->weak, NULL);\n  clearvalues(g, g->allweak, NULL);\n  origweak = g->weak; origall = g->allweak;\n  work += g->GCmemtrav;  /* stop counting (objects being finalized) */\n  separatetobefnz(g, 0);  /* separate objects to be finalized */\n  g->gcfinnum = 1;  /* there may be objects to be finalized */\n  markbeingfnz(g);  /* mark objects that will be finalized */\n  propagateall(g);  /* remark, to propagate 'resurrection' */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all resurrected objects are marked. */\n  /* remove dead objects from weak tables */\n  clearkeys(g, g->ephemeron, NULL);  /* clear keys from all ephemeron tables */\n  clearkeys(g, g->allweak, NULL);  /* clear keys from all 'allweak' tables */\n  /* clear values from resurrected weak tables */\n  clearvalues(g, g->weak, origweak);\n  clearvalues(g, g->allweak, origall);\n  luaS_clearcache(g);\n  g->currentwhite = cast_byte(otherwhite(g));  /* flip current white */\n  work += g->GCmemtrav;  /* complete counting */\n  return work;  /* estimate of memory marked by 'atomic' */\n}\n\n\nstatic lu_mem sweepstep (lua_State *L, global_State *g,\n                         int nextstate, GCObject **nextlist) {\n  if (g->sweepgc) {\n    l_mem olddebt = g->GCdebt;\n    g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n    if (g->sweepgc)  /* is there still something to sweep? */\n      return (GCSWEEPMAX * GCSWEEPCOST);\n  }\n  /* else enter next state */\n  g->gcstate = nextstate;\n  g->sweepgc = nextlist;\n  return 0;\n}\n\n\nstatic lu_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  switch (g->gcstate) {\n    case GCSpause: {\n      g->GCmemtrav = g->strt.size * sizeof(GCObject*);\n      restartcollection(g);\n      g->gcstate = GCSpropagate;\n      return g->GCmemtrav;\n    }\n    case GCSpropagate: {\n      g->GCmemtrav = 0;\n      lua_assert(g->gray);\n      propagatemark(g);\n       if (g->gray == NULL)  /* no more gray objects? */\n        g->gcstate = GCSatomic;  /* finish propagate phase */\n      return g->GCmemtrav;  /* memory traversed in this step */\n    }\n    case GCSatomic: {\n      lu_mem work;\n      propagateall(g);  /* make sure gray list is empty */\n      work = atomic(L);  /* work is what was traversed by 'atomic' */\n      entersweep(L);\n      g->GCestimate = gettotalbytes(g);  /* first estimate */;\n      return work;\n    }\n    case GCSswpallgc: {  /* sweep \"regular\" objects */\n      return sweepstep(L, g, GCSswpfinobj, &g->finobj);\n    }\n    case GCSswpfinobj: {  /* sweep objects with finalizers */\n      return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);\n    }\n    case GCSswptobefnz: {  /* sweep objects to be finalized */\n      return sweepstep(L, g, GCSswpend, NULL);\n    }\n    case GCSswpend: {  /* finish sweeps */\n      makewhite(g, g->mainthread);  /* sweep main thread */\n      checkSizes(L, g);\n      g->gcstate = GCScallfin;\n      return 0;\n    }\n    case GCScallfin: {  /* call remaining finalizers */\n      if (g->tobefnz && g->gckind != KGC_EMERGENCY) {\n        int n = runafewfinalizers(L);\n        return (n * GCFINALIZECOST);\n      }\n      else {  /* emergency mode or no more finalizers */\n        g->gcstate = GCSpause;  /* finish collection */\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** advances the garbage collector until it reaches a state allowed\n** by 'statemask'\n*/\nvoid luaC_runtilstate (lua_State *L, int statesmask) {\n  global_State *g = G(L);\n  while (!testbit(statesmask, g->gcstate))\n    singlestep(L);\n}\n\n\n/*\n** get GC debt and convert it from Kb to 'work units' (avoid zero debt\n** and overflows)\n*/\nstatic l_mem getdebt (global_State *g) {\n  l_mem debt = g->GCdebt;\n  int stepmul = g->gcstepmul;\n  if (debt <= 0) return 0;  /* minimal debt */\n  else {\n    debt = (debt / STEPMULADJ) + 1;\n    debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;\n    return debt;\n  }\n}\n\n/*\n** performs a basic GC step when collector is running\n*/\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  l_mem debt = getdebt(g);  /* GC deficit (be paid now) */\n  if (!g->gcrunning) {  /* not running? */\n    luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */\n    return;\n  }\n  do {  /* repeat until pause or enough \"credit\" (negative debt) */\n    lu_mem work = singlestep(L);  /* perform one single step */\n    debt -= work;\n  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);\n  if (g->gcstate == GCSpause)\n    setpause(g);  /* pause until next cycle */\n  else {\n    debt = (debt / g->gcstepmul) * STEPMULADJ;  /* convert 'work units' to Kb */\n    luaE_setdebt(g, debt);\n    runafewfinalizers(L);\n  }\n}\n\n\n/*\n** Performs a full GC cycle; if 'isemergency', set a flag to avoid\n** some operations which could change the interpreter state in some\n** unexpected ways (running finalizers and shrinking some structures).\n** Before running the collection, check 'keepinvariant'; if it is true,\n** there may be some objects marked as black, so the collector has\n** to sweep all objects to turn them back to white (as white has not\n** changed, nothing will be collected).\n*/\nvoid luaC_fullgc (lua_State *L, int isemergency) {\n  global_State *g = G(L);\n  lua_assert(g->gckind == KGC_NORMAL);\n  if (isemergency) g->gckind = KGC_EMERGENCY;  /* set flag */\n  if (keepinvariant(g)) {  /* black objects? */\n    entersweep(L); /* sweep everything to turn them back to white */\n  }\n  /* finish any pending sweep phase to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpause));\n  luaC_runtilstate(L, ~bitmask(GCSpause));  /* start new collection */\n  luaC_runtilstate(L, bitmask(GCScallfin));  /* run up to finalizers */\n  /* estimate must be correct after a full GC cycle */\n  lua_assert(g->GCestimate == gettotalbytes(g));\n  luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n  g->gckind = KGC_NORMAL;\n  setpause(g);\n}\n\n/* }====================================================== */\n\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n/*\n** Collectable objects may have one of three colors: white, which\n** means the object is not marked; gray, which means the\n** object is marked, but its references may be not marked; and\n** black, which means that the object and all its references are marked.\n** The main invariant of the garbage collector, while marking objects,\n** is that a black object can never point to a white one. Moreover,\n** any gray object must be in a \"gray list\" (gray, grayagain, weak,\n** allweak, ephemeron) so that it can be visited again before finishing\n** the collection cycle. These lists have no meaning when the invariant\n** is not being enforced (e.g., sweep phase).\n*/\n\n\n\n/* how much to allocate before next GC step */\n#if !defined(GCSTEPSIZE)\n/* ~100 small strings */\n#define GCSTEPSIZE\t(cast_int(100 * sizeof(TString)))\n#endif\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpropagate\t0\n#define GCSatomic\t1\n#define GCSswpallgc\t2\n#define GCSswpfinobj\t3\n#define GCSswptobefnz\t4\n#define GCSswpend\t5\n#define GCScallfin\t6\n#define GCSpause\t7\n\n\n#define issweepphase(g)  \\\n\t(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)\n\n\n/*\n** macro to tell when main invariant (white objects cannot point to black\n** ones) must be kept. During a collection, the sweep\n** phase may break the invariant, as objects turned white may point to\n** still-black objects. The invariant is restored when sweep ends and\n** all objects are white again.\n*/\n\n#define keepinvariant(g)\t((g)->gcstate <= GCSatomic)\n\n\n/*\n** some useful bit tricks\n*/\n#define resetbits(x,m)\t\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t\t((x) |= (m))\n#define testbits(x,m)\t\t((x) & (m))\n#define bitmask(b)\t\t(1<<(b))\n#define bit2mask(b1,b2)\t\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\t\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\t\tresetbits(x, bitmask(b))\n#define testbit(x,b)\t\ttestbits(x, bitmask(b))\n\n\n/* Layout for bit use in 'marked' field: */\n#define WHITE0BIT\t0  /* object is white (type 0) */\n#define WHITE1BIT\t1  /* object is white (type 1) */\n#define BLACKBIT\t2  /* object is black */\n#define FINALIZEDBIT\t3  /* object has been marked for finalization */\n/* bit 7 is currently used by tests (luaL_checkmemory) */\n\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      testbits((x)->marked, WHITEBITS)\n#define isblack(x)      testbit((x)->marked, BLACKBIT)\n#define isgray(x)  /* neither white nor black */  \\\n\t(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))\n\n#define tofinalize(x)\ttestbit((x)->marked, FINALIZEDBIT)\n\n#define otherwhite(g)\t((g)->currentwhite ^ WHITEBITS)\n#define isdeadm(ow,m)\t(!(((m) ^ WHITEBITS) & (ow)))\n#define isdead(g,v)\tisdeadm(otherwhite(g), (v)->marked)\n\n#define changewhite(x)\t((x)->marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->marked, BLACKBIT)\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n\n/*\n** Does one step of collection when debt becomes positive. 'pre'/'pos'\n** allows some adjustments to be done only when needed. macro\n** 'condchangemem' is used only for heavy tests (forcing a full\n** GC cycle on every opportunity)\n*/\n#define luaC_condGC(L,pre,pos) \\\n\t{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \\\n\t  condchangemem(L,pre,pos); }\n\n/* more often than not, 'pre'/'pos' are empty */\n#define luaC_checkGC(L)\t\tluaC_condGC(L,(void)0,(void)0)\n\n\n#define luaC_barrier(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \\\n\tluaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))\n\n#define luaC_barrierback(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \\\n\tluaC_barrierback_(L,p) : cast_void(0))\n\n#define luaC_objbarrier(L,p,o) (  \\\n\t(isblack(p) && iswhite(o)) ? \\\n\tluaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))\n\n#define luaC_upvalbarrier(L,uv) ( \\\n\t(iscollectable((uv)->v) && !upisopen(uv)) ? \\\n         luaC_upvalbarrier_(L,uv) : cast_void(0))\n\nLUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_freeallobjects (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);\nLUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);\nLUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);\nLUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o);\nLUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);\nLUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $\n** Initialization of libraries for lua.c and other clients\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n/*\n** If you embed Lua in your program and need to open the standard\n** libraries, call luaL_openlibs in your program. If you need a\n** different set of libraries, copy this file to your project and edit\n** it to suit your needs.\n**\n** You can also *preload* libraries, so that a later 'require' can\n** open the library, which is already linked to the application.\n** For that, do the following code:\n**\n**  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\");\n**  lua_pushcfunction(L, luaopen_modname);\n**  lua_setfield(L, -2, modname);\n**  lua_pop(L, 1);  // remove _PRELOAD table\n*/\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\n/*\n** these libs are loaded by lua.c and are readily available to any Lua\n** program\n*/\nstatic const luaL_Reg loadedlibs[] = {\n  {\"_G\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_COLIBNAME, luaopen_coroutine},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_UTF8LIBNAME, luaopen_utf8},\n  {LUA_DBLIBNAME, luaopen_debug},\n#if defined(LUA_COMPAT_BITLIB)\n  {LUA_BITLIBNAME, luaopen_bit32},\n#endif\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib;\n  /* \"require\" functions from 'loadedlibs' and set results to global table */\n  for (lib = loadedlibs; lib->func; lib++) {\n    luaL_requiref(L, lib->name, lib->func, 1);\n    lua_pop(L, 1);  /* remove lib */\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.149 2016/05/02 14:03:19 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <locale.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** Change this macro to accept other modes for 'fopen' besides\n** the standard ones.\n*/\n#if !defined(l_checkmode)\n\n/* accepted extensions to 'mode' in 'fopen' */\n#if !defined(L_MODEEXT)\n#define L_MODEEXT\t\"b\"\n#endif\n\n/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */\n#define l_checkmode(mode) \\\n\t(*mode != '\\0' && strchr(\"rwa\", *(mode++)) != NULL &&\t\\\n\t(*mode != '+' || (++mode, 1)) &&  /* skip if char is '+' */\t\\\n\t(strspn(mode, L_MODEEXT) == strlen(mode)))\n\n#endif\n\n/*\n** {======================================================\n** l_popen spawns a new process connected to the current\n** one through the file streams.\n** =======================================================\n*/\n\n#if !defined(l_popen)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_popen(L,c,m)\t\t(fflush(NULL), popen(c,m))\n#define l_pclose(L,file)\t(pclose(file))\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#define l_popen(L,c,m)\t\t(_popen(c,m))\n#define l_pclose(L,file)\t(_pclose(file))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_popen(L,c,m)  \\\n\t  ((void)((void)c, m), \\\n\t  luaL_error(L, \"'popen' not supported\"), \\\n\t  (FILE*)0)\n#define l_pclose(L,file)\t\t((void)L, (void)file, -1)\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#if !defined(l_getc)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\n#define l_getc(f)\t\tgetc_unlocked(f)\n#define l_lockfile(f)\t\tflockfile(f)\n#define l_unlockfile(f)\t\tfunlockfile(f)\n#else\n#define l_getc(f)\t\tgetc(f)\n#define l_lockfile(f)\t\t((void)0)\n#define l_unlockfile(f)\t\t((void)0)\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** {======================================================\n** l_fseek: configuration for longer offsets\n** =======================================================\n*/\n\n#if !defined(l_fseek)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <sys/types.h>\n\n#define l_fseek(f,o,w)\t\tfseeko(f,o,w)\n#define l_ftell(f)\t\tftello(f)\n#define l_seeknum\t\toff_t\n\n#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \\\n   && defined(_MSC_VER) && (_MSC_VER >= 1400)\t/* }{ */\n\n/* Windows (but not DDK) and Visual C++ 2005 or higher */\n#define l_fseek(f,o,w)\t\t_fseeki64(f,o,w)\n#define l_ftell(f)\t\t_ftelli64(f)\n#define l_seeknum\t\t__int64\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_fseek(f,o,w)\t\tfseek(f,o,w)\n#define l_ftell(f)\t\tftell(f)\n#define l_seeknum\t\tlong\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#define IO_PREFIX\t\"_IO_\"\n#define IOPREF_LEN\t(sizeof(IO_PREFIX)/sizeof(char) - 1)\n#define IO_INPUT\t(IO_PREFIX \"input\")\n#define IO_OUTPUT\t(IO_PREFIX \"output\")\n\n\ntypedef luaL_Stream LStream;\n\n\n#define tolstream(L)\t((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n#define isclosed(p)\t((p)->closef == NULL)\n\n\nstatic int io_type (lua_State *L) {\n  LStream *p;\n  luaL_checkany(L, 1);\n  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);\n  if (p == NULL)\n    lua_pushnil(L);  /* not a file */\n  else if (isclosed(p))\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic int f_tostring (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", p->f);\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    luaL_error(L, \"attempt to use a closed file\");\n  lua_assert(p->f);\n  return p->f;\n}\n\n\n/*\n** When creating file handles, always creates a 'closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** handle is in a consistent state.\n*/\nstatic LStream *newprefile (lua_State *L) {\n  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));\n  p->closef = NULL;  /* mark file handle as 'closed' */\n  luaL_setmetatable(L, LUA_FILEHANDLE);\n  return p;\n}\n\n\n/*\n** Calls the 'close' function from a file handle. The 'volatile' avoids\n** a bug in some versions of the Clang compiler (e.g., clang 3.0 for\n** 32 bits).\n*/\nstatic int aux_close (lua_State *L) {\n  LStream *p = tolstream(L);\n  volatile lua_CFunction cf = p->closef;\n  p->closef = NULL;  /* mark stream as closed */\n  return (*cf)(L);  /* close it */\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))  /* no argument? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */\n  tofile(L);  /* make sure argument is an open stream */\n  return aux_close(L);\n}\n\n\nstatic int f_gc (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (!isclosed(p) && p->f != NULL)\n    aux_close(L);  /* ignore closed and incompletely open files */\n  return 0;\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  int res = fclose(p->f);\n  return luaL_fileresult(L, (res == 0), NULL);\n}\n\n\nstatic LStream *newfile (lua_State *L) {\n  LStream *p = newprefile(L);\n  p->f = NULL;\n  p->closef = &io_fclose;\n  return p;\n}\n\n\nstatic void opencheck (lua_State *L, const char *fname, const char *mode) {\n  LStream *p = newfile(L);\n  p->f = fopen(fname, mode);\n  if (p->f == NULL)\n    luaL_error(L, \"cannot open file '%s' (%s)\", fname, strerror(errno));\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newfile(L);\n  const char *md = mode;  /* to traverse/check mode */\n  luaL_argcheck(L, l_checkmode(md), 2, \"invalid mode\");\n  p->f = fopen(filename, mode);\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  LStream *p = tolstream(L);\n  return luaL_execresult(L, l_pclose(L, p->f));\n#endif\n}\n\n\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newprefile(L);\n  p->f = l_popen(L, filename, mode);\n  p->closef = &io_pclose;\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  LStream *p = newfile(L);\n  p->f = tmpfile();\n  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, const char *findex) {\n  LStream *p;\n  lua_getfield(L, LUA_REGISTRYINDEX, findex);\n  p = (LStream *)lua_touserdata(L, -1);\n  if (isclosed(p))\n    luaL_error(L, \"standard %s file is closed\", findex + IOPREF_LEN);\n  return p->f;\n}\n\n\nstatic int g_iofile (lua_State *L, const char *f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename)\n      opencheck(L, filename, mode);\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_setfield(L, LUA_REGISTRYINDEX, f);\n  }\n  /* return current value */\n  lua_getfield(L, LUA_REGISTRYINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\n/*\n** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit\n** in the limit for upvalues of a closure)\n*/\n#define MAXARGLINE\t250\n\nstatic void aux_lines (lua_State *L, int toclose) {\n  int n = lua_gettop(L) - 1;  /* number of arguments to read */\n  luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, \"too many arguments\");\n  lua_pushinteger(L, n);  /* number of arguments to read */\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_rotate(L, 2, 2);  /* move 'n' and 'toclose' to their positions */\n  lua_pushcclosure(L, io_readline, 3 + n);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  int toclose;\n  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */\n  if (lua_isnil(L, 1)) {  /* no file name? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */\n    lua_replace(L, 1);  /* put it at index 1 */\n    tofile(L);  /* check that it's a valid file handle */\n    toclose = 0;  /* do not close it after iteration */\n  }\n  else {  /* open a new file */\n    const char *filename = luaL_checkstring(L, 1);\n    opencheck(L, filename, \"r\");\n    lua_replace(L, 1);  /* put file at index 1 */\n    toclose = 1;  /* close it after iteration */\n  }\n  aux_lines(L, toclose);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM     200\n#endif\n\n\n/* auxiliary structure used by 'read_number' */\ntypedef struct {\n  FILE *f;  /* file being read */\n  int c;  /* current character (look ahead) */\n  int n;  /* number of elements in buffer 'buff' */\n  char buff[L_MAXLENNUM + 1];  /* +1 for ending '\\0' */\n} RN;\n\n\n/*\n** Add current char to buffer (if not out of space) and read next one\n*/\nstatic int nextc (RN *rn) {\n  if (rn->n >= L_MAXLENNUM) {  /* buffer overflow? */\n    rn->buff[0] = '\\0';  /* invalidate result */\n    return 0;  /* fail */\n  }\n  else {\n    rn->buff[rn->n++] = rn->c;  /* save current char */\n    rn->c = l_getc(rn->f);  /* read next one */\n    return 1;\n  }\n}\n\n\n/*\n** Accept current char if it is in 'set' (of size 2)\n*/\nstatic int test2 (RN *rn, const char *set) {\n  if (rn->c == set[0] || rn->c == set[1])\n    return nextc(rn);\n  else return 0;\n}\n\n\n/*\n** Read a sequence of (hex)digits\n*/\nstatic int readdigits (RN *rn, int hex) {\n  int count = 0;\n  while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn))\n    count++;\n  return count;\n}\n\n\n/*\n** Read a number: first reads a valid prefix of a numeral into a buffer.\n** Then it calls 'lua_stringtonumber' to check whether the format is\n** correct and to convert it to a Lua number\n*/\nstatic int read_number (lua_State *L, FILE *f) {\n  RN rn;\n  int count = 0;\n  int hex = 0;\n  char decp[2];\n  rn.f = f; rn.n = 0;\n  decp[0] = lua_getlocaledecpoint();  /* get decimal point from locale */\n  decp[1] = '.';  /* always accept a dot */\n  l_lockfile(rn.f);\n  do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */\n  test2(&rn, \"-+\");  /* optional signal */\n  if (test2(&rn, \"00\")) {\n    if (test2(&rn, \"xX\")) hex = 1;  /* numeral is hexadecimal */\n    else count = 1;  /* count initial '0' as a valid digit */\n  }\n  count += readdigits(&rn, hex);  /* integral part */\n  if (test2(&rn, decp))  /* decimal point? */\n    count += readdigits(&rn, hex);  /* fractional part */\n  if (count > 0 && test2(&rn, (hex ? \"pP\" : \"eE\"))) {  /* exponent mark? */\n    test2(&rn, \"-+\");  /* exponent signal */\n    readdigits(&rn, 0);  /* exponent digits */\n  }\n  ungetc(rn.c, rn.f);  /* unread look-ahead char */\n  l_unlockfile(rn.f);\n  rn.buff[rn.n] = '\\0';  /* finish string */\n  if (lua_stringtonumber(L, rn.buff))  /* is this a valid number? */\n    return 1;  /* ok */\n  else {  /* invalid format */\n   lua_pushnil(L);  /* \"result\" to be removed */\n   return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);  /* no-op when c == EOF */\n  lua_pushliteral(L, \"\");\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f, int chop) {\n  luaL_Buffer b;\n  int c = '\\0';\n  luaL_buffinit(L, &b);\n  while (c != EOF && c != '\\n') {  /* repeat until end of line */\n    char *buff = luaL_prepbuffer(&b);  /* preallocate buffer */\n    int i = 0;\n    l_lockfile(f);  /* no memory errors can happen inside the lock */\n    while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')\n      buff[i++] = c;\n    l_unlockfile(f);\n    luaL_addsize(&b, i);\n  }\n  if (!chop && c == '\\n')  /* want a newline and have one? */\n    luaL_addchar(&b, c);  /* add ending newline to result */\n  luaL_pushresult(&b);  /* close buffer */\n  /* return ok if read something (either a newline or something else) */\n  return (c == '\\n' || lua_rawlen(L, -1) > 0);\n}\n\n\nstatic void read_all (lua_State *L, FILE *f) {\n  size_t nr;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */\n    char *p = luaL_prepbuffer(&b);\n    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);\n    luaL_addsize(&b, nr);\n  } while (nr == LUAL_BUFFERSIZE);\n  luaL_pushresult(&b);  /* close buffer */\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t nr;  /* number of chars actually read */\n  char *p;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */\n  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */\n  luaL_addsize(&b, nr);\n  luaL_pushresult(&b);  /* close buffer */\n  return (nr > 0);  /* true iff read something */\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f, 1);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)luaL_checkinteger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = luaL_checkstring(L, n);\n        if (*p == '*') p++;  /* skip optional '*' (for compatibility) */\n        switch (*p) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f, 1);\n            break;\n          case 'L':  /* line with end-of-line */\n            success = read_line(L, f, 0);\n            break;\n          case 'a':  /* file */\n            read_all(L, f);  /* read entire file */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return luaL_fileresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));\n  int i;\n  int n = (int)lua_tointeger(L, lua_upvalueindex(2));\n  if (isclosed(p))  /* file is already closed? */\n    return luaL_error(L, \"file is already closed\");\n  lua_settop(L , 1);\n  luaL_checkstack(L, n, \"too many arguments\");\n  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */\n    lua_pushvalue(L, lua_upvalueindex(3 + i));\n  n = g_read(L, p->f, 2);  /* 'n' is number of results */\n  lua_assert(n > 0);  /* should return at least a nil */\n  if (lua_toboolean(L, -n))  /* read at least one value? */\n    return n;  /* return them */\n  else {  /* first result is nil: EOF or error */\n    if (n > 1) {  /* is there error information? */\n      /* 2nd result is error message */\n      return luaL_error(L, \"%s\", lua_tostring(L, -n + 1));\n    }\n    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - arg;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      int len = lua_isinteger(L, arg)\n                ? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg))\n                : fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg));\n      status = status && (len > 0);\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  if (status) return 1;  /* file handle already on stack top */\n  else return luaL_fileresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  FILE *f = tofile(L);\n  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */\n  return g_write(L, f, 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  lua_Integer p3 = luaL_optinteger(L, 3, 0);\n  l_seeknum offset = (l_seeknum)p3;\n  luaL_argcheck(L, (lua_Integer)offset == p3, 3,\n                  \"not an integer in proper range\");\n  op = l_fseek(f, offset, mode[op]);\n  if (op)\n    return luaL_fileresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, (lua_Integer)l_ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], (size_t)sz);\n  return luaL_fileresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\n/*\n** functions for 'io' library\n*/\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\n/*\n** methods for file handles\n*/\nstatic const luaL_Reg flib[] = {\n  {\"close\", io_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", f_gc},\n  {\"__tostring\", f_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */\n  lua_pop(L, 1);  /* pop new metatable */\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  p->closef = &io_noclose;  /* keep file opened */\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, const char *k,\n                           const char *fname) {\n  LStream *p = newprefile(L);\n  p->f = f;\n  p->closef = &io_noclose;\n  if (k != NULL) {\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */\n  }\n  lua_setfield(L, -2, fname);  /* add file to module */\n}\n\n\nLUAMOD_API int luaopen_io (lua_State *L) {\n  luaL_newlib(L, iolib);  /* new module */\n  createmeta(L);\n  /* create (and set) default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, NULL, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nstatic const char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"goto\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"//\", \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<<\", \">>\", \"::\", \"<eof>\",\n    \"<number>\", \"<integer>\", \"<name>\", \"<string>\"\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token);\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {\n    size_t newsize;\n    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)\n      lexerror(ls, \"lexical element too long\", 0);\n    newsize = luaZ_sizebuffer(b) * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[luaZ_bufflen(b)++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */\n  luaC_fix(L, obj2gco(e));  /* never collect this name */\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */\n    ts->extra = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {  /* single-byte symbols? */\n    lua_assert(token == cast_uchar(token));\n    return luaO_pushfstring(ls->L, \"'%c'\", token);\n  }\n  else {\n    const char *s = luaX_tokens[token - FIRST_RESERVED];\n    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */\n      return luaO_pushfstring(ls->L, \"'%s'\", s);\n    else  /* names, strings, and numerals */\n      return s;\n  }\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME: case TK_STRING:\n    case TK_FLT: case TK_INT:\n      save(ls, '\\0');\n      return luaO_pushfstring(ls->L, \"'%s'\", luaZ_buffer(ls->buff));\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token) {\n  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near %s\", msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nl_noret luaX_syntaxerror (LexState *ls, const char *msg) {\n  lexerror(ls, msg, ls->t.token);\n}\n\n\n/*\n** creates a new string and anchors it in scanner's table so that\n** it will not be collected until the end of the compilation\n** (by that time it should be anchored somewhere)\n*/\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TValue *o;  /* entry for 'str' */\n  TString *ts = luaS_newlstr(L, str, l);  /* create new string */\n  setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */\n  o = luaH_set(L, ls->h, L->top - 1);\n  if (ttisnil(o)) {  /* not in use yet? */\n    /* boolean value does not need GC barrier;\n       table has no metatable, so it does not need to invalidate cache */\n    setbvalue(o, 1);  /* t[string] = true */\n    luaC_checkGC(L);\n  }\n  else {  /* string already present */\n    ts = tsvalue(keyfromval(o));  /* re-use value previously stored */\n  }\n  L->top--;  /* remove string from stack */\n  return ts;\n}\n\n\n/*\n** increment line number and skips newline sequence (any of\n** \\n, \\r, \\n\\r, or \\r\\n)\n*/\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip '\\n' or '\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip '\\n\\r' or '\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    lexerror(ls, \"chunk has too many lines\", 0);\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,\n                    int firstchar) {\n  ls->t.token = 0;\n  ls->L = L;\n  ls->current = firstchar;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\nstatic int check_next1 (LexState *ls, int c) {\n  if (ls->current == c) {\n    next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check whether current char is in set 'set' (with two chars) and\n** saves it\n*/\nstatic int check_next2 (LexState *ls, const char *set) {\n  lua_assert(set[2] == '\\0');\n  if (ls->current == set[0] || ls->current == set[1]) {\n    save_and_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/* LUA_NUMBER */\n/*\n** this function is quite liberal in what it accepts, as 'luaO_str2num'\n** will reject ill-formed numerals.\n*/\nstatic int read_numeral (LexState *ls, SemInfo *seminfo) {\n  TValue obj;\n  const char *expo = \"Ee\";\n  int first = ls->current;\n  lua_assert(lisdigit(ls->current));\n  save_and_next(ls);\n  if (first == '0' && check_next2(ls, \"xX\"))  /* hexadecimal? */\n    expo = \"Pp\";\n  for (;;) {\n    if (check_next2(ls, expo))  /* exponent part? */\n      check_next2(ls, \"-+\");  /* optional exponent sign */\n    if (lisxdigit(ls->current))\n      save_and_next(ls);\n    else if (ls->current == '.')\n      save_and_next(ls);\n    else break;\n  }\n  save(ls, '\\0');\n  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */\n    lexerror(ls, \"malformed number\", TK_FLT);\n  if (ttisinteger(&obj)) {\n    seminfo->i = ivalue(&obj);\n    return TK_INT;\n  }\n  else {\n    lua_assert(ttisfloat(&obj));\n    seminfo->r = fltvalue(&obj);\n    return TK_FLT;\n  }\n}\n\n\n/*\n** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return\n** its number of '='s; otherwise, return a negative number (-1 iff there\n** are no '='s after initial bracket)\n*/\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int line = ls->linenumber;  /* initial line (for error message) */\n  save_and_next(ls);  /* skip 2nd '[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ: {  /* error */\n        const char *what = (seminfo ? \"string\" : \"comment\");\n        const char *msg = luaO_pushfstring(ls->L,\n                     \"unfinished long %s (starting at line %d)\", what, line);\n        lexerror(ls, msg, TK_EOS);\n        break;  /* to avoid warnings */\n      }\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd ']' */\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n': case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void esccheck (LexState *ls, int c, const char *msg) {\n  if (!c) {\n    if (ls->current != EOZ)\n      save_and_next(ls);  /* add current to buffer for error message */\n    lexerror(ls, msg, TK_STRING);\n  }\n}\n\n\nstatic int gethexa (LexState *ls) {\n  save_and_next(ls);\n  esccheck (ls, lisxdigit(ls->current), \"hexadecimal digit expected\");\n  return luaO_hexavalue(ls->current);\n}\n\n\nstatic int readhexaesc (LexState *ls) {\n  int r = gethexa(ls);\n  r = (r << 4) + gethexa(ls);\n  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic unsigned long readutf8esc (LexState *ls) {\n  unsigned long r;\n  int i = 4;  /* chars to be removed: '\\', 'u', '{', and first digit */\n  save_and_next(ls);  /* skip 'u' */\n  esccheck(ls, ls->current == '{', \"missing '{'\");\n  r = gethexa(ls);  /* must have at least one digit */\n  while ((save_and_next(ls), lisxdigit(ls->current))) {\n    i++;\n    r = (r << 4) + luaO_hexavalue(ls->current);\n    esccheck(ls, r <= 0x10FFFF, \"UTF-8 value too large\");\n  }\n  esccheck(ls, ls->current == '}', \"missing '}'\");\n  next(ls);  /* skip '}' */\n  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic void utf8esc (LexState *ls) {\n  char buff[UTF8BUFFSZ];\n  int n = luaO_utf8esc(buff, readutf8esc(ls));\n  for (; n > 0; n--)  /* add 'buff' to string */\n    save(ls, buff[UTF8BUFFSZ - n]);\n}\n\n\nstatic int readdecesc (LexState *ls) {\n  int i;\n  int r = 0;  /* result accumulator */\n  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */\n    r = 10*r + ls->current - '0';\n    save_and_next(ls);\n  }\n  esccheck(ls, r <= UCHAR_MAX, \"decimal escape too large\");\n  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */\n  return r;\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);  /* keep delimiter (for error messages) */\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        lexerror(ls, \"unfinished string\", TK_EOS);\n        break;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        lexerror(ls, \"unfinished string\", TK_STRING);\n        break;  /* to avoid warnings */\n      case '\\\\': {  /* escape sequences */\n        int c;  /* final character to be saved */\n        save_and_next(ls);  /* keep '\\\\' for error messages */\n        switch (ls->current) {\n          case 'a': c = '\\a'; goto read_save;\n          case 'b': c = '\\b'; goto read_save;\n          case 'f': c = '\\f'; goto read_save;\n          case 'n': c = '\\n'; goto read_save;\n          case 'r': c = '\\r'; goto read_save;\n          case 't': c = '\\t'; goto read_save;\n          case 'v': c = '\\v'; goto read_save;\n          case 'x': c = readhexaesc(ls); goto read_save;\n          case 'u': utf8esc(ls);  goto no_save;\n          case '\\n': case '\\r':\n            inclinenumber(ls); c = '\\n'; goto only_save;\n          case '\\\\': case '\\\"': case '\\'':\n            c = ls->current; goto read_save;\n          case EOZ: goto no_save;  /* will raise an error next loop */\n          case 'z': {  /* zap following span of spaces */\n            luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n            next(ls);  /* skip the 'z' */\n            while (lisspace(ls->current)) {\n              if (currIsNewline(ls)) inclinenumber(ls);\n              else next(ls);\n            }\n            goto no_save;\n          }\n          default: {\n            esccheck(ls, lisdigit(ls->current), \"invalid escape sequence\");\n            c = readdecesc(ls);  /* digital escape '\\ddd' */\n            goto only_save;\n          }\n        }\n       read_save:\n         next(ls);\n         /* go through */\n       only_save:\n         luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n         save(ls, c);\n         /* go through */\n       no_save: break;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n': case '\\r': {  /* line breaks */\n        inclinenumber(ls);\n        break;\n      }\n      case ' ': case '\\f': case '\\t': case '\\v': {  /* spaces */\n        next(ls);\n        break;\n      }\n      case '-': {  /* '-' or '--' (comment) */\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {  /* long comment? */\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* skip long comment */\n            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */\n            break;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);  /* skip until end of line (or end of file) */\n        break;\n      }\n      case '[': {  /* long string or simply '[' */\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep != -1)  /* '[=...' missing second bracket */\n          lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n        return '[';\n      }\n      case '=': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_EQ;\n        else return '=';\n      }\n      case '<': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_LE;\n        else if (check_next1(ls, '<')) return TK_SHL;\n        else return '<';\n      }\n      case '>': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_GE;\n        else if (check_next1(ls, '>')) return TK_SHR;\n        else return '>';\n      }\n      case '/': {\n        next(ls);\n        if (check_next1(ls, '/')) return TK_IDIV;\n        else return '/';\n      }\n      case '~': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_NE;\n        else return '~';\n      }\n      case ':': {\n        next(ls);\n        if (check_next1(ls, ':')) return TK_DBCOLON;\n        else return ':';\n      }\n      case '\"': case '\\'': {  /* short literal strings */\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {  /* '.', '..', '...', or number */\n        save_and_next(ls);\n        if (check_next1(ls, '.')) {\n          if (check_next1(ls, '.'))\n            return TK_DOTS;   /* '...' */\n          else return TK_CONCAT;   /* '..' */\n        }\n        else if (!lisdigit(ls->current)) return '.';\n        else return read_numeral(ls, seminfo);\n      }\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9': {\n        return read_numeral(ls, seminfo);\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (lislalpha(ls->current)) {  /* identifier or reserved word? */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (lislalnum(ls->current));\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          seminfo->ts = ts;\n          if (isreserved(ts))  /* reserved word? */\n            return ts->extra - 1 + FIRST_RESERVED;\n          else {\n            return TK_NAME;\n          }\n        }\n        else {  /* single-char tokens (+ - / ...) */\n          int c = ls->current;\n          next(ls);\n          return c;\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nint luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n  return ls->lookahead.token;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n\n#if !defined(LUA_ENV)\n#define LUA_ENV\t\t\"_ENV\"\n#endif\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,\n  TK_SHL, TK_SHR,\n  TK_DBCOLON, TK_EOS,\n  TK_FLT, TK_INT, TK_NAME, TK_STRING\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\ntypedef union {\n  lua_Number r;\n  lua_Integer i;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\n/* state of the lexer plus state of the parser when shared by all\n   functions */\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token 'consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* current function (parser) */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  Table *h;  /* to avoid collection/reuse strings */\n  struct Dyndata *dyd;  /* dynamic structures used by the parser */\n  TString *source;  /* current source name */\n  TString *envn;  /* environment variable name */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source, int firstchar);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC int luaX_lookahead (LexState *ls);\nLUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $\n** Limits, basic types, and some other 'installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n/*\n** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count\n** the total memory used by Lua (in bytes). Usually, 'size_t' and\n** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.\n*/\n#if defined(LUAI_MEM)\t\t/* { external definitions? */\ntypedef LUAI_UMEM lu_mem;\ntypedef LUAI_MEM l_mem;\n#elif LUAI_BITSINT >= 32\t/* }{ */\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\n#else  /* 16-bit ints */\t/* }{ */\ntypedef unsigned long lu_mem;\ntypedef long l_mem;\n#endif\t\t\t\t/* } */\n\n\n/* chars used as small naturals (so that 'char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n/* maximum size visible for Lua (must be representable in a lua_Integer */\n#define MAX_SIZE\t(sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \\\n                          : (size_t)(LUA_MAXINTEGER))\n\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0))\n\n#define MAX_LMEM\t((l_mem)(MAX_LUMEM >> 1))\n\n\n#define MAX_INT\t\tINT_MAX  /* maximum value of an int */\n\n\n/*\n** conversion of pointer to unsigned integer:\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define point2uint(p)\t((unsigned int)((size_t)(p) & UINT_MAX))\n\n\n\n/* type to ensure maximum alignment */\n#if defined(LUAI_USER_ALIGNMENT_T)\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n#else\ntypedef union {\n  lua_Number n;\n  double u;\n  void *s;\n  lua_Integer i;\n  long l;\n} L_Umaxalign;\n#endif\n\n\n\n/* types of 'usual argument conversions' for lua_Number and lua_Integer */\ntypedef LUAI_UACNUMBER l_uacNumber;\ntypedef LUAI_UACINT l_uacInt;\n\n\n/* internal assertions for in-house debugging */\n#if defined(lua_assert)\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n/* to avoid problems with conditions too long */\n#define lua_longassert(c)\t((c) ? (void)0 : lua_assert(0))\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define lua_longassert(c)\t((void)0)\n#endif\n\n/*\n** assertion for checking API calls\n*/\n#if !defined(luai_apicheck)\n#define luai_apicheck(l,e)\tlua_assert(e)\n#endif\n\n#define api_check(l,e,msg)\tluai_apicheck(l,(e) && msg)\n\n\n/* macro to avoid warnings about unused variables */\n#if !defined(UNUSED)\n#define UNUSED(x)\t((void)(x))\n#endif\n\n\n/* type casts (a macro highlights casts in the code) */\n#define cast(t, exp)\t((t)(exp))\n\n#define cast_void(i)\tcast(void, (i))\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n#define cast_uchar(i)\tcast(unsigned char, (i))\n\n\n/* cast a signed lua_Integer to lua_Unsigned */\n#if !defined(l_castS2U)\n#define l_castS2U(i)\t((lua_Unsigned)(i))\n#endif\n\n/*\n** cast a lua_Unsigned to a signed lua_Integer; this cast is\n** not strict ISO C, but two-complement architectures should\n** work fine.\n*/\n#if !defined(l_castU2S)\n#define l_castU2S(i)\t((lua_Integer)(i))\n#endif\n\n\n/*\n** non-return type\n*/\n#if defined(__GNUC__)\n#define l_noret\t\tvoid __attribute__((noreturn))\n#elif defined(_MSC_VER) && _MSC_VER >= 1200\n#define l_noret\t\tvoid __declspec(noreturn)\n#else\n#define l_noret\t\tvoid\n#endif\n\n\n\n/*\n** maximum depth for nested C calls and syntactical nested non-terminals\n** in a program. (Value must fit in an unsigned short int.)\n*/\n#if !defined(LUAI_MAXCCALLS)\n#define LUAI_MAXCCALLS\t\t200\n#endif\n\n\n\n/*\n** type for virtual-machine instructions;\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\n#if LUAI_BITSINT >= 32\ntypedef unsigned int Instruction;\n#else\ntypedef unsigned long Instruction;\n#endif\n\n\n\n/*\n** Maximum length for short strings, that is, strings that are\n** internalized. (Cannot be smaller than reserved words or tags for\n** metamethods, as these strings must be internalized;\n** #(\"function\") = 8, #(\"__newindex\") = 10.)\n*/\n#if !defined(LUAI_MAXSHORTLEN)\n#define LUAI_MAXSHORTLEN\t40\n#endif\n\n\n/*\n** Initial size for the string table (must be power of 2).\n** The Lua core alone registers ~50 strings (reserved words +\n** metaevent keys + a few others). Libraries would typically add\n** a few dozens more.\n*/\n#if !defined(MINSTRTABSIZE)\n#define MINSTRTABSIZE\t128\n#endif\n\n\n/*\n** Size of cache for strings in the API. 'N' is the number of\n** sets (better be a prime) and \"M\" is the size of each set (M == 1\n** makes a direct cache.)\n*/\n#if !defined(STRCACHE_N)\n#define STRCACHE_N\t\t53\n#define STRCACHE_M\t\t2\n#endif\n\n\n/* minimum size for string buffer */\n#if !defined(LUA_MINBUFFER)\n#define LUA_MINBUFFER\t32\n#endif\n\n\n/*\n** macros that are executed whenever program enters the Lua core\n** ('lua_lock') and leaves the core ('lua_unlock')\n*/\n#if !defined(lua_lock)\n#define lua_lock(L)\t((void) 0)\n#define lua_unlock(L)\t((void) 0)\n#endif\n\n/*\n** macro executed during Lua functions at points where the\n** function can yield.\n*/\n#if !defined(luai_threadyield)\n#define luai_threadyield(L)\t{lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** these macros allow user-specific actions on threads when you defined\n** LUAI_EXTRASPACE and need to do something extra when a thread is\n** created/deleted/resumed/yielded.\n*/\n#if !defined(luai_userstateopen)\n#define luai_userstateopen(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstateclose)\n#define luai_userstateclose(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstatethread)\n#define luai_userstatethread(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstatefree)\n#define luai_userstatefree(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstateresume)\n#define luai_userstateresume(L,n)\t((void)L)\n#endif\n\n#if !defined(luai_userstateyield)\n#define luai_userstateyield(L,n)\t((void)L)\n#endif\n\n\n\n/*\n** The luai_num* macros define the primitive operations over numbers.\n*/\n\n/* floor division (defined as 'floor(a/b)') */\n#if !defined(luai_numidiv)\n#define luai_numidiv(L,a,b)     ((void)L, l_floor(luai_numdiv(L,a,b)))\n#endif\n\n/* float division */\n#if !defined(luai_numdiv)\n#define luai_numdiv(L,a,b)      ((a)/(b))\n#endif\n\n/*\n** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when\n** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of\n** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)\n** ~= floor(a/b)'. That happens when the division has a non-integer\n** negative result, which is equivalent to the test below.\n*/\n#if !defined(luai_nummod)\n#define luai_nummod(L,a,b,m)  \\\n  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }\n#endif\n\n/* exponentiation */\n#if !defined(luai_numpow)\n#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))\n#endif\n\n/* the others are quite standard operations */\n#if !defined(luai_numadd)\n#define luai_numadd(L,a,b)      ((a)+(b))\n#define luai_numsub(L,a,b)      ((a)-(b))\n#define luai_nummul(L,a,b)      ((a)*(b))\n#define luai_numunm(L,a)        (-(a))\n#define luai_numeq(a,b)         ((a)==(b))\n#define luai_numlt(a,b)         ((a)<(b))\n#define luai_numle(a,b)         ((a)<=(b))\n#define luai_numisnan(a)        (!luai_numeq((a), (a)))\n#endif\n\n\n\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/\n#if !defined(HARDSTACKTESTS)\n#define condmovestack(L,pre,pos)\t((void)0)\n#else\n/* realloc stack keeping its size */\n#define condmovestack(L,pre,pos)  \\\n\t{ int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; }\n#endif\n\n#if !defined(HARDMEMTESTS)\n#define condchangemem(L,pre,pos)\t((void)0)\n#else\n#define condchangemem(L,pre,pos)  \\\n\t{ if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI\t(l_mathop(3.141592653589793238462643383279502884))\n\n\n#if !defined(l_rand)\t\t/* { */\n#if defined(LUA_USE_POSIX)\n#define l_rand()\trandom()\n#define l_srand(x)\tsrandom(x)\n#define L_RANDMAX\t2147483647\t/* (2^31 - 1), following POSIX */\n#else\n#define l_rand()\trand()\n#define l_srand(x)\tsrand(x)\n#define L_RANDMAX\tRAND_MAX\n#endif\n#endif\t\t\t\t/* } */\n\n\nstatic int math_abs (lua_State *L) {\n  if (lua_isinteger(L, 1)) {\n    lua_Integer n = lua_tointeger(L, 1);\n    if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);\n    lua_pushinteger(L, n);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_Number y = luaL_checknumber(L, 1);\n  lua_Number x = luaL_optnumber(L, 2, 1);\n  lua_pushnumber(L, l_mathop(atan2)(y, x));\n  return 1;\n}\n\n\nstatic int math_toint (lua_State *L) {\n  int valid;\n  lua_Integer n = lua_tointegerx(L, 1, &valid);\n  if (valid)\n    lua_pushinteger(L, n);\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);  /* value is not convertible to integer */\n  }\n  return 1;\n}\n\n\nstatic void pushnumint (lua_State *L, lua_Number d) {\n  lua_Integer n;\n  if (lua_numbertointeger(d, &n))  /* does 'd' fit in an integer? */\n    lua_pushinteger(L, n);  /* result is integer */\n  else\n    lua_pushnumber(L, d);  /* result is float */\n}\n\n\nstatic int math_floor (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own floor */\n  else {\n    lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_ceil (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own ceil */\n  else {\n    lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_fmod (lua_State *L) {\n  if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) {\n    lua_Integer d = lua_tointeger(L, 2);\n    if ((lua_Unsigned)d + 1u <= 1u) {  /* special cases: -1 or 0 */\n      luaL_argcheck(L, d != 0, 2, \"zero\");\n      lua_pushinteger(L, 0);  /* avoid overflow with 0x80000... / -1 */\n    }\n    else\n      lua_pushinteger(L, lua_tointeger(L, 1) % d);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),\n                                     luaL_checknumber(L, 2)));\n  return 1;\n}\n\n\n/*\n** next function does not use 'modf', avoiding problems with 'double*'\n** (which is not compatible with 'float*') when lua_Number is not\n** 'double'.\n*/\nstatic int math_modf (lua_State *L) {\n  if (lua_isinteger(L ,1)) {\n    lua_settop(L, 1);  /* number is its own integer part */\n    lua_pushnumber(L, 0);  /* no fractional part */\n  }\n  else {\n    lua_Number n = luaL_checknumber(L, 1);\n    /* integer part (rounds toward zero) */\n    lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);\n    pushnumint(L, ip);\n    /* fractional part (test needed for inf/-inf) */\n    lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));\n  }\n  return 2;\n}\n\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n\nstatic int math_ult (lua_State *L) {\n  lua_Integer a = luaL_checkinteger(L, 1);\n  lua_Integer b = luaL_checkinteger(L, 2);\n  lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b);\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number res;\n  if (lua_isnoneornil(L, 2))\n    res = l_mathop(log)(x);\n  else {\n    lua_Number base = luaL_checknumber(L, 2);\n    if (base == 10.0) res = l_mathop(log10)(x);\n    else res = l_mathop(log)(x)/l_mathop(log)(base);\n  }\n  lua_pushnumber(L, res);\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));\n  return 1;\n}\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imin = 1;  /* index of current minimum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, i, imin, LUA_OPLT))\n      imin = i;\n  }\n  lua_pushvalue(L, imin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imax = 1;  /* index of current maximum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, imax, i, LUA_OPLT))\n      imax = i;\n  }\n  lua_pushvalue(L, imax);\n  return 1;\n}\n\n/*\n** This function uses 'double' (instead of 'lua_Number') to ensure that\n** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0'\n** will keep full precision (ensuring that 'r' is always less than 1.0.)\n*/\nstatic int math_random (lua_State *L) {\n  lua_Integer low, up;\n  double r = (double)l_rand() * (1.0 / ((double)L_RANDMAX + 1.0));\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, (lua_Number)r);  /* Number between 0 and 1 */\n      return 1;\n    }\n    case 1: {  /* only upper limit */\n      low = 1;\n      up = luaL_checkinteger(L, 1);\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      low = luaL_checkinteger(L, 1);\n      up = luaL_checkinteger(L, 2);\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  /* random integer in the interval [low, up] */\n  luaL_argcheck(L, low <= up, 1, \"interval is empty\"); \n  luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,\n                   \"interval too large\");\n  r *= (double)(up - low) + 1.0;\n  lua_pushinteger(L, (lua_Integer)r + low);\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));\n  (void)l_rand(); /* discard first value to avoid undesirable correlations */\n  return 0;\n}\n\n\nstatic int math_type (lua_State *L) {\n  if (lua_type(L, 1) == LUA_TNUMBER) {\n      if (lua_isinteger(L, 1))\n        lua_pushliteral(L, \"integer\"); \n      else\n        lua_pushliteral(L, \"float\"); \n  }\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);\n  }\n  return 1;\n}\n\n\n/*\n** {==================================================================\n** Deprecated functions (for compatibility only)\n** ===================================================================\n*/\n#if defined(LUA_COMPAT_MATHLIB)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number y = luaL_checknumber(L, 2);\n  lua_pushnumber(L, l_mathop(pow)(x, y));\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  int ep = (int)luaL_checkinteger(L, 2);\n  lua_pushnumber(L, l_mathop(ldexp)(x, ep));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n#endif\n/* }================================================================== */\n\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"tointeger\", math_toint},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"ult\",   math_ult},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tan\",   math_tan},\n  {\"type\", math_type},\n#if defined(LUA_COMPAT_MATHLIB)\n  {\"atan2\", math_atan},\n  {\"cosh\",   math_cosh},\n  {\"sinh\",   math_sinh},\n  {\"tanh\",   math_tanh},\n  {\"pow\",   math_pow},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n#endif\n  /* placeholders */\n  {\"pi\", NULL},\n  {\"huge\", NULL},\n  {\"maxinteger\", NULL},\n  {\"mininteger\", NULL},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUAMOD_API int luaopen_math (lua_State *L) {\n  luaL_newlib(L, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, (lua_Number)HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n  lua_pushinteger(L, LUA_MAXINTEGER);\n  lua_setfield(L, -2, \"maxinteger\");\n  lua_pushinteger(L, LUA_MININTEGER);\n  lua_setfield(L, -2, \"mininteger\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** ('osize' is the old size, 'nsize' is the new size)\n**\n** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no\n** matter 'x').\n**\n** * frealloc(ud, p, x, 0) frees the block 'p'\n** (in this specific case, frealloc must return NULL);\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ISO C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *what) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, \"too many %s (limit is %d)\", what, limit);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nl_noret luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  void *newblock;\n  global_State *g = G(L);\n  size_t realosize = (block) ? osize : 0;\n  lua_assert((realosize == 0) == (block == NULL));\n#if defined(HARDMEMTESTS)\n  if (nsize > realosize && g->gcrunning)\n    luaC_fullgc(L, 1);  /* force a GC whenever possible */\n#endif\n  newblock = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (newblock == NULL && nsize > 0) {\n    lua_assert(nsize > realosize);  /* cannot fail when shrinking a block */\n    if (g->version) {  /* is state fully built? */\n      luaC_fullgc(L, 1);  /* try to free some memory... */\n      newblock = (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */\n    }\n    if (newblock == NULL)\n      luaD_throw(L, LUA_ERRMEM);\n  }\n  lua_assert((nsize == 0) == (newblock == NULL));\n  g->GCdebt = (g->GCdebt + nsize) - realosize;\n  return newblock;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** This macro reallocs a vector 'b' from 'on' to 'n' elements, where\n** each element has size 'e'. In case of arithmetic overflow of the\n** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because\n** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e).\n**\n** (The macro is somewhat complex to avoid warnings:  The 'sizeof'\n** comparison avoids a runtime comparison when overflow cannot occur.\n** The compiler should be able to optimize the real test by itself, but\n** when it does it, it may give a warning about \"comparison is always\n** false due to limited range of data type\"; the +1 tricks the compiler,\n** avoiding this warning but also this optimization.)\n*/\n#define luaM_reallocv(L,b,on,n,e) \\\n  (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \\\n      ? luaM_toobig(L) : cast_void(0)) , \\\n   luaM_realloc_(L, (b), (on)*(e), (n)*(e)))\n\n/*\n** Arrays of chars do not need any test\n*/\n#define luaM_reallocvchar(L,b,on,n)  \\\n    cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n)   luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0)\n\n#define luaM_malloc(L,s)\tluaM_realloc_(L, NULL, 0, (s))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_newobject(L,tag,s)\tluaM_realloc_(L, NULL, tag, (s))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\nLUAI_FUNC l_noret luaM_toobig (lua_State *L);\n\n/* not to be called directly */\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *what);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.127 2015/11/23 11:30:45 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR\t\"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR\t\"LUA_CPATH\"\n#endif\n\n#define LUA_PATHSUFFIX\t\t\"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n#define LUA_PATHVARVERSION\t\tLUA_PATH_VAR LUA_PATHSUFFIX\n#define LUA_CPATHVARVERSION\t\tLUA_CPATH_VAR LUA_PATHSUFFIX\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_PATH_SEP)\n#define LUA_PATH_SEP\t\t\";\"\n#endif\n#if !defined (LUA_PATH_MARK)\n#define LUA_PATH_MARK\t\t\"?\"\n#endif\n#if !defined (LUA_EXEC_DIR)\n#define LUA_EXEC_DIR\t\t\"!\"\n#endif\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** unique key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const int CLIBS = 0;\n\n#define LIB_FAIL\t\"open\"\n\n#define setprogdir(L)\t\t((void)0)\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n#undef setprogdir\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\n\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATH_SEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATH_SEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n                                     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file '%s'\", filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"\\n\\tno module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_PRELOAD\");\n  if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else\n      lua_pop(L, 2);  /* remove both returns */\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* _LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, 2, name);  /* _LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_pushstring(L, name);  /* pass name as argument to module loader */\n  lua_insert(L, -2);  /* name is 1st argument (before search data) */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\n/*\n** changes the environment variable of calling function\n*/\nstatic void set_env (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, \"'module' not called from a Lua function\");\n  lua_pushvalue(L, -2);  /* copy new environment table to top */\n  lua_setupvalue(L, -2, 1);\n  lua_pop(L, 1);  /* remove function */\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    if (lua_isfunction(L, i)) {  /* avoid 'calling' extra info. */\n      lua_pushvalue(L, i);  /* get option (a function) */\n      lua_pushvalue(L, -2);  /* module */\n      lua_call(L, 1, 0);\n    }\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = lua_gettop(L);  /* last parameter */\n  luaL_pushmodule(L, modname, 1);  /* get/create module table */\n  /* check whether table already has a _NAME field */\n  if (lua_getfield(L, -1, \"_NAME\") != LUA_TNIL)\n    lua_pop(L, 1);  /* table is an initialized module */\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  set_env(L);\n  dooptions(L, lastarg);\n  return 1;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushglobaltable(L);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n#endif\n/* }====================================================== */\n\n\n\n/* auxiliary mark (for internal use) */\n#define AUXMARK\t\t\"\\1\"\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\nstatic void setpath (lua_State *L, const char *fieldname, const char *envname1,\n                                   const char *envname2, const char *def) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(envname1);\n  if (path == NULL)  /* no environment variable? */\n    path = getenv(envname2);  /* try alternative name */\n#endif\n\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, def);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,\n                              LUA_PATH_SEP AUXMARK LUA_PATH_SEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n#if defined(LUA_COMPAT_MODULE)\n  {\"seeall\", ll_seeall},\n#endif\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n#if defined(LUA_COMPAT_MODULE)\n  {\"module\", ll_module},\n#endif\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if defined(LUA_COMPAT_LOADERS)\n  lua_pushvalue(L, -1);  /* make a copy of 'searchers' table */\n  lua_setfield(L, -3, \"loaders\");  /* put it in field 'loaders' */\n#endif\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  lua_newtable(L);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n  lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set field 'path' */\n  setpath(L, \"path\", LUA_PATHVARVERSION, LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  /* set field 'cpath' */\n  setpath(L, \"cpath\", LUA_CPATHVARVERSION, LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\");\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/loadlib_rel.c",
    "content": "/*\n** $Id: loadlib.c,v 1.127 2015/11/23 11:30:45 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR\t\"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR\t\"LUA_CPATH\"\n#endif\n\n#define LUA_PATHSUFFIX\t\t\"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n#define LUA_PATHVARVERSION\t\tLUA_PATH_VAR LUA_PATHSUFFIX\n#define LUA_CPATHVARVERSION\t\tLUA_CPATH_VAR LUA_PATHSUFFIX\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_PATH_SEP)\n#define LUA_PATH_SEP\t\t\";\"\n#endif\n#if !defined (LUA_PATH_MARK)\n#define LUA_PATH_MARK\t\t\"?\"\n#endif\n#if !defined (LUA_EXEC_DIR)\n#define LUA_EXEC_DIR\t\t\"!\"\n#endif\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** unique key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const int CLIBS = 0;\n\n#define LIB_FAIL\t\"open\"\n\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n/*\n** {=========================================================================\n** This determines the location of the executable for relative module loading\n** Modified by the LuaDist project for UNIX platforms\n** ==========================================================================\n*/\n#if defined(_WIN32)\n  #include <windows.h>\n  #define _PATH_MAX MAX_PATH\n#else\n  #define _PATH_MAX PATH_MAX\n#endif\n\n#if defined (__CYGWIN__)\n  #include <sys/cygwin.h>\n#endif\n\n#if defined(__linux__) || defined(__sun)\n  #include <unistd.h> /* readlink */\n#endif\n\n#if defined(__APPLE__)\n  #include <sys/param.h>\n  #include <mach-o/dyld.h>\n#endif\n\n#if defined(__FreeBSD__)\n  #include <sys/types.h>\n  #include <sys/sysctl.h>\n#endif\n\nstatic void setprogdir(lua_State *L) {\n  char progdir[_PATH_MAX + 1];\n  char *lb;\n  int nsize = sizeof(progdir)/sizeof(char);\n  int n = 0;\n#if defined(__CYGWIN__)\n  char win_buff[_PATH_MAX + 1];\n  GetModuleFileNameA(NULL, win_buff, nsize);\n  cygwin_conv_path(CCP_WIN_A_TO_POSIX, win_buff, progdir, nsize);\n  n = strlen(progdir);\n#elif defined(_WIN32)\n  n = GetModuleFileNameA(NULL, progdir, nsize);\n#elif defined(__linux__)\n  n = readlink(\"/proc/self/exe\", progdir, nsize);\n  if (n > 0) progdir[n] = 0;\n#elif defined(__sun)\n  pid_t pid = getpid();\n  char linkname[256];\n  sprintf(linkname, \"/proc/%d/path/a.out\", pid);\n  n = readlink(linkname, progdir, nsize);\n  if (n > 0) progdir[n] = 0;  \n#elif defined(__FreeBSD__)\n  int mib[4];\n  mib[0] = CTL_KERN;\n  mib[1] = KERN_PROC;\n  mib[2] = KERN_PROC_PATHNAME;\n  mib[3] = -1;\n  size_t cb = nsize;\n  sysctl(mib, 4, progdir, &cb, NULL, 0);\n  n = cb;\n#elif defined(__BSD__)\n  n = readlink(\"/proc/curproc/file\", progdir, nsize);\n  if (n > 0) progdir[n] = 0;\n#elif defined(__APPLE__)\n  uint32_t nsize_apple = nsize;\n  if (_NSGetExecutablePath(progdir, &nsize_apple) == 0)\n    n = strlen(progdir);\n#else\n  // FALLBACK\n  // Use 'lsof' ... should work on most UNIX systems (incl. OSX)\n  // lsof will list open files, this captures the 1st file listed (usually the executable)\n  int pid;\n  FILE* fd;\n  char cmd[80];\n  pid = getpid();\n\n  sprintf(cmd, \"lsof -p %d | awk '{if ($5==\\\"REG\\\") { print $9 ; exit}}' 2> /dev/null\", pid);\n  fd = popen(cmd, \"r\");\n  n = fread(progdir, 1, nsize, fd);\n  pclose(fd);\n\n  // remove newline\n  if (n > 1) progdir[--n] = '\\0';\n#endif\n  if (n == 0 || n == nsize || (lb = strrchr(progdir, (int)LUA_DIRSEP[0])) == NULL)\n    luaL_error(L, \"unable to get process executable path\");\n  else {\n    *lb = '\\0';\n    \n    // Replace the relative path placeholder\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, progdir);\n    lua_remove(L, -2);\n  }\n}\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATH_SEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATH_SEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n                                     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file '%s'\", filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"\\n\\tno module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_PRELOAD\");\n  if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else\n      lua_pop(L, 2);  /* remove both returns */\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* _LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, 2, name);  /* _LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_pushstring(L, name);  /* pass name as argument to module loader */\n  lua_insert(L, -2);  /* name is 1st argument (before search data) */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\n/*\n** changes the environment variable of calling function\n*/\nstatic void set_env (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, \"'module' not called from a Lua function\");\n  lua_pushvalue(L, -2);  /* copy new environment table to top */\n  lua_setupvalue(L, -2, 1);\n  lua_pop(L, 1);  /* remove function */\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    if (lua_isfunction(L, i)) {  /* avoid 'calling' extra info. */\n      lua_pushvalue(L, i);  /* get option (a function) */\n      lua_pushvalue(L, -2);  /* module */\n      lua_call(L, 1, 0);\n    }\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = lua_gettop(L);  /* last parameter */\n  luaL_pushmodule(L, modname, 1);  /* get/create module table */\n  /* check whether table already has a _NAME field */\n  if (lua_getfield(L, -1, \"_NAME\") != LUA_TNIL)\n    lua_pop(L, 1);  /* table is an initialized module */\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  set_env(L);\n  dooptions(L, lastarg);\n  return 1;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushglobaltable(L);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n#endif\n/* }====================================================== */\n\n\n\n/* auxiliary mark (for internal use) */\n#define AUXMARK\t\t\"\\1\"\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\nstatic void setpath (lua_State *L, const char *fieldname, const char *envname1,\n                                   const char *envname2, const char *def) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(envname1);\n  if (path == NULL)  /* no environment variable? */\n    path = getenv(envname2);  /* try alternative name */\n#endif\n\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, def);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,\n                              LUA_PATH_SEP AUXMARK LUA_PATH_SEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n#if defined(LUA_COMPAT_MODULE)\n  {\"seeall\", ll_seeall},\n#endif\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n#if defined(LUA_COMPAT_MODULE)\n  {\"module\", ll_module},\n#endif\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if defined(LUA_COMPAT_LOADERS)\n  lua_pushvalue(L, -1);  /* make a copy of 'searchers' table */\n  lua_setfield(L, -3, \"loaders\");  /* put it in field 'loaders' */\n#endif\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  lua_newtable(L);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n  lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set field 'path' */\n  setpath(L, \"path\", LUA_PATHVARVERSION, LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  /* set field 'cpath' */\n  setpath(L, \"cpath\", LUA_CPATHVARVERSION, LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\");\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.111 2016/05/20 14:07:48 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nLUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* exponent */\n  if (x < 8) return x;\n  while (x >= (8 << 4)) {  /* coarse steps */\n    x = (x + 0xf) >> 4;  /* x = ceil(x / 16) */\n    e += 4;\n  }\n  while (x >= (8 << 1)) {  /* fine steps */\n    x = (x + 1) >> 1;  /* x = ceil(x / 2) */\n    e++;\n  }\n  return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);\n}\n\n\n/*\n** Computes ceil(log2(x))\n*/\nint luaO_ceillog2 (unsigned int x) {\n  static const lu_byte log_2[256] = {  /* log_2[i] = ceil(log2(i - 1)) */\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = 0;\n  x--;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n}\n\n\nstatic lua_Integer intarith (lua_State *L, int op, lua_Integer v1,\n                                                   lua_Integer v2) {\n  switch (op) {\n    case LUA_OPADD: return intop(+, v1, v2);\n    case LUA_OPSUB:return intop(-, v1, v2);\n    case LUA_OPMUL:return intop(*, v1, v2);\n    case LUA_OPMOD: return luaV_mod(L, v1, v2);\n    case LUA_OPIDIV: return luaV_div(L, v1, v2);\n    case LUA_OPBAND: return intop(&, v1, v2);\n    case LUA_OPBOR: return intop(|, v1, v2);\n    case LUA_OPBXOR: return intop(^, v1, v2);\n    case LUA_OPSHL: return luaV_shiftl(v1, v2);\n    case LUA_OPSHR: return luaV_shiftl(v1, -v2);\n    case LUA_OPUNM: return intop(-, 0, v1);\n    case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lua_Number numarith (lua_State *L, int op, lua_Number v1,\n                                                  lua_Number v2) {\n  switch (op) {\n    case LUA_OPADD: return luai_numadd(L, v1, v2);\n    case LUA_OPSUB: return luai_numsub(L, v1, v2);\n    case LUA_OPMUL: return luai_nummul(L, v1, v2);\n    case LUA_OPDIV: return luai_numdiv(L, v1, v2);\n    case LUA_OPPOW: return luai_numpow(L, v1, v2);\n    case LUA_OPIDIV: return luai_numidiv(L, v1, v2);\n    case LUA_OPUNM: return luai_numunm(L, v1);\n    case LUA_OPMOD: {\n      lua_Number m;\n      luai_nummod(L, v1, v2, m);\n      return m;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                 TValue *res) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR:\n    case LUA_OPBNOT: {  /* operate only on integers */\n      lua_Integer i1; lua_Integer i2;\n      if (tointeger(p1, &i1) && tointeger(p2, &i2)) {\n        setivalue(res, intarith(L, op, i1, i2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    case LUA_OPDIV: case LUA_OPPOW: {  /* operate only on floats */\n      lua_Number n1; lua_Number n2;\n      if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    default: {  /* other operations */\n      lua_Number n1; lua_Number n2;\n      if (ttisinteger(p1) && ttisinteger(p2)) {\n        setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));\n        return;\n      }\n      else if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n  }\n  /* could not perform raw operation; try metamethod */\n  lua_assert(L != NULL);  /* should not fail when folding (compile time) */\n  luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));\n}\n\n\nint luaO_hexavalue (int c) {\n  if (lisdigit(c)) return c - '0';\n  else return (ltolower(c) - 'a') + 10;\n}\n\n\nstatic int isneg (const char **s) {\n  if (**s == '-') { (*s)++; return 1; }\n  else if (**s == '+') (*s)++;\n  return 0;\n}\n\n\n\n/*\n** {==================================================================\n** Lua's implementation for 'lua_strx2number'\n** ===================================================================\n*/\n\n#if !defined(lua_strx2number)\n\n/* maximum number of significant digits to read (to avoid overflows\n   even with single floats) */\n#define MAXSIGDIG\t30\n\n/*\n** convert an hexadecimal numeric string to a number, following\n** C99 specification for 'strtod'\n*/\nstatic lua_Number lua_strx2number (const char *s, char **endptr) {\n  int dot = lua_getlocaledecpoint();\n  lua_Number r = 0.0;  /* result (accumulator) */\n  int sigdig = 0;  /* number of significant digits */\n  int nosigdig = 0;  /* number of non-significant digits */\n  int e = 0;  /* exponent correction */\n  int neg;  /* 1 if number is negative */\n  int hasdot = 0;  /* true after seen a dot */\n  *endptr = cast(char *, s);  /* nothing is valid yet */\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);  /* check signal */\n  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */\n    return 0.0;  /* invalid format (no '0x') */\n  for (s += 2; ; s++) {  /* skip '0x' and read numeral */\n    if (*s == dot) {\n      if (hasdot) break;  /* second dot? stop loop */\n      else hasdot = 1;\n    }\n    else if (lisxdigit(cast_uchar(*s))) {\n      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */\n        nosigdig++;\n      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */\n          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);\n      else e++; /* too many digits; ignore, but still count for exponent */\n      if (hasdot) e--;  /* decimal digit? correct exponent */\n    }\n    else break;  /* neither a dot nor a digit */\n  }\n  if (nosigdig + sigdig == 0)  /* no digits? */\n    return 0.0;  /* invalid format */\n  *endptr = cast(char *, s);  /* valid up to here */\n  e *= 4;  /* each digit multiplies/divides value by 2^4 */\n  if (*s == 'p' || *s == 'P') {  /* exponent part? */\n    int exp1 = 0;  /* exponent value */\n    int neg1;  /* exponent signal */\n    s++;  /* skip 'p' */\n    neg1 = isneg(&s);  /* signal */\n    if (!lisdigit(cast_uchar(*s)))\n      return 0.0;  /* invalid; must have at least one digit */\n    while (lisdigit(cast_uchar(*s)))  /* read exponent */\n      exp1 = exp1 * 10 + *(s++) - '0';\n    if (neg1) exp1 = -exp1;\n    e += exp1;\n    *endptr = cast(char *, s);  /* valid up to here */\n  }\n  if (neg) r = -r;\n  return l_mathop(ldexp)(r, e);\n}\n\n#endif\n/* }====================================================== */\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM\t200\n#endif\n\nstatic const char *l_str2dloc (const char *s, lua_Number *result, int mode) {\n  char *endptr;\n  *result = (mode == 'x') ? lua_strx2number(s, &endptr)  /* try to convert */\n                          : lua_str2number(s, &endptr);\n  if (endptr == s) return NULL;  /* nothing recognized? */\n  while (lisspace(cast_uchar(*endptr))) endptr++;  /* skip trailing spaces */\n  return (*endptr == '\\0') ? endptr : NULL;  /* OK if no trailing characters */\n}\n\n\n/*\n** Convert string 's' to a Lua number (put in 'result'). Return NULL\n** on fail or the address of the ending '\\0' on success.\n** 'pmode' points to (and 'mode' contains) special things in the string:\n** - 'x'/'X' means an hexadecimal numeral\n** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)\n** - '.' just optimizes the search for the common case (nothing special)\n** This function accepts both the current locale or a dot as the radix\n** mark. If the convertion fails, it may mean number has a dot but\n** locale accepts something else. In that case, the code copies 's'\n** to a buffer (because 's' is read-only), changes the dot to the\n** current locale radix mark, and tries to convert again.\n*/\nstatic const char *l_str2d (const char *s, lua_Number *result) {\n  const char *endptr;\n  const char *pmode = strpbrk(s, \".xXnN\");\n  int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;\n  if (mode == 'n')  /* reject 'inf' and 'nan' */\n    return NULL;\n  endptr = l_str2dloc(s, result, mode);  /* try to convert */\n  if (endptr == NULL) {  /* failed? may be a different locale */\n    char buff[L_MAXLENNUM + 1];\n    char *pdot = strchr(s, '.');\n    if (strlen(s) > L_MAXLENNUM || pdot == NULL)\n      return NULL;  /* string too long or no dot; fail */\n    strcpy(buff, s);  /* copy string to buffer */\n    buff[pdot - s] = lua_getlocaledecpoint();  /* correct decimal point */\n    endptr = l_str2dloc(buff, result, mode);  /* try again */\n    if (endptr != NULL)\n      endptr = s + (endptr - buff);  /* make relative to 's' */\n  }\n  return endptr;\n}\n\n\n#define MAXBY10\t\tcast(lua_Unsigned, LUA_MAXINTEGER / 10)\n#define MAXLASTD\tcast_int(LUA_MAXINTEGER % 10)\n\nstatic const char *l_str2int (const char *s, lua_Integer *result) {\n  lua_Unsigned a = 0;\n  int empty = 1;\n  int neg;\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);\n  if (s[0] == '0' &&\n      (s[1] == 'x' || s[1] == 'X')) {  /* hex? */\n    s += 2;  /* skip '0x' */\n    for (; lisxdigit(cast_uchar(*s)); s++) {\n      a = a * 16 + luaO_hexavalue(*s);\n      empty = 0;\n    }\n  }\n  else {  /* decimal */\n    for (; lisdigit(cast_uchar(*s)); s++) {\n      int d = *s - '0';\n      if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg))  /* overflow? */\n        return NULL;  /* do not accept it (as integer) */\n      a = a * 10 + d;\n      empty = 0;\n    }\n  }\n  while (lisspace(cast_uchar(*s))) s++;  /* skip trailing spaces */\n  if (empty || *s != '\\0') return NULL;  /* something wrong in the numeral */\n  else {\n    *result = l_castU2S((neg) ? 0u - a : a);\n    return s;\n  }\n}\n\n\nsize_t luaO_str2num (const char *s, TValue *o) {\n  lua_Integer i; lua_Number n;\n  const char *e;\n  if ((e = l_str2int(s, &i)) != NULL) {  /* try as an integer */\n    setivalue(o, i);\n  }\n  else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */\n    setfltvalue(o, n);\n  }\n  else\n    return 0;  /* conversion failed */\n  return (e - s) + 1;  /* success; return string size */\n}\n\n\nint luaO_utf8esc (char *buff, unsigned long x) {\n  int n = 1;  /* number of bytes put in buffer (backwards) */\n  lua_assert(x <= 0x10FFFF);\n  if (x < 0x80)  /* ascii? */\n    buff[UTF8BUFFSZ - 1] = cast(char, x);\n  else {  /* need continuation bytes */\n    unsigned int mfb = 0x3f;  /* maximum that fits in first byte */\n    do {  /* add continuation bytes */\n      buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));\n      x >>= 6;  /* remove added bits */\n      mfb >>= 1;  /* now there is one less bit available in first byte */\n    } while (x > mfb);  /* still needs continuation byte? */\n    buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x);  /* add first byte */\n  }\n  return n;\n}\n\n\n/* maximum length of the conversion of a number to a string */\n#define MAXNUMBER2STR\t50\n\n\n/*\n** Convert a number object to a string\n*/\nvoid luaO_tostring (lua_State *L, StkId obj) {\n  char buff[MAXNUMBER2STR];\n  size_t len;\n  lua_assert(ttisnumber(obj));\n  if (ttisinteger(obj))\n    len = lua_integer2str(buff, sizeof(buff), ivalue(obj));\n  else {\n    len = lua_number2str(buff, sizeof(buff), fltvalue(obj));\n#if !defined(LUA_COMPAT_FLOATSTRING)\n    if (buff[strspn(buff, \"-0123456789\")] == '\\0') {  /* looks like an int? */\n      buff[len++] = lua_getlocaledecpoint();\n      buff[len++] = '0';  /* adds '.0' to result */\n    }\n#endif\n  }\n  setsvalue2s(L, obj, luaS_newlstr(L, buff, len));\n}\n\n\nstatic void pushstr (lua_State *L, const char *str, size_t l) {\n  setsvalue2s(L, L->top, luaS_newlstr(L, str, l));\n  luaD_inctop(L);\n}\n\n\n/*\n** this function handles only '%d', '%c', '%f', '%p', and '%s' \n   conventional formats, plus Lua-specific '%I' and '%U'\n*/\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 0;\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    pushstr(L, fmt, e - fmt);\n    switch (*(e+1)) {\n      case 's': {  /* zero-terminated string */\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s, strlen(s));\n        break;\n      }\n      case 'c': {  /* an 'int' as a character */\n        char buff = cast(char, va_arg(argp, int));\n        if (lisprint(cast_uchar(buff)))\n          pushstr(L, &buff, 1);\n        else  /* non-printable character; print its code */\n          luaO_pushfstring(L, \"<\\\\%d>\", cast_uchar(buff));\n        break;\n      }\n      case 'd': {  /* an 'int' */\n        setivalue(L->top, va_arg(argp, int));\n        goto top2str;\n      }\n      case 'I': {  /* a 'lua_Integer' */\n        setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));\n        goto top2str;\n      }\n      case 'f': {  /* a 'lua_Number' */\n        setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n      top2str:  /* convert the top element to a string */\n        luaD_inctop(L);\n        luaO_tostring(L, L->top - 1);\n        break;\n      }\n      case 'p': {  /* a pointer */\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */\n        int l = l_sprintf(buff, sizeof(buff), \"%p\", va_arg(argp, void *));\n        pushstr(L, buff, l);\n        break;\n      }\n      case 'U': {  /* an 'int' as a UTF-8 sequence */\n        char buff[UTF8BUFFSZ];\n        int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));\n        pushstr(L, buff + UTF8BUFFSZ - l, l);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\", 1);\n        break;\n      }\n      default: {\n        luaG_runerror(L, \"invalid option '%%%c' to 'lua_pushfstring'\",\n                         *(e + 1));\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  luaD_checkstack(L, 1);\n  pushstr(L, fmt, strlen(fmt));\n  if (n > 0) luaV_concat(L, n + 1);\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\n/* number of chars of a literal string without the ending \\0 */\n#define LL(x)\t(sizeof(x)/sizeof(char) - 1)\n\n#define RETS\t\"...\"\n#define PRE\t\"[string \\\"\"\n#define POS\t\"\\\"]\"\n\n#define addstr(a,b,l)\t( memcpy(a,b,(l) * sizeof(char)), a += (l) )\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  size_t l = strlen(source);\n  if (*source == '=') {  /* 'literal' source */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* truncate it */\n      addstr(out, source + 1, bufflen - 1);\n      *out = '\\0';\n    }\n  }\n  else if (*source == '@') {  /* file name */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* add '...' before rest of name */\n      addstr(out, RETS, LL(RETS));\n      bufflen -= LL(RETS);\n      memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));\n    }\n  }\n  else {  /* string; format as [string \"source\"] */\n    const char *nl = strchr(source, '\\n');  /* find first new line (if any) */\n    addstr(out, PRE, LL(PRE));  /* add prefix */\n    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\\0' */\n    if (l < bufflen && nl == NULL) {  /* small one-line source? */\n      addstr(out, source, l);  /* keep it */\n    }\n    else {\n      if (nl != NULL) l = nl - source;  /* stop at first newline */\n      if (l > bufflen) l = bufflen;\n      addstr(out, source, l);\n      addstr(out, RETS, LL(RETS));\n    }\n    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.116 2015/11/03 18:33:10 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\tLUA_NUMTAGS\t\t/* function prototypes */\n#define LUA_TDEADKEY\t(LUA_NUMTAGS+1)\t\t/* removed keys in tables */\n\n/*\n** number of all possible tags (including LUA_TNONE but excluding DEADKEY)\n*/\n#define LUA_TOTALTAGS\t(LUA_TPROTO + 2)\n\n\n/*\n** tags for Tagged Values have the following use of bits:\n** bits 0-3: actual tag (a LUA_T* value)\n** bits 4-5: variant bits\n** bit 6: whether value is collectable\n*/\n\n\n/*\n** LUA_TFUNCTION variants:\n** 0 - Lua function\n** 1 - light C function\n** 2 - regular C function (closure)\n*/\n\n/* Variant tags for functions */\n#define LUA_TLCL\t(LUA_TFUNCTION | (0 << 4))  /* Lua closure */\n#define LUA_TLCF\t(LUA_TFUNCTION | (1 << 4))  /* light C function */\n#define LUA_TCCL\t(LUA_TFUNCTION | (2 << 4))  /* C closure */\n\n\n/* Variant tags for strings */\n#define LUA_TSHRSTR\t(LUA_TSTRING | (0 << 4))  /* short strings */\n#define LUA_TLNGSTR\t(LUA_TSTRING | (1 << 4))  /* long strings */\n\n\n/* Variant tags for numbers */\n#define LUA_TNUMFLT\t(LUA_TNUMBER | (0 << 4))  /* float numbers */\n#define LUA_TNUMINT\t(LUA_TNUMBER | (1 << 4))  /* integer numbers */\n\n\n/* Bit mark for collectable types */\n#define BIT_ISCOLLECTABLE\t(1 << 6)\n\n/* mark a tag as collectable */\n#define ctb(t)\t\t\t((t) | BIT_ISCOLLECTABLE)\n\n\n/*\n** Common type for all collectable objects\n*/\ntypedef struct GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common type has only the common header\n*/\nstruct GCObject {\n  CommonHeader;\n};\n\n\n\n\n/*\n** Tagged Values. This is the basic representation of values in Lua,\n** an actual value plus a tag with its type.\n*/\n\n/*\n** Union of all Lua values\n*/\ntypedef union Value {\n  GCObject *gc;    /* collectable objects */\n  void *p;         /* light userdata */\n  int b;           /* booleans */\n  lua_CFunction f; /* light C functions */\n  lua_Integer i;   /* integer numbers */\n  lua_Number n;    /* float numbers */\n} Value;\n\n\n#define TValuefields\tValue value_; int tt_\n\n\ntypedef struct lua_TValue {\n  TValuefields;\n} TValue;\n\n\n\n/* macro defining a nil value */\n#define NILCONSTANT\t{NULL}, LUA_TNIL\n\n\n#define val_(o)\t\t((o)->value_)\n\n\n/* raw type tag of a TValue */\n#define rttype(o)\t((o)->tt_)\n\n/* tag with no variants (bits 0-3) */\n#define novariant(x)\t((x) & 0x0F)\n\n/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */\n#define ttype(o)\t(rttype(o) & 0x3F)\n\n/* type tag of a TValue with no variants (bits 0-3) */\n#define ttnov(o)\t(novariant(rttype(o)))\n\n\n/* Macros to test type */\n#define checktag(o,t)\t\t(rttype(o) == (t))\n#define checktype(o,t)\t\t(ttnov(o) == (t))\n#define ttisnumber(o)\t\tchecktype((o), LUA_TNUMBER)\n#define ttisfloat(o)\t\tchecktag((o), LUA_TNUMFLT)\n#define ttisinteger(o)\t\tchecktag((o), LUA_TNUMINT)\n#define ttisnil(o)\t\tchecktag((o), LUA_TNIL)\n#define ttisboolean(o)\t\tchecktag((o), LUA_TBOOLEAN)\n#define ttislightuserdata(o)\tchecktag((o), LUA_TLIGHTUSERDATA)\n#define ttisstring(o)\t\tchecktype((o), LUA_TSTRING)\n#define ttisshrstring(o)\tchecktag((o), ctb(LUA_TSHRSTR))\n#define ttislngstring(o)\tchecktag((o), ctb(LUA_TLNGSTR))\n#define ttistable(o)\t\tchecktag((o), ctb(LUA_TTABLE))\n#define ttisfunction(o)\t\tchecktype(o, LUA_TFUNCTION)\n#define ttisclosure(o)\t\t((rttype(o) & 0x1F) == LUA_TFUNCTION)\n#define ttisCclosure(o)\t\tchecktag((o), ctb(LUA_TCCL))\n#define ttisLclosure(o)\t\tchecktag((o), ctb(LUA_TLCL))\n#define ttislcf(o)\t\tchecktag((o), LUA_TLCF)\n#define ttisfulluserdata(o)\tchecktag((o), ctb(LUA_TUSERDATA))\n#define ttisthread(o)\t\tchecktag((o), ctb(LUA_TTHREAD))\n#define ttisdeadkey(o)\t\tchecktag((o), LUA_TDEADKEY)\n\n\n/* Macros to access values */\n#define ivalue(o)\tcheck_exp(ttisinteger(o), val_(o).i)\n#define fltvalue(o)\tcheck_exp(ttisfloat(o), val_(o).n)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), \\\n\t(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))\n#define gcvalue(o)\tcheck_exp(iscollectable(o), val_(o).gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), val_(o).p)\n#define tsvalue(o)\tcheck_exp(ttisstring(o), gco2ts(val_(o).gc))\n#define uvalue(o)\tcheck_exp(ttisfulluserdata(o), gco2u(val_(o).gc))\n#define clvalue(o)\tcheck_exp(ttisclosure(o), gco2cl(val_(o).gc))\n#define clLvalue(o)\tcheck_exp(ttisLclosure(o), gco2lcl(val_(o).gc))\n#define clCvalue(o)\tcheck_exp(ttisCclosure(o), gco2ccl(val_(o).gc))\n#define fvalue(o)\tcheck_exp(ttislcf(o), val_(o).f)\n#define hvalue(o)\tcheck_exp(ttistable(o), gco2t(val_(o).gc))\n#define bvalue(o)\tcheck_exp(ttisboolean(o), val_(o).b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), gco2th(val_(o).gc))\n/* a dead value may get the 'gc' field, but cannot access its contents */\n#define deadvalue(o)\tcheck_exp(ttisdeadkey(o), cast(void *, val_(o).gc))\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n\n#define iscollectable(o)\t(rttype(o) & BIT_ISCOLLECTABLE)\n\n\n/* Macros for internal tests */\n#define righttt(obj)\t\t(ttype(obj) == gcvalue(obj)->tt)\n\n#define checkliveness(L,obj) \\\n\tlua_longassert(!iscollectable(obj) || \\\n\t\t(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))\n\n\n/* Macros to set values */\n#define settt_(o,t)\t((o)->tt_=(t))\n\n#define setfltvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }\n\n#define chgfltvalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }\n\n#define setivalue(obj,x) \\\n  { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }\n\n#define chgivalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }\n\n#define setnilvalue(obj) settt_(obj, LUA_TNIL)\n\n#define setfvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }\n\n#define setpvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }\n\n#define setbvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }\n\n#define setgcovalue(L,obj,x) \\\n  { TValue *io = (obj); GCObject *i_g=(x); \\\n    val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }\n\n#define setsvalue(L,obj,x) \\\n  { TValue *io = (obj); TString *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \\\n    checkliveness(L,io); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *io = (obj); Udata *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \\\n    checkliveness(L,io); }\n\n#define setthvalue(L,obj,x) \\\n  { TValue *io = (obj); lua_State *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \\\n    checkliveness(L,io); }\n\n#define setclLvalue(L,obj,x) \\\n  { TValue *io = (obj); LClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \\\n    checkliveness(L,io); }\n\n#define setclCvalue(L,obj,x) \\\n  { TValue *io = (obj); CClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \\\n    checkliveness(L,io); }\n\n#define sethvalue(L,obj,x) \\\n  { TValue *io = (obj); Table *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \\\n    checkliveness(L,io); }\n\n#define setdeadvalue(obj)\tsettt_(obj, LUA_TDEADKEY)\n\n\n\n#define setobj(L,obj1,obj2) \\\n\t{ TValue *io1=(obj1); *io1 = *(obj2); \\\n\t  (void)L; checkliveness(L,io1); }\n\n\n/*\n** different types of assignments, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n/* to table (define it as an expression to be used in macros) */\n#define setobj2t(L,o1,o2)  ((void)L, *(o1)=*(o2), checkliveness(L,(o1)))\n\n\n\n\n/*\n** {======================================================\n** types and prototypes\n** =======================================================\n*/\n\n\ntypedef TValue *StkId;  /* index to stack elements */\n\n\n\n\n/*\n** Header for string value; string bytes follow the end of this structure\n** (aligned according to 'UTString'; see next).\n*/\ntypedef struct TString {\n  CommonHeader;\n  lu_byte extra;  /* reserved words for short strings; \"has hash\" for longs */\n  lu_byte shrlen;  /* length for short strings */\n  unsigned int hash;\n  union {\n    size_t lnglen;  /* length for long strings */\n    struct TString *hnext;  /* linked list for hash table */\n  } u;\n} TString;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UTString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  TString tsv;\n} UTString;\n\n\n/*\n** Get the actual string (array of bytes) from a 'TString'.\n** (Access to 'extra' ensures that value is really a 'TString'.)\n*/\n#define getstr(ts)  \\\n  check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))\n\n\n/* get the actual string (array of bytes) from a Lua value */\n#define svalue(o)       getstr(tsvalue(o))\n\n/* get string length from 'TString *s' */\n#define tsslen(s)\t((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)\n\n/* get string length from 'TValue *o' */\n#define vslen(o)\ttsslen(tsvalue(o))\n\n\n/*\n** Header for userdata; memory area follows the end of this structure\n** (aligned according to 'UUdata'; see next).\n*/\ntypedef struct Udata {\n  CommonHeader;\n  lu_byte ttuv_;  /* user value's tag */\n  struct Table *metatable;\n  size_t len;  /* number of bytes */\n  union Value user_;  /* user value */\n} Udata;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UUdata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for 'local' udata */\n  Udata uv;\n} UUdata;\n\n\n/*\n**  Get the address of memory block inside 'Udata'.\n** (Access to 'ttuv_' ensures that value is really a 'Udata'.)\n*/\n#define getudatamem(u)  \\\n  check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata)))\n\n#define setuservalue(L,u,o) \\\n\t{ const TValue *io=(o); Udata *iu = (u); \\\n\t  iu->user_ = io->value_; iu->ttuv_ = rttype(io); \\\n\t  checkliveness(L,io); }\n\n\n#define getuservalue(L,u,o) \\\n\t{ TValue *io=(o); const Udata *iu = (u); \\\n\t  io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n\t  checkliveness(L,io); }\n\n\n/*\n** Description of an upvalue for function prototypes\n*/\ntypedef struct Upvaldesc {\n  TString *name;  /* upvalue name (for debug information) */\n  lu_byte instack;  /* whether it is in stack (register) */\n  lu_byte idx;  /* index of upvalue (in stack or in outer function's list) */\n} Upvaldesc;\n\n\n/*\n** Description of a local variable for function prototypes\n** (used for debug information)\n*/\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  lu_byte numparams;  /* number of fixed parameters */\n  lu_byte is_vararg;  /* 2: declared vararg; 1: uses vararg */\n  lu_byte maxstacksize;  /* number of registers needed by this function */\n  int sizeupvalues;  /* size of 'upvalues' */\n  int sizek;  /* size of 'k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of 'p' */\n  int sizelocvars;\n  int linedefined;  /* debug information  */\n  int lastlinedefined;  /* debug information  */\n  TValue *k;  /* constants used by the function */\n  Instruction *code;  /* opcodes */\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines (debug information) */\n  LocVar *locvars;  /* information about local variables (debug information) */\n  Upvaldesc *upvalues;  /* upvalue information */\n  struct LClosure *cache;  /* last-created closure with this prototype */\n  TString  *source;  /* used for debug information */\n  GCObject *gclist;\n} Proto;\n\n\n\n/*\n** Lua Upvalues\n*/\ntypedef struct UpVal UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte nupvalues; GCObject *gclist\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];  /* list of upvalues */\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];  /* list of upvalues */\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define isLfunction(o)\tttisLclosure(o)\n\n#define getproto(o)\t(clLvalue(o)->p)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    int next;  /* for chaining (offset for next node) */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\n/* copy a value into a key without messing up field 'next' */\n#define setnodekey(L,key,obj) \\\n\t{ TKey *k_=(key); const TValue *io_=(obj); \\\n\t  k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \\\n\t  (void)L; checkliveness(L,io_); }\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */\n  lu_byte lsizenode;  /* log2 of size of 'node' array */\n  unsigned int sizearray;  /* size of 'array' array */\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  struct Table *metatable;\n  GCObject *gclist;\n} Table;\n\n\n\n/*\n** 'module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n/*\n** (address of) a fixed nil value\n*/\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\n\nLUAI_DDEC const TValue luaO_nilobject_;\n\n/* size of buffer for 'luaO_utf8esc' function */\n#define UTF8BUFFSZ\t8\n\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);\nLUAI_FUNC int luaO_ceillog2 (unsigned int x);\nLUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,\n                           const TValue *p2, TValue *res);\nLUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);\nLUAI_FUNC int luaO_hexavalue (int c);\nLUAI_FUNC void luaO_tostring (lua_State *L, StkId obj);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lopcodes_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nLUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADKX\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETTABUP\",\n  \"GETTABLE\",\n  \"SETTABUP\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"MOD\",\n  \"POW\",\n  \"DIV\",\n  \"IDIV\",\n  \"BAND\",\n  \"BOR\",\n  \"BXOR\",\n  \"SHL\",\n  \"SHR\",\n  \"UNM\",\n  \"BNOT\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORCALL\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSURE\",\n  \"VARARG\",\n  \"EXTRAARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nLUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgN, OpArgN, iABx)\t\t/* OP_LOADKX */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgU, OpArgK, iABC)\t\t/* OP_GETTABUP */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABUP */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_IDIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BAND */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BXOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHR */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_BNOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(0, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORCALL */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n ,opmode(0, 0, OpArgU, OpArgU, iAx)\t\t/* OP_EXTRAARG */\n};\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.148 2014/10/25 11:50:46 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t'A' : 8 bits\n\t'B' : 9 bits\n\t'C' : 9 bits\n\t'Ax' : 26 bits ('A', 'B', and 'C' together)\n\t'Bx' : 18 bits ('B' and 'C' together)\n\t'sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx, iAx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n#define SIZE_Ax\t\t(SIZE_C + SIZE_B + SIZE_A)\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n#define POS_Ax\t\tPOS_A\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* 'sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n#if SIZE_Ax < LUAI_BITSINT-1\n#define MAXARG_Ax\t((1<<SIZE_Ax)-1)\n#else\n#define MAXARG_Ax\tMAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with 'n' 1 bits at position 'p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<(n)))<<(p))\n\n/* creates a mask with 'n' 0 bits at position 'p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define getarg(i,pos,size)\t(cast(int, ((i)>>pos) & MASK1(size,0)))\n#define setarg(i,v,pos,size)\t((i) = (((i)&MASK0(size,pos)) | \\\n                ((cast(Instruction, v)<<pos)&MASK1(size,pos))))\n\n#define GETARG_A(i)\tgetarg(i, POS_A, SIZE_A)\n#define SETARG_A(i,v)\tsetarg(i, v, POS_A, SIZE_A)\n\n#define GETARG_B(i)\tgetarg(i, POS_B, SIZE_B)\n#define SETARG_B(i,v)\tsetarg(i, v, POS_B, SIZE_B)\n\n#define GETARG_C(i)\tgetarg(i, POS_C, SIZE_C)\n#define SETARG_C(i,v)\tsetarg(i, v, POS_C, SIZE_C)\n\n#define GETARG_Bx(i)\tgetarg(i, POS_Bx, SIZE_Bx)\n#define SETARG_Bx(i,v)\tsetarg(i, v, POS_Bx, SIZE_Bx)\n\n#define GETARG_Ax(i)\tgetarg(i, POS_Ax, SIZE_Ax)\n#define SETARG_Ax(i,v)\tsetarg(i, v, POS_Ax, SIZE_Ax)\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n#define CREATE_Ax(o,a)\t\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_Ax))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#define MAXINDEXRK\t(BITRK - 1)\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADKX,/*\tA \tR(A) := Kst(extra arg)\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A), R(A+1), ..., R(A+B) := nil\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETTABUP,/*\tA B C\tR(A) := UpValue[B][RK(C)]\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETTABUP,/*\tA B C\tUpValue[A][RK(B)] := RK(C)\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_IDIV,/*\tA B C\tR(A) := RK(B) // RK(C)\t\t\t\t*/\nOP_BAND,/*\tA B C\tR(A) := RK(B) & RK(C)\t\t\t\t*/\nOP_BOR,/*\tA B C\tR(A) := RK(B) | RK(C)\t\t\t\t*/\nOP_BXOR,/*\tA B C\tR(A) := RK(B) ~ RK(C)\t\t\t\t*/\nOP_SHL,/*\tA B C\tR(A) := RK(B) << RK(C)\t\t\t\t*/\nOP_SHR,/*\tA B C\tR(A) := RK(B) >> RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_BNOT,/*\tA B\tR(A) := ~R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tA sBx\tpc+=sBx; if (A) close all upvalues >= R(A - 1)\t*/\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++\t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++\t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/\nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/\n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORCALL,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));\t*/\nOP_TFORLOOP,/*\tA sBx\tif R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/\n\nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx])\t\t\t*/\n\nOP_VARARG,/*\tA B\tR(A), R(A+1), ..., R(A+B-2) = vararg\t\t*/\n\nOP_EXTRAARG/*\tAx\textra (larger) argument for previous opcode\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_EXTRAARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is\n  set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,\n  OP_SETLIST) may use 'top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n  set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to 'top'.\n\n  (*) In OP_SETLIST, if (B == 0) then B = 'top'; if (C == 0) then next\n  'instruction' is EXTRAARG(real C).\n\n  (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.\n\n  (*) For comparisons, A specifies what condition the test should accept\n  (true or false).\n\n  (*) All 'skips' (pc++) assume that next instruction is a jump.\n\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test (next instruction must be a jump)\n*/\n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.64 2016/04/18 13:06:55 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** {==================================================================\n** List of valid conversion specifiers for the 'strftime' function;\n** options are grouped by length; group of length 2 start with '||'.\n** ===================================================================\n*/\n#if !defined(LUA_STRFTIMEOPTIONS)\t/* { */\n\n/* options for ANSI C 89 */\n#define L_STRFTIMEC89\t\t\"aAbBcdHIjmMpSUwWxXyYZ%\"\n\n/* options for ISO C 99 and POSIX */\n#define L_STRFTIMEC99 \"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%\" \\\n\t\"||\" \"EcECExEXEyEY\" \"OdOeOHOIOmOMOSOuOUOVOwOWOy\"\n\n/* options for Windows */\n#define L_STRFTIMEWIN \"aAbBcdHIjmMpSUwWxXyYzZ%\" \\\n\t\"||\" \"#c#x#d#H#I#j#m#M#S#U#w#W#y#Y\"\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEWIN\n#elif defined(LUA_USE_C89)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC89\n#else  /* C99 specification */\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC99\n#endif\n\n#endif\t\t\t\t\t/* } */\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for time-related stuff\n** ===================================================================\n*/\n\n#if !defined(l_time_t)\t\t/* { */\n/*\n** type to represent time_t in Lua\n*/\n#define l_timet\t\t\tlua_Integer\n#define l_pushtime(L,t)\t\tlua_pushinteger(L,(lua_Integer)(t))\n\nstatic time_t l_checktime (lua_State *L, int arg) {\n  lua_Integer t = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, (time_t)t == t, arg, \"time out-of-bounds\");\n  return (time_t)t;\n}\n\n#endif\t\t\t\t/* } */\n\n\n#if !defined(l_gmtime)\t\t/* { */\n/*\n** By default, Lua uses gmtime/localtime, except when POSIX is available,\n** where it uses gmtime_r/localtime_r\n*/\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_gmtime(t,r)\t\tgmtime_r(t,r)\n#define l_localtime(t,r)\tlocaltime_r(t,r)\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_gmtime(t,r)\t\t((void)(r)->tm_sec, gmtime(t))\n#define l_localtime(t,r)  \t((void)(r)->tm_sec, localtime(t))\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for 'tmpnam':\n** By default, Lua uses tmpnam except when POSIX is available, where\n** it uses mkstemp.\n** ===================================================================\n*/\n#if !defined(lua_tmpnam)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n\n#define LUA_TMPNAMBUFSIZE\t32\n\n#if !defined(LUA_TMPNAMTEMPLATE)\n#define LUA_TMPNAMTEMPLATE\t\"/tmp/lua_XXXXXX\"\n#endif\n\n#define lua_tmpnam(b,e) { \\\n        strcpy(b, LUA_TMPNAMTEMPLATE); \\\n        e = mkstemp(b); \\\n        if (e != -1) close(e); \\\n        e = (e == -1); }\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n/* }================================================================== */\n\n\n\n\nstatic int os_execute (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *cmd = luaL_optstring(L, 1, NULL);\n  int stat = system(cmd);\n  if (cmd != NULL)\n    return luaL_execresult(L, stat);\n  else {\n    lua_pushboolean(L, stat);  /* true if there is a shell */\n    return 1;\n  }\n#endif\n}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\n\n/*\n** Set all fields from structure 'tm' in the table on top of the stack\n*/\nstatic void setallfields (lua_State *L, struct tm *stm) {\n  setfield(L, \"sec\", stm->tm_sec);\n  setfield(L, \"min\", stm->tm_min);\n  setfield(L, \"hour\", stm->tm_hour);\n  setfield(L, \"day\", stm->tm_mday);\n  setfield(L, \"month\", stm->tm_mon + 1);\n  setfield(L, \"year\", stm->tm_year + 1900);\n  setfield(L, \"wday\", stm->tm_wday + 1);\n  setfield(L, \"yday\", stm->tm_yday + 1);\n  setboolfield(L, \"isdst\", stm->tm_isdst);\n}\n\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\n/* maximum value for date fields (to avoid arithmetic overflows with 'int') */\n#if !defined(L_MAXDATEFIELD)\n#define L_MAXDATEFIELD\t(INT_MAX / 2)\n#endif\n\nstatic int getfield (lua_State *L, const char *key, int d, int delta) {\n  int isnum;\n  int t = lua_getfield(L, -1, key);  /* get field and its type */\n  lua_Integer res = lua_tointegerx(L, -1, &isnum);\n  if (!isnum) {  /* field is not an integer? */\n    if (t != LUA_TNIL)  /* some other value? */\n      return luaL_error(L, \"field '%s' is not an integer\", key);\n    else if (d < 0)  /* absent field; no default? */\n      return luaL_error(L, \"field '%s' missing in date table\", key);\n    res = d;\n  }\n  else {\n    if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))\n      return luaL_error(L, \"field '%s' is out-of-bound\", key);\n    res -= delta;\n  }\n  lua_pop(L, 1);\n  return (int)res;\n}\n\n\nstatic const char *checkoption (lua_State *L, const char *conv, char *buff) {\n  const char *option;\n  int oplen = 1;\n  for (option = LUA_STRFTIMEOPTIONS; *option != '\\0'; option += oplen) {\n    if (*option == '|')  /* next block? */\n      oplen++;  /* next length */\n    else if (memcmp(conv, option, oplen) == 0) {  /* match? */\n      memcpy(buff, conv, oplen);  /* copy valid option to buffer */\n      buff[oplen] = '\\0';\n      return conv + oplen;  /* return next item */\n    }\n  }\n  luaL_argerror(L, 1,\n    lua_pushfstring(L, \"invalid conversion specifier '%%%s'\", conv));\n  return conv;  /* to avoid warnings */\n}\n\n\n/* maximum size for an individual 'strftime' item */\n#define SIZETIMEFMT\t250\n\n\nstatic int os_date (lua_State *L) {\n  const char *s = luaL_optstring(L, 1, \"%c\");\n  time_t t = luaL_opt(L, l_checktime, 2, time(NULL));\n  struct tm tmr, *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = l_gmtime(&t, &tmr);\n    s++;  /* skip '!' */\n  }\n  else\n    stm = l_localtime(&t, &tmr);\n  if (stm == NULL)  /* invalid date? */\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setallfields(L, stm);\n  }\n  else {\n    char cc[4];  /* buffer for individual conversion specifiers */\n    luaL_Buffer b;\n    cc[0] = '%';\n    luaL_buffinit(L, &b);\n    while (*s) {\n      if (*s != '%')  /* not a conversion specifier? */\n        luaL_addchar(&b, *s++);\n      else {\n        size_t reslen;\n        char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);\n        s = checkoption(L, s + 1, cc + 1);  /* copy specifier to 'cc' */\n        reslen = strftime(buff, SIZETIMEFMT, cc, stm);\n        luaL_addsize(&b, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0, 0);\n    ts.tm_min = getfield(L, \"min\", 0, 0);\n    ts.tm_hour = getfield(L, \"hour\", 12, 0);\n    ts.tm_mday = getfield(L, \"day\", -1, 0);\n    ts.tm_mon = getfield(L, \"month\", -1, 1);\n    ts.tm_year = getfield(L, \"year\", -1, 1900);\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n    setallfields(L, &ts);  /* update fields with normalized values */\n  }\n  if (t != (time_t)(l_timet)t || t == (time_t)(-1))\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  l_pushtime(L, t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  time_t t1 = l_checktime(L, 1);\n  time_t t2 = l_checktime(L, 2);\n  lua_pushnumber(L, (lua_Number)difftime(t1, t2));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  int status;\n  if (lua_isboolean(L, 1))\n    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);\n  else\n    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);\n  if (lua_toboolean(L, 2))\n    lua_close(L);\n  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */\n  return 0;\n}\n\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  {\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUAMOD_API int luaopen_os (lua_State *L) {\n  luaL_newlib(L, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.153 2016/05/13 19:10:16 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n/* maximum number of local variables per function (must be smaller\n   than 250, due to the bytecode format) */\n#define MAXVARS\t\t200\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n\n/* because all strings are unified by the scanner, the parser\n   can use pointer equality for string equality */\n#define eqstr(a,b)\t((a) == (b))\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int firstlabel;  /* index of first label in this block */\n  int firstgoto;  /* index of first pending goto in this block */\n  lu_byte nactvar;  /* # active locals outside the block */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isloop;  /* true if 'block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void statement (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\n/* semantic error */\nstatic l_noret semerror (LexState *ls, const char *msg) {\n  ls->t.token = 0;  /* remove \"near <token>\" from final message */\n  luaX_syntaxerror(ls, msg);\n}\n\n\nstatic l_noret error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, \"%s expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic l_noret errorlimit (FuncState *fs, int limit, const char *what) {\n  lua_State *L = fs->ls->L;\n  const char *msg;\n  int line = fs->f->linedefined;\n  const char *where = (line == 0)\n                      ? \"main function\"\n                      : luaO_pushfstring(L, \"function at line %d\", line);\n  msg = luaO_pushfstring(L, \"too many %s (limit is %d) in %s\",\n                             what, limit, where);\n  luaX_syntaxerror(fs->ls, msg);\n}\n\n\nstatic void checklimit (FuncState *fs, int v, int l, const char *what) {\n  if (v > l) errorlimit(fs, l, what);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             \"%s expected (to close %s at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname (LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"local variables\");\n  while (oldsize < f->sizelocvars)\n    f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\nstatic void new_localvar (LexState *ls, TString *name) {\n  FuncState *fs = ls->fs;\n  Dyndata *dyd = ls->dyd;\n  int reg = registerlocalvar(ls, name);\n  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,\n                  MAXVARS, \"local variables\");\n  luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,\n                  dyd->actvar.size, Vardesc, MAX_INT, \"local variables\");\n  dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);\n}\n\n\nstatic void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {\n  new_localvar(ls, luaX_newstring(ls, name, sz));\n}\n\n#define new_localvarliteral(ls,v) \\\n\tnew_localvarliteral_(ls, \"\" v, (sizeof(v)/sizeof(char))-1)\n\n\nstatic LocVar *getlocvar (FuncState *fs, int i) {\n  int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;\n  lua_assert(idx < fs->nlocvars);\n  return &fs->f->locvars[idx];\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (FuncState *fs, int tolevel) {\n  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar)->endpc = fs->pc;\n}\n\n\nstatic int searchupvalue (FuncState *fs, TString *name) {\n  int i;\n  Upvaldesc *up = fs->f->upvalues;\n  for (i = 0; i < fs->nups; i++) {\n    if (eqstr(up[i].name, name)) return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic int newupvalue (FuncState *fs, TString *name, expdesc *v) {\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  checklimit(fs, fs->nups + 1, MAXUPVAL, \"upvalues\");\n  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,\n                  Upvaldesc, MAXUPVAL, \"upvalues\");\n  while (oldsize < f->sizeupvalues)\n    f->upvalues[oldsize++].name = NULL;\n  f->upvalues[fs->nups].instack = (v->k == VLOCAL);\n  f->upvalues[fs->nups].idx = cast_byte(v->u.info);\n  f->upvalues[fs->nups].name = name;\n  luaC_objbarrier(fs->ls->L, f, name);\n  return fs->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {\n    if (eqstr(n, getlocvar(fs, i)->varname))\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\n/*\n  Mark block where variable at given level was defined\n  (to emit close instructions later).\n*/\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl->nactvar > level)\n    bl = bl->previous;\n  bl->upval = 1;\n}\n\n\n/*\n  Find variable with given name 'n'. If it is an upvalue, add this\n  upvalue into all intermediate functions.\n*/\nstatic void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL)  /* no more levels? */\n    init_exp(var, VVOID, 0);  /* default is global */\n  else {\n    int v = searchvar(fs, n);  /* look up locals at current level */\n    if (v >= 0) {  /* found? */\n      init_exp(var, VLOCAL, v);  /* variable is local */\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n    }\n    else {  /* not found as local at current level; try upvalues */\n      int idx = searchupvalue(fs, n);  /* try existing upvalues */\n      if (idx < 0) {  /* not found? */\n        singlevaraux(fs->prev, n, var, 0);  /* try upper levels */\n        if (var->k == VVOID)  /* not found? */\n          return;  /* it is a global */\n        /* else was LOCAL or UPVAL */\n        idx  = newupvalue(fs, n, var);  /* will be a new upvalue */\n      }\n      init_exp(var, VUPVAL, idx);  /* new or old upvalue */\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  singlevaraux(fs, varname, var, 1);\n  if (var->k == VVOID) {  /* global name? */\n    expdesc key;\n    singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */\n    lua_assert(var->k != VVOID);  /* this one must exist */\n    codestring(ls, &key, varname);  /* key is variable name */\n    luaK_indexed(fs, var, &key);  /* env[varname] */\n  }\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  lua_State *L = ls->L;\n  ++L->nCcalls;\n  checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, \"C levels\");\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void closegoto (LexState *ls, int g, Labeldesc *label) {\n  int i;\n  FuncState *fs = ls->fs;\n  Labellist *gl = &ls->dyd->gt;\n  Labeldesc *gt = &gl->arr[g];\n  lua_assert(eqstr(gt->name, label->name));\n  if (gt->nactvar < label->nactvar) {\n    TString *vname = getlocvar(fs, gt->nactvar)->varname;\n    const char *msg = luaO_pushfstring(ls->L,\n      \"<goto %s> at line %d jumps into the scope of local '%s'\",\n      getstr(gt->name), gt->line, getstr(vname));\n    semerror(ls, msg);\n  }\n  luaK_patchlist(fs, gt->pc, label->pc);\n  /* remove goto from pending list */\n  for (i = g; i < gl->n - 1; i++)\n    gl->arr[i] = gl->arr[i + 1];\n  gl->n--;\n}\n\n\n/*\n** try to close a goto with existing labels; this solves backward jumps\n*/\nstatic int findlabel (LexState *ls, int g) {\n  int i;\n  BlockCnt *bl = ls->fs->bl;\n  Dyndata *dyd = ls->dyd;\n  Labeldesc *gt = &dyd->gt.arr[g];\n  /* check labels in current block for a match */\n  for (i = bl->firstlabel; i < dyd->label.n; i++) {\n    Labeldesc *lb = &dyd->label.arr[i];\n    if (eqstr(lb->name, gt->name)) {  /* correct label? */\n      if (gt->nactvar > lb->nactvar &&\n          (bl->upval || dyd->label.n > bl->firstlabel))\n        luaK_patchclose(ls->fs, gt->pc, lb->nactvar);\n      closegoto(ls, g, lb);  /* close it */\n      return 1;\n    }\n  }\n  return 0;  /* label not found; cannot close goto */\n}\n\n\nstatic int newlabelentry (LexState *ls, Labellist *l, TString *name,\n                          int line, int pc) {\n  int n = l->n;\n  luaM_growvector(ls->L, l->arr, n, l->size,\n                  Labeldesc, SHRT_MAX, \"labels/gotos\");\n  l->arr[n].name = name;\n  l->arr[n].line = line;\n  l->arr[n].nactvar = ls->fs->nactvar;\n  l->arr[n].pc = pc;\n  l->n = n + 1;\n  return n;\n}\n\n\n/*\n** check whether new label 'lb' matches any pending gotos in current\n** block; solves forward jumps\n*/\nstatic void findgotos (LexState *ls, Labeldesc *lb) {\n  Labellist *gl = &ls->dyd->gt;\n  int i = ls->fs->bl->firstgoto;\n  while (i < gl->n) {\n    if (eqstr(gl->arr[i].name, lb->name))\n      closegoto(ls, i, lb);\n    else\n      i++;\n  }\n}\n\n\n/*\n** export pending gotos to outer level, to check them against\n** outer labels; if the block being exited has upvalues, and\n** the goto exits the scope of any variable (which can be the\n** upvalue), close those variables being exited.\n*/\nstatic void movegotosout (FuncState *fs, BlockCnt *bl) {\n  int i = bl->firstgoto;\n  Labellist *gl = &fs->ls->dyd->gt;\n  /* correct pending gotos to current block and try to close it\n     with visible labels */\n  while (i < gl->n) {\n    Labeldesc *gt = &gl->arr[i];\n    if (gt->nactvar > bl->nactvar) {\n      if (bl->upval)\n        luaK_patchclose(fs, gt->pc, bl->nactvar);\n      gt->nactvar = bl->nactvar;\n    }\n    if (!findlabel(fs->ls, i))\n      i++;  /* move to next one */\n  }\n}\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {\n  bl->isloop = isloop;\n  bl->nactvar = fs->nactvar;\n  bl->firstlabel = fs->ls->dyd->label.n;\n  bl->firstgoto = fs->ls->dyd->gt.n;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\n/*\n** create a label named 'break' to resolve break statements\n*/\nstatic void breaklabel (LexState *ls) {\n  TString *n = luaS_new(ls->L, \"break\");\n  int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);\n  findgotos(ls, &ls->dyd->label.arr[l]);\n}\n\n/*\n** generates an error for an undefined 'goto'; choose appropriate\n** message when label name is a reserved word (which can only be 'break')\n*/\nstatic l_noret undefgoto (LexState *ls, Labeldesc *gt) {\n  const char *msg = isreserved(gt->name)\n                    ? \"<%s> at line %d not inside a loop\"\n                    : \"no visible label '%s' for <goto> at line %d\";\n  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);\n  semerror(ls, msg);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  LexState *ls = fs->ls;\n  if (bl->previous && bl->upval) {\n    /* create a 'jump to here' to close upvalues */\n    int j = luaK_jump(fs);\n    luaK_patchclose(fs, j, bl->nactvar);\n    luaK_patchtohere(fs, j);\n  }\n  if (bl->isloop)\n    breaklabel(ls);  /* close pending breaks */\n  fs->bl = bl->previous;\n  removevars(fs, bl->nactvar);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  ls->dyd->label.n = bl->firstlabel;  /* remove local labels */\n  if (bl->previous)  /* inner block? */\n    movegotosout(fs, bl);  /* update pending gotos to outer block */\n  else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */\n    undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */\n}\n\n\n/*\n** adds a new prototype into list of prototypes\n*/\nstatic Proto *addprototype (LexState *ls) {\n  Proto *clp;\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;  /* prototype of current function */\n  if (fs->np >= f->sizep) {\n    int oldsize = f->sizep;\n    luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, \"functions\");\n    while (oldsize < f->sizep)\n      f->p[oldsize++] = NULL;\n  }\n  f->p[fs->np++] = clp = luaF_newproto(L);\n  luaC_objbarrier(L, f, clp);\n  return clp;\n}\n\n\n/*\n** codes instruction to create new closure in parent function.\n** The OP_CLOSURE instruction must use the last available register,\n** so that, if it invokes the GC, the GC knows which registers\n** are in use at that time.\n*/\nstatic void codeclosure (LexState *ls, expdesc *v) {\n  FuncState *fs = ls->fs->prev;\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));\n  luaK_exp2nextreg(fs, v);  /* fix it at the last register */\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {\n  Proto *f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nups = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->firstlocal = ls->dyd->actvar.n;\n  fs->bl = NULL;\n  f = fs->f;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  enterblock(fs, bl, 0);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  luaK_ret(fs, 0, 0);  /* final return */\n  leaveblock(fs);\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);\n  f->sizeupvalues = fs->nups;\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  luaC_checkGC(L);\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\n/*\n** check whether current token is in the follow set of a block.\n** 'until' closes syntactical blocks, but do not close scope,\n** so it is handled in separate.\n*/\nstatic int block_follow (LexState *ls, int withuntil) {\n  switch (ls->t.token) {\n    case TK_ELSE: case TK_ELSEIF:\n    case TK_END: case TK_EOS:\n      return 1;\n    case TK_UNTIL: return withuntil;\n    default: return 0;\n  }\n}\n\n\nstatic void statlist (LexState *ls) {\n  /* statlist -> { stat [';'] } */\n  while (!block_follow(ls, 1)) {\n    if (ls->t.token == TK_RETURN) {\n      statement(ls);\n      return;  /* 'return' must be last statement */\n    }\n    statement(ls);\n  }\n}\n\n\nstatic void fieldsel (LexState *ls, expdesc *v) {\n  /* fieldsel -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyregup(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of 'record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | '['exp1']') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  /* listfield -> exp */\n  expr(ls, &cc->v);\n  checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void field (LexState *ls, struct ConsControl *cc) {\n  /* field -> listfield | recfield */\n  switch(ls->t.token) {\n    case TK_NAME: {  /* may be 'listfield' or 'recfield' */\n      if (luaX_lookahead(ls) != '=')  /* expression? */\n        listfield(ls, cc);\n      else\n        recfield(ls, cc);\n      break;\n    }\n    case '[': {\n      recfield(ls, cc);\n      break;\n    }\n    default: {\n      listfield(ls, cc);\n      break;\n    }\n  }\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> '{' [ field { sep field } [sep] ] '}'\n     sep -> ',' | ';' */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    field(ls, &cc);\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { ',' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is 'parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls));\n          nparams++;\n          break;\n        }\n        case TK_DOTS: {  /* param -> '...' */\n          luaX_next(ls);\n          f->is_vararg = 2;  /* declared vararg */\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or '...' expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar);\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int ismethod, int line) {\n  /* body ->  '(' parlist ')' block END */\n  FuncState new_fs;\n  BlockCnt bl;\n  new_fs.f = addprototype(ls);\n  new_fs.f->linedefined = line;\n  open_func(ls, &new_fs, &bl);\n  checknext(ls, '(');\n  if (ismethod) {\n    new_localvarliteral(ls, \"self\");  /* create 'self' parameter */\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  statlist(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  codeclosure(ls, e);\n  close_func(ls);\n}\n\n\nstatic int explist (LexState *ls, expdesc *v) {\n  /* explist -> expr { ',' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f, int line) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> '(' [ explist ] ')' */\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use 'seminfo' before 'next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n    }\n  }\n}\n\n\nstatic void suffixedexp (LexState *ls, expdesc *v) {\n  /* suffixedexp ->\n       primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  primaryexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* fieldsel */\n        fieldsel(ls, v);\n        break;\n      }\n      case '[': {  /* '[' exp1 ']' */\n        expdesc key;\n        luaK_exp2anyregup(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* ':' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v, line);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v, line);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |\n                  constructor | FUNCTION body | suffixedexp */\n  switch (ls->t.token) {\n    case TK_FLT: {\n      init_exp(v, VKFLT, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_INT: {\n      init_exp(v, VKINT, 0);\n      v->u.ival = ls->t.seminfo.i;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use '...' outside a vararg function\");\n      fs->f->is_vararg = 1;  /* function actually uses vararg */\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      suffixedexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '~': return OPR_BNOT;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case '/': return OPR_DIV;\n    case TK_IDIV: return OPR_IDIV;\n    case '&': return OPR_BAND;\n    case '|': return OPR_BOR;\n    case '~': return OPR_BXOR;\n    case TK_SHL: return OPR_SHL;\n    case TK_SHR: return OPR_SHR;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {10, 10}, {10, 10},           /* '+' '-' */\n   {11, 11}, {11, 11},           /* '*' '%' */\n   {14, 13},                  /* '^' (right associative) */\n   {11, 11}, {11, 11},           /* '/' '//' */\n   {6, 6}, {4, 4}, {5, 5},   /* '&' '|' '~' */\n   {7, 7}, {7, 7},           /* '<<' '>>' */\n   {9, 8},                   /* '..' (right associative) */\n   {3, 3}, {3, 3}, {3, 3},   /* ==, <, <= */\n   {3, 3}, {3, 3}, {3, 3},   /* ~=, >, >= */\n   {2, 2}, {1, 1}            /* and, or */\n};\n\n#define UNARY_PRIORITY\t12  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where 'binop' is any binary operator with a priority higher than 'limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    int line = ls->linenumber;\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v, line);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than 'limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    int line = ls->linenumber;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2, line);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic void block (LexState *ls) {\n  /* block -> statlist */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  statlist(ls);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to an upvalue/local variable, the\n** upvalue/local variable is begin used in a previous assignment to a\n** table. If so, save original upvalue/local value in a safe place and\n** use this safe copy in the previous assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {  /* check all previous assignments */\n    if (lh->v.k == VINDEXED) {  /* assigning to a table? */\n      /* table is the upvalue/local being assigned now? */\n      if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.vt = VLOCAL;\n        lh->v.u.ind.t = extra;  /* previous assignment will use safe copy */\n      }\n      /* index is the local being assigned? (index cannot be upvalue) */\n      if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.idx = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    /* copy upvalue/local value to a temporary (in position 'extra') */\n    OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, op, extra, v->u.info, 0);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, vkisvar(lh->v.k), \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> ',' suffixedexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    suffixedexp(ls, &nv.v);\n    if (nv.v.k != VINDEXED)\n      check_conflict(ls, lh, &nv.v);\n    checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,\n                    \"C levels\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> '=' explist */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist(ls, &e);\n    if (nexps != nvars) {\n      adjust_assign(ls, nvars, nexps, &e);\n      if (nexps > nvars)\n        ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n    }\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* 'falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void gotostat (LexState *ls, int pc) {\n  int line = ls->linenumber;\n  TString *label;\n  int g;\n  if (testnext(ls, TK_GOTO))\n    label = str_checkname(ls);\n  else {\n    luaX_next(ls);  /* skip break */\n    label = luaS_new(ls->L, \"break\");\n  }\n  g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);\n  findlabel(ls, g);  /* close it if label already defined */\n}\n\n\n/* check for repeated labels on the same block */\nstatic void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {\n  int i;\n  for (i = fs->bl->firstlabel; i < ll->n; i++) {\n    if (eqstr(label, ll->arr[i].name)) {\n      const char *msg = luaO_pushfstring(fs->ls->L,\n                          \"label '%s' already defined on line %d\",\n                          getstr(label), ll->arr[i].line);\n      semerror(fs->ls, msg);\n    }\n  }\n}\n\n\n/* skip no-op statements */\nstatic void skipnoopstat (LexState *ls) {\n  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)\n    statement(ls);\n}\n\n\nstatic void labelstat (LexState *ls, TString *label, int line) {\n  /* label -> '::' NAME '::' */\n  FuncState *fs = ls->fs;\n  Labellist *ll = &ls->dyd->label;\n  int l;  /* index of new label being created */\n  checkrepeated(fs, ll, label);  /* check for repeated labels */\n  checknext(ls, TK_DBCOLON);  /* skip double colon */\n  /* create new entry for this label */\n  l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));\n  skipnoopstat(ls);  /* skip other no-op statements */\n  if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */\n    /* assume that locals are already out of scope */\n    ll->arr[l].nactvar = fs->bl->nactvar;\n  }\n  findgotos(ls, &ll->arr[l]);\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_jumpto(fs, whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  statlist(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (bl2.upval)  /* upvalues? */\n    luaK_patchclose(fs, condexit, bl2.nactvar);\n  leaveblock(fs);  /* finish scope */\n  luaK_patchlist(fs, condexit, repeat_init);  /* close the loop */\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int reg;\n  expr(ls, &e);\n  luaK_exp2nextreg(ls->fs, &e);\n  lua_assert(e.k == VNONRELOC);\n  reg = e.u.info;\n  return reg;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  if (isnum)  /* numeric for? */\n    endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);\n  else {  /* generic for */\n    luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);\n    luaK_fixline(fs, line);\n    endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);\n  }\n  luaK_patchlist(fs, endfor, prep + 1);\n  luaK_fixline(fs, line);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\");\n  new_localvarliteral(ls, \"(for limit)\");\n  new_localvarliteral(ls, \"(for step)\");\n  new_localvar(ls, varname);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codek(fs, fs->freereg, luaK_intK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 4;  /* gen, state, control, plus at least one declared var */\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for control)\");\n  /* create declared variables */\n  new_localvar(ls, indexname);\n  while (testnext(ls, ',')) {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  }\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip 'for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, \"'=' or 'in' expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope ('break' jumps to this point) */\n}\n\n\nstatic void test_then_block (LexState *ls, int *escapelist) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  expdesc v;\n  int jf;  /* instruction to skip 'then' code (if condition is false) */\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  expr(ls, &v);  /* read condition */\n  checknext(ls, TK_THEN);\n  if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {\n    luaK_goiffalse(ls->fs, &v);  /* will jump to label if condition is true */\n    enterblock(fs, &bl, 0);  /* must enter block before 'goto' */\n    gotostat(ls, v.t);  /* handle goto/break */\n    skipnoopstat(ls);  /* skip other no-op statements */\n    if (block_follow(ls, 0)) {  /* 'goto' is the entire block? */\n      leaveblock(fs);\n      return;  /* and that is it */\n    }\n    else  /* must skip over 'then' part if condition is false */\n      jf = luaK_jump(fs);\n  }\n  else {  /* regular case (not goto/break) */\n    luaK_goiftrue(ls->fs, &v);  /* skip over block if condition is false */\n    enterblock(fs, &bl, 0);\n    jf = v.f;\n  }\n  statlist(ls);  /* 'then' part */\n  leaveblock(fs);\n  if (ls->t.token == TK_ELSE ||\n      ls->t.token == TK_ELSEIF)  /* followed by 'else'/'elseif'? */\n    luaK_concat(fs, escapelist, luaK_jump(fs));  /* must jump over it */\n  luaK_patchtohere(fs, jf);\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int escapelist = NO_JUMP;  /* exit list for finished parts */\n  test_then_block(ls, &escapelist);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF)\n    test_then_block(ls, &escapelist);  /* ELSEIF cond THEN block */\n  if (testnext(ls, TK_ELSE))\n    block(ls);  /* 'else' part */\n  check_match(ls, TK_END, TK_IF, line);\n  luaK_patchtohere(fs, escapelist);  /* patch escape list to 'if' end */\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls));  /* new local variable */\n  adjustlocalvars(ls, 1);  /* enter its scope */\n  body(ls, &b, 0, ls->linenumber);  /* function created in next register */\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, b.u.info)->startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {',' NAME} ['=' explist] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {fieldsel} [':' NAME] */\n  int ismethod = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    fieldsel(ls, v);\n  if (ls->t.token == ':') {\n    ismethod = 1;\n    fieldsel(ls, v);\n  }\n  return ismethod;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int ismethod;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  ismethod = funcname(ls, &v);\n  body(ls, &b, ismethod, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition \"happens\" in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  suffixedexp(ls, &v.v);\n  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n  else {  /* stat -> func */\n    check_condition(ls, v.v.k == VCALL, \"syntax error\");\n    SETARG_C(getinstruction(fs, &v.v), 1);  /* call statement uses no results */\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN [explist] [';'] */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  if (block_follow(ls, 1) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the stack */\n        first = fs->nactvar;  /* return all active values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n  testnext(ls, ';');  /* skip optional semicolon */\n}\n\n\nstatic void statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  enterlevel(ls);\n  switch (ls->t.token) {\n    case ';': {  /* stat -> ';' (empty statement) */\n      luaX_next(ls);  /* skip ';' */\n      break;\n    }\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      break;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      break;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      break;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      break;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      break;\n    }\n    case TK_FUNCTION: {  /* stat -> funcstat */\n      funcstat(ls, line);\n      break;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      break;\n    }\n    case TK_DBCOLON: {  /* stat -> label */\n      luaX_next(ls);  /* skip double colon */\n      labelstat(ls, str_checkname(ls), line);\n      break;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      luaX_next(ls);  /* skip RETURN */\n      retstat(ls);\n      break;\n    }\n    case TK_BREAK:   /* stat -> breakstat */\n    case TK_GOTO: {  /* stat -> 'goto' NAME */\n      gotostat(ls, luaK_jump(ls->fs));\n      break;\n    }\n    default: {  /* stat -> func | assignment */\n      exprstat(ls);\n      break;\n    }\n  }\n  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n             ls->fs->freereg >= ls->fs->nactvar);\n  ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n\n\n/*\n** compiles the main function, which is a regular vararg function with an\n** upvalue named LUA_ENV\n*/\nstatic void mainfunc (LexState *ls, FuncState *fs) {\n  BlockCnt bl;\n  expdesc v;\n  open_func(ls, fs, &bl);\n  fs->f->is_vararg = 2;  /* main function is always declared vararg */\n  init_exp(&v, VLOCAL, 0);  /* create and... */\n  newupvalue(fs, ls->envn, &v);  /* ...set environment upvalue */\n  luaX_next(ls);  /* read first token */\n  statlist(ls);  /* parse main body */\n  check(ls, TK_EOS);\n  close_func(ls);\n}\n\n\nLClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                       Dyndata *dyd, const char *name, int firstchar) {\n  LexState lexstate;\n  FuncState funcstate;\n  LClosure *cl = luaF_newLclosure(L, 1);  /* create main closure */\n  setclLvalue(L, L->top, cl);  /* anchor it (to avoid being collected) */\n  luaD_inctop(L);\n  lexstate.h = luaH_new(L);  /* create table for scanner */\n  sethvalue(L, L->top, lexstate.h);  /* anchor it */\n  luaD_inctop(L);\n  funcstate.f = cl->p = luaF_newproto(L);\n  funcstate.f->source = luaS_new(L, name);  /* create and anchor TString */\n  lua_assert(iswhite(funcstate.f));  /* do not need barrier here */\n  lexstate.buff = buff;\n  lexstate.dyd = dyd;\n  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;\n  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);\n  mainfunc(&lexstate, &funcstate);\n  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);\n  /* all scopes should be correctly finished */\n  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);\n  L->top--;  /* remove scanner's table */\n  return cl;  /* closure is on the stack, too */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression and variable descriptor.\n** Code generation for variables and expressions can be delayed to allow\n** optimizations; An 'expdesc' structure describes a potentially-delayed\n** variable/expression. It has a description of its \"main\" value plus a\n** list of conditional jumps that can also produce its value (generated\n** by short-circuit operators 'and'/'or').\n*/\n\n/* kinds of variables/expressions */\ntypedef enum {\n  VVOID,  /* when 'expdesc' describes the last expression a list,\n             this kind means an empty list (so, no expression) */\n  VNIL,  /* constant nil */\n  VTRUE,  /* constant true */\n  VFALSE,  /* constant false */\n  VK,  /* constant in 'k'; info = index of constant in 'k' */\n  VKFLT,  /* floating constant; nval = numerical float value */\n  VKINT,  /* integer constant; nval = numerical integer value */\n  VNONRELOC,  /* expression has its value in a fixed register;\n                 info = result register */\n  VLOCAL,  /* local variable; info = local register */\n  VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */\n  VINDEXED,  /* indexed variable;\n                ind.vt = whether 't' is register or upvalue;\n                ind.t = table register or upvalue;\n                ind.idx = key's R/K index */\n  VJMP,  /* expression is a test/comparison;\n            info = pc of corresponding jump instruction */\n  VRELOCABLE,  /* expression can put result in any register;\n                  info = instruction pc */\n  VCALL,  /* expression is a function call; info = instruction pc */\n  VVARARG  /* vararg expression; info = instruction pc */\n} expkind;\n\n\n#define vkisvar(k)\t(VLOCAL <= (k) && (k) <= VINDEXED)\n#define vkisinreg(k)\t((k) == VNONRELOC || (k) == VLOCAL)\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    lua_Integer ival;    /* for VKINT */\n    lua_Number nval;  /* for VKFLT */\n    int info;  /* for generic use */\n    struct {  /* for indexed variables (VINDEXED) */\n      short idx;  /* index (R/K) */\n      lu_byte t;  /* table (register or upvalue) */\n      lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */\n    } ind;\n  } u;\n  int t;  /* patch list of 'exit when true' */\n  int f;  /* patch list of 'exit when false' */\n} expdesc;\n\n\n/* description of active local variable */\ntypedef struct Vardesc {\n  short idx;  /* variable index in stack */\n} Vardesc;\n\n\n/* description of pending goto statements and label statements */\ntypedef struct Labeldesc {\n  TString *name;  /* label identifier */\n  int pc;  /* position in code */\n  int line;  /* line where it appeared */\n  lu_byte nactvar;  /* local level where it appears in current block */\n} Labeldesc;\n\n\n/* list of labels or gotos */\ntypedef struct Labellist {\n  Labeldesc *arr;  /* array */\n  int n;  /* number of entries in use */\n  int size;  /* array size */\n} Labellist;\n\n\n/* dynamic structures used by the parser */\ntypedef struct Dyndata {\n  struct {  /* list of active local variables */\n    Vardesc *arr;\n    int n;\n    int size;\n  } actvar;\n  Labellist gt;  /* list of pending gotos */\n  Labellist label;   /* list of active labels */\n} Dyndata;\n\n\n/* control of blocks */\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to 'ncode') */\n  int lasttarget;   /* 'label' of last 'jump label' */\n  int jpc;  /* list of pending jumps to 'pc' */\n  int nk;  /* number of elements in 'k' */\n  int np;  /* number of elements in 'p' */\n  int firstlocal;  /* index of first local var (in Dyndata array) */\n  short nlocvars;  /* number of elements in 'f->locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  lu_byte nups;  /* number of upvalues */\n  lu_byte freereg;  /* first free register */\n} FuncState;\n\n\nLUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                 Dyndata *dyd, const char *name, int firstchar);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lprefix.h",
    "content": "/*\n** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $\n** Definitions for Lua code that must come before any other header file\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lprefix_h\n#define lprefix_h\n\n\n/*\n** Allows POSIX/XSI stuff\n*/\n#if !defined(LUA_USE_C89)\t/* { */\n\n#if !defined(_XOPEN_SOURCE)\n#define _XOPEN_SOURCE           600\n#elif _XOPEN_SOURCE == 0\n#undef _XOPEN_SOURCE  /* use -D_XOPEN_SOURCE=0 to undefine it */\n#endif\n\n/*\n** Allows manipulation of large files in gcc and some other compilers\n*/\n#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)\n#define _LARGEFILE_SOURCE       1\n#define _FILE_OFFSET_BITS       64\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Windows stuff\n*/\n#if defined(_WIN32) \t/* { */\n\n#if !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS  /* avoid warnings about ISO C functions */\n#endif\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUAI_GCPAUSE)\n#define LUAI_GCPAUSE\t200  /* 200% */\n#endif\n\n#if !defined(LUAI_GCMUL)\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n#endif\n\n\n/*\n** a macro to help the creation of a unique random seed when a state is\n** created; the seed is used to randomize hashes.\n*/\n#if !defined(luai_makeseed)\n#include <time.h>\n#define luai_makeseed()\t\tcast(unsigned int, time(NULL))\n#endif\n\n\n\n/*\n** thread state + extra space\n*/\ntypedef struct LX {\n  lu_byte extra_[LUA_EXTRASPACE];\n  lua_State l;\n} LX;\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  LX l;\n  global_State g;\n} LG;\n\n\n\n#define fromstate(L)\t(cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))\n\n\n/*\n** Compute an initial seed as random as possible. Rely on Address Space\n** Layout Randomization (if present) to increase randomness..\n*/\n#define addbuff(b,p,e) \\\n  { size_t t = cast(size_t, e); \\\n    memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }\n\nstatic unsigned int makeseed (lua_State *L) {\n  char buff[4 * sizeof(size_t)];\n  unsigned int h = luai_makeseed();\n  int p = 0;\n  addbuff(buff, p, L);  /* heap variable */\n  addbuff(buff, p, &h);  /* local variable */\n  addbuff(buff, p, luaO_nilobject);  /* global variable */\n  addbuff(buff, p, &lua_newstate);  /* public function */\n  lua_assert(p == sizeof(buff));\n  return luaS_hash(buff, p, h);\n}\n\n\n/*\n** set GCdebt to a new value keeping the value (totalbytes + GCdebt)\n** invariant (and avoiding underflows in 'totalbytes')\n*/\nvoid luaE_setdebt (global_State *g, l_mem debt) {\n  l_mem tb = gettotalbytes(g);\n  lua_assert(tb > 0);\n  if (debt < tb - MAX_LMEM)\n    debt = tb - MAX_LMEM;  /* will make 'totalbytes == MAX_LMEM' */\n  g->totalbytes = tb - debt;\n  g->GCdebt = debt;\n}\n\n\nCallInfo *luaE_extendCI (lua_State *L) {\n  CallInfo *ci = luaM_new(L, CallInfo);\n  lua_assert(L->ci->next == NULL);\n  L->ci->next = ci;\n  ci->previous = L->ci;\n  ci->next = NULL;\n  L->nci++;\n  return ci;\n}\n\n\n/*\n** free all CallInfo structures not in use by a thread\n*/\nvoid luaE_freeCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next = ci->next;\n  ci->next = NULL;\n  while ((ci = next) != NULL) {\n    next = ci->next;\n    luaM_free(L, ci);\n    L->nci--;\n  }\n}\n\n\n/*\n** free half of the CallInfo structures not in use by a thread\n*/\nvoid luaE_shrinkCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next2;  /* next's next */\n  /* while there are two nexts */\n  while (ci->next != NULL && (next2 = ci->next->next) != NULL) {\n    luaM_free(L, ci->next);  /* free next */\n    L->nci--;\n    ci->next = next2;  /* remove 'next' from the list */\n    next2->previous = ci;\n    ci = next2;  /* keep next's next */\n  }\n}\n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  int i; CallInfo *ci;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);\n  L1->stacksize = BASIC_STACK_SIZE;\n  for (i = 0; i < BASIC_STACK_SIZE; i++)\n    setnilvalue(L1->stack + i);  /* erase new stack */\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;\n  /* initialize first ci */\n  ci = &L1->base_ci;\n  ci->next = ci->previous = NULL;\n  ci->callstatus = 0;\n  ci->func = L1->top;\n  setnilvalue(L1->top++);  /* 'function' entry for this 'ci' */\n  ci->top = L1->top + LUA_MINSTACK;\n  L1->ci = ci;\n}\n\n\nstatic void freestack (lua_State *L) {\n  if (L->stack == NULL)\n    return;  /* stack not completely built yet */\n  L->ci = &L->base_ci;  /* free the entire 'ci' list */\n  luaE_freeCI(L);\n  lua_assert(L->nci == 0);\n  luaM_freearray(L, L->stack, L->stacksize);  /* free stack array */\n}\n\n\n/*\n** Create registry table and its predefined values\n*/\nstatic void init_registry (lua_State *L, global_State *g) {\n  TValue temp;\n  /* create registry */\n  Table *registry = luaH_new(L);\n  sethvalue(L, &g->l_registry, registry);\n  luaH_resize(L, registry, LUA_RIDX_LAST, 0);\n  /* registry[LUA_RIDX_MAINTHREAD] = L */\n  setthvalue(L, &temp, L);  /* temp = L */\n  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);\n  /* registry[LUA_RIDX_GLOBALS] = table of globals */\n  sethvalue(L, &temp, luaH_new(L));  /* temp = new table (global table) */\n  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);\n}\n\n\n/*\n** open parts of the state that may cause memory-allocation errors.\n** ('g->version' != NULL flags that the state was completely build)\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  init_registry(L, g);\n  luaS_init(L);\n  luaT_init(L);\n  luaX_init(L);\n  g->gcrunning = 1;  /* allow gc */\n  g->version = lua_version(NULL);\n  luai_userstateopen(L);\n}\n\n\n/*\n** preinitialize a thread with consistent values without allocating\n** any memory (to avoid errors)\n*/\nstatic void preinit_thread (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->ci = NULL;\n  L->nci = 0;\n  L->stacksize = 0;\n  L->twups = L;  /* thread has no upvalues */\n  L->errorJmp = NULL;\n  L->nCcalls = 0;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->nny = 1;\n  L->status = LUA_OK;\n  L->errfunc = 0;\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeallobjects(L);  /* collect all objects */\n  if (g->version)  /* closing a fully built state? */\n    luai_userstateclose(L);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);\n  freestack(L);\n  lua_assert(gettotalbytes(g) == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);  /* free main block */\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  global_State *g = G(L);\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  /* create new thread */\n  L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;\n  L1->marked = luaC_white(g);\n  L1->tt = LUA_TTHREAD;\n  /* link it on list 'allgc' */\n  L1->next = g->allgc;\n  g->allgc = obj2gco(L1);\n  /* anchor it on L stack */\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  preinit_thread(L1, g);\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  /* initialize L1 extra space */\n  memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread),\n         LUA_EXTRASPACE);\n  luai_userstatethread(L, L1);\n  stack_init(L1, L);  /* init stack */\n  lua_unlock(L);\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  LX *l = fromstate(L1);\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L, L1);\n  freestack(L1);\n  luaM_free(L, l);\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));\n  if (l == NULL) return NULL;\n  L = &l->l.l;\n  g = &l->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bitmask(WHITE0BIT);\n  L->marked = luaC_white(g);\n  preinit_thread(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->seed = makeseed(L);\n  g->gcrunning = 0;  /* no GC while building state */\n  g->GCestimate = 0;\n  g->strt.size = g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(&g->l_registry);\n  g->panic = NULL;\n  g->version = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_NORMAL;\n  g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL;\n  g->sweepgc = NULL;\n  g->gray = g->grayagain = NULL;\n  g->weak = g->ephemeron = g->allweak = NULL;\n  g->twups = NULL;\n  g->totalbytes = sizeof(LG);\n  g->GCdebt = 0;\n  g->gcfinnum = 0;\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  return L;\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  close_state(L);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.130 2015/12/16 16:39:38 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n/*\n\n** Some notes about garbage-collected objects: All objects in Lua must\n** be kept somehow accessible until being freed, so all objects always\n** belong to one (and only one) of these lists, using field 'next' of\n** the 'CommonHeader' for the link:\n**\n** 'allgc': all objects not marked for finalization;\n** 'finobj': all objects marked for finalization;\n** 'tobefnz': all objects ready to be finalized; \n** 'fixedgc': all objects that are not to be collected (currently\n** only small strings, such as reserved words).\n\n*/\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/*\n** Atomic type (relative to signals) to better ensure that 'lua_sethook' \n** is thread safe\n*/\n#if !defined(l_signalT)\n#include <signal.h>\n#define l_signalT\tsig_atomic_t\n#endif\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n/* kinds of Garbage Collection */\n#define KGC_NORMAL\t0\n#define KGC_EMERGENCY\t1\t/* gc was forced by an allocation failure */\n\n\ntypedef struct stringtable {\n  TString **hash;\n  int nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** Information about a call.\n** When a thread yields, 'func' is adjusted to pretend that the\n** top function has only the yielded values in its stack; in that\n** case, the actual 'func' value is saved in field 'extra'. \n** When a function calls another with a continuation, 'extra' keeps\n** the function index so that, in case of errors, the continuation\n** function can be called with the correct top.\n*/\ntypedef struct CallInfo {\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  struct CallInfo *previous, *next;  /* dynamic call link */\n  union {\n    struct {  /* only for Lua functions */\n      StkId base;  /* base for this function */\n      const Instruction *savedpc;\n    } l;\n    struct {  /* only for C functions */\n      lua_KFunction k;  /* continuation in case of yields */\n      ptrdiff_t old_errfunc;\n      lua_KContext ctx;  /* context info. in case of yields */\n    } c;\n  } u;\n  ptrdiff_t extra;\n  short nresults;  /* expected number of results from this function */\n  lu_byte callstatus;\n} CallInfo;\n\n\n/*\n** Bits in CallInfo status\n*/\n#define CIST_OAH\t(1<<0)\t/* original value of 'allowhook' */\n#define CIST_LUA\t(1<<1)\t/* call is running a Lua function */\n#define CIST_HOOKED\t(1<<2)\t/* call is running a debug hook */\n#define CIST_FRESH\t(1<<3)\t/* call is running on a fresh invocation\n                                   of luaV_execute */\n#define CIST_YPCALL\t(1<<4)\t/* call is a yieldable protected call */\n#define CIST_TAIL\t(1<<5)\t/* call was tail called */\n#define CIST_HOOKYIELD\t(1<<6)\t/* last hook called yielded */\n#define CIST_LEQ\t(1<<7)  /* using __lt for __le */\n\n#define isLua(ci)\t((ci)->callstatus & CIST_LUA)\n\n/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */\n#define setoah(st,v)\t((st) = ((st) & ~CIST_OAH) | (v))\n#define getoah(st)\t((st) & CIST_OAH)\n\n\n/*\n** 'global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to 'frealloc' */\n  l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */\n  l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */\n  lu_mem GCmemtrav;  /* memory traversed by the GC */\n  lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */\n  stringtable strt;  /* hash table for strings */\n  TValue l_registry;\n  unsigned int seed;  /* randomized seed for hashes */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gckind;  /* kind of GC running */\n  lu_byte gcrunning;  /* true if GC is running */\n  GCObject *allgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* current position of sweep in list */\n  GCObject *finobj;  /* list of collectable objects with finalizers */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of tables with weak values */\n  GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */\n  GCObject *allweak;  /* list of all-weak tables */\n  GCObject *tobefnz;  /* list of userdata to be GC */\n  GCObject *fixedgc;  /* list of objects not to be collected */\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  unsigned int gcfinnum;  /* number of finalizers to call in each GC step */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC 'granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  struct lua_State *mainthread;\n  const lua_Number *version;  /* pointer to version number */\n  TString *memerrmsg;  /* memory-error message */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */\n  TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */\n} global_State;\n\n\n/*\n** 'per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  unsigned short nci;  /* number of items in 'ci' list */\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *oldpc;  /* last pc traced */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  UpVal *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */\n  volatile lua_Hook hook;\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n  int stacksize;\n  int basehookcount;\n  int hookcount;\n  unsigned short nny;  /* number of non-yieldable calls in stack */\n  unsigned short nCcalls;  /* number of nested C calls */\n  l_signalT hookmask;\n  lu_byte allowhook;\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects (only for conversions)\n*/\nunion GCUnion {\n  GCObject gc;  /* common header */\n  struct TString ts;\n  struct Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct lua_State th;  /* thread */\n};\n\n\n#define cast_u(o)\tcast(union GCUnion *, (o))\n\n/* macros to convert a GCObject into a specific value */\n#define gco2ts(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))\n#define gco2u(o)  check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))\n#define gco2lcl(o)  check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))\n#define gco2ccl(o)  check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))\n#define gco2cl(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))\n#define gco2t(o)  check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))\n#define gco2p(o)  check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))\n#define gco2th(o)  check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))\n\n\n/* macro to convert a Lua object into a GCObject */\n#define obj2gco(v) \\\n\tcheck_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))\n\n\n/* actual number of total bytes allocated */\n#define gettotalbytes(g)\tcast(lu_mem, (g)->totalbytes + (g)->GCdebt)\n\nLUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\nLUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);\nLUAI_FUNC void luaE_freeCI (lua_State *L);\nLUAI_FUNC void luaE_shrinkCI (lua_State *L);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n#define MEMERRMSG       \"not enough memory\"\n\n\n/*\n** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to\n** compute its hash\n*/\n#if !defined(LUAI_HASHLIMIT)\n#define LUAI_HASHLIMIT\t\t5\n#endif\n\n\n/*\n** equality for long strings\n*/\nint luaS_eqlngstr (TString *a, TString *b) {\n  size_t len = a->u.lnglen;\n  lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);\n  return (a == b) ||  /* same instance or... */\n    ((len == b->u.lnglen) &&  /* equal length and ... */\n     (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */\n}\n\n\nunsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {\n  unsigned int h = seed ^ cast(unsigned int, l);\n  size_t step = (l >> LUAI_HASHLIMIT) + 1;\n  for (; l >= step; l -= step)\n    h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));\n  return h;\n}\n\n\nunsigned int luaS_hashlongstr (TString *ts) {\n  lua_assert(ts->tt == LUA_TLNGSTR);\n  if (ts->extra == 0) {  /* no hash? */\n    ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);\n    ts->extra = 1;  /* now it has its hash */\n  }\n  return ts->hash;\n}\n\n\n/*\n** resizes the string table\n*/\nvoid luaS_resize (lua_State *L, int newsize) {\n  int i;\n  stringtable *tb = &G(L)->strt;\n  if (newsize > tb->size) {  /* grow table if needed */\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n    for (i = tb->size; i < newsize; i++)\n      tb->hash[i] = NULL;\n  }\n  for (i = 0; i < tb->size; i++) {  /* rehash */\n    TString *p = tb->hash[i];\n    tb->hash[i] = NULL;\n    while (p) {  /* for each node in the list */\n      TString *hnext = p->u.hnext;  /* save next */\n      unsigned int h = lmod(p->hash, newsize);  /* new position */\n      p->u.hnext = tb->hash[h];  /* chain it */\n      tb->hash[h] = p;\n      p = hnext;\n    }\n  }\n  if (newsize < tb->size) {  /* shrink table if needed */\n    /* vanishing slice should be empty */\n    lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n  }\n  tb->size = newsize;\n}\n\n\n/*\n** Clear API string cache. (Entries cannot be empty, so fill them with\n** a non-collectable string.)\n*/\nvoid luaS_clearcache (global_State *g) {\n  int i, j;\n  for (i = 0; i < STRCACHE_N; i++)\n    for (j = 0; j < STRCACHE_M; j++) {\n    if (iswhite(g->strcache[i][j]))  /* will entry be collected? */\n      g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */\n    }\n}\n\n\n/*\n** Initialize the string table and the string cache\n*/\nvoid luaS_init (lua_State *L) {\n  global_State *g = G(L);\n  int i, j;\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  /* pre-create memory-error message */\n  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);\n  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */\n  for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */\n    for (j = 0; j < STRCACHE_M; j++)\n      g->strcache[i][j] = g->memerrmsg;\n}\n\n\n\n/*\n** creates a new string object\n*/\nstatic TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {\n  TString *ts;\n  GCObject *o;\n  size_t totalsize;  /* total size of TString object */\n  totalsize = sizelstring(l);\n  o = luaC_newobj(L, tag, totalsize);\n  ts = gco2ts(o);\n  ts->hash = h;\n  ts->extra = 0;\n  getstr(ts)[l] = '\\0';  /* ending 0 */\n  return ts;\n}\n\n\nTString *luaS_createlngstrobj (lua_State *L, size_t l) {\n  TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);\n  ts->u.lnglen = l;\n  return ts;\n}\n\n\nvoid luaS_remove (lua_State *L, TString *ts) {\n  stringtable *tb = &G(L)->strt;\n  TString **p = &tb->hash[lmod(ts->hash, tb->size)];\n  while (*p != ts)  /* find previous element */\n    p = &(*p)->u.hnext;\n  *p = (*p)->u.hnext;  /* remove element from its list */\n  tb->nuse--;\n}\n\n\n/*\n** checks whether short string exists and reuses it or creates a new one\n*/\nstatic TString *internshrstr (lua_State *L, const char *str, size_t l) {\n  TString *ts;\n  global_State *g = G(L);\n  unsigned int h = luaS_hash(str, l, g->seed);\n  TString **list = &g->strt.hash[lmod(h, g->strt.size)];\n  lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */\n  for (ts = *list; ts != NULL; ts = ts->u.hnext) {\n    if (l == ts->shrlen &&\n        (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {\n      /* found! */\n      if (isdead(g, ts))  /* dead (but not collected yet)? */\n        changewhite(ts);  /* resurrect it */\n      return ts;\n    }\n  }\n  if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {\n    luaS_resize(L, g->strt.size * 2);\n    list = &g->strt.hash[lmod(h, g->strt.size)];  /* recompute with new size */\n  }\n  ts = createstrobj(L, l, LUA_TSHRSTR, h);\n  memcpy(getstr(ts), str, l * sizeof(char));\n  ts->shrlen = cast_byte(l);\n  ts->u.hnext = *list;\n  *list = ts;\n  g->strt.nuse++;\n  return ts;\n}\n\n\n/*\n** new string (with explicit length)\n*/\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  if (l <= LUAI_MAXSHORTLEN)  /* short string? */\n    return internshrstr(L, str, l);\n  else {\n    TString *ts;\n    if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char))\n      luaM_toobig(L);\n    ts = luaS_createlngstrobj(L, l);\n    memcpy(getstr(ts), str, l * sizeof(char));\n    return ts;\n  }\n}\n\n\n/*\n** Create or reuse a zero-terminated string, first checking in the\n** cache (using the string address as a key). The cache can contain\n** only zero-terminated strings, so it is safe to use 'strcmp' to\n** check hits.\n*/\nTString *luaS_new (lua_State *L, const char *str) {\n  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */\n  int j;\n  TString **p = G(L)->strcache[i];\n  for (j = 0; j < STRCACHE_M; j++) {\n    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */\n      return p[j];  /* that is it */\n  }\n  /* normal route */\n  for (j = STRCACHE_M - 1; j > 0; j--)\n    p[j] = p[j - 1];  /* move out last element */\n  /* new element is first in the list */\n  p[0] = luaS_newlstr(L, str, strlen(str));\n  return p[0];\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s) {\n  Udata *u;\n  GCObject *o;\n  if (s > MAX_SIZE - sizeof(Udata))\n    luaM_toobig(L);\n  o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s));\n  u = gco2u(o);\n  u->len = s;\n  u->metatable = NULL;\n  setuservalue(L, u, luaO_nilobject);\n  return u;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizelstring(l)  (sizeof(union UTString) + ((l) + 1) * sizeof(char))\n\n#define sizeludata(l)\t(sizeof(union UUdata) + (l))\n#define sizeudata(u)\tsizeludata((u)->len)\n\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n\n/*\n** test whether a string is a reserved word\n*/\n#define isreserved(s)\t((s)->tt == LUA_TSHRSTR && (s)->extra > 0)\n\n\n/*\n** equality for short strings, which are always internalized\n*/\n#define eqshrstr(a,b)\tcheck_exp((a)->tt == LUA_TSHRSTR, (a) == (b))\n\n\nLUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);\nLUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);\nLUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC void luaS_clearcache (global_State *g);\nLUAI_FUNC void luaS_init (lua_State *L);\nLUAI_FUNC void luaS_remove (lua_State *L, TString *ts);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\nLUAI_FUNC TString *luaS_new (lua_State *L, const char *str);\nLUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.251 2016/05/20 14:13:21 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <float.h>\n#include <limits.h>\n#include <locale.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** maximum number of captures that a pattern can do during\n** pattern-matching. This limit is arbitrary, but must fit in\n** an unsigned char.\n*/\n#if !defined(LUA_MAXCAPTURES)\n#define LUA_MAXCAPTURES\t\t32\n#endif\n\n\n/* macro to 'unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n\n/*\n** Some sizes are better limited to fit in 'int', but must also fit in\n** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)\n*/\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n#define MAXSIZE  \\\n\t(sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))\n\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, (lua_Integer)l);\n  return 1;\n}\n\n\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer start = posrelat(luaL_checkinteger(L, 2), l);\n  lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (lua_Integer)l) end = l;\n  if (start <= end)\n    lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l, i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i = 0; i < l; i++)\n    p[i] = s[l - i - 1];\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = tolower(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = toupper(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_rep (lua_State *L) {\n  size_t l, lsep;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer n = luaL_checkinteger(L, 2);\n  const char *sep = luaL_optlstring(L, 3, \"\", &lsep);\n  if (n <= 0) lua_pushliteral(L, \"\");\n  else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */\n    return luaL_error(L, \"resulting string too large\");\n  else {\n    size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;\n    luaL_Buffer b;\n    char *p = luaL_buffinitsize(L, &b, totallen);\n    while (n-- > 1) {  /* first n-1 copies (followed by separator) */\n      memcpy(p, s, l * sizeof(char)); p += l;\n      if (lsep > 0) {  /* empty 'memcpy' is not that cheap */\n        memcpy(p, sep, lsep * sizeof(char));\n        p += lsep;\n      }\n    }\n    memcpy(p, s, l * sizeof(char));  /* last copy (not followed by separator) */\n    luaL_pushresultsize(&b, totallen);\n  }\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi < 1) posi = 1;\n  if (pose > (lua_Integer)l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* arithmetic overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  char *p = luaL_buffinitsize(L, &b, n);\n  for (i=1; i<=n; i++) {\n    lua_Integer c = luaL_checkinteger(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"value out of range\");\n    p[i - 1] = uchar(c);\n  }\n  luaL_pushresultsize(&b, n);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void *b, size_t size, void *B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer *) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  int strip = lua_toboolean(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b, strip) != 0)\n    return luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end ('\\0') of source string */\n  const char *p_end;  /* end ('\\0') of pattern */\n  lua_State *L;\n  int matchdepth;  /* control for recursive depth (to avoid C stack overflow) */\n  unsigned char level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n/* recursive function */\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\n/* maximum recursion depth for 'match' */\n#if !defined(MAXCCALLS)\n#define MAXCCALLS\t200\n#endif\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index %%%d\", l + 1);\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (p == ms->p_end)\n        luaL_error(ms->L, \"malformed pattern (ends with '%%')\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a ']' */\n        if (p == ms->p_end)\n          luaL_error(ms->L, \"malformed pattern (missing ']')\");\n        if (*(p++) == L_ESC && p < ms->p_end)\n          p++;  /* skip escapes (e.g. '%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'g' : res = isgraph(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;  /* deprecated option */\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the '^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (MatchState *ms, const char *s, const char *p,\n                        const char *ep) {\n  if (s >= ms->src_end)\n    return 0;\n  else {\n    int c = uchar(*s);\n    switch (*p) {\n      case '.': return 1;  /* matches any char */\n      case L_ESC: return match_class(c, uchar(*(p+1)));\n      case '[': return matchbracketclass(c, p, ep-1);\n      default:  return (uchar(*p) == c);\n    }\n  }\n}\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (p >= ms->p_end - 1)\n    luaL_error(ms->L, \"malformed pattern (missing arguments to '%%b')\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while (singlematch(ms, s + i, p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (singlematch(ms, s, p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  if (ms->matchdepth-- == 0)\n    luaL_error(ms->L, \"pattern too complex\");\n  init: /* using goto's to optimize tail recursion */\n  if (p != ms->p_end) {  /* end of pattern? */\n    switch (*p) {\n      case '(': {  /* start capture */\n        if (*(p + 1) == ')')  /* position capture? */\n          s = start_capture(ms, s, p + 2, CAP_POSITION);\n        else\n          s = start_capture(ms, s, p + 1, CAP_UNFINISHED);\n        break;\n      }\n      case ')': {  /* end capture */\n        s = end_capture(ms, s, p + 1);\n        break;\n      }\n      case '$': {\n        if ((p + 1) != ms->p_end)  /* is the '$' the last char in pattern? */\n          goto dflt;  /* no; go to default */\n        s = (s == ms->src_end) ? s : NULL;  /* check end of string */\n        break;\n      }\n      case L_ESC: {  /* escaped sequences not in the format class[*+?-]? */\n        switch (*(p + 1)) {\n          case 'b': {  /* balanced string? */\n            s = matchbalance(ms, s, p + 2);\n            if (s != NULL) {\n              p += 4; goto init;  /* return match(ms, s, p + 4); */\n            }  /* else fail (s == NULL) */\n            break;\n          }\n          case 'f': {  /* frontier? */\n            const char *ep; char previous;\n            p += 2;\n            if (*p != '[')\n              luaL_error(ms->L, \"missing '[' after '%%f' in pattern\");\n            ep = classend(ms, p);  /* points to what is next */\n            previous = (s == ms->src_init) ? '\\0' : *(s - 1);\n            if (!matchbracketclass(uchar(previous), p, ep - 1) &&\n               matchbracketclass(uchar(*s), p, ep - 1)) {\n              p = ep; goto init;  /* return match(ms, s, ep); */\n            }\n            s = NULL;  /* match failed */\n            break;\n          }\n          case '0': case '1': case '2': case '3':\n          case '4': case '5': case '6': case '7':\n          case '8': case '9': {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p + 1)));\n            if (s != NULL) {\n              p += 2; goto init;  /* return match(ms, s, p + 2) */\n            }\n            break;\n          }\n          default: goto dflt;\n        }\n        break;\n      }\n      default: dflt: {  /* pattern class plus optional suffix */\n        const char *ep = classend(ms, p);  /* points to optional suffix */\n        /* does not match at least once? */\n        if (!singlematch(ms, s, p, ep)) {\n          if (*ep == '*' || *ep == '?' || *ep == '-') {  /* accept empty? */\n            p = ep + 1; goto init;  /* return match(ms, s, ep + 1); */\n          }\n          else  /* '+' or no suffix */\n            s = NULL;  /* fail */\n        }\n        else {  /* matched once */\n          switch (*ep) {  /* handle optional suffix */\n            case '?': {  /* optional */\n              const char *res;\n              if ((res = match(ms, s + 1, ep + 1)) != NULL)\n                s = res;\n              else {\n                p = ep + 1; goto init;  /* else return match(ms, s, ep + 1); */\n              }\n              break;\n            }\n            case '+':  /* 1 or more repetitions */\n              s++;  /* 1 match already done */\n              /* FALLTHROUGH */\n            case '*':  /* 0 or more repetitions */\n              s = max_expand(ms, s, p, ep);\n              break;\n            case '-':  /* 0 or more repetitions (minimum) */\n              s = min_expand(ms, s, p, ep);\n              break;\n            default:  /* no suffix */\n              s++; p = ep; goto init;  /* return match(ms, s + 1, ep); */\n          }\n        }\n        break;\n      }\n    }\n  }\n  ms->matchdepth++;\n  return s;\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative 'l1' */\n  else {\n    const char *init;  /* to search for a '*s2' inside 's1' */\n    l2--;  /* 1st char will be checked by 'memchr' */\n    l1 = l1-l2;  /* 's2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct 'l1' and 's1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index %%%d\", i + 1);\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\n/* check whether pattern has no special characters */\nstatic int nospecials (const char *p, size_t l) {\n  size_t upto = 0;\n  do {\n    if (strpbrk(p + upto, SPECIALS))\n      return 0;  /* pattern has a special character */\n    upto += strlen(p + upto) + 1;  /* may have more after \\0 */\n  } while (upto <= l);\n  return 1;  /* no special chars found */\n}\n\n\nstatic void prepstate (MatchState *ms, lua_State *L,\n                       const char *s, size_t ls, const char *p, size_t lp) {\n  ms->L = L;\n  ms->matchdepth = MAXCCALLS;\n  ms->src_init = s;\n  ms->src_end = s + ls;\n  ms->p_end = p + lp;\n}\n\n\nstatic void reprepstate (MatchState *ms) {\n  ms->level = 0;\n  lua_assert(ms->matchdepth == MAXCCALLS);\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);\n  if (init < 1) init = 1;\n  else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */\n    lua_pushnil(L);  /* cannot find anything */\n    return 1;\n  }\n  /* explicit request or no special characters? */\n  if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {\n    /* do a plain search */\n    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);\n    if (s2) {\n      lua_pushinteger(L, (s2 - s) + 1);\n      lua_pushinteger(L, (s2 - s) + lp);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    const char *s1 = s + init - 1;\n    int anchor = (*p == '^');\n    if (anchor) {\n      p++; lp--;  /* skip anchor character */\n    }\n    prepstate(&ms, L, s, ls, p, lp);\n    do {\n      const char *res;\n      reprepstate(&ms);\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, (s1 - s) + 1);  /* start */\n          lua_pushinteger(L, res - s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\n/* state for 'gmatch' */\ntypedef struct GMatchState {\n  const char *src;  /* current position */\n  const char *p;  /* pattern */\n  const char *lastmatch;  /* end of last match */\n  MatchState ms;  /* match state */\n} GMatchState;\n\n\nstatic int gmatch_aux (lua_State *L) {\n  GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));\n  const char *src;\n  gm->ms.L = L;\n  for (src = gm->src; src <= gm->ms.src_end; src++) {\n    const char *e;\n    reprepstate(&gm->ms);\n    if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {\n      gm->src = gm->lastmatch = e;\n      return push_captures(&gm->ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  GMatchState *gm;\n  lua_settop(L, 2);  /* keep them on closure to avoid being collected */\n  gm = (GMatchState *)lua_newuserdata(L, sizeof(GMatchState));\n  prepstate(&gm->ms, L, s, ls, p, lp);\n  gm->src = s; gm->p = p; gm->lastmatch = NULL;\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  lua_State *L = ms->L;\n  const char *news = lua_tolstring(L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i]))) {\n        if (news[i] != L_ESC)\n          luaL_error(L, \"invalid use of '%c' in replacement string\", L_ESC);\n        luaL_addchar(b, news[i]);\n      }\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_tolstring(L, -1, NULL);  /* if number, convert it to string */\n        lua_remove(L, -2);  /* remove original value */\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                       const char *e, int tr) {\n  lua_State *L = ms->L;\n  switch (tr) {\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n    default: {  /* LUA_TNUMBER or LUA_TSTRING */\n      add_s(ms, b, s, e);\n      return;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1));\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl, lp;\n  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */\n  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */\n  const char *lastmatch = NULL;  /* end of last match */\n  int tr = lua_type(L, 3);  /* replacement type */\n  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */\n  int anchor = (*p == '^');\n  lua_Integer n = 0;  /* replacement count */\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  if (anchor) {\n    p++; lp--;  /* skip anchor character */\n  }\n  prepstate(&ms, L, src, srcl, p, lp);\n  while (n < max_s) {\n    const char *e;\n    reprepstate(&ms);  /* (re)prepare state for new match */\n    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */\n      n++;\n      add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */\n      src = lastmatch = e;\n    }\n    else if (src < ms.src_end)  /* otherwise, skip one character */\n      luaL_addchar(&b, *src++);\n    else break;  /* end of subject */\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** STRING FORMAT\n** =======================================================\n*/\n\n#if !defined(lua_number2strx)\t/* { */\n\n/*\n** Hexadecimal floating-point formatter\n*/\n\n#include <math.h>\n\n#define SIZELENMOD\t(sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))\n\n\n/*\n** Number of bits that goes into the first digit. It can be any value\n** between 1 and 4; the following definition tries to align the number\n** to nibble boundaries by making what is left after that first digit a\n** multiple of 4.\n*/\n#define L_NBFD\t\t((l_mathlim(MANT_DIG) - 1)%4 + 1)\n\n\n/*\n** Add integer part of 'x' to buffer and return new 'x'\n*/\nstatic lua_Number adddigit (char *buff, int n, lua_Number x) {\n  lua_Number dd = l_mathop(floor)(x);  /* get integer part from 'x' */\n  int d = (int)dd;\n  buff[n] = (d < 10 ? d + '0' : d - 10 + 'a');  /* add to buffer */\n  return x - dd;  /* return what is left */\n}\n\n\nstatic int num2straux (char *buff, int sz, lua_Number x) {\n  if (x != x || x == HUGE_VAL || x == -HUGE_VAL)  /* inf or NaN? */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT, x);  /* equal to '%g' */\n  else if (x == 0) {  /* can be -0... */\n    /* create \"0\" or \"-0\" followed by exponent */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT \"x0p+0\", x);\n  }\n  else {\n    int e;\n    lua_Number m = l_mathop(frexp)(x, &e);  /* 'x' fraction and exponent */\n    int n = 0;  /* character count */\n    if (m < 0) {  /* is number negative? */\n      buff[n++] = '-';  /* add signal */\n      m = -m;  /* make it positive */\n    }\n    buff[n++] = '0'; buff[n++] = 'x';  /* add \"0x\" */\n    m = adddigit(buff, n++, m * (1 << L_NBFD));  /* add first digit */\n    e -= L_NBFD;  /* this digit goes before the radix point */\n    if (m > 0) {  /* more digits? */\n      buff[n++] = lua_getlocaledecpoint();  /* add radix point */\n      do {  /* add as many digits as needed */\n        m = adddigit(buff, n++, m * 16);\n      } while (m > 0);\n    }\n    n += l_sprintf(buff + n, sz - n, \"p%+d\", e);  /* add exponent */\n    lua_assert(n < sz);\n    return n;\n  }\n}\n\n\nstatic int lua_number2strx (lua_State *L, char *buff, int sz,\n                            const char *fmt, lua_Number x) {\n  int n = num2straux(buff, sz, x);\n  if (fmt[SIZELENMOD] == 'A') {\n    int i;\n    for (i = 0; i < n; i++)\n      buff[i] = toupper(uchar(buff[i]));\n  }\n  else if (fmt[SIZELENMOD] != 'a')\n    luaL_error(L, \"modifiers for format '%%a'/'%%A' not implemented\");\n  return n;\n}\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Maximum size of each formatted item. This maximum size is produced\n** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',\n** and '\\0') + number of decimal digits to represent maxfloat (which\n** is maximum exponent + 1). (99+3+1 then rounded to 120 for \"extra\n** expenses\", such as locale-dependent stuff)\n*/\n#define MAX_ITEM        (120 + l_mathlim(MAX_10_EXP))\n\n\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n\n/*\n** maximum size of each format specification (such as \"%-099.99d\")\n*/\n#define MAX_FORMAT\t32\n\n\nstatic void addquoted (luaL_Buffer *b, const char *s, size_t len) {\n  luaL_addchar(b, '\"');\n  while (len--) {\n    if (*s == '\"' || *s == '\\\\' || *s == '\\n') {\n      luaL_addchar(b, '\\\\');\n      luaL_addchar(b, *s);\n    }\n    else if (iscntrl(uchar(*s))) {\n      char buff[10];\n      if (!isdigit(uchar(*(s+1))))\n        l_sprintf(buff, sizeof(buff), \"\\\\%d\", (int)uchar(*s));\n      else\n        l_sprintf(buff, sizeof(buff), \"\\\\%03d\", (int)uchar(*s));\n      luaL_addstring(b, buff);\n    }\n    else\n      luaL_addchar(b, *s);\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\n\n/*\n** Ensures the 'buff' string uses a dot as the radix character.\n*/\nstatic void checkdp (char *buff, int nb) {\n  if (memchr(buff, '.', nb) == NULL) {  /* no dot? */\n    char point = lua_getlocaledecpoint();  /* try locale point */\n    char *ppoint = memchr(buff, point, nb);\n    if (ppoint) *ppoint = '.';  /* change it to a dot */\n  }\n}\n\n\nstatic void addliteral (lua_State *L, luaL_Buffer *b, int arg) {\n  switch (lua_type(L, arg)) {\n    case LUA_TSTRING: {\n      size_t len;\n      const char *s = lua_tolstring(L, arg, &len);\n      addquoted(b, s, len);\n      break;\n    }\n    case LUA_TNUMBER: {\n      char *buff = luaL_prepbuffsize(b, MAX_ITEM);\n      int nb;\n      if (!lua_isinteger(L, arg)) {  /* float? */\n        lua_Number n = lua_tonumber(L, arg);  /* write as hexa ('%a') */\n        nb = lua_number2strx(L, buff, MAX_ITEM, \"%\" LUA_NUMBER_FRMLEN \"a\", n);\n        checkdp(buff, nb);  /* ensure it uses a dot */\n      }\n      else {  /* integers */\n        lua_Integer n = lua_tointeger(L, arg);\n        const char *format = (n == LUA_MININTEGER)  /* corner case? */\n                           ? \"0x%\" LUA_INTEGER_FRMLEN \"x\"  /* use hexa */\n                           : LUA_INTEGER_FMT;  /* else use default format */\n        nb = l_sprintf(buff, MAX_ITEM, format, n);\n      }\n      luaL_addsize(b, nb);\n      break;\n    }\n    case LUA_TNIL: case LUA_TBOOLEAN: {\n      luaL_tolstring(L, arg, NULL);\n      luaL_addvalue(b);\n      break;\n    }\n    default: {\n      luaL_argerror(L, arg, \"value has no literal form\");\n    }\n  }\n}\n\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));\n  form += (p - strfrmt) + 1;\n  *form = '\\0';\n  return p;\n}\n\n\n/*\n** add length modifier into formats\n*/\nstatic void addlenmod (char *form, const char *lenmod) {\n  size_t l = strlen(form);\n  size_t lm = strlen(lenmod);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, lenmod);\n  form[l + lm - 1] = spec;\n  form[l + lm] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format ('%...') */\n      char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */\n      int nb = 0;  /* number of bytes in added item */\n      if (++arg > top)\n        luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));\n          break;\n        }\n        case 'd': case 'i':\n        case 'o': case 'u': case 'x': case 'X': {\n          lua_Integer n = luaL_checkinteger(L, arg);\n          addlenmod(form, LUA_INTEGER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, n);\n          break;\n        }\n        case 'a': case 'A':\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = lua_number2strx(L, buff, MAX_ITEM, form,\n                                  luaL_checknumber(L, arg));\n          break;\n        case 'e': case 'E': case 'f':\n        case 'g': case 'G': {\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, luaL_checknumber(L, arg));\n          break;\n        }\n        case 'q': {\n          addliteral(L, &b, arg);\n          break;\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_tolstring(L, arg, &l);\n          if (form[2] == '\\0')  /* no modifiers? */\n            luaL_addvalue(&b);  /* keep entire string */\n          else {\n            luaL_argcheck(L, l == strlen(s), arg, \"string contains zeros\");\n            if (!strchr(form, '.') && l >= 100) {\n              /* no precision and string is too long to be formatted */\n              luaL_addvalue(&b);  /* keep entire string */\n            }\n            else {  /* format the string into 'buff' */\n              nb = l_sprintf(buff, MAX_ITEM, form, s);\n              lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */\n            }\n          }\n          break;\n        }\n        default: {  /* also treat cases 'pnLlh' */\n          return luaL_error(L, \"invalid option '%%%c' to 'format'\",\n                               *(strfrmt - 1));\n        }\n      }\n      lua_assert(nb < MAX_ITEM);\n      luaL_addsize(&b, nb);\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** PACK/UNPACK\n** =======================================================\n*/\n\n\n/* value used for padding */\n#if !defined(LUAL_PACKPADBYTE)\n#define LUAL_PACKPADBYTE\t\t0x00\n#endif\n\n/* maximum size for the binary representation of an integer */\n#define MAXINTSIZE\t16\n\n/* number of bits in a character */\n#define NB\tCHAR_BIT\n\n/* mask for one character (NB 1's) */\n#define MC\t((1 << NB) - 1)\n\n/* size of a lua_Integer */\n#define SZINT\t((int)sizeof(lua_Integer))\n\n\n/* dummy union to get native endianness */\nstatic const union {\n  int dummy;\n  char little;  /* true iff machine is little endian */\n} nativeendian = {1};\n\n\n/* dummy structure to get native alignment requirements */\nstruct cD {\n  char c;\n  union { double d; void *p; lua_Integer i; lua_Number n; } u;\n};\n\n#define MAXALIGN\t(offsetof(struct cD, u))\n\n\n/*\n** Union for serializing floats\n*/\ntypedef union Ftypes {\n  float f;\n  double d;\n  lua_Number n;\n  char buff[5 * sizeof(lua_Number)];  /* enough for any float type */\n} Ftypes;\n\n\n/*\n** information to pack/unpack stuff\n*/\ntypedef struct Header {\n  lua_State *L;\n  int islittle;\n  int maxalign;\n} Header;\n\n\n/*\n** options for pack/unpack\n*/\ntypedef enum KOption {\n  Kint,\t\t/* signed integers */\n  Kuint,\t/* unsigned integers */\n  Kfloat,\t/* floating-point numbers */\n  Kchar,\t/* fixed-length strings */\n  Kstring,\t/* strings with prefixed length */\n  Kzstr,\t/* zero-terminated strings */\n  Kpadding,\t/* padding */\n  Kpaddalign,\t/* padding for alignment */\n  Knop\t\t/* no-op (configuration or spaces) */\n} KOption;\n\n\n/*\n** Read an integer numeral from string 'fmt' or return 'df' if\n** there is no numeral\n*/\nstatic int digit (int c) { return '0' <= c && c <= '9'; }\n\nstatic int getnum (const char **fmt, int df) {\n  if (!digit(**fmt))  /* no number? */\n    return df;  /* return default value */\n  else {\n    int a = 0;\n    do {\n      a = a*10 + (*((*fmt)++) - '0');\n    } while (digit(**fmt) && a <= ((int)MAXSIZE - 9)/10);\n    return a;\n  }\n}\n\n\n/*\n** Read an integer numeral and raises an error if it is larger\n** than the maximum size for integers.\n*/\nstatic int getnumlimit (Header *h, const char **fmt, int df) {\n  int sz = getnum(fmt, df);\n  if (sz > MAXINTSIZE || sz <= 0)\n    luaL_error(h->L, \"integral size (%d) out of limits [1,%d]\",\n                     sz, MAXINTSIZE);\n  return sz;\n}\n\n\n/*\n** Initialize Header\n*/\nstatic void initheader (lua_State *L, Header *h) {\n  h->L = L;\n  h->islittle = nativeendian.little;\n  h->maxalign = 1;\n}\n\n\n/*\n** Read and classify next option. 'size' is filled with option's size.\n*/\nstatic KOption getoption (Header *h, const char **fmt, int *size) {\n  int opt = *((*fmt)++);\n  *size = 0;  /* default */\n  switch (opt) {\n    case 'b': *size = sizeof(char); return Kint;\n    case 'B': *size = sizeof(char); return Kuint;\n    case 'h': *size = sizeof(short); return Kint;\n    case 'H': *size = sizeof(short); return Kuint;\n    case 'l': *size = sizeof(long); return Kint;\n    case 'L': *size = sizeof(long); return Kuint;\n    case 'j': *size = sizeof(lua_Integer); return Kint;\n    case 'J': *size = sizeof(lua_Integer); return Kuint;\n    case 'T': *size = sizeof(size_t); return Kuint;\n    case 'f': *size = sizeof(float); return Kfloat;\n    case 'd': *size = sizeof(double); return Kfloat;\n    case 'n': *size = sizeof(lua_Number); return Kfloat;\n    case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;\n    case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;\n    case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;\n    case 'c':\n      *size = getnum(fmt, -1);\n      if (*size == -1)\n        luaL_error(h->L, \"missing size for format option 'c'\");\n      return Kchar;\n    case 'z': return Kzstr;\n    case 'x': *size = 1; return Kpadding;\n    case 'X': return Kpaddalign;\n    case ' ': break;\n    case '<': h->islittle = 1; break;\n    case '>': h->islittle = 0; break;\n    case '=': h->islittle = nativeendian.little; break;\n    case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break;\n    default: luaL_error(h->L, \"invalid format option '%c'\", opt);\n  }\n  return Knop;\n}\n\n\n/*\n** Read, classify, and fill other details about the next option.\n** 'psize' is filled with option's size, 'notoalign' with its\n** alignment requirements.\n** Local variable 'size' gets the size to be aligned. (Kpadal option\n** always gets its full alignment, other options are limited by \n** the maximum alignment ('maxalign'). Kchar option needs no alignment\n** despite its size.\n*/\nstatic KOption getdetails (Header *h, size_t totalsize,\n                           const char **fmt, int *psize, int *ntoalign) {\n  KOption opt = getoption(h, fmt, psize);\n  int align = *psize;  /* usually, alignment follows size */\n  if (opt == Kpaddalign) {  /* 'X' gets alignment from following option */\n    if (**fmt == '\\0' || getoption(h, fmt, &align) == Kchar || align == 0)\n      luaL_argerror(h->L, 1, \"invalid next option for option 'X'\");\n  }\n  if (align <= 1 || opt == Kchar)  /* need no alignment? */\n    *ntoalign = 0;\n  else {\n    if (align > h->maxalign)  /* enforce maximum alignment */\n      align = h->maxalign;\n    if ((align & (align - 1)) != 0)  /* is 'align' not a power of 2? */\n      luaL_argerror(h->L, 1, \"format asks for alignment not power of 2\");\n    *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1);\n  }\n  return opt;\n}\n\n\n/*\n** Pack integer 'n' with 'size' bytes and 'islittle' endianness.\n** The final 'if' handles the case when 'size' is larger than\n** the size of a Lua integer, correcting the extra sign-extension\n** bytes if necessary (by default they would be zeros).\n*/\nstatic void packint (luaL_Buffer *b, lua_Unsigned n,\n                     int islittle, int size, int neg) {\n  char *buff = luaL_prepbuffsize(b, size);\n  int i;\n  buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */\n  for (i = 1; i < size; i++) {\n    n >>= NB;\n    buff[islittle ? i : size - 1 - i] = (char)(n & MC);\n  }\n  if (neg && size > SZINT) {  /* negative number need sign extension? */\n    for (i = SZINT; i < size; i++)  /* correct extra bytes */\n      buff[islittle ? i : size - 1 - i] = (char)MC;\n  }\n  luaL_addsize(b, size);  /* add result to buffer */\n}\n\n\n/*\n** Copy 'size' bytes from 'src' to 'dest', correcting endianness if\n** given 'islittle' is different from native endianness.\n*/\nstatic void copywithendian (volatile char *dest, volatile const char *src,\n                            int size, int islittle) {\n  if (islittle == nativeendian.little) {\n    while (size-- != 0)\n      *(dest++) = *(src++);\n  }\n  else {\n    dest += size - 1;\n    while (size-- != 0)\n      *(dest--) = *(src++);\n  }\n}\n\n\nstatic int str_pack (lua_State *L) {\n  luaL_Buffer b;\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  int arg = 1;  /* current argument to pack */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  lua_pushnil(L);  /* mark to separate arguments from string buffer */\n  luaL_buffinit(L, &b);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    totalsize += ntoalign + size;\n    while (ntoalign-- > 0)\n     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */\n    arg++;\n    switch (opt) {\n      case Kint: {  /* signed integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT) {  /* need overflow check? */\n          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);\n          luaL_argcheck(L, -lim <= n && n < lim, arg, \"integer overflow\");\n        }\n        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));\n        break;\n      }\n      case Kuint: {  /* unsigned integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT)  /* need overflow check? */\n          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),\n                           arg, \"unsigned overflow\");\n        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);\n        break;\n      }\n      case Kfloat: {  /* floating-point options */\n        volatile Ftypes u;\n        char *buff = luaL_prepbuffsize(&b, size);\n        lua_Number n = luaL_checknumber(L, arg);  /* get argument */\n        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */\n        else if (size == sizeof(u.d)) u.d = (double)n;\n        else u.n = n;\n        /* move 'u' to final result, correcting endianness if needed */\n        copywithendian(buff, u.buff, size, h.islittle);\n        luaL_addsize(&b, size);\n        break;\n      }\n      case Kchar: {  /* fixed-size string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, len <= (size_t)size, arg,\n                         \"string longer than given size\");\n        luaL_addlstring(&b, s, len);  /* add string */\n        while (len++ < (size_t)size)  /* pad extra space */\n          luaL_addchar(&b, LUAL_PACKPADBYTE);\n        break;\n      }\n      case Kstring: {  /* strings with length count */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, size >= (int)sizeof(size_t) ||\n                         len < ((size_t)1 << (size * NB)),\n                         arg, \"string length does not fit in given size\");\n        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */\n        luaL_addlstring(&b, s, len);\n        totalsize += len;\n        break;\n      }\n      case Kzstr: {  /* zero-terminated string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, strlen(s) == len, arg, \"string contains zeros\");\n        luaL_addlstring(&b, s, len);\n        luaL_addchar(&b, '\\0');  /* add zero at the end */\n        totalsize += len + 1;\n        break;\n      }\n      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */\n      case Kpaddalign: case Knop:\n        arg--;  /* undo increment */\n        break;\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_packsize (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    size += ntoalign;  /* total space used by option */\n    luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,\n                     \"format result too large\");\n    totalsize += size;\n    switch (opt) {\n      case Kstring:  /* strings with length count */\n      case Kzstr:    /* zero-terminated string */\n        luaL_argerror(L, 1, \"variable-length format\");\n        /* call never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:  break;\n    }\n  }\n  lua_pushinteger(L, (lua_Integer)totalsize);\n  return 1;\n}\n\n\n/*\n** Unpack an integer with 'size' bytes and 'islittle' endianness.\n** If size is smaller than the size of a Lua integer and integer\n** is signed, must do sign extension (propagating the sign to the\n** higher bits); if size is larger than the size of a Lua integer,\n** it must check the unread bytes to see whether they do not cause an\n** overflow.\n*/\nstatic lua_Integer unpackint (lua_State *L, const char *str,\n                              int islittle, int size, int issigned) {\n  lua_Unsigned res = 0;\n  int i;\n  int limit = (size  <= SZINT) ? size : SZINT;\n  for (i = limit - 1; i >= 0; i--) {\n    res <<= NB;\n    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];\n  }\n  if (size < SZINT) {  /* real size smaller than lua_Integer? */\n    if (issigned) {  /* needs sign extension? */\n      lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);\n      res = ((res ^ mask) - mask);  /* do sign extension */\n    }\n  }\n  else if (size > SZINT) {  /* must check unread bytes */\n    int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;\n    for (i = limit; i < size; i++) {\n      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)\n        luaL_error(L, \"%d-byte integer does not fit into Lua Integer\", size);\n    }\n  }\n  return (lua_Integer)res;\n}\n\n\nstatic int str_unpack (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);\n  size_t ld;\n  const char *data = luaL_checklstring(L, 2, &ld);\n  size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;\n  int n = 0;  /* number of results */\n  luaL_argcheck(L, pos <= ld, 3, \"initial position out of string\");\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);\n    if ((size_t)ntoalign + size > ~pos || pos + ntoalign + size > ld)\n      luaL_argerror(L, 2, \"data string too short\");\n    pos += ntoalign;  /* skip alignment */\n    /* stack space for item + next position */\n    luaL_checkstack(L, 2, \"too many results\");\n    n++;\n    switch (opt) {\n      case Kint:\n      case Kuint: {\n        lua_Integer res = unpackint(L, data + pos, h.islittle, size,\n                                       (opt == Kint));\n        lua_pushinteger(L, res);\n        break;\n      }\n      case Kfloat: {\n        volatile Ftypes u;\n        lua_Number num;\n        copywithendian(u.buff, data + pos, size, h.islittle);\n        if (size == sizeof(u.f)) num = (lua_Number)u.f;\n        else if (size == sizeof(u.d)) num = (lua_Number)u.d;\n        else num = u.n;\n        lua_pushnumber(L, num);\n        break;\n      }\n      case Kchar: {\n        lua_pushlstring(L, data + pos, size);\n        break;\n      }\n      case Kstring: {\n        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);\n        luaL_argcheck(L, pos + len + size <= ld, 2, \"data string too short\");\n        lua_pushlstring(L, data + pos + size, len);\n        pos += len;  /* skip string */\n        break;\n      }\n      case Kzstr: {\n        size_t len = (int)strlen(data + pos);\n        lua_pushlstring(L, data + pos, len);\n        pos += len + 1;  /* skip string plus final '\\0' */\n        break;\n      }\n      case Kpaddalign: case Kpadding: case Knop:\n        n--;  /* undo increment */\n        break;\n    }\n    pos += size;\n  }\n  lua_pushinteger(L, pos + 1);  /* next position */\n  return n + 1;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {\"pack\", str_pack},\n  {\"packsize\", str_packsize},\n  {\"unpack\", str_unpack},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* table to be metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);  /* copy table */\n  lua_setmetatable(L, -2);  /* set table as metatable for strings */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* get string library */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = string */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUAMOD_API int luaopen_string (lua_State *L) {\n  luaL_newlib(L, strlib);\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.117 2015/11/19 19:16:22 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest 'n' such that\n** more than half the slots between 1 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the 'original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <limits.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/*\n** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is\n** the largest integer such that MAXASIZE fits in an unsigned int.\n*/\n#define MAXABITS\tcast_int(sizeof(int) * CHAR_BIT - 1)\n#define MAXASIZE\t(1u << MAXABITS)\n\n/*\n** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest\n** integer such that 2^MAXHBITS fits in a signed int. (Note that the\n** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still\n** fits comfortably in an unsigned int.)\n*/\n#define MAXHBITS\t(MAXABITS - 1)\n\n\n#define hashpow2(t,n)\t\t(gnode(t, lmod((n), sizenode(t))))\n\n#define hashstr(t,str)\t\thashpow2(t, (str)->hash)\n#define hashboolean(t,p)\thashpow2(t, p)\n#define hashint(t,i)\t\thashpow2(t, i)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, point2uint(p))\n\n\n#define dummynode\t\t(&dummynode_)\n\n#define isdummy(n)\t\t((n) == dummynode)\n\nstatic const Node dummynode_ = {\n  {NILCONSTANT},  /* value */\n  {{NILCONSTANT, 0}}  /* key */\n};\n\n\n/*\n** Hash for floating-point numbers.\n** The main computation should be just\n**     n = frexp(n, &i); return (n * INT_MAX) + i\n** but there are some numerical subtleties.\n** In a two-complement representation, INT_MAX does not has an exact\n** representation as a float, but INT_MIN does; because the absolute\n** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the\n** absolute value of the product 'frexp * -INT_MIN' is smaller or equal\n** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when\n** adding 'i'; the use of '~u' (instead of '-u') avoids problems with\n** INT_MIN.\n*/\n#if !defined(l_hashfloat)\nstatic int l_hashfloat (lua_Number n) {\n  int i;\n  lua_Integer ni;\n  n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);\n  if (!lua_numbertointeger(n, &ni)) {  /* is 'n' inf/-inf/NaN? */\n    lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));\n    return 0;\n  }\n  else {  /* normal case */\n    unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);\n    return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);\n  }\n}\n#endif\n\n\n/*\n** returns the 'main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMINT:\n      return hashint(t, ivalue(key));\n    case LUA_TNUMFLT:\n      return hashmod(t, l_hashfloat(fltvalue(key)));\n    case LUA_TSHRSTR:\n      return hashstr(t, tsvalue(key));\n    case LUA_TLNGSTR:\n      return hashpow2(t, luaS_hashlongstr(tsvalue(key)));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    case LUA_TLCF:\n      return hashpointer(t, fvalue(key));\n    default:\n      lua_assert(!ttisdeadkey(key));\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for 'key' if 'key' is an appropriate key to live in\n** the array part of the table, 0 otherwise.\n*/\nstatic unsigned int arrayindex (const TValue *key) {\n  if (ttisinteger(key)) {\n    lua_Integer k = ivalue(key);\n    if (0 < k && (lua_Unsigned)k <= MAXASIZE)\n      return cast(unsigned int, k);  /* 'key' is an appropriate array index */\n  }\n  return 0;  /* 'key' did not match some condition */\n}\n\n\n/*\n** returns the index of a 'key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signaled by 0.\n*/\nstatic unsigned int findindex (lua_State *L, Table *t, StkId key) {\n  unsigned int i;\n  if (ttisnil(key)) return 0;  /* first iteration */\n  i = arrayindex(key);\n  if (i != 0 && i <= t->sizearray)  /* is 'key' inside array part? */\n    return i;  /* yes; that's the index */\n  else {\n    int nx;\n    Node *n = mainposition(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in 'next' */\n      if (luaV_rawequalobj(gkey(n), key) ||\n            (ttisdeadkey(gkey(n)) && iscollectable(key) &&\n             deadvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return (i + 1) + t->sizearray;\n      }\n      nx = gnext(n);\n      if (nx == 0)\n        luaG_runerror(L, \"invalid key to 'next'\");  /* key not found */\n      else n += nx;\n    }\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  unsigned int i = findindex(L, t, key);  /* find original element */\n  for (; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setivalue(key, i + 1);\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) {  /* hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, gkey(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n/*\n** Compute the optimal size for the array part of table 't'. 'nums' is a\n** \"count array\" where 'nums[i]' is the number of integers in the table\n** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of\n** integer keys in the table and leaves with the number of keys that\n** will go to the array part; return the optimal size.\n*/\nstatic unsigned int computesizes (unsigned int nums[], unsigned int *pna) {\n  int i;\n  unsigned int twotoi;  /* 2^i (candidate for optimal size) */\n  unsigned int a = 0;  /* number of elements smaller than 2^i */\n  unsigned int na = 0;  /* number of elements to go to array part */\n  unsigned int optimal = 0;  /* optimal size for array part */\n  /* loop while keys can fill more than half of total size */\n  for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        optimal = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements up to 'optimal' will go to array part */\n      }\n    }\n  }\n  lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);\n  *pna = na;\n  return optimal;\n}\n\n\nstatic int countint (const TValue *key, unsigned int *nums) {\n  unsigned int k = arrayindex(key);\n  if (k != 0) {  /* is 'key' an appropriate array index? */\n    nums[luaO_ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Count keys in array part of table 't': Fill 'nums[i]' with\n** number of keys that will go into corresponding slice and return\n** total number of non-nil keys.\n*/\nstatic unsigned int numusearray (const Table *t, unsigned int *nums) {\n  int lg;\n  unsigned int ttlg;  /* 2^lg */\n  unsigned int ause = 0;  /* summation of 'nums' */\n  unsigned int i = 1;  /* count to traverse all array keys */\n  /* traverse each slice */\n  for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {\n    unsigned int lc = 0;  /* counter */\n    unsigned int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg - 1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* elements added to 'nums' (can go to array part) */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(gkey(n), nums);\n      totaluse++;\n    }\n  }\n  *pna += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, unsigned int size) {\n  unsigned int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic void setnodevector (lua_State *L, Table *t, unsigned int size) {\n  int lsize;\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common 'dummynode' */\n    lsize = 0;\n  }\n  else {\n    int i;\n    lsize = luaO_ceillog2(size);\n    if (lsize > MAXHBITS)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i = 0; i < (int)size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = 0;\n      setnilvalue(wgkey(n));\n      setnilvalue(gval(n));\n    }\n  }\n  t->lsizenode = cast_byte(lsize);\n  t->lastfree = gnode(t, size);  /* all positions are free */\n}\n\n\nvoid luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                          unsigned int nhsize) {\n  unsigned int i;\n  int j;\n  unsigned int oldasize = t->sizearray;\n  int oldhsize = t->lsizenode;\n  Node *nold = t->node;  /* save old hash ... */\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  /* create new hash part with appropriate size */\n  setnodevector(L, t, nhsize);\n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        luaH_setint(L, t, i + 1, &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n  /* re-insert elements from hash part */\n  for (j = twoto(oldhsize) - 1; j >= 0; j--) {\n    Node *old = nold + j;\n    if (!ttisnil(gval(old))) {\n      /* doesn't need barrier/invalidate cache, as entry was\n         already present in the table */\n      setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));\n    }\n  }\n  if (!isdummy(nold))\n    luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old hash */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {\n  int nsize = isdummy(t->node) ? 0 : sizenode(t);\n  luaH_resize(L, t, nasize, nsize);\n}\n\n/*\n** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i\n*/\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  unsigned int asize;  /* optimal size for array part */\n  unsigned int na;  /* number of keys in the array part */\n  unsigned int nums[MAXABITS + 1];\n  int i;\n  int totaluse;\n  for (i = 0; i <= MAXABITS; i++) nums[i] = 0;  /* reset counts */\n  na = numusearray(t, nums);  /* count keys in array part */\n  totaluse = na;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &na);  /* count keys in hash part */\n  /* count extra key */\n  na += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  asize = computesizes(nums, &na);\n  /* resize the table to new computed sizes */\n  luaH_resize(L, t, asize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));\n  Table *t = gco2t(o);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  t->array = NULL;\n  t->sizearray = 0;\n  setnodevector(L, t, 0);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (!isdummy(t->node))\n    luaM_freearray(L, t->node, cast(size_t, sizenode(t)));\n  luaM_freearray(L, t->array, t->sizearray);\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  while (t->lastfree > t->node) {\n    t->lastfree--;\n    if (ttisnil(gkey(t->lastfree)))\n      return t->lastfree;\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main\n** position is free. If not, check whether colliding node is in its main\n** position or not: if it is not, move colliding node to an empty place and\n** put new key in its main position; otherwise (colliding node is in its main\n** position), new key goes to an empty position.\n*/\nTValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp;\n  TValue aux;\n  if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n  else if (ttisfloat(key)) {\n    lua_Integer k;\n    if (luaV_tointeger(key, &k, 0)) {  /* index is int? */\n      setivalue(&aux, k);\n      key = &aux;  /* insert it as an integer */\n    }\n    else if (luai_numisnan(fltvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n  }\n  mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || isdummy(mp)) {  /* main position is taken? */\n    Node *othern;\n    Node *f = getfreepos(t);  /* get a free place */\n    if (f == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      /* whatever called 'newkey' takes care of TM cache */\n      return luaH_set(L, t, key);  /* insert key into grown table */\n    }\n    lua_assert(!isdummy(f));\n    othern = mainposition(t, gkey(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (othern + gnext(othern) != mp)  /* find previous */\n        othern += gnext(othern);\n      gnext(othern) = cast_int(f - othern);  /* rechain to point to 'f' */\n      *f = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      if (gnext(mp) != 0) {\n        gnext(f) += cast_int(mp - f);  /* correct 'next' */\n        gnext(mp) = 0;  /* now 'mp' is free */\n      }\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      if (gnext(mp) != 0)\n        gnext(f) = cast_int((mp + gnext(mp)) - f);  /* chain new position */\n      else lua_assert(gnext(f) == 0);\n      gnext(mp) = cast_int(f - mp);\n      mp = f;\n    }\n  }\n  setnodekey(L, &mp->i_key, key);\n  luaC_barrierback(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getint (Table *t, lua_Integer key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (l_castS2U(key) - 1 < t->sizearray)\n    return &t->array[key - 1];\n  else {\n    Node *n = hashint(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)\n        return gval(n);  /* that's it */\n      else {\n        int nx = gnext(n);\n        if (nx == 0) break;\n        n += nx;\n      }\n    }\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for short strings\n*/\nconst TValue *luaH_getshortstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  lua_assert(key->tt == LUA_TSHRSTR);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    const TValue *k = gkey(n);\n    if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\n/*\n** \"Generic\" get version. (Not that generic: not valid for integers,\n** which may be in array part, nor for floats with integral values.)\n*/\nstatic const TValue *getgeneric (Table *t, const TValue *key) {\n  Node *n = mainposition(t, key);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (luaV_rawequalobj(gkey(n), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  if (key->tt == LUA_TSHRSTR)\n    return luaH_getshortstr(t, key);\n  else {  /* for long strings, use generic case */\n    TValue ko;\n    setsvalue(cast(lua_State *, NULL), &ko, key);\n    return getgeneric(t, &ko);\n  }\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));\n    case LUA_TNUMINT: return luaH_getint(t, ivalue(key));\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TNUMFLT: {\n      lua_Integer k;\n      if (luaV_tointeger(key, &k, 0)) /* index is int? */\n        return luaH_getint(t, k);  /* use specialized version */\n      /* else... */\n    }  /* FALLTHROUGH */\n    default:\n      return getgeneric(t, key);\n  }\n}\n\n\n/*\n** beware: when using this function you probably need to check a GC\n** barrier and invalidate the TM cache.\n*/\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else return luaH_newkey(L, t, key);\n}\n\n\nvoid luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {\n  const TValue *p = luaH_getint(t, key);\n  TValue *cell;\n  if (p != luaO_nilobject)\n    cell = cast(TValue *, p);\n  else {\n    TValue k;\n    setivalue(&k, key);\n    cell = luaH_newkey(L, t, &k);\n  }\n  setobj2t(L, cell, value);\n}\n\n\nstatic int unbound_search (Table *t, unsigned int j) {\n  unsigned int i = j;  /* i is zero or a present index */\n  j++;\n  /* find 'i' and 'j' such that i is present and j is not */\n  while (!ttisnil(luaH_getint(t, j))) {\n    i = j;\n    if (j > cast(unsigned int, MAX_INT)/2) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getint(t, i))) i++;\n      return i - 1;\n    }\n    j *= 2;\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    unsigned int m = (i+j)/2;\n    if (ttisnil(luaH_getint(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table 't'. A 'boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nint luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (isdummy(t->node))  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (Node *n) { return isdummy(n); }\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n\n/* 'const' to avoid wrong writings that can mess up field 'next' */ \n#define gkey(n)\t\tcast(const TValue*, (&(n)->i_key.tvk))\n\n/*\n** writable version of 'gkey'; allows updates to individual fields,\n** but not to the whole (which has incompatible type)\n*/\n#define wgkey(n)\t\t(&(n)->i_key.nk)\n\n#define invalidateTMcache(t)\t((t)->flags = 0)\n\n\n/* returns the key, given the value of a table entry */\n#define keyfromval(v) \\\n  (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))\n\n\nLUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);\nLUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,\n                                                    TValue *value);\nLUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L);\nLUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                                    unsigned int nhsize);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC int luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (Node *n);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** Operations that an object must define to mimic a table\n** (some functions only need some of them)\n*/\n#define TAB_R\t1\t\t\t/* read */\n#define TAB_W\t2\t\t\t/* write */\n#define TAB_L\t4\t\t\t/* length */\n#define TAB_RW\t(TAB_R | TAB_W)\t\t/* read/write */\n\n\n#define aux_getn(L,n,w)\t(checktab(L, n, (w) | TAB_L), luaL_len(L, n))\n\n\nstatic int checkfield (lua_State *L, const char *key, int n) {\n  lua_pushstring(L, key);\n  return (lua_rawget(L, -n) != LUA_TNIL);\n}\n\n\n/*\n** Check that 'arg' either is a table or can behave like one (that is,\n** has a metatable with the required metamethods)\n*/\nstatic void checktab (lua_State *L, int arg, int what) {\n  if (lua_type(L, arg) != LUA_TTABLE) {  /* is it not a table? */\n    int n = 1;  /* number of elements to pop */\n    if (lua_getmetatable(L, arg) &&  /* must have metatable */\n        (!(what & TAB_R) || checkfield(L, \"__index\", ++n)) &&\n        (!(what & TAB_W) || checkfield(L, \"__newindex\", ++n)) &&\n        (!(what & TAB_L) || checkfield(L, \"__len\", ++n))) {\n      lua_pop(L, n);  /* pop metatable and tested metamethods */\n    }\n    else\n      luaL_checktype(L, arg, LUA_TTABLE);  /* force an error */\n  }\n}\n\n\n#if defined(LUA_COMPAT_MAXN)\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n#endif\n\n\nstatic int tinsert (lua_State *L) {\n  lua_Integer e = aux_getn(L, 1, TAB_RW) + 1;  /* first empty element */\n  lua_Integer pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      lua_Integer i;\n      pos = luaL_checkinteger(L, 2);  /* 2nd argument is the position */\n      luaL_argcheck(L, 1 <= pos && pos <= e, 2, \"position out of bounds\");\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_geti(L, 1, i - 1);\n        lua_seti(L, 1, i);  /* t[i] = t[i - 1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to 'insert'\");\n    }\n  }\n  lua_seti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  lua_Integer size = aux_getn(L, 1, TAB_RW);\n  lua_Integer pos = luaL_optinteger(L, 2, size);\n  if (pos != size)  /* validate 'pos' if given */\n    luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, \"position out of bounds\");\n  lua_geti(L, 1, pos);  /* result = t[pos] */\n  for ( ; pos < size; pos++) {\n    lua_geti(L, 1, pos + 1);\n    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */\n  }\n  lua_pushnil(L);\n  lua_seti(L, 1, pos);  /* t[pos] = nil */\n  return 1;\n}\n\n\n/*\n** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever\n** possible, copy in increasing order, which is better for rehashing.\n** \"possible\" means destination after original range, or smaller\n** than origin, or copying to another table.\n*/\nstatic int tmove (lua_State *L) {\n  lua_Integer f = luaL_checkinteger(L, 2);\n  lua_Integer e = luaL_checkinteger(L, 3);\n  lua_Integer t = luaL_checkinteger(L, 4);\n  int tt = !lua_isnoneornil(L, 5) ? 5 : 1;  /* destination table */\n  checktab(L, 1, TAB_R);\n  checktab(L, tt, TAB_W);\n  if (e >= f) {  /* otherwise, nothing to move */\n    lua_Integer n, i;\n    luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,\n                  \"too many elements to move\");\n    n = e - f + 1;  /* number of elements to move */\n    luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,\n                  \"destination wrap around\");\n    if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {\n      for (i = 0; i < n; i++) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n    else {\n      for (i = n - 1; i >= 0; i--) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n  }\n  lua_pushvalue(L, tt);  /* return destination table */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {\n  lua_geti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for 'concat'\",\n                  luaL_typename(L, -1), i);\n  luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  lua_Integer last = aux_getn(L, 1, TAB_R);\n  size_t lsep;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  lua_Integer i = luaL_optinteger(L, 3, 1);\n  last = luaL_optinteger(L, 4, last);\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Pack/unpack\n** =======================================================\n*/\n\nstatic int pack (lua_State *L) {\n  int i;\n  int n = lua_gettop(L);  /* number of elements to pack */\n  lua_createtable(L, n, 1);  /* create result table */\n  lua_insert(L, 1);  /* put it at index 1 */\n  for (i = n; i >= 1; i--)  /* assign elements */\n    lua_seti(L, 1, i);\n  lua_pushinteger(L, n);\n  lua_setfield(L, 1, \"n\");  /* t.n = number of elements */\n  return 1;  /* return table */\n}\n\n\nstatic int unpack (lua_State *L) {\n  lua_Unsigned n;\n  lua_Integer i = luaL_optinteger(L, 2, 1);\n  lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */\n  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, (int)(++n)))\n    return luaL_error(L, \"too many results to unpack\");\n  for (; i < e; i++) {  /* push arg[i..e - 1] (to avoid overflows) */\n    lua_geti(L, 1, i);\n  }\n  lua_geti(L, 1, e);  /* push last element */\n  return (int)n;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on 'Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n** =======================================================\n*/\n\n\n/* type for array indices */\ntypedef unsigned int IdxT;\n\n\n/*\n** Produce a \"random\" 'unsigned int' to randomize pivot choice. This\n** macro is used only when 'sort' detects a big imbalance in the result\n** of a partition. (If you don't want/need this \"randomness\", ~0 is a\n** good choice.)\n*/\n#if !defined(l_randomizePivot)\t\t/* { */\n\n#include <time.h>\n\n/* size of 'e' measured in number of 'unsigned int's */\n#define sof(e)\t\t(sizeof(e) / sizeof(unsigned int))\n\n/*\n** Use 'time' and 'clock' as sources of \"randomness\". Because we don't\n** know the types 'clock_t' and 'time_t', we cannot cast them to\n** anything without risking overflows. A safe way to use their values\n** is to copy them to an array of a known type and use the array values.\n*/\nstatic unsigned int l_randomizePivot (void) {\n  clock_t c = clock();\n  time_t t = time(NULL);\n  unsigned int buff[sof(c) + sof(t)];\n  unsigned int i, rnd = 0;\n  memcpy(buff, &c, sof(c) * sizeof(unsigned int));\n  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));\n  for (i = 0; i < sof(buff); i++)\n    rnd += buff[i];\n  return rnd;\n}\n\n#endif\t\t\t\t\t/* } */\n\n\n/* arrays larger than 'RANLIMIT' may use randomized pivots */\n#define RANLIMIT\t100u\n\n\nstatic void set2 (lua_State *L, IdxT i, IdxT j) {\n  lua_seti(L, 1, i);\n  lua_seti(L, 1, j);\n}\n\n\n/*\n** Return true iff value at stack index 'a' is less than the value at\n** index 'b' (according to the order of the sort).\n*/\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (lua_isnil(L, 2))  /* no function? */\n    return lua_compare(L, a, b, LUA_OPLT);  /* a < b */\n  else {  /* function */\n    int res;\n    lua_pushvalue(L, 2);    /* push function */\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and 'a' */\n    lua_call(L, 2, 1);      /* call function */\n    res = lua_toboolean(L, -1);  /* get result */\n    lua_pop(L, 1);          /* pop result */\n    return res;\n  }\n}\n\n\n/*\n** Does the partition: Pivot P is at the top of the stack.\n** precondition: a[lo] <= P == a[up-1] <= a[up],\n** so it only needs to do the partition from lo + 1 to up - 2.\n** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]\n** returns 'i'.\n*/\nstatic IdxT partition (lua_State *L, IdxT lo, IdxT up) {\n  IdxT i = lo;  /* will be incremented before first use */\n  IdxT j = up - 1;  /* will be decremented before first use */\n  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */\n  for (;;) {\n    /* next loop: repeat ++i while a[i] < P */\n    while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {\n      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[i] */\n    }\n    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */\n    /* next loop: repeat --j while P < a[j] */\n    while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {\n      if (j < i)  /* j < i  but  a[j] > P ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[j] */\n    }\n    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */\n    if (j < i) {  /* no elements out of place? */\n      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */\n      lua_pop(L, 1);  /* pop a[j] */\n      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */\n      set2(L, up - 1, i);\n      return i;\n    }\n    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */\n    set2(L, i, j);\n  }\n}\n\n\n/*\n** Choose an element in the middle (2nd-3th quarters) of [lo,up]\n** \"randomized\" by 'rnd'\n*/\nstatic IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {\n  IdxT r4 = (up - lo) / 4;  /* range/4 */\n  IdxT p = rnd % (r4 * 2) + (lo + r4);\n  lua_assert(lo + r4 <= p && p <= up - r4);\n  return p;\n}\n\n\n/*\n** QuickSort algorithm (recursive function)\n*/\nstatic void auxsort (lua_State *L, IdxT lo, IdxT up,\n                                   unsigned int rnd) {\n  while (lo < up) {  /* loop for tail recursion */\n    IdxT p;  /* Pivot index */\n    IdxT n;  /* to be used later */\n    /* sort elements 'lo', 'p', and 'up' */\n    lua_geti(L, 1, lo);\n    lua_geti(L, 1, up);\n    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */\n      set2(L, lo, up);  /* swap a[lo] - a[up] */\n    else\n      lua_pop(L, 2);  /* remove both values */\n    if (up - lo == 1)  /* only 2 elements? */\n      return;  /* already sorted */\n    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */\n      p = (lo + up)/2;  /* middle element is a good pivot */\n    else  /* for larger intervals, it is worth a random pivot */\n      p = choosePivot(lo, up, rnd);\n    lua_geti(L, 1, p);\n    lua_geti(L, 1, lo);\n    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */\n      set2(L, p, lo);  /* swap a[p] - a[lo] */\n    else {\n      lua_pop(L, 1);  /* remove a[lo] */\n      lua_geti(L, 1, up);\n      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */\n        set2(L, p, up);  /* swap a[up] - a[p] */\n      else\n        lua_pop(L, 2);\n    }\n    if (up - lo == 2)  /* only 3 elements? */\n      return;  /* already sorted */\n    lua_geti(L, 1, p);  /* get middle element (Pivot) */\n    lua_pushvalue(L, -1);  /* push Pivot */\n    lua_geti(L, 1, up - 1);  /* push a[up - 1] */\n    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */\n    p = partition(L, lo, up);\n    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */\n    if (p - lo < up - p) {  /* lower interval is smaller? */\n      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */\n      n = p - lo;  /* size of smaller interval */\n      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */\n    }\n    else {\n      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */\n      n = up - p;  /* size of smaller interval */\n      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */\n    }\n    if ((up - lo) / 128 > n) /* partition too imbalanced? */\n      rnd = l_randomizePivot();  /* try a new randomization */\n  }  /* tail call auxsort(L, lo, up, rnd) */\n}\n\n\nstatic int sort (lua_State *L) {\n  lua_Integer n = aux_getn(L, 1, TAB_RW);\n  if (n > 1) {  /* non-trivial interval? */\n    luaL_argcheck(L, n < INT_MAX, 1, \"array too big\");\n    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */\n    lua_settop(L, 2);  /* make sure there are two arguments */\n    auxsort(L, 1, (IdxT)n, 0);\n  }\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n#if defined(LUA_COMPAT_MAXN)\n  {\"maxn\", maxn},\n#endif\n  {\"insert\", tinsert},\n  {\"pack\", pack},\n  {\"unpack\", unpack},\n  {\"remove\", tremove},\n  {\"move\", tmove},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_table (lua_State *L) {\n  luaL_newlib(L, tab_funcs);\n#if defined(LUA_COMPAT_UNPACK)\n  /* _G.unpack = table.unpack */\n  lua_getfield(L, -1, \"unpack\");\n  lua_setglobal(L, \"unpack\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.37 2016/02/26 19:20:15 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\" \n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\nstatic const char udatatypename[] = \"userdata\";\n\nLUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {\n  \"no value\",\n  \"nil\", \"boolean\", udatatypename, \"number\",\n  \"string\", \"table\", \"function\", udatatypename, \"thread\",\n  \"proto\" /* this last case is used for tests only */\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__len\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__mod\", \"__pow\",\n    \"__div\", \"__idiv\",\n    \"__band\", \"__bor\", \"__bxor\", \"__shl\", \"__shr\",\n    \"__unm\", \"__bnot\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaC_fix(L, obj2gco(G(L)->tmname[i]));  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getshortstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttnov(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(o)];\n  }\n  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n\n/*\n** Return the name of the type of an object. For tables and userdata\n** with metatable, use their '__name' metafield, if present.\n*/\nconst char *luaT_objtypename (lua_State *L, const TValue *o) {\n  Table *mt;\n  if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||\n      (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {\n    const TValue *name = luaH_getshortstr(mt, luaS_new(L, \"__name\"));\n    if (ttisstring(name))  /* is '__name' a string? */\n      return getstr(tsvalue(name));  /* use it as type name */\n  }\n  return ttypename(ttnov(o));  /* else use standard type name */\n}\n\n\nvoid luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                  const TValue *p2, TValue *p3, int hasres) {\n  ptrdiff_t result = savestack(L, p3);\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  L->top += 3;\n  if (!hasres)  /* no result? 'p3' is third argument */\n    setobj2s(L, L->top++, p3);  /* 3rd argument */\n  /* metamethod may yield only when called from Lua code */\n  if (isLua(L->ci))\n    luaD_call(L, func, hasres);\n  else\n    luaD_callnoyield(L, func, hasres);\n  if (hasres) {  /* if has result, move it to its place */\n    p3 = restorestack(L, result);\n    setobjs2s(L, p3, --L->top);\n  }\n}\n\n\nint luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  luaT_callTM(L, tm, p1, p2, res, 1);\n  return 1;\n}\n\n\nvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, res, event)) {\n    switch (event) {\n      case TM_CONCAT:\n        luaG_concaterror(L, p1, p2);\n      /* call never returns, but to avoid warnings: *//* FALLTHROUGH */\n      case TM_BAND: case TM_BOR: case TM_BXOR:\n      case TM_SHL: case TM_SHR: case TM_BNOT: {\n        lua_Number dummy;\n        if (tonumber(p1, &dummy) && tonumber(p2, &dummy))\n          luaG_tointerror(L, p1, p2);\n        else\n          luaG_opinterror(L, p1, p2, \"perform bitwise operation on\");\n      }\n      /* calls never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:\n        luaG_opinterror(L, p1, p2, \"perform arithmetic on\");\n    }\n  }\n}\n\n\nint luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, L->top, event))\n    return -1;  /* no metamethod */\n  else\n    return !l_isfalse(L->top);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\" and \"ORDER OP\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_LEN,\n  TM_EQ,  /* last tag method with fast access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_MOD,\n  TM_POW,\n  TM_DIV,\n  TM_IDIV,\n  TM_BAND,\n  TM_BOR,\n  TM_BXOR,\n  TM_SHL,\n  TM_SHR,\n  TM_UNM,\n  TM_BNOT,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\n#define ttypename(x)\tluaT_typenames_[(x) + 1]\n\nLUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];\n\n\nLUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\nLUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                            const TValue *p2, TValue *p3, int hasres);\nLUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,\n                                const TValue *p2, TMS event);\n\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.226 2015/08/14 19:11:20 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n#define lua_c\n\n#include \"lprefix.h\"\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if !defined(LUA_PROMPT)\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n#endif\n\n#if !defined(LUA_PROGNAME)\n#define LUA_PROGNAME\t\t\"lua\"\n#endif\n\n#if !defined(LUA_MAXINPUT)\n#define LUA_MAXINPUT\t\t512\n#endif\n\n#if !defined(LUA_INIT_VAR)\n#define LUA_INIT_VAR\t\t\"LUA_INIT\"\n#endif\n\n#define LUA_INITVARVERSION  \\\n\tLUA_INIT_VAR \"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n\n/*\n** lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n** is, whether we're running lua interactively).\n*/\n#if !defined(lua_stdin_is_tty)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#include <io.h>\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definition */\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** lua_readline defines how to show a prompt and then read a line from\n** the standard input.\n** lua_saveline defines how to \"save\" a read line in a \"history\".\n** lua_freeline defines how to free a line read by lua_readline.\n*/\n#if !defined(lua_readline)\t/* { */\n\n#if defined(LUA_USE_READLINE)\t/* { */\n\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,line)\t((void)L, add_history(line))\n#define lua_freeline(L,b)\t((void)L, free(b))\n\n#else\t\t\t\t/* }{ */\n\n#define lua_readline(L,b,p) \\\n        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,line)\t{ (void)L; (void)line; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n/*\n** Hook set by signal function to stop the interpreter.\n*/\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);  /* reset hook */\n  luaL_error(L, \"interrupted!\");\n}\n\n\n/*\n** Function to be called at a C signal. Because a C signal cannot\n** just change a Lua state (as there is no proper synchronization),\n** this function only sets a hook that, when called, will stop the\n** interpreter.\n*/\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (const char *badoption) {\n  lua_writestringerror(\"%s: \", progname);\n  if (badoption[1] == 'e' || badoption[1] == 'l')\n    lua_writestringerror(\"'%s' needs argument\\n\", badoption);\n  else\n    lua_writestringerror(\"unrecognized option '%s'\\n\", badoption);\n  lua_writestringerror(\n  \"usage: %s [options] [script [args]]\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string 'stat'\\n\"\n  \"  -i       enter interactive mode after executing 'script'\\n\"\n  \"  -l name  require library 'name'\\n\"\n  \"  -v       show version information\\n\"\n  \"  -E       ignore environment variables\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and execute stdin\\n\"\n  ,\n  progname);\n}\n\n\n/*\n** Prints an error message, adding the program name in front of it\n** (if present)\n*/\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) lua_writestringerror(\"%s: \", pname);\n  lua_writestringerror(\"%s\\n\", msg);\n}\n\n\n/*\n** Check whether 'status' is not OK and, if so, prints the error\n** message on the top of the stack. It assumes that the error object\n** is a string, as it was either generated by Lua or by 'msghandler'.\n*/\nstatic int report (lua_State *L, int status) {\n  if (status != LUA_OK) {\n    const char *msg = lua_tostring(L, -1);\n    l_message(progname, msg);\n    lua_pop(L, 1);  /* remove message */\n  }\n  return status;\n}\n\n\n/*\n** Message handler used to run all chunks\n*/\nstatic int msghandler (lua_State *L) {\n  const char *msg = lua_tostring(L, 1);\n  if (msg == NULL) {  /* is error object not a string? */\n    if (luaL_callmeta(L, 1, \"__tostring\") &&  /* does it have a metamethod */\n        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */\n      return 1;  /* that is the message */\n    else\n      msg = lua_pushfstring(L, \"(error object is a %s value)\",\n                               luaL_typename(L, 1));\n  }\n  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */\n  return 1;  /* return the traceback */\n}\n\n\n/*\n** Interface to 'lua_pcall', which sets appropriate message function\n** and C-signal handler. Used to run all chunks.\n*/\nstatic int docall (lua_State *L, int narg, int nres) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, msghandler);  /* push message handler */\n  lua_insert(L, base);  /* put it under function and args */\n  globalL = L;  /* to be available to 'laction' */\n  signal(SIGINT, laction);  /* set C-signal handler */\n  status = lua_pcall(L, narg, nres, base);\n  signal(SIGINT, SIG_DFL); /* reset C-signal handler */\n  lua_remove(L, base);  /* remove message handler from the stack */\n  return status;\n}\n\n\nstatic void print_version (void) {\n  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));\n  lua_writeline();\n}\n\n\n/*\n** Create the 'arg' table, which stores all arguments from the\n** command line ('argv'). It should be aligned so that, at index 0,\n** it has 'argv[script]', which is the script name. The arguments\n** to the script (everything after 'script') go to positive indices;\n** other arguments (before the script name) go to negative indices.\n** If there is no script name, assume interpreter's name as base.\n*/\nstatic void createargtable (lua_State *L, char **argv, int argc, int script) {\n  int i, narg;\n  if (script == argc) script = 0;  /* no script name? */\n  narg = argc - (script + 1);  /* number of positive indices */\n  lua_createtable(L, narg, script + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - script);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\n\nstatic int dochunk (lua_State *L, int status) {\n  if (status == LUA_OK) status = docall(L, 0, 0);\n  return report(L, status);\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  return dochunk(L, luaL_loadfile(L, name));\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));\n}\n\n\n/*\n** Calls 'require(name)' and stores the result in a global variable\n** with the given name.\n*/\nstatic int dolibrary (lua_State *L, const char *name) {\n  int status;\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  status = docall(L, 1, 1);  /* call 'require(name)' */\n  if (status == LUA_OK)\n    lua_setglobal(L, name);  /* global[name] = require return */\n  return report(L, status);\n}\n\n\n/*\n** Returns the string to be used as a prompt by the interpreter.\n*/\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getglobal(L, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  return p;\n}\n\n/* mark in error messages for incomplete statements */\n#define EOFMARK\t\t\"<eof>\"\n#define marklen\t\t(sizeof(EOFMARK)/sizeof(char) - 1)\n\n\n/*\n** Check whether 'status' signals a syntax error and the error\n** message at the top of the stack ends with the above mark for\n** incomplete statements.\n*/\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\n/*\n** Prompt the user, read a line, and push it into the Lua stack.\n*/\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  int readstatus = lua_readline(L, b, prmt);\n  if (readstatus == 0)\n    return 0;  /* no input (prompt will be popped by caller) */\n  lua_pop(L, 1);  /* remove prompt */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[--l] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */\n    lua_pushfstring(L, \"return %s\", b + 1);  /* change '=' to 'return' */\n  else\n    lua_pushlstring(L, b, l);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\n/*\n** Try to compile line on the stack as 'return <line>;'; on return, stack\n** has either compiled chunk or original line (if compilation failed).\n*/\nstatic int addreturn (lua_State *L) {\n  const char *line = lua_tostring(L, -1);  /* original line */\n  const char *retline = lua_pushfstring(L, \"return %s;\", line);\n  int status = luaL_loadbuffer(L, retline, strlen(retline), \"=stdin\");\n  if (status == LUA_OK) {\n    lua_remove(L, -2);  /* remove modified line */\n    if (line[0] != '\\0')  /* non empty? */\n      lua_saveline(L, line);  /* keep history */\n  }\n  else\n    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */\n  return status;\n}\n\n\n/*\n** Read multiple lines until a complete Lua statement\n*/\nstatic int multiline (lua_State *L) {\n  for (;;) {  /* repeat until gets a complete statement */\n    size_t len;\n    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */\n    int status = luaL_loadbuffer(L, line, len, \"=stdin\");  /* try it */\n    if (!incomplete(L, status) || !pushline(L, 0)) {\n      lua_saveline(L, line);  /* keep history */\n      return status;  /* cannot or should not try to add continuation line */\n    }\n    lua_pushliteral(L, \"\\n\");  /* add newline... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n}\n\n\n/*\n** Read a line and try to load (compile) it first as an expression (by\n** adding \"return \" in front of it) and second as a statement. Return\n** the final status of load/call with the resulting function (if any)\n** in the top of the stack.\n*/\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */\n    status = multiline(L);  /* try as command, maybe with continuation lines */\n  lua_remove(L, 1);  /* remove line from the stack */\n  lua_assert(lua_gettop(L) == 1);\n  return status;\n}\n\n\n/*\n** Prints (calling the Lua 'print' function) any values on the stack\n*/\nstatic void l_print (lua_State *L) {\n  int n = lua_gettop(L);\n  if (n > 0) {  /* any result to be printed? */\n    luaL_checkstack(L, LUA_MINSTACK, \"too many results to print\");\n    lua_getglobal(L, \"print\");\n    lua_insert(L, 1);\n    if (lua_pcall(L, n, 0, 0) != LUA_OK)\n      l_message(progname, lua_pushfstring(L, \"error calling 'print' (%s)\",\n                                             lua_tostring(L, -1)));\n  }\n}\n\n\n/*\n** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and\n** print any results.\n*/\nstatic void doREPL (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;  /* no 'progname' on errors in interactive mode */\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK)\n      status = docall(L, 0, LUA_MULTRET);\n    if (status == LUA_OK) l_print(L);\n    else report(L, status);\n  }\n  lua_settop(L, 0);  /* clear stack */\n  lua_writeline();\n  progname = oldprogname;\n}\n\n\n/*\n** Push on the stack the contents of table 'arg' from 1 to #arg\n*/\nstatic int pushargs (lua_State *L) {\n  int i, n;\n  if (lua_getglobal(L, \"arg\") != LUA_TTABLE)\n    luaL_error(L, \"'arg' is not a table\");\n  n = (int)luaL_len(L, -1);\n  luaL_checkstack(L, n + 3, \"too many arguments to script\");\n  for (i = 1; i <= n; i++)\n    lua_rawgeti(L, -i, i);\n  lua_remove(L, -i);  /* remove table from the stack */\n  return n;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv) {\n  int status;\n  const char *fname = argv[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    int n = pushargs(L);  /* push arguments to script */\n    status = docall(L, n, LUA_MULTRET);\n  }\n  return report(L, status);\n}\n\n\n\n/* bits of various argument indicators in 'args' */\n#define has_error\t1\t/* bad option */\n#define has_i\t\t2\t/* -i */\n#define has_v\t\t4\t/* -v */\n#define has_e\t\t8\t/* -e */\n#define has_E\t\t16\t/* -E */\n\n/*\n** Traverses all arguments from 'argv', returning a mask with those\n** needed before running any Lua code (or an error code if it finds\n** any invalid argument). 'first' returns the first not-handled argument \n** (either the script name or a bad argument in case of error).\n*/\nstatic int collectargs (char **argv, int *first) {\n  int args = 0;\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    *first = i;\n    if (argv[i][0] != '-')  /* not an option? */\n        return args;  /* stop handling options */\n    switch (argv[i][1]) {  /* else check option */\n      case '-':  /* '--' */\n        if (argv[i][2] != '\\0')  /* extra characters after '--'? */\n          return has_error;  /* invalid option */\n        *first = i + 1;\n        return args;\n      case '\\0':  /* '-' */\n        return args;  /* script \"name\" is '-' */\n      case 'E':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_E;\n        break;\n      case 'i':\n        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */ \n      case 'v':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_v;\n        break;\n      case 'e':\n        args |= has_e;  /* FALLTHROUGH */\n      case 'l':  /* both options need an argument */\n        if (argv[i][2] == '\\0') {  /* no concatenated argument? */\n          i++;  /* try next 'argv' */\n          if (argv[i] == NULL || argv[i][0] == '-')\n            return has_error;  /* no next argument or it is another option */\n        }\n        break;\n      default:  /* invalid option */\n        return has_error;\n    }\n  }\n  *first = i;  /* no script name */\n  return args;\n}\n\n\n/*\n** Processes options 'e' and 'l', which involve running Lua code.\n** Returns 0 if some code raises an error.\n*/\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    int option = argv[i][1];\n    lua_assert(argv[i][0] == '-');  /* already checked */\n    if (option == 'e' || option == 'l') {\n      int status;\n      const char *extra = argv[i] + 2;  /* both options need an argument */\n      if (*extra == '\\0') extra = argv[++i];\n      lua_assert(extra != NULL);\n      status = (option == 'e')\n               ? dostring(L, extra, \"=(command line)\")\n               : dolibrary(L, extra);\n      if (status != LUA_OK) return 0;\n    }\n  }\n  return 1;\n}\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *name = \"=\" LUA_INITVARVERSION;\n  const char *init = getenv(name + 1);\n  if (init == NULL) {\n    name = \"=\" LUA_INIT_VAR;\n    init = getenv(name + 1);  /* try alternative name */\n  }\n  if (init == NULL) return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, name);\n}\n\n\n/*\n** Main body of stand-alone interpreter (to be called in protected mode).\n** Reads the options and handles them all.\n*/\nstatic int pmain (lua_State *L) {\n  int argc = (int)lua_tointeger(L, 1);\n  char **argv = (char **)lua_touserdata(L, 2);\n  int script;\n  int args = collectargs(argv, &script);\n  luaL_checkversion(L);  /* check that interpreter has correct version */\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  if (args == has_error) {  /* bad arg? */\n    print_usage(argv[script]);  /* 'script' has index of bad arg. */\n    return 0;\n  }\n  if (args & has_v)  /* option '-v'? */\n    print_version();\n  if (args & has_E) {  /* option '-E'? */\n    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  luaL_openlibs(L);  /* open standard libraries */\n  createargtable(L, argv, argc, script);  /* create table 'arg' */\n  if (!(args & has_E)) {  /* no option '-E'? */\n    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */\n      return 0;  /* error running LUA_INIT */\n  }\n  if (!runargs(L, argv, script))  /* execute arguments -e and -l */\n    return 0;  /* something failed */\n  if (script < argc &&  /* execute main script (if there is one) */\n      handle_script(L, argv + script) != LUA_OK)\n    return 0;\n  if (args & has_i)  /* -i option? */\n    doREPL(L);  /* do read-eval-print loop */\n  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */\n    if (lua_stdin_is_tty()) {  /* running in interactive mode? */\n      print_version();\n      doREPL(L);  /* do read-eval-print loop */\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  lua_pushboolean(L, 1);  /* signal no errors */\n  return 1;\n}\n\n\nint main (int argc, char **argv) {\n  int status, result;\n  lua_State *L = luaL_newstate();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */\n  lua_pushinteger(L, argc);  /* 1st argument */\n  lua_pushlightuserdata(L, argv); /* 2nd argument */\n  status = lua_pcall(L, 2, 1, 0);  /* do the call */\n  result = lua_toboolean(L, -1);  /* get result */\n  report(L, status);\n  lua_close(L);\n  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.331 2016/05/30 15:53:28 roberto Exp $\n** Lua - A Scripting Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION_MAJOR\t\"5\"\n#define LUA_VERSION_MINOR\t\"3\"\n#define LUA_VERSION_NUM\t\t503\n#define LUA_VERSION_RELEASE\t\"3\"\n\n#define LUA_VERSION\t\"Lua \" LUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#define LUA_RELEASE\tLUA_VERSION \".\" LUA_VERSION_RELEASE\n#define LUA_COPYRIGHT\tLUA_RELEASE \"  Copyright (C) 1994-2016 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo, W. Celes\"\n\n\n/* mark for precompiled code ('<esc>Lua') */\n#define LUA_SIGNATURE\t\"\\x1bLua\"\n\n/* option for multiple returns in 'lua_pcall' and 'lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** Pseudo-indices\n** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty\n** space after that to help overflow detection)\n*/\n#define LUA_REGISTRYINDEX\t(-LUAI_MAXSTACK - 1000)\n#define lua_upvalueindex(i)\t(LUA_REGISTRYINDEX - (i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRGCMM\t5\n#define LUA_ERRERR\t6\n\n\ntypedef struct lua_State lua_State;\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n#define LUA_NUMTAGS\t\t9\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/* predefined values in the registry */\n#define LUA_RIDX_MAINTHREAD\t1\n#define LUA_RIDX_GLOBALS\t2\n#define LUA_RIDX_LAST\t\tLUA_RIDX_GLOBALS\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n/* unsigned integer type */\ntypedef LUA_UNSIGNED lua_Unsigned;\n\n/* type for continuation-function contexts */\ntypedef LUA_KCONTEXT lua_KContext;\n\n\n/*\n** Type for C functions registered with Lua\n*/\ntypedef int (*lua_CFunction) (lua_State *L);\n\n/*\n** Type for continuation functions\n*/\ntypedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);\n\n\n/*\n** Type for functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);\n\n\n/*\n** Type for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/*\n** RCS ident string\n*/\nextern const char lua_ident[];\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\nLUA_API const lua_Number *(lua_version) (lua_State *L);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_absindex) (lua_State *L, int idx);\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_rotate) (lua_State *L, int idx, int n);\nLUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);\nLUA_API int   (lua_checkstack) (lua_State *L, int n);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isinteger) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_rawlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** Comparison and arithmetic functions\n*/\n\n#define LUA_OPADD\t0\t/* ORDER TM, ORDER OP */\n#define LUA_OPSUB\t1\n#define LUA_OPMUL\t2\n#define LUA_OPMOD\t3\n#define LUA_OPPOW\t4\n#define LUA_OPDIV\t5\n#define LUA_OPIDIV\t6\n#define LUA_OPBAND\t7\n#define LUA_OPBOR\t8\n#define LUA_OPBXOR\t9\n#define LUA_OPSHL\t10\n#define LUA_OPSHR\t11\n#define LUA_OPUNM\t12\n#define LUA_OPBNOT\t13\n\nLUA_API void  (lua_arith) (lua_State *L, int op);\n\n#define LUA_OPEQ\t0\n#define LUA_OPLT\t1\n#define LUA_OPLE\t2\n\nLUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void        (lua_pushnil) (lua_State *L);\nLUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);\nLUA_API const char *(lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API int (lua_getglobal) (lua_State *L, const char *name);\nLUA_API int (lua_gettable) (lua_State *L, int idx);\nLUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawget) (lua_State *L, int idx);\nLUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);\n\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API int  (lua_getuservalue) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_setglobal) (lua_State *L, const char *name);\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_seti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_setuservalue) (lua_State *L, int idx);\n\n\n/*\n** 'load' and 'call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,\n                           lua_KContext ctx, lua_KFunction k);\n#define lua_call(L,n,r)\t\tlua_callk(L, (n), (r), 0, NULL)\n\nLUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,\n                            lua_KContext ctx, lua_KFunction k);\n#define lua_pcall(L,n,r,f)\tlua_pcallk(L, (n), (r), (f), 0, NULL)\n\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                          const char *chunkname, const char *mode);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yieldk)     (lua_State *L, int nresults, lua_KContext ctx,\n                               lua_KFunction k);\nLUA_API int  (lua_resume)     (lua_State *L, lua_State *from, int narg);\nLUA_API int  (lua_status)     (lua_State *L);\nLUA_API int (lua_isyieldable) (lua_State *L);\n\n#define lua_yield(L,n)\t\tlua_yieldk(L, (n), 0, NULL)\n\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\nLUA_API void  (lua_len)    (lua_State *L, int idx);\n\nLUA_API size_t   (lua_stringtonumber) (lua_State *L, const char *s);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** {==============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_getextraspace(L)\t((void *)((char *)(L) - LUA_EXTRASPACE))\n\n#define lua_tonumber(L,i)\tlua_tonumberx(L,(i),NULL)\n#define lua_tointeger(L,i)\tlua_tointegerx(L,(i),NULL)\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\tlua_pushstring(L, \"\" s)\n\n#define lua_pushglobaltable(L)  \\\n\t((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n#define lua_insert(L,idx)\tlua_rotate(L, (idx), 1)\n\n#define lua_remove(L,idx)\t(lua_rotate(L, (idx), -1), lua_pop(L, 1))\n\n#define lua_replace(L,idx)\t(lua_copy(L, -1, (idx)), lua_pop(L, 1))\n\n/* }============================================================== */\n\n\n/*\n** {==============================================================\n** compatibility macros for unsigned conversions\n** ===============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define lua_pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define lua_tounsignedx(L,i,is)\t((lua_Unsigned)lua_tointegerx(L,i,is))\n#define lua_tounsigned(L,i)\tlua_tounsignedx(L,(i),NULL)\n\n#endif\n/* }============================================================== */\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILCALL 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debugger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);\nLUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);\nLUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);\n\nLUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);\nLUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,\n                                               int fidx2, int n2);\n\nLUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook (lua_gethook) (lua_State *L);\nLUA_API int (lua_gethookmask) (lua_State *L);\nLUA_API int (lua_gethookcount) (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) 'global', 'local', 'field', 'method' */\n  const char *what;\t/* (S) 'Lua', 'C', 'main', 'tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  unsigned char nups;\t/* (u) number of upvalues */\n  unsigned char nparams;/* (u) number of parameters */\n  char isvararg;        /* (u) */\n  char istailcall;\t/* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  struct CallInfo *i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2016 Lua.org, PUC-Rio.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "build/lua-5.3.3/src/lua.rc",
    "content": "0  ICON  \"../etc/lua_lang.ico\"\r\n\r\n1 VERSIONINFO\r\n FILEVERSION 5,3,0,0\r\n PRODUCTVERSION 5,3,0,0\r\nBEGIN\r\n    BLOCK \"StringFileInfo\"\r\n    BEGIN\r\n        BLOCK \"040904b0\"\r\n        BEGIN\r\n            VALUE \"Comments\", \"www.lua.org\\0\"\r\n            VALUE \"CompanyName\", \"Lua.org\\0\"\r\n            VALUE \"FileDescription\", \"Lua Standalone Interpreter\\0\"\r\n            VALUE \"FileVersion\", \"5.3.0\\0\"\r\n            VALUE \"LegalCopyright\", \"Copyright  1994-2015 Lua.org, PUC-Rio.\\0\"\r\n            VALUE \"OriginalFilename\", \"lua.exe\\0\"\r\n            VALUE \"ProductName\", \"Lua - The Programming Language\\0\"\r\n            VALUE \"ProductVersion\", \"5.3.0\\0\"\r\n            VALUE \"PrivateBuild\", \"Built using LuaDist\\0\"\r\n        END\r\n    END\r\nEND\r\n\r\n#ifdef MSVC8\r\n1 24 \"lua_dll8.manifest\"\r\n#elif MSVC9\r\n1 24 \"lua_dll9.manifest\"\r\n#endif\r\n"
  },
  {
    "path": "build/lua-5.3.3/src/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** Lua compiler (saves bytecodes to files; also lists bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\nstatic void PrintFunction(const Proto* f, int full);\n#define luaU_print\tPrintFunction\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define OUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option '%s'\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n  \"usage: %s [options] [filenames]\\n\"\n  \"Available options are:\\n\"\n  \"  -l       list (use -l -l for full listing)\\n\"\n  \"  -o name  output to file 'name' (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and process stdin\\n\"\n  ,progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define IS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))\n    usage(\"'-o' needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s\\n\",LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define FUNCTION \"(function()end)();\"\n\nstatic const char* reader(lua_State *L, void *ud, size_t *size)\n{\n UNUSED(L);\n if ((*(int*)ud)--)\n {\n  *size=sizeof(FUNCTION)-1;\n  return FUNCTION;\n }\n else\n {\n  *size=0;\n  return NULL;\n }\n}\n\n#define toproto(L,i) getproto(L->top+(i))\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  Proto* f;\n  int i=n;\n  if (lua_load(L,reader,&i,\"=(\" PROGNAME \")\",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));\n  f=toproto(L,-1);\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;\n  }\n  f->sizelineinfo=0;\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstatic int pmain(lua_State* L)\n{\n int argc=(int)lua_tointeger(L,1);\n char** argv=(char**)lua_touserdata(L,2);\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=luaL_newstate();\n if (L==NULL) fatal(\"cannot create state: not enough memory\");\n lua_pushcfunction(L,&pmain);\n lua_pushinteger(L,argc);\n lua_pushlightuserdata(L,argv);\n if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n\n/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=tsslen(ts);\n printf(\"%c\",'\"');\n for (i=0; i<n; i++)\n {\n  int c=(int)(unsigned char)s[i];\n  switch (c)\n  {\n   case '\"':  printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint(c))\n   \t\t\tprintf(\"%c\",c);\n\t\telse\n\t\t\tprintf(\"\\\\%03d\",c);\n  }\n }\n printf(\"%c\",'\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMFLT:\n\t{\n\tchar buff[100];\n\tsprintf(buff,LUA_NUMBER_FMT,fltvalue(o));\n\tprintf(\"%s\",buff);\n\tif (buff[strspn(buff,\"-0123456789\")]=='\\0') printf(\".0\");\n\tbreak;\n\t}\n  case LUA_TNUMINT:\n\tprintf(LUA_INTEGER_FMT,ivalue(o));\n\tbreak;\n  case LUA_TSHRSTR: case LUA_TLNGSTR:\n\tPrintString(tsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\n#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : \"-\")\n#define MYK(x)\t\t(-1-(x))\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int ax=GETARG_Ax(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getfuncline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (MYK(INDEXK(b))) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (MYK(INDEXK(c))) : c);\n    break;\n   case iABx:\n    printf(\"%d\",a);\n    if (getBMode(o)==OpArgK) printf(\" %d\",MYK(bx));\n    if (getBMode(o)==OpArgU) printf(\" %d\",bx);\n    break;\n   case iAsBx:\n    printf(\"%d %d\",a,sbx);\n    break;\n   case iAx:\n    printf(\"%d\",MYK(ax));\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    break;\n   case OP_GETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(a));\n    if (ISK(b)) { printf(\" \"); PrintConstant(f,INDEXK(b)); }\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_POW:\n   case OP_DIV:\n   case OP_IDIV:\n   case OP_BAND:\n   case OP_BOR:\n   case OP_BXOR:\n   case OP_SHL:\n   case OP_SHR:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n   case OP_TFORLOOP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]); else printf(\"\\t; %d\",c);\n    break;\n   case OP_EXTRAARG:\n    printf(\"\\t; \"); PrintConstant(f,ax);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t((x==1)?\"\":\"s\")\n#define S(x)\t(int)(x),SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=f->source ? getstr(f->source) : \"=?\";\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\t(int)(f->numparams),f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->sizeupvalues));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintDebug(const Proto* f)\n{\n int i,n;\n n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);\n }\n}\n\nstatic void PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full) PrintDebug(f);\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "build/lua-5.3.3/src/luac.rc",
    "content": "0  ICON  \"../etc/lua.ico\"\r\n\r\n1 VERSIONINFO\r\n FILEVERSION 5,3,0,0\r\n PRODUCTVERSION 5,3,0,0\r\nBEGIN\r\n    BLOCK \"StringFileInfo\"\r\n    BEGIN\r\n        BLOCK \"040904b0\"\r\n        BEGIN\r\n            VALUE \"Comments\", \"www.lua.org\\0\"\r\n            VALUE \"CompanyName\", \"Lua.org\\0\"\r\n            VALUE \"FileDescription\", \"Lua Compiler\\0\"\r\n            VALUE \"FileVersion\", \"5.3.0\\0\"\r\n            VALUE \"LegalCopyright\", \"Copyright  1994-2015 Lua.org, PUC-Rio.\\0\"\r\n            VALUE \"OriginalFilename\", \"luac.exe\\0\"\r\n            VALUE \"ProductName\", \"Lua - The Programming Language\\0\"\r\n            VALUE \"ProductVersion\", \"5.3.0\\0\"\r\n            VALUE \"PrivateBuild\", \"Built using LuaDist\\0\"\r\n        END\r\n    END\r\nEND\r\n\r\n#ifdef MSVC8\r\n1 24 \"lua_dll8.manifest\"\r\n#elif MSVC9\r\n1 24 \"lua_dll9.manifest\"\r\n#endif\r\n"
  },
  {
    "path": "build/lua-5.3.3/src/luaconf.h.in",
    "content": "/*\n** $Id: luaconf.h,v 1.255 2016/05/01 20:06:09 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ===================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n** {====================================================================\n** System Configuration: macros to adapt (if needed) Lua to some\n** particular platform, for instance compiling it with 32-bit numbers or\n** restricting it to C89.\n** =====================================================================\n*/\n\n/*\n@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You\n** can also define LUA_32BITS in the make file, but changing here you\n** ensure that all software connected to Lua will be compiled with the\n** same configuration.\n*/\n/* #define LUA_32BITS */\n\n\n/*\n@@ LUA_USE_C89 controls the use of non-ISO-C89 features.\n** Define it if you want Lua to avoid the use of a few C99 features\n** or Windows-specific features on Windows.\n*/\n/* #define LUA_USE_C89 */\n\n\n/*\n** By default, Lua on Windows use (some) specific Windows features\n*/\n#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)\n#define LUA_USE_WINDOWS  /* enable goodies for regular Windows */\n#endif\n\n\n#if defined(LUA_USE_WINDOWS)\n#if !defined(WINAPI_FAMILY_PARTITION)\n#define LUA_DL_DLL\t/* enable support for DLL */\n#endif\n#define LUA_USE_C89\t/* broadly, Windows is C89 */\n#endif\n\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* MacOS does not need -ldl */\n#define LUA_USE_READLINE\t/* needs an extra library: -lreadline */\n#endif\n\n\n/*\n@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for\n** C89 ('long' and 'double'); Windows always has '__int64', so it does\n** not need to use this case.\n*/\n#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)\n#define LUA_C89_NUMBERS\n#endif\n\n\n\n/*\n@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.\n*/\n/* avoid undefined shifts */\n#if ((INT_MAX >> 15) >> 15) >= 1\n#define LUAI_BITSINT\t32\n#else\n/* 'int' always must have at least 16 bits */\n#define LUAI_BITSINT\t16\n#endif\n\n\n/*\n@@ LUA_INT_TYPE defines the type for Lua integers.\n@@ LUA_FLOAT_TYPE defines the type for Lua floats.\n** Lua should work fine with any mix of these options (if supported\n** by your C compiler). The usual configurations are 64-bit integers\n** and 'double' (the default), 32-bit integers and 'float' (for\n** restricted platforms), and 'long'/'double' (for C compilers not\n** compliant with C99, which may not have support for 'long long').\n*/\n\n/* predefined options for LUA_INT_TYPE */\n#define LUA_INT_INT\t\t1\n#define LUA_INT_LONG\t\t2\n#define LUA_INT_LONGLONG\t3\n\n/* predefined options for LUA_FLOAT_TYPE */\n#define LUA_FLOAT_FLOAT\t\t1\n#define LUA_FLOAT_DOUBLE\t2\n#define LUA_FLOAT_LONGDOUBLE\t3\n\n#if defined(LUA_32BITS)\t\t/* { */\n/*\n** 32-bit integers and 'float'\n*/\n#if LUAI_BITSINT >= 32  /* use 'int' if big enough */\n#define LUA_INT_TYPE\tLUA_INT_INT\n#else  /* otherwise use 'long' */\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#endif\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT\n\n#elif defined(LUA_C89_NUMBERS)\t/* }{ */\n/*\n** largest types available for C89 ('long' and 'double')\n*/\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** default configuration for 64-bit Lua ('long long' and 'double')\n*/\n#if !defined(LUA_INT_TYPE)\n#define LUA_INT_TYPE\tLUA_INT_LONGLONG\n#endif\n\n#if !defined(LUA_FLOAT_TYPE)\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n#endif\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n** Configuration for Paths.\n** ===================================================================\n*/\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n** Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n** C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#define LUA_VDIR\tLUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#if defined(_WIN32)\t/* { */\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_SHRDIR\t\"!\\\\..\\\\share\\\\lua\\\\\" LUA_VDIR \"\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua;\" \\\n\t\tLUA_SHRDIR\"?.lua;\" LUA_SHRDIR\"?\\\\init.lua;\" \\\n\t\t\".\\\\?.lua;\" \".\\\\?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.dll;\" \\\n\t\tLUA_CDIR\"..\\\\lib\\\\lua\\\\\" LUA_VDIR \"\\\\?.dll;\" \\\n\t\tLUA_CDIR\"loadall.dll;\" \".\\\\?.dll\"\n\n#else\t\t\t/* }{ */\n\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/\" LUA_VDIR \"/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/\" LUA_VDIR \"/\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua;\" \\\n\t\t\"./?.lua;\" \"./?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so;\" \"./?.so\"\n#endif\t\t\t/* } */\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Marks for exported symbols in the C code\n** ===================================================================\n*/\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all auxiliary library functions.\n@@ LUAMOD_API is a mark for all standard library opening functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\t/* { */\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\t/* { */\n#define LUA_API __declspec(dllexport)\n#else\t\t\t\t\t\t/* }{ */\n#define LUA_API __declspec(dllimport)\n#endif\t\t\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#define LUA_API\t\textern\n\n#endif\t\t\t\t/* } */\n\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n#define LUAMOD_API\tLUALIB_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n** exported to outside modules.\n@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables\n** that are not to be exported to outside modules (LUAI_DDEF for\n** definitions and LUAI_DDEC for declarations).\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library. Not all elf targets support\n** this attribute. Unfortunately, gcc does not offer a way to check\n** whether the target offers that support, and those without support\n** give a warning about it. To avoid these warnings, change to the\n** default definition.\n*/\n#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n    defined(__ELF__)\t\t/* { */\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#else\t\t\t\t/* }{ */\n#define LUAI_FUNC\textern\n#endif\t\t\t\t/* } */\n\n#define LUAI_DDEC\tLUAI_FUNC\n#define LUAI_DDEF\t/* empty */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Compatibility with previous versions\n** ===================================================================\n*/\n\n/*\n@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.\n@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.\n** You can define it to get all options, or change specific options\n** to fit your specific needs.\n*/\n#if defined(LUA_COMPAT_5_2)\t/* { */\n\n/*\n@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated\n** functions in the mathematical library.\n*/\n#define LUA_COMPAT_MATHLIB\n\n/*\n@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.\n*/\n#define LUA_COMPAT_BITLIB\n\n/*\n@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.\n*/\n#define LUA_COMPAT_IPAIRS\n\n/*\n@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for\n** manipulating other integer types (lua_pushunsigned, lua_tounsigned,\n** luaL_checkint, luaL_checklong, etc.)\n*/\n#define LUA_COMPAT_APIINTCASTS\n\n#endif\t\t\t\t/* } */\n\n\n#if defined(LUA_COMPAT_5_1)\t/* { */\n\n/* Incompatibilities from 5.2 -> 5.3 */\n#define LUA_COMPAT_MATHLIB\n#define LUA_COMPAT_APIINTCASTS\n\n/*\n@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.\n** You can replace it with 'table.unpack'.\n*/\n#define LUA_COMPAT_UNPACK\n\n/*\n@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.\n** You can replace it with 'package.searchers'.\n*/\n#define LUA_COMPAT_LOADERS\n\n/*\n@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.\n** You can call your C function directly (with light C functions).\n*/\n#define lua_cpcall(L,f,u)  \\\n\t(lua_pushcfunction(L, (f)), \\\n\t lua_pushlightuserdata(L,(u)), \\\n\t lua_pcall(L,1,0,0))\n\n\n/*\n@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.\n** You can rewrite 'log10(x)' as 'log(x, 10)'.\n*/\n#define LUA_COMPAT_LOG10\n\n/*\n@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base\n** library. You can rewrite 'loadstring(s)' as 'load(s)'.\n*/\n#define LUA_COMPAT_LOADSTRING\n\n/*\n@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.\n*/\n#define LUA_COMPAT_MAXN\n\n/*\n@@ The following macros supply trivial compatibility for some\n** changes in the API. The macros themselves document how to\n** change your code to avoid using them.\n*/\n#define lua_strlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_equal(L,idx1,idx2)\t\tlua_compare(L,(idx1),(idx2),LUA_OPEQ)\n#define lua_lessthan(L,idx1,idx2)\tlua_compare(L,(idx1),(idx2),LUA_OPLT)\n\n/*\n@@ LUA_COMPAT_MODULE controls compatibility with previous\n** module functions 'module' (Lua) and 'luaL_register' (C).\n*/\n#define LUA_COMPAT_MODULE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a\n@@ a float mark ('.0').\n** This macro is not on by default even in compatibility mode,\n** because this is not really an incompatibility.\n*/\n/* #define LUA_COMPAT_FLOATSTRING */\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Numbers.\n** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*\n** satisfy your needs.\n** ===================================================================\n*/\n\n/*\n@@ LUA_NUMBER is the floating-point type used by Lua.\n@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'\n@@ over a floating number.\n@@ l_mathlim(x) corrects limit name 'x' to the proper float type\n** by prefixing it with one of FLT/DBL/LDBL.\n@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.\n@@ LUA_NUMBER_FMT is the format for writing floats.\n@@ lua_number2str converts a float to a string.\n@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.\n@@ l_floor takes the floor of a float.\n@@ lua_str2number converts a decimal numeric string to a number.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define l_floor(x)\t\t(l_mathop(floor)(x))\n\n#define lua_number2str(s,sz,n)\tl_sprintf((s), sz, LUA_NUMBER_FMT, (n))\n\n/*\n@@ lua_numbertointeger converts a float number to an integer, or\n** returns 0 if float is not within the range of a lua_Integer.\n** (The range comparisons are tricky because of rounding. The tests\n** here assume a two-complement representation, where MININTEGER always\n** has an exact representation as a float; MAXINTEGER may not have one,\n** and therefore its conversion to float may have an ill-defined value.)\n*/\n#define lua_numbertointeger(n,p) \\\n  ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \\\n   (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \\\n      (*(p) = (LUA_INTEGER)(n), 1))\n\n\n/* now the variable definitions */\n\n#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT\t\t/* { single float */\n\n#define LUA_NUMBER\tfloat\n\n#define l_mathlim(n)\t\t(FLT_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.7g\"\n\n#define l_mathop(op)\t\top##f\n\n#define lua_str2number(s,p)\tstrtof((s), (p))\n\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\t/* }{ long double */\n\n#define LUA_NUMBER\tlong double\n\n#define l_mathlim(n)\t\t(LDBL_##n)\n\n#define LUAI_UACNUMBER\tlong double\n\n#define LUA_NUMBER_FRMLEN\t\"L\"\n#define LUA_NUMBER_FMT\t\t\"%.19Lg\"\n\n#define l_mathop(op)\t\top##l\n\n#define lua_str2number(s,p)\tstrtold((s), (p))\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE\t/* }{ double */\n\n#define LUA_NUMBER\tdouble\n\n#define l_mathlim(n)\t\t(DBL_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n\n#define l_mathop(op)\t\top\n\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n#else\t\t\t\t\t\t/* }{ */\n\n#error \"numeric float type not defined\"\n\n#endif\t\t\t\t\t/* } */\n\n\n\n/*\n@@ LUA_INTEGER is the integer type used by Lua.\n**\n@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.\n**\n@@ LUAI_UACINT is the result of an 'usual argument conversion'\n@@ over a lUA_INTEGER.\n@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.\n@@ LUA_INTEGER_FMT is the format for writing integers.\n@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.\n@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.\n@@ lua_integer2str converts an integer to a string.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define LUA_INTEGER_FMT\t\t\"%\" LUA_INTEGER_FRMLEN \"d\"\n#define lua_integer2str(s,sz,n)\tl_sprintf((s), sz, LUA_INTEGER_FMT, (n))\n\n#define LUAI_UACINT\t\tLUA_INTEGER\n\n/*\n** use LUAI_UACINT here to avoid problems with promotions (which\n** can turn a comparison between unsigneds into a signed comparison)\n*/\n#define LUA_UNSIGNED\t\tunsigned LUAI_UACINT\n\n\n/* now the variable definitions */\n\n#if LUA_INT_TYPE == LUA_INT_INT\t\t/* { int */\n\n#define LUA_INTEGER\t\tint\n#define LUA_INTEGER_FRMLEN\t\"\"\n\n#define LUA_MAXINTEGER\t\tINT_MAX\n#define LUA_MININTEGER\t\tINT_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONG\t/* }{ long */\n\n#define LUA_INTEGER\t\tlong\n#define LUA_INTEGER_FRMLEN\t\"l\"\n\n#define LUA_MAXINTEGER\t\tLONG_MAX\n#define LUA_MININTEGER\t\tLONG_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONGLONG\t/* }{ long long */\n\n/* use presence of macro LLONG_MAX as proxy for C99 compliance */\n#if defined(LLONG_MAX)\t\t/* { */\n/* use ISO C99 stuff */\n\n#define LUA_INTEGER\t\tlong long\n#define LUA_INTEGER_FRMLEN\t\"ll\"\n\n#define LUA_MAXINTEGER\t\tLLONG_MAX\n#define LUA_MININTEGER\t\tLLONG_MIN\n\n#elif defined(LUA_USE_WINDOWS) /* }{ */\n/* in Windows, can use specific Windows types */\n\n#define LUA_INTEGER\t\t__int64\n#define LUA_INTEGER_FRMLEN\t\"I64\"\n\n#define LUA_MAXINTEGER\t\t_I64_MAX\n#define LUA_MININTEGER\t\t_I64_MIN\n\n#else\t\t\t\t/* }{ */\n\n#error \"Compiler does not support 'long long'. Use option '-DLUA_32BITS' \\\n  or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)\"\n\n#endif\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#error \"numeric integer type not defined\"\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Dependencies with C99 and other C details\n** ===================================================================\n*/\n\n/*\n@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.\n** (All uses in Lua have only one format item.)\n*/\n#if !defined(LUA_USE_C89)\n#define l_sprintf(s,sz,f,i)\tsnprintf(s,sz,f,i)\n#else\n#define l_sprintf(s,sz,f,i)\t((void)(sz), sprintf(s,f,i))\n#endif\n\n\n/*\n@@ lua_strx2number converts an hexadecimal numeric string to a number.\n** In C99, 'strtod' does that conversion. Otherwise, you can\n** leave 'lua_strx2number' undefined and Lua will provide its own\n** implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_strx2number(s,p)\t\tlua_str2number(s,p)\n#endif\n\n\n/*\n@@ lua_number2strx converts a float to an hexadecimal numeric string. \n** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.\n** Otherwise, you can leave 'lua_number2strx' undefined and Lua will\n** provide its own implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_number2strx(L,b,sz,f,n)\t((void)L, l_sprintf(b,sz,f,n))\n#endif\n\n\n/*\n** 'strtof' and 'opf' variants for math functions are not valid in\n** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the\n** availability of these variants. ('math.h' is already included in\n** all files that use these macros.)\n*/\n#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))\n#undef l_mathop  /* variants not available */\n#undef lua_str2number\n#define l_mathop(op)\t\t(lua_Number)op  /* no variant */\n#define lua_str2number(s,p)\t((lua_Number)strtod((s), (p)))\n#endif\n\n\n/*\n@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation\n** functions.  It must be a numerical type; Lua will use 'intptr_t' if\n** available, otherwise it will use 'ptrdiff_t' (the nearest thing to\n** 'intptr_t' in C89)\n*/\n#define LUA_KCONTEXT\tptrdiff_t\n\n#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \\\n    __STDC_VERSION__ >= 199901L\n#include <stdint.h>\n#if defined(INTPTR_MAX)  /* even in C99 this type is optional */\n#undef LUA_KCONTEXT\n#define LUA_KCONTEXT\tintptr_t\n#endif\n#endif\n\n\n/*\n@@ lua_getlocaledecpoint gets the locale \"radix character\" (decimal point).\n** Change that if you do not want to use C locales. (Code using this\n** macro must include header 'locale.h'.)\n*/\n#ifdef __ANDROID__\n#define lua_getlocaledecpoint() '.'\n#elif !defined(lua_getlocaledecpoint)\n#define lua_getlocaledecpoint()\t\t(localeconv()->decimal_point[0])\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Language Variations\n** =====================================================================\n*/\n\n/*\n@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some\n** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from\n** numbers to strings. Define LUA_NOCVTS2N to turn off automatic\n** coercion from strings to numbers.\n*/\n/* #define LUA_NOCVTN2S */\n/* #define LUA_NOCVTS2N */\n\n\n/*\n@@ LUA_USE_APICHECK turns on several consistency checks on the C API.\n** Define it as a help when debugging C code.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(l,e)\tassert(e)\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Macros that affect the API and must be stable (that is, must be the\n** same when you compile Lua and when you compile code that links to\n** Lua). You probably do not want/need to change them.\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXSTACK limits the size of the Lua stack.\n** CHANGE it if you need a different limit. This limit is arbitrary;\n** its only purpose is to stop Lua from consuming unlimited stack\n** space (and to reserve some numbers for pseudo-indices).\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_MAXSTACK\t\t1000000\n#else\n#define LUAI_MAXSTACK\t\t15000\n#endif\n\n\n/*\n@@ LUA_EXTRASPACE defines the size of a raw memory area associated with\n** a Lua state with very fast access.\n** CHANGE it if you need a different size.\n*/\n#define LUA_EXTRASPACE\t\t(sizeof(void *))\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@@ of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#cmakedefine LUA_IDSIZE\t@LUA_IDSIZE@\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n** CHANGE it if it uses too much C-stack space. (For long double,\n** 'string.format(\"%.99f\", 1e4932)' needs ~5030 bytes, so a\n** smaller buffer would force a memory allocation for each call to\n** 'string.format'.)\n*/\n#if defined(LUA_FLOAT_LONGDOUBLE)\n#define LUAL_BUFFERSIZE\t\t8192\n#else\n#define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** Lua does not use these macros anymore; they are here for\n** compatibility only.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n\nLUAMOD_API int (luaopen_base) (lua_State *L);\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUAMOD_API int (luaopen_coroutine) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUAMOD_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUAMOD_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUAMOD_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUAMOD_API int (luaopen_string) (lua_State *L);\n\n#define LUA_UTF8LIBNAME\t\"utf8\"\nLUAMOD_API int (luaopen_utf8) (lua_State *L);\n\n#define LUA_BITLIBNAME\t\"bit32\"\nLUAMOD_API int (luaopen_bit32) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUAMOD_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUAMOD_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUAMOD_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L);\n\n\n\n#if !defined(lua_assert)\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\n\n#if !defined(luai_verifycode)\n#define luai_verifycode(L,b,f)  /* empty */\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  ZIO *Z;\n  const char *name;\n} LoadState;\n\n\nstatic l_noret error(LoadState *S, const char *why) {\n  luaO_pushfstring(S->L, \"%s: %s precompiled chunk\", S->name, why);\n  luaD_throw(S->L, LUA_ERRSYNTAX);\n}\n\n\n/*\n** All high-level loads go through LoadVector; you can change it to\n** adapt to the endianness of the input\n*/\n#define LoadVector(S,b,n)\tLoadBlock(S,b,(n)*sizeof((b)[0]))\n\nstatic void LoadBlock (LoadState *S, void *b, size_t size) {\n  if (luaZ_read(S->Z, b, size) != 0)\n    error(S, \"truncated\");\n}\n\n\n#define LoadVar(S,x)\t\tLoadVector(S,&x,1)\n\n\nstatic lu_byte LoadByte (LoadState *S) {\n  lu_byte x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic int LoadInt (LoadState *S) {\n  int x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Number LoadNumber (LoadState *S) {\n  lua_Number x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Integer LoadInteger (LoadState *S) {\n  lua_Integer x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic TString *LoadString (LoadState *S) {\n  size_t size = LoadByte(S);\n  if (size == 0xFF)\n    LoadVar(S, size);\n  if (size == 0)\n    return NULL;\n  else if (--size <= LUAI_MAXSHORTLEN) {  /* short string? */\n    char buff[LUAI_MAXSHORTLEN];\n    LoadVector(S, buff, size);\n    return luaS_newlstr(S->L, buff, size);\n  }\n  else {  /* long string */\n    TString *ts = luaS_createlngstrobj(S->L, size);\n    LoadVector(S, getstr(ts), size);  /* load directly in final place */\n    return ts;\n  }\n}\n\n\nstatic void LoadCode (LoadState *S, Proto *f) {\n  int n = LoadInt(S);\n  f->code = luaM_newvector(S->L, n, Instruction);\n  f->sizecode = n;\n  LoadVector(S, f->code, n);\n}\n\n\nstatic void LoadFunction(LoadState *S, Proto *f, TString *psource);\n\n\nstatic void LoadConstants (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->k = luaM_newvector(S->L, n, TValue);\n  f->sizek = n;\n  for (i = 0; i < n; i++)\n    setnilvalue(&f->k[i]);\n  for (i = 0; i < n; i++) {\n    TValue *o = &f->k[i];\n    int t = LoadByte(S);\n    switch (t) {\n    case LUA_TNIL:\n      setnilvalue(o);\n      break;\n    case LUA_TBOOLEAN:\n      setbvalue(o, LoadByte(S));\n      break;\n    case LUA_TNUMFLT:\n      setfltvalue(o, LoadNumber(S));\n      break;\n    case LUA_TNUMINT:\n      setivalue(o, LoadInteger(S));\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      setsvalue2n(S->L, o, LoadString(S));\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void LoadProtos (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->p = luaM_newvector(S->L, n, Proto *);\n  f->sizep = n;\n  for (i = 0; i < n; i++)\n    f->p[i] = NULL;\n  for (i = 0; i < n; i++) {\n    f->p[i] = luaF_newproto(S->L);\n    LoadFunction(S, f->p[i], f->source);\n  }\n}\n\n\nstatic void LoadUpvalues (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->upvalues = luaM_newvector(S->L, n, Upvaldesc);\n  f->sizeupvalues = n;\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = NULL;\n  for (i = 0; i < n; i++) {\n    f->upvalues[i].instack = LoadByte(S);\n    f->upvalues[i].idx = LoadByte(S);\n  }\n}\n\n\nstatic void LoadDebug (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->lineinfo = luaM_newvector(S->L, n, int);\n  f->sizelineinfo = n;\n  LoadVector(S, f->lineinfo, n);\n  n = LoadInt(S);\n  f->locvars = luaM_newvector(S->L, n, LocVar);\n  f->sizelocvars = n;\n  for (i = 0; i < n; i++)\n    f->locvars[i].varname = NULL;\n  for (i = 0; i < n; i++) {\n    f->locvars[i].varname = LoadString(S);\n    f->locvars[i].startpc = LoadInt(S);\n    f->locvars[i].endpc = LoadInt(S);\n  }\n  n = LoadInt(S);\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = LoadString(S);\n}\n\n\nstatic void LoadFunction (LoadState *S, Proto *f, TString *psource) {\n  f->source = LoadString(S);\n  if (f->source == NULL)  /* no source in dump? */\n    f->source = psource;  /* reuse parent's source */\n  f->linedefined = LoadInt(S);\n  f->lastlinedefined = LoadInt(S);\n  f->numparams = LoadByte(S);\n  f->is_vararg = LoadByte(S);\n  f->maxstacksize = LoadByte(S);\n  LoadCode(S, f);\n  LoadConstants(S, f);\n  LoadUpvalues(S, f);\n  LoadProtos(S, f);\n  LoadDebug(S, f);\n}\n\n\nstatic void checkliteral (LoadState *S, const char *s, const char *msg) {\n  char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */\n  size_t len = strlen(s);\n  LoadVector(S, buff, len);\n  if (memcmp(s, buff, len) != 0)\n    error(S, msg);\n}\n\n\nstatic void fchecksize (LoadState *S, size_t size, const char *tname) {\n  if (LoadByte(S) != size)\n    error(S, luaO_pushfstring(S->L, \"%s size mismatch in\", tname));\n}\n\n\n#define checksize(S,t)\tfchecksize(S,sizeof(t),#t)\n\nstatic void checkHeader (LoadState *S) {\n  checkliteral(S, LUA_SIGNATURE + 1, \"not a\");  /* 1st char already checked */\n  if (LoadByte(S) != LUAC_VERSION)\n    error(S, \"version mismatch in\");\n  if (LoadByte(S) != LUAC_FORMAT)\n    error(S, \"format mismatch in\");\n  checkliteral(S, LUAC_DATA, \"corrupted\");\n  checksize(S, int);\n  checksize(S, size_t);\n  checksize(S, Instruction);\n  checksize(S, lua_Integer);\n  checksize(S, lua_Number);\n  if (LoadInteger(S) != LUAC_INT)\n    error(S, \"endianness mismatch in\");\n  if (LoadNumber(S) != LUAC_NUM)\n    error(S, \"float format mismatch in\");\n}\n\n\n/*\n** load precompiled chunk\n*/\nLClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {\n  LoadState S;\n  LClosure *cl;\n  if (*name == '@' || *name == '=')\n    S.name = name + 1;\n  else if (*name == LUA_SIGNATURE[0])\n    S.name = \"binary string\";\n  else\n    S.name = name;\n  S.L = L;\n  S.Z = Z;\n  checkHeader(&S);\n  cl = luaF_newLclosure(L, LoadByte(&S));\n  setclLvalue(L, L->top, cl);\n  luaD_inctop(L);\n  cl->p = luaF_newproto(L);\n  LoadFunction(&S, cl->p, NULL);\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luai_verifycode(L, buff, cl->p);\n  return cl;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/* data to catch conversion errors */\n#define LUAC_DATA\t\"\\x19\\x93\\r\\n\\x1a\\n\"\n\n#define LUAC_INT\t0x5678\n#define LUAC_NUM\tcast_num(370.5)\n\n#define MYINT(s)\t(s[0]-'0')\n#define LUAC_VERSION\t(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))\n#define LUAC_FORMAT\t0\t/* this is the official format */\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,\n                         void* data, int strip);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lutf8lib.c",
    "content": "/*\n** $Id: lutf8lib.c,v 1.15 2015/03/28 19:16:55 roberto Exp $\n** Standard library for UTF-8 manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define lutf8lib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <assert.h>\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#define MAXUNICODE\t0x10FFFF\n\n#define iscont(p)\t((*(p) & 0xC0) == 0x80)\n\n\n/* from strlib */\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer u_posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\n/*\n** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.\n*/\nstatic const char *utf8_decode (const char *o, int *val) {\n  static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};\n  const unsigned char *s = (const unsigned char *)o;\n  unsigned int c = s[0];\n  unsigned int res = 0;  /* final result */\n  if (c < 0x80)  /* ascii? */\n    res = c;\n  else {\n    int count = 0;  /* to count number of continuation bytes */\n    while (c & 0x40) {  /* still have continuation bytes? */\n      int cc = s[++count];  /* read next byte */\n      if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */\n        return NULL;  /* invalid byte sequence */\n      res = (res << 6) | (cc & 0x3F);  /* add lower 6 bits from cont. byte */\n      c <<= 1;  /* to test next bit */\n    }\n    res |= ((c & 0x7F) << (count * 5));  /* add first byte */\n    if (count > 3 || res > MAXUNICODE || res <= limits[count])\n      return NULL;  /* invalid byte sequence */\n    s += count;  /* skip continuation bytes read */\n  }\n  if (val) *val = res;\n  return (const char *)s + 1;  /* +1 to include first byte */\n}\n\n\n/*\n** utf8len(s [, i [, j]]) --> number of characters that start in the\n** range [i,j], or nil + current position if 's' is not well formed in\n** that interval\n*/\nstatic int utflen (lua_State *L) {\n  int n = 0;\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,\n                   \"initial position out of string\");\n  luaL_argcheck(L, --posj < (lua_Integer)len, 3,\n                   \"final position out of string\");\n  while (posi <= posj) {\n    const char *s1 = utf8_decode(s + posi, NULL);\n    if (s1 == NULL) {  /* conversion error? */\n      lua_pushnil(L);  /* return nil ... */\n      lua_pushinteger(L, posi + 1);  /* ... and current position */\n      return 2;\n    }\n    posi = s1 - s;\n    n++;\n  }\n  lua_pushinteger(L, n);\n  return 1;\n}\n\n\n/*\n** codepoint(s, [i, [j]])  -> returns codepoints for all characters\n** that start in the range [i,j]\n*/\nstatic int codepoint (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  int n;\n  const char *se;\n  luaL_argcheck(L, posi >= 1, 2, \"out of range\");\n  luaL_argcheck(L, pose <= (lua_Integer)len, 3, \"out of range\");\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  n = 0;\n  se = s + pose;\n  for (s += posi - 1; s < se;) {\n    int code;\n    s = utf8_decode(s, &code);\n    if (s == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, code);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void pushutfchar (lua_State *L, int arg) {\n  lua_Integer code = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, \"value out of range\");\n  lua_pushfstring(L, \"%U\", (long)code);\n}\n\n\n/*\n** utfchar(n1, n2, ...)  -> char(n1)..char(n2)...\n*/\nstatic int utfchar (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  if (n == 1)  /* optimize common case of single char */\n    pushutfchar(L, 1);\n  else {\n    int i;\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    for (i = 1; i <= n; i++) {\n      pushutfchar(L, i);\n      luaL_addvalue(&b);\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\n/*\n** offset(s, n, [i])  -> index where n-th character counting from\n**   position 'i' starts; 0 means character at 'i'.\n*/\nstatic int byteoffset (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n  = luaL_checkinteger(L, 2);\n  lua_Integer posi = (n >= 0) ? 1 : len + 1;\n  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,\n                   \"position out of range\");\n  if (n == 0) {\n    /* find beginning of current byte sequence */\n    while (posi > 0 && iscont(s + posi)) posi--;\n  }\n  else {\n    if (iscont(s + posi))\n      luaL_error(L, \"initial position is a continuation byte\");\n    if (n < 0) {\n       while (n < 0 && posi > 0) {  /* move back */\n         do {  /* find beginning of previous character */\n           posi--;\n         } while (posi > 0 && iscont(s + posi));\n         n++;\n       }\n     }\n     else {\n       n--;  /* do not move for 1st character */\n       while (n > 0 && posi < (lua_Integer)len) {\n         do {  /* find beginning of next character */\n           posi++;\n         } while (iscont(s + posi));  /* (cannot pass final '\\0') */\n         n--;\n       }\n     }\n  }\n  if (n == 0)  /* did it find given character? */\n    lua_pushinteger(L, posi + 1);\n  else  /* no such character */\n    lua_pushnil(L);\n  return 1;  \n}\n\n\nstatic int iter_aux (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n = lua_tointeger(L, 2) - 1;\n  if (n < 0)  /* first iteration? */\n    n = 0;  /* start from here */\n  else if (n < (lua_Integer)len) {\n    n++;  /* skip current byte */\n    while (iscont(s + n)) n++;  /* and its continuations */\n  }\n  if (n >= (lua_Integer)len)\n    return 0;  /* no more codepoints */\n  else {\n    int code;\n    const char *next = utf8_decode(s + n, &code);\n    if (next == NULL || iscont(next))\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, n + 1);\n    lua_pushinteger(L, code);\n    return 2;\n  }\n}\n\n\nstatic int iter_codes (lua_State *L) {\n  luaL_checkstring(L, 1);\n  lua_pushcfunction(L, iter_aux);\n  lua_pushvalue(L, 1);\n  lua_pushinteger(L, 0);\n  return 3;\n}\n\n\n/* pattern to match a single UTF-8 character */\n#define UTF8PATT\t\"[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*\"\n\n\nstatic const luaL_Reg funcs[] = {\n  {\"offset\", byteoffset},\n  {\"codepoint\", codepoint},\n  {\"char\", utfchar},\n  {\"len\", utflen},\n  {\"codes\", iter_codes},\n  /* placeholders */\n  {\"charpattern\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_utf8 (lua_State *L) {\n  luaL_newlib(L, funcs);\n  lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);\n  lua_setfield(L, -2, \"charpattern\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.268 2016/02/05 19:59:14 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t2000\n\n\n\n/*\n** 'l_intfitsf' checks whether a given integer can be converted to a\n** float without rounding. Used in comparisons. Left undefined if\n** all integers fit in a float precisely.\n*/\n#if !defined(l_intfitsf)\n\n/* number of bits in the mantissa of a float */\n#define NBM\t\t(l_mathlim(MANT_DIG))\n\n/*\n** Check whether some integers may not fit in a float, that is, whether\n** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).\n** (The shifts are done in parts to avoid shifting by more than the size\n** of an integer. In a worst case, NBM == 113 for long double and\n** sizeof(integer) == 32.)\n*/\n#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \\\n\t>> (NBM - (3 * (NBM / 4))))  >  0\n\n#define l_intfitsf(i)  \\\n  (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM))\n\n#endif\n\n#endif\n\n\n\n/*\n** Try to convert a value to a float. The float case is already handled\n** by the macro 'tonumber'.\n*/\nint luaV_tonumber_ (const TValue *obj, lua_Number *n) {\n  TValue v;\n  if (ttisinteger(obj)) {\n    *n = cast_num(ivalue(obj));\n    return 1;\n  }\n  else if (cvt2num(obj) &&  /* string convertible to number? */\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */\n    return 1;\n  }\n  else\n    return 0;  /* conversion failed */\n}\n\n\n/*\n** try to convert a value to an integer, rounding according to 'mode':\n** mode == 0: accepts only integral values\n** mode == 1: takes the floor of the number\n** mode == 2: takes the ceil of the number\n*/\nint luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {\n  TValue v;\n again:\n  if (ttisfloat(obj)) {\n    lua_Number n = fltvalue(obj);\n    lua_Number f = l_floor(n);\n    if (n != f) {  /* not an integral value? */\n      if (mode == 0) return 0;  /* fails if mode demands integral value */\n      else if (mode > 1)  /* needs ceil? */\n        f += 1;  /* convert floor to ceil (remember: n != f) */\n    }\n    return lua_numbertointeger(f, p);\n  }\n  else if (ttisinteger(obj)) {\n    *p = ivalue(obj);\n    return 1;\n  }\n  else if (cvt2num(obj) &&\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    obj = &v;\n    goto again;  /* convert result from 'luaO_str2num' to an integer */\n  }\n  return 0;  /* conversion failed */\n}\n\n\n/*\n** Try to convert a 'for' limit to an integer, preserving the\n** semantics of the loop.\n** (The following explanation assumes a non-negative step; it is valid\n** for negative steps mutatis mutandis.)\n** If the limit can be converted to an integer, rounding down, that is\n** it.\n** Otherwise, check whether the limit can be converted to a number.  If\n** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,\n** which means no limit.  If the number is too negative, the loop\n** should not run, because any initial integer value is larger than the\n** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects\n** the extreme case when the initial value is LUA_MININTEGER, in which\n** case the LUA_MININTEGER limit would still run the loop once.\n*/\nstatic int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,\n                     int *stopnow) {\n  *stopnow = 0;  /* usually, let loops run */\n  if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) {  /* not fit in integer? */\n    lua_Number n;  /* try to convert to float */\n    if (!tonumber(obj, &n)) /* cannot convert to float? */\n      return 0;  /* not a number */\n    if (luai_numlt(0, n)) {  /* if true, float is larger than max integer */\n      *p = LUA_MAXINTEGER;\n      if (step < 0) *stopnow = 1;\n    }\n    else {  /* float is smaller than min integer */\n      *p = LUA_MININTEGER;\n      if (step >= 0) *stopnow = 1;\n    }\n  }\n  return 1;\n}\n\n\n/*\n** Finish the table access 'val = t[key]'.\n** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to\n** t[k] entry (which must be nil).\n*/\nvoid luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,\n                      const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  const TValue *tm;  /* metamethod */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    if (slot == NULL) {  /* 't' is not a table? */\n      lua_assert(!ttistable(t));\n      tm = luaT_gettmbyobj(L, t, TM_INDEX);\n      if (ttisnil(tm))\n        luaG_typeerror(L, t, \"index\");  /* no metamethod */\n      /* else will try the metamethod */\n    }\n    else {  /* 't' is a table */\n      lua_assert(ttisnil(slot));\n      tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        setnilvalue(val);  /* result is nil */\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    if (ttisfunction(tm)) {  /* is metamethod a function? */\n      luaT_callTM(L, tm, t, key, val, 1);  /* call it */\n      return;\n    }\n    t = tm;  /* else try to access 'tm[key]' */\n    if (luaV_fastget(L,t,key,slot,luaH_get)) {  /* fast track? */\n      setobj2s(L, val, slot);  /* done */\n      return;\n    }\n    /* else repeat (tail call 'luaV_finishget') */\n  }\n  luaG_runerror(L, \"'__index' chain too long; possible loop\");\n}\n\n\n/*\n** Finish a table assignment 't[key] = val'.\n** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points\n** to the entry 't[key]', or to 'luaO_nilobject' if there is no such\n** entry.  (The value at 'slot' must be nil, otherwise 'luaV_fastset'\n** would have done the job.)\n*/\nvoid luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                     StkId val, const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;  /* '__newindex' metamethod */\n    if (slot != NULL) {  /* is 't' a table? */\n      Table *h = hvalue(t);  /* save 't' table */\n      lua_assert(ttisnil(slot));  /* old value must be nil */\n      tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        if (slot == luaO_nilobject)  /* no previous entry? */\n          slot = luaH_newkey(L, h, key);  /* create one */\n        /* no metamethod and (now) there is an entry with given key */\n        setobj2t(L, cast(TValue *, slot), val);  /* set its new value */\n        invalidateTMcache(h);\n        luaC_barrierback(L, h, val);\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    else {  /* not a table; check metamethod */\n      if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n        luaG_typeerror(L, t, \"index\");\n    }\n    /* try the metamethod */\n    if (ttisfunction(tm)) {\n      luaT_callTM(L, tm, t, key, val, 0);\n      return;\n    }\n    t = tm;  /* else repeat assignment over 'tm' */\n    if (luaV_fastset(L, t, key, slot, luaH_get, val))\n      return;  /* done */\n    /* else loop */\n  }\n  luaG_runerror(L, \"'__newindex' chain too long; possible loop\");\n}\n\n\n/*\n** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-\n** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.\n** The code is a little tricky because it allows '\\0' in the strings\n** and it uses 'strcoll' (to respect locales) for each segments\n** of the strings.\n*/\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = tsslen(ls);\n  const char *r = getstr(rs);\n  size_t lr = tsslen(rs);\n  for (;;) {  /* for each segment */\n    int temp = strcoll(l, r);\n    if (temp != 0)  /* not equal? */\n      return temp;  /* done */\n    else {  /* strings are equal up to a '\\0' */\n      size_t len = strlen(l);  /* index of first '\\0' in both strings */\n      if (len == lr)  /* 'rs' is finished? */\n        return (len == ll) ? 0 : 1;  /* check 'ls' */\n      else if (len == ll)  /* 'ls' is finished? */\n        return -1;  /* 'ls' is smaller than 'rs' ('rs' is not finished) */\n      /* both strings longer than 'len'; go on comparing after the '\\0' */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than float 'f'. If 'i' has an\n** exact representation as a float ('l_intfitsf'), compare numbers as\n** floats. Otherwise, if 'f' is outside the range for integers, result\n** is trivial. Otherwise, compare them as integers. (When 'i' has no\n** float representation, either 'f' is \"far away\" from 'i' or 'f' has\n** no precision left for a fractional part; either way, how 'f' is\n** truncated is irrelevant.) When 'f' is NaN, comparisons must result\n** in false.\n*/\nstatic int LTintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f > cast_num(LUA_MININTEGER))  /* minint < f <= maxint ? */\n      return (i < cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f <= minint <= i (or 'f' is NaN)  -->  not(i < f) */\n      return 0;\n  }\n#endif\n  return luai_numlt(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Check whether integer 'i' is less than or equal to float 'f'.\n** See comments on previous function.\n*/\nstatic int LEintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f >= cast_num(LUA_MININTEGER))  /* minint <= f <= maxint ? */\n      return (i <= cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f < minint <= i (or 'f' is NaN)  -->  not(i <= f) */\n      return 0;\n  }\n#endif\n  return luai_numle(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Return 'l < r', for numbers.\n*/\nstatic int LTnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li < ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LTintfloat(li, fltvalue(r));  /* l < r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numlt(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /* NaN < i is always false */\n    else  /* without NaN, (l < r)  <-->  not(r <= l) */\n      return !LEintfloat(ivalue(r), lf);  /* not (r <= l) ? */\n  }\n}\n\n\n/*\n** Return 'l <= r', for numbers.\n*/\nstatic int LEnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li <= ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LEintfloat(li, fltvalue(r));  /* l <= r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numle(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /*  NaN <= i is always false */\n    else  /* without NaN, (l <= r)  <-->  not(r < l) */\n      return !LTintfloat(ivalue(r), lf);  /* not (r < l) ? */\n  }\n}\n\n\n/*\n** Main operation less than; return 'l < r'.\n*/\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LTnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) < 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0)  /* no metamethod? */\n    luaG_ordererror(L, l, r);  /* error */\n  return res;\n}\n\n\n/*\n** Main operation less than or equal to; return 'l <= r'. If it needs\n** a metamethod and there is no '__le', try '__lt', based on\n** l <= r iff !(r < l) (assuming a total order). If the metamethod\n** yields during this substitution, the continuation has to know\n** about it (to negate the result of r<l); bit CIST_LEQ in the call\n** status keeps that information.\n*/\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LEnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0)  /* try 'le' */\n    return res;\n  else {  /* try 'lt': */\n    L->ci->callstatus |= CIST_LEQ;  /* mark it is doing 'lt' for 'le' */\n    res = luaT_callorderTM(L, r, l, TM_LT);\n    L->ci->callstatus ^= CIST_LEQ;  /* clear mark */\n    if (res < 0)\n      luaG_ordererror(L, l, r);\n    return !res;  /* result is negated */\n  }\n}\n\n\n/*\n** Main operation for equality of Lua values; return 't1 == t2'.\n** L == NULL means raw equality (no metamethods)\n*/\nint luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  if (ttype(t1) != ttype(t2)) {  /* not the same variant? */\n    if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)\n      return 0;  /* only numbers can be equal with different variants */\n    else {  /* two numbers with different variants */\n      lua_Integer i1, i2;  /* compare them as integers */\n      return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);\n    }\n  }\n  /* values have same type and same variant */\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));\n    case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TLCF: return fvalue(t1) == fvalue(t2);\n    case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default:\n      return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL)  /* no TM? */\n    return 0;  /* objects are different */\n  luaT_callTM(L, tm, t1, t2, L->top, 1);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\n/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */\n#define tostring(L,o)  \\\n\t(ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))\n\n#define isemptystr(o)\t(ttisshrstring(o) && tsvalue(o)->shrlen == 0)\n\n/* copy strings in stack from top - n up to top - 1 to buffer */\nstatic void copy2buff (StkId top, int n, char *buff) {\n  size_t tl = 0;  /* size already copied */\n  do {\n    size_t l = vslen(top - n);  /* length of string being copied */\n    memcpy(buff + tl, svalue(top - n), l * sizeof(char));\n    tl += l;\n  } while (--n > 0);\n}\n\n\n/*\n** Main operation for concatenation: concat 'total' values in the stack,\n** from 'L->top - total' up to 'L->top - 1'.\n*/\nvoid luaV_concat (lua_State *L, int total) {\n  lua_assert(total >= 2);\n  do {\n    StkId top = L->top;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1))\n      luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT);\n    else if (isemptystr(top - 1))  /* second operand is empty? */\n      cast_void(tostring(L, top - 2));  /* result is first operand */\n    else if (isemptystr(top - 2)) {  /* first operand is an empty string? */\n      setobjs2s(L, top - 2, top - 1);  /* result is second op. */\n    }\n    else {\n      /* at least two non-empty string values; get as many as possible */\n      size_t tl = vslen(top - 1);\n      TString *ts;\n      /* collect total length and number of strings */\n      for (n = 1; n < total && tostring(L, top - n - 1); n++) {\n        size_t l = vslen(top - n - 1);\n        if (l >= (MAX_SIZE/sizeof(char)) - tl)\n          luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */\n        char buff[LUAI_MAXSHORTLEN];\n        copy2buff(top, n, buff);  /* copy strings to buffer */\n        ts = luaS_newlstr(L, buff, tl);\n      }\n      else {  /* long string; copy strings directly to final result */\n        ts = luaS_createlngstrobj(L, tl);\n        copy2buff(top, n, getstr(ts));\n      }\n      setsvalue2s(L, top - n, ts);  /* create result */\n    }\n    total -= n-1;  /* got 'n' strings to create 1 new */\n    L->top -= n-1;  /* popped 'n' strings and pushed one */\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\n/*\n** Main operation 'ra' = #rb'.\n*/\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n  const TValue *tm;\n  switch (ttype(rb)) {\n    case LUA_TTABLE: {\n      Table *h = hvalue(rb);\n      tm = fasttm(L, h->metatable, TM_LEN);\n      if (tm) break;  /* metamethod? break switch to call it */\n      setivalue(ra, luaH_getn(h));  /* else primitive len */\n      return;\n    }\n    case LUA_TSHRSTR: {\n      setivalue(ra, tsvalue(rb)->shrlen);\n      return;\n    }\n    case LUA_TLNGSTR: {\n      setivalue(ra, tsvalue(rb)->u.lnglen);\n      return;\n    }\n    default: {  /* try metamethod */\n      tm = luaT_gettmbyobj(L, rb, TM_LEN);\n      if (ttisnil(tm))  /* no metamethod? */\n        luaG_typeerror(L, rb, \"get length of\");\n      break;\n    }\n  }\n  luaT_callTM(L, tm, rb, rb, ra, 1);\n}\n\n\n/*\n** Integer division; return 'm // n', that is, floor(m/n).\n** C division truncates its result (rounds towards zero).\n** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,\n** otherwise 'floor(q) == trunc(q) - 1'.\n*/\nlua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to divide by zero\");\n    return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */\n  }\n  else {\n    lua_Integer q = m / n;  /* perform C division */\n    if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */\n      q -= 1;  /* correct result for different rounding */\n    return q;\n  }\n}\n\n\n/*\n** Integer modulus; return 'm % n'. (Assume that C '%' with\n** negative operands follows C99 behavior. See previous comment\n** about luaV_div.)\n*/\nlua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to perform 'n%%0'\");\n    return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */\n  }\n  else {\n    lua_Integer r = m % n;\n    if (r != 0 && (m ^ n) < 0)  /* 'm/n' would be non-integer negative? */\n      r += n;  /* correct result for different rounding */\n    return r;\n  }\n}\n\n\n/* number of bits in an integer */\n#define NBITS\tcast_int(sizeof(lua_Integer) * CHAR_BIT)\n\n/*\n** Shift left operation. (Shift right just negates 'y'.)\n*/\nlua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {\n  if (y < 0) {  /* shift right? */\n    if (y <= -NBITS) return 0;\n    else return intop(>>, x, -y);\n  }\n  else {  /* shift left */\n    if (y >= NBITS) return 0;\n    else return intop(<<, x, y);\n  }\n}\n\n\n/*\n** check whether cached closure in prototype 'p' may be reused, that is,\n** whether there is a cached closure with the same upvalues needed by\n** new closure to be created.\n*/\nstatic LClosure *getcached (Proto *p, UpVal **encup, StkId base) {\n  LClosure *c = p->cache;\n  if (c != NULL) {  /* is there a cached closure? */\n    int nup = p->sizeupvalues;\n    Upvaldesc *uv = p->upvalues;\n    int i;\n    for (i = 0; i < nup; i++) {  /* check whether it has right upvalues */\n      TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;\n      if (c->upvals[i]->v != v)\n        return NULL;  /* wrong upvalue; cannot reuse closure */\n    }\n  }\n  return c;  /* return cached closure (or NULL if no cached closure) */\n}\n\n\n/*\n** create a new Lua closure, push it in the stack, and initialize\n** its upvalues. Note that the closure is not cached if prototype is\n** already black (which means that 'cache' was already cleared by the\n** GC).\n*/\nstatic void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,\n                         StkId ra) {\n  int nup = p->sizeupvalues;\n  Upvaldesc *uv = p->upvalues;\n  int i;\n  LClosure *ncl = luaF_newLclosure(L, nup);\n  ncl->p = p;\n  setclLvalue(L, ra, ncl);  /* anchor new closure in stack */\n  for (i = 0; i < nup; i++) {  /* fill in its upvalues */\n    if (uv[i].instack)  /* upvalue refers to local variable? */\n      ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);\n    else  /* get upvalue from enclosing function */\n      ncl->upvals[i] = encup[uv[i].idx];\n    ncl->upvals[i]->refcount++;\n    /* new closure is white, so we do not need a barrier here */\n  }\n  if (!isblack(p))  /* cache will not break GC invariant? */\n    p->cache = ncl;  /* save it on cache for reuse */\n}\n\n\n/*\n** finish execution of an opcode interrupted by an yield\n*/\nvoid luaV_finishOp (lua_State *L) {\n  CallInfo *ci = L->ci;\n  StkId base = ci->u.l.base;\n  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */\n  OpCode op = GET_OPCODE(inst);\n  switch (op) {  /* finish its execution */\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV:\n    case OP_BAND: case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR:\n    case OP_MOD: case OP_POW:\n    case OP_UNM: case OP_BNOT: case OP_LEN:\n    case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {\n      setobjs2s(L, base + GETARG_A(inst), --L->top);\n      break;\n    }\n    case OP_LE: case OP_LT: case OP_EQ: {\n      int res = !l_isfalse(L->top - 1);\n      L->top--;\n      if (ci->callstatus & CIST_LEQ) {  /* \"<=\" using \"<\" instead? */\n        lua_assert(op == OP_LE);\n        ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        res = !res;  /* negate result */\n      }\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);\n      if (res != GETARG_A(inst))  /* condition failed? */\n        ci->u.l.savedpc++;  /* skip jump instruction */\n      break;\n    }\n    case OP_CONCAT: {\n      StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */\n      int b = GETARG_B(inst);      /* first element to concatenate */\n      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */\n      setobj2s(L, top - 2, top);  /* put TM result in proper position */\n      if (total > 1) {  /* are there elements to concat? */\n        L->top = top - 1;  /* top is one after last element (at top-2) */\n        luaV_concat(L, total);  /* concat them (may yield again) */\n      }\n      /* move final result to final position */\n      setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);\n      L->top = ci->top;  /* restore top */\n      break;\n    }\n    case OP_TFORCALL: {\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);\n      L->top = ci->top;  /* correct top */\n      break;\n    }\n    case OP_CALL: {\n      if (GETARG_C(inst) - 1 >= 0)  /* nresults >= 0? */\n        L->top = ci->top;  /* adjust results */\n      break;\n    }\n    case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n\n\n/*\n** {==================================================================\n** Function 'luaV_execute': main interpreter loop\n** ===================================================================\n*/\n\n\n/*\n** some macros for common tasks in 'luaV_execute'\n*/\n\n\n#define RA(i)\t(base+GETARG_A(i))\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n\n\n/* execute a jump instruction */\n#define dojump(ci,i,e) \\\n  { int a = GETARG_A(i); \\\n    if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \\\n    ci->u.l.savedpc += GETARG_sBx(i) + e; }\n\n/* for test instructions, execute the jump instruction that follows it */\n#define donextjump(ci)\t{ i = *ci->u.l.savedpc; dojump(ci, i, 1); }\n\n\n#define Protect(x)\t{ {x;}; base = ci->u.l.base; }\n\n#define checkGC(L,c)  \\\n\t{ luaC_condGC(L, L->top = (c),  /* limit of live values */ \\\n                         Protect(L->top = ci->top));  /* restore top */ \\\n           luai_threadyield(L); }\n\n\n/* fetch an instruction and prepare its execution */\n#define vmfetch()\t{ \\\n  i = *(ci->u.l.savedpc++); \\\n  if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) \\\n    Protect(luaG_traceexec(L)); \\\n  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \\\n  lua_assert(base == ci->u.l.base); \\\n  lua_assert(base <= L->top && L->top < L->stack + L->stacksize); \\\n}\n\n#define vmdispatch(o)\tswitch(o)\n#define vmcase(l)\tcase l:\n#define vmbreak\t\tbreak\n\n\n/*\n** copy of 'luaV_gettable', but protecting the call to potential\n** metamethod (which can reallocate the stack)\n*/\n#define gettableProtected(L,t,k,v)  { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else Protect(luaV_finishget(L,t,k,v,slot)); }\n\n\n/* same for 'luaV_settable' */\n#define settableProtected(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    Protect(luaV_finishset(L,t,k,v,slot)); }\n\n\n\nvoid luaV_execute (lua_State *L) {\n  CallInfo *ci = L->ci;\n  LClosure *cl;\n  TValue *k;\n  StkId base;\n  ci->callstatus |= CIST_FRESH;  /* fresh invocation of 'luaV_execute\" */\n newframe:  /* reentry point when frame changes (call/return) */\n  lua_assert(ci == L->ci);\n  cl = clLvalue(ci->func);  /* local reference to function's closure */\n  k = cl->p->k;  /* local reference to function's constant table */\n  base = ci->u.l.base;  /* local copy of function's base */\n  /* main loop of interpreter */\n  for (;;) {\n    Instruction i;\n    StkId ra;\n    vmfetch();\n    vmdispatch (GET_OPCODE(i)) {\n      vmcase(OP_MOVE) {\n        setobjs2s(L, ra, RB(i));\n        vmbreak;\n      }\n      vmcase(OP_LOADK) {\n        TValue *rb = k + GETARG_Bx(i);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADKX) {\n        TValue *rb;\n        lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n        rb = k + GETARG_Ax(*ci->u.l.savedpc++);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADBOOL) {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) ci->u.l.savedpc++;  /* skip next instruction (if C) */\n        vmbreak;\n      }\n      vmcase(OP_LOADNIL) {\n        int b = GETARG_B(i);\n        do {\n          setnilvalue(ra++);\n        } while (b--);\n        vmbreak;\n      }\n      vmcase(OP_GETUPVAL) {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        vmbreak;\n      }\n      vmcase(OP_GETTABUP) {\n        TValue *upval = cl->upvals[GETARG_B(i)]->v;\n        TValue *rc = RKC(i);\n        gettableProtected(L, upval, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_GETTABLE) {\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        gettableProtected(L, rb, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_SETTABUP) {\n        TValue *upval = cl->upvals[GETARG_A(i)]->v;\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, upval, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_SETUPVAL) {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_upvalbarrier(L, uv);\n        vmbreak;\n      }\n      vmcase(OP_SETTABLE) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, ra, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_NEWTABLE) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Table *t = luaH_new(L);\n        sethvalue(L, ra, t);\n        if (b != 0 || c != 0)\n          luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_SELF) {\n        const TValue *aux;\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        setobjs2s(L, ra + 1, rb);\n        if (luaV_fastget(L, rb, key, aux, luaH_getstr)) {\n          setobj2s(L, ra, aux);\n        }\n        else Protect(luaV_finishget(L, rb, rc, ra, aux));\n        vmbreak;\n      }\n      vmcase(OP_ADD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(+, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numadd(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); }\n        vmbreak;\n      }\n      vmcase(OP_SUB) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(-, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numsub(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); }\n        vmbreak;\n      }\n      vmcase(OP_MUL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(*, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_nummul(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); }\n        vmbreak;\n      }\n      vmcase(OP_DIV) {  /* float division (always with floats) */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numdiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); }\n        vmbreak;\n      }\n      vmcase(OP_BAND) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(&, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); }\n        vmbreak;\n      }\n      vmcase(OP_BOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(|, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); }\n        vmbreak;\n      }\n      vmcase(OP_BXOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(^, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); }\n        vmbreak;\n      }\n      vmcase(OP_SHL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); }\n        vmbreak;\n      }\n      vmcase(OP_SHR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, -ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); }\n        vmbreak;\n      }\n      vmcase(OP_MOD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_mod(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          lua_Number m;\n          luai_nummod(L, nb, nc, m);\n          setfltvalue(ra, m);\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); }\n        vmbreak;\n      }\n      vmcase(OP_IDIV) {  /* floor division */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_div(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numidiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); }\n        vmbreak;\n      }\n      vmcase(OP_POW) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numpow(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); }\n        vmbreak;\n      }\n      vmcase(OP_UNM) {\n        TValue *rb = RB(i);\n        lua_Number nb;\n        if (ttisinteger(rb)) {\n          lua_Integer ib = ivalue(rb);\n          setivalue(ra, intop(-, 0, ib));\n        }\n        else if (tonumber(rb, &nb)) {\n          setfltvalue(ra, luai_numunm(L, nb));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));\n        }\n        vmbreak;\n      }\n      vmcase(OP_BNOT) {\n        TValue *rb = RB(i);\n        lua_Integer ib;\n        if (tointeger(rb, &ib)) {\n          setivalue(ra, intop(^, ~l_castS2U(0), ib));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));\n        }\n        vmbreak;\n      }\n      vmcase(OP_NOT) {\n        TValue *rb = RB(i);\n        int res = l_isfalse(rb);  /* next assignment may change this value */\n        setbvalue(ra, res);\n        vmbreak;\n      }\n      vmcase(OP_LEN) {\n        Protect(luaV_objlen(L, ra, RB(i)));\n        vmbreak;\n      }\n      vmcase(OP_CONCAT) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        StkId rb;\n        L->top = base + c + 1;  /* mark the end of concat operands */\n        Protect(luaV_concat(L, c - b + 1));\n        ra = RA(i);  /* 'luaV_concat' may invoke TMs and move the stack */\n        rb = base + b;\n        setobjs2s(L, ra, rb);\n        checkGC(L, (ra >= rb ? ra + 1 : rb));\n        L->top = ci->top;  /* restore top */\n        vmbreak;\n      }\n      vmcase(OP_JMP) {\n        dojump(ci, i, 0);\n        vmbreak;\n      }\n      vmcase(OP_EQ) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (luaV_equalobj(L, rb, rc) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LT) {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LE) {\n        Protect(\n          if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_TEST) {\n        if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))\n            ci->u.l.savedpc++;\n          else\n          donextjump(ci);\n        vmbreak;\n      }\n      vmcase(OP_TESTSET) {\n        TValue *rb = RB(i);\n        if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))\n          ci->u.l.savedpc++;\n        else {\n          setobjs2s(L, ra, rb);\n          donextjump(ci);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CALL) {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        if (luaD_precall(L, ra, nresults)) {  /* C function? */\n          if (nresults >= 0)\n            L->top = ci->top;  /* adjust results */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {  /* Lua function */\n          ci = L->ci;\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_TAILCALL) {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        if (luaD_precall(L, ra, LUA_MULTRET)) {  /* C function? */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {\n          /* tail call: put called frame (n) in place of caller one (o) */\n          CallInfo *nci = L->ci;  /* called frame */\n          CallInfo *oci = nci->previous;  /* caller frame */\n          StkId nfunc = nci->func;  /* called function */\n          StkId ofunc = oci->func;  /* caller function */\n          /* last stack slot filled by 'precall' */\n          StkId lim = nci->u.l.base + getproto(nfunc)->numparams;\n          int aux;\n          /* close all upvalues from previous call */\n          if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);\n          /* move new frame into old one */\n          for (aux = 0; nfunc + aux < lim; aux++)\n            setobjs2s(L, ofunc + aux, nfunc + aux);\n          oci->u.l.base = ofunc + (nci->u.l.base - nfunc);  /* correct base */\n          oci->top = L->top = ofunc + (L->top - nfunc);  /* correct top */\n          oci->u.l.savedpc = nci->u.l.savedpc;\n          oci->callstatus |= CIST_TAIL;  /* function was tail called */\n          ci = L->ci = oci;  /* remove new frame */\n          lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_RETURN) {\n        int b = GETARG_B(i);\n        if (cl->p->sizep > 0) luaF_close(L, base);\n        b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));\n        if (ci->callstatus & CIST_FRESH)  /* local 'ci' still from callee */\n          return;  /* external invocation: return */\n        else {  /* invocation via reentry: continue execution */\n          ci = L->ci;\n          if (b) L->top = ci->top;\n          lua_assert(isLua(ci));\n          lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n      }\n      vmcase(OP_FORLOOP) {\n        if (ttisinteger(ra)) {  /* integer loop? */\n          lua_Integer step = ivalue(ra + 2);\n          lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */\n          lua_Integer limit = ivalue(ra + 1);\n          if ((0 < step) ? (idx <= limit) : (limit <= idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgivalue(ra, idx);  /* update internal index... */\n            setivalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        else {  /* floating loop */\n          lua_Number step = fltvalue(ra + 2);\n          lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */\n          lua_Number limit = fltvalue(ra + 1);\n          if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                  : luai_numle(limit, idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgfltvalue(ra, idx);  /* update internal index... */\n            setfltvalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        vmbreak;\n      }\n      vmcase(OP_FORPREP) {\n        TValue *init = ra;\n        TValue *plimit = ra + 1;\n        TValue *pstep = ra + 2;\n        lua_Integer ilimit;\n        int stopnow;\n        if (ttisinteger(init) && ttisinteger(pstep) &&\n            forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {\n          /* all values are integer */\n          lua_Integer initv = (stopnow ? 0 : ivalue(init));\n          setivalue(plimit, ilimit);\n          setivalue(init, intop(-, initv, ivalue(pstep)));\n        }\n        else {  /* try making all values floats */\n          lua_Number ninit; lua_Number nlimit; lua_Number nstep;\n          if (!tonumber(plimit, &nlimit))\n            luaG_runerror(L, \"'for' limit must be a number\");\n          setfltvalue(plimit, nlimit);\n          if (!tonumber(pstep, &nstep))\n            luaG_runerror(L, \"'for' step must be a number\");\n          setfltvalue(pstep, nstep);\n          if (!tonumber(init, &ninit))\n            luaG_runerror(L, \"'for' initial value must be a number\");\n          setfltvalue(init, luai_numsub(L, ninit, nstep));\n        }\n        ci->u.l.savedpc += GETARG_sBx(i);\n        vmbreak;\n      }\n      vmcase(OP_TFORCALL) {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb + 3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = ci->top;\n        i = *(ci->u.l.savedpc++);  /* go to next instruction */\n        ra = RA(i);\n        lua_assert(GET_OPCODE(i) == OP_TFORLOOP);\n        goto l_tforloop;\n      }\n      vmcase(OP_TFORLOOP) {\n        l_tforloop:\n        if (!ttisnil(ra + 1)) {  /* continue loop? */\n          setobjs2s(L, ra, ra + 1);  /* save control variable */\n           ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETLIST) {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        unsigned int last;\n        Table *h;\n        if (n == 0) n = cast_int(L->top - ra) - 1;\n        if (c == 0) {\n          lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n          c = GETARG_Ax(*ci->u.l.savedpc++);\n        }\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* preallocate it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          luaH_setint(L, h, last--, val);\n          luaC_barrierback(L, h, val);\n        }\n        L->top = ci->top;  /* correct top (in case of previous open call) */\n        vmbreak;\n      }\n      vmcase(OP_CLOSURE) {\n        Proto *p = cl->p->p[GETARG_Bx(i)];\n        LClosure *ncl = getcached(p, cl->upvals, base);  /* cached closure */\n        if (ncl == NULL)  /* no match? */\n          pushclosure(L, p, cl->upvals, base, ra);  /* create a new one */\n        else\n          setclLvalue(L, ra, ncl);  /* push cashed closure */\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_VARARG) {\n        int b = GETARG_B(i) - 1;  /* required results */\n        int j;\n        int n = cast_int(base - ci->func) - cl->p->numparams - 1;\n        if (n < 0)  /* less arguments than parameters? */\n          n = 0;  /* no vararg arguments */\n        if (b < 0) {  /* B == 0? */\n          b = n;  /* get all var. arguments */\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          L->top = ra + n;\n        }\n        for (j = 0; j < b && j < n; j++)\n          setobjs2s(L, ra + j, base - n + j);\n        for (; j < b; j++)  /* complete required results with nil */\n          setnilvalue(ra + j);\n        vmbreak;\n      }\n      vmcase(OP_EXTRAARG) {\n        lua_assert(0);\n        vmbreak;\n      }\n    }\n  }\n}\n\n/* }================================================================== */\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.40 2016/01/05 16:07:21 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUA_NOCVTN2S)\n#define cvt2str(o)\tttisnumber(o)\n#else\n#define cvt2str(o)\t0\t/* no conversion from numbers to strings */\n#endif\n\n\n#if !defined(LUA_NOCVTS2N)\n#define cvt2num(o)\tttisstring(o)\n#else\n#define cvt2num(o)\t0\t/* no conversion from strings to numbers */\n#endif\n\n\n/*\n** You can define LUA_FLOORN2I if you want to convert floats to integers\n** by flooring them (instead of raising an error if they are not\n** integral values)\n*/\n#if !defined(LUA_FLOORN2I)\n#define LUA_FLOORN2I\t\t0\n#endif\n\n\n#define tonumber(o,n) \\\n\t(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))\n\n#define tointeger(o,i) \\\n    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n\n#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))\n\n#define luaV_rawequalobj(t1,t2)\t\tluaV_equalobj(NULL,t1,t2)\n\n\n/*\n** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,\n** return 1 with 'slot' pointing to 't[k]' (final result).  Otherwise,\n** return 0 (meaning it will have to check metamethod) with 'slot'\n** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).\n** 'f' is the raw get function to use.\n*/\n#define luaV_fastget(L,t,k,slot,f) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = f(hvalue(t), k),  /* else, do raw access */  \\\n      !ttisnil(slot)))  /* result not nil? */\n\n/*\n** standard implementation for 'gettable'\n*/\n#define luaV_gettable(L,t,k,v) { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else luaV_finishget(L,t,k,v,slot); }\n\n\n/*\n** Fast track for set table. If 't' is a table and 't[k]' is not nil,\n** call GC barrier, do a raw 't[k]=v', and return true; otherwise,\n** return false with 'slot' equal to NULL (if 't' is not a table) or\n** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro\n** returns true, there is no need to 'invalidateTMcache', because the\n** call is not creating a new entry.\n*/\n#define luaV_fastset(L,t,k,slot,f,v) \\\n  (!ttistable(t) \\\n   ? (slot = NULL, 0) \\\n   : (slot = f(hvalue(t), k), \\\n     ttisnil(slot) ? 0 \\\n     : (luaC_barrierback(L, hvalue(t), v), \\\n        setobj2t(L, cast(TValue *,slot), v), \\\n        1)))\n\n\n#define luaV_settable(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    luaV_finishset(L,t,k,v,slot); }\n  \n\n\nLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);\nLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);\nLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishOp (lua_State *L);\nLUAI_FUNC void luaV_execute (lua_State *L);\nLUAI_FUNC void luaV_concat (lua_State *L, int total);\nLUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);\nLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0)\n    return EOZ;\n  z->n = size - 1;  /* discount char being returned */\n  z->p = buff;\n  return cast_uchar(*(z->p++));\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (z->n == 0) {  /* no bytes in buffer? */\n      if (luaZ_fill(z) == EOZ)  /* try to read more */\n        return n;  /* no more input; return number of missing bytes */\n      else {\n        z->n++;  /* luaZ_fill consumed first byte; put it back */\n        z->p--;\n      }\n    }\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.3/src/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))\n\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_buffremove(buff,i)\t((buff)->n -= (i))\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \\\n\t\t\t\t(buff)->buffsize, size), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);\t/* read next n bytes */\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\t\t/* reader function */\n  void *data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.3/src/wmain.c",
    "content": "#include <windows.h>\n#include <stdlib.h> /* declaration of __argc and __argv */\n\nextern int main(int, char **);\n\nint PASCAL WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int ncmdshow)\n{\n  int rc;\n  \n  extern int __argc;     /* this seems to work for all the compilers we tested, except Watcom compilers */\n  extern char** __argv;\n  \n  rc = main(__argc, __argv);\n  \n  return rc;\n}\n"
  },
  {
    "path": "build/lua-5.3.4/Makefile",
    "content": "# Makefile for installing Lua\n# See doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\n# Where to install. The installation starts in the src and doc directories,\n# so take care if INSTALL_TOP is not an absolute path. See the local target.\n# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with\n# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.\nINSTALL_TOP= /usr/local\nINSTALL_BIN= $(INSTALL_TOP)/bin\nINSTALL_INC= $(INSTALL_TOP)/include\nINSTALL_LIB= $(INSTALL_TOP)/lib\nINSTALL_MAN= $(INSTALL_TOP)/man/man1\nINSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V\nINSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V\n\n# How to install. If your install program does not support \"-p\", then\n# you may have to run ranlib on the installed liblua.a.\nINSTALL= install -p\nINSTALL_EXEC= $(INSTALL) -m 0755\nINSTALL_DATA= $(INSTALL) -m 0644\n#\n# If you don't have \"install\" you can use \"cp\" instead.\n# INSTALL= cp -p\n# INSTALL_EXEC= $(INSTALL)\n# INSTALL_DATA= $(INSTALL)\n\n# Other utilities.\nMKDIR= mkdir -p\nRM= rm -f\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\n# Convenience platforms targets.\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\n# What to install.\nTO_BIN= lua luac\nTO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp\nTO_LIB= liblua.a\nTO_MAN= lua.1 luac.1\n\n# Lua version and release.\nV= 5.3\nR= $V.4\n\n# Targets start here.\nall:\t$(PLAT)\n\n$(PLATS) clean:\n\tcd src && $(MAKE) $@\n\ntest:\tdummy\n\tsrc/lua -v\n\ninstall: dummy\n\tcd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)\n\tcd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)\n\tcd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)\n\tcd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)\n\tcd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)\n\nuninstall:\n\tcd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)\n\tcd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)\n\tcd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)\n\tcd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)\n\nlocal:\n\t$(MAKE) install INSTALL_TOP=../install\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\t@echo \"See doc/readme.html for complete instructions.\"\n\n# make may get confused with test/ and install/\ndummy:\n\n# echo config parameters\necho:\n\t@cd src && $(MAKE) -s echo\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"V= $V\"\n\t@echo \"R= $R\"\n\t@echo \"TO_BIN= $(TO_BIN)\"\n\t@echo \"TO_INC= $(TO_INC)\"\n\t@echo \"TO_LIB= $(TO_LIB)\"\n\t@echo \"TO_MAN= $(TO_MAN)\"\n\t@echo \"INSTALL_TOP= $(INSTALL_TOP)\"\n\t@echo \"INSTALL_BIN= $(INSTALL_BIN)\"\n\t@echo \"INSTALL_INC= $(INSTALL_INC)\"\n\t@echo \"INSTALL_LIB= $(INSTALL_LIB)\"\n\t@echo \"INSTALL_MAN= $(INSTALL_MAN)\"\n\t@echo \"INSTALL_LMOD= $(INSTALL_LMOD)\"\n\t@echo \"INSTALL_CMOD= $(INSTALL_CMOD)\"\n\t@echo \"INSTALL_EXEC= $(INSTALL_EXEC)\"\n\t@echo \"INSTALL_DATA= $(INSTALL_DATA)\"\n\n# echo pkg-config data\npc:\n\t@echo \"version=$R\"\n\t@echo \"prefix=$(INSTALL_TOP)\"\n\t@echo \"libdir=$(INSTALL_LIB)\"\n\t@echo \"includedir=$(INSTALL_INC)\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.4/README",
    "content": "\nThis is Lua 5.3.4, released on 12 Jan 2017.\n\nFor installation instructions, license details, and\nfurther information about Lua, see doc/readme.html.\n\n"
  },
  {
    "path": "build/lua-5.3.4/doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"index.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nThe reference manual is the official definition of the Lua language.\n<BR>\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/pil/\">Programming in Lua</A>.\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2017 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<A HREF=\"http://www.lua.org/license.html\">Lua license</A>.\n</SMALL>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL CLASS=\"contents menubar\">\n<LI><A HREF=\"manual.html\">1 &ndash; Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 &ndash; Basic Concepts</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 &ndash; Values and Types</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 &ndash; Environments and the Global Environment</A>\n<LI><A HREF=\"manual.html#2.3\">2.3 &ndash; Error Handling</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 &ndash; Metatables and Metamethods</A>\n<LI><A HREF=\"manual.html#2.5\">2.5 &ndash; Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 &ndash; Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 &ndash; Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 &ndash; Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 &ndash; The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 &ndash; Lexical Conventions</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 &ndash; Variables</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 &ndash; Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#3.3.1\">3.3.1 &ndash; Blocks</A>\n<LI><A HREF=\"manual.html#3.3.2\">3.3.2 &ndash; Chunks</A>\n<LI><A HREF=\"manual.html#3.3.3\">3.3.3 &ndash; Assignment</A>\n<LI><A HREF=\"manual.html#3.3.4\">3.3.4 &ndash; Control Structures</A>\n<LI><A HREF=\"manual.html#3.3.5\">3.3.5 &ndash; For Statement</A>\n<LI><A HREF=\"manual.html#3.3.6\">3.3.6 &ndash; Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#3.3.7\">3.3.7 &ndash; Local Declarations</A>\n</UL>\n<LI><A HREF=\"manual.html#3.4\">3.4 &ndash; Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#3.4.1\">3.4.1 &ndash; Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#3.4.2\">3.4.2 &ndash; Bitwise Operators</A>\n<LI><A HREF=\"manual.html#3.4.3\">3.4.3 &ndash; Coercions and Conversions</A>\n<LI><A HREF=\"manual.html#3.4.4\">3.4.4 &ndash; Relational Operators</A>\n<LI><A HREF=\"manual.html#3.4.5\">3.4.5 &ndash; Logical Operators</A>\n<LI><A HREF=\"manual.html#3.4.6\">3.4.6 &ndash; Concatenation</A>\n<LI><A HREF=\"manual.html#3.4.7\">3.4.7 &ndash; The Length Operator</A>\n<LI><A HREF=\"manual.html#3.4.8\">3.4.8 &ndash; Precedence</A>\n<LI><A HREF=\"manual.html#3.4.9\">3.4.9 &ndash; Table Constructors</A>\n<LI><A HREF=\"manual.html#3.4.10\">3.4.10 &ndash; Function Calls</A>\n<LI><A HREF=\"manual.html#3.4.11\">3.4.11 &ndash; Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#3.5\">3.5 &ndash; Visibility Rules</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 &ndash; The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 &ndash; The Stack</A>\n<LI><A HREF=\"manual.html#4.2\">4.2 &ndash; Stack Size</A>\n<LI><A HREF=\"manual.html#4.3\">4.3 &ndash; Valid and Acceptable Indices</A>\n<LI><A HREF=\"manual.html#4.4\">4.4 &ndash; C Closures</A>\n<LI><A HREF=\"manual.html#4.5\">4.5 &ndash; Registry</A>\n<LI><A HREF=\"manual.html#4.6\">4.6 &ndash; Error Handling in C</A>\n<LI><A HREF=\"manual.html#4.7\">4.7 &ndash; Handling Yields in C</A>\n<LI><A HREF=\"manual.html#4.8\">4.8 &ndash; Functions and Types</A>\n<LI><A HREF=\"manual.html#4.9\">4.9 &ndash; The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 &ndash; The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 &ndash; Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 &ndash; Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#6.1\">6.1 &ndash; Basic Functions</A>\n<LI><A HREF=\"manual.html#6.2\">6.2 &ndash; Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#6.3\">6.3 &ndash; Modules</A>\n<LI><A HREF=\"manual.html#6.4\">6.4 &ndash; String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#6.4.1\">6.4.1 &ndash; Patterns</A>\n<LI><A HREF=\"manual.html#6.4.2\">6.4.2 &ndash; Format Strings for Pack and Unpack</A>\n</UL>\n<LI><A HREF=\"manual.html#6.5\">6.5 &ndash; UTF-8 Support</A>\n<LI><A HREF=\"manual.html#6.6\">6.6 &ndash; Table Manipulation</A>\n<LI><A HREF=\"manual.html#6.7\">6.7 &ndash; Mathematical Functions</A>\n<LI><A HREF=\"manual.html#6.8\">6.8 &ndash; Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#6.9\">6.9 &ndash; Operating System Facilities</A>\n<LI><A HREF=\"manual.html#6.10\">6.10 &ndash; The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#7\">7 &ndash; Lua Standalone</A>\n<P>\n<LI><A HREF=\"manual.html#8\">8 &ndash; Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#8.1\">8.1 &ndash; Changes in the Language</A>\n<LI><A HREF=\"manual.html#8.2\">8.2 &ndash; Changes in the Libraries</A>\n<LI><A HREF=\"manual.html#8.3\">8.3 &ndash; Changes in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#9\">9 &ndash; The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE CLASS=\"menubar\" WIDTH=\"100%\">\n<TR>\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<P>\n<A HREF=\"manual.html#6.1\">basic</A><BR>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawlen\">rawlen</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.2\">coroutine</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.isyieldable\">coroutine.isyieldable</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.10\">debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.getuservalue\">debug.getuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setuservalue\">debug.setuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvalueid\">debug.upvalueid</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvaluejoin\">debug.upvaluejoin</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.8\">io</A><BR>\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<P>\n<A HREF=\"manual.html#6.7\">math</A><BR>\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.maxinteger\">math.maxinteger</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.mininteger\">math.mininteger</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tointeger\">math.tointeger</A><BR>\n<A HREF=\"manual.html#pdf-math.type\">math.type</A><BR>\n<A HREF=\"manual.html#pdf-math.ult\">math.ult</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.9\">os</A><BR>\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.3\">package</A><BR>\n<A HREF=\"manual.html#pdf-package.config\">package.config</A><BR>\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.searchers\">package.searchers</A><BR>\n<A HREF=\"manual.html#pdf-package.searchpath\">package.searchpath</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.4\">string</A><BR>\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.pack\">string.pack</A><BR>\n<A HREF=\"manual.html#pdf-string.packsize\">string.packsize</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.unpack\">string.unpack</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.6\">table</A><BR>\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.move\">table.move</A><BR>\n<A HREF=\"manual.html#pdf-table.pack\">table.pack</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n<A HREF=\"manual.html#pdf-table.unpack\">table.unpack</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.5\">utf8</A><BR>\n<A HREF=\"manual.html#pdf-utf8.char\">utf8.char</A><BR>\n<A HREF=\"manual.html#pdf-utf8.charpattern\">utf8.charpattern</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codepoint\">utf8.codepoint</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codes\">utf8.codes</A><BR>\n<A HREF=\"manual.html#pdf-utf8.len\">utf8.len</A><BR>\n<A HREF=\"manual.html#pdf-utf8.offset\">utf8.offset</A><BR>\n\n<H3><A NAME=\"env\">environment<BR>variables</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_CPATH\">LUA_CPATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_CPATH_5_3\">LUA_CPATH_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT\">LUA_INIT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT_5_3\">LUA_INIT_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH\">LUA_PATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH_5_3\">LUA_PATH_5_3</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"api\">C API</A></H3>\n<P>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_KContext\">lua_KContext</A><BR>\n<A HREF=\"manual.html#lua_KFunction\">lua_KFunction</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Unsigned\">lua_Unsigned</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n\n<P>\n<A HREF=\"manual.html#lua_absindex\">lua_absindex</A><BR>\n<A HREF=\"manual.html#lua_arith\">lua_arith</A><BR>\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_callk\">lua_callk</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_compare\">lua_compare</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_copy\">lua_copy</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getextraspace\">lua_getextraspace</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_geti\">lua_geti</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_getuservalue\">lua_getuservalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_isinteger\">lua_isinteger</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_isyieldable\">lua_isyieldable</A><BR>\n<A HREF=\"manual.html#lua_len\">lua_len</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdata\">lua_newuserdata</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_numbertointeger\">lua_numbertointeger</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pcallk\">lua_pcallk</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushglobaltable\">lua_pushglobaltable</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawgetp\">lua_rawgetp</A><BR>\n<A HREF=\"manual.html#lua_rawlen\">lua_rawlen</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_rawsetp\">lua_rawsetp</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_rotate\">lua_rotate</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_seti\">lua_seti</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_setuservalue\">lua_setuservalue</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_stringtonumber\">lua_stringtonumber</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tointegerx\">lua_tointegerx</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_tonumberx\">lua_tonumberx</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueid\">lua_upvalueid</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_upvaluejoin\">lua_upvaluejoin</A><BR>\n<A HREF=\"manual.html#lua_version\">lua_version</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n<A HREF=\"manual.html#lua_yieldk\">lua_yieldk</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"auxlib\">auxiliary library</A></H3>\n<P>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<A HREF=\"manual.html#luaL_Stream\">luaL_Stream</A><BR>\n\n<P>\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_buffinitsize\">luaL_buffinitsize</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_checkversion\">luaL_checkversion</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_execresult\">luaL_execresult</A><BR>\n<A HREF=\"manual.html#luaL_fileresult\">luaL_fileresult</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_getsubtable\">luaL_getsubtable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_len\">luaL_len</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadbufferx\">luaL_loadbufferx</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadfilex\">luaL_loadfilex</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newlib\">luaL_newlib</A><BR>\n<A HREF=\"manual.html#luaL_newlibtable\">luaL_newlibtable</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_opt\">luaL_opt</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffsize\">luaL_prepbuffsize</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_pushresultsize\">luaL_pushresultsize</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_requiref\">luaL_requiref</A><BR>\n<A HREF=\"manual.html#luaL_setfuncs\">luaL_setfuncs</A><BR>\n<A HREF=\"manual.html#luaL_setmetatable\">luaL_setmetatable</A><BR>\n<A HREF=\"manual.html#luaL_testudata\">luaL_testudata</A><BR>\n<A HREF=\"manual.html#luaL_tolstring\">luaL_tolstring</A><BR>\n<A HREF=\"manual.html#luaL_traceback\">luaL_traceback</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n<H3><A NAME=\"library\">standard library</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-luaopen_base\">luaopen_base</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_coroutine\">luaopen_coroutine</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_debug\">luaopen_debug</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_io\">luaopen_io</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_math\">luaopen_math</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_os\">luaopen_os</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_package\">luaopen_package</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_string\">luaopen_string</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_table\">luaopen_table</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_utf8\">luaopen_utf8</A><BR>\n\n<H3><A NAME=\"constants\">constants</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_ERRERR\">LUA_ERRERR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRFILE\">LUA_ERRFILE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRGCMM\">LUA_ERRGCMM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRMEM\">LUA_ERRMEM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRRUN\">LUA_ERRRUN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRSYNTAX\">LUA_ERRSYNTAX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCALL\">LUA_HOOKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCOUNT\">LUA_HOOKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKLINE\">LUA_HOOKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKRET\">LUA_HOOKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKTAILCALL\">LUA_HOOKTAILCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCALL\">LUA_MASKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCOUNT\">LUA_MASKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKLINE\">LUA_MASKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKRET\">LUA_MASKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MAXINTEGER\">LUA_MAXINTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MININTEGER\">LUA_MININTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MINSTACK\">LUA_MINSTACK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MULTRET\">LUA_MULTRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_NOREF\">LUA_NOREF</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OK\">LUA_OK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPADD\">LUA_OPADD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBAND\">LUA_OPBAND</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBNOT\">LUA_OPBNOT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBOR\">LUA_OPBOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBXOR\">LUA_OPBXOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPDIV\">LUA_OPDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPEQ\">LUA_OPEQ</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPIDIV\">LUA_OPIDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLE\">LUA_OPLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLT\">LUA_OPLT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMOD\">LUA_OPMOD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMUL\">LUA_OPMUL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPPOW\">LUA_OPPOW</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHL\">LUA_OPSHL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHR\">LUA_OPSHR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSUB\">LUA_OPSUB</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPUNM\">LUA_OPUNM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REFNIL\">LUA_REFNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REGISTRYINDEX\">LUA_REGISTRYINDEX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_GLOBALS\">LUA_RIDX_GLOBALS</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_MAINTHREAD\">LUA_RIDX_MAINTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TBOOLEAN\">LUA_TBOOLEAN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TFUNCTION\">LUA_TFUNCTION</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TLIGHTUSERDATA\">LUA_TLIGHTUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNIL\">LUA_TNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNONE\">LUA_TNONE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNUMBER\">LUA_TNUMBER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TSTRING\">LUA_TSTRING</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTABLE\">LUA_TTABLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTHREAD\">LUA_TTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TUSERDATA\">LUA_TUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_USE_APICHECK\">LUA_USE_APICHECK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_YIELD\">LUA_YIELD</A><BR>\n<A HREF=\"manual.html#pdf-LUAL_BUFFERSIZE\">LUAL_BUFFERSIZE</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n\n<P CLASS=\"footer\">\nLast update:\nThu Dec 22 18:29:39 BRST 2016\n</P>\n<!--\nLast change: revised for Lua 5.3.4\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.4/doc/index.css",
    "content": "ul {\n\tlist-style-type: none ;\n}\n\nul.contents {\n\tpadding: 0 ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\ttext-align: left ;\n\tline-height: 1.25 ;\n\twidth: 15% ;\n}\n"
  },
  {
    "path": "build/lua-5.3.4/doc/lua.1",
    "content": ".\\\" $Id: lua.man,v 1.14 2016/10/17 15:43:50 lhf Exp $\n.TH LUA 1 \"$Date: 2016/10/17 15:43:50 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the standalone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nThe given\n.I options\nare handled in order and then\nthe Lua program in file\n.I script\nis loaded and executed.\nThe given\n.I args\nare available to\n.I script\nas strings in a global table named\n.BR arg .\nIf no options or arguments are given,\nthen\n.B \"\\-v \\-i\"\nis assumed when the standard input is a terminal;\notherwise,\n.B \"\\-\"\nis assumed.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf the line contains an expression or list of expressions,\nthen the line is evaluated and the results are printed.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\n.LP\nAt the very start,\nbefore even handling the command line,\n.B lua\nchecks the contents of the environment variables\n.B LUA_INIT_5_3\nor\n.BR LUA_INIT ,\nin that order.\nIf the contents is of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n.SH OPTIONS\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\n.TP\n.B \\-i\nenter interactive mode after executing\n.IR script .\n.TP\n.BI \\-l \" name\"\nexecute the equivalent of\n.IB name =require(' name ')\nbefore executing\n.IR script .\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-E\nignore environment variables.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and execute the standard input as a file.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nThe documentation at lua.org,\nespecially section 7 of the reference manual.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.4/doc/lua.css",
    "content": "html {\n\tbackground-color: #F8F8F8 ;\n}\n\nbody {\n\tbackground-color: #FFFFFF ;\n\tcolor: #000000 ;\n\tfont-family: Helvetica, Arial, sans-serif ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n\tmargin: 16px auto ;\n\tpadding: 32px ;\n\tborder: solid #a0a0a0 1px ;\n\tborder-radius: 20px ;\n\tmax-width: 70em ;\n\twidth: 90% ;\n}\n\nh1, h2, h3, h4 {\n\tcolor: #000080 ;\n\tfont-family: Verdana, Geneva, sans-serif ;\n\tfont-weight: normal ;\n\tfont-style: normal ;\n\ttext-align: left ;\n}\n\nh1 {\n\tfont-size: 28pt ;\n}\n\nh1 img {\n\tvertical-align: text-bottom ;\n}\n\nh2:before {\n\tcontent: \"\\2756\" ;\n\tpadding-right: 0.5em ;\n}\n\na {\n\ttext-decoration: none ;\n}\n\na:link {\n\tcolor: #000080 ;\n}\n\na:link:hover, a:visited:hover {\n\tbackground-color: #D0D0FF ;\n\tcolor: #000080 ;\n\tborder-radius: 4px ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\ndiv.menubar {\n\tpadding-bottom: 0.5em ;\n}\n\np.menubar {\n\tmargin-left: 2.5em ;\n}\n\n.menubar a:hover  {\n\tmargin: -3px -3px -3px -3px ;\n\tpadding: 3px  3px  3px  3px ;\n\tborder-radius: 4px ;\n}\n\n:target {\n\tbackground-color: #F0F0F0 ;\n\tmargin: -8px ;\n\tpadding: 8px ;\n\tborder-radius: 8px ;\n\toutline: none ;\n}\n\nhr {\n\tdisplay: none ;\n}\n\ntable hr {\n\tbackground-color: #a0a0a0 ;\n\tcolor: #a0a0a0 ;\n\tborder: 0 ;\n\theight: 1px ;\n\tdisplay: block ;\n}\n\n.footer {\n\tcolor: gray ;\n\tfont-size: x-small ;\n\ttext-transform: lowercase ;\n}\n\ninput[type=text] {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 2em ;\n\tbackground-image: url('images/search.png') ;\n\tbackground-repeat: no-repeat ;\n\tbackground-position: 4px center ;\n\tpadding-left: 20px ;\n\theight: 2em ;\n}\n\npre.session {\n\tbackground-color: #F8F8F8 ;\n\tpadding: 1em ;\n\tborder-radius: 8px ;\n}\n\ntd.gutter {\n\twidth: 4% ;\n}\n\ntable.columns {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntable.columns td {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\tpadding-bottom: 1em ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n}\n\np.logos a:link:hover, p.logos a:visited:hover {\n\tbackground-color: inherit ;\n}\n\ntable.book {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntable.book td {\n\tpadding: 0 ;\n\tvertical-align: top ;\n}\n\ntable.book td.cover {\n\tpadding-right: 1em ;\n}\n\ntable.book img {\n\tborder: solid #000080 1px ;\n}\n\ntable.book span {\n\tfont-size: small ;\n\ttext-align: left ;\n\tdisplay: block ;\n\tmargin-top: 0.25em ;\n}\n\nimg {\n\tbackground-color: white ;\n}\n"
  },
  {
    "path": "build/lua-5.3.4/doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $\n.TH LUAC 1 \"$Date: 2011/11/16 13:53:40 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files containing precompiled chunks\nthat can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\n.B luac\nproduces a single output file containing the combined bytecodes\nfor all files given.\nExecuting the combined file is equivalent to executing the given files.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nPrecompiled chunks are\n.I not\nportable across different architectures.\nMoreover,\nthe internal format of precompiled chunks\nis likely to change when a new version of Lua is released.\nMake sure you save the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\nUse\n.B \\-l \\-l\nfor a full listing.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be one of the given files because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file loads without errors.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nIn particular,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and process standard input.\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nThe documentation at lua.org.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.4/doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n\tfont-size: inherit ;\n}\n\npre, code {\n\tfont-size: 12pt ;\n}\n\nspan.apii {\n\tcolor: gray ;\n\tfloat: right ;\n\tfont-family: inherit ;\n\tfont-style: normal ;\n\tfont-size: small ;\n}\n\nh2:before {\n\tcontent: \"\" ;\n\tpadding-right: 0em ;\n}\n"
  },
  {
    "path": "build/lua-5.3.4/doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2017 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html\">Lua license</a>.\n</SMALL>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"contents.html#contents\">contents</A>\n&middot;\n<A HREF=\"contents.html#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of,v 1.167 2017/01/09 15:18:11 roberto Exp $ -->\n\n\n\n\n<h1>1 &ndash; <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is a powerful, efficient, lightweight, embeddable scripting language.\nIt supports procedural programming,\nobject-oriented programming, functional programming,\ndata-driven programming, and data description.\n\n\n<p>\nLua combines simple procedural syntax with powerful data description\nconstructs based on associative arrays and extensible semantics.\nLua is dynamically typed,\nruns by interpreting bytecode with a register-based\nvirtual machine,\nand has automatic memory management with\nincremental garbage collection,\nmaking it ideal for configuration, scripting,\nand rapid prototyping.\n\n\n<p>\nLua is implemented as a library, written in <em>clean C</em>,\nthe common subset of Standard&nbsp;C and C++.\nThe Lua distribution includes a host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete,\nstandalone Lua interpreter,\nfor interactive or batch use.\nLua is intended to be used both as a powerful, lightweight,\nembeddable scripting language for any program that needs one,\nand as a powerful but lightweight and efficient stand-alone language.\n\n\n<p>\nAs an extension language, Lua has no notion of a \"main\" program:\nit works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\n(Frequently, this host is the stand-alone <code>lua</code> program.)\nThe host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua</em>.\n\n\n\n<h1>2 &ndash; <a name=\"2\">Basic Concepts</a></h1>\n\n<p>\nThis section describes the basic concepts of the language.\n\n\n\n<h2>2.1 &ndash; <a name=\"2.1\">Values and Types</a></h2>\n\n<p>\nLua is a <em>dynamically typed language</em>.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are <em>first-class values</em>.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\nThe type <em>nil</em> has one single value, <b>nil</b>,\nwhose main property is to be different from any other value;\nit usually represents the absence of a useful value.\nThe type <em>boolean</em> has two values, <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nany other value makes it true.\nThe type <em>number</em> represents both\ninteger numbers and real (floating-point) numbers.\nThe type <em>string</em> represents immutable sequences of bytes.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit value,\nincluding embedded zeros ('<code>\\0</code>').\nLua is also encoding-agnostic;\nit makes no assumptions about the contents of a string.\n\n\n<p>\nThe type <em>number</em> uses two internal representations,\nor two subtypes,\none called <em>integer</em> and the other called <em>float</em>.\nLua has explicit rules about when each representation is used,\nbut it also converts between them automatically as needed (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\nTherefore,\nthe programmer may choose to mostly ignore the difference\nbetween integers and floats\nor to assume complete control over the representation of each number.\nStandard Lua uses 64-bit integers and double-precision (64-bit) floats,\nbut you can also compile Lua so that it\nuses 32-bit integers and/or single-precision (32-bit) floats.\nThe option with 32 bits for both integers and floats\nis particularly attractive\nfor small machines and embedded systems.\n(See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C (see <a href=\"#3.4.10\">&sect;3.4.10</a>).\nBoth are represented by the type <em>function</em>.\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nA userdata value represents a block of raw memory.\nThere are two kinds of userdata:\n<em>full userdata</em>,\nwhich is an object with a block of memory managed by Lua,\nand <em>light userdata</em>,\nwhich is simply a C&nbsp;pointer value.\nUserdata has no predefined operations in Lua,\nexcept assignment and identity test.\nBy using <em>metatables</em>,\nthe programmer can define operations for full userdata values\n(see <a href=\"#2.4\">&sect;2.4</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by the host program.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.6\">&sect;2.6</a>).\nLua threads are not related to operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads natively.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can be indexed not only with numbers,\nbut with any Lua value except <b>nil</b> and NaN.\n(<em>Not a Number</em> is a special value used to represent\nundefined or unrepresentable numerical results, such as <code>0/0</code>.)\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nAny key with value <b>nil</b> is not considered part of the table.\nConversely, any key that is not part of a table has\nan associated value <b>nil</b>.\n\n\n<p>\nTables are the sole data-structuring mechanism in Lua;\nthey can be used to represent ordinary arrays, lists,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#3.4.9\">&sect;3.4.9</a>).\n\n\n<p>\nLike indices,\nthe values of table fields can be of any type.\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#3.4.11\">&sect;3.4.11</a>).\n\n\n<p>\nThe indexing of tables follows\nthe definition of raw equality in the language.\nThe expressions <code>a[i]</code> and <code>a[j]</code>\ndenote the same table element\nif and only if <code>i</code> and <code>j</code> are raw equal\n(that is, equal without metamethods).\nIn particular, floats with integral values\nare equal to their respective integers\n(e.g., <code>1.0 == 1</code>).\nTo avoid ambiguities,\nany float with integral value used as a key\nis converted to its respective integer.\nFor instance, if you write <code>a[2.0] = true</code>,\nthe actual key inserted into the table will be the\ninteger <code>2</code>.\n(On the other hand,\n2 and \"<code>2</code>\" are different Lua values and therefore\ndenote different table entries.)\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value (see <a href=\"#6.1\">&sect;6.1</a>).\n\n\n\n\n\n<h2>2.2 &ndash; <a name=\"2.2\">Environments and the Global Environment</a></h2>\n\n<p>\nAs will be discussed in <a href=\"#3.2\">&sect;3.2</a> and <a href=\"#3.3.3\">&sect;3.3.3</a>,\nany reference to a free name\n(that is, a name not bound to any declaration) <code>var</code>\nis syntactically translated to <code>_ENV.var</code>.\nMoreover, every chunk is compiled in the scope of\nan external local variable named <code>_ENV</code> (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nso <code>_ENV</code> itself is never a free name in a chunk.\n\n\n<p>\nDespite the existence of this external <code>_ENV</code> variable and\nthe translation of free names,\n<code>_ENV</code> is a completely regular name.\nIn particular,\nyou can define new variables and parameters with that name.\nEach reference to a free name uses the <code>_ENV</code> that is\nvisible at that point in the program,\nfollowing the usual visibility rules of Lua (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nAny table used as the value of <code>_ENV</code> is called an <em>environment</em>.\n\n\n<p>\nLua keeps a distinguished environment called the <em>global environment</em>.\nThis value is kept at a special index in the C registry (see <a href=\"#4.5\">&sect;4.5</a>).\nIn Lua, the global variable <a href=\"#pdf-_G\"><code>_G</code></a> is initialized with this same value.\n(<a href=\"#pdf-_G\"><code>_G</code></a> is never used internally.)\n\n\n<p>\nWhen Lua loads a chunk,\nthe default value for its <code>_ENV</code> upvalue\nis the global environment (see <a href=\"#pdf-load\"><code>load</code></a>).\nTherefore, by default,\nfree names in Lua code refer to entries in the global environment\n(and, therefore, they are also called <em>global variables</em>).\nMoreover, all standard libraries are loaded in the global environment\nand some functions there operate on that environment.\nYou can use <a href=\"#pdf-load\"><code>load</code></a> (or <a href=\"#pdf-loadfile\"><code>loadfile</code></a>)\nto load a chunk with a different environment.\n(In C, you have to load the chunk and then change the value\nof its first upvalue.)\n\n\n\n\n\n<h2>2.3 &ndash; <a name=\"2.3\">Error Handling</a></h2>\n\n<p>\nBecause Lua is an embedded extension language,\nall Lua actions start from C&nbsp;code in the host program\ncalling a function from the Lua library.\n(When you use Lua standalone,\nthe <code>lua</code> application is the host program.)\nWhenever an error occurs during\nthe compilation or execution of a Lua chunk,\ncontrol returns to the host,\nwhich can take appropriate measures\n(such as printing an error message).\n\n\n<p>\nLua code can explicitly generate an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\nIf you need to catch errors in Lua,\nyou can use <a href=\"#pdf-pcall\"><code>pcall</code></a> or <a href=\"#pdf-xpcall\"><code>xpcall</code></a>\nto call a given function in <em>protected mode</em>.\n\n\n<p>\nWhenever there is an error,\nan <em>error object</em> (also called an <em>error message</em>)\nis propagated with information about the error.\nLua itself only generates errors whose error object is a string,\nbut programs may generate errors with\nany value as the error object.\nIt is up to the Lua program or its host to handle such error objects.\n\n\n<p>\nWhen you use <a href=\"#pdf-xpcall\"><code>xpcall</code></a> or <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nyou may give a <em>message handler</em>\nto be called in case of errors.\nThis function is called with the original error object\nand returns a new error object.\nIt is called before the error unwinds the stack,\nso that it can gather more information about the error,\nfor instance by inspecting the stack and creating a stack traceback.\nThis message handler is still protected by the protected call;\nso, an error inside the message handler\nwill call the message handler again.\nIf this loop goes on for too long,\nLua breaks it and returns an appropriate message.\n(The message handler is called only for regular runtime errors.\nIt is not called for memory-allocation errors\nnor for errors while running finalizers.)\n\n\n\n\n\n<h2>2.4 &ndash; <a name=\"2.4\">Metatables and Metamethods</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain special operations.\nYou can change several aspects of the behavior\nof operations over a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field \"<code>__add</code>\" of the value's metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nThe key for each event in a metatable is a string\nwith the event name prefixed by two underscores;\nthe corresponding values are called <em>metamethods</em>.\nIn the previous example, the key is \"<code>__add</code>\"\nand the metamethod is the function that performs the addition.\n\n\n<p>\nYou can query the metatable of any value\nusing the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\nLua queries metamethods in metatables using a raw access (see <a href=\"#pdf-rawget\"><code>rawget</code></a>).\nSo, to retrieve the metamethod for event <code>ev</code> in object <code>o</code>,\nLua does the equivalent to the following code:\n\n<pre>\n     rawget(getmetatable(<em>o</em>) or {}, \"__<em>ev</em>\")\n</pre>\n\n<p>\nYou can replace the metatable of tables\nusing the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a> function.\nYou cannot change the metatable of other types from Lua code\n(except by using the debug library (<a href=\"#6.10\">&sect;6.10</a>));\nyou should use the C&nbsp;API for that.\n\n\n<p>\nTables and full userdata have individual metatables\n(although multiple tables and userdata can share their metatables).\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\nBy default, a value has no metatable,\nbut the string library sets a metatable for the string type (see <a href=\"#6.4\">&sect;6.4</a>).\n\n\n<p>\nA metatable controls how an object behaves in\narithmetic operations, bitwise operations,\norder comparisons, concatenation, length operation, calls, and indexing.\nA metatable also can define a function to be called\nwhen a userdata or a table is garbage collected (<a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nFor the unary operators (negation, length, and bitwise NOT),\nthe metamethod is computed and called with a dummy second operand,\nequal to the first one.\nThis extra operand is only to simplify Lua's internals\n(by making these operators behave like a binary operation)\nand may be removed in future versions.\n(For most uses this extra operand is irrelevant.)\n\n\n<p>\nA detailed list of events controlled by metatables is given next.\nEach operation is identified by its corresponding key.\n\n\n\n<ul>\n\n<li><b><code>__add</code>: </b>\nthe addition (<code>+</code>) operation.\nIf any operand for an addition is not a number\n(nor a string coercible to a number),\nLua will try to call a metamethod.\nFirst, Lua will check the first operand (even if it is valid).\nIf that operand does not define a metamethod for <code>__add</code>,\nthen Lua will check the second operand.\nIf Lua can find a metamethod,\nit calls the metamethod with the two operands as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nOtherwise,\nit raises an error.\n</li>\n\n<li><b><code>__sub</code>: </b>\nthe subtraction (<code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mul</code>: </b>\nthe multiplication (<code>*</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__div</code>: </b>\nthe division (<code>/</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mod</code>: </b>\nthe modulo (<code>%</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__pow</code>: </b>\nthe exponentiation (<code>^</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__unm</code>: </b>\nthe negation (unary <code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__idiv</code>: </b>\nthe floor division (<code>//</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__band</code>: </b>\nthe bitwise AND (<code>&amp;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither an integer\nnor a value coercible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\n</li>\n\n<li><b><code>__bor</code>: </b>\nthe bitwise OR (<code>|</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bxor</code>: </b>\nthe bitwise exclusive OR (binary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bnot</code>: </b>\nthe bitwise NOT (unary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shl</code>: </b>\nthe bitwise left shift (<code>&lt;&lt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shr</code>: </b>\nthe bitwise right shift (<code>&gt;&gt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__concat</code>: </b>\nthe concatenation (<code>..</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither a string nor a number\n(which is always coercible to a string).\n</li>\n\n<li><b><code>__len</code>: </b>\nthe length (<code>#</code>) operation.\nIf the object is not a string,\nLua will try its metamethod.\nIf there is a metamethod,\nLua calls it with the object as argument,\nand the result of the call\n(always adjusted to one value)\nis the result of the operation.\nIf there is no metamethod but the object is a table,\nthen Lua uses the table length operation (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nOtherwise, Lua raises an error.\n</li>\n\n<li><b><code>__eq</code>: </b>\nthe equal (<code>==</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are either both tables or both full userdata\nand they are not primitively equal.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__lt</code>: </b>\nthe less than (<code>&lt;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are neither both numbers nor both strings.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__le</code>: </b>\nthe less equal (<code>&lt;=</code>) operation.\nUnlike other operations,\nthe less-equal operation can use two different events.\nFirst, Lua looks for the <code>__le</code> metamethod in both operands,\nlike in the less than operation.\nIf it cannot find such a metamethod,\nthen it will try the <code>__lt</code> metamethod,\nassuming that <code>a &lt;= b</code> is equivalent to <code>not (b &lt; a)</code>.\nAs with the other comparison operators,\nthe result is always a boolean.\n(This use of the <code>__lt</code> event can be removed in future versions;\nit is also slower than a real <code>__le</code> metamethod.)\n</li>\n\n<li><b><code>__index</code>: </b>\nThe indexing access <code>table[key]</code>.\nThis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nDespite the name,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code> and <code>key</code> as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nIf it is a table,\nthe final result is the result of indexing this table with <code>key</code>.\n(This indexing is regular, not raw,\nand therefore can trigger another metamethod.)\n</li>\n\n<li><b><code>__newindex</code>: </b>\nThe indexing assignment <code>table[key] = value</code>.\nLike the index event,\nthis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nLike with indexing,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.\nIf it is a table,\nLua does an indexing assignment to this table with the same key and value.\n(This assignment is regular, not raw,\nand therefore can trigger another metamethod.)\n\n\n<p>\nWhenever there is a <code>__newindex</code> metamethod,\nLua does not perform the primitive assignment.\n(If necessary,\nthe metamethod itself can call <a href=\"#pdf-rawset\"><code>rawset</code></a>\nto do the assignment.)\n</li>\n\n<li><b><code>__call</code>: </b>\nThe call operation <code>func(args)</code>.\nThis event happens when Lua tries to call a non-function value\n(that is, <code>func</code> is not a function).\nThe metamethod is looked up in <code>func</code>.\nIf present,\nthe metamethod is called with <code>func</code> as its first argument,\nfollowed by the arguments of the original call (<code>args</code>).\nAll results of the call\nare the result of the operation.\n(This is the only metamethod that allows multiple results.)\n</li>\n\n</ul>\n\n<p>\nIt is a good practice to add all needed metamethods to a table\nbefore setting it as a metatable of some object.\nIn particular, the <code>__gc</code> metamethod works only when this order\nis followed (see <a href=\"#2.5.1\">&sect;2.5.1</a>).\n\n\n<p>\nBecause metatables are regular tables,\nthey can contain arbitrary fields,\nnot only the event names defined above.\nSome functions in the standard library\n(e.g., <a href=\"#pdf-tostring\"><code>tostring</code></a>)\nuse other fields in metatables for their own purposes.\n\n\n\n\n\n<h2>2.5 &ndash; <a name=\"2.5\">Garbage Collection</a></h2>\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou do not have to worry about allocating memory for new objects\nor freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> to collect all <em>dead objects</em>\n(that is, objects that are no longer accessible from Lua).\nAll memory used by Lua is subject to automatic management:\nstrings, tables, userdata, functions, threads, internal structures, etc.\n\n\n<p>\nLua implements an incremental mark-and-sweep collector.\nIt uses two numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em> and\nthe <em>garbage-collector step multiplier</em>.\nBoth use percentage points as units\n(e.g., a value of 100 means an internal value of 1).\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nLarger values make the collector less aggressive.\nValues smaller than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\n\n\n<p>\nThe garbage-collector step multiplier\ncontrols the relative speed of the collector relative to\nmemory allocation.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nYou should not use values smaller than 100,\nbecause they make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default is 200,\nwhich means that the collector runs at \"twice\"\nthe speed of memory allocation.\n\n\n<p>\nIf you set the step multiplier to a very large number\n(larger than 10% of the maximum number of\nbytes that the program may use),\nthe collector behaves like a stop-the-world collector.\nIf you then set the pause to 200,\nthe collector behaves as in old Lua versions,\ndoing a complete collection every time Lua doubles its\nmemory usage.\n\n\n<p>\nYou can change these numbers by calling <a href=\"#lua_gc\"><code>lua_gc</code></a> in C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nYou can also use these functions to control\nthe collector directly (e.g., stop and restart it).\n\n\n\n<h3>2.5.1 &ndash; <a name=\"2.5.1\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nYou can set garbage-collector metamethods for tables\nand, using the C&nbsp;API,\nfor full userdata (see <a href=\"#2.4\">&sect;2.4</a>).\nThese metamethods are also called <em>finalizers</em>.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management\n(such as closing files, network or database connections,\nor freeing your own memory).\n\n\n<p>\nFor an object (table or userdata) to be finalized when collected,\nyou must <em>mark</em> it for finalization.\n\nYou mark an object for finalization when you set its metatable\nand the metatable has a field indexed by the string \"<code>__gc</code>\".\nNote that if you set a metatable without a <code>__gc</code> field\nand later create that field in the metatable,\nthe object will not be marked for finalization.\n\n\n<p>\nWhen a marked object becomes garbage,\nit is not collected immediately by the garbage collector.\nInstead, Lua puts it in a list.\nAfter the collection,\nLua goes through that list.\nFor each object in the list,\nit checks the object's <code>__gc</code> metamethod:\nIf it is a function,\nLua calls it with the object as its single argument;\nif the metamethod is not a function,\nLua simply ignores it.\n\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers for objects are called in\nthe reverse order that the objects were marked for finalization,\namong those collected in that cycle;\nthat is, the first finalizer to be called is the one associated\nwith the object marked last in the program.\nThe execution of each finalizer may occur at any point during\nthe execution of the regular code.\n\n\n<p>\nBecause the object being collected must still be used by the finalizer,\nthat object (and other objects accessible only through it)\nmust be <em>resurrected</em> by Lua.\nUsually, this resurrection is transient,\nand the object memory is freed in the next garbage-collection cycle.\nHowever, if the finalizer stores the object in some global place\n(e.g., a global variable),\nthen the resurrection is permanent.\nMoreover, if the finalizer marks a finalizing object for finalization again,\nits finalizer will be called again in the next cycle where the\nobject is unreachable.\nIn any case,\nthe object memory is freed only in a GC cycle where\nthe object is unreachable and not marked for finalization.\n\n\n<p>\nWhen you close a state (see <a href=\"#lua_close\"><code>lua_close</code></a>),\nLua calls the finalizers of all objects marked for finalization,\nfollowing the reverse order that they were marked.\nIf any finalizer marks objects for collection during that phase,\nthese marks have no effect.\n\n\n\n\n\n<h3>2.5.2 &ndash; <a name=\"2.5.2\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect that object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak values allows the collection of its values,\nbut prevents the collection of its keys.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nIf the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',\nthe keys in the table are weak.\nIf <code>__mode</code> contains '<code>v</code>',\nthe values in the table are weak.\n\n\n<p>\nA table with weak keys and strong values\nis also called an <em>ephemeron table</em>.\nIn an ephemeron table,\na value is considered reachable only if its key is reachable.\nIn particular,\nif the only reference to a key comes through its value,\nthe pair is removed.\n\n\n<p>\nAny change in the weakness of a table may take effect only\nat the next collect cycle.\nIn particular, if you change the weakness to a stronger mode,\nLua may still collect some items from that table\nbefore the change takes effect.\n\n\n<p>\nOnly objects that have an explicit construction\nare removed from weak tables.\nValues, such as numbers and light C&nbsp;functions,\nare not subject to garbage collection,\nand therefore are not removed from weak tables\n(unless their associated values are collected).\nAlthough strings are subject to garbage collection,\nthey do not have an explicit construction,\nand therefore are not removed from weak tables.\n\n\n<p>\nResurrected objects\n(that is, objects being finalized\nand objects accessible only through objects being finalized)\nhave a special behavior in weak tables.\nThey are removed from weak values before running their finalizers,\nbut are removed from weak keys only in the next collection\nafter running their finalizers, when such objects are actually freed.\nThis behavior allows the finalizer to access properties\nassociated with the object through weak tables.\n\n\n<p>\nIf a weak table is among the resurrected objects in a collection cycle,\nit may not be properly cleared until the next cycle.\n\n\n\n\n\n\n\n<h2>2.6 &ndash; <a name=\"2.6\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine by calling <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine.\n\n\n<p>\nYou execute a coroutine by calling <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution by\ncalling its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed\nas arguments to that function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn case of normal termination,\n<a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus an error object.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> does not catch errors;\nany error is propagated to the caller.\n\n\n<p>\nAs an example of how coroutines work,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n     \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n<p>\nYou can also create and manipulate coroutines through the C API:\nsee functions <a href=\"#lua_newthread\"><code>lua_newthread</code></a>, <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nand <a href=\"#lua_yield\"><code>lua_yield</code></a>.\n\n\n\n\n\n<h1>3 &ndash; <a name=\"3\">The Language</a></h1>\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nLanguage constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.\nThe complete syntax of Lua can be found in <a href=\"#9\">&sect;9</a>\nat the end of this manual.\n\n\n\n<h2>3.1 &ndash; <a name=\"3.1\">Lexical Conventions</a></h2>\n\n<p>\nLua is a free-form language.\nIt ignores spaces (including new lines) and comments\nbetween lexical elements (tokens),\nexcept as delimiters between names and keywords.\n\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of letters,\ndigits, and underscores,\nnot beginning with a digit and\nnot being a reserved word.\nIdentifiers are used to name variables, table fields, and labels.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif    end\n     false     for       function  goto      if        in\n     local     nil       not       or        repeat    return\n     then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention,\nprograms should avoid creating\nnames that start with an underscore followed by\none or more uppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>).\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     &amp;     ~     |     &lt;&lt;    &gt;&gt;    //\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]     ::\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\nA <em>short literal string</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nA backslash followed by a line break\nresults in a newline in the string.\nThe escape sequence '<code>\\z</code>' skips the following span\nof white-space characters,\nincluding line breaks;\nit is particularly useful to break and indent a long literal string\ninto multiple lines without adding the newlines and spaces\ninto the string contents.\nA short literal string cannot contain unescaped line breaks\nnor escapes not forming a valid escape sequence.\n\n\n<p>\nWe can specify any byte in a short literal string by its numeric value\n(including embedded zeros).\nThis can be done\nwith the escape sequence <code>\\x<em>XX</em></code>,\nwhere <em>XX</em> is a sequence of exactly two hexadecimal digits,\nor with the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a decimal escape sequence is to be followed by a digit,\nit must be expressed using exactly three digits.)\n\n\n<p>\nThe UTF-8 encoding of a Unicode character\ncan be inserted in a literal string with\nthe escape sequence <code>\\u{<em>XXX</em>}</code>\n(note the mandatory enclosing brackets),\nwhere <em>XXX</em> is a sequence of one or more hexadecimal digits\nrepresenting the character code point.\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>, \nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>, \nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance,\na closing long bracket of level&nbsp;4 is written as  <code>]====]</code>.\nA <em>long literal</em> starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nIt can contain any text except a closing bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nAny kind of end-of-line sequence\n(carriage return, newline, carriage return followed by newline,\nor newline followed by carriage return)\nis converted to a simple newline.\n\n\n<p>\nFor convenience,\nwhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nAny byte in a literal string not\nexplicitly affected by the previous rules represents itself.\nHowever, Lua opens files for parsing in text mode,\nand the system file functions may have problems with\nsome control characters.\nSo, it is safer to represent\nnon-text data as a quoted literal with\nexplicit escape sequences for the non-text characters.\n\n\n<p>\nA <em>numeric constant</em> (or <em>numeral</em>)\ncan be written with an optional fractional part\nand an optional decimal exponent,\nmarked by a letter '<code>e</code>' or '<code>E</code>'.\nLua also accepts hexadecimal constants,\nwhich start with <code>0x</code> or <code>0X</code>.\nHexadecimal constants also accept an optional fractional part\nplus an optional binary exponent,\nmarked by a letter '<code>p</code>' or '<code>P</code>'.\nA numeric constant with a radix point or an exponent\ndenotes a float;\notherwise,\nif its value fits in an integer,\nit denotes an integer.\nExamples of valid integer constants are\n\n<pre>\n     3   345   0xff   0xBEBADA\n</pre><p>\nExamples of valid float constants are\n\n<pre>\n     3.0     3.1416     314.16e-2     0.31416E1     34e1\n     0x0.1E  0xA23p-4   0X1.921FB54442D18P+1\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\nLong comments are frequently used to disable code temporarily.\n\n\n\n\n\n<h2>3.2 &ndash; <a name=\"3.2\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers, as defined in <a href=\"#3.1\">&sect;3.1</a>.\n\n\n<p>\nAny variable name is assumed to be global unless explicitly declared\nas a local (see <a href=\"#3.3.7\">&sect;3.3.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;\n</pre><p>\nThe meaning of accesses to table fields can be changed via metatables.\nAn access to an indexed variable <code>t[i]</code> is equivalent to\na call <code>gettable_event(t,i)</code>.\n(See <a href=\"#2.4\">&sect;2.4</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>.</b>&rsquo; Name\n</pre>\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_ENV.x</code>.\nDue to the way that chunks are compiled,\n<code>_ENV</code> is never a global name (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h2>3.3 &ndash; <a name=\"3.3\">Statements</a></h2>\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in Pascal or C.\nThis set includes\nassignments, control structures, function calls,\nand variable declarations.\n\n\n\n<h3>3.3.1 &ndash; <a name=\"3.3.1\">Blocks</a></h3>\n\n<p>\nA block is a list of statements,\nwhich are executed sequentially:\n\n<pre>\n\tblock ::= {stat}\n</pre><p>\nLua has <em>empty statements</em>\nthat allow you to separate statements with semicolons,\nstart a block with a semicolon\nor write two semicolons in sequence:\n\n<pre>\n\tstat ::= &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nFunction calls and assignments\ncan start with an open parenthesis.\nThis possibility leads to an ambiguity in Lua's grammar.\nConsider the following fragment:\n\n<pre>\n     a = b + c\n     (print or io.write)('done')\n</pre><p>\nThe grammar could see it in two ways:\n\n<pre>\n     a = b + c(print or io.write)('done')\n     \n     a = b + c; (print or io.write)('done')\n</pre><p>\nThe current parser always sees such constructions\nin the first way,\ninterpreting the open parenthesis\nas the start of the arguments to a call.\nTo avoid this ambiguity,\nit is a good practice to always precede with a semicolon\nstatements that start with a parenthesis:\n\n<pre>\n     ;(print or io.write)('done')\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> statement in the middle\nof another block (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\n\n\n\n\n\n<h3>3.3.2 &ndash; <a name=\"3.3.2\">Chunks</a></h3>\n\n<p>\nThe unit of compilation of Lua is called a <em>chunk</em>.\nSyntactically,\na chunk is simply a block:\n\n<pre>\n\tchunk ::= block\n</pre>\n\n<p>\nLua handles a chunk as the body of an anonymous function\nwith a variable number of arguments\n(see <a href=\"#3.4.11\">&sect;3.4.11</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\nMoreover, such anonymous function is compiled as in the\nscope of an external local variable called <code>_ENV</code> (see <a href=\"#2.2\">&sect;2.2</a>).\nThe resulting function always has <code>_ENV</code> as its only upvalue,\neven if it does not use that variable.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first <em>loads</em> it,\nprecompiling the chunk's code into instructions for a virtual machine,\nand then Lua executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be precompiled into binary form;\nsee program <code>luac</code> and function <a href=\"#pdf-string.dump\"><code>string.dump</code></a> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly (see <a href=\"#pdf-load\"><code>load</code></a>).\n\n\n\n\n\n<h3>3.3.3 &ndash; <a name=\"3.3.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist &lsquo;<b>=</b>&rsquo; explist\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#3.4\">&sect;3.4</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with as many  <b>nil</b>'s as needed.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then the assignments are performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nThe meaning of assignments to global variables\nand table fields can be changed via metatables.\nAn assignment to an indexed variable <code>t[i] = val</code> is equivalent to\n<code>settable_event(t,i,val)</code>.\n(See <a href=\"#2.4\">&sect;2.4</a> for a complete description of the\n<code>settable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nAn assignment to a global name <code>x = val</code>\nis equivalent to the assignment\n<code>_ENV.x = val</code> (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h3>3.3.4 &ndash; <a name=\"3.3.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#3.3.5\">&sect;3.3.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> are considered false.\nAll values different from <b>nil</b> and <b>false</b> are considered true\n(in particular, the number 0 and the empty string are also true).\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>goto</b> statement transfers the program control to a label.\nFor syntactical reasons,\nlabels in Lua are considered statements too:\n\n\n\n<pre>\n\tstat ::= <b>goto</b> Name\n\tstat ::= label\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n</pre>\n\n<p>\nA label is visible in the entire block where it is defined,\nexcept\ninside nested blocks where a label with the same name is defined and\ninside nested functions.\nA goto may jump to any visible label as long as it does not\nenter into the scope of a local variable.\n\n\n<p>\nLabels and empty statements are called <em>void statements</em>,\nas they perform no actions.\n\n\n<p>\nThe <b>break</b> statement terminates the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk\n(which is an anonymous function).\n\nFunctions can return more than one value,\nso the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n</pre>\n\n<p>\nThe <b>return</b> statement can only be written\nas the last statement of a block.\nIf it is really necessary to <b>return</b> in the middle of a block,\nthen an explicit inner block can be used,\nas in the idiom <code>do return end</code>,\nbecause now <b>return</b> is the last statement in its (inner) block.\n\n\n\n\n\n<h3>3.3.5 &ndash; <a name=\"3.3.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numerical and one generic.\n\n\n<p>\nThe numerical <b>for</b> loop repeats a block of code while a\ncontrol variable runs through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe <em>block</em> is repeated for <em>name</em> starting at the value of\nthe first <em>exp</em>, until it passes the second <em>exp</em> by steps of the\nthird <em>exp</em>.\nMore precisely, a <b>for</b> statement like\n\n<pre>\n     for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)\n       if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end\n       <em>var</em> = <em>var</em> - <em>step</em>\n       while true do\n         <em>var</em> = <em>var</em> + <em>step</em>\n         if (<em>step</em> &gt;= 0 and <em>var</em> &gt; <em>limit</em>) or (<em>step</em> &lt; 0 and <em>var</em> &lt; <em>limit</em>) then\n           break\n         end\n         local v = <em>var</em>\n         <em>block</em>\n       end\n     end\n</pre>\n\n<p>\nNote the following:\n\n<ul>\n\n<li>\nAll three control expressions are evaluated only once,\nbefore the loop starts.\nThey must all result in numbers.\n</li>\n\n<li>\n<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.\nThe names shown here are for explanatory purposes only.\n</li>\n\n<li>\nIf the third expression (the step) is absent,\nthen a step of&nbsp;1 is used.\n</li>\n\n<li>\nYou can use <b>break</b> and <b>goto</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variable <code>v</code> is local to the loop body.\nIf you need its value after the loop,\nassign it to another variable before exiting the loop.\n</li>\n\n</ul>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>\n       while true do\n         local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)\n         if <em>var_1</em> == nil then break end\n         <em>var</em> = <em>var_1</em>\n         <em>block</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\n<code><em>explist</em></code> is evaluated only once.\nIts results are an <em>iterator</em> function,\na <em>state</em>,\nand an initial value for the first <em>iterator variable</em>.\n</li>\n\n<li>\n<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.\nThe names are here for explanatory purposes only.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variables <code><em>var_i</em></code> are local to the loop;\nyou cannot use their values after the <b>for</b> ends.\nIf you need these values,\nthen assign them to other variables before breaking or exiting the loop.\n</li>\n\n</ul>\n\n\n\n\n<h3>3.3.6 &ndash; <a name=\"3.3.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>.\n\n\n\n\n\n<h3>3.3.7 &ndash; <a name=\"3.3.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initial assignment:\n\n<pre>\n\tstat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#3.3.3\">&sect;3.3.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nA chunk is also a block (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nand so local variables can be declared in a chunk outside any explicit block.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#3.5\">&sect;3.5</a>.\n\n\n\n\n\n\n\n<h2>3.4 &ndash; <a name=\"3.4\">Expressions</a></h2>\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Numeral\n\texp ::= LiteralString\n\texp ::= functiondef\n\texp ::= tableconstructor\n\texp ::= &lsquo;<b>...</b>&rsquo;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n</pre>\n\n<p>\nNumerals and literal strings are explained in <a href=\"#3.1\">&sect;3.1</a>;\nvariables are explained in <a href=\"#3.2\">&sect;3.2</a>;\nfunction definitions are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>;\nfunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>;\ntable constructors are explained in <a href=\"#3.4.9\">&sect;3.4.9</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nbitwise operators (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nrelational operators (see <a href=\"#3.4.4\">&sect;3.4.4</a>), logical operators (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the concatenation operator (see <a href=\"#3.4.6\">&sect;3.4.6</a>).\nUnary operators comprise the unary minus (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nthe unary bitwise NOT (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nthe unary logical <b>not</b> (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the unary <em>length operator</em> (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf a function call is used as a statement (see <a href=\"#3.3.6\">&sect;3.3.6</a>),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the expression is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\neither discarding all values except the first one\nor adding a single <b>nil</b> if there are no values.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg parameter, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg parameter)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg parameters\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg parameters\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n<h3>3.4.1 &ndash; <a name=\"3.4.1\">Arithmetic Operators</a></h3><p>\nLua supports the following arithmetic operators:\n\n<ul>\n<li><b><code>+</code>: </b>addition</li>\n<li><b><code>-</code>: </b>subtraction</li>\n<li><b><code>*</code>: </b>multiplication</li>\n<li><b><code>/</code>: </b>float division</li>\n<li><b><code>//</code>: </b>floor division</li>\n<li><b><code>%</code>: </b>modulo</li>\n<li><b><code>^</code>: </b>exponentiation</li>\n<li><b><code>-</code>: </b>unary minus</li>\n</ul>\n\n<p>\nWith the exception of exponentiation and float division,\nthe arithmetic operators work as follows:\nIf both operands are integers,\nthe operation is performed over integers and the result is an integer.\nOtherwise, if both operands are numbers\nor strings that can be converted to\nnumbers (see <a href=\"#3.4.3\">&sect;3.4.3</a>),\nthen they are converted to floats,\nthe operation is performed following the usual rules\nfor floating-point arithmetic\n(usually the IEEE 754 standard),\nand the result is a float.\n\n\n<p>\nExponentiation and float division (<code>/</code>)\nalways convert their operands to floats\nand the result is always a float.\nExponentiation uses the ISO&nbsp;C function <code>pow</code>,\nso that it works for non-integer exponents too.\n\n\n<p>\nFloor division (<code>//</code>) is a division\nthat rounds the quotient towards minus infinity,\nthat is, the floor of the division of its operands.\n\n\n<p>\nModulo is defined as the remainder of a division\nthat rounds the quotient towards minus infinity (floor division).\n\n\n<p>\nIn case of overflows in integer arithmetic,\nall operations <em>wrap around</em>,\naccording to the usual rules of two-complement arithmetic.\n(In other words,\nthey return the unique representable integer\nthat is equal modulo <em>2<sup>64</sup></em> to the mathematical result.)\n\n\n\n<h3>3.4.2 &ndash; <a name=\"3.4.2\">Bitwise Operators</a></h3><p>\nLua supports the following bitwise operators:\n\n<ul>\n<li><b><code>&amp;</code>: </b>bitwise AND</li>\n<li><b><code>&#124;</code>: </b>bitwise OR</li>\n<li><b><code>~</code>: </b>bitwise exclusive OR</li>\n<li><b><code>&gt;&gt;</code>: </b>right shift</li>\n<li><b><code>&lt;&lt;</code>: </b>left shift</li>\n<li><b><code>~</code>: </b>unary bitwise NOT</li>\n</ul>\n\n<p>\nAll bitwise operations convert its operands to integers\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>),\noperate on all bits of those integers,\nand result in an integer.\n\n\n<p>\nBoth right and left shifts fill the vacant bits with zeros.\nNegative displacements shift to the other direction;\ndisplacements with absolute values equal to or higher than\nthe number of bits in an integer\nresult in zero (as all bits are shifted out).\n\n\n\n\n\n<h3>3.4.3 &ndash; <a name=\"3.4.3\">Coercions and Conversions</a></h3><p>\nLua provides some automatic conversions between some\ntypes and representations at run time.\nBitwise operators always convert float operands to integers.\nExponentiation and float division\nalways convert integer operands to floats.\nAll other arithmetic operations applied to mixed numbers\n(integers and floats) convert the integer operand to a float;\nthis is called the <em>usual rule</em>.\nThe C API also converts both integers to floats and\nfloats to integers, as needed.\nMoreover, string concatenation accepts numbers as arguments,\nbesides strings.\n\n\n<p>\nLua also converts strings to numbers,\nwhenever a number is expected.\n\n\n<p>\nIn a conversion from integer to float,\nif the integer value has an exact representation as a float,\nthat is the result.\nOtherwise,\nthe conversion gets the nearest higher or\nthe nearest lower representable value.\nThis kind of conversion never fails.\n\n\n<p>\nThe conversion from float to integer\nchecks whether the float has an exact representation as an integer\n(that is, the float has an integral value and\nit is in the range of integer representation).\nIf it does, that representation is the result.\nOtherwise, the conversion fails.\n\n\n<p>\nThe conversion from strings to numbers goes as follows:\nFirst, the string is converted to an integer or a float,\nfollowing its syntax and the rules of the Lua lexer.\n(The string may have also leading and trailing spaces and a sign.)\nThen, the resulting number (float or integer)\nis converted to the type (float or integer) required by the context\n(e.g., the operation that forced the conversion).\n\n\n<p>\nAll conversions from strings to numbers\naccept both a dot and the current locale mark\nas the radix character.\n(The Lua lexer, however, accepts only a dot.)\n\n\n<p>\nThe conversion from numbers to strings uses a\nnon-specified human-readable format.\nFor complete control over how numbers are converted to strings,\nuse the <code>format</code> function from the string library\n(see <a href=\"#pdf-string.format\"><code>string.format</code></a>).\n\n\n\n\n\n<h3>3.4.4 &ndash; <a name=\"3.4.4\">Relational Operators</a></h3><p>\nLua supports the following relational operators:\n\n<ul>\n<li><b><code>==</code>: </b>equality</li>\n<li><b><code>~=</code>: </b>inequality</li>\n<li><b><code>&lt;</code>: </b>less than</li>\n<li><b><code>&gt;</code>: </b>greater than</li>\n<li><b><code>&lt;=</code>: </b>less or equal</li>\n<li><b><code>&gt;=</code>: </b>greater or equal</li>\n</ul><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nStrings are compared in the obvious way.\nNumbers are equal if they denote the same mathematical value.\n\n\n<p>\nTables, userdata, and threads\nare compared by reference:\ntwo objects are considered equal only if they are the same object.\nEvery time you create a new object\n(a table, userdata, or thread),\nthis new object is different from any previously existing object.\nClosures with the same reference are always equal.\nClosures with any detectable difference\n(different behavior, different definition) are always different.\n\n\n<p>\nYou can change the way that Lua compares tables and userdata\nby using the \"eq\" metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nEquality comparisons do not convert strings to numbers\nor vice versa.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers,\nthen they are compared according to their mathematical values\n(regardless of their subtypes).\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the \"lt\" or the \"le\"\nmetamethod (see <a href=\"#2.4\">&sect;2.4</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n<p>\nFollowing the IEEE 754 standard,\nNaN is considered neither smaller than,\nnor equal to, nor greater than any value (including itself).\n\n\n\n\n\n<h3>3.4.5 &ndash; <a name=\"3.4.5\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#3.3.4\">&sect;3.3.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-circuit evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre><p>\n(In this manual,\n<code>--&gt;</code> indicates the result of the preceding expression.)\n\n\n\n\n\n<h3>3.4.6 &ndash; <a name=\"3.4.6\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers, then they are converted to\nstrings according to the rules described in <a href=\"#3.4.3\">&sect;3.4.3</a>.\nOtherwise, the <code>__concat</code> metamethod is called (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.7 &ndash; <a name=\"3.4.7\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary prefix operator <code>#</code>.\n\n\n<p>\nThe length of a string is its number of bytes\n(that is, the usual meaning of string length when each\ncharacter is one byte).\n\n\n<p>\nThe length operator applied on a table\nreturns a border in that table.\nA <em>border</em> in a table <code>t</code> is any natural number\nthat satisfies the following condition:\n\n<pre>\n     (border == 0 or t[border] ~= nil) and t[border + 1] == nil\n</pre><p>\nIn words,\na border is any (natural) index in a table\nwhere a non-nil value is followed by a nil value\n(or zero, when index 1 is nil).\n\n\n<p>\nA table with exactly one border is called a <em>sequence</em>.\nFor instance, the table <code>{10, 20, 30, 40, 50}</code> is a sequence,\nas it has only one border (5).\nThe table <code>{10, 20, 30, nil, 50}</code> has two borders (3 and 5),\nand therefore it is not a sequence.\nThe table <code>{nil, 20, 30, nil, nil, 60, nil}</code>\nhas three borders (0, 3, and 6),\nso it is not a sequence, too.\nThe table <code>{}</code> is a sequence with border 0.\nNote that non-natural keys do not interfere\nwith whether a table is a sequence.\n\n\n<p>\nWhen <code>t</code> is a sequence,\n<code>#t</code> returns its only border,\nwhich corresponds to the intuitive notion of the length of the sequence.\nWhen <code>t</code> is not a sequence,\n<code>#t</code> can return any of its borders.\n(The exact one depends on details of\nthe internal representation of the table,\nwhich in turn can depend on how the table was populated and\nthe memory addresses of its non-numeric keys.)\n\n\n<p>\nThe computation of the length of a table\nhas a guaranteed worst time of <em>O(log n)</em>,\nwhere <em>n</em> is the largest natural key in the table.\n\n\n<p>\nA program can modify the behavior of the length operator for\nany value but strings through the <code>__len</code> metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.8 &ndash; <a name=\"3.4.8\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     |\n     ~\n     &amp;\n     &lt;&lt;    &gt;&gt;\n     ..\n     +     -\n     *     /     //    %\n     unary operators (not   #     -     ~)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>3.4.9 &ndash; <a name=\"3.4.9\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFinally, fields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive integers\nstarting with 1.\nFields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nThe order of the assignments in a constructor is undefined.\n(This order would be relevant only when there are repeated keys.)\n\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#3.4.10\">&sect;3.4.10</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>3.4.10 &ndash; <a name=\"3.4.10\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, the prefixexp \"call\" metamethod is called,\nhaving as first parameter the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp &lsquo;<b>:</b>&rsquo; Name args\n</pre><p>\ncan be used to call \"methods\".\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;\n\targs ::= tableconstructor\n\targs ::= LiteralString\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nA call of the form <code>return <em>functioncall</em></code> is called\na <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument;\nthis syntax makes the calling function return exactly\nthe returns of the called function.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>3.4.11 &ndash; <a name=\"3.4.11\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunctiondef ::= <b>function</b> funcbody\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\nnot to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua precompiles a chunk,\nall its function bodies are precompiled too.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance (or <em>closure</em>)\nis the final value of the expression.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n</pre><p>\nWhen a function is called,\nthe list of arguments is adjusted to\nthe length of the list of parameters,\nunless the function is a <em>vararg function</em>,\nwhich is indicated by three dots ('<code>...</code>')\nat the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL            PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\n\nThere is a system-dependent limit on the number of values\nthat a function may return.\nThis limit is guaranteed to be larger than 1000.\n\n\n<p>\nThe <em>colon</em> syntax\nis used for defining <em>methods</em>,\nthat is, functions that have an implicit extra parameter <code>self</code>.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>3.5 &ndash; <a name=\"3.5\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of a local variable begins at the first statement after\nits declaration and lasts until the last non-void statement\nof the innermost block that includes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called\nan <em>upvalue</em>, or <em>external local variable</em>,\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i=1,10 do\n       local y = 0\n       a[i] = function () y=y+1; return x+y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h1>4 &ndash; <a name=\"4\">The Application Program Interface</a></h1>\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nExcept where stated otherwise,\nall such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments for validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith the macro <a name=\"pdf-LUA_USE_APICHECK\"><code>LUA_USE_APICHECK</code></a> defined.\n\n\n<p>\nThe Lua library is fully reentrant:\nit has no global variables.\nIt keeps all information it needs in a dynamic structure,\ncalled the <em>Lua state</em>.\n\n\n<p>\nEach Lua state has one or more threads,\nwhich correspond to independent, cooperative lines of execution.\nThe type <a href=\"#lua_State\"><code>lua_State</code></a> (despite its name) refers to a thread.\n(Indirectly, through the thread, it also refers to the\nLua state associated to the thread.)\n\n\n<p>\nA pointer to a thread must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch and returns a pointer\nto the <em>main thread</em> in the new state.\n\n\n\n<h2>4.1 &ndash; <a name=\"4.1\">The Stack</a></h2>\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\nFunctions in the API can access this stack through the\nLua state parameter that they receive.\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function can store temporary\nLua values and must push its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an absolute stack position\n(starting at&nbsp;1);\na negative index represents an offset relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\n\n\n\n\n\n<h2>4.2 &ndash; <a name=\"4.2\">Stack Size</a></h2>\n\n<p>\nWhen you interact with the Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto ensure that the stack has enough space for pushing new elements.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that the stack has space for\nat least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> extra slots.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nWhen you call a Lua function\nwithout a fixed number of results (see <a href=\"#lua_call\"><code>lua_call</code></a>),\nLua ensures that the stack has enough space for all results,\nbut it does not ensure any extra space.\nSo, before pushing anything in the stack after such a call\nyou should use <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\n\n\n\n\n\n<h2>4.3 &ndash; <a name=\"4.3\">Valid and Acceptable Indices</a></h2>\n\n<p>\nAny function in the API that receives stack indices\nworks only with <em>valid indices</em> or <em>acceptable indices</em>.\n\n\n<p>\nA <em>valid index</em> is an index that refers to a\nposition that stores a modifiable Lua value.\nIt comprises stack indices between&nbsp;1 and the stack top\n(<code>1 &le; abs(index) &le; top</code>)\n\nplus <em>pseudo-indices</em>,\nwhich represent some positions that are accessible to C&nbsp;code\nbut that are not in the stack.\nPseudo-indices are used to access the registry (see <a href=\"#4.5\">&sect;4.5</a>)\nand the upvalues of a C&nbsp;function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n<p>\nFunctions that do not need a specific mutable position,\nbut only a value (e.g., query functions),\ncan be called with acceptable indices.\nAn <em>acceptable index</em> can be any valid index,\nbut it also can be any positive index after the stack top\nwithin the space allocated for the stack,\nthat is, indices up to the stack size.\n(Note that 0 is never an acceptable index.)\nExcept when noted otherwise,\nfunctions in the API work with acceptable indices.\n\n\n<p>\nAcceptable indices serve to avoid extra tests\nagainst the stack top when querying the stack.\nFor instance, a C&nbsp;function can query its third argument\nwithout the need to first check whether there is a third argument,\nthat is, without the need to check whether 3 is a valid index.\n\n\n<p>\nFor functions that can be called with acceptable indices,\nany non-valid index is treated as if it\ncontains a value of a virtual type <a name=\"pdf-LUA_TNONE\"><code>LUA_TNONE</code></a>,\nwhich behaves like a nil value.\n\n\n\n\n\n<h2>4.4 &ndash; <a name=\"4.4\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>);\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called.\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a href=\"#lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first upvalue associated with a function is at index\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function\n(but not greater than 256,\nwhich is one plus the maximum number of upvalues in a closure),\nproduces an acceptable but invalid index.\n\n\n\n\n\n<h2>4.5 &ndash; <a name=\"4.5\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na predefined table that can be used by any C&nbsp;code to\nstore whatever Lua values it needs to store.\nThe registry table is always located at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it must take care to choose keys\nthat are different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name,\nor a light userdata with the address of a C&nbsp;object in your code,\nor any Lua object created by your code.\nAs with variable names,\nstring keys starting with an underscore followed by\nuppercase letters are reserved for Lua.\n\n\n<p>\nThe integer keys in the registry are used\nby the reference mechanism (see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>)\nand by some predefined values.\nTherefore, integer keys must not be used for other purposes.\n\n\n<p>\nWhen you create a new Lua state,\nits registry comes with some predefined values.\nThese predefined values are indexed with integer keys\ndefined as constants in <code>lua.h</code>.\nThe following constants are defined:\n\n<ul>\n<li><b><a name=\"pdf-LUA_RIDX_MAINTHREAD\"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has\nthe main thread of the state.\n(The main thread is the one created together with the state.)\n</li>\n\n<li><b><a name=\"pdf-LUA_RIDX_GLOBALS\"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has\nthe global environment.\n</li>\n</ul>\n\n\n\n\n<h2>4.6 &ndash; <a name=\"4.6\">Error Handling in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(Lua will use exceptions if you compile it as C++;\nsearch for <code>LUAI_THROW</code> in the source code for details.)\nWhen Lua faces any error\n(such as a memory allocation error or a type error)\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recovery point;\nany error jumps to the most recent active recovery point.\n\n\n<p>\nInside a C&nbsp;function you can raise an error by calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n<p>\nMost functions in the API can raise an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can raise errors.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em> (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>)\nand then calls <code>abort</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning\n(e.g., doing a long jump to your own recovery point outside Lua).\n\n\n<p>\nThe panic function,\nas its name implies,\nis a mechanism of last resort.\nPrograms should avoid it.\nAs a general rule,\nwhen a C&nbsp;function is called by Lua with a Lua state,\nit can do whatever it wants on that Lua state,\nas it should be already protected.\nHowever,\nwhen C code operates on other Lua states\n(e.g., a Lua parameter to the function,\na Lua state stored in the registry, or\nthe result of <a href=\"#lua_newthread\"><code>lua_newthread</code></a>),\nit should use them only in API calls that cannot raise errors.\n\n\n<p>\nThe panic function runs as if it were a message handler (see <a href=\"#2.3\">&sect;2.3</a>);\nin particular, the error object is at the top of the stack.\nHowever, there is no guarantee about stack space.\nTo push anything on the stack,\nthe panic function must first check the available space (see <a href=\"#4.2\">&sect;4.2</a>).\n\n\n\n\n\n<h2>4.7 &ndash; <a name=\"4.7\">Handling Yields in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.\nTherefore, if a C&nbsp;function <code>foo</code> calls an API function\nand this API function yields\n(directly or indirectly by calling another function that yields),\nLua cannot return to <code>foo</code> any more,\nbecause the <code>longjmp</code> removes its frame from the C stack.\n\n\n<p>\nTo avoid this kind of problem,\nLua raises an error whenever it tries to yield across an API call,\nexcept for three functions:\n<a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, <a href=\"#lua_callk\"><code>lua_callk</code></a>, and <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\nAll those functions receive a <em>continuation function</em>\n(as a parameter named <code>k</code>) to continue execution after a yield.\n\n\n<p>\nWe need to set some terminology to explain continuations.\nWe have a C&nbsp;function called from Lua which we will call\nthe <em>original function</em>.\nThis original function then calls one of those three functions in the C API,\nwhich we will call the <em>callee function</em>,\nthat then yields the current thread.\n(This can happen when the callee function is <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nor when the callee function is either <a href=\"#lua_callk\"><code>lua_callk</code></a> or <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>\nand the function called by them yields.)\n\n\n<p>\nSuppose the running thread yields while executing the callee function.\nAfter the thread resumes,\nit eventually will finish running the callee function.\nHowever,\nthe callee function cannot return to the original function,\nbecause its frame in the C stack was destroyed by the yield.\nInstead, Lua calls a <em>continuation function</em>,\nwhich was given as an argument to the callee function.\nAs the name implies,\nthe continuation function should continue the task\nof the original function.\n\n\n<p>\nAs an illustration, consider the following function:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       status = lua_pcall(L, n, m, h);  /* calls Lua */\n       ...     /* code 2 */\n     }\n</pre><p>\nNow we want to allow\nthe Lua code being run by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> to yield.\nFirst, we can rewrite our function like here:\n\n<pre>\n     int k (lua_State *L, int status, lua_KContext ctx) {\n       ...  /* code 2 */\n     }\n     \n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcall(L, n, m, h), ctx);\n     }\n</pre><p>\nIn the above code,\nthe new function <code>k</code> is a\n<em>continuation function</em> (with type <a href=\"#lua_KFunction\"><code>lua_KFunction</code></a>),\nwhich should do all the work that the original function\nwas doing after calling <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\nNow, we must inform Lua that it must call <code>k</code> if the Lua code\nbeing executed by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> gets interrupted in some way\n(errors or yielding),\nso we rewrite the code as here,\nreplacing <a href=\"#lua_pcall\"><code>lua_pcall</code></a> by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);\n     }\n</pre><p>\nNote the external, explicit call to the continuation:\nLua will call the continuation only if needed, that is,\nin case of errors or resuming after a yield.\nIf the called function returns normally without ever yielding,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a> (and <a href=\"#lua_callk\"><code>lua_callk</code></a>) will also return normally.\n(Of course, instead of calling the continuation in that case,\nyou can do the equivalent work directly inside the original function.)\n\n\n<p>\nBesides the Lua state,\nthe continuation function has two other parameters:\nthe final status of the call plus the context value (<code>ctx</code>) that\nwas passed originally to <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\n(Lua does not use this context value;\nit only passes this value from the original function to the\ncontinuation function.)\nFor <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nthe status is the same value that would be returned by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nexcept that it is <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when being executed after a yield\n(instead of <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>).\nFor <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> and <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nthe status is always <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when Lua calls the continuation.\n(For these two functions,\nLua will not call the continuation in case of errors,\nbecause they do not handle errors.)\nSimilarly, when using <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nyou should call the continuation function\nwith <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> as the status.\n(For <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, there is not much point in calling\ndirectly the continuation function,\nbecause <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> usually does not return.)\n\n\n<p>\nLua treats the continuation function as if it were the original function.\nThe continuation function receives the same Lua stack\nfrom the original function,\nin the same state it would be if the callee function had returned.\n(For instance,\nafter a <a href=\"#lua_callk\"><code>lua_callk</code></a> the function and its arguments are\nremoved from the stack and replaced by the results from the call.)\nIt also has the same upvalues.\nWhatever it returns is handled by Lua as if it were the return\nof the original function.\n\n\n\n\n\n<h2>4.8 &ndash; <a name=\"4.8\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments\n(e.g., they may depend on what is on the stack).\nThe third field, <code>x</code>,\ntells whether the function may raise errors:\n'<code>-</code>' means the function never raises any error;\n'<code>m</code>' means the function may raise out-of-memory errors\nand errors running a <code>__gc</code> metamethod;\n'<code>e</code>' means the function may raise any errors\n(it can run arbitrary Lua code,\neither directly or through metamethods);\n'<code>v</code>' means the function may raise an error on purpose.\n\n\n\n<hr><h3><a name=\"lua_absindex\"><code>lua_absindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_absindex (lua_State *L, int idx);</pre>\n\n<p>\nConverts the acceptable index <code>idx</code>\ninto an equivalent absolute index\n(that is, one that does not depend on the stack top).\n\n\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block or some code about what\nis being allocated;\nand <code>nsize</code>, the new size of the block.\n\n\n<p>\nWhen <code>ptr</code> is not <code>NULL</code>,\n<code>osize</code> is the size of the block pointed by <code>ptr</code>,\nthat is, the size given when it was allocated or reallocated.\n\n\n<p>\nWhen <code>ptr</code> is <code>NULL</code>,\n<code>osize</code> encodes the kind of object that Lua is allocating.\n<code>osize</code> is any of\n<a href=\"#pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>, <a href=\"#pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>, <a href=\"#pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a href=\"#pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>, or <a href=\"#pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a> when (and only when)\nLua is creating a new object of that type.\nWhen <code>osize</code> is some other value,\nLua is allocating memory for something else.\n\n\n<p>\nLua assumes the following behavior from the allocator function:\n\n\n<p>\nWhen <code>nsize</code> is zero,\nthe allocator must behave like <code>free</code>\nand return <code>NULL</code>.\n\n\n<p>\nWhen <code>nsize</code> is not zero,\nthe allocator must behave like <code>realloc</code>.\nThe allocator returns <code>NULL</code>\nif and only if it cannot fulfill the request.\nLua assumes that the allocator never fails when\n<code>osize &gt;= nsize</code>.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nNote that Standard&nbsp;C ensures\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.\nThis code assumes that <code>realloc</code> does not fail when shrinking a block.\n(Although Standard&nbsp;C does not ensure this behavior,\nit seems to be a safe assumption.)\n\n\n\n\n\n<hr><h3><a name=\"lua_arith\"><code>lua_arith</code></a></h3><p>\n<span class=\"apii\">[-(2|1), +1, <em>e</em>]</span>\n<pre>void lua_arith (lua_State *L, int op);</pre>\n\n<p>\nPerforms an arithmetic or bitwise operation over the two values\n(or one, in the case of negations)\nat the top of the stack,\nwith the value at the top being the second operand,\npops these values, and pushes the result of the operation.\nThe function follows the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPADD\"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSUB\"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMUL\"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>\n<li><b><a name=\"pdf-LUA_OPDIV\"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</code>)</li>\n<li><b><a name=\"pdf-LUA_OPIDIV\"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMOD\"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>\n<li><b><a name=\"pdf-LUA_OPPOW\"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>\n<li><b><a name=\"pdf-LUA_OPUNM\"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBNOT\"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBAND\"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&amp;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBOR\"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBXOR\"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHL\"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code>&lt;&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHR\"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>&gt;&gt;</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one (see <a href=\"#4.6\">&sect;4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs+1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\n\n\n<p>\nTo call a function you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the function are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nAll arguments and the function value are popped from the stack\nwhen the function is called.\nThe function results are pushed onto the stack when the function returns.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, all results from the function are pushed;\nLua takes care that the returned values fit into the stack space,\nbut it does not ensure any extra space in the stack.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error inside the called function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getglobal(L, \"f\");                  /* function to be called */\n     lua_pushliteral(L, \"how\");                       /* 1st argument */\n     lua_getglobal(L, \"t\");                    /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setglobal(L, \"a\");                         /* set global 'a' */\n</pre><p>\nNote that the code above is <em>balanced</em>:\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_callk\"><code>lua_callk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_callk (lua_State *L,\n                int nargs,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numeric arguments and returns their average and their sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0.0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushliteral(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_checkstack (lua_State *L, int n);</pre>\n\n<p>\nEnsures that the stack has space for at least <code>n</code> extra slots\n(that is, that you can safely push up to <code>n</code> values into it).\nIt returns false if it cannot fulfill the request,\neither because it would cause the stack\nto be larger than a fixed maximum size\n(typically at least several thousand elements) or\nbecause it cannot allocate memory for the extra space.\nThis function never shrinks the stack;\nif the stack already has space for the extra slots,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nDestroys all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any)\nand frees all dynamic memory used by this state.\nOn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs that create multiple states,\nsuch as daemons or web servers,\nwill probably need to close states as soon as they are not needed.\n\n\n\n\n\n<hr><h3><a name=\"lua_compare\"><code>lua_compare</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>\n\n<p>\nCompares two Lua values.\nReturns 1 if the value at index <code>index1</code> satisfies <code>op</code>\nwhen compared with the value at index <code>index2</code>,\nfollowing the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is not valid.\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPEQ\"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLT\"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLE\"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result at the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#3.4.6\">&sect;3.4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_copy\"><code>lua_copy</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>\n\n<p>\nCopies the element at index <code>fromidx</code>\ninto the valid index <code>toidx</code>,\nreplacing the value at that position.\nValues at other positions are not affected.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nParameter <code>narr</code> is a hint for how many elements the table\nwill have as a sequence;\nparameter <code>nrec</code> is a hint for how many other elements\nthe table will have.\nLua may use these hints to preallocate memory for the new table.\nThis preallocation is useful for performance when you know in advance\nhow many elements the table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_dump (lua_State *L,\n                        lua_Writer writer,\n                        void *data,\n                        int strip);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nIf <code>strip</code> is true,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nGenerates a Lua error,\nusing the value at the top of the stack as the error object.\nThis function does a long jump,\nand therefore never returns\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_gc (lua_State *L, int what, int data);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>:\n\n<ul>\n\n<li><b><code>LUA_GCSTOP</code>: </b>\nstops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>: </b>\nrestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOLLECT</code>: </b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>: </b>\nreturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>: </b>\nreturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code>: </b>\nperforms an incremental step of garbage collection.\n</li>\n\n<li><b><code>LUA_GCSETPAUSE</code>: </b>\nsets <code>data</code> as the new value\nfor the <em>pause</em> of the collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the pause.\n</li>\n\n<li><b><code>LUA_GCSETSTEPMUL</code>: </b>\nsets <code>data</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the step multiplier.\n</li>\n\n<li><b><code>LUA_GCISRUNNING</code>: </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n<p>\nFor more details about these options,\nsee <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer given when the memory-allocator function was set.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getextraspace\"><code>lua_getextraspace</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_getextraspace (lua_State *L);</pre>\n\n<p>\nReturns a pointer to a raw memory area associated with the\ngiven Lua state.\nThe application can use this area for any purpose;\nLua does not use it for anything.\n\n\n<p>\nEach new thread has this area initialized with a copy\nof the area of the main thread.\n\n\n<p>\nBy default, this area has the size of a pointer to void,\nbut you can recompile Lua with a different size for this area.\n(See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nReturns the type of that value.\n\n\n\n\n\n<hr><h3><a name=\"lua_geti\"><code>lua_geti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_geti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nPushes onto the stack the value <code>t[i]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index has a metatable,\nthe function pushes that metatable onto the stack and returns&nbsp;1.\nOtherwise,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>int lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index\nand <code>k</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the key from the stack,\npushing the resulting value in its place.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack;\nin particular, 0&nbsp;means an empty stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_getuservalue\"><code>lua_getuservalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_getuservalue (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the Lua value associated with the full userdata\nat the given index.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ... lua_Integer;</pre>\n\n<p>\nThe type of integers in Lua.\n\n\n<p>\nBy default this type is <code>long long</code>,\n(usually a 64-bit two-complement integer),\nbut that can be changed to <code>long</code> or <code>int</code>\n(usually a 32-bit two-complement integer).\n(See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n<p>\nLua also defines the constants\n<a name=\"pdf-LUA_MININTEGER\"><code>LUA_MININTEGER</code></a> and <a name=\"pdf-LUA_MAXINTEGER\"><code>LUA_MAXINTEGER</code></a>,\nwith the minimum and the maximum values that fit in this type.\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isinteger\"><code>lua_isinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isinteger (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is an integer\n(that is, the value is a number and is represented as an integer),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isyieldable\"><code>lua_isyieldable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isyieldable (lua_State *L);</pre>\n\n<p>\nReturns 1 if the given coroutine can yield,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_KContext\"><code>lua_KContext</code></a></h3>\n<pre>typedef ... lua_KContext;</pre>\n\n<p>\nThe type for continuation-function contexts.\nIt must be a numeric type.\nThis type is defined as <code>intptr_t</code>\nwhen <code>intptr_t</code> is available,\nso that it can store pointers too.\nOtherwise, it is defined as <code>ptrdiff_t</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_KFunction\"><code>lua_KFunction</code></a></h3>\n<pre>typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);</pre>\n\n<p>\nType for continuation functions (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_len\"><code>lua_len</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the length of the value at the given index.\nIt is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>) and\nmay trigger a metamethod for the \"length\" event (see <a href=\"#2.4\">&sect;2.4</a>).\nThe result is pushed on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname,\n              const char *mode);</pre>\n\n<p>\nLoads a Lua chunk without running it.\nIf there are no errors,\n<code>lua_load</code> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\n\n\n<p>\nThe return values of <code>lua_load</code> are:\n\n<ul>\n\n<li><b><a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>: </b> no errors;</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>: </b>\nsyntax error during precompilation;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation (out-of-memory) error;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\n(This error has no relation with the chunk being loaded.\nIt is generated by the garbage collector.)\n</li>\n\n</ul>\n\n<p>\nThe <code>lua_load</code> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#4.9\">&sect;4.9</a>).\n\n\n<p>\n<code>lua_load</code> automatically detects whether the chunk is text or binary\nand loads it accordingly (see program <code>luac</code>).\nThe string <code>mode</code> works as in function <a href=\"#pdf-load\"><code>load</code></a>,\nwith the addition that\na <code>NULL</code> value is equivalent to the string \"<code>bt</code>\".\n\n\n<p>\n<code>lua_load</code> uses the stack internally,\nso the reader function must always leave the stack\nunmodified when returning.\n\n\n<p>\nIf the resulting function has upvalues,\nits first upvalue is set to the value of the global environment\nstored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href=\"#4.5\">&sect;4.5</a>).\nWhen loading main chunks,\nthis upvalue will be the <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nOther upvalues are initialized with <b>nil</b>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new thread running in a new, independent state.\nReturns <code>NULL</code> if it cannot create the thread or the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua does all memory allocation for this state\nthrough this function (see <a href=\"#lua_Alloc\"><code>lua_Alloc</code></a>).\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\npasses to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new thread returned by this function shares with the original thread\nits global environment,\nbut has an independent execution stack.\n\n\n<p>\nThere is no explicit function to close or to destroy a thread.\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdata\"><code>lua_newuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>\n\n<p>\nThis function allocates a new block of memory with the given size,\npushes onto the stack a new full userdata with the block address,\nand returns this address.\nThe host program can freely use this memory.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>e</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key&ndash;value pair from the table at the given index\n(the \"next\" pair after the given key).\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 (and pushes nothing).\n\n\n<p>\nA typical traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\ndo not call <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> may change\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef ... lua_Number;</pre>\n\n<p>\nThe type of floats in Lua.\n\n\n<p>\nBy default this type is double,\nbut that can be changed to a single float or a long double.\n(See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_numbertointeger\"><code>lua_numbertointeger</code></a></h3>\n<pre>int lua_numbertointeger (lua_Number n, lua_Integer *p);</pre>\n\n<p>\nConverts a Lua float to a Lua integer.\nThis macro assumes that <code>n</code> has an integral value.\nIf that value is within the range of Lua integers,\nit is converted to an integer and assigned to <code>*p</code>.\nThe macro results in a boolean indicating whether the\nconversion was successful.\n(Note that this range test can be tricky to do\ncorrectly without this macro,\ndue to roundings.)\n\n\n<p>\nThis macro may evaluate its arguments more than once.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>\n\n<p>\nCalls a function in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error object),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>msgh</code> is 0,\nthen the error object returned on the stack\nis exactly the original error object.\nOtherwise, <code>msgh</code> is the stack index of a\n<em>message handler</em>.\n(This index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis function will be called with the error object\nand its return value will be the object\nreturned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the message handler is used to add more debug\ninformation to the error object, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns one of the following constants\n(defined in <code>lua.h</code>):\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OK\"><code>LUA_OK</code></a> (0): </b>\nsuccess.</li>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>: </b>\na runtime error.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation error.\nFor such errors, Lua does not call the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>: </b>\nerror while running the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\nFor such errors, Lua does not call the message handler\n(as this kind of error typically has no relation\nwith the function being called).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pcallk\"><code>lua_pcallk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcallk (lua_State *L,\n                int nargs,\n                int nresults,\n                int msgh,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, &ndash;]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a C&nbsp;closure (see <a href=\"#4.4\">&sect;4.4</a>);\nthese values are then accessible to the function whenever it is called.\nTo associate values with a C&nbsp;function,\nfirst these values must be pushed onto the stack\n(when there are multiple values, the first value is pushed first).\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values will be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n<p>\nWhen <code>n</code> is zero,\nthis function creates a <em>light C&nbsp;function</em>,\nwhich is just a pointer to the C&nbsp;function.\nIn that case, it never raises a memory error.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function receives a pointer to a C&nbsp;function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\n\n\n<p>\nAny function to be callable by Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string.\nIt is similar to the ISO&nbsp;C function <code>sprintf</code>,\nbut has some important differences:\n\n<ul>\n\n<li>\nYou do not have to allocate space for the result:\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\n</li>\n\n<li>\nThe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts the character '<code>%</code>'),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%I</code>' (inserts a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>),\n'<code>%p</code>' (inserts a pointer as a hexadecimal numeral),\n'<code>%d</code>' (inserts an <code>int</code>),\n'<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and\n'<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).\n</li>\n\n</ul>\n\n<p>\nUnlike other push functions,\nthis function checks for the stack space it needs,\nincluding the slot for its result.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushglobaltable\"><code>lua_pushglobaltable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushglobaltable (lua_State *L);</pre>\n\n<p>\nPushes the global environment onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes an integer with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer, a <code>void*</code>.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushstring\"><code>lua_pushstring</code></a>,\nbut should be used only when <code>s</code> is a literal string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain any binary data,\nincluding embedded zeros.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a float with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n<p>\nIf <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, without calling the <code>__eq</code> metamethod).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are not valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>int lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgeti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the table at the given index.\nThe access is raw,\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgetp\"><code>lua_rawgetp</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the table at the given index and\n<code>k</code> is the pointer <code>p</code> represented as a light userdata.\nThe access is raw;\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawlen\"><code>lua_rawlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>size_t lua_rawlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the raw \"length\" of the value at the given index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>')\nwith no metamethods;\nfor userdata, this is the size of the block of memory allocated\nfor the userdata;\nfor other values, it is&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nDoes the equivalent of <code>t[i] = v</code>,\nwhere <code>t</code> is the table at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke the <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawsetp\"><code>lua_rawsetp</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nDoes the equivalent of <code>t[p] = v</code>,\nwhere <code>t</code> is the table at the given index,\n<code>p</code> is encoded as a light userdata,\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time it needs another piece of the chunk,\n<a href=\"#lua_load\"><code>lua_load</code></a> calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>\n\n<p>\nSets the C&nbsp;function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index\nwithout shifting any element\n(therefore replacing the value at that given index),\nand then pops the top element.\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>int lua_resume (lua_State *L, lua_State *from, int nargs);</pre>\n\n<p>\nStarts and resumes a coroutine in the given thread <code>L</code>.\n\n\n<p>\nTo start a coroutine,\nyou push onto the thread stack the main function plus any arguments;\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>nargs</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns, the stack contains all values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nor all values returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\n\n\n<p>\nIn case of errors,\nthe stack is not unwound,\nso you can use the debug API over it.\nThe error object is on the top of the stack.\n\n\n<p>\nTo resume a coroutine,\nyou remove any results from the last <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nput on its stack only the values to\nbe passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nThe parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.\nIf there is no such coroutine,\nthis parameter can be <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_rotate\"><code>lua_rotate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_rotate (lua_State *L, int idx, int n);</pre>\n\n<p>\nRotates the stack elements between the valid index <code>idx</code>\nand the top of the stack.\nThe elements are rotated <code>n</code> positions in the direction of the top,\nfor a positive <code>n</code>,\nor <code>-n</code> positions in the direction of the bottom,\nfor a negative <code>n</code>.\nThe absolute value of <code>n</code> must not be greater than the size\nof the slice being rotated.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_seti\"><code>lua_seti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_seti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nDoes the equivalent to <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and\nsets it as the new metatable for the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index,\n<code>v</code> is the value at the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is larger than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_setuservalue\"><code>lua_setuservalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setuservalue (lua_State *L, int index);</pre>\n\n<p>\nPops a value from the stack and sets it as\nthe new value associated to the full userdata at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nAn opaque structure that points to a thread and indirectly\n(through the thread) to the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is accessible through this structure.\n\n\n<p>\nA pointer to this structure must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be 0 (<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>) for a normal thread,\nan error code if the thread finished the execution\nof a <a href=\"#lua_resume\"><code>lua_resume</code></a> with an error,\nor <a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n<p>\nYou can only call functions in threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>.\nYou can resume threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>\n(to start a new coroutine) or <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a>\n(to resume a coroutine).\n\n\n\n\n\n<hr><h3><a name=\"lua_stringtonumber\"><code>lua_stringtonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>size_t lua_stringtonumber (lua_State *L, const char *s);</pre>\n\n<p>\nConverts the zero-terminated string <code>s</code> to a number,\npushes that number into the stack,\nand returns the total size of the string,\nthat is, its length plus one.\nThe conversion can result in an integer or a float,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\nThe string may have leading and trailing spaces and a sign.\nIf the string is not a valid numeral,\nreturns 0 and pushes nothing.\n(Note that the result can be used as a boolean,\ntrue if the conversion succeeds.)\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns true for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns false.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tointegerx\"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointegerx\"><code>lua_tointegerx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be an integer,\nor a number or string convertible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <code>lua_tointegerx</code> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <code>lua_tolstring</code> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <code>lua_tolstring</code> is applied to keys during a table traversal.)\n\n\n<p>\n<code>lua_tolstring</code> returns a pointer\nto a string inside the Lua state.\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\n\n\n<p>\nBecause Lua has garbage collection,\nthere is no guarantee that the pointer returned by <code>lua_tolstring</code>\nwill be valid after the corresponding Lua value is removed from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumberx\"><code>lua_tonumberx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, or a function;\notherwise, <code>lua_topointer</code> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for hashing and debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index is a full userdata,\nreturns its block address.\nIf the value is a light userdata,\nreturns its pointer.\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given valid index,\nor <code>LUA_TNONE</code> for a non-valid (but acceptable) index.\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<a name=\"pdf-LUA_TNIL\"><code>LUA_TNIL</code></a> (0),\n<a name=\"pdf-LUA_TNUMBER\"><code>LUA_TNUMBER</code></a>,\n<a name=\"pdf-LUA_TBOOLEAN\"><code>LUA_TBOOLEAN</code></a>,\n<a name=\"pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>,\n<a name=\"pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>,\n<a name=\"pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a name=\"pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>,\n<a name=\"pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a>,\nand\n<a name=\"pdf-LUA_TLIGHTUSERDATA\"><code>LUA_TLIGHTUSERDATA</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *lua_typename (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Unsigned\"><code>lua_Unsigned</code></a></h3>\n<pre>typedef ... lua_Unsigned;</pre>\n\n<p>\nThe unsigned version of <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_upvalueindex (int i);</pre>\n\n<p>\nReturns the pseudo-index that represents the <code>i</code>-th upvalue of\nthe running function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_version\"><code>lua_version</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const lua_Number *lua_version (lua_State *L);</pre>\n\n<p>\nReturns the address of the version number\n(a C static variable)\nstored in the Lua core.\nWhen called with a valid <a href=\"#lua_State\"><code>lua_State</code></a>,\nreturns the address of the version used to create that state.\nWhen called with <code>NULL</code>,\nreturns the address of the version running the call.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time it produces another piece of chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>data</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the same state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yield (lua_State *L, int nresults);</pre>\n\n<p>\nThis function is equivalent to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nbut it has no continuation (see <a href=\"#4.7\">&sect;4.7</a>).\nTherefore, when the thread resumes,\nit continues the function that called\nthe function calling <code>lua_yield</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yieldk\"><code>lua_yieldk</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yieldk (lua_State *L,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nYields a coroutine (thread).\n\n\n<p>\nWhen a C&nbsp;function calls <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat will be passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nWhen the coroutine is resumed again,\nLua calls the given continuation function <code>k</code> to continue\nthe execution of the C&nbsp;function that yielded (see <a href=\"#4.7\">&sect;4.7</a>).\nThis continuation function receives the same stack\nfrom the previous function,\nwith the <code>n</code> results removed and\nreplaced by the arguments passed to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\nMoreover,\nthe continuation function receives the value <code>ctx</code>\nthat was passed to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>.\n\n\n<p>\nUsually, this function does not return;\nwhen the coroutine eventually resumes,\nit continues executing the continuation function.\nHowever, there is one special case,\nwhich is when this function is called\nfrom inside a line or a count hook (see <a href=\"#4.9\">&sect;4.9</a>).\nIn that case, <code>lua_yieldk</code> should be called with no continuation\n(probably in the form of <a href=\"#lua_yield\"><code>lua_yield</code></a>) and no results,\nand the hook should return immediately after the call.\nLua will yield and,\nwhen the coroutine resumes again,\nit will continue the normal execution\nof the (Lua) function that triggered the hook.\n\n\n<p>\nThis function can raise an error if it is called from a thread\nwith a pending C call with no continuation function,\nor it is called from a thread that is not running inside a resume\n(e.g., the main thread).\n\n\n\n\n\n\n\n<h2>4.9 &ndash; <a name=\"4.9\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  int currentline;            /* (l) */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  unsigned char nups;         /* (u) number of upvalues */\n  unsigned char nparams;      /* (u) number of parameters */\n  char isvararg;              /* (u) */\n  char istailcall;            /* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about a function or an activation record.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\ncall <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>: </b>\nthe name of the chunk that created the function.\nIf <code>source</code> starts with a '<code>@</code>',\nit means that the function was defined in a file where\nthe file name follows the '<code>@</code>'.\nIf <code>source</code> starts with a '<code>=</code>',\nthe remainder of its contents describe the source in a user-dependent manner.\nOtherwise,\nthe function was defined in a string where\n<code>source</code> is that string.\n</li>\n\n<li><b><code>short_src</code>: </b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>: </b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>: </b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>: </b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk.\n</li>\n\n<li><b><code>currentline</code>: </b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>: </b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>: </b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>istailcall</code>: </b>\ntrue if this function invocation was called by a tail call.\nIn this case, the caller of this level is not in the stack.\n</li>\n\n<li><b><code>nups</code>: </b>\nthe number of upvalues of the function.\n</li>\n\n<li><b><code>nparams</code>: </b>\nthe number of fixed parameters of the function\n(always 0&nbsp;for C&nbsp;functions).\n</li>\n\n<li><b><code>isvararg</code>: </b>\ntrue if the function is a vararg function\n(always true for C&nbsp;functions).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>e</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nGets information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function from the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getglobal(L, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>': </b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;\n</li>\n\n<li><b>'<code>u</code>': </b> fills in the fields\n<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;\n</li>\n\n<li><b>'<code>f</code>': </b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>': </b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n\n\n<p>\nIf this option is given together with option '<code>f</code>',\nits table is pushed after the function.\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 on error\n(for instance, an invalid option in <code>what</code>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable of\na given activation record or a given function.\n\n\n<p>\nIn the first case,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect;\nsee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for details about variable indices\nand names.\n\n\n<p>\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nIn the second case, <code>ar</code> must be <code>NULL</code> and the function\nto be inspected must be at the top of the stack.\nIn this case, only parameters of Lua functions are visible\n(as there is no information about what variables are active)\nand no values are pushed onto the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGets information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>\n(except for tail calls, which do not count on the stack).\nWhen there are no errors, <a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 1;\nwhen called with a level greater than the stack depth,\nit returns 0.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about the <code>n</code>-th upvalue\nof the closure at index <code>funcindex</code>.\nIt pushes the upvalue's value onto the stack\nand returns its name.\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n\n\n<p>\nUpvalues have no particular order,\nas they are active through the whole function.\nThey are numbered in an arbitrary order.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILCALL\"><code>LUA_HOOKTAILCALL</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nFor call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,\nthe normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;\nin this case, there will be no corresponding return event.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n<p>\nHook functions cannot have continuations,\nthat is, they cannot call <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>, or <a href=\"#lua_callk\"><code>lua_callk</code></a> with a non-null <code>k</code>.\n\n\n<p>\nHook functions can yield under the following conditions:\nOnly count and line events can yield;\nto yield, a hook function must finish its execution\ncalling <a href=\"#lua_yield\"><code>lua_yield</code></a> with <code>nresults</code> equal to zero\n(that is, with no values).\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise OR of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook: </b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function,\nbefore the function gets its arguments.\n</li>\n\n<li><b>The return hook: </b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\nThere is no standard way to access the values\nto be returned by the function.\n</li>\n\n<li><b>The line hook: </b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n<li><b>The count hook: </b> is called after the interpreter executes every\n<code>count</code> instructions.\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n</ul>\n\n<p>\nA hook is disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nIt assigns the value at the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n<p>\nParameters <code>ar</code> and <code>n</code> are as in function <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value at the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueid\"><code>lua_upvalueid</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nReturns a unique identifier for the upvalue numbered <code>n</code>\nfrom the closure at index <code>funcindex</code>.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>,\nbut <code>n</code> cannot be greater than the number of upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvaluejoin\"><code>lua_upvaluejoin</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,\n                                    int funcindex2, int n2);</pre>\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.\n\n\n\n\n\n\n\n<h1>5 &ndash; <a name=\"5\">The Auxiliary Library</a></h1>\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all\ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions and types from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with that API.\nNevertheless, the use of the auxiliary library ensures\nmore consistency to your code.\n\n\n<p>\nSeveral functions in the auxiliary library use internally some\nextra stack slots.\nWhen a function in the auxiliary library uses less than five slots,\nit does not check the stack size;\nit simply assumes that there are enough slots.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n<p>\nFunctions called <code>luaL_check*</code>\nalways raise an error if the check is not satisfied.\n\n\n\n<h2>5.1 &ndash; <a name=\"5.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the byte <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>)\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +?, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value at the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int arg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf it is not, raises an error with a standard message (see <a href=\"#luaL_argerror\"><code>luaL_argerror</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre>\n\n<p>\nRaises an error reporting a problem with argument <code>arg</code>\nof the C&nbsp;function that called it,\nusing a standard message\nthat includes <code>extramsg</code> as a comment:\n\n<pre>\n     bad argument #<em>arg</em> to '<em>funcname</em>' (<em>extramsg</em>)\n</pre><p>\nThis function never returns.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nFinish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nIf you know beforehand the total size of the resulting string,\nyou can use the buffer like this:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it and preallocate a space of\nsize <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>\n\n<li>Then copy the string into that space.</li>\n\n<li>\nFinish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,\nwhere <code>sz</code> is the total size of the resulting string\ncopied into that space.\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a> the stack is back to its\nlevel when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>.\nThis function does not allocate any space;\nthe buffer must be declared as a variable\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinitsize\"><code>luaL_buffinitsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence\n<a href=\"#luaL_buffinit\"><code>luaL_buffinit</code></a>, <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field passing the object as its only argument.\nIn this case this function returns true and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns false (without pushing any value on the stack).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>arg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is an integer\n(or can be converted to an integer)\nand returns this integer cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills <code>*l</code>\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a number\nand returns this number.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int arg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>arg</code> or when this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message\n(or <code>NULL</code> for no additional text).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int arg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>) and\nreturns the userdata address (see <a href=\"#lua_touserdata\"><code>lua_touserdata</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkversion\"><code>luaL_checkversion</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkversion (lua_State *L);</pre>\n\n<p>\nChecks whether the core running the call,\nthe core that created the Lua state,\nand the code making the call are all using the same version of Lua.\nAlso checks whether the core running the call\nand the core that created the Lua state\nare using the same address space.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>e</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, &ndash;]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_execresult\"><code>luaL_execresult</code></a></h3><p>\n<span class=\"apii\">[-0, +3, <em>m</em>]</span>\n<pre>int luaL_execresult (lua_State *L, int stat);</pre>\n\n<p>\nThis function produces the return values for\nprocess-related functions in the standard library\n(<a href=\"#pdf-os.execute\"><code>os.execute</code></a> and <a href=\"#pdf-io.close\"><code>io.close</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_fileresult\"><code>luaL_fileresult</code></a></h3><p>\n<span class=\"apii\">[-0, +(1|3), <em>m</em>]</span>\n<pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre>\n\n<p>\nThis function produces the return values for\nfile-related functions in the standard library\n(<a href=\"#pdf-io.open\"><code>io.open</code></a>, <a href=\"#pdf-os.rename\"><code>os.rename</code></a>, <a href=\"#pdf-file:seek\"><code>file:seek</code></a>, etc.).\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code> and returns the type of pushed value.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\npushes nothing and returns <code>LUA_TNIL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>)\n(<b>nil</b> if there is no metatable associated with that name).\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getsubtable\"><code>luaL_getsubtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre>\n\n<p>\nEnsures that the value <code>t[fname]</code>,\nwhere <code>t</code> is the value at index <code>idx</code>,\nis a table,\nand pushes that table onto the stack.\nReturns true if it finds a previous table there\nand false if it creates a new table.\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code> by replacing\nany occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_len\"><code>luaL_len</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>lua_Integer luaL_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given index\nas a number;\nit is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nRaises an error if the result of the operation is not an integer.\n(This case only can happen through metamethods.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadbufferx\"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbufferx\"><code>luaL_loadbufferx</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbufferx (lua_State *L,\n                      const char *buff,\n                      size_t sz,\n                      const char *name,\n                      const char *mode);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadfilex\"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfilex\"><code>luaL_loadfilex</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfilex (lua_State *L, const char *filename,\n                                            const char *mode);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>,\nbut it has an extra error code <a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>\nfor file-related errors\n(e.g., it cannot open or read the file).\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlib\"><code>luaL_newlib</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlib (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table and registers there\nthe functions in list <code>l</code>.\n\n\n<p>\nIt is implemented as the following macro:\n\n<pre>\n     (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n</pre><p>\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlibtable\"><code>luaL_newlibtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table with a size optimized\nto store all entries in the array <code>l</code>\n(but does not actually store them).\nIt is intended to be used in conjunction with <a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>\n(see <a href=\"#luaL_newlib\"><code>luaL_newlib</code></a>).\n\n\n<p>\nIt is implemented as a macro.\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds to this new table the pair <code>__name = tname</code>,\nadds to the registry the pair <code>[tname] = new table</code>,\nand returns 1.\n(The entry <code>__name</code> is used by some error-reporting functions.)\n\n\n<p>\nIn both cases pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C <code>realloc</code> function\nand then sets a panic function (see <a href=\"#4.6\">&sect;4.6</a>) that prints\nan error message to the standard error output in case of fatal\nerrors.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_opt\"><code>luaL_opt</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>T luaL_opt (L, func, arg, dflt);</pre>\n\n<p>\nThis macro is defined as follows:\n\n<pre>\n     (lua_isnoneornil(L,(arg)) ? (dflt) : func(L,(arg)))\n</pre><p>\nIn words, if the argument <code>arg</code> is nil or absent,\nthe macro results in the default <code>dflt</code>.\nOtherwise, it results in the result of calling <code>func</code>\nwith the state <code>L</code> and the argument index <code>arg</code> as\nparameters.\nNote that it evaluates the expression <code>dflt</code> only if needed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int arg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is an integer\n(or convertible to an integer),\nreturns this integer.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int arg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills the position <code>*l</code> with the result's length.\nIf the result is <code>NULL</code>\n(only possible when returning <code>d</code> and <code>d == NULL</code>),\nits length is considered zero.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a number,\nreturns this number.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int arg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>\nwith the predefined size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nReturns an address to a space of size <code>sz</code>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add\nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresultsize\"><code>luaL_pushresultsize</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence <a href=\"#luaL_addsize\"><code>luaL_addsize</code></a>, <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object at the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nFunction <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference and its associated object.\n\n\n<p>\nIf the object at the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with a sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_requiref\"><code>luaL_requiref</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void luaL_requiref (lua_State *L, const char *modname,\n                    lua_CFunction openf, int glb);</pre>\n\n<p>\nIf <code>modname</code> is not already present in <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a>,\ncalls function <code>openf</code> with string <code>modname</code> as an argument\nand sets the call result in <code>package.loaded[modname]</code>,\nas if that function has been called through <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n<p>\nIf <code>glb</code> is true,\nalso stores the module into global <code>modname</code>.\n\n\n<p>\nLeaves a copy of the module on the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setfuncs\"><code>luaL_setfuncs</code></a></h3><p>\n<span class=\"apii\">[-nup, +0, <em>m</em>]</span>\n<pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>\n\n<p>\nRegisters all functions in the array <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack\n(below optional upvalues, see next).\n\n\n<p>\nWhen <code>nup</code> is not zero,\nall functions are created sharing <code>nup</code> upvalues,\nwhich must be previously pushed on the stack\non top of the library table.\nThese values are popped from the stack after the registration.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setmetatable\"><code>luaL_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nSets the metatable of the object at the top of the stack\nas the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_Stream\"><code>luaL_Stream</code></a></h3>\n<pre>typedef struct luaL_Stream {\n  FILE *f;\n  lua_CFunction closef;\n} luaL_Stream;</pre>\n\n<p>\nThe standard representation for file handles,\nwhich is used by the standard I/O library.\n\n\n<p>\nA file handle is implemented as a full userdata,\nwith a metatable called <code>LUA_FILEHANDLE</code>\n(where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).\nThe metatable is created by the I/O library\n(see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n<p>\nThis userdata must start with the structure <code>luaL_Stream</code>;\nit can contain other data after this initial structure.\nField <code>f</code> points to the corresponding C stream\n(or it can be <code>NULL</code> to indicate an incompletely created handle).\nField <code>closef</code> points to a Lua function\nthat will be called to close the stream\nwhen the handle is closed or collected;\nthis function receives the file handle as its sole argument and\nmust return either <b>true</b> (in case of success)\nor <b>nil</b> plus an error message (in case of error).\nOnce Lua calls this field,\nit changes the field value to <code>NULL</code>\nto signal that the handle is closed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_testudata\"><code>luaL_testudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nThis function works like <a href=\"#luaL_checkudata\"><code>luaL_checkudata</code></a>,\nexcept that, when the test fails,\nit returns <code>NULL</code> instead of raising an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_tolstring\"><code>luaL_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre>\n\n<p>\nConverts any Lua value at the given index to a C&nbsp;string\nin a reasonable format.\nThe resulting string is pushed onto the stack and also\nreturned by the function.\nIf <code>len</code> is not <code>NULL</code>,\nthe function also sets <code>*len</code> with the string length.\n\n\n<p>\nIf the value has a metatable with a <code>__tostring</code> field,\nthen <code>luaL_tolstring</code> calls the corresponding metamethod\nwith the value as argument,\nand uses the result of the call as its result.\n\n\n\n\n\n<hr><h3><a name=\"luaL_traceback\"><code>luaL_traceback</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n                     int level);</pre>\n\n<p>\nCreates and pushes a traceback of the stack <code>L1</code>.\nIf <code>msg</code> is not <code>NULL</code> it is appended\nat the beginning of the traceback.\nThe <code>level</code> parameter tells at which level\nto start the traceback.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>6 &ndash; <a name=\"6\">Standard Libraries</a></h1>\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented directly through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to \"outside\" services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut are quite useful or have critical performance requirements that\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library (<a href=\"#6.1\">&sect;6.1</a>);</li>\n\n<li>coroutine library (<a href=\"#6.2\">&sect;6.2</a>);</li>\n\n<li>package library (<a href=\"#6.3\">&sect;6.3</a>);</li>\n\n<li>string manipulation (<a href=\"#6.4\">&sect;6.4</a>);</li>\n\n<li>basic UTF-8 support (<a href=\"#6.5\">&sect;6.5</a>);</li>\n\n<li>table manipulation (<a href=\"#6.6\">&sect;6.6</a>);</li>\n\n<li>mathematical functions (<a href=\"#6.7\">&sect;6.7</a>) (sin, log, etc.);</li>\n\n<li>input and output (<a href=\"#6.8\">&sect;6.8</a>);</li>\n\n<li>operating system facilities (<a href=\"#6.9\">&sect;6.9</a>);</li>\n\n<li>debug facilities (<a href=\"#6.10\">&sect;6.10</a>).</li>\n\n</ul><p>\nExcept for the basic and the package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nthe host program can open them individually by using\n<a href=\"#luaL_requiref\"><code>luaL_requiref</code></a> to call\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_coroutine\"><code>luaopen_coroutine</code></a> (for the coroutine library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_utf8\"><code>luaopen_utf8</code></a> (for the UTF8 library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the operating system library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>.\n\n\n\n<h2>6.1 &ndash; <a name=\"6.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide\nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\n\n\n<p>\nCalls <a href=\"#pdf-error\"><code>error</code></a> if\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\nIn case of error,\n<code>message</code> is the error object;\nwhen absent, it defaults to \"<code>assertion failed!</code>\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage ([opt [, arg]])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"<code>collect</code>\": </b>\nperforms a full garbage-collection cycle.\nThis is the default option.\n</li>\n\n<li><b>\"<code>stop</code>\": </b>\nstops automatic execution of the garbage collector.\nThe collector will run only when explicitly invoked,\nuntil a call to restart it.\n</li>\n\n<li><b>\"<code>restart</code>\": </b>\nrestarts automatic execution of the garbage collector.\n</li>\n\n<li><b>\"<code>count</code>\": </b>\nreturns the total memory in use by Lua in Kbytes.\nThe value has a fractional part,\nso that it multiplied by 1024\ngives the exact number of bytes in use by Lua\n(except for overflows).\n</li>\n\n<li><b>\"<code>step</code>\": </b>\nperforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>.\nWith a zero value,\nthe collector will perform one basic (indivisible) step.\nFor non-zero values,\nthe collector will perform as if that amount of memory\n(in KBytes) had been allocated by Lua.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"<code>setpause</code>\": </b>\nsets <code>arg</code> as the new value for the <em>pause</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>pause</em>.\n</li>\n\n<li><b>\"<code>setstepmul</code>\": </b>\nsets <code>arg</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>step</em>.\n</li>\n\n<li><b>\"<code>isrunning</code>\": </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile ([filename])</code></a></h3>\nOpens the named file and executes its contents as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller (that is, <code>dofile</code> does not run in protected mode).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nTerminates the last protected function called\nand returns <code>message</code> as the error object.\nFunction <code>error</code> never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message, if the message is a string.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (see <a href=\"#2.2\">&sect;2.2</a>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice versa.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>__metatable</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values (an iterator function, the table <code>t</code>, and 0)\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the key&ndash;value pairs\n(<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,\nup to the first nil value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>\n\n\n<p>\nLoads a chunk.\n\n\n<p>\nIf <code>chunk</code> is a string, the chunk is this string.\nIf <code>chunk</code> is a function,\n<code>load</code> calls it repeatedly to get the chunk pieces.\nEach call to <code>chunk</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no syntactic errors,\nreturns the compiled chunk as a function;\notherwise, returns <b>nil</b> plus the error message.\n\n\n<p>\nIf the resulting function has upvalues,\nthe first upvalue is set to the value of <code>env</code>,\nif that parameter is given,\nor to the value of the global environment.\nOther upvalues are initialized with <b>nil</b>.\n(When you load a main chunk,\nthe resulting function will always have exactly one upvalue,\nthe <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nHowever,\nwhen you load a binary chunk created from a function (see <a href=\"#pdf-string.dump\"><code>string.dump</code></a>),\nthe resulting function can have an arbitrary number of upvalues.)\nAll upvalues are fresh, that is,\nthey are not shared with any other function.\n\n\n<p>\n<code>chunkname</code> is used as the name of the chunk for error messages\nand debug information (see <a href=\"#4.9\">&sect;4.9</a>).\nWhen absent,\nit defaults to <code>chunk</code>, if <code>chunk</code> is a string,\nor to \"<code>=(load)</code>\" otherwise.\n\n\n<p>\nThe string <code>mode</code> controls whether the chunk can be text or binary\n(that is, a precompiled chunk).\nIt may be the string \"<code>b</code>\" (only binary chunks),\n\"<code>t</code>\" (only text chunks),\nor \"<code>bt</code>\" (both binary and text).\nThe default is \"<code>bt</code>\".\n\n\n<p>\nLua does not check the consistency of binary chunks.\nMaliciously crafted binary chunks can crash\nthe interpreter.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\n<code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numerical order,\nuse a numerical <b>for</b>.)\n\n\n<p>\nThe behavior of <code>next</code> is undefined if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may clear existing fields.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nIf <code>t</code> has a metamethod <code>__pairs</code>,\ncalls it with <code>t</code> as argument and returns the first three\nresults from the call.\n\n\n<p>\nOtherwise,\nreturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCalls function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments\nand prints their values to <code>stdout</code>,\nusing the <a href=\"#pdf-tostring\"><code>tostring</code></a> function to convert each argument to a string.\n<code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\nfor instance for debugging.\nFor complete control over the output,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a> and <a href=\"#pdf-io.write\"><code>io.write</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking the <code>__eq</code> metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout invoking the <code>__index</code> metamethod.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawlen\"><code>rawlen (v)</code></a></h3>\nReturns the length of the object <code>v</code>,\nwhich must be a table or a string,\nwithout invoking the <code>__len</code> metamethod.\nReturns an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout invoking the <code>__newindex</code> metamethod.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b> and NaN,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>;\na negative number indexes from the end (-1 is the last argument).\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\n(To change the metatable of other types from Lua code,\nyou must use the debug library (<a href=\"#6.10\">&sect;6.10</a>).)\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>__metatable</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\n\n\n<p>\nWhen called with no <code>base</code>,\n<code>tonumber</code> tries to convert its argument to a number.\nIf the argument is already a number or\na string convertible to a number,\nthen <code>tonumber</code> returns this number;\notherwise, it returns <b>nil</b>.\n\n\n<p>\nThe conversion of strings can result in integers or floats,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\n(The string may have leading and trailing spaces and a sign.)\n\n\n<p>\nWhen called with <code>base</code>,\nthen <code>e</code> must be a string to be interpreted as\nan integer numeral in that base.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIf the string <code>e</code> is not a valid numeral in the given base,\nthe function returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (v)</code></a></h3>\nReceives a value of any type and\nconverts it to a string in a human-readable format.\n(For complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.)\n\n\n<p>\nIf the metatable of <code>v</code> has a <code>__tostring</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>v</code> as argument,\nand uses the result of the call as its result.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\n\n\n<p>\nA global variable (not a function) that\nholds a string containing the running Lua version.\nThe current value of this variable is \"<code>Lua 5.3</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that it sets a new message handler <code>msgh</code>.\n\n\n\n\n\n\n\n<h2>6.2 &ndash; <a name=\"6.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThis library comprises the operations to manipulate coroutines,\nwhich come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.6\">&sect;2.6</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.isyieldable\"><code>coroutine.isyieldable ()</code></a></h3>\n\n\n<p>\nReturns true when the running coroutine can yield.\n\n\n<p>\nA running coroutine is yieldable if it is not the main thread and\nit is not inside a non-yieldable C&nbsp;function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, ... are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, ... are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(when the coroutine yields) or any values returned by the body function\n(when the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine plus a boolean,\ntrue when the running coroutine is the main one.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running (that is, it called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to the function behave as the\nextra arguments to <code>resume</code>.\nReturns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error, propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>6.3 &ndash; <a name=\"6.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading modules in Lua.\nIt exports one function directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a>.\nEverything else is exported in a table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a> sequence.\nBy changing this sequence,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which must be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with two arguments:\n<code>modname</code> and an extra value dependent on how it got the loader.\n(If the loader came from a file,\nthis extra value is the file name.)\nIf the loader returns any non-nil value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader does not return a non-nil value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> raises an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.config\"><code>package.config</code></a></h3>\n\n\n<p>\nA string describing some compile-time configurations for packages.\nThis string is a sequence of lines:\n\n<ul>\n\n<li>The first line is the directory separator string.\nDefault is '<code>\\</code>' for Windows and '<code>/</code>' for all other systems.</li>\n\n<li>The second line is the character that separates templates in a path.\nDefault is '<code>;</code>'.</li>\n\n<li>The third line is the string that marks the\nsubstitution points in a template.\nDefault is '<code>?</code>'.</li>\n\n<li>The fourth line is a string that, in a path in Windows,\nis replaced by the executable's directory.\nDefault is '<code>!</code>'.</li>\n\n<li>The fifth line is a mark to ignore all text after it\nwhen building the <code>luaopen_</code> function name.\nDefault is '<code>-</code>'.</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH_5_3\"><code>LUA_CPATH_5_3</code></a>,\nor the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>,\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\n\n\n<p>\nIf <code>funcname</code> is \"<code>*</code>\",\nthen it only links with the library,\nmaking the symbols exported by the library\navailable to other dynamically linked libraries.\nOtherwise,\nit looks for a function <code>funcname</code> inside the library\nand returns this function as a C&nbsp;function.\nSo, <code>funcname</code> must follow the <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a> prototype\n(see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and an extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by Standard&nbsp;C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH_5_3\"><code>LUA_PATH_5_3</code></a> or\nthe environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif those environment variables are not defined.\nAny \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchers\"><code>package.searchers</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to load modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole parameter.\nThe function can return another function (the module <em>loader</em>)\nplus an extra value that will be passed to that loader,\nor a string explaining why it did not find that module\n(or <b>nil</b> if it has nothing to say).\n\n\n<p>\nLua initializes this table with four searcher functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nThe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nAgain,\nthe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits suffix after (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.b.c-v2.1</code>,\nthe function name will be <code>luaopen_a_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n<p>\nAll searchers except the first one (preload) return as the extra value\nthe file name where the module was found,\nas returned by <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nThe first searcher returns no extra value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchpath\"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3>\n\n\n<p>\nSearches for the given <code>name</code> in the given <code>path</code>.\n\n\n<p>\nA path is a string containing a sequence of\n<em>templates</em> separated by semicolons.\nFor each template,\nthe function replaces each interrogation mark (if any)\nin the template with a copy of <code>name</code>\nwherein all occurrences of <code>sep</code>\n(a dot, by default)\nwere replaced by <code>rep</code>\n(the system's directory separator, by default),\nand then tries to open the resulting file name.\n\n\n<p>\nFor instance, if the path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for the name <code>foo.a</code>\nwill try to open the files\n<code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and\n<code>/usr/local/foo/a/init.lua</code>, in that order.\n\n\n<p>\nReturns the resulting name of the first file that it can\nopen in read mode (after closing the file),\nor <b>nil</b> plus an error message if none succeeds.\n(This error message lists all file names it tried to open.)\n\n\n\n\n\n\n\n<h2>6.4 &ndash; <a name=\"6.4\">String Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s,i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numeric codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, ..., <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\nThese indices are corrected\nfollowing the same rules of function <a href=\"#pdf-string.sub\"><code>string.sub</code></a>.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numeric code equal\nto its corresponding argument.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function [, strip])</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation\n(a <em>binary chunk</em>)\nof the given function,\nso that a later <a href=\"#pdf-load\"><code>load</code></a> on this string returns\na copy of the function (but with new upvalues).\nIf <code>strip</code> is a true value,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nFunctions with upvalues have only their number of upvalues saved.\nWhen (re)loaded,\nthose upvalues receive fresh instances containing <b>nil</b>.\n(You can use the debug library to serialize\nand reload the upvalues of a function\nin a way adequate to your needs.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\n\n\n<p>\nLooks for the first match of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>nil</b>.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered magic.\nNote that if <code>plain</code> is given, then <code>init</code> must be given as well.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument (which must be a string).\nThe format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.\nThe only differences are that the options/modifiers\n<code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>,\nand <code>p</code> are not supported\nand that there is an extra option, <code>q</code>.\n\n\n<p>\nThe <code>q</code> option formats a string between double quotes,\nusing escape sequences when necessary to ensure that\nit can safely be read back by the Lua interpreter.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nmay produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre>\n\n<p>\nOptions\n<code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>G</code>, and <code>g</code> all expect a number as argument.\nOptions <code>c</code>, <code>d</code>,\n<code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>\nexpect an integer.\nWhen Lua is compiled with a C89 compiler,\noptions <code>A</code> and <code>a</code> (hexadecimal floats)\ndo not support any modifier (flags, width, length).\n\n\n<p>\nOption <code>s</code> expects a string;\nif its argument is not a string,\nit is converted to one following the same rules of <a href=\"#pdf-tostring\"><code>tostring</code></a>.\nIf the option has any modifier (flags, width, length),\nthe string argument should not contain embedded zeros.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern)</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>)\nover the string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\n\n\n<p>\nAs an example, the following loop\nwill iterate over all the words from string <code>s</code>,\nprinting one per line:\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a caret '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\nThe name <code>gsub</code> comes from <em>Global SUBstitution</em>.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>d</em></code>,\nwith <em>d</em> between 1 and 9,\nstands for the value of the <em>d</em>-th captured substring.\nThe sequence <code>%0</code> stands for the whole match.\nThe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order.\n\n\n<p>\nIn any case,\nif the pattern specifies no captures,\nthen it behaves as if the whole pattern was inside a capture.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return load(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.3\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.3.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\nLooks for the first <em>match</em> of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>nil</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.pack\"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.\npacked (that is, serialized in binary form)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.packsize\"><code>string.packsize (fmt)</code></a></h3>\n\n\n<p>\nReturns the size of a string resulting from <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nwith the given format.\nThe format string cannot have the variable-length options\n'<code>s</code>' or '<code>z</code>' (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n [, sep])</code></a></h3>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code> separated by the string <code>sep</code>.\nThe default value for <code>sep</code> is the empty string\n(that is, no separator).\nReturns the empty string if <code>n</code> is not positive.\n\n\n<p>\n(Note that it is very easy to exhaust the memory of your machine\nwith a single call to this function.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> (for a positive <code>i</code>)\nreturns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n<p>\nIf, after the translation of negative indices,\n<code>i</code> is less than 1,\nit is corrected to 1.\nIf <code>j</code> is greater than the string length,\nit is corrected to that length.\nIf, after these corrections,\n<code>i</code> is greater than <code>j</code>,\nthe function returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.unpack\"><code>string.unpack (fmt, s [, pos])</code></a></h3>\n\n\n<p>\nReturns the values packed in string <code>s</code> (see <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\nAn optional <code>pos</code> marks where\nto start reading in <code>s</code> (default is 1).\nAfter the read values,\nthis function also returns the index of the first unread byte in <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n\n\n<h3>6.4.1 &ndash; <a name=\"6.4.1\">Patterns</a></h3>\n\n<p>\nPatterns in Lua are described by regular strings,\nwhich are interpreted as patterns by the pattern-matching functions\n<a href=\"#pdf-string.find\"><code>string.find</code></a>,\n<a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>,\n<a href=\"#pdf-string.gsub\"><code>string.gsub</code></a>,\nand <a href=\"#pdf-string.match\"><code>string.match</code></a>.\nThis section describes the syntax and the meaning\n(that is, what they match) of these strings.\n\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>: </b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>: </b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>: </b> represents all letters.</li>\n\n<li><b><code>%c</code>: </b> represents all control characters.</li>\n\n<li><b><code>%d</code>: </b> represents all digits.</li>\n\n<li><b><code>%g</code>: </b> represents all printable characters except space.</li>\n\n<li><b><code>%l</code>: </b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>: </b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>: </b> represents all space characters.</li>\n\n<li><b><code>%u</code>: </b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>\n\n<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny non-alphanumeric character\n(including all punctuation characters, even the non-magical)\ncan be preceded by a '<code>%</code>'\nwhen used to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>: </b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range,\nin ascending order, with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nYou can put a closing square bracket in a set\nby positioning it as the first character in the set.\nYou can put an hyphen in a set\nby positioning it as the first or the last character in the set.\n(You can also use an escape for both cases.)\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>: </b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches zero or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches one or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches zero or more repetitions of characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the shortest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches zero or one occurrence of a character in the class.\nIt always matches one occurrence if possible;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n<li>\n<code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;\nsuch item matches an empty string at any position such that\nthe next character belongs to <em>set</em>\nand the previous character does not belong to <em>set</em>.\nThe set <em>set</em> is interpreted as previously described.\nThe beginning and the end of the subject are handled as if\nthey were the character '<code>\\0</code>'.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA caret '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture (and therefore has number&nbsp;1);\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the empty capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n\n\n\n\n\n<h3>6.4.2 &ndash; <a name=\"6.4.2\">Format Strings for Pack and Unpack</a></h3>\n\n<p>\nThe first argument to <a href=\"#pdf-string.pack\"><code>string.pack</code></a>,\n<a href=\"#pdf-string.packsize\"><code>string.packsize</code></a>, and <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>\nis a format string,\nwhich describes the layout of the structure being created or read.\n\n\n<p>\nA format string is a sequence of conversion options.\nThe conversion options are as follows:\n\n<ul>\n<li><b><code>&lt;</code>: </b>sets little endian</li>\n<li><b><code>&gt;</code>: </b>sets big endian</li>\n<li><b><code>=</code>: </b>sets native endian</li>\n<li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>\n(default is native alignment)</li>\n<li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>\n<li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>\n<li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>\n<li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>\n<li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>\n<li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>\n<li><b><code>j</code>: </b>a <code>lua_Integer</code></li>\n<li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>\n<li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>\n<li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>f</code>: </b>a <code>float</code> (native size)</li>\n<li><b><code>d</code>: </b>a <code>double</code> (native size)</li>\n<li><b><code>n</code>: </b>a <code>lua_Number</code></li>\n<li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>\n<li><b><code>z</code>: </b>a zero-terminated string</li>\n<li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length\ncoded as an unsigned integer with <code>n</code> bytes\n(default is a <code>size_t</code>)</li>\n<li><b><code>x</code>: </b>one byte of padding</li>\n<li><b><code>X<em>op</em></code>: </b>an empty item that aligns\naccording to option <code>op</code>\n(which is otherwise ignored)</li>\n<li><b>'<code> </code>': </b>(empty space) ignored</li>\n</ul><p>\n(A \"<code>[<em>n</em>]</code>\" means an optional integral numeral.)\nExcept for padding, spaces, and configurations\n(options \"<code>xX &lt;=&gt;!</code>\"),\neach option corresponds to an argument (in <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\nor a result (in <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n<p>\nFor options \"<code>!<em>n</em></code>\", \"<code>s<em>n</em></code>\", \"<code>i<em>n</em></code>\", and \"<code>I<em>n</em></code>\",\n<code>n</code> can be any integer between 1 and 16.\nAll integral options check overflows;\n<a href=\"#pdf-string.pack\"><code>string.pack</code></a> checks whether the given value fits in the given size;\n<a href=\"#pdf-string.unpack\"><code>string.unpack</code></a> checks whether the read value fits in a Lua integer.\n\n\n<p>\nAny format string starts as if prefixed by \"<code>!1=</code>\",\nthat is,\nwith maximum alignment of 1 (no alignment)\nand native endianness.\n\n\n<p>\nAlignment works as follows:\nFor each option,\nthe format gets extra padding until the data starts\nat an offset that is a multiple of the minimum between the\noption size and the maximum alignment;\nthis minimum must be a power of 2.\nOptions \"<code>c</code>\" and \"<code>z</code>\" are not aligned;\noption \"<code>s</code>\" follows the alignment of its starting integer.\n\n\n<p>\nAll padding is filled with zeros by <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\n(and ignored by <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n\n\n\n\n\n<h2>6.5 &ndash; <a name=\"6.5\">UTF-8 Support</a></h2>\n\n<p>\nThis library provides basic support for UTF-8 encoding.\nIt provides all its functions inside the table <a name=\"pdf-utf8\"><code>utf8</code></a>.\nThis library does not provide any support for Unicode other\nthan the handling of the encoding.\nAny operation that needs the meaning of a character,\nsuch as character classification, is outside its scope.\n\n\n<p>\nUnless stated otherwise,\nall functions that expect a byte position as a parameter\nassume that the given position is either the start of a byte sequence\nor one plus the length of the subject string.\nAs in the string library,\nnegative indices count from the end of the string.\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.char\"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers,\nconverts each one to its corresponding UTF-8 byte sequence\nand returns a string with the concatenation of all these sequences.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.charpattern\"><code>utf8.charpattern</code></a></h3>\nThe pattern (a string, not a function) \"<code>[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*</code>\"\n(see <a href=\"#6.4.1\">&sect;6.4.1</a>),\nwhich matches exactly one UTF-8 byte sequence,\nassuming that the subject is a valid UTF-8 string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codes\"><code>utf8.codes (s)</code></a></h3>\n\n\n<p>\nReturns values so that the construction\n\n<pre>\n     for p, c in utf8.codes(s) do <em>body</em> end\n</pre><p>\nwill iterate over all characters in string <code>s</code>,\nwith <code>p</code> being the position (in bytes) and <code>c</code> the code point\nof each character.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codepoint\"><code>utf8.codepoint (s [, i [, j]])</code></a></h3>\nReturns the codepoints (as integers) from all characters in <code>s</code>\nthat start between byte position <code>i</code> and <code>j</code> (both included).\nThe default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.len\"><code>utf8.len (s [, i [, j]])</code></a></h3>\nReturns the number of UTF-8 characters in string <code>s</code>\nthat start between positions <code>i</code> and <code>j</code> (both inclusive).\nThe default for <code>i</code> is 1 and for <code>j</code> is -1.\nIf it finds any invalid byte sequence,\nreturns a false value plus the position of the first invalid byte.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.offset\"><code>utf8.offset (s, n [, i])</code></a></h3>\nReturns the position (in bytes) where the encoding of the\n<code>n</code>-th character of <code>s</code>\n(counting from position <code>i</code>) starts.\nA negative <code>n</code> gets characters before position <code>i</code>.\nThe default for <code>i</code> is 1 when <code>n</code> is non-negative\nand <code>#s + 1</code> otherwise,\nso that <code>utf8.offset(s, -n)</code> gets the offset of the\n<code>n</code>-th character from the end of the string.\nIf the specified character is neither in the subject\nnor right after its end,\nthe function returns <b>nil</b>.\n\n\n<p>\nAs a special case,\nwhen <code>n</code> is 0 the function returns the start of the encoding\nof the character that contains the <code>i</code>-th byte of <code>s</code>.\n\n\n<p>\nThis function assumes that <code>s</code> is a valid UTF-8 string.\n\n\n\n\n\n\n\n<h2>6.6 &ndash; <a name=\"6.6\">Table Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nRemember that, whenever an operation needs the length of a table,\nall caveats about the length operator apply (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nAll functions ignore non-numeric keys\nin the tables given as arguments.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>\n\n\n<p>\nGiven a list where all elements are strings or numbers,\nreturns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is <code>#list</code>.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (list, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>list</code>,\nshifting up the elements\n<code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.\nThe default value for <code>pos</code> is <code>#list+1</code>,\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof list <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.move\"><code>table.move (a1, f, e, t [,a2])</code></a></h3>\n\n\n<p>\nMoves elements from table <code>a1</code> to table <code>a2</code>,\nperforming the equivalent to the following\nmultiple assignment:\n<code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.\nThe default for <code>a2</code> is <code>a1</code>.\nThe destination range can overlap with the source range.\nThe number of elements to be moved must fit in a Lua integer.\n\n\n<p>\nReturns the destination table <code>a2</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.pack\"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a new table with all parameters stored into keys 1, 2, etc.\nand with a field \"<code>n</code>\" with the total number of parameters.\nNote that the resulting table may not be a sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (list [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>list</code> the element at position <code>pos</code>,\nreturning the value of the removed element.\nWhen <code>pos</code> is an integer between 1 and <code>#list</code>,\nit shifts down the elements\n<code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>\nand erases element <code>list[#list]</code>;\nThe index <code>pos</code> can also be 0 when <code>#list</code> is 0,\nor <code>#list + 1</code>;\nin those cases, the function erases the element <code>list[pos]</code>.\n\n\n<p>\nThe default value for <code>pos</code> is <code>#list</code>,\nso that a call <code>table.remove(l)</code> removes the last element\nof list <code>l</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (list [, comp])</code></a></h3>\n\n\n<p>\nSorts list elements in a given order, <em>in-place</em>,\nfrom <code>list[1]</code> to <code>list[#list]</code>.\nIf <code>comp</code> is given,\nthen it must be a function that receives two list elements\nand returns true when the first element must come\nbefore the second in the final order\n(so that, after the sort,\n<code>i &lt; j</code> implies <code>not comp(list[j],list[i])</code>).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nNote that the <code>comp</code> function must define\na strict partial order over the elements in the list;\nthat is, it must be asymmetric and transitive.\nOtherwise, no valid sort may be possible.\n\n\n<p>\nThe sort algorithm is not stable:\nelements considered equal by the given order\nmay have their relative positions changed by the sort.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.unpack\"><code>table.unpack (list [, i [, j]])</code></a></h3>\n\n\n<p>\nReturns the elements from the given list.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.\n\n\n\n\n\n\n\n<h2>6.7 &ndash; <a name=\"6.7\">Mathematical Functions</a></h2>\n\n<p>\nThis library provides basic mathematical functions.\nIt provides all its functions and constants inside the table <a name=\"pdf-math\"><code>math</code></a>.\nFunctions with the annotation \"<code>integer/float</code>\" give\ninteger results for integer arguments\nand float results for float (or mixed) arguments.\nRounding functions\n(<a href=\"#pdf-math.ceil\"><code>math.ceil</code></a>, <a href=\"#pdf-math.floor\"><code>math.floor</code></a>, and <a href=\"#pdf-math.modf\"><code>math.modf</code></a>)\nreturn an integer when the result fits in the range of an integer,\nor a float otherwise.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the absolute value of <code>x</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (y [, x])</code></a></h3>\n\n\n<p>\n\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both parameters to find the\nquadrant of the result.\n(It also handles correctly the case of <code>x</code> being zero.)\n\n\n<p>\nThe default value for <code>x</code> is 1,\nso that the call <code>math.atan(y)</code>\nreturns the arc tangent of <code>y</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integral value larger than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from radians to degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>\n(where <code>e</code> is the base of natural logarithms).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integral value smaller than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe float value <code>HUGE_VAL</code>,\na value larger than any other numeric value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x [, base])</code></a></h3>\n\n\n<p>\nReturns the logarithm of <code>x</code> in the given base.\nThe default for <code>base</code> is <em>e</em>\n(so that the function returns the natural logarithm of <code>x</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the maximum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.maxinteger\"><code>math.maxinteger</code></a></h3>\nAn integer with the maximum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the minimum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.mininteger\"><code>math.mininteger</code></a></h3>\nAn integer with the minimum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns the integral part of <code>x</code> and the fractional part of <code>x</code>.\nIts second result is always a float.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>&pi;</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from degrees to radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nWhen called without arguments,\nreturns a pseudo-random float with uniform distribution\nin the range  <em>[0,1)</em>.  \nWhen called with two integers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a pseudo-random integer\nwith uniform distribution in the range <em>[m, n]</em>.\n(The value <em>n-m</em> cannot be negative and must fit in a Lua integer.)\nThe call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>.\n\n\n<p>\nThis function is an interface to the underling\npseudo-random generator function provided by C.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed (x)</code></a></h3>\n\n\n<p>\nSets <code>x</code> as the \"seed\"\nfor the pseudo-random generator:\nequal seeds produce equal sequences of numbers.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tointeger\"><code>math.tointeger (x)</code></a></h3>\n\n\n<p>\nIf the value <code>x</code> is convertible to an integer,\nreturns that integer.\nOtherwise, returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.type\"><code>math.type (x)</code></a></h3>\n\n\n<p>\nReturns \"<code>integer</code>\" if <code>x</code> is an integer,\n\"<code>float</code>\" if it is a float,\nor <b>nil</b> if <code>x</code> is not a number.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ult\"><code>math.ult (m, n)</code></a></h3>\n\n\n<p>\nReturns a boolean,\ntrue if and only if integer <code>m</code> is below integer <code>n</code> when\nthey are compared as unsigned integers.\n\n\n\n\n\n\n\n<h2>6.8 &ndash; <a name=\"6.8\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file handles;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are over these default files.\nThe second style uses explicit file handles.\n\n\n<p>\nWhen using implicit file handles,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file handles,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file handle\nand then all operations are supplied as methods of the file handle.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file handles with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>nil</b> on failure\n(plus an error message as a second result and\na system-dependent error code as a third result)\nand some value different from <b>nil</b> on success.\nOn non-POSIX systems,\nthe computation of the error message and error code\nin case of errors\nmay be not thread safe,\nbecause they rely on the global C variable <code>errno</code>.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():flush()</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without parameters,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that\nworks like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.\nWhen the iterator function detects the end of file,\nit returns no values (to finish the loop) and automatically closes the file.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines(\"*l\")</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case it does not close the file when the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIn case of success,\nit returns a new file handle.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"<code>r</code>\": </b> read mode (the default);</li>\n<li><b>\"<code>w</code>\": </b> write mode;</li>\n<li><b>\"<code>a</code>\": </b> append mode;</li>\n<li><b>\"<code>r+</code>\": </b> update mode, all previous data is preserved;</li>\n<li><b>\"<code>w+</code>\": </b> update mode, all previous data is erased;</li>\n<li><b>\"<code>a+</code>\": </b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n<p>\nStarts program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nIn case of success,\nreturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>nil</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n<p>\nWhen closing a file handle created with <a href=\"#pdf-io.popen\"><code>io.popen</code></a>,\n<a href=\"#pdf-file:close\"><code>file:close</code></a> returns the same values\nreturned by <a href=\"#pdf-os.execute\"><code>os.execute</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreads the file according to the given formats.\nWhen no format is given,\nuses \"<code>l</code>\" as a default.\nAs an example, the construction\n\n<pre>\n     for c in file:lines(1) do <em>body</em> end\n</pre><p>\nwill iterate over all characters of the file,\nstarting at the current position.\nUnlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string or a number with the characters read,\nor <b>nil</b> if it cannot read data with the specified format.\n(In this latter case,\nthe function does not read subsequent formats.)\nWhen called without formats,\nit uses a default format that reads the next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"<code>n</code>\": </b>\nreads a numeral and returns it as a float or an integer,\nfollowing the lexical conventions of Lua.\n(The numeral may have leading spaces and a sign.)\nThis format always reads the longest input sequence that\nis a valid prefix for a numeral;\nif that prefix does not form a valid numeral\n(e.g., an empty string, \"<code>0x</code>\", or \"<code>3.4e-</code>\"),\nit is discarded and the function returns <b>nil</b>.\n</li>\n\n<li><b>\"<code>a</code>\": </b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string.\n</li>\n\n<li><b>\"<code>l</code>\": </b>\nreads the next line skipping the end of line,\nreturning <b>nil</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b>\"<code>L</code>\": </b>\nreads the next line keeping the end-of-line character (if present),\nreturning <b>nil</b> on end of file.\n</li>\n\n<li><b><em>number</em>: </b>\nreads a string with up to this number of bytes,\nreturning <b>nil</b> on end of file.\nIf <code>number</code> is zero,\nit reads nothing and returns an empty string,\nor <b>nil</b> on end of file.\n</li>\n\n</ul><p>\nThe formats \"<code>l</code>\" and \"<code>L</code>\" should be used only for text files.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence [, offset]])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"<code>set</code>\": </b> base is position 0 (beginning of the file);</li>\n<li><b>\"<code>cur</code>\": </b> base is current position;</li>\n<li><b>\"<code>end</code>\": </b> base is end of file;</li>\n</ul><p>\nIn case of success, <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf <code>seek</code> fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for an output file.\nThere are three available modes:\n\n<ul>\n\n<li><b>\"<code>no</code>\": </b>\nno buffering; the result of any output operation appears immediately.\n</li>\n\n<li><b>\"<code>full</code>\": </b>\nfull buffering; output operation is performed only\nwhen the buffer is full or when\nyou explicitly <code>flush</code> the file (see <a href=\"#pdf-io.flush\"><code>io.flush</code></a>).\n</li>\n\n<li><b>\"<code>line</code>\": </b>\nline buffering; output is buffered until a newline is output\nor there is any input from some special files\n(such as a terminal device).\n</li>\n\n</ul><p>\nFor the last two cases, <code>size</code>\nspecifies the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to <code>file</code>.\nThe arguments must be strings or numbers.\n\n\n<p>\nIn case of success, this function returns <code>file</code>.\nOtherwise it returns <b>nil</b> plus a string describing the error.\n\n\n\n\n\n\n\n<h2>6.9 &ndash; <a name=\"6.9\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),\n<code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),\n<code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),\n<code>yday</code> (day of the year, 1&ndash;366),\nand <code>isdst</code> (daylight saving flag, a boolean).\nThis last field may be absent\nif the information is not available.\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.\n\n\n<p>\nWhen called without arguments,\n<code>date</code> returns a reasonable date and time representation that depends on\nthe host system and on the current locale.\n(More specifically, <code>os.date()</code> is equivalent to <code>os.date(\"%c\")</code>.)\n\n\n<p>\nOn non-POSIX systems,\nthis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the difference, in seconds,\nfrom time <code>t1</code> to time <code>t2</code>\n(where the times are values returned by <a href=\"#pdf-os.time\"><code>os.time</code></a>).\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the ISO&nbsp;C function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIts first result is <b>true</b>\nif the command terminated successfully,\nor <b>nil</b> otherwise.\nAfter this first result\nthe function returns a string plus a number,\nas follows:\n\n<ul>\n\n<li><b>\"<code>exit</code>\": </b>\nthe command terminated normally;\nthe following number is the exit status of the command.\n</li>\n\n<li><b>\"<code>signal</code>\": </b>\nthe command was terminated by a signal;\nthe following number is the signal that terminated the command.\n</li>\n\n</ul>\n\n<p>\nWhen called without a <code>command</code>,\n<code>os.execute</code> returns a boolean that is true if a shell is available.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code [, close]])</code></a></h3>\n\n\n<p>\nCalls the ISO&nbsp;C function <code>exit</code> to terminate the host program.\nIf <code>code</code> is <b>true</b>,\nthe returned status is <code>EXIT_SUCCESS</code>;\nif <code>code</code> is <b>false</b>,\nthe returned status is <code>EXIT_FAILURE</code>;\nif <code>code</code> is a number,\nthe returned status is this number.\nThe default value for <code>code</code> is <b>true</b>.\n\n\n<p>\nIf the optional second argument <code>close</code> is true,\ncloses the Lua state before exiting.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>,\nor <b>nil</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file (or empty directory, on POSIX systems)\nwith the given name.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames the file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a system-dependent string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>nil</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n<p>\nThis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>setlocale</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the local date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields\n<code>hour</code> (default is 12),\n<code>min</code> (default is 0),\n<code>sec</code> (default is 0),\nand <code>isdst</code> (default is <b>nil</b>).\nOther fields are ignored.\nFor a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function.\n\n\n<p>\nThe values in these fields do not need to be inside their valid ranges.\nFor instance, if <code>sec</code> is -10,\nit means -10 seconds from the time specified by the other fields;\nif <code>hour</code> is 1000,\nit means +1000 hours from the time specified by the other fields.\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems,\nthis number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<a href=\"#pdf-os.date\"><code>os.date</code></a> and <a href=\"#pdf-os.difftime\"><code>os.difftime</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nOn POSIX systems,\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>6.10 &ndash; <a name=\"6.10\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface (<a href=\"#4.9\">&sect;4.9</a>) to Lua programs.\nYou should exert care when using this library.\nSeveral of its functions\nviolate basic assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside;\nthat userdata metatables cannot be changed by Lua code;\nthat Lua programs do not crash)\nand therefore can compromise otherwise secure code.\nMoreover, some functions in this library may be slow.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count\n(as set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly\nor you can give a number as the value of <code>f</code>,\nwhich means the function running at level <code>f</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>\n(except for tail calls, which do not count on the stack);\nand so on.\nIf <code>f</code> is a number larger than the number of active functions,\nthen <code>getinfo</code> returns <b>nil</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] f, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>f</code> of the stack.\nThis function accesses not only explicit local variables,\nbut also parameters, temporaries, etc.\n\n\n<p>\nThe first parameter or local variable has index&nbsp;1, and so on,\nfollowing the order that they are declared in the code,\ncounting only the variables that are active\nin the current scope of the function.\nNegative indices refer to vararg parameters;\n-1 is the first vararg parameter.\nThe function returns <b>nil</b> if there is no variable with the given index,\nand raises an error when called with a level out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(internal variables such as loop control variables,\nand variables from chunks saved without debug information).\n\n\n<p>\nThe parameter <code>f</code> may also be a function.\nIn that case, <code>getlocal</code> returns only the name of function parameters.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (value)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>value</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (f, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue with the given index.\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(variables from chunks saved without debug information).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getuservalue\"><code>debug.getuservalue (u)</code></a></h3>\n\n\n<p>\nReturns the Lua value associated to <code>u</code>.\nIf <code>u</code> is not a full userdata,\nreturns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as a hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have any combination of the following characters,\nwith the given meaning:\n\n<ul>\n<li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>\n<li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>\n<li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nMoreover,\nwith a <code>count</code> different from zero,\nthe hook is called also after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first parameter is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code> (or <code>\"tail call\"</code>),\n<code>\"return\"</code>,\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function\n(level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n<p>\nSee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for more information about\nvariable indices and names.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (value, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>value</code> to the given <code>table</code>\n(which can be <b>nil</b>).\nReturns <code>value</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (f, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setuservalue\"><code>debug.setuservalue (udata, value)</code></a></h3>\n\n\n<p>\nSets the given <code>value</code> as\nthe Lua value associated to the given <code>udata</code>.\n<code>udata</code> must be a full userdata.\n\n\n<p>\nReturns <code>udata</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>\n\n\n<p>\nIf <code>message</code> is present but is neither a string nor <b>nil</b>,\nthis function returns <code>message</code> without further processing.\nOtherwise,\nit returns a string with a traceback of the call stack.\nThe optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvalueid\"><code>debug.upvalueid (f, n)</code></a></h3>\n\n\n<p>\nReturns a unique identifier (as a light userdata)\nfor the upvalue numbered <code>n</code>\nfrom the given function.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvaluejoin\"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>\n\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.\n\n\n\n\n\n\n\n<h1>7 &ndash; <a name=\"7\">Lua Standalone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a standalone language.\nAn interpreter for Lua as a standalone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe standalone interpreter includes\nall standard libraries, including the debug library.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li>\n<li><b><code>-l <em>mod</em></code>: </b> \"requires\" <em>mod</em>;</li>\n<li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li>\n<li><b><code>-v</code>: </b> prints version information;</li>\n<li><b><code>-E</code>: </b> ignores environment variables;</li>\n<li><b><code>--</code>: </b> stops handling options;</li>\n<li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nWhen called without option <code>-E</code>,\nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT_5_3\"><code>LUA_INIT_5_3</code></a>\n(or <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a> if the versioned name is not defined)\nbefore running any argument.\nIf the variable content has the format <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nWhen called with option <code>-E</code>,\nbesides ignoring <code>LUA_INIT</code>,\nLua also ignores\nthe values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>,\nsetting the values of\n<a href=\"#pdf-package.path\"><code>package.path</code></a> and <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>\nwith the default paths defined in <code>luaconf.h</code>.\n\n\n<p>\nAll options are handled in order, except <code>-i</code> and <code>-E</code>.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e'a=1' -e 'print(a)' script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then print the value of <code>a</code>,\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore running any code,\n<code>lua</code> collects all command-line arguments\nin a global table called <code>arg</code>.\nThe script name goes to index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus its options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe table is like this:\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nIf there is no script in the call,\nthe interpreter name goes to index 0,\nfollowed by the other arguments.\nFor instance, the call\n\n<pre>\n     $ lua -e \"print(arg[1])\"\n</pre><p>\nwill print \"<code>-e</code>\".\nIf there is a script,\nthe script is called with parameters\n<code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.\n(Like all chunks in Lua,\nthe script is compiled as a vararg function.)\n\n\n<p>\nIn interactive mode,\nLua repeatedly prompts and waits for a line.\nAfter reading a line,\nLua first try to interpret the line as an expression.\nIf it succeeds, it prints its value.\nOtherwise, it interprets the line as a statement.\nIf you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\n\n\n<p>\nIn case of unprotected errors in the script,\nthe interpreter reports the error to the standard error stream.\nIf the error object is not a string but\nhas a metamethod <code>__tostring</code>,\nthe interpreter calls this metamethod to produce the final message.\nOtherwise, the interpreter converts the error object to a string\nand adds a stack traceback to it.\n\n\n<p>\nWhen finishing normally,\nthe interpreter closes its main Lua state\n(see <a href=\"#lua_close\"><code>lua_close</code></a>).\nThe script can avoid this step by\ncalling <a href=\"#pdf-os.exit\"><code>os.exit</code></a> to terminate.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nthe standalone interpreter skips\nthe first line of a chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\n(Of course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen\n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.)\n\n\n\n<h1>8 &ndash; <a name=\"8\">Incompatibilities with the Previous Version</a></h1>\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.2 to Lua&nbsp;5.3.\nYou can avoid some incompatibilities by compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the future.\n\n\n<p>\nLua versions can always change the C API in ways that\ndo not imply source-code changes in a program,\nsuch as the numeric values for constants\nor the implementation of functions as macros.\nTherefore,\nyou should not assume that binaries are compatible between\ndifferent Lua versions.\nAlways recompile clients of the Lua API when\nusing a new version.\n\n\n<p>\nSimilarly, Lua versions can always change the internal representation\nof precompiled chunks;\nprecompiled chunks are not compatible between different Lua versions.\n\n\n<p>\nThe standard paths in the official distribution may\nchange between versions.\n\n\n\n<h2>8.1 &ndash; <a name=\"8.1\">Changes in the Language</a></h2>\n<ul>\n\n<li>\nThe main difference between Lua&nbsp;5.2 and Lua&nbsp;5.3 is the\nintroduction of an integer subtype for numbers.\nAlthough this change should not affect \"normal\" computations,\nsome computations\n(mainly those that involve some kind of overflow)\ncan give different results.\n\n\n<p>\nYou can fix these differences by forcing a number to be a float\n(in Lua&nbsp;5.2 all numbers were float),\nin particular writing constants with an ending <code>.0</code>\nor using <code>x = x + 0.0</code> to convert a variable.\n(This recommendation is only for a quick fix\nfor an occasional incompatibility;\nit is not a general guideline for good programming.\nFor good programming,\nuse floats where you need floats\nand integers where you need integers.)\n</li>\n\n<li>\nThe conversion of a float to a string now adds a <code>.0</code> suffix\nto the result if it looks like an integer.\n(For instance, the float 2.0 will be printed as <code>2.0</code>,\nnot as <code>2</code>.)\nYou should always use an explicit format\nwhen you need a specific format for numbers.\n\n\n<p>\n(Formally this is not an incompatibility,\nbecause Lua does not specify how numbers are formatted as strings,\nbut some programs assumed a specific format.)\n</li>\n\n<li>\nThe generational mode for the garbage collector was removed.\n(It was an experimental feature in Lua&nbsp;5.2.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.2 &ndash; <a name=\"8.2\">Changes in the Libraries</a></h2>\n<ul>\n\n<li>\nThe <code>bit32</code> library has been deprecated.\nIt is easy to require a compatible external library or,\nbetter yet, to replace its functions with appropriate bitwise operations.\n(Keep in mind that <code>bit32</code> operates on 32-bit integers,\nwhile the bitwise operators in Lua&nbsp;5.3 operate on Lua integers,\nwhich by default have 64&nbsp;bits.)\n</li>\n\n<li>\nThe Table library now respects metamethods\nfor setting and getting elements.\n</li>\n\n<li>\nThe <a href=\"#pdf-ipairs\"><code>ipairs</code></a> iterator now respects metamethods and\nits <code>__ipairs</code> metamethod has been deprecated.\n</li>\n\n<li>\nOption names in <a href=\"#pdf-io.read\"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore.\nFor compatibility, Lua will continue to accept (and ignore) this character.\n</li>\n\n<li>\nThe following functions were deprecated in the mathematical library:\n<code>atan2</code>, <code>cosh</code>, <code>sinh</code>, <code>tanh</code>, <code>pow</code>,\n<code>frexp</code>, and <code>ldexp</code>.\nYou can replace <code>math.pow(x,y)</code> with <code>x^y</code>;\nyou can replace <code>math.atan2</code> with <code>math.atan</code>,\nwhich now accepts one or two parameters;\nyou can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>.\nFor the other operations,\nyou can either use an external library or\nimplement them in Lua.\n</li>\n\n<li>\nThe searcher for C loaders used by <a href=\"#pdf-require\"><code>require</code></a>\nchanged the way it handles versioned names.\nNow, the version should come after the module name\n(as is usual in most other tools).\nFor compatibility, that searcher still tries the old format\nif it cannot find an open function according to the new style.\n(Lua&nbsp;5.2 already worked that way,\nbut it did not document the change.)\n</li>\n\n<li>\nThe call <code>collectgarbage(\"count\")</code> now returns only one result.\n(You can compute that second result from the fractional part\nof the first result.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.3 &ndash; <a name=\"8.3\">Changes in the API</a></h2>\n\n\n<ul>\n\n<li>\nContinuation functions now receive as parameters what they needed\nto get through <code>lua_getctx</code>,\nso <code>lua_getctx</code> has been removed.\nAdapt your code accordingly.\n</li>\n\n<li>\nFunction <a href=\"#lua_dump\"><code>lua_dump</code></a> has an extra parameter, <code>strip</code>.\nUse 0 as the value of this parameter to get the old behavior.\n</li>\n\n<li>\nFunctions to inject/project unsigned integers\n(<code>lua_pushunsigned</code>, <code>lua_tounsigned</code>, <code>lua_tounsignedx</code>,\n<code>luaL_checkunsigned</code>, <code>luaL_optunsigned</code>)\nwere deprecated.\nUse their signed equivalents with a type cast.\n</li>\n\n<li>\nMacros to project non-default integer types\n(<code>luaL_checkint</code>, <code>luaL_optint</code>, <code>luaL_checklong</code>, <code>luaL_optlong</code>)\nwere deprecated.\nUse their equivalent over <a href=\"#lua_Integer\"><code>lua_Integer</code></a> with a type cast\n(or, when possible, use <a href=\"#lua_Integer\"><code>lua_Integer</code></a> in your code).\n</li>\n\n</ul>\n\n\n\n\n<h1>9 &ndash; <a name=\"9\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\nAs usual in extended BNF,\n{A} means 0 or more As,\nand [A] means an optional A.\n(For operator precedences, see <a href=\"#3.4.8\">&sect;3.4.8</a>;\nfor a description of the terminals\nName, Numeral,\nand LiteralString, see <a href=\"#3.1\">&sect;3.1</a>.)\n\n\n\n\n<pre>\n\n\tchunk ::= block\n\n\tblock ::= {stat} [retstat]\n\n\tstat ::=  &lsquo;<b>;</b>&rsquo; | \n\t\t varlist &lsquo;<b>=</b>&rsquo; explist | \n\t\t functioncall | \n\t\t label | \n\t\t <b>break</b> | \n\t\t <b>goto</b> Name | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] \n\n\tretstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\n\tvar ::=  Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name \n\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | &lsquo;<b>...</b>&rsquo; | functiondef | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n\n\tfunctioncall ::=  prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args \n\n\targs ::=  &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | LiteralString \n\n\tfunctiondef ::= <b>function</b> funcbody\n\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n\n\tbinop ::=  &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>//</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; | \n\t\t &lsquo;<b>&amp;</b>&rsquo; | &lsquo;<b>~</b>&rsquo; | &lsquo;<b>|</b>&rsquo; | &lsquo;<b>&gt;&gt;</b>&rsquo; | &lsquo;<b>&lt;&lt;</b>&rsquo; | &lsquo;<b>..</b>&rsquo; | \n\t\t &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo; | &lsquo;<b>~</b>&rsquo;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n<P CLASS=\"footer\">\nLast update:\nMon Jan  9 13:30:53 BRST 2017\n</P>\n<!--\nLast change: revised for Lua 5.3.4\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "build/lua-5.3.4/doc/readme.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 readme</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<STYLE TYPE=\"text/css\">\nblockquote, .display {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 8px ;\n\tpadding: 1em ;\n\tmargin: 0px ;\n}\n\n.display {\n\tword-spacing: 0.25em ;\n}\n\ndl.display dd {\n\tpadding-bottom: 0.2em ;\n}\n\ntt, kbd, code {\n\tfont-size: 12pt ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nWelcome to Lua 5.3\n</H1>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"#about\">about</A>\n&middot;\n<A HREF=\"#install\">installation</A>\n&middot;\n<A HREF=\"#changes\">changes</A>\n&middot;\n<A HREF=\"#license\">license</A>\n&middot;\n<A HREF=\"contents.html\">reference manual</A>\n</DIV>\n\n<H2><A NAME=\"about\">About Lua</A></H2>\n<P>\nLua is a powerful, fast, lightweight, embeddable scripting language\ndeveloped by a\n<A HREF=\"http://www.lua.org/authors.html\">team</A>\nat\n<A HREF=\"http://www.puc-rio.br/\">PUC-Rio</A>,\nthe Pontifical Catholic University of Rio de Janeiro in Brazil.\nLua is\n<A HREF=\"#license\">free software</A>\nused in many products and projects around the world.\n\n<P>\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\nprovides complete information\nabout Lua,\nincluding\nan\n<A HREF=\"http://www.lua.org/about.html\">executive summary</A>\nand\nupdated\n<A HREF=\"http://www.lua.org/docs.html\">documentation</A>,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.3/\">reference manual</A>,\nwhich may differ slightly from the\n<A HREF=\"contents.html\">local copy</A>\ndistributed in this package.\n\n<H2><A NAME=\"install\">Installing Lua</A></H2>\n<P>\nLua is distributed in\n<A HREF=\"http://www.lua.org/ftp/\">source</A>\nform.\nYou need to build it before using it.\nBuilding Lua should be straightforward\nbecause\nLua is implemented in pure ANSI C and compiles unmodified in all known\nplatforms that have an ANSI C compiler.\nLua also compiles unmodified as C++.\nThe instructions given below for building Lua are for Unix-like platforms.\nSee also\n<A HREF=\"#other\">instructions for other systems</A>\nand\n<A HREF=\"#customization\">customization options</A>.\n\n<P>\nIf you don't have the time or the inclination to compile Lua yourself,\nget a binary from\n<A HREF=\"http://lua-users.org/wiki/LuaBinaries\">LuaBinaries</A>.\nTry also\n<A HREF=\"http://luadist.org/\">LuaDist</A>,\na multi-platform distribution of Lua that includes batteries.\n\n<H3>Building Lua</H3>\n<P>\nIn most Unix-like platforms, simply do \"<KBD>make</KBD>\" with a suitable target.\nHere are the details.\n\n<OL>\n<LI>\nOpen a terminal window and move to\nthe top-level directory, which is named <TT>lua-5.3.x</TT>.\nThe <TT>Makefile</TT> there controls both the build process and the installation process.\n<P>\n<LI>\n  Do \"<KBD>make</KBD>\" and see if your platform is listed.\n  The platforms currently supported are:\n<P>\n<P CLASS=\"display\">\n   aix bsd c89 freebsd generic linux macosx mingw posix solaris\n</P>\n<P>\n  If your platform is listed, just do \"<KBD>make xxx</KBD>\", where xxx\n  is your platform name.\n<P>\n  If your platform is not listed, try the closest one or posix, generic,\n  c89, in this order.\n<P>\n<LI>\nThe compilation takes only a few moments\nand produces three files in the <TT>src</TT> directory:\nlua (the interpreter),\nluac (the compiler),\nand liblua.a (the library).\n<P>\n<LI>\n  To check that Lua has been built correctly, do \"<KBD>make test</KBD>\"\n  after building Lua. This will run the interpreter and print its version.\n</OL>\n<P>\nIf you're running Linux and get compilation errors,\nmake sure you have installed the <TT>readline</TT> development package\n(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).\nIf you get link errors after that,\nthen try \"<KBD>make linux MYLIBS=-ltermcap</KBD>\".\n\n<H3>Installing Lua</H3>\n<P>\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"<KBD>make install</KBD>\". The official\n  place and the way to install files are defined in the <TT>Makefile</TT>. You'll\n  probably need the right permissions to install files.\n\n<P>\n  To build and install Lua in one step, do \"<KBD>make xxx install</KBD>\",\n  where xxx is your platform name.\n\n<P>\n  To install Lua locally, do \"<KBD>make local</KBD>\".\n  This will create a directory <TT>install</TT> with subdirectories\n  <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,\n  and install Lua as listed below.\n\n  To install Lua locally, but in some other directory, do\n  \"<KBD>make install INSTALL_TOP=xxx</KBD>\", where xxx is your chosen directory.\n  The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,\n  so take care if <TT>INSTALL_TOP</TT> is not an absolute path.\n\n<DL CLASS=\"display\">\n<DT>\n    bin:\n<DD>\n    lua luac\n<DT>\n    include:\n<DD>\n    lua.h luaconf.h lualib.h lauxlib.h lua.hpp\n<DT>\n    lib:\n<DD>\n    liblua.a\n<DT>\n    man/man1:\n<DD>\n    lua.1 luac.1\n</DL>\n\n<P>\n  These are the only directories you need for development.\n  If you only want to run Lua programs,\n  you only need the files in <TT>bin</TT> and <TT>man</TT>.\n  The files in <TT>include</TT> and <TT>lib</TT> are needed for\n  embedding Lua in C or C++ programs.\n\n<H3><A NAME=\"customization\">Customization</A></H3>\n<P>\n  Three kinds of things can be customized by editing a file:\n<UL>\n    <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.\n    <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.\n    <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.\n</UL>\n\n<P>\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables in the command line when invoking make.\n  Nevertheless, it's probably best to edit and save the Makefiles to\n  record the changes you've made.\n\n<P>\n  On the other hand, if you need to customize some Lua features, you'll need\n  to edit <TT>src/luaconf.h</TT> before building and installing Lua.\n  The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n  Further customization is available to experts by editing the Lua sources.\n\n<H3><A NAME=\"other\">Building Lua on other systems</A></H3>\n<P>\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n<DL CLASS=\"display\">\n<DT>\nlibrary:\n<DD>\nlapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c\nlmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c\nltm.c lundump.c lvm.c lzio.c\nlauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c\nlmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c\n<DT>\ninterpreter:\n<DD>\n  library, lua.c\n<DT>\ncompiler:\n<DD>\n  library, luac.c\n</DL>\n\n<P>\n  To use Lua as a library in your own programs you'll need to know how to\n  create and use libraries with your compiler. Moreover, to dynamically load\n  C libraries for Lua you'll need to know how to create dynamic libraries\n  and you'll need to make sure that the Lua API functions are accessible to\n  those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library\n  into each dynamic library. For Unix, we recommend that the Lua library\n  be linked statically into the host program and its symbols exported for\n  dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.\n  For Windows, we recommend that the Lua library be a DLL.\n  In all cases, the compiler luac should be linked statically.\n\n<P>\n  As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize\n  some features before building Lua.\n\n<H2><A NAME=\"changes\">Changes since Lua 5.2</A></H2>\n<P>\nHere are the main changes introduced in Lua 5.3.\nThe\n<A HREF=\"contents.html\">reference manual</A>\nlists the\n<A HREF=\"manual.html#8\">incompatibilities</A> that had to be introduced.\n\n<H3>Main changes</H3>\n<UL>\n<LI> integers (64-bit by default)\n<LI> official support for 32-bit numbers\n<LI> bitwise operators\n<LI> basic utf-8 support\n<LI> functions for packing and unpacking values\n\n</UL>\n\nHere are the other changes introduced in Lua 5.3:\n<H3>Language</H3>\n<UL>\n<LI> userdata can have any Lua value as uservalue\n<LI> floor division\n<LI> more flexible rules for some metamethods\n</UL>\n\n<H3>Libraries</H3>\n<UL>\n<LI> <CODE>ipairs</CODE> and the table library respect metamethods\n<LI> strip option in <CODE>string.dump</CODE>\n<LI> table library respects metamethods\n<LI> new function <CODE>table.move</CODE>\n<LI> new function <CODE>string.pack</CODE>\n<LI> new function <CODE>string.unpack</CODE>\n<LI> new function <CODE>string.packsize</CODE>\n</UL>\n\n<H3>C API</H3>\n<UL>\n<LI> simpler API for continuation functions in C\n<LI> <CODE>lua_gettable</CODE> and similar functions return type of resulted value\n<LI> strip option in <CODE>lua_dump</CODE>\n<LI> new function: <CODE>lua_geti</CODE>\n<LI> new function: <CODE>lua_seti</CODE>\n<LI> new function: <CODE>lua_isyieldable</CODE>\n<LI> new function: <CODE>lua_numbertointeger</CODE>\n<LI> new function: <CODE>lua_rotate</CODE>\n<LI> new function: <CODE>lua_stringtonumber</CODE>\n</UL>\n\n<H3>Lua standalone interpreter</H3>\n<UL>\n<LI> can be used as calculator; no need to prefix with '='\n<LI> <CODE>arg</CODE> table available to all code\n</UL>\n\n<H2><A NAME=\"license\">License</A></H2>\n<P>\n<A HREF=\"http://www.opensource.org/docs/definition.php\">\n<IMG SRC=\"osi-certified-72x60.png\" ALIGN=\"right\" ALT=\"[osi certified]\" STYLE=\"padding-left: 30px ;\">\n</A>\nLua is free software distributed under the terms of the\n<A HREF=\"http://www.opensource.org/licenses/mit-license.html\">MIT license</A>\nreproduced below;\nit may be used for any purpose, including commercial purposes,\nat absolutely no cost without having to ask us.\n\nThe only requirement is that if you do use Lua,\nthen you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.\n\nFor details, see\n<A HREF=\"http://www.lua.org/license.html\">this</A>.\n\n<BLOCKQUOTE STYLE=\"padding-bottom: 0em\">\nCopyright &copy; 1994&ndash;2017 Lua.org, PUC-Rio.\n\n<P>\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n<P>\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n<P>\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n</BLOCKQUOTE>\n<P>\n\n<P CLASS=\"footer\">\nLast update:\nThu Dec 22 18:22:57 BRST 2016\n</P>\n<!--\nLast change: revised for Lua 5.3.4\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.4/src/Makefile",
    "content": "# Makefile for building Lua\n# See ../doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\nCC= gcc -std=gnu99\nCFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)\nLDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)\nLIBS= -lm $(SYSLIBS) $(MYLIBS)\n\nAR= ar rcu\nRANLIB= ranlib\nRM= rm -f\n\nSYSCFLAGS=\nSYSLDFLAGS=\nSYSLIBS=\n\nMYCFLAGS=\nMYLDFLAGS=\nMYLIBS=\nMYOBJS=\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\nLUA_A=\tliblua.a\nCORE_O=\tlapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \\\n\tlmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \\\n\tltm.o lundump.o lvm.o lzio.o\nLIB_O=\tlauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \\\n\tlmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o\nBASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)\n\nLUA_T=\tlua\nLUA_O=\tlua.o\n\nLUAC_T=\tluac\nLUAC_O=\tluac.o\n\nALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)\nALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)\nALL_A= $(LUA_A)\n\n# Targets start here.\ndefault: $(PLAT)\n\nall:\t$(ALL_T)\n\no:\t$(ALL_O)\n\na:\t$(ALL_A)\n\n$(LUA_A): $(BASE_O)\n\t$(AR) $@ $(BASE_O)\n\t$(RANLIB) $@\n\n$(LUA_T): $(LUA_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)\n\n$(LUAC_T): $(LUAC_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)\n\nclean:\n\t$(RM) $(ALL_T) $(ALL_O)\n\ndepend:\n\t@$(CC) $(CFLAGS) -MM l*.c\n\necho:\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"CC= $(CC)\"\n\t@echo \"CFLAGS= $(CFLAGS)\"\n\t@echo \"LDFLAGS= $(SYSLDFLAGS)\"\n\t@echo \"LIBS= $(LIBS)\"\n\t@echo \"AR= $(AR)\"\n\t@echo \"RANLIB= $(RANLIB)\"\n\t@echo \"RM= $(RM)\"\n\n# Convenience targets for popular platforms\nALL= all\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\naix:\n\t$(MAKE) $(ALL) CC=\"xlc\" CFLAGS=\"-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-ldl\" SYSLDFLAGS=\"-brtl -bexpall\"\n\nbsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-Wl,-E\"\n\nc89:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_C89\" CC=\"gcc -std=c89\"\n\t@echo ''\n\t@echo '*** C89 does not guarantee 64-bit integers for Lua.'\n\t@echo ''\n\n\nfreebsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -lreadline\"\n\ngeneric: $(ALL)\n\nlinux:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -ldl -lreadline\"\n\nmacosx:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_MACOSX\" SYSLIBS=\"-lreadline\" CC=cc\n\nmingw:\n\t$(MAKE) \"LUA_A=lua53.dll\" \"LUA_T=lua.exe\" \\\n\t\"AR=$(CC) -shared -o\" \"RANLIB=strip --strip-unneeded\" \\\n\t\"SYSCFLAGS=-DLUA_BUILD_AS_DLL\" \"SYSLIBS=\" \"SYSLDFLAGS=-s\" lua.exe\n\t$(MAKE) \"LUAC_T=luac.exe\" luac.exe\n\nposix:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX\"\n\nsolaris:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT\" SYSLIBS=\"-ldl\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) default o a clean depend echo none\n\n# DO NOT DELETE\n\nlapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \\\n ltable.h lundump.h lvm.h\nlauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h\nlbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lgc.h lstring.h ltable.h lvm.h\nlcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h\nldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \\\n ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h\nldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \\\n lparser.h lstring.h ltable.h lundump.h lvm.h\nldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \\\n ltm.h lzio.h lmem.h lundump.h\nlfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \\\n lgc.h lstate.h ltm.h lzio.h lmem.h\nlgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h\nlinit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h\nliolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nllex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \\\n lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \\\n lstring.h ltable.h\nlmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h\nloadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \\\n ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \\\n lvm.h\nlopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h\nloslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lfunc.h lstring.h lgc.h ltable.h\nlstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \\\n lstring.h ltable.h\nlstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h\nlstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h\nltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h\nlua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nluac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \\\n lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h\nlundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \\\n lundump.h\nlutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \\\n ltable.h lvm.h\nlzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \\\n lobject.h ltm.h lzio.h\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.4/src/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$LuaVersion: \" LUA_COPYRIGHT \" $\"\n  \"$LuaAuthors: \" LUA_AUTHORS \" $\";\n\n\n/* value at a non-valid index */\n#define NONVALIDVALUE\t\tcast(TValue *, luaO_nilobject)\n\n/* corresponding test */\n#define isvalid(o)\t((o) != luaO_nilobject)\n\n/* test for pseudo index */\n#define ispseudo(i)\t\t((i) <= LUA_REGISTRYINDEX)\n\n/* test for upvalue */\n#define isupvalue(i)\t\t((i) < LUA_REGISTRYINDEX)\n\n/* test for valid but not pseudo index */\n#define isstackindex(i, o)\t(isvalid(o) && !ispseudo(i))\n\n#define api_checkvalidindex(l,o)  api_check(l, isvalid(o), \"invalid index\")\n\n#define api_checkstackindex(l, i, o)  \\\n\tapi_check(l, isstackindex(i, o), \"index not in the stack\")\n\n\nstatic TValue *index2addr (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    TValue *o = ci->func + idx;\n    api_check(L, idx <= ci->top - (ci->func + 1), \"unacceptable index\");\n    if (o >= L->top) return NONVALIDVALUE;\n    else return o;\n  }\n  else if (!ispseudo(idx)) {  /* negative index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    return L->top + idx;\n  }\n  else if (idx == LUA_REGISTRYINDEX)\n    return &G(L)->l_registry;\n  else {  /* upvalues */\n    idx = LUA_REGISTRYINDEX - idx;\n    api_check(L, idx <= MAXUPVAL + 1, \"upvalue index too large\");\n    if (ttislcf(ci->func))  /* light C function? */\n      return NONVALIDVALUE;  /* it has no upvalues */\n    else {\n      CClosure *func = clCvalue(ci->func);\n      return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;\n    }\n  }\n}\n\n\n/*\n** to be called by 'lua_checkstack' in protected mode, to grow stack\n** capturing memory errors\n*/\nstatic void growstack (lua_State *L, void *ud) {\n  int size = *(int *)ud;\n  luaD_growstack(L, size);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int n) {\n  int res;\n  CallInfo *ci = L->ci;\n  lua_lock(L);\n  api_check(L, n >= 0, \"negative 'n'\");\n  if (L->stack_last - L->top > n)  /* stack large enough? */\n    res = 1;  /* yes; check is OK */\n  else {  /* no; need to grow stack */\n    int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;\n    if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */\n      res = 0;  /* no */\n    else  /* try to grow stack */\n      res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK);\n  }\n  if (res && ci->top < L->top + n)\n    ci->top = L->top + n;  /* adjust frame top */\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to), \"moving among independent states\");\n  api_check(from, to->ci->top - to->top >= n, \"stack overflow\");\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobj2s(to, to->top, from->top + i);\n    to->top++;  /* stack already checked by previous 'api_check' */\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API const lua_Number *lua_version (lua_State *L) {\n  static const lua_Number version = LUA_VERSION_NUM;\n  if (L == NULL) return &version;\n  else return G(L)->version;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\n/*\n** convert an acceptable stack index into an absolute index\n*/\nLUA_API int lua_absindex (lua_State *L, int idx) {\n  return (idx > 0 || ispseudo(idx))\n         ? idx\n         : cast_int(L->top - L->ci->func) + idx;\n}\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - (L->ci->func + 1));\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  StkId func = L->ci->func;\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - (func + 1), \"new top too large\");\n    while (L->top < (func + 1) + idx)\n      setnilvalue(L->top++);\n    L->top = (func + 1) + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - (func + 1)), \"invalid new top\");\n    L->top += idx+1;  /* 'subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\n/*\n** Reverse the stack segment from 'from' to 'to'\n** (auxiliary to 'lua_rotate')\n*/\nstatic void reverse (lua_State *L, StkId from, StkId to) {\n  for (; from < to; from++, to--) {\n    TValue temp;\n    setobj(L, &temp, from);\n    setobjs2s(L, from, to);\n    setobj2s(L, to, &temp);\n  }\n}\n\n\n/*\n** Let x = AB, where A is a prefix of length 'n'. Then,\n** rotate x n == BA. But BA == (A^r . B^r)^r.\n*/\nLUA_API void lua_rotate (lua_State *L, int idx, int n) {\n  StkId p, t, m;\n  lua_lock(L);\n  t = L->top - 1;  /* end of stack segment being rotated */\n  p = index2addr(L, idx);  /* start of segment */\n  api_checkstackindex(L, idx, p);\n  api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), \"invalid 'n'\");\n  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */\n  reverse(L, p, m);  /* reverse the prefix with length 'n' */\n  reverse(L, m + 1, t);  /* reverse the suffix */\n  reverse(L, p, t);  /* reverse the entire segment */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {\n  TValue *fr, *to;\n  lua_lock(L);\n  fr = index2addr(L, fromidx);\n  to = index2addr(L, toidx);\n  api_checkvalidindex(L, to);\n  setobj(L, to, fr);\n  if (isupvalue(toidx))  /* function upvalue? */\n    luaC_barrier(L, clCvalue(L->ci->func), fr);\n  /* LUA_REGISTRYINDEX does not need gc barrier\n     (collector revisits it before finishing collection) */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2addr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (isvalid(o) ? ttnov(o) : LUA_TNONE);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, \"invalid tag\");\n  return ttypename(t);\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (ttislcf(o) || (ttisCclosure(o)));\n}\n\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return ttisinteger(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisstring(o) || cvt2str(o));\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisfulluserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2addr(L, index1);\n  StkId o2 = index2addr(L, index2);\n  return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;\n}\n\n\nLUA_API void lua_arith (lua_State *L, int op) {\n  lua_lock(L);\n  if (op != LUA_OPUNM && op != LUA_OPBNOT)\n    api_checknelems(L, 2);  /* all other operations expect two operands */\n  else {  /* for unary operations, add fake 2nd operand */\n    api_checknelems(L, 1);\n    setobjs2s(L, L->top, L->top - 1);\n    api_incr_top(L);\n  }\n  /* first operand at top - 2, second at top - 1; result go to top - 2 */\n  luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2);\n  L->top--;  /* remove second operand */\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {\n  StkId o1, o2;\n  int i = 0;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2addr(L, index1);\n  o2 = index2addr(L, index2);\n  if (isvalid(o1) && isvalid(o2)) {\n    switch (op) {\n      case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;\n      case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;\n      case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;\n      default: api_check(L, 0, \"invalid option\");\n    }\n  }\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {\n  size_t sz = luaO_str2num(s, L->top);\n  if (sz != 0)\n    api_incr_top(L);\n  return sz;\n}\n\n\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tonumber(o, &n);\n  if (!isnum)\n    n = 0;  /* call to 'tonumber' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return n;\n}\n\n\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {\n  lua_Integer res;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tointeger(o, &res);\n  if (!isnum)\n    res = 0;  /* call to 'tointeger' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return res;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2addr(L, idx);\n  if (!ttisstring(o)) {\n    if (!cvt2str(o)) {  /* not convertible? */\n      if (len != NULL) *len = 0;\n      return NULL;\n    }\n    lua_lock(L);  /* 'luaO_tostring' may create a new string */\n    luaO_tostring(L, o);\n    luaC_checkGC(L);\n    o = index2addr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL)\n    *len = vslen(o);\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_rawlen (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSHRSTR: return tsvalue(o)->shrlen;\n    case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  if (ttislcf(o)) return fvalue(o);\n  else if (ttisCclosure(o))\n    return clCvalue(o)->f;\n  else return NULL;  /* not a C function */\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttnov(o)) {\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TLCL: return clLvalue(o);\n    case LUA_TCCL: return clCvalue(o);\n    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setfltvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setivalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** Pushes on the stack a string with given length. Avoid using 's' when\n** 'len' == 0 (as 's' can be NULL in that case), due to later use of\n** 'memcmp' and 'memcpy'.\n*/\nLUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  TString *ts;\n  lua_lock(L);\n  ts = (len == 0) ? luaS_new(L, \"\") : luaS_newlstr(L, s, len);\n  setsvalue2s(L, L->top, ts);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getstr(ts);\n}\n\n\nLUA_API const char *lua_pushstring (lua_State *L, const char *s) {\n  lua_lock(L);\n  if (s == NULL)\n    setnilvalue(L->top);\n  else {\n    TString *ts;\n    ts = luaS_new(L, s);\n    setsvalue2s(L, L->top, ts);\n    s = getstr(ts);  /* internal copy's address */\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return s;\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  lua_lock(L);\n  if (n == 0) {\n    setfvalue(L->top, fn);\n  }\n  else {\n    CClosure *cl;\n    api_checknelems(L, n);\n    api_check(L, n <= MAXUPVAL, \"upvalue index too large\");\n    cl = luaF_newCclosure(L, n);\n    cl->f = fn;\n    L->top -= n;\n    while (n--) {\n      setobj2n(L, &cl->upvalue[n], L->top + n);\n      /* does not need barrier because closure is white */\n    }\n    setclCvalue(L, L->top, cl);\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(L->top, p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nstatic int auxgetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setsvalue2s(L, L->top, str);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);\n  return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API int lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);\n  return auxgetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  if (luaV_fastget(L, t, n, slot, luaH_getint)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top, luaH_getint(hvalue(t), n));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {\n  StkId t;\n  TValue k;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  setobj2s(L, L->top, luaH_get(hvalue(t), &k));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  Table *t;\n  lua_lock(L);\n  t = luaH_new(L);\n  sethvalue(L, L->top, t);\n  api_incr_top(L);\n  if (narray > 0 || nrec > 0)\n    luaH_resize(L, t, narray, nrec);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt;\n  int res = 0;\n  lua_lock(L);\n  obj = index2addr(L, objindex);\n  switch (ttnov(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(obj)];\n      break;\n  }\n  if (mt != NULL) {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API int lua_getuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  getuservalue(L, uvalue(o), L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n/*\n** t[k] = value at the top of the stack (where 'k' is a string)\n*/\nstatic void auxsetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  api_checknelems(L, 1);\n  if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);  /* lock done by caller */\n}\n\n\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2addr(L, idx);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2addr(L, idx);\n  if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId o;\n  TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  slot = luaH_set(L, hvalue(o), L->top - 2);\n  setobj2t(L, slot, L->top - 1);\n  invalidateTMcache(hvalue(o));\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  luaH_setint(L, hvalue(o), n, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {\n  StkId o;\n  TValue k, *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  slot = luaH_set(L, hvalue(o), &k);\n  setobj2t(L, slot, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2addr(L, objindex);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1), \"table expected\");\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttnov(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, gcvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, uvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    default: {\n      G(L)->mt[ttnov(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API void lua_setuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  setuservalue(L, uvalue(o), L->top - 1);\n  luaC_barrier(L, gcvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\n/*\n** 'load' and 'call' functions (run Lua code)\n*/\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \\\n\t\"results from function overflow current stack size\")\n\n\nLUA_API void lua_callk (lua_State *L, int nargs, int nresults,\n                        lua_KContext ctx, lua_KFunction k) {\n  StkId func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  if (k != NULL && L->nny == 0) {  /* need to prepare continuation? */\n    L->ci->u.c.k = k;  /* save continuation */\n    L->ci->u.c.ctx = ctx;  /* save context */\n    luaD_call(L, func, nresults);  /* do the call */\n  }\n  else  /* no continuation or no yieldable */\n    luaD_callnoyield(L, func, nresults);  /* just do the call */\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to 'f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_callnoyield(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,\n                        lua_KContext ctx, lua_KFunction k) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2addr(L, errfunc);\n    api_checkstackindex(L, errfunc, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  if (k == NULL || L->nny > 0) {  /* no continuation or no yieldable? */\n    c.nresults = nresults;  /* do a 'conventional' protected call */\n    status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  }\n  else {  /* prepare continuation (call is already protected by 'resume') */\n    CallInfo *ci = L->ci;\n    ci->u.c.k = k;  /* save continuation */\n    ci->u.c.ctx = ctx;  /* save context */\n    /* save information for error recovery */\n    ci->extra = savestack(L, c.func);\n    ci->u.c.old_errfunc = L->errfunc;\n    L->errfunc = func;\n    setoah(ci->callstatus, L->allowhook);  /* save value of 'allowhook' */\n    ci->callstatus |= CIST_YPCALL;  /* function can do error recovery */\n    luaD_call(L, c.func, nresults);  /* do the call */\n    ci->callstatus &= ~CIST_YPCALL;\n    L->errfunc = ci->u.c.old_errfunc;\n    status = LUA_OK;  /* if it is here, there were no errors */\n  }\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname, const char *mode) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname, mode);\n  if (status == LUA_OK) {  /* no errors? */\n    LClosure *f = clLvalue(L->top - 1);  /* get newly created function */\n    if (f->nupvalues >= 1) {  /* does it have an upvalue? */\n      /* get global table from registry */\n      Table *reg = hvalue(&G(L)->l_registry);\n      const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);\n      /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */\n      setobj(L, f->upvals[0]->v, gt);\n      luaC_upvalbarrier(L, f->upvals[0]);\n    }\n  }\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, getproto(o), writer, data, strip);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->gcrunning = 0;\n      break;\n    }\n    case LUA_GCRESTART: {\n      luaE_setdebt(g, 0);\n      g->gcrunning = 1;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L, 0);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(gettotalbytes(g) >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(gettotalbytes(g) & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      l_mem debt = 1;  /* =1 to signal that it did an actual step */\n      lu_byte oldrunning = g->gcrunning;\n      g->gcrunning = 1;  /* allow GC to run */\n      if (data == 0) {\n        luaE_setdebt(g, -GCSTEPSIZE);  /* to do a \"small\" step */\n        luaC_step(L);\n      }\n      else {  /* add 'data' to total debt */\n        debt = cast(l_mem, data) * 1024 + g->GCdebt;\n        luaE_setdebt(g, debt);\n        luaC_checkGC(L);\n      }\n      g->gcrunning = oldrunning;  /* restore previous state */\n      if (debt > 0 && g->gcstate == GCSpause)  /* end of cycle? */\n        res = 1;  /* signal it */\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      if (data < 40) data = 40;  /* avoid ridiculous low values (and 0) */\n      g->gcstepmul = data;\n      break;\n    }\n    case LUA_GCISRUNNING: {\n      res = g->gcrunning;\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  /* code unreachable; will unlock when control actually leaves the kernel */\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaV_concat(L, n);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_len (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_objlen(L, L->top, t);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  u = luaS_newudata(L, size);\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getudatamem(u);\n}\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val,\n                                CClosure **owner, UpVal **uv) {\n  switch (ttype(fi)) {\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      if (!(1 <= n && n <= f->nupvalues)) return NULL;\n      *val = &f->upvalue[n-1];\n      if (owner) *owner = f;\n      return \"\";\n    }\n    case LUA_TLCL: {  /* Lua closure */\n      LClosure *f = clLvalue(fi);\n      TString *name;\n      Proto *p = f->p;\n      if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n      *val = f->upvals[n-1]->v;\n      if (uv) *uv = f->upvals[n - 1];\n      name = p->upvalues[n-1].name;\n      return (name == NULL) ? \"(*no name)\" : getstr(name);\n    }\n    default: return NULL;  /* not a closure */\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  lua_lock(L);\n  name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  CClosure *owner = NULL;\n  UpVal *uv = NULL;\n  StkId fi;\n  lua_lock(L);\n  fi = index2addr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val, &owner, &uv);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    if (owner) { luaC_barrier(L, owner, L->top); }\n    else if (uv) { luaC_upvalbarrier(L, uv); }\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {\n  LClosure *f;\n  StkId fi = index2addr(L, fidx);\n  api_check(L, ttisLclosure(fi), \"Lua function expected\");\n  f = clLvalue(fi);\n  api_check(L, (1 <= n && n <= f->p->sizeupvalues), \"invalid upvalue index\");\n  if (pf) *pf = f;\n  return &f->upvals[n - 1];  /* get its upvalue pointer */\n}\n\n\nLUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {\n  StkId fi = index2addr(L, fidx);\n  switch (ttype(fi)) {\n    case LUA_TLCL: {  /* lua closure */\n      return *getupvalref(L, fidx, n, NULL);\n    }\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      api_check(L, 1 <= n && n <= f->nupvalues, \"invalid upvalue index\");\n      return &f->upvalue[n - 1];\n    }\n    default: {\n      api_check(L, 0, \"closure expected\");\n      return NULL;\n    }\n  }\n}\n\n\nLUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,\n                                            int fidx2, int n2) {\n  LClosure *f1;\n  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);\n  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);\n  luaC_upvdeccount(L, *up1);\n  *up1 = *up2;\n  (*up1)->refcount++;\n  if (upisopen(*up1)) (*up1)->u.open.touched = 1;\n  luaC_upvalbarrier(L, *up1);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"llimits.h\"\n#include \"lstate.h\"\n\n#define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \\\n\t\t\t\t\"stack overflow\");}\n\n#define adjustresults(L,nres) \\\n    { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }\n\n#define api_checknelems(L,n)\tapi_check(L, (n) < (L->top - L->ci->func), \\\n\t\t\t\t  \"not enough elements in the stack\")\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/*\n** This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n/*\n** {======================================================\n** Traceback\n** =======================================================\n*/\n\n\n#define LEVELS1\t10\t/* size of the first part of the stack */\n#define LEVELS2\t11\t/* size of the second part of the stack */\n\n\n\n/*\n** search for 'objidx' in table at index -1.\n** return 1 + string at top if find a good name.\n*/\nstatic int findfield (lua_State *L, int objidx, int level) {\n  if (level == 0 || !lua_istable(L, -1))\n    return 0;  /* not found */\n  lua_pushnil(L);  /* start 'next' loop */\n  while (lua_next(L, -2)) {  /* for each pair in table */\n    if (lua_type(L, -2) == LUA_TSTRING) {  /* ignore non-string keys */\n      if (lua_rawequal(L, objidx, -1)) {  /* found object? */\n        lua_pop(L, 1);  /* remove value (but keep name) */\n        return 1;\n      }\n      else if (findfield(L, objidx, level - 1)) {  /* try recursively */\n        lua_remove(L, -2);  /* remove table (but keep name) */\n        lua_pushliteral(L, \".\");\n        lua_insert(L, -2);  /* place '.' between the two names */\n        lua_concat(L, 3);\n        return 1;\n      }\n    }\n    lua_pop(L, 1);  /* remove value */\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Search for a name for a function in all loaded modules\n*/\nstatic int pushglobalfuncname (lua_State *L, lua_Debug *ar) {\n  int top = lua_gettop(L);\n  lua_getinfo(L, \"f\", ar);  /* push function */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  if (findfield(L, top + 1, 2)) {\n    const char *name = lua_tostring(L, -1);\n    if (strncmp(name, \"_G.\", 3) == 0) {  /* name start with '_G.'? */\n      lua_pushstring(L, name + 3);  /* push name without prefix */\n      lua_remove(L, -2);  /* remove original name */\n    }\n    lua_copy(L, -1, top + 1);  /* move name to proper place */\n    lua_pop(L, 2);  /* remove pushed values */\n    return 1;\n  }\n  else {\n    lua_settop(L, top);  /* remove function and global table */\n    return 0;\n  }\n}\n\n\nstatic void pushfuncname (lua_State *L, lua_Debug *ar) {\n  if (pushglobalfuncname(L, ar)) {  /* try first a global name */\n    lua_pushfstring(L, \"function '%s'\", lua_tostring(L, -1));\n    lua_remove(L, -2);  /* remove name */\n  }\n  else if (*ar->namewhat != '\\0')  /* is there a name from code? */\n    lua_pushfstring(L, \"%s '%s'\", ar->namewhat, ar->name);  /* use it */\n  else if (*ar->what == 'm')  /* main? */\n      lua_pushliteral(L, \"main chunk\");\n  else if (*ar->what != 'C')  /* for Lua functions, use <file:line> */\n    lua_pushfstring(L, \"function <%s:%d>\", ar->short_src, ar->linedefined);\n  else  /* nothing left... */\n    lua_pushliteral(L, \"?\");\n}\n\n\nstatic int lastlevel (lua_State *L) {\n  lua_Debug ar;\n  int li = 1, le = 1;\n  /* find an upper bound */\n  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }\n  /* do a binary search */\n  while (li < le) {\n    int m = (li + le)/2;\n    if (lua_getstack(L, m, &ar)) li = m + 1;\n    else le = m;\n  }\n  return le - 1;\n}\n\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,\n                                const char *msg, int level) {\n  lua_Debug ar;\n  int top = lua_gettop(L);\n  int last = lastlevel(L1);\n  int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;\n  if (msg)\n    lua_pushfstring(L, \"%s\\n\", msg);\n  luaL_checkstack(L, 10, NULL);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (n1-- == 0) {  /* too many levels? */\n      lua_pushliteral(L, \"\\n\\t...\");  /* add a '...' */\n      level = last - LEVELS2 + 1;  /* and skip to last ones */\n    }\n    else {\n      lua_getinfo(L1, \"Slnt\", &ar);\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n      if (ar.currentline > 0)\n        lua_pushfstring(L, \"%d:\", ar.currentline);\n      lua_pushliteral(L, \" in \");\n      pushfuncname(L, &ar);\n      if (ar.istailcall)\n        lua_pushliteral(L, \"\\n\\t(...tail calls...)\");\n      lua_concat(L, lua_gettop(L) - top);\n    }\n  }\n  lua_concat(L, lua_gettop(L) - top);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", arg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    arg--;  /* do not count 'self' */\n    if (arg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling '%s' on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : \"?\";\n  return luaL_error(L, \"bad argument #%d to '%s' (%s)\",\n                        arg, ar.name, extramsg);\n}\n\n\nstatic int typeerror (lua_State *L, int arg, const char *tname) {\n  const char *msg;\n  const char *typearg;  /* name for the type of the actual argument */\n  if (luaL_getmetafield(L, arg, \"__name\") == LUA_TSTRING)\n    typearg = lua_tostring(L, -1);  /* use the given type name */\n  else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)\n    typearg = \"light userdata\";  /* special name for messages */\n  else\n    typearg = luaL_typename(L, arg);  /* standard name */\n  msg = lua_pushfstring(L, \"%s expected, got %s\", tname, typearg);\n  return luaL_argerror(L, arg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int arg, int tag) {\n  typeerror(L, arg, lua_typename(L, tag));\n}\n\n\n/*\n** The use of 'lua_pushfstring' ensures this function does not\n** need reserved stack space when called.\n*/\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushfstring(L, \"\");  /* else, no information available... */\n}\n\n\n/*\n** Again, the use of 'lua_pushvfstring' ensures this function does\n** not need reserved stack space when called. (At worst, it generates\n** an error with \"stack overflow\" instead of the given message.)\n*/\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n\nLUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (stat) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushstring(L, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n#if !defined(l_inspectstat)\t/* { */\n\n#if defined(LUA_USE_POSIX)\n\n#include <sys/wait.h>\n\n/*\n** use appropriate macros to interpret 'pclose' return status\n*/\n#define l_inspectstat(stat,what)  \\\n   if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \\\n   else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = \"signal\"; }\n\n#else\n\n#define l_inspectstat(stat,what)  /* no op */\n\n#endif\n\n#endif\t\t\t\t/* } */\n\n\nLUALIB_API int luaL_execresult (lua_State *L, int stat) {\n  const char *what = \"exit\";  /* type of termination */\n  if (stat == -1)  /* error? */\n    return luaL_fileresult(L, 0, NULL);\n  else {\n    l_inspectstat(stat, what);  /* interpret result */\n    if (*what == 'e' && stat == 0)  /* successful termination? */\n      lua_pushboolean(L, 1);\n    else\n      lua_pushnil(L);\n    lua_pushstring(L, what);\n    lua_pushinteger(L, stat);\n    return 3;  /* return true/nil,what,code */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Userdata's metatable manipulation\n** =======================================================\n*/\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  if (luaL_getmetatable(L, tname) != LUA_TNIL)  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_createtable(L, 0, 2);  /* create metatable */\n  lua_pushstring(L, tname);\n  lua_setfield(L, -2, \"__name\");  /* metatable.__name = tname */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {\n  luaL_getmetatable(L, tname);\n  lua_setmetatable(L, -2);\n}\n\n\nLUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      luaL_getmetatable(L, tname);  /* get correct metatable */\n      if (!lua_rawequal(L, -1, -2))  /* not the same? */\n        p = NULL;  /* value is a userdata with wrong metatable */\n      lua_pop(L, 2);  /* remove both metatables */\n      return p;\n    }\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = luaL_testudata(L, ud, tname);\n  if (p == NULL) typeerror(L, ud, tname);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Argument check functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, arg, def) :\n                             luaL_checkstring(L, arg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, arg,\n                       lua_pushfstring(L, \"invalid option '%s'\", name));\n}\n\n\n/*\n** Ensures the stack has at least 'space' extra slots, raising an error\n** if it cannot fulfill the request. (The error handling needs a few\n** extra slots to format the error message. In case of an error without\n** this extra space, Lua will generate the same 'stack overflow' error,\n** but without 'msg'.)\n*/\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {\n  if (!lua_checkstack(L, space)) {\n    if (msg)\n      luaL_error(L, \"stack overflow (%s)\", msg);\n    else\n      luaL_error(L, \"stack overflow\");\n  }\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int arg, int t) {\n  if (lua_type(L, arg) != t)\n    tag_error(L, arg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNONE)\n    luaL_argerror(L, arg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) {\n  const char *s = lua_tolstring(L, arg, len);\n  if (!s) tag_error(L, arg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int arg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, arg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, arg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) {\n  int isnum;\n  lua_Number d = lua_tonumberx(L, arg, &isnum);\n  if (!isnum)\n    tag_error(L, arg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, arg, def);\n}\n\n\nstatic void interror (lua_State *L, int arg) {\n  if (lua_isnumber(L, arg))\n    luaL_argerror(L, arg, \"number has no integer representation\");\n  else\n    tag_error(L, arg, LUA_TNUMBER);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {\n  int isnum;\n  lua_Integer d = lua_tointegerx(L, arg, &isnum);\n  if (!isnum) {\n    interror(L, arg);\n  }\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, arg, def);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n/* userdata to box arbitrary data */\ntypedef struct UBox {\n  void *box;\n  size_t bsize;\n} UBox;\n\n\nstatic void *resizebox (lua_State *L, int idx, size_t newsize) {\n  void *ud;\n  lua_Alloc allocf = lua_getallocf(L, &ud);\n  UBox *box = (UBox *)lua_touserdata(L, idx);\n  void *temp = allocf(ud, box->box, box->bsize, newsize);\n  if (temp == NULL && newsize > 0) {  /* allocation error? */\n    resizebox(L, idx, 0);  /* free buffer */\n    luaL_error(L, \"not enough memory for buffer allocation\");\n  }\n  box->box = temp;\n  box->bsize = newsize;\n  return temp;\n}\n\n\nstatic int boxgc (lua_State *L) {\n  resizebox(L, 1, 0);\n  return 0;\n}\n\n\nstatic void *newbox (lua_State *L, size_t newsize) {\n  UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));\n  box->box = NULL;\n  box->bsize = 0;\n  if (luaL_newmetatable(L, \"LUABOX\")) {  /* creating metatable? */\n    lua_pushcfunction(L, boxgc);\n    lua_setfield(L, -2, \"__gc\");  /* metatable.__gc = boxgc */\n  }\n  lua_setmetatable(L, -2);\n  return resizebox(L, -1, newsize);\n}\n\n\n/*\n** check whether buffer is using a userdata on the stack as a temporary\n** buffer\n*/\n#define buffonstack(B)\t((B)->b != (B)->initb)\n\n\n/*\n** returns a pointer to a free area with at least 'sz' bytes\n*/\nLUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {\n  lua_State *L = B->L;\n  if (B->size - B->n < sz) {  /* not enough space? */\n    char *newbuff;\n    size_t newsize = B->size * 2;  /* double buffer size */\n    if (newsize - B->n < sz)  /* not big enough? */\n      newsize = B->n + sz;\n    if (newsize < B->n || newsize - B->n < sz)\n      luaL_error(L, \"buffer too large\");\n    /* create larger buffer */\n    if (buffonstack(B))\n      newbuff = (char *)resizebox(L, -1, newsize);\n    else {  /* no buffer yet */\n      newbuff = (char *)newbox(L, newsize);\n      memcpy(newbuff, B->b, B->n * sizeof(char));  /* copy original content */\n    }\n    B->b = newbuff;\n    B->size = newsize;\n  }\n  return &B->b[B->n];\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */\n    char *b = luaL_prepbuffsize(B, l);\n    memcpy(b, s, l * sizeof(char));\n    luaL_addsize(B, l);\n  }\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  lua_pushlstring(L, B->b, B->n);\n  if (buffonstack(B)) {\n    resizebox(L, -2, 0);  /* delete old buffer */\n    lua_remove(L, -2);  /* remove its header from the stack */\n  }\n}\n\n\nLUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {\n  luaL_addsize(B, sz);\n  luaL_pushresult(B);\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t l;\n  const char *s = lua_tolstring(L, -1, &l);\n  if (buffonstack(B))\n    lua_insert(L, -2);  /* put value below buffer */\n  luaL_addlstring(B, s, l);\n  lua_remove(L, (buffonstack(B)) ? -2 : -1);  /* remove value */\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->b = B->initb;\n  B->n = 0;\n  B->size = LUAL_BUFFERSIZE;\n}\n\n\nLUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {\n  luaL_buffinit(L, B);\n  return luaL_prepbuffsize(B, sz);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Reference system\n** =======================================================\n*/\n\n/* index of free-list header */\n#define freelist\t0\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* 'nil' has a unique fixed reference */\n  }\n  t = lua_absindex(L, t);\n  lua_rawgeti(L, t, freelist);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[freelist] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, freelist);  /* (t[freelist] = t[ref]) */\n  }\n  else  /* no free elements */\n    ref = (int)lua_rawlen(L, t) + 1;  /* get a new reference */\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = lua_absindex(L, t);\n    lua_rawgeti(L, t, freelist);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[freelist] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, freelist);  /* t[freelist] = ref */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int n;  /* number of pre-read characters */\n  FILE *f;  /* file being read */\n  char buff[BUFSIZ];  /* area for reading file */\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;  /* not used */\n  if (lf->n > 0) {  /* are there pre-read characters to be read? */\n    *size = lf->n;  /* return them (chars already in buffer) */\n    lf->n = 0;  /* no more pre-read characters */\n  }\n  else {  /* read a block from file */\n    /* 'fread' can return > 0 *and* set the EOF flag. If next call to\n       'getF' called 'fread', it might still wait for user input.\n       The next check avoids this problem. */\n    if (feof(lf->f)) return NULL;\n    *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */\n  }\n  return lf->buff;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nstatic int skipBOM (LoadF *lf) {\n  const char *p = \"\\xEF\\xBB\\xBF\";  /* UTF-8 BOM mark */\n  int c;\n  lf->n = 0;\n  do {\n    c = getc(lf->f);\n    if (c == EOF || c != *(const unsigned char *)p++) return c;\n    lf->buff[lf->n++] = c;  /* to be read by the parser */\n  } while (*p != '\\0');\n  lf->n = 0;  /* prefix matched; discard it */\n  return getc(lf->f);  /* return next character */\n}\n\n\n/*\n** reads the first character of file 'f' and skips an optional BOM mark\n** in its beginning plus its first line if it starts with '#'. Returns\n** true if it skipped the first line.  In any case, '*cp' has the\n** first \"valid\" character of the file (after the optional BOM and\n** a first-line comment).\n*/\nstatic int skipcomment (LoadF *lf, int *cp) {\n  int c = *cp = skipBOM(lf);\n  if (c == '#') {  /* first line is a comment (Unix exec. file)? */\n    do {  /* skip first line */\n      c = getc(lf->f);\n    } while (c != EOF && c != '\\n');\n    *cp = getc(lf->f);  /* skip end-of-line, if present */\n    return 1;  /* there was a comment */\n  }\n  else return 0;  /* no comment */\n}\n\n\nLUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,\n                                             const char *mode) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  if (skipcomment(&lf, &c))  /* read initial portion */\n    lf.buff[lf.n++] = '\\n';  /* add line to correct line numbers */\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    skipcomment(&lf, &c);  /* re-read initial portion */\n  }\n  if (c != EOF)\n    lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;  /* not used */\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,\n                                 const char *name, const char *mode) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name, mode);\n}\n\n\nLUALIB_API int luaL_loadstring (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return LUA_TNIL;\n  else {\n    int tt;\n    lua_pushstring(L, event);\n    tt = lua_rawget(L, -2);\n    if (tt == LUA_TNIL)  /* is metafield nil? */\n      lua_pop(L, 2);  /* remove metatable and metafield */\n    else\n      lua_remove(L, -2);  /* remove only metatable */\n    return tt;  /* return metafield type */\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = lua_absindex(L, obj);\n  if (luaL_getmetafield(L, obj, event) == LUA_TNIL)  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {\n  lua_Integer l;\n  int isnum;\n  lua_len(L, idx);\n  l = lua_tointegerx(L, -1, &isnum);\n  if (!isnum)\n    luaL_error(L, \"object length is not an integer\");\n  lua_pop(L, 1);  /* remove object */\n  return l;\n}\n\n\nLUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {\n  if (luaL_callmeta(L, idx, \"__tostring\")) {  /* metafield? */\n    if (!lua_isstring(L, -1))\n      luaL_error(L, \"'__tostring' must return a string\");\n  }\n  else {\n    switch (lua_type(L, idx)) {\n      case LUA_TNUMBER: {\n        if (lua_isinteger(L, idx))\n          lua_pushfstring(L, \"%I\", (LUAI_UACINT)lua_tointeger(L, idx));\n        else\n          lua_pushfstring(L, \"%f\", (LUAI_UACNUMBER)lua_tonumber(L, idx));\n        break;\n      }\n      case LUA_TSTRING:\n        lua_pushvalue(L, idx);\n        break;\n      case LUA_TBOOLEAN:\n        lua_pushstring(L, (lua_toboolean(L, idx) ? \"true\" : \"false\"));\n        break;\n      case LUA_TNIL:\n        lua_pushliteral(L, \"nil\");\n        break;\n      default: {\n        int tt = luaL_getmetafield(L, idx, \"__name\");  /* try name */\n        const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :\n                                                 luaL_typename(L, idx);\n        lua_pushfstring(L, \"%s: %p\", kind, lua_topointer(L, idx));\n        if (tt != LUA_TNIL)\n          lua_remove(L, -2);  /* remove '__name' */\n        break;\n      }\n    }\n  }\n  return lua_tolstring(L, -1, len);\n}\n\n\n/*\n** {======================================================\n** Compatibility with 5.1 module functions\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\nstatic const char *luaL_findtable (lua_State *L, int idx,\n                                   const char *fname, int szhint) {\n  const char *e;\n  if (idx) lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    if (lua_rawget(L, -2) == LUA_TNIL) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n/*\n** Count number of elements in a luaL_Reg list.\n*/\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l && l->name; l++) size++;\n  return size;\n}\n\n\n/*\n** Find or create a module table with a given name. The function\n** first looks at the LOADED table and, if that fails, try a\n** global variable with that name. In any case, leaves on the stack\n** the module table.\n*/\nLUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,\n                                 int sizehint) {\n  luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);\n  if (lua_getfield(L, -1, modname) != LUA_TTABLE) {  /* no LOADED[modname]? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    lua_pushglobaltable(L);\n    if (luaL_findtable(L, 0, modname, sizehint) != NULL)\n      luaL_error(L, \"name conflict for module '%s'\", modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = new table */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n}\n\n\nLUALIB_API void luaL_openlib (lua_State *L, const char *libname,\n                               const luaL_Reg *l, int nup) {\n  luaL_checkversion(L);\n  if (libname) {\n    luaL_pushmodule(L, libname, libsize(l));  /* get/create library table */\n    lua_insert(L, -(nup + 1));  /* move library table to below upvalues */\n  }\n  if (l)\n    luaL_setfuncs(L, l, nup);\n  else\n    lua_pop(L, nup);  /* remove upvalues */\n}\n\n#endif\n/* }====================================================== */\n\n/*\n** set functions from list 'l' into table at top - 'nup'; each\n** function gets the 'nup' elements at the top as upvalues.\n** Returns with only the table at the stack.\n*/\nLUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name != NULL; l++) {  /* fill the table with given functions */\n    int i;\n    for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** ensure that stack[idx][fname] has a table and push that table\n** into the stack\n*/\nLUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {\n  if (lua_getfield(L, idx, fname) == LUA_TTABLE)\n    return 1;  /* table already there */\n  else {\n    lua_pop(L, 1);  /* remove previous result */\n    idx = lua_absindex(L, idx);\n    lua_newtable(L);\n    lua_pushvalue(L, -1);  /* copy to be left at top */\n    lua_setfield(L, idx, fname);  /* assign new table to field */\n    return 0;  /* false, because did not find table there */\n  }\n}\n\n\n/*\n** Stripped-down 'require': After checking \"loaded\" table, calls 'openf'\n** to open a module, registers the result in 'package.loaded' table and,\n** if 'glb' is true, also registers the result in the global table.\n** Leaves resulting module on the top.\n*/\nLUALIB_API void luaL_requiref (lua_State *L, const char *modname,\n                               lua_CFunction openf, int glb) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, -1, modname);  /* LOADED[modname] */\n  if (!lua_toboolean(L, -1)) {  /* package not already loaded? */\n    lua_pop(L, 1);  /* remove field */\n    lua_pushcfunction(L, openf);\n    lua_pushstring(L, modname);  /* argument to open function */\n    lua_call(L, 1, 1);  /* call 'openf' to open module */\n    lua_pushvalue(L, -1);  /* make copy of module (call result) */\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = module */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n  if (glb) {\n    lua_pushvalue(L, -1);  /* copy of module */\n    lua_setglobal(L, modname);  /* _G[modname] = module */\n  }\n}\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after 'p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud; (void)osize;  /* not used */\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  lua_writestringerror(\"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                        lua_tostring(L, -1));\n  return 0;  /* return to Lua to abort */\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n\nLUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {\n  const lua_Number *v = lua_version(L);\n  if (sz != LUAL_NUMSIZES)  /* check numeric types */\n    luaL_error(L, \"core and library have incompatible numeric types\");\n  if (v != lua_version(NULL))\n    luaL_error(L, \"multiple Lua VMs detected\");\n  else if (*v != ver)\n    luaL_error(L, \"version mismatch: app. needs %f, Lua core provides %f\",\n                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n\n/* extra error code for 'luaL_loadfilex' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\n/* key, in the registry, for table of loaded modules */\n#define LUA_LOADED_TABLE\t\"_LOADED\"\n\n\n/* key, in the registry, for table of preloaded loaders */\n#define LUA_PRELOAD_TABLE\t\"_PRELOAD\"\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n#define LUAL_NUMSIZES\t(sizeof(lua_Integer)*16 + sizeof(lua_Number))\n\nLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);\n#define luaL_checkversion(L)  \\\n\t  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)\n\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\nLUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int arg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void  (luaL_setmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\nLUALIB_API int (luaL_execresult) (lua_State *L, int stat);\n\n/* predefined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n                                               const char *mode);\n\n#define luaL_loadfile(L,f)\tluaL_loadfilex(L,f,NULL)\n\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n                                   const char *name, const char *mode);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\nLUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\n\nLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\n\nLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\n                                  const char *msg, int level);\n\nLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\n                                 lua_CFunction openf, int glb);\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n\n#define luaL_newlibtable(L,l)\t\\\n  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n\n#define luaL_newlib(L,l)  \\\n  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n\n#define luaL_argcheck(L, cond,arg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (arg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n#define luaL_loadbuffer(L,s,sz,n)\tluaL_loadbufferx(L,s,sz,n,NULL)\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\ntypedef struct luaL_Buffer {\n  char *b;  /* buffer address */\n  size_t size;  /* buffer size */\n  size_t n;  /* number of characters in buffer */\n  lua_State *L;\n  char initb[LUAL_BUFFERSIZE];  /* initial buffer */\n} luaL_Buffer;\n\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\\n   ((B)->b[(B)->n++] = (c)))\n\n#define luaL_addsize(B,s)\t((B)->n += (s))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\n\n#define luaL_prepbuffer(B)\tluaL_prepbuffsize(B, LUAL_BUFFERSIZE)\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** File handles for IO library\n** =======================================================\n*/\n\n/*\n** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\n** initial structure 'luaL_Stream' (it may contain other fields\n** after that initial structure).\n*/\n\n#define LUA_FILEHANDLE          \"FILE*\"\n\n\ntypedef struct luaL_Stream {\n  FILE *f;  /* stream (NULL for incompletely created streams) */\n  lua_CFunction closef;  /* to close stream (NULL for closed streams) */\n} luaL_Stream;\n\n/* }====================================================== */\n\n\n\n/* compatibility with old module system */\n#if defined(LUA_COMPAT_MODULE)\n\nLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\n                                   int sizehint);\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\n\n#define luaL_register(L,n,l)\t(luaL_openlib(L,(n),(l),0))\n\n#endif\n\n\n/*\n** {==================================================================\n** \"Abstraction Layer\" for basic report of messages and errors\n** ===================================================================\n*/\n\n/* print a string */\n#if !defined(lua_writestring)\n#define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)\n#endif\n\n/* print a newline and flush the output */\n#if !defined(lua_writeline)\n#define lua_writeline()        (lua_writestring(\"\\n\", 1), fflush(stdout))\n#endif\n\n/* print an error message */\n#if !defined(lua_writestringerror)\n#define lua_writestringerror(s,p) \\\n        (fprintf(stderr, (s), (p)), fflush(stderr))\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {============================================================\n** Compatibility with deprecated conversions\n** =============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define luaL_checkunsigned(L,a)\t((lua_Unsigned)luaL_checkinteger(L,a))\n#define luaL_optunsigned(L,a,d)\t\\\n\t((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))\n\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#endif\n/* }============================================================ */\n\n\n\n#endif\n\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    size_t l;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tolstring(L, -1, &l);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, \"'tostring' must return a string to 'print'\");\n    if (i>1) lua_writestring(\"\\t\", 1);\n    lua_writestring(s, l);\n    lua_pop(L, 1);  /* pop result */\n  }\n  lua_writeline();\n  return 0;\n}\n\n\n#define SPACECHARS\t\" \\f\\n\\r\\t\\v\"\n\nstatic const char *b_str2int (const char *s, int base, lua_Integer *pn) {\n  lua_Unsigned n = 0;\n  int neg = 0;\n  s += strspn(s, SPACECHARS);  /* skip initial spaces */\n  if (*s == '-') { s++; neg = 1; }  /* handle signal */\n  else if (*s == '+') s++;\n  if (!isalnum((unsigned char)*s))  /* no digit? */\n    return NULL;\n  do {\n    int digit = (isdigit((unsigned char)*s)) ? *s - '0'\n                   : (toupper((unsigned char)*s) - 'A') + 10;\n    if (digit >= base) return NULL;  /* invalid numeral */\n    n = n * base + digit;\n    s++;\n  } while (isalnum((unsigned char)*s));\n  s += strspn(s, SPACECHARS);  /* skip trailing spaces */\n  *pn = (lua_Integer)((neg) ? (0u - n) : n);\n  return s;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */\n    luaL_checkany(L, 1);\n    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */\n      lua_settop(L, 1);  /* yes; return it */\n      return 1;\n    }\n    else {\n      size_t l;\n      const char *s = lua_tolstring(L, 1, &l);\n      if (s != NULL && lua_stringtonumber(L, s) == l + 1)\n        return 1;  /* successful conversion to number */\n      /* else not a number */\n    }\n  }\n  else {\n    size_t l;\n    const char *s;\n    lua_Integer n = 0;  /* to avoid warnings */\n    lua_Integer base = luaL_checkinteger(L, 2);\n    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */\n    s = lua_tolstring(L, 1, &l);\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    if (b_str2int(s, (int)base, &n) == s + l) {\n      lua_pushinteger(L, n);\n      return 1;\n    }  /* else not a number */\n  }  /* else not a number */\n  lua_pushnil(L);  /* not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = (int)luaL_optinteger(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {\n    luaL_where(L, level);   /* add extra information */\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\") != LUA_TNIL)\n    return luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawlen (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,\n                   \"table or string expected\");\n  lua_pushinteger(L, lua_rawlen(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\n    \"isrunning\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n    LUA_GCISRUNNING};\n  int o = optsnum[luaL_checkoption(L, 1, \"collect\", opts)];\n  int ex = (int)luaL_optinteger(L, 2, 0);\n  int res = lua_gc(L, o, ex);\n  switch (o) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: case LUA_GCISRUNNING: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushinteger(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t != LUA_TNONE, 1, \"value expected\");\n  lua_pushstring(L, lua_typename(L, t));\n  return 1;\n}\n\n\nstatic int pairsmeta (lua_State *L, const char *method, int iszero,\n                      lua_CFunction iter) {\n  luaL_checkany(L, 1);\n  if (luaL_getmetafield(L, 1, method) == LUA_TNIL) {  /* no metamethod? */\n    lua_pushcfunction(L, iter);  /* will return generator, */\n    lua_pushvalue(L, 1);  /* state, */\n    if (iszero) lua_pushinteger(L, 0);  /* and initial value */\n    else lua_pushnil(L);\n  }\n  else {\n    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */\n    lua_call(L, 1, 3);  /* get 3 values from metamethod */\n  }\n  return 3;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  return pairsmeta(L, \"__pairs\", 0, luaB_next);\n}\n\n\n/*\n** Traversal function for 'ipairs'\n*/\nstatic int ipairsaux (lua_State *L) {\n  lua_Integer i = luaL_checkinteger(L, 2) + 1;\n  lua_pushinteger(L, i);\n  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;\n}\n\n\n/*\n** 'ipairs' function. Returns 'ipairsaux', given \"table\", 0.\n** (The given \"table\" may not be a table.)\n*/\nstatic int luaB_ipairs (lua_State *L) {\n#if defined(LUA_COMPAT_IPAIRS)\n  return pairsmeta(L, \"__ipairs\", 1, ipairsaux);\n#else\n  luaL_checkany(L, 1);\n  lua_pushcfunction(L, ipairsaux);  /* iteration function */\n  lua_pushvalue(L, 1);  /* state */\n  lua_pushinteger(L, 0);  /* initial value */\n  return 3;\n#endif\n}\n\n\nstatic int load_aux (lua_State *L, int status, int envidx) {\n  if (status == LUA_OK) {\n    if (envidx != 0) {  /* 'env' parameter? */\n      lua_pushvalue(L, envidx);  /* environment for loaded function */\n      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */\n        lua_pop(L, 1);  /* remove 'env' if not used by previous call */\n    }\n    return 1;\n  }\n  else {  /* error (message is on top of the stack) */\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  const char *mode = luaL_optstring(L, 2, NULL);\n  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */\n  int status = luaL_loadfilex(L, fname, mode);\n  return load_aux(L, status, env);\n}\n\n\n/*\n** {======================================================\n** Generic Read function\n** =======================================================\n*/\n\n\n/*\n** reserved slot, above all arguments, to hold a copy of the returned\n** string to avoid it being collected while parsed. 'load' has four\n** optional arguments (chunk, source name, mode, and environment).\n*/\n#define RESERVEDSLOT\t5\n\n\n/*\n** Reader for generic 'load' function: 'lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)(ud);  /* not used */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* pop result */\n    *size = 0;\n    return NULL;\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"reader function must return a string\");\n  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */\n  return lua_tolstring(L, RESERVEDSLOT, size);\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  size_t l;\n  const char *s = lua_tolstring(L, 1, &l);\n  const char *mode = luaL_optstring(L, 3, \"bt\");\n  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */\n  if (s != NULL) {  /* loading a string? */\n    const char *chunkname = luaL_optstring(L, 2, s);\n    status = luaL_loadbufferx(L, s, l, chunkname, mode);\n  }\n  else {  /* loading from a reader function */\n    const char *chunkname = luaL_optstring(L, 2, \"=(load)\");\n    luaL_checktype(L, 1, LUA_TFUNCTION);\n    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */\n    status = lua_load(L, generic_reader, NULL, chunkname, mode);\n  }\n  return load_aux(L, status, env);\n}\n\n/* }====================================================== */\n\n\nstatic int dofilecont (lua_State *L, int d1, lua_KContext d2) {\n  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */\n  return lua_gettop(L) - 1;\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  lua_settop(L, 1);\n  if (luaL_loadfile(L, fname) != LUA_OK)\n    return lua_error(L);\n  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);\n  return dofilecont(L, 0, 0);\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  if (lua_toboolean(L, 1))  /* condition is true? */\n    return lua_gettop(L);  /* return all arguments */\n  else {  /* error */\n    luaL_checkany(L, 1);  /* there must be a condition */\n    lua_remove(L, 1);  /* remove it */\n    lua_pushliteral(L, \"assertion failed!\");  /* default message */\n    lua_settop(L, 1);  /* leave only message (default if no other one) */\n    return luaB_error(L);  /* call 'error' */\n  }\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    lua_Integer i = luaL_checkinteger(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - (int)i;\n  }\n}\n\n\n/*\n** Continuation function for 'pcall' and 'xpcall'. Both functions\n** already pushed a 'true' before doing the call, so in case of success\n** 'finishpcall' only has to return everything in the stack minus\n** 'extra' values (where 'extra' is exactly the number of items to be\n** ignored).\n*/\nstatic int finishpcall (lua_State *L, int status, lua_KContext extra) {\n  if (status != LUA_OK && status != LUA_YIELD) {  /* error? */\n    lua_pushboolean(L, 0);  /* first result (false) */\n    lua_pushvalue(L, -2);  /* error message */\n    return 2;  /* return false, msg */\n  }\n  else\n    return lua_gettop(L) - (int)extra;  /* return all results */\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  lua_pushboolean(L, 1);  /* first result if no errors */\n  lua_insert(L, 1);  /* put it in place */\n  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);\n  return finishpcall(L, status, 0);\n}\n\n\n/*\n** Do a protected call with error handling. After 'lua_rotate', the\n** stack will have <f, err, true, f, [args...]>; so, the function passes\n** 2 to 'finishpcall' to skip the 2 first values when returning results.\n*/\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  int n = lua_gettop(L);\n  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */\n  lua_pushboolean(L, 1);  /* first result */\n  lua_pushvalue(L, 1);  /* function */\n  lua_rotate(L, 3, 2);  /* move them below function's arguments */\n  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);\n  return finishpcall(L, status, 2);\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_tolstring(L, 1, NULL);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"ipairs\", luaB_ipairs},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n#if defined(LUA_COMPAT_LOADSTRING)\n  {\"loadstring\", luaB_load},\n#endif\n  {\"next\", luaB_next},\n  {\"pairs\", luaB_pairs},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawlen\", luaB_rawlen},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"xpcall\", luaB_xpcall},\n  /* placeholders */\n  {\"_G\", NULL},\n  {\"_VERSION\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_base (lua_State *L) {\n  /* open lib into global table */\n  lua_pushglobaltable(L);\n  luaL_setfuncs(L, base_funcs, 0);\n  /* set global _G */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_G\");\n  /* set global _VERSION */\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setfield(L, -2, \"_VERSION\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lbitlib.c",
    "content": "/*\n** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $\n** Standard library for bitwise operations\n** See Copyright Notice in lua.h\n*/\n\n#define lbitlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if defined(LUA_COMPAT_BITLIB)\t\t/* { */\n\n\n#define pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define checkunsigned(L,i)\t((lua_Unsigned)luaL_checkinteger(L,i))\n\n\n/* number of bits to consider in a number */\n#if !defined(LUA_NBITS)\n#define LUA_NBITS\t32\n#endif\n\n\n/*\n** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must\n** be made in two parts to avoid problems when LUA_NBITS is equal to the\n** number of bits in a lua_Unsigned.)\n*/\n#define ALLONES\t\t(~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))\n\n\n/* macro to trim extra bits */\n#define trim(x)\t\t((x) & ALLONES)\n\n\n/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */\n#define mask(n)\t\t(~((ALLONES << 1) << ((n) - 1)))\n\n\n\nstatic lua_Unsigned andaux (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = ~(lua_Unsigned)0;\n  for (i = 1; i <= n; i++)\n    r &= checkunsigned(L, i);\n  return trim(r);\n}\n\n\nstatic int b_and (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_test (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  lua_pushboolean(L, r != 0);\n  return 1;\n}\n\n\nstatic int b_or (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r |= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_xor (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r ^= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_not (lua_State *L) {\n  lua_Unsigned r = ~checkunsigned(L, 1);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) {\n  if (i < 0) {  /* shift right? */\n    i = -i;\n    r = trim(r);\n    if (i >= LUA_NBITS) r = 0;\n    else r >>= i;\n  }\n  else {  /* shift left */\n    if (i >= LUA_NBITS) r = 0;\n    else r <<= i;\n    r = trim(r);\n  }\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_lshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_arshift (lua_State *L) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  lua_Integer i = luaL_checkinteger(L, 2);\n  if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1))))\n    return b_shift(L, r, -i);\n  else {  /* arithmetic shift for 'negative' number */\n    if (i >= LUA_NBITS) r = ALLONES;\n    else\n      r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i));  /* add signal bit */\n    pushunsigned(L, r);\n    return 1;\n  }\n}\n\n\nstatic int b_rot (lua_State *L, lua_Integer d) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  int i = d & (LUA_NBITS - 1);  /* i = d % NBITS */\n  r = trim(r);\n  if (i != 0)  /* avoid undefined shift of LUA_NBITS when i == 0 */\n    r = (r << i) | (r >> (LUA_NBITS - i));\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_lrot (lua_State *L) {\n  return b_rot(L, luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rrot (lua_State *L) {\n  return b_rot(L, -luaL_checkinteger(L, 2));\n}\n\n\n/*\n** get field and width arguments for field-manipulation functions,\n** checking whether they are valid.\n** ('luaL_error' called without 'return' to avoid later warnings about\n** 'width' being used uninitialized.)\n*/\nstatic int fieldargs (lua_State *L, int farg, int *width) {\n  lua_Integer f = luaL_checkinteger(L, farg);\n  lua_Integer w = luaL_optinteger(L, farg + 1, 1);\n  luaL_argcheck(L, 0 <= f, farg, \"field cannot be negative\");\n  luaL_argcheck(L, 0 < w, farg + 1, \"width must be positive\");\n  if (f + w > LUA_NBITS)\n    luaL_error(L, \"trying to access non-existent bits\");\n  *width = (int)w;\n  return (int)f;\n}\n\n\nstatic int b_extract (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  int f = fieldargs(L, 2, &w);\n  r = (r >> f) & mask(w);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_replace (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  lua_Unsigned v = trim(checkunsigned(L, 2));\n  int f = fieldargs(L, 3, &w);\n  lua_Unsigned m = mask(w);\n  r = (r & ~(m << f)) | ((v & m) << f);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic const luaL_Reg bitlib[] = {\n  {\"arshift\", b_arshift},\n  {\"band\", b_and},\n  {\"bnot\", b_not},\n  {\"bor\", b_or},\n  {\"bxor\", b_xor},\n  {\"btest\", b_test},\n  {\"extract\", b_extract},\n  {\"lrotate\", b_lrot},\n  {\"lshift\", b_lshift},\n  {\"replace\", b_replace},\n  {\"rrotate\", b_rrot},\n  {\"rshift\", b_rshift},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  luaL_newlib(L, bitlib);\n  return 1;\n}\n\n\n#else\t\t\t\t\t/* }{ */\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  return luaL_error(L, \"library 'bit32' has been deprecated\");\n}\n\n#endif\t\t\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.4/src/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <math.h>\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/* Maximum number of registers in a Lua function (must fit in 8 bits) */\n#define MAXREGS\t\t255\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\n/*\n** If expression is a numeric constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nstatic int tonumeral(const expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a numeral */\n  switch (e->k) {\n    case VKINT:\n      if (v) setivalue(v, e->u.ival);\n      return 1;\n    case VKFLT:\n      if (v) setfltvalue(v, e->u.nval);\n      return 1;\n    default: return 0;\n  }\n}\n\n\n/*\n** Create a OP_LOADNIL instruction, but try to optimize: if the previous\n** instruction is also OP_LOADNIL and ranges are compatible, adjust\n** range of previous instruction instead of emitting a new one. (For\n** instance, 'local a; local b' will generate a single opcode.)\n*/\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  int l = from + n - 1;  /* last register to set nil */\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    previous = &fs->f->code[fs->pc-1];\n    if (GET_OPCODE(*previous) == OP_LOADNIL) {  /* previous is LOADNIL? */\n      int pfrom = GETARG_A(*previous);  /* get previous range */\n      int pl = pfrom + GETARG_B(*previous);\n      if ((pfrom <= from && from <= pl + 1) ||\n          (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */\n        if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */\n        if (pl > l) l = pl;  /* l = max(l, pl) */\n        SETARG_A(*previous, from);\n        SETARG_B(*previous, l - from);\n        return;\n      }\n    }  /* else go through */\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */\n}\n\n\n/*\n** Gets the destination address of a jump instruction. Used to traverse\n** a list of jumps.\n*/\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\n/*\n** Fix jump instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua)\n*/\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** Concatenate jump-list 'l2' into jump-list 'l1'\n*/\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;  /* nothing to concatenate? */\n  else if (*l1 == NO_JUMP)  /* no original list? */\n    *l1 = l2;  /* 'l1' points to 'l2' */\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);  /* last element links to 'l2' */\n  }\n}\n\n\n/*\n** Create a jump instruction and return its position, so its destination\n** can be fixed later (with 'fixjump'). If there are jumps to\n** this position (kept in 'jpc'), link them all together so that\n** 'patchlistaux' will fix all them directly to the final destination.\n*/\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;  /* no more jumps to here */\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\n/*\n** Code a 'return' instruction\n*/\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\n/*\n** Code a \"conditional jump\", that is, a test or comparison opcode\n** followed by a jump. Return jump position.\n*/\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\n/*\n** returns current 'pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\n/*\n** Returns the position of the instruction \"controlling\" a given\n** jump (that is, its condition), or the jump itself if it is\n** unconditional.\n*/\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** Patch destination register for a TESTSET instruction.\n** If instruction in position 'node' is not a TESTSET, return 0 (\"fails\").\n** Otherwise, if 'reg' is not 'NO_REG', set it as the destination\n** register. Otherwise, change instruction to a simple 'TEST' (produces\n** no register value)\n*/\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else {\n     /* no register to put value or register already has the value;\n        change instruction to simple test */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n  }\n  return 1;\n}\n\n\n/*\n** Traverse a list of tests ensuring no one produces a value\n*/\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\n/*\n** Traverse a list of tests, patching their destination address and\n** registers: tests producing values jump to 'vtarget' (and put their\n** values in 'reg'), other tests jump to 'dtarget'.\n*/\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\n/*\n** Ensure all pending jumps to current position are fixed (jumping\n** to current position with no values) and reset list of pending\n** jumps\n*/\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\n/*\n** Add elements in 'list' to list of pending jumps to \"here\"\n** (current position)\n*/\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);  /* mark \"here\" as a jump target */\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\n/*\n** Path all jumps in 'list' to jump to 'target'.\n** (The assert means that we cannot fix a jump to a forward address\n** because we only know addresses once code is generated.)\n*/\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)  /* 'target' is current position? */\n    luaK_patchtohere(fs, list);  /* add list to pending jumps */\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\n/*\n** Path all jumps in 'list' to close upvalues up to given 'level'\n** (The assertion checks that jumps either were closing nothing\n** or were closing higher levels, from inner blocks.)\n*/\nvoid luaK_patchclose (FuncState *fs, int list, int level) {\n  level++;  /* argument is +1 to reserve 0 as non-op */\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&\n                (GETARG_A(fs->f->code[list]) == 0 ||\n                 GETARG_A(fs->f->code[list]) >= level));\n    SETARG_A(fs->f->code[list], level);\n  }\n}\n\n\n/*\n** Emit instruction 'i', checking for array sizes and saving also its\n** line information. Return 'i' position.\n*/\nstatic int luaK_code (FuncState *fs, Instruction i) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* 'pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"opcodes\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"opcodes\");\n  f->lineinfo[fs->pc] = fs->ls->lastline;\n  return fs->pc++;\n}\n\n\n/*\n** Format and emit an 'iABC' instruction. (Assertions check consistency\n** of parameters versus opcode.)\n*/\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c));\n}\n\n\n/*\n** Format and emit an 'iABx' instruction.\n*/\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, bc));\n}\n\n\n/*\n** Emit an \"extra argument\" instruction (format 'iAx')\n*/\nstatic int codeextraarg (FuncState *fs, int a) {\n  lua_assert(a <= MAXARG_Ax);\n  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));\n}\n\n\n/*\n** Emit a \"load constant\" instruction, using either 'OP_LOADK'\n** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'\n** instruction with \"extra argument\".\n*/\nint luaK_codek (FuncState *fs, int reg, int k) {\n  if (k <= MAXARG_Bx)\n    return luaK_codeABx(fs, OP_LOADK, reg, k);\n  else {\n    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);\n    codeextraarg(fs, k);\n    return p;\n  }\n}\n\n\n/*\n** Check register-stack level, keeping track of its maximum size\n** in field 'maxstacksize'\n*/\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXREGS)\n      luaX_syntaxerror(fs->ls,\n        \"function or expression needs too many registers\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\n/*\n** Reserve 'n' registers in register stack\n*/\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\n/*\n** Free register 'reg', if it is neither a constant index nor\n** a local variable.\n)\n*/\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\n/*\n** Free register used by expression 'e' (if any)\n*/\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.info);\n}\n\n\n/*\n** Free registers used by expressions 'e1' and 'e2' (if any) in proper\n** order.\n*/\nstatic void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {\n  int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;\n  int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;\n  if (r1 > r2) {\n    freereg(fs, r1);\n    freereg(fs, r2);\n  }\n  else {\n    freereg(fs, r2);\n    freereg(fs, r1);\n  }\n}\n\n\n/*\n** Add constant 'v' to prototype's list of constants (field 'k').\n** Use scanner's table to cache position of constants in constant list\n** and try to reuse constants. Because some values should not be used\n** as keys (nil cannot be a key, integer keys can collapse with float\n** keys), the caller must provide a useful 'key' for indexing the cache.\n*/\nstatic int addk (FuncState *fs, TValue *key, TValue *v) {\n  lua_State *L = fs->ls->L;\n  Proto *f = fs->f;\n  TValue *idx = luaH_set(L, fs->ls->h, key);  /* index scanner table */\n  int k, oldsize;\n  if (ttisinteger(idx)) {  /* is there an index there? */\n    k = cast_int(ivalue(idx));\n    /* correct value? (warning: must distinguish floats from integers!) */\n    if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&\n                      luaV_rawequalobj(&f->k[k], v))\n      return k;  /* reuse index */\n  }\n  /* constant not found; create a new entry */\n  oldsize = f->sizek;\n  k = fs->nk;\n  /* numerical value does not need GC barrier;\n     table has no metatable, so it does not need to invalidate cache */\n  setivalue(idx, k);\n  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, \"constants\");\n  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n  setobj(L, &f->k[k], v);\n  fs->nk++;\n  luaC_barrier(L, f, v);\n  return k;\n}\n\n\n/*\n** Add a string to list of constants and return its index.\n*/\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->ls->L, &o, s);\n  return addk(fs, &o, &o);  /* use string itself as key */\n}\n\n\n/*\n** Add an integer to list of constants and return its index.\n** Integers use userdata as keys to avoid collision with floats with\n** same value; conversion to 'void*' is used only for hashing, so there\n** are no \"precision\" problems.\n*/\nint luaK_intK (FuncState *fs, lua_Integer n) {\n  TValue k, o;\n  setpvalue(&k, cast(void*, cast(size_t, n)));\n  setivalue(&o, n);\n  return addk(fs, &k, &o);\n}\n\n/*\n** Add a float to list of constants and return its index.\n*/\nstatic int luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setfltvalue(&o, r);\n  return addk(fs, &o, &o);  /* use number itself as key */\n}\n\n\n/*\n** Add a boolean to list of constants and return its index.\n*/\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add nil to list of constants and return its index.\n*/\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->ls->L, &k, fs->ls->h);\n  return addk(fs, &k, &v);\n}\n\n\n/*\n** Fix an expression to return the number of results 'nresults'.\n** Either 'e' is a multi-ret expression (function call or vararg)\n** or 'nresults' is LUA_MULTRET (as any expression can satisfy that).\n*/\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getinstruction(fs, e), nresults + 1);\n  }\n  else if (e->k == VVARARG) {\n    Instruction *pc = &getinstruction(fs, e);\n    SETARG_B(*pc, nresults + 1);\n    SETARG_A(*pc, fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n  else lua_assert(nresults == LUA_MULTRET);\n}\n\n\n/*\n** Fix an expression to return one result.\n** If expression is not a multi-ret expression (function call or\n** vararg), it already returns one result, so nothing needs to be done.\n** Function calls become VNONRELOC expressions (as its result comes\n** fixed in the base register of the call), while vararg expressions\n** become VRELOCABLE (as OP_VARARG puts its results where it wants).\n** (Calls are created returning one result, so that does not need\n** to be fixed.)\n*/\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    /* already returns 1 value */\n    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);\n    e->k = VNONRELOC;  /* result has fixed position */\n    e->u.info = GETARG_A(getinstruction(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getinstruction(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\n/*\n** Ensure that expression 'e' is not a variable.\n*/\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {  /* already in a register */\n      e->k = VNONRELOC;  /* becomes a non-relocatable value */\n      break;\n    }\n    case VUPVAL: {  /* move value to some (pending) register */\n      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      OpCode op;\n      freereg(fs, e->u.ind.idx);\n      if (e->u.ind.vt == VLOCAL) {  /* is 't' in a register? */\n        freereg(fs, e->u.ind.t);\n        op = OP_GETTABLE;\n      }\n      else {\n        lua_assert(e->u.ind.vt == VUPVAL);\n        op = OP_GETTABUP;  /* 't' is in an upvalue */\n      }\n      e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG: case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\n/*\n** Ensures expression value is in register 'reg' (and therefore\n** 'e' will become a non-relocatable expression).\n*/\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE: case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codek(fs, reg, e->u.info);\n      break;\n    }\n    case VKFLT: {\n      luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VKINT: {\n      luaK_codek(fs, reg, luaK_intK(fs, e->u.ival));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getinstruction(fs, e);\n      SETARG_A(*pc, reg);  /* instruction will put result in 'reg' */\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures expression value is in any register.\n*/\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {  /* no fixed register yet? */\n    luaK_reserveregs(fs, 1);  /* get a register */\n    discharge2reg(fs, e, fs->freereg-1);  /* put value there */\n  }\n}\n\n\nstatic int code_loadbool (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** or produce an inverted value\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in register 'reg'.\n** If expression has jumps, need to patch these jumps either to\n** its final position or to \"load\" instructions (for those tests\n** that do not produce values).\n*/\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)  /* expression itself is a test? */\n    luaK_concat(fs, &e->t, e->u.info);  /* put this jump in 't' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_loadbool(fs, reg, 0, 1);\n      p_t = code_loadbool(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in next available register.\n*/\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in some (any) register and return that register.\n*/\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {  /* expression already has a register? */\n    if (!hasjumps(e))  /* no jumps? */\n      return e->u.info;  /* result is already in a register */\n    if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.info);  /* put final result in it */\n      return e->u.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* otherwise, use next available register */\n  return e->u.info;\n}\n\n\n/*\n** Ensures final expression result is either in a register or in an\n** upvalue.\n*/\nvoid luaK_exp2anyregup (FuncState *fs, expdesc *e) {\n  if (e->k != VUPVAL || hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Ensures final expression result is either in a register or it is\n** a constant.\n*/\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\n/*\n** Ensures final expression result is in a valid R/K index\n** (that is, it is either in a register or in 'k' with an index\n** in the range of R/K indices).\n** Returns R/K index.\n*/\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {  /* move constants to 'k' */\n    case VTRUE: e->u.info = boolK(fs, 1); goto vk;\n    case VFALSE: e->u.info = boolK(fs, 0); goto vk;\n    case VNIL: e->u.info = nilK(fs); goto vk;\n    case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;\n    case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;\n    case VK:\n     vk:\n      e->k = VK;\n      if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */\n        return RKASK(e->u.info);\n      else break;\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Generate code to store result of expression 'ex' into variable 'var'.\n*/\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.info);  /* compute 'ex' into proper place */\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);\n      break;\n    }\n    case VINDEXED: {\n      OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);\n      break;\n    }\n    default: lua_assert(0);  /* invalid var kind to store */\n  }\n  freeexp(fs, ex);\n}\n\n\n/*\n** Emit SELF instruction (convert expression 'e' into 'e:key(e,').\n*/\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int ereg;\n  luaK_exp2anyreg(fs, e);\n  ereg = e->u.info;  /* register where 'e' was placed */\n  freeexp(fs, e);\n  e->u.info = fs->freereg;  /* base register for op_self */\n  e->k = VNONRELOC;  /* self expression has a fixed register */\n  luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */\n  luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n}\n\n\n/*\n** Negate condition 'e' (where 'e' is a comparison).\n*/\nstatic void negatecondition (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\n/*\n** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'\n** is true, code will jump if 'e' is true.) Return jump position.\n** Optimize when 'e' is 'not' something, inverting the condition\n** and removing the 'not'.\n*/\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getinstruction(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);\n}\n\n\n/*\n** Emit code to go through if 'e' is true, jump otherwise.\n*/\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {  /* condition? */\n      negatecondition(fs, e);  /* jump when it is false */\n      pc = e->u.info;  /* save jump position */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);  /* jump when false */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert new jump in false list */\n  luaK_patchtohere(fs, e->t);  /* true list jumps to here (to go through) */\n  e->t = NO_JUMP;\n}\n\n\n/*\n** Emit code to go through if 'e' is false, jump otherwise.\n*/\nvoid luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {\n      pc = e->u.info;  /* already jump if true */\n      break;\n    }\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);  /* jump if true */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert new jump in 't' list */\n  luaK_patchtohere(fs, e->f);  /* false list jumps to here (to go through) */\n  e->f = NO_JUMP;\n}\n\n\n/*\n** Code 'not e', doing constant folding.\n*/\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;  /* true == not nil == not false */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      e->k = VFALSE;  /* false == not \"x\" == not 0.5 == not 1 == not true */\n      break;\n    }\n    case VJMP: {\n      negatecondition(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: lua_assert(0);  /* cannot happen */\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);  /* values are useless when negated */\n  removevalues(fs, e->t);\n}\n\n\n/*\n** Create expression 't[k]'. 't' must have its final result already in a\n** register or upvalue.\n*/\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));\n  t->u.ind.t = t->u.info;  /* register or upvalue index */\n  t->u.ind.idx = luaK_exp2RK(fs, k);  /* R/K index for key */\n  t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL;\n  t->k = VINDEXED;\n}\n\n\n/*\n** Return false if folding can raise an error.\n** Bitwise operations need operands convertible to integers; division\n** operations cannot have 0 as divisor.\n*/\nstatic int validop (int op, TValue *v1, TValue *v2) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: {  /* conversion errors */\n      lua_Integer i;\n      return (tointeger(v1, &i) && tointeger(v2, &i));\n    }\n    case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD:  /* division by 0 */\n      return (nvalue(v2) != 0);\n    default: return 1;  /* everything else is valid */\n  }\n}\n\n\n/*\n** Try to \"constant-fold\" an operation; return 1 iff successful.\n** (In this case, 'e1' has the final result.)\n*/\nstatic int constfolding (FuncState *fs, int op, expdesc *e1,\n                                                const expdesc *e2) {\n  TValue v1, v2, res;\n  if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))\n    return 0;  /* non-numeric operands or not safe to fold */\n  luaO_arith(fs->ls->L, op, &v1, &v2, &res);  /* does operation */\n  if (ttisinteger(&res)) {\n    e1->k = VKINT;\n    e1->u.ival = ivalue(&res);\n  }\n  else {  /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */\n    lua_Number n = fltvalue(&res);\n    if (luai_numisnan(n) || n == 0)\n      return 0;\n    e1->k = VKFLT;\n    e1->u.nval = n;\n  }\n  return 1;\n}\n\n\n/*\n** Emit code for unary expressions that \"produce values\"\n** (everything but 'not').\n** Expression to produce final result will be encoded in 'e'.\n*/\nstatic void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {\n  int r = luaK_exp2anyreg(fs, e);  /* opcodes operate only on registers */\n  freeexp(fs, e);\n  e->u.info = luaK_codeABC(fs, op, 0, r, 0);  /* generate opcode */\n  e->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\"\n** (everything but logical operators 'and'/'or' and comparison\n** operators).\n** Expression to produce final result will be encoded in 'e1'.\n** Because 'luaK_exp2RK' can free registers, its calls must be\n** in \"stack order\" (that is, first on 'e2', which may have more\n** recent registers to be released).\n*/\nstatic void codebinexpval (FuncState *fs, OpCode op,\n                           expdesc *e1, expdesc *e2, int line) {\n  int rk2 = luaK_exp2RK(fs, e2);  /* both operands are \"RK\" */\n  int rk1 = luaK_exp2RK(fs, e1);\n  freeexps(fs, e1, e2);\n  e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2);  /* generate opcode */\n  e1->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for comparisons.\n** 'e1' was already put in R/K form by 'luaK_infix'.\n*/\nstatic void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {\n  int rk1 = (e1->k == VK) ? RKASK(e1->u.info)\n                          : check_exp(e1->k == VNONRELOC, e1->u.info);\n  int rk2 = luaK_exp2RK(fs, e2);\n  freeexps(fs, e1, e2);\n  switch (opr) {\n    case OPR_NE: {  /* '(a ~= b)' ==> 'not (a == b)' */\n      e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2);\n      break;\n    }\n    case OPR_GT: case OPR_GE: {\n      /* '(a > b)' ==> '(b < a)';  '(a >= b)' ==> '(b <= a)' */\n      OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk2, rk1);  /* invert operands */\n      break;\n    }\n    default: {  /* '==', '<', '<=' use their own opcodes */\n      OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk1, rk2);\n      break;\n    }\n  }\n  e1->k = VJMP;\n}\n\n\n/*\n** Aplly prefix operation 'op' to expression 'e'.\n*/\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {\n  static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};\n  switch (op) {\n    case OPR_MINUS: case OPR_BNOT:  /* use 'ef' as fake 2nd operand */\n      if (constfolding(fs, op + LUA_OPUNM, e, &ef))\n        break;\n      /* FALLTHROUGH */\n    case OPR_LEN:\n      codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);\n      break;\n    case OPR_NOT: codenot(fs, e); break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Process 1st operand 'v' of binary operation 'op' before reading\n** 2nd operand.\n*/\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);  /* go ahead only if 'v' is true */\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);  /* go ahead only if 'v' is false */\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the 'stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB:\n    case OPR_MUL: case OPR_DIV: case OPR_IDIV:\n    case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2RK(fs, v);\n      /* else keep numeral, which may be folded with 2nd operand */\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\n/*\n** Finalize code for binary operation, after reading 2nd operand.\n** For '(a .. b .. c)' (which is '(a .. (b .. c))', because\n** concatenation is right associative), merge second CONCAT into first\n** one.\n*/\nvoid luaK_posfix (FuncState *fs, BinOpr op,\n                  expdesc *e1, expdesc *e2, int line) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE &&\n          GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getinstruction(fs, e2), e1->u.info);\n        e1->k = VRELOCABLE; e1->u.info = e2->u.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codebinexpval(fs, OP_CONCAT, e1, e2, line);\n      }\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_IDIV: case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!constfolding(fs, op + LUA_OPADD, e1, e2))\n        codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);\n      break;\n    }\n    case OPR_EQ: case OPR_LT: case OPR_LE:\n    case OPR_NE: case OPR_GT: case OPR_GE: {\n      codecomp(fs, op, e1, e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Change line information associated with current position.\n*/\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\n/*\n** Emit a SETLIST instruction.\n** 'base' is register that keeps table;\n** 'nelems' is #table plus those to be stored now;\n** 'tostore' is number of values (in registers 'base + 1',...) to add to\n** table (or LUA_MULTRET to add up to stack top).\n*/\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else if (c <= MAXARG_Ax) {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    codeextraarg(fs, c);\n  }\n  else\n    luaX_syntaxerror(fs->ls, \"constructor too long\");\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums  (ORDER OP)\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,\n  OPR_DIV,\n  OPR_IDIV,\n  OPR_BAND, OPR_BOR, OPR_BXOR,\n  OPR_SHL, OPR_SHR,\n  OPR_CONCAT,\n  OPR_EQ, OPR_LT, OPR_LE,\n  OPR_NE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n/* get (pointer to) instruction of given 'expdesc' */\n#define getinstruction(fs,e)\t((fs)->f->code[(e)->u.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\n#define luaK_jumpto(fs,t)\tluaK_patchlist(fs, luaK_jump(fs), t)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,\n                            expdesc *v2, int line);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lcorolib.c",
    "content": "/*\n** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $\n** Coroutine Library\n** See Copyright Notice in lua.h\n*/\n\n#define lcorolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic lua_State *getco (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"thread expected\");\n  return co;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status;\n  if (!lua_checkstack(co, narg)) {\n    lua_pushliteral(L, \"too many arguments to resume\");\n    return -1;  /* error flag */\n  }\n  if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {\n    lua_pushliteral(L, \"cannot resume dead coroutine\");\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, L, narg);\n  if (status == LUA_OK || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1)) {\n      lua_pop(co, nres);  /* remove results anyway */\n      lua_pushliteral(L, \"too many results to resume\");\n      return -1;  /* error flag */\n    }\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = getco(L);\n  int r;\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + 'resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_type(L, -1) == LUA_TSTRING) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    return lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  NL = lua_newthread(L);\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = getco(L);\n  if (L == co) lua_pushliteral(L, \"running\");\n  else {\n    switch (lua_status(co)) {\n      case LUA_YIELD:\n        lua_pushliteral(L, \"suspended\");\n        break;\n      case LUA_OK: {\n        lua_Debug ar;\n        if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n          lua_pushliteral(L, \"normal\");  /* it is running */\n        else if (lua_gettop(co) == 0)\n            lua_pushliteral(L, \"dead\");\n        else\n          lua_pushliteral(L, \"suspended\");  /* initial state */\n        break;\n      }\n      default:  /* some error occurred */\n        lua_pushliteral(L, \"dead\");\n        break;\n    }\n  }\n  return 1;\n}\n\n\nstatic int luaB_yieldable (lua_State *L) {\n  lua_pushboolean(L, lua_isyieldable(L));\n  return 1;\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  int ismain = lua_pushthread(L);\n  lua_pushboolean(L, ismain);\n  return 2;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {\"isyieldable\", luaB_yieldable},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_coroutine (lua_State *L) {\n  luaL_newlib(L, co_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lctype.c",
    "content": "/*\n** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lctype_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lctype.h\"\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\nLUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {\n  0x00,  /* EOZ */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 0. */\n  0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 1. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\t/* 2. */\n  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,\t/* 3. */\n  0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 4. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 5. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 6. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 7. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 8. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 9. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* a. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* b. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* c. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* d. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* e. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* f. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n};\n\n#endif\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.4/src/lctype.h",
    "content": "/*\n** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lctype_h\n#define lctype_h\n\n#include \"lua.h\"\n\n\n/*\n** WARNING: the functions defined here do not necessarily correspond\n** to the similar functions in the standard C ctype.h. They are\n** optimized for the specific needs of Lua\n*/\n\n#if !defined(LUA_USE_CTYPE)\n\n#if 'A' == 65 && '0' == 48\n/* ASCII case: can use its own tables; faster and fixed */\n#define LUA_USE_CTYPE\t0\n#else\n/* must use standard C ctype */\n#define LUA_USE_CTYPE\t1\n#endif\n\n#endif\n\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n#include \"llimits.h\"\n\n\n#define ALPHABIT\t0\n#define DIGITBIT\t1\n#define PRINTBIT\t2\n#define SPACEBIT\t3\n#define XDIGITBIT\t4\n\n\n#define MASK(B)\t\t(1 << (B))\n\n\n/*\n** add 1 to char to allow index -1 (EOZ)\n*/\n#define testprop(c,p)\t(luai_ctype_[(c)+1] & (p))\n\n/*\n** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'\n*/\n#define lislalpha(c)\ttestprop(c, MASK(ALPHABIT))\n#define lislalnum(c)\ttestprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))\n#define lisdigit(c)\ttestprop(c, MASK(DIGITBIT))\n#define lisspace(c)\ttestprop(c, MASK(SPACEBIT))\n#define lisprint(c)\ttestprop(c, MASK(PRINTBIT))\n#define lisxdigit(c)\ttestprop(c, MASK(XDIGITBIT))\n\n/*\n** this 'ltolower' only works for alphabetic characters\n*/\n#define ltolower(c)\t((c) | ('A' ^ 'a'))\n\n\n/* two more entries for 0 and -1 (EOZ) */\nLUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];\n\n\n#else\t\t\t/* }{ */\n\n/*\n** use standard C ctypes\n*/\n\n#include <ctype.h>\n\n\n#define lislalpha(c)\t(isalpha(c) || (c) == '_')\n#define lislalnum(c)\t(isalnum(c) || (c) == '_')\n#define lisdigit(c)\t(isdigit(c))\n#define lisspace(c)\t(isspace(c))\n#define lisprint(c)\t(isprint(c))\n#define lisxdigit(c)\t(isxdigit(c))\n\n#define ltolower(c)\t(tolower(c))\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** The hook table at registry[&HOOKKEY] maps threads to their current\n** hook function. (We only need the unique address of 'HOOKKEY'.)\n*/\nstatic const int HOOKKEY = 0;\n\n\n/*\n** If L1 != L, L1 can be in any state, and therefore there are no\n** guarantees about its stack space; any push in L1 must be\n** checked.\n*/\nstatic void checkstack (lua_State *L, lua_State *L1, int n) {\n  if (L != L1 && !lua_checkstack(L1, n))\n    luaL_error(L, \"stack overflow\");\n}\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;  /* return 1st argument */\n}\n\n\nstatic int db_getuservalue (lua_State *L) {\n  if (lua_type(L, 1) != LUA_TUSERDATA)\n    lua_pushnil(L);\n  else\n    lua_getuservalue(L, 1);\n  return 1;\n}\n\n\nstatic int db_setuservalue (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TUSERDATA);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_setuservalue(L, 1);\n  return 1;\n}\n\n\n/*\n** Auxiliary function used by several library functions: check for\n** an optional thread as function's first argument and set 'arg' with\n** 1 if this argument is present (so that functions can skip it to\n** access their other arguments)\n*/\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;  /* function will operate over current thread */\n  }\n}\n\n\n/*\n** Variations of 'lua_settable', used by 'db_getinfo' to put results\n** from 'lua_getinfo' into result table. Key is always a string;\n** value can be a string, an int, or a boolean.\n*/\nstatic void settabss (lua_State *L, const char *k, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsi (lua_State *L, const char *k, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsb (lua_State *L, const char *k, int v) {\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, k);\n}\n\n\n/*\n** In function 'db_getinfo', the call to 'lua_getinfo' may push\n** results on the stack; later it creates the result table to put\n** these objects. Function 'treatstackoption' puts the result from\n** 'lua_getinfo' on top of the result table so that it can call\n** 'lua_setfield'.\n*/\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1)\n    lua_rotate(L, -2, 1);  /* exchange object and table */\n  else\n    lua_xmove(L1, L, 1);  /* move object to the \"main\" stack */\n  lua_setfield(L, -2, fname);  /* put object into table */\n}\n\n\n/*\n** Calls 'lua_getinfo' and collects all results in a new table.\n** L1 needs stack space for an optional input (function) plus\n** two optional outputs (function and line table) from function\n** 'lua_getinfo'.\n*/\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnStu\");\n  checkstack(L, L1, 3);\n  if (lua_isfunction(L, arg + 1)) {  /* info about a function? */\n    options = lua_pushfstring(L, \">%s\", options);  /* add '>' to 'options' */\n    lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */\n    lua_xmove(L, L1, 1);\n  }\n  else {  /* stack level */\n    if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_newtable(L);  /* table to collect results */\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u')) {\n    settabsi(L, \"nups\", ar.nups);\n    settabsi(L, \"nparams\", ar.nparams);\n    settabsb(L, \"isvararg\", ar.isvararg);\n  }\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 't'))\n    settabsb(L, \"istailcall\", ar.istailcall);\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n\n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */\n  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\n    lua_pushvalue(L, arg + 1);  /* push function */\n    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\n    return 1;  /* return only name (there is no value) */\n  }\n  else {  /* stack-level argument */\n    int level = (int)luaL_checkinteger(L, arg + 1);\n    if (!lua_getstack(L1, level, &ar))  /* out of range? */\n      return luaL_argerror(L, arg+1, \"level out of range\");\n    checkstack(L, L1, 1);\n    name = lua_getlocal(L1, &ar, nvar);\n    if (name) {\n      lua_xmove(L1, L, 1);  /* move local value */\n      lua_pushstring(L, name);  /* push name */\n      lua_rotate(L, -2, 1);  /* re-order */\n      return 2;\n    }\n    else {\n      lua_pushnil(L);  /* no name (nor value) */\n      return 1;\n    }\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  const char *name;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  int level = (int)luaL_checkinteger(L, arg + 1);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);\n  if (!lua_getstack(L1, level, &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  checkstack(L, L1, 1);\n  lua_xmove(L, L1, 1);\n  name = lua_setlocal(L1, &ar, nvar);\n  if (name == NULL)\n    lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */\n  lua_pushstring(L, name);\n  return 1;\n}\n\n\n/*\n** get (if 'get' is true) or set an upvalue from a closure\n*/\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */\n  luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));  /* no-op if get is false */\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n/*\n** Check whether a given upvalue from a given closure exists and\n** returns its index\n*/\nstatic int checkupval (lua_State *L, int argf, int argnup) {\n  int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */\n  luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */\n  luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup,\n                   \"invalid upvalue index\");\n  return nup;\n}\n\n\nstatic int db_upvalueid (lua_State *L) {\n  int n = checkupval(L, 1, 2);\n  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\n  return 1;\n}\n\n\nstatic int db_upvaluejoin (lua_State *L) {\n  int n1 = checkupval(L, 1, 2);\n  int n2 = checkupval(L, 3, 4);\n  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, \"Lua function expected\");\n  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, \"Lua function expected\");\n  lua_upvaluejoin(L, 1, n1, 3, n2);\n  return 0;\n}\n\n\n/*\n** Call hook function registered at hook table for the current\n** thread (if there is one)\n*/\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail call\"};\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n  lua_pushthread(L);\n  if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */\n    lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);  /* push current line */\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);  /* call hook function */\n  }\n}\n\n\n/*\n** Convert a string mask (for 'sethook') into a bit mask\n*/\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\n/*\n** Convert a bit mask (for 'gethook') into a string mask\n*/\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = (int)luaL_optinteger(L, arg + 3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {\n    lua_createtable(L, 0, 2);  /* create a hook table */\n    lua_pushvalue(L, -1);\n    lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */\n    lua_pushstring(L, \"k\");\n    lua_setfield(L, -2, \"__mode\");  /** hooktable.__mode = \"k\" */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */\n  }\n  checkstack(L, L1, 1);\n  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */\n  lua_pushvalue(L, arg + 1);  /* value (hook function) */\n  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */\n  lua_sethook(L1, func, mask, count);\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook == NULL)  /* no hook? */\n    lua_pushnil(L);\n  else if (hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {  /* hook table must exist */\n    lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n    checkstack(L, L1, 1);\n    lua_pushthread(L1); lua_xmove(L1, L, 1);\n    lua_rawget(L, -2);   /* 1st result = hooktable[L1] */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */\n  lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    lua_writestringerror(\"%s\", \"lua_debug> \");\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0))\n      lua_writestringerror(\"%s\\n\", lua_tostring(L, -1));\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\nstatic int db_traceback (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg + 1);\n  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\n    lua_pushvalue(L, arg + 1);  /* return it untouched */\n  else {\n    int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);\n    luaL_traceback(L, L1, msg, level);\n  }\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getuservalue\", db_getuservalue},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"upvaluejoin\", db_upvaluejoin},\n  {\"upvalueid\", db_upvalueid},\n  {\"setuservalue\", db_setuservalue},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_traceback},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_debug (lua_State *L) {\n  luaL_newlib(L, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n#define noLuaClosure(f)\t\t((f) == NULL || (f)->c.tt == LUA_TCCL)\n\n\n/* Active Lua function (given call info) */\n#define ci_func(ci)\t\t(clLvalue((ci)->func))\n\n\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                    const char **name);\n\n\nstatic int currentpc (CallInfo *ci) {\n  lua_assert(isLua(ci));\n  return pcRel(ci->u.l.savedpc, ci_func(ci)->p);\n}\n\n\nstatic int currentline (CallInfo *ci) {\n  return getfuncline(ci_func(ci)->p, currentpc(ci));\n}\n\n\n/*\n** If function yielded, its 'func' can be in the 'extra' field. The\n** next function restores 'func' to its correct value for debugging\n** purposes. (It exchanges 'func' and 'extra'; so, when called again,\n** after debugging, it also \"re-restores\" ** 'func' to its altered value.\n*/\nstatic void swapextra (lua_State *L) {\n  if (L->status == LUA_YIELD) {\n    CallInfo *ci = L->ci;  /* get function that yielded */\n    StkId temp = ci->func;  /* exchange its 'func' and 'extra' values */\n    ci->func = restorestack(L, ci->extra);\n    ci->extra = savestack(L, temp);\n  }\n}\n\n\n/*\n** This function can be called asynchronously (e.g. during a signal).\n** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by\n** 'resethookcount') are for debug only, and it is no problem if they\n** get arbitrary values (causes at most one wrong hook call). 'hookmask'\n** is an atomic value. We assume that pointers are atomic too (e.g., gcc\n** ensures that for all platforms where it runs). Moreover, 'hook' is\n** always checked before being called (see 'luaD_hook').\n*/\nLUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  if (isLua(L->ci))\n    L->oldpc = L->ci->u.l.savedpc;\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  if (level < 0) return 0;  /* invalid (negative) level */\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)\n    level--;\n  if (level == 0 && ci != &L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = ci;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic const char *upvalname (Proto *p, int uv) {\n  TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);\n  if (s == NULL) return \"?\";\n  else return getstr(s);\n}\n\n\nstatic const char *findvararg (CallInfo *ci, int n, StkId *pos) {\n  int nparams = clLvalue(ci->func)->p->numparams;\n  if (n >= cast_int(ci->u.l.base - ci->func) - nparams)\n    return NULL;  /* no such vararg */\n  else {\n    *pos = ci->func + nparams + n;\n    return \"(*vararg)\";  /* generic name for any vararg */\n  }\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n,\n                              StkId *pos) {\n  const char *name = NULL;\n  StkId base;\n  if (isLua(ci)) {\n    if (n < 0)  /* access to vararg values? */\n      return findvararg(ci, -n, pos);\n    else {\n      base = ci->u.l.base;\n      name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));\n    }\n  }\n  else\n    base = ci->func + 1;\n  if (name == NULL) {  /* no 'standard' name? */\n    StkId limit = (ci == L->ci) ? L->top : ci->next->func;\n    if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      name = \"(*temporary)\";  /* generic name for any valid slot */\n    else\n      return NULL;  /* no name */\n  }\n  *pos = base + (n - 1);\n  return name;\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  if (ar == NULL) {  /* information about non-active function? */\n    if (!isLfunction(L->top - 1))  /* not a Lua function? */\n      name = NULL;\n    else  /* consider live variables at function start (parameters) */\n      name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);\n  }\n  else {  /* active function; get information through 'ar' */\n    StkId pos = NULL;  /* to avoid warnings */\n    name = findlocal(L, ar->i_ci, n, &pos);\n    if (name) {\n      setobj2s(L, L->top, pos);\n      api_incr_top(L);\n    }\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  StkId pos = NULL;  /* to avoid warnings */\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  name = findlocal(L, ar->i_ci, n, &pos);\n  if (name) {\n    setobjs2s(L, pos, L->top - 1);\n    L->top--;  /* pop value */\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (noLuaClosure(cl)) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    Proto *p = cl->l.p;\n    ar->source = p->source ? getstr(p->source) : \"=?\";\n    ar->linedefined = p->linedefined;\n    ar->lastlinedefined = p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (noLuaClosure(f)) {\n    setnilvalue(L->top);\n    api_incr_top(L);\n  }\n  else {\n    int i;\n    TValue v;\n    int *lineinfo = f->l.p->lineinfo;\n    Table *t = luaH_new(L);  /* new table to store active lines */\n    sethvalue(L, L->top, t);  /* push it on stack */\n    api_incr_top(L);\n    setbvalue(&v, 1);  /* boolean 'true' to be the value of all indices */\n    for (i = 0; i < f->l.p->sizelineinfo; i++)  /* for all lines with code */\n      luaH_setint(L, t, lineinfo[i], &v);  /* table[line] = true */\n  }\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  if (ci == NULL)  /* no 'ci'? */\n    return NULL;  /* no info */\n  else if (ci->callstatus & CIST_FIN) {  /* is this a finalizer? */\n    *name = \"__gc\";\n    return \"metamethod\";  /* report it as such */\n  }\n  /* calling function is a known Lua function? */\n  else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))\n    return funcnamefromcode(L, ci->previous, name);\n  else return NULL;  /* no way to find a name */\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                       Closure *f, CallInfo *ci) {\n  int status = 1;\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = (f == NULL) ? 0 : f->c.nupvalues;\n        if (noLuaClosure(f)) {\n          ar->isvararg = 1;\n          ar->nparams = 0;\n        }\n        else {\n          ar->isvararg = f->l.p->is_vararg;\n          ar->nparams = f->l.p->numparams;\n        }\n        break;\n      }\n      case 't': {\n        ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = getfuncname(L, ci, &ar->name);\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *cl;\n  CallInfo *ci;\n  StkId func;\n  lua_lock(L);\n  swapextra(L);\n  if (*what == '>') {\n    ci = NULL;\n    func = L->top - 1;\n    api_check(L, ttisfunction(func), \"function expected\");\n    what++;  /* skip the '>' */\n    L->top--;  /* pop function */\n  }\n  else {\n    ci = ar->i_ci;\n    func = ci->func;\n    lua_assert(ttisfunction(ci->func));\n  }\n  cl = ttisclosure(func) ? clvalue(func) : NULL;\n  status = auxgetinfo(L, what, ar, cl, ci);\n  if (strchr(what, 'f')) {\n    setobjs2s(L, L->top, func);\n    api_incr_top(L);\n  }\n  swapextra(L);  /* correct before option 'L', which can raise a mem. error */\n  if (strchr(what, 'L'))\n    collectvalidlines(L, cl);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution\n** =======================================================\n*/\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name);\n\n\n/*\n** find a \"name\" for the RK value 'c'\n*/\nstatic void kname (Proto *p, int pc, int c, const char **name) {\n  if (ISK(c)) {  /* is 'c' a constant? */\n    TValue *kvalue = &p->k[INDEXK(c)];\n    if (ttisstring(kvalue)) {  /* literal constant? */\n      *name = svalue(kvalue);  /* it is its own name */\n      return;\n    }\n    /* else no reasonable name found */\n  }\n  else {  /* 'c' is a register */\n    const char *what = getobjname(p, pc, c, name); /* search for 'c' */\n    if (what && *what == 'c') {  /* found a constant name? */\n      return;  /* 'name' already filled */\n    }\n    /* else no reasonable name found */\n  }\n  *name = \"?\";  /* no reasonable name found */\n}\n\n\nstatic int filterpc (int pc, int jmptarget) {\n  if (pc < jmptarget)  /* is code conditional (inside a jump)? */\n    return -1;  /* cannot know who sets that register */\n  else return pc;  /* current position sets that register */\n}\n\n\n/*\n** try to find last instruction before 'lastpc' that modified register 'reg'\n*/\nstatic int findsetreg (Proto *p, int lastpc, int reg) {\n  int pc;\n  int setreg = -1;  /* keep last instruction that changed 'reg' */\n  int jmptarget = 0;  /* any code before this address is conditional */\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    switch (op) {\n      case OP_LOADNIL: {\n        int b = GETARG_B(i);\n        if (a <= reg && reg <= a + b)  /* set registers from 'a' to 'a+b' */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_TFORCALL: {\n        if (reg >= a + 2)  /* affect all regs above its base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (reg >= a)  /* affect all registers above base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_JMP: {\n        int b = GETARG_sBx(i);\n        int dest = pc + 1 + b;\n        /* jump is forward and do not skip 'lastpc'? */\n        if (pc < dest && dest <= lastpc) {\n          if (dest > jmptarget)\n            jmptarget = dest;  /* update 'jmptarget' */\n        }\n        break;\n      }\n      default:\n        if (testAMode(op) && reg == a)  /* any instruction that set A */\n          setreg = filterpc(pc, jmptarget);\n        break;\n    }\n  }\n  return setreg;\n}\n\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name) {\n  int pc;\n  *name = luaF_getlocalname(p, reg + 1, lastpc);\n  if (*name)  /* is a local? */\n    return \"local\";\n  /* else try symbolic execution */\n  pc = findsetreg(p, lastpc, reg);\n  if (pc != -1) {  /* could find instruction? */\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    switch (op) {\n      case OP_MOVE: {\n        int b = GETARG_B(i);  /* move from 'b' to 'a' */\n        if (b < GETARG_A(i))\n          return getobjname(p, pc, b, name);  /* get name for 'b' */\n        break;\n      }\n      case OP_GETTABUP:\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        int t = GETARG_B(i);  /* table index */\n        const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */\n                         ? luaF_getlocalname(p, t + 1, pc)\n                         : upvalname(p, t);\n        kname(p, pc, k, name);\n        return (vn && strcmp(vn, LUA_ENV) == 0) ? \"global\" : \"field\";\n      }\n      case OP_GETUPVAL: {\n        *name = upvalname(p, GETARG_B(i));\n        return \"upvalue\";\n      }\n      case OP_LOADK:\n      case OP_LOADKX: {\n        int b = (op == OP_LOADK) ? GETARG_Bx(i)\n                                 : GETARG_Ax(p->code[pc + 1]);\n        if (ttisstring(&p->k[b])) {\n          *name = svalue(&p->k[b]);\n          return \"constant\";\n        }\n        break;\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, pc, k, name);\n        return \"method\";\n      }\n      default: break;  /* go through to return NULL */\n    }\n  }\n  return NULL;  /* could not find reasonable name */\n}\n\n\n/*\n** Try to find a name for a function based on the code that called it.\n** (Only works when function was called by a Lua function.)\n** Returns what the name is (e.g., \"for iterator\", \"method\",\n** \"metamethod\") and sets '*name' to point to the name.\n*/\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                     const char **name) {\n  TMS tm = (TMS)0;  /* (initial value avoids warnings) */\n  Proto *p = ci_func(ci)->p;  /* calling function */\n  int pc = currentpc(ci);  /* calling instruction index */\n  Instruction i = p->code[pc];  /* calling instruction */\n  if (ci->callstatus & CIST_HOOKED) {  /* was it called inside a hook? */\n    *name = \"?\";\n    return \"hook\";\n  }\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n      return getobjname(p, pc, GETARG_A(i), name);  /* get function name */\n    case OP_TFORCALL: {  /* for iterator */\n      *name = \"for iterator\";\n       return \"for iterator\";\n    }\n    /* other instructions can do calls through metamethods */\n    case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:\n      tm = TM_INDEX;\n      break;\n    case OP_SETTABUP: case OP_SETTABLE:\n      tm = TM_NEWINDEX;\n      break;\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:\n    case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:\n    case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {\n      int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD);  /* ORDER OP */\n      tm = cast(TMS, offset + cast_int(TM_ADD));  /* ORDER TM */\n      break;\n    }\n    case OP_UNM: tm = TM_UNM; break;\n    case OP_BNOT: tm = TM_BNOT; break;\n    case OP_LEN: tm = TM_LEN; break;\n    case OP_CONCAT: tm = TM_CONCAT; break;\n    case OP_EQ: tm = TM_EQ; break;\n    case OP_LT: tm = TM_LT; break;\n    case OP_LE: tm = TM_LE; break;\n    default:\n      return NULL;  /* cannot find a reasonable name */\n  }\n  *name = getstr(G(L)->tmname[tm]);\n  return \"metamethod\";\n}\n\n/* }====================================================== */\n\n\n\n/*\n** The subtraction of two potentially unrelated pointers is\n** not ISO C, but it should not crash a program; the subsequent\n** checks are ISO C and ensure a correct result.\n*/\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  ptrdiff_t i = o - ci->u.l.base;\n  return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);\n}\n\n\n/*\n** Checks whether value 'o' came from an upvalue. (That can only happen\n** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on\n** upvalues.)\n*/\nstatic const char *getupvalname (CallInfo *ci, const TValue *o,\n                                 const char **name) {\n  LClosure *c = ci_func(ci);\n  int i;\n  for (i = 0; i < c->nupvalues; i++) {\n    if (c->upvals[i]->v == o) {\n      *name = upvalname(c->p, i);\n      return \"upvalue\";\n    }\n  }\n  return NULL;\n}\n\n\nstatic const char *varinfo (lua_State *L, const TValue *o) {\n  const char *name = NULL;  /* to avoid warnings */\n  CallInfo *ci = L->ci;\n  const char *kind = NULL;\n  if (isLua(ci)) {\n    kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */\n    if (!kind && isinstack(ci, o))  /* no? try a register */\n      kind = getobjname(ci_func(ci)->p, currentpc(ci),\n                        cast_int(o - ci->u.l.base), &name);\n  }\n  return (kind) ? luaO_pushfstring(L, \" (%s '%s')\", kind, name) : \"\";\n}\n\n\nl_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *t = luaT_objtypename(L, o);\n  luaG_runerror(L, \"attempt to %s a %s value%s\", op, t, varinfo(L, o));\n}\n\n\nl_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {\n  if (ttisstring(p1) || cvt2str(p1)) p1 = p2;\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nl_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                         const TValue *p2, const char *msg) {\n  lua_Number temp;\n  if (!tonumber(p1, &temp))  /* first operand is wrong? */\n    p2 = p1;  /* now second is wrong */\n  luaG_typeerror(L, p2, msg);\n}\n\n\n/*\n** Error when both values are convertible to numbers, but not to integers\n*/\nl_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {\n  lua_Integer temp;\n  if (!tointeger(p1, &temp))\n    p2 = p1;\n  luaG_runerror(L, \"number%s has no integer representation\", varinfo(L, p2));\n}\n\n\nl_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_objtypename(L, p1);\n  const char *t2 = luaT_objtypename(L, p2);\n  if (strcmp(t1, t2) == 0)\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n}\n\n\n/* add src:line information to 'msg' */\nconst char *luaG_addinfo (lua_State *L, const char *msg, TString *src,\n                                        int line) {\n  char buff[LUA_IDSIZE];\n  if (src)\n    luaO_chunkid(buff, getstr(src), LUA_IDSIZE);\n  else {  /* no source available; use \"?\" instead */\n    buff[0] = '?'; buff[1] = '\\0';\n  }\n  return luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n}\n\n\nl_noret luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    L->top++;  /* assume EXTRA_STACK */\n    luaD_callnoyield(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nl_noret luaG_runerror (lua_State *L, const char *fmt, ...) {\n  CallInfo *ci = L->ci;\n  const char *msg;\n  va_list argp;\n  luaC_checkGC(L);  /* error message uses memory */\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);  /* format message */\n  va_end(argp);\n  if (isLua(ci))  /* if Lua function, add source:line information */\n    luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));\n  luaG_errormsg(L);\n}\n\n\nvoid luaG_traceexec (lua_State *L) {\n  CallInfo *ci = L->ci;\n  lu_byte mask = L->hookmask;\n  int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));\n  if (counthook)\n    resethookcount(L);  /* reset count */\n  else if (!(mask & LUA_MASKLINE))\n    return;  /* no line hook and count != 0; nothing to be done */\n  if (ci->callstatus & CIST_HOOKYIELD) {  /* called hook last time? */\n    ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */\n    return;  /* do not call hook again (VM yielded, so it did not move) */\n  }\n  if (counthook)\n    luaD_hook(L, LUA_HOOKCOUNT, -1);  /* call count hook */\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(ci)->p;\n    int npc = pcRel(ci->u.l.savedpc, p);\n    int newline = getfuncline(p, npc);\n    if (npc == 0 ||  /* call linehook when enter a new function, */\n        ci->u.l.savedpc <= L->oldpc ||  /* when jump back (loop), or when */\n        newline != getfuncline(p, pcRel(L->oldpc, p)))  /* enter a new line */\n      luaD_hook(L, LUA_HOOKLINE, newline);  /* call line hook */\n  }\n  L->oldpc = ci->u.l.savedpc;\n  if (L->status == LUA_YIELD) {  /* did hook yield? */\n    if (counthook)\n      L->hookcount = 1;  /* undo decrement to zero */\n    ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */\n    ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */\n    ci->func = L->top - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getfuncline(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : -1)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,\n                                                const char *opname);\nLUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,\n                                                  const TValue *p2);\nLUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2,\n                                                 const char *msg);\nLUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,\n                                                  TString *src, int line);\nLUAI_FUNC l_noret luaG_errormsg (lua_State *L);\nLUAI_FUNC void luaG_traceexec (lua_State *L);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n#define errorstatus(s)\t((s) > LUA_YIELD)\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n/*\n** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By\n** default, Lua handles errors with exceptions when compiling as\n** C++ code, with _longjmp/_setjmp when asked to use them, and with\n** longjmp/setjmp otherwise.\n*/\n#if !defined(LUAI_THROW)\t\t\t\t/* { */\n\n#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)\t/* { */\n\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\t\tthrow(c)\n#define LUAI_TRY(L,c,a) \\\n\ttry { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\t\tint  /* dummy variable */\n\n#elif defined(LUA_USE_POSIX)\t\t\t\t/* }{ */\n\n/* in POSIX, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#else\t\t\t\t\t\t\t/* }{ */\n\n/* ISO C handling with long jumps */\n#define LUAI_THROW(L,c)\t\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#endif\t\t\t\t\t\t\t/* } */\n\n#endif\t\t\t\t\t\t\t/* } */\n\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nstatic void seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {  /* memory error? */\n      setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    default: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nl_noret luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {  /* thread has an error handler? */\n    L->errorJmp->status = errcode;  /* set status */\n    LUAI_THROW(L, L->errorJmp);  /* jump to it */\n  }\n  else {  /* thread has no error handler */\n    global_State *g = G(L);\n    L->status = cast_byte(errcode);  /* mark it as dead */\n    if (g->mainthread->errorJmp) {  /* main thread has a handler? */\n      setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */\n      luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */\n    }\n    else {  /* no handler at all; abort */\n      if (g->panic) {  /* panic function? */\n        seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */\n        if (L->ci->top < L->top)\n          L->ci->top = L->top;  /* pushing msg. can break this invariant */\n        lua_unlock(L);\n        g->panic(L);  /* call panic function (last chance to jump out) */\n      }\n      abort();\n    }\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  unsigned short oldnCcalls = L->nCcalls;\n  struct lua_longjmp lj;\n  lj.status = LUA_OK;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  L->nCcalls = oldnCcalls;\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\n/*\n** {==================================================================\n** Stack reallocation\n** ===================================================================\n*/\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  UpVal *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->u.open.next)\n    up->v = (up->v - oldstack) + L->stack;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n    if (isLua(ci))\n      ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;\n  }\n}\n\n\n/* some space for error handling */\n#define ERRORSTACKSIZE\t(LUAI_MAXSTACK + 200)\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int lim = L->stacksize;\n  lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);\n  luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);\n  for (; lim < newsize; lim++)\n    setnilvalue(L->stack + lim); /* erase new segment */\n  L->stacksize = newsize;\n  L->stack_last = L->stack + newsize - EXTRA_STACK;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  int size = L->stacksize;\n  if (size > LUAI_MAXSTACK)  /* error after extra size? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;\n    int newsize = 2 * size;\n    if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;\n    if (newsize < needed) newsize = needed;\n    if (newsize > LUAI_MAXSTACK) {  /* stack overflow? */\n      luaD_reallocstack(L, ERRORSTACKSIZE);\n      luaG_runerror(L, \"stack overflow\");\n    }\n    else\n      luaD_reallocstack(L, newsize);\n  }\n}\n\n\nstatic int stackinuse (lua_State *L) {\n  CallInfo *ci;\n  StkId lim = L->top;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    if (lim < ci->top) lim = ci->top;\n  }\n  lua_assert(lim <= L->stack_last);\n  return cast_int(lim - L->stack) + 1;  /* part of stack in use */\n}\n\n\nvoid luaD_shrinkstack (lua_State *L) {\n  int inuse = stackinuse(L);\n  int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;\n  if (goodsize > LUAI_MAXSTACK)\n    goodsize = LUAI_MAXSTACK;  /* respect stack limit */\n  if (L->stacksize > LUAI_MAXSTACK)  /* had been handling stack overflow? */\n    luaE_freeCI(L);  /* free all CIs (list grew because of an error) */\n  else\n    luaE_shrinkCI(L);  /* shrink list */\n  /* if thread is currently not handling a stack overflow and its\n     good size is smaller than current size, shrink its stack */\n  if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) &&\n      goodsize < L->stacksize)\n    luaD_reallocstack(L, goodsize);\n  else  /* don't change stack */\n    condmovestack(L,{},{});  /* (change only for debugging) */\n}\n\n\nvoid luaD_inctop (lua_State *L) {\n  luaD_checkstack(L, 1);\n  L->top++;\n}\n\n/* }================================================================== */\n\n\n/*\n** Call a hook for the given event. Make sure there is a hook to be\n** called. (Both 'L->hook' and 'L->hookmask', which triggers this\n** function, can be changed asynchronously by signals.)\n*/\nvoid luaD_hook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {  /* make sure there is a hook */\n    CallInfo *ci = L->ci;\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    ar.i_ci = ci;\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    ci->top = L->top + LUA_MINSTACK;\n    lua_assert(ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    ci->callstatus |= CIST_HOOKED;\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n    ci->callstatus &= ~CIST_HOOKED;\n  }\n}\n\n\nstatic void callhook (lua_State *L, CallInfo *ci) {\n  int hook = LUA_HOOKCALL;\n  ci->u.l.savedpc++;  /* hooks assume 'pc' is already incremented */\n  if (isLua(ci->previous) &&\n      GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {\n    ci->callstatus |= CIST_TAIL;\n    hook = LUA_HOOKTAILCALL;\n  }\n  luaD_hook(L, hook, -1);\n  ci->u.l.savedpc--;  /* correct 'pc' */\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n  StkId base, fixed;\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i = 0; i < nfixargs && i < actual; i++) {\n    setobjs2s(L, L->top++, fixed + i);\n    setnilvalue(fixed + i);  /* erase original copy (for GC) */\n  }\n  for (; i < nfixargs; i++)\n    setnilvalue(L->top++);  /* complete missing arguments */\n  return base;\n}\n\n\n/*\n** Check whether __call metafield of 'func' is a function. If so, put\n** it in stack below original 'func' so that 'luaD_precall' can call\n** it. Raise an error if __call metafield is not a function.\n*/\nstatic void tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at 'func' */\n  for (p = L->top; p > func; p--)\n    setobjs2s(L, p, p-1);\n  L->top++;  /* slot ensured by caller */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n}\n\n\n/*\n** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.\n** Handle most typical cases (zero results for commands, one result for\n** expressions, multiple results for tail calls/single parameters)\n** separated.\n*/\nstatic int moveresults (lua_State *L, const TValue *firstResult, StkId res,\n                                      int nres, int wanted) {\n  switch (wanted) {  /* handle typical cases separately */\n    case 0: break;  /* nothing to move */\n    case 1: {  /* one result needed */\n      if (nres == 0)   /* no results? */\n        firstResult = luaO_nilobject;  /* adjust with nil */\n      setobjs2s(L, res, firstResult);  /* move it to proper place */\n      break;\n    }\n    case LUA_MULTRET: {\n      int i;\n      for (i = 0; i < nres; i++)  /* move all results to correct place */\n        setobjs2s(L, res + i, firstResult + i);\n      L->top = res + nres;\n      return 0;  /* wanted == LUA_MULTRET */\n    }\n    default: {\n      int i;\n      if (wanted <= nres) {  /* enough results? */\n        for (i = 0; i < wanted; i++)  /* move wanted results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n      }\n      else {  /* not enough results; use all of them plus nils */\n        for (i = 0; i < nres; i++)  /* move all results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n        for (; i < wanted; i++)  /* complete wanted number of results */\n          setnilvalue(res + i);\n      }\n      break;\n    }\n  }\n  L->top = res + wanted;  /* top points after the last result */\n  return 1;\n}\n\n\n/*\n** Finishes a function call: calls hook if necessary, removes CallInfo,\n** moves current number of results to proper place; returns 0 iff call\n** wanted multiple (variable number of) results.\n*/\nint luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {\n  StkId res;\n  int wanted = ci->nresults;\n  if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {\n    if (L->hookmask & LUA_MASKRET) {\n      ptrdiff_t fr = savestack(L, firstResult);  /* hook may change stack */\n      luaD_hook(L, LUA_HOOKRET, -1);\n      firstResult = restorestack(L, fr);\n    }\n    L->oldpc = ci->previous->u.l.savedpc;  /* 'oldpc' for caller function */\n  }\n  res = ci->func;  /* res == final position of 1st result */\n  L->ci = ci->previous;  /* back to caller */\n  /* move results to proper place */\n  return moveresults(L, firstResult, res, nres, wanted);\n}\n\n\n\n#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))\n\n\n/* macro to check stack size, preserving 'p' */\n#define checkstackp(L,n,p)  \\\n  luaD_checkstackaux(L, n, \\\n    ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \\\n    luaC_checkGC(L),  /* stack grow uses memory */ \\\n    p = restorestack(L, t__))  /* 'pos' part: restore 'p' */\n\n\n/*\n** Prepares a function call: checks the stack, creates a new CallInfo\n** entry, fills in the relevant information, calls hook if needed.\n** If function is a C function, does the call, too. (Otherwise, leave\n** the execution ('luaV_execute') to the caller, to allow stackless\n** calls.) Returns true iff function has been executed (C function).\n*/\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  lua_CFunction f;\n  CallInfo *ci;\n  switch (ttype(func)) {\n    case LUA_TCCL:  /* C closure */\n      f = clCvalue(func)->f;\n      goto Cfunc;\n    case LUA_TLCF:  /* light C function */\n      f = fvalue(func);\n     Cfunc: {\n      int n;  /* number of returns */\n      checkstackp(L, LUA_MINSTACK, func);  /* ensure minimum stack size */\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->top = L->top + LUA_MINSTACK;\n      lua_assert(ci->top <= L->stack_last);\n      ci->callstatus = 0;\n      if (L->hookmask & LUA_MASKCALL)\n        luaD_hook(L, LUA_HOOKCALL, -1);\n      lua_unlock(L);\n      n = (*f)(L);  /* do the actual call */\n      lua_lock(L);\n      api_checknelems(L, n);\n      luaD_poscall(L, ci, L->top - n, n);\n      return 1;\n    }\n    case LUA_TLCL: {  /* Lua function: prepare its call */\n      StkId base;\n      Proto *p = clLvalue(func)->p;\n      int n = cast_int(L->top - func) - 1;  /* number of real arguments */\n      int fsize = p->maxstacksize;  /* frame size */\n      checkstackp(L, fsize, func);\n      if (p->is_vararg)\n        base = adjust_varargs(L, p, n);\n      else {  /* non vararg function */\n        for (; n < p->numparams; n++)\n          setnilvalue(L->top++);  /* complete missing arguments */\n        base = func + 1;\n      }\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->u.l.base = base;\n      L->top = ci->top = base + fsize;\n      lua_assert(ci->top <= L->stack_last);\n      ci->u.l.savedpc = p->code;  /* starting point */\n      ci->callstatus = CIST_LUA;\n      if (L->hookmask & LUA_MASKCALL)\n        callhook(L, ci);\n      return 0;\n    }\n    default: {  /* not a function */\n      checkstackp(L, 1, func);  /* ensure space for metamethod */\n      tryfuncTM(L, func);  /* try to get '__call' metamethod */\n      return luaD_precall(L, func, nresults);  /* now it must be a function */\n    }\n  }\n}\n\n\n/*\n** Check appropriate error for stack overflow (\"regular\" overflow or\n** overflow while handling stack overflow). If 'nCalls' is larger than\n** LUAI_MAXCCALLS (which means it is handling a \"regular\" overflow) but\n** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to\n** allow overflow handling to work)\n*/\nstatic void stackerror (lua_State *L) {\n  if (L->nCcalls == LUAI_MAXCCALLS)\n    luaG_runerror(L, \"C stack overflow\");\n  else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n    luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/\nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS)\n    stackerror(L);\n  if (!luaD_precall(L, func, nResults))  /* is a Lua function? */\n    luaV_execute(L);  /* call it */\n  L->nCcalls--;\n}\n\n\n/*\n** Similar to 'luaD_call', but does not allow yields during the call\n*/\nvoid luaD_callnoyield (lua_State *L, StkId func, int nResults) {\n  L->nny++;\n  luaD_call(L, func, nResults);\n  L->nny--;\n}\n\n\n/*\n** Completes the execution of an interrupted C function, calling its\n** continuation function.\n*/\nstatic void finishCcall (lua_State *L, int status) {\n  CallInfo *ci = L->ci;\n  int n;\n  /* must have a continuation and must be able to call it */\n  lua_assert(ci->u.c.k != NULL && L->nny == 0);\n  /* error status can only happen in a protected call */\n  lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD);\n  if (ci->callstatus & CIST_YPCALL) {  /* was inside a pcall? */\n    ci->callstatus &= ~CIST_YPCALL;  /* continuation is also inside it */\n    L->errfunc = ci->u.c.old_errfunc;  /* with the same error function */\n  }\n  /* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already\n     handled */\n  adjustresults(L, ci->nresults);\n  lua_unlock(L);\n  n = (*ci->u.c.k)(L, status, ci->u.c.ctx);  /* call continuation function */\n  lua_lock(L);\n  api_checknelems(L, n);\n  luaD_poscall(L, ci, L->top - n, n);  /* finish 'luaD_precall' */\n}\n\n\n/*\n** Executes \"full continuation\" (everything in the stack) of a\n** previously interrupted coroutine until the stack is empty (or another\n** interruption long-jumps out of the loop). If the coroutine is\n** recovering from an error, 'ud' points to the error status, which must\n** be passed to the first continuation function (otherwise the default\n** status is LUA_YIELD).\n*/\nstatic void unroll (lua_State *L, void *ud) {\n  if (ud != NULL)  /* error status? */\n    finishCcall(L, *(int *)ud);  /* finish 'lua_pcallk' callee */\n  while (L->ci != &L->base_ci) {  /* something in the stack */\n    if (!isLua(L->ci))  /* C function? */\n      finishCcall(L, LUA_YIELD);  /* complete its execution */\n    else {  /* Lua function */\n      luaV_finishOp(L);  /* finish interrupted instruction */\n      luaV_execute(L);  /* execute down to higher C 'boundary' */\n    }\n  }\n}\n\n\n/*\n** Try to find a suspended protected call (a \"recover point\") for the\n** given thread.\n*/\nstatic CallInfo *findpcall (lua_State *L) {\n  CallInfo *ci;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {  /* search for a pcall */\n    if (ci->callstatus & CIST_YPCALL)\n      return ci;\n  }\n  return NULL;  /* no pending pcall */\n}\n\n\n/*\n** Recovers from an error in a coroutine. Finds a recover point (if\n** there is one) and completes the execution of the interrupted\n** 'luaD_pcall'. If there is no recover point, returns zero.\n*/\nstatic int recover (lua_State *L, int status) {\n  StkId oldtop;\n  CallInfo *ci = findpcall(L);\n  if (ci == NULL) return 0;  /* no recovery point */\n  /* \"finish\" luaD_pcall */\n  oldtop = restorestack(L, ci->extra);\n  luaF_close(L, oldtop);\n  seterrorobj(L, status, oldtop);\n  L->ci = ci;\n  L->allowhook = getoah(ci->callstatus);  /* restore original 'allowhook' */\n  L->nny = 0;  /* should be zero to be yieldable */\n  luaD_shrinkstack(L);\n  L->errfunc = ci->u.c.old_errfunc;\n  return 1;  /* continue running the coroutine */\n}\n\n\n/*\n** Signal an error in the call to 'lua_resume', not in the execution\n** of the coroutine itself. (Such errors should not be handled by any\n** coroutine error handler and should not kill the coroutine.)\n*/\nstatic int resume_error (lua_State *L, const char *msg, int narg) {\n  L->top -= narg;  /* remove args from the stack */\n  setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */\n  api_incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\n/*\n** Do the work for 'lua_resume' in protected mode. Most of the work\n** depends on the status of the coroutine: initial state, suspended\n** inside a hook, or regularly suspended (optionally with a continuation\n** function), plus erroneous cases: non-suspended coroutine or dead\n** coroutine.\n*/\nstatic void resume (lua_State *L, void *ud) {\n  int n = *(cast(int*, ud));  /* number of arguments */\n  StkId firstArg = L->top - n;  /* first argument */\n  CallInfo *ci = L->ci;\n  if (L->status == LUA_OK) {  /* starting a coroutine? */\n    if (!luaD_precall(L, firstArg - 1, LUA_MULTRET))  /* Lua function? */\n      luaV_execute(L);  /* call it */\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = LUA_OK;  /* mark that it is running (again) */\n    ci->func = restorestack(L, ci->extra);\n    if (isLua(ci))  /* yielded inside a hook? */\n      luaV_execute(L);  /* just continue running Lua code */\n    else {  /* 'common' yield */\n      if (ci->u.c.k != NULL) {  /* does it have a continuation function? */\n        lua_unlock(L);\n        n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */\n        lua_lock(L);\n        api_checknelems(L, n);\n        firstArg = L->top - n;  /* yield results come from continuation */\n      }\n      luaD_poscall(L, ci, firstArg, n);  /* finish 'luaD_precall' */\n    }\n    unroll(L, NULL);  /* run continuation */\n  }\n}\n\n\nLUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {\n  int status;\n  unsigned short oldnny = L->nny;  /* save \"number of non-yieldable\" calls */\n  lua_lock(L);\n  if (L->status == LUA_OK) {  /* may be starting a coroutine */\n    if (L->ci != &L->base_ci)  /* not in base level? */\n      return resume_error(L, \"cannot resume non-suspended coroutine\", nargs);\n  }\n  else if (L->status != LUA_YIELD)\n    return resume_error(L, \"cannot resume dead coroutine\", nargs);\n  L->nCcalls = (from) ? from->nCcalls + 1 : 1;\n  if (L->nCcalls >= LUAI_MAXCCALLS)\n    return resume_error(L, \"C stack overflow\", nargs);\n  luai_userstateresume(L, nargs);\n  L->nny = 0;  /* allow yields */\n  api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);\n  status = luaD_rawrunprotected(L, resume, &nargs);\n  if (status == -1)  /* error calling 'lua_resume'? */\n    status = LUA_ERRRUN;\n  else {  /* continue running after recoverable errors */\n    while (errorstatus(status) && recover(L, status)) {\n      /* unroll continuation */\n      status = luaD_rawrunprotected(L, unroll, &status);\n    }\n    if (errorstatus(status)) {  /* unrecoverable error? */\n      L->status = cast_byte(status);  /* mark thread as 'dead' */\n      seterrorobj(L, status, L->top);  /* push error message */\n      L->ci->top = L->top;\n    }\n    else lua_assert(status == L->status);  /* normal end or yield */\n  }\n  L->nny = oldnny;  /* restore 'nny' */\n  L->nCcalls--;\n  lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_isyieldable (lua_State *L) {\n  return (L->nny == 0);\n}\n\n\nLUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,\n                        lua_KFunction k) {\n  CallInfo *ci = L->ci;\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  api_checknelems(L, nresults);\n  if (L->nny > 0) {\n    if (L != G(L)->mainthread)\n      luaG_runerror(L, \"attempt to yield across a C-call boundary\");\n    else\n      luaG_runerror(L, \"attempt to yield from outside a coroutine\");\n  }\n  L->status = LUA_YIELD;\n  ci->extra = savestack(L, ci->func);  /* save current 'func' */\n  if (isLua(ci)) {  /* inside a hook? */\n    api_check(L, k == NULL, \"hooks cannot continue after yielding\");\n  }\n  else {\n    if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */\n      ci->u.c.ctx = ctx;  /* save context */\n    ci->func = L->top - nresults - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n  lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */\n  lua_unlock(L);\n  return 0;  /* return to 'luaD_hook' */\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  CallInfo *old_ci = L->ci;\n  lu_byte old_allowhooks = L->allowhook;\n  unsigned short old_nny = L->nny;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != LUA_OK) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close possible pending closures */\n    seterrorobj(L, status, oldtop);\n    L->ci = old_ci;\n    L->allowhook = old_allowhooks;\n    L->nny = old_nny;\n    luaD_shrinkstack(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to 'f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* dynamic structure used by the scanner */\n  Dyndata dyd;  /* dynamic structures used by the parser */\n  const char *mode;\n  const char *name;\n};\n\n\nstatic void checkmode (lua_State *L, const char *mode, const char *x) {\n  if (mode && strchr(mode, x[0]) == NULL) {\n    luaO_pushfstring(L,\n       \"attempt to load a %s chunk (mode is '%s')\", x, mode);\n    luaD_throw(L, LUA_ERRSYNTAX);\n  }\n}\n\n\nstatic void f_parser (lua_State *L, void *ud) {\n  LClosure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = zgetc(p->z);  /* read first character */\n  if (c == LUA_SIGNATURE[0]) {\n    checkmode(L, p->mode, \"binary\");\n    cl = luaU_undump(L, p->z, p->name);\n  }\n  else {\n    checkmode(L, p->mode, \"text\");\n    cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);\n  }\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luaF_initupvals(L, cl);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                        const char *mode) {\n  struct SParser p;\n  int status;\n  L->nny++;  /* cannot yield during parsing */\n  p.z = z; p.name = name; p.mode = mode;\n  p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;\n  p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;\n  p.dyd.label.arr = NULL; p.dyd.label.size = 0;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);\n  luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);\n  luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);\n  L->nny--;\n  return status;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n/*\n** Macro to check stack size and grow stack if needed.  Parameters\n** 'pre'/'pos' allow the macro to preserve a pointer into the\n** stack across reallocations, doing the work only when needed.\n** 'condmovestack' is used in heavy tests to force a stack reallocation\n** at every check.\n*/\n#define luaD_checkstackaux(L,n,pre,pos)  \\\n\tif (L->stack_last - L->top <= (n)) \\\n\t  { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }\n\n/* In general, 'pre'/'pos' are empty (nothing to save) */\n#define luaD_checkstack(L,n)\tluaD_checkstackaux(L,n,(void)0,(void)0)\n\n\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n\n/* type of protected functions, to be ran by 'runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                                  const char *mode);\nLUAI_FUNC void luaD_hook (lua_State *L, int event, int line);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,\n                                          int nres);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\nLUAI_FUNC void luaD_shrinkstack (lua_State *L);\nLUAI_FUNC void luaD_inctop (lua_State *L);\n\nLUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\n\ntypedef struct {\n  lua_State *L;\n  lua_Writer writer;\n  void *data;\n  int strip;\n  int status;\n} DumpState;\n\n\n/*\n** All high-level dumps go through DumpVector; you can change it to\n** change the endianness of the result\n*/\n#define DumpVector(v,n,D)\tDumpBlock(v,(n)*sizeof((v)[0]),D)\n\n#define DumpLiteral(s,D)\tDumpBlock(s, sizeof(s) - sizeof(char), D)\n\n\nstatic void DumpBlock (const void *b, size_t size, DumpState *D) {\n  if (D->status == 0 && size > 0) {\n    lua_unlock(D->L);\n    D->status = (*D->writer)(D->L, b, size, D->data);\n    lua_lock(D->L);\n  }\n}\n\n\n#define DumpVar(x,D)\t\tDumpVector(&x,1,D)\n\n\nstatic void DumpByte (int y, DumpState *D) {\n  lu_byte x = (lu_byte)y;\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInt (int x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpNumber (lua_Number x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInteger (lua_Integer x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpString (const TString *s, DumpState *D) {\n  if (s == NULL)\n    DumpByte(0, D);\n  else {\n    size_t size = tsslen(s) + 1;  /* include trailing '\\0' */\n    const char *str = getstr(s);\n    if (size < 0xFF)\n      DumpByte(cast_int(size), D);\n    else {\n      DumpByte(0xFF, D);\n      DumpVar(size, D);\n    }\n    DumpVector(str, size - 1, D);  /* no need to save '\\0' */\n  }\n}\n\n\nstatic void DumpCode (const Proto *f, DumpState *D) {\n  DumpInt(f->sizecode, D);\n  DumpVector(f->code, f->sizecode, D);\n}\n\n\nstatic void DumpFunction(const Proto *f, TString *psource, DumpState *D);\n\nstatic void DumpConstants (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizek;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    const TValue *o = &f->k[i];\n    DumpByte(ttype(o), D);\n    switch (ttype(o)) {\n    case LUA_TNIL:\n      break;\n    case LUA_TBOOLEAN:\n      DumpByte(bvalue(o), D);\n      break;\n    case LUA_TNUMFLT:\n      DumpNumber(fltvalue(o), D);\n      break;\n    case LUA_TNUMINT:\n      DumpInteger(ivalue(o), D);\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      DumpString(tsvalue(o), D);\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void DumpProtos (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizep;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpFunction(f->p[i], f->source, D);\n}\n\n\nstatic void DumpUpvalues (const Proto *f, DumpState *D) {\n  int i, n = f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpByte(f->upvalues[i].instack, D);\n    DumpByte(f->upvalues[i].idx, D);\n  }\n}\n\n\nstatic void DumpDebug (const Proto *f, DumpState *D) {\n  int i, n;\n  n = (D->strip) ? 0 : f->sizelineinfo;\n  DumpInt(n, D);\n  DumpVector(f->lineinfo, n, D);\n  n = (D->strip) ? 0 : f->sizelocvars;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpString(f->locvars[i].varname, D);\n    DumpInt(f->locvars[i].startpc, D);\n    DumpInt(f->locvars[i].endpc, D);\n  }\n  n = (D->strip) ? 0 : f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpString(f->upvalues[i].name, D);\n}\n\n\nstatic void DumpFunction (const Proto *f, TString *psource, DumpState *D) {\n  if (D->strip || f->source == psource)\n    DumpString(NULL, D);  /* no debug info or same source as its parent */\n  else\n    DumpString(f->source, D);\n  DumpInt(f->linedefined, D);\n  DumpInt(f->lastlinedefined, D);\n  DumpByte(f->numparams, D);\n  DumpByte(f->is_vararg, D);\n  DumpByte(f->maxstacksize, D);\n  DumpCode(f, D);\n  DumpConstants(f, D);\n  DumpUpvalues(f, D);\n  DumpProtos(f, D);\n  DumpDebug(f, D);\n}\n\n\nstatic void DumpHeader (DumpState *D) {\n  DumpLiteral(LUA_SIGNATURE, D);\n  DumpByte(LUAC_VERSION, D);\n  DumpByte(LUAC_FORMAT, D);\n  DumpLiteral(LUAC_DATA, D);\n  DumpByte(sizeof(int), D);\n  DumpByte(sizeof(size_t), D);\n  DumpByte(sizeof(Instruction), D);\n  DumpByte(sizeof(lua_Integer), D);\n  DumpByte(sizeof(lua_Number), D);\n  DumpInteger(LUAC_INT, D);\n  DumpNumber(LUAC_NUM, D);\n}\n\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,\n              int strip) {\n  DumpState D;\n  D.L = L;\n  D.writer = w;\n  D.data = data;\n  D.strip = strip;\n  D.status = 0;\n  DumpHeader(&D);\n  DumpByte(f->sizeupvalues, &D);\n  DumpFunction(f, NULL, &D);\n  return D.status;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nCClosure *luaF_newCclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));\n  CClosure *c = gco2ccl(o);\n  c->nupvalues = cast_byte(n);\n  return c;\n}\n\n\nLClosure *luaF_newLclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));\n  LClosure *c = gco2lcl(o);\n  c->p = NULL;\n  c->nupvalues = cast_byte(n);\n  while (n--) c->upvals[n] = NULL;\n  return c;\n}\n\n/*\n** fill a closure with new closed upvalues\n*/\nvoid luaF_initupvals (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = luaM_new(L, UpVal);\n    uv->refcount = 1;\n    uv->v = &uv->u.value;  /* make it closed */\n    setnilvalue(uv->v);\n    cl->upvals[i] = uv;\n  }\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  UpVal **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  lua_assert(isintwups(L) || L->openupval == NULL);\n  while (*pp != NULL && (p = *pp)->v >= level) {\n    lua_assert(upisopen(p));\n    if (p->v == level)  /* found a corresponding upvalue? */\n      return p;  /* return it */\n    pp = &p->u.open.next;\n  }\n  /* not found: create a new upvalue */\n  uv = luaM_new(L, UpVal);\n  uv->refcount = 0;\n  uv->u.open.next = *pp;  /* link it to list of open upvalues */\n  uv->u.open.touched = 1;\n  *pp = uv;\n  uv->v = level;  /* current value lives in the stack */\n  if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */\n    L->twups = G(L)->twups;  /* link it to the list */\n    G(L)->twups = L;\n  }\n  return uv;\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  while (L->openupval != NULL && (uv = L->openupval)->v >= level) {\n    lua_assert(upisopen(uv));\n    L->openupval = uv->u.open.next;  /* remove from 'open' list */\n    if (uv->refcount == 0)  /* no references? */\n      luaM_free(L, uv);  /* free upvalue */\n    else {\n      setobj(L, &uv->u.value, uv->v);  /* move value to upvalue slot */\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_upvalbarrier(L, uv);\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));\n  Proto *f = gco2p(o);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->cache = NULL;\n  f->sizecode = 0;\n  f->lineinfo = NULL;\n  f->sizelineinfo = 0;\n  f->upvalues = NULL;\n  f->sizeupvalues = 0;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->locvars = NULL;\n  f->sizelocvars = 0;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode);\n  luaM_freearray(L, f->p, f->sizep);\n  luaM_freearray(L, f->k, f->sizek);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo);\n  luaM_freearray(L, f->locvars, f->sizelocvars);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues);\n  luaM_free(L, f);\n}\n\n\n/*\n** Look for n-th local variable at line 'line' in function 'func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\n/* test whether thread is in 'twups' list */\n#define isintwups(L)\t(L->twups != L)\n\n\n/*\n** maximum number of upvalues in a closure (both C and Lua). (Value\n** must fit in a VM register.)\n*/\n#define MAXUPVAL\t255\n\n\n/*\n** Upvalues for Lua closures\n*/\nstruct UpVal {\n  TValue *v;  /* points to stack or to its own value */\n  lu_mem refcount;  /* reference counter */\n  union {\n    struct {  /* (when open) */\n      UpVal *next;  /* linked list */\n      int touched;  /* mark to avoid cycles with dead threads */\n    } open;\n    TValue value;  /* the value (when closed) */\n  } u;\n};\n\n#define upisopen(up)\t((up)->v != &(up)->u.value)\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);\nLUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);\nLUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.215 2016/12/22 13:08:50 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n/*\n** internal state for collector while inside the atomic phase. The\n** collector should never be in this state while running regular code.\n*/\n#define GCSinsideatomic\t\t(GCSpause + 1)\n\n/*\n** cost of sweeping one element (the size of a small object divided\n** by some adjust for the sweep speed)\n*/\n#define GCSWEEPCOST\t((sizeof(TString) + 4) / 4)\n\n/* maximum number of elements to sweep in each single step */\n#define GCSWEEPMAX\t(cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))\n\n/* cost of calling one finalizer */\n#define GCFINALIZECOST\tGCSWEEPCOST\n\n\n/*\n** macro to adjust 'stepmul': 'stepmul' is actually used like\n** 'stepmul / STEPMULADJ' (value chosen by tests)\n*/\n#define STEPMULADJ\t\t200\n\n\n/*\n** macro to adjust 'pause': 'pause' is actually used like\n** 'pause / PAUSEADJ' (value chosen by tests)\n*/\n#define PAUSEADJ\t\t100\n\n\n/*\n** 'makewhite' erases all color bits then sets only the current white\n** bit\n*/\n#define maskcolors\t(~(bitmask(BLACKBIT) | WHITEBITS))\n#define makewhite(g,x)\t\\\n (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))\n\n#define white2gray(x)\tresetbits(x->marked, WHITEBITS)\n#define black2gray(x)\tresetbit(x->marked, BLACKBIT)\n\n\n#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))\n\n#define checkdeadkey(n)\tlua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))\n\n\n#define checkconsistency(obj)  \\\n  lua_longassert(!iscollectable(obj) || righttt(obj))\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t)\t{ if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }\n\n/*\n** mark an object that can be NULL (either because it is really optional,\n** or it was stripped as debug info, or inside an uncompleted structure)\n*/\n#define markobjectN(g,t)\t{ if (t) markobject(g,t); }\n\nstatic void reallymarkobject (global_State *g, GCObject *o);\n\n\n/*\n** {======================================================\n** Generic functions\n** =======================================================\n*/\n\n\n/*\n** one after last element in a hash array\n*/\n#define gnodelast(h)\tgnode(h, cast(size_t, sizenode(h)))\n\n\n/*\n** link collectable object 'o' into list pointed by 'p'\n*/\n#define linkgclist(o,p)\t((o)->gclist = (p), (p) = obj2gco(o))\n\n\n/*\n** If key is not marked, mark its entry as dead. This allows key to be\n** collected, but keeps its entry in the table.  A dead node is needed\n** when Lua looks up for a key (it may be part of a chain) and when\n** traversing a weak table (key might be removed from the table during\n** traversal). Other places never manipulate dead keys, because its\n** associated nil value is enough to signal that the entry is logically\n** empty.\n*/\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (valiswhite(gkey(n)))\n    setdeadvalue(wgkey(n));  /* unused and unmarked key; remove it */\n}\n\n\n/*\n** tells whether a key or value can be cleared from a weak\n** table. Non-collectable objects are never removed from weak\n** tables. Strings behave as 'values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for objects\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (global_State *g, const TValue *o) {\n  if (!iscollectable(o)) return 0;\n  else if (ttisstring(o)) {\n    markobject(g, tsvalue(o));  /* strings are 'values', so are never weak */\n    return 0;\n  }\n  else return iswhite(gcvalue(o));\n}\n\n\n/*\n** barrier that moves collector forward, that is, mark the white object\n** being pointed by a black object. (If in sweep phase, clear the black\n** object to white [sweep it] to avoid other barrier calls for this\n** same object.)\n*/\nvoid luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  if (keepinvariant(g))  /* must keep invariant? */\n    reallymarkobject(g, v);  /* restore invariant */\n  else {  /* sweep phase */\n    lua_assert(issweepphase(g));\n    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */\n  }\n}\n\n\n/*\n** barrier that moves collector backward, that is, mark the black object\n** pointing to a white object as gray again.\n*/\nvoid luaC_barrierback_ (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  lua_assert(isblack(t) && !isdead(g, t));\n  black2gray(t);  /* make table gray (again) */\n  linkgclist(t, g->grayagain);\n}\n\n\n/*\n** barrier for assignments to closed upvalues. Because upvalues are\n** shared among closures, it is impossible to know the color of all\n** closures pointing to it. So, we assume that the object being assigned\n** must be marked.\n*/\nvoid luaC_upvalbarrier_ (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = gcvalue(uv->v);\n  lua_assert(!upisopen(uv));  /* ensured by macro luaC_upvalbarrier */\n  if (keepinvariant(g))\n    markobject(g, o);\n}\n\n\nvoid luaC_fix (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(g->allgc == o);  /* object must be 1st in 'allgc' list! */\n  white2gray(o);  /* they will be gray forever */\n  g->allgc = o->next;  /* remove object from 'allgc' list */\n  o->next = g->fixedgc;  /* link it to 'fixedgc' list */\n  g->fixedgc = o;\n}\n\n\n/*\n** create a new collectable object (with given type and size) and link\n** it to 'allgc' list.\n*/\nGCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {\n  global_State *g = G(L);\n  GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));\n  o->marked = luaC_white(g);\n  o->tt = tt;\n  o->next = g->allgc;\n  g->allgc = o;\n  return o;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Mark functions\n** =======================================================\n*/\n\n\n/*\n** mark an object. Userdata, strings, and closed upvalues are visited\n** and turned black here. Other objects are marked gray and added\n** to appropriate list to be visited (and turned black) later. (Open\n** upvalues are already linked in 'headuv' list.)\n*/\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n reentry:\n  white2gray(o);\n  switch (o->tt) {\n    case LUA_TSHRSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->shrlen);\n      break;\n    }\n    case LUA_TLNGSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      TValue uvalue;\n      markobjectN(g, gco2u(o)->metatable);  /* mark its metatable */\n      gray2black(o);\n      g->GCmemtrav += sizeudata(gco2u(o));\n      getuservalue(g->mainthread, gco2u(o), &uvalue);\n      if (valiswhite(&uvalue)) {  /* markvalue(g, &uvalue); */\n        o = gcvalue(&uvalue);\n        goto reentry;\n      }\n      break;\n    }\n    case LUA_TLCL: {\n      linkgclist(gco2lcl(o), g->gray);\n      break;\n    }\n    case LUA_TCCL: {\n      linkgclist(gco2ccl(o), g->gray);\n      break;\n    }\n    case LUA_TTABLE: {\n      linkgclist(gco2t(o), g->gray);\n      break;\n    }\n    case LUA_TTHREAD: {\n      linkgclist(gco2th(o), g->gray);\n      break;\n    }\n    case LUA_TPROTO: {\n      linkgclist(gco2p(o), g->gray);\n      break;\n    }\n    default: lua_assert(0); break;\n  }\n}\n\n\n/*\n** mark metamethods for basic types\n*/\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i < LUA_NUMTAGS; i++)\n    markobjectN(g, g->mt[i]);\n}\n\n\n/*\n** mark all objects in list of being-finalized\n*/\nstatic void markbeingfnz (global_State *g) {\n  GCObject *o;\n  for (o = g->tobefnz; o != NULL; o = o->next)\n    markobject(g, o);\n}\n\n\n/*\n** Mark all values stored in marked open upvalues from non-marked threads.\n** (Values from marked threads were already marked when traversing the\n** thread.) Remove from the list threads that no longer have upvalues and\n** not-marked threads.\n*/\nstatic void remarkupvals (global_State *g) {\n  lua_State *thread;\n  lua_State **p = &g->twups;\n  while ((thread = *p) != NULL) {\n    lua_assert(!isblack(thread));  /* threads are never black */\n    if (isgray(thread) && thread->openupval != NULL)\n      p = &thread->twups;  /* keep marked thread with upvalues in the list */\n    else {  /* thread is not marked or without upvalues */\n      UpVal *uv;\n      *p = thread->twups;  /* remove thread from the list */\n      thread->twups = thread;  /* mark that it is out of list */\n      for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) {\n        if (uv->u.open.touched) {\n          markvalue(g, uv->v);  /* remark upvalue's value */\n          uv->u.open.touched = 0;\n        }\n      }\n    }\n  }\n}\n\n\n/*\n** mark root set and reset all gray lists, to start a new collection\n*/\nstatic void restartcollection (global_State *g) {\n  g->gray = g->grayagain = NULL;\n  g->weak = g->allweak = g->ephemeron = NULL;\n  markobject(g, g->mainthread);\n  markvalue(g, &g->l_registry);\n  markmt(g);\n  markbeingfnz(g);  /* mark any finalizing object left from previous cycle */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Traverse functions\n** =======================================================\n*/\n\n/*\n** Traverse a table with weak values and link it to proper list. During\n** propagate phase, keep it in 'grayagain' list, to be revisited in the\n** atomic phase. In the atomic phase, if table has any white value,\n** put it in 'weak' list, to be cleared.\n*/\nstatic void traverseweakvalue (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  /* if there is array part, assume it may have white values (it is not\n     worth traversing it now just to check) */\n  int hasclears = (h->sizearray > 0);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      if (!hasclears && iscleared(g, gval(n)))  /* is there a white value? */\n        hasclears = 1;  /* table will have to be cleared */\n    }\n  }\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasclears)\n    linkgclist(h, g->weak);  /* has to be cleared later */\n}\n\n\n/*\n** Traverse an ephemeron table and link it to proper list. Returns true\n** iff any object was marked during this traversal (which implies that\n** convergence has to continue). During propagation phase, keep table\n** in 'grayagain' list, to be visited again in the atomic phase. In\n** the atomic phase, if table has any white->white entry, it has to\n** be revisited during ephemeron convergence (as that key may turn\n** black). Otherwise, if it has any white key, table has to be cleared\n** (in the atomic phase).\n*/\nstatic int traverseephemeron (global_State *g, Table *h) {\n  int marked = 0;  /* true if an object is marked in this traversal */\n  int hasclears = 0;  /* true if table has white keys */\n  int hasww = 0;  /* true if table has entry \"white-key -> white-value\" */\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  /* traverse array part */\n  for (i = 0; i < h->sizearray; i++) {\n    if (valiswhite(&h->array[i])) {\n      marked = 1;\n      reallymarkobject(g, gcvalue(&h->array[i]));\n    }\n  }\n  /* traverse hash part */\n  for (n = gnode(h, 0); n < limit; n++) {\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else if (iscleared(g, gkey(n))) {  /* key is not marked (yet)? */\n      hasclears = 1;  /* table must be cleared */\n      if (valiswhite(gval(n)))  /* value not marked yet? */\n        hasww = 1;  /* white-white entry */\n    }\n    else if (valiswhite(gval(n))) {  /* value not marked yet? */\n      marked = 1;\n      reallymarkobject(g, gcvalue(gval(n)));  /* mark it now */\n    }\n  }\n  /* link table into proper list */\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasww)  /* table has white->white entries? */\n    linkgclist(h, g->ephemeron);  /* have to propagate again */\n  else if (hasclears)  /* table has white keys? */\n    linkgclist(h, g->allweak);  /* may have to clean white keys */\n  return marked;\n}\n\n\nstatic void traversestrongtable (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  for (i = 0; i < h->sizearray; i++)  /* traverse array part */\n    markvalue(g, &h->array[i]);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      markvalue(g, gval(n));  /* mark value */\n    }\n  }\n}\n\n\nstatic lu_mem traversetable (global_State *g, Table *h) {\n  const char *weakkey, *weakvalue;\n  const TValue *mode = gfasttm(g, h->metatable, TM_MODE);\n  markobjectN(g, h->metatable);\n  if (mode && ttisstring(mode) &&  /* is there a weak mode? */\n      ((weakkey = strchr(svalue(mode), 'k')),\n       (weakvalue = strchr(svalue(mode), 'v')),\n       (weakkey || weakvalue))) {  /* is really weak? */\n    black2gray(h);  /* keep table gray */\n    if (!weakkey)  /* strong keys? */\n      traverseweakvalue(g, h);\n    else if (!weakvalue)  /* strong values? */\n      traverseephemeron(g, h);\n    else  /* all weak */\n      linkgclist(h, g->allweak);  /* nothing to traverse now */\n  }\n  else  /* not weak */\n    traversestrongtable(g, h);\n  return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                         sizeof(Node) * cast(size_t, allocsizenode(h));\n}\n\n\n/*\n** Traverse a prototype. (While a prototype is being build, its\n** arrays can be larger than needed; the extra slots are filled with\n** NULL, so the use of 'markobjectN')\n*/\nstatic int traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->cache && iswhite(f->cache))\n    f->cache = NULL;  /* allow cache to be collected */\n  markobjectN(g, f->source);\n  for (i = 0; i < f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */\n    markobjectN(g, f->upvalues[i].name);\n  for (i = 0; i < f->sizep; i++)  /* mark nested protos */\n    markobjectN(g, f->p[i]);\n  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */\n    markobjectN(g, f->locvars[i].varname);\n  return sizeof(Proto) + sizeof(Instruction) * f->sizecode +\n                         sizeof(Proto *) * f->sizep +\n                         sizeof(TValue) * f->sizek +\n                         sizeof(int) * f->sizelineinfo +\n                         sizeof(LocVar) * f->sizelocvars +\n                         sizeof(Upvaldesc) * f->sizeupvalues;\n}\n\n\nstatic lu_mem traverseCclosure (global_State *g, CClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++)  /* mark its upvalues */\n    markvalue(g, &cl->upvalue[i]);\n  return sizeCclosure(cl->nupvalues);\n}\n\n/*\n** open upvalues point to values in a thread, so those values should\n** be marked when the thread is traversed except in the atomic phase\n** (because then the value cannot be changed by the thread and the\n** thread may not be traversed again)\n*/\nstatic lu_mem traverseLclosure (global_State *g, LClosure *cl) {\n  int i;\n  markobjectN(g, cl->p);  /* mark its prototype */\n  for (i = 0; i < cl->nupvalues; i++) {  /* mark its upvalues */\n    UpVal *uv = cl->upvals[i];\n    if (uv != NULL) {\n      if (upisopen(uv) && g->gcstate != GCSinsideatomic)\n        uv->u.open.touched = 1;  /* can be marked in 'remarkupvals' */\n      else\n        markvalue(g, uv->v);\n    }\n  }\n  return sizeLclosure(cl->nupvalues);\n}\n\n\nstatic lu_mem traversethread (global_State *g, lua_State *th) {\n  StkId o = th->stack;\n  if (o == NULL)\n    return 1;  /* stack not completely built yet */\n  lua_assert(g->gcstate == GCSinsideatomic ||\n             th->openupval == NULL || isintwups(th));\n  for (; o < th->top; o++)  /* mark live elements in the stack */\n    markvalue(g, o);\n  if (g->gcstate == GCSinsideatomic) {  /* final traversal? */\n    StkId lim = th->stack + th->stacksize;  /* real end of stack */\n    for (; o < lim; o++)  /* clear not-marked stack slice */\n      setnilvalue(o);\n    /* 'remarkupvals' may have removed thread from 'twups' list */\n    if (!isintwups(th) && th->openupval != NULL) {\n      th->twups = g->twups;  /* link it back to the list */\n      g->twups = th;\n    }\n  }\n  else if (g->gckind != KGC_EMERGENCY)\n    luaD_shrinkstack(th); /* do not change stack in emergency cycle */\n  return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n          sizeof(CallInfo) * th->nci);\n}\n\n\n/*\n** traverse one gray object, turning it to black (except for threads,\n** which are always gray).\n*/\nstatic void propagatemark (global_State *g) {\n  lu_mem size;\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2t(o);\n      g->gray = h->gclist;  /* remove from 'gray' list */\n      size = traversetable(g, h);\n      break;\n    }\n    case LUA_TLCL: {\n      LClosure *cl = gco2lcl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseLclosure(g, cl);\n      break;\n    }\n    case LUA_TCCL: {\n      CClosure *cl = gco2ccl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseCclosure(g, cl);\n      break;\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;  /* remove from 'gray' list */\n      linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n      black2gray(o);\n      size = traversethread(g, th);\n      break;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;  /* remove from 'gray' list */\n      size = traverseproto(g, p);\n      break;\n    }\n    default: lua_assert(0); return;\n  }\n  g->GCmemtrav += size;\n}\n\n\nstatic void propagateall (global_State *g) {\n  while (g->gray) propagatemark(g);\n}\n\n\nstatic void convergeephemerons (global_State *g) {\n  int changed;\n  do {\n    GCObject *w;\n    GCObject *next = g->ephemeron;  /* get ephemeron list */\n    g->ephemeron = NULL;  /* tables may return to this list when traversed */\n    changed = 0;\n    while ((w = next) != NULL) {\n      next = gco2t(w)->gclist;\n      if (traverseephemeron(g, gco2t(w))) {  /* traverse marked some value? */\n        propagateall(g);  /* propagate changes */\n        changed = 1;  /* will have to revisit all ephemeron tables */\n      }\n    }\n  } while (changed);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Sweep Functions\n** =======================================================\n*/\n\n\n/*\n** clear entries with unmarked keys from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearkeys (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {\n        setnilvalue(gval(n));  /* remove value ... */\n      }\n\t  if (ttisnil(gval(n)))  /* is entry empty? */\n\t    removeentry(n);  /* remove entry from table */\n    }\n  }\n}\n\n\n/*\n** clear entries with unmarked values from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearvalues (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    unsigned int i;\n    for (i = 0; i < h->sizearray; i++) {\n      TValue *o = &h->array[i];\n      if (iscleared(g, o))  /* value was collected? */\n        setnilvalue(o);  /* remove value */\n    }\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\nvoid luaC_upvdeccount (lua_State *L, UpVal *uv) {\n  lua_assert(uv->refcount > 0);\n  uv->refcount--;\n  if (uv->refcount == 0 && !upisopen(uv))\n    luaM_free(L, uv);\n}\n\n\nstatic void freeLclosure (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = cl->upvals[i];\n    if (uv)\n      luaC_upvdeccount(L, uv);\n  }\n  luaM_freemem(L, cl, sizeLclosure(cl->nupvalues));\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TLCL: {\n      freeLclosure(L, gco2lcl(o));\n      break;\n    }\n    case LUA_TCCL: {\n      luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));\n      break;\n    }\n    case LUA_TTABLE: luaH_free(L, gco2t(o)); break;\n    case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;\n    case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;\n    case LUA_TSHRSTR:\n      luaS_remove(L, gco2ts(o));  /* remove it from hash table */\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));\n      break;\n    case LUA_TLNGSTR: {\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);\n\n\n/*\n** sweep at most 'count' elements from a list of GCObjects erasing dead\n** objects, where a dead object is one marked with the old (non current)\n** white; change all non-dead objects back to white, preparing for next\n** collection cycle. Return where to continue the traversal or NULL if\n** list is finished.\n*/\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  global_State *g = G(L);\n  int ow = otherwhite(g);\n  int white = luaC_white(g);  /* current white */\n  while (*p != NULL && count-- > 0) {\n    GCObject *curr = *p;\n    int marked = curr->marked;\n    if (isdeadm(ow, marked)) {  /* is 'curr' dead? */\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* change mark to 'white' */\n      curr->marked = cast_byte((marked & maskcolors) | white);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  return (*p == NULL) ? NULL : p;\n}\n\n\n/*\n** sweep a list until a live object (or end of list)\n*/\nstatic GCObject **sweeptolive (lua_State *L, GCObject **p) {\n  GCObject **old = p;\n  do {\n    p = sweeplist(L, p, 1);\n  } while (p == old);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Finalization\n** =======================================================\n*/\n\n/*\n** If possible, shrink string table\n*/\nstatic void checkSizes (lua_State *L, global_State *g) {\n  if (g->gckind != KGC_EMERGENCY) {\n    l_mem olddebt = g->GCdebt;\n    if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */\n      luaS_resize(L, g->strt.size / 2);  /* shrink it a little */\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n  }\n}\n\n\nstatic GCObject *udata2finalize (global_State *g) {\n  GCObject *o = g->tobefnz;  /* get first element */\n  lua_assert(tofinalize(o));\n  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */\n  o->next = g->allgc;  /* return it to 'allgc' list */\n  g->allgc = o;\n  resetbit(o->marked, FINALIZEDBIT);  /* object is \"normal\" again */\n  if (issweepphase(g))\n    makewhite(g, o);  /* \"sweep\" object */\n  return o;\n}\n\n\nstatic void dothecall (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 2, 0);\n}\n\n\nstatic void GCTM (lua_State *L, int propagateerrors) {\n  global_State *g = G(L);\n  const TValue *tm;\n  TValue v;\n  setgcovalue(L, &v, udata2finalize(g));\n  tm = luaT_gettmbyobj(L, &v, TM_GC);\n  if (tm != NULL && ttisfunction(tm)) {  /* is there a finalizer? */\n    int status;\n    lu_byte oldah = L->allowhook;\n    int running  = g->gcrunning;\n    L->allowhook = 0;  /* stop debug hooks during GC metamethod */\n    g->gcrunning = 0;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);  /* push finalizer... */\n    setobj2s(L, L->top + 1, &v);  /* ... and its argument */\n    L->top += 2;  /* and (next line) call the finalizer */\n    L->ci->callstatus |= CIST_FIN;  /* will run a finalizer */\n    status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);\n    L->ci->callstatus &= ~CIST_FIN;  /* not running a finalizer anymore */\n    L->allowhook = oldah;  /* restore hooks */\n    g->gcrunning = running;  /* restore state */\n    if (status != LUA_OK && propagateerrors) {  /* error while running __gc? */\n      if (status == LUA_ERRRUN) {  /* is there an error object? */\n        const char *msg = (ttisstring(L->top - 1))\n                            ? svalue(L->top - 1)\n                            : \"no message\";\n        luaO_pushfstring(L, \"error in __gc metamethod (%s)\", msg);\n        status = LUA_ERRGCMM;  /* error in __gc metamethod */\n      }\n      luaD_throw(L, status);  /* re-throw error */\n    }\n  }\n}\n\n\n/*\n** call a few (up to 'g->gcfinnum') finalizers\n*/\nstatic int runafewfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  unsigned int i;\n  lua_assert(!g->tobefnz || g->gcfinnum > 0);\n  for (i = 0; g->tobefnz && i < g->gcfinnum; i++)\n    GCTM(L, 1);  /* call one finalizer */\n  g->gcfinnum = (!g->tobefnz) ? 0  /* nothing more to finalize? */\n                    : g->gcfinnum * 2;  /* else call a few more next time */\n  return i;\n}\n\n\n/*\n** call all pending finalizers\n*/\nstatic void callallpendingfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  while (g->tobefnz)\n    GCTM(L, 0);\n}\n\n\n/*\n** find last 'next' field in list 'p' list (to add elements in its end)\n*/\nstatic GCObject **findlast (GCObject **p) {\n  while (*p != NULL)\n    p = &(*p)->next;\n  return p;\n}\n\n\n/*\n** move all unreachable objects (or 'all' objects) that need\n** finalization from list 'finobj' to list 'tobefnz' (to be finalized)\n*/\nstatic void separatetobefnz (global_State *g, int all) {\n  GCObject *curr;\n  GCObject **p = &g->finobj;\n  GCObject **lastnext = findlast(&g->tobefnz);\n  while ((curr = *p) != NULL) {  /* traverse all finalizable objects */\n    lua_assert(tofinalize(curr));\n    if (!(iswhite(curr) || all))  /* not being collected? */\n      p = &curr->next;  /* don't bother with it */\n    else {\n      *p = curr->next;  /* remove 'curr' from 'finobj' list */\n      curr->next = *lastnext;  /* link at the end of 'tobefnz' list */\n      *lastnext = curr;\n      lastnext = &curr->next;\n    }\n  }\n}\n\n\n/*\n** if object 'o' has a finalizer, remove it from 'allgc' list (must\n** search the list to find it) and link it in 'finobj' list.\n*/\nvoid luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {\n  global_State *g = G(L);\n  if (tofinalize(o) ||                 /* obj. is already marked... */\n      gfasttm(g, mt, TM_GC) == NULL)   /* or has no finalizer? */\n    return;  /* nothing to be done */\n  else {  /* move 'o' to 'finobj' list */\n    GCObject **p;\n    if (issweepphase(g)) {\n      makewhite(g, o);  /* \"sweep\" object 'o' */\n      if (g->sweepgc == &o->next)  /* should not remove 'sweepgc' object */\n        g->sweepgc = sweeptolive(L, g->sweepgc);  /* change 'sweepgc' */\n    }\n    /* search for pointer pointing to 'o' */\n    for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }\n    *p = o->next;  /* remove 'o' from 'allgc' list */\n    o->next = g->finobj;  /* link it in 'finobj' list */\n    g->finobj = o;\n    l_setbit(o->marked, FINALIZEDBIT);  /* mark it as such */\n  }\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** GC control\n** =======================================================\n*/\n\n\n/*\n** Set a reasonable \"time\" to wait before starting a new GC cycle; cycle\n** will start when memory use hits threshold. (Division by 'estimate'\n** should be OK: it cannot be zero (because Lua cannot even start with\n** less than PAUSEADJ bytes).\n*/\nstatic void setpause (global_State *g) {\n  l_mem threshold, debt;\n  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */\n  lua_assert(estimate > 0);\n  threshold = (g->gcpause < MAX_LMEM / estimate)  /* overflow? */\n            ? estimate * g->gcpause  /* no overflow */\n            : MAX_LMEM;  /* overflow; truncate to maximum */\n  debt = gettotalbytes(g) - threshold;\n  luaE_setdebt(g, debt);\n}\n\n\n/*\n** Enter first sweep phase.\n** The call to 'sweeplist' tries to make pointer point to an object\n** inside the list (instead of to the header), so that the real sweep do\n** not need to skip objects created between \"now\" and the start of the\n** real sweep.\n*/\nstatic void entersweep (lua_State *L) {\n  global_State *g = G(L);\n  g->gcstate = GCSswpallgc;\n  lua_assert(g->sweepgc == NULL);\n  g->sweepgc = sweeplist(L, &g->allgc, 1);\n}\n\n\nvoid luaC_freeallobjects (lua_State *L) {\n  global_State *g = G(L);\n  separatetobefnz(g, 1);  /* separate all objects with finalizers */\n  lua_assert(g->finobj == NULL);\n  callallpendingfinalizers(L);\n  lua_assert(g->tobefnz == NULL);\n  g->currentwhite = WHITEBITS; /* this \"white\" makes all objects look dead */\n  g->gckind = KGC_NORMAL;\n  sweepwholelist(L, &g->finobj);\n  sweepwholelist(L, &g->allgc);\n  sweepwholelist(L, &g->fixedgc);  /* collect fixed objects */\n  lua_assert(g->strt.nuse == 0);\n}\n\n\nstatic l_mem atomic (lua_State *L) {\n  global_State *g = G(L);\n  l_mem work;\n  GCObject *origweak, *origall;\n  GCObject *grayagain = g->grayagain;  /* save original list */\n  lua_assert(g->ephemeron == NULL && g->weak == NULL);\n  lua_assert(!iswhite(g->mainthread));\n  g->gcstate = GCSinsideatomic;\n  g->GCmemtrav = 0;  /* start counting work */\n  markobject(g, L);  /* mark running thread */\n  /* registry and global metatables may be changed by API */\n  markvalue(g, &g->l_registry);\n  markmt(g);  /* mark global metatables */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  propagateall(g);  /* propagate changes */\n  work = g->GCmemtrav;  /* stop counting (do not recount 'grayagain') */\n  g->gray = grayagain;\n  propagateall(g);  /* traverse 'grayagain' list */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all strongly accessible objects are marked. */\n  /* Clear values from weak tables, before checking finalizers */\n  clearvalues(g, g->weak, NULL);\n  clearvalues(g, g->allweak, NULL);\n  origweak = g->weak; origall = g->allweak;\n  work += g->GCmemtrav;  /* stop counting (objects being finalized) */\n  separatetobefnz(g, 0);  /* separate objects to be finalized */\n  g->gcfinnum = 1;  /* there may be objects to be finalized */\n  markbeingfnz(g);  /* mark objects that will be finalized */\n  propagateall(g);  /* remark, to propagate 'resurrection' */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all resurrected objects are marked. */\n  /* remove dead objects from weak tables */\n  clearkeys(g, g->ephemeron, NULL);  /* clear keys from all ephemeron tables */\n  clearkeys(g, g->allweak, NULL);  /* clear keys from all 'allweak' tables */\n  /* clear values from resurrected weak tables */\n  clearvalues(g, g->weak, origweak);\n  clearvalues(g, g->allweak, origall);\n  luaS_clearcache(g);\n  g->currentwhite = cast_byte(otherwhite(g));  /* flip current white */\n  work += g->GCmemtrav;  /* complete counting */\n  return work;  /* estimate of memory marked by 'atomic' */\n}\n\n\nstatic lu_mem sweepstep (lua_State *L, global_State *g,\n                         int nextstate, GCObject **nextlist) {\n  if (g->sweepgc) {\n    l_mem olddebt = g->GCdebt;\n    g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n    if (g->sweepgc)  /* is there still something to sweep? */\n      return (GCSWEEPMAX * GCSWEEPCOST);\n  }\n  /* else enter next state */\n  g->gcstate = nextstate;\n  g->sweepgc = nextlist;\n  return 0;\n}\n\n\nstatic lu_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  switch (g->gcstate) {\n    case GCSpause: {\n      g->GCmemtrav = g->strt.size * sizeof(GCObject*);\n      restartcollection(g);\n      g->gcstate = GCSpropagate;\n      return g->GCmemtrav;\n    }\n    case GCSpropagate: {\n      g->GCmemtrav = 0;\n      lua_assert(g->gray);\n      propagatemark(g);\n       if (g->gray == NULL)  /* no more gray objects? */\n        g->gcstate = GCSatomic;  /* finish propagate phase */\n      return g->GCmemtrav;  /* memory traversed in this step */\n    }\n    case GCSatomic: {\n      lu_mem work;\n      propagateall(g);  /* make sure gray list is empty */\n      work = atomic(L);  /* work is what was traversed by 'atomic' */\n      entersweep(L);\n      g->GCestimate = gettotalbytes(g);  /* first estimate */;\n      return work;\n    }\n    case GCSswpallgc: {  /* sweep \"regular\" objects */\n      return sweepstep(L, g, GCSswpfinobj, &g->finobj);\n    }\n    case GCSswpfinobj: {  /* sweep objects with finalizers */\n      return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);\n    }\n    case GCSswptobefnz: {  /* sweep objects to be finalized */\n      return sweepstep(L, g, GCSswpend, NULL);\n    }\n    case GCSswpend: {  /* finish sweeps */\n      makewhite(g, g->mainthread);  /* sweep main thread */\n      checkSizes(L, g);\n      g->gcstate = GCScallfin;\n      return 0;\n    }\n    case GCScallfin: {  /* call remaining finalizers */\n      if (g->tobefnz && g->gckind != KGC_EMERGENCY) {\n        int n = runafewfinalizers(L);\n        return (n * GCFINALIZECOST);\n      }\n      else {  /* emergency mode or no more finalizers */\n        g->gcstate = GCSpause;  /* finish collection */\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** advances the garbage collector until it reaches a state allowed\n** by 'statemask'\n*/\nvoid luaC_runtilstate (lua_State *L, int statesmask) {\n  global_State *g = G(L);\n  while (!testbit(statesmask, g->gcstate))\n    singlestep(L);\n}\n\n\n/*\n** get GC debt and convert it from Kb to 'work units' (avoid zero debt\n** and overflows)\n*/\nstatic l_mem getdebt (global_State *g) {\n  l_mem debt = g->GCdebt;\n  int stepmul = g->gcstepmul;\n  if (debt <= 0) return 0;  /* minimal debt */\n  else {\n    debt = (debt / STEPMULADJ) + 1;\n    debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;\n    return debt;\n  }\n}\n\n/*\n** performs a basic GC step when collector is running\n*/\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  l_mem debt = getdebt(g);  /* GC deficit (be paid now) */\n  if (!g->gcrunning) {  /* not running? */\n    luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */\n    return;\n  }\n  do {  /* repeat until pause or enough \"credit\" (negative debt) */\n    lu_mem work = singlestep(L);  /* perform one single step */\n    debt -= work;\n  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);\n  if (g->gcstate == GCSpause)\n    setpause(g);  /* pause until next cycle */\n  else {\n    debt = (debt / g->gcstepmul) * STEPMULADJ;  /* convert 'work units' to Kb */\n    luaE_setdebt(g, debt);\n    runafewfinalizers(L);\n  }\n}\n\n\n/*\n** Performs a full GC cycle; if 'isemergency', set a flag to avoid\n** some operations which could change the interpreter state in some\n** unexpected ways (running finalizers and shrinking some structures).\n** Before running the collection, check 'keepinvariant'; if it is true,\n** there may be some objects marked as black, so the collector has\n** to sweep all objects to turn them back to white (as white has not\n** changed, nothing will be collected).\n*/\nvoid luaC_fullgc (lua_State *L, int isemergency) {\n  global_State *g = G(L);\n  lua_assert(g->gckind == KGC_NORMAL);\n  if (isemergency) g->gckind = KGC_EMERGENCY;  /* set flag */\n  if (keepinvariant(g)) {  /* black objects? */\n    entersweep(L); /* sweep everything to turn them back to white */\n  }\n  /* finish any pending sweep phase to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpause));\n  luaC_runtilstate(L, ~bitmask(GCSpause));  /* start new collection */\n  luaC_runtilstate(L, bitmask(GCScallfin));  /* run up to finalizers */\n  /* estimate must be correct after a full GC cycle */\n  lua_assert(g->GCestimate == gettotalbytes(g));\n  luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n  g->gckind = KGC_NORMAL;\n  setpause(g);\n}\n\n/* }====================================================== */\n\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n/*\n** Collectable objects may have one of three colors: white, which\n** means the object is not marked; gray, which means the\n** object is marked, but its references may be not marked; and\n** black, which means that the object and all its references are marked.\n** The main invariant of the garbage collector, while marking objects,\n** is that a black object can never point to a white one. Moreover,\n** any gray object must be in a \"gray list\" (gray, grayagain, weak,\n** allweak, ephemeron) so that it can be visited again before finishing\n** the collection cycle. These lists have no meaning when the invariant\n** is not being enforced (e.g., sweep phase).\n*/\n\n\n\n/* how much to allocate before next GC step */\n#if !defined(GCSTEPSIZE)\n/* ~100 small strings */\n#define GCSTEPSIZE\t(cast_int(100 * sizeof(TString)))\n#endif\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpropagate\t0\n#define GCSatomic\t1\n#define GCSswpallgc\t2\n#define GCSswpfinobj\t3\n#define GCSswptobefnz\t4\n#define GCSswpend\t5\n#define GCScallfin\t6\n#define GCSpause\t7\n\n\n#define issweepphase(g)  \\\n\t(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)\n\n\n/*\n** macro to tell when main invariant (white objects cannot point to black\n** ones) must be kept. During a collection, the sweep\n** phase may break the invariant, as objects turned white may point to\n** still-black objects. The invariant is restored when sweep ends and\n** all objects are white again.\n*/\n\n#define keepinvariant(g)\t((g)->gcstate <= GCSatomic)\n\n\n/*\n** some useful bit tricks\n*/\n#define resetbits(x,m)\t\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t\t((x) |= (m))\n#define testbits(x,m)\t\t((x) & (m))\n#define bitmask(b)\t\t(1<<(b))\n#define bit2mask(b1,b2)\t\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\t\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\t\tresetbits(x, bitmask(b))\n#define testbit(x,b)\t\ttestbits(x, bitmask(b))\n\n\n/* Layout for bit use in 'marked' field: */\n#define WHITE0BIT\t0  /* object is white (type 0) */\n#define WHITE1BIT\t1  /* object is white (type 1) */\n#define BLACKBIT\t2  /* object is black */\n#define FINALIZEDBIT\t3  /* object has been marked for finalization */\n/* bit 7 is currently used by tests (luaL_checkmemory) */\n\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      testbits((x)->marked, WHITEBITS)\n#define isblack(x)      testbit((x)->marked, BLACKBIT)\n#define isgray(x)  /* neither white nor black */  \\\n\t(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))\n\n#define tofinalize(x)\ttestbit((x)->marked, FINALIZEDBIT)\n\n#define otherwhite(g)\t((g)->currentwhite ^ WHITEBITS)\n#define isdeadm(ow,m)\t(!(((m) ^ WHITEBITS) & (ow)))\n#define isdead(g,v)\tisdeadm(otherwhite(g), (v)->marked)\n\n#define changewhite(x)\t((x)->marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->marked, BLACKBIT)\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n\n/*\n** Does one step of collection when debt becomes positive. 'pre'/'pos'\n** allows some adjustments to be done only when needed. macro\n** 'condchangemem' is used only for heavy tests (forcing a full\n** GC cycle on every opportunity)\n*/\n#define luaC_condGC(L,pre,pos) \\\n\t{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \\\n\t  condchangemem(L,pre,pos); }\n\n/* more often than not, 'pre'/'pos' are empty */\n#define luaC_checkGC(L)\t\tluaC_condGC(L,(void)0,(void)0)\n\n\n#define luaC_barrier(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \\\n\tluaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))\n\n#define luaC_barrierback(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \\\n\tluaC_barrierback_(L,p) : cast_void(0))\n\n#define luaC_objbarrier(L,p,o) (  \\\n\t(isblack(p) && iswhite(o)) ? \\\n\tluaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))\n\n#define luaC_upvalbarrier(L,uv) ( \\\n\t(iscollectable((uv)->v) && !upisopen(uv)) ? \\\n         luaC_upvalbarrier_(L,uv) : cast_void(0))\n\nLUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_freeallobjects (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);\nLUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);\nLUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);\nLUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o);\nLUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);\nLUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $\n** Initialization of libraries for lua.c and other clients\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n/*\n** If you embed Lua in your program and need to open the standard\n** libraries, call luaL_openlibs in your program. If you need a\n** different set of libraries, copy this file to your project and edit\n** it to suit your needs.\n**\n** You can also *preload* libraries, so that a later 'require' can\n** open the library, which is already linked to the application.\n** For that, do the following code:\n**\n**  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n**  lua_pushcfunction(L, luaopen_modname);\n**  lua_setfield(L, -2, modname);\n**  lua_pop(L, 1);  // remove PRELOAD table\n*/\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\n/*\n** these libs are loaded by lua.c and are readily available to any Lua\n** program\n*/\nstatic const luaL_Reg loadedlibs[] = {\n  {\"_G\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_COLIBNAME, luaopen_coroutine},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_UTF8LIBNAME, luaopen_utf8},\n  {LUA_DBLIBNAME, luaopen_debug},\n#if defined(LUA_COMPAT_BITLIB)\n  {LUA_BITLIBNAME, luaopen_bit32},\n#endif\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib;\n  /* \"require\" functions from 'loadedlibs' and set results to global table */\n  for (lib = loadedlibs; lib->func; lib++) {\n    luaL_requiref(L, lib->name, lib->func, 1);\n    lua_pop(L, 1);  /* remove lib */\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <locale.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** Change this macro to accept other modes for 'fopen' besides\n** the standard ones.\n*/\n#if !defined(l_checkmode)\n\n/* accepted extensions to 'mode' in 'fopen' */\n#if !defined(L_MODEEXT)\n#define L_MODEEXT\t\"b\"\n#endif\n\n/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */\nstatic int l_checkmode (const char *mode) {\n  return (*mode != '\\0' && strchr(\"rwa\", *(mode++)) != NULL &&\n         (*mode != '+' || (++mode, 1)) &&  /* skip if char is '+' */\n         (strspn(mode, L_MODEEXT) == strlen(mode)));  /* check extensions */\n}\n\n#endif\n\n/*\n** {======================================================\n** l_popen spawns a new process connected to the current\n** one through the file streams.\n** =======================================================\n*/\n\n#if !defined(l_popen)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_popen(L,c,m)\t\t(fflush(NULL), popen(c,m))\n#define l_pclose(L,file)\t(pclose(file))\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#define l_popen(L,c,m)\t\t(_popen(c,m))\n#define l_pclose(L,file)\t(_pclose(file))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_popen(L,c,m)  \\\n\t  ((void)((void)c, m), \\\n\t  luaL_error(L, \"'popen' not supported\"), \\\n\t  (FILE*)0)\n#define l_pclose(L,file)\t\t((void)L, (void)file, -1)\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#if !defined(l_getc)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\n#define l_getc(f)\t\tgetc_unlocked(f)\n#define l_lockfile(f)\t\tflockfile(f)\n#define l_unlockfile(f)\t\tfunlockfile(f)\n#else\n#define l_getc(f)\t\tgetc(f)\n#define l_lockfile(f)\t\t((void)0)\n#define l_unlockfile(f)\t\t((void)0)\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** {======================================================\n** l_fseek: configuration for longer offsets\n** =======================================================\n*/\n\n#if !defined(l_fseek)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <sys/types.h>\n\n#define l_fseek(f,o,w)\t\tfseeko(f,o,w)\n#define l_ftell(f)\t\tftello(f)\n#define l_seeknum\t\toff_t\n\n#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \\\n   && defined(_MSC_VER) && (_MSC_VER >= 1400)\t/* }{ */\n\n/* Windows (but not DDK) and Visual C++ 2005 or higher */\n#define l_fseek(f,o,w)\t\t_fseeki64(f,o,w)\n#define l_ftell(f)\t\t_ftelli64(f)\n#define l_seeknum\t\t__int64\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_fseek(f,o,w)\t\tfseek(f,o,w)\n#define l_ftell(f)\t\tftell(f)\n#define l_seeknum\t\tlong\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#define IO_PREFIX\t\"_IO_\"\n#define IOPREF_LEN\t(sizeof(IO_PREFIX)/sizeof(char) - 1)\n#define IO_INPUT\t(IO_PREFIX \"input\")\n#define IO_OUTPUT\t(IO_PREFIX \"output\")\n\n\ntypedef luaL_Stream LStream;\n\n\n#define tolstream(L)\t((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n#define isclosed(p)\t((p)->closef == NULL)\n\n\nstatic int io_type (lua_State *L) {\n  LStream *p;\n  luaL_checkany(L, 1);\n  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);\n  if (p == NULL)\n    lua_pushnil(L);  /* not a file */\n  else if (isclosed(p))\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic int f_tostring (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", p->f);\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    luaL_error(L, \"attempt to use a closed file\");\n  lua_assert(p->f);\n  return p->f;\n}\n\n\n/*\n** When creating file handles, always creates a 'closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** handle is in a consistent state.\n*/\nstatic LStream *newprefile (lua_State *L) {\n  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));\n  p->closef = NULL;  /* mark file handle as 'closed' */\n  luaL_setmetatable(L, LUA_FILEHANDLE);\n  return p;\n}\n\n\n/*\n** Calls the 'close' function from a file handle. The 'volatile' avoids\n** a bug in some versions of the Clang compiler (e.g., clang 3.0 for\n** 32 bits).\n*/\nstatic int aux_close (lua_State *L) {\n  LStream *p = tolstream(L);\n  volatile lua_CFunction cf = p->closef;\n  p->closef = NULL;  /* mark stream as closed */\n  return (*cf)(L);  /* close it */\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))  /* no argument? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */\n  tofile(L);  /* make sure argument is an open stream */\n  return aux_close(L);\n}\n\n\nstatic int f_gc (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (!isclosed(p) && p->f != NULL)\n    aux_close(L);  /* ignore closed and incompletely open files */\n  return 0;\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  int res = fclose(p->f);\n  return luaL_fileresult(L, (res == 0), NULL);\n}\n\n\nstatic LStream *newfile (lua_State *L) {\n  LStream *p = newprefile(L);\n  p->f = NULL;\n  p->closef = &io_fclose;\n  return p;\n}\n\n\nstatic void opencheck (lua_State *L, const char *fname, const char *mode) {\n  LStream *p = newfile(L);\n  p->f = fopen(fname, mode);\n  if (p->f == NULL)\n    luaL_error(L, \"cannot open file '%s' (%s)\", fname, strerror(errno));\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newfile(L);\n  const char *md = mode;  /* to traverse/check mode */\n  luaL_argcheck(L, l_checkmode(md), 2, \"invalid mode\");\n  p->f = fopen(filename, mode);\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  LStream *p = tolstream(L);\n  return luaL_execresult(L, l_pclose(L, p->f));\n#endif\n}\n\n\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newprefile(L);\n  p->f = l_popen(L, filename, mode);\n  p->closef = &io_pclose;\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  LStream *p = newfile(L);\n  p->f = tmpfile();\n  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, const char *findex) {\n  LStream *p;\n  lua_getfield(L, LUA_REGISTRYINDEX, findex);\n  p = (LStream *)lua_touserdata(L, -1);\n  if (isclosed(p))\n    luaL_error(L, \"standard %s file is closed\", findex + IOPREF_LEN);\n  return p->f;\n}\n\n\nstatic int g_iofile (lua_State *L, const char *f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename)\n      opencheck(L, filename, mode);\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_setfield(L, LUA_REGISTRYINDEX, f);\n  }\n  /* return current value */\n  lua_getfield(L, LUA_REGISTRYINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\n/*\n** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit\n** in the limit for upvalues of a closure)\n*/\n#define MAXARGLINE\t250\n\nstatic void aux_lines (lua_State *L, int toclose) {\n  int n = lua_gettop(L) - 1;  /* number of arguments to read */\n  luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, \"too many arguments\");\n  lua_pushinteger(L, n);  /* number of arguments to read */\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_rotate(L, 2, 2);  /* move 'n' and 'toclose' to their positions */\n  lua_pushcclosure(L, io_readline, 3 + n);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  int toclose;\n  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */\n  if (lua_isnil(L, 1)) {  /* no file name? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */\n    lua_replace(L, 1);  /* put it at index 1 */\n    tofile(L);  /* check that it's a valid file handle */\n    toclose = 0;  /* do not close it after iteration */\n  }\n  else {  /* open a new file */\n    const char *filename = luaL_checkstring(L, 1);\n    opencheck(L, filename, \"r\");\n    lua_replace(L, 1);  /* put file at index 1 */\n    toclose = 1;  /* close it after iteration */\n  }\n  aux_lines(L, toclose);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM     200\n#endif\n\n\n/* auxiliary structure used by 'read_number' */\ntypedef struct {\n  FILE *f;  /* file being read */\n  int c;  /* current character (look ahead) */\n  int n;  /* number of elements in buffer 'buff' */\n  char buff[L_MAXLENNUM + 1];  /* +1 for ending '\\0' */\n} RN;\n\n\n/*\n** Add current char to buffer (if not out of space) and read next one\n*/\nstatic int nextc (RN *rn) {\n  if (rn->n >= L_MAXLENNUM) {  /* buffer overflow? */\n    rn->buff[0] = '\\0';  /* invalidate result */\n    return 0;  /* fail */\n  }\n  else {\n    rn->buff[rn->n++] = rn->c;  /* save current char */\n    rn->c = l_getc(rn->f);  /* read next one */\n    return 1;\n  }\n}\n\n\n/*\n** Accept current char if it is in 'set' (of size 2)\n*/\nstatic int test2 (RN *rn, const char *set) {\n  if (rn->c == set[0] || rn->c == set[1])\n    return nextc(rn);\n  else return 0;\n}\n\n\n/*\n** Read a sequence of (hex)digits\n*/\nstatic int readdigits (RN *rn, int hex) {\n  int count = 0;\n  while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn))\n    count++;\n  return count;\n}\n\n\n/*\n** Read a number: first reads a valid prefix of a numeral into a buffer.\n** Then it calls 'lua_stringtonumber' to check whether the format is\n** correct and to convert it to a Lua number\n*/\nstatic int read_number (lua_State *L, FILE *f) {\n  RN rn;\n  int count = 0;\n  int hex = 0;\n  char decp[2];\n  rn.f = f; rn.n = 0;\n  decp[0] = lua_getlocaledecpoint();  /* get decimal point from locale */\n  decp[1] = '.';  /* always accept a dot */\n  l_lockfile(rn.f);\n  do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */\n  test2(&rn, \"-+\");  /* optional signal */\n  if (test2(&rn, \"00\")) {\n    if (test2(&rn, \"xX\")) hex = 1;  /* numeral is hexadecimal */\n    else count = 1;  /* count initial '0' as a valid digit */\n  }\n  count += readdigits(&rn, hex);  /* integral part */\n  if (test2(&rn, decp))  /* decimal point? */\n    count += readdigits(&rn, hex);  /* fractional part */\n  if (count > 0 && test2(&rn, (hex ? \"pP\" : \"eE\"))) {  /* exponent mark? */\n    test2(&rn, \"-+\");  /* exponent signal */\n    readdigits(&rn, 0);  /* exponent digits */\n  }\n  ungetc(rn.c, rn.f);  /* unread look-ahead char */\n  l_unlockfile(rn.f);\n  rn.buff[rn.n] = '\\0';  /* finish string */\n  if (lua_stringtonumber(L, rn.buff))  /* is this a valid number? */\n    return 1;  /* ok */\n  else {  /* invalid format */\n   lua_pushnil(L);  /* \"result\" to be removed */\n   return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);  /* no-op when c == EOF */\n  lua_pushliteral(L, \"\");\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f, int chop) {\n  luaL_Buffer b;\n  int c = '\\0';\n  luaL_buffinit(L, &b);\n  while (c != EOF && c != '\\n') {  /* repeat until end of line */\n    char *buff = luaL_prepbuffer(&b);  /* preallocate buffer */\n    int i = 0;\n    l_lockfile(f);  /* no memory errors can happen inside the lock */\n    while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')\n      buff[i++] = c;\n    l_unlockfile(f);\n    luaL_addsize(&b, i);\n  }\n  if (!chop && c == '\\n')  /* want a newline and have one? */\n    luaL_addchar(&b, c);  /* add ending newline to result */\n  luaL_pushresult(&b);  /* close buffer */\n  /* return ok if read something (either a newline or something else) */\n  return (c == '\\n' || lua_rawlen(L, -1) > 0);\n}\n\n\nstatic void read_all (lua_State *L, FILE *f) {\n  size_t nr;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */\n    char *p = luaL_prepbuffer(&b);\n    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);\n    luaL_addsize(&b, nr);\n  } while (nr == LUAL_BUFFERSIZE);\n  luaL_pushresult(&b);  /* close buffer */\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t nr;  /* number of chars actually read */\n  char *p;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */\n  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */\n  luaL_addsize(&b, nr);\n  luaL_pushresult(&b);  /* close buffer */\n  return (nr > 0);  /* true iff read something */\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f, 1);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)luaL_checkinteger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = luaL_checkstring(L, n);\n        if (*p == '*') p++;  /* skip optional '*' (for compatibility) */\n        switch (*p) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f, 1);\n            break;\n          case 'L':  /* line with end-of-line */\n            success = read_line(L, f, 0);\n            break;\n          case 'a':  /* file */\n            read_all(L, f);  /* read entire file */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return luaL_fileresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));\n  int i;\n  int n = (int)lua_tointeger(L, lua_upvalueindex(2));\n  if (isclosed(p))  /* file is already closed? */\n    return luaL_error(L, \"file is already closed\");\n  lua_settop(L , 1);\n  luaL_checkstack(L, n, \"too many arguments\");\n  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */\n    lua_pushvalue(L, lua_upvalueindex(3 + i));\n  n = g_read(L, p->f, 2);  /* 'n' is number of results */\n  lua_assert(n > 0);  /* should return at least a nil */\n  if (lua_toboolean(L, -n))  /* read at least one value? */\n    return n;  /* return them */\n  else {  /* first result is nil: EOF or error */\n    if (n > 1) {  /* is there error information? */\n      /* 2nd result is error message */\n      return luaL_error(L, \"%s\", lua_tostring(L, -n + 1));\n    }\n    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - arg;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      int len = lua_isinteger(L, arg)\n                ? fprintf(f, LUA_INTEGER_FMT,\n                             (LUAI_UACINT)lua_tointeger(L, arg))\n                : fprintf(f, LUA_NUMBER_FMT,\n                             (LUAI_UACNUMBER)lua_tonumber(L, arg));\n      status = status && (len > 0);\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  if (status) return 1;  /* file handle already on stack top */\n  else return luaL_fileresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  FILE *f = tofile(L);\n  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */\n  return g_write(L, f, 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  lua_Integer p3 = luaL_optinteger(L, 3, 0);\n  l_seeknum offset = (l_seeknum)p3;\n  luaL_argcheck(L, (lua_Integer)offset == p3, 3,\n                  \"not an integer in proper range\");\n  op = l_fseek(f, offset, mode[op]);\n  if (op)\n    return luaL_fileresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, (lua_Integer)l_ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], (size_t)sz);\n  return luaL_fileresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\n/*\n** functions for 'io' library\n*/\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\n/*\n** methods for file handles\n*/\nstatic const luaL_Reg flib[] = {\n  {\"close\", io_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", f_gc},\n  {\"__tostring\", f_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */\n  lua_pop(L, 1);  /* pop new metatable */\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  p->closef = &io_noclose;  /* keep file opened */\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, const char *k,\n                           const char *fname) {\n  LStream *p = newprefile(L);\n  p->f = f;\n  p->closef = &io_noclose;\n  if (k != NULL) {\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */\n  }\n  lua_setfield(L, -2, fname);  /* add file to module */\n}\n\n\nLUAMOD_API int luaopen_io (lua_State *L) {\n  luaL_newlib(L, iolib);  /* new module */\n  createmeta(L);\n  /* create (and set) default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, NULL, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nstatic const char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"goto\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"//\", \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<<\", \">>\", \"::\", \"<eof>\",\n    \"<number>\", \"<integer>\", \"<name>\", \"<string>\"\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token);\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {\n    size_t newsize;\n    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)\n      lexerror(ls, \"lexical element too long\", 0);\n    newsize = luaZ_sizebuffer(b) * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[luaZ_bufflen(b)++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */\n  luaC_fix(L, obj2gco(e));  /* never collect this name */\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */\n    ts->extra = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {  /* single-byte symbols? */\n    lua_assert(token == cast_uchar(token));\n    return luaO_pushfstring(ls->L, \"'%c'\", token);\n  }\n  else {\n    const char *s = luaX_tokens[token - FIRST_RESERVED];\n    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */\n      return luaO_pushfstring(ls->L, \"'%s'\", s);\n    else  /* names, strings, and numerals */\n      return s;\n  }\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME: case TK_STRING:\n    case TK_FLT: case TK_INT:\n      save(ls, '\\0');\n      return luaO_pushfstring(ls->L, \"'%s'\", luaZ_buffer(ls->buff));\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token) {\n  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near %s\", msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nl_noret luaX_syntaxerror (LexState *ls, const char *msg) {\n  lexerror(ls, msg, ls->t.token);\n}\n\n\n/*\n** creates a new string and anchors it in scanner's table so that\n** it will not be collected until the end of the compilation\n** (by that time it should be anchored somewhere)\n*/\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TValue *o;  /* entry for 'str' */\n  TString *ts = luaS_newlstr(L, str, l);  /* create new string */\n  setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */\n  o = luaH_set(L, ls->h, L->top - 1);\n  if (ttisnil(o)) {  /* not in use yet? */\n    /* boolean value does not need GC barrier;\n       table has no metatable, so it does not need to invalidate cache */\n    setbvalue(o, 1);  /* t[string] = true */\n    luaC_checkGC(L);\n  }\n  else {  /* string already present */\n    ts = tsvalue(keyfromval(o));  /* re-use value previously stored */\n  }\n  L->top--;  /* remove string from stack */\n  return ts;\n}\n\n\n/*\n** increment line number and skips newline sequence (any of\n** \\n, \\r, \\n\\r, or \\r\\n)\n*/\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip '\\n' or '\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip '\\n\\r' or '\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    lexerror(ls, \"chunk has too many lines\", 0);\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,\n                    int firstchar) {\n  ls->t.token = 0;\n  ls->L = L;\n  ls->current = firstchar;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\nstatic int check_next1 (LexState *ls, int c) {\n  if (ls->current == c) {\n    next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check whether current char is in set 'set' (with two chars) and\n** saves it\n*/\nstatic int check_next2 (LexState *ls, const char *set) {\n  lua_assert(set[2] == '\\0');\n  if (ls->current == set[0] || ls->current == set[1]) {\n    save_and_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/* LUA_NUMBER */\n/*\n** this function is quite liberal in what it accepts, as 'luaO_str2num'\n** will reject ill-formed numerals.\n*/\nstatic int read_numeral (LexState *ls, SemInfo *seminfo) {\n  TValue obj;\n  const char *expo = \"Ee\";\n  int first = ls->current;\n  lua_assert(lisdigit(ls->current));\n  save_and_next(ls);\n  if (first == '0' && check_next2(ls, \"xX\"))  /* hexadecimal? */\n    expo = \"Pp\";\n  for (;;) {\n    if (check_next2(ls, expo))  /* exponent part? */\n      check_next2(ls, \"-+\");  /* optional exponent sign */\n    if (lisxdigit(ls->current))\n      save_and_next(ls);\n    else if (ls->current == '.')\n      save_and_next(ls);\n    else break;\n  }\n  save(ls, '\\0');\n  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */\n    lexerror(ls, \"malformed number\", TK_FLT);\n  if (ttisinteger(&obj)) {\n    seminfo->i = ivalue(&obj);\n    return TK_INT;\n  }\n  else {\n    lua_assert(ttisfloat(&obj));\n    seminfo->r = fltvalue(&obj);\n    return TK_FLT;\n  }\n}\n\n\n/*\n** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return\n** its number of '='s; otherwise, return a negative number (-1 iff there\n** are no '='s after initial bracket)\n*/\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int line = ls->linenumber;  /* initial line (for error message) */\n  save_and_next(ls);  /* skip 2nd '[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ: {  /* error */\n        const char *what = (seminfo ? \"string\" : \"comment\");\n        const char *msg = luaO_pushfstring(ls->L,\n                     \"unfinished long %s (starting at line %d)\", what, line);\n        lexerror(ls, msg, TK_EOS);\n        break;  /* to avoid warnings */\n      }\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd ']' */\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n': case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void esccheck (LexState *ls, int c, const char *msg) {\n  if (!c) {\n    if (ls->current != EOZ)\n      save_and_next(ls);  /* add current to buffer for error message */\n    lexerror(ls, msg, TK_STRING);\n  }\n}\n\n\nstatic int gethexa (LexState *ls) {\n  save_and_next(ls);\n  esccheck (ls, lisxdigit(ls->current), \"hexadecimal digit expected\");\n  return luaO_hexavalue(ls->current);\n}\n\n\nstatic int readhexaesc (LexState *ls) {\n  int r = gethexa(ls);\n  r = (r << 4) + gethexa(ls);\n  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic unsigned long readutf8esc (LexState *ls) {\n  unsigned long r;\n  int i = 4;  /* chars to be removed: '\\', 'u', '{', and first digit */\n  save_and_next(ls);  /* skip 'u' */\n  esccheck(ls, ls->current == '{', \"missing '{'\");\n  r = gethexa(ls);  /* must have at least one digit */\n  while ((save_and_next(ls), lisxdigit(ls->current))) {\n    i++;\n    r = (r << 4) + luaO_hexavalue(ls->current);\n    esccheck(ls, r <= 0x10FFFF, \"UTF-8 value too large\");\n  }\n  esccheck(ls, ls->current == '}', \"missing '}'\");\n  next(ls);  /* skip '}' */\n  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic void utf8esc (LexState *ls) {\n  char buff[UTF8BUFFSZ];\n  int n = luaO_utf8esc(buff, readutf8esc(ls));\n  for (; n > 0; n--)  /* add 'buff' to string */\n    save(ls, buff[UTF8BUFFSZ - n]);\n}\n\n\nstatic int readdecesc (LexState *ls) {\n  int i;\n  int r = 0;  /* result accumulator */\n  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */\n    r = 10*r + ls->current - '0';\n    save_and_next(ls);\n  }\n  esccheck(ls, r <= UCHAR_MAX, \"decimal escape too large\");\n  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */\n  return r;\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);  /* keep delimiter (for error messages) */\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        lexerror(ls, \"unfinished string\", TK_EOS);\n        break;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        lexerror(ls, \"unfinished string\", TK_STRING);\n        break;  /* to avoid warnings */\n      case '\\\\': {  /* escape sequences */\n        int c;  /* final character to be saved */\n        save_and_next(ls);  /* keep '\\\\' for error messages */\n        switch (ls->current) {\n          case 'a': c = '\\a'; goto read_save;\n          case 'b': c = '\\b'; goto read_save;\n          case 'f': c = '\\f'; goto read_save;\n          case 'n': c = '\\n'; goto read_save;\n          case 'r': c = '\\r'; goto read_save;\n          case 't': c = '\\t'; goto read_save;\n          case 'v': c = '\\v'; goto read_save;\n          case 'x': c = readhexaesc(ls); goto read_save;\n          case 'u': utf8esc(ls);  goto no_save;\n          case '\\n': case '\\r':\n            inclinenumber(ls); c = '\\n'; goto only_save;\n          case '\\\\': case '\\\"': case '\\'':\n            c = ls->current; goto read_save;\n          case EOZ: goto no_save;  /* will raise an error next loop */\n          case 'z': {  /* zap following span of spaces */\n            luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n            next(ls);  /* skip the 'z' */\n            while (lisspace(ls->current)) {\n              if (currIsNewline(ls)) inclinenumber(ls);\n              else next(ls);\n            }\n            goto no_save;\n          }\n          default: {\n            esccheck(ls, lisdigit(ls->current), \"invalid escape sequence\");\n            c = readdecesc(ls);  /* digital escape '\\ddd' */\n            goto only_save;\n          }\n        }\n       read_save:\n         next(ls);\n         /* go through */\n       only_save:\n         luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n         save(ls, c);\n         /* go through */\n       no_save: break;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n': case '\\r': {  /* line breaks */\n        inclinenumber(ls);\n        break;\n      }\n      case ' ': case '\\f': case '\\t': case '\\v': {  /* spaces */\n        next(ls);\n        break;\n      }\n      case '-': {  /* '-' or '--' (comment) */\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {  /* long comment? */\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* skip long comment */\n            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */\n            break;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);  /* skip until end of line (or end of file) */\n        break;\n      }\n      case '[': {  /* long string or simply '[' */\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep != -1)  /* '[=...' missing second bracket */\n          lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n        return '[';\n      }\n      case '=': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_EQ;\n        else return '=';\n      }\n      case '<': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_LE;\n        else if (check_next1(ls, '<')) return TK_SHL;\n        else return '<';\n      }\n      case '>': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_GE;\n        else if (check_next1(ls, '>')) return TK_SHR;\n        else return '>';\n      }\n      case '/': {\n        next(ls);\n        if (check_next1(ls, '/')) return TK_IDIV;\n        else return '/';\n      }\n      case '~': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_NE;\n        else return '~';\n      }\n      case ':': {\n        next(ls);\n        if (check_next1(ls, ':')) return TK_DBCOLON;\n        else return ':';\n      }\n      case '\"': case '\\'': {  /* short literal strings */\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {  /* '.', '..', '...', or number */\n        save_and_next(ls);\n        if (check_next1(ls, '.')) {\n          if (check_next1(ls, '.'))\n            return TK_DOTS;   /* '...' */\n          else return TK_CONCAT;   /* '..' */\n        }\n        else if (!lisdigit(ls->current)) return '.';\n        else return read_numeral(ls, seminfo);\n      }\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9': {\n        return read_numeral(ls, seminfo);\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (lislalpha(ls->current)) {  /* identifier or reserved word? */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (lislalnum(ls->current));\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          seminfo->ts = ts;\n          if (isreserved(ts))  /* reserved word? */\n            return ts->extra - 1 + FIRST_RESERVED;\n          else {\n            return TK_NAME;\n          }\n        }\n        else {  /* single-char tokens (+ - / ...) */\n          int c = ls->current;\n          next(ls);\n          return c;\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nint luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n  return ls->lookahead.token;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n\n#if !defined(LUA_ENV)\n#define LUA_ENV\t\t\"_ENV\"\n#endif\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,\n  TK_SHL, TK_SHR,\n  TK_DBCOLON, TK_EOS,\n  TK_FLT, TK_INT, TK_NAME, TK_STRING\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\ntypedef union {\n  lua_Number r;\n  lua_Integer i;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\n/* state of the lexer plus state of the parser when shared by all\n   functions */\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token 'consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* current function (parser) */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  Table *h;  /* to avoid collection/reuse strings */\n  struct Dyndata *dyd;  /* dynamic structures used by the parser */\n  TString *source;  /* current source name */\n  TString *envn;  /* environment variable name */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source, int firstchar);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC int luaX_lookahead (LexState *ls);\nLUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $\n** Limits, basic types, and some other 'installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n/*\n** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count\n** the total memory used by Lua (in bytes). Usually, 'size_t' and\n** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.\n*/\n#if defined(LUAI_MEM)\t\t/* { external definitions? */\ntypedef LUAI_UMEM lu_mem;\ntypedef LUAI_MEM l_mem;\n#elif LUAI_BITSINT >= 32\t/* }{ */\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\n#else  /* 16-bit ints */\t/* }{ */\ntypedef unsigned long lu_mem;\ntypedef long l_mem;\n#endif\t\t\t\t/* } */\n\n\n/* chars used as small naturals (so that 'char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n/* maximum size visible for Lua (must be representable in a lua_Integer */\n#define MAX_SIZE\t(sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \\\n                          : (size_t)(LUA_MAXINTEGER))\n\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0))\n\n#define MAX_LMEM\t((l_mem)(MAX_LUMEM >> 1))\n\n\n#define MAX_INT\t\tINT_MAX  /* maximum value of an int */\n\n\n/*\n** conversion of pointer to unsigned integer:\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define point2uint(p)\t((unsigned int)((size_t)(p) & UINT_MAX))\n\n\n\n/* type to ensure maximum alignment */\n#if defined(LUAI_USER_ALIGNMENT_T)\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n#else\ntypedef union {\n  lua_Number n;\n  double u;\n  void *s;\n  lua_Integer i;\n  long l;\n} L_Umaxalign;\n#endif\n\n\n\n/* types of 'usual argument conversions' for lua_Number and lua_Integer */\ntypedef LUAI_UACNUMBER l_uacNumber;\ntypedef LUAI_UACINT l_uacInt;\n\n\n/* internal assertions for in-house debugging */\n#if defined(lua_assert)\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n/* to avoid problems with conditions too long */\n#define lua_longassert(c)\t((c) ? (void)0 : lua_assert(0))\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define lua_longassert(c)\t((void)0)\n#endif\n\n/*\n** assertion for checking API calls\n*/\n#if !defined(luai_apicheck)\n#define luai_apicheck(l,e)\tlua_assert(e)\n#endif\n\n#define api_check(l,e,msg)\tluai_apicheck(l,(e) && msg)\n\n\n/* macro to avoid warnings about unused variables */\n#if !defined(UNUSED)\n#define UNUSED(x)\t((void)(x))\n#endif\n\n\n/* type casts (a macro highlights casts in the code) */\n#define cast(t, exp)\t((t)(exp))\n\n#define cast_void(i)\tcast(void, (i))\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n#define cast_uchar(i)\tcast(unsigned char, (i))\n\n\n/* cast a signed lua_Integer to lua_Unsigned */\n#if !defined(l_castS2U)\n#define l_castS2U(i)\t((lua_Unsigned)(i))\n#endif\n\n/*\n** cast a lua_Unsigned to a signed lua_Integer; this cast is\n** not strict ISO C, but two-complement architectures should\n** work fine.\n*/\n#if !defined(l_castU2S)\n#define l_castU2S(i)\t((lua_Integer)(i))\n#endif\n\n\n/*\n** non-return type\n*/\n#if defined(__GNUC__)\n#define l_noret\t\tvoid __attribute__((noreturn))\n#elif defined(_MSC_VER) && _MSC_VER >= 1200\n#define l_noret\t\tvoid __declspec(noreturn)\n#else\n#define l_noret\t\tvoid\n#endif\n\n\n\n/*\n** maximum depth for nested C calls and syntactical nested non-terminals\n** in a program. (Value must fit in an unsigned short int.)\n*/\n#if !defined(LUAI_MAXCCALLS)\n#define LUAI_MAXCCALLS\t\t200\n#endif\n\n\n\n/*\n** type for virtual-machine instructions;\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\n#if LUAI_BITSINT >= 32\ntypedef unsigned int Instruction;\n#else\ntypedef unsigned long Instruction;\n#endif\n\n\n\n/*\n** Maximum length for short strings, that is, strings that are\n** internalized. (Cannot be smaller than reserved words or tags for\n** metamethods, as these strings must be internalized;\n** #(\"function\") = 8, #(\"__newindex\") = 10.)\n*/\n#if !defined(LUAI_MAXSHORTLEN)\n#define LUAI_MAXSHORTLEN\t40\n#endif\n\n\n/*\n** Initial size for the string table (must be power of 2).\n** The Lua core alone registers ~50 strings (reserved words +\n** metaevent keys + a few others). Libraries would typically add\n** a few dozens more.\n*/\n#if !defined(MINSTRTABSIZE)\n#define MINSTRTABSIZE\t128\n#endif\n\n\n/*\n** Size of cache for strings in the API. 'N' is the number of\n** sets (better be a prime) and \"M\" is the size of each set (M == 1\n** makes a direct cache.)\n*/\n#if !defined(STRCACHE_N)\n#define STRCACHE_N\t\t53\n#define STRCACHE_M\t\t2\n#endif\n\n\n/* minimum size for string buffer */\n#if !defined(LUA_MINBUFFER)\n#define LUA_MINBUFFER\t32\n#endif\n\n\n/*\n** macros that are executed whenever program enters the Lua core\n** ('lua_lock') and leaves the core ('lua_unlock')\n*/\n#if !defined(lua_lock)\n#define lua_lock(L)\t((void) 0)\n#define lua_unlock(L)\t((void) 0)\n#endif\n\n/*\n** macro executed during Lua functions at points where the\n** function can yield.\n*/\n#if !defined(luai_threadyield)\n#define luai_threadyield(L)\t{lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** these macros allow user-specific actions on threads when you defined\n** LUAI_EXTRASPACE and need to do something extra when a thread is\n** created/deleted/resumed/yielded.\n*/\n#if !defined(luai_userstateopen)\n#define luai_userstateopen(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstateclose)\n#define luai_userstateclose(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstatethread)\n#define luai_userstatethread(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstatefree)\n#define luai_userstatefree(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstateresume)\n#define luai_userstateresume(L,n)\t((void)L)\n#endif\n\n#if !defined(luai_userstateyield)\n#define luai_userstateyield(L,n)\t((void)L)\n#endif\n\n\n\n/*\n** The luai_num* macros define the primitive operations over numbers.\n*/\n\n/* floor division (defined as 'floor(a/b)') */\n#if !defined(luai_numidiv)\n#define luai_numidiv(L,a,b)     ((void)L, l_floor(luai_numdiv(L,a,b)))\n#endif\n\n/* float division */\n#if !defined(luai_numdiv)\n#define luai_numdiv(L,a,b)      ((a)/(b))\n#endif\n\n/*\n** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when\n** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of\n** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)\n** ~= floor(a/b)'. That happens when the division has a non-integer\n** negative result, which is equivalent to the test below.\n*/\n#if !defined(luai_nummod)\n#define luai_nummod(L,a,b,m)  \\\n  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }\n#endif\n\n/* exponentiation */\n#if !defined(luai_numpow)\n#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))\n#endif\n\n/* the others are quite standard operations */\n#if !defined(luai_numadd)\n#define luai_numadd(L,a,b)      ((a)+(b))\n#define luai_numsub(L,a,b)      ((a)-(b))\n#define luai_nummul(L,a,b)      ((a)*(b))\n#define luai_numunm(L,a)        (-(a))\n#define luai_numeq(a,b)         ((a)==(b))\n#define luai_numlt(a,b)         ((a)<(b))\n#define luai_numle(a,b)         ((a)<=(b))\n#define luai_numisnan(a)        (!luai_numeq((a), (a)))\n#endif\n\n\n\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/\n#if !defined(HARDSTACKTESTS)\n#define condmovestack(L,pre,pos)\t((void)0)\n#else\n/* realloc stack keeping its size */\n#define condmovestack(L,pre,pos)  \\\n\t{ int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; }\n#endif\n\n#if !defined(HARDMEMTESTS)\n#define condchangemem(L,pre,pos)\t((void)0)\n#else\n#define condchangemem(L,pre,pos)  \\\n\t{ if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.119 2016/12/22 13:08:50 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI\t(l_mathop(3.141592653589793238462643383279502884))\n\n\n#if !defined(l_rand)\t\t/* { */\n#if defined(LUA_USE_POSIX)\n#define l_rand()\trandom()\n#define l_srand(x)\tsrandom(x)\n#define L_RANDMAX\t2147483647\t/* (2^31 - 1), following POSIX */\n#else\n#define l_rand()\trand()\n#define l_srand(x)\tsrand(x)\n#define L_RANDMAX\tRAND_MAX\n#endif\n#endif\t\t\t\t/* } */\n\n\nstatic int math_abs (lua_State *L) {\n  if (lua_isinteger(L, 1)) {\n    lua_Integer n = lua_tointeger(L, 1);\n    if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);\n    lua_pushinteger(L, n);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_Number y = luaL_checknumber(L, 1);\n  lua_Number x = luaL_optnumber(L, 2, 1);\n  lua_pushnumber(L, l_mathop(atan2)(y, x));\n  return 1;\n}\n\n\nstatic int math_toint (lua_State *L) {\n  int valid;\n  lua_Integer n = lua_tointegerx(L, 1, &valid);\n  if (valid)\n    lua_pushinteger(L, n);\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);  /* value is not convertible to integer */\n  }\n  return 1;\n}\n\n\nstatic void pushnumint (lua_State *L, lua_Number d) {\n  lua_Integer n;\n  if (lua_numbertointeger(d, &n))  /* does 'd' fit in an integer? */\n    lua_pushinteger(L, n);  /* result is integer */\n  else\n    lua_pushnumber(L, d);  /* result is float */\n}\n\n\nstatic int math_floor (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own floor */\n  else {\n    lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_ceil (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own ceil */\n  else {\n    lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_fmod (lua_State *L) {\n  if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) {\n    lua_Integer d = lua_tointeger(L, 2);\n    if ((lua_Unsigned)d + 1u <= 1u) {  /* special cases: -1 or 0 */\n      luaL_argcheck(L, d != 0, 2, \"zero\");\n      lua_pushinteger(L, 0);  /* avoid overflow with 0x80000... / -1 */\n    }\n    else\n      lua_pushinteger(L, lua_tointeger(L, 1) % d);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),\n                                     luaL_checknumber(L, 2)));\n  return 1;\n}\n\n\n/*\n** next function does not use 'modf', avoiding problems with 'double*'\n** (which is not compatible with 'float*') when lua_Number is not\n** 'double'.\n*/\nstatic int math_modf (lua_State *L) {\n  if (lua_isinteger(L ,1)) {\n    lua_settop(L, 1);  /* number is its own integer part */\n    lua_pushnumber(L, 0);  /* no fractional part */\n  }\n  else {\n    lua_Number n = luaL_checknumber(L, 1);\n    /* integer part (rounds toward zero) */\n    lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);\n    pushnumint(L, ip);\n    /* fractional part (test needed for inf/-inf) */\n    lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));\n  }\n  return 2;\n}\n\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n\nstatic int math_ult (lua_State *L) {\n  lua_Integer a = luaL_checkinteger(L, 1);\n  lua_Integer b = luaL_checkinteger(L, 2);\n  lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b);\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number res;\n  if (lua_isnoneornil(L, 2))\n    res = l_mathop(log)(x);\n  else {\n    lua_Number base = luaL_checknumber(L, 2);\n    if (base == l_mathop(10.0))\n      res = l_mathop(log10)(x);\n    else\n      res = l_mathop(log)(x)/l_mathop(log)(base);\n  }\n  lua_pushnumber(L, res);\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));\n  return 1;\n}\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imin = 1;  /* index of current minimum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, i, imin, LUA_OPLT))\n      imin = i;\n  }\n  lua_pushvalue(L, imin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imax = 1;  /* index of current maximum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, imax, i, LUA_OPLT))\n      imax = i;\n  }\n  lua_pushvalue(L, imax);\n  return 1;\n}\n\n/*\n** This function uses 'double' (instead of 'lua_Number') to ensure that\n** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0'\n** will keep full precision (ensuring that 'r' is always less than 1.0.)\n*/\nstatic int math_random (lua_State *L) {\n  lua_Integer low, up;\n  double r = (double)l_rand() * (1.0 / ((double)L_RANDMAX + 1.0));\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, (lua_Number)r);  /* Number between 0 and 1 */\n      return 1;\n    }\n    case 1: {  /* only upper limit */\n      low = 1;\n      up = luaL_checkinteger(L, 1);\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      low = luaL_checkinteger(L, 1);\n      up = luaL_checkinteger(L, 2);\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  /* random integer in the interval [low, up] */\n  luaL_argcheck(L, low <= up, 1, \"interval is empty\");\n  luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,\n                   \"interval too large\");\n  r *= (double)(up - low) + 1.0;\n  lua_pushinteger(L, (lua_Integer)r + low);\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));\n  (void)l_rand(); /* discard first value to avoid undesirable correlations */\n  return 0;\n}\n\n\nstatic int math_type (lua_State *L) {\n  if (lua_type(L, 1) == LUA_TNUMBER) {\n      if (lua_isinteger(L, 1))\n        lua_pushliteral(L, \"integer\");\n      else\n        lua_pushliteral(L, \"float\");\n  }\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);\n  }\n  return 1;\n}\n\n\n/*\n** {==================================================================\n** Deprecated functions (for compatibility only)\n** ===================================================================\n*/\n#if defined(LUA_COMPAT_MATHLIB)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number y = luaL_checknumber(L, 2);\n  lua_pushnumber(L, l_mathop(pow)(x, y));\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  int ep = (int)luaL_checkinteger(L, 2);\n  lua_pushnumber(L, l_mathop(ldexp)(x, ep));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n#endif\n/* }================================================================== */\n\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"tointeger\", math_toint},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"ult\",   math_ult},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tan\",   math_tan},\n  {\"type\", math_type},\n#if defined(LUA_COMPAT_MATHLIB)\n  {\"atan2\", math_atan},\n  {\"cosh\",   math_cosh},\n  {\"sinh\",   math_sinh},\n  {\"tanh\",   math_tanh},\n  {\"pow\",   math_pow},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n#endif\n  /* placeholders */\n  {\"pi\", NULL},\n  {\"huge\", NULL},\n  {\"maxinteger\", NULL},\n  {\"mininteger\", NULL},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUAMOD_API int luaopen_math (lua_State *L) {\n  luaL_newlib(L, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, (lua_Number)HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n  lua_pushinteger(L, LUA_MAXINTEGER);\n  lua_setfield(L, -2, \"maxinteger\");\n  lua_pushinteger(L, LUA_MININTEGER);\n  lua_setfield(L, -2, \"mininteger\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** ('osize' is the old size, 'nsize' is the new size)\n**\n** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no\n** matter 'x').\n**\n** * frealloc(ud, p, x, 0) frees the block 'p'\n** (in this specific case, frealloc must return NULL);\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ISO C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *what) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, \"too many %s (limit is %d)\", what, limit);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nl_noret luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  void *newblock;\n  global_State *g = G(L);\n  size_t realosize = (block) ? osize : 0;\n  lua_assert((realosize == 0) == (block == NULL));\n#if defined(HARDMEMTESTS)\n  if (nsize > realosize && g->gcrunning)\n    luaC_fullgc(L, 1);  /* force a GC whenever possible */\n#endif\n  newblock = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (newblock == NULL && nsize > 0) {\n    lua_assert(nsize > realosize);  /* cannot fail when shrinking a block */\n    if (g->version) {  /* is state fully built? */\n      luaC_fullgc(L, 1);  /* try to free some memory... */\n      newblock = (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */\n    }\n    if (newblock == NULL)\n      luaD_throw(L, LUA_ERRMEM);\n  }\n  lua_assert((nsize == 0) == (newblock == NULL));\n  g->GCdebt = (g->GCdebt + nsize) - realosize;\n  return newblock;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** This macro reallocs a vector 'b' from 'on' to 'n' elements, where\n** each element has size 'e'. In case of arithmetic overflow of the\n** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because\n** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e).\n**\n** (The macro is somewhat complex to avoid warnings:  The 'sizeof'\n** comparison avoids a runtime comparison when overflow cannot occur.\n** The compiler should be able to optimize the real test by itself, but\n** when it does it, it may give a warning about \"comparison is always\n** false due to limited range of data type\"; the +1 tricks the compiler,\n** avoiding this warning but also this optimization.)\n*/\n#define luaM_reallocv(L,b,on,n,e) \\\n  (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \\\n      ? luaM_toobig(L) : cast_void(0)) , \\\n   luaM_realloc_(L, (b), (on)*(e), (n)*(e)))\n\n/*\n** Arrays of chars do not need any test\n*/\n#define luaM_reallocvchar(L,b,on,n)  \\\n    cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n)   luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0)\n\n#define luaM_malloc(L,s)\tluaM_realloc_(L, NULL, 0, (s))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_newobject(L,tag,s)\tluaM_realloc_(L, NULL, tag, (s))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\nLUAI_FUNC l_noret luaM_toobig (lua_State *L);\n\n/* not to be called directly */\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *what);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** unique key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const int CLIBS = 0;\n\n#define LIB_FAIL\t\"open\"\n\n\n#define setprogdir(L)           ((void)0)\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\n\n#undef setprogdir\n\n\n/*\n** Replace in the path (on the top of the stack) any occurrence\n** of LUA_EXEC_DIR with the executable's path.\n*/\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);  /* get exec. name */\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';  /* cut name on the last '\\\\' to get the path */\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** {==================================================================\n** Set Paths\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR    \"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR   \"LUA_CPATH\"\n#endif\n\n\n#define AUXMARK         \"\\1\"\t/* auxiliary mark */\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\n/*\n** Set a path\n*/\nstatic void setpath (lua_State *L, const char *fieldname,\n                                   const char *envname,\n                                   const char *dft) {\n  const char *nver = lua_pushfstring(L, \"%s%s\", envname, LUA_VERSUFFIX);\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(nver);  /* use versioned name */\n  if (path == NULL)  /* no environment variable? */\n    path = getenv(envname);  /* try unversioned name */\n#endif\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, dft);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,\n                              LUA_PATH_SEP AUXMARK LUA_PATH_SEP);\n    luaL_gsub(L, path, AUXMARK, dft);\n    lua_remove(L, -2); /* remove result from 1st 'gsub' */\n  }\n  setprogdir(L);\n  lua_setfield(L, -3, fieldname);  /* package[fieldname] = path value */\n  lua_pop(L, 1);  /* pop versioned variable name */\n}\n\n/* }================================================================== */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATH_SEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATH_SEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n                                     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file '%s'\", filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"\\n\\tno module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else\n      lua_pop(L, 2);  /* remove both returns */\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, 2, name);  /* LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_pushstring(L, name);  /* pass name as argument to module loader */\n  lua_insert(L, -2);  /* name is 1st argument (before search data) */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* LOADED[name] = returned value */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\n/*\n** changes the environment variable of calling function\n*/\nstatic void set_env (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, \"'module' not called from a Lua function\");\n  lua_pushvalue(L, -2);  /* copy new environment table to top */\n  lua_setupvalue(L, -2, 1);\n  lua_pop(L, 1);  /* remove function */\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    if (lua_isfunction(L, i)) {  /* avoid 'calling' extra info. */\n      lua_pushvalue(L, i);  /* get option (a function) */\n      lua_pushvalue(L, -2);  /* module */\n      lua_call(L, 1, 0);\n    }\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = lua_gettop(L);  /* last parameter */\n  luaL_pushmodule(L, modname, 1);  /* get/create module table */\n  /* check whether table already has a _NAME field */\n  if (lua_getfield(L, -1, \"_NAME\") != LUA_TNIL)\n    lua_pop(L, 1);  /* table is an initialized module */\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  set_env(L);\n  dooptions(L, lastarg);\n  return 1;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushglobaltable(L);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n#endif\n/* }====================================================== */\n\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n#if defined(LUA_COMPAT_MODULE)\n  {\"seeall\", ll_seeall},\n#endif\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n#if defined(LUA_COMPAT_MODULE)\n  {\"module\", ll_module},\n#endif\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if defined(LUA_COMPAT_LOADERS)\n  lua_pushvalue(L, -1);  /* make a copy of 'searchers' table */\n  lua_setfield(L, -3, \"loaders\");  /* put it in field 'loaders' */\n#endif\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  lua_newtable(L);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n  lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set paths */\n  setpath(L, \"path\", LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  setpath(L, \"cpath\", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.113 2016/12/22 13:08:50 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nLUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* exponent */\n  if (x < 8) return x;\n  while (x >= (8 << 4)) {  /* coarse steps */\n    x = (x + 0xf) >> 4;  /* x = ceil(x / 16) */\n    e += 4;\n  }\n  while (x >= (8 << 1)) {  /* fine steps */\n    x = (x + 1) >> 1;  /* x = ceil(x / 2) */\n    e++;\n  }\n  return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);\n}\n\n\n/*\n** Computes ceil(log2(x))\n*/\nint luaO_ceillog2 (unsigned int x) {\n  static const lu_byte log_2[256] = {  /* log_2[i] = ceil(log2(i - 1)) */\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = 0;\n  x--;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n}\n\n\nstatic lua_Integer intarith (lua_State *L, int op, lua_Integer v1,\n                                                   lua_Integer v2) {\n  switch (op) {\n    case LUA_OPADD: return intop(+, v1, v2);\n    case LUA_OPSUB:return intop(-, v1, v2);\n    case LUA_OPMUL:return intop(*, v1, v2);\n    case LUA_OPMOD: return luaV_mod(L, v1, v2);\n    case LUA_OPIDIV: return luaV_div(L, v1, v2);\n    case LUA_OPBAND: return intop(&, v1, v2);\n    case LUA_OPBOR: return intop(|, v1, v2);\n    case LUA_OPBXOR: return intop(^, v1, v2);\n    case LUA_OPSHL: return luaV_shiftl(v1, v2);\n    case LUA_OPSHR: return luaV_shiftl(v1, -v2);\n    case LUA_OPUNM: return intop(-, 0, v1);\n    case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lua_Number numarith (lua_State *L, int op, lua_Number v1,\n                                                  lua_Number v2) {\n  switch (op) {\n    case LUA_OPADD: return luai_numadd(L, v1, v2);\n    case LUA_OPSUB: return luai_numsub(L, v1, v2);\n    case LUA_OPMUL: return luai_nummul(L, v1, v2);\n    case LUA_OPDIV: return luai_numdiv(L, v1, v2);\n    case LUA_OPPOW: return luai_numpow(L, v1, v2);\n    case LUA_OPIDIV: return luai_numidiv(L, v1, v2);\n    case LUA_OPUNM: return luai_numunm(L, v1);\n    case LUA_OPMOD: {\n      lua_Number m;\n      luai_nummod(L, v1, v2, m);\n      return m;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                 TValue *res) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR:\n    case LUA_OPBNOT: {  /* operate only on integers */\n      lua_Integer i1; lua_Integer i2;\n      if (tointeger(p1, &i1) && tointeger(p2, &i2)) {\n        setivalue(res, intarith(L, op, i1, i2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    case LUA_OPDIV: case LUA_OPPOW: {  /* operate only on floats */\n      lua_Number n1; lua_Number n2;\n      if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    default: {  /* other operations */\n      lua_Number n1; lua_Number n2;\n      if (ttisinteger(p1) && ttisinteger(p2)) {\n        setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));\n        return;\n      }\n      else if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n  }\n  /* could not perform raw operation; try metamethod */\n  lua_assert(L != NULL);  /* should not fail when folding (compile time) */\n  luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));\n}\n\n\nint luaO_hexavalue (int c) {\n  if (lisdigit(c)) return c - '0';\n  else return (ltolower(c) - 'a') + 10;\n}\n\n\nstatic int isneg (const char **s) {\n  if (**s == '-') { (*s)++; return 1; }\n  else if (**s == '+') (*s)++;\n  return 0;\n}\n\n\n\n/*\n** {==================================================================\n** Lua's implementation for 'lua_strx2number'\n** ===================================================================\n*/\n\n#if !defined(lua_strx2number)\n\n/* maximum number of significant digits to read (to avoid overflows\n   even with single floats) */\n#define MAXSIGDIG\t30\n\n/*\n** convert an hexadecimal numeric string to a number, following\n** C99 specification for 'strtod'\n*/\nstatic lua_Number lua_strx2number (const char *s, char **endptr) {\n  int dot = lua_getlocaledecpoint();\n  lua_Number r = 0.0;  /* result (accumulator) */\n  int sigdig = 0;  /* number of significant digits */\n  int nosigdig = 0;  /* number of non-significant digits */\n  int e = 0;  /* exponent correction */\n  int neg;  /* 1 if number is negative */\n  int hasdot = 0;  /* true after seen a dot */\n  *endptr = cast(char *, s);  /* nothing is valid yet */\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);  /* check signal */\n  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */\n    return 0.0;  /* invalid format (no '0x') */\n  for (s += 2; ; s++) {  /* skip '0x' and read numeral */\n    if (*s == dot) {\n      if (hasdot) break;  /* second dot? stop loop */\n      else hasdot = 1;\n    }\n    else if (lisxdigit(cast_uchar(*s))) {\n      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */\n        nosigdig++;\n      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */\n          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);\n      else e++; /* too many digits; ignore, but still count for exponent */\n      if (hasdot) e--;  /* decimal digit? correct exponent */\n    }\n    else break;  /* neither a dot nor a digit */\n  }\n  if (nosigdig + sigdig == 0)  /* no digits? */\n    return 0.0;  /* invalid format */\n  *endptr = cast(char *, s);  /* valid up to here */\n  e *= 4;  /* each digit multiplies/divides value by 2^4 */\n  if (*s == 'p' || *s == 'P') {  /* exponent part? */\n    int exp1 = 0;  /* exponent value */\n    int neg1;  /* exponent signal */\n    s++;  /* skip 'p' */\n    neg1 = isneg(&s);  /* signal */\n    if (!lisdigit(cast_uchar(*s)))\n      return 0.0;  /* invalid; must have at least one digit */\n    while (lisdigit(cast_uchar(*s)))  /* read exponent */\n      exp1 = exp1 * 10 + *(s++) - '0';\n    if (neg1) exp1 = -exp1;\n    e += exp1;\n    *endptr = cast(char *, s);  /* valid up to here */\n  }\n  if (neg) r = -r;\n  return l_mathop(ldexp)(r, e);\n}\n\n#endif\n/* }====================================================== */\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM\t200\n#endif\n\nstatic const char *l_str2dloc (const char *s, lua_Number *result, int mode) {\n  char *endptr;\n  *result = (mode == 'x') ? lua_strx2number(s, &endptr)  /* try to convert */\n                          : lua_str2number(s, &endptr);\n  if (endptr == s) return NULL;  /* nothing recognized? */\n  while (lisspace(cast_uchar(*endptr))) endptr++;  /* skip trailing spaces */\n  return (*endptr == '\\0') ? endptr : NULL;  /* OK if no trailing characters */\n}\n\n\n/*\n** Convert string 's' to a Lua number (put in 'result'). Return NULL\n** on fail or the address of the ending '\\0' on success.\n** 'pmode' points to (and 'mode' contains) special things in the string:\n** - 'x'/'X' means an hexadecimal numeral\n** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)\n** - '.' just optimizes the search for the common case (nothing special)\n** This function accepts both the current locale or a dot as the radix\n** mark. If the convertion fails, it may mean number has a dot but\n** locale accepts something else. In that case, the code copies 's'\n** to a buffer (because 's' is read-only), changes the dot to the\n** current locale radix mark, and tries to convert again.\n*/\nstatic const char *l_str2d (const char *s, lua_Number *result) {\n  const char *endptr;\n  const char *pmode = strpbrk(s, \".xXnN\");\n  int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;\n  if (mode == 'n')  /* reject 'inf' and 'nan' */\n    return NULL;\n  endptr = l_str2dloc(s, result, mode);  /* try to convert */\n  if (endptr == NULL) {  /* failed? may be a different locale */\n    char buff[L_MAXLENNUM + 1];\n    const char *pdot = strchr(s, '.');\n    if (strlen(s) > L_MAXLENNUM || pdot == NULL)\n      return NULL;  /* string too long or no dot; fail */\n    strcpy(buff, s);  /* copy string to buffer */\n    buff[pdot - s] = lua_getlocaledecpoint();  /* correct decimal point */\n    endptr = l_str2dloc(buff, result, mode);  /* try again */\n    if (endptr != NULL)\n      endptr = s + (endptr - buff);  /* make relative to 's' */\n  }\n  return endptr;\n}\n\n\n#define MAXBY10\t\tcast(lua_Unsigned, LUA_MAXINTEGER / 10)\n#define MAXLASTD\tcast_int(LUA_MAXINTEGER % 10)\n\nstatic const char *l_str2int (const char *s, lua_Integer *result) {\n  lua_Unsigned a = 0;\n  int empty = 1;\n  int neg;\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);\n  if (s[0] == '0' &&\n      (s[1] == 'x' || s[1] == 'X')) {  /* hex? */\n    s += 2;  /* skip '0x' */\n    for (; lisxdigit(cast_uchar(*s)); s++) {\n      a = a * 16 + luaO_hexavalue(*s);\n      empty = 0;\n    }\n  }\n  else {  /* decimal */\n    for (; lisdigit(cast_uchar(*s)); s++) {\n      int d = *s - '0';\n      if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg))  /* overflow? */\n        return NULL;  /* do not accept it (as integer) */\n      a = a * 10 + d;\n      empty = 0;\n    }\n  }\n  while (lisspace(cast_uchar(*s))) s++;  /* skip trailing spaces */\n  if (empty || *s != '\\0') return NULL;  /* something wrong in the numeral */\n  else {\n    *result = l_castU2S((neg) ? 0u - a : a);\n    return s;\n  }\n}\n\n\nsize_t luaO_str2num (const char *s, TValue *o) {\n  lua_Integer i; lua_Number n;\n  const char *e;\n  if ((e = l_str2int(s, &i)) != NULL) {  /* try as an integer */\n    setivalue(o, i);\n  }\n  else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */\n    setfltvalue(o, n);\n  }\n  else\n    return 0;  /* conversion failed */\n  return (e - s) + 1;  /* success; return string size */\n}\n\n\nint luaO_utf8esc (char *buff, unsigned long x) {\n  int n = 1;  /* number of bytes put in buffer (backwards) */\n  lua_assert(x <= 0x10FFFF);\n  if (x < 0x80)  /* ascii? */\n    buff[UTF8BUFFSZ - 1] = cast(char, x);\n  else {  /* need continuation bytes */\n    unsigned int mfb = 0x3f;  /* maximum that fits in first byte */\n    do {  /* add continuation bytes */\n      buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));\n      x >>= 6;  /* remove added bits */\n      mfb >>= 1;  /* now there is one less bit available in first byte */\n    } while (x > mfb);  /* still needs continuation byte? */\n    buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x);  /* add first byte */\n  }\n  return n;\n}\n\n\n/* maximum length of the conversion of a number to a string */\n#define MAXNUMBER2STR\t50\n\n\n/*\n** Convert a number object to a string\n*/\nvoid luaO_tostring (lua_State *L, StkId obj) {\n  char buff[MAXNUMBER2STR];\n  size_t len;\n  lua_assert(ttisnumber(obj));\n  if (ttisinteger(obj))\n    len = lua_integer2str(buff, sizeof(buff), ivalue(obj));\n  else {\n    len = lua_number2str(buff, sizeof(buff), fltvalue(obj));\n#if !defined(LUA_COMPAT_FLOATSTRING)\n    if (buff[strspn(buff, \"-0123456789\")] == '\\0') {  /* looks like an int? */\n      buff[len++] = lua_getlocaledecpoint();\n      buff[len++] = '0';  /* adds '.0' to result */\n    }\n#endif\n  }\n  setsvalue2s(L, obj, luaS_newlstr(L, buff, len));\n}\n\n\nstatic void pushstr (lua_State *L, const char *str, size_t l) {\n  setsvalue2s(L, L->top, luaS_newlstr(L, str, l));\n  luaD_inctop(L);\n}\n\n\n/*\n** this function handles only '%d', '%c', '%f', '%p', and '%s'\n   conventional formats, plus Lua-specific '%I' and '%U'\n*/\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 0;\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    pushstr(L, fmt, e - fmt);\n    switch (*(e+1)) {\n      case 's': {  /* zero-terminated string */\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s, strlen(s));\n        break;\n      }\n      case 'c': {  /* an 'int' as a character */\n        char buff = cast(char, va_arg(argp, int));\n        if (lisprint(cast_uchar(buff)))\n          pushstr(L, &buff, 1);\n        else  /* non-printable character; print its code */\n          luaO_pushfstring(L, \"<\\\\%d>\", cast_uchar(buff));\n        break;\n      }\n      case 'd': {  /* an 'int' */\n        setivalue(L->top, va_arg(argp, int));\n        goto top2str;\n      }\n      case 'I': {  /* a 'lua_Integer' */\n        setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));\n        goto top2str;\n      }\n      case 'f': {  /* a 'lua_Number' */\n        setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n      top2str:  /* convert the top element to a string */\n        luaD_inctop(L);\n        luaO_tostring(L, L->top - 1);\n        break;\n      }\n      case 'p': {  /* a pointer */\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */\n        int l = l_sprintf(buff, sizeof(buff), \"%p\", va_arg(argp, void *));\n        pushstr(L, buff, l);\n        break;\n      }\n      case 'U': {  /* an 'int' as a UTF-8 sequence */\n        char buff[UTF8BUFFSZ];\n        int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));\n        pushstr(L, buff + UTF8BUFFSZ - l, l);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\", 1);\n        break;\n      }\n      default: {\n        luaG_runerror(L, \"invalid option '%%%c' to 'lua_pushfstring'\",\n                         *(e + 1));\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  luaD_checkstack(L, 1);\n  pushstr(L, fmt, strlen(fmt));\n  if (n > 0) luaV_concat(L, n + 1);\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\n/* number of chars of a literal string without the ending \\0 */\n#define LL(x)\t(sizeof(x)/sizeof(char) - 1)\n\n#define RETS\t\"...\"\n#define PRE\t\"[string \\\"\"\n#define POS\t\"\\\"]\"\n\n#define addstr(a,b,l)\t( memcpy(a,b,(l) * sizeof(char)), a += (l) )\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  size_t l = strlen(source);\n  if (*source == '=') {  /* 'literal' source */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* truncate it */\n      addstr(out, source + 1, bufflen - 1);\n      *out = '\\0';\n    }\n  }\n  else if (*source == '@') {  /* file name */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* add '...' before rest of name */\n      addstr(out, RETS, LL(RETS));\n      bufflen -= LL(RETS);\n      memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));\n    }\n  }\n  else {  /* string; format as [string \"source\"] */\n    const char *nl = strchr(source, '\\n');  /* find first new line (if any) */\n    addstr(out, PRE, LL(PRE));  /* add prefix */\n    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\\0' */\n    if (l < bufflen && nl == NULL) {  /* small one-line source? */\n      addstr(out, source, l);  /* keep it */\n    }\n    else {\n      if (nl != NULL) l = nl - source;  /* stop at first newline */\n      if (l > bufflen) l = bufflen;\n      addstr(out, source, l);\n      addstr(out, RETS, LL(RETS));\n    }\n    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.117 2016/08/01 19:51:24 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\tLUA_NUMTAGS\t\t/* function prototypes */\n#define LUA_TDEADKEY\t(LUA_NUMTAGS+1)\t\t/* removed keys in tables */\n\n/*\n** number of all possible tags (including LUA_TNONE but excluding DEADKEY)\n*/\n#define LUA_TOTALTAGS\t(LUA_TPROTO + 2)\n\n\n/*\n** tags for Tagged Values have the following use of bits:\n** bits 0-3: actual tag (a LUA_T* value)\n** bits 4-5: variant bits\n** bit 6: whether value is collectable\n*/\n\n\n/*\n** LUA_TFUNCTION variants:\n** 0 - Lua function\n** 1 - light C function\n** 2 - regular C function (closure)\n*/\n\n/* Variant tags for functions */\n#define LUA_TLCL\t(LUA_TFUNCTION | (0 << 4))  /* Lua closure */\n#define LUA_TLCF\t(LUA_TFUNCTION | (1 << 4))  /* light C function */\n#define LUA_TCCL\t(LUA_TFUNCTION | (2 << 4))  /* C closure */\n\n\n/* Variant tags for strings */\n#define LUA_TSHRSTR\t(LUA_TSTRING | (0 << 4))  /* short strings */\n#define LUA_TLNGSTR\t(LUA_TSTRING | (1 << 4))  /* long strings */\n\n\n/* Variant tags for numbers */\n#define LUA_TNUMFLT\t(LUA_TNUMBER | (0 << 4))  /* float numbers */\n#define LUA_TNUMINT\t(LUA_TNUMBER | (1 << 4))  /* integer numbers */\n\n\n/* Bit mark for collectable types */\n#define BIT_ISCOLLECTABLE\t(1 << 6)\n\n/* mark a tag as collectable */\n#define ctb(t)\t\t\t((t) | BIT_ISCOLLECTABLE)\n\n\n/*\n** Common type for all collectable objects\n*/\ntypedef struct GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common type has only the common header\n*/\nstruct GCObject {\n  CommonHeader;\n};\n\n\n\n\n/*\n** Tagged Values. This is the basic representation of values in Lua,\n** an actual value plus a tag with its type.\n*/\n\n/*\n** Union of all Lua values\n*/\ntypedef union Value {\n  GCObject *gc;    /* collectable objects */\n  void *p;         /* light userdata */\n  int b;           /* booleans */\n  lua_CFunction f; /* light C functions */\n  lua_Integer i;   /* integer numbers */\n  lua_Number n;    /* float numbers */\n} Value;\n\n\n#define TValuefields\tValue value_; int tt_\n\n\ntypedef struct lua_TValue {\n  TValuefields;\n} TValue;\n\n\n\n/* macro defining a nil value */\n#define NILCONSTANT\t{NULL}, LUA_TNIL\n\n\n#define val_(o)\t\t((o)->value_)\n\n\n/* raw type tag of a TValue */\n#define rttype(o)\t((o)->tt_)\n\n/* tag with no variants (bits 0-3) */\n#define novariant(x)\t((x) & 0x0F)\n\n/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */\n#define ttype(o)\t(rttype(o) & 0x3F)\n\n/* type tag of a TValue with no variants (bits 0-3) */\n#define ttnov(o)\t(novariant(rttype(o)))\n\n\n/* Macros to test type */\n#define checktag(o,t)\t\t(rttype(o) == (t))\n#define checktype(o,t)\t\t(ttnov(o) == (t))\n#define ttisnumber(o)\t\tchecktype((o), LUA_TNUMBER)\n#define ttisfloat(o)\t\tchecktag((o), LUA_TNUMFLT)\n#define ttisinteger(o)\t\tchecktag((o), LUA_TNUMINT)\n#define ttisnil(o)\t\tchecktag((o), LUA_TNIL)\n#define ttisboolean(o)\t\tchecktag((o), LUA_TBOOLEAN)\n#define ttislightuserdata(o)\tchecktag((o), LUA_TLIGHTUSERDATA)\n#define ttisstring(o)\t\tchecktype((o), LUA_TSTRING)\n#define ttisshrstring(o)\tchecktag((o), ctb(LUA_TSHRSTR))\n#define ttislngstring(o)\tchecktag((o), ctb(LUA_TLNGSTR))\n#define ttistable(o)\t\tchecktag((o), ctb(LUA_TTABLE))\n#define ttisfunction(o)\t\tchecktype(o, LUA_TFUNCTION)\n#define ttisclosure(o)\t\t((rttype(o) & 0x1F) == LUA_TFUNCTION)\n#define ttisCclosure(o)\t\tchecktag((o), ctb(LUA_TCCL))\n#define ttisLclosure(o)\t\tchecktag((o), ctb(LUA_TLCL))\n#define ttislcf(o)\t\tchecktag((o), LUA_TLCF)\n#define ttisfulluserdata(o)\tchecktag((o), ctb(LUA_TUSERDATA))\n#define ttisthread(o)\t\tchecktag((o), ctb(LUA_TTHREAD))\n#define ttisdeadkey(o)\t\tchecktag((o), LUA_TDEADKEY)\n\n\n/* Macros to access values */\n#define ivalue(o)\tcheck_exp(ttisinteger(o), val_(o).i)\n#define fltvalue(o)\tcheck_exp(ttisfloat(o), val_(o).n)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), \\\n\t(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))\n#define gcvalue(o)\tcheck_exp(iscollectable(o), val_(o).gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), val_(o).p)\n#define tsvalue(o)\tcheck_exp(ttisstring(o), gco2ts(val_(o).gc))\n#define uvalue(o)\tcheck_exp(ttisfulluserdata(o), gco2u(val_(o).gc))\n#define clvalue(o)\tcheck_exp(ttisclosure(o), gco2cl(val_(o).gc))\n#define clLvalue(o)\tcheck_exp(ttisLclosure(o), gco2lcl(val_(o).gc))\n#define clCvalue(o)\tcheck_exp(ttisCclosure(o), gco2ccl(val_(o).gc))\n#define fvalue(o)\tcheck_exp(ttislcf(o), val_(o).f)\n#define hvalue(o)\tcheck_exp(ttistable(o), gco2t(val_(o).gc))\n#define bvalue(o)\tcheck_exp(ttisboolean(o), val_(o).b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), gco2th(val_(o).gc))\n/* a dead value may get the 'gc' field, but cannot access its contents */\n#define deadvalue(o)\tcheck_exp(ttisdeadkey(o), cast(void *, val_(o).gc))\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n\n#define iscollectable(o)\t(rttype(o) & BIT_ISCOLLECTABLE)\n\n\n/* Macros for internal tests */\n#define righttt(obj)\t\t(ttype(obj) == gcvalue(obj)->tt)\n\n#define checkliveness(L,obj) \\\n\tlua_longassert(!iscollectable(obj) || \\\n\t\t(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))\n\n\n/* Macros to set values */\n#define settt_(o,t)\t((o)->tt_=(t))\n\n#define setfltvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }\n\n#define chgfltvalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }\n\n#define setivalue(obj,x) \\\n  { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }\n\n#define chgivalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }\n\n#define setnilvalue(obj) settt_(obj, LUA_TNIL)\n\n#define setfvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }\n\n#define setpvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }\n\n#define setbvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }\n\n#define setgcovalue(L,obj,x) \\\n  { TValue *io = (obj); GCObject *i_g=(x); \\\n    val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }\n\n#define setsvalue(L,obj,x) \\\n  { TValue *io = (obj); TString *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \\\n    checkliveness(L,io); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *io = (obj); Udata *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \\\n    checkliveness(L,io); }\n\n#define setthvalue(L,obj,x) \\\n  { TValue *io = (obj); lua_State *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \\\n    checkliveness(L,io); }\n\n#define setclLvalue(L,obj,x) \\\n  { TValue *io = (obj); LClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \\\n    checkliveness(L,io); }\n\n#define setclCvalue(L,obj,x) \\\n  { TValue *io = (obj); CClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \\\n    checkliveness(L,io); }\n\n#define sethvalue(L,obj,x) \\\n  { TValue *io = (obj); Table *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \\\n    checkliveness(L,io); }\n\n#define setdeadvalue(obj)\tsettt_(obj, LUA_TDEADKEY)\n\n\n\n#define setobj(L,obj1,obj2) \\\n\t{ TValue *io1=(obj1); *io1 = *(obj2); \\\n\t  (void)L; checkliveness(L,io1); }\n\n\n/*\n** different types of assignments, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n/* to table (define it as an expression to be used in macros) */\n#define setobj2t(L,o1,o2)  ((void)L, *(o1)=*(o2), checkliveness(L,(o1)))\n\n\n\n\n/*\n** {======================================================\n** types and prototypes\n** =======================================================\n*/\n\n\ntypedef TValue *StkId;  /* index to stack elements */\n\n\n\n\n/*\n** Header for string value; string bytes follow the end of this structure\n** (aligned according to 'UTString'; see next).\n*/\ntypedef struct TString {\n  CommonHeader;\n  lu_byte extra;  /* reserved words for short strings; \"has hash\" for longs */\n  lu_byte shrlen;  /* length for short strings */\n  unsigned int hash;\n  union {\n    size_t lnglen;  /* length for long strings */\n    struct TString *hnext;  /* linked list for hash table */\n  } u;\n} TString;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UTString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  TString tsv;\n} UTString;\n\n\n/*\n** Get the actual string (array of bytes) from a 'TString'.\n** (Access to 'extra' ensures that value is really a 'TString'.)\n*/\n#define getstr(ts)  \\\n  check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))\n\n\n/* get the actual string (array of bytes) from a Lua value */\n#define svalue(o)       getstr(tsvalue(o))\n\n/* get string length from 'TString *s' */\n#define tsslen(s)\t((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)\n\n/* get string length from 'TValue *o' */\n#define vslen(o)\ttsslen(tsvalue(o))\n\n\n/*\n** Header for userdata; memory area follows the end of this structure\n** (aligned according to 'UUdata'; see next).\n*/\ntypedef struct Udata {\n  CommonHeader;\n  lu_byte ttuv_;  /* user value's tag */\n  struct Table *metatable;\n  size_t len;  /* number of bytes */\n  union Value user_;  /* user value */\n} Udata;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UUdata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for 'local' udata */\n  Udata uv;\n} UUdata;\n\n\n/*\n**  Get the address of memory block inside 'Udata'.\n** (Access to 'ttuv_' ensures that value is really a 'Udata'.)\n*/\n#define getudatamem(u)  \\\n  check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata)))\n\n#define setuservalue(L,u,o) \\\n\t{ const TValue *io=(o); Udata *iu = (u); \\\n\t  iu->user_ = io->value_; iu->ttuv_ = rttype(io); \\\n\t  checkliveness(L,io); }\n\n\n#define getuservalue(L,u,o) \\\n\t{ TValue *io=(o); const Udata *iu = (u); \\\n\t  io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n\t  checkliveness(L,io); }\n\n\n/*\n** Description of an upvalue for function prototypes\n*/\ntypedef struct Upvaldesc {\n  TString *name;  /* upvalue name (for debug information) */\n  lu_byte instack;  /* whether it is in stack (register) */\n  lu_byte idx;  /* index of upvalue (in stack or in outer function's list) */\n} Upvaldesc;\n\n\n/*\n** Description of a local variable for function prototypes\n** (used for debug information)\n*/\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  lu_byte numparams;  /* number of fixed parameters */\n  lu_byte is_vararg;\n  lu_byte maxstacksize;  /* number of registers needed by this function */\n  int sizeupvalues;  /* size of 'upvalues' */\n  int sizek;  /* size of 'k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of 'p' */\n  int sizelocvars;\n  int linedefined;  /* debug information  */\n  int lastlinedefined;  /* debug information  */\n  TValue *k;  /* constants used by the function */\n  Instruction *code;  /* opcodes */\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines (debug information) */\n  LocVar *locvars;  /* information about local variables (debug information) */\n  Upvaldesc *upvalues;  /* upvalue information */\n  struct LClosure *cache;  /* last-created closure with this prototype */\n  TString  *source;  /* used for debug information */\n  GCObject *gclist;\n} Proto;\n\n\n\n/*\n** Lua Upvalues\n*/\ntypedef struct UpVal UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte nupvalues; GCObject *gclist\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];  /* list of upvalues */\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];  /* list of upvalues */\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define isLfunction(o)\tttisLclosure(o)\n\n#define getproto(o)\t(clLvalue(o)->p)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    int next;  /* for chaining (offset for next node) */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\n/* copy a value into a key without messing up field 'next' */\n#define setnodekey(L,key,obj) \\\n\t{ TKey *k_=(key); const TValue *io_=(obj); \\\n\t  k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \\\n\t  (void)L; checkliveness(L,io_); }\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */\n  lu_byte lsizenode;  /* log2 of size of 'node' array */\n  unsigned int sizearray;  /* size of 'array' array */\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  struct Table *metatable;\n  GCObject *gclist;\n} Table;\n\n\n\n/*\n** 'module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n/*\n** (address of) a fixed nil value\n*/\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\n\nLUAI_DDEC const TValue luaO_nilobject_;\n\n/* size of buffer for 'luaO_utf8esc' function */\n#define UTF8BUFFSZ\t8\n\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);\nLUAI_FUNC int luaO_ceillog2 (unsigned int x);\nLUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,\n                           const TValue *p2, TValue *res);\nLUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);\nLUAI_FUNC int luaO_hexavalue (int c);\nLUAI_FUNC void luaO_tostring (lua_State *L, StkId obj);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lopcodes_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nLUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADKX\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETTABUP\",\n  \"GETTABLE\",\n  \"SETTABUP\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"MOD\",\n  \"POW\",\n  \"DIV\",\n  \"IDIV\",\n  \"BAND\",\n  \"BOR\",\n  \"BXOR\",\n  \"SHL\",\n  \"SHR\",\n  \"UNM\",\n  \"BNOT\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORCALL\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSURE\",\n  \"VARARG\",\n  \"EXTRAARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nLUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgN, OpArgN, iABx)\t\t/* OP_LOADKX */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgU, OpArgK, iABC)\t\t/* OP_GETTABUP */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABUP */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_IDIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BAND */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BXOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHR */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_BNOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(0, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORCALL */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n ,opmode(0, 0, OpArgU, OpArgU, iAx)\t\t/* OP_EXTRAARG */\n};\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t'A' : 8 bits\n\t'B' : 9 bits\n\t'C' : 9 bits\n\t'Ax' : 26 bits ('A', 'B', and 'C' together)\n\t'Bx' : 18 bits ('B' and 'C' together)\n\t'sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx, iAx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n#define SIZE_Ax\t\t(SIZE_C + SIZE_B + SIZE_A)\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n#define POS_Ax\t\tPOS_A\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* 'sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n#if SIZE_Ax < LUAI_BITSINT-1\n#define MAXARG_Ax\t((1<<SIZE_Ax)-1)\n#else\n#define MAXARG_Ax\tMAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with 'n' 1 bits at position 'p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<(n)))<<(p))\n\n/* creates a mask with 'n' 0 bits at position 'p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define getarg(i,pos,size)\t(cast(int, ((i)>>pos) & MASK1(size,0)))\n#define setarg(i,v,pos,size)\t((i) = (((i)&MASK0(size,pos)) | \\\n                ((cast(Instruction, v)<<pos)&MASK1(size,pos))))\n\n#define GETARG_A(i)\tgetarg(i, POS_A, SIZE_A)\n#define SETARG_A(i,v)\tsetarg(i, v, POS_A, SIZE_A)\n\n#define GETARG_B(i)\tgetarg(i, POS_B, SIZE_B)\n#define SETARG_B(i,v)\tsetarg(i, v, POS_B, SIZE_B)\n\n#define GETARG_C(i)\tgetarg(i, POS_C, SIZE_C)\n#define SETARG_C(i,v)\tsetarg(i, v, POS_C, SIZE_C)\n\n#define GETARG_Bx(i)\tgetarg(i, POS_Bx, SIZE_Bx)\n#define SETARG_Bx(i,v)\tsetarg(i, v, POS_Bx, SIZE_Bx)\n\n#define GETARG_Ax(i)\tgetarg(i, POS_Ax, SIZE_Ax)\n#define SETARG_Ax(i,v)\tsetarg(i, v, POS_Ax, SIZE_Ax)\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n#define CREATE_Ax(o,a)\t\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_Ax))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#if !defined(MAXINDEXRK)  /* (for debugging only) */\n#define MAXINDEXRK\t(BITRK - 1)\n#endif\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADKX,/*\tA \tR(A) := Kst(extra arg)\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A), R(A+1), ..., R(A+B) := nil\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETTABUP,/*\tA B C\tR(A) := UpValue[B][RK(C)]\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETTABUP,/*\tA B C\tUpValue[A][RK(B)] := RK(C)\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_IDIV,/*\tA B C\tR(A) := RK(B) // RK(C)\t\t\t\t*/\nOP_BAND,/*\tA B C\tR(A) := RK(B) & RK(C)\t\t\t\t*/\nOP_BOR,/*\tA B C\tR(A) := RK(B) | RK(C)\t\t\t\t*/\nOP_BXOR,/*\tA B C\tR(A) := RK(B) ~ RK(C)\t\t\t\t*/\nOP_SHL,/*\tA B C\tR(A) := RK(B) << RK(C)\t\t\t\t*/\nOP_SHR,/*\tA B C\tR(A) := RK(B) >> RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_BNOT,/*\tA B\tR(A) := ~R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tA sBx\tpc+=sBx; if (A) close all upvalues >= R(A - 1)\t*/\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++\t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++\t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/\nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/\n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORCALL,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));\t*/\nOP_TFORLOOP,/*\tA sBx\tif R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/\n\nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx])\t\t\t*/\n\nOP_VARARG,/*\tA B\tR(A), R(A+1), ..., R(A+B-2) = vararg\t\t*/\n\nOP_EXTRAARG/*\tAx\textra (larger) argument for previous opcode\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_EXTRAARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is\n  set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,\n  OP_SETLIST) may use 'top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n  set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to 'top'.\n\n  (*) In OP_SETLIST, if (B == 0) then B = 'top'; if (C == 0) then next\n  'instruction' is EXTRAARG(real C).\n\n  (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.\n\n  (*) For comparisons, A specifies what condition the test should accept\n  (true or false).\n\n  (*) All 'skips' (pc++) assume that next instruction is a jump.\n\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test (next instruction must be a jump)\n*/\n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.65 2016/07/18 17:58:58 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** {==================================================================\n** List of valid conversion specifiers for the 'strftime' function;\n** options are grouped by length; group of length 2 start with '||'.\n** ===================================================================\n*/\n#if !defined(LUA_STRFTIMEOPTIONS)\t/* { */\n\n/* options for ANSI C 89 (only 1-char options) */\n#define L_STRFTIMEC89\t\t\"aAbBcdHIjmMpSUwWxXyYZ%\"\n\n/* options for ISO C 99 and POSIX */\n#define L_STRFTIMEC99 \"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%\" \\\n    \"||\" \"EcECExEXEyEY\" \"OdOeOHOIOmOMOSOuOUOVOwOWOy\"  /* two-char options */\n\n/* options for Windows */\n#define L_STRFTIMEWIN \"aAbBcdHIjmMpSUwWxXyYzZ%\" \\\n    \"||\" \"#c#x#d#H#I#j#m#M#S#U#w#W#y#Y\"  /* two-char options */\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEWIN\n#elif defined(LUA_USE_C89)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC89\n#else  /* C99 specification */\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC99\n#endif\n\n#endif\t\t\t\t\t/* } */\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for time-related stuff\n** ===================================================================\n*/\n\n#if !defined(l_time_t)\t\t/* { */\n/*\n** type to represent time_t in Lua\n*/\n#define l_timet\t\t\tlua_Integer\n#define l_pushtime(L,t)\t\tlua_pushinteger(L,(lua_Integer)(t))\n\nstatic time_t l_checktime (lua_State *L, int arg) {\n  lua_Integer t = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, (time_t)t == t, arg, \"time out-of-bounds\");\n  return (time_t)t;\n}\n\n#endif\t\t\t\t/* } */\n\n\n#if !defined(l_gmtime)\t\t/* { */\n/*\n** By default, Lua uses gmtime/localtime, except when POSIX is available,\n** where it uses gmtime_r/localtime_r\n*/\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_gmtime(t,r)\t\tgmtime_r(t,r)\n#define l_localtime(t,r)\tlocaltime_r(t,r)\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_gmtime(t,r)\t\t((void)(r)->tm_sec, gmtime(t))\n#define l_localtime(t,r)  \t((void)(r)->tm_sec, localtime(t))\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for 'tmpnam':\n** By default, Lua uses tmpnam except when POSIX is available, where\n** it uses mkstemp.\n** ===================================================================\n*/\n#if !defined(lua_tmpnam)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n\n#define LUA_TMPNAMBUFSIZE\t32\n\n#if !defined(LUA_TMPNAMTEMPLATE)\n#define LUA_TMPNAMTEMPLATE\t\"/tmp/lua_XXXXXX\"\n#endif\n\n#define lua_tmpnam(b,e) { \\\n        strcpy(b, LUA_TMPNAMTEMPLATE); \\\n        e = mkstemp(b); \\\n        if (e != -1) close(e); \\\n        e = (e == -1); }\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n/* }================================================================== */\n\n\n\n\n//static int os_execute (lua_State *L) {\n//#if defined(WINAPI_FAMILY_PARTITION)\n//  return luaL_error(L, \"unsupport api in uwp platform\");\n//#else\n//  const char *cmd = luaL_optstring(L, 1, NULL);\n//  int stat = system(cmd);\n//  if (cmd != NULL)\n//    return luaL_execresult(L, stat);\n//  else {\n//    lua_pushboolean(L, stat);  /* true if there is a shell */\n//    return 1;\n//  }\n//#endif\n//}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\n\n/*\n** Set all fields from structure 'tm' in the table on top of the stack\n*/\nstatic void setallfields (lua_State *L, struct tm *stm) {\n  setfield(L, \"sec\", stm->tm_sec);\n  setfield(L, \"min\", stm->tm_min);\n  setfield(L, \"hour\", stm->tm_hour);\n  setfield(L, \"day\", stm->tm_mday);\n  setfield(L, \"month\", stm->tm_mon + 1);\n  setfield(L, \"year\", stm->tm_year + 1900);\n  setfield(L, \"wday\", stm->tm_wday + 1);\n  setfield(L, \"yday\", stm->tm_yday + 1);\n  setboolfield(L, \"isdst\", stm->tm_isdst);\n}\n\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\n/* maximum value for date fields (to avoid arithmetic overflows with 'int') */\n#if !defined(L_MAXDATEFIELD)\n#define L_MAXDATEFIELD\t(INT_MAX / 2)\n#endif\n\nstatic int getfield (lua_State *L, const char *key, int d, int delta) {\n  int isnum;\n  int t = lua_getfield(L, -1, key);  /* get field and its type */\n  lua_Integer res = lua_tointegerx(L, -1, &isnum);\n  if (!isnum) {  /* field is not an integer? */\n    if (t != LUA_TNIL)  /* some other value? */\n      return luaL_error(L, \"field '%s' is not an integer\", key);\n    else if (d < 0)  /* absent field; no default? */\n      return luaL_error(L, \"field '%s' missing in date table\", key);\n    res = d;\n  }\n  else {\n    if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))\n      return luaL_error(L, \"field '%s' is out-of-bound\", key);\n    res -= delta;\n  }\n  lua_pop(L, 1);\n  return (int)res;\n}\n\n\nstatic const char *checkoption (lua_State *L, const char *conv,\n                                ptrdiff_t convlen, char *buff) {\n  const char *option = LUA_STRFTIMEOPTIONS;\n  int oplen = 1;  /* length of options being checked */\n  for (; *option != '\\0' && oplen <= convlen; option += oplen) {\n    if (*option == '|')  /* next block? */\n      oplen++;  /* will check options with next length (+1) */\n    else if (memcmp(conv, option, oplen) == 0) {  /* match? */\n      memcpy(buff, conv, oplen);  /* copy valid option to buffer */\n      buff[oplen] = '\\0';\n      return conv + oplen;  /* return next item */\n    }\n  }\n  luaL_argerror(L, 1,\n    lua_pushfstring(L, \"invalid conversion specifier '%%%s'\", conv));\n  return conv;  /* to avoid warnings */\n}\n\n\n/* maximum size for an individual 'strftime' item */\n#define SIZETIMEFMT\t250\n\n\nstatic int os_date (lua_State *L) {\n  size_t slen;\n  const char *s = luaL_optlstring(L, 1, \"%c\", &slen);\n  time_t t = luaL_opt(L, l_checktime, 2, time(NULL));\n  const char *se = s + slen;  /* 's' end */\n  struct tm tmr, *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = l_gmtime(&t, &tmr);\n    s++;  /* skip '!' */\n  }\n  else\n    stm = l_localtime(&t, &tmr);\n  if (stm == NULL)  /* invalid date? */\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setallfields(L, stm);\n  }\n  else {\n    char cc[4];  /* buffer for individual conversion specifiers */\n    luaL_Buffer b;\n    cc[0] = '%';\n    luaL_buffinit(L, &b);\n    while (s < se) {\n      if (*s != '%')  /* not a conversion specifier? */\n        luaL_addchar(&b, *s++);\n      else {\n        size_t reslen;\n        char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);\n        s++;  /* skip '%' */\n        s = checkoption(L, s, se - s, cc + 1);  /* copy specifier to 'cc' */\n        reslen = strftime(buff, SIZETIMEFMT, cc, stm);\n        luaL_addsize(&b, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0, 0);\n    ts.tm_min = getfield(L, \"min\", 0, 0);\n    ts.tm_hour = getfield(L, \"hour\", 12, 0);\n    ts.tm_mday = getfield(L, \"day\", -1, 0);\n    ts.tm_mon = getfield(L, \"month\", -1, 1);\n    ts.tm_year = getfield(L, \"year\", -1, 1900);\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n    setallfields(L, &ts);  /* update fields with normalized values */\n  }\n  if (t != (time_t)(l_timet)t || t == (time_t)(-1))\n    luaL_error(L, \"time result cannot be represented in this installation\");\n  l_pushtime(L, t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  time_t t1 = l_checktime(L, 1);\n  time_t t2 = l_checktime(L, 2);\n  lua_pushnumber(L, (lua_Number)difftime(t1, t2));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  int status;\n  if (lua_isboolean(L, 1))\n    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);\n  else\n    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);\n  if (lua_toboolean(L, 2))\n    lua_close(L);\n  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */\n  return 0;\n}\n\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  //{\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUAMOD_API int luaopen_os (lua_State *L) {\n  luaL_newlib(L, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.155 2016/08/01 19:51:24 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n/* maximum number of local variables per function (must be smaller\n   than 250, due to the bytecode format) */\n#define MAXVARS\t\t200\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n\n/* because all strings are unified by the scanner, the parser\n   can use pointer equality for string equality */\n#define eqstr(a,b)\t((a) == (b))\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int firstlabel;  /* index of first label in this block */\n  int firstgoto;  /* index of first pending goto in this block */\n  lu_byte nactvar;  /* # active locals outside the block */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isloop;  /* true if 'block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void statement (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\n/* semantic error */\nstatic l_noret semerror (LexState *ls, const char *msg) {\n  ls->t.token = 0;  /* remove \"near <token>\" from final message */\n  luaX_syntaxerror(ls, msg);\n}\n\n\nstatic l_noret error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, \"%s expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic l_noret errorlimit (FuncState *fs, int limit, const char *what) {\n  lua_State *L = fs->ls->L;\n  const char *msg;\n  int line = fs->f->linedefined;\n  const char *where = (line == 0)\n                      ? \"main function\"\n                      : luaO_pushfstring(L, \"function at line %d\", line);\n  msg = luaO_pushfstring(L, \"too many %s (limit is %d) in %s\",\n                             what, limit, where);\n  luaX_syntaxerror(fs->ls, msg);\n}\n\n\nstatic void checklimit (FuncState *fs, int v, int l, const char *what) {\n  if (v > l) errorlimit(fs, l, what);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             \"%s expected (to close %s at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname (LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"local variables\");\n  while (oldsize < f->sizelocvars)\n    f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\nstatic void new_localvar (LexState *ls, TString *name) {\n  FuncState *fs = ls->fs;\n  Dyndata *dyd = ls->dyd;\n  int reg = registerlocalvar(ls, name);\n  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,\n                  MAXVARS, \"local variables\");\n  luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,\n                  dyd->actvar.size, Vardesc, MAX_INT, \"local variables\");\n  dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);\n}\n\n\nstatic void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {\n  new_localvar(ls, luaX_newstring(ls, name, sz));\n}\n\n#define new_localvarliteral(ls,v) \\\n\tnew_localvarliteral_(ls, \"\" v, (sizeof(v)/sizeof(char))-1)\n\n\nstatic LocVar *getlocvar (FuncState *fs, int i) {\n  int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;\n  lua_assert(idx < fs->nlocvars);\n  return &fs->f->locvars[idx];\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (FuncState *fs, int tolevel) {\n  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar)->endpc = fs->pc;\n}\n\n\nstatic int searchupvalue (FuncState *fs, TString *name) {\n  int i;\n  Upvaldesc *up = fs->f->upvalues;\n  for (i = 0; i < fs->nups; i++) {\n    if (eqstr(up[i].name, name)) return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic int newupvalue (FuncState *fs, TString *name, expdesc *v) {\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  checklimit(fs, fs->nups + 1, MAXUPVAL, \"upvalues\");\n  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,\n                  Upvaldesc, MAXUPVAL, \"upvalues\");\n  while (oldsize < f->sizeupvalues)\n    f->upvalues[oldsize++].name = NULL;\n  f->upvalues[fs->nups].instack = (v->k == VLOCAL);\n  f->upvalues[fs->nups].idx = cast_byte(v->u.info);\n  f->upvalues[fs->nups].name = name;\n  luaC_objbarrier(fs->ls->L, f, name);\n  return fs->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {\n    if (eqstr(n, getlocvar(fs, i)->varname))\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\n/*\n  Mark block where variable at given level was defined\n  (to emit close instructions later).\n*/\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl->nactvar > level)\n    bl = bl->previous;\n  bl->upval = 1;\n}\n\n\n/*\n  Find variable with given name 'n'. If it is an upvalue, add this\n  upvalue into all intermediate functions.\n*/\nstatic void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL)  /* no more levels? */\n    init_exp(var, VVOID, 0);  /* default is global */\n  else {\n    int v = searchvar(fs, n);  /* look up locals at current level */\n    if (v >= 0) {  /* found? */\n      init_exp(var, VLOCAL, v);  /* variable is local */\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n    }\n    else {  /* not found as local at current level; try upvalues */\n      int idx = searchupvalue(fs, n);  /* try existing upvalues */\n      if (idx < 0) {  /* not found? */\n        singlevaraux(fs->prev, n, var, 0);  /* try upper levels */\n        if (var->k == VVOID)  /* not found? */\n          return;  /* it is a global */\n        /* else was LOCAL or UPVAL */\n        idx  = newupvalue(fs, n, var);  /* will be a new upvalue */\n      }\n      init_exp(var, VUPVAL, idx);  /* new or old upvalue */\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  singlevaraux(fs, varname, var, 1);\n  if (var->k == VVOID) {  /* global name? */\n    expdesc key;\n    singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */\n    lua_assert(var->k != VVOID);  /* this one must exist */\n    codestring(ls, &key, varname);  /* key is variable name */\n    luaK_indexed(fs, var, &key);  /* env[varname] */\n  }\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n  if (nexps > nvars)\n    ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  lua_State *L = ls->L;\n  ++L->nCcalls;\n  checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, \"C levels\");\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void closegoto (LexState *ls, int g, Labeldesc *label) {\n  int i;\n  FuncState *fs = ls->fs;\n  Labellist *gl = &ls->dyd->gt;\n  Labeldesc *gt = &gl->arr[g];\n  lua_assert(eqstr(gt->name, label->name));\n  if (gt->nactvar < label->nactvar) {\n    TString *vname = getlocvar(fs, gt->nactvar)->varname;\n    const char *msg = luaO_pushfstring(ls->L,\n      \"<goto %s> at line %d jumps into the scope of local '%s'\",\n      getstr(gt->name), gt->line, getstr(vname));\n    semerror(ls, msg);\n  }\n  luaK_patchlist(fs, gt->pc, label->pc);\n  /* remove goto from pending list */\n  for (i = g; i < gl->n - 1; i++)\n    gl->arr[i] = gl->arr[i + 1];\n  gl->n--;\n}\n\n\n/*\n** try to close a goto with existing labels; this solves backward jumps\n*/\nstatic int findlabel (LexState *ls, int g) {\n  int i;\n  BlockCnt *bl = ls->fs->bl;\n  Dyndata *dyd = ls->dyd;\n  Labeldesc *gt = &dyd->gt.arr[g];\n  /* check labels in current block for a match */\n  for (i = bl->firstlabel; i < dyd->label.n; i++) {\n    Labeldesc *lb = &dyd->label.arr[i];\n    if (eqstr(lb->name, gt->name)) {  /* correct label? */\n      if (gt->nactvar > lb->nactvar &&\n          (bl->upval || dyd->label.n > bl->firstlabel))\n        luaK_patchclose(ls->fs, gt->pc, lb->nactvar);\n      closegoto(ls, g, lb);  /* close it */\n      return 1;\n    }\n  }\n  return 0;  /* label not found; cannot close goto */\n}\n\n\nstatic int newlabelentry (LexState *ls, Labellist *l, TString *name,\n                          int line, int pc) {\n  int n = l->n;\n  luaM_growvector(ls->L, l->arr, n, l->size,\n                  Labeldesc, SHRT_MAX, \"labels/gotos\");\n  l->arr[n].name = name;\n  l->arr[n].line = line;\n  l->arr[n].nactvar = ls->fs->nactvar;\n  l->arr[n].pc = pc;\n  l->n = n + 1;\n  return n;\n}\n\n\n/*\n** check whether new label 'lb' matches any pending gotos in current\n** block; solves forward jumps\n*/\nstatic void findgotos (LexState *ls, Labeldesc *lb) {\n  Labellist *gl = &ls->dyd->gt;\n  int i = ls->fs->bl->firstgoto;\n  while (i < gl->n) {\n    if (eqstr(gl->arr[i].name, lb->name))\n      closegoto(ls, i, lb);\n    else\n      i++;\n  }\n}\n\n\n/*\n** export pending gotos to outer level, to check them against\n** outer labels; if the block being exited has upvalues, and\n** the goto exits the scope of any variable (which can be the\n** upvalue), close those variables being exited.\n*/\nstatic void movegotosout (FuncState *fs, BlockCnt *bl) {\n  int i = bl->firstgoto;\n  Labellist *gl = &fs->ls->dyd->gt;\n  /* correct pending gotos to current block and try to close it\n     with visible labels */\n  while (i < gl->n) {\n    Labeldesc *gt = &gl->arr[i];\n    if (gt->nactvar > bl->nactvar) {\n      if (bl->upval)\n        luaK_patchclose(fs, gt->pc, bl->nactvar);\n      gt->nactvar = bl->nactvar;\n    }\n    if (!findlabel(fs->ls, i))\n      i++;  /* move to next one */\n  }\n}\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {\n  bl->isloop = isloop;\n  bl->nactvar = fs->nactvar;\n  bl->firstlabel = fs->ls->dyd->label.n;\n  bl->firstgoto = fs->ls->dyd->gt.n;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\n/*\n** create a label named 'break' to resolve break statements\n*/\nstatic void breaklabel (LexState *ls) {\n  TString *n = luaS_new(ls->L, \"break\");\n  int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);\n  findgotos(ls, &ls->dyd->label.arr[l]);\n}\n\n/*\n** generates an error for an undefined 'goto'; choose appropriate\n** message when label name is a reserved word (which can only be 'break')\n*/\nstatic l_noret undefgoto (LexState *ls, Labeldesc *gt) {\n  const char *msg = isreserved(gt->name)\n                    ? \"<%s> at line %d not inside a loop\"\n                    : \"no visible label '%s' for <goto> at line %d\";\n  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);\n  semerror(ls, msg);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  LexState *ls = fs->ls;\n  if (bl->previous && bl->upval) {\n    /* create a 'jump to here' to close upvalues */\n    int j = luaK_jump(fs);\n    luaK_patchclose(fs, j, bl->nactvar);\n    luaK_patchtohere(fs, j);\n  }\n  if (bl->isloop)\n    breaklabel(ls);  /* close pending breaks */\n  fs->bl = bl->previous;\n  removevars(fs, bl->nactvar);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  ls->dyd->label.n = bl->firstlabel;  /* remove local labels */\n  if (bl->previous)  /* inner block? */\n    movegotosout(fs, bl);  /* update pending gotos to outer block */\n  else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */\n    undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */\n}\n\n\n/*\n** adds a new prototype into list of prototypes\n*/\nstatic Proto *addprototype (LexState *ls) {\n  Proto *clp;\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;  /* prototype of current function */\n  if (fs->np >= f->sizep) {\n    int oldsize = f->sizep;\n    luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, \"functions\");\n    while (oldsize < f->sizep)\n      f->p[oldsize++] = NULL;\n  }\n  f->p[fs->np++] = clp = luaF_newproto(L);\n  luaC_objbarrier(L, f, clp);\n  return clp;\n}\n\n\n/*\n** codes instruction to create new closure in parent function.\n** The OP_CLOSURE instruction must use the last available register,\n** so that, if it invokes the GC, the GC knows which registers\n** are in use at that time.\n*/\nstatic void codeclosure (LexState *ls, expdesc *v) {\n  FuncState *fs = ls->fs->prev;\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));\n  luaK_exp2nextreg(fs, v);  /* fix it at the last register */\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {\n  Proto *f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nups = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->firstlocal = ls->dyd->actvar.n;\n  fs->bl = NULL;\n  f = fs->f;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  enterblock(fs, bl, 0);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  luaK_ret(fs, 0, 0);  /* final return */\n  leaveblock(fs);\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);\n  f->sizeupvalues = fs->nups;\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  luaC_checkGC(L);\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\n/*\n** check whether current token is in the follow set of a block.\n** 'until' closes syntactical blocks, but do not close scope,\n** so it is handled in separate.\n*/\nstatic int block_follow (LexState *ls, int withuntil) {\n  switch (ls->t.token) {\n    case TK_ELSE: case TK_ELSEIF:\n    case TK_END: case TK_EOS:\n      return 1;\n    case TK_UNTIL: return withuntil;\n    default: return 0;\n  }\n}\n\n\nstatic void statlist (LexState *ls) {\n  /* statlist -> { stat [';'] } */\n  while (!block_follow(ls, 1)) {\n    if (ls->t.token == TK_RETURN) {\n      statement(ls);\n      return;  /* 'return' must be last statement */\n    }\n    statement(ls);\n  }\n}\n\n\nstatic void fieldsel (LexState *ls, expdesc *v) {\n  /* fieldsel -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyregup(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of 'record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | '['exp1']') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  /* listfield -> exp */\n  expr(ls, &cc->v);\n  checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void field (LexState *ls, struct ConsControl *cc) {\n  /* field -> listfield | recfield */\n  switch(ls->t.token) {\n    case TK_NAME: {  /* may be 'listfield' or 'recfield' */\n      if (luaX_lookahead(ls) != '=')  /* expression? */\n        listfield(ls, cc);\n      else\n        recfield(ls, cc);\n      break;\n    }\n    case '[': {\n      recfield(ls, cc);\n      break;\n    }\n    default: {\n      listfield(ls, cc);\n      break;\n    }\n  }\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> '{' [ field { sep field } [sep] ] '}'\n     sep -> ',' | ';' */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    field(ls, &cc);\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { ',' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is 'parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls));\n          nparams++;\n          break;\n        }\n        case TK_DOTS: {  /* param -> '...' */\n          luaX_next(ls);\n          f->is_vararg = 1;  /* declared vararg */\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or '...' expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar);\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int ismethod, int line) {\n  /* body ->  '(' parlist ')' block END */\n  FuncState new_fs;\n  BlockCnt bl;\n  new_fs.f = addprototype(ls);\n  new_fs.f->linedefined = line;\n  open_func(ls, &new_fs, &bl);\n  checknext(ls, '(');\n  if (ismethod) {\n    new_localvarliteral(ls, \"self\");  /* create 'self' parameter */\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  statlist(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  codeclosure(ls, e);\n  close_func(ls);\n}\n\n\nstatic int explist (LexState *ls, expdesc *v) {\n  /* explist -> expr { ',' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f, int line) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> '(' [ explist ] ')' */\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use 'seminfo' before 'next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n    }\n  }\n}\n\n\nstatic void suffixedexp (LexState *ls, expdesc *v) {\n  /* suffixedexp ->\n       primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  primaryexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* fieldsel */\n        fieldsel(ls, v);\n        break;\n      }\n      case '[': {  /* '[' exp1 ']' */\n        expdesc key;\n        luaK_exp2anyregup(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* ':' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v, line);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v, line);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |\n                  constructor | FUNCTION body | suffixedexp */\n  switch (ls->t.token) {\n    case TK_FLT: {\n      init_exp(v, VKFLT, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_INT: {\n      init_exp(v, VKINT, 0);\n      v->u.ival = ls->t.seminfo.i;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use '...' outside a vararg function\");\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      suffixedexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '~': return OPR_BNOT;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case '/': return OPR_DIV;\n    case TK_IDIV: return OPR_IDIV;\n    case '&': return OPR_BAND;\n    case '|': return OPR_BOR;\n    case '~': return OPR_BXOR;\n    case TK_SHL: return OPR_SHL;\n    case TK_SHR: return OPR_SHR;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {10, 10}, {10, 10},           /* '+' '-' */\n   {11, 11}, {11, 11},           /* '*' '%' */\n   {14, 13},                  /* '^' (right associative) */\n   {11, 11}, {11, 11},           /* '/' '//' */\n   {6, 6}, {4, 4}, {5, 5},   /* '&' '|' '~' */\n   {7, 7}, {7, 7},           /* '<<' '>>' */\n   {9, 8},                   /* '..' (right associative) */\n   {3, 3}, {3, 3}, {3, 3},   /* ==, <, <= */\n   {3, 3}, {3, 3}, {3, 3},   /* ~=, >, >= */\n   {2, 2}, {1, 1}            /* and, or */\n};\n\n#define UNARY_PRIORITY\t12  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where 'binop' is any binary operator with a priority higher than 'limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    int line = ls->linenumber;\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v, line);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than 'limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    int line = ls->linenumber;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2, line);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic void block (LexState *ls) {\n  /* block -> statlist */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  statlist(ls);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to an upvalue/local variable, the\n** upvalue/local variable is begin used in a previous assignment to a\n** table. If so, save original upvalue/local value in a safe place and\n** use this safe copy in the previous assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {  /* check all previous assignments */\n    if (lh->v.k == VINDEXED) {  /* assigning to a table? */\n      /* table is the upvalue/local being assigned now? */\n      if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.vt = VLOCAL;\n        lh->v.u.ind.t = extra;  /* previous assignment will use safe copy */\n      }\n      /* index is the local being assigned? (index cannot be upvalue) */\n      if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.idx = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    /* copy upvalue/local value to a temporary (in position 'extra') */\n    OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, op, extra, v->u.info, 0);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, vkisvar(lh->v.k), \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> ',' suffixedexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    suffixedexp(ls, &nv.v);\n    if (nv.v.k != VINDEXED)\n      check_conflict(ls, lh, &nv.v);\n    checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,\n                    \"C levels\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> '=' explist */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist(ls, &e);\n    if (nexps != nvars)\n      adjust_assign(ls, nvars, nexps, &e);\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* 'falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void gotostat (LexState *ls, int pc) {\n  int line = ls->linenumber;\n  TString *label;\n  int g;\n  if (testnext(ls, TK_GOTO))\n    label = str_checkname(ls);\n  else {\n    luaX_next(ls);  /* skip break */\n    label = luaS_new(ls->L, \"break\");\n  }\n  g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);\n  findlabel(ls, g);  /* close it if label already defined */\n}\n\n\n/* check for repeated labels on the same block */\nstatic void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {\n  int i;\n  for (i = fs->bl->firstlabel; i < ll->n; i++) {\n    if (eqstr(label, ll->arr[i].name)) {\n      const char *msg = luaO_pushfstring(fs->ls->L,\n                          \"label '%s' already defined on line %d\",\n                          getstr(label), ll->arr[i].line);\n      semerror(fs->ls, msg);\n    }\n  }\n}\n\n\n/* skip no-op statements */\nstatic void skipnoopstat (LexState *ls) {\n  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)\n    statement(ls);\n}\n\n\nstatic void labelstat (LexState *ls, TString *label, int line) {\n  /* label -> '::' NAME '::' */\n  FuncState *fs = ls->fs;\n  Labellist *ll = &ls->dyd->label;\n  int l;  /* index of new label being created */\n  checkrepeated(fs, ll, label);  /* check for repeated labels */\n  checknext(ls, TK_DBCOLON);  /* skip double colon */\n  /* create new entry for this label */\n  l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));\n  skipnoopstat(ls);  /* skip other no-op statements */\n  if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */\n    /* assume that locals are already out of scope */\n    ll->arr[l].nactvar = fs->bl->nactvar;\n  }\n  findgotos(ls, &ll->arr[l]);\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_jumpto(fs, whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  statlist(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (bl2.upval)  /* upvalues? */\n    luaK_patchclose(fs, condexit, bl2.nactvar);\n  leaveblock(fs);  /* finish scope */\n  luaK_patchlist(fs, condexit, repeat_init);  /* close the loop */\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int reg;\n  expr(ls, &e);\n  luaK_exp2nextreg(ls->fs, &e);\n  lua_assert(e.k == VNONRELOC);\n  reg = e.u.info;\n  return reg;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  if (isnum)  /* numeric for? */\n    endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);\n  else {  /* generic for */\n    luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);\n    luaK_fixline(fs, line);\n    endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);\n  }\n  luaK_patchlist(fs, endfor, prep + 1);\n  luaK_fixline(fs, line);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\");\n  new_localvarliteral(ls, \"(for limit)\");\n  new_localvarliteral(ls, \"(for step)\");\n  new_localvar(ls, varname);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codek(fs, fs->freereg, luaK_intK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 4;  /* gen, state, control, plus at least one declared var */\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for control)\");\n  /* create declared variables */\n  new_localvar(ls, indexname);\n  while (testnext(ls, ',')) {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  }\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip 'for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, \"'=' or 'in' expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope ('break' jumps to this point) */\n}\n\n\nstatic void test_then_block (LexState *ls, int *escapelist) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  expdesc v;\n  int jf;  /* instruction to skip 'then' code (if condition is false) */\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  expr(ls, &v);  /* read condition */\n  checknext(ls, TK_THEN);\n  if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {\n    luaK_goiffalse(ls->fs, &v);  /* will jump to label if condition is true */\n    enterblock(fs, &bl, 0);  /* must enter block before 'goto' */\n    gotostat(ls, v.t);  /* handle goto/break */\n\twhile (testnext(ls, ';')) {}  /* skip semicolons */\n    if (block_follow(ls, 0)) {  /* 'goto' is the entire block? */\n      leaveblock(fs);\n      return;  /* and that is it */\n    }\n    else  /* must skip over 'then' part if condition is false */\n      jf = luaK_jump(fs);\n  }\n  else {  /* regular case (not goto/break) */\n    luaK_goiftrue(ls->fs, &v);  /* skip over block if condition is false */\n    enterblock(fs, &bl, 0);\n    jf = v.f;\n  }\n  statlist(ls);  /* 'then' part */\n  leaveblock(fs);\n  if (ls->t.token == TK_ELSE ||\n      ls->t.token == TK_ELSEIF)  /* followed by 'else'/'elseif'? */\n    luaK_concat(fs, escapelist, luaK_jump(fs));  /* must jump over it */\n  luaK_patchtohere(fs, jf);\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int escapelist = NO_JUMP;  /* exit list for finished parts */\n  test_then_block(ls, &escapelist);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF)\n    test_then_block(ls, &escapelist);  /* ELSEIF cond THEN block */\n  if (testnext(ls, TK_ELSE))\n    block(ls);  /* 'else' part */\n  check_match(ls, TK_END, TK_IF, line);\n  luaK_patchtohere(fs, escapelist);  /* patch escape list to 'if' end */\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls));  /* new local variable */\n  adjustlocalvars(ls, 1);  /* enter its scope */\n  body(ls, &b, 0, ls->linenumber);  /* function created in next register */\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, b.u.info)->startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {',' NAME} ['=' explist] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {fieldsel} [':' NAME] */\n  int ismethod = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    fieldsel(ls, v);\n  if (ls->t.token == ':') {\n    ismethod = 1;\n    fieldsel(ls, v);\n  }\n  return ismethod;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int ismethod;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  ismethod = funcname(ls, &v);\n  body(ls, &b, ismethod, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition \"happens\" in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  suffixedexp(ls, &v.v);\n  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n  else {  /* stat -> func */\n    check_condition(ls, v.v.k == VCALL, \"syntax error\");\n    SETARG_C(getinstruction(fs, &v.v), 1);  /* call statement uses no results */\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN [explist] [';'] */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  if (block_follow(ls, 1) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the stack */\n        first = fs->nactvar;  /* return all active values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n  testnext(ls, ';');  /* skip optional semicolon */\n}\n\n\nstatic void statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  enterlevel(ls);\n  switch (ls->t.token) {\n    case ';': {  /* stat -> ';' (empty statement) */\n      luaX_next(ls);  /* skip ';' */\n      break;\n    }\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      break;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      break;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      break;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      break;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      break;\n    }\n    case TK_FUNCTION: {  /* stat -> funcstat */\n      funcstat(ls, line);\n      break;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      break;\n    }\n    case TK_DBCOLON: {  /* stat -> label */\n      luaX_next(ls);  /* skip double colon */\n      labelstat(ls, str_checkname(ls), line);\n      break;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      luaX_next(ls);  /* skip RETURN */\n      retstat(ls);\n      break;\n    }\n    case TK_BREAK:   /* stat -> breakstat */\n    case TK_GOTO: {  /* stat -> 'goto' NAME */\n      gotostat(ls, luaK_jump(ls->fs));\n      break;\n    }\n    default: {  /* stat -> func | assignment */\n      exprstat(ls);\n      break;\n    }\n  }\n  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n             ls->fs->freereg >= ls->fs->nactvar);\n  ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n\n\n/*\n** compiles the main function, which is a regular vararg function with an\n** upvalue named LUA_ENV\n*/\nstatic void mainfunc (LexState *ls, FuncState *fs) {\n  BlockCnt bl;\n  expdesc v;\n  open_func(ls, fs, &bl);\n  fs->f->is_vararg = 1;  /* main function is always declared vararg */\n  init_exp(&v, VLOCAL, 0);  /* create and... */\n  newupvalue(fs, ls->envn, &v);  /* ...set environment upvalue */\n  luaX_next(ls);  /* read first token */\n  statlist(ls);  /* parse main body */\n  check(ls, TK_EOS);\n  close_func(ls);\n}\n\n\nLClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                       Dyndata *dyd, const char *name, int firstchar) {\n  LexState lexstate;\n  FuncState funcstate;\n  LClosure *cl = luaF_newLclosure(L, 1);  /* create main closure */\n  setclLvalue(L, L->top, cl);  /* anchor it (to avoid being collected) */\n  luaD_inctop(L);\n  lexstate.h = luaH_new(L);  /* create table for scanner */\n  sethvalue(L, L->top, lexstate.h);  /* anchor it */\n  luaD_inctop(L);\n  funcstate.f = cl->p = luaF_newproto(L);\n  funcstate.f->source = luaS_new(L, name);  /* create and anchor TString */\n  lua_assert(iswhite(funcstate.f));  /* do not need barrier here */\n  lexstate.buff = buff;\n  lexstate.dyd = dyd;\n  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;\n  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);\n  mainfunc(&lexstate, &funcstate);\n  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);\n  /* all scopes should be correctly finished */\n  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);\n  L->top--;  /* remove scanner's table */\n  return cl;  /* closure is on the stack, too */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression and variable descriptor.\n** Code generation for variables and expressions can be delayed to allow\n** optimizations; An 'expdesc' structure describes a potentially-delayed\n** variable/expression. It has a description of its \"main\" value plus a\n** list of conditional jumps that can also produce its value (generated\n** by short-circuit operators 'and'/'or').\n*/\n\n/* kinds of variables/expressions */\ntypedef enum {\n  VVOID,  /* when 'expdesc' describes the last expression a list,\n             this kind means an empty list (so, no expression) */\n  VNIL,  /* constant nil */\n  VTRUE,  /* constant true */\n  VFALSE,  /* constant false */\n  VK,  /* constant in 'k'; info = index of constant in 'k' */\n  VKFLT,  /* floating constant; nval = numerical float value */\n  VKINT,  /* integer constant; nval = numerical integer value */\n  VNONRELOC,  /* expression has its value in a fixed register;\n                 info = result register */\n  VLOCAL,  /* local variable; info = local register */\n  VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */\n  VINDEXED,  /* indexed variable;\n                ind.vt = whether 't' is register or upvalue;\n                ind.t = table register or upvalue;\n                ind.idx = key's R/K index */\n  VJMP,  /* expression is a test/comparison;\n            info = pc of corresponding jump instruction */\n  VRELOCABLE,  /* expression can put result in any register;\n                  info = instruction pc */\n  VCALL,  /* expression is a function call; info = instruction pc */\n  VVARARG  /* vararg expression; info = instruction pc */\n} expkind;\n\n\n#define vkisvar(k)\t(VLOCAL <= (k) && (k) <= VINDEXED)\n#define vkisinreg(k)\t((k) == VNONRELOC || (k) == VLOCAL)\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    lua_Integer ival;    /* for VKINT */\n    lua_Number nval;  /* for VKFLT */\n    int info;  /* for generic use */\n    struct {  /* for indexed variables (VINDEXED) */\n      short idx;  /* index (R/K) */\n      lu_byte t;  /* table (register or upvalue) */\n      lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */\n    } ind;\n  } u;\n  int t;  /* patch list of 'exit when true' */\n  int f;  /* patch list of 'exit when false' */\n} expdesc;\n\n\n/* description of active local variable */\ntypedef struct Vardesc {\n  short idx;  /* variable index in stack */\n} Vardesc;\n\n\n/* description of pending goto statements and label statements */\ntypedef struct Labeldesc {\n  TString *name;  /* label identifier */\n  int pc;  /* position in code */\n  int line;  /* line where it appeared */\n  lu_byte nactvar;  /* local level where it appears in current block */\n} Labeldesc;\n\n\n/* list of labels or gotos */\ntypedef struct Labellist {\n  Labeldesc *arr;  /* array */\n  int n;  /* number of entries in use */\n  int size;  /* array size */\n} Labellist;\n\n\n/* dynamic structures used by the parser */\ntypedef struct Dyndata {\n  struct {  /* list of active local variables */\n    Vardesc *arr;\n    int n;\n    int size;\n  } actvar;\n  Labellist gt;  /* list of pending gotos */\n  Labellist label;   /* list of active labels */\n} Dyndata;\n\n\n/* control of blocks */\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to 'ncode') */\n  int lasttarget;   /* 'label' of last 'jump label' */\n  int jpc;  /* list of pending jumps to 'pc' */\n  int nk;  /* number of elements in 'k' */\n  int np;  /* number of elements in 'p' */\n  int firstlocal;  /* index of first local var (in Dyndata array) */\n  short nlocvars;  /* number of elements in 'f->locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  lu_byte nups;  /* number of upvalues */\n  lu_byte freereg;  /* first free register */\n} FuncState;\n\n\nLUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                 Dyndata *dyd, const char *name, int firstchar);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lprefix.h",
    "content": "/*\n** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $\n** Definitions for Lua code that must come before any other header file\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lprefix_h\n#define lprefix_h\n\n\n/*\n** Allows POSIX/XSI stuff\n*/\n#if !defined(LUA_USE_C89)\t/* { */\n\n#if !defined(_XOPEN_SOURCE)\n#define _XOPEN_SOURCE           600\n#elif _XOPEN_SOURCE == 0\n#undef _XOPEN_SOURCE  /* use -D_XOPEN_SOURCE=0 to undefine it */\n#endif\n\n/*\n** Allows manipulation of large files in gcc and some other compilers\n*/\n#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)\n#define _LARGEFILE_SOURCE       1\n#define _FILE_OFFSET_BITS       64\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Windows stuff\n*/\n#if defined(_WIN32) \t/* { */\n\n#if !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS  /* avoid warnings about ISO C functions */\n#endif\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUAI_GCPAUSE)\n#define LUAI_GCPAUSE\t200  /* 200% */\n#endif\n\n#if !defined(LUAI_GCMUL)\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n#endif\n\n\n/*\n** a macro to help the creation of a unique random seed when a state is\n** created; the seed is used to randomize hashes.\n*/\n#if !defined(luai_makeseed)\n#include <time.h>\n#define luai_makeseed()\t\tcast(unsigned int, time(NULL))\n#endif\n\n\n\n/*\n** thread state + extra space\n*/\ntypedef struct LX {\n  lu_byte extra_[LUA_EXTRASPACE];\n  lua_State l;\n} LX;\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  LX l;\n  global_State g;\n} LG;\n\n\n\n#define fromstate(L)\t(cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))\n\n\n/*\n** Compute an initial seed as random as possible. Rely on Address Space\n** Layout Randomization (if present) to increase randomness..\n*/\n#define addbuff(b,p,e) \\\n  { size_t t = cast(size_t, e); \\\n    memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }\n\nstatic unsigned int makeseed (lua_State *L) {\n  char buff[4 * sizeof(size_t)];\n  unsigned int h = luai_makeseed();\n  int p = 0;\n  addbuff(buff, p, L);  /* heap variable */\n  addbuff(buff, p, &h);  /* local variable */\n  addbuff(buff, p, luaO_nilobject);  /* global variable */\n  addbuff(buff, p, &lua_newstate);  /* public function */\n  lua_assert(p == sizeof(buff));\n  return luaS_hash(buff, p, h);\n}\n\n\n/*\n** set GCdebt to a new value keeping the value (totalbytes + GCdebt)\n** invariant (and avoiding underflows in 'totalbytes')\n*/\nvoid luaE_setdebt (global_State *g, l_mem debt) {\n  l_mem tb = gettotalbytes(g);\n  lua_assert(tb > 0);\n  if (debt < tb - MAX_LMEM)\n    debt = tb - MAX_LMEM;  /* will make 'totalbytes == MAX_LMEM' */\n  g->totalbytes = tb - debt;\n  g->GCdebt = debt;\n}\n\n\nCallInfo *luaE_extendCI (lua_State *L) {\n  CallInfo *ci = luaM_new(L, CallInfo);\n  lua_assert(L->ci->next == NULL);\n  L->ci->next = ci;\n  ci->previous = L->ci;\n  ci->next = NULL;\n  L->nci++;\n  return ci;\n}\n\n\n/*\n** free all CallInfo structures not in use by a thread\n*/\nvoid luaE_freeCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next = ci->next;\n  ci->next = NULL;\n  while ((ci = next) != NULL) {\n    next = ci->next;\n    luaM_free(L, ci);\n    L->nci--;\n  }\n}\n\n\n/*\n** free half of the CallInfo structures not in use by a thread\n*/\nvoid luaE_shrinkCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next2;  /* next's next */\n  /* while there are two nexts */\n  while (ci->next != NULL && (next2 = ci->next->next) != NULL) {\n    luaM_free(L, ci->next);  /* free next */\n    L->nci--;\n    ci->next = next2;  /* remove 'next' from the list */\n    next2->previous = ci;\n    ci = next2;  /* keep next's next */\n  }\n}\n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  int i; CallInfo *ci;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);\n  L1->stacksize = BASIC_STACK_SIZE;\n  for (i = 0; i < BASIC_STACK_SIZE; i++)\n    setnilvalue(L1->stack + i);  /* erase new stack */\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;\n  /* initialize first ci */\n  ci = &L1->base_ci;\n  ci->next = ci->previous = NULL;\n  ci->callstatus = 0;\n  ci->func = L1->top;\n  setnilvalue(L1->top++);  /* 'function' entry for this 'ci' */\n  ci->top = L1->top + LUA_MINSTACK;\n  L1->ci = ci;\n}\n\n\nstatic void freestack (lua_State *L) {\n  if (L->stack == NULL)\n    return;  /* stack not completely built yet */\n  L->ci = &L->base_ci;  /* free the entire 'ci' list */\n  luaE_freeCI(L);\n  lua_assert(L->nci == 0);\n  luaM_freearray(L, L->stack, L->stacksize);  /* free stack array */\n}\n\n\n/*\n** Create registry table and its predefined values\n*/\nstatic void init_registry (lua_State *L, global_State *g) {\n  TValue temp;\n  /* create registry */\n  Table *registry = luaH_new(L);\n  sethvalue(L, &g->l_registry, registry);\n  luaH_resize(L, registry, LUA_RIDX_LAST, 0);\n  /* registry[LUA_RIDX_MAINTHREAD] = L */\n  setthvalue(L, &temp, L);  /* temp = L */\n  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);\n  /* registry[LUA_RIDX_GLOBALS] = table of globals */\n  sethvalue(L, &temp, luaH_new(L));  /* temp = new table (global table) */\n  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);\n}\n\n\n/*\n** open parts of the state that may cause memory-allocation errors.\n** ('g->version' != NULL flags that the state was completely build)\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  init_registry(L, g);\n  luaS_init(L);\n  luaT_init(L);\n  luaX_init(L);\n  g->gcrunning = 1;  /* allow gc */\n  g->version = lua_version(NULL);\n  luai_userstateopen(L);\n}\n\n\n/*\n** preinitialize a thread with consistent values without allocating\n** any memory (to avoid errors)\n*/\nstatic void preinit_thread (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->ci = NULL;\n  L->nci = 0;\n  L->stacksize = 0;\n  L->twups = L;  /* thread has no upvalues */\n  L->errorJmp = NULL;\n  L->nCcalls = 0;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->nny = 1;\n  L->status = LUA_OK;\n  L->errfunc = 0;\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeallobjects(L);  /* collect all objects */\n  if (g->version)  /* closing a fully built state? */\n    luai_userstateclose(L);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);\n  freestack(L);\n  lua_assert(gettotalbytes(g) == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);  /* free main block */\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  global_State *g = G(L);\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  /* create new thread */\n  L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;\n  L1->marked = luaC_white(g);\n  L1->tt = LUA_TTHREAD;\n  /* link it on list 'allgc' */\n  L1->next = g->allgc;\n  g->allgc = obj2gco(L1);\n  /* anchor it on L stack */\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  preinit_thread(L1, g);\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  /* initialize L1 extra space */\n  memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread),\n         LUA_EXTRASPACE);\n  luai_userstatethread(L, L1);\n  stack_init(L1, L);  /* init stack */\n  lua_unlock(L);\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  LX *l = fromstate(L1);\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L, L1);\n  freestack(L1);\n  luaM_free(L, l);\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));\n  if (l == NULL) return NULL;\n  L = &l->l.l;\n  g = &l->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bitmask(WHITE0BIT);\n  L->marked = luaC_white(g);\n  preinit_thread(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->seed = makeseed(L);\n  g->gcrunning = 0;  /* no GC while building state */\n  g->GCestimate = 0;\n  g->strt.size = g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(&g->l_registry);\n  g->panic = NULL;\n  g->version = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_NORMAL;\n  g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL;\n  g->sweepgc = NULL;\n  g->gray = g->grayagain = NULL;\n  g->weak = g->ephemeron = g->allweak = NULL;\n  g->twups = NULL;\n  g->totalbytes = sizeof(LG);\n  g->GCdebt = 0;\n  g->gcfinnum = 0;\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  return L;\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  close_state(L);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.133 2016/12/22 13:08:50 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n/*\n\n** Some notes about garbage-collected objects: All objects in Lua must\n** be kept somehow accessible until being freed, so all objects always\n** belong to one (and only one) of these lists, using field 'next' of\n** the 'CommonHeader' for the link:\n**\n** 'allgc': all objects not marked for finalization;\n** 'finobj': all objects marked for finalization;\n** 'tobefnz': all objects ready to be finalized;\n** 'fixedgc': all objects that are not to be collected (currently\n** only small strings, such as reserved words).\n\n*/\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/*\n** Atomic type (relative to signals) to better ensure that 'lua_sethook'\n** is thread safe\n*/\n#if !defined(l_signalT)\n#include <signal.h>\n#define l_signalT\tsig_atomic_t\n#endif\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n/* kinds of Garbage Collection */\n#define KGC_NORMAL\t0\n#define KGC_EMERGENCY\t1\t/* gc was forced by an allocation failure */\n\n\ntypedef struct stringtable {\n  TString **hash;\n  int nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** Information about a call.\n** When a thread yields, 'func' is adjusted to pretend that the\n** top function has only the yielded values in its stack; in that\n** case, the actual 'func' value is saved in field 'extra'.\n** When a function calls another with a continuation, 'extra' keeps\n** the function index so that, in case of errors, the continuation\n** function can be called with the correct top.\n*/\ntypedef struct CallInfo {\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  struct CallInfo *previous, *next;  /* dynamic call link */\n  union {\n    struct {  /* only for Lua functions */\n      StkId base;  /* base for this function */\n      const Instruction *savedpc;\n    } l;\n    struct {  /* only for C functions */\n      lua_KFunction k;  /* continuation in case of yields */\n      ptrdiff_t old_errfunc;\n      lua_KContext ctx;  /* context info. in case of yields */\n    } c;\n  } u;\n  ptrdiff_t extra;\n  short nresults;  /* expected number of results from this function */\n  unsigned short callstatus;\n} CallInfo;\n\n\n/*\n** Bits in CallInfo status\n*/\n#define CIST_OAH\t(1<<0)\t/* original value of 'allowhook' */\n#define CIST_LUA\t(1<<1)\t/* call is running a Lua function */\n#define CIST_HOOKED\t(1<<2)\t/* call is running a debug hook */\n#define CIST_FRESH\t(1<<3)\t/* call is running on a fresh invocation\n                                   of luaV_execute */\n#define CIST_YPCALL\t(1<<4)\t/* call is a yieldable protected call */\n#define CIST_TAIL\t(1<<5)\t/* call was tail called */\n#define CIST_HOOKYIELD\t(1<<6)\t/* last hook called yielded */\n#define CIST_LEQ\t(1<<7)  /* using __lt for __le */\n#define CIST_FIN\t(1<<8)  /* call is running a finalizer */\n\n#define isLua(ci)\t((ci)->callstatus & CIST_LUA)\n\n/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */\n#define setoah(st,v)\t((st) = ((st) & ~CIST_OAH) | (v))\n#define getoah(st)\t((st) & CIST_OAH)\n\n\n/*\n** 'global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to 'frealloc' */\n  l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */\n  l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */\n  lu_mem GCmemtrav;  /* memory traversed by the GC */\n  lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */\n  stringtable strt;  /* hash table for strings */\n  TValue l_registry;\n  unsigned int seed;  /* randomized seed for hashes */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gckind;  /* kind of GC running */\n  lu_byte gcrunning;  /* true if GC is running */\n  GCObject *allgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* current position of sweep in list */\n  GCObject *finobj;  /* list of collectable objects with finalizers */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of tables with weak values */\n  GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */\n  GCObject *allweak;  /* list of all-weak tables */\n  GCObject *tobefnz;  /* list of userdata to be GC */\n  GCObject *fixedgc;  /* list of objects not to be collected */\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  unsigned int gcfinnum;  /* number of finalizers to call in each GC step */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC 'granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  struct lua_State *mainthread;\n  const lua_Number *version;  /* pointer to version number */\n  TString *memerrmsg;  /* memory-error message */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */\n  TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */\n} global_State;\n\n\n/*\n** 'per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  unsigned short nci;  /* number of items in 'ci' list */\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *oldpc;  /* last pc traced */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  UpVal *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */\n  volatile lua_Hook hook;\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n  int stacksize;\n  int basehookcount;\n  int hookcount;\n  unsigned short nny;  /* number of non-yieldable calls in stack */\n  unsigned short nCcalls;  /* number of nested C calls */\n  l_signalT hookmask;\n  lu_byte allowhook;\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects (only for conversions)\n*/\nunion GCUnion {\n  GCObject gc;  /* common header */\n  struct TString ts;\n  struct Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct lua_State th;  /* thread */\n};\n\n\n#define cast_u(o)\tcast(union GCUnion *, (o))\n\n/* macros to convert a GCObject into a specific value */\n#define gco2ts(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))\n#define gco2u(o)  check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))\n#define gco2lcl(o)  check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))\n#define gco2ccl(o)  check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))\n#define gco2cl(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))\n#define gco2t(o)  check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))\n#define gco2p(o)  check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))\n#define gco2th(o)  check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))\n\n\n/* macro to convert a Lua object into a GCObject */\n#define obj2gco(v) \\\n\tcheck_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))\n\n\n/* actual number of total bytes allocated */\n#define gettotalbytes(g)\tcast(lu_mem, (g)->totalbytes + (g)->GCdebt)\n\nLUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\nLUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);\nLUAI_FUNC void luaE_freeCI (lua_State *L);\nLUAI_FUNC void luaE_shrinkCI (lua_State *L);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n#define MEMERRMSG       \"not enough memory\"\n\n\n/*\n** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to\n** compute its hash\n*/\n#if !defined(LUAI_HASHLIMIT)\n#define LUAI_HASHLIMIT\t\t5\n#endif\n\n\n/*\n** equality for long strings\n*/\nint luaS_eqlngstr (TString *a, TString *b) {\n  size_t len = a->u.lnglen;\n  lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);\n  return (a == b) ||  /* same instance or... */\n    ((len == b->u.lnglen) &&  /* equal length and ... */\n     (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */\n}\n\n\nunsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {\n  unsigned int h = seed ^ cast(unsigned int, l);\n  size_t step = (l >> LUAI_HASHLIMIT) + 1;\n  for (; l >= step; l -= step)\n    h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));\n  return h;\n}\n\n\nunsigned int luaS_hashlongstr (TString *ts) {\n  lua_assert(ts->tt == LUA_TLNGSTR);\n  if (ts->extra == 0) {  /* no hash? */\n    ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);\n    ts->extra = 1;  /* now it has its hash */\n  }\n  return ts->hash;\n}\n\n\n/*\n** resizes the string table\n*/\nvoid luaS_resize (lua_State *L, int newsize) {\n  int i;\n  stringtable *tb = &G(L)->strt;\n  if (newsize > tb->size) {  /* grow table if needed */\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n    for (i = tb->size; i < newsize; i++)\n      tb->hash[i] = NULL;\n  }\n  for (i = 0; i < tb->size; i++) {  /* rehash */\n    TString *p = tb->hash[i];\n    tb->hash[i] = NULL;\n    while (p) {  /* for each node in the list */\n      TString *hnext = p->u.hnext;  /* save next */\n      unsigned int h = lmod(p->hash, newsize);  /* new position */\n      p->u.hnext = tb->hash[h];  /* chain it */\n      tb->hash[h] = p;\n      p = hnext;\n    }\n  }\n  if (newsize < tb->size) {  /* shrink table if needed */\n    /* vanishing slice should be empty */\n    lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n  }\n  tb->size = newsize;\n}\n\n\n/*\n** Clear API string cache. (Entries cannot be empty, so fill them with\n** a non-collectable string.)\n*/\nvoid luaS_clearcache (global_State *g) {\n  int i, j;\n  for (i = 0; i < STRCACHE_N; i++)\n    for (j = 0; j < STRCACHE_M; j++) {\n    if (iswhite(g->strcache[i][j]))  /* will entry be collected? */\n      g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */\n    }\n}\n\n\n/*\n** Initialize the string table and the string cache\n*/\nvoid luaS_init (lua_State *L) {\n  global_State *g = G(L);\n  int i, j;\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  /* pre-create memory-error message */\n  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);\n  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */\n  for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */\n    for (j = 0; j < STRCACHE_M; j++)\n      g->strcache[i][j] = g->memerrmsg;\n}\n\n\n\n/*\n** creates a new string object\n*/\nstatic TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {\n  TString *ts;\n  GCObject *o;\n  size_t totalsize;  /* total size of TString object */\n  totalsize = sizelstring(l);\n  o = luaC_newobj(L, tag, totalsize);\n  ts = gco2ts(o);\n  ts->hash = h;\n  ts->extra = 0;\n  getstr(ts)[l] = '\\0';  /* ending 0 */\n  return ts;\n}\n\n\nTString *luaS_createlngstrobj (lua_State *L, size_t l) {\n  TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);\n  ts->u.lnglen = l;\n  return ts;\n}\n\n\nvoid luaS_remove (lua_State *L, TString *ts) {\n  stringtable *tb = &G(L)->strt;\n  TString **p = &tb->hash[lmod(ts->hash, tb->size)];\n  while (*p != ts)  /* find previous element */\n    p = &(*p)->u.hnext;\n  *p = (*p)->u.hnext;  /* remove element from its list */\n  tb->nuse--;\n}\n\n\n/*\n** checks whether short string exists and reuses it or creates a new one\n*/\nstatic TString *internshrstr (lua_State *L, const char *str, size_t l) {\n  TString *ts;\n  global_State *g = G(L);\n  unsigned int h = luaS_hash(str, l, g->seed);\n  TString **list = &g->strt.hash[lmod(h, g->strt.size)];\n  lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */\n  for (ts = *list; ts != NULL; ts = ts->u.hnext) {\n    if (l == ts->shrlen &&\n        (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {\n      /* found! */\n      if (isdead(g, ts))  /* dead (but not collected yet)? */\n        changewhite(ts);  /* resurrect it */\n      return ts;\n    }\n  }\n  if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {\n    luaS_resize(L, g->strt.size * 2);\n    list = &g->strt.hash[lmod(h, g->strt.size)];  /* recompute with new size */\n  }\n  ts = createstrobj(L, l, LUA_TSHRSTR, h);\n  memcpy(getstr(ts), str, l * sizeof(char));\n  ts->shrlen = cast_byte(l);\n  ts->u.hnext = *list;\n  *list = ts;\n  g->strt.nuse++;\n  return ts;\n}\n\n\n/*\n** new string (with explicit length)\n*/\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  if (l <= LUAI_MAXSHORTLEN)  /* short string? */\n    return internshrstr(L, str, l);\n  else {\n    TString *ts;\n    if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char))\n      luaM_toobig(L);\n    ts = luaS_createlngstrobj(L, l);\n    memcpy(getstr(ts), str, l * sizeof(char));\n    return ts;\n  }\n}\n\n\n/*\n** Create or reuse a zero-terminated string, first checking in the\n** cache (using the string address as a key). The cache can contain\n** only zero-terminated strings, so it is safe to use 'strcmp' to\n** check hits.\n*/\nTString *luaS_new (lua_State *L, const char *str) {\n  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */\n  int j;\n  TString **p = G(L)->strcache[i];\n  for (j = 0; j < STRCACHE_M; j++) {\n    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */\n      return p[j];  /* that is it */\n  }\n  /* normal route */\n  for (j = STRCACHE_M - 1; j > 0; j--)\n    p[j] = p[j - 1];  /* move out last element */\n  /* new element is first in the list */\n  p[0] = luaS_newlstr(L, str, strlen(str));\n  return p[0];\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s) {\n  Udata *u;\n  GCObject *o;\n  if (s > MAX_SIZE - sizeof(Udata))\n    luaM_toobig(L);\n  o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s));\n  u = gco2u(o);\n  u->len = s;\n  u->metatable = NULL;\n  setuservalue(L, u, luaO_nilobject);\n  return u;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizelstring(l)  (sizeof(union UTString) + ((l) + 1) * sizeof(char))\n\n#define sizeludata(l)\t(sizeof(union UUdata) + (l))\n#define sizeudata(u)\tsizeludata((u)->len)\n\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n\n/*\n** test whether a string is a reserved word\n*/\n#define isreserved(s)\t((s)->tt == LUA_TSHRSTR && (s)->extra > 0)\n\n\n/*\n** equality for short strings, which are always internalized\n*/\n#define eqshrstr(a,b)\tcheck_exp((a)->tt == LUA_TSHRSTR, (a) == (b))\n\n\nLUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);\nLUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);\nLUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC void luaS_clearcache (global_State *g);\nLUAI_FUNC void luaS_init (lua_State *L);\nLUAI_FUNC void luaS_remove (lua_State *L, TString *ts);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\nLUAI_FUNC TString *luaS_new (lua_State *L, const char *str);\nLUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <float.h>\n#include <limits.h>\n#include <locale.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** maximum number of captures that a pattern can do during\n** pattern-matching. This limit is arbitrary, but must fit in\n** an unsigned char.\n*/\n#if !defined(LUA_MAXCAPTURES)\n#define LUA_MAXCAPTURES\t\t32\n#endif\n\n\n/* macro to 'unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n\n/*\n** Some sizes are better limited to fit in 'int', but must also fit in\n** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)\n*/\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n#define MAXSIZE  \\\n\t(sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))\n\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, (lua_Integer)l);\n  return 1;\n}\n\n\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer start = posrelat(luaL_checkinteger(L, 2), l);\n  lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (lua_Integer)l) end = l;\n  if (start <= end)\n    lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l, i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i = 0; i < l; i++)\n    p[i] = s[l - i - 1];\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = tolower(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = toupper(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_rep (lua_State *L) {\n  size_t l, lsep;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer n = luaL_checkinteger(L, 2);\n  const char *sep = luaL_optlstring(L, 3, \"\", &lsep);\n  if (n <= 0) lua_pushliteral(L, \"\");\n  else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */\n    return luaL_error(L, \"resulting string too large\");\n  else {\n    size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;\n    luaL_Buffer b;\n    char *p = luaL_buffinitsize(L, &b, totallen);\n    while (n-- > 1) {  /* first n-1 copies (followed by separator) */\n      memcpy(p, s, l * sizeof(char)); p += l;\n      if (lsep > 0) {  /* empty 'memcpy' is not that cheap */\n        memcpy(p, sep, lsep * sizeof(char));\n        p += lsep;\n      }\n    }\n    memcpy(p, s, l * sizeof(char));  /* last copy (not followed by separator) */\n    luaL_pushresultsize(&b, totallen);\n  }\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi < 1) posi = 1;\n  if (pose > (lua_Integer)l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* arithmetic overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  char *p = luaL_buffinitsize(L, &b, n);\n  for (i=1; i<=n; i++) {\n    lua_Integer c = luaL_checkinteger(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"value out of range\");\n    p[i - 1] = uchar(c);\n  }\n  luaL_pushresultsize(&b, n);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void *b, size_t size, void *B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer *) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  int strip = lua_toboolean(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b, strip) != 0)\n    return luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end ('\\0') of source string */\n  const char *p_end;  /* end ('\\0') of pattern */\n  lua_State *L;\n  int matchdepth;  /* control for recursive depth (to avoid C stack overflow) */\n  unsigned char level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n/* recursive function */\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\n/* maximum recursion depth for 'match' */\n#if !defined(MAXCCALLS)\n#define MAXCCALLS\t200\n#endif\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index %%%d\", l + 1);\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (p == ms->p_end)\n        luaL_error(ms->L, \"malformed pattern (ends with '%%')\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a ']' */\n        if (p == ms->p_end)\n          luaL_error(ms->L, \"malformed pattern (missing ']')\");\n        if (*(p++) == L_ESC && p < ms->p_end)\n          p++;  /* skip escapes (e.g. '%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'g' : res = isgraph(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;  /* deprecated option */\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the '^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (MatchState *ms, const char *s, const char *p,\n                        const char *ep) {\n  if (s >= ms->src_end)\n    return 0;\n  else {\n    int c = uchar(*s);\n    switch (*p) {\n      case '.': return 1;  /* matches any char */\n      case L_ESC: return match_class(c, uchar(*(p+1)));\n      case '[': return matchbracketclass(c, p, ep-1);\n      default:  return (uchar(*p) == c);\n    }\n  }\n}\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (p >= ms->p_end - 1)\n    luaL_error(ms->L, \"malformed pattern (missing arguments to '%%b')\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while (singlematch(ms, s + i, p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (singlematch(ms, s, p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  if (ms->matchdepth-- == 0)\n    luaL_error(ms->L, \"pattern too complex\");\n  init: /* using goto's to optimize tail recursion */\n  if (p != ms->p_end) {  /* end of pattern? */\n    switch (*p) {\n      case '(': {  /* start capture */\n        if (*(p + 1) == ')')  /* position capture? */\n          s = start_capture(ms, s, p + 2, CAP_POSITION);\n        else\n          s = start_capture(ms, s, p + 1, CAP_UNFINISHED);\n        break;\n      }\n      case ')': {  /* end capture */\n        s = end_capture(ms, s, p + 1);\n        break;\n      }\n      case '$': {\n        if ((p + 1) != ms->p_end)  /* is the '$' the last char in pattern? */\n          goto dflt;  /* no; go to default */\n        s = (s == ms->src_end) ? s : NULL;  /* check end of string */\n        break;\n      }\n      case L_ESC: {  /* escaped sequences not in the format class[*+?-]? */\n        switch (*(p + 1)) {\n          case 'b': {  /* balanced string? */\n            s = matchbalance(ms, s, p + 2);\n            if (s != NULL) {\n              p += 4; goto init;  /* return match(ms, s, p + 4); */\n            }  /* else fail (s == NULL) */\n            break;\n          }\n          case 'f': {  /* frontier? */\n            const char *ep; char previous;\n            p += 2;\n            if (*p != '[')\n              luaL_error(ms->L, \"missing '[' after '%%f' in pattern\");\n            ep = classend(ms, p);  /* points to what is next */\n            previous = (s == ms->src_init) ? '\\0' : *(s - 1);\n            if (!matchbracketclass(uchar(previous), p, ep - 1) &&\n               matchbracketclass(uchar(*s), p, ep - 1)) {\n              p = ep; goto init;  /* return match(ms, s, ep); */\n            }\n            s = NULL;  /* match failed */\n            break;\n          }\n          case '0': case '1': case '2': case '3':\n          case '4': case '5': case '6': case '7':\n          case '8': case '9': {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p + 1)));\n            if (s != NULL) {\n              p += 2; goto init;  /* return match(ms, s, p + 2) */\n            }\n            break;\n          }\n          default: goto dflt;\n        }\n        break;\n      }\n      default: dflt: {  /* pattern class plus optional suffix */\n        const char *ep = classend(ms, p);  /* points to optional suffix */\n        /* does not match at least once? */\n        if (!singlematch(ms, s, p, ep)) {\n          if (*ep == '*' || *ep == '?' || *ep == '-') {  /* accept empty? */\n            p = ep + 1; goto init;  /* return match(ms, s, ep + 1); */\n          }\n          else  /* '+' or no suffix */\n            s = NULL;  /* fail */\n        }\n        else {  /* matched once */\n          switch (*ep) {  /* handle optional suffix */\n            case '?': {  /* optional */\n              const char *res;\n              if ((res = match(ms, s + 1, ep + 1)) != NULL)\n                s = res;\n              else {\n                p = ep + 1; goto init;  /* else return match(ms, s, ep + 1); */\n              }\n              break;\n            }\n            case '+':  /* 1 or more repetitions */\n              s++;  /* 1 match already done */\n              /* FALLTHROUGH */\n            case '*':  /* 0 or more repetitions */\n              s = max_expand(ms, s, p, ep);\n              break;\n            case '-':  /* 0 or more repetitions (minimum) */\n              s = min_expand(ms, s, p, ep);\n              break;\n            default:  /* no suffix */\n              s++; p = ep; goto init;  /* return match(ms, s + 1, ep); */\n          }\n        }\n        break;\n      }\n    }\n  }\n  ms->matchdepth++;\n  return s;\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative 'l1' */\n  else {\n    const char *init;  /* to search for a '*s2' inside 's1' */\n    l2--;  /* 1st char will be checked by 'memchr' */\n    l1 = l1-l2;  /* 's2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct 'l1' and 's1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index %%%d\", i + 1);\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\n/* check whether pattern has no special characters */\nstatic int nospecials (const char *p, size_t l) {\n  size_t upto = 0;\n  do {\n    if (strpbrk(p + upto, SPECIALS))\n      return 0;  /* pattern has a special character */\n    upto += strlen(p + upto) + 1;  /* may have more after \\0 */\n  } while (upto <= l);\n  return 1;  /* no special chars found */\n}\n\n\nstatic void prepstate (MatchState *ms, lua_State *L,\n                       const char *s, size_t ls, const char *p, size_t lp) {\n  ms->L = L;\n  ms->matchdepth = MAXCCALLS;\n  ms->src_init = s;\n  ms->src_end = s + ls;\n  ms->p_end = p + lp;\n}\n\n\nstatic void reprepstate (MatchState *ms) {\n  ms->level = 0;\n  lua_assert(ms->matchdepth == MAXCCALLS);\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);\n  if (init < 1) init = 1;\n  else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */\n    lua_pushnil(L);  /* cannot find anything */\n    return 1;\n  }\n  /* explicit request or no special characters? */\n  if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {\n    /* do a plain search */\n    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);\n    if (s2) {\n      lua_pushinteger(L, (s2 - s) + 1);\n      lua_pushinteger(L, (s2 - s) + lp);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    const char *s1 = s + init - 1;\n    int anchor = (*p == '^');\n    if (anchor) {\n      p++; lp--;  /* skip anchor character */\n    }\n    prepstate(&ms, L, s, ls, p, lp);\n    do {\n      const char *res;\n      reprepstate(&ms);\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, (s1 - s) + 1);  /* start */\n          lua_pushinteger(L, res - s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\n/* state for 'gmatch' */\ntypedef struct GMatchState {\n  const char *src;  /* current position */\n  const char *p;  /* pattern */\n  const char *lastmatch;  /* end of last match */\n  MatchState ms;  /* match state */\n} GMatchState;\n\n\nstatic int gmatch_aux (lua_State *L) {\n  GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));\n  const char *src;\n  gm->ms.L = L;\n  for (src = gm->src; src <= gm->ms.src_end; src++) {\n    const char *e;\n    reprepstate(&gm->ms);\n    if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {\n      gm->src = gm->lastmatch = e;\n      return push_captures(&gm->ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  GMatchState *gm;\n  lua_settop(L, 2);  /* keep them on closure to avoid being collected */\n  gm = (GMatchState *)lua_newuserdata(L, sizeof(GMatchState));\n  prepstate(&gm->ms, L, s, ls, p, lp);\n  gm->src = s; gm->p = p; gm->lastmatch = NULL;\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  lua_State *L = ms->L;\n  const char *news = lua_tolstring(L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i]))) {\n        if (news[i] != L_ESC)\n          luaL_error(L, \"invalid use of '%c' in replacement string\", L_ESC);\n        luaL_addchar(b, news[i]);\n      }\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_tolstring(L, -1, NULL);  /* if number, convert it to string */\n        lua_remove(L, -2);  /* remove original value */\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                       const char *e, int tr) {\n  lua_State *L = ms->L;\n  switch (tr) {\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n    default: {  /* LUA_TNUMBER or LUA_TSTRING */\n      add_s(ms, b, s, e);\n      return;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1));\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl, lp;\n  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */\n  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */\n  const char *lastmatch = NULL;  /* end of last match */\n  int tr = lua_type(L, 3);  /* replacement type */\n  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */\n  int anchor = (*p == '^');\n  lua_Integer n = 0;  /* replacement count */\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  if (anchor) {\n    p++; lp--;  /* skip anchor character */\n  }\n  prepstate(&ms, L, src, srcl, p, lp);\n  while (n < max_s) {\n    const char *e;\n    reprepstate(&ms);  /* (re)prepare state for new match */\n    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */\n      n++;\n      add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */\n      src = lastmatch = e;\n    }\n    else if (src < ms.src_end)  /* otherwise, skip one character */\n      luaL_addchar(&b, *src++);\n    else break;  /* end of subject */\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** STRING FORMAT\n** =======================================================\n*/\n\n#if !defined(lua_number2strx)\t/* { */\n\n/*\n** Hexadecimal floating-point formatter\n*/\n\n#include <math.h>\n\n#define SIZELENMOD\t(sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))\n\n\n/*\n** Number of bits that goes into the first digit. It can be any value\n** between 1 and 4; the following definition tries to align the number\n** to nibble boundaries by making what is left after that first digit a\n** multiple of 4.\n*/\n#define L_NBFD\t\t((l_mathlim(MANT_DIG) - 1)%4 + 1)\n\n\n/*\n** Add integer part of 'x' to buffer and return new 'x'\n*/\nstatic lua_Number adddigit (char *buff, int n, lua_Number x) {\n  lua_Number dd = l_mathop(floor)(x);  /* get integer part from 'x' */\n  int d = (int)dd;\n  buff[n] = (d < 10 ? d + '0' : d - 10 + 'a');  /* add to buffer */\n  return x - dd;  /* return what is left */\n}\n\n\nstatic int num2straux (char *buff, int sz, lua_Number x) {\n  /* if 'inf' or 'NaN', format it like '%g' */\n  if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);\n  else if (x == 0) {  /* can be -0... */\n    /* create \"0\" or \"-0\" followed by exponent */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT \"x0p+0\", (LUAI_UACNUMBER)x);\n  }\n  else {\n    int e;\n    lua_Number m = l_mathop(frexp)(x, &e);  /* 'x' fraction and exponent */\n    int n = 0;  /* character count */\n    if (m < 0) {  /* is number negative? */\n      buff[n++] = '-';  /* add signal */\n      m = -m;  /* make it positive */\n    }\n    buff[n++] = '0'; buff[n++] = 'x';  /* add \"0x\" */\n    m = adddigit(buff, n++, m * (1 << L_NBFD));  /* add first digit */\n    e -= L_NBFD;  /* this digit goes before the radix point */\n    if (m > 0) {  /* more digits? */\n      buff[n++] = lua_getlocaledecpoint();  /* add radix point */\n      do {  /* add as many digits as needed */\n        m = adddigit(buff, n++, m * 16);\n      } while (m > 0);\n    }\n    n += l_sprintf(buff + n, sz - n, \"p%+d\", e);  /* add exponent */\n    lua_assert(n < sz);\n    return n;\n  }\n}\n\n\nstatic int lua_number2strx (lua_State *L, char *buff, int sz,\n                            const char *fmt, lua_Number x) {\n  int n = num2straux(buff, sz, x);\n  if (fmt[SIZELENMOD] == 'A') {\n    int i;\n    for (i = 0; i < n; i++)\n      buff[i] = toupper(uchar(buff[i]));\n  }\n  else if (fmt[SIZELENMOD] != 'a')\n    luaL_error(L, \"modifiers for format '%%a'/'%%A' not implemented\");\n  return n;\n}\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Maximum size of each formatted item. This maximum size is produced\n** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',\n** and '\\0') + number of decimal digits to represent maxfloat (which\n** is maximum exponent + 1). (99+3+1 then rounded to 120 for \"extra\n** expenses\", such as locale-dependent stuff)\n*/\n#define MAX_ITEM        (120 + l_mathlim(MAX_10_EXP))\n\n\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n\n/*\n** maximum size of each format specification (such as \"%-099.99d\")\n*/\n#define MAX_FORMAT\t32\n\n\nstatic void addquoted (luaL_Buffer *b, const char *s, size_t len) {\n  luaL_addchar(b, '\"');\n  while (len--) {\n    if (*s == '\"' || *s == '\\\\' || *s == '\\n') {\n      luaL_addchar(b, '\\\\');\n      luaL_addchar(b, *s);\n    }\n    else if (iscntrl(uchar(*s))) {\n      char buff[10];\n      if (!isdigit(uchar(*(s+1))))\n        l_sprintf(buff, sizeof(buff), \"\\\\%d\", (int)uchar(*s));\n      else\n        l_sprintf(buff, sizeof(buff), \"\\\\%03d\", (int)uchar(*s));\n      luaL_addstring(b, buff);\n    }\n    else\n      luaL_addchar(b, *s);\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\n\n/*\n** Ensures the 'buff' string uses a dot as the radix character.\n*/\nstatic void checkdp (char *buff, int nb) {\n  if (memchr(buff, '.', nb) == NULL) {  /* no dot? */\n    char point = lua_getlocaledecpoint();  /* try locale point */\n    char *ppoint = (char *)memchr(buff, point, nb);\n    if (ppoint) *ppoint = '.';  /* change it to a dot */\n  }\n}\n\n\nstatic void addliteral (lua_State *L, luaL_Buffer *b, int arg) {\n  switch (lua_type(L, arg)) {\n    case LUA_TSTRING: {\n      size_t len;\n      const char *s = lua_tolstring(L, arg, &len);\n      addquoted(b, s, len);\n      break;\n    }\n    case LUA_TNUMBER: {\n      char *buff = luaL_prepbuffsize(b, MAX_ITEM);\n      int nb;\n      if (!lua_isinteger(L, arg)) {  /* float? */\n        lua_Number n = lua_tonumber(L, arg);  /* write as hexa ('%a') */\n        nb = lua_number2strx(L, buff, MAX_ITEM, \"%\" LUA_NUMBER_FRMLEN \"a\", n);\n        checkdp(buff, nb);  /* ensure it uses a dot */\n      }\n      else {  /* integers */\n        lua_Integer n = lua_tointeger(L, arg);\n        const char *format = (n == LUA_MININTEGER)  /* corner case? */\n                           ? \"0x%\" LUA_INTEGER_FRMLEN \"x\"  /* use hexa */\n                           : LUA_INTEGER_FMT;  /* else use default format */\n        nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);\n      }\n      luaL_addsize(b, nb);\n      break;\n    }\n    case LUA_TNIL: case LUA_TBOOLEAN: {\n      luaL_tolstring(L, arg, NULL);\n      luaL_addvalue(b);\n      break;\n    }\n    default: {\n      luaL_argerror(L, arg, \"value has no literal form\");\n    }\n  }\n}\n\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));\n  form += (p - strfrmt) + 1;\n  *form = '\\0';\n  return p;\n}\n\n\n/*\n** add length modifier into formats\n*/\nstatic void addlenmod (char *form, const char *lenmod) {\n  size_t l = strlen(form);\n  size_t lm = strlen(lenmod);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, lenmod);\n  form[l + lm - 1] = spec;\n  form[l + lm] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format ('%...') */\n      char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */\n      int nb = 0;  /* number of bytes in added item */\n      if (++arg > top)\n        luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));\n          break;\n        }\n        case 'd': case 'i':\n        case 'o': case 'u': case 'x': case 'X': {\n          lua_Integer n = luaL_checkinteger(L, arg);\n          addlenmod(form, LUA_INTEGER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);\n          break;\n        }\n        case 'a': case 'A':\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = lua_number2strx(L, buff, MAX_ITEM, form,\n                                  luaL_checknumber(L, arg));\n          break;\n        case 'e': case 'E': case 'f':\n        case 'g': case 'G': {\n          lua_Number n = luaL_checknumber(L, arg);\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);\n          break;\n        }\n        case 'q': {\n          addliteral(L, &b, arg);\n          break;\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_tolstring(L, arg, &l);\n          if (form[2] == '\\0')  /* no modifiers? */\n            luaL_addvalue(&b);  /* keep entire string */\n          else {\n            luaL_argcheck(L, l == strlen(s), arg, \"string contains zeros\");\n            if (!strchr(form, '.') && l >= 100) {\n              /* no precision and string is too long to be formatted */\n              luaL_addvalue(&b);  /* keep entire string */\n            }\n            else {  /* format the string into 'buff' */\n              nb = l_sprintf(buff, MAX_ITEM, form, s);\n              lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */\n            }\n          }\n          break;\n        }\n        default: {  /* also treat cases 'pnLlh' */\n          return luaL_error(L, \"invalid option '%%%c' to 'format'\",\n                               *(strfrmt - 1));\n        }\n      }\n      lua_assert(nb < MAX_ITEM);\n      luaL_addsize(&b, nb);\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** PACK/UNPACK\n** =======================================================\n*/\n\n\n/* value used for padding */\n#if !defined(LUAL_PACKPADBYTE)\n#define LUAL_PACKPADBYTE\t\t0x00\n#endif\n\n/* maximum size for the binary representation of an integer */\n#define MAXINTSIZE\t16\n\n/* number of bits in a character */\n#define NB\tCHAR_BIT\n\n/* mask for one character (NB 1's) */\n#define MC\t((1 << NB) - 1)\n\n/* size of a lua_Integer */\n#define SZINT\t((int)sizeof(lua_Integer))\n\n\n/* dummy union to get native endianness */\nstatic const union {\n  int dummy;\n  char little;  /* true iff machine is little endian */\n} nativeendian = {1};\n\n\n/* dummy structure to get native alignment requirements */\nstruct cD {\n  char c;\n  union { double d; void *p; lua_Integer i; lua_Number n; } u;\n};\n\n#define MAXALIGN\t(offsetof(struct cD, u))\n\n\n/*\n** Union for serializing floats\n*/\ntypedef union Ftypes {\n  float f;\n  double d;\n  lua_Number n;\n  char buff[5 * sizeof(lua_Number)];  /* enough for any float type */\n} Ftypes;\n\n\n/*\n** information to pack/unpack stuff\n*/\ntypedef struct Header {\n  lua_State *L;\n  int islittle;\n  int maxalign;\n} Header;\n\n\n/*\n** options for pack/unpack\n*/\ntypedef enum KOption {\n  Kint,\t\t/* signed integers */\n  Kuint,\t/* unsigned integers */\n  Kfloat,\t/* floating-point numbers */\n  Kchar,\t/* fixed-length strings */\n  Kstring,\t/* strings with prefixed length */\n  Kzstr,\t/* zero-terminated strings */\n  Kpadding,\t/* padding */\n  Kpaddalign,\t/* padding for alignment */\n  Knop\t\t/* no-op (configuration or spaces) */\n} KOption;\n\n\n/*\n** Read an integer numeral from string 'fmt' or return 'df' if\n** there is no numeral\n*/\nstatic int digit (int c) { return '0' <= c && c <= '9'; }\n\nstatic int getnum (const char **fmt, int df) {\n  if (!digit(**fmt))  /* no number? */\n    return df;  /* return default value */\n  else {\n    int a = 0;\n    do {\n      a = a*10 + (*((*fmt)++) - '0');\n    } while (digit(**fmt) && a <= ((int)MAXSIZE - 9)/10);\n    return a;\n  }\n}\n\n\n/*\n** Read an integer numeral and raises an error if it is larger\n** than the maximum size for integers.\n*/\nstatic int getnumlimit (Header *h, const char **fmt, int df) {\n  int sz = getnum(fmt, df);\n  if (sz > MAXINTSIZE || sz <= 0)\n    luaL_error(h->L, \"integral size (%d) out of limits [1,%d]\",\n                     sz, MAXINTSIZE);\n  return sz;\n}\n\n\n/*\n** Initialize Header\n*/\nstatic void initheader (lua_State *L, Header *h) {\n  h->L = L;\n  h->islittle = nativeendian.little;\n  h->maxalign = 1;\n}\n\n\n/*\n** Read and classify next option. 'size' is filled with option's size.\n*/\nstatic KOption getoption (Header *h, const char **fmt, int *size) {\n  int opt = *((*fmt)++);\n  *size = 0;  /* default */\n  switch (opt) {\n    case 'b': *size = sizeof(char); return Kint;\n    case 'B': *size = sizeof(char); return Kuint;\n    case 'h': *size = sizeof(short); return Kint;\n    case 'H': *size = sizeof(short); return Kuint;\n    case 'l': *size = sizeof(long); return Kint;\n    case 'L': *size = sizeof(long); return Kuint;\n    case 'j': *size = sizeof(lua_Integer); return Kint;\n    case 'J': *size = sizeof(lua_Integer); return Kuint;\n    case 'T': *size = sizeof(size_t); return Kuint;\n    case 'f': *size = sizeof(float); return Kfloat;\n    case 'd': *size = sizeof(double); return Kfloat;\n    case 'n': *size = sizeof(lua_Number); return Kfloat;\n    case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;\n    case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;\n    case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;\n    case 'c':\n      *size = getnum(fmt, -1);\n      if (*size == -1)\n        luaL_error(h->L, \"missing size for format option 'c'\");\n      return Kchar;\n    case 'z': return Kzstr;\n    case 'x': *size = 1; return Kpadding;\n    case 'X': return Kpaddalign;\n    case ' ': break;\n    case '<': h->islittle = 1; break;\n    case '>': h->islittle = 0; break;\n    case '=': h->islittle = nativeendian.little; break;\n    case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break;\n    default: luaL_error(h->L, \"invalid format option '%c'\", opt);\n  }\n  return Knop;\n}\n\n\n/*\n** Read, classify, and fill other details about the next option.\n** 'psize' is filled with option's size, 'notoalign' with its\n** alignment requirements.\n** Local variable 'size' gets the size to be aligned. (Kpadal option\n** always gets its full alignment, other options are limited by\n** the maximum alignment ('maxalign'). Kchar option needs no alignment\n** despite its size.\n*/\nstatic KOption getdetails (Header *h, size_t totalsize,\n                           const char **fmt, int *psize, int *ntoalign) {\n  KOption opt = getoption(h, fmt, psize);\n  int align = *psize;  /* usually, alignment follows size */\n  if (opt == Kpaddalign) {  /* 'X' gets alignment from following option */\n    if (**fmt == '\\0' || getoption(h, fmt, &align) == Kchar || align == 0)\n      luaL_argerror(h->L, 1, \"invalid next option for option 'X'\");\n  }\n  if (align <= 1 || opt == Kchar)  /* need no alignment? */\n    *ntoalign = 0;\n  else {\n    if (align > h->maxalign)  /* enforce maximum alignment */\n      align = h->maxalign;\n    if ((align & (align - 1)) != 0)  /* is 'align' not a power of 2? */\n      luaL_argerror(h->L, 1, \"format asks for alignment not power of 2\");\n    *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1);\n  }\n  return opt;\n}\n\n\n/*\n** Pack integer 'n' with 'size' bytes and 'islittle' endianness.\n** The final 'if' handles the case when 'size' is larger than\n** the size of a Lua integer, correcting the extra sign-extension\n** bytes if necessary (by default they would be zeros).\n*/\nstatic void packint (luaL_Buffer *b, lua_Unsigned n,\n                     int islittle, int size, int neg) {\n  char *buff = luaL_prepbuffsize(b, size);\n  int i;\n  buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */\n  for (i = 1; i < size; i++) {\n    n >>= NB;\n    buff[islittle ? i : size - 1 - i] = (char)(n & MC);\n  }\n  if (neg && size > SZINT) {  /* negative number need sign extension? */\n    for (i = SZINT; i < size; i++)  /* correct extra bytes */\n      buff[islittle ? i : size - 1 - i] = (char)MC;\n  }\n  luaL_addsize(b, size);  /* add result to buffer */\n}\n\n\n/*\n** Copy 'size' bytes from 'src' to 'dest', correcting endianness if\n** given 'islittle' is different from native endianness.\n*/\nstatic void copywithendian (volatile char *dest, volatile const char *src,\n                            int size, int islittle) {\n  if (islittle == nativeendian.little) {\n    while (size-- != 0)\n      *(dest++) = *(src++);\n  }\n  else {\n    dest += size - 1;\n    while (size-- != 0)\n      *(dest--) = *(src++);\n  }\n}\n\n\nstatic int str_pack (lua_State *L) {\n  luaL_Buffer b;\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  int arg = 1;  /* current argument to pack */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  lua_pushnil(L);  /* mark to separate arguments from string buffer */\n  luaL_buffinit(L, &b);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    totalsize += ntoalign + size;\n    while (ntoalign-- > 0)\n     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */\n    arg++;\n    switch (opt) {\n      case Kint: {  /* signed integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT) {  /* need overflow check? */\n          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);\n          luaL_argcheck(L, -lim <= n && n < lim, arg, \"integer overflow\");\n        }\n        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));\n        break;\n      }\n      case Kuint: {  /* unsigned integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT)  /* need overflow check? */\n          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),\n                           arg, \"unsigned overflow\");\n        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);\n        break;\n      }\n      case Kfloat: {  /* floating-point options */\n        volatile Ftypes u;\n        char *buff = luaL_prepbuffsize(&b, size);\n        lua_Number n = luaL_checknumber(L, arg);  /* get argument */\n        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */\n        else if (size == sizeof(u.d)) u.d = (double)n;\n        else u.n = n;\n        /* move 'u' to final result, correcting endianness if needed */\n        copywithendian(buff, u.buff, size, h.islittle);\n        luaL_addsize(&b, size);\n        break;\n      }\n      case Kchar: {  /* fixed-size string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, len <= (size_t)size, arg,\n                         \"string longer than given size\");\n        luaL_addlstring(&b, s, len);  /* add string */\n        while (len++ < (size_t)size)  /* pad extra space */\n          luaL_addchar(&b, LUAL_PACKPADBYTE);\n        break;\n      }\n      case Kstring: {  /* strings with length count */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, size >= (int)sizeof(size_t) ||\n                         len < ((size_t)1 << (size * NB)),\n                         arg, \"string length does not fit in given size\");\n        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */\n        luaL_addlstring(&b, s, len);\n        totalsize += len;\n        break;\n      }\n      case Kzstr: {  /* zero-terminated string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, strlen(s) == len, arg, \"string contains zeros\");\n        luaL_addlstring(&b, s, len);\n        luaL_addchar(&b, '\\0');  /* add zero at the end */\n        totalsize += len + 1;\n        break;\n      }\n      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */\n      case Kpaddalign: case Knop:\n        arg--;  /* undo increment */\n        break;\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_packsize (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    size += ntoalign;  /* total space used by option */\n    luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,\n                     \"format result too large\");\n    totalsize += size;\n    switch (opt) {\n      case Kstring:  /* strings with length count */\n      case Kzstr:    /* zero-terminated string */\n        luaL_argerror(L, 1, \"variable-length format\");\n        /* call never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:  break;\n    }\n  }\n  lua_pushinteger(L, (lua_Integer)totalsize);\n  return 1;\n}\n\n\n/*\n** Unpack an integer with 'size' bytes and 'islittle' endianness.\n** If size is smaller than the size of a Lua integer and integer\n** is signed, must do sign extension (propagating the sign to the\n** higher bits); if size is larger than the size of a Lua integer,\n** it must check the unread bytes to see whether they do not cause an\n** overflow.\n*/\nstatic lua_Integer unpackint (lua_State *L, const char *str,\n                              int islittle, int size, int issigned) {\n  lua_Unsigned res = 0;\n  int i;\n  int limit = (size  <= SZINT) ? size : SZINT;\n  for (i = limit - 1; i >= 0; i--) {\n    res <<= NB;\n    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];\n  }\n  if (size < SZINT) {  /* real size smaller than lua_Integer? */\n    if (issigned) {  /* needs sign extension? */\n      lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);\n      res = ((res ^ mask) - mask);  /* do sign extension */\n    }\n  }\n  else if (size > SZINT) {  /* must check unread bytes */\n    int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;\n    for (i = limit; i < size; i++) {\n      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)\n        luaL_error(L, \"%d-byte integer does not fit into Lua Integer\", size);\n    }\n  }\n  return (lua_Integer)res;\n}\n\n\nstatic int str_unpack (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);\n  size_t ld;\n  const char *data = luaL_checklstring(L, 2, &ld);\n  size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;\n  int n = 0;  /* number of results */\n  luaL_argcheck(L, pos <= ld, 3, \"initial position out of string\");\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);\n    if ((size_t)ntoalign + size > ~pos || pos + ntoalign + size > ld)\n      luaL_argerror(L, 2, \"data string too short\");\n    pos += ntoalign;  /* skip alignment */\n    /* stack space for item + next position */\n    luaL_checkstack(L, 2, \"too many results\");\n    n++;\n    switch (opt) {\n      case Kint:\n      case Kuint: {\n        lua_Integer res = unpackint(L, data + pos, h.islittle, size,\n                                       (opt == Kint));\n        lua_pushinteger(L, res);\n        break;\n      }\n      case Kfloat: {\n        volatile Ftypes u;\n        lua_Number num;\n        copywithendian(u.buff, data + pos, size, h.islittle);\n        if (size == sizeof(u.f)) num = (lua_Number)u.f;\n        else if (size == sizeof(u.d)) num = (lua_Number)u.d;\n        else num = u.n;\n        lua_pushnumber(L, num);\n        break;\n      }\n      case Kchar: {\n        lua_pushlstring(L, data + pos, size);\n        break;\n      }\n      case Kstring: {\n        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);\n        luaL_argcheck(L, pos + len + size <= ld, 2, \"data string too short\");\n        lua_pushlstring(L, data + pos + size, len);\n        pos += len;  /* skip string */\n        break;\n      }\n      case Kzstr: {\n        size_t len = (int)strlen(data + pos);\n        lua_pushlstring(L, data + pos, len);\n        pos += len + 1;  /* skip string plus final '\\0' */\n        break;\n      }\n      case Kpaddalign: case Kpadding: case Knop:\n        n--;  /* undo increment */\n        break;\n    }\n    pos += size;\n  }\n  lua_pushinteger(L, pos + 1);  /* next position */\n  return n + 1;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {\"pack\", str_pack},\n  {\"packsize\", str_packsize},\n  {\"unpack\", str_unpack},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* table to be metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);  /* copy table */\n  lua_setmetatable(L, -2);  /* set table as metatable for strings */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* get string library */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = string */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUAMOD_API int luaopen_string (lua_State *L) {\n  luaL_newlib(L, strlib);\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.118 2016/11/07 12:38:35 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest 'n' such that\n** more than half the slots between 1 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the 'original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <limits.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/*\n** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is\n** the largest integer such that MAXASIZE fits in an unsigned int.\n*/\n#define MAXABITS\tcast_int(sizeof(int) * CHAR_BIT - 1)\n#define MAXASIZE\t(1u << MAXABITS)\n\n/*\n** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest\n** integer such that 2^MAXHBITS fits in a signed int. (Note that the\n** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still\n** fits comfortably in an unsigned int.)\n*/\n#define MAXHBITS\t(MAXABITS - 1)\n\n\n#define hashpow2(t,n)\t\t(gnode(t, lmod((n), sizenode(t))))\n\n#define hashstr(t,str)\t\thashpow2(t, (str)->hash)\n#define hashboolean(t,p)\thashpow2(t, p)\n#define hashint(t,i)\t\thashpow2(t, i)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, point2uint(p))\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {NILCONSTANT},  /* value */\n  {{NILCONSTANT, 0}}  /* key */\n};\n\n\n/*\n** Hash for floating-point numbers.\n** The main computation should be just\n**     n = frexp(n, &i); return (n * INT_MAX) + i\n** but there are some numerical subtleties.\n** In a two-complement representation, INT_MAX does not has an exact\n** representation as a float, but INT_MIN does; because the absolute\n** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the\n** absolute value of the product 'frexp * -INT_MIN' is smaller or equal\n** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when\n** adding 'i'; the use of '~u' (instead of '-u') avoids problems with\n** INT_MIN.\n*/\n#if !defined(l_hashfloat)\nstatic int l_hashfloat (lua_Number n) {\n  int i;\n  lua_Integer ni;\n  n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);\n  if (!lua_numbertointeger(n, &ni)) {  /* is 'n' inf/-inf/NaN? */\n    lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));\n    return 0;\n  }\n  else {  /* normal case */\n    unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);\n    return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);\n  }\n}\n#endif\n\n\n/*\n** returns the 'main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMINT:\n      return hashint(t, ivalue(key));\n    case LUA_TNUMFLT:\n      return hashmod(t, l_hashfloat(fltvalue(key)));\n    case LUA_TSHRSTR:\n      return hashstr(t, tsvalue(key));\n    case LUA_TLNGSTR:\n      return hashpow2(t, luaS_hashlongstr(tsvalue(key)));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    case LUA_TLCF:\n      return hashpointer(t, fvalue(key));\n    default:\n      lua_assert(!ttisdeadkey(key));\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for 'key' if 'key' is an appropriate key to live in\n** the array part of the table, 0 otherwise.\n*/\nstatic unsigned int arrayindex (const TValue *key) {\n  if (ttisinteger(key)) {\n    lua_Integer k = ivalue(key);\n    if (0 < k && (lua_Unsigned)k <= MAXASIZE)\n      return cast(unsigned int, k);  /* 'key' is an appropriate array index */\n  }\n  return 0;  /* 'key' did not match some condition */\n}\n\n\n/*\n** returns the index of a 'key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signaled by 0.\n*/\nstatic unsigned int findindex (lua_State *L, Table *t, StkId key) {\n  unsigned int i;\n  if (ttisnil(key)) return 0;  /* first iteration */\n  i = arrayindex(key);\n  if (i != 0 && i <= t->sizearray)  /* is 'key' inside array part? */\n    return i;  /* yes; that's the index */\n  else {\n    int nx;\n    Node *n = mainposition(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in 'next' */\n      if (luaV_rawequalobj(gkey(n), key) ||\n            (ttisdeadkey(gkey(n)) && iscollectable(key) &&\n             deadvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return (i + 1) + t->sizearray;\n      }\n      nx = gnext(n);\n      if (nx == 0)\n        luaG_runerror(L, \"invalid key to 'next'\");  /* key not found */\n      else n += nx;\n    }\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  unsigned int i = findindex(L, t, key);  /* find original element */\n  for (; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setivalue(key, i + 1);\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) {  /* hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, gkey(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n/*\n** Compute the optimal size for the array part of table 't'. 'nums' is a\n** \"count array\" where 'nums[i]' is the number of integers in the table\n** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of\n** integer keys in the table and leaves with the number of keys that\n** will go to the array part; return the optimal size.\n*/\nstatic unsigned int computesizes (unsigned int nums[], unsigned int *pna) {\n  int i;\n  unsigned int twotoi;  /* 2^i (candidate for optimal size) */\n  unsigned int a = 0;  /* number of elements smaller than 2^i */\n  unsigned int na = 0;  /* number of elements to go to array part */\n  unsigned int optimal = 0;  /* optimal size for array part */\n  /* loop while keys can fill more than half of total size */\n  for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        optimal = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements up to 'optimal' will go to array part */\n      }\n    }\n  }\n  lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);\n  *pna = na;\n  return optimal;\n}\n\n\nstatic int countint (const TValue *key, unsigned int *nums) {\n  unsigned int k = arrayindex(key);\n  if (k != 0) {  /* is 'key' an appropriate array index? */\n    nums[luaO_ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Count keys in array part of table 't': Fill 'nums[i]' with\n** number of keys that will go into corresponding slice and return\n** total number of non-nil keys.\n*/\nstatic unsigned int numusearray (const Table *t, unsigned int *nums) {\n  int lg;\n  unsigned int ttlg;  /* 2^lg */\n  unsigned int ause = 0;  /* summation of 'nums' */\n  unsigned int i = 1;  /* count to traverse all array keys */\n  /* traverse each slice */\n  for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {\n    unsigned int lc = 0;  /* counter */\n    unsigned int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg - 1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* elements added to 'nums' (can go to array part) */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(gkey(n), nums);\n      totaluse++;\n    }\n  }\n  *pna += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, unsigned int size) {\n  unsigned int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic void setnodevector (lua_State *L, Table *t, unsigned int size) {\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common 'dummynode' */\n    t->lsizenode = 0;\n    t->lastfree = NULL;  /* signal that it is using dummy node */\n  }\n  else {\n    int i;\n    int lsize = luaO_ceillog2(size);\n    if (lsize > MAXHBITS)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i = 0; i < (int)size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = 0;\n      setnilvalue(wgkey(n));\n      setnilvalue(gval(n));\n    }\n    t->lsizenode = cast_byte(lsize);\n    t->lastfree = gnode(t, size);  /* all positions are free */\n  }\n}\n\n\nvoid luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                          unsigned int nhsize) {\n  unsigned int i;\n  int j;\n  unsigned int oldasize = t->sizearray;\n  int oldhsize = allocsizenode(t);\n  Node *nold = t->node;  /* save old hash ... */\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  /* create new hash part with appropriate size */\n  setnodevector(L, t, nhsize);\n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        luaH_setint(L, t, i + 1, &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n  /* re-insert elements from hash part */\n  for (j = oldhsize - 1; j >= 0; j--) {\n    Node *old = nold + j;\n    if (!ttisnil(gval(old))) {\n      /* doesn't need barrier/invalidate cache, as entry was\n         already present in the table */\n      setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));\n    }\n  }\n  if (oldhsize > 0)  /* not the dummy node? */\n    luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {\n  int nsize = allocsizenode(t);\n  luaH_resize(L, t, nasize, nsize);\n}\n\n/*\n** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i\n*/\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  unsigned int asize;  /* optimal size for array part */\n  unsigned int na;  /* number of keys in the array part */\n  unsigned int nums[MAXABITS + 1];\n  int i;\n  int totaluse;\n  for (i = 0; i <= MAXABITS; i++) nums[i] = 0;  /* reset counts */\n  na = numusearray(t, nums);  /* count keys in array part */\n  totaluse = na;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &na);  /* count keys in hash part */\n  /* count extra key */\n  na += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  asize = computesizes(nums, &na);\n  /* resize the table to new computed sizes */\n  luaH_resize(L, t, asize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));\n  Table *t = gco2t(o);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  t->array = NULL;\n  t->sizearray = 0;\n  setnodevector(L, t, 0);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (!isdummy(t))\n    luaM_freearray(L, t->node, cast(size_t, sizenode(t)));\n  luaM_freearray(L, t->array, t->sizearray);\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  if (!isdummy(t)) {\n    while (t->lastfree > t->node) {\n      t->lastfree--;\n      if (ttisnil(gkey(t->lastfree)))\n        return t->lastfree;\n    }\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main\n** position is free. If not, check whether colliding node is in its main\n** position or not: if it is not, move colliding node to an empty place and\n** put new key in its main position; otherwise (colliding node is in its main\n** position), new key goes to an empty position.\n*/\nTValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp;\n  TValue aux;\n  if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n  else if (ttisfloat(key)) {\n    lua_Integer k;\n    if (luaV_tointeger(key, &k, 0)) {  /* does index fit in an integer? */\n      setivalue(&aux, k);\n      key = &aux;  /* insert it as an integer */\n    }\n    else if (luai_numisnan(fltvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n  }\n  mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || isdummy(t)) {  /* main position is taken? */\n    Node *othern;\n    Node *f = getfreepos(t);  /* get a free place */\n    if (f == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      /* whatever called 'newkey' takes care of TM cache */\n      return luaH_set(L, t, key);  /* insert key into grown table */\n    }\n    lua_assert(!isdummy(t));\n    othern = mainposition(t, gkey(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (othern + gnext(othern) != mp)  /* find previous */\n        othern += gnext(othern);\n      gnext(othern) = cast_int(f - othern);  /* rechain to point to 'f' */\n      *f = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      if (gnext(mp) != 0) {\n        gnext(f) += cast_int(mp - f);  /* correct 'next' */\n        gnext(mp) = 0;  /* now 'mp' is free */\n      }\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      if (gnext(mp) != 0)\n        gnext(f) = cast_int((mp + gnext(mp)) - f);  /* chain new position */\n      else lua_assert(gnext(f) == 0);\n      gnext(mp) = cast_int(f - mp);\n      mp = f;\n    }\n  }\n  setnodekey(L, &mp->i_key, key);\n  luaC_barrierback(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getint (Table *t, lua_Integer key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (l_castS2U(key) - 1 < t->sizearray)\n    return &t->array[key - 1];\n  else {\n    Node *n = hashint(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)\n        return gval(n);  /* that's it */\n      else {\n        int nx = gnext(n);\n        if (nx == 0) break;\n        n += nx;\n      }\n    }\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for short strings\n*/\nconst TValue *luaH_getshortstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  lua_assert(key->tt == LUA_TSHRSTR);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    const TValue *k = gkey(n);\n    if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\n/*\n** \"Generic\" get version. (Not that generic: not valid for integers,\n** which may be in array part, nor for floats with integral values.)\n*/\nstatic const TValue *getgeneric (Table *t, const TValue *key) {\n  Node *n = mainposition(t, key);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (luaV_rawequalobj(gkey(n), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  if (key->tt == LUA_TSHRSTR)\n    return luaH_getshortstr(t, key);\n  else {  /* for long strings, use generic case */\n    TValue ko;\n    setsvalue(cast(lua_State *, NULL), &ko, key);\n    return getgeneric(t, &ko);\n  }\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));\n    case LUA_TNUMINT: return luaH_getint(t, ivalue(key));\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TNUMFLT: {\n      lua_Integer k;\n      if (luaV_tointeger(key, &k, 0)) /* index is int? */\n        return luaH_getint(t, k);  /* use specialized version */\n      /* else... */\n    }  /* FALLTHROUGH */\n    default:\n      return getgeneric(t, key);\n  }\n}\n\n\n/*\n** beware: when using this function you probably need to check a GC\n** barrier and invalidate the TM cache.\n*/\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else return luaH_newkey(L, t, key);\n}\n\n\nvoid luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {\n  const TValue *p = luaH_getint(t, key);\n  TValue *cell;\n  if (p != luaO_nilobject)\n    cell = cast(TValue *, p);\n  else {\n    TValue k;\n    setivalue(&k, key);\n    cell = luaH_newkey(L, t, &k);\n  }\n  setobj2t(L, cell, value);\n}\n\n\nstatic int unbound_search (Table *t, unsigned int j) {\n  unsigned int i = j;  /* i is zero or a present index */\n  j++;\n  /* find 'i' and 'j' such that i is present and j is not */\n  while (!ttisnil(luaH_getint(t, j))) {\n    i = j;\n    if (j > cast(unsigned int, MAX_INT)/2) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getint(t, i))) i++;\n      return i - 1;\n    }\n    j *= 2;\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    unsigned int m = (i+j)/2;\n    if (ttisnil(luaH_getint(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table 't'. A 'boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nint luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (isdummy(t))  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (const Table *t) { return isdummy(t); }\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n\n/* 'const' to avoid wrong writings that can mess up field 'next' */\n#define gkey(n)\t\tcast(const TValue*, (&(n)->i_key.tvk))\n\n/*\n** writable version of 'gkey'; allows updates to individual fields,\n** but not to the whole (which has incompatible type)\n*/\n#define wgkey(n)\t\t(&(n)->i_key.nk)\n\n#define invalidateTMcache(t)\t((t)->flags = 0)\n\n\n/* true when 't' is using 'dummynode' as its hash part */\n#define isdummy(t)\t\t((t)->lastfree == NULL)\n\n\n/* allocated size for hash nodes */\n#define allocsizenode(t)\t(isdummy(t) ? 0 : sizenode(t))\n\n\n/* returns the key, given the value of a table entry */\n#define keyfromval(v) \\\n  (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))\n\n\nLUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);\nLUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,\n                                                    TValue *value);\nLUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L);\nLUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                                    unsigned int nhsize);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC int luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (const Table *t);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** Operations that an object must define to mimic a table\n** (some functions only need some of them)\n*/\n#define TAB_R\t1\t\t\t/* read */\n#define TAB_W\t2\t\t\t/* write */\n#define TAB_L\t4\t\t\t/* length */\n#define TAB_RW\t(TAB_R | TAB_W)\t\t/* read/write */\n\n\n#define aux_getn(L,n,w)\t(checktab(L, n, (w) | TAB_L), luaL_len(L, n))\n\n\nstatic int checkfield (lua_State *L, const char *key, int n) {\n  lua_pushstring(L, key);\n  return (lua_rawget(L, -n) != LUA_TNIL);\n}\n\n\n/*\n** Check that 'arg' either is a table or can behave like one (that is,\n** has a metatable with the required metamethods)\n*/\nstatic void checktab (lua_State *L, int arg, int what) {\n  if (lua_type(L, arg) != LUA_TTABLE) {  /* is it not a table? */\n    int n = 1;  /* number of elements to pop */\n    if (lua_getmetatable(L, arg) &&  /* must have metatable */\n        (!(what & TAB_R) || checkfield(L, \"__index\", ++n)) &&\n        (!(what & TAB_W) || checkfield(L, \"__newindex\", ++n)) &&\n        (!(what & TAB_L) || checkfield(L, \"__len\", ++n))) {\n      lua_pop(L, n);  /* pop metatable and tested metamethods */\n    }\n    else\n      luaL_checktype(L, arg, LUA_TTABLE);  /* force an error */\n  }\n}\n\n\n#if defined(LUA_COMPAT_MAXN)\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n#endif\n\n\nstatic int tinsert (lua_State *L) {\n  lua_Integer e = aux_getn(L, 1, TAB_RW) + 1;  /* first empty element */\n  lua_Integer pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      lua_Integer i;\n      pos = luaL_checkinteger(L, 2);  /* 2nd argument is the position */\n      luaL_argcheck(L, 1 <= pos && pos <= e, 2, \"position out of bounds\");\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_geti(L, 1, i - 1);\n        lua_seti(L, 1, i);  /* t[i] = t[i - 1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to 'insert'\");\n    }\n  }\n  lua_seti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  lua_Integer size = aux_getn(L, 1, TAB_RW);\n  lua_Integer pos = luaL_optinteger(L, 2, size);\n  if (pos != size)  /* validate 'pos' if given */\n    luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, \"position out of bounds\");\n  lua_geti(L, 1, pos);  /* result = t[pos] */\n  for ( ; pos < size; pos++) {\n    lua_geti(L, 1, pos + 1);\n    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */\n  }\n  lua_pushnil(L);\n  lua_seti(L, 1, pos);  /* t[pos] = nil */\n  return 1;\n}\n\n\n/*\n** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever\n** possible, copy in increasing order, which is better for rehashing.\n** \"possible\" means destination after original range, or smaller\n** than origin, or copying to another table.\n*/\nstatic int tmove (lua_State *L) {\n  lua_Integer f = luaL_checkinteger(L, 2);\n  lua_Integer e = luaL_checkinteger(L, 3);\n  lua_Integer t = luaL_checkinteger(L, 4);\n  int tt = !lua_isnoneornil(L, 5) ? 5 : 1;  /* destination table */\n  checktab(L, 1, TAB_R);\n  checktab(L, tt, TAB_W);\n  if (e >= f) {  /* otherwise, nothing to move */\n    lua_Integer n, i;\n    luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,\n                  \"too many elements to move\");\n    n = e - f + 1;  /* number of elements to move */\n    luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,\n                  \"destination wrap around\");\n    if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {\n      for (i = 0; i < n; i++) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n    else {\n      for (i = n - 1; i >= 0; i--) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n  }\n  lua_pushvalue(L, tt);  /* return destination table */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {\n  lua_geti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for 'concat'\",\n                  luaL_typename(L, -1), i);\n  luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  lua_Integer last = aux_getn(L, 1, TAB_R);\n  size_t lsep;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  lua_Integer i = luaL_optinteger(L, 3, 1);\n  last = luaL_optinteger(L, 4, last);\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Pack/unpack\n** =======================================================\n*/\n\nstatic int pack (lua_State *L) {\n  int i;\n  int n = lua_gettop(L);  /* number of elements to pack */\n  lua_createtable(L, n, 1);  /* create result table */\n  lua_insert(L, 1);  /* put it at index 1 */\n  for (i = n; i >= 1; i--)  /* assign elements */\n    lua_seti(L, 1, i);\n  lua_pushinteger(L, n);\n  lua_setfield(L, 1, \"n\");  /* t.n = number of elements */\n  return 1;  /* return table */\n}\n\n\nstatic int unpack (lua_State *L) {\n  lua_Unsigned n;\n  lua_Integer i = luaL_optinteger(L, 2, 1);\n  lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */\n  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, (int)(++n)))\n    return luaL_error(L, \"too many results to unpack\");\n  for (; i < e; i++) {  /* push arg[i..e - 1] (to avoid overflows) */\n    lua_geti(L, 1, i);\n  }\n  lua_geti(L, 1, e);  /* push last element */\n  return (int)n;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on 'Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n** =======================================================\n*/\n\n\n/* type for array indices */\ntypedef unsigned int IdxT;\n\n\n/*\n** Produce a \"random\" 'unsigned int' to randomize pivot choice. This\n** macro is used only when 'sort' detects a big imbalance in the result\n** of a partition. (If you don't want/need this \"randomness\", ~0 is a\n** good choice.)\n*/\n#if !defined(l_randomizePivot)\t\t/* { */\n\n#include <time.h>\n\n/* size of 'e' measured in number of 'unsigned int's */\n#define sof(e)\t\t(sizeof(e) / sizeof(unsigned int))\n\n/*\n** Use 'time' and 'clock' as sources of \"randomness\". Because we don't\n** know the types 'clock_t' and 'time_t', we cannot cast them to\n** anything without risking overflows. A safe way to use their values\n** is to copy them to an array of a known type and use the array values.\n*/\nstatic unsigned int l_randomizePivot (void) {\n  clock_t c = clock();\n  time_t t = time(NULL);\n  unsigned int buff[sof(c) + sof(t)];\n  unsigned int i, rnd = 0;\n  memcpy(buff, &c, sof(c) * sizeof(unsigned int));\n  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));\n  for (i = 0; i < sof(buff); i++)\n    rnd += buff[i];\n  return rnd;\n}\n\n#endif\t\t\t\t\t/* } */\n\n\n/* arrays larger than 'RANLIMIT' may use randomized pivots */\n#define RANLIMIT\t100u\n\n\nstatic void set2 (lua_State *L, IdxT i, IdxT j) {\n  lua_seti(L, 1, i);\n  lua_seti(L, 1, j);\n}\n\n\n/*\n** Return true iff value at stack index 'a' is less than the value at\n** index 'b' (according to the order of the sort).\n*/\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (lua_isnil(L, 2))  /* no function? */\n    return lua_compare(L, a, b, LUA_OPLT);  /* a < b */\n  else {  /* function */\n    int res;\n    lua_pushvalue(L, 2);    /* push function */\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and 'a' */\n    lua_call(L, 2, 1);      /* call function */\n    res = lua_toboolean(L, -1);  /* get result */\n    lua_pop(L, 1);          /* pop result */\n    return res;\n  }\n}\n\n\n/*\n** Does the partition: Pivot P is at the top of the stack.\n** precondition: a[lo] <= P == a[up-1] <= a[up],\n** so it only needs to do the partition from lo + 1 to up - 2.\n** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]\n** returns 'i'.\n*/\nstatic IdxT partition (lua_State *L, IdxT lo, IdxT up) {\n  IdxT i = lo;  /* will be incremented before first use */\n  IdxT j = up - 1;  /* will be decremented before first use */\n  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */\n  for (;;) {\n    /* next loop: repeat ++i while a[i] < P */\n    while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {\n      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[i] */\n    }\n    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */\n    /* next loop: repeat --j while P < a[j] */\n    while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {\n      if (j < i)  /* j < i  but  a[j] > P ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[j] */\n    }\n    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */\n    if (j < i) {  /* no elements out of place? */\n      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */\n      lua_pop(L, 1);  /* pop a[j] */\n      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */\n      set2(L, up - 1, i);\n      return i;\n    }\n    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */\n    set2(L, i, j);\n  }\n}\n\n\n/*\n** Choose an element in the middle (2nd-3th quarters) of [lo,up]\n** \"randomized\" by 'rnd'\n*/\nstatic IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {\n  IdxT r4 = (up - lo) / 4;  /* range/4 */\n  IdxT p = rnd % (r4 * 2) + (lo + r4);\n  lua_assert(lo + r4 <= p && p <= up - r4);\n  return p;\n}\n\n\n/*\n** QuickSort algorithm (recursive function)\n*/\nstatic void auxsort (lua_State *L, IdxT lo, IdxT up,\n                                   unsigned int rnd) {\n  while (lo < up) {  /* loop for tail recursion */\n    IdxT p;  /* Pivot index */\n    IdxT n;  /* to be used later */\n    /* sort elements 'lo', 'p', and 'up' */\n    lua_geti(L, 1, lo);\n    lua_geti(L, 1, up);\n    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */\n      set2(L, lo, up);  /* swap a[lo] - a[up] */\n    else\n      lua_pop(L, 2);  /* remove both values */\n    if (up - lo == 1)  /* only 2 elements? */\n      return;  /* already sorted */\n    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */\n      p = (lo + up)/2;  /* middle element is a good pivot */\n    else  /* for larger intervals, it is worth a random pivot */\n      p = choosePivot(lo, up, rnd);\n    lua_geti(L, 1, p);\n    lua_geti(L, 1, lo);\n    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */\n      set2(L, p, lo);  /* swap a[p] - a[lo] */\n    else {\n      lua_pop(L, 1);  /* remove a[lo] */\n      lua_geti(L, 1, up);\n      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */\n        set2(L, p, up);  /* swap a[up] - a[p] */\n      else\n        lua_pop(L, 2);\n    }\n    if (up - lo == 2)  /* only 3 elements? */\n      return;  /* already sorted */\n    lua_geti(L, 1, p);  /* get middle element (Pivot) */\n    lua_pushvalue(L, -1);  /* push Pivot */\n    lua_geti(L, 1, up - 1);  /* push a[up - 1] */\n    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */\n    p = partition(L, lo, up);\n    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */\n    if (p - lo < up - p) {  /* lower interval is smaller? */\n      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */\n      n = p - lo;  /* size of smaller interval */\n      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */\n    }\n    else {\n      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */\n      n = up - p;  /* size of smaller interval */\n      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */\n    }\n    if ((up - lo) / 128 > n) /* partition too imbalanced? */\n      rnd = l_randomizePivot();  /* try a new randomization */\n  }  /* tail call auxsort(L, lo, up, rnd) */\n}\n\n\nstatic int sort (lua_State *L) {\n  lua_Integer n = aux_getn(L, 1, TAB_RW);\n  if (n > 1) {  /* non-trivial interval? */\n    luaL_argcheck(L, n < INT_MAX, 1, \"array too big\");\n    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */\n    lua_settop(L, 2);  /* make sure there are two arguments */\n    auxsort(L, 1, (IdxT)n, 0);\n  }\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n#if defined(LUA_COMPAT_MAXN)\n  {\"maxn\", maxn},\n#endif\n  {\"insert\", tinsert},\n  {\"pack\", pack},\n  {\"unpack\", unpack},\n  {\"remove\", tremove},\n  {\"move\", tmove},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_table (lua_State *L) {\n  luaL_newlib(L, tab_funcs);\n#if defined(LUA_COMPAT_UNPACK)\n  /* _G.unpack = table.unpack */\n  lua_getfield(L, -1, \"unpack\");\n  lua_setglobal(L, \"unpack\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.38 2016/12/22 13:08:50 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\nstatic const char udatatypename[] = \"userdata\";\n\nLUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {\n  \"no value\",\n  \"nil\", \"boolean\", udatatypename, \"number\",\n  \"string\", \"table\", \"function\", udatatypename, \"thread\",\n  \"proto\" /* this last case is used for tests only */\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__len\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__mod\", \"__pow\",\n    \"__div\", \"__idiv\",\n    \"__band\", \"__bor\", \"__bxor\", \"__shl\", \"__shr\",\n    \"__unm\", \"__bnot\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaC_fix(L, obj2gco(G(L)->tmname[i]));  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getshortstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttnov(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(o)];\n  }\n  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n\n/*\n** Return the name of the type of an object. For tables and userdata\n** with metatable, use their '__name' metafield, if present.\n*/\nconst char *luaT_objtypename (lua_State *L, const TValue *o) {\n  Table *mt;\n  if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||\n      (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {\n    const TValue *name = luaH_getshortstr(mt, luaS_new(L, \"__name\"));\n    if (ttisstring(name))  /* is '__name' a string? */\n      return getstr(tsvalue(name));  /* use it as type name */\n  }\n  return ttypename(ttnov(o));  /* else use standard type name */\n}\n\n\nvoid luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                  const TValue *p2, TValue *p3, int hasres) {\n  ptrdiff_t result = savestack(L, p3);\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  L->top += 3;\n  if (!hasres)  /* no result? 'p3' is third argument */\n    setobj2s(L, L->top++, p3);  /* 3rd argument */\n  /* metamethod may yield only when called from Lua code */\n  if (isLua(L->ci))\n    luaD_call(L, func, hasres);\n  else\n    luaD_callnoyield(L, func, hasres);\n  if (hasres) {  /* if has result, move it to its place */\n    p3 = restorestack(L, result);\n    setobjs2s(L, p3, --L->top);\n  }\n}\n\n\nint luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  luaT_callTM(L, tm, p1, p2, res, 1);\n  return 1;\n}\n\n\nvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, res, event)) {\n    switch (event) {\n      case TM_CONCAT:\n        luaG_concaterror(L, p1, p2);\n      /* call never returns, but to avoid warnings: *//* FALLTHROUGH */\n      case TM_BAND: case TM_BOR: case TM_BXOR:\n      case TM_SHL: case TM_SHR: case TM_BNOT: {\n        lua_Number dummy;\n        if (tonumber(p1, &dummy) && tonumber(p2, &dummy))\n          luaG_tointerror(L, p1, p2);\n        else\n          luaG_opinterror(L, p1, p2, \"perform bitwise operation on\");\n      }\n      /* calls never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:\n        luaG_opinterror(L, p1, p2, \"perform arithmetic on\");\n    }\n  }\n}\n\n\nint luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, L->top, event))\n    return -1;  /* no metamethod */\n  else\n    return !l_isfalse(L->top);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\" and \"ORDER OP\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_LEN,\n  TM_EQ,  /* last tag method with fast access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_MOD,\n  TM_POW,\n  TM_DIV,\n  TM_IDIV,\n  TM_BAND,\n  TM_BOR,\n  TM_BXOR,\n  TM_SHL,\n  TM_SHR,\n  TM_UNM,\n  TM_BNOT,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\n#define ttypename(x)\tluaT_typenames_[(x) + 1]\n\nLUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];\n\n\nLUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\nLUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                            const TValue *p2, TValue *p3, int hasres);\nLUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,\n                                const TValue *p2, TMS event);\n\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.230 2017/01/12 17:14:26 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n#define lua_c\n\n#include \"lprefix.h\"\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n#if !defined(LUA_PROMPT)\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n#endif\n\n#if !defined(LUA_PROGNAME)\n#define LUA_PROGNAME\t\t\"lua\"\n#endif\n\n#if !defined(LUA_MAXINPUT)\n#define LUA_MAXINPUT\t\t512\n#endif\n\n#if !defined(LUA_INIT_VAR)\n#define LUA_INIT_VAR\t\t\"LUA_INIT\"\n#endif\n\n#define LUA_INITVARVERSION\tLUA_INIT_VAR LUA_VERSUFFIX\n\n\n/*\n** lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n** is, whether we're running lua interactively).\n*/\n#if !defined(lua_stdin_is_tty)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#include <io.h>\n#include <windows.h>\n\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definition */\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** lua_readline defines how to show a prompt and then read a line from\n** the standard input.\n** lua_saveline defines how to \"save\" a read line in a \"history\".\n** lua_freeline defines how to free a line read by lua_readline.\n*/\n#if !defined(lua_readline)\t/* { */\n\n#if defined(LUA_USE_READLINE)\t/* { */\n\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,line)\t((void)L, add_history(line))\n#define lua_freeline(L,b)\t((void)L, free(b))\n\n#else\t\t\t\t/* }{ */\n\n#define lua_readline(L,b,p) \\\n        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,line)\t{ (void)L; (void)line; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n/*\n** Hook set by signal function to stop the interpreter.\n*/\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);  /* reset hook */\n  luaL_error(L, \"interrupted!\");\n}\n\n\n/*\n** Function to be called at a C signal. Because a C signal cannot\n** just change a Lua state (as there is no proper synchronization),\n** this function only sets a hook that, when called, will stop the\n** interpreter.\n*/\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (const char *badoption) {\n  lua_writestringerror(\"%s: \", progname);\n  if (badoption[1] == 'e' || badoption[1] == 'l')\n    lua_writestringerror(\"'%s' needs argument\\n\", badoption);\n  else\n    lua_writestringerror(\"unrecognized option '%s'\\n\", badoption);\n  lua_writestringerror(\n  \"usage: %s [options] [script [args]]\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string 'stat'\\n\"\n  \"  -i       enter interactive mode after executing 'script'\\n\"\n  \"  -l name  require library 'name'\\n\"\n  \"  -v       show version information\\n\"\n  \"  -E       ignore environment variables\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and execute stdin\\n\"\n  ,\n  progname);\n}\n\n\n/*\n** Prints an error message, adding the program name in front of it\n** (if present)\n*/\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) lua_writestringerror(\"%s: \", pname);\n  lua_writestringerror(\"%s\\n\", msg);\n}\n\n\n/*\n** Check whether 'status' is not OK and, if so, prints the error\n** message on the top of the stack. It assumes that the error object\n** is a string, as it was either generated by Lua or by 'msghandler'.\n*/\nstatic int report (lua_State *L, int status) {\n  if (status != LUA_OK) {\n    const char *msg = lua_tostring(L, -1);\n    l_message(progname, msg);\n    lua_pop(L, 1);  /* remove message */\n  }\n  return status;\n}\n\n\n/*\n** Message handler used to run all chunks\n*/\nstatic int msghandler (lua_State *L) {\n  const char *msg = lua_tostring(L, 1);\n  if (msg == NULL) {  /* is error object not a string? */\n    if (luaL_callmeta(L, 1, \"__tostring\") &&  /* does it have a metamethod */\n        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */\n      return 1;  /* that is the message */\n    else\n      msg = lua_pushfstring(L, \"(error object is a %s value)\",\n                               luaL_typename(L, 1));\n  }\n  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */\n  return 1;  /* return the traceback */\n}\n\n\n/*\n** Interface to 'lua_pcall', which sets appropriate message function\n** and C-signal handler. Used to run all chunks.\n*/\nstatic int docall (lua_State *L, int narg, int nres) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, msghandler);  /* push message handler */\n  lua_insert(L, base);  /* put it under function and args */\n  globalL = L;  /* to be available to 'laction' */\n  signal(SIGINT, laction);  /* set C-signal handler */\n  status = lua_pcall(L, narg, nres, base);\n  signal(SIGINT, SIG_DFL); /* reset C-signal handler */\n  lua_remove(L, base);  /* remove message handler from the stack */\n  return status;\n}\n\n\nstatic void print_version (void) {\n  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));\n  lua_writeline();\n}\n\n\n/*\n** Create the 'arg' table, which stores all arguments from the\n** command line ('argv'). It should be aligned so that, at index 0,\n** it has 'argv[script]', which is the script name. The arguments\n** to the script (everything after 'script') go to positive indices;\n** other arguments (before the script name) go to negative indices.\n** If there is no script name, assume interpreter's name as base.\n*/\nstatic void createargtable (lua_State *L, char **argv, int argc, int script) {\n  int i, narg;\n  if (script == argc) script = 0;  /* no script name? */\n  narg = argc - (script + 1);  /* number of positive indices */\n  lua_createtable(L, narg, script + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - script);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\n\nstatic int dochunk (lua_State *L, int status) {\n  if (status == LUA_OK) status = docall(L, 0, 0);\n  return report(L, status);\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  return dochunk(L, luaL_loadfile(L, name));\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));\n}\n\n\n/*\n** Calls 'require(name)' and stores the result in a global variable\n** with the given name.\n*/\nstatic int dolibrary (lua_State *L, const char *name) {\n  int status;\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  status = docall(L, 1, 1);  /* call 'require(name)' */\n  if (status == LUA_OK)\n    lua_setglobal(L, name);  /* global[name] = require return */\n  return report(L, status);\n}\n\n\n/*\n** Returns the string to be used as a prompt by the interpreter.\n*/\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getglobal(L, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  return p;\n}\n\n/* mark in error messages for incomplete statements */\n#define EOFMARK\t\t\"<eof>\"\n#define marklen\t\t(sizeof(EOFMARK)/sizeof(char) - 1)\n\n\n/*\n** Check whether 'status' signals a syntax error and the error\n** message at the top of the stack ends with the above mark for\n** incomplete statements.\n*/\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\n/*\n** Prompt the user, read a line, and push it into the Lua stack.\n*/\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  int readstatus = lua_readline(L, b, prmt);\n  if (readstatus == 0)\n    return 0;  /* no input (prompt will be popped by caller) */\n  lua_pop(L, 1);  /* remove prompt */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[--l] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */\n    lua_pushfstring(L, \"return %s\", b + 1);  /* change '=' to 'return' */\n  else\n    lua_pushlstring(L, b, l);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\n/*\n** Try to compile line on the stack as 'return <line>;'; on return, stack\n** has either compiled chunk or original line (if compilation failed).\n*/\nstatic int addreturn (lua_State *L) {\n  const char *line = lua_tostring(L, -1);  /* original line */\n  const char *retline = lua_pushfstring(L, \"return %s;\", line);\n  int status = luaL_loadbuffer(L, retline, strlen(retline), \"=stdin\");\n  if (status == LUA_OK) {\n    lua_remove(L, -2);  /* remove modified line */\n    if (line[0] != '\\0')  /* non empty? */\n      lua_saveline(L, line);  /* keep history */\n  }\n  else\n    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */\n  return status;\n}\n\n\n/*\n** Read multiple lines until a complete Lua statement\n*/\nstatic int multiline (lua_State *L) {\n  for (;;) {  /* repeat until gets a complete statement */\n    size_t len;\n    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */\n    int status = luaL_loadbuffer(L, line, len, \"=stdin\");  /* try it */\n    if (!incomplete(L, status) || !pushline(L, 0)) {\n      lua_saveline(L, line);  /* keep history */\n      return status;  /* cannot or should not try to add continuation line */\n    }\n    lua_pushliteral(L, \"\\n\");  /* add newline... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n}\n\n\n/*\n** Read a line and try to load (compile) it first as an expression (by\n** adding \"return \" in front of it) and second as a statement. Return\n** the final status of load/call with the resulting function (if any)\n** in the top of the stack.\n*/\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */\n    status = multiline(L);  /* try as command, maybe with continuation lines */\n  lua_remove(L, 1);  /* remove line from the stack */\n  lua_assert(lua_gettop(L) == 1);\n  return status;\n}\n\n\n/*\n** Prints (calling the Lua 'print' function) any values on the stack\n*/\nstatic void l_print (lua_State *L) {\n  int n = lua_gettop(L);\n  if (n > 0) {  /* any result to be printed? */\n    luaL_checkstack(L, LUA_MINSTACK, \"too many results to print\");\n    lua_getglobal(L, \"print\");\n    lua_insert(L, 1);\n    if (lua_pcall(L, n, 0, 0) != LUA_OK)\n      l_message(progname, lua_pushfstring(L, \"error calling 'print' (%s)\",\n                                             lua_tostring(L, -1)));\n  }\n}\n\n\n/*\n** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and\n** print any results.\n*/\nstatic void doREPL (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;  /* no 'progname' on errors in interactive mode */\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK)\n      status = docall(L, 0, LUA_MULTRET);\n    if (status == LUA_OK) l_print(L);\n    else report(L, status);\n  }\n  lua_settop(L, 0);  /* clear stack */\n  lua_writeline();\n  progname = oldprogname;\n}\n\n\n/*\n** Push on the stack the contents of table 'arg' from 1 to #arg\n*/\nstatic int pushargs (lua_State *L) {\n  int i, n;\n  if (lua_getglobal(L, \"arg\") != LUA_TTABLE)\n    luaL_error(L, \"'arg' is not a table\");\n  n = (int)luaL_len(L, -1);\n  luaL_checkstack(L, n + 3, \"too many arguments to script\");\n  for (i = 1; i <= n; i++)\n    lua_rawgeti(L, -i, i);\n  lua_remove(L, -i);  /* remove table from the stack */\n  return n;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv) {\n  int status;\n  const char *fname = argv[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    int n = pushargs(L);  /* push arguments to script */\n    status = docall(L, n, LUA_MULTRET);\n  }\n  return report(L, status);\n}\n\n\n\n/* bits of various argument indicators in 'args' */\n#define has_error\t1\t/* bad option */\n#define has_i\t\t2\t/* -i */\n#define has_v\t\t4\t/* -v */\n#define has_e\t\t8\t/* -e */\n#define has_E\t\t16\t/* -E */\n\n/*\n** Traverses all arguments from 'argv', returning a mask with those\n** needed before running any Lua code (or an error code if it finds\n** any invalid argument). 'first' returns the first not-handled argument\n** (either the script name or a bad argument in case of error).\n*/\nstatic int collectargs (char **argv, int *first) {\n  int args = 0;\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    *first = i;\n    if (argv[i][0] != '-')  /* not an option? */\n        return args;  /* stop handling options */\n    switch (argv[i][1]) {  /* else check option */\n      case '-':  /* '--' */\n        if (argv[i][2] != '\\0')  /* extra characters after '--'? */\n          return has_error;  /* invalid option */\n        *first = i + 1;\n        return args;\n      case '\\0':  /* '-' */\n        return args;  /* script \"name\" is '-' */\n      case 'E':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_E;\n        break;\n      case 'i':\n        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */\n      case 'v':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_v;\n        break;\n      case 'e':\n        args |= has_e;  /* FALLTHROUGH */\n      case 'l':  /* both options need an argument */\n        if (argv[i][2] == '\\0') {  /* no concatenated argument? */\n          i++;  /* try next 'argv' */\n          if (argv[i] == NULL || argv[i][0] == '-')\n            return has_error;  /* no next argument or it is another option */\n        }\n        break;\n      default:  /* invalid option */\n        return has_error;\n    }\n  }\n  *first = i;  /* no script name */\n  return args;\n}\n\n\n/*\n** Processes options 'e' and 'l', which involve running Lua code.\n** Returns 0 if some code raises an error.\n*/\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    int option = argv[i][1];\n    lua_assert(argv[i][0] == '-');  /* already checked */\n    if (option == 'e' || option == 'l') {\n      int status;\n      const char *extra = argv[i] + 2;  /* both options need an argument */\n      if (*extra == '\\0') extra = argv[++i];\n      lua_assert(extra != NULL);\n      status = (option == 'e')\n               ? dostring(L, extra, \"=(command line)\")\n               : dolibrary(L, extra);\n      if (status != LUA_OK) return 0;\n    }\n  }\n  return 1;\n}\n\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *name = \"=\" LUA_INITVARVERSION;\n  const char *init = getenv(name + 1);\n  if (init == NULL) {\n    name = \"=\" LUA_INIT_VAR;\n    init = getenv(name + 1);  /* try alternative name */\n  }\n  if (init == NULL) return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, name);\n}\n\n\n/*\n** Main body of stand-alone interpreter (to be called in protected mode).\n** Reads the options and handles them all.\n*/\nstatic int pmain (lua_State *L) {\n  int argc = (int)lua_tointeger(L, 1);\n  char **argv = (char **)lua_touserdata(L, 2);\n  int script;\n  int args = collectargs(argv, &script);\n  luaL_checkversion(L);  /* check that interpreter has correct version */\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  if (args == has_error) {  /* bad arg? */\n    print_usage(argv[script]);  /* 'script' has index of bad arg. */\n    return 0;\n  }\n  if (args & has_v)  /* option '-v'? */\n    print_version();\n  if (args & has_E) {  /* option '-E'? */\n    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  luaL_openlibs(L);  /* open standard libraries */\n  createargtable(L, argv, argc, script);  /* create table 'arg' */\n  if (!(args & has_E)) {  /* no option '-E'? */\n    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */\n      return 0;  /* error running LUA_INIT */\n  }\n  if (!runargs(L, argv, script))  /* execute arguments -e and -l */\n    return 0;  /* something failed */\n  if (script < argc &&  /* execute main script (if there is one) */\n      handle_script(L, argv + script) != LUA_OK)\n    return 0;\n  if (args & has_i)  /* -i option? */\n    doREPL(L);  /* do read-eval-print loop */\n  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */\n    if (lua_stdin_is_tty()) {  /* running in interactive mode? */\n      print_version();\n      doREPL(L);  /* do read-eval-print loop */\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  lua_pushboolean(L, 1);  /* signal no errors */\n  return 1;\n}\n\n\nint main (int argc, char **argv) {\n  int status, result;\n  lua_State *L = luaL_newstate();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */\n  lua_pushinteger(L, argc);  /* 1st argument */\n  lua_pushlightuserdata(L, argv); /* 2nd argument */\n  status = lua_pcall(L, 2, 1, 0);  /* do the call */\n  result = lua_toboolean(L, -1);  /* get result */\n  report(L, status);\n  lua_close(L);\n  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.332 2016/12/22 15:51:20 roberto Exp $\n** Lua - A Scripting Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION_MAJOR\t\"5\"\n#define LUA_VERSION_MINOR\t\"3\"\n#define LUA_VERSION_NUM\t\t503\n#define LUA_VERSION_RELEASE\t\"4\"\n\n#define LUA_VERSION\t\"Lua \" LUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#define LUA_RELEASE\tLUA_VERSION \".\" LUA_VERSION_RELEASE\n#define LUA_COPYRIGHT\tLUA_RELEASE \"  Copyright (C) 1994-2017 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo, W. Celes\"\n\n\n/* mark for precompiled code ('<esc>Lua') */\n#define LUA_SIGNATURE\t\"\\x1bLua\"\n\n/* option for multiple returns in 'lua_pcall' and 'lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** Pseudo-indices\n** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty\n** space after that to help overflow detection)\n*/\n#define LUA_REGISTRYINDEX\t(-LUAI_MAXSTACK - 1000)\n#define lua_upvalueindex(i)\t(LUA_REGISTRYINDEX - (i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRGCMM\t5\n#define LUA_ERRERR\t6\n\n\ntypedef struct lua_State lua_State;\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n#define LUA_NUMTAGS\t\t9\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/* predefined values in the registry */\n#define LUA_RIDX_MAINTHREAD\t1\n#define LUA_RIDX_GLOBALS\t2\n#define LUA_RIDX_LAST\t\tLUA_RIDX_GLOBALS\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n/* unsigned integer type */\ntypedef LUA_UNSIGNED lua_Unsigned;\n\n/* type for continuation-function contexts */\ntypedef LUA_KCONTEXT lua_KContext;\n\n\n/*\n** Type for C functions registered with Lua\n*/\ntypedef int (*lua_CFunction) (lua_State *L);\n\n/*\n** Type for continuation functions\n*/\ntypedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);\n\n\n/*\n** Type for functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);\n\n\n/*\n** Type for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/*\n** RCS ident string\n*/\nextern const char lua_ident[];\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\nLUA_API const lua_Number *(lua_version) (lua_State *L);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_absindex) (lua_State *L, int idx);\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_rotate) (lua_State *L, int idx, int n);\nLUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);\nLUA_API int   (lua_checkstack) (lua_State *L, int n);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isinteger) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_rawlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** Comparison and arithmetic functions\n*/\n\n#define LUA_OPADD\t0\t/* ORDER TM, ORDER OP */\n#define LUA_OPSUB\t1\n#define LUA_OPMUL\t2\n#define LUA_OPMOD\t3\n#define LUA_OPPOW\t4\n#define LUA_OPDIV\t5\n#define LUA_OPIDIV\t6\n#define LUA_OPBAND\t7\n#define LUA_OPBOR\t8\n#define LUA_OPBXOR\t9\n#define LUA_OPSHL\t10\n#define LUA_OPSHR\t11\n#define LUA_OPUNM\t12\n#define LUA_OPBNOT\t13\n\nLUA_API void  (lua_arith) (lua_State *L, int op);\n\n#define LUA_OPEQ\t0\n#define LUA_OPLT\t1\n#define LUA_OPLE\t2\n\nLUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void        (lua_pushnil) (lua_State *L);\nLUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);\nLUA_API const char *(lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API int (lua_getglobal) (lua_State *L, const char *name);\nLUA_API int (lua_gettable) (lua_State *L, int idx);\nLUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawget) (lua_State *L, int idx);\nLUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);\n\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API int  (lua_getuservalue) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_setglobal) (lua_State *L, const char *name);\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_seti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_setuservalue) (lua_State *L, int idx);\n\n\n/*\n** 'load' and 'call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,\n                           lua_KContext ctx, lua_KFunction k);\n#define lua_call(L,n,r)\t\tlua_callk(L, (n), (r), 0, NULL)\n\nLUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,\n                            lua_KContext ctx, lua_KFunction k);\n#define lua_pcall(L,n,r,f)\tlua_pcallk(L, (n), (r), (f), 0, NULL)\n\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                          const char *chunkname, const char *mode);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yieldk)     (lua_State *L, int nresults, lua_KContext ctx,\n                               lua_KFunction k);\nLUA_API int  (lua_resume)     (lua_State *L, lua_State *from, int narg);\nLUA_API int  (lua_status)     (lua_State *L);\nLUA_API int (lua_isyieldable) (lua_State *L);\n\n#define lua_yield(L,n)\t\tlua_yieldk(L, (n), 0, NULL)\n\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\nLUA_API void  (lua_len)    (lua_State *L, int idx);\n\nLUA_API size_t   (lua_stringtonumber) (lua_State *L, const char *s);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** {==============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_getextraspace(L)\t((void *)((char *)(L) - LUA_EXTRASPACE))\n\n#define lua_tonumber(L,i)\tlua_tonumberx(L,(i),NULL)\n#define lua_tointeger(L,i)\tlua_tointegerx(L,(i),NULL)\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\tlua_pushstring(L, \"\" s)\n\n#define lua_pushglobaltable(L)  \\\n\t((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n#define lua_insert(L,idx)\tlua_rotate(L, (idx), 1)\n\n#define lua_remove(L,idx)\t(lua_rotate(L, (idx), -1), lua_pop(L, 1))\n\n#define lua_replace(L,idx)\t(lua_copy(L, -1, (idx)), lua_pop(L, 1))\n\n/* }============================================================== */\n\n\n/*\n** {==============================================================\n** compatibility macros for unsigned conversions\n** ===============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define lua_pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define lua_tounsignedx(L,i,is)\t((lua_Unsigned)lua_tointegerx(L,i,is))\n#define lua_tounsigned(L,i)\tlua_tounsignedx(L,(i),NULL)\n\n#endif\n/* }============================================================== */\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILCALL 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debugger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);\nLUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);\nLUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);\n\nLUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);\nLUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,\n                                               int fidx2, int n2);\n\nLUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook (lua_gethook) (lua_State *L);\nLUA_API int (lua_gethookmask) (lua_State *L);\nLUA_API int (lua_gethookcount) (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) 'global', 'local', 'field', 'method' */\n  const char *what;\t/* (S) 'Lua', 'C', 'main', 'tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  unsigned char nups;\t/* (u) number of upvalues */\n  unsigned char nparams;/* (u) number of parameters */\n  char isvararg;        /* (u) */\n  char istailcall;\t/* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  struct CallInfo *i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2017 Lua.org, PUC-Rio.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "build/lua-5.3.4/src/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** Lua compiler (saves bytecodes to files; also lists bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\nstatic void PrintFunction(const Proto* f, int full);\n#define luaU_print\tPrintFunction\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define OUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option '%s'\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n  \"usage: %s [options] [filenames]\\n\"\n  \"Available options are:\\n\"\n  \"  -l       list (use -l -l for full listing)\\n\"\n  \"  -o name  output to file 'name' (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and process stdin\\n\"\n  ,progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define IS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))\n    usage(\"'-o' needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s\\n\",LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define FUNCTION \"(function()end)();\"\n\nstatic const char* reader(lua_State *L, void *ud, size_t *size)\n{\n UNUSED(L);\n if ((*(int*)ud)--)\n {\n  *size=sizeof(FUNCTION)-1;\n  return FUNCTION;\n }\n else\n {\n  *size=0;\n  return NULL;\n }\n}\n\n#define toproto(L,i) getproto(L->top+(i))\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  Proto* f;\n  int i=n;\n  if (lua_load(L,reader,&i,\"=(\" PROGNAME \")\",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));\n  f=toproto(L,-1);\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;\n  }\n  f->sizelineinfo=0;\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstatic int pmain(lua_State* L)\n{\n int argc=(int)lua_tointeger(L,1);\n char** argv=(char**)lua_touserdata(L,2);\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=luaL_newstate();\n if (L==NULL) fatal(\"cannot create state: not enough memory\");\n lua_pushcfunction(L,&pmain);\n lua_pushinteger(L,argc);\n lua_pushlightuserdata(L,argv);\n if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n\n/*\n** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=tsslen(ts);\n printf(\"%c\",'\"');\n for (i=0; i<n; i++)\n {\n  int c=(int)(unsigned char)s[i];\n  switch (c)\n  {\n   case '\"':  printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint(c))\n   \t\t\tprintf(\"%c\",c);\n\t\telse\n\t\t\tprintf(\"\\\\%03d\",c);\n  }\n }\n printf(\"%c\",'\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMFLT:\n\t{\n\tchar buff[100];\n\tsprintf(buff,LUA_NUMBER_FMT,fltvalue(o));\n\tprintf(\"%s\",buff);\n\tif (buff[strspn(buff,\"-0123456789\")]=='\\0') printf(\".0\");\n\tbreak;\n\t}\n  case LUA_TNUMINT:\n\tprintf(LUA_INTEGER_FMT,ivalue(o));\n\tbreak;\n  case LUA_TSHRSTR: case LUA_TLNGSTR:\n\tPrintString(tsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\n#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : \"-\")\n#define MYK(x)\t\t(-1-(x))\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int ax=GETARG_Ax(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getfuncline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (MYK(INDEXK(b))) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (MYK(INDEXK(c))) : c);\n    break;\n   case iABx:\n    printf(\"%d\",a);\n    if (getBMode(o)==OpArgK) printf(\" %d\",MYK(bx));\n    if (getBMode(o)==OpArgU) printf(\" %d\",bx);\n    break;\n   case iAsBx:\n    printf(\"%d %d\",a,sbx);\n    break;\n   case iAx:\n    printf(\"%d\",MYK(ax));\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    break;\n   case OP_GETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(a));\n    if (ISK(b)) { printf(\" \"); PrintConstant(f,INDEXK(b)); }\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_POW:\n   case OP_DIV:\n   case OP_IDIV:\n   case OP_BAND:\n   case OP_BOR:\n   case OP_BXOR:\n   case OP_SHL:\n   case OP_SHR:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n   case OP_TFORLOOP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]); else printf(\"\\t; %d\",c);\n    break;\n   case OP_EXTRAARG:\n    printf(\"\\t; \"); PrintConstant(f,ax);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t((x==1)?\"\":\"s\")\n#define S(x)\t(int)(x),SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=f->source ? getstr(f->source) : \"=?\";\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\t(int)(f->numparams),f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->sizeupvalues));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintDebug(const Proto* f)\n{\n int i,n;\n n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);\n }\n}\n\nstatic void PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full) PrintDebug(f);\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "build/lua-5.3.4/src/luaconf.h.in",
    "content": "/*\n** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ===================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n** {====================================================================\n** System Configuration: macros to adapt (if needed) Lua to some\n** particular platform, for instance compiling it with 32-bit numbers or\n** restricting it to C89.\n** =====================================================================\n*/\n\n/*\n@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You\n** can also define LUA_32BITS in the make file, but changing here you\n** ensure that all software connected to Lua will be compiled with the\n** same configuration.\n*/\n/* #define LUA_32BITS */\n\n\n/*\n@@ LUA_USE_C89 controls the use of non-ISO-C89 features.\n** Define it if you want Lua to avoid the use of a few C99 features\n** or Windows-specific features on Windows.\n*/\n/* #define LUA_USE_C89 */\n\n\n/*\n** By default, Lua on Windows use (some) specific Windows features\n*/\n#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)\n#define LUA_USE_WINDOWS  /* enable goodies for regular Windows */\n#endif\n\n\n#if defined(LUA_USE_WINDOWS)\n#if !defined(WINAPI_FAMILY_PARTITION)\n#define LUA_DL_DLL\t/* enable support for DLL */\n#endif\n#define LUA_USE_C89\t/* broadly, Windows is C89 */\n#endif\n\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* MacOS does not need -ldl */\n#define LUA_USE_READLINE\t/* needs an extra library: -lreadline */\n#endif\n\n\n/*\n@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for\n** C89 ('long' and 'double'); Windows always has '__int64', so it does\n** not need to use this case.\n*/\n#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)\n#define LUA_C89_NUMBERS\n#endif\n\n\n\n/*\n@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.\n*/\n/* avoid undefined shifts */\n#if ((INT_MAX >> 15) >> 15) >= 1\n#define LUAI_BITSINT\t32\n#else\n/* 'int' always must have at least 16 bits */\n#define LUAI_BITSINT\t16\n#endif\n\n\n/*\n@@ LUA_INT_TYPE defines the type for Lua integers.\n@@ LUA_FLOAT_TYPE defines the type for Lua floats.\n** Lua should work fine with any mix of these options (if supported\n** by your C compiler). The usual configurations are 64-bit integers\n** and 'double' (the default), 32-bit integers and 'float' (for\n** restricted platforms), and 'long'/'double' (for C compilers not\n** compliant with C99, which may not have support for 'long long').\n*/\n\n/* predefined options for LUA_INT_TYPE */\n#define LUA_INT_INT\t\t1\n#define LUA_INT_LONG\t\t2\n#define LUA_INT_LONGLONG\t3\n\n/* predefined options for LUA_FLOAT_TYPE */\n#define LUA_FLOAT_FLOAT\t\t1\n#define LUA_FLOAT_DOUBLE\t2\n#define LUA_FLOAT_LONGDOUBLE\t3\n\n#if defined(LUA_32BITS)\t\t/* { */\n/*\n** 32-bit integers and 'float'\n*/\n#if LUAI_BITSINT >= 32  /* use 'int' if big enough */\n#define LUA_INT_TYPE\tLUA_INT_INT\n#else  /* otherwise use 'long' */\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#endif\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT\n\n#elif defined(LUA_C89_NUMBERS)\t/* }{ */\n/*\n** largest types available for C89 ('long' and 'double')\n*/\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** default configuration for 64-bit Lua ('long long' and 'double')\n*/\n#if !defined(LUA_INT_TYPE)\n#define LUA_INT_TYPE\tLUA_INT_LONGLONG\n#endif\n\n#if !defined(LUA_FLOAT_TYPE)\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n#endif\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n** Configuration for Paths.\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n*/\n#define LUA_PATH_SEP            \";\"\n#define LUA_PATH_MARK           \"?\"\n#define LUA_EXEC_DIR            \"!\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n** Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n** C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#define LUA_VDIR\tLUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#if defined(_WIN32)\t/* { */\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_SHRDIR\t\"!\\\\..\\\\share\\\\lua\\\\\" LUA_VDIR \"\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua;\" \\\n\t\tLUA_SHRDIR\"?.lua;\" LUA_SHRDIR\"?\\\\init.lua;\" \\\n\t\t\".\\\\?.lua;\" \".\\\\?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.dll;\" \\\n\t\tLUA_CDIR\"..\\\\lib\\\\lua\\\\\" LUA_VDIR \"\\\\?.dll;\" \\\n\t\tLUA_CDIR\"loadall.dll;\" \".\\\\?.dll\"\n\n#else\t\t\t/* }{ */\n\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/\" LUA_VDIR \"/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/\" LUA_VDIR \"/\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua;\" \\\n\t\t\"./?.lua;\" \"./?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so;\" \"./?.so\"\n#endif\t\t\t/* } */\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Marks for exported symbols in the C code\n** ===================================================================\n*/\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all auxiliary library functions.\n@@ LUAMOD_API is a mark for all standard library opening functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\t/* { */\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\t/* { */\n#define LUA_API __declspec(dllexport)\n#else\t\t\t\t\t\t/* }{ */\n#define LUA_API __declspec(dllimport)\n#endif\t\t\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#define LUA_API\t\textern\n\n#endif\t\t\t\t/* } */\n\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n#define LUAMOD_API\tLUALIB_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n** exported to outside modules.\n@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables\n** that are not to be exported to outside modules (LUAI_DDEF for\n** definitions and LUAI_DDEC for declarations).\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library. Not all elf targets support\n** this attribute. Unfortunately, gcc does not offer a way to check\n** whether the target offers that support, and those without support\n** give a warning about it. To avoid these warnings, change to the\n** default definition.\n*/\n#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n    defined(__ELF__)\t\t/* { */\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#else\t\t\t\t/* }{ */\n#define LUAI_FUNC\textern\n#endif\t\t\t\t/* } */\n\n#define LUAI_DDEC\tLUAI_FUNC\n#define LUAI_DDEF\t/* empty */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Compatibility with previous versions\n** ===================================================================\n*/\n\n/*\n@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.\n@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.\n** You can define it to get all options, or change specific options\n** to fit your specific needs.\n*/\n#if defined(LUA_COMPAT_5_2)\t/* { */\n\n/*\n@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated\n** functions in the mathematical library.\n*/\n#define LUA_COMPAT_MATHLIB\n\n/*\n@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.\n*/\n#define LUA_COMPAT_BITLIB\n\n/*\n@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.\n*/\n#define LUA_COMPAT_IPAIRS\n\n/*\n@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for\n** manipulating other integer types (lua_pushunsigned, lua_tounsigned,\n** luaL_checkint, luaL_checklong, etc.)\n*/\n#define LUA_COMPAT_APIINTCASTS\n\n#endif\t\t\t\t/* } */\n\n\n#if defined(LUA_COMPAT_5_1)\t/* { */\n\n/* Incompatibilities from 5.2 -> 5.3 */\n#define LUA_COMPAT_MATHLIB\n#define LUA_COMPAT_APIINTCASTS\n\n/*\n@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.\n** You can replace it with 'table.unpack'.\n*/\n#define LUA_COMPAT_UNPACK\n\n/*\n@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.\n** You can replace it with 'package.searchers'.\n*/\n#define LUA_COMPAT_LOADERS\n\n/*\n@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.\n** You can call your C function directly (with light C functions).\n*/\n#define lua_cpcall(L,f,u)  \\\n\t(lua_pushcfunction(L, (f)), \\\n\t lua_pushlightuserdata(L,(u)), \\\n\t lua_pcall(L,1,0,0))\n\n\n/*\n@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.\n** You can rewrite 'log10(x)' as 'log(x, 10)'.\n*/\n#define LUA_COMPAT_LOG10\n\n/*\n@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base\n** library. You can rewrite 'loadstring(s)' as 'load(s)'.\n*/\n#define LUA_COMPAT_LOADSTRING\n\n/*\n@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.\n*/\n#define LUA_COMPAT_MAXN\n\n/*\n@@ The following macros supply trivial compatibility for some\n** changes in the API. The macros themselves document how to\n** change your code to avoid using them.\n*/\n#define lua_strlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_equal(L,idx1,idx2)\t\tlua_compare(L,(idx1),(idx2),LUA_OPEQ)\n#define lua_lessthan(L,idx1,idx2)\tlua_compare(L,(idx1),(idx2),LUA_OPLT)\n\n/*\n@@ LUA_COMPAT_MODULE controls compatibility with previous\n** module functions 'module' (Lua) and 'luaL_register' (C).\n*/\n#define LUA_COMPAT_MODULE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a\n@@ a float mark ('.0').\n** This macro is not on by default even in compatibility mode,\n** because this is not really an incompatibility.\n*/\n/* #define LUA_COMPAT_FLOATSTRING */\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Numbers.\n** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*\n** satisfy your needs.\n** ===================================================================\n*/\n\n/*\n@@ LUA_NUMBER is the floating-point type used by Lua.\n@@ LUAI_UACNUMBER is the result of a 'default argument promotion'\n@@ over a floating number.\n@@ l_mathlim(x) corrects limit name 'x' to the proper float type\n** by prefixing it with one of FLT/DBL/LDBL.\n@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.\n@@ LUA_NUMBER_FMT is the format for writing floats.\n@@ lua_number2str converts a float to a string.\n@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.\n@@ l_floor takes the floor of a float.\n@@ lua_str2number converts a decimal numeric string to a number.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define l_floor(x)\t\t(l_mathop(floor)(x))\n\n#define lua_number2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))\n\n/*\n@@ lua_numbertointeger converts a float number to an integer, or\n** returns 0 if float is not within the range of a lua_Integer.\n** (The range comparisons are tricky because of rounding. The tests\n** here assume a two-complement representation, where MININTEGER always\n** has an exact representation as a float; MAXINTEGER may not have one,\n** and therefore its conversion to float may have an ill-defined value.)\n*/\n#define lua_numbertointeger(n,p) \\\n  ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \\\n   (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \\\n      (*(p) = (LUA_INTEGER)(n), 1))\n\n\n/* now the variable definitions */\n\n#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT\t\t/* { single float */\n\n#define LUA_NUMBER\tfloat\n\n#define l_mathlim(n)\t\t(FLT_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.7g\"\n\n#define l_mathop(op)\t\top##f\n\n#define lua_str2number(s,p)\tstrtof((s), (p))\n\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\t/* }{ long double */\n\n#define LUA_NUMBER\tlong double\n\n#define l_mathlim(n)\t\t(LDBL_##n)\n\n#define LUAI_UACNUMBER\tlong double\n\n#define LUA_NUMBER_FRMLEN\t\"L\"\n#define LUA_NUMBER_FMT\t\t\"%.19Lg\"\n\n#define l_mathop(op)\t\top##l\n\n#define lua_str2number(s,p)\tstrtold((s), (p))\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE\t/* }{ double */\n\n#define LUA_NUMBER\tdouble\n\n#define l_mathlim(n)\t\t(DBL_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n\n#define l_mathop(op)\t\top\n\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n#else\t\t\t\t\t\t/* }{ */\n\n#error \"numeric float type not defined\"\n\n#endif\t\t\t\t\t/* } */\n\n\n\n/*\n@@ LUA_INTEGER is the integer type used by Lua.\n**\n@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.\n**\n@@ LUAI_UACINT is the result of a 'default argument promotion'\n@@ over a lUA_INTEGER.\n@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.\n@@ LUA_INTEGER_FMT is the format for writing integers.\n@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.\n@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.\n@@ lua_integer2str converts an integer to a string.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define LUA_INTEGER_FMT\t\t\"%\" LUA_INTEGER_FRMLEN \"d\"\n\n#define LUAI_UACINT\t\tLUA_INTEGER\n\n#define lua_integer2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))\n\n/*\n** use LUAI_UACINT here to avoid problems with promotions (which\n** can turn a comparison between unsigneds into a signed comparison)\n*/\n#define LUA_UNSIGNED\t\tunsigned LUAI_UACINT\n\n\n/* now the variable definitions */\n\n#if LUA_INT_TYPE == LUA_INT_INT\t\t/* { int */\n\n#define LUA_INTEGER\t\tint\n#define LUA_INTEGER_FRMLEN\t\"\"\n\n#define LUA_MAXINTEGER\t\tINT_MAX\n#define LUA_MININTEGER\t\tINT_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONG\t/* }{ long */\n\n#define LUA_INTEGER\t\tlong\n#define LUA_INTEGER_FRMLEN\t\"l\"\n\n#define LUA_MAXINTEGER\t\tLONG_MAX\n#define LUA_MININTEGER\t\tLONG_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONGLONG\t/* }{ long long */\n\n/* use presence of macro LLONG_MAX as proxy for C99 compliance */\n#if defined(LLONG_MAX)\t\t/* { */\n/* use ISO C99 stuff */\n\n#define LUA_INTEGER\t\tlong long\n#define LUA_INTEGER_FRMLEN\t\"ll\"\n\n#define LUA_MAXINTEGER\t\tLLONG_MAX\n#define LUA_MININTEGER\t\tLLONG_MIN\n\n#elif defined(LUA_USE_WINDOWS) /* }{ */\n/* in Windows, can use specific Windows types */\n\n#define LUA_INTEGER\t\t__int64\n#define LUA_INTEGER_FRMLEN\t\"I64\"\n\n#define LUA_MAXINTEGER\t\t_I64_MAX\n#define LUA_MININTEGER\t\t_I64_MIN\n\n#else\t\t\t\t/* }{ */\n\n#error \"Compiler does not support 'long long'. Use option '-DLUA_32BITS' \\\n  or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)\"\n\n#endif\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#error \"numeric integer type not defined\"\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Dependencies with C99 and other C details\n** ===================================================================\n*/\n\n/*\n@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.\n** (All uses in Lua have only one format item.)\n*/\n#if !defined(LUA_USE_C89)\n#define l_sprintf(s,sz,f,i)\tsnprintf(s,sz,f,i)\n#else\n#define l_sprintf(s,sz,f,i)\t((void)(sz), sprintf(s,f,i))\n#endif\n\n\n/*\n@@ lua_strx2number converts an hexadecimal numeric string to a number.\n** In C99, 'strtod' does that conversion. Otherwise, you can\n** leave 'lua_strx2number' undefined and Lua will provide its own\n** implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_strx2number(s,p)\t\tlua_str2number(s,p)\n#endif\n\n\n/*\n@@ lua_number2strx converts a float to an hexadecimal numeric string.\n** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.\n** Otherwise, you can leave 'lua_number2strx' undefined and Lua will\n** provide its own implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_number2strx(L,b,sz,f,n)  \\\n\t((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))\n#endif\n\n\n/*\n** 'strtof' and 'opf' variants for math functions are not valid in\n** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the\n** availability of these variants. ('math.h' is already included in\n** all files that use these macros.)\n*/\n#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))\n#undef l_mathop  /* variants not available */\n#undef lua_str2number\n#define l_mathop(op)\t\t(lua_Number)op  /* no variant */\n#define lua_str2number(s,p)\t((lua_Number)strtod((s), (p)))\n#endif\n\n\n/*\n@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation\n** functions.  It must be a numerical type; Lua will use 'intptr_t' if\n** available, otherwise it will use 'ptrdiff_t' (the nearest thing to\n** 'intptr_t' in C89)\n*/\n#define LUA_KCONTEXT\tptrdiff_t\n\n#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \\\n    __STDC_VERSION__ >= 199901L\n#include <stdint.h>\n#if defined(INTPTR_MAX)  /* even in C99 this type is optional */\n#undef LUA_KCONTEXT\n#define LUA_KCONTEXT\tintptr_t\n#endif\n#endif\n\n\n/*\n@@ lua_getlocaledecpoint gets the locale \"radix character\" (decimal point).\n** Change that if you do not want to use C locales. (Code using this\n** macro must include header 'locale.h'.)\n*/\n#ifdef __ANDROID__\n#define lua_getlocaledecpoint() '.'\n#elif !defined(lua_getlocaledecpoint)\n#define lua_getlocaledecpoint()\t\t(localeconv()->decimal_point[0])\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Language Variations\n** =====================================================================\n*/\n\n/*\n@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some\n** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from\n** numbers to strings. Define LUA_NOCVTS2N to turn off automatic\n** coercion from strings to numbers.\n*/\n/* #define LUA_NOCVTN2S */\n/* #define LUA_NOCVTS2N */\n\n\n/*\n@@ LUA_USE_APICHECK turns on several consistency checks on the C API.\n** Define it as a help when debugging C code.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(l,e)\tassert(e)\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Macros that affect the API and must be stable (that is, must be the\n** same when you compile Lua and when you compile code that links to\n** Lua). You probably do not want/need to change them.\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXSTACK limits the size of the Lua stack.\n** CHANGE it if you need a different limit. This limit is arbitrary;\n** its only purpose is to stop Lua from consuming unlimited stack\n** space (and to reserve some numbers for pseudo-indices).\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_MAXSTACK\t\t1000000\n#else\n#define LUAI_MAXSTACK\t\t15000\n#endif\n\n\n/*\n@@ LUA_EXTRASPACE defines the size of a raw memory area associated with\n** a Lua state with very fast access.\n** CHANGE it if you need a different size.\n*/\n#define LUA_EXTRASPACE\t\t(sizeof(void *))\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@@ of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#cmakedefine LUA_IDSIZE\t@LUA_IDSIZE@\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n** CHANGE it if it uses too much C-stack space. (For long double,\n** 'string.format(\"%.99f\", -1e4932)' needs 5034 bytes, so a\n** smaller buffer would force a memory allocation for each call to\n** 'string.format'.)\n*/\n#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\n#define LUAL_BUFFERSIZE\t\t8192\n#else\n#define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** Lua does not use these macros anymore; they are here for\n** compatibility only.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* version suffix for environment variable names */\n#define LUA_VERSUFFIX          \"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n\nLUAMOD_API int (luaopen_base) (lua_State *L);\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUAMOD_API int (luaopen_coroutine) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUAMOD_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUAMOD_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUAMOD_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUAMOD_API int (luaopen_string) (lua_State *L);\n\n#define LUA_UTF8LIBNAME\t\"utf8\"\nLUAMOD_API int (luaopen_utf8) (lua_State *L);\n\n#define LUA_BITLIBNAME\t\"bit32\"\nLUAMOD_API int (luaopen_bit32) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUAMOD_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUAMOD_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUAMOD_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L);\n\n\n\n#if !defined(lua_assert)\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\n\n#if !defined(luai_verifycode)\n#define luai_verifycode(L,b,f)  /* empty */\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  ZIO *Z;\n  const char *name;\n} LoadState;\n\n\nstatic l_noret error(LoadState *S, const char *why) {\n  luaO_pushfstring(S->L, \"%s: %s precompiled chunk\", S->name, why);\n  luaD_throw(S->L, LUA_ERRSYNTAX);\n}\n\n\n/*\n** All high-level loads go through LoadVector; you can change it to\n** adapt to the endianness of the input\n*/\n#define LoadVector(S,b,n)\tLoadBlock(S,b,(n)*sizeof((b)[0]))\n\nstatic void LoadBlock (LoadState *S, void *b, size_t size) {\n  if (luaZ_read(S->Z, b, size) != 0)\n    error(S, \"truncated\");\n}\n\n\n#define LoadVar(S,x)\t\tLoadVector(S,&x,1)\n\n\nstatic lu_byte LoadByte (LoadState *S) {\n  lu_byte x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic int LoadInt (LoadState *S) {\n  int x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Number LoadNumber (LoadState *S) {\n  lua_Number x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Integer LoadInteger (LoadState *S) {\n  lua_Integer x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic TString *LoadString (LoadState *S) {\n  size_t size = LoadByte(S);\n  if (size == 0xFF)\n    LoadVar(S, size);\n  if (size == 0)\n    return NULL;\n  else if (--size <= LUAI_MAXSHORTLEN) {  /* short string? */\n    char buff[LUAI_MAXSHORTLEN];\n    LoadVector(S, buff, size);\n    return luaS_newlstr(S->L, buff, size);\n  }\n  else {  /* long string */\n    TString *ts = luaS_createlngstrobj(S->L, size);\n    LoadVector(S, getstr(ts), size);  /* load directly in final place */\n    return ts;\n  }\n}\n\n\nstatic void LoadCode (LoadState *S, Proto *f) {\n  int n = LoadInt(S);\n  f->code = luaM_newvector(S->L, n, Instruction);\n  f->sizecode = n;\n  LoadVector(S, f->code, n);\n}\n\n\nstatic void LoadFunction(LoadState *S, Proto *f, TString *psource);\n\n\nstatic void LoadConstants (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->k = luaM_newvector(S->L, n, TValue);\n  f->sizek = n;\n  for (i = 0; i < n; i++)\n    setnilvalue(&f->k[i]);\n  for (i = 0; i < n; i++) {\n    TValue *o = &f->k[i];\n    int t = LoadByte(S);\n    switch (t) {\n    case LUA_TNIL:\n      setnilvalue(o);\n      break;\n    case LUA_TBOOLEAN:\n      setbvalue(o, LoadByte(S));\n      break;\n    case LUA_TNUMFLT:\n      setfltvalue(o, LoadNumber(S));\n      break;\n    case LUA_TNUMINT:\n      setivalue(o, LoadInteger(S));\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      setsvalue2n(S->L, o, LoadString(S));\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void LoadProtos (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->p = luaM_newvector(S->L, n, Proto *);\n  f->sizep = n;\n  for (i = 0; i < n; i++)\n    f->p[i] = NULL;\n  for (i = 0; i < n; i++) {\n    f->p[i] = luaF_newproto(S->L);\n    LoadFunction(S, f->p[i], f->source);\n  }\n}\n\n\nstatic void LoadUpvalues (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->upvalues = luaM_newvector(S->L, n, Upvaldesc);\n  f->sizeupvalues = n;\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = NULL;\n  for (i = 0; i < n; i++) {\n    f->upvalues[i].instack = LoadByte(S);\n    f->upvalues[i].idx = LoadByte(S);\n  }\n}\n\n\nstatic void LoadDebug (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->lineinfo = luaM_newvector(S->L, n, int);\n  f->sizelineinfo = n;\n  LoadVector(S, f->lineinfo, n);\n  n = LoadInt(S);\n  f->locvars = luaM_newvector(S->L, n, LocVar);\n  f->sizelocvars = n;\n  for (i = 0; i < n; i++)\n    f->locvars[i].varname = NULL;\n  for (i = 0; i < n; i++) {\n    f->locvars[i].varname = LoadString(S);\n    f->locvars[i].startpc = LoadInt(S);\n    f->locvars[i].endpc = LoadInt(S);\n  }\n  n = LoadInt(S);\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = LoadString(S);\n}\n\n\nstatic void LoadFunction (LoadState *S, Proto *f, TString *psource) {\n  f->source = LoadString(S);\n  if (f->source == NULL)  /* no source in dump? */\n    f->source = psource;  /* reuse parent's source */\n  f->linedefined = LoadInt(S);\n  f->lastlinedefined = LoadInt(S);\n  f->numparams = LoadByte(S);\n  f->is_vararg = LoadByte(S);\n  f->maxstacksize = LoadByte(S);\n  LoadCode(S, f);\n  LoadConstants(S, f);\n  LoadUpvalues(S, f);\n  LoadProtos(S, f);\n  LoadDebug(S, f);\n}\n\n\nstatic void checkliteral (LoadState *S, const char *s, const char *msg) {\n  char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */\n  size_t len = strlen(s);\n  LoadVector(S, buff, len);\n  if (memcmp(s, buff, len) != 0)\n    error(S, msg);\n}\n\n\nstatic void fchecksize (LoadState *S, size_t size, const char *tname) {\n  if (LoadByte(S) != size)\n    error(S, luaO_pushfstring(S->L, \"%s size mismatch in\", tname));\n}\n\n\n#define checksize(S,t)\tfchecksize(S,sizeof(t),#t)\n\nstatic void checkHeader (LoadState *S) {\n  checkliteral(S, LUA_SIGNATURE + 1, \"not a\");  /* 1st char already checked */\n  if (LoadByte(S) != LUAC_VERSION)\n    error(S, \"version mismatch in\");\n  if (LoadByte(S) != LUAC_FORMAT)\n    error(S, \"format mismatch in\");\n  checkliteral(S, LUAC_DATA, \"corrupted\");\n  checksize(S, int);\n  checksize(S, size_t);\n  checksize(S, Instruction);\n  checksize(S, lua_Integer);\n  checksize(S, lua_Number);\n  if (LoadInteger(S) != LUAC_INT)\n    error(S, \"endianness mismatch in\");\n  if (LoadNumber(S) != LUAC_NUM)\n    error(S, \"float format mismatch in\");\n}\n\n\n/*\n** load precompiled chunk\n*/\nLClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {\n  LoadState S;\n  LClosure *cl;\n  if (*name == '@' || *name == '=')\n    S.name = name + 1;\n  else if (*name == LUA_SIGNATURE[0])\n    S.name = \"binary string\";\n  else\n    S.name = name;\n  S.L = L;\n  S.Z = Z;\n  checkHeader(&S);\n  cl = luaF_newLclosure(L, LoadByte(&S));\n  setclLvalue(L, L->top, cl);\n  luaD_inctop(L);\n  cl->p = luaF_newproto(L);\n  LoadFunction(&S, cl->p, NULL);\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luai_verifycode(L, buff, cl->p);\n  return cl;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/* data to catch conversion errors */\n#define LUAC_DATA\t\"\\x19\\x93\\r\\n\\x1a\\n\"\n\n#define LUAC_INT\t0x5678\n#define LUAC_NUM\tcast_num(370.5)\n\n#define MYINT(s)\t(s[0]-'0')\n#define LUAC_VERSION\t(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))\n#define LUAC_FORMAT\t0\t/* this is the official format */\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,\n                         void* data, int strip);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lutf8lib.c",
    "content": "/*\n** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $\n** Standard library for UTF-8 manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define lutf8lib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <assert.h>\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#define MAXUNICODE\t0x10FFFF\n\n#define iscont(p)\t((*(p) & 0xC0) == 0x80)\n\n\n/* from strlib */\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer u_posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\n/*\n** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.\n*/\nstatic const char *utf8_decode (const char *o, int *val) {\n  static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};\n  const unsigned char *s = (const unsigned char *)o;\n  unsigned int c = s[0];\n  unsigned int res = 0;  /* final result */\n  if (c < 0x80)  /* ascii? */\n    res = c;\n  else {\n    int count = 0;  /* to count number of continuation bytes */\n    while (c & 0x40) {  /* still have continuation bytes? */\n      int cc = s[++count];  /* read next byte */\n      if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */\n        return NULL;  /* invalid byte sequence */\n      res = (res << 6) | (cc & 0x3F);  /* add lower 6 bits from cont. byte */\n      c <<= 1;  /* to test next bit */\n    }\n    res |= ((c & 0x7F) << (count * 5));  /* add first byte */\n    if (count > 3 || res > MAXUNICODE || res <= limits[count])\n      return NULL;  /* invalid byte sequence */\n    s += count;  /* skip continuation bytes read */\n  }\n  if (val) *val = res;\n  return (const char *)s + 1;  /* +1 to include first byte */\n}\n\n\n/*\n** utf8len(s [, i [, j]]) --> number of characters that start in the\n** range [i,j], or nil + current position if 's' is not well formed in\n** that interval\n*/\nstatic int utflen (lua_State *L) {\n  int n = 0;\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,\n                   \"initial position out of string\");\n  luaL_argcheck(L, --posj < (lua_Integer)len, 3,\n                   \"final position out of string\");\n  while (posi <= posj) {\n    const char *s1 = utf8_decode(s + posi, NULL);\n    if (s1 == NULL) {  /* conversion error? */\n      lua_pushnil(L);  /* return nil ... */\n      lua_pushinteger(L, posi + 1);  /* ... and current position */\n      return 2;\n    }\n    posi = s1 - s;\n    n++;\n  }\n  lua_pushinteger(L, n);\n  return 1;\n}\n\n\n/*\n** codepoint(s, [i, [j]])  -> returns codepoints for all characters\n** that start in the range [i,j]\n*/\nstatic int codepoint (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  int n;\n  const char *se;\n  luaL_argcheck(L, posi >= 1, 2, \"out of range\");\n  luaL_argcheck(L, pose <= (lua_Integer)len, 3, \"out of range\");\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  n = 0;\n  se = s + pose;\n  for (s += posi - 1; s < se;) {\n    int code;\n    s = utf8_decode(s, &code);\n    if (s == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, code);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void pushutfchar (lua_State *L, int arg) {\n  lua_Integer code = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, \"value out of range\");\n  lua_pushfstring(L, \"%U\", (long)code);\n}\n\n\n/*\n** utfchar(n1, n2, ...)  -> char(n1)..char(n2)...\n*/\nstatic int utfchar (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  if (n == 1)  /* optimize common case of single char */\n    pushutfchar(L, 1);\n  else {\n    int i;\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    for (i = 1; i <= n; i++) {\n      pushutfchar(L, i);\n      luaL_addvalue(&b);\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\n/*\n** offset(s, n, [i])  -> index where n-th character counting from\n**   position 'i' starts; 0 means character at 'i'.\n*/\nstatic int byteoffset (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n  = luaL_checkinteger(L, 2);\n  lua_Integer posi = (n >= 0) ? 1 : len + 1;\n  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,\n                   \"position out of range\");\n  if (n == 0) {\n    /* find beginning of current byte sequence */\n    while (posi > 0 && iscont(s + posi)) posi--;\n  }\n  else {\n    if (iscont(s + posi))\n      luaL_error(L, \"initial position is a continuation byte\");\n    if (n < 0) {\n       while (n < 0 && posi > 0) {  /* move back */\n         do {  /* find beginning of previous character */\n           posi--;\n         } while (posi > 0 && iscont(s + posi));\n         n++;\n       }\n     }\n     else {\n       n--;  /* do not move for 1st character */\n       while (n > 0 && posi < (lua_Integer)len) {\n         do {  /* find beginning of next character */\n           posi++;\n         } while (iscont(s + posi));  /* (cannot pass final '\\0') */\n         n--;\n       }\n     }\n  }\n  if (n == 0)  /* did it find given character? */\n    lua_pushinteger(L, posi + 1);\n  else  /* no such character */\n    lua_pushnil(L);\n  return 1;\n}\n\n\nstatic int iter_aux (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n = lua_tointeger(L, 2) - 1;\n  if (n < 0)  /* first iteration? */\n    n = 0;  /* start from here */\n  else if (n < (lua_Integer)len) {\n    n++;  /* skip current byte */\n    while (iscont(s + n)) n++;  /* and its continuations */\n  }\n  if (n >= (lua_Integer)len)\n    return 0;  /* no more codepoints */\n  else {\n    int code;\n    const char *next = utf8_decode(s + n, &code);\n    if (next == NULL || iscont(next))\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, n + 1);\n    lua_pushinteger(L, code);\n    return 2;\n  }\n}\n\n\nstatic int iter_codes (lua_State *L) {\n  luaL_checkstring(L, 1);\n  lua_pushcfunction(L, iter_aux);\n  lua_pushvalue(L, 1);\n  lua_pushinteger(L, 0);\n  return 3;\n}\n\n\n/* pattern to match a single UTF-8 character */\n#define UTF8PATT\t\"[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*\"\n\n\nstatic const luaL_Reg funcs[] = {\n  {\"offset\", byteoffset},\n  {\"codepoint\", codepoint},\n  {\"char\", utfchar},\n  {\"len\", utflen},\n  {\"codes\", iter_codes},\n  /* placeholders */\n  {\"charpattern\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_utf8 (lua_State *L) {\n  luaL_newlib(L, funcs);\n  lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);\n  lua_setfield(L, -2, \"charpattern\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.268 2016/02/05 19:59:14 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t2000\n\n\n\n/*\n** 'l_intfitsf' checks whether a given integer can be converted to a\n** float without rounding. Used in comparisons. Left undefined if\n** all integers fit in a float precisely.\n*/\n#if !defined(l_intfitsf)\n\n/* number of bits in the mantissa of a float */\n#define NBM\t\t(l_mathlim(MANT_DIG))\n\n/*\n** Check whether some integers may not fit in a float, that is, whether\n** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).\n** (The shifts are done in parts to avoid shifting by more than the size\n** of an integer. In a worst case, NBM == 113 for long double and\n** sizeof(integer) == 32.)\n*/\n#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \\\n\t>> (NBM - (3 * (NBM / 4))))  >  0\n\n#define l_intfitsf(i)  \\\n  (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM))\n\n#endif\n\n#endif\n\n\n\n/*\n** Try to convert a value to a float. The float case is already handled\n** by the macro 'tonumber'.\n*/\nint luaV_tonumber_ (const TValue *obj, lua_Number *n) {\n  TValue v;\n  if (ttisinteger(obj)) {\n    *n = cast_num(ivalue(obj));\n    return 1;\n  }\n  else if (cvt2num(obj) &&  /* string convertible to number? */\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */\n    return 1;\n  }\n  else\n    return 0;  /* conversion failed */\n}\n\n\n/*\n** try to convert a value to an integer, rounding according to 'mode':\n** mode == 0: accepts only integral values\n** mode == 1: takes the floor of the number\n** mode == 2: takes the ceil of the number\n*/\nint luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {\n  TValue v;\n again:\n  if (ttisfloat(obj)) {\n    lua_Number n = fltvalue(obj);\n    lua_Number f = l_floor(n);\n    if (n != f) {  /* not an integral value? */\n      if (mode == 0) return 0;  /* fails if mode demands integral value */\n      else if (mode > 1)  /* needs ceil? */\n        f += 1;  /* convert floor to ceil (remember: n != f) */\n    }\n    return lua_numbertointeger(f, p);\n  }\n  else if (ttisinteger(obj)) {\n    *p = ivalue(obj);\n    return 1;\n  }\n  else if (cvt2num(obj) &&\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    obj = &v;\n    goto again;  /* convert result from 'luaO_str2num' to an integer */\n  }\n  return 0;  /* conversion failed */\n}\n\n\n/*\n** Try to convert a 'for' limit to an integer, preserving the\n** semantics of the loop.\n** (The following explanation assumes a non-negative step; it is valid\n** for negative steps mutatis mutandis.)\n** If the limit can be converted to an integer, rounding down, that is\n** it.\n** Otherwise, check whether the limit can be converted to a number.  If\n** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,\n** which means no limit.  If the number is too negative, the loop\n** should not run, because any initial integer value is larger than the\n** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects\n** the extreme case when the initial value is LUA_MININTEGER, in which\n** case the LUA_MININTEGER limit would still run the loop once.\n*/\nstatic int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,\n                     int *stopnow) {\n  *stopnow = 0;  /* usually, let loops run */\n  if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) {  /* not fit in integer? */\n    lua_Number n;  /* try to convert to float */\n    if (!tonumber(obj, &n)) /* cannot convert to float? */\n      return 0;  /* not a number */\n    if (luai_numlt(0, n)) {  /* if true, float is larger than max integer */\n      *p = LUA_MAXINTEGER;\n      if (step < 0) *stopnow = 1;\n    }\n    else {  /* float is smaller than min integer */\n      *p = LUA_MININTEGER;\n      if (step >= 0) *stopnow = 1;\n    }\n  }\n  return 1;\n}\n\n\n/*\n** Finish the table access 'val = t[key]'.\n** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to\n** t[k] entry (which must be nil).\n*/\nvoid luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,\n                      const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  const TValue *tm;  /* metamethod */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    if (slot == NULL) {  /* 't' is not a table? */\n      lua_assert(!ttistable(t));\n      tm = luaT_gettmbyobj(L, t, TM_INDEX);\n      if (ttisnil(tm))\n        luaG_typeerror(L, t, \"index\");  /* no metamethod */\n      /* else will try the metamethod */\n    }\n    else {  /* 't' is a table */\n      lua_assert(ttisnil(slot));\n      tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        setnilvalue(val);  /* result is nil */\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    if (ttisfunction(tm)) {  /* is metamethod a function? */\n      luaT_callTM(L, tm, t, key, val, 1);  /* call it */\n      return;\n    }\n    t = tm;  /* else try to access 'tm[key]' */\n    if (luaV_fastget(L,t,key,slot,luaH_get)) {  /* fast track? */\n      setobj2s(L, val, slot);  /* done */\n      return;\n    }\n    /* else repeat (tail call 'luaV_finishget') */\n  }\n  luaG_runerror(L, \"'__index' chain too long; possible loop\");\n}\n\n\n/*\n** Finish a table assignment 't[key] = val'.\n** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points\n** to the entry 't[key]', or to 'luaO_nilobject' if there is no such\n** entry.  (The value at 'slot' must be nil, otherwise 'luaV_fastset'\n** would have done the job.)\n*/\nvoid luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                     StkId val, const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;  /* '__newindex' metamethod */\n    if (slot != NULL) {  /* is 't' a table? */\n      Table *h = hvalue(t);  /* save 't' table */\n      lua_assert(ttisnil(slot));  /* old value must be nil */\n      tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        if (slot == luaO_nilobject)  /* no previous entry? */\n          slot = luaH_newkey(L, h, key);  /* create one */\n        /* no metamethod and (now) there is an entry with given key */\n        setobj2t(L, cast(TValue *, slot), val);  /* set its new value */\n        invalidateTMcache(h);\n        luaC_barrierback(L, h, val);\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    else {  /* not a table; check metamethod */\n      if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n        luaG_typeerror(L, t, \"index\");\n    }\n    /* try the metamethod */\n    if (ttisfunction(tm)) {\n      luaT_callTM(L, tm, t, key, val, 0);\n      return;\n    }\n    t = tm;  /* else repeat assignment over 'tm' */\n    if (luaV_fastset(L, t, key, slot, luaH_get, val))\n      return;  /* done */\n    /* else loop */\n  }\n  luaG_runerror(L, \"'__newindex' chain too long; possible loop\");\n}\n\n\n/*\n** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-\n** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.\n** The code is a little tricky because it allows '\\0' in the strings\n** and it uses 'strcoll' (to respect locales) for each segments\n** of the strings.\n*/\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = tsslen(ls);\n  const char *r = getstr(rs);\n  size_t lr = tsslen(rs);\n  for (;;) {  /* for each segment */\n    int temp = strcoll(l, r);\n    if (temp != 0)  /* not equal? */\n      return temp;  /* done */\n    else {  /* strings are equal up to a '\\0' */\n      size_t len = strlen(l);  /* index of first '\\0' in both strings */\n      if (len == lr)  /* 'rs' is finished? */\n        return (len == ll) ? 0 : 1;  /* check 'ls' */\n      else if (len == ll)  /* 'ls' is finished? */\n        return -1;  /* 'ls' is smaller than 'rs' ('rs' is not finished) */\n      /* both strings longer than 'len'; go on comparing after the '\\0' */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than float 'f'. If 'i' has an\n** exact representation as a float ('l_intfitsf'), compare numbers as\n** floats. Otherwise, if 'f' is outside the range for integers, result\n** is trivial. Otherwise, compare them as integers. (When 'i' has no\n** float representation, either 'f' is \"far away\" from 'i' or 'f' has\n** no precision left for a fractional part; either way, how 'f' is\n** truncated is irrelevant.) When 'f' is NaN, comparisons must result\n** in false.\n*/\nstatic int LTintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f > cast_num(LUA_MININTEGER))  /* minint < f <= maxint ? */\n      return (i < cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f <= minint <= i (or 'f' is NaN)  -->  not(i < f) */\n      return 0;\n  }\n#endif\n  return luai_numlt(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Check whether integer 'i' is less than or equal to float 'f'.\n** See comments on previous function.\n*/\nstatic int LEintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f >= cast_num(LUA_MININTEGER))  /* minint <= f <= maxint ? */\n      return (i <= cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f < minint <= i (or 'f' is NaN)  -->  not(i <= f) */\n      return 0;\n  }\n#endif\n  return luai_numle(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Return 'l < r', for numbers.\n*/\nstatic int LTnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li < ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LTintfloat(li, fltvalue(r));  /* l < r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numlt(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /* NaN < i is always false */\n    else  /* without NaN, (l < r)  <-->  not(r <= l) */\n      return !LEintfloat(ivalue(r), lf);  /* not (r <= l) ? */\n  }\n}\n\n\n/*\n** Return 'l <= r', for numbers.\n*/\nstatic int LEnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li <= ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LEintfloat(li, fltvalue(r));  /* l <= r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numle(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /*  NaN <= i is always false */\n    else  /* without NaN, (l <= r)  <-->  not(r < l) */\n      return !LTintfloat(ivalue(r), lf);  /* not (r < l) ? */\n  }\n}\n\n\n/*\n** Main operation less than; return 'l < r'.\n*/\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LTnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) < 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0)  /* no metamethod? */\n    luaG_ordererror(L, l, r);  /* error */\n  return res;\n}\n\n\n/*\n** Main operation less than or equal to; return 'l <= r'. If it needs\n** a metamethod and there is no '__le', try '__lt', based on\n** l <= r iff !(r < l) (assuming a total order). If the metamethod\n** yields during this substitution, the continuation has to know\n** about it (to negate the result of r<l); bit CIST_LEQ in the call\n** status keeps that information.\n*/\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LEnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0)  /* try 'le' */\n    return res;\n  else {  /* try 'lt': */\n    L->ci->callstatus |= CIST_LEQ;  /* mark it is doing 'lt' for 'le' */\n    res = luaT_callorderTM(L, r, l, TM_LT);\n    L->ci->callstatus ^= CIST_LEQ;  /* clear mark */\n    if (res < 0)\n      luaG_ordererror(L, l, r);\n    return !res;  /* result is negated */\n  }\n}\n\n\n/*\n** Main operation for equality of Lua values; return 't1 == t2'.\n** L == NULL means raw equality (no metamethods)\n*/\nint luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  if (ttype(t1) != ttype(t2)) {  /* not the same variant? */\n    if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)\n      return 0;  /* only numbers can be equal with different variants */\n    else {  /* two numbers with different variants */\n      lua_Integer i1, i2;  /* compare them as integers */\n      return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);\n    }\n  }\n  /* values have same type and same variant */\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));\n    case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TLCF: return fvalue(t1) == fvalue(t2);\n    case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default:\n      return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL)  /* no TM? */\n    return 0;  /* objects are different */\n  luaT_callTM(L, tm, t1, t2, L->top, 1);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\n/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */\n#define tostring(L,o)  \\\n\t(ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))\n\n#define isemptystr(o)\t(ttisshrstring(o) && tsvalue(o)->shrlen == 0)\n\n/* copy strings in stack from top - n up to top - 1 to buffer */\nstatic void copy2buff (StkId top, int n, char *buff) {\n  size_t tl = 0;  /* size already copied */\n  do {\n    size_t l = vslen(top - n);  /* length of string being copied */\n    memcpy(buff + tl, svalue(top - n), l * sizeof(char));\n    tl += l;\n  } while (--n > 0);\n}\n\n\n/*\n** Main operation for concatenation: concat 'total' values in the stack,\n** from 'L->top - total' up to 'L->top - 1'.\n*/\nvoid luaV_concat (lua_State *L, int total) {\n  lua_assert(total >= 2);\n  do {\n    StkId top = L->top;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1))\n      luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT);\n    else if (isemptystr(top - 1))  /* second operand is empty? */\n      cast_void(tostring(L, top - 2));  /* result is first operand */\n    else if (isemptystr(top - 2)) {  /* first operand is an empty string? */\n      setobjs2s(L, top - 2, top - 1);  /* result is second op. */\n    }\n    else {\n      /* at least two non-empty string values; get as many as possible */\n      size_t tl = vslen(top - 1);\n      TString *ts;\n      /* collect total length and number of strings */\n      for (n = 1; n < total && tostring(L, top - n - 1); n++) {\n        size_t l = vslen(top - n - 1);\n        if (l >= (MAX_SIZE/sizeof(char)) - tl)\n          luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */\n        char buff[LUAI_MAXSHORTLEN];\n        copy2buff(top, n, buff);  /* copy strings to buffer */\n        ts = luaS_newlstr(L, buff, tl);\n      }\n      else {  /* long string; copy strings directly to final result */\n        ts = luaS_createlngstrobj(L, tl);\n        copy2buff(top, n, getstr(ts));\n      }\n      setsvalue2s(L, top - n, ts);  /* create result */\n    }\n    total -= n-1;  /* got 'n' strings to create 1 new */\n    L->top -= n-1;  /* popped 'n' strings and pushed one */\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\n/*\n** Main operation 'ra' = #rb'.\n*/\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n  const TValue *tm;\n  switch (ttype(rb)) {\n    case LUA_TTABLE: {\n      Table *h = hvalue(rb);\n      tm = fasttm(L, h->metatable, TM_LEN);\n      if (tm) break;  /* metamethod? break switch to call it */\n      setivalue(ra, luaH_getn(h));  /* else primitive len */\n      return;\n    }\n    case LUA_TSHRSTR: {\n      setivalue(ra, tsvalue(rb)->shrlen);\n      return;\n    }\n    case LUA_TLNGSTR: {\n      setivalue(ra, tsvalue(rb)->u.lnglen);\n      return;\n    }\n    default: {  /* try metamethod */\n      tm = luaT_gettmbyobj(L, rb, TM_LEN);\n      if (ttisnil(tm))  /* no metamethod? */\n        luaG_typeerror(L, rb, \"get length of\");\n      break;\n    }\n  }\n  luaT_callTM(L, tm, rb, rb, ra, 1);\n}\n\n\n/*\n** Integer division; return 'm // n', that is, floor(m/n).\n** C division truncates its result (rounds towards zero).\n** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,\n** otherwise 'floor(q) == trunc(q) - 1'.\n*/\nlua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to divide by zero\");\n    return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */\n  }\n  else {\n    lua_Integer q = m / n;  /* perform C division */\n    if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */\n      q -= 1;  /* correct result for different rounding */\n    return q;\n  }\n}\n\n\n/*\n** Integer modulus; return 'm % n'. (Assume that C '%' with\n** negative operands follows C99 behavior. See previous comment\n** about luaV_div.)\n*/\nlua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to perform 'n%%0'\");\n    return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */\n  }\n  else {\n    lua_Integer r = m % n;\n    if (r != 0 && (m ^ n) < 0)  /* 'm/n' would be non-integer negative? */\n      r += n;  /* correct result for different rounding */\n    return r;\n  }\n}\n\n\n/* number of bits in an integer */\n#define NBITS\tcast_int(sizeof(lua_Integer) * CHAR_BIT)\n\n/*\n** Shift left operation. (Shift right just negates 'y'.)\n*/\nlua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {\n  if (y < 0) {  /* shift right? */\n    if (y <= -NBITS) return 0;\n    else return intop(>>, x, -y);\n  }\n  else {  /* shift left */\n    if (y >= NBITS) return 0;\n    else return intop(<<, x, y);\n  }\n}\n\n\n/*\n** check whether cached closure in prototype 'p' may be reused, that is,\n** whether there is a cached closure with the same upvalues needed by\n** new closure to be created.\n*/\nstatic LClosure *getcached (Proto *p, UpVal **encup, StkId base) {\n  LClosure *c = p->cache;\n  if (c != NULL) {  /* is there a cached closure? */\n    int nup = p->sizeupvalues;\n    Upvaldesc *uv = p->upvalues;\n    int i;\n    for (i = 0; i < nup; i++) {  /* check whether it has right upvalues */\n      TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;\n      if (c->upvals[i]->v != v)\n        return NULL;  /* wrong upvalue; cannot reuse closure */\n    }\n  }\n  return c;  /* return cached closure (or NULL if no cached closure) */\n}\n\n\n/*\n** create a new Lua closure, push it in the stack, and initialize\n** its upvalues. Note that the closure is not cached if prototype is\n** already black (which means that 'cache' was already cleared by the\n** GC).\n*/\nstatic void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,\n                         StkId ra) {\n  int nup = p->sizeupvalues;\n  Upvaldesc *uv = p->upvalues;\n  int i;\n  LClosure *ncl = luaF_newLclosure(L, nup);\n  ncl->p = p;\n  setclLvalue(L, ra, ncl);  /* anchor new closure in stack */\n  for (i = 0; i < nup; i++) {  /* fill in its upvalues */\n    if (uv[i].instack)  /* upvalue refers to local variable? */\n      ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);\n    else  /* get upvalue from enclosing function */\n      ncl->upvals[i] = encup[uv[i].idx];\n    ncl->upvals[i]->refcount++;\n    /* new closure is white, so we do not need a barrier here */\n  }\n  if (!isblack(p))  /* cache will not break GC invariant? */\n    p->cache = ncl;  /* save it on cache for reuse */\n}\n\n\n/*\n** finish execution of an opcode interrupted by an yield\n*/\nvoid luaV_finishOp (lua_State *L) {\n  CallInfo *ci = L->ci;\n  StkId base = ci->u.l.base;\n  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */\n  OpCode op = GET_OPCODE(inst);\n  switch (op) {  /* finish its execution */\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV:\n    case OP_BAND: case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR:\n    case OP_MOD: case OP_POW:\n    case OP_UNM: case OP_BNOT: case OP_LEN:\n    case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {\n      setobjs2s(L, base + GETARG_A(inst), --L->top);\n      break;\n    }\n    case OP_LE: case OP_LT: case OP_EQ: {\n      int res = !l_isfalse(L->top - 1);\n      L->top--;\n      if (ci->callstatus & CIST_LEQ) {  /* \"<=\" using \"<\" instead? */\n        lua_assert(op == OP_LE);\n        ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        res = !res;  /* negate result */\n      }\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);\n      if (res != GETARG_A(inst))  /* condition failed? */\n        ci->u.l.savedpc++;  /* skip jump instruction */\n      break;\n    }\n    case OP_CONCAT: {\n      StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */\n      int b = GETARG_B(inst);      /* first element to concatenate */\n      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */\n      setobj2s(L, top - 2, top);  /* put TM result in proper position */\n      if (total > 1) {  /* are there elements to concat? */\n        L->top = top - 1;  /* top is one after last element (at top-2) */\n        luaV_concat(L, total);  /* concat them (may yield again) */\n      }\n      /* move final result to final position */\n      setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);\n      L->top = ci->top;  /* restore top */\n      break;\n    }\n    case OP_TFORCALL: {\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);\n      L->top = ci->top;  /* correct top */\n      break;\n    }\n    case OP_CALL: {\n      if (GETARG_C(inst) - 1 >= 0)  /* nresults >= 0? */\n        L->top = ci->top;  /* adjust results */\n      break;\n    }\n    case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n\n\n/*\n** {==================================================================\n** Function 'luaV_execute': main interpreter loop\n** ===================================================================\n*/\n\n\n/*\n** some macros for common tasks in 'luaV_execute'\n*/\n\n\n#define RA(i)\t(base+GETARG_A(i))\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n\n\n/* execute a jump instruction */\n#define dojump(ci,i,e) \\\n  { int a = GETARG_A(i); \\\n    if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \\\n    ci->u.l.savedpc += GETARG_sBx(i) + e; }\n\n/* for test instructions, execute the jump instruction that follows it */\n#define donextjump(ci)\t{ i = *ci->u.l.savedpc; dojump(ci, i, 1); }\n\n\n#define Protect(x)\t{ {x;}; base = ci->u.l.base; }\n\n#define checkGC(L,c)  \\\n\t{ luaC_condGC(L, L->top = (c),  /* limit of live values */ \\\n                         Protect(L->top = ci->top));  /* restore top */ \\\n           luai_threadyield(L); }\n\n\n/* fetch an instruction and prepare its execution */\n#define vmfetch()\t{ \\\n  i = *(ci->u.l.savedpc++); \\\n  if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) \\\n    Protect(luaG_traceexec(L)); \\\n  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \\\n  lua_assert(base == ci->u.l.base); \\\n  lua_assert(base <= L->top && L->top < L->stack + L->stacksize); \\\n}\n\n#define vmdispatch(o)\tswitch(o)\n#define vmcase(l)\tcase l:\n#define vmbreak\t\tbreak\n\n\n/*\n** copy of 'luaV_gettable', but protecting the call to potential\n** metamethod (which can reallocate the stack)\n*/\n#define gettableProtected(L,t,k,v)  { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else Protect(luaV_finishget(L,t,k,v,slot)); }\n\n\n/* same for 'luaV_settable' */\n#define settableProtected(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    Protect(luaV_finishset(L,t,k,v,slot)); }\n\n\n\nvoid luaV_execute (lua_State *L) {\n  CallInfo *ci = L->ci;\n  LClosure *cl;\n  TValue *k;\n  StkId base;\n  ci->callstatus |= CIST_FRESH;  /* fresh invocation of 'luaV_execute\" */\n newframe:  /* reentry point when frame changes (call/return) */\n  lua_assert(ci == L->ci);\n  cl = clLvalue(ci->func);  /* local reference to function's closure */\n  k = cl->p->k;  /* local reference to function's constant table */\n  base = ci->u.l.base;  /* local copy of function's base */\n  /* main loop of interpreter */\n  for (;;) {\n    Instruction i;\n    StkId ra;\n    vmfetch();\n    vmdispatch (GET_OPCODE(i)) {\n      vmcase(OP_MOVE) {\n        setobjs2s(L, ra, RB(i));\n        vmbreak;\n      }\n      vmcase(OP_LOADK) {\n        TValue *rb = k + GETARG_Bx(i);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADKX) {\n        TValue *rb;\n        lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n        rb = k + GETARG_Ax(*ci->u.l.savedpc++);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADBOOL) {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) ci->u.l.savedpc++;  /* skip next instruction (if C) */\n        vmbreak;\n      }\n      vmcase(OP_LOADNIL) {\n        int b = GETARG_B(i);\n        do {\n          setnilvalue(ra++);\n        } while (b--);\n        vmbreak;\n      }\n      vmcase(OP_GETUPVAL) {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        vmbreak;\n      }\n      vmcase(OP_GETTABUP) {\n        TValue *upval = cl->upvals[GETARG_B(i)]->v;\n        TValue *rc = RKC(i);\n        gettableProtected(L, upval, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_GETTABLE) {\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        gettableProtected(L, rb, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_SETTABUP) {\n        TValue *upval = cl->upvals[GETARG_A(i)]->v;\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, upval, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_SETUPVAL) {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_upvalbarrier(L, uv);\n        vmbreak;\n      }\n      vmcase(OP_SETTABLE) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, ra, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_NEWTABLE) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Table *t = luaH_new(L);\n        sethvalue(L, ra, t);\n        if (b != 0 || c != 0)\n          luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_SELF) {\n        const TValue *aux;\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        setobjs2s(L, ra + 1, rb);\n        if (luaV_fastget(L, rb, key, aux, luaH_getstr)) {\n          setobj2s(L, ra, aux);\n        }\n        else Protect(luaV_finishget(L, rb, rc, ra, aux));\n        vmbreak;\n      }\n      vmcase(OP_ADD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(+, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numadd(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); }\n        vmbreak;\n      }\n      vmcase(OP_SUB) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(-, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numsub(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); }\n        vmbreak;\n      }\n      vmcase(OP_MUL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(*, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_nummul(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); }\n        vmbreak;\n      }\n      vmcase(OP_DIV) {  /* float division (always with floats) */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numdiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); }\n        vmbreak;\n      }\n      vmcase(OP_BAND) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(&, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); }\n        vmbreak;\n      }\n      vmcase(OP_BOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(|, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); }\n        vmbreak;\n      }\n      vmcase(OP_BXOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(^, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); }\n        vmbreak;\n      }\n      vmcase(OP_SHL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); }\n        vmbreak;\n      }\n      vmcase(OP_SHR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, -ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); }\n        vmbreak;\n      }\n      vmcase(OP_MOD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_mod(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          lua_Number m;\n          luai_nummod(L, nb, nc, m);\n          setfltvalue(ra, m);\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); }\n        vmbreak;\n      }\n      vmcase(OP_IDIV) {  /* floor division */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_div(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numidiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); }\n        vmbreak;\n      }\n      vmcase(OP_POW) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numpow(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); }\n        vmbreak;\n      }\n      vmcase(OP_UNM) {\n        TValue *rb = RB(i);\n        lua_Number nb;\n        if (ttisinteger(rb)) {\n          lua_Integer ib = ivalue(rb);\n          setivalue(ra, intop(-, 0, ib));\n        }\n        else if (tonumber(rb, &nb)) {\n          setfltvalue(ra, luai_numunm(L, nb));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));\n        }\n        vmbreak;\n      }\n      vmcase(OP_BNOT) {\n        TValue *rb = RB(i);\n        lua_Integer ib;\n        if (tointeger(rb, &ib)) {\n          setivalue(ra, intop(^, ~l_castS2U(0), ib));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));\n        }\n        vmbreak;\n      }\n      vmcase(OP_NOT) {\n        TValue *rb = RB(i);\n        int res = l_isfalse(rb);  /* next assignment may change this value */\n        setbvalue(ra, res);\n        vmbreak;\n      }\n      vmcase(OP_LEN) {\n        Protect(luaV_objlen(L, ra, RB(i)));\n        vmbreak;\n      }\n      vmcase(OP_CONCAT) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        StkId rb;\n        L->top = base + c + 1;  /* mark the end of concat operands */\n        Protect(luaV_concat(L, c - b + 1));\n        ra = RA(i);  /* 'luaV_concat' may invoke TMs and move the stack */\n        rb = base + b;\n        setobjs2s(L, ra, rb);\n        checkGC(L, (ra >= rb ? ra + 1 : rb));\n        L->top = ci->top;  /* restore top */\n        vmbreak;\n      }\n      vmcase(OP_JMP) {\n        dojump(ci, i, 0);\n        vmbreak;\n      }\n      vmcase(OP_EQ) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (luaV_equalobj(L, rb, rc) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LT) {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LE) {\n        Protect(\n          if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_TEST) {\n        if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))\n            ci->u.l.savedpc++;\n          else\n          donextjump(ci);\n        vmbreak;\n      }\n      vmcase(OP_TESTSET) {\n        TValue *rb = RB(i);\n        if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))\n          ci->u.l.savedpc++;\n        else {\n          setobjs2s(L, ra, rb);\n          donextjump(ci);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CALL) {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        if (luaD_precall(L, ra, nresults)) {  /* C function? */\n          if (nresults >= 0)\n            L->top = ci->top;  /* adjust results */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {  /* Lua function */\n          ci = L->ci;\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_TAILCALL) {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        if (luaD_precall(L, ra, LUA_MULTRET)) {  /* C function? */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {\n          /* tail call: put called frame (n) in place of caller one (o) */\n          CallInfo *nci = L->ci;  /* called frame */\n          CallInfo *oci = nci->previous;  /* caller frame */\n          StkId nfunc = nci->func;  /* called function */\n          StkId ofunc = oci->func;  /* caller function */\n          /* last stack slot filled by 'precall' */\n          StkId lim = nci->u.l.base + getproto(nfunc)->numparams;\n          int aux;\n          /* close all upvalues from previous call */\n          if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);\n          /* move new frame into old one */\n          for (aux = 0; nfunc + aux < lim; aux++)\n            setobjs2s(L, ofunc + aux, nfunc + aux);\n          oci->u.l.base = ofunc + (nci->u.l.base - nfunc);  /* correct base */\n          oci->top = L->top = ofunc + (L->top - nfunc);  /* correct top */\n          oci->u.l.savedpc = nci->u.l.savedpc;\n          oci->callstatus |= CIST_TAIL;  /* function was tail called */\n          ci = L->ci = oci;  /* remove new frame */\n          lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_RETURN) {\n        int b = GETARG_B(i);\n        if (cl->p->sizep > 0) luaF_close(L, base);\n        b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));\n        if (ci->callstatus & CIST_FRESH)  /* local 'ci' still from callee */\n          return;  /* external invocation: return */\n        else {  /* invocation via reentry: continue execution */\n          ci = L->ci;\n          if (b) L->top = ci->top;\n          lua_assert(isLua(ci));\n          lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n      }\n      vmcase(OP_FORLOOP) {\n        if (ttisinteger(ra)) {  /* integer loop? */\n          lua_Integer step = ivalue(ra + 2);\n          lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */\n          lua_Integer limit = ivalue(ra + 1);\n          if ((0 < step) ? (idx <= limit) : (limit <= idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgivalue(ra, idx);  /* update internal index... */\n            setivalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        else {  /* floating loop */\n          lua_Number step = fltvalue(ra + 2);\n          lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */\n          lua_Number limit = fltvalue(ra + 1);\n          if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                  : luai_numle(limit, idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgfltvalue(ra, idx);  /* update internal index... */\n            setfltvalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        vmbreak;\n      }\n      vmcase(OP_FORPREP) {\n        TValue *init = ra;\n        TValue *plimit = ra + 1;\n        TValue *pstep = ra + 2;\n        lua_Integer ilimit;\n        int stopnow;\n        if (ttisinteger(init) && ttisinteger(pstep) &&\n            forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {\n          /* all values are integer */\n          lua_Integer initv = (stopnow ? 0 : ivalue(init));\n          setivalue(plimit, ilimit);\n          setivalue(init, intop(-, initv, ivalue(pstep)));\n        }\n        else {  /* try making all values floats */\n          lua_Number ninit; lua_Number nlimit; lua_Number nstep;\n          if (!tonumber(plimit, &nlimit))\n            luaG_runerror(L, \"'for' limit must be a number\");\n          setfltvalue(plimit, nlimit);\n          if (!tonumber(pstep, &nstep))\n            luaG_runerror(L, \"'for' step must be a number\");\n          setfltvalue(pstep, nstep);\n          if (!tonumber(init, &ninit))\n            luaG_runerror(L, \"'for' initial value must be a number\");\n          setfltvalue(init, luai_numsub(L, ninit, nstep));\n        }\n        ci->u.l.savedpc += GETARG_sBx(i);\n        vmbreak;\n      }\n      vmcase(OP_TFORCALL) {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb + 3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = ci->top;\n        i = *(ci->u.l.savedpc++);  /* go to next instruction */\n        ra = RA(i);\n        lua_assert(GET_OPCODE(i) == OP_TFORLOOP);\n        goto l_tforloop;\n      }\n      vmcase(OP_TFORLOOP) {\n        l_tforloop:\n        if (!ttisnil(ra + 1)) {  /* continue loop? */\n          setobjs2s(L, ra, ra + 1);  /* save control variable */\n           ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETLIST) {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        unsigned int last;\n        Table *h;\n        if (n == 0) n = cast_int(L->top - ra) - 1;\n        if (c == 0) {\n          lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n          c = GETARG_Ax(*ci->u.l.savedpc++);\n        }\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* preallocate it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          luaH_setint(L, h, last--, val);\n          luaC_barrierback(L, h, val);\n        }\n        L->top = ci->top;  /* correct top (in case of previous open call) */\n        vmbreak;\n      }\n      vmcase(OP_CLOSURE) {\n        Proto *p = cl->p->p[GETARG_Bx(i)];\n        LClosure *ncl = getcached(p, cl->upvals, base);  /* cached closure */\n        if (ncl == NULL)  /* no match? */\n          pushclosure(L, p, cl->upvals, base, ra);  /* create a new one */\n        else\n          setclLvalue(L, ra, ncl);  /* push cashed closure */\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_VARARG) {\n        int b = GETARG_B(i) - 1;  /* required results */\n        int j;\n        int n = cast_int(base - ci->func) - cl->p->numparams - 1;\n        if (n < 0)  /* less arguments than parameters? */\n          n = 0;  /* no vararg arguments */\n        if (b < 0) {  /* B == 0? */\n          b = n;  /* get all var. arguments */\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          L->top = ra + n;\n        }\n        for (j = 0; j < b && j < n; j++)\n          setobjs2s(L, ra + j, base - n + j);\n        for (; j < b; j++)  /* complete required results with nil */\n          setnilvalue(ra + j);\n        vmbreak;\n      }\n      vmcase(OP_EXTRAARG) {\n        lua_assert(0);\n        vmbreak;\n      }\n    }\n  }\n}\n\n/* }================================================================== */\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUA_NOCVTN2S)\n#define cvt2str(o)\tttisnumber(o)\n#else\n#define cvt2str(o)\t0\t/* no conversion from numbers to strings */\n#endif\n\n\n#if !defined(LUA_NOCVTS2N)\n#define cvt2num(o)\tttisstring(o)\n#else\n#define cvt2num(o)\t0\t/* no conversion from strings to numbers */\n#endif\n\n\n/*\n** You can define LUA_FLOORN2I if you want to convert floats to integers\n** by flooring them (instead of raising an error if they are not\n** integral values)\n*/\n#if !defined(LUA_FLOORN2I)\n#define LUA_FLOORN2I\t\t0\n#endif\n\n\n#define tonumber(o,n) \\\n\t(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))\n\n#define tointeger(o,i) \\\n    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n\n#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))\n\n#define luaV_rawequalobj(t1,t2)\t\tluaV_equalobj(NULL,t1,t2)\n\n\n/*\n** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,\n** return 1 with 'slot' pointing to 't[k]' (final result).  Otherwise,\n** return 0 (meaning it will have to check metamethod) with 'slot'\n** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).\n** 'f' is the raw get function to use.\n*/\n#define luaV_fastget(L,t,k,slot,f) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = f(hvalue(t), k),  /* else, do raw access */  \\\n      !ttisnil(slot)))  /* result not nil? */\n\n/*\n** standard implementation for 'gettable'\n*/\n#define luaV_gettable(L,t,k,v) { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else luaV_finishget(L,t,k,v,slot); }\n\n\n/*\n** Fast track for set table. If 't' is a table and 't[k]' is not nil,\n** call GC barrier, do a raw 't[k]=v', and return true; otherwise,\n** return false with 'slot' equal to NULL (if 't' is not a table) or\n** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro\n** returns true, there is no need to 'invalidateTMcache', because the\n** call is not creating a new entry.\n*/\n#define luaV_fastset(L,t,k,slot,f,v) \\\n  (!ttistable(t) \\\n   ? (slot = NULL, 0) \\\n   : (slot = f(hvalue(t), k), \\\n     ttisnil(slot) ? 0 \\\n     : (luaC_barrierback(L, hvalue(t), v), \\\n        setobj2t(L, cast(TValue *,slot), v), \\\n        1)))\n\n\n#define luaV_settable(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    luaV_finishset(L,t,k,v,slot); }\n\n\n\nLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);\nLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);\nLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishOp (lua_State *L);\nLUAI_FUNC void luaV_execute (lua_State *L);\nLUAI_FUNC void luaV_concat (lua_State *L, int total);\nLUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);\nLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.4/src/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0)\n    return EOZ;\n  z->n = size - 1;  /* discount char being returned */\n  z->p = buff;\n  return cast_uchar(*(z->p++));\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (z->n == 0) {  /* no bytes in buffer? */\n      if (luaZ_fill(z) == EOZ)  /* try to read more */\n        return n;  /* no more input; return number of missing bytes */\n      else {\n        z->n++;  /* luaZ_fill consumed first byte; put it back */\n        z->p--;\n      }\n    }\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.4/src/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))\n\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_buffremove(buff,i)\t((buff)->n -= (i))\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \\\n\t\t\t\t(buff)->buffsize, size), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);\t/* read next n bytes */\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\t\t/* reader function */\n  void *data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/Makefile",
    "content": "# Makefile for installing Lua\n# See doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\n# Where to install. The installation starts in the src and doc directories,\n# so take care if INSTALL_TOP is not an absolute path. See the local target.\n# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with\n# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.\nINSTALL_TOP= /usr/local\nINSTALL_BIN= $(INSTALL_TOP)/bin\nINSTALL_INC= $(INSTALL_TOP)/include\nINSTALL_LIB= $(INSTALL_TOP)/lib\nINSTALL_MAN= $(INSTALL_TOP)/man/man1\nINSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V\nINSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V\n\n# How to install. If your install program does not support \"-p\", then\n# you may have to run ranlib on the installed liblua.a.\nINSTALL= install -p\nINSTALL_EXEC= $(INSTALL) -m 0755\nINSTALL_DATA= $(INSTALL) -m 0644\n#\n# If you don't have \"install\" you can use \"cp\" instead.\n# INSTALL= cp -p\n# INSTALL_EXEC= $(INSTALL)\n# INSTALL_DATA= $(INSTALL)\n\n# Other utilities.\nMKDIR= mkdir -p\nRM= rm -f\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\n# Convenience platforms targets.\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\n# What to install.\nTO_BIN= lua luac\nTO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp\nTO_LIB= liblua.a\nTO_MAN= lua.1 luac.1\n\n# Lua version and release.\nV= 5.3\nR= $V.4\n\n# Targets start here.\nall:\t$(PLAT)\n\n$(PLATS) clean:\n\tcd src && $(MAKE) $@\n\ntest:\tdummy\n\tsrc/lua -v\n\ninstall: dummy\n\tcd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)\n\tcd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)\n\tcd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)\n\tcd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)\n\tcd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)\n\nuninstall:\n\tcd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)\n\tcd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)\n\tcd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)\n\tcd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)\n\nlocal:\n\t$(MAKE) install INSTALL_TOP=../install\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\t@echo \"See doc/readme.html for complete instructions.\"\n\n# make may get confused with test/ and install/\ndummy:\n\n# echo config parameters\necho:\n\t@cd src && $(MAKE) -s echo\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"V= $V\"\n\t@echo \"R= $R\"\n\t@echo \"TO_BIN= $(TO_BIN)\"\n\t@echo \"TO_INC= $(TO_INC)\"\n\t@echo \"TO_LIB= $(TO_LIB)\"\n\t@echo \"TO_MAN= $(TO_MAN)\"\n\t@echo \"INSTALL_TOP= $(INSTALL_TOP)\"\n\t@echo \"INSTALL_BIN= $(INSTALL_BIN)\"\n\t@echo \"INSTALL_INC= $(INSTALL_INC)\"\n\t@echo \"INSTALL_LIB= $(INSTALL_LIB)\"\n\t@echo \"INSTALL_MAN= $(INSTALL_MAN)\"\n\t@echo \"INSTALL_LMOD= $(INSTALL_LMOD)\"\n\t@echo \"INSTALL_CMOD= $(INSTALL_CMOD)\"\n\t@echo \"INSTALL_EXEC= $(INSTALL_EXEC)\"\n\t@echo \"INSTALL_DATA= $(INSTALL_DATA)\"\n\n# echo pkg-config data\npc:\n\t@echo \"version=$R\"\n\t@echo \"prefix=$(INSTALL_TOP)\"\n\t@echo \"libdir=$(INSTALL_LIB)\"\n\t@echo \"includedir=$(INSTALL_INC)\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.5/README",
    "content": "\nThis is Lua 5.3.5, released on 26 Jun 2018.\n\nFor installation instructions, license details, and\nfurther information about Lua, see doc/readme.html.\n\n"
  },
  {
    "path": "build/lua-5.3.5/doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"index.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nThe reference manual is the official definition of the Lua language.\n<BR>\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/pil/\">Programming in Lua</A>.\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2018 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<A HREF=\"http://www.lua.org/license.html\">Lua license</A>.\n</SMALL>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL CLASS=\"contents menubar\">\n<LI><A HREF=\"manual.html\">1 &ndash; Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 &ndash; Basic Concepts</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 &ndash; Values and Types</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 &ndash; Environments and the Global Environment</A>\n<LI><A HREF=\"manual.html#2.3\">2.3 &ndash; Error Handling</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 &ndash; Metatables and Metamethods</A>\n<LI><A HREF=\"manual.html#2.5\">2.5 &ndash; Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 &ndash; Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 &ndash; Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 &ndash; Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 &ndash; The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 &ndash; Lexical Conventions</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 &ndash; Variables</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 &ndash; Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#3.3.1\">3.3.1 &ndash; Blocks</A>\n<LI><A HREF=\"manual.html#3.3.2\">3.3.2 &ndash; Chunks</A>\n<LI><A HREF=\"manual.html#3.3.3\">3.3.3 &ndash; Assignment</A>\n<LI><A HREF=\"manual.html#3.3.4\">3.3.4 &ndash; Control Structures</A>\n<LI><A HREF=\"manual.html#3.3.5\">3.3.5 &ndash; For Statement</A>\n<LI><A HREF=\"manual.html#3.3.6\">3.3.6 &ndash; Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#3.3.7\">3.3.7 &ndash; Local Declarations</A>\n</UL>\n<LI><A HREF=\"manual.html#3.4\">3.4 &ndash; Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#3.4.1\">3.4.1 &ndash; Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#3.4.2\">3.4.2 &ndash; Bitwise Operators</A>\n<LI><A HREF=\"manual.html#3.4.3\">3.4.3 &ndash; Coercions and Conversions</A>\n<LI><A HREF=\"manual.html#3.4.4\">3.4.4 &ndash; Relational Operators</A>\n<LI><A HREF=\"manual.html#3.4.5\">3.4.5 &ndash; Logical Operators</A>\n<LI><A HREF=\"manual.html#3.4.6\">3.4.6 &ndash; Concatenation</A>\n<LI><A HREF=\"manual.html#3.4.7\">3.4.7 &ndash; The Length Operator</A>\n<LI><A HREF=\"manual.html#3.4.8\">3.4.8 &ndash; Precedence</A>\n<LI><A HREF=\"manual.html#3.4.9\">3.4.9 &ndash; Table Constructors</A>\n<LI><A HREF=\"manual.html#3.4.10\">3.4.10 &ndash; Function Calls</A>\n<LI><A HREF=\"manual.html#3.4.11\">3.4.11 &ndash; Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#3.5\">3.5 &ndash; Visibility Rules</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 &ndash; The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 &ndash; The Stack</A>\n<LI><A HREF=\"manual.html#4.2\">4.2 &ndash; Stack Size</A>\n<LI><A HREF=\"manual.html#4.3\">4.3 &ndash; Valid and Acceptable Indices</A>\n<LI><A HREF=\"manual.html#4.4\">4.4 &ndash; C Closures</A>\n<LI><A HREF=\"manual.html#4.5\">4.5 &ndash; Registry</A>\n<LI><A HREF=\"manual.html#4.6\">4.6 &ndash; Error Handling in C</A>\n<LI><A HREF=\"manual.html#4.7\">4.7 &ndash; Handling Yields in C</A>\n<LI><A HREF=\"manual.html#4.8\">4.8 &ndash; Functions and Types</A>\n<LI><A HREF=\"manual.html#4.9\">4.9 &ndash; The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 &ndash; The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 &ndash; Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 &ndash; Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#6.1\">6.1 &ndash; Basic Functions</A>\n<LI><A HREF=\"manual.html#6.2\">6.2 &ndash; Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#6.3\">6.3 &ndash; Modules</A>\n<LI><A HREF=\"manual.html#6.4\">6.4 &ndash; String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#6.4.1\">6.4.1 &ndash; Patterns</A>\n<LI><A HREF=\"manual.html#6.4.2\">6.4.2 &ndash; Format Strings for Pack and Unpack</A>\n</UL>\n<LI><A HREF=\"manual.html#6.5\">6.5 &ndash; UTF-8 Support</A>\n<LI><A HREF=\"manual.html#6.6\">6.6 &ndash; Table Manipulation</A>\n<LI><A HREF=\"manual.html#6.7\">6.7 &ndash; Mathematical Functions</A>\n<LI><A HREF=\"manual.html#6.8\">6.8 &ndash; Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#6.9\">6.9 &ndash; Operating System Facilities</A>\n<LI><A HREF=\"manual.html#6.10\">6.10 &ndash; The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#7\">7 &ndash; Lua Standalone</A>\n<P>\n<LI><A HREF=\"manual.html#8\">8 &ndash; Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#8.1\">8.1 &ndash; Changes in the Language</A>\n<LI><A HREF=\"manual.html#8.2\">8.2 &ndash; Changes in the Libraries</A>\n<LI><A HREF=\"manual.html#8.3\">8.3 &ndash; Changes in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#9\">9 &ndash; The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE CLASS=\"menubar\" WIDTH=\"100%\">\n<TR>\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<P>\n<A HREF=\"manual.html#6.1\">basic</A><BR>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawlen\">rawlen</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.2\">coroutine</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.isyieldable\">coroutine.isyieldable</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.10\">debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.getuservalue\">debug.getuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setuservalue\">debug.setuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvalueid\">debug.upvalueid</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvaluejoin\">debug.upvaluejoin</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.8\">io</A><BR>\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<P>\n<A HREF=\"manual.html#6.7\">math</A><BR>\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.maxinteger\">math.maxinteger</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.mininteger\">math.mininteger</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tointeger\">math.tointeger</A><BR>\n<A HREF=\"manual.html#pdf-math.type\">math.type</A><BR>\n<A HREF=\"manual.html#pdf-math.ult\">math.ult</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.9\">os</A><BR>\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.3\">package</A><BR>\n<A HREF=\"manual.html#pdf-package.config\">package.config</A><BR>\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.searchers\">package.searchers</A><BR>\n<A HREF=\"manual.html#pdf-package.searchpath\">package.searchpath</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.4\">string</A><BR>\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.pack\">string.pack</A><BR>\n<A HREF=\"manual.html#pdf-string.packsize\">string.packsize</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.unpack\">string.unpack</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.6\">table</A><BR>\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.move\">table.move</A><BR>\n<A HREF=\"manual.html#pdf-table.pack\">table.pack</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n<A HREF=\"manual.html#pdf-table.unpack\">table.unpack</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.5\">utf8</A><BR>\n<A HREF=\"manual.html#pdf-utf8.char\">utf8.char</A><BR>\n<A HREF=\"manual.html#pdf-utf8.charpattern\">utf8.charpattern</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codepoint\">utf8.codepoint</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codes\">utf8.codes</A><BR>\n<A HREF=\"manual.html#pdf-utf8.len\">utf8.len</A><BR>\n<A HREF=\"manual.html#pdf-utf8.offset\">utf8.offset</A><BR>\n\n<H3><A NAME=\"env\">environment<BR>variables</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_CPATH\">LUA_CPATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_CPATH_5_3\">LUA_CPATH_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT\">LUA_INIT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT_5_3\">LUA_INIT_5_3</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH\">LUA_PATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH_5_3\">LUA_PATH_5_3</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"api\">C API</A></H3>\n<P>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_KContext\">lua_KContext</A><BR>\n<A HREF=\"manual.html#lua_KFunction\">lua_KFunction</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Unsigned\">lua_Unsigned</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n\n<P>\n<A HREF=\"manual.html#lua_absindex\">lua_absindex</A><BR>\n<A HREF=\"manual.html#lua_arith\">lua_arith</A><BR>\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_callk\">lua_callk</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_compare\">lua_compare</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_copy\">lua_copy</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getextraspace\">lua_getextraspace</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_geti\">lua_geti</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_getuservalue\">lua_getuservalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_isinteger\">lua_isinteger</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_isyieldable\">lua_isyieldable</A><BR>\n<A HREF=\"manual.html#lua_len\">lua_len</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdata\">lua_newuserdata</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_numbertointeger\">lua_numbertointeger</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pcallk\">lua_pcallk</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushglobaltable\">lua_pushglobaltable</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawgetp\">lua_rawgetp</A><BR>\n<A HREF=\"manual.html#lua_rawlen\">lua_rawlen</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_rawsetp\">lua_rawsetp</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_rotate\">lua_rotate</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_seti\">lua_seti</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_setuservalue\">lua_setuservalue</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_stringtonumber\">lua_stringtonumber</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tointegerx\">lua_tointegerx</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_tonumberx\">lua_tonumberx</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueid\">lua_upvalueid</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_upvaluejoin\">lua_upvaluejoin</A><BR>\n<A HREF=\"manual.html#lua_version\">lua_version</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n<A HREF=\"manual.html#lua_yieldk\">lua_yieldk</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"auxlib\">auxiliary library</A></H3>\n<P>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<A HREF=\"manual.html#luaL_Stream\">luaL_Stream</A><BR>\n\n<P>\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_buffinitsize\">luaL_buffinitsize</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_checkversion\">luaL_checkversion</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_execresult\">luaL_execresult</A><BR>\n<A HREF=\"manual.html#luaL_fileresult\">luaL_fileresult</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_getsubtable\">luaL_getsubtable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_len\">luaL_len</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadbufferx\">luaL_loadbufferx</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadfilex\">luaL_loadfilex</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newlib\">luaL_newlib</A><BR>\n<A HREF=\"manual.html#luaL_newlibtable\">luaL_newlibtable</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_opt\">luaL_opt</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffsize\">luaL_prepbuffsize</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_pushresultsize\">luaL_pushresultsize</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_requiref\">luaL_requiref</A><BR>\n<A HREF=\"manual.html#luaL_setfuncs\">luaL_setfuncs</A><BR>\n<A HREF=\"manual.html#luaL_setmetatable\">luaL_setmetatable</A><BR>\n<A HREF=\"manual.html#luaL_testudata\">luaL_testudata</A><BR>\n<A HREF=\"manual.html#luaL_tolstring\">luaL_tolstring</A><BR>\n<A HREF=\"manual.html#luaL_traceback\">luaL_traceback</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n<H3><A NAME=\"library\">standard library</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-luaopen_base\">luaopen_base</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_coroutine\">luaopen_coroutine</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_debug\">luaopen_debug</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_io\">luaopen_io</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_math\">luaopen_math</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_os\">luaopen_os</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_package\">luaopen_package</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_string\">luaopen_string</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_table\">luaopen_table</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_utf8\">luaopen_utf8</A><BR>\n\n<H3><A NAME=\"constants\">constants</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_ERRERR\">LUA_ERRERR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRFILE\">LUA_ERRFILE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRGCMM\">LUA_ERRGCMM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRMEM\">LUA_ERRMEM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRRUN\">LUA_ERRRUN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRSYNTAX\">LUA_ERRSYNTAX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCALL\">LUA_HOOKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCOUNT\">LUA_HOOKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKLINE\">LUA_HOOKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKRET\">LUA_HOOKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKTAILCALL\">LUA_HOOKTAILCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCALL\">LUA_MASKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCOUNT\">LUA_MASKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKLINE\">LUA_MASKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKRET\">LUA_MASKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MAXINTEGER\">LUA_MAXINTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MININTEGER\">LUA_MININTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MINSTACK\">LUA_MINSTACK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MULTRET\">LUA_MULTRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_NOREF\">LUA_NOREF</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OK\">LUA_OK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPADD\">LUA_OPADD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBAND\">LUA_OPBAND</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBNOT\">LUA_OPBNOT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBOR\">LUA_OPBOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBXOR\">LUA_OPBXOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPDIV\">LUA_OPDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPEQ\">LUA_OPEQ</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPIDIV\">LUA_OPIDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLE\">LUA_OPLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLT\">LUA_OPLT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMOD\">LUA_OPMOD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMUL\">LUA_OPMUL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPPOW\">LUA_OPPOW</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHL\">LUA_OPSHL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHR\">LUA_OPSHR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSUB\">LUA_OPSUB</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPUNM\">LUA_OPUNM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REFNIL\">LUA_REFNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REGISTRYINDEX\">LUA_REGISTRYINDEX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_GLOBALS\">LUA_RIDX_GLOBALS</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_MAINTHREAD\">LUA_RIDX_MAINTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TBOOLEAN\">LUA_TBOOLEAN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TFUNCTION\">LUA_TFUNCTION</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TLIGHTUSERDATA\">LUA_TLIGHTUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNIL\">LUA_TNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNONE\">LUA_TNONE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNUMBER\">LUA_TNUMBER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TSTRING\">LUA_TSTRING</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTABLE\">LUA_TTABLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTHREAD\">LUA_TTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TUSERDATA\">LUA_TUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_USE_APICHECK\">LUA_USE_APICHECK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_YIELD\">LUA_YIELD</A><BR>\n<A HREF=\"manual.html#pdf-LUAL_BUFFERSIZE\">LUAL_BUFFERSIZE</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n\n<P CLASS=\"footer\">\nLast update:\nMon Jun 18 22:56:06 -03 2018\n</P>\n<!--\nLast change: revised for Lua 5.3.5\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.5/doc/index.css",
    "content": "ul {\n\tlist-style-type: none ;\n}\n\nul.contents {\n\tpadding: 0 ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\ttext-align: left ;\n\tline-height: 1.25 ;\n\twidth: 15% ;\n}\n"
  },
  {
    "path": "build/lua-5.3.5/doc/lua.1",
    "content": ".\\\" $Id: lua.man,v 1.14 2016/10/17 15:43:50 lhf Exp $\n.TH LUA 1 \"$Date: 2016/10/17 15:43:50 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the standalone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nThe given\n.I options\nare handled in order and then\nthe Lua program in file\n.I script\nis loaded and executed.\nThe given\n.I args\nare available to\n.I script\nas strings in a global table named\n.BR arg .\nIf no options or arguments are given,\nthen\n.B \"\\-v \\-i\"\nis assumed when the standard input is a terminal;\notherwise,\n.B \"\\-\"\nis assumed.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf the line contains an expression or list of expressions,\nthen the line is evaluated and the results are printed.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\n.LP\nAt the very start,\nbefore even handling the command line,\n.B lua\nchecks the contents of the environment variables\n.B LUA_INIT_5_3\nor\n.BR LUA_INIT ,\nin that order.\nIf the contents is of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n.SH OPTIONS\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\n.TP\n.B \\-i\nenter interactive mode after executing\n.IR script .\n.TP\n.BI \\-l \" name\"\nexecute the equivalent of\n.IB name =require(' name ')\nbefore executing\n.IR script .\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-E\nignore environment variables.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and execute the standard input as a file.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nThe documentation at lua.org,\nespecially section 7 of the reference manual.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.5/doc/lua.css",
    "content": "html {\n\tbackground-color: #F8F8F8 ;\n}\n\nbody {\n\tbackground-color: #FFFFFF ;\n\tcolor: #000000 ;\n\tfont-family: Helvetica, Arial, sans-serif ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n\tmargin: 16px auto ;\n\tpadding: 32px ;\n\tborder: solid #ccc 1px ;\n\tborder-radius: 20px ;\n\tmax-width: 70em ;\n\twidth: 90% ;\n}\n\nh1, h2, h3, h4 {\n\tcolor: #000080 ;\n\tfont-family: Verdana, Geneva, sans-serif ;\n\tfont-weight: normal ;\n\tfont-style: normal ;\n\ttext-align: left ;\n}\n\nh1 {\n\tfont-size: 28pt ;\n}\n\nh1 img {\n\tvertical-align: text-bottom ;\n}\n\nh2:before {\n\tcontent: \"\\2756\" ;\n\tpadding-right: 0.5em ;\n}\n\na {\n\ttext-decoration: none ;\n}\n\na:link {\n\tcolor: #000080 ;\n}\n\na:link:hover, a:visited:hover {\n\tbackground-color: #D0D0FF ;\n\tcolor: #000080 ;\n\tborder-radius: 4px ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\ndiv.menubar {\n\tpadding-bottom: 0.5em ;\n}\n\np.menubar {\n\tmargin-left: 2.5em ;\n}\n\n.menubar a:hover  {\n\tmargin: -3px -3px -3px -3px ;\n\tpadding: 3px  3px  3px  3px ;\n\tborder-radius: 4px ;\n}\n\n:target {\n\tbackground-color: #F0F0F0 ;\n\tmargin: -8px ;\n\tpadding: 8px ;\n\tborder-radius: 8px ;\n\toutline: none ;\n}\n\nhr {\n\tdisplay: none ;\n}\n\ntable hr {\n\tbackground-color: #a0a0a0 ;\n\tcolor: #a0a0a0 ;\n\tborder: 0 ;\n\theight: 1px ;\n\tdisplay: block ;\n}\n\n.footer {\n\tcolor: gray ;\n\tfont-size: x-small ;\n\ttext-transform: lowercase ;\n}\n\ninput[type=text] {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 2em ;\n\tbackground-image: url('images/search.png') ;\n\tbackground-repeat: no-repeat ;\n\tbackground-position: 4px center ;\n\tpadding-left: 20px ;\n\theight: 2em ;\n}\n\npre.session {\n\tbackground-color: #F8F8F8 ;\n\tpadding: 1em ;\n\tborder-radius: 8px ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tpadding: 0 ;\n\tmargin: 0 ;\n}\n\ntd.gutter {\n\twidth: 4% ;\n}\n\ntable.columns td {\n\tvertical-align: top ;\n\tpadding-bottom: 1em ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n}\n\ntable.book td {\n\tvertical-align: top ;\n}\n\ntable.book td.cover {\n\tpadding-right: 1em ;\n}\n\ntable.book img {\n\tborder: solid #000080 1px ;\n}\n\ntable.book span {\n\tfont-size: small ;\n\ttext-align: left ;\n\tdisplay: block ;\n\tmargin-top: 0.25em ;\n}\n\np.logos a:link:hover, p.logos a:visited:hover {\n\tbackground-color: inherit ;\n}\n\nimg {\n\tbackground-color: white ;\n}\n"
  },
  {
    "path": "build/lua-5.3.5/doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $\n.TH LUAC 1 \"$Date: 2011/11/16 13:53:40 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files containing precompiled chunks\nthat can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\n.B luac\nproduces a single output file containing the combined bytecodes\nfor all files given.\nExecuting the combined file is equivalent to executing the given files.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nPrecompiled chunks are\n.I not\nportable across different architectures.\nMoreover,\nthe internal format of precompiled chunks\nis likely to change when a new version of Lua is released.\nMake sure you save the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\nUse\n.B \\-l \\-l\nfor a full listing.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be one of the given files because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file loads without errors.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nIn particular,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and process standard input.\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nThe documentation at lua.org.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.3.5/doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n\tfont-size: inherit ;\n}\n\npre, code {\n\tfont-size: 12pt ;\n}\n\nspan.apii {\n\tcolor: gray ;\n\tfloat: right ;\n\tfont-family: inherit ;\n\tfont-style: normal ;\n\tfont-size: small ;\n}\n\nh2:before {\n\tcontent: \"\" ;\n\tpadding-right: 0em ;\n}\n"
  },
  {
    "path": "build/lua-5.3.5/doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 Reference Manual</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.3 Reference Manual\n</H1>\n\n<P>\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n\n<P>\n<SMALL>\nCopyright &copy; 2015&ndash;2018 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html\">Lua license</a>.\n</SMALL>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"contents.html#contents\">contents</A>\n&middot;\n<A HREF=\"contents.html#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of,v 1.167.1.2 2018/06/26 15:49:07 roberto Exp $ -->\n\n\n\n\n<h1>1 &ndash; <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is a powerful, efficient, lightweight, embeddable scripting language.\nIt supports procedural programming,\nobject-oriented programming, functional programming,\ndata-driven programming, and data description.\n\n\n<p>\nLua combines simple procedural syntax with powerful data description\nconstructs based on associative arrays and extensible semantics.\nLua is dynamically typed,\nruns by interpreting bytecode with a register-based\nvirtual machine,\nand has automatic memory management with\nincremental garbage collection,\nmaking it ideal for configuration, scripting,\nand rapid prototyping.\n\n\n<p>\nLua is implemented as a library, written in <em>clean C</em>,\nthe common subset of Standard&nbsp;C and C++.\nThe Lua distribution includes a host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete,\nstandalone Lua interpreter,\nfor interactive or batch use.\nLua is intended to be used both as a powerful, lightweight,\nembeddable scripting language for any program that needs one,\nand as a powerful but lightweight and efficient stand-alone language.\n\n\n<p>\nAs an extension language, Lua has no notion of a \"main\" program:\nit works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\n(Frequently, this host is the stand-alone <code>lua</code> program.)\nThe host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua</em>.\n\n\n\n<h1>2 &ndash; <a name=\"2\">Basic Concepts</a></h1>\n\n<p>\nThis section describes the basic concepts of the language.\n\n\n\n<h2>2.1 &ndash; <a name=\"2.1\">Values and Types</a></h2>\n\n<p>\nLua is a <em>dynamically typed language</em>.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are <em>first-class values</em>.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\nThe type <em>nil</em> has one single value, <b>nil</b>,\nwhose main property is to be different from any other value;\nit usually represents the absence of a useful value.\nThe type <em>boolean</em> has two values, <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nany other value makes it true.\nThe type <em>number</em> represents both\ninteger numbers and real (floating-point) numbers.\nThe type <em>string</em> represents immutable sequences of bytes.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit value,\nincluding embedded zeros ('<code>\\0</code>').\nLua is also encoding-agnostic;\nit makes no assumptions about the contents of a string.\n\n\n<p>\nThe type <em>number</em> uses two internal representations,\nor two subtypes,\none called <em>integer</em> and the other called <em>float</em>.\nLua has explicit rules about when each representation is used,\nbut it also converts between them automatically as needed (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\nTherefore,\nthe programmer may choose to mostly ignore the difference\nbetween integers and floats\nor to assume complete control over the representation of each number.\nStandard Lua uses 64-bit integers and double-precision (64-bit) floats,\nbut you can also compile Lua so that it\nuses 32-bit integers and/or single-precision (32-bit) floats.\nThe option with 32 bits for both integers and floats\nis particularly attractive\nfor small machines and embedded systems.\n(See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C (see <a href=\"#3.4.10\">&sect;3.4.10</a>).\nBoth are represented by the type <em>function</em>.\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nA userdata value represents a block of raw memory.\nThere are two kinds of userdata:\n<em>full userdata</em>,\nwhich is an object with a block of memory managed by Lua,\nand <em>light userdata</em>,\nwhich is simply a C&nbsp;pointer value.\nUserdata has no predefined operations in Lua,\nexcept assignment and identity test.\nBy using <em>metatables</em>,\nthe programmer can define operations for full userdata values\n(see <a href=\"#2.4\">&sect;2.4</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by the host program.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.6\">&sect;2.6</a>).\nLua threads are not related to operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads natively.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can have as indices not only numbers,\nbut any Lua value except <b>nil</b> and NaN.\n(<em>Not a Number</em> is a special value used to represent\nundefined or unrepresentable numerical results, such as <code>0/0</code>.)\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nAny key with value <b>nil</b> is not considered part of the table.\nConversely, any key that is not part of a table has\nan associated value <b>nil</b>.\n\n\n<p>\nTables are the sole data-structuring mechanism in Lua;\nthey can be used to represent ordinary arrays, lists,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#3.4.9\">&sect;3.4.9</a>).\n\n\n<p>\nLike indices,\nthe values of table fields can be of any type.\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#3.4.11\">&sect;3.4.11</a>).\n\n\n<p>\nThe indexing of tables follows\nthe definition of raw equality in the language.\nThe expressions <code>a[i]</code> and <code>a[j]</code>\ndenote the same table element\nif and only if <code>i</code> and <code>j</code> are raw equal\n(that is, equal without metamethods).\nIn particular, floats with integral values\nare equal to their respective integers\n(e.g., <code>1.0 == 1</code>).\nTo avoid ambiguities,\nany float with integral value used as a key\nis converted to its respective integer.\nFor instance, if you write <code>a[2.0] = true</code>,\nthe actual key inserted into the table will be the\ninteger <code>2</code>.\n(On the other hand,\n2 and \"<code>2</code>\" are different Lua values and therefore\ndenote different table entries.)\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value (see <a href=\"#6.1\">&sect;6.1</a>).\n\n\n\n\n\n<h2>2.2 &ndash; <a name=\"2.2\">Environments and the Global Environment</a></h2>\n\n<p>\nAs will be discussed in <a href=\"#3.2\">&sect;3.2</a> and <a href=\"#3.3.3\">&sect;3.3.3</a>,\nany reference to a free name\n(that is, a name not bound to any declaration) <code>var</code>\nis syntactically translated to <code>_ENV.var</code>.\nMoreover, every chunk is compiled in the scope of\nan external local variable named <code>_ENV</code> (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nso <code>_ENV</code> itself is never a free name in a chunk.\n\n\n<p>\nDespite the existence of this external <code>_ENV</code> variable and\nthe translation of free names,\n<code>_ENV</code> is a completely regular name.\nIn particular,\nyou can define new variables and parameters with that name.\nEach reference to a free name uses the <code>_ENV</code> that is\nvisible at that point in the program,\nfollowing the usual visibility rules of Lua (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nAny table used as the value of <code>_ENV</code> is called an <em>environment</em>.\n\n\n<p>\nLua keeps a distinguished environment called the <em>global environment</em>.\nThis value is kept at a special index in the C registry (see <a href=\"#4.5\">&sect;4.5</a>).\nIn Lua, the global variable <a href=\"#pdf-_G\"><code>_G</code></a> is initialized with this same value.\n(<a href=\"#pdf-_G\"><code>_G</code></a> is never used internally.)\n\n\n<p>\nWhen Lua loads a chunk,\nthe default value for its <code>_ENV</code> upvalue\nis the global environment (see <a href=\"#pdf-load\"><code>load</code></a>).\nTherefore, by default,\nfree names in Lua code refer to entries in the global environment\n(and, therefore, they are also called <em>global variables</em>).\nMoreover, all standard libraries are loaded in the global environment\nand some functions there operate on that environment.\nYou can use <a href=\"#pdf-load\"><code>load</code></a> (or <a href=\"#pdf-loadfile\"><code>loadfile</code></a>)\nto load a chunk with a different environment.\n(In C, you have to load the chunk and then change the value\nof its first upvalue.)\n\n\n\n\n\n<h2>2.3 &ndash; <a name=\"2.3\">Error Handling</a></h2>\n\n<p>\nBecause Lua is an embedded extension language,\nall Lua actions start from C&nbsp;code in the host program\ncalling a function from the Lua library.\n(When you use Lua standalone,\nthe <code>lua</code> application is the host program.)\nWhenever an error occurs during\nthe compilation or execution of a Lua chunk,\ncontrol returns to the host,\nwhich can take appropriate measures\n(such as printing an error message).\n\n\n<p>\nLua code can explicitly generate an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\nIf you need to catch errors in Lua,\nyou can use <a href=\"#pdf-pcall\"><code>pcall</code></a> or <a href=\"#pdf-xpcall\"><code>xpcall</code></a>\nto call a given function in <em>protected mode</em>.\n\n\n<p>\nWhenever there is an error,\nan <em>error object</em> (also called an <em>error message</em>)\nis propagated with information about the error.\nLua itself only generates errors whose error object is a string,\nbut programs may generate errors with\nany value as the error object.\nIt is up to the Lua program or its host to handle such error objects.\n\n\n<p>\nWhen you use <a href=\"#pdf-xpcall\"><code>xpcall</code></a> or <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nyou may give a <em>message handler</em>\nto be called in case of errors.\nThis function is called with the original error object\nand returns a new error object.\nIt is called before the error unwinds the stack,\nso that it can gather more information about the error,\nfor instance by inspecting the stack and creating a stack traceback.\nThis message handler is still protected by the protected call;\nso, an error inside the message handler\nwill call the message handler again.\nIf this loop goes on for too long,\nLua breaks it and returns an appropriate message.\n(The message handler is called only for regular runtime errors.\nIt is not called for memory-allocation errors\nnor for errors while running finalizers.)\n\n\n\n\n\n<h2>2.4 &ndash; <a name=\"2.4\">Metatables and Metamethods</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain special operations.\nYou can change several aspects of the behavior\nof operations over a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field \"<code>__add</code>\" of the value's metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nThe key for each event in a metatable is a string\nwith the event name prefixed by two underscores;\nthe corresponding values are called <em>metamethods</em>.\nIn the previous example, the key is \"<code>__add</code>\"\nand the metamethod is the function that performs the addition.\nUnless stated otherwise,\nmetamethods should be function values.\n\n\n<p>\nYou can query the metatable of any value\nusing the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\nLua queries metamethods in metatables using a raw access (see <a href=\"#pdf-rawget\"><code>rawget</code></a>).\nSo, to retrieve the metamethod for event <code>ev</code> in object <code>o</code>,\nLua does the equivalent to the following code:\n\n<pre>\n     rawget(getmetatable(<em>o</em>) or {}, \"__<em>ev</em>\")\n</pre>\n\n<p>\nYou can replace the metatable of tables\nusing the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a> function.\nYou cannot change the metatable of other types from Lua code\n(except by using the debug library (<a href=\"#6.10\">&sect;6.10</a>));\nyou should use the C&nbsp;API for that.\n\n\n<p>\nTables and full userdata have individual metatables\n(although multiple tables and userdata can share their metatables).\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\nBy default, a value has no metatable,\nbut the string library sets a metatable for the string type (see <a href=\"#6.4\">&sect;6.4</a>).\n\n\n<p>\nA metatable controls how an object behaves in\narithmetic operations, bitwise operations,\norder comparisons, concatenation, length operation, calls, and indexing.\nA metatable also can define a function to be called\nwhen a userdata or a table is garbage collected (<a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nFor the unary operators (negation, length, and bitwise NOT),\nthe metamethod is computed and called with a dummy second operand,\nequal to the first one.\nThis extra operand is only to simplify Lua's internals\n(by making these operators behave like a binary operation)\nand may be removed in future versions.\n(For most uses this extra operand is irrelevant.)\n\n\n<p>\nA detailed list of events controlled by metatables is given next.\nEach operation is identified by its corresponding key.\n\n\n\n<ul>\n\n<li><b><code>__add</code>: </b>\nthe addition (<code>+</code>) operation.\nIf any operand for an addition is not a number\n(nor a string coercible to a number),\nLua will try to call a metamethod.\nFirst, Lua will check the first operand (even if it is valid).\nIf that operand does not define a metamethod for <code>__add</code>,\nthen Lua will check the second operand.\nIf Lua can find a metamethod,\nit calls the metamethod with the two operands as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nOtherwise,\nit raises an error.\n</li>\n\n<li><b><code>__sub</code>: </b>\nthe subtraction (<code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mul</code>: </b>\nthe multiplication (<code>*</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__div</code>: </b>\nthe division (<code>/</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mod</code>: </b>\nthe modulo (<code>%</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__pow</code>: </b>\nthe exponentiation (<code>^</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__unm</code>: </b>\nthe negation (unary <code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__idiv</code>: </b>\nthe floor division (<code>//</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__band</code>: </b>\nthe bitwise AND (<code>&amp;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither an integer\nnor a value coercible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\n</li>\n\n<li><b><code>__bor</code>: </b>\nthe bitwise OR (<code>|</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bxor</code>: </b>\nthe bitwise exclusive OR (binary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bnot</code>: </b>\nthe bitwise NOT (unary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shl</code>: </b>\nthe bitwise left shift (<code>&lt;&lt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shr</code>: </b>\nthe bitwise right shift (<code>&gt;&gt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__concat</code>: </b>\nthe concatenation (<code>..</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither a string nor a number\n(which is always coercible to a string).\n</li>\n\n<li><b><code>__len</code>: </b>\nthe length (<code>#</code>) operation.\nIf the object is not a string,\nLua will try its metamethod.\nIf there is a metamethod,\nLua calls it with the object as argument,\nand the result of the call\n(always adjusted to one value)\nis the result of the operation.\nIf there is no metamethod but the object is a table,\nthen Lua uses the table length operation (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nOtherwise, Lua raises an error.\n</li>\n\n<li><b><code>__eq</code>: </b>\nthe equal (<code>==</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are either both tables or both full userdata\nand they are not primitively equal.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__lt</code>: </b>\nthe less than (<code>&lt;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are neither both numbers nor both strings.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__le</code>: </b>\nthe less equal (<code>&lt;=</code>) operation.\nUnlike other operations,\nthe less-equal operation can use two different events.\nFirst, Lua looks for the <code>__le</code> metamethod in both operands,\nlike in the less than operation.\nIf it cannot find such a metamethod,\nthen it will try the <code>__lt</code> metamethod,\nassuming that <code>a &lt;= b</code> is equivalent to <code>not (b &lt; a)</code>.\nAs with the other comparison operators,\nthe result is always a boolean.\n(This use of the <code>__lt</code> event can be removed in future versions;\nit is also slower than a real <code>__le</code> metamethod.)\n</li>\n\n<li><b><code>__index</code>: </b>\nThe indexing access operation <code>table[key]</code>.\nThis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nDespite the name,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code> and <code>key</code> as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nIf it is a table,\nthe final result is the result of indexing this table with <code>key</code>.\n(This indexing is regular, not raw,\nand therefore can trigger another metamethod.)\n</li>\n\n<li><b><code>__newindex</code>: </b>\nThe indexing assignment <code>table[key] = value</code>.\nLike the index event,\nthis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metamethod is looked up in <code>table</code>.\n\n\n<p>\nLike with indexing,\nthe metamethod for this event can be either a function or a table.\nIf it is a function,\nit is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.\nIf it is a table,\nLua does an indexing assignment to this table with the same key and value.\n(This assignment is regular, not raw,\nand therefore can trigger another metamethod.)\n\n\n<p>\nWhenever there is a <code>__newindex</code> metamethod,\nLua does not perform the primitive assignment.\n(If necessary,\nthe metamethod itself can call <a href=\"#pdf-rawset\"><code>rawset</code></a>\nto do the assignment.)\n</li>\n\n<li><b><code>__call</code>: </b>\nThe call operation <code>func(args)</code>.\nThis event happens when Lua tries to call a non-function value\n(that is, <code>func</code> is not a function).\nThe metamethod is looked up in <code>func</code>.\nIf present,\nthe metamethod is called with <code>func</code> as its first argument,\nfollowed by the arguments of the original call (<code>args</code>).\nAll results of the call\nare the result of the operation.\n(This is the only metamethod that allows multiple results.)\n</li>\n\n</ul>\n\n<p>\nIt is a good practice to add all needed metamethods to a table\nbefore setting it as a metatable of some object.\nIn particular, the <code>__gc</code> metamethod works only when this order\nis followed (see <a href=\"#2.5.1\">&sect;2.5.1</a>).\n\n\n<p>\nBecause metatables are regular tables,\nthey can contain arbitrary fields,\nnot only the event names defined above.\nSome functions in the standard library\n(e.g., <a href=\"#pdf-tostring\"><code>tostring</code></a>)\nuse other fields in metatables for their own purposes.\n\n\n\n\n\n<h2>2.5 &ndash; <a name=\"2.5\">Garbage Collection</a></h2>\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou do not have to worry about allocating memory for new objects\nor freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> to collect all <em>dead objects</em>\n(that is, objects that are no longer accessible from Lua).\nAll memory used by Lua is subject to automatic management:\nstrings, tables, userdata, functions, threads, internal structures, etc.\n\n\n<p>\nLua implements an incremental mark-and-sweep collector.\nIt uses two numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em> and\nthe <em>garbage-collector step multiplier</em>.\nBoth use percentage points as units\n(e.g., a value of 100 means an internal value of 1).\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nLarger values make the collector less aggressive.\nValues smaller than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\n\n\n<p>\nThe garbage-collector step multiplier\ncontrols the relative speed of the collector relative to\nmemory allocation.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nYou should not use values smaller than 100,\nbecause they make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default is 200,\nwhich means that the collector runs at \"twice\"\nthe speed of memory allocation.\n\n\n<p>\nIf you set the step multiplier to a very large number\n(larger than 10% of the maximum number of\nbytes that the program may use),\nthe collector behaves like a stop-the-world collector.\nIf you then set the pause to 200,\nthe collector behaves as in old Lua versions,\ndoing a complete collection every time Lua doubles its\nmemory usage.\n\n\n<p>\nYou can change these numbers by calling <a href=\"#lua_gc\"><code>lua_gc</code></a> in C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nYou can also use these functions to control\nthe collector directly (e.g., stop and restart it).\n\n\n\n<h3>2.5.1 &ndash; <a name=\"2.5.1\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nYou can set garbage-collector metamethods for tables\nand, using the C&nbsp;API,\nfor full userdata (see <a href=\"#2.4\">&sect;2.4</a>).\nThese metamethods are also called <em>finalizers</em>.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management\n(such as closing files, network or database connections,\nor freeing your own memory).\n\n\n<p>\nFor an object (table or userdata) to be finalized when collected,\nyou must <em>mark</em> it for finalization.\n\nYou mark an object for finalization when you set its metatable\nand the metatable has a field indexed by the string \"<code>__gc</code>\".\nNote that if you set a metatable without a <code>__gc</code> field\nand later create that field in the metatable,\nthe object will not be marked for finalization.\n\n\n<p>\nWhen a marked object becomes garbage,\nit is not collected immediately by the garbage collector.\nInstead, Lua puts it in a list.\nAfter the collection,\nLua goes through that list.\nFor each object in the list,\nit checks the object's <code>__gc</code> metamethod:\nIf it is a function,\nLua calls it with the object as its single argument;\nif the metamethod is not a function,\nLua simply ignores it.\n\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers for objects are called in\nthe reverse order that the objects were marked for finalization,\namong those collected in that cycle;\nthat is, the first finalizer to be called is the one associated\nwith the object marked last in the program.\nThe execution of each finalizer may occur at any point during\nthe execution of the regular code.\n\n\n<p>\nBecause the object being collected must still be used by the finalizer,\nthat object (and other objects accessible only through it)\nmust be <em>resurrected</em> by Lua.\nUsually, this resurrection is transient,\nand the object memory is freed in the next garbage-collection cycle.\nHowever, if the finalizer stores the object in some global place\n(e.g., a global variable),\nthen the resurrection is permanent.\nMoreover, if the finalizer marks a finalizing object for finalization again,\nits finalizer will be called again in the next cycle where the\nobject is unreachable.\nIn any case,\nthe object memory is freed only in a GC cycle where\nthe object is unreachable and not marked for finalization.\n\n\n<p>\nWhen you close a state (see <a href=\"#lua_close\"><code>lua_close</code></a>),\nLua calls the finalizers of all objects marked for finalization,\nfollowing the reverse order that they were marked.\nIf any finalizer marks objects for collection during that phase,\nthese marks have no effect.\n\n\n\n\n\n<h3>2.5.2 &ndash; <a name=\"2.5.2\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect that object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak values allows the collection of its values,\nbut prevents the collection of its keys.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nIf the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',\nthe keys in the table are weak.\nIf <code>__mode</code> contains '<code>v</code>',\nthe values in the table are weak.\n\n\n<p>\nA table with weak keys and strong values\nis also called an <em>ephemeron table</em>.\nIn an ephemeron table,\na value is considered reachable only if its key is reachable.\nIn particular,\nif the only reference to a key comes through its value,\nthe pair is removed.\n\n\n<p>\nAny change in the weakness of a table may take effect only\nat the next collect cycle.\nIn particular, if you change the weakness to a stronger mode,\nLua may still collect some items from that table\nbefore the change takes effect.\n\n\n<p>\nOnly objects that have an explicit construction\nare removed from weak tables.\nValues, such as numbers and light C&nbsp;functions,\nare not subject to garbage collection,\nand therefore are not removed from weak tables\n(unless their associated values are collected).\nAlthough strings are subject to garbage collection,\nthey do not have an explicit construction,\nand therefore are not removed from weak tables.\n\n\n<p>\nResurrected objects\n(that is, objects being finalized\nand objects accessible only through objects being finalized)\nhave a special behavior in weak tables.\nThey are removed from weak values before running their finalizers,\nbut are removed from weak keys only in the next collection\nafter running their finalizers, when such objects are actually freed.\nThis behavior allows the finalizer to access properties\nassociated with the object through weak tables.\n\n\n<p>\nIf a weak table is among the resurrected objects in a collection cycle,\nit may not be properly cleared until the next cycle.\n\n\n\n\n\n\n\n<h2>2.6 &ndash; <a name=\"2.6\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine by calling <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine.\n\n\n<p>\nYou execute a coroutine by calling <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution by\ncalling its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed\nas arguments to that function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn case of normal termination,\n<a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus an error object.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> does not catch errors;\nany error is propagated to the caller.\n\n\n<p>\nAs an example of how coroutines work,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n     \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n<p>\nYou can also create and manipulate coroutines through the C API:\nsee functions <a href=\"#lua_newthread\"><code>lua_newthread</code></a>, <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nand <a href=\"#lua_yield\"><code>lua_yield</code></a>.\n\n\n\n\n\n<h1>3 &ndash; <a name=\"3\">The Language</a></h1>\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nLanguage constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.\nThe complete syntax of Lua can be found in <a href=\"#9\">&sect;9</a>\nat the end of this manual.\n\n\n\n<h2>3.1 &ndash; <a name=\"3.1\">Lexical Conventions</a></h2>\n\n<p>\nLua is a free-form language.\nIt ignores spaces (including new lines) and comments\nbetween lexical elements (tokens),\nexcept as delimiters between names and keywords.\n\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of letters,\ndigits, and underscores,\nnot beginning with a digit and\nnot being a reserved word.\nIdentifiers are used to name variables, table fields, and labels.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif    end\n     false     for       function  goto      if        in\n     local     nil       not       or        repeat    return\n     then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention,\nprograms should avoid creating\nnames that start with an underscore followed by\none or more uppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>).\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     &amp;     ~     |     &lt;&lt;    &gt;&gt;    //\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]     ::\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\nA <em>short literal string</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nA backslash followed by a line break\nresults in a newline in the string.\nThe escape sequence '<code>\\z</code>' skips the following span\nof white-space characters,\nincluding line breaks;\nit is particularly useful to break and indent a long literal string\ninto multiple lines without adding the newlines and spaces\ninto the string contents.\nA short literal string cannot contain unescaped line breaks\nnor escapes not forming a valid escape sequence.\n\n\n<p>\nWe can specify any byte in a short literal string by its numeric value\n(including embedded zeros).\nThis can be done\nwith the escape sequence <code>\\x<em>XX</em></code>,\nwhere <em>XX</em> is a sequence of exactly two hexadecimal digits,\nor with the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a decimal escape sequence is to be followed by a digit,\nit must be expressed using exactly three digits.)\n\n\n<p>\nThe UTF-8 encoding of a Unicode character\ncan be inserted in a literal string with\nthe escape sequence <code>\\u{<em>XXX</em>}</code>\n(note the mandatory enclosing brackets),\nwhere <em>XXX</em> is a sequence of one or more hexadecimal digits\nrepresenting the character code point.\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>, \nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>, \nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance,\na closing long bracket of level&nbsp;4 is written as  <code>]====]</code>.\nA <em>long literal</em> starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nIt can contain any text except a closing bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nAny kind of end-of-line sequence\n(carriage return, newline, carriage return followed by newline,\nor newline followed by carriage return)\nis converted to a simple newline.\n\n\n<p>\nFor convenience,\nwhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nAny byte in a literal string not\nexplicitly affected by the previous rules represents itself.\nHowever, Lua opens files for parsing in text mode,\nand the system file functions may have problems with\nsome control characters.\nSo, it is safer to represent\nnon-text data as a quoted literal with\nexplicit escape sequences for the non-text characters.\n\n\n<p>\nA <em>numeric constant</em> (or <em>numeral</em>)\ncan be written with an optional fractional part\nand an optional decimal exponent,\nmarked by a letter '<code>e</code>' or '<code>E</code>'.\nLua also accepts hexadecimal constants,\nwhich start with <code>0x</code> or <code>0X</code>.\nHexadecimal constants also accept an optional fractional part\nplus an optional binary exponent,\nmarked by a letter '<code>p</code>' or '<code>P</code>'.\nA numeric constant with a radix point or an exponent\ndenotes a float;\notherwise,\nif its value fits in an integer,\nit denotes an integer.\nExamples of valid integer constants are\n\n<pre>\n     3   345   0xff   0xBEBADA\n</pre><p>\nExamples of valid float constants are\n\n<pre>\n     3.0     3.1416     314.16e-2     0.31416E1     34e1\n     0x0.1E  0xA23p-4   0X1.921FB54442D18P+1\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\nLong comments are frequently used to disable code temporarily.\n\n\n\n\n\n<h2>3.2 &ndash; <a name=\"3.2\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers, as defined in <a href=\"#3.1\">&sect;3.1</a>.\n\n\n<p>\nAny variable name is assumed to be global unless explicitly declared\nas a local (see <a href=\"#3.3.7\">&sect;3.3.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;\n</pre><p>\nThe meaning of accesses to table fields can be changed via metatables\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>.</b>&rsquo; Name\n</pre>\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_ENV.x</code>.\nDue to the way that chunks are compiled,\n<code>_ENV</code> is never a global name (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h2>3.3 &ndash; <a name=\"3.3\">Statements</a></h2>\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in Pascal or C.\nThis set includes\nassignments, control structures, function calls,\nand variable declarations.\n\n\n\n<h3>3.3.1 &ndash; <a name=\"3.3.1\">Blocks</a></h3>\n\n<p>\nA block is a list of statements,\nwhich are executed sequentially:\n\n<pre>\n\tblock ::= {stat}\n</pre><p>\nLua has <em>empty statements</em>\nthat allow you to separate statements with semicolons,\nstart a block with a semicolon\nor write two semicolons in sequence:\n\n<pre>\n\tstat ::= &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nFunction calls and assignments\ncan start with an open parenthesis.\nThis possibility leads to an ambiguity in Lua's grammar.\nConsider the following fragment:\n\n<pre>\n     a = b + c\n     (print or io.write)('done')\n</pre><p>\nThe grammar could see it in two ways:\n\n<pre>\n     a = b + c(print or io.write)('done')\n     \n     a = b + c; (print or io.write)('done')\n</pre><p>\nThe current parser always sees such constructions\nin the first way,\ninterpreting the open parenthesis\nas the start of the arguments to a call.\nTo avoid this ambiguity,\nit is a good practice to always precede with a semicolon\nstatements that start with a parenthesis:\n\n<pre>\n     ;(print or io.write)('done')\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> statement in the middle\nof another block (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\n\n\n\n\n\n<h3>3.3.2 &ndash; <a name=\"3.3.2\">Chunks</a></h3>\n\n<p>\nThe unit of compilation of Lua is called a <em>chunk</em>.\nSyntactically,\na chunk is simply a block:\n\n<pre>\n\tchunk ::= block\n</pre>\n\n<p>\nLua handles a chunk as the body of an anonymous function\nwith a variable number of arguments\n(see <a href=\"#3.4.11\">&sect;3.4.11</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\nMoreover, such anonymous function is compiled as in the\nscope of an external local variable called <code>_ENV</code> (see <a href=\"#2.2\">&sect;2.2</a>).\nThe resulting function always has <code>_ENV</code> as its only upvalue,\neven if it does not use that variable.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first <em>loads</em> it,\nprecompiling the chunk's code into instructions for a virtual machine,\nand then Lua executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be precompiled into binary form;\nsee program <code>luac</code> and function <a href=\"#pdf-string.dump\"><code>string.dump</code></a> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly (see <a href=\"#pdf-load\"><code>load</code></a>).\n\n\n\n\n\n<h3>3.3.3 &ndash; <a name=\"3.3.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist &lsquo;<b>=</b>&rsquo; explist\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#3.4\">&sect;3.4</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with as many  <b>nil</b>'s as needed.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then the assignments are performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nAn assignment to a global name <code>x = val</code>\nis equivalent to the assignment\n<code>_ENV.x = val</code> (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n<p>\nThe meaning of assignments to table fields and\nglobal variables (which are actually table fields, too)\ncan be changed via metatables (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.3.4 &ndash; <a name=\"3.3.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#3.3.5\">&sect;3.3.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> are considered false.\nAll values different from <b>nil</b> and <b>false</b> are considered true\n(in particular, the number 0 and the empty string are also true).\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>goto</b> statement transfers the program control to a label.\nFor syntactical reasons,\nlabels in Lua are considered statements too:\n\n\n\n<pre>\n\tstat ::= <b>goto</b> Name\n\tstat ::= label\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n</pre>\n\n<p>\nA label is visible in the entire block where it is defined,\nexcept\ninside nested blocks where a label with the same name is defined and\ninside nested functions.\nA goto may jump to any visible label as long as it does not\nenter into the scope of a local variable.\n\n\n<p>\nLabels and empty statements are called <em>void statements</em>,\nas they perform no actions.\n\n\n<p>\nThe <b>break</b> statement terminates the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk\n(which is an anonymous function).\n\nFunctions can return more than one value,\nso the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n</pre>\n\n<p>\nThe <b>return</b> statement can only be written\nas the last statement of a block.\nIf it is really necessary to <b>return</b> in the middle of a block,\nthen an explicit inner block can be used,\nas in the idiom <code>do return end</code>,\nbecause now <b>return</b> is the last statement in its (inner) block.\n\n\n\n\n\n<h3>3.3.5 &ndash; <a name=\"3.3.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numerical and one generic.\n\n\n<p>\nThe numerical <b>for</b> loop repeats a block of code while a\ncontrol variable runs through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe <em>block</em> is repeated for <em>name</em> starting at the value of\nthe first <em>exp</em>, until it passes the second <em>exp</em> by steps of the\nthird <em>exp</em>.\nMore precisely, a <b>for</b> statement like\n\n<pre>\n     for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)\n       if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end\n       <em>var</em> = <em>var</em> - <em>step</em>\n       while true do\n         <em>var</em> = <em>var</em> + <em>step</em>\n         if (<em>step</em> &gt;= 0 and <em>var</em> &gt; <em>limit</em>) or (<em>step</em> &lt; 0 and <em>var</em> &lt; <em>limit</em>) then\n           break\n         end\n         local v = <em>var</em>\n         <em>block</em>\n       end\n     end\n</pre>\n\n<p>\nNote the following:\n\n<ul>\n\n<li>\nAll three control expressions are evaluated only once,\nbefore the loop starts.\nThey must all result in numbers.\n</li>\n\n<li>\n<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.\nThe names shown here are for explanatory purposes only.\n</li>\n\n<li>\nIf the third expression (the step) is absent,\nthen a step of&nbsp;1 is used.\n</li>\n\n<li>\nYou can use <b>break</b> and <b>goto</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variable <code>v</code> is local to the loop body.\nIf you need its value after the loop,\nassign it to another variable before exiting the loop.\n</li>\n\n</ul>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>\n       while true do\n         local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)\n         if <em>var_1</em> == nil then break end\n         <em>var</em> = <em>var_1</em>\n         <em>block</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\n<code><em>explist</em></code> is evaluated only once.\nIts results are an <em>iterator</em> function,\na <em>state</em>,\nand an initial value for the first <em>iterator variable</em>.\n</li>\n\n<li>\n<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.\nThe names are here for explanatory purposes only.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variables <code><em>var_i</em></code> are local to the loop;\nyou cannot use their values after the <b>for</b> ends.\nIf you need these values,\nthen assign them to other variables before breaking or exiting the loop.\n</li>\n\n</ul>\n\n\n\n\n<h3>3.3.6 &ndash; <a name=\"3.3.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>.\n\n\n\n\n\n<h3>3.3.7 &ndash; <a name=\"3.3.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initial assignment:\n\n<pre>\n\tstat ::= <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist]\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#3.3.3\">&sect;3.3.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nA chunk is also a block (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nand so local variables can be declared in a chunk outside any explicit block.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#3.5\">&sect;3.5</a>.\n\n\n\n\n\n\n\n<h2>3.4 &ndash; <a name=\"3.4\">Expressions</a></h2>\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Numeral\n\texp ::= LiteralString\n\texp ::= functiondef\n\texp ::= tableconstructor\n\texp ::= &lsquo;<b>...</b>&rsquo;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n</pre>\n\n<p>\nNumerals and literal strings are explained in <a href=\"#3.1\">&sect;3.1</a>;\nvariables are explained in <a href=\"#3.2\">&sect;3.2</a>;\nfunction definitions are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>;\nfunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>;\ntable constructors are explained in <a href=\"#3.4.9\">&sect;3.4.9</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nbitwise operators (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nrelational operators (see <a href=\"#3.4.4\">&sect;3.4.4</a>), logical operators (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the concatenation operator (see <a href=\"#3.4.6\">&sect;3.4.6</a>).\nUnary operators comprise the unary minus (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nthe unary bitwise NOT (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nthe unary logical <b>not</b> (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the unary <em>length operator</em> (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf a function call is used as a statement (see <a href=\"#3.3.6\">&sect;3.3.6</a>),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the expression is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\neither discarding all values except the first one\nor adding a single <b>nil</b> if there are no values.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg argument, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg argument)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg arguments\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg arguments\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n<h3>3.4.1 &ndash; <a name=\"3.4.1\">Arithmetic Operators</a></h3><p>\nLua supports the following arithmetic operators:\n\n<ul>\n<li><b><code>+</code>: </b>addition</li>\n<li><b><code>-</code>: </b>subtraction</li>\n<li><b><code>*</code>: </b>multiplication</li>\n<li><b><code>/</code>: </b>float division</li>\n<li><b><code>//</code>: </b>floor division</li>\n<li><b><code>%</code>: </b>modulo</li>\n<li><b><code>^</code>: </b>exponentiation</li>\n<li><b><code>-</code>: </b>unary minus</li>\n</ul>\n\n<p>\nWith the exception of exponentiation and float division,\nthe arithmetic operators work as follows:\nIf both operands are integers,\nthe operation is performed over integers and the result is an integer.\nOtherwise, if both operands are numbers\nor strings that can be converted to\nnumbers (see <a href=\"#3.4.3\">&sect;3.4.3</a>),\nthen they are converted to floats,\nthe operation is performed following the usual rules\nfor floating-point arithmetic\n(usually the IEEE 754 standard),\nand the result is a float.\n\n\n<p>\nExponentiation and float division (<code>/</code>)\nalways convert their operands to floats\nand the result is always a float.\nExponentiation uses the ISO&nbsp;C function <code>pow</code>,\nso that it works for non-integer exponents too.\n\n\n<p>\nFloor division (<code>//</code>) is a division\nthat rounds the quotient towards minus infinity,\nthat is, the floor of the division of its operands.\n\n\n<p>\nModulo is defined as the remainder of a division\nthat rounds the quotient towards minus infinity (floor division).\n\n\n<p>\nIn case of overflows in integer arithmetic,\nall operations <em>wrap around</em>,\naccording to the usual rules of two-complement arithmetic.\n(In other words,\nthey return the unique representable integer\nthat is equal modulo <em>2<sup>64</sup></em> to the mathematical result.)\n\n\n\n<h3>3.4.2 &ndash; <a name=\"3.4.2\">Bitwise Operators</a></h3><p>\nLua supports the following bitwise operators:\n\n<ul>\n<li><b><code>&amp;</code>: </b>bitwise AND</li>\n<li><b><code>&#124;</code>: </b>bitwise OR</li>\n<li><b><code>~</code>: </b>bitwise exclusive OR</li>\n<li><b><code>&gt;&gt;</code>: </b>right shift</li>\n<li><b><code>&lt;&lt;</code>: </b>left shift</li>\n<li><b><code>~</code>: </b>unary bitwise NOT</li>\n</ul>\n\n<p>\nAll bitwise operations convert its operands to integers\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>),\noperate on all bits of those integers,\nand result in an integer.\n\n\n<p>\nBoth right and left shifts fill the vacant bits with zeros.\nNegative displacements shift to the other direction;\ndisplacements with absolute values equal to or higher than\nthe number of bits in an integer\nresult in zero (as all bits are shifted out).\n\n\n\n\n\n<h3>3.4.3 &ndash; <a name=\"3.4.3\">Coercions and Conversions</a></h3><p>\nLua provides some automatic conversions between some\ntypes and representations at run time.\nBitwise operators always convert float operands to integers.\nExponentiation and float division\nalways convert integer operands to floats.\nAll other arithmetic operations applied to mixed numbers\n(integers and floats) convert the integer operand to a float;\nthis is called the <em>usual rule</em>.\nThe C API also converts both integers to floats and\nfloats to integers, as needed.\nMoreover, string concatenation accepts numbers as arguments,\nbesides strings.\n\n\n<p>\nLua also converts strings to numbers,\nwhenever a number is expected.\n\n\n<p>\nIn a conversion from integer to float,\nif the integer value has an exact representation as a float,\nthat is the result.\nOtherwise,\nthe conversion gets the nearest higher or\nthe nearest lower representable value.\nThis kind of conversion never fails.\n\n\n<p>\nThe conversion from float to integer\nchecks whether the float has an exact representation as an integer\n(that is, the float has an integral value and\nit is in the range of integer representation).\nIf it does, that representation is the result.\nOtherwise, the conversion fails.\n\n\n<p>\nThe conversion from strings to numbers goes as follows:\nFirst, the string is converted to an integer or a float,\nfollowing its syntax and the rules of the Lua lexer.\n(The string may have also leading and trailing spaces and a sign.)\nThen, the resulting number (float or integer)\nis converted to the type (float or integer) required by the context\n(e.g., the operation that forced the conversion).\n\n\n<p>\nAll conversions from strings to numbers\naccept both a dot and the current locale mark\nas the radix character.\n(The Lua lexer, however, accepts only a dot.)\n\n\n<p>\nThe conversion from numbers to strings uses a\nnon-specified human-readable format.\nFor complete control over how numbers are converted to strings,\nuse the <code>format</code> function from the string library\n(see <a href=\"#pdf-string.format\"><code>string.format</code></a>).\n\n\n\n\n\n<h3>3.4.4 &ndash; <a name=\"3.4.4\">Relational Operators</a></h3><p>\nLua supports the following relational operators:\n\n<ul>\n<li><b><code>==</code>: </b>equality</li>\n<li><b><code>~=</code>: </b>inequality</li>\n<li><b><code>&lt;</code>: </b>less than</li>\n<li><b><code>&gt;</code>: </b>greater than</li>\n<li><b><code>&lt;=</code>: </b>less or equal</li>\n<li><b><code>&gt;=</code>: </b>greater or equal</li>\n</ul><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nStrings are compared in the obvious way.\nNumbers are equal if they denote the same mathematical value.\n\n\n<p>\nTables, userdata, and threads\nare compared by reference:\ntwo objects are considered equal only if they are the same object.\nEvery time you create a new object\n(a table, userdata, or thread),\nthis new object is different from any previously existing object.\nA closure is always equal to itself.\nClosures with any detectable difference\n(different behavior, different definition) are always different.\nClosures created at different times but with no detectable differences\nmay be classified as equal or not\n(depending on internal caching details).\n\n\n<p>\nYou can change the way that Lua compares tables and userdata\nby using the \"eq\" metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nEquality comparisons do not convert strings to numbers\nor vice versa.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers,\nthen they are compared according to their mathematical values\n(regardless of their subtypes).\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the \"lt\" or the \"le\"\nmetamethod (see <a href=\"#2.4\">&sect;2.4</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n<p>\nFollowing the IEEE 754 standard,\nNaN is considered neither smaller than,\nnor equal to, nor greater than any value (including itself).\n\n\n\n\n\n<h3>3.4.5 &ndash; <a name=\"3.4.5\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#3.3.4\">&sect;3.3.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-circuit evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre><p>\n(In this manual,\n<code>--&gt;</code> indicates the result of the preceding expression.)\n\n\n\n\n\n<h3>3.4.6 &ndash; <a name=\"3.4.6\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers, then they are converted to\nstrings according to the rules described in <a href=\"#3.4.3\">&sect;3.4.3</a>.\nOtherwise, the <code>__concat</code> metamethod is called (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.7 &ndash; <a name=\"3.4.7\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary prefix operator <code>#</code>.\n\n\n<p>\nThe length of a string is its number of bytes\n(that is, the usual meaning of string length when each\ncharacter is one byte).\n\n\n<p>\nThe length operator applied on a table\nreturns a border in that table.\nA <em>border</em> in a table <code>t</code> is any natural number\nthat satisfies the following condition:\n\n<pre>\n     (border == 0 or t[border] ~= nil) and t[border + 1] == nil\n</pre><p>\nIn words,\na border is any (natural) index in a table\nwhere a non-nil value is followed by a nil value\n(or zero, when index 1 is nil).\n\n\n<p>\nA table with exactly one border is called a <em>sequence</em>.\nFor instance, the table <code>{10, 20, 30, 40, 50}</code> is a sequence,\nas it has only one border (5).\nThe table <code>{10, 20, 30, nil, 50}</code> has two borders (3 and 5),\nand therefore it is not a sequence.\nThe table <code>{nil, 20, 30, nil, nil, 60, nil}</code>\nhas three borders (0, 3, and 6),\nso it is not a sequence, too.\nThe table <code>{}</code> is a sequence with border 0.\nNote that non-natural keys do not interfere\nwith whether a table is a sequence.\n\n\n<p>\nWhen <code>t</code> is a sequence,\n<code>#t</code> returns its only border,\nwhich corresponds to the intuitive notion of the length of the sequence.\nWhen <code>t</code> is not a sequence,\n<code>#t</code> can return any of its borders.\n(The exact one depends on details of\nthe internal representation of the table,\nwhich in turn can depend on how the table was populated and\nthe memory addresses of its non-numeric keys.)\n\n\n<p>\nThe computation of the length of a table\nhas a guaranteed worst time of <em>O(log n)</em>,\nwhere <em>n</em> is the largest natural key in the table.\n\n\n<p>\nA program can modify the behavior of the length operator for\nany value but strings through the <code>__len</code> metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.8 &ndash; <a name=\"3.4.8\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     |\n     ~\n     &amp;\n     &lt;&lt;    &gt;&gt;\n     ..\n     +     -\n     *     /     //    %\n     unary operators (not   #     -     ~)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>3.4.9 &ndash; <a name=\"3.4.9\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFinally, fields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive integers\nstarting with 1.\nFields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nThe order of the assignments in a constructor is undefined.\n(This order would be relevant only when there are repeated keys.)\n\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#3.4.10\">&sect;3.4.10</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>3.4.10 &ndash; <a name=\"3.4.10\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, the prefixexp \"call\" metamethod is called,\nhaving as first argument the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp &lsquo;<b>:</b>&rsquo; Name args\n</pre><p>\ncan be used to call \"methods\".\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;\n\targs ::= tableconstructor\n\targs ::= LiteralString\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nA call of the form <code>return <em>functioncall</em></code> is called\na <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument;\nthis syntax makes the calling function return exactly\nthe returns of the called function.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>3.4.11 &ndash; <a name=\"3.4.11\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunctiondef ::= <b>function</b> funcbody\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\nnot to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua precompiles a chunk,\nall its function bodies are precompiled too.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance (or <em>closure</em>)\nis the final value of the expression.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n</pre><p>\nWhen a function is called,\nthe list of arguments is adjusted to\nthe length of the list of parameters,\nunless the function is a <em>vararg function</em>,\nwhich is indicated by three dots ('<code>...</code>')\nat the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL            PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\n\nThere is a system-dependent limit on the number of values\nthat a function may return.\nThis limit is guaranteed to be larger than 1000.\n\n\n<p>\nThe <em>colon</em> syntax\nis used for defining <em>methods</em>,\nthat is, functions that have an implicit extra parameter <code>self</code>.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>3.5 &ndash; <a name=\"3.5\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of a local variable begins at the first statement after\nits declaration and lasts until the last non-void statement\nof the innermost block that includes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called\nan <em>upvalue</em>, or <em>external local variable</em>,\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i=1,10 do\n       local y = 0\n       a[i] = function () y=y+1; return x+y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h1>4 &ndash; <a name=\"4\">The Application Program Interface</a></h1>\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nExcept where stated otherwise,\nall such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments for validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith the macro <a name=\"pdf-LUA_USE_APICHECK\"><code>LUA_USE_APICHECK</code></a> defined.\n\n\n<p>\nThe Lua library is fully reentrant:\nit has no global variables.\nIt keeps all information it needs in a dynamic structure,\ncalled the <em>Lua state</em>.\n\n\n<p>\nEach Lua state has one or more threads,\nwhich correspond to independent, cooperative lines of execution.\nThe type <a href=\"#lua_State\"><code>lua_State</code></a> (despite its name) refers to a thread.\n(Indirectly, through the thread, it also refers to the\nLua state associated to the thread.)\n\n\n<p>\nA pointer to a thread must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch and returns a pointer\nto the <em>main thread</em> in the new state.\n\n\n\n<h2>4.1 &ndash; <a name=\"4.1\">The Stack</a></h2>\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\nFunctions in the API can access this stack through the\nLua state parameter that they receive.\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function can store temporary\nLua values and must push its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an absolute stack position\n(starting at&nbsp;1);\na negative index represents an offset relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\n\n\n\n\n\n<h2>4.2 &ndash; <a name=\"4.2\">Stack Size</a></h2>\n\n<p>\nWhen you interact with the Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto ensure that the stack has enough space for pushing new elements.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that the stack has space for\nat least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> extra slots.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nWhen you call a Lua function\nwithout a fixed number of results (see <a href=\"#lua_call\"><code>lua_call</code></a>),\nLua ensures that the stack has enough space for all results,\nbut it does not ensure any extra space.\nSo, before pushing anything in the stack after such a call\nyou should use <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\n\n\n\n\n\n<h2>4.3 &ndash; <a name=\"4.3\">Valid and Acceptable Indices</a></h2>\n\n<p>\nAny function in the API that receives stack indices\nworks only with <em>valid indices</em> or <em>acceptable indices</em>.\n\n\n<p>\nA <em>valid index</em> is an index that refers to a\nposition that stores a modifiable Lua value.\nIt comprises stack indices between&nbsp;1 and the stack top\n(<code>1 &le; abs(index) &le; top</code>)\n\nplus <em>pseudo-indices</em>,\nwhich represent some positions that are accessible to C&nbsp;code\nbut that are not in the stack.\nPseudo-indices are used to access the registry (see <a href=\"#4.5\">&sect;4.5</a>)\nand the upvalues of a C&nbsp;function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n<p>\nFunctions that do not need a specific mutable position,\nbut only a value (e.g., query functions),\ncan be called with acceptable indices.\nAn <em>acceptable index</em> can be any valid index,\nbut it also can be any positive index after the stack top\nwithin the space allocated for the stack,\nthat is, indices up to the stack size.\n(Note that 0 is never an acceptable index.)\nExcept when noted otherwise,\nfunctions in the API work with acceptable indices.\n\n\n<p>\nAcceptable indices serve to avoid extra tests\nagainst the stack top when querying the stack.\nFor instance, a C&nbsp;function can query its third argument\nwithout the need to first check whether there is a third argument,\nthat is, without the need to check whether 3 is a valid index.\n\n\n<p>\nFor functions that can be called with acceptable indices,\nany non-valid index is treated as if it\ncontains a value of a virtual type <a name=\"pdf-LUA_TNONE\"><code>LUA_TNONE</code></a>,\nwhich behaves like a nil value.\n\n\n\n\n\n<h2>4.4 &ndash; <a name=\"4.4\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>);\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called.\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a href=\"#lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first upvalue associated with a function is at index\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function\n(but not greater than 256,\nwhich is one plus the maximum number of upvalues in a closure),\nproduces an acceptable but invalid index.\n\n\n\n\n\n<h2>4.5 &ndash; <a name=\"4.5\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na predefined table that can be used by any C&nbsp;code to\nstore whatever Lua values it needs to store.\nThe registry table is always located at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it must take care to choose keys\nthat are different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name,\nor a light userdata with the address of a C&nbsp;object in your code,\nor any Lua object created by your code.\nAs with variable names,\nstring keys starting with an underscore followed by\nuppercase letters are reserved for Lua.\n\n\n<p>\nThe integer keys in the registry are used\nby the reference mechanism (see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>)\nand by some predefined values.\nTherefore, integer keys must not be used for other purposes.\n\n\n<p>\nWhen you create a new Lua state,\nits registry comes with some predefined values.\nThese predefined values are indexed with integer keys\ndefined as constants in <code>lua.h</code>.\nThe following constants are defined:\n\n<ul>\n<li><b><a name=\"pdf-LUA_RIDX_MAINTHREAD\"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has\nthe main thread of the state.\n(The main thread is the one created together with the state.)\n</li>\n\n<li><b><a name=\"pdf-LUA_RIDX_GLOBALS\"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has\nthe global environment.\n</li>\n</ul>\n\n\n\n\n<h2>4.6 &ndash; <a name=\"4.6\">Error Handling in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(Lua will use exceptions if you compile it as C++;\nsearch for <code>LUAI_THROW</code> in the source code for details.)\nWhen Lua faces any error\n(such as a memory allocation error or a type error)\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recovery point;\nany error jumps to the most recent active recovery point.\n\n\n<p>\nInside a C&nbsp;function you can raise an error by calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n<p>\nMost functions in the API can raise an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can raise errors.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em> (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>)\nand then calls <code>abort</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning\n(e.g., doing a long jump to your own recovery point outside Lua).\n\n\n<p>\nThe panic function,\nas its name implies,\nis a mechanism of last resort.\nPrograms should avoid it.\nAs a general rule,\nwhen a C&nbsp;function is called by Lua with a Lua state,\nit can do whatever it wants on that Lua state,\nas it should be already protected.\nHowever,\nwhen C code operates on other Lua states\n(e.g., a Lua argument to the function,\na Lua state stored in the registry, or\nthe result of <a href=\"#lua_newthread\"><code>lua_newthread</code></a>),\nit should use them only in API calls that cannot raise errors.\n\n\n<p>\nThe panic function runs as if it were a message handler (see <a href=\"#2.3\">&sect;2.3</a>);\nin particular, the error object is at the top of the stack.\nHowever, there is no guarantee about stack space.\nTo push anything on the stack,\nthe panic function must first check the available space (see <a href=\"#4.2\">&sect;4.2</a>).\n\n\n\n\n\n<h2>4.7 &ndash; <a name=\"4.7\">Handling Yields in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.\nTherefore, if a C&nbsp;function <code>foo</code> calls an API function\nand this API function yields\n(directly or indirectly by calling another function that yields),\nLua cannot return to <code>foo</code> any more,\nbecause the <code>longjmp</code> removes its frame from the C stack.\n\n\n<p>\nTo avoid this kind of problem,\nLua raises an error whenever it tries to yield across an API call,\nexcept for three functions:\n<a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, <a href=\"#lua_callk\"><code>lua_callk</code></a>, and <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\nAll those functions receive a <em>continuation function</em>\n(as a parameter named <code>k</code>) to continue execution after a yield.\n\n\n<p>\nWe need to set some terminology to explain continuations.\nWe have a C&nbsp;function called from Lua which we will call\nthe <em>original function</em>.\nThis original function then calls one of those three functions in the C API,\nwhich we will call the <em>callee function</em>,\nthat then yields the current thread.\n(This can happen when the callee function is <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nor when the callee function is either <a href=\"#lua_callk\"><code>lua_callk</code></a> or <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>\nand the function called by them yields.)\n\n\n<p>\nSuppose the running thread yields while executing the callee function.\nAfter the thread resumes,\nit eventually will finish running the callee function.\nHowever,\nthe callee function cannot return to the original function,\nbecause its frame in the C stack was destroyed by the yield.\nInstead, Lua calls a <em>continuation function</em>,\nwhich was given as an argument to the callee function.\nAs the name implies,\nthe continuation function should continue the task\nof the original function.\n\n\n<p>\nAs an illustration, consider the following function:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       status = lua_pcall(L, n, m, h);  /* calls Lua */\n       ...     /* code 2 */\n     }\n</pre><p>\nNow we want to allow\nthe Lua code being run by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> to yield.\nFirst, we can rewrite our function like here:\n\n<pre>\n     int k (lua_State *L, int status, lua_KContext ctx) {\n       ...  /* code 2 */\n     }\n     \n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcall(L, n, m, h), ctx);\n     }\n</pre><p>\nIn the above code,\nthe new function <code>k</code> is a\n<em>continuation function</em> (with type <a href=\"#lua_KFunction\"><code>lua_KFunction</code></a>),\nwhich should do all the work that the original function\nwas doing after calling <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\nNow, we must inform Lua that it must call <code>k</code> if the Lua code\nbeing executed by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> gets interrupted in some way\n(errors or yielding),\nso we rewrite the code as here,\nreplacing <a href=\"#lua_pcall\"><code>lua_pcall</code></a> by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);\n     }\n</pre><p>\nNote the external, explicit call to the continuation:\nLua will call the continuation only if needed, that is,\nin case of errors or resuming after a yield.\nIf the called function returns normally without ever yielding,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a> (and <a href=\"#lua_callk\"><code>lua_callk</code></a>) will also return normally.\n(Of course, instead of calling the continuation in that case,\nyou can do the equivalent work directly inside the original function.)\n\n\n<p>\nBesides the Lua state,\nthe continuation function has two other parameters:\nthe final status of the call plus the context value (<code>ctx</code>) that\nwas passed originally to <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\n(Lua does not use this context value;\nit only passes this value from the original function to the\ncontinuation function.)\nFor <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nthe status is the same value that would be returned by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nexcept that it is <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when being executed after a yield\n(instead of <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>).\nFor <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> and <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nthe status is always <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when Lua calls the continuation.\n(For these two functions,\nLua will not call the continuation in case of errors,\nbecause they do not handle errors.)\nSimilarly, when using <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nyou should call the continuation function\nwith <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> as the status.\n(For <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, there is not much point in calling\ndirectly the continuation function,\nbecause <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> usually does not return.)\n\n\n<p>\nLua treats the continuation function as if it were the original function.\nThe continuation function receives the same Lua stack\nfrom the original function,\nin the same state it would be if the callee function had returned.\n(For instance,\nafter a <a href=\"#lua_callk\"><code>lua_callk</code></a> the function and its arguments are\nremoved from the stack and replaced by the results from the call.)\nIt also has the same upvalues.\nWhatever it returns is handled by Lua as if it were the return\nof the original function.\n\n\n\n\n\n<h2>4.8 &ndash; <a name=\"4.8\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments\n(e.g., they may depend on what is on the stack).\nThe third field, <code>x</code>,\ntells whether the function may raise errors:\n'<code>-</code>' means the function never raises any error;\n'<code>m</code>' means the function may raise out-of-memory errors\nand errors running a <code>__gc</code> metamethod;\n'<code>e</code>' means the function may raise any errors\n(it can run arbitrary Lua code,\neither directly or through metamethods);\n'<code>v</code>' means the function may raise an error on purpose.\n\n\n\n<hr><h3><a name=\"lua_absindex\"><code>lua_absindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_absindex (lua_State *L, int idx);</pre>\n\n<p>\nConverts the acceptable index <code>idx</code>\ninto an equivalent absolute index\n(that is, one that does not depend on the stack top).\n\n\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block or some code about what\nis being allocated;\nand <code>nsize</code>, the new size of the block.\n\n\n<p>\nWhen <code>ptr</code> is not <code>NULL</code>,\n<code>osize</code> is the size of the block pointed by <code>ptr</code>,\nthat is, the size given when it was allocated or reallocated.\n\n\n<p>\nWhen <code>ptr</code> is <code>NULL</code>,\n<code>osize</code> encodes the kind of object that Lua is allocating.\n<code>osize</code> is any of\n<a href=\"#pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>, <a href=\"#pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>, <a href=\"#pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a href=\"#pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>, or <a href=\"#pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a> when (and only when)\nLua is creating a new object of that type.\nWhen <code>osize</code> is some other value,\nLua is allocating memory for something else.\n\n\n<p>\nLua assumes the following behavior from the allocator function:\n\n\n<p>\nWhen <code>nsize</code> is zero,\nthe allocator must behave like <code>free</code>\nand return <code>NULL</code>.\n\n\n<p>\nWhen <code>nsize</code> is not zero,\nthe allocator must behave like <code>realloc</code>.\nThe allocator returns <code>NULL</code>\nif and only if it cannot fulfill the request.\nLua assumes that the allocator never fails when\n<code>osize &gt;= nsize</code>.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nNote that Standard&nbsp;C ensures\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.\nThis code assumes that <code>realloc</code> does not fail when shrinking a block.\n(Although Standard&nbsp;C does not ensure this behavior,\nit seems to be a safe assumption.)\n\n\n\n\n\n<hr><h3><a name=\"lua_arith\"><code>lua_arith</code></a></h3><p>\n<span class=\"apii\">[-(2|1), +1, <em>e</em>]</span>\n<pre>void lua_arith (lua_State *L, int op);</pre>\n\n<p>\nPerforms an arithmetic or bitwise operation over the two values\n(or one, in the case of negations)\nat the top of the stack,\nwith the value at the top being the second operand,\npops these values, and pushes the result of the operation.\nThe function follows the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPADD\"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSUB\"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMUL\"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>\n<li><b><a name=\"pdf-LUA_OPDIV\"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</code>)</li>\n<li><b><a name=\"pdf-LUA_OPIDIV\"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMOD\"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>\n<li><b><a name=\"pdf-LUA_OPPOW\"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>\n<li><b><a name=\"pdf-LUA_OPUNM\"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBNOT\"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBAND\"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&amp;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBOR\"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBXOR\"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHL\"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code>&lt;&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHR\"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>&gt;&gt;</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one (see <a href=\"#4.6\">&sect;4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs+1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\n\n\n<p>\nTo call a function you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the function are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nAll arguments and the function value are popped from the stack\nwhen the function is called.\nThe function results are pushed onto the stack when the function returns.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, all results from the function are pushed;\nLua takes care that the returned values fit into the stack space,\nbut it does not ensure any extra space in the stack.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error inside the called function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getglobal(L, \"f\");                  /* function to be called */\n     lua_pushliteral(L, \"how\");                       /* 1st argument */\n     lua_getglobal(L, \"t\");                    /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setglobal(L, \"a\");                         /* set global 'a' */\n</pre><p>\nNote that the code above is <em>balanced</em>:\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_callk\"><code>lua_callk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_callk (lua_State *L,\n                int nargs,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numeric arguments and returns their average and their sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0.0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushliteral(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_checkstack (lua_State *L, int n);</pre>\n\n<p>\nEnsures that the stack has space for at least <code>n</code> extra slots\n(that is, that you can safely push up to <code>n</code> values into it).\nIt returns false if it cannot fulfill the request,\neither because it would cause the stack\nto be larger than a fixed maximum size\n(typically at least several thousand elements) or\nbecause it cannot allocate memory for the extra space.\nThis function never shrinks the stack;\nif the stack already has space for the extra slots,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nDestroys all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any)\nand frees all dynamic memory used by this state.\nIn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs that create multiple states,\nsuch as daemons or web servers,\nwill probably need to close states as soon as they are not needed.\n\n\n\n\n\n<hr><h3><a name=\"lua_compare\"><code>lua_compare</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>\n\n<p>\nCompares two Lua values.\nReturns 1 if the value at index <code>index1</code> satisfies <code>op</code>\nwhen compared with the value at index <code>index2</code>,\nfollowing the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is not valid.\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPEQ\"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLT\"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLE\"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result at the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#3.4.6\">&sect;3.4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_copy\"><code>lua_copy</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>\n\n<p>\nCopies the element at index <code>fromidx</code>\ninto the valid index <code>toidx</code>,\nreplacing the value at that position.\nValues at other positions are not affected.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nParameter <code>narr</code> is a hint for how many elements the table\nwill have as a sequence;\nparameter <code>nrec</code> is a hint for how many other elements\nthe table will have.\nLua may use these hints to preallocate memory for the new table.\nThis preallocation is useful for performance when you know in advance\nhow many elements the table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_dump (lua_State *L,\n                        lua_Writer writer,\n                        void *data,\n                        int strip);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nIf <code>strip</code> is true,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nGenerates a Lua error,\nusing the value at the top of the stack as the error object.\nThis function does a long jump,\nand therefore never returns\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_gc (lua_State *L, int what, int data);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>:\n\n<ul>\n\n<li><b><code>LUA_GCSTOP</code>: </b>\nstops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>: </b>\nrestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOLLECT</code>: </b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>: </b>\nreturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>: </b>\nreturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code>: </b>\nperforms an incremental step of garbage collection.\n</li>\n\n<li><b><code>LUA_GCSETPAUSE</code>: </b>\nsets <code>data</code> as the new value\nfor the <em>pause</em> of the collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the pause.\n</li>\n\n<li><b><code>LUA_GCSETSTEPMUL</code>: </b>\nsets <code>data</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>)\nand returns the previous value of the step multiplier.\n</li>\n\n<li><b><code>LUA_GCISRUNNING</code>: </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n<p>\nFor more details about these options,\nsee <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer given when the memory-allocator function was set.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getextraspace\"><code>lua_getextraspace</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_getextraspace (lua_State *L);</pre>\n\n<p>\nReturns a pointer to a raw memory area associated with the\ngiven Lua state.\nThe application can use this area for any purpose;\nLua does not use it for anything.\n\n\n<p>\nEach new thread has this area initialized with a copy\nof the area of the main thread.\n\n\n<p>\nBy default, this area has the size of a pointer to void,\nbut you can recompile Lua with a different size for this area.\n(See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nReturns the type of that value.\n\n\n\n\n\n<hr><h3><a name=\"lua_geti\"><code>lua_geti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_geti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nPushes onto the stack the value <code>t[i]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index has a metatable,\nthe function pushes that metatable onto the stack and returns&nbsp;1.\nOtherwise,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>int lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index\nand <code>k</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the key from the stack,\npushing the resulting value in its place.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack;\nin particular, 0&nbsp;means an empty stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_getuservalue\"><code>lua_getuservalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_getuservalue (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the Lua value associated with the full userdata\nat the given index.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ... lua_Integer;</pre>\n\n<p>\nThe type of integers in Lua.\n\n\n<p>\nBy default this type is <code>long long</code>,\n(usually a 64-bit two-complement integer),\nbut that can be changed to <code>long</code> or <code>int</code>\n(usually a 32-bit two-complement integer).\n(See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n<p>\nLua also defines the constants\n<a name=\"pdf-LUA_MININTEGER\"><code>LUA_MININTEGER</code></a> and <a name=\"pdf-LUA_MAXINTEGER\"><code>LUA_MAXINTEGER</code></a>,\nwith the minimum and the maximum values that fit in this type.\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isinteger\"><code>lua_isinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isinteger (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is an integer\n(that is, the value is a number and is represented as an integer),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isyieldable\"><code>lua_isyieldable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isyieldable (lua_State *L);</pre>\n\n<p>\nReturns 1 if the given coroutine can yield,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_KContext\"><code>lua_KContext</code></a></h3>\n<pre>typedef ... lua_KContext;</pre>\n\n<p>\nThe type for continuation-function contexts.\nIt must be a numeric type.\nThis type is defined as <code>intptr_t</code>\nwhen <code>intptr_t</code> is available,\nso that it can store pointers too.\nOtherwise, it is defined as <code>ptrdiff_t</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_KFunction\"><code>lua_KFunction</code></a></h3>\n<pre>typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);</pre>\n\n<p>\nType for continuation functions (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_len\"><code>lua_len</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the length of the value at the given index.\nIt is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>) and\nmay trigger a metamethod for the \"length\" event (see <a href=\"#2.4\">&sect;2.4</a>).\nThe result is pushed on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname,\n              const char *mode);</pre>\n\n<p>\nLoads a Lua chunk without running it.\nIf there are no errors,\n<code>lua_load</code> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\n\n\n<p>\nThe return values of <code>lua_load</code> are:\n\n<ul>\n\n<li><b><a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>: </b> no errors;</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>: </b>\nsyntax error during precompilation;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation (out-of-memory) error;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\n(This error has no relation with the chunk being loaded.\nIt is generated by the garbage collector.)\n</li>\n\n</ul>\n\n<p>\nThe <code>lua_load</code> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#4.9\">&sect;4.9</a>).\n\n\n<p>\n<code>lua_load</code> automatically detects whether the chunk is text or binary\nand loads it accordingly (see program <code>luac</code>).\nThe string <code>mode</code> works as in function <a href=\"#pdf-load\"><code>load</code></a>,\nwith the addition that\na <code>NULL</code> value is equivalent to the string \"<code>bt</code>\".\n\n\n<p>\n<code>lua_load</code> uses the stack internally,\nso the reader function must always leave the stack\nunmodified when returning.\n\n\n<p>\nIf the resulting function has upvalues,\nits first upvalue is set to the value of the global environment\nstored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href=\"#4.5\">&sect;4.5</a>).\nWhen loading main chunks,\nthis upvalue will be the <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nOther upvalues are initialized with <b>nil</b>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new thread running in a new, independent state.\nReturns <code>NULL</code> if it cannot create the thread or the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua does all memory allocation for this state\nthrough this function (see <a href=\"#lua_Alloc\"><code>lua_Alloc</code></a>).\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\npasses to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new thread returned by this function shares with the original thread\nits global environment,\nbut has an independent execution stack.\n\n\n<p>\nThere is no explicit function to close or to destroy a thread.\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdata\"><code>lua_newuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>\n\n<p>\nThis function allocates a new block of memory with the given size,\npushes onto the stack a new full userdata with the block address,\nand returns this address.\nThe host program can freely use this memory.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>e</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key&ndash;value pair from the table at the given index\n(the \"next\" pair after the given key).\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 (and pushes nothing).\n\n\n<p>\nA typical traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\ndo not call <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> may change\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef ... lua_Number;</pre>\n\n<p>\nThe type of floats in Lua.\n\n\n<p>\nBy default this type is double,\nbut that can be changed to a single float or a long double.\n(See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_numbertointeger\"><code>lua_numbertointeger</code></a></h3>\n<pre>int lua_numbertointeger (lua_Number n, lua_Integer *p);</pre>\n\n<p>\nConverts a Lua float to a Lua integer.\nThis macro assumes that <code>n</code> has an integral value.\nIf that value is within the range of Lua integers,\nit is converted to an integer and assigned to <code>*p</code>.\nThe macro results in a boolean indicating whether the\nconversion was successful.\n(Note that this range test can be tricky to do\ncorrectly without this macro,\ndue to roundings.)\n\n\n<p>\nThis macro may evaluate its arguments more than once.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>\n\n<p>\nCalls a function in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error object),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>msgh</code> is 0,\nthen the error object returned on the stack\nis exactly the original error object.\nOtherwise, <code>msgh</code> is the stack index of a\n<em>message handler</em>.\n(This index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis function will be called with the error object\nand its return value will be the object\nreturned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the message handler is used to add more debug\ninformation to the error object, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns one of the following constants\n(defined in <code>lua.h</code>):\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OK\"><code>LUA_OK</code></a> (0): </b>\nsuccess.</li>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>: </b>\na runtime error.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation error.\nFor such errors, Lua does not call the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>: </b>\nerror while running the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRGCMM\"><code>LUA_ERRGCMM</code></a>: </b>\nerror while running a <code>__gc</code> metamethod.\nFor such errors, Lua does not call the message handler\n(as this kind of error typically has no relation\nwith the function being called).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pcallk\"><code>lua_pcallk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcallk (lua_State *L,\n                int nargs,\n                int nresults,\n                int msgh,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nbut allows the called function to yield (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, &ndash;]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a C&nbsp;closure (see <a href=\"#4.4\">&sect;4.4</a>);\nthese values are then accessible to the function whenever it is called.\nTo associate values with a C&nbsp;function,\nfirst these values must be pushed onto the stack\n(when there are multiple values, the first value is pushed first).\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values will be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n<p>\nWhen <code>n</code> is zero,\nthis function creates a <em>light C&nbsp;function</em>,\nwhich is just a pointer to the C&nbsp;function.\nIn that case, it never raises a memory error.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function receives a pointer to a C&nbsp;function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\n\n\n<p>\nAny function to be callable by Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string.\nIt is similar to the ISO&nbsp;C function <code>sprintf</code>,\nbut has some important differences:\n\n<ul>\n\n<li>\nYou do not have to allocate space for the result:\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\n</li>\n\n<li>\nThe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts the character '<code>%</code>'),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%I</code>' (inserts a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>),\n'<code>%p</code>' (inserts a pointer as a hexadecimal numeral),\n'<code>%d</code>' (inserts an <code>int</code>),\n'<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and\n'<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).\n</li>\n\n</ul>\n\n<p>\nUnlike other push functions,\nthis function checks for the stack space it needs,\nincluding the slot for its result.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushglobaltable\"><code>lua_pushglobaltable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushglobaltable (lua_State *L);</pre>\n\n<p>\nPushes the global environment onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes an integer with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer, a <code>void*</code>.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushstring\"><code>lua_pushstring</code></a>,\nbut should be used only when <code>s</code> is a literal string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain any binary data,\nincluding embedded zeros.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a float with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\n\n\n<p>\nReturns a pointer to the internal copy of the string.\n\n\n<p>\nIf <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, without calling the <code>__eq</code> metamethod).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are not valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>int lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgeti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the table at the given index.\nThe access is raw,\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgetp\"><code>lua_rawgetp</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the table at the given index and\n<code>k</code> is the pointer <code>p</code> represented as a light userdata.\nThe access is raw;\nthat is, it does not invoke the <code>__index</code> metamethod.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawlen\"><code>lua_rawlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>size_t lua_rawlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the raw \"length\" of the value at the given index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>')\nwith no metamethods;\nfor userdata, this is the size of the block of memory allocated\nfor the userdata;\nfor other values, it is&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nDoes the equivalent of <code>t[i] = v</code>,\nwhere <code>t</code> is the table at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke the <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawsetp\"><code>lua_rawsetp</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nDoes the equivalent of <code>t[p] = v</code>,\nwhere <code>t</code> is the table at the given index,\n<code>p</code> is encoded as a light userdata,\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not invoke <code>__newindex</code> metamethod.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time it needs another piece of the chunk,\n<a href=\"#lua_load\"><code>lua_load</code></a> calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>\n\n<p>\nSets the C&nbsp;function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index\nwithout shifting any element\n(therefore replacing the value at that given index),\nand then pops the top element.\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>int lua_resume (lua_State *L, lua_State *from, int nargs);</pre>\n\n<p>\nStarts and resumes a coroutine in the given thread <code>L</code>.\n\n\n<p>\nTo start a coroutine,\nyou push onto the thread stack the main function plus any arguments;\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>nargs</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns, the stack contains all values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nor all values returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\n\n\n<p>\nIn case of errors,\nthe stack is not unwound,\nso you can use the debug API over it.\nThe error object is on the top of the stack.\n\n\n<p>\nTo resume a coroutine,\nyou remove any results from the last <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nput on its stack only the values to\nbe passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nThe parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.\nIf there is no such coroutine,\nthis parameter can be <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_rotate\"><code>lua_rotate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_rotate (lua_State *L, int idx, int n);</pre>\n\n<p>\nRotates the stack elements between the valid index <code>idx</code>\nand the top of the stack.\nThe elements are rotated <code>n</code> positions in the direction of the top,\nfor a positive <code>n</code>,\nor <code>-n</code> positions in the direction of the bottom,\nfor a negative <code>n</code>.\nThe absolute value of <code>n</code> must not be greater than the size\nof the slice being rotated.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_seti\"><code>lua_seti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_seti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nDoes the equivalent to <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and\nsets it as the new metatable for the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index,\n<code>v</code> is the value at the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is larger than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_setuservalue\"><code>lua_setuservalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_setuservalue (lua_State *L, int index);</pre>\n\n<p>\nPops a value from the stack and sets it as\nthe new value associated to the full userdata at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nAn opaque structure that points to a thread and indirectly\n(through the thread) to the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is accessible through this structure.\n\n\n<p>\nA pointer to this structure must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be 0 (<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>) for a normal thread,\nan error code if the thread finished the execution\nof a <a href=\"#lua_resume\"><code>lua_resume</code></a> with an error,\nor <a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n<p>\nYou can only call functions in threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>.\nYou can resume threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>\n(to start a new coroutine) or <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a>\n(to resume a coroutine).\n\n\n\n\n\n<hr><h3><a name=\"lua_stringtonumber\"><code>lua_stringtonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>size_t lua_stringtonumber (lua_State *L, const char *s);</pre>\n\n<p>\nConverts the zero-terminated string <code>s</code> to a number,\npushes that number into the stack,\nand returns the total size of the string,\nthat is, its length plus one.\nThe conversion can result in an integer or a float,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\nThe string may have leading and trailing spaces and a sign.\nIf the string is not a valid numeral,\nreturns 0 and pushes nothing.\n(Note that the result can be used as a boolean,\ntrue if the conversion succeeds.)\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns true for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns false.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tointegerx\"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointegerx\"><code>lua_tointegerx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be an integer,\nor a number or string convertible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <code>lua_tointegerx</code> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <code>lua_tolstring</code> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <code>lua_tolstring</code> is applied to keys during a table traversal.)\n\n\n<p>\n<code>lua_tolstring</code> returns a pointer\nto a string inside the Lua state.\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\n\n\n<p>\nBecause Lua has garbage collection,\nthere is no guarantee that the pointer returned by <code>lua_tolstring</code>\nwill be valid after the corresponding Lua value is removed from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumberx\"><code>lua_tonumberx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, or a function;\notherwise, <code>lua_topointer</code> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for hashing and debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index is a full userdata,\nreturns its block address.\nIf the value is a light userdata,\nreturns its pointer.\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given valid index,\nor <code>LUA_TNONE</code> for a non-valid (but acceptable) index.\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<a name=\"pdf-LUA_TNIL\"><code>LUA_TNIL</code></a> (0),\n<a name=\"pdf-LUA_TNUMBER\"><code>LUA_TNUMBER</code></a>,\n<a name=\"pdf-LUA_TBOOLEAN\"><code>LUA_TBOOLEAN</code></a>,\n<a name=\"pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>,\n<a name=\"pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>,\n<a name=\"pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a name=\"pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>,\n<a name=\"pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a>,\nand\n<a name=\"pdf-LUA_TLIGHTUSERDATA\"><code>LUA_TLIGHTUSERDATA</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *lua_typename (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Unsigned\"><code>lua_Unsigned</code></a></h3>\n<pre>typedef ... lua_Unsigned;</pre>\n\n<p>\nThe unsigned version of <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_upvalueindex (int i);</pre>\n\n<p>\nReturns the pseudo-index that represents the <code>i</code>-th upvalue of\nthe running function (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_version\"><code>lua_version</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const lua_Number *lua_version (lua_State *L);</pre>\n\n<p>\nReturns the address of the version number\n(a C static variable)\nstored in the Lua core.\nWhen called with a valid <a href=\"#lua_State\"><code>lua_State</code></a>,\nreturns the address of the version used to create that state.\nWhen called with <code>NULL</code>,\nreturns the address of the version running the call.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time it produces another piece of chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>data</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the same state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yield (lua_State *L, int nresults);</pre>\n\n<p>\nThis function is equivalent to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nbut it has no continuation (see <a href=\"#4.7\">&sect;4.7</a>).\nTherefore, when the thread resumes,\nit continues the function that called\nthe function calling <code>lua_yield</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yieldk\"><code>lua_yieldk</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>e</em>]</span>\n<pre>int lua_yieldk (lua_State *L,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nYields a coroutine (thread).\n\n\n<p>\nWhen a C&nbsp;function calls <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat will be passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nWhen the coroutine is resumed again,\nLua calls the given continuation function <code>k</code> to continue\nthe execution of the C&nbsp;function that yielded (see <a href=\"#4.7\">&sect;4.7</a>).\nThis continuation function receives the same stack\nfrom the previous function,\nwith the <code>n</code> results removed and\nreplaced by the arguments passed to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\nMoreover,\nthe continuation function receives the value <code>ctx</code>\nthat was passed to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>.\n\n\n<p>\nUsually, this function does not return;\nwhen the coroutine eventually resumes,\nit continues executing the continuation function.\nHowever, there is one special case,\nwhich is when this function is called\nfrom inside a line or a count hook (see <a href=\"#4.9\">&sect;4.9</a>).\nIn that case, <code>lua_yieldk</code> should be called with no continuation\n(probably in the form of <a href=\"#lua_yield\"><code>lua_yield</code></a>) and no results,\nand the hook should return immediately after the call.\nLua will yield and,\nwhen the coroutine resumes again,\nit will continue the normal execution\nof the (Lua) function that triggered the hook.\n\n\n<p>\nThis function can raise an error if it is called from a thread\nwith a pending C call with no continuation function,\nor it is called from a thread that is not running inside a resume\n(e.g., the main thread).\n\n\n\n\n\n\n\n<h2>4.9 &ndash; <a name=\"4.9\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  int currentline;            /* (l) */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  unsigned char nups;         /* (u) number of upvalues */\n  unsigned char nparams;      /* (u) number of parameters */\n  char isvararg;              /* (u) */\n  char istailcall;            /* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about a function or an activation record.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\ncall <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>: </b>\nthe name of the chunk that created the function.\nIf <code>source</code> starts with a '<code>@</code>',\nit means that the function was defined in a file where\nthe file name follows the '<code>@</code>'.\nIf <code>source</code> starts with a '<code>=</code>',\nthe remainder of its contents describe the source in a user-dependent manner.\nOtherwise,\nthe function was defined in a string where\n<code>source</code> is that string.\n</li>\n\n<li><b><code>short_src</code>: </b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>: </b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>: </b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>: </b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk.\n</li>\n\n<li><b><code>currentline</code>: </b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>: </b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>: </b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>istailcall</code>: </b>\ntrue if this function invocation was called by a tail call.\nIn this case, the caller of this level is not in the stack.\n</li>\n\n<li><b><code>nups</code>: </b>\nthe number of upvalues of the function.\n</li>\n\n<li><b><code>nparams</code>: </b>\nthe number of fixed parameters of the function\n(always 0&nbsp;for C&nbsp;functions).\n</li>\n\n<li><b><code>isvararg</code>: </b>\ntrue if the function is a vararg function\n(always true for C&nbsp;functions).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>e</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nGets information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function, you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function from the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getglobal(L, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>': </b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;\n</li>\n\n<li><b>'<code>u</code>': </b> fills in the fields\n<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;\n</li>\n\n<li><b>'<code>f</code>': </b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>': </b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n\n\n<p>\nIf this option is given together with option '<code>f</code>',\nits table is pushed after the function.\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 on error\n(for instance, an invalid option in <code>what</code>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable of\na given activation record or a given function.\n\n\n<p>\nIn the first case,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect;\nsee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for details about variable indices\nand names.\n\n\n<p>\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nIn the second case, <code>ar</code> must be <code>NULL</code> and the function\nto be inspected must be at the top of the stack.\nIn this case, only parameters of Lua functions are visible\n(as there is no information about what variables are active)\nand no values are pushed onto the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGets information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>\n(except for tail calls, which do not count on the stack).\nWhen there are no errors, <a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 1;\nwhen called with a level greater than the stack depth,\nit returns 0.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about the <code>n</code>-th upvalue\nof the closure at index <code>funcindex</code>.\nIt pushes the upvalue's value onto the stack\nand returns its name.\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n\n\n<p>\nUpvalues have no particular order,\nas they are active through the whole function.\nThey are numbered in an arbitrary order.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILCALL\"><code>LUA_HOOKTAILCALL</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nFor call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,\nthe normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;\nin this case, there will be no corresponding return event.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n<p>\nHook functions cannot have continuations,\nthat is, they cannot call <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>, or <a href=\"#lua_callk\"><code>lua_callk</code></a> with a non-null <code>k</code>.\n\n\n<p>\nHook functions can yield under the following conditions:\nOnly count and line events can yield;\nto yield, a hook function must finish its execution\ncalling <a href=\"#lua_yield\"><code>lua_yield</code></a> with <code>nresults</code> equal to zero\n(that is, with no values).\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise OR of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook: </b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function,\nbefore the function gets its arguments.\n</li>\n\n<li><b>The return hook: </b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\nThere is no standard way to access the values\nto be returned by the function.\n</li>\n\n<li><b>The line hook: </b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n<li><b>The count hook: </b> is called after the interpreter executes every\n<code>count</code> instructions.\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n</ul>\n\n<p>\nA hook is disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nIt assigns the value at the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n<p>\nParameters <code>ar</code> and <code>n</code> are as in function <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value at the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueid\"><code>lua_upvalueid</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nReturns a unique identifier for the upvalue numbered <code>n</code>\nfrom the closure at index <code>funcindex</code>.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>,\nbut <code>n</code> cannot be greater than the number of upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvaluejoin\"><code>lua_upvaluejoin</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,\n                                    int funcindex2, int n2);</pre>\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.\n\n\n\n\n\n\n\n<h1>5 &ndash; <a name=\"5\">The Auxiliary Library</a></h1>\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all\ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions and types from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with that API.\nNevertheless, the use of the auxiliary library ensures\nmore consistency to your code.\n\n\n<p>\nSeveral functions in the auxiliary library use internally some\nextra stack slots.\nWhen a function in the auxiliary library uses less than five slots,\nit does not check the stack size;\nit simply assumes that there are enough slots.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n<p>\nFunctions called <code>luaL_check*</code>\nalways raise an error if the check is not satisfied.\n\n\n\n<h2>5.1 &ndash; <a name=\"5.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the byte <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>)\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +?, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value at the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int arg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf it is not, raises an error with a standard message (see <a href=\"#luaL_argerror\"><code>luaL_argerror</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre>\n\n<p>\nRaises an error reporting a problem with argument <code>arg</code>\nof the C&nbsp;function that called it,\nusing a standard message\nthat includes <code>extramsg</code> as a comment:\n\n<pre>\n     bad argument #<em>arg</em> to '<em>funcname</em>' (<em>extramsg</em>)\n</pre><p>\nThis function never returns.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nFinish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nIf you know beforehand the total size of the resulting string,\nyou can use the buffer like this:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it and preallocate a space of\nsize <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>\n\n<li>Then copy the string into that space.</li>\n\n<li>\nFinish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,\nwhere <code>sz</code> is the total size of the resulting string\ncopied into that space.\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a> the stack is back to its\nlevel when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>.\nThis function does not allocate any space;\nthe buffer must be declared as a variable\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinitsize\"><code>luaL_buffinitsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence\n<a href=\"#luaL_buffinit\"><code>luaL_buffinit</code></a>, <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field passing the object as its only argument.\nIn this case this function returns true and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns false (without pushing any value on the stack).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>arg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is an integer\n(or can be converted to an integer)\nand returns this integer cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills <code>*l</code>\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a number\nand returns this number.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int arg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>arg</code> or when this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message\n(or <code>NULL</code> for no additional text).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int arg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>) and\nreturns the userdata address (see <a href=\"#lua_touserdata\"><code>lua_touserdata</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkversion\"><code>luaL_checkversion</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkversion (lua_State *L);</pre>\n\n<p>\nChecks whether the core running the call,\nthe core that created the Lua state,\nand the code making the call are all using the same version of Lua.\nAlso checks whether the core running the call\nand the core that created the Lua state\nare using the same address space.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>e</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, &ndash;]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns false if there are no errors\nor true in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_execresult\"><code>luaL_execresult</code></a></h3><p>\n<span class=\"apii\">[-0, +3, <em>m</em>]</span>\n<pre>int luaL_execresult (lua_State *L, int stat);</pre>\n\n<p>\nThis function produces the return values for\nprocess-related functions in the standard library\n(<a href=\"#pdf-os.execute\"><code>os.execute</code></a> and <a href=\"#pdf-io.close\"><code>io.close</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_fileresult\"><code>luaL_fileresult</code></a></h3><p>\n<span class=\"apii\">[-0, +(1|3), <em>m</em>]</span>\n<pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre>\n\n<p>\nThis function produces the return values for\nfile-related functions in the standard library\n(<a href=\"#pdf-io.open\"><code>io.open</code></a>, <a href=\"#pdf-os.rename\"><code>os.rename</code></a>, <a href=\"#pdf-file:seek\"><code>file:seek</code></a>, etc.).\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code> and returns the type of the pushed value.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\npushes nothing and returns <code>LUA_TNIL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>)\n(<b>nil</b> if there is no metatable associated with that name).\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getsubtable\"><code>luaL_getsubtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre>\n\n<p>\nEnsures that the value <code>t[fname]</code>,\nwhere <code>t</code> is the value at index <code>idx</code>,\nis a table,\nand pushes that table onto the stack.\nReturns true if it finds a previous table there\nand false if it creates a new table.\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code> by replacing\nany occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_len\"><code>luaL_len</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>lua_Integer luaL_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given index\nas a number;\nit is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nRaises an error if the result of the operation is not an integer.\n(This case only can happen through metamethods.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadbufferx\"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbufferx\"><code>luaL_loadbufferx</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbufferx (lua_State *L,\n                      const char *buff,\n                      size_t sz,\n                      const char *name,\n                      const char *mode);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadfilex\"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfilex\"><code>luaL_loadfilex</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfilex (lua_State *L, const char *filename,\n                                            const char *mode);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThe string <code>mode</code> works as in function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>,\nbut it has an extra error code <a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>\nfor file-related errors\n(e.g., it cannot open or read the file).\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlib\"><code>luaL_newlib</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlib (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table and registers there\nthe functions in list <code>l</code>.\n\n\n<p>\nIt is implemented as the following macro:\n\n<pre>\n     (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n</pre><p>\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlibtable\"><code>luaL_newlibtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table with a size optimized\nto store all entries in the array <code>l</code>\n(but does not actually store them).\nIt is intended to be used in conjunction with <a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>\n(see <a href=\"#luaL_newlib\"><code>luaL_newlib</code></a>).\n\n\n<p>\nIt is implemented as a macro.\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds to this new table the pair <code>__name = tname</code>,\nadds to the registry the pair <code>[tname] = new table</code>,\nand returns 1.\n(The entry <code>__name</code> is used by some error-reporting functions.)\n\n\n<p>\nIn both cases pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C <code>realloc</code> function\nand then sets a panic function (see <a href=\"#4.6\">&sect;4.6</a>) that prints\nan error message to the standard error output in case of fatal\nerrors.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_opt\"><code>luaL_opt</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>T luaL_opt (L, func, arg, dflt);</pre>\n\n<p>\nThis macro is defined as follows:\n\n<pre>\n     (lua_isnoneornil(L,(arg)) ? (dflt) : func(L,(arg)))\n</pre><p>\nIn words, if the argument <code>arg</code> is nil or absent,\nthe macro results in the default <code>dflt</code>.\nOtherwise, it results in the result of calling <code>func</code>\nwith the state <code>L</code> and the argument index <code>arg</code> as\narguments.\nNote that it evaluates the expression <code>dflt</code> only if needed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int arg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is an integer\n(or convertible to an integer),\nreturns this integer.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int arg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills the position <code>*l</code> with the result's length.\nIf the result is <code>NULL</code>\n(only possible when returning <code>d</code> and <code>d == NULL</code>),\nits length is considered zero.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a number,\nreturns this number.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int arg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>\nwith the predefined size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nReturns an address to a space of size <code>sz</code>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add\nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresultsize\"><code>luaL_pushresultsize</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence <a href=\"#luaL_addsize\"><code>luaL_addsize</code></a>, <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object at the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nFunction <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference and its associated object.\n\n\n<p>\nIf the object at the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with a sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_requiref\"><code>luaL_requiref</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void luaL_requiref (lua_State *L, const char *modname,\n                    lua_CFunction openf, int glb);</pre>\n\n<p>\nIf <code>modname</code> is not already present in <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a>,\ncalls function <code>openf</code> with string <code>modname</code> as an argument\nand sets the call result in <code>package.loaded[modname]</code>,\nas if that function has been called through <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n<p>\nIf <code>glb</code> is true,\nalso stores the module into global <code>modname</code>.\n\n\n<p>\nLeaves a copy of the module on the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setfuncs\"><code>luaL_setfuncs</code></a></h3><p>\n<span class=\"apii\">[-nup, +0, <em>m</em>]</span>\n<pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>\n\n<p>\nRegisters all functions in the array <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack\n(below optional upvalues, see next).\n\n\n<p>\nWhen <code>nup</code> is not zero,\nall functions are created sharing <code>nup</code> upvalues,\nwhich must be previously pushed on the stack\non top of the library table.\nThese values are popped from the stack after the registration.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setmetatable\"><code>luaL_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nSets the metatable of the object at the top of the stack\nas the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_Stream\"><code>luaL_Stream</code></a></h3>\n<pre>typedef struct luaL_Stream {\n  FILE *f;\n  lua_CFunction closef;\n} luaL_Stream;</pre>\n\n<p>\nThe standard representation for file handles,\nwhich is used by the standard I/O library.\n\n\n<p>\nA file handle is implemented as a full userdata,\nwith a metatable called <code>LUA_FILEHANDLE</code>\n(where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).\nThe metatable is created by the I/O library\n(see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n<p>\nThis userdata must start with the structure <code>luaL_Stream</code>;\nit can contain other data after this initial structure.\nField <code>f</code> points to the corresponding C stream\n(or it can be <code>NULL</code> to indicate an incompletely created handle).\nField <code>closef</code> points to a Lua function\nthat will be called to close the stream\nwhen the handle is closed or collected;\nthis function receives the file handle as its sole argument and\nmust return either <b>true</b> (in case of success)\nor <b>nil</b> plus an error message (in case of error).\nOnce Lua calls this field,\nit changes the field value to <code>NULL</code>\nto signal that the handle is closed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_testudata\"><code>luaL_testudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nThis function works like <a href=\"#luaL_checkudata\"><code>luaL_checkudata</code></a>,\nexcept that, when the test fails,\nit returns <code>NULL</code> instead of raising an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_tolstring\"><code>luaL_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre>\n\n<p>\nConverts any Lua value at the given index to a C&nbsp;string\nin a reasonable format.\nThe resulting string is pushed onto the stack and also\nreturned by the function.\nIf <code>len</code> is not <code>NULL</code>,\nthe function also sets <code>*len</code> with the string length.\n\n\n<p>\nIf the value has a metatable with a <code>__tostring</code> field,\nthen <code>luaL_tolstring</code> calls the corresponding metamethod\nwith the value as argument,\nand uses the result of the call as its result.\n\n\n\n\n\n<hr><h3><a name=\"luaL_traceback\"><code>luaL_traceback</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n                     int level);</pre>\n\n<p>\nCreates and pushes a traceback of the stack <code>L1</code>.\nIf <code>msg</code> is not <code>NULL</code> it is appended\nat the beginning of the traceback.\nThe <code>level</code> parameter tells at which level\nto start the traceback.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>6 &ndash; <a name=\"6\">Standard Libraries</a></h1>\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented directly through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to \"outside\" services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut are quite useful or have critical performance requirements that\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library (<a href=\"#6.1\">&sect;6.1</a>);</li>\n\n<li>coroutine library (<a href=\"#6.2\">&sect;6.2</a>);</li>\n\n<li>package library (<a href=\"#6.3\">&sect;6.3</a>);</li>\n\n<li>string manipulation (<a href=\"#6.4\">&sect;6.4</a>);</li>\n\n<li>basic UTF-8 support (<a href=\"#6.5\">&sect;6.5</a>);</li>\n\n<li>table manipulation (<a href=\"#6.6\">&sect;6.6</a>);</li>\n\n<li>mathematical functions (<a href=\"#6.7\">&sect;6.7</a>) (sin, log, etc.);</li>\n\n<li>input and output (<a href=\"#6.8\">&sect;6.8</a>);</li>\n\n<li>operating system facilities (<a href=\"#6.9\">&sect;6.9</a>);</li>\n\n<li>debug facilities (<a href=\"#6.10\">&sect;6.10</a>).</li>\n\n</ul><p>\nExcept for the basic and the package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nthe host program can open them individually by using\n<a href=\"#luaL_requiref\"><code>luaL_requiref</code></a> to call\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_coroutine\"><code>luaopen_coroutine</code></a> (for the coroutine library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_utf8\"><code>luaopen_utf8</code></a> (for the UTF8 library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the operating system library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>.\n\n\n\n<h2>6.1 &ndash; <a name=\"6.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide\nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\n\n\n<p>\nCalls <a href=\"#pdf-error\"><code>error</code></a> if\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\nIn case of error,\n<code>message</code> is the error object;\nwhen absent, it defaults to \"<code>assertion failed!</code>\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage ([opt [, arg]])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"<code>collect</code>\": </b>\nperforms a full garbage-collection cycle.\nThis is the default option.\n</li>\n\n<li><b>\"<code>stop</code>\": </b>\nstops automatic execution of the garbage collector.\nThe collector will run only when explicitly invoked,\nuntil a call to restart it.\n</li>\n\n<li><b>\"<code>restart</code>\": </b>\nrestarts automatic execution of the garbage collector.\n</li>\n\n<li><b>\"<code>count</code>\": </b>\nreturns the total memory in use by Lua in Kbytes.\nThe value has a fractional part,\nso that it multiplied by 1024\ngives the exact number of bytes in use by Lua\n(except for overflows).\n</li>\n\n<li><b>\"<code>step</code>\": </b>\nperforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>.\nWith a zero value,\nthe collector will perform one basic (indivisible) step.\nFor non-zero values,\nthe collector will perform as if that amount of memory\n(in KBytes) had been allocated by Lua.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"<code>setpause</code>\": </b>\nsets <code>arg</code> as the new value for the <em>pause</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>pause</em>.\n</li>\n\n<li><b>\"<code>setstepmul</code>\": </b>\nsets <code>arg</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.5\">&sect;2.5</a>).\nReturns the previous value for <em>step</em>.\n</li>\n\n<li><b>\"<code>isrunning</code>\": </b>\nreturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile ([filename])</code></a></h3>\nOpens the named file and executes its contents as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller (that is, <code>dofile</code> does not run in protected mode).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nTerminates the last protected function called\nand returns <code>message</code> as the error object.\nFunction <code>error</code> never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message, if the message is a string.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (see <a href=\"#2.2\">&sect;2.2</a>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice versa.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>__metatable</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values (an iterator function, the table <code>t</code>, and 0)\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the key&ndash;value pairs\n(<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,\nup to the first nil value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>\n\n\n<p>\nLoads a chunk.\n\n\n<p>\nIf <code>chunk</code> is a string, the chunk is this string.\nIf <code>chunk</code> is a function,\n<code>load</code> calls it repeatedly to get the chunk pieces.\nEach call to <code>chunk</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no syntactic errors,\nreturns the compiled chunk as a function;\notherwise, returns <b>nil</b> plus the error message.\n\n\n<p>\nIf the resulting function has upvalues,\nthe first upvalue is set to the value of <code>env</code>,\nif that parameter is given,\nor to the value of the global environment.\nOther upvalues are initialized with <b>nil</b>.\n(When you load a main chunk,\nthe resulting function will always have exactly one upvalue,\nthe <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nHowever,\nwhen you load a binary chunk created from a function (see <a href=\"#pdf-string.dump\"><code>string.dump</code></a>),\nthe resulting function can have an arbitrary number of upvalues.)\nAll upvalues are fresh, that is,\nthey are not shared with any other function.\n\n\n<p>\n<code>chunkname</code> is used as the name of the chunk for error messages\nand debug information (see <a href=\"#4.9\">&sect;4.9</a>).\nWhen absent,\nit defaults to <code>chunk</code>, if <code>chunk</code> is a string,\nor to \"<code>=(load)</code>\" otherwise.\n\n\n<p>\nThe string <code>mode</code> controls whether the chunk can be text or binary\n(that is, a precompiled chunk).\nIt may be the string \"<code>b</code>\" (only binary chunks),\n\"<code>t</code>\" (only text chunks),\nor \"<code>bt</code>\" (both binary and text).\nThe default is \"<code>bt</code>\".\n\n\n<p>\nLua does not check the consistency of binary chunks.\nMaliciously crafted binary chunks can crash\nthe interpreter.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\n<code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numerical order,\nuse a numerical <b>for</b>.)\n\n\n<p>\nThe behavior of <code>next</code> is undefined if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may clear existing fields.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nIf <code>t</code> has a metamethod <code>__pairs</code>,\ncalls it with <code>t</code> as argument and returns the first three\nresults from the call.\n\n\n<p>\nOtherwise,\nreturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCalls function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments\nand prints their values to <code>stdout</code>,\nusing the <a href=\"#pdf-tostring\"><code>tostring</code></a> function to convert each argument to a string.\n<code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\nfor instance for debugging.\nFor complete control over the output,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a> and <a href=\"#pdf-io.write\"><code>io.write</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking the <code>__eq</code> metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout invoking the <code>__index</code> metamethod.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawlen\"><code>rawlen (v)</code></a></h3>\nReturns the length of the object <code>v</code>,\nwhich must be a table or a string,\nwithout invoking the <code>__len</code> metamethod.\nReturns an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout invoking the <code>__newindex</code> metamethod.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b> and NaN,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>;\na negative number indexes from the end (-1 is the last argument).\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\n(To change the metatable of other types from Lua code,\nyou must use the debug library (<a href=\"#6.10\">&sect;6.10</a>).)\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>__metatable</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\n\n\n<p>\nWhen called with no <code>base</code>,\n<code>tonumber</code> tries to convert its argument to a number.\nIf the argument is already a number or\na string convertible to a number,\nthen <code>tonumber</code> returns this number;\notherwise, it returns <b>nil</b>.\n\n\n<p>\nThe conversion of strings can result in integers or floats,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\n(The string may have leading and trailing spaces and a sign.)\n\n\n<p>\nWhen called with <code>base</code>,\nthen <code>e</code> must be a string to be interpreted as\nan integer numeral in that base.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIf the string <code>e</code> is not a valid numeral in the given base,\nthe function returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (v)</code></a></h3>\nReceives a value of any type and\nconverts it to a string in a human-readable format.\n(For complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.)\n\n\n<p>\nIf the metatable of <code>v</code> has a <code>__tostring</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>v</code> as argument,\nand uses the result of the call as its result.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\n\n\n<p>\nA global variable (not a function) that\nholds a string containing the running Lua version.\nThe current value of this variable is \"<code>Lua 5.3</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that it sets a new message handler <code>msgh</code>.\n\n\n\n\n\n\n\n<h2>6.2 &ndash; <a name=\"6.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThis library comprises the operations to manipulate coroutines,\nwhich come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.6\">&sect;2.6</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.isyieldable\"><code>coroutine.isyieldable ()</code></a></h3>\n\n\n<p>\nReturns true when the running coroutine can yield.\n\n\n<p>\nA running coroutine is yieldable if it is not the main thread and\nit is not inside a non-yieldable C&nbsp;function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, ... are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, ... are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(when the coroutine yields) or any values returned by the body function\n(when the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine plus a boolean,\ntrue when the running coroutine is the main one.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running (that is, it called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to the function behave as the\nextra arguments to <code>resume</code>.\nReturns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error, propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>6.3 &ndash; <a name=\"6.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading modules in Lua.\nIt exports one function directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a>.\nEverything else is exported in a table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a> sequence.\nBy changing this sequence,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which must be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with two arguments:\n<code>modname</code> and an extra value dependent on how it got the loader.\n(If the loader came from a file,\nthis extra value is the file name.)\nIf the loader returns any non-nil value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader does not return a non-nil value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> raises an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.config\"><code>package.config</code></a></h3>\n\n\n<p>\nA string describing some compile-time configurations for packages.\nThis string is a sequence of lines:\n\n<ul>\n\n<li>The first line is the directory separator string.\nDefault is '<code>\\</code>' for Windows and '<code>/</code>' for all other systems.</li>\n\n<li>The second line is the character that separates templates in a path.\nDefault is '<code>;</code>'.</li>\n\n<li>The third line is the string that marks the\nsubstitution points in a template.\nDefault is '<code>?</code>'.</li>\n\n<li>The fourth line is a string that, in a path in Windows,\nis replaced by the executable's directory.\nDefault is '<code>!</code>'.</li>\n\n<li>The fifth line is a mark to ignore all text after it\nwhen building the <code>luaopen_</code> function name.\nDefault is '<code>-</code>'.</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH_5_3\"><code>LUA_CPATH_5_3</code></a>,\nor the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>,\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\n\n\n<p>\nIf <code>funcname</code> is \"<code>*</code>\",\nthen it only links with the library,\nmaking the symbols exported by the library\navailable to other dynamically linked libraries.\nOtherwise,\nit looks for a function <code>funcname</code> inside the library\nand returns this function as a C&nbsp;function.\nSo, <code>funcname</code> must follow the <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a> prototype\n(see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and an extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by Standard&nbsp;C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH_5_3\"><code>LUA_PATH_5_3</code></a> or\nthe environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif those environment variables are not defined.\nAny \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchers\"><code>package.searchers</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to load modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole parameter.\nThe function can return another function (the module <em>loader</em>)\nplus an extra value that will be passed to that loader,\nor a string explaining why it did not find that module\n(or <b>nil</b> if it has nothing to say).\n\n\n<p>\nLua initializes this table with four searcher functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nThe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nAgain,\nthe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits suffix after (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.b.c-v2.1</code>,\nthe function name will be <code>luaopen_a_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n<p>\nAll searchers except the first one (preload) return as the extra value\nthe file name where the module was found,\nas returned by <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nThe first searcher returns no extra value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchpath\"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3>\n\n\n<p>\nSearches for the given <code>name</code> in the given <code>path</code>.\n\n\n<p>\nA path is a string containing a sequence of\n<em>templates</em> separated by semicolons.\nFor each template,\nthe function replaces each interrogation mark (if any)\nin the template with a copy of <code>name</code>\nwherein all occurrences of <code>sep</code>\n(a dot, by default)\nwere replaced by <code>rep</code>\n(the system's directory separator, by default),\nand then tries to open the resulting file name.\n\n\n<p>\nFor instance, if the path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for the name <code>foo.a</code>\nwill try to open the files\n<code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and\n<code>/usr/local/foo/a/init.lua</code>, in that order.\n\n\n<p>\nReturns the resulting name of the first file that it can\nopen in read mode (after closing the file),\nor <b>nil</b> plus an error message if none succeeds.\n(This error message lists all file names it tried to open.)\n\n\n\n\n\n\n\n<h2>6.4 &ndash; <a name=\"6.4\">String Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s,i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numeric codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, ..., <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\nThese indices are corrected\nfollowing the same rules of function <a href=\"#pdf-string.sub\"><code>string.sub</code></a>.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numeric code equal\nto its corresponding argument.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function [, strip])</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation\n(a <em>binary chunk</em>)\nof the given function,\nso that a later <a href=\"#pdf-load\"><code>load</code></a> on this string returns\na copy of the function (but with new upvalues).\nIf <code>strip</code> is a true value,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nFunctions with upvalues have only their number of upvalues saved.\nWhen (re)loaded,\nthose upvalues receive fresh instances containing <b>nil</b>.\n(You can use the debug library to serialize\nand reload the upvalues of a function\nin a way adequate to your needs.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\n\n\n<p>\nLooks for the first match of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>nil</b>.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered magic.\nNote that if <code>plain</code> is given, then <code>init</code> must be given as well.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument (which must be a string).\nThe format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.\nThe only differences are that the options/modifiers\n<code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>,\nand <code>p</code> are not supported\nand that there is an extra option, <code>q</code>.\n\n\n<p>\nThe <code>q</code> option formats a string between double quotes,\nusing escape sequences when necessary to ensure that\nit can safely be read back by the Lua interpreter.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nmay produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre>\n\n<p>\nOptions\n<code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>G</code>, and <code>g</code> all expect a number as argument.\nOptions <code>c</code>, <code>d</code>,\n<code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>\nexpect an integer.\nWhen Lua is compiled with a C89 compiler,\noptions <code>A</code> and <code>a</code> (hexadecimal floats)\ndo not support any modifier (flags, width, length).\n\n\n<p>\nOption <code>s</code> expects a string;\nif its argument is not a string,\nit is converted to one following the same rules of <a href=\"#pdf-tostring\"><code>tostring</code></a>.\nIf the option has any modifier (flags, width, length),\nthe string argument should not contain embedded zeros.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern)</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>)\nover the string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\n\n\n<p>\nAs an example, the following loop\nwill iterate over all the words from string <code>s</code>,\nprinting one per line:\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a caret '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\nThe name <code>gsub</code> comes from <em>Global SUBstitution</em>.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>d</em></code>,\nwith <em>d</em> between 1 and 9,\nstands for the value of the <em>d</em>-th captured substring.\nThe sequence <code>%0</code> stands for the whole match.\nThe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order.\n\n\n<p>\nIn any case,\nif the pattern specifies no captures,\nthen it behaves as if the whole pattern was inside a capture.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return load(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.3\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.3.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\nLooks for the first <em>match</em> of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>nil</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.pack\"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.\npacked (that is, serialized in binary form)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.packsize\"><code>string.packsize (fmt)</code></a></h3>\n\n\n<p>\nReturns the size of a string resulting from <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nwith the given format.\nThe format string cannot have the variable-length options\n'<code>s</code>' or '<code>z</code>' (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n [, sep])</code></a></h3>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code> separated by the string <code>sep</code>.\nThe default value for <code>sep</code> is the empty string\n(that is, no separator).\nReturns the empty string if <code>n</code> is not positive.\n\n\n<p>\n(Note that it is very easy to exhaust the memory of your machine\nwith a single call to this function.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> (for a positive <code>i</code>)\nreturns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n<p>\nIf, after the translation of negative indices,\n<code>i</code> is less than 1,\nit is corrected to 1.\nIf <code>j</code> is greater than the string length,\nit is corrected to that length.\nIf, after these corrections,\n<code>i</code> is greater than <code>j</code>,\nthe function returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.unpack\"><code>string.unpack (fmt, s [, pos])</code></a></h3>\n\n\n<p>\nReturns the values packed in string <code>s</code> (see <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\nAn optional <code>pos</code> marks where\nto start reading in <code>s</code> (default is 1).\nAfter the read values,\nthis function also returns the index of the first unread byte in <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n\n\n<h3>6.4.1 &ndash; <a name=\"6.4.1\">Patterns</a></h3>\n\n<p>\nPatterns in Lua are described by regular strings,\nwhich are interpreted as patterns by the pattern-matching functions\n<a href=\"#pdf-string.find\"><code>string.find</code></a>,\n<a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>,\n<a href=\"#pdf-string.gsub\"><code>string.gsub</code></a>,\nand <a href=\"#pdf-string.match\"><code>string.match</code></a>.\nThis section describes the syntax and the meaning\n(that is, what they match) of these strings.\n\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>: </b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>: </b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>: </b> represents all letters.</li>\n\n<li><b><code>%c</code>: </b> represents all control characters.</li>\n\n<li><b><code>%d</code>: </b> represents all digits.</li>\n\n<li><b><code>%g</code>: </b> represents all printable characters except space.</li>\n\n<li><b><code>%l</code>: </b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>: </b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>: </b> represents all space characters.</li>\n\n<li><b><code>%u</code>: </b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>\n\n<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny non-alphanumeric character\n(including all punctuation characters, even the non-magical)\ncan be preceded by a '<code>%</code>'\nwhen used to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>: </b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range,\nin ascending order, with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nYou can put a closing square bracket in a set\nby positioning it as the first character in the set.\nYou can put a hyphen in a set\nby positioning it as the first or the last character in the set.\n(You can also use an escape for both cases.)\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>: </b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches zero or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches one or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches zero or more repetitions of characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the shortest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches zero or one occurrence of a character in the class.\nIt always matches one occurrence if possible;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n<li>\n<code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;\nsuch item matches an empty string at any position such that\nthe next character belongs to <em>set</em>\nand the previous character does not belong to <em>set</em>.\nThe set <em>set</em> is interpreted as previously described.\nThe beginning and the end of the subject are handled as if\nthey were the character '<code>\\0</code>'.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA caret '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture (and therefore has number&nbsp;1);\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the empty capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n\n\n\n\n\n<h3>6.4.2 &ndash; <a name=\"6.4.2\">Format Strings for Pack and Unpack</a></h3>\n\n<p>\nThe first argument to <a href=\"#pdf-string.pack\"><code>string.pack</code></a>,\n<a href=\"#pdf-string.packsize\"><code>string.packsize</code></a>, and <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>\nis a format string,\nwhich describes the layout of the structure being created or read.\n\n\n<p>\nA format string is a sequence of conversion options.\nThe conversion options are as follows:\n\n<ul>\n<li><b><code>&lt;</code>: </b>sets little endian</li>\n<li><b><code>&gt;</code>: </b>sets big endian</li>\n<li><b><code>=</code>: </b>sets native endian</li>\n<li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>\n(default is native alignment)</li>\n<li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>\n<li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>\n<li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>\n<li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>\n<li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>\n<li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>\n<li><b><code>j</code>: </b>a <code>lua_Integer</code></li>\n<li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>\n<li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>\n<li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>f</code>: </b>a <code>float</code> (native size)</li>\n<li><b><code>d</code>: </b>a <code>double</code> (native size)</li>\n<li><b><code>n</code>: </b>a <code>lua_Number</code></li>\n<li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>\n<li><b><code>z</code>: </b>a zero-terminated string</li>\n<li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length\ncoded as an unsigned integer with <code>n</code> bytes\n(default is a <code>size_t</code>)</li>\n<li><b><code>x</code>: </b>one byte of padding</li>\n<li><b><code>X<em>op</em></code>: </b>an empty item that aligns\naccording to option <code>op</code>\n(which is otherwise ignored)</li>\n<li><b>'<code> </code>': </b>(empty space) ignored</li>\n</ul><p>\n(A \"<code>[<em>n</em>]</code>\" means an optional integral numeral.)\nExcept for padding, spaces, and configurations\n(options \"<code>xX &lt;=&gt;!</code>\"),\neach option corresponds to an argument (in <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\nor a result (in <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n<p>\nFor options \"<code>!<em>n</em></code>\", \"<code>s<em>n</em></code>\", \"<code>i<em>n</em></code>\", and \"<code>I<em>n</em></code>\",\n<code>n</code> can be any integer between 1 and 16.\nAll integral options check overflows;\n<a href=\"#pdf-string.pack\"><code>string.pack</code></a> checks whether the given value fits in the given size;\n<a href=\"#pdf-string.unpack\"><code>string.unpack</code></a> checks whether the read value fits in a Lua integer.\n\n\n<p>\nAny format string starts as if prefixed by \"<code>!1=</code>\",\nthat is,\nwith maximum alignment of 1 (no alignment)\nand native endianness.\n\n\n<p>\nAlignment works as follows:\nFor each option,\nthe format gets extra padding until the data starts\nat an offset that is a multiple of the minimum between the\noption size and the maximum alignment;\nthis minimum must be a power of 2.\nOptions \"<code>c</code>\" and \"<code>z</code>\" are not aligned;\noption \"<code>s</code>\" follows the alignment of its starting integer.\n\n\n<p>\nAll padding is filled with zeros by <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\n(and ignored by <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>).\n\n\n\n\n\n\n\n<h2>6.5 &ndash; <a name=\"6.5\">UTF-8 Support</a></h2>\n\n<p>\nThis library provides basic support for UTF-8 encoding.\nIt provides all its functions inside the table <a name=\"pdf-utf8\"><code>utf8</code></a>.\nThis library does not provide any support for Unicode other\nthan the handling of the encoding.\nAny operation that needs the meaning of a character,\nsuch as character classification, is outside its scope.\n\n\n<p>\nUnless stated otherwise,\nall functions that expect a byte position as a parameter\nassume that the given position is either the start of a byte sequence\nor one plus the length of the subject string.\nAs in the string library,\nnegative indices count from the end of the string.\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.char\"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers,\nconverts each one to its corresponding UTF-8 byte sequence\nand returns a string with the concatenation of all these sequences.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.charpattern\"><code>utf8.charpattern</code></a></h3>\nThe pattern (a string, not a function) \"<code>[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*</code>\"\n(see <a href=\"#6.4.1\">&sect;6.4.1</a>),\nwhich matches exactly one UTF-8 byte sequence,\nassuming that the subject is a valid UTF-8 string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codes\"><code>utf8.codes (s)</code></a></h3>\n\n\n<p>\nReturns values so that the construction\n\n<pre>\n     for p, c in utf8.codes(s) do <em>body</em> end\n</pre><p>\nwill iterate over all characters in string <code>s</code>,\nwith <code>p</code> being the position (in bytes) and <code>c</code> the code point\nof each character.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codepoint\"><code>utf8.codepoint (s [, i [, j]])</code></a></h3>\nReturns the codepoints (as integers) from all characters in <code>s</code>\nthat start between byte position <code>i</code> and <code>j</code> (both included).\nThe default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.len\"><code>utf8.len (s [, i [, j]])</code></a></h3>\nReturns the number of UTF-8 characters in string <code>s</code>\nthat start between positions <code>i</code> and <code>j</code> (both inclusive).\nThe default for <code>i</code> is 1 and for <code>j</code> is -1.\nIf it finds any invalid byte sequence,\nreturns a false value plus the position of the first invalid byte.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.offset\"><code>utf8.offset (s, n [, i])</code></a></h3>\nReturns the position (in bytes) where the encoding of the\n<code>n</code>-th character of <code>s</code>\n(counting from position <code>i</code>) starts.\nA negative <code>n</code> gets characters before position <code>i</code>.\nThe default for <code>i</code> is 1 when <code>n</code> is non-negative\nand <code>#s + 1</code> otherwise,\nso that <code>utf8.offset(s, -n)</code> gets the offset of the\n<code>n</code>-th character from the end of the string.\nIf the specified character is neither in the subject\nnor right after its end,\nthe function returns <b>nil</b>.\n\n\n<p>\nAs a special case,\nwhen <code>n</code> is 0 the function returns the start of the encoding\nof the character that contains the <code>i</code>-th byte of <code>s</code>.\n\n\n<p>\nThis function assumes that <code>s</code> is a valid UTF-8 string.\n\n\n\n\n\n\n\n<h2>6.6 &ndash; <a name=\"6.6\">Table Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nRemember that, whenever an operation needs the length of a table,\nall caveats about the length operator apply (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nAll functions ignore non-numeric keys\nin the tables given as arguments.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>\n\n\n<p>\nGiven a list where all elements are strings or numbers,\nreturns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is <code>#list</code>.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (list, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>list</code>,\nshifting up the elements\n<code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.\nThe default value for <code>pos</code> is <code>#list+1</code>,\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof list <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.move\"><code>table.move (a1, f, e, t [,a2])</code></a></h3>\n\n\n<p>\nMoves elements from table <code>a1</code> to table <code>a2</code>,\nperforming the equivalent to the following\nmultiple assignment:\n<code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.\nThe default for <code>a2</code> is <code>a1</code>.\nThe destination range can overlap with the source range.\nThe number of elements to be moved must fit in a Lua integer.\n\n\n<p>\nReturns the destination table <code>a2</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.pack\"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a new table with all arguments stored into keys 1, 2, etc.\nand with a field \"<code>n</code>\" with the total number of arguments.\nNote that the resulting table may not be a sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (list [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>list</code> the element at position <code>pos</code>,\nreturning the value of the removed element.\nWhen <code>pos</code> is an integer between 1 and <code>#list</code>,\nit shifts down the elements\n<code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>\nand erases element <code>list[#list]</code>;\nThe index <code>pos</code> can also be 0 when <code>#list</code> is 0,\nor <code>#list + 1</code>;\nin those cases, the function erases the element <code>list[pos]</code>.\n\n\n<p>\nThe default value for <code>pos</code> is <code>#list</code>,\nso that a call <code>table.remove(l)</code> removes the last element\nof list <code>l</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (list [, comp])</code></a></h3>\n\n\n<p>\nSorts list elements in a given order, <em>in-place</em>,\nfrom <code>list[1]</code> to <code>list[#list]</code>.\nIf <code>comp</code> is given,\nthen it must be a function that receives two list elements\nand returns true when the first element must come\nbefore the second in the final order\n(so that, after the sort,\n<code>i &lt; j</code> implies <code>not comp(list[j],list[i])</code>).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nNote that the <code>comp</code> function must define\na strict partial order over the elements in the list;\nthat is, it must be asymmetric and transitive.\nOtherwise, no valid sort may be possible.\n\n\n<p>\nThe sort algorithm is not stable:\nelements considered equal by the given order\nmay have their relative positions changed by the sort.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.unpack\"><code>table.unpack (list [, i [, j]])</code></a></h3>\n\n\n<p>\nReturns the elements from the given list.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.\n\n\n\n\n\n\n\n<h2>6.7 &ndash; <a name=\"6.7\">Mathematical Functions</a></h2>\n\n<p>\nThis library provides basic mathematical functions.\nIt provides all its functions and constants inside the table <a name=\"pdf-math\"><code>math</code></a>.\nFunctions with the annotation \"<code>integer/float</code>\" give\ninteger results for integer arguments\nand float results for float (or mixed) arguments.\nRounding functions\n(<a href=\"#pdf-math.ceil\"><code>math.ceil</code></a>, <a href=\"#pdf-math.floor\"><code>math.floor</code></a>, and <a href=\"#pdf-math.modf\"><code>math.modf</code></a>)\nreturn an integer when the result fits in the range of an integer,\nor a float otherwise.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the absolute value of <code>x</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (y [, x])</code></a></h3>\n\n\n<p>\n\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both arguments to find the\nquadrant of the result.\n(It also handles correctly the case of <code>x</code> being zero.)\n\n\n<p>\nThe default value for <code>x</code> is 1,\nso that the call <code>math.atan(y)</code>\nreturns the arc tangent of <code>y</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integral value larger than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from radians to degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>\n(where <code>e</code> is the base of natural logarithms).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integral value smaller than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe float value <code>HUGE_VAL</code>,\na value larger than any other numeric value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x [, base])</code></a></h3>\n\n\n<p>\nReturns the logarithm of <code>x</code> in the given base.\nThe default for <code>base</code> is <em>e</em>\n(so that the function returns the natural logarithm of <code>x</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the maximum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.maxinteger\"><code>math.maxinteger</code></a></h3>\nAn integer with the maximum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the minimum value,\naccording to the Lua operator <code>&lt;</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.mininteger\"><code>math.mininteger</code></a></h3>\nAn integer with the minimum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns the integral part of <code>x</code> and the fractional part of <code>x</code>.\nIts second result is always a float.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>&pi;</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from degrees to radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nWhen called without arguments,\nreturns a pseudo-random float with uniform distribution\nin the range  <em>[0,1)</em>.  \nWhen called with two integers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a pseudo-random integer\nwith uniform distribution in the range <em>[m, n]</em>.\n(The value <em>n-m</em> cannot be negative and must fit in a Lua integer.)\nThe call <code>math.random(n)</code> is equivalent to <code>math.random(1,n)</code>.\n\n\n<p>\nThis function is an interface to the underling\npseudo-random generator function provided by C.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed (x)</code></a></h3>\n\n\n<p>\nSets <code>x</code> as the \"seed\"\nfor the pseudo-random generator:\nequal seeds produce equal sequences of numbers.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tointeger\"><code>math.tointeger (x)</code></a></h3>\n\n\n<p>\nIf the value <code>x</code> is convertible to an integer,\nreturns that integer.\nOtherwise, returns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.type\"><code>math.type (x)</code></a></h3>\n\n\n<p>\nReturns \"<code>integer</code>\" if <code>x</code> is an integer,\n\"<code>float</code>\" if it is a float,\nor <b>nil</b> if <code>x</code> is not a number.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ult\"><code>math.ult (m, n)</code></a></h3>\n\n\n<p>\nReturns a boolean,\ntrue if and only if integer <code>m</code> is below integer <code>n</code> when\nthey are compared as unsigned integers.\n\n\n\n\n\n\n\n<h2>6.8 &ndash; <a name=\"6.8\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file handles;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are over these default files.\nThe second style uses explicit file handles.\n\n\n<p>\nWhen using implicit file handles,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file handles,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file handle\nand then all operations are supplied as methods of the file handle.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file handles with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>nil</b> on failure\n(plus an error message as a second result and\na system-dependent error code as a third result)\nand some value different from <b>nil</b> on success.\nIn non-POSIX systems,\nthe computation of the error message and error code\nin case of errors\nmay be not thread safe,\nbecause they rely on the global C variable <code>errno</code>.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():flush()</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without arguments,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that\nworks like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.\nWhen the iterator function detects the end of file,\nit returns no values (to finish the loop) and automatically closes the file.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines(\"*l\")</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case, the iterator does not close the file when the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIn case of success,\nit returns a new file handle.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"<code>r</code>\": </b> read mode (the default);</li>\n<li><b>\"<code>w</code>\": </b> write mode;</li>\n<li><b>\"<code>a</code>\": </b> append mode;</li>\n<li><b>\"<code>r+</code>\": </b> update mode, all previous data is preserved;</li>\n<li><b>\"<code>w+</code>\": </b> update mode, all previous data is erased;</li>\n<li><b>\"<code>a+</code>\": </b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n<p>\nStarts program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nIn case of success,\nreturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>nil</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n<p>\nWhen closing a file handle created with <a href=\"#pdf-io.popen\"><code>io.popen</code></a>,\n<a href=\"#pdf-file:close\"><code>file:close</code></a> returns the same values\nreturned by <a href=\"#pdf-os.execute\"><code>os.execute</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreads the file according to the given formats.\nWhen no format is given,\nuses \"<code>l</code>\" as a default.\nAs an example, the construction\n\n<pre>\n     for c in file:lines(1) do <em>body</em> end\n</pre><p>\nwill iterate over all characters of the file,\nstarting at the current position.\nUnlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string or a number with the characters read,\nor <b>nil</b> if it cannot read data with the specified format.\n(In this latter case,\nthe function does not read subsequent formats.)\nWhen called without formats,\nit uses a default format that reads the next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"<code>n</code>\": </b>\nreads a numeral and returns it as a float or an integer,\nfollowing the lexical conventions of Lua.\n(The numeral may have leading spaces and a sign.)\nThis format always reads the longest input sequence that\nis a valid prefix for a numeral;\nif that prefix does not form a valid numeral\n(e.g., an empty string, \"<code>0x</code>\", or \"<code>3.4e-</code>\"),\nit is discarded and the function returns <b>nil</b>.\n</li>\n\n<li><b>\"<code>a</code>\": </b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string.\n</li>\n\n<li><b>\"<code>l</code>\": </b>\nreads the next line skipping the end of line,\nreturning <b>nil</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b>\"<code>L</code>\": </b>\nreads the next line keeping the end-of-line character (if present),\nreturning <b>nil</b> on end of file.\n</li>\n\n<li><b><em>number</em>: </b>\nreads a string with up to this number of bytes,\nreturning <b>nil</b> on end of file.\nIf <code>number</code> is zero,\nit reads nothing and returns an empty string,\nor <b>nil</b> on end of file.\n</li>\n\n</ul><p>\nThe formats \"<code>l</code>\" and \"<code>L</code>\" should be used only for text files.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence [, offset]])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"<code>set</code>\": </b> base is position 0 (beginning of the file);</li>\n<li><b>\"<code>cur</code>\": </b> base is current position;</li>\n<li><b>\"<code>end</code>\": </b> base is end of file;</li>\n</ul><p>\nIn case of success, <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf <code>seek</code> fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for an output file.\nThere are three available modes:\n\n<ul>\n\n<li><b>\"<code>no</code>\": </b>\nno buffering; the result of any output operation appears immediately.\n</li>\n\n<li><b>\"<code>full</code>\": </b>\nfull buffering; output operation is performed only\nwhen the buffer is full or when\nyou explicitly <code>flush</code> the file (see <a href=\"#pdf-io.flush\"><code>io.flush</code></a>).\n</li>\n\n<li><b>\"<code>line</code>\": </b>\nline buffering; output is buffered until a newline is output\nor there is any input from some special files\n(such as a terminal device).\n</li>\n\n</ul><p>\nFor the last two cases, <code>size</code>\nspecifies the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to <code>file</code>.\nThe arguments must be strings or numbers.\n\n\n<p>\nIn case of success, this function returns <code>file</code>.\nOtherwise it returns <b>nil</b> plus a string describing the error.\n\n\n\n\n\n\n\n<h2>6.9 &ndash; <a name=\"6.9\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),\n<code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59), <code>sec</code> (0&ndash;61),\n<code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),\n<code>yday</code> (day of the year, 1&ndash;366),\nand <code>isdst</code> (daylight saving flag, a boolean).\nThis last field may be absent\nif the information is not available.\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.\n\n\n<p>\nWhen called without arguments,\n<code>date</code> returns a reasonable date and time representation that depends on\nthe host system and on the current locale.\n(More specifically, <code>os.date()</code> is equivalent to <code>os.date(\"%c\")</code>.)\n\n\n<p>\nIn non-POSIX systems,\nthis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the difference, in seconds,\nfrom time <code>t1</code> to time <code>t2</code>\n(where the times are values returned by <a href=\"#pdf-os.time\"><code>os.time</code></a>).\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the ISO&nbsp;C function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIts first result is <b>true</b>\nif the command terminated successfully,\nor <b>nil</b> otherwise.\nAfter this first result\nthe function returns a string plus a number,\nas follows:\n\n<ul>\n\n<li><b>\"<code>exit</code>\": </b>\nthe command terminated normally;\nthe following number is the exit status of the command.\n</li>\n\n<li><b>\"<code>signal</code>\": </b>\nthe command was terminated by a signal;\nthe following number is the signal that terminated the command.\n</li>\n\n</ul>\n\n<p>\nWhen called without a <code>command</code>,\n<code>os.execute</code> returns a boolean that is true if a shell is available.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code [, close]])</code></a></h3>\n\n\n<p>\nCalls the ISO&nbsp;C function <code>exit</code> to terminate the host program.\nIf <code>code</code> is <b>true</b>,\nthe returned status is <code>EXIT_SUCCESS</code>;\nif <code>code</code> is <b>false</b>,\nthe returned status is <code>EXIT_FAILURE</code>;\nif <code>code</code> is a number,\nthe returned status is this number.\nThe default value for <code>code</code> is <b>true</b>.\n\n\n<p>\nIf the optional second argument <code>close</code> is true,\ncloses the Lua state before exiting.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>,\nor <b>nil</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file (or empty directory, on POSIX systems)\nwith the given name.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames the file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a system-dependent string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>nil</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n<p>\nThis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>setlocale</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the local date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields\n<code>hour</code> (default is 12),\n<code>min</code> (default is 0),\n<code>sec</code> (default is 0),\nand <code>isdst</code> (default is <b>nil</b>).\nOther fields are ignored.\nFor a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function.\n\n\n<p>\nThe values in these fields do not need to be inside their valid ranges.\nFor instance, if <code>sec</code> is -10,\nit means -10 seconds from the time specified by the other fields;\nif <code>hour</code> is 1000,\nit means +1000 hours from the time specified by the other fields.\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems,\nthis number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<a href=\"#pdf-os.date\"><code>os.date</code></a> and <a href=\"#pdf-os.difftime\"><code>os.difftime</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nIn POSIX systems,\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>6.10 &ndash; <a name=\"6.10\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface (<a href=\"#4.9\">&sect;4.9</a>) to Lua programs.\nYou should exert care when using this library.\nSeveral of its functions\nviolate basic assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside;\nthat userdata metatables cannot be changed by Lua code;\nthat Lua programs do not crash)\nand therefore can compromise otherwise secure code.\nMoreover, some functions in this library may be slow.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count\n(as set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly\nor you can give a number as the value of <code>f</code>,\nwhich means the function running at level <code>f</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>\n(except for tail calls, which do not count on the stack);\nand so on.\nIf <code>f</code> is a number larger than the number of active functions,\nthen <code>getinfo</code> returns <b>nil</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] f, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>f</code> of the stack.\nThis function accesses not only explicit local variables,\nbut also parameters, temporaries, etc.\n\n\n<p>\nThe first parameter or local variable has index&nbsp;1, and so on,\nfollowing the order that they are declared in the code,\ncounting only the variables that are active\nin the current scope of the function.\nNegative indices refer to vararg arguments;\n-1 is the first vararg argument.\nThe function returns <b>nil</b> if there is no variable with the given index,\nand raises an error when called with a level out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(internal variables such as loop control variables,\nand variables from chunks saved without debug information).\n\n\n<p>\nThe parameter <code>f</code> may also be a function.\nIn that case, <code>getlocal</code> returns only the name of function parameters.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (value)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>value</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (f, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue with the given index.\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(variables from chunks saved without debug information).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getuservalue\"><code>debug.getuservalue (u)</code></a></h3>\n\n\n<p>\nReturns the Lua value associated to <code>u</code>.\nIf <code>u</code> is not a full userdata,\nreturns <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as a hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have any combination of the following characters,\nwith the given meaning:\n\n<ul>\n<li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>\n<li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>\n<li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nMoreover,\nwith a <code>count</code> different from zero,\nthe hook is called also after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first argument is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code> (or <code>\"tail call\"</code>),\n<code>\"return\"</code>,\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function\n(level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n<p>\nSee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for more information about\nvariable indices and names.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (value, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>value</code> to the given <code>table</code>\n(which can be <b>nil</b>).\nReturns <code>value</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (f, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>nil</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setuservalue\"><code>debug.setuservalue (udata, value)</code></a></h3>\n\n\n<p>\nSets the given <code>value</code> as\nthe Lua value associated to the given <code>udata</code>.\n<code>udata</code> must be a full userdata.\n\n\n<p>\nReturns <code>udata</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>\n\n\n<p>\nIf <code>message</code> is present but is neither a string nor <b>nil</b>,\nthis function returns <code>message</code> without further processing.\nOtherwise,\nit returns a string with a traceback of the call stack.\nThe optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvalueid\"><code>debug.upvalueid (f, n)</code></a></h3>\n\n\n<p>\nReturns a unique identifier (as a light userdata)\nfor the upvalue numbered <code>n</code>\nfrom the given function.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvaluejoin\"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>\n\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.\n\n\n\n\n\n\n\n<h1>7 &ndash; <a name=\"7\">Lua Standalone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a standalone language.\nAn interpreter for Lua as a standalone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe standalone interpreter includes\nall standard libraries, including the debug library.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li>\n<li><b><code>-l <em>mod</em></code>: </b> \"requires\" <em>mod</em> and assigns the\n  result to global @<em>mod</em>;</li>\n<li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li>\n<li><b><code>-v</code>: </b> prints version information;</li>\n<li><b><code>-E</code>: </b> ignores environment variables;</li>\n<li><b><code>--</code>: </b> stops handling options;</li>\n<li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nWhen called without option <code>-E</code>,\nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT_5_3\"><code>LUA_INIT_5_3</code></a>\n(or <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a> if the versioned name is not defined)\nbefore running any argument.\nIf the variable content has the format <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nWhen called with option <code>-E</code>,\nbesides ignoring <code>LUA_INIT</code>,\nLua also ignores\nthe values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>,\nsetting the values of\n<a href=\"#pdf-package.path\"><code>package.path</code></a> and <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>\nwith the default paths defined in <code>luaconf.h</code>.\n\n\n<p>\nAll options are handled in order, except <code>-i</code> and <code>-E</code>.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e'a=1' -e 'print(a)' script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then print the value of <code>a</code>,\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore running any code,\n<code>lua</code> collects all command-line arguments\nin a global table called <code>arg</code>.\nThe script name goes to index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus its options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe table is like this:\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nIf there is no script in the call,\nthe interpreter name goes to index 0,\nfollowed by the other arguments.\nFor instance, the call\n\n<pre>\n     $ lua -e \"print(arg[1])\"\n</pre><p>\nwill print \"<code>-e</code>\".\nIf there is a script,\nthe script is called with arguments\n<code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.\n(Like all chunks in Lua,\nthe script is compiled as a vararg function.)\n\n\n<p>\nIn interactive mode,\nLua repeatedly prompts and waits for a line.\nAfter reading a line,\nLua first try to interpret the line as an expression.\nIf it succeeds, it prints its value.\nOtherwise, it interprets the line as a statement.\nIf you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\n\n\n<p>\nIn case of unprotected errors in the script,\nthe interpreter reports the error to the standard error stream.\nIf the error object is not a string but\nhas a metamethod <code>__tostring</code>,\nthe interpreter calls this metamethod to produce the final message.\nOtherwise, the interpreter converts the error object to a string\nand adds a stack traceback to it.\n\n\n<p>\nWhen finishing normally,\nthe interpreter closes its main Lua state\n(see <a href=\"#lua_close\"><code>lua_close</code></a>).\nThe script can avoid this step by\ncalling <a href=\"#pdf-os.exit\"><code>os.exit</code></a> to terminate.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nthe standalone interpreter skips\nthe first line of a chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\n(Of course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen\n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.)\n\n\n\n<h1>8 &ndash; <a name=\"8\">Incompatibilities with the Previous Version</a></h1>\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.2 to Lua&nbsp;5.3.\nYou can avoid some incompatibilities by compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the future.\n\n\n<p>\nLua versions can always change the C API in ways that\ndo not imply source-code changes in a program,\nsuch as the numeric values for constants\nor the implementation of functions as macros.\nTherefore,\nyou should not assume that binaries are compatible between\ndifferent Lua versions.\nAlways recompile clients of the Lua API when\nusing a new version.\n\n\n<p>\nSimilarly, Lua versions can always change the internal representation\nof precompiled chunks;\nprecompiled chunks are not compatible between different Lua versions.\n\n\n<p>\nThe standard paths in the official distribution may\nchange between versions.\n\n\n\n<h2>8.1 &ndash; <a name=\"8.1\">Changes in the Language</a></h2>\n<ul>\n\n<li>\nThe main difference between Lua&nbsp;5.2 and Lua&nbsp;5.3 is the\nintroduction of an integer subtype for numbers.\nAlthough this change should not affect \"normal\" computations,\nsome computations\n(mainly those that involve some kind of overflow)\ncan give different results.\n\n\n<p>\nYou can fix these differences by forcing a number to be a float\n(in Lua&nbsp;5.2 all numbers were float),\nin particular writing constants with an ending <code>.0</code>\nor using <code>x = x + 0.0</code> to convert a variable.\n(This recommendation is only for a quick fix\nfor an occasional incompatibility;\nit is not a general guideline for good programming.\nFor good programming,\nuse floats where you need floats\nand integers where you need integers.)\n</li>\n\n<li>\nThe conversion of a float to a string now adds a <code>.0</code> suffix\nto the result if it looks like an integer.\n(For instance, the float 2.0 will be printed as <code>2.0</code>,\nnot as <code>2</code>.)\nYou should always use an explicit format\nwhen you need a specific format for numbers.\n\n\n<p>\n(Formally this is not an incompatibility,\nbecause Lua does not specify how numbers are formatted as strings,\nbut some programs assumed a specific format.)\n</li>\n\n<li>\nThe generational mode for the garbage collector was removed.\n(It was an experimental feature in Lua&nbsp;5.2.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.2 &ndash; <a name=\"8.2\">Changes in the Libraries</a></h2>\n<ul>\n\n<li>\nThe <code>bit32</code> library has been deprecated.\nIt is easy to require a compatible external library or,\nbetter yet, to replace its functions with appropriate bitwise operations.\n(Keep in mind that <code>bit32</code> operates on 32-bit integers,\nwhile the bitwise operators in Lua&nbsp;5.3 operate on Lua integers,\nwhich by default have 64&nbsp;bits.)\n</li>\n\n<li>\nThe Table library now respects metamethods\nfor setting and getting elements.\n</li>\n\n<li>\nThe <a href=\"#pdf-ipairs\"><code>ipairs</code></a> iterator now respects metamethods and\nits <code>__ipairs</code> metamethod has been deprecated.\n</li>\n\n<li>\nOption names in <a href=\"#pdf-io.read\"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore.\nFor compatibility, Lua will continue to accept (and ignore) this character.\n</li>\n\n<li>\nThe following functions were deprecated in the mathematical library:\n<code>atan2</code>, <code>cosh</code>, <code>sinh</code>, <code>tanh</code>, <code>pow</code>,\n<code>frexp</code>, and <code>ldexp</code>.\nYou can replace <code>math.pow(x,y)</code> with <code>x^y</code>;\nyou can replace <code>math.atan2</code> with <code>math.atan</code>,\nwhich now accepts one or two arguments;\nyou can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>.\nFor the other operations,\nyou can either use an external library or\nimplement them in Lua.\n</li>\n\n<li>\nThe searcher for C loaders used by <a href=\"#pdf-require\"><code>require</code></a>\nchanged the way it handles versioned names.\nNow, the version should come after the module name\n(as is usual in most other tools).\nFor compatibility, that searcher still tries the old format\nif it cannot find an open function according to the new style.\n(Lua&nbsp;5.2 already worked that way,\nbut it did not document the change.)\n</li>\n\n<li>\nThe call <code>collectgarbage(\"count\")</code> now returns only one result.\n(You can compute that second result from the fractional part\nof the first result.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.3 &ndash; <a name=\"8.3\">Changes in the API</a></h2>\n\n\n<ul>\n\n<li>\nContinuation functions now receive as arguments what they needed\nto get through <code>lua_getctx</code>,\nso <code>lua_getctx</code> has been removed.\nAdapt your code accordingly.\n</li>\n\n<li>\nFunction <a href=\"#lua_dump\"><code>lua_dump</code></a> has an extra parameter, <code>strip</code>.\nUse 0 as the value of this parameter to get the old behavior.\n</li>\n\n<li>\nFunctions to inject/project unsigned integers\n(<code>lua_pushunsigned</code>, <code>lua_tounsigned</code>, <code>lua_tounsignedx</code>,\n<code>luaL_checkunsigned</code>, <code>luaL_optunsigned</code>)\nwere deprecated.\nUse their signed equivalents with a type cast.\n</li>\n\n<li>\nMacros to project non-default integer types\n(<code>luaL_checkint</code>, <code>luaL_optint</code>, <code>luaL_checklong</code>, <code>luaL_optlong</code>)\nwere deprecated.\nUse their equivalent over <a href=\"#lua_Integer\"><code>lua_Integer</code></a> with a type cast\n(or, when possible, use <a href=\"#lua_Integer\"><code>lua_Integer</code></a> in your code).\n</li>\n\n</ul>\n\n\n\n\n<h1>9 &ndash; <a name=\"9\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\nAs usual in extended BNF,\n{A} means 0 or more As,\nand [A] means an optional A.\n(For operator precedences, see <a href=\"#3.4.8\">&sect;3.4.8</a>;\nfor a description of the terminals\nName, Numeral,\nand LiteralString, see <a href=\"#3.1\">&sect;3.1</a>.)\n\n\n\n\n<pre>\n\n\tchunk ::= block\n\n\tblock ::= {stat} [retstat]\n\n\tstat ::=  &lsquo;<b>;</b>&rsquo; | \n\t\t varlist &lsquo;<b>=</b>&rsquo; explist | \n\t\t functioncall | \n\t\t label | \n\t\t <b>break</b> | \n\t\t <b>goto</b> Name | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] \n\n\tretstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\n\tvar ::=  Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name \n\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | &lsquo;<b>...</b>&rsquo; | functiondef | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n\n\tfunctioncall ::=  prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args \n\n\targs ::=  &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | LiteralString \n\n\tfunctiondef ::= <b>function</b> funcbody\n\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n\n\tbinop ::=  &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>//</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; | \n\t\t &lsquo;<b>&amp;</b>&rsquo; | &lsquo;<b>~</b>&rsquo; | &lsquo;<b>|</b>&rsquo; | &lsquo;<b>&gt;&gt;</b>&rsquo; | &lsquo;<b>&lt;&lt;</b>&rsquo; | &lsquo;<b>..</b>&rsquo; | \n\t\t &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo; | &lsquo;<b>~</b>&rsquo;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n\n<P CLASS=\"footer\">\nLast update:\nTue Jun 26 13:16:37 -03 2018\n</P>\n<!--\nLast change: revised for Lua 5.3.5\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "build/lua-5.3.5/doc/readme.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.3 readme</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<STYLE TYPE=\"text/css\">\nblockquote, .display {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 8px ;\n\tpadding: 1em ;\n\tmargin: 0px ;\n}\n\n.display {\n\tword-spacing: 0.25em ;\n}\n\ndl.display dd {\n\tpadding-bottom: 0.2em ;\n}\n\ntt, kbd, code {\n\tfont-size: 12pt ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nWelcome to Lua 5.3\n</H1>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"#about\">about</A>\n&middot;\n<A HREF=\"#install\">installation</A>\n&middot;\n<A HREF=\"#changes\">changes</A>\n&middot;\n<A HREF=\"#license\">license</A>\n&middot;\n<A HREF=\"contents.html\">reference manual</A>\n</DIV>\n\n<H2><A NAME=\"about\">About Lua</A></H2>\n<P>\nLua is a powerful, fast, lightweight, embeddable scripting language\ndeveloped by a\n<A HREF=\"http://www.lua.org/authors.html\">team</A>\nat\n<A HREF=\"http://www.puc-rio.br/\">PUC-Rio</A>,\nthe Pontifical Catholic University of Rio de Janeiro in Brazil.\nLua is\n<A HREF=\"#license\">free software</A>\nused in many products and projects around the world.\n\n<P>\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\nprovides complete information\nabout Lua,\nincluding\nan\n<A HREF=\"http://www.lua.org/about.html\">executive summary</A>\nand\nupdated\n<A HREF=\"http://www.lua.org/docs.html\">documentation</A>,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.3/\">reference manual</A>,\nwhich may differ slightly from the\n<A HREF=\"contents.html\">local copy</A>\ndistributed in this package.\n\n<H2><A NAME=\"install\">Installing Lua</A></H2>\n<P>\nLua is distributed in\n<A HREF=\"http://www.lua.org/ftp/\">source</A>\nform.\nYou need to build it before using it.\nBuilding Lua should be straightforward\nbecause\nLua is implemented in pure ANSI C and compiles unmodified in all known\nplatforms that have an ANSI C compiler.\nLua also compiles unmodified as C++.\nThe instructions given below for building Lua are for Unix-like platforms.\nSee also\n<A HREF=\"#other\">instructions for other systems</A>\nand\n<A HREF=\"#customization\">customization options</A>.\n\n<P>\nIf you don't have the time or the inclination to compile Lua yourself,\nget a binary from\n<A HREF=\"http://lua-users.org/wiki/LuaBinaries\">LuaBinaries</A>.\nTry also\n<A HREF=\"http://luadist.org/\">LuaDist</A>,\na multi-platform distribution of Lua that includes batteries.\n\n<H3>Building Lua</H3>\n<P>\nIn most Unix-like platforms, simply do \"<KBD>make</KBD>\" with a suitable target.\nHere are the details.\n\n<OL>\n<LI>\nOpen a terminal window and move to\nthe top-level directory, which is named <TT>lua-5.3.5</TT>.\nThe <TT>Makefile</TT> there controls both the build process and the installation process.\n<P>\n<LI>\n  Do \"<KBD>make</KBD>\" and see if your platform is listed.\n  The platforms currently supported are:\n<P>\n<P CLASS=\"display\">\n   aix bsd c89 freebsd generic linux macosx mingw posix solaris\n</P>\n<P>\n  If your platform is listed, just do \"<KBD>make xxx</KBD>\", where xxx\n  is your platform name.\n<P>\n  If your platform is not listed, try the closest one or posix, generic,\n  c89, in this order.\n<P>\n<LI>\nThe compilation takes only a few moments\nand produces three files in the <TT>src</TT> directory:\nlua (the interpreter),\nluac (the compiler),\nand liblua.a (the library).\n<P>\n<LI>\n  To check that Lua has been built correctly, do \"<KBD>make test</KBD>\"\n  after building Lua. This will run the interpreter and print its version.\n</OL>\n<P>\nIf you're running Linux and get compilation errors,\nmake sure you have installed the <TT>readline</TT> development package\n(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).\nIf you get link errors after that,\nthen try \"<KBD>make linux MYLIBS=-ltermcap</KBD>\".\n\n<H3>Installing Lua</H3>\n<P>\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"<KBD>make install</KBD>\". The official\n  place and the way to install files are defined in the <TT>Makefile</TT>. You'll\n  probably need the right permissions to install files.\n\n<P>\n  To build and install Lua in one step, do \"<KBD>make xxx install</KBD>\",\n  where xxx is your platform name.\n\n<P>\n  To install Lua locally, do \"<KBD>make local</KBD>\".\n  This will create a directory <TT>install</TT> with subdirectories\n  <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,\n  and install Lua as listed below.\n\n  To install Lua locally, but in some other directory, do\n  \"<KBD>make install INSTALL_TOP=xxx</KBD>\", where xxx is your chosen directory.\n  The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,\n  so take care if <TT>INSTALL_TOP</TT> is not an absolute path.\n\n<DL CLASS=\"display\">\n<DT>\n    bin:\n<DD>\n    lua luac\n<DT>\n    include:\n<DD>\n    lua.h luaconf.h lualib.h lauxlib.h lua.hpp\n<DT>\n    lib:\n<DD>\n    liblua.a\n<DT>\n    man/man1:\n<DD>\n    lua.1 luac.1\n</DL>\n\n<P>\n  These are the only directories you need for development.\n  If you only want to run Lua programs,\n  you only need the files in <TT>bin</TT> and <TT>man</TT>.\n  The files in <TT>include</TT> and <TT>lib</TT> are needed for\n  embedding Lua in C or C++ programs.\n\n<H3><A NAME=\"customization\">Customization</A></H3>\n<P>\n  Three kinds of things can be customized by editing a file:\n<UL>\n    <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.\n    <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.\n    <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.\n</UL>\n\n<P>\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables in the command line when invoking make.\n  Nevertheless, it's probably best to edit and save the Makefiles to\n  record the changes you've made.\n\n<P>\n  On the other hand, if you need to customize some Lua features, you'll need\n  to edit <TT>src/luaconf.h</TT> before building and installing Lua.\n  The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n  Further customization is available to experts by editing the Lua sources.\n\n<H3><A NAME=\"other\">Building Lua on other systems</A></H3>\n<P>\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n<DL CLASS=\"display\">\n<DT>\nlibrary:\n<DD>\nlapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c\nlmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c\nltm.c lundump.c lvm.c lzio.c\nlauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c\nlmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c\n<DT>\ninterpreter:\n<DD>\n  library, lua.c\n<DT>\ncompiler:\n<DD>\n  library, luac.c\n</DL>\n\n<P>\n  To use Lua as a library in your own programs you'll need to know how to\n  create and use libraries with your compiler. Moreover, to dynamically load\n  C libraries for Lua you'll need to know how to create dynamic libraries\n  and you'll need to make sure that the Lua API functions are accessible to\n  those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library\n  into each dynamic library. For Unix, we recommend that the Lua library\n  be linked statically into the host program and its symbols exported for\n  dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.\n  For Windows, we recommend that the Lua library be a DLL.\n  In all cases, the compiler luac should be linked statically.\n\n<P>\n  As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize\n  some features before building Lua.\n\n<H2><A NAME=\"changes\">Changes since Lua 5.2</A></H2>\n<P>\nHere are the main changes introduced in Lua 5.3.\nThe\n<A HREF=\"contents.html\">reference manual</A>\nlists the\n<A HREF=\"manual.html#8\">incompatibilities</A> that had to be introduced.\n\n<H3>Main changes</H3>\n<UL>\n<LI> integers (64-bit by default)\n<LI> official support for 32-bit numbers\n<LI> bitwise operators\n<LI> basic utf-8 support\n<LI> functions for packing and unpacking values\n\n</UL>\n\nHere are the other changes introduced in Lua 5.3:\n<H3>Language</H3>\n<UL>\n<LI> userdata can have any Lua value as uservalue\n<LI> floor division\n<LI> more flexible rules for some metamethods\n</UL>\n\n<H3>Libraries</H3>\n<UL>\n<LI> <CODE>ipairs</CODE> and the table library respect metamethods\n<LI> strip option in <CODE>string.dump</CODE>\n<LI> table library respects metamethods\n<LI> new function <CODE>table.move</CODE>\n<LI> new function <CODE>string.pack</CODE>\n<LI> new function <CODE>string.unpack</CODE>\n<LI> new function <CODE>string.packsize</CODE>\n</UL>\n\n<H3>C API</H3>\n<UL>\n<LI> simpler API for continuation functions in C\n<LI> <CODE>lua_gettable</CODE> and similar functions return type of resulted value\n<LI> strip option in <CODE>lua_dump</CODE>\n<LI> new function: <CODE>lua_geti</CODE>\n<LI> new function: <CODE>lua_seti</CODE>\n<LI> new function: <CODE>lua_isyieldable</CODE>\n<LI> new function: <CODE>lua_numbertointeger</CODE>\n<LI> new function: <CODE>lua_rotate</CODE>\n<LI> new function: <CODE>lua_stringtonumber</CODE>\n</UL>\n\n<H3>Lua standalone interpreter</H3>\n<UL>\n<LI> can be used as calculator; no need to prefix with '='\n<LI> <CODE>arg</CODE> table available to all code\n</UL>\n\n<H2><A NAME=\"license\">License</A></H2>\n<P>\n<A HREF=\"http://www.opensource.org/docs/definition.php\">\n<IMG SRC=\"osi-certified-72x60.png\" ALIGN=\"right\" ALT=\"[osi certified]\" STYLE=\"padding-left: 30px ;\">\n</A>\nLua is free software distributed under the terms of the\n<A HREF=\"http://www.opensource.org/licenses/mit-license.html\">MIT license</A>\nreproduced below;\nit may be used for any purpose, including commercial purposes,\nat absolutely no cost without having to ask us.\n\nThe only requirement is that if you do use Lua,\nthen you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.\n\nFor details, see\n<A HREF=\"http://www.lua.org/license.html\">this</A>.\n\n<BLOCKQUOTE STYLE=\"padding-bottom: 0em\">\nCopyright &copy; 1994&ndash;2017 Lua.org, PUC-Rio.\n\n<P>\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n<P>\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n<P>\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n</BLOCKQUOTE>\n<P>\n\n<P CLASS=\"footer\">\nLast update:\nMon Jun 18 22:57:33 -03 2018\n</P>\n<!--\nLast change: revised for Lua 5.3.5\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.3.5/src/Makefile",
    "content": "# Makefile for building Lua\n# See ../doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= none\n\nCC= gcc -std=gnu99\nCFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)\nLDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)\nLIBS= -lm $(SYSLIBS) $(MYLIBS)\n\nAR= ar rcu\nRANLIB= ranlib\nRM= rm -f\n\nSYSCFLAGS=\nSYSLDFLAGS=\nSYSLIBS=\n\nMYCFLAGS=\nMYLDFLAGS=\nMYLIBS=\nMYOBJS=\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\nPLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris\n\nLUA_A=\tliblua.a\nCORE_O=\tlapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \\\n\tlmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \\\n\tltm.o lundump.o lvm.o lzio.o\nLIB_O=\tlauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \\\n\tlmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o\nBASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)\n\nLUA_T=\tlua\nLUA_O=\tlua.o\n\nLUAC_T=\tluac\nLUAC_O=\tluac.o\n\nALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)\nALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)\nALL_A= $(LUA_A)\n\n# Targets start here.\ndefault: $(PLAT)\n\nall:\t$(ALL_T)\n\no:\t$(ALL_O)\n\na:\t$(ALL_A)\n\n$(LUA_A): $(BASE_O)\n\t$(AR) $@ $(BASE_O)\n\t$(RANLIB) $@\n\n$(LUA_T): $(LUA_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)\n\n$(LUAC_T): $(LUAC_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)\n\nclean:\n\t$(RM) $(ALL_T) $(ALL_O)\n\ndepend:\n\t@$(CC) $(CFLAGS) -MM l*.c\n\necho:\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"CC= $(CC)\"\n\t@echo \"CFLAGS= $(CFLAGS)\"\n\t@echo \"LDFLAGS= $(SYSLDFLAGS)\"\n\t@echo \"LIBS= $(LIBS)\"\n\t@echo \"AR= $(AR)\"\n\t@echo \"RANLIB= $(RANLIB)\"\n\t@echo \"RM= $(RM)\"\n\n# Convenience targets for popular platforms\nALL= all\n\nnone:\n\t@echo \"Please do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\naix:\n\t$(MAKE) $(ALL) CC=\"xlc\" CFLAGS=\"-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-ldl\" SYSLDFLAGS=\"-brtl -bexpall\"\n\nbsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-Wl,-E\"\n\nc89:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_C89\" CC=\"gcc -std=c89\"\n\t@echo ''\n\t@echo '*** C89 does not guarantee 64-bit integers for Lua.'\n\t@echo ''\n\n\nfreebsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit\" SYSLIBS=\"-Wl,-E -ledit\" CC=\"cc\"\n\ngeneric: $(ALL)\n\nlinux:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -ldl -lreadline\"\n\nmacosx:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_MACOSX\" SYSLIBS=\"-lreadline\"\n\nmingw:\n\t$(MAKE) \"LUA_A=lua53.dll\" \"LUA_T=lua.exe\" \\\n\t\"AR=$(CC) -shared -o\" \"RANLIB=strip --strip-unneeded\" \\\n\t\"SYSCFLAGS=-DLUA_BUILD_AS_DLL\" \"SYSLIBS=\" \"SYSLDFLAGS=-s\" lua.exe\n\t$(MAKE) \"LUAC_T=luac.exe\" luac.exe\n\nposix:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX\"\n\nsolaris:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT\" SYSLIBS=\"-ldl\"\n\n# list targets that do not create files (but not all makes understand .PHONY)\n.PHONY: all $(PLATS) default o a clean depend echo none\n\n# DO NOT DELETE\n\nlapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \\\n ltable.h lundump.h lvm.h\nlauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h\nlbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lgc.h lstring.h ltable.h lvm.h\nlcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h\nldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \\\n ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h\nldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \\\n lparser.h lstring.h ltable.h lundump.h lvm.h\nldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \\\n ltm.h lzio.h lmem.h lundump.h\nlfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \\\n lgc.h lstate.h ltm.h lzio.h lmem.h\nlgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h\nlinit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h\nliolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nllex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \\\n lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \\\n lstring.h ltable.h\nlmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h\nloadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \\\n ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \\\n lvm.h\nlopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h\nloslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lfunc.h lstring.h lgc.h ltable.h\nlstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \\\n lstring.h ltable.h\nlstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h\nlstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h\nltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h\nlua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nluac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \\\n lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h\nlundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \\\n lundump.h\nlutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \\\n ltable.h lvm.h\nlzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \\\n lobject.h ltm.h lzio.h\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.3.5/src/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.259.1.2 2017/12/06 18:35:12 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$LuaVersion: \" LUA_COPYRIGHT \" $\"\n  \"$LuaAuthors: \" LUA_AUTHORS \" $\";\n\n\n/* value at a non-valid index */\n#define NONVALIDVALUE\t\tcast(TValue *, luaO_nilobject)\n\n/* corresponding test */\n#define isvalid(o)\t((o) != luaO_nilobject)\n\n/* test for pseudo index */\n#define ispseudo(i)\t\t((i) <= LUA_REGISTRYINDEX)\n\n/* test for upvalue */\n#define isupvalue(i)\t\t((i) < LUA_REGISTRYINDEX)\n\n/* test for valid but not pseudo index */\n#define isstackindex(i, o)\t(isvalid(o) && !ispseudo(i))\n\n#define api_checkvalidindex(l,o)  api_check(l, isvalid(o), \"invalid index\")\n\n#define api_checkstackindex(l, i, o)  \\\n\tapi_check(l, isstackindex(i, o), \"index not in the stack\")\n\n\nstatic TValue *index2addr (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    TValue *o = ci->func + idx;\n    api_check(L, idx <= ci->top - (ci->func + 1), \"unacceptable index\");\n    if (o >= L->top) return NONVALIDVALUE;\n    else return o;\n  }\n  else if (!ispseudo(idx)) {  /* negative index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    return L->top + idx;\n  }\n  else if (idx == LUA_REGISTRYINDEX)\n    return &G(L)->l_registry;\n  else {  /* upvalues */\n    idx = LUA_REGISTRYINDEX - idx;\n    api_check(L, idx <= MAXUPVAL + 1, \"upvalue index too large\");\n    if (ttislcf(ci->func))  /* light C function? */\n      return NONVALIDVALUE;  /* it has no upvalues */\n    else {\n      CClosure *func = clCvalue(ci->func);\n      return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE;\n    }\n  }\n}\n\n\n/*\n** to be called by 'lua_checkstack' in protected mode, to grow stack\n** capturing memory errors\n*/\nstatic void growstack (lua_State *L, void *ud) {\n  int size = *(int *)ud;\n  luaD_growstack(L, size);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int n) {\n  int res;\n  CallInfo *ci = L->ci;\n  lua_lock(L);\n  api_check(L, n >= 0, \"negative 'n'\");\n  if (L->stack_last - L->top > n)  /* stack large enough? */\n    res = 1;  /* yes; check is OK */\n  else {  /* no; need to grow stack */\n    int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;\n    if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */\n      res = 0;  /* no */\n    else  /* try to grow stack */\n      res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK);\n  }\n  if (res && ci->top < L->top + n)\n    ci->top = L->top + n;  /* adjust frame top */\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to), \"moving among independent states\");\n  api_check(from, to->ci->top - to->top >= n, \"stack overflow\");\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobj2s(to, to->top, from->top + i);\n    to->top++;  /* stack already checked by previous 'api_check' */\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API const lua_Number *lua_version (lua_State *L) {\n  static const lua_Number version = LUA_VERSION_NUM;\n  if (L == NULL) return &version;\n  else return G(L)->version;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\n/*\n** convert an acceptable stack index into an absolute index\n*/\nLUA_API int lua_absindex (lua_State *L, int idx) {\n  return (idx > 0 || ispseudo(idx))\n         ? idx\n         : cast_int(L->top - L->ci->func) + idx;\n}\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - (L->ci->func + 1));\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  StkId func = L->ci->func;\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - (func + 1), \"new top too large\");\n    while (L->top < (func + 1) + idx)\n      setnilvalue(L->top++);\n    L->top = (func + 1) + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - (func + 1)), \"invalid new top\");\n    L->top += idx+1;  /* 'subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\n/*\n** Reverse the stack segment from 'from' to 'to'\n** (auxiliary to 'lua_rotate')\n*/\nstatic void reverse (lua_State *L, StkId from, StkId to) {\n  for (; from < to; from++, to--) {\n    TValue temp;\n    setobj(L, &temp, from);\n    setobjs2s(L, from, to);\n    setobj2s(L, to, &temp);\n  }\n}\n\n\n/*\n** Let x = AB, where A is a prefix of length 'n'. Then,\n** rotate x n == BA. But BA == (A^r . B^r)^r.\n*/\nLUA_API void lua_rotate (lua_State *L, int idx, int n) {\n  StkId p, t, m;\n  lua_lock(L);\n  t = L->top - 1;  /* end of stack segment being rotated */\n  p = index2addr(L, idx);  /* start of segment */\n  api_checkstackindex(L, idx, p);\n  api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), \"invalid 'n'\");\n  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */\n  reverse(L, p, m);  /* reverse the prefix with length 'n' */\n  reverse(L, m + 1, t);  /* reverse the suffix */\n  reverse(L, p, t);  /* reverse the entire segment */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {\n  TValue *fr, *to;\n  lua_lock(L);\n  fr = index2addr(L, fromidx);\n  to = index2addr(L, toidx);\n  api_checkvalidindex(L, to);\n  setobj(L, to, fr);\n  if (isupvalue(toidx))  /* function upvalue? */\n    luaC_barrier(L, clCvalue(L->ci->func), fr);\n  /* LUA_REGISTRYINDEX does not need gc barrier\n     (collector revisits it before finishing collection) */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2addr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (isvalid(o) ? ttnov(o) : LUA_TNONE);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, \"invalid tag\");\n  return ttypename(t);\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (ttislcf(o) || (ttisCclosure(o)));\n}\n\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return ttisinteger(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisstring(o) || cvt2str(o));\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return (ttisfulluserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2addr(L, index1);\n  StkId o2 = index2addr(L, index2);\n  return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0;\n}\n\n\nLUA_API void lua_arith (lua_State *L, int op) {\n  lua_lock(L);\n  if (op != LUA_OPUNM && op != LUA_OPBNOT)\n    api_checknelems(L, 2);  /* all other operations expect two operands */\n  else {  /* for unary operations, add fake 2nd operand */\n    api_checknelems(L, 1);\n    setobjs2s(L, L->top, L->top - 1);\n    api_incr_top(L);\n  }\n  /* first operand at top - 2, second at top - 1; result go to top - 2 */\n  luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2);\n  L->top--;  /* remove second operand */\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {\n  StkId o1, o2;\n  int i = 0;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2addr(L, index1);\n  o2 = index2addr(L, index2);\n  if (isvalid(o1) && isvalid(o2)) {\n    switch (op) {\n      case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;\n      case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;\n      case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;\n      default: api_check(L, 0, \"invalid option\");\n    }\n  }\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {\n  size_t sz = luaO_str2num(s, L->top);\n  if (sz != 0)\n    api_incr_top(L);\n  return sz;\n}\n\n\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {\n  lua_Number n;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tonumber(o, &n);\n  if (!isnum)\n    n = 0;  /* call to 'tonumber' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return n;\n}\n\n\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {\n  lua_Integer res;\n  const TValue *o = index2addr(L, idx);\n  int isnum = tointeger(o, &res);\n  if (!isnum)\n    res = 0;  /* call to 'tointeger' may change 'n' even if it fails */\n  if (pisnum) *pisnum = isnum;\n  return res;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2addr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2addr(L, idx);\n  if (!ttisstring(o)) {\n    if (!cvt2str(o)) {  /* not convertible? */\n      if (len != NULL) *len = 0;\n      return NULL;\n    }\n    lua_lock(L);  /* 'luaO_tostring' may create a new string */\n    luaO_tostring(L, o);\n    luaC_checkGC(L);\n    o = index2addr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL)\n    *len = vslen(o);\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_rawlen (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSHRSTR: return tsvalue(o)->shrlen;\n    case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  if (ttislcf(o)) return fvalue(o);\n  else if (ttisCclosure(o))\n    return clCvalue(o)->f;\n  else return NULL;  /* not a C function */\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttnov(o)) {\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2addr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TLCL: return clLvalue(o);\n    case LUA_TCCL: return clCvalue(o);\n    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setfltvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setivalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** Pushes on the stack a string with given length. Avoid using 's' when\n** 'len' == 0 (as 's' can be NULL in that case), due to later use of\n** 'memcmp' and 'memcpy'.\n*/\nLUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  TString *ts;\n  lua_lock(L);\n  ts = (len == 0) ? luaS_new(L, \"\") : luaS_newlstr(L, s, len);\n  setsvalue2s(L, L->top, ts);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getstr(ts);\n}\n\n\nLUA_API const char *lua_pushstring (lua_State *L, const char *s) {\n  lua_lock(L);\n  if (s == NULL)\n    setnilvalue(L->top);\n  else {\n    TString *ts;\n    ts = luaS_new(L, s);\n    setsvalue2s(L, L->top, ts);\n    s = getstr(ts);  /* internal copy's address */\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return s;\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  lua_lock(L);\n  if (n == 0) {\n    setfvalue(L->top, fn);\n    api_incr_top(L);\n  }\n  else {\n    CClosure *cl;\n    api_checknelems(L, n);\n    api_check(L, n <= MAXUPVAL, \"upvalue index too large\");\n    cl = luaF_newCclosure(L, n);\n    cl->f = fn;\n    L->top -= n;\n    while (n--) {\n      setobj2n(L, &cl->upvalue[n], L->top + n);\n      /* does not need barrier because closure is white */\n    }\n    setclCvalue(L, L->top, cl);\n    api_incr_top(L);\n    luaC_checkGC(L);\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(L->top, p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nstatic int auxgetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setsvalue2s(L, L->top, str);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);\n  return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API int lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_getfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);\n  return auxgetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  if (luaV_fastget(L, t, n, slot, luaH_getint)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishget(L, t, L->top - 1, L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setobj2s(L, L->top, luaH_getint(hvalue(t), n));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {\n  StkId t;\n  TValue k;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  setobj2s(L, L->top, luaH_get(hvalue(t), &k));\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  Table *t;\n  lua_lock(L);\n  t = luaH_new(L);\n  sethvalue(L, L->top, t);\n  api_incr_top(L);\n  if (narray > 0 || nrec > 0)\n    luaH_resize(L, t, narray, nrec);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt;\n  int res = 0;\n  lua_lock(L);\n  obj = index2addr(L, objindex);\n  switch (ttnov(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(obj)];\n      break;\n  }\n  if (mt != NULL) {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API int lua_getuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  getuservalue(L, uvalue(o), L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttnov(L->top - 1);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n/*\n** t[k] = value at the top of the stack (where 'k' is a string)\n*/\nstatic void auxsetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  api_checknelems(L, 1);\n  if (luaV_fastset(L, t, str, slot, luaH_getstr, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);  /* lock done by caller */\n}\n\n\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n  Table *reg = hvalue(&G(L)->l_registry);\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2addr(L, idx);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, index2addr(L, idx), k);\n}\n\n\nLUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {\n  StkId t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2addr(L, idx);\n  if (luaV_fastset(L, t, n, slot, luaH_getint, L->top - 1))\n    L->top--;  /* pop value */\n  else {\n    setivalue(L->top, n);\n    api_incr_top(L);\n    luaV_finishset(L, t, L->top - 1, L->top - 2, slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId o;\n  TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  slot = luaH_set(L, hvalue(o), L->top - 2);\n  setobj2t(L, slot, L->top - 1);\n  invalidateTMcache(hvalue(o));\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  luaH_setint(L, hvalue(o), n, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {\n  StkId o;\n  TValue k, *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttistable(o), \"table expected\");\n  setpvalue(&k, cast(void *, p));\n  slot = luaH_set(L, hvalue(o), &k);\n  setobj2t(L, slot, L->top - 1);\n  luaC_barrierback(L, hvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2addr(L, objindex);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1), \"table expected\");\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttnov(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, gcvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, uvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    default: {\n      G(L)->mt[ttnov(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API void lua_setuservalue (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2addr(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  setuservalue(L, uvalue(o), L->top - 1);\n  luaC_barrier(L, gcvalue(o), L->top - 1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\n/*\n** 'load' and 'call' functions (run Lua code)\n*/\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \\\n\t\"results from function overflow current stack size\")\n\n\nLUA_API void lua_callk (lua_State *L, int nargs, int nresults,\n                        lua_KContext ctx, lua_KFunction k) {\n  StkId func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  if (k != NULL && L->nny == 0) {  /* need to prepare continuation? */\n    L->ci->u.c.k = k;  /* save continuation */\n    L->ci->u.c.ctx = ctx;  /* save context */\n    luaD_call(L, func, nresults);  /* do the call */\n  }\n  else  /* no continuation or no yieldable */\n    luaD_callnoyield(L, func, nresults);  /* just do the call */\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to 'f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_callnoyield(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,\n                        lua_KContext ctx, lua_KFunction k) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2addr(L, errfunc);\n    api_checkstackindex(L, errfunc, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  if (k == NULL || L->nny > 0) {  /* no continuation or no yieldable? */\n    c.nresults = nresults;  /* do a 'conventional' protected call */\n    status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  }\n  else {  /* prepare continuation (call is already protected by 'resume') */\n    CallInfo *ci = L->ci;\n    ci->u.c.k = k;  /* save continuation */\n    ci->u.c.ctx = ctx;  /* save context */\n    /* save information for error recovery */\n    ci->extra = savestack(L, c.func);\n    ci->u.c.old_errfunc = L->errfunc;\n    L->errfunc = func;\n    setoah(ci->callstatus, L->allowhook);  /* save value of 'allowhook' */\n    ci->callstatus |= CIST_YPCALL;  /* function can do error recovery */\n    luaD_call(L, c.func, nresults);  /* do the call */\n    ci->callstatus &= ~CIST_YPCALL;\n    L->errfunc = ci->u.c.old_errfunc;\n    status = LUA_OK;  /* if it is here, there were no errors */\n  }\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname, const char *mode) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname, mode);\n  if (status == LUA_OK) {  /* no errors? */\n    LClosure *f = clLvalue(L->top - 1);  /* get newly created function */\n    if (f->nupvalues >= 1) {  /* does it have an upvalue? */\n      /* get global table from registry */\n      Table *reg = hvalue(&G(L)->l_registry);\n      const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);\n      /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */\n      setobj(L, f->upvals[0]->v, gt);\n      luaC_upvalbarrier(L, f->upvals[0]);\n    }\n  }\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, getproto(o), writer, data, strip);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->gcrunning = 0;\n      break;\n    }\n    case LUA_GCRESTART: {\n      luaE_setdebt(g, 0);\n      g->gcrunning = 1;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L, 0);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(gettotalbytes(g) >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(gettotalbytes(g) & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      l_mem debt = 1;  /* =1 to signal that it did an actual step */\n      lu_byte oldrunning = g->gcrunning;\n      g->gcrunning = 1;  /* allow GC to run */\n      if (data == 0) {\n        luaE_setdebt(g, -GCSTEPSIZE);  /* to do a \"small\" step */\n        luaC_step(L);\n      }\n      else {  /* add 'data' to total debt */\n        debt = cast(l_mem, data) * 1024 + g->GCdebt;\n        luaE_setdebt(g, debt);\n        luaC_checkGC(L);\n      }\n      g->gcrunning = oldrunning;  /* restore previous state */\n      if (debt > 0 && g->gcstate == GCSpause)  /* end of cycle? */\n        res = 1;  /* signal it */\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      if (data < 40) data = 40;  /* avoid ridiculous low values (and 0) */\n      g->gcstepmul = data;\n      break;\n    }\n    case LUA_GCISRUNNING: {\n      res = g->gcrunning;\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  /* code unreachable; will unlock when control actually leaves the kernel */\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaV_concat(L, n);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_len (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2addr(L, idx);\n  luaV_objlen(L, L->top, t);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  u = luaS_newudata(L, size);\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getudatamem(u);\n}\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val,\n                                CClosure **owner, UpVal **uv) {\n  switch (ttype(fi)) {\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      if (!(1 <= n && n <= f->nupvalues)) return NULL;\n      *val = &f->upvalue[n-1];\n      if (owner) *owner = f;\n      return \"\";\n    }\n    case LUA_TLCL: {  /* Lua closure */\n      LClosure *f = clLvalue(fi);\n      TString *name;\n      Proto *p = f->p;\n      if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n      *val = f->upvals[n-1]->v;\n      if (uv) *uv = f->upvals[n - 1];\n      name = p->upvalues[n-1].name;\n      return (name == NULL) ? \"(*no name)\" : getstr(name);\n    }\n    default: return NULL;  /* not a closure */\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  lua_lock(L);\n  name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  CClosure *owner = NULL;\n  UpVal *uv = NULL;\n  StkId fi;\n  lua_lock(L);\n  fi = index2addr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val, &owner, &uv);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    if (owner) { luaC_barrier(L, owner, L->top); }\n    else if (uv) { luaC_upvalbarrier(L, uv); }\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {\n  LClosure *f;\n  StkId fi = index2addr(L, fidx);\n  api_check(L, ttisLclosure(fi), \"Lua function expected\");\n  f = clLvalue(fi);\n  api_check(L, (1 <= n && n <= f->p->sizeupvalues), \"invalid upvalue index\");\n  if (pf) *pf = f;\n  return &f->upvals[n - 1];  /* get its upvalue pointer */\n}\n\n\nLUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {\n  StkId fi = index2addr(L, fidx);\n  switch (ttype(fi)) {\n    case LUA_TLCL: {  /* lua closure */\n      return *getupvalref(L, fidx, n, NULL);\n    }\n    case LUA_TCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      api_check(L, 1 <= n && n <= f->nupvalues, \"invalid upvalue index\");\n      return &f->upvalue[n - 1];\n    }\n    default: {\n      api_check(L, 0, \"closure expected\");\n      return NULL;\n    }\n  }\n}\n\n\nLUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,\n                                            int fidx2, int n2) {\n  LClosure *f1;\n  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);\n  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);\n  luaC_upvdeccount(L, *up1);\n  *up1 = *up2;\n  (*up1)->refcount++;\n  if (upisopen(*up1)) (*up1)->u.open.touched = 1;\n  luaC_upvalbarrier(L, *up1);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"llimits.h\"\n#include \"lstate.h\"\n\n#define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \\\n\t\t\t\t\"stack overflow\");}\n\n#define adjustresults(L,nres) \\\n    { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }\n\n#define api_checknelems(L,n)\tapi_check(L, (n) < (L->top - L->ci->func), \\\n\t\t\t\t  \"not enough elements in the stack\")\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.289.1.1 2017/04/19 17:20:42 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/*\n** This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n/*\n** {======================================================\n** Traceback\n** =======================================================\n*/\n\n\n#define LEVELS1\t10\t/* size of the first part of the stack */\n#define LEVELS2\t11\t/* size of the second part of the stack */\n\n\n\n/*\n** search for 'objidx' in table at index -1.\n** return 1 + string at top if find a good name.\n*/\nstatic int findfield (lua_State *L, int objidx, int level) {\n  if (level == 0 || !lua_istable(L, -1))\n    return 0;  /* not found */\n  lua_pushnil(L);  /* start 'next' loop */\n  while (lua_next(L, -2)) {  /* for each pair in table */\n    if (lua_type(L, -2) == LUA_TSTRING) {  /* ignore non-string keys */\n      if (lua_rawequal(L, objidx, -1)) {  /* found object? */\n        lua_pop(L, 1);  /* remove value (but keep name) */\n        return 1;\n      }\n      else if (findfield(L, objidx, level - 1)) {  /* try recursively */\n        lua_remove(L, -2);  /* remove table (but keep name) */\n        lua_pushliteral(L, \".\");\n        lua_insert(L, -2);  /* place '.' between the two names */\n        lua_concat(L, 3);\n        return 1;\n      }\n    }\n    lua_pop(L, 1);  /* remove value */\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Search for a name for a function in all loaded modules\n*/\nstatic int pushglobalfuncname (lua_State *L, lua_Debug *ar) {\n  int top = lua_gettop(L);\n  lua_getinfo(L, \"f\", ar);  /* push function */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  if (findfield(L, top + 1, 2)) {\n    const char *name = lua_tostring(L, -1);\n    if (strncmp(name, \"_G.\", 3) == 0) {  /* name start with '_G.'? */\n      lua_pushstring(L, name + 3);  /* push name without prefix */\n      lua_remove(L, -2);  /* remove original name */\n    }\n    lua_copy(L, -1, top + 1);  /* move name to proper place */\n    lua_pop(L, 2);  /* remove pushed values */\n    return 1;\n  }\n  else {\n    lua_settop(L, top);  /* remove function and global table */\n    return 0;\n  }\n}\n\n\nstatic void pushfuncname (lua_State *L, lua_Debug *ar) {\n  if (pushglobalfuncname(L, ar)) {  /* try first a global name */\n    lua_pushfstring(L, \"function '%s'\", lua_tostring(L, -1));\n    lua_remove(L, -2);  /* remove name */\n  }\n  else if (*ar->namewhat != '\\0')  /* is there a name from code? */\n    lua_pushfstring(L, \"%s '%s'\", ar->namewhat, ar->name);  /* use it */\n  else if (*ar->what == 'm')  /* main? */\n      lua_pushliteral(L, \"main chunk\");\n  else if (*ar->what != 'C')  /* for Lua functions, use <file:line> */\n    lua_pushfstring(L, \"function <%s:%d>\", ar->short_src, ar->linedefined);\n  else  /* nothing left... */\n    lua_pushliteral(L, \"?\");\n}\n\n\nstatic int lastlevel (lua_State *L) {\n  lua_Debug ar;\n  int li = 1, le = 1;\n  /* find an upper bound */\n  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }\n  /* do a binary search */\n  while (li < le) {\n    int m = (li + le)/2;\n    if (lua_getstack(L, m, &ar)) li = m + 1;\n    else le = m;\n  }\n  return le - 1;\n}\n\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,\n                                const char *msg, int level) {\n  lua_Debug ar;\n  int top = lua_gettop(L);\n  int last = lastlevel(L1);\n  int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;\n  if (msg)\n    lua_pushfstring(L, \"%s\\n\", msg);\n  luaL_checkstack(L, 10, NULL);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (n1-- == 0) {  /* too many levels? */\n      lua_pushliteral(L, \"\\n\\t...\");  /* add a '...' */\n      level = last - LEVELS2 + 1;  /* and skip to last ones */\n    }\n    else {\n      lua_getinfo(L1, \"Slnt\", &ar);\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n      if (ar.currentline > 0)\n        lua_pushfstring(L, \"%d:\", ar.currentline);\n      lua_pushliteral(L, \" in \");\n      pushfuncname(L, &ar);\n      if (ar.istailcall)\n        lua_pushliteral(L, \"\\n\\t(...tail calls...)\");\n      lua_concat(L, lua_gettop(L) - top);\n    }\n  }\n  lua_concat(L, lua_gettop(L) - top);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", arg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    arg--;  /* do not count 'self' */\n    if (arg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling '%s' on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : \"?\";\n  return luaL_error(L, \"bad argument #%d to '%s' (%s)\",\n                        arg, ar.name, extramsg);\n}\n\n\nstatic int typeerror (lua_State *L, int arg, const char *tname) {\n  const char *msg;\n  const char *typearg;  /* name for the type of the actual argument */\n  if (luaL_getmetafield(L, arg, \"__name\") == LUA_TSTRING)\n    typearg = lua_tostring(L, -1);  /* use the given type name */\n  else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)\n    typearg = \"light userdata\";  /* special name for messages */\n  else\n    typearg = luaL_typename(L, arg);  /* standard name */\n  msg = lua_pushfstring(L, \"%s expected, got %s\", tname, typearg);\n  return luaL_argerror(L, arg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int arg, int tag) {\n  typeerror(L, arg, lua_typename(L, tag));\n}\n\n\n/*\n** The use of 'lua_pushfstring' ensures this function does not\n** need reserved stack space when called.\n*/\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushfstring(L, \"\");  /* else, no information available... */\n}\n\n\n/*\n** Again, the use of 'lua_pushvfstring' ensures this function does\n** not need reserved stack space when called. (At worst, it generates\n** an error with \"stack overflow\" instead of the given message.)\n*/\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n\nLUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (stat) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushstring(L, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n#if !defined(l_inspectstat)\t/* { */\n\n#if defined(LUA_USE_POSIX)\n\n#include <sys/wait.h>\n\n/*\n** use appropriate macros to interpret 'pclose' return status\n*/\n#define l_inspectstat(stat,what)  \\\n   if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \\\n   else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = \"signal\"; }\n\n#else\n\n#define l_inspectstat(stat,what)  /* no op */\n\n#endif\n\n#endif\t\t\t\t/* } */\n\n\nLUALIB_API int luaL_execresult (lua_State *L, int stat) {\n  const char *what = \"exit\";  /* type of termination */\n  if (stat == -1)  /* error? */\n    return luaL_fileresult(L, 0, NULL);\n  else {\n    l_inspectstat(stat, what);  /* interpret result */\n    if (*what == 'e' && stat == 0)  /* successful termination? */\n      lua_pushboolean(L, 1);\n    else\n      lua_pushnil(L);\n    lua_pushstring(L, what);\n    lua_pushinteger(L, stat);\n    return 3;  /* return true/nil,what,code */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Userdata's metatable manipulation\n** =======================================================\n*/\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  if (luaL_getmetatable(L, tname) != LUA_TNIL)  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_createtable(L, 0, 2);  /* create metatable */\n  lua_pushstring(L, tname);\n  lua_setfield(L, -2, \"__name\");  /* metatable.__name = tname */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {\n  luaL_getmetatable(L, tname);\n  lua_setmetatable(L, -2);\n}\n\n\nLUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      luaL_getmetatable(L, tname);  /* get correct metatable */\n      if (!lua_rawequal(L, -1, -2))  /* not the same? */\n        p = NULL;  /* value is a userdata with wrong metatable */\n      lua_pop(L, 2);  /* remove both metatables */\n      return p;\n    }\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = luaL_testudata(L, ud, tname);\n  if (p == NULL) typeerror(L, ud, tname);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Argument check functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, arg, def) :\n                             luaL_checkstring(L, arg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, arg,\n                       lua_pushfstring(L, \"invalid option '%s'\", name));\n}\n\n\n/*\n** Ensures the stack has at least 'space' extra slots, raising an error\n** if it cannot fulfill the request. (The error handling needs a few\n** extra slots to format the error message. In case of an error without\n** this extra space, Lua will generate the same 'stack overflow' error,\n** but without 'msg'.)\n*/\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {\n  if (!lua_checkstack(L, space)) {\n    if (msg)\n      luaL_error(L, \"stack overflow (%s)\", msg);\n    else\n      luaL_error(L, \"stack overflow\");\n  }\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int arg, int t) {\n  if (lua_type(L, arg) != t)\n    tag_error(L, arg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNONE)\n    luaL_argerror(L, arg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) {\n  const char *s = lua_tolstring(L, arg, len);\n  if (!s) tag_error(L, arg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int arg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, arg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, arg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) {\n  int isnum;\n  lua_Number d = lua_tonumberx(L, arg, &isnum);\n  if (!isnum)\n    tag_error(L, arg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, arg, def);\n}\n\n\nstatic void interror (lua_State *L, int arg) {\n  if (lua_isnumber(L, arg))\n    luaL_argerror(L, arg, \"number has no integer representation\");\n  else\n    tag_error(L, arg, LUA_TNUMBER);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {\n  int isnum;\n  lua_Integer d = lua_tointegerx(L, arg, &isnum);\n  if (!isnum) {\n    interror(L, arg);\n  }\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, arg, def);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n/* userdata to box arbitrary data */\ntypedef struct UBox {\n  void *box;\n  size_t bsize;\n} UBox;\n\n\nstatic void *resizebox (lua_State *L, int idx, size_t newsize) {\n  void *ud;\n  lua_Alloc allocf = lua_getallocf(L, &ud);\n  UBox *box = (UBox *)lua_touserdata(L, idx);\n  void *temp = allocf(ud, box->box, box->bsize, newsize);\n  if (temp == NULL && newsize > 0) {  /* allocation error? */\n    resizebox(L, idx, 0);  /* free buffer */\n    luaL_error(L, \"not enough memory for buffer allocation\");\n  }\n  box->box = temp;\n  box->bsize = newsize;\n  return temp;\n}\n\n\nstatic int boxgc (lua_State *L) {\n  resizebox(L, 1, 0);\n  return 0;\n}\n\n\nstatic void *newbox (lua_State *L, size_t newsize) {\n  UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));\n  box->box = NULL;\n  box->bsize = 0;\n  if (luaL_newmetatable(L, \"LUABOX\")) {  /* creating metatable? */\n    lua_pushcfunction(L, boxgc);\n    lua_setfield(L, -2, \"__gc\");  /* metatable.__gc = boxgc */\n  }\n  lua_setmetatable(L, -2);\n  return resizebox(L, -1, newsize);\n}\n\n\n/*\n** check whether buffer is using a userdata on the stack as a temporary\n** buffer\n*/\n#define buffonstack(B)\t((B)->b != (B)->initb)\n\n\n/*\n** returns a pointer to a free area with at least 'sz' bytes\n*/\nLUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {\n  lua_State *L = B->L;\n  if (B->size - B->n < sz) {  /* not enough space? */\n    char *newbuff;\n    size_t newsize = B->size * 2;  /* double buffer size */\n    if (newsize - B->n < sz)  /* not big enough? */\n      newsize = B->n + sz;\n    if (newsize < B->n || newsize - B->n < sz)\n      luaL_error(L, \"buffer too large\");\n    /* create larger buffer */\n    if (buffonstack(B))\n      newbuff = (char *)resizebox(L, -1, newsize);\n    else {  /* no buffer yet */\n      newbuff = (char *)newbox(L, newsize);\n      memcpy(newbuff, B->b, B->n * sizeof(char));  /* copy original content */\n    }\n    B->b = newbuff;\n    B->size = newsize;\n  }\n  return &B->b[B->n];\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */\n    char *b = luaL_prepbuffsize(B, l);\n    memcpy(b, s, l * sizeof(char));\n    luaL_addsize(B, l);\n  }\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  lua_pushlstring(L, B->b, B->n);\n  if (buffonstack(B)) {\n    resizebox(L, -2, 0);  /* delete old buffer */\n    lua_remove(L, -2);  /* remove its header from the stack */\n  }\n}\n\n\nLUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {\n  luaL_addsize(B, sz);\n  luaL_pushresult(B);\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t l;\n  const char *s = lua_tolstring(L, -1, &l);\n  if (buffonstack(B))\n    lua_insert(L, -2);  /* put value below buffer */\n  luaL_addlstring(B, s, l);\n  lua_remove(L, (buffonstack(B)) ? -2 : -1);  /* remove value */\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->b = B->initb;\n  B->n = 0;\n  B->size = LUAL_BUFFERSIZE;\n}\n\n\nLUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {\n  luaL_buffinit(L, B);\n  return luaL_prepbuffsize(B, sz);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Reference system\n** =======================================================\n*/\n\n/* index of free-list header */\n#define freelist\t0\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* 'nil' has a unique fixed reference */\n  }\n  t = lua_absindex(L, t);\n  lua_rawgeti(L, t, freelist);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[freelist] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, freelist);  /* (t[freelist] = t[ref]) */\n  }\n  else  /* no free elements */\n    ref = (int)lua_rawlen(L, t) + 1;  /* get a new reference */\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = lua_absindex(L, t);\n    lua_rawgeti(L, t, freelist);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[freelist] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, freelist);  /* t[freelist] = ref */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int n;  /* number of pre-read characters */\n  FILE *f;  /* file being read */\n  char buff[BUFSIZ];  /* area for reading file */\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;  /* not used */\n  if (lf->n > 0) {  /* are there pre-read characters to be read? */\n    *size = lf->n;  /* return them (chars already in buffer) */\n    lf->n = 0;  /* no more pre-read characters */\n  }\n  else {  /* read a block from file */\n    /* 'fread' can return > 0 *and* set the EOF flag. If next call to\n       'getF' called 'fread', it might still wait for user input.\n       The next check avoids this problem. */\n    if (feof(lf->f)) return NULL;\n    *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */\n  }\n  return lf->buff;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nstatic int skipBOM (LoadF *lf) {\n  const char *p = \"\\xEF\\xBB\\xBF\";  /* UTF-8 BOM mark */\n  int c;\n  lf->n = 0;\n  do {\n    c = getc(lf->f);\n    if (c == EOF || c != *(const unsigned char *)p++) return c;\n    lf->buff[lf->n++] = c;  /* to be read by the parser */\n  } while (*p != '\\0');\n  lf->n = 0;  /* prefix matched; discard it */\n  return getc(lf->f);  /* return next character */\n}\n\n\n/*\n** reads the first character of file 'f' and skips an optional BOM mark\n** in its beginning plus its first line if it starts with '#'. Returns\n** true if it skipped the first line.  In any case, '*cp' has the\n** first \"valid\" character of the file (after the optional BOM and\n** a first-line comment).\n*/\nstatic int skipcomment (LoadF *lf, int *cp) {\n  int c = *cp = skipBOM(lf);\n  if (c == '#') {  /* first line is a comment (Unix exec. file)? */\n    do {  /* skip first line */\n      c = getc(lf->f);\n    } while (c != EOF && c != '\\n');\n    *cp = getc(lf->f);  /* skip end-of-line, if present */\n    return 1;  /* there was a comment */\n  }\n  else return 0;  /* no comment */\n}\n\n\nLUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,\n                                             const char *mode) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  if (skipcomment(&lf, &c))  /* read initial portion */\n    lf.buff[lf.n++] = '\\n';  /* add line to correct line numbers */\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    skipcomment(&lf, &c);  /* re-read initial portion */\n  }\n  if (c != EOF)\n    lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;  /* not used */\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,\n                                 const char *name, const char *mode) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name, mode);\n}\n\n\nLUALIB_API int luaL_loadstring (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return LUA_TNIL;\n  else {\n    int tt;\n    lua_pushstring(L, event);\n    tt = lua_rawget(L, -2);\n    if (tt == LUA_TNIL)  /* is metafield nil? */\n      lua_pop(L, 2);  /* remove metatable and metafield */\n    else\n      lua_remove(L, -2);  /* remove only metatable */\n    return tt;  /* return metafield type */\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = lua_absindex(L, obj);\n  if (luaL_getmetafield(L, obj, event) == LUA_TNIL)  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {\n  lua_Integer l;\n  int isnum;\n  lua_len(L, idx);\n  l = lua_tointegerx(L, -1, &isnum);\n  if (!isnum)\n    luaL_error(L, \"object length is not an integer\");\n  lua_pop(L, 1);  /* remove object */\n  return l;\n}\n\n\nLUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {\n  if (luaL_callmeta(L, idx, \"__tostring\")) {  /* metafield? */\n    if (!lua_isstring(L, -1))\n      luaL_error(L, \"'__tostring' must return a string\");\n  }\n  else {\n    switch (lua_type(L, idx)) {\n      case LUA_TNUMBER: {\n        if (lua_isinteger(L, idx))\n          lua_pushfstring(L, \"%I\", (LUAI_UACINT)lua_tointeger(L, idx));\n        else\n          lua_pushfstring(L, \"%f\", (LUAI_UACNUMBER)lua_tonumber(L, idx));\n        break;\n      }\n      case LUA_TSTRING:\n        lua_pushvalue(L, idx);\n        break;\n      case LUA_TBOOLEAN:\n        lua_pushstring(L, (lua_toboolean(L, idx) ? \"true\" : \"false\"));\n        break;\n      case LUA_TNIL:\n        lua_pushliteral(L, \"nil\");\n        break;\n      default: {\n        int tt = luaL_getmetafield(L, idx, \"__name\");  /* try name */\n        const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :\n                                                 luaL_typename(L, idx);\n        lua_pushfstring(L, \"%s: %p\", kind, lua_topointer(L, idx));\n        if (tt != LUA_TNIL)\n          lua_remove(L, -2);  /* remove '__name' */\n        break;\n      }\n    }\n  }\n  return lua_tolstring(L, -1, len);\n}\n\n\n/*\n** {======================================================\n** Compatibility with 5.1 module functions\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\nstatic const char *luaL_findtable (lua_State *L, int idx,\n                                   const char *fname, int szhint) {\n  const char *e;\n  if (idx) lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    if (lua_rawget(L, -2) == LUA_TNIL) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n/*\n** Count number of elements in a luaL_Reg list.\n*/\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l && l->name; l++) size++;\n  return size;\n}\n\n\n/*\n** Find or create a module table with a given name. The function\n** first looks at the LOADED table and, if that fails, try a\n** global variable with that name. In any case, leaves on the stack\n** the module table.\n*/\nLUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,\n                                 int sizehint) {\n  luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);\n  if (lua_getfield(L, -1, modname) != LUA_TTABLE) {  /* no LOADED[modname]? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    lua_pushglobaltable(L);\n    if (luaL_findtable(L, 0, modname, sizehint) != NULL)\n      luaL_error(L, \"name conflict for module '%s'\", modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = new table */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n}\n\n\nLUALIB_API void luaL_openlib (lua_State *L, const char *libname,\n                               const luaL_Reg *l, int nup) {\n  luaL_checkversion(L);\n  if (libname) {\n    luaL_pushmodule(L, libname, libsize(l));  /* get/create library table */\n    lua_insert(L, -(nup + 1));  /* move library table to below upvalues */\n  }\n  if (l)\n    luaL_setfuncs(L, l, nup);\n  else\n    lua_pop(L, nup);  /* remove upvalues */\n}\n\n#endif\n/* }====================================================== */\n\n/*\n** set functions from list 'l' into table at top - 'nup'; each\n** function gets the 'nup' elements at the top as upvalues.\n** Returns with only the table at the stack.\n*/\nLUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name != NULL; l++) {  /* fill the table with given functions */\n    int i;\n    for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** ensure that stack[idx][fname] has a table and push that table\n** into the stack\n*/\nLUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {\n  if (lua_getfield(L, idx, fname) == LUA_TTABLE)\n    return 1;  /* table already there */\n  else {\n    lua_pop(L, 1);  /* remove previous result */\n    idx = lua_absindex(L, idx);\n    lua_newtable(L);\n    lua_pushvalue(L, -1);  /* copy to be left at top */\n    lua_setfield(L, idx, fname);  /* assign new table to field */\n    return 0;  /* false, because did not find table there */\n  }\n}\n\n\n/*\n** Stripped-down 'require': After checking \"loaded\" table, calls 'openf'\n** to open a module, registers the result in 'package.loaded' table and,\n** if 'glb' is true, also registers the result in the global table.\n** Leaves resulting module on the top.\n*/\nLUALIB_API void luaL_requiref (lua_State *L, const char *modname,\n                               lua_CFunction openf, int glb) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, -1, modname);  /* LOADED[modname] */\n  if (!lua_toboolean(L, -1)) {  /* package not already loaded? */\n    lua_pop(L, 1);  /* remove field */\n    lua_pushcfunction(L, openf);\n    lua_pushstring(L, modname);  /* argument to open function */\n    lua_call(L, 1, 1);  /* call 'openf' to open module */\n    lua_pushvalue(L, -1);  /* make copy of module (call result) */\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = module */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n  if (glb) {\n    lua_pushvalue(L, -1);  /* copy of module */\n    lua_setglobal(L, modname);  /* _G[modname] = module */\n  }\n}\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after 'p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud; (void)osize;  /* not used */\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  lua_writestringerror(\"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                        lua_tostring(L, -1));\n  return 0;  /* return to Lua to abort */\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n\nLUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {\n  const lua_Number *v = lua_version(L);\n  if (sz != LUAL_NUMSIZES)  /* check numeric types */\n    luaL_error(L, \"core and library have incompatible numeric types\");\n  if (v != lua_version(NULL))\n    luaL_error(L, \"multiple Lua VMs detected\");\n  else if (*v != ver)\n    luaL_error(L, \"version mismatch: app. needs %f, Lua core provides %f\",\n                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n\n/* extra error code for 'luaL_loadfilex' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\n/* key, in the registry, for table of loaded modules */\n#define LUA_LOADED_TABLE\t\"_LOADED\"\n\n\n/* key, in the registry, for table of preloaded loaders */\n#define LUA_PRELOAD_TABLE\t\"_PRELOAD\"\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n#define LUAL_NUMSIZES\t(sizeof(lua_Integer)*16 + sizeof(lua_Number))\n\nLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);\n#define luaL_checkversion(L)  \\\n\t  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)\n\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\nLUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int arg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void  (luaL_setmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\nLUALIB_API int (luaL_execresult) (lua_State *L, int stat);\n\n/* predefined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n                                               const char *mode);\n\n#define luaL_loadfile(L,f)\tluaL_loadfilex(L,f,NULL)\n\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n                                   const char *name, const char *mode);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\nLUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\n\nLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\n\nLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\n                                  const char *msg, int level);\n\nLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\n                                 lua_CFunction openf, int glb);\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n\n#define luaL_newlibtable(L,l)\t\\\n  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n\n#define luaL_newlib(L,l)  \\\n  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n\n#define luaL_argcheck(L, cond,arg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (arg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n#define luaL_loadbuffer(L,s,sz,n)\tluaL_loadbufferx(L,s,sz,n,NULL)\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\ntypedef struct luaL_Buffer {\n  char *b;  /* buffer address */\n  size_t size;  /* buffer size */\n  size_t n;  /* number of characters in buffer */\n  lua_State *L;\n  char initb[LUAL_BUFFERSIZE];  /* initial buffer */\n} luaL_Buffer;\n\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\\n   ((B)->b[(B)->n++] = (c)))\n\n#define luaL_addsize(B,s)\t((B)->n += (s))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\n\n#define luaL_prepbuffer(B)\tluaL_prepbuffsize(B, LUAL_BUFFERSIZE)\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** File handles for IO library\n** =======================================================\n*/\n\n/*\n** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\n** initial structure 'luaL_Stream' (it may contain other fields\n** after that initial structure).\n*/\n\n#define LUA_FILEHANDLE          \"FILE*\"\n\n\ntypedef struct luaL_Stream {\n  FILE *f;  /* stream (NULL for incompletely created streams) */\n  lua_CFunction closef;  /* to close stream (NULL for closed streams) */\n} luaL_Stream;\n\n/* }====================================================== */\n\n\n\n/* compatibility with old module system */\n#if defined(LUA_COMPAT_MODULE)\n\nLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\n                                   int sizehint);\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\n\n#define luaL_register(L,n,l)\t(luaL_openlib(L,(n),(l),0))\n\n#endif\n\n\n/*\n** {==================================================================\n** \"Abstraction Layer\" for basic report of messages and errors\n** ===================================================================\n*/\n\n/* print a string */\n#if !defined(lua_writestring)\n#define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)\n#endif\n\n/* print a newline and flush the output */\n#if !defined(lua_writeline)\n#define lua_writeline()        (lua_writestring(\"\\n\", 1), fflush(stdout))\n#endif\n\n/* print an error message */\n#if !defined(lua_writestringerror)\n#define lua_writestringerror(s,p) \\\n        (fprintf(stderr, (s), (p)), fflush(stderr))\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {============================================================\n** Compatibility with deprecated conversions\n** =============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define luaL_checkunsigned(L,a)\t((lua_Unsigned)luaL_checkinteger(L,a))\n#define luaL_optunsigned(L,a,d)\t\\\n\t((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))\n\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#endif\n/* }============================================================ */\n\n\n\n#endif\n\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.314.1.1 2017/04/19 17:39:34 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    size_t l;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tolstring(L, -1, &l);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, \"'tostring' must return a string to 'print'\");\n    if (i>1) lua_writestring(\"\\t\", 1);\n    lua_writestring(s, l);\n    lua_pop(L, 1);  /* pop result */\n  }\n  lua_writeline();\n  return 0;\n}\n\n\n#define SPACECHARS\t\" \\f\\n\\r\\t\\v\"\n\nstatic const char *b_str2int (const char *s, int base, lua_Integer *pn) {\n  lua_Unsigned n = 0;\n  int neg = 0;\n  s += strspn(s, SPACECHARS);  /* skip initial spaces */\n  if (*s == '-') { s++; neg = 1; }  /* handle signal */\n  else if (*s == '+') s++;\n  if (!isalnum((unsigned char)*s))  /* no digit? */\n    return NULL;\n  do {\n    int digit = (isdigit((unsigned char)*s)) ? *s - '0'\n                   : (toupper((unsigned char)*s) - 'A') + 10;\n    if (digit >= base) return NULL;  /* invalid numeral */\n    n = n * base + digit;\n    s++;\n  } while (isalnum((unsigned char)*s));\n  s += strspn(s, SPACECHARS);  /* skip trailing spaces */\n  *pn = (lua_Integer)((neg) ? (0u - n) : n);\n  return s;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */\n    luaL_checkany(L, 1);\n    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */\n      lua_settop(L, 1);  /* yes; return it */\n      return 1;\n    }\n    else {\n      size_t l;\n      const char *s = lua_tolstring(L, 1, &l);\n      if (s != NULL && lua_stringtonumber(L, s) == l + 1)\n        return 1;  /* successful conversion to number */\n      /* else not a number */\n    }\n  }\n  else {\n    size_t l;\n    const char *s;\n    lua_Integer n = 0;  /* to avoid warnings */\n    lua_Integer base = luaL_checkinteger(L, 2);\n    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */\n    s = lua_tolstring(L, 1, &l);\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    if (b_str2int(s, (int)base, &n) == s + l) {\n      lua_pushinteger(L, n);\n      return 1;\n    }  /* else not a number */\n  }  /* else not a number */\n  lua_pushnil(L);  /* not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = (int)luaL_optinteger(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {\n    luaL_where(L, level);   /* add extra information */\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\") != LUA_TNIL)\n    return luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawlen (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,\n                   \"table or string expected\");\n  lua_pushinteger(L, lua_rawlen(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\n    \"isrunning\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n    LUA_GCISRUNNING};\n  int o = optsnum[luaL_checkoption(L, 1, \"collect\", opts)];\n  int ex = (int)luaL_optinteger(L, 2, 0);\n  int res = lua_gc(L, o, ex);\n  switch (o) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: case LUA_GCISRUNNING: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushinteger(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t != LUA_TNONE, 1, \"value expected\");\n  lua_pushstring(L, lua_typename(L, t));\n  return 1;\n}\n\n\nstatic int pairsmeta (lua_State *L, const char *method, int iszero,\n                      lua_CFunction iter) {\n  luaL_checkany(L, 1);\n  if (luaL_getmetafield(L, 1, method) == LUA_TNIL) {  /* no metamethod? */\n    lua_pushcfunction(L, iter);  /* will return generator, */\n    lua_pushvalue(L, 1);  /* state, */\n    if (iszero) lua_pushinteger(L, 0);  /* and initial value */\n    else lua_pushnil(L);\n  }\n  else {\n    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */\n    lua_call(L, 1, 3);  /* get 3 values from metamethod */\n  }\n  return 3;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  return pairsmeta(L, \"__pairs\", 0, luaB_next);\n}\n\n\n/*\n** Traversal function for 'ipairs'\n*/\nstatic int ipairsaux (lua_State *L) {\n  lua_Integer i = luaL_checkinteger(L, 2) + 1;\n  lua_pushinteger(L, i);\n  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;\n}\n\n\n/*\n** 'ipairs' function. Returns 'ipairsaux', given \"table\", 0.\n** (The given \"table\" may not be a table.)\n*/\nstatic int luaB_ipairs (lua_State *L) {\n#if defined(LUA_COMPAT_IPAIRS)\n  return pairsmeta(L, \"__ipairs\", 1, ipairsaux);\n#else\n  luaL_checkany(L, 1);\n  lua_pushcfunction(L, ipairsaux);  /* iteration function */\n  lua_pushvalue(L, 1);  /* state */\n  lua_pushinteger(L, 0);  /* initial value */\n  return 3;\n#endif\n}\n\n\nstatic int load_aux (lua_State *L, int status, int envidx) {\n  if (status == LUA_OK) {\n    if (envidx != 0) {  /* 'env' parameter? */\n      lua_pushvalue(L, envidx);  /* environment for loaded function */\n      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */\n        lua_pop(L, 1);  /* remove 'env' if not used by previous call */\n    }\n    return 1;\n  }\n  else {  /* error (message is on top of the stack) */\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  const char *mode = luaL_optstring(L, 2, NULL);\n  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */\n  int status = luaL_loadfilex(L, fname, mode);\n  return load_aux(L, status, env);\n}\n\n\n/*\n** {======================================================\n** Generic Read function\n** =======================================================\n*/\n\n\n/*\n** reserved slot, above all arguments, to hold a copy of the returned\n** string to avoid it being collected while parsed. 'load' has four\n** optional arguments (chunk, source name, mode, and environment).\n*/\n#define RESERVEDSLOT\t5\n\n\n/*\n** Reader for generic 'load' function: 'lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)(ud);  /* not used */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* pop result */\n    *size = 0;\n    return NULL;\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"reader function must return a string\");\n  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */\n  return lua_tolstring(L, RESERVEDSLOT, size);\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  size_t l;\n  const char *s = lua_tolstring(L, 1, &l);\n  const char *mode = luaL_optstring(L, 3, \"bt\");\n  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */\n  if (s != NULL) {  /* loading a string? */\n    const char *chunkname = luaL_optstring(L, 2, s);\n    status = luaL_loadbufferx(L, s, l, chunkname, mode);\n  }\n  else {  /* loading from a reader function */\n    const char *chunkname = luaL_optstring(L, 2, \"=(load)\");\n    luaL_checktype(L, 1, LUA_TFUNCTION);\n    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */\n    status = lua_load(L, generic_reader, NULL, chunkname, mode);\n  }\n  return load_aux(L, status, env);\n}\n\n/* }====================================================== */\n\n\nstatic int dofilecont (lua_State *L, int d1, lua_KContext d2) {\n  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */\n  return lua_gettop(L) - 1;\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  lua_settop(L, 1);\n  if (luaL_loadfile(L, fname) != LUA_OK)\n    return lua_error(L);\n  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);\n  return dofilecont(L, 0, 0);\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  if (lua_toboolean(L, 1))  /* condition is true? */\n    return lua_gettop(L);  /* return all arguments */\n  else {  /* error */\n    luaL_checkany(L, 1);  /* there must be a condition */\n    lua_remove(L, 1);  /* remove it */\n    lua_pushliteral(L, \"assertion failed!\");  /* default message */\n    lua_settop(L, 1);  /* leave only message (default if no other one) */\n    return luaB_error(L);  /* call 'error' */\n  }\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    lua_Integer i = luaL_checkinteger(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - (int)i;\n  }\n}\n\n\n/*\n** Continuation function for 'pcall' and 'xpcall'. Both functions\n** already pushed a 'true' before doing the call, so in case of success\n** 'finishpcall' only has to return everything in the stack minus\n** 'extra' values (where 'extra' is exactly the number of items to be\n** ignored).\n*/\nstatic int finishpcall (lua_State *L, int status, lua_KContext extra) {\n  if (status != LUA_OK && status != LUA_YIELD) {  /* error? */\n    lua_pushboolean(L, 0);  /* first result (false) */\n    lua_pushvalue(L, -2);  /* error message */\n    return 2;  /* return false, msg */\n  }\n  else\n    return lua_gettop(L) - (int)extra;  /* return all results */\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  lua_pushboolean(L, 1);  /* first result if no errors */\n  lua_insert(L, 1);  /* put it in place */\n  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);\n  return finishpcall(L, status, 0);\n}\n\n\n/*\n** Do a protected call with error handling. After 'lua_rotate', the\n** stack will have <f, err, true, f, [args...]>; so, the function passes\n** 2 to 'finishpcall' to skip the 2 first values when returning results.\n*/\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  int n = lua_gettop(L);\n  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */\n  lua_pushboolean(L, 1);  /* first result */\n  lua_pushvalue(L, 1);  /* function */\n  lua_rotate(L, 3, 2);  /* move them below function's arguments */\n  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);\n  return finishpcall(L, status, 2);\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_tolstring(L, 1, NULL);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"ipairs\", luaB_ipairs},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n#if defined(LUA_COMPAT_LOADSTRING)\n  {\"loadstring\", luaB_load},\n#endif\n  {\"next\", luaB_next},\n  {\"pairs\", luaB_pairs},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawlen\", luaB_rawlen},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"xpcall\", luaB_xpcall},\n  /* placeholders */\n  {\"_G\", NULL},\n  {\"_VERSION\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_base (lua_State *L) {\n  /* open lib into global table */\n  lua_pushglobaltable(L);\n  luaL_setfuncs(L, base_funcs, 0);\n  /* set global _G */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_G\");\n  /* set global _VERSION */\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setfield(L, -2, \"_VERSION\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lbitlib.c",
    "content": "/*\n** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 roberto Exp $\n** Standard library for bitwise operations\n** See Copyright Notice in lua.h\n*/\n\n#define lbitlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if defined(LUA_COMPAT_BITLIB)\t\t/* { */\n\n\n#define pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define checkunsigned(L,i)\t((lua_Unsigned)luaL_checkinteger(L,i))\n\n\n/* number of bits to consider in a number */\n#if !defined(LUA_NBITS)\n#define LUA_NBITS\t32\n#endif\n\n\n/*\n** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must\n** be made in two parts to avoid problems when LUA_NBITS is equal to the\n** number of bits in a lua_Unsigned.)\n*/\n#define ALLONES\t\t(~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))\n\n\n/* macro to trim extra bits */\n#define trim(x)\t\t((x) & ALLONES)\n\n\n/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */\n#define mask(n)\t\t(~((ALLONES << 1) << ((n) - 1)))\n\n\n\nstatic lua_Unsigned andaux (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = ~(lua_Unsigned)0;\n  for (i = 1; i <= n; i++)\n    r &= checkunsigned(L, i);\n  return trim(r);\n}\n\n\nstatic int b_and (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_test (lua_State *L) {\n  lua_Unsigned r = andaux(L);\n  lua_pushboolean(L, r != 0);\n  return 1;\n}\n\n\nstatic int b_or (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r |= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_xor (lua_State *L) {\n  int i, n = lua_gettop(L);\n  lua_Unsigned r = 0;\n  for (i = 1; i <= n; i++)\n    r ^= checkunsigned(L, i);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_not (lua_State *L) {\n  lua_Unsigned r = ~checkunsigned(L, 1);\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) {\n  if (i < 0) {  /* shift right? */\n    i = -i;\n    r = trim(r);\n    if (i >= LUA_NBITS) r = 0;\n    else r >>= i;\n  }\n  else {  /* shift left */\n    if (i >= LUA_NBITS) r = 0;\n    else r <<= i;\n    r = trim(r);\n  }\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_lshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rshift (lua_State *L) {\n  return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_arshift (lua_State *L) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  lua_Integer i = luaL_checkinteger(L, 2);\n  if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1))))\n    return b_shift(L, r, -i);\n  else {  /* arithmetic shift for 'negative' number */\n    if (i >= LUA_NBITS) r = ALLONES;\n    else\n      r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i));  /* add signal bit */\n    pushunsigned(L, r);\n    return 1;\n  }\n}\n\n\nstatic int b_rot (lua_State *L, lua_Integer d) {\n  lua_Unsigned r = checkunsigned(L, 1);\n  int i = d & (LUA_NBITS - 1);  /* i = d % NBITS */\n  r = trim(r);\n  if (i != 0)  /* avoid undefined shift of LUA_NBITS when i == 0 */\n    r = (r << i) | (r >> (LUA_NBITS - i));\n  pushunsigned(L, trim(r));\n  return 1;\n}\n\n\nstatic int b_lrot (lua_State *L) {\n  return b_rot(L, luaL_checkinteger(L, 2));\n}\n\n\nstatic int b_rrot (lua_State *L) {\n  return b_rot(L, -luaL_checkinteger(L, 2));\n}\n\n\n/*\n** get field and width arguments for field-manipulation functions,\n** checking whether they are valid.\n** ('luaL_error' called without 'return' to avoid later warnings about\n** 'width' being used uninitialized.)\n*/\nstatic int fieldargs (lua_State *L, int farg, int *width) {\n  lua_Integer f = luaL_checkinteger(L, farg);\n  lua_Integer w = luaL_optinteger(L, farg + 1, 1);\n  luaL_argcheck(L, 0 <= f, farg, \"field cannot be negative\");\n  luaL_argcheck(L, 0 < w, farg + 1, \"width must be positive\");\n  if (f + w > LUA_NBITS)\n    luaL_error(L, \"trying to access non-existent bits\");\n  *width = (int)w;\n  return (int)f;\n}\n\n\nstatic int b_extract (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  int f = fieldargs(L, 2, &w);\n  r = (r >> f) & mask(w);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic int b_replace (lua_State *L) {\n  int w;\n  lua_Unsigned r = trim(checkunsigned(L, 1));\n  lua_Unsigned v = trim(checkunsigned(L, 2));\n  int f = fieldargs(L, 3, &w);\n  lua_Unsigned m = mask(w);\n  r = (r & ~(m << f)) | ((v & m) << f);\n  pushunsigned(L, r);\n  return 1;\n}\n\n\nstatic const luaL_Reg bitlib[] = {\n  {\"arshift\", b_arshift},\n  {\"band\", b_and},\n  {\"bnot\", b_not},\n  {\"bor\", b_or},\n  {\"bxor\", b_xor},\n  {\"btest\", b_test},\n  {\"extract\", b_extract},\n  {\"lrotate\", b_lrot},\n  {\"lshift\", b_lshift},\n  {\"replace\", b_replace},\n  {\"rrotate\", b_rrot},\n  {\"rshift\", b_rshift},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  luaL_newlib(L, bitlib);\n  return 1;\n}\n\n\n#else\t\t\t\t\t/* }{ */\n\n\nLUAMOD_API int luaopen_bit32 (lua_State *L) {\n  return luaL_error(L, \"library 'bit32' has been deprecated\");\n}\n\n#endif\t\t\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.5/src/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.112.1.1 2017/04/19 17:20:42 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <math.h>\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/* Maximum number of registers in a Lua function (must fit in 8 bits) */\n#define MAXREGS\t\t255\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\n/*\n** If expression is a numeric constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nstatic int tonumeral(const expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a numeral */\n  switch (e->k) {\n    case VKINT:\n      if (v) setivalue(v, e->u.ival);\n      return 1;\n    case VKFLT:\n      if (v) setfltvalue(v, e->u.nval);\n      return 1;\n    default: return 0;\n  }\n}\n\n\n/*\n** Create a OP_LOADNIL instruction, but try to optimize: if the previous\n** instruction is also OP_LOADNIL and ranges are compatible, adjust\n** range of previous instruction instead of emitting a new one. (For\n** instance, 'local a; local b' will generate a single opcode.)\n*/\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  int l = from + n - 1;  /* last register to set nil */\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    previous = &fs->f->code[fs->pc-1];\n    if (GET_OPCODE(*previous) == OP_LOADNIL) {  /* previous is LOADNIL? */\n      int pfrom = GETARG_A(*previous);  /* get previous range */\n      int pl = pfrom + GETARG_B(*previous);\n      if ((pfrom <= from && from <= pl + 1) ||\n          (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */\n        if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */\n        if (pl > l) l = pl;  /* l = max(l, pl) */\n        SETARG_A(*previous, from);\n        SETARG_B(*previous, l - from);\n        return;\n      }\n    }  /* else go through */\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */\n}\n\n\n/*\n** Gets the destination address of a jump instruction. Used to traverse\n** a list of jumps.\n*/\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\n/*\n** Fix jump instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua)\n*/\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** Concatenate jump-list 'l2' into jump-list 'l1'\n*/\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;  /* nothing to concatenate? */\n  else if (*l1 == NO_JUMP)  /* no original list? */\n    *l1 = l2;  /* 'l1' points to 'l2' */\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);  /* last element links to 'l2' */\n  }\n}\n\n\n/*\n** Create a jump instruction and return its position, so its destination\n** can be fixed later (with 'fixjump'). If there are jumps to\n** this position (kept in 'jpc'), link them all together so that\n** 'patchlistaux' will fix all them directly to the final destination.\n*/\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;  /* no more jumps to here */\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\n/*\n** Code a 'return' instruction\n*/\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\n/*\n** Code a \"conditional jump\", that is, a test or comparison opcode\n** followed by a jump. Return jump position.\n*/\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\n/*\n** returns current 'pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\n/*\n** Returns the position of the instruction \"controlling\" a given\n** jump (that is, its condition), or the jump itself if it is\n** unconditional.\n*/\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** Patch destination register for a TESTSET instruction.\n** If instruction in position 'node' is not a TESTSET, return 0 (\"fails\").\n** Otherwise, if 'reg' is not 'NO_REG', set it as the destination\n** register. Otherwise, change instruction to a simple 'TEST' (produces\n** no register value)\n*/\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else {\n     /* no register to put value or register already has the value;\n        change instruction to simple test */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n  }\n  return 1;\n}\n\n\n/*\n** Traverse a list of tests ensuring no one produces a value\n*/\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\n/*\n** Traverse a list of tests, patching their destination address and\n** registers: tests producing values jump to 'vtarget' (and put their\n** values in 'reg'), other tests jump to 'dtarget'.\n*/\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\n/*\n** Ensure all pending jumps to current position are fixed (jumping\n** to current position with no values) and reset list of pending\n** jumps\n*/\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\n/*\n** Add elements in 'list' to list of pending jumps to \"here\"\n** (current position)\n*/\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);  /* mark \"here\" as a jump target */\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\n/*\n** Path all jumps in 'list' to jump to 'target'.\n** (The assert means that we cannot fix a jump to a forward address\n** because we only know addresses once code is generated.)\n*/\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)  /* 'target' is current position? */\n    luaK_patchtohere(fs, list);  /* add list to pending jumps */\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\n/*\n** Path all jumps in 'list' to close upvalues up to given 'level'\n** (The assertion checks that jumps either were closing nothing\n** or were closing higher levels, from inner blocks.)\n*/\nvoid luaK_patchclose (FuncState *fs, int list, int level) {\n  level++;  /* argument is +1 to reserve 0 as non-op */\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&\n                (GETARG_A(fs->f->code[list]) == 0 ||\n                 GETARG_A(fs->f->code[list]) >= level));\n    SETARG_A(fs->f->code[list], level);\n  }\n}\n\n\n/*\n** Emit instruction 'i', checking for array sizes and saving also its\n** line information. Return 'i' position.\n*/\nstatic int luaK_code (FuncState *fs, Instruction i) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* 'pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"opcodes\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"opcodes\");\n  f->lineinfo[fs->pc] = fs->ls->lastline;\n  return fs->pc++;\n}\n\n\n/*\n** Format and emit an 'iABC' instruction. (Assertions check consistency\n** of parameters versus opcode.)\n*/\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_B && c <= MAXARG_C);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c));\n}\n\n\n/*\n** Format and emit an 'iABx' instruction.\n*/\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, bc));\n}\n\n\n/*\n** Emit an \"extra argument\" instruction (format 'iAx')\n*/\nstatic int codeextraarg (FuncState *fs, int a) {\n  lua_assert(a <= MAXARG_Ax);\n  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));\n}\n\n\n/*\n** Emit a \"load constant\" instruction, using either 'OP_LOADK'\n** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'\n** instruction with \"extra argument\".\n*/\nint luaK_codek (FuncState *fs, int reg, int k) {\n  if (k <= MAXARG_Bx)\n    return luaK_codeABx(fs, OP_LOADK, reg, k);\n  else {\n    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);\n    codeextraarg(fs, k);\n    return p;\n  }\n}\n\n\n/*\n** Check register-stack level, keeping track of its maximum size\n** in field 'maxstacksize'\n*/\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXREGS)\n      luaX_syntaxerror(fs->ls,\n        \"function or expression needs too many registers\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\n/*\n** Reserve 'n' registers in register stack\n*/\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\n/*\n** Free register 'reg', if it is neither a constant index nor\n** a local variable.\n)\n*/\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\n/*\n** Free register used by expression 'e' (if any)\n*/\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.info);\n}\n\n\n/*\n** Free registers used by expressions 'e1' and 'e2' (if any) in proper\n** order.\n*/\nstatic void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {\n  int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;\n  int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;\n  if (r1 > r2) {\n    freereg(fs, r1);\n    freereg(fs, r2);\n  }\n  else {\n    freereg(fs, r2);\n    freereg(fs, r1);\n  }\n}\n\n\n/*\n** Add constant 'v' to prototype's list of constants (field 'k').\n** Use scanner's table to cache position of constants in constant list\n** and try to reuse constants. Because some values should not be used\n** as keys (nil cannot be a key, integer keys can collapse with float\n** keys), the caller must provide a useful 'key' for indexing the cache.\n*/\nstatic int addk (FuncState *fs, TValue *key, TValue *v) {\n  lua_State *L = fs->ls->L;\n  Proto *f = fs->f;\n  TValue *idx = luaH_set(L, fs->ls->h, key);  /* index scanner table */\n  int k, oldsize;\n  if (ttisinteger(idx)) {  /* is there an index there? */\n    k = cast_int(ivalue(idx));\n    /* correct value? (warning: must distinguish floats from integers!) */\n    if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&\n                      luaV_rawequalobj(&f->k[k], v))\n      return k;  /* reuse index */\n  }\n  /* constant not found; create a new entry */\n  oldsize = f->sizek;\n  k = fs->nk;\n  /* numerical value does not need GC barrier;\n     table has no metatable, so it does not need to invalidate cache */\n  setivalue(idx, k);\n  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, \"constants\");\n  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n  setobj(L, &f->k[k], v);\n  fs->nk++;\n  luaC_barrier(L, f, v);\n  return k;\n}\n\n\n/*\n** Add a string to list of constants and return its index.\n*/\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->ls->L, &o, s);\n  return addk(fs, &o, &o);  /* use string itself as key */\n}\n\n\n/*\n** Add an integer to list of constants and return its index.\n** Integers use userdata as keys to avoid collision with floats with\n** same value; conversion to 'void*' is used only for hashing, so there\n** are no \"precision\" problems.\n*/\nint luaK_intK (FuncState *fs, lua_Integer n) {\n  TValue k, o;\n  setpvalue(&k, cast(void*, cast(size_t, n)));\n  setivalue(&o, n);\n  return addk(fs, &k, &o);\n}\n\n/*\n** Add a float to list of constants and return its index.\n*/\nstatic int luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setfltvalue(&o, r);\n  return addk(fs, &o, &o);  /* use number itself as key */\n}\n\n\n/*\n** Add a boolean to list of constants and return its index.\n*/\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add nil to list of constants and return its index.\n*/\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->ls->L, &k, fs->ls->h);\n  return addk(fs, &k, &v);\n}\n\n\n/*\n** Fix an expression to return the number of results 'nresults'.\n** Either 'e' is a multi-ret expression (function call or vararg)\n** or 'nresults' is LUA_MULTRET (as any expression can satisfy that).\n*/\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getinstruction(fs, e), nresults + 1);\n  }\n  else if (e->k == VVARARG) {\n    Instruction *pc = &getinstruction(fs, e);\n    SETARG_B(*pc, nresults + 1);\n    SETARG_A(*pc, fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n  else lua_assert(nresults == LUA_MULTRET);\n}\n\n\n/*\n** Fix an expression to return one result.\n** If expression is not a multi-ret expression (function call or\n** vararg), it already returns one result, so nothing needs to be done.\n** Function calls become VNONRELOC expressions (as its result comes\n** fixed in the base register of the call), while vararg expressions\n** become VRELOCABLE (as OP_VARARG puts its results where it wants).\n** (Calls are created returning one result, so that does not need\n** to be fixed.)\n*/\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    /* already returns 1 value */\n    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);\n    e->k = VNONRELOC;  /* result has fixed position */\n    e->u.info = GETARG_A(getinstruction(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getinstruction(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\n/*\n** Ensure that expression 'e' is not a variable.\n*/\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {  /* already in a register */\n      e->k = VNONRELOC;  /* becomes a non-relocatable value */\n      break;\n    }\n    case VUPVAL: {  /* move value to some (pending) register */\n      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      OpCode op;\n      freereg(fs, e->u.ind.idx);\n      if (e->u.ind.vt == VLOCAL) {  /* is 't' in a register? */\n        freereg(fs, e->u.ind.t);\n        op = OP_GETTABLE;\n      }\n      else {\n        lua_assert(e->u.ind.vt == VUPVAL);\n        op = OP_GETTABUP;  /* 't' is in an upvalue */\n      }\n      e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG: case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\n/*\n** Ensures expression value is in register 'reg' (and therefore\n** 'e' will become a non-relocatable expression).\n*/\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE: case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codek(fs, reg, e->u.info);\n      break;\n    }\n    case VKFLT: {\n      luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VKINT: {\n      luaK_codek(fs, reg, luaK_intK(fs, e->u.ival));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getinstruction(fs, e);\n      SETARG_A(*pc, reg);  /* instruction will put result in 'reg' */\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures expression value is in any register.\n*/\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {  /* no fixed register yet? */\n    luaK_reserveregs(fs, 1);  /* get a register */\n    discharge2reg(fs, e, fs->freereg-1);  /* put value there */\n  }\n}\n\n\nstatic int code_loadbool (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** or produce an inverted value\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in register 'reg'.\n** If expression has jumps, need to patch these jumps either to\n** its final position or to \"load\" instructions (for those tests\n** that do not produce values).\n*/\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)  /* expression itself is a test? */\n    luaK_concat(fs, &e->t, e->u.info);  /* put this jump in 't' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_loadbool(fs, reg, 0, 1);\n      p_t = code_loadbool(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in next available register.\n*/\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\n/*\n** Ensures final expression result (including results from its jump\n** lists) is in some (any) register and return that register.\n*/\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {  /* expression already has a register? */\n    if (!hasjumps(e))  /* no jumps? */\n      return e->u.info;  /* result is already in a register */\n    if (e->u.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.info);  /* put final result in it */\n      return e->u.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* otherwise, use next available register */\n  return e->u.info;\n}\n\n\n/*\n** Ensures final expression result is either in a register or in an\n** upvalue.\n*/\nvoid luaK_exp2anyregup (FuncState *fs, expdesc *e) {\n  if (e->k != VUPVAL || hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Ensures final expression result is either in a register or it is\n** a constant.\n*/\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\n/*\n** Ensures final expression result is in a valid R/K index\n** (that is, it is either in a register or in 'k' with an index\n** in the range of R/K indices).\n** Returns R/K index.\n*/\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {  /* move constants to 'k' */\n    case VTRUE: e->u.info = boolK(fs, 1); goto vk;\n    case VFALSE: e->u.info = boolK(fs, 0); goto vk;\n    case VNIL: e->u.info = nilK(fs); goto vk;\n    case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;\n    case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;\n    case VK:\n     vk:\n      e->k = VK;\n      if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */\n        return RKASK(e->u.info);\n      else break;\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Generate code to store result of expression 'ex' into variable 'var'.\n*/\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.info);  /* compute 'ex' into proper place */\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);\n      break;\n    }\n    case VINDEXED: {\n      OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP;\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);\n      break;\n    }\n    default: lua_assert(0);  /* invalid var kind to store */\n  }\n  freeexp(fs, ex);\n}\n\n\n/*\n** Emit SELF instruction (convert expression 'e' into 'e:key(e,').\n*/\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int ereg;\n  luaK_exp2anyreg(fs, e);\n  ereg = e->u.info;  /* register where 'e' was placed */\n  freeexp(fs, e);\n  e->u.info = fs->freereg;  /* base register for op_self */\n  e->k = VNONRELOC;  /* self expression has a fixed register */\n  luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */\n  luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n}\n\n\n/*\n** Negate condition 'e' (where 'e' is a comparison).\n*/\nstatic void negatecondition (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\n/*\n** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'\n** is true, code will jump if 'e' is true.) Return jump position.\n** Optimize when 'e' is 'not' something, inverting the condition\n** and removing the 'not'.\n*/\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getinstruction(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);\n}\n\n\n/*\n** Emit code to go through if 'e' is true, jump otherwise.\n*/\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {  /* condition? */\n      negatecondition(fs, e);  /* jump when it is false */\n      pc = e->u.info;  /* save jump position */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);  /* jump when false */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert new jump in false list */\n  luaK_patchtohere(fs, e->t);  /* true list jumps to here (to go through) */\n  e->t = NO_JUMP;\n}\n\n\n/*\n** Emit code to go through if 'e' is false, jump otherwise.\n*/\nvoid luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {\n      pc = e->u.info;  /* already jump if true */\n      break;\n    }\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);  /* jump if true */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert new jump in 't' list */\n  luaK_patchtohere(fs, e->f);  /* false list jumps to here (to go through) */\n  e->f = NO_JUMP;\n}\n\n\n/*\n** Code 'not e', doing constant folding.\n*/\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;  /* true == not nil == not false */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VTRUE: {\n      e->k = VFALSE;  /* false == not \"x\" == not 0.5 == not 1 == not true */\n      break;\n    }\n    case VJMP: {\n      negatecondition(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: lua_assert(0);  /* cannot happen */\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);  /* values are useless when negated */\n  removevalues(fs, e->t);\n}\n\n\n/*\n** Create expression 't[k]'. 't' must have its final result already in a\n** register or upvalue.\n*/\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));\n  t->u.ind.t = t->u.info;  /* register or upvalue index */\n  t->u.ind.idx = luaK_exp2RK(fs, k);  /* R/K index for key */\n  t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL : VLOCAL;\n  t->k = VINDEXED;\n}\n\n\n/*\n** Return false if folding can raise an error.\n** Bitwise operations need operands convertible to integers; division\n** operations cannot have 0 as divisor.\n*/\nstatic int validop (int op, TValue *v1, TValue *v2) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: {  /* conversion errors */\n      lua_Integer i;\n      return (tointeger(v1, &i) && tointeger(v2, &i));\n    }\n    case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD:  /* division by 0 */\n      return (nvalue(v2) != 0);\n    default: return 1;  /* everything else is valid */\n  }\n}\n\n\n/*\n** Try to \"constant-fold\" an operation; return 1 iff successful.\n** (In this case, 'e1' has the final result.)\n*/\nstatic int constfolding (FuncState *fs, int op, expdesc *e1,\n                                                const expdesc *e2) {\n  TValue v1, v2, res;\n  if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))\n    return 0;  /* non-numeric operands or not safe to fold */\n  luaO_arith(fs->ls->L, op, &v1, &v2, &res);  /* does operation */\n  if (ttisinteger(&res)) {\n    e1->k = VKINT;\n    e1->u.ival = ivalue(&res);\n  }\n  else {  /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */\n    lua_Number n = fltvalue(&res);\n    if (luai_numisnan(n) || n == 0)\n      return 0;\n    e1->k = VKFLT;\n    e1->u.nval = n;\n  }\n  return 1;\n}\n\n\n/*\n** Emit code for unary expressions that \"produce values\"\n** (everything but 'not').\n** Expression to produce final result will be encoded in 'e'.\n*/\nstatic void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {\n  int r = luaK_exp2anyreg(fs, e);  /* opcodes operate only on registers */\n  freeexp(fs, e);\n  e->u.info = luaK_codeABC(fs, op, 0, r, 0);  /* generate opcode */\n  e->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\"\n** (everything but logical operators 'and'/'or' and comparison\n** operators).\n** Expression to produce final result will be encoded in 'e1'.\n** Because 'luaK_exp2RK' can free registers, its calls must be\n** in \"stack order\" (that is, first on 'e2', which may have more\n** recent registers to be released).\n*/\nstatic void codebinexpval (FuncState *fs, OpCode op,\n                           expdesc *e1, expdesc *e2, int line) {\n  int rk2 = luaK_exp2RK(fs, e2);  /* both operands are \"RK\" */\n  int rk1 = luaK_exp2RK(fs, e1);\n  freeexps(fs, e1, e2);\n  e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2);  /* generate opcode */\n  e1->k = VRELOCABLE;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for comparisons.\n** 'e1' was already put in R/K form by 'luaK_infix'.\n*/\nstatic void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {\n  int rk1 = (e1->k == VK) ? RKASK(e1->u.info)\n                          : check_exp(e1->k == VNONRELOC, e1->u.info);\n  int rk2 = luaK_exp2RK(fs, e2);\n  freeexps(fs, e1, e2);\n  switch (opr) {\n    case OPR_NE: {  /* '(a ~= b)' ==> 'not (a == b)' */\n      e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2);\n      break;\n    }\n    case OPR_GT: case OPR_GE: {\n      /* '(a > b)' ==> '(b < a)';  '(a >= b)' ==> '(b <= a)' */\n      OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk2, rk1);  /* invert operands */\n      break;\n    }\n    default: {  /* '==', '<', '<=' use their own opcodes */\n      OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);\n      e1->u.info = condjump(fs, op, 1, rk1, rk2);\n      break;\n    }\n  }\n  e1->k = VJMP;\n}\n\n\n/*\n** Aplly prefix operation 'op' to expression 'e'.\n*/\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {\n  static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};\n  switch (op) {\n    case OPR_MINUS: case OPR_BNOT:  /* use 'ef' as fake 2nd operand */\n      if (constfolding(fs, op + LUA_OPUNM, e, &ef))\n        break;\n      /* FALLTHROUGH */\n    case OPR_LEN:\n      codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);\n      break;\n    case OPR_NOT: codenot(fs, e); break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Process 1st operand 'v' of binary operation 'op' before reading\n** 2nd operand.\n*/\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);  /* go ahead only if 'v' is true */\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);  /* go ahead only if 'v' is false */\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the 'stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB:\n    case OPR_MUL: case OPR_DIV: case OPR_IDIV:\n    case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2RK(fs, v);\n      /* else keep numeral, which may be folded with 2nd operand */\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\n/*\n** Finalize code for binary operation, after reading 2nd operand.\n** For '(a .. b .. c)' (which is '(a .. (b .. c))', because\n** concatenation is right associative), merge second CONCAT into first\n** one.\n*/\nvoid luaK_posfix (FuncState *fs, BinOpr op,\n                  expdesc *e1, expdesc *e2, int line) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list closed by 'luK_infix' */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE &&\n          GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getinstruction(fs, e2), e1->u.info);\n        e1->k = VRELOCABLE; e1->u.info = e2->u.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codebinexpval(fs, OP_CONCAT, e1, e2, line);\n      }\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_IDIV: case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!constfolding(fs, op + LUA_OPADD, e1, e2))\n        codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);\n      break;\n    }\n    case OPR_EQ: case OPR_LT: case OPR_LE:\n    case OPR_NE: case OPR_GT: case OPR_GE: {\n      codecomp(fs, op, e1, e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Change line information associated with current position.\n*/\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\n/*\n** Emit a SETLIST instruction.\n** 'base' is register that keeps table;\n** 'nelems' is #table plus those to be stored now;\n** 'tostore' is number of values (in registers 'base + 1',...) to add to\n** table (or LUA_MULTRET to add up to stack top).\n*/\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else if (c <= MAXARG_Ax) {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    codeextraarg(fs, c);\n  }\n  else\n    luaX_syntaxerror(fs->ls, \"constructor too long\");\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums  (ORDER OP)\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,\n  OPR_DIV,\n  OPR_IDIV,\n  OPR_BAND, OPR_BOR, OPR_BXOR,\n  OPR_SHL, OPR_SHR,\n  OPR_CONCAT,\n  OPR_EQ, OPR_LT, OPR_LE,\n  OPR_NE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n/* get (pointer to) instruction of given 'expdesc' */\n#define getinstruction(fs,e)\t((fs)->f->code[(e)->u.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\n#define luaK_jumpto(fs,t)\tluaK_patchlist(fs, luaK_jump(fs), t)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,\n                            expdesc *v2, int line);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lcorolib.c",
    "content": "/*\n** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 roberto Exp $\n** Coroutine Library\n** See Copyright Notice in lua.h\n*/\n\n#define lcorolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic lua_State *getco (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"thread expected\");\n  return co;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status;\n  if (!lua_checkstack(co, narg)) {\n    lua_pushliteral(L, \"too many arguments to resume\");\n    return -1;  /* error flag */\n  }\n  if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {\n    lua_pushliteral(L, \"cannot resume dead coroutine\");\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, L, narg);\n  if (status == LUA_OK || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1)) {\n      lua_pop(co, nres);  /* remove results anyway */\n      lua_pushliteral(L, \"too many results to resume\");\n      return -1;  /* error flag */\n    }\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = getco(L);\n  int r;\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + 'resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_type(L, -1) == LUA_TSTRING) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    return lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  NL = lua_newthread(L);\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = getco(L);\n  if (L == co) lua_pushliteral(L, \"running\");\n  else {\n    switch (lua_status(co)) {\n      case LUA_YIELD:\n        lua_pushliteral(L, \"suspended\");\n        break;\n      case LUA_OK: {\n        lua_Debug ar;\n        if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n          lua_pushliteral(L, \"normal\");  /* it is running */\n        else if (lua_gettop(co) == 0)\n            lua_pushliteral(L, \"dead\");\n        else\n          lua_pushliteral(L, \"suspended\");  /* initial state */\n        break;\n      }\n      default:  /* some error occurred */\n        lua_pushliteral(L, \"dead\");\n        break;\n    }\n  }\n  return 1;\n}\n\n\nstatic int luaB_yieldable (lua_State *L) {\n  lua_pushboolean(L, lua_isyieldable(L));\n  return 1;\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  int ismain = lua_pushthread(L);\n  lua_pushboolean(L, ismain);\n  return 2;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {\"isyieldable\", luaB_yieldable},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_coroutine (lua_State *L) {\n  luaL_newlib(L, co_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lctype.c",
    "content": "/*\n** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lctype_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lctype.h\"\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\nLUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {\n  0x00,  /* EOZ */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 0. */\n  0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 1. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\t/* 2. */\n  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,\t/* 3. */\n  0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 4. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 5. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 6. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 7. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 8. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 9. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* a. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* b. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* c. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* d. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* e. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* f. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n};\n\n#endif\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.3.5/src/lctype.h",
    "content": "/*\n** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lctype_h\n#define lctype_h\n\n#include \"lua.h\"\n\n\n/*\n** WARNING: the functions defined here do not necessarily correspond\n** to the similar functions in the standard C ctype.h. They are\n** optimized for the specific needs of Lua\n*/\n\n#if !defined(LUA_USE_CTYPE)\n\n#if 'A' == 65 && '0' == 48\n/* ASCII case: can use its own tables; faster and fixed */\n#define LUA_USE_CTYPE\t0\n#else\n/* must use standard C ctype */\n#define LUA_USE_CTYPE\t1\n#endif\n\n#endif\n\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n#include \"llimits.h\"\n\n\n#define ALPHABIT\t0\n#define DIGITBIT\t1\n#define PRINTBIT\t2\n#define SPACEBIT\t3\n#define XDIGITBIT\t4\n\n\n#define MASK(B)\t\t(1 << (B))\n\n\n/*\n** add 1 to char to allow index -1 (EOZ)\n*/\n#define testprop(c,p)\t(luai_ctype_[(c)+1] & (p))\n\n/*\n** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'\n*/\n#define lislalpha(c)\ttestprop(c, MASK(ALPHABIT))\n#define lislalnum(c)\ttestprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))\n#define lisdigit(c)\ttestprop(c, MASK(DIGITBIT))\n#define lisspace(c)\ttestprop(c, MASK(SPACEBIT))\n#define lisprint(c)\ttestprop(c, MASK(PRINTBIT))\n#define lisxdigit(c)\ttestprop(c, MASK(XDIGITBIT))\n\n/*\n** this 'ltolower' only works for alphabetic characters\n*/\n#define ltolower(c)\t((c) | ('A' ^ 'a'))\n\n\n/* two more entries for 0 and -1 (EOZ) */\nLUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];\n\n\n#else\t\t\t/* }{ */\n\n/*\n** use standard C ctypes\n*/\n\n#include <ctype.h>\n\n\n#define lislalpha(c)\t(isalpha(c) || (c) == '_')\n#define lislalnum(c)\t(isalnum(c) || (c) == '_')\n#define lisdigit(c)\t(isdigit(c))\n#define lisspace(c)\t(isspace(c))\n#define lisprint(c)\t(isprint(c))\n#define lisxdigit(c)\t(isxdigit(c))\n\n#define ltolower(c)\t(tolower(c))\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.151.1.1 2017/04/19 17:20:42 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** The hook table at registry[&HOOKKEY] maps threads to their current\n** hook function. (We only need the unique address of 'HOOKKEY'.)\n*/\nstatic const int HOOKKEY = 0;\n\n\n/*\n** If L1 != L, L1 can be in any state, and therefore there are no\n** guarantees about its stack space; any push in L1 must be\n** checked.\n*/\nstatic void checkstack (lua_State *L, lua_State *L1, int n) {\n  if (L != L1 && !lua_checkstack(L1, n))\n    luaL_error(L, \"stack overflow\");\n}\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;  /* return 1st argument */\n}\n\n\nstatic int db_getuservalue (lua_State *L) {\n  if (lua_type(L, 1) != LUA_TUSERDATA)\n    lua_pushnil(L);\n  else\n    lua_getuservalue(L, 1);\n  return 1;\n}\n\n\nstatic int db_setuservalue (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TUSERDATA);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_setuservalue(L, 1);\n  return 1;\n}\n\n\n/*\n** Auxiliary function used by several library functions: check for\n** an optional thread as function's first argument and set 'arg' with\n** 1 if this argument is present (so that functions can skip it to\n** access their other arguments)\n*/\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;  /* function will operate over current thread */\n  }\n}\n\n\n/*\n** Variations of 'lua_settable', used by 'db_getinfo' to put results\n** from 'lua_getinfo' into result table. Key is always a string;\n** value can be a string, an int, or a boolean.\n*/\nstatic void settabss (lua_State *L, const char *k, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsi (lua_State *L, const char *k, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsb (lua_State *L, const char *k, int v) {\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, k);\n}\n\n\n/*\n** In function 'db_getinfo', the call to 'lua_getinfo' may push\n** results on the stack; later it creates the result table to put\n** these objects. Function 'treatstackoption' puts the result from\n** 'lua_getinfo' on top of the result table so that it can call\n** 'lua_setfield'.\n*/\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1)\n    lua_rotate(L, -2, 1);  /* exchange object and table */\n  else\n    lua_xmove(L1, L, 1);  /* move object to the \"main\" stack */\n  lua_setfield(L, -2, fname);  /* put object into table */\n}\n\n\n/*\n** Calls 'lua_getinfo' and collects all results in a new table.\n** L1 needs stack space for an optional input (function) plus\n** two optional outputs (function and line table) from function\n** 'lua_getinfo'.\n*/\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnStu\");\n  checkstack(L, L1, 3);\n  if (lua_isfunction(L, arg + 1)) {  /* info about a function? */\n    options = lua_pushfstring(L, \">%s\", options);  /* add '>' to 'options' */\n    lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */\n    lua_xmove(L, L1, 1);\n  }\n  else {  /* stack level */\n    if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_newtable(L);  /* table to collect results */\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u')) {\n    settabsi(L, \"nups\", ar.nups);\n    settabsi(L, \"nparams\", ar.nparams);\n    settabsb(L, \"isvararg\", ar.isvararg);\n  }\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 't'))\n    settabsb(L, \"istailcall\", ar.istailcall);\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n\n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */\n  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\n    lua_pushvalue(L, arg + 1);  /* push function */\n    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\n    return 1;  /* return only name (there is no value) */\n  }\n  else {  /* stack-level argument */\n    int level = (int)luaL_checkinteger(L, arg + 1);\n    if (!lua_getstack(L1, level, &ar))  /* out of range? */\n      return luaL_argerror(L, arg+1, \"level out of range\");\n    checkstack(L, L1, 1);\n    name = lua_getlocal(L1, &ar, nvar);\n    if (name) {\n      lua_xmove(L1, L, 1);  /* move local value */\n      lua_pushstring(L, name);  /* push name */\n      lua_rotate(L, -2, 1);  /* re-order */\n      return 2;\n    }\n    else {\n      lua_pushnil(L);  /* no name (nor value) */\n      return 1;\n    }\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  const char *name;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  int level = (int)luaL_checkinteger(L, arg + 1);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);\n  if (!lua_getstack(L1, level, &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  checkstack(L, L1, 1);\n  lua_xmove(L, L1, 1);\n  name = lua_setlocal(L1, &ar, nvar);\n  if (name == NULL)\n    lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */\n  lua_pushstring(L, name);\n  return 1;\n}\n\n\n/*\n** get (if 'get' is true) or set an upvalue from a closure\n*/\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */\n  luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));  /* no-op if get is false */\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n/*\n** Check whether a given upvalue from a given closure exists and\n** returns its index\n*/\nstatic int checkupval (lua_State *L, int argf, int argnup) {\n  int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */\n  luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */\n  luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup,\n                   \"invalid upvalue index\");\n  return nup;\n}\n\n\nstatic int db_upvalueid (lua_State *L) {\n  int n = checkupval(L, 1, 2);\n  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\n  return 1;\n}\n\n\nstatic int db_upvaluejoin (lua_State *L) {\n  int n1 = checkupval(L, 1, 2);\n  int n2 = checkupval(L, 3, 4);\n  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, \"Lua function expected\");\n  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, \"Lua function expected\");\n  lua_upvaluejoin(L, 1, n1, 3, n2);\n  return 0;\n}\n\n\n/*\n** Call hook function registered at hook table for the current\n** thread (if there is one)\n*/\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail call\"};\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n  lua_pushthread(L);\n  if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */\n    lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);  /* push current line */\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);  /* call hook function */\n  }\n}\n\n\n/*\n** Convert a string mask (for 'sethook') into a bit mask\n*/\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\n/*\n** Convert a bit mask (for 'gethook') into a string mask\n*/\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = (int)luaL_optinteger(L, arg + 3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) {\n    lua_createtable(L, 0, 2);  /* create a hook table */\n    lua_pushvalue(L, -1);\n    lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY);  /* set it in position */\n    lua_pushstring(L, \"k\");\n    lua_setfield(L, -2, \"__mode\");  /** hooktable.__mode = \"k\" */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */\n  }\n  checkstack(L, L1, 1);\n  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */\n  lua_pushvalue(L, arg + 1);  /* value (hook function) */\n  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */\n  lua_sethook(L1, func, mask, count);\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook == NULL)  /* no hook? */\n    lua_pushnil(L);\n  else if (hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {  /* hook table must exist */\n    lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY);\n    checkstack(L, L1, 1);\n    lua_pushthread(L1); lua_xmove(L1, L, 1);\n    lua_rawget(L, -2);   /* 1st result = hooktable[L1] */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */\n  lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    lua_writestringerror(\"%s\", \"lua_debug> \");\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0))\n      lua_writestringerror(\"%s\\n\", lua_tostring(L, -1));\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\nstatic int db_traceback (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg + 1);\n  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\n    lua_pushvalue(L, arg + 1);  /* return it untouched */\n  else {\n    int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);\n    luaL_traceback(L, L1, msg, level);\n  }\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getuservalue\", db_getuservalue},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"upvaluejoin\", db_upvaluejoin},\n  {\"upvalueid\", db_upvalueid},\n  {\"setuservalue\", db_setuservalue},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_traceback},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_debug (lua_State *L) {\n  luaL_newlib(L, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.121.1.2 2017/07/10 17:21:50 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n#define noLuaClosure(f)\t\t((f) == NULL || (f)->c.tt == LUA_TCCL)\n\n\n/* Active Lua function (given call info) */\n#define ci_func(ci)\t\t(clLvalue((ci)->func))\n\n\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                    const char **name);\n\n\nstatic int currentpc (CallInfo *ci) {\n  lua_assert(isLua(ci));\n  return pcRel(ci->u.l.savedpc, ci_func(ci)->p);\n}\n\n\nstatic int currentline (CallInfo *ci) {\n  return getfuncline(ci_func(ci)->p, currentpc(ci));\n}\n\n\n/*\n** If function yielded, its 'func' can be in the 'extra' field. The\n** next function restores 'func' to its correct value for debugging\n** purposes. (It exchanges 'func' and 'extra'; so, when called again,\n** after debugging, it also \"re-restores\" ** 'func' to its altered value.\n*/\nstatic void swapextra (lua_State *L) {\n  if (L->status == LUA_YIELD) {\n    CallInfo *ci = L->ci;  /* get function that yielded */\n    StkId temp = ci->func;  /* exchange its 'func' and 'extra' values */\n    ci->func = restorestack(L, ci->extra);\n    ci->extra = savestack(L, temp);\n  }\n}\n\n\n/*\n** This function can be called asynchronously (e.g. during a signal).\n** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by\n** 'resethookcount') are for debug only, and it is no problem if they\n** get arbitrary values (causes at most one wrong hook call). 'hookmask'\n** is an atomic value. We assume that pointers are atomic too (e.g., gcc\n** ensures that for all platforms where it runs). Moreover, 'hook' is\n** always checked before being called (see 'luaD_hook').\n*/\nLUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  if (isLua(L->ci))\n    L->oldpc = L->ci->u.l.savedpc;\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  if (level < 0) return 0;  /* invalid (negative) level */\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)\n    level--;\n  if (level == 0 && ci != &L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = ci;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic const char *upvalname (Proto *p, int uv) {\n  TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);\n  if (s == NULL) return \"?\";\n  else return getstr(s);\n}\n\n\nstatic const char *findvararg (CallInfo *ci, int n, StkId *pos) {\n  int nparams = clLvalue(ci->func)->p->numparams;\n  if (n >= cast_int(ci->u.l.base - ci->func) - nparams)\n    return NULL;  /* no such vararg */\n  else {\n    *pos = ci->func + nparams + n;\n    return \"(*vararg)\";  /* generic name for any vararg */\n  }\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n,\n                              StkId *pos) {\n  const char *name = NULL;\n  StkId base;\n  if (isLua(ci)) {\n    if (n < 0)  /* access to vararg values? */\n      return findvararg(ci, -n, pos);\n    else {\n      base = ci->u.l.base;\n      name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));\n    }\n  }\n  else\n    base = ci->func + 1;\n  if (name == NULL) {  /* no 'standard' name? */\n    StkId limit = (ci == L->ci) ? L->top : ci->next->func;\n    if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      name = \"(*temporary)\";  /* generic name for any valid slot */\n    else\n      return NULL;  /* no name */\n  }\n  *pos = base + (n - 1);\n  return name;\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  if (ar == NULL) {  /* information about non-active function? */\n    if (!isLfunction(L->top - 1))  /* not a Lua function? */\n      name = NULL;\n    else  /* consider live variables at function start (parameters) */\n      name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);\n  }\n  else {  /* active function; get information through 'ar' */\n    StkId pos = NULL;  /* to avoid warnings */\n    name = findlocal(L, ar->i_ci, n, &pos);\n    if (name) {\n      setobj2s(L, L->top, pos);\n      api_incr_top(L);\n    }\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  StkId pos = NULL;  /* to avoid warnings */\n  const char *name;\n  lua_lock(L);\n  swapextra(L);\n  name = findlocal(L, ar->i_ci, n, &pos);\n  if (name) {\n    setobjs2s(L, pos, L->top - 1);\n    L->top--;  /* pop value */\n  }\n  swapextra(L);\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (noLuaClosure(cl)) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    Proto *p = cl->l.p;\n    ar->source = p->source ? getstr(p->source) : \"=?\";\n    ar->linedefined = p->linedefined;\n    ar->lastlinedefined = p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (noLuaClosure(f)) {\n    setnilvalue(L->top);\n    api_incr_top(L);\n  }\n  else {\n    int i;\n    TValue v;\n    int *lineinfo = f->l.p->lineinfo;\n    Table *t = luaH_new(L);  /* new table to store active lines */\n    sethvalue(L, L->top, t);  /* push it on stack */\n    api_incr_top(L);\n    setbvalue(&v, 1);  /* boolean 'true' to be the value of all indices */\n    for (i = 0; i < f->l.p->sizelineinfo; i++)  /* for all lines with code */\n      luaH_setint(L, t, lineinfo[i], &v);  /* table[line] = true */\n  }\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  if (ci == NULL)  /* no 'ci'? */\n    return NULL;  /* no info */\n  else if (ci->callstatus & CIST_FIN) {  /* is this a finalizer? */\n    *name = \"__gc\";\n    return \"metamethod\";  /* report it as such */\n  }\n  /* calling function is a known Lua function? */\n  else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))\n    return funcnamefromcode(L, ci->previous, name);\n  else return NULL;  /* no way to find a name */\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                       Closure *f, CallInfo *ci) {\n  int status = 1;\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = (f == NULL) ? 0 : f->c.nupvalues;\n        if (noLuaClosure(f)) {\n          ar->isvararg = 1;\n          ar->nparams = 0;\n        }\n        else {\n          ar->isvararg = f->l.p->is_vararg;\n          ar->nparams = f->l.p->numparams;\n        }\n        break;\n      }\n      case 't': {\n        ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = getfuncname(L, ci, &ar->name);\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *cl;\n  CallInfo *ci;\n  StkId func;\n  lua_lock(L);\n  swapextra(L);\n  if (*what == '>') {\n    ci = NULL;\n    func = L->top - 1;\n    api_check(L, ttisfunction(func), \"function expected\");\n    what++;  /* skip the '>' */\n    L->top--;  /* pop function */\n  }\n  else {\n    ci = ar->i_ci;\n    func = ci->func;\n    lua_assert(ttisfunction(ci->func));\n  }\n  cl = ttisclosure(func) ? clvalue(func) : NULL;\n  status = auxgetinfo(L, what, ar, cl, ci);\n  if (strchr(what, 'f')) {\n    setobjs2s(L, L->top, func);\n    api_incr_top(L);\n  }\n  swapextra(L);  /* correct before option 'L', which can raise a mem. error */\n  if (strchr(what, 'L'))\n    collectvalidlines(L, cl);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution\n** =======================================================\n*/\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name);\n\n\n/*\n** find a \"name\" for the RK value 'c'\n*/\nstatic void kname (Proto *p, int pc, int c, const char **name) {\n  if (ISK(c)) {  /* is 'c' a constant? */\n    TValue *kvalue = &p->k[INDEXK(c)];\n    if (ttisstring(kvalue)) {  /* literal constant? */\n      *name = svalue(kvalue);  /* it is its own name */\n      return;\n    }\n    /* else no reasonable name found */\n  }\n  else {  /* 'c' is a register */\n    const char *what = getobjname(p, pc, c, name); /* search for 'c' */\n    if (what && *what == 'c') {  /* found a constant name? */\n      return;  /* 'name' already filled */\n    }\n    /* else no reasonable name found */\n  }\n  *name = \"?\";  /* no reasonable name found */\n}\n\n\nstatic int filterpc (int pc, int jmptarget) {\n  if (pc < jmptarget)  /* is code conditional (inside a jump)? */\n    return -1;  /* cannot know who sets that register */\n  else return pc;  /* current position sets that register */\n}\n\n\n/*\n** try to find last instruction before 'lastpc' that modified register 'reg'\n*/\nstatic int findsetreg (Proto *p, int lastpc, int reg) {\n  int pc;\n  int setreg = -1;  /* keep last instruction that changed 'reg' */\n  int jmptarget = 0;  /* any code before this address is conditional */\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    switch (op) {\n      case OP_LOADNIL: {\n        int b = GETARG_B(i);\n        if (a <= reg && reg <= a + b)  /* set registers from 'a' to 'a+b' */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_TFORCALL: {\n        if (reg >= a + 2)  /* affect all regs above its base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (reg >= a)  /* affect all registers above base */\n          setreg = filterpc(pc, jmptarget);\n        break;\n      }\n      case OP_JMP: {\n        int b = GETARG_sBx(i);\n        int dest = pc + 1 + b;\n        /* jump is forward and do not skip 'lastpc'? */\n        if (pc < dest && dest <= lastpc) {\n          if (dest > jmptarget)\n            jmptarget = dest;  /* update 'jmptarget' */\n        }\n        break;\n      }\n      default:\n        if (testAMode(op) && reg == a)  /* any instruction that set A */\n          setreg = filterpc(pc, jmptarget);\n        break;\n    }\n  }\n  return setreg;\n}\n\n\nstatic const char *getobjname (Proto *p, int lastpc, int reg,\n                               const char **name) {\n  int pc;\n  *name = luaF_getlocalname(p, reg + 1, lastpc);\n  if (*name)  /* is a local? */\n    return \"local\";\n  /* else try symbolic execution */\n  pc = findsetreg(p, lastpc, reg);\n  if (pc != -1) {  /* could find instruction? */\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    switch (op) {\n      case OP_MOVE: {\n        int b = GETARG_B(i);  /* move from 'b' to 'a' */\n        if (b < GETARG_A(i))\n          return getobjname(p, pc, b, name);  /* get name for 'b' */\n        break;\n      }\n      case OP_GETTABUP:\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        int t = GETARG_B(i);  /* table index */\n        const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */\n                         ? luaF_getlocalname(p, t + 1, pc)\n                         : upvalname(p, t);\n        kname(p, pc, k, name);\n        return (vn && strcmp(vn, LUA_ENV) == 0) ? \"global\" : \"field\";\n      }\n      case OP_GETUPVAL: {\n        *name = upvalname(p, GETARG_B(i));\n        return \"upvalue\";\n      }\n      case OP_LOADK:\n      case OP_LOADKX: {\n        int b = (op == OP_LOADK) ? GETARG_Bx(i)\n                                 : GETARG_Ax(p->code[pc + 1]);\n        if (ttisstring(&p->k[b])) {\n          *name = svalue(&p->k[b]);\n          return \"constant\";\n        }\n        break;\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, pc, k, name);\n        return \"method\";\n      }\n      default: break;  /* go through to return NULL */\n    }\n  }\n  return NULL;  /* could not find reasonable name */\n}\n\n\n/*\n** Try to find a name for a function based on the code that called it.\n** (Only works when function was called by a Lua function.)\n** Returns what the name is (e.g., \"for iterator\", \"method\",\n** \"metamethod\") and sets '*name' to point to the name.\n*/\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                     const char **name) {\n  TMS tm = (TMS)0;  /* (initial value avoids warnings) */\n  Proto *p = ci_func(ci)->p;  /* calling function */\n  int pc = currentpc(ci);  /* calling instruction index */\n  Instruction i = p->code[pc];  /* calling instruction */\n  if (ci->callstatus & CIST_HOOKED) {  /* was it called inside a hook? */\n    *name = \"?\";\n    return \"hook\";\n  }\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n      return getobjname(p, pc, GETARG_A(i), name);  /* get function name */\n    case OP_TFORCALL: {  /* for iterator */\n      *name = \"for iterator\";\n       return \"for iterator\";\n    }\n    /* other instructions can do calls through metamethods */\n    case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:\n      tm = TM_INDEX;\n      break;\n    case OP_SETTABUP: case OP_SETTABLE:\n      tm = TM_NEWINDEX;\n      break;\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:\n    case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:\n    case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {\n      int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD);  /* ORDER OP */\n      tm = cast(TMS, offset + cast_int(TM_ADD));  /* ORDER TM */\n      break;\n    }\n    case OP_UNM: tm = TM_UNM; break;\n    case OP_BNOT: tm = TM_BNOT; break;\n    case OP_LEN: tm = TM_LEN; break;\n    case OP_CONCAT: tm = TM_CONCAT; break;\n    case OP_EQ: tm = TM_EQ; break;\n    case OP_LT: tm = TM_LT; break;\n    case OP_LE: tm = TM_LE; break;\n    default:\n      return NULL;  /* cannot find a reasonable name */\n  }\n  *name = getstr(G(L)->tmname[tm]);\n  return \"metamethod\";\n}\n\n/* }====================================================== */\n\n\n\n/*\n** The subtraction of two potentially unrelated pointers is\n** not ISO C, but it should not crash a program; the subsequent\n** checks are ISO C and ensure a correct result.\n*/\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  ptrdiff_t i = o - ci->u.l.base;\n  return (0 <= i && i < (ci->top - ci->u.l.base) && ci->u.l.base + i == o);\n}\n\n\n/*\n** Checks whether value 'o' came from an upvalue. (That can only happen\n** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on\n** upvalues.)\n*/\nstatic const char *getupvalname (CallInfo *ci, const TValue *o,\n                                 const char **name) {\n  LClosure *c = ci_func(ci);\n  int i;\n  for (i = 0; i < c->nupvalues; i++) {\n    if (c->upvals[i]->v == o) {\n      *name = upvalname(c->p, i);\n      return \"upvalue\";\n    }\n  }\n  return NULL;\n}\n\n\nstatic const char *varinfo (lua_State *L, const TValue *o) {\n  const char *name = NULL;  /* to avoid warnings */\n  CallInfo *ci = L->ci;\n  const char *kind = NULL;\n  if (isLua(ci)) {\n    kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */\n    if (!kind && isinstack(ci, o))  /* no? try a register */\n      kind = getobjname(ci_func(ci)->p, currentpc(ci),\n                        cast_int(o - ci->u.l.base), &name);\n  }\n  return (kind) ? luaO_pushfstring(L, \" (%s '%s')\", kind, name) : \"\";\n}\n\n\nl_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *t = luaT_objtypename(L, o);\n  luaG_runerror(L, \"attempt to %s a %s value%s\", op, t, varinfo(L, o));\n}\n\n\nl_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {\n  if (ttisstring(p1) || cvt2str(p1)) p1 = p2;\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nl_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                         const TValue *p2, const char *msg) {\n  lua_Number temp;\n  if (!tonumber(p1, &temp))  /* first operand is wrong? */\n    p2 = p1;  /* now second is wrong */\n  luaG_typeerror(L, p2, msg);\n}\n\n\n/*\n** Error when both values are convertible to numbers, but not to integers\n*/\nl_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {\n  lua_Integer temp;\n  if (!tointeger(p1, &temp))\n    p2 = p1;\n  luaG_runerror(L, \"number%s has no integer representation\", varinfo(L, p2));\n}\n\n\nl_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_objtypename(L, p1);\n  const char *t2 = luaT_objtypename(L, p2);\n  if (strcmp(t1, t2) == 0)\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n}\n\n\n/* add src:line information to 'msg' */\nconst char *luaG_addinfo (lua_State *L, const char *msg, TString *src,\n                                        int line) {\n  char buff[LUA_IDSIZE];\n  if (src)\n    luaO_chunkid(buff, getstr(src), LUA_IDSIZE);\n  else {  /* no source available; use \"?\" instead */\n    buff[0] = '?'; buff[1] = '\\0';\n  }\n  return luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n}\n\n\nl_noret luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    L->top++;  /* assume EXTRA_STACK */\n    luaD_callnoyield(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nl_noret luaG_runerror (lua_State *L, const char *fmt, ...) {\n  CallInfo *ci = L->ci;\n  const char *msg;\n  va_list argp;\n  luaC_checkGC(L);  /* error message uses memory */\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);  /* format message */\n  va_end(argp);\n  if (isLua(ci))  /* if Lua function, add source:line information */\n    luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));\n  luaG_errormsg(L);\n}\n\n\nvoid luaG_traceexec (lua_State *L) {\n  CallInfo *ci = L->ci;\n  lu_byte mask = L->hookmask;\n  int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));\n  if (counthook)\n    resethookcount(L);  /* reset count */\n  else if (!(mask & LUA_MASKLINE))\n    return;  /* no line hook and count != 0; nothing to be done */\n  if (ci->callstatus & CIST_HOOKYIELD) {  /* called hook last time? */\n    ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */\n    return;  /* do not call hook again (VM yielded, so it did not move) */\n  }\n  if (counthook)\n    luaD_hook(L, LUA_HOOKCOUNT, -1);  /* call count hook */\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(ci)->p;\n    int npc = pcRel(ci->u.l.savedpc, p);\n    int newline = getfuncline(p, npc);\n    if (npc == 0 ||  /* call linehook when enter a new function, */\n        ci->u.l.savedpc <= L->oldpc ||  /* when jump back (loop), or when */\n        newline != getfuncline(p, pcRel(L->oldpc, p)))  /* enter a new line */\n      luaD_hook(L, LUA_HOOKLINE, newline);  /* call line hook */\n  }\n  L->oldpc = ci->u.l.savedpc;\n  if (L->status == LUA_YIELD) {  /* did hook yield? */\n    if (counthook)\n      L->hookcount = 1;  /* undo decrement to zero */\n    ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */\n    ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */\n    ci->func = L->top - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getfuncline(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : -1)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,\n                                                const char *opname);\nLUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,\n                                                  const TValue *p2);\nLUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2,\n                                                 const char *msg);\nLUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,\n                                                  TString *src, int line);\nLUAI_FUNC l_noret luaG_errormsg (lua_State *L);\nLUAI_FUNC void luaG_traceexec (lua_State *L);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.157.1.1 2017/04/19 17:20:42 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n#define errorstatus(s)\t((s) > LUA_YIELD)\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n/*\n** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By\n** default, Lua handles errors with exceptions when compiling as\n** C++ code, with _longjmp/_setjmp when asked to use them, and with\n** longjmp/setjmp otherwise.\n*/\n#if !defined(LUAI_THROW)\t\t\t\t/* { */\n\n#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)\t/* { */\n\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\t\tthrow(c)\n#define LUAI_TRY(L,c,a) \\\n\ttry { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\t\tint  /* dummy variable */\n\n#elif defined(LUA_USE_POSIX)\t\t\t\t/* }{ */\n\n/* in POSIX, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#else\t\t\t\t\t\t\t/* }{ */\n\n/* ISO C handling with long jumps */\n#define LUAI_THROW(L,c)\t\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#endif\t\t\t\t\t\t\t/* } */\n\n#endif\t\t\t\t\t\t\t/* } */\n\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nstatic void seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {  /* memory error? */\n      setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    default: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nl_noret luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {  /* thread has an error handler? */\n    L->errorJmp->status = errcode;  /* set status */\n    LUAI_THROW(L, L->errorJmp);  /* jump to it */\n  }\n  else {  /* thread has no error handler */\n    global_State *g = G(L);\n    L->status = cast_byte(errcode);  /* mark it as dead */\n    if (g->mainthread->errorJmp) {  /* main thread has a handler? */\n      setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */\n      luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */\n    }\n    else {  /* no handler at all; abort */\n      if (g->panic) {  /* panic function? */\n        seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */\n        if (L->ci->top < L->top)\n          L->ci->top = L->top;  /* pushing msg. can break this invariant */\n        lua_unlock(L);\n        g->panic(L);  /* call panic function (last chance to jump out) */\n      }\n      abort();\n    }\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  unsigned short oldnCcalls = L->nCcalls;\n  struct lua_longjmp lj;\n  lj.status = LUA_OK;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  L->nCcalls = oldnCcalls;\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\n/*\n** {==================================================================\n** Stack reallocation\n** ===================================================================\n*/\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  UpVal *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->u.open.next)\n    up->v = (up->v - oldstack) + L->stack;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n    if (isLua(ci))\n      ci->u.l.base = (ci->u.l.base - oldstack) + L->stack;\n  }\n}\n\n\n/* some space for error handling */\n#define ERRORSTACKSIZE\t(LUAI_MAXSTACK + 200)\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int lim = L->stacksize;\n  lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);\n  luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);\n  for (; lim < newsize; lim++)\n    setnilvalue(L->stack + lim); /* erase new segment */\n  L->stacksize = newsize;\n  L->stack_last = L->stack + newsize - EXTRA_STACK;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  int size = L->stacksize;\n  if (size > LUAI_MAXSTACK)  /* error after extra size? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;\n    int newsize = 2 * size;\n    if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;\n    if (newsize < needed) newsize = needed;\n    if (newsize > LUAI_MAXSTACK) {  /* stack overflow? */\n      luaD_reallocstack(L, ERRORSTACKSIZE);\n      luaG_runerror(L, \"stack overflow\");\n    }\n    else\n      luaD_reallocstack(L, newsize);\n  }\n}\n\n\nstatic int stackinuse (lua_State *L) {\n  CallInfo *ci;\n  StkId lim = L->top;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    if (lim < ci->top) lim = ci->top;\n  }\n  lua_assert(lim <= L->stack_last);\n  return cast_int(lim - L->stack) + 1;  /* part of stack in use */\n}\n\n\nvoid luaD_shrinkstack (lua_State *L) {\n  int inuse = stackinuse(L);\n  int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;\n  if (goodsize > LUAI_MAXSTACK)\n    goodsize = LUAI_MAXSTACK;  /* respect stack limit */\n  if (L->stacksize > LUAI_MAXSTACK)  /* had been handling stack overflow? */\n    luaE_freeCI(L);  /* free all CIs (list grew because of an error) */\n  else\n    luaE_shrinkCI(L);  /* shrink list */\n  /* if thread is currently not handling a stack overflow and its\n     good size is smaller than current size, shrink its stack */\n  if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) &&\n      goodsize < L->stacksize)\n    luaD_reallocstack(L, goodsize);\n  else  /* don't change stack */\n    condmovestack(L,{},{});  /* (change only for debugging) */\n}\n\n\nvoid luaD_inctop (lua_State *L) {\n  luaD_checkstack(L, 1);\n  L->top++;\n}\n\n/* }================================================================== */\n\n\n/*\n** Call a hook for the given event. Make sure there is a hook to be\n** called. (Both 'L->hook' and 'L->hookmask', which triggers this\n** function, can be changed asynchronously by signals.)\n*/\nvoid luaD_hook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {  /* make sure there is a hook */\n    CallInfo *ci = L->ci;\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    ar.i_ci = ci;\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    ci->top = L->top + LUA_MINSTACK;\n    lua_assert(ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    ci->callstatus |= CIST_HOOKED;\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n    ci->callstatus &= ~CIST_HOOKED;\n  }\n}\n\n\nstatic void callhook (lua_State *L, CallInfo *ci) {\n  int hook = LUA_HOOKCALL;\n  ci->u.l.savedpc++;  /* hooks assume 'pc' is already incremented */\n  if (isLua(ci->previous) &&\n      GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {\n    ci->callstatus |= CIST_TAIL;\n    hook = LUA_HOOKTAILCALL;\n  }\n  luaD_hook(L, hook, -1);\n  ci->u.l.savedpc--;  /* correct 'pc' */\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n  StkId base, fixed;\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i = 0; i < nfixargs && i < actual; i++) {\n    setobjs2s(L, L->top++, fixed + i);\n    setnilvalue(fixed + i);  /* erase original copy (for GC) */\n  }\n  for (; i < nfixargs; i++)\n    setnilvalue(L->top++);  /* complete missing arguments */\n  return base;\n}\n\n\n/*\n** Check whether __call metafield of 'func' is a function. If so, put\n** it in stack below original 'func' so that 'luaD_precall' can call\n** it. Raise an error if __call metafield is not a function.\n*/\nstatic void tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at 'func' */\n  for (p = L->top; p > func; p--)\n    setobjs2s(L, p, p-1);\n  L->top++;  /* slot ensured by caller */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n}\n\n\n/*\n** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.\n** Handle most typical cases (zero results for commands, one result for\n** expressions, multiple results for tail calls/single parameters)\n** separated.\n*/\nstatic int moveresults (lua_State *L, const TValue *firstResult, StkId res,\n                                      int nres, int wanted) {\n  switch (wanted) {  /* handle typical cases separately */\n    case 0: break;  /* nothing to move */\n    case 1: {  /* one result needed */\n      if (nres == 0)   /* no results? */\n        firstResult = luaO_nilobject;  /* adjust with nil */\n      setobjs2s(L, res, firstResult);  /* move it to proper place */\n      break;\n    }\n    case LUA_MULTRET: {\n      int i;\n      for (i = 0; i < nres; i++)  /* move all results to correct place */\n        setobjs2s(L, res + i, firstResult + i);\n      L->top = res + nres;\n      return 0;  /* wanted == LUA_MULTRET */\n    }\n    default: {\n      int i;\n      if (wanted <= nres) {  /* enough results? */\n        for (i = 0; i < wanted; i++)  /* move wanted results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n      }\n      else {  /* not enough results; use all of them plus nils */\n        for (i = 0; i < nres; i++)  /* move all results to correct place */\n          setobjs2s(L, res + i, firstResult + i);\n        for (; i < wanted; i++)  /* complete wanted number of results */\n          setnilvalue(res + i);\n      }\n      break;\n    }\n  }\n  L->top = res + wanted;  /* top points after the last result */\n  return 1;\n}\n\n\n/*\n** Finishes a function call: calls hook if necessary, removes CallInfo,\n** moves current number of results to proper place; returns 0 iff call\n** wanted multiple (variable number of) results.\n*/\nint luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {\n  StkId res;\n  int wanted = ci->nresults;\n  if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) {\n    if (L->hookmask & LUA_MASKRET) {\n      ptrdiff_t fr = savestack(L, firstResult);  /* hook may change stack */\n      luaD_hook(L, LUA_HOOKRET, -1);\n      firstResult = restorestack(L, fr);\n    }\n    L->oldpc = ci->previous->u.l.savedpc;  /* 'oldpc' for caller function */\n  }\n  res = ci->func;  /* res == final position of 1st result */\n  L->ci = ci->previous;  /* back to caller */\n  /* move results to proper place */\n  return moveresults(L, firstResult, res, nres, wanted);\n}\n\n\n\n#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))\n\n\n/* macro to check stack size, preserving 'p' */\n#define checkstackp(L,n,p)  \\\n  luaD_checkstackaux(L, n, \\\n    ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \\\n    luaC_checkGC(L),  /* stack grow uses memory */ \\\n    p = restorestack(L, t__))  /* 'pos' part: restore 'p' */\n\n\n/*\n** Prepares a function call: checks the stack, creates a new CallInfo\n** entry, fills in the relevant information, calls hook if needed.\n** If function is a C function, does the call, too. (Otherwise, leave\n** the execution ('luaV_execute') to the caller, to allow stackless\n** calls.) Returns true iff function has been executed (C function).\n*/\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  lua_CFunction f;\n  CallInfo *ci;\n  switch (ttype(func)) {\n    case LUA_TCCL:  /* C closure */\n      f = clCvalue(func)->f;\n      goto Cfunc;\n    case LUA_TLCF:  /* light C function */\n      f = fvalue(func);\n     Cfunc: {\n      int n;  /* number of returns */\n      checkstackp(L, LUA_MINSTACK, func);  /* ensure minimum stack size */\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->top = L->top + LUA_MINSTACK;\n      lua_assert(ci->top <= L->stack_last);\n      ci->callstatus = 0;\n      if (L->hookmask & LUA_MASKCALL)\n        luaD_hook(L, LUA_HOOKCALL, -1);\n      lua_unlock(L);\n      n = (*f)(L);  /* do the actual call */\n      lua_lock(L);\n      api_checknelems(L, n);\n      luaD_poscall(L, ci, L->top - n, n);\n      return 1;\n    }\n    case LUA_TLCL: {  /* Lua function: prepare its call */\n      StkId base;\n      Proto *p = clLvalue(func)->p;\n      int n = cast_int(L->top - func) - 1;  /* number of real arguments */\n      int fsize = p->maxstacksize;  /* frame size */\n      checkstackp(L, fsize, func);\n      if (p->is_vararg)\n        base = adjust_varargs(L, p, n);\n      else {  /* non vararg function */\n        for (; n < p->numparams; n++)\n          setnilvalue(L->top++);  /* complete missing arguments */\n        base = func + 1;\n      }\n      ci = next_ci(L);  /* now 'enter' new function */\n      ci->nresults = nresults;\n      ci->func = func;\n      ci->u.l.base = base;\n      L->top = ci->top = base + fsize;\n      lua_assert(ci->top <= L->stack_last);\n      ci->u.l.savedpc = p->code;  /* starting point */\n      ci->callstatus = CIST_LUA;\n      if (L->hookmask & LUA_MASKCALL)\n        callhook(L, ci);\n      return 0;\n    }\n    default: {  /* not a function */\n      checkstackp(L, 1, func);  /* ensure space for metamethod */\n      tryfuncTM(L, func);  /* try to get '__call' metamethod */\n      return luaD_precall(L, func, nresults);  /* now it must be a function */\n    }\n  }\n}\n\n\n/*\n** Check appropriate error for stack overflow (\"regular\" overflow or\n** overflow while handling stack overflow). If 'nCalls' is larger than\n** LUAI_MAXCCALLS (which means it is handling a \"regular\" overflow) but\n** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to\n** allow overflow handling to work)\n*/\nstatic void stackerror (lua_State *L) {\n  if (L->nCcalls == LUAI_MAXCCALLS)\n    luaG_runerror(L, \"C stack overflow\");\n  else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n    luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/\nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS)\n    stackerror(L);\n  if (!luaD_precall(L, func, nResults))  /* is a Lua function? */\n    luaV_execute(L);  /* call it */\n  L->nCcalls--;\n}\n\n\n/*\n** Similar to 'luaD_call', but does not allow yields during the call\n*/\nvoid luaD_callnoyield (lua_State *L, StkId func, int nResults) {\n  L->nny++;\n  luaD_call(L, func, nResults);\n  L->nny--;\n}\n\n\n/*\n** Completes the execution of an interrupted C function, calling its\n** continuation function.\n*/\nstatic void finishCcall (lua_State *L, int status) {\n  CallInfo *ci = L->ci;\n  int n;\n  /* must have a continuation and must be able to call it */\n  lua_assert(ci->u.c.k != NULL && L->nny == 0);\n  /* error status can only happen in a protected call */\n  lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD);\n  if (ci->callstatus & CIST_YPCALL) {  /* was inside a pcall? */\n    ci->callstatus &= ~CIST_YPCALL;  /* continuation is also inside it */\n    L->errfunc = ci->u.c.old_errfunc;  /* with the same error function */\n  }\n  /* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already\n     handled */\n  adjustresults(L, ci->nresults);\n  lua_unlock(L);\n  n = (*ci->u.c.k)(L, status, ci->u.c.ctx);  /* call continuation function */\n  lua_lock(L);\n  api_checknelems(L, n);\n  luaD_poscall(L, ci, L->top - n, n);  /* finish 'luaD_precall' */\n}\n\n\n/*\n** Executes \"full continuation\" (everything in the stack) of a\n** previously interrupted coroutine until the stack is empty (or another\n** interruption long-jumps out of the loop). If the coroutine is\n** recovering from an error, 'ud' points to the error status, which must\n** be passed to the first continuation function (otherwise the default\n** status is LUA_YIELD).\n*/\nstatic void unroll (lua_State *L, void *ud) {\n  if (ud != NULL)  /* error status? */\n    finishCcall(L, *(int *)ud);  /* finish 'lua_pcallk' callee */\n  while (L->ci != &L->base_ci) {  /* something in the stack */\n    if (!isLua(L->ci))  /* C function? */\n      finishCcall(L, LUA_YIELD);  /* complete its execution */\n    else {  /* Lua function */\n      luaV_finishOp(L);  /* finish interrupted instruction */\n      luaV_execute(L);  /* execute down to higher C 'boundary' */\n    }\n  }\n}\n\n\n/*\n** Try to find a suspended protected call (a \"recover point\") for the\n** given thread.\n*/\nstatic CallInfo *findpcall (lua_State *L) {\n  CallInfo *ci;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {  /* search for a pcall */\n    if (ci->callstatus & CIST_YPCALL)\n      return ci;\n  }\n  return NULL;  /* no pending pcall */\n}\n\n\n/*\n** Recovers from an error in a coroutine. Finds a recover point (if\n** there is one) and completes the execution of the interrupted\n** 'luaD_pcall'. If there is no recover point, returns zero.\n*/\nstatic int recover (lua_State *L, int status) {\n  StkId oldtop;\n  CallInfo *ci = findpcall(L);\n  if (ci == NULL) return 0;  /* no recovery point */\n  /* \"finish\" luaD_pcall */\n  oldtop = restorestack(L, ci->extra);\n  luaF_close(L, oldtop);\n  seterrorobj(L, status, oldtop);\n  L->ci = ci;\n  L->allowhook = getoah(ci->callstatus);  /* restore original 'allowhook' */\n  L->nny = 0;  /* should be zero to be yieldable */\n  luaD_shrinkstack(L);\n  L->errfunc = ci->u.c.old_errfunc;\n  return 1;  /* continue running the coroutine */\n}\n\n\n/*\n** Signal an error in the call to 'lua_resume', not in the execution\n** of the coroutine itself. (Such errors should not be handled by any\n** coroutine error handler and should not kill the coroutine.)\n*/\nstatic int resume_error (lua_State *L, const char *msg, int narg) {\n  L->top -= narg;  /* remove args from the stack */\n  setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */\n  api_incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\n/*\n** Do the work for 'lua_resume' in protected mode. Most of the work\n** depends on the status of the coroutine: initial state, suspended\n** inside a hook, or regularly suspended (optionally with a continuation\n** function), plus erroneous cases: non-suspended coroutine or dead\n** coroutine.\n*/\nstatic void resume (lua_State *L, void *ud) {\n  int n = *(cast(int*, ud));  /* number of arguments */\n  StkId firstArg = L->top - n;  /* first argument */\n  CallInfo *ci = L->ci;\n  if (L->status == LUA_OK) {  /* starting a coroutine? */\n    if (!luaD_precall(L, firstArg - 1, LUA_MULTRET))  /* Lua function? */\n      luaV_execute(L);  /* call it */\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = LUA_OK;  /* mark that it is running (again) */\n    ci->func = restorestack(L, ci->extra);\n    if (isLua(ci))  /* yielded inside a hook? */\n      luaV_execute(L);  /* just continue running Lua code */\n    else {  /* 'common' yield */\n      if (ci->u.c.k != NULL) {  /* does it have a continuation function? */\n        lua_unlock(L);\n        n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */\n        lua_lock(L);\n        api_checknelems(L, n);\n        firstArg = L->top - n;  /* yield results come from continuation */\n      }\n      luaD_poscall(L, ci, firstArg, n);  /* finish 'luaD_precall' */\n    }\n    unroll(L, NULL);  /* run continuation */\n  }\n}\n\n\nLUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {\n  int status;\n  unsigned short oldnny = L->nny;  /* save \"number of non-yieldable\" calls */\n  lua_lock(L);\n  if (L->status == LUA_OK) {  /* may be starting a coroutine */\n    if (L->ci != &L->base_ci)  /* not in base level? */\n      return resume_error(L, \"cannot resume non-suspended coroutine\", nargs);\n  }\n  else if (L->status != LUA_YIELD)\n    return resume_error(L, \"cannot resume dead coroutine\", nargs);\n  L->nCcalls = (from) ? from->nCcalls + 1 : 1;\n  if (L->nCcalls >= LUAI_MAXCCALLS)\n    return resume_error(L, \"C stack overflow\", nargs);\n  luai_userstateresume(L, nargs);\n  L->nny = 0;  /* allow yields */\n  api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);\n  status = luaD_rawrunprotected(L, resume, &nargs);\n  if (status == -1)  /* error calling 'lua_resume'? */\n    status = LUA_ERRRUN;\n  else {  /* continue running after recoverable errors */\n    while (errorstatus(status) && recover(L, status)) {\n      /* unroll continuation */\n      status = luaD_rawrunprotected(L, unroll, &status);\n    }\n    if (errorstatus(status)) {  /* unrecoverable error? */\n      L->status = cast_byte(status);  /* mark thread as 'dead' */\n      seterrorobj(L, status, L->top);  /* push error message */\n      L->ci->top = L->top;\n    }\n    else lua_assert(status == L->status);  /* normal end or yield */\n  }\n  L->nny = oldnny;  /* restore 'nny' */\n  L->nCcalls--;\n  lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_isyieldable (lua_State *L) {\n  return (L->nny == 0);\n}\n\n\nLUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,\n                        lua_KFunction k) {\n  CallInfo *ci = L->ci;\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  api_checknelems(L, nresults);\n  if (L->nny > 0) {\n    if (L != G(L)->mainthread)\n      luaG_runerror(L, \"attempt to yield across a C-call boundary\");\n    else\n      luaG_runerror(L, \"attempt to yield from outside a coroutine\");\n  }\n  L->status = LUA_YIELD;\n  ci->extra = savestack(L, ci->func);  /* save current 'func' */\n  if (isLua(ci)) {  /* inside a hook? */\n    api_check(L, k == NULL, \"hooks cannot continue after yielding\");\n  }\n  else {\n    if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */\n      ci->u.c.ctx = ctx;  /* save context */\n    ci->func = L->top - nresults - 1;  /* protect stack below results */\n    luaD_throw(L, LUA_YIELD);\n  }\n  lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */\n  lua_unlock(L);\n  return 0;  /* return to 'luaD_hook' */\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  CallInfo *old_ci = L->ci;\n  lu_byte old_allowhooks = L->allowhook;\n  unsigned short old_nny = L->nny;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != LUA_OK) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close possible pending closures */\n    seterrorobj(L, status, oldtop);\n    L->ci = old_ci;\n    L->allowhook = old_allowhooks;\n    L->nny = old_nny;\n    luaD_shrinkstack(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to 'f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* dynamic structure used by the scanner */\n  Dyndata dyd;  /* dynamic structures used by the parser */\n  const char *mode;\n  const char *name;\n};\n\n\nstatic void checkmode (lua_State *L, const char *mode, const char *x) {\n  if (mode && strchr(mode, x[0]) == NULL) {\n    luaO_pushfstring(L,\n       \"attempt to load a %s chunk (mode is '%s')\", x, mode);\n    luaD_throw(L, LUA_ERRSYNTAX);\n  }\n}\n\n\nstatic void f_parser (lua_State *L, void *ud) {\n  LClosure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = zgetc(p->z);  /* read first character */\n  if (c == LUA_SIGNATURE[0]) {\n    checkmode(L, p->mode, \"binary\");\n    cl = luaU_undump(L, p->z, p->name);\n  }\n  else {\n    checkmode(L, p->mode, \"text\");\n    cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);\n  }\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luaF_initupvals(L, cl);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                        const char *mode) {\n  struct SParser p;\n  int status;\n  L->nny++;  /* cannot yield during parsing */\n  p.z = z; p.name = name; p.mode = mode;\n  p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;\n  p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;\n  p.dyd.label.arr = NULL; p.dyd.label.size = 0;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);\n  luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);\n  luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);\n  L->nny--;\n  return status;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n/*\n** Macro to check stack size and grow stack if needed.  Parameters\n** 'pre'/'pos' allow the macro to preserve a pointer into the\n** stack across reallocations, doing the work only when needed.\n** 'condmovestack' is used in heavy tests to force a stack reallocation\n** at every check.\n*/\n#define luaD_checkstackaux(L,n,pre,pos)  \\\n\tif (L->stack_last - L->top <= (n)) \\\n\t  { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }\n\n/* In general, 'pre'/'pos' are empty (nothing to save) */\n#define luaD_checkstack(L,n)\tluaD_checkstackaux(L,n,(void)0,(void)0)\n\n\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n\n/* type of protected functions, to be ran by 'runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                                  const char *mode);\nLUAI_FUNC void luaD_hook (lua_State *L, int event, int line);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,\n                                          int nres);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\nLUAI_FUNC void luaD_shrinkstack (lua_State *L);\nLUAI_FUNC void luaD_inctop (lua_State *L);\n\nLUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.37.1.1 2017/04/19 17:20:42 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\n#if LUAC_COMPATIBLE_FORMAT\n#include <stdint.h>\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  lua_Writer writer;\n  void *data;\n  int strip;\n  int status;\n} DumpState;\n\n\n/*\n** All high-level dumps go through DumpVector; you can change it to\n** change the endianness of the result\n*/\n#define DumpVector(v,n,D)\tDumpBlock(v,(n)*sizeof((v)[0]),D)\n\n#define DumpLiteral(s,D)\tDumpBlock(s, sizeof(s) - sizeof(char), D)\n\n\nstatic void DumpBlock (const void *b, size_t size, DumpState *D) {\n  if (D->status == 0 && size > 0) {\n    lua_unlock(D->L);\n    D->status = (*D->writer)(D->L, b, size, D->data);\n    lua_lock(D->L);\n  }\n}\n\n\n#define DumpVar(x,D)\t\tDumpVector(&x,1,D)\n\n\nstatic void DumpByte (int y, DumpState *D) {\n  lu_byte x = (lu_byte)y;\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInt (int x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpNumber (lua_Number x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpInteger (lua_Integer x, DumpState *D) {\n  DumpVar(x, D);\n}\n\n\nstatic void DumpString (const TString *s, DumpState *D) {\n  if (s == NULL)\n    DumpByte(0, D);\n  else {\n#if LUAC_COMPATIBLE_FORMAT\n    uint32_t size = tsslen(s) + 1;\n#else\n    size_t size = tsslen(s) + 1;  /* include trailing '\\0' */\n#endif\n    const char *str = getstr(s);\n    if (size < 0xFF)\n      DumpByte(cast_int(size), D);\n    else {\n      DumpByte(0xFF, D);\n      DumpVar(size, D);\n    }\n    DumpVector(str, size - 1, D);  /* no need to save '\\0' */\n  }\n}\n\n\nstatic void DumpCode (const Proto *f, DumpState *D) {\n  DumpInt(f->sizecode, D);\n  DumpVector(f->code, f->sizecode, D);\n}\n\n\nstatic void DumpFunction(const Proto *f, TString *psource, DumpState *D);\n\nstatic void DumpConstants (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizek;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    const TValue *o = &f->k[i];\n    DumpByte(ttype(o), D);\n    switch (ttype(o)) {\n    case LUA_TNIL:\n      break;\n    case LUA_TBOOLEAN:\n      DumpByte(bvalue(o), D);\n      break;\n    case LUA_TNUMFLT:\n      DumpNumber(fltvalue(o), D);\n      break;\n    case LUA_TNUMINT:\n      DumpInteger(ivalue(o), D);\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      DumpString(tsvalue(o), D);\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void DumpProtos (const Proto *f, DumpState *D) {\n  int i;\n  int n = f->sizep;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpFunction(f->p[i], f->source, D);\n}\n\n\nstatic void DumpUpvalues (const Proto *f, DumpState *D) {\n  int i, n = f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpByte(f->upvalues[i].instack, D);\n    DumpByte(f->upvalues[i].idx, D);\n  }\n}\n\n\nstatic void DumpDebug (const Proto *f, DumpState *D) {\n  int i, n;\n  n = (D->strip) ? 0 : f->sizelineinfo;\n  DumpInt(n, D);\n  DumpVector(f->lineinfo, n, D);\n  n = (D->strip) ? 0 : f->sizelocvars;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++) {\n    DumpString(f->locvars[i].varname, D);\n    DumpInt(f->locvars[i].startpc, D);\n    DumpInt(f->locvars[i].endpc, D);\n  }\n  n = (D->strip) ? 0 : f->sizeupvalues;\n  DumpInt(n, D);\n  for (i = 0; i < n; i++)\n    DumpString(f->upvalues[i].name, D);\n}\n\n\nstatic void DumpFunction (const Proto *f, TString *psource, DumpState *D) {\n  if (D->strip || f->source == psource)\n    DumpString(NULL, D);  /* no debug info or same source as its parent */\n  else\n    DumpString(f->source, D);\n  DumpInt(f->linedefined, D);\n  DumpInt(f->lastlinedefined, D);\n  DumpByte(f->numparams, D);\n  DumpByte(f->is_vararg, D);\n  DumpByte(f->maxstacksize, D);\n  DumpCode(f, D);\n  DumpConstants(f, D);\n  DumpUpvalues(f, D);\n  DumpProtos(f, D);\n  DumpDebug(f, D);\n}\n\n\nstatic void DumpHeader (DumpState *D) {\n  DumpLiteral(LUA_SIGNATURE, D);\n  DumpByte(LUAC_VERSION, D);\n  DumpByte(LUAC_FORMAT, D);\n  DumpLiteral(LUAC_DATA, D);\n  DumpByte(sizeof(int), D);\n#if !LUAC_COMPATIBLE_FORMAT\n  DumpByte(sizeof(size_t), D);\n#endif\n  DumpByte(sizeof(Instruction), D);\n  DumpByte(sizeof(lua_Integer), D);\n  DumpByte(sizeof(lua_Number), D);\n  DumpInteger(LUAC_INT, D);\n  DumpNumber(LUAC_NUM, D);\n}\n\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,\n              int strip) {\n  DumpState D;\n  D.L = L;\n  D.writer = w;\n  D.data = data;\n  D.strip = strip;\n  D.status = 0;\n  DumpHeader(&D);\n  DumpByte(f->sizeupvalues, &D);\n  DumpFunction(f, NULL, &D);\n  return D.status;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.45.1.1 2017/04/19 17:39:34 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nCClosure *luaF_newCclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));\n  CClosure *c = gco2ccl(o);\n  c->nupvalues = cast_byte(n);\n  return c;\n}\n\n\nLClosure *luaF_newLclosure (lua_State *L, int n) {\n  GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));\n  LClosure *c = gco2lcl(o);\n  c->p = NULL;\n  c->nupvalues = cast_byte(n);\n  while (n--) c->upvals[n] = NULL;\n  return c;\n}\n\n/*\n** fill a closure with new closed upvalues\n*/\nvoid luaF_initupvals (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = luaM_new(L, UpVal);\n    uv->refcount = 1;\n    uv->v = &uv->u.value;  /* make it closed */\n    setnilvalue(uv->v);\n    cl->upvals[i] = uv;\n  }\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  UpVal **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  lua_assert(isintwups(L) || L->openupval == NULL);\n  while (*pp != NULL && (p = *pp)->v >= level) {\n    lua_assert(upisopen(p));\n    if (p->v == level)  /* found a corresponding upvalue? */\n      return p;  /* return it */\n    pp = &p->u.open.next;\n  }\n  /* not found: create a new upvalue */\n  uv = luaM_new(L, UpVal);\n  uv->refcount = 0;\n  uv->u.open.next = *pp;  /* link it to list of open upvalues */\n  uv->u.open.touched = 1;\n  *pp = uv;\n  uv->v = level;  /* current value lives in the stack */\n  if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */\n    L->twups = G(L)->twups;  /* link it to the list */\n    G(L)->twups = L;\n  }\n  return uv;\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  while (L->openupval != NULL && (uv = L->openupval)->v >= level) {\n    lua_assert(upisopen(uv));\n    L->openupval = uv->u.open.next;  /* remove from 'open' list */\n    if (uv->refcount == 0)  /* no references? */\n      luaM_free(L, uv);  /* free upvalue */\n    else {\n      setobj(L, &uv->u.value, uv->v);  /* move value to upvalue slot */\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_upvalbarrier(L, uv);\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));\n  Proto *f = gco2p(o);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->cache = NULL;\n  f->sizecode = 0;\n  f->lineinfo = NULL;\n  f->sizelineinfo = 0;\n  f->upvalues = NULL;\n  f->sizeupvalues = 0;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->locvars = NULL;\n  f->sizelocvars = 0;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode);\n  luaM_freearray(L, f->p, f->sizep);\n  luaM_freearray(L, f->k, f->sizek);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo);\n  luaM_freearray(L, f->locvars, f->sizelocvars);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues);\n  luaM_free(L, f);\n}\n\n\n/*\n** Look for n-th local variable at line 'line' in function 'func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\n/* test whether thread is in 'twups' list */\n#define isintwups(L)\t(L->twups != L)\n\n\n/*\n** maximum number of upvalues in a closure (both C and Lua). (Value\n** must fit in a VM register.)\n*/\n#define MAXUPVAL\t255\n\n\n/*\n** Upvalues for Lua closures\n*/\nstruct UpVal {\n  TValue *v;  /* points to stack or to its own value */\n  lu_mem refcount;  /* reference counter */\n  union {\n    struct {  /* (when open) */\n      UpVal *next;  /* linked list */\n      int touched;  /* mark to avoid cycles with dead threads */\n    } open;\n    TValue value;  /* the value (when closed) */\n  } u;\n};\n\n#define upisopen(up)\t((up)->v != &(up)->u.value)\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);\nLUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);\nLUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.215.1.2 2017/08/31 16:15:27 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n/*\n** internal state for collector while inside the atomic phase. The\n** collector should never be in this state while running regular code.\n*/\n#define GCSinsideatomic\t\t(GCSpause + 1)\n\n/*\n** cost of sweeping one element (the size of a small object divided\n** by some adjust for the sweep speed)\n*/\n#define GCSWEEPCOST\t((sizeof(TString) + 4) / 4)\n\n/* maximum number of elements to sweep in each single step */\n#define GCSWEEPMAX\t(cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))\n\n/* cost of calling one finalizer */\n#define GCFINALIZECOST\tGCSWEEPCOST\n\n\n/*\n** macro to adjust 'stepmul': 'stepmul' is actually used like\n** 'stepmul / STEPMULADJ' (value chosen by tests)\n*/\n#define STEPMULADJ\t\t200\n\n\n/*\n** macro to adjust 'pause': 'pause' is actually used like\n** 'pause / PAUSEADJ' (value chosen by tests)\n*/\n#define PAUSEADJ\t\t100\n\n\n/*\n** 'makewhite' erases all color bits then sets only the current white\n** bit\n*/\n#define maskcolors\t(~(bitmask(BLACKBIT) | WHITEBITS))\n#define makewhite(g,x)\t\\\n (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))\n\n#define white2gray(x)\tresetbits(x->marked, WHITEBITS)\n#define black2gray(x)\tresetbit(x->marked, BLACKBIT)\n\n\n#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))\n\n#define checkdeadkey(n)\tlua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n)))\n\n\n#define checkconsistency(obj)  \\\n  lua_longassert(!iscollectable(obj) || righttt(obj))\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t)\t{ if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }\n\n/*\n** mark an object that can be NULL (either because it is really optional,\n** or it was stripped as debug info, or inside an uncompleted structure)\n*/\n#define markobjectN(g,t)\t{ if (t) markobject(g,t); }\n\nstatic void reallymarkobject (global_State *g, GCObject *o);\n\n\n/*\n** {======================================================\n** Generic functions\n** =======================================================\n*/\n\n\n/*\n** one after last element in a hash array\n*/\n#define gnodelast(h)\tgnode(h, cast(size_t, sizenode(h)))\n\n\n/*\n** link collectable object 'o' into list pointed by 'p'\n*/\n#define linkgclist(o,p)\t((o)->gclist = (p), (p) = obj2gco(o))\n\n\n/*\n** If key is not marked, mark its entry as dead. This allows key to be\n** collected, but keeps its entry in the table.  A dead node is needed\n** when Lua looks up for a key (it may be part of a chain) and when\n** traversing a weak table (key might be removed from the table during\n** traversal). Other places never manipulate dead keys, because its\n** associated nil value is enough to signal that the entry is logically\n** empty.\n*/\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (valiswhite(gkey(n)))\n    setdeadvalue(wgkey(n));  /* unused and unmarked key; remove it */\n}\n\n\n/*\n** tells whether a key or value can be cleared from a weak\n** table. Non-collectable objects are never removed from weak\n** tables. Strings behave as 'values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for objects\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (global_State *g, const TValue *o) {\n  if (!iscollectable(o)) return 0;\n  else if (ttisstring(o)) {\n    markobject(g, tsvalue(o));  /* strings are 'values', so are never weak */\n    return 0;\n  }\n  else return iswhite(gcvalue(o));\n}\n\n\n/*\n** barrier that moves collector forward, that is, mark the white object\n** being pointed by a black object. (If in sweep phase, clear the black\n** object to white [sweep it] to avoid other barrier calls for this\n** same object.)\n*/\nvoid luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  if (keepinvariant(g))  /* must keep invariant? */\n    reallymarkobject(g, v);  /* restore invariant */\n  else {  /* sweep phase */\n    lua_assert(issweepphase(g));\n    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */\n  }\n}\n\n\n/*\n** barrier that moves collector backward, that is, mark the black object\n** pointing to a white object as gray again.\n*/\nvoid luaC_barrierback_ (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  lua_assert(isblack(t) && !isdead(g, t));\n  black2gray(t);  /* make table gray (again) */\n  linkgclist(t, g->grayagain);\n}\n\n\n/*\n** barrier for assignments to closed upvalues. Because upvalues are\n** shared among closures, it is impossible to know the color of all\n** closures pointing to it. So, we assume that the object being assigned\n** must be marked.\n*/\nvoid luaC_upvalbarrier_ (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = gcvalue(uv->v);\n  lua_assert(!upisopen(uv));  /* ensured by macro luaC_upvalbarrier */\n  if (keepinvariant(g))\n    markobject(g, o);\n}\n\n\nvoid luaC_fix (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(g->allgc == o);  /* object must be 1st in 'allgc' list! */\n  white2gray(o);  /* they will be gray forever */\n  g->allgc = o->next;  /* remove object from 'allgc' list */\n  o->next = g->fixedgc;  /* link it to 'fixedgc' list */\n  g->fixedgc = o;\n}\n\n\n/*\n** create a new collectable object (with given type and size) and link\n** it to 'allgc' list.\n*/\nGCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {\n  global_State *g = G(L);\n  GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));\n  o->marked = luaC_white(g);\n  o->tt = tt;\n  o->next = g->allgc;\n  g->allgc = o;\n  return o;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Mark functions\n** =======================================================\n*/\n\n\n/*\n** mark an object. Userdata, strings, and closed upvalues are visited\n** and turned black here. Other objects are marked gray and added\n** to appropriate list to be visited (and turned black) later. (Open\n** upvalues are already linked in 'headuv' list.)\n*/\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n reentry:\n  white2gray(o);\n  switch (o->tt) {\n    case LUA_TSHRSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->shrlen);\n      break;\n    }\n    case LUA_TLNGSTR: {\n      gray2black(o);\n      g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      TValue uvalue;\n      markobjectN(g, gco2u(o)->metatable);  /* mark its metatable */\n      gray2black(o);\n      g->GCmemtrav += sizeudata(gco2u(o));\n      getuservalue(g->mainthread, gco2u(o), &uvalue);\n      if (valiswhite(&uvalue)) {  /* markvalue(g, &uvalue); */\n        o = gcvalue(&uvalue);\n        goto reentry;\n      }\n      break;\n    }\n    case LUA_TLCL: {\n      linkgclist(gco2lcl(o), g->gray);\n      break;\n    }\n    case LUA_TCCL: {\n      linkgclist(gco2ccl(o), g->gray);\n      break;\n    }\n    case LUA_TTABLE: {\n      linkgclist(gco2t(o), g->gray);\n      break;\n    }\n    case LUA_TTHREAD: {\n      linkgclist(gco2th(o), g->gray);\n      break;\n    }\n    case LUA_TPROTO: {\n      linkgclist(gco2p(o), g->gray);\n      break;\n    }\n    default: lua_assert(0); break;\n  }\n}\n\n\n/*\n** mark metamethods for basic types\n*/\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i < LUA_NUMTAGS; i++)\n    markobjectN(g, g->mt[i]);\n}\n\n\n/*\n** mark all objects in list of being-finalized\n*/\nstatic void markbeingfnz (global_State *g) {\n  GCObject *o;\n  for (o = g->tobefnz; o != NULL; o = o->next)\n    markobject(g, o);\n}\n\n\n/*\n** Mark all values stored in marked open upvalues from non-marked threads.\n** (Values from marked threads were already marked when traversing the\n** thread.) Remove from the list threads that no longer have upvalues and\n** not-marked threads.\n*/\nstatic void remarkupvals (global_State *g) {\n  lua_State *thread;\n  lua_State **p = &g->twups;\n  while ((thread = *p) != NULL) {\n    lua_assert(!isblack(thread));  /* threads are never black */\n    if (isgray(thread) && thread->openupval != NULL)\n      p = &thread->twups;  /* keep marked thread with upvalues in the list */\n    else {  /* thread is not marked or without upvalues */\n      UpVal *uv;\n      *p = thread->twups;  /* remove thread from the list */\n      thread->twups = thread;  /* mark that it is out of list */\n      for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) {\n        if (uv->u.open.touched) {\n          markvalue(g, uv->v);  /* remark upvalue's value */\n          uv->u.open.touched = 0;\n        }\n      }\n    }\n  }\n}\n\n\n/*\n** mark root set and reset all gray lists, to start a new collection\n*/\nstatic void restartcollection (global_State *g) {\n  g->gray = g->grayagain = NULL;\n  g->weak = g->allweak = g->ephemeron = NULL;\n  markobject(g, g->mainthread);\n  markvalue(g, &g->l_registry);\n  markmt(g);\n  markbeingfnz(g);  /* mark any finalizing object left from previous cycle */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Traverse functions\n** =======================================================\n*/\n\n/*\n** Traverse a table with weak values and link it to proper list. During\n** propagate phase, keep it in 'grayagain' list, to be revisited in the\n** atomic phase. In the atomic phase, if table has any white value,\n** put it in 'weak' list, to be cleared.\n*/\nstatic void traverseweakvalue (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  /* if there is array part, assume it may have white values (it is not\n     worth traversing it now just to check) */\n  int hasclears = (h->sizearray > 0);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      if (!hasclears && iscleared(g, gval(n)))  /* is there a white value? */\n        hasclears = 1;  /* table will have to be cleared */\n    }\n  }\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasclears)\n    linkgclist(h, g->weak);  /* has to be cleared later */\n}\n\n\n/*\n** Traverse an ephemeron table and link it to proper list. Returns true\n** iff any object was marked during this traversal (which implies that\n** convergence has to continue). During propagation phase, keep table\n** in 'grayagain' list, to be visited again in the atomic phase. In\n** the atomic phase, if table has any white->white entry, it has to\n** be revisited during ephemeron convergence (as that key may turn\n** black). Otherwise, if it has any white key, table has to be cleared\n** (in the atomic phase).\n*/\nstatic int traverseephemeron (global_State *g, Table *h) {\n  int marked = 0;  /* true if an object is marked in this traversal */\n  int hasclears = 0;  /* true if table has white keys */\n  int hasww = 0;  /* true if table has entry \"white-key -> white-value\" */\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  /* traverse array part */\n  for (i = 0; i < h->sizearray; i++) {\n    if (valiswhite(&h->array[i])) {\n      marked = 1;\n      reallymarkobject(g, gcvalue(&h->array[i]));\n    }\n  }\n  /* traverse hash part */\n  for (n = gnode(h, 0); n < limit; n++) {\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else if (iscleared(g, gkey(n))) {  /* key is not marked (yet)? */\n      hasclears = 1;  /* table must be cleared */\n      if (valiswhite(gval(n)))  /* value not marked yet? */\n        hasww = 1;  /* white-white entry */\n    }\n    else if (valiswhite(gval(n))) {  /* value not marked yet? */\n      marked = 1;\n      reallymarkobject(g, gcvalue(gval(n)));  /* mark it now */\n    }\n  }\n  /* link table into proper list */\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasww)  /* table has white->white entries? */\n    linkgclist(h, g->ephemeron);  /* have to propagate again */\n  else if (hasclears)  /* table has white keys? */\n    linkgclist(h, g->allweak);  /* may have to clean white keys */\n  return marked;\n}\n\n\nstatic void traversestrongtable (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  for (i = 0; i < h->sizearray; i++)  /* traverse array part */\n    markvalue(g, &h->array[i]);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    checkdeadkey(n);\n    if (ttisnil(gval(n)))  /* entry is empty? */\n      removeentry(n);  /* remove it */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      markvalue(g, gkey(n));  /* mark key */\n      markvalue(g, gval(n));  /* mark value */\n    }\n  }\n}\n\n\nstatic lu_mem traversetable (global_State *g, Table *h) {\n  const char *weakkey, *weakvalue;\n  const TValue *mode = gfasttm(g, h->metatable, TM_MODE);\n  markobjectN(g, h->metatable);\n  if (mode && ttisstring(mode) &&  /* is there a weak mode? */\n      ((weakkey = strchr(svalue(mode), 'k')),\n       (weakvalue = strchr(svalue(mode), 'v')),\n       (weakkey || weakvalue))) {  /* is really weak? */\n    black2gray(h);  /* keep table gray */\n    if (!weakkey)  /* strong keys? */\n      traverseweakvalue(g, h);\n    else if (!weakvalue)  /* strong values? */\n      traverseephemeron(g, h);\n    else  /* all weak */\n      linkgclist(h, g->allweak);  /* nothing to traverse now */\n  }\n  else  /* not weak */\n    traversestrongtable(g, h);\n  return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                         sizeof(Node) * cast(size_t, allocsizenode(h));\n}\n\n\n/*\n** Traverse a prototype. (While a prototype is being build, its\n** arrays can be larger than needed; the extra slots are filled with\n** NULL, so the use of 'markobjectN')\n*/\nstatic int traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->cache && iswhite(f->cache))\n    f->cache = NULL;  /* allow cache to be collected */\n  markobjectN(g, f->source);\n  for (i = 0; i < f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */\n    markobjectN(g, f->upvalues[i].name);\n  for (i = 0; i < f->sizep; i++)  /* mark nested protos */\n    markobjectN(g, f->p[i]);\n  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */\n    markobjectN(g, f->locvars[i].varname);\n  return sizeof(Proto) + sizeof(Instruction) * f->sizecode +\n                         sizeof(Proto *) * f->sizep +\n                         sizeof(TValue) * f->sizek +\n                         sizeof(int) * f->sizelineinfo +\n                         sizeof(LocVar) * f->sizelocvars +\n                         sizeof(Upvaldesc) * f->sizeupvalues;\n}\n\n\nstatic lu_mem traverseCclosure (global_State *g, CClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++)  /* mark its upvalues */\n    markvalue(g, &cl->upvalue[i]);\n  return sizeCclosure(cl->nupvalues);\n}\n\n/*\n** open upvalues point to values in a thread, so those values should\n** be marked when the thread is traversed except in the atomic phase\n** (because then the value cannot be changed by the thread and the\n** thread may not be traversed again)\n*/\nstatic lu_mem traverseLclosure (global_State *g, LClosure *cl) {\n  int i;\n  markobjectN(g, cl->p);  /* mark its prototype */\n  for (i = 0; i < cl->nupvalues; i++) {  /* mark its upvalues */\n    UpVal *uv = cl->upvals[i];\n    if (uv != NULL) {\n      if (upisopen(uv) && g->gcstate != GCSinsideatomic)\n        uv->u.open.touched = 1;  /* can be marked in 'remarkupvals' */\n      else\n        markvalue(g, uv->v);\n    }\n  }\n  return sizeLclosure(cl->nupvalues);\n}\n\n\nstatic lu_mem traversethread (global_State *g, lua_State *th) {\n  StkId o = th->stack;\n  if (o == NULL)\n    return 1;  /* stack not completely built yet */\n  lua_assert(g->gcstate == GCSinsideatomic ||\n             th->openupval == NULL || isintwups(th));\n  for (; o < th->top; o++)  /* mark live elements in the stack */\n    markvalue(g, o);\n  if (g->gcstate == GCSinsideatomic) {  /* final traversal? */\n    StkId lim = th->stack + th->stacksize;  /* real end of stack */\n    for (; o < lim; o++)  /* clear not-marked stack slice */\n      setnilvalue(o);\n    /* 'remarkupvals' may have removed thread from 'twups' list */\n    if (!isintwups(th) && th->openupval != NULL) {\n      th->twups = g->twups;  /* link it back to the list */\n      g->twups = th;\n    }\n  }\n  else if (g->gckind != KGC_EMERGENCY)\n    luaD_shrinkstack(th); /* do not change stack in emergency cycle */\n  return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n          sizeof(CallInfo) * th->nci);\n}\n\n\n/*\n** traverse one gray object, turning it to black (except for threads,\n** which are always gray).\n*/\nstatic void propagatemark (global_State *g) {\n  lu_mem size;\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2t(o);\n      g->gray = h->gclist;  /* remove from 'gray' list */\n      size = traversetable(g, h);\n      break;\n    }\n    case LUA_TLCL: {\n      LClosure *cl = gco2lcl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseLclosure(g, cl);\n      break;\n    }\n    case LUA_TCCL: {\n      CClosure *cl = gco2ccl(o);\n      g->gray = cl->gclist;  /* remove from 'gray' list */\n      size = traverseCclosure(g, cl);\n      break;\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;  /* remove from 'gray' list */\n      linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n      black2gray(o);\n      size = traversethread(g, th);\n      break;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;  /* remove from 'gray' list */\n      size = traverseproto(g, p);\n      break;\n    }\n    default: lua_assert(0); return;\n  }\n  g->GCmemtrav += size;\n}\n\n\nstatic void propagateall (global_State *g) {\n  while (g->gray) propagatemark(g);\n}\n\n\nstatic void convergeephemerons (global_State *g) {\n  int changed;\n  do {\n    GCObject *w;\n    GCObject *next = g->ephemeron;  /* get ephemeron list */\n    g->ephemeron = NULL;  /* tables may return to this list when traversed */\n    changed = 0;\n    while ((w = next) != NULL) {\n      next = gco2t(w)->gclist;\n      if (traverseephemeron(g, gco2t(w))) {  /* traverse marked some value? */\n        propagateall(g);  /* propagate changes */\n        changed = 1;  /* will have to revisit all ephemeron tables */\n      }\n    }\n  } while (changed);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Sweep Functions\n** =======================================================\n*/\n\n\n/*\n** clear entries with unmarked keys from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearkeys (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {\n        setnilvalue(gval(n));  /* remove value ... */\n      }\n      if (ttisnil(gval(n)))  /* is entry empty? */\n        removeentry(n);  /* remove entry from table */\n    }\n  }\n}\n\n\n/*\n** clear entries with unmarked values from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearvalues (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    unsigned int i;\n    for (i = 0; i < h->sizearray; i++) {\n      TValue *o = &h->array[i];\n      if (iscleared(g, o))  /* value was collected? */\n        setnilvalue(o);  /* remove value */\n    }\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* and remove entry from table */\n      }\n    }\n  }\n}\n\n\nvoid luaC_upvdeccount (lua_State *L, UpVal *uv) {\n  lua_assert(uv->refcount > 0);\n  uv->refcount--;\n  if (uv->refcount == 0 && !upisopen(uv))\n    luaM_free(L, uv);\n}\n\n\nstatic void freeLclosure (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    UpVal *uv = cl->upvals[i];\n    if (uv)\n      luaC_upvdeccount(L, uv);\n  }\n  luaM_freemem(L, cl, sizeLclosure(cl->nupvalues));\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TLCL: {\n      freeLclosure(L, gco2lcl(o));\n      break;\n    }\n    case LUA_TCCL: {\n      luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));\n      break;\n    }\n    case LUA_TTABLE: luaH_free(L, gco2t(o)); break;\n    case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;\n    case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;\n    case LUA_TSHRSTR:\n      luaS_remove(L, gco2ts(o));  /* remove it from hash table */\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));\n      break;\n    case LUA_TLNGSTR: {\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count);\n\n\n/*\n** sweep at most 'count' elements from a list of GCObjects erasing dead\n** objects, where a dead object is one marked with the old (non current)\n** white; change all non-dead objects back to white, preparing for next\n** collection cycle. Return where to continue the traversal or NULL if\n** list is finished.\n*/\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  global_State *g = G(L);\n  int ow = otherwhite(g);\n  int white = luaC_white(g);  /* current white */\n  while (*p != NULL && count-- > 0) {\n    GCObject *curr = *p;\n    int marked = curr->marked;\n    if (isdeadm(ow, marked)) {  /* is 'curr' dead? */\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* change mark to 'white' */\n      curr->marked = cast_byte((marked & maskcolors) | white);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  return (*p == NULL) ? NULL : p;\n}\n\n\n/*\n** sweep a list until a live object (or end of list)\n*/\nstatic GCObject **sweeptolive (lua_State *L, GCObject **p) {\n  GCObject **old = p;\n  do {\n    p = sweeplist(L, p, 1);\n  } while (p == old);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Finalization\n** =======================================================\n*/\n\n/*\n** If possible, shrink string table\n*/\nstatic void checkSizes (lua_State *L, global_State *g) {\n  if (g->gckind != KGC_EMERGENCY) {\n    l_mem olddebt = g->GCdebt;\n    if (g->strt.nuse < g->strt.size / 4)  /* string table too big? */\n      luaS_resize(L, g->strt.size / 2);  /* shrink it a little */\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n  }\n}\n\n\nstatic GCObject *udata2finalize (global_State *g) {\n  GCObject *o = g->tobefnz;  /* get first element */\n  lua_assert(tofinalize(o));\n  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */\n  o->next = g->allgc;  /* return it to 'allgc' list */\n  g->allgc = o;\n  resetbit(o->marked, FINALIZEDBIT);  /* object is \"normal\" again */\n  if (issweepphase(g))\n    makewhite(g, o);  /* \"sweep\" object */\n  return o;\n}\n\n\nstatic void dothecall (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 2, 0);\n}\n\n\nstatic void GCTM (lua_State *L, int propagateerrors) {\n  global_State *g = G(L);\n  const TValue *tm;\n  TValue v;\n  setgcovalue(L, &v, udata2finalize(g));\n  tm = luaT_gettmbyobj(L, &v, TM_GC);\n  if (tm != NULL && ttisfunction(tm)) {  /* is there a finalizer? */\n    int status;\n    lu_byte oldah = L->allowhook;\n    int running  = g->gcrunning;\n    L->allowhook = 0;  /* stop debug hooks during GC metamethod */\n    g->gcrunning = 0;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);  /* push finalizer... */\n    setobj2s(L, L->top + 1, &v);  /* ... and its argument */\n    L->top += 2;  /* and (next line) call the finalizer */\n    L->ci->callstatus |= CIST_FIN;  /* will run a finalizer */\n    status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);\n    L->ci->callstatus &= ~CIST_FIN;  /* not running a finalizer anymore */\n    L->allowhook = oldah;  /* restore hooks */\n    g->gcrunning = running;  /* restore state */\n    if (status != LUA_OK && propagateerrors) {  /* error while running __gc? */\n      if (status == LUA_ERRRUN) {  /* is there an error object? */\n        const char *msg = (ttisstring(L->top - 1))\n                            ? svalue(L->top - 1)\n                            : \"no message\";\n        luaO_pushfstring(L, \"error in __gc metamethod (%s)\", msg);\n        status = LUA_ERRGCMM;  /* error in __gc metamethod */\n      }\n      luaD_throw(L, status);  /* re-throw error */\n    }\n  }\n}\n\n\n/*\n** call a few (up to 'g->gcfinnum') finalizers\n*/\nstatic int runafewfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  unsigned int i;\n  lua_assert(!g->tobefnz || g->gcfinnum > 0);\n  for (i = 0; g->tobefnz && i < g->gcfinnum; i++)\n    GCTM(L, 1);  /* call one finalizer */\n  g->gcfinnum = (!g->tobefnz) ? 0  /* nothing more to finalize? */\n                    : g->gcfinnum * 2;  /* else call a few more next time */\n  return i;\n}\n\n\n/*\n** call all pending finalizers\n*/\nstatic void callallpendingfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  while (g->tobefnz)\n    GCTM(L, 0);\n}\n\n\n/*\n** find last 'next' field in list 'p' list (to add elements in its end)\n*/\nstatic GCObject **findlast (GCObject **p) {\n  while (*p != NULL)\n    p = &(*p)->next;\n  return p;\n}\n\n\n/*\n** move all unreachable objects (or 'all' objects) that need\n** finalization from list 'finobj' to list 'tobefnz' (to be finalized)\n*/\nstatic void separatetobefnz (global_State *g, int all) {\n  GCObject *curr;\n  GCObject **p = &g->finobj;\n  GCObject **lastnext = findlast(&g->tobefnz);\n  while ((curr = *p) != NULL) {  /* traverse all finalizable objects */\n    lua_assert(tofinalize(curr));\n    if (!(iswhite(curr) || all))  /* not being collected? */\n      p = &curr->next;  /* don't bother with it */\n    else {\n      *p = curr->next;  /* remove 'curr' from 'finobj' list */\n      curr->next = *lastnext;  /* link at the end of 'tobefnz' list */\n      *lastnext = curr;\n      lastnext = &curr->next;\n    }\n  }\n}\n\n\n/*\n** if object 'o' has a finalizer, remove it from 'allgc' list (must\n** search the list to find it) and link it in 'finobj' list.\n*/\nvoid luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {\n  global_State *g = G(L);\n  if (tofinalize(o) ||                 /* obj. is already marked... */\n      gfasttm(g, mt, TM_GC) == NULL)   /* or has no finalizer? */\n    return;  /* nothing to be done */\n  else {  /* move 'o' to 'finobj' list */\n    GCObject **p;\n    if (issweepphase(g)) {\n      makewhite(g, o);  /* \"sweep\" object 'o' */\n      if (g->sweepgc == &o->next)  /* should not remove 'sweepgc' object */\n        g->sweepgc = sweeptolive(L, g->sweepgc);  /* change 'sweepgc' */\n    }\n    /* search for pointer pointing to 'o' */\n    for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }\n    *p = o->next;  /* remove 'o' from 'allgc' list */\n    o->next = g->finobj;  /* link it in 'finobj' list */\n    g->finobj = o;\n    l_setbit(o->marked, FINALIZEDBIT);  /* mark it as such */\n  }\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** GC control\n** =======================================================\n*/\n\n\n/*\n** Set a reasonable \"time\" to wait before starting a new GC cycle; cycle\n** will start when memory use hits threshold. (Division by 'estimate'\n** should be OK: it cannot be zero (because Lua cannot even start with\n** less than PAUSEADJ bytes).\n*/\nstatic void setpause (global_State *g) {\n  l_mem threshold, debt;\n  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */\n  lua_assert(estimate > 0);\n  threshold = (g->gcpause < MAX_LMEM / estimate)  /* overflow? */\n            ? estimate * g->gcpause  /* no overflow */\n            : MAX_LMEM;  /* overflow; truncate to maximum */\n  debt = gettotalbytes(g) - threshold;\n  luaE_setdebt(g, debt);\n}\n\n\n/*\n** Enter first sweep phase.\n** The call to 'sweeplist' tries to make pointer point to an object\n** inside the list (instead of to the header), so that the real sweep do\n** not need to skip objects created between \"now\" and the start of the\n** real sweep.\n*/\nstatic void entersweep (lua_State *L) {\n  global_State *g = G(L);\n  g->gcstate = GCSswpallgc;\n  lua_assert(g->sweepgc == NULL);\n  g->sweepgc = sweeplist(L, &g->allgc, 1);\n}\n\n\nvoid luaC_freeallobjects (lua_State *L) {\n  global_State *g = G(L);\n  separatetobefnz(g, 1);  /* separate all objects with finalizers */\n  lua_assert(g->finobj == NULL);\n  callallpendingfinalizers(L);\n  lua_assert(g->tobefnz == NULL);\n  g->currentwhite = WHITEBITS; /* this \"white\" makes all objects look dead */\n  g->gckind = KGC_NORMAL;\n  sweepwholelist(L, &g->finobj);\n  sweepwholelist(L, &g->allgc);\n  sweepwholelist(L, &g->fixedgc);  /* collect fixed objects */\n  lua_assert(g->strt.nuse == 0);\n}\n\n\nstatic l_mem atomic (lua_State *L) {\n  global_State *g = G(L);\n  l_mem work;\n  GCObject *origweak, *origall;\n  GCObject *grayagain = g->grayagain;  /* save original list */\n  lua_assert(g->ephemeron == NULL && g->weak == NULL);\n  lua_assert(!iswhite(g->mainthread));\n  g->gcstate = GCSinsideatomic;\n  g->GCmemtrav = 0;  /* start counting work */\n  markobject(g, L);  /* mark running thread */\n  /* registry and global metatables may be changed by API */\n  markvalue(g, &g->l_registry);\n  markmt(g);  /* mark global metatables */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  propagateall(g);  /* propagate changes */\n  work = g->GCmemtrav;  /* stop counting (do not recount 'grayagain') */\n  g->gray = grayagain;\n  propagateall(g);  /* traverse 'grayagain' list */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all strongly accessible objects are marked. */\n  /* Clear values from weak tables, before checking finalizers */\n  clearvalues(g, g->weak, NULL);\n  clearvalues(g, g->allweak, NULL);\n  origweak = g->weak; origall = g->allweak;\n  work += g->GCmemtrav;  /* stop counting (objects being finalized) */\n  separatetobefnz(g, 0);  /* separate objects to be finalized */\n  g->gcfinnum = 1;  /* there may be objects to be finalized */\n  markbeingfnz(g);  /* mark objects that will be finalized */\n  propagateall(g);  /* remark, to propagate 'resurrection' */\n  g->GCmemtrav = 0;  /* restart counting */\n  convergeephemerons(g);\n  /* at this point, all resurrected objects are marked. */\n  /* remove dead objects from weak tables */\n  clearkeys(g, g->ephemeron, NULL);  /* clear keys from all ephemeron tables */\n  clearkeys(g, g->allweak, NULL);  /* clear keys from all 'allweak' tables */\n  /* clear values from resurrected weak tables */\n  clearvalues(g, g->weak, origweak);\n  clearvalues(g, g->allweak, origall);\n  luaS_clearcache(g);\n  g->currentwhite = cast_byte(otherwhite(g));  /* flip current white */\n  work += g->GCmemtrav;  /* complete counting */\n  return work;  /* estimate of memory marked by 'atomic' */\n}\n\n\nstatic lu_mem sweepstep (lua_State *L, global_State *g,\n                         int nextstate, GCObject **nextlist) {\n  if (g->sweepgc) {\n    l_mem olddebt = g->GCdebt;\n    g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n    if (g->sweepgc)  /* is there still something to sweep? */\n      return (GCSWEEPMAX * GCSWEEPCOST);\n  }\n  /* else enter next state */\n  g->gcstate = nextstate;\n  g->sweepgc = nextlist;\n  return 0;\n}\n\n\nstatic lu_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  switch (g->gcstate) {\n    case GCSpause: {\n      g->GCmemtrav = g->strt.size * sizeof(GCObject*);\n      restartcollection(g);\n      g->gcstate = GCSpropagate;\n      return g->GCmemtrav;\n    }\n    case GCSpropagate: {\n      g->GCmemtrav = 0;\n      lua_assert(g->gray);\n      propagatemark(g);\n       if (g->gray == NULL)  /* no more gray objects? */\n        g->gcstate = GCSatomic;  /* finish propagate phase */\n      return g->GCmemtrav;  /* memory traversed in this step */\n    }\n    case GCSatomic: {\n      lu_mem work;\n      propagateall(g);  /* make sure gray list is empty */\n      work = atomic(L);  /* work is what was traversed by 'atomic' */\n      entersweep(L);\n      g->GCestimate = gettotalbytes(g);  /* first estimate */;\n      return work;\n    }\n    case GCSswpallgc: {  /* sweep \"regular\" objects */\n      return sweepstep(L, g, GCSswpfinobj, &g->finobj);\n    }\n    case GCSswpfinobj: {  /* sweep objects with finalizers */\n      return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);\n    }\n    case GCSswptobefnz: {  /* sweep objects to be finalized */\n      return sweepstep(L, g, GCSswpend, NULL);\n    }\n    case GCSswpend: {  /* finish sweeps */\n      makewhite(g, g->mainthread);  /* sweep main thread */\n      checkSizes(L, g);\n      g->gcstate = GCScallfin;\n      return 0;\n    }\n    case GCScallfin: {  /* call remaining finalizers */\n      if (g->tobefnz && g->gckind != KGC_EMERGENCY) {\n        int n = runafewfinalizers(L);\n        return (n * GCFINALIZECOST);\n      }\n      else {  /* emergency mode or no more finalizers */\n        g->gcstate = GCSpause;  /* finish collection */\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** advances the garbage collector until it reaches a state allowed\n** by 'statemask'\n*/\nvoid luaC_runtilstate (lua_State *L, int statesmask) {\n  global_State *g = G(L);\n  while (!testbit(statesmask, g->gcstate))\n    singlestep(L);\n}\n\n\n/*\n** get GC debt and convert it from Kb to 'work units' (avoid zero debt\n** and overflows)\n*/\nstatic l_mem getdebt (global_State *g) {\n  l_mem debt = g->GCdebt;\n  int stepmul = g->gcstepmul;\n  if (debt <= 0) return 0;  /* minimal debt */\n  else {\n    debt = (debt / STEPMULADJ) + 1;\n    debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;\n    return debt;\n  }\n}\n\n/*\n** performs a basic GC step when collector is running\n*/\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  l_mem debt = getdebt(g);  /* GC deficit (be paid now) */\n  if (!g->gcrunning) {  /* not running? */\n    luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */\n    return;\n  }\n  do {  /* repeat until pause or enough \"credit\" (negative debt) */\n    lu_mem work = singlestep(L);  /* perform one single step */\n    debt -= work;\n  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);\n  if (g->gcstate == GCSpause)\n    setpause(g);  /* pause until next cycle */\n  else {\n    debt = (debt / g->gcstepmul) * STEPMULADJ;  /* convert 'work units' to Kb */\n    luaE_setdebt(g, debt);\n    runafewfinalizers(L);\n  }\n}\n\n\n/*\n** Performs a full GC cycle; if 'isemergency', set a flag to avoid\n** some operations which could change the interpreter state in some\n** unexpected ways (running finalizers and shrinking some structures).\n** Before running the collection, check 'keepinvariant'; if it is true,\n** there may be some objects marked as black, so the collector has\n** to sweep all objects to turn them back to white (as white has not\n** changed, nothing will be collected).\n*/\nvoid luaC_fullgc (lua_State *L, int isemergency) {\n  global_State *g = G(L);\n  lua_assert(g->gckind == KGC_NORMAL);\n  if (isemergency) g->gckind = KGC_EMERGENCY;  /* set flag */\n  if (keepinvariant(g)) {  /* black objects? */\n    entersweep(L); /* sweep everything to turn them back to white */\n  }\n  /* finish any pending sweep phase to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpause));\n  luaC_runtilstate(L, ~bitmask(GCSpause));  /* start new collection */\n  luaC_runtilstate(L, bitmask(GCScallfin));  /* run up to finalizers */\n  /* estimate must be correct after a full GC cycle */\n  lua_assert(g->GCestimate == gettotalbytes(g));\n  luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n  g->gckind = KGC_NORMAL;\n  setpause(g);\n}\n\n/* }====================================================== */\n\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.91.1.1 2017/04/19 17:39:34 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n/*\n** Collectable objects may have one of three colors: white, which\n** means the object is not marked; gray, which means the\n** object is marked, but its references may be not marked; and\n** black, which means that the object and all its references are marked.\n** The main invariant of the garbage collector, while marking objects,\n** is that a black object can never point to a white one. Moreover,\n** any gray object must be in a \"gray list\" (gray, grayagain, weak,\n** allweak, ephemeron) so that it can be visited again before finishing\n** the collection cycle. These lists have no meaning when the invariant\n** is not being enforced (e.g., sweep phase).\n*/\n\n\n\n/* how much to allocate before next GC step */\n#if !defined(GCSTEPSIZE)\n/* ~100 small strings */\n#define GCSTEPSIZE\t(cast_int(100 * sizeof(TString)))\n#endif\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpropagate\t0\n#define GCSatomic\t1\n#define GCSswpallgc\t2\n#define GCSswpfinobj\t3\n#define GCSswptobefnz\t4\n#define GCSswpend\t5\n#define GCScallfin\t6\n#define GCSpause\t7\n\n\n#define issweepphase(g)  \\\n\t(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)\n\n\n/*\n** macro to tell when main invariant (white objects cannot point to black\n** ones) must be kept. During a collection, the sweep\n** phase may break the invariant, as objects turned white may point to\n** still-black objects. The invariant is restored when sweep ends and\n** all objects are white again.\n*/\n\n#define keepinvariant(g)\t((g)->gcstate <= GCSatomic)\n\n\n/*\n** some useful bit tricks\n*/\n#define resetbits(x,m)\t\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t\t((x) |= (m))\n#define testbits(x,m)\t\t((x) & (m))\n#define bitmask(b)\t\t(1<<(b))\n#define bit2mask(b1,b2)\t\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\t\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\t\tresetbits(x, bitmask(b))\n#define testbit(x,b)\t\ttestbits(x, bitmask(b))\n\n\n/* Layout for bit use in 'marked' field: */\n#define WHITE0BIT\t0  /* object is white (type 0) */\n#define WHITE1BIT\t1  /* object is white (type 1) */\n#define BLACKBIT\t2  /* object is black */\n#define FINALIZEDBIT\t3  /* object has been marked for finalization */\n/* bit 7 is currently used by tests (luaL_checkmemory) */\n\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      testbits((x)->marked, WHITEBITS)\n#define isblack(x)      testbit((x)->marked, BLACKBIT)\n#define isgray(x)  /* neither white nor black */  \\\n\t(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))\n\n#define tofinalize(x)\ttestbit((x)->marked, FINALIZEDBIT)\n\n#define otherwhite(g)\t((g)->currentwhite ^ WHITEBITS)\n#define isdeadm(ow,m)\t(!(((m) ^ WHITEBITS) & (ow)))\n#define isdead(g,v)\tisdeadm(otherwhite(g), (v)->marked)\n\n#define changewhite(x)\t((x)->marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->marked, BLACKBIT)\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n\n/*\n** Does one step of collection when debt becomes positive. 'pre'/'pos'\n** allows some adjustments to be done only when needed. macro\n** 'condchangemem' is used only for heavy tests (forcing a full\n** GC cycle on every opportunity)\n*/\n#define luaC_condGC(L,pre,pos) \\\n\t{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \\\n\t  condchangemem(L,pre,pos); }\n\n/* more often than not, 'pre'/'pos' are empty */\n#define luaC_checkGC(L)\t\tluaC_condGC(L,(void)0,(void)0)\n\n\n#define luaC_barrier(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \\\n\tluaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))\n\n#define luaC_barrierback(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \\\n\tluaC_barrierback_(L,p) : cast_void(0))\n\n#define luaC_objbarrier(L,p,o) (  \\\n\t(isblack(p) && iswhite(o)) ? \\\n\tluaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))\n\n#define luaC_upvalbarrier(L,uv) ( \\\n\t(iscollectable((uv)->v) && !upisopen(uv)) ? \\\n         luaC_upvalbarrier_(L,uv) : cast_void(0))\n\nLUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_freeallobjects (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);\nLUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);\nLUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);\nLUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o);\nLUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);\nLUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $\n** Initialization of libraries for lua.c and other clients\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n/*\n** If you embed Lua in your program and need to open the standard\n** libraries, call luaL_openlibs in your program. If you need a\n** different set of libraries, copy this file to your project and edit\n** it to suit your needs.\n**\n** You can also *preload* libraries, so that a later 'require' can\n** open the library, which is already linked to the application.\n** For that, do the following code:\n**\n**  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n**  lua_pushcfunction(L, luaopen_modname);\n**  lua_setfield(L, -2, modname);\n**  lua_pop(L, 1);  // remove PRELOAD table\n*/\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\n/*\n** these libs are loaded by lua.c and are readily available to any Lua\n** program\n*/\nstatic const luaL_Reg loadedlibs[] = {\n  {\"_G\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_COLIBNAME, luaopen_coroutine},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_UTF8LIBNAME, luaopen_utf8},\n  {LUA_DBLIBNAME, luaopen_debug},\n#if defined(LUA_COMPAT_BITLIB)\n  {LUA_BITLIBNAME, luaopen_bit32},\n#endif\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib;\n  /* \"require\" functions from 'loadedlibs' and set results to global table */\n  for (lib = loadedlibs; lib->func; lib++) {\n    luaL_requiref(L, lib->name, lib->func, 1);\n    lua_pop(L, 1);  /* remove lib */\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.151.1.1 2017/04/19 17:29:57 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <locale.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** Change this macro to accept other modes for 'fopen' besides\n** the standard ones.\n*/\n#if !defined(l_checkmode)\n\n/* accepted extensions to 'mode' in 'fopen' */\n#if !defined(L_MODEEXT)\n#define L_MODEEXT\t\"b\"\n#endif\n\n/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */\nstatic int l_checkmode (const char *mode) {\n  return (*mode != '\\0' && strchr(\"rwa\", *(mode++)) != NULL &&\n         (*mode != '+' || (++mode, 1)) &&  /* skip if char is '+' */\n         (strspn(mode, L_MODEEXT) == strlen(mode)));  /* check extensions */\n}\n\n#endif\n\n/*\n** {======================================================\n** l_popen spawns a new process connected to the current\n** one through the file streams.\n** =======================================================\n*/\n\n#if !defined(l_popen)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_popen(L,c,m)\t\t(fflush(NULL), popen(c,m))\n#define l_pclose(L,file)\t(pclose(file))\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#define l_popen(L,c,m)\t\t(_popen(c,m))\n#define l_pclose(L,file)\t(_pclose(file))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_popen(L,c,m)  \\\n\t  ((void)((void)c, m), \\\n\t  luaL_error(L, \"'popen' not supported\"), \\\n\t  (FILE*)0)\n#define l_pclose(L,file)\t\t((void)L, (void)file, -1)\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#if !defined(l_getc)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\n#define l_getc(f)\t\tgetc_unlocked(f)\n#define l_lockfile(f)\t\tflockfile(f)\n#define l_unlockfile(f)\t\tfunlockfile(f)\n#else\n#define l_getc(f)\t\tgetc(f)\n#define l_lockfile(f)\t\t((void)0)\n#define l_unlockfile(f)\t\t((void)0)\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** {======================================================\n** l_fseek: configuration for longer offsets\n** =======================================================\n*/\n\n#if !defined(l_fseek)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <sys/types.h>\n\n#define l_fseek(f,o,w)\t\tfseeko(f,o,w)\n#define l_ftell(f)\t\tftello(f)\n#define l_seeknum\t\toff_t\n\n#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \\\n   && defined(_MSC_VER) && (_MSC_VER >= 1400)\t/* }{ */\n\n/* Windows (but not DDK) and Visual C++ 2005 or higher */\n#define l_fseek(f,o,w)\t\t_fseeki64(f,o,w)\n#define l_ftell(f)\t\t_ftelli64(f)\n#define l_seeknum\t\t__int64\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_fseek(f,o,w)\t\tfseek(f,o,w)\n#define l_ftell(f)\t\tftell(f)\n#define l_seeknum\t\tlong\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#define IO_PREFIX\t\"_IO_\"\n#define IOPREF_LEN\t(sizeof(IO_PREFIX)/sizeof(char) - 1)\n#define IO_INPUT\t(IO_PREFIX \"input\")\n#define IO_OUTPUT\t(IO_PREFIX \"output\")\n\n\ntypedef luaL_Stream LStream;\n\n\n#define tolstream(L)\t((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n#define isclosed(p)\t((p)->closef == NULL)\n\n\nstatic int io_type (lua_State *L) {\n  LStream *p;\n  luaL_checkany(L, 1);\n  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);\n  if (p == NULL)\n    lua_pushnil(L);  /* not a file */\n  else if (isclosed(p))\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic int f_tostring (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", p->f);\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    luaL_error(L, \"attempt to use a closed file\");\n  lua_assert(p->f);\n  return p->f;\n}\n\n\n/*\n** When creating file handles, always creates a 'closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** handle is in a consistent state.\n*/\nstatic LStream *newprefile (lua_State *L) {\n  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));\n  p->closef = NULL;  /* mark file handle as 'closed' */\n  luaL_setmetatable(L, LUA_FILEHANDLE);\n  return p;\n}\n\n\n/*\n** Calls the 'close' function from a file handle. The 'volatile' avoids\n** a bug in some versions of the Clang compiler (e.g., clang 3.0 for\n** 32 bits).\n*/\nstatic int aux_close (lua_State *L) {\n  LStream *p = tolstream(L);\n  volatile lua_CFunction cf = p->closef;\n  p->closef = NULL;  /* mark stream as closed */\n  return (*cf)(L);  /* close it */\n}\n\n\nstatic int f_close (lua_State *L) {\n  tofile(L);  /* make sure argument is an open stream */\n  return aux_close(L);\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))  /* no argument? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */\n  return f_close(L);\n}\n\n\nstatic int f_gc (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (!isclosed(p) && p->f != NULL)\n    aux_close(L);  /* ignore closed and incompletely open files */\n  return 0;\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  int res = fclose(p->f);\n  return luaL_fileresult(L, (res == 0), NULL);\n}\n\n\nstatic LStream *newfile (lua_State *L) {\n  LStream *p = newprefile(L);\n  p->f = NULL;\n  p->closef = &io_fclose;\n  return p;\n}\n\n\nstatic void opencheck (lua_State *L, const char *fname, const char *mode) {\n  LStream *p = newfile(L);\n  p->f = fopen(fname, mode);\n  if (p->f == NULL)\n    luaL_error(L, \"cannot open file '%s' (%s)\", fname, strerror(errno));\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newfile(L);\n  const char *md = mode;  /* to traverse/check mode */\n  luaL_argcheck(L, l_checkmode(md), 2, \"invalid mode\");\n  p->f = fopen(filename, mode);\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  LStream *p = tolstream(L);\n  return luaL_execresult(L, l_pclose(L, p->f));\n#endif\n}\n\n\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newprefile(L);\n  p->f = l_popen(L, filename, mode);\n  p->closef = &io_pclose;\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  LStream *p = newfile(L);\n  p->f = tmpfile();\n  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, const char *findex) {\n  LStream *p;\n  lua_getfield(L, LUA_REGISTRYINDEX, findex);\n  p = (LStream *)lua_touserdata(L, -1);\n  if (isclosed(p))\n    luaL_error(L, \"standard %s file is closed\", findex + IOPREF_LEN);\n  return p->f;\n}\n\n\nstatic int g_iofile (lua_State *L, const char *f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename)\n      opencheck(L, filename, mode);\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_setfield(L, LUA_REGISTRYINDEX, f);\n  }\n  /* return current value */\n  lua_getfield(L, LUA_REGISTRYINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\n/*\n** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit\n** in the limit for upvalues of a closure)\n*/\n#define MAXARGLINE\t250\n\nstatic void aux_lines (lua_State *L, int toclose) {\n  int n = lua_gettop(L) - 1;  /* number of arguments to read */\n  luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, \"too many arguments\");\n  lua_pushinteger(L, n);  /* number of arguments to read */\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_rotate(L, 2, 2);  /* move 'n' and 'toclose' to their positions */\n  lua_pushcclosure(L, io_readline, 3 + n);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  int toclose;\n  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */\n  if (lua_isnil(L, 1)) {  /* no file name? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */\n    lua_replace(L, 1);  /* put it at index 1 */\n    tofile(L);  /* check that it's a valid file handle */\n    toclose = 0;  /* do not close it after iteration */\n  }\n  else {  /* open a new file */\n    const char *filename = luaL_checkstring(L, 1);\n    opencheck(L, filename, \"r\");\n    lua_replace(L, 1);  /* put file at index 1 */\n    toclose = 1;  /* close it after iteration */\n  }\n  aux_lines(L, toclose);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM     200\n#endif\n\n\n/* auxiliary structure used by 'read_number' */\ntypedef struct {\n  FILE *f;  /* file being read */\n  int c;  /* current character (look ahead) */\n  int n;  /* number of elements in buffer 'buff' */\n  char buff[L_MAXLENNUM + 1];  /* +1 for ending '\\0' */\n} RN;\n\n\n/*\n** Add current char to buffer (if not out of space) and read next one\n*/\nstatic int nextc (RN *rn) {\n  if (rn->n >= L_MAXLENNUM) {  /* buffer overflow? */\n    rn->buff[0] = '\\0';  /* invalidate result */\n    return 0;  /* fail */\n  }\n  else {\n    rn->buff[rn->n++] = rn->c;  /* save current char */\n    rn->c = l_getc(rn->f);  /* read next one */\n    return 1;\n  }\n}\n\n\n/*\n** Accept current char if it is in 'set' (of size 2)\n*/\nstatic int test2 (RN *rn, const char *set) {\n  if (rn->c == set[0] || rn->c == set[1])\n    return nextc(rn);\n  else return 0;\n}\n\n\n/*\n** Read a sequence of (hex)digits\n*/\nstatic int readdigits (RN *rn, int hex) {\n  int count = 0;\n  while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn))\n    count++;\n  return count;\n}\n\n\n/*\n** Read a number: first reads a valid prefix of a numeral into a buffer.\n** Then it calls 'lua_stringtonumber' to check whether the format is\n** correct and to convert it to a Lua number\n*/\nstatic int read_number (lua_State *L, FILE *f) {\n  RN rn;\n  int count = 0;\n  int hex = 0;\n  char decp[2];\n  rn.f = f; rn.n = 0;\n  decp[0] = lua_getlocaledecpoint();  /* get decimal point from locale */\n  decp[1] = '.';  /* always accept a dot */\n  l_lockfile(rn.f);\n  do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */\n  test2(&rn, \"-+\");  /* optional signal */\n  if (test2(&rn, \"00\")) {\n    if (test2(&rn, \"xX\")) hex = 1;  /* numeral is hexadecimal */\n    else count = 1;  /* count initial '0' as a valid digit */\n  }\n  count += readdigits(&rn, hex);  /* integral part */\n  if (test2(&rn, decp))  /* decimal point? */\n    count += readdigits(&rn, hex);  /* fractional part */\n  if (count > 0 && test2(&rn, (hex ? \"pP\" : \"eE\"))) {  /* exponent mark? */\n    test2(&rn, \"-+\");  /* exponent signal */\n    readdigits(&rn, 0);  /* exponent digits */\n  }\n  ungetc(rn.c, rn.f);  /* unread look-ahead char */\n  l_unlockfile(rn.f);\n  rn.buff[rn.n] = '\\0';  /* finish string */\n  if (lua_stringtonumber(L, rn.buff))  /* is this a valid number? */\n    return 1;  /* ok */\n  else {  /* invalid format */\n   lua_pushnil(L);  /* \"result\" to be removed */\n   return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);  /* no-op when c == EOF */\n  lua_pushliteral(L, \"\");\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f, int chop) {\n  luaL_Buffer b;\n  int c = '\\0';\n  luaL_buffinit(L, &b);\n  while (c != EOF && c != '\\n') {  /* repeat until end of line */\n    char *buff = luaL_prepbuffer(&b);  /* preallocate buffer */\n    int i = 0;\n    l_lockfile(f);  /* no memory errors can happen inside the lock */\n    while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')\n      buff[i++] = c;\n    l_unlockfile(f);\n    luaL_addsize(&b, i);\n  }\n  if (!chop && c == '\\n')  /* want a newline and have one? */\n    luaL_addchar(&b, c);  /* add ending newline to result */\n  luaL_pushresult(&b);  /* close buffer */\n  /* return ok if read something (either a newline or something else) */\n  return (c == '\\n' || lua_rawlen(L, -1) > 0);\n}\n\n\nstatic void read_all (lua_State *L, FILE *f) {\n  size_t nr;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */\n    char *p = luaL_prepbuffer(&b);\n    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);\n    luaL_addsize(&b, nr);\n  } while (nr == LUAL_BUFFERSIZE);\n  luaL_pushresult(&b);  /* close buffer */\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t nr;  /* number of chars actually read */\n  char *p;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */\n  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */\n  luaL_addsize(&b, nr);\n  luaL_pushresult(&b);  /* close buffer */\n  return (nr > 0);  /* true iff read something */\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f, 1);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)luaL_checkinteger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = luaL_checkstring(L, n);\n        if (*p == '*') p++;  /* skip optional '*' (for compatibility) */\n        switch (*p) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f, 1);\n            break;\n          case 'L':  /* line with end-of-line */\n            success = read_line(L, f, 0);\n            break;\n          case 'a':  /* file */\n            read_all(L, f);  /* read entire file */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return luaL_fileresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));\n  int i;\n  int n = (int)lua_tointeger(L, lua_upvalueindex(2));\n  if (isclosed(p))  /* file is already closed? */\n    return luaL_error(L, \"file is already closed\");\n  lua_settop(L , 1);\n  luaL_checkstack(L, n, \"too many arguments\");\n  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */\n    lua_pushvalue(L, lua_upvalueindex(3 + i));\n  n = g_read(L, p->f, 2);  /* 'n' is number of results */\n  lua_assert(n > 0);  /* should return at least a nil */\n  if (lua_toboolean(L, -n))  /* read at least one value? */\n    return n;  /* return them */\n  else {  /* first result is nil: EOF or error */\n    if (n > 1) {  /* is there error information? */\n      /* 2nd result is error message */\n      return luaL_error(L, \"%s\", lua_tostring(L, -n + 1));\n    }\n    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - arg;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      int len = lua_isinteger(L, arg)\n                ? fprintf(f, LUA_INTEGER_FMT,\n                             (LUAI_UACINT)lua_tointeger(L, arg))\n                : fprintf(f, LUA_NUMBER_FMT,\n                             (LUAI_UACNUMBER)lua_tonumber(L, arg));\n      status = status && (len > 0);\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  if (status) return 1;  /* file handle already on stack top */\n  else return luaL_fileresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  FILE *f = tofile(L);\n  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */\n  return g_write(L, f, 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  lua_Integer p3 = luaL_optinteger(L, 3, 0);\n  l_seeknum offset = (l_seeknum)p3;\n  luaL_argcheck(L, (lua_Integer)offset == p3, 3,\n                  \"not an integer in proper range\");\n  op = l_fseek(f, offset, mode[op]);\n  if (op)\n    return luaL_fileresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, (lua_Integer)l_ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], (size_t)sz);\n  return luaL_fileresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\n/*\n** functions for 'io' library\n*/\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\n/*\n** methods for file handles\n*/\nstatic const luaL_Reg flib[] = {\n  {\"close\", f_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", f_gc},\n  {\"__tostring\", f_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_setfuncs(L, flib, 0);  /* add file methods to new metatable */\n  lua_pop(L, 1);  /* pop new metatable */\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  p->closef = &io_noclose;  /* keep file opened */\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, const char *k,\n                           const char *fname) {\n  LStream *p = newprefile(L);\n  p->f = f;\n  p->closef = &io_noclose;\n  if (k != NULL) {\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */\n  }\n  lua_setfield(L, -2, fname);  /* add file to module */\n}\n\n\nLUAMOD_API int luaopen_io (lua_State *L) {\n  luaL_newlib(L, iolib);  /* new module */\n  createmeta(L);\n  /* create (and set) default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, NULL, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.96.1.1 2017/04/19 17:20:42 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nstatic const char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"goto\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"//\", \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<<\", \">>\", \"::\", \"<eof>\",\n    \"<number>\", \"<integer>\", \"<name>\", \"<string>\"\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token);\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {\n    size_t newsize;\n    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)\n      lexerror(ls, \"lexical element too long\", 0);\n    newsize = luaZ_sizebuffer(b) * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[luaZ_bufflen(b)++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */\n  luaC_fix(L, obj2gco(e));  /* never collect this name */\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */\n    ts->extra = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {  /* single-byte symbols? */\n    lua_assert(token == cast_uchar(token));\n    return luaO_pushfstring(ls->L, \"'%c'\", token);\n  }\n  else {\n    const char *s = luaX_tokens[token - FIRST_RESERVED];\n    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */\n      return luaO_pushfstring(ls->L, \"'%s'\", s);\n    else  /* names, strings, and numerals */\n      return s;\n  }\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME: case TK_STRING:\n    case TK_FLT: case TK_INT:\n      save(ls, '\\0');\n      return luaO_pushfstring(ls->L, \"'%s'\", luaZ_buffer(ls->buff));\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token) {\n  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near %s\", msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nl_noret luaX_syntaxerror (LexState *ls, const char *msg) {\n  lexerror(ls, msg, ls->t.token);\n}\n\n\n/*\n** creates a new string and anchors it in scanner's table so that\n** it will not be collected until the end of the compilation\n** (by that time it should be anchored somewhere)\n*/\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TValue *o;  /* entry for 'str' */\n  TString *ts = luaS_newlstr(L, str, l);  /* create new string */\n  setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */\n  o = luaH_set(L, ls->h, L->top - 1);\n  if (ttisnil(o)) {  /* not in use yet? */\n    /* boolean value does not need GC barrier;\n       table has no metatable, so it does not need to invalidate cache */\n    setbvalue(o, 1);  /* t[string] = true */\n    luaC_checkGC(L);\n  }\n  else {  /* string already present */\n    ts = tsvalue(keyfromval(o));  /* re-use value previously stored */\n  }\n  L->top--;  /* remove string from stack */\n  return ts;\n}\n\n\n/*\n** increment line number and skips newline sequence (any of\n** \\n, \\r, \\n\\r, or \\r\\n)\n*/\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip '\\n' or '\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip '\\n\\r' or '\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    lexerror(ls, \"chunk has too many lines\", 0);\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,\n                    int firstchar) {\n  ls->t.token = 0;\n  ls->L = L;\n  ls->current = firstchar;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\nstatic int check_next1 (LexState *ls, int c) {\n  if (ls->current == c) {\n    next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check whether current char is in set 'set' (with two chars) and\n** saves it\n*/\nstatic int check_next2 (LexState *ls, const char *set) {\n  lua_assert(set[2] == '\\0');\n  if (ls->current == set[0] || ls->current == set[1]) {\n    save_and_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/* LUA_NUMBER */\n/*\n** this function is quite liberal in what it accepts, as 'luaO_str2num'\n** will reject ill-formed numerals.\n*/\nstatic int read_numeral (LexState *ls, SemInfo *seminfo) {\n  TValue obj;\n  const char *expo = \"Ee\";\n  int first = ls->current;\n  lua_assert(lisdigit(ls->current));\n  save_and_next(ls);\n  if (first == '0' && check_next2(ls, \"xX\"))  /* hexadecimal? */\n    expo = \"Pp\";\n  for (;;) {\n    if (check_next2(ls, expo))  /* exponent part? */\n      check_next2(ls, \"-+\");  /* optional exponent sign */\n    if (lisxdigit(ls->current))\n      save_and_next(ls);\n    else if (ls->current == '.')\n      save_and_next(ls);\n    else break;\n  }\n  save(ls, '\\0');\n  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */\n    lexerror(ls, \"malformed number\", TK_FLT);\n  if (ttisinteger(&obj)) {\n    seminfo->i = ivalue(&obj);\n    return TK_INT;\n  }\n  else {\n    lua_assert(ttisfloat(&obj));\n    seminfo->r = fltvalue(&obj);\n    return TK_FLT;\n  }\n}\n\n\n/*\n** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return\n** its number of '='s; otherwise, return a negative number (-1 iff there\n** are no '='s after initial bracket)\n*/\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int line = ls->linenumber;  /* initial line (for error message) */\n  save_and_next(ls);  /* skip 2nd '[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ: {  /* error */\n        const char *what = (seminfo ? \"string\" : \"comment\");\n        const char *msg = luaO_pushfstring(ls->L,\n                     \"unfinished long %s (starting at line %d)\", what, line);\n        lexerror(ls, msg, TK_EOS);\n        break;  /* to avoid warnings */\n      }\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd ']' */\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n': case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void esccheck (LexState *ls, int c, const char *msg) {\n  if (!c) {\n    if (ls->current != EOZ)\n      save_and_next(ls);  /* add current to buffer for error message */\n    lexerror(ls, msg, TK_STRING);\n  }\n}\n\n\nstatic int gethexa (LexState *ls) {\n  save_and_next(ls);\n  esccheck (ls, lisxdigit(ls->current), \"hexadecimal digit expected\");\n  return luaO_hexavalue(ls->current);\n}\n\n\nstatic int readhexaesc (LexState *ls) {\n  int r = gethexa(ls);\n  r = (r << 4) + gethexa(ls);\n  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic unsigned long readutf8esc (LexState *ls) {\n  unsigned long r;\n  int i = 4;  /* chars to be removed: '\\', 'u', '{', and first digit */\n  save_and_next(ls);  /* skip 'u' */\n  esccheck(ls, ls->current == '{', \"missing '{'\");\n  r = gethexa(ls);  /* must have at least one digit */\n  while ((save_and_next(ls), lisxdigit(ls->current))) {\n    i++;\n    r = (r << 4) + luaO_hexavalue(ls->current);\n    esccheck(ls, r <= 0x10FFFF, \"UTF-8 value too large\");\n  }\n  esccheck(ls, ls->current == '}', \"missing '}'\");\n  next(ls);  /* skip '}' */\n  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic void utf8esc (LexState *ls) {\n  char buff[UTF8BUFFSZ];\n  int n = luaO_utf8esc(buff, readutf8esc(ls));\n  for (; n > 0; n--)  /* add 'buff' to string */\n    save(ls, buff[UTF8BUFFSZ - n]);\n}\n\n\nstatic int readdecesc (LexState *ls) {\n  int i;\n  int r = 0;  /* result accumulator */\n  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */\n    r = 10*r + ls->current - '0';\n    save_and_next(ls);\n  }\n  esccheck(ls, r <= UCHAR_MAX, \"decimal escape too large\");\n  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */\n  return r;\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);  /* keep delimiter (for error messages) */\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        lexerror(ls, \"unfinished string\", TK_EOS);\n        break;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        lexerror(ls, \"unfinished string\", TK_STRING);\n        break;  /* to avoid warnings */\n      case '\\\\': {  /* escape sequences */\n        int c;  /* final character to be saved */\n        save_and_next(ls);  /* keep '\\\\' for error messages */\n        switch (ls->current) {\n          case 'a': c = '\\a'; goto read_save;\n          case 'b': c = '\\b'; goto read_save;\n          case 'f': c = '\\f'; goto read_save;\n          case 'n': c = '\\n'; goto read_save;\n          case 'r': c = '\\r'; goto read_save;\n          case 't': c = '\\t'; goto read_save;\n          case 'v': c = '\\v'; goto read_save;\n          case 'x': c = readhexaesc(ls); goto read_save;\n          case 'u': utf8esc(ls);  goto no_save;\n          case '\\n': case '\\r':\n            inclinenumber(ls); c = '\\n'; goto only_save;\n          case '\\\\': case '\\\"': case '\\'':\n            c = ls->current; goto read_save;\n          case EOZ: goto no_save;  /* will raise an error next loop */\n          case 'z': {  /* zap following span of spaces */\n            luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n            next(ls);  /* skip the 'z' */\n            while (lisspace(ls->current)) {\n              if (currIsNewline(ls)) inclinenumber(ls);\n              else next(ls);\n            }\n            goto no_save;\n          }\n          default: {\n            esccheck(ls, lisdigit(ls->current), \"invalid escape sequence\");\n            c = readdecesc(ls);  /* digital escape '\\ddd' */\n            goto only_save;\n          }\n        }\n       read_save:\n         next(ls);\n         /* go through */\n       only_save:\n         luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n         save(ls, c);\n         /* go through */\n       no_save: break;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n': case '\\r': {  /* line breaks */\n        inclinenumber(ls);\n        break;\n      }\n      case ' ': case '\\f': case '\\t': case '\\v': {  /* spaces */\n        next(ls);\n        break;\n      }\n      case '-': {  /* '-' or '--' (comment) */\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {  /* long comment? */\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* skip long comment */\n            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */\n            break;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);  /* skip until end of line (or end of file) */\n        break;\n      }\n      case '[': {  /* long string or simply '[' */\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep != -1)  /* '[=...' missing second bracket */\n          lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n        return '[';\n      }\n      case '=': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_EQ;\n        else return '=';\n      }\n      case '<': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_LE;\n        else if (check_next1(ls, '<')) return TK_SHL;\n        else return '<';\n      }\n      case '>': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_GE;\n        else if (check_next1(ls, '>')) return TK_SHR;\n        else return '>';\n      }\n      case '/': {\n        next(ls);\n        if (check_next1(ls, '/')) return TK_IDIV;\n        else return '/';\n      }\n      case '~': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_NE;\n        else return '~';\n      }\n      case ':': {\n        next(ls);\n        if (check_next1(ls, ':')) return TK_DBCOLON;\n        else return ':';\n      }\n      case '\"': case '\\'': {  /* short literal strings */\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {  /* '.', '..', '...', or number */\n        save_and_next(ls);\n        if (check_next1(ls, '.')) {\n          if (check_next1(ls, '.'))\n            return TK_DOTS;   /* '...' */\n          else return TK_CONCAT;   /* '..' */\n        }\n        else if (!lisdigit(ls->current)) return '.';\n        else return read_numeral(ls, seminfo);\n      }\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9': {\n        return read_numeral(ls, seminfo);\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (lislalpha(ls->current)) {  /* identifier or reserved word? */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (lislalnum(ls->current));\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          seminfo->ts = ts;\n          if (isreserved(ts))  /* reserved word? */\n            return ts->extra - 1 + FIRST_RESERVED;\n          else {\n            return TK_NAME;\n          }\n        }\n        else {  /* single-char tokens (+ - / ...) */\n          int c = ls->current;\n          next(ls);\n          return c;\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nint luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n  return ls->lookahead.token;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n\n#if !defined(LUA_ENV)\n#define LUA_ENV\t\t\"_ENV\"\n#endif\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,\n  TK_SHL, TK_SHR,\n  TK_DBCOLON, TK_EOS,\n  TK_FLT, TK_INT, TK_NAME, TK_STRING\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\ntypedef union {\n  lua_Number r;\n  lua_Integer i;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\n/* state of the lexer plus state of the parser when shared by all\n   functions */\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token 'consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* current function (parser) */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  Table *h;  /* to avoid collection/reuse strings */\n  struct Dyndata *dyd;  /* dynamic structures used by the parser */\n  TString *source;  /* current source name */\n  TString *envn;  /* environment variable name */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source, int firstchar);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC int luaX_lookahead (LexState *ls);\nLUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.141.1.1 2017/04/19 17:20:42 roberto Exp $\n** Limits, basic types, and some other 'installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n/*\n** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count\n** the total memory used by Lua (in bytes). Usually, 'size_t' and\n** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.\n*/\n#if defined(LUAI_MEM)\t\t/* { external definitions? */\ntypedef LUAI_UMEM lu_mem;\ntypedef LUAI_MEM l_mem;\n#elif LUAI_BITSINT >= 32\t/* }{ */\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\n#else  /* 16-bit ints */\t/* }{ */\ntypedef unsigned long lu_mem;\ntypedef long l_mem;\n#endif\t\t\t\t/* } */\n\n\n/* chars used as small naturals (so that 'char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n/* maximum size visible for Lua (must be representable in a lua_Integer */\n#define MAX_SIZE\t(sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \\\n                          : (size_t)(LUA_MAXINTEGER))\n\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0))\n\n#define MAX_LMEM\t((l_mem)(MAX_LUMEM >> 1))\n\n\n#define MAX_INT\t\tINT_MAX  /* maximum value of an int */\n\n\n/*\n** conversion of pointer to unsigned integer:\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define point2uint(p)\t((unsigned int)((size_t)(p) & UINT_MAX))\n\n\n\n/* type to ensure maximum alignment */\n#if defined(LUAI_USER_ALIGNMENT_T)\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n#else\ntypedef union {\n  lua_Number n;\n  double u;\n  void *s;\n  lua_Integer i;\n  long l;\n} L_Umaxalign;\n#endif\n\n\n\n/* types of 'usual argument conversions' for lua_Number and lua_Integer */\ntypedef LUAI_UACNUMBER l_uacNumber;\ntypedef LUAI_UACINT l_uacInt;\n\n\n/* internal assertions for in-house debugging */\n#if defined(lua_assert)\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n/* to avoid problems with conditions too long */\n#define lua_longassert(c)\t((c) ? (void)0 : lua_assert(0))\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define lua_longassert(c)\t((void)0)\n#endif\n\n/*\n** assertion for checking API calls\n*/\n#if !defined(luai_apicheck)\n#define luai_apicheck(l,e)\tlua_assert(e)\n#endif\n\n#define api_check(l,e,msg)\tluai_apicheck(l,(e) && msg)\n\n\n/* macro to avoid warnings about unused variables */\n#if !defined(UNUSED)\n#define UNUSED(x)\t((void)(x))\n#endif\n\n\n/* type casts (a macro highlights casts in the code) */\n#define cast(t, exp)\t((t)(exp))\n\n#define cast_void(i)\tcast(void, (i))\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n#define cast_uchar(i)\tcast(unsigned char, (i))\n\n\n/* cast a signed lua_Integer to lua_Unsigned */\n#if !defined(l_castS2U)\n#define l_castS2U(i)\t((lua_Unsigned)(i))\n#endif\n\n/*\n** cast a lua_Unsigned to a signed lua_Integer; this cast is\n** not strict ISO C, but two-complement architectures should\n** work fine.\n*/\n#if !defined(l_castU2S)\n#define l_castU2S(i)\t((lua_Integer)(i))\n#endif\n\n\n/*\n** non-return type\n*/\n#if defined(__GNUC__)\n#define l_noret\t\tvoid __attribute__((noreturn))\n#elif defined(_MSC_VER) && _MSC_VER >= 1200\n#define l_noret\t\tvoid __declspec(noreturn)\n#else\n#define l_noret\t\tvoid\n#endif\n\n\n\n/*\n** maximum depth for nested C calls and syntactical nested non-terminals\n** in a program. (Value must fit in an unsigned short int.)\n*/\n#if !defined(LUAI_MAXCCALLS)\n#define LUAI_MAXCCALLS\t\t200\n#endif\n\n\n\n/*\n** type for virtual-machine instructions;\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\n#if LUAI_BITSINT >= 32\ntypedef unsigned int Instruction;\n#else\ntypedef unsigned long Instruction;\n#endif\n\n\n\n/*\n** Maximum length for short strings, that is, strings that are\n** internalized. (Cannot be smaller than reserved words or tags for\n** metamethods, as these strings must be internalized;\n** #(\"function\") = 8, #(\"__newindex\") = 10.)\n*/\n#if !defined(LUAI_MAXSHORTLEN)\n#define LUAI_MAXSHORTLEN\t40\n#endif\n\n\n/*\n** Initial size for the string table (must be power of 2).\n** The Lua core alone registers ~50 strings (reserved words +\n** metaevent keys + a few others). Libraries would typically add\n** a few dozens more.\n*/\n#if !defined(MINSTRTABSIZE)\n#define MINSTRTABSIZE\t128\n#endif\n\n\n/*\n** Size of cache for strings in the API. 'N' is the number of\n** sets (better be a prime) and \"M\" is the size of each set (M == 1\n** makes a direct cache.)\n*/\n#if !defined(STRCACHE_N)\n#define STRCACHE_N\t\t53\n#define STRCACHE_M\t\t2\n#endif\n\n\n/* minimum size for string buffer */\n#if !defined(LUA_MINBUFFER)\n#define LUA_MINBUFFER\t32\n#endif\n\n\n/*\n** macros that are executed whenever program enters the Lua core\n** ('lua_lock') and leaves the core ('lua_unlock')\n*/\n#if !defined(lua_lock)\n#define lua_lock(L)\t((void) 0)\n#define lua_unlock(L)\t((void) 0)\n#endif\n\n/*\n** macro executed during Lua functions at points where the\n** function can yield.\n*/\n#if !defined(luai_threadyield)\n#define luai_threadyield(L)\t{lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** these macros allow user-specific actions on threads when you defined\n** LUAI_EXTRASPACE and need to do something extra when a thread is\n** created/deleted/resumed/yielded.\n*/\n#if !defined(luai_userstateopen)\n#define luai_userstateopen(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstateclose)\n#define luai_userstateclose(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstatethread)\n#define luai_userstatethread(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstatefree)\n#define luai_userstatefree(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstateresume)\n#define luai_userstateresume(L,n)\t((void)L)\n#endif\n\n#if !defined(luai_userstateyield)\n#define luai_userstateyield(L,n)\t((void)L)\n#endif\n\n\n\n/*\n** The luai_num* macros define the primitive operations over numbers.\n*/\n\n/* floor division (defined as 'floor(a/b)') */\n#if !defined(luai_numidiv)\n#define luai_numidiv(L,a,b)     ((void)L, l_floor(luai_numdiv(L,a,b)))\n#endif\n\n/* float division */\n#if !defined(luai_numdiv)\n#define luai_numdiv(L,a,b)      ((a)/(b))\n#endif\n\n/*\n** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when\n** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of\n** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)\n** ~= floor(a/b)'. That happens when the division has a non-integer\n** negative result, which is equivalent to the test below.\n*/\n#if !defined(luai_nummod)\n#define luai_nummod(L,a,b,m)  \\\n  { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }\n#endif\n\n/* exponentiation */\n#if !defined(luai_numpow)\n#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))\n#endif\n\n/* the others are quite standard operations */\n#if !defined(luai_numadd)\n#define luai_numadd(L,a,b)      ((a)+(b))\n#define luai_numsub(L,a,b)      ((a)-(b))\n#define luai_nummul(L,a,b)      ((a)*(b))\n#define luai_numunm(L,a)        (-(a))\n#define luai_numeq(a,b)         ((a)==(b))\n#define luai_numlt(a,b)         ((a)<(b))\n#define luai_numle(a,b)         ((a)<=(b))\n#define luai_numisnan(a)        (!luai_numeq((a), (a)))\n#endif\n\n\n\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/\n#if !defined(HARDSTACKTESTS)\n#define condmovestack(L,pre,pos)\t((void)0)\n#else\n/* realloc stack keeping its size */\n#define condmovestack(L,pre,pos)  \\\n\t{ int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; }\n#endif\n\n#if !defined(HARDMEMTESTS)\n#define condchangemem(L,pre,pos)\t((void)0)\n#else\n#define condchangemem(L,pre,pos)  \\\n\t{ if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.119.1.1 2017/04/19 17:20:42 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI\t(l_mathop(3.141592653589793238462643383279502884))\n\n\n#if !defined(l_rand)\t\t/* { */\n#if defined(LUA_USE_POSIX)\n#define l_rand()\trandom()\n#define l_srand(x)\tsrandom(x)\n#define L_RANDMAX\t2147483647\t/* (2^31 - 1), following POSIX */\n#else\n#define l_rand()\trand()\n#define l_srand(x)\tsrand(x)\n#define L_RANDMAX\tRAND_MAX\n#endif\n#endif\t\t\t\t/* } */\n\n\nstatic int math_abs (lua_State *L) {\n  if (lua_isinteger(L, 1)) {\n    lua_Integer n = lua_tointeger(L, 1);\n    if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);\n    lua_pushinteger(L, n);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_Number y = luaL_checknumber(L, 1);\n  lua_Number x = luaL_optnumber(L, 2, 1);\n  lua_pushnumber(L, l_mathop(atan2)(y, x));\n  return 1;\n}\n\n\nstatic int math_toint (lua_State *L) {\n  int valid;\n  lua_Integer n = lua_tointegerx(L, 1, &valid);\n  if (valid)\n    lua_pushinteger(L, n);\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);  /* value is not convertible to integer */\n  }\n  return 1;\n}\n\n\nstatic void pushnumint (lua_State *L, lua_Number d) {\n  lua_Integer n;\n  if (lua_numbertointeger(d, &n))  /* does 'd' fit in an integer? */\n    lua_pushinteger(L, n);  /* result is integer */\n  else\n    lua_pushnumber(L, d);  /* result is float */\n}\n\n\nstatic int math_floor (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own floor */\n  else {\n    lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_ceil (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own ceil */\n  else {\n    lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_fmod (lua_State *L) {\n  if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) {\n    lua_Integer d = lua_tointeger(L, 2);\n    if ((lua_Unsigned)d + 1u <= 1u) {  /* special cases: -1 or 0 */\n      luaL_argcheck(L, d != 0, 2, \"zero\");\n      lua_pushinteger(L, 0);  /* avoid overflow with 0x80000... / -1 */\n    }\n    else\n      lua_pushinteger(L, lua_tointeger(L, 1) % d);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),\n                                     luaL_checknumber(L, 2)));\n  return 1;\n}\n\n\n/*\n** next function does not use 'modf', avoiding problems with 'double*'\n** (which is not compatible with 'float*') when lua_Number is not\n** 'double'.\n*/\nstatic int math_modf (lua_State *L) {\n  if (lua_isinteger(L ,1)) {\n    lua_settop(L, 1);  /* number is its own integer part */\n    lua_pushnumber(L, 0);  /* no fractional part */\n  }\n  else {\n    lua_Number n = luaL_checknumber(L, 1);\n    /* integer part (rounds toward zero) */\n    lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);\n    pushnumint(L, ip);\n    /* fractional part (test needed for inf/-inf) */\n    lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));\n  }\n  return 2;\n}\n\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n\nstatic int math_ult (lua_State *L) {\n  lua_Integer a = luaL_checkinteger(L, 1);\n  lua_Integer b = luaL_checkinteger(L, 2);\n  lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b);\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number res;\n  if (lua_isnoneornil(L, 2))\n    res = l_mathop(log)(x);\n  else {\n    lua_Number base = luaL_checknumber(L, 2);\n    if (base == l_mathop(10.0))\n      res = l_mathop(log10)(x);\n    else\n      res = l_mathop(log)(x)/l_mathop(log)(base);\n  }\n  lua_pushnumber(L, res);\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));\n  return 1;\n}\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imin = 1;  /* index of current minimum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, i, imin, LUA_OPLT))\n      imin = i;\n  }\n  lua_pushvalue(L, imin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imax = 1;  /* index of current maximum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, imax, i, LUA_OPLT))\n      imax = i;\n  }\n  lua_pushvalue(L, imax);\n  return 1;\n}\n\n/*\n** This function uses 'double' (instead of 'lua_Number') to ensure that\n** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0'\n** will keep full precision (ensuring that 'r' is always less than 1.0.)\n*/\nstatic int math_random (lua_State *L) {\n  lua_Integer low, up;\n  double r = (double)l_rand() * (1.0 / ((double)L_RANDMAX + 1.0));\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, (lua_Number)r);  /* Number between 0 and 1 */\n      return 1;\n    }\n    case 1: {  /* only upper limit */\n      low = 1;\n      up = luaL_checkinteger(L, 1);\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      low = luaL_checkinteger(L, 1);\n      up = luaL_checkinteger(L, 2);\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  /* random integer in the interval [low, up] */\n  luaL_argcheck(L, low <= up, 1, \"interval is empty\");\n  luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,\n                   \"interval too large\");\n  r *= (double)(up - low) + 1.0;\n  lua_pushinteger(L, (lua_Integer)r + low);\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));\n  (void)l_rand(); /* discard first value to avoid undesirable correlations */\n  return 0;\n}\n\n\nstatic int math_type (lua_State *L) {\n  if (lua_type(L, 1) == LUA_TNUMBER) {\n      if (lua_isinteger(L, 1))\n        lua_pushliteral(L, \"integer\");\n      else\n        lua_pushliteral(L, \"float\");\n  }\n  else {\n    luaL_checkany(L, 1);\n    lua_pushnil(L);\n  }\n  return 1;\n}\n\n\n/*\n** {==================================================================\n** Deprecated functions (for compatibility only)\n** ===================================================================\n*/\n#if defined(LUA_COMPAT_MATHLIB)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number y = luaL_checknumber(L, 2);\n  lua_pushnumber(L, l_mathop(pow)(x, y));\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  int ep = (int)luaL_checkinteger(L, 2);\n  lua_pushnumber(L, l_mathop(ldexp)(x, ep));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n#endif\n/* }================================================================== */\n\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"tointeger\", math_toint},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"ult\",   math_ult},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tan\",   math_tan},\n  {\"type\", math_type},\n#if defined(LUA_COMPAT_MATHLIB)\n  {\"atan2\", math_atan},\n  {\"cosh\",   math_cosh},\n  {\"sinh\",   math_sinh},\n  {\"tanh\",   math_tanh},\n  {\"pow\",   math_pow},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n#endif\n  /* placeholders */\n  {\"pi\", NULL},\n  {\"huge\", NULL},\n  {\"maxinteger\", NULL},\n  {\"mininteger\", NULL},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUAMOD_API int luaopen_math (lua_State *L) {\n  luaL_newlib(L, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, (lua_Number)HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n  lua_pushinteger(L, LUA_MAXINTEGER);\n  lua_setfield(L, -2, \"maxinteger\");\n  lua_pushinteger(L, LUA_MININTEGER);\n  lua_setfield(L, -2, \"mininteger\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** ('osize' is the old size, 'nsize' is the new size)\n**\n** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no\n** matter 'x').\n**\n** * frealloc(ud, p, x, 0) frees the block 'p'\n** (in this specific case, frealloc must return NULL);\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ISO C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *what) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, \"too many %s (limit is %d)\", what, limit);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nl_noret luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  void *newblock;\n  global_State *g = G(L);\n  size_t realosize = (block) ? osize : 0;\n  lua_assert((realosize == 0) == (block == NULL));\n#if defined(HARDMEMTESTS)\n  if (nsize > realosize && g->gcrunning)\n    luaC_fullgc(L, 1);  /* force a GC whenever possible */\n#endif\n  newblock = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (newblock == NULL && nsize > 0) {\n    lua_assert(nsize > realosize);  /* cannot fail when shrinking a block */\n    if (g->version) {  /* is state fully built? */\n      luaC_fullgc(L, 1);  /* try to free some memory... */\n      newblock = (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */\n    }\n    if (newblock == NULL)\n      luaD_throw(L, LUA_ERRMEM);\n  }\n  lua_assert((nsize == 0) == (newblock == NULL));\n  g->GCdebt = (g->GCdebt + nsize) - realosize;\n  return newblock;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** This macro reallocs a vector 'b' from 'on' to 'n' elements, where\n** each element has size 'e'. In case of arithmetic overflow of the\n** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because\n** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e).\n**\n** (The macro is somewhat complex to avoid warnings:  The 'sizeof'\n** comparison avoids a runtime comparison when overflow cannot occur.\n** The compiler should be able to optimize the real test by itself, but\n** when it does it, it may give a warning about \"comparison is always\n** false due to limited range of data type\"; the +1 tricks the compiler,\n** avoiding this warning but also this optimization.)\n*/\n#define luaM_reallocv(L,b,on,n,e) \\\n  (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \\\n      ? luaM_toobig(L) : cast_void(0)) , \\\n   luaM_realloc_(L, (b), (on)*(e), (n)*(e)))\n\n/*\n** Arrays of chars do not need any test\n*/\n#define luaM_reallocvchar(L,b,on,n)  \\\n    cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n)   luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0)\n\n#define luaM_malloc(L,s)\tluaM_realloc_(L, NULL, 0, (s))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_newobject(L,tag,s)\tluaM_realloc_(L, NULL, tag, (s))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\nLUAI_FUNC l_noret luaM_toobig (lua_State *L);\n\n/* not to be called directly */\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *what);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.130.1.1 2017/04/19 17:20:42 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** unique key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const int CLIBS = 0;\n\n#define LIB_FAIL\t\"open\"\n\n\n#define setprogdir(L)           ((void)0)\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\n\n#undef setprogdir\n\n\n/*\n** Replace in the path (on the top of the stack) any occurrence\n** of LUA_EXEC_DIR with the executable's path.\n*/\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);  /* get exec. name */\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';  /* cut name on the last '\\\\' to get the path */\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** {==================================================================\n** Set Paths\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR    \"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR   \"LUA_CPATH\"\n#endif\n\n\n#define AUXMARK         \"\\1\"\t/* auxiliary mark */\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\n/*\n** Set a path\n*/\nstatic void setpath (lua_State *L, const char *fieldname,\n                                   const char *envname,\n                                   const char *dft) {\n  const char *nver = lua_pushfstring(L, \"%s%s\", envname, LUA_VERSUFFIX);\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(nver);  /* use versioned name */\n  if (path == NULL)  /* no environment variable? */\n    path = getenv(envname);  /* try unversioned name */\n#endif\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, dft);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,\n                              LUA_PATH_SEP AUXMARK LUA_PATH_SEP);\n    luaL_gsub(L, path, AUXMARK, dft);\n    lua_remove(L, -2); /* remove result from 1st 'gsub' */\n  }\n  setprogdir(L);\n  lua_setfield(L, -3, fieldname);  /* package[fieldname] = path value */\n  lua_pop(L, 1);  /* pop versioned variable name */\n}\n\n/* }================================================================== */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATH_SEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATH_SEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n                                     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file '%s'\", filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"\\n\\tno module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else\n      lua_pop(L, 2);  /* remove both returns */\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, 2, name);  /* LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_pushstring(L, name);  /* pass name as argument to module loader */\n  lua_insert(L, -2);  /* name is 1st argument (before search data) */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* LOADED[name] = returned value */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n#if defined(LUA_COMPAT_MODULE)\n\n/*\n** changes the environment variable of calling function\n*/\nstatic void set_env (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, \"'module' not called from a Lua function\");\n  lua_pushvalue(L, -2);  /* copy new environment table to top */\n  lua_setupvalue(L, -2, 1);\n  lua_pop(L, 1);  /* remove function */\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    if (lua_isfunction(L, i)) {  /* avoid 'calling' extra info. */\n      lua_pushvalue(L, i);  /* get option (a function) */\n      lua_pushvalue(L, -2);  /* module */\n      lua_call(L, 1, 0);\n    }\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = lua_gettop(L);  /* last parameter */\n  luaL_pushmodule(L, modname, 1);  /* get/create module table */\n  /* check whether table already has a _NAME field */\n  if (lua_getfield(L, -1, \"_NAME\") != LUA_TNIL)\n    lua_pop(L, 1);  /* table is an initialized module */\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  set_env(L);\n  dooptions(L, lastarg);\n  return 1;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushglobaltable(L);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n#endif\n/* }====================================================== */\n\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n#if defined(LUA_COMPAT_MODULE)\n  {\"seeall\", ll_seeall},\n#endif\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n#if defined(LUA_COMPAT_MODULE)\n  {\"module\", ll_module},\n#endif\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if defined(LUA_COMPAT_LOADERS)\n  lua_pushvalue(L, -1);  /* make a copy of 'searchers' table */\n  lua_setfield(L, -3, \"loaders\");  /* put it in field 'loaders' */\n#endif\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  lua_newtable(L);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n  lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS);  /* set CLIBS table in registry */\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set paths */\n  setpath(L, \"path\", LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  setpath(L, \"cpath\", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.113.1.1 2017/04/19 17:29:57 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nLUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* exponent */\n  if (x < 8) return x;\n  while (x >= (8 << 4)) {  /* coarse steps */\n    x = (x + 0xf) >> 4;  /* x = ceil(x / 16) */\n    e += 4;\n  }\n  while (x >= (8 << 1)) {  /* fine steps */\n    x = (x + 1) >> 1;  /* x = ceil(x / 2) */\n    e++;\n  }\n  return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);\n}\n\n\n/*\n** Computes ceil(log2(x))\n*/\nint luaO_ceillog2 (unsigned int x) {\n  static const lu_byte log_2[256] = {  /* log_2[i] = ceil(log2(i - 1)) */\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = 0;\n  x--;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n}\n\n\nstatic lua_Integer intarith (lua_State *L, int op, lua_Integer v1,\n                                                   lua_Integer v2) {\n  switch (op) {\n    case LUA_OPADD: return intop(+, v1, v2);\n    case LUA_OPSUB:return intop(-, v1, v2);\n    case LUA_OPMUL:return intop(*, v1, v2);\n    case LUA_OPMOD: return luaV_mod(L, v1, v2);\n    case LUA_OPIDIV: return luaV_div(L, v1, v2);\n    case LUA_OPBAND: return intop(&, v1, v2);\n    case LUA_OPBOR: return intop(|, v1, v2);\n    case LUA_OPBXOR: return intop(^, v1, v2);\n    case LUA_OPSHL: return luaV_shiftl(v1, v2);\n    case LUA_OPSHR: return luaV_shiftl(v1, -v2);\n    case LUA_OPUNM: return intop(-, 0, v1);\n    case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lua_Number numarith (lua_State *L, int op, lua_Number v1,\n                                                  lua_Number v2) {\n  switch (op) {\n    case LUA_OPADD: return luai_numadd(L, v1, v2);\n    case LUA_OPSUB: return luai_numsub(L, v1, v2);\n    case LUA_OPMUL: return luai_nummul(L, v1, v2);\n    case LUA_OPDIV: return luai_numdiv(L, v1, v2);\n    case LUA_OPPOW: return luai_numpow(L, v1, v2);\n    case LUA_OPIDIV: return luai_numidiv(L, v1, v2);\n    case LUA_OPUNM: return luai_numunm(L, v1);\n    case LUA_OPMOD: {\n      lua_Number m;\n      luai_nummod(L, v1, v2, m);\n      return m;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                 TValue *res) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR:\n    case LUA_OPBNOT: {  /* operate only on integers */\n      lua_Integer i1; lua_Integer i2;\n      if (tointeger(p1, &i1) && tointeger(p2, &i2)) {\n        setivalue(res, intarith(L, op, i1, i2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    case LUA_OPDIV: case LUA_OPPOW: {  /* operate only on floats */\n      lua_Number n1; lua_Number n2;\n      if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n    default: {  /* other operations */\n      lua_Number n1; lua_Number n2;\n      if (ttisinteger(p1) && ttisinteger(p2)) {\n        setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));\n        return;\n      }\n      else if (tonumber(p1, &n1) && tonumber(p2, &n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return;\n      }\n      else break;  /* go to the end */\n    }\n  }\n  /* could not perform raw operation; try metamethod */\n  lua_assert(L != NULL);  /* should not fail when folding (compile time) */\n  luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));\n}\n\n\nint luaO_hexavalue (int c) {\n  if (lisdigit(c)) return c - '0';\n  else return (ltolower(c) - 'a') + 10;\n}\n\n\nstatic int isneg (const char **s) {\n  if (**s == '-') { (*s)++; return 1; }\n  else if (**s == '+') (*s)++;\n  return 0;\n}\n\n\n\n/*\n** {==================================================================\n** Lua's implementation for 'lua_strx2number'\n** ===================================================================\n*/\n\n#if !defined(lua_strx2number)\n\n/* maximum number of significant digits to read (to avoid overflows\n   even with single floats) */\n#define MAXSIGDIG\t30\n\n/*\n** convert an hexadecimal numeric string to a number, following\n** C99 specification for 'strtod'\n*/\nstatic lua_Number lua_strx2number (const char *s, char **endptr) {\n  int dot = lua_getlocaledecpoint();\n  lua_Number r = 0.0;  /* result (accumulator) */\n  int sigdig = 0;  /* number of significant digits */\n  int nosigdig = 0;  /* number of non-significant digits */\n  int e = 0;  /* exponent correction */\n  int neg;  /* 1 if number is negative */\n  int hasdot = 0;  /* true after seen a dot */\n  *endptr = cast(char *, s);  /* nothing is valid yet */\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);  /* check signal */\n  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */\n    return 0.0;  /* invalid format (no '0x') */\n  for (s += 2; ; s++) {  /* skip '0x' and read numeral */\n    if (*s == dot) {\n      if (hasdot) break;  /* second dot? stop loop */\n      else hasdot = 1;\n    }\n    else if (lisxdigit(cast_uchar(*s))) {\n      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */\n        nosigdig++;\n      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */\n          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);\n      else e++; /* too many digits; ignore, but still count for exponent */\n      if (hasdot) e--;  /* decimal digit? correct exponent */\n    }\n    else break;  /* neither a dot nor a digit */\n  }\n  if (nosigdig + sigdig == 0)  /* no digits? */\n    return 0.0;  /* invalid format */\n  *endptr = cast(char *, s);  /* valid up to here */\n  e *= 4;  /* each digit multiplies/divides value by 2^4 */\n  if (*s == 'p' || *s == 'P') {  /* exponent part? */\n    int exp1 = 0;  /* exponent value */\n    int neg1;  /* exponent signal */\n    s++;  /* skip 'p' */\n    neg1 = isneg(&s);  /* signal */\n    if (!lisdigit(cast_uchar(*s)))\n      return 0.0;  /* invalid; must have at least one digit */\n    while (lisdigit(cast_uchar(*s)))  /* read exponent */\n      exp1 = exp1 * 10 + *(s++) - '0';\n    if (neg1) exp1 = -exp1;\n    e += exp1;\n    *endptr = cast(char *, s);  /* valid up to here */\n  }\n  if (neg) r = -r;\n  return l_mathop(ldexp)(r, e);\n}\n\n#endif\n/* }====================================================== */\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM\t200\n#endif\n\nstatic const char *l_str2dloc (const char *s, lua_Number *result, int mode) {\n  char *endptr;\n  *result = (mode == 'x') ? lua_strx2number(s, &endptr)  /* try to convert */\n                          : lua_str2number(s, &endptr);\n  if (endptr == s) return NULL;  /* nothing recognized? */\n  while (lisspace(cast_uchar(*endptr))) endptr++;  /* skip trailing spaces */\n  return (*endptr == '\\0') ? endptr : NULL;  /* OK if no trailing characters */\n}\n\n\n/*\n** Convert string 's' to a Lua number (put in 'result'). Return NULL\n** on fail or the address of the ending '\\0' on success.\n** 'pmode' points to (and 'mode' contains) special things in the string:\n** - 'x'/'X' means an hexadecimal numeral\n** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)\n** - '.' just optimizes the search for the common case (nothing special)\n** This function accepts both the current locale or a dot as the radix\n** mark. If the convertion fails, it may mean number has a dot but\n** locale accepts something else. In that case, the code copies 's'\n** to a buffer (because 's' is read-only), changes the dot to the\n** current locale radix mark, and tries to convert again.\n*/\nstatic const char *l_str2d (const char *s, lua_Number *result) {\n  const char *endptr;\n  const char *pmode = strpbrk(s, \".xXnN\");\n  int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;\n  if (mode == 'n')  /* reject 'inf' and 'nan' */\n    return NULL;\n  endptr = l_str2dloc(s, result, mode);  /* try to convert */\n  if (endptr == NULL) {  /* failed? may be a different locale */\n    char buff[L_MAXLENNUM + 1];\n    const char *pdot = strchr(s, '.');\n    if (strlen(s) > L_MAXLENNUM || pdot == NULL)\n      return NULL;  /* string too long or no dot; fail */\n    strcpy(buff, s);  /* copy string to buffer */\n    buff[pdot - s] = lua_getlocaledecpoint();  /* correct decimal point */\n    endptr = l_str2dloc(buff, result, mode);  /* try again */\n    if (endptr != NULL)\n      endptr = s + (endptr - buff);  /* make relative to 's' */\n  }\n  return endptr;\n}\n\n\n#define MAXBY10\t\tcast(lua_Unsigned, LUA_MAXINTEGER / 10)\n#define MAXLASTD\tcast_int(LUA_MAXINTEGER % 10)\n\nstatic const char *l_str2int (const char *s, lua_Integer *result) {\n  lua_Unsigned a = 0;\n  int empty = 1;\n  int neg;\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);\n  if (s[0] == '0' &&\n      (s[1] == 'x' || s[1] == 'X')) {  /* hex? */\n    s += 2;  /* skip '0x' */\n    for (; lisxdigit(cast_uchar(*s)); s++) {\n      a = a * 16 + luaO_hexavalue(*s);\n      empty = 0;\n    }\n  }\n  else {  /* decimal */\n    for (; lisdigit(cast_uchar(*s)); s++) {\n      int d = *s - '0';\n      if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg))  /* overflow? */\n        return NULL;  /* do not accept it (as integer) */\n      a = a * 10 + d;\n      empty = 0;\n    }\n  }\n  while (lisspace(cast_uchar(*s))) s++;  /* skip trailing spaces */\n  if (empty || *s != '\\0') return NULL;  /* something wrong in the numeral */\n  else {\n    *result = l_castU2S((neg) ? 0u - a : a);\n    return s;\n  }\n}\n\n\nsize_t luaO_str2num (const char *s, TValue *o) {\n  lua_Integer i; lua_Number n;\n  const char *e;\n  if ((e = l_str2int(s, &i)) != NULL) {  /* try as an integer */\n    setivalue(o, i);\n  }\n  else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */\n    setfltvalue(o, n);\n  }\n  else\n    return 0;  /* conversion failed */\n  return (e - s) + 1;  /* success; return string size */\n}\n\n\nint luaO_utf8esc (char *buff, unsigned long x) {\n  int n = 1;  /* number of bytes put in buffer (backwards) */\n  lua_assert(x <= 0x10FFFF);\n  if (x < 0x80)  /* ascii? */\n    buff[UTF8BUFFSZ - 1] = cast(char, x);\n  else {  /* need continuation bytes */\n    unsigned int mfb = 0x3f;  /* maximum that fits in first byte */\n    do {  /* add continuation bytes */\n      buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));\n      x >>= 6;  /* remove added bits */\n      mfb >>= 1;  /* now there is one less bit available in first byte */\n    } while (x > mfb);  /* still needs continuation byte? */\n    buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x);  /* add first byte */\n  }\n  return n;\n}\n\n\n/* maximum length of the conversion of a number to a string */\n#define MAXNUMBER2STR\t50\n\n\n/*\n** Convert a number object to a string\n*/\nvoid luaO_tostring (lua_State *L, StkId obj) {\n  char buff[MAXNUMBER2STR];\n  size_t len;\n  lua_assert(ttisnumber(obj));\n  if (ttisinteger(obj))\n    len = lua_integer2str(buff, sizeof(buff), ivalue(obj));\n  else {\n    len = lua_number2str(buff, sizeof(buff), fltvalue(obj));\n#if !defined(LUA_COMPAT_FLOATSTRING)\n    if (buff[strspn(buff, \"-0123456789\")] == '\\0') {  /* looks like an int? */\n      buff[len++] = lua_getlocaledecpoint();\n      buff[len++] = '0';  /* adds '.0' to result */\n    }\n#endif\n  }\n  setsvalue2s(L, obj, luaS_newlstr(L, buff, len));\n}\n\n\nstatic void pushstr (lua_State *L, const char *str, size_t l) {\n  setsvalue2s(L, L->top, luaS_newlstr(L, str, l));\n  luaD_inctop(L);\n}\n\n\n/*\n** this function handles only '%d', '%c', '%f', '%p', and '%s'\n   conventional formats, plus Lua-specific '%I' and '%U'\n*/\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 0;\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    pushstr(L, fmt, e - fmt);\n    switch (*(e+1)) {\n      case 's': {  /* zero-terminated string */\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s, strlen(s));\n        break;\n      }\n      case 'c': {  /* an 'int' as a character */\n        char buff = cast(char, va_arg(argp, int));\n        if (lisprint(cast_uchar(buff)))\n          pushstr(L, &buff, 1);\n        else  /* non-printable character; print its code */\n          luaO_pushfstring(L, \"<\\\\%d>\", cast_uchar(buff));\n        break;\n      }\n      case 'd': {  /* an 'int' */\n        setivalue(L->top, va_arg(argp, int));\n        goto top2str;\n      }\n      case 'I': {  /* a 'lua_Integer' */\n        setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));\n        goto top2str;\n      }\n      case 'f': {  /* a 'lua_Number' */\n        setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n      top2str:  /* convert the top element to a string */\n        luaD_inctop(L);\n        luaO_tostring(L, L->top - 1);\n        break;\n      }\n      case 'p': {  /* a pointer */\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */\n        void *p = va_arg(argp, void *);\n        int l = lua_pointer2str(buff, sizeof(buff), p);\n        pushstr(L, buff, l);\n        break;\n      }\n      case 'U': {  /* an 'int' as a UTF-8 sequence */\n        char buff[UTF8BUFFSZ];\n        int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));\n        pushstr(L, buff + UTF8BUFFSZ - l, l);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\", 1);\n        break;\n      }\n      default: {\n        luaG_runerror(L, \"invalid option '%%%c' to 'lua_pushfstring'\",\n                         *(e + 1));\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  luaD_checkstack(L, 1);\n  pushstr(L, fmt, strlen(fmt));\n  if (n > 0) luaV_concat(L, n + 1);\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\n/* number of chars of a literal string without the ending \\0 */\n#define LL(x)\t(sizeof(x)/sizeof(char) - 1)\n\n#define RETS\t\"...\"\n#define PRE\t\"[string \\\"\"\n#define POS\t\"\\\"]\"\n\n#define addstr(a,b,l)\t( memcpy(a,b,(l) * sizeof(char)), a += (l) )\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  size_t l = strlen(source);\n  if (*source == '=') {  /* 'literal' source */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* truncate it */\n      addstr(out, source + 1, bufflen - 1);\n      *out = '\\0';\n    }\n  }\n  else if (*source == '@') {  /* file name */\n    if (l <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, l * sizeof(char));\n    else {  /* add '...' before rest of name */\n      addstr(out, RETS, LL(RETS));\n      bufflen -= LL(RETS);\n      memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));\n    }\n  }\n  else {  /* string; format as [string \"source\"] */\n    const char *nl = strchr(source, '\\n');  /* find first new line (if any) */\n    addstr(out, PRE, LL(PRE));  /* add prefix */\n    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\\0' */\n    if (l < bufflen && nl == NULL) {  /* small one-line source? */\n      addstr(out, source, l);  /* keep it */\n    }\n    else {\n      if (nl != NULL) l = nl - source;  /* stop at first newline */\n      if (l > bufflen) l = bufflen;\n      addstr(out, source, l);\n      addstr(out, RETS, LL(RETS));\n    }\n    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.117.1.1 2017/04/19 17:39:34 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\tLUA_NUMTAGS\t\t/* function prototypes */\n#define LUA_TDEADKEY\t(LUA_NUMTAGS+1)\t\t/* removed keys in tables */\n\n/*\n** number of all possible tags (including LUA_TNONE but excluding DEADKEY)\n*/\n#define LUA_TOTALTAGS\t(LUA_TPROTO + 2)\n\n\n/*\n** tags for Tagged Values have the following use of bits:\n** bits 0-3: actual tag (a LUA_T* value)\n** bits 4-5: variant bits\n** bit 6: whether value is collectable\n*/\n\n\n/*\n** LUA_TFUNCTION variants:\n** 0 - Lua function\n** 1 - light C function\n** 2 - regular C function (closure)\n*/\n\n/* Variant tags for functions */\n#define LUA_TLCL\t(LUA_TFUNCTION | (0 << 4))  /* Lua closure */\n#define LUA_TLCF\t(LUA_TFUNCTION | (1 << 4))  /* light C function */\n#define LUA_TCCL\t(LUA_TFUNCTION | (2 << 4))  /* C closure */\n\n\n/* Variant tags for strings */\n#define LUA_TSHRSTR\t(LUA_TSTRING | (0 << 4))  /* short strings */\n#define LUA_TLNGSTR\t(LUA_TSTRING | (1 << 4))  /* long strings */\n\n\n/* Variant tags for numbers */\n#define LUA_TNUMFLT\t(LUA_TNUMBER | (0 << 4))  /* float numbers */\n#define LUA_TNUMINT\t(LUA_TNUMBER | (1 << 4))  /* integer numbers */\n\n\n/* Bit mark for collectable types */\n#define BIT_ISCOLLECTABLE\t(1 << 6)\n\n/* mark a tag as collectable */\n#define ctb(t)\t\t\t((t) | BIT_ISCOLLECTABLE)\n\n\n/*\n** Common type for all collectable objects\n*/\ntypedef struct GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common type has only the common header\n*/\nstruct GCObject {\n  CommonHeader;\n};\n\n\n\n\n/*\n** Tagged Values. This is the basic representation of values in Lua,\n** an actual value plus a tag with its type.\n*/\n\n/*\n** Union of all Lua values\n*/\ntypedef union Value {\n  GCObject *gc;    /* collectable objects */\n  void *p;         /* light userdata */\n  int b;           /* booleans */\n  lua_CFunction f; /* light C functions */\n  lua_Integer i;   /* integer numbers */\n  lua_Number n;    /* float numbers */\n} Value;\n\n\n#define TValuefields\tValue value_; int tt_\n\n\ntypedef struct lua_TValue {\n  TValuefields;\n} TValue;\n\n\n\n/* macro defining a nil value */\n#define NILCONSTANT\t{NULL}, LUA_TNIL\n\n\n#define val_(o)\t\t((o)->value_)\n\n\n/* raw type tag of a TValue */\n#define rttype(o)\t((o)->tt_)\n\n/* tag with no variants (bits 0-3) */\n#define novariant(x)\t((x) & 0x0F)\n\n/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */\n#define ttype(o)\t(rttype(o) & 0x3F)\n\n/* type tag of a TValue with no variants (bits 0-3) */\n#define ttnov(o)\t(novariant(rttype(o)))\n\n\n/* Macros to test type */\n#define checktag(o,t)\t\t(rttype(o) == (t))\n#define checktype(o,t)\t\t(ttnov(o) == (t))\n#define ttisnumber(o)\t\tchecktype((o), LUA_TNUMBER)\n#define ttisfloat(o)\t\tchecktag((o), LUA_TNUMFLT)\n#define ttisinteger(o)\t\tchecktag((o), LUA_TNUMINT)\n#define ttisnil(o)\t\tchecktag((o), LUA_TNIL)\n#define ttisboolean(o)\t\tchecktag((o), LUA_TBOOLEAN)\n#define ttislightuserdata(o)\tchecktag((o), LUA_TLIGHTUSERDATA)\n#define ttisstring(o)\t\tchecktype((o), LUA_TSTRING)\n#define ttisshrstring(o)\tchecktag((o), ctb(LUA_TSHRSTR))\n#define ttislngstring(o)\tchecktag((o), ctb(LUA_TLNGSTR))\n#define ttistable(o)\t\tchecktag((o), ctb(LUA_TTABLE))\n#define ttisfunction(o)\t\tchecktype(o, LUA_TFUNCTION)\n#define ttisclosure(o)\t\t((rttype(o) & 0x1F) == LUA_TFUNCTION)\n#define ttisCclosure(o)\t\tchecktag((o), ctb(LUA_TCCL))\n#define ttisLclosure(o)\t\tchecktag((o), ctb(LUA_TLCL))\n#define ttislcf(o)\t\tchecktag((o), LUA_TLCF)\n#define ttisfulluserdata(o)\tchecktag((o), ctb(LUA_TUSERDATA))\n#define ttisthread(o)\t\tchecktag((o), ctb(LUA_TTHREAD))\n#define ttisdeadkey(o)\t\tchecktag((o), LUA_TDEADKEY)\n\n\n/* Macros to access values */\n#define ivalue(o)\tcheck_exp(ttisinteger(o), val_(o).i)\n#define fltvalue(o)\tcheck_exp(ttisfloat(o), val_(o).n)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), \\\n\t(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))\n#define gcvalue(o)\tcheck_exp(iscollectable(o), val_(o).gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), val_(o).p)\n#define tsvalue(o)\tcheck_exp(ttisstring(o), gco2ts(val_(o).gc))\n#define uvalue(o)\tcheck_exp(ttisfulluserdata(o), gco2u(val_(o).gc))\n#define clvalue(o)\tcheck_exp(ttisclosure(o), gco2cl(val_(o).gc))\n#define clLvalue(o)\tcheck_exp(ttisLclosure(o), gco2lcl(val_(o).gc))\n#define clCvalue(o)\tcheck_exp(ttisCclosure(o), gco2ccl(val_(o).gc))\n#define fvalue(o)\tcheck_exp(ttislcf(o), val_(o).f)\n#define hvalue(o)\tcheck_exp(ttistable(o), gco2t(val_(o).gc))\n#define bvalue(o)\tcheck_exp(ttisboolean(o), val_(o).b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), gco2th(val_(o).gc))\n/* a dead value may get the 'gc' field, but cannot access its contents */\n#define deadvalue(o)\tcheck_exp(ttisdeadkey(o), cast(void *, val_(o).gc))\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n\n#define iscollectable(o)\t(rttype(o) & BIT_ISCOLLECTABLE)\n\n\n/* Macros for internal tests */\n#define righttt(obj)\t\t(ttype(obj) == gcvalue(obj)->tt)\n\n#define checkliveness(L,obj) \\\n\tlua_longassert(!iscollectable(obj) || \\\n\t\t(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))\n\n\n/* Macros to set values */\n#define settt_(o,t)\t((o)->tt_=(t))\n\n#define setfltvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }\n\n#define chgfltvalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }\n\n#define setivalue(obj,x) \\\n  { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }\n\n#define chgivalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }\n\n#define setnilvalue(obj) settt_(obj, LUA_TNIL)\n\n#define setfvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }\n\n#define setpvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }\n\n#define setbvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }\n\n#define setgcovalue(L,obj,x) \\\n  { TValue *io = (obj); GCObject *i_g=(x); \\\n    val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }\n\n#define setsvalue(L,obj,x) \\\n  { TValue *io = (obj); TString *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \\\n    checkliveness(L,io); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *io = (obj); Udata *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \\\n    checkliveness(L,io); }\n\n#define setthvalue(L,obj,x) \\\n  { TValue *io = (obj); lua_State *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \\\n    checkliveness(L,io); }\n\n#define setclLvalue(L,obj,x) \\\n  { TValue *io = (obj); LClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \\\n    checkliveness(L,io); }\n\n#define setclCvalue(L,obj,x) \\\n  { TValue *io = (obj); CClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \\\n    checkliveness(L,io); }\n\n#define sethvalue(L,obj,x) \\\n  { TValue *io = (obj); Table *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \\\n    checkliveness(L,io); }\n\n#define setdeadvalue(obj)\tsettt_(obj, LUA_TDEADKEY)\n\n\n\n#define setobj(L,obj1,obj2) \\\n\t{ TValue *io1=(obj1); *io1 = *(obj2); \\\n\t  (void)L; checkliveness(L,io1); }\n\n\n/*\n** different types of assignments, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n/* to table (define it as an expression to be used in macros) */\n#define setobj2t(L,o1,o2)  ((void)L, *(o1)=*(o2), checkliveness(L,(o1)))\n\n\n\n\n/*\n** {======================================================\n** types and prototypes\n** =======================================================\n*/\n\n\ntypedef TValue *StkId;  /* index to stack elements */\n\n\n\n\n/*\n** Header for string value; string bytes follow the end of this structure\n** (aligned according to 'UTString'; see next).\n*/\ntypedef struct TString {\n  CommonHeader;\n  lu_byte extra;  /* reserved words for short strings; \"has hash\" for longs */\n  lu_byte shrlen;  /* length for short strings */\n  unsigned int hash;\n  union {\n    size_t lnglen;  /* length for long strings */\n    struct TString *hnext;  /* linked list for hash table */\n  } u;\n} TString;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UTString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  TString tsv;\n} UTString;\n\n\n/*\n** Get the actual string (array of bytes) from a 'TString'.\n** (Access to 'extra' ensures that value is really a 'TString'.)\n*/\n#define getstr(ts)  \\\n  check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))\n\n\n/* get the actual string (array of bytes) from a Lua value */\n#define svalue(o)       getstr(tsvalue(o))\n\n/* get string length from 'TString *s' */\n#define tsslen(s)\t((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)\n\n/* get string length from 'TValue *o' */\n#define vslen(o)\ttsslen(tsvalue(o))\n\n\n/*\n** Header for userdata; memory area follows the end of this structure\n** (aligned according to 'UUdata'; see next).\n*/\ntypedef struct Udata {\n  CommonHeader;\n  lu_byte ttuv_;  /* user value's tag */\n  struct Table *metatable;\n  size_t len;  /* number of bytes */\n  union Value user_;  /* user value */\n} Udata;\n\n\n/*\n** Ensures that address after this type is always fully aligned.\n*/\ntypedef union UUdata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for 'local' udata */\n  Udata uv;\n} UUdata;\n\n\n/*\n**  Get the address of memory block inside 'Udata'.\n** (Access to 'ttuv_' ensures that value is really a 'Udata'.)\n*/\n#define getudatamem(u)  \\\n  check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata)))\n\n#define setuservalue(L,u,o) \\\n\t{ const TValue *io=(o); Udata *iu = (u); \\\n\t  iu->user_ = io->value_; iu->ttuv_ = rttype(io); \\\n\t  checkliveness(L,io); }\n\n\n#define getuservalue(L,u,o) \\\n\t{ TValue *io=(o); const Udata *iu = (u); \\\n\t  io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n\t  checkliveness(L,io); }\n\n\n/*\n** Description of an upvalue for function prototypes\n*/\ntypedef struct Upvaldesc {\n  TString *name;  /* upvalue name (for debug information) */\n  lu_byte instack;  /* whether it is in stack (register) */\n  lu_byte idx;  /* index of upvalue (in stack or in outer function's list) */\n} Upvaldesc;\n\n\n/*\n** Description of a local variable for function prototypes\n** (used for debug information)\n*/\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  lu_byte numparams;  /* number of fixed parameters */\n  lu_byte is_vararg;\n  lu_byte maxstacksize;  /* number of registers needed by this function */\n  int sizeupvalues;  /* size of 'upvalues' */\n  int sizek;  /* size of 'k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of 'p' */\n  int sizelocvars;\n  int linedefined;  /* debug information  */\n  int lastlinedefined;  /* debug information  */\n  TValue *k;  /* constants used by the function */\n  Instruction *code;  /* opcodes */\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines (debug information) */\n  LocVar *locvars;  /* information about local variables (debug information) */\n  Upvaldesc *upvalues;  /* upvalue information */\n  struct LClosure *cache;  /* last-created closure with this prototype */\n  TString  *source;  /* used for debug information */\n  GCObject *gclist;\n} Proto;\n\n\n\n/*\n** Lua Upvalues\n*/\ntypedef struct UpVal UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte nupvalues; GCObject *gclist\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];  /* list of upvalues */\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];  /* list of upvalues */\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define isLfunction(o)\tttisLclosure(o)\n\n#define getproto(o)\t(clLvalue(o)->p)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    int next;  /* for chaining (offset for next node) */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\n/* copy a value into a key without messing up field 'next' */\n#define setnodekey(L,key,obj) \\\n\t{ TKey *k_=(key); const TValue *io_=(obj); \\\n\t  k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \\\n\t  (void)L; checkliveness(L,io_); }\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */\n  lu_byte lsizenode;  /* log2 of size of 'node' array */\n  unsigned int sizearray;  /* size of 'array' array */\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  struct Table *metatable;\n  GCObject *gclist;\n} Table;\n\n\n\n/*\n** 'module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n/*\n** (address of) a fixed nil value\n*/\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\n\nLUAI_DDEC const TValue luaO_nilobject_;\n\n/* size of buffer for 'luaO_utf8esc' function */\n#define UTF8BUFFSZ\t8\n\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);\nLUAI_FUNC int luaO_ceillog2 (unsigned int x);\nLUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,\n                           const TValue *p2, TValue *res);\nLUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);\nLUAI_FUNC int luaO_hexavalue (int c);\nLUAI_FUNC void luaO_tostring (lua_State *L, StkId obj);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.55.1.1 2017/04/19 17:20:42 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lopcodes_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nLUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADKX\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETTABUP\",\n  \"GETTABLE\",\n  \"SETTABUP\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"MOD\",\n  \"POW\",\n  \"DIV\",\n  \"IDIV\",\n  \"BAND\",\n  \"BOR\",\n  \"BXOR\",\n  \"SHL\",\n  \"SHR\",\n  \"UNM\",\n  \"BNOT\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORCALL\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSURE\",\n  \"VARARG\",\n  \"EXTRAARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nLUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgN, OpArgN, iABx)\t\t/* OP_LOADKX */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgU, OpArgK, iABC)\t\t/* OP_GETTABUP */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABUP */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_IDIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BAND */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_BXOR */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SHR */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_BNOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(0, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORCALL */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n ,opmode(0, 0, OpArgU, OpArgU, iAx)\t\t/* OP_EXTRAARG */\n};\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.149.1.1 2017/04/19 17:20:42 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t'A' : 8 bits\n\t'B' : 9 bits\n\t'C' : 9 bits\n\t'Ax' : 26 bits ('A', 'B', and 'C' together)\n\t'Bx' : 18 bits ('B' and 'C' together)\n\t'sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx, iAx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n#define SIZE_Ax\t\t(SIZE_C + SIZE_B + SIZE_A)\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n#define POS_Ax\t\tPOS_A\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* 'sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n#if SIZE_Ax < LUAI_BITSINT-1\n#define MAXARG_Ax\t((1<<SIZE_Ax)-1)\n#else\n#define MAXARG_Ax\tMAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with 'n' 1 bits at position 'p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<(n)))<<(p))\n\n/* creates a mask with 'n' 0 bits at position 'p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define getarg(i,pos,size)\t(cast(int, ((i)>>pos) & MASK1(size,0)))\n#define setarg(i,v,pos,size)\t((i) = (((i)&MASK0(size,pos)) | \\\n                ((cast(Instruction, v)<<pos)&MASK1(size,pos))))\n\n#define GETARG_A(i)\tgetarg(i, POS_A, SIZE_A)\n#define SETARG_A(i,v)\tsetarg(i, v, POS_A, SIZE_A)\n\n#define GETARG_B(i)\tgetarg(i, POS_B, SIZE_B)\n#define SETARG_B(i,v)\tsetarg(i, v, POS_B, SIZE_B)\n\n#define GETARG_C(i)\tgetarg(i, POS_C, SIZE_C)\n#define SETARG_C(i,v)\tsetarg(i, v, POS_C, SIZE_C)\n\n#define GETARG_Bx(i)\tgetarg(i, POS_Bx, SIZE_Bx)\n#define SETARG_Bx(i,v)\tsetarg(i, v, POS_Bx, SIZE_Bx)\n\n#define GETARG_Ax(i)\tgetarg(i, POS_Ax, SIZE_Ax)\n#define SETARG_Ax(i,v)\tsetarg(i, v, POS_Ax, SIZE_Ax)\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n#define CREATE_Ax(o,a)\t\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_Ax))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#if !defined(MAXINDEXRK)  /* (for debugging only) */\n#define MAXINDEXRK\t(BITRK - 1)\n#endif\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADKX,/*\tA \tR(A) := Kst(extra arg)\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A), R(A+1), ..., R(A+B) := nil\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETTABUP,/*\tA B C\tR(A) := UpValue[B][RK(C)]\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETTABUP,/*\tA B C\tUpValue[A][RK(B)] := RK(C)\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_IDIV,/*\tA B C\tR(A) := RK(B) // RK(C)\t\t\t\t*/\nOP_BAND,/*\tA B C\tR(A) := RK(B) & RK(C)\t\t\t\t*/\nOP_BOR,/*\tA B C\tR(A) := RK(B) | RK(C)\t\t\t\t*/\nOP_BXOR,/*\tA B C\tR(A) := RK(B) ~ RK(C)\t\t\t\t*/\nOP_SHL,/*\tA B C\tR(A) := RK(B) << RK(C)\t\t\t\t*/\nOP_SHR,/*\tA B C\tR(A) := RK(B) >> RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_BNOT,/*\tA B\tR(A) := ~R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tA sBx\tpc+=sBx; if (A) close all upvalues >= R(A - 1)\t*/\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++\t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++\t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/\nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/\n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORCALL,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));\t*/\nOP_TFORLOOP,/*\tA sBx\tif R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/\n\nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx])\t\t\t*/\n\nOP_VARARG,/*\tA B\tR(A), R(A+1), ..., R(A+B-2) = vararg\t\t*/\n\nOP_EXTRAARG/*\tAx\textra (larger) argument for previous opcode\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_EXTRAARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is\n  set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,\n  OP_SETLIST) may use 'top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n  set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to 'top'.\n\n  (*) In OP_SETLIST, if (B == 0) then B = 'top'; if (C == 0) then next\n  'instruction' is EXTRAARG(real C).\n\n  (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.\n\n  (*) For comparisons, A specifies what condition the test should accept\n  (true or false).\n\n  (*) All 'skips' (pc++) assume that next instruction is a jump.\n\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test (next instruction must be a jump)\n*/\n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.65.1.1 2017/04/19 17:29:57 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** {==================================================================\n** List of valid conversion specifiers for the 'strftime' function;\n** options are grouped by length; group of length 2 start with '||'.\n** ===================================================================\n*/\n#if !defined(LUA_STRFTIMEOPTIONS)\t/* { */\n\n/* options for ANSI C 89 (only 1-char options) */\n#define L_STRFTIMEC89\t\t\"aAbBcdHIjmMpSUwWxXyYZ%\"\n\n/* options for ISO C 99 and POSIX */\n#define L_STRFTIMEC99 \"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%\" \\\n    \"||\" \"EcECExEXEyEY\" \"OdOeOHOIOmOMOSOuOUOVOwOWOy\"  /* two-char options */\n\n/* options for Windows */\n#define L_STRFTIMEWIN \"aAbBcdHIjmMpSUwWxXyYzZ%\" \\\n    \"||\" \"#c#x#d#H#I#j#m#M#S#U#w#W#y#Y\"  /* two-char options */\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEWIN\n#elif defined(LUA_USE_C89)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC89\n#else  /* C99 specification */\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC99\n#endif\n\n#endif\t\t\t\t\t/* } */\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for time-related stuff\n** ===================================================================\n*/\n\n#if !defined(l_time_t)\t\t/* { */\n/*\n** type to represent time_t in Lua\n*/\n#define l_timet\t\t\tlua_Integer\n#define l_pushtime(L,t)\t\tlua_pushinteger(L,(lua_Integer)(t))\n\nstatic time_t l_checktime (lua_State *L, int arg) {\n  lua_Integer t = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, (time_t)t == t, arg, \"time out-of-bounds\");\n  return (time_t)t;\n}\n\n#endif\t\t\t\t/* } */\n\n\n#if !defined(l_gmtime)\t\t/* { */\n/*\n** By default, Lua uses gmtime/localtime, except when POSIX is available,\n** where it uses gmtime_r/localtime_r\n*/\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_gmtime(t,r)\t\tgmtime_r(t,r)\n#define l_localtime(t,r)\tlocaltime_r(t,r)\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_gmtime(t,r)\t\t((void)(r)->tm_sec, gmtime(t))\n#define l_localtime(t,r)  \t((void)(r)->tm_sec, localtime(t))\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for 'tmpnam':\n** By default, Lua uses tmpnam except when POSIX is available, where\n** it uses mkstemp.\n** ===================================================================\n*/\n#if !defined(lua_tmpnam)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n\n#define LUA_TMPNAMBUFSIZE\t32\n\n#if !defined(LUA_TMPNAMTEMPLATE)\n#define LUA_TMPNAMTEMPLATE\t\"/tmp/lua_XXXXXX\"\n#endif\n\n#define lua_tmpnam(b,e) { \\\n        strcpy(b, LUA_TMPNAMTEMPLATE); \\\n        e = mkstemp(b); \\\n        if (e != -1) close(e); \\\n        e = (e == -1); }\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n/* }================================================================== */\n\n\n\n\n//static int os_execute (lua_State *L) {\n//  const char *cmd = luaL_optstring(L, 1, NULL);\n//  int stat = system(cmd);\n//  if (cmd != NULL)\n//    return luaL_execresult(L, stat);\n//  else {\n//    lua_pushboolean(L, stat);  /* true if there is a shell */\n//    return 1;\n//  }\n//}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\n\n/*\n** Set all fields from structure 'tm' in the table on top of the stack\n*/\nstatic void setallfields (lua_State *L, struct tm *stm) {\n  setfield(L, \"sec\", stm->tm_sec);\n  setfield(L, \"min\", stm->tm_min);\n  setfield(L, \"hour\", stm->tm_hour);\n  setfield(L, \"day\", stm->tm_mday);\n  setfield(L, \"month\", stm->tm_mon + 1);\n  setfield(L, \"year\", stm->tm_year + 1900);\n  setfield(L, \"wday\", stm->tm_wday + 1);\n  setfield(L, \"yday\", stm->tm_yday + 1);\n  setboolfield(L, \"isdst\", stm->tm_isdst);\n}\n\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\n/* maximum value for date fields (to avoid arithmetic overflows with 'int') */\n#if !defined(L_MAXDATEFIELD)\n#define L_MAXDATEFIELD\t(INT_MAX / 2)\n#endif\n\nstatic int getfield (lua_State *L, const char *key, int d, int delta) {\n  int isnum;\n  int t = lua_getfield(L, -1, key);  /* get field and its type */\n  lua_Integer res = lua_tointegerx(L, -1, &isnum);\n  if (!isnum) {  /* field is not an integer? */\n    if (t != LUA_TNIL)  /* some other value? */\n      return luaL_error(L, \"field '%s' is not an integer\", key);\n    else if (d < 0)  /* absent field; no default? */\n      return luaL_error(L, \"field '%s' missing in date table\", key);\n    res = d;\n  }\n  else {\n    if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))\n      return luaL_error(L, \"field '%s' is out-of-bound\", key);\n    res -= delta;\n  }\n  lua_pop(L, 1);\n  return (int)res;\n}\n\n\nstatic const char *checkoption (lua_State *L, const char *conv,\n                                ptrdiff_t convlen, char *buff) {\n  const char *option = LUA_STRFTIMEOPTIONS;\n  int oplen = 1;  /* length of options being checked */\n  for (; *option != '\\0' && oplen <= convlen; option += oplen) {\n    if (*option == '|')  /* next block? */\n      oplen++;  /* will check options with next length (+1) */\n    else if (memcmp(conv, option, oplen) == 0) {  /* match? */\n      memcpy(buff, conv, oplen);  /* copy valid option to buffer */\n      buff[oplen] = '\\0';\n      return conv + oplen;  /* return next item */\n    }\n  }\n  luaL_argerror(L, 1,\n    lua_pushfstring(L, \"invalid conversion specifier '%%%s'\", conv));\n  return conv;  /* to avoid warnings */\n}\n\n\n/* maximum size for an individual 'strftime' item */\n#define SIZETIMEFMT\t250\n\n\nstatic int os_date (lua_State *L) {\n  size_t slen;\n  const char *s = luaL_optlstring(L, 1, \"%c\", &slen);\n  time_t t = luaL_opt(L, l_checktime, 2, time(NULL));\n  const char *se = s + slen;  /* 's' end */\n  struct tm tmr, *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = l_gmtime(&t, &tmr);\n    s++;  /* skip '!' */\n  }\n  else\n    stm = l_localtime(&t, &tmr);\n  if (stm == NULL)  /* invalid date? */\n    return luaL_error(L,\n                 \"time result cannot be represented in this installation\");\n  if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setallfields(L, stm);\n  }\n  else {\n    char cc[4];  /* buffer for individual conversion specifiers */\n    luaL_Buffer b;\n    cc[0] = '%';\n    luaL_buffinit(L, &b);\n    while (s < se) {\n      if (*s != '%')  /* not a conversion specifier? */\n        luaL_addchar(&b, *s++);\n      else {\n        size_t reslen;\n        char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);\n        s++;  /* skip '%' */\n        s = checkoption(L, s, se - s, cc + 1);  /* copy specifier to 'cc' */\n        reslen = strftime(buff, SIZETIMEFMT, cc, stm);\n        luaL_addsize(&b, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0, 0);\n    ts.tm_min = getfield(L, \"min\", 0, 0);\n    ts.tm_hour = getfield(L, \"hour\", 12, 0);\n    ts.tm_mday = getfield(L, \"day\", -1, 0);\n    ts.tm_mon = getfield(L, \"month\", -1, 1);\n    ts.tm_year = getfield(L, \"year\", -1, 1900);\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n    setallfields(L, &ts);  /* update fields with normalized values */\n  }\n  if (t != (time_t)(l_timet)t || t == (time_t)(-1))\n    return luaL_error(L,\n                  \"time result cannot be represented in this installation\");\n  l_pushtime(L, t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  time_t t1 = l_checktime(L, 1);\n  time_t t2 = l_checktime(L, 2);\n  lua_pushnumber(L, (lua_Number)difftime(t1, t2));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  int status;\n  if (lua_isboolean(L, 1))\n    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);\n  else\n    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);\n  if (lua_toboolean(L, 2))\n    lua_close(L);\n  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */\n  return 0;\n}\n\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  //{\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUAMOD_API int luaopen_os (lua_State *L) {\n  luaL_newlib(L, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.155.1.2 2017/04/29 18:11:40 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n/* maximum number of local variables per function (must be smaller\n   than 250, due to the bytecode format) */\n#define MAXVARS\t\t200\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n\n/* because all strings are unified by the scanner, the parser\n   can use pointer equality for string equality */\n#define eqstr(a,b)\t((a) == (b))\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int firstlabel;  /* index of first label in this block */\n  int firstgoto;  /* index of first pending goto in this block */\n  lu_byte nactvar;  /* # active locals outside the block */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isloop;  /* true if 'block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void statement (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\n/* semantic error */\nstatic l_noret semerror (LexState *ls, const char *msg) {\n  ls->t.token = 0;  /* remove \"near <token>\" from final message */\n  luaX_syntaxerror(ls, msg);\n}\n\n\nstatic l_noret error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, \"%s expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic l_noret errorlimit (FuncState *fs, int limit, const char *what) {\n  lua_State *L = fs->ls->L;\n  const char *msg;\n  int line = fs->f->linedefined;\n  const char *where = (line == 0)\n                      ? \"main function\"\n                      : luaO_pushfstring(L, \"function at line %d\", line);\n  msg = luaO_pushfstring(L, \"too many %s (limit is %d) in %s\",\n                             what, limit, where);\n  luaX_syntaxerror(fs->ls, msg);\n}\n\n\nstatic void checklimit (FuncState *fs, int v, int l, const char *what) {\n  if (v > l) errorlimit(fs, l, what);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             \"%s expected (to close %s at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname (LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"local variables\");\n  while (oldsize < f->sizelocvars)\n    f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\nstatic void new_localvar (LexState *ls, TString *name) {\n  FuncState *fs = ls->fs;\n  Dyndata *dyd = ls->dyd;\n  int reg = registerlocalvar(ls, name);\n  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,\n                  MAXVARS, \"local variables\");\n  luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,\n                  dyd->actvar.size, Vardesc, MAX_INT, \"local variables\");\n  dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);\n}\n\n\nstatic void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {\n  new_localvar(ls, luaX_newstring(ls, name, sz));\n}\n\n#define new_localvarliteral(ls,v) \\\n\tnew_localvarliteral_(ls, \"\" v, (sizeof(v)/sizeof(char))-1)\n\n\nstatic LocVar *getlocvar (FuncState *fs, int i) {\n  int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;\n  lua_assert(idx < fs->nlocvars);\n  return &fs->f->locvars[idx];\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (FuncState *fs, int tolevel) {\n  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar)->endpc = fs->pc;\n}\n\n\nstatic int searchupvalue (FuncState *fs, TString *name) {\n  int i;\n  Upvaldesc *up = fs->f->upvalues;\n  for (i = 0; i < fs->nups; i++) {\n    if (eqstr(up[i].name, name)) return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic int newupvalue (FuncState *fs, TString *name, expdesc *v) {\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  checklimit(fs, fs->nups + 1, MAXUPVAL, \"upvalues\");\n  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,\n                  Upvaldesc, MAXUPVAL, \"upvalues\");\n  while (oldsize < f->sizeupvalues)\n    f->upvalues[oldsize++].name = NULL;\n  f->upvalues[fs->nups].instack = (v->k == VLOCAL);\n  f->upvalues[fs->nups].idx = cast_byte(v->u.info);\n  f->upvalues[fs->nups].name = name;\n  luaC_objbarrier(fs->ls->L, f, name);\n  return fs->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {\n    if (eqstr(n, getlocvar(fs, i)->varname))\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\n/*\n  Mark block where variable at given level was defined\n  (to emit close instructions later).\n*/\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl->nactvar > level)\n    bl = bl->previous;\n  bl->upval = 1;\n}\n\n\n/*\n  Find variable with given name 'n'. If it is an upvalue, add this\n  upvalue into all intermediate functions.\n*/\nstatic void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL)  /* no more levels? */\n    init_exp(var, VVOID, 0);  /* default is global */\n  else {\n    int v = searchvar(fs, n);  /* look up locals at current level */\n    if (v >= 0) {  /* found? */\n      init_exp(var, VLOCAL, v);  /* variable is local */\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n    }\n    else {  /* not found as local at current level; try upvalues */\n      int idx = searchupvalue(fs, n);  /* try existing upvalues */\n      if (idx < 0) {  /* not found? */\n        singlevaraux(fs->prev, n, var, 0);  /* try upper levels */\n        if (var->k == VVOID)  /* not found? */\n          return;  /* it is a global */\n        /* else was LOCAL or UPVAL */\n        idx  = newupvalue(fs, n, var);  /* will be a new upvalue */\n      }\n      init_exp(var, VUPVAL, idx);  /* new or old upvalue */\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  singlevaraux(fs, varname, var, 1);\n  if (var->k == VVOID) {  /* global name? */\n    expdesc key;\n    singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */\n    lua_assert(var->k != VVOID);  /* this one must exist */\n    codestring(ls, &key, varname);  /* key is variable name */\n    luaK_indexed(fs, var, &key);  /* env[varname] */\n  }\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n  if (nexps > nvars)\n    ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  lua_State *L = ls->L;\n  ++L->nCcalls;\n  checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, \"C levels\");\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void closegoto (LexState *ls, int g, Labeldesc *label) {\n  int i;\n  FuncState *fs = ls->fs;\n  Labellist *gl = &ls->dyd->gt;\n  Labeldesc *gt = &gl->arr[g];\n  lua_assert(eqstr(gt->name, label->name));\n  if (gt->nactvar < label->nactvar) {\n    TString *vname = getlocvar(fs, gt->nactvar)->varname;\n    const char *msg = luaO_pushfstring(ls->L,\n      \"<goto %s> at line %d jumps into the scope of local '%s'\",\n      getstr(gt->name), gt->line, getstr(vname));\n    semerror(ls, msg);\n  }\n  luaK_patchlist(fs, gt->pc, label->pc);\n  /* remove goto from pending list */\n  for (i = g; i < gl->n - 1; i++)\n    gl->arr[i] = gl->arr[i + 1];\n  gl->n--;\n}\n\n\n/*\n** try to close a goto with existing labels; this solves backward jumps\n*/\nstatic int findlabel (LexState *ls, int g) {\n  int i;\n  BlockCnt *bl = ls->fs->bl;\n  Dyndata *dyd = ls->dyd;\n  Labeldesc *gt = &dyd->gt.arr[g];\n  /* check labels in current block for a match */\n  for (i = bl->firstlabel; i < dyd->label.n; i++) {\n    Labeldesc *lb = &dyd->label.arr[i];\n    if (eqstr(lb->name, gt->name)) {  /* correct label? */\n      if (gt->nactvar > lb->nactvar &&\n          (bl->upval || dyd->label.n > bl->firstlabel))\n        luaK_patchclose(ls->fs, gt->pc, lb->nactvar);\n      closegoto(ls, g, lb);  /* close it */\n      return 1;\n    }\n  }\n  return 0;  /* label not found; cannot close goto */\n}\n\n\nstatic int newlabelentry (LexState *ls, Labellist *l, TString *name,\n                          int line, int pc) {\n  int n = l->n;\n  luaM_growvector(ls->L, l->arr, n, l->size,\n                  Labeldesc, SHRT_MAX, \"labels/gotos\");\n  l->arr[n].name = name;\n  l->arr[n].line = line;\n  l->arr[n].nactvar = ls->fs->nactvar;\n  l->arr[n].pc = pc;\n  l->n = n + 1;\n  return n;\n}\n\n\n/*\n** check whether new label 'lb' matches any pending gotos in current\n** block; solves forward jumps\n*/\nstatic void findgotos (LexState *ls, Labeldesc *lb) {\n  Labellist *gl = &ls->dyd->gt;\n  int i = ls->fs->bl->firstgoto;\n  while (i < gl->n) {\n    if (eqstr(gl->arr[i].name, lb->name))\n      closegoto(ls, i, lb);\n    else\n      i++;\n  }\n}\n\n\n/*\n** export pending gotos to outer level, to check them against\n** outer labels; if the block being exited has upvalues, and\n** the goto exits the scope of any variable (which can be the\n** upvalue), close those variables being exited.\n*/\nstatic void movegotosout (FuncState *fs, BlockCnt *bl) {\n  int i = bl->firstgoto;\n  Labellist *gl = &fs->ls->dyd->gt;\n  /* correct pending gotos to current block and try to close it\n     with visible labels */\n  while (i < gl->n) {\n    Labeldesc *gt = &gl->arr[i];\n    if (gt->nactvar > bl->nactvar) {\n      if (bl->upval)\n        luaK_patchclose(fs, gt->pc, bl->nactvar);\n      gt->nactvar = bl->nactvar;\n    }\n    if (!findlabel(fs->ls, i))\n      i++;  /* move to next one */\n  }\n}\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {\n  bl->isloop = isloop;\n  bl->nactvar = fs->nactvar;\n  bl->firstlabel = fs->ls->dyd->label.n;\n  bl->firstgoto = fs->ls->dyd->gt.n;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\n/*\n** create a label named 'break' to resolve break statements\n*/\nstatic void breaklabel (LexState *ls) {\n  TString *n = luaS_new(ls->L, \"break\");\n  int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);\n  findgotos(ls, &ls->dyd->label.arr[l]);\n}\n\n/*\n** generates an error for an undefined 'goto'; choose appropriate\n** message when label name is a reserved word (which can only be 'break')\n*/\nstatic l_noret undefgoto (LexState *ls, Labeldesc *gt) {\n  const char *msg = isreserved(gt->name)\n                    ? \"<%s> at line %d not inside a loop\"\n                    : \"no visible label '%s' for <goto> at line %d\";\n  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);\n  semerror(ls, msg);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  LexState *ls = fs->ls;\n  if (bl->previous && bl->upval) {\n    /* create a 'jump to here' to close upvalues */\n    int j = luaK_jump(fs);\n    luaK_patchclose(fs, j, bl->nactvar);\n    luaK_patchtohere(fs, j);\n  }\n  if (bl->isloop)\n    breaklabel(ls);  /* close pending breaks */\n  fs->bl = bl->previous;\n  removevars(fs, bl->nactvar);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  ls->dyd->label.n = bl->firstlabel;  /* remove local labels */\n  if (bl->previous)  /* inner block? */\n    movegotosout(fs, bl);  /* update pending gotos to outer block */\n  else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */\n    undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */\n}\n\n\n/*\n** adds a new prototype into list of prototypes\n*/\nstatic Proto *addprototype (LexState *ls) {\n  Proto *clp;\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;  /* prototype of current function */\n  if (fs->np >= f->sizep) {\n    int oldsize = f->sizep;\n    luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, \"functions\");\n    while (oldsize < f->sizep)\n      f->p[oldsize++] = NULL;\n  }\n  f->p[fs->np++] = clp = luaF_newproto(L);\n  luaC_objbarrier(L, f, clp);\n  return clp;\n}\n\n\n/*\n** codes instruction to create new closure in parent function.\n** The OP_CLOSURE instruction must use the last available register,\n** so that, if it invokes the GC, the GC knows which registers\n** are in use at that time.\n*/\nstatic void codeclosure (LexState *ls, expdesc *v) {\n  FuncState *fs = ls->fs->prev;\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));\n  luaK_exp2nextreg(fs, v);  /* fix it at the last register */\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {\n  Proto *f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nups = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->firstlocal = ls->dyd->actvar.n;\n  fs->bl = NULL;\n  f = fs->f;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  enterblock(fs, bl, 0);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  luaK_ret(fs, 0, 0);  /* final return */\n  leaveblock(fs);\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);\n  f->sizeupvalues = fs->nups;\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  luaC_checkGC(L);\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\n/*\n** check whether current token is in the follow set of a block.\n** 'until' closes syntactical blocks, but do not close scope,\n** so it is handled in separate.\n*/\nstatic int block_follow (LexState *ls, int withuntil) {\n  switch (ls->t.token) {\n    case TK_ELSE: case TK_ELSEIF:\n    case TK_END: case TK_EOS:\n      return 1;\n    case TK_UNTIL: return withuntil;\n    default: return 0;\n  }\n}\n\n\nstatic void statlist (LexState *ls) {\n  /* statlist -> { stat [';'] } */\n  while (!block_follow(ls, 1)) {\n    if (ls->t.token == TK_RETURN) {\n      statement(ls);\n      return;  /* 'return' must be last statement */\n    }\n    statement(ls);\n  }\n}\n\n\nstatic void fieldsel (LexState *ls, expdesc *v) {\n  /* fieldsel -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyregup(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of 'record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | '['exp1']') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  /* listfield -> exp */\n  expr(ls, &cc->v);\n  checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void field (LexState *ls, struct ConsControl *cc) {\n  /* field -> listfield | recfield */\n  switch(ls->t.token) {\n    case TK_NAME: {  /* may be 'listfield' or 'recfield' */\n      if (luaX_lookahead(ls) != '=')  /* expression? */\n        listfield(ls, cc);\n      else\n        recfield(ls, cc);\n      break;\n    }\n    case '[': {\n      recfield(ls, cc);\n      break;\n    }\n    default: {\n      listfield(ls, cc);\n      break;\n    }\n  }\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> '{' [ field { sep field } [sep] ] '}'\n     sep -> ',' | ';' */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    field(ls, &cc);\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { ',' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is 'parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls));\n          nparams++;\n          break;\n        }\n        case TK_DOTS: {  /* param -> '...' */\n          luaX_next(ls);\n          f->is_vararg = 1;  /* declared vararg */\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or '...' expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar);\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int ismethod, int line) {\n  /* body ->  '(' parlist ')' block END */\n  FuncState new_fs;\n  BlockCnt bl;\n  new_fs.f = addprototype(ls);\n  new_fs.f->linedefined = line;\n  open_func(ls, &new_fs, &bl);\n  checknext(ls, '(');\n  if (ismethod) {\n    new_localvarliteral(ls, \"self\");  /* create 'self' parameter */\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  statlist(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  codeclosure(ls, e);\n  close_func(ls);\n}\n\n\nstatic int explist (LexState *ls, expdesc *v) {\n  /* explist -> expr { ',' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f, int line) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> '(' [ explist ] ')' */\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use 'seminfo' before 'next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n    }\n  }\n}\n\n\nstatic void suffixedexp (LexState *ls, expdesc *v) {\n  /* suffixedexp ->\n       primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  primaryexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* fieldsel */\n        fieldsel(ls, v);\n        break;\n      }\n      case '[': {  /* '[' exp1 ']' */\n        expdesc key;\n        luaK_exp2anyregup(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* ':' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v, line);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v, line);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |\n                  constructor | FUNCTION body | suffixedexp */\n  switch (ls->t.token) {\n    case TK_FLT: {\n      init_exp(v, VKFLT, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_INT: {\n      init_exp(v, VKINT, 0);\n      v->u.ival = ls->t.seminfo.i;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use '...' outside a vararg function\");\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      suffixedexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '~': return OPR_BNOT;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case '/': return OPR_DIV;\n    case TK_IDIV: return OPR_IDIV;\n    case '&': return OPR_BAND;\n    case '|': return OPR_BOR;\n    case '~': return OPR_BXOR;\n    case TK_SHL: return OPR_SHL;\n    case TK_SHR: return OPR_SHR;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {10, 10}, {10, 10},           /* '+' '-' */\n   {11, 11}, {11, 11},           /* '*' '%' */\n   {14, 13},                  /* '^' (right associative) */\n   {11, 11}, {11, 11},           /* '/' '//' */\n   {6, 6}, {4, 4}, {5, 5},   /* '&' '|' '~' */\n   {7, 7}, {7, 7},           /* '<<' '>>' */\n   {9, 8},                   /* '..' (right associative) */\n   {3, 3}, {3, 3}, {3, 3},   /* ==, <, <= */\n   {3, 3}, {3, 3}, {3, 3},   /* ~=, >, >= */\n   {2, 2}, {1, 1}            /* and, or */\n};\n\n#define UNARY_PRIORITY\t12  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where 'binop' is any binary operator with a priority higher than 'limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    int line = ls->linenumber;\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v, line);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than 'limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    int line = ls->linenumber;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2, line);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic void block (LexState *ls) {\n  /* block -> statlist */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  statlist(ls);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to an upvalue/local variable, the\n** upvalue/local variable is begin used in a previous assignment to a\n** table. If so, save original upvalue/local value in a safe place and\n** use this safe copy in the previous assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {  /* check all previous assignments */\n    if (lh->v.k == VINDEXED) {  /* assigning to a table? */\n      /* table is the upvalue/local being assigned now? */\n      if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.vt = VLOCAL;\n        lh->v.u.ind.t = extra;  /* previous assignment will use safe copy */\n      }\n      /* index is the local being assigned? (index cannot be upvalue) */\n      if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {\n        conflict = 1;\n        lh->v.u.ind.idx = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    /* copy upvalue/local value to a temporary (in position 'extra') */\n    OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, op, extra, v->u.info, 0);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, vkisvar(lh->v.k), \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> ',' suffixedexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    suffixedexp(ls, &nv.v);\n    if (nv.v.k != VINDEXED)\n      check_conflict(ls, lh, &nv.v);\n    checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,\n                    \"C levels\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> '=' explist */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist(ls, &e);\n    if (nexps != nvars)\n      adjust_assign(ls, nvars, nexps, &e);\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* 'falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void gotostat (LexState *ls, int pc) {\n  int line = ls->linenumber;\n  TString *label;\n  int g;\n  if (testnext(ls, TK_GOTO))\n    label = str_checkname(ls);\n  else {\n    luaX_next(ls);  /* skip break */\n    label = luaS_new(ls->L, \"break\");\n  }\n  g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);\n  findlabel(ls, g);  /* close it if label already defined */\n}\n\n\n/* check for repeated labels on the same block */\nstatic void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {\n  int i;\n  for (i = fs->bl->firstlabel; i < ll->n; i++) {\n    if (eqstr(label, ll->arr[i].name)) {\n      const char *msg = luaO_pushfstring(fs->ls->L,\n                          \"label '%s' already defined on line %d\",\n                          getstr(label), ll->arr[i].line);\n      semerror(fs->ls, msg);\n    }\n  }\n}\n\n\n/* skip no-op statements */\nstatic void skipnoopstat (LexState *ls) {\n  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)\n    statement(ls);\n}\n\n\nstatic void labelstat (LexState *ls, TString *label, int line) {\n  /* label -> '::' NAME '::' */\n  FuncState *fs = ls->fs;\n  Labellist *ll = &ls->dyd->label;\n  int l;  /* index of new label being created */\n  checkrepeated(fs, ll, label);  /* check for repeated labels */\n  checknext(ls, TK_DBCOLON);  /* skip double colon */\n  /* create new entry for this label */\n  l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));\n  skipnoopstat(ls);  /* skip other no-op statements */\n  if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */\n    /* assume that locals are already out of scope */\n    ll->arr[l].nactvar = fs->bl->nactvar;\n  }\n  findgotos(ls, &ll->arr[l]);\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_jumpto(fs, whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  statlist(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (bl2.upval)  /* upvalues? */\n    luaK_patchclose(fs, condexit, bl2.nactvar);\n  leaveblock(fs);  /* finish scope */\n  luaK_patchlist(fs, condexit, repeat_init);  /* close the loop */\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int reg;\n  expr(ls, &e);\n  luaK_exp2nextreg(ls->fs, &e);\n  lua_assert(e.k == VNONRELOC);\n  reg = e.u.info;\n  return reg;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  if (isnum)  /* numeric for? */\n    endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);\n  else {  /* generic for */\n    luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);\n    luaK_fixline(fs, line);\n    endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);\n  }\n  luaK_patchlist(fs, endfor, prep + 1);\n  luaK_fixline(fs, line);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\");\n  new_localvarliteral(ls, \"(for limit)\");\n  new_localvarliteral(ls, \"(for step)\");\n  new_localvar(ls, varname);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codek(fs, fs->freereg, luaK_intK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 4;  /* gen, state, control, plus at least one declared var */\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for control)\");\n  /* create declared variables */\n  new_localvar(ls, indexname);\n  while (testnext(ls, ',')) {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  }\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip 'for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, \"'=' or 'in' expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope ('break' jumps to this point) */\n}\n\n\nstatic void test_then_block (LexState *ls, int *escapelist) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  expdesc v;\n  int jf;  /* instruction to skip 'then' code (if condition is false) */\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  expr(ls, &v);  /* read condition */\n  checknext(ls, TK_THEN);\n  if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {\n    luaK_goiffalse(ls->fs, &v);  /* will jump to label if condition is true */\n    enterblock(fs, &bl, 0);  /* must enter block before 'goto' */\n    gotostat(ls, v.t);  /* handle goto/break */\n    while (testnext(ls, ';')) {}  /* skip colons */\n    if (block_follow(ls, 0)) {  /* 'goto' is the entire block? */\n      leaveblock(fs);\n      return;  /* and that is it */\n    }\n    else  /* must skip over 'then' part if condition is false */\n      jf = luaK_jump(fs);\n  }\n  else {  /* regular case (not goto/break) */\n    luaK_goiftrue(ls->fs, &v);  /* skip over block if condition is false */\n    enterblock(fs, &bl, 0);\n    jf = v.f;\n  }\n  statlist(ls);  /* 'then' part */\n  leaveblock(fs);\n  if (ls->t.token == TK_ELSE ||\n      ls->t.token == TK_ELSEIF)  /* followed by 'else'/'elseif'? */\n    luaK_concat(fs, escapelist, luaK_jump(fs));  /* must jump over it */\n  luaK_patchtohere(fs, jf);\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int escapelist = NO_JUMP;  /* exit list for finished parts */\n  test_then_block(ls, &escapelist);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF)\n    test_then_block(ls, &escapelist);  /* ELSEIF cond THEN block */\n  if (testnext(ls, TK_ELSE))\n    block(ls);  /* 'else' part */\n  check_match(ls, TK_END, TK_IF, line);\n  luaK_patchtohere(fs, escapelist);  /* patch escape list to 'if' end */\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls));  /* new local variable */\n  adjustlocalvars(ls, 1);  /* enter its scope */\n  body(ls, &b, 0, ls->linenumber);  /* function created in next register */\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, b.u.info)->startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {',' NAME} ['=' explist] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {fieldsel} [':' NAME] */\n  int ismethod = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    fieldsel(ls, v);\n  if (ls->t.token == ':') {\n    ismethod = 1;\n    fieldsel(ls, v);\n  }\n  return ismethod;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int ismethod;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  ismethod = funcname(ls, &v);\n  body(ls, &b, ismethod, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition \"happens\" in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  suffixedexp(ls, &v.v);\n  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n  else {  /* stat -> func */\n    check_condition(ls, v.v.k == VCALL, \"syntax error\");\n    SETARG_C(getinstruction(fs, &v.v), 1);  /* call statement uses no results */\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN [explist] [';'] */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  if (block_follow(ls, 1) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the stack */\n        first = fs->nactvar;  /* return all active values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n  testnext(ls, ';');  /* skip optional semicolon */\n}\n\n\nstatic void statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  enterlevel(ls);\n  switch (ls->t.token) {\n    case ';': {  /* stat -> ';' (empty statement) */\n      luaX_next(ls);  /* skip ';' */\n      break;\n    }\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      break;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      break;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      break;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      break;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      break;\n    }\n    case TK_FUNCTION: {  /* stat -> funcstat */\n      funcstat(ls, line);\n      break;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      break;\n    }\n    case TK_DBCOLON: {  /* stat -> label */\n      luaX_next(ls);  /* skip double colon */\n      labelstat(ls, str_checkname(ls), line);\n      break;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      luaX_next(ls);  /* skip RETURN */\n      retstat(ls);\n      break;\n    }\n    case TK_BREAK:   /* stat -> breakstat */\n    case TK_GOTO: {  /* stat -> 'goto' NAME */\n      gotostat(ls, luaK_jump(ls->fs));\n      break;\n    }\n    default: {  /* stat -> func | assignment */\n      exprstat(ls);\n      break;\n    }\n  }\n  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n             ls->fs->freereg >= ls->fs->nactvar);\n  ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n\n\n/*\n** compiles the main function, which is a regular vararg function with an\n** upvalue named LUA_ENV\n*/\nstatic void mainfunc (LexState *ls, FuncState *fs) {\n  BlockCnt bl;\n  expdesc v;\n  open_func(ls, fs, &bl);\n  fs->f->is_vararg = 1;  /* main function is always declared vararg */\n  init_exp(&v, VLOCAL, 0);  /* create and... */\n  newupvalue(fs, ls->envn, &v);  /* ...set environment upvalue */\n  luaX_next(ls);  /* read first token */\n  statlist(ls);  /* parse main body */\n  check(ls, TK_EOS);\n  close_func(ls);\n}\n\n\nLClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                       Dyndata *dyd, const char *name, int firstchar) {\n  LexState lexstate;\n  FuncState funcstate;\n  LClosure *cl = luaF_newLclosure(L, 1);  /* create main closure */\n  setclLvalue(L, L->top, cl);  /* anchor it (to avoid being collected) */\n  luaD_inctop(L);\n  lexstate.h = luaH_new(L);  /* create table for scanner */\n  sethvalue(L, L->top, lexstate.h);  /* anchor it */\n  luaD_inctop(L);\n  funcstate.f = cl->p = luaF_newproto(L);\n  funcstate.f->source = luaS_new(L, name);  /* create and anchor TString */\n  lua_assert(iswhite(funcstate.f));  /* do not need barrier here */\n  lexstate.buff = buff;\n  lexstate.dyd = dyd;\n  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;\n  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);\n  mainfunc(&lexstate, &funcstate);\n  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);\n  /* all scopes should be correctly finished */\n  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);\n  L->top--;  /* remove scanner's table */\n  return cl;  /* closure is on the stack, too */\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression and variable descriptor.\n** Code generation for variables and expressions can be delayed to allow\n** optimizations; An 'expdesc' structure describes a potentially-delayed\n** variable/expression. It has a description of its \"main\" value plus a\n** list of conditional jumps that can also produce its value (generated\n** by short-circuit operators 'and'/'or').\n*/\n\n/* kinds of variables/expressions */\ntypedef enum {\n  VVOID,  /* when 'expdesc' describes the last expression a list,\n             this kind means an empty list (so, no expression) */\n  VNIL,  /* constant nil */\n  VTRUE,  /* constant true */\n  VFALSE,  /* constant false */\n  VK,  /* constant in 'k'; info = index of constant in 'k' */\n  VKFLT,  /* floating constant; nval = numerical float value */\n  VKINT,  /* integer constant; nval = numerical integer value */\n  VNONRELOC,  /* expression has its value in a fixed register;\n                 info = result register */\n  VLOCAL,  /* local variable; info = local register */\n  VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */\n  VINDEXED,  /* indexed variable;\n                ind.vt = whether 't' is register or upvalue;\n                ind.t = table register or upvalue;\n                ind.idx = key's R/K index */\n  VJMP,  /* expression is a test/comparison;\n            info = pc of corresponding jump instruction */\n  VRELOCABLE,  /* expression can put result in any register;\n                  info = instruction pc */\n  VCALL,  /* expression is a function call; info = instruction pc */\n  VVARARG  /* vararg expression; info = instruction pc */\n} expkind;\n\n\n#define vkisvar(k)\t(VLOCAL <= (k) && (k) <= VINDEXED)\n#define vkisinreg(k)\t((k) == VNONRELOC || (k) == VLOCAL)\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    lua_Integer ival;    /* for VKINT */\n    lua_Number nval;  /* for VKFLT */\n    int info;  /* for generic use */\n    struct {  /* for indexed variables (VINDEXED) */\n      short idx;  /* index (R/K) */\n      lu_byte t;  /* table (register or upvalue) */\n      lu_byte vt;  /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */\n    } ind;\n  } u;\n  int t;  /* patch list of 'exit when true' */\n  int f;  /* patch list of 'exit when false' */\n} expdesc;\n\n\n/* description of active local variable */\ntypedef struct Vardesc {\n  short idx;  /* variable index in stack */\n} Vardesc;\n\n\n/* description of pending goto statements and label statements */\ntypedef struct Labeldesc {\n  TString *name;  /* label identifier */\n  int pc;  /* position in code */\n  int line;  /* line where it appeared */\n  lu_byte nactvar;  /* local level where it appears in current block */\n} Labeldesc;\n\n\n/* list of labels or gotos */\ntypedef struct Labellist {\n  Labeldesc *arr;  /* array */\n  int n;  /* number of entries in use */\n  int size;  /* array size */\n} Labellist;\n\n\n/* dynamic structures used by the parser */\ntypedef struct Dyndata {\n  struct {  /* list of active local variables */\n    Vardesc *arr;\n    int n;\n    int size;\n  } actvar;\n  Labellist gt;  /* list of pending gotos */\n  Labellist label;   /* list of active labels */\n} Dyndata;\n\n\n/* control of blocks */\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to 'ncode') */\n  int lasttarget;   /* 'label' of last 'jump label' */\n  int jpc;  /* list of pending jumps to 'pc' */\n  int nk;  /* number of elements in 'k' */\n  int np;  /* number of elements in 'p' */\n  int firstlocal;  /* index of first local var (in Dyndata array) */\n  short nlocvars;  /* number of elements in 'f->locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  lu_byte nups;  /* number of upvalues */\n  lu_byte freereg;  /* first free register */\n} FuncState;\n\n\nLUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                 Dyndata *dyd, const char *name, int firstchar);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lprefix.h",
    "content": "/*\n** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $\n** Definitions for Lua code that must come before any other header file\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lprefix_h\n#define lprefix_h\n\n\n/*\n** Allows POSIX/XSI stuff\n*/\n#if !defined(LUA_USE_C89)\t/* { */\n\n#if !defined(_XOPEN_SOURCE)\n#define _XOPEN_SOURCE           600\n#elif _XOPEN_SOURCE == 0\n#undef _XOPEN_SOURCE  /* use -D_XOPEN_SOURCE=0 to undefine it */\n#endif\n\n/*\n** Allows manipulation of large files in gcc and some other compilers\n*/\n#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)\n#define _LARGEFILE_SOURCE       1\n#define _FILE_OFFSET_BITS       64\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Windows stuff\n*/\n#if defined(_WIN32) \t/* { */\n\n#if !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS  /* avoid warnings about ISO C functions */\n#endif\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUAI_GCPAUSE)\n#define LUAI_GCPAUSE\t200  /* 200% */\n#endif\n\n#if !defined(LUAI_GCMUL)\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n#endif\n\n\n/*\n** a macro to help the creation of a unique random seed when a state is\n** created; the seed is used to randomize hashes.\n*/\n#if !defined(luai_makeseed)\n#include <time.h>\n#define luai_makeseed()\t\tcast(unsigned int, time(NULL))\n#endif\n\n\n\n/*\n** thread state + extra space\n*/\ntypedef struct LX {\n  lu_byte extra_[LUA_EXTRASPACE];\n  lua_State l;\n} LX;\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  LX l;\n  global_State g;\n} LG;\n\n\n\n#define fromstate(L)\t(cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))\n\n\n/*\n** Compute an initial seed as random as possible. Rely on Address Space\n** Layout Randomization (if present) to increase randomness..\n*/\n#define addbuff(b,p,e) \\\n  { size_t t = cast(size_t, e); \\\n    memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }\n\nstatic unsigned int makeseed (lua_State *L) {\n  char buff[4 * sizeof(size_t)];\n  unsigned int h = luai_makeseed();\n  int p = 0;\n  addbuff(buff, p, L);  /* heap variable */\n  addbuff(buff, p, &h);  /* local variable */\n  addbuff(buff, p, luaO_nilobject);  /* global variable */\n  addbuff(buff, p, &lua_newstate);  /* public function */\n  lua_assert(p == sizeof(buff));\n  return luaS_hash(buff, p, h);\n}\n\n\n/*\n** set GCdebt to a new value keeping the value (totalbytes + GCdebt)\n** invariant (and avoiding underflows in 'totalbytes')\n*/\nvoid luaE_setdebt (global_State *g, l_mem debt) {\n  l_mem tb = gettotalbytes(g);\n  lua_assert(tb > 0);\n  if (debt < tb - MAX_LMEM)\n    debt = tb - MAX_LMEM;  /* will make 'totalbytes == MAX_LMEM' */\n  g->totalbytes = tb - debt;\n  g->GCdebt = debt;\n}\n\n\nCallInfo *luaE_extendCI (lua_State *L) {\n  CallInfo *ci = luaM_new(L, CallInfo);\n  lua_assert(L->ci->next == NULL);\n  L->ci->next = ci;\n  ci->previous = L->ci;\n  ci->next = NULL;\n  L->nci++;\n  return ci;\n}\n\n\n/*\n** free all CallInfo structures not in use by a thread\n*/\nvoid luaE_freeCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next = ci->next;\n  ci->next = NULL;\n  while ((ci = next) != NULL) {\n    next = ci->next;\n    luaM_free(L, ci);\n    L->nci--;\n  }\n}\n\n\n/*\n** free half of the CallInfo structures not in use by a thread\n*/\nvoid luaE_shrinkCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next2;  /* next's next */\n  /* while there are two nexts */\n  while (ci->next != NULL && (next2 = ci->next->next) != NULL) {\n    luaM_free(L, ci->next);  /* free next */\n    L->nci--;\n    ci->next = next2;  /* remove 'next' from the list */\n    next2->previous = ci;\n    ci = next2;  /* keep next's next */\n  }\n}\n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  int i; CallInfo *ci;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);\n  L1->stacksize = BASIC_STACK_SIZE;\n  for (i = 0; i < BASIC_STACK_SIZE; i++)\n    setnilvalue(L1->stack + i);  /* erase new stack */\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;\n  /* initialize first ci */\n  ci = &L1->base_ci;\n  ci->next = ci->previous = NULL;\n  ci->callstatus = 0;\n  ci->func = L1->top;\n  setnilvalue(L1->top++);  /* 'function' entry for this 'ci' */\n  ci->top = L1->top + LUA_MINSTACK;\n  L1->ci = ci;\n}\n\n\nstatic void freestack (lua_State *L) {\n  if (L->stack == NULL)\n    return;  /* stack not completely built yet */\n  L->ci = &L->base_ci;  /* free the entire 'ci' list */\n  luaE_freeCI(L);\n  lua_assert(L->nci == 0);\n  luaM_freearray(L, L->stack, L->stacksize);  /* free stack array */\n}\n\n\n/*\n** Create registry table and its predefined values\n*/\nstatic void init_registry (lua_State *L, global_State *g) {\n  TValue temp;\n  /* create registry */\n  Table *registry = luaH_new(L);\n  sethvalue(L, &g->l_registry, registry);\n  luaH_resize(L, registry, LUA_RIDX_LAST, 0);\n  /* registry[LUA_RIDX_MAINTHREAD] = L */\n  setthvalue(L, &temp, L);  /* temp = L */\n  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);\n  /* registry[LUA_RIDX_GLOBALS] = table of globals */\n  sethvalue(L, &temp, luaH_new(L));  /* temp = new table (global table) */\n  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);\n}\n\n\n/*\n** open parts of the state that may cause memory-allocation errors.\n** ('g->version' != NULL flags that the state was completely build)\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  init_registry(L, g);\n  luaS_init(L);\n  luaT_init(L);\n  luaX_init(L);\n  g->gcrunning = 1;  /* allow gc */\n  g->version = lua_version(NULL);\n  luai_userstateopen(L);\n}\n\n\n/*\n** preinitialize a thread with consistent values without allocating\n** any memory (to avoid errors)\n*/\nstatic void preinit_thread (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->ci = NULL;\n  L->nci = 0;\n  L->stacksize = 0;\n  L->twups = L;  /* thread has no upvalues */\n  L->errorJmp = NULL;\n  L->nCcalls = 0;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->nny = 1;\n  L->status = LUA_OK;\n  L->errfunc = 0;\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeallobjects(L);  /* collect all objects */\n  if (g->version)  /* closing a fully built state? */\n    luai_userstateclose(L);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);\n  freestack(L);\n  lua_assert(gettotalbytes(g) == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);  /* free main block */\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  global_State *g = G(L);\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  /* create new thread */\n  L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;\n  L1->marked = luaC_white(g);\n  L1->tt = LUA_TTHREAD;\n  /* link it on list 'allgc' */\n  L1->next = g->allgc;\n  g->allgc = obj2gco(L1);\n  /* anchor it on L stack */\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  preinit_thread(L1, g);\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  /* initialize L1 extra space */\n  memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread),\n         LUA_EXTRASPACE);\n  luai_userstatethread(L, L1);\n  stack_init(L1, L);  /* init stack */\n  lua_unlock(L);\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  LX *l = fromstate(L1);\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L, L1);\n  freestack(L1);\n  luaM_free(L, l);\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));\n  if (l == NULL) return NULL;\n  L = &l->l.l;\n  g = &l->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bitmask(WHITE0BIT);\n  L->marked = luaC_white(g);\n  preinit_thread(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->seed = makeseed(L);\n  g->gcrunning = 0;  /* no GC while building state */\n  g->GCestimate = 0;\n  g->strt.size = g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(&g->l_registry);\n  g->panic = NULL;\n  g->version = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_NORMAL;\n  g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL;\n  g->sweepgc = NULL;\n  g->gray = g->grayagain = NULL;\n  g->weak = g->ephemeron = g->allweak = NULL;\n  g->twups = NULL;\n  g->totalbytes = sizeof(LG);\n  g->GCdebt = 0;\n  g->gcfinnum = 0;\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  return L;\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  close_state(L);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n/*\n\n** Some notes about garbage-collected objects: All objects in Lua must\n** be kept somehow accessible until being freed, so all objects always\n** belong to one (and only one) of these lists, using field 'next' of\n** the 'CommonHeader' for the link:\n**\n** 'allgc': all objects not marked for finalization;\n** 'finobj': all objects marked for finalization;\n** 'tobefnz': all objects ready to be finalized;\n** 'fixedgc': all objects that are not to be collected (currently\n** only small strings, such as reserved words).\n**\n** Moreover, there is another set of lists that control gray objects.\n** These lists are linked by fields 'gclist'. (All objects that\n** can become gray have such a field. The field is not the same\n** in all objects, but it always has this name.)  Any gray object\n** must belong to one of these lists, and all objects in these lists\n** must be gray:\n**\n** 'gray': regular gray objects, still waiting to be visited.\n** 'grayagain': objects that must be revisited at the atomic phase.\n**   That includes\n**   - black objects got in a write barrier;\n**   - all kinds of weak tables during propagation phase;\n**   - all threads.\n** 'weak': tables with weak values to be cleared;\n** 'ephemeron': ephemeron tables with white->white entries;\n** 'allweak': tables with weak keys and/or weak values to be cleared.\n** The last three lists are used only during the atomic phase.\n\n*/\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/*\n** Atomic type (relative to signals) to better ensure that 'lua_sethook'\n** is thread safe\n*/\n#if !defined(l_signalT)\n#include <signal.h>\n#define l_signalT\tsig_atomic_t\n#endif\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n/* kinds of Garbage Collection */\n#define KGC_NORMAL\t0\n#define KGC_EMERGENCY\t1\t/* gc was forced by an allocation failure */\n\n\ntypedef struct stringtable {\n  TString **hash;\n  int nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** Information about a call.\n** When a thread yields, 'func' is adjusted to pretend that the\n** top function has only the yielded values in its stack; in that\n** case, the actual 'func' value is saved in field 'extra'.\n** When a function calls another with a continuation, 'extra' keeps\n** the function index so that, in case of errors, the continuation\n** function can be called with the correct top.\n*/\ntypedef struct CallInfo {\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  struct CallInfo *previous, *next;  /* dynamic call link */\n  union {\n    struct {  /* only for Lua functions */\n      StkId base;  /* base for this function */\n      const Instruction *savedpc;\n    } l;\n    struct {  /* only for C functions */\n      lua_KFunction k;  /* continuation in case of yields */\n      ptrdiff_t old_errfunc;\n      lua_KContext ctx;  /* context info. in case of yields */\n    } c;\n  } u;\n  ptrdiff_t extra;\n  short nresults;  /* expected number of results from this function */\n  unsigned short callstatus;\n} CallInfo;\n\n\n/*\n** Bits in CallInfo status\n*/\n#define CIST_OAH\t(1<<0)\t/* original value of 'allowhook' */\n#define CIST_LUA\t(1<<1)\t/* call is running a Lua function */\n#define CIST_HOOKED\t(1<<2)\t/* call is running a debug hook */\n#define CIST_FRESH\t(1<<3)\t/* call is running on a fresh invocation\n                                   of luaV_execute */\n#define CIST_YPCALL\t(1<<4)\t/* call is a yieldable protected call */\n#define CIST_TAIL\t(1<<5)\t/* call was tail called */\n#define CIST_HOOKYIELD\t(1<<6)\t/* last hook called yielded */\n#define CIST_LEQ\t(1<<7)  /* using __lt for __le */\n#define CIST_FIN\t(1<<8)  /* call is running a finalizer */\n\n#define isLua(ci)\t((ci)->callstatus & CIST_LUA)\n\n/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */\n#define setoah(st,v)\t((st) = ((st) & ~CIST_OAH) | (v))\n#define getoah(st)\t((st) & CIST_OAH)\n\n\n/*\n** 'global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to 'frealloc' */\n  l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */\n  l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */\n  lu_mem GCmemtrav;  /* memory traversed by the GC */\n  lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */\n  stringtable strt;  /* hash table for strings */\n  TValue l_registry;\n  unsigned int seed;  /* randomized seed for hashes */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gckind;  /* kind of GC running */\n  lu_byte gcrunning;  /* true if GC is running */\n  GCObject *allgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* current position of sweep in list */\n  GCObject *finobj;  /* list of collectable objects with finalizers */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of tables with weak values */\n  GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */\n  GCObject *allweak;  /* list of all-weak tables */\n  GCObject *tobefnz;  /* list of userdata to be GC */\n  GCObject *fixedgc;  /* list of objects not to be collected */\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  unsigned int gcfinnum;  /* number of finalizers to call in each GC step */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC 'granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  struct lua_State *mainthread;\n  const lua_Number *version;  /* pointer to version number */\n  TString *memerrmsg;  /* memory-error message */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */\n  TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */\n} global_State;\n\n\n/*\n** 'per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  unsigned short nci;  /* number of items in 'ci' list */\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *oldpc;  /* last pc traced */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  UpVal *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */\n  volatile lua_Hook hook;\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n  int stacksize;\n  int basehookcount;\n  int hookcount;\n  unsigned short nny;  /* number of non-yieldable calls in stack */\n  unsigned short nCcalls;  /* number of nested C calls */\n  l_signalT hookmask;\n  lu_byte allowhook;\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects (only for conversions)\n*/\nunion GCUnion {\n  GCObject gc;  /* common header */\n  struct TString ts;\n  struct Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct lua_State th;  /* thread */\n};\n\n\n#define cast_u(o)\tcast(union GCUnion *, (o))\n\n/* macros to convert a GCObject into a specific value */\n#define gco2ts(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))\n#define gco2u(o)  check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))\n#define gco2lcl(o)  check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))\n#define gco2ccl(o)  check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))\n#define gco2cl(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))\n#define gco2t(o)  check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))\n#define gco2p(o)  check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))\n#define gco2th(o)  check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))\n\n\n/* macro to convert a Lua object into a GCObject */\n#define obj2gco(v) \\\n\tcheck_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))\n\n\n/* actual number of total bytes allocated */\n#define gettotalbytes(g)\tcast(lu_mem, (g)->totalbytes + (g)->GCdebt)\n\nLUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\nLUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);\nLUAI_FUNC void luaE_freeCI (lua_State *L);\nLUAI_FUNC void luaE_shrinkCI (lua_State *L);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.56.1.1 2017/04/19 17:20:42 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n#define MEMERRMSG       \"not enough memory\"\n\n\n/*\n** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to\n** compute its hash\n*/\n#if !defined(LUAI_HASHLIMIT)\n#define LUAI_HASHLIMIT\t\t5\n#endif\n\n\n/*\n** equality for long strings\n*/\nint luaS_eqlngstr (TString *a, TString *b) {\n  size_t len = a->u.lnglen;\n  lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);\n  return (a == b) ||  /* same instance or... */\n    ((len == b->u.lnglen) &&  /* equal length and ... */\n     (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */\n}\n\n\nunsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {\n  unsigned int h = seed ^ cast(unsigned int, l);\n  size_t step = (l >> LUAI_HASHLIMIT) + 1;\n  for (; l >= step; l -= step)\n    h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));\n  return h;\n}\n\n\nunsigned int luaS_hashlongstr (TString *ts) {\n  lua_assert(ts->tt == LUA_TLNGSTR);\n  if (ts->extra == 0) {  /* no hash? */\n    ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);\n    ts->extra = 1;  /* now it has its hash */\n  }\n  return ts->hash;\n}\n\n\n/*\n** resizes the string table\n*/\nvoid luaS_resize (lua_State *L, int newsize) {\n  int i;\n  stringtable *tb = &G(L)->strt;\n  if (newsize > tb->size) {  /* grow table if needed */\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n    for (i = tb->size; i < newsize; i++)\n      tb->hash[i] = NULL;\n  }\n  for (i = 0; i < tb->size; i++) {  /* rehash */\n    TString *p = tb->hash[i];\n    tb->hash[i] = NULL;\n    while (p) {  /* for each node in the list */\n      TString *hnext = p->u.hnext;  /* save next */\n      unsigned int h = lmod(p->hash, newsize);  /* new position */\n      p->u.hnext = tb->hash[h];  /* chain it */\n      tb->hash[h] = p;\n      p = hnext;\n    }\n  }\n  if (newsize < tb->size) {  /* shrink table if needed */\n    /* vanishing slice should be empty */\n    lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);\n  }\n  tb->size = newsize;\n}\n\n\n/*\n** Clear API string cache. (Entries cannot be empty, so fill them with\n** a non-collectable string.)\n*/\nvoid luaS_clearcache (global_State *g) {\n  int i, j;\n  for (i = 0; i < STRCACHE_N; i++)\n    for (j = 0; j < STRCACHE_M; j++) {\n    if (iswhite(g->strcache[i][j]))  /* will entry be collected? */\n      g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */\n    }\n}\n\n\n/*\n** Initialize the string table and the string cache\n*/\nvoid luaS_init (lua_State *L) {\n  global_State *g = G(L);\n  int i, j;\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  /* pre-create memory-error message */\n  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);\n  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */\n  for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */\n    for (j = 0; j < STRCACHE_M; j++)\n      g->strcache[i][j] = g->memerrmsg;\n}\n\n\n\n/*\n** creates a new string object\n*/\nstatic TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {\n  TString *ts;\n  GCObject *o;\n  size_t totalsize;  /* total size of TString object */\n  totalsize = sizelstring(l);\n  o = luaC_newobj(L, tag, totalsize);\n  ts = gco2ts(o);\n  ts->hash = h;\n  ts->extra = 0;\n  getstr(ts)[l] = '\\0';  /* ending 0 */\n  return ts;\n}\n\n\nTString *luaS_createlngstrobj (lua_State *L, size_t l) {\n  TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);\n  ts->u.lnglen = l;\n  return ts;\n}\n\n\nvoid luaS_remove (lua_State *L, TString *ts) {\n  stringtable *tb = &G(L)->strt;\n  TString **p = &tb->hash[lmod(ts->hash, tb->size)];\n  while (*p != ts)  /* find previous element */\n    p = &(*p)->u.hnext;\n  *p = (*p)->u.hnext;  /* remove element from its list */\n  tb->nuse--;\n}\n\n\n/*\n** checks whether short string exists and reuses it or creates a new one\n*/\nstatic TString *internshrstr (lua_State *L, const char *str, size_t l) {\n  TString *ts;\n  global_State *g = G(L);\n  unsigned int h = luaS_hash(str, l, g->seed);\n  TString **list = &g->strt.hash[lmod(h, g->strt.size)];\n  lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */\n  for (ts = *list; ts != NULL; ts = ts->u.hnext) {\n    if (l == ts->shrlen &&\n        (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {\n      /* found! */\n      if (isdead(g, ts))  /* dead (but not collected yet)? */\n        changewhite(ts);  /* resurrect it */\n      return ts;\n    }\n  }\n  if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {\n    luaS_resize(L, g->strt.size * 2);\n    list = &g->strt.hash[lmod(h, g->strt.size)];  /* recompute with new size */\n  }\n  ts = createstrobj(L, l, LUA_TSHRSTR, h);\n  memcpy(getstr(ts), str, l * sizeof(char));\n  ts->shrlen = cast_byte(l);\n  ts->u.hnext = *list;\n  *list = ts;\n  g->strt.nuse++;\n  return ts;\n}\n\n\n/*\n** new string (with explicit length)\n*/\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  if (l <= LUAI_MAXSHORTLEN)  /* short string? */\n    return internshrstr(L, str, l);\n  else {\n    TString *ts;\n    if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char))\n      luaM_toobig(L);\n    ts = luaS_createlngstrobj(L, l);\n    memcpy(getstr(ts), str, l * sizeof(char));\n    return ts;\n  }\n}\n\n\n/*\n** Create or reuse a zero-terminated string, first checking in the\n** cache (using the string address as a key). The cache can contain\n** only zero-terminated strings, so it is safe to use 'strcmp' to\n** check hits.\n*/\nTString *luaS_new (lua_State *L, const char *str) {\n  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */\n  int j;\n  TString **p = G(L)->strcache[i];\n  for (j = 0; j < STRCACHE_M; j++) {\n    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */\n      return p[j];  /* that is it */\n  }\n  /* normal route */\n  for (j = STRCACHE_M - 1; j > 0; j--)\n    p[j] = p[j - 1];  /* move out last element */\n  /* new element is first in the list */\n  p[0] = luaS_newlstr(L, str, strlen(str));\n  return p[0];\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s) {\n  Udata *u;\n  GCObject *o;\n  if (s > MAX_SIZE - sizeof(Udata))\n    luaM_toobig(L);\n  o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s));\n  u = gco2u(o);\n  u->len = s;\n  u->metatable = NULL;\n  setuservalue(L, u, luaO_nilobject);\n  return u;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizelstring(l)  (sizeof(union UTString) + ((l) + 1) * sizeof(char))\n\n#define sizeludata(l)\t(sizeof(union UUdata) + (l))\n#define sizeudata(u)\tsizeludata((u)->len)\n\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n\n/*\n** test whether a string is a reserved word\n*/\n#define isreserved(s)\t((s)->tt == LUA_TSHRSTR && (s)->extra > 0)\n\n\n/*\n** equality for short strings, which are always internalized\n*/\n#define eqshrstr(a,b)\tcheck_exp((a)->tt == LUA_TSHRSTR, (a) == (b))\n\n\nLUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);\nLUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);\nLUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC void luaS_clearcache (global_State *g);\nLUAI_FUNC void luaS_init (lua_State *L);\nLUAI_FUNC void luaS_remove (lua_State *L, TString *ts);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\nLUAI_FUNC TString *luaS_new (lua_State *L, const char *str);\nLUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.254.1.1 2017/04/19 17:29:57 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <float.h>\n#include <limits.h>\n#include <locale.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** maximum number of captures that a pattern can do during\n** pattern-matching. This limit is arbitrary, but must fit in\n** an unsigned char.\n*/\n#if !defined(LUA_MAXCAPTURES)\n#define LUA_MAXCAPTURES\t\t32\n#endif\n\n\n/* macro to 'unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n\n/*\n** Some sizes are better limited to fit in 'int', but must also fit in\n** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)\n*/\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n#define MAXSIZE  \\\n\t(sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))\n\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, (lua_Integer)l);\n  return 1;\n}\n\n\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer start = posrelat(luaL_checkinteger(L, 2), l);\n  lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (lua_Integer)l) end = l;\n  if (start <= end)\n    lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l, i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i = 0; i < l; i++)\n    p[i] = s[l - i - 1];\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = tolower(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = toupper(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_rep (lua_State *L) {\n  size_t l, lsep;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer n = luaL_checkinteger(L, 2);\n  const char *sep = luaL_optlstring(L, 3, \"\", &lsep);\n  if (n <= 0) lua_pushliteral(L, \"\");\n  else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */\n    return luaL_error(L, \"resulting string too large\");\n  else {\n    size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;\n    luaL_Buffer b;\n    char *p = luaL_buffinitsize(L, &b, totallen);\n    while (n-- > 1) {  /* first n-1 copies (followed by separator) */\n      memcpy(p, s, l * sizeof(char)); p += l;\n      if (lsep > 0) {  /* empty 'memcpy' is not that cheap */\n        memcpy(p, sep, lsep * sizeof(char));\n        p += lsep;\n      }\n    }\n    memcpy(p, s, l * sizeof(char));  /* last copy (not followed by separator) */\n    luaL_pushresultsize(&b, totallen);\n  }\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi < 1) posi = 1;\n  if (pose > (lua_Integer)l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* arithmetic overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  char *p = luaL_buffinitsize(L, &b, n);\n  for (i=1; i<=n; i++) {\n    lua_Integer c = luaL_checkinteger(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"value out of range\");\n    p[i - 1] = uchar(c);\n  }\n  luaL_pushresultsize(&b, n);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void *b, size_t size, void *B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer *) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  int strip = lua_toboolean(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b, strip) != 0)\n    return luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end ('\\0') of source string */\n  const char *p_end;  /* end ('\\0') of pattern */\n  lua_State *L;\n  int matchdepth;  /* control for recursive depth (to avoid C stack overflow) */\n  unsigned char level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n/* recursive function */\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\n/* maximum recursion depth for 'match' */\n#if !defined(MAXCCALLS)\n#define MAXCCALLS\t200\n#endif\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index %%%d\", l + 1);\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (p == ms->p_end)\n        luaL_error(ms->L, \"malformed pattern (ends with '%%')\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a ']' */\n        if (p == ms->p_end)\n          luaL_error(ms->L, \"malformed pattern (missing ']')\");\n        if (*(p++) == L_ESC && p < ms->p_end)\n          p++;  /* skip escapes (e.g. '%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'g' : res = isgraph(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;  /* deprecated option */\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the '^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (MatchState *ms, const char *s, const char *p,\n                        const char *ep) {\n  if (s >= ms->src_end)\n    return 0;\n  else {\n    int c = uchar(*s);\n    switch (*p) {\n      case '.': return 1;  /* matches any char */\n      case L_ESC: return match_class(c, uchar(*(p+1)));\n      case '[': return matchbracketclass(c, p, ep-1);\n      default:  return (uchar(*p) == c);\n    }\n  }\n}\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (p >= ms->p_end - 1)\n    luaL_error(ms->L, \"malformed pattern (missing arguments to '%%b')\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while (singlematch(ms, s + i, p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (singlematch(ms, s, p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  if (ms->matchdepth-- == 0)\n    luaL_error(ms->L, \"pattern too complex\");\n  init: /* using goto's to optimize tail recursion */\n  if (p != ms->p_end) {  /* end of pattern? */\n    switch (*p) {\n      case '(': {  /* start capture */\n        if (*(p + 1) == ')')  /* position capture? */\n          s = start_capture(ms, s, p + 2, CAP_POSITION);\n        else\n          s = start_capture(ms, s, p + 1, CAP_UNFINISHED);\n        break;\n      }\n      case ')': {  /* end capture */\n        s = end_capture(ms, s, p + 1);\n        break;\n      }\n      case '$': {\n        if ((p + 1) != ms->p_end)  /* is the '$' the last char in pattern? */\n          goto dflt;  /* no; go to default */\n        s = (s == ms->src_end) ? s : NULL;  /* check end of string */\n        break;\n      }\n      case L_ESC: {  /* escaped sequences not in the format class[*+?-]? */\n        switch (*(p + 1)) {\n          case 'b': {  /* balanced string? */\n            s = matchbalance(ms, s, p + 2);\n            if (s != NULL) {\n              p += 4; goto init;  /* return match(ms, s, p + 4); */\n            }  /* else fail (s == NULL) */\n            break;\n          }\n          case 'f': {  /* frontier? */\n            const char *ep; char previous;\n            p += 2;\n            if (*p != '[')\n              luaL_error(ms->L, \"missing '[' after '%%f' in pattern\");\n            ep = classend(ms, p);  /* points to what is next */\n            previous = (s == ms->src_init) ? '\\0' : *(s - 1);\n            if (!matchbracketclass(uchar(previous), p, ep - 1) &&\n               matchbracketclass(uchar(*s), p, ep - 1)) {\n              p = ep; goto init;  /* return match(ms, s, ep); */\n            }\n            s = NULL;  /* match failed */\n            break;\n          }\n          case '0': case '1': case '2': case '3':\n          case '4': case '5': case '6': case '7':\n          case '8': case '9': {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p + 1)));\n            if (s != NULL) {\n              p += 2; goto init;  /* return match(ms, s, p + 2) */\n            }\n            break;\n          }\n          default: goto dflt;\n        }\n        break;\n      }\n      default: dflt: {  /* pattern class plus optional suffix */\n        const char *ep = classend(ms, p);  /* points to optional suffix */\n        /* does not match at least once? */\n        if (!singlematch(ms, s, p, ep)) {\n          if (*ep == '*' || *ep == '?' || *ep == '-') {  /* accept empty? */\n            p = ep + 1; goto init;  /* return match(ms, s, ep + 1); */\n          }\n          else  /* '+' or no suffix */\n            s = NULL;  /* fail */\n        }\n        else {  /* matched once */\n          switch (*ep) {  /* handle optional suffix */\n            case '?': {  /* optional */\n              const char *res;\n              if ((res = match(ms, s + 1, ep + 1)) != NULL)\n                s = res;\n              else {\n                p = ep + 1; goto init;  /* else return match(ms, s, ep + 1); */\n              }\n              break;\n            }\n            case '+':  /* 1 or more repetitions */\n              s++;  /* 1 match already done */\n              /* FALLTHROUGH */\n            case '*':  /* 0 or more repetitions */\n              s = max_expand(ms, s, p, ep);\n              break;\n            case '-':  /* 0 or more repetitions (minimum) */\n              s = min_expand(ms, s, p, ep);\n              break;\n            default:  /* no suffix */\n              s++; p = ep; goto init;  /* return match(ms, s + 1, ep); */\n          }\n        }\n        break;\n      }\n    }\n  }\n  ms->matchdepth++;\n  return s;\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative 'l1' */\n  else {\n    const char *init;  /* to search for a '*s2' inside 's1' */\n    l2--;  /* 1st char will be checked by 'memchr' */\n    l1 = l1-l2;  /* 's2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct 'l1' and 's1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index %%%d\", i + 1);\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\n/* check whether pattern has no special characters */\nstatic int nospecials (const char *p, size_t l) {\n  size_t upto = 0;\n  do {\n    if (strpbrk(p + upto, SPECIALS))\n      return 0;  /* pattern has a special character */\n    upto += strlen(p + upto) + 1;  /* may have more after \\0 */\n  } while (upto <= l);\n  return 1;  /* no special chars found */\n}\n\n\nstatic void prepstate (MatchState *ms, lua_State *L,\n                       const char *s, size_t ls, const char *p, size_t lp) {\n  ms->L = L;\n  ms->matchdepth = MAXCCALLS;\n  ms->src_init = s;\n  ms->src_end = s + ls;\n  ms->p_end = p + lp;\n}\n\n\nstatic void reprepstate (MatchState *ms) {\n  ms->level = 0;\n  lua_assert(ms->matchdepth == MAXCCALLS);\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);\n  if (init < 1) init = 1;\n  else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */\n    lua_pushnil(L);  /* cannot find anything */\n    return 1;\n  }\n  /* explicit request or no special characters? */\n  if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {\n    /* do a plain search */\n    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);\n    if (s2) {\n      lua_pushinteger(L, (s2 - s) + 1);\n      lua_pushinteger(L, (s2 - s) + lp);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    const char *s1 = s + init - 1;\n    int anchor = (*p == '^');\n    if (anchor) {\n      p++; lp--;  /* skip anchor character */\n    }\n    prepstate(&ms, L, s, ls, p, lp);\n    do {\n      const char *res;\n      reprepstate(&ms);\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, (s1 - s) + 1);  /* start */\n          lua_pushinteger(L, res - s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\n/* state for 'gmatch' */\ntypedef struct GMatchState {\n  const char *src;  /* current position */\n  const char *p;  /* pattern */\n  const char *lastmatch;  /* end of last match */\n  MatchState ms;  /* match state */\n} GMatchState;\n\n\nstatic int gmatch_aux (lua_State *L) {\n  GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));\n  const char *src;\n  gm->ms.L = L;\n  for (src = gm->src; src <= gm->ms.src_end; src++) {\n    const char *e;\n    reprepstate(&gm->ms);\n    if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {\n      gm->src = gm->lastmatch = e;\n      return push_captures(&gm->ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  GMatchState *gm;\n  lua_settop(L, 2);  /* keep them on closure to avoid being collected */\n  gm = (GMatchState *)lua_newuserdata(L, sizeof(GMatchState));\n  prepstate(&gm->ms, L, s, ls, p, lp);\n  gm->src = s; gm->p = p; gm->lastmatch = NULL;\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  lua_State *L = ms->L;\n  const char *news = lua_tolstring(L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i]))) {\n        if (news[i] != L_ESC)\n          luaL_error(L, \"invalid use of '%c' in replacement string\", L_ESC);\n        luaL_addchar(b, news[i]);\n      }\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_tolstring(L, -1, NULL);  /* if number, convert it to string */\n        lua_remove(L, -2);  /* remove original value */\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                       const char *e, int tr) {\n  lua_State *L = ms->L;\n  switch (tr) {\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n    default: {  /* LUA_TNUMBER or LUA_TSTRING */\n      add_s(ms, b, s, e);\n      return;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1));\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl, lp;\n  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */\n  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */\n  const char *lastmatch = NULL;  /* end of last match */\n  int tr = lua_type(L, 3);  /* replacement type */\n  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */\n  int anchor = (*p == '^');\n  lua_Integer n = 0;  /* replacement count */\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  if (anchor) {\n    p++; lp--;  /* skip anchor character */\n  }\n  prepstate(&ms, L, src, srcl, p, lp);\n  while (n < max_s) {\n    const char *e;\n    reprepstate(&ms);  /* (re)prepare state for new match */\n    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */\n      n++;\n      add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */\n      src = lastmatch = e;\n    }\n    else if (src < ms.src_end)  /* otherwise, skip one character */\n      luaL_addchar(&b, *src++);\n    else break;  /* end of subject */\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** STRING FORMAT\n** =======================================================\n*/\n\n#if !defined(lua_number2strx)\t/* { */\n\n/*\n** Hexadecimal floating-point formatter\n*/\n\n#include <math.h>\n\n#define SIZELENMOD\t(sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))\n\n\n/*\n** Number of bits that goes into the first digit. It can be any value\n** between 1 and 4; the following definition tries to align the number\n** to nibble boundaries by making what is left after that first digit a\n** multiple of 4.\n*/\n#define L_NBFD\t\t((l_mathlim(MANT_DIG) - 1)%4 + 1)\n\n\n/*\n** Add integer part of 'x' to buffer and return new 'x'\n*/\nstatic lua_Number adddigit (char *buff, int n, lua_Number x) {\n  lua_Number dd = l_mathop(floor)(x);  /* get integer part from 'x' */\n  int d = (int)dd;\n  buff[n] = (d < 10 ? d + '0' : d - 10 + 'a');  /* add to buffer */\n  return x - dd;  /* return what is left */\n}\n\n\nstatic int num2straux (char *buff, int sz, lua_Number x) {\n  /* if 'inf' or 'NaN', format it like '%g' */\n  if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);\n  else if (x == 0) {  /* can be -0... */\n    /* create \"0\" or \"-0\" followed by exponent */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT \"x0p+0\", (LUAI_UACNUMBER)x);\n  }\n  else {\n    int e;\n    lua_Number m = l_mathop(frexp)(x, &e);  /* 'x' fraction and exponent */\n    int n = 0;  /* character count */\n    if (m < 0) {  /* is number negative? */\n      buff[n++] = '-';  /* add signal */\n      m = -m;  /* make it positive */\n    }\n    buff[n++] = '0'; buff[n++] = 'x';  /* add \"0x\" */\n    m = adddigit(buff, n++, m * (1 << L_NBFD));  /* add first digit */\n    e -= L_NBFD;  /* this digit goes before the radix point */\n    if (m > 0) {  /* more digits? */\n      buff[n++] = lua_getlocaledecpoint();  /* add radix point */\n      do {  /* add as many digits as needed */\n        m = adddigit(buff, n++, m * 16);\n      } while (m > 0);\n    }\n    n += l_sprintf(buff + n, sz - n, \"p%+d\", e);  /* add exponent */\n    lua_assert(n < sz);\n    return n;\n  }\n}\n\n\nstatic int lua_number2strx (lua_State *L, char *buff, int sz,\n                            const char *fmt, lua_Number x) {\n  int n = num2straux(buff, sz, x);\n  if (fmt[SIZELENMOD] == 'A') {\n    int i;\n    for (i = 0; i < n; i++)\n      buff[i] = toupper(uchar(buff[i]));\n  }\n  else if (fmt[SIZELENMOD] != 'a')\n    return luaL_error(L, \"modifiers for format '%%a'/'%%A' not implemented\");\n  return n;\n}\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Maximum size of each formatted item. This maximum size is produced\n** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',\n** and '\\0') + number of decimal digits to represent maxfloat (which\n** is maximum exponent + 1). (99+3+1 then rounded to 120 for \"extra\n** expenses\", such as locale-dependent stuff)\n*/\n#define MAX_ITEM        (120 + l_mathlim(MAX_10_EXP))\n\n\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n\n/*\n** maximum size of each format specification (such as \"%-099.99d\")\n*/\n#define MAX_FORMAT\t32\n\n\nstatic void addquoted (luaL_Buffer *b, const char *s, size_t len) {\n  luaL_addchar(b, '\"');\n  while (len--) {\n    if (*s == '\"' || *s == '\\\\' || *s == '\\n') {\n      luaL_addchar(b, '\\\\');\n      luaL_addchar(b, *s);\n    }\n    else if (iscntrl(uchar(*s))) {\n      char buff[10];\n      if (!isdigit(uchar(*(s+1))))\n        l_sprintf(buff, sizeof(buff), \"\\\\%d\", (int)uchar(*s));\n      else\n        l_sprintf(buff, sizeof(buff), \"\\\\%03d\", (int)uchar(*s));\n      luaL_addstring(b, buff);\n    }\n    else\n      luaL_addchar(b, *s);\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\n\n/*\n** Ensures the 'buff' string uses a dot as the radix character.\n*/\nstatic void checkdp (char *buff, int nb) {\n  if (memchr(buff, '.', nb) == NULL) {  /* no dot? */\n    char point = lua_getlocaledecpoint();  /* try locale point */\n    char *ppoint = (char *)memchr(buff, point, nb);\n    if (ppoint) *ppoint = '.';  /* change it to a dot */\n  }\n}\n\n\nstatic void addliteral (lua_State *L, luaL_Buffer *b, int arg) {\n  switch (lua_type(L, arg)) {\n    case LUA_TSTRING: {\n      size_t len;\n      const char *s = lua_tolstring(L, arg, &len);\n      addquoted(b, s, len);\n      break;\n    }\n    case LUA_TNUMBER: {\n      char *buff = luaL_prepbuffsize(b, MAX_ITEM);\n      int nb;\n      if (!lua_isinteger(L, arg)) {  /* float? */\n        lua_Number n = lua_tonumber(L, arg);  /* write as hexa ('%a') */\n        nb = lua_number2strx(L, buff, MAX_ITEM, \"%\" LUA_NUMBER_FRMLEN \"a\", n);\n        checkdp(buff, nb);  /* ensure it uses a dot */\n      }\n      else {  /* integers */\n        lua_Integer n = lua_tointeger(L, arg);\n        const char *format = (n == LUA_MININTEGER)  /* corner case? */\n                           ? \"0x%\" LUA_INTEGER_FRMLEN \"x\"  /* use hexa */\n                           : LUA_INTEGER_FMT;  /* else use default format */\n        nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);\n      }\n      luaL_addsize(b, nb);\n      break;\n    }\n    case LUA_TNIL: case LUA_TBOOLEAN: {\n      luaL_tolstring(L, arg, NULL);\n      luaL_addvalue(b);\n      break;\n    }\n    default: {\n      luaL_argerror(L, arg, \"value has no literal form\");\n    }\n  }\n}\n\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));\n  form += (p - strfrmt) + 1;\n  *form = '\\0';\n  return p;\n}\n\n\n/*\n** add length modifier into formats\n*/\nstatic void addlenmod (char *form, const char *lenmod) {\n  size_t l = strlen(form);\n  size_t lm = strlen(lenmod);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, lenmod);\n  form[l + lm - 1] = spec;\n  form[l + lm] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format ('%...') */\n      char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */\n      int nb = 0;  /* number of bytes in added item */\n      if (++arg > top)\n        luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));\n          break;\n        }\n        case 'd': case 'i':\n        case 'o': case 'u': case 'x': case 'X': {\n          lua_Integer n = luaL_checkinteger(L, arg);\n          addlenmod(form, LUA_INTEGER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);\n          break;\n        }\n        case 'a': case 'A':\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = lua_number2strx(L, buff, MAX_ITEM, form,\n                                  luaL_checknumber(L, arg));\n          break;\n        case 'e': case 'E': case 'f':\n        case 'g': case 'G': {\n          lua_Number n = luaL_checknumber(L, arg);\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);\n          break;\n        }\n        case 'q': {\n          addliteral(L, &b, arg);\n          break;\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_tolstring(L, arg, &l);\n          if (form[2] == '\\0')  /* no modifiers? */\n            luaL_addvalue(&b);  /* keep entire string */\n          else {\n            luaL_argcheck(L, l == strlen(s), arg, \"string contains zeros\");\n            if (!strchr(form, '.') && l >= 100) {\n              /* no precision and string is too long to be formatted */\n              luaL_addvalue(&b);  /* keep entire string */\n            }\n            else {  /* format the string into 'buff' */\n              nb = l_sprintf(buff, MAX_ITEM, form, s);\n              lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */\n            }\n          }\n          break;\n        }\n        default: {  /* also treat cases 'pnLlh' */\n          return luaL_error(L, \"invalid option '%%%c' to 'format'\",\n                               *(strfrmt - 1));\n        }\n      }\n      lua_assert(nb < MAX_ITEM);\n      luaL_addsize(&b, nb);\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** PACK/UNPACK\n** =======================================================\n*/\n\n\n/* value used for padding */\n#if !defined(LUAL_PACKPADBYTE)\n#define LUAL_PACKPADBYTE\t\t0x00\n#endif\n\n/* maximum size for the binary representation of an integer */\n#define MAXINTSIZE\t16\n\n/* number of bits in a character */\n#define NB\tCHAR_BIT\n\n/* mask for one character (NB 1's) */\n#define MC\t((1 << NB) - 1)\n\n/* size of a lua_Integer */\n#define SZINT\t((int)sizeof(lua_Integer))\n\n\n/* dummy union to get native endianness */\nstatic const union {\n  int dummy;\n  char little;  /* true iff machine is little endian */\n} nativeendian = {1};\n\n\n/* dummy structure to get native alignment requirements */\nstruct cD {\n  char c;\n  union { double d; void *p; lua_Integer i; lua_Number n; } u;\n};\n\n#define MAXALIGN\t(offsetof(struct cD, u))\n\n\n/*\n** Union for serializing floats\n*/\ntypedef union Ftypes {\n  float f;\n  double d;\n  lua_Number n;\n  char buff[5 * sizeof(lua_Number)];  /* enough for any float type */\n} Ftypes;\n\n\n/*\n** information to pack/unpack stuff\n*/\ntypedef struct Header {\n  lua_State *L;\n  int islittle;\n  int maxalign;\n} Header;\n\n\n/*\n** options for pack/unpack\n*/\ntypedef enum KOption {\n  Kint,\t\t/* signed integers */\n  Kuint,\t/* unsigned integers */\n  Kfloat,\t/* floating-point numbers */\n  Kchar,\t/* fixed-length strings */\n  Kstring,\t/* strings with prefixed length */\n  Kzstr,\t/* zero-terminated strings */\n  Kpadding,\t/* padding */\n  Kpaddalign,\t/* padding for alignment */\n  Knop\t\t/* no-op (configuration or spaces) */\n} KOption;\n\n\n/*\n** Read an integer numeral from string 'fmt' or return 'df' if\n** there is no numeral\n*/\nstatic int digit (int c) { return '0' <= c && c <= '9'; }\n\nstatic int getnum (const char **fmt, int df) {\n  if (!digit(**fmt))  /* no number? */\n    return df;  /* return default value */\n  else {\n    int a = 0;\n    do {\n      a = a*10 + (*((*fmt)++) - '0');\n    } while (digit(**fmt) && a <= ((int)MAXSIZE - 9)/10);\n    return a;\n  }\n}\n\n\n/*\n** Read an integer numeral and raises an error if it is larger\n** than the maximum size for integers.\n*/\nstatic int getnumlimit (Header *h, const char **fmt, int df) {\n  int sz = getnum(fmt, df);\n  if (sz > MAXINTSIZE || sz <= 0)\n    return luaL_error(h->L, \"integral size (%d) out of limits [1,%d]\",\n                            sz, MAXINTSIZE);\n  return sz;\n}\n\n\n/*\n** Initialize Header\n*/\nstatic void initheader (lua_State *L, Header *h) {\n  h->L = L;\n  h->islittle = nativeendian.little;\n  h->maxalign = 1;\n}\n\n\n/*\n** Read and classify next option. 'size' is filled with option's size.\n*/\nstatic KOption getoption (Header *h, const char **fmt, int *size) {\n  int opt = *((*fmt)++);\n  *size = 0;  /* default */\n  switch (opt) {\n    case 'b': *size = sizeof(char); return Kint;\n    case 'B': *size = sizeof(char); return Kuint;\n    case 'h': *size = sizeof(short); return Kint;\n    case 'H': *size = sizeof(short); return Kuint;\n    case 'l': *size = sizeof(long); return Kint;\n    case 'L': *size = sizeof(long); return Kuint;\n    case 'j': *size = sizeof(lua_Integer); return Kint;\n    case 'J': *size = sizeof(lua_Integer); return Kuint;\n    case 'T': *size = sizeof(size_t); return Kuint;\n    case 'f': *size = sizeof(float); return Kfloat;\n    case 'd': *size = sizeof(double); return Kfloat;\n    case 'n': *size = sizeof(lua_Number); return Kfloat;\n    case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;\n    case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;\n    case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;\n    case 'c':\n      *size = getnum(fmt, -1);\n      if (*size == -1)\n        luaL_error(h->L, \"missing size for format option 'c'\");\n      return Kchar;\n    case 'z': return Kzstr;\n    case 'x': *size = 1; return Kpadding;\n    case 'X': return Kpaddalign;\n    case ' ': break;\n    case '<': h->islittle = 1; break;\n    case '>': h->islittle = 0; break;\n    case '=': h->islittle = nativeendian.little; break;\n    case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break;\n    default: luaL_error(h->L, \"invalid format option '%c'\", opt);\n  }\n  return Knop;\n}\n\n\n/*\n** Read, classify, and fill other details about the next option.\n** 'psize' is filled with option's size, 'notoalign' with its\n** alignment requirements.\n** Local variable 'size' gets the size to be aligned. (Kpadal option\n** always gets its full alignment, other options are limited by\n** the maximum alignment ('maxalign'). Kchar option needs no alignment\n** despite its size.\n*/\nstatic KOption getdetails (Header *h, size_t totalsize,\n                           const char **fmt, int *psize, int *ntoalign) {\n  KOption opt = getoption(h, fmt, psize);\n  int align = *psize;  /* usually, alignment follows size */\n  if (opt == Kpaddalign) {  /* 'X' gets alignment from following option */\n    if (**fmt == '\\0' || getoption(h, fmt, &align) == Kchar || align == 0)\n      luaL_argerror(h->L, 1, \"invalid next option for option 'X'\");\n  }\n  if (align <= 1 || opt == Kchar)  /* need no alignment? */\n    *ntoalign = 0;\n  else {\n    if (align > h->maxalign)  /* enforce maximum alignment */\n      align = h->maxalign;\n    if ((align & (align - 1)) != 0)  /* is 'align' not a power of 2? */\n      luaL_argerror(h->L, 1, \"format asks for alignment not power of 2\");\n    *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1);\n  }\n  return opt;\n}\n\n\n/*\n** Pack integer 'n' with 'size' bytes and 'islittle' endianness.\n** The final 'if' handles the case when 'size' is larger than\n** the size of a Lua integer, correcting the extra sign-extension\n** bytes if necessary (by default they would be zeros).\n*/\nstatic void packint (luaL_Buffer *b, lua_Unsigned n,\n                     int islittle, int size, int neg) {\n  char *buff = luaL_prepbuffsize(b, size);\n  int i;\n  buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */\n  for (i = 1; i < size; i++) {\n    n >>= NB;\n    buff[islittle ? i : size - 1 - i] = (char)(n & MC);\n  }\n  if (neg && size > SZINT) {  /* negative number need sign extension? */\n    for (i = SZINT; i < size; i++)  /* correct extra bytes */\n      buff[islittle ? i : size - 1 - i] = (char)MC;\n  }\n  luaL_addsize(b, size);  /* add result to buffer */\n}\n\n\n/*\n** Copy 'size' bytes from 'src' to 'dest', correcting endianness if\n** given 'islittle' is different from native endianness.\n*/\nstatic void copywithendian (volatile char *dest, volatile const char *src,\n                            int size, int islittle) {\n  if (islittle == nativeendian.little) {\n    while (size-- != 0)\n      *(dest++) = *(src++);\n  }\n  else {\n    dest += size - 1;\n    while (size-- != 0)\n      *(dest--) = *(src++);\n  }\n}\n\n\nstatic int str_pack (lua_State *L) {\n  luaL_Buffer b;\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  int arg = 1;  /* current argument to pack */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  lua_pushnil(L);  /* mark to separate arguments from string buffer */\n  luaL_buffinit(L, &b);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    totalsize += ntoalign + size;\n    while (ntoalign-- > 0)\n     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */\n    arg++;\n    switch (opt) {\n      case Kint: {  /* signed integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT) {  /* need overflow check? */\n          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);\n          luaL_argcheck(L, -lim <= n && n < lim, arg, \"integer overflow\");\n        }\n        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));\n        break;\n      }\n      case Kuint: {  /* unsigned integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT)  /* need overflow check? */\n          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),\n                           arg, \"unsigned overflow\");\n        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);\n        break;\n      }\n      case Kfloat: {  /* floating-point options */\n        volatile Ftypes u;\n        char *buff = luaL_prepbuffsize(&b, size);\n        lua_Number n = luaL_checknumber(L, arg);  /* get argument */\n        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */\n        else if (size == sizeof(u.d)) u.d = (double)n;\n        else u.n = n;\n        /* move 'u' to final result, correcting endianness if needed */\n        copywithendian(buff, u.buff, size, h.islittle);\n        luaL_addsize(&b, size);\n        break;\n      }\n      case Kchar: {  /* fixed-size string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, len <= (size_t)size, arg,\n                         \"string longer than given size\");\n        luaL_addlstring(&b, s, len);  /* add string */\n        while (len++ < (size_t)size)  /* pad extra space */\n          luaL_addchar(&b, LUAL_PACKPADBYTE);\n        break;\n      }\n      case Kstring: {  /* strings with length count */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, size >= (int)sizeof(size_t) ||\n                         len < ((size_t)1 << (size * NB)),\n                         arg, \"string length does not fit in given size\");\n        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */\n        luaL_addlstring(&b, s, len);\n        totalsize += len;\n        break;\n      }\n      case Kzstr: {  /* zero-terminated string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, strlen(s) == len, arg, \"string contains zeros\");\n        luaL_addlstring(&b, s, len);\n        luaL_addchar(&b, '\\0');  /* add zero at the end */\n        totalsize += len + 1;\n        break;\n      }\n      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */\n      case Kpaddalign: case Knop:\n        arg--;  /* undo increment */\n        break;\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_packsize (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    size += ntoalign;  /* total space used by option */\n    luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,\n                     \"format result too large\");\n    totalsize += size;\n    switch (opt) {\n      case Kstring:  /* strings with length count */\n      case Kzstr:    /* zero-terminated string */\n        luaL_argerror(L, 1, \"variable-length format\");\n        /* call never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:  break;\n    }\n  }\n  lua_pushinteger(L, (lua_Integer)totalsize);\n  return 1;\n}\n\n\n/*\n** Unpack an integer with 'size' bytes and 'islittle' endianness.\n** If size is smaller than the size of a Lua integer and integer\n** is signed, must do sign extension (propagating the sign to the\n** higher bits); if size is larger than the size of a Lua integer,\n** it must check the unread bytes to see whether they do not cause an\n** overflow.\n*/\nstatic lua_Integer unpackint (lua_State *L, const char *str,\n                              int islittle, int size, int issigned) {\n  lua_Unsigned res = 0;\n  int i;\n  int limit = (size  <= SZINT) ? size : SZINT;\n  for (i = limit - 1; i >= 0; i--) {\n    res <<= NB;\n    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];\n  }\n  if (size < SZINT) {  /* real size smaller than lua_Integer? */\n    if (issigned) {  /* needs sign extension? */\n      lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);\n      res = ((res ^ mask) - mask);  /* do sign extension */\n    }\n  }\n  else if (size > SZINT) {  /* must check unread bytes */\n    int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;\n    for (i = limit; i < size; i++) {\n      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)\n        luaL_error(L, \"%d-byte integer does not fit into Lua Integer\", size);\n    }\n  }\n  return (lua_Integer)res;\n}\n\n\nstatic int str_unpack (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);\n  size_t ld;\n  const char *data = luaL_checklstring(L, 2, &ld);\n  size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;\n  int n = 0;  /* number of results */\n  luaL_argcheck(L, pos <= ld, 3, \"initial position out of string\");\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);\n    if ((size_t)ntoalign + size > ~pos || pos + ntoalign + size > ld)\n      luaL_argerror(L, 2, \"data string too short\");\n    pos += ntoalign;  /* skip alignment */\n    /* stack space for item + next position */\n    luaL_checkstack(L, 2, \"too many results\");\n    n++;\n    switch (opt) {\n      case Kint:\n      case Kuint: {\n        lua_Integer res = unpackint(L, data + pos, h.islittle, size,\n                                       (opt == Kint));\n        lua_pushinteger(L, res);\n        break;\n      }\n      case Kfloat: {\n        volatile Ftypes u;\n        lua_Number num;\n        copywithendian(u.buff, data + pos, size, h.islittle);\n        if (size == sizeof(u.f)) num = (lua_Number)u.f;\n        else if (size == sizeof(u.d)) num = (lua_Number)u.d;\n        else num = u.n;\n        lua_pushnumber(L, num);\n        break;\n      }\n      case Kchar: {\n        lua_pushlstring(L, data + pos, size);\n        break;\n      }\n      case Kstring: {\n        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);\n        luaL_argcheck(L, pos + len + size <= ld, 2, \"data string too short\");\n        lua_pushlstring(L, data + pos + size, len);\n        pos += len;  /* skip string */\n        break;\n      }\n      case Kzstr: {\n        size_t len = (int)strlen(data + pos);\n        lua_pushlstring(L, data + pos, len);\n        pos += len + 1;  /* skip string plus final '\\0' */\n        break;\n      }\n      case Kpaddalign: case Kpadding: case Knop:\n        n--;  /* undo increment */\n        break;\n    }\n    pos += size;\n  }\n  lua_pushinteger(L, pos + 1);  /* next position */\n  return n + 1;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {\"pack\", str_pack},\n  {\"packsize\", str_packsize},\n  {\"unpack\", str_unpack},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* table to be metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);  /* copy table */\n  lua_setmetatable(L, -2);  /* set table as metatable for strings */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* get string library */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = string */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUAMOD_API int luaopen_string (lua_State *L) {\n  luaL_newlib(L, strlib);\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.118.1.4 2018/06/08 16:22:51 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest 'n' such that\n** more than half the slots between 1 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the 'original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <limits.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/*\n** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is\n** the largest integer such that MAXASIZE fits in an unsigned int.\n*/\n#define MAXABITS\tcast_int(sizeof(int) * CHAR_BIT - 1)\n#define MAXASIZE\t(1u << MAXABITS)\n\n/*\n** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest\n** integer such that 2^MAXHBITS fits in a signed int. (Note that the\n** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still\n** fits comfortably in an unsigned int.)\n*/\n#define MAXHBITS\t(MAXABITS - 1)\n\n\n#define hashpow2(t,n)\t\t(gnode(t, lmod((n), sizenode(t))))\n\n#define hashstr(t,str)\t\thashpow2(t, (str)->hash)\n#define hashboolean(t,p)\thashpow2(t, p)\n#define hashint(t,i)\t\thashpow2(t, i)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, point2uint(p))\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {NILCONSTANT},  /* value */\n  {{NILCONSTANT, 0}}  /* key */\n};\n\n\n/*\n** Hash for floating-point numbers.\n** The main computation should be just\n**     n = frexp(n, &i); return (n * INT_MAX) + i\n** but there are some numerical subtleties.\n** In a two-complement representation, INT_MAX does not has an exact\n** representation as a float, but INT_MIN does; because the absolute\n** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the\n** absolute value of the product 'frexp * -INT_MIN' is smaller or equal\n** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when\n** adding 'i'; the use of '~u' (instead of '-u') avoids problems with\n** INT_MIN.\n*/\n#if !defined(l_hashfloat)\nstatic int l_hashfloat (lua_Number n) {\n  int i;\n  lua_Integer ni;\n  n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);\n  if (!lua_numbertointeger(n, &ni)) {  /* is 'n' inf/-inf/NaN? */\n    lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));\n    return 0;\n  }\n  else {  /* normal case */\n    unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);\n    return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);\n  }\n}\n#endif\n\n\n/*\n** returns the 'main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMINT:\n      return hashint(t, ivalue(key));\n    case LUA_TNUMFLT:\n      return hashmod(t, l_hashfloat(fltvalue(key)));\n    case LUA_TSHRSTR:\n      return hashstr(t, tsvalue(key));\n    case LUA_TLNGSTR:\n      return hashpow2(t, luaS_hashlongstr(tsvalue(key)));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    case LUA_TLCF:\n      return hashpointer(t, fvalue(key));\n    default:\n      lua_assert(!ttisdeadkey(key));\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for 'key' if 'key' is an appropriate key to live in\n** the array part of the table, 0 otherwise.\n*/\nstatic unsigned int arrayindex (const TValue *key) {\n  if (ttisinteger(key)) {\n    lua_Integer k = ivalue(key);\n    if (0 < k && (lua_Unsigned)k <= MAXASIZE)\n      return cast(unsigned int, k);  /* 'key' is an appropriate array index */\n  }\n  return 0;  /* 'key' did not match some condition */\n}\n\n\n/*\n** returns the index of a 'key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signaled by 0.\n*/\nstatic unsigned int findindex (lua_State *L, Table *t, StkId key) {\n  unsigned int i;\n  if (ttisnil(key)) return 0;  /* first iteration */\n  i = arrayindex(key);\n  if (i != 0 && i <= t->sizearray)  /* is 'key' inside array part? */\n    return i;  /* yes; that's the index */\n  else {\n    int nx;\n    Node *n = mainposition(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in 'next' */\n      if (luaV_rawequalobj(gkey(n), key) ||\n            (ttisdeadkey(gkey(n)) && iscollectable(key) &&\n             deadvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return (i + 1) + t->sizearray;\n      }\n      nx = gnext(n);\n      if (nx == 0)\n        luaG_runerror(L, \"invalid key to 'next'\");  /* key not found */\n      else n += nx;\n    }\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  unsigned int i = findindex(L, t, key);  /* find original element */\n  for (; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setivalue(key, i + 1);\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) {  /* hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, gkey(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n/*\n** Compute the optimal size for the array part of table 't'. 'nums' is a\n** \"count array\" where 'nums[i]' is the number of integers in the table\n** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of\n** integer keys in the table and leaves with the number of keys that\n** will go to the array part; return the optimal size.\n*/\nstatic unsigned int computesizes (unsigned int nums[], unsigned int *pna) {\n  int i;\n  unsigned int twotoi;  /* 2^i (candidate for optimal size) */\n  unsigned int a = 0;  /* number of elements smaller than 2^i */\n  unsigned int na = 0;  /* number of elements to go to array part */\n  unsigned int optimal = 0;  /* optimal size for array part */\n  /* loop while keys can fill more than half of total size */\n  for (i = 0, twotoi = 1;\n       twotoi > 0 && *pna > twotoi / 2;\n       i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        optimal = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements up to 'optimal' will go to array part */\n      }\n    }\n  }\n  lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);\n  *pna = na;\n  return optimal;\n}\n\n\nstatic int countint (const TValue *key, unsigned int *nums) {\n  unsigned int k = arrayindex(key);\n  if (k != 0) {  /* is 'key' an appropriate array index? */\n    nums[luaO_ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Count keys in array part of table 't': Fill 'nums[i]' with\n** number of keys that will go into corresponding slice and return\n** total number of non-nil keys.\n*/\nstatic unsigned int numusearray (const Table *t, unsigned int *nums) {\n  int lg;\n  unsigned int ttlg;  /* 2^lg */\n  unsigned int ause = 0;  /* summation of 'nums' */\n  unsigned int i = 1;  /* count to traverse all array keys */\n  /* traverse each slice */\n  for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {\n    unsigned int lc = 0;  /* counter */\n    unsigned int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg - 1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* elements added to 'nums' (can go to array part) */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(gkey(n), nums);\n      totaluse++;\n    }\n  }\n  *pna += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, unsigned int size) {\n  unsigned int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic void setnodevector (lua_State *L, Table *t, unsigned int size) {\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common 'dummynode' */\n    t->lsizenode = 0;\n    t->lastfree = NULL;  /* signal that it is using dummy node */\n  }\n  else {\n    int i;\n    int lsize = luaO_ceillog2(size);\n    if (lsize > MAXHBITS)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i = 0; i < (int)size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = 0;\n      setnilvalue(wgkey(n));\n      setnilvalue(gval(n));\n    }\n    t->lsizenode = cast_byte(lsize);\n    t->lastfree = gnode(t, size);  /* all positions are free */\n  }\n}\n\n\ntypedef struct {\n  Table *t;\n  unsigned int nhsize;\n} AuxsetnodeT;\n\n\nstatic void auxsetnode (lua_State *L, void *ud) {\n  AuxsetnodeT *asn = cast(AuxsetnodeT *, ud);\n  setnodevector(L, asn->t, asn->nhsize);\n}\n\n\nvoid luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                          unsigned int nhsize) {\n  unsigned int i;\n  int j;\n  AuxsetnodeT asn;\n  unsigned int oldasize = t->sizearray;\n  int oldhsize = allocsizenode(t);\n  Node *nold = t->node;  /* save old hash ... */\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  /* create new hash part with appropriate size */\n  asn.t = t; asn.nhsize = nhsize;\n  if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) {  /* mem. error? */\n    setarrayvector(L, t, oldasize);  /* array back to its original size */\n    luaD_throw(L, LUA_ERRMEM);  /* rethrow memory error */\n  }\n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        luaH_setint(L, t, i + 1, &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n  /* re-insert elements from hash part */\n  for (j = oldhsize - 1; j >= 0; j--) {\n    Node *old = nold + j;\n    if (!ttisnil(gval(old))) {\n      /* doesn't need barrier/invalidate cache, as entry was\n         already present in the table */\n      setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));\n    }\n  }\n  if (oldhsize > 0)  /* not the dummy node? */\n    luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {\n  int nsize = allocsizenode(t);\n  luaH_resize(L, t, nasize, nsize);\n}\n\n/*\n** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i\n*/\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  unsigned int asize;  /* optimal size for array part */\n  unsigned int na;  /* number of keys in the array part */\n  unsigned int nums[MAXABITS + 1];\n  int i;\n  int totaluse;\n  for (i = 0; i <= MAXABITS; i++) nums[i] = 0;  /* reset counts */\n  na = numusearray(t, nums);  /* count keys in array part */\n  totaluse = na;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &na);  /* count keys in hash part */\n  /* count extra key */\n  na += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  asize = computesizes(nums, &na);\n  /* resize the table to new computed sizes */\n  luaH_resize(L, t, asize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));\n  Table *t = gco2t(o);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  t->array = NULL;\n  t->sizearray = 0;\n  setnodevector(L, t, 0);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (!isdummy(t))\n    luaM_freearray(L, t->node, cast(size_t, sizenode(t)));\n  luaM_freearray(L, t->array, t->sizearray);\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  if (!isdummy(t)) {\n    while (t->lastfree > t->node) {\n      t->lastfree--;\n      if (ttisnil(gkey(t->lastfree)))\n        return t->lastfree;\n    }\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main\n** position is free. If not, check whether colliding node is in its main\n** position or not: if it is not, move colliding node to an empty place and\n** put new key in its main position; otherwise (colliding node is in its main\n** position), new key goes to an empty position.\n*/\nTValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp;\n  TValue aux;\n  if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n  else if (ttisfloat(key)) {\n    lua_Integer k;\n    if (luaV_tointeger(key, &k, 0)) {  /* does index fit in an integer? */\n      setivalue(&aux, k);\n      key = &aux;  /* insert it as an integer */\n    }\n    else if (luai_numisnan(fltvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n  }\n  mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || isdummy(t)) {  /* main position is taken? */\n    Node *othern;\n    Node *f = getfreepos(t);  /* get a free place */\n    if (f == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      /* whatever called 'newkey' takes care of TM cache */\n      return luaH_set(L, t, key);  /* insert key into grown table */\n    }\n    lua_assert(!isdummy(t));\n    othern = mainposition(t, gkey(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (othern + gnext(othern) != mp)  /* find previous */\n        othern += gnext(othern);\n      gnext(othern) = cast_int(f - othern);  /* rechain to point to 'f' */\n      *f = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      if (gnext(mp) != 0) {\n        gnext(f) += cast_int(mp - f);  /* correct 'next' */\n        gnext(mp) = 0;  /* now 'mp' is free */\n      }\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      if (gnext(mp) != 0)\n        gnext(f) = cast_int((mp + gnext(mp)) - f);  /* chain new position */\n      else lua_assert(gnext(f) == 0);\n      gnext(mp) = cast_int(f - mp);\n      mp = f;\n    }\n  }\n  setnodekey(L, &mp->i_key, key);\n  luaC_barrierback(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getint (Table *t, lua_Integer key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (l_castS2U(key) - 1 < t->sizearray)\n    return &t->array[key - 1];\n  else {\n    Node *n = hashint(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)\n        return gval(n);  /* that's it */\n      else {\n        int nx = gnext(n);\n        if (nx == 0) break;\n        n += nx;\n      }\n    }\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for short strings\n*/\nconst TValue *luaH_getshortstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  lua_assert(key->tt == LUA_TSHRSTR);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    const TValue *k = gkey(n);\n    if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\n/*\n** \"Generic\" get version. (Not that generic: not valid for integers,\n** which may be in array part, nor for floats with integral values.)\n*/\nstatic const TValue *getgeneric (Table *t, const TValue *key) {\n  Node *n = mainposition(t, key);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (luaV_rawequalobj(gkey(n), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return luaO_nilobject;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  if (key->tt == LUA_TSHRSTR)\n    return luaH_getshortstr(t, key);\n  else {  /* for long strings, use generic case */\n    TValue ko;\n    setsvalue(cast(lua_State *, NULL), &ko, key);\n    return getgeneric(t, &ko);\n  }\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));\n    case LUA_TNUMINT: return luaH_getint(t, ivalue(key));\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TNUMFLT: {\n      lua_Integer k;\n      if (luaV_tointeger(key, &k, 0)) /* index is int? */\n        return luaH_getint(t, k);  /* use specialized version */\n      /* else... */\n    }  /* FALLTHROUGH */\n    default:\n      return getgeneric(t, key);\n  }\n}\n\n\n/*\n** beware: when using this function you probably need to check a GC\n** barrier and invalidate the TM cache.\n*/\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else return luaH_newkey(L, t, key);\n}\n\n\nvoid luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {\n  const TValue *p = luaH_getint(t, key);\n  TValue *cell;\n  if (p != luaO_nilobject)\n    cell = cast(TValue *, p);\n  else {\n    TValue k;\n    setivalue(&k, key);\n    cell = luaH_newkey(L, t, &k);\n  }\n  setobj2t(L, cell, value);\n}\n\n\nstatic lua_Unsigned unbound_search (Table *t, lua_Unsigned j) {\n  lua_Unsigned i = j;  /* i is zero or a present index */\n  j++;\n  /* find 'i' and 'j' such that i is present and j is not */\n  while (!ttisnil(luaH_getint(t, j))) {\n    i = j;\n    if (j > l_castS2U(LUA_MAXINTEGER) / 2) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getint(t, i))) i++;\n      return i - 1;\n    }\n    j *= 2;\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    lua_Unsigned m = (i+j)/2;\n    if (ttisnil(luaH_getint(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table 't'. A 'boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nlua_Unsigned luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (isdummy(t))  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (const Table *t) { return isdummy(t); }\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n\n/* 'const' to avoid wrong writings that can mess up field 'next' */\n#define gkey(n)\t\tcast(const TValue*, (&(n)->i_key.tvk))\n\n/*\n** writable version of 'gkey'; allows updates to individual fields,\n** but not to the whole (which has incompatible type)\n*/\n#define wgkey(n)\t\t(&(n)->i_key.nk)\n\n#define invalidateTMcache(t)\t((t)->flags = 0)\n\n\n/* true when 't' is using 'dummynode' as its hash part */\n#define isdummy(t)\t\t((t)->lastfree == NULL)\n\n\n/* allocated size for hash nodes */\n#define allocsizenode(t)\t(isdummy(t) ? 0 : sizenode(t))\n\n\n/* returns the key, given the value of a table entry */\n#define keyfromval(v) \\\n  (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))\n\n\nLUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);\nLUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,\n                                                    TValue *value);\nLUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L);\nLUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                                    unsigned int nhsize);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC lua_Unsigned luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (const Table *t);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.93.1.1 2017/04/19 17:20:42 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** Operations that an object must define to mimic a table\n** (some functions only need some of them)\n*/\n#define TAB_R\t1\t\t\t/* read */\n#define TAB_W\t2\t\t\t/* write */\n#define TAB_L\t4\t\t\t/* length */\n#define TAB_RW\t(TAB_R | TAB_W)\t\t/* read/write */\n\n\n#define aux_getn(L,n,w)\t(checktab(L, n, (w) | TAB_L), luaL_len(L, n))\n\n\nstatic int checkfield (lua_State *L, const char *key, int n) {\n  lua_pushstring(L, key);\n  return (lua_rawget(L, -n) != LUA_TNIL);\n}\n\n\n/*\n** Check that 'arg' either is a table or can behave like one (that is,\n** has a metatable with the required metamethods)\n*/\nstatic void checktab (lua_State *L, int arg, int what) {\n  if (lua_type(L, arg) != LUA_TTABLE) {  /* is it not a table? */\n    int n = 1;  /* number of elements to pop */\n    if (lua_getmetatable(L, arg) &&  /* must have metatable */\n        (!(what & TAB_R) || checkfield(L, \"__index\", ++n)) &&\n        (!(what & TAB_W) || checkfield(L, \"__newindex\", ++n)) &&\n        (!(what & TAB_L) || checkfield(L, \"__len\", ++n))) {\n      lua_pop(L, n);  /* pop metatable and tested metamethods */\n    }\n    else\n      luaL_checktype(L, arg, LUA_TTABLE);  /* force an error */\n  }\n}\n\n\n#if defined(LUA_COMPAT_MAXN)\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n#endif\n\n\nstatic int tinsert (lua_State *L) {\n  lua_Integer e = aux_getn(L, 1, TAB_RW) + 1;  /* first empty element */\n  lua_Integer pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      lua_Integer i;\n      pos = luaL_checkinteger(L, 2);  /* 2nd argument is the position */\n      luaL_argcheck(L, 1 <= pos && pos <= e, 2, \"position out of bounds\");\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_geti(L, 1, i - 1);\n        lua_seti(L, 1, i);  /* t[i] = t[i - 1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to 'insert'\");\n    }\n  }\n  lua_seti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  lua_Integer size = aux_getn(L, 1, TAB_RW);\n  lua_Integer pos = luaL_optinteger(L, 2, size);\n  if (pos != size)  /* validate 'pos' if given */\n    luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, \"position out of bounds\");\n  lua_geti(L, 1, pos);  /* result = t[pos] */\n  for ( ; pos < size; pos++) {\n    lua_geti(L, 1, pos + 1);\n    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */\n  }\n  lua_pushnil(L);\n  lua_seti(L, 1, pos);  /* t[pos] = nil */\n  return 1;\n}\n\n\n/*\n** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever\n** possible, copy in increasing order, which is better for rehashing.\n** \"possible\" means destination after original range, or smaller\n** than origin, or copying to another table.\n*/\nstatic int tmove (lua_State *L) {\n  lua_Integer f = luaL_checkinteger(L, 2);\n  lua_Integer e = luaL_checkinteger(L, 3);\n  lua_Integer t = luaL_checkinteger(L, 4);\n  int tt = !lua_isnoneornil(L, 5) ? 5 : 1;  /* destination table */\n  checktab(L, 1, TAB_R);\n  checktab(L, tt, TAB_W);\n  if (e >= f) {  /* otherwise, nothing to move */\n    lua_Integer n, i;\n    luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,\n                  \"too many elements to move\");\n    n = e - f + 1;  /* number of elements to move */\n    luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,\n                  \"destination wrap around\");\n    if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {\n      for (i = 0; i < n; i++) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n    else {\n      for (i = n - 1; i >= 0; i--) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n  }\n  lua_pushvalue(L, tt);  /* return destination table */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {\n  lua_geti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for 'concat'\",\n                  luaL_typename(L, -1), i);\n  luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  lua_Integer last = aux_getn(L, 1, TAB_R);\n  size_t lsep;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  lua_Integer i = luaL_optinteger(L, 3, 1);\n  last = luaL_optinteger(L, 4, last);\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Pack/unpack\n** =======================================================\n*/\n\nstatic int pack (lua_State *L) {\n  int i;\n  int n = lua_gettop(L);  /* number of elements to pack */\n  lua_createtable(L, n, 1);  /* create result table */\n  lua_insert(L, 1);  /* put it at index 1 */\n  for (i = n; i >= 1; i--)  /* assign elements */\n    lua_seti(L, 1, i);\n  lua_pushinteger(L, n);\n  lua_setfield(L, 1, \"n\");  /* t.n = number of elements */\n  return 1;  /* return table */\n}\n\n\nstatic int unpack (lua_State *L) {\n  lua_Unsigned n;\n  lua_Integer i = luaL_optinteger(L, 2, 1);\n  lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */\n  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, (int)(++n)))\n    return luaL_error(L, \"too many results to unpack\");\n  for (; i < e; i++) {  /* push arg[i..e - 1] (to avoid overflows) */\n    lua_geti(L, 1, i);\n  }\n  lua_geti(L, 1, e);  /* push last element */\n  return (int)n;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on 'Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n** =======================================================\n*/\n\n\n/* type for array indices */\ntypedef unsigned int IdxT;\n\n\n/*\n** Produce a \"random\" 'unsigned int' to randomize pivot choice. This\n** macro is used only when 'sort' detects a big imbalance in the result\n** of a partition. (If you don't want/need this \"randomness\", ~0 is a\n** good choice.)\n*/\n#if !defined(l_randomizePivot)\t\t/* { */\n\n#include <time.h>\n\n/* size of 'e' measured in number of 'unsigned int's */\n#define sof(e)\t\t(sizeof(e) / sizeof(unsigned int))\n\n/*\n** Use 'time' and 'clock' as sources of \"randomness\". Because we don't\n** know the types 'clock_t' and 'time_t', we cannot cast them to\n** anything without risking overflows. A safe way to use their values\n** is to copy them to an array of a known type and use the array values.\n*/\nstatic unsigned int l_randomizePivot (void) {\n  clock_t c = clock();\n  time_t t = time(NULL);\n  unsigned int buff[sof(c) + sof(t)];\n  unsigned int i, rnd = 0;\n  memcpy(buff, &c, sof(c) * sizeof(unsigned int));\n  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));\n  for (i = 0; i < sof(buff); i++)\n    rnd += buff[i];\n  return rnd;\n}\n\n#endif\t\t\t\t\t/* } */\n\n\n/* arrays larger than 'RANLIMIT' may use randomized pivots */\n#define RANLIMIT\t100u\n\n\nstatic void set2 (lua_State *L, IdxT i, IdxT j) {\n  lua_seti(L, 1, i);\n  lua_seti(L, 1, j);\n}\n\n\n/*\n** Return true iff value at stack index 'a' is less than the value at\n** index 'b' (according to the order of the sort).\n*/\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (lua_isnil(L, 2))  /* no function? */\n    return lua_compare(L, a, b, LUA_OPLT);  /* a < b */\n  else {  /* function */\n    int res;\n    lua_pushvalue(L, 2);    /* push function */\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and 'a' */\n    lua_call(L, 2, 1);      /* call function */\n    res = lua_toboolean(L, -1);  /* get result */\n    lua_pop(L, 1);          /* pop result */\n    return res;\n  }\n}\n\n\n/*\n** Does the partition: Pivot P is at the top of the stack.\n** precondition: a[lo] <= P == a[up-1] <= a[up],\n** so it only needs to do the partition from lo + 1 to up - 2.\n** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]\n** returns 'i'.\n*/\nstatic IdxT partition (lua_State *L, IdxT lo, IdxT up) {\n  IdxT i = lo;  /* will be incremented before first use */\n  IdxT j = up - 1;  /* will be decremented before first use */\n  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */\n  for (;;) {\n    /* next loop: repeat ++i while a[i] < P */\n    while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {\n      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[i] */\n    }\n    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */\n    /* next loop: repeat --j while P < a[j] */\n    while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {\n      if (j < i)  /* j < i  but  a[j] > P ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[j] */\n    }\n    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */\n    if (j < i) {  /* no elements out of place? */\n      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */\n      lua_pop(L, 1);  /* pop a[j] */\n      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */\n      set2(L, up - 1, i);\n      return i;\n    }\n    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */\n    set2(L, i, j);\n  }\n}\n\n\n/*\n** Choose an element in the middle (2nd-3th quarters) of [lo,up]\n** \"randomized\" by 'rnd'\n*/\nstatic IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {\n  IdxT r4 = (up - lo) / 4;  /* range/4 */\n  IdxT p = rnd % (r4 * 2) + (lo + r4);\n  lua_assert(lo + r4 <= p && p <= up - r4);\n  return p;\n}\n\n\n/*\n** QuickSort algorithm (recursive function)\n*/\nstatic void auxsort (lua_State *L, IdxT lo, IdxT up,\n                                   unsigned int rnd) {\n  while (lo < up) {  /* loop for tail recursion */\n    IdxT p;  /* Pivot index */\n    IdxT n;  /* to be used later */\n    /* sort elements 'lo', 'p', and 'up' */\n    lua_geti(L, 1, lo);\n    lua_geti(L, 1, up);\n    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */\n      set2(L, lo, up);  /* swap a[lo] - a[up] */\n    else\n      lua_pop(L, 2);  /* remove both values */\n    if (up - lo == 1)  /* only 2 elements? */\n      return;  /* already sorted */\n    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */\n      p = (lo + up)/2;  /* middle element is a good pivot */\n    else  /* for larger intervals, it is worth a random pivot */\n      p = choosePivot(lo, up, rnd);\n    lua_geti(L, 1, p);\n    lua_geti(L, 1, lo);\n    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */\n      set2(L, p, lo);  /* swap a[p] - a[lo] */\n    else {\n      lua_pop(L, 1);  /* remove a[lo] */\n      lua_geti(L, 1, up);\n      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */\n        set2(L, p, up);  /* swap a[up] - a[p] */\n      else\n        lua_pop(L, 2);\n    }\n    if (up - lo == 2)  /* only 3 elements? */\n      return;  /* already sorted */\n    lua_geti(L, 1, p);  /* get middle element (Pivot) */\n    lua_pushvalue(L, -1);  /* push Pivot */\n    lua_geti(L, 1, up - 1);  /* push a[up - 1] */\n    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */\n    p = partition(L, lo, up);\n    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */\n    if (p - lo < up - p) {  /* lower interval is smaller? */\n      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */\n      n = p - lo;  /* size of smaller interval */\n      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */\n    }\n    else {\n      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */\n      n = up - p;  /* size of smaller interval */\n      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */\n    }\n    if ((up - lo) / 128 > n) /* partition too imbalanced? */\n      rnd = l_randomizePivot();  /* try a new randomization */\n  }  /* tail call auxsort(L, lo, up, rnd) */\n}\n\n\nstatic int sort (lua_State *L) {\n  lua_Integer n = aux_getn(L, 1, TAB_RW);\n  if (n > 1) {  /* non-trivial interval? */\n    luaL_argcheck(L, n < INT_MAX, 1, \"array too big\");\n    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */\n    lua_settop(L, 2);  /* make sure there are two arguments */\n    auxsort(L, 1, (IdxT)n, 0);\n  }\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n#if defined(LUA_COMPAT_MAXN)\n  {\"maxn\", maxn},\n#endif\n  {\"insert\", tinsert},\n  {\"pack\", pack},\n  {\"unpack\", unpack},\n  {\"remove\", tremove},\n  {\"move\", tmove},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_table (lua_State *L) {\n  luaL_newlib(L, tab_funcs);\n#if defined(LUA_COMPAT_UNPACK)\n  /* _G.unpack = table.unpack */\n  lua_getfield(L, -1, \"unpack\");\n  lua_setglobal(L, \"unpack\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\nstatic const char udatatypename[] = \"userdata\";\n\nLUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {\n  \"no value\",\n  \"nil\", \"boolean\", udatatypename, \"number\",\n  \"string\", \"table\", \"function\", udatatypename, \"thread\",\n  \"proto\" /* this last case is used for tests only */\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__len\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__mod\", \"__pow\",\n    \"__div\", \"__idiv\",\n    \"__band\", \"__bor\", \"__bxor\", \"__shl\", \"__shr\",\n    \"__unm\", \"__bnot\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaC_fix(L, obj2gco(G(L)->tmname[i]));  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getshortstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttnov(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttnov(o)];\n  }\n  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n\n/*\n** Return the name of the type of an object. For tables and userdata\n** with metatable, use their '__name' metafield, if present.\n*/\nconst char *luaT_objtypename (lua_State *L, const TValue *o) {\n  Table *mt;\n  if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||\n      (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {\n    const TValue *name = luaH_getshortstr(mt, luaS_new(L, \"__name\"));\n    if (ttisstring(name))  /* is '__name' a string? */\n      return getstr(tsvalue(name));  /* use it as type name */\n  }\n  return ttypename(ttnov(o));  /* else use standard type name */\n}\n\n\nvoid luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                  const TValue *p2, TValue *p3, int hasres) {\n  ptrdiff_t result = savestack(L, p3);\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  L->top += 3;\n  if (!hasres)  /* no result? 'p3' is third argument */\n    setobj2s(L, L->top++, p3);  /* 3rd argument */\n  /* metamethod may yield only when called from Lua code */\n  if (isLua(L->ci))\n    luaD_call(L, func, hasres);\n  else\n    luaD_callnoyield(L, func, hasres);\n  if (hasres) {  /* if has result, move it to its place */\n    p3 = restorestack(L, result);\n    setobjs2s(L, p3, --L->top);\n  }\n}\n\n\nint luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  luaT_callTM(L, tm, p1, p2, res, 1);\n  return 1;\n}\n\n\nvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, res, event)) {\n    switch (event) {\n      case TM_CONCAT:\n        luaG_concaterror(L, p1, p2);\n      /* call never returns, but to avoid warnings: *//* FALLTHROUGH */\n      case TM_BAND: case TM_BOR: case TM_BXOR:\n      case TM_SHL: case TM_SHR: case TM_BNOT: {\n        lua_Number dummy;\n        if (tonumber(p1, &dummy) && tonumber(p2, &dummy))\n          luaG_tointerror(L, p1, p2);\n        else\n          luaG_opinterror(L, p1, p2, \"perform bitwise operation on\");\n      }\n      /* calls never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:\n        luaG_opinterror(L, p1, p2, \"perform arithmetic on\");\n    }\n  }\n}\n\n\nint luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      TMS event) {\n  if (!luaT_callbinTM(L, p1, p2, L->top, event))\n    return -1;  /* no metamethod */\n  else\n    return !l_isfalse(L->top);\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\" and \"ORDER OP\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_LEN,\n  TM_EQ,  /* last tag method with fast access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_MOD,\n  TM_POW,\n  TM_DIV,\n  TM_IDIV,\n  TM_BAND,\n  TM_BOR,\n  TM_BXOR,\n  TM_SHL,\n  TM_SHR,\n  TM_UNM,\n  TM_BNOT,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\n#define ttypename(x)\tluaT_typenames_[(x) + 1]\n\nLUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];\n\n\nLUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\nLUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                            const TValue *p2, TValue *p3, int hasres);\nLUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,\n                                const TValue *p2, TMS event);\n\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.230.1.1 2017/04/19 17:29:57 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n#define lua_c\n\n#include \"lprefix.h\"\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n#if !defined(LUA_PROMPT)\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n#endif\n\n#if !defined(LUA_PROGNAME)\n#define LUA_PROGNAME\t\t\"lua\"\n#endif\n\n#if !defined(LUA_MAXINPUT)\n#define LUA_MAXINPUT\t\t512\n#endif\n\n#if !defined(LUA_INIT_VAR)\n#define LUA_INIT_VAR\t\t\"LUA_INIT\"\n#endif\n\n#define LUA_INITVARVERSION\tLUA_INIT_VAR LUA_VERSUFFIX\n\n\n/*\n** lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n** is, whether we're running lua interactively).\n*/\n#if !defined(lua_stdin_is_tty)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#include <io.h>\n#include <windows.h>\n\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definition */\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** lua_readline defines how to show a prompt and then read a line from\n** the standard input.\n** lua_saveline defines how to \"save\" a read line in a \"history\".\n** lua_freeline defines how to free a line read by lua_readline.\n*/\n#if !defined(lua_readline)\t/* { */\n\n#if defined(LUA_USE_READLINE)\t/* { */\n\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,line)\t((void)L, add_history(line))\n#define lua_freeline(L,b)\t((void)L, free(b))\n\n#else\t\t\t\t/* }{ */\n\n#define lua_readline(L,b,p) \\\n        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,line)\t{ (void)L; (void)line; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n/*\n** Hook set by signal function to stop the interpreter.\n*/\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);  /* reset hook */\n  luaL_error(L, \"interrupted!\");\n}\n\n\n/*\n** Function to be called at a C signal. Because a C signal cannot\n** just change a Lua state (as there is no proper synchronization),\n** this function only sets a hook that, when called, will stop the\n** interpreter.\n*/\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (const char *badoption) {\n  lua_writestringerror(\"%s: \", progname);\n  if (badoption[1] == 'e' || badoption[1] == 'l')\n    lua_writestringerror(\"'%s' needs argument\\n\", badoption);\n  else\n    lua_writestringerror(\"unrecognized option '%s'\\n\", badoption);\n  lua_writestringerror(\n  \"usage: %s [options] [script [args]]\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string 'stat'\\n\"\n  \"  -i       enter interactive mode after executing 'script'\\n\"\n  \"  -l name  require library 'name' into global 'name'\\n\"\n  \"  -v       show version information\\n\"\n  \"  -E       ignore environment variables\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and execute stdin\\n\"\n  ,\n  progname);\n}\n\n\n/*\n** Prints an error message, adding the program name in front of it\n** (if present)\n*/\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) lua_writestringerror(\"%s: \", pname);\n  lua_writestringerror(\"%s\\n\", msg);\n}\n\n\n/*\n** Check whether 'status' is not OK and, if so, prints the error\n** message on the top of the stack. It assumes that the error object\n** is a string, as it was either generated by Lua or by 'msghandler'.\n*/\nstatic int report (lua_State *L, int status) {\n  if (status != LUA_OK) {\n    const char *msg = lua_tostring(L, -1);\n    l_message(progname, msg);\n    lua_pop(L, 1);  /* remove message */\n  }\n  return status;\n}\n\n\n/*\n** Message handler used to run all chunks\n*/\nstatic int msghandler (lua_State *L) {\n  const char *msg = lua_tostring(L, 1);\n  if (msg == NULL) {  /* is error object not a string? */\n    if (luaL_callmeta(L, 1, \"__tostring\") &&  /* does it have a metamethod */\n        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */\n      return 1;  /* that is the message */\n    else\n      msg = lua_pushfstring(L, \"(error object is a %s value)\",\n                               luaL_typename(L, 1));\n  }\n  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */\n  return 1;  /* return the traceback */\n}\n\n\n/*\n** Interface to 'lua_pcall', which sets appropriate message function\n** and C-signal handler. Used to run all chunks.\n*/\nstatic int docall (lua_State *L, int narg, int nres) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, msghandler);  /* push message handler */\n  lua_insert(L, base);  /* put it under function and args */\n  globalL = L;  /* to be available to 'laction' */\n  signal(SIGINT, laction);  /* set C-signal handler */\n  status = lua_pcall(L, narg, nres, base);\n  signal(SIGINT, SIG_DFL); /* reset C-signal handler */\n  lua_remove(L, base);  /* remove message handler from the stack */\n  return status;\n}\n\n\nstatic void print_version (void) {\n  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));\n  lua_writeline();\n}\n\n\n/*\n** Create the 'arg' table, which stores all arguments from the\n** command line ('argv'). It should be aligned so that, at index 0,\n** it has 'argv[script]', which is the script name. The arguments\n** to the script (everything after 'script') go to positive indices;\n** other arguments (before the script name) go to negative indices.\n** If there is no script name, assume interpreter's name as base.\n*/\nstatic void createargtable (lua_State *L, char **argv, int argc, int script) {\n  int i, narg;\n  if (script == argc) script = 0;  /* no script name? */\n  narg = argc - (script + 1);  /* number of positive indices */\n  lua_createtable(L, narg, script + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - script);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\n\nstatic int dochunk (lua_State *L, int status) {\n  if (status == LUA_OK) status = docall(L, 0, 0);\n  return report(L, status);\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  return dochunk(L, luaL_loadfile(L, name));\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));\n}\n\n\n/*\n** Calls 'require(name)' and stores the result in a global variable\n** with the given name.\n*/\nstatic int dolibrary (lua_State *L, const char *name) {\n  int status;\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  status = docall(L, 1, 1);  /* call 'require(name)' */\n  if (status == LUA_OK)\n    lua_setglobal(L, name);  /* global[name] = require return */\n  return report(L, status);\n}\n\n\n/*\n** Returns the string to be used as a prompt by the interpreter.\n*/\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getglobal(L, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  return p;\n}\n\n/* mark in error messages for incomplete statements */\n#define EOFMARK\t\t\"<eof>\"\n#define marklen\t\t(sizeof(EOFMARK)/sizeof(char) - 1)\n\n\n/*\n** Check whether 'status' signals a syntax error and the error\n** message at the top of the stack ends with the above mark for\n** incomplete statements.\n*/\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\n/*\n** Prompt the user, read a line, and push it into the Lua stack.\n*/\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  int readstatus = lua_readline(L, b, prmt);\n  if (readstatus == 0)\n    return 0;  /* no input (prompt will be popped by caller) */\n  lua_pop(L, 1);  /* remove prompt */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[--l] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */\n    lua_pushfstring(L, \"return %s\", b + 1);  /* change '=' to 'return' */\n  else\n    lua_pushlstring(L, b, l);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\n/*\n** Try to compile line on the stack as 'return <line>;'; on return, stack\n** has either compiled chunk or original line (if compilation failed).\n*/\nstatic int addreturn (lua_State *L) {\n  const char *line = lua_tostring(L, -1);  /* original line */\n  const char *retline = lua_pushfstring(L, \"return %s;\", line);\n  int status = luaL_loadbuffer(L, retline, strlen(retline), \"=stdin\");\n  if (status == LUA_OK) {\n    lua_remove(L, -2);  /* remove modified line */\n    if (line[0] != '\\0')  /* non empty? */\n      lua_saveline(L, line);  /* keep history */\n  }\n  else\n    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */\n  return status;\n}\n\n\n/*\n** Read multiple lines until a complete Lua statement\n*/\nstatic int multiline (lua_State *L) {\n  for (;;) {  /* repeat until gets a complete statement */\n    size_t len;\n    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */\n    int status = luaL_loadbuffer(L, line, len, \"=stdin\");  /* try it */\n    if (!incomplete(L, status) || !pushline(L, 0)) {\n      lua_saveline(L, line);  /* keep history */\n      return status;  /* cannot or should not try to add continuation line */\n    }\n    lua_pushliteral(L, \"\\n\");  /* add newline... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n}\n\n\n/*\n** Read a line and try to load (compile) it first as an expression (by\n** adding \"return \" in front of it) and second as a statement. Return\n** the final status of load/call with the resulting function (if any)\n** in the top of the stack.\n*/\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */\n    status = multiline(L);  /* try as command, maybe with continuation lines */\n  lua_remove(L, 1);  /* remove line from the stack */\n  lua_assert(lua_gettop(L) == 1);\n  return status;\n}\n\n\n/*\n** Prints (calling the Lua 'print' function) any values on the stack\n*/\nstatic void l_print (lua_State *L) {\n  int n = lua_gettop(L);\n  if (n > 0) {  /* any result to be printed? */\n    luaL_checkstack(L, LUA_MINSTACK, \"too many results to print\");\n    lua_getglobal(L, \"print\");\n    lua_insert(L, 1);\n    if (lua_pcall(L, n, 0, 0) != LUA_OK)\n      l_message(progname, lua_pushfstring(L, \"error calling 'print' (%s)\",\n                                             lua_tostring(L, -1)));\n  }\n}\n\n\n/*\n** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and\n** print any results.\n*/\nstatic void doREPL (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;  /* no 'progname' on errors in interactive mode */\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK)\n      status = docall(L, 0, LUA_MULTRET);\n    if (status == LUA_OK) l_print(L);\n    else report(L, status);\n  }\n  lua_settop(L, 0);  /* clear stack */\n  lua_writeline();\n  progname = oldprogname;\n}\n\n\n/*\n** Push on the stack the contents of table 'arg' from 1 to #arg\n*/\nstatic int pushargs (lua_State *L) {\n  int i, n;\n  if (lua_getglobal(L, \"arg\") != LUA_TTABLE)\n    luaL_error(L, \"'arg' is not a table\");\n  n = (int)luaL_len(L, -1);\n  luaL_checkstack(L, n + 3, \"too many arguments to script\");\n  for (i = 1; i <= n; i++)\n    lua_rawgeti(L, -i, i);\n  lua_remove(L, -i);  /* remove table from the stack */\n  return n;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv) {\n  int status;\n  const char *fname = argv[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    int n = pushargs(L);  /* push arguments to script */\n    status = docall(L, n, LUA_MULTRET);\n  }\n  return report(L, status);\n}\n\n\n\n/* bits of various argument indicators in 'args' */\n#define has_error\t1\t/* bad option */\n#define has_i\t\t2\t/* -i */\n#define has_v\t\t4\t/* -v */\n#define has_e\t\t8\t/* -e */\n#define has_E\t\t16\t/* -E */\n\n/*\n** Traverses all arguments from 'argv', returning a mask with those\n** needed before running any Lua code (or an error code if it finds\n** any invalid argument). 'first' returns the first not-handled argument\n** (either the script name or a bad argument in case of error).\n*/\nstatic int collectargs (char **argv, int *first) {\n  int args = 0;\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    *first = i;\n    if (argv[i][0] != '-')  /* not an option? */\n        return args;  /* stop handling options */\n    switch (argv[i][1]) {  /* else check option */\n      case '-':  /* '--' */\n        if (argv[i][2] != '\\0')  /* extra characters after '--'? */\n          return has_error;  /* invalid option */\n        *first = i + 1;\n        return args;\n      case '\\0':  /* '-' */\n        return args;  /* script \"name\" is '-' */\n      case 'E':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_E;\n        break;\n      case 'i':\n        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */\n      case 'v':\n        if (argv[i][2] != '\\0')  /* extra characters after 1st? */\n          return has_error;  /* invalid option */\n        args |= has_v;\n        break;\n      case 'e':\n        args |= has_e;  /* FALLTHROUGH */\n      case 'l':  /* both options need an argument */\n        if (argv[i][2] == '\\0') {  /* no concatenated argument? */\n          i++;  /* try next 'argv' */\n          if (argv[i] == NULL || argv[i][0] == '-')\n            return has_error;  /* no next argument or it is another option */\n        }\n        break;\n      default:  /* invalid option */\n        return has_error;\n    }\n  }\n  *first = i;  /* no script name */\n  return args;\n}\n\n\n/*\n** Processes options 'e' and 'l', which involve running Lua code.\n** Returns 0 if some code raises an error.\n*/\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    int option = argv[i][1];\n    lua_assert(argv[i][0] == '-');  /* already checked */\n    if (option == 'e' || option == 'l') {\n      int status;\n      const char *extra = argv[i] + 2;  /* both options need an argument */\n      if (*extra == '\\0') extra = argv[++i];\n      lua_assert(extra != NULL);\n      status = (option == 'e')\n               ? dostring(L, extra, \"=(command line)\")\n               : dolibrary(L, extra);\n      if (status != LUA_OK) return 0;\n    }\n  }\n  return 1;\n}\n\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *name = \"=\" LUA_INITVARVERSION;\n  const char *init = getenv(name + 1);\n  if (init == NULL) {\n    name = \"=\" LUA_INIT_VAR;\n    init = getenv(name + 1);  /* try alternative name */\n  }\n  if (init == NULL) return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, name);\n}\n\n\n/*\n** Main body of stand-alone interpreter (to be called in protected mode).\n** Reads the options and handles them all.\n*/\nstatic int pmain (lua_State *L) {\n  int argc = (int)lua_tointeger(L, 1);\n  char **argv = (char **)lua_touserdata(L, 2);\n  int script;\n  int args = collectargs(argv, &script);\n  luaL_checkversion(L);  /* check that interpreter has correct version */\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  if (args == has_error) {  /* bad arg? */\n    print_usage(argv[script]);  /* 'script' has index of bad arg. */\n    return 0;\n  }\n  if (args & has_v)  /* option '-v'? */\n    print_version();\n  if (args & has_E) {  /* option '-E'? */\n    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  luaL_openlibs(L);  /* open standard libraries */\n  createargtable(L, argv, argc, script);  /* create table 'arg' */\n  if (!(args & has_E)) {  /* no option '-E'? */\n    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */\n      return 0;  /* error running LUA_INIT */\n  }\n  if (!runargs(L, argv, script))  /* execute arguments -e and -l */\n    return 0;  /* something failed */\n  if (script < argc &&  /* execute main script (if there is one) */\n      handle_script(L, argv + script) != LUA_OK)\n    return 0;\n  if (args & has_i)  /* -i option? */\n    doREPL(L);  /* do read-eval-print loop */\n  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */\n    if (lua_stdin_is_tty()) {  /* running in interactive mode? */\n      print_version();\n      doREPL(L);  /* do read-eval-print loop */\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  lua_pushboolean(L, 1);  /* signal no errors */\n  return 1;\n}\n\n\nint main (int argc, char **argv) {\n  int status, result;\n  lua_State *L = luaL_newstate();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */\n  lua_pushinteger(L, argc);  /* 1st argument */\n  lua_pushlightuserdata(L, argv); /* 2nd argument */\n  status = lua_pcall(L, 2, 1, 0);  /* do the call */\n  result = lua_toboolean(L, -1);  /* get result */\n  report(L, status);\n  lua_close(L);\n  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $\n** Lua - A Scripting Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION_MAJOR\t\"5\"\n#define LUA_VERSION_MINOR\t\"3\"\n#define LUA_VERSION_NUM\t\t503\n#define LUA_VERSION_RELEASE\t\"5\"\n\n#define LUA_VERSION\t\"Lua \" LUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#define LUA_RELEASE\tLUA_VERSION \".\" LUA_VERSION_RELEASE\n#define LUA_COPYRIGHT\tLUA_RELEASE \"  Copyright (C) 1994-2018 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo, W. Celes\"\n\n\n/* mark for precompiled code ('<esc>Lua') */\n#define LUA_SIGNATURE\t\"\\x1bLua\"\n\n/* option for multiple returns in 'lua_pcall' and 'lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** Pseudo-indices\n** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty\n** space after that to help overflow detection)\n*/\n#define LUA_REGISTRYINDEX\t(-LUAI_MAXSTACK - 1000)\n#define lua_upvalueindex(i)\t(LUA_REGISTRYINDEX - (i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRGCMM\t5\n#define LUA_ERRERR\t6\n\n\ntypedef struct lua_State lua_State;\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n#define LUA_NUMTAGS\t\t9\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/* predefined values in the registry */\n#define LUA_RIDX_MAINTHREAD\t1\n#define LUA_RIDX_GLOBALS\t2\n#define LUA_RIDX_LAST\t\tLUA_RIDX_GLOBALS\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n/* unsigned integer type */\ntypedef LUA_UNSIGNED lua_Unsigned;\n\n/* type for continuation-function contexts */\ntypedef LUA_KCONTEXT lua_KContext;\n\n\n/*\n** Type for C functions registered with Lua\n*/\ntypedef int (*lua_CFunction) (lua_State *L);\n\n/*\n** Type for continuation functions\n*/\ntypedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);\n\n\n/*\n** Type for functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);\n\n\n/*\n** Type for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/*\n** RCS ident string\n*/\nextern const char lua_ident[];\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\nLUA_API const lua_Number *(lua_version) (lua_State *L);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_absindex) (lua_State *L, int idx);\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_rotate) (lua_State *L, int idx, int n);\nLUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);\nLUA_API int   (lua_checkstack) (lua_State *L, int n);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isinteger) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_rawlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** Comparison and arithmetic functions\n*/\n\n#define LUA_OPADD\t0\t/* ORDER TM, ORDER OP */\n#define LUA_OPSUB\t1\n#define LUA_OPMUL\t2\n#define LUA_OPMOD\t3\n#define LUA_OPPOW\t4\n#define LUA_OPDIV\t5\n#define LUA_OPIDIV\t6\n#define LUA_OPBAND\t7\n#define LUA_OPBOR\t8\n#define LUA_OPBXOR\t9\n#define LUA_OPSHL\t10\n#define LUA_OPSHR\t11\n#define LUA_OPUNM\t12\n#define LUA_OPBNOT\t13\n\nLUA_API void  (lua_arith) (lua_State *L, int op);\n\n#define LUA_OPEQ\t0\n#define LUA_OPLT\t1\n#define LUA_OPLE\t2\n\nLUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void        (lua_pushnil) (lua_State *L);\nLUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);\nLUA_API const char *(lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API int (lua_getglobal) (lua_State *L, const char *name);\nLUA_API int (lua_gettable) (lua_State *L, int idx);\nLUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawget) (lua_State *L, int idx);\nLUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);\n\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API int  (lua_getuservalue) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_setglobal) (lua_State *L, const char *name);\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_seti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_setuservalue) (lua_State *L, int idx);\n\n\n/*\n** 'load' and 'call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,\n                           lua_KContext ctx, lua_KFunction k);\n#define lua_call(L,n,r)\t\tlua_callk(L, (n), (r), 0, NULL)\n\nLUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,\n                            lua_KContext ctx, lua_KFunction k);\n#define lua_pcall(L,n,r,f)\tlua_pcallk(L, (n), (r), (f), 0, NULL)\n\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                          const char *chunkname, const char *mode);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yieldk)     (lua_State *L, int nresults, lua_KContext ctx,\n                               lua_KFunction k);\nLUA_API int  (lua_resume)     (lua_State *L, lua_State *from, int narg);\nLUA_API int  (lua_status)     (lua_State *L);\nLUA_API int (lua_isyieldable) (lua_State *L);\n\n#define lua_yield(L,n)\t\tlua_yieldk(L, (n), 0, NULL)\n\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\nLUA_API void  (lua_len)    (lua_State *L, int idx);\n\nLUA_API size_t   (lua_stringtonumber) (lua_State *L, const char *s);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** {==============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_getextraspace(L)\t((void *)((char *)(L) - LUA_EXTRASPACE))\n\n#define lua_tonumber(L,i)\tlua_tonumberx(L,(i),NULL)\n#define lua_tointeger(L,i)\tlua_tointegerx(L,(i),NULL)\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\tlua_pushstring(L, \"\" s)\n\n#define lua_pushglobaltable(L)  \\\n\t((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n#define lua_insert(L,idx)\tlua_rotate(L, (idx), 1)\n\n#define lua_remove(L,idx)\t(lua_rotate(L, (idx), -1), lua_pop(L, 1))\n\n#define lua_replace(L,idx)\t(lua_copy(L, -1, (idx)), lua_pop(L, 1))\n\n/* }============================================================== */\n\n\n/*\n** {==============================================================\n** compatibility macros for unsigned conversions\n** ===============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define lua_pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define lua_tounsignedx(L,i,is)\t((lua_Unsigned)lua_tointegerx(L,i,is))\n#define lua_tounsigned(L,i)\tlua_tounsignedx(L,(i),NULL)\n\n#endif\n/* }============================================================== */\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILCALL 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debugger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);\nLUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);\nLUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);\n\nLUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);\nLUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,\n                                               int fidx2, int n2);\n\nLUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook (lua_gethook) (lua_State *L);\nLUA_API int (lua_gethookmask) (lua_State *L);\nLUA_API int (lua_gethookcount) (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) 'global', 'local', 'field', 'method' */\n  const char *what;\t/* (S) 'Lua', 'C', 'main', 'tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  unsigned char nups;\t/* (u) number of upvalues */\n  unsigned char nparams;/* (u) number of parameters */\n  char isvararg;        /* (u) */\n  char istailcall;\t/* (t) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  struct CallInfo *i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2018 Lua.org, PUC-Rio.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "build/lua-5.3.5/src/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $\n** Lua compiler (saves bytecodes to files; also lists bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\nstatic void PrintFunction(const Proto* f, int full);\n#define luaU_print\tPrintFunction\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define OUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option '%s'\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n  \"usage: %s [options] [filenames]\\n\"\n  \"Available options are:\\n\"\n  \"  -l       list (use -l -l for full listing)\\n\"\n  \"  -o name  output to file 'name' (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and process stdin\\n\"\n  ,progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define IS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))\n    usage(\"'-o' needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s\\n\",LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define FUNCTION \"(function()end)();\"\n\nstatic const char* reader(lua_State *L, void *ud, size_t *size)\n{\n UNUSED(L);\n if ((*(int*)ud)--)\n {\n  *size=sizeof(FUNCTION)-1;\n  return FUNCTION;\n }\n else\n {\n  *size=0;\n  return NULL;\n }\n}\n\n#define toproto(L,i) getproto(L->top+(i))\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  Proto* f;\n  int i=n;\n  if (lua_load(L,reader,&i,\"=(\" PROGNAME \")\",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));\n  f=toproto(L,-1);\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;\n  }\n  f->sizelineinfo=0;\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstatic int pmain(lua_State* L)\n{\n int argc=(int)lua_tointeger(L,1);\n char** argv=(char**)lua_touserdata(L,2);\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=luaL_newstate();\n if (L==NULL) fatal(\"cannot create state: not enough memory\");\n lua_pushcfunction(L,&pmain);\n lua_pushinteger(L,argc);\n lua_pushlightuserdata(L,argv);\n if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n\n/*\n** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=tsslen(ts);\n printf(\"%c\",'\"');\n for (i=0; i<n; i++)\n {\n  int c=(int)(unsigned char)s[i];\n  switch (c)\n  {\n   case '\"':  printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint(c))\n   \t\t\tprintf(\"%c\",c);\n\t\telse\n\t\t\tprintf(\"\\\\%03d\",c);\n  }\n }\n printf(\"%c\",'\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMFLT:\n\t{\n\tchar buff[100];\n\tsprintf(buff,LUA_NUMBER_FMT,fltvalue(o));\n\tprintf(\"%s\",buff);\n\tif (buff[strspn(buff,\"-0123456789\")]=='\\0') printf(\".0\");\n\tbreak;\n\t}\n  case LUA_TNUMINT:\n\tprintf(LUA_INTEGER_FMT,ivalue(o));\n\tbreak;\n  case LUA_TSHRSTR: case LUA_TLNGSTR:\n\tPrintString(tsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\n#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : \"-\")\n#define MYK(x)\t\t(-1-(x))\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int ax=GETARG_Ax(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getfuncline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (MYK(INDEXK(b))) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (MYK(INDEXK(c))) : c);\n    break;\n   case iABx:\n    printf(\"%d\",a);\n    if (getBMode(o)==OpArgK) printf(\" %d\",MYK(bx));\n    if (getBMode(o)==OpArgU) printf(\" %d\",bx);\n    break;\n   case iAsBx:\n    printf(\"%d %d\",a,sbx);\n    break;\n   case iAx:\n    printf(\"%d\",MYK(ax));\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    break;\n   case OP_GETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(b));\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABUP:\n    printf(\"\\t; %s\",UPVALNAME(a));\n    if (ISK(b)) { printf(\" \"); PrintConstant(f,INDEXK(b)); }\n    if (ISK(c)) { printf(\" \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_MOD:\n   case OP_POW:\n   case OP_DIV:\n   case OP_IDIV:\n   case OP_BAND:\n   case OP_BOR:\n   case OP_BXOR:\n   case OP_SHL:\n   case OP_SHR:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n   case OP_TFORLOOP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]); else printf(\"\\t; %d\",c);\n    break;\n   case OP_EXTRAARG:\n    printf(\"\\t; \"); PrintConstant(f,ax);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t((x==1)?\"\":\"s\")\n#define S(x)\t(int)(x),SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=f->source ? getstr(f->source) : \"=?\";\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\t(int)(f->numparams),f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->sizeupvalues));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintDebug(const Proto* f)\n{\n int i,n;\n n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);\n }\n}\n\nstatic void PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full) PrintDebug(f);\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "build/lua-5.3.5/src/luaconf.h.in",
    "content": "/*\n** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ===================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n** {====================================================================\n** System Configuration: macros to adapt (if needed) Lua to some\n** particular platform, for instance compiling it with 32-bit numbers or\n** restricting it to C89.\n** =====================================================================\n*/\n\n/*\n@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You\n** can also define LUA_32BITS in the make file, but changing here you\n** ensure that all software connected to Lua will be compiled with the\n** same configuration.\n*/\n/* #define LUA_32BITS */\n\n\n/*\n@@ LUA_USE_C89 controls the use of non-ISO-C89 features.\n** Define it if you want Lua to avoid the use of a few C99 features\n** or Windows-specific features on Windows.\n*/\n/* #define LUA_USE_C89 */\n\n\n/*\n** By default, Lua on Windows use (some) specific Windows features\n*/\n#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)\n#define LUA_USE_WINDOWS  /* enable goodies for regular Windows */\n#endif\n\n\n#if defined(LUA_USE_WINDOWS)\n#if !defined(WINAPI_FAMILY_PARTITION)\n#define LUA_DL_DLL\t/* enable support for DLL */\n#endif\n#define LUA_USE_C89\t/* broadly, Windows is C89 */\n#endif\n\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* MacOS does not need -ldl */\n#define LUA_USE_READLINE\t/* needs an extra library: -lreadline */\n#endif\n\n\n/*\n@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for\n** C89 ('long' and 'double'); Windows always has '__int64', so it does\n** not need to use this case.\n*/\n#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)\n#define LUA_C89_NUMBERS\n#endif\n\n\n\n/*\n@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.\n*/\n/* avoid undefined shifts */\n#if ((INT_MAX >> 15) >> 15) >= 1\n#define LUAI_BITSINT\t32\n#else\n/* 'int' always must have at least 16 bits */\n#define LUAI_BITSINT\t16\n#endif\n\n\n/*\n@@ LUA_INT_TYPE defines the type for Lua integers.\n@@ LUA_FLOAT_TYPE defines the type for Lua floats.\n** Lua should work fine with any mix of these options (if supported\n** by your C compiler). The usual configurations are 64-bit integers\n** and 'double' (the default), 32-bit integers and 'float' (for\n** restricted platforms), and 'long'/'double' (for C compilers not\n** compliant with C99, which may not have support for 'long long').\n*/\n\n/* predefined options for LUA_INT_TYPE */\n#define LUA_INT_INT\t\t1\n#define LUA_INT_LONG\t\t2\n#define LUA_INT_LONGLONG\t3\n\n/* predefined options for LUA_FLOAT_TYPE */\n#define LUA_FLOAT_FLOAT\t\t1\n#define LUA_FLOAT_DOUBLE\t2\n#define LUA_FLOAT_LONGDOUBLE\t3\n\n#if defined(LUA_32BITS)\t\t/* { */\n/*\n** 32-bit integers and 'float'\n*/\n#if LUAI_BITSINT >= 32  /* use 'int' if big enough */\n#define LUA_INT_TYPE\tLUA_INT_INT\n#else  /* otherwise use 'long' */\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#endif\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT\n\n#elif defined(LUA_C89_NUMBERS)\t/* }{ */\n/*\n** largest types available for C89 ('long' and 'double')\n*/\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** default configuration for 64-bit Lua ('long long' and 'double')\n*/\n#if !defined(LUA_INT_TYPE)\n#define LUA_INT_TYPE\tLUA_INT_LONGLONG\n#endif\n\n#if !defined(LUA_FLOAT_TYPE)\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n#endif\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n** Configuration for Paths.\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n*/\n#define LUA_PATH_SEP            \";\"\n#define LUA_PATH_MARK           \"?\"\n#define LUA_EXEC_DIR            \"!\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n** Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n** C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#define LUA_VDIR\tLUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#if defined(_WIN32)\t/* { */\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_SHRDIR\t\"!\\\\..\\\\share\\\\lua\\\\\" LUA_VDIR \"\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua;\" \\\n\t\tLUA_SHRDIR\"?.lua;\" LUA_SHRDIR\"?\\\\init.lua;\" \\\n\t\t\".\\\\?.lua;\" \".\\\\?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.dll;\" \\\n\t\tLUA_CDIR\"..\\\\lib\\\\lua\\\\\" LUA_VDIR \"\\\\?.dll;\" \\\n\t\tLUA_CDIR\"loadall.dll;\" \".\\\\?.dll\"\n\n#else\t\t\t/* }{ */\n\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/\" LUA_VDIR \"/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/\" LUA_VDIR \"/\"\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua;\" \\\n\t\t\"./?.lua;\" \"./?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so;\" \"./?.so\"\n#endif\t\t\t/* } */\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Marks for exported symbols in the C code\n** ===================================================================\n*/\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all auxiliary library functions.\n@@ LUAMOD_API is a mark for all standard library opening functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\t/* { */\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\t/* { */\n#define LUA_API __declspec(dllexport)\n#else\t\t\t\t\t\t/* }{ */\n#define LUA_API __declspec(dllimport)\n#endif\t\t\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#define LUA_API\t\textern\n\n#endif\t\t\t\t/* } */\n\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n#define LUAMOD_API\tLUALIB_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n** exported to outside modules.\n@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables\n** that are not to be exported to outside modules (LUAI_DDEF for\n** definitions and LUAI_DDEC for declarations).\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library. Not all elf targets support\n** this attribute. Unfortunately, gcc does not offer a way to check\n** whether the target offers that support, and those without support\n** give a warning about it. To avoid these warnings, change to the\n** default definition.\n*/\n#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n    defined(__ELF__)\t\t/* { */\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#else\t\t\t\t/* }{ */\n#define LUAI_FUNC\textern\n#endif\t\t\t\t/* } */\n\n#define LUAI_DDEC\tLUAI_FUNC\n#define LUAI_DDEF\t/* empty */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Compatibility with previous versions\n** ===================================================================\n*/\n\n/*\n@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.\n@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.\n** You can define it to get all options, or change specific options\n** to fit your specific needs.\n*/\n#if defined(LUA_COMPAT_5_2)\t/* { */\n\n/*\n@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated\n** functions in the mathematical library.\n*/\n#define LUA_COMPAT_MATHLIB\n\n/*\n@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.\n*/\n#define LUA_COMPAT_BITLIB\n\n/*\n@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.\n*/\n#define LUA_COMPAT_IPAIRS\n\n/*\n@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for\n** manipulating other integer types (lua_pushunsigned, lua_tounsigned,\n** luaL_checkint, luaL_checklong, etc.)\n*/\n#define LUA_COMPAT_APIINTCASTS\n\n#endif\t\t\t\t/* } */\n\n\n#if defined(LUA_COMPAT_5_1)\t/* { */\n\n/* Incompatibilities from 5.2 -> 5.3 */\n#define LUA_COMPAT_MATHLIB\n#define LUA_COMPAT_APIINTCASTS\n\n/*\n@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.\n** You can replace it with 'table.unpack'.\n*/\n#define LUA_COMPAT_UNPACK\n\n/*\n@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.\n** You can replace it with 'package.searchers'.\n*/\n#define LUA_COMPAT_LOADERS\n\n/*\n@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.\n** You can call your C function directly (with light C functions).\n*/\n#define lua_cpcall(L,f,u)  \\\n\t(lua_pushcfunction(L, (f)), \\\n\t lua_pushlightuserdata(L,(u)), \\\n\t lua_pcall(L,1,0,0))\n\n\n/*\n@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.\n** You can rewrite 'log10(x)' as 'log(x, 10)'.\n*/\n#define LUA_COMPAT_LOG10\n\n/*\n@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base\n** library. You can rewrite 'loadstring(s)' as 'load(s)'.\n*/\n#define LUA_COMPAT_LOADSTRING\n\n/*\n@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.\n*/\n#define LUA_COMPAT_MAXN\n\n/*\n@@ The following macros supply trivial compatibility for some\n** changes in the API. The macros themselves document how to\n** change your code to avoid using them.\n*/\n#define lua_strlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_equal(L,idx1,idx2)\t\tlua_compare(L,(idx1),(idx2),LUA_OPEQ)\n#define lua_lessthan(L,idx1,idx2)\tlua_compare(L,(idx1),(idx2),LUA_OPLT)\n\n/*\n@@ LUA_COMPAT_MODULE controls compatibility with previous\n** module functions 'module' (Lua) and 'luaL_register' (C).\n*/\n#define LUA_COMPAT_MODULE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a\n@@ a float mark ('.0').\n** This macro is not on by default even in compatibility mode,\n** because this is not really an incompatibility.\n*/\n/* #define LUA_COMPAT_FLOATSTRING */\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Numbers.\n** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*\n** satisfy your needs.\n** ===================================================================\n*/\n\n/*\n@@ LUA_NUMBER is the floating-point type used by Lua.\n@@ LUAI_UACNUMBER is the result of a 'default argument promotion'\n@@ over a floating number.\n@@ l_mathlim(x) corrects limit name 'x' to the proper float type\n** by prefixing it with one of FLT/DBL/LDBL.\n@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.\n@@ LUA_NUMBER_FMT is the format for writing floats.\n@@ lua_number2str converts a float to a string.\n@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.\n@@ l_floor takes the floor of a float.\n@@ lua_str2number converts a decimal numeric string to a number.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define l_floor(x)\t\t(l_mathop(floor)(x))\n\n#define lua_number2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))\n\n/*\n@@ lua_numbertointeger converts a float number to an integer, or\n** returns 0 if float is not within the range of a lua_Integer.\n** (The range comparisons are tricky because of rounding. The tests\n** here assume a two-complement representation, where MININTEGER always\n** has an exact representation as a float; MAXINTEGER may not have one,\n** and therefore its conversion to float may have an ill-defined value.)\n*/\n#define lua_numbertointeger(n,p) \\\n  ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \\\n   (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \\\n      (*(p) = (LUA_INTEGER)(n), 1))\n\n\n/* now the variable definitions */\n\n#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT\t\t/* { single float */\n\n#define LUA_NUMBER\tfloat\n\n#define l_mathlim(n)\t\t(FLT_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.7g\"\n\n#define l_mathop(op)\t\top##f\n\n#define lua_str2number(s,p)\tstrtof((s), (p))\n\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\t/* }{ long double */\n\n#define LUA_NUMBER\tlong double\n\n#define l_mathlim(n)\t\t(LDBL_##n)\n\n#define LUAI_UACNUMBER\tlong double\n\n#define LUA_NUMBER_FRMLEN\t\"L\"\n#define LUA_NUMBER_FMT\t\t\"%.19Lg\"\n\n#define l_mathop(op)\t\top##l\n\n#define lua_str2number(s,p)\tstrtold((s), (p))\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE\t/* }{ double */\n\n#define LUA_NUMBER\tdouble\n\n#define l_mathlim(n)\t\t(DBL_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n\n#define l_mathop(op)\t\top\n\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n#else\t\t\t\t\t\t/* }{ */\n\n#error \"numeric float type not defined\"\n\n#endif\t\t\t\t\t/* } */\n\n\n\n/*\n@@ LUA_INTEGER is the integer type used by Lua.\n**\n@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.\n**\n@@ LUAI_UACINT is the result of a 'default argument promotion'\n@@ over a lUA_INTEGER.\n@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.\n@@ LUA_INTEGER_FMT is the format for writing integers.\n@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.\n@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.\n@@ lua_integer2str converts an integer to a string.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define LUA_INTEGER_FMT\t\t\"%\" LUA_INTEGER_FRMLEN \"d\"\n\n#define LUAI_UACINT\t\tLUA_INTEGER\n\n#define lua_integer2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))\n\n/*\n** use LUAI_UACINT here to avoid problems with promotions (which\n** can turn a comparison between unsigneds into a signed comparison)\n*/\n#define LUA_UNSIGNED\t\tunsigned LUAI_UACINT\n\n\n/* now the variable definitions */\n\n#if LUA_INT_TYPE == LUA_INT_INT\t\t/* { int */\n\n#define LUA_INTEGER\t\tint\n#define LUA_INTEGER_FRMLEN\t\"\"\n\n#define LUA_MAXINTEGER\t\tINT_MAX\n#define LUA_MININTEGER\t\tINT_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONG\t/* }{ long */\n\n#define LUA_INTEGER\t\tlong\n#define LUA_INTEGER_FRMLEN\t\"l\"\n\n#define LUA_MAXINTEGER\t\tLONG_MAX\n#define LUA_MININTEGER\t\tLONG_MIN\n\n#elif LUA_INT_TYPE == LUA_INT_LONGLONG\t/* }{ long long */\n\n/* use presence of macro LLONG_MAX as proxy for C99 compliance */\n#if defined(LLONG_MAX)\t\t/* { */\n/* use ISO C99 stuff */\n\n#define LUA_INTEGER\t\tlong long\n#define LUA_INTEGER_FRMLEN\t\"ll\"\n\n#define LUA_MAXINTEGER\t\tLLONG_MAX\n#define LUA_MININTEGER\t\tLLONG_MIN\n\n#elif defined(LUA_USE_WINDOWS) /* }{ */\n/* in Windows, can use specific Windows types */\n\n#define LUA_INTEGER\t\t__int64\n#define LUA_INTEGER_FRMLEN\t\"I64\"\n\n#define LUA_MAXINTEGER\t\t_I64_MAX\n#define LUA_MININTEGER\t\t_I64_MIN\n\n#else\t\t\t\t/* }{ */\n\n#error \"Compiler does not support 'long long'. Use option '-DLUA_32BITS' \\\n  or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)\"\n\n#endif\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#error \"numeric integer type not defined\"\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Dependencies with C99 and other C details\n** ===================================================================\n*/\n\n/*\n@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.\n** (All uses in Lua have only one format item.)\n*/\n#if !defined(LUA_USE_C89)\n#define l_sprintf(s,sz,f,i)\tsnprintf(s,sz,f,i)\n#else\n#define l_sprintf(s,sz,f,i)\t((void)(sz), sprintf(s,f,i))\n#endif\n\n\n/*\n@@ lua_strx2number converts an hexadecimal numeric string to a number.\n** In C99, 'strtod' does that conversion. Otherwise, you can\n** leave 'lua_strx2number' undefined and Lua will provide its own\n** implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_strx2number(s,p)\t\tlua_str2number(s,p)\n#endif\n\n\n/*\n@@ lua_pointer2str converts a pointer to a readable string in a\n** non-specified way.\n*/\n#define lua_pointer2str(buff,sz,p)\tl_sprintf(buff,sz,\"%p\",p)\n\n\n/*\n@@ lua_number2strx converts a float to an hexadecimal numeric string.\n** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.\n** Otherwise, you can leave 'lua_number2strx' undefined and Lua will\n** provide its own implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_number2strx(L,b,sz,f,n)  \\\n\t((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))\n#endif\n\n\n/*\n** 'strtof' and 'opf' variants for math functions are not valid in\n** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the\n** availability of these variants. ('math.h' is already included in\n** all files that use these macros.)\n*/\n#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))\n#undef l_mathop  /* variants not available */\n#undef lua_str2number\n#define l_mathop(op)\t\t(lua_Number)op  /* no variant */\n#define lua_str2number(s,p)\t((lua_Number)strtod((s), (p)))\n#endif\n\n\n/*\n@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation\n** functions.  It must be a numerical type; Lua will use 'intptr_t' if\n** available, otherwise it will use 'ptrdiff_t' (the nearest thing to\n** 'intptr_t' in C89)\n*/\n#define LUA_KCONTEXT\tptrdiff_t\n\n#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \\\n    __STDC_VERSION__ >= 199901L\n#include <stdint.h>\n#if defined(INTPTR_MAX)  /* even in C99 this type is optional */\n#undef LUA_KCONTEXT\n#define LUA_KCONTEXT\tintptr_t\n#endif\n#endif\n\n\n/*\n@@ lua_getlocaledecpoint gets the locale \"radix character\" (decimal point).\n** Change that if you do not want to use C locales. (Code using this\n** macro must include header 'locale.h'.)\n*/\n#ifdef __ANDROID__\n#define lua_getlocaledecpoint() '.'\n#elif !defined(lua_getlocaledecpoint)\n#define lua_getlocaledecpoint()\t\t(localeconv()->decimal_point[0])\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Language Variations\n** =====================================================================\n*/\n\n/*\n@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some\n** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from\n** numbers to strings. Define LUA_NOCVTS2N to turn off automatic\n** coercion from strings to numbers.\n*/\n/* #define LUA_NOCVTN2S */\n/* #define LUA_NOCVTS2N */\n\n\n/*\n@@ LUA_USE_APICHECK turns on several consistency checks on the C API.\n** Define it as a help when debugging C code.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(l,e)\tassert(e)\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Macros that affect the API and must be stable (that is, must be the\n** same when you compile Lua and when you compile code that links to\n** Lua). You probably do not want/need to change them.\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXSTACK limits the size of the Lua stack.\n** CHANGE it if you need a different limit. This limit is arbitrary;\n** its only purpose is to stop Lua from consuming unlimited stack\n** space (and to reserve some numbers for pseudo-indices).\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_MAXSTACK\t\t1000000\n#else\n#define LUAI_MAXSTACK\t\t15000\n#endif\n\n\n/*\n@@ LUA_EXTRASPACE defines the size of a raw memory area associated with\n** a Lua state with very fast access.\n** CHANGE it if you need a different size.\n*/\n#define LUA_EXTRASPACE\t\t(sizeof(void *))\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@@ of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#cmakedefine LUA_IDSIZE\t@LUA_IDSIZE@\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n** CHANGE it if it uses too much C-stack space. (For long double,\n** 'string.format(\"%.99f\", -1e4932)' needs 5034 bytes, so a\n** smaller buffer would force a memory allocation for each call to\n** 'string.format'.)\n*/\n#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\n#define LUAL_BUFFERSIZE\t\t8192\n#else\n#define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** Lua does not use these macros anymore; they are here for\n** compatibility only.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* version suffix for environment variable names */\n#define LUA_VERSUFFIX          \"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n\nLUAMOD_API int (luaopen_base) (lua_State *L);\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUAMOD_API int (luaopen_coroutine) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUAMOD_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUAMOD_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUAMOD_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUAMOD_API int (luaopen_string) (lua_State *L);\n\n#define LUA_UTF8LIBNAME\t\"utf8\"\nLUAMOD_API int (luaopen_utf8) (lua_State *L);\n\n#define LUA_BITLIBNAME\t\"bit32\"\nLUAMOD_API int (luaopen_bit32) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUAMOD_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUAMOD_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUAMOD_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L);\n\n\n\n#if !defined(lua_assert)\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.44.1.1 2017/04/19 17:20:42 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\n#if LUAC_COMPATIBLE_FORMAT\n#include <stdint.h>\n#endif\n\n\n#if !defined(luai_verifycode)\n#define luai_verifycode(L,b,f)  /* empty */\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  ZIO *Z;\n  const char *name;\n} LoadState;\n\n\nstatic l_noret error(LoadState *S, const char *why) {\n  luaO_pushfstring(S->L, \"%s: %s precompiled chunk\", S->name, why);\n  luaD_throw(S->L, LUA_ERRSYNTAX);\n}\n\n\n/*\n** All high-level loads go through LoadVector; you can change it to\n** adapt to the endianness of the input\n*/\n#define LoadVector(S,b,n)\tLoadBlock(S,b,(n)*sizeof((b)[0]))\n\nstatic void LoadBlock (LoadState *S, void *b, size_t size) {\n  if (luaZ_read(S->Z, b, size) != 0)\n    error(S, \"truncated\");\n}\n\n\n#define LoadVar(S,x)\t\tLoadVector(S,&x,1)\n\n\nstatic lu_byte LoadByte (LoadState *S) {\n  lu_byte x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic int LoadInt (LoadState *S) {\n  int x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Number LoadNumber (LoadState *S) {\n  lua_Number x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Integer LoadInteger (LoadState *S) {\n  lua_Integer x;\n  LoadVar(S, x);\n  return x;\n}\n\n\nstatic TString *LoadString (LoadState *S) {\n#if LUAC_COMPATIBLE_FORMAT\n  uint32_t size = LoadByte(S);\n#else\n  size_t size = LoadByte(S);\n#endif\n  if (size == 0xFF)\n    LoadVar(S, size);\n  if (size == 0)\n    return NULL;\n  else if (--size <= LUAI_MAXSHORTLEN) {  /* short string? */\n    char buff[LUAI_MAXSHORTLEN];\n    LoadVector(S, buff, size);\n    return luaS_newlstr(S->L, buff, size);\n  }\n  else {  /* long string */\n    TString *ts = luaS_createlngstrobj(S->L, size);\n    LoadVector(S, getstr(ts), size);  /* load directly in final place */\n    return ts;\n  }\n}\n\n\nstatic void LoadCode (LoadState *S, Proto *f) {\n  int n = LoadInt(S);\n  f->code = luaM_newvector(S->L, n, Instruction);\n  f->sizecode = n;\n  LoadVector(S, f->code, n);\n}\n\n\nstatic void LoadFunction(LoadState *S, Proto *f, TString *psource);\n\n\nstatic void LoadConstants (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->k = luaM_newvector(S->L, n, TValue);\n  f->sizek = n;\n  for (i = 0; i < n; i++)\n    setnilvalue(&f->k[i]);\n  for (i = 0; i < n; i++) {\n    TValue *o = &f->k[i];\n    int t = LoadByte(S);\n    switch (t) {\n    case LUA_TNIL:\n      setnilvalue(o);\n      break;\n    case LUA_TBOOLEAN:\n      setbvalue(o, LoadByte(S));\n      break;\n    case LUA_TNUMFLT:\n      setfltvalue(o, LoadNumber(S));\n      break;\n    case LUA_TNUMINT:\n      setivalue(o, LoadInteger(S));\n      break;\n    case LUA_TSHRSTR:\n    case LUA_TLNGSTR:\n      setsvalue2n(S->L, o, LoadString(S));\n      break;\n    default:\n      lua_assert(0);\n    }\n  }\n}\n\n\nstatic void LoadProtos (LoadState *S, Proto *f) {\n  int i;\n  int n = LoadInt(S);\n  f->p = luaM_newvector(S->L, n, Proto *);\n  f->sizep = n;\n  for (i = 0; i < n; i++)\n    f->p[i] = NULL;\n  for (i = 0; i < n; i++) {\n    f->p[i] = luaF_newproto(S->L);\n    LoadFunction(S, f->p[i], f->source);\n  }\n}\n\n\nstatic void LoadUpvalues (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->upvalues = luaM_newvector(S->L, n, Upvaldesc);\n  f->sizeupvalues = n;\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = NULL;\n  for (i = 0; i < n; i++) {\n    f->upvalues[i].instack = LoadByte(S);\n    f->upvalues[i].idx = LoadByte(S);\n  }\n}\n\n\nstatic void LoadDebug (LoadState *S, Proto *f) {\n  int i, n;\n  n = LoadInt(S);\n  f->lineinfo = luaM_newvector(S->L, n, int);\n  f->sizelineinfo = n;\n  LoadVector(S, f->lineinfo, n);\n  n = LoadInt(S);\n  f->locvars = luaM_newvector(S->L, n, LocVar);\n  f->sizelocvars = n;\n  for (i = 0; i < n; i++)\n    f->locvars[i].varname = NULL;\n  for (i = 0; i < n; i++) {\n    f->locvars[i].varname = LoadString(S);\n    f->locvars[i].startpc = LoadInt(S);\n    f->locvars[i].endpc = LoadInt(S);\n  }\n  n = LoadInt(S);\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = LoadString(S);\n}\n\n\nstatic void LoadFunction (LoadState *S, Proto *f, TString *psource) {\n  f->source = LoadString(S);\n  if (f->source == NULL)  /* no source in dump? */\n    f->source = psource;  /* reuse parent's source */\n  f->linedefined = LoadInt(S);\n  f->lastlinedefined = LoadInt(S);\n  f->numparams = LoadByte(S);\n  f->is_vararg = LoadByte(S);\n  f->maxstacksize = LoadByte(S);\n  LoadCode(S, f);\n  LoadConstants(S, f);\n  LoadUpvalues(S, f);\n  LoadProtos(S, f);\n  LoadDebug(S, f);\n}\n\n\nstatic void checkliteral (LoadState *S, const char *s, const char *msg) {\n  char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */\n  size_t len = strlen(s);\n  LoadVector(S, buff, len);\n  if (memcmp(s, buff, len) != 0)\n    error(S, msg);\n}\n\n\nstatic void fchecksize (LoadState *S, size_t size, const char *tname) {\n  if (LoadByte(S) != size)\n    error(S, luaO_pushfstring(S->L, \"%s size mismatch in\", tname));\n}\n\n\n#define checksize(S,t)\tfchecksize(S,sizeof(t),#t)\n\nstatic void checkHeader (LoadState *S) {\n  checkliteral(S, LUA_SIGNATURE + 1, \"not a\");  /* 1st char already checked */\n  if (LoadByte(S) != LUAC_VERSION)\n    error(S, \"version mismatch in\");\n  if (LoadByte(S) != LUAC_FORMAT)\n    error(S, \"format mismatch in\");\n  checkliteral(S, LUAC_DATA, \"corrupted\");\n  checksize(S, int);\n#if !LUAC_COMPATIBLE_FORMAT\n  checksize(S, size_t);\n#endif\n  checksize(S, Instruction);\n  checksize(S, lua_Integer);\n  checksize(S, lua_Number);\n  if (LoadInteger(S) != LUAC_INT)\n    error(S, \"endianness mismatch in\");\n  if (LoadNumber(S) != LUAC_NUM)\n    error(S, \"float format mismatch in\");\n}\n\n\n/*\n** load precompiled chunk\n*/\nLClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {\n  LoadState S;\n  LClosure *cl;\n  if (*name == '@' || *name == '=')\n    S.name = name + 1;\n  else if (*name == LUA_SIGNATURE[0])\n    S.name = \"binary string\";\n  else\n    S.name = name;\n  S.L = L;\n  S.Z = Z;\n  checkHeader(&S);\n  cl = luaF_newLclosure(L, LoadByte(&S));\n  setclLvalue(L, L->top, cl);\n  luaD_inctop(L);\n  cl->p = luaF_newproto(L);\n  LoadFunction(&S, cl->p, NULL);\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luai_verifycode(L, buff, cl->p);\n  return cl;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/* data to catch conversion errors */\n#define LUAC_DATA\t\"\\x19\\x93\\r\\n\\x1a\\n\"\n\n#define LUAC_INT\t0x5678\n#define LUAC_NUM\tcast_num(370.5)\n\n#define MYINT(s)\t(s[0]-'0')\n#define LUAC_VERSION\t(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))\n#if LUAC_COMPATIBLE_FORMAT\n#define LUAC_FORMAT 1\n#else\n#define LUAC_FORMAT\t0\t/* this is the official format */\n#endif\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,\n                         void* data, int strip);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lutf8lib.c",
    "content": "/*\n** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 roberto Exp $\n** Standard library for UTF-8 manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define lutf8lib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <assert.h>\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#define MAXUNICODE\t0x10FFFF\n\n#define iscont(p)\t((*(p) & 0xC0) == 0x80)\n\n\n/* from strlib */\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer u_posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\n/*\n** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.\n*/\nstatic const char *utf8_decode (const char *o, int *val) {\n  static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};\n  const unsigned char *s = (const unsigned char *)o;\n  unsigned int c = s[0];\n  unsigned int res = 0;  /* final result */\n  if (c < 0x80)  /* ascii? */\n    res = c;\n  else {\n    int count = 0;  /* to count number of continuation bytes */\n    while (c & 0x40) {  /* still have continuation bytes? */\n      int cc = s[++count];  /* read next byte */\n      if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */\n        return NULL;  /* invalid byte sequence */\n      res = (res << 6) | (cc & 0x3F);  /* add lower 6 bits from cont. byte */\n      c <<= 1;  /* to test next bit */\n    }\n    res |= ((c & 0x7F) << (count * 5));  /* add first byte */\n    if (count > 3 || res > MAXUNICODE || res <= limits[count])\n      return NULL;  /* invalid byte sequence */\n    s += count;  /* skip continuation bytes read */\n  }\n  if (val) *val = res;\n  return (const char *)s + 1;  /* +1 to include first byte */\n}\n\n\n/*\n** utf8len(s [, i [, j]]) --> number of characters that start in the\n** range [i,j], or nil + current position if 's' is not well formed in\n** that interval\n*/\nstatic int utflen (lua_State *L) {\n  int n = 0;\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,\n                   \"initial position out of string\");\n  luaL_argcheck(L, --posj < (lua_Integer)len, 3,\n                   \"final position out of string\");\n  while (posi <= posj) {\n    const char *s1 = utf8_decode(s + posi, NULL);\n    if (s1 == NULL) {  /* conversion error? */\n      lua_pushnil(L);  /* return nil ... */\n      lua_pushinteger(L, posi + 1);  /* ... and current position */\n      return 2;\n    }\n    posi = s1 - s;\n    n++;\n  }\n  lua_pushinteger(L, n);\n  return 1;\n}\n\n\n/*\n** codepoint(s, [i, [j]])  -> returns codepoints for all characters\n** that start in the range [i,j]\n*/\nstatic int codepoint (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  int n;\n  const char *se;\n  luaL_argcheck(L, posi >= 1, 2, \"out of range\");\n  luaL_argcheck(L, pose <= (lua_Integer)len, 3, \"out of range\");\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  n = 0;\n  se = s + pose;\n  for (s += posi - 1; s < se;) {\n    int code;\n    s = utf8_decode(s, &code);\n    if (s == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, code);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void pushutfchar (lua_State *L, int arg) {\n  lua_Integer code = luaL_checkinteger(L, arg);\n  luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, \"value out of range\");\n  lua_pushfstring(L, \"%U\", (long)code);\n}\n\n\n/*\n** utfchar(n1, n2, ...)  -> char(n1)..char(n2)...\n*/\nstatic int utfchar (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  if (n == 1)  /* optimize common case of single char */\n    pushutfchar(L, 1);\n  else {\n    int i;\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    for (i = 1; i <= n; i++) {\n      pushutfchar(L, i);\n      luaL_addvalue(&b);\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\n/*\n** offset(s, n, [i])  -> index where n-th character counting from\n**   position 'i' starts; 0 means character at 'i'.\n*/\nstatic int byteoffset (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n  = luaL_checkinteger(L, 2);\n  lua_Integer posi = (n >= 0) ? 1 : len + 1;\n  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,\n                   \"position out of range\");\n  if (n == 0) {\n    /* find beginning of current byte sequence */\n    while (posi > 0 && iscont(s + posi)) posi--;\n  }\n  else {\n    if (iscont(s + posi))\n      return luaL_error(L, \"initial position is a continuation byte\");\n    if (n < 0) {\n       while (n < 0 && posi > 0) {  /* move back */\n         do {  /* find beginning of previous character */\n           posi--;\n         } while (posi > 0 && iscont(s + posi));\n         n++;\n       }\n     }\n     else {\n       n--;  /* do not move for 1st character */\n       while (n > 0 && posi < (lua_Integer)len) {\n         do {  /* find beginning of next character */\n           posi++;\n         } while (iscont(s + posi));  /* (cannot pass final '\\0') */\n         n--;\n       }\n     }\n  }\n  if (n == 0)  /* did it find given character? */\n    lua_pushinteger(L, posi + 1);\n  else  /* no such character */\n    lua_pushnil(L);\n  return 1;\n}\n\n\nstatic int iter_aux (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n = lua_tointeger(L, 2) - 1;\n  if (n < 0)  /* first iteration? */\n    n = 0;  /* start from here */\n  else if (n < (lua_Integer)len) {\n    n++;  /* skip current byte */\n    while (iscont(s + n)) n++;  /* and its continuations */\n  }\n  if (n >= (lua_Integer)len)\n    return 0;  /* no more codepoints */\n  else {\n    int code;\n    const char *next = utf8_decode(s + n, &code);\n    if (next == NULL || iscont(next))\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, n + 1);\n    lua_pushinteger(L, code);\n    return 2;\n  }\n}\n\n\nstatic int iter_codes (lua_State *L) {\n  luaL_checkstring(L, 1);\n  lua_pushcfunction(L, iter_aux);\n  lua_pushvalue(L, 1);\n  lua_pushinteger(L, 0);\n  return 3;\n}\n\n\n/* pattern to match a single UTF-8 character */\n#define UTF8PATT\t\"[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*\"\n\n\nstatic const luaL_Reg funcs[] = {\n  {\"offset\", byteoffset},\n  {\"codepoint\", codepoint},\n  {\"char\", utfchar},\n  {\"len\", utflen},\n  {\"codes\", iter_codes},\n  /* placeholders */\n  {\"charpattern\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_utf8 (lua_State *L) {\n  luaL_newlib(L, funcs);\n  lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);\n  lua_setfield(L, -2, \"charpattern\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.268.1.1 2017/04/19 17:39:34 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t2000\n\n\n\n/*\n** 'l_intfitsf' checks whether a given integer can be converted to a\n** float without rounding. Used in comparisons. Left undefined if\n** all integers fit in a float precisely.\n*/\n#if !defined(l_intfitsf)\n\n/* number of bits in the mantissa of a float */\n#define NBM\t\t(l_mathlim(MANT_DIG))\n\n/*\n** Check whether some integers may not fit in a float, that is, whether\n** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).\n** (The shifts are done in parts to avoid shifting by more than the size\n** of an integer. In a worst case, NBM == 113 for long double and\n** sizeof(integer) == 32.)\n*/\n#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \\\n\t>> (NBM - (3 * (NBM / 4))))  >  0\n\n#define l_intfitsf(i)  \\\n  (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM))\n\n#endif\n\n#endif\n\n\n\n/*\n** Try to convert a value to a float. The float case is already handled\n** by the macro 'tonumber'.\n*/\nint luaV_tonumber_ (const TValue *obj, lua_Number *n) {\n  TValue v;\n  if (ttisinteger(obj)) {\n    *n = cast_num(ivalue(obj));\n    return 1;\n  }\n  else if (cvt2num(obj) &&  /* string convertible to number? */\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */\n    return 1;\n  }\n  else\n    return 0;  /* conversion failed */\n}\n\n\n/*\n** try to convert a value to an integer, rounding according to 'mode':\n** mode == 0: accepts only integral values\n** mode == 1: takes the floor of the number\n** mode == 2: takes the ceil of the number\n*/\nint luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {\n  TValue v;\n again:\n  if (ttisfloat(obj)) {\n    lua_Number n = fltvalue(obj);\n    lua_Number f = l_floor(n);\n    if (n != f) {  /* not an integral value? */\n      if (mode == 0) return 0;  /* fails if mode demands integral value */\n      else if (mode > 1)  /* needs ceil? */\n        f += 1;  /* convert floor to ceil (remember: n != f) */\n    }\n    return lua_numbertointeger(f, p);\n  }\n  else if (ttisinteger(obj)) {\n    *p = ivalue(obj);\n    return 1;\n  }\n  else if (cvt2num(obj) &&\n            luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {\n    obj = &v;\n    goto again;  /* convert result from 'luaO_str2num' to an integer */\n  }\n  return 0;  /* conversion failed */\n}\n\n\n/*\n** Try to convert a 'for' limit to an integer, preserving the\n** semantics of the loop.\n** (The following explanation assumes a non-negative step; it is valid\n** for negative steps mutatis mutandis.)\n** If the limit can be converted to an integer, rounding down, that is\n** it.\n** Otherwise, check whether the limit can be converted to a number.  If\n** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,\n** which means no limit.  If the number is too negative, the loop\n** should not run, because any initial integer value is larger than the\n** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects\n** the extreme case when the initial value is LUA_MININTEGER, in which\n** case the LUA_MININTEGER limit would still run the loop once.\n*/\nstatic int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,\n                     int *stopnow) {\n  *stopnow = 0;  /* usually, let loops run */\n  if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) {  /* not fit in integer? */\n    lua_Number n;  /* try to convert to float */\n    if (!tonumber(obj, &n)) /* cannot convert to float? */\n      return 0;  /* not a number */\n    if (luai_numlt(0, n)) {  /* if true, float is larger than max integer */\n      *p = LUA_MAXINTEGER;\n      if (step < 0) *stopnow = 1;\n    }\n    else {  /* float is smaller than min integer */\n      *p = LUA_MININTEGER;\n      if (step >= 0) *stopnow = 1;\n    }\n  }\n  return 1;\n}\n\n\n/*\n** Finish the table access 'val = t[key]'.\n** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to\n** t[k] entry (which must be nil).\n*/\nvoid luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,\n                      const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  const TValue *tm;  /* metamethod */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    if (slot == NULL) {  /* 't' is not a table? */\n      lua_assert(!ttistable(t));\n      tm = luaT_gettmbyobj(L, t, TM_INDEX);\n      if (ttisnil(tm))\n        luaG_typeerror(L, t, \"index\");  /* no metamethod */\n      /* else will try the metamethod */\n    }\n    else {  /* 't' is a table */\n      lua_assert(ttisnil(slot));\n      tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        setnilvalue(val);  /* result is nil */\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    if (ttisfunction(tm)) {  /* is metamethod a function? */\n      luaT_callTM(L, tm, t, key, val, 1);  /* call it */\n      return;\n    }\n    t = tm;  /* else try to access 'tm[key]' */\n    if (luaV_fastget(L,t,key,slot,luaH_get)) {  /* fast track? */\n      setobj2s(L, val, slot);  /* done */\n      return;\n    }\n    /* else repeat (tail call 'luaV_finishget') */\n  }\n  luaG_runerror(L, \"'__index' chain too long; possible loop\");\n}\n\n\n/*\n** Finish a table assignment 't[key] = val'.\n** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points\n** to the entry 't[key]', or to 'luaO_nilobject' if there is no such\n** entry.  (The value at 'slot' must be nil, otherwise 'luaV_fastset'\n** would have done the job.)\n*/\nvoid luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                     StkId val, const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;  /* '__newindex' metamethod */\n    if (slot != NULL) {  /* is 't' a table? */\n      Table *h = hvalue(t);  /* save 't' table */\n      lua_assert(ttisnil(slot));  /* old value must be nil */\n      tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        if (slot == luaO_nilobject)  /* no previous entry? */\n          slot = luaH_newkey(L, h, key);  /* create one */\n        /* no metamethod and (now) there is an entry with given key */\n        setobj2t(L, cast(TValue *, slot), val);  /* set its new value */\n        invalidateTMcache(h);\n        luaC_barrierback(L, h, val);\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    else {  /* not a table; check metamethod */\n      if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n        luaG_typeerror(L, t, \"index\");\n    }\n    /* try the metamethod */\n    if (ttisfunction(tm)) {\n      luaT_callTM(L, tm, t, key, val, 0);\n      return;\n    }\n    t = tm;  /* else repeat assignment over 'tm' */\n    if (luaV_fastset(L, t, key, slot, luaH_get, val))\n      return;  /* done */\n    /* else loop */\n  }\n  luaG_runerror(L, \"'__newindex' chain too long; possible loop\");\n}\n\n\n/*\n** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-\n** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.\n** The code is a little tricky because it allows '\\0' in the strings\n** and it uses 'strcoll' (to respect locales) for each segments\n** of the strings.\n*/\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = tsslen(ls);\n  const char *r = getstr(rs);\n  size_t lr = tsslen(rs);\n  for (;;) {  /* for each segment */\n    int temp = strcoll(l, r);\n    if (temp != 0)  /* not equal? */\n      return temp;  /* done */\n    else {  /* strings are equal up to a '\\0' */\n      size_t len = strlen(l);  /* index of first '\\0' in both strings */\n      if (len == lr)  /* 'rs' is finished? */\n        return (len == ll) ? 0 : 1;  /* check 'ls' */\n      else if (len == ll)  /* 'ls' is finished? */\n        return -1;  /* 'ls' is smaller than 'rs' ('rs' is not finished) */\n      /* both strings longer than 'len'; go on comparing after the '\\0' */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than float 'f'. If 'i' has an\n** exact representation as a float ('l_intfitsf'), compare numbers as\n** floats. Otherwise, if 'f' is outside the range for integers, result\n** is trivial. Otherwise, compare them as integers. (When 'i' has no\n** float representation, either 'f' is \"far away\" from 'i' or 'f' has\n** no precision left for a fractional part; either way, how 'f' is\n** truncated is irrelevant.) When 'f' is NaN, comparisons must result\n** in false.\n*/\nstatic int LTintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f > cast_num(LUA_MININTEGER))  /* minint < f <= maxint ? */\n      return (i < cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f <= minint <= i (or 'f' is NaN)  -->  not(i < f) */\n      return 0;\n  }\n#endif\n  return luai_numlt(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Check whether integer 'i' is less than or equal to float 'f'.\n** See comments on previous function.\n*/\nstatic int LEintfloat (lua_Integer i, lua_Number f) {\n#if defined(l_intfitsf)\n  if (!l_intfitsf(i)) {\n    if (f >= -cast_num(LUA_MININTEGER))  /* -minint == maxint + 1 */\n      return 1;  /* f >= maxint + 1 > i */\n    else if (f >= cast_num(LUA_MININTEGER))  /* minint <= f <= maxint ? */\n      return (i <= cast(lua_Integer, f));  /* compare them as integers */\n    else  /* f < minint <= i (or 'f' is NaN)  -->  not(i <= f) */\n      return 0;\n  }\n#endif\n  return luai_numle(cast_num(i), f);  /* compare them as floats */\n}\n\n\n/*\n** Return 'l < r', for numbers.\n*/\nstatic int LTnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li < ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LTintfloat(li, fltvalue(r));  /* l < r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numlt(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /* NaN < i is always false */\n    else  /* without NaN, (l < r)  <-->  not(r <= l) */\n      return !LEintfloat(ivalue(r), lf);  /* not (r <= l) ? */\n  }\n}\n\n\n/*\n** Return 'l <= r', for numbers.\n*/\nstatic int LEnum (const TValue *l, const TValue *r) {\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li <= ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LEintfloat(li, fltvalue(r));  /* l <= r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numle(lf, fltvalue(r));  /* both are float */\n    else if (luai_numisnan(lf))  /* 'r' is int and 'l' is float */\n      return 0;  /*  NaN <= i is always false */\n    else  /* without NaN, (l <= r)  <-->  not(r < l) */\n      return !LTintfloat(ivalue(r), lf);  /* not (r < l) ? */\n  }\n}\n\n\n/*\n** Main operation less than; return 'l < r'.\n*/\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LTnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) < 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0)  /* no metamethod? */\n    luaG_ordererror(L, l, r);  /* error */\n  return res;\n}\n\n\n/*\n** Main operation less than or equal to; return 'l <= r'. If it needs\n** a metamethod and there is no '__le', try '__lt', based on\n** l <= r iff !(r < l) (assuming a total order). If the metamethod\n** yields during this substitution, the continuation has to know\n** about it (to negate the result of r<l); bit CIST_LEQ in the call\n** status keeps that information.\n*/\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LEnum(l, r);\n  else if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;\n  else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0)  /* try 'le' */\n    return res;\n  else {  /* try 'lt': */\n    L->ci->callstatus |= CIST_LEQ;  /* mark it is doing 'lt' for 'le' */\n    res = luaT_callorderTM(L, r, l, TM_LT);\n    L->ci->callstatus ^= CIST_LEQ;  /* clear mark */\n    if (res < 0)\n      luaG_ordererror(L, l, r);\n    return !res;  /* result is negated */\n  }\n}\n\n\n/*\n** Main operation for equality of Lua values; return 't1 == t2'.\n** L == NULL means raw equality (no metamethods)\n*/\nint luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  if (ttype(t1) != ttype(t2)) {  /* not the same variant? */\n    if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)\n      return 0;  /* only numbers can be equal with different variants */\n    else {  /* two numbers with different variants */\n      lua_Integer i1, i2;  /* compare them as integers */\n      return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);\n    }\n  }\n  /* values have same type and same variant */\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));\n    case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TLCF: return fvalue(t1) == fvalue(t2);\n    case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default:\n      return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL)  /* no TM? */\n    return 0;  /* objects are different */\n  luaT_callTM(L, tm, t1, t2, L->top, 1);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\n/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */\n#define tostring(L,o)  \\\n\t(ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))\n\n#define isemptystr(o)\t(ttisshrstring(o) && tsvalue(o)->shrlen == 0)\n\n/* copy strings in stack from top - n up to top - 1 to buffer */\nstatic void copy2buff (StkId top, int n, char *buff) {\n  size_t tl = 0;  /* size already copied */\n  do {\n    size_t l = vslen(top - n);  /* length of string being copied */\n    memcpy(buff + tl, svalue(top - n), l * sizeof(char));\n    tl += l;\n  } while (--n > 0);\n}\n\n\n/*\n** Main operation for concatenation: concat 'total' values in the stack,\n** from 'L->top - total' up to 'L->top - 1'.\n*/\nvoid luaV_concat (lua_State *L, int total) {\n  lua_assert(total >= 2);\n  do {\n    StkId top = L->top;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1))\n      luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT);\n    else if (isemptystr(top - 1))  /* second operand is empty? */\n      cast_void(tostring(L, top - 2));  /* result is first operand */\n    else if (isemptystr(top - 2)) {  /* first operand is an empty string? */\n      setobjs2s(L, top - 2, top - 1);  /* result is second op. */\n    }\n    else {\n      /* at least two non-empty string values; get as many as possible */\n      size_t tl = vslen(top - 1);\n      TString *ts;\n      /* collect total length and number of strings */\n      for (n = 1; n < total && tostring(L, top - n - 1); n++) {\n        size_t l = vslen(top - n - 1);\n        if (l >= (MAX_SIZE/sizeof(char)) - tl)\n          luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */\n        char buff[LUAI_MAXSHORTLEN];\n        copy2buff(top, n, buff);  /* copy strings to buffer */\n        ts = luaS_newlstr(L, buff, tl);\n      }\n      else {  /* long string; copy strings directly to final result */\n        ts = luaS_createlngstrobj(L, tl);\n        copy2buff(top, n, getstr(ts));\n      }\n      setsvalue2s(L, top - n, ts);  /* create result */\n    }\n    total -= n-1;  /* got 'n' strings to create 1 new */\n    L->top -= n-1;  /* popped 'n' strings and pushed one */\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\n/*\n** Main operation 'ra' = #rb'.\n*/\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n  const TValue *tm;\n  switch (ttype(rb)) {\n    case LUA_TTABLE: {\n      Table *h = hvalue(rb);\n      tm = fasttm(L, h->metatable, TM_LEN);\n      if (tm) break;  /* metamethod? break switch to call it */\n      setivalue(ra, luaH_getn(h));  /* else primitive len */\n      return;\n    }\n    case LUA_TSHRSTR: {\n      setivalue(ra, tsvalue(rb)->shrlen);\n      return;\n    }\n    case LUA_TLNGSTR: {\n      setivalue(ra, tsvalue(rb)->u.lnglen);\n      return;\n    }\n    default: {  /* try metamethod */\n      tm = luaT_gettmbyobj(L, rb, TM_LEN);\n      if (ttisnil(tm))  /* no metamethod? */\n        luaG_typeerror(L, rb, \"get length of\");\n      break;\n    }\n  }\n  luaT_callTM(L, tm, rb, rb, ra, 1);\n}\n\n\n/*\n** Integer division; return 'm // n', that is, floor(m/n).\n** C division truncates its result (rounds towards zero).\n** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,\n** otherwise 'floor(q) == trunc(q) - 1'.\n*/\nlua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to divide by zero\");\n    return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */\n  }\n  else {\n    lua_Integer q = m / n;  /* perform C division */\n    if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */\n      q -= 1;  /* correct result for different rounding */\n    return q;\n  }\n}\n\n\n/*\n** Integer modulus; return 'm % n'. (Assume that C '%' with\n** negative operands follows C99 behavior. See previous comment\n** about luaV_div.)\n*/\nlua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to perform 'n%%0'\");\n    return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */\n  }\n  else {\n    lua_Integer r = m % n;\n    if (r != 0 && (m ^ n) < 0)  /* 'm/n' would be non-integer negative? */\n      r += n;  /* correct result for different rounding */\n    return r;\n  }\n}\n\n\n/* number of bits in an integer */\n#define NBITS\tcast_int(sizeof(lua_Integer) * CHAR_BIT)\n\n/*\n** Shift left operation. (Shift right just negates 'y'.)\n*/\nlua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {\n  if (y < 0) {  /* shift right? */\n    if (y <= -NBITS) return 0;\n    else return intop(>>, x, -y);\n  }\n  else {  /* shift left */\n    if (y >= NBITS) return 0;\n    else return intop(<<, x, y);\n  }\n}\n\n\n/*\n** check whether cached closure in prototype 'p' may be reused, that is,\n** whether there is a cached closure with the same upvalues needed by\n** new closure to be created.\n*/\nstatic LClosure *getcached (Proto *p, UpVal **encup, StkId base) {\n  LClosure *c = p->cache;\n  if (c != NULL) {  /* is there a cached closure? */\n    int nup = p->sizeupvalues;\n    Upvaldesc *uv = p->upvalues;\n    int i;\n    for (i = 0; i < nup; i++) {  /* check whether it has right upvalues */\n      TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;\n      if (c->upvals[i]->v != v)\n        return NULL;  /* wrong upvalue; cannot reuse closure */\n    }\n  }\n  return c;  /* return cached closure (or NULL if no cached closure) */\n}\n\n\n/*\n** create a new Lua closure, push it in the stack, and initialize\n** its upvalues. Note that the closure is not cached if prototype is\n** already black (which means that 'cache' was already cleared by the\n** GC).\n*/\nstatic void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,\n                         StkId ra) {\n  int nup = p->sizeupvalues;\n  Upvaldesc *uv = p->upvalues;\n  int i;\n  LClosure *ncl = luaF_newLclosure(L, nup);\n  ncl->p = p;\n  setclLvalue(L, ra, ncl);  /* anchor new closure in stack */\n  for (i = 0; i < nup; i++) {  /* fill in its upvalues */\n    if (uv[i].instack)  /* upvalue refers to local variable? */\n      ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);\n    else  /* get upvalue from enclosing function */\n      ncl->upvals[i] = encup[uv[i].idx];\n    ncl->upvals[i]->refcount++;\n    /* new closure is white, so we do not need a barrier here */\n  }\n  if (!isblack(p))  /* cache will not break GC invariant? */\n    p->cache = ncl;  /* save it on cache for reuse */\n}\n\n\n/*\n** finish execution of an opcode interrupted by an yield\n*/\nvoid luaV_finishOp (lua_State *L) {\n  CallInfo *ci = L->ci;\n  StkId base = ci->u.l.base;\n  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */\n  OpCode op = GET_OPCODE(inst);\n  switch (op) {  /* finish its execution */\n    case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV:\n    case OP_BAND: case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR:\n    case OP_MOD: case OP_POW:\n    case OP_UNM: case OP_BNOT: case OP_LEN:\n    case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {\n      setobjs2s(L, base + GETARG_A(inst), --L->top);\n      break;\n    }\n    case OP_LE: case OP_LT: case OP_EQ: {\n      int res = !l_isfalse(L->top - 1);\n      L->top--;\n      if (ci->callstatus & CIST_LEQ) {  /* \"<=\" using \"<\" instead? */\n        lua_assert(op == OP_LE);\n        ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        res = !res;  /* negate result */\n      }\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);\n      if (res != GETARG_A(inst))  /* condition failed? */\n        ci->u.l.savedpc++;  /* skip jump instruction */\n      break;\n    }\n    case OP_CONCAT: {\n      StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */\n      int b = GETARG_B(inst);      /* first element to concatenate */\n      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */\n      setobj2s(L, top - 2, top);  /* put TM result in proper position */\n      if (total > 1) {  /* are there elements to concat? */\n        L->top = top - 1;  /* top is one after last element (at top-2) */\n        luaV_concat(L, total);  /* concat them (may yield again) */\n      }\n      /* move final result to final position */\n      setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);\n      L->top = ci->top;  /* restore top */\n      break;\n    }\n    case OP_TFORCALL: {\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);\n      L->top = ci->top;  /* correct top */\n      break;\n    }\n    case OP_CALL: {\n      if (GETARG_C(inst) - 1 >= 0)  /* nresults >= 0? */\n        L->top = ci->top;  /* adjust results */\n      break;\n    }\n    case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n\n\n/*\n** {==================================================================\n** Function 'luaV_execute': main interpreter loop\n** ===================================================================\n*/\n\n\n/*\n** some macros for common tasks in 'luaV_execute'\n*/\n\n\n#define RA(i)\t(base+GETARG_A(i))\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n\n\n/* execute a jump instruction */\n#define dojump(ci,i,e) \\\n  { int a = GETARG_A(i); \\\n    if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \\\n    ci->u.l.savedpc += GETARG_sBx(i) + e; }\n\n/* for test instructions, execute the jump instruction that follows it */\n#define donextjump(ci)\t{ i = *ci->u.l.savedpc; dojump(ci, i, 1); }\n\n\n#define Protect(x)\t{ {x;}; base = ci->u.l.base; }\n\n#define checkGC(L,c)  \\\n\t{ luaC_condGC(L, L->top = (c),  /* limit of live values */ \\\n                         Protect(L->top = ci->top));  /* restore top */ \\\n           luai_threadyield(L); }\n\n\n/* fetch an instruction and prepare its execution */\n#define vmfetch()\t{ \\\n  i = *(ci->u.l.savedpc++); \\\n  if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) \\\n    Protect(luaG_traceexec(L)); \\\n  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \\\n  lua_assert(base == ci->u.l.base); \\\n  lua_assert(base <= L->top && L->top < L->stack + L->stacksize); \\\n}\n\n#define vmdispatch(o)\tswitch(o)\n#define vmcase(l)\tcase l:\n#define vmbreak\t\tbreak\n\n\n/*\n** copy of 'luaV_gettable', but protecting the call to potential\n** metamethod (which can reallocate the stack)\n*/\n#define gettableProtected(L,t,k,v)  { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else Protect(luaV_finishget(L,t,k,v,slot)); }\n\n\n/* same for 'luaV_settable' */\n#define settableProtected(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    Protect(luaV_finishset(L,t,k,v,slot)); }\n\n\n\nvoid luaV_execute (lua_State *L) {\n  CallInfo *ci = L->ci;\n  LClosure *cl;\n  TValue *k;\n  StkId base;\n  ci->callstatus |= CIST_FRESH;  /* fresh invocation of 'luaV_execute\" */\n newframe:  /* reentry point when frame changes (call/return) */\n  lua_assert(ci == L->ci);\n  cl = clLvalue(ci->func);  /* local reference to function's closure */\n  k = cl->p->k;  /* local reference to function's constant table */\n  base = ci->u.l.base;  /* local copy of function's base */\n  /* main loop of interpreter */\n  for (;;) {\n    Instruction i;\n    StkId ra;\n    vmfetch();\n    vmdispatch (GET_OPCODE(i)) {\n      vmcase(OP_MOVE) {\n        setobjs2s(L, ra, RB(i));\n        vmbreak;\n      }\n      vmcase(OP_LOADK) {\n        TValue *rb = k + GETARG_Bx(i);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADKX) {\n        TValue *rb;\n        lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n        rb = k + GETARG_Ax(*ci->u.l.savedpc++);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADBOOL) {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) ci->u.l.savedpc++;  /* skip next instruction (if C) */\n        vmbreak;\n      }\n      vmcase(OP_LOADNIL) {\n        int b = GETARG_B(i);\n        do {\n          setnilvalue(ra++);\n        } while (b--);\n        vmbreak;\n      }\n      vmcase(OP_GETUPVAL) {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        vmbreak;\n      }\n      vmcase(OP_GETTABUP) {\n        TValue *upval = cl->upvals[GETARG_B(i)]->v;\n        TValue *rc = RKC(i);\n        gettableProtected(L, upval, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_GETTABLE) {\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        gettableProtected(L, rb, rc, ra);\n        vmbreak;\n      }\n      vmcase(OP_SETTABUP) {\n        TValue *upval = cl->upvals[GETARG_A(i)]->v;\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, upval, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_SETUPVAL) {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_upvalbarrier(L, uv);\n        vmbreak;\n      }\n      vmcase(OP_SETTABLE) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        settableProtected(L, ra, rb, rc);\n        vmbreak;\n      }\n      vmcase(OP_NEWTABLE) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Table *t = luaH_new(L);\n        sethvalue(L, ra, t);\n        if (b != 0 || c != 0)\n          luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_SELF) {\n        const TValue *aux;\n        StkId rb = RB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        setobjs2s(L, ra + 1, rb);\n        if (luaV_fastget(L, rb, key, aux, luaH_getstr)) {\n          setobj2s(L, ra, aux);\n        }\n        else Protect(luaV_finishget(L, rb, rc, ra, aux));\n        vmbreak;\n      }\n      vmcase(OP_ADD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(+, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numadd(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); }\n        vmbreak;\n      }\n      vmcase(OP_SUB) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(-, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numsub(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); }\n        vmbreak;\n      }\n      vmcase(OP_MUL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, intop(*, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_nummul(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); }\n        vmbreak;\n      }\n      vmcase(OP_DIV) {  /* float division (always with floats) */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numdiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); }\n        vmbreak;\n      }\n      vmcase(OP_BAND) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(&, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); }\n        vmbreak;\n      }\n      vmcase(OP_BOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(|, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); }\n        vmbreak;\n      }\n      vmcase(OP_BXOR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, intop(^, ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); }\n        vmbreak;\n      }\n      vmcase(OP_SHL) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); }\n        vmbreak;\n      }\n      vmcase(OP_SHR) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Integer ib; lua_Integer ic;\n        if (tointeger(rb, &ib) && tointeger(rc, &ic)) {\n          setivalue(ra, luaV_shiftl(ib, -ic));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); }\n        vmbreak;\n      }\n      vmcase(OP_MOD) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_mod(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          lua_Number m;\n          luai_nummod(L, nb, nc, m);\n          setfltvalue(ra, m);\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); }\n        vmbreak;\n      }\n      vmcase(OP_IDIV) {  /* floor division */\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (ttisinteger(rb) && ttisinteger(rc)) {\n          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);\n          setivalue(ra, luaV_div(L, ib, ic));\n        }\n        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numidiv(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); }\n        vmbreak;\n      }\n      vmcase(OP_POW) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        lua_Number nb; lua_Number nc;\n        if (tonumber(rb, &nb) && tonumber(rc, &nc)) {\n          setfltvalue(ra, luai_numpow(L, nb, nc));\n        }\n        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); }\n        vmbreak;\n      }\n      vmcase(OP_UNM) {\n        TValue *rb = RB(i);\n        lua_Number nb;\n        if (ttisinteger(rb)) {\n          lua_Integer ib = ivalue(rb);\n          setivalue(ra, intop(-, 0, ib));\n        }\n        else if (tonumber(rb, &nb)) {\n          setfltvalue(ra, luai_numunm(L, nb));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));\n        }\n        vmbreak;\n      }\n      vmcase(OP_BNOT) {\n        TValue *rb = RB(i);\n        lua_Integer ib;\n        if (tointeger(rb, &ib)) {\n          setivalue(ra, intop(^, ~l_castS2U(0), ib));\n        }\n        else {\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));\n        }\n        vmbreak;\n      }\n      vmcase(OP_NOT) {\n        TValue *rb = RB(i);\n        int res = l_isfalse(rb);  /* next assignment may change this value */\n        setbvalue(ra, res);\n        vmbreak;\n      }\n      vmcase(OP_LEN) {\n        Protect(luaV_objlen(L, ra, RB(i)));\n        vmbreak;\n      }\n      vmcase(OP_CONCAT) {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        StkId rb;\n        L->top = base + c + 1;  /* mark the end of concat operands */\n        Protect(luaV_concat(L, c - b + 1));\n        ra = RA(i);  /* 'luaV_concat' may invoke TMs and move the stack */\n        rb = base + b;\n        setobjs2s(L, ra, rb);\n        checkGC(L, (ra >= rb ? ra + 1 : rb));\n        L->top = ci->top;  /* restore top */\n        vmbreak;\n      }\n      vmcase(OP_JMP) {\n        dojump(ci, i, 0);\n        vmbreak;\n      }\n      vmcase(OP_EQ) {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (luaV_equalobj(L, rb, rc) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LT) {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_LE) {\n        Protect(\n          if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))\n            ci->u.l.savedpc++;\n          else\n            donextjump(ci);\n        )\n        vmbreak;\n      }\n      vmcase(OP_TEST) {\n        if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))\n            ci->u.l.savedpc++;\n          else\n          donextjump(ci);\n        vmbreak;\n      }\n      vmcase(OP_TESTSET) {\n        TValue *rb = RB(i);\n        if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))\n          ci->u.l.savedpc++;\n        else {\n          setobjs2s(L, ra, rb);\n          donextjump(ci);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CALL) {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        if (luaD_precall(L, ra, nresults)) {  /* C function? */\n          if (nresults >= 0)\n            L->top = ci->top;  /* adjust results */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {  /* Lua function */\n          ci = L->ci;\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_TAILCALL) {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        if (luaD_precall(L, ra, LUA_MULTRET)) {  /* C function? */\n          Protect((void)0);  /* update 'base' */\n        }\n        else {\n          /* tail call: put called frame (n) in place of caller one (o) */\n          CallInfo *nci = L->ci;  /* called frame */\n          CallInfo *oci = nci->previous;  /* caller frame */\n          StkId nfunc = nci->func;  /* called function */\n          StkId ofunc = oci->func;  /* caller function */\n          /* last stack slot filled by 'precall' */\n          StkId lim = nci->u.l.base + getproto(nfunc)->numparams;\n          int aux;\n          /* close all upvalues from previous call */\n          if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);\n          /* move new frame into old one */\n          for (aux = 0; nfunc + aux < lim; aux++)\n            setobjs2s(L, ofunc + aux, nfunc + aux);\n          oci->u.l.base = ofunc + (nci->u.l.base - nfunc);  /* correct base */\n          oci->top = L->top = ofunc + (L->top - nfunc);  /* correct top */\n          oci->u.l.savedpc = nci->u.l.savedpc;\n          oci->callstatus |= CIST_TAIL;  /* function was tail called */\n          ci = L->ci = oci;  /* remove new frame */\n          lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n        vmbreak;\n      }\n      vmcase(OP_RETURN) {\n        int b = GETARG_B(i);\n        if (cl->p->sizep > 0) luaF_close(L, base);\n        b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));\n        if (ci->callstatus & CIST_FRESH)  /* local 'ci' still from callee */\n          return;  /* external invocation: return */\n        else {  /* invocation via reentry: continue execution */\n          ci = L->ci;\n          if (b) L->top = ci->top;\n          lua_assert(isLua(ci));\n          lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);\n          goto newframe;  /* restart luaV_execute over new Lua function */\n        }\n      }\n      vmcase(OP_FORLOOP) {\n        if (ttisinteger(ra)) {  /* integer loop? */\n          lua_Integer step = ivalue(ra + 2);\n          lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */\n          lua_Integer limit = ivalue(ra + 1);\n          if ((0 < step) ? (idx <= limit) : (limit <= idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgivalue(ra, idx);  /* update internal index... */\n            setivalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        else {  /* floating loop */\n          lua_Number step = fltvalue(ra + 2);\n          lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */\n          lua_Number limit = fltvalue(ra + 1);\n          if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                  : luai_numle(limit, idx)) {\n            ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n            chgfltvalue(ra, idx);  /* update internal index... */\n            setfltvalue(ra + 3, idx);  /* ...and external index */\n          }\n        }\n        vmbreak;\n      }\n      vmcase(OP_FORPREP) {\n        TValue *init = ra;\n        TValue *plimit = ra + 1;\n        TValue *pstep = ra + 2;\n        lua_Integer ilimit;\n        int stopnow;\n        if (ttisinteger(init) && ttisinteger(pstep) &&\n            forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {\n          /* all values are integer */\n          lua_Integer initv = (stopnow ? 0 : ivalue(init));\n          setivalue(plimit, ilimit);\n          setivalue(init, intop(-, initv, ivalue(pstep)));\n        }\n        else {  /* try making all values floats */\n          lua_Number ninit; lua_Number nlimit; lua_Number nstep;\n          if (!tonumber(plimit, &nlimit))\n            luaG_runerror(L, \"'for' limit must be a number\");\n          setfltvalue(plimit, nlimit);\n          if (!tonumber(pstep, &nstep))\n            luaG_runerror(L, \"'for' step must be a number\");\n          setfltvalue(pstep, nstep);\n          if (!tonumber(init, &ninit))\n            luaG_runerror(L, \"'for' initial value must be a number\");\n          setfltvalue(init, luai_numsub(L, ninit, nstep));\n        }\n        ci->u.l.savedpc += GETARG_sBx(i);\n        vmbreak;\n      }\n      vmcase(OP_TFORCALL) {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb + 3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = ci->top;\n        i = *(ci->u.l.savedpc++);  /* go to next instruction */\n        ra = RA(i);\n        lua_assert(GET_OPCODE(i) == OP_TFORLOOP);\n        goto l_tforloop;\n      }\n      vmcase(OP_TFORLOOP) {\n        l_tforloop:\n        if (!ttisnil(ra + 1)) {  /* continue loop? */\n          setobjs2s(L, ra, ra + 1);  /* save control variable */\n           ci->u.l.savedpc += GETARG_sBx(i);  /* jump back */\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETLIST) {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        unsigned int last;\n        Table *h;\n        if (n == 0) n = cast_int(L->top - ra) - 1;\n        if (c == 0) {\n          lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);\n          c = GETARG_Ax(*ci->u.l.savedpc++);\n        }\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* preallocate it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          luaH_setint(L, h, last--, val);\n          luaC_barrierback(L, h, val);\n        }\n        L->top = ci->top;  /* correct top (in case of previous open call) */\n        vmbreak;\n      }\n      vmcase(OP_CLOSURE) {\n        Proto *p = cl->p->p[GETARG_Bx(i)];\n        LClosure *ncl = getcached(p, cl->upvals, base);  /* cached closure */\n        if (ncl == NULL)  /* no match? */\n          pushclosure(L, p, cl->upvals, base, ra);  /* create a new one */\n        else\n          setclLvalue(L, ra, ncl);  /* push cashed closure */\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_VARARG) {\n        int b = GETARG_B(i) - 1;  /* required results */\n        int j;\n        int n = cast_int(base - ci->func) - cl->p->numparams - 1;\n        if (n < 0)  /* less arguments than parameters? */\n          n = 0;  /* no vararg arguments */\n        if (b < 0) {  /* B == 0? */\n          b = n;  /* get all var. arguments */\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          L->top = ra + n;\n        }\n        for (j = 0; j < b && j < n; j++)\n          setobjs2s(L, ra + j, base - n + j);\n        for (; j < b; j++)  /* complete required results with nil */\n          setnilvalue(ra + j);\n        vmbreak;\n      }\n      vmcase(OP_EXTRAARG) {\n        lua_assert(0);\n        vmbreak;\n      }\n    }\n  }\n}\n\n/* }================================================================== */\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUA_NOCVTN2S)\n#define cvt2str(o)\tttisnumber(o)\n#else\n#define cvt2str(o)\t0\t/* no conversion from numbers to strings */\n#endif\n\n\n#if !defined(LUA_NOCVTS2N)\n#define cvt2num(o)\tttisstring(o)\n#else\n#define cvt2num(o)\t0\t/* no conversion from strings to numbers */\n#endif\n\n\n/*\n** You can define LUA_FLOORN2I if you want to convert floats to integers\n** by flooring them (instead of raising an error if they are not\n** integral values)\n*/\n#if !defined(LUA_FLOORN2I)\n#define LUA_FLOORN2I\t\t0\n#endif\n\n\n#define tonumber(o,n) \\\n\t(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))\n\n#define tointeger(o,i) \\\n    (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n\n#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))\n\n#define luaV_rawequalobj(t1,t2)\t\tluaV_equalobj(NULL,t1,t2)\n\n\n/*\n** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,\n** return 1 with 'slot' pointing to 't[k]' (final result).  Otherwise,\n** return 0 (meaning it will have to check metamethod) with 'slot'\n** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).\n** 'f' is the raw get function to use.\n*/\n#define luaV_fastget(L,t,k,slot,f) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = f(hvalue(t), k),  /* else, do raw access */  \\\n      !ttisnil(slot)))  /* result not nil? */\n\n/*\n** standard implementation for 'gettable'\n*/\n#define luaV_gettable(L,t,k,v) { const TValue *slot; \\\n  if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \\\n  else luaV_finishget(L,t,k,v,slot); }\n\n\n/*\n** Fast track for set table. If 't' is a table and 't[k]' is not nil,\n** call GC barrier, do a raw 't[k]=v', and return true; otherwise,\n** return false with 'slot' equal to NULL (if 't' is not a table) or\n** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro\n** returns true, there is no need to 'invalidateTMcache', because the\n** call is not creating a new entry.\n*/\n#define luaV_fastset(L,t,k,slot,f,v) \\\n  (!ttistable(t) \\\n   ? (slot = NULL, 0) \\\n   : (slot = f(hvalue(t), k), \\\n     ttisnil(slot) ? 0 \\\n     : (luaC_barrierback(L, hvalue(t), v), \\\n        setobj2t(L, cast(TValue *,slot), v), \\\n        1)))\n\n\n#define luaV_settable(L,t,k,v) { const TValue *slot; \\\n  if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \\\n    luaV_finishset(L,t,k,v,slot); }\n\n\n\nLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);\nLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);\nLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishOp (lua_State *L);\nLUAI_FUNC void luaV_execute (lua_State *L);\nLUAI_FUNC void luaV_concat (lua_State *L, int total);\nLUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);\nLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.3.5/src/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0)\n    return EOZ;\n  z->n = size - 1;  /* discount char being returned */\n  z->p = buff;\n  return cast_uchar(*(z->p++));\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (z->n == 0) {  /* no bytes in buffer? */\n      if (luaZ_fill(z) == EOZ)  /* try to read more */\n        return n;  /* no more input; return number of missing bytes */\n      else {\n        z->n++;  /* luaZ_fill consumed first byte; put it back */\n        z->p--;\n      }\n    }\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n"
  },
  {
    "path": "build/lua-5.3.5/src/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))\n\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_buffremove(buff,i)\t((buff)->n -= (i))\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \\\n\t\t\t\t(buff)->buffsize, size), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);\t/* read next n bytes */\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\t\t/* reader function */\n  void *data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/Makefile",
    "content": "# Makefile for installing Lua\n# See doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= guess\n\n# Where to install. The installation starts in the src and doc directories,\n# so take care if INSTALL_TOP is not an absolute path. See the local target.\n# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with\n# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.\nINSTALL_TOP= /usr/local\nINSTALL_BIN= $(INSTALL_TOP)/bin\nINSTALL_INC= $(INSTALL_TOP)/include\nINSTALL_LIB= $(INSTALL_TOP)/lib\nINSTALL_MAN= $(INSTALL_TOP)/man/man1\nINSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V\nINSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V\n\n# How to install. If your install program does not support \"-p\", then\n# you may have to run ranlib on the installed liblua.a.\nINSTALL= install -p\nINSTALL_EXEC= $(INSTALL) -m 0755\nINSTALL_DATA= $(INSTALL) -m 0644\n#\n# If you don't have \"install\" you can use \"cp\" instead.\n# INSTALL= cp -p\n# INSTALL_EXEC= $(INSTALL)\n# INSTALL_DATA= $(INSTALL)\n\n# Other utilities.\nMKDIR= mkdir -p\nRM= rm -f\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\n# Convenience platforms targets.\nPLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris\n\n# What to install.\nTO_BIN= lua luac\nTO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp\nTO_LIB= liblua.a\nTO_MAN= lua.1 luac.1\n\n# Lua version and release.\nV= 5.4\nR= $V.1\n\n# Targets start here.\nall:\t$(PLAT)\n\n$(PLATS) help test clean:\n\t@cd src && $(MAKE) $@\n\ninstall: dummy\n\tcd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)\n\tcd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)\n\tcd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)\n\tcd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)\n\tcd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)\n\nuninstall:\n\tcd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)\n\tcd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)\n\tcd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)\n\tcd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)\n\nlocal:\n\t$(MAKE) install INSTALL_TOP=../install\n\n# make may get confused with install/ if it does not support .PHONY.\ndummy:\n\n# Echo config parameters.\necho:\n\t@cd src && $(MAKE) -s echo\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"V= $V\"\n\t@echo \"R= $R\"\n\t@echo \"TO_BIN= $(TO_BIN)\"\n\t@echo \"TO_INC= $(TO_INC)\"\n\t@echo \"TO_LIB= $(TO_LIB)\"\n\t@echo \"TO_MAN= $(TO_MAN)\"\n\t@echo \"INSTALL_TOP= $(INSTALL_TOP)\"\n\t@echo \"INSTALL_BIN= $(INSTALL_BIN)\"\n\t@echo \"INSTALL_INC= $(INSTALL_INC)\"\n\t@echo \"INSTALL_LIB= $(INSTALL_LIB)\"\n\t@echo \"INSTALL_MAN= $(INSTALL_MAN)\"\n\t@echo \"INSTALL_LMOD= $(INSTALL_LMOD)\"\n\t@echo \"INSTALL_CMOD= $(INSTALL_CMOD)\"\n\t@echo \"INSTALL_EXEC= $(INSTALL_EXEC)\"\n\t@echo \"INSTALL_DATA= $(INSTALL_DATA)\"\n\n# Echo pkg-config data.\npc:\n\t@echo \"version=$R\"\n\t@echo \"prefix=$(INSTALL_TOP)\"\n\t@echo \"libdir=$(INSTALL_LIB)\"\n\t@echo \"includedir=$(INSTALL_INC)\"\n\n# Targets that do not create files (not all makes understand .PHONY).\n.PHONY: all $(PLATS) help test clean install uninstall local dummy echo pc\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.4.1/README",
    "content": "\nThis is Lua 5.4.1, released on 30 Sep 2020.\n\nFor installation instructions, license details, and\nfurther information about Lua, see doc/readme.html.\n\n"
  },
  {
    "path": "build/lua-5.4.1/doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.4 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"index.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.4 Reference Manual\n</H1>\n\n<P>\nThe reference manual is the official definition of the Lua language.\n<BR>\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/pil/\">Programming in Lua</A>.\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<P>\n<SMALL>\nCopyright &copy; 2020 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<A HREF=\"http://www.lua.org/license.html\">Lua license</A>.\n</SMALL>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL CLASS=\"contents menubar\">\n<LI><A HREF=\"manual.html\">1 &ndash; Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 &ndash; Basic Concepts</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 &ndash; Values and Types</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 &ndash; Environments and the Global Environment</A>\n<LI><A HREF=\"manual.html#2.3\">2.3 &ndash; Error Handling</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 &ndash; Metatables and Metamethods</A>\n<LI><A HREF=\"manual.html#2.5\">2.5 &ndash; Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 &ndash; Incremental Garbage Collection</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 &ndash; Generational Garbage Collection</A>\n<LI><A HREF=\"manual.html#2.5.3\">2.5.3 &ndash; Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.5.4\">2.5.4 &ndash; Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 &ndash; Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 &ndash; The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 &ndash; Lexical Conventions</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 &ndash; Variables</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 &ndash; Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#3.3.1\">3.3.1 &ndash; Blocks</A>\n<LI><A HREF=\"manual.html#3.3.2\">3.3.2 &ndash; Chunks</A>\n<LI><A HREF=\"manual.html#3.3.3\">3.3.3 &ndash; Assignment</A>\n<LI><A HREF=\"manual.html#3.3.4\">3.3.4 &ndash; Control Structures</A>\n<LI><A HREF=\"manual.html#3.3.5\">3.3.5 &ndash; For Statement</A>\n<LI><A HREF=\"manual.html#3.3.6\">3.3.6 &ndash; Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#3.3.7\">3.3.7 &ndash; Local Declarations</A>\n<LI><A HREF=\"manual.html#3.3.8\">3.3.8 &ndash; To-be-closed Variables</A>\n</UL>\n<LI><A HREF=\"manual.html#3.4\">3.4 &ndash; Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#3.4.1\">3.4.1 &ndash; Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#3.4.2\">3.4.2 &ndash; Bitwise Operators</A>\n<LI><A HREF=\"manual.html#3.4.3\">3.4.3 &ndash; Coercions and Conversions</A>\n<LI><A HREF=\"manual.html#3.4.4\">3.4.4 &ndash; Relational Operators</A>\n<LI><A HREF=\"manual.html#3.4.5\">3.4.5 &ndash; Logical Operators</A>\n<LI><A HREF=\"manual.html#3.4.6\">3.4.6 &ndash; Concatenation</A>\n<LI><A HREF=\"manual.html#3.4.7\">3.4.7 &ndash; The Length Operator</A>\n<LI><A HREF=\"manual.html#3.4.8\">3.4.8 &ndash; Precedence</A>\n<LI><A HREF=\"manual.html#3.4.9\">3.4.9 &ndash; Table Constructors</A>\n<LI><A HREF=\"manual.html#3.4.10\">3.4.10 &ndash; Function Calls</A>\n<LI><A HREF=\"manual.html#3.4.11\">3.4.11 &ndash; Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#3.5\">3.5 &ndash; Visibility Rules</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 &ndash; The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 &ndash; The Stack</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1.1\">4.1.1 &ndash; Stack Size</A>\n<LI><A HREF=\"manual.html#4.1.2\">4.1.2 &ndash; Valid and Acceptable Indices</A>\n<LI><A HREF=\"manual.html#4.1.3\">4.1.3 &ndash; Pointers to strings</A>\n</UL>\n<LI><A HREF=\"manual.html#4.2\">4.2 &ndash; C Closures</A>\n<LI><A HREF=\"manual.html#4.3\">4.3 &ndash; Registry</A>\n<LI><A HREF=\"manual.html#4.4\">4.4 &ndash; Error Handling in C</A>\n<UL>\n<LI><A HREF=\"manual.html#4.4.1\">4.4.1 &ndash; Status Codes</A>\n</UL>\n<LI><A HREF=\"manual.html#4.5\">4.5 &ndash; Handling Yields in C</A>\n<LI><A HREF=\"manual.html#4.6\">4.6 &ndash; Functions and Types</A>\n<LI><A HREF=\"manual.html#4.7\">4.7 &ndash; The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 &ndash; The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 &ndash; Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 &ndash; The Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#6.1\">6.1 &ndash; Basic Functions</A>\n<LI><A HREF=\"manual.html#6.2\">6.2 &ndash; Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#6.3\">6.3 &ndash; Modules</A>\n<LI><A HREF=\"manual.html#6.4\">6.4 &ndash; String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#6.4.1\">6.4.1 &ndash; Patterns</A>\n<LI><A HREF=\"manual.html#6.4.2\">6.4.2 &ndash; Format Strings for Pack and Unpack</A>\n</UL>\n<LI><A HREF=\"manual.html#6.5\">6.5 &ndash; UTF-8 Support</A>\n<LI><A HREF=\"manual.html#6.6\">6.6 &ndash; Table Manipulation</A>\n<LI><A HREF=\"manual.html#6.7\">6.7 &ndash; Mathematical Functions</A>\n<LI><A HREF=\"manual.html#6.8\">6.8 &ndash; Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#6.9\">6.9 &ndash; Operating System Facilities</A>\n<LI><A HREF=\"manual.html#6.10\">6.10 &ndash; The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#7\">7 &ndash; Lua Standalone</A>\n<P>\n<LI><A HREF=\"manual.html#8\">8 &ndash; Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#8.1\">8.1 &ndash; Incompatibilities in the Language</A>\n<LI><A HREF=\"manual.html#8.2\">8.2 &ndash; Incompatibilities in the Libraries</A>\n<LI><A HREF=\"manual.html#8.3\">8.3 &ndash; Incompatibilities in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#9\">9 &ndash; The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE CLASS=\"menubar\" WIDTH=\"100%\">\n<TR>\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<P>\n<A HREF=\"manual.html#6.1\">basic</A><BR>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawlen\">rawlen</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-warn\">warn</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.2\">coroutine</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.close\">coroutine.close</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.isyieldable\">coroutine.isyieldable</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.10\">debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.getuservalue\">debug.getuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setcstacklimit\">debug.setcstacklimit</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setuservalue\">debug.setuservalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvalueid\">debug.upvalueid</A><BR>\n<A HREF=\"manual.html#pdf-debug.upvaluejoin\">debug.upvaluejoin</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.8\">io</A><BR>\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<P>\n<A HREF=\"manual.html#6.7\">math</A><BR>\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.maxinteger\">math.maxinteger</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.mininteger\">math.mininteger</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tointeger\">math.tointeger</A><BR>\n<A HREF=\"manual.html#pdf-math.type\">math.type</A><BR>\n<A HREF=\"manual.html#pdf-math.ult\">math.ult</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.9\">os</A><BR>\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.3\">package</A><BR>\n<A HREF=\"manual.html#pdf-package.config\">package.config</A><BR>\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.searchers\">package.searchers</A><BR>\n<A HREF=\"manual.html#pdf-package.searchpath\">package.searchpath</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.4\">string</A><BR>\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.pack\">string.pack</A><BR>\n<A HREF=\"manual.html#pdf-string.packsize\">string.packsize</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.unpack\">string.unpack</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.6\">table</A><BR>\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.move\">table.move</A><BR>\n<A HREF=\"manual.html#pdf-table.pack\">table.pack</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n<A HREF=\"manual.html#pdf-table.unpack\">table.unpack</A><BR>\n\n<P>\n<A HREF=\"manual.html#6.5\">utf8</A><BR>\n<A HREF=\"manual.html#pdf-utf8.char\">utf8.char</A><BR>\n<A HREF=\"manual.html#pdf-utf8.charpattern\">utf8.charpattern</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codepoint\">utf8.codepoint</A><BR>\n<A HREF=\"manual.html#pdf-utf8.codes\">utf8.codes</A><BR>\n<A HREF=\"manual.html#pdf-utf8.len\">utf8.len</A><BR>\n<A HREF=\"manual.html#pdf-utf8.offset\">utf8.offset</A><BR>\n\n<H3><A NAME=\"metamethods\">metamethods</A></H3>\n<P>\n<A HREF=\"manual.html#2.4\">__add</A><BR>\n<A HREF=\"manual.html#2.4\">__band</A><BR>\n<A HREF=\"manual.html#2.4\">__bnot</A><BR>\n<A HREF=\"manual.html#2.4\">__bor</A><BR>\n<A HREF=\"manual.html#2.4\">__bxor</A><BR>\n<A HREF=\"manual.html#2.4\">__call</A><BR>\n<A HREF=\"manual.html#3.3.8\">__close</A><BR>\n<A HREF=\"manual.html#2.4\">__concat</A><BR>\n<A HREF=\"manual.html#2.4\">__div</A><BR>\n<A HREF=\"manual.html#2.4\">__eq</A><BR>\n<A HREF=\"manual.html#2.5.3\">__gc</A><BR>\n<A HREF=\"manual.html#2.4\">__idiv</A><BR>\n<A HREF=\"manual.html#2.4\">__index</A><BR>\n<A HREF=\"manual.html#2.4\">__le</A><BR>\n<A HREF=\"manual.html#2.4\">__len</A><BR>\n<A HREF=\"manual.html#2.4\">__lt</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">__metatable</A><BR>\n<A HREF=\"manual.html#2.4\">__mod</A><BR>\n<A HREF=\"manual.html#2.5.4\">__mode</A><BR>\n<A HREF=\"manual.html#2.4\">__mul</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">__name</A><BR>\n<A HREF=\"manual.html#2.4\">__newindex</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">__pairs</A><BR>\n<A HREF=\"manual.html#2.4\">__pow</A><BR>\n<A HREF=\"manual.html#2.4\">__shl</A><BR>\n<A HREF=\"manual.html#2.4\">__shr</A><BR>\n<A HREF=\"manual.html#2.4\">__sub</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">__tostring</A><BR>\n<A HREF=\"manual.html#2.4\">__unm</A><BR>\n\n<H3><A NAME=\"env\">environment<BR>variables</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_CPATH\">LUA_CPATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_CPATH_5_4\">LUA_CPATH_5_4</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT\">LUA_INIT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_INIT_5_4\">LUA_INIT_5_4</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH\">LUA_PATH</A><BR>\n<A HREF=\"manual.html#pdf-LUA_PATH_5_4\">LUA_PATH_5_4</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"api\">C API</A></H3>\n<P>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_KContext\">lua_KContext</A><BR>\n<A HREF=\"manual.html#lua_KFunction\">lua_KFunction</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Unsigned\">lua_Unsigned</A><BR>\n<A HREF=\"manual.html#lua_WarnFunction\">lua_WarnFunction</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n\n<P>\n<A HREF=\"manual.html#lua_absindex\">lua_absindex</A><BR>\n<A HREF=\"manual.html#lua_arith\">lua_arith</A><BR>\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_callk\">lua_callk</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_compare\">lua_compare</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_copy\">lua_copy</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getextraspace\">lua_getextraspace</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_geti\">lua_geti</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getiuservalue\">lua_getiuservalue</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_isinteger\">lua_isinteger</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_isyieldable\">lua_isyieldable</A><BR>\n<A HREF=\"manual.html#lua_len\">lua_len</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdatauv\">lua_newuserdatauv</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_numbertointeger\">lua_numbertointeger</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pcallk\">lua_pcallk</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushglobaltable\">lua_pushglobaltable</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawgetp\">lua_rawgetp</A><BR>\n<A HREF=\"manual.html#lua_rawlen\">lua_rawlen</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_rawsetp\">lua_rawsetp</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resetthread\">lua_resetthread</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_rotate\">lua_rotate</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setcstacklimit\">lua_setcstacklimit</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_seti\">lua_seti</A><BR>\n<A HREF=\"manual.html#lua_setiuservalue\">lua_setiuservalue</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_setwarnf\">lua_setwarnf</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_stringtonumber\">lua_stringtonumber</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_toclose\">lua_toclose</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tointegerx\">lua_tointegerx</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_tonumberx\">lua_tonumberx</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueid\">lua_upvalueid</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_upvaluejoin\">lua_upvaluejoin</A><BR>\n<A HREF=\"manual.html#lua_version\">lua_version</A><BR>\n<A HREF=\"manual.html#lua_warning\">lua_warning</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n<A HREF=\"manual.html#lua_yieldk\">lua_yieldk</A><BR>\n\n</TD>\n<TD>\n<H3><A NAME=\"auxlib\">auxiliary library</A></H3>\n<P>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<A HREF=\"manual.html#luaL_Stream\">luaL_Stream</A><BR>\n\n<P>\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addgsub\">luaL_addgsub</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_argexpected\">luaL_argexpected</A><BR>\n<A HREF=\"manual.html#luaL_buffaddr\">luaL_buffaddr</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_buffinitsize\">luaL_buffinitsize</A><BR>\n<A HREF=\"manual.html#luaL_bufflen\">luaL_bufflen</A><BR>\n<A HREF=\"manual.html#luaL_buffsub\">luaL_buffsub</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_checkversion\">luaL_checkversion</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_execresult\">luaL_execresult</A><BR>\n<A HREF=\"manual.html#luaL_fileresult\">luaL_fileresult</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_getsubtable\">luaL_getsubtable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_len\">luaL_len</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadbufferx\">luaL_loadbufferx</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadfilex\">luaL_loadfilex</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newlib\">luaL_newlib</A><BR>\n<A HREF=\"manual.html#luaL_newlibtable\">luaL_newlibtable</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_opt\">luaL_opt</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffsize\">luaL_prepbuffsize</A><BR>\n<A HREF=\"manual.html#luaL_pushfail\">luaL_pushfail</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_pushresultsize\">luaL_pushresultsize</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_requiref\">luaL_requiref</A><BR>\n<A HREF=\"manual.html#luaL_setfuncs\">luaL_setfuncs</A><BR>\n<A HREF=\"manual.html#luaL_setmetatable\">luaL_setmetatable</A><BR>\n<A HREF=\"manual.html#luaL_testudata\">luaL_testudata</A><BR>\n<A HREF=\"manual.html#luaL_tolstring\">luaL_tolstring</A><BR>\n<A HREF=\"manual.html#luaL_traceback\">luaL_traceback</A><BR>\n<A HREF=\"manual.html#luaL_typeerror\">luaL_typeerror</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n<H3><A NAME=\"library\">standard library</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-luaopen_base\">luaopen_base</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_coroutine\">luaopen_coroutine</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_debug\">luaopen_debug</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_io\">luaopen_io</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_math\">luaopen_math</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_os\">luaopen_os</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_package\">luaopen_package</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_string\">luaopen_string</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_table\">luaopen_table</A><BR>\n<A HREF=\"manual.html#pdf-luaopen_utf8\">luaopen_utf8</A><BR>\n\n<H3><A NAME=\"constants\">constants</A></H3>\n<P>\n<A HREF=\"manual.html#pdf-LUA_ERRERR\">LUA_ERRERR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRFILE\">LUA_ERRFILE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRMEM\">LUA_ERRMEM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRRUN\">LUA_ERRRUN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_ERRSYNTAX\">LUA_ERRSYNTAX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCALL\">LUA_HOOKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKCOUNT\">LUA_HOOKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKLINE\">LUA_HOOKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKRET\">LUA_HOOKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_HOOKTAILCALL\">LUA_HOOKTAILCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUAL_BUFFERSIZE\">LUAL_BUFFERSIZE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCALL\">LUA_MASKCALL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKCOUNT\">LUA_MASKCOUNT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKLINE\">LUA_MASKLINE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MASKRET\">LUA_MASKRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MAXINTEGER\">LUA_MAXINTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MININTEGER\">LUA_MININTEGER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MINSTACK\">LUA_MINSTACK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_MULTRET\">LUA_MULTRET</A><BR>\n<A HREF=\"manual.html#pdf-LUA_NOREF\">LUA_NOREF</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OK\">LUA_OK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPADD\">LUA_OPADD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBAND\">LUA_OPBAND</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBNOT\">LUA_OPBNOT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBOR\">LUA_OPBOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPBXOR\">LUA_OPBXOR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPDIV\">LUA_OPDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPEQ\">LUA_OPEQ</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPIDIV\">LUA_OPIDIV</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLE\">LUA_OPLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPLT\">LUA_OPLT</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMOD\">LUA_OPMOD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPMUL\">LUA_OPMUL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPPOW\">LUA_OPPOW</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHL\">LUA_OPSHL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSHR\">LUA_OPSHR</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPSUB\">LUA_OPSUB</A><BR>\n<A HREF=\"manual.html#pdf-LUA_OPUNM\">LUA_OPUNM</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REFNIL\">LUA_REFNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_REGISTRYINDEX\">LUA_REGISTRYINDEX</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_GLOBALS\">LUA_RIDX_GLOBALS</A><BR>\n<A HREF=\"manual.html#pdf-LUA_RIDX_MAINTHREAD\">LUA_RIDX_MAINTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TBOOLEAN\">LUA_TBOOLEAN</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TFUNCTION\">LUA_TFUNCTION</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TLIGHTUSERDATA\">LUA_TLIGHTUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNIL\">LUA_TNIL</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNONE\">LUA_TNONE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TNUMBER\">LUA_TNUMBER</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TSTRING\">LUA_TSTRING</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTABLE\">LUA_TTABLE</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TTHREAD\">LUA_TTHREAD</A><BR>\n<A HREF=\"manual.html#pdf-LUA_TUSERDATA\">LUA_TUSERDATA</A><BR>\n<A HREF=\"manual.html#pdf-LUA_USE_APICHECK\">LUA_USE_APICHECK</A><BR>\n<A HREF=\"manual.html#pdf-LUA_YIELD\">LUA_YIELD</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n\n<P CLASS=\"footer\">\nLast update:\nWed Sep 30 06:45:10 -03 2020\n</P>\n<!--\nLast change: revised for Lua 5.4.1\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.4.1/doc/index.css",
    "content": "ul {\n\tlist-style-type: none ;\n}\n\nul.contents {\n\tpadding: 0 ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tvertical-align: top ;\n\tpadding: 0 ;\n\ttext-align: left ;\n\tline-height: 1.25 ;\n\twidth: 15% ;\n}\n"
  },
  {
    "path": "build/lua-5.4.1/doc/lua.1",
    "content": ".\\\" $Id: lua.man,v 1.14 2020/05/21 19:31:21 lhf Exp $\n.TH LUA 1 \"$Date: 2020/05/21 19:31:21 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the standalone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nAfter handling the\n.IR options ,\nthe Lua program in file\n.I script\nis loaded and executed.\nThe\n.I args\nare available to\n.I script\nas strings in a global table named\n.B arg\nand also as arguments to its main function.\nWhen called without arguments,\n.B lua\nbehaves as\n.B \"lua \\-v \\-i\"\nif the standard input is a terminal,\nand as\n.B \"lua \\-\"\notherwise.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf the line contains an expression,\nthen the line is evaluated and the result is printed.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\n.LP\nBefore handling command line options and scripts,\n.B lua\nchecks the contents of the environment variables\n.B LUA_INIT_5_4\nand\n.BR LUA_INIT ,\nin that order.\nIf the contents are of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the contents are assumed to be a Lua statement and is executed.\nWhen\n.B LUA_INIT_5_4\nis defined,\n.B LUA_INIT\nis ignored.\n.SH OPTIONS\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\n.TP\n.B \\-i\nenter interactive mode after executing\n.IR script .\n.TP\n.BI \\-l \" name\"\nrequire library\n.I name\ninto global\n.IR name .\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-E\nignore environment variables.\n.TP\n.B \\-W\nturn warnings on.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and execute the standard input as a file.\n.SH ENVIRONMENT VARIABLES\nThe following environment variables affect the execution of\n.BR lua .\nWhen defined,\nthe version-specific variants take priority\nand the version-neutral variants are ignored.\n.TP\n.B LUA_INIT, LUA_INIT_5_4\nCode to be executed before command line options and scripts.\n.TP\n.B LUA_PATH, LUA_PATH_5_4\nInitial value of package.cpath,\nthe path used by require to search for Lua loaders.\n.TP\n.B LUA_CPATH, LUA_CPATH_5_4\nInitial value of package.cpath,\nthe path used by require to search for C loaders.\n.SH EXIT STATUS\nIf a script calls os.exit,\nthen\n.B lua\nexits with the given exit status.\nOtherwise,\n.B lua\nexits\nwith EXIT_SUCCESS (0 on POSIX systems) if there were no errors\nand\nwith EXIT_FAILURE (1 on POSIX systems) if there were errors.\nErrors raised in interactive mode do not cause exits.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nThe documentation at lua.org,\nespecially section 7 of the reference manual.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.4.1/doc/lua.css",
    "content": "html {\n\tbackground-color: #F8F8F8 ;\n}\n\nbody {\n\tbackground-color: #FFFFFF ;\n\tcolor: #000000 ;\n\tfont-family: Helvetica, Arial, sans-serif ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n\tmargin: 16px auto ;\n\tpadding: 32px ;\n\tborder: solid #ccc 1px ;\n\tborder-radius: 20px ;\n\tmax-width: 70em ;\n\twidth: 90% ;\n}\n\nh1, h2, h3, h4 {\n\tcolor: #000080 ;\n\tfont-family: Verdana, Geneva, sans-serif ;\n\tfont-weight: normal ;\n\tfont-style: normal ;\n\ttext-align: left ;\n}\n\nh1 {\n\tfont-size: 28pt ;\n}\n\nh1 img {\n\tvertical-align: text-bottom ;\n}\n\nh2:before {\n\tcontent: \"\\2756\" ;\n\tpadding-right: 0.5em ;\n}\n\na {\n\ttext-decoration: none ;\n}\n\na:link {\n\tcolor: #000080 ;\n}\n\na:link:hover, a:visited:hover {\n\tbackground-color: #D0D0FF ;\n\tcolor: #000080 ;\n\tborder-radius: 4px ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\ndiv.menubar {\n\tpadding-bottom: 0.5em ;\n}\n\np.menubar {\n\tmargin-left: 2.5em ;\n}\n\n.menubar a:hover  {\n\tmargin: -3px -3px -3px -3px ;\n\tpadding: 3px  3px  3px  3px ;\n\tborder-radius: 4px ;\n}\n\n:target {\n\tbackground-color: #F0F0F0 ;\n\tmargin: -8px ;\n\tpadding: 8px ;\n\tborder-radius: 8px ;\n\toutline: none ;\n}\n\nhr {\n\tdisplay: none ;\n}\n\ntable hr {\n\tbackground-color: #a0a0a0 ;\n\tcolor: #a0a0a0 ;\n\tborder: 0 ;\n\theight: 1px ;\n\tdisplay: block ;\n}\n\n.footer {\n\tcolor: gray ;\n\tfont-size: x-small ;\n\ttext-transform: lowercase ;\n}\n\ninput[type=text] {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 2em ;\n\tbackground-image: url('images/search.png') ;\n\tbackground-repeat: no-repeat ;\n\tbackground-position: 4px center ;\n\tpadding-left: 20px ;\n\theight: 2em ;\n}\n\npre.session {\n\tbackground-color: #F8F8F8 ;\n\tpadding: 1em ;\n\tborder-radius: 8px ;\n}\n\ntable {\n\tborder: none ;\n\tborder-spacing: 0 ;\n\tborder-collapse: collapse ;\n}\n\ntd {\n\tpadding: 0 ;\n\tmargin: 0 ;\n}\n\ntd.gutter {\n\twidth: 4% ;\n}\n\ntable.columns td {\n\tvertical-align: top ;\n\tpadding-bottom: 1em ;\n\ttext-align: justify ;\n\tline-height: 1.25 ;\n}\n\ntable.book td {\n\tvertical-align: top ;\n}\n\ntable.book td.cover {\n\tpadding-right: 1em ;\n}\n\ntable.book img {\n\tborder: solid #000080 1px ;\n}\n\ntable.book span {\n\tfont-size: small ;\n\ttext-align: left ;\n\tdisplay: block ;\n\tmargin-top: 0.25em ;\n}\n\np.logos a:link:hover, p.logos a:visited:hover {\n\tbackground-color: inherit ;\n}\n\nimg {\n\tbackground-color: white ;\n}\n"
  },
  {
    "path": "build/lua-5.4.1/doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $\n.TH LUAC 1 \"$Date: 2011/11/16 13:53:40 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files containing precompiled chunks\nthat can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\n.B luac\nproduces a single output file containing the combined bytecodes\nfor all files given.\nExecuting the combined file is equivalent to executing the given files.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nPrecompiled chunks are\n.I not\nportable across different architectures.\nMoreover,\nthe internal format of precompiled chunks\nis likely to change when a new version of Lua is released.\nMake sure you save the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\nUse\n.B \\-l \\-l\nfor a full listing.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be one of the given files because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file loads without errors.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nIn particular,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.TP\n.B \\-\\-\nstop handling options.\n.TP\n.B \\-\nstop handling options and process standard input.\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nThe documentation at lua.org.\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "build/lua-5.4.1/doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n\tfont-size: inherit ;\n}\n\npre, code {\n\tfont-size: 12pt ;\n}\n\nspan.apii {\n\tcolor: gray ;\n\tfloat: right ;\n\tfont-family: inherit ;\n\tfont-style: normal ;\n\tfont-size: small ;\n}\n\nh2:before {\n\tcontent: \"\" ;\n\tpadding-right: 0em ;\n}\n"
  },
  {
    "path": "build/lua-5.4.1/doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.4 Reference Manual</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nLua 5.4 Reference Manual\n</H1>\n\n<P>\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n\n<P>\n<SMALL>\nCopyright &copy; 2020 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html\">Lua license</a>.\n</SMALL>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"contents.html#contents\">contents</A>\n&middot;\n<A HREF=\"contents.html#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/\">other versions</A>\n</DIV>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of $ -->\n\n\n\n\n<h1>1 &ndash; <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is a powerful, efficient, lightweight, embeddable scripting language.\nIt supports procedural programming,\nobject-oriented programming, functional programming,\ndata-driven programming, and data description.\n\n\n<p>\nLua combines simple procedural syntax with powerful data description\nconstructs based on associative arrays and extensible semantics.\nLua is dynamically typed,\nruns by interpreting bytecode with a register-based\nvirtual machine,\nand has automatic memory management with\na generational garbage collection,\nmaking it ideal for configuration, scripting,\nand rapid prototyping.\n\n\n<p>\nLua is implemented as a library, written in <em>clean C</em>,\nthe common subset of Standard&nbsp;C and C++.\nThe Lua distribution includes a host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete,\nstandalone Lua interpreter,\nfor interactive or batch use.\nLua is intended to be used both as a powerful, lightweight,\nembeddable scripting language for any program that needs one,\nand as a powerful but lightweight and efficient stand-alone language.\n\n\n<p>\nAs an extension language, Lua has no notion of a \"main\" program:\nit works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\n(Frequently, this host is the stand-alone <code>lua</code> program.)\nThe host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua</em>.\n\n\n\n<h1>2 &ndash; <a name=\"2\">Basic Concepts</a></h1>\n\n\n\n<p>\nThis section describes the basic concepts of the language.\n\n\n\n\n\n<h2>2.1 &ndash; <a name=\"2.1\">Values and Types</a></h2>\n\n<p>\nLua is a dynamically typed language.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are first-class values.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\nThe type <em>nil</em> has one single value, <b>nil</b>,\nwhose main property is to be different from any other value;\nit often represents the absence of a useful value.\nThe type <em>boolean</em> has two values, <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nthey are collectively called <em>false values</em>.\nAny other value makes a condition true.\n\n\n<p>\nThe type <em>number</em> represents both\ninteger numbers and real (floating-point) numbers,\nusing two subtypes: <em>integer</em> and <em>float</em>.\nStandard Lua uses 64-bit integers and double-precision (64-bit) floats,\nbut you can also compile Lua so that it\nuses 32-bit integers and/or single-precision (32-bit) floats.\nThe option with 32 bits for both integers and floats\nis particularly attractive\nfor small machines and embedded systems.\n(See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)\n\n\n<p>\nUnless stated otherwise,\nany overflow when manipulating integer values <em>wrap around</em>,\naccording to the usual rules of two-complement arithmetic.\n(In other words,\nthe actual result is the unique representable integer\nthat is equal modulo <em>2<sup>n</sup></em> to the mathematical result,\nwhere <em>n</em> is the number of bits of the integer type.)\n\n\n<p>\nLua has explicit rules about when each subtype is used,\nbut it also converts between them automatically as needed (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\nTherefore,\nthe programmer may choose to mostly ignore the difference\nbetween integers and floats\nor to assume complete control over the representation of each number.\n\n\n<p>\nThe type <em>string</em> represents immutable sequences of bytes.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit value,\nincluding embedded zeros ('<code>\\0</code>').\nLua is also encoding-agnostic;\nit makes no assumptions about the contents of a string.\nThe length of any string in Lua must fit in a Lua integer.\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C (see <a href=\"#3.4.10\">&sect;3.4.10</a>).\nBoth are represented by the type <em>function</em>.\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nA userdata value represents a block of raw memory.\nThere are two kinds of userdata:\n<em>full userdata</em>,\nwhich is an object with a block of memory managed by Lua,\nand <em>light userdata</em>,\nwhich is simply a C&nbsp;pointer value.\nUserdata has no predefined operations in Lua,\nexcept assignment and identity test.\nBy using <em>metatables</em>,\nthe programmer can define operations for full userdata values\n(see <a href=\"#2.4\">&sect;2.4</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by\nthe host program and C&nbsp;libraries.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.6\">&sect;2.6</a>).\nLua threads are not related to operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads natively.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can have as indices not only numbers,\nbut any Lua value except <b>nil</b> and NaN.\n(<em>Not a Number</em> is a special floating-point value\nused by the IEEE 754 standard to represent\nundefined numerical results, such as <code>0/0</code>.)\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nAny key associated to the value <b>nil</b> is not considered part of the table.\nConversely, any key that is not part of a table has\nan associated value <b>nil</b>.\n\n\n<p>\nTables are the sole data-structuring mechanism in Lua;\nthey can be used to represent ordinary arrays, lists,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#3.4.9\">&sect;3.4.9</a>).\n\n\n<p>\nLike indices,\nthe values of table fields can be of any type.\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#3.4.11\">&sect;3.4.11</a>).\n\n\n<p>\nThe indexing of tables follows\nthe definition of raw equality in the language.\nThe expressions <code>a[i]</code> and <code>a[j]</code>\ndenote the same table element\nif and only if <code>i</code> and <code>j</code> are raw equal\n(that is, equal without metamethods).\nIn particular, floats with integral values\nare equal to their respective integers\n(e.g., <code>1.0 == 1</code>).\nTo avoid ambiguities,\nany float used as a key that is equal to an integer\nis converted to that integer.\nFor instance, if you write <code>a[2.0] = true</code>,\nthe actual key inserted into the table will be the integer <code>2</code>.\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value (see <a href=\"#pdf-type\"><code>type</code></a>).\n\n\n\n\n\n<h2>2.2 &ndash; <a name=\"2.2\">Environments and the Global Environment</a></h2>\n\n<p>\nAs we will discuss further in <a href=\"#3.2\">&sect;3.2</a> and <a href=\"#3.3.3\">&sect;3.3.3</a>,\nany reference to a free name\n(that is, a name not bound to any declaration) <code>var</code>\nis syntactically translated to <code>_ENV.var</code>.\nMoreover, every chunk is compiled in the scope of\nan external local variable named <code>_ENV</code> (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nso <code>_ENV</code> itself is never a free name in a chunk.\n\n\n<p>\nDespite the existence of this external <code>_ENV</code> variable and\nthe translation of free names,\n<code>_ENV</code> is a completely regular name.\nIn particular,\nyou can define new variables and parameters with that name.\nEach reference to a free name uses the <code>_ENV</code> that is\nvisible at that point in the program,\nfollowing the usual visibility rules of Lua (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nAny table used as the value of <code>_ENV</code> is called an <em>environment</em>.\n\n\n<p>\nLua keeps a distinguished environment called the <em>global environment</em>.\nThis value is kept at a special index in the C registry (see <a href=\"#4.3\">&sect;4.3</a>).\nIn Lua, the global variable <a href=\"#pdf-_G\"><code>_G</code></a> is initialized with this same value.\n(<a href=\"#pdf-_G\"><code>_G</code></a> is never used internally,\nso changing its value will affect only your own code.)\n\n\n<p>\nWhen Lua loads a chunk,\nthe default value for its <code>_ENV</code> variable\nis the global environment (see <a href=\"#pdf-load\"><code>load</code></a>).\nTherefore, by default,\nfree names in Lua code refer to entries in the global environment\nand, therefore, they are also called <em>global variables</em>.\nMoreover, all standard libraries are loaded in the global environment\nand some functions there operate on that environment.\nYou can use <a href=\"#pdf-load\"><code>load</code></a> (or <a href=\"#pdf-loadfile\"><code>loadfile</code></a>)\nto load a chunk with a different environment.\n(In C, you have to load the chunk and then change the value\nof its first upvalue; see <a href=\"#lua_setupvalue\"><code>lua_setupvalue</code></a>.)\n\n\n\n\n\n<h2>2.3 &ndash; <a name=\"2.3\">Error Handling</a></h2>\n\n<p>\nSeveral operations in Lua can <em>raise</em> an error.\nAn error interrupts the normal flow of the program,\nwhich can continue by <em>catching</em> the error.\n\n\n<p>\nLua code can explicitly raise an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\n(This function never returns.)\n\n\n<p>\nTo catch errors in Lua,\nyou can do a <em>protected call</em>,\nusing <a href=\"#pdf-pcall\"><code>pcall</code></a> (or <a href=\"#pdf-xpcall\"><code>xpcall</code></a>).\nThe function <a href=\"#pdf-pcall\"><code>pcall</code></a> calls a given function in <em>protected mode</em>.\nAny error while running the function stops its execution,\nand control returns immediately to <code>pcall</code>,\nwhich returns a status code.\n\n\n<p>\nBecause Lua is an embedded extension language,\nLua code starts running by a call\nfrom C&nbsp;code in the host program.\n(When you use Lua standalone,\nthe <code>lua</code> application is the host program.)\nUsually, this call is protected;\nso, when an otherwise unprotected error occurs during\nthe compilation or execution of a Lua chunk,\ncontrol returns to the host,\nwhich can take appropriate measures,\nsuch as printing an error message.\n\n\n<p>\nWhenever there is an error,\nan <em>error object</em>\nis propagated with information about the error.\nLua itself only generates errors whose error object is a string,\nbut programs may generate errors with\nany value as the error object.\nIt is up to the Lua program or its host to handle such error objects.\nFor historical reasons,\nan error object is often called an <em>error message</em>,\neven though it does not have to be a string.\n\n\n<p>\nWhen you use <a href=\"#pdf-xpcall\"><code>xpcall</code></a> (or <a href=\"#lua_pcall\"><code>lua_pcall</code></a>, in C)\nyou may give a <em>message handler</em>\nto be called in case of errors.\nThis function is called with the original error object\nand returns a new error object.\nIt is called before the error unwinds the stack,\nso that it can gather more information about the error,\nfor instance by inspecting the stack and creating a stack traceback.\nThis message handler is still protected by the protected call;\nso, an error inside the message handler\nwill call the message handler again.\nIf this loop goes on for too long,\nLua breaks it and returns an appropriate message.\nThe message handler is called only for regular runtime errors.\nIt is not called for memory-allocation errors\nnor for errors while running finalizers or other message handlers.\n\n\n<p>\nLua also offers a system of <em>warnings</em> (see <a href=\"#pdf-warn\"><code>warn</code></a>).\nUnlike errors, warnings do not interfere\nin any way with program execution.\nThey typically only generate a message to the user,\nalthough this behavior can be adapted from C (see <a href=\"#lua_setwarnf\"><code>lua_setwarnf</code></a>).\n\n\n\n\n\n<h2>2.4 &ndash; <a name=\"2.4\">Metatables and Metamethods</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain events.\nYou can change several aspects of the behavior\nof a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field \"<code>__add</code>\" of the value's metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nThe key for each event in a metatable is a string\nwith the event name prefixed by two underscores;\nthe corresponding value is called a <em>metavalue</em>.\nFor most events, the metavalue must be a function,\nwhich is then called a <em>metamethod</em>.\nIn the previous example, the key is the string \"<code>__add</code>\"\nand the metamethod is the function that performs the addition.\nUnless stated otherwise,\na metamethod may in fact be any callable value,\nwhich is either a function or a value with a <code>__call</code> metamethod.\n\n\n<p>\nYou can query the metatable of any value\nusing the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\nLua queries metamethods in metatables using a raw access (see <a href=\"#pdf-rawget\"><code>rawget</code></a>).\n\n\n<p>\nYou can replace the metatable of tables\nusing the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a> function.\nYou cannot change the metatable of other types from Lua code,\nexcept by using the debug library (<a href=\"#6.10\">&sect;6.10</a>).\n\n\n<p>\nTables and full userdata have individual metatables,\nalthough multiple tables and userdata can share their metatables.\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\nBy default, a value has no metatable,\nbut the string library sets a metatable for the string type (see <a href=\"#6.4\">&sect;6.4</a>).\n\n\n<p>\nA detailed list of operations controlled by metatables is given next.\nEach event is identified by its corresponding key.\nBy convention, all metatable keys used by Lua are composed by\ntwo underscores followed by lowercase Latin letters.\n\n\n\n<ul>\n\n<li><b><code>__add</code>: </b>\nthe addition (<code>+</code>) operation.\nIf any operand for an addition is not a number,\nLua will try to call a metamethod.\nIt starts by checking the first operand (even if it is a number);\nif that operand does not define a metamethod for <code>__add</code>,\nthen Lua will check the second operand.\nIf Lua can find a metamethod,\nit calls the metamethod with the two operands as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nOtherwise, if no metamethod is found,\nLua raises an error.\n</li>\n\n<li><b><code>__sub</code>: </b>\nthe subtraction (<code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mul</code>: </b>\nthe multiplication (<code>*</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__div</code>: </b>\nthe division (<code>/</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__mod</code>: </b>\nthe modulo (<code>%</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__pow</code>: </b>\nthe exponentiation (<code>^</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__unm</code>: </b>\nthe negation (unary <code>-</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__idiv</code>: </b>\nthe floor division (<code>//</code>) operation.\nBehavior similar to the addition operation.\n</li>\n\n<li><b><code>__band</code>: </b>\nthe bitwise AND (<code>&amp;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither an integer\nnor a float coercible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\n</li>\n\n<li><b><code>__bor</code>: </b>\nthe bitwise OR (<code>|</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bxor</code>: </b>\nthe bitwise exclusive OR (binary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__bnot</code>: </b>\nthe bitwise NOT (unary <code>~</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shl</code>: </b>\nthe bitwise left shift (<code>&lt;&lt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__shr</code>: </b>\nthe bitwise right shift (<code>&gt;&gt;</code>) operation.\nBehavior similar to the bitwise AND operation.\n</li>\n\n<li><b><code>__concat</code>: </b>\nthe concatenation (<code>..</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod\nif any operand is neither a string nor a number\n(which is always coercible to a string).\n</li>\n\n<li><b><code>__len</code>: </b>\nthe length (<code>#</code>) operation.\nIf the object is not a string,\nLua will try its metamethod.\nIf there is a metamethod,\nLua calls it with the object as argument,\nand the result of the call\n(always adjusted to one value)\nis the result of the operation.\nIf there is no metamethod but the object is a table,\nthen Lua uses the table length operation (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nOtherwise, Lua raises an error.\n</li>\n\n<li><b><code>__eq</code>: </b>\nthe equal (<code>==</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are either both tables or both full userdata\nand they are not primitively equal.\nThe result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__lt</code>: </b>\nthe less than (<code>&lt;</code>) operation.\nBehavior similar to the addition operation,\nexcept that Lua will try a metamethod only when the values\nbeing compared are neither both numbers nor both strings.\nMoreover, the result of the call is always converted to a boolean.\n</li>\n\n<li><b><code>__le</code>: </b>\nthe less equal (<code>&lt;=</code>) operation.\nBehavior similar to the less than operation.\n</li>\n\n<li><b><code>__index</code>: </b>\nThe indexing access operation <code>table[key]</code>.\nThis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metavalue is looked up in the metatable of <code>table</code>.\n\n\n<p>\nThe metavalue for this event can be either a function, a table,\nor any value with an <code>__index</code> metavalue.\nIf it is a function,\nit is called with <code>table</code> and <code>key</code> as arguments,\nand the result of the call\n(adjusted to one value)\nis the result of the operation.\nOtherwise,\nthe final result is the result of indexing this metavalue with <code>key</code>.\nThis indexing is regular, not raw,\nand therefore can trigger another <code>__index</code> metavalue.\n</li>\n\n<li><b><code>__newindex</code>: </b>\nThe indexing assignment <code>table[key] = value</code>.\nLike the index event,\nthis event happens when <code>table</code> is not a table or\nwhen <code>key</code> is not present in <code>table</code>.\nThe metavalue is looked up in the metatable of <code>table</code>.\n\n\n<p>\nLike with indexing,\nthe metavalue for this event can be either a function, a table,\nor any value with an <code>__newindex</code> metavalue.\nIf it is a function,\nit is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.\nOtherwise,\nLua repeats the indexing assignment over this metavalue\nwith the same key and value.\nThis assignment is regular, not raw,\nand therefore can trigger another <code>__newindex</code> metavalue.\n\n\n<p>\nWhenever a <code>__newindex</code> metavalue is invoked,\nLua does not perform the primitive assignment.\nIf needed,\nthe metamethod itself can call <a href=\"#pdf-rawset\"><code>rawset</code></a>\nto do the assignment.\n</li>\n\n<li><b><code>__call</code>: </b>\nThe call operation <code>func(args)</code>.\nThis event happens when Lua tries to call a non-function value\n(that is, <code>func</code> is not a function).\nThe metamethod is looked up in <code>func</code>.\nIf present,\nthe metamethod is called with <code>func</code> as its first argument,\nfollowed by the arguments of the original call (<code>args</code>).\nAll results of the call\nare the results of the operation.\nThis is the only metamethod that allows multiple results.\n</li>\n\n</ul>\n\n<p>\nIn addition to the previous list,\nthe interpreter also respects the following keys in metatables:\n<code>__gc</code> (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\n<code>__close</code> (see <a href=\"#3.3.8\">&sect;3.3.8</a>),\n<code>__mode</code> (see <a href=\"#2.5.4\">&sect;2.5.4</a>),\nand <code>__name</code>.\n(The entry <code>__name</code>,\nwhen it contains a string,\nmay be used by <a href=\"#pdf-tostring\"><code>tostring</code></a> and in error messages.)\n\n\n<p>\nFor the unary operators (negation, length, and bitwise NOT),\nthe metamethod is computed and called with a dummy second operand,\nequal to the first one.\nThis extra operand is only to simplify Lua's internals\n(by making these operators behave like a binary operation)\nand may be removed in future versions.\nFor most uses this extra operand is irrelevant.\n\n\n<p>\nBecause metatables are regular tables,\nthey can contain arbitrary fields,\nnot only the event names defined above.\nSome functions in the standard library\n(e.g., <a href=\"#pdf-tostring\"><code>tostring</code></a>)\nuse other fields in metatables for their own purposes.\n\n\n<p>\nIt is a good practice to add all needed metamethods to a table\nbefore setting it as a metatable of some object.\nIn particular, the <code>__gc</code> metamethod works only when this order\nis followed (see <a href=\"#2.5.3\">&sect;2.5.3</a>).\nIt is also a good practice to set the metatable of an object\nright after its creation.\n\n\n\n\n\n<h2>2.5 &ndash; <a name=\"2.5\">Garbage Collection</a></h2>\n\n\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou do not have to worry about allocating memory for new objects\nor freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> to collect all <em>dead</em> objects.\nAll memory used by Lua is subject to automatic management:\nstrings, tables, userdata, functions, threads, internal structures, etc.\n\n\n<p>\nAn object is considered <em>dead</em>\nas soon as the collector can be sure the object\nwill not be accessed again in the normal execution of the program.\n(\"Normal execution\" here excludes finalizers,\nwhich can resurrect dead objects (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nand excludes also operations using the debug library.)\nNote that the time when the collector can be sure that an object\nis dead may not coincide with the programmer's expectations.\nThe only guarantees are that Lua will not collect an object\nthat may still be accessed in the normal execution of the program,\nand it will eventually collect an object\nthat is inaccessible from Lua.\n(Here,\n<em>inaccessible from Lua</em> means that neither a variable nor\nanother live object refer to the object.)\nBecause Lua has no knowledge about C&nbsp;code,\nit never collects objects accessible through the registry (see <a href=\"#4.3\">&sect;4.3</a>),\nwhich includes the global environment (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n<p>\nThe garbage collector (GC) in Lua can work in two modes:\nincremental and generational.\n\n\n<p>\nThe default GC mode with the default parameters\nare adequate for most uses.\nHowever, programs that waste a large proportion of their time\nallocating and freeing memory can benefit from other settings.\nKeep in mind that the GC behavior is non-portable\nboth across platforms and across different Lua releases;\ntherefore, optimal settings are also non-portable.\n\n\n<p>\nYou can change the GC mode and parameters by calling\n<a href=\"#lua_gc\"><code>lua_gc</code></a> in&nbsp;C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nYou can also use these functions to control\nthe collector directly (e.g., to stop and restart it).\n\n\n\n\n\n<h3>2.5.1 &ndash; <a name=\"2.5.1\">Incremental Garbage Collection</a></h3>\n\n<p>\nIn incremental mode,\neach GC cycle performs a mark-and-sweep collection in small steps\ninterleaved with the program's execution.\nIn this mode,\nthe collector uses three numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em>,\nthe <em>garbage-collector step multiplier</em>,\nand the <em>garbage-collector step size</em>.\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nThe collector starts a new cycle when the use of memory\nhits <em>n%</em> of the use after the previous collection.\nLarger values make the collector less aggressive.\nValues equal to or less than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\nThe default value is 200; the maximum value is 1000.\n\n\n<p>\nThe garbage-collector step multiplier\ncontrols the speed of the collector relative to\nmemory allocation,\nthat is,\nhow many elements it marks or sweeps for each\nkilobyte of memory allocated.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nYou should not use values less than 100,\nbecause they make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default value is 100;  the maximum value is 1000.\n\n\n<p>\nThe garbage-collector step size controls the\nsize of each incremental step,\nspecifically how many bytes the interpreter allocates\nbefore performing a step.\nThis parameter is logarithmic:\nA value of <em>n</em> means the interpreter will allocate <em>2<sup>n</sup></em>\nbytes between steps and perform equivalent work during the step.\nA large value (e.g., 60) makes the collector a stop-the-world\n(non-incremental) collector.\nThe default value is 13,\nwhich means steps of approximately 8&nbsp;Kbytes.\n\n\n\n\n\n<h3>2.5.2 &ndash; <a name=\"2.5.2\">Generational Garbage Collection</a></h3>\n\n<p>\nIn generational mode,\nthe collector does frequent <em>minor</em> collections,\nwhich traverses only objects recently created.\nIf after a minor collection the use of memory is still above a limit,\nthe collector does a stop-the-world <em>major</em> collection,\nwhich traverses all objects.\nThe generational mode uses two parameters:\nthe <em>minor multiplier</em> and the <em>the major multiplier</em>.\n\n\n<p>\nThe minor multiplier controls the frequency of minor collections.\nFor a minor multiplier <em>x</em>,\na new minor collection will be done when memory\ngrows <em>x%</em> larger than the memory in use after the previous major\ncollection.\nFor instance, for a multiplier of 20,\nthe collector will do a minor collection when the use of memory\ngets 20% larger than the use after the previous major collection.\nThe default value is 20; the maximum value is 200.\n\n\n<p>\nThe major multiplier controls the frequency of major collections.\nFor a major multiplier <em>x</em>,\na new major collection will be done when memory\ngrows <em>x%</em> larger than the memory in use after the previous major\ncollection.\nFor instance, for a multiplier of 100,\nthe collector will do a major collection when the use of memory\ngets larger than twice the use after the previous collection.\nThe default value is 100; the maximum value is 1000.\n\n\n\n\n\n<h3>2.5.3 &ndash; <a name=\"2.5.3\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nYou can set garbage-collector metamethods for tables\nand, using the C&nbsp;API,\nfor full userdata (see <a href=\"#2.4\">&sect;2.4</a>).\nThese metamethods, called <em>finalizers</em>,\nare called when the garbage collector detects that the\ncorresponding table or userdata is dead.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management such as closing files,\nnetwork or database connections,\nor freeing your own memory.\n\n\n<p>\nFor an object (table or userdata) to be finalized when collected,\nyou must <em>mark</em> it for finalization.\n\nYou mark an object for finalization when you set its metatable\nand the metatable has a field indexed by the string \"<code>__gc</code>\".\nNote that if you set a metatable without a <code>__gc</code> field\nand later create that field in the metatable,\nthe object will not be marked for finalization.\n\n\n<p>\nWhen a marked object becomes dead,\nit is not collected immediately by the garbage collector.\nInstead, Lua puts it in a list.\nAfter the collection,\nLua goes through that list.\nFor each object in the list,\nit checks the object's <code>__gc</code> metamethod:\nIf it is present,\nLua calls it with the object as its single argument.\n\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers are called in\nthe reverse order that the objects were marked for finalization,\namong those collected in that cycle;\nthat is, the first finalizer to be called is the one associated\nwith the object marked last in the program.\nThe execution of each finalizer may occur at any point during\nthe execution of the regular code.\n\n\n<p>\nBecause the object being collected must still be used by the finalizer,\nthat object (and other objects accessible only through it)\nmust be <em>resurrected</em> by Lua.\nUsually, this resurrection is transient,\nand the object memory is freed in the next garbage-collection cycle.\nHowever, if the finalizer stores the object in some global place\n(e.g., a global variable),\nthen the resurrection is permanent.\nMoreover, if the finalizer marks a finalizing object for finalization again,\nits finalizer will be called again in the next cycle where the\nobject is dead.\nIn any case,\nthe object memory is freed only in a GC cycle where\nthe object is dead and not marked for finalization.\n\n\n<p>\nWhen you close a state (see <a href=\"#lua_close\"><code>lua_close</code></a>),\nLua calls the finalizers of all objects marked for finalization,\nfollowing the reverse order that they were marked.\nIf any finalizer marks objects for collection during that phase,\nthese marks have no effect.\n\n\n<p>\nFinalizers cannot yield.\nExcept for that, they can do anything,\nsuch as raise errors, create new objects,\nor even run the garbage collector.\nHowever, because they can run in unpredictable times,\nit is good practice to restrict each finalizer\nto the minimum necessary to properly release\nits associated resource.\n\n\n<p>\nAny error while running a finalizer generates a warning;\nthe error is not propagated.\n\n\n\n\n\n<h3>2.5.4 &ndash; <a name=\"2.5.4\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect that object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak values allows the collection of its values,\nbut prevents the collection of its keys.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nThis metavalue, if present, must be one of the following strings:\n\"<code>k</code>\", for a table with weak keys;\n\"<code>v</code>\", for a table with weak values;\nor \"<code>kv</code>\", for a table with both weak keys and values.\n\n\n<p>\nA table with weak keys and strong values\nis also called an <em>ephemeron table</em>.\nIn an ephemeron table,\na value is considered reachable only if its key is reachable.\nIn particular,\nif the only reference to a key comes through its value,\nthe pair is removed.\n\n\n<p>\nAny change in the weakness of a table may take effect only\nat the next collect cycle.\nIn particular, if you change the weakness to a stronger mode,\nLua may still collect some items from that table\nbefore the change takes effect.\n\n\n<p>\nOnly objects that have an explicit construction\nare removed from weak tables.\nValues, such as numbers and light C&nbsp;functions,\nare not subject to garbage collection,\nand therefore are not removed from weak tables\n(unless their associated values are collected).\nAlthough strings are subject to garbage collection,\nthey do not have an explicit construction and\ntheir equality is by value;\nthey behave more like values than like objects.\nTherefore, they are not removed from weak tables.\n\n\n<p>\nResurrected objects\n(that is, objects being finalized\nand objects accessible only through objects being finalized)\nhave a special behavior in weak tables.\nThey are removed from weak values before running their finalizers,\nbut are removed from weak keys only in the next collection\nafter running their finalizers, when such objects are actually freed.\nThis behavior allows the finalizer to access properties\nassociated with the object through weak tables.\n\n\n<p>\nIf a weak table is among the resurrected objects in a collection cycle,\nit may not be properly cleared until the next cycle.\n\n\n\n\n\n\n\n<h2>2.6 &ndash; <a name=\"2.6\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine by calling <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine.\n\n\n<p>\nYou execute a coroutine by calling <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution by\ncalling its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed\nas arguments to that function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn case of normal termination,\n<a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus the error object.\nIn this case, the coroutine does not unwind its stack,\nso that it is possible to inspect it after the error\nwith the debug API.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nthe function created by <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a>\npropagates any error to the caller.\nIn this case,\nthe function also closes the coroutine (see <a href=\"#pdf-coroutine.close\"><code>coroutine.close</code></a>).\n\n\n<p>\nAs an example of how coroutines work,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n     \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n<p>\nYou can also create and manipulate coroutines through the C API:\nsee functions <a href=\"#lua_newthread\"><code>lua_newthread</code></a>, <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nand <a href=\"#lua_yield\"><code>lua_yield</code></a>.\n\n\n\n\n\n<h1>3 &ndash; <a name=\"3\">The Language</a></h1>\n\n\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nLanguage constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like &lsquo;<b>=</b>&rsquo;.\nThe complete syntax of Lua can be found in <a href=\"#9\">&sect;9</a>\nat the end of this manual.\n\n\n\n\n\n<h2>3.1 &ndash; <a name=\"3.1\">Lexical Conventions</a></h2>\n\n<p>\nLua is a free-form language.\nIt ignores spaces and comments between lexical elements (tokens),\nexcept as delimiters between two tokens.\nIn source code,\nLua recognizes as spaces the standard ASCII whitespace\ncharacters space, form feed, newline,\ncarriage return, horizontal tab, and vertical tab.\n\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of Latin letters,\nArabic-Indic digits, and underscores,\nnot beginning with a digit and\nnot being a reserved word.\nIdentifiers are used to name variables, table fields, and labels.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif    end\n     false     for       function  goto      if        in\n     local     nil       not       or        repeat    return\n     then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention,\nprograms should avoid creating\nnames that start with an underscore followed by\none or more uppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>).\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     &amp;     ~     |     &lt;&lt;    &gt;&gt;    //\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]     ::\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\nA <em>short literal string</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nA backslash followed by a line break\nresults in a newline in the string.\nThe escape sequence '<code>\\z</code>' skips the following span\nof whitespace characters,\nincluding line breaks;\nit is particularly useful to break and indent a long literal string\ninto multiple lines without adding the newlines and spaces\ninto the string contents.\nA short literal string cannot contain unescaped line breaks\nnor escapes not forming a valid escape sequence.\n\n\n<p>\nWe can specify any byte in a short literal string,\nincluding embedded zeros,\nby its numeric value.\nThis can be done\nwith the escape sequence <code>\\x<em>XX</em></code>,\nwhere <em>XX</em> is a sequence of exactly two hexadecimal digits,\nor with the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a decimal escape sequence is to be followed by a digit,\nit must be expressed using exactly three digits.)\n\n\n<p>\nThe UTF-8 encoding of a Unicode character\ncan be inserted in a literal string with\nthe escape sequence <code>\\u{<em>XXX</em>}</code>\n(with mandatory enclosing braces),\nwhere <em>XXX</em> is a sequence of one or more hexadecimal digits\nrepresenting the character code point.\nThis code point can be any value less than <em>2<sup>31</sup></em>.\n(Lua uses the original UTF-8 specification here,\nwhich is not restricted to valid Unicode code points.)\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>, \nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>, \nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance,\na closing long bracket of level&nbsp;4 is written as  <code>]====]</code>.\nA <em>long literal</em> starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nIt can contain any text except a closing bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nAny kind of end-of-line sequence\n(carriage return, newline, carriage return followed by newline,\nor newline followed by carriage return)\nis converted to a simple newline.\nWhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\n\n\n<p>\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nAny byte in a literal string not\nexplicitly affected by the previous rules represents itself.\nHowever, Lua opens files for parsing in text mode,\nand the system's file functions may have problems with\nsome control characters.\nSo, it is safer to represent\nbinary data as a quoted literal with\nexplicit escape sequences for the non-text characters.\n\n\n<p>\nA <em>numeric constant</em> (or <em>numeral</em>)\ncan be written with an optional fractional part\nand an optional decimal exponent,\nmarked by a letter '<code>e</code>' or '<code>E</code>'.\nLua also accepts hexadecimal constants,\nwhich start with <code>0x</code> or <code>0X</code>.\nHexadecimal constants also accept an optional fractional part\nplus an optional binary exponent,\nmarked by a letter '<code>p</code>' or '<code>P</code>'.\n\n\n<p>\nA numeric constant with a radix point or an exponent\ndenotes a float;\notherwise,\nif its value fits in an integer or it is a hexadecimal constant,\nit denotes an integer;\notherwise (that is, a decimal integer numeral that overflows),\nit denotes a float.\nHexadecimal numerals with neither a radix point nor an exponent\nalways denote an integer value;\nif the value overflows, it <em>wraps around</em>\nto fit into a valid integer.\n\n\n<p>\nExamples of valid integer constants are\n\n<pre>\n     3   345   0xff   0xBEBADA\n</pre><p>\nExamples of valid float constants are\n\n<pre>\n     3.0     3.1416     314.16e-2     0.31416E1     34e1\n     0x0.1E  0xA23p-4   0X1.921FB54442D18P+1\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\n\n\n\n\n\n<h2>3.2 &ndash; <a name=\"3.2\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers (see <a href=\"#3.1\">&sect;3.1</a>).\n\n\n<p>\nAny variable name is assumed to be global unless explicitly declared\nas a local (see <a href=\"#3.3.7\">&sect;3.3.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;\n</pre><p>\nThe meaning of accesses to table fields can be changed via metatables\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp &lsquo;<b>.</b>&rsquo; Name\n</pre>\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_ENV.x</code>.\nDue to the way that chunks are compiled,\nthe variable <code>_ENV</code> itself is never global (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n\n\n\n<h2>3.3 &ndash; <a name=\"3.3\">Statements</a></h2>\n\n\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in other conventional languages.\nThis set includes\nblocks, assignments, control structures, function calls,\nand variable declarations.\n\n\n\n\n\n<h3>3.3.1 &ndash; <a name=\"3.3.1\">Blocks</a></h3>\n\n<p>\nA block is a list of statements,\nwhich are executed sequentially:\n\n<pre>\n\tblock ::= {stat}\n</pre><p>\nLua has <em>empty statements</em>\nthat allow you to separate statements with semicolons,\nstart a block with a semicolon\nor write two semicolons in sequence:\n\n<pre>\n\tstat ::= &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nBoth function calls and assignments\ncan start with an open parenthesis.\nThis possibility leads to an ambiguity in Lua's grammar.\nConsider the following fragment:\n\n<pre>\n     a = b + c\n     (print or io.write)('done')\n</pre><p>\nThe grammar could see this fragment in two ways:\n\n<pre>\n     a = b + c(print or io.write)('done')\n     \n     a = b + c; (print or io.write)('done')\n</pre><p>\nThe current parser always sees such constructions\nin the first way,\ninterpreting the open parenthesis\nas the start of the arguments to a call.\nTo avoid this ambiguity,\nit is a good practice to always precede with a semicolon\nstatements that start with a parenthesis:\n\n<pre>\n     ;(print or io.write)('done')\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> statement in the middle\nof another block (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\n\n\n\n\n\n<h3>3.3.2 &ndash; <a name=\"3.3.2\">Chunks</a></h3>\n\n<p>\nThe unit of compilation of Lua is called a <em>chunk</em>.\nSyntactically,\na chunk is simply a block:\n\n<pre>\n\tchunk ::= block\n</pre>\n\n<p>\nLua handles a chunk as the body of an anonymous function\nwith a variable number of arguments\n(see <a href=\"#3.4.11\">&sect;3.4.11</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\nMoreover, such anonymous function is compiled as in the\nscope of an external local variable called <code>_ENV</code> (see <a href=\"#2.2\">&sect;2.2</a>).\nThe resulting function always has <code>_ENV</code> as its only external variable,\neven if it does not use that variable.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first <em>loads</em> it,\nprecompiling the chunk's code into instructions for a virtual machine,\nand then Lua executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be precompiled into binary form;\nsee the program <code>luac</code> and the function <a href=\"#pdf-string.dump\"><code>string.dump</code></a> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly (see <a href=\"#pdf-load\"><code>load</code></a>).\n\n\n\n\n\n<h3>3.3.3 &ndash; <a name=\"3.3.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist &lsquo;<b>=</b>&rsquo; explist\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#3.4\">&sect;3.4</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with <b>nil</b>'s.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then the assignments are performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nAn assignment to a global name <code>x = val</code>\nis equivalent to the assignment\n<code>_ENV.x = val</code> (see <a href=\"#2.2\">&sect;2.2</a>).\n\n\n<p>\nThe meaning of assignments to table fields and\nglobal variables (which are actually table fields, too)\ncan be changed via metatables (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.3.4 &ndash; <a name=\"3.3.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#3.3.5\">&sect;3.3.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> test false.\nAll values different from <b>nil</b> and <b>false</b> test true.\nIn particular, the number 0 and the empty string also test true.\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>goto</b> statement transfers the program control to a label.\nFor syntactical reasons,\nlabels in Lua are considered statements too:\n\n\n\n<pre>\n\tstat ::= <b>goto</b> Name\n\tstat ::= label\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n</pre>\n\n<p>\nA label is visible in the entire block where it is defined,\nexcept inside nested functions.\nA goto may jump to any visible label as long as it does not\nenter into the scope of a local variable.\nA label should not be declared\nwhere a label with the same name is visible,\neven if this other label has been declared in an enclosing block.\n\n\n<p>\nLabels and empty statements are called <em>void statements</em>,\nas they perform no actions.\n\n\n<p>\nThe <b>break</b> statement terminates the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk\n(which is handled as an anonymous function).\n\nFunctions can return more than one value,\nso the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n</pre>\n\n<p>\nThe <b>return</b> statement can only be written\nas the last statement of a block.\nIf it is necessary to <b>return</b> in the middle of a block,\nthen an explicit inner block can be used,\nas in the idiom <code>do return end</code>,\nbecause now <b>return</b> is the last statement in its (inner) block.\n\n\n\n\n\n<h3>3.3.5 &ndash; <a name=\"3.3.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numerical and one generic.\n\n\n\n<h4>The numerical <b>for</b> loop</h4>\n\n<p>\nThe numerical <b>for</b> loop repeats a block of code while a\ncontrol variable goes through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe given identifier (Name) defines the control variable,\nwhich is a new variable local to the loop body (<em>block</em>).\n\n\n<p>\nThe loop starts by evaluating once the three control expressions.\nTheir values are called respectively\nthe <em>initial value</em>, the <em>limit</em>, and the <em>step</em>.\nIf the step is absent, it defaults to&nbsp;1.\n\n\n<p>\nIf both the initial value and the step are integers,\nthe loop is done with integers;\nnote that the limit may not be an integer.\nOtherwise, the three values are converted to\nfloats and the loop is done with floats.\nBeware of floating-point accuracy in this case.\n\n\n<p>\nAfter that initialization,\nthe loop body is repeated with the value of the control variable\ngoing through an arithmetic progression,\nstarting at the initial value,\nwith a common difference given by the step.\nA negative step makes a decreasing sequence;\na step equal to zero raises an error.\nThe loop continues while the value is less than\nor equal to the limit\n(greater than or equal to for a negative step).\nIf the initial value is already greater than the limit\n(or less than, if the step is negative),\nthe body is not executed.\n\n\n<p>\nFor integer loops,\nthe control variable never wraps around;\ninstead, the loop ends in case of an overflow.\n\n\n<p>\nYou should not change the value of the control variable\nduring the loop.\nIf you need its value after the loop,\nassign it to another variable before exiting the loop.\n\n\n\n\n\n<h4>The generic <b>for</b> loop</h4>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>body</em> end\n</pre><p>\nworks as follows.\n\n\n<p>\nThe names <em>var_i</em> declare loop variables local to the loop body.\nThe first of these variables is the <em>control variable</em>.\n\n\n<p>\nThe loop starts by evaluating <em>explist</em>\nto produce four values:\nan <em>iterator function</em>,\na <em>state</em>,\nan initial value for the control variable,\nand a <em>closing value</em>.\n\n\n<p>\nThen, at each iteration,\nLua calls the iterator function with two arguments:\nthe state and the control variable.\nThe results from this call are then assigned to the loop variables,\nfollowing the rules of multiple assignments (see <a href=\"#3.3.3\">&sect;3.3.3</a>).\nIf the control variable becomes <b>nil</b>,\nthe loop terminates.\nOtherwise, the body is executed and the loop goes\nto the next iteration.\n\n\n<p>\nThe closing value behaves like a\nto-be-closed variable (see <a href=\"#3.3.8\">&sect;3.3.8</a>),\nwhich can be used to release resources when the loop ends.\nOtherwise, it does not interfere with the loop.\n\n\n<p>\nYou should not change the value of the control variable\nduring the loop.\n\n\n\n\n\n\n\n<h3>3.3.6 &ndash; <a name=\"3.3.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>.\n\n\n\n\n\n<h3>3.3.7 &ndash; <a name=\"3.3.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initialization:\n\n<pre>\n\tstat ::= <b>local</b> attnamelist [&lsquo;<b>=</b>&rsquo; explist]\n\tattnamelist ::=  Name attrib {&lsquo;<b>,</b>&rsquo; Name attrib}\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#3.3.3\">&sect;3.3.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nEach variable name may be postfixed by an attribute\n(a name between angle brackets):\n\n<pre>\n\tattrib ::= [&lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo;]\n</pre><p>\nThere are two possible attributes:\n<code>const</code>, which declares a constant variable,\nthat is, a variable that cannot be assigned to\nafter its initialization;\nand <code>close</code>, which declares a to-be-closed variable (see <a href=\"#3.3.8\">&sect;3.3.8</a>).\nA list of variables can contain at most one to-be-closed variable.\n\n\n<p>\nA chunk is also a block (see <a href=\"#3.3.2\">&sect;3.3.2</a>),\nand so local variables can be declared in a chunk outside any explicit block.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#3.5\">&sect;3.5</a>.\n\n\n\n\n\n<h3>3.3.8 &ndash; <a name=\"3.3.8\">To-be-closed Variables</a></h3>\n\n<p>\nA to-be-closed variable behaves like a constant local variable,\nexcept that its value is <em>closed</em> whenever the variable\ngoes out of scope, including normal block termination,\nexiting its block by <b>break</b>/<b>goto</b>/<b>return</b>,\nor exiting by an error.\n\n\n<p>\nHere, to <em>close</em> a value means\nto call its <code>__close</code> metamethod.\nWhen calling the metamethod,\nthe value itself is passed as the first argument\nand the error object that caused the exit (if any)\nis passed as a second argument;\nif there was no error, the second argument is <b>nil</b>.\n\n\n<p>\nThe value assigned to a to-be-closed variable\nmust have a <code>__close</code> metamethod\nor be a false value.\n(<b>nil</b> and <b>false</b> are ignored as to-be-closed values.)\n\n\n<p>\nIf several to-be-closed variables go out of scope at the same event,\nthey are closed in the reverse order that they were declared.\n\n\n<p>\nIf there is any error while running a closing method,\nthat error is handled like an error in the regular code\nwhere the variable was defined.\nHowever, Lua may call the method one more time.\n\n\n<p>\nAfter an error,\nthe other pending closing methods will still be called.\nErrors in these methods\ninterrupt the respective method and generate a warning,\nbut are otherwise ignored;\nthe error reported is only the original one.\n\n\n<p>\nIf a coroutine yields and is never resumed again,\nsome variables may never go out of scope,\nand therefore they will never be closed.\n(These variables are the ones created inside the coroutine\nand in scope at the point where the coroutine yielded.)\nSimilarly, if a coroutine ends with an error,\nit does not unwind its stack,\nso it does not close any variable.\nIn both cases,\nyou can either use finalizers\nor call <a href=\"#pdf-coroutine.close\"><code>coroutine.close</code></a> to close the variables.\nHowever, if the coroutine was created\nthrough <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a>,\nthen its corresponding function will close the coroutine\nin case of errors.\n\n\n\n\n\n\n\n<h2>3.4 &ndash; <a name=\"3.4\">Expressions</a></h2>\n\n\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Numeral\n\texp ::= LiteralString\n\texp ::= functiondef\n\texp ::= tableconstructor\n\texp ::= &lsquo;<b>...</b>&rsquo;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n</pre>\n\n<p>\nNumerals and literal strings are explained in <a href=\"#3.1\">&sect;3.1</a>;\nvariables are explained in <a href=\"#3.2\">&sect;3.2</a>;\nfunction definitions are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>;\nfunction calls are explained in <a href=\"#3.4.10\">&sect;3.4.10</a>;\ntable constructors are explained in <a href=\"#3.4.9\">&sect;3.4.9</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#3.4.11\">&sect;3.4.11</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nbitwise operators (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nrelational operators (see <a href=\"#3.4.4\">&sect;3.4.4</a>), logical operators (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the concatenation operator (see <a href=\"#3.4.6\">&sect;3.4.6</a>).\nUnary operators comprise the unary minus (see <a href=\"#3.4.1\">&sect;3.4.1</a>),\nthe unary bitwise NOT (see <a href=\"#3.4.2\">&sect;3.4.2</a>),\nthe unary logical <b>not</b> (see <a href=\"#3.4.5\">&sect;3.4.5</a>),\nand the unary <em>length operator</em> (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf a function call is used as a statement (see <a href=\"#3.3.6\">&sect;3.3.6</a>),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the expression is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\neither discarding all values except the first one\nor adding a single <b>nil</b> if there are no values.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg argument, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg argument)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg arguments\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg arguments\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n\n\n<h3>3.4.1 &ndash; <a name=\"3.4.1\">Arithmetic Operators</a></h3><p>\nLua supports the following arithmetic operators:\n\n<ul>\n<li><b><code>+</code>: </b>addition</li>\n<li><b><code>-</code>: </b>subtraction</li>\n<li><b><code>*</code>: </b>multiplication</li>\n<li><b><code>/</code>: </b>float division</li>\n<li><b><code>//</code>: </b>floor division</li>\n<li><b><code>%</code>: </b>modulo</li>\n<li><b><code>^</code>: </b>exponentiation</li>\n<li><b><code>-</code>: </b>unary minus</li>\n</ul>\n\n<p>\nWith the exception of exponentiation and float division,\nthe arithmetic operators work as follows:\nIf both operands are integers,\nthe operation is performed over integers and the result is an integer.\nOtherwise, if both operands are numbers,\nthen they are converted to floats,\nthe operation is performed following the machine's rules\nfor floating-point arithmetic\n(usually the IEEE 754 standard),\nand the result is a float.\n(The string library coerces strings to numbers in\narithmetic operations; see <a href=\"#3.4.3\">&sect;3.4.3</a> for details.)\n\n\n<p>\nExponentiation and float division (<code>/</code>)\nalways convert their operands to floats\nand the result is always a float.\nExponentiation uses the ISO&nbsp;C function <code>pow</code>,\nso that it works for non-integer exponents too.\n\n\n<p>\nFloor division (<code>//</code>) is a division\nthat rounds the quotient towards minus infinity,\nresulting in the floor of the division of its operands.\n\n\n<p>\nModulo is defined as the remainder of a division\nthat rounds the quotient towards minus infinity (floor division).\n\n\n<p>\nIn case of overflows in integer arithmetic,\nall operations <em>wrap around</em>.\n\n\n\n<h3>3.4.2 &ndash; <a name=\"3.4.2\">Bitwise Operators</a></h3><p>\nLua supports the following bitwise operators:\n\n<ul>\n<li><b><code>&amp;</code>: </b>bitwise AND</li>\n<li><b><code>&#124;</code>: </b>bitwise OR</li>\n<li><b><code>~</code>: </b>bitwise exclusive OR</li>\n<li><b><code>&gt;&gt;</code>: </b>right shift</li>\n<li><b><code>&lt;&lt;</code>: </b>left shift</li>\n<li><b><code>~</code>: </b>unary bitwise NOT</li>\n</ul>\n\n<p>\nAll bitwise operations convert its operands to integers\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>),\noperate on all bits of those integers,\nand result in an integer.\n\n\n<p>\nBoth right and left shifts fill the vacant bits with zeros.\nNegative displacements shift to the other direction;\ndisplacements with absolute values equal to or higher than\nthe number of bits in an integer\nresult in zero (as all bits are shifted out).\n\n\n\n\n\n<h3>3.4.3 &ndash; <a name=\"3.4.3\">Coercions and Conversions</a></h3><p>\nLua provides some automatic conversions between some\ntypes and representations at run time.\nBitwise operators always convert float operands to integers.\nExponentiation and float division\nalways convert integer operands to floats.\nAll other arithmetic operations applied to mixed numbers\n(integers and floats) convert the integer operand to a float.\nThe C API also converts both integers to floats and\nfloats to integers, as needed.\nMoreover, string concatenation accepts numbers as arguments,\nbesides strings.\n\n\n<p>\nIn a conversion from integer to float,\nif the integer value has an exact representation as a float,\nthat is the result.\nOtherwise,\nthe conversion gets the nearest higher or\nthe nearest lower representable value.\nThis kind of conversion never fails.\n\n\n<p>\nThe conversion from float to integer\nchecks whether the float has an exact representation as an integer\n(that is, the float has an integral value and\nit is in the range of integer representation).\nIf it does, that representation is the result.\nOtherwise, the conversion fails.\n\n\n<p>\nSeveral places in Lua coerce strings to numbers when necessary.\nIn particular,\nthe string library sets metamethods that try to coerce\nstrings to numbers in all arithmetic operations.\nIf the conversion fails,\nthe library calls the metamethod of the other operand\n(if present) or it raises an error.\nNote that bitwise operators do not do this coercion.\n\n\n<p>\nNonetheless, it is always a good practice not to rely on these\nimplicit coercions, as they are not always applied;\nin particular, <code>\"1\"==1</code> is false and <code>\"1\"&lt;1</code> raises an error\n(see <a href=\"#3.4.4\">&sect;3.4.4</a>).\nThese coercions exist mainly for compatibility and may be removed\nin future versions of the language.\n\n\n<p>\nA string is converted to an integer or a float\nfollowing its syntax and the rules of the Lua lexer.\nThe string may have also leading and trailing whitespaces and a sign.\nAll conversions from strings to numbers\naccept both a dot and the current locale mark\nas the radix character.\n(The Lua lexer, however, accepts only a dot.)\nIf the string is not a valid numeral,\nthe conversion fails.\nIf necessary, the result of this first step is then converted\nto a specific number subtype following the previous rules\nfor conversions between floats and integers.\n\n\n<p>\nThe conversion from numbers to strings uses a\nnon-specified human-readable format.\nTo convert numbers to strings in any specific way,\nuse the function <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n\n\n\n<h3>3.4.4 &ndash; <a name=\"3.4.4\">Relational Operators</a></h3><p>\nLua supports the following relational operators:\n\n<ul>\n<li><b><code>==</code>: </b>equality</li>\n<li><b><code>~=</code>: </b>inequality</li>\n<li><b><code>&lt;</code>: </b>less than</li>\n<li><b><code>&gt;</code>: </b>greater than</li>\n<li><b><code>&lt;=</code>: </b>less or equal</li>\n<li><b><code>&gt;=</code>: </b>greater or equal</li>\n</ul><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nStrings are equal if they have the same byte content.\nNumbers are equal if they denote the same mathematical value.\n\n\n<p>\nTables, userdata, and threads\nare compared by reference:\ntwo objects are considered equal only if they are the same object.\nEvery time you create a new object\n(a table, a userdata, or a thread),\nthis new object is different from any previously existing object.\nA function is always equal to itself.\nFunctions with any detectable difference\n(different behavior, different definition) are always different.\nFunctions created at different times but with no detectable differences\nmay be classified as equal or not\n(depending on internal caching details).\n\n\n<p>\nYou can change the way that Lua compares tables and userdata\nby using the <code>__eq</code> metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nEquality comparisons do not convert strings to numbers\nor vice versa.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers,\nthen they are compared according to their mathematical values,\nregardless of their subtypes.\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the <code>__lt</code> or the <code>__le</code>\nmetamethod (see <a href=\"#2.4\">&sect;2.4</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n<p>\nFollowing the IEEE 754 standard,\nthe special value NaN is considered neither less than,\nnor equal to, nor greater than any value, including itself.\n\n\n\n\n\n<h3>3.4.5 &ndash; <a name=\"3.4.5\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#3.3.4\">&sect;3.3.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-circuit evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre>\n\n\n\n\n<h3>3.4.6 &ndash; <a name=\"3.4.6\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers,\nthen the numbers are converted to strings\nin a non-specified format (see <a href=\"#3.4.3\">&sect;3.4.3</a>).\nOtherwise, the <code>__concat</code> metamethod is called (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.7 &ndash; <a name=\"3.4.7\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary prefix operator <code>#</code>.\n\n\n<p>\nThe length of a string is its number of bytes.\n(That is the usual meaning of string length when each\ncharacter is one byte.)\n\n\n<p>\nThe length operator applied on a table\nreturns a border in that table.\nA <em>border</em> in a table <code>t</code> is any natural number\nthat satisfies the following condition:\n\n<pre>\n     (border == 0 or t[border] ~= nil) and t[border + 1] == nil\n</pre><p>\nIn words,\na border is any (natural) index present in the table\nthat is followed by an absent index\n(or zero, when index 1 is absent).\n\n\n<p>\nA table with exactly one border is called a <em>sequence</em>.\nFor instance, the table <code>{10, 20, 30, 40, 50}</code> is a sequence,\nas it has only one border (5).\nThe table <code>{10, 20, 30, nil, 50}</code> has two borders (3 and 5),\nand therefore it is not a sequence.\n(The <b>nil</b> at index 4 is called a <em>hole</em>.)\nThe table <code>{nil, 20, 30, nil, nil, 60, nil}</code>\nhas three borders (0, 3, and 6) and three holes\n(at indices 1, 4, and 5),\nso it is not a sequence, too.\nThe table <code>{}</code> is a sequence with border 0.\nNote that non-natural keys do not interfere\nwith whether a table is a sequence.\n\n\n<p>\nWhen <code>t</code> is a sequence,\n<code>#t</code> returns its only border,\nwhich corresponds to the intuitive notion of the length of the sequence.\nWhen <code>t</code> is not a sequence,\n<code>#t</code> can return any of its borders.\n(The exact one depends on details of\nthe internal representation of the table,\nwhich in turn can depend on how the table was populated and\nthe memory addresses of its non-numeric keys.)\n\n\n<p>\nThe computation of the length of a table\nhas a guaranteed worst time of <em>O(log n)</em>,\nwhere <em>n</em> is the largest natural key in the table.\n\n\n<p>\nA program can modify the behavior of the length operator for\nany value but strings through the <code>__len</code> metamethod (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<h3>3.4.8 &ndash; <a name=\"3.4.8\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     |\n     ~\n     &amp;\n     &lt;&lt;    &gt;&gt;\n     ..\n     +     -\n     *     /     //    %\n     unary operators (not   #     -     ~)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>3.4.9 &ndash; <a name=\"3.4.9\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive integers\nstarting with 1;\nfields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nThe order of the assignments in a constructor is undefined.\n(This order would be relevant only when there are repeated keys.)\n\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#3.4.10\">&sect;3.4.10</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>3.4.10 &ndash; <a name=\"3.4.10\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, if present,\nthe prefixexp <code>__call</code> metamethod is called:\nits first argument is the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp &lsquo;<b>:</b>&rsquo; Name args\n</pre><p>\ncan be used to emulate methods.\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo;\n\targs ::= tableconstructor\n\targs ::= LiteralString\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nA call of the form <code>return <em>functioncall</em></code> not in the\nscope of a to-be-closed variable is called a <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument,\nand it is outside the scope of any to-be-closed variable.\nThis syntax makes the calling function return exactly\nthe returns of the called function,\nwithout any intervening action.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)      -- result multiplied by 2\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>3.4.11 &ndash; <a name=\"3.4.11\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunctiondef ::= <b>function</b> funcbody\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\nnot to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua precompiles a chunk,\nall its function bodies are precompiled too,\nbut they are not created yet.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance, or <em>closure</em>,\nis the final value of the expression.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n</pre><p>\nWhen a Lua function is called,\nit adjusts its list of arguments to\nthe length of its list of parameters,\nunless the function is a <em>vararg function</em>,\nwhich is indicated by three dots ('<code>...</code>')\nat the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL             PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#3.3.4\">&sect;3.3.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\n\nThere is a system-dependent limit on the number of values\nthat a function may return.\nThis limit is guaranteed to be greater than 1000.\n\n\n<p>\nThe <em>colon</em> syntax\nis used to emulate <em>methods</em>,\nadding an implicit extra parameter <code>self</code> to the function.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>3.5 &ndash; <a name=\"3.5\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of a local variable begins at the first statement after\nits declaration and lasts until the last non-void statement\nof the innermost block that includes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called an <em>upvalue</em>\n(or <em>external local variable</em>, or simply <em>external variable</em>)\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i = 1, 10 do\n       local y = 0\n       a[i] = function () y = y + 1; return x + y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h1>4 &ndash; <a name=\"4\">The Application Program Interface</a></h1>\n\n\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nExcept where stated otherwise,\nall such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments\nfor validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith the macro <a name=\"pdf-LUA_USE_APICHECK\"><code>LUA_USE_APICHECK</code></a> defined.\n\n\n<p>\nThe Lua library is fully reentrant:\nit has no global variables.\nIt keeps all information it needs in a dynamic structure,\ncalled the <em>Lua state</em>.\n\n\n<p>\nEach Lua state has one or more threads,\nwhich correspond to independent, cooperative lines of execution.\nThe type <a href=\"#lua_State\"><code>lua_State</code></a> (despite its name) refers to a thread.\n(Indirectly, through the thread, it also refers to the\nLua state associated to the thread.)\n\n\n<p>\nA pointer to a thread must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch and returns a pointer\nto the <em>main thread</em> in the new state.\n\n\n\n\n\n<h2>4.1 &ndash; <a name=\"4.1\">The Stack</a></h2>\n\n\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\nFunctions in the API can access this stack through the\nLua state parameter that they receive.\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function can store temporary\nLua values and must push its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an absolute stack position,\nstarting at&nbsp;1 as the bottom of the stack;\na negative index represents an offset relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\n\n\n\n\n\n<h3>4.1.1 &ndash; <a name=\"4.1.1\">Stack Size</a></h3>\n\n<p>\nWhen you interact with the Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto ensure that the stack has enough space for pushing new elements.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that the stack has space for\nat least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> extra elements;\nthat is, you can safely push up to <code>LUA_MINSTACK</code> values into it.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nWhen you call a Lua function\nwithout a fixed number of results (see <a href=\"#lua_call\"><code>lua_call</code></a>),\nLua ensures that the stack has enough space for all results,\nbut it does not ensure any extra space.\nSo, before pushing anything on the stack after such a call\nyou should use <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\n\n\n\n\n\n<h3>4.1.2 &ndash; <a name=\"4.1.2\">Valid and Acceptable Indices</a></h3>\n\n<p>\nAny function in the API that receives stack indices\nworks only with <em>valid indices</em> or <em>acceptable indices</em>.\n\n\n<p>\nA <em>valid index</em> is an index that refers to a\nposition that stores a modifiable Lua value.\nIt comprises stack indices between&nbsp;1 and the stack top\n(<code>1 &le; abs(index) &le; top</code>)\n\nplus <em>pseudo-indices</em>,\nwhich represent some positions that are accessible to C&nbsp;code\nbut that are not in the stack.\nPseudo-indices are used to access the registry (see <a href=\"#4.3\">&sect;4.3</a>)\nand the upvalues of a C&nbsp;function (see <a href=\"#4.2\">&sect;4.2</a>).\n\n\n<p>\nFunctions that do not need a specific mutable position,\nbut only a value (e.g., query functions),\ncan be called with acceptable indices.\nAn <em>acceptable index</em> can be any valid index,\nbut it also can be any positive index after the stack top\nwithin the space allocated for the stack,\nthat is, indices up to the stack size.\n(Note that 0 is never an acceptable index.)\nIndices to upvalues (see <a href=\"#4.2\">&sect;4.2</a>) greater than the real number\nof upvalues in the current C&nbsp;function are also acceptable (but invalid).\nExcept when noted otherwise,\nfunctions in the API work with acceptable indices.\n\n\n<p>\nAcceptable indices serve to avoid extra tests\nagainst the stack top when querying the stack.\nFor instance, a C&nbsp;function can query its third argument\nwithout the need to check whether there is a third argument,\nthat is, without the need to check whether 3 is a valid index.\n\n\n<p>\nFor functions that can be called with acceptable indices,\nany non-valid index is treated as if it\ncontains a value of a virtual type <a name=\"pdf-LUA_TNONE\"><code>LUA_TNONE</code></a>,\nwhich behaves like a nil value.\n\n\n\n\n\n<h3>4.1.3 &ndash; <a name=\"4.1.3\">Pointers to strings</a></h3>\n\n<p>\nSeveral functions in the API return pointers (<code>const char*</code>)\nto Lua strings in the stack.\n(See <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, <a href=\"#lua_pushlstring\"><code>lua_pushlstring</code></a>,\n<a href=\"#lua_pushstring\"><code>lua_pushstring</code></a>, and <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a>.\nSee also <a href=\"#luaL_checklstring\"><code>luaL_checklstring</code></a>, <a href=\"#luaL_checkstring\"><code>luaL_checkstring</code></a>,\nand <a href=\"#luaL_tolstring\"><code>luaL_tolstring</code></a> in the auxiliary library.)\n\n\n<p>\nIn general,\nLua's garbage collection can free or move internal memory\nand then invalidate pointers to internal strings.\nTo allow a safe use of these pointers,\nThe API guarantees that any pointer to a string in a stack index\nis valid while the value at that index is neither modified nor popped.\nWhen the index is a pseudo-index (referring to an upvalue),\nthe pointer is valid while the corresponding call is active and\nthe corresponding upvalue is not modified.\n\n\n<p>\nSome functions in the debug interface\nalso return pointers to strings,\nnamely <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>, <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>,\n<a href=\"#lua_setlocal\"><code>lua_setlocal</code></a>, and <a href=\"#lua_setupvalue\"><code>lua_setupvalue</code></a>.\nFor these functions, the pointer is guaranteed to\nbe valid while the caller function is active and\nthe given closure (if one was given) is in the stack.\n\n\n<p>\nExcept for these guarantees,\nthe garbage collector is free to invalidate\nany pointer to internal strings.\n\n\n\n\n\n\n\n<h2>4.2 &ndash; <a name=\"4.2\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>);\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called.\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a href=\"#lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first upvalue associated with a function is at index\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function\n(but not greater than 256,\nwhich is one plus the maximum number of upvalues in a closure),\nproduces an acceptable but invalid index.\n\n\n<p>\nA C&nbsp;closure can also change the values\nof its corresponding upvalues.\n\n\n\n\n\n<h2>4.3 &ndash; <a name=\"4.3\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na predefined table that can be used by any C&nbsp;code to\nstore whatever Lua values it needs to store.\nThe registry table is always accessible at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it must take care to choose keys\nthat are different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name,\nor a light userdata with the address of a C&nbsp;object in your code,\nor any Lua object created by your code.\nAs with variable names,\nstring keys starting with an underscore followed by\nuppercase letters are reserved for Lua.\n\n\n<p>\nThe integer keys in the registry are used\nby the reference mechanism (see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>)\nand by some predefined values.\nTherefore, integer keys in the registry\nmust not be used for other purposes.\n\n\n<p>\nWhen you create a new Lua state,\nits registry comes with some predefined values.\nThese predefined values are indexed with integer keys\ndefined as constants in <code>lua.h</code>.\nThe following constants are defined:\n\n<ul>\n<li><b><a name=\"pdf-LUA_RIDX_MAINTHREAD\"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index the registry has\nthe main thread of the state.\n(The main thread is the one created together with the state.)\n</li>\n\n<li><b><a name=\"pdf-LUA_RIDX_GLOBALS\"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has\nthe global environment.\n</li>\n</ul>\n\n\n\n\n<h2>4.4 &ndash; <a name=\"4.4\">Error Handling in C</a></h2>\n\n\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(Lua will use exceptions if you compile it as C++;\nsearch for <code>LUAI_THROW</code> in the source code for details.)\nWhen Lua faces any error,\nsuch as a memory allocation error or a type error,\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recovery point;\nany error jumps to the most recent active recovery point.\n\n\n<p>\nInside a C&nbsp;function you can raise an error explicitly\nby calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n<p>\nMost functions in the API can raise an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can raise errors.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em> (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>)\nand then calls <code>abort</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning\n(e.g., doing a long jump to your own recovery point outside Lua).\n\n\n<p>\nThe panic function,\nas its name implies,\nis a mechanism of last resort.\nPrograms should avoid it.\nAs a general rule,\nwhen a C&nbsp;function is called by Lua with a Lua state,\nit can do whatever it wants on that Lua state,\nas it should be already protected.\nHowever,\nwhen C code operates on other Lua states\n(e.g., a Lua-state argument to the function,\na Lua state stored in the registry, or\nthe result of <a href=\"#lua_newthread\"><code>lua_newthread</code></a>),\nit should use them only in API calls that cannot raise errors.\n\n\n<p>\nThe panic function runs as if it were a message handler (see <a href=\"#2.3\">&sect;2.3</a>);\nin particular, the error object is on the top of the stack.\nHowever, there is no guarantee about stack space.\nTo push anything on the stack,\nthe panic function must first check the available space (see <a href=\"#4.1.1\">&sect;4.1.1</a>).\n\n\n\n\n\n<h3>4.4.1 &ndash; <a name=\"4.4.1\">Status Codes</a></h3>\n\n<p>\nSeveral functions that report errors in the API use the following\nstatus codes to indicate different kinds of errors or other conditions:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OK\"><code>LUA_OK</code></a> (0): </b> no errors.</li>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>: </b> a runtime error.</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>: </b>\nmemory allocation error.\nFor such errors, Lua does not call the message handler.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>: </b> error while running the message handler.</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>: </b> syntax error during precompilation.</li>\n\n<li><b><a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a>: </b> the thread (coroutine) yields.</li>\n\n<li><b><a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>: </b> a file-related error;\ne.g., it cannot open or read the file.</li>\n\n</ul><p>\nThese constants are defined in the header file <code>lua.h</code>.\n\n\n\n\n\n\n\n<h2>4.5 &ndash; <a name=\"4.5\">Handling Yields in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.\nTherefore, if a C&nbsp;function <code>foo</code> calls an API function\nand this API function yields\n(directly or indirectly by calling another function that yields),\nLua cannot return to <code>foo</code> any more,\nbecause the <code>longjmp</code> removes its frame from the C stack.\n\n\n<p>\nTo avoid this kind of problem,\nLua raises an error whenever it tries to yield across an API call,\nexcept for three functions:\n<a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, <a href=\"#lua_callk\"><code>lua_callk</code></a>, and <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\nAll those functions receive a <em>continuation function</em>\n(as a parameter named <code>k</code>) to continue execution after a yield.\n\n\n<p>\nWe need to set some terminology to explain continuations.\nWe have a C&nbsp;function called from Lua which we will call\nthe <em>original function</em>.\nThis original function then calls one of those three functions in the C API,\nwhich we will call the <em>callee function</em>,\nthat then yields the current thread.\nThis can happen when the callee function is <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nor when the callee function is either <a href=\"#lua_callk\"><code>lua_callk</code></a> or <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>\nand the function called by them yields.\n\n\n<p>\nSuppose the running thread yields while executing the callee function.\nAfter the thread resumes,\nit eventually will finish running the callee function.\nHowever,\nthe callee function cannot return to the original function,\nbecause its frame in the C stack was destroyed by the yield.\nInstead, Lua calls a <em>continuation function</em>,\nwhich was given as an argument to the callee function.\nAs the name implies,\nthe continuation function should continue the task\nof the original function.\n\n\n<p>\nAs an illustration, consider the following function:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       status = lua_pcall(L, n, m, h);  /* calls Lua */\n       ...     /* code 2 */\n     }\n</pre><p>\nNow we want to allow\nthe Lua code being run by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> to yield.\nFirst, we can rewrite our function like here:\n\n<pre>\n     int k (lua_State *L, int status, lua_KContext ctx) {\n       ...  /* code 2 */\n     }\n     \n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcall(L, n, m, h), ctx);\n     }\n</pre><p>\nIn the above code,\nthe new function <code>k</code> is a\n<em>continuation function</em> (with type <a href=\"#lua_KFunction\"><code>lua_KFunction</code></a>),\nwhich should do all the work that the original function\nwas doing after calling <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\nNow, we must inform Lua that it must call <code>k</code> if the Lua code\nbeing executed by <a href=\"#lua_pcall\"><code>lua_pcall</code></a> gets interrupted in some way\n(errors or yielding),\nso we rewrite the code as here,\nreplacing <a href=\"#lua_pcall\"><code>lua_pcall</code></a> by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>:\n\n<pre>\n     int original_function (lua_State *L) {\n       ...     /* code 1 */\n       return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);\n     }\n</pre><p>\nNote the external, explicit call to the continuation:\nLua will call the continuation only if needed, that is,\nin case of errors or resuming after a yield.\nIf the called function returns normally without ever yielding,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a> (and <a href=\"#lua_callk\"><code>lua_callk</code></a>) will also return normally.\n(Of course, instead of calling the continuation in that case,\nyou can do the equivalent work directly inside the original function.)\n\n\n<p>\nBesides the Lua state,\nthe continuation function has two other parameters:\nthe final status of the call and the context value (<code>ctx</code>) that\nwas passed originally to <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>.\nLua does not use this context value;\nit only passes this value from the original function to the\ncontinuation function.\nFor <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nthe status is the same value that would be returned by <a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>,\nexcept that it is <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when being executed after a yield\n(instead of <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>).\nFor <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> and <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nthe status is always <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> when Lua calls the continuation.\n(For these two functions,\nLua will not call the continuation in case of errors,\nbecause they do not handle errors.)\nSimilarly, when using <a href=\"#lua_callk\"><code>lua_callk</code></a>,\nyou should call the continuation function\nwith <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> as the status.\n(For <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>, there is not much point in calling\ndirectly the continuation function,\nbecause <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a> usually does not return.)\n\n\n<p>\nLua treats the continuation function as if it were the original function.\nThe continuation function receives the same Lua stack\nfrom the original function,\nin the same state it would be if the callee function had returned.\n(For instance,\nafter a <a href=\"#lua_callk\"><code>lua_callk</code></a> the function and its arguments are\nremoved from the stack and replaced by the results from the call.)\nIt also has the same upvalues.\nWhatever it returns is handled by Lua as if it were the return\nof the original function.\n\n\n\n\n\n<h2>4.6 &ndash; <a name=\"4.6\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments.\n(For instance, they may depend on what is in the stack.)\nThe third field, <code>x</code>,\ntells whether the function may raise errors:\n'<code>-</code>' means the function never raises any error;\n'<code>m</code>' means the function may raise only out-of-memory errors;\n'<code>v</code>' means the function may raise the errors explained in the text;\n'<code>e</code>' means the function can run arbitrary Lua code,\neither directly or through metamethods,\nand therefore may raise any errors.\n\n\n\n<hr><h3><a name=\"lua_absindex\"><code>lua_absindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_absindex (lua_State *L, int idx);</pre>\n\n<p>\nConverts the acceptable index <code>idx</code>\ninto an equivalent absolute index\n(that is, one that does not depend on the stack top).\n\n\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block or some code about what\nis being allocated;\nand <code>nsize</code>, the new size of the block.\n\n\n<p>\nWhen <code>ptr</code> is not <code>NULL</code>,\n<code>osize</code> is the size of the block pointed by <code>ptr</code>,\nthat is, the size given when it was allocated or reallocated.\n\n\n<p>\nWhen <code>ptr</code> is <code>NULL</code>,\n<code>osize</code> encodes the kind of object that Lua is allocating.\n<code>osize</code> is any of\n<a href=\"#pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>, <a href=\"#pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>, <a href=\"#pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a href=\"#pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>, or <a href=\"#pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a> when (and only when)\nLua is creating a new object of that type.\nWhen <code>osize</code> is some other value,\nLua is allocating memory for something else.\n\n\n<p>\nLua assumes the following behavior from the allocator function:\n\n\n<p>\nWhen <code>nsize</code> is zero,\nthe allocator must behave like <code>free</code>\nand then return <code>NULL</code>.\n\n\n<p>\nWhen <code>nsize</code> is not zero,\nthe allocator must behave like <code>realloc</code>.\nIn particular, the allocator returns <code>NULL</code>\nif and only if it cannot fulfill the request.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nNote that Standard&nbsp;C ensures\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_arith\"><code>lua_arith</code></a></h3><p>\n<span class=\"apii\">[-(2|1), +1, <em>e</em>]</span>\n<pre>void lua_arith (lua_State *L, int op);</pre>\n\n<p>\nPerforms an arithmetic or bitwise operation over the two values\n(or one, in the case of negations)\nat the top of the stack,\nwith the value on the top being the second operand,\npops these values, and pushes the result of the operation.\nThe function follows the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPADD\"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSUB\"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMUL\"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li>\n<li><b><a name=\"pdf-LUA_OPDIV\"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</code>)</li>\n<li><b><a name=\"pdf-LUA_OPIDIV\"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//</code>)</li>\n<li><b><a name=\"pdf-LUA_OPMOD\"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li>\n<li><b><a name=\"pdf-LUA_OPPOW\"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li>\n<li><b><a name=\"pdf-LUA_OPUNM\"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBNOT\"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBAND\"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&amp;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBOR\"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>)</li>\n<li><b><a name=\"pdf-LUA_OPBXOR\"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<code>~</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHL\"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code>&lt;&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPSHR\"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>&gt;&gt;</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one (see <a href=\"#4.4\">&sect;4.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs+1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\nLike regular Lua calls,\n<code>lua_call</code> respects the <code>__call</code> metamethod.\nSo, here the word \"function\"\nmeans any callable value.\n\n\n<p>\nTo do a call you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the call are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nWhen the function returns,\nall arguments and the function value are popped\nand the call results are pushed onto the stack.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, all results from the function are pushed;\nLua takes care that the returned values fit into the stack space,\nbut it does not ensure any extra space in the stack.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error while calling and running the function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getglobal(L, \"f\");                  /* function to be called */\n     lua_pushliteral(L, \"how\");                       /* 1st argument */\n     lua_getglobal(L, \"t\");                    /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setglobal(L, \"a\");                         /* set global 'a' */\n</pre><p>\nNote that the code above is <em>balanced</em>:\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_callk\"><code>lua_callk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_callk (lua_State *L,\n                int nargs,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>,\nbut allows the called function to yield (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns in C the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numeric arguments and returns their average and their sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0.0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushliteral(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_checkstack (lua_State *L, int n);</pre>\n\n<p>\nEnsures that the stack has space for at least <code>n</code> extra elements,\nthat is, that you can safely push up to <code>n</code> values into it.\nIt returns false if it cannot fulfill the request,\neither because it would cause the stack\nto be greater than a fixed maximum size\n(typically at least several thousand elements) or\nbecause it cannot allocate memory for the extra space.\nThis function never shrinks the stack;\nif the stack already has space for the extra elements,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nClose all active to-be-closed variables in the main thread,\nrelease all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any),\nand frees all dynamic memory used by this state.\n\n\n<p>\nOn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs that create multiple states,\nsuch as daemons or web servers,\nwill probably need to close states as soon as they are not needed.\n\n\n\n\n\n<hr><h3><a name=\"lua_compare\"><code>lua_compare</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre>\n\n<p>\nCompares two Lua values.\nReturns 1 if the value at index <code>index1</code> satisfies <code>op</code>\nwhen compared with the value at index <code>index2</code>,\nfollowing the semantics of the corresponding Lua operator\n(that is, it may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is not valid.\n\n\n<p>\nThe value of <code>op</code> must be one of the following constants:\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_OPEQ\"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLT\"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</code>)</li>\n<li><b><a name=\"pdf-LUA_OPLE\"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt;=</code>)</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result on the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#3.4.6\">&sect;3.4.6</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_copy\"><code>lua_copy</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre>\n\n<p>\nCopies the element at index <code>fromidx</code>\ninto the valid index <code>toidx</code>,\nreplacing the value at that position.\nValues at other positions are not affected.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nParameter <code>narr</code> is a hint for how many elements the table\nwill have as a sequence;\nparameter <code>nrec</code> is a hint for how many other elements\nthe table will have.\nLua may use these hints to preallocate memory for the new table.\nThis preallocation may help performance when you know in advance\nhow many elements the table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_dump (lua_State *L,\n                        lua_Writer writer,\n                        void *data,\n                        int strip);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nIf <code>strip</code> is true,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nRaises a Lua error,\nusing the value on the top of the stack as the error object.\nThis function does a long jump,\nand therefore never returns\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gc (lua_State *L, int what, ...);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>.\nFor options that need extra arguments,\nthey are listed after the option.\n\n<ul>\n\n<li><b><code>LUA_GCCOLLECT</code>: </b>\nPerforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCSTOP</code>: </b>\nStops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>: </b>\nRestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>: </b>\nReturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>: </b>\nReturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code> <code>(int stepsize)</code>: </b>\nPerforms an incremental step of garbage collection,\ncorresponding to the allocation of <code>stepsize</code> Kbytes.\n</li>\n\n<li><b><code>LUA_GCISRUNNING</code>: </b>\nReturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n<li><b><code>LUA_GCINC</code> (int pause, int stepmul, stepsize): </b>\nChanges the collector to incremental mode\nwith the given parameters (see <a href=\"#2.5.1\">&sect;2.5.1</a>).\nReturns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).\n</li>\n\n<li><b><code>LUA_GCGEN</code> (int minormul, int majormul): </b>\nChanges the collector to generational mode\nwith the given parameters (see <a href=\"#2.5.2\">&sect;2.5.2</a>).\nReturns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).\n</li>\n\n</ul><p>\nFor more details about these options,\nsee <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer given when the memory-allocator function was set.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getextraspace\"><code>lua_getextraspace</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_getextraspace (lua_State *L);</pre>\n\n<p>\nReturns a pointer to a raw memory area associated with the\ngiven Lua state.\nThe application can use this area for any purpose;\nLua does not use it for anything.\n\n\n<p>\nEach new thread has this area initialized with a copy\nof the area of the main thread.\n\n\n<p>\nBy default, this area has the size of a pointer to void,\nbut you can recompile Lua with a different size for this area.\n(See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nReturns the type of that value.\n\n\n\n\n\n<hr><h3><a name=\"lua_geti\"><code>lua_geti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int lua_geti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nPushes onto the stack the value <code>t[i]</code>,\nwhere <code>t</code> is the value at the given index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index has a metatable,\nthe function pushes that metatable onto the stack and returns&nbsp;1.\nOtherwise,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>int lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given index\nand <code>k</code> is the value on the top of the stack.\n\n\n<p>\nThis function pops the key from the stack,\npushing the resulting value in its place.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack;\nin particular, 0&nbsp;means an empty stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_getiuservalue\"><code>lua_getiuservalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_getiuservalue (lua_State *L, int index, int n);</pre>\n\n<p>\nPushes onto the stack the <code>n</code>-th user value associated with the\nfull userdata at the given index and\nreturns the type of the pushed value.\n\n\n<p>\nIf the userdata does not have that value,\npushes <b>nil</b> and returns <a href=\"#pdf-LUA_TNONE\"><code>LUA_TNONE</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ... lua_Integer;</pre>\n\n<p>\nThe type of integers in Lua.\n\n\n<p>\nBy default this type is <code>long long</code>,\n(usually a 64-bit two-complement integer),\nbut that can be changed to <code>long</code> or <code>int</code>\n(usually a 32-bit two-complement integer).\n(See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n<p>\nLua also defines the constants\n<a name=\"pdf-LUA_MININTEGER\"><code>LUA_MININTEGER</code></a> and <a name=\"pdf-LUA_MAXINTEGER\"><code>LUA_MAXINTEGER</code></a>,\nwith the minimum and the maximum values that fit in this type.\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isinteger\"><code>lua_isinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isinteger (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is an integer\n(that is, the value is a number and is represented as an integer),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given index is not valid\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isyieldable\"><code>lua_isyieldable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_isyieldable (lua_State *L);</pre>\n\n<p>\nReturns 1 if the given coroutine can yield,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_KContext\"><code>lua_KContext</code></a></h3>\n<pre>typedef ... lua_KContext;</pre>\n\n<p>\nThe type for continuation-function contexts.\nIt must be a numeric type.\nThis type is defined as <code>intptr_t</code>\nwhen <code>intptr_t</code> is available,\nso that it can store pointers too.\nOtherwise, it is defined as <code>ptrdiff_t</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_KFunction\"><code>lua_KFunction</code></a></h3>\n<pre>typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);</pre>\n\n<p>\nType for continuation functions (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_len\"><code>lua_len</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the length of the value at the given index.\nIt is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>) and\nmay trigger a metamethod for the \"length\" event (see <a href=\"#2.4\">&sect;2.4</a>).\nThe result is pushed on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname,\n              const char *mode);</pre>\n\n<p>\nLoads a Lua chunk without running it.\nIf there are no errors,\n<code>lua_load</code> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\n\n\n<p>\nThe <code>lua_load</code> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#4.7\">&sect;4.7</a>).\n\n\n<p>\n<code>lua_load</code> automatically detects whether the chunk is text or binary\nand loads it accordingly (see program <code>luac</code>).\nThe string <code>mode</code> works as in function <a href=\"#pdf-load\"><code>load</code></a>,\nwith the addition that\na <code>NULL</code> value is equivalent to the string \"<code>bt</code>\".\n\n\n<p>\n<code>lua_load</code> uses the stack internally,\nso the reader function must always leave the stack\nunmodified when returning.\n\n\n<p>\n<code>lua_load</code> can return\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>, <a href=\"#pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>, or <a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>.\nThe function may also return other values corresponding to\nerrors raised by the read function (see <a href=\"#4.4.1\">&sect;4.4.1</a>).\n\n\n<p>\nIf the resulting function has upvalues,\nits first upvalue is set to the value of the global environment\nstored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href=\"#4.3\">&sect;4.3</a>).\nWhen loading main chunks,\nthis upvalue will be the <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nOther upvalues are initialized with <b>nil</b>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new independent state and returns its main thread.\nReturns <code>NULL</code> if it cannot create the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua will do all memory allocation for this state\nthrough this function (see <a href=\"#lua_Alloc\"><code>lua_Alloc</code></a>).\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\npasses to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new thread returned by this function shares with the original thread\nits global environment,\nbut has an independent execution stack.\n\n\n<p>\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdatauv\"><code>lua_newuserdatauv</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue);</pre>\n\n<p>\nThis function creates and pushes on the stack a new full userdata,\nwith <code>nuvalue</code> associated Lua values, called <code>user values</code>,\nplus an associated block of raw memory with <code>size</code> bytes.\n(The user values can be set and read with the functions\n<a href=\"#lua_setiuservalue\"><code>lua_setiuservalue</code></a> and <a href=\"#lua_getiuservalue\"><code>lua_getiuservalue</code></a>.)\n\n\n<p>\nThe function returns the address of the block of memory.\nLua ensures that this address is valid as long as\nthe corresponding userdata is alive (see <a href=\"#2.5\">&sect;2.5</a>).\nMoreover, if the userdata is marked for finalization (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nits address is valid at least until the call to its finalizer.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>v</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key&ndash;value pair from the table at the given index,\nthe \"next\" pair after the given key.\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 and pushes nothing.\n\n\n<p>\nA typical table traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\navoid calling <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> may change\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n<p>\nThis function may raise an error if the given key\nis neither <b>nil</b> nor present in the table.\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef ... lua_Number;</pre>\n\n<p>\nThe type of floats in Lua.\n\n\n<p>\nBy default this type is double,\nbut that can be changed to a single float or a long double.\n(See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)\n\n\n\n\n\n<hr><h3><a name=\"lua_numbertointeger\"><code>lua_numbertointeger</code></a></h3>\n<pre>int lua_numbertointeger (lua_Number n, lua_Integer *p);</pre>\n\n<p>\nTries to convert a Lua float to a Lua integer;\nthe float <code>n</code> must have an integral value.\nIf that value is within the range of Lua integers,\nit is converted to an integer and assigned to <code>*p</code>.\nThe macro results in a boolean indicating whether the\nconversion was successful.\n(Note that this range test can be tricky to do\ncorrectly without this macro, due to rounding.)\n\n\n<p>\nThis macro may evaluate its arguments more than once.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre>\n\n<p>\nCalls a function (or a callable object) in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error object),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>msgh</code> is 0,\nthen the error object returned on the stack\nis exactly the original error object.\nOtherwise, <code>msgh</code> is the stack index of a\n<em>message handler</em>.\n(This index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis handler will be called with the error object\nand its return value will be the object\nreturned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the message handler is used to add more debug\ninformation to the error object, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns one of the following status codes:\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>, <a href=\"#pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>, <a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>, or <a href=\"#pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcallk\"><code>lua_pcallk</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), &ndash;]</span>\n<pre>int lua_pcallk (lua_State *L,\n                int nargs,\n                int nresults,\n                int msgh,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nThis function behaves exactly like <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nexcept that it allows the called function to yield (see <a href=\"#4.5\">&sect;4.5</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, &ndash;]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\nThis function receives a pointer to a C&nbsp;function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\nThe parameter <code>n</code> tells how many upvalues this function will have\n(see <a href=\"#4.2\">&sect;4.2</a>).\n\n\n<p>\nAny function to be callable by Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthe so called upvalues;\nthese upvalues are then accessible to the function whenever it is called.\nThis association is called a C&nbsp;closure (see <a href=\"#4.2\">&sect;4.2</a>).\nTo create a C&nbsp;closure,\nfirst the initial values for its upvalues must be pushed onto the stack.\n(When there are multiple upvalues, the first value is pushed first.)\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values will be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n<p>\nWhen <code>n</code> is zero,\nthis function creates a <em>light C&nbsp;function</em>,\nwhich is just a pointer to the C&nbsp;function.\nIn that case, it never raises a memory error.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function is equivalent to <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> with no upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>v</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string (see <a href=\"#4.1.3\">&sect;4.1.3</a>).\nIt is similar to the ISO&nbsp;C function <code>sprintf</code>,\nbut has two important differences.\nFirst,\nyou do not have to allocate space for the result;\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\nSecond,\nthe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts the character '<code>%</code>'),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%I</code>' (inserts a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>),\n'<code>%p</code>' (inserts a pointer),\n'<code>%d</code>' (inserts an <code>int</code>),\n'<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and\n'<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).\n\n\n<p>\nThis function may raise errors due to memory overflow\nor an invalid conversion specifier.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushglobaltable\"><code>lua_pushglobaltable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushglobaltable (lua_State *L);</pre>\n\n<p>\nPushes the global environment onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes an integer with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer, a <code>void*</code>.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushstring\"><code>lua_pushstring</code></a>,\nbut should be used only when <code>s</code> is a literal string.\n(Lua may optimize this case.)\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua will make or reuse an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain any binary data,\nincluding embedded zeros.\n\n\n<p>\nReturns a pointer to the internal copy of the string (see <a href=\"#4.1.3\">&sect;4.1.3</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a float with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua will make or reuse an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\n\n\n<p>\nReturns a pointer to the internal copy of the string (see <a href=\"#4.1.3\">&sect;4.1.3</a>).\n\n\n<p>\nIf <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>v</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, equal without calling the <code>__eq</code> metamethod).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are not valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, &ndash;]</span>\n<pre>int lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgeti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the table at the given index.\nThe access is raw,\nthat is, it does not use the <code>__index</code> metavalue.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgetp\"><code>lua_rawgetp</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int lua_rawgetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the table at the given index and\n<code>k</code> is the pointer <code>p</code> represented as a light userdata.\nThe access is raw;\nthat is, it does not use the <code>__index</code> metavalue.\n\n\n<p>\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawlen\"><code>lua_rawlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Unsigned lua_rawlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the raw \"length\" of the value at the given index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>')\nwith no metamethods;\nfor userdata, this is the size of the block of memory allocated\nfor the userdata.\nFor other values, this call returns&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, lua_Integer i);</pre>\n\n<p>\nDoes the equivalent of <code>t[i] = v</code>,\nwhere <code>t</code> is the table at the given index\nand <code>v</code> is the value on the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not use the <code>__newindex</code> metavalue.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawsetp\"><code>lua_rawsetp</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre>\n\n<p>\nDoes the equivalent of <code>t[p] = v</code>,\nwhere <code>t</code> is the table at the given index,\n<code>p</code> is encoded as a light userdata,\nand <code>v</code> is the value on the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw,\nthat is, it does not use the <code>__newindex</code> metavalue.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time <a href=\"#lua_load\"><code>lua_load</code></a> needs another piece of the chunk,\nit calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre>\n\n<p>\nSets the C&nbsp;function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index\nwithout shifting any element\n(therefore replacing the value at that given index),\nand then pops the top element.\n\n\n\n\n\n<hr><h3><a name=\"lua_resetthread\"><code>lua_resetthread</code></a></h3><p>\n<span class=\"apii\">[-0, +?, &ndash;]</span>\n<pre>int lua_resetthread (lua_State *L);</pre>\n\n<p>\nResets a thread, cleaning its call stack and closing all pending\nto-be-closed variables.\nReturns a status code:\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> for no errors in closing methods,\nor an error status otherwise.\nIn case of error,\nleaves the error object on the top of the stack,\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>int lua_resume (lua_State *L, lua_State *from, int nargs,\n                          int *nresults);</pre>\n\n<p>\nStarts and resumes a coroutine in the given thread <code>L</code>.\n\n\n<p>\nTo start a coroutine,\nyou push the main function plus any arguments\nonto the empty stack of the thread.\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>nargs</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns,\n<code>*nresults</code> is updated and\nthe top of the stack contains\nthe <code>*nresults</code> values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>\nor returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n<a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#4.4.1\">&sect;4.4.1</a>).\nIn case of errors,\nthe error object is on the top of the stack.\n\n\n<p>\nTo resume a coroutine,\nyou remove the <code>*nresults</code> yielded values from its stack,\npush the values to be passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nThe parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.\nIf there is no such coroutine,\nthis parameter can be <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_rotate\"><code>lua_rotate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_rotate (lua_State *L, int idx, int n);</pre>\n\n<p>\nRotates the stack elements between the valid index <code>idx</code>\nand the top of the stack.\nThe elements are rotated <code>n</code> positions in the direction of the top,\nfor a positive <code>n</code>,\nor <code>-n</code> positions in the direction of the bottom,\nfor a negative <code>n</code>.\nThe absolute value of <code>n</code> must not be greater than the size\nof the slice being rotated.\nThis function cannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value on the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_seti\"><code>lua_seti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_seti (lua_State *L, int index, lua_Integer n);</pre>\n\n<p>\nDoes the equivalent to <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given index\nand <code>v</code> is the value on the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setiuservalue\"><code>lua_setiuservalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>int lua_setiuservalue (lua_State *L, int index, int n);</pre>\n\n<p>\nPops a value from the stack and sets it as\nthe new <code>n</code>-th user value associated to the\nfull userdata at the given index.\nReturns 0 if the userdata does not have that value.\n\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, &ndash;]</span>\n<pre>int lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table or <b>nil</b> from the stack and\nsets that value as the new metatable for the value at the given index.\n(<b>nil</b> means no metatable.)\n\n\n<p>\n(For historical reasons, this function returns an <code>int</code>,\nwhich now is always 1.)\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given index,\n<code>v</code> is the value on the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.4\">&sect;2.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is greater than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_setwarnf\"><code>lua_setwarnf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud);</pre>\n\n<p>\nSets the warning function to be used by Lua to emit warnings\n(see <a href=\"#lua_WarnFunction\"><code>lua_WarnFunction</code></a>).\nThe <code>ud</code> parameter sets the value <code>ud</code> passed to\nthe warning function.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nAn opaque structure that points to a thread and indirectly\n(through the thread) to the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is accessible through this structure.\n\n\n<p>\nA pointer to this structure must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> for a normal thread,\nan error code if the thread finished the execution\nof a <a href=\"#lua_resume\"><code>lua_resume</code></a> with an error,\nor <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n<p>\nYou can call functions only in threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>.\nYou can resume threads with status <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a>\n(to start a new coroutine) or <a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a>\n(to resume a coroutine).\n\n\n\n\n\n<hr><h3><a name=\"lua_stringtonumber\"><code>lua_stringtonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>size_t lua_stringtonumber (lua_State *L, const char *s);</pre>\n\n<p>\nConverts the zero-terminated string <code>s</code> to a number,\npushes that number into the stack,\nand returns the total size of the string,\nthat is, its length plus one.\nThe conversion can result in an integer or a float,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\nThe string may have leading and trailing whitespaces and a sign.\nIf the string is not a valid numeral,\nreturns 0 and pushes nothing.\n(Note that the result can be used as a boolean,\ntrue if the conversion succeeds.)\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns true for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns false.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_toclose\"><code>lua_toclose</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void lua_toclose (lua_State *L, int index);</pre>\n\n<p>\nMarks the given index in the stack as a\nto-be-closed \"variable\" (see <a href=\"#3.3.8\">&sect;3.3.8</a>).\nLike a to-be-closed variable in Lua,\nthe value at that index in the stack will be closed\nwhen it goes out of scope.\nHere, in the context of a C function,\nto go out of scope means that the running function returns to Lua,\nthere is an error,\nor the index is removed from the stack through\n<a href=\"#lua_settop\"><code>lua_settop</code></a> or <a href=\"#lua_pop\"><code>lua_pop</code></a>.\nAn index marked as to-be-closed should not be removed from the stack\nby any other function in the API except <a href=\"#lua_settop\"><code>lua_settop</code></a> or <a href=\"#lua_pop\"><code>lua_pop</code></a>.\n\n\n<p>\nThis function should not be called for an index\nthat is equal to or below an active to-be-closed index.\n\n\n<p>\nIn the case of an out-of-memory error,\nthe value in the given index is immediately closed,\nas if it was already marked.\n\n\n<p>\nNote that, both in case of errors and of a regular return,\nby the time the <code>__close</code> metamethod runs,\nthe C&nbsp;stack was already unwound,\nso that any automatic C variable declared in the calling function\nwill be out of scope.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tointegerx\"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointegerx\"><code>lua_tointegerx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be an integer,\nor a number or string convertible to an integer (see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <code>lua_tointegerx</code> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <code>lua_tolstring</code> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <code>lua_tolstring</code> is applied to keys during a table traversal.)\n\n\n<p>\n<code>lua_tolstring</code> returns a pointer\nto a string inside the Lua state (see <a href=\"#4.1.3\">&sect;4.1.3</a>).\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumberx\"><code>lua_tonumberx</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre>\n\n<p>\nConverts the Lua value at the given index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#3.4.3\">&sect;3.4.3</a>);\notherwise, <a href=\"#lua_tonumberx\"><code>lua_tonumberx</code></a> returns&nbsp;0.\n\n\n<p>\nIf <code>isnum</code> is not <code>NULL</code>,\nits referent is assigned a boolean value that\nindicates whether the operation succeeded.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, a string, or a function;\notherwise, <code>lua_topointer</code> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for hashing and debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given index is a full userdata,\nreturns its memory-block address.\nIf the value is a light userdata,\nreturns its value (a pointer).\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given valid index,\nor <code>LUA_TNONE</code> for a non-valid but acceptable index.\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<a name=\"pdf-LUA_TNIL\"><code>LUA_TNIL</code></a>,\n<a name=\"pdf-LUA_TNUMBER\"><code>LUA_TNUMBER</code></a>,\n<a name=\"pdf-LUA_TBOOLEAN\"><code>LUA_TBOOLEAN</code></a>,\n<a name=\"pdf-LUA_TSTRING\"><code>LUA_TSTRING</code></a>,\n<a name=\"pdf-LUA_TTABLE\"><code>LUA_TTABLE</code></a>,\n<a name=\"pdf-LUA_TFUNCTION\"><code>LUA_TFUNCTION</code></a>,\n<a name=\"pdf-LUA_TUSERDATA\"><code>LUA_TUSERDATA</code></a>,\n<a name=\"pdf-LUA_TTHREAD\"><code>LUA_TTHREAD</code></a>,\nand\n<a name=\"pdf-LUA_TLIGHTUSERDATA\"><code>LUA_TLIGHTUSERDATA</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *lua_typename (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Unsigned\"><code>lua_Unsigned</code></a></h3>\n<pre>typedef ... lua_Unsigned;</pre>\n\n<p>\nThe unsigned version of <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_upvalueindex (int i);</pre>\n\n<p>\nReturns the pseudo-index that represents the <code>i</code>-th upvalue of\nthe running function (see <a href=\"#4.2\">&sect;4.2</a>).\n<code>i</code> must be in the range <em>[1,256]</em>.\n\n\n\n\n\n<hr><h3><a name=\"lua_version\"><code>lua_version</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Number lua_version (lua_State *L);</pre>\n\n<p>\nReturns the version number of this core.\n\n\n\n\n\n<hr><h3><a name=\"lua_WarnFunction\"><code>lua_WarnFunction</code></a></h3>\n<pre>typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);</pre>\n\n<p>\nThe type of warning functions, called by Lua to emit warnings.\nThe first parameter is an opaque pointer\nset by <a href=\"#lua_setwarnf\"><code>lua_setwarnf</code></a>.\nThe second parameter is the warning message.\nThe third parameter is a boolean that\nindicates whether the message is\nto be continued by the message in the next call.\n\n\n<p>\nSee <a href=\"#pdf-warn\"><code>warn</code></a> for more details about warnings.\n\n\n\n\n\n<hr><h3><a name=\"lua_warning\"><code>lua_warning</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_warning (lua_State *L, const char *msg, int tocont);</pre>\n\n<p>\nEmits a warning with the given message.\nA message in a call with <code>tocont</code> true should be\ncontinued in another call to this function.\n\n\n<p>\nSee <a href=\"#pdf-warn\"><code>warn</code></a> for more details about warnings.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time <a href=\"#lua_dump\"><code>lua_dump</code></a> produces another piece of chunk,\nit calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>ud</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the same state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>v</em>]</span>\n<pre>int lua_yield (lua_State *L, int nresults);</pre>\n\n<p>\nThis function is equivalent to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nbut it has no continuation (see <a href=\"#4.5\">&sect;4.5</a>).\nTherefore, when the thread resumes,\nit continues the function that called\nthe function calling <code>lua_yield</code>.\nTo avoid surprises,\nthis function should be called only in a tail call.\n\n\n\n\n\n<hr><h3><a name=\"lua_yieldk\"><code>lua_yieldk</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>v</em>]</span>\n<pre>int lua_yieldk (lua_State *L,\n                int nresults,\n                lua_KContext ctx,\n                lua_KFunction k);</pre>\n\n<p>\nYields a coroutine (thread).\n\n\n<p>\nWhen a C&nbsp;function calls <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat will be passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n<p>\nWhen the coroutine is resumed again,\nLua calls the given continuation function <code>k</code> to continue\nthe execution of the C&nbsp;function that yielded (see <a href=\"#4.5\">&sect;4.5</a>).\nThis continuation function receives the same stack\nfrom the previous function,\nwith the <code>n</code> results removed and\nreplaced by the arguments passed to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\nMoreover,\nthe continuation function receives the value <code>ctx</code>\nthat was passed to <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>.\n\n\n<p>\nUsually, this function does not return;\nwhen the coroutine eventually resumes,\nit continues executing the continuation function.\nHowever, there is one special case,\nwhich is when this function is called\nfrom inside a line or a count hook (see <a href=\"#4.7\">&sect;4.7</a>).\nIn that case, <code>lua_yieldk</code> should be called with no continuation\n(probably in the form of <a href=\"#lua_yield\"><code>lua_yield</code></a>) and no results,\nand the hook should return immediately after the call.\nLua will yield and,\nwhen the coroutine resumes again,\nit will continue the normal execution\nof the (Lua) function that triggered the hook.\n\n\n<p>\nThis function can raise an error if it is called from a thread\nwith a pending C call with no continuation function\n(what is called a <em>C-call boundary</em>),\nor it is called from a thread that is not running inside a resume\n(typically the main thread).\n\n\n\n\n\n\n\n<h2>4.7 &ndash; <a name=\"4.7\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  size_t srclen;              /* (S) */\n  int currentline;            /* (l) */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  unsigned char nups;         /* (u) number of upvalues */\n  unsigned char nparams;      /* (u) number of parameters */\n  char isvararg;              /* (u) */\n  char istailcall;            /* (t) */\n  unsigned short ftransfer;   /* (r) index of first value transferred */\n  unsigned short ntransfer;   /* (r) number of transferred values */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about a function or an activation record.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\nyou must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>: </b>\nthe source of the chunk that created the function.\nIf <code>source</code> starts with a '<code>@</code>',\nit means that the function was defined in a file where\nthe file name follows the '<code>@</code>'.\nIf <code>source</code> starts with a '<code>=</code>',\nthe remainder of its contents describes the source in a user-dependent manner.\nOtherwise,\nthe function was defined in a string where\n<code>source</code> is that string.\n</li>\n\n<li><b><code>srclen</code>: </b>\nThe length of the string <code>source</code>.\n</li>\n\n<li><b><code>short_src</code>: </b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>: </b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>: </b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>: </b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk.\n</li>\n\n<li><b><code>currentline</code>: </b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>: </b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>: </b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>istailcall</code>: </b>\ntrue if this function invocation was called by a tail call.\nIn this case, the caller of this level is not in the stack.\n</li>\n\n<li><b><code>nups</code>: </b>\nthe number of upvalues of the function.\n</li>\n\n<li><b><code>nparams</code>: </b>\nthe number of parameters of the function\n(always 0&nbsp;for C&nbsp;functions).\n</li>\n\n<li><b><code>isvararg</code>: </b>\ntrue if the function is a vararg function\n(always true for C&nbsp;functions).\n</li>\n\n<li><b><code>ftransfer</code>: </b>\nthe index in the stack of the first value being \"transferred\",\nthat is, parameters in a call or return values in a return.\n(The other values are in consecutive indices.)\nUsing this index, you can access and modify these values\nthrough <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> and <a href=\"#lua_setlocal\"><code>lua_setlocal</code></a>.\nThis field is only meaningful during a\ncall hook, denoting the first parameter,\nor a return hook, denoting the first value being returned.\n(For call hooks, this value is always 1.)\n</li>\n\n<li><b><code>ntransfer</code>: </b>\nThe number of values being transferred (see previous item).\n(For calls of Lua functions,\nthis value is always equal to <code>nparams</code>.)\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>m</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nGets information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function, you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function from the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getglobal(L, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>': </b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;\n</li>\n\n<li><b>'<code>u</code>': </b> fills in the fields\n<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;\n</li>\n\n<li><b>'<code>f</code>': </b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>': </b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n\n\n<p>\nIf this option is given together with option '<code>f</code>',\nits table is pushed after the function.\n\n\n<p>\nThis is the only option that can raise a memory error.\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 to signal an invalid option in <code>what</code>;\neven then the valid options are handled correctly.\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable or a temporary value\nof a given activation record or a given function.\n\n\n<p>\nIn the first case,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect;\nsee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for details about variable indices\nand names.\n\n\n<p>\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nIn the second case, <code>ar</code> must be <code>NULL</code> and the function\nto be inspected must be on the top of the stack.\nIn this case, only parameters of Lua functions are visible\n(as there is no information about what variables are active)\nand no values are pushed onto the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGets information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>\n(except for tail calls, which do not count in the stack).\nWhen called with a level greater than the stack depth,\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 0;\notherwise it returns 1.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), &ndash;]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about the <code>n</code>-th upvalue\nof the closure at index <code>funcindex</code>.\nIt pushes the upvalue's value onto the stack\nand returns its name.\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nSee <a href=\"#pdf-debug.getupvalue\"><code>debug.getupvalue</code></a> for more information about upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILCALL\"><code>LUA_HOOKTAILCALL</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nFor call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,\nthe normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;\nin this case, there will be no corresponding return event.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n<p>\nHook functions cannot have continuations,\nthat is, they cannot call <a href=\"#lua_yieldk\"><code>lua_yieldk</code></a>,\n<a href=\"#lua_pcallk\"><code>lua_pcallk</code></a>, or <a href=\"#lua_callk\"><code>lua_callk</code></a> with a non-null <code>k</code>.\n\n\n<p>\nHook functions can yield under the following conditions:\nOnly count and line events can yield;\nto yield, a hook function must finish its execution\ncalling <a href=\"#lua_yield\"><code>lua_yield</code></a> with <code>nresults</code> equal to zero\n(that is, with no values).\n\n\n\n\n\n<hr><h3><a name=\"lua_setcstacklimit\"><code>lua_setcstacklimit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>int (lua_setcstacklimit) (lua_State *L, unsigned int limit);</pre>\n\n<p>\nSets a new limit for the C stack.\nThis limit controls how deeply nested calls can go in Lua,\nwith the intent of avoiding a stack overflow.\nReturns the old limit in case of success,\nor zero in case of error.\nFor more details about this function,\nsee <a href=\"#pdf-debug.setcstacklimit\"><code>debug.setcstacklimit</code></a>,\nits equivalent in the standard library.\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise OR of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook: </b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function.\n</li>\n\n<li><b>The return hook: </b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\n</li>\n\n<li><b>The line hook: </b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\nThis event only happens while Lua is executing a Lua function.\n</li>\n\n<li><b>The count hook: </b> is called after the interpreter executes every\n<code>count</code> instructions.\nThis event only happens while Lua is executing a Lua function.\n</li>\n\n</ul>\n\n<p>\nHooks are disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nIt assigns the value on the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n<p>\nParameters <code>ar</code> and <code>n</code> are as in the function <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, &ndash;]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value on the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index <code>n</code> is greater than the number of upvalues.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in\nthe function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvalueid\"><code>lua_upvalueid</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nReturns a unique identifier for the upvalue numbered <code>n</code>\nfrom the closure at index <code>funcindex</code>.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n<p>\nParameters <code>funcindex</code> and <code>n</code> are as in\nthe function <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>,\nbut <code>n</code> cannot be greater than the number of upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_upvaluejoin\"><code>lua_upvaluejoin</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,\n                                    int funcindex2, int n2);</pre>\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.\n\n\n\n\n\n\n\n<h1>5 &ndash; <a name=\"5\">The Auxiliary Library</a></h1>\n\n\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all\ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions and types from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with that API.\nNevertheless, the use of the auxiliary library ensures\nmore consistency to your code.\n\n\n<p>\nSeveral functions in the auxiliary library use internally some\nextra stack slots.\nWhen a function in the auxiliary library uses less than five slots,\nit does not check the stack size;\nit simply assumes that there are enough slots.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n<p>\nFunctions called <code>luaL_check*</code>\nalways raise an error if the check is not satisfied.\n\n\n\n\n\n<h2>5.1 &ndash; <a name=\"5.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the byte <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addgsub\"><code>luaL_addgsub</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const void luaL_addgsub (luaL_Buffer *B, const char *s,\n                         const char *p, const char *r);</pre>\n\n<p>\nAdds a copy of the string <code>s</code> to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>),\nreplacing any occurrence of the string <code>p</code>\nwith the string <code>r</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, &ndash;]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code>\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +?, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value on the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int arg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf it is not, raises an error with a standard message (see <a href=\"#luaL_argerror\"><code>luaL_argerror</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int arg, const char *extramsg);</pre>\n\n<p>\nRaises an error reporting a problem with argument <code>arg</code>\nof the C&nbsp;function that called it,\nusing a standard message\nthat includes <code>extramsg</code> as a comment:\n\n<pre>\n     bad argument #<em>arg</em> to '<em>funcname</em>' (<em>extramsg</em>)\n</pre><p>\nThis function never returns.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argexpected\"><code>luaL_argexpected</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argexpected (lua_State *L,\n                       int cond,\n                       int arg,\n                       const char *tname);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf it is not, raises an error about the type of the argument <code>arg</code>\nwith a standard message (see <a href=\"#luaL_typeerror\"><code>luaL_typeerror</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nFinish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nIf you know beforehand the maximum size of the resulting string,\nyou can use the buffer like this:\n\n<ul>\n\n<li>First declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then initialize it and preallocate a space of\nsize <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>\n\n<li>Then produce the string into that space.</li>\n\n<li>\nFinish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,\nwhere <code>sz</code> is the total size of the resulting string\ncopied into that space (which may be less than or\nequal to the preallocated size).\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a>,\nthe stack is back to its level when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffaddr\"><code>luaL_buffaddr</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>char *luaL_buffaddr (luaL_Buffer *B);</pre>\n\n<p>\nReturns the address of the current content of buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nNote that any addition to the buffer may invalidate this address.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThis function does not allocate any space;\nthe buffer must be declared as a variable.\n\n\n\n\n\n<hr><h3><a name=\"luaL_bufflen\"><code>luaL_bufflen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>size_t luaL_bufflen (luaL_Buffer *B);</pre>\n\n<p>\nReturns the length of the current content of buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinitsize\"><code>luaL_buffinitsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence\n<a href=\"#luaL_buffinit\"><code>luaL_buffinit</code></a>, <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffsub\"><code>luaL_buffsub</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_buffsub (luaL_Buffer *B, int n);</pre>\n\n<p>\nRemoves <code>n</code> bytes from the the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe buffer must have at least that many bytes.\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field passing the object as its only argument.\nIn this case this function returns true and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns false without pushing any value on the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>arg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is an integer\n(or can be converted to an integer)\nand returns this integer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int arg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills its referent\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a number\nand returns this number converted to a <code>lua_Number</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int arg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>arg</code> or when this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message\n(or <code>NULL</code> for no additional text).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int arg);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int arg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>arg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>) and\nreturns the userdata's memory-block address (see <a href=\"#lua_touserdata\"><code>lua_touserdata</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkversion\"><code>luaL_checkversion</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkversion (lua_State *L);</pre>\n\n<p>\nChecks whether the code making the call and the Lua library being called\nare using the same version of Lua and the same numeric types.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>m</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if there are no errors,\nor an error code in case of errors (see <a href=\"#4.4.1\">&sect;4.4.1</a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, &ndash;]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns <a href=\"#pdf-LUA_OK\"><code>LUA_OK</code></a> if there are no errors,\nor an error code in case of errors (see <a href=\"#4.4.1\">&sect;4.4.1</a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_execresult\"><code>luaL_execresult</code></a></h3><p>\n<span class=\"apii\">[-0, +3, <em>m</em>]</span>\n<pre>int luaL_execresult (lua_State *L, int stat);</pre>\n\n<p>\nThis function produces the return values for\nprocess-related functions in the standard library\n(<a href=\"#pdf-os.execute\"><code>os.execute</code></a> and <a href=\"#pdf-io.close\"><code>io.close</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_fileresult\"><code>luaL_fileresult</code></a></h3><p>\n<span class=\"apii\">[-0, +(1|3), <em>m</em>]</span>\n<pre>int luaL_fileresult (lua_State *L, int stat, const char *fname);</pre>\n\n<p>\nThis function produces the return values for\nfile-related functions in the standard library\n(<a href=\"#pdf-io.open\"><code>io.open</code></a>, <a href=\"#pdf-os.rename\"><code>os.rename</code></a>, <a href=\"#pdf-file:seek\"><code>file:seek</code></a>, etc.).\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code> and returns the type of the pushed value.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\npushes nothing and returns <code>LUA_TNIL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with the name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>),\nor <b>nil</b> if there is no metatable associated with that name.\nReturns the type of the pushed value.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getsubtable\"><code>luaL_getsubtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>int luaL_getsubtable (lua_State *L, int idx, const char *fname);</pre>\n\n<p>\nEnsures that the value <code>t[fname]</code>,\nwhere <code>t</code> is the value at index <code>idx</code>,\nis a table,\nand pushes that table onto the stack.\nReturns true if it finds a previous table there\nand false if it creates a new table.\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code>,\nreplacing any occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_len\"><code>luaL_len</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>lua_Integer luaL_len (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given index\nas a number;\nit is equivalent to the '<code>#</code>' operator in Lua (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nRaises an error if the result of the operation is not an integer.\n(This case can only happen through metamethods.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadbufferx\"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbufferx\"><code>luaL_loadbufferx</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadbufferx (lua_State *L,\n                      const char *buff,\n                      size_t sz,\n                      const char *name,\n                      const char *mode);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\nThe string <code>mode</code> works as in the function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_loadfilex\"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfilex\"><code>luaL_loadfilex</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfilex (lua_State *L, const char *filename,\n                                            const char *mode);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThe string <code>mode</code> works as in the function <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>\nor <a href=\"#pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a> for file-related errors.\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlib\"><code>luaL_newlib</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlib (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table and registers there\nthe functions in the list <code>l</code>.\n\n\n<p>\nIt is implemented as the following macro:\n\n<pre>\n     (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n</pre><p>\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newlibtable\"><code>luaL_newlibtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);</pre>\n\n<p>\nCreates a new table with a size optimized\nto store all entries in the array <code>l</code>\n(but does not actually store them).\nIt is intended to be used in conjunction with <a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>\n(see <a href=\"#luaL_newlib\"><code>luaL_newlib</code></a>).\n\n\n<p>\nIt is implemented as a macro.\nThe array <code>l</code> must be the actual array,\nnot a pointer to it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds to this new table the pair <code>__name = tname</code>,\nadds to the registry the pair <code>[tname] = new table</code>,\nand returns 1.\n\n\n<p>\nIn both cases,\nthe function pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C allocation functions\nand then sets a warning function and a panic function (see <a href=\"#4.4\">&sect;4.4</a>)\nthat print messages to the standard error output.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_opt\"><code>luaL_opt</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>T luaL_opt (L, func, arg, dflt);</pre>\n\n<p>\nThis macro is defined as follows:\n\n<pre>\n     (lua_isnoneornil(L,(arg)) ? (dflt) : func(L,(arg)))\n</pre><p>\nIn words, if the argument <code>arg</code> is nil or absent,\nthe macro results in the default <code>dflt</code>.\nOtherwise, it results in the result of calling <code>func</code>\nwith the state <code>L</code> and the argument index <code>arg</code> as\narguments.\nNote that it evaluates the expression <code>dflt</code> only if needed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int arg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is an integer\n(or it is convertible to an integer),\nreturns this integer.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int arg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills its referent with the result's length.\nIf the result is <code>NULL</code>\n(only possible when returning <code>d</code> and <code>d == NULL</code>),\nits length is considered zero.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a number,\nreturns this number as a <code>lua_Number</code>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int arg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>arg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nEquivalent to <a href=\"#luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a>\nwith the predefined size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffsize\"><code>luaL_prepbuffsize</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>m</em>]</span>\n<pre>char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nReturns an address to a space of size <code>sz</code>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add\nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushfail\"><code>luaL_pushfail</code></a></h3><p>\n<span class=\"apii\">[-0, +1, &ndash;]</span>\n<pre>void luaL_pushfail (lua_State *L);</pre>\n\n<p>\nPushes the <b>fail</b> value onto the stack (see <a href=\"#6\">&sect;6</a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresultsize\"><code>luaL_pushresultsize</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresultsize (luaL_Buffer *B, size_t sz);</pre>\n\n<p>\nEquivalent to the sequence <a href=\"#luaL_addsize\"><code>luaL_addsize</code></a>, <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object on the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into the table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by the reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nThe function <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference.\n\n\n<p>\nIf the object on the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_setfuncs\"><code>luaL_setfuncs</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with a sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_requiref\"><code>luaL_requiref</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void luaL_requiref (lua_State *L, const char *modname,\n                    lua_CFunction openf, int glb);</pre>\n\n<p>\nIf <code>package.loaded[modname]</code> is not true,\ncalls the function <code>openf</code> with the string <code>modname</code> as an argument\nand sets the call result to <code>package.loaded[modname]</code>,\nas if that function has been called through <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n<p>\nIf <code>glb</code> is true,\nalso stores the module into the global <code>modname</code>.\n\n\n<p>\nLeaves a copy of the module on the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setfuncs\"><code>luaL_setfuncs</code></a></h3><p>\n<span class=\"apii\">[-nup, +0, <em>m</em>]</span>\n<pre>void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);</pre>\n\n<p>\nRegisters all functions in the array <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack\n(below optional upvalues, see next).\n\n\n<p>\nWhen <code>nup</code> is not zero,\nall functions are created with <code>nup</code> upvalues,\ninitialized with copies of the <code>nup</code> values\npreviously pushed on the stack\non top of the library table.\nThese values are popped from the stack after the registration.\n\n\n\n\n\n<hr><h3><a name=\"luaL_setmetatable\"><code>luaL_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nSets the metatable of the object on the top of the stack\nas the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_Stream\"><code>luaL_Stream</code></a></h3>\n<pre>typedef struct luaL_Stream {\n  FILE *f;\n  lua_CFunction closef;\n} luaL_Stream;</pre>\n\n<p>\nThe standard representation for file handles\nused by the standard I/O library.\n\n\n<p>\nA file handle is implemented as a full userdata,\nwith a metatable called <code>LUA_FILEHANDLE</code>\n(where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).\nThe metatable is created by the I/O library\n(see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n<p>\nThis userdata must start with the structure <code>luaL_Stream</code>;\nit can contain other data after this initial structure.\nThe field <code>f</code> points to the corresponding C stream\n(or it can be <code>NULL</code> to indicate an incompletely created handle).\nThe field <code>closef</code> points to a Lua function\nthat will be called to close the stream\nwhen the handle is closed or collected;\nthis function receives the file handle as its sole argument and\nmust return either a true value, in case of success,\nor a false value plus an error message, in case of error.\nOnce Lua calls this field,\nit changes the field value to <code>NULL</code>\nto signal that the handle is closed.\n\n\n\n\n\n<hr><h3><a name=\"luaL_testudata\"><code>luaL_testudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void *luaL_testudata (lua_State *L, int arg, const char *tname);</pre>\n\n<p>\nThis function works like <a href=\"#luaL_checkudata\"><code>luaL_checkudata</code></a>,\nexcept that, when the test fails,\nit returns <code>NULL</code> instead of raising an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_tolstring\"><code>luaL_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>const char *luaL_tolstring (lua_State *L, int idx, size_t *len);</pre>\n\n<p>\nConverts any Lua value at the given index to a C&nbsp;string\nin a reasonable format.\nThe resulting string is pushed onto the stack and also\nreturned by the function (see <a href=\"#4.1.3\">&sect;4.1.3</a>).\nIf <code>len</code> is not <code>NULL</code>,\nthe function also sets <code>*len</code> with the string length.\n\n\n<p>\nIf the value has a metatable with a <code>__tostring</code> field,\nthen <code>luaL_tolstring</code> calls the corresponding metamethod\nwith the value as argument,\nand uses the result of the call as its result.\n\n\n\n\n\n<hr><h3><a name=\"luaL_traceback\"><code>luaL_traceback</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n                     int level);</pre>\n\n<p>\nCreates and pushes a traceback of the stack <code>L1</code>.\nIf <code>msg</code> is not <code>NULL</code>, it is appended\nat the beginning of the traceback.\nThe <code>level</code> parameter tells at which level\nto start the traceback.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typeerror\"><code>luaL_typeerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_typeerror (lua_State *L,\n                                      int arg,\n                                      const char *tname);</pre>\n\n<p>\nRaises a type error for the argument <code>arg</code>\nof the C&nbsp;function that called it,\nusing a standard message;\n<code>tname</code> is a \"name\" for the expected type.\nThis function never returns.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, &ndash;]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases the reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>6 &ndash; <a name=\"6\">The Standard Libraries</a></h1>\n\n\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented in&nbsp;C through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to outside services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut that for different reasons\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nUnless otherwise noted,\nthese library functions do not adjust its number of arguments\nto its expected parameters.\nFor instance, a function documented as <code>foo(arg)</code>\nshould not be called without an argument.\n\n\n<p>\nThe notation <b>fail</b> means a false value representing\nsome kind of failure.\n(Currently, <b>fail</b> is equal to <b>nil</b>,\nbut that may change in future versions.\nThe recommendation is to always test the success of these functions\nwith <code>(not status)</code>, instead of <code>(status == nil)</code>.)\n\n\n<p>\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library (<a href=\"#6.1\">&sect;6.1</a>);</li>\n\n<li>coroutine library (<a href=\"#6.2\">&sect;6.2</a>);</li>\n\n<li>package library (<a href=\"#6.3\">&sect;6.3</a>);</li>\n\n<li>string manipulation (<a href=\"#6.4\">&sect;6.4</a>);</li>\n\n<li>basic UTF-8 support (<a href=\"#6.5\">&sect;6.5</a>);</li>\n\n<li>table manipulation (<a href=\"#6.6\">&sect;6.6</a>);</li>\n\n<li>mathematical functions (<a href=\"#6.7\">&sect;6.7</a>) (sin, log, etc.);</li>\n\n<li>input and output (<a href=\"#6.8\">&sect;6.8</a>);</li>\n\n<li>operating system facilities (<a href=\"#6.9\">&sect;6.9</a>);</li>\n\n<li>debug facilities (<a href=\"#6.10\">&sect;6.10</a>).</li>\n\n</ul><p>\nExcept for the basic and the package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nthe host program can open them individually by using\n<a href=\"#luaL_requiref\"><code>luaL_requiref</code></a> to call\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_coroutine\"><code>luaopen_coroutine</code></a> (for the coroutine library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_utf8\"><code>luaopen_utf8</code></a> (for the UTF-8 library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the operating system library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>.\n\n\n\n\n\n<h2>6.1 &ndash; <a name=\"6.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide\nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\n\n\n<p>\nRaises an error if\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\nIn case of error,\n<code>message</code> is the error object;\nwhen absent, it defaults to \"<code>assertion failed!</code>\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage ([opt [, arg]])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"<code>collect</code>\": </b>\nPerforms a full garbage-collection cycle.\nThis is the default option.\n</li>\n\n<li><b>\"<code>stop</code>\": </b>\nStops automatic execution of the garbage collector.\nThe collector will run only when explicitly invoked,\nuntil a call to restart it.\n</li>\n\n<li><b>\"<code>restart</code>\": </b>\nRestarts automatic execution of the garbage collector.\n</li>\n\n<li><b>\"<code>count</code>\": </b>\nReturns the total memory in use by Lua in Kbytes.\nThe value has a fractional part,\nso that it multiplied by 1024\ngives the exact number of bytes in use by Lua.\n</li>\n\n<li><b>\"<code>step</code>\": </b>\nPerforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>.\nWith a zero value,\nthe collector will perform one basic (indivisible) step.\nFor non-zero values,\nthe collector will perform as if that amount of memory\n(in Kbytes) had been allocated by Lua.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"<code>isrunning</code>\": </b>\nReturns a boolean that tells whether the collector is running\n(i.e., not stopped).\n</li>\n\n<li><b>\"<code>incremental</code>\": </b>\nChange the collector mode to incremental.\nThis option can be followed by three numbers:\nthe garbage-collector pause,\nthe step multiplier,\nand the step size (see <a href=\"#2.5.1\">&sect;2.5.1</a>).\nA zero means to not change that value.\n</li>\n\n<li><b>\"<code>generational</code>\": </b>\nChange the collector mode to generational.\nThis option can be followed by two numbers:\nthe garbage-collector minor multiplier\nand the major multiplier (see <a href=\"#2.5.2\">&sect;2.5.2</a>).\nA zero means to not change that value.\n</li>\n\n</ul><p>\nSee <a href=\"#2.5\">&sect;2.5</a> for more details about garbage collection\nand some of these options.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile ([filename])</code></a></h3>\nOpens the named file and executes its content as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the content of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller.\n(That is, <code>dofile</code> does not run in protected mode.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nRaises an error (see <a href=\"#2.3\">&sect;2.3</a>) with @{message} as the error object.\nThis function never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message, if the message is a string.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (see <a href=\"#2.2\">&sect;2.2</a>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice versa.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>__metatable</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values (an iterator function, the table <code>t</code>, and 0)\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the key&ndash;value pairs\n(<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,\nup to the first absent index.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>\n\n\n<p>\nLoads a chunk.\n\n\n<p>\nIf <code>chunk</code> is a string, the chunk is this string.\nIf <code>chunk</code> is a function,\n<code>load</code> calls it repeatedly to get the chunk pieces.\nEach call to <code>chunk</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no syntactic errors,\n<code>load</code> returns the compiled chunk as a function;\notherwise, it returns <b>fail</b> plus the error message.\n\n\n<p>\nWhen you load a main chunk,\nthe resulting function will always have exactly one upvalue,\nthe <code>_ENV</code> variable (see <a href=\"#2.2\">&sect;2.2</a>).\nHowever,\nwhen you load a binary chunk created from a function (see <a href=\"#pdf-string.dump\"><code>string.dump</code></a>),\nthe resulting function can have an arbitrary number of upvalues,\nand there is no guarantee that its first upvalue will be\nthe <code>_ENV</code> variable.\n(A non-main function may not even have an <code>_ENV</code> upvalue.)\n\n\n<p>\nRegardless, if the resulting function has any upvalues,\nits first upvalue is set to the value of <code>env</code>,\nif that parameter is given,\nor to the value of the global environment.\nOther upvalues are initialized with <b>nil</b>.\nAll upvalues are fresh, that is,\nthey are not shared with any other function.\n\n\n<p>\n<code>chunkname</code> is used as the name of the chunk for error messages\nand debug information (see <a href=\"#4.7\">&sect;4.7</a>).\nWhen absent,\nit defaults to <code>chunk</code>, if <code>chunk</code> is a string,\nor to \"<code>=(load)</code>\" otherwise.\n\n\n<p>\nThe string <code>mode</code> controls whether the chunk can be text or binary\n(that is, a precompiled chunk).\nIt may be the string \"<code>b</code>\" (only binary chunks),\n\"<code>t</code>\" (only text chunks),\nor \"<code>bt</code>\" (both binary and text).\nThe default is \"<code>bt</code>\".\n\n\n<p>\nIt is safe to load malformed binary chunks;\n<code>load</code> signals an appropriate error.\nHowever,\nLua does not check the consistency of the code inside binary chunks;\nrunning maliciously crafted bytecode can crash the interpreter.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\nA call to <code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numerical order,\nuse a numerical <b>for</b>.)\n\n\n<p>\nThe behavior of <code>next</code> is undefined if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may set existing fields to nil.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nIf <code>t</code> has a metamethod <code>__pairs</code>,\ncalls it with <code>t</code> as argument and returns the first three\nresults from the call.\n\n\n<p>\nOtherwise,\nreturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCalls the function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error object.\nNote that errors caught by <code>pcall</code> do not call a message handler.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments\nand prints their values to <code>stdout</code>,\nconverting each argument to a string\nfollowing the same rules of <a href=\"#pdf-tostring\"><code>tostring</code></a>.\n\n\n<p>\nThe function <code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\nfor instance for debugging.\nFor complete control over the output,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a> and <a href=\"#pdf-io.write\"><code>io.write</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking the <code>__eq</code> metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout using the <code>__index</code> metavalue.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawlen\"><code>rawlen (v)</code></a></h3>\nReturns the length of the object <code>v</code>,\nwhich must be a table or a string,\nwithout invoking the <code>__len</code> metamethod.\nReturns an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout using the <code>__newindex</code> metavalue.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b> and NaN,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>;\na negative number indexes from the end (-1 is the last argument).\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>__metatable</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n<p>\nTo change the metatable of other types from Lua code,\nyou must use the debug library (<a href=\"#6.10\">&sect;6.10</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\n\n\n<p>\nWhen called with no <code>base</code>,\n<code>tonumber</code> tries to convert its argument to a number.\nIf the argument is already a number or\na string convertible to a number,\nthen <code>tonumber</code> returns this number;\notherwise, it returns <b>fail</b>.\n\n\n<p>\nThe conversion of strings can result in integers or floats,\naccording to the lexical conventions of Lua (see <a href=\"#3.1\">&sect;3.1</a>).\nThe string may have leading and trailing spaces and a sign.\n\n\n<p>\nWhen called with <code>base</code>,\nthen <code>e</code> must be a string to be interpreted as\nan integer numeral in that base.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIf the string <code>e</code> is not a valid numeral in the given base,\nthe function returns <b>fail</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (v)</code></a></h3>\n\n\n<p>\nReceives a value of any type and\nconverts it to a string in a human-readable format.\n\n\n<p>\nIf the metatable of <code>v</code> has a <code>__tostring</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>v</code> as argument,\nand uses the result of the call as its result.\nOtherwise, if the metatable of <code>v</code> has a <code>__name</code> field\nwith a string value,\n<code>tostring</code> may use that string in its final result.\n\n\n<p>\nFor complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\n\n\n<p>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\n\n\n<p>\nA global variable (not a function) that\nholds a string containing the running Lua version.\nThe current value of this variable is \"<code>Lua 5.4</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-warn\"><code>warn (msg1, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEmits a warning with a message composed by the concatenation\nof all its arguments (which should be strings).\n\n\n<p>\nBy convention,\na one-piece message starting with '<code>@</code>'\nis intended to be a <em>control message</em>,\nwhich is a message to the warning system itself.\nIn particular, the standard warning function in Lua\nrecognizes the control messages \"<code>@off</code>\",\nto stop the emission of warnings,\nand \"<code>@on</code>\", to (re)start the emission;\nit ignores unknown control messages.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that it sets a new message handler <code>msgh</code>.\n\n\n\n\n\n\n\n<h2>6.2 &ndash; <a name=\"6.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThis library comprises the operations to manipulate coroutines,\nwhich come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.6\">&sect;2.6</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.close\"><code>coroutine.close (co)</code></a></h3>\n\n\n<p>\nCloses coroutine <code>co</code>,\nthat is,\ncloses all its pending to-be-closed variables\nand puts the coroutine in a dead state.\nThe given coroutine must be dead or suspended.\nIn case of error closing some variable,\nreturns <b>false</b> plus the error object;\notherwise returns <b>true</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.isyieldable\"><code>coroutine.isyieldable ([co])</code></a></h3>\n\n\n<p>\nReturns true when the coroutine <code>co</code> can yield.\nThe default for <code>co</code> is the running coroutine.\n\n\n<p>\nA coroutine is yieldable if it is not the main thread and\nit is not inside a non-yieldable C&nbsp;function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, ... are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, ... are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(when the coroutine yields) or any values returned by the body function\n(when the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine plus a boolean,\ntrue when the running coroutine is the main one.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of the coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running\n(that is, it is the one that called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>;\n<code>f</code> must be a function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to this function behave as the\nextra arguments to <code>resume</code>.\nThe function returns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error,\nthe function closes the coroutine and propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>6.3 &ndash; <a name=\"6.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading modules in Lua.\nIt exports one function directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a>.\nEverything else is exported in the table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\n(The absence of a second result in this case\nsignals that this call did not have to load the module.)\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the table <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>.\nEach item in this table is a search function,\nthat searches for the module in a particular way.\nBy changing this table,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which must be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.searchers\"><code>package.searchers</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with two arguments:\n<code>modname</code> and an extra value,\na <em>loader data</em>,\nalso returned by the searcher.\nThe loader data can be any value useful to the module;\nfor the default searchers,\nit indicates where the loader was found.\n(For instance, if the loader came from a file,\nthis extra value is the file path.)\nIf the loader returns any non-nil value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader does not return a non-nil value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\nBesides that value, <code>require</code> also returns as a second result\nthe loader data returned by the searcher,\nwhich indicates how <code>require</code> found the module.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> raises an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.config\"><code>package.config</code></a></h3>\n\n\n<p>\nA string describing some compile-time configurations for packages.\nThis string is a sequence of lines:\n\n<ul>\n\n<li>The first line is the directory separator string.\nDefault is '<code>\\</code>' for Windows and '<code>/</code>' for all other systems.</li>\n\n<li>The second line is the character that separates templates in a path.\nDefault is '<code>;</code>'.</li>\n\n<li>The third line is the string that marks the\nsubstitution points in a template.\nDefault is '<code>?</code>'.</li>\n\n<li>The fourth line is a string that, in a path in Windows,\nis replaced by the executable's directory.\nDefault is '<code>!</code>'.</li>\n\n<li>The fifth line is a mark to ignore all text after it\nwhen building the <code>luaopen_</code> function name.\nDefault is '<code>-</code>'.</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nA string with the path used by <a href=\"#pdf-require\"><code>require</code></a>\nto search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH_5_4\"><code>LUA_CPATH_5_4</code></a>,\nor the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>,\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\n\n\n<p>\nIf <code>funcname</code> is \"<code>*</code>\",\nthen it only links with the library,\nmaking the symbols exported by the library\navailable to other dynamically linked libraries.\nOtherwise,\nit looks for a function <code>funcname</code> inside the library\nand returns this function as a C&nbsp;function.\nSo, <code>funcname</code> must follow the <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a> prototype\n(see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and an extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by Standard&nbsp;C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n<p>\nThis function is inherently insecure,\nas it allows Lua to call any function in any readable dynamic\nlibrary in the system.\n(Lua calls any function assuming the function\nhas a proper prototype and respects a proper protocol\n(see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\nTherefore,\ncalling an arbitrary function in an arbitrary dynamic library\nmore often than not results in an access violation.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nA string with the path used by <a href=\"#pdf-require\"><code>require</code></a>\nto search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH_5_4\"><code>LUA_PATH_5_4</code></a> or\nthe environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif those environment variables are not defined.\nA \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n<p>\nThis variable is only a reference to the real table;\nassignments to this variable do not change the\ntable used by <a href=\"#pdf-require\"><code>require</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchers\"><code>package.searchers</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to find modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole argument.\nIf the searcher finds the module,\nit returns another function, the module <em>loader</em>,\nplus an extra value, a <em>loader data</em>,\nthat will be passed to that loader and\nreturned as a second result by <a href=\"#pdf-require\"><code>require</code></a>.\nIf it cannot find the module,\nit returns a string explaining why\n(or <b>nil</b> if it has nothing to say).\n\n\n<p>\nLua initializes this table with four searcher functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nThe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nAgain,\nthe search is done as described in function <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits suffix after (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.b.c-v2.1</code>,\nthe function name will be <code>luaopen_a_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n<p>\nAll searchers except the first one (preload) return as the extra value\nthe file path where the module was found,\nas returned by <a href=\"#pdf-package.searchpath\"><code>package.searchpath</code></a>.\nThe first searcher always returns the string \"<code>:preload:</code>\".\n\n\n<p>\nSearchers should raise no errors and have no side effects in Lua.\n(They may have side effects in C,\nfor instance by linking the application with a library.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.searchpath\"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3>\n\n\n<p>\nSearches for the given <code>name</code> in the given <code>path</code>.\n\n\n<p>\nA path is a string containing a sequence of\n<em>templates</em> separated by semicolons.\nFor each template,\nthe function replaces each interrogation mark (if any)\nin the template with a copy of <code>name</code>\nwherein all occurrences of <code>sep</code>\n(a dot, by default)\nwere replaced by <code>rep</code>\n(the system's directory separator, by default),\nand then tries to open the resulting file name.\n\n\n<p>\nFor instance, if the path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for the name <code>foo.a</code>\nwill try to open the files\n<code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and\n<code>/usr/local/foo/a/init.lua</code>, in that order.\n\n\n<p>\nReturns the resulting name of the first file that it can\nopen in read mode (after closing the file),\nor <b>fail</b> plus an error message if none succeeds.\n(This error message lists all file names it tried to open.)\n\n\n\n\n\n\n\n<h2>6.4 &ndash; <a name=\"6.4\">String Manipulation</a></h2>\n\n\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s,i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numeric codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, ..., <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\nThese indices are corrected\nfollowing the same rules of function <a href=\"#pdf-string.sub\"><code>string.sub</code></a>.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numeric code equal\nto its corresponding argument.\n\n\n<p>\nNumeric codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function [, strip])</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation\n(a <em>binary chunk</em>)\nof the given function,\nso that a later <a href=\"#pdf-load\"><code>load</code></a> on this string returns\na copy of the function (but with new upvalues).\nIf <code>strip</code> is a true value,\nthe binary representation may not include all debug information\nabout the function,\nto save space.\n\n\n<p>\nFunctions with upvalues have only their number of upvalues saved.\nWhen (re)loaded,\nthose upvalues receive fresh instances.\n(See the <a href=\"#pdf-load\"><code>load</code></a> function for details about\nhow these upvalues are initialized.\nYou can use the debug library to serialize\nand reload the upvalues of a function\nin a way adequate to your needs.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\n\n\n<p>\nLooks for the first match of\n<code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>fail</b>.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered magic.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument,\nwhich must be a string.\nThe format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.\nThe only differences are that the conversion specifiers and modifiers\n<code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, and <code>n</code> are not supported\nand that there is an extra specifier, <code>q</code>.\n\n\n<p>\nThe specifier <code>q</code> formats booleans, nil, numbers, and strings\nin a way that the result is a valid constant in Lua source code.\nBooleans and nil are written in the obvious way\n(<code>true</code>, <code>false</code>, <code>nil</code>).\nFloats are written in hexadecimal,\nto preserve full precision.\nA string is written between double quotes,\nusing escape sequences when necessary to ensure that\nit can safely be read back by the Lua interpreter.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nmay produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre><p>\nThis specifier does not support modifiers (flags, width, length).\n\n\n<p>\nThe conversion specifiers\n<code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>G</code>, and <code>g</code> all expect a number as argument.\nThe specifiers <code>c</code>, <code>d</code>,\n<code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>\nexpect an integer.\nWhen Lua is compiled with a C89 compiler,\nthe specifiers <code>A</code> and <code>a</code> (hexadecimal floats)\ndo not support modifiers.\n\n\n<p>\nThe specifier <code>s</code> expects a string;\nif its argument is not a string,\nit is converted to one following the same rules of <a href=\"#pdf-tostring\"><code>tostring</code></a>.\nIf the specifier has any modifier,\nthe corresponding string argument should not contain embedded zeros.\n\n\n<p>\nThe specifier <code>p</code> formats the pointer\nreturned by <a href=\"#lua_topointer\"><code>lua_topointer</code></a>.\nThat gives a unique string identifier for tables, userdata,\nthreads, strings, and functions.\nFor other values (numbers, nil, booleans),\nthis specifier results in a string representing\nthe pointer <code>NULL</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern [, init])</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>)\nover the string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n<p>\nAs an example, the following loop\nwill iterate over all the words from string <code>s</code>,\nprinting one per line:\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a caret '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\nThe name <code>gsub</code> comes from <em>Global SUBstitution</em>.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>d</em></code>,\nwith <em>d</em> between 1 and 9,\nstands for the value of the <em>d</em>-th captured substring;\nthe sequence <code>%0</code> stands for the whole match;\nthe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order.\n\n\n<p>\nIn any case,\nif the pattern specifies no captures,\nthen it behaves as if the whole pattern was inside a capture.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return load(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.4\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.4.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\n\n\n<p>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\n\n\n<p>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\n\n\n<p>\nLooks for the first <em>match</em> of\nthe <code>pattern</code> (see <a href=\"#6.4.1\">&sect;6.4.1</a>) in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>fail</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numeric argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.pack\"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.\nserialized in binary form (packed)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.packsize\"><code>string.packsize (fmt)</code></a></h3>\n\n\n<p>\nReturns the size of a string resulting from <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nwith the given format.\nThe format string cannot have the variable-length options\n'<code>s</code>' or '<code>z</code>' (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n [, sep])</code></a></h3>\n\n\n<p>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code> separated by the string <code>sep</code>.\nThe default value for <code>sep</code> is the empty string\n(that is, no separator).\nReturns the empty string if <code>n</code> is not positive.\n\n\n<p>\n(Note that it is very easy to exhaust the memory of your machine\nwith a single call to this function.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\n\n\n<p>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\n\n\n<p>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> (for a positive <code>i</code>)\nreturns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n<p>\nIf, after the translation of negative indices,\n<code>i</code> is less than 1,\nit is corrected to 1.\nIf <code>j</code> is greater than the string length,\nit is corrected to that length.\nIf, after these corrections,\n<code>i</code> is greater than <code>j</code>,\nthe function returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.unpack\"><code>string.unpack (fmt, s [, pos])</code></a></h3>\n\n\n<p>\nReturns the values packed in string <code>s</code> (see <a href=\"#pdf-string.pack\"><code>string.pack</code></a>)\naccording to the format string <code>fmt</code> (see <a href=\"#6.4.2\">&sect;6.4.2</a>).\nAn optional <code>pos</code> marks where\nto start reading in <code>s</code> (default is 1).\nAfter the read values,\nthis function also returns the index of the first unread byte in <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\n\n\n<p>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n\n\n\n\n<h3>6.4.1 &ndash; <a name=\"6.4.1\">Patterns</a></h3>\n\n\n\n<p>\nPatterns in Lua are described by regular strings,\nwhich are interpreted as patterns by the pattern-matching functions\n<a href=\"#pdf-string.find\"><code>string.find</code></a>,\n<a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>,\n<a href=\"#pdf-string.gsub\"><code>string.gsub</code></a>,\nand <a href=\"#pdf-string.match\"><code>string.match</code></a>.\nThis section describes the syntax and the meaning\n(that is, what they match) of these strings.\n\n\n\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>: </b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>: </b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>: </b> represents all letters.</li>\n\n<li><b><code>%c</code>: </b> represents all control characters.</li>\n\n<li><b><code>%d</code>: </b> represents all digits.</li>\n\n<li><b><code>%g</code>: </b> represents all printable characters except space.</li>\n\n<li><b><code>%l</code>: </b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>: </b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>: </b> represents all space characters.</li>\n\n<li><b><code>%u</code>: </b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>\n\n<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny non-alphanumeric character\n(including all punctuation characters, even the non-magical)\ncan be preceded by a '<code>%</code>' to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>: </b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range,\nin ascending order, with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nYou can put a closing square bracket in a set\nby positioning it as the first character in the set.\nYou can put a hyphen in a set\nby positioning it as the first or the last character in the set.\n(You can also use an escape for both cases.)\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>: </b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches sequences of zero or more characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches sequences of one or more characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches sequences of zero or more characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the shortest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches zero or one occurrence of a character in the class.\nIt always matches one occurrence if possible;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n<li>\n<code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;\nsuch item matches an empty string at any position such that\nthe next character belongs to <em>set</em>\nand the previous character does not belong to <em>set</em>.\nThe set <em>set</em> is interpreted as previously described.\nThe beginning and the end of the subject are handled as if\nthey were the character '<code>\\0</code>'.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA caret '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture, and therefore has number&nbsp;1;\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n\n\n\n<h4>Multiple matches:</h4><p>\nThe function <a href=\"#pdf-string.gsub\"><code>string.gsub</code></a> and the iterator <a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>\nmatch multiple occurrences of the given pattern in the subject.\nFor these functions,\na new match is considered valid only\nif it ends at least one byte after the end of the previous match.\nIn other words, the pattern machine never accepts the\nempty string as a match immediately after another match.\nAs an example,\nconsider the results of the following code:\n\n<pre>\n     &gt; string.gsub(\"abc\", \"()a*()\", print);\n     --&gt; 1   2\n     --&gt; 3   3\n     --&gt; 4   4\n</pre><p>\nThe second and third results come from Lua matching an empty\nstring after '<code>b</code>' and another one after '<code>c</code>'.\nLua does not match an empty string after '<code>a</code>',\nbecause it would end at the same position of the previous match.\n\n\n\n\n\n\n\n<h3>6.4.2 &ndash; <a name=\"6.4.2\">Format Strings for Pack and Unpack</a></h3>\n\n<p>\nThe first argument to <a href=\"#pdf-string.pack\"><code>string.pack</code></a>,\n<a href=\"#pdf-string.packsize\"><code>string.packsize</code></a>, and <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>\nis a format string,\nwhich describes the layout of the structure being created or read.\n\n\n<p>\nA format string is a sequence of conversion options.\nThe conversion options are as follows:\n\n<ul>\n<li><b><code>&lt;</code>: </b>sets little endian</li>\n<li><b><code>&gt;</code>: </b>sets big endian</li>\n<li><b><code>=</code>: </b>sets native endian</li>\n<li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>\n(default is native alignment)</li>\n<li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>\n<li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>\n<li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>\n<li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>\n<li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>\n<li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>\n<li><b><code>j</code>: </b>a <code>lua_Integer</code></li>\n<li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>\n<li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>\n<li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes\n(default is native size)</li>\n<li><b><code>f</code>: </b>a <code>float</code> (native size)</li>\n<li><b><code>d</code>: </b>a <code>double</code> (native size)</li>\n<li><b><code>n</code>: </b>a <code>lua_Number</code></li>\n<li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>\n<li><b><code>z</code>: </b>a zero-terminated string</li>\n<li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length\ncoded as an unsigned integer with <code>n</code> bytes\n(default is a <code>size_t</code>)</li>\n<li><b><code>x</code>: </b>one byte of padding</li>\n<li><b><code>X<em>op</em></code>: </b>an empty item that aligns\naccording to option <code>op</code>\n(which is otherwise ignored)</li>\n<li><b>'<code> </code>': </b>(space) ignored</li>\n</ul><p>\n(A \"<code>[<em>n</em>]</code>\" means an optional integral numeral.)\nExcept for padding, spaces, and configurations\n(options \"<code>xX &lt;=&gt;!</code>\"),\neach option corresponds to an argument in <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nor a result in <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>.\n\n\n<p>\nFor options \"<code>!<em>n</em></code>\", \"<code>s<em>n</em></code>\", \"<code>i<em>n</em></code>\", and \"<code>I<em>n</em></code>\",\n<code>n</code> can be any integer between 1 and 16.\nAll integral options check overflows;\n<a href=\"#pdf-string.pack\"><code>string.pack</code></a> checks whether the given value fits in the given size;\n<a href=\"#pdf-string.unpack\"><code>string.unpack</code></a> checks whether the read value fits in a Lua integer.\nFor the unsigned options,\nLua integers are treated as unsigned values too.\n\n\n<p>\nAny format string starts as if prefixed by \"<code>!1=</code>\",\nthat is,\nwith maximum alignment of 1 (no alignment)\nand native endianness.\n\n\n<p>\nNative endianness assumes that the whole system is\neither big or little endian.\nThe packing functions will not emulate correctly the behavior\nof mixed-endian formats.\n\n\n<p>\nAlignment works as follows:\nFor each option,\nthe format gets extra padding until the data starts\nat an offset that is a multiple of the minimum between the\noption size and the maximum alignment;\nthis minimum must be a power of 2.\nOptions \"<code>c</code>\" and \"<code>z</code>\" are not aligned;\noption \"<code>s</code>\" follows the alignment of its starting integer.\n\n\n<p>\nAll padding is filled with zeros by <a href=\"#pdf-string.pack\"><code>string.pack</code></a>\nand ignored by <a href=\"#pdf-string.unpack\"><code>string.unpack</code></a>.\n\n\n\n\n\n\n\n<h2>6.5 &ndash; <a name=\"6.5\">UTF-8 Support</a></h2>\n\n<p>\nThis library provides basic support for UTF-8 encoding.\nIt provides all its functions inside the table <a name=\"pdf-utf8\"><code>utf8</code></a>.\nThis library does not provide any support for Unicode other\nthan the handling of the encoding.\nAny operation that needs the meaning of a character,\nsuch as character classification, is outside its scope.\n\n\n<p>\nUnless stated otherwise,\nall functions that expect a byte position as a parameter\nassume that the given position is either the start of a byte sequence\nor one plus the length of the subject string.\nAs in the string library,\nnegative indices count from the end of the string.\n\n\n<p>\nFunctions that create byte sequences\naccept all values up to <code>0x7FFFFFFF</code>,\nas defined in the original UTF-8 specification;\nthat implies byte sequences of up to six bytes.\n\n\n<p>\nFunctions that interpret byte sequences only accept\nvalid sequences (well formed and not overlong).\nBy default, they only accept byte sequences\nthat result in valid Unicode code points,\nrejecting values greater than <code>10FFFF</code> and surrogates.\nA boolean argument <code>lax</code>, when available,\nlifts these checks,\nso that all values up to <code>0x7FFFFFFF</code> are accepted.\n(Not well formed and overlong sequences are still rejected.)\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.char\"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReceives zero or more integers,\nconverts each one to its corresponding UTF-8 byte sequence\nand returns a string with the concatenation of all these sequences.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.charpattern\"><code>utf8.charpattern</code></a></h3>\n\n\n<p>\nThe pattern (a string, not a function) \"<code>[\\0-\\x7F\\xC2-\\xFD][\\x80-\\xBF]*</code>\"\n(see <a href=\"#6.4.1\">&sect;6.4.1</a>),\nwhich matches exactly one UTF-8 byte sequence,\nassuming that the subject is a valid UTF-8 string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codes\"><code>utf8.codes (s [, lax])</code></a></h3>\n\n\n<p>\nReturns values so that the construction\n\n<pre>\n     for p, c in utf8.codes(s) do <em>body</em> end\n</pre><p>\nwill iterate over all UTF-8 characters in string <code>s</code>,\nwith <code>p</code> being the position (in bytes) and <code>c</code> the code point\nof each character.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.codepoint\"><code>utf8.codepoint (s [, i [, j [, lax]]])</code></a></h3>\n\n\n<p>\nReturns the code points (as integers) from all characters in <code>s</code>\nthat start between byte position <code>i</code> and <code>j</code> (both included).\nThe default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.\nIt raises an error if it meets any invalid byte sequence.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.len\"><code>utf8.len (s [, i [, j [, lax]]])</code></a></h3>\n\n\n<p>\nReturns the number of UTF-8 characters in string <code>s</code>\nthat start between positions <code>i</code> and <code>j</code> (both inclusive).\nThe default for <code>i</code> is 1 and for <code>j</code> is -1.\nIf it finds any invalid byte sequence,\nreturns <b>fail</b> plus the position of the first invalid byte.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-utf8.offset\"><code>utf8.offset (s, n [, i])</code></a></h3>\n\n\n<p>\nReturns the position (in bytes) where the encoding of the\n<code>n</code>-th character of <code>s</code>\n(counting from position <code>i</code>) starts.\nA negative <code>n</code> gets characters before position <code>i</code>.\nThe default for <code>i</code> is 1 when <code>n</code> is non-negative\nand <code>#s + 1</code> otherwise,\nso that <code>utf8.offset(s, -n)</code> gets the offset of the\n<code>n</code>-th character from the end of the string.\nIf the specified character is neither in the subject\nnor right after its end,\nthe function returns <b>fail</b>.\n\n\n<p>\nAs a special case,\nwhen <code>n</code> is 0 the function returns the start of the encoding\nof the character that contains the <code>i</code>-th byte of <code>s</code>.\n\n\n<p>\nThis function assumes that <code>s</code> is a valid UTF-8 string.\n\n\n\n\n\n\n\n<h2>6.6 &ndash; <a name=\"6.6\">Table Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nRemember that, whenever an operation needs the length of a table,\nall caveats about the length operator apply (see <a href=\"#3.4.7\">&sect;3.4.7</a>).\nAll functions ignore non-numeric keys\nin the tables given as arguments.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>\n\n\n<p>\nGiven a list where all elements are strings or numbers,\nreturns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is <code>#list</code>.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (list, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>list</code>,\nshifting up the elements\n<code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.\nThe default value for <code>pos</code> is <code>#list+1</code>,\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof the list <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.move\"><code>table.move (a1, f, e, t [,a2])</code></a></h3>\n\n\n<p>\nMoves elements from the table <code>a1</code> to the table <code>a2</code>,\nperforming the equivalent to the following\nmultiple assignment:\n<code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.\nThe default for <code>a2</code> is <code>a1</code>.\nThe destination range can overlap with the source range.\nThe number of elements to be moved must fit in a Lua integer.\n\n\n<p>\nReturns the destination table <code>a2</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.pack\"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns a new table with all arguments stored into keys 1, 2, etc.\nand with a field \"<code>n</code>\" with the total number of arguments.\nNote that the resulting table may not be a sequence,\nif some arguments are <b>nil</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (list [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>list</code> the element at position <code>pos</code>,\nreturning the value of the removed element.\nWhen <code>pos</code> is an integer between 1 and <code>#list</code>,\nit shifts down the elements\n<code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>\nand erases element <code>list[#list]</code>;\nThe index <code>pos</code> can also be 0 when <code>#list</code> is 0,\nor <code>#list + 1</code>.\n\n\n<p>\nThe default value for <code>pos</code> is <code>#list</code>,\nso that a call <code>table.remove(l)</code> removes the last element\nof the list <code>l</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (list [, comp])</code></a></h3>\n\n\n<p>\nSorts the list elements in a given order, <em>in-place</em>,\nfrom <code>list[1]</code> to <code>list[#list]</code>.\nIf <code>comp</code> is given,\nthen it must be a function that receives two list elements\nand returns true when the first element must come\nbefore the second in the final order\n(so that, after the sort,\n<code>i &lt; j</code> implies <code>not comp(list[j],list[i])</code>).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nNote that the <code>comp</code> function must define\na strict partial order over the elements in the list;\nthat is, it must be asymmetric and transitive.\nOtherwise, no valid sort may be possible.\n\n\n<p>\nThe sort algorithm is not stable:\nelements considered equal by the given order\nmay have their relative positions changed by the sort.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.unpack\"><code>table.unpack (list [, i [, j]])</code></a></h3>\n\n\n<p>\nReturns the elements from the given list.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.\n\n\n\n\n\n\n\n<h2>6.7 &ndash; <a name=\"6.7\">Mathematical Functions</a></h2>\n\n<p>\nThis library provides basic mathematical functions.\nIt provides all its functions and constants inside the table <a name=\"pdf-math\"><code>math</code></a>.\nFunctions with the annotation \"<code>integer/float</code>\" give\ninteger results for integer arguments\nand float results for non-integer arguments.\nThe rounding functions\n<a href=\"#pdf-math.ceil\"><code>math.ceil</code></a>, <a href=\"#pdf-math.floor\"><code>math.floor</code></a>, and <a href=\"#pdf-math.modf\"><code>math.modf</code></a>\nreturn an integer when the result fits in the range of an integer,\nor a float otherwise.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the maximum value between <code>x</code> and <code>-x</code>. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (y [, x])</code></a></h3>\n\n\n<p>\n\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both arguments to find the\nquadrant of the result.\nIt also handles correctly the case of <code>x</code> being zero.\n\n\n<p>\nThe default value for <code>x</code> is 1,\nso that the call <code>math.atan(y)</code>\nreturns the arc tangent of <code>y</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integral value greater than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from radians to degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>\n(where <code>e</code> is the base of natural logarithms).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integral value less than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero. (integer/float)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe float value <code>HUGE_VAL</code>,\na value greater than any other numeric value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x [, base])</code></a></h3>\n\n\n<p>\nReturns the logarithm of <code>x</code> in the given base.\nThe default for <code>base</code> is <em>e</em>\n(so that the function returns the natural logarithm of <code>x</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the maximum value,\naccording to the Lua operator <code>&lt;</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.maxinteger\"><code>math.maxinteger</code></a></h3>\nAn integer with the maximum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the argument with the minimum value,\naccording to the Lua operator <code>&lt;</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.mininteger\"><code>math.mininteger</code></a></h3>\nAn integer with the minimum value for an integer.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns the integral part of <code>x</code> and the fractional part of <code>x</code>.\nIts second result is always a float.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>&pi;</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nConverts the angle <code>x</code> from degrees to radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nWhen called without arguments,\nreturns a pseudo-random float with uniform distribution\nin the range  <em>[0,1)</em>.  \nWhen called with two integers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a pseudo-random integer\nwith uniform distribution in the range <em>[m, n]</em>.\nThe call <code>math.random(n)</code>, for a positive <code>n</code>,\nis equivalent to <code>math.random(1,n)</code>.\nThe call <code>math.random(0)</code> produces an integer with\nall bits (pseudo)random.\n\n\n<p>\nThis function uses the <code>xoshiro256**</code> algorithm to produce\npseudo-random 64-bit integers,\nwhich are the results of calls with argument&nbsp;0.\nOther results (ranges and floats)\nare unbiased extracted from these integers.\n\n\n<p>\nLua initializes its pseudo-random generator with the equivalent of\na call to <a href=\"#pdf-math.randomseed\"><code>math.randomseed</code></a> with no arguments,\nso that <code>math.random</code> should generate\ndifferent sequences of results each time the program runs.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed ([x [, y]])</code></a></h3>\n\n\n<p>\nWhen called with at least one argument,\nthe integer parameters <code>x</code> and <code>y</code> are\njoined into a 128-bit <em>seed</em> that\nis used to reinitialize the pseudo-random generator;\nequal seeds produce equal sequences of numbers.\nThe default for <code>y</code> is zero.\n\n\n<p>\nWhen called with no arguments,\nLua generates a seed with\na weak attempt for randomness.\n\n\n<p>\nThis function returns the two seed components\nthat were effectively used,\nso that setting them again repeats the sequence.\n\n\n<p>\nTo ensure a required level of randomness to the initial state\n(or contrarily, to have a deterministic sequence,\nfor instance when debugging a program),\nyou should call <a href=\"#pdf-math.randomseed\"><code>math.randomseed</code></a> with explicit arguments.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tointeger\"><code>math.tointeger (x)</code></a></h3>\n\n\n<p>\nIf the value <code>x</code> is convertible to an integer,\nreturns that integer.\nOtherwise, returns <b>fail</b>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.type\"><code>math.type (x)</code></a></h3>\n\n\n<p>\nReturns \"<code>integer</code>\" if <code>x</code> is an integer,\n\"<code>float</code>\" if it is a float,\nor <b>fail</b> if <code>x</code> is not a number.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ult\"><code>math.ult (m, n)</code></a></h3>\n\n\n<p>\nReturns a boolean,\ntrue if and only if integer <code>m</code> is below integer <code>n</code> when\nthey are compared as unsigned integers.\n\n\n\n\n\n\n\n<h2>6.8 &ndash; <a name=\"6.8\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file handles;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are done over these default files.\nThe second style uses explicit file handles.\n\n\n<p>\nWhen using implicit file handles,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file handles,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file handle\nand then all operations are supplied as methods of the file handle.\n\n\n<p>\nThe metatable for file handles provides metamethods\nfor <code>__gc</code> and <code>__close</code> that try\nto close the file when called.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file handles with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>fail</b> on failure,\nplus an error message as a second result and\na system-dependent error code as a third result,\nand some non-false value on success.\nOn non-POSIX systems,\nthe computation of the error message and error code\nin case of errors\nmay be not thread safe,\nbecause they rely on the global C variable <code>errno</code>.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():flush()</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without arguments,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that\nworks like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.\nWhen the iterator function fails to read any value,\nit automatically closes the file.\nBesides the iterator function,\n<code>io.lines</code> returns three other values:\ntwo <b>nil</b> values as placeholders,\nplus the created file handle.\nTherefore, when used in a generic <b>for</b> loop,\nthe file is closed also if the loop is interrupted by an\nerror or a <b>break</b>.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines(\"l\")</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case, the iterator does not close the file when the loop ends.\n\n\n<p>\nIn case of errors opening the file,\nthis function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIn case of success,\nit returns a new file handle.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"<code>r</code>\": </b> read mode (the default);</li>\n<li><b>\"<code>w</code>\": </b> write mode;</li>\n<li><b>\"<code>a</code>\": </b> append mode;</li>\n<li><b>\"<code>r+</code>\": </b> update mode, all previous data is preserved;</li>\n<li><b>\"<code>w+</code>\": </b> update mode, all previous data is erased;</li>\n<li><b>\"<code>a+</code>\": </b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n<p>\nStarts the program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nIn case of success,\nreturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>fail</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n<p>\nWhen closing a file handle created with <a href=\"#pdf-io.popen\"><code>io.popen</code></a>,\n<a href=\"#pdf-file:close\"><code>file:close</code></a> returns the same values\nreturned by <a href=\"#pdf-os.execute\"><code>os.execute</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreads the file according to the given formats.\nWhen no format is given,\nuses \"<code>l</code>\" as a default.\nAs an example, the construction\n\n<pre>\n     for c in file:lines(1) do <em>body</em> end\n</pre><p>\nwill iterate over all characters of the file,\nstarting at the current position.\nUnlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string or a number with the characters read,\nor <b>fail</b> if it cannot read data with the specified format.\n(In this latter case,\nthe function does not read subsequent formats.)\nWhen called without arguments,\nit uses a default format that reads the next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"<code>n</code>\": </b>\nreads a numeral and returns it as a float or an integer,\nfollowing the lexical conventions of Lua.\n(The numeral may have leading whitespaces and a sign.)\nThis format always reads the longest input sequence that\nis a valid prefix for a numeral;\nif that prefix does not form a valid numeral\n(e.g., an empty string, \"<code>0x</code>\", or \"<code>3.4e-</code>\")\nor it is too long (more than 200 characters),\nit is discarded and the format returns <b>fail</b>.\n</li>\n\n<li><b>\"<code>a</code>\": </b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string;\nthis format never fails.\n</li>\n\n<li><b>\"<code>l</code>\": </b>\nreads the next line skipping the end of line,\nreturning <b>fail</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b>\"<code>L</code>\": </b>\nreads the next line keeping the end-of-line character (if present),\nreturning <b>fail</b> on end of file.\n</li>\n\n<li><b><em>number</em>: </b>\nreads a string with up to this number of bytes,\nreturning <b>fail</b> on end of file.\nIf <code>number</code> is zero,\nit reads nothing and returns an empty string,\nor <b>fail</b> on end of file.\n</li>\n\n</ul><p>\nThe formats \"<code>l</code>\" and \"<code>L</code>\" should be used only for text files.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence [, offset]])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"<code>set</code>\": </b> base is position 0 (beginning of the file);</li>\n<li><b>\"<code>cur</code>\": </b> base is current position;</li>\n<li><b>\"<code>end</code>\": </b> base is end of file;</li>\n</ul><p>\nIn case of success, <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf <code>seek</code> fails, it returns <b>fail</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for a file.\nThere are three available modes:\n\n<ul>\n<li><b>\"<code>no</code>\": </b> no buffering.</li>\n<li><b>\"<code>full</code>\": </b> full buffering.</li>\n<li><b>\"<code>line</code>\": </b> line buffering.</li>\n</ul>\n\n<p>\nFor the last two cases,\n<code>size</code> is a hint for the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n<p>\nThe specific behavior of each mode is non portable;\ncheck the underlying ISO&nbsp;C function <code>setvbuf</code> in your platform for\nmore details.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to <code>file</code>.\nThe arguments must be strings or numbers.\n\n\n<p>\nIn case of success, this function returns <code>file</code>.\n\n\n\n\n\n\n\n<h2>6.9 &ndash; <a name=\"6.9\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program,\nas returned by the underlying ISO&nbsp;C function <code>clock</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),\n<code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59),\n<code>sec</code> (0&ndash;61, due to leap seconds),\n<code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),\n<code>yday</code> (day of the year, 1&ndash;366),\nand <code>isdst</code> (daylight saving flag, a boolean).\nThis last field may be absent\nif the information is not available.\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.\n\n\n<p>\nIf <code>format</code> is absent, it defaults to \"<code>%c</code>\",\nwhich gives a human-readable date and time representation\nusing the current locale.\n\n\n<p>\nOn non-POSIX systems,\nthis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the difference, in seconds,\nfrom time <code>t1</code> to time <code>t2</code>\n(where the times are values returned by <a href=\"#pdf-os.time\"><code>os.time</code></a>).\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the ISO&nbsp;C function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIts first result is <b>true</b>\nif the command terminated successfully,\nor <b>fail</b> otherwise.\nAfter this first result\nthe function returns a string plus a number,\nas follows:\n\n<ul>\n\n<li><b>\"<code>exit</code>\": </b>\nthe command terminated normally;\nthe following number is the exit status of the command.\n</li>\n\n<li><b>\"<code>signal</code>\": </b>\nthe command was terminated by a signal;\nthe following number is the signal that terminated the command.\n</li>\n\n</ul>\n\n<p>\nWhen called without a <code>command</code>,\n<code>os.execute</code> returns a boolean that is true if a shell is available.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code [, close]])</code></a></h3>\n\n\n<p>\nCalls the ISO&nbsp;C function <code>exit</code> to terminate the host program.\nIf <code>code</code> is <b>true</b>,\nthe returned status is <code>EXIT_SUCCESS</code>;\nif <code>code</code> is <b>false</b>,\nthe returned status is <code>EXIT_FAILURE</code>;\nif <code>code</code> is a number,\nthe returned status is this number.\nThe default value for <code>code</code> is <b>true</b>.\n\n\n<p>\nIf the optional second argument <code>close</code> is true,\ncloses the Lua state before exiting.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>\nor <b>fail</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file (or empty directory, on POSIX systems)\nwith the given name.\nIf this function fails, it returns <b>fail</b>\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames the file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>fail</b>,\nplus a string describing the error and the error code.\nOtherwise, it returns true.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a system-dependent string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>fail</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n<p>\nThis function may be not thread safe\nbecause of its reliance on C&nbsp;function <code>setlocale</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the local date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields\n<code>hour</code> (default is 12),\n<code>min</code> (default is 0),\n<code>sec</code> (default is 0),\nand <code>isdst</code> (default is <b>nil</b>).\nOther fields are ignored.\nFor a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function.\n\n\n<p>\nWhen the function is called,\nthe values in these fields do not need to be inside their valid ranges.\nFor instance, if <code>sec</code> is -10,\nit means 10 seconds before the time specified by the other fields;\nif <code>hour</code> is 1000,\nit means 1000 hours after the time specified by the other fields.\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems,\nthis number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<a href=\"#pdf-os.date\"><code>os.date</code></a> and <a href=\"#pdf-os.difftime\"><code>os.difftime</code></a>.\n\n\n<p>\nWhen called with a table,\n<code>os.time</code> also normalizes all the fields\ndocumented in the <a href=\"#pdf-os.date\"><code>os.date</code></a> function,\nso that they represent the same time as before the call\nbut with values inside their valid ranges.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nIn POSIX systems,\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>6.10 &ndash; <a name=\"6.10\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface (<a href=\"#4.7\">&sect;4.7</a>) to Lua programs.\nYou should exert care when using this library.\nSeveral of its functions\nviolate basic assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside;\nthat userdata metatables cannot be changed by Lua code;\nthat Lua programs do not crash)\nand therefore can compromise otherwise secure code.\nMoreover, some functions in this library may be slow.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count,\nas set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function.\n\n\n<p>\nReturns <b>fail</b> if there is no active hook.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly\nor you can give a number as the value of <code>f</code>,\nwhich means the function running at level <code>f</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>\n(except for tail calls, which do not count in the stack);\nand so on.\nIf <code>f</code> is a number greater than the number of active functions,\nthen <code>getinfo</code> returns <b>fail</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] f, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>f</code> of the stack.\nThis function accesses not only explicit local variables,\nbut also parameters and temporary values.\n\n\n<p>\nThe first parameter or local variable has index&nbsp;1, and so on,\nfollowing the order that they are declared in the code,\ncounting only the variables that are active\nin the current scope of the function.\nCompile-time constants may not appear in this listing,\nif they were optimized away by the compiler.\nNegative indices refer to vararg arguments;\n-1 is the first vararg argument.\nThe function returns <b>fail</b>\nif there is no variable with the given index,\nand raises an error when called with a level out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parenthesis) \nrepresent variables with no known names\n(internal variables such as loop control variables,\nand variables from chunks saved without debug information).\n\n\n<p>\nThe parameter <code>f</code> may also be a function.\nIn that case, <code>getlocal</code> returns only the name of function parameters.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (value)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>value</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#4.3\">&sect;4.3</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (f, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>fail</b>\nif there is no upvalue with the given index.\n\n\n<p>\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n\n\n<p>\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n\n\n<p>\nVariable name '<code>?</code>' (interrogation mark)\nrepresents variables with no known names\n(variables from chunks saved without debug information).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getuservalue\"><code>debug.getuservalue (u, n)</code></a></h3>\n\n\n<p>\nReturns the <code>n</code>-th user value associated\nto the userdata <code>u</code> plus a boolean,\n<b>false</b> if the userdata does not have that value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setcstacklimit\"><code>debug.setcstacklimit (limit)</code></a></h3>\n\n\n<p>\nSets a new limit for the C stack.\nThis limit controls how deeply nested calls can go in Lua,\nwith the intent of avoiding a stack overflow.\nA limit too small restricts recursive calls pointlessly;\na limit too large exposes the interpreter to stack-overflow crashes.\nUnfortunately, there is no way to know a priori\nthe maximum safe limit for a platform.\n\n\n<p>\nEach call made from Lua code counts one unit.\nOther operations (e.g., calls made from C to Lua or resuming a coroutine)\nmay have a higher cost.\n\n\n<p>\nThis function has the following restrictions:\n\n<ul>\n<li>It can only be called from the main coroutine (thread);</li>\n<li>It cannot be called while handling a stack-overflow error;</li>\n<li><code>limit</code> must be less than 40000;</li>\n<li><code>limit</code> cannot be less than the amount of C stack in use.</li>\n</ul><p>\nIf a call does not respect some restriction,\nit returns a false value.\nOtherwise,\nthe call returns the old limit.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as the debug hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have any combination of the following characters,\nwith the given meaning:\n\n<ul>\n<li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>\n<li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>\n<li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nMoreover,\nwith a <code>count</code> different from zero,\nthe hook is called also after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first parameter is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code>, <code>\"tail call\"</code>, <code>\"return\"</code>,\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function.\n(Level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>fail</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n<p>\nSee <a href=\"#pdf-debug.getlocal\"><code>debug.getlocal</code></a> for more information about\nvariable indices and names.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (value, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>value</code> to the given <code>table</code>\n(which can be <b>nil</b>).\nReturns <code>value</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (f, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>f</code>.\nThe function returns <b>fail</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n<p>\nSee <a href=\"#pdf-debug.getupvalue\"><code>debug.getupvalue</code></a> for more information about upvalues.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setuservalue\"><code>debug.setuservalue (udata, value, n)</code></a></h3>\n\n\n<p>\nSets the given <code>value</code> as\nthe <code>n</code>-th user value associated to the given <code>udata</code>.\n<code>udata</code> must be a full userdata.\n\n\n<p>\nReturns <code>udata</code>,\nor <b>fail</b> if the userdata does not have that value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3>\n\n\n<p>\nIf <code>message</code> is present but is neither a string nor <b>nil</b>,\nthis function returns <code>message</code> without further processing.\nOtherwise,\nit returns a string with a traceback of the call stack.\nThe optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvalueid\"><code>debug.upvalueid (f, n)</code></a></h3>\n\n\n<p>\nReturns a unique identifier (as a light userdata)\nfor the upvalue numbered <code>n</code>\nfrom the given function.\n\n\n<p>\nThese unique identifiers allow a program to check whether different\nclosures share upvalues.\nLua closures that share an upvalue\n(that is, that access a same external local variable)\nwill return identical ids for those upvalue indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.upvaluejoin\"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>\n\n\n<p>\nMake the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>\nrefer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.\n\n\n\n\n\n\n\n<h1>7 &ndash; <a name=\"7\">Lua Standalone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a standalone language.\nAn interpreter for Lua as a standalone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe standalone interpreter includes\nall standard libraries.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>: </b> execute string <em>stat</em>;</li>\n<li><b><code>-i</code>: </b> enter interactive mode after running <em>script</em>;</li>\n<li><b><code>-l <em>mod</em></code>: </b> \"require\" <em>mod</em> and assign the\n  result to global <em>mod</em>;</li>\n<li><b><code>-v</code>: </b> print version information;</li>\n<li><b><code>-E</code>: </b> ignore environment variables;</li>\n<li><b><code>-W</code>: </b> turn warnings on;</li>\n<li><b><code>--</code>: </b> stop handling options;</li>\n<li><b><code>-</code>: </b> execute <code>stdin</code> as a file and stop handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nWhen called without the option <code>-E</code>,\nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT_5_4\"><code>LUA_INIT_5_4</code></a>\n(or <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a> if the versioned name is not defined)\nbefore running any argument.\nIf the variable content has the format <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nWhen called with the option <code>-E</code>,\nLua does not consult any environment variables.\nIn particular,\nthe values of <a href=\"#pdf-package.path\"><code>package.path</code></a> and <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>\nare set with the default paths defined in <code>luaconf.h</code>.\n\n\n<p>\nThe options <code>-e</code>, <code>-l</code>, and <code>-W</code> are handled in\nthe order they appear.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e 'a=1' -llib1 script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then require the library <code>lib1</code>,\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore running any code,\n<code>lua</code> collects all command-line arguments\nin a global table called <code>arg</code>.\nThe script name goes to index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus its options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe table is like this:\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nIf there is no script in the call,\nthe interpreter name goes to index 0,\nfollowed by the other arguments.\nFor instance, the call\n\n<pre>\n     $ lua -e \"print(arg[1])\"\n</pre><p>\nwill print \"<code>-e</code>\".\nIf there is a script,\nthe script is called with arguments\n<code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.\nLike all chunks in Lua,\nthe script is compiled as a vararg function.\n\n\n<p>\nIn interactive mode,\nLua repeatedly prompts and waits for a line.\nAfter reading a line,\nLua first try to interpret the line as an expression.\nIf it succeeds, it prints its value.\nOtherwise, it interprets the line as a statement.\nIf you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\n\n\n<p>\nIn case of unprotected errors in the script,\nthe interpreter reports the error to the standard error stream.\nIf the error object is not a string but\nhas a metamethod <code>__tostring</code>,\nthe interpreter calls this metamethod to produce the final message.\nOtherwise, the interpreter converts the error object to a string\nand adds a stack traceback to it.\nWhen warnings are on,\nthey are simply printed in the standard error output.\n\n\n<p>\nWhen finishing normally,\nthe interpreter closes its main Lua state\n(see <a href=\"#lua_close\"><code>lua_close</code></a>).\nThe script can avoid this step by\ncalling <a href=\"#pdf-os.exit\"><code>os.exit</code></a> to terminate.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nLua skips the first line of a file chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\nOf course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen\n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.\n\n\n\n<h1>8 &ndash; <a name=\"8\">Incompatibilities with the Previous Version</a></h1>\n\n\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.3 to Lua&nbsp;5.4.\n\n\n<p>\nYou can avoid some incompatibilities by compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the future.\nMore often than not,\ncompatibility issues arise when these compatibility options\nare removed.\nSo, whenever you have the chance,\nyou should try to test your code with a version of Lua compiled\nwith all compatibility options turned off.\nThat will ease transitions to newer versions of Lua.\n\n\n<p>\nLua versions can always change the C API in ways that\ndo not imply source-code changes in a program,\nsuch as the numeric values for constants\nor the implementation of functions as macros.\nTherefore,\nyou should never assume that binaries are compatible between\ndifferent Lua versions.\nAlways recompile clients of the Lua API when\nusing a new version.\n\n\n<p>\nSimilarly, Lua versions can always change the internal representation\nof precompiled chunks;\nprecompiled chunks are not compatible between different Lua versions.\n\n\n<p>\nThe standard paths in the official distribution may\nchange between versions.\n\n\n\n\n\n<h2>8.1 &ndash; <a name=\"8.1\">Incompatibilities in the Language</a></h2>\n<ul>\n\n<li>\nThe coercion of strings to numbers in\narithmetic and bitwise operations\nhas been removed from the core language.\nThe string library does a similar job\nfor arithmetic (but not for bitwise) operations\nusing the string metamethods.\nHowever, unlike in previous versions,\nthe new implementation preserves the implicit type of the numeral\nin the string.\nFor instance, the result of <code>\"1\" + \"2\"</code> now is an integer,\nnot a float.\n</li>\n\n<li>\nLiteral decimal integer constants that overflow are read as floats,\ninstead of wrapping around.\nYou can use hexadecimal notation for such constants if you\nwant the old behavior\n(reading them as integers with wrap around).\n</li>\n\n<li>\nThe use of the <code>__lt</code> metamethod to emulate <code>__le</code>\nhas been removed.\nWhen needed, this metamethod must be explicitly defined.\n</li>\n\n<li>\nThe semantics of the numerical <b>for</b> loop\nover integers changed in some details.\nIn particular, the control variable never wraps around.\n</li>\n\n<li>\nA label for a <b>goto</b> cannot be declared where a label with the same\nname is visible, even if this other label is declared in an enclosing\nblock.\n</li>\n\n<li>\nWhen finalizing an object,\nLua does not ignore <code>__gc</code> metamethods that are not functions.\nAny value will be called, if present.\n(Non-callable values will generate a warning,\nlike any other error when calling a finalizer.)\n</li>\n\n</ul>\n\n\n\n\n<h2>8.2 &ndash; <a name=\"8.2\">Incompatibilities in the Libraries</a></h2>\n<ul>\n\n<li>\nThe function <a href=\"#pdf-print\"><code>print</code></a> does not call <a href=\"#pdf-tostring\"><code>tostring</code></a>\nto format its arguments;\ninstead, it has this functionality hardwired.\nYou should use <code>__tostring</code> to modify how values are printed.\n</li>\n\n<li>\nThe pseudo-random number generator used by the function <a href=\"#pdf-math.random\"><code>math.random</code></a>\nnow starts with a somewhat random seed.\nMoreover, it uses a different algorithm.\n</li>\n\n<li>\nBy default, the decoding functions in the <a href=\"#pdf-utf8\"><code>utf8</code></a> library\ndo not accept surrogates as valid code points.\nAn extra parameter in these functions makes them more permissive.\n</li>\n\n<li>\nThe options \"<code>setpause</code>\" and \"<code>setstepmul</code>\"\nof the function <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> are deprecated.\nYou should use the new option \"<code>incremental</code>\" to set them.\n</li>\n\n<li>\nThe function <a href=\"#pdf-io.lines\"><code>io.lines</code></a> now returns four values,\ninstead of just one.\nThat can be a problem when it is used as the sole\nargument to another function that has optional parameters,\nsuch as in <code>load(io.lines(filename, \"L\"))</code>.\nTo fix that issue,\nyou can wrap the call into parentheses,\nto adjust its number of results to one.\n</li>\n\n</ul>\n\n\n\n\n<h2>8.3 &ndash; <a name=\"8.3\">Incompatibilities in the API</a></h2>\n\n\n<ul>\n\n<li>\nFull userdata now has an arbitrary number of associated user values.\nTherefore, the functions <code>lua_newuserdata</code>,\n<code>lua_setuservalue</code>, and <code>lua_getuservalue</code> were\nreplaced by <a href=\"#lua_newuserdatauv\"><code>lua_newuserdatauv</code></a>,\n<a href=\"#lua_setiuservalue\"><code>lua_setiuservalue</code></a>, and <a href=\"#lua_getiuservalue\"><code>lua_getiuservalue</code></a>,\nwhich have an extra argument.\n\n\n<p>\nFor compatibility, the old names still work as macros assuming\none single user value.\nNote, however, that userdata with zero user values\nare more efficient memory-wise.\n</li>\n\n<li>\nThe function <a href=\"#lua_resume\"><code>lua_resume</code></a> has an extra parameter.\nThis out parameter returns the number of values on\nthe top of the stack that were yielded or returned by the coroutine.\n(In previous versions,\nthose values were the entire stack.)\n</li>\n\n<li>\nThe function <a href=\"#lua_version\"><code>lua_version</code></a> returns the version number,\ninstead of an address of the version number.\nThe Lua core should work correctly with libraries using their\nown static copies of the same core,\nso there is no need to check whether they are using the same\naddress space.\n</li>\n\n<li>\nThe constant <code>LUA_ERRGCMM</code> was removed.\nErrors in finalizers are never propagated;\ninstead, they generate a warning.\n</li>\n\n<li>\nThe options <code>LUA_GCSETPAUSE</code> and <code>LUA_GCSETSTEPMUL</code>\nof the function <a href=\"#lua_gc\"><code>lua_gc</code></a> are deprecated.\nYou should use the new option <code>LUA_GCINC</code> to set them.\n</li>\n\n</ul>\n\n\n\n\n<h1>9 &ndash; <a name=\"9\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\nAs usual in extended BNF,\n{A} means 0 or more As,\nand [A] means an optional A.\n(For operator precedences, see <a href=\"#3.4.8\">&sect;3.4.8</a>;\nfor a description of the terminals\nName, Numeral,\nand LiteralString, see <a href=\"#3.1\">&sect;3.1</a>.)\n\n\n\n\n<pre>\n\n\tchunk ::= block\n\n\tblock ::= {stat} [retstat]\n\n\tstat ::=  &lsquo;<b>;</b>&rsquo; | \n\t\t varlist &lsquo;<b>=</b>&rsquo; explist | \n\t\t functioncall | \n\t\t label | \n\t\t <b>break</b> | \n\t\t <b>goto</b> Name | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name &lsquo;<b>=</b>&rsquo; exp &lsquo;<b>,</b>&rsquo; exp [&lsquo;<b>,</b>&rsquo; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> attnamelist [&lsquo;<b>=</b>&rsquo; explist] \n\n\tattnamelist ::=  Name attrib {&lsquo;<b>,</b>&rsquo; Name attrib}\n\n\tattrib ::= [&lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo;]\n\n\tretstat ::= <b>return</b> [explist] [&lsquo;<b>;</b>&rsquo;]\n\n\tlabel ::= &lsquo;<b>::</b>&rsquo; Name &lsquo;<b>::</b>&rsquo;\n\n\tfuncname ::= Name {&lsquo;<b>.</b>&rsquo; Name} [&lsquo;<b>:</b>&rsquo; Name]\n\n\tvarlist ::= var {&lsquo;<b>,</b>&rsquo; var}\n\n\tvar ::=  Name | prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; | prefixexp &lsquo;<b>.</b>&rsquo; Name \n\n\tnamelist ::= Name {&lsquo;<b>,</b>&rsquo; Name}\n\n\texplist ::= exp {&lsquo;<b>,</b>&rsquo; exp}\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Numeral | LiteralString | &lsquo;<b>...</b>&rsquo; | functiondef | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | &lsquo;<b>(</b>&rsquo; exp &lsquo;<b>)</b>&rsquo;\n\n\tfunctioncall ::=  prefixexp args | prefixexp &lsquo;<b>:</b>&rsquo; Name args \n\n\targs ::=  &lsquo;<b>(</b>&rsquo; [explist] &lsquo;<b>)</b>&rsquo; | tableconstructor | LiteralString \n\n\tfunctiondef ::= <b>function</b> funcbody\n\n\tfuncbody ::= &lsquo;<b>(</b>&rsquo; [parlist] &lsquo;<b>)</b>&rsquo; block <b>end</b>\n\n\tparlist ::= namelist [&lsquo;<b>,</b>&rsquo; &lsquo;<b>...</b>&rsquo;] | &lsquo;<b>...</b>&rsquo;\n\n\ttableconstructor ::= &lsquo;<b>{</b>&rsquo; [fieldlist] &lsquo;<b>}</b>&rsquo;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; &lsquo;<b>=</b>&rsquo; exp | Name &lsquo;<b>=</b>&rsquo; exp | exp\n\n\tfieldsep ::= &lsquo;<b>,</b>&rsquo; | &lsquo;<b>;</b>&rsquo;\n\n\tbinop ::=  &lsquo;<b>+</b>&rsquo; | &lsquo;<b>-</b>&rsquo; | &lsquo;<b>*</b>&rsquo; | &lsquo;<b>/</b>&rsquo; | &lsquo;<b>//</b>&rsquo; | &lsquo;<b>^</b>&rsquo; | &lsquo;<b>%</b>&rsquo; | \n\t\t &lsquo;<b>&amp;</b>&rsquo; | &lsquo;<b>~</b>&rsquo; | &lsquo;<b>|</b>&rsquo; | &lsquo;<b>&gt;&gt;</b>&rsquo; | &lsquo;<b>&lt;&lt;</b>&rsquo; | &lsquo;<b>..</b>&rsquo; | \n\t\t &lsquo;<b>&lt;</b>&rsquo; | &lsquo;<b>&lt;=</b>&rsquo; | &lsquo;<b>&gt;</b>&rsquo; | &lsquo;<b>&gt;=</b>&rsquo; | &lsquo;<b>==</b>&rsquo; | &lsquo;<b>~=</b>&rsquo; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= &lsquo;<b>-</b>&rsquo; | <b>not</b> | &lsquo;<b>#</b>&rsquo; | &lsquo;<b>~</b>&rsquo;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n<P CLASS=\"footer\">\nLast update:\nWed Sep 30 09:46:30 UTC 2020\n</P>\n<!--\nLast change: revised for Lua 5.4.1\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "build/lua-5.4.1/doc/readme.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.4 readme</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<STYLE TYPE=\"text/css\">\nblockquote, .display {\n\tborder: solid #a0a0a0 2px ;\n\tborder-radius: 8px ;\n\tpadding: 1em ;\n\tmargin: 0px ;\n}\n\n.display {\n\tword-spacing: 0.25em ;\n}\n\ndl.display dd {\n\tpadding-bottom: 0.2em ;\n}\n\ntt, kbd, code {\n\tfont-size: 12pt ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\"></A>\nWelcome to Lua 5.4\n</H1>\n\n<DIV CLASS=\"menubar\">\n<A HREF=\"#about\">about</A>\n&middot;\n<A HREF=\"#install\">installation</A>\n&middot;\n<A HREF=\"#changes\">changes</A>\n&middot;\n<A HREF=\"#license\">license</A>\n&middot;\n<A HREF=\"contents.html\">reference manual</A>\n</DIV>\n\n<H2><A NAME=\"about\">About Lua</A></H2>\n<P>\nLua is a powerful, efficient, lightweight, embeddable scripting language\ndeveloped by a\n<A HREF=\"http://www.lua.org/authors.html\">team</A>\nat\n<A HREF=\"http://www.puc-rio.br/\">PUC-Rio</A>,\nthe Pontifical Catholic University of Rio de Janeiro in Brazil.\nLua is\n<A HREF=\"#license\">free software</A>\nused in\n<A HREF=\"http://www.lua.org/uses.html\">many products and projects</A>\naround the world.\n\n<P>\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\nprovides complete information\nabout Lua,\nincluding\nan\n<A HREF=\"http://www.lua.org/about.html\">executive summary</A>\nand\nupdated\n<A HREF=\"http://www.lua.org/docs.html\">documentation</A>,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.4/\">reference manual</A>,\nwhich may differ slightly from the\n<A HREF=\"contents.html\">local copy</A>\ndistributed in this package.\n\n<H2><A NAME=\"install\">Installing Lua</A></H2>\n<P>\nLua is distributed in\n<A HREF=\"http://www.lua.org/ftp/\">source</A>\nform.\nYou need to build it before using it.\nBuilding Lua should be straightforward\nbecause\nLua is implemented in pure ANSI C and compiles unmodified in all known\nplatforms that have an ANSI C compiler.\nLua also compiles unmodified as C++.\nThe instructions given below for building Lua are for Unix-like platforms,\nsuch as Linux and Mac OS X.\nSee also\n<A HREF=\"#other\">instructions for other systems</A>\nand\n<A HREF=\"#customization\">customization options</A>.\n\n<P>\nIf you don't have the time or the inclination to compile Lua yourself,\nget a binary from\n<A HREF=\"http://lua-users.org/wiki/LuaBinaries\">LuaBinaries</A>.\nTry also\n<A HREF=\"http://luadist.org/\">LuaDist</A>,\na multi-platform distribution of Lua that includes batteries.\n\n<H3>Building Lua</H3>\n<P>\nIn most common Unix-like platforms, simply do \"<KBD>make</KBD>\".\nHere are the details.\n\n<OL>\n<LI>\nOpen a terminal window and move to\nthe top-level directory, which is named <TT>lua-5.4.1</TT>.\nThe <TT>Makefile</TT> there controls both the build process and the installation process.\n<P>\n<LI>\n  Do \"<KBD>make</KBD>\". The <TT>Makefile</TT> will guess your platform and build Lua for it.\n<P>\n<LI>\n  If the guess failed, do \"<KBD>make help</KBD>\" and see if your platform is listed.\n  The platforms currently supported are:\n<P>\n<P CLASS=\"display\">\n   guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris\n</P>\n<P>\n  If your platform is listed, just do \"<KBD>make xxx</KBD>\", where xxx\n  is your platform name.\n<P>\n  If your platform is not listed, try the closest one or posix, generic,\n  c89, in this order.\n<P>\n<LI>\nThe compilation takes only a few moments\nand produces three files in the <TT>src</TT> directory:\nlua (the interpreter),\nluac (the compiler),\nand liblua.a (the library).\n<P>\n<LI>\n  To check that Lua has been built correctly, do \"<KBD>make test</KBD>\"\n  after building Lua. This will run the interpreter and print its version.\n</OL>\n<P>\nIf you're running Linux, try \"<KBD>make linux-readline</KBD>\" to build the interactive Lua interpreter with handy line-editing and history capabilities.\nIf you get compilation errors,\nmake sure you have installed the <TT>readline</TT> development package\n(which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).\nIf you get link errors after that,\nthen try \"<KBD>make linux-readline MYLIBS=-ltermcap</KBD>\".\n\n<H3>Installing Lua</H3>\n<P>\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"<KBD>make install</KBD>\". The official\n  place and the way to install files are defined in the <TT>Makefile</TT>. You'll\n  probably need the right permissions to install files, and so may need to do \"<KBD>sudo make install</KBD>\".\n\n<P>\n  To build and install Lua in one step, do \"<KBD>make all install</KBD>\",\n  or \"<KBD>make xxx install</KBD>\",\n  where xxx is your platform name.\n\n<P>\n  To install Lua locally after building it, do \"<KBD>make local</KBD>\".\n  This will create a directory <TT>install</TT> with subdirectories\n  <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, <TT>share</TT>,\n  and install Lua as listed below.\n\n  To install Lua locally, but in some other directory, do\n  \"<KBD>make install INSTALL_TOP=xxx</KBD>\", where xxx is your chosen directory.\n  The installation starts in the <TT>src</TT> and <TT>doc</TT> directories,\n  so take care if <TT>INSTALL_TOP</TT> is not an absolute path.\n\n<DL CLASS=\"display\">\n<DT>\n    bin:\n<DD>\n    lua luac\n<DT>\n    include:\n<DD>\n    lua.h luaconf.h lualib.h lauxlib.h lua.hpp\n<DT>\n    lib:\n<DD>\n    liblua.a\n<DT>\n    man/man1:\n<DD>\n    lua.1 luac.1\n</DL>\n\n<P>\n  These are the only directories you need for development.\n  If you only want to run Lua programs,\n  you only need the files in <TT>bin</TT> and <TT>man</TT>.\n  The files in <TT>include</TT> and <TT>lib</TT> are needed for\n  embedding Lua in C or C++ programs.\n\n<H3><A NAME=\"customization\">Customization</A></H3>\n<P>\n  Three kinds of things can be customized by editing a file:\n<UL>\n    <LI> Where and how to install Lua &mdash; edit <TT>Makefile</TT>.\n    <LI> How to build Lua &mdash; edit <TT>src/Makefile</TT>.\n    <LI> Lua features &mdash; edit <TT>src/luaconf.h</TT>.\n</UL>\n\n<P>\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables in the command line when invoking make.\n  Nevertheless, it's probably best to edit and save the Makefiles to\n  record the changes you've made.\n\n<P>\n  On the other hand, if you need to customize some Lua features, you'll need\n  to edit <TT>src/luaconf.h</TT> before building and installing Lua.\n  The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n  Further customization is available to experts by editing the Lua sources.\n\n<H3><A NAME=\"other\">Building Lua on other systems</A></H3>\n<P>\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n<DL CLASS=\"display\">\n<DT>\nlibrary:\n<DD>\nlapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c\nlauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c lmathlib.c loadlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c linit.c\n<DT>\ninterpreter:\n<DD>\n  library, lua.c\n<DT>\ncompiler:\n<DD>\n  library, luac.c\n</DL>\n\n<P>\n  To use Lua as a library in your own programs, you'll need to know how to\n  create and use libraries with your compiler. Moreover, to dynamically load\n  C libraries for Lua, you'll need to know how to create dynamic libraries\n  and you'll need to make sure that the Lua API functions are accessible to\n  those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library\n  into each dynamic library. For Unix, we recommend that the Lua library\n  be linked statically into the host program and its symbols exported for\n  dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter.\n  For Windows, we recommend that the Lua library be a DLL.\n  In all cases, the compiler luac should be linked statically.\n\n<P>\n  As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize\n  some features before building Lua.\n\n<H2><A NAME=\"changes\">Changes since Lua 5.3</A></H2>\n<P>\nHere are the main changes introduced in Lua 5.4.\nThe\n<A HREF=\"contents.html\">reference manual</A>\nlists the\n<A HREF=\"manual.html#8\">incompatibilities</A> that had to be introduced.\n\n<H3>Main changes</H3>\n<UL>\n<LI> new generational mode for garbage collection\n<LI> to-be-closed variables\n<LI> const variables\n<LI> userdata can have multiple user values\n<LI> new implementation for math.random\n<LI> warning system\n<LI> debug information about function arguments and returns\n<LI> new semantics for the integer 'for' loop\n<LI> optional 'init' argument to 'string.gmatch'\n<LI> new functions 'lua_resetthread' and 'coroutine.close'\n<LI> string-to-number coercions moved to the string library\n<LI> allocation function allowed to fail when shrinking a memory block\n<LI> new format '%p' in 'string.format'\n<LI> utf8 library accepts codepoints up to 2^31\n</UL>\n\n<H2><A NAME=\"license\">License</A></H2>\n<P>\n<A HREF=\"http://www.opensource.org/docs/definition.php\">\n<IMG SRC=\"osi-certified-72x60.png\" ALIGN=\"right\" ALT=\"[osi certified]\" STYLE=\"padding-left: 30px ;\">\n</A>\nLua is free software distributed under the terms of the\n<A HREF=\"http://www.opensource.org/licenses/mit-license.html\">MIT license</A>\nreproduced below;\nit may be used for any purpose, including commercial purposes,\nat absolutely no cost without having to ask us.\n\nThe only requirement is that if you do use Lua,\nthen you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.\n\nFor details, see\n<A HREF=\"http://www.lua.org/license.html\">this</A>.\n\n<BLOCKQUOTE STYLE=\"padding-bottom: 0em\">\nCopyright &copy; 1994&ndash;2020 Lua.org, PUC-Rio.\n\n<P>\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n<P>\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n<P>\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n</BLOCKQUOTE>\n<P>\n\n<P CLASS=\"footer\">\nLast update:\nWed Sep 30 09:55:45 UTC 2020\n</P>\n<!--\nLast change: revised for Lua 5.4.1\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "build/lua-5.4.1/src/Makefile",
    "content": "# Makefile for building Lua\n# See ../doc/readme.html for installation and customization instructions.\n\n# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================\n\n# Your platform. See PLATS for possible values.\nPLAT= guess\n\nCC= gcc -std=gnu99\nCFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)\nLDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)\nLIBS= -lm $(SYSLIBS) $(MYLIBS)\n\nAR= ar rcu\nRANLIB= ranlib\nRM= rm -f\nUNAME= uname\n\nSYSCFLAGS=\nSYSLDFLAGS=\nSYSLIBS=\n\nMYCFLAGS=\nMYLDFLAGS=\nMYLIBS=\nMYOBJS=\n\n# Special flags for compiler modules; -Os reduces code size.\nCMCFLAGS= -Os\n\n# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======\n\nPLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris\n\nLUA_A=\tliblua.a\nCORE_O=\tlapi.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\nLIB_O=\tlauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o\nBASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)\n\nLUA_T=\tlua\nLUA_O=\tlua.o\n\nLUAC_T=\tluac\nLUAC_O=\tluac.o\n\nALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)\nALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)\nALL_A= $(LUA_A)\n\n# Targets start here.\ndefault: $(PLAT)\n\nall:\t$(ALL_T)\n\no:\t$(ALL_O)\n\na:\t$(ALL_A)\n\n$(LUA_A): $(BASE_O)\n\t$(AR) $@ $(BASE_O)\n\t$(RANLIB) $@\n\n$(LUA_T): $(LUA_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)\n\n$(LUAC_T): $(LUAC_O) $(LUA_A)\n\t$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)\n\ntest:\n\t./lua -v\n\nclean:\n\t$(RM) $(ALL_T) $(ALL_O)\n\ndepend:\n\t@$(CC) $(CFLAGS) -MM l*.c\n\necho:\n\t@echo \"PLAT= $(PLAT)\"\n\t@echo \"CC= $(CC)\"\n\t@echo \"CFLAGS= $(CFLAGS)\"\n\t@echo \"LDFLAGS= $(SYSLDFLAGS)\"\n\t@echo \"LIBS= $(LIBS)\"\n\t@echo \"AR= $(AR)\"\n\t@echo \"RANLIB= $(RANLIB)\"\n\t@echo \"RM= $(RM)\"\n\t@echo \"UNAME= $(UNAME)\"\n\n# Convenience targets for popular platforms.\nALL= all\n\nhelp:\n\t@echo \"Do 'make PLATFORM' where PLATFORM is one of these:\"\n\t@echo \"   $(PLATS)\"\n\t@echo \"See doc/readme.html for complete instructions.\"\n\nguess:\n\t@echo Guessing `$(UNAME)`\n\t@$(MAKE) `$(UNAME)`\n\nAIX aix:\n\t$(MAKE) $(ALL) CC=\"xlc\" CFLAGS=\"-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-ldl\" SYSLDFLAGS=\"-brtl -bexpall\"\n\nbsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN\" SYSLIBS=\"-Wl,-E\"\n\nc89:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_C89\" CC=\"gcc -std=c89\"\n\t@echo ''\n\t@echo '*** C89 does not guarantee 64-bit integers for Lua.'\n\t@echo ''\n\nFreeBSD NetBSD OpenBSD freebsd:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit\" SYSLIBS=\"-Wl,-E -ledit\" CC=\"cc\"\n\ngeneric: $(ALL)\n\nLinux linux:\tlinux-noreadline\n\nlinux-noreadline:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX\" SYSLIBS=\"-Wl,-E -ldl\"\n\nlinux-readline:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_LINUX -DLUA_USE_READLINE\" SYSLIBS=\"-Wl,-E -ldl -lreadline\"\n\nDarwin macos macosx:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_MACOSX -DLUA_USE_READLINE\" SYSLIBS=\"-lreadline\"\n\nmingw:\n\t$(MAKE) \"LUA_A=lua54.dll\" \"LUA_T=lua.exe\" \\\n\t\"AR=$(CC) -shared -o\" \"RANLIB=strip --strip-unneeded\" \\\n\t\"SYSCFLAGS=-DLUA_BUILD_AS_DLL\" \"SYSLIBS=\" \"SYSLDFLAGS=-s\" lua.exe\n\t$(MAKE) \"LUAC_T=luac.exe\" luac.exe\n\nposix:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX\"\n\nSunOS solaris:\n\t$(MAKE) $(ALL) SYSCFLAGS=\"-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT\" SYSLIBS=\"-ldl\"\n\n# Targets that do not create files (not all makes understand .PHONY).\n.PHONY: all $(PLATS) help test clean default o a depend echo\n\n# Compiler modules may use special flags.\nllex.o:\n\t$(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c\n\nlparser.o:\n\t$(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c\n\nlcode.o:\n\t$(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c\n\n# DO NOT DELETE\n\nlapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \\\n ltable.h lundump.h lvm.h\nlauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h\nlbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lgc.h lstring.h ltable.h lvm.h\nlcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h\nldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \\\n ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h\nldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \\\n lparser.h lstring.h ltable.h lundump.h lvm.h\nldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \\\n ltm.h lzio.h lmem.h lundump.h\nlfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h\nlgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h\nlinit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h\nliolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nllex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \\\n lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \\\n lstring.h ltable.h\nlmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h\nloadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \\\n ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \\\n lvm.h\nlopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h\nloslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \\\n llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \\\n ldo.h lfunc.h lstring.h lgc.h ltable.h\nlstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \\\n lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \\\n lstring.h ltable.h\nlstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h\nlstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h\nltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h\nlua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nluac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h lopcodes.h lopnames.h lundump.h\nlundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \\\n lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \\\n lundump.h\nlutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h\nlvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \\\n llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \\\n ltable.h lvm.h ljumptab.h\nlzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \\\n lobject.h ltm.h lzio.h\n\n# (end of Makefile)\n"
  },
  {
    "path": "build/lua-5.4.1/src/lapi.c",
    "content": "/*\n** $Id: lapi.c $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stdarg.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$LuaVersion: \" LUA_COPYRIGHT \" $\"\n  \"$LuaAuthors: \" LUA_AUTHORS \" $\";\n\n\n\n/*\n** Test for a valid index.\n** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed.\n** However, it covers the most common cases in a faster way.\n*/\n#define isvalid(L, o)\t(!ttisnil(o) || o != &G(L)->nilvalue)\n\n\n/* test for pseudo index */\n#define ispseudo(i)\t\t((i) <= LUA_REGISTRYINDEX)\n\n/* test for upvalue */\n#define isupvalue(i)\t\t((i) < LUA_REGISTRYINDEX)\n\n\nstatic TValue *index2value (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    StkId o = ci->func + idx;\n    api_check(L, idx <= L->ci->top - (ci->func + 1), \"unacceptable index\");\n    if (o >= L->top) return &G(L)->nilvalue;\n    else return s2v(o);\n  }\n  else if (!ispseudo(idx)) {  /* negative index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    return s2v(L->top + idx);\n  }\n  else if (idx == LUA_REGISTRYINDEX)\n    return &G(L)->l_registry;\n  else {  /* upvalues */\n    idx = LUA_REGISTRYINDEX - idx;\n    api_check(L, idx <= MAXUPVAL + 1, \"upvalue index too large\");\n    if (ttislcf(s2v(ci->func)))  /* light C function? */\n      return &G(L)->nilvalue;  /* it has no upvalues */\n    else {\n      CClosure *func = clCvalue(s2v(ci->func));\n      return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : &G(L)->nilvalue;\n    }\n  }\n}\n\n\nstatic StkId index2stack (lua_State *L, int idx) {\n  CallInfo *ci = L->ci;\n  if (idx > 0) {\n    StkId o = ci->func + idx;\n    api_check(L, o < L->top, \"unacceptable index\");\n    return o;\n  }\n  else {    /* non-positive index */\n    api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), \"invalid index\");\n    api_check(L, !ispseudo(idx), \"invalid index\");\n    return L->top + idx;\n  }\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int n) {\n  int res;\n  CallInfo *ci;\n  lua_lock(L);\n  ci = L->ci;\n  api_check(L, n >= 0, \"negative 'n'\");\n  if (L->stack_last - L->top > n)  /* stack large enough? */\n    res = 1;  /* yes; check is OK */\n  else {  /* no; need to grow stack */\n    int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;\n    if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */\n      res = 0;  /* no */\n    else  /* try to grow stack */\n      res = luaD_growstack(L, n, 0);\n  }\n  if (res && ci->top < L->top + n)\n    ci->top = L->top + n;  /* adjust frame top */\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  int i;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to), \"moving among independent states\");\n  api_check(from, to->ci->top - to->top >= n, \"stack overflow\");\n  from->top -= n;\n  for (i = 0; i < n; i++) {\n    setobjs2s(to, to->top, from->top + i);\n    to->top++;  /* stack already checked by previous 'api_check' */\n  }\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API lua_Number lua_version (lua_State *L) {\n  UNUSED(L);\n  return LUA_VERSION_NUM;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\n/*\n** convert an acceptable stack index into an absolute index\n*/\nLUA_API int lua_absindex (lua_State *L, int idx) {\n  return (idx > 0 || ispseudo(idx))\n         ? idx\n         : cast_int(L->top - L->ci->func) + idx;\n}\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - (L->ci->func + 1));\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  CallInfo *ci;\n  StkId func;\n  ptrdiff_t diff;  /* difference for new top */\n  lua_lock(L);\n  ci = L->ci;\n  func = ci->func;\n  if (idx >= 0) {\n    api_check(L, idx <= ci->top - (func + 1), \"new top too large\");\n    diff = ((func + 1) + idx) - L->top;\n    for (; diff > 0; diff--)\n      setnilvalue(s2v(L->top++));  /* clear new slots */\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - (func + 1)), \"invalid new top\");\n    diff = idx + 1;  /* will \"subtract\" index (as it is negative) */\n  }\n  if (diff < 0 && hastocloseCfunc(ci->nresults))\n    luaF_close(L, L->top + diff, LUA_OK);\n  L->top += diff;  /* correct top only after closing any upvalue */\n  lua_unlock(L);\n}\n\n\n/*\n** Reverse the stack segment from 'from' to 'to'\n** (auxiliary to 'lua_rotate')\n** Note that we move(copy) only the value inside the stack.\n** (We do not move additional fields that may exist.)\n*/\nstatic void reverse (lua_State *L, StkId from, StkId to) {\n  for (; from < to; from++, to--) {\n    TValue temp;\n    setobj(L, &temp, s2v(from));\n    setobjs2s(L, from, to);\n    setobj2s(L, to, &temp);\n  }\n}\n\n\n/*\n** Let x = AB, where A is a prefix of length 'n'. Then,\n** rotate x n == BA. But BA == (A^r . B^r)^r.\n*/\nLUA_API void lua_rotate (lua_State *L, int idx, int n) {\n  StkId p, t, m;\n  lua_lock(L);\n  t = L->top - 1;  /* end of stack segment being rotated */\n  p = index2stack(L, idx);  /* start of segment */\n  api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), \"invalid 'n'\");\n  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */\n  reverse(L, p, m);  /* reverse the prefix with length 'n' */\n  reverse(L, m + 1, t);  /* reverse the suffix */\n  reverse(L, p, t);  /* reverse the entire segment */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {\n  TValue *fr, *to;\n  lua_lock(L);\n  fr = index2value(L, fromidx);\n  to = index2value(L, toidx);\n  api_check(L, isvalid(L, to), \"invalid index\");\n  setobj(L, to, fr);\n  if (isupvalue(toidx))  /* function upvalue? */\n    luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr);\n  /* LUA_REGISTRYINDEX does not need gc barrier\n     (collector revisits it before finishing collection) */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2value(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return (isvalid(L, o) ? ttype(o) : LUA_TNONE);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  api_check(L, LUA_TNONE <= t && t < LUA_NUMTYPES, \"invalid type\");\n  return ttypename(t);\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return (ttislcf(o) || (ttisCclosure(o)));\n}\n\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return ttisinteger(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  lua_Number n;\n  const TValue *o = index2value(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return (ttisstring(o) || cvt2str(o));\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return (ttisfulluserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  const TValue *o1 = index2value(L, index1);\n  const TValue *o2 = index2value(L, index2);\n  return (isvalid(L, o1) && isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0;\n}\n\n\nLUA_API void lua_arith (lua_State *L, int op) {\n  lua_lock(L);\n  if (op != LUA_OPUNM && op != LUA_OPBNOT)\n    api_checknelems(L, 2);  /* all other operations expect two operands */\n  else {  /* for unary operations, add fake 2nd operand */\n    api_checknelems(L, 1);\n    setobjs2s(L, L->top, L->top - 1);\n    api_incr_top(L);\n  }\n  /* first operand at top - 2, second at top - 1; result go to top - 2 */\n  luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2);\n  L->top--;  /* remove second operand */\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {\n  const TValue *o1;\n  const TValue *o2;\n  int i = 0;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2value(L, index1);\n  o2 = index2value(L, index2);\n  if (isvalid(L, o1) && isvalid(L, o2)) {\n    switch (op) {\n      case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;\n      case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;\n      case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;\n      default: api_check(L, 0, \"invalid option\");\n    }\n  }\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {\n  size_t sz = luaO_str2num(s, s2v(L->top));\n  if (sz != 0)\n    api_incr_top(L);\n  return sz;\n}\n\n\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {\n  lua_Number n = 0;\n  const TValue *o = index2value(L, idx);\n  int isnum = tonumber(o, &n);\n  if (pisnum)\n    *pisnum = isnum;\n  return n;\n}\n\n\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {\n  lua_Integer res = 0;\n  const TValue *o = index2value(L, idx);\n  int isnum = tointeger(o, &res);\n  if (pisnum)\n    *pisnum = isnum;\n  return res;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  TValue *o;\n  lua_lock(L);\n  o = index2value(L, idx);\n  if (!ttisstring(o)) {\n    if (!cvt2str(o)) {  /* not convertible? */\n      if (len != NULL) *len = 0;\n      lua_unlock(L);\n      return NULL;\n    }\n    luaO_tostring(L, o);\n    luaC_checkGC(L);\n    o = index2value(L, idx);  /* previous call may reallocate the stack */\n  }\n  if (len != NULL)\n    *len = vslen(o);\n  lua_unlock(L);\n  return svalue(o);\n}\n\n\nLUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  switch (ttypetag(o)) {\n    case LUA_VSHRSTR: return tsvalue(o)->shrlen;\n    case LUA_VLNGSTR: return tsvalue(o)->u.lnglen;\n    case LUA_VUSERDATA: return uvalue(o)->len;\n    case LUA_VTABLE: return luaH_getn(hvalue(o));\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  if (ttislcf(o)) return fvalue(o);\n  else if (ttisCclosure(o))\n    return clCvalue(o)->f;\n  else return NULL;  /* not a C function */\n}\n\n\nstatic void *touserdata (const TValue *o) {\n  switch (ttype(o)) {\n    case LUA_TUSERDATA: return getudatamem(uvalue(o));\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return touserdata(o);\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\n/*\n** Returns a pointer to the internal representation of an object.\n** Note that ANSI C does not allow the conversion of a pointer to\n** function to a 'void*', so the conversion here goes through\n** a 'size_t'. (As the returned pointer is only informative, this\n** conversion should not be a problem.)\n*/\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  const TValue *o = index2value(L, idx);\n  switch (ttypetag(o)) {\n    case LUA_VLCF: return cast_voidp(cast_sizet(fvalue(o)));\n    case LUA_VUSERDATA: case LUA_VLIGHTUSERDATA:\n      return touserdata(o);\n    default: {\n      if (iscollectable(o))\n        return gcvalue(o);\n      else\n        return NULL;\n    }\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(s2v(L->top));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setfltvalue(s2v(L->top), n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setivalue(s2v(L->top), n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** Pushes on the stack a string with given length. Avoid using 's' when\n** 'len' == 0 (as 's' can be NULL in that case), due to later use of\n** 'memcmp' and 'memcpy'.\n*/\nLUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  TString *ts;\n  lua_lock(L);\n  ts = (len == 0) ? luaS_new(L, \"\") : luaS_newlstr(L, s, len);\n  setsvalue2s(L, L->top, ts);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getstr(ts);\n}\n\n\nLUA_API const char *lua_pushstring (lua_State *L, const char *s) {\n  lua_lock(L);\n  if (s == NULL)\n    setnilvalue(s2v(L->top));\n  else {\n    TString *ts;\n    ts = luaS_new(L, s);\n    setsvalue2s(L, L->top, ts);\n    s = getstr(ts);  /* internal copy's address */\n  }\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return s;\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  lua_lock(L);\n  if (n == 0) {\n    setfvalue(s2v(L->top), fn);\n    api_incr_top(L);\n  }\n  else {\n    CClosure *cl;\n    api_checknelems(L, n);\n    api_check(L, n <= MAXUPVAL, \"upvalue index too large\");\n    cl = luaF_newCclosure(L, n);\n    cl->f = fn;\n    L->top -= n;\n    while (n--) {\n      setobj2n(L, &cl->upvalue[n], s2v(L->top + n));\n      /* does not need barrier because closure is white */\n      lua_assert(iswhite(cl));\n    }\n    setclCvalue(L, s2v(L->top), cl);\n    api_incr_top(L);\n    luaC_checkGC(L);\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  if (b)\n    setbtvalue(s2v(L->top));\n  else\n    setbfvalue(s2v(L->top));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, void *p) {\n  lua_lock(L);\n  setpvalue(s2v(L->top), p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, s2v(L->top), L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nstatic int auxgetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    setobj2s(L, L->top, slot);\n    api_incr_top(L);\n  }\n  else {\n    setsvalue2s(L, L->top, str);\n    api_incr_top(L);\n    luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);\n  }\n  lua_unlock(L);\n  return ttype(s2v(L->top - 1));\n}\n\n\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n  Table *reg;\n  lua_lock(L);\n  reg = hvalue(&G(L)->l_registry);\n  return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API int lua_gettable (lua_State *L, int idx) {\n  const TValue *slot;\n  TValue *t;\n  lua_lock(L);\n  t = index2value(L, idx);\n  if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) {\n    setobj2s(L, L->top - 1, slot);\n  }\n  else\n    luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);\n  lua_unlock(L);\n  return ttype(s2v(L->top - 1));\n}\n\n\nLUA_API int lua_getfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);\n  return auxgetstr(L, index2value(L, idx), k);\n}\n\n\nLUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {\n  TValue *t;\n  const TValue *slot;\n  lua_lock(L);\n  t = index2value(L, idx);\n  if (luaV_fastgeti(L, t, n, slot)) {\n    setobj2s(L, L->top, slot);\n  }\n  else {\n    TValue aux;\n    setivalue(&aux, n);\n    luaV_finishget(L, t, &aux, L->top, slot);\n  }\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttype(s2v(L->top - 1));\n}\n\n\nstatic int finishrawget (lua_State *L, const TValue *val) {\n  if (isempty(val))  /* avoid copying empty items to the stack */\n    setnilvalue(s2v(L->top));\n  else\n    setobj2s(L, L->top, val);\n  api_incr_top(L);\n  lua_unlock(L);\n  return ttype(s2v(L->top - 1));\n}\n\n\nstatic Table *gettable (lua_State *L, int idx) {\n  TValue *t = index2value(L, idx);\n  api_check(L, ttistable(t), \"table expected\");\n  return hvalue(t);\n}\n\n\nLUA_API int lua_rawget (lua_State *L, int idx) {\n  Table *t;\n  const TValue *val;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = gettable(L, idx);\n  val = luaH_get(t, s2v(L->top - 1));\n  L->top--;  /* remove key */\n  return finishrawget(L, val);\n}\n\n\nLUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {\n  Table *t;\n  lua_lock(L);\n  t = gettable(L, idx);\n  return finishrawget(L, luaH_getint(t, n));\n}\n\n\nLUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {\n  Table *t;\n  TValue k;\n  lua_lock(L);\n  t = gettable(L, idx);\n  setpvalue(&k, cast_voidp(p));\n  return finishrawget(L, luaH_get(t, &k));\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  Table *t;\n  lua_lock(L);\n  t = luaH_new(L);\n  sethvalue2s(L, L->top, t);\n  api_incr_top(L);\n  if (narray > 0 || nrec > 0)\n    luaH_resize(L, t, narray, nrec);\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt;\n  int res = 0;\n  lua_lock(L);\n  obj = index2value(L, objindex);\n  switch (ttype(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(obj)];\n      break;\n  }\n  if (mt != NULL) {\n    sethvalue2s(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {\n  TValue *o;\n  int t;\n  lua_lock(L);\n  o = index2value(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  if (n <= 0 || n > uvalue(o)->nuvalue) {\n    setnilvalue(s2v(L->top));\n    t = LUA_TNONE;\n  }\n  else {\n    setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv);\n    t = ttype(s2v(L->top));\n  }\n  api_incr_top(L);\n  lua_unlock(L);\n  return t;\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n/*\n** t[k] = value at the top of the stack (where 'k' is a string)\n*/\nstatic void auxsetstr (lua_State *L, const TValue *t, const char *k) {\n  const TValue *slot;\n  TString *str = luaS_new(L, k);\n  api_checknelems(L, 1);\n  if (luaV_fastget(L, t, str, slot, luaH_getstr)) {\n    luaV_finishfastset(L, t, slot, s2v(L->top - 1));\n    L->top--;  /* pop value */\n  }\n  else {\n    setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */\n    api_incr_top(L);\n    luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot);\n    L->top -= 2;  /* pop value and key */\n  }\n  lua_unlock(L);  /* lock done by caller */\n}\n\n\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n  Table *reg;\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  reg = hvalue(&G(L)->l_registry);\n  auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);\n}\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  TValue *t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2value(L, idx);\n  if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) {\n    luaV_finishfastset(L, t, slot, s2v(L->top - 1));\n  }\n  else\n    luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  lua_lock(L);  /* unlock done in 'auxsetstr' */\n  auxsetstr(L, index2value(L, idx), k);\n}\n\n\nLUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {\n  TValue *t;\n  const TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2value(L, idx);\n  if (luaV_fastgeti(L, t, n, slot)) {\n    luaV_finishfastset(L, t, slot, s2v(L->top - 1));\n  }\n  else {\n    TValue aux;\n    setivalue(&aux, n);\n    luaV_finishset(L, t, &aux, s2v(L->top - 1), slot);\n  }\n  L->top--;  /* pop value */\n  lua_unlock(L);\n}\n\n\nstatic void aux_rawset (lua_State *L, int idx, TValue *key, int n) {\n  Table *t;\n  TValue *slot;\n  lua_lock(L);\n  api_checknelems(L, n);\n  t = gettable(L, idx);\n  slot = luaH_set(L, t, key);\n  setobj2t(L, slot, s2v(L->top - 1));\n  invalidateTMcache(t);\n  luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));\n  L->top -= n;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  aux_rawset(L, idx, s2v(L->top - 2), 2);\n}\n\n\nLUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {\n  TValue k;\n  setpvalue(&k, cast_voidp(p));\n  aux_rawset(L, idx, &k, 1);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {\n  Table *t;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = gettable(L, idx);\n  luaH_setint(L, t, n, s2v(L->top - 1));\n  luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2value(L, objindex);\n  if (ttisnil(s2v(L->top - 1)))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(s2v(L->top - 1)), \"table expected\");\n    mt = hvalue(s2v(L->top - 1));\n  }\n  switch (ttype(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, gcvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt) {\n        luaC_objbarrier(L, uvalue(obj), mt);\n        luaC_checkfinalizer(L, gcvalue(obj), mt);\n      }\n      break;\n    }\n    default: {\n      G(L)->mt[ttype(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {\n  TValue *o;\n  int res;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2value(L, idx);\n  api_check(L, ttisfulluserdata(o), \"full userdata expected\");\n  if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue)))\n    res = 0;  /* 'n' not in [1, uvalue(o)->nuvalue] */\n  else {\n    setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1));\n    luaC_barrierback(L, gcvalue(o), s2v(L->top - 1));\n    res = 1;\n  }\n  L->top--;\n  lua_unlock(L);\n  return res;\n}\n\n\n/*\n** 'load' and 'call' functions (run Lua code)\n*/\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \\\n\t\"results from function overflow current stack size\")\n\n\nLUA_API void lua_callk (lua_State *L, int nargs, int nresults,\n                        lua_KContext ctx, lua_KFunction k) {\n  StkId func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  if (k != NULL && yieldable(L)) {  /* need to prepare continuation? */\n    L->ci->u.c.k = k;  /* save continuation */\n    L->ci->u.c.ctx = ctx;  /* save context */\n    luaD_call(L, func, nresults);  /* do the call */\n  }\n  else  /* no continuation or no yieldable */\n    luaD_callnoyield(L, func, nresults);  /* just do the call */\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to 'f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_callnoyield(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,\n                        lua_KContext ctx, lua_KFunction k) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_check(L, k == NULL || !isLua(L->ci),\n    \"cannot use continuations inside hooks\");\n  api_checknelems(L, nargs+1);\n  api_check(L, L->status == LUA_OK, \"cannot do calls on non-normal thread\");\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2stack(L, errfunc);\n    api_check(L, ttisfunction(s2v(o)), \"error handler must be a function\");\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  if (k == NULL || !yieldable(L)) {  /* no continuation or no yieldable? */\n    c.nresults = nresults;  /* do a 'conventional' protected call */\n    status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  }\n  else {  /* prepare continuation (call is already protected by 'resume') */\n    CallInfo *ci = L->ci;\n    ci->u.c.k = k;  /* save continuation */\n    ci->u.c.ctx = ctx;  /* save context */\n    /* save information for error recovery */\n    ci->u2.funcidx = cast_int(savestack(L, c.func));\n    ci->u.c.old_errfunc = L->errfunc;\n    L->errfunc = func;\n    setoah(ci->callstatus, L->allowhook);  /* save value of 'allowhook' */\n    ci->callstatus |= CIST_YPCALL;  /* function can do error recovery */\n    luaD_call(L, c.func, nresults);  /* do the call */\n    ci->callstatus &= ~CIST_YPCALL;\n    L->errfunc = ci->u.c.old_errfunc;\n    status = LUA_OK;  /* if it is here, there were no errors */\n  }\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname, const char *mode) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname, mode);\n  if (status == LUA_OK) {  /* no errors? */\n    LClosure *f = clLvalue(s2v(L->top - 1));  /* get newly created function */\n    if (f->nupvalues >= 1) {  /* does it have an upvalue? */\n      /* get global table from registry */\n      Table *reg = hvalue(&G(L)->l_registry);\n      const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);\n      /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */\n      setobj(L, f->upvals[0]->v, gt);\n      luaC_barrier(L, f->upvals[0], gt);\n    }\n  }\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = s2v(L->top - 1);\n  if (isLfunction(o))\n    status = luaU_dump(L, getproto(o), writer, data, strip);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\nLUA_API int lua_gc (lua_State *L, int what, ...) {\n  va_list argp;\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  va_start(argp, what);\n  switch (what) {\n    case LUA_GCSTOP: {\n      g->gcrunning = 0;\n      break;\n    }\n    case LUA_GCRESTART: {\n      luaE_setdebt(g, 0);\n      g->gcrunning = 1;\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L, 0);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(gettotalbytes(g) >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(gettotalbytes(g) & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      int data = va_arg(argp, int);\n      l_mem debt = 1;  /* =1 to signal that it did an actual step */\n      lu_byte oldrunning = g->gcrunning;\n      g->gcrunning = 1;  /* allow GC to run */\n      if (data == 0) {\n        luaE_setdebt(g, 0);  /* do a basic step */\n        luaC_step(L);\n      }\n      else {  /* add 'data' to total debt */\n        debt = cast(l_mem, data) * 1024 + g->GCdebt;\n        luaE_setdebt(g, debt);\n        luaC_checkGC(L);\n      }\n      g->gcrunning = oldrunning;  /* restore previous state */\n      if (debt > 0 && g->gcstate == GCSpause)  /* end of cycle? */\n        res = 1;  /* signal it */\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      int data = va_arg(argp, int);\n      res = getgcparam(g->gcpause);\n      setgcparam(g->gcpause, data);\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      int data = va_arg(argp, int);\n      res = getgcparam(g->gcstepmul);\n      setgcparam(g->gcstepmul, data);\n      break;\n    }\n    case LUA_GCISRUNNING: {\n      res = g->gcrunning;\n      break;\n    }\n    case LUA_GCGEN: {\n      int minormul = va_arg(argp, int);\n      int majormul = va_arg(argp, int);\n      res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;\n      if (minormul != 0)\n        g->genminormul = minormul;\n      if (majormul != 0)\n        setgcparam(g->genmajormul, majormul);\n      luaC_changemode(L, KGC_GEN);\n      break;\n    }\n    case LUA_GCINC: {\n      int pause = va_arg(argp, int);\n      int stepmul = va_arg(argp, int);\n      int stepsize = va_arg(argp, int);\n      res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;\n      if (pause != 0)\n        setgcparam(g->gcpause, pause);\n      if (stepmul != 0)\n        setgcparam(g->gcstepmul, stepmul);\n      if (stepsize != 0)\n        g->gcstepsize = stepsize;\n      luaC_changemode(L, KGC_INC);\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  va_end(argp);\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  TValue *errobj;\n  lua_lock(L);\n  errobj = s2v(L->top - 1);\n  api_checknelems(L, 1);\n  /* error object is the memory error message? */\n  if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg))\n    luaM_error(L);  /* raise a memory error */\n  else\n    luaG_errormsg(L);  /* raise a regular error */\n  /* code unreachable; will unlock when control actually leaves the kernel */\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  Table *t;\n  int more;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = gettable(L, idx);\n  more = luaH_next(L, t, L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_toclose (lua_State *L, int idx) {\n  int nresults;\n  StkId o;\n  lua_lock(L);\n  o = index2stack(L, idx);\n  nresults = L->ci->nresults;\n  api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o,\n               \"marked index below or equal new one\");\n  luaF_newtbcupval(L, o);  /* create new to-be-closed upvalue */\n  if (!hastocloseCfunc(nresults))  /* function not marked yet? */\n    L->ci->nresults = codeNresults(nresults);  /* mark it */\n  lua_assert(hastocloseCfunc(L->ci->nresults));\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n > 0)\n    luaV_concat(L, n);\n  else {  /* nothing to concatenate */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));  /* push empty string */\n    api_incr_top(L);\n  }\n  luaC_checkGC(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_len (lua_State *L, int idx) {\n  TValue *t;\n  lua_lock(L);\n  t = index2value(L, idx);\n  luaV_objlen(L, L->top, t);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nvoid lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) {\n  lua_lock(L);\n  G(L)->ud_warn = ud;\n  G(L)->warnf = f;\n  lua_unlock(L);\n}\n\n\nvoid lua_warning (lua_State *L, const char *msg, int tocont) {\n  lua_lock(L);\n  luaE_warning(L, msg, tocont);\n  lua_unlock(L);\n}\n\n\n\nLUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {\n  Udata *u;\n  lua_lock(L);\n  api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, \"invalid value\");\n  u = luaS_newudata(L, size, nuvalue);\n  setuvalue(L, s2v(L->top), u);\n  api_incr_top(L);\n  luaC_checkGC(L);\n  lua_unlock(L);\n  return getudatamem(u);\n}\n\n\n\nstatic const char *aux_upvalue (TValue *fi, int n, TValue **val,\n                                GCObject **owner) {\n  switch (ttypetag(fi)) {\n    case LUA_VCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      if (!(cast_uint(n) - 1u < cast_uint(f->nupvalues)))\n        return NULL;  /* 'n' not in [1, f->nupvalues] */\n      *val = &f->upvalue[n-1];\n      if (owner) *owner = obj2gco(f);\n      return \"\";\n    }\n    case LUA_VLCL: {  /* Lua closure */\n      LClosure *f = clLvalue(fi);\n      TString *name;\n      Proto *p = f->p;\n      if (!(cast_uint(n) - 1u  < cast_uint(p->sizeupvalues)))\n        return NULL;  /* 'n' not in [1, p->sizeupvalues] */\n      *val = f->upvals[n-1]->v;\n      if (owner) *owner = obj2gco(f->upvals[n - 1]);\n      name = p->upvalues[n-1].name;\n      return (name == NULL) ? \"(no name)\" : getstr(name);\n    }\n    default: return NULL;  /* not a closure */\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  lua_lock(L);\n  name = aux_upvalue(index2value(L, funcindex), n, &val, NULL);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val = NULL;  /* to avoid warnings */\n  GCObject *owner = NULL;  /* to avoid warnings */\n  TValue *fi;\n  lua_lock(L);\n  fi = index2value(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val, &owner);\n  if (name) {\n    L->top--;\n    setobj(L, val, s2v(L->top));\n    luaC_barrier(L, owner, val);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {\n  LClosure *f;\n  TValue *fi = index2value(L, fidx);\n  api_check(L, ttisLclosure(fi), \"Lua function expected\");\n  f = clLvalue(fi);\n  api_check(L, (1 <= n && n <= f->p->sizeupvalues), \"invalid upvalue index\");\n  if (pf) *pf = f;\n  return &f->upvals[n - 1];  /* get its upvalue pointer */\n}\n\n\nLUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {\n  TValue *fi = index2value(L, fidx);\n  switch (ttypetag(fi)) {\n    case LUA_VLCL: {  /* lua closure */\n      return *getupvalref(L, fidx, n, NULL);\n    }\n    case LUA_VCCL: {  /* C closure */\n      CClosure *f = clCvalue(fi);\n      api_check(L, 1 <= n && n <= f->nupvalues, \"invalid upvalue index\");\n      return &f->upvalue[n - 1];\n    }\n    default: {\n      api_check(L, 0, \"closure expected\");\n      return NULL;\n    }\n  }\n}\n\n\nLUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,\n                                            int fidx2, int n2) {\n  LClosure *f1;\n  UpVal **up1 = getupvalref(L, fidx1, n1, &f1);\n  UpVal **up2 = getupvalref(L, fidx2, n2, NULL);\n  *up1 = *up2;\n  luaC_objbarrier(L, f1, *up1);\n}\n\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lapi.h",
    "content": "/*\n** $Id: lapi.h $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"llimits.h\"\n#include \"lstate.h\"\n\n\n/* Increments 'L->top', checking for stack overflows */\n#define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \\\n\t\t\t\t\"stack overflow\");}\n\n\n/*\n** If a call returns too many multiple returns, the callee may not have\n** stack space to accommodate all results. In this case, this macro\n** increases its stack space ('L->ci->top').\n*/\n#define adjustresults(L,nres) \\\n    { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }\n\n\n/* Ensure the stack has at least 'n' elements */\n#define api_checknelems(L,n)\tapi_check(L, (n) < (L->top - L->ci->func), \\\n\t\t\t\t  \"not enough elements in the stack\")\n\n\n/*\n** To reduce the overhead of returning from C functions, the presence of\n** to-be-closed variables in these functions is coded in the CallInfo's\n** field 'nresults', in a way that functions with no to-be-closed variables\n** with zero, one, or \"all\" wanted results have no overhead. Functions\n** with other number of wanted results, as well as functions with\n** variables to be closed, have an extra check.\n*/\n\n#define hastocloseCfunc(n)\t((n) < LUA_MULTRET)\n\n#define codeNresults(n)\t\t(-(n) - 3)\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/*\n** This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n\n\n#if !defined(MAX_SIZET)\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n#endif\n\n\n/*\n** {======================================================\n** Traceback\n** =======================================================\n*/\n\n\n#define LEVELS1\t10\t/* size of the first part of the stack */\n#define LEVELS2\t11\t/* size of the second part of the stack */\n\n\n\n/*\n** Search for 'objidx' in table at index -1. ('objidx' must be an\n** absolute index.) Return 1 + string at top if it found a good name.\n*/\nstatic int findfield (lua_State *L, int objidx, int level) {\n  if (level == 0 || !lua_istable(L, -1))\n    return 0;  /* not found */\n  lua_pushnil(L);  /* start 'next' loop */\n  while (lua_next(L, -2)) {  /* for each pair in table */\n    if (lua_type(L, -2) == LUA_TSTRING) {  /* ignore non-string keys */\n      if (lua_rawequal(L, objidx, -1)) {  /* found object? */\n        lua_pop(L, 1);  /* remove value (but keep name) */\n        return 1;\n      }\n      else if (findfield(L, objidx, level - 1)) {  /* try recursively */\n        /* stack: lib_name, lib_table, field_name (top) */\n        lua_pushliteral(L, \".\");  /* place '.' between the two names */\n        lua_replace(L, -3);  /* (in the slot occupied by table) */\n        lua_concat(L, 3);  /* lib_name.field_name */\n        return 1;\n      }\n    }\n    lua_pop(L, 1);  /* remove value */\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Search for a name for a function in all loaded modules\n*/\nstatic int pushglobalfuncname (lua_State *L, lua_Debug *ar) {\n  int top = lua_gettop(L);\n  lua_getinfo(L, \"f\", ar);  /* push function */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  if (findfield(L, top + 1, 2)) {\n    const char *name = lua_tostring(L, -1);\n    if (strncmp(name, LUA_GNAME \".\", 3) == 0) {  /* name start with '_G.'? */\n      lua_pushstring(L, name + 3);  /* push name without prefix */\n      lua_remove(L, -2);  /* remove original name */\n    }\n    lua_copy(L, -1, top + 1);  /* copy name to proper place */\n    lua_settop(L, top + 1);  /* remove table \"loaded\" and name copy */\n    return 1;\n  }\n  else {\n    lua_settop(L, top);  /* remove function and global table */\n    return 0;\n  }\n}\n\n\nstatic void pushfuncname (lua_State *L, lua_Debug *ar) {\n  if (pushglobalfuncname(L, ar)) {  /* try first a global name */\n    lua_pushfstring(L, \"function '%s'\", lua_tostring(L, -1));\n    lua_remove(L, -2);  /* remove name */\n  }\n  else if (*ar->namewhat != '\\0')  /* is there a name from code? */\n    lua_pushfstring(L, \"%s '%s'\", ar->namewhat, ar->name);  /* use it */\n  else if (*ar->what == 'm')  /* main? */\n      lua_pushliteral(L, \"main chunk\");\n  else if (*ar->what != 'C')  /* for Lua functions, use <file:line> */\n    lua_pushfstring(L, \"function <%s:%d>\", ar->short_src, ar->linedefined);\n  else  /* nothing left... */\n    lua_pushliteral(L, \"?\");\n}\n\n\nstatic int lastlevel (lua_State *L) {\n  lua_Debug ar;\n  int li = 1, le = 1;\n  /* find an upper bound */\n  while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }\n  /* do a binary search */\n  while (li < le) {\n    int m = (li + le)/2;\n    if (lua_getstack(L, m, &ar)) li = m + 1;\n    else le = m;\n  }\n  return le - 1;\n}\n\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,\n                                const char *msg, int level) {\n  luaL_Buffer b;\n  lua_Debug ar;\n  int last = lastlevel(L1);\n  int limit2show = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;\n  luaL_buffinit(L, &b);\n  if (msg) {\n    luaL_addstring(&b, msg);\n    luaL_addchar(&b, '\\n');\n  }\n  luaL_addstring(&b, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (limit2show-- == 0) {  /* too many levels? */\n      int n = last - level - LEVELS2 + 1;  /* number of levels to skip */\n      lua_pushfstring(L, \"\\n\\t...\\t(skipping %d levels)\", n);\n      luaL_addvalue(&b);  /* add warning about skip */\n      level += n;  /* and skip to last levels */\n    }\n    else {\n      lua_getinfo(L1, \"Slnt\", &ar);\n      if (ar.currentline <= 0)\n        lua_pushfstring(L, \"\\n\\t%s: in \", ar.short_src);\n      else\n        lua_pushfstring(L, \"\\n\\t%s:%d: in \", ar.short_src, ar.currentline);\n      luaL_addvalue(&b);\n      pushfuncname(L, &ar);\n      luaL_addvalue(&b);\n      if (ar.istailcall)\n        luaL_addstring(&b, \"\\n\\t(...tail calls...)\");\n    }\n  }\n  luaL_pushresult(&b);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", arg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    arg--;  /* do not count 'self' */\n    if (arg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling '%s' on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : \"?\";\n  return luaL_error(L, \"bad argument #%d to '%s' (%s)\",\n                        arg, ar.name, extramsg);\n}\n\n\nint luaL_typeerror (lua_State *L, int arg, const char *tname) {\n  const char *msg;\n  const char *typearg;  /* name for the type of the actual argument */\n  if (luaL_getmetafield(L, arg, \"__name\") == LUA_TSTRING)\n    typearg = lua_tostring(L, -1);  /* use the given type name */\n  else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)\n    typearg = \"light userdata\";  /* special name for messages */\n  else\n    typearg = luaL_typename(L, arg);  /* standard name */\n  msg = lua_pushfstring(L, \"%s expected, got %s\", tname, typearg);\n  return luaL_argerror(L, arg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int arg, int tag) {\n  luaL_typeerror(L, arg, lua_typename(L, tag));\n}\n\n\n/*\n** The use of 'lua_pushfstring' ensures this function does not\n** need reserved stack space when called.\n*/\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushfstring(L, \"\");  /* else, no information available... */\n}\n\n\n/*\n** Again, the use of 'lua_pushvfstring' ensures this function does\n** not need reserved stack space when called. (At worst, it generates\n** an error with \"stack overflow\" instead of the given message.)\n*/\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n\nLUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (stat) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    luaL_pushfail(L);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushstring(L, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\n#if !defined(l_inspectstat)\t/* { */\n\n#if defined(LUA_USE_POSIX)\n\n#include <sys/wait.h>\n\n/*\n** use appropriate macros to interpret 'pclose' return status\n*/\n#define l_inspectstat(stat,what)  \\\n   if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \\\n   else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = \"signal\"; }\n\n#else\n\n#define l_inspectstat(stat,what)  /* no op */\n\n#endif\n\n#endif\t\t\t\t/* } */\n\n\nLUALIB_API int luaL_execresult (lua_State *L, int stat) {\n  const char *what = \"exit\";  /* type of termination */\n  if (stat != 0 && errno != 0)  /* error with an 'errno'? */\n    return luaL_fileresult(L, 0, NULL);\n  else {\n    l_inspectstat(stat, what);  /* interpret result */\n    if (*what == 'e' && stat == 0)  /* successful termination? */\n      lua_pushboolean(L, 1);\n    else\n      luaL_pushfail(L);\n    lua_pushstring(L, what);\n    lua_pushinteger(L, stat);\n    return 3;  /* return true/fail,what,code */\n  }\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Userdata's metatable manipulation\n** =======================================================\n*/\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  if (luaL_getmetatable(L, tname) != LUA_TNIL)  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_createtable(L, 0, 2);  /* create metatable */\n  lua_pushstring(L, tname);\n  lua_setfield(L, -2, \"__name\");  /* metatable.__name = tname */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {\n  luaL_getmetatable(L, tname);\n  lua_setmetatable(L, -2);\n}\n\n\nLUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      luaL_getmetatable(L, tname);  /* get correct metatable */\n      if (!lua_rawequal(L, -1, -2))  /* not the same? */\n        p = NULL;  /* value is a userdata with wrong metatable */\n      lua_pop(L, 2);  /* remove both metatables */\n      return p;\n    }\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = luaL_testudata(L, ud, tname);\n  luaL_argexpected(L, p != NULL, ud, tname);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Argument check functions\n** =======================================================\n*/\n\nLUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, arg, def) :\n                             luaL_checkstring(L, arg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, arg,\n                       lua_pushfstring(L, \"invalid option '%s'\", name));\n}\n\n\n/*\n** Ensures the stack has at least 'space' extra slots, raising an error\n** if it cannot fulfill the request. (The error handling needs a few\n** extra slots to format the error message. In case of an error without\n** this extra space, Lua will generate the same 'stack overflow' error,\n** but without 'msg'.)\n*/\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) {\n  if (!lua_checkstack(L, space)) {\n    if (msg)\n      luaL_error(L, \"stack overflow (%s)\", msg);\n    else\n      luaL_error(L, \"stack overflow\");\n  }\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int arg, int t) {\n  if (lua_type(L, arg) != t)\n    tag_error(L, arg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNONE)\n    luaL_argerror(L, arg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) {\n  const char *s = lua_tolstring(L, arg, len);\n  if (!s) tag_error(L, arg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int arg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, arg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, arg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) {\n  int isnum;\n  lua_Number d = lua_tonumberx(L, arg, &isnum);\n  if (!isnum)\n    tag_error(L, arg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, arg, def);\n}\n\n\nstatic void interror (lua_State *L, int arg) {\n  if (lua_isnumber(L, arg))\n    luaL_argerror(L, arg, \"number has no integer representation\");\n  else\n    tag_error(L, arg, LUA_TNUMBER);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) {\n  int isnum;\n  lua_Integer d = lua_tointegerx(L, arg, &isnum);\n  if (!isnum) {\n    interror(L, arg);\n  }\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, arg, def);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n/* userdata to box arbitrary data */\ntypedef struct UBox {\n  void *box;\n  size_t bsize;\n} UBox;\n\n\nstatic void *resizebox (lua_State *L, int idx, size_t newsize) {\n  void *ud;\n  lua_Alloc allocf = lua_getallocf(L, &ud);\n  UBox *box = (UBox *)lua_touserdata(L, idx);\n  void *temp = allocf(ud, box->box, box->bsize, newsize);\n  if (temp == NULL && newsize > 0) {  /* allocation error? */\n    lua_pushliteral(L, \"not enough memory\");\n    lua_error(L);  /* raise a memory error */\n  }\n  box->box = temp;\n  box->bsize = newsize;\n  return temp;\n}\n\n\nstatic int boxgc (lua_State *L) {\n  resizebox(L, 1, 0);\n  return 0;\n}\n\n\nstatic const luaL_Reg boxmt[] = {  /* box metamethods */\n  {\"__gc\", boxgc},\n  {\"__close\", boxgc},\n  {NULL, NULL}\n};\n\n\nstatic void newbox (lua_State *L) {\n  UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0);\n  box->box = NULL;\n  box->bsize = 0;\n  if (luaL_newmetatable(L, \"_UBOX*\"))  /* creating metatable? */\n    luaL_setfuncs(L, boxmt, 0);  /* set its metamethods */\n  lua_setmetatable(L, -2);\n}\n\n\n/*\n** check whether buffer is using a userdata on the stack as a temporary\n** buffer\n*/\n#define buffonstack(B)\t((B)->b != (B)->init.b)\n\n\n/*\n** Compute new size for buffer 'B', enough to accommodate extra 'sz'\n** bytes.\n*/\nstatic size_t newbuffsize (luaL_Buffer *B, size_t sz) {\n  size_t newsize = B->size * 2;  /* double buffer size */\n  if (MAX_SIZET - sz < B->n)  /* overflow in (B->n + sz)? */\n    return luaL_error(B->L, \"buffer too large\");\n  if (newsize < B->n + sz)  /* double is not big enough? */\n    newsize = B->n + sz;\n  return newsize;\n}\n\n\n/*\n** Returns a pointer to a free area with at least 'sz' bytes in buffer\n** 'B'. 'boxidx' is the relative position in the stack where the\n** buffer's box is or should be.\n*/\nstatic char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) {\n  if (B->size - B->n >= sz)  /* enough space? */\n    return B->b + B->n;\n  else {\n    lua_State *L = B->L;\n    char *newbuff;\n    size_t newsize = newbuffsize(B, sz);\n    /* create larger buffer */\n    if (buffonstack(B))  /* buffer already has a box? */\n      newbuff = (char *)resizebox(L, boxidx, newsize);  /* resize it */\n    else {  /* no box yet */\n      lua_pushnil(L);  /* reserve slot for final result */\n      newbox(L);  /* create a new box */\n      /* move box (and slot) to its intended position */\n      lua_rotate(L, boxidx - 1, 2);\n      lua_toclose(L, boxidx);\n      newbuff = (char *)resizebox(L, boxidx, newsize);\n      memcpy(newbuff, B->b, B->n * sizeof(char));  /* copy original content */\n    }\n    B->b = newbuff;\n    B->size = newsize;\n    return newbuff + B->n;\n  }\n}\n\n/*\n** returns a pointer to a free area with at least 'sz' bytes\n*/\nLUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {\n  return prepbuffsize(B, sz, -1);\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */\n    char *b = prepbuffsize(B, l, -1);\n    memcpy(b, s, l * sizeof(char));\n    luaL_addsize(B, l);\n  }\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  lua_pushlstring(L, B->b, B->n);\n  if (buffonstack(B)) {\n    lua_copy(L, -1, -3);  /* move string to reserved slot */\n    lua_pop(L, 2);  /* pop string and box (closing the box) */\n  }\n}\n\n\nLUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {\n  luaL_addsize(B, sz);\n  luaL_pushresult(B);\n}\n\n\n/*\n** 'luaL_addvalue' is the only function in the Buffer system where the\n** box (if existent) is not on the top of the stack. So, instead of\n** calling 'luaL_addlstring', it replicates the code using -2 as the\n** last argument to 'prepbuffsize', signaling that the box is (or will\n** be) bellow the string being added to the buffer. (Box creation can\n** trigger an emergency GC, so we should not remove the string from the\n** stack before we have the space guaranteed.)\n*/\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t len;\n  const char *s = lua_tolstring(L, -1, &len);\n  char *b = prepbuffsize(B, len, -2);\n  memcpy(b, s, len * sizeof(char));\n  luaL_addsize(B, len);\n  lua_pop(L, 1);  /* pop string */\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->b = B->init.b;\n  B->n = 0;\n  B->size = LUAL_BUFFERSIZE;\n}\n\n\nLUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {\n  luaL_buffinit(L, B);\n  return prepbuffsize(B, sz, -1);\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Reference system\n** =======================================================\n*/\n\n/* index of free-list header */\n#define freelist\t0\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* 'nil' has a unique fixed reference */\n  }\n  t = lua_absindex(L, t);\n  lua_rawgeti(L, t, freelist);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[freelist] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, freelist);  /* (t[freelist] = t[ref]) */\n  }\n  else  /* no free elements */\n    ref = (int)lua_rawlen(L, t) + 1;  /* get a new reference */\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = lua_absindex(L, t);\n    lua_rawgeti(L, t, freelist);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[freelist] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, freelist);  /* t[freelist] = ref */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int n;  /* number of pre-read characters */\n  FILE *f;  /* file being read */\n  char buff[BUFSIZ];  /* area for reading file */\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;  /* not used */\n  if (lf->n > 0) {  /* are there pre-read characters to be read? */\n    *size = lf->n;  /* return them (chars already in buffer) */\n    lf->n = 0;  /* no more pre-read characters */\n  }\n  else {  /* read a block from file */\n    /* 'fread' can return > 0 *and* set the EOF flag. If next call to\n       'getF' called 'fread', it might still wait for user input.\n       The next check avoids this problem. */\n    if (feof(lf->f)) return NULL;\n    *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */\n  }\n  return lf->buff;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nstatic int skipBOM (LoadF *lf) {\n  const char *p = \"\\xEF\\xBB\\xBF\";  /* UTF-8 BOM mark */\n  int c;\n  lf->n = 0;\n  do {\n    c = getc(lf->f);\n    if (c == EOF || c != *(const unsigned char *)p++) return c;\n    lf->buff[lf->n++] = c;  /* to be read by the parser */\n  } while (*p != '\\0');\n  lf->n = 0;  /* prefix matched; discard it */\n  return getc(lf->f);  /* return next character */\n}\n\n\n/*\n** reads the first character of file 'f' and skips an optional BOM mark\n** in its beginning plus its first line if it starts with '#'. Returns\n** true if it skipped the first line.  In any case, '*cp' has the\n** first \"valid\" character of the file (after the optional BOM and\n** a first-line comment).\n*/\nstatic int skipcomment (LoadF *lf, int *cp) {\n  int c = *cp = skipBOM(lf);\n  if (c == '#') {  /* first line is a comment (Unix exec. file)? */\n    do {  /* skip first line */\n      c = getc(lf->f);\n    } while (c != EOF && c != '\\n');\n    *cp = getc(lf->f);  /* skip end-of-line, if present */\n    return 1;  /* there was a comment */\n  }\n  else return 0;  /* no comment */\n}\n\n\nLUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,\n                                             const char *mode) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  if (skipcomment(&lf, &c))  /* read initial portion */\n    lf.buff[lf.n++] = '\\n';  /* add line to correct line numbers */\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    skipcomment(&lf, &c);  /* re-read initial portion */\n  }\n  if (c != EOF)\n    lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;  /* not used */\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,\n                                 const char *name, const char *mode) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name, mode);\n}\n\n\nLUALIB_API int luaL_loadstring (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return LUA_TNIL;\n  else {\n    int tt;\n    lua_pushstring(L, event);\n    tt = lua_rawget(L, -2);\n    if (tt == LUA_TNIL)  /* is metafield nil? */\n      lua_pop(L, 2);  /* remove metatable and metafield */\n    else\n      lua_remove(L, -2);  /* remove only metatable */\n    return tt;  /* return metafield type */\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = lua_absindex(L, obj);\n  if (luaL_getmetafield(L, obj, event) == LUA_TNIL)  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {\n  lua_Integer l;\n  int isnum;\n  lua_len(L, idx);\n  l = lua_tointegerx(L, -1, &isnum);\n  if (!isnum)\n    luaL_error(L, \"object length is not an integer\");\n  lua_pop(L, 1);  /* remove object */\n  return l;\n}\n\n\nLUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {\n  if (luaL_callmeta(L, idx, \"__tostring\")) {  /* metafield? */\n    if (!lua_isstring(L, -1))\n      luaL_error(L, \"'__tostring' must return a string\");\n  }\n  else {\n    switch (lua_type(L, idx)) {\n      case LUA_TNUMBER: {\n        if (lua_isinteger(L, idx))\n          lua_pushfstring(L, \"%I\", (LUAI_UACINT)lua_tointeger(L, idx));\n        else\n          lua_pushfstring(L, \"%f\", (LUAI_UACNUMBER)lua_tonumber(L, idx));\n        break;\n      }\n      case LUA_TSTRING:\n        lua_pushvalue(L, idx);\n        break;\n      case LUA_TBOOLEAN:\n        lua_pushstring(L, (lua_toboolean(L, idx) ? \"true\" : \"false\"));\n        break;\n      case LUA_TNIL:\n        lua_pushliteral(L, \"nil\");\n        break;\n      default: {\n        int tt = luaL_getmetafield(L, idx, \"__name\");  /* try name */\n        const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :\n                                                 luaL_typename(L, idx);\n        lua_pushfstring(L, \"%s: %p\", kind, lua_topointer(L, idx));\n        if (tt != LUA_TNIL)\n          lua_remove(L, -2);  /* remove '__name' */\n        break;\n      }\n    }\n  }\n  return lua_tolstring(L, -1, len);\n}\n\n\n/*\n** set functions from list 'l' into table at top - 'nup'; each\n** function gets the 'nup' elements at the top as upvalues.\n** Returns with only the table at the stack.\n*/\nLUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name != NULL; l++) {  /* fill the table with given functions */\n    if (l->func == NULL)  /* place holder? */\n      lua_pushboolean(L, 0);\n    else {\n      int i;\n      for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n        lua_pushvalue(L, -nup);\n      lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */\n    }\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** ensure that stack[idx][fname] has a table and push that table\n** into the stack\n*/\nLUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {\n  if (lua_getfield(L, idx, fname) == LUA_TTABLE)\n    return 1;  /* table already there */\n  else {\n    lua_pop(L, 1);  /* remove previous result */\n    idx = lua_absindex(L, idx);\n    lua_newtable(L);\n    lua_pushvalue(L, -1);  /* copy to be left at top */\n    lua_setfield(L, idx, fname);  /* assign new table to field */\n    return 0;  /* false, because did not find table there */\n  }\n}\n\n\n/*\n** Stripped-down 'require': After checking \"loaded\" table, calls 'openf'\n** to open a module, registers the result in 'package.loaded' table and,\n** if 'glb' is true, also registers the result in the global table.\n** Leaves resulting module on the top.\n*/\nLUALIB_API void luaL_requiref (lua_State *L, const char *modname,\n                               lua_CFunction openf, int glb) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, -1, modname);  /* LOADED[modname] */\n  if (!lua_toboolean(L, -1)) {  /* package not already loaded? */\n    lua_pop(L, 1);  /* remove field */\n    lua_pushcfunction(L, openf);\n    lua_pushstring(L, modname);  /* argument to open function */\n    lua_call(L, 1, 1);  /* call 'openf' to open module */\n    lua_pushvalue(L, -1);  /* make copy of module (call result) */\n    lua_setfield(L, -3, modname);  /* LOADED[modname] = module */\n  }\n  lua_remove(L, -2);  /* remove LOADED table */\n  if (glb) {\n    lua_pushvalue(L, -1);  /* copy of module */\n    lua_setglobal(L, modname);  /* _G[modname] = module */\n  }\n}\n\n\nLUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,\n                                     const char *p, const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(b, s, wild - s);  /* push prefix */\n    luaL_addstring(b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after 'p' */\n  }\n  luaL_addstring(b, s);  /* push last suffix */\n}\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s,\n                                  const char *p, const char *r) {\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  luaL_addgsub(&b, s, p, r);\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  (void)ud; (void)osize;  /* not used */\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  else\n    return realloc(ptr, nsize);\n}\n\n\nstatic int panic (lua_State *L) {\n  const char *msg = lua_tostring(L, -1);\n  if (msg == NULL) msg = \"error object is not a string\";\n  lua_writestringerror(\"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                        msg);\n  return 0;  /* return to Lua to abort */\n}\n\n\n/*\n** Emit a warning. '*warnstate' means:\n** 0 - warning system is off;\n** 1 - ready to start a new message;\n** 2 - previous message is to be continued.\n*/\nstatic void warnf (void *ud, const char *message, int tocont) {\n  int *warnstate = (int *)ud;\n  if (*warnstate != 2 && !tocont && *message == '@') {  /* control message? */\n    if (strcmp(message, \"@off\") == 0)\n      *warnstate = 0;\n    else if (strcmp(message, \"@on\") == 0)\n      *warnstate = 1;\n    return;\n  }\n  else if (*warnstate == 0)  /* warnings off? */\n    return;\n  if (*warnstate == 1)  /* previous message was the last? */\n    lua_writestringerror(\"%s\", \"Lua warning: \");  /* start a new warning */\n  lua_writestringerror(\"%s\", message);  /* write message */\n  if (tocont)  /* not the last part? */\n    *warnstate = 2;  /* to be continued */\n  else {  /* last part */\n    lua_writestringerror(\"%s\", \"\\n\");  /* finish message with end-of-line */\n    *warnstate = 1;  /* ready to start a new message */\n  }\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  if (L) {\n    int *warnstate;  /* space for warning state */\n    lua_atpanic(L, &panic);\n    warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0);\n    luaL_ref(L, LUA_REGISTRYINDEX);  /* make sure it won't be collected */\n    *warnstate = 0;  /* default is warnings off */\n    lua_setwarnf(L, warnf, warnstate);\n  }\n  return L;\n}\n\n\nLUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {\n  lua_Number v = lua_version(L);\n  if (sz != LUAL_NUMSIZES)  /* check numeric types */\n    luaL_error(L, \"core and library have incompatible numeric types\");\n  else if (v != ver)\n    luaL_error(L, \"version mismatch: app. needs %f, Lua core provides %f\",\n                  (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)v);\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n/* global table */\n#define LUA_GNAME\t\"_G\"\n\n\ntypedef struct luaL_Buffer luaL_Buffer;\n\n\n/* extra error code for 'luaL_loadfilex' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\n/* key, in the registry, for table of loaded modules */\n#define LUA_LOADED_TABLE\t\"_LOADED\"\n\n\n/* key, in the registry, for table of preloaded loaders */\n#define LUA_PRELOAD_TABLE\t\"_PRELOAD\"\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n#define LUAL_NUMSIZES\t(sizeof(lua_Integer)*16 + sizeof(lua_Number))\n\nLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);\n#define luaL_checkversion(L)  \\\n\t  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)\n\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\nLUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);\nLUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int arg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void  (luaL_setmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\nLUALIB_API int (luaL_execresult) (lua_State *L, int stat);\n\n\n/* predefined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n                                               const char *mode);\n\n#define luaL_loadfile(L,f)\tluaL_loadfilex(L,f,NULL)\n\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n                                   const char *name, const char *mode);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\nLUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);\n\nLUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,\n                                     const char *p, const char *r);\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,\n                                    const char *p, const char *r);\n\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\n\nLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\n\nLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\n                                  const char *msg, int level);\n\nLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\n                                 lua_CFunction openf, int glb);\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n\n#define luaL_newlibtable(L,l)\t\\\n  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n\n#define luaL_newlib(L,l)  \\\n  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\n\n#define luaL_argcheck(L, cond,arg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (arg), (extramsg))))\n\n#define luaL_argexpected(L,cond,arg,tname)\t\\\n\t\t((void)((cond) || luaL_typeerror(L, (arg), (tname))))\n\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n#define luaL_loadbuffer(L,s,sz,n)\tluaL_loadbufferx(L,s,sz,n,NULL)\n\n\n/* push the value used to represent failure/error */\n#define luaL_pushfail(L)\tlua_pushnil(L)\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\nstruct luaL_Buffer {\n  char *b;  /* buffer address */\n  size_t size;  /* buffer size */\n  size_t n;  /* number of characters in buffer */\n  lua_State *L;\n  union {\n    LUAI_MAXALIGN;  /* ensure maximum alignment for buffer */\n    char b[LUAL_BUFFERSIZE];  /* initial buffer */\n  } init;\n};\n\n\n#define luaL_bufflen(bf)\t((bf)->n)\n#define luaL_buffaddr(bf)\t((bf)->b)\n\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\\n   ((B)->b[(B)->n++] = (c)))\n\n#define luaL_addsize(B,s)\t((B)->n += (s))\n\n#define luaL_buffsub(B,s)\t((B)->n -= (s))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\nLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\n\n#define luaL_prepbuffer(B)\tluaL_prepbuffsize(B, LUAL_BUFFERSIZE)\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** File handles for IO library\n** =======================================================\n*/\n\n/*\n** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\n** initial structure 'luaL_Stream' (it may contain other fields\n** after that initial structure).\n*/\n\n#define LUA_FILEHANDLE          \"FILE*\"\n\n\ntypedef struct luaL_Stream {\n  FILE *f;  /* stream (NULL for incompletely created streams) */\n  lua_CFunction closef;  /* to close stream (NULL for closed streams) */\n} luaL_Stream;\n\n/* }====================================================== */\n\n/*\n** {==================================================================\n** \"Abstraction Layer\" for basic report of messages and errors\n** ===================================================================\n*/\n\n/* print a string */\n#if !defined(lua_writestring)\n#define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)\n#endif\n\n/* print a newline and flush the output */\n#if !defined(lua_writeline)\n#define lua_writeline()        (lua_writestring(\"\\n\", 1), fflush(stdout))\n#endif\n\n/* print an error message */\n#if !defined(lua_writestringerror)\n#define lua_writestringerror(s,p) \\\n        (fprintf(stderr, (s), (p)), fflush(stderr))\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {============================================================\n** Compatibility with deprecated conversions\n** =============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define luaL_checkunsigned(L,a)\t((lua_Unsigned)luaL_checkinteger(L,a))\n#define luaL_optunsigned(L,a,d)\t\\\n\t((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))\n\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#endif\n/* }============================================================ */\n\n\n\n#endif\n\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  for (i = 1; i <= n; i++) {  /* for each argument */\n    size_t l;\n    const char *s = luaL_tolstring(L, i, &l);  /* convert it to string */\n    if (i > 1)  /* not the first element? */\n      lua_writestring(\"\\t\", 1);  /* add a tab before it */\n    lua_writestring(s, l);  /* print it */\n    lua_pop(L, 1);  /* pop result */\n  }\n  lua_writeline();\n  return 0;\n}\n\n\n/*\n** Creates a warning with all given arguments.\n** Check first for errors; otherwise an error may interrupt\n** the composition of a warning, leaving it unfinished.\n*/\nstatic int luaB_warn (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_checkstring(L, 1);  /* at least one argument */\n  for (i = 2; i <= n; i++)\n    luaL_checkstring(L, i);  /* make sure all arguments are strings */\n  for (i = 1; i < n; i++)  /* compose warning */\n    lua_warning(L, lua_tostring(L, i), 1);\n  lua_warning(L, lua_tostring(L, n), 0);  /* close warning */\n  return 0;\n}\n\n\n#define SPACECHARS\t\" \\f\\n\\r\\t\\v\"\n\nstatic const char *b_str2int (const char *s, int base, lua_Integer *pn) {\n  lua_Unsigned n = 0;\n  int neg = 0;\n  s += strspn(s, SPACECHARS);  /* skip initial spaces */\n  if (*s == '-') { s++; neg = 1; }  /* handle sign */\n  else if (*s == '+') s++;\n  if (!isalnum((unsigned char)*s))  /* no digit? */\n    return NULL;\n  do {\n    int digit = (isdigit((unsigned char)*s)) ? *s - '0'\n                   : (toupper((unsigned char)*s) - 'A') + 10;\n    if (digit >= base) return NULL;  /* invalid numeral */\n    n = n * base + digit;\n    s++;\n  } while (isalnum((unsigned char)*s));\n  s += strspn(s, SPACECHARS);  /* skip trailing spaces */\n  *pn = (lua_Integer)((neg) ? (0u - n) : n);\n  return s;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */\n    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */\n      lua_settop(L, 1);  /* yes; return it */\n      return 1;\n    }\n    else {\n      size_t l;\n      const char *s = lua_tolstring(L, 1, &l);\n      if (s != NULL && lua_stringtonumber(L, s) == l + 1)\n        return 1;  /* successful conversion to number */\n      /* else not a number */\n      luaL_checkany(L, 1);  /* (but there must be some parameter) */\n    }\n  }\n  else {\n    size_t l;\n    const char *s;\n    lua_Integer n = 0;  /* to avoid warnings */\n    lua_Integer base = luaL_checkinteger(L, 2);\n    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */\n    s = lua_tolstring(L, 1, &l);\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    if (b_str2int(s, (int)base, &n) == s + l) {\n      lua_pushinteger(L, n);\n      return 1;\n    }  /* else not a number */\n  }  /* else not a number */\n  luaL_pushfail(L);  /* not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = (int)luaL_optinteger(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {\n    luaL_where(L, level);   /* add extra information */\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, \"nil or table\");\n  if (luaL_getmetafield(L, 1, \"__metatable\") != LUA_TNIL)\n    return luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawlen (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,\n                      \"table or string\");\n  lua_pushinteger(L, lua_rawlen(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int pushmode (lua_State *L, int oldmode) {\n  lua_pushstring(L, (oldmode == LUA_GCINC) ? \"incremental\" : \"generational\");\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\n    \"isrunning\", \"generational\", \"incremental\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n    LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};\n  int o = optsnum[luaL_checkoption(L, 1, \"collect\", opts)];\n  switch (o) {\n    case LUA_GCCOUNT: {\n      int k = lua_gc(L, o);\n      int b = lua_gc(L, LUA_GCCOUNTB);\n      lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: {\n      int step = (int)luaL_optinteger(L, 2, 0);\n      int res = lua_gc(L, o, step);\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    case LUA_GCSETPAUSE:\n    case LUA_GCSETSTEPMUL: {\n      int p = (int)luaL_optinteger(L, 2, 0);\n      int previous = lua_gc(L, o, p);\n      lua_pushinteger(L, previous);\n      return 1;\n    }\n    case LUA_GCISRUNNING: {\n      int res = lua_gc(L, o);\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    case LUA_GCGEN: {\n      int minormul = (int)luaL_optinteger(L, 2, 0);\n      int majormul = (int)luaL_optinteger(L, 3, 0);\n      return pushmode(L, lua_gc(L, o, minormul, majormul));\n    }\n    case LUA_GCINC: {\n      int pause = (int)luaL_optinteger(L, 2, 0);\n      int stepmul = (int)luaL_optinteger(L, 3, 0);\n      int stepsize = (int)luaL_optinteger(L, 4, 0);\n      return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));\n    }\n    default: {\n      int res = lua_gc(L, o);\n      lua_pushinteger(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  int t = lua_type(L, 1);\n  luaL_argcheck(L, t != LUA_TNONE, 1, \"value expected\");\n  lua_pushstring(L, lua_typename(L, t));\n  return 1;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (luaL_getmetafield(L, 1, \"__pairs\") == LUA_TNIL) {  /* no metamethod? */\n    lua_pushcfunction(L, luaB_next);  /* will return generator, */\n    lua_pushvalue(L, 1);  /* state, */\n    lua_pushnil(L);  /* and initial value */\n  }\n  else {\n    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */\n    lua_call(L, 1, 3);  /* get 3 values from metamethod */\n  }\n  return 3;\n}\n\n\n/*\n** Traversal function for 'ipairs'\n*/\nstatic int ipairsaux (lua_State *L) {\n  lua_Integer i = luaL_checkinteger(L, 2) + 1;\n  lua_pushinteger(L, i);\n  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;\n}\n\n\n/*\n** 'ipairs' function. Returns 'ipairsaux', given \"table\", 0.\n** (The given \"table\" may not be a table.)\n*/\nstatic int luaB_ipairs (lua_State *L) {\n  luaL_checkany(L, 1);\n  lua_pushcfunction(L, ipairsaux);  /* iteration function */\n  lua_pushvalue(L, 1);  /* state */\n  lua_pushinteger(L, 0);  /* initial value */\n  return 3;\n}\n\n\nstatic int load_aux (lua_State *L, int status, int envidx) {\n  if (status == LUA_OK) {\n    if (envidx != 0) {  /* 'env' parameter? */\n      lua_pushvalue(L, envidx);  /* environment for loaded function */\n      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */\n        lua_pop(L, 1);  /* remove 'env' if not used by previous call */\n    }\n    return 1;\n  }\n  else {  /* error (message is on top of the stack) */\n    luaL_pushfail(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return fail plus error message */\n  }\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  const char *mode = luaL_optstring(L, 2, NULL);\n  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */\n  int status = luaL_loadfilex(L, fname, mode);\n  return load_aux(L, status, env);\n}\n\n\n/*\n** {======================================================\n** Generic Read function\n** =======================================================\n*/\n\n\n/*\n** reserved slot, above all arguments, to hold a copy of the returned\n** string to avoid it being collected while parsed. 'load' has four\n** optional arguments (chunk, source name, mode, and environment).\n*/\n#define RESERVEDSLOT\t5\n\n\n/*\n** Reader for generic 'load' function: 'lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)(ud);  /* not used */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* pop result */\n    *size = 0;\n    return NULL;\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"reader function must return a string\");\n  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */\n  return lua_tolstring(L, RESERVEDSLOT, size);\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  size_t l;\n  const char *s = lua_tolstring(L, 1, &l);\n  const char *mode = luaL_optstring(L, 3, \"bt\");\n  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */\n  if (s != NULL) {  /* loading a string? */\n    const char *chunkname = luaL_optstring(L, 2, s);\n    status = luaL_loadbufferx(L, s, l, chunkname, mode);\n  }\n  else {  /* loading from a reader function */\n    const char *chunkname = luaL_optstring(L, 2, \"=(load)\");\n    luaL_checktype(L, 1, LUA_TFUNCTION);\n    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */\n    status = lua_load(L, generic_reader, NULL, chunkname, mode);\n  }\n  return load_aux(L, status, env);\n}\n\n/* }====================================================== */\n\n\nstatic int dofilecont (lua_State *L, int d1, lua_KContext d2) {\n  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */\n  return lua_gettop(L) - 1;\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  lua_settop(L, 1);\n  if (luaL_loadfile(L, fname) != LUA_OK)\n    return lua_error(L);\n  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);\n  return dofilecont(L, 0, 0);\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  if (lua_toboolean(L, 1))  /* condition is true? */\n    return lua_gettop(L);  /* return all arguments */\n  else {  /* error */\n    luaL_checkany(L, 1);  /* there must be a condition */\n    lua_remove(L, 1);  /* remove it */\n    lua_pushliteral(L, \"assertion failed!\");  /* default message */\n    lua_settop(L, 1);  /* leave only message (default if no other one) */\n    return luaB_error(L);  /* call 'error' */\n  }\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    lua_Integer i = luaL_checkinteger(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - (int)i;\n  }\n}\n\n\n/*\n** Continuation function for 'pcall' and 'xpcall'. Both functions\n** already pushed a 'true' before doing the call, so in case of success\n** 'finishpcall' only has to return everything in the stack minus\n** 'extra' values (where 'extra' is exactly the number of items to be\n** ignored).\n*/\nstatic int finishpcall (lua_State *L, int status, lua_KContext extra) {\n  if (status != LUA_OK && status != LUA_YIELD) {  /* error? */\n    lua_pushboolean(L, 0);  /* first result (false) */\n    lua_pushvalue(L, -2);  /* error message */\n    return 2;  /* return false, msg */\n  }\n  else\n    return lua_gettop(L) - (int)extra;  /* return all results */\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  lua_pushboolean(L, 1);  /* first result if no errors */\n  lua_insert(L, 1);  /* put it in place */\n  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);\n  return finishpcall(L, status, 0);\n}\n\n\n/*\n** Do a protected call with error handling. After 'lua_rotate', the\n** stack will have <f, err, true, f, [args...]>; so, the function passes\n** 2 to 'finishpcall' to skip the 2 first values when returning results.\n*/\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  int n = lua_gettop(L);\n  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */\n  lua_pushboolean(L, 1);  /* first result */\n  lua_pushvalue(L, 1);  /* function */\n  lua_rotate(L, 3, 2);  /* move them below function's arguments */\n  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);\n  return finishpcall(L, status, 2);\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_tolstring(L, 1, NULL);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"ipairs\", luaB_ipairs},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n  {\"next\", luaB_next},\n  {\"pairs\", luaB_pairs},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"warn\", luaB_warn},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawlen\", luaB_rawlen},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"xpcall\", luaB_xpcall},\n  /* placeholders */\n  {LUA_GNAME, NULL},\n  {\"_VERSION\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_base (lua_State *L) {\n  /* open lib into global table */\n  lua_pushglobaltable(L);\n  luaL_setfuncs(L, base_funcs, 0);\n  /* set global _G */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, LUA_GNAME);\n  /* set global _VERSION */\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setfield(L, -2, \"_VERSION\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lcode.c",
    "content": "/*\n** $Id: lcode.c $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <math.h>\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/* Maximum number of registers in a Lua function (must fit in 8 bits) */\n#define MAXREGS\t\t255\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\nstatic int codesJ (FuncState *fs, OpCode o, int sj, int k);\n\n\n\n/* semantic error */\nl_noret luaK_semerror (LexState *ls, const char *msg) {\n  ls->t.token = 0;  /* remove \"near <token>\" from final message */\n  luaX_syntaxerror(ls, msg);\n}\n\n\n/*\n** If expression is a numeric constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nstatic int tonumeral (const expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a numeral */\n  switch (e->k) {\n    case VKINT:\n      if (v) setivalue(v, e->u.ival);\n      return 1;\n    case VKFLT:\n      if (v) setfltvalue(v, e->u.nval);\n      return 1;\n    default: return 0;\n  }\n}\n\n\n/*\n** Get the constant value from a constant expression\n*/\nstatic TValue *const2val (FuncState *fs, const expdesc *e) {\n  lua_assert(e->k == VCONST);\n  return &fs->ls->dyd->actvar.arr[e->u.info].k;\n}\n\n\n/*\n** If expression is a constant, fills 'v' with its value\n** and returns 1. Otherwise, returns 0.\n*/\nint luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v) {\n  if (hasjumps(e))\n    return 0;  /* not a constant */\n  switch (e->k) {\n    case VFALSE:\n      setbfvalue(v);\n      return 1;\n    case VTRUE:\n      setbtvalue(v);\n      return 1;\n    case VNIL:\n      setnilvalue(v);\n      return 1;\n    case VKSTR: {\n      setsvalue(fs->ls->L, v, e->u.strval);\n      return 1;\n    }\n    case VCONST: {\n      setobj(fs->ls->L, v, const2val(fs, e));\n      return 1;\n    }\n    default: return tonumeral(e, v);\n  }\n}\n\n\n/*\n** Return the previous instruction of the current code. If there\n** may be a jump target between the current instruction and the\n** previous one, return an invalid instruction (to avoid wrong\n** optimizations).\n*/\nstatic Instruction *previousinstruction (FuncState *fs) {\n  static const Instruction invalidinstruction = ~(Instruction)0;\n  if (fs->pc > fs->lasttarget)\n    return &fs->f->code[fs->pc - 1];  /* previous instruction */\n  else\n    return cast(Instruction*, &invalidinstruction);\n}\n\n\n/*\n** Create a OP_LOADNIL instruction, but try to optimize: if the previous\n** instruction is also OP_LOADNIL and ranges are compatible, adjust\n** range of previous instruction instead of emitting a new one. (For\n** instance, 'local a; local b' will generate a single opcode.)\n*/\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  int l = from + n - 1;  /* last register to set nil */\n  Instruction *previous = previousinstruction(fs);\n  if (GET_OPCODE(*previous) == OP_LOADNIL) {  /* previous is LOADNIL? */\n    int pfrom = GETARG_A(*previous);  /* get previous range */\n    int pl = pfrom + GETARG_B(*previous);\n    if ((pfrom <= from && from <= pl + 1) ||\n        (from <= pfrom && pfrom <= l + 1)) {  /* can connect both? */\n      if (pfrom < from) from = pfrom;  /* from = min(from, pfrom) */\n      if (pl > l) l = pl;  /* l = max(l, pl) */\n      SETARG_A(*previous, from);\n      SETARG_B(*previous, l - from);\n      return;\n    }  /* else go through */\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0);  /* else no optimization */\n}\n\n\n/*\n** Gets the destination address of a jump instruction. Used to traverse\n** a list of jumps.\n*/\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sJ(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\n/*\n** Fix jump instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua)\n*/\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  lua_assert(dest != NO_JUMP);\n  if (!(-OFFSET_sJ <= offset && offset <= MAXARG_sJ - OFFSET_sJ))\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  lua_assert(GET_OPCODE(*jmp) == OP_JMP);\n  SETARG_sJ(*jmp, offset);\n}\n\n\n/*\n** Concatenate jump-list 'l2' into jump-list 'l1'\n*/\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;  /* nothing to concatenate? */\n  else if (*l1 == NO_JUMP)  /* no original list? */\n    *l1 = l2;  /* 'l1' points to 'l2' */\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);  /* last element links to 'l2' */\n  }\n}\n\n\n/*\n** Create a jump instruction and return its position, so its destination\n** can be fixed later (with 'fixjump').\n*/\nint luaK_jump (FuncState *fs) {\n  return codesJ(fs, OP_JMP, NO_JUMP, 0);\n}\n\n\n/*\n** Code a 'return' instruction\n*/\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  OpCode op;\n  switch (nret) {\n    case 0: op = OP_RETURN0; break;\n    case 1: op = OP_RETURN1; break;\n    default: op = OP_RETURN; break;\n  }\n  luaK_codeABC(fs, op, first, nret + 1, 0);\n}\n\n\n/*\n** Code a \"conditional jump\", that is, a test or comparison opcode\n** followed by a jump. Return jump position.\n*/\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C, int k) {\n  luaK_codeABCk(fs, op, A, B, C, k);\n  return luaK_jump(fs);\n}\n\n\n/*\n** returns current 'pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\n/*\n** Returns the position of the instruction \"controlling\" a given\n** jump (that is, its condition), or the jump itself if it is\n** unconditional.\n*/\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** Patch destination register for a TESTSET instruction.\n** If instruction in position 'node' is not a TESTSET, return 0 (\"fails\").\n** Otherwise, if 'reg' is not 'NO_REG', set it as the destination\n** register. Otherwise, change instruction to a simple 'TEST' (produces\n** no register value)\n*/\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else {\n     /* no register to put value or register already has the value;\n        change instruction to simple test */\n    *i = CREATE_ABCk(OP_TEST, GETARG_B(*i), 0, 0, GETARG_k(*i));\n  }\n  return 1;\n}\n\n\n/*\n** Traverse a list of tests ensuring no one produces a value\n*/\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\n/*\n** Traverse a list of tests, patching their destination address and\n** registers: tests producing values jump to 'vtarget' (and put their\n** values in 'reg'), other tests jump to 'dtarget'.\n*/\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\n/*\n** Path all jumps in 'list' to jump to 'target'.\n** (The assert means that we cannot fix a jump to a forward address\n** because we only know addresses once code is generated.)\n*/\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  lua_assert(target <= fs->pc);\n  patchlistaux(fs, list, target, NO_REG, target);\n}\n\n\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  int hr = luaK_getlabel(fs);  /* mark \"here\" as a jump target */\n  luaK_patchlist(fs, list, hr);\n}\n\n\n/*\n** MAXimum number of successive Instructions WiTHout ABSolute line\n** information.\n*/\n#if !defined(MAXIWTHABS)\n#define MAXIWTHABS\t120\n#endif\n\n\n/* limit for difference between lines in relative line info. */\n#define LIMLINEDIFF\t0x80\n\n\n/*\n** Save line info for a new instruction. If difference from last line\n** does not fit in a byte, of after that many instructions, save a new\n** absolute line info; (in that case, the special value 'ABSLINEINFO'\n** in 'lineinfo' signals the existence of this absolute information.)\n** Otherwise, store the difference from last line in 'lineinfo'.\n*/\nstatic void savelineinfo (FuncState *fs, Proto *f, int line) {\n  int linedif = line - fs->previousline;\n  int pc = fs->pc - 1;  /* last instruction coded */\n  if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ > MAXIWTHABS) {\n    luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo,\n                    f->sizeabslineinfo, AbsLineInfo, MAX_INT, \"lines\");\n    f->abslineinfo[fs->nabslineinfo].pc = pc;\n    f->abslineinfo[fs->nabslineinfo++].line = line;\n    linedif = ABSLINEINFO;  /* signal that there is absolute information */\n    fs->iwthabs = 0;  /* restart counter */\n  }\n  luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte,\n                  MAX_INT, \"opcodes\");\n  f->lineinfo[pc] = linedif;\n  fs->previousline = line;  /* last line saved */\n}\n\n\n/*\n** Remove line information from the last instruction.\n** If line information for that instruction is absolute, set 'iwthabs'\n** above its max to force the new (replacing) instruction to have\n** absolute line info, too.\n*/\nstatic void removelastlineinfo (FuncState *fs) {\n  Proto *f = fs->f;\n  int pc = fs->pc - 1;  /* last instruction coded */\n  if (f->lineinfo[pc] != ABSLINEINFO) {  /* relative line info? */\n    fs->previousline -= f->lineinfo[pc];  /* correct last line saved */\n    fs->iwthabs--;  /* undo previous increment */\n  }\n  else {  /* absolute line information */\n    lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == pc);\n    fs->nabslineinfo--;  /* remove it */\n    fs->iwthabs = MAXIWTHABS + 1;  /* force next line info to be absolute */\n  }\n}\n\n\n/*\n** Remove the last instruction created, correcting line information\n** accordingly.\n*/\nstatic void removelastinstruction (FuncState *fs) {\n  removelastlineinfo(fs);\n  fs->pc--;\n}\n\n\n/*\n** Emit instruction 'i', checking for array sizes and saving also its\n** line information. Return 'i' position.\n*/\nint luaK_code (FuncState *fs, Instruction i) {\n  Proto *f = fs->f;\n  /* put new instruction in code array */\n  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"opcodes\");\n  f->code[fs->pc++] = i;\n  savelineinfo(fs, f, fs->ls->lastline);\n  return fs->pc - 1;  /* index of new instruction */\n}\n\n\n/*\n** Format and emit an 'iABC' instruction. (Assertions check consistency\n** of parameters versus opcode.)\n*/\nint luaK_codeABCk (FuncState *fs, OpCode o, int a, int b, int c, int k) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_B &&\n             c <= MAXARG_C && (k & ~1) == 0);\n  return luaK_code(fs, CREATE_ABCk(o, a, b, c, k));\n}\n\n\n/*\n** Format and emit an 'iABx' instruction.\n*/\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx);\n  lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, bc));\n}\n\n\n/*\n** Format and emit an 'iAsBx' instruction.\n*/\nint luaK_codeAsBx (FuncState *fs, OpCode o, int a, int bc) {\n  unsigned int b = bc + OFFSET_sBx;\n  lua_assert(getOpMode(o) == iAsBx);\n  lua_assert(a <= MAXARG_A && b <= MAXARG_Bx);\n  return luaK_code(fs, CREATE_ABx(o, a, b));\n}\n\n\n/*\n** Format and emit an 'isJ' instruction.\n*/\nstatic int codesJ (FuncState *fs, OpCode o, int sj, int k) {\n  unsigned int j = sj + OFFSET_sJ;\n  lua_assert(getOpMode(o) == isJ);\n  lua_assert(j <= MAXARG_sJ && (k & ~1) == 0);\n  return luaK_code(fs, CREATE_sJ(o, j, k));\n}\n\n\n/*\n** Emit an \"extra argument\" instruction (format 'iAx')\n*/\nstatic int codeextraarg (FuncState *fs, int a) {\n  lua_assert(a <= MAXARG_Ax);\n  return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));\n}\n\n\n/*\n** Emit a \"load constant\" instruction, using either 'OP_LOADK'\n** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'\n** instruction with \"extra argument\".\n*/\nstatic int luaK_codek (FuncState *fs, int reg, int k) {\n  if (k <= MAXARG_Bx)\n    return luaK_codeABx(fs, OP_LOADK, reg, k);\n  else {\n    int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);\n    codeextraarg(fs, k);\n    return p;\n  }\n}\n\n\n/*\n** Check register-stack level, keeping track of its maximum size\n** in field 'maxstacksize'\n*/\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXREGS)\n      luaX_syntaxerror(fs->ls,\n        \"function or expression needs too many registers\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\n/*\n** Reserve 'n' registers in register stack\n*/\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\n/*\n** Free register 'reg', if it is neither a constant index nor\n** a local variable.\n)\n*/\nstatic void freereg (FuncState *fs, int reg) {\n  if (reg >= luaY_nvarstack(fs)) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\n/*\n** Free two registers in proper order\n*/\nstatic void freeregs (FuncState *fs, int r1, int r2) {\n  if (r1 > r2) {\n    freereg(fs, r1);\n    freereg(fs, r2);\n  }\n  else {\n    freereg(fs, r2);\n    freereg(fs, r1);\n  }\n}\n\n\n/*\n** Free register used by expression 'e' (if any)\n*/\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.info);\n}\n\n\n/*\n** Free registers used by expressions 'e1' and 'e2' (if any) in proper\n** order.\n*/\nstatic void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {\n  int r1 = (e1->k == VNONRELOC) ? e1->u.info : -1;\n  int r2 = (e2->k == VNONRELOC) ? e2->u.info : -1;\n  freeregs(fs, r1, r2);\n}\n\n\n/*\n** Add constant 'v' to prototype's list of constants (field 'k').\n** Use scanner's table to cache position of constants in constant list\n** and try to reuse constants. Because some values should not be used\n** as keys (nil cannot be a key, integer keys can collapse with float\n** keys), the caller must provide a useful 'key' for indexing the cache.\n*/\nstatic int addk (FuncState *fs, TValue *key, TValue *v) {\n  lua_State *L = fs->ls->L;\n  Proto *f = fs->f;\n  TValue *idx = luaH_set(L, fs->ls->h, key);  /* index scanner table */\n  int k, oldsize;\n  if (ttisinteger(idx)) {  /* is there an index there? */\n    k = cast_int(ivalue(idx));\n    /* correct value? (warning: must distinguish floats from integers!) */\n    if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&\n                      luaV_rawequalobj(&f->k[k], v))\n      return k;  /* reuse index */\n  }\n  /* constant not found; create a new entry */\n  oldsize = f->sizek;\n  k = fs->nk;\n  /* numerical value does not need GC barrier;\n     table has no metatable, so it does not need to invalidate cache */\n  setivalue(idx, k);\n  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, \"constants\");\n  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n  setobj(L, &f->k[k], v);\n  fs->nk++;\n  luaC_barrier(L, f, v);\n  return k;\n}\n\n\n/*\n** Add a string to list of constants and return its index.\n*/\nstatic int stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->ls->L, &o, s);\n  return addk(fs, &o, &o);  /* use string itself as key */\n}\n\n\n/*\n** Add an integer to list of constants and return its index.\n** Integers use userdata as keys to avoid collision with floats with\n** same value; conversion to 'void*' is used only for hashing, so there\n** are no \"precision\" problems.\n*/\nstatic int luaK_intK (FuncState *fs, lua_Integer n) {\n  TValue k, o;\n  setpvalue(&k, cast_voidp(cast_sizet(n)));\n  setivalue(&o, n);\n  return addk(fs, &k, &o);\n}\n\n/*\n** Add a float to list of constants and return its index.\n*/\nstatic int luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setfltvalue(&o, r);\n  return addk(fs, &o, &o);  /* use number itself as key */\n}\n\n\n/*\n** Add a false to list of constants and return its index.\n*/\nstatic int boolF (FuncState *fs) {\n  TValue o;\n  setbfvalue(&o);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add a true to list of constants and return its index.\n*/\nstatic int boolT (FuncState *fs) {\n  TValue o;\n  setbtvalue(&o);\n  return addk(fs, &o, &o);  /* use boolean itself as key */\n}\n\n\n/*\n** Add nil to list of constants and return its index.\n*/\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->ls->L, &k, fs->ls->h);\n  return addk(fs, &k, &v);\n}\n\n\n/*\n** Check whether 'i' can be stored in an 'sC' operand. Equivalent to\n** (0 <= int2sC(i) && int2sC(i) <= MAXARG_C) but without risk of\n** overflows in the hidden addition inside 'int2sC'.\n*/\nstatic int fitsC (lua_Integer i) {\n  return (l_castS2U(i) + OFFSET_sC <= cast_uint(MAXARG_C));\n}\n\n\n/*\n** Check whether 'i' can be stored in an 'sBx' operand.\n*/\nstatic int fitsBx (lua_Integer i) {\n  return (-OFFSET_sBx <= i && i <= MAXARG_Bx - OFFSET_sBx);\n}\n\n\nvoid luaK_int (FuncState *fs, int reg, lua_Integer i) {\n  if (fitsBx(i))\n    luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i));\n  else\n    luaK_codek(fs, reg, luaK_intK(fs, i));\n}\n\n\nstatic void luaK_float (FuncState *fs, int reg, lua_Number f) {\n  lua_Integer fi;\n  if (luaV_flttointeger(f, &fi, F2Ieq) && fitsBx(fi))\n    luaK_codeAsBx(fs, OP_LOADF, reg, cast_int(fi));\n  else\n    luaK_codek(fs, reg, luaK_numberK(fs, f));\n}\n\n\n/*\n** Convert a constant in 'v' into an expression description 'e'\n*/\nstatic void const2exp (TValue *v, expdesc *e) {\n  switch (ttypetag(v)) {\n    case LUA_VNUMINT:\n      e->k = VKINT; e->u.ival = ivalue(v);\n      break;\n    case LUA_VNUMFLT:\n      e->k = VKFLT; e->u.nval = fltvalue(v);\n      break;\n    case LUA_VFALSE:\n      e->k = VFALSE;\n      break;\n    case LUA_VTRUE:\n      e->k = VTRUE;\n      break;\n    case LUA_VNIL:\n      e->k = VNIL;\n      break;\n    case LUA_VSHRSTR:  case LUA_VLNGSTR:\n      e->k = VKSTR; e->u.strval = tsvalue(v);\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Fix an expression to return the number of results 'nresults'.\n** 'e' must be a multi-ret expression (function call or vararg).\n*/\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  Instruction *pc = &getinstruction(fs, e);\n  if (e->k == VCALL)  /* expression is an open function call? */\n    SETARG_C(*pc, nresults + 1);\n  else {\n    lua_assert(e->k == VVARARG);\n    SETARG_C(*pc, nresults + 1);\n    SETARG_A(*pc, fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\n/*\n** Convert a VKSTR to a VK\n*/\nstatic void str2K (FuncState *fs, expdesc *e) {\n  lua_assert(e->k == VKSTR);\n  e->u.info = stringK(fs, e->u.strval);\n  e->k = VK;\n}\n\n\n/*\n** Fix an expression to return one result.\n** If expression is not a multi-ret expression (function call or\n** vararg), it already returns one result, so nothing needs to be done.\n** Function calls become VNONRELOC expressions (as its result comes\n** fixed in the base register of the call), while vararg expressions\n** become VRELOC (as OP_VARARG puts its results where it wants).\n** (Calls are created returning one result, so that does not need\n** to be fixed.)\n*/\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    /* already returns 1 value */\n    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);\n    e->k = VNONRELOC;  /* result has fixed position */\n    e->u.info = GETARG_A(getinstruction(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_C(getinstruction(fs, e), 2);\n    e->k = VRELOC;  /* can relocate its simple result */\n  }\n}\n\n\n/*\n** Ensure that expression 'e' is not a variable (nor a constant).\n** (Expression still may have jump lists.)\n*/\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VCONST: {\n      const2exp(const2val(fs, e), e);\n      break;\n    }\n    case VLOCAL: {  /* already in a register */\n      e->u.info = e->u.var.sidx;\n      e->k = VNONRELOC;  /* becomes a non-relocatable value */\n      break;\n    }\n    case VUPVAL: {  /* move value to some (pending) register */\n      e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);\n      e->k = VRELOC;\n      break;\n    }\n    case VINDEXUP: {\n      e->u.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOC;\n      break;\n    }\n    case VINDEXI: {\n      freereg(fs, e->u.ind.t);\n      e->u.info = luaK_codeABC(fs, OP_GETI, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOC;\n      break;\n    }\n    case VINDEXSTR: {\n      freereg(fs, e->u.ind.t);\n      e->u.info = luaK_codeABC(fs, OP_GETFIELD, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOC;\n      break;\n    }\n    case VINDEXED: {\n      freeregs(fs, e->u.ind.t, e->u.ind.idx);\n      e->u.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.ind.t, e->u.ind.idx);\n      e->k = VRELOC;\n      break;\n    }\n    case VVARARG: case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\n/*\n** Ensures expression value is in register 'reg' (and therefore\n** 'e' will become a non-relocatable expression).\n** (Expression still may have jump lists.)\n*/\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE: {\n      luaK_codeABC(fs, OP_LOADFALSE, reg, 0, 0);\n      break;\n    }\n    case VTRUE: {\n      luaK_codeABC(fs, OP_LOADTRUE, reg, 0, 0);\n      break;\n    }\n    case VKSTR: {\n      str2K(fs, e);\n    }  /* FALLTHROUGH */\n    case VK: {\n      luaK_codek(fs, reg, e->u.info);\n      break;\n    }\n    case VKFLT: {\n      luaK_float(fs, reg, e->u.nval);\n      break;\n    }\n    case VKINT: {\n      luaK_int(fs, reg, e->u.ival);\n      break;\n    }\n    case VRELOC: {\n      Instruction *pc = &getinstruction(fs, e);\n      SETARG_A(*pc, reg);  /* instruction will put result in 'reg' */\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures expression value is in any register.\n** (Expression still may have jump lists.)\n*/\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {  /* no fixed register yet? */\n    luaK_reserveregs(fs, 1);  /* get a register */\n    discharge2reg(fs, e, fs->freereg-1);  /* put value there */\n  }\n}\n\n\nstatic int code_loadbool (FuncState *fs, int A, OpCode op) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, op, A, 0, 0);\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** or produce an inverted value\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\n/*\n** Ensures final expression result (which includes results from its\n** jump lists) is in register 'reg'.\n** If expression has jumps, need to patch these jumps either to\n** its final position or to \"load\" instructions (for those tests\n** that do not produce values).\n*/\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)  /* expression itself is a test? */\n    luaK_concat(fs, &e->t, e->u.info);  /* put this jump in 't' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_loadbool(fs, reg, OP_LFALSESKIP);  /* skip next inst. */\n      p_t = code_loadbool(fs, reg, OP_LOADTRUE);\n      /* jump around these booleans if 'e' is not a test */\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.info = reg;\n  e->k = VNONRELOC;\n}\n\n\n/*\n** Ensures final expression result is in next available register.\n*/\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\n/*\n** Ensures final expression result is in some (any) register\n** and return that register.\n*/\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {  /* expression already has a register? */\n    if (!hasjumps(e))  /* no jumps? */\n      return e->u.info;  /* result is already in a register */\n    if (e->u.info >= luaY_nvarstack(fs)) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.info);  /* put final result in it */\n      return e->u.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* otherwise, use next available register */\n  return e->u.info;\n}\n\n\n/*\n** Ensures final expression result is either in a register\n** or in an upvalue.\n*/\nvoid luaK_exp2anyregup (FuncState *fs, expdesc *e) {\n  if (e->k != VUPVAL || hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n}\n\n\n/*\n** Ensures final expression result is either in a register\n** or it is a constant.\n*/\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\n/*\n** Try to make 'e' a K expression with an index in the range of R/K\n** indices. Return true iff succeeded.\n*/\nstatic int luaK_exp2K (FuncState *fs, expdesc *e) {\n  if (!hasjumps(e)) {\n    int info;\n    switch (e->k) {  /* move constants to 'k' */\n      case VTRUE: info = boolT(fs); break;\n      case VFALSE: info = boolF(fs); break;\n      case VNIL: info = nilK(fs); break;\n      case VKINT: info = luaK_intK(fs, e->u.ival); break;\n      case VKFLT: info = luaK_numberK(fs, e->u.nval); break;\n      case VKSTR: info = stringK(fs, e->u.strval); break;\n      case VK: info = e->u.info; break;\n      default: return 0;  /* not a constant */\n    }\n    if (info <= MAXINDEXRK) {  /* does constant fit in 'argC'? */\n      e->k = VK;  /* make expression a 'K' expression */\n      e->u.info = info;\n      return 1;\n    }\n  }\n  /* else, expression doesn't fit; leave it unchanged */\n  return 0;\n}\n\n\n/*\n** Ensures final expression result is in a valid R/K index\n** (that is, it is either in a register or in 'k' with an index\n** in the range of R/K indices).\n** Returns 1 iff expression is K.\n*/\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  if (luaK_exp2K(fs, e))\n    return 1;\n  else {  /* not a constant in the right range: put it in a register */\n    luaK_exp2anyreg(fs, e);\n    return 0;\n  }\n}\n\n\nstatic void codeABRK (FuncState *fs, OpCode o, int a, int b,\n                      expdesc *ec) {\n  int k = luaK_exp2RK(fs, ec);\n  luaK_codeABCk(fs, o, a, b, ec->u.info, k);\n}\n\n\n/*\n** Generate code to store result of expression 'ex' into variable 'var'.\n*/\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.var.sidx);  /* compute 'ex' into proper place */\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);\n      break;\n    }\n    case VINDEXUP: {\n      codeABRK(fs, OP_SETTABUP, var->u.ind.t, var->u.ind.idx, ex);\n      break;\n    }\n    case VINDEXI: {\n      codeABRK(fs, OP_SETI, var->u.ind.t, var->u.ind.idx, ex);\n      break;\n    }\n    case VINDEXSTR: {\n      codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex);\n      break;\n    }\n    case VINDEXED: {\n      codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex);\n      break;\n    }\n    default: lua_assert(0);  /* invalid var kind to store */\n  }\n  freeexp(fs, ex);\n}\n\n\n/*\n** Emit SELF instruction (convert expression 'e' into 'e:key(e,').\n*/\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int ereg;\n  luaK_exp2anyreg(fs, e);\n  ereg = e->u.info;  /* register where 'e' was placed */\n  freeexp(fs, e);\n  e->u.info = fs->freereg;  /* base register for op_self */\n  e->k = VNONRELOC;  /* self expression has a fixed register */\n  luaK_reserveregs(fs, 2);  /* function and 'self' produced by op_self */\n  codeABRK(fs, OP_SELF, e->u.info, ereg, key);\n  freeexp(fs, key);\n}\n\n\n/*\n** Negate condition 'e' (where 'e' is a comparison).\n*/\nstatic void negatecondition (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_k(*pc, (GETARG_k(*pc) ^ 1));\n}\n\n\n/*\n** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'\n** is true, code will jump if 'e' is true.) Return jump position.\n** Optimize when 'e' is 'not' something, inverting the condition\n** and removing the 'not'.\n*/\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOC) {\n    Instruction ie = getinstruction(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      removelastinstruction(fs);  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.info, 0, cond);\n}\n\n\n/*\n** Emit code to go through if 'e' is true, jump otherwise.\n*/\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {  /* condition? */\n      negatecondition(fs, e);  /* jump when it is false */\n      pc = e->u.info;  /* save jump position */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);  /* jump when false */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert new jump in false list */\n  luaK_patchtohere(fs, e->t);  /* true list jumps to here (to go through) */\n  e->t = NO_JUMP;\n}\n\n\n/*\n** Emit code to go through if 'e' is false, jump otherwise.\n*/\nvoid luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of new jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VJMP: {\n      pc = e->u.info;  /* already jump if true */\n      break;\n    }\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);  /* jump if true */\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert new jump in 't' list */\n  luaK_patchtohere(fs, e->f);  /* false list jumps to here (to go through) */\n  e->f = NO_JUMP;\n}\n\n\n/*\n** Code 'not e', doing constant folding.\n*/\nstatic void codenot (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;  /* true == not nil == not false */\n      break;\n    }\n    case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {\n      e->k = VFALSE;  /* false == not \"x\" == not 0.5 == not 1 == not true */\n      break;\n    }\n    case VJMP: {\n      negatecondition(fs, e);\n      break;\n    }\n    case VRELOC:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0);\n      e->k = VRELOC;\n      break;\n    }\n    default: lua_assert(0);  /* cannot happen */\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);  /* values are useless when negated */\n  removevalues(fs, e->t);\n}\n\n\n/*\n** Check whether expression 'e' is a small literal string\n*/\nstatic int isKstr (FuncState *fs, expdesc *e) {\n  return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B &&\n          ttisshrstring(&fs->f->k[e->u.info]));\n}\n\n/*\n** Check whether expression 'e' is a literal integer.\n*/\nint luaK_isKint (expdesc *e) {\n  return (e->k == VKINT && !hasjumps(e));\n}\n\n\n/*\n** Check whether expression 'e' is a literal integer in\n** proper range to fit in register C\n*/\nstatic int isCint (expdesc *e) {\n  return luaK_isKint(e) && (l_castS2U(e->u.ival) <= l_castS2U(MAXARG_C));\n}\n\n\n/*\n** Check whether expression 'e' is a literal integer in\n** proper range to fit in register sC\n*/\nstatic int isSCint (expdesc *e) {\n  return luaK_isKint(e) && fitsC(e->u.ival);\n}\n\n\n/*\n** Check whether expression 'e' is a literal integer or float in\n** proper range to fit in a register (sB or sC).\n*/\nstatic int isSCnumber (expdesc *e, int *pi, int *isfloat) {\n  lua_Integer i;\n  if (e->k == VKINT)\n    i = e->u.ival;\n  else if (e->k == VKFLT && luaV_flttointeger(e->u.nval, &i, F2Ieq))\n    *isfloat = 1;\n  else\n    return 0;  /* not a number */\n  if (!hasjumps(e) && fitsC(i)) {\n    *pi = int2sC(cast_int(i));\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Create expression 't[k]'. 't' must have its final result already in a\n** register or upvalue. Upvalues can only be indexed by literal strings.\n** Keys can be literal strings in the constant table or arbitrary\n** values in registers.\n*/\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  if (k->k == VKSTR)\n    str2K(fs, k);\n  lua_assert(!hasjumps(t) &&\n             (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL));\n  if (t->k == VUPVAL && !isKstr(fs, k))  /* upvalue indexed by non 'Kstr'? */\n    luaK_exp2anyreg(fs, t);  /* put it in a register */\n  if (t->k == VUPVAL) {\n    t->u.ind.t = t->u.info;  /* upvalue index */\n    t->u.ind.idx = k->u.info;  /* literal string */\n    t->k = VINDEXUP;\n  }\n  else {\n    /* register index of the table */\n    t->u.ind.t = (t->k == VLOCAL) ? t->u.var.sidx: t->u.info;\n    if (isKstr(fs, k)) {\n      t->u.ind.idx = k->u.info;  /* literal string */\n      t->k = VINDEXSTR;\n    }\n    else if (isCint(k)) {\n      t->u.ind.idx = cast_int(k->u.ival);  /* int. constant in proper range */\n      t->k = VINDEXI;\n    }\n    else {\n      t->u.ind.idx = luaK_exp2anyreg(fs, k);  /* register */\n      t->k = VINDEXED;\n    }\n  }\n}\n\n\n/*\n** Return false if folding can raise an error.\n** Bitwise operations need operands convertible to integers; division\n** operations cannot have 0 as divisor.\n*/\nstatic int validop (int op, TValue *v1, TValue *v2) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: {  /* conversion errors */\n      lua_Integer i;\n      return (tointegerns(v1, &i) && tointegerns(v2, &i));\n    }\n    case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD:  /* division by 0 */\n      return (nvalue(v2) != 0);\n    default: return 1;  /* everything else is valid */\n  }\n}\n\n\n/*\n** Try to \"constant-fold\" an operation; return 1 iff successful.\n** (In this case, 'e1' has the final result.)\n*/\nstatic int constfolding (FuncState *fs, int op, expdesc *e1,\n                                        const expdesc *e2) {\n  TValue v1, v2, res;\n  if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))\n    return 0;  /* non-numeric operands or not safe to fold */\n  luaO_rawarith(fs->ls->L, op, &v1, &v2, &res);  /* does operation */\n  if (ttisinteger(&res)) {\n    e1->k = VKINT;\n    e1->u.ival = ivalue(&res);\n  }\n  else {  /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */\n    lua_Number n = fltvalue(&res);\n    if (luai_numisnan(n) || n == 0)\n      return 0;\n    e1->k = VKFLT;\n    e1->u.nval = n;\n  }\n  return 1;\n}\n\n\n/*\n** Emit code for unary expressions that \"produce values\"\n** (everything but 'not').\n** Expression to produce final result will be encoded in 'e'.\n*/\nstatic void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {\n  int r = luaK_exp2anyreg(fs, e);  /* opcodes operate only on registers */\n  freeexp(fs, e);\n  e->u.info = luaK_codeABC(fs, op, 0, r, 0);  /* generate opcode */\n  e->k = VRELOC;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\"\n** (everything but logical operators 'and'/'or' and comparison\n** operators).\n** Expression to produce final result will be encoded in 'e1'.\n*/\nstatic void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,\n                             OpCode op, int v2, int flip, int line,\n                             OpCode mmop, TMS event) {\n  int v1 = luaK_exp2anyreg(fs, e1);\n  int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0);\n  freeexps(fs, e1, e2);\n  e1->u.info = pc;\n  e1->k = VRELOC;  /* all those operations are relocatable */\n  luaK_fixline(fs, line);\n  luaK_codeABCk(fs, mmop, v1, v2, event, flip);  /* to call metamethod */\n  luaK_fixline(fs, line);\n}\n\n\n/*\n** Emit code for binary expressions that \"produce values\" over\n** two registers.\n*/\nstatic void codebinexpval (FuncState *fs, OpCode op,\n                           expdesc *e1, expdesc *e2, int line) {\n  int v2 = luaK_exp2anyreg(fs, e2);  /* both operands are in registers */\n  lua_assert(OP_ADD <= op && op <= OP_SHR);\n  finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,\n                  cast(TMS, (op - OP_ADD) + TM_ADD));\n}\n\n\n/*\n** Code binary operators with immediate operands.\n*/\nstatic void codebini (FuncState *fs, OpCode op,\n                       expdesc *e1, expdesc *e2, int flip, int line,\n                       TMS event) {\n  int v2 = int2sC(cast_int(e2->u.ival));  /* immediate operand */\n  lua_assert(e2->k == VKINT);\n  finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINI, event);\n}\n\n\n/* Try to code a binary operator negating its second operand.\n** For the metamethod, 2nd operand must keep its original value.\n*/\nstatic int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2,\n                             OpCode op, int line, TMS event) {\n  if (!luaK_isKint(e2))\n    return 0;  /* not an integer constant */\n  else {\n    lua_Integer i2 = e2->u.ival;\n    if (!(fitsC(i2) && fitsC(-i2)))\n      return 0;  /* not in the proper range */\n    else {  /* operating a small integer constant */\n      int v2 = cast_int(i2);\n      finishbinexpval(fs, e1, e2, op, int2sC(-v2), 0, line, OP_MMBINI, event);\n      /* correct metamethod argument */\n      SETARG_B(fs->f->code[fs->pc - 1], int2sC(v2));\n      return 1;  /* successfully coded */\n    }\n  }\n}\n\n\nstatic void swapexps (expdesc *e1, expdesc *e2) {\n  expdesc temp = *e1; *e1 = *e2; *e2 = temp;  /* swap 'e1' and 'e2' */\n}\n\n\n/*\n** Code arithmetic operators ('+', '-', ...). If second operand is a\n** constant in the proper range, use variant opcodes with K operands.\n*/\nstatic void codearith (FuncState *fs, BinOpr opr,\n                       expdesc *e1, expdesc *e2, int flip, int line) {\n  TMS event = cast(TMS, opr + TM_ADD);\n  if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) {  /* K operand? */\n    int v2 = e2->u.info;  /* K index */\n    OpCode op = cast(OpCode, opr + OP_ADDK);\n    finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);\n  }\n  else {  /* 'e2' is neither an immediate nor a K operand */\n    OpCode op = cast(OpCode, opr + OP_ADD);\n    if (flip)\n      swapexps(e1, e2);  /* back to original order */\n    codebinexpval(fs, op, e1, e2, line);  /* use standard operators */\n  }\n}\n\n\n/*\n** Code commutative operators ('+', '*'). If first operand is a\n** numeric constant, change order of operands to try to use an\n** immediate or K operator.\n*/\nstatic void codecommutative (FuncState *fs, BinOpr op,\n                             expdesc *e1, expdesc *e2, int line) {\n  int flip = 0;\n  if (tonumeral(e1, NULL)) {  /* is first operand a numeric constant? */\n    swapexps(e1, e2);  /* change order */\n    flip = 1;\n  }\n  if (op == OPR_ADD && isSCint(e2))  /* immediate operand? */\n    codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);\n  else\n    codearith(fs, op, e1, e2, flip, line);\n}\n\n\n/*\n** Code bitwise operations; they are all associative, so the function\n** tries to put an integer constant as the 2nd operand (a K operand).\n*/\nstatic void codebitwise (FuncState *fs, BinOpr opr,\n                         expdesc *e1, expdesc *e2, int line) {\n  int flip = 0;\n  int v2;\n  OpCode op;\n  if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {\n    swapexps(e1, e2);  /* 'e2' will be the constant operand */\n    flip = 1;\n  }\n  else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) {  /* no constants? */\n    op = cast(OpCode, opr + OP_ADD);\n    codebinexpval(fs, op, e1, e2, line);  /* all-register opcodes */\n    return;\n  }\n  v2 = e2->u.info;  /* index in K array */\n  op = cast(OpCode, opr + OP_ADDK);\n  lua_assert(ttisinteger(&fs->f->k[v2]));\n  finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,\n                  cast(TMS, opr + TM_ADD));\n}\n\n\n/*\n** Emit code for order comparisons. When using an immediate operand,\n** 'isfloat' tells whether the original value was a float.\n*/\nstatic void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {\n  int r1, r2;\n  int im;\n  int isfloat = 0;\n  if (isSCnumber(e2, &im, &isfloat)) {\n    /* use immediate operand */\n    r1 = luaK_exp2anyreg(fs, e1);\n    r2 = im;\n    op = cast(OpCode, (op - OP_LT) + OP_LTI);\n  }\n  else if (isSCnumber(e1, &im, &isfloat)) {\n    /* transform (A < B) to (B > A) and (A <= B) to (B >= A) */\n    r1 = luaK_exp2anyreg(fs, e2);\n    r2 = im;\n    op = (op == OP_LT) ? OP_GTI : OP_GEI;\n  }\n  else {  /* regular case, compare two registers */\n    r1 = luaK_exp2anyreg(fs, e1);\n    r2 = luaK_exp2anyreg(fs, e2);\n  }\n  freeexps(fs, e1, e2);\n  e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);\n  e1->k = VJMP;\n}\n\n\n/*\n** Emit code for equality comparisons ('==', '~=').\n** 'e1' was already put as RK by 'luaK_infix'.\n*/\nstatic void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {\n  int r1, r2;\n  int im;\n  int isfloat = 0;  /* not needed here, but kept for symmetry */\n  OpCode op;\n  if (e1->k != VNONRELOC) {\n    lua_assert(e1->k == VK || e1->k == VKINT || e1->k == VKFLT);\n    swapexps(e1, e2);\n  }\n  r1 = luaK_exp2anyreg(fs, e1);  /* 1st expression must be in register */\n  if (isSCnumber(e2, &im, &isfloat)) {\n    op = OP_EQI;\n    r2 = im;  /* immediate operand */\n  }\n  else if (luaK_exp2RK(fs, e2)) {  /* 1st expression is constant? */\n    op = OP_EQK;\n    r2 = e2->u.info;  /* constant index */\n  }\n  else {\n    op = OP_EQ;  /* will compare two registers */\n    r2 = luaK_exp2anyreg(fs, e2);\n  }\n  freeexps(fs, e1, e2);\n  e1->u.info = condjump(fs, op, r1, r2, isfloat, (opr == OPR_EQ));\n  e1->k = VJMP;\n}\n\n\n/*\n** Apply prefix operation 'op' to expression 'e'.\n*/\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {\n  static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};\n  luaK_dischargevars(fs, e);\n  switch (op) {\n    case OPR_MINUS: case OPR_BNOT:  /* use 'ef' as fake 2nd operand */\n      if (constfolding(fs, op + LUA_OPUNM, e, &ef))\n        break;\n      /* else */ /* FALLTHROUGH */\n    case OPR_LEN:\n      codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);\n      break;\n    case OPR_NOT: codenot(fs, e); break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Process 1st operand 'v' of binary operation 'op' before reading\n** 2nd operand.\n*/\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  luaK_dischargevars(fs, v);\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);  /* go ahead only if 'v' is true */\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);  /* go ahead only if 'v' is false */\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the stack */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB:\n    case OPR_MUL: case OPR_DIV: case OPR_IDIV:\n    case OPR_MOD: case OPR_POW:\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR:\n    case OPR_SHL: case OPR_SHR: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2anyreg(fs, v);\n      /* else keep numeral, which may be folded with 2nd operand */\n      break;\n    }\n    case OPR_EQ: case OPR_NE: {\n      if (!tonumeral(v, NULL))\n        luaK_exp2RK(fs, v);\n      /* else keep numeral, which may be an immediate operand */\n      break;\n    }\n    case OPR_LT: case OPR_LE:\n    case OPR_GT: case OPR_GE: {\n      int dummy, dummy2;\n      if (!isSCnumber(v, &dummy, &dummy2))\n        luaK_exp2anyreg(fs, v);\n      /* else keep numeral, which may be an immediate operand */\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n/*\n** Create code for '(e1 .. e2)'.\n** For '(e1 .. e2.1 .. e2.2)' (which is '(e1 .. (e2.1 .. e2.2))',\n** because concatenation is right associative), merge both CONCATs.\n*/\nstatic void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) {\n  Instruction *ie2 = previousinstruction(fs);\n  if (GET_OPCODE(*ie2) == OP_CONCAT) {  /* is 'e2' a concatenation? */\n    int n = GETARG_B(*ie2);  /* # of elements concatenated in 'e2' */\n    lua_assert(e1->u.info + 1 == GETARG_A(*ie2));\n    freeexp(fs, e2);\n    SETARG_A(*ie2, e1->u.info);  /* correct first element ('e1') */\n    SETARG_B(*ie2, n + 1);  /* will concatenate one more element */\n  }\n  else {  /* 'e2' is not a concatenation */\n    luaK_codeABC(fs, OP_CONCAT, e1->u.info, 2, 0);  /* new concat opcode */\n    freeexp(fs, e2);\n    luaK_fixline(fs, line);\n  }\n}\n\n\n/*\n** Finalize code for binary operation, after reading 2nd operand.\n*/\nvoid luaK_posfix (FuncState *fs, BinOpr opr,\n                  expdesc *e1, expdesc *e2, int line) {\n  luaK_dischargevars(fs, e2);\n  if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2))\n    return;  /* done by folding */\n  switch (opr) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list closed by 'luaK_infix' */\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list closed by 'luaK_infix' */\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {  /* e1 .. e2 */\n      luaK_exp2nextreg(fs, e2);\n      codeconcat(fs, e1, e2, line);\n      break;\n    }\n    case OPR_ADD: case OPR_MUL: {\n      codecommutative(fs, opr, e1, e2, line);\n      break;\n    }\n    case OPR_SUB: {\n      if (finishbinexpneg(fs, e1, e2, OP_ADDI, line, TM_SUB))\n        break; /* coded as (r1 + -I) */\n      /* ELSE */\n    }  /* FALLTHROUGH */\n    case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: {\n      codearith(fs, opr, e1, e2, 0, line);\n      break;\n    }\n    case OPR_BAND: case OPR_BOR: case OPR_BXOR: {\n      codebitwise(fs, opr, e1, e2, line);\n      break;\n    }\n    case OPR_SHL: {\n      if (isSCint(e1)) {\n        swapexps(e1, e2);\n        codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL);  /* I << r2 */\n      }\n      else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {\n        /* coded as (r1 >> -I) */;\n      }\n      else  /* regular case (two registers) */\n       codebinexpval(fs, OP_SHL, e1, e2, line);\n      break;\n    }\n    case OPR_SHR: {\n      if (isSCint(e2))\n        codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR);  /* r1 >> I */\n      else  /* regular case (two registers) */\n        codebinexpval(fs, OP_SHR, e1, e2, line);\n      break;\n    }\n    case OPR_EQ: case OPR_NE: {\n      codeeq(fs, opr, e1, e2);\n      break;\n    }\n    case OPR_LT: case OPR_LE: {\n      OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);\n      codeorder(fs, op, e1, e2);\n      break;\n    }\n    case OPR_GT: case OPR_GE: {\n      /* '(a > b)' <=> '(b < a)';  '(a >= b)' <=> '(b <= a)' */\n      OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);\n      swapexps(e1, e2);\n      codeorder(fs, op, e1, e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** Change line information associated with current position, by removing\n** previous info and adding it again with new line.\n*/\nvoid luaK_fixline (FuncState *fs, int line) {\n  removelastlineinfo(fs);\n  savelineinfo(fs, fs->f, line);\n}\n\n\nvoid luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) {\n  Instruction *inst = &fs->f->code[pc];\n  int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0;  /* hash size */\n  int extra = asize / (MAXARG_C + 1);  /* higher bits of array size */\n  int rc = asize % (MAXARG_C + 1);  /* lower bits of array size */\n  int k = (extra > 0);  /* true iff needs extra argument */\n  *inst = CREATE_ABCk(OP_NEWTABLE, ra, rb, rc, k);\n  *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra);\n}\n\n\n/*\n** Emit a SETLIST instruction.\n** 'base' is register that keeps table;\n** 'nelems' is #table plus those to be stored now;\n** 'tostore' is number of values (in registers 'base + 1',...) to add to\n** table (or LUA_MULTRET to add up to stack top).\n*/\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  lua_assert(tostore != 0 && tostore <= LFIELDS_PER_FLUSH);\n  if (tostore == LUA_MULTRET)\n    tostore = 0;\n  if (nelems <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, tostore, nelems);\n  else {\n    int extra = nelems / (MAXARG_C + 1);\n    nelems %= (MAXARG_C + 1);\n    luaK_codeABCk(fs, OP_SETLIST, base, tostore, nelems, 1);\n    codeextraarg(fs, extra);\n  }\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n\n/*\n** return the final target of a jump (skipping jumps to jumps)\n*/\nstatic int finaltarget (Instruction *code, int i) {\n  int count;\n  for (count = 0; count < 100; count++) {  /* avoid infinite loops */\n    Instruction pc = code[i];\n    if (GET_OPCODE(pc) != OP_JMP)\n      break;\n     else\n       i += GETARG_sJ(pc) + 1;\n  }\n  return i;\n}\n\n\n/*\n** Do a final pass over the code of a function, doing small peephole\n** optimizations and adjustments.\n*/\nvoid luaK_finish (FuncState *fs) {\n  int i;\n  Proto *p = fs->f;\n  for (i = 0; i < fs->pc; i++) {\n    Instruction *pc = &p->code[i];\n    lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));\n    switch (GET_OPCODE(*pc)) {\n      case OP_RETURN0: case OP_RETURN1: {\n        if (!(fs->needclose || p->is_vararg))\n          break;  /* no extra work */\n        /* else use OP_RETURN to do the extra work */\n        SET_OPCODE(*pc, OP_RETURN);\n      }  /* FALLTHROUGH */\n      case OP_RETURN: case OP_TAILCALL: {\n        if (fs->needclose)\n          SETARG_k(*pc, 1);  /* signal that it needs to close */\n        if (p->is_vararg)\n          SETARG_C(*pc, p->numparams + 1);  /* signal that it is vararg */\n        break;\n      }\n      case OP_JMP: {\n        int target = finaltarget(p->code, i);\n        fixjump(fs, i, target);\n        break;\n      }\n      default: break;\n    }\n  }\n}\n"
  },
  {
    "path": "build/lua-5.4.1/src/lcode.h",
    "content": "/*\n** $Id: lcode.h $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums  (ORDER OP)\n*/\ntypedef enum BinOpr {\n  /* arithmetic operators */\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,\n  OPR_DIV, OPR_IDIV,\n  /* bitwise operators */\n  OPR_BAND, OPR_BOR, OPR_BXOR,\n  OPR_SHL, OPR_SHR,\n  /* string operator */\n  OPR_CONCAT,\n  /* comparison operators */\n  OPR_EQ, OPR_LT, OPR_LE,\n  OPR_NE, OPR_GT, OPR_GE,\n  /* logical operators */\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\n/* true if operation is foldable (that is, it is arithmetic or bitwise) */\n#define foldbinop(op)\t((op) <= OPR_SHR)\n\n\n#define luaK_codeABC(fs,o,a,b,c)\tluaK_codeABCk(fs,o,a,b,c,0)\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n/* get (pointer to) instruction of given 'expdesc' */\n#define getinstruction(fs,e)\t((fs)->f->code[(e)->u.info])\n\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\n#define luaK_jumpto(fs,t)\tluaK_patchlist(fs, luaK_jump(fs), t)\n\nLUAI_FUNC int luaK_code (FuncState *fs, Instruction i);\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx);\nLUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,\n                                            int B, int C, int k);\nLUAI_FUNC int luaK_isKint (expdesc *e);\nLUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,\n                            expdesc *v2, int line);\nLUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,\n                                  int ra, int asize, int hsize);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\nLUAI_FUNC void luaK_finish (FuncState *fs);\nLUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lcorolib.c",
    "content": "/*\n** $Id: lcorolib.c $\n** Coroutine Library\n** See Copyright Notice in lua.h\n*/\n\n#define lcorolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdlib.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic lua_State *getco (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argexpected(L, co, 1, \"thread\");\n  return co;\n}\n\n\n/*\n** Resumes a coroutine. Returns the number of results for non-error\n** cases or -1 for errors.\n*/\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status, nres;\n  if (!lua_checkstack(co, narg)) {\n    lua_pushliteral(L, \"too many arguments to resume\");\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, L, narg, &nres);\n  if (status == LUA_OK || status == LUA_YIELD) {\n    if (!lua_checkstack(L, nres + 1)) {\n      lua_pop(co, nres);  /* remove results anyway */\n      lua_pushliteral(L, \"too many results to resume\");\n      return -1;  /* error flag */\n    }\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = getco(L);\n  int r;\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + 'resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {  /* error? */\n    int stat = lua_status(co);\n    if (stat != LUA_OK && stat != LUA_YIELD)  /* error in the coroutine? */\n      lua_resetthread(co);  /* close its tbc variables */\n    if (stat != LUA_ERRMEM &&  /* not a memory error and ... */\n        lua_type(L, -1) == LUA_TSTRING) {  /* ... error object is a string? */\n      luaL_where(L, 1);  /* add extra info, if available */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    return lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\nstatic int luaB_cocreate (lua_State *L) {\n  lua_State *NL;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  NL = lua_newthread(L);\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\n#define COS_RUN\t\t0\n#define COS_DEAD\t1\n#define COS_YIELD\t2\n#define COS_NORM\t3\n\n\nstatic const char *const statname[] =\n  {\"running\", \"dead\", \"suspended\", \"normal\"};\n\n\nstatic int auxstatus (lua_State *L, lua_State *co) {\n  if (L == co) return COS_RUN;\n  else {\n    switch (lua_status(co)) {\n      case LUA_YIELD:\n        return COS_YIELD;\n      case LUA_OK: {\n        lua_Debug ar;\n        if (lua_getstack(co, 0, &ar))  /* does it have frames? */\n          return COS_NORM;  /* it is running */\n        else if (lua_gettop(co) == 0)\n            return COS_DEAD;\n        else\n          return COS_YIELD;  /* initial state */\n      }\n      default:  /* some error occurred */\n        return COS_DEAD;\n    }\n  }\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = getco(L);\n  lua_pushstring(L, statname[auxstatus(L, co)]);\n  return 1;\n}\n\n\nstatic int luaB_yieldable (lua_State *L) {\n  lua_State *co = lua_isnone(L, 1) ? L : getco(L);\n  lua_pushboolean(L, lua_isyieldable(co));\n  return 1;\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  int ismain = lua_pushthread(L);\n  lua_pushboolean(L, ismain);\n  return 2;\n}\n\n\nstatic int luaB_close (lua_State *L) {\n  lua_State *co = getco(L);\n  int status = auxstatus(L, co);\n  switch (status) {\n    case COS_DEAD: case COS_YIELD: {\n      status = lua_resetthread(co);\n      if (status == LUA_OK) {\n        lua_pushboolean(L, 1);\n        return 1;\n      }\n      else {\n        lua_pushboolean(L, 0);\n        lua_xmove(co, L, 1);  /* copy error message */\n        return 2;\n      }\n    }\n    default:  /* normal or running coroutine */\n      return luaL_error(L, \"cannot close a %s coroutine\", statname[status]);\n  }\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n  {\"isyieldable\", luaB_yieldable},\n  {\"close\", luaB_close},\n  {NULL, NULL}\n};\n\n\n\nLUAMOD_API int luaopen_coroutine (lua_State *L) {\n  luaL_newlib(L, co_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lctype.c",
    "content": "/*\n** $Id: lctype.c $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#define lctype_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lctype.h\"\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n\n#if defined (LUA_UCID)\t\t/* accept UniCode IDentifiers? */\n/* consider all non-ascii codepoints to be alphabetic */\n#define NONA\t\t0x01\n#else\n#define NONA\t\t0x00\t/* default */\n#endif\n\n\nLUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {\n  0x00,  /* EOZ */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 0. */\n  0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\t/* 1. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,\n  0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\t/* 2. */\n  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,\t/* 3. */\n  0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 4. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 5. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,\n  0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,\t/* 6. */\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\n  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,\t/* 7. */\n  0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* 8. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* 9. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* a. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* b. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  0x00,  0x00,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* c. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* d. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\t/* e. */\n  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,  NONA,\n  NONA,  NONA,  NONA,  NONA,  NONA,  0x00,  0x00,  0x00,\t/* f. */\n  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00\n};\n\n#endif\t\t\t/* } */\n"
  },
  {
    "path": "build/lua-5.4.1/src/lctype.h",
    "content": "/*\n** $Id: lctype.h $\n** 'ctype' functions for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lctype_h\n#define lctype_h\n\n#include \"lua.h\"\n\n\n/*\n** WARNING: the functions defined here do not necessarily correspond\n** to the similar functions in the standard C ctype.h. They are\n** optimized for the specific needs of Lua.\n*/\n\n#if !defined(LUA_USE_CTYPE)\n\n#if 'A' == 65 && '0' == 48\n/* ASCII case: can use its own tables; faster and fixed */\n#define LUA_USE_CTYPE\t0\n#else\n/* must use standard C ctype */\n#define LUA_USE_CTYPE\t1\n#endif\n\n#endif\n\n\n#if !LUA_USE_CTYPE\t/* { */\n\n#include <limits.h>\n\n#include \"llimits.h\"\n\n\n#define ALPHABIT\t0\n#define DIGITBIT\t1\n#define PRINTBIT\t2\n#define SPACEBIT\t3\n#define XDIGITBIT\t4\n\n\n#define MASK(B)\t\t(1 << (B))\n\n\n/*\n** add 1 to char to allow index -1 (EOZ)\n*/\n#define testprop(c,p)\t(luai_ctype_[(c)+1] & (p))\n\n/*\n** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'\n*/\n#define lislalpha(c)\ttestprop(c, MASK(ALPHABIT))\n#define lislalnum(c)\ttestprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))\n#define lisdigit(c)\ttestprop(c, MASK(DIGITBIT))\n#define lisspace(c)\ttestprop(c, MASK(SPACEBIT))\n#define lisprint(c)\ttestprop(c, MASK(PRINTBIT))\n#define lisxdigit(c)\ttestprop(c, MASK(XDIGITBIT))\n\n\n/*\n** In ASCII, this 'ltolower' is correct for alphabetic characters and\n** for '.'. That is enough for Lua needs. ('check_exp' ensures that\n** the character either is an upper-case letter or is unchanged by\n** the transformation, which holds for lower-case letters and '.'.)\n*/\n#define ltolower(c)  \\\n  check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')),  \\\n            (c) | ('A' ^ 'a'))\n\n\n/* one entry for each character and for -1 (EOZ) */\nLUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)\n\n\n#else\t\t\t/* }{ */\n\n/*\n** use standard C ctypes\n*/\n\n#include <ctype.h>\n\n\n#define lislalpha(c)\t(isalpha(c) || (c) == '_')\n#define lislalnum(c)\t(isalnum(c) || (c) == '_')\n#define lisdigit(c)\t(isdigit(c))\n#define lisspace(c)\t(isspace(c))\n#define lisprint(c)\t(isprint(c))\n#define lisxdigit(c)\t(isxdigit(c))\n\n#define ltolower(c)\t(tolower(c))\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** The hook table at registry[HOOKKEY] maps threads to their current\n** hook function.\n*/\nstatic const char *const HOOKKEY = \"_HOOKKEY\";\n\n\n/*\n** If L1 != L, L1 can be in any state, and therefore there are no\n** guarantees about its stack space; any push in L1 must be\n** checked.\n*/\nstatic void checkstack (lua_State *L, lua_State *L1, int n) {\n  if (L != L1 && !lua_checkstack(L1, n))\n    luaL_error(L, \"stack overflow\");\n}\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, \"nil or table\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;  /* return 1st argument */\n}\n\n\nstatic int db_getuservalue (lua_State *L) {\n  int n = (int)luaL_optinteger(L, 2, 1);\n  if (lua_type(L, 1) != LUA_TUSERDATA)\n    luaL_pushfail(L);\n  else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) {\n    lua_pushboolean(L, 1);\n    return 2;\n  }\n  return 1;\n}\n\n\nstatic int db_setuservalue (lua_State *L) {\n  int n = (int)luaL_optinteger(L, 3, 1);\n  luaL_checktype(L, 1, LUA_TUSERDATA);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  if (!lua_setiuservalue(L, 1, n))\n    luaL_pushfail(L);\n  return 1;\n}\n\n\n/*\n** Auxiliary function used by several library functions: check for\n** an optional thread as function's first argument and set 'arg' with\n** 1 if this argument is present (so that functions can skip it to\n** access their other arguments)\n*/\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;  /* function will operate over current thread */\n  }\n}\n\n\n/*\n** Variations of 'lua_settable', used by 'db_getinfo' to put results\n** from 'lua_getinfo' into result table. Key is always a string;\n** value can be a string, an int, or a boolean.\n*/\nstatic void settabss (lua_State *L, const char *k, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsi (lua_State *L, const char *k, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, k);\n}\n\nstatic void settabsb (lua_State *L, const char *k, int v) {\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, k);\n}\n\n\n/*\n** In function 'db_getinfo', the call to 'lua_getinfo' may push\n** results on the stack; later it creates the result table to put\n** these objects. Function 'treatstackoption' puts the result from\n** 'lua_getinfo' on top of the result table so that it can call\n** 'lua_setfield'.\n*/\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1)\n    lua_rotate(L, -2, 1);  /* exchange object and table */\n  else\n    lua_xmove(L1, L, 1);  /* move object to the \"main\" stack */\n  lua_setfield(L, -2, fname);  /* put object into table */\n}\n\n\n/*\n** Calls 'lua_getinfo' and collects all results in a new table.\n** L1 needs stack space for an optional input (function) plus\n** two optional outputs (function and line table) from function\n** 'lua_getinfo'.\n*/\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnSrtu\");\n  checkstack(L, L1, 3);\n  if (lua_isfunction(L, arg + 1)) {  /* info about a function? */\n    options = lua_pushfstring(L, \">%s\", options);  /* add '>' to 'options' */\n    lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */\n    lua_xmove(L, L1, 1);\n  }\n  else {  /* stack level */\n    if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {\n      luaL_pushfail(L);  /* level out of range */\n      return 1;\n    }\n  }\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_newtable(L);  /* table to collect results */\n  if (strchr(options, 'S')) {\n    lua_pushlstring(L, ar.source, ar.srclen);\n    lua_setfield(L, -2, \"source\");\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u')) {\n    settabsi(L, \"nups\", ar.nups);\n    settabsi(L, \"nparams\", ar.nparams);\n    settabsb(L, \"isvararg\", ar.isvararg);\n  }\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 'r')) {\n    settabsi(L, \"ftransfer\", ar.ftransfer);\n    settabsi(L, \"ntransfer\", ar.ntransfer);\n  }\n  if (strchr(options, 't'))\n    settabsb(L, \"istailcall\", ar.istailcall);\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n\n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */\n  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\n    lua_pushvalue(L, arg + 1);  /* push function */\n    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\n    return 1;  /* return only name (there is no value) */\n  }\n  else {  /* stack-level argument */\n    lua_Debug ar;\n    const char *name;\n    int level = (int)luaL_checkinteger(L, arg + 1);\n    if (!lua_getstack(L1, level, &ar))  /* out of range? */\n      return luaL_argerror(L, arg+1, \"level out of range\");\n    checkstack(L, L1, 1);\n    name = lua_getlocal(L1, &ar, nvar);\n    if (name) {\n      lua_xmove(L1, L, 1);  /* move local value */\n      lua_pushstring(L, name);  /* push name */\n      lua_rotate(L, -2, 1);  /* re-order */\n      return 2;\n    }\n    else {\n      luaL_pushfail(L);  /* no name (nor value) */\n      return 1;\n    }\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  const char *name;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  int level = (int)luaL_checkinteger(L, arg + 1);\n  int nvar = (int)luaL_checkinteger(L, arg + 2);\n  if (!lua_getstack(L1, level, &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  checkstack(L, L1, 1);\n  lua_xmove(L, L1, 1);\n  name = lua_setlocal(L1, &ar, nvar);\n  if (name == NULL)\n    lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */\n  lua_pushstring(L, name);\n  return 1;\n}\n\n\n/*\n** get (if 'get' is true) or set an upvalue from a closure\n*/\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */\n  luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));  /* no-op if get is false */\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n/*\n** Check whether a given upvalue from a given closure exists and\n** returns its index\n*/\nstatic int checkupval (lua_State *L, int argf, int argnup) {\n  int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */\n  luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */\n  luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup,\n                   \"invalid upvalue index\");\n  return nup;\n}\n\n\nstatic int db_upvalueid (lua_State *L) {\n  int n = checkupval(L, 1, 2);\n  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\n  return 1;\n}\n\n\nstatic int db_upvaluejoin (lua_State *L) {\n  int n1 = checkupval(L, 1, 2);\n  int n2 = checkupval(L, 3, 4);\n  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, \"Lua function expected\");\n  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, \"Lua function expected\");\n  lua_upvaluejoin(L, 1, n1, 3, n2);\n  return 0;\n}\n\n\n/*\n** Call hook function registered at hook table for the current\n** thread (if there is one)\n*/\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail call\"};\n  lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);\n  lua_pushthread(L);\n  if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */\n    lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);  /* push current line */\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);  /* call hook function */\n  }\n}\n\n\n/*\n** Convert a string mask (for 'sethook') into a bit mask\n*/\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\n/*\n** Convert a bit mask (for 'gethook') into a string mask\n*/\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {  /* no hook? */\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = (int)luaL_optinteger(L, arg + 3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {\n    /* table just created; initialize it */\n    lua_pushstring(L, \"k\");\n    lua_setfield(L, -2, \"__mode\");  /** hooktable.__mode = \"k\" */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, -2);  /* metatable(hooktable) = hooktable */\n  }\n  checkstack(L, L1, 1);\n  lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */\n  lua_pushvalue(L, arg + 1);  /* value (hook function) */\n  lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */\n  lua_sethook(L1, func, mask, count);\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook == NULL) {  /* no hook? */\n    luaL_pushfail(L);\n    return 1;\n  }\n  else if (hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {  /* hook table must exist */\n    lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);\n    checkstack(L, L1, 1);\n    lua_pushthread(L1); lua_xmove(L1, L, 1);\n    lua_rawget(L, -2);   /* 1st result = hooktable[L1] */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */\n  lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    lua_writestringerror(\"%s\", \"lua_debug> \");\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0))\n      lua_writestringerror(\"%s\\n\", luaL_tolstring(L, -1, NULL));\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\nstatic int db_traceback (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg + 1);\n  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\n    lua_pushvalue(L, arg + 1);  /* return it untouched */\n  else {\n    int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);\n    luaL_traceback(L, L1, msg, level);\n  }\n  return 1;\n}\n\n\nstatic int db_setcstacklimit (lua_State *L) {\n  int limit = (int)luaL_checkinteger(L, 1);\n  int res = lua_setcstacklimit(L, limit);\n  if (res == 0)\n    lua_pushboolean(L, 0);\n  else\n    lua_pushinteger(L, res);\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getuservalue\", db_getuservalue},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"upvaluejoin\", db_upvaluejoin},\n  {\"upvalueid\", db_upvalueid},\n  {\"setuservalue\", db_setuservalue},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_traceback},\n  {\"setcstacklimit\", db_setcstacklimit},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_debug (lua_State *L) {\n  luaL_newlib(L, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n#define noLuaClosure(f)\t\t((f) == NULL || (f)->c.tt == LUA_VCCL)\n\n/* inverse of 'pcRel' */\n#define invpcRel(pc, p)\t\t((p)->code + (pc) + 1)\n\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                    const char **name);\n\n\nstatic int currentpc (CallInfo *ci) {\n  lua_assert(isLua(ci));\n  return pcRel(ci->u.l.savedpc, ci_func(ci)->p);\n}\n\n\n/*\n** Get a \"base line\" to find the line corresponding to an instruction.\n** For that, search the array of absolute line info for the largest saved\n** instruction smaller or equal to the wanted instruction. A special\n** case is when there is no absolute info or the instruction is before\n** the first absolute one.\n*/\nstatic int getbaseline (const Proto *f, int pc, int *basepc) {\n  if (f->sizeabslineinfo == 0 || pc < f->abslineinfo[0].pc) {\n    *basepc = -1;  /* start from the beginning */\n    return f->linedefined;\n  }\n  else {\n    unsigned int i;\n    if (pc >= f->abslineinfo[f->sizeabslineinfo - 1].pc)\n      i = f->sizeabslineinfo - 1;  /* instruction is after last saved one */\n    else {  /* binary search */\n      unsigned int j = f->sizeabslineinfo - 1;  /* pc < anchorlines[j] */\n      i = 0;  /* abslineinfo[i] <= pc */\n      while (i < j - 1) {\n        unsigned int m = (j + i) / 2;\n        if (pc >= f->abslineinfo[m].pc)\n          i = m;\n        else\n          j = m;\n      }\n    }\n    *basepc = f->abslineinfo[i].pc;\n    return f->abslineinfo[i].line;\n  }\n}\n\n\n/*\n** Get the line corresponding to instruction 'pc' in function 'f';\n** first gets a base line and from there does the increments until\n** the desired instruction.\n*/\nint luaG_getfuncline (const Proto *f, int pc) {\n  if (f->lineinfo == NULL)  /* no debug information? */\n    return -1;\n  else {\n    int basepc;\n    int baseline = getbaseline(f, pc, &basepc);\n    while (basepc++ < pc) {  /* walk until given instruction */\n      lua_assert(f->lineinfo[basepc] != ABSLINEINFO);\n      baseline += f->lineinfo[basepc];  /* correct line */\n    }\n    return baseline;\n  }\n}\n\n\nstatic int getcurrentline (CallInfo *ci) {\n  return luaG_getfuncline(ci_func(ci)->p, currentpc(ci));\n}\n\n\n/*\n** Set 'trap' for all active Lua frames.\n** This function can be called during a signal, under \"reasonable\"\n** assumptions. A new 'ci' is completely linked in the list before it\n** becomes part of the \"active\" list, and we assume that pointers are\n** atomic; see comment in next function.\n** (A compiler doing interprocedural optimizations could, theoretically,\n** reorder memory writes in such a way that the list could be\n** temporarily broken while inserting a new element. We simply assume it\n** has no good reasons to do that.)\n*/\nstatic void settraps (CallInfo *ci) {\n  for (; ci != NULL; ci = ci->previous)\n    if (isLua(ci))\n      ci->u.l.trap = 1;\n}\n\n\n/*\n** This function can be called during a signal, under \"reasonable\"\n** assumptions.\n** Fields 'basehookcount' and 'hookcount' (set by 'resethookcount')\n** are for debug only, and it is no problem if they get arbitrary\n** values (causes at most one wrong hook call). 'hookmask' is an atomic\n** value. We assume that pointers are atomic too (e.g., gcc ensures that\n** for all platforms where it runs). Moreover, 'hook' is always checked\n** before being called (see 'luaD_hook').\n*/\nLUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n  if (mask)\n    settraps(L->ci);  /* to trace inside 'luaV_execute' */\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  if (level < 0) return 0;  /* invalid (negative) level */\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)\n    level--;\n  if (level == 0 && ci != &L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = ci;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic const char *upvalname (const Proto *p, int uv) {\n  TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name);\n  if (s == NULL) return \"?\";\n  else return getstr(s);\n}\n\n\nstatic const char *findvararg (CallInfo *ci, int n, StkId *pos) {\n  if (clLvalue(s2v(ci->func))->p->is_vararg) {\n    int nextra = ci->u.l.nextraargs;\n    if (n >= -nextra) {  /* 'n' is negative */\n      *pos = ci->func - nextra - (n + 1);\n      return \"(vararg)\";  /* generic name for any vararg */\n    }\n  }\n  return NULL;  /* no such vararg */\n}\n\n\nconst char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {\n  StkId base = ci->func + 1;\n  const char *name = NULL;\n  if (isLua(ci)) {\n    if (n < 0)  /* access to vararg values? */\n      return findvararg(ci, n, pos);\n    else\n      name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));\n  }\n  if (name == NULL) {  /* no 'standard' name? */\n    StkId limit = (ci == L->ci) ? L->top : ci->next->func;\n    if (limit - base >= n && n > 0) {  /* is 'n' inside 'ci' stack? */\n      /* generic name for any valid slot */\n      name = isLua(ci) ? \"(temporary)\" : \"(C temporary)\";\n    }\n    else\n      return NULL;  /* no name */\n  }\n  if (pos)\n    *pos = base + (n - 1);\n  return name;\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  const char *name;\n  lua_lock(L);\n  if (ar == NULL) {  /* information about non-active function? */\n    if (!isLfunction(s2v(L->top - 1)))  /* not a Lua function? */\n      name = NULL;\n    else  /* consider live variables at function start (parameters) */\n      name = luaF_getlocalname(clLvalue(s2v(L->top - 1))->p, n, 0);\n  }\n  else {  /* active function; get information through 'ar' */\n    StkId pos = NULL;  /* to avoid warnings */\n    name = luaG_findlocal(L, ar->i_ci, n, &pos);\n    if (name) {\n      setobjs2s(L, L->top, pos);\n      api_incr_top(L);\n    }\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  StkId pos = NULL;  /* to avoid warnings */\n  const char *name;\n  lua_lock(L);\n  name = luaG_findlocal(L, ar->i_ci, n, &pos);\n  if (name) {\n    setobjs2s(L, pos, L->top - 1);\n    L->top--;  /* pop value */\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (noLuaClosure(cl)) {\n    ar->source = \"=[C]\";\n    ar->srclen = LL(\"=[C]\");\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    const Proto *p = cl->l.p;\n    if (p->source) {\n      ar->source = getstr(p->source);\n      ar->srclen = tsslen(p->source);\n    }\n    else {\n      ar->source = \"=?\";\n      ar->srclen = LL(\"=?\");\n    }\n    ar->linedefined = p->linedefined;\n    ar->lastlinedefined = p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, ar->srclen);\n}\n\n\nstatic int nextline (const Proto *p, int currentline, int pc) {\n  if (p->lineinfo[pc] != ABSLINEINFO)\n    return currentline + p->lineinfo[pc];\n  else\n    return luaG_getfuncline(p, pc);\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (noLuaClosure(f)) {\n    setnilvalue(s2v(L->top));\n    api_incr_top(L);\n  }\n  else {\n    int i;\n    TValue v;\n    const Proto *p = f->l.p;\n    int currentline = p->linedefined;\n    Table *t = luaH_new(L);  /* new table to store active lines */\n    sethvalue2s(L, L->top, t);  /* push it on stack */\n    api_incr_top(L);\n    setbtvalue(&v);  /* boolean 'true' to be the value of all indices */\n    for (i = 0; i < p->sizelineinfo; i++) {  /* for all lines with code */\n      currentline = nextline(p, currentline, i);\n      luaH_setint(L, t, currentline, &v);  /* table[line] = true */\n    }\n  }\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  if (ci == NULL)  /* no 'ci'? */\n    return NULL;  /* no info */\n  else if (ci->callstatus & CIST_FIN) {  /* is this a finalizer? */\n    *name = \"__gc\";\n    return \"metamethod\";  /* report it as such */\n  }\n  /* calling function is a known Lua function? */\n  else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))\n    return funcnamefromcode(L, ci->previous, name);\n  else return NULL;  /* no way to find a name */\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                       Closure *f, CallInfo *ci) {\n  int status = 1;\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci && isLua(ci)) ? getcurrentline(ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = (f == NULL) ? 0 : f->c.nupvalues;\n        if (noLuaClosure(f)) {\n          ar->isvararg = 1;\n          ar->nparams = 0;\n        }\n        else {\n          ar->isvararg = f->l.p->is_vararg;\n          ar->nparams = f->l.p->numparams;\n        }\n        break;\n      }\n      case 't': {\n        ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = getfuncname(L, ci, &ar->name);\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'r': {\n        if (ci == NULL || !(ci->callstatus & CIST_TRAN))\n          ar->ftransfer = ar->ntransfer = 0;\n        else {\n          ar->ftransfer = ci->u2.transferinfo.ftransfer;\n          ar->ntransfer = ci->u2.transferinfo.ntransfer;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *cl;\n  CallInfo *ci;\n  TValue *func;\n  lua_lock(L);\n  if (*what == '>') {\n    ci = NULL;\n    func = s2v(L->top - 1);\n    api_check(L, ttisfunction(func), \"function expected\");\n    what++;  /* skip the '>' */\n    L->top--;  /* pop function */\n  }\n  else {\n    ci = ar->i_ci;\n    func = s2v(ci->func);\n    lua_assert(ttisfunction(func));\n  }\n  cl = ttisclosure(func) ? clvalue(func) : NULL;\n  status = auxgetinfo(L, what, ar, cl, ci);\n  if (strchr(what, 'f')) {\n    setobj2s(L, L->top, func);\n    api_incr_top(L);\n  }\n  if (strchr(what, 'L'))\n    collectvalidlines(L, cl);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution\n** =======================================================\n*/\n\nstatic const char *getobjname (const Proto *p, int lastpc, int reg,\n                               const char **name);\n\n\n/*\n** Find a \"name\" for the constant 'c'.\n*/\nstatic void kname (const Proto *p, int c, const char **name) {\n  TValue *kvalue = &p->k[c];\n  *name = (ttisstring(kvalue)) ? svalue(kvalue) : \"?\";\n}\n\n\n/*\n** Find a \"name\" for the register 'c'.\n*/\nstatic void rname (const Proto *p, int pc, int c, const char **name) {\n  const char *what = getobjname(p, pc, c, name); /* search for 'c' */\n  if (!(what && *what == 'c'))  /* did not find a constant name? */\n    *name = \"?\";\n}\n\n\n/*\n** Find a \"name\" for a 'C' value in an RK instruction.\n*/\nstatic void rkname (const Proto *p, int pc, Instruction i, const char **name) {\n  int c = GETARG_C(i);  /* key index */\n  if (GETARG_k(i))  /* is 'c' a constant? */\n    kname(p, c, name);\n  else  /* 'c' is a register */\n    rname(p, pc, c, name);\n}\n\n\nstatic int filterpc (int pc, int jmptarget) {\n  if (pc < jmptarget)  /* is code conditional (inside a jump)? */\n    return -1;  /* cannot know who sets that register */\n  else return pc;  /* current position sets that register */\n}\n\n\n/*\n** Try to find last instruction before 'lastpc' that modified register 'reg'.\n*/\nstatic int findsetreg (const Proto *p, int lastpc, int reg) {\n  int pc;\n  int setreg = -1;  /* keep last instruction that changed 'reg' */\n  int jmptarget = 0;  /* any code before this address is conditional */\n  if (testMMMode(GET_OPCODE(p->code[lastpc])))\n    lastpc--;  /* previous instruction was not actually executed */\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    int change;  /* true if current instruction changed 'reg' */\n    switch (op) {\n      case OP_LOADNIL: {  /* set registers from 'a' to 'a+b' */\n        int b = GETARG_B(i);\n        change = (a <= reg && reg <= a + b);\n        break;\n      }\n      case OP_TFORCALL: {  /* affect all regs above its base */\n        change = (reg >= a + 2);\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {  /* affect all registers above base */\n        change = (reg >= a);\n        break;\n      }\n      case OP_JMP: {  /* doesn't change registers, but changes 'jmptarget' */\n        int b = GETARG_sJ(i);\n        int dest = pc + 1 + b;\n        /* jump does not skip 'lastpc' and is larger than current one? */\n        if (dest <= lastpc && dest > jmptarget)\n          jmptarget = dest;  /* update 'jmptarget' */\n        change = 0;\n        break;\n      }\n      default:  /* any instruction that sets A */\n        change = (testAMode(op) && reg == a);\n        break;\n    }\n    if (change)\n      setreg = filterpc(pc, jmptarget);\n  }\n  return setreg;\n}\n\n\n/*\n** Check whether table being indexed by instruction 'i' is the\n** environment '_ENV'\n*/\nstatic const char *gxf (const Proto *p, int pc, Instruction i, int isup) {\n  int t = GETARG_B(i);  /* table index */\n  const char *name;  /* name of indexed variable */\n  if (isup)  /* is an upvalue? */\n    name = upvalname(p, t);\n  else\n    getobjname(p, pc, t, &name);\n  return (name && strcmp(name, LUA_ENV) == 0) ? \"global\" : \"field\";\n}\n\n\nstatic const char *getobjname (const Proto *p, int lastpc, int reg,\n                               const char **name) {\n  int pc;\n  *name = luaF_getlocalname(p, reg + 1, lastpc);\n  if (*name)  /* is a local? */\n    return \"local\";\n  /* else try symbolic execution */\n  pc = findsetreg(p, lastpc, reg);\n  if (pc != -1) {  /* could find instruction? */\n    Instruction i = p->code[pc];\n    OpCode op = GET_OPCODE(i);\n    switch (op) {\n      case OP_MOVE: {\n        int b = GETARG_B(i);  /* move from 'b' to 'a' */\n        if (b < GETARG_A(i))\n          return getobjname(p, pc, b, name);  /* get name for 'b' */\n        break;\n      }\n      case OP_GETTABUP: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, k, name);\n        return gxf(p, pc, i, 1);\n      }\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        rname(p, pc, k, name);\n        return gxf(p, pc, i, 0);\n      }\n      case OP_GETI: {\n        *name = \"integer index\";\n        return \"field\";\n      }\n      case OP_GETFIELD: {\n        int k = GETARG_C(i);  /* key index */\n        kname(p, k, name);\n        return gxf(p, pc, i, 0);\n      }\n      case OP_GETUPVAL: {\n        *name = upvalname(p, GETARG_B(i));\n        return \"upvalue\";\n      }\n      case OP_LOADK:\n      case OP_LOADKX: {\n        int b = (op == OP_LOADK) ? GETARG_Bx(i)\n                                 : GETARG_Ax(p->code[pc + 1]);\n        if (ttisstring(&p->k[b])) {\n          *name = svalue(&p->k[b]);\n          return \"constant\";\n        }\n        break;\n      }\n      case OP_SELF: {\n        rkname(p, pc, i, name);\n        return \"method\";\n      }\n      default: break;  /* go through to return NULL */\n    }\n  }\n  return NULL;  /* could not find reasonable name */\n}\n\n\n/*\n** Try to find a name for a function based on the code that called it.\n** (Only works when function was called by a Lua function.)\n** Returns what the name is (e.g., \"for iterator\", \"method\",\n** \"metamethod\") and sets '*name' to point to the name.\n*/\nstatic const char *funcnamefromcode (lua_State *L, CallInfo *ci,\n                                     const char **name) {\n  TMS tm = (TMS)0;  /* (initial value avoids warnings) */\n  const Proto *p = ci_func(ci)->p;  /* calling function */\n  int pc = currentpc(ci);  /* calling instruction index */\n  Instruction i = p->code[pc];  /* calling instruction */\n  if (ci->callstatus & CIST_HOOKED) {  /* was it called inside a hook? */\n    *name = \"?\";\n    return \"hook\";\n  }\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n      return getobjname(p, pc, GETARG_A(i), name);  /* get function name */\n    case OP_TFORCALL: {  /* for iterator */\n      *name = \"for iterator\";\n       return \"for iterator\";\n    }\n    /* other instructions can do calls through metamethods */\n    case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:\n    case OP_GETI: case OP_GETFIELD:\n      tm = TM_INDEX;\n      break;\n    case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD:\n      tm = TM_NEWINDEX;\n      break;\n    case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {\n      tm = cast(TMS, GETARG_C(i));\n      break;\n    }\n    case OP_UNM: tm = TM_UNM; break;\n    case OP_BNOT: tm = TM_BNOT; break;\n    case OP_LEN: tm = TM_LEN; break;\n    case OP_CONCAT: tm = TM_CONCAT; break;\n    case OP_EQ: tm = TM_EQ; break;\n    case OP_LT: case OP_LE: case OP_LTI: case OP_LEI:\n      *name = \"order\";  /* '<=' can call '__lt', etc. */\n      return \"metamethod\";\n    case OP_CLOSE: case OP_RETURN:\n      *name = \"close\";\n      return \"metamethod\";\n    default:\n      return NULL;  /* cannot find a reasonable name */\n  }\n  *name = getstr(G(L)->tmname[tm]) + 2;\n  return \"metamethod\";\n}\n\n/* }====================================================== */\n\n\n\n/*\n** The subtraction of two potentially unrelated pointers is\n** not ISO C, but it should not crash a program; the subsequent\n** checks are ISO C and ensure a correct result.\n*/\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  StkId base = ci->func + 1;\n  ptrdiff_t i = cast(StkId, o) - base;\n  return (0 <= i && i < (ci->top - base) && s2v(base + i) == o);\n}\n\n\n/*\n** Checks whether value 'o' came from an upvalue. (That can only happen\n** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on\n** upvalues.)\n*/\nstatic const char *getupvalname (CallInfo *ci, const TValue *o,\n                                 const char **name) {\n  LClosure *c = ci_func(ci);\n  int i;\n  for (i = 0; i < c->nupvalues; i++) {\n    if (c->upvals[i]->v == o) {\n      *name = upvalname(c->p, i);\n      return \"upvalue\";\n    }\n  }\n  return NULL;\n}\n\n\nstatic const char *varinfo (lua_State *L, const TValue *o) {\n  const char *name = NULL;  /* to avoid warnings */\n  CallInfo *ci = L->ci;\n  const char *kind = NULL;\n  if (isLua(ci)) {\n    kind = getupvalname(ci, o, &name);  /* check whether 'o' is an upvalue */\n    if (!kind && isinstack(ci, o))  /* no? try a register */\n      kind = getobjname(ci_func(ci)->p, currentpc(ci),\n                        cast_int(cast(StkId, o) - (ci->func + 1)), &name);\n  }\n  return (kind) ? luaO_pushfstring(L, \" (%s '%s')\", kind, name) : \"\";\n}\n\n\nl_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *t = luaT_objtypename(L, o);\n  luaG_runerror(L, \"attempt to %s a %s value%s\", op, t, varinfo(L, o));\n}\n\n\nl_noret luaG_forerror (lua_State *L, const TValue *o, const char *what) {\n  luaG_runerror(L, \"bad 'for' %s (number expected, got %s)\",\n                   what, luaT_objtypename(L, o));\n}\n\n\nl_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) {\n  if (ttisstring(p1) || cvt2str(p1)) p1 = p2;\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nl_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                         const TValue *p2, const char *msg) {\n  if (!ttisnumber(p1))  /* first operand is wrong? */\n    p2 = p1;  /* now second is wrong */\n  luaG_typeerror(L, p2, msg);\n}\n\n\n/*\n** Error when both values are convertible to numbers, but not to integers\n*/\nl_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) {\n  lua_Integer temp;\n  if (!tointegerns(p1, &temp))\n    p2 = p1;\n  luaG_runerror(L, \"number%s has no integer representation\", varinfo(L, p2));\n}\n\n\nl_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_objtypename(L, p1);\n  const char *t2 = luaT_objtypename(L, p2);\n  if (strcmp(t1, t2) == 0)\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n}\n\n\n/* add src:line information to 'msg' */\nconst char *luaG_addinfo (lua_State *L, const char *msg, TString *src,\n                                        int line) {\n  char buff[LUA_IDSIZE];\n  if (src)\n    luaO_chunkid(buff, getstr(src), tsslen(src));\n  else {  /* no source available; use \"?\" instead */\n    buff[0] = '?'; buff[1] = '\\0';\n  }\n  return luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n}\n\n\nl_noret luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    lua_assert(ttisfunction(s2v(errfunc)));\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    L->top++;  /* assume EXTRA_STACK */\n    luaD_callnoyield(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nl_noret luaG_runerror (lua_State *L, const char *fmt, ...) {\n  CallInfo *ci = L->ci;\n  const char *msg;\n  va_list argp;\n  luaC_checkGC(L);  /* error message uses memory */\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);  /* format message */\n  va_end(argp);\n  if (isLua(ci))  /* if Lua function, add source:line information */\n    luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));\n  luaG_errormsg(L);\n}\n\n\n/*\n** Check whether new instruction 'newpc' is in a different line from\n** previous instruction 'oldpc'.\n*/\nstatic int changedline (const Proto *p, int oldpc, int newpc) {\n  if (p->lineinfo == NULL)  /* no debug information? */\n    return 0;\n  while (oldpc++ < newpc) {\n    if (p->lineinfo[oldpc] != 0)\n      return (luaG_getfuncline(p, oldpc - 1) != luaG_getfuncline(p, newpc));\n  }\n  return 0;  /* no line changes between positions */\n}\n\n\n/*\n** Traces the execution of a Lua function. Called before the execution\n** of each opcode, when debug is on. 'L->oldpc' stores the last\n** instruction traced, to detect line changes. When entering a new\n** function, 'npci' will be zero and will test as a new line without\n** the need for 'oldpc'; so, 'oldpc' does not need to be initialized\n** before. Some exceptional conditions may return to a function without\n** updating 'oldpc'. In that case, 'oldpc' may be invalid; if so, it is\n** reset to zero.  (A wrong but valid 'oldpc' at most causes an extra\n** call to a line hook.)\n*/\nint luaG_traceexec (lua_State *L, const Instruction *pc) {\n  CallInfo *ci = L->ci;\n  lu_byte mask = L->hookmask;\n  const Proto *p = ci_func(ci)->p;\n  int counthook;\n  /* 'L->oldpc' may be invalid; reset it in this case */\n  int oldpc = (L->oldpc < p->sizecode) ? L->oldpc : 0;\n  if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) {  /* no hooks? */\n    ci->u.l.trap = 0;  /* don't need to stop again */\n    return 0;  /* turn off 'trap' */\n  }\n  pc++;  /* reference is always next instruction */\n  ci->u.l.savedpc = pc;  /* save 'pc' */\n  counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));\n  if (counthook)\n    resethookcount(L);  /* reset count */\n  else if (!(mask & LUA_MASKLINE))\n    return 1;  /* no line hook and count != 0; nothing to be done now */\n  if (ci->callstatus & CIST_HOOKYIELD) {  /* called hook last time? */\n    ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */\n    return 1;  /* do not call hook again (VM yielded, so it did not move) */\n  }\n  if (!isIT(*(ci->u.l.savedpc - 1)))\n    L->top = ci->top;  /* prepare top */\n  if (counthook)\n    luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0);  /* call count hook */\n  if (mask & LUA_MASKLINE) {\n    int npci = pcRel(pc, p);\n    if (npci == 0 ||  /* call linehook when enter a new function, */\n        pc <= invpcRel(oldpc, p) ||  /* when jump back (loop), or when */\n        changedline(p, oldpc, npci)) {  /* enter new line */\n      int newline = luaG_getfuncline(p, npci);\n      luaD_hook(L, LUA_HOOKLINE, newline, 0, 0);  /* call line hook */\n    }\n    L->oldpc = npci;  /* 'pc' of last call to line hook */\n  }\n  if (L->status == LUA_YIELD) {  /* did hook yield? */\n    if (counthook)\n      L->hookcount = 1;  /* undo decrement to zero */\n    ci->u.l.savedpc--;  /* undo increment (resume will increment it again) */\n    ci->callstatus |= CIST_HOOKYIELD;  /* mark that it yielded */\n    luaD_throw(L, LUA_YIELD);\n  }\n  return 1;  /* keep 'trap' on */\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast_int((pc) - (p)->code) - 1)\n\n\n/* Active Lua function (given call info) */\n#define ci_func(ci)\t\t(clLvalue(s2v((ci)->func)))\n\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n/*\n** mark for entries in 'lineinfo' array that has absolute information in\n** 'abslineinfo' array\n*/\n#define ABSLINEINFO\t(-0x80)\n\nLUAI_FUNC int luaG_getfuncline (const Proto *f, int pc);\nLUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n,\n                                                    StkId *pos);\nLUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,\n                                                const char *opname);\nLUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o,\n                                               const char *what);\nLUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,\n                                                  const TValue *p2);\nLUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2,\n                                                 const char *msg);\nLUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,\n                                                 const TValue *p2);\nLUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,\n                                                  TString *src, int line);\nLUAI_FUNC l_noret luaG_errormsg (lua_State *L);\nLUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldo.c",
    "content": "/*\n** $Id: ldo.c $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n#define errorstatus(s)\t((s) > LUA_YIELD)\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n/*\n** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By\n** default, Lua handles errors with exceptions when compiling as\n** C++ code, with _longjmp/_setjmp when asked to use them, and with\n** longjmp/setjmp otherwise.\n*/\n#if !defined(LUAI_THROW)\t\t\t\t/* { */\n\n#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)\t/* { */\n\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\t\tthrow(c)\n#define LUAI_TRY(L,c,a) \\\n\ttry { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\t\tint  /* dummy variable */\n\n#elif defined(LUA_USE_POSIX)\t\t\t\t/* }{ */\n\n/* in POSIX, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#else\t\t\t\t\t\t\t/* }{ */\n\n/* ISO C handling with long jumps */\n#define LUAI_THROW(L,c)\t\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\t\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\t\tjmp_buf\n\n#endif\t\t\t\t\t\t\t/* } */\n\n#endif\t\t\t\t\t\t\t/* } */\n\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nvoid luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {  /* memory error? */\n      setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */\n      break;\n    }\n    case LUA_ERRERR: {\n      setsvalue2s(L, oldtop, luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    case CLOSEPROTECT: {\n      setnilvalue(s2v(oldtop));  /* no error message */\n      break;\n    }\n    default: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nl_noret luaD_throw (lua_State *L, int errcode) {\n  if (L->errorJmp) {  /* thread has an error handler? */\n    L->errorJmp->status = errcode;  /* set status */\n    LUAI_THROW(L, L->errorJmp);  /* jump to it */\n  }\n  else {  /* thread has no error handler */\n    global_State *g = G(L);\n    errcode = luaF_close(L, L->stack, errcode);  /* close all upvalues */\n    L->status = cast_byte(errcode);  /* mark it as dead */\n    if (g->mainthread->errorJmp) {  /* main thread has a handler? */\n      setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */\n      luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */\n    }\n    else {  /* no handler at all; abort */\n      if (g->panic) {  /* panic function? */\n        luaD_seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */\n        if (L->ci->top < L->top)\n          L->ci->top = L->top;  /* pushing msg. can break this invariant */\n        lua_unlock(L);\n        g->panic(L);  /* call panic function (last chance to jump out) */\n      }\n      abort();\n    }\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  global_State *g = G(L);\n  l_uint32 oldnCcalls = g->Cstacklimit - (L->nCcalls + L->nci);\n  struct lua_longjmp lj;\n  lj.status = LUA_OK;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  L->nCcalls = g->Cstacklimit - oldnCcalls - L->nci;\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\n/*\n** {==================================================================\n** Stack reallocation\n** ===================================================================\n*/\nstatic void correctstack (lua_State *L, StkId oldstack, StkId newstack) {\n  CallInfo *ci;\n  UpVal *up;\n  if (oldstack == newstack)\n    return;  /* stack address did not change */\n  L->top = (L->top - oldstack) + newstack;\n  for (up = L->openupval; up != NULL; up = up->u.open.next)\n    up->v = s2v((uplevel(up) - oldstack) + newstack);\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    ci->top = (ci->top - oldstack) + newstack;\n    ci->func = (ci->func - oldstack) + newstack;\n    if (isLua(ci))\n      ci->u.l.trap = 1;  /* signal to update 'trap' in 'luaV_execute' */\n  }\n}\n\n\n/* some space for error handling */\n#define ERRORSTACKSIZE\t(LUAI_MAXSTACK + 200)\n\n\nint luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {\n  int lim = L->stacksize;\n  StkId newstack = luaM_reallocvector(L, L->stack, lim, newsize, StackValue);\n  lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK);\n  if (unlikely(newstack == NULL)) {  /* reallocation failed? */\n    if (raiseerror)\n      luaM_error(L);\n    else return 0;  /* do not raise an error */\n  }\n  for (; lim < newsize; lim++)\n    setnilvalue(s2v(newstack + lim)); /* erase new segment */\n  correctstack(L, L->stack, newstack);\n  L->stack = newstack;\n  L->stacksize = newsize;\n  L->stack_last = L->stack + newsize - EXTRA_STACK;\n  return 1;\n}\n\n\n/*\n** Try to grow the stack by at least 'n' elements. when 'raiseerror'\n** is true, raises any error; otherwise, return 0 in case of errors.\n*/\nint luaD_growstack (lua_State *L, int n, int raiseerror) {\n  int size = L->stacksize;\n  int newsize = 2 * size;  /* tentative new size */\n  if (unlikely(size > LUAI_MAXSTACK)) {  /* need more space after extra size? */\n    if (raiseerror)\n      luaD_throw(L, LUA_ERRERR);  /* error inside message handler */\n    else return 0;\n  }\n  else {\n    int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;\n    if (newsize > LUAI_MAXSTACK)  /* cannot cross the limit */\n      newsize = LUAI_MAXSTACK;\n    if (newsize < needed)  /* but must respect what was asked for */\n      newsize = needed;\n    if (unlikely(newsize > LUAI_MAXSTACK)) {  /* stack overflow? */\n      /* add extra size to be able to handle the error message */\n      luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);\n      if (raiseerror)\n        luaG_runerror(L, \"stack overflow\");\n      else return 0;\n    }\n  }  /* else no errors */\n  return luaD_reallocstack(L, newsize, raiseerror);\n}\n\n\nstatic int stackinuse (lua_State *L) {\n  CallInfo *ci;\n  StkId lim = L->top;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {\n    if (lim < ci->top) lim = ci->top;\n  }\n  lua_assert(lim <= L->stack_last);\n  return cast_int(lim - L->stack) + 1;  /* part of stack in use */\n}\n\n\nvoid luaD_shrinkstack (lua_State *L) {\n  int inuse = stackinuse(L);\n  int goodsize = inuse + BASIC_STACK_SIZE;\n  if (goodsize > LUAI_MAXSTACK)\n    goodsize = LUAI_MAXSTACK;  /* respect stack limit */\n  /* if thread is currently not handling a stack overflow and its\n     good size is smaller than current size, shrink its stack */\n  if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && goodsize < L->stacksize)\n    luaD_reallocstack(L, goodsize, 0);  /* ok if that fails */\n  else  /* don't change stack */\n    condmovestack(L,{},{});  /* (change only for debugging) */\n  luaE_shrinkCI(L);  /* shrink CI list */\n}\n\n\nvoid luaD_inctop (lua_State *L) {\n  luaD_checkstack(L, 1);\n  L->top++;\n}\n\n/* }================================================================== */\n\n\n/*\n** Call a hook for the given event. Make sure there is a hook to be\n** called. (Both 'L->hook' and 'L->hookmask', which trigger this\n** function, can be changed asynchronously by signals.)\n*/\nvoid luaD_hook (lua_State *L, int event, int line,\n                              int ftransfer, int ntransfer) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {  /* make sure there is a hook */\n    int mask = CIST_HOOKED;\n    CallInfo *ci = L->ci;\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    ar.i_ci = ci;\n    if (ntransfer != 0) {\n      mask |= CIST_TRAN;  /* 'ci' has transfer information */\n      ci->u2.transferinfo.ftransfer = ftransfer;\n      ci->u2.transferinfo.ntransfer = ntransfer;\n    }\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    if (L->top + LUA_MINSTACK > ci->top)\n      ci->top = L->top + LUA_MINSTACK;\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    ci->callstatus |= mask;\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n    ci->callstatus &= ~mask;\n  }\n}\n\n\n/*\n** Executes a call hook for Lua functions. This function is called\n** whenever 'hookmask' is not zero, so it checks whether call hooks are\n** active.\n*/\nvoid luaD_hookcall (lua_State *L, CallInfo *ci) {\n  int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL;\n  Proto *p;\n  if (!(L->hookmask & LUA_MASKCALL))  /* some other hook? */\n    return;  /* don't call hook */\n  p = clLvalue(s2v(ci->func))->p;\n  L->top = ci->top;  /* prepare top */\n  ci->u.l.savedpc++;  /* hooks assume 'pc' is already incremented */\n  luaD_hook(L, hook, -1, 1, p->numparams);\n  ci->u.l.savedpc--;  /* correct 'pc' */\n}\n\n\nstatic StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) {\n  ptrdiff_t oldtop = savestack(L, L->top);  /* hook may change top */\n  int delta = 0;\n  if (isLuacode(ci)) {\n    Proto *p = ci_func(ci)->p;\n    if (p->is_vararg)\n      delta = ci->u.l.nextraargs + p->numparams + 1;\n    if (L->top < ci->top)\n      L->top = ci->top;  /* correct top to run hook */\n  }\n  if (L->hookmask & LUA_MASKRET) {  /* is return hook on? */\n    int ftransfer;\n    ci->func += delta;  /* if vararg, back to virtual 'func' */\n    ftransfer = cast(unsigned short, firstres - ci->func);\n    luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres);  /* call it */\n    ci->func -= delta;\n  }\n  if (isLua(ci = ci->previous))\n    L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p);  /* update 'oldpc' */\n  return restorestack(L, oldtop);\n}\n\n\n/*\n** Check whether 'func' has a '__call' metafield. If so, put it in the\n** stack, below original 'func', so that 'luaD_call' can call it. Raise\n** an error if there is no '__call' metafield.\n*/\nvoid luaD_tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);\n  StkId p;\n  if (unlikely(ttisnil(tm)))\n    luaG_typeerror(L, s2v(func), \"call\");  /* nothing to call */\n  for (p = L->top; p > func; p--)  /* open space for metamethod */\n    setobjs2s(L, p, p-1);\n  L->top++;  /* stack space pre-allocated by the caller */\n  setobj2s(L, func, tm);  /* metamethod is the new function to be called */\n}\n\n\n/*\n** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.\n** Handle most typical cases (zero results for commands, one result for\n** expressions, multiple results for tail calls/single parameters)\n** separated.\n*/\nstatic void moveresults (lua_State *L, StkId res, int nres, int wanted) {\n  StkId firstresult;\n  int i;\n  switch (wanted) {  /* handle typical cases separately */\n    case 0:  /* no values needed */\n      L->top = res;\n      return;\n    case 1:  /* one value needed */\n      if (nres == 0)   /* no results? */\n        setnilvalue(s2v(res));  /* adjust with nil */\n      else\n        setobjs2s(L, res, L->top - nres);  /* move it to proper place */\n      L->top = res + 1;\n      return;\n    case LUA_MULTRET:\n      wanted = nres;  /* we want all results */\n      break;\n    default:  /* multiple results (or to-be-closed variables) */\n      if (hastocloseCfunc(wanted)) {  /* to-be-closed variables? */\n        ptrdiff_t savedres = savestack(L, res);\n        luaF_close(L, res, LUA_OK);  /* may change the stack */\n        res = restorestack(L, savedres);\n        wanted = codeNresults(wanted);  /* correct value */\n        if (wanted == LUA_MULTRET)\n          wanted = nres;\n      }\n      break;\n  }\n  firstresult = L->top - nres;  /* index of first result */\n  /* move all results to correct place */\n  for (i = 0; i < nres && i < wanted; i++)\n    setobjs2s(L, res + i, firstresult + i);\n  for (; i < wanted; i++)  /* complete wanted number of results */\n    setnilvalue(s2v(res + i));\n  L->top = res + wanted;  /* top points after the last result */\n}\n\n\n/*\n** Finishes a function call: calls hook if necessary, removes CallInfo,\n** moves current number of results to proper place.\n*/\nvoid luaD_poscall (lua_State *L, CallInfo *ci, int nres) {\n  if (L->hookmask)\n    L->top = rethook(L, ci, L->top - nres, nres);\n  L->ci = ci->previous;  /* back to caller */\n  /* move results to proper place */\n  moveresults(L, ci->func, nres, ci->nresults);\n}\n\n\n\n#define next_ci(L)  (L->ci->next ? L->ci->next : luaE_extendCI(L))\n\n\n/*\n** Prepare a function for a tail call, building its call info on top\n** of the current call info. 'narg1' is the number of arguments plus 1\n** (so that it includes the function itself).\n*/\nvoid luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) {\n  Proto *p = clLvalue(s2v(func))->p;\n  int fsize = p->maxstacksize;  /* frame size */\n  int nfixparams = p->numparams;\n  int i;\n  for (i = 0; i < narg1; i++)  /* move down function and arguments */\n    setobjs2s(L, ci->func + i, func + i);\n  checkstackGC(L, fsize);\n  func = ci->func;  /* moved-down function */\n  for (; narg1 <= nfixparams; narg1++)\n    setnilvalue(s2v(func + narg1));  /* complete missing arguments */\n  ci->top = func + 1 + fsize;  /* top for new function */\n  lua_assert(ci->top <= L->stack_last);\n  ci->u.l.savedpc = p->code;  /* starting point */\n  ci->callstatus |= CIST_TAIL;\n  L->top = func + narg1;  /* set top */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/\nvoid luaD_call (lua_State *L, StkId func, int nresults) {\n  lua_CFunction f;\n retry:\n  switch (ttypetag(s2v(func))) {\n    case LUA_VCCL:  /* C closure */\n      f = clCvalue(s2v(func))->f;\n      goto Cfunc;\n    case LUA_VLCF:  /* light C function */\n      f = fvalue(s2v(func));\n     Cfunc: {\n      int n;  /* number of returns */\n      CallInfo *ci;\n      checkstackGCp(L, LUA_MINSTACK, func);  /* ensure minimum stack size */\n      L->ci = ci = next_ci(L);\n      ci->nresults = nresults;\n      ci->callstatus = CIST_C;\n      ci->top = L->top + LUA_MINSTACK;\n      ci->func = func;\n      lua_assert(ci->top <= L->stack_last);\n      if (L->hookmask & LUA_MASKCALL) {\n        int narg = cast_int(L->top - func) - 1;\n        luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);\n      }\n      lua_unlock(L);\n      n = (*f)(L);  /* do the actual call */\n      lua_lock(L);\n      api_checknelems(L, n);\n      luaD_poscall(L, ci, n);\n      break;\n    }\n    case LUA_VLCL: {  /* Lua function */\n      CallInfo *ci;\n      Proto *p = clLvalue(s2v(func))->p;\n      int narg = cast_int(L->top - func) - 1;  /* number of real arguments */\n      int nfixparams = p->numparams;\n      int fsize = p->maxstacksize;  /* frame size */\n      checkstackGCp(L, fsize, func);\n      L->ci = ci = next_ci(L);\n      ci->nresults = nresults;\n      ci->u.l.savedpc = p->code;  /* starting point */\n      ci->callstatus = 0;\n      ci->top = func + 1 + fsize;\n      ci->func = func;\n      L->ci = ci;\n      for (; narg < nfixparams; narg++)\n        setnilvalue(s2v(L->top++));  /* complete missing arguments */\n      lua_assert(ci->top <= L->stack_last);\n      luaV_execute(L, ci);  /* run the function */\n      break;\n    }\n    default: {  /* not a function */\n      checkstackGCp(L, 1, func);  /* space for metamethod */\n      luaD_tryfuncTM(L, func);  /* try to get '__call' metamethod */\n      goto retry;  /* try again with metamethod */\n    }\n  }\n}\n\n\n/*\n** Similar to 'luaD_call', but does not allow yields during the call.\n*/\nvoid luaD_callnoyield (lua_State *L, StkId func, int nResults) {\n  incXCcalls(L);\n  if (getCcalls(L) <= CSTACKERR) {  /* possible C stack overflow? */\n    luaE_exitCcall(L);  /* to compensate decrement in next call */\n    luaE_enterCcall(L);  /* check properly */\n  }\n  luaD_call(L, func, nResults);\n  decXCcalls(L);\n}\n\n\n/*\n** Completes the execution of an interrupted C function, calling its\n** continuation function.\n*/\nstatic void finishCcall (lua_State *L, int status) {\n  CallInfo *ci = L->ci;\n  int n;\n  /* must have a continuation and must be able to call it */\n  lua_assert(ci->u.c.k != NULL && yieldable(L));\n  /* error status can only happen in a protected call */\n  lua_assert((ci->callstatus & CIST_YPCALL) || status == LUA_YIELD);\n  if (ci->callstatus & CIST_YPCALL) {  /* was inside a pcall? */\n    ci->callstatus &= ~CIST_YPCALL;  /* continuation is also inside it */\n    L->errfunc = ci->u.c.old_errfunc;  /* with the same error function */\n  }\n  /* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already\n     handled */\n  adjustresults(L, ci->nresults);\n  lua_unlock(L);\n  n = (*ci->u.c.k)(L, status, ci->u.c.ctx);  /* call continuation function */\n  lua_lock(L);\n  api_checknelems(L, n);\n  luaD_poscall(L, ci, n);  /* finish 'luaD_call' */\n}\n\n\n/*\n** Executes \"full continuation\" (everything in the stack) of a\n** previously interrupted coroutine until the stack is empty (or another\n** interruption long-jumps out of the loop). If the coroutine is\n** recovering from an error, 'ud' points to the error status, which must\n** be passed to the first continuation function (otherwise the default\n** status is LUA_YIELD).\n*/\nstatic void unroll (lua_State *L, void *ud) {\n  CallInfo *ci;\n  if (ud != NULL)  /* error status? */\n    finishCcall(L, *(int *)ud);  /* finish 'lua_pcallk' callee */\n  while ((ci = L->ci) != &L->base_ci) {  /* something in the stack */\n    if (!isLua(ci))  /* C function? */\n      finishCcall(L, LUA_YIELD);  /* complete its execution */\n    else {  /* Lua function */\n      luaV_finishOp(L);  /* finish interrupted instruction */\n      luaV_execute(L, ci);  /* execute down to higher C 'boundary' */\n    }\n  }\n}\n\n\n/*\n** Try to find a suspended protected call (a \"recover point\") for the\n** given thread.\n*/\nstatic CallInfo *findpcall (lua_State *L) {\n  CallInfo *ci;\n  for (ci = L->ci; ci != NULL; ci = ci->previous) {  /* search for a pcall */\n    if (ci->callstatus & CIST_YPCALL)\n      return ci;\n  }\n  return NULL;  /* no pending pcall */\n}\n\n\n/*\n** Recovers from an error in a coroutine. Finds a recover point (if\n** there is one) and completes the execution of the interrupted\n** 'luaD_pcall'. If there is no recover point, returns zero.\n*/\nstatic int recover (lua_State *L, int status) {\n  StkId oldtop;\n  CallInfo *ci = findpcall(L);\n  if (ci == NULL) return 0;  /* no recovery point */\n  /* \"finish\" luaD_pcall */\n  oldtop = restorestack(L, ci->u2.funcidx);\n  luaF_close(L, oldtop, status);  /* may change the stack */\n  oldtop = restorestack(L, ci->u2.funcidx);\n  luaD_seterrorobj(L, status, oldtop);\n  L->ci = ci;\n  L->allowhook = getoah(ci->callstatus);  /* restore original 'allowhook' */\n  luaD_shrinkstack(L);\n  L->errfunc = ci->u.c.old_errfunc;\n  return 1;  /* continue running the coroutine */\n}\n\n\n/*\n** Signal an error in the call to 'lua_resume', not in the execution\n** of the coroutine itself. (Such errors should not be handled by any\n** coroutine error handler and should not kill the coroutine.)\n*/\nstatic int resume_error (lua_State *L, const char *msg, int narg) {\n  L->top -= narg;  /* remove args from the stack */\n  setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */\n  api_incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\n/*\n** Do the work for 'lua_resume' in protected mode. Most of the work\n** depends on the status of the coroutine: initial state, suspended\n** inside a hook, or regularly suspended (optionally with a continuation\n** function), plus erroneous cases: non-suspended coroutine or dead\n** coroutine.\n*/\nstatic void resume (lua_State *L, void *ud) {\n  int n = *(cast(int*, ud));  /* number of arguments */\n  StkId firstArg = L->top - n;  /* first argument */\n  CallInfo *ci = L->ci;\n  if (L->status == LUA_OK) {  /* starting a coroutine? */\n    luaD_call(L, firstArg - 1, LUA_MULTRET);\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = LUA_OK;  /* mark that it is running (again) */\n    if (isLua(ci))  /* yielded inside a hook? */\n      luaV_execute(L, ci);  /* just continue running Lua code */\n    else {  /* 'common' yield */\n      if (ci->u.c.k != NULL) {  /* does it have a continuation function? */\n        lua_unlock(L);\n        n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */\n        lua_lock(L);\n        api_checknelems(L, n);\n      }\n      luaD_poscall(L, ci, n);  /* finish 'luaD_call' */\n    }\n    unroll(L, NULL);  /* run continuation */\n  }\n}\n\nLUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,\n                                      int *nresults) {\n  int status;\n  lua_lock(L);\n  if (L->status == LUA_OK) {  /* may be starting a coroutine */\n    if (L->ci != &L->base_ci)  /* not in base level? */\n      return resume_error(L, \"cannot resume non-suspended coroutine\", nargs);\n    else if (L->top - (L->ci->func + 1) == nargs)  /* no function? */\n      return resume_error(L, \"cannot resume dead coroutine\", nargs);\n  }\n  else if (L->status != LUA_YIELD)  /* ended with errors? */\n    return resume_error(L, \"cannot resume dead coroutine\", nargs);\n  if (from == NULL)\n    L->nCcalls = CSTACKTHREAD;\n  else  /* correct 'nCcalls' for this thread */\n    L->nCcalls = getCcalls(from) - L->nci - CSTACKCF;\n  if (L->nCcalls <= CSTACKERR)\n    return resume_error(L, \"C stack overflow\", nargs);\n  luai_userstateresume(L, nargs);\n  api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);\n  status = luaD_rawrunprotected(L, resume, &nargs);\n   /* continue running after recoverable errors */\n  while (errorstatus(status) && recover(L, status)) {\n    /* unroll continuation */\n    status = luaD_rawrunprotected(L, unroll, &status);\n  }\n  if (likely(!errorstatus(status)))\n    lua_assert(status == L->status);  /* normal end or yield */\n  else {  /* unrecoverable error */\n    L->status = cast_byte(status);  /* mark thread as 'dead' */\n    luaD_seterrorobj(L, status, L->top);  /* push error message */\n    L->ci->top = L->top;\n  }\n  *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield\n                                    : cast_int(L->top - (L->ci->func + 1));\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_isyieldable (lua_State *L) {\n  return yieldable(L);\n}\n\n\nLUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,\n                        lua_KFunction k) {\n  CallInfo *ci;\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  ci = L->ci;\n  api_checknelems(L, nresults);\n  if (unlikely(!yieldable(L))) {\n    if (L != G(L)->mainthread)\n      luaG_runerror(L, \"attempt to yield across a C-call boundary\");\n    else\n      luaG_runerror(L, \"attempt to yield from outside a coroutine\");\n  }\n  L->status = LUA_YIELD;\n  if (isLua(ci)) {  /* inside a hook? */\n    lua_assert(!isLuacode(ci));\n    api_check(L, k == NULL, \"hooks cannot continue after yielding\");\n    ci->u2.nyield = 0;  /* no results */\n  }\n  else {\n    if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */\n      ci->u.c.ctx = ctx;  /* save context */\n    ci->u2.nyield = nresults;  /* save number of results */\n    luaD_throw(L, LUA_YIELD);\n  }\n  lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */\n  lua_unlock(L);\n  return 0;  /* return to 'luaD_hook' */\n}\n\n\n/*\n** Call the C function 'func' in protected mode, restoring basic\n** thread information ('allowhook', etc.) and in particular\n** its stack level in case of errors.\n*/\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  CallInfo *old_ci = L->ci;\n  lu_byte old_allowhooks = L->allowhook;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (unlikely(status != LUA_OK)) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    L->ci = old_ci;\n    L->allowhook = old_allowhooks;\n    status = luaF_close(L, oldtop, status);\n    oldtop = restorestack(L, old_top);  /* previous call may change stack */\n    luaD_seterrorobj(L, status, oldtop);\n    luaD_shrinkstack(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to 'f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* dynamic structure used by the scanner */\n  Dyndata dyd;  /* dynamic structures used by the parser */\n  const char *mode;\n  const char *name;\n};\n\n\nstatic void checkmode (lua_State *L, const char *mode, const char *x) {\n  if (mode && strchr(mode, x[0]) == NULL) {\n    luaO_pushfstring(L,\n       \"attempt to load a %s chunk (mode is '%s')\", x, mode);\n    luaD_throw(L, LUA_ERRSYNTAX);\n  }\n}\n\n\nstatic void f_parser (lua_State *L, void *ud) {\n  LClosure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = zgetc(p->z);  /* read first character */\n  if (c == LUA_SIGNATURE[0]) {\n    checkmode(L, p->mode, \"binary\");\n    cl = luaU_undump(L, p->z, p->name);\n  }\n  else {\n    checkmode(L, p->mode, \"text\");\n    cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);\n  }\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luaF_initupvals(L, cl);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                        const char *mode) {\n  struct SParser p;\n  int status;\n  incnny(L);  /* cannot yield during parsing */\n  p.z = z; p.name = name; p.mode = mode;\n  p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;\n  p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;\n  p.dyd.label.arr = NULL; p.dyd.label.size = 0;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);\n  luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);\n  luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);\n  decnny(L);\n  return status;\n}\n\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldo.h",
    "content": "/*\n** $Id: ldo.h $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n/*\n** Macro to check stack size and grow stack if needed.  Parameters\n** 'pre'/'pos' allow the macro to preserve a pointer into the\n** stack across reallocations, doing the work only when needed.\n** It also allows the running of one GC step when the stack is\n** reallocated.\n** 'condmovestack' is used in heavy tests to force a stack reallocation\n** at every check.\n*/\n#define luaD_checkstackaux(L,n,pre,pos)  \\\n\tif (L->stack_last - L->top <= (n)) \\\n\t  { pre; luaD_growstack(L, n, 1); pos; } \\\n        else { condmovestack(L,pre,pos); }\n\n/* In general, 'pre'/'pos' are empty (nothing to save) */\n#define luaD_checkstack(L,n)\tluaD_checkstackaux(L,n,(void)0,(void)0)\n\n\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((StkId)((char *)L->stack + (n)))\n\n\n/* macro to check stack size, preserving 'p' */\n#define checkstackGCp(L,n,p)  \\\n  luaD_checkstackaux(L, n, \\\n    ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \\\n    luaC_checkGC(L),  /* stack grow uses memory */ \\\n    p = restorestack(L, t__))  /* 'pos' part: restore 'p' */\n\n\n/* macro to check stack size and GC */\n#define checkstackGC(L,fsize)  \\\n\tluaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)\n\n\n/* type of protected functions, to be ran by 'runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,\n                                                  const char *mode);\nLUAI_FUNC void luaD_hook (lua_State *L, int event, int line,\n                                        int fTransfer, int nTransfer);\nLUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);\nLUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);\nLUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);\nLUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);\nLUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);\nLUAI_FUNC void luaD_shrinkstack (lua_State *L);\nLUAI_FUNC void luaD_inctop (lua_State *L);\n\nLUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ldump.c",
    "content": "/*\n** $Id: ldump.c $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\n\ntypedef struct {\n  lua_State *L;\n  lua_Writer writer;\n  void *data;\n  int strip;\n  int status;\n} DumpState;\n\n\n/*\n** All high-level dumps go through dumpVector; you can change it to\n** change the endianness of the result\n*/\n#define dumpVector(D,v,n)\tdumpBlock(D,v,(n)*sizeof((v)[0]))\n\n#define dumpLiteral(D, s)\tdumpBlock(D,s,sizeof(s) - sizeof(char))\n\n\nstatic void dumpBlock (DumpState *D, const void *b, size_t size) {\n  if (D->status == 0 && size > 0) {\n    lua_unlock(D->L);\n    D->status = (*D->writer)(D->L, b, size, D->data);\n    lua_lock(D->L);\n  }\n}\n\n\n#define dumpVar(D,x)\t\tdumpVector(D,&x,1)\n\n\nstatic void dumpByte (DumpState *D, int y) {\n  lu_byte x = (lu_byte)y;\n  dumpVar(D, x);\n}\n\n\n/* dumpInt Buff Size */\n#define DIBS    ((sizeof(size_t) * 8 / 7) + 1)\n\nstatic void dumpSize (DumpState *D, size_t x) {\n  lu_byte buff[DIBS];\n  int n = 0;\n  do {\n    buff[DIBS - (++n)] = x & 0x7f;  /* fill buffer in reverse order */\n    x >>= 7;\n  } while (x != 0);\n  buff[DIBS - 1] |= 0x80;  /* mark last byte */\n  dumpVector(D, buff + DIBS - n, n);\n}\n\n\nstatic void dumpInt (DumpState *D, int x) {\n  dumpSize(D, x);\n}\n\n\nstatic void dumpNumber (DumpState *D, lua_Number x) {\n  dumpVar(D, x);\n}\n\n\nstatic void dumpInteger (DumpState *D, lua_Integer x) {\n  dumpVar(D, x);\n}\n\n\nstatic void dumpString (DumpState *D, const TString *s) {\n  if (s == NULL)\n    dumpSize(D, 0);\n  else {\n    size_t size = tsslen(s);\n    const char *str = getstr(s);\n    dumpSize(D, size + 1);\n    dumpVector(D, str, size);\n  }\n}\n\n\nstatic void dumpCode (DumpState *D, const Proto *f) {\n  dumpInt(D, f->sizecode);\n  dumpVector(D, f->code, f->sizecode);\n}\n\n\nstatic void dumpFunction(DumpState *D, const Proto *f, TString *psource);\n\nstatic void dumpConstants (DumpState *D, const Proto *f) {\n  int i;\n  int n = f->sizek;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++) {\n    const TValue *o = &f->k[i];\n    int tt = ttypetag(o);\n    dumpByte(D, tt);\n    switch (tt) {\n      case LUA_VNUMFLT:\n        dumpNumber(D, fltvalue(o));\n        break;\n      case LUA_VNUMINT:\n        dumpInteger(D, ivalue(o));\n        break;\n      case LUA_VSHRSTR:\n      case LUA_VLNGSTR:\n        dumpString(D, tsvalue(o));\n        break;\n      default:\n        lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE);\n    }\n  }\n}\n\n\nstatic void dumpProtos (DumpState *D, const Proto *f) {\n  int i;\n  int n = f->sizep;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++)\n    dumpFunction(D, f->p[i], f->source);\n}\n\n\nstatic void dumpUpvalues (DumpState *D, const Proto *f) {\n  int i, n = f->sizeupvalues;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++) {\n    dumpByte(D, f->upvalues[i].instack);\n    dumpByte(D, f->upvalues[i].idx);\n    dumpByte(D, f->upvalues[i].kind);\n  }\n}\n\n\nstatic void dumpDebug (DumpState *D, const Proto *f) {\n  int i, n;\n  n = (D->strip) ? 0 : f->sizelineinfo;\n  dumpInt(D, n);\n  dumpVector(D, f->lineinfo, n);\n  n = (D->strip) ? 0 : f->sizeabslineinfo;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++) {\n    dumpInt(D, f->abslineinfo[i].pc);\n    dumpInt(D, f->abslineinfo[i].line);\n  }\n  n = (D->strip) ? 0 : f->sizelocvars;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++) {\n    dumpString(D, f->locvars[i].varname);\n    dumpInt(D, f->locvars[i].startpc);\n    dumpInt(D, f->locvars[i].endpc);\n  }\n  n = (D->strip) ? 0 : f->sizeupvalues;\n  dumpInt(D, n);\n  for (i = 0; i < n; i++)\n    dumpString(D, f->upvalues[i].name);\n}\n\n\nstatic void dumpFunction (DumpState *D, const Proto *f, TString *psource) {\n  if (D->strip || f->source == psource)\n    dumpString(D, NULL);  /* no debug info or same source as its parent */\n  else\n    dumpString(D, f->source);\n  dumpInt(D, f->linedefined);\n  dumpInt(D, f->lastlinedefined);\n  dumpByte(D, f->numparams);\n  dumpByte(D, f->is_vararg);\n  dumpByte(D, f->maxstacksize);\n  dumpCode(D, f);\n  dumpConstants(D, f);\n  dumpUpvalues(D, f);\n  dumpProtos(D, f);\n  dumpDebug(D, f);\n}\n\n\nstatic void dumpHeader (DumpState *D) {\n  dumpLiteral(D, LUA_SIGNATURE);\n  dumpByte(D, LUAC_VERSION);\n  dumpByte(D, LUAC_FORMAT);\n  dumpLiteral(D, LUAC_DATA);\n  dumpByte(D, sizeof(Instruction));\n  dumpByte(D, sizeof(lua_Integer));\n  dumpByte(D, sizeof(lua_Number));\n  dumpInteger(D, LUAC_INT);\n  dumpNumber(D, LUAC_NUM);\n}\n\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,\n              int strip) {\n  DumpState D;\n  D.L = L;\n  D.writer = w;\n  D.data = data;\n  D.strip = strip;\n  D.status = 0;\n  dumpHeader(&D);\n  dumpByte(&D, f->sizeupvalues);\n  dumpFunction(&D, f, NULL);\n  return D.status;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\nCClosure *luaF_newCclosure (lua_State *L, int nupvals) {\n  GCObject *o = luaC_newobj(L, LUA_VCCL, sizeCclosure(nupvals));\n  CClosure *c = gco2ccl(o);\n  c->nupvalues = cast_byte(nupvals);\n  return c;\n}\n\n\nLClosure *luaF_newLclosure (lua_State *L, int nupvals) {\n  GCObject *o = luaC_newobj(L, LUA_VLCL, sizeLclosure(nupvals));\n  LClosure *c = gco2lcl(o);\n  c->p = NULL;\n  c->nupvalues = cast_byte(nupvals);\n  while (nupvals--) c->upvals[nupvals] = NULL;\n  return c;\n}\n\n\n/*\n** fill a closure with new closed upvalues\n*/\nvoid luaF_initupvals (lua_State *L, LClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++) {\n    GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));\n    UpVal *uv = gco2upv(o);\n    uv->v = &uv->u.value;  /* make it closed */\n    setnilvalue(uv->v);\n    cl->upvals[i] = uv;\n    luaC_objbarrier(L, cl, o);\n  }\n}\n\n\n/*\n** Create a new upvalue at the given level, and link it to the list of\n** open upvalues of 'L' after entry 'prev'.\n**/\nstatic UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) {\n  GCObject *o = luaC_newobj(L, LUA_VUPVAL, sizeof(UpVal));\n  UpVal *uv = gco2upv(o);\n  UpVal *next = *prev;\n  uv->v = s2v(level);  /* current value lives in the stack */\n  uv->tbc = tbc;\n  uv->u.open.next = next;  /* link it to list of open upvalues */\n  uv->u.open.previous = prev;\n  if (next)\n    next->u.open.previous = &uv->u.open.next;\n  *prev = uv;\n  if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */\n    L->twups = G(L)->twups;  /* link it to the list */\n    G(L)->twups = L;\n  }\n  return uv;\n}\n\n\n/*\n** Find and reuse, or create if it does not exist, an upvalue\n** at the given level.\n*/\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  UpVal **pp = &L->openupval;\n  UpVal *p;\n  lua_assert(isintwups(L) || L->openupval == NULL);\n  while ((p = *pp) != NULL && uplevel(p) >= level) {  /* search for it */\n    lua_assert(!isdead(G(L), p));\n    if (uplevel(p) == level)  /* corresponding upvalue? */\n      return p;  /* return it */\n    pp = &p->u.open.next;\n  }\n  /* not found: create a new upvalue after 'pp' */\n  return newupval(L, 0, level, pp);\n}\n\n\nstatic void callclose (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 3, 0);\n}\n\n\n/*\n** Prepare closing method plus its arguments for object 'obj' with\n** error message 'err'. (This function assumes EXTRA_STACK.)\n*/\nstatic int prepclosingmethod (lua_State *L, TValue *obj, TValue *err) {\n  StkId top = L->top;\n  const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);\n  if (ttisnil(tm))  /* no metamethod? */\n    return 0;  /* nothing to call */\n  setobj2s(L, top, tm);  /* will call metamethod... */\n  setobj2s(L, top + 1, obj);  /* with 'self' as the 1st argument */\n  setobj2s(L, top + 2, err);  /* and error msg. as 2nd argument */\n  L->top = top + 3;  /* add function and arguments */\n  return 1;\n}\n\n\n/*\n** Raise an error with message 'msg', inserting the name of the\n** local variable at position 'level' in the stack.\n*/\nstatic void varerror (lua_State *L, StkId level, const char *msg) {\n  int idx = cast_int(level - L->ci->func);\n  const char *vname = luaG_findlocal(L, L->ci, idx, NULL);\n  if (vname == NULL) vname = \"?\";\n  luaG_runerror(L, msg, vname);\n}\n\n\n/*\n** Prepare and call a closing method. If status is OK, code is still\n** inside the original protected call, and so any error will be handled\n** there. Otherwise, a previous error already activated the original\n** protected call, and so the call to the closing method must be\n** protected here. (A status == CLOSEPROTECT behaves like a previous\n** error, to also run the closing method in protected mode).\n** If status is OK, the call to the closing method will be pushed\n** at the top of the stack. Otherwise, values are pushed after\n** the 'level' of the upvalue being closed, as everything after\n** that won't be used again.\n*/\nstatic int callclosemth (lua_State *L, StkId level, int status) {\n  TValue *uv = s2v(level);  /* value being closed */\n  if (likely(status == LUA_OK)) {\n    if (prepclosingmethod(L, uv, &G(L)->nilvalue))  /* something to call? */\n      callclose(L, NULL);  /* call closing method */\n    else if (!l_isfalse(uv))  /* non-closable non-false value? */\n      varerror(L, level, \"attempt to close non-closable variable '%s'\");\n  }\n  else {  /* must close the object in protected mode */\n    ptrdiff_t oldtop;\n    level++;  /* space for error message */\n    oldtop = savestack(L, level + 1);  /* top will be after that */\n    luaD_seterrorobj(L, status, level);  /* set error message */\n    if (prepclosingmethod(L, uv, s2v(level))) {  /* something to call? */\n      int newstatus = luaD_pcall(L, callclose, NULL, oldtop, 0);\n      if (newstatus != LUA_OK && status == CLOSEPROTECT)  /* first error? */\n        status = newstatus;  /* this will be the new error */\n      else {\n        if (newstatus != LUA_OK)  /* suppressed error? */\n          luaE_warnerror(L, \"__close metamethod\");\n        /* leave original error (or nil) on top */\n        L->top = restorestack(L, oldtop);\n      }\n    }\n    /* else no metamethod; ignore this case and keep original error */\n  }\n  return status;\n}\n\n\n/*\n** Try to create a to-be-closed upvalue\n** (can raise a memory-allocation error)\n*/\nstatic void trynewtbcupval (lua_State *L, void *ud) {\n  newupval(L, 1, cast(StkId, ud), &L->openupval);\n}\n\n\n/*\n** Create a to-be-closed upvalue. If there is a memory error\n** when creating the upvalue, the closing method must be called here,\n** as there is no upvalue to call it later.\n*/\nvoid luaF_newtbcupval (lua_State *L, StkId level) {\n  TValue *obj = s2v(level);\n  lua_assert(L->openupval == NULL || uplevel(L->openupval) < level);\n  if (!l_isfalse(obj)) {  /* false doesn't need to be closed */\n    int status;\n    const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);\n    if (ttisnil(tm))  /* no metamethod? */\n      varerror(L, level, \"variable '%s' got a non-closable value\");\n    status = luaD_rawrunprotected(L, trynewtbcupval, level);\n    if (unlikely(status != LUA_OK)) {  /* memory error creating upvalue? */\n      lua_assert(status == LUA_ERRMEM);\n      luaD_seterrorobj(L, LUA_ERRMEM, level + 1);  /* save error message */\n      /* next call must succeed, as object is closable */\n      prepclosingmethod(L, s2v(level), s2v(level + 1));\n      callclose(L, NULL);  /* call closing method */\n      luaD_throw(L, LUA_ERRMEM);  /* throw memory error */\n    }\n  }\n}\n\n\nvoid luaF_unlinkupval (UpVal *uv) {\n  lua_assert(upisopen(uv));\n  *uv->u.open.previous = uv->u.open.next;\n  if (uv->u.open.next)\n    uv->u.open.next->u.open.previous = uv->u.open.previous;\n}\n\n\nint luaF_close (lua_State *L, StkId level, int status) {\n  UpVal *uv;\n  while ((uv = L->openupval) != NULL && uplevel(uv) >= level) {\n    TValue *slot = &uv->u.value;  /* new position for value */\n    lua_assert(uplevel(uv) < L->top);\n    if (uv->tbc && status != NOCLOSINGMETH) {\n      /* must run closing method, which may change the stack */\n      ptrdiff_t levelrel = savestack(L, level);\n      status = callclosemth(L, uplevel(uv), status);\n      level = restorestack(L, levelrel);\n    }\n    luaF_unlinkupval(uv);\n    setobj(L, slot, uv->v);  /* move value to upvalue slot */\n    uv->v = slot;  /* now current value lives here */\n    if (!iswhite(uv)) {  /* neither white nor dead? */\n      nw2black(uv);  /* closed upvalues cannot be gray */\n      luaC_barrier(L, uv, slot);\n    }\n  }\n  return status;\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_VPROTO, sizeof(Proto));\n  Proto *f = gco2p(o);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->sizecode = 0;\n  f->lineinfo = NULL;\n  f->sizelineinfo = 0;\n  f->abslineinfo = NULL;\n  f->sizeabslineinfo = 0;\n  f->upvalues = NULL;\n  f->sizeupvalues = 0;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->locvars = NULL;\n  f->sizelocvars = 0;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  luaM_freearray(L, f->code, f->sizecode);\n  luaM_freearray(L, f->p, f->sizep);\n  luaM_freearray(L, f->k, f->sizek);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo);\n  luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo);\n  luaM_freearray(L, f->locvars, f->sizelocvars);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues);\n  luaM_free(L, f);\n}\n\n\n/*\n** Look for n-th local variable at line 'line' in function 'func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast_int(offsetof(CClosure, upvalue)) + \\\n                         cast_int(sizeof(TValue)) * (n))\n\n#define sizeLclosure(n)\t(cast_int(offsetof(LClosure, upvals)) + \\\n                         cast_int(sizeof(TValue *)) * (n))\n\n\n/* test whether thread is in 'twups' list */\n#define isintwups(L)\t(L->twups != L)\n\n\n/*\n** maximum number of upvalues in a closure (both C and Lua). (Value\n** must fit in a VM register.)\n*/\n#define MAXUPVAL\t255\n\n\n#define upisopen(up)\t((up)->v != &(up)->u.value)\n\n\n#define uplevel(up)\tcheck_exp(upisopen(up), cast(StkId, (up)->v))\n\n\n/*\n** maximum number of misses before giving up the cache of closures\n** in prototypes\n*/\n#define MAXMISS\t\t10\n\n\n/*\n** Special \"status\" for 'luaF_close'\n*/\n\n/* close upvalues without running their closing methods */\n#define NOCLOSINGMETH\t(-1)\n\n/* close upvalues running all closing methods in protected mode */\n#define CLOSEPROTECT\t(-2)\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);\nLUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);\nLUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);\nLUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);\nLUAI_FUNC void luaF_unlinkupval (UpVal *uv);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lgc.c",
    "content": "/*\n** $Id: lgc.c $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <stdio.h>\n#include <string.h>\n\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n/*\n** Maximum number of elements to sweep in each single step.\n** (Large enough to dissipate fixed overheads but small enough\n** to allow small steps for the collector.)\n*/\n#define GCSWEEPMAX\t100\n\n/*\n** Maximum number of finalizers to call in each single step.\n*/\n#define GCFINMAX\t10\n\n\n/*\n** Cost of calling one finalizer.\n*/\n#define GCFINALIZECOST\t50\n\n\n/*\n** The equivalent, in bytes, of one unit of \"work\" (visiting a slot,\n** sweeping an object, etc.)\n*/\n#define WORK2MEM\tsizeof(TValue)\n\n\n/*\n** macro to adjust 'pause': 'pause' is actually used like\n** 'pause / PAUSEADJ' (value chosen by tests)\n*/\n#define PAUSEADJ\t\t100\n\n\n/* mask with all color bits */\n#define maskcolors\t(bitmask(BLACKBIT) | WHITEBITS)\n\n/* mask with all GC bits */\n#define maskgcbits      (maskcolors | AGEBITS)\n\n\n/* macro to erase all color bits then set only the current white bit */\n#define makewhite(g,x)\t\\\n  (x->marked = cast_byte((x->marked & ~maskcolors) | luaC_white(g)))\n\n/* make an object gray (neither white nor black) */\n#define set2gray(x)\tresetbits(x->marked, maskcolors)\n\n\n/* make an object black (coming from any color) */\n#define set2black(x)  \\\n  (x->marked = cast_byte((x->marked & ~WHITEBITS) | bitmask(BLACKBIT)))\n\n\n#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))\n\n#define keyiswhite(n)   (keyiscollectable(n) && iswhite(gckey(n)))\n\n\n/*\n** Protected access to objects in values\n*/\n#define gcvalueN(o)     (iscollectable(o) ? gcvalue(o) : NULL)\n\n\n#define markvalue(g,o) { checkliveness(g->mainthread,o); \\\n  if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }\n\n#define markkey(g, n)\t{ if keyiswhite(n) reallymarkobject(g,gckey(n)); }\n\n#define markobject(g,t)\t{ if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }\n\n/*\n** mark an object that can be NULL (either because it is really optional,\n** or it was stripped as debug info, or inside an uncompleted structure)\n*/\n#define markobjectN(g,t)\t{ if (t) markobject(g,t); }\n\nstatic void reallymarkobject (global_State *g, GCObject *o);\nstatic lu_mem atomic (lua_State *L);\nstatic void entersweep (lua_State *L);\n\n\n/*\n** {======================================================\n** Generic functions\n** =======================================================\n*/\n\n\n/*\n** one after last element in a hash array\n*/\n#define gnodelast(h)\tgnode(h, cast_sizet(sizenode(h)))\n\n\nstatic GCObject **getgclist (GCObject *o) {\n  switch (o->tt) {\n    case LUA_VTABLE: return &gco2t(o)->gclist;\n    case LUA_VLCL: return &gco2lcl(o)->gclist;\n    case LUA_VCCL: return &gco2ccl(o)->gclist;\n    case LUA_VTHREAD: return &gco2th(o)->gclist;\n    case LUA_VPROTO: return &gco2p(o)->gclist;\n    case LUA_VUSERDATA: {\n      Udata *u = gco2u(o);\n      lua_assert(u->nuvalue > 0);\n      return &u->gclist;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** Link a collectable object 'o' with a known type into the list 'p'.\n** (Must be a macro to access the 'gclist' field in different types.)\n*/\n#define linkgclist(o,p)\tlinkgclist_(obj2gco(o), &(o)->gclist, &(p))\n\nstatic void linkgclist_ (GCObject *o, GCObject **pnext, GCObject **list) {\n  lua_assert(!isgray(o));  /* cannot be in a gray list */\n  *pnext = *list;\n  *list = o;\n  set2gray(o);  /* now it is */\n}\n\n\n/*\n** Link a generic collectable object 'o' into the list 'p'.\n*/\n#define linkobjgclist(o,p) linkgclist_(obj2gco(o), getgclist(o), &(p))\n\n\n\n/*\n** Clear keys for empty entries in tables. If entry is empty\n** and its key is not marked, mark its entry as dead. This allows the\n** collection of the key, but keeps its entry in the table (its removal\n** could break a chain). The main feature of a dead key is that it must\n** be different from any other value, to do not disturb searches.\n** Other places never manipulate dead keys, because its associated empty\n** value is enough to signal that the entry is logically empty.\n*/\nstatic void clearkey (Node *n) {\n  lua_assert(isempty(gval(n)));\n  if (keyiswhite(n))\n    setdeadkey(n);  /* unused and unmarked key; remove it */\n}\n\n\n/*\n** tells whether a key or value can be cleared from a weak\n** table. Non-collectable objects are never removed from weak\n** tables. Strings behave as 'values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for objects\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (global_State *g, const GCObject *o) {\n  if (o == NULL) return 0;  /* non-collectable value */\n  else if (novariant(o->tt) == LUA_TSTRING) {\n    markobject(g, o);  /* strings are 'values', so are never weak */\n    return 0;\n  }\n  else return iswhite(o);\n}\n\n\n/*\n** Barrier that moves collector forward, that is, marks the white object\n** 'v' being pointed by the black object 'o'.  In the generational\n** mode, 'v' must also become old, if 'o' is old; however, it cannot\n** be changed directly to OLD, because it may still point to non-old\n** objects. So, it is marked as OLD0. In the next cycle it will become\n** OLD1, and in the next it will finally become OLD (regular old). By\n** then, any object it points to will also be old.  If called in the\n** incremental sweep phase, it clears the black object to white (sweep\n** it) to avoid other barrier calls for this same object. (That cannot\n** be done is generational mode, as its sweep does not distinguish\n** whites from deads.)\n*/\nvoid luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  if (keepinvariant(g)) {  /* must keep invariant? */\n    reallymarkobject(g, v);  /* restore invariant */\n    if (isold(o)) {\n      lua_assert(!isold(v));  /* white object could not be old */\n      setage(v, G_OLD0);  /* restore generational invariant */\n    }\n  }\n  else {  /* sweep phase */\n    lua_assert(issweepphase(g));\n    if (g->gckind == KGC_INC)  /* incremental mode? */\n      makewhite(g, o);  /* mark 'o' as white to avoid other barriers */\n  }\n}\n\n\n/*\n** barrier that moves collector backward, that is, mark the black object\n** pointing to a white object as gray again.\n*/\nvoid luaC_barrierback_ (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && !isdead(g, o));\n  lua_assert((g->gckind == KGC_GEN) == (isold(o) && getage(o) != G_TOUCHED1));\n  if (getage(o) == G_TOUCHED2)  /* already in gray list? */\n    set2gray(o);  /* make it gray to become touched1 */\n  else  /* link it in 'grayagain' and paint it gray */\n    linkobjgclist(o, g->grayagain);\n  if (isold(o))  /* generational mode? */\n    setage(o, G_TOUCHED1);  /* touched in current cycle */\n}\n\n\nvoid luaC_fix (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  lua_assert(g->allgc == o);  /* object must be 1st in 'allgc' list! */\n  set2gray(o);  /* they will be gray forever */\n  setage(o, G_OLD);  /* and old forever */\n  g->allgc = o->next;  /* remove object from 'allgc' list */\n  o->next = g->fixedgc;  /* link it to 'fixedgc' list */\n  g->fixedgc = o;\n}\n\n\n/*\n** create a new collectable object (with given type and size) and link\n** it to 'allgc' list.\n*/\nGCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {\n  global_State *g = G(L);\n  GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));\n  o->marked = luaC_white(g);\n  o->tt = tt;\n  o->next = g->allgc;\n  g->allgc = o;\n  return o;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Mark functions\n** =======================================================\n*/\n\n\n/*\n** Mark an object.  Userdata with no user values, strings, and closed\n** upvalues are visited and turned black here.  Open upvalues are\n** already indirectly linked through their respective threads in the\n** 'twups' list, so they don't go to the gray list; nevertheless, they\n** are kept gray to avoid barriers, as their values will be revisited\n** by the thread or by 'remarkupvals'.  Other objects are added to the\n** gray list to be visited (and turned black) later.  Both userdata and\n** upvalues can call this function recursively, but this recursion goes\n** for at most two levels: An upvalue cannot refer to another upvalue\n** (only closures can), and a userdata's metatable must be a table.\n*/\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n  switch (o->tt) {\n    case LUA_VSHRSTR:\n    case LUA_VLNGSTR: {\n      set2black(o);  /* nothing to visit */\n      break;\n    }\n    case LUA_VUPVAL: {\n      UpVal *uv = gco2upv(o);\n      if (upisopen(uv))\n        set2gray(uv);  /* open upvalues are kept gray */\n      else\n        set2black(o);  /* closed upvalues are visited here */\n      markvalue(g, uv->v);  /* mark its content */\n      break;\n    }\n    case LUA_VUSERDATA: {\n      Udata *u = gco2u(o);\n      if (u->nuvalue == 0) {  /* no user values? */\n        markobjectN(g, u->metatable);  /* mark its metatable */\n        set2black(o);  /* nothing else to mark */\n        break;\n      }\n      /* else... */\n    }  /* FALLTHROUGH */\n    case LUA_VLCL: case LUA_VCCL: case LUA_VTABLE:\n    case LUA_VTHREAD: case LUA_VPROTO: {\n      linkobjgclist(o, g->gray);  /* to be visited later */\n      break;\n    }\n    default: lua_assert(0); break;\n  }\n}\n\n\n/*\n** mark metamethods for basic types\n*/\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i < LUA_NUMTAGS; i++)\n    markobjectN(g, g->mt[i]);\n}\n\n\n/*\n** mark all objects in list of being-finalized\n*/\nstatic lu_mem markbeingfnz (global_State *g) {\n  GCObject *o;\n  lu_mem count = 0;\n  for (o = g->tobefnz; o != NULL; o = o->next) {\n    count++;\n    markobject(g, o);\n  }\n  return count;\n}\n\n\n/*\n** For each non-marked thread, simulates a barrier between each open\n** upvalue and its value. (If the thread is collected, the value will be\n** assigned to the upvalue, but then it can be too late for the barrier\n** to act. The \"barrier\" does not need to check colors: A non-marked\n** thread must be young; upvalues cannot be older than their threads; so\n** any visited upvalue must be young too.) Also removes the thread from\n** the list, as it was already visited. Removes also threads with no\n** upvalues, as they have nothing to be checked. (If the thread gets an\n** upvalue later, it will be linked in the list again.)\n*/\nstatic int remarkupvals (global_State *g) {\n  lua_State *thread;\n  lua_State **p = &g->twups;\n  int work = 0;  /* estimate of how much work was done here */\n  while ((thread = *p) != NULL) {\n    work++;\n    if (!iswhite(thread) && thread->openupval != NULL)\n      p = &thread->twups;  /* keep marked thread with upvalues in the list */\n    else {  /* thread is not marked or without upvalues */\n      UpVal *uv;\n      lua_assert(!isold(thread) || thread->openupval == NULL);\n      *p = thread->twups;  /* remove thread from the list */\n      thread->twups = thread;  /* mark that it is out of list */\n      for (uv = thread->openupval; uv != NULL; uv = uv->u.open.next) {\n        lua_assert(getage(uv) <= getage(thread));\n        work++;\n        if (!iswhite(uv)) {  /* upvalue already visited? */\n          lua_assert(upisopen(uv) && isgray(uv));\n          markvalue(g, uv->v);  /* mark its value */\n        }\n      }\n    }\n  }\n  return work;\n}\n\n\nstatic void cleargraylists (global_State *g) {\n  g->gray = g->grayagain = NULL;\n  g->weak = g->allweak = g->ephemeron = NULL;\n}\n\n\n/*\n** mark root set and reset all gray lists, to start a new collection\n*/\nstatic void restartcollection (global_State *g) {\n  cleargraylists(g);\n  markobject(g, g->mainthread);\n  markvalue(g, &g->l_registry);\n  markmt(g);\n  markbeingfnz(g);  /* mark any finalizing object left from previous cycle */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Traverse functions\n** =======================================================\n*/\n\n\n/*\n** Check whether object 'o' should be kept in the 'grayagain' list for\n** post-processing by 'correctgraylist'. (It could put all old objects\n** in the list and leave all the work to 'correctgraylist', but it is\n** more efficient to avoid adding elements that will be removed.) Only\n** TOUCHED1 objects need to be in the list. TOUCHED2 doesn't need to go\n** back to a gray list, but then it must become OLD. (That is what\n** 'correctgraylist' does when it finds a TOUCHED2 object.)\n*/\nstatic void genlink (global_State *g, GCObject *o) {\n  lua_assert(isblack(o));\n  if (getage(o) == G_TOUCHED1) {  /* touched in this cycle? */\n    linkobjgclist(o, g->grayagain);  /* link it back in 'grayagain' */\n  }  /* everything else do not need to be linked back */\n  else if (getage(o) == G_TOUCHED2)\n    changeage(o, G_TOUCHED2, G_OLD);  /* advance age */\n}\n\n\n/*\n** Traverse a table with weak values and link it to proper list. During\n** propagate phase, keep it in 'grayagain' list, to be revisited in the\n** atomic phase. In the atomic phase, if table has any white value,\n** put it in 'weak' list, to be cleared.\n*/\nstatic void traverseweakvalue (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  /* if there is array part, assume it may have white values (it is not\n     worth traversing it now just to check) */\n  int hasclears = (h->alimit > 0);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    if (isempty(gval(n)))  /* entry is empty? */\n      clearkey(n);  /* clear its key */\n    else {\n      lua_assert(!keyisnil(n));\n      markkey(g, n);\n      if (!hasclears && iscleared(g, gcvalueN(gval(n))))  /* a white value? */\n        hasclears = 1;  /* table will have to be cleared */\n    }\n  }\n  if (g->gcstate == GCSatomic && hasclears)\n    linkgclist(h, g->weak);  /* has to be cleared later */\n  else\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n}\n\n\n/*\n** Traverse an ephemeron table and link it to proper list. Returns true\n** iff any object was marked during this traversal (which implies that\n** convergence has to continue). During propagation phase, keep table\n** in 'grayagain' list, to be visited again in the atomic phase. In\n** the atomic phase, if table has any white->white entry, it has to\n** be revisited during ephemeron convergence (as that key may turn\n** black). Otherwise, if it has any white key, table has to be cleared\n** (in the atomic phase). In generational mode, some tables\n** must be kept in some gray list for post-processing; this is done\n** by 'genlink'.\n*/\nstatic int traverseephemeron (global_State *g, Table *h, int inv) {\n  int marked = 0;  /* true if an object is marked in this traversal */\n  int hasclears = 0;  /* true if table has white keys */\n  int hasww = 0;  /* true if table has entry \"white-key -> white-value\" */\n  unsigned int i;\n  unsigned int asize = luaH_realasize(h);\n  unsigned int nsize = sizenode(h);\n  /* traverse array part */\n  for (i = 0; i < asize; i++) {\n    if (valiswhite(&h->array[i])) {\n      marked = 1;\n      reallymarkobject(g, gcvalue(&h->array[i]));\n    }\n  }\n  /* traverse hash part; if 'inv', traverse descending\n     (see 'convergeephemerons') */\n  for (i = 0; i < nsize; i++) {\n    Node *n = inv ? gnode(h, nsize - 1 - i) : gnode(h, i);\n    if (isempty(gval(n)))  /* entry is empty? */\n      clearkey(n);  /* clear its key */\n    else if (iscleared(g, gckeyN(n))) {  /* key is not marked (yet)? */\n      hasclears = 1;  /* table must be cleared */\n      if (valiswhite(gval(n)))  /* value not marked yet? */\n        hasww = 1;  /* white-white entry */\n    }\n    else if (valiswhite(gval(n))) {  /* value not marked yet? */\n      marked = 1;\n      reallymarkobject(g, gcvalue(gval(n)));  /* mark it now */\n    }\n  }\n  /* link table into proper list */\n  if (g->gcstate == GCSpropagate)\n    linkgclist(h, g->grayagain);  /* must retraverse it in atomic phase */\n  else if (hasww)  /* table has white->white entries? */\n    linkgclist(h, g->ephemeron);  /* have to propagate again */\n  else if (hasclears)  /* table has white keys? */\n    linkgclist(h, g->allweak);  /* may have to clean white keys */\n  else\n    genlink(g, obj2gco(h));  /* check whether collector still needs to see it */\n  return marked;\n}\n\n\nstatic void traversestrongtable (global_State *g, Table *h) {\n  Node *n, *limit = gnodelast(h);\n  unsigned int i;\n  unsigned int asize = luaH_realasize(h);\n  for (i = 0; i < asize; i++)  /* traverse array part */\n    markvalue(g, &h->array[i]);\n  for (n = gnode(h, 0); n < limit; n++) {  /* traverse hash part */\n    if (isempty(gval(n)))  /* entry is empty? */\n      clearkey(n);  /* clear its key */\n    else {\n      lua_assert(!keyisnil(n));\n      markkey(g, n);\n      markvalue(g, gval(n));\n    }\n  }\n  genlink(g, obj2gco(h));\n}\n\n\nstatic lu_mem traversetable (global_State *g, Table *h) {\n  const char *weakkey, *weakvalue;\n  const TValue *mode = gfasttm(g, h->metatable, TM_MODE);\n  markobjectN(g, h->metatable);\n  if (mode && ttisstring(mode) &&  /* is there a weak mode? */\n      (cast_void(weakkey = strchr(svalue(mode), 'k')),\n       cast_void(weakvalue = strchr(svalue(mode), 'v')),\n       (weakkey || weakvalue))) {  /* is really weak? */\n    if (!weakkey)  /* strong keys? */\n      traverseweakvalue(g, h);\n    else if (!weakvalue)  /* strong values? */\n      traverseephemeron(g, h, 0);\n    else  /* all weak */\n      linkgclist(h, g->allweak);  /* nothing to traverse now */\n  }\n  else  /* not weak */\n    traversestrongtable(g, h);\n  return 1 + h->alimit + 2 * allocsizenode(h);\n}\n\n\nstatic int traverseudata (global_State *g, Udata *u) {\n  int i;\n  markobjectN(g, u->metatable);  /* mark its metatable */\n  for (i = 0; i < u->nuvalue; i++)\n    markvalue(g, &u->uv[i].uv);\n  genlink(g, obj2gco(u));\n  return 1 + u->nuvalue;\n}\n\n\n/*\n** Traverse a prototype. (While a prototype is being build, its\n** arrays can be larger than needed; the extra slots are filled with\n** NULL, so the use of 'markobjectN')\n*/\nstatic int traverseproto (global_State *g, Proto *f) {\n  int i;\n  markobjectN(g, f->source);\n  for (i = 0; i < f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */\n    markobjectN(g, f->upvalues[i].name);\n  for (i = 0; i < f->sizep; i++)  /* mark nested protos */\n    markobjectN(g, f->p[i]);\n  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */\n    markobjectN(g, f->locvars[i].varname);\n  return 1 + f->sizek + f->sizeupvalues + f->sizep + f->sizelocvars;\n}\n\n\nstatic int traverseCclosure (global_State *g, CClosure *cl) {\n  int i;\n  for (i = 0; i < cl->nupvalues; i++)  /* mark its upvalues */\n    markvalue(g, &cl->upvalue[i]);\n  return 1 + cl->nupvalues;\n}\n\n/*\n** Traverse a Lua closure, marking its prototype and its upvalues.\n** (Both can be NULL while closure is being created.)\n*/\nstatic int traverseLclosure (global_State *g, LClosure *cl) {\n  int i;\n  markobjectN(g, cl->p);  /* mark its prototype */\n  for (i = 0; i < cl->nupvalues; i++) {  /* visit its upvalues */\n    UpVal *uv = cl->upvals[i];\n    markobjectN(g, uv);  /* mark upvalue */\n  }\n  return 1 + cl->nupvalues;\n}\n\n\n/*\n** Traverse a thread, marking the elements in the stack up to its top\n** and cleaning the rest of the stack in the final traversal. That\n** ensures that the entire stack have valid (non-dead) objects.\n** Threads have no barriers. In gen. mode, old threads must be visited\n** at every cycle, because they might point to young objects.  In inc.\n** mode, the thread can still be modified before the end of the cycle,\n** and therefore it must be visited again in the atomic phase. To ensure\n** these visits, threads must return to a gray list if they are not new\n** (which can only happen in generational mode) or if the traverse is in\n** the propagate phase (which can only happen in incremental mode).\n*/\nstatic int traversethread (global_State *g, lua_State *th) {\n  UpVal *uv;\n  StkId o = th->stack;\n  if (isold(th) || g->gcstate == GCSpropagate)\n    linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n  if (o == NULL)\n    return 1;  /* stack not completely built yet */\n  lua_assert(g->gcstate == GCSatomic ||\n             th->openupval == NULL || isintwups(th));\n  for (; o < th->top; o++)  /* mark live elements in the stack */\n    markvalue(g, s2v(o));\n  for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)\n    markobject(g, uv);  /* open upvalues cannot be collected */\n  if (g->gcstate == GCSatomic) {  /* final traversal? */\n    StkId lim = th->stack + th->stacksize;  /* real end of stack */\n    for (; o < lim; o++)  /* clear not-marked stack slice */\n      setnilvalue(s2v(o));\n    /* 'remarkupvals' may have removed thread from 'twups' list */\n    if (!isintwups(th) && th->openupval != NULL) {\n      th->twups = g->twups;  /* link it back to the list */\n      g->twups = th;\n    }\n  }\n  else if (!g->gcemergency)\n    luaD_shrinkstack(th); /* do not change stack in emergency cycle */\n  return 1 + th->stacksize;\n}\n\n\n/*\n** traverse one gray object, turning it to black.\n*/\nstatic lu_mem propagatemark (global_State *g) {\n  GCObject *o = g->gray;\n  nw2black(o);\n  g->gray = *getgclist(o);  /* remove from 'gray' list */\n  switch (o->tt) {\n    case LUA_VTABLE: return traversetable(g, gco2t(o));\n    case LUA_VUSERDATA: return traverseudata(g, gco2u(o));\n    case LUA_VLCL: return traverseLclosure(g, gco2lcl(o));\n    case LUA_VCCL: return traverseCclosure(g, gco2ccl(o));\n    case LUA_VPROTO: return traverseproto(g, gco2p(o));\n    case LUA_VTHREAD: return traversethread(g, gco2th(o));\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lu_mem propagateall (global_State *g) {\n  lu_mem tot = 0;\n  while (g->gray)\n    tot += propagatemark(g);\n  return tot;\n}\n\n\n/*\n** Traverse all ephemeron tables propagating marks from keys to values.\n** Repeat until it converges, that is, nothing new is marked. 'dir'\n** inverts the direction of the traversals, trying to speed up\n** convergence on chains in the same table.\n**\n*/\nstatic void convergeephemerons (global_State *g) {\n  int changed;\n  int dir = 0;\n  do {\n    GCObject *w;\n    GCObject *next = g->ephemeron;  /* get ephemeron list */\n    g->ephemeron = NULL;  /* tables may return to this list when traversed */\n    changed = 0;\n    while ((w = next) != NULL) {  /* for each ephemeron table */\n      Table *h = gco2t(w);\n      next = h->gclist;  /* list is rebuilt during loop */\n      nw2black(h);  /* out of the list (for now) */\n      if (traverseephemeron(g, h, dir)) {  /* marked some value? */\n        propagateall(g);  /* propagate changes */\n        changed = 1;  /* will have to revisit all ephemeron tables */\n      }\n    }\n    dir = !dir;  /* invert direction next time */\n  } while (changed);  /* repeat until no more changes */\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Sweep Functions\n** =======================================================\n*/\n\n\n/*\n** clear entries with unmarked keys from all weaktables in list 'l'\n*/\nstatic void clearbykeys (global_State *g, GCObject *l) {\n  for (; l; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *limit = gnodelast(h);\n    Node *n;\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (iscleared(g, gckeyN(n)))  /* unmarked key? */\n        setempty(gval(n));  /* remove entry */\n      if (isempty(gval(n)))  /* is entry empty? */\n        clearkey(n);  /* clear its key */\n    }\n  }\n}\n\n\n/*\n** clear entries with unmarked values from all weaktables in list 'l' up\n** to element 'f'\n*/\nstatic void clearbyvalues (global_State *g, GCObject *l, GCObject *f) {\n  for (; l != f; l = gco2t(l)->gclist) {\n    Table *h = gco2t(l);\n    Node *n, *limit = gnodelast(h);\n    unsigned int i;\n    unsigned int asize = luaH_realasize(h);\n    for (i = 0; i < asize; i++) {\n      TValue *o = &h->array[i];\n      if (iscleared(g, gcvalueN(o)))  /* value was collected? */\n        setempty(o);  /* remove entry */\n    }\n    for (n = gnode(h, 0); n < limit; n++) {\n      if (iscleared(g, gcvalueN(gval(n))))  /* unmarked value? */\n        setempty(gval(n));  /* remove entry */\n      if (isempty(gval(n)))  /* is entry empty? */\n        clearkey(n);  /* clear its key */\n    }\n  }\n}\n\n\nstatic void freeupval (lua_State *L, UpVal *uv) {\n  if (upisopen(uv))\n    luaF_unlinkupval(uv);\n  luaM_free(L, uv);\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->tt) {\n    case LUA_VPROTO:\n      luaF_freeproto(L, gco2p(o));\n      break;\n    case LUA_VUPVAL:\n      freeupval(L, gco2upv(o));\n      break;\n    case LUA_VLCL:\n      luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));\n      break;\n    case LUA_VCCL:\n      luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));\n      break;\n    case LUA_VTABLE:\n      luaH_free(L, gco2t(o));\n      break;\n    case LUA_VTHREAD:\n      luaE_freethread(L, gco2th(o));\n      break;\n    case LUA_VUSERDATA: {\n      Udata *u = gco2u(o);\n      luaM_freemem(L, o, sizeudata(u->nuvalue, u->len));\n      break;\n    }\n    case LUA_VSHRSTR:\n      luaS_remove(L, gco2ts(o));  /* remove it from hash table */\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));\n      break;\n    case LUA_VLNGSTR:\n      luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));\n      break;\n    default: lua_assert(0);\n  }\n}\n\n\n/*\n** sweep at most 'countin' elements from a list of GCObjects erasing dead\n** objects, where a dead object is one marked with the old (non current)\n** white; change all non-dead objects back to white, preparing for next\n** collection cycle. Return where to continue the traversal or NULL if\n** list is finished. ('*countout' gets the number of elements traversed.)\n*/\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, int countin,\n                             int *countout) {\n  global_State *g = G(L);\n  int ow = otherwhite(g);\n  int i;\n  int white = luaC_white(g);  /* current white */\n  for (i = 0; *p != NULL && i < countin; i++) {\n    GCObject *curr = *p;\n    int marked = curr->marked;\n    if (isdeadm(ow, marked)) {  /* is 'curr' dead? */\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* change mark to 'white' */\n      curr->marked = cast_byte((marked & ~maskgcbits) | white);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  if (countout)\n    *countout = i;  /* number of elements traversed */\n  return (*p == NULL) ? NULL : p;\n}\n\n\n/*\n** sweep a list until a live object (or end of list)\n*/\nstatic GCObject **sweeptolive (lua_State *L, GCObject **p) {\n  GCObject **old = p;\n  do {\n    p = sweeplist(L, p, 1, NULL);\n  } while (p == old);\n  return p;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Finalization\n** =======================================================\n*/\n\n/*\n** If possible, shrink string table.\n*/\nstatic void checkSizes (lua_State *L, global_State *g) {\n  if (!g->gcemergency) {\n    if (g->strt.nuse < g->strt.size / 4) {  /* string table too big? */\n      l_mem olddebt = g->GCdebt;\n      luaS_resize(L, g->strt.size / 2);\n      g->GCestimate += g->GCdebt - olddebt;  /* correct estimate */\n    }\n  }\n}\n\n\n/*\n** Get the next udata to be finalized from the 'tobefnz' list, and\n** link it back into the 'allgc' list.\n*/\nstatic GCObject *udata2finalize (global_State *g) {\n  GCObject *o = g->tobefnz;  /* get first element */\n  lua_assert(tofinalize(o));\n  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */\n  o->next = g->allgc;  /* return it to 'allgc' list */\n  g->allgc = o;\n  resetbit(o->marked, FINALIZEDBIT);  /* object is \"normal\" again */\n  if (issweepphase(g))\n    makewhite(g, o);  /* \"sweep\" object */\n  else if (getage(o) == G_OLD1)\n    g->firstold1 = o;  /* it is the first OLD1 object in the list */\n  return o;\n}\n\n\nstatic void dothecall (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaD_callnoyield(L, L->top - 2, 0);\n}\n\n\nstatic void GCTM (lua_State *L) {\n  global_State *g = G(L);\n  const TValue *tm;\n  TValue v;\n  lua_assert(!g->gcemergency);\n  setgcovalue(L, &v, udata2finalize(g));\n  tm = luaT_gettmbyobj(L, &v, TM_GC);\n  if (!notm(tm)) {  /* is there a finalizer? */\n    int status;\n    lu_byte oldah = L->allowhook;\n    int running  = g->gcrunning;\n    L->allowhook = 0;  /* stop debug hooks during GC metamethod */\n    g->gcrunning = 0;  /* avoid GC steps */\n    setobj2s(L, L->top++, tm);  /* push finalizer... */\n    setobj2s(L, L->top++, &v);  /* ... and its argument */\n    L->ci->callstatus |= CIST_FIN;  /* will run a finalizer */\n    status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);\n    L->ci->callstatus &= ~CIST_FIN;  /* not running a finalizer anymore */\n    L->allowhook = oldah;  /* restore hooks */\n    g->gcrunning = running;  /* restore state */\n    if (unlikely(status != LUA_OK)) {  /* error while running __gc? */\n      luaE_warnerror(L, \"__gc metamethod\");\n      L->top--;  /* pops error object */\n    }\n  }\n}\n\n\n/*\n** Call a few finalizers\n*/\nstatic int runafewfinalizers (lua_State *L, int n) {\n  global_State *g = G(L);\n  int i;\n  for (i = 0; i < n && g->tobefnz; i++)\n    GCTM(L);  /* call one finalizer */\n  return i;\n}\n\n\n/*\n** call all pending finalizers\n*/\nstatic void callallpendingfinalizers (lua_State *L) {\n  global_State *g = G(L);\n  while (g->tobefnz)\n    GCTM(L);\n}\n\n\n/*\n** find last 'next' field in list 'p' list (to add elements in its end)\n*/\nstatic GCObject **findlast (GCObject **p) {\n  while (*p != NULL)\n    p = &(*p)->next;\n  return p;\n}\n\n\n/*\n** Move all unreachable objects (or 'all' objects) that need\n** finalization from list 'finobj' to list 'tobefnz' (to be finalized).\n** (Note that objects after 'finobjold1' cannot be white, so they\n** don't need to be traversed. In incremental mode, 'finobjold1' is NULL,\n** so the whole list is traversed.)\n*/\nstatic void separatetobefnz (global_State *g, int all) {\n  GCObject *curr;\n  GCObject **p = &g->finobj;\n  GCObject **lastnext = findlast(&g->tobefnz);\n  while ((curr = *p) != g->finobjold1) {  /* traverse all finalizable objects */\n    lua_assert(tofinalize(curr));\n    if (!(iswhite(curr) || all))  /* not being collected? */\n      p = &curr->next;  /* don't bother with it */\n    else {\n      if (curr == g->finobjsur)  /* removing 'finobjsur'? */\n        g->finobjsur = curr->next;  /* correct it */\n      *p = curr->next;  /* remove 'curr' from 'finobj' list */\n      curr->next = *lastnext;  /* link at the end of 'tobefnz' list */\n      *lastnext = curr;\n      lastnext = &curr->next;\n    }\n  }\n}\n\n\n/*\n** If pointer 'p' points to 'o', move it to the next element.\n*/\nstatic void checkpointer (GCObject **p, GCObject *o) {\n  if (o == *p)\n    *p = o->next;\n}\n\n\n/*\n** Correct pointers to objects inside 'allgc' list when\n** object 'o' is being removed from the list.\n*/\nstatic void correctpointers (global_State *g, GCObject *o) {\n  checkpointer(&g->survival, o);\n  checkpointer(&g->old1, o);\n  checkpointer(&g->reallyold, o);\n  checkpointer(&g->firstold1, o);\n}\n\n\n/*\n** if object 'o' has a finalizer, remove it from 'allgc' list (must\n** search the list to find it) and link it in 'finobj' list.\n*/\nvoid luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {\n  global_State *g = G(L);\n  if (tofinalize(o) ||                 /* obj. is already marked... */\n      gfasttm(g, mt, TM_GC) == NULL)   /* or has no finalizer? */\n    return;  /* nothing to be done */\n  else {  /* move 'o' to 'finobj' list */\n    GCObject **p;\n    if (issweepphase(g)) {\n      makewhite(g, o);  /* \"sweep\" object 'o' */\n      if (g->sweepgc == &o->next)  /* should not remove 'sweepgc' object */\n        g->sweepgc = sweeptolive(L, g->sweepgc);  /* change 'sweepgc' */\n    }\n    else\n      correctpointers(g, o);\n    /* search for pointer pointing to 'o' */\n    for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }\n    *p = o->next;  /* remove 'o' from 'allgc' list */\n    o->next = g->finobj;  /* link it in 'finobj' list */\n    g->finobj = o;\n    l_setbit(o->marked, FINALIZEDBIT);  /* mark it as such */\n  }\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** Generational Collector\n** =======================================================\n*/\n\nstatic void setpause (global_State *g);\n\n\n/*\n** Sweep a list of objects to enter generational mode.  Deletes dead\n** objects and turns the non dead to old. All non-dead threads---which\n** are now old---must be in a gray list. Everything else is not in a\n** gray list. Open upvalues are also kept gray.\n*/\nstatic void sweep2old (lua_State *L, GCObject **p) {\n  GCObject *curr;\n  global_State *g = G(L);\n  while ((curr = *p) != NULL) {\n    if (iswhite(curr)) {  /* is 'curr' dead? */\n      lua_assert(isdead(g, curr));\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* all surviving objects become old */\n      setage(curr, G_OLD);\n      if (curr->tt == LUA_VTHREAD) {  /* threads must be watched */\n        lua_State *th = gco2th(curr);\n        linkgclist(th, g->grayagain);  /* insert into 'grayagain' list */\n      }\n      else if (curr->tt == LUA_VUPVAL && upisopen(gco2upv(curr)))\n        set2gray(curr);  /* open upvalues are always gray */\n      else  /* everything else is black */\n        nw2black(curr);\n      p = &curr->next;  /* go to next element */\n    }\n  }\n}\n\n\n/*\n** Sweep for generational mode. Delete dead objects. (Because the\n** collection is not incremental, there are no \"new white\" objects\n** during the sweep. So, any white object must be dead.) For\n** non-dead objects, advance their ages and clear the color of\n** new objects. (Old objects keep their colors.)\n** The ages of G_TOUCHED1 and G_TOUCHED2 objects cannot be advanced\n** here, because these old-generation objects are usually not swept\n** here.  They will all be advanced in 'correctgraylist'. That function\n** will also remove objects turned white here from any gray list.\n*/\nstatic GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p,\n                            GCObject *limit, GCObject **pfirstold1) {\n  static const lu_byte nextage[] = {\n    G_SURVIVAL,  /* from G_NEW */\n    G_OLD1,      /* from G_SURVIVAL */\n    G_OLD1,      /* from G_OLD0 */\n    G_OLD,       /* from G_OLD1 */\n    G_OLD,       /* from G_OLD (do not change) */\n    G_TOUCHED1,  /* from G_TOUCHED1 (do not change) */\n    G_TOUCHED2   /* from G_TOUCHED2 (do not change) */\n  };\n  int white = luaC_white(g);\n  GCObject *curr;\n  while ((curr = *p) != limit) {\n    if (iswhite(curr)) {  /* is 'curr' dead? */\n      lua_assert(!isold(curr) && isdead(g, curr));\n      *p = curr->next;  /* remove 'curr' from list */\n      freeobj(L, curr);  /* erase 'curr' */\n    }\n    else {  /* correct mark and age */\n      if (getage(curr) == G_NEW) {  /* new objects go back to white */\n        int marked = curr->marked & ~maskgcbits;  /* erase GC bits */\n        curr->marked = cast_byte(marked | G_SURVIVAL | white);\n      }\n      else {  /* all other objects will be old, and so keep their color */\n        setage(curr, nextage[getage(curr)]);\n        if (getage(curr) == G_OLD1 && *pfirstold1 == NULL)\n          *pfirstold1 = curr;  /* first OLD1 object in the list */\n      }\n      p = &curr->next;  /* go to next element */\n    }\n  }\n  return p;\n}\n\n\n/*\n** Traverse a list making all its elements white and clearing their\n** age. In incremental mode, all objects are 'new' all the time,\n** except for fixed strings (which are always old).\n*/\nstatic void whitelist (global_State *g, GCObject *p) {\n  int white = luaC_white(g);\n  for (; p != NULL; p = p->next)\n    p->marked = cast_byte((p->marked & ~maskgcbits) | white);\n}\n\n\n/*\n** Correct a list of gray objects. Return pointer to where rest of the\n** list should be linked.\n** Because this correction is done after sweeping, young objects might\n** be turned white and still be in the list. They are only removed.\n** 'TOUCHED1' objects are advanced to 'TOUCHED2' and remain on the list;\n** Non-white threads also remain on the list; 'TOUCHED2' objects become\n** regular old; they and anything else are removed from the list.\n*/\nstatic GCObject **correctgraylist (GCObject **p) {\n  GCObject *curr;\n  while ((curr = *p) != NULL) {\n    GCObject **next = getgclist(curr);\n    if (iswhite(curr))\n      goto remove;  /* remove all white objects */\n    else if (getage(curr) == G_TOUCHED1) {  /* touched in this cycle? */\n      lua_assert(isgray(curr));\n      nw2black(curr);  /* make it black, for next barrier */\n      changeage(curr, G_TOUCHED1, G_TOUCHED2);\n      goto remain;  /* keep it in the list and go to next element */\n    }\n    else if (curr->tt == LUA_VTHREAD) {\n      lua_assert(isgray(curr));\n      goto remain;  /* keep non-white threads on the list */\n    }\n    else {  /* everything else is removed */\n      lua_assert(isold(curr));  /* young objects should be white here */\n      if (getage(curr) == G_TOUCHED2)  /* advance from TOUCHED2... */\n        changeage(curr, G_TOUCHED2, G_OLD);  /* ... to OLD */\n      nw2black(curr);  /* make object black (to be removed) */\n      goto remove;\n    }\n    remove: *p = *next; continue;\n    remain: p = next; continue;\n  }\n  return p;\n}\n\n\n/*\n** Correct all gray lists, coalescing them into 'grayagain'.\n*/\nstatic void correctgraylists (global_State *g) {\n  GCObject **list = correctgraylist(&g->grayagain);\n  *list = g->weak; g->weak = NULL;\n  list = correctgraylist(list);\n  *list = g->allweak; g->allweak = NULL;\n  list = correctgraylist(list);\n  *list = g->ephemeron; g->ephemeron = NULL;\n  correctgraylist(list);\n}\n\n\n/*\n** Mark black 'OLD1' objects when starting a new young collection.\n** Gray objects are already in some gray list, and so will be visited\n** in the atomic step.\n*/\nstatic void markold (global_State *g, GCObject *from, GCObject *to) {\n  GCObject *p;\n  for (p = from; p != to; p = p->next) {\n    if (getage(p) == G_OLD1) {\n      lua_assert(!iswhite(p));\n      changeage(p, G_OLD1, G_OLD);  /* now they are old */\n      if (isblack(p))\n        reallymarkobject(g, p);\n    }\n  }\n}\n\n\n/*\n** Finish a young-generation collection.\n*/\nstatic void finishgencycle (lua_State *L, global_State *g) {\n  correctgraylists(g);\n  checkSizes(L, g);\n  g->gcstate = GCSpropagate;  /* skip restart */\n  if (!g->gcemergency)\n    callallpendingfinalizers(L);\n}\n\n\n/*\n** Does a young collection. First, mark 'OLD1' objects. Then does the\n** atomic step. Then, sweep all lists and advance pointers. Finally,\n** finish the collection.\n*/\nstatic void youngcollection (lua_State *L, global_State *g) {\n  GCObject **psurvival;  /* to point to first non-dead survival object */\n  GCObject *dummy;  /* dummy out parameter to 'sweepgen' */\n  lua_assert(g->gcstate == GCSpropagate);\n  if (g->firstold1) {  /* are there regular OLD1 objects? */\n    markold(g, g->firstold1, g->reallyold);  /* mark them */\n    g->firstold1 = NULL;  /* no more OLD1 objects (for now) */\n  }\n  markold(g, g->finobj, g->finobjrold);\n  markold(g, g->tobefnz, NULL);\n  atomic(L);\n\n  /* sweep nursery and get a pointer to its last live element */\n  g->gcstate = GCSswpallgc;\n  psurvival = sweepgen(L, g, &g->allgc, g->survival, &g->firstold1);\n  /* sweep 'survival' */\n  sweepgen(L, g, psurvival, g->old1, &g->firstold1);\n  g->reallyold = g->old1;\n  g->old1 = *psurvival;  /* 'survival' survivals are old now */\n  g->survival = g->allgc;  /* all news are survivals */\n\n  /* repeat for 'finobj' lists */\n  dummy = NULL;  /* no 'firstold1' optimization for 'finobj' lists */\n  psurvival = sweepgen(L, g, &g->finobj, g->finobjsur, &dummy);\n  /* sweep 'survival' */\n  sweepgen(L, g, psurvival, g->finobjold1, &dummy);\n  g->finobjrold = g->finobjold1;\n  g->finobjold1 = *psurvival;  /* 'survival' survivals are old now */\n  g->finobjsur = g->finobj;  /* all news are survivals */\n\n  sweepgen(L, g, &g->tobefnz, NULL, &dummy);\n  finishgencycle(L, g);\n}\n\n\n/*\n** Clears all gray lists, sweeps objects, and prepare sublists to enter\n** generational mode. The sweeps remove dead objects and turn all\n** surviving objects to old. Threads go back to 'grayagain'; everything\n** else is turned black (not in any gray list).\n*/\nstatic void atomic2gen (lua_State *L, global_State *g) {\n  cleargraylists(g);\n  /* sweep all elements making them old */\n  g->gcstate = GCSswpallgc;\n  sweep2old(L, &g->allgc);\n  /* everything alive now is old */\n  g->reallyold = g->old1 = g->survival = g->allgc;\n  g->firstold1 = NULL;  /* there are no OLD1 objects anywhere */\n\n  /* repeat for 'finobj' lists */\n  sweep2old(L, &g->finobj);\n  g->finobjrold = g->finobjold1 = g->finobjsur = g->finobj;\n\n  sweep2old(L, &g->tobefnz);\n\n  g->gckind = KGC_GEN;\n  g->lastatomic = 0;\n  g->GCestimate = gettotalbytes(g);  /* base for memory control */\n  finishgencycle(L, g);\n}\n\n\n/*\n** Enter generational mode. Must go until the end of an atomic cycle\n** to ensure that all objects are correctly marked and weak tables\n** are cleared. Then, turn all objects into old and finishes the\n** collection.\n*/\nstatic lu_mem entergen (lua_State *L, global_State *g) {\n  lu_mem numobjs;\n  luaC_runtilstate(L, bitmask(GCSpause));  /* prepare to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */\n  numobjs = atomic(L);  /* propagates all and then do the atomic stuff */\n  atomic2gen(L, g);\n  return numobjs;\n}\n\n\n/*\n** Enter incremental mode. Turn all objects white, make all\n** intermediate lists point to NULL (to avoid invalid pointers),\n** and go to the pause state.\n*/\nstatic void enterinc (global_State *g) {\n  whitelist(g, g->allgc);\n  g->reallyold = g->old1 = g->survival = NULL;\n  whitelist(g, g->finobj);\n  whitelist(g, g->tobefnz);\n  g->finobjrold = g->finobjold1 = g->finobjsur = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_INC;\n  g->lastatomic = 0;\n}\n\n\n/*\n** Change collector mode to 'newmode'.\n*/\nvoid luaC_changemode (lua_State *L, int newmode) {\n  global_State *g = G(L);\n  if (newmode != g->gckind) {\n    if (newmode == KGC_GEN)  /* entering generational mode? */\n      entergen(L, g);\n    else\n      enterinc(g);  /* entering incremental mode */\n  }\n  g->lastatomic = 0;\n}\n\n\n/*\n** Does a full collection in generational mode.\n*/\nstatic lu_mem fullgen (lua_State *L, global_State *g) {\n  enterinc(g);\n  return entergen(L, g);\n}\n\n\n/*\n** Set debt for the next minor collection, which will happen when\n** memory grows 'genminormul'%.\n*/\nstatic void setminordebt (global_State *g) {\n  luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));\n}\n\n\n/*\n** Does a major collection after last collection was a \"bad collection\".\n**\n** When the program is building a big structure, it allocates lots of\n** memory but generates very little garbage. In those scenarios,\n** the generational mode just wastes time doing small collections, and\n** major collections are frequently what we call a \"bad collection\", a\n** collection that frees too few objects. To avoid the cost of switching\n** between generational mode and the incremental mode needed for full\n** (major) collections, the collector tries to stay in incremental mode\n** after a bad collection, and to switch back to generational mode only\n** after a \"good\" collection (one that traverses less than 9/8 objects\n** of the previous one).\n** The collector must choose whether to stay in incremental mode or to\n** switch back to generational mode before sweeping. At this point, it\n** does not know the real memory in use, so it cannot use memory to\n** decide whether to return to generational mode. Instead, it uses the\n** number of objects traversed (returned by 'atomic') as a proxy. The\n** field 'g->lastatomic' keeps this count from the last collection.\n** ('g->lastatomic != 0' also means that the last collection was bad.)\n*/\nstatic void stepgenfull (lua_State *L, global_State *g) {\n  lu_mem newatomic;  /* count of traversed objects */\n  lu_mem lastatomic = g->lastatomic;  /* count from last collection */\n  if (g->gckind == KGC_GEN)  /* still in generational mode? */\n    enterinc(g);  /* enter incremental mode */\n  luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */\n  newatomic = atomic(L);  /* mark everybody */\n  if (newatomic < lastatomic + (lastatomic >> 3)) {  /* good collection? */\n    atomic2gen(L, g);  /* return to generational mode */\n    setminordebt(g);\n  }\n  else {  /* another bad collection; stay in incremental mode */\n    g->GCestimate = gettotalbytes(g);  /* first estimate */;\n    entersweep(L);\n    luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n    setpause(g);\n    g->lastatomic = newatomic;\n  }\n}\n\n\n/*\n** Does a generational \"step\".\n** Usually, this means doing a minor collection and setting the debt to\n** make another collection when memory grows 'genminormul'% larger.\n**\n** However, there are exceptions.  If memory grows 'genmajormul'%\n** larger than it was at the end of the last major collection (kept\n** in 'g->GCestimate'), the function does a major collection. At the\n** end, it checks whether the major collection was able to free a\n** decent amount of memory (at least half the growth in memory since\n** previous major collection). If so, the collector keeps its state,\n** and the next collection will probably be minor again. Otherwise,\n** we have what we call a \"bad collection\". In that case, set the field\n** 'g->lastatomic' to signal that fact, so that the next collection will\n** go to 'stepgenfull'.\n**\n** 'GCdebt <= 0' means an explicit call to GC step with \"size\" zero;\n** in that case, do a minor collection.\n*/\nstatic void genstep (lua_State *L, global_State *g) {\n  if (g->lastatomic != 0)  /* last collection was a bad one? */\n    stepgenfull(L, g);  /* do a full step */\n  else {\n    lu_mem majorbase = g->GCestimate;  /* memory after last major collection */\n    lu_mem majorinc = (majorbase / 100) * getgcparam(g->genmajormul);\n    if (g->GCdebt > 0 && gettotalbytes(g) > majorbase + majorinc) {\n      lu_mem numobjs = fullgen(L, g);  /* do a major collection */\n      if (gettotalbytes(g) < majorbase + (majorinc / 2)) {\n        /* collected at least half of memory growth since last major\n           collection; keep doing minor collections */\n        setminordebt(g);\n      }\n      else {  /* bad collection */\n        g->lastatomic = numobjs;  /* signal that last collection was bad */\n        setpause(g);  /* do a long wait for next (major) collection */\n      }\n    }\n    else {  /* regular case; do a minor collection */\n      youngcollection(L, g);\n      setminordebt(g);\n      g->GCestimate = majorbase;  /* preserve base value */\n    }\n  }\n  lua_assert(isdecGCmodegen(g));\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** GC control\n** =======================================================\n*/\n\n\n/*\n** Set the \"time\" to wait before starting a new GC cycle; cycle will\n** start when memory use hits the threshold of ('estimate' * pause /\n** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,\n** because Lua cannot even start with less than PAUSEADJ bytes).\n*/\nstatic void setpause (global_State *g) {\n  l_mem threshold, debt;\n  int pause = getgcparam(g->gcpause);\n  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */\n  lua_assert(estimate > 0);\n  threshold = (pause < MAX_LMEM / estimate)  /* overflow? */\n            ? estimate * pause  /* no overflow */\n            : MAX_LMEM;  /* overflow; truncate to maximum */\n  debt = gettotalbytes(g) - threshold;\n  if (debt > 0) debt = 0;\n  luaE_setdebt(g, debt);\n}\n\n\n/*\n** Enter first sweep phase.\n** The call to 'sweeptolive' makes the pointer point to an object\n** inside the list (instead of to the header), so that the real sweep do\n** not need to skip objects created between \"now\" and the start of the\n** real sweep.\n*/\nstatic void entersweep (lua_State *L) {\n  global_State *g = G(L);\n  g->gcstate = GCSswpallgc;\n  lua_assert(g->sweepgc == NULL);\n  g->sweepgc = sweeptolive(L, &g->allgc);\n}\n\n\n/*\n** Delete all objects in list 'p' until (but not including) object\n** 'limit'.\n*/\nstatic void deletelist (lua_State *L, GCObject *p, GCObject *limit) {\n  while (p != limit) {\n    GCObject *next = p->next;\n    freeobj(L, p);\n    p = next;\n  }\n}\n\n\n/*\n** Call all finalizers of the objects in the given Lua state, and\n** then free all objects, except for the main thread.\n*/\nvoid luaC_freeallobjects (lua_State *L) {\n  global_State *g = G(L);\n  luaC_changemode(L, KGC_INC);\n  separatetobefnz(g, 1);  /* separate all objects with finalizers */\n  lua_assert(g->finobj == NULL);\n  callallpendingfinalizers(L);\n  deletelist(L, g->allgc, obj2gco(g->mainthread));\n  deletelist(L, g->finobj, NULL);\n  deletelist(L, g->fixedgc, NULL);  /* collect fixed objects */\n  lua_assert(g->strt.nuse == 0);\n}\n\n\nstatic lu_mem atomic (lua_State *L) {\n  global_State *g = G(L);\n  lu_mem work = 0;\n  GCObject *origweak, *origall;\n  GCObject *grayagain = g->grayagain;  /* save original list */\n  g->grayagain = NULL;\n  lua_assert(g->ephemeron == NULL && g->weak == NULL);\n  lua_assert(!iswhite(g->mainthread));\n  g->gcstate = GCSatomic;\n  markobject(g, L);  /* mark running thread */\n  /* registry and global metatables may be changed by API */\n  markvalue(g, &g->l_registry);\n  markmt(g);  /* mark global metatables */\n  work += propagateall(g);  /* empties 'gray' list */\n  /* remark occasional upvalues of (maybe) dead threads */\n  work += remarkupvals(g);\n  work += propagateall(g);  /* propagate changes */\n  g->gray = grayagain;\n  work += propagateall(g);  /* traverse 'grayagain' list */\n  convergeephemerons(g);\n  /* at this point, all strongly accessible objects are marked. */\n  /* Clear values from weak tables, before checking finalizers */\n  clearbyvalues(g, g->weak, NULL);\n  clearbyvalues(g, g->allweak, NULL);\n  origweak = g->weak; origall = g->allweak;\n  separatetobefnz(g, 0);  /* separate objects to be finalized */\n  work += markbeingfnz(g);  /* mark objects that will be finalized */\n  work += propagateall(g);  /* remark, to propagate 'resurrection' */\n  convergeephemerons(g);\n  /* at this point, all resurrected objects are marked. */\n  /* remove dead objects from weak tables */\n  clearbykeys(g, g->ephemeron);  /* clear keys from all ephemeron tables */\n  clearbykeys(g, g->allweak);  /* clear keys from all 'allweak' tables */\n  /* clear values from resurrected weak tables */\n  clearbyvalues(g, g->weak, origweak);\n  clearbyvalues(g, g->allweak, origall);\n  luaS_clearcache(g);\n  g->currentwhite = cast_byte(otherwhite(g));  /* flip current white */\n  lua_assert(g->gray == NULL);\n  return work;  /* estimate of slots marked by 'atomic' */\n}\n\n\nstatic int sweepstep (lua_State *L, global_State *g,\n                      int nextstate, GCObject **nextlist) {\n  if (g->sweepgc) {\n    l_mem olddebt = g->GCdebt;\n    int count;\n    g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX, &count);\n    g->GCestimate += g->GCdebt - olddebt;  /* update estimate */\n    return count;\n  }\n  else {  /* enter next state */\n    g->gcstate = nextstate;\n    g->sweepgc = nextlist;\n    return 0;  /* no work done */\n  }\n}\n\n\nstatic lu_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  switch (g->gcstate) {\n    case GCSpause: {\n      restartcollection(g);\n      g->gcstate = GCSpropagate;\n      return 1;\n    }\n    case GCSpropagate: {\n      if (g->gray == NULL) {  /* no more gray objects? */\n        g->gcstate = GCSenteratomic;  /* finish propagate phase */\n        return 0;\n      }\n      else\n        return propagatemark(g);  /* traverse one gray object */\n    }\n    case GCSenteratomic: {\n      lu_mem work = atomic(L);  /* work is what was traversed by 'atomic' */\n      entersweep(L);\n      g->GCestimate = gettotalbytes(g);  /* first estimate */;\n      return work;\n    }\n    case GCSswpallgc: {  /* sweep \"regular\" objects */\n      return sweepstep(L, g, GCSswpfinobj, &g->finobj);\n    }\n    case GCSswpfinobj: {  /* sweep objects with finalizers */\n      return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);\n    }\n    case GCSswptobefnz: {  /* sweep objects to be finalized */\n      return sweepstep(L, g, GCSswpend, NULL);\n    }\n    case GCSswpend: {  /* finish sweeps */\n      checkSizes(L, g);\n      g->gcstate = GCScallfin;\n      return 0;\n    }\n    case GCScallfin: {  /* call remaining finalizers */\n      if (g->tobefnz && !g->gcemergency) {\n        int n = runafewfinalizers(L, GCFINMAX);\n        return n * GCFINALIZECOST;\n      }\n      else {  /* emergency mode or no more finalizers */\n        g->gcstate = GCSpause;  /* finish collection */\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\n/*\n** advances the garbage collector until it reaches a state allowed\n** by 'statemask'\n*/\nvoid luaC_runtilstate (lua_State *L, int statesmask) {\n  global_State *g = G(L);\n  while (!testbit(statesmask, g->gcstate))\n    singlestep(L);\n}\n\n\n/*\n** Performs a basic incremental step. The debt and step size are\n** converted from bytes to \"units of work\"; then the function loops\n** running single steps until adding that many units of work or\n** finishing a cycle (pause state). Finally, it sets the debt that\n** controls when next step will be performed.\n*/\nstatic void incstep (lua_State *L, global_State *g) {\n  int stepmul = (getgcparam(g->gcstepmul) | 1);  /* avoid division by 0 */\n  l_mem debt = (g->GCdebt / WORK2MEM) * stepmul;\n  l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem))\n                 ? ((cast(l_mem, 1) << g->gcstepsize) / WORK2MEM) * stepmul\n                 : MAX_LMEM;  /* overflow; keep maximum value */\n  do {  /* repeat until pause or enough \"credit\" (negative debt) */\n    lu_mem work = singlestep(L);  /* perform one single step */\n    debt -= work;\n  } while (debt > -stepsize && g->gcstate != GCSpause);\n  if (g->gcstate == GCSpause)\n    setpause(g);  /* pause until next cycle */\n  else {\n    debt = (debt / stepmul) * WORK2MEM;  /* convert 'work units' to bytes */\n    luaE_setdebt(g, debt);\n  }\n}\n\n/*\n** performs a basic GC step if collector is running\n*/\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  lua_assert(!g->gcemergency);\n  if (g->gcrunning) {  /* running? */\n    if(isdecGCmodegen(g))\n      genstep(L, g);\n    else\n      incstep(L, g);\n  }\n}\n\n\n/*\n** Perform a full collection in incremental mode.\n** Before running the collection, check 'keepinvariant'; if it is true,\n** there may be some objects marked as black, so the collector has\n** to sweep all objects to turn them back to white (as white has not\n** changed, nothing will be collected).\n*/\nstatic void fullinc (lua_State *L, global_State *g) {\n  if (keepinvariant(g))  /* black objects? */\n    entersweep(L); /* sweep everything to turn them back to white */\n  /* finish any pending sweep phase to start a new cycle */\n  luaC_runtilstate(L, bitmask(GCSpause));\n  luaC_runtilstate(L, bitmask(GCScallfin));  /* run up to finalizers */\n  /* estimate must be correct after a full GC cycle */\n  lua_assert(g->GCestimate == gettotalbytes(g));\n  luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */\n  setpause(g);\n}\n\n\n/*\n** Performs a full GC cycle; if 'isemergency', set a flag to avoid\n** some operations which could change the interpreter state in some\n** unexpected ways (running finalizers and shrinking some structures).\n*/\nvoid luaC_fullgc (lua_State *L, int isemergency) {\n  global_State *g = G(L);\n  lua_assert(!g->gcemergency);\n  g->gcemergency = isemergency;  /* set flag */\n  if (g->gckind == KGC_INC)\n    fullinc(L, g);\n  else\n    fullgen(L, g);\n  g->gcemergency = 0;\n}\n\n/* }====================================================== */\n\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lgc.h",
    "content": "/*\n** $Id: lgc.h $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n/*\n** Collectable objects may have one of three colors: white, which means\n** the object is not marked; gray, which means the object is marked, but\n** its references may be not marked; and black, which means that the\n** object and all its references are marked.  The main invariant of the\n** garbage collector, while marking objects, is that a black object can\n** never point to a white one. Moreover, any gray object must be in a\n** \"gray list\" (gray, grayagain, weak, allweak, ephemeron) so that it\n** can be visited again before finishing the collection cycle. (Open\n** upvalues are an exception to this rule.)  These lists have no meaning\n** when the invariant is not being enforced (e.g., sweep phase).\n*/\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpropagate\t0\n#define GCSenteratomic\t1\n#define GCSatomic\t2\n#define GCSswpallgc\t3\n#define GCSswpfinobj\t4\n#define GCSswptobefnz\t5\n#define GCSswpend\t6\n#define GCScallfin\t7\n#define GCSpause\t8\n\n\n#define issweepphase(g)  \\\n\t(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)\n\n\n/*\n** macro to tell when main invariant (white objects cannot point to black\n** ones) must be kept. During a collection, the sweep\n** phase may break the invariant, as objects turned white may point to\n** still-black objects. The invariant is restored when sweep ends and\n** all objects are white again.\n*/\n\n#define keepinvariant(g)\t((g)->gcstate <= GCSatomic)\n\n\n/*\n** some useful bit tricks\n*/\n#define resetbits(x,m)\t\t((x) &= cast_byte(~(m)))\n#define setbits(x,m)\t\t((x) |= (m))\n#define testbits(x,m)\t\t((x) & (m))\n#define bitmask(b)\t\t(1<<(b))\n#define bit2mask(b1,b2)\t\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\t\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\t\tresetbits(x, bitmask(b))\n#define testbit(x,b)\t\ttestbits(x, bitmask(b))\n\n\n/*\n** Layout for bit use in 'marked' field. First three bits are\n** used for object \"age\" in generational mode. Last bit is used\n** by tests.\n*/\n#define WHITE0BIT\t3  /* object is white (type 0) */\n#define WHITE1BIT\t4  /* object is white (type 1) */\n#define BLACKBIT\t5  /* object is black */\n#define FINALIZEDBIT\t6  /* object has been marked for finalization */\n\n#define TESTBIT\t\t7\n\n\n\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      testbits((x)->marked, WHITEBITS)\n#define isblack(x)      testbit((x)->marked, BLACKBIT)\n#define isgray(x)  /* neither white nor black */  \\\n\t(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))\n\n#define tofinalize(x)\ttestbit((x)->marked, FINALIZEDBIT)\n\n#define otherwhite(g)\t((g)->currentwhite ^ WHITEBITS)\n#define isdeadm(ow,m)\t((m) & (ow))\n#define isdead(g,v)\tisdeadm(otherwhite(g), (v)->marked)\n\n#define changewhite(x)\t((x)->marked ^= WHITEBITS)\n#define nw2black(x)  \\\n\tcheck_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT))\n\n#define luaC_white(g)\tcast_byte((g)->currentwhite & WHITEBITS)\n\n\n/* object age in generational mode */\n#define G_NEW\t\t0\t/* created in current cycle */\n#define G_SURVIVAL\t1\t/* created in previous cycle */\n#define G_OLD0\t\t2\t/* marked old by frw. barrier in this cycle */\n#define G_OLD1\t\t3\t/* first full cycle as old */\n#define G_OLD\t\t4\t/* really old object (not to be visited) */\n#define G_TOUCHED1\t5\t/* old object touched this cycle */\n#define G_TOUCHED2\t6\t/* old object touched in previous cycle */\n\n#define AGEBITS\t\t7  /* all age bits (111) */\n\n#define getage(o)\t((o)->marked & AGEBITS)\n#define setage(o,a)  ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a))\n#define isold(o)\t(getage(o) > G_SURVIVAL)\n\n#define changeage(o,f,t)  \\\n\tcheck_exp(getage(o) == (f), (o)->marked ^= ((f)^(t)))\n\n\n/* Default Values for GC parameters */\n#define LUAI_GENMAJORMUL         100\n#define LUAI_GENMINORMUL         20\n\n/* wait memory to double before starting new cycle */\n#define LUAI_GCPAUSE    200\n\n/*\n** some gc parameters are stored divided by 4 to allow a maximum value\n** up to 1023 in a 'lu_byte'.\n*/\n#define getgcparam(p)\t((p) * 4)\n#define setgcparam(p,v)\t((p) = (v) / 4)\n\n#define LUAI_GCMUL      100\n\n/* how much to allocate before next GC step (log2) */\n#define LUAI_GCSTEPSIZE 13      /* 8 KB */\n\n\n/*\n** Check whether the declared GC mode is generational. While in\n** generational mode, the collector can go temporarily to incremental\n** mode to improve performance. This is signaled by 'g->lastatomic != 0'.\n*/\n#define isdecGCmodegen(g)\t(g->gckind == KGC_GEN || g->lastatomic != 0)\n\n/*\n** Does one step of collection when debt becomes positive. 'pre'/'pos'\n** allows some adjustments to be done only when needed. macro\n** 'condchangemem' is used only for heavy tests (forcing a full\n** GC cycle on every opportunity)\n*/\n#define luaC_condGC(L,pre,pos) \\\n\t{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \\\n\t  condchangemem(L,pre,pos); }\n\n/* more often than not, 'pre'/'pos' are empty */\n#define luaC_checkGC(L)\t\tluaC_condGC(L,(void)0,(void)0)\n\n\n#define luaC_barrier(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \\\n\tluaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))\n\n#define luaC_barrierback(L,p,v) (  \\\n\t(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \\\n\tluaC_barrierback_(L,p) : cast_void(0))\n\n#define luaC_objbarrier(L,p,o) (  \\\n\t(isblack(p) && iswhite(o)) ? \\\n\tluaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))\n\nLUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_freeallobjects (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);\nLUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);\nLUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);\nLUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);\nLUAI_FUNC void luaC_changemode (lua_State *L, int newmode);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/linit.c",
    "content": "/*\n** $Id: linit.c $\n** Initialization of libraries for lua.c and other clients\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n/*\n** If you embed Lua in your program and need to open the standard\n** libraries, call luaL_openlibs in your program. If you need a\n** different set of libraries, copy this file to your project and edit\n** it to suit your needs.\n**\n** You can also *preload* libraries, so that a later 'require' can\n** open the library, which is already linked to the application.\n** For that, do the following code:\n**\n**  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n**  lua_pushcfunction(L, luaopen_modname);\n**  lua_setfield(L, -2, modname);\n**  lua_pop(L, 1);  // remove PRELOAD table\n*/\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\n/*\n** these libs are loaded by lua.c and are readily available to any Lua\n** program\n*/\nstatic const luaL_Reg loadedlibs[] = {\n  {LUA_GNAME, luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_COLIBNAME, luaopen_coroutine},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_UTF8LIBNAME, luaopen_utf8},\n  {LUA_DBLIBNAME, luaopen_debug},\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib;\n  /* \"require\" functions from 'loadedlibs' and set results to global table */\n  for (lib = loadedlibs; lib->func; lib++) {\n    luaL_requiref(L, lib->name, lib->func, 1);\n    lua_pop(L, 1);  /* remove lib */\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/liolib.c",
    "content": "/*\n** $Id: liolib.c $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <locale.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n\n/*\n** Change this macro to accept other modes for 'fopen' besides\n** the standard ones.\n*/\n#if !defined(l_checkmode)\n\n/* accepted extensions to 'mode' in 'fopen' */\n#if !defined(L_MODEEXT)\n#define L_MODEEXT\t\"b\"\n#endif\n\n/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */\nstatic int l_checkmode (const char *mode) {\n  return (*mode != '\\0' && strchr(\"rwa\", *(mode++)) != NULL &&\n         (*mode != '+' || ((void)(++mode), 1)) &&  /* skip if char is '+' */\n         (strspn(mode, L_MODEEXT) == strlen(mode)));  /* check extensions */\n}\n\n#endif\n\n/*\n** {======================================================\n** l_popen spawns a new process connected to the current\n** one through the file streams.\n** =======================================================\n*/\n\n#if !defined(l_checkmodep)\n/* By default, Lua accepts only \"r\" or \"w\" as mode */\n#define l_checkmodep(m)\t((m[0] == 'r' || m[0] == 'w') && m[1] == '\\0')\n#endif\n\n\n#if !defined(l_popen)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_popen(L,c,m)\t\t(fflush(NULL), popen(c,m))\n#define l_pclose(L,file)\t(pclose(file))\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#define l_popen(L,c,m)\t\t(_popen(c,m))\n#define l_pclose(L,file)\t(_pclose(file))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_popen(L,c,m)  \\\n\t  ((void)c, (void)m, \\\n\t  luaL_error(L, \"'popen' not supported\"), \\\n\t  (FILE*)0)\n#define l_pclose(L,file)\t\t((void)L, (void)file, -1)\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n#if !defined(l_getc)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\n#define l_getc(f)\t\tgetc_unlocked(f)\n#define l_lockfile(f)\t\tflockfile(f)\n#define l_unlockfile(f)\t\tfunlockfile(f)\n#else\n#define l_getc(f)\t\tgetc(f)\n#define l_lockfile(f)\t\t((void)0)\n#define l_unlockfile(f)\t\t((void)0)\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** {======================================================\n** l_fseek: configuration for longer offsets\n** =======================================================\n*/\n\n#if !defined(l_fseek)\t\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <sys/types.h>\n\n#define l_fseek(f,o,w)\t\tfseeko(f,o,w)\n#define l_ftell(f)\t\tftello(f)\n#define l_seeknum\t\toff_t\n\n#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \\\n   && defined(_MSC_VER) && (_MSC_VER >= 1400)\t/* }{ */\n\n/* Windows (but not DDK) and Visual C++ 2005 or higher */\n#define l_fseek(f,o,w)\t\t_fseeki64(f,o,w)\n#define l_ftell(f)\t\t_ftelli64(f)\n#define l_seeknum\t\t__int64\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_fseek(f,o,w)\t\tfseek(f,o,w)\n#define l_ftell(f)\t\tftell(f)\n#define l_seeknum\t\tlong\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }====================================================== */\n\n\n\n#define IO_PREFIX\t\"_IO_\"\n#define IOPREF_LEN\t(sizeof(IO_PREFIX)/sizeof(char) - 1)\n#define IO_INPUT\t(IO_PREFIX \"input\")\n#define IO_OUTPUT\t(IO_PREFIX \"output\")\n\n\ntypedef luaL_Stream LStream;\n\n\n#define tolstream(L)\t((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n#define isclosed(p)\t((p)->closef == NULL)\n\n\nstatic int io_type (lua_State *L) {\n  LStream *p;\n  luaL_checkany(L, 1);\n  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);\n  if (p == NULL)\n    luaL_pushfail(L);  /* not a file */\n  else if (isclosed(p))\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic int f_tostring (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", p->f);\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (isclosed(p))\n    luaL_error(L, \"attempt to use a closed file\");\n  lua_assert(p->f);\n  return p->f;\n}\n\n\n/*\n** When creating file handles, always creates a 'closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** handle is in a consistent state.\n*/\nstatic LStream *newprefile (lua_State *L) {\n  LStream *p = (LStream *)lua_newuserdatauv(L, sizeof(LStream), 0);\n  p->closef = NULL;  /* mark file handle as 'closed' */\n  luaL_setmetatable(L, LUA_FILEHANDLE);\n  return p;\n}\n\n\n/*\n** Calls the 'close' function from a file handle. The 'volatile' avoids\n** a bug in some versions of the Clang compiler (e.g., clang 3.0 for\n** 32 bits).\n*/\nstatic int aux_close (lua_State *L) {\n  LStream *p = tolstream(L);\n  volatile lua_CFunction cf = p->closef;\n  p->closef = NULL;  /* mark stream as closed */\n  return (*cf)(L);  /* close it */\n}\n\n\nstatic int f_close (lua_State *L) {\n  tofile(L);  /* make sure argument is an open stream */\n  return aux_close(L);\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))  /* no argument? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use default output */\n  return f_close(L);\n}\n\n\nstatic int f_gc (lua_State *L) {\n  LStream *p = tolstream(L);\n  if (!isclosed(p) && p->f != NULL)\n    aux_close(L);  /* ignore closed and incompletely open files */\n  return 0;\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  int res = fclose(p->f);\n  return luaL_fileresult(L, (res == 0), NULL);\n}\n\n\nstatic LStream *newfile (lua_State *L) {\n  LStream *p = newprefile(L);\n  p->f = NULL;\n  p->closef = &io_fclose;\n  return p;\n}\n\n\nstatic void opencheck (lua_State *L, const char *fname, const char *mode) {\n  LStream *p = newfile(L);\n  p->f = fopen(fname, mode);\n  if (p->f == NULL)\n    luaL_error(L, \"cannot open file '%s' (%s)\", fname, strerror(errno));\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newfile(L);\n  const char *md = mode;  /* to traverse/check mode */\n  luaL_argcheck(L, l_checkmode(md), 2, \"invalid mode\");\n  p->f = fopen(filename, mode);\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  LStream *p = tolstream(L);\n  errno = 0;\n  return luaL_execresult(L, l_pclose(L, p->f));\n#endif\n}\n\n\nstatic int io_popen (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  LStream *p = newprefile(L);\n  luaL_argcheck(L, l_checkmodep(mode), 2, \"invalid mode\");\n  p->f = l_popen(L, filename, mode);\n  p->closef = &io_pclose;\n  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;\n#endif\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  LStream *p = newfile(L);\n  p->f = tmpfile();\n  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, const char *findex) {\n  LStream *p;\n  lua_getfield(L, LUA_REGISTRYINDEX, findex);\n  p = (LStream *)lua_touserdata(L, -1);\n  if (isclosed(p))\n    luaL_error(L, \"default %s file is closed\", findex + IOPREF_LEN);\n  return p->f;\n}\n\n\nstatic int g_iofile (lua_State *L, const char *f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename)\n      opencheck(L, filename, mode);\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_setfield(L, LUA_REGISTRYINDEX, f);\n  }\n  /* return current value */\n  lua_getfield(L, LUA_REGISTRYINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\n/*\n** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit\n** in the limit for upvalues of a closure)\n*/\n#define MAXARGLINE\t250\n\n/*\n** Auxiliary function to create the iteration function for 'lines'.\n** The iteration function is a closure over 'io_readline', with\n** the following upvalues:\n** 1) The file being read (first value in the stack)\n** 2) the number of arguments to read\n** 3) a boolean, true iff file has to be closed when finished ('toclose')\n** *) a variable number of format arguments (rest of the stack)\n*/\nstatic void aux_lines (lua_State *L, int toclose) {\n  int n = lua_gettop(L) - 1;  /* number of arguments to read */\n  luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, \"too many arguments\");\n  lua_pushvalue(L, 1);  /* file */\n  lua_pushinteger(L, n);  /* number of arguments to read */\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_rotate(L, 2, 3);  /* move the three values to their positions */\n  lua_pushcclosure(L, io_readline, 3 + n);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 0);\n  return 1;\n}\n\n\n/*\n** Return an iteration function for 'io.lines'. If file has to be\n** closed, also returns the file itself as a second result (to be\n** closed as the state at the exit of a generic for).\n*/\nstatic int io_lines (lua_State *L) {\n  int toclose;\n  if (lua_isnone(L, 1)) lua_pushnil(L);  /* at least one argument */\n  if (lua_isnil(L, 1)) {  /* no file name? */\n    lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT);  /* get default input */\n    lua_replace(L, 1);  /* put it at index 1 */\n    tofile(L);  /* check that it's a valid file handle */\n    toclose = 0;  /* do not close it after iteration */\n  }\n  else {  /* open a new file */\n    const char *filename = luaL_checkstring(L, 1);\n    opencheck(L, filename, \"r\");\n    lua_replace(L, 1);  /* put file at index 1 */\n    toclose = 1;  /* close it after iteration */\n  }\n  aux_lines(L, toclose);  /* push iteration function */\n  if (toclose) {\n    lua_pushnil(L);  /* state */\n    lua_pushnil(L);  /* control */\n    lua_pushvalue(L, 1);  /* file is the to-be-closed variable (4th result) */\n    return 4;\n  }\n  else\n    return 1;\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\n/* maximum length of a numeral */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM     200\n#endif\n\n\n/* auxiliary structure used by 'read_number' */\ntypedef struct {\n  FILE *f;  /* file being read */\n  int c;  /* current character (look ahead) */\n  int n;  /* number of elements in buffer 'buff' */\n  char buff[L_MAXLENNUM + 1];  /* +1 for ending '\\0' */\n} RN;\n\n\n/*\n** Add current char to buffer (if not out of space) and read next one\n*/\nstatic int nextc (RN *rn) {\n  if (rn->n >= L_MAXLENNUM) {  /* buffer overflow? */\n    rn->buff[0] = '\\0';  /* invalidate result */\n    return 0;  /* fail */\n  }\n  else {\n    rn->buff[rn->n++] = rn->c;  /* save current char */\n    rn->c = l_getc(rn->f);  /* read next one */\n    return 1;\n  }\n}\n\n\n/*\n** Accept current char if it is in 'set' (of size 2)\n*/\nstatic int test2 (RN *rn, const char *set) {\n  if (rn->c == set[0] || rn->c == set[1])\n    return nextc(rn);\n  else return 0;\n}\n\n\n/*\n** Read a sequence of (hex)digits\n*/\nstatic int readdigits (RN *rn, int hex) {\n  int count = 0;\n  while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn))\n    count++;\n  return count;\n}\n\n\n/*\n** Read a number: first reads a valid prefix of a numeral into a buffer.\n** Then it calls 'lua_stringtonumber' to check whether the format is\n** correct and to convert it to a Lua number.\n*/\nstatic int read_number (lua_State *L, FILE *f) {\n  RN rn;\n  int count = 0;\n  int hex = 0;\n  char decp[2];\n  rn.f = f; rn.n = 0;\n  decp[0] = lua_getlocaledecpoint();  /* get decimal point from locale */\n  decp[1] = '.';  /* always accept a dot */\n  l_lockfile(rn.f);\n  do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */\n  test2(&rn, \"-+\");  /* optional sign */\n  if (test2(&rn, \"00\")) {\n    if (test2(&rn, \"xX\")) hex = 1;  /* numeral is hexadecimal */\n    else count = 1;  /* count initial '0' as a valid digit */\n  }\n  count += readdigits(&rn, hex);  /* integral part */\n  if (test2(&rn, decp))  /* decimal point? */\n    count += readdigits(&rn, hex);  /* fractional part */\n  if (count > 0 && test2(&rn, (hex ? \"pP\" : \"eE\"))) {  /* exponent mark? */\n    test2(&rn, \"-+\");  /* exponent sign */\n    readdigits(&rn, 0);  /* exponent digits */\n  }\n  ungetc(rn.c, rn.f);  /* unread look-ahead char */\n  l_unlockfile(rn.f);\n  rn.buff[rn.n] = '\\0';  /* finish string */\n  if (lua_stringtonumber(L, rn.buff))  /* is this a valid number? */\n    return 1;  /* ok */\n  else {  /* invalid format */\n   lua_pushnil(L);  /* \"result\" to be removed */\n   return 0;  /* read fails */\n  }\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);  /* no-op when c == EOF */\n  lua_pushliteral(L, \"\");\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f, int chop) {\n  luaL_Buffer b;\n  int c;\n  luaL_buffinit(L, &b);\n  do {  /* may need to read several chunks to get whole line */\n    char *buff = luaL_prepbuffer(&b);  /* preallocate buffer space */\n    int i = 0;\n    l_lockfile(f);  /* no memory errors can happen inside the lock */\n    while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')\n      buff[i++] = c;  /* read up to end of line or buffer limit */\n    l_unlockfile(f);\n    luaL_addsize(&b, i);\n  } while (c != EOF && c != '\\n');  /* repeat until end of line */\n  if (!chop && c == '\\n')  /* want a newline and have one? */\n    luaL_addchar(&b, c);  /* add ending newline to result */\n  luaL_pushresult(&b);  /* close buffer */\n  /* return ok if read something (either a newline or something else) */\n  return (c == '\\n' || lua_rawlen(L, -1) > 0);\n}\n\n\nstatic void read_all (lua_State *L, FILE *f) {\n  size_t nr;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */\n    char *p = luaL_prepbuffer(&b);\n    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);\n    luaL_addsize(&b, nr);\n  } while (nr == LUAL_BUFFERSIZE);\n  luaL_pushresult(&b);  /* close buffer */\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t nr;  /* number of chars actually read */\n  char *p;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */\n  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */\n  luaL_addsize(&b, nr);\n  luaL_pushresult(&b);  /* close buffer */\n  return (nr > 0);  /* true iff read something */\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int n, success;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f, 1);\n    n = first + 1;  /* to return 1 result */\n  }\n  else {\n    /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)luaL_checkinteger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = luaL_checkstring(L, n);\n        if (*p == '*') p++;  /* skip optional '*' (for compatibility) */\n        switch (*p) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f, 1);\n            break;\n          case 'L':  /* line with end-of-line */\n            success = read_line(L, f, 0);\n            break;\n          case 'a':  /* file */\n            read_all(L, f);  /* read entire file */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return luaL_fileresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    luaL_pushfail(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\n/*\n** Iteration function for 'lines'.\n*/\nstatic int io_readline (lua_State *L) {\n  LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));\n  int i;\n  int n = (int)lua_tointeger(L, lua_upvalueindex(2));\n  if (isclosed(p))  /* file is already closed? */\n    return luaL_error(L, \"file is already closed\");\n  lua_settop(L , 1);\n  luaL_checkstack(L, n, \"too many arguments\");\n  for (i = 1; i <= n; i++)  /* push arguments to 'g_read' */\n    lua_pushvalue(L, lua_upvalueindex(3 + i));\n  n = g_read(L, p->f, 2);  /* 'n' is number of results */\n  lua_assert(n > 0);  /* should return at least a nil */\n  if (lua_toboolean(L, -n))  /* read at least one value? */\n    return n;  /* return them */\n  else {  /* first result is false: EOF or error */\n    if (n > 1) {  /* is there error information? */\n      /* 2nd result is error message */\n      return luaL_error(L, \"%s\", lua_tostring(L, -n + 1));\n    }\n    if (lua_toboolean(L, lua_upvalueindex(3))) {  /* generator created file? */\n      lua_settop(L, 0);  /* clear stack */\n      lua_pushvalue(L, lua_upvalueindex(1));  /* push file at index 1 */\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - arg;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      int len = lua_isinteger(L, arg)\n                ? fprintf(f, LUA_INTEGER_FMT,\n                             (LUAI_UACINT)lua_tointeger(L, arg))\n                : fprintf(f, LUA_NUMBER_FMT,\n                             (LUAI_UACNUMBER)lua_tonumber(L, arg));\n      status = status && (len > 0);\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  if (status) return 1;  /* file handle already on stack top */\n  else return luaL_fileresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  FILE *f = tofile(L);\n  lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */\n  return g_write(L, f, 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  lua_Integer p3 = luaL_optinteger(L, 3, 0);\n  l_seeknum offset = (l_seeknum)p3;\n  luaL_argcheck(L, (lua_Integer)offset == p3, 3,\n                  \"not an integer in proper range\");\n  op = l_fseek(f, offset, mode[op]);\n  if (op)\n    return luaL_fileresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, (lua_Integer)l_ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], (size_t)sz);\n  return luaL_fileresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\n/*\n** functions for 'io' library\n*/\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\n/*\n** methods for file handles\n*/\nstatic const luaL_Reg meth[] = {\n  {\"read\", f_read},\n  {\"write\", f_write},\n  {\"lines\", f_lines},\n  {\"flush\", f_flush},\n  {\"seek\", f_seek},\n  {\"close\", f_close},\n  {\"setvbuf\", f_setvbuf},\n  {NULL, NULL}\n};\n\n\n/*\n** metamethods for file handles\n*/\nstatic const luaL_Reg metameth[] = {\n  {\"__index\", NULL},  /* place holder */\n  {\"__gc\", f_gc},\n  {\"__close\", f_gc},\n  {\"__tostring\", f_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* metatable for file handles */\n  luaL_setfuncs(L, metameth, 0);  /* add metamethods to new metatable */\n  luaL_newlibtable(L, meth);  /* create method table */\n  luaL_setfuncs(L, meth, 0);  /* add file methods to method table */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = method table */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  LStream *p = tolstream(L);\n  p->closef = &io_noclose;  /* keep file opened */\n  luaL_pushfail(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, const char *k,\n                           const char *fname) {\n  LStream *p = newprefile(L);\n  p->f = f;\n  p->closef = &io_noclose;\n  if (k != NULL) {\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */\n  }\n  lua_setfield(L, -2, fname);  /* add file to module */\n}\n\n\nLUAMOD_API int luaopen_io (lua_State *L) {\n  luaL_newlib(L, iolib);  /* new module */\n  createmeta(L);\n  /* create (and set) default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, NULL, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ljumptab.h",
    "content": "/*\n** $Id: ljumptab.h $\n** Jump Table for the Lua interpreter\n** See Copyright Notice in lua.h\n*/\n\n\n#undef vmdispatch\n#undef vmcase\n#undef vmbreak\n\n#define vmdispatch(x)     goto *disptab[x];\n\n#define vmcase(l)     L_##l:\n\n#define vmbreak\t\tvmfetch(); vmdispatch(GET_OPCODE(i));\n\n\nstatic const void *const disptab[NUM_OPCODES] = {\n\n#if 0\n** you can update the following list with this command:\n**\n**  sed -n '/^OP_/\\!d; s/OP_/\\&\\&L_OP_/ ; s/,.*/,/ ; s/\\/.*// ; p'  lopcodes.h\n**\n#endif\n\n&&L_OP_MOVE,\n&&L_OP_LOADI,\n&&L_OP_LOADF,\n&&L_OP_LOADK,\n&&L_OP_LOADKX,\n&&L_OP_LOADFALSE,\n&&L_OP_LFALSESKIP,\n&&L_OP_LOADTRUE,\n&&L_OP_LOADNIL,\n&&L_OP_GETUPVAL,\n&&L_OP_SETUPVAL,\n&&L_OP_GETTABUP,\n&&L_OP_GETTABLE,\n&&L_OP_GETI,\n&&L_OP_GETFIELD,\n&&L_OP_SETTABUP,\n&&L_OP_SETTABLE,\n&&L_OP_SETI,\n&&L_OP_SETFIELD,\n&&L_OP_NEWTABLE,\n&&L_OP_SELF,\n&&L_OP_ADDI,\n&&L_OP_ADDK,\n&&L_OP_SUBK,\n&&L_OP_MULK,\n&&L_OP_MODK,\n&&L_OP_POWK,\n&&L_OP_DIVK,\n&&L_OP_IDIVK,\n&&L_OP_BANDK,\n&&L_OP_BORK,\n&&L_OP_BXORK,\n&&L_OP_SHRI,\n&&L_OP_SHLI,\n&&L_OP_ADD,\n&&L_OP_SUB,\n&&L_OP_MUL,\n&&L_OP_MOD,\n&&L_OP_POW,\n&&L_OP_DIV,\n&&L_OP_IDIV,\n&&L_OP_BAND,\n&&L_OP_BOR,\n&&L_OP_BXOR,\n&&L_OP_SHL,\n&&L_OP_SHR,\n&&L_OP_MMBIN,\n&&L_OP_MMBINI,\n&&L_OP_MMBINK,\n&&L_OP_UNM,\n&&L_OP_BNOT,\n&&L_OP_NOT,\n&&L_OP_LEN,\n&&L_OP_CONCAT,\n&&L_OP_CLOSE,\n&&L_OP_TBC,\n&&L_OP_JMP,\n&&L_OP_EQ,\n&&L_OP_LT,\n&&L_OP_LE,\n&&L_OP_EQK,\n&&L_OP_EQI,\n&&L_OP_LTI,\n&&L_OP_LEI,\n&&L_OP_GTI,\n&&L_OP_GEI,\n&&L_OP_TEST,\n&&L_OP_TESTSET,\n&&L_OP_CALL,\n&&L_OP_TAILCALL,\n&&L_OP_RETURN,\n&&L_OP_RETURN0,\n&&L_OP_RETURN1,\n&&L_OP_FORLOOP,\n&&L_OP_FORPREP,\n&&L_OP_TFORPREP,\n&&L_OP_TFORCALL,\n&&L_OP_TFORLOOP,\n&&L_OP_SETLIST,\n&&L_OP_CLOSURE,\n&&L_OP_VARARG,\n&&L_OP_VARARGPREP,\n&&L_OP_EXTRAARG\n\n};\n"
  },
  {
    "path": "build/lua-5.4.1/src/llex.c",
    "content": "/*\n** $Id: llex.c $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls)\t(ls->current = zgetc(ls->z))\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nstatic const char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"goto\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"//\", \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<<\", \">>\", \"::\", \"<eof>\",\n    \"<number>\", \"<integer>\", \"<name>\", \"<string>\"\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token);\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {\n    size_t newsize;\n    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)\n      lexerror(ls, \"lexical element too long\", 0);\n    newsize = luaZ_sizebuffer(b) * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[luaZ_bufflen(b)++] = cast_char(c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */\n  luaC_fix(L, obj2gco(e));  /* never collect this name */\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */\n    ts->extra = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {  /* single-byte symbols? */\n    if (lisprint(token))\n      return luaO_pushfstring(ls->L, \"'%c'\", token);\n    else  /* control character */\n      return luaO_pushfstring(ls->L, \"'<\\\\%d>'\", token);\n  }\n  else {\n    const char *s = luaX_tokens[token - FIRST_RESERVED];\n    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */\n      return luaO_pushfstring(ls->L, \"'%s'\", s);\n    else  /* names, strings, and numerals */\n      return s;\n  }\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME: case TK_STRING:\n    case TK_FLT: case TK_INT:\n      save(ls, '\\0');\n      return luaO_pushfstring(ls->L, \"'%s'\", luaZ_buffer(ls->buff));\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nstatic l_noret lexerror (LexState *ls, const char *msg, int token) {\n  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near %s\", msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nl_noret luaX_syntaxerror (LexState *ls, const char *msg) {\n  lexerror(ls, msg, ls->t.token);\n}\n\n\n/*\n** creates a new string and anchors it in scanner's table so that\n** it will not be collected until the end of the compilation\n** (by that time it should be anchored somewhere)\n*/\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TValue *o;  /* entry for 'str' */\n  TString *ts = luaS_newlstr(L, str, l);  /* create new string */\n  setsvalue2s(L, L->top++, ts);  /* temporarily anchor it in stack */\n  o = luaH_set(L, ls->h, s2v(L->top - 1));\n  if (isempty(o)) {  /* not in use yet? */\n    /* boolean value does not need GC barrier;\n       table is not a metatable, so it does not need to invalidate cache */\n    setbtvalue(o);  /* t[string] = true */\n    luaC_checkGC(L);\n  }\n  else {  /* string already present */\n    ts = keystrval(nodefromval(o));  /* re-use value previously stored */\n  }\n  L->top--;  /* remove string from stack */\n  return ts;\n}\n\n\n/*\n** increment line number and skips newline sequence (any of\n** \\n, \\r, \\n\\r, or \\r\\n)\n*/\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip '\\n' or '\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip '\\n\\r' or '\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    lexerror(ls, \"chunk has too many lines\", 0);\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,\n                    int firstchar) {\n  ls->t.token = 0;\n  ls->L = L;\n  ls->current = firstchar;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\nstatic int check_next1 (LexState *ls, int c) {\n  if (ls->current == c) {\n    next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check whether current char is in set 'set' (with two chars) and\n** saves it\n*/\nstatic int check_next2 (LexState *ls, const char *set) {\n  lua_assert(set[2] == '\\0');\n  if (ls->current == set[0] || ls->current == set[1]) {\n    save_and_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/* LUA_NUMBER */\n/*\n** This function is quite liberal in what it accepts, as 'luaO_str2num'\n** will reject ill-formed numerals. Roughly, it accepts the following\n** pattern:\n**\n**   %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*\n**\n** The only tricky part is to accept [+-] only after a valid exponent\n** mark, to avoid reading '3-4' or '0xe+1' as a single number.\n**\n** The caller might have already read an initial dot.\n*/\nstatic int read_numeral (LexState *ls, SemInfo *seminfo) {\n  TValue obj;\n  const char *expo = \"Ee\";\n  int first = ls->current;\n  lua_assert(lisdigit(ls->current));\n  save_and_next(ls);\n  if (first == '0' && check_next2(ls, \"xX\"))  /* hexadecimal? */\n    expo = \"Pp\";\n  for (;;) {\n    if (check_next2(ls, expo))  /* exponent mark? */\n      check_next2(ls, \"-+\");  /* optional exponent sign */\n    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */\n      save_and_next(ls);\n    else break;\n  }\n  if (lislalpha(ls->current))  /* is numeral touching a letter? */\n    save_and_next(ls);  /* force an error */\n  save(ls, '\\0');\n  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */\n    lexerror(ls, \"malformed number\", TK_FLT);\n  if (ttisinteger(&obj)) {\n    seminfo->i = ivalue(&obj);\n    return TK_INT;\n  }\n  else {\n    lua_assert(ttisfloat(&obj));\n    seminfo->r = fltvalue(&obj);\n    return TK_FLT;\n  }\n}\n\n\n/*\n** reads a sequence '[=*[' or ']=*]', leaving the last bracket.\n** If sequence is well formed, return its number of '='s + 2; otherwise,\n** return 1 if there is no '='s or 0 otherwise (an unfinished '[==...').\n*/\nstatic size_t skip_sep (LexState *ls) {\n  size_t count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count + 2\n         : (count == 0) ? 1\n         : 0;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {\n  int line = ls->linenumber;  /* initial line (for error message) */\n  save_and_next(ls);  /* skip 2nd '[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ: {  /* error */\n        const char *what = (seminfo ? \"string\" : \"comment\");\n        const char *msg = luaO_pushfstring(ls->L,\n                     \"unfinished long %s (starting at line %d)\", what, line);\n        lexerror(ls, msg, TK_EOS);\n        break;  /* to avoid warnings */\n      }\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd ']' */\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n': case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,\n                                     luaZ_bufflen(ls->buff) - 2 * sep);\n}\n\n\nstatic void esccheck (LexState *ls, int c, const char *msg) {\n  if (!c) {\n    if (ls->current != EOZ)\n      save_and_next(ls);  /* add current to buffer for error message */\n    lexerror(ls, msg, TK_STRING);\n  }\n}\n\n\nstatic int gethexa (LexState *ls) {\n  save_and_next(ls);\n  esccheck (ls, lisxdigit(ls->current), \"hexadecimal digit expected\");\n  return luaO_hexavalue(ls->current);\n}\n\n\nstatic int readhexaesc (LexState *ls) {\n  int r = gethexa(ls);\n  r = (r << 4) + gethexa(ls);\n  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic unsigned long readutf8esc (LexState *ls) {\n  unsigned long r;\n  int i = 4;  /* chars to be removed: '\\', 'u', '{', and first digit */\n  save_and_next(ls);  /* skip 'u' */\n  esccheck(ls, ls->current == '{', \"missing '{'\");\n  r = gethexa(ls);  /* must have at least one digit */\n  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {\n    i++;\n    esccheck(ls, r <= (0x7FFFFFFFu >> 4), \"UTF-8 value too large\");\n    r = (r << 4) + luaO_hexavalue(ls->current);\n  }\n  esccheck(ls, ls->current == '}', \"missing '}'\");\n  next(ls);  /* skip '}' */\n  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */\n  return r;\n}\n\n\nstatic void utf8esc (LexState *ls) {\n  char buff[UTF8BUFFSZ];\n  int n = luaO_utf8esc(buff, readutf8esc(ls));\n  for (; n > 0; n--)  /* add 'buff' to string */\n    save(ls, buff[UTF8BUFFSZ - n]);\n}\n\n\nstatic int readdecesc (LexState *ls) {\n  int i;\n  int r = 0;  /* result accumulator */\n  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */\n    r = 10*r + ls->current - '0';\n    save_and_next(ls);\n  }\n  esccheck(ls, r <= UCHAR_MAX, \"decimal escape too large\");\n  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */\n  return r;\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);  /* keep delimiter (for error messages) */\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        lexerror(ls, \"unfinished string\", TK_EOS);\n        break;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        lexerror(ls, \"unfinished string\", TK_STRING);\n        break;  /* to avoid warnings */\n      case '\\\\': {  /* escape sequences */\n        int c;  /* final character to be saved */\n        save_and_next(ls);  /* keep '\\\\' for error messages */\n        switch (ls->current) {\n          case 'a': c = '\\a'; goto read_save;\n          case 'b': c = '\\b'; goto read_save;\n          case 'f': c = '\\f'; goto read_save;\n          case 'n': c = '\\n'; goto read_save;\n          case 'r': c = '\\r'; goto read_save;\n          case 't': c = '\\t'; goto read_save;\n          case 'v': c = '\\v'; goto read_save;\n          case 'x': c = readhexaesc(ls); goto read_save;\n          case 'u': utf8esc(ls);  goto no_save;\n          case '\\n': case '\\r':\n            inclinenumber(ls); c = '\\n'; goto only_save;\n          case '\\\\': case '\\\"': case '\\'':\n            c = ls->current; goto read_save;\n          case EOZ: goto no_save;  /* will raise an error next loop */\n          case 'z': {  /* zap following span of spaces */\n            luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n            next(ls);  /* skip the 'z' */\n            while (lisspace(ls->current)) {\n              if (currIsNewline(ls)) inclinenumber(ls);\n              else next(ls);\n            }\n            goto no_save;\n          }\n          default: {\n            esccheck(ls, lisdigit(ls->current), \"invalid escape sequence\");\n            c = readdecesc(ls);  /* digital escape '\\ddd' */\n            goto only_save;\n          }\n        }\n       read_save:\n         next(ls);\n         /* go through */\n       only_save:\n         luaZ_buffremove(ls->buff, 1);  /* remove '\\\\' */\n         save(ls, c);\n         /* go through */\n       no_save: break;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n': case '\\r': {  /* line breaks */\n        inclinenumber(ls);\n        break;\n      }\n      case ' ': case '\\f': case '\\t': case '\\v': {  /* spaces */\n        next(ls);\n        break;\n      }\n      case '-': {  /* '-' or '--' (comment) */\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {  /* long comment? */\n          size_t sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */\n          if (sep >= 2) {\n            read_long_string(ls, NULL, sep);  /* skip long comment */\n            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */\n            break;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);  /* skip until end of line (or end of file) */\n        break;\n      }\n      case '[': {  /* long string or simply '[' */\n        size_t sep = skip_sep(ls);\n        if (sep >= 2) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep == 0)  /* '[=...' missing second bracket? */\n          lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n        return '[';\n      }\n      case '=': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_EQ;\n        else return '=';\n      }\n      case '<': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_LE;\n        else if (check_next1(ls, '<')) return TK_SHL;\n        else return '<';\n      }\n      case '>': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_GE;\n        else if (check_next1(ls, '>')) return TK_SHR;\n        else return '>';\n      }\n      case '/': {\n        next(ls);\n        if (check_next1(ls, '/')) return TK_IDIV;\n        else return '/';\n      }\n      case '~': {\n        next(ls);\n        if (check_next1(ls, '=')) return TK_NE;\n        else return '~';\n      }\n      case ':': {\n        next(ls);\n        if (check_next1(ls, ':')) return TK_DBCOLON;\n        else return ':';\n      }\n      case '\"': case '\\'': {  /* short literal strings */\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {  /* '.', '..', '...', or number */\n        save_and_next(ls);\n        if (check_next1(ls, '.')) {\n          if (check_next1(ls, '.'))\n            return TK_DOTS;   /* '...' */\n          else return TK_CONCAT;   /* '..' */\n        }\n        else if (!lisdigit(ls->current)) return '.';\n        else return read_numeral(ls, seminfo);\n      }\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9': {\n        return read_numeral(ls, seminfo);\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (lislalpha(ls->current)) {  /* identifier or reserved word? */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (lislalnum(ls->current));\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          seminfo->ts = ts;\n          if (isreserved(ts))  /* reserved word? */\n            return ts->extra - 1 + FIRST_RESERVED;\n          else {\n            return TK_NAME;\n          }\n        }\n        else {  /* single-char tokens (+ - / ...) */\n          int c = ls->current;\n          next(ls);\n          return c;\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nint luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n  return ls->lookahead.token;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/llex.h",
    "content": "/*\n** $Id: llex.h $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include <limits.h>\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Single-char tokens (terminal symbols) are represented by their own\n** numeric code. Other tokens start at the following value.\n*/\n#define FIRST_RESERVED\t(UCHAR_MAX + 1)\n\n\n#if !defined(LUA_ENV)\n#define LUA_ENV\t\t\"_ENV\"\n#endif\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,\n  TK_SHL, TK_SHR,\n  TK_DBCOLON, TK_EOS,\n  TK_FLT, TK_INT, TK_NAME, TK_STRING\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast_int(TK_WHILE-FIRST_RESERVED + 1))\n\n\ntypedef union {\n  lua_Number r;\n  lua_Integer i;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\n/* state of the lexer plus state of the parser when shared by all\n   functions */\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token 'consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* current function (parser) */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  Table *h;  /* to avoid collection/reuse strings */\n  struct Dyndata *dyd;  /* dynamic structures used by the parser */\n  TString *source;  /* current source name */\n  TString *envn;  /* environment variable name */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source, int firstchar);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC int luaX_lookahead (LexState *ls);\nLUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/llimits.h",
    "content": "/*\n** $Id: llimits.h $\n** Limits, basic types, and some other 'installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n\n/*\n** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count\n** the total memory used by Lua (in bytes). Usually, 'size_t' and\n** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.\n*/\n#if defined(LUAI_MEM)\t\t/* { external definitions? */\ntypedef LUAI_UMEM lu_mem;\ntypedef LUAI_MEM l_mem;\n#elif LUAI_IS32INT\t/* }{ */\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\n#else  /* 16-bit ints */\t/* }{ */\ntypedef unsigned long lu_mem;\ntypedef long l_mem;\n#endif\t\t\t\t/* } */\n\n\n/* chars used as small naturals (so that 'char' is reserved for characters) */\ntypedef unsigned char lu_byte;\ntypedef signed char ls_byte;\n\n\n/* maximum value for size_t */\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n/* maximum size visible for Lua (must be representable in a lua_Integer) */\n#define MAX_SIZE\t(sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \\\n                          : (size_t)(LUA_MAXINTEGER))\n\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0))\n\n#define MAX_LMEM\t((l_mem)(MAX_LUMEM >> 1))\n\n\n#define MAX_INT\t\tINT_MAX  /* maximum value of an int */\n\n\n/*\n** floor of the log2 of the maximum signed value for integral type 't'.\n** (That is, maximum 'n' such that '2^n' fits in the given signed type.)\n*/\n#define log2maxs(t)\t(sizeof(t) * 8 - 2)\n\n\n/*\n** test whether an unsigned value is a power of 2 (or zero)\n*/\n#define ispow2(x)\t(((x) & ((x) - 1)) == 0)\n\n\n/* number of chars of a literal string without the ending \\0 */\n#define LL(x)   (sizeof(x)/sizeof(char) - 1)\n\n\n/*\n** conversion of pointer to unsigned integer:\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define point2uint(p)\t((unsigned int)((size_t)(p) & UINT_MAX))\n\n\n\n/* types of 'usual argument conversions' for lua_Number and lua_Integer */\ntypedef LUAI_UACNUMBER l_uacNumber;\ntypedef LUAI_UACINT l_uacInt;\n\n\n/*\n** Internal assertions for in-house debugging\n*/\n#if defined LUAI_ASSERT\n#undef NDEBUG\n#include <assert.h>\n#define lua_assert(c)           assert(c)\n#endif\n\n#if defined(lua_assert)\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n/* to avoid problems with conditions too long */\n#define lua_longassert(c)\t((c) ? (void)0 : lua_assert(0))\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define lua_longassert(c)\t((void)0)\n#endif\n\n/*\n** assertion for checking API calls\n*/\n#if !defined(luai_apicheck)\n#define luai_apicheck(l,e)\t((void)l, lua_assert(e))\n#endif\n\n#define api_check(l,e,msg)\tluai_apicheck(l,(e) && msg)\n\n\n/* macro to avoid warnings about unused variables */\n#if !defined(UNUSED)\n#define UNUSED(x)\t((void)(x))\n#endif\n\n\n/* type casts (a macro highlights casts in the code) */\n#define cast(t, exp)\t((t)(exp))\n\n#define cast_void(i)\tcast(void, (i))\n#define cast_voidp(i)\tcast(void *, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n#define cast_uint(i)\tcast(unsigned int, (i))\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_uchar(i)\tcast(unsigned char, (i))\n#define cast_char(i)\tcast(char, (i))\n#define cast_charp(i)\tcast(char *, (i))\n#define cast_sizet(i)\tcast(size_t, (i))\n\n\n/* cast a signed lua_Integer to lua_Unsigned */\n#if !defined(l_castS2U)\n#define l_castS2U(i)\t((lua_Unsigned)(i))\n#endif\n\n/*\n** cast a lua_Unsigned to a signed lua_Integer; this cast is\n** not strict ISO C, but two-complement architectures should\n** work fine.\n*/\n#if !defined(l_castU2S)\n#define l_castU2S(i)\t((lua_Integer)(i))\n#endif\n\n\n/*\n** macros to improve jump prediction (used mainly for error handling)\n*/\n#if !defined(likely)\n\n#if defined(__GNUC__)\n#define likely(x)\t(__builtin_expect(((x) != 0), 1))\n#define unlikely(x)\t(__builtin_expect(((x) != 0), 0))\n#else\n#define likely(x)\t(x)\n#define unlikely(x)\t(x)\n#endif\n\n#endif\n\n\n/*\n** non-return type\n*/\n#if !defined(l_noret)\n\n#if defined(__GNUC__)\n#define l_noret\t\tvoid __attribute__((noreturn))\n#elif defined(_MSC_VER) && _MSC_VER >= 1200\n#define l_noret\t\tvoid __declspec(noreturn)\n#else\n#define l_noret\t\tvoid\n#endif\n\n#endif\n\n\n/*\n** type for virtual-machine instructions;\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\n#if LUAI_IS32INT\ntypedef unsigned int l_uint32;\n#else\ntypedef unsigned long l_uint32;\n#endif\n\ntypedef l_uint32 Instruction;\n\n\n\n/*\n** Maximum length for short strings, that is, strings that are\n** internalized. (Cannot be smaller than reserved words or tags for\n** metamethods, as these strings must be internalized;\n** #(\"function\") = 8, #(\"__newindex\") = 10.)\n*/\n#if !defined(LUAI_MAXSHORTLEN)\n#define LUAI_MAXSHORTLEN\t40\n#endif\n\n\n/*\n** Initial size for the string table (must be power of 2).\n** The Lua core alone registers ~50 strings (reserved words +\n** metaevent keys + a few others). Libraries would typically add\n** a few dozens more.\n*/\n#if !defined(MINSTRTABSIZE)\n#define MINSTRTABSIZE\t128\n#endif\n\n\n/*\n** Size of cache for strings in the API. 'N' is the number of\n** sets (better be a prime) and \"M\" is the size of each set (M == 1\n** makes a direct cache.)\n*/\n#if !defined(STRCACHE_N)\n#define STRCACHE_N\t\t53\n#define STRCACHE_M\t\t2\n#endif\n\n\n/* minimum size for string buffer */\n#if !defined(LUA_MINBUFFER)\n#define LUA_MINBUFFER\t32\n#endif\n\n\n/*\n** macros that are executed whenever program enters the Lua core\n** ('lua_lock') and leaves the core ('lua_unlock')\n*/\n#if !defined(lua_lock)\n#define lua_lock(L)\t((void) 0)\n#define lua_unlock(L)\t((void) 0)\n#endif\n\n/*\n** macro executed during Lua functions at points where the\n** function can yield.\n*/\n#if !defined(luai_threadyield)\n#define luai_threadyield(L)\t{lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** these macros allow user-specific actions when a thread is\n** created/deleted/resumed/yielded.\n*/\n#if !defined(luai_userstateopen)\n#define luai_userstateopen(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstateclose)\n#define luai_userstateclose(L)\t\t((void)L)\n#endif\n\n#if !defined(luai_userstatethread)\n#define luai_userstatethread(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstatefree)\n#define luai_userstatefree(L,L1)\t((void)L)\n#endif\n\n#if !defined(luai_userstateresume)\n#define luai_userstateresume(L,n)\t((void)L)\n#endif\n\n#if !defined(luai_userstateyield)\n#define luai_userstateyield(L,n)\t((void)L)\n#endif\n\n\n\n/*\n** The luai_num* macros define the primitive operations over numbers.\n*/\n\n/* floor division (defined as 'floor(a/b)') */\n#if !defined(luai_numidiv)\n#define luai_numidiv(L,a,b)     ((void)L, l_floor(luai_numdiv(L,a,b)))\n#endif\n\n/* float division */\n#if !defined(luai_numdiv)\n#define luai_numdiv(L,a,b)      ((a)/(b))\n#endif\n\n/*\n** modulo: defined as 'a - floor(a/b)*b'; the direct computation\n** using this definition has several problems with rounding errors,\n** so it is better to use 'fmod'. 'fmod' gives the result of\n** 'a - trunc(a/b)*b', and therefore must be corrected when\n** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a\n** non-integer negative result: non-integer result is equivalent to\n** a non-zero remainder 'm'; negative result is equivalent to 'a' and\n** 'b' with different signs, or 'm' and 'b' with different signs\n** (as the result 'm' of 'fmod' has the same sign of 'a').\n*/\n#if !defined(luai_nummod)\n#define luai_nummod(L,a,b,m)  \\\n  { (void)L; (m) = l_mathop(fmod)(a,b); \\\n    if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }\n#endif\n\n/* exponentiation */\n#if !defined(luai_numpow)\n#define luai_numpow(L,a,b)      ((void)L, l_mathop(pow)(a,b))\n#endif\n\n/* the others are quite standard operations */\n#if !defined(luai_numadd)\n#define luai_numadd(L,a,b)      ((a)+(b))\n#define luai_numsub(L,a,b)      ((a)-(b))\n#define luai_nummul(L,a,b)      ((a)*(b))\n#define luai_numunm(L,a)        (-(a))\n#define luai_numeq(a,b)         ((a)==(b))\n#define luai_numlt(a,b)         ((a)<(b))\n#define luai_numle(a,b)         ((a)<=(b))\n#define luai_numgt(a,b)         ((a)>(b))\n#define luai_numge(a,b)         ((a)>=(b))\n#define luai_numisnan(a)        (!luai_numeq((a), (a)))\n#endif\n\n\n\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/\n#if !defined(HARDSTACKTESTS)\n#define condmovestack(L,pre,pos)\t((void)0)\n#else\n/* realloc stack keeping its size */\n#define condmovestack(L,pre,pos)  \\\n  { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_, 0); pos; }\n#endif\n\n#if !defined(HARDMEMTESTS)\n#define condchangemem(L,pre,pos)\t((void)0)\n#else\n#define condchangemem(L,pre,pos)  \\\n\t{ if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdlib.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI\t(l_mathop(3.141592653589793238462643383279502884))\n\n\nstatic int math_abs (lua_State *L) {\n  if (lua_isinteger(L, 1)) {\n    lua_Integer n = lua_tointeger(L, 1);\n    if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);\n    lua_pushinteger(L, n);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_Number y = luaL_checknumber(L, 1);\n  lua_Number x = luaL_optnumber(L, 2, 1);\n  lua_pushnumber(L, l_mathop(atan2)(y, x));\n  return 1;\n}\n\n\nstatic int math_toint (lua_State *L) {\n  int valid;\n  lua_Integer n = lua_tointegerx(L, 1, &valid);\n  if (valid)\n    lua_pushinteger(L, n);\n  else {\n    luaL_checkany(L, 1);\n    luaL_pushfail(L);  /* value is not convertible to integer */\n  }\n  return 1;\n}\n\n\nstatic void pushnumint (lua_State *L, lua_Number d) {\n  lua_Integer n;\n  if (lua_numbertointeger(d, &n))  /* does 'd' fit in an integer? */\n    lua_pushinteger(L, n);  /* result is integer */\n  else\n    lua_pushnumber(L, d);  /* result is float */\n}\n\n\nstatic int math_floor (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own floor */\n  else {\n    lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_ceil (lua_State *L) {\n  if (lua_isinteger(L, 1))\n    lua_settop(L, 1);  /* integer is its own ceil */\n  else {\n    lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1));\n    pushnumint(L, d);\n  }\n  return 1;\n}\n\n\nstatic int math_fmod (lua_State *L) {\n  if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) {\n    lua_Integer d = lua_tointeger(L, 2);\n    if ((lua_Unsigned)d + 1u <= 1u) {  /* special cases: -1 or 0 */\n      luaL_argcheck(L, d != 0, 2, \"zero\");\n      lua_pushinteger(L, 0);  /* avoid overflow with 0x80000... / -1 */\n    }\n    else\n      lua_pushinteger(L, lua_tointeger(L, 1) % d);\n  }\n  else\n    lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),\n                                     luaL_checknumber(L, 2)));\n  return 1;\n}\n\n\n/*\n** next function does not use 'modf', avoiding problems with 'double*'\n** (which is not compatible with 'float*') when lua_Number is not\n** 'double'.\n*/\nstatic int math_modf (lua_State *L) {\n  if (lua_isinteger(L ,1)) {\n    lua_settop(L, 1);  /* number is its own integer part */\n    lua_pushnumber(L, 0);  /* no fractional part */\n  }\n  else {\n    lua_Number n = luaL_checknumber(L, 1);\n    /* integer part (rounds toward zero) */\n    lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);\n    pushnumint(L, ip);\n    /* fractional part (test needed for inf/-inf) */\n    lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip));\n  }\n  return 2;\n}\n\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n\nstatic int math_ult (lua_State *L) {\n  lua_Integer a = luaL_checkinteger(L, 1);\n  lua_Integer b = luaL_checkinteger(L, 2);\n  lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b);\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number res;\n  if (lua_isnoneornil(L, 2))\n    res = l_mathop(log)(x);\n  else {\n    lua_Number base = luaL_checknumber(L, 2);\n#if !defined(LUA_USE_C89)\n    if (base == l_mathop(2.0))\n      res = l_mathop(log2)(x); else\n#endif\n    if (base == l_mathop(10.0))\n      res = l_mathop(log10)(x);\n    else\n      res = l_mathop(log)(x)/l_mathop(log)(base);\n  }\n  lua_pushnumber(L, res);\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI));\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0)));\n  return 1;\n}\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imin = 1;  /* index of current minimum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, i, imin, LUA_OPLT))\n      imin = i;\n  }\n  lua_pushvalue(L, imin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int imax = 1;  /* index of current maximum value */\n  int i;\n  luaL_argcheck(L, n >= 1, 1, \"value expected\");\n  for (i = 2; i <= n; i++) {\n    if (lua_compare(L, imax, i, LUA_OPLT))\n      imax = i;\n  }\n  lua_pushvalue(L, imax);\n  return 1;\n}\n\n\nstatic int math_type (lua_State *L) {\n  if (lua_type(L, 1) == LUA_TNUMBER)\n    lua_pushstring(L, (lua_isinteger(L, 1)) ? \"integer\" : \"float\");\n  else {\n    luaL_checkany(L, 1);\n    luaL_pushfail(L);\n  }\n  return 1;\n}\n\n\n\n/*\n** {==================================================================\n** Pseudo-Random Number Generator based on 'xoshiro256**'.\n** ===================================================================\n*/\n\n/* number of binary digits in the mantissa of a float */\n#define FIGS\tl_floatatt(MANT_DIG)\n\n#if FIGS > 64\n/* there are only 64 random bits; use them all */\n#undef FIGS\n#define FIGS\t64\n#endif\n\n\n/*\n** LUA_RAND32 forces the use of 32-bit integers in the implementation\n** of the PRN generator (mainly for testing).\n*/\n#if !defined(LUA_RAND32) && !defined(Rand64)\n\n/* try to find an integer type with at least 64 bits */\n\n#if (ULONG_MAX >> 31 >> 31) >= 3\n\n/* 'long' has at least 64 bits */\n#define Rand64\t\tunsigned long\n\n#elif !defined(LUA_USE_C89) && defined(LLONG_MAX)\n\n/* there is a 'long long' type (which must have at least 64 bits) */\n#define Rand64\t\tunsigned long long\n\n#elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3\n\n/* 'lua_Integer' has at least 64 bits */\n#define Rand64\t\tlua_Unsigned\n\n#endif\n\n#endif\n\n\n#if defined(Rand64)  /* { */\n\n/*\n** Standard implementation, using 64-bit integers.\n** If 'Rand64' has more than 64 bits, the extra bits do not interfere\n** with the 64 initial bits, except in a right shift. Moreover, the\n** final result has to discard the extra bits.\n*/\n\n/* avoid using extra bits when needed */\n#define trim64(x)\t((x) & 0xffffffffffffffffu)\n\n\n/* rotate left 'x' by 'n' bits */\nstatic Rand64 rotl (Rand64 x, int n) {\n  return (x << n) | (trim64(x) >> (64 - n));\n}\n\nstatic Rand64 nextrand (Rand64 *state) {\n  Rand64 state0 = state[0];\n  Rand64 state1 = state[1];\n  Rand64 state2 = state[2] ^ state0;\n  Rand64 state3 = state[3] ^ state1;\n  Rand64 res = rotl(state1 * 5, 7) * 9;\n  state[0] = state0 ^ state3;\n  state[1] = state1 ^ state2;\n  state[2] = state2 ^ (state1 << 17);\n  state[3] = rotl(state3, 45);\n  return res;\n}\n\n\n/* must take care to not shift stuff by more than 63 slots */\n\n\n/*\n** Convert bits from a random integer into a float in the\n** interval [0,1), getting the higher FIG bits from the\n** random unsigned integer and converting that to a float.\n*/\n\n/* must throw out the extra (64 - FIGS) bits */\n#define shift64_FIG\t(64 - FIGS)\n\n/* to scale to [0, 1), multiply by scaleFIG = 2^(-FIGS) */\n#define scaleFIG\t(l_mathop(0.5) / ((Rand64)1 << (FIGS - 1)))\n\nstatic lua_Number I2d (Rand64 x) {\n  return (lua_Number)(trim64(x) >> shift64_FIG) * scaleFIG;\n}\n\n/* convert a 'Rand64' to a 'lua_Unsigned' */\n#define I2UInt(x)\t((lua_Unsigned)trim64(x))\n\n/* convert a 'lua_Unsigned' to a 'Rand64' */\n#define Int2I(x)\t((Rand64)(x))\n\n\n#else\t/* no 'Rand64'   }{ */\n\n/* get an integer with at least 32 bits */\n#if LUAI_IS32INT\ntypedef unsigned int lu_int32;\n#else\ntypedef unsigned long lu_int32;\n#endif\n\n\n/*\n** Use two 32-bit integers to represent a 64-bit quantity.\n*/\ntypedef struct Rand64 {\n  lu_int32 h;  /* higher half */\n  lu_int32 l;  /* lower half */\n} Rand64;\n\n\n/*\n** If 'lu_int32' has more than 32 bits, the extra bits do not interfere\n** with the 32 initial bits, except in a right shift and comparisons.\n** Moreover, the final result has to discard the extra bits.\n*/\n\n/* avoid using extra bits when needed */\n#define trim32(x)\t((x) & 0xffffffffu)\n\n\n/*\n** basic operations on 'Rand64' values\n*/\n\n/* build a new Rand64 value */\nstatic Rand64 packI (lu_int32 h, lu_int32 l) {\n  Rand64 result;\n  result.h = h;\n  result.l = l;\n  return result;\n}\n\n/* return i << n */\nstatic Rand64 Ishl (Rand64 i, int n) {\n  lua_assert(n > 0 && n < 32);\n  return packI((i.h << n) | (trim32(i.l) >> (32 - n)), i.l << n);\n}\n\n/* i1 ^= i2 */\nstatic void Ixor (Rand64 *i1, Rand64 i2) {\n  i1->h ^= i2.h;\n  i1->l ^= i2.l;\n}\n\n/* return i1 + i2 */\nstatic Rand64 Iadd (Rand64 i1, Rand64 i2) {\n  Rand64 result = packI(i1.h + i2.h, i1.l + i2.l);\n  if (trim32(result.l) < trim32(i1.l))  /* carry? */\n    result.h++;\n  return result;\n}\n\n/* return i * 5 */\nstatic Rand64 times5 (Rand64 i) {\n  return Iadd(Ishl(i, 2), i);  /* i * 5 == (i << 2) + i */\n}\n\n/* return i * 9 */\nstatic Rand64 times9 (Rand64 i) {\n  return Iadd(Ishl(i, 3), i);  /* i * 9 == (i << 3) + i */\n}\n\n/* return 'i' rotated left 'n' bits */\nstatic Rand64 rotl (Rand64 i, int n) {\n  lua_assert(n > 0 && n < 32);\n  return packI((i.h << n) | (trim32(i.l) >> (32 - n)),\n               (trim32(i.h) >> (32 - n)) | (i.l << n));\n}\n\n/* for offsets larger than 32, rotate right by 64 - offset */\nstatic Rand64 rotl1 (Rand64 i, int n) {\n  lua_assert(n > 32 && n < 64);\n  n = 64 - n;\n  return packI((trim32(i.h) >> n) | (i.l << (32 - n)),\n               (i.h << (32 - n)) | (trim32(i.l) >> n));\n}\n\n/*\n** implementation of 'xoshiro256**' algorithm on 'Rand64' values\n*/\nstatic Rand64 nextrand (Rand64 *state) {\n  Rand64 res = times9(rotl(times5(state[1]), 7));\n  Rand64 t = Ishl(state[1], 17);\n  Ixor(&state[2], state[0]);\n  Ixor(&state[3], state[1]);\n  Ixor(&state[1], state[2]);\n  Ixor(&state[0], state[3]);\n  Ixor(&state[2], t);\n  state[3] = rotl1(state[3], 45);\n  return res;\n}\n\n\n/*\n** Converts a 'Rand64' into a float.\n*/\n\n/* an unsigned 1 with proper type */\n#define UONE\t\t((lu_int32)1)\n\n\n#if FIGS <= 32\n\n/* 2^(-FIGS) */\n#define scaleFIG       (l_mathop(0.5) / (UONE << (FIGS - 1)))\n\n/*\n** get up to 32 bits from higher half, shifting right to\n** throw out the extra bits.\n*/\nstatic lua_Number I2d (Rand64 x) {\n  lua_Number h = (lua_Number)(trim32(x.h) >> (32 - FIGS));\n  return h * scaleFIG;\n}\n\n#else\t/* 32 < FIGS <= 64 */\n\n/* must take care to not shift stuff by more than 31 slots */\n\n/* 2^(-FIGS) = 1.0 / 2^30 / 2^3 / 2^(FIGS-33) */\n#define scaleFIG  \\\n\t((lua_Number)1.0 / (UONE << 30) / 8.0 / (UONE << (FIGS - 33)))\n\n/*\n** use FIGS - 32 bits from lower half, throwing out the other\n** (32 - (FIGS - 32)) = (64 - FIGS) bits\n*/\n#define shiftLOW\t(64 - FIGS)\n\n/*\n** higher 32 bits go after those (FIGS - 32) bits: shiftHI = 2^(FIGS - 32)\n*/\n#define shiftHI\t\t((lua_Number)(UONE << (FIGS - 33)) * 2.0)\n\n\nstatic lua_Number I2d (Rand64 x) {\n  lua_Number h = (lua_Number)trim32(x.h) * shiftHI;\n  lua_Number l = (lua_Number)(trim32(x.l) >> shiftLOW);\n  return (h + l) * scaleFIG;\n}\n\n#endif\n\n\n/* convert a 'Rand64' to a 'lua_Unsigned' */\nstatic lua_Unsigned I2UInt (Rand64 x) {\n  return ((lua_Unsigned)trim32(x.h) << 31 << 1) | (lua_Unsigned)trim32(x.l);\n}\n\n/* convert a 'lua_Unsigned' to a 'Rand64' */\nstatic Rand64 Int2I (lua_Unsigned n) {\n  return packI((lu_int32)(n >> 31 >> 1), (lu_int32)n);\n}\n\n#endif  /* } */\n\n\n/*\n** A state uses four 'Rand64' values.\n*/\ntypedef struct {\n  Rand64 s[4];\n} RanState;\n\n\n/*\n** Project the random integer 'ran' into the interval [0, n].\n** Because 'ran' has 2^B possible values, the projection can only be\n** uniform when the size of the interval is a power of 2 (exact\n** division). Otherwise, to get a uniform projection into [0, n], we\n** first compute 'lim', the smallest Mersenne number not smaller than\n** 'n'. We then project 'ran' into the interval [0, lim].  If the result\n** is inside [0, n], we are done. Otherwise, we try with another 'ran',\n** until we have a result inside the interval.\n*/\nstatic lua_Unsigned project (lua_Unsigned ran, lua_Unsigned n,\n                             RanState *state) {\n  if ((n & (n + 1)) == 0)  /* is 'n + 1' a power of 2? */\n    return ran & n;  /* no bias */\n  else {\n    lua_Unsigned lim = n;\n    /* compute the smallest (2^b - 1) not smaller than 'n' */\n    lim |= (lim >> 1);\n    lim |= (lim >> 2);\n    lim |= (lim >> 4);\n    lim |= (lim >> 8);\n    lim |= (lim >> 16);\n#if (LUA_MAXUNSIGNED >> 31) >= 3\n    lim |= (lim >> 32);  /* integer type has more than 32 bits */\n#endif\n    lua_assert((lim & (lim + 1)) == 0  /* 'lim + 1' is a power of 2, */\n      && lim >= n  /* not smaller than 'n', */\n      && (lim >> 1) < n);  /* and it is the smallest one */\n    while ((ran &= lim) > n)  /* project 'ran' into [0..lim] */\n      ran = I2UInt(nextrand(state->s));  /* not inside [0..n]? try again */\n    return ran;\n  }\n}\n\n\nstatic int math_random (lua_State *L) {\n  lua_Integer low, up;\n  lua_Unsigned p;\n  RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1));\n  Rand64 rv = nextrand(state->s);  /* next pseudo-random value */\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, I2d(rv));  /* float between 0 and 1 */\n      return 1;\n    }\n    case 1: {  /* only upper limit */\n      low = 1;\n      up = luaL_checkinteger(L, 1);\n      if (up == 0) {  /* single 0 as argument? */\n        lua_pushinteger(L, I2UInt(rv));  /* full random integer */\n        return 1;\n      }\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      low = luaL_checkinteger(L, 1);\n      up = luaL_checkinteger(L, 2);\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  /* random integer in the interval [low, up] */\n  luaL_argcheck(L, low <= up, 1, \"interval is empty\");\n  /* project random integer into the interval [0, up - low] */\n  p = project(I2UInt(rv), (lua_Unsigned)up - (lua_Unsigned)low, state);\n  lua_pushinteger(L, p + (lua_Unsigned)low);\n  return 1;\n}\n\n\nstatic void setseed (lua_State *L, Rand64 *state,\n                     lua_Unsigned n1, lua_Unsigned n2) {\n  int i;\n  state[0] = Int2I(n1);\n  state[1] = Int2I(0xff);  /* avoid a zero state */\n  state[2] = Int2I(n2);\n  state[3] = Int2I(0);\n  for (i = 0; i < 16; i++)\n    nextrand(state);  /* discard initial values to \"spread\" seed */\n  lua_pushinteger(L, n1);\n  lua_pushinteger(L, n2);\n}\n\n\n/*\n** Set a \"random\" seed. To get some randomness, use the current time\n** and the address of 'L' (in case the machine does address space layout\n** randomization).\n*/\nstatic void randseed (lua_State *L, RanState *state) {\n  lua_Unsigned seed1 = (lua_Unsigned)time(NULL);\n  lua_Unsigned seed2 = (lua_Unsigned)(size_t)L;\n  setseed(L, state->s, seed1, seed2);\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1));\n  if (lua_isnone(L, 1)) {\n    randseed(L, state);\n  }\n  else {\n    lua_Integer n1 = luaL_checkinteger(L, 1);\n    lua_Integer n2 = luaL_optinteger(L, 2, 0);\n    setseed(L, state->s, n1, n2);\n  }\n  return 2;  /* return seeds */\n}\n\n\nstatic const luaL_Reg randfuncs[] = {\n  {\"random\", math_random},\n  {\"randomseed\", math_randomseed},\n  {NULL, NULL}\n};\n\n\n/*\n** Register the random functions and initialize their state.\n*/\nstatic void setrandfunc (lua_State *L) {\n  RanState *state = (RanState *)lua_newuserdatauv(L, sizeof(RanState), 0);\n  randseed(L, state);  /* initialize with a \"random\" seed */\n  lua_pop(L, 2);  /* remove pushed seeds */\n  luaL_setfuncs(L, randfuncs, 1);\n}\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Deprecated functions (for compatibility only)\n** ===================================================================\n*/\n#if defined(LUA_COMPAT_MATHLIB)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  lua_Number y = luaL_checknumber(L, 2);\n  lua_pushnumber(L, l_mathop(pow)(x, y));\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_Number x = luaL_checknumber(L, 1);\n  int ep = (int)luaL_checkinteger(L, 2);\n  lua_pushnumber(L, l_mathop(ldexp)(x, ep));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));\n  return 1;\n}\n\n#endif\n/* }================================================================== */\n\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"tointeger\", math_toint},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"ult\",   math_ult},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"rad\",   math_rad},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tan\",   math_tan},\n  {\"type\", math_type},\n#if defined(LUA_COMPAT_MATHLIB)\n  {\"atan2\", math_atan},\n  {\"cosh\",   math_cosh},\n  {\"sinh\",   math_sinh},\n  {\"tanh\",   math_tanh},\n  {\"pow\",   math_pow},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n#endif\n  /* placeholders */\n  {\"random\", NULL},\n  {\"randomseed\", NULL},\n  {\"pi\", NULL},\n  {\"huge\", NULL},\n  {\"maxinteger\", NULL},\n  {\"mininteger\", NULL},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUAMOD_API int luaopen_math (lua_State *L) {\n  luaL_newlib(L, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, (lua_Number)HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n  lua_pushinteger(L, LUA_MAXINTEGER);\n  lua_setfield(L, -2, \"maxinteger\");\n  lua_pushinteger(L, LUA_MININTEGER);\n  lua_setfield(L, -2, \"mininteger\");\n  setrandfunc(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lmem.c",
    "content": "/*\n** $Id: lmem.c $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#if defined(EMERGENCYGCTESTS)\n/*\n** First allocation will fail whenever not building initial state\n** and not shrinking a block. (This fail will trigger 'tryagain' and\n** a full GC cycle at every allocation.)\n*/\nstatic void *firsttry (global_State *g, void *block, size_t os, size_t ns) {\n  if (ttisnil(&g->nilvalue) && ns > os)\n    return NULL;  /* fail */\n  else  /* normal allocation */\n    return (*g->frealloc)(g->ud, block, os, ns);\n}\n#else\n#define firsttry(g,block,os,ns)    ((*g->frealloc)(g->ud, block, os, ns))\n#endif\n\n\n\n\n\n/*\n** About the realloc function:\n** void *frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** ('osize' is the old size, 'nsize' is the new size)\n**\n** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL.\n** Particularly, frealloc(ud, NULL, 0, 0) does nothing,\n** which is equivalent to free(NULL) in ISO C.\n**\n** - frealloc(ud, NULL, x, s) creates a new block of size 's'\n** (no matter 'x'). Returns NULL if it cannot create the new block.\n**\n** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from\n** size 'x' to size 'y'. Returns NULL if it cannot reallocate the\n** block to the new size.\n*/\n\n\n\n\n/*\n** {==================================================================\n** Functions to allocate/deallocate arrays for the Parser\n** ===================================================================\n*/\n\n/*\n** Minimum size for arrays during parsing, to avoid overhead of\n** reallocating to size 1, then 2, and then 4. All these arrays\n** will be reallocated to exact sizes or erased when parsing ends.\n*/\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,\n                     int size_elems, int limit, const char *what) {\n  void *newblock;\n  int size = *psize;\n  if (nelems + 1 <= size)  /* does one extra element still fit? */\n    return block;  /* nothing to be done */\n  if (size >= limit / 2) {  /* cannot double it? */\n    if (unlikely(size >= limit))  /* cannot grow even a little? */\n      luaG_runerror(L, \"too many %s (limit is %d)\", what, limit);\n    size = limit;  /* still have at least one free place */\n  }\n  else {\n    size *= 2;\n    if (size < MINSIZEARRAY)\n      size = MINSIZEARRAY;  /* minimum size */\n  }\n  lua_assert(nelems + 1 <= size && size <= limit);\n  /* 'limit' ensures that multiplication will not overflow */\n  newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems,\n                                         cast_sizet(size) * size_elems);\n  *psize = size;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\n/*\n** In prototypes, the size of the array is also its number of\n** elements (to save memory). So, if it cannot shrink an array\n** to its number of elements, the only option is to raise an\n** error.\n*/\nvoid *luaM_shrinkvector_ (lua_State *L, void *block, int *size,\n                          int final_n, int size_elem) {\n  void *newblock;\n  size_t oldsize = cast_sizet((*size) * size_elem);\n  size_t newsize = cast_sizet(final_n * size_elem);\n  lua_assert(newsize <= oldsize);\n  newblock = luaM_saferealloc_(L, block, oldsize, newsize);\n  *size = final_n;\n  return newblock;\n}\n\n/* }================================================================== */\n\n\nl_noret luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n}\n\n\n/*\n** Free memory\n*/\nvoid luaM_free_ (lua_State *L, void *block, size_t osize) {\n  global_State *g = G(L);\n  lua_assert((osize == 0) == (block == NULL));\n  (*g->frealloc)(g->ud, block, osize, 0);\n  g->GCdebt -= osize;\n}\n\n\n/*\n** In case of allocation fail, this function will call the GC to try\n** to free some memory and then try the allocation again.\n** (It should not be called when shrinking a block, because then the\n** interpreter may be in the middle of a collection step.)\n*/\nstatic void *tryagain (lua_State *L, void *block,\n                       size_t osize, size_t nsize) {\n  global_State *g = G(L);\n  if (ttisnil(&g->nilvalue)) {  /* is state fully build? */\n    luaC_fullgc(L, 1);  /* try to free some memory... */\n    return (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */\n  }\n  else return NULL;  /* cannot free any memory without a full state */\n}\n\n\n/*\n** Generic allocation routine.\n** If allocation fails while shrinking a block, do not try again; the\n** GC shrinks some blocks and it is not reentrant.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  void *newblock;\n  global_State *g = G(L);\n  lua_assert((osize == 0) == (block == NULL));\n  newblock = firsttry(g, block, osize, nsize);\n  if (unlikely(newblock == NULL && nsize > 0)) {\n    if (nsize > osize)  /* not shrinking a block? */\n      newblock = tryagain(L, block, osize, nsize);\n    if (newblock == NULL)  /* still no memory? */\n      return NULL;  /* do not update 'GCdebt' */\n  }\n  lua_assert((nsize == 0) == (newblock == NULL));\n  g->GCdebt = (g->GCdebt + nsize) - osize;\n  return newblock;\n}\n\n\nvoid *luaM_saferealloc_ (lua_State *L, void *block, size_t osize,\n                                                    size_t nsize) {\n  void *newblock = luaM_realloc_(L, block, osize, nsize);\n  if (unlikely(newblock == NULL && nsize > 0))  /* allocation failed? */\n    luaM_error(L);\n  return newblock;\n}\n\n\nvoid *luaM_malloc_ (lua_State *L, size_t size, int tag) {\n  if (size == 0)\n    return NULL;  /* that's all */\n  else {\n    global_State *g = G(L);\n    void *newblock = firsttry(g, NULL, tag, size);\n    if (unlikely(newblock == NULL)) {\n      newblock = tryagain(L, NULL, tag, size);\n      if (newblock == NULL)\n        luaM_error(L);\n    }\n    g->GCdebt += size;\n    return newblock;\n  }\n}\n"
  },
  {
    "path": "build/lua-5.4.1/src/lmem.h",
    "content": "/*\n** $Id: lmem.h $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n#define luaM_error(L)\tluaD_throw(L, LUA_ERRMEM)\n\n\n/*\n** This macro tests whether it is safe to multiply 'n' by the size of\n** type 't' without overflows. Because 'e' is always constant, it avoids\n** the runtime division MAX_SIZET/(e).\n** (The macro is somewhat complex to avoid warnings:  The 'sizeof'\n** comparison avoids a runtime comparison when overflow cannot occur.\n** The compiler should be able to optimize the real test by itself, but\n** when it does it, it may give a warning about \"comparison is always\n** false due to limited range of data type\"; the +1 tricks the compiler,\n** avoiding this warning but also this optimization.)\n*/\n#define luaM_testsize(n,e)  \\\n\t(sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))\n\n#define luaM_checksize(L,n,e)  \\\n\t(luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))\n\n\n/*\n** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that\n** the result is not larger than 'n' and cannot overflow a 'size_t'\n** when multiplied by the size of type 't'. (Assumes that 'n' is an\n** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.)\n*/\n#define luaM_limitN(n,t)  \\\n  ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) :  \\\n     cast_uint((MAX_SIZET/sizeof(t))))\n\n\n/*\n** Arrays of chars do not need any test\n*/\n#define luaM_reallocvchar(L,b,on,n)  \\\n  cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))\n\n#define luaM_freemem(L, b, s)\tluaM_free_(L, (b), (s))\n#define luaM_free(L, b)\t\tluaM_free_(L, (b), sizeof(*(b)))\n#define luaM_freearray(L, b, n)   luaM_free_(L, (b), (n)*sizeof(*(b)))\n\n#define luaM_new(L,t)\t\tcast(t*, luaM_malloc_(L, sizeof(t), 0))\n#define luaM_newvector(L,n,t)\tcast(t*, luaM_malloc_(L, (n)*sizeof(t), 0))\n#define luaM_newvectorchecked(L,n,t) \\\n  (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t))\n\n#define luaM_newobject(L,tag,s)\tluaM_malloc_(L, (s), tag)\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n\t((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \\\n                         luaM_limitN(limit,t),e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \\\n                                  cast_sizet(n) * sizeof(t))))\n\n#define luaM_shrinkvector(L,v,size,fs,t) \\\n   ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t))))\n\nLUAI_FUNC l_noret luaM_toobig (lua_State *L);\n\n/* not to be called directly */\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize,\n                                                              size_t size);\nLUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems,\n                               int *size, int size_elem, int limit,\n                               const char *what);\nLUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem,\n                                    int final_n, int size_elem);\nLUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag);\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Windows, and a stub for other\n** systems.\n*/\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** LUA_IGMARK is a mark to ignore all before it when building the\n** luaopen_ function name.\n*/\n#if !defined (LUA_IGMARK)\n#define LUA_IGMARK\t\t\"-\"\n#endif\n\n\n/*\n** LUA_CSUBSEP is the character that replaces dots in submodule names\n** when searching for a C loader.\n** LUA_LSUBSEP is the character that replaces dots in submodule names\n** when searching for a Lua loader.\n*/\n#if !defined(LUA_CSUBSEP)\n#define LUA_CSUBSEP\t\tLUA_DIRSEP\n#endif\n\n#if !defined(LUA_LSUBSEP)\n#define LUA_LSUBSEP\t\tLUA_DIRSEP\n#endif\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n/*\n** key for table in the registry that keeps handles\n** for all loaded C libraries\n*/\nstatic const char *const CLIBS = \"_CLIBS\";\n\n#define LIB_FAIL\t\"open\"\n\n\n#define setprogdir(L)           ((void)0)\n\n\n/*\n** Special type equivalent to '(void*)' for functions in gcc\n** (to suppress warnings when converting function pointers)\n*/\ntypedef void (*voidf)(void);\n\n\n/*\n** system-dependent functions\n*/\n\n/*\n** unload library 'lib'\n*/\nstatic void lsys_unloadlib (void *lib);\n\n/*\n** load C library in file 'path'. If 'seeglb', load with all names in\n** the library global.\n** Returns the library; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb);\n\n/*\n** Try to find a function named 'sym' in library 'lib'.\n** Returns the function; in case of error, returns NULL plus an\n** error string in the stack.\n*/\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n\n#if defined(LUA_USE_DLOPEN)\t/* { */\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\n/*\n** Macro to convert pointer-to-void* to pointer-to-function. This cast\n** is undefined according to ISO C, but POSIX assumes that it works.\n** (The '__extension__' in gnu compilers is only to avoid warnings.)\n*/\n#if defined(__GNUC__)\n#define cast_func(p) (__extension__ (lua_CFunction)(p))\n#else\n#define cast_func(p) ((lua_CFunction)(p))\n#endif\n\n\nstatic void lsys_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = cast_func(dlsym(lib, sym));\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\t/* }{ */\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n/*\n** optional flags for LoadLibraryEx\n*/\n#if !defined(LUA_LLE_FLAGS)\n#define LUA_LLE_FLAGS\t0\n#endif\n\n\n#undef setprogdir\n\n\n/*\n** Replace in the path (on the top of the stack) any occurrence\n** of LUA_EXEC_DIR with the executable's path.\n*/\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);  /* get exec. name */\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';  /* cut name on the last '\\\\' to get the path */\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void lsys_unloadlib (void *lib) {\n  FreeLibrary((HMODULE)lib);\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);\n  (void)(seeglb);  /* not used: symbols are 'global' by default */\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)(voidf)GetProcAddress((HMODULE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n#else\t\t\t\t/* }{ */\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void lsys_unloadlib (void *lib) {\n  (void)(lib);  /* not used */\n}\n\n\nstatic void *lsys_load (lua_State *L, const char *path, int seeglb) {\n  (void)(path); (void)(seeglb);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {\n  (void)(lib); (void)(sym);  /* not used */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\t\t\t\t/* } */\n\n\n/*\n** {==================================================================\n** Set Paths\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment\n** variables that Lua check to set its paths.\n*/\n#if !defined(LUA_PATH_VAR)\n#define LUA_PATH_VAR    \"LUA_PATH\"\n#endif\n\n#if !defined(LUA_CPATH_VAR)\n#define LUA_CPATH_VAR   \"LUA_CPATH\"\n#endif\n\n\n\n/*\n** return registry.LUA_NOENV as a boolean\n*/\nstatic int noenv (lua_State *L) {\n  int b;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  b = lua_toboolean(L, -1);\n  lua_pop(L, 1);  /* remove value */\n  return b;\n}\n\n\n/*\n** Set a path\n*/\nstatic void setpath (lua_State *L, const char *fieldname,\n                                   const char *envname,\n                                   const char *dft) {\n  const char *dftmark;\n  const char *nver = lua_pushfstring(L, \"%s%s\", envname, LUA_VERSUFFIX);\n#if defined(WINAPI_FAMILY_PARTITION)\n  const char *path = NULL;\n#else\n  const char *path = getenv(nver);  /* try versioned name */\n  if (path == NULL)  /* no versioned environment variable? */\n    path = getenv(envname);  /* try unversioned name */\n#endif\n  if (path == NULL || noenv(L))  /* no environment variable? */\n    lua_pushstring(L, dft);  /* use default */\n  else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL)\n    lua_pushstring(L, path);  /* nothing to change */\n  else {  /* path contains a \";;\": insert default path in its place */\n    size_t len = strlen(path);\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    if (path < dftmark) {  /* is there a prefix before ';;'? */\n      luaL_addlstring(&b, path, dftmark - path);  /* add it */\n      luaL_addchar(&b, *LUA_PATH_SEP);\n    }\n    luaL_addstring(&b, dft);  /* add default */\n    if (dftmark < path + len - 2) {  /* is there a suffix after ';;'? */\n      luaL_addchar(&b, *LUA_PATH_SEP);\n      luaL_addlstring(&b, dftmark + 2, (path + len - 2) - dftmark);\n    }\n    luaL_pushresult(&b);\n  }\n  setprogdir(L);\n  lua_setfield(L, -3, fieldname);  /* package[fieldname] = path value */\n  lua_pop(L, 1);  /* pop versioned variable name ('nver') */\n}\n\n/* }================================================================== */\n\n\n/*\n** return registry.CLIBS[path]\n*/\nstatic void *checkclib (lua_State *L, const char *path) {\n  void *plib;\n  lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);\n  lua_getfield(L, -1, path);\n  plib = lua_touserdata(L, -1);  /* plib = CLIBS[path] */\n  lua_pop(L, 2);  /* pop CLIBS table and 'plib' */\n  return plib;\n}\n\n\n/*\n** registry.CLIBS[path] = plib        -- for queries\n** registry.CLIBS[#CLIBS + 1] = plib  -- also keep a list of all libraries\n*/\nstatic void addtoclib (lua_State *L, const char *path, void *plib) {\n  lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);\n  lua_pushlightuserdata(L, plib);\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, path);  /* CLIBS[path] = plib */\n  lua_rawseti(L, -2, luaL_len(L, -2) + 1);  /* CLIBS[#CLIBS + 1] = plib */\n  lua_pop(L, 1);  /* pop CLIBS table */\n}\n\n\n/*\n** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib\n** handles in list CLIBS\n*/\nstatic int gctm (lua_State *L) {\n  lua_Integer n = luaL_len(L, 1);\n  for (; n >= 1; n--) {  /* for each handle, in reverse order */\n    lua_rawgeti(L, 1, n);  /* get handle CLIBS[n] */\n    lsys_unloadlib(lua_touserdata(L, -1));\n    lua_pop(L, 1);  /* pop handle */\n  }\n  return 0;\n}\n\n\n\n/* error codes for 'lookforfunc' */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n/*\n** Look for a C function named 'sym' in a dynamically loaded library\n** 'path'.\n** First, check whether the library is already loaded; if not, try\n** to load it.\n** Then, if 'sym' is '*', return true (as library has been loaded).\n** Otherwise, look for symbol 'sym' in the library and push a\n** C function with that symbol.\n** Return 0 and 'true' or a function in the stack; in case of\n** errors, return an error code and an error message in the stack.\n*/\nstatic int lookforfunc (lua_State *L, const char *path, const char *sym) {\n  void *reg = checkclib(L, path);  /* check loaded C libraries */\n  if (reg == NULL) {  /* must load library? */\n    reg = lsys_load(L, path, *sym == '*');  /* global symbols if 'sym'=='*' */\n    if (reg == NULL) return ERRLIB;  /* unable to load library */\n    addtoclib(L, path, reg);\n  }\n  if (*sym == '*') {  /* loading only library (no function)? */\n    lua_pushboolean(L, 1);  /* return 'true' */\n    return 0;  /* no errors */\n  }\n  else {\n    lua_CFunction f = lsys_sym(L, reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);  /* else create new function */\n    return 0;  /* no errors */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = lookforfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    luaL_pushfail(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return fail, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\n/*\n** Get the next name in '*path' = 'name1;name2;name3;...', changing\n** the ending ';' to '\\0' to create a zero-terminated string. Return\n** NULL when list ends.\n*/\nstatic const char *getnextfilename (char **path, char *end) {\n  char *sep;\n  char *name = *path;\n  if (name == end)\n    return NULL;  /* no more names */\n  else if (*name == '\\0') {  /* from previous iteration? */\n    *name = *LUA_PATH_SEP;  /* restore separator */\n    name++;  /* skip it */\n  }\n  sep = strchr(name, *LUA_PATH_SEP);  /* find next separator */\n  if (sep == NULL)  /* separator not found? */\n    sep = end;  /* name goes until the end */\n  *sep = '\\0';  /* finish file name */\n  *path = sep;  /* will start next search from here */\n  return name;\n}\n\n\n/*\n** Given a path such as \";blabla.so;blublu.so\", pushes the string\n**\n** no file 'blabla.so'\n**\tno file 'blublu.so'\n*/\nstatic void pusherrornotfound (lua_State *L, const char *path) {\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  luaL_addstring(&b, \"no file '\");\n  luaL_addgsub(&b, path, LUA_PATH_SEP, \"'\\n\\tno file '\");\n  luaL_addstring(&b, \"'\");\n  luaL_pushresult(&b);\n}\n\n\nstatic const char *searchpath (lua_State *L, const char *name,\n                                             const char *path,\n                                             const char *sep,\n                                             const char *dirsep) {\n  luaL_Buffer buff;\n  char *pathname;  /* path with name inserted */\n  char *endpathname;  /* its end */\n  const char *filename;\n  /* separator is non-empty and appears in 'name'? */\n  if (*sep != '\\0' && strchr(name, *sep) != NULL)\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  luaL_buffinit(L, &buff);\n  /* add path to the buffer, replacing marks ('?') with the file name */\n  luaL_addgsub(&buff, path, LUA_PATH_MARK, name);\n  luaL_addchar(&buff, '\\0');\n  pathname = luaL_buffaddr(&buff);  /* writable list of file names */\n  endpathname = pathname + luaL_bufflen(&buff) - 1;\n  while ((filename = getnextfilename(&pathname, endpathname)) != NULL) {\n    if (readable(filename))  /* does file exist and is readable? */\n      return lua_pushstring(L, filename);  /* save and return name */\n  }\n  luaL_pushresult(&buff);  /* push path to create error message */\n  pusherrornotfound(L, lua_tostring(L, -1));  /* create error message */\n  return NULL;  /* not found */\n}\n\n\nstatic int ll_searchpath (lua_State *L) {\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n                                luaL_checkstring(L, 2),\n                                luaL_optstring(L, 3, \".\"),\n                                luaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) return 1;\n  else {  /* error message is on top of the stack */\n    luaL_pushfail(L);\n    lua_insert(L, -2);\n    return 2;  /* return fail + error message */\n  }\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname,\n                                           const char *dirsep) {\n  const char *path;\n  lua_getfield(L, lua_upvalueindex(1), pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, \"'package.%s' must be a string\", pname);\n  return searchpath(L, name, path, \".\", dirsep);\n}\n\n\nstatic int checkload (lua_State *L, int stat, const char *filename) {\n  if (stat) {  /* module loaded successfully? */\n    lua_pushstring(L, filename);  /* will be 2nd argument to module */\n    return 2;  /* return open function and file name */\n  }\n  else\n    return luaL_error(L, \"error loading module '%s' from file '%s':\\n\\t%s\",\n                          lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int searcher_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\", LUA_LSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename);\n}\n\n\n/*\n** Try to find a load function for module 'modname' at file 'filename'.\n** First, change '.' to '_' in 'modname'; then, if 'modname' has\n** the form X-Y (that is, it has an \"ignore mark\"), build a function\n** name \"luaopen_X\" and look for it. (For compatibility, if that\n** fails, it also tries \"luaopen_Y\".) If there is no ignore mark,\n** look for a function named \"luaopen_modname\".\n*/\nstatic int loadfunc (lua_State *L, const char *filename, const char *modname) {\n  const char *openfunc;\n  const char *mark;\n  modname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  mark = strchr(modname, *LUA_IGMARK);\n  if (mark) {\n    int stat;\n    openfunc = lua_pushlstring(L, modname, mark - modname);\n    openfunc = lua_pushfstring(L, LUA_POF\"%s\", openfunc);\n    stat = lookforfunc(L, filename, openfunc);\n    if (stat != ERRFUNC) return stat;\n    modname = mark + 1;  /* else go ahead and try old-style name */\n  }\n  openfunc = lua_pushfstring(L, LUA_POF\"%s\", modname);\n  return lookforfunc(L, filename, openfunc);\n}\n\n\nstatic int searcher_C (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* module not found in this path */\n  return checkload(L, (loadfunc(L, filename, name) == 0), filename);\n}\n\n\nstatic int searcher_Croot (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\", LUA_CSUBSEP);\n  if (filename == NULL) return 1;  /* root not found */\n  if ((stat = loadfunc(L, filename, name)) != 0) {\n    if (stat != ERRFUNC)\n      return checkload(L, 0, filename);  /* real error */\n    else {  /* open function not found */\n      lua_pushfstring(L, \"no module '%s' in file '%s'\", name, filename);\n      return 1;\n    }\n  }\n  lua_pushstring(L, filename);  /* will be 2nd argument to module */\n  return 2;\n}\n\n\nstatic int searcher_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  if (lua_getfield(L, -1, name) == LUA_TNIL) {  /* not found? */\n    lua_pushfstring(L, \"no field package.preload['%s']\", name);\n    return 1;\n  }\n  else {\n    lua_pushliteral(L, \":preload:\");\n    return 2;\n  }\n}\n\n\nstatic void findloader (lua_State *L, const char *name) {\n  int i;\n  luaL_Buffer msg;  /* to build error message */\n  /* push 'package.searchers' to index 3 in the stack */\n  if (lua_getfield(L, lua_upvalueindex(1), \"searchers\") != LUA_TTABLE)\n    luaL_error(L, \"'package.searchers' must be a table\");\n  luaL_buffinit(L, &msg);\n  /*  iterate over available searchers to find a loader */\n  for (i = 1; ; i++) {\n    luaL_addstring(&msg, \"\\n\\t\");  /* error-message prefix */\n    if (lua_rawgeti(L, 3, i) == LUA_TNIL) {  /* no more searchers? */\n      lua_pop(L, 1);  /* remove nil */\n      luaL_buffsub(&msg, 2);  /* remove prefix */\n      luaL_pushresult(&msg);  /* create error message */\n      luaL_error(L, \"module '%s' not found:%s\", name, lua_tostring(L, -1));\n    }\n    lua_pushstring(L, name);\n    lua_call(L, 1, 2);  /* call it */\n    if (lua_isfunction(L, -2))  /* did it find a loader? */\n      return;  /* module loader found */\n    else if (lua_isstring(L, -2)) {  /* searcher returned error message? */\n      lua_pop(L, 1);  /* remove extra return */\n      luaL_addvalue(&msg);  /* concatenate error message */\n    }\n    else {  /* no error message */\n      lua_pop(L, 2);  /* remove both returns */\n      luaL_buffsub(&msg, 2);  /* remove prefix */\n    }\n  }\n}\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_settop(L, 1);  /* LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_getfield(L, 2, name);  /* LOADED[name] */\n  if (lua_toboolean(L, -1))  /* is it there? */\n    return 1;  /* package is already loaded */\n  /* else must load package */\n  lua_pop(L, 1);  /* remove 'getfield' result */\n  findloader(L, name);\n  lua_rotate(L, -2, 1);  /* function <-> loader data */\n  lua_pushvalue(L, 1);  /* name is 1st argument to module loader */\n  lua_pushvalue(L, -3);  /* loader data is 2nd argument */\n  /* stack: ...; loader data; loader function; mod. name; loader data */\n  lua_call(L, 2, 1);  /* run loader to load module */\n  /* stack: ...; loader data; result from loader */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* LOADED[name] = returned value */\n  else\n    lua_pop(L, 1);  /* pop nil */\n  if (lua_getfield(L, 2, name) == LUA_TNIL) {   /* module set no value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_copy(L, -1, -2);  /* replace loader result */\n    lua_setfield(L, 2, name);  /* LOADED[name] = true */\n  }\n  lua_rotate(L, -2, 1);  /* loader data <-> module result  */\n  return 2;  /* return module result and loader data */\n}\n\n/* }====================================================== */\n\n\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"searchpath\", ll_searchpath},\n  /* placeholders */\n  {\"preload\", NULL},\n  {\"cpath\", NULL},\n  {\"path\", NULL},\n  {\"searchers\", NULL},\n  {\"loaded\", NULL},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic void createsearcherstable (lua_State *L) {\n  static const lua_CFunction searchers[] =\n    {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};\n  int i;\n  /* create 'searchers' table */\n  lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);\n  /* fill it with predefined searchers */\n  for (i=0; searchers[i] != NULL; i++) {\n    lua_pushvalue(L, -2);  /* set 'package' as upvalue for all searchers */\n    lua_pushcclosure(L, searchers[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n  lua_setfield(L, -2, \"searchers\");  /* put it in field 'searchers' */\n}\n\n\n/*\n** create table CLIBS to keep track of loaded C libraries,\n** setting a finalizer to close all libraries when closing state.\n*/\nstatic void createclibstable (lua_State *L) {\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);  /* create CLIBS table */\n  lua_createtable(L, 0, 1);  /* create metatable for CLIBS */\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");  /* set finalizer for CLIBS table */\n  lua_setmetatable(L, -2);\n}\n\n\nLUAMOD_API int luaopen_package (lua_State *L) {\n  createclibstable(L);\n  luaL_newlib(L, pk_funcs);  /* create 'package' table */\n  createsearcherstable(L);\n  /* set paths */\n  setpath(L, \"path\", LUA_PATH_VAR, LUA_PATH_DEFAULT);\n  setpath(L, \"cpath\", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATH_SEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXEC_DIR \"\\n\" LUA_IGMARK \"\\n\");\n  lua_setfield(L, -2, \"config\");\n  /* set field 'loaded' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field 'preload' */\n  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushglobaltable(L);\n  lua_pushvalue(L, -2);  /* set 'package' as upvalue for next lib */\n  luaL_setfuncs(L, ll_funcs, 1);  /* open lib into global table */\n  lua_pop(L, 1);  /* pop global table */\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lobject.c",
    "content": "/*\n** $Id: lobject.c $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <locale.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lctype.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n/*\n** Computes ceil(log2(x))\n*/\nint luaO_ceillog2 (unsigned int x) {\n  static const lu_byte log_2[256] = {  /* log_2[i] = ceil(log2(i - 1)) */\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = 0;\n  x--;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n}\n\n\nstatic lua_Integer intarith (lua_State *L, int op, lua_Integer v1,\n                                                   lua_Integer v2) {\n  switch (op) {\n    case LUA_OPADD: return intop(+, v1, v2);\n    case LUA_OPSUB:return intop(-, v1, v2);\n    case LUA_OPMUL:return intop(*, v1, v2);\n    case LUA_OPMOD: return luaV_mod(L, v1, v2);\n    case LUA_OPIDIV: return luaV_idiv(L, v1, v2);\n    case LUA_OPBAND: return intop(&, v1, v2);\n    case LUA_OPBOR: return intop(|, v1, v2);\n    case LUA_OPBXOR: return intop(^, v1, v2);\n    case LUA_OPSHL: return luaV_shiftl(v1, v2);\n    case LUA_OPSHR: return luaV_shiftl(v1, -v2);\n    case LUA_OPUNM: return intop(-, 0, v1);\n    case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic lua_Number numarith (lua_State *L, int op, lua_Number v1,\n                                                  lua_Number v2) {\n  switch (op) {\n    case LUA_OPADD: return luai_numadd(L, v1, v2);\n    case LUA_OPSUB: return luai_numsub(L, v1, v2);\n    case LUA_OPMUL: return luai_nummul(L, v1, v2);\n    case LUA_OPDIV: return luai_numdiv(L, v1, v2);\n    case LUA_OPPOW: return luai_numpow(L, v1, v2);\n    case LUA_OPIDIV: return luai_numidiv(L, v1, v2);\n    case LUA_OPUNM: return luai_numunm(L, v1);\n    case LUA_OPMOD: return luaV_modf(L, v1, v2);\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nint luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                   TValue *res) {\n  switch (op) {\n    case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:\n    case LUA_OPSHL: case LUA_OPSHR:\n    case LUA_OPBNOT: {  /* operate only on integers */\n      lua_Integer i1; lua_Integer i2;\n      if (tointegerns(p1, &i1) && tointegerns(p2, &i2)) {\n        setivalue(res, intarith(L, op, i1, i2));\n        return 1;\n      }\n      else return 0;  /* fail */\n    }\n    case LUA_OPDIV: case LUA_OPPOW: {  /* operate only on floats */\n      lua_Number n1; lua_Number n2;\n      if (tonumberns(p1, n1) && tonumberns(p2, n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return 1;\n      }\n      else return 0;  /* fail */\n    }\n    default: {  /* other operations */\n      lua_Number n1; lua_Number n2;\n      if (ttisinteger(p1) && ttisinteger(p2)) {\n        setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));\n        return 1;\n      }\n      else if (tonumberns(p1, n1) && tonumberns(p2, n2)) {\n        setfltvalue(res, numarith(L, op, n1, n2));\n        return 1;\n      }\n      else return 0;  /* fail */\n    }\n  }\n}\n\n\nvoid luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,\n                 StkId res) {\n  if (!luaO_rawarith(L, op, p1, p2, s2v(res))) {\n    /* could not perform raw operation; try metamethod */\n    luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));\n  }\n}\n\n\nint luaO_hexavalue (int c) {\n  if (lisdigit(c)) return c - '0';\n  else return (ltolower(c) - 'a') + 10;\n}\n\n\nstatic int isneg (const char **s) {\n  if (**s == '-') { (*s)++; return 1; }\n  else if (**s == '+') (*s)++;\n  return 0;\n}\n\n\n\n/*\n** {==================================================================\n** Lua's implementation for 'lua_strx2number'\n** ===================================================================\n*/\n\n#if !defined(lua_strx2number)\n\n/* maximum number of significant digits to read (to avoid overflows\n   even with single floats) */\n#define MAXSIGDIG\t30\n\n/*\n** convert a hexadecimal numeric string to a number, following\n** C99 specification for 'strtod'\n*/\nstatic lua_Number lua_strx2number (const char *s, char **endptr) {\n  int dot = lua_getlocaledecpoint();\n  lua_Number r = 0.0;  /* result (accumulator) */\n  int sigdig = 0;  /* number of significant digits */\n  int nosigdig = 0;  /* number of non-significant digits */\n  int e = 0;  /* exponent correction */\n  int neg;  /* 1 if number is negative */\n  int hasdot = 0;  /* true after seen a dot */\n  *endptr = cast_charp(s);  /* nothing is valid yet */\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);  /* check sign */\n  if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */\n    return 0.0;  /* invalid format (no '0x') */\n  for (s += 2; ; s++) {  /* skip '0x' and read numeral */\n    if (*s == dot) {\n      if (hasdot) break;  /* second dot? stop loop */\n      else hasdot = 1;\n    }\n    else if (lisxdigit(cast_uchar(*s))) {\n      if (sigdig == 0 && *s == '0')  /* non-significant digit (zero)? */\n        nosigdig++;\n      else if (++sigdig <= MAXSIGDIG)  /* can read it without overflow? */\n          r = (r * cast_num(16.0)) + luaO_hexavalue(*s);\n      else e++; /* too many digits; ignore, but still count for exponent */\n      if (hasdot) e--;  /* decimal digit? correct exponent */\n    }\n    else break;  /* neither a dot nor a digit */\n  }\n  if (nosigdig + sigdig == 0)  /* no digits? */\n    return 0.0;  /* invalid format */\n  *endptr = cast_charp(s);  /* valid up to here */\n  e *= 4;  /* each digit multiplies/divides value by 2^4 */\n  if (*s == 'p' || *s == 'P') {  /* exponent part? */\n    int exp1 = 0;  /* exponent value */\n    int neg1;  /* exponent sign */\n    s++;  /* skip 'p' */\n    neg1 = isneg(&s);  /* sign */\n    if (!lisdigit(cast_uchar(*s)))\n      return 0.0;  /* invalid; must have at least one digit */\n    while (lisdigit(cast_uchar(*s)))  /* read exponent */\n      exp1 = exp1 * 10 + *(s++) - '0';\n    if (neg1) exp1 = -exp1;\n    e += exp1;\n    *endptr = cast_charp(s);  /* valid up to here */\n  }\n  if (neg) r = -r;\n  return l_mathop(ldexp)(r, e);\n}\n\n#endif\n/* }====================================================== */\n\n\n/* maximum length of a numeral to be converted to a number */\n#if !defined (L_MAXLENNUM)\n#define L_MAXLENNUM\t200\n#endif\n\n/*\n** Convert string 's' to a Lua number (put in 'result'). Return NULL on\n** fail or the address of the ending '\\0' on success. ('mode' == 'x')\n** means a hexadecimal numeral.\n*/\nstatic const char *l_str2dloc (const char *s, lua_Number *result, int mode) {\n  char *endptr;\n  *result = (mode == 'x') ? lua_strx2number(s, &endptr)  /* try to convert */\n                          : lua_str2number(s, &endptr);\n  if (endptr == s) return NULL;  /* nothing recognized? */\n  while (lisspace(cast_uchar(*endptr))) endptr++;  /* skip trailing spaces */\n  return (*endptr == '\\0') ? endptr : NULL;  /* OK iff no trailing chars */\n}\n\n\n/*\n** Convert string 's' to a Lua number (put in 'result') handling the\n** current locale.\n** This function accepts both the current locale or a dot as the radix\n** mark. If the conversion fails, it may mean number has a dot but\n** locale accepts something else. In that case, the code copies 's'\n** to a buffer (because 's' is read-only), changes the dot to the\n** current locale radix mark, and tries to convert again.\n** The variable 'mode' checks for special characters in the string:\n** - 'n' means 'inf' or 'nan' (which should be rejected)\n** - 'x' means a hexadecimal numeral\n** - '.' just optimizes the search for the common case (no special chars)\n*/\nstatic const char *l_str2d (const char *s, lua_Number *result) {\n  const char *endptr;\n  const char *pmode = strpbrk(s, \".xXnN\");  /* look for special chars */\n  int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;\n  if (mode == 'n')  /* reject 'inf' and 'nan' */\n    return NULL;\n  endptr = l_str2dloc(s, result, mode);  /* try to convert */\n  if (endptr == NULL) {  /* failed? may be a different locale */\n    char buff[L_MAXLENNUM + 1];\n    const char *pdot = strchr(s, '.');\n    if (strlen(s) > L_MAXLENNUM || pdot == NULL)\n      return NULL;  /* string too long or no dot; fail */\n    strcpy(buff, s);  /* copy string to buffer */\n    buff[pdot - s] = lua_getlocaledecpoint();  /* correct decimal point */\n    endptr = l_str2dloc(buff, result, mode);  /* try again */\n    if (endptr != NULL)\n      endptr = s + (endptr - buff);  /* make relative to 's' */\n  }\n  return endptr;\n}\n\n\n#define MAXBY10\t\tcast(lua_Unsigned, LUA_MAXINTEGER / 10)\n#define MAXLASTD\tcast_int(LUA_MAXINTEGER % 10)\n\nstatic const char *l_str2int (const char *s, lua_Integer *result) {\n  lua_Unsigned a = 0;\n  int empty = 1;\n  int neg;\n  while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */\n  neg = isneg(&s);\n  if (s[0] == '0' &&\n      (s[1] == 'x' || s[1] == 'X')) {  /* hex? */\n    s += 2;  /* skip '0x' */\n    for (; lisxdigit(cast_uchar(*s)); s++) {\n      a = a * 16 + luaO_hexavalue(*s);\n      empty = 0;\n    }\n  }\n  else {  /* decimal */\n    for (; lisdigit(cast_uchar(*s)); s++) {\n      int d = *s - '0';\n      if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg))  /* overflow? */\n        return NULL;  /* do not accept it (as integer) */\n      a = a * 10 + d;\n      empty = 0;\n    }\n  }\n  while (lisspace(cast_uchar(*s))) s++;  /* skip trailing spaces */\n  if (empty || *s != '\\0') return NULL;  /* something wrong in the numeral */\n  else {\n    *result = l_castU2S((neg) ? 0u - a : a);\n    return s;\n  }\n}\n\n\nsize_t luaO_str2num (const char *s, TValue *o) {\n  lua_Integer i; lua_Number n;\n  const char *e;\n  if ((e = l_str2int(s, &i)) != NULL) {  /* try as an integer */\n    setivalue(o, i);\n  }\n  else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */\n    setfltvalue(o, n);\n  }\n  else\n    return 0;  /* conversion failed */\n  return (e - s) + 1;  /* success; return string size */\n}\n\n\nint luaO_utf8esc (char *buff, unsigned long x) {\n  int n = 1;  /* number of bytes put in buffer (backwards) */\n  lua_assert(x <= 0x7FFFFFFFu);\n  if (x < 0x80)  /* ascii? */\n    buff[UTF8BUFFSZ - 1] = cast_char(x);\n  else {  /* need continuation bytes */\n    unsigned int mfb = 0x3f;  /* maximum that fits in first byte */\n    do {  /* add continuation bytes */\n      buff[UTF8BUFFSZ - (n++)] = cast_char(0x80 | (x & 0x3f));\n      x >>= 6;  /* remove added bits */\n      mfb >>= 1;  /* now there is one less bit available in first byte */\n    } while (x > mfb);  /* still needs continuation byte? */\n    buff[UTF8BUFFSZ - n] = cast_char((~mfb << 1) | x);  /* add first byte */\n  }\n  return n;\n}\n\n\n/*\n** Maximum length of the conversion of a number to a string. Must be\n** enough to accommodate both LUA_INTEGER_FMT and LUA_NUMBER_FMT.\n** (For a long long int, this is 19 digits plus a sign and a final '\\0',\n** adding to 21. For a long double, it can go to a sign, 33 digits,\n** the dot, an exponent letter, an exponent sign, 5 exponent digits,\n** and a final '\\0', adding to 43.)\n*/\n#define MAXNUMBER2STR\t44\n\n\n/*\n** Convert a number object to a string, adding it to a buffer\n*/\nstatic int tostringbuff (TValue *obj, char *buff) {\n  int len;\n  lua_assert(ttisnumber(obj));\n  if (ttisinteger(obj))\n    len = lua_integer2str(buff, MAXNUMBER2STR, ivalue(obj));\n  else {\n    len = lua_number2str(buff, MAXNUMBER2STR, fltvalue(obj));\n    if (buff[strspn(buff, \"-0123456789\")] == '\\0') {  /* looks like an int? */\n      buff[len++] = lua_getlocaledecpoint();\n      buff[len++] = '0';  /* adds '.0' to result */\n    }\n  }\n  return len;\n}\n\n\n/*\n** Convert a number object to a Lua string, replacing the value at 'obj'\n*/\nvoid luaO_tostring (lua_State *L, TValue *obj) {\n  char buff[MAXNUMBER2STR];\n  int len = tostringbuff(obj, buff);\n  setsvalue(L, obj, luaS_newlstr(L, buff, len));\n}\n\n\n\n\n/*\n** {==================================================================\n** 'luaO_pushvfstring'\n** ===================================================================\n*/\n\n/* size for buffer space used by 'luaO_pushvfstring' */\n#define BUFVFS\t\t200\n\n/* buffer used by 'luaO_pushvfstring' */\ntypedef struct BuffFS {\n  lua_State *L;\n  int pushed;  /* number of string pieces already on the stack */\n  int blen;  /* length of partial string in 'space' */\n  char space[BUFVFS];  /* holds last part of the result */\n} BuffFS;\n\n\n/*\n** Push given string to the stack, as part of the buffer, and\n** join the partial strings in the stack into one.\n*/\nstatic void pushstr (BuffFS *buff, const char *str, size_t l) {\n  lua_State *L = buff->L;\n  setsvalue2s(L, L->top, luaS_newlstr(L, str, l));\n  L->top++;  /* may use one extra slot */\n  buff->pushed++;\n  luaV_concat(L, buff->pushed);  /* join partial results into one */\n  buff->pushed = 1;\n}\n\n\n/*\n** empty the buffer space into the stack\n*/\nstatic void clearbuff (BuffFS *buff) {\n  pushstr(buff, buff->space, buff->blen);  /* push buffer contents */\n  buff->blen = 0;  /* space now is empty */\n}\n\n\n/*\n** Get a space of size 'sz' in the buffer. If buffer has not enough\n** space, empty it. 'sz' must fit in an empty buffer.\n*/\nstatic char *getbuff (BuffFS *buff, int sz) {\n  lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS);\n  if (sz > BUFVFS - buff->blen)  /* not enough space? */\n    clearbuff(buff);\n  return buff->space + buff->blen;\n}\n\n\n#define addsize(b,sz)\t((b)->blen += (sz))\n\n\n/*\n** Add 'str' to the buffer. If string is larger than the buffer space,\n** push the string directly to the stack.\n*/\nstatic void addstr2buff (BuffFS *buff, const char *str, size_t slen) {\n  if (slen <= BUFVFS) {  /* does string fit into buffer? */\n    char *bf = getbuff(buff, cast_int(slen));\n    memcpy(bf, str, slen);  /* add string to buffer */\n    addsize(buff, cast_int(slen));\n  }\n  else {  /* string larger than buffer */\n    clearbuff(buff);  /* string comes after buffer's content */\n    pushstr(buff, str, slen);  /* push string */\n  }\n}\n\n\n/*\n** Add a number to the buffer.\n*/\nstatic void addnum2buff (BuffFS *buff, TValue *num) {\n  char *numbuff = getbuff(buff, MAXNUMBER2STR);\n  int len = tostringbuff(num, numbuff);  /* format number into 'numbuff' */\n  addsize(buff, len);\n}\n\n\n/*\n** this function handles only '%d', '%c', '%f', '%p', '%s', and '%%'\n   conventional formats, plus Lua-specific '%I' and '%U'\n*/\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  BuffFS buff;  /* holds last part of the result */\n  const char *e;  /* points to next '%' */\n  buff.pushed = buff.blen = 0;\n  buff.L = L;\n  while ((e = strchr(fmt, '%')) != NULL) {\n    addstr2buff(&buff, fmt, e - fmt);  /* add 'fmt' up to '%' */\n    switch (*(e + 1)) {  /* conversion specifier */\n      case 's': {  /* zero-terminated string */\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        addstr2buff(&buff, s, strlen(s));\n        break;\n      }\n      case 'c': {  /* an 'int' as a character */\n        char c = cast_uchar(va_arg(argp, int));\n        addstr2buff(&buff, &c, sizeof(char));\n        break;\n      }\n      case 'd': {  /* an 'int' */\n        TValue num;\n        setivalue(&num, va_arg(argp, int));\n        addnum2buff(&buff, &num);\n        break;\n      }\n      case 'I': {  /* a 'lua_Integer' */\n        TValue num;\n        setivalue(&num, cast(lua_Integer, va_arg(argp, l_uacInt)));\n        addnum2buff(&buff, &num);\n        break;\n      }\n      case 'f': {  /* a 'lua_Number' */\n        TValue num;\n        setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber)));\n        addnum2buff(&buff, &num);\n        break;\n      }\n      case 'p': {  /* a pointer */\n        const int sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */\n        char *bf = getbuff(&buff, sz);\n        void *p = va_arg(argp, void *);\n        int len = lua_pointer2str(bf, sz, p);\n        addsize(&buff, len);\n        break;\n      }\n      case 'U': {  /* a 'long' as a UTF-8 sequence */\n        char bf[UTF8BUFFSZ];\n        int len = luaO_utf8esc(bf, va_arg(argp, long));\n        addstr2buff(&buff, bf + UTF8BUFFSZ - len, len);\n        break;\n      }\n      case '%': {\n        addstr2buff(&buff, \"%\", 1);\n        break;\n      }\n      default: {\n        luaG_runerror(L, \"invalid option '%%%c' to 'lua_pushfstring'\",\n                         *(e + 1));\n      }\n    }\n    fmt = e + 2;  /* skip '%' and the specifier */\n  }\n  addstr2buff(&buff, fmt, strlen(fmt));  /* rest of 'fmt' */\n  clearbuff(&buff);  /* empty buffer into the stack */\n  lua_assert(buff.pushed == 1);\n  return svalue(s2v(L->top - 1));\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n/* }================================================================== */\n\n\n#define RETS\t\"...\"\n#define PRE\t\"[string \\\"\"\n#define POS\t\"\\\"]\"\n\n#define addstr(a,b,l)\t( memcpy(a,b,(l) * sizeof(char)), a += (l) )\n\nvoid luaO_chunkid (char *out, const char *source, size_t srclen) {\n  size_t bufflen = LUA_IDSIZE;  /* free space in buffer */\n  if (*source == '=') {  /* 'literal' source */\n    if (srclen <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, srclen * sizeof(char));\n    else {  /* truncate it */\n      addstr(out, source + 1, bufflen - 1);\n      *out = '\\0';\n    }\n  }\n  else if (*source == '@') {  /* file name */\n    if (srclen <= bufflen)  /* small enough? */\n      memcpy(out, source + 1, srclen * sizeof(char));\n    else {  /* add '...' before rest of name */\n      addstr(out, RETS, LL(RETS));\n      bufflen -= LL(RETS);\n      memcpy(out, source + 1 + srclen - bufflen, bufflen * sizeof(char));\n    }\n  }\n  else {  /* string; format as [string \"source\"] */\n    const char *nl = strchr(source, '\\n');  /* find first new line (if any) */\n    addstr(out, PRE, LL(PRE));  /* add prefix */\n    bufflen -= LL(PRE RETS POS) + 1;  /* save space for prefix+suffix+'\\0' */\n    if (srclen < bufflen && nl == NULL) {  /* small one-line source? */\n      addstr(out, source, srclen);  /* keep it */\n    }\n    else {\n      if (nl != NULL) srclen = nl - source;  /* stop at first newline */\n      if (srclen > bufflen) srclen = bufflen;\n      addstr(out, source, srclen);\n      addstr(out, RETS, LL(RETS));\n    }\n    memcpy(out, POS, (LL(POS) + 1) * sizeof(char));\n  }\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lobject.h",
    "content": "/*\n** $Id: lobject.h $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/*\n** Extra types for collectable non-values\n*/\n#define LUA_TUPVAL\tLUA_NUMTYPES  /* upvalues */\n#define LUA_TPROTO\t(LUA_NUMTYPES+1)  /* function prototypes */\n\n\n/*\n** number of all possible types (including LUA_TNONE)\n*/\n#define LUA_TOTALTYPES\t\t(LUA_TPROTO + 2)\n\n\n/*\n** tags for Tagged Values have the following use of bits:\n** bits 0-3: actual tag (a LUA_T* constant)\n** bits 4-5: variant bits\n** bit 6: whether value is collectable\n*/\n\n/* add variant bits to a type */\n#define makevariant(t,v)\t((t) | ((v) << 4))\n\n\n\n/*\n** Union of all Lua values\n*/\ntypedef union Value {\n  struct GCObject *gc;    /* collectable objects */\n  void *p;         /* light userdata */\n  lua_CFunction f; /* light C functions */\n  lua_Integer i;   /* integer numbers */\n  lua_Number n;    /* float numbers */\n} Value;\n\n\n/*\n** Tagged Values. This is the basic representation of values in Lua:\n** an actual value plus a tag with its type.\n*/\n\n#define TValuefields\tValue value_; lu_byte tt_\n\ntypedef struct TValue {\n  TValuefields;\n} TValue;\n\n\n#define val_(o)\t\t((o)->value_)\n#define valraw(o)\t(&val_(o))\n\n\n/* raw type tag of a TValue */\n#define rawtt(o)\t((o)->tt_)\n\n/* tag with no variants (bits 0-3) */\n#define novariant(t)\t((t) & 0x0F)\n\n/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */\n#define withvariant(t)\t((t) & 0x3F)\n#define ttypetag(o)\twithvariant(rawtt(o))\n\n/* type of a TValue */\n#define ttype(o)\t(novariant(rawtt(o)))\n\n\n/* Macros to test type */\n#define checktag(o,t)\t\t(rawtt(o) == (t))\n#define checktype(o,t)\t\t(ttype(o) == (t))\n\n\n/* Macros for internal tests */\n\n/* collectable object has the same tag as the original value */\n#define righttt(obj)\t\t(ttypetag(obj) == gcvalue(obj)->tt)\n\n/*\n** Any value being manipulated by the program either is non\n** collectable, or the collectable object has the right tag\n** and it is not dead. The option 'L == NULL' allows other\n** macros using this one to be used where L is not available.\n*/\n#define checkliveness(L,obj) \\\n\t((void)L, lua_longassert(!iscollectable(obj) || \\\n\t\t(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))))\n\n\n/* Macros to set values */\n\n/* set a value's tag */\n#define settt_(o,t)\t((o)->tt_=(t))\n\n\n/* main macro to copy values (from 'obj1' to 'obj2') */\n#define setobj(L,obj1,obj2) \\\n\t{ TValue *io1=(obj1); const TValue *io2=(obj2); \\\n          io1->value_ = io2->value_; settt_(io1, io2->tt_); \\\n\t  checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }\n\n/*\n** Different types of assignments, according to source and destination.\n** (They are mostly equal now, but may be different in the future.)\n*/\n\n/* from stack to stack */\n#define setobjs2s(L,o1,o2)\tsetobj(L,s2v(o1),s2v(o2))\n/* to stack (not from same stack) */\n#define setobj2s(L,o1,o2)\tsetobj(L,s2v(o1),o2)\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n/* to table */\n#define setobj2t\tsetobj\n\n\n/*\n** Entries in the Lua stack\n*/\ntypedef union StackValue {\n  TValue val;\n} StackValue;\n\n\n/* index to stack elements */\ntypedef StackValue *StkId;\n\n/* convert a 'StackValue' to a 'TValue' */\n#define s2v(o)\t(&(o)->val)\n\n\n\n/*\n** {==================================================================\n** Nil\n** ===================================================================\n*/\n\n/* Standard nil */\n#define LUA_VNIL\tmakevariant(LUA_TNIL, 0)\n\n/* Empty slot (which might be different from a slot containing nil) */\n#define LUA_VEMPTY\tmakevariant(LUA_TNIL, 1)\n\n/* Value returned for a key not found in a table (absent key) */\n#define LUA_VABSTKEY\tmakevariant(LUA_TNIL, 2)\n\n\n/* macro to test for (any kind of) nil */\n#define ttisnil(v)\t\tchecktype((v), LUA_TNIL)\n\n\n/* macro to test for a standard nil */\n#define ttisstrictnil(o)\tchecktag((o), LUA_VNIL)\n\n\n#define setnilvalue(obj) settt_(obj, LUA_VNIL)\n\n\n#define isabstkey(v)\t\tchecktag((v), LUA_VABSTKEY)\n\n\n/*\n** macro to detect non-standard nils (used only in assertions)\n*/\n#define isnonstrictnil(v)\t(ttisnil(v) && !ttisstrictnil(v))\n\n\n/*\n** By default, entries with any kind of nil are considered empty.\n** (In any definition, values associated with absent keys must also\n** be accepted as empty.)\n*/\n#define isempty(v)\t\tttisnil(v)\n\n\n/* macro defining a value corresponding to an absent key */\n#define ABSTKEYCONSTANT\t\t{NULL}, LUA_VABSTKEY\n\n\n/* mark an entry as empty */\n#define setempty(v)\t\tsettt_(v, LUA_VEMPTY)\n\n\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Booleans\n** ===================================================================\n*/\n\n\n#define LUA_VFALSE\tmakevariant(LUA_TBOOLEAN, 0)\n#define LUA_VTRUE\tmakevariant(LUA_TBOOLEAN, 1)\n\n#define ttisboolean(o)\t\tchecktype((o), LUA_TBOOLEAN)\n#define ttisfalse(o)\t\tchecktag((o), LUA_VFALSE)\n#define ttistrue(o)\t\tchecktag((o), LUA_VTRUE)\n\n\n#define l_isfalse(o)\t(ttisfalse(o) || ttisnil(o))\n\n\n#define setbfvalue(obj)\t\tsettt_(obj, LUA_VFALSE)\n#define setbtvalue(obj)\t\tsettt_(obj, LUA_VTRUE)\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Threads\n** ===================================================================\n*/\n\n#define LUA_VTHREAD\t\tmakevariant(LUA_TTHREAD, 0)\n\n#define ttisthread(o)\t\tchecktag((o), ctb(LUA_VTHREAD))\n\n#define thvalue(o)\tcheck_exp(ttisthread(o), gco2th(val_(o).gc))\n\n#define setthvalue(L,obj,x) \\\n  { TValue *io = (obj); lua_State *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \\\n    checkliveness(L,io); }\n\n#define setthvalue2s(L,o,t)\tsetthvalue(L,s2v(o),t)\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Collectable Objects\n** ===================================================================\n*/\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tstruct GCObject *next; lu_byte tt; lu_byte marked\n\n\n/* Common type for all collectable objects */\ntypedef struct GCObject {\n  CommonHeader;\n} GCObject;\n\n\n/* Bit mark for collectable types */\n#define BIT_ISCOLLECTABLE\t(1 << 6)\n\n#define iscollectable(o)\t(rawtt(o) & BIT_ISCOLLECTABLE)\n\n/* mark a tag as collectable */\n#define ctb(t)\t\t\t((t) | BIT_ISCOLLECTABLE)\n\n#define gcvalue(o)\tcheck_exp(iscollectable(o), val_(o).gc)\n\n#define gcvalueraw(v)\t((v).gc)\n\n#define setgcovalue(L,obj,x) \\\n  { TValue *io = (obj); GCObject *i_g=(x); \\\n    val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Numbers\n** ===================================================================\n*/\n\n/* Variant tags for numbers */\n#define LUA_VNUMINT\tmakevariant(LUA_TNUMBER, 0)  /* integer numbers */\n#define LUA_VNUMFLT\tmakevariant(LUA_TNUMBER, 1)  /* float numbers */\n\n#define ttisnumber(o)\t\tchecktype((o), LUA_TNUMBER)\n#define ttisfloat(o)\t\tchecktag((o), LUA_VNUMFLT)\n#define ttisinteger(o)\t\tchecktag((o), LUA_VNUMINT)\n\n#define nvalue(o)\tcheck_exp(ttisnumber(o), \\\n\t(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))\n#define fltvalue(o)\tcheck_exp(ttisfloat(o), val_(o).n)\n#define ivalue(o)\tcheck_exp(ttisinteger(o), val_(o).i)\n\n#define fltvalueraw(v)\t((v).n)\n#define ivalueraw(v)\t((v).i)\n\n#define setfltvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); }\n\n#define chgfltvalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }\n\n#define setivalue(obj,x) \\\n  { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); }\n\n#define chgivalue(obj,x) \\\n  { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Strings\n** ===================================================================\n*/\n\n/* Variant tags for strings */\n#define LUA_VSHRSTR\tmakevariant(LUA_TSTRING, 0)  /* short strings */\n#define LUA_VLNGSTR\tmakevariant(LUA_TSTRING, 1)  /* long strings */\n\n#define ttisstring(o)\t\tchecktype((o), LUA_TSTRING)\n#define ttisshrstring(o)\tchecktag((o), ctb(LUA_VSHRSTR))\n#define ttislngstring(o)\tchecktag((o), ctb(LUA_VLNGSTR))\n\n#define tsvalueraw(v)\t(gco2ts((v).gc))\n\n#define tsvalue(o)\tcheck_exp(ttisstring(o), gco2ts(val_(o).gc))\n\n#define setsvalue(L,obj,x) \\\n  { TValue *io = (obj); TString *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \\\n    checkliveness(L,io); }\n\n/* set a string to the stack */\n#define setsvalue2s(L,o,s)\tsetsvalue(L,s2v(o),s)\n\n/* set a string to a new object */\n#define setsvalue2n\tsetsvalue\n\n\n/*\n** Header for a string value.\n*/\ntypedef struct TString {\n  CommonHeader;\n  lu_byte extra;  /* reserved words for short strings; \"has hash\" for longs */\n  lu_byte shrlen;  /* length for short strings */\n  unsigned int hash;\n  union {\n    size_t lnglen;  /* length for long strings */\n    struct TString *hnext;  /* linked list for hash table */\n  } u;\n  char contents[1];\n} TString;\n\n\n\n/*\n** Get the actual string (array of bytes) from a 'TString'.\n*/\n#define getstr(ts)  ((ts)->contents)\n\n\n/* get the actual string (array of bytes) from a Lua value */\n#define svalue(o)       getstr(tsvalue(o))\n\n/* get string length from 'TString *s' */\n#define tsslen(s)\t((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen)\n\n/* get string length from 'TValue *o' */\n#define vslen(o)\ttsslen(tsvalue(o))\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Userdata\n** ===================================================================\n*/\n\n\n/*\n** Light userdata should be a variant of userdata, but for compatibility\n** reasons they are also different types.\n*/\n#define LUA_VLIGHTUSERDATA\tmakevariant(LUA_TLIGHTUSERDATA, 0)\n\n#define LUA_VUSERDATA\t\tmakevariant(LUA_TUSERDATA, 0)\n\n#define ttislightuserdata(o)\tchecktag((o), LUA_VLIGHTUSERDATA)\n#define ttisfulluserdata(o)\tchecktag((o), ctb(LUA_VUSERDATA))\n\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), val_(o).p)\n#define uvalue(o)\tcheck_exp(ttisfulluserdata(o), gco2u(val_(o).gc))\n\n#define pvalueraw(v)\t((v).p)\n\n#define setpvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); }\n\n#define setuvalue(L,obj,x) \\\n  { TValue *io = (obj); Udata *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \\\n    checkliveness(L,io); }\n\n\n/* Ensures that addresses after this type are always fully aligned. */\ntypedef union UValue {\n  TValue uv;\n  LUAI_MAXALIGN;  /* ensures maximum alignment for udata bytes */\n} UValue;\n\n\n/*\n** Header for userdata with user values;\n** memory area follows the end of this structure.\n*/\ntypedef struct Udata {\n  CommonHeader;\n  unsigned short nuvalue;  /* number of user values */\n  size_t len;  /* number of bytes */\n  struct Table *metatable;\n  GCObject *gclist;\n  UValue uv[1];  /* user values */\n} Udata;\n\n\n/*\n** Header for userdata with no user values. These userdata do not need\n** to be gray during GC, and therefore do not need a 'gclist' field.\n** To simplify, the code always use 'Udata' for both kinds of userdata,\n** making sure it never accesses 'gclist' on userdata with no user values.\n** This structure here is used only to compute the correct size for\n** this representation. (The 'bindata' field in its end ensures correct\n** alignment for binary data following this header.)\n*/\ntypedef struct Udata0 {\n  CommonHeader;\n  unsigned short nuvalue;  /* number of user values */\n  size_t len;  /* number of bytes */\n  struct Table *metatable;\n  union {LUAI_MAXALIGN;} bindata;\n} Udata0;\n\n\n/* compute the offset of the memory area of a userdata */\n#define udatamemoffset(nuv) \\\n\t((nuv) == 0 ? offsetof(Udata0, bindata)  \\\n                    : offsetof(Udata, uv) + (sizeof(UValue) * (nuv)))\n\n/* get the address of the memory block inside 'Udata' */\n#define getudatamem(u)\t(cast_charp(u) + udatamemoffset((u)->nuvalue))\n\n/* compute the size of a userdata */\n#define sizeudata(nuv,nb)\t(udatamemoffset(nuv) + (nb))\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Prototypes\n** ===================================================================\n*/\n\n#define LUA_VPROTO\tmakevariant(LUA_TPROTO, 0)\n\n\n/*\n** Description of an upvalue for function prototypes\n*/\ntypedef struct Upvaldesc {\n  TString *name;  /* upvalue name (for debug information) */\n  lu_byte instack;  /* whether it is in stack (register) */\n  lu_byte idx;  /* index of upvalue (in stack or in outer function's list) */\n  lu_byte kind;  /* kind of corresponding variable */\n} Upvaldesc;\n\n\n/*\n** Description of a local variable for function prototypes\n** (used for debug information)\n*/\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n/*\n** Associates the absolute line source for a given instruction ('pc').\n** The array 'lineinfo' gives, for each instruction, the difference in\n** lines from the previous instruction. When that difference does not\n** fit into a byte, Lua saves the absolute line for that instruction.\n** (Lua also saves the absolute line periodically, to speed up the\n** computation of a line number: we can use binary search in the\n** absolute-line array, but we must traverse the 'lineinfo' array\n** linearly to compute a line.)\n*/\ntypedef struct AbsLineInfo {\n  int pc;\n  int line;\n} AbsLineInfo;\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  lu_byte numparams;  /* number of fixed (named) parameters */\n  lu_byte is_vararg;\n  lu_byte maxstacksize;  /* number of registers needed by this function */\n  int sizeupvalues;  /* size of 'upvalues' */\n  int sizek;  /* size of 'k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of 'p' */\n  int sizelocvars;\n  int sizeabslineinfo;  /* size of 'abslineinfo' */\n  int linedefined;  /* debug information  */\n  int lastlinedefined;  /* debug information  */\n  TValue *k;  /* constants used by the function */\n  Instruction *code;  /* opcodes */\n  struct Proto **p;  /* functions defined inside the function */\n  Upvaldesc *upvalues;  /* upvalue information */\n  ls_byte *lineinfo;  /* information about source lines (debug information) */\n  AbsLineInfo *abslineinfo;  /* idem */\n  LocVar *locvars;  /* information about local variables (debug information) */\n  TString  *source;  /* used for debug information */\n  GCObject *gclist;\n} Proto;\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Closures\n** ===================================================================\n*/\n\n#define LUA_VUPVAL\tmakevariant(LUA_TUPVAL, 0)\n\n\n/* Variant tags for functions */\n#define LUA_VLCL\tmakevariant(LUA_TFUNCTION, 0)  /* Lua closure */\n#define LUA_VLCF\tmakevariant(LUA_TFUNCTION, 1)  /* light C function */\n#define LUA_VCCL\tmakevariant(LUA_TFUNCTION, 2)  /* C closure */\n\n#define ttisfunction(o)\t\tchecktype(o, LUA_TFUNCTION)\n#define ttisclosure(o)\t\t((rawtt(o) & 0x1F) == LUA_VLCL)\n#define ttisLclosure(o)\t\tchecktag((o), ctb(LUA_VLCL))\n#define ttislcf(o)\t\tchecktag((o), LUA_VLCF)\n#define ttisCclosure(o)\t\tchecktag((o), ctb(LUA_VCCL))\n\n#define isLfunction(o)\tttisLclosure(o)\n\n#define clvalue(o)\tcheck_exp(ttisclosure(o), gco2cl(val_(o).gc))\n#define clLvalue(o)\tcheck_exp(ttisLclosure(o), gco2lcl(val_(o).gc))\n#define fvalue(o)\tcheck_exp(ttislcf(o), val_(o).f)\n#define clCvalue(o)\tcheck_exp(ttisCclosure(o), gco2ccl(val_(o).gc))\n\n#define fvalueraw(v)\t((v).f)\n\n#define setclLvalue(L,obj,x) \\\n  { TValue *io = (obj); LClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \\\n    checkliveness(L,io); }\n\n#define setclLvalue2s(L,o,cl)\tsetclLvalue(L,s2v(o),cl)\n\n#define setfvalue(obj,x) \\\n  { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); }\n\n#define setclCvalue(L,obj,x) \\\n  { TValue *io = (obj); CClosure *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \\\n    checkliveness(L,io); }\n\n\n/*\n** Upvalues for Lua closures\n*/\ntypedef struct UpVal {\n  CommonHeader;\n  lu_byte tbc;  /* true if it represents a to-be-closed variable */\n  TValue *v;  /* points to stack or to its own value */\n  union {\n    struct {  /* (when open) */\n      struct UpVal *next;  /* linked list */\n      struct UpVal **previous;\n    } open;\n    TValue value;  /* the value (when closed) */\n  } u;\n} UpVal;\n\n\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte nupvalues; GCObject *gclist\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];  /* list of upvalues */\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];  /* list of upvalues */\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define getproto(o)\t(clLvalue(o)->p)\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Tables\n** ===================================================================\n*/\n\n#define LUA_VTABLE\tmakevariant(LUA_TTABLE, 0)\n\n#define ttistable(o)\t\tchecktag((o), ctb(LUA_VTABLE))\n\n#define hvalue(o)\tcheck_exp(ttistable(o), gco2t(val_(o).gc))\n\n#define sethvalue(L,obj,x) \\\n  { TValue *io = (obj); Table *x_ = (x); \\\n    val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \\\n    checkliveness(L,io); }\n\n#define sethvalue2s(L,o,h)\tsethvalue(L,s2v(o),h)\n\n\n/*\n** Nodes for Hash tables: A pack of two TValue's (key-value pairs)\n** plus a 'next' field to link colliding entries. The distribution\n** of the key's fields ('key_tt' and 'key_val') not forming a proper\n** 'TValue' allows for a smaller size for 'Node' both in 4-byte\n** and 8-byte alignments.\n*/\ntypedef union Node {\n  struct NodeKey {\n    TValuefields;  /* fields for value */\n    lu_byte key_tt;  /* key type */\n    int next;  /* for chaining */\n    Value key_val;  /* key value */\n  } u;\n  TValue i_val;  /* direct access to node's value as a proper 'TValue' */\n} Node;\n\n\n/* copy a value into a key */\n#define setnodekey(L,node,obj) \\\n\t{ Node *n_=(node); const TValue *io_=(obj); \\\n\t  n_->u.key_val = io_->value_; n_->u.key_tt = io_->tt_; \\\n\t  checkliveness(L,io_); }\n\n\n/* copy a value from a key */\n#define getnodekey(L,obj,node) \\\n\t{ TValue *io_=(obj); const Node *n_=(node); \\\n\t  io_->value_ = n_->u.key_val; io_->tt_ = n_->u.key_tt; \\\n\t  checkliveness(L,io_); }\n\n\n/*\n** About 'alimit': if 'isrealasize(t)' is true, then 'alimit' is the\n** real size of 'array'. Otherwise, the real size of 'array' is the\n** smallest power of two not smaller than 'alimit' (or zero iff 'alimit'\n** is zero); 'alimit' is then used as a hint for #t.\n*/\n\n#define BITRAS\t\t(1 << 7)\n#define isrealasize(t)\t\t(!((t)->flags & BITRAS))\n#define setrealasize(t)\t\t((t)->flags &= cast_byte(~BITRAS))\n#define setnorealasize(t)\t((t)->flags |= BITRAS)\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */\n  lu_byte lsizenode;  /* log2 of size of 'node' array */\n  unsigned int alimit;  /* \"limit\" of 'array' array */\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  struct Table *metatable;\n  GCObject *gclist;\n} Table;\n\n\n/*\n** Macros to manipulate keys inserted in nodes\n*/\n#define keytt(node)\t\t((node)->u.key_tt)\n#define keyval(node)\t\t((node)->u.key_val)\n\n#define keyisnil(node)\t\t(keytt(node) == LUA_TNIL)\n#define keyisinteger(node)\t(keytt(node) == LUA_VNUMINT)\n#define keyival(node)\t\t(keyval(node).i)\n#define keyisshrstr(node)\t(keytt(node) == ctb(LUA_VSHRSTR))\n#define keystrval(node)\t\t(gco2ts(keyval(node).gc))\n\n#define setnilkey(node)\t\t(keytt(node) = LUA_TNIL)\n\n#define keyiscollectable(n)\t(keytt(n) & BIT_ISCOLLECTABLE)\n\n#define gckey(n)\t(keyval(n).gc)\n#define gckeyN(n)\t(keyiscollectable(n) ? gckey(n) : NULL)\n\n\n/*\n** Use a \"nil table\" to mark dead keys in a table. Those keys serve\n** to keep space for removed entries, which may still be part of\n** chains. Note that the 'keytt' does not have the BIT_ISCOLLECTABLE\n** set, so these values are considered not collectable and are different\n** from any valid value.\n*/\n#define setdeadkey(n)\t(keytt(n) = LUA_TTABLE, gckey(n) = NULL)\n\n/* }================================================================== */\n\n\n\n/*\n** 'module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n/* size of buffer for 'luaO_utf8esc' function */\n#define UTF8BUFFSZ\t8\n\nLUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x);\nLUAI_FUNC int luaO_ceillog2 (unsigned int x);\nLUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1,\n                             const TValue *p2, TValue *res);\nLUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1,\n                           const TValue *p2, StkId res);\nLUAI_FUNC size_t luaO_str2num (const char *s, TValue *o);\nLUAI_FUNC int luaO_hexavalue (int c);\nLUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lopcodes_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nLUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       MM OT IT T  A  mode\t\t   opcode  */\n  opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_MOVE */\n ,opmode(0, 0, 0, 0, 1, iAsBx)\t\t/* OP_LOADI */\n ,opmode(0, 0, 0, 0, 1, iAsBx)\t\t/* OP_LOADF */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_LOADKX */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_LOADFALSE */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_LFALSESKIP */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_LOADTRUE */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_GETTABUP */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_GETI */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_GETFIELD */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_SETTABUP */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_SETI */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_SETFIELD */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SELF */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_ADDI */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_ADDK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SUBK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_MULK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_MODK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_POWK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_DIVK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_IDIVK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BANDK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BORK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BXORK */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SHRI */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SHLI */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_ADD */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SUB */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_MUL */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_MOD */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_POW */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_DIV */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_IDIV */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BAND */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BOR */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BXOR */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SHL */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_SHR */\n ,opmode(1, 0, 0, 0, 0, iABC)\t\t/* OP_MMBIN */\n ,opmode(1, 0, 0, 0, 0, iABC)\t\t/* OP_MMBINI*/\n ,opmode(1, 0, 0, 0, 0, iABC)\t\t/* OP_MMBINK*/\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_UNM */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_BNOT */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_NOT */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_LEN */\n ,opmode(0, 0, 0, 0, 1, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_CLOSE */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_TBC */\n ,opmode(0, 0, 0, 0, 0, isJ)\t\t/* OP_JMP */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_EQ */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_LT */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_LE */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_EQK */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_EQI */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_LTI */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_LEI */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_GTI */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_GEI */\n ,opmode(0, 0, 0, 1, 0, iABC)\t\t/* OP_TEST */\n ,opmode(0, 0, 0, 1, 1, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, 1, 0, 1, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, 1, 0, 1, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, 1, 0, 0, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_RETURN0 */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_RETURN1 */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_FORLOOP */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_FORPREP */\n ,opmode(0, 0, 0, 0, 0, iABx)\t\t/* OP_TFORPREP */\n ,opmode(0, 0, 0, 0, 0, iABC)\t\t/* OP_TFORCALL */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, 1, 0, 0, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 0, 0, 0, 1, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, 0, 0, 1, iABC)\t\t/* OP_VARARG */\n ,opmode(0, 0, 1, 0, 1, iABC)\t\t/* OP_VARARGPREP */\n ,opmode(0, 0, 0, 0, 0, iAx)\t\t/* OP_EXTRAARG */\n};\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned 32-bit integers.\n  All instructions have an opcode in the first 7 bits.\n  Instructions can have the following formats:\n\n        3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0\n        1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0\niABC          C(8)     |      B(8)     |k|     A(8)      |   Op(7)     |\niABx                Bx(17)               |     A(8)      |   Op(7)     |\niAsBx              sBx (signed)(17)      |     A(8)      |   Op(7)     |\niAx                           Ax(25)                     |   Op(7)     |\nisJ                           sJ(25)                     |   Op(7)     |\n\n  A signed argument is represented in excess K: the represented value is\n  the written unsigned value minus K, where K is half the maximum for the\n  corresponding unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx, iAx, isJ};  /* basic instruction formats */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t8\n#define SIZE_B\t\t8\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B + 1)\n#define SIZE_A\t\t8\n#define SIZE_Ax\t\t(SIZE_Bx + SIZE_A)\n#define SIZE_sJ\t\t(SIZE_Bx + SIZE_A)\n\n#define SIZE_OP\t\t7\n\n#define POS_OP\t\t0\n\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_k\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_k + 1)\n#define POS_C\t\t(POS_B + SIZE_B)\n\n#define POS_Bx\t\tPOS_k\n\n#define POS_Ax\t\tPOS_A\n\n#define POS_sJ\t\tPOS_A\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) 'int' to manipulate most arguments,\n** so they must fit in ints.\n*/\n\n/* Check whether type 'int' has at least 'b' bits ('b' < 32) */\n#define L_INTHASBITS(b)\t\t((UINT_MAX >> ((b) - 1)) >= 1)\n\n\n#if L_INTHASBITS(SIZE_Bx)\n#define MAXARG_Bx\t((1<<SIZE_Bx)-1)\n#else\n#define MAXARG_Bx\tMAX_INT\n#endif\n\n#define OFFSET_sBx\t(MAXARG_Bx>>1)         /* 'sBx' is signed */\n\n\n#if L_INTHASBITS(SIZE_Ax)\n#define MAXARG_Ax\t((1<<SIZE_Ax)-1)\n#else\n#define MAXARG_Ax\tMAX_INT\n#endif\n\n#if L_INTHASBITS(SIZE_sJ)\n#define MAXARG_sJ\t((1 << SIZE_sJ) - 1)\n#else\n#define MAXARG_sJ\tMAX_INT\n#endif\n\n#define OFFSET_sJ\t(MAXARG_sJ >> 1)\n\n\n#define MAXARG_A\t((1<<SIZE_A)-1)\n#define MAXARG_B\t((1<<SIZE_B)-1)\n#define MAXARG_C\t((1<<SIZE_C)-1)\n#define OFFSET_sC\t(MAXARG_C >> 1)\n\n#define int2sC(i)\t((i) + OFFSET_sC)\n#define sC2int(i)\t((i) - OFFSET_sC)\n\n\n/* creates a mask with 'n' 1 bits at position 'p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<(n)))<<(p))\n\n/* creates a mask with 'n' 0 bits at position 'p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define checkopm(i,m)\t(getOpMode(GET_OPCODE(i)) == m)\n\n\n#define getarg(i,pos,size)\t(cast_int(((i)>>(pos)) & MASK1(size,0)))\n#define setarg(i,v,pos,size)\t((i) = (((i)&MASK0(size,pos)) | \\\n                ((cast(Instruction, v)<<pos)&MASK1(size,pos))))\n\n#define GETARG_A(i)\tgetarg(i, POS_A, SIZE_A)\n#define SETARG_A(i,v)\tsetarg(i, v, POS_A, SIZE_A)\n\n#define GETARG_B(i)\tcheck_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))\n#define GETARG_sB(i)\tsC2int(GETARG_B(i))\n#define SETARG_B(i,v)\tsetarg(i, v, POS_B, SIZE_B)\n\n#define GETARG_C(i)\tcheck_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))\n#define GETARG_sC(i)\tsC2int(GETARG_C(i))\n#define SETARG_C(i,v)\tsetarg(i, v, POS_C, SIZE_C)\n\n#define TESTARG_k(i)\tcheck_exp(checkopm(i, iABC), (cast_int(((i) & (1u << POS_k)))))\n#define GETARG_k(i)\tcheck_exp(checkopm(i, iABC), getarg(i, POS_k, 1))\n#define SETARG_k(i,v)\tsetarg(i, v, POS_k, 1)\n\n#define GETARG_Bx(i)\tcheck_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))\n#define SETARG_Bx(i,v)\tsetarg(i, v, POS_Bx, SIZE_Bx)\n\n#define GETARG_Ax(i)\tcheck_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax))\n#define SETARG_Ax(i,v)\tsetarg(i, v, POS_Ax, SIZE_Ax)\n\n#define GETARG_sBx(i)  \\\n\tcheck_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast_uint((b)+OFFSET_sBx))\n\n#define GETARG_sJ(i)  \\\n\tcheck_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)\n#define SETARG_sJ(i,j) \\\n\tsetarg(i, cast_uint((j)+OFFSET_sJ), POS_sJ, SIZE_sJ)\n\n\n#define CREATE_ABCk(o,a,b,c,k)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C) \\\n\t\t\t| (cast(Instruction, k)<<POS_k))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n#define CREATE_Ax(o,a)\t\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_Ax))\n\n#define CREATE_sJ(o,j,k)\t((cast(Instruction, o) << POS_OP) \\\n\t\t\t| (cast(Instruction, j) << POS_sJ) \\\n\t\t\t| (cast(Instruction, k) << POS_k))\n\n\n#if !defined(MAXINDEXRK)  /* (for debugging only) */\n#define MAXINDEXRK\tMAXARG_B\n#endif\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R[x] - register\n** K[x] - constant (in constant table)\n** RK(x) == if k(i) then K[x] else R[x]\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\n  name\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR[A] := R[B]\t\t\t\t\t*/\nOP_LOADI,/*\tA sBx\tR[A] := sBx\t\t\t\t\t*/\nOP_LOADF,/*\tA sBx\tR[A] := (lua_Number)sBx\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR[A] := K[Bx]\t\t\t\t\t*/\nOP_LOADKX,/*\tA\tR[A] := K[extra arg]\t\t\t\t*/\nOP_LOADFALSE,/*\tA\tR[A] := false\t\t\t\t\t*/\nOP_LFALSESKIP,/*A\tR[A] := false; pc++\t\t\t\t*/\nOP_LOADTRUE,/*\tA\tR[A] := true\t\t\t\t\t*/\nOP_LOADNIL,/*\tA B\tR[A], R[A+1], ..., R[A+B] := nil\t\t*/\nOP_GETUPVAL,/*\tA B\tR[A] := UpValue[B]\t\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R[A]\t\t\t\t*/\n\nOP_GETTABUP,/*\tA B C\tR[A] := UpValue[B][K[C]:string]\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR[A] := R[B][R[C]]\t\t\t\t*/\nOP_GETI,/*\tA B C\tR[A] := R[B][C]\t\t\t\t\t*/\nOP_GETFIELD,/*\tA B C\tR[A] := R[B][K[C]:string]\t\t\t*/\n\nOP_SETTABUP,/*\tA B C\tUpValue[A][K[B]:string] := RK(C)\t\t*/\nOP_SETTABLE,/*\tA B C\tR[A][R[B]] := RK(C)\t\t\t\t*/\nOP_SETI,/*\tA B C\tR[A][B] := RK(C)\t\t\t\t*/\nOP_SETFIELD,/*\tA B C\tR[A][K[B]:string] := RK(C)\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C k\tR[A] := {}\t\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR[A+1] := R[B]; R[A] := R[B][RK(C):string]\t*/\n\nOP_ADDI,/*\tA B sC\tR[A] := R[B] + sC\t\t\t\t*/\n\nOP_ADDK,/*\tA B C\tR[A] := R[B] + K[C]\t\t\t\t*/\nOP_SUBK,/*\tA B C\tR[A] := R[B] - K[C]\t\t\t\t*/\nOP_MULK,/*\tA B C\tR[A] := R[B] * K[C]\t\t\t\t*/\nOP_MODK,/*\tA B C\tR[A] := R[B] % K[C]\t\t\t\t*/\nOP_POWK,/*\tA B C\tR[A] := R[B] ^ K[C]\t\t\t\t*/\nOP_DIVK,/*\tA B C\tR[A] := R[B] / K[C]\t\t\t\t*/\nOP_IDIVK,/*\tA B C\tR[A] := R[B] // K[C]\t\t\t\t*/\n\nOP_BANDK,/*\tA B C\tR[A] := R[B] & K[C]:integer\t\t\t*/\nOP_BORK,/*\tA B C\tR[A] := R[B] | K[C]:integer\t\t\t*/\nOP_BXORK,/*\tA B C\tR[A] := R[B] ~ K[C]:integer\t\t\t*/\n\nOP_SHRI,/*\tA B sC\tR[A] := R[B] >> sC\t\t\t\t*/\nOP_SHLI,/*\tA B sC\tR[A] := sC << R[B]\t\t\t\t*/\n\nOP_ADD,/*\tA B C\tR[A] := R[B] + R[C]\t\t\t\t*/\nOP_SUB,/*\tA B C\tR[A] := R[B] - R[C]\t\t\t\t*/\nOP_MUL,/*\tA B C\tR[A] := R[B] * R[C]\t\t\t\t*/\nOP_MOD,/*\tA B C\tR[A] := R[B] % R[C]\t\t\t\t*/\nOP_POW,/*\tA B C\tR[A] := R[B] ^ R[C]\t\t\t\t*/\nOP_DIV,/*\tA B C\tR[A] := R[B] / R[C]\t\t\t\t*/\nOP_IDIV,/*\tA B C\tR[A] := R[B] // R[C]\t\t\t\t*/\n\nOP_BAND,/*\tA B C\tR[A] := R[B] & R[C]\t\t\t\t*/\nOP_BOR,/*\tA B C\tR[A] := R[B] | R[C]\t\t\t\t*/\nOP_BXOR,/*\tA B C\tR[A] := R[B] ~ R[C]\t\t\t\t*/\nOP_SHL,/*\tA B C\tR[A] := R[B] << R[C]\t\t\t\t*/\nOP_SHR,/*\tA B C\tR[A] := R[B] >> R[C]\t\t\t\t*/\n\nOP_MMBIN,/*\tA B C\tcall C metamethod over R[A] and R[B]\t\t*/\nOP_MMBINI,/*\tA sB C k\tcall C metamethod over R[A] and sB\t*/\nOP_MMBINK,/*\tA B C k\t\tcall C metamethod over R[A] and K[B]\t*/\n\nOP_UNM,/*\tA B\tR[A] := -R[B]\t\t\t\t\t*/\nOP_BNOT,/*\tA B\tR[A] := ~R[B]\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR[A] := not R[B]\t\t\t\t*/\nOP_LEN,/*\tA B\tR[A] := length of R[B]\t\t\t\t*/\n\nOP_CONCAT,/*\tA B\tR[A] := R[A].. ... ..R[A + B - 1]\t\t*/\n\nOP_CLOSE,/*\tA\tclose all upvalues >= R[A]\t\t\t*/\nOP_TBC,/*\tA\tmark variable A \"to be closed\"\t\t\t*/\nOP_JMP,/*\tsJ\tpc += sJ\t\t\t\t\t*/\nOP_EQ,/*\tA B k\tif ((R[A] == R[B]) ~= k) then pc++\t\t*/\nOP_LT,/*\tA B k\tif ((R[A] <  R[B]) ~= k) then pc++\t\t*/\nOP_LE,/*\tA B k\tif ((R[A] <= R[B]) ~= k) then pc++\t\t*/\n\nOP_EQK,/*\tA B k\tif ((R[A] == K[B]) ~= k) then pc++\t\t*/\nOP_EQI,/*\tA sB k\tif ((R[A] == sB) ~= k) then pc++\t\t*/\nOP_LTI,/*\tA sB k\tif ((R[A] < sB) ~= k) then pc++\t\t\t*/\nOP_LEI,/*\tA sB k\tif ((R[A] <= sB) ~= k) then pc++\t\t*/\nOP_GTI,/*\tA sB k\tif ((R[A] > sB) ~= k) then pc++\t\t\t*/\nOP_GEI,/*\tA sB k\tif ((R[A] >= sB) ~= k) then pc++\t\t*/\n\nOP_TEST,/*\tA k\tif (not R[A] == k) then pc++\t\t\t*/\nOP_TESTSET,/*\tA B k\tif (not R[B] == k) then pc++ else R[A] := R[B]\t*/\n\nOP_CALL,/*\tA B C\tR[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */\nOP_TAILCALL,/*\tA B C k\treturn R[A](R[A+1], ... ,R[A+B-1])\t\t*/\n\nOP_RETURN,/*\tA B C k\treturn R[A], ... ,R[A+B-2]\t(see note)\t*/\nOP_RETURN0,/*\t\treturn\t\t\t\t\t\t*/\nOP_RETURN1,/*\tA\treturn R[A]\t\t\t\t\t*/\n\nOP_FORLOOP,/*\tA Bx\tupdate counters; if loop continues then pc-=Bx; */\nOP_FORPREP,/*\tA Bx\t<check values and prepare counters>;\n                        if not to run then pc+=Bx+1;\t\t\t*/\n\nOP_TFORPREP,/*\tA Bx\tcreate upvalue for R[A + 3]; pc+=Bx\t\t*/\nOP_TFORCALL,/*\tA C\tR[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]);\t*/\nOP_TFORLOOP,/*\tA Bx\tif R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx }\t*/\n\nOP_SETLIST,/*\tA B C k\tR[A][(C-1)*FPF+i] := R[A+i], 1 <= i <= B\t*/\n\nOP_CLOSURE,/*\tA Bx\tR[A] := closure(KPROTO[Bx])\t\t\t*/\n\nOP_VARARG,/*\tA C\tR[A], R[A+1], ..., R[A+C-2] = vararg\t\t*/\n\nOP_VARARGPREP,/*A\t(adjust vararg parameters)\t\t\t*/\n\nOP_EXTRAARG/*\tAx\textra (larger) argument for previous opcode\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t((int)(OP_EXTRAARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then\n  'top' is set to last_result+1, so next open instruction (OP_CALL,\n  OP_RETURN*, OP_SETLIST) may use 'top'.\n\n  (*) In OP_VARARG, if (C == 0) then use actual number of varargs and\n  set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to 'top'.\n\n  (*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always\n  OP_EXTRAARG.\n\n  (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then\n  real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the\n  bits of C).\n\n  (*) In OP_NEWTABLE, B is log2 of the hash size (which is always a\n  power of 2) plus 1, or zero for size zero. If not k, the array size\n  is C. Otherwise, the array size is EXTRAARG _ C.\n\n  (*) For comparisons, k specifies what condition the test should accept\n  (true or false).\n\n  (*) In OP_MMBINI/OP_MMBINK, k means the arguments were flipped\n   (the constant is the first operand).\n\n  (*) All 'skips' (pc++) assume that next instruction is a jump.\n\n  (*) In instructions OP_RETURN/OP_TAILCALL, 'k' specifies that the\n  function builds upvalues, which may need to be closed. C > 0 means\n  the function is vararg, so that its 'func' must be corrected before\n  returning; in this case, (C - 1) is its number of fixed parameters.\n\n  (*) In comparisons with an immediate operand, C signals whether the\n  original operand was a float. (It must be corrected in case of\n  metamethods.)\n\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-2: op mode\n** bit 3: instruction set register A\n** bit 4: operator is a test (next instruction must be a jump)\n** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0)\n** bit 6: instruction sets 'L->top' for next instruction (when C == 0)\n** bit 7: instruction is an MM instruction (call a metamethod)\n*/\n\nLUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];)\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 7))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 3))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 4))\n#define testITMode(m)\t(luaP_opmodes[m] & (1 << 5))\n#define testOTMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testMMMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n/* \"out top\" (set top for next instruction) */\n#define isOT(i)  \\\n\t((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \\\n          GET_OPCODE(i) == OP_TAILCALL)\n\n/* \"in top\" (uses top from previous instruction) */\n#define isIT(i)\t\t(testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0)\n\n#define opmode(mm,ot,it,t,a,m)  \\\n    (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lopnames.h",
    "content": "/*\n** $Id: lopnames.h $\n** Opcode names\n** See Copyright Notice in lua.h\n*/\n\n#if !defined(lopnames_h)\n#define lopnames_h\n\n#include <stddef.h>\n\n\n/* ORDER OP */\n\nstatic const char *const opnames[] = {\n  \"MOVE\",\n  \"LOADI\",\n  \"LOADF\",\n  \"LOADK\",\n  \"LOADKX\",\n  \"LOADFALSE\",\n  \"LFALSESKIP\",\n  \"LOADTRUE\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"SETUPVAL\",\n  \"GETTABUP\",\n  \"GETTABLE\",\n  \"GETI\",\n  \"GETFIELD\",\n  \"SETTABUP\",\n  \"SETTABLE\",\n  \"SETI\",\n  \"SETFIELD\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADDI\",\n  \"ADDK\",\n  \"SUBK\",\n  \"MULK\",\n  \"MODK\",\n  \"POWK\",\n  \"DIVK\",\n  \"IDIVK\",\n  \"BANDK\",\n  \"BORK\",\n  \"BXORK\",\n  \"SHRI\",\n  \"SHLI\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"MOD\",\n  \"POW\",\n  \"DIV\",\n  \"IDIV\",\n  \"BAND\",\n  \"BOR\",\n  \"BXOR\",\n  \"SHL\",\n  \"SHR\",\n  \"MMBIN\",\n  \"MMBINI\",\n  \"MMBINK\",\n  \"UNM\",\n  \"BNOT\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"CLOSE\",\n  \"TBC\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"EQK\",\n  \"EQI\",\n  \"LTI\",\n  \"LEI\",\n  \"GTI\",\n  \"GEI\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"RETURN0\",\n  \"RETURN1\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORPREP\",\n  \"TFORCALL\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSURE\",\n  \"VARARG\",\n  \"VARARGPREP\",\n  \"EXTRAARG\",\n  NULL\n};\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/loslib.c",
    "content": "/*\n** $Id: loslib.c $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** {==================================================================\n** List of valid conversion specifiers for the 'strftime' function;\n** options are grouped by length; group of length 2 start with '||'.\n** ===================================================================\n*/\n#if !defined(LUA_STRFTIMEOPTIONS)\t/* { */\n\n/* options for ANSI C 89 (only 1-char options) */\n#define L_STRFTIMEC89\t\t\"aAbBcdHIjmMpSUwWxXyYZ%\"\n\n/* options for ISO C 99 and POSIX */\n#define L_STRFTIMEC99 \"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%\" \\\n    \"||\" \"EcECExEXEyEY\" \"OdOeOHOIOmOMOSOuOUOVOwOWOy\"  /* two-char options */\n\n/* options for Windows */\n#define L_STRFTIMEWIN \"aAbBcdHIjmMpSUwWxXyYzZ%\" \\\n    \"||\" \"#c#x#d#H#I#j#m#M#S#U#w#W#y#Y\"  /* two-char options */\n\n#if defined(LUA_USE_WINDOWS)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEWIN\n#elif defined(LUA_USE_C89)\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC89\n#else  /* C99 specification */\n#define LUA_STRFTIMEOPTIONS\tL_STRFTIMEC99\n#endif\n\n#endif\t\t\t\t\t/* } */\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for time-related stuff\n** ===================================================================\n*/\n\n/*\n** type to represent time_t in Lua\n*/\n#if !defined(LUA_NUMTIME)\t/* { */\n\n#define l_timet\t\t\tlua_Integer\n#define l_pushtime(L,t)\t\tlua_pushinteger(L,(lua_Integer)(t))\n#define l_gettime(L,arg)\tluaL_checkinteger(L, arg)\n\n#else\t\t\t\t/* }{ */\n\n#define l_timet\t\t\tlua_Number\n#define l_pushtime(L,t)\t\tlua_pushnumber(L,(lua_Number)(t))\n#define l_gettime(L,arg)\tluaL_checknumber(L, arg)\n\n#endif\t\t\t\t/* } */\n\n\n#if !defined(l_gmtime)\t\t/* { */\n/*\n** By default, Lua uses gmtime/localtime, except when POSIX is available,\n** where it uses gmtime_r/localtime_r\n*/\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#define l_gmtime(t,r)\t\tgmtime_r(t,r)\n#define l_localtime(t,r)\tlocaltime_r(t,r)\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define l_gmtime(t,r)\t\t((void)(r)->tm_sec, gmtime(t))\n#define l_localtime(t,r)\t((void)(r)->tm_sec, localtime(t))\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Configuration for 'tmpnam':\n** By default, Lua uses tmpnam except when POSIX is available, where\n** it uses mkstemp.\n** ===================================================================\n*/\n#if !defined(lua_tmpnam)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n\n#define LUA_TMPNAMBUFSIZE\t32\n\n#if !defined(LUA_TMPNAMTEMPLATE)\n#define LUA_TMPNAMTEMPLATE\t\"/tmp/lua_XXXXXX\"\n#endif\n\n#define lua_tmpnam(b,e) { \\\n        strcpy(b, LUA_TMPNAMTEMPLATE); \\\n        e = mkstemp(b); \\\n        if (e != -1) close(e); \\\n        e = (e == -1); }\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definitions */\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n/* }================================================================== */\n\n\n\n//static int os_execute (lua_State *L) {\n//  const char *cmd = luaL_optstring(L, 1, NULL);\n//  errno = 0;\n//  stat = system(cmd);\n//  if (cmd != NULL)\n//    return luaL_execresult(L, stat);\n//  else {\n//    lua_pushboolean(L, stat);  /* true if there is a shell */\n//    return 1;\n//  }\n//}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n#if defined(WINAPI_FAMILY_PARTITION)\n  return luaL_error(L, \"unsupport api in uwp platform\");\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n#endif\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\n/*\n** About the overflow check: an overflow cannot occur when time\n** is represented by a lua_Integer, because either lua_Integer is\n** large enough to represent all int fields or it is not large enough\n** to represent a time that cause a field to overflow.  However, if\n** times are represented as doubles and lua_Integer is int, then the\n** time 0x1.e1853b0d184f6p+55 would cause an overflow when adding 1900\n** to compute the year.\n*/\nstatic void setfield (lua_State *L, const char *key, int value, int delta) {\n  #if (defined(LUA_NUMTIME) && LUA_MAXINTEGER <= INT_MAX)\n    if (value > LUA_MAXINTEGER - delta)\n      luaL_error(L, \"field '%s' is out-of-bound\", key);\n  #endif\n  lua_pushinteger(L, (lua_Integer)value + delta);\n  lua_setfield(L, -2, key);\n}\n\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\n\n/*\n** Set all fields from structure 'tm' in the table on top of the stack\n*/\nstatic void setallfields (lua_State *L, struct tm *stm) {\n  setfield(L, \"year\", stm->tm_year, 1900);\n  setfield(L, \"month\", stm->tm_mon, 1);\n  setfield(L, \"day\", stm->tm_mday, 0);\n  setfield(L, \"hour\", stm->tm_hour, 0);\n  setfield(L, \"min\", stm->tm_min, 0);\n  setfield(L, \"sec\", stm->tm_sec, 0);\n  setfield(L, \"yday\", stm->tm_yday, 1);\n  setfield(L, \"wday\", stm->tm_wday, 1);\n  setboolfield(L, \"isdst\", stm->tm_isdst);\n}\n\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\nstatic int getfield (lua_State *L, const char *key, int d, int delta) {\n  int isnum;\n  int t = lua_getfield(L, -1, key);  /* get field and its type */\n  lua_Integer res = lua_tointegerx(L, -1, &isnum);\n  if (!isnum) {  /* field is not an integer? */\n    if (t != LUA_TNIL)  /* some other value? */\n      return luaL_error(L, \"field '%s' is not an integer\", key);\n    else if (d < 0)  /* absent field; no default? */\n      return luaL_error(L, \"field '%s' missing in date table\", key);\n    res = d;\n  }\n  else {\n    /* unsigned avoids overflow when lua_Integer has 32 bits */\n    if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta\n                   : (lua_Integer)INT_MIN + delta <= res))\n      return luaL_error(L, \"field '%s' is out-of-bound\", key);\n    res -= delta;\n  }\n  lua_pop(L, 1);\n  return (int)res;\n}\n\n\nstatic const char *checkoption (lua_State *L, const char *conv,\n                                ptrdiff_t convlen, char *buff) {\n  const char *option = LUA_STRFTIMEOPTIONS;\n  int oplen = 1;  /* length of options being checked */\n  for (; *option != '\\0' && oplen <= convlen; option += oplen) {\n    if (*option == '|')  /* next block? */\n      oplen++;  /* will check options with next length (+1) */\n    else if (memcmp(conv, option, oplen) == 0) {  /* match? */\n      memcpy(buff, conv, oplen);  /* copy valid option to buffer */\n      buff[oplen] = '\\0';\n      return conv + oplen;  /* return next item */\n    }\n  }\n  luaL_argerror(L, 1,\n    lua_pushfstring(L, \"invalid conversion specifier '%%%s'\", conv));\n  return conv;  /* to avoid warnings */\n}\n\n\nstatic time_t l_checktime (lua_State *L, int arg) {\n  l_timet t = l_gettime(L, arg);\n  luaL_argcheck(L, (time_t)t == t, arg, \"time out-of-bounds\");\n  return (time_t)t;\n}\n\n\n/* maximum size for an individual 'strftime' item */\n#define SIZETIMEFMT\t250\n\n\nstatic int os_date (lua_State *L) {\n  size_t slen;\n  const char *s = luaL_optlstring(L, 1, \"%c\", &slen);\n  time_t t = luaL_opt(L, l_checktime, 2, time(NULL));\n  const char *se = s + slen;  /* 's' end */\n  struct tm tmr, *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = l_gmtime(&t, &tmr);\n    s++;  /* skip '!' */\n  }\n  else\n    stm = l_localtime(&t, &tmr);\n  if (stm == NULL)  /* invalid date? */\n    return luaL_error(L,\n                 \"date result cannot be represented in this installation\");\n  if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setallfields(L, stm);\n  }\n  else {\n    char cc[4];  /* buffer for individual conversion specifiers */\n    luaL_Buffer b;\n    cc[0] = '%';\n    luaL_buffinit(L, &b);\n    while (s < se) {\n      if (*s != '%')  /* not a conversion specifier? */\n        luaL_addchar(&b, *s++);\n      else {\n        size_t reslen;\n        char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);\n        s++;  /* skip '%' */\n        s = checkoption(L, s, se - s, cc + 1);  /* copy specifier to 'cc' */\n        reslen = strftime(buff, SIZETIMEFMT, cc, stm);\n        luaL_addsize(&b, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_year = getfield(L, \"year\", -1, 1900);\n    ts.tm_mon = getfield(L, \"month\", -1, 1);\n    ts.tm_mday = getfield(L, \"day\", -1, 0);\n    ts.tm_hour = getfield(L, \"hour\", 12, 0);\n    ts.tm_min = getfield(L, \"min\", 0, 0);\n    ts.tm_sec = getfield(L, \"sec\", 0, 0);\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n    setallfields(L, &ts);  /* update fields with normalized values */\n  }\n  if (t != (time_t)(l_timet)t || t == (time_t)(-1))\n    return luaL_error(L,\n                  \"time result cannot be represented in this installation\");\n  l_pushtime(L, t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  time_t t1 = l_checktime(L, 1);\n  time_t t2 = l_checktime(L, 2);\n  lua_pushnumber(L, (lua_Number)difftime(t1, t2));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  int status;\n  if (lua_isboolean(L, 1))\n    status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);\n  else\n    status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS);\n  if (lua_toboolean(L, 2))\n    lua_close(L);\n  if (L) exit(status);  /* 'if' to avoid warnings for unreachable 'return' */\n  return 0;\n}\n\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  //{\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUAMOD_API int luaopen_os (lua_State *L) {\n  luaL_newlib(L, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lparser.c",
    "content": "/*\n** $Id: lparser.c $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n/* maximum number of local variables per function (must be smaller\n   than 250, due to the bytecode format) */\n#define MAXVARS\t\t200\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n\n/* because all strings are unified by the scanner, the parser\n   can use pointer equality for string equality */\n#define eqstr(a,b)\t((a) == (b))\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int firstlabel;  /* index of first label in this block */\n  int firstgoto;  /* index of first pending goto in this block */\n  lu_byte nactvar;  /* # active locals outside the block */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isloop;  /* true if 'block' is a loop */\n  lu_byte insidetbc;  /* true if inside the scope of a to-be-closed var. */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void statement (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\nstatic l_noret error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, \"%s expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic l_noret errorlimit (FuncState *fs, int limit, const char *what) {\n  lua_State *L = fs->ls->L;\n  const char *msg;\n  int line = fs->f->linedefined;\n  const char *where = (line == 0)\n                      ? \"main function\"\n                      : luaO_pushfstring(L, \"function at line %d\", line);\n  msg = luaO_pushfstring(L, \"too many %s (limit is %d) in %s\",\n                             what, limit, where);\n  luaX_syntaxerror(fs->ls, msg);\n}\n\n\nstatic void checklimit (FuncState *fs, int v, int l, const char *what) {\n  if (v > l) errorlimit(fs, l, what);\n}\n\n\n/*\n** Test whether next token is 'c'; if so, skip it.\n*/\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\n/*\n** Check that next token is 'c'.\n*/\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\n\n/*\n** Check that next token is 'c' and skip it.\n*/\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n/*\n** Check that next token is 'what' and skip it. In case of error,\n** raise an error that the expected 'what' should match a 'who'\n** in line 'where' (if that is not the current line).\n*/\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (unlikely(!testnext(ls, what))) {\n    if (where == ls->linenumber)  /* all in the same line? */\n      error_expected(ls, what);  /* do not need a complex message */\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             \"%s expected (to close %s at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.info = i;\n}\n\n\nstatic void codestring (expdesc *e, TString *s) {\n  e->f = e->t = NO_JUMP;\n  e->k = VKSTR;\n  e->u.strval = s;\n}\n\n\nstatic void codename (LexState *ls, expdesc *e) {\n  codestring(e, str_checkname(ls));\n}\n\n\n/*\n** Register a new local variable in the active 'Proto' (for debug\n** information).\n*/\nstatic int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"local variables\");\n  while (oldsize < f->sizelocvars)\n    f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->ndebugvars].varname = varname;\n  f->locvars[fs->ndebugvars].startpc = fs->pc;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->ndebugvars++;\n}\n\n\n/*\n** Create a new local variable with the given 'name'. Return its index\n** in the function.\n*/\nstatic int new_localvar (LexState *ls, TString *name) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Dyndata *dyd = ls->dyd;\n  Vardesc *var;\n  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,\n                 MAXVARS, \"local variables\");\n  luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,\n                  dyd->actvar.size, Vardesc, USHRT_MAX, \"local variables\");\n  var = &dyd->actvar.arr[dyd->actvar.n++];\n  var->vd.kind = VDKREG;  /* default */\n  var->vd.name = name;\n  return dyd->actvar.n - 1 - fs->firstlocal;\n}\n\n#define new_localvarliteral(ls,v) \\\n    new_localvar(ls,  \\\n      luaX_newstring(ls, \"\" v, (sizeof(v)/sizeof(char)) - 1));\n\n\n\n/*\n** Return the \"variable description\" (Vardesc) of a given variable.\n** (Unless noted otherwise, all variables are referred to by their\n** compiler indices.)\n*/\nstatic Vardesc *getlocalvardesc (FuncState *fs, int vidx) {\n  return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx];\n}\n\n\n/*\n** Convert 'nvar', a compiler index level, to it corresponding\n** stack index level. For that, search for the highest variable\n** below that level that is in the stack and uses its stack\n** index ('sidx').\n*/\nstatic int stacklevel (FuncState *fs, int nvar) {\n  while (nvar-- > 0) {\n    Vardesc *vd = getlocalvardesc(fs, nvar);  /* get variable */\n    if (vd->vd.kind != RDKCTC)  /* is in the stack? */\n      return vd->vd.sidx + 1;\n  }\n  return 0;  /* no variables in the stack */\n}\n\n\n/*\n** Return the number of variables in the stack for function 'fs'\n*/\nint luaY_nvarstack (FuncState *fs) {\n  return stacklevel(fs, fs->nactvar);\n}\n\n\n/*\n** Get the debug-information entry for current variable 'vidx'.\n*/\nstatic LocVar *localdebuginfo (FuncState *fs, int vidx) {\n  Vardesc *vd = getlocalvardesc(fs,  vidx);\n  if (vd->vd.kind == RDKCTC)\n    return NULL;  /* no debug info. for constants */\n  else {\n    int idx = vd->vd.pidx;\n    lua_assert(idx < fs->ndebugvars);\n    return &fs->f->locvars[idx];\n  }\n}\n\n\n/*\n** Create an expression representing variable 'vidx'\n*/\nstatic void init_var (FuncState *fs, expdesc *e, int vidx) {\n  e->f = e->t = NO_JUMP;\n  e->k = VLOCAL;\n  e->u.var.vidx = vidx;\n  e->u.var.sidx = getlocalvardesc(fs, vidx)->vd.sidx;\n}\n\n\n/*\n** Raises an error if variable described by 'e' is read only\n*/\nstatic void check_readonly (LexState *ls, expdesc *e) {\n  FuncState *fs = ls->fs;\n  TString *varname = NULL;  /* to be set if variable is const */\n  switch (e->k) {\n    case VCONST: {\n      varname = ls->dyd->actvar.arr[e->u.info].vd.name;\n      break;\n    }\n    case VLOCAL: {\n      Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx);\n      if (vardesc->vd.kind != VDKREG)  /* not a regular variable? */\n        varname = vardesc->vd.name;\n      break;\n    }\n    case VUPVAL: {\n      Upvaldesc *up = &fs->f->upvalues[e->u.info];\n      if (up->kind != VDKREG)\n        varname = up->name;\n      break;\n    }\n    default:\n      return;  /* other cases cannot be read-only */\n  }\n  if (varname) {\n    const char *msg = luaO_pushfstring(ls->L,\n       \"attempt to assign to const variable '%s'\", getstr(varname));\n    luaK_semerror(ls, msg);  /* error */\n  }\n}\n\n\n/*\n** Start the scope for the last 'nvars' created variables.\n*/\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  int stklevel = luaY_nvarstack(fs);\n  int i;\n  for (i = 0; i < nvars; i++) {\n    int vidx = fs->nactvar++;\n    Vardesc *var = getlocalvardesc(fs, vidx);\n    var->vd.sidx = stklevel++;\n    var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);\n  }\n}\n\n\n/*\n** Close the scope for all variables up to level 'tolevel'.\n** (debug info.)\n*/\nstatic void removevars (FuncState *fs, int tolevel) {\n  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);\n  while (fs->nactvar > tolevel) {\n    LocVar *var = localdebuginfo(fs, --fs->nactvar);\n    if (var)  /* does it have debug information? */\n      var->endpc = fs->pc;\n  }\n}\n\n\n/*\n** Search the upvalues of the function 'fs' for one\n** with the given 'name'.\n*/\nstatic int searchupvalue (FuncState *fs, TString *name) {\n  int i;\n  Upvaldesc *up = fs->f->upvalues;\n  for (i = 0; i < fs->nups; i++) {\n    if (eqstr(up[i].name, name)) return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic Upvaldesc *allocupvalue (FuncState *fs) {\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  checklimit(fs, fs->nups + 1, MAXUPVAL, \"upvalues\");\n  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,\n                  Upvaldesc, MAXUPVAL, \"upvalues\");\n  while (oldsize < f->sizeupvalues)\n    f->upvalues[oldsize++].name = NULL;\n  return &f->upvalues[fs->nups++];\n}\n\n\nstatic int newupvalue (FuncState *fs, TString *name, expdesc *v) {\n  Upvaldesc *up = allocupvalue(fs);\n  FuncState *prev = fs->prev;\n  if (v->k == VLOCAL) {\n    up->instack = 1;\n    up->idx = v->u.var.sidx;\n    up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind;\n    lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name));\n  }\n  else {\n    up->instack = 0;\n    up->idx = cast_byte(v->u.info);\n    up->kind = prev->f->upvalues[v->u.info].kind;\n    lua_assert(eqstr(name, prev->f->upvalues[v->u.info].name));\n  }\n  up->name = name;\n  luaC_objbarrier(fs->ls->L, fs->f, name);\n  return fs->nups - 1;\n}\n\n\n/*\n** Look for an active local variable with the name 'n' in the\n** function 'fs'. If found, initialize 'var' with it and return\n** its expression kind; otherwise return -1.\n*/\nstatic int searchvar (FuncState *fs, TString *n, expdesc *var) {\n  int i;\n  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {\n    Vardesc *vd = getlocalvardesc(fs, i);\n    if (eqstr(n, vd->vd.name)) {  /* found? */\n      if (vd->vd.kind == RDKCTC)  /* compile-time constant? */\n        init_exp(var, VCONST, fs->firstlocal + i);\n      else  /* real variable */\n        init_var(fs, var, i);\n      return var->k;\n    }\n  }\n  return -1;  /* not found */\n}\n\n\n/*\n** Mark block where variable at given level was defined\n** (to emit close instructions later).\n*/\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl->nactvar > level)\n    bl = bl->previous;\n  bl->upval = 1;\n  fs->needclose = 1;\n}\n\n\n/*\n** Find a variable with the given name 'n'. If it is an upvalue, add\n** this upvalue into all intermediate functions. If it is a global, set\n** 'var' as 'void' as a flag.\n*/\nstatic void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL)  /* no more levels? */\n    init_exp(var, VVOID, 0);  /* default is global */\n  else {\n    int v = searchvar(fs, n, var);  /* look up locals at current level */\n    if (v >= 0) {  /* found? */\n      if (v == VLOCAL && !base)\n        markupval(fs, var->u.var.vidx);  /* local will be used as an upval */\n    }\n    else {  /* not found as local at current level; try upvalues */\n      int idx = searchupvalue(fs, n);  /* try existing upvalues */\n      if (idx < 0) {  /* not found? */\n        singlevaraux(fs->prev, n, var, 0);  /* try upper levels */\n        if (var->k == VLOCAL || var->k == VUPVAL)  /* local or upvalue? */\n          idx  = newupvalue(fs, n, var);  /* will be a new upvalue */\n        else  /* it is a global or a constant */\n          return;  /* don't need to do anything at this level */\n      }\n      init_exp(var, VUPVAL, idx);  /* new or old upvalue */\n    }\n  }\n}\n\n\n/*\n** Find a variable with the given name 'n', handling global variables\n** too.\n*/\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  singlevaraux(fs, varname, var, 1);\n  if (var->k == VVOID) {  /* global name? */\n    expdesc key;\n    singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */\n    lua_assert(var->k != VVOID);  /* this one must exist */\n    codestring(&key, varname);  /* key is variable name */\n    luaK_indexed(fs, var, &key);  /* env[varname] */\n  }\n}\n\n\n/*\n** Adjust the number of results from an expression list 'e' with 'nexps'\n** expressions to 'nvars' values.\n*/\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int needed = nvars - nexps;  /* extra values needed */\n  if (hasmultret(e->k)) {  /* last expression has multiple returns? */\n    int extra = needed + 1;  /* discount last expression itself */\n    if (extra < 0)\n      extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n  }\n  else {\n    if (e->k != VVOID)  /* at least one expression? */\n      luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (needed > 0)  /* missing values? */\n      luaK_nil(fs, fs->freereg, needed);  /* complete with nils */\n  }\n  if (needed > 0)\n    luaK_reserveregs(fs, needed);  /* registers for extra values */\n  else  /* adding 'needed' is actually a subtraction */\n    fs->freereg += needed;  /* remove extra values */\n}\n\n\n/*\n** Macros to limit the maximum recursion depth while parsing\n*/\n#define enterlevel(ls)\tluaE_enterCcall((ls)->L)\n\n#define leavelevel(ls)\tluaE_exitCcall((ls)->L)\n\n\n/*\n** Generates an error that a goto jumps into the scope of some\n** local variable.\n*/\nstatic l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {\n  const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name);\n  const char *msg = \"<goto %s> at line %d jumps into the scope of local '%s'\";\n  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname);\n  luaK_semerror(ls, msg);  /* raise the error */\n}\n\n\n/*\n** Solves the goto at index 'g' to given 'label' and removes it\n** from the list of pending goto's.\n** If it jumps into the scope of some variable, raises an error.\n*/\nstatic void solvegoto (LexState *ls, int g, Labeldesc *label) {\n  int i;\n  Labellist *gl = &ls->dyd->gt;  /* list of goto's */\n  Labeldesc *gt = &gl->arr[g];  /* goto to be resolved */\n  lua_assert(eqstr(gt->name, label->name));\n  if (unlikely(gt->nactvar < label->nactvar))  /* enter some scope? */\n    jumpscopeerror(ls, gt);\n  luaK_patchlist(ls->fs, gt->pc, label->pc);\n  for (i = g; i < gl->n - 1; i++)  /* remove goto from pending list */\n    gl->arr[i] = gl->arr[i + 1];\n  gl->n--;\n}\n\n\n/*\n** Search for an active label with the given name.\n*/\nstatic Labeldesc *findlabel (LexState *ls, TString *name) {\n  int i;\n  Dyndata *dyd = ls->dyd;\n  /* check labels in current function for a match */\n  for (i = ls->fs->firstlabel; i < dyd->label.n; i++) {\n    Labeldesc *lb = &dyd->label.arr[i];\n    if (eqstr(lb->name, name))  /* correct label? */\n      return lb;\n  }\n  return NULL;  /* label not found */\n}\n\n\n/*\n** Adds a new label/goto in the corresponding list.\n*/\nstatic int newlabelentry (LexState *ls, Labellist *l, TString *name,\n                          int line, int pc) {\n  int n = l->n;\n  luaM_growvector(ls->L, l->arr, n, l->size,\n                  Labeldesc, SHRT_MAX, \"labels/gotos\");\n  l->arr[n].name = name;\n  l->arr[n].line = line;\n  l->arr[n].nactvar = ls->fs->nactvar;\n  l->arr[n].close = 0;\n  l->arr[n].pc = pc;\n  l->n = n + 1;\n  return n;\n}\n\n\nstatic int newgotoentry (LexState *ls, TString *name, int line, int pc) {\n  return newlabelentry(ls, &ls->dyd->gt, name, line, pc);\n}\n\n\n/*\n** Solves forward jumps. Check whether new label 'lb' matches any\n** pending gotos in current block and solves them. Return true\n** if any of the goto's need to close upvalues.\n*/\nstatic int solvegotos (LexState *ls, Labeldesc *lb) {\n  Labellist *gl = &ls->dyd->gt;\n  int i = ls->fs->bl->firstgoto;\n  int needsclose = 0;\n  while (i < gl->n) {\n    if (eqstr(gl->arr[i].name, lb->name)) {\n      needsclose |= gl->arr[i].close;\n      solvegoto(ls, i, lb);  /* will remove 'i' from the list */\n    }\n    else\n      i++;\n  }\n  return needsclose;\n}\n\n\n/*\n** Create a new label with the given 'name' at the given 'line'.\n** 'last' tells whether label is the last non-op statement in its\n** block. Solves all pending goto's to this new label and adds\n** a close instruction if necessary.\n** Returns true iff it added a close instruction.\n*/\nstatic int createlabel (LexState *ls, TString *name, int line,\n                        int last) {\n  FuncState *fs = ls->fs;\n  Labellist *ll = &ls->dyd->label;\n  int l = newlabelentry(ls, ll, name, line, luaK_getlabel(fs));\n  if (last) {  /* label is last no-op statement in the block? */\n    /* assume that locals are already out of scope */\n    ll->arr[l].nactvar = fs->bl->nactvar;\n  }\n  if (solvegotos(ls, &ll->arr[l])) {  /* need close? */\n    luaK_codeABC(fs, OP_CLOSE, luaY_nvarstack(fs), 0, 0);\n    return 1;\n  }\n  return 0;\n}\n\n\n/*\n** Adjust pending gotos to outer level of a block.\n*/\nstatic void movegotosout (FuncState *fs, BlockCnt *bl) {\n  int i;\n  Labellist *gl = &fs->ls->dyd->gt;\n  /* correct pending gotos to current block */\n  for (i = bl->firstgoto; i < gl->n; i++) {  /* for each pending goto */\n    Labeldesc *gt = &gl->arr[i];\n    /* leaving a variable scope? */\n    if (stacklevel(fs, gt->nactvar) > stacklevel(fs, bl->nactvar))\n      gt->close |= bl->upval;  /* jump may need a close */\n    gt->nactvar = bl->nactvar;  /* update goto level */\n  }\n}\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {\n  bl->isloop = isloop;\n  bl->nactvar = fs->nactvar;\n  bl->firstlabel = fs->ls->dyd->label.n;\n  bl->firstgoto = fs->ls->dyd->gt.n;\n  bl->upval = 0;\n  bl->insidetbc = (fs->bl != NULL && fs->bl->insidetbc);\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == luaY_nvarstack(fs));\n}\n\n\n/*\n** generates an error for an undefined 'goto'.\n*/\nstatic l_noret undefgoto (LexState *ls, Labeldesc *gt) {\n  const char *msg;\n  if (eqstr(gt->name, luaS_newliteral(ls->L, \"break\"))) {\n    msg = \"break outside loop at line %d\";\n    msg = luaO_pushfstring(ls->L, msg, gt->line);\n  }\n  else {\n    msg = \"no visible label '%s' for <goto> at line %d\";\n    msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);\n  }\n  luaK_semerror(ls, msg);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  LexState *ls = fs->ls;\n  int hasclose = 0;\n  int stklevel = stacklevel(fs, bl->nactvar);  /* level outside the block */\n  if (bl->isloop)  /* fix pending breaks? */\n    hasclose = createlabel(ls, luaS_newliteral(ls->L, \"break\"), 0, 0);\n  if (!hasclose && bl->previous && bl->upval)\n    luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0);\n  fs->bl = bl->previous;\n  removevars(fs, bl->nactvar);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = stklevel;  /* free registers */\n  ls->dyd->label.n = bl->firstlabel;  /* remove local labels */\n  if (bl->previous)  /* inner block? */\n    movegotosout(fs, bl);  /* update pending gotos to outer block */\n  else {\n    if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */\n      undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */\n  }\n}\n\n\n/*\n** adds a new prototype into list of prototypes\n*/\nstatic Proto *addprototype (LexState *ls) {\n  Proto *clp;\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;  /* prototype of current function */\n  if (fs->np >= f->sizep) {\n    int oldsize = f->sizep;\n    luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, \"functions\");\n    while (oldsize < f->sizep)\n      f->p[oldsize++] = NULL;\n  }\n  f->p[fs->np++] = clp = luaF_newproto(L);\n  luaC_objbarrier(L, f, clp);\n  return clp;\n}\n\n\n/*\n** codes instruction to create new closure in parent function.\n** The OP_CLOSURE instruction uses the last available register,\n** so that, if it invokes the GC, the GC knows which registers\n** are in use at that time.\n\n*/\nstatic void codeclosure (LexState *ls, expdesc *v) {\n  FuncState *fs = ls->fs->prev;\n  init_exp(v, VRELOC, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));\n  luaK_exp2nextreg(fs, v);  /* fix it at the last register */\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {\n  Proto *f = fs->f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->previousline = f->linedefined;\n  fs->iwthabs = 0;\n  fs->lasttarget = 0;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->nabslineinfo = 0;\n  fs->np = 0;\n  fs->nups = 0;\n  fs->ndebugvars = 0;\n  fs->nactvar = 0;\n  fs->needclose = 0;\n  fs->firstlocal = ls->dyd->actvar.n;\n  fs->firstlabel = ls->dyd->label.n;\n  fs->bl = NULL;\n  f->source = ls->source;\n  luaC_objbarrier(ls->L, f, f->source);\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  enterblock(fs, bl, 0);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  luaK_ret(fs, luaY_nvarstack(fs), 0);  /* final return */\n  leaveblock(fs);\n  lua_assert(fs->bl == NULL);\n  luaK_finish(fs);\n  luaM_shrinkvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  luaM_shrinkvector(L, f->lineinfo, f->sizelineinfo, fs->pc, ls_byte);\n  luaM_shrinkvector(L, f->abslineinfo, f->sizeabslineinfo,\n                       fs->nabslineinfo, AbsLineInfo);\n  luaM_shrinkvector(L, f->k, f->sizek, fs->nk, TValue);\n  luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *);\n  luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar);\n  luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);\n  ls->fs = fs->prev;\n  luaC_checkGC(L);\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\n/*\n** check whether current token is in the follow set of a block.\n** 'until' closes syntactical blocks, but do not close scope,\n** so it is handled in separate.\n*/\nstatic int block_follow (LexState *ls, int withuntil) {\n  switch (ls->t.token) {\n    case TK_ELSE: case TK_ELSEIF:\n    case TK_END: case TK_EOS:\n      return 1;\n    case TK_UNTIL: return withuntil;\n    default: return 0;\n  }\n}\n\n\nstatic void statlist (LexState *ls) {\n  /* statlist -> { stat [';'] } */\n  while (!block_follow(ls, 1)) {\n    if (ls->t.token == TK_RETURN) {\n      statement(ls);\n      return;  /* 'return' must be last statement */\n    }\n    statement(ls);\n  }\n}\n\n\nstatic void fieldsel (LexState *ls, expdesc *v) {\n  /* fieldsel -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyregup(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  codename(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\ntypedef struct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of 'record' elements */\n  int na;  /* number of array elements already stored */\n  int tostore;  /* number of array elements pending to be stored */\n} ConsControl;\n\n\nstatic void recfield (LexState *ls, ConsControl *cc) {\n  /* recfield -> (NAME | '['exp']') = exp */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc tab, key, val;\n  if (ls->t.token == TK_NAME) {\n    checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    codename(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  tab = *cc->t;\n  luaK_indexed(fs, &tab, &key);\n  expr(ls, &val);\n  luaK_storevar(fs, &tab, &val);\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);  /* flush */\n    cc->na += cc->tostore;\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);\n  }\n  cc->na += cc->tostore;\n}\n\n\nstatic void listfield (LexState *ls, ConsControl *cc) {\n  /* listfield -> exp */\n  expr(ls, &cc->v);\n  cc->tostore++;\n}\n\n\nstatic void field (LexState *ls, ConsControl *cc) {\n  /* field -> listfield | recfield */\n  switch(ls->t.token) {\n    case TK_NAME: {  /* may be 'listfield' or 'recfield' */\n      if (luaX_lookahead(ls) != '=')  /* expression? */\n        listfield(ls, cc);\n      else\n        recfield(ls, cc);\n      break;\n    }\n    case '[': {\n      recfield(ls, cc);\n      break;\n    }\n    default: {\n      listfield(ls, cc);\n      break;\n    }\n  }\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> '{' [ field { sep field } [sep] ] '}'\n     sep -> ',' | ';' */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  ConsControl cc;\n  luaK_code(fs, 0);  /* space for extra arg. */\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VNONRELOC, fs->freereg);  /* table will be at stack top */\n  luaK_reserveregs(fs, 1);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    field(ls, &cc);\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh);\n}\n\n/* }====================================================================== */\n\n\nstatic void setvararg (FuncState *fs, int nparams) {\n  fs->f->is_vararg = 1;\n  luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);\n}\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { ',' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  int isvararg = 0;\n  if (ls->t.token != ')') {  /* is 'parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls));\n          nparams++;\n          break;\n        }\n        case TK_DOTS: {  /* param -> '...' */\n          luaX_next(ls);\n          isvararg = 1;\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or '...' expected\");\n      }\n    } while (!isvararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar);\n  if (isvararg)\n    setvararg(fs, f->numparams);  /* declared vararg */\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve registers for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int ismethod, int line) {\n  /* body ->  '(' parlist ')' block END */\n  FuncState new_fs;\n  BlockCnt bl;\n  new_fs.f = addprototype(ls);\n  new_fs.f->linedefined = line;\n  open_func(ls, &new_fs, &bl);\n  checknext(ls, '(');\n  if (ismethod) {\n    new_localvarliteral(ls, \"self\");  /* create 'self' parameter */\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  statlist(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  codeclosure(ls, e);\n  close_func(ls);\n}\n\n\nstatic int explist (LexState *ls, expdesc *v) {\n  /* explist -> expr { ',' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f, int line) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> '(' [ explist ] ')' */\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist(ls, &args);\n        if (hasmultret(args.k))\n          luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(&args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use 'seminfo' before 'next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n    }\n  }\n}\n\n\nstatic void suffixedexp (LexState *ls, expdesc *v) {\n  /* suffixedexp ->\n       primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  primaryexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* fieldsel */\n        fieldsel(ls, v);\n        break;\n      }\n      case '[': {  /* '[' exp ']' */\n        expdesc key;\n        luaK_exp2anyregup(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* ':' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        codename(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v, line);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v, line);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |\n                  constructor | FUNCTION body | suffixedexp */\n  switch (ls->t.token) {\n    case TK_FLT: {\n      init_exp(v, VKFLT, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_INT: {\n      init_exp(v, VKINT, 0);\n      v->u.ival = ls->t.seminfo.i;\n      break;\n    }\n    case TK_STRING: {\n      codestring(v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use '...' outside a vararg function\");\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      suffixedexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '~': return OPR_BNOT;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case '/': return OPR_DIV;\n    case TK_IDIV: return OPR_IDIV;\n    case '&': return OPR_BAND;\n    case '|': return OPR_BOR;\n    case '~': return OPR_BXOR;\n    case TK_SHL: return OPR_SHL;\n    case TK_SHR: return OPR_SHR;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\n/*\n** Priority table for binary operators.\n*/\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {10, 10}, {10, 10},           /* '+' '-' */\n   {11, 11}, {11, 11},           /* '*' '%' */\n   {14, 13},                  /* '^' (right associative) */\n   {11, 11}, {11, 11},           /* '/' '//' */\n   {6, 6}, {4, 4}, {5, 5},   /* '&' '|' '~' */\n   {7, 7}, {7, 7},           /* '<<' '>>' */\n   {9, 8},                   /* '..' (right associative) */\n   {3, 3}, {3, 3}, {3, 3},   /* ==, <, <= */\n   {3, 3}, {3, 3}, {3, 3},   /* ~=, >, >= */\n   {2, 2}, {1, 1}            /* and, or */\n};\n\n#define UNARY_PRIORITY\t12  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where 'binop' is any binary operator with a priority higher than 'limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {  /* prefix (unary) operator? */\n    int line = ls->linenumber;\n    luaX_next(ls);  /* skip operator */\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v, line);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than 'limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    int line = ls->linenumber;\n    luaX_next(ls);  /* skip operator */\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2, line);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic void block (LexState *ls) {\n  /* block -> statlist */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  statlist(ls);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to an upvalue/local variable, the\n** upvalue/local variable is begin used in a previous assignment to a\n** table. If so, save original upvalue/local value in a safe place and\n** use this safe copy in the previous assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {  /* check all previous assignments */\n    if (vkisindexed(lh->v.k)) {  /* assignment to table field? */\n      if (lh->v.k == VINDEXUP) {  /* is table an upvalue? */\n        if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {\n          conflict = 1;  /* table is the upvalue being assigned now */\n          lh->v.k = VINDEXSTR;\n          lh->v.u.ind.t = extra;  /* assignment will use safe copy */\n        }\n      }\n      else {  /* table is a register */\n        if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.sidx) {\n          conflict = 1;  /* table is the local being assigned now */\n          lh->v.u.ind.t = extra;  /* assignment will use safe copy */\n        }\n        /* is index the local being assigned? */\n        if (lh->v.k == VINDEXED && v->k == VLOCAL &&\n            lh->v.u.ind.idx == v->u.var.sidx) {\n          conflict = 1;\n          lh->v.u.ind.idx = extra;  /* previous assignment will use safe copy */\n        }\n      }\n    }\n  }\n  if (conflict) {\n    /* copy upvalue/local value to a temporary (in position 'extra') */\n    if (v->k == VLOCAL)\n      luaK_codeABC(fs, OP_MOVE, extra, v->u.var.sidx, 0);\n    else\n      luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n/*\n** Parse and compile a multiple assignment. The first \"variable\"\n** (a 'suffixedexp') was already read by the caller.\n**\n** assignment -> suffixedexp restassign\n** restassign -> ',' suffixedexp restassign | '=' explist\n*/\nstatic void restassign (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, vkisvar(lh->v.k), \"syntax error\");\n  check_readonly(ls, &lh->v);\n  if (testnext(ls, ',')) {  /* restassign -> ',' suffixedexp restassign */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    suffixedexp(ls, &nv.v);\n    if (!vkisindexed(nv.v.k))\n      check_conflict(ls, lh, &nv.v);\n    enterlevel(ls);  /* control recursion depth */\n    restassign(ls, &nv, nvars+1);\n    leavelevel(ls);\n  }\n  else {  /* restassign -> '=' explist */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist(ls, &e);\n    if (nexps != nvars)\n      adjust_assign(ls, nvars, nexps, &e);\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* 'falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void gotostat (LexState *ls) {\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  TString *name = str_checkname(ls);  /* label's name */\n  Labeldesc *lb = findlabel(ls, name);\n  if (lb == NULL)  /* no label? */\n    /* forward jump; will be resolved when the label is declared */\n    newgotoentry(ls, name, line, luaK_jump(fs));\n  else {  /* found a label */\n    /* backward jump; will be resolved here */\n    int lblevel = stacklevel(fs, lb->nactvar);  /* label level */\n    if (luaY_nvarstack(fs) > lblevel)  /* leaving the scope of a variable? */\n      luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0);\n    /* create jump and link it to the label */\n    luaK_patchlist(fs, luaK_jump(fs), lb->pc);\n  }\n}\n\n\n/*\n** Break statement. Semantically equivalent to \"goto break\".\n*/\nstatic void breakstat (LexState *ls) {\n  int line = ls->linenumber;\n  luaX_next(ls);  /* skip break */\n  newgotoentry(ls, luaS_newliteral(ls->L, \"break\"), line, luaK_jump(ls->fs));\n}\n\n\n/*\n** Check whether there is already a label with the given 'name'.\n*/\nstatic void checkrepeated (LexState *ls, TString *name) {\n  Labeldesc *lb = findlabel(ls, name);\n  if (unlikely(lb != NULL)) {  /* already defined? */\n    const char *msg = \"label '%s' already defined on line %d\";\n    msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line);\n    luaK_semerror(ls, msg);  /* error */\n  }\n}\n\n\nstatic void labelstat (LexState *ls, TString *name, int line) {\n  /* label -> '::' NAME '::' */\n  checknext(ls, TK_DBCOLON);  /* skip double colon */\n  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)\n    statement(ls);  /* skip other no-op statements */\n  checkrepeated(ls, name);  /* check for repeated labels */\n  createlabel(ls, name, line, block_follow(ls, 0));\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_jumpto(fs, whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  statlist(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  leaveblock(fs);  /* finish scope */\n  if (bl2.upval) {  /* upvalues? */\n    int exit = luaK_jump(fs);  /* normal exit must jump over fix */\n    luaK_patchtohere(fs, condexit);  /* repetition must close upvalues */\n    luaK_codeABC(fs, OP_CLOSE, stacklevel(fs, bl2.nactvar), 0, 0);\n    condexit = luaK_jump(fs);  /* repeat after closing upvalues */\n    luaK_patchtohere(fs, exit);  /* normal exit comes to here */\n  }\n  luaK_patchlist(fs, condexit, repeat_init);  /* close the loop */\n  leaveblock(fs);  /* finish loop */\n}\n\n\n/*\n** Read an expression and generate code to put its results in next\n** stack slot.\n**\n*/\nstatic void exp1 (LexState *ls) {\n  expdesc e;\n  expr(ls, &e);\n  luaK_exp2nextreg(ls->fs, &e);\n  lua_assert(e.k == VNONRELOC);\n}\n\n\n/*\n** Fix for instruction at position 'pc' to jump to 'dest'.\n** (Jump addresses are relative in Lua). 'back' true means\n** a back jump.\n*/\nstatic void fixforjump (FuncState *fs, int pc, int dest, int back) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest - (pc + 1);\n  if (back)\n    offset = -offset;\n  if (unlikely(offset > MAXARG_Bx))\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_Bx(*jmp, offset);\n}\n\n\n/*\n** Generate code for a 'for' loop.\n*/\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isgen) {\n  /* forbody -> DO block */\n  static const OpCode forprep[2] = {OP_FORPREP, OP_TFORPREP};\n  static const OpCode forloop[2] = {OP_FORLOOP, OP_TFORLOOP};\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  checknext(ls, TK_DO);\n  prep = luaK_codeABx(fs, forprep[isgen], base, 0);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  fixforjump(fs, prep, luaK_getlabel(fs), 0);\n  if (isgen) {  /* generic for? */\n    luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);\n    luaK_fixline(fs, line);\n  }\n  endfor = luaK_codeABx(fs, forloop[isgen], base, 0);\n  fixforjump(fs, endfor, prep + 1, 1);\n  luaK_fixline(fs, line);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp,exp[,exp] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvar(ls, varname);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_int(fs, fs->freereg, 1);\n    luaK_reserveregs(fs, 1);\n  }\n  adjustlocalvars(ls, 3);  /* control variables */\n  forbody(ls, base, line, 1, 0);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 5;  /* gen, state, control, toclose, 'indexname' */\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for state)\");\n  new_localvarliteral(ls, \"(for state)\");\n  /* create declared variables */\n  new_localvar(ls, indexname);\n  while (testnext(ls, ',')) {\n    new_localvar(ls, str_checkname(ls));\n    nvars++;\n  }\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 4, explist(ls, &e), &e);\n  adjustlocalvars(ls, 4);  /* control variables */\n  markupval(fs, fs->nactvar);  /* last control var. must be closed */\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 4, 1);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip 'for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, \"'=' or 'in' expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope ('break' jumps to this point) */\n}\n\n\n/*\n** Check whether next instruction is a single jump (a 'break', a 'goto'\n** to a forward label, or a 'goto' to a backward label with no variable\n** to close). If so, set the name of the 'label' it is jumping to\n** (\"break\" for a 'break') or to where it is jumping to ('target') and\n** return true. If not a single jump, leave input unchanged, to be\n** handled as a regular statement.\n*/\nstatic int issinglejump (LexState *ls, TString **label, int *target) {\n  if (testnext(ls, TK_BREAK)) {  /* a break? */\n    *label = luaS_newliteral(ls->L, \"break\");\n    return 1;\n  }\n  else if (ls->t.token != TK_GOTO || luaX_lookahead(ls) != TK_NAME)\n    return 0;  /* not a valid goto */\n  else {\n    TString *lname = ls->lookahead.seminfo.ts;  /* label's id */\n    Labeldesc *lb = findlabel(ls, lname);\n    if (lb) {  /* a backward jump? */\n      /* does it need to close variables? */\n      if (luaY_nvarstack(ls->fs) > stacklevel(ls->fs, lb->nactvar))\n        return 0;  /* not a single jump; cannot optimize */\n      *target = lb->pc;\n    }\n    else  /* jump forward */\n      *label = lname;\n    luaX_next(ls);  /* skip goto */\n    luaX_next(ls);  /* skip name */\n    return 1;\n  }\n}\n\n\nstatic void test_then_block (LexState *ls, int *escapelist) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  BlockCnt bl;\n  int line;\n  FuncState *fs = ls->fs;\n  TString *jlb = NULL;\n  int target = NO_JUMP;\n  expdesc v;\n  int jf;  /* instruction to skip 'then' code (if condition is false) */\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  expr(ls, &v);  /* read condition */\n  checknext(ls, TK_THEN);\n  line = ls->linenumber;\n  if (issinglejump(ls, &jlb, &target)) {  /* 'if x then goto' ? */\n    luaK_goiffalse(ls->fs, &v);  /* will jump to label if condition is true */\n    enterblock(fs, &bl, 0);  /* must enter block before 'goto' */\n    if (jlb != NULL)  /* forward jump? */\n      newgotoentry(ls, jlb, line, v.t);  /* will be resolved later */\n    else  /* backward jump */\n      luaK_patchlist(fs, v.t, target);  /* jump directly to 'target' */\n    while (testnext(ls, ';')) {}  /* skip semicolons */\n    if (block_follow(ls, 0)) {  /* jump is the entire block? */\n      leaveblock(fs);\n      return;  /* and that is it */\n    }\n    else  /* must skip over 'then' part if condition is false */\n      jf = luaK_jump(fs);\n  }\n  else {  /* regular case (not a jump) */\n    luaK_goiftrue(ls->fs, &v);  /* skip over block if condition is false */\n    enterblock(fs, &bl, 0);\n    jf = v.f;\n  }\n  statlist(ls);  /* 'then' part */\n  leaveblock(fs);\n  if (ls->t.token == TK_ELSE ||\n      ls->t.token == TK_ELSEIF)  /* followed by 'else'/'elseif'? */\n    luaK_concat(fs, escapelist, luaK_jump(fs));  /* must jump over it */\n  luaK_patchtohere(fs, jf);\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int escapelist = NO_JUMP;  /* exit list for finished parts */\n  test_then_block(ls, &escapelist);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF)\n    test_then_block(ls, &escapelist);  /* ELSEIF cond THEN block */\n  if (testnext(ls, TK_ELSE))\n    block(ls);  /* 'else' part */\n  check_match(ls, TK_END, TK_IF, line);\n  luaK_patchtohere(fs, escapelist);  /* patch escape list to 'if' end */\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc b;\n  FuncState *fs = ls->fs;\n  int fvar = fs->nactvar;  /* function's variable index */\n  new_localvar(ls, str_checkname(ls));  /* new local variable */\n  adjustlocalvars(ls, 1);  /* enter its scope */\n  body(ls, &b, 0, ls->linenumber);  /* function created in next register */\n  /* debug information will only see the variable after this point! */\n  localdebuginfo(fs, fvar)->startpc = fs->pc;\n}\n\n\nstatic int getlocalattribute (LexState *ls) {\n  /* ATTRIB -> ['<' Name '>'] */\n  if (testnext(ls, '<')) {\n    const char *attr = getstr(str_checkname(ls));\n    checknext(ls, '>');\n    if (strcmp(attr, \"const\") == 0)\n      return RDKCONST;  /* read-only variable */\n    else if (strcmp(attr, \"close\") == 0)\n      return RDKTOCLOSE;  /* to-be-closed variable */\n    else\n      luaK_semerror(ls,\n        luaO_pushfstring(ls->L, \"unknown attribute '%s'\", attr));\n  }\n  return VDKREG;  /* regular variable */\n}\n\n\nstatic void checktoclose (LexState *ls, int level) {\n  if (level != -1) {  /* is there a to-be-closed variable? */\n    FuncState *fs = ls->fs;\n    markupval(fs, level + 1);\n    fs->bl->insidetbc = 1;  /* in the scope of a to-be-closed variable */\n    luaK_codeABC(fs, OP_TBC, stacklevel(fs, level), 0, 0);\n  }\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL ATTRIB NAME {',' ATTRIB NAME} ['=' explist] */\n  FuncState *fs = ls->fs;\n  int toclose = -1;  /* index of to-be-closed variable (if any) */\n  Vardesc *var;  /* last variable */\n  int vidx, kind;  /* index and kind of last variable */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    vidx = new_localvar(ls, str_checkname(ls));\n    kind = getlocalattribute(ls);\n    getlocalvardesc(fs, vidx)->vd.kind = kind;\n    if (kind == RDKTOCLOSE) {  /* to-be-closed? */\n      if (toclose != -1)  /* one already present? */\n        luaK_semerror(ls, \"multiple to-be-closed variables in local list\");\n      toclose = fs->nactvar + nvars;\n    }\n    nvars++;\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  var = getlocalvardesc(fs, vidx);  /* get last variable */\n  if (nvars == nexps &&  /* no adjustments? */\n      var->vd.kind == RDKCONST &&  /* last variable is const? */\n      luaK_exp2const(fs, &e, &var->k)) {  /* compile-time constant? */\n    var->vd.kind = RDKCTC;  /* variable is a compile-time constant */\n    adjustlocalvars(ls, nvars - 1);  /* exclude last variable */\n    fs->nactvar++;  /* but count it */\n  }\n  else {\n    adjust_assign(ls, nvars, nexps, &e);\n    adjustlocalvars(ls, nvars);\n  }\n  checktoclose(ls, toclose);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {fieldsel} [':' NAME] */\n  int ismethod = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    fieldsel(ls, v);\n  if (ls->t.token == ':') {\n    ismethod = 1;\n    fieldsel(ls, v);\n  }\n  return ismethod;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int ismethod;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  ismethod = funcname(ls, &v);\n  body(ls, &b, ismethod, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition \"happens\" in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  suffixedexp(ls, &v.v);\n  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */\n    v.prev = NULL;\n    restassign(ls, &v, 1);\n  }\n  else {  /* stat -> func */\n    Instruction *inst;\n    check_condition(ls, v.v.k == VCALL, \"syntax error\");\n    inst = &getinstruction(fs, &v.v);\n    SETARG_C(*inst, 1);  /* call statement uses no results */\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN [explist] [';'] */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nret;  /* number of values being returned */\n  int first = luaY_nvarstack(fs);  /* first slot to be returned */\n  if (block_follow(ls, 1) || ls->t.token == ';')\n    nret = 0;  /* return no values */\n  else {\n    nret = explist(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) {  /* tail call? */\n        SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getinstruction(fs,&e)) == luaY_nvarstack(fs));\n      }\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);  /* can use original slot */\n      else {  /* values must go to the top of the stack */\n        luaK_exp2nextreg(fs, &e);\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n  testnext(ls, ';');  /* skip optional semicolon */\n}\n\n\nstatic void statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  enterlevel(ls);\n  switch (ls->t.token) {\n    case ';': {  /* stat -> ';' (empty statement) */\n      luaX_next(ls);  /* skip ';' */\n      break;\n    }\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      break;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      break;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      break;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      break;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      break;\n    }\n    case TK_FUNCTION: {  /* stat -> funcstat */\n      funcstat(ls, line);\n      break;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      break;\n    }\n    case TK_DBCOLON: {  /* stat -> label */\n      luaX_next(ls);  /* skip double colon */\n      labelstat(ls, str_checkname(ls), line);\n      break;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      luaX_next(ls);  /* skip RETURN */\n      retstat(ls);\n      break;\n    }\n    case TK_BREAK: {  /* stat -> breakstat */\n      breakstat(ls);\n      break;\n    }\n    case TK_GOTO: {  /* stat -> 'goto' NAME */\n      luaX_next(ls);  /* skip 'goto' */\n      gotostat(ls);\n      break;\n    }\n    default: {  /* stat -> func | assignment */\n      exprstat(ls);\n      break;\n    }\n  }\n  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n             ls->fs->freereg >= luaY_nvarstack(ls->fs));\n  ls->fs->freereg = luaY_nvarstack(ls->fs);  /* free registers */\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n\n\n/*\n** compiles the main function, which is a regular vararg function with an\n** upvalue named LUA_ENV\n*/\nstatic void mainfunc (LexState *ls, FuncState *fs) {\n  BlockCnt bl;\n  Upvaldesc *env;\n  open_func(ls, fs, &bl);\n  setvararg(fs, 0);  /* main function is always declared vararg */\n  env = allocupvalue(fs);  /* ...set environment upvalue */\n  env->instack = 1;\n  env->idx = 0;\n  env->kind = VDKREG;\n  env->name = ls->envn;\n  luaC_objbarrier(ls->L, fs->f, env->name);\n  luaX_next(ls);  /* read first token */\n  statlist(ls);  /* parse main body */\n  check(ls, TK_EOS);\n  close_func(ls);\n}\n\n\nLClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                       Dyndata *dyd, const char *name, int firstchar) {\n  LexState lexstate;\n  FuncState funcstate;\n  LClosure *cl = luaF_newLclosure(L, 1);  /* create main closure */\n  setclLvalue2s(L, L->top, cl);  /* anchor it (to avoid being collected) */\n  luaD_inctop(L);\n  lexstate.h = luaH_new(L);  /* create table for scanner */\n  sethvalue2s(L, L->top, lexstate.h);  /* anchor it */\n  luaD_inctop(L);\n  funcstate.f = cl->p = luaF_newproto(L);\n  luaC_objbarrier(L, cl, cl->p);\n  funcstate.f->source = luaS_new(L, name);  /* create and anchor TString */\n  luaC_objbarrier(L, funcstate.f, funcstate.f->source);\n  lexstate.buff = buff;\n  lexstate.dyd = dyd;\n  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;\n  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);\n  mainfunc(&lexstate, &funcstate);\n  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);\n  /* all scopes should be correctly finished */\n  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);\n  L->top--;  /* remove scanner's table */\n  return cl;  /* closure is on the stack, too */\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lparser.h",
    "content": "/*\n** $Id: lparser.h $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression and variable descriptor.\n** Code generation for variables and expressions can be delayed to allow\n** optimizations; An 'expdesc' structure describes a potentially-delayed\n** variable/expression. It has a description of its \"main\" value plus a\n** list of conditional jumps that can also produce its value (generated\n** by short-circuit operators 'and'/'or').\n*/\n\n/* kinds of variables/expressions */\ntypedef enum {\n  VVOID,  /* when 'expdesc' describes the last expression a list,\n             this kind means an empty list (so, no expression) */\n  VNIL,  /* constant nil */\n  VTRUE,  /* constant true */\n  VFALSE,  /* constant false */\n  VK,  /* constant in 'k'; info = index of constant in 'k' */\n  VKFLT,  /* floating constant; nval = numerical float value */\n  VKINT,  /* integer constant; ival = numerical integer value */\n  VKSTR,  /* string constant; strval = TString address;\n             (string is fixed by the lexer) */\n  VNONRELOC,  /* expression has its value in a fixed register;\n                 info = result register */\n  VLOCAL,  /* local variable; var.sidx = stack index (local register);\n              var.vidx = relative index in 'actvar.arr'  */\n  VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */\n  VCONST,  /* compile-time constant; info = absolute index in 'actvar.arr'  */\n  VINDEXED,  /* indexed variable;\n                ind.t = table register;\n                ind.idx = key's R index */\n  VINDEXUP,  /* indexed upvalue;\n                ind.t = table upvalue;\n                ind.idx = key's K index */\n  VINDEXI, /* indexed variable with constant integer;\n                ind.t = table register;\n                ind.idx = key's value */\n  VINDEXSTR, /* indexed variable with literal string;\n                ind.t = table register;\n                ind.idx = key's K index */\n  VJMP,  /* expression is a test/comparison;\n            info = pc of corresponding jump instruction */\n  VRELOC,  /* expression can put result in any register;\n              info = instruction pc */\n  VCALL,  /* expression is a function call; info = instruction pc */\n  VVARARG  /* vararg expression; info = instruction pc */\n} expkind;\n\n\n#define vkisvar(k)\t(VLOCAL <= (k) && (k) <= VINDEXSTR)\n#define vkisindexed(k)\t(VINDEXED <= (k) && (k) <= VINDEXSTR)\n\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    lua_Integer ival;    /* for VKINT */\n    lua_Number nval;  /* for VKFLT */\n    TString *strval;  /* for VKSTR */\n    int info;  /* for generic use */\n    struct {  /* for indexed variables */\n      short idx;  /* index (R or \"long\" K) */\n      lu_byte t;  /* table (register or upvalue) */\n    } ind;\n    struct {  /* for local variables */\n      lu_byte sidx;  /* index in the stack */\n      unsigned short vidx;  /* compiler index (in 'actvar.arr')  */\n    } var;\n  } u;\n  int t;  /* patch list of 'exit when true' */\n  int f;  /* patch list of 'exit when false' */\n} expdesc;\n\n\n/* kinds of variables */\n#define VDKREG\t\t0   /* regular */\n#define RDKCONST\t1   /* constant */\n#define RDKTOCLOSE\t2   /* to-be-closed */\n#define RDKCTC\t\t3   /* compile-time constant */\n\n/* description of an active local variable */\ntypedef union Vardesc {\n  struct {\n    TValuefields;  /* constant value (if it is a compile-time constant) */\n    lu_byte kind;\n    lu_byte sidx;  /* index of the variable in the stack */\n    short pidx;  /* index of the variable in the Proto's 'locvars' array */\n    TString *name;  /* variable name */\n  } vd;\n  TValue k;  /* constant value (if any) */\n} Vardesc;\n\n\n\n/* description of pending goto statements and label statements */\ntypedef struct Labeldesc {\n  TString *name;  /* label identifier */\n  int pc;  /* position in code */\n  int line;  /* line where it appeared */\n  lu_byte nactvar;  /* number of active variables in that position */\n  lu_byte close;  /* goto that escapes upvalues */\n} Labeldesc;\n\n\n/* list of labels or gotos */\ntypedef struct Labellist {\n  Labeldesc *arr;  /* array */\n  int n;  /* number of entries in use */\n  int size;  /* array size */\n} Labellist;\n\n\n/* dynamic structures used by the parser */\ntypedef struct Dyndata {\n  struct {  /* list of all active local variables */\n    Vardesc *arr;\n    int n;\n    int size;\n  } actvar;\n  Labellist gt;  /* list of pending gotos */\n  Labellist label;   /* list of active labels */\n} Dyndata;\n\n\n/* control of blocks */\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to 'ncode') */\n  int lasttarget;   /* 'label' of last 'jump label' */\n  int previousline;  /* last line that was saved in 'lineinfo' */\n  int nk;  /* number of elements in 'k' */\n  int np;  /* number of elements in 'p' */\n  int nabslineinfo;  /* number of elements in 'abslineinfo' */\n  int firstlocal;  /* index of first local var (in Dyndata array) */\n  int firstlabel;  /* index of first label (in 'dyd->label->arr') */\n  short ndebugvars;  /* number of elements in 'f->locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  lu_byte nups;  /* number of upvalues */\n  lu_byte freereg;  /* first free register */\n  lu_byte iwthabs;  /* instructions issued since last absolute line info */\n  lu_byte needclose;  /* function needs to close upvalues when returning */\n} FuncState;\n\n\nLUAI_FUNC int luaY_nvarstack (FuncState *fs);\nLUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                 Dyndata *dyd, const char *name, int firstchar);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lprefix.h",
    "content": "/*\n** $Id: lprefix.h $\n** Definitions for Lua code that must come before any other header file\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lprefix_h\n#define lprefix_h\n\n\n/*\n** Allows POSIX/XSI stuff\n*/\n#if !defined(LUA_USE_C89)\t/* { */\n\n#if !defined(_XOPEN_SOURCE)\n#define _XOPEN_SOURCE           600\n#elif _XOPEN_SOURCE == 0\n#undef _XOPEN_SOURCE  /* use -D_XOPEN_SOURCE=0 to undefine it */\n#endif\n\n/*\n** Allows manipulation of large files in gcc and some other compilers\n*/\n#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)\n#define _LARGEFILE_SOURCE       1\n#define _FILE_OFFSET_BITS       64\n#endif\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Windows stuff\n*/\n#if defined(_WIN32)\t/* { */\n\n#if !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS  /* avoid warnings about ISO C functions */\n#endif\n\n#endif\t\t\t/* } */\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lstate.c",
    "content": "/*\n** $Id: lstate.c $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n\n/*\n** thread state + extra space\n*/\ntypedef struct LX {\n  lu_byte extra_[LUA_EXTRASPACE];\n  lua_State l;\n} LX;\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  LX l;\n  global_State g;\n} LG;\n\n\n\n#define fromstate(L)\t(cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))\n\n\n/*\n** A macro to create a \"random\" seed when a state is created;\n** the seed is used to randomize string hashes.\n*/\n#if !defined(luai_makeseed)\n\n#include <time.h>\n\n/*\n** Compute an initial seed with some level of randomness.\n** Rely on Address Space Layout Randomization (if present) and\n** current time.\n*/\n#define addbuff(b,p,e) \\\n  { size_t t = cast_sizet(e); \\\n    memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }\n\nstatic unsigned int luai_makeseed (lua_State *L) {\n  char buff[3 * sizeof(size_t)];\n  unsigned int h = cast_uint(time(NULL));\n  int p = 0;\n  addbuff(buff, p, L);  /* heap variable */\n  addbuff(buff, p, &h);  /* local variable */\n  addbuff(buff, p, &lua_newstate);  /* public function */\n  lua_assert(p == sizeof(buff));\n  return luaS_hash(buff, p, h, 1);\n}\n\n#endif\n\n\n/*\n** set GCdebt to a new value keeping the value (totalbytes + GCdebt)\n** invariant (and avoiding underflows in 'totalbytes')\n*/\nvoid luaE_setdebt (global_State *g, l_mem debt) {\n  l_mem tb = gettotalbytes(g);\n  lua_assert(tb > 0);\n  if (debt < tb - MAX_LMEM)\n    debt = tb - MAX_LMEM;  /* will make 'totalbytes == MAX_LMEM' */\n  g->totalbytes = tb - debt;\n  g->GCdebt = debt;\n}\n\n\nLUA_API int lua_setcstacklimit (lua_State *L, unsigned int limit) {\n  global_State *g = G(L);\n  int ccalls;\n  luaE_freeCI(L);  /* release unused CIs */\n  ccalls = getCcalls(L);\n  if (limit >= 40000)\n    return 0;  /* out of bounds */\n  limit += CSTACKERR;\n  if (L != g-> mainthread)\n    return 0;  /* only main thread can change the C stack */\n  else if (ccalls <= CSTACKERR)\n    return 0;  /* handling overflow */\n  else {\n    int diff = limit - g->Cstacklimit;\n    if (ccalls + diff <= CSTACKERR)\n      return 0;  /* new limit would cause an overflow */\n    g->Cstacklimit = limit;  /* set new limit */\n    L->nCcalls += diff;  /* correct 'nCcalls' */\n    return limit - diff - CSTACKERR;  /* success; return previous limit */\n  }\n}\n\n\n/*\n** Decrement count of \"C calls\" and check for overflows. In case of\n** a stack overflow, check appropriate error (\"regular\" overflow or\n** overflow while handling stack overflow).  If 'nCcalls' is smaller\n** than CSTACKERR but larger than CSTACKMARK, it means it has just\n** entered the \"overflow zone\", so the function raises an overflow\n** error.  If 'nCcalls' is smaller than CSTACKMARK (which means it is\n** already handling an overflow) but larger than CSTACKERRMARK, does\n** not report an error (to allow message handling to work). Otherwise,\n** report a stack overflow while handling a stack overflow (probably\n** caused by a repeating error in the message handling function).\n*/\n\nvoid luaE_enterCcall (lua_State *L) {\n  int ncalls = getCcalls(L);\n  L->nCcalls--;\n  if (ncalls <= CSTACKERR) {  /* possible overflow? */\n    luaE_freeCI(L);  /* release unused CIs */\n    ncalls = getCcalls(L);  /* update call count */\n    if (ncalls <= CSTACKERR) {  /* still overflow? */\n      if (ncalls <= CSTACKERRMARK)  /* below error-handling zone? */\n        luaD_throw(L, LUA_ERRERR);  /* error while handling stack error */\n      else if (ncalls >= CSTACKMARK) {\n        /* not in error-handling zone; raise the error now */\n        L->nCcalls = (CSTACKMARK - 1);  /* enter error-handling zone */\n        luaG_runerror(L, \"C stack overflow\");\n      }\n      /* else stack is in the error-handling zone;\n         allow message handler to work */\n    }\n  }\n}\n\n\nCallInfo *luaE_extendCI (lua_State *L) {\n  CallInfo *ci;\n  lua_assert(L->ci->next == NULL);\n  luaE_enterCcall(L);\n  ci = luaM_new(L, CallInfo);\n  lua_assert(L->ci->next == NULL);\n  L->ci->next = ci;\n  ci->previous = L->ci;\n  ci->next = NULL;\n  ci->u.l.trap = 0;\n  L->nci++;\n  return ci;\n}\n\n\n/*\n** free all CallInfo structures not in use by a thread\n*/\nvoid luaE_freeCI (lua_State *L) {\n  CallInfo *ci = L->ci;\n  CallInfo *next = ci->next;\n  ci->next = NULL;\n  L->nCcalls += L->nci;  /* add removed elements back to 'nCcalls' */\n  while ((ci = next) != NULL) {\n    next = ci->next;\n    luaM_free(L, ci);\n    L->nci--;\n  }\n  L->nCcalls -= L->nci;  /* adjust result */\n}\n\n\n/*\n** free half of the CallInfo structures not in use by a thread,\n** keeping the first one.\n*/\nvoid luaE_shrinkCI (lua_State *L) {\n  CallInfo *ci = L->ci->next;  /* first free CallInfo */\n  CallInfo *next;\n  if (ci == NULL)\n    return;  /* no extra elements */\n  L->nCcalls += L->nci;  /* add removed elements back to 'nCcalls' */\n  while ((next = ci->next) != NULL) {  /* two extra elements? */\n    CallInfo *next2 = next->next;  /* next's next */\n    ci->next = next2;  /* remove next from the list */\n    L->nci--;\n    luaM_free(L, next);  /* free next */\n    if (next2 == NULL)\n      break;  /* no more elements */\n    else {\n      next2->previous = ci;\n      ci = next2;  /* continue */\n    }\n  }\n  L->nCcalls -= L->nci;  /* adjust result */\n}\n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  int i; CallInfo *ci;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue);\n  L1->stacksize = BASIC_STACK_SIZE;\n  for (i = 0; i < BASIC_STACK_SIZE; i++)\n    setnilvalue(s2v(L1->stack + i));  /* erase new stack */\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;\n  /* initialize first ci */\n  ci = &L1->base_ci;\n  ci->next = ci->previous = NULL;\n  ci->callstatus = CIST_C;\n  ci->func = L1->top;\n  ci->u.c.k = NULL;\n  ci->nresults = 0;\n  setnilvalue(s2v(L1->top));  /* 'function' entry for this 'ci' */\n  L1->top++;\n  ci->top = L1->top + LUA_MINSTACK;\n  L1->ci = ci;\n}\n\n\nstatic void freestack (lua_State *L) {\n  if (L->stack == NULL)\n    return;  /* stack not completely built yet */\n  L->ci = &L->base_ci;  /* free the entire 'ci' list */\n  luaE_freeCI(L);\n  lua_assert(L->nci == 0);\n  luaM_freearray(L, L->stack, L->stacksize);  /* free stack array */\n}\n\n\n/*\n** Create registry table and its predefined values\n*/\nstatic void init_registry (lua_State *L, global_State *g) {\n  TValue temp;\n  /* create registry */\n  Table *registry = luaH_new(L);\n  sethvalue(L, &g->l_registry, registry);\n  luaH_resize(L, registry, LUA_RIDX_LAST, 0);\n  /* registry[LUA_RIDX_MAINTHREAD] = L */\n  setthvalue(L, &temp, L);  /* temp = L */\n  luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);\n  /* registry[LUA_RIDX_GLOBALS] = table of globals */\n  sethvalue(L, &temp, luaH_new(L));  /* temp = new table (global table) */\n  luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);\n}\n\n\n/*\n** open parts of the state that may cause memory-allocation errors.\n** ('g->nilvalue' being a nil value flags that the state was completely\n** build.)\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  init_registry(L, g);\n  luaS_init(L);\n  luaT_init(L);\n  luaX_init(L);\n  g->gcrunning = 1;  /* allow gc */\n  setnilvalue(&g->nilvalue);\n  luai_userstateopen(L);\n}\n\n\n/*\n** preinitialize a thread with consistent values without allocating\n** any memory (to avoid errors)\n*/\nstatic void preinit_thread (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->ci = NULL;\n  L->nci = 0;\n  L->stacksize = 0;\n  L->twups = L;  /* thread has no upvalues */\n  L->errorJmp = NULL;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->status = LUA_OK;\n  L->errfunc = 0;\n  L->oldpc = 0;\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack, CLOSEPROTECT);  /* close all upvalues */\n  luaC_freeallobjects(L);  /* collect all objects */\n  if (ttisnil(&g->nilvalue))  /* closing a fully built state? */\n    luai_userstateclose(L);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);\n  freestack(L);\n  lua_assert(gettotalbytes(g) == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0);  /* free main block */\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  global_State *g;\n  lua_State *L1;\n  lua_lock(L);\n  g = G(L);\n  luaC_checkGC(L);\n  /* create new thread */\n  L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;\n  L1->marked = luaC_white(g);\n  L1->tt = LUA_VTHREAD;\n  /* link it on list 'allgc' */\n  L1->next = g->allgc;\n  g->allgc = obj2gco(L1);\n  /* anchor it on L stack */\n  setthvalue2s(L, L->top, L1);\n  api_incr_top(L);\n  preinit_thread(L1, g);\n  L1->nCcalls = getCcalls(L);\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  /* initialize L1 extra space */\n  memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread),\n         LUA_EXTRASPACE);\n  luai_userstatethread(L, L1);\n  stack_init(L1, L);  /* init stack */\n  lua_unlock(L);\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  LX *l = fromstate(L1);\n  luaF_close(L1, L1->stack, NOCLOSINGMETH);  /* close all upvalues */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L, L1);\n  freestack(L1);\n  luaM_free(L, l);\n}\n\n\nint lua_resetthread (lua_State *L) {\n  CallInfo *ci;\n  int status;\n  lua_lock(L);\n  L->ci = ci = &L->base_ci;  /* unwind CallInfo list */\n  setnilvalue(s2v(L->stack));  /* 'function' entry for basic 'ci' */\n  ci->func = L->stack;\n  ci->callstatus = CIST_C;\n  status = luaF_close(L, L->stack, CLOSEPROTECT);\n  if (status != CLOSEPROTECT)  /* real errors? */\n    luaD_seterrorobj(L, status, L->stack + 1);\n  else {\n    status = LUA_OK;\n    L->top = L->stack + 1;\n  }\n  ci->top = L->top + LUA_MINSTACK;\n  L->status = status;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));\n  if (l == NULL) return NULL;\n  L = &l->l.l;\n  g = &l->g;\n  L->tt = LUA_VTHREAD;\n  g->currentwhite = bitmask(WHITE0BIT);\n  L->marked = luaC_white(g);\n  preinit_thread(L, g);\n  g->allgc = obj2gco(L);  /* by now, only object is the main thread */\n  L->next = NULL;\n  g->Cstacklimit = L->nCcalls = LUAI_MAXCSTACK + CSTACKERR;\n  incnny(L);  /* main thread is always non yieldable */\n  g->frealloc = f;\n  g->ud = ud;\n  g->warnf = NULL;\n  g->ud_warn = NULL;\n  g->mainthread = L;\n  g->seed = luai_makeseed(L);\n  g->gcrunning = 0;  /* no GC while building state */\n  g->strt.size = g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(&g->l_registry);\n  g->panic = NULL;\n  g->gcstate = GCSpause;\n  g->gckind = KGC_INC;\n  g->gcemergency = 0;\n  g->finobj = g->tobefnz = g->fixedgc = NULL;\n  g->firstold1 = g->survival = g->old1 = g->reallyold = NULL;\n  g->finobjsur = g->finobjold1 = g->finobjrold = NULL;\n  g->sweepgc = NULL;\n  g->gray = g->grayagain = NULL;\n  g->weak = g->ephemeron = g->allweak = NULL;\n  g->twups = NULL;\n  g->totalbytes = sizeof(LG);\n  g->GCdebt = 0;\n  g->lastatomic = 0;\n  setivalue(&g->nilvalue, 0);  /* to signal that state is not yet built */\n  setgcparam(g->gcpause, LUAI_GCPAUSE);\n  setgcparam(g->gcstepmul, LUAI_GCMUL);\n  g->gcstepsize = LUAI_GCSTEPSIZE;\n  setgcparam(g->genmajormul, LUAI_GENMAJORMUL);\n  g->genminormul = LUAI_GENMINORMUL;\n  for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  return L;\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  lua_lock(L);\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  close_state(L);\n}\n\n\nvoid luaE_warning (lua_State *L, const char *msg, int tocont) {\n  lua_WarnFunction wf = G(L)->warnf;\n  if (wf != NULL)\n    wf(G(L)->ud_warn, msg, tocont);\n}\n\n\n/*\n** Generate a warning from an error message\n*/\nvoid luaE_warnerror (lua_State *L, const char *where) {\n  TValue *errobj = s2v(L->top - 1);  /* error object */\n  const char *msg = (ttisstring(errobj))\n                  ? svalue(errobj)\n                  : \"error object is not a string\";\n  /* produce warning \"error in %s (%s)\" (where, msg) */\n  luaE_warning(L, \"error in \", 1);\n  luaE_warning(L, where, 1);\n  luaE_warning(L, \" (\", 1);\n  luaE_warning(L, msg, 1);\n  luaE_warning(L, \")\", 0);\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lstate.h",
    "content": "/*\n** $Id: lstate.h $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n\n\n/*\n** Some notes about garbage-collected objects: All objects in Lua must\n** be kept somehow accessible until being freed, so all objects always\n** belong to one (and only one) of these lists, using field 'next' of\n** the 'CommonHeader' for the link:\n**\n** 'allgc': all objects not marked for finalization;\n** 'finobj': all objects marked for finalization;\n** 'tobefnz': all objects ready to be finalized;\n** 'fixedgc': all objects that are not to be collected (currently\n** only small strings, such as reserved words).\n**\n** For the generational collector, some of these lists have marks for\n** generations. Each mark points to the first element in the list for\n** that particular generation; that generation goes until the next mark.\n**\n** 'allgc' -> 'survival': new objects;\n** 'survival' -> 'old': objects that survived one collection;\n** 'old1' -> 'reallyold': objects that became old in last collection;\n** 'reallyold' -> NULL: objects old for more than one cycle.\n**\n** 'finobj' -> 'finobjsur': new objects marked for finalization;\n** 'finobjsur' -> 'finobjold1': survived   \"\"\"\";\n** 'finobjold1' -> 'finobjrold': just old  \"\"\"\";\n** 'finobjrold' -> NULL: really old       \"\"\"\".\n**\n** All lists can contain elements older than their main ages, due\n** to 'luaC_checkfinalizer' and 'udata2finalize', which move\n** objects between the normal lists and the \"marked for finalization\"\n** lists. Moreover, barriers can age young objects in young lists as\n** OLD0, which then become OLD1. However, a list never contains\n** elements younger than their main ages.\n**\n** The generational collector also uses a pointer 'firstold1', which\n** points to the first OLD1 object in the list. It is used to optimize\n** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'\n** and 'reallyold', but often the list has no OLD1 objects or they are\n** after 'old1'.) Note the difference between it and 'old1':\n** 'firstold1': no OLD1 objects before this point; there can be all\n**   ages after it.\n** 'old1': no objects younger than OLD1 after this point.\n*/\n\n/*\n** Moreover, there is another set of lists that control gray objects.\n** These lists are linked by fields 'gclist'. (All objects that\n** can become gray have such a field. The field is not the same\n** in all objects, but it always has this name.)  Any gray object\n** must belong to one of these lists, and all objects in these lists\n** must be gray (with two exceptions explained below):\n**\n** 'gray': regular gray objects, still waiting to be visited.\n** 'grayagain': objects that must be revisited at the atomic phase.\n**   That includes\n**   - black objects got in a write barrier;\n**   - all kinds of weak tables during propagation phase;\n**   - all threads.\n** 'weak': tables with weak values to be cleared;\n** 'ephemeron': ephemeron tables with white->white entries;\n** 'allweak': tables with weak keys and/or weak values to be cleared.\n**\n** The exceptions to that \"gray rule\" are:\n** - TOUCHED2 objects in generational mode stay in a gray list (because\n** they must be visited again at the end of the cycle), but they are\n** marked black because assignments to them must activate barriers (to\n** move them back to TOUCHED1).\n** - Open upvales are kept gray to avoid barriers, but they stay out\n** of gray lists. (They don't even have a 'gclist' field.)\n*/\n\n\n\n/*\n** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of\n** how many \"C calls\" it still can do in the C stack, to avoid C-stack\n** overflow.  This count is very rough approximation; it considers only\n** recursive functions inside the interpreter, as non-recursive calls\n** can be considered using a fixed (although unknown) amount of stack\n** space.\n**\n** The count has two parts: the lower part is the count itself; the\n** higher part counts the number of non-yieldable calls in the stack.\n** (They are together so that we can change both with one instruction.)\n**\n** Because calls to external C functions can use an unknown amount\n** of space (e.g., functions using an auxiliary buffer), calls\n** to these functions add more than one to the count (see CSTACKCF).\n**\n** The proper count excludes the number of CallInfo structures allocated\n** by Lua, as a kind of \"potential\" calls. So, when Lua calls a function\n** (and \"consumes\" one CallInfo), it needs neither to decrement nor to\n** check 'nCcalls', as its use of C stack is already accounted for.\n*/\n\n/* number of \"C stack slots\" used by an external C function */\n#define CSTACKCF\t10\n\n\n/*\n** The C-stack size is sliced in the following zones:\n** - larger than CSTACKERR: normal stack;\n** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;\n** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;\n** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;\n** (Because the counter can be decremented CSTACKCF at once, we need\n** the so called \"buffer zones\", with at least that size, to properly\n** detect a change from one zone to the next.)\n*/\n#define CSTACKERR\t(8 * CSTACKCF)\n#define CSTACKMARK\t(CSTACKERR - (CSTACKCF + 2))\n#define CSTACKERRMARK\t(CSTACKCF + 2)\n\n\n/* initial limit for the C-stack of threads */\n#define CSTACKTHREAD\t(2 * CSTACKERR)\n\n\n/* true if this thread does not have non-yieldable calls in the stack */\n#define yieldable(L)\t\t(((L)->nCcalls & 0xffff0000) == 0)\n\n/* real number of C calls */\n#define getCcalls(L)\t((L)->nCcalls & 0xffff)\n\n\n/* Increment the number of non-yieldable calls */\n#define incnny(L)\t((L)->nCcalls += 0x10000)\n\n/* Decrement the number of non-yieldable calls */\n#define decnny(L)\t((L)->nCcalls -= 0x10000)\n\n/* Increment the number of non-yieldable calls and decrement nCcalls */\n#define incXCcalls(L)\t((L)->nCcalls += 0x10000 - CSTACKCF)\n\n/* Decrement the number of non-yieldable calls and increment nCcalls */\n#define decXCcalls(L)\t((L)->nCcalls -= 0x10000 - CSTACKCF)\n\n\n\n\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/*\n** Atomic type (relative to signals) to better ensure that 'lua_sethook'\n** is thread safe\n*/\n#if !defined(l_signalT)\n#include <signal.h>\n#define l_signalT\tsig_atomic_t\n#endif\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n/* kinds of Garbage Collection */\n#define KGC_INC\t\t0\t/* incremental gc */\n#define KGC_GEN\t\t1\t/* generational gc */\n\n\ntypedef struct stringtable {\n  TString **hash;\n  int nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** Information about a call.\n*/\ntypedef struct CallInfo {\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  struct CallInfo *previous, *next;  /* dynamic call link */\n  union {\n    struct {  /* only for Lua functions */\n      const Instruction *savedpc;\n      volatile l_signalT trap;\n      int nextraargs;  /* # of extra arguments in vararg functions */\n    } l;\n    struct {  /* only for C functions */\n      lua_KFunction k;  /* continuation in case of yields */\n      ptrdiff_t old_errfunc;\n      lua_KContext ctx;  /* context info. in case of yields */\n    } c;\n  } u;\n  union {\n    int funcidx;  /* called-function index */\n    int nyield;  /* number of values yielded */\n    struct {  /* info about transferred values (for call/return hooks) */\n      unsigned short ftransfer;  /* offset of first value transferred */\n      unsigned short ntransfer;  /* number of values transferred */\n    } transferinfo;\n  } u2;\n  short nresults;  /* expected number of results from this function */\n  unsigned short callstatus;\n} CallInfo;\n\n\n/*\n** Bits in CallInfo status\n*/\n#define CIST_OAH\t(1<<0)\t/* original value of 'allowhook' */\n#define CIST_C\t\t(1<<1)\t/* call is running a C function */\n#define CIST_HOOKED\t(1<<2)\t/* call is running a debug hook */\n#define CIST_YPCALL\t(1<<3)\t/* call is a yieldable protected call */\n#define CIST_TAIL\t(1<<4)\t/* call was tail called */\n#define CIST_HOOKYIELD\t(1<<5)\t/* last hook called yielded */\n#define CIST_FIN\t(1<<6)  /* call is running a finalizer */\n#define CIST_TRAN\t(1<<7)\t/* 'ci' has transfer information */\n#if defined(LUA_COMPAT_LT_LE)\n#define CIST_LEQ\t(1<<8)  /* using __lt for __le */\n#endif\n\n/* active function is a Lua function */\n#define isLua(ci)\t(!((ci)->callstatus & CIST_C))\n\n/* call is running Lua code (not a hook) */\n#define isLuacode(ci)\t(!((ci)->callstatus & (CIST_C | CIST_HOOKED)))\n\n/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */\n#define setoah(st,v)\t((st) = ((st) & ~CIST_OAH) | (v))\n#define getoah(st)\t((st) & CIST_OAH)\n\n\n/*\n** 'global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to 'frealloc' */\n  l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */\n  l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */\n  lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */\n  lu_mem lastatomic;  /* see function 'genstep' in file 'lgc.c' */\n  stringtable strt;  /* hash table for strings */\n  TValue l_registry;\n  TValue nilvalue;  /* a nil value */\n  unsigned int seed;  /* randomized seed for hashes */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gckind;  /* kind of GC running */\n  lu_byte genminormul;  /* control for minor generational collections */\n  lu_byte genmajormul;  /* control for major generational collections */\n  lu_byte gcrunning;  /* true if GC is running */\n  lu_byte gcemergency;  /* true if this is an emergency collection */\n  lu_byte gcpause;  /* size of pause between successive GCs */\n  lu_byte gcstepmul;  /* GC \"speed\" */\n  lu_byte gcstepsize;  /* (log2 of) GC granularity */\n  GCObject *allgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* current position of sweep in list */\n  GCObject *finobj;  /* list of collectable objects with finalizers */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of tables with weak values */\n  GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */\n  GCObject *allweak;  /* list of all-weak tables */\n  GCObject *tobefnz;  /* list of userdata to be GC */\n  GCObject *fixedgc;  /* list of objects not to be collected */\n  /* fields for generational collector */\n  GCObject *survival;  /* start of objects that survived one GC cycle */\n  GCObject *old1;  /* start of old1 objects */\n  GCObject *reallyold;  /* objects more than one cycle old (\"really old\") */\n  GCObject *firstold1;  /* first OLD1 object in the list (if any) */\n  GCObject *finobjsur;  /* list of survival objects with finalizers */\n  GCObject *finobjold1;  /* list of old1 objects with finalizers */\n  GCObject *finobjrold;  /* list of really old objects with finalizers */\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  struct lua_State *mainthread;\n  TString *memerrmsg;  /* message for memory-allocation errors */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */\n  TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */\n  lua_WarnFunction warnf;  /* warning function */\n  void *ud_warn;         /* auxiliary data to 'warnf' */\n  unsigned int Cstacklimit;  /* current limit for the C stack */\n} global_State;\n\n\n/*\n** 'per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  lu_byte status;\n  lu_byte allowhook;\n  unsigned short nci;  /* number of items in 'ci' list */\n  StkId top;  /* first free slot in the stack */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  UpVal *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_State *twups;  /* list of threads with open upvalues */\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */\n  volatile lua_Hook hook;\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n  l_uint32 nCcalls;  /* number of allowed nested C calls - 'nci' */\n  int oldpc;  /* last pc traced */\n  int stacksize;\n  int basehookcount;\n  int hookcount;\n  volatile l_signalT hookmask;\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects (only for conversions)\n** ISO C99, 6.5.2.3 p.5:\n** \"if a union contains several structures that share a common initial\n** sequence [...], and if the union object currently contains one\n** of these structures, it is permitted to inspect the common initial\n** part of any of them anywhere that a declaration of the complete type\n** of the union is visible.\"\n*/\nunion GCUnion {\n  GCObject gc;  /* common header */\n  struct TString ts;\n  struct Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct lua_State th;  /* thread */\n  struct UpVal upv;\n};\n\n\n/*\n** ISO C99, 6.7.2.1 p.14:\n** \"A pointer to a union object, suitably converted, points to each of\n** its members [...], and vice versa.\"\n*/\n#define cast_u(o)\tcast(union GCUnion *, (o))\n\n/* macros to convert a GCObject into a specific value */\n#define gco2ts(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))\n#define gco2u(o)  check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))\n#define gco2lcl(o)  check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))\n#define gco2ccl(o)  check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))\n#define gco2cl(o)  \\\n\tcheck_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))\n#define gco2t(o)  check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))\n#define gco2p(o)  check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))\n#define gco2th(o)  check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))\n#define gco2upv(o)\tcheck_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))\n\n\n/*\n** macro to convert a Lua object into a GCObject\n** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)\n*/\n#define obj2gco(v)\tcheck_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))\n\n\n/* actual number of total bytes allocated */\n#define gettotalbytes(g)\tcast(lu_mem, (g)->totalbytes + (g)->GCdebt)\n\nLUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\nLUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);\nLUAI_FUNC void luaE_freeCI (lua_State *L);\nLUAI_FUNC void luaE_shrinkCI (lua_State *L);\nLUAI_FUNC void luaE_enterCcall (lua_State *L);\nLUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);\nLUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);\n\n\n#define luaE_exitCcall(L)\t((L)->nCcalls++)\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lstring.c",
    "content": "/*\n** $Id: lstring.c $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n/*\n** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a long string to\n** compute its hash\n*/\n#if !defined(LUAI_HASHLIMIT)\n#define LUAI_HASHLIMIT\t\t5\n#endif\n\n\n\n/*\n** Maximum size for string table.\n*/\n#define MAXSTRTB\tcast_int(luaM_limitN(MAX_INT, TString*))\n\n\n/*\n** equality for long strings\n*/\nint luaS_eqlngstr (TString *a, TString *b) {\n  size_t len = a->u.lnglen;\n  lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR);\n  return (a == b) ||  /* same instance or... */\n    ((len == b->u.lnglen) &&  /* equal length and ... */\n     (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */\n}\n\n\nunsigned int luaS_hash (const char *str, size_t l, unsigned int seed,\n                        size_t step) {\n  unsigned int h = seed ^ cast_uint(l);\n  for (; l >= step; l -= step)\n    h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));\n  return h;\n}\n\n\nunsigned int luaS_hashlongstr (TString *ts) {\n  lua_assert(ts->tt == LUA_VLNGSTR);\n  if (ts->extra == 0) {  /* no hash? */\n    size_t len = ts->u.lnglen;\n    size_t step = (len >> LUAI_HASHLIMIT) + 1;\n    ts->hash = luaS_hash(getstr(ts), len, ts->hash, step);\n    ts->extra = 1;  /* now it has its hash */\n  }\n  return ts->hash;\n}\n\n\nstatic void tablerehash (TString **vect, int osize, int nsize) {\n  int i;\n  for (i = osize; i < nsize; i++)  /* clear new elements */\n    vect[i] = NULL;\n  for (i = 0; i < osize; i++) {  /* rehash old part of the array */\n    TString *p = vect[i];\n    vect[i] = NULL;\n    while (p) {  /* for each string in the list */\n      TString *hnext = p->u.hnext;  /* save next */\n      unsigned int h = lmod(p->hash, nsize);  /* new position */\n      p->u.hnext = vect[h];  /* chain it into array */\n      vect[h] = p;\n      p = hnext;\n    }\n  }\n}\n\n\n/*\n** Resize the string table. If allocation fails, keep the current size.\n** (This can degrade performance, but any non-zero size should work\n** correctly.)\n*/\nvoid luaS_resize (lua_State *L, int nsize) {\n  stringtable *tb = &G(L)->strt;\n  int osize = tb->size;\n  TString **newvect;\n  if (nsize < osize)  /* shrinking table? */\n    tablerehash(tb->hash, osize, nsize);  /* depopulate shrinking part */\n  newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*);\n  if (unlikely(newvect == NULL)) {  /* reallocation failed? */\n    if (nsize < osize)  /* was it shrinking table? */\n      tablerehash(tb->hash, nsize, osize);  /* restore to original size */\n    /* leave table as it was */\n  }\n  else {  /* allocation succeeded */\n    tb->hash = newvect;\n    tb->size = nsize;\n    if (nsize > osize)\n      tablerehash(newvect, osize, nsize);  /* rehash for new size */\n  }\n}\n\n\n/*\n** Clear API string cache. (Entries cannot be empty, so fill them with\n** a non-collectable string.)\n*/\nvoid luaS_clearcache (global_State *g) {\n  int i, j;\n  for (i = 0; i < STRCACHE_N; i++)\n    for (j = 0; j < STRCACHE_M; j++) {\n      if (iswhite(g->strcache[i][j]))  /* will entry be collected? */\n        g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */\n    }\n}\n\n\n/*\n** Initialize the string table and the string cache\n*/\nvoid luaS_init (lua_State *L) {\n  global_State *g = G(L);\n  int i, j;\n  stringtable *tb = &G(L)->strt;\n  tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*);\n  tablerehash(tb->hash, 0, MINSTRTABSIZE);  /* clear array */\n  tb->size = MINSTRTABSIZE;\n  /* pre-create memory-error message */\n  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);\n  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */\n  for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */\n    for (j = 0; j < STRCACHE_M; j++)\n      g->strcache[i][j] = g->memerrmsg;\n}\n\n\n\n/*\n** creates a new string object\n*/\nstatic TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {\n  TString *ts;\n  GCObject *o;\n  size_t totalsize;  /* total size of TString object */\n  totalsize = sizelstring(l);\n  o = luaC_newobj(L, tag, totalsize);\n  ts = gco2ts(o);\n  ts->hash = h;\n  ts->extra = 0;\n  getstr(ts)[l] = '\\0';  /* ending 0 */\n  return ts;\n}\n\n\nTString *luaS_createlngstrobj (lua_State *L, size_t l) {\n  TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed);\n  ts->u.lnglen = l;\n  return ts;\n}\n\n\nvoid luaS_remove (lua_State *L, TString *ts) {\n  stringtable *tb = &G(L)->strt;\n  TString **p = &tb->hash[lmod(ts->hash, tb->size)];\n  while (*p != ts)  /* find previous element */\n    p = &(*p)->u.hnext;\n  *p = (*p)->u.hnext;  /* remove element from its list */\n  tb->nuse--;\n}\n\n\nstatic void growstrtab (lua_State *L, stringtable *tb) {\n  if (unlikely(tb->nuse == MAX_INT)) {  /* too many strings? */\n    luaC_fullgc(L, 1);  /* try to free some... */\n    if (tb->nuse == MAX_INT)  /* still too many? */\n      luaM_error(L);  /* cannot even create a message... */\n  }\n  if (tb->size <= MAXSTRTB / 2)  /* can grow string table? */\n    luaS_resize(L, tb->size * 2);\n}\n\n\n/*\n** Checks whether short string exists and reuses it or creates a new one.\n*/\nstatic TString *internshrstr (lua_State *L, const char *str, size_t l) {\n  TString *ts;\n  global_State *g = G(L);\n  stringtable *tb = &g->strt;\n  unsigned int h = luaS_hash(str, l, g->seed, 1);\n  TString **list = &tb->hash[lmod(h, tb->size)];\n  lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */\n  for (ts = *list; ts != NULL; ts = ts->u.hnext) {\n    if (l == ts->shrlen && (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {\n      /* found! */\n      if (isdead(g, ts))  /* dead (but not collected yet)? */\n        changewhite(ts);  /* resurrect it */\n      return ts;\n    }\n  }\n  /* else must create a new string */\n  if (tb->nuse >= tb->size) {  /* need to grow string table? */\n    growstrtab(L, tb);\n    list = &tb->hash[lmod(h, tb->size)];  /* rehash with new size */\n  }\n  ts = createstrobj(L, l, LUA_VSHRSTR, h);\n  memcpy(getstr(ts), str, l * sizeof(char));\n  ts->shrlen = cast_byte(l);\n  ts->u.hnext = *list;\n  *list = ts;\n  tb->nuse++;\n  return ts;\n}\n\n\n/*\n** new string (with explicit length)\n*/\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  if (l <= LUAI_MAXSHORTLEN)  /* short string? */\n    return internshrstr(L, str, l);\n  else {\n    TString *ts;\n    if (unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char)))\n      luaM_toobig(L);\n    ts = luaS_createlngstrobj(L, l);\n    memcpy(getstr(ts), str, l * sizeof(char));\n    return ts;\n  }\n}\n\n\n/*\n** Create or reuse a zero-terminated string, first checking in the\n** cache (using the string address as a key). The cache can contain\n** only zero-terminated strings, so it is safe to use 'strcmp' to\n** check hits.\n*/\nTString *luaS_new (lua_State *L, const char *str) {\n  unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */\n  int j;\n  TString **p = G(L)->strcache[i];\n  for (j = 0; j < STRCACHE_M; j++) {\n    if (strcmp(str, getstr(p[j])) == 0)  /* hit? */\n      return p[j];  /* that is it */\n  }\n  /* normal route */\n  for (j = STRCACHE_M - 1; j > 0; j--)\n    p[j] = p[j - 1];  /* move out last element */\n  /* new element is first in the list */\n  p[0] = luaS_newlstr(L, str, strlen(str));\n  return p[0];\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s, int nuvalue) {\n  Udata *u;\n  int i;\n  GCObject *o;\n  if (unlikely(s > MAX_SIZE - udatamemoffset(nuvalue)))\n    luaM_toobig(L);\n  o = luaC_newobj(L, LUA_VUSERDATA, sizeudata(nuvalue, s));\n  u = gco2u(o);\n  u->len = s;\n  u->nuvalue = nuvalue;\n  u->metatable = NULL;\n  for (i = 0; i < nuvalue; i++)\n    setnilvalue(&u->uv[i].uv);\n  return u;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lstring.h",
    "content": "/*\n** $Id: lstring.h $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n/*\n** Memory-allocation error message must be preallocated (it cannot\n** be created after memory is exhausted)\n*/\n#define MEMERRMSG       \"not enough memory\"\n\n\n/*\n** Size of a TString: Size of the header plus space for the string\n** itself (including final '\\0').\n*/\n#define sizelstring(l)  (offsetof(TString, contents) + ((l) + 1) * sizeof(char))\n\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n\n/*\n** test whether a string is a reserved word\n*/\n#define isreserved(s)\t((s)->tt == LUA_VSHRSTR && (s)->extra > 0)\n\n\n/*\n** equality for short strings, which are always internalized\n*/\n#define eqshrstr(a,b)\tcheck_exp((a)->tt == LUA_VSHRSTR, (a) == (b))\n\n\nLUAI_FUNC unsigned int luaS_hash (const char *str, size_t l,\n                                  unsigned int seed, size_t step);\nLUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);\nLUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC void luaS_clearcache (global_State *g);\nLUAI_FUNC void luaS_init (lua_State *L);\nLUAI_FUNC void luaS_remove (lua_State *L, TString *ts);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\nLUAI_FUNC TString *luaS_new (lua_State *L, const char *str);\nLUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <ctype.h>\n#include <float.h>\n#include <limits.h>\n#include <locale.h>\n#include <math.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** maximum number of captures that a pattern can do during\n** pattern-matching. This limit is arbitrary, but must fit in\n** an unsigned char.\n*/\n#if !defined(LUA_MAXCAPTURES)\n#define LUA_MAXCAPTURES\t\t32\n#endif\n\n\n/* macro to 'unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n\n/*\n** Some sizes are better limited to fit in 'int', but must also fit in\n** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)\n*/\n#define MAX_SIZET\t((size_t)(~(size_t)0))\n\n#define MAXSIZE  \\\n\t(sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))\n\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, (lua_Integer)l);\n  return 1;\n}\n\n\n/*\n** translate a relative initial string position\n** (negative means back from end): clip result to [1, inf).\n** The length of any string in Lua must fit in a lua_Integer,\n** so there are no overflows in the casts.\n** The inverted comparison avoids a possible overflow\n** computing '-pos'.\n*/\nstatic size_t posrelatI (lua_Integer pos, size_t len) {\n  if (pos > 0)\n    return (size_t)pos;\n  else if (pos == 0)\n    return 1;\n  else if (pos < -(lua_Integer)len)  /* inverted comparison */\n    return 1;  /* clip to 1 */\n  else return len + (size_t)pos + 1;\n}\n\n\n/*\n** Gets an optional ending string position from argument 'arg',\n** with default value 'def'.\n** Negative means back from end: clip result to [0, len]\n*/\nstatic size_t getendpos (lua_State *L, int arg, lua_Integer def,\n                         size_t len) {\n  lua_Integer pos = luaL_optinteger(L, arg, def);\n  if (pos > (lua_Integer)len)\n    return len;\n  else if (pos >= 0)\n    return (size_t)pos;\n  else if (pos < -(lua_Integer)len)\n    return 0;\n  else return len + (size_t)pos + 1;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  size_t start = posrelatI(luaL_checkinteger(L, 2), l);\n  size_t end = getendpos(L, 3, -1, l);\n  if (start <= end)\n    lua_pushlstring(L, s + start - 1, (end - start) + 1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l, i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i = 0; i < l; i++)\n    p[i] = s[l - i - 1];\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = tolower(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  char *p = luaL_buffinitsize(L, &b, l);\n  for (i=0; i<l; i++)\n    p[i] = toupper(uchar(s[i]));\n  luaL_pushresultsize(&b, l);\n  return 1;\n}\n\n\nstatic int str_rep (lua_State *L) {\n  size_t l, lsep;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer n = luaL_checkinteger(L, 2);\n  const char *sep = luaL_optlstring(L, 3, \"\", &lsep);\n  if (n <= 0) lua_pushliteral(L, \"\");\n  else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */\n    return luaL_error(L, \"resulting string too large\");\n  else {\n    size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;\n    luaL_Buffer b;\n    char *p = luaL_buffinitsize(L, &b, totallen);\n    while (n-- > 1) {  /* first n-1 copies (followed by separator) */\n      memcpy(p, s, l * sizeof(char)); p += l;\n      if (lsep > 0) {  /* empty 'memcpy' is not that cheap */\n        memcpy(p, sep, lsep * sizeof(char));\n        p += lsep;\n      }\n    }\n    memcpy(p, s, l * sizeof(char));  /* last copy (not followed by separator) */\n    luaL_pushresultsize(&b, totallen);\n  }\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  lua_Integer pi = luaL_optinteger(L, 2, 1);\n  size_t posi = posrelatI(pi, l);\n  size_t pose = getendpos(L, 3, pi, l);\n  int n, i;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= (size_t)INT_MAX)  /* arithmetic overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  char *p = luaL_buffinitsize(L, &b, n);\n  for (i=1; i<=n; i++) {\n    lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i);\n    luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, \"value out of range\");\n    p[i - 1] = uchar(c);\n  }\n  luaL_pushresultsize(&b, n);\n  return 1;\n}\n\n\n/*\n** Buffer to store the result of 'string.dump'. It must be initialized\n** after the call to 'lua_dump', to ensure that the function is on the\n** top of the stack when 'lua_dump' is called. ('luaL_buffinit' might\n** push stuff.)\n*/\nstruct str_Writer {\n  int init;  /* true iff buffer has been initialized */\n  luaL_Buffer B;\n};\n\n\nstatic int writer (lua_State *L, const void *b, size_t size, void *ud) {\n  struct str_Writer *state = (struct str_Writer *)ud;\n  if (!state->init) {\n    state->init = 1;\n    luaL_buffinit(L, &state->B);\n  }\n  luaL_addlstring(&state->B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  struct str_Writer state;\n  int strip = lua_toboolean(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);  /* ensure function is on the top of the stack */\n  state.init = 0;\n  if (lua_dump(L, writer, &state, strip) != 0)\n    return luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&state.B);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** METAMETHODS\n** =======================================================\n*/\n\n#if defined(LUA_NOCVTS2N)\t/* { */\n\n/* no coercion from strings to numbers */\n\nstatic const luaL_Reg stringmetamethods[] = {\n  {\"__index\", NULL},  /* placeholder */\n  {NULL, NULL}\n};\n\n#else\t\t/* }{ */\n\nstatic int tonum (lua_State *L, int arg) {\n  if (lua_type(L, arg) == LUA_TNUMBER) {  /* already a number? */\n    lua_pushvalue(L, arg);\n    return 1;\n  }\n  else {  /* check whether it is a numerical string */\n    size_t len;\n    const char *s = lua_tolstring(L, arg, &len);\n    return (s != NULL && lua_stringtonumber(L, s) == len + 1);\n  }\n}\n\n\nstatic void trymt (lua_State *L, const char *mtname) {\n  lua_settop(L, 2);  /* back to the original arguments */\n  if (lua_type(L, 2) == LUA_TSTRING || !luaL_getmetafield(L, 2, mtname))\n    luaL_error(L, \"attempt to %s a '%s' with a '%s'\", mtname + 2,\n                  luaL_typename(L, -2), luaL_typename(L, -1));\n  lua_insert(L, -3);  /* put metamethod before arguments */\n  lua_call(L, 2, 1);  /* call metamethod */\n}\n\n\nstatic int arith (lua_State *L, int op, const char *mtname) {\n  if (tonum(L, 1) && tonum(L, 2))\n    lua_arith(L, op);  /* result will be on the top */\n  else\n    trymt(L, mtname);\n  return 1;\n}\n\n\nstatic int arith_add (lua_State *L) {\n  return arith(L, LUA_OPADD, \"__add\");\n}\n\nstatic int arith_sub (lua_State *L) {\n  return arith(L, LUA_OPSUB, \"__sub\");\n}\n\nstatic int arith_mul (lua_State *L) {\n  return arith(L, LUA_OPMUL, \"__mul\");\n}\n\nstatic int arith_mod (lua_State *L) {\n  return arith(L, LUA_OPMOD, \"__mod\");\n}\n\nstatic int arith_pow (lua_State *L) {\n  return arith(L, LUA_OPPOW, \"__pow\");\n}\n\nstatic int arith_div (lua_State *L) {\n  return arith(L, LUA_OPDIV, \"__div\");\n}\n\nstatic int arith_idiv (lua_State *L) {\n  return arith(L, LUA_OPIDIV, \"__idiv\");\n}\n\nstatic int arith_unm (lua_State *L) {\n  return arith(L, LUA_OPUNM, \"__unm\");\n}\n\n\nstatic const luaL_Reg stringmetamethods[] = {\n  {\"__add\", arith_add},\n  {\"__sub\", arith_sub},\n  {\"__mul\", arith_mul},\n  {\"__mod\", arith_mod},\n  {\"__pow\", arith_pow},\n  {\"__div\", arith_div},\n  {\"__idiv\", arith_idiv},\n  {\"__unm\", arith_unm},\n  {\"__index\", NULL},  /* placeholder */\n  {NULL, NULL}\n};\n\n#endif\t\t/* } */\n\n/* }====================================================== */\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end ('\\0') of source string */\n  const char *p_end;  /* end ('\\0') of pattern */\n  lua_State *L;\n  int matchdepth;  /* control for recursive depth (to avoid C stack overflow) */\n  unsigned char level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n/* recursive function */\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\n/* maximum recursion depth for 'match' */\n#if !defined(MAXCCALLS)\n#define MAXCCALLS\t200\n#endif\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index %%%d\", l + 1);\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (p == ms->p_end)\n        luaL_error(ms->L, \"malformed pattern (ends with '%%')\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a ']' */\n        if (p == ms->p_end)\n          luaL_error(ms->L, \"malformed pattern (missing ']')\");\n        if (*(p++) == L_ESC && p < ms->p_end)\n          p++;  /* skip escapes (e.g. '%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'g' : res = isgraph(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;  /* deprecated option */\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the '^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (MatchState *ms, const char *s, const char *p,\n                        const char *ep) {\n  if (s >= ms->src_end)\n    return 0;\n  else {\n    int c = uchar(*s);\n    switch (*p) {\n      case '.': return 1;  /* matches any char */\n      case L_ESC: return match_class(c, uchar(*(p+1)));\n      case '[': return matchbracketclass(c, p, ep-1);\n      default:  return (uchar(*p) == c);\n    }\n  }\n}\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (p >= ms->p_end - 1)\n    luaL_error(ms->L, \"malformed pattern (missing arguments to '%%b')\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while (singlematch(ms, s + i, p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (singlematch(ms, s, p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  if (ms->matchdepth-- == 0)\n    luaL_error(ms->L, \"pattern too complex\");\n  init: /* using goto's to optimize tail recursion */\n  if (p != ms->p_end) {  /* end of pattern? */\n    switch (*p) {\n      case '(': {  /* start capture */\n        if (*(p + 1) == ')')  /* position capture? */\n          s = start_capture(ms, s, p + 2, CAP_POSITION);\n        else\n          s = start_capture(ms, s, p + 1, CAP_UNFINISHED);\n        break;\n      }\n      case ')': {  /* end capture */\n        s = end_capture(ms, s, p + 1);\n        break;\n      }\n      case '$': {\n        if ((p + 1) != ms->p_end)  /* is the '$' the last char in pattern? */\n          goto dflt;  /* no; go to default */\n        s = (s == ms->src_end) ? s : NULL;  /* check end of string */\n        break;\n      }\n      case L_ESC: {  /* escaped sequences not in the format class[*+?-]? */\n        switch (*(p + 1)) {\n          case 'b': {  /* balanced string? */\n            s = matchbalance(ms, s, p + 2);\n            if (s != NULL) {\n              p += 4; goto init;  /* return match(ms, s, p + 4); */\n            }  /* else fail (s == NULL) */\n            break;\n          }\n          case 'f': {  /* frontier? */\n            const char *ep; char previous;\n            p += 2;\n            if (*p != '[')\n              luaL_error(ms->L, \"missing '[' after '%%f' in pattern\");\n            ep = classend(ms, p);  /* points to what is next */\n            previous = (s == ms->src_init) ? '\\0' : *(s - 1);\n            if (!matchbracketclass(uchar(previous), p, ep - 1) &&\n               matchbracketclass(uchar(*s), p, ep - 1)) {\n              p = ep; goto init;  /* return match(ms, s, ep); */\n            }\n            s = NULL;  /* match failed */\n            break;\n          }\n          case '0': case '1': case '2': case '3':\n          case '4': case '5': case '6': case '7':\n          case '8': case '9': {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p + 1)));\n            if (s != NULL) {\n              p += 2; goto init;  /* return match(ms, s, p + 2) */\n            }\n            break;\n          }\n          default: goto dflt;\n        }\n        break;\n      }\n      default: dflt: {  /* pattern class plus optional suffix */\n        const char *ep = classend(ms, p);  /* points to optional suffix */\n        /* does not match at least once? */\n        if (!singlematch(ms, s, p, ep)) {\n          if (*ep == '*' || *ep == '?' || *ep == '-') {  /* accept empty? */\n            p = ep + 1; goto init;  /* return match(ms, s, ep + 1); */\n          }\n          else  /* '+' or no suffix */\n            s = NULL;  /* fail */\n        }\n        else {  /* matched once */\n          switch (*ep) {  /* handle optional suffix */\n            case '?': {  /* optional */\n              const char *res;\n              if ((res = match(ms, s + 1, ep + 1)) != NULL)\n                s = res;\n              else {\n                p = ep + 1; goto init;  /* else return match(ms, s, ep + 1); */\n              }\n              break;\n            }\n            case '+':  /* 1 or more repetitions */\n              s++;  /* 1 match already done */\n              /* FALLTHROUGH */\n            case '*':  /* 0 or more repetitions */\n              s = max_expand(ms, s, p, ep);\n              break;\n            case '-':  /* 0 or more repetitions (minimum) */\n              s = min_expand(ms, s, p, ep);\n              break;\n            default:  /* no suffix */\n              s++; p = ep; goto init;  /* return match(ms, s + 1, ep); */\n          }\n        }\n        break;\n      }\n    }\n  }\n  ms->matchdepth++;\n  return s;\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative 'l1' */\n  else {\n    const char *init;  /* to search for a '*s2' inside 's1' */\n    l2--;  /* 1st char will be checked by 'memchr' */\n    l1 = l1-l2;  /* 's2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct 'l1' and 's1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\n/*\n** get information about the i-th capture. If there are no captures\n** and 'i==0', return information about the whole match, which\n** is the range 's'..'e'. If the capture is a string, return\n** its length and put its address in '*cap'. If it is an integer\n** (a position), push it on the stack and return CAP_POSITION.\n*/\nstatic size_t get_onecapture (MatchState *ms, int i, const char *s,\n                              const char *e, const char **cap) {\n  if (i >= ms->level) {\n    if (i != 0)\n      luaL_error(ms->L, \"invalid capture index %%%d\", i + 1);\n    *cap = s;\n    return e - s;\n  }\n  else {\n    ptrdiff_t capl = ms->capture[i].len;\n    *cap = ms->capture[i].init;\n    if (capl == CAP_UNFINISHED)\n      luaL_error(ms->L, \"unfinished capture\");\n    else if (capl == CAP_POSITION)\n      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);\n    return capl;\n  }\n}\n\n\n/*\n** Push the i-th capture on the stack.\n*/\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  const char *cap;\n  ptrdiff_t l = get_onecapture(ms, i, s, e, &cap);\n  if (l != CAP_POSITION)\n    lua_pushlstring(ms->L, cap, l);\n  /* else position was already pushed */\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\n/* check whether pattern has no special characters */\nstatic int nospecials (const char *p, size_t l) {\n  size_t upto = 0;\n  do {\n    if (strpbrk(p + upto, SPECIALS))\n      return 0;  /* pattern has a special character */\n    upto += strlen(p + upto) + 1;  /* may have more after \\0 */\n  } while (upto <= l);\n  return 1;  /* no special chars found */\n}\n\n\nstatic void prepstate (MatchState *ms, lua_State *L,\n                       const char *s, size_t ls, const char *p, size_t lp) {\n  ms->L = L;\n  ms->matchdepth = MAXCCALLS;\n  ms->src_init = s;\n  ms->src_end = s + ls;\n  ms->p_end = p + lp;\n}\n\n\nstatic void reprepstate (MatchState *ms) {\n  ms->level = 0;\n  lua_assert(ms->matchdepth == MAXCCALLS);\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1;\n  if (init > ls) {  /* start after string's end? */\n    luaL_pushfail(L);  /* cannot find anything */\n    return 1;\n  }\n  /* explicit request or no special characters? */\n  if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {\n    /* do a plain search */\n    const char *s2 = lmemfind(s + init, ls - init, p, lp);\n    if (s2) {\n      lua_pushinteger(L, (s2 - s) + 1);\n      lua_pushinteger(L, (s2 - s) + lp);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    const char *s1 = s + init;\n    int anchor = (*p == '^');\n    if (anchor) {\n      p++; lp--;  /* skip anchor character */\n    }\n    prepstate(&ms, L, s, ls, p, lp);\n    do {\n      const char *res;\n      reprepstate(&ms);\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, (s1 - s) + 1);  /* start */\n          lua_pushinteger(L, res - s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  luaL_pushfail(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\n/* state for 'gmatch' */\ntypedef struct GMatchState {\n  const char *src;  /* current position */\n  const char *p;  /* pattern */\n  const char *lastmatch;  /* end of last match */\n  MatchState ms;  /* match state */\n} GMatchState;\n\n\nstatic int gmatch_aux (lua_State *L) {\n  GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));\n  const char *src;\n  gm->ms.L = L;\n  for (src = gm->src; src <= gm->ms.src_end; src++) {\n    const char *e;\n    reprepstate(&gm->ms);\n    if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {\n      gm->src = gm->lastmatch = e;\n      return push_captures(&gm->ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  size_t ls, lp;\n  const char *s = luaL_checklstring(L, 1, &ls);\n  const char *p = luaL_checklstring(L, 2, &lp);\n  size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1;\n  GMatchState *gm;\n  lua_settop(L, 2);  /* keep strings on closure to avoid being collected */\n  gm = (GMatchState *)lua_newuserdatauv(L, sizeof(GMatchState), 0);\n  if (init > ls)  /* start after string's end? */\n    init = ls + 1;  /* avoid overflows in 's + init' */\n  prepstate(&gm->ms, L, s, ls, p, lp);\n  gm->src = s + init; gm->p = p; gm->lastmatch = NULL;\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l;\n  lua_State *L = ms->L;\n  const char *news = lua_tolstring(L, 3, &l);\n  const char *p;\n  while ((p = (char *)memchr(news, L_ESC, l)) != NULL) {\n    luaL_addlstring(b, news, p - news);\n    p++;  /* skip ESC */\n    if (*p == L_ESC)  /* '%%' */\n      luaL_addchar(b, *p);\n    else if (*p == '0')  /* '%0' */\n        luaL_addlstring(b, s, e - s);\n    else if (isdigit(uchar(*p))) {  /* '%n' */\n      const char *cap;\n      ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap);\n      if (resl == CAP_POSITION)\n        luaL_addvalue(b);  /* add position to accumulated result */\n      else\n        luaL_addlstring(b, cap, resl);\n    }\n    else\n      luaL_error(L, \"invalid use of '%c' in replacement string\", L_ESC);\n    l -= p + 1 - news;\n    news = p + 1;\n  }\n  luaL_addlstring(b, news, l);\n}\n\n\n/*\n** Add the replacement value to the string buffer 'b'.\n** Return true if the original string was changed. (Function calls and\n** table indexing resulting in nil or false do not change the subject.)\n*/\nstatic int add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                      const char *e, int tr) {\n  lua_State *L = ms->L;\n  switch (tr) {\n    case LUA_TFUNCTION: {  /* call the function */\n      int n;\n      lua_pushvalue(L, 3);  /* push the function */\n      n = push_captures(ms, s, e);  /* all captures as arguments */\n      lua_call(L, n, 1);  /* call it */\n      break;\n    }\n    case LUA_TTABLE: {  /* index the table */\n      push_onecapture(ms, 0, s, e);  /* first capture is the index */\n      lua_gettable(L, 3);\n      break;\n    }\n    default: {  /* LUA_TNUMBER or LUA_TSTRING */\n      add_s(ms, b, s, e);  /* add value to the buffer */\n      return 1;  /* something changed */\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);  /* remove value */\n    luaL_addlstring(b, s, e - s);  /* keep original text */\n    return 0;  /* no changes */\n  }\n  else if (!lua_isstring(L, -1))\n    return luaL_error(L, \"invalid replacement value (a %s)\",\n                         luaL_typename(L, -1));\n  else {\n    luaL_addvalue(b);  /* add result to accumulator */\n    return 1;  /* something changed */\n  }\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl, lp;\n  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */\n  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */\n  const char *lastmatch = NULL;  /* end of last match */\n  int tr = lua_type(L, 3);  /* replacement type */\n  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */\n  int anchor = (*p == '^');\n  lua_Integer n = 0;  /* replacement count */\n  int changed = 0;  /* change flag */\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argexpected(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table\");\n  luaL_buffinit(L, &b);\n  if (anchor) {\n    p++; lp--;  /* skip anchor character */\n  }\n  prepstate(&ms, L, src, srcl, p, lp);\n  while (n < max_s) {\n    const char *e;\n    reprepstate(&ms);  /* (re)prepare state for new match */\n    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */\n      n++;\n      changed = add_value(&ms, &b, src, e, tr) | changed;\n      src = lastmatch = e;\n    }\n    else if (src < ms.src_end)  /* otherwise, skip one character */\n      luaL_addchar(&b, *src++);\n    else break;  /* end of subject */\n    if (anchor) break;\n  }\n  if (!changed)  /* no changes? */\n    lua_pushvalue(L, 1);  /* return original string */\n  else {  /* something changed */\n    luaL_addlstring(&b, src, ms.src_end-src);\n    luaL_pushresult(&b);  /* create and return new string */\n  }\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** STRING FORMAT\n** =======================================================\n*/\n\n#if !defined(lua_number2strx)\t/* { */\n\n/*\n** Hexadecimal floating-point formatter\n*/\n\n#define SIZELENMOD\t(sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))\n\n\n/*\n** Number of bits that goes into the first digit. It can be any value\n** between 1 and 4; the following definition tries to align the number\n** to nibble boundaries by making what is left after that first digit a\n** multiple of 4.\n*/\n#define L_NBFD\t\t((l_floatatt(MANT_DIG) - 1)%4 + 1)\n\n\n/*\n** Add integer part of 'x' to buffer and return new 'x'\n*/\nstatic lua_Number adddigit (char *buff, int n, lua_Number x) {\n  lua_Number dd = l_mathop(floor)(x);  /* get integer part from 'x' */\n  int d = (int)dd;\n  buff[n] = (d < 10 ? d + '0' : d - 10 + 'a');  /* add to buffer */\n  return x - dd;  /* return what is left */\n}\n\n\nstatic int num2straux (char *buff, int sz, lua_Number x) {\n  /* if 'inf' or 'NaN', format it like '%g' */\n  if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);\n  else if (x == 0) {  /* can be -0... */\n    /* create \"0\" or \"-0\" followed by exponent */\n    return l_sprintf(buff, sz, LUA_NUMBER_FMT \"x0p+0\", (LUAI_UACNUMBER)x);\n  }\n  else {\n    int e;\n    lua_Number m = l_mathop(frexp)(x, &e);  /* 'x' fraction and exponent */\n    int n = 0;  /* character count */\n    if (m < 0) {  /* is number negative? */\n      buff[n++] = '-';  /* add sign */\n      m = -m;  /* make it positive */\n    }\n    buff[n++] = '0'; buff[n++] = 'x';  /* add \"0x\" */\n    m = adddigit(buff, n++, m * (1 << L_NBFD));  /* add first digit */\n    e -= L_NBFD;  /* this digit goes before the radix point */\n    if (m > 0) {  /* more digits? */\n      buff[n++] = lua_getlocaledecpoint();  /* add radix point */\n      do {  /* add as many digits as needed */\n        m = adddigit(buff, n++, m * 16);\n      } while (m > 0);\n    }\n    n += l_sprintf(buff + n, sz - n, \"p%+d\", e);  /* add exponent */\n    lua_assert(n < sz);\n    return n;\n  }\n}\n\n\nstatic int lua_number2strx (lua_State *L, char *buff, int sz,\n                            const char *fmt, lua_Number x) {\n  int n = num2straux(buff, sz, x);\n  if (fmt[SIZELENMOD] == 'A') {\n    int i;\n    for (i = 0; i < n; i++)\n      buff[i] = toupper(uchar(buff[i]));\n  }\n  else if (fmt[SIZELENMOD] != 'a')\n    return luaL_error(L, \"modifiers for format '%%a'/'%%A' not implemented\");\n  return n;\n}\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Maximum size for items formatted with '%f'. This size is produced\n** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',\n** and '\\0') + number of decimal digits to represent maxfloat (which\n** is maximum exponent + 1). (99+3+1, adding some extra, 110)\n*/\n#define MAX_ITEMF\t(110 + l_floatatt(MAX_10_EXP))\n\n\n/*\n** All formats except '%f' do not need that large limit.  The other\n** float formats use exponents, so that they fit in the 99 limit for\n** significant digits; 's' for large strings and 'q' add items directly\n** to the buffer; all integer formats also fit in the 99 limit.  The\n** worst case are floats: they may need 99 significant digits, plus\n** '0x', '-', '.', 'e+XXXX', and '\\0'. Adding some extra, 120.\n*/\n#define MAX_ITEM\t120\n\n\n/* valid flags in a format specification */\n#if !defined(L_FMTFLAGS)\n#define L_FMTFLAGS\t\"-+ #0\"\n#endif\n\n\n/*\n** maximum size of each format specification (such as \"%-099.99d\")\n*/\n#define MAX_FORMAT\t32\n\n\nstatic void addquoted (luaL_Buffer *b, const char *s, size_t len) {\n  luaL_addchar(b, '\"');\n  while (len--) {\n    if (*s == '\"' || *s == '\\\\' || *s == '\\n') {\n      luaL_addchar(b, '\\\\');\n      luaL_addchar(b, *s);\n    }\n    else if (iscntrl(uchar(*s))) {\n      char buff[10];\n      if (!isdigit(uchar(*(s+1))))\n        l_sprintf(buff, sizeof(buff), \"\\\\%d\", (int)uchar(*s));\n      else\n        l_sprintf(buff, sizeof(buff), \"\\\\%03d\", (int)uchar(*s));\n      luaL_addstring(b, buff);\n    }\n    else\n      luaL_addchar(b, *s);\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\n\n/*\n** Serialize a floating-point number in such a way that it can be\n** scanned back by Lua. Use hexadecimal format for \"common\" numbers\n** (to preserve precision); inf, -inf, and NaN are handled separately.\n** (NaN cannot be expressed as a numeral, so we write '(0/0)' for it.)\n*/\nstatic int quotefloat (lua_State *L, char *buff, lua_Number n) {\n  const char *s;  /* for the fixed representations */\n  if (n == (lua_Number)HUGE_VAL)  /* inf? */\n    s = \"1e9999\";\n  else if (n == -(lua_Number)HUGE_VAL)  /* -inf? */\n    s = \"-1e9999\";\n  else if (n != n)  /* NaN? */\n    s = \"(0/0)\";\n  else {  /* format number as hexadecimal */\n    int  nb = lua_number2strx(L, buff, MAX_ITEM,\n                                 \"%\" LUA_NUMBER_FRMLEN \"a\", n);\n    /* ensures that 'buff' string uses a dot as the radix character */\n    if (memchr(buff, '.', nb) == NULL) {  /* no dot? */\n      char point = lua_getlocaledecpoint();  /* try locale point */\n      char *ppoint = (char *)memchr(buff, point, nb);\n      if (ppoint) *ppoint = '.';  /* change it to a dot */\n    }\n    return nb;\n  }\n  /* for the fixed representations */\n  return l_sprintf(buff, MAX_ITEM, \"%s\", s);\n}\n\n\nstatic void addliteral (lua_State *L, luaL_Buffer *b, int arg) {\n  switch (lua_type(L, arg)) {\n    case LUA_TSTRING: {\n      size_t len;\n      const char *s = lua_tolstring(L, arg, &len);\n      addquoted(b, s, len);\n      break;\n    }\n    case LUA_TNUMBER: {\n      char *buff = luaL_prepbuffsize(b, MAX_ITEM);\n      int nb;\n      if (!lua_isinteger(L, arg))  /* float? */\n        nb = quotefloat(L, buff, lua_tonumber(L, arg));\n      else {  /* integers */\n        lua_Integer n = lua_tointeger(L, arg);\n        const char *format = (n == LUA_MININTEGER)  /* corner case? */\n                           ? \"0x%\" LUA_INTEGER_FRMLEN \"x\"  /* use hex */\n                           : LUA_INTEGER_FMT;  /* else use default format */\n        nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);\n      }\n      luaL_addsize(b, nb);\n      break;\n    }\n    case LUA_TNIL: case LUA_TBOOLEAN: {\n      luaL_tolstring(L, arg, NULL);\n      luaL_addvalue(b);\n      break;\n    }\n    default: {\n      luaL_argerror(L, arg, \"value has no literal form\");\n    }\n  }\n}\n\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(L_FMTFLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(L_FMTFLAGS)/sizeof(char))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));\n  form += (p - strfrmt) + 1;\n  *form = '\\0';\n  return p;\n}\n\n\n/*\n** add length modifier into formats\n*/\nstatic void addlenmod (char *form, const char *lenmod) {\n  size_t l = strlen(form);\n  size_t lm = strlen(lenmod);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, lenmod);\n  form[l + lm - 1] = spec;\n  form[l + lm] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int top = lua_gettop(L);\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format ('%...') */\n      int maxitem = MAX_ITEM;\n      char *buff = luaL_prepbuffsize(&b, maxitem);  /* to put formatted item */\n      int nb = 0;  /* number of bytes in added item */\n      if (++arg > top)\n        return luaL_argerror(L, arg, \"no value\");\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          nb = l_sprintf(buff, maxitem, form, (int)luaL_checkinteger(L, arg));\n          break;\n        }\n        case 'd': case 'i':\n        case 'o': case 'u': case 'x': case 'X': {\n          lua_Integer n = luaL_checkinteger(L, arg);\n          addlenmod(form, LUA_INTEGER_FRMLEN);\n          nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n);\n          break;\n        }\n        case 'a': case 'A':\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = lua_number2strx(L, buff, maxitem, form,\n                                  luaL_checknumber(L, arg));\n          break;\n        case 'f':\n          maxitem = MAX_ITEMF;  /* extra space for '%f' */\n          buff = luaL_prepbuffsize(&b, maxitem);\n          /* FALLTHROUGH */\n        case 'e': case 'E': case 'g': case 'G': {\n          lua_Number n = luaL_checknumber(L, arg);\n          addlenmod(form, LUA_NUMBER_FRMLEN);\n          nb = l_sprintf(buff, maxitem, form, (LUAI_UACNUMBER)n);\n          break;\n        }\n        case 'p': {\n          const void *p = lua_topointer(L, arg);\n          if (p == NULL) {  /* avoid calling 'printf' with argument NULL */\n            p = \"(null)\";  /* result */\n            form[strlen(form) - 1] = 's';  /* format it as a string */\n          }\n          nb = l_sprintf(buff, maxitem, form, p);\n          break;\n        }\n        case 'q': {\n          if (form[2] != '\\0')  /* modifiers? */\n            return luaL_error(L, \"specifier '%%q' cannot have modifiers\");\n          addliteral(L, &b, arg);\n          break;\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_tolstring(L, arg, &l);\n          if (form[2] == '\\0')  /* no modifiers? */\n            luaL_addvalue(&b);  /* keep entire string */\n          else {\n            luaL_argcheck(L, l == strlen(s), arg, \"string contains zeros\");\n            if (!strchr(form, '.') && l >= 100) {\n              /* no precision and string is too long to be formatted */\n              luaL_addvalue(&b);  /* keep entire string */\n            }\n            else {  /* format the string into 'buff' */\n              nb = l_sprintf(buff, maxitem, form, s);\n              lua_pop(L, 1);  /* remove result from 'luaL_tolstring' */\n            }\n          }\n          break;\n        }\n        default: {  /* also treat cases 'pnLlh' */\n          return luaL_error(L, \"invalid conversion '%s' to 'format'\", form);\n        }\n      }\n      lua_assert(nb < maxitem);\n      luaL_addsize(&b, nb);\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n/* }====================================================== */\n\n\n/*\n** {======================================================\n** PACK/UNPACK\n** =======================================================\n*/\n\n\n/* value used for padding */\n#if !defined(LUAL_PACKPADBYTE)\n#define LUAL_PACKPADBYTE\t\t0x00\n#endif\n\n/* maximum size for the binary representation of an integer */\n#define MAXINTSIZE\t16\n\n/* number of bits in a character */\n#define NB\tCHAR_BIT\n\n/* mask for one character (NB 1's) */\n#define MC\t((1 << NB) - 1)\n\n/* size of a lua_Integer */\n#define SZINT\t((int)sizeof(lua_Integer))\n\n\n/* dummy union to get native endianness */\nstatic const union {\n  int dummy;\n  char little;  /* true iff machine is little endian */\n} nativeendian = {1};\n\n\n/* dummy structure to get native alignment requirements */\nstruct cD {\n  char c;\n  union { double d; void *p; lua_Integer i; lua_Number n; } u;\n};\n\n#define MAXALIGN\t(offsetof(struct cD, u))\n\n\n/*\n** Union for serializing floats\n*/\ntypedef union Ftypes {\n  float f;\n  double d;\n  lua_Number n;\n  char buff[5 * sizeof(lua_Number)];  /* enough for any float type */\n} Ftypes;\n\n\n/*\n** information to pack/unpack stuff\n*/\ntypedef struct Header {\n  lua_State *L;\n  int islittle;\n  int maxalign;\n} Header;\n\n\n/*\n** options for pack/unpack\n*/\ntypedef enum KOption {\n  Kint,\t\t/* signed integers */\n  Kuint,\t/* unsigned integers */\n  Kfloat,\t/* floating-point numbers */\n  Kchar,\t/* fixed-length strings */\n  Kstring,\t/* strings with prefixed length */\n  Kzstr,\t/* zero-terminated strings */\n  Kpadding,\t/* padding */\n  Kpaddalign,\t/* padding for alignment */\n  Knop\t\t/* no-op (configuration or spaces) */\n} KOption;\n\n\n/*\n** Read an integer numeral from string 'fmt' or return 'df' if\n** there is no numeral\n*/\nstatic int digit (int c) { return '0' <= c && c <= '9'; }\n\nstatic int getnum (const char **fmt, int df) {\n  if (!digit(**fmt))  /* no number? */\n    return df;  /* return default value */\n  else {\n    int a = 0;\n    do {\n      a = a*10 + (*((*fmt)++) - '0');\n    } while (digit(**fmt) && a <= ((int)MAXSIZE - 9)/10);\n    return a;\n  }\n}\n\n\n/*\n** Read an integer numeral and raises an error if it is larger\n** than the maximum size for integers.\n*/\nstatic int getnumlimit (Header *h, const char **fmt, int df) {\n  int sz = getnum(fmt, df);\n  if (sz > MAXINTSIZE || sz <= 0)\n    return luaL_error(h->L, \"integral size (%d) out of limits [1,%d]\",\n                            sz, MAXINTSIZE);\n  return sz;\n}\n\n\n/*\n** Initialize Header\n*/\nstatic void initheader (lua_State *L, Header *h) {\n  h->L = L;\n  h->islittle = nativeendian.little;\n  h->maxalign = 1;\n}\n\n\n/*\n** Read and classify next option. 'size' is filled with option's size.\n*/\nstatic KOption getoption (Header *h, const char **fmt, int *size) {\n  int opt = *((*fmt)++);\n  *size = 0;  /* default */\n  switch (opt) {\n    case 'b': *size = sizeof(char); return Kint;\n    case 'B': *size = sizeof(char); return Kuint;\n    case 'h': *size = sizeof(short); return Kint;\n    case 'H': *size = sizeof(short); return Kuint;\n    case 'l': *size = sizeof(long); return Kint;\n    case 'L': *size = sizeof(long); return Kuint;\n    case 'j': *size = sizeof(lua_Integer); return Kint;\n    case 'J': *size = sizeof(lua_Integer); return Kuint;\n    case 'T': *size = sizeof(size_t); return Kuint;\n    case 'f': *size = sizeof(float); return Kfloat;\n    case 'd': *size = sizeof(double); return Kfloat;\n    case 'n': *size = sizeof(lua_Number); return Kfloat;\n    case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;\n    case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;\n    case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;\n    case 'c':\n      *size = getnum(fmt, -1);\n      if (*size == -1)\n        luaL_error(h->L, \"missing size for format option 'c'\");\n      return Kchar;\n    case 'z': return Kzstr;\n    case 'x': *size = 1; return Kpadding;\n    case 'X': return Kpaddalign;\n    case ' ': break;\n    case '<': h->islittle = 1; break;\n    case '>': h->islittle = 0; break;\n    case '=': h->islittle = nativeendian.little; break;\n    case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break;\n    default: luaL_error(h->L, \"invalid format option '%c'\", opt);\n  }\n  return Knop;\n}\n\n\n/*\n** Read, classify, and fill other details about the next option.\n** 'psize' is filled with option's size, 'notoalign' with its\n** alignment requirements.\n** Local variable 'size' gets the size to be aligned. (Kpadal option\n** always gets its full alignment, other options are limited by\n** the maximum alignment ('maxalign'). Kchar option needs no alignment\n** despite its size.\n*/\nstatic KOption getdetails (Header *h, size_t totalsize,\n                           const char **fmt, int *psize, int *ntoalign) {\n  KOption opt = getoption(h, fmt, psize);\n  int align = *psize;  /* usually, alignment follows size */\n  if (opt == Kpaddalign) {  /* 'X' gets alignment from following option */\n    if (**fmt == '\\0' || getoption(h, fmt, &align) == Kchar || align == 0)\n      luaL_argerror(h->L, 1, \"invalid next option for option 'X'\");\n  }\n  if (align <= 1 || opt == Kchar)  /* need no alignment? */\n    *ntoalign = 0;\n  else {\n    if (align > h->maxalign)  /* enforce maximum alignment */\n      align = h->maxalign;\n    if ((align & (align - 1)) != 0)  /* is 'align' not a power of 2? */\n      luaL_argerror(h->L, 1, \"format asks for alignment not power of 2\");\n    *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1);\n  }\n  return opt;\n}\n\n\n/*\n** Pack integer 'n' with 'size' bytes and 'islittle' endianness.\n** The final 'if' handles the case when 'size' is larger than\n** the size of a Lua integer, correcting the extra sign-extension\n** bytes if necessary (by default they would be zeros).\n*/\nstatic void packint (luaL_Buffer *b, lua_Unsigned n,\n                     int islittle, int size, int neg) {\n  char *buff = luaL_prepbuffsize(b, size);\n  int i;\n  buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */\n  for (i = 1; i < size; i++) {\n    n >>= NB;\n    buff[islittle ? i : size - 1 - i] = (char)(n & MC);\n  }\n  if (neg && size > SZINT) {  /* negative number need sign extension? */\n    for (i = SZINT; i < size; i++)  /* correct extra bytes */\n      buff[islittle ? i : size - 1 - i] = (char)MC;\n  }\n  luaL_addsize(b, size);  /* add result to buffer */\n}\n\n\n/*\n** Copy 'size' bytes from 'src' to 'dest', correcting endianness if\n** given 'islittle' is different from native endianness.\n*/\nstatic void copywithendian (volatile char *dest, volatile const char *src,\n                            int size, int islittle) {\n  if (islittle == nativeendian.little) {\n    while (size-- != 0)\n      *(dest++) = *(src++);\n  }\n  else {\n    dest += size - 1;\n    while (size-- != 0)\n      *(dest--) = *(src++);\n  }\n}\n\n\nstatic int str_pack (lua_State *L) {\n  luaL_Buffer b;\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  int arg = 1;  /* current argument to pack */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  lua_pushnil(L);  /* mark to separate arguments from string buffer */\n  luaL_buffinit(L, &b);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    totalsize += ntoalign + size;\n    while (ntoalign-- > 0)\n     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */\n    arg++;\n    switch (opt) {\n      case Kint: {  /* signed integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT) {  /* need overflow check? */\n          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);\n          luaL_argcheck(L, -lim <= n && n < lim, arg, \"integer overflow\");\n        }\n        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));\n        break;\n      }\n      case Kuint: {  /* unsigned integers */\n        lua_Integer n = luaL_checkinteger(L, arg);\n        if (size < SZINT)  /* need overflow check? */\n          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),\n                           arg, \"unsigned overflow\");\n        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);\n        break;\n      }\n      case Kfloat: {  /* floating-point options */\n        volatile Ftypes u;\n        char *buff = luaL_prepbuffsize(&b, size);\n        lua_Number n = luaL_checknumber(L, arg);  /* get argument */\n        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */\n        else if (size == sizeof(u.d)) u.d = (double)n;\n        else u.n = n;\n        /* move 'u' to final result, correcting endianness if needed */\n        copywithendian(buff, u.buff, size, h.islittle);\n        luaL_addsize(&b, size);\n        break;\n      }\n      case Kchar: {  /* fixed-size string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, len <= (size_t)size, arg,\n                         \"string longer than given size\");\n        luaL_addlstring(&b, s, len);  /* add string */\n        while (len++ < (size_t)size)  /* pad extra space */\n          luaL_addchar(&b, LUAL_PACKPADBYTE);\n        break;\n      }\n      case Kstring: {  /* strings with length count */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, size >= (int)sizeof(size_t) ||\n                         len < ((size_t)1 << (size * NB)),\n                         arg, \"string length does not fit in given size\");\n        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */\n        luaL_addlstring(&b, s, len);\n        totalsize += len;\n        break;\n      }\n      case Kzstr: {  /* zero-terminated string */\n        size_t len;\n        const char *s = luaL_checklstring(L, arg, &len);\n        luaL_argcheck(L, strlen(s) == len, arg, \"string contains zeros\");\n        luaL_addlstring(&b, s, len);\n        luaL_addchar(&b, '\\0');  /* add zero at the end */\n        totalsize += len + 1;\n        break;\n      }\n      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */\n      case Kpaddalign: case Knop:\n        arg--;  /* undo increment */\n        break;\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_packsize (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);  /* format string */\n  size_t totalsize = 0;  /* accumulate total size of result */\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);\n    luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1,\n                     \"variable-length format\");\n    size += ntoalign;  /* total space used by option */\n    luaL_argcheck(L, totalsize <= MAXSIZE - size, 1,\n                     \"format result too large\");\n    totalsize += size;\n  }\n  lua_pushinteger(L, (lua_Integer)totalsize);\n  return 1;\n}\n\n\n/*\n** Unpack an integer with 'size' bytes and 'islittle' endianness.\n** If size is smaller than the size of a Lua integer and integer\n** is signed, must do sign extension (propagating the sign to the\n** higher bits); if size is larger than the size of a Lua integer,\n** it must check the unread bytes to see whether they do not cause an\n** overflow.\n*/\nstatic lua_Integer unpackint (lua_State *L, const char *str,\n                              int islittle, int size, int issigned) {\n  lua_Unsigned res = 0;\n  int i;\n  int limit = (size  <= SZINT) ? size : SZINT;\n  for (i = limit - 1; i >= 0; i--) {\n    res <<= NB;\n    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];\n  }\n  if (size < SZINT) {  /* real size smaller than lua_Integer? */\n    if (issigned) {  /* needs sign extension? */\n      lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);\n      res = ((res ^ mask) - mask);  /* do sign extension */\n    }\n  }\n  else if (size > SZINT) {  /* must check unread bytes */\n    int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;\n    for (i = limit; i < size; i++) {\n      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)\n        luaL_error(L, \"%d-byte integer does not fit into Lua Integer\", size);\n    }\n  }\n  return (lua_Integer)res;\n}\n\n\nstatic int str_unpack (lua_State *L) {\n  Header h;\n  const char *fmt = luaL_checkstring(L, 1);\n  size_t ld;\n  const char *data = luaL_checklstring(L, 2, &ld);\n  size_t pos = posrelatI(luaL_optinteger(L, 3, 1), ld) - 1;\n  int n = 0;  /* number of results */\n  luaL_argcheck(L, pos <= ld, 3, \"initial position out of string\");\n  initheader(L, &h);\n  while (*fmt != '\\0') {\n    int size, ntoalign;\n    KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign);\n    luaL_argcheck(L, (size_t)ntoalign + size <= ld - pos, 2,\n                    \"data string too short\");\n    pos += ntoalign;  /* skip alignment */\n    /* stack space for item + next position */\n    luaL_checkstack(L, 2, \"too many results\");\n    n++;\n    switch (opt) {\n      case Kint:\n      case Kuint: {\n        lua_Integer res = unpackint(L, data + pos, h.islittle, size,\n                                       (opt == Kint));\n        lua_pushinteger(L, res);\n        break;\n      }\n      case Kfloat: {\n        volatile Ftypes u;\n        lua_Number num;\n        copywithendian(u.buff, data + pos, size, h.islittle);\n        if (size == sizeof(u.f)) num = (lua_Number)u.f;\n        else if (size == sizeof(u.d)) num = (lua_Number)u.d;\n        else num = u.n;\n        lua_pushnumber(L, num);\n        break;\n      }\n      case Kchar: {\n        lua_pushlstring(L, data + pos, size);\n        break;\n      }\n      case Kstring: {\n        size_t len = (size_t)unpackint(L, data + pos, h.islittle, size, 0);\n        luaL_argcheck(L, len <= ld - pos - size, 2, \"data string too short\");\n        lua_pushlstring(L, data + pos + size, len);\n        pos += len;  /* skip string */\n        break;\n      }\n      case Kzstr: {\n        size_t len = (int)strlen(data + pos);\n        luaL_argcheck(L, pos + len < ld, 2,\n                         \"unfinished string for format 'z'\");\n        lua_pushlstring(L, data + pos, len);\n        pos += len + 1;  /* skip string plus final '\\0' */\n        break;\n      }\n      case Kpaddalign: case Kpadding: case Knop:\n        n--;  /* undo increment */\n        break;\n    }\n    pos += size;\n  }\n  lua_pushinteger(L, pos + 1);  /* next position */\n  return n + 1;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {\"pack\", str_pack},\n  {\"packsize\", str_packsize},\n  {\"unpack\", str_unpack},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  /* table to be metatable for strings */\n  luaL_newlibtable(L, stringmetamethods);\n  luaL_setfuncs(L, stringmetamethods, 0);\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);  /* copy table */\n  lua_setmetatable(L, -2);  /* set table as metatable for strings */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* get string library */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = string */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUAMOD_API int luaopen_string (lua_State *L) {\n  luaL_newlib(L, strlib);\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ltable.c",
    "content": "/*\n** $Id: ltable.c $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest 'n' such that\n** more than half the slots between 1 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the 'original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <limits.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lvm.h\"\n\n\n/*\n** MAXABITS is the largest integer such that MAXASIZE fits in an\n** unsigned int.\n*/\n#define MAXABITS\tcast_int(sizeof(int) * CHAR_BIT - 1)\n\n\n/*\n** MAXASIZE is the maximum size of the array part. It is the minimum\n** between 2^MAXABITS and the maximum size that, measured in bytes,\n** fits in a 'size_t'.\n*/\n#define MAXASIZE\tluaM_limitN(1u << MAXABITS, TValue)\n\n/*\n** MAXHBITS is the largest integer such that 2^MAXHBITS fits in a\n** signed int.\n*/\n#define MAXHBITS\t(MAXABITS - 1)\n\n\n/*\n** MAXHSIZE is the maximum size of the hash part. It is the minimum\n** between 2^MAXHBITS and the maximum size such that, measured in bytes,\n** it fits in a 'size_t'.\n*/\n#define MAXHSIZE\tluaM_limitN(1u << MAXHBITS, Node)\n\n\n#define hashpow2(t,n)\t\t(gnode(t, lmod((n), sizenode(t))))\n\n#define hashstr(t,str)\t\thashpow2(t, (str)->hash)\n#define hashboolean(t,p)\thashpow2(t, p)\n#define hashint(t,i)\t\thashpow2(t, i)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, point2uint(p))\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {{NULL}, LUA_VEMPTY,  /* value's value and type */\n   LUA_VNIL, 0, {NULL}}  /* key type, next, and key value */\n};\n\n\nstatic const TValue absentkey = {ABSTKEYCONSTANT};\n\n\n\n/*\n** Hash for floating-point numbers.\n** The main computation should be just\n**     n = frexp(n, &i); return (n * INT_MAX) + i\n** but there are some numerical subtleties.\n** In a two-complement representation, INT_MAX does not has an exact\n** representation as a float, but INT_MIN does; because the absolute\n** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the\n** absolute value of the product 'frexp * -INT_MIN' is smaller or equal\n** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when\n** adding 'i'; the use of '~u' (instead of '-u') avoids problems with\n** INT_MIN.\n*/\n#if !defined(l_hashfloat)\nstatic int l_hashfloat (lua_Number n) {\n  int i;\n  lua_Integer ni;\n  n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);\n  if (!lua_numbertointeger(n, &ni)) {  /* is 'n' inf/-inf/NaN? */\n    lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));\n    return 0;\n  }\n  else {  /* normal case */\n    unsigned int u = cast_uint(i) + cast_uint(ni);\n    return cast_int(u <= cast_uint(INT_MAX) ? u : ~u);\n  }\n}\n#endif\n\n\n/*\n** returns the 'main' position of an element in a table (that is,\n** the index of its hash value). The key comes broken (tag in 'ktt'\n** and value in 'vkl') so that we can call it on keys inserted into\n** nodes.\n*/\nstatic Node *mainposition (const Table *t, int ktt, const Value *kvl) {\n  switch (withvariant(ktt)) {\n    case LUA_VNUMINT:\n      return hashint(t, ivalueraw(*kvl));\n    case LUA_VNUMFLT:\n      return hashmod(t, l_hashfloat(fltvalueraw(*kvl)));\n    case LUA_VSHRSTR:\n      return hashstr(t, tsvalueraw(*kvl));\n    case LUA_VLNGSTR:\n      return hashpow2(t, luaS_hashlongstr(tsvalueraw(*kvl)));\n    case LUA_VFALSE:\n      return hashboolean(t, 0);\n    case LUA_VTRUE:\n      return hashboolean(t, 1);\n    case LUA_VLIGHTUSERDATA:\n      return hashpointer(t, pvalueraw(*kvl));\n    case LUA_VLCF:\n      return hashpointer(t, fvalueraw(*kvl));\n    default:\n      return hashpointer(t, gcvalueraw(*kvl));\n  }\n}\n\n\n/*\n** Returns the main position of an element given as a 'TValue'\n*/\nstatic Node *mainpositionTV (const Table *t, const TValue *key) {\n  return mainposition(t, rawtt(key), valraw(key));\n}\n\n\n/*\n** Check whether key 'k1' is equal to the key in node 'n2'.\n** This equality is raw, so there are no metamethods. Floats\n** with integer values have been normalized, so integers cannot\n** be equal to floats. It is assumed that 'eqshrstr' is simply\n** pointer equality, so that short strings are handled in the\n** default case.\n*/\nstatic int equalkey (const TValue *k1, const Node *n2) {\n  if (rawtt(k1) != keytt(n2))  /* not the same variants? */\n   return 0;  /* cannot be same key */\n  switch (ttypetag(k1)) {\n    case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:\n      return 1;\n    case LUA_VNUMINT:\n      return (ivalue(k1) == keyival(n2));\n    case LUA_VNUMFLT:\n      return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));\n    case LUA_VLIGHTUSERDATA:\n      return pvalue(k1) == pvalueraw(keyval(n2));\n    case LUA_VLCF:\n      return fvalue(k1) == fvalueraw(keyval(n2));\n    case LUA_VLNGSTR:\n      return luaS_eqlngstr(tsvalue(k1), keystrval(n2));\n    default:\n      return gcvalue(k1) == gcvalueraw(keyval(n2));\n  }\n}\n\n\n/*\n** True if value of 'alimit' is equal to the real size of the array\n** part of table 't'. (Otherwise, the array part must be larger than\n** 'alimit'.)\n*/\n#define limitequalsasize(t)\t(isrealasize(t) || ispow2((t)->alimit))\n\n\n/*\n** Returns the real size of the 'array' array\n*/\nLUAI_FUNC unsigned int luaH_realasize (const Table *t) {\n  if (limitequalsasize(t))\n    return t->alimit;  /* this is the size */\n  else {\n    unsigned int size = t->alimit;\n    /* compute the smallest power of 2 not smaller than 'n' */\n    size |= (size >> 1);\n    size |= (size >> 2);\n    size |= (size >> 4);\n    size |= (size >> 8);\n    size |= (size >> 16);\n#if (UINT_MAX >> 30) > 3\n    size |= (size >> 32);  /* unsigned int has more than 32 bits */\n#endif\n    size++;\n    lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size);\n    return size;\n  }\n}\n\n\n/*\n** Check whether real size of the array is a power of 2.\n** (If it is not, 'alimit' cannot be changed to any other value\n** without changing the real size.)\n*/\nstatic int ispow2realasize (const Table *t) {\n  return (!isrealasize(t) || ispow2(t->alimit));\n}\n\n\nstatic unsigned int setlimittosize (Table *t) {\n  t->alimit = luaH_realasize(t);\n  setrealasize(t);\n  return t->alimit;\n}\n\n\n#define limitasasize(t)\tcheck_exp(isrealasize(t), t->alimit)\n\n\n\n/*\n** \"Generic\" get version. (Not that generic: not valid for integers,\n** which may be in array part, nor for floats with integral values.)\n*/\nstatic const TValue *getgeneric (Table *t, const TValue *key) {\n  Node *n = mainpositionTV(t, key);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (equalkey(key, n))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return &absentkey;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\n/*\n** returns the index for 'k' if 'k' is an appropriate key to live in\n** the array part of a table, 0 otherwise.\n*/\nstatic unsigned int arrayindex (lua_Integer k) {\n  if (l_castS2U(k) - 1u < MAXASIZE)  /* 'k' in [1, MAXASIZE]? */\n    return cast_uint(k);  /* 'key' is an appropriate array index */\n  else\n    return 0;\n}\n\n\n/*\n** returns the index of a 'key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signaled by 0.\n*/\nstatic unsigned int findindex (lua_State *L, Table *t, TValue *key,\n                               unsigned int asize) {\n  unsigned int i;\n  if (ttisnil(key)) return 0;  /* first iteration */\n  i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0;\n  if (i - 1u < asize)  /* is 'key' inside array part? */\n    return i;  /* yes; that's the index */\n  else {\n    const TValue *n = getgeneric(t, key);\n    if (unlikely(isabstkey(n)))\n      luaG_runerror(L, \"invalid key to 'next'\");  /* key not found */\n    i = cast_int(nodefromval(n) - gnode(t, 0));  /* key index in hash table */\n    /* hash elements are numbered after array ones */\n    return (i + 1) + asize;\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  unsigned int asize = luaH_realasize(t);\n  unsigned int i = findindex(L, t, s2v(key), asize);  /* find original key */\n  for (; i < asize; i++) {  /* try first array part */\n    if (!isempty(&t->array[i])) {  /* a non-empty entry? */\n      setivalue(s2v(key), i + 1);\n      setobj2s(L, key + 1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= asize; cast_int(i) < sizenode(t); i++) {  /* hash part */\n    if (!isempty(gval(gnode(t, i)))) {  /* a non-empty entry? */\n      Node *n = gnode(t, i);\n      getnodekey(L, s2v(key), n);\n      setobj2s(L, key + 1, gval(n));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\nstatic void freehash (lua_State *L, Table *t) {\n  if (!isdummy(t))\n    luaM_freearray(L, t->node, cast_sizet(sizenode(t)));\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n/*\n** Compute the optimal size for the array part of table 't'. 'nums' is a\n** \"count array\" where 'nums[i]' is the number of integers in the table\n** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of\n** integer keys in the table and leaves with the number of keys that\n** will go to the array part; return the optimal size.  (The condition\n** 'twotoi > 0' in the for loop stops the loop if 'twotoi' overflows.)\n*/\nstatic unsigned int computesizes (unsigned int nums[], unsigned int *pna) {\n  int i;\n  unsigned int twotoi;  /* 2^i (candidate for optimal size) */\n  unsigned int a = 0;  /* number of elements smaller than 2^i */\n  unsigned int na = 0;  /* number of elements to go to array part */\n  unsigned int optimal = 0;  /* optimal size for array part */\n  /* loop while keys can fill more than half of total size */\n  for (i = 0, twotoi = 1;\n       twotoi > 0 && *pna > twotoi / 2;\n       i++, twotoi *= 2) {\n    a += nums[i];\n    if (a > twotoi/2) {  /* more than half elements present? */\n      optimal = twotoi;  /* optimal size (till now) */\n      na = a;  /* all elements up to 'optimal' will go to array part */\n    }\n  }\n  lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);\n  *pna = na;\n  return optimal;\n}\n\n\nstatic int countint (lua_Integer key, unsigned int *nums) {\n  unsigned int k = arrayindex(key);\n  if (k != 0) {  /* is 'key' an appropriate array index? */\n    nums[luaO_ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** Count keys in array part of table 't': Fill 'nums[i]' with\n** number of keys that will go into corresponding slice and return\n** total number of non-nil keys.\n*/\nstatic unsigned int numusearray (const Table *t, unsigned int *nums) {\n  int lg;\n  unsigned int ttlg;  /* 2^lg */\n  unsigned int ause = 0;  /* summation of 'nums' */\n  unsigned int i = 1;  /* count to traverse all array keys */\n  unsigned int asize = limitasasize(t);  /* real array size */\n  /* traverse each slice */\n  for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {\n    unsigned int lc = 0;  /* counter */\n    unsigned int lim = ttlg;\n    if (lim > asize) {\n      lim = asize;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg - 1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!isempty(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* elements added to 'nums' (can go to array part) */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!isempty(gval(n))) {\n      if (keyisinteger(n))\n        ause += countint(keyival(n), nums);\n      totaluse++;\n    }\n  }\n  *pna += ause;\n  return totaluse;\n}\n\n\n/*\n** Creates an array for the hash part of a table with the given\n** size, or reuses the dummy node if size is zero.\n** The computation for size overflow is in two steps: the first\n** comparison ensures that the shift in the second one does not\n** overflow.\n*/\nstatic void setnodevector (lua_State *L, Table *t, unsigned int size) {\n  if (size == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common 'dummynode' */\n    t->lsizenode = 0;\n    t->lastfree = NULL;  /* signal that it is using dummy node */\n  }\n  else {\n    int i;\n    int lsize = luaO_ceillog2(size);\n    if (lsize > MAXHBITS || (1u << lsize) > MAXHSIZE)\n      luaG_runerror(L, \"table overflow\");\n    size = twoto(lsize);\n    t->node = luaM_newvector(L, size, Node);\n    for (i = 0; i < (int)size; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = 0;\n      setnilkey(n);\n      setempty(gval(n));\n    }\n    t->lsizenode = cast_byte(lsize);\n    t->lastfree = gnode(t, size);  /* all positions are free */\n  }\n}\n\n\n/*\n** (Re)insert all elements from the hash part of 'ot' into table 't'.\n*/\nstatic void reinsert (lua_State *L, Table *ot, Table *t) {\n  int j;\n  int size = sizenode(ot);\n  for (j = 0; j < size; j++) {\n    Node *old = gnode(ot, j);\n    if (!isempty(gval(old))) {\n      /* doesn't need barrier/invalidate cache, as entry was\n         already present in the table */\n      TValue k;\n      getnodekey(L, &k, old);\n      setobjt2t(L, luaH_set(L, t, &k), gval(old));\n    }\n  }\n}\n\n\n/*\n** Exchange the hash part of 't1' and 't2'.\n*/\nstatic void exchangehashpart (Table *t1, Table *t2) {\n  lu_byte lsizenode = t1->lsizenode;\n  Node *node = t1->node;\n  Node *lastfree = t1->lastfree;\n  t1->lsizenode = t2->lsizenode;\n  t1->node = t2->node;\n  t1->lastfree = t2->lastfree;\n  t2->lsizenode = lsizenode;\n  t2->node = node;\n  t2->lastfree = lastfree;\n}\n\n\n/*\n** Resize table 't' for the new given sizes. Both allocations (for\n** the hash part and for the array part) can fail, which creates some\n** subtleties. If the first allocation, for the hash part, fails, an\n** error is raised and that is it. Otherwise, it copies the elements from\n** the shrinking part of the array (if it is shrinking) into the new\n** hash. Then it reallocates the array part.  If that fails, the table\n** is in its original state; the function frees the new hash part and then\n** raises the allocation error. Otherwise, it sets the new hash part\n** into the table, initializes the new part of the array (if any) with\n** nils and reinserts the elements of the old hash back into the new\n** parts of the table.\n*/\nvoid luaH_resize (lua_State *L, Table *t, unsigned int newasize,\n                                          unsigned int nhsize) {\n  unsigned int i;\n  Table newt;  /* to keep the new hash part */\n  unsigned int oldasize = setlimittosize(t);\n  TValue *newarray;\n  /* create new hash part with appropriate size into 'newt' */\n  setnodevector(L, &newt, nhsize);\n  if (newasize < oldasize) {  /* will array shrink? */\n    t->alimit = newasize;  /* pretend array has new size... */\n    exchangehashpart(t, &newt);  /* and new hash */\n    /* re-insert into the new hash the elements from vanishing slice */\n    for (i = newasize; i < oldasize; i++) {\n      if (!isempty(&t->array[i]))\n        luaH_setint(L, t, i + 1, &t->array[i]);\n    }\n    t->alimit = oldasize;  /* restore current size... */\n    exchangehashpart(t, &newt);  /* and hash (in case of errors) */\n  }\n  /* allocate new array */\n  newarray = luaM_reallocvector(L, t->array, oldasize, newasize, TValue);\n  if (unlikely(newarray == NULL && newasize > 0)) {  /* allocation failed? */\n    freehash(L, &newt);  /* release new hash part */\n    luaM_error(L);  /* raise error (with array unchanged) */\n  }\n  /* allocation ok; initialize new part of the array */\n  exchangehashpart(t, &newt);  /* 't' has the new hash ('newt' has the old) */\n  t->array = newarray;  /* set new array part */\n  t->alimit = newasize;\n  for (i = oldasize; i < newasize; i++)  /* clear new slice of the array */\n     setempty(&t->array[i]);\n  /* re-insert elements from old hash part into new parts */\n  reinsert(L, &newt, t);  /* 'newt' now has the old hash */\n  freehash(L, &newt);  /* free old hash part */\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {\n  int nsize = allocsizenode(t);\n  luaH_resize(L, t, nasize, nsize);\n}\n\n/*\n** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i\n*/\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  unsigned int asize;  /* optimal size for array part */\n  unsigned int na;  /* number of keys in the array part */\n  unsigned int nums[MAXABITS + 1];\n  int i;\n  int totaluse;\n  for (i = 0; i <= MAXABITS; i++) nums[i] = 0;  /* reset counts */\n  setlimittosize(t);\n  na = numusearray(t, nums);  /* count keys in array part */\n  totaluse = na;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &na);  /* count keys in hash part */\n  /* count extra key */\n  if (ttisinteger(ek))\n    na += countint(ivalue(ek), nums);\n  totaluse++;\n  /* compute new size for array part */\n  asize = computesizes(nums, &na);\n  /* resize the table to new computed sizes */\n  luaH_resize(L, t, asize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L) {\n  GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table));\n  Table *t = gco2t(o);\n  t->metatable = NULL;\n  t->flags = cast_byte(maskflags);  /* table has no metamethod fields */\n  t->array = NULL;\n  t->alimit = 0;\n  setnodevector(L, t, 0);\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  freehash(L, t);\n  luaM_freearray(L, t->array, luaH_realasize(t));\n  luaM_free(L, t);\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  if (!isdummy(t)) {\n    while (t->lastfree > t->node) {\n      t->lastfree--;\n      if (keyisnil(t->lastfree))\n        return t->lastfree;\n    }\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main\n** position is free. If not, check whether colliding node is in its main\n** position or not: if it is not, move colliding node to an empty place and\n** put new key in its main position; otherwise (colliding node is in its main\n** position), new key goes to an empty position.\n*/\nTValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp;\n  TValue aux;\n  if (unlikely(ttisnil(key)))\n    luaG_runerror(L, \"table index is nil\");\n  else if (ttisfloat(key)) {\n    lua_Number f = fltvalue(key);\n    lua_Integer k;\n    if (luaV_flttointeger(f, &k, F2Ieq)) {  /* does key fit in an integer? */\n      setivalue(&aux, k);\n      key = &aux;  /* insert it as an integer */\n    }\n    else if (unlikely(luai_numisnan(f)))\n      luaG_runerror(L, \"table index is NaN\");\n  }\n  mp = mainpositionTV(t, key);\n  if (!isempty(gval(mp)) || isdummy(t)) {  /* main position is taken? */\n    Node *othern;\n    Node *f = getfreepos(t);  /* get a free place */\n    if (f == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      /* whatever called 'newkey' takes care of TM cache */\n      return luaH_set(L, t, key);  /* insert key into grown table */\n    }\n    lua_assert(!isdummy(t));\n    othern = mainposition(t, keytt(mp), &keyval(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (othern + gnext(othern) != mp)  /* find previous */\n        othern += gnext(othern);\n      gnext(othern) = cast_int(f - othern);  /* rechain to point to 'f' */\n      *f = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      if (gnext(mp) != 0) {\n        gnext(f) += cast_int(mp - f);  /* correct 'next' */\n        gnext(mp) = 0;  /* now 'mp' is free */\n      }\n      setempty(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      if (gnext(mp) != 0)\n        gnext(f) = cast_int((mp + gnext(mp)) - f);  /* chain new position */\n      else lua_assert(gnext(f) == 0);\n      gnext(mp) = cast_int(f - mp);\n      mp = f;\n    }\n  }\n  setnodekey(L, mp, key);\n  luaC_barrierback(L, obj2gco(t), key);\n  lua_assert(isempty(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** Search function for integers. If integer is inside 'alimit', get it\n** directly from the array part. Otherwise, if 'alimit' is not equal to\n** the real size of the array, key still can be in the array part. In\n** this case, try to avoid a call to 'luaH_realasize' when key is just\n** one more than the limit (so that it can be incremented without\n** changing the real size of the array).\n*/\nconst TValue *luaH_getint (Table *t, lua_Integer key) {\n  if (l_castS2U(key) - 1u < t->alimit)  /* 'key' in [1, t->alimit]? */\n    return &t->array[key - 1];\n  else if (!limitequalsasize(t) &&  /* key still may be in the array part? */\n           (l_castS2U(key) == t->alimit + 1 ||\n            l_castS2U(key) - 1u < luaH_realasize(t))) {\n    t->alimit = cast_uint(key);  /* probably '#t' is here now */\n    return &t->array[key - 1];\n  }\n  else {\n    Node *n = hashint(t, key);\n    for (;;) {  /* check whether 'key' is somewhere in the chain */\n      if (keyisinteger(n) && keyival(n) == key)\n        return gval(n);  /* that's it */\n      else {\n        int nx = gnext(n);\n        if (nx == 0) break;\n        n += nx;\n      }\n    }\n    return &absentkey;\n  }\n}\n\n\n/*\n** search function for short strings\n*/\nconst TValue *luaH_getshortstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  lua_assert(key->tt == LUA_VSHRSTR);\n  for (;;) {  /* check whether 'key' is somewhere in the chain */\n    if (keyisshrstr(n) && eqshrstr(keystrval(n), key))\n      return gval(n);  /* that's it */\n    else {\n      int nx = gnext(n);\n      if (nx == 0)\n        return &absentkey;  /* not found */\n      n += nx;\n    }\n  }\n}\n\n\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  if (key->tt == LUA_VSHRSTR)\n    return luaH_getshortstr(t, key);\n  else {  /* for long strings, use generic case */\n    TValue ko;\n    setsvalue(cast(lua_State *, NULL), &ko, key);\n    return getgeneric(t, &ko);\n  }\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttypetag(key)) {\n    case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key));\n    case LUA_VNUMINT: return luaH_getint(t, ivalue(key));\n    case LUA_VNIL: return &absentkey;\n    case LUA_VNUMFLT: {\n      lua_Integer k;\n      if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */\n        return luaH_getint(t, k);  /* use specialized version */\n      /* else... */\n    }  /* FALLTHROUGH */\n    default:\n      return getgeneric(t, key);\n  }\n}\n\n\n/*\n** beware: when using this function you probably need to check a GC\n** barrier and invalidate the TM cache.\n*/\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  if (!isabstkey(p))\n    return cast(TValue *, p);\n  else return luaH_newkey(L, t, key);\n}\n\n\nvoid luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {\n  const TValue *p = luaH_getint(t, key);\n  TValue *cell;\n  if (!isabstkey(p))\n    cell = cast(TValue *, p);\n  else {\n    TValue k;\n    setivalue(&k, key);\n    cell = luaH_newkey(L, t, &k);\n  }\n  setobj2t(L, cell, value);\n}\n\n\n/*\n** Try to find a boundary in the hash part of table 't'. From the\n** caller, we know that 'j' is zero or present and that 'j + 1' is\n** present. We want to find a larger key that is absent from the\n** table, so that we can do a binary search between the two keys to\n** find a boundary. We keep doubling 'j' until we get an absent index.\n** If the doubling would overflow, we try LUA_MAXINTEGER. If it is\n** absent, we are ready for the binary search. ('j', being max integer,\n** is larger or equal to 'i', but it cannot be equal because it is\n** absent while 'i' is present; so 'j > i'.) Otherwise, 'j' is a\n** boundary. ('j + 1' cannot be a present integer key because it is\n** not a valid integer in Lua.)\n*/\nstatic lua_Unsigned hash_search (Table *t, lua_Unsigned j) {\n  lua_Unsigned i;\n  if (j == 0) j++;  /* the caller ensures 'j + 1' is present */\n  do {\n    i = j;  /* 'i' is a present index */\n    if (j <= l_castS2U(LUA_MAXINTEGER) / 2)\n      j *= 2;\n    else {\n      j = LUA_MAXINTEGER;\n      if (isempty(luaH_getint(t, j)))  /* t[j] not present? */\n        break;  /* 'j' now is an absent index */\n      else  /* weird case */\n        return j;  /* well, max integer is a boundary... */\n    }\n  } while (!isempty(luaH_getint(t, j)));  /* repeat until an absent t[j] */\n  /* i < j  &&  t[i] present  &&  t[j] absent */\n  while (j - i > 1u) {  /* do a binary search between them */\n    lua_Unsigned m = (i + j) / 2;\n    if (isempty(luaH_getint(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\nstatic unsigned int binsearch (const TValue *array, unsigned int i,\n                                                    unsigned int j) {\n  while (j - i > 1u) {  /* binary search */\n    unsigned int m = (i + j) / 2;\n    if (isempty(&array[m - 1])) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table 't'. (A 'boundary' is an integer index\n** such that t[i] is present and t[i+1] is absent, or 0 if t[1] is absent\n** and 'maxinteger' if t[maxinteger] is present.)\n** (In the next explanation, we use Lua indices, that is, with base 1.\n** The code itself uses base 0 when indexing the array part of the table.)\n** The code starts with 'limit = t->alimit', a position in the array\n** part that may be a boundary.\n**\n** (1) If 't[limit]' is empty, there must be a boundary before it.\n** As a common case (e.g., after 't[#t]=nil'), check whether 'limit-1'\n** is present. If so, it is a boundary. Otherwise, do a binary search\n** between 0 and limit to find a boundary. In both cases, try to\n** use this boundary as the new 'alimit', as a hint for the next call.\n**\n** (2) If 't[limit]' is not empty and the array has more elements\n** after 'limit', try to find a boundary there. Again, try first\n** the special case (which should be quite frequent) where 'limit+1'\n** is empty, so that 'limit' is a boundary. Otherwise, check the\n** last element of the array part. If it is empty, there must be a\n** boundary between the old limit (present) and the last element\n** (absent), which is found with a binary search. (This boundary always\n** can be a new limit.)\n**\n** (3) The last case is when there are no elements in the array part\n** (limit == 0) or its last element (the new limit) is present.\n** In this case, must check the hash part. If there is no hash part\n** or 'limit+1' is absent, 'limit' is a boundary.  Otherwise, call\n** 'hash_search' to find a boundary in the hash part of the table.\n** (In those cases, the boundary is not inside the array part, and\n** therefore cannot be used as a new limit.)\n*/\nlua_Unsigned luaH_getn (Table *t) {\n  unsigned int limit = t->alimit;\n  if (limit > 0 && isempty(&t->array[limit - 1])) {  /* (1)? */\n    /* there must be a boundary before 'limit' */\n    if (limit >= 2 && !isempty(&t->array[limit - 2])) {\n      /* 'limit - 1' is a boundary; can it be a new limit? */\n      if (ispow2realasize(t) && !ispow2(limit - 1)) {\n        t->alimit = limit - 1;\n        setnorealasize(t);  /* now 'alimit' is not the real size */\n      }\n      return limit - 1;\n    }\n    else {  /* must search for a boundary in [0, limit] */\n      unsigned int boundary = binsearch(t->array, 0, limit);\n      /* can this boundary represent the real size of the array? */\n      if (ispow2realasize(t) && boundary > luaH_realasize(t) / 2) {\n        t->alimit = boundary;  /* use it as the new limit */\n        setnorealasize(t);\n      }\n      return boundary;\n    }\n  }\n  /* 'limit' is zero or present in table */\n  if (!limitequalsasize(t)) {  /* (2)? */\n    /* 'limit' > 0 and array has more elements after 'limit' */\n    if (isempty(&t->array[limit]))  /* 'limit + 1' is empty? */\n      return limit;  /* this is the boundary */\n    /* else, try last element in the array */\n    limit = luaH_realasize(t);\n    if (isempty(&t->array[limit - 1])) {  /* empty? */\n      /* there must be a boundary in the array after old limit,\n         and it must be a valid new limit */\n      unsigned int boundary = binsearch(t->array, t->alimit, limit);\n      t->alimit = boundary;\n      return boundary;\n    }\n    /* else, new limit is present in the table; check the hash part */\n  }\n  /* (3) 'limit' is the last element and either is zero or present in table */\n  lua_assert(limit == luaH_realasize(t) &&\n             (limit == 0 || !isempty(&t->array[limit - 1])));\n  if (isdummy(t) || isempty(luaH_getint(t, cast(lua_Integer, limit + 1))))\n    return limit;  /* 'limit + 1' is absent */\n  else  /* 'limit + 1' is also present */\n    return hash_search(t, limit);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\n/* export these functions for the test library */\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainpositionTV(t, key);\n}\n\nint luaH_isdummy (const Table *t) { return isdummy(t); }\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/ltable.h",
    "content": "/*\n** $Id: ltable.h $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->u.next)\n\n\n/*\n** Clear all bits of fast-access metamethods, which means that the table\n** may have any of these metamethods. (First access that fails after the\n** clearing will set the bit again.)\n*/\n#define invalidateTMcache(t)\t((t)->flags &= ~maskflags)\n\n\n/* true when 't' is using 'dummynode' as its hash part */\n#define isdummy(t)\t\t((t)->lastfree == NULL)\n\n\n/* allocated size for hash nodes */\n#define allocsizenode(t)\t(isdummy(t) ? 0 : sizenode(t))\n\n\n/* returns the Node, given the value of a table entry */\n#define nodefromval(v)\tcast(Node *, (v))\n\n\nLUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);\nLUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,\n                                                    TValue *value);\nLUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L);\nLUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,\n                                                    unsigned int nhsize);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC lua_Unsigned luaH_getn (Table *t);\nLUAI_FUNC unsigned int luaH_realasize (const Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (const Table *t);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <stddef.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/*\n** Operations that an object must define to mimic a table\n** (some functions only need some of them)\n*/\n#define TAB_R\t1\t\t\t/* read */\n#define TAB_W\t2\t\t\t/* write */\n#define TAB_L\t4\t\t\t/* length */\n#define TAB_RW\t(TAB_R | TAB_W)\t\t/* read/write */\n\n\n#define aux_getn(L,n,w)\t(checktab(L, n, (w) | TAB_L), luaL_len(L, n))\n\n\nstatic int checkfield (lua_State *L, const char *key, int n) {\n  lua_pushstring(L, key);\n  return (lua_rawget(L, -n) != LUA_TNIL);\n}\n\n\n/*\n** Check that 'arg' either is a table or can behave like one (that is,\n** has a metatable with the required metamethods)\n*/\nstatic void checktab (lua_State *L, int arg, int what) {\n  if (lua_type(L, arg) != LUA_TTABLE) {  /* is it not a table? */\n    int n = 1;  /* number of elements to pop */\n    if (lua_getmetatable(L, arg) &&  /* must have metatable */\n        (!(what & TAB_R) || checkfield(L, \"__index\", ++n)) &&\n        (!(what & TAB_W) || checkfield(L, \"__newindex\", ++n)) &&\n        (!(what & TAB_L) || checkfield(L, \"__len\", ++n))) {\n      lua_pop(L, n);  /* pop metatable and tested metamethods */\n    }\n    else\n      luaL_checktype(L, arg, LUA_TTABLE);  /* force an error */\n  }\n}\n\n\nstatic int tinsert (lua_State *L) {\n  lua_Integer e = aux_getn(L, 1, TAB_RW) + 1;  /* first empty element */\n  lua_Integer pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      lua_Integer i;\n      pos = luaL_checkinteger(L, 2);  /* 2nd argument is the position */\n      /* check whether 'pos' is in [1, e] */\n      luaL_argcheck(L, (lua_Unsigned)pos - 1u < (lua_Unsigned)e, 2,\n                       \"position out of bounds\");\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_geti(L, 1, i - 1);\n        lua_seti(L, 1, i);  /* t[i] = t[i - 1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to 'insert'\");\n    }\n  }\n  lua_seti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  lua_Integer size = aux_getn(L, 1, TAB_RW);\n  lua_Integer pos = luaL_optinteger(L, 2, size);\n  if (pos != size)  /* validate 'pos' if given */\n    /* check whether 'pos' is in [1, size + 1] */\n    luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1,\n                     \"position out of bounds\");\n  lua_geti(L, 1, pos);  /* result = t[pos] */\n  for ( ; pos < size; pos++) {\n    lua_geti(L, 1, pos + 1);\n    lua_seti(L, 1, pos);  /* t[pos] = t[pos + 1] */\n  }\n  lua_pushnil(L);\n  lua_seti(L, 1, pos);  /* remove entry t[pos] */\n  return 1;\n}\n\n\n/*\n** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever\n** possible, copy in increasing order, which is better for rehashing.\n** \"possible\" means destination after original range, or smaller\n** than origin, or copying to another table.\n*/\nstatic int tmove (lua_State *L) {\n  lua_Integer f = luaL_checkinteger(L, 2);\n  lua_Integer e = luaL_checkinteger(L, 3);\n  lua_Integer t = luaL_checkinteger(L, 4);\n  int tt = !lua_isnoneornil(L, 5) ? 5 : 1;  /* destination table */\n  checktab(L, 1, TAB_R);\n  checktab(L, tt, TAB_W);\n  if (e >= f) {  /* otherwise, nothing to move */\n    lua_Integer n, i;\n    luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,\n                  \"too many elements to move\");\n    n = e - f + 1;  /* number of elements to move */\n    luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,\n                  \"destination wrap around\");\n    if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {\n      for (i = 0; i < n; i++) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n    else {\n      for (i = n - 1; i >= 0; i--) {\n        lua_geti(L, 1, f + i);\n        lua_seti(L, tt, t + i);\n      }\n    }\n  }\n  lua_pushvalue(L, tt);  /* return destination table */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {\n  lua_geti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for 'concat'\",\n                  luaL_typename(L, -1), i);\n  luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  lua_Integer last = aux_getn(L, 1, TAB_R);\n  size_t lsep;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  lua_Integer i = luaL_optinteger(L, 3, 1);\n  last = luaL_optinteger(L, 4, last);\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Pack/unpack\n** =======================================================\n*/\n\nstatic int tpack (lua_State *L) {\n  int i;\n  int n = lua_gettop(L);  /* number of elements to pack */\n  lua_createtable(L, n, 1);  /* create result table */\n  lua_insert(L, 1);  /* put it at index 1 */\n  for (i = n; i >= 1; i--)  /* assign elements */\n    lua_seti(L, 1, i);\n  lua_pushinteger(L, n);\n  lua_setfield(L, 1, \"n\");  /* t.n = number of elements */\n  return 1;  /* return table */\n}\n\n\nstatic int tunpack (lua_State *L) {\n  lua_Unsigned n;\n  lua_Integer i = luaL_optinteger(L, 2, 1);\n  lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = (lua_Unsigned)e - i;  /* number of elements minus 1 (avoid overflows) */\n  if (n >= (unsigned int)INT_MAX  || !lua_checkstack(L, (int)(++n)))\n    return luaL_error(L, \"too many results to unpack\");\n  for (; i < e; i++) {  /* push arg[i..e - 1] (to avoid overflows) */\n    lua_geti(L, 1, i);\n  }\n  lua_geti(L, 1, e);  /* push last element */\n  return (int)n;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on 'Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n** =======================================================\n*/\n\n\n/* type for array indices */\ntypedef unsigned int IdxT;\n\n\n/*\n** Produce a \"random\" 'unsigned int' to randomize pivot choice. This\n** macro is used only when 'sort' detects a big imbalance in the result\n** of a partition. (If you don't want/need this \"randomness\", ~0 is a\n** good choice.)\n*/\n#if !defined(l_randomizePivot)\t\t/* { */\n\n#include <time.h>\n\n/* size of 'e' measured in number of 'unsigned int's */\n#define sof(e)\t\t(sizeof(e) / sizeof(unsigned int))\n\n/*\n** Use 'time' and 'clock' as sources of \"randomness\". Because we don't\n** know the types 'clock_t' and 'time_t', we cannot cast them to\n** anything without risking overflows. A safe way to use their values\n** is to copy them to an array of a known type and use the array values.\n*/\nstatic unsigned int l_randomizePivot (void) {\n  clock_t c = clock();\n  time_t t = time(NULL);\n  unsigned int buff[sof(c) + sof(t)];\n  unsigned int i, rnd = 0;\n  memcpy(buff, &c, sof(c) * sizeof(unsigned int));\n  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));\n  for (i = 0; i < sof(buff); i++)\n    rnd += buff[i];\n  return rnd;\n}\n\n#endif\t\t\t\t\t/* } */\n\n\n/* arrays larger than 'RANLIMIT' may use randomized pivots */\n#define RANLIMIT\t100u\n\n\nstatic void set2 (lua_State *L, IdxT i, IdxT j) {\n  lua_seti(L, 1, i);\n  lua_seti(L, 1, j);\n}\n\n\n/*\n** Return true iff value at stack index 'a' is less than the value at\n** index 'b' (according to the order of the sort).\n*/\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (lua_isnil(L, 2))  /* no function? */\n    return lua_compare(L, a, b, LUA_OPLT);  /* a < b */\n  else {  /* function */\n    int res;\n    lua_pushvalue(L, 2);    /* push function */\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and 'a' */\n    lua_call(L, 2, 1);      /* call function */\n    res = lua_toboolean(L, -1);  /* get result */\n    lua_pop(L, 1);          /* pop result */\n    return res;\n  }\n}\n\n\n/*\n** Does the partition: Pivot P is at the top of the stack.\n** precondition: a[lo] <= P == a[up-1] <= a[up],\n** so it only needs to do the partition from lo + 1 to up - 2.\n** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]\n** returns 'i'.\n*/\nstatic IdxT partition (lua_State *L, IdxT lo, IdxT up) {\n  IdxT i = lo;  /* will be incremented before first use */\n  IdxT j = up - 1;  /* will be decremented before first use */\n  /* loop invariant: a[lo .. i] <= P <= a[j .. up] */\n  for (;;) {\n    /* next loop: repeat ++i while a[i] < P */\n    while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {\n      if (i == up - 1)  /* a[i] < P  but a[up - 1] == P  ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[i] */\n    }\n    /* after the loop, a[i] >= P and a[lo .. i - 1] < P */\n    /* next loop: repeat --j while P < a[j] */\n    while ((void)lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {\n      if (j < i)  /* j < i  but  a[j] > P ?? */\n        luaL_error(L, \"invalid order function for sorting\");\n      lua_pop(L, 1);  /* remove a[j] */\n    }\n    /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */\n    if (j < i) {  /* no elements out of place? */\n      /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */\n      lua_pop(L, 1);  /* pop a[j] */\n      /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */\n      set2(L, up - 1, i);\n      return i;\n    }\n    /* otherwise, swap a[i] - a[j] to restore invariant and repeat */\n    set2(L, i, j);\n  }\n}\n\n\n/*\n** Choose an element in the middle (2nd-3th quarters) of [lo,up]\n** \"randomized\" by 'rnd'\n*/\nstatic IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {\n  IdxT r4 = (up - lo) / 4;  /* range/4 */\n  IdxT p = rnd % (r4 * 2) + (lo + r4);\n  lua_assert(lo + r4 <= p && p <= up - r4);\n  return p;\n}\n\n\n/*\n** Quicksort algorithm (recursive function)\n*/\nstatic void auxsort (lua_State *L, IdxT lo, IdxT up,\n                                   unsigned int rnd) {\n  while (lo < up) {  /* loop for tail recursion */\n    IdxT p;  /* Pivot index */\n    IdxT n;  /* to be used later */\n    /* sort elements 'lo', 'p', and 'up' */\n    lua_geti(L, 1, lo);\n    lua_geti(L, 1, up);\n    if (sort_comp(L, -1, -2))  /* a[up] < a[lo]? */\n      set2(L, lo, up);  /* swap a[lo] - a[up] */\n    else\n      lua_pop(L, 2);  /* remove both values */\n    if (up - lo == 1)  /* only 2 elements? */\n      return;  /* already sorted */\n    if (up - lo < RANLIMIT || rnd == 0)  /* small interval or no randomize? */\n      p = (lo + up)/2;  /* middle element is a good pivot */\n    else  /* for larger intervals, it is worth a random pivot */\n      p = choosePivot(lo, up, rnd);\n    lua_geti(L, 1, p);\n    lua_geti(L, 1, lo);\n    if (sort_comp(L, -2, -1))  /* a[p] < a[lo]? */\n      set2(L, p, lo);  /* swap a[p] - a[lo] */\n    else {\n      lua_pop(L, 1);  /* remove a[lo] */\n      lua_geti(L, 1, up);\n      if (sort_comp(L, -1, -2))  /* a[up] < a[p]? */\n        set2(L, p, up);  /* swap a[up] - a[p] */\n      else\n        lua_pop(L, 2);\n    }\n    if (up - lo == 2)  /* only 3 elements? */\n      return;  /* already sorted */\n    lua_geti(L, 1, p);  /* get middle element (Pivot) */\n    lua_pushvalue(L, -1);  /* push Pivot */\n    lua_geti(L, 1, up - 1);  /* push a[up - 1] */\n    set2(L, p, up - 1);  /* swap Pivot (a[p]) with a[up - 1] */\n    p = partition(L, lo, up);\n    /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */\n    if (p - lo < up - p) {  /* lower interval is smaller? */\n      auxsort(L, lo, p - 1, rnd);  /* call recursively for lower interval */\n      n = p - lo;  /* size of smaller interval */\n      lo = p + 1;  /* tail call for [p + 1 .. up] (upper interval) */\n    }\n    else {\n      auxsort(L, p + 1, up, rnd);  /* call recursively for upper interval */\n      n = up - p;  /* size of smaller interval */\n      up = p - 1;  /* tail call for [lo .. p - 1]  (lower interval) */\n    }\n    if ((up - lo) / 128 > n) /* partition too imbalanced? */\n      rnd = l_randomizePivot();  /* try a new randomization */\n  }  /* tail call auxsort(L, lo, up, rnd) */\n}\n\n\nstatic int sort (lua_State *L) {\n  lua_Integer n = aux_getn(L, 1, TAB_RW);\n  if (n > 1) {  /* non-trivial interval? */\n    luaL_argcheck(L, n < INT_MAX, 1, \"array too big\");\n    if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n      luaL_checktype(L, 2, LUA_TFUNCTION);  /* must be a function */\n    lua_settop(L, 2);  /* make sure there are two arguments */\n    auxsort(L, 1, (IdxT)n, 0);\n  }\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n  {\"insert\", tinsert},\n  {\"pack\", tpack},\n  {\"unpack\", tunpack},\n  {\"remove\", tremove},\n  {\"move\", tmove},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_table (lua_State *L) {\n  luaL_newlib(L, tab_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ltm.c",
    "content": "/*\n** $Id: ltm.c $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\nstatic const char udatatypename[] = \"userdata\";\n\nLUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTYPES] = {\n  \"no value\",\n  \"nil\", \"boolean\", udatatypename, \"number\",\n  \"string\", \"table\", \"function\", udatatypename, \"thread\",\n  \"upvalue\", \"proto\" /* these last cases are used for tests only */\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__len\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__mod\", \"__pow\",\n    \"__div\", \"__idiv\",\n    \"__band\", \"__bor\", \"__bxor\", \"__shl\", \"__shr\",\n    \"__unm\", \"__bnot\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\", \"__close\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaC_fix(L, obj2gco(G(L)->tmname[i]));  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getshortstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (notm(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttype(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(o)];\n  }\n  return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : &G(L)->nilvalue);\n}\n\n\n/*\n** Return the name of the type of an object. For tables and userdata\n** with metatable, use their '__name' metafield, if present.\n*/\nconst char *luaT_objtypename (lua_State *L, const TValue *o) {\n  Table *mt;\n  if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||\n      (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {\n    const TValue *name = luaH_getshortstr(mt, luaS_new(L, \"__name\"));\n    if (ttisstring(name))  /* is '__name' a string? */\n      return getstr(tsvalue(name));  /* use it as type name */\n  }\n  return ttypename(ttype(o));  /* else use standard type name */\n}\n\n\nvoid luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                  const TValue *p2, const TValue *p3) {\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  setobj2s(L, func + 3, p3);  /* 3rd argument */\n  L->top = func + 4;\n  /* metamethod may yield only when called from Lua code */\n  if (isLuacode(L->ci))\n    luaD_call(L, func, 0);\n  else\n    luaD_callnoyield(L, func, 0);\n}\n\n\nvoid luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1,\n                     const TValue *p2, StkId res) {\n  ptrdiff_t result = savestack(L, res);\n  StkId func = L->top;\n  setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */\n  setobj2s(L, func + 1, p1);  /* 1st argument */\n  setobj2s(L, func + 2, p2);  /* 2nd argument */\n  L->top += 3;\n  /* metamethod may yield only when called from Lua code */\n  if (isLuacode(L->ci))\n    luaD_call(L, func, 1);\n  else\n    luaD_callnoyield(L, func, 1);\n  res = restorestack(L, result);\n  setobjs2s(L, res, --L->top);  /* move result to its place */\n}\n\n\nstatic int callbinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (notm(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (notm(tm)) return 0;\n  luaT_callTMres(L, tm, p1, p2, res);\n  return 1;\n}\n\n\nvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                    StkId res, TMS event) {\n  if (!callbinTM(L, p1, p2, res, event)) {\n    switch (event) {\n      case TM_BAND: case TM_BOR: case TM_BXOR:\n      case TM_SHL: case TM_SHR: case TM_BNOT: {\n        if (ttisnumber(p1) && ttisnumber(p2))\n          luaG_tointerror(L, p1, p2);\n        else\n          luaG_opinterror(L, p1, p2, \"perform bitwise operation on\");\n      }\n      /* calls never return, but to avoid warnings: *//* FALLTHROUGH */\n      default:\n        luaG_opinterror(L, p1, p2, \"perform arithmetic on\");\n    }\n  }\n}\n\n\nvoid luaT_tryconcatTM (lua_State *L) {\n  StkId top = L->top;\n  if (!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2, TM_CONCAT))\n    luaG_concaterror(L, s2v(top - 2), s2v(top - 1));\n}\n\n\nvoid luaT_trybinassocTM (lua_State *L, const TValue *p1, const TValue *p2,\n                                       int flip, StkId res, TMS event) {\n  if (flip)\n    luaT_trybinTM(L, p2, p1, res, event);\n  else\n    luaT_trybinTM(L, p1, p2, res, event);\n}\n\n\nvoid luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,\n                                   int flip, StkId res, TMS event) {\n  TValue aux;\n  setivalue(&aux, i2);\n  luaT_trybinassocTM(L, p1, &aux, flip, res, event);\n}\n\n\n/*\n** Calls an order tag method.\n** For lessequal, LUA_COMPAT_LT_LE keeps compatibility with old\n** behavior: if there is no '__le', try '__lt', based on l <= r iff\n** !(r < l) (assuming a total order). If the metamethod yields during\n** this substitution, the continuation has to know about it (to negate\n** the result of r<l); bit CIST_LEQ in the call status keeps that\n** information.\n*/\nint luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                      TMS event) {\n  if (callbinTM(L, p1, p2, L->top, event))  /* try original event */\n    return !l_isfalse(s2v(L->top));\n#if defined(LUA_COMPAT_LT_LE)\n  else if (event == TM_LE) {\n      /* try '!(p2 < p1)' for '(p1 <= p2)' */\n      L->ci->callstatus |= CIST_LEQ;  /* mark it is doing 'lt' for 'le' */\n      if (callbinTM(L, p2, p1, L->top, TM_LT)) {\n        L->ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        return l_isfalse(s2v(L->top));\n      }\n      /* else error will remove this 'ci'; no need to clear mark */\n  }\n#endif\n  luaG_ordererror(L, p1, p2);  /* no metamethod found */\n  return 0;  /* to avoid warnings */\n}\n\n\nint luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,\n                       int flip, int isfloat, TMS event) {\n  TValue aux; const TValue *p2;\n  if (isfloat) {\n    setfltvalue(&aux, cast_num(v2));\n  }\n  else\n    setivalue(&aux, v2);\n  if (flip) {  /* arguments were exchanged? */\n    p2 = p1; p1 = &aux;  /* correct them */\n  }\n  else\n    p2 = &aux;\n  return luaT_callorderTM(L, p1, p2, event);\n}\n\n\nvoid luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci,\n                         const Proto *p) {\n  int i;\n  int actual = cast_int(L->top - ci->func) - 1;  /* number of arguments */\n  int nextra = actual - nfixparams;  /* number of extra arguments */\n  ci->u.l.nextraargs = nextra;\n  luaD_checkstack(L, p->maxstacksize + 1);\n  /* copy function to the top of the stack */\n  setobjs2s(L, L->top++, ci->func);\n  /* move fixed parameters to the top of the stack */\n  for (i = 1; i <= nfixparams; i++) {\n    setobjs2s(L, L->top++, ci->func + i);\n    setnilvalue(s2v(ci->func + i));  /* erase original parameter (for GC) */\n  }\n  ci->func += actual + 1;\n  ci->top += actual + 1;\n  lua_assert(L->top <= ci->top && ci->top <= L->stack_last);\n}\n\n\nvoid luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {\n  int i;\n  int nextra = ci->u.l.nextraargs;\n  if (wanted < 0) {\n    wanted = nextra;  /* get all extra arguments available */\n    checkstackGCp(L, nextra, where);  /* ensure stack space */\n    L->top = where + nextra;  /* next instruction will need top */\n  }\n  for (i = 0; i < wanted && i < nextra; i++)\n    setobjs2s(L, where + i, ci->func - nextra + i);\n  for (; i < wanted; i++)   /* complete required results with nil */\n    setnilvalue(s2v(where + i));\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/ltm.h",
    "content": "/*\n** $Id: ltm.h $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\" and \"ORDER OP\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_LEN,\n  TM_EQ,  /* last tag method with fast access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_MOD,\n  TM_POW,\n  TM_DIV,\n  TM_IDIV,\n  TM_BAND,\n  TM_BOR,\n  TM_BXOR,\n  TM_SHL,\n  TM_SHR,\n  TM_UNM,\n  TM_BNOT,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_CLOSE,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n/*\n** Mask with 1 in all fast-access methods. A 1 in any of these bits\n** in the flag of a (meta)table means the metatable does not have the\n** corresponding metamethod field. (Bit 7 of the flag is used for\n** 'isrealasize'.)\n*/\n#define maskflags\t(~(~0u << (TM_EQ + 1)))\n\n\n/*\n** Test whether there is no tagmethod.\n** (Because tagmethods use raw accesses, the result may be an \"empty\" nil.)\n*/\n#define notm(tm)\tttisnil(tm)\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\n#define ttypename(x)\tluaT_typenames_[(x) + 1]\n\nLUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)\n\n\nLUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\nLUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,\n                            const TValue *p2, const TValue *p3);\nLUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f,\n                            const TValue *p1, const TValue *p2, StkId p3);\nLUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,\n                              StkId res, TMS event);\nLUAI_FUNC void luaT_tryconcatTM (lua_State *L);\nLUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1,\n       const TValue *p2, int inv, StkId res, TMS event);\nLUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,\n                               int inv, StkId res, TMS event);\nLUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,\n                                const TValue *p2, TMS event);\nLUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,\n                                 int inv, int isfloat, TMS event);\n\nLUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,\n                                   struct CallInfo *ci, const Proto *p);\nLUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci,\n                                              StkId where, int wanted);\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lua.c",
    "content": "/*\n** $Id: lua.c $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n#define lua_c\n\n#include \"lprefix.h\"\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include <signal.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#if !defined(LUA_PROGNAME)\n#define LUA_PROGNAME\t\t\"lua\"\n#endif\n\n#if !defined(LUA_INIT_VAR)\n#define LUA_INIT_VAR\t\t\"LUA_INIT\"\n#endif\n\n#define LUA_INITVARVERSION\tLUA_INIT_VAR LUA_VERSUFFIX\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n/*\n** Hook set by signal function to stop the interpreter.\n*/\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);  /* reset hook */\n  luaL_error(L, \"interrupted!\");\n}\n\n\n/*\n** Function to be called at a C signal. Because a C signal cannot\n** just change a Lua state (as there is no proper synchronization),\n** this function only sets a hook that, when called, will stop the\n** interpreter.\n*/\nstatic void laction (int i) {\n  int flag = LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE | LUA_MASKCOUNT;\n  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */\n  lua_sethook(globalL, lstop, flag, 1);\n}\n\n\nstatic void print_usage (const char *badoption) {\n  lua_writestringerror(\"%s: \", progname);\n  if (badoption[1] == 'e' || badoption[1] == 'l')\n    lua_writestringerror(\"'%s' needs argument\\n\", badoption);\n  else\n    lua_writestringerror(\"unrecognized option '%s'\\n\", badoption);\n  lua_writestringerror(\n  \"usage: %s [options] [script [args]]\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string 'stat'\\n\"\n  \"  -i       enter interactive mode after executing 'script'\\n\"\n  \"  -l name  require library 'name' into global 'name'\\n\"\n  \"  -v       show version information\\n\"\n  \"  -E       ignore environment variables\\n\"\n  \"  -W       turn warnings on\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and execute stdin\\n\"\n  ,\n  progname);\n}\n\n\n/*\n** Prints an error message, adding the program name in front of it\n** (if present)\n*/\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) lua_writestringerror(\"%s: \", pname);\n  lua_writestringerror(\"%s\\n\", msg);\n}\n\n\n/*\n** Check whether 'status' is not OK and, if so, prints the error\n** message on the top of the stack. It assumes that the error object\n** is a string, as it was either generated by Lua or by 'msghandler'.\n*/\nstatic int report (lua_State *L, int status) {\n  if (status != LUA_OK) {\n    const char *msg = lua_tostring(L, -1);\n    l_message(progname, msg);\n    lua_pop(L, 1);  /* remove message */\n  }\n  return status;\n}\n\n\n/*\n** Message handler used to run all chunks\n*/\nstatic int msghandler (lua_State *L) {\n  const char *msg = lua_tostring(L, 1);\n  if (msg == NULL) {  /* is error object not a string? */\n    if (luaL_callmeta(L, 1, \"__tostring\") &&  /* does it have a metamethod */\n        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */\n      return 1;  /* that is the message */\n    else\n      msg = lua_pushfstring(L, \"(error object is a %s value)\",\n                               luaL_typename(L, 1));\n  }\n  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */\n  return 1;  /* return the traceback */\n}\n\n\n/*\n** Interface to 'lua_pcall', which sets appropriate message function\n** and C-signal handler. Used to run all chunks.\n*/\nstatic int docall (lua_State *L, int narg, int nres) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, msghandler);  /* push message handler */\n  lua_insert(L, base);  /* put it under function and args */\n  globalL = L;  /* to be available to 'laction' */\n  signal(SIGINT, laction);  /* set C-signal handler */\n  status = lua_pcall(L, narg, nres, base);\n  signal(SIGINT, SIG_DFL); /* reset C-signal handler */\n  lua_remove(L, base);  /* remove message handler from the stack */\n  return status;\n}\n\n\nstatic void print_version (void) {\n  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));\n  lua_writeline();\n}\n\n\n/*\n** Create the 'arg' table, which stores all arguments from the\n** command line ('argv'). It should be aligned so that, at index 0,\n** it has 'argv[script]', which is the script name. The arguments\n** to the script (everything after 'script') go to positive indices;\n** other arguments (before the script name) go to negative indices.\n** If there is no script name, assume interpreter's name as base.\n*/\nstatic void createargtable (lua_State *L, char **argv, int argc, int script) {\n  int i, narg;\n  if (script == argc) script = 0;  /* no script name? */\n  narg = argc - (script + 1);  /* number of positive indices */\n  lua_createtable(L, narg, script + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - script);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\n\nstatic int dochunk (lua_State *L, int status) {\n  if (status == LUA_OK) status = docall(L, 0, 0);\n  return report(L, status);\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  return dochunk(L, luaL_loadfile(L, name));\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));\n}\n\n\n/*\n** Calls 'require(name)' and stores the result in a global variable\n** with the given name.\n*/\nstatic int dolibrary (lua_State *L, const char *name) {\n  int status;\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  status = docall(L, 1, 1);  /* call 'require(name)' */\n  if (status == LUA_OK)\n    lua_setglobal(L, name);  /* global[name] = require return */\n  return report(L, status);\n}\n\n\n/*\n** Push on the stack the contents of table 'arg' from 1 to #arg\n*/\nstatic int pushargs (lua_State *L) {\n  int i, n;\n  if (lua_getglobal(L, \"arg\") != LUA_TTABLE)\n    luaL_error(L, \"'arg' is not a table\");\n  n = (int)luaL_len(L, -1);\n  luaL_checkstack(L, n + 3, \"too many arguments to script\");\n  for (i = 1; i <= n; i++)\n    lua_rawgeti(L, -i, i);\n  lua_remove(L, -i);  /* remove table from the stack */\n  return n;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv) {\n  int status;\n  const char *fname = argv[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    int n = pushargs(L);  /* push arguments to script */\n    status = docall(L, n, LUA_MULTRET);\n  }\n  return report(L, status);\n}\n\n\n/* bits of various argument indicators in 'args' */\n#define has_error\t1\t/* bad option */\n#define has_i\t\t2\t/* -i */\n#define has_v\t\t4\t/* -v */\n#define has_e\t\t8\t/* -e */\n#define has_E\t\t16\t/* -E */\n\n\n/*\n** Traverses all arguments from 'argv', returning a mask with those\n** needed before running any Lua code (or an error code if it finds\n** any invalid argument). 'first' returns the first not-handled argument\n** (either the script name or a bad argument in case of error).\n*/\nstatic int collectargs (char **argv, int *first) {\n  int args = 0;\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    *first = i;\n    if (argv[i][0] != '-')  /* not an option? */\n        return args;  /* stop handling options */\n    switch (argv[i][1]) {  /* else check option */\n      case '-':  /* '--' */\n        if (argv[i][2] != '\\0')  /* extra characters after '--'? */\n          return has_error;  /* invalid option */\n        *first = i + 1;\n        return args;\n      case '\\0':  /* '-' */\n        return args;  /* script \"name\" is '-' */\n      case 'E':\n        if (argv[i][2] != '\\0')  /* extra characters? */\n          return has_error;  /* invalid option */\n        args |= has_E;\n        break;\n      case 'W':\n        if (argv[i][2] != '\\0')  /* extra characters? */\n          return has_error;  /* invalid option */\n        break;\n      case 'i':\n        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */\n      case 'v':\n        if (argv[i][2] != '\\0')  /* extra characters? */\n          return has_error;  /* invalid option */\n        args |= has_v;\n        break;\n      case 'e':\n        args |= has_e;  /* FALLTHROUGH */\n      case 'l':  /* both options need an argument */\n        if (argv[i][2] == '\\0') {  /* no concatenated argument? */\n          i++;  /* try next 'argv' */\n          if (argv[i] == NULL || argv[i][0] == '-')\n            return has_error;  /* no next argument or it is another option */\n        }\n        break;\n      default:  /* invalid option */\n        return has_error;\n    }\n  }\n  *first = i;  /* no script name */\n  return args;\n}\n\n\n/*\n** Processes options 'e' and 'l', which involve running Lua code, and\n** 'W', which also affects the state.\n** Returns 0 if some code raises an error.\n*/\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    int option = argv[i][1];\n    lua_assert(argv[i][0] == '-');  /* already checked */\n    switch (option) {\n      case 'e':  case 'l': {\n        int status;\n        const char *extra = argv[i] + 2;  /* both options need an argument */\n        if (*extra == '\\0') extra = argv[++i];\n        lua_assert(extra != NULL);\n        status = (option == 'e')\n                 ? dostring(L, extra, \"=(command line)\")\n                 : dolibrary(L, extra);\n        if (status != LUA_OK) return 0;\n        break;\n      }\n      case 'W':\n        lua_warning(L, \"@on\", 0);  /* warnings on */\n        break;\n    }\n  }\n  return 1;\n}\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *name = \"=\" LUA_INITVARVERSION;\n  const char *init = getenv(name + 1);\n  if (init == NULL) {\n    name = \"=\" LUA_INIT_VAR;\n    init = getenv(name + 1);  /* try alternative name */\n  }\n  if (init == NULL) return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, name);\n}\n\n\n/*\n** {==================================================================\n** Read-Eval-Print Loop (REPL)\n** ===================================================================\n*/\n\n#if !defined(LUA_PROMPT)\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n#endif\n\n#if !defined(LUA_MAXINPUT)\n#define LUA_MAXINPUT\t\t512\n#endif\n\n\n/*\n** lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n** is, whether we're running lua interactively).\n*/\n#if !defined(lua_stdin_is_tty)\t/* { */\n\n#if defined(LUA_USE_POSIX)\t/* { */\n\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n\n#elif defined(LUA_USE_WINDOWS)\t/* }{ */\n\n#include <io.h>\n#include <windows.h>\n\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n\n#else\t\t\t\t/* }{ */\n\n/* ISO C definition */\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** lua_readline defines how to show a prompt and then read a line from\n** the standard input.\n** lua_saveline defines how to \"save\" a read line in a \"history\".\n** lua_freeline defines how to free a line read by lua_readline.\n*/\n#if !defined(lua_readline)\t/* { */\n\n#if defined(LUA_USE_READLINE)\t/* { */\n\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_initreadline(L)\t((void)L, rl_readline_name=\"lua\")\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,line)\t((void)L, add_history(line))\n#define lua_freeline(L,b)\t((void)L, free(b))\n\n#else\t\t\t\t/* }{ */\n\n#define lua_initreadline(L)  ((void)L)\n#define lua_readline(L,b,p) \\\n        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,line)\t{ (void)L; (void)line; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n\n#endif\t\t\t\t/* } */\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** Returns the string to be used as a prompt by the interpreter.\n*/\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getglobal(L, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  return p;\n}\n\n/* mark in error messages for incomplete statements */\n#define EOFMARK\t\t\"<eof>\"\n#define marklen\t\t(sizeof(EOFMARK)/sizeof(char) - 1)\n\n\n/*\n** Check whether 'status' signals a syntax error and the error\n** message at the top of the stack ends with the above mark for\n** incomplete statements.\n*/\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\n/*\n** Prompt the user, read a line, and push it into the Lua stack.\n*/\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  int readstatus = lua_readline(L, b, prmt);\n  if (readstatus == 0)\n    return 0;  /* no input (prompt will be popped by caller) */\n  lua_pop(L, 1);  /* remove prompt */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[--l] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */\n    lua_pushfstring(L, \"return %s\", b + 1);  /* change '=' to 'return' */\n  else\n    lua_pushlstring(L, b, l);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\n/*\n** Try to compile line on the stack as 'return <line>;'; on return, stack\n** has either compiled chunk or original line (if compilation failed).\n*/\nstatic int addreturn (lua_State *L) {\n  const char *line = lua_tostring(L, -1);  /* original line */\n  const char *retline = lua_pushfstring(L, \"return %s;\", line);\n  int status = luaL_loadbuffer(L, retline, strlen(retline), \"=stdin\");\n  if (status == LUA_OK) {\n    lua_remove(L, -2);  /* remove modified line */\n    if (line[0] != '\\0')  /* non empty? */\n      lua_saveline(L, line);  /* keep history */\n  }\n  else\n    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */\n  return status;\n}\n\n\n/*\n** Read multiple lines until a complete Lua statement\n*/\nstatic int multiline (lua_State *L) {\n  for (;;) {  /* repeat until gets a complete statement */\n    size_t len;\n    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */\n    int status = luaL_loadbuffer(L, line, len, \"=stdin\");  /* try it */\n    if (!incomplete(L, status) || !pushline(L, 0)) {\n      lua_saveline(L, line);  /* keep history */\n      return status;  /* cannot or should not try to add continuation line */\n    }\n    lua_pushliteral(L, \"\\n\");  /* add newline... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n}\n\n\n/*\n** Read a line and try to load (compile) it first as an expression (by\n** adding \"return \" in front of it) and second as a statement. Return\n** the final status of load/call with the resulting function (if any)\n** in the top of the stack.\n*/\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */\n    status = multiline(L);  /* try as command, maybe with continuation lines */\n  lua_remove(L, 1);  /* remove line from the stack */\n  lua_assert(lua_gettop(L) == 1);\n  return status;\n}\n\n\n/*\n** Prints (calling the Lua 'print' function) any values on the stack\n*/\nstatic void l_print (lua_State *L) {\n  int n = lua_gettop(L);\n  if (n > 0) {  /* any result to be printed? */\n    luaL_checkstack(L, LUA_MINSTACK, \"too many results to print\");\n    lua_getglobal(L, \"print\");\n    lua_insert(L, 1);\n    if (lua_pcall(L, n, 0, 0) != LUA_OK)\n      l_message(progname, lua_pushfstring(L, \"error calling 'print' (%s)\",\n                                             lua_tostring(L, -1)));\n  }\n}\n\n\n/*\n** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and\n** print any results.\n*/\nstatic void doREPL (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;  /* no 'progname' on errors in interactive mode */\n  lua_initreadline(L);\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK)\n      status = docall(L, 0, LUA_MULTRET);\n    if (status == LUA_OK) l_print(L);\n    else report(L, status);\n  }\n  lua_settop(L, 0);  /* clear stack */\n  lua_writeline();\n  progname = oldprogname;\n}\n\n/* }================================================================== */\n\n\n/*\n** Main body of stand-alone interpreter (to be called in protected mode).\n** Reads the options and handles them all.\n*/\nstatic int pmain (lua_State *L) {\n  int argc = (int)lua_tointeger(L, 1);\n  char **argv = (char **)lua_touserdata(L, 2);\n  int script;\n  int args = collectargs(argv, &script);\n  luaL_checkversion(L);  /* check that interpreter has correct version */\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  if (args == has_error) {  /* bad arg? */\n    print_usage(argv[script]);  /* 'script' has index of bad arg. */\n    return 0;\n  }\n  if (args & has_v)  /* option '-v'? */\n    print_version();\n  if (args & has_E) {  /* option '-E'? */\n    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  luaL_openlibs(L);  /* open standard libraries */\n  createargtable(L, argv, argc, script);  /* create table 'arg' */\n  lua_gc(L, LUA_GCGEN, 0, 0);  /* GC in generational mode */\n  if (!(args & has_E)) {  /* no option '-E'? */\n    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */\n      return 0;  /* error running LUA_INIT */\n  }\n  if (!runargs(L, argv, script))  /* execute arguments -e and -l */\n    return 0;  /* something failed */\n  if (script < argc &&  /* execute main script (if there is one) */\n      handle_script(L, argv + script) != LUA_OK)\n    return 0;\n  if (args & has_i)  /* -i option? */\n    doREPL(L);  /* do read-eval-print loop */\n  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */\n    if (lua_stdin_is_tty()) {  /* running in interactive mode? */\n      print_version();\n      doREPL(L);  /* do read-eval-print loop */\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  lua_pushboolean(L, 1);  /* signal no errors */\n  return 1;\n}\n\n\nint main (int argc, char **argv) {\n  int status, result;\n  lua_State *L = luaL_newstate();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */\n  lua_pushinteger(L, argc);  /* 1st argument */\n  lua_pushlightuserdata(L, argv); /* 2nd argument */\n  status = lua_pcall(L, 2, 1, 0);  /* do the call */\n  result = lua_toboolean(L, -1);  /* get result */\n  report(L, status);\n  lua_close(L);\n  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lua.h",
    "content": "/*\n** $Id: lua.h $\n** Lua - A Scripting Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION_MAJOR\t\"5\"\n#define LUA_VERSION_MINOR\t\"4\"\n#define LUA_VERSION_RELEASE\t\"1\"\n\n#define LUA_VERSION_NUM\t\t\t504\n#define LUA_VERSION_RELEASE_NUM\t\t(LUA_VERSION_NUM * 100 + 0)\n\n#define LUA_VERSION\t\"Lua \" LUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#define LUA_RELEASE\tLUA_VERSION \".\" LUA_VERSION_RELEASE\n#define LUA_COPYRIGHT\tLUA_RELEASE \"  Copyright (C) 1994-2020 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo, W. Celes\"\n\n\n/* mark for precompiled code ('<esc>Lua') */\n#define LUA_SIGNATURE\t\"\\x1bLua\"\n\n/* option for multiple returns in 'lua_pcall' and 'lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** Pseudo-indices\n** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty\n** space after that to help overflow detection)\n*/\n#define LUA_REGISTRYINDEX\t(-LUAI_MAXSTACK - 1000)\n#define lua_upvalueindex(i)\t(LUA_REGISTRYINDEX - (i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n#define LUA_NUMTYPES\t\t9\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/* predefined values in the registry */\n#define LUA_RIDX_MAINTHREAD\t1\n#define LUA_RIDX_GLOBALS\t2\n#define LUA_RIDX_LAST\t\tLUA_RIDX_GLOBALS\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n/* unsigned integer type */\ntypedef LUA_UNSIGNED lua_Unsigned;\n\n/* type for continuation-function contexts */\ntypedef LUA_KCONTEXT lua_KContext;\n\n\n/*\n** Type for C functions registered with Lua\n*/\ntypedef int (*lua_CFunction) (lua_State *L);\n\n/*\n** Type for continuation functions\n*/\ntypedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);\n\n\n/*\n** Type for functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);\n\n\n/*\n** Type for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** Type for warning functions\n*/\ntypedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);\n\n\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/*\n** RCS ident string\n*/\nextern const char lua_ident[];\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\nLUA_API int        (lua_resetthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\nLUA_API lua_Number (lua_version) (lua_State *L);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_absindex) (lua_State *L, int idx);\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_rotate) (lua_State *L, int idx, int n);\nLUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);\nLUA_API int   (lua_checkstack) (lua_State *L, int n);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isinteger) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API lua_Unsigned    (lua_rawlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** Comparison and arithmetic functions\n*/\n\n#define LUA_OPADD\t0\t/* ORDER TM, ORDER OP */\n#define LUA_OPSUB\t1\n#define LUA_OPMUL\t2\n#define LUA_OPMOD\t3\n#define LUA_OPPOW\t4\n#define LUA_OPDIV\t5\n#define LUA_OPIDIV\t6\n#define LUA_OPBAND\t7\n#define LUA_OPBOR\t8\n#define LUA_OPBXOR\t9\n#define LUA_OPSHL\t10\n#define LUA_OPSHR\t11\n#define LUA_OPUNM\t12\n#define LUA_OPBNOT\t13\n\nLUA_API void  (lua_arith) (lua_State *L, int op);\n\n#define LUA_OPEQ\t0\n#define LUA_OPLT\t1\n#define LUA_OPLE\t2\n\nLUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void        (lua_pushnil) (lua_State *L);\nLUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);\nLUA_API const char *(lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API int (lua_getglobal) (lua_State *L, const char *name);\nLUA_API int (lua_gettable) (lua_State *L, int idx);\nLUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawget) (lua_State *L, int idx);\nLUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);\nLUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);\n\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API int  (lua_getiuservalue) (lua_State *L, int idx, int n);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_setglobal) (lua_State *L, const char *name);\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_seti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, lua_Integer n);\nLUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setiuservalue) (lua_State *L, int idx, int n);\n\n\n/*\n** 'load' and 'call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults,\n                           lua_KContext ctx, lua_KFunction k);\n#define lua_call(L,n,r)\t\tlua_callk(L, (n), (r), 0, NULL)\n\nLUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,\n                            lua_KContext ctx, lua_KFunction k);\n#define lua_pcall(L,n,r,f)\tlua_pcallk(L, (n), (r), (f), 0, NULL)\n\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                          const char *chunkname, const char *mode);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yieldk)     (lua_State *L, int nresults, lua_KContext ctx,\n                               lua_KFunction k);\nLUA_API int  (lua_resume)     (lua_State *L, lua_State *from, int narg,\n                               int *nres);\nLUA_API int  (lua_status)     (lua_State *L);\nLUA_API int (lua_isyieldable) (lua_State *L);\n\n#define lua_yield(L,n)\t\tlua_yieldk(L, (n), 0, NULL)\n\n\n/*\n** Warning-related functions\n*/\nLUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);\nLUA_API void (lua_warning)  (lua_State *L, const char *msg, int tocont);\n\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n#define LUA_GCGEN\t\t10\n#define LUA_GCINC\t\t11\n\nLUA_API int (lua_gc) (lua_State *L, int what, ...);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\nLUA_API void  (lua_len)    (lua_State *L, int idx);\n\nLUA_API size_t   (lua_stringtonumber) (lua_State *L, const char *s);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);\n\nLUA_API void  (lua_toclose) (lua_State *L, int idx);\n\n\n/*\n** {==============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_getextraspace(L)\t((void *)((char *)(L) - LUA_EXTRASPACE))\n\n#define lua_tonumber(L,i)\tlua_tonumberx(L,(i),NULL)\n#define lua_tointeger(L,i)\tlua_tointegerx(L,(i),NULL)\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\tlua_pushstring(L, \"\" s)\n\n#define lua_pushglobaltable(L)  \\\n\t((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n#define lua_insert(L,idx)\tlua_rotate(L, (idx), 1)\n\n#define lua_remove(L,idx)\t(lua_rotate(L, (idx), -1), lua_pop(L, 1))\n\n#define lua_replace(L,idx)\t(lua_copy(L, -1, (idx)), lua_pop(L, 1))\n\n/* }============================================================== */\n\n\n/*\n** {==============================================================\n** compatibility macros\n** ===============================================================\n*/\n#if defined(LUA_COMPAT_APIINTCASTS)\n\n#define lua_pushunsigned(L,n)\tlua_pushinteger(L, (lua_Integer)(n))\n#define lua_tounsignedx(L,i,is)\t((lua_Unsigned)lua_tointegerx(L,i,is))\n#define lua_tounsigned(L,i)\tlua_tounsignedx(L,(i),NULL)\n\n#endif\n\n#define lua_newuserdata(L,s)\tlua_newuserdatauv(L,s,1)\n#define lua_getuservalue(L,idx)\tlua_getiuservalue(L,idx,1)\n#define lua_setuservalue(L,idx)\tlua_setiuservalue(L,idx,1)\n\n#define LUA_NUMTAGS\t\tLUA_NUMTYPES\n\n/* }============================================================== */\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILCALL 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debugger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);\nLUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);\nLUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);\n\nLUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);\nLUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,\n                                               int fidx2, int n2);\n\nLUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook (lua_gethook) (lua_State *L);\nLUA_API int (lua_gethookmask) (lua_State *L);\nLUA_API int (lua_gethookcount) (lua_State *L);\n\nLUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) 'global', 'local', 'field', 'method' */\n  const char *what;\t/* (S) 'Lua', 'C', 'main', 'tail' */\n  const char *source;\t/* (S) */\n  size_t srclen;\t/* (S) */\n  int currentline;\t/* (l) */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  unsigned char nups;\t/* (u) number of upvalues */\n  unsigned char nparams;/* (u) number of parameters */\n  char isvararg;        /* (u) */\n  char istailcall;\t/* (t) */\n  unsigned short ftransfer;   /* (r) index of first value transferred */\n  unsigned short ntransfer;   /* (r) number of transferred values */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  struct CallInfo *i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2020 Lua.org, PUC-Rio.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "build/lua-5.4.1/src/luac.c",
    "content": "/*\n** $Id: luac.c $\n** Lua compiler (saves bytecodes to files; also lists bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lopnames.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\nstatic void PrintFunction(const Proto* f, int full);\n#define luaU_print\tPrintFunction\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define OUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\nstatic TString **tmname;\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option '%s'\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n  \"usage: %s [options] [filenames]\\n\"\n  \"Available options are:\\n\"\n  \"  -l       list (use -l -l for full listing)\\n\"\n  \"  -o name  output to file 'name' (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        stop handling options and process stdin\\n\"\n  ,progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define IS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))\n    usage(\"'-o' needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s\\n\",LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define FUNCTION \"(function()end)();\"\n\nstatic const char* reader(lua_State* L, void* ud, size_t* size)\n{\n UNUSED(L);\n if ((*(int*)ud)--)\n {\n  *size=sizeof(FUNCTION)-1;\n  return FUNCTION;\n }\n else\n {\n  *size=0;\n  return NULL;\n }\n}\n\n#define toproto(L,i) getproto(s2v(L->top+(i)))\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  Proto* f;\n  int i=n;\n  if (lua_load(L,reader,&i,\"=(\" PROGNAME \")\",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));\n  f=toproto(L,-1);\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;\n  }\n  f->sizelineinfo=0;\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstatic int pmain(lua_State* L)\n{\n int argc=(int)lua_tointeger(L,1);\n char** argv=(char**)lua_touserdata(L,2);\n const Proto* f;\n int i;\n tmname=G(L)->tmname;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=luaL_newstate();\n if (L==NULL) fatal(\"cannot create state: not enough memory\");\n lua_pushcfunction(L,&pmain);\n lua_pushinteger(L,argc);\n lua_pushlightuserdata(L,argv);\n if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n\n/*\n** print bytecodes\n*/\n\n#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : \"-\")\n#define VOID(p) ((const void*)(p))\n#define eventname(i) (getstr(tmname[i]))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=tsslen(ts);\n printf(\"\\\"\");\n for (i=0; i<n; i++)\n {\n  int c=(int)(unsigned char)s[i];\n  switch (c)\n  {\n   case '\"':\n\tprintf(\"\\\\\\\"\");\n\tbreak;\n   case '\\\\':\n\tprintf(\"\\\\\\\\\");\n\tbreak;\n   case '\\a':\n\tprintf(\"\\\\a\");\n\tbreak;\n   case '\\b':\n\tprintf(\"\\\\b\");\n\tbreak;\n   case '\\f':\n\tprintf(\"\\\\f\");\n\tbreak;\n   case '\\n':\n\tprintf(\"\\\\n\");\n\tbreak;\n   case '\\r':\n\tprintf(\"\\\\r\");\n\tbreak;\n   case '\\t':\n\tprintf(\"\\\\t\");\n\tbreak;\n   case '\\v':\n\tprintf(\"\\\\v\");\n\tbreak;\n   default:\n\tif (isprint(c)) printf(\"%c\",c); else printf(\"\\\\%03d\",c);\n\tbreak;\n  }\n }\n printf(\"\\\"\");\n}\n\nstatic void PrintType(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttypetag(o))\n {\n  case LUA_VNIL:\n\tprintf(\"N\");\n\tbreak;\n  case LUA_VFALSE:\n  case LUA_VTRUE:\n\tprintf(\"B\");\n\tbreak;\n  case LUA_VNUMFLT:\n\tprintf(\"F\");\n\tbreak;\n  case LUA_VNUMINT:\n\tprintf(\"I\");\n\tbreak;\n  case LUA_VSHRSTR:\n  case LUA_VLNGSTR:\n\tprintf(\"S\");\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"?%d\",ttypetag(o));\n\tbreak;\n }\n printf(\"\\t\");\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttypetag(o))\n {\n  case LUA_VNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_VFALSE:\n\tprintf(\"false\");\n\tbreak;\n  case LUA_VTRUE:\n\tprintf(\"true\");\n\tbreak;\n  case LUA_VNUMFLT:\n\t{\n\tchar buff[100];\n\tsprintf(buff,LUA_NUMBER_FMT,fltvalue(o));\n\tprintf(\"%s\",buff);\n\tif (buff[strspn(buff,\"-0123456789\")]=='\\0') printf(\".0\");\n\tbreak;\n\t}\n  case LUA_VNUMINT:\n\tprintf(LUA_INTEGER_FMT,ivalue(o));\n\tbreak;\n  case LUA_VSHRSTR:\n  case LUA_VLNGSTR:\n\tPrintString(tsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"?%d\",ttypetag(o));\n\tbreak;\n }\n}\n\n#define COMMENT\t\t\"\\t; \"\n#define EXTRAARG\tGETARG_Ax(code[pc+1])\n#define EXTRAARGC\t(EXTRAARG*(MAXARG_C+1))\n#define ISK\t\t(isk ? \"k\" : \"\")\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int ax=GETARG_Ax(i);\n  int bx=GETARG_Bx(i);\n  int sb=GETARG_sB(i);\n  int sc=GETARG_sC(i);\n  int sbx=GETARG_sBx(i);\n  int isk=GETARG_k(i);\n  int line=luaG_getfuncline(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",opnames[o]);\n  switch (o)\n  {\n   case OP_MOVE:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_LOADI:\n\tprintf(\"%d %d\",a,sbx);\n\tbreak;\n   case OP_LOADF:\n\tprintf(\"%d %d\",a,sbx);\n\tbreak;\n   case OP_LOADK:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT); PrintConstant(f,bx);\n\tbreak;\n   case OP_LOADKX:\n\tprintf(\"%d\",a);\n\tprintf(COMMENT); PrintConstant(f,EXTRAARG);\n\tbreak;\n   case OP_LOADFALSE:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_LFALSESKIP:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_LOADTRUE:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_LOADNIL:\n\tprintf(\"%d %d\",a,b);\n\tprintf(COMMENT \"%d out\",b+1);\n\tbreak;\n   case OP_GETUPVAL:\n\tprintf(\"%d %d\",a,b);\n\tprintf(COMMENT \"%s\",UPVALNAME(b));\n\tbreak;\n   case OP_SETUPVAL:\n\tprintf(\"%d %d\",a,b);\n\tprintf(COMMENT \"%s\",UPVALNAME(b));\n\tbreak;\n   case OP_GETTABUP:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT \"%s\",UPVALNAME(b));\n\tprintf(\" \"); PrintConstant(f,c);\n\tbreak;\n   case OP_GETTABLE:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_GETI:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_GETFIELD:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_SETTABUP:\n\tprintf(\"%d %d %d%s\",a,b,c,ISK);\n\tprintf(COMMENT \"%s\",UPVALNAME(a));\n\tprintf(\" \"); PrintConstant(f,b);\n\tif (isk) { printf(\" \"); PrintConstant(f,c); }\n\tbreak;\n   case OP_SETTABLE:\n\tprintf(\"%d %d %d%s\",a,b,c,ISK);\n\tif (isk) { printf(COMMENT); PrintConstant(f,c); }\n\tbreak;\n   case OP_SETI:\n\tprintf(\"%d %d %d%s\",a,b,c,ISK);\n\tif (isk) { printf(COMMENT); PrintConstant(f,c); }\n\tbreak;\n   case OP_SETFIELD:\n\tprintf(\"%d %d %d%s\",a,b,c,ISK);\n\tprintf(COMMENT); PrintConstant(f,b);\n\tif (isk) { printf(\" \"); PrintConstant(f,c); }\n\tbreak;\n   case OP_NEWTABLE:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT \"%d\",c+EXTRAARGC);\n\tbreak;\n   case OP_SELF:\n\tprintf(\"%d %d %d%s\",a,b,c,ISK);\n\tif (isk) { printf(COMMENT); PrintConstant(f,c); }\n\tbreak;\n   case OP_ADDI:\n\tprintf(\"%d %d %d\",a,b,sc);\n\tbreak;\n   case OP_ADDK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_SUBK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_MULK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_MODK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_POWK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_DIVK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_IDIVK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_BANDK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_BORK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_BXORK:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT); PrintConstant(f,c);\n\tbreak;\n   case OP_SHRI:\n\tprintf(\"%d %d %d\",a,b,sc);\n\tbreak;\n   case OP_SHLI:\n\tprintf(\"%d %d %d\",a,b,sc);\n\tbreak;\n   case OP_ADD:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_SUB:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_MUL:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_MOD:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_POW:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_DIV:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_IDIV:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_BAND:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_BOR:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_BXOR:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_SHL:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_SHR:\n\tprintf(\"%d %d %d\",a,b,c);\n\tbreak;\n   case OP_MMBIN:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT \"%s\",eventname(c));\n\tbreak;\n   case OP_MMBINI:\n\tprintf(\"%d %d %d %d\",a,sb,c,isk);\n\tprintf(COMMENT \"%s\",eventname(c));\n\tif (isk) printf(\" flip\");\n\tbreak;\n   case OP_MMBINK:\n\tprintf(\"%d %d %d %d\",a,b,c,isk);\n\tprintf(COMMENT \"%s \",eventname(c)); PrintConstant(f,b);\n\tif (isk) printf(\" flip\");\n\tbreak;\n   case OP_UNM:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_BNOT:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_NOT:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_LEN:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_CONCAT:\n\tprintf(\"%d %d\",a,b);\n\tbreak;\n   case OP_CLOSE:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_TBC:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_JMP:\n\tprintf(\"%d\",GETARG_sJ(i));\n\tprintf(COMMENT \"to %d\",GETARG_sJ(i)+pc+2);\n\tbreak;\n   case OP_EQ:\n\tprintf(\"%d %d %d\",a,b,isk);\n\tbreak;\n   case OP_LT:\n\tprintf(\"%d %d %d\",a,b,isk);\n\tbreak;\n   case OP_LE:\n\tprintf(\"%d %d %d\",a,b,isk);\n\tbreak;\n   case OP_EQK:\n\tprintf(\"%d %d %d\",a,b,isk);\n\tprintf(COMMENT); PrintConstant(f,b);\n\tbreak;\n   case OP_EQI:\n\tprintf(\"%d %d %d\",a,sb,isk);\n\tbreak;\n   case OP_LTI:\n\tprintf(\"%d %d %d\",a,sb,isk);\n\tbreak;\n   case OP_LEI:\n\tprintf(\"%d %d %d\",a,sb,isk);\n\tbreak;\n   case OP_GTI:\n\tprintf(\"%d %d %d\",a,sb,isk);\n\tbreak;\n   case OP_GEI:\n\tprintf(\"%d %d %d\",a,sb,isk);\n\tbreak;\n   case OP_TEST:\n\tprintf(\"%d %d\",a,isk);\n\tbreak;\n   case OP_TESTSET:\n\tprintf(\"%d %d %d\",a,b,isk);\n\tbreak;\n   case OP_CALL:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT);\n\tif (b==0) printf(\"all in \"); else printf(\"%d in \",b-1);\n\tif (c==0) printf(\"all out\"); else printf(\"%d out\",c-1);\n\tbreak;\n   case OP_TAILCALL:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT \"%d in\",b-1);\n\tbreak;\n   case OP_RETURN:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT);\n\tif (b==0) printf(\"all out\"); else printf(\"%d out\",b-1);\n\tbreak;\n   case OP_RETURN0:\n\tbreak;\n   case OP_RETURN1:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_FORLOOP:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT \"to %d\",pc-bx+2);\n\tbreak;\n   case OP_FORPREP:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT \"to %d\",pc+bx+2);\n\tbreak;\n   case OP_TFORPREP:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT \"to %d\",pc+bx+2);\n\tbreak;\n   case OP_TFORCALL:\n\tprintf(\"%d %d\",a,c);\n\tbreak;\n   case OP_TFORLOOP:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT \"to %d\",pc-bx+2);\n\tbreak;\n   case OP_SETLIST:\n\tprintf(\"%d %d %d\",a,b,c);\n\tif (isk) printf(COMMENT \"%d\",c+EXTRAARGC);\n\tbreak;\n   case OP_CLOSURE:\n\tprintf(\"%d %d\",a,bx);\n\tprintf(COMMENT \"%p\",VOID(f->p[bx]));\n\tbreak;\n   case OP_VARARG:\n\tprintf(\"%d %d\",a,c);\n\tprintf(COMMENT);\n\tif (c==0) printf(\"all out\"); else printf(\"%d out\",c-1);\n\tbreak;\n   case OP_VARARGPREP:\n\tprintf(\"%d\",a);\n\tbreak;\n   case OP_EXTRAARG:\n\tprintf(\"%d\",ax);\n\tbreak;\n#if 0\n   default:\n\tprintf(\"%d %d %d\",a,b,c);\n\tprintf(COMMENT \"not handled\");\n\tbreak;\n#endif\n  }\n  printf(\"\\n\");\n }\n}\n\n\n#define SS(x)\t((x==1)?\"\":\"s\")\n#define S(x)\t(int)(x),SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=f->source ? getstr(f->source) : \"=?\";\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s at %p)\\n\",\n\t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\t(int)(f->numparams),f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->sizeupvalues));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintDebug(const Proto* f)\n{\n int i,n;\n n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i);\n  PrintType(f,i);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);\n }\n}\n\nstatic void PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full) PrintDebug(f);\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "build/lua-5.4.1/src/luaconf.h.in",
    "content": "/*\n** $Id: luaconf.h $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ===================================================================\n** General Configuration File for Lua\n**\n** Some definitions here can be changed externally, through the\n** compiler (e.g., with '-D' options). Those are protected by\n** '#if !defined' guards. However, several other definitions should\n** be changed directly here, either because they affect the Lua\n** ABI (by making the changes here, you ensure that all software\n** connected to Lua, such as C libraries, will be compiled with the\n** same configuration); or because they are seldom changed.\n**\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n** {====================================================================\n** System Configuration: macros to adapt (if needed) Lua to some\n** particular platform, for instance restricting it to C89.\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXCSTACK defines the maximum depth for nested calls and\n** also limits the maximum depth of other recursive algorithms in\n** the implementation, such as syntactic analysis. A value too\n** large may allow the interpreter to crash (C-stack overflow).\n** The default value seems ok for regular machines, but may be\n** too high for restricted hardware.\n** The test file 'cstack.lua' may help finding a good limit.\n** (It will crash with a limit too high.)\n*/\n#if !defined(LUAI_MAXCSTACK)\n#define LUAI_MAXCSTACK\t\t2000\n#endif\n\n\n/*\n@@ LUA_USE_C89 controls the use of non-ISO-C89 features.\n** Define it if you want Lua to avoid the use of a few C99 features\n** or Windows-specific features on Windows.\n*/\n/* #define LUA_USE_C89 */\n\n\n/*\n** By default, Lua on Windows use (some) specific Windows features\n*/\n#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)\n#define LUA_USE_WINDOWS  /* enable goodies for regular Windows */\n#endif\n\n\n#if defined(LUA_USE_WINDOWS)\n#if !defined(WINAPI_FAMILY_PARTITION)\n#define LUA_DL_DLL\t/* enable support for DLL */\n#endif\n#define LUA_USE_C89\t/* broadly, Windows is C89 */\n#endif\n\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#endif\n\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* MacOS does not need -ldl */\n#endif\n\n\n/*\n@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.\n*/\n#define LUAI_IS32INT\t((UINT_MAX >> 30) >= 3)\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Number types.\n** ===================================================================\n*/\n\n/*\n@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.\n*/\n/* #define LUA_32BITS */\n\n\n/*\n@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for\n** C89 ('long' and 'double'); Windows always has '__int64', so it does\n** not need to use this case.\n*/\n#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)\n#define LUA_C89_NUMBERS\n#endif\n\n\n/*\n@@ LUA_INT_TYPE defines the type for Lua integers.\n@@ LUA_FLOAT_TYPE defines the type for Lua floats.\n** Lua should work fine with any mix of these options supported\n** by your C compiler. The usual configurations are 64-bit integers\n** and 'double' (the default), 32-bit integers and 'float' (for\n** restricted platforms), and 'long'/'double' (for C compilers not\n** compliant with C99, which may not have support for 'long long').\n*/\n\n/* predefined options for LUA_INT_TYPE */\n#define LUA_INT_INT\t\t1\n#define LUA_INT_LONG\t\t2\n#define LUA_INT_LONGLONG\t3\n\n/* predefined options for LUA_FLOAT_TYPE */\n#define LUA_FLOAT_FLOAT\t\t1\n#define LUA_FLOAT_DOUBLE\t2\n#define LUA_FLOAT_LONGDOUBLE\t3\n\n#if defined(LUA_32BITS)\t\t/* { */\n/*\n** 32-bit integers and 'float'\n*/\n#if LUAI_IS32INT  /* use 'int' if big enough */\n#define LUA_INT_TYPE\tLUA_INT_INT\n#else  /* otherwise use 'long' */\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#endif\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT\n\n#elif defined(LUA_C89_NUMBERS)\t/* }{ */\n/*\n** largest types available for C89 ('long' and 'double')\n*/\n#define LUA_INT_TYPE\tLUA_INT_LONG\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** default configuration for 64-bit Lua ('long long' and 'double')\n*/\n#if !defined(LUA_INT_TYPE)\n#define LUA_INT_TYPE\tLUA_INT_LONGLONG\n#endif\n\n#if !defined(LUA_FLOAT_TYPE)\n#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE\n#endif\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Paths.\n** ===================================================================\n*/\n\n/*\n** LUA_PATH_SEP is the character that separates templates in a path.\n** LUA_PATH_MARK is the string that marks the substitution points in a\n** template.\n** LUA_EXEC_DIR in a Windows path is replaced by the executable's\n** directory.\n*/\n#define LUA_PATH_SEP            \";\"\n#define LUA_PATH_MARK           \"?\"\n#define LUA_EXEC_DIR            \"!\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n** Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n** C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n\n#define LUA_VDIR\tLUA_VERSION_MAJOR \".\" LUA_VERSION_MINOR\n#if defined(_WIN32)\t/* { */\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_SHRDIR\t\"!\\\\..\\\\share\\\\lua\\\\\" LUA_VDIR \"\\\\\"\n\n#if !defined(LUA_PATH_DEFAULT)\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua;\" \\\n\t\tLUA_SHRDIR\"?.lua;\" LUA_SHRDIR\"?\\\\init.lua;\" \\\n\t\t\".\\\\?.lua;\" \".\\\\?\\\\init.lua\"\n#endif\n\n#if !defined(LUA_CPATH_DEFAULT)\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.dll;\" \\\n\t\tLUA_CDIR\"..\\\\lib\\\\lua\\\\\" LUA_VDIR \"\\\\?.dll;\" \\\n\t\tLUA_CDIR\"loadall.dll;\" \".\\\\?.dll\"\n#endif\n\n#else\t\t\t/* }{ */\n\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/\" LUA_VDIR \"/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/\" LUA_VDIR \"/\"\n\n#if !defined(LUA_PATH_DEFAULT)\n#define LUA_PATH_DEFAULT  \\\n\t\tLUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\tLUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua;\" \\\n\t\t\"./?.lua;\" \"./?/init.lua\"\n#endif\n\n#if !defined(LUA_CPATH_DEFAULT)\n#define LUA_CPATH_DEFAULT \\\n\t\tLUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so;\" \"./?.so\"\n#endif\n\n#endif\t\t\t/* } */\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if !defined(LUA_DIRSEP)\n\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Marks for exported symbols in the C code\n** ===================================================================\n*/\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all auxiliary library functions.\n@@ LUAMOD_API is a mark for all standard library opening functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\t/* { */\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\t/* { */\n#define LUA_API __declspec(dllexport)\n#else\t\t\t\t\t\t/* }{ */\n#define LUA_API __declspec(dllimport)\n#endif\t\t\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#define LUA_API\t\textern\n\n#endif\t\t\t\t/* } */\n\n\n/*\n** More often than not the libs go together with the core.\n*/\n#define LUALIB_API\tLUA_API\n#define LUAMOD_API\tLUA_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n** exported to outside modules.\n@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,\n** none of which to be exported to outside modules (LUAI_DDEF for\n** definitions and LUAI_DDEC for declarations).\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library. Not all elf targets support\n** this attribute. Unfortunately, gcc does not offer a way to check\n** whether the target offers that support, and those without support\n** give a warning about it. To avoid these warnings, change to the\n** default definition.\n*/\n#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n    defined(__ELF__)\t\t/* { */\n#define LUAI_FUNC\t__attribute__((visibility(\"internal\"))) extern\n#else\t\t\t\t/* }{ */\n#define LUAI_FUNC\textern\n#endif\t\t\t\t/* } */\n\n#define LUAI_DDEC(dec)\tLUAI_FUNC dec\n#define LUAI_DDEF\t/* empty */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Compatibility with previous versions\n** ===================================================================\n*/\n\n/*\n@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.\n** You can define it to get all options, or change specific options\n** to fit your specific needs.\n*/\n#if defined(LUA_COMPAT_5_3)\t/* { */\n\n/*\n@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated\n** functions in the mathematical library.\n** (These functions were already officially removed in 5.3;\n** nevertheless they are still available here.)\n*/\n#define LUA_COMPAT_MATHLIB\n\n/*\n@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for\n** manipulating other integer types (lua_pushunsigned, lua_tounsigned,\n** luaL_checkint, luaL_checklong, etc.)\n** (These macros were also officially removed in 5.3, but they are still\n** available here.)\n*/\n#define LUA_COMPAT_APIINTCASTS\n\n\n/*\n@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod\n** using '__lt'.\n*/\n#define LUA_COMPAT_LT_LE\n\n\n/*\n@@ The following macros supply trivial compatibility for some\n** changes in the API. The macros themselves document how to\n** change your code to avoid using them.\n** (Once more, these macros were officially removed in 5.3, but they are\n** still available here.)\n*/\n#define lua_strlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_objlen(L,i)\t\tlua_rawlen(L, (i))\n\n#define lua_equal(L,idx1,idx2)\t\tlua_compare(L,(idx1),(idx2),LUA_OPEQ)\n#define lua_lessthan(L,idx1,idx2)\tlua_compare(L,(idx1),(idx2),LUA_OPLT)\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n\n/*\n** {==================================================================\n** Configuration for Numbers.\n** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*\n** satisfy your needs.\n** ===================================================================\n*/\n\n/*\n@@ LUA_NUMBER is the floating-point type used by Lua.\n@@ LUAI_UACNUMBER is the result of a 'default argument promotion'\n@@ over a floating number.\n@@ l_floatatt(x) corrects float attribute 'x' to the proper float type\n** by prefixing it with one of FLT/DBL/LDBL.\n@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.\n@@ LUA_NUMBER_FMT is the format for writing floats.\n@@ lua_number2str converts a float to a string.\n@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.\n@@ l_floor takes the floor of a float.\n@@ lua_str2number converts a decimal numeral to a number.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define l_floor(x)\t\t(l_mathop(floor)(x))\n\n#define lua_number2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))\n\n/*\n@@ lua_numbertointeger converts a float number with an integral value\n** to an integer, or returns 0 if float is not within the range of\n** a lua_Integer.  (The range comparisons are tricky because of\n** rounding. The tests here assume a two-complement representation,\n** where MININTEGER always has an exact representation as a float;\n** MAXINTEGER may not have one, and therefore its conversion to float\n** may have an ill-defined value.)\n*/\n#define lua_numbertointeger(n,p) \\\n  ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \\\n   (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \\\n      (*(p) = (LUA_INTEGER)(n), 1))\n\n\n/* now the variable definitions */\n\n#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT\t\t/* { single float */\n\n#define LUA_NUMBER\tfloat\n\n#define l_floatatt(n)\t\t(FLT_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.7g\"\n\n#define l_mathop(op)\t\top##f\n\n#define lua_str2number(s,p)\tstrtof((s), (p))\n\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE\t/* }{ long double */\n\n#define LUA_NUMBER\tlong double\n\n#define l_floatatt(n)\t\t(LDBL_##n)\n\n#define LUAI_UACNUMBER\tlong double\n\n#define LUA_NUMBER_FRMLEN\t\"L\"\n#define LUA_NUMBER_FMT\t\t\"%.19Lg\"\n\n#define l_mathop(op)\t\top##l\n\n#define lua_str2number(s,p)\tstrtold((s), (p))\n\n#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE\t/* }{ double */\n\n#define LUA_NUMBER\tdouble\n\n#define l_floatatt(n)\t\t(DBL_##n)\n\n#define LUAI_UACNUMBER\tdouble\n\n#define LUA_NUMBER_FRMLEN\t\"\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n\n#define l_mathop(op)\t\top\n\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n#else\t\t\t\t\t\t/* }{ */\n\n#error \"numeric float type not defined\"\n\n#endif\t\t\t\t\t/* } */\n\n\n\n/*\n@@ LUA_INTEGER is the integer type used by Lua.\n**\n@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.\n**\n@@ LUAI_UACINT is the result of a 'default argument promotion'\n@@ over a LUA_INTEGER.\n@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.\n@@ LUA_INTEGER_FMT is the format for writing integers.\n@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.\n@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.\n@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.\n@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED.\n@@ lua_integer2str converts an integer to a string.\n*/\n\n\n/* The following definitions are good for most cases here */\n\n#define LUA_INTEGER_FMT\t\t\"%\" LUA_INTEGER_FRMLEN \"d\"\n\n#define LUAI_UACINT\t\tLUA_INTEGER\n\n#define lua_integer2str(s,sz,n)  \\\n\tl_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))\n\n/*\n** use LUAI_UACINT here to avoid problems with promotions (which\n** can turn a comparison between unsigneds into a signed comparison)\n*/\n#define LUA_UNSIGNED\t\tunsigned LUAI_UACINT\n\n\n#define LUA_UNSIGNEDBITS\t(sizeof(LUA_UNSIGNED) * CHAR_BIT)\n\n\n/* now the variable definitions */\n\n#if LUA_INT_TYPE == LUA_INT_INT\t\t/* { int */\n\n#define LUA_INTEGER\t\tint\n#define LUA_INTEGER_FRMLEN\t\"\"\n\n#define LUA_MAXINTEGER\t\tINT_MAX\n#define LUA_MININTEGER\t\tINT_MIN\n\n#define LUA_MAXUNSIGNED\t\tUINT_MAX\n\n#elif LUA_INT_TYPE == LUA_INT_LONG\t/* }{ long */\n\n#define LUA_INTEGER\t\tlong\n#define LUA_INTEGER_FRMLEN\t\"l\"\n\n#define LUA_MAXINTEGER\t\tLONG_MAX\n#define LUA_MININTEGER\t\tLONG_MIN\n\n#define LUA_MAXUNSIGNED\t\tULONG_MAX\n\n#elif LUA_INT_TYPE == LUA_INT_LONGLONG\t/* }{ long long */\n\n/* use presence of macro LLONG_MAX as proxy for C99 compliance */\n#if defined(LLONG_MAX)\t\t/* { */\n/* use ISO C99 stuff */\n\n#define LUA_INTEGER\t\tlong long\n#define LUA_INTEGER_FRMLEN\t\"ll\"\n\n#define LUA_MAXINTEGER\t\tLLONG_MAX\n#define LUA_MININTEGER\t\tLLONG_MIN\n\n#define LUA_MAXUNSIGNED\t\tULLONG_MAX\n\n#elif defined(LUA_USE_WINDOWS) /* }{ */\n/* in Windows, can use specific Windows types */\n\n#define LUA_INTEGER\t\t__int64\n#define LUA_INTEGER_FRMLEN\t\"I64\"\n\n#define LUA_MAXINTEGER\t\t_I64_MAX\n#define LUA_MININTEGER\t\t_I64_MIN\n\n#define LUA_MAXUNSIGNED\t\t_UI64_MAX\n\n#else\t\t\t\t/* }{ */\n\n#error \"Compiler does not support 'long long'. Use option '-DLUA_32BITS' \\\n  or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)\"\n\n#endif\t\t\t\t/* } */\n\n#else\t\t\t\t/* }{ */\n\n#error \"numeric integer type not defined\"\n\n#endif\t\t\t\t/* } */\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Dependencies with C99 and other C details\n** ===================================================================\n*/\n\n/*\n@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.\n** (All uses in Lua have only one format item.)\n*/\n#if !defined(LUA_USE_C89)\n#define l_sprintf(s,sz,f,i)\tsnprintf(s,sz,f,i)\n#else\n#define l_sprintf(s,sz,f,i)\t((void)(sz), sprintf(s,f,i))\n#endif\n\n\n/*\n@@ lua_strx2number converts a hexadecimal numeral to a number.\n** In C99, 'strtod' does that conversion. Otherwise, you can\n** leave 'lua_strx2number' undefined and Lua will provide its own\n** implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_strx2number(s,p)\t\tlua_str2number(s,p)\n#endif\n\n\n/*\n@@ lua_pointer2str converts a pointer to a readable string in a\n** non-specified way.\n*/\n#define lua_pointer2str(buff,sz,p)\tl_sprintf(buff,sz,\"%p\",p)\n\n\n/*\n@@ lua_number2strx converts a float to a hexadecimal numeral.\n** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.\n** Otherwise, you can leave 'lua_number2strx' undefined and Lua will\n** provide its own implementation.\n*/\n#if !defined(LUA_USE_C89)\n#define lua_number2strx(L,b,sz,f,n)  \\\n\t((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))\n#endif\n\n\n/*\n** 'strtof' and 'opf' variants for math functions are not valid in\n** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the\n** availability of these variants. ('math.h' is already included in\n** all files that use these macros.)\n*/\n#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))\n#undef l_mathop  /* variants not available */\n#undef lua_str2number\n#define l_mathop(op)\t\t(lua_Number)op  /* no variant */\n#define lua_str2number(s,p)\t((lua_Number)strtod((s), (p)))\n#endif\n\n\n/*\n@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation\n** functions.  It must be a numerical type; Lua will use 'intptr_t' if\n** available, otherwise it will use 'ptrdiff_t' (the nearest thing to\n** 'intptr_t' in C89)\n*/\n#define LUA_KCONTEXT\tptrdiff_t\n\n#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \\\n    __STDC_VERSION__ >= 199901L\n#include <stdint.h>\n#if defined(INTPTR_MAX)  /* even in C99 this type is optional */\n#undef LUA_KCONTEXT\n#define LUA_KCONTEXT\tintptr_t\n#endif\n#endif\n\n\n/*\n@@ lua_getlocaledecpoint gets the locale \"radix character\" (decimal point).\n** Change that if you do not want to use C locales. (Code using this\n** macro must include the header 'locale.h'.)\n*/\n#ifdef __ANDROID__\n#define lua_getlocaledecpoint() '.'\n#elif !defined(lua_getlocaledecpoint)\n#define lua_getlocaledecpoint()\t\t(localeconv()->decimal_point[0])\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Language Variations\n** =====================================================================\n*/\n\n/*\n@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some\n** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from\n** numbers to strings. Define LUA_NOCVTS2N to turn off automatic\n** coercion from strings to numbers.\n*/\n/* #define LUA_NOCVTN2S */\n/* #define LUA_NOCVTS2N */\n\n\n/*\n@@ LUA_USE_APICHECK turns on several consistency checks on the C API.\n** Define it as a help when debugging C code.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(l,e)\tassert(e)\n#endif\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Macros that affect the API and must be stable (that is, must be the\n** same when you compile Lua and when you compile code that links to\n** Lua).\n** =====================================================================\n*/\n\n/*\n@@ LUAI_MAXSTACK limits the size of the Lua stack.\n** CHANGE it if you need a different limit. This limit is arbitrary;\n** its only purpose is to stop Lua from consuming unlimited stack\n** space (and to reserve some numbers for pseudo-indices).\n** (It must fit into max(size_t)/32.)\n*/\n#if LUAI_IS32INT\n#define LUAI_MAXSTACK\t\t1000000\n#else\n#define LUAI_MAXSTACK\t\t15000\n#endif\n\n\n/*\n@@ LUA_EXTRASPACE defines the size of a raw memory area associated with\n** a Lua state with very fast access.\n** CHANGE it if you need a different size.\n*/\n#define LUA_EXTRASPACE\t\t(sizeof(void *))\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@@ of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#cmakedefine LUA_IDSIZE\t@LUA_IDSIZE@\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n*/\n#define LUAL_BUFFERSIZE   ((int)(16 * sizeof(void*) * sizeof(lua_Number)))\n\n\n/*\n@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure\n** maximum alignment for the other items in that union.\n*/\n#define LUAI_MAXALIGN  lua_Number n; double u; void *s; lua_Integer i; long l\n\n/* }================================================================== */\n\n\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n\n\n#endif\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lualib.h",
    "content": "/*\n** $Id: lualib.h $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* version suffix for environment variable names */\n#define LUA_VERSUFFIX          \"_\" LUA_VERSION_MAJOR \"_\" LUA_VERSION_MINOR\n\n\nLUAMOD_API int (luaopen_base) (lua_State *L);\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUAMOD_API int (luaopen_coroutine) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUAMOD_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUAMOD_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUAMOD_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUAMOD_API int (luaopen_string) (lua_State *L);\n\n#define LUA_UTF8LIBNAME\t\"utf8\"\nLUAMOD_API int (luaopen_utf8) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUAMOD_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUAMOD_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUAMOD_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L);\n\n\n\n#if !defined(lua_assert)\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lundump.c",
    "content": "/*\n** $Id: lundump.c $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <limits.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\n\n#if !defined(luai_verifycode)\n#define luai_verifycode(L,f)  /* empty */\n#endif\n\n\ntypedef struct {\n  lua_State *L;\n  ZIO *Z;\n  const char *name;\n} LoadState;\n\n\nstatic l_noret error (LoadState *S, const char *why) {\n  luaO_pushfstring(S->L, \"%s: bad binary format (%s)\", S->name, why);\n  luaD_throw(S->L, LUA_ERRSYNTAX);\n}\n\n\n/*\n** All high-level loads go through loadVector; you can change it to\n** adapt to the endianness of the input\n*/\n#define loadVector(S,b,n)\tloadBlock(S,b,(n)*sizeof((b)[0]))\n\nstatic void loadBlock (LoadState *S, void *b, size_t size) {\n  if (luaZ_read(S->Z, b, size) != 0)\n    error(S, \"truncated chunk\");\n}\n\n\n#define loadVar(S,x)\t\tloadVector(S,&x,1)\n\n\nstatic lu_byte loadByte (LoadState *S) {\n  int b = zgetc(S->Z);\n  if (b == EOZ)\n    error(S, \"truncated chunk\");\n  return cast_byte(b);\n}\n\n\nstatic size_t loadUnsigned (LoadState *S, size_t limit) {\n  size_t x = 0;\n  int b;\n  limit >>= 7;\n  do {\n    b = loadByte(S);\n    if (x >= limit)\n      error(S, \"integer overflow\");\n    x = (x << 7) | (b & 0x7f);\n  } while ((b & 0x80) == 0);\n  return x;\n}\n\n\nstatic size_t loadSize (LoadState *S) {\n  return loadUnsigned(S, ~(size_t)0);\n}\n\n\nstatic int loadInt (LoadState *S) {\n  return cast_int(loadUnsigned(S, INT_MAX));\n}\n\n\nstatic lua_Number loadNumber (LoadState *S) {\n  lua_Number x;\n  loadVar(S, x);\n  return x;\n}\n\n\nstatic lua_Integer loadInteger (LoadState *S) {\n  lua_Integer x;\n  loadVar(S, x);\n  return x;\n}\n\n\n/*\n** Load a nullable string into prototype 'p'.\n*/\nstatic TString *loadStringN (LoadState *S, Proto *p) {\n  lua_State *L = S->L;\n  TString *ts;\n  size_t size = loadSize(S);\n  if (size == 0)  /* no string? */\n    return NULL;\n  else if (--size <= LUAI_MAXSHORTLEN) {  /* short string? */\n    char buff[LUAI_MAXSHORTLEN];\n    loadVector(S, buff, size);  /* load string into buffer */\n    ts = luaS_newlstr(L, buff, size);  /* create string */\n  }\n  else {  /* long string */\n    ts = luaS_createlngstrobj(L, size);  /* create string */\n    setsvalue2s(L, L->top, ts);  /* anchor it ('loadVector' can GC) */\n    luaD_inctop(L);\n    loadVector(S, getstr(ts), size);  /* load directly in final place */\n    L->top--;  /* pop string */\n  }\n  luaC_objbarrier(L, p, ts);\n  return ts;\n}\n\n\n/*\n** Load a non-nullable string into prototype 'p'.\n*/\nstatic TString *loadString (LoadState *S, Proto *p) {\n  TString *st = loadStringN(S, p);\n  if (st == NULL)\n    error(S, \"bad format for constant string\");\n  return st;\n}\n\n\nstatic void loadCode (LoadState *S, Proto *f) {\n  int n = loadInt(S);\n  f->code = luaM_newvectorchecked(S->L, n, Instruction);\n  f->sizecode = n;\n  loadVector(S, f->code, n);\n}\n\n\nstatic void loadFunction(LoadState *S, Proto *f, TString *psource);\n\n\nstatic void loadConstants (LoadState *S, Proto *f) {\n  int i;\n  int n = loadInt(S);\n  f->k = luaM_newvectorchecked(S->L, n, TValue);\n  f->sizek = n;\n  for (i = 0; i < n; i++)\n    setnilvalue(&f->k[i]);\n  for (i = 0; i < n; i++) {\n    TValue *o = &f->k[i];\n    int t = loadByte(S);\n    switch (t) {\n      case LUA_VNIL:\n        setnilvalue(o);\n        break;\n      case LUA_VFALSE:\n        setbfvalue(o);\n        break;\n      case LUA_VTRUE:\n        setbtvalue(o);\n        break;\n      case LUA_VNUMFLT:\n        setfltvalue(o, loadNumber(S));\n        break;\n      case LUA_VNUMINT:\n        setivalue(o, loadInteger(S));\n        break;\n      case LUA_VSHRSTR:\n      case LUA_VLNGSTR:\n        setsvalue2n(S->L, o, loadString(S, f));\n        break;\n      default: lua_assert(0);\n    }\n  }\n}\n\n\nstatic void loadProtos (LoadState *S, Proto *f) {\n  int i;\n  int n = loadInt(S);\n  f->p = luaM_newvectorchecked(S->L, n, Proto *);\n  f->sizep = n;\n  for (i = 0; i < n; i++)\n    f->p[i] = NULL;\n  for (i = 0; i < n; i++) {\n    f->p[i] = luaF_newproto(S->L);\n    luaC_objbarrier(S->L, f, f->p[i]);\n    loadFunction(S, f->p[i], f->source);\n  }\n}\n\n\n/*\n** Load the upvalues for a function. The names must be filled first,\n** because the filling of the other fields can raise read errors and\n** the creation of the error message can call an emergency collection;\n** in that case all prototypes must be consistent for the GC.\n*/\nstatic void loadUpvalues (LoadState *S, Proto *f) {\n  int i, n;\n  n = loadInt(S);\n  f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc);\n  f->sizeupvalues = n;\n  for (i = 0; i < n; i++)  /* make array valid for GC */\n    f->upvalues[i].name = NULL;\n  for (i = 0; i < n; i++) {  /* following calls can raise errors */\n    f->upvalues[i].instack = loadByte(S);\n    f->upvalues[i].idx = loadByte(S);\n    f->upvalues[i].kind = loadByte(S);\n  }\n}\n\n\nstatic void loadDebug (LoadState *S, Proto *f) {\n  int i, n;\n  n = loadInt(S);\n  f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte);\n  f->sizelineinfo = n;\n  loadVector(S, f->lineinfo, n);\n  n = loadInt(S);\n  f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo);\n  f->sizeabslineinfo = n;\n  for (i = 0; i < n; i++) {\n    f->abslineinfo[i].pc = loadInt(S);\n    f->abslineinfo[i].line = loadInt(S);\n  }\n  n = loadInt(S);\n  f->locvars = luaM_newvectorchecked(S->L, n, LocVar);\n  f->sizelocvars = n;\n  for (i = 0; i < n; i++)\n    f->locvars[i].varname = NULL;\n  for (i = 0; i < n; i++) {\n    f->locvars[i].varname = loadStringN(S, f);\n    f->locvars[i].startpc = loadInt(S);\n    f->locvars[i].endpc = loadInt(S);\n  }\n  n = loadInt(S);\n  for (i = 0; i < n; i++)\n    f->upvalues[i].name = loadStringN(S, f);\n}\n\n\nstatic void loadFunction (LoadState *S, Proto *f, TString *psource) {\n  f->source = loadStringN(S, f);\n  if (f->source == NULL)  /* no source in dump? */\n    f->source = psource;  /* reuse parent's source */\n  f->linedefined = loadInt(S);\n  f->lastlinedefined = loadInt(S);\n  f->numparams = loadByte(S);\n  f->is_vararg = loadByte(S);\n  f->maxstacksize = loadByte(S);\n  loadCode(S, f);\n  loadConstants(S, f);\n  loadUpvalues(S, f);\n  loadProtos(S, f);\n  loadDebug(S, f);\n}\n\n\nstatic void checkliteral (LoadState *S, const char *s, const char *msg) {\n  char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */\n  size_t len = strlen(s);\n  loadVector(S, buff, len);\n  if (memcmp(s, buff, len) != 0)\n    error(S, msg);\n}\n\n\nstatic void fchecksize (LoadState *S, size_t size, const char *tname) {\n  if (loadByte(S) != size)\n    error(S, luaO_pushfstring(S->L, \"%s size mismatch\", tname));\n}\n\n\n#define checksize(S,t)\tfchecksize(S,sizeof(t),#t)\n\nstatic void checkHeader (LoadState *S) {\n  /* skip 1st char (already read and checked) */\n  checkliteral(S, &LUA_SIGNATURE[1], \"not a binary chunk\");\n  if (loadByte(S) != LUAC_VERSION)\n    error(S, \"version mismatch\");\n  if (loadByte(S) != LUAC_FORMAT)\n    error(S, \"format mismatch\");\n  checkliteral(S, LUAC_DATA, \"corrupted chunk\");\n  checksize(S, Instruction);\n  checksize(S, lua_Integer);\n  checksize(S, lua_Number);\n  if (loadInteger(S) != LUAC_INT)\n    error(S, \"integer format mismatch\");\n  if (loadNumber(S) != LUAC_NUM)\n    error(S, \"float format mismatch\");\n}\n\n\n/*\n** Load precompiled chunk.\n*/\nLClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {\n  LoadState S;\n  LClosure *cl;\n  if (*name == '@' || *name == '=')\n    S.name = name + 1;\n  else if (*name == LUA_SIGNATURE[0])\n    S.name = \"binary string\";\n  else\n    S.name = name;\n  S.L = L;\n  S.Z = Z;\n  checkHeader(&S);\n  cl = luaF_newLclosure(L, loadByte(&S));\n  setclLvalue2s(L, L->top, cl);\n  luaD_inctop(L);\n  cl->p = luaF_newproto(L);\n  luaC_objbarrier(L, cl, cl->p);\n  loadFunction(&S, cl->p, NULL);\n  lua_assert(cl->nupvalues == cl->p->sizeupvalues);\n  luai_verifycode(L, cl->p);\n  return cl;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lundump.h",
    "content": "/*\n** $Id: lundump.h $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/* data to catch conversion errors */\n#define LUAC_DATA\t\"\\x19\\x93\\r\\n\\x1a\\n\"\n\n#define LUAC_INT\t0x5678\n#define LUAC_NUM\tcast_num(370.5)\n\n/*\n** Encode major-minor version in one byte, one nibble for each\n*/\n#define MYINT(s)\t(s[0]-'0')  /* assume one-digit numerals */\n#define LUAC_VERSION\t(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))\n\n#define LUAC_FORMAT\t0\t/* this is the official format */\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,\n                         void* data, int strip);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lutf8lib.c",
    "content": "/*\n** $Id: lutf8lib.c $\n** Standard library for UTF-8 manipulation\n** See Copyright Notice in lua.h\n*/\n\n#define lutf8lib_c\n#define LUA_LIB\n\n#include \"lprefix.h\"\n\n\n#include <assert.h>\n#include <limits.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#define MAXUNICODE\t0x10FFFFu\n\n#define MAXUTF\t\t0x7FFFFFFFu\n\n/*\n** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.\n*/\n#if (UINT_MAX >> 30) >= 1\ntypedef unsigned int utfint;\n#else\ntypedef unsigned long utfint;\n#endif\n\n\n#define iscont(p)\t((*(p) & 0xC0) == 0x80)\n\n\n/* from strlib */\n/* translate a relative string position: negative means back from end */\nstatic lua_Integer u_posrelat (lua_Integer pos, size_t len) {\n  if (pos >= 0) return pos;\n  else if (0u - (size_t)pos > len) return 0;\n  else return (lua_Integer)len + pos + 1;\n}\n\n\n/*\n** Decode one UTF-8 sequence, returning NULL if byte sequence is\n** invalid.  The array 'limits' stores the minimum value for each\n** sequence length, to check for overlong representations. Its first\n** entry forces an error for non-ascii bytes with no continuation\n** bytes (count == 0).\n*/\nstatic const char *utf8_decode (const char *s, utfint *val, int strict) {\n  static const utfint limits[] =\n        {~(utfint)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u};\n  unsigned int c = (unsigned char)s[0];\n  utfint res = 0;  /* final result */\n  if (c < 0x80)  /* ascii? */\n    res = c;\n  else {\n    int count = 0;  /* to count number of continuation bytes */\n    for (; c & 0x40; c <<= 1) {  /* while it needs continuation bytes... */\n      unsigned int cc = (unsigned char)s[++count];  /* read next byte */\n      if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */\n        return NULL;  /* invalid byte sequence */\n      res = (res << 6) | (cc & 0x3F);  /* add lower 6 bits from cont. byte */\n    }\n    res |= ((utfint)(c & 0x7F) << (count * 5));  /* add first byte */\n    if (count > 5 || res > MAXUTF || res < limits[count])\n      return NULL;  /* invalid byte sequence */\n    s += count;  /* skip continuation bytes read */\n  }\n  if (strict) {\n    /* check for invalid code points; too large or surrogates */\n    if (res > MAXUNICODE || (0xD800u <= res && res <= 0xDFFFu))\n      return NULL;\n  }\n  if (val) *val = res;\n  return s + 1;  /* +1 to include first byte */\n}\n\n\n/*\n** utf8len(s [, i [, j [, lax]]]) --> number of characters that\n** start in the range [i,j], or nil + current position if 's' is not\n** well formed in that interval\n*/\nstatic int utflen (lua_State *L) {\n  lua_Integer n = 0;  /* counter for the number of characters */\n  size_t len;  /* string length in bytes */\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);\n  int lax = lua_toboolean(L, 4);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,\n                   \"initial position out of bounds\");\n  luaL_argcheck(L, --posj < (lua_Integer)len, 3,\n                   \"final position out of bounds\");\n  while (posi <= posj) {\n    const char *s1 = utf8_decode(s + posi, NULL, !lax);\n    if (s1 == NULL) {  /* conversion error? */\n      luaL_pushfail(L);  /* return fail ... */\n      lua_pushinteger(L, posi + 1);  /* ... and current position */\n      return 2;\n    }\n    posi = s1 - s;\n    n++;\n  }\n  lua_pushinteger(L, n);\n  return 1;\n}\n\n\n/*\n** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all\n** characters that start in the range [i,j]\n*/\nstatic int codepoint (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len);\n  lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  int lax = lua_toboolean(L, 4);\n  int n;\n  const char *se;\n  luaL_argcheck(L, posi >= 1, 2, \"out of bounds\");\n  luaL_argcheck(L, pose <= (lua_Integer)len, 3, \"out of bounds\");\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */\n    return luaL_error(L, \"string slice too long\");\n  n = (int)(pose -  posi) + 1;  /* upper bound for number of returns */\n  luaL_checkstack(L, n, \"string slice too long\");\n  n = 0;  /* count the number of returns */\n  se = s + pose;  /* string end */\n  for (s += posi - 1; s < se;) {\n    utfint code;\n    s = utf8_decode(s, &code, !lax);\n    if (s == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, code);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void pushutfchar (lua_State *L, int arg) {\n  lua_Unsigned code = (lua_Unsigned)luaL_checkinteger(L, arg);\n  luaL_argcheck(L, code <= MAXUTF, arg, \"value out of range\");\n  lua_pushfstring(L, \"%U\", (long)code);\n}\n\n\n/*\n** utfchar(n1, n2, ...)  -> char(n1)..char(n2)...\n*/\nstatic int utfchar (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  if (n == 1)  /* optimize common case of single char */\n    pushutfchar(L, 1);\n  else {\n    int i;\n    luaL_Buffer b;\n    luaL_buffinit(L, &b);\n    for (i = 1; i <= n; i++) {\n      pushutfchar(L, i);\n      luaL_addvalue(&b);\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\n/*\n** offset(s, n, [i])  -> index where n-th character counting from\n**   position 'i' starts; 0 means character at 'i'.\n*/\nstatic int byteoffset (lua_State *L) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n  = luaL_checkinteger(L, 2);\n  lua_Integer posi = (n >= 0) ? 1 : len + 1;\n  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);\n  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,\n                   \"position out of bounds\");\n  if (n == 0) {\n    /* find beginning of current byte sequence */\n    while (posi > 0 && iscont(s + posi)) posi--;\n  }\n  else {\n    if (iscont(s + posi))\n      return luaL_error(L, \"initial position is a continuation byte\");\n    if (n < 0) {\n       while (n < 0 && posi > 0) {  /* move back */\n         do {  /* find beginning of previous character */\n           posi--;\n         } while (posi > 0 && iscont(s + posi));\n         n++;\n       }\n     }\n     else {\n       n--;  /* do not move for 1st character */\n       while (n > 0 && posi < (lua_Integer)len) {\n         do {  /* find beginning of next character */\n           posi++;\n         } while (iscont(s + posi));  /* (cannot pass final '\\0') */\n         n--;\n       }\n     }\n  }\n  if (n == 0)  /* did it find given character? */\n    lua_pushinteger(L, posi + 1);\n  else  /* no such character */\n    luaL_pushfail(L);\n  return 1;\n}\n\n\nstatic int iter_aux (lua_State *L, int strict) {\n  size_t len;\n  const char *s = luaL_checklstring(L, 1, &len);\n  lua_Integer n = lua_tointeger(L, 2) - 1;\n  if (n < 0)  /* first iteration? */\n    n = 0;  /* start from here */\n  else if (n < (lua_Integer)len) {\n    n++;  /* skip current byte */\n    while (iscont(s + n)) n++;  /* and its continuations */\n  }\n  if (n >= (lua_Integer)len)\n    return 0;  /* no more codepoints */\n  else {\n    utfint code;\n    const char *next = utf8_decode(s + n, &code, strict);\n    if (next == NULL)\n      return luaL_error(L, \"invalid UTF-8 code\");\n    lua_pushinteger(L, n + 1);\n    lua_pushinteger(L, code);\n    return 2;\n  }\n}\n\n\nstatic int iter_auxstrict (lua_State *L) {\n  return iter_aux(L, 1);\n}\n\nstatic int iter_auxlax (lua_State *L) {\n  return iter_aux(L, 0);\n}\n\n\nstatic int iter_codes (lua_State *L) {\n  int lax = lua_toboolean(L, 2);\n  luaL_checkstring(L, 1);\n  lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict);\n  lua_pushvalue(L, 1);\n  lua_pushinteger(L, 0);\n  return 3;\n}\n\n\n/* pattern to match a single UTF-8 character */\n#define UTF8PATT\t\"[\\0-\\x7F\\xC2-\\xFD][\\x80-\\xBF]*\"\n\n\nstatic const luaL_Reg funcs[] = {\n  {\"offset\", byteoffset},\n  {\"codepoint\", codepoint},\n  {\"char\", utfchar},\n  {\"len\", utflen},\n  {\"codes\", iter_codes},\n  /* placeholders */\n  {\"charpattern\", NULL},\n  {NULL, NULL}\n};\n\n\nLUAMOD_API int luaopen_utf8 (lua_State *L) {\n  luaL_newlib(L, funcs);\n  lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);\n  lua_setfield(L, -2, \"charpattern\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lvm.c",
    "content": "/*\n** $Id: lvm.c $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n#include <float.h>\n#include <limits.h>\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n/*\n** By default, use jump tables in the main interpreter loop on gcc\n** and compatible compilers.\n*/\n#if !defined(LUA_USE_JUMPTABLE)\n#if defined(__GNUC__)\n#define LUA_USE_JUMPTABLE\t1\n#else\n#define LUA_USE_JUMPTABLE\t0\n#endif\n#endif\n\n\n\n/* limit for table tag-method chains (to avoid infinite loops) */\n#define MAXTAGLOOP\t2000\n\n\n/*\n** 'l_intfitsf' checks whether a given integer is in the range that\n** can be converted to a float without rounding. Used in comparisons.\n*/\n\n/* number of bits in the mantissa of a float */\n#define NBM\t\t(l_floatatt(MANT_DIG))\n\n/*\n** Check whether some integers may not fit in a float, testing whether\n** (maxinteger >> NBM) > 0. (That implies (1 << NBM) <= maxinteger.)\n** (The shifts are done in parts, to avoid shifting by more than the size\n** of an integer. In a worst case, NBM == 113 for long double and\n** sizeof(long) == 32.)\n*/\n#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \\\n\t>> (NBM - (3 * (NBM / 4))))  >  0\n\n/* limit for integers that fit in a float */\n#define MAXINTFITSF\t((lua_Unsigned)1 << NBM)\n\n/* check whether 'i' is in the interval [-MAXINTFITSF, MAXINTFITSF] */\n#define l_intfitsf(i)\t((MAXINTFITSF + l_castS2U(i)) <= (2 * MAXINTFITSF))\n\n#else  /* all integers fit in a float precisely */\n\n#define l_intfitsf(i)\t1\n\n#endif\n\n\n/*\n** Try to convert a value from string to a number value.\n** If the value is not a string or is a string not representing\n** a valid numeral (or if coercions from strings to numbers\n** are disabled via macro 'cvt2num'), do not modify 'result'\n** and return 0.\n*/\nstatic int l_strton (const TValue *obj, TValue *result) {\n  lua_assert(obj != result);\n  if (!cvt2num(obj))  /* is object not a string? */\n    return 0;\n  else\n    return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1);\n}\n\n\n/*\n** Try to convert a value to a float. The float case is already handled\n** by the macro 'tonumber'.\n*/\nint luaV_tonumber_ (const TValue *obj, lua_Number *n) {\n  TValue v;\n  if (ttisinteger(obj)) {\n    *n = cast_num(ivalue(obj));\n    return 1;\n  }\n  else if (l_strton(obj, &v)) {  /* string coercible to number? */\n    *n = nvalue(&v);  /* convert result of 'luaO_str2num' to a float */\n    return 1;\n  }\n  else\n    return 0;  /* conversion failed */\n}\n\n\n/*\n** try to convert a float to an integer, rounding according to 'mode'.\n*/\nint luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {\n  lua_Number f = l_floor(n);\n  if (n != f) {  /* not an integral value? */\n    if (mode == F2Ieq) return 0;  /* fails if mode demands integral value */\n    else if (mode == F2Iceil)  /* needs ceil? */\n      f += 1;  /* convert floor to ceil (remember: n != f) */\n  }\n  return lua_numbertointeger(f, p);\n}\n\n\n/*\n** try to convert a value to an integer, rounding according to 'mode',\n** without string coercion.\n** (\"Fast track\" handled by macro 'tointegerns'.)\n*/\nint luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) {\n  if (ttisfloat(obj))\n    return luaV_flttointeger(fltvalue(obj), p, mode);\n  else if (ttisinteger(obj)) {\n    *p = ivalue(obj);\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\n/*\n** try to convert a value to an integer.\n*/\nint luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode) {\n  TValue v;\n  if (l_strton(obj, &v))  /* does 'obj' point to a numerical string? */\n    obj = &v;  /* change it to point to its corresponding number */\n  return luaV_tointegerns(obj, p, mode);\n}\n\n\n/*\n** Try to convert a 'for' limit to an integer, preserving the semantics\n** of the loop. Return true if the loop must not run; otherwise, '*p'\n** gets the integer limit.\n** (The following explanation assumes a positive step; it is valid for\n** negative steps mutatis mutandis.)\n** If the limit is an integer or can be converted to an integer,\n** rounding down, that is the limit.\n** Otherwise, check whether the limit can be converted to a float. If\n** the float is too large, clip it to LUA_MAXINTEGER.  If the float\n** is too negative, the loop should not run, because any initial\n** integer value is greater than such limit; so, the function returns\n** true to signal that. (For this latter case, no integer limit would be\n** correct; even a limit of LUA_MININTEGER would run the loop once for\n** an initial value equal to LUA_MININTEGER.)\n*/\nstatic int forlimit (lua_State *L, lua_Integer init, const TValue *lim,\n                                   lua_Integer *p, lua_Integer step) {\n  if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) {\n    /* not coercible to in integer */\n    lua_Number flim;  /* try to convert to float */\n    if (!tonumber(lim, &flim)) /* cannot convert to float? */\n      luaG_forerror(L, lim, \"limit\");\n    /* else 'flim' is a float out of integer bounds */\n    if (luai_numlt(0, flim)) {  /* if it is positive, it is too large */\n      if (step < 0) return 1;  /* initial value must be less than it */\n      *p = LUA_MAXINTEGER;  /* truncate */\n    }\n    else {  /* it is less than min integer */\n      if (step > 0) return 1;  /* initial value must be greater than it */\n      *p = LUA_MININTEGER;  /* truncate */\n    }\n  }\n  return (step > 0 ? init > *p : init < *p);  /* not to run? */\n}\n\n\n/*\n** Prepare a numerical for loop (opcode OP_FORPREP).\n** Return true to skip the loop. Otherwise,\n** after preparation, stack will be as follows:\n**   ra : internal index (safe copy of the control variable)\n**   ra + 1 : loop counter (integer loops) or limit (float loops)\n**   ra + 2 : step\n**   ra + 3 : control variable\n*/\nstatic int forprep (lua_State *L, StkId ra) {\n  TValue *pinit = s2v(ra);\n  TValue *plimit = s2v(ra + 1);\n  TValue *pstep = s2v(ra + 2);\n  if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */\n    lua_Integer init = ivalue(pinit);\n    lua_Integer step = ivalue(pstep);\n    lua_Integer limit;\n    if (step == 0)\n      luaG_runerror(L, \"'for' step is zero\");\n    setivalue(s2v(ra + 3), init);  /* control variable */\n    if (forlimit(L, init, plimit, &limit, step))\n      return 1;  /* skip the loop */\n    else {  /* prepare loop counter */\n      lua_Unsigned count;\n      if (step > 0) {  /* ascending loop? */\n        count = l_castS2U(limit) - l_castS2U(init);\n        if (step != 1)  /* avoid division in the too common case */\n          count /= l_castS2U(step);\n      }\n      else {  /* step < 0; descending loop */\n        count = l_castS2U(init) - l_castS2U(limit);\n        /* 'step+1' avoids negating 'mininteger' */\n        count /= l_castS2U(-(step + 1)) + 1u;\n      }\n      /* store the counter in place of the limit (which won't be\n         needed anymore */\n      setivalue(plimit, l_castU2S(count));\n    }\n  }\n  else {  /* try making all values floats */\n    lua_Number init; lua_Number limit; lua_Number step;\n    if (unlikely(!tonumber(plimit, &limit)))\n      luaG_forerror(L, plimit, \"limit\");\n    if (unlikely(!tonumber(pstep, &step)))\n      luaG_forerror(L, pstep, \"step\");\n    if (unlikely(!tonumber(pinit, &init)))\n      luaG_forerror(L, pinit, \"initial value\");\n    if (step == 0)\n      luaG_runerror(L, \"'for' step is zero\");\n    if (luai_numlt(0, step) ? luai_numlt(limit, init)\n                            : luai_numlt(init, limit))\n      return 1;  /* skip the loop */\n    else {\n      /* make sure internal values are all floats */\n      setfltvalue(plimit, limit);\n      setfltvalue(pstep, step);\n      setfltvalue(s2v(ra), init);  /* internal index */\n      setfltvalue(s2v(ra + 3), init);  /* control variable */\n    }\n  }\n  return 0;\n}\n\n\n/*\n** Execute a step of a float numerical for loop, returning\n** true iff the loop must continue. (The integer case is\n** written online with opcode OP_FORLOOP, for performance.)\n*/\nstatic int floatforloop (StkId ra) {\n  lua_Number step = fltvalue(s2v(ra + 2));\n  lua_Number limit = fltvalue(s2v(ra + 1));\n  lua_Number idx = fltvalue(s2v(ra));  /* internal index */\n  idx = luai_numadd(L, idx, step);  /* increment index */\n  if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                          : luai_numle(limit, idx)) {\n    chgfltvalue(s2v(ra), idx);  /* update internal index */\n    setfltvalue(s2v(ra + 3), idx);  /* and control variable */\n    return 1;  /* jump back */\n  }\n  else\n    return 0;  /* finish the loop */\n}\n\n\n/*\n** Finish the table access 'val = t[key]'.\n** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to\n** t[k] entry (which must be empty).\n*/\nvoid luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,\n                      const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  const TValue *tm;  /* metamethod */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    if (slot == NULL) {  /* 't' is not a table? */\n      lua_assert(!ttistable(t));\n      tm = luaT_gettmbyobj(L, t, TM_INDEX);\n      if (unlikely(notm(tm)))\n        luaG_typeerror(L, t, \"index\");  /* no metamethod */\n      /* else will try the metamethod */\n    }\n    else {  /* 't' is a table */\n      lua_assert(isempty(slot));\n      tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);  /* table's metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        setnilvalue(s2v(val));  /* result is nil */\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    if (ttisfunction(tm)) {  /* is metamethod a function? */\n      luaT_callTMres(L, tm, t, key, val);  /* call it */\n      return;\n    }\n    t = tm;  /* else try to access 'tm[key]' */\n    if (luaV_fastget(L, t, key, slot, luaH_get)) {  /* fast track? */\n      setobj2s(L, val, slot);  /* done */\n      return;\n    }\n    /* else repeat (tail call 'luaV_finishget') */\n  }\n  luaG_runerror(L, \"'__index' chain too long; possible loop\");\n}\n\n\n/*\n** Finish a table assignment 't[key] = val'.\n** If 'slot' is NULL, 't' is not a table.  Otherwise, 'slot' points\n** to the entry 't[key]', or to a value with an absent key if there\n** is no such entry.  (The value at 'slot' must be empty, otherwise\n** 'luaV_fastget' would have done the job.)\n*/\nvoid luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                     TValue *val, const TValue *slot) {\n  int loop;  /* counter to avoid infinite loops */\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;  /* '__newindex' metamethod */\n    if (slot != NULL) {  /* is 't' a table? */\n      Table *h = hvalue(t);  /* save 't' table */\n      lua_assert(isempty(slot));  /* slot must be empty */\n      tm = fasttm(L, h->metatable, TM_NEWINDEX);  /* get metamethod */\n      if (tm == NULL) {  /* no metamethod? */\n        if (isabstkey(slot))  /* no previous entry? */\n          slot = luaH_newkey(L, h, key);  /* create one */\n        /* no metamethod and (now) there is an entry with given key */\n        setobj2t(L, cast(TValue *, slot), val);  /* set its new value */\n        invalidateTMcache(h);\n        luaC_barrierback(L, obj2gco(h), val);\n        return;\n      }\n      /* else will try the metamethod */\n    }\n    else {  /* not a table; check metamethod */\n      tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);\n      if (unlikely(notm(tm)))\n        luaG_typeerror(L, t, \"index\");\n    }\n    /* try the metamethod */\n    if (ttisfunction(tm)) {\n      luaT_callTM(L, tm, t, key, val);\n      return;\n    }\n    t = tm;  /* else repeat assignment over 'tm' */\n    if (luaV_fastget(L, t, key, slot, luaH_get)) {\n      luaV_finishfastset(L, t, slot, val);\n      return;  /* done */\n    }\n    /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */\n  }\n  luaG_runerror(L, \"'__newindex' chain too long; possible loop\");\n}\n\n\n/*\n** Compare two strings 'ls' x 'rs', returning an integer less-equal-\n** -greater than zero if 'ls' is less-equal-greater than 'rs'.\n** The code is a little tricky because it allows '\\0' in the strings\n** and it uses 'strcoll' (to respect locales) for each segments\n** of the strings.\n*/\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = tsslen(ls);\n  const char *r = getstr(rs);\n  size_t lr = tsslen(rs);\n  for (;;) {  /* for each segment */\n    int temp = strcoll(l, r);\n    if (temp != 0)  /* not equal? */\n      return temp;  /* done */\n    else {  /* strings are equal up to a '\\0' */\n      size_t len = strlen(l);  /* index of first '\\0' in both strings */\n      if (len == lr)  /* 'rs' is finished? */\n        return (len == ll) ? 0 : 1;  /* check 'ls' */\n      else if (len == ll)  /* 'ls' is finished? */\n        return -1;  /* 'ls' is less than 'rs' ('rs' is not finished) */\n      /* both strings longer than 'len'; go on comparing after the '\\0' */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than float 'f'. If 'i' has an\n** exact representation as a float ('l_intfitsf'), compare numbers as\n** floats. Otherwise, use the equivalence 'i < f <=> i < ceil(f)'.\n** If 'ceil(f)' is out of integer range, either 'f' is greater than\n** all integers or less than all integers.\n** (The test with 'l_intfitsf' is only for performance; the else\n** case is correct for all values, but it is slow due to the conversion\n** from float to int.)\n** When 'f' is NaN, comparisons must result in false.\n*/\nstatic int LTintfloat (lua_Integer i, lua_Number f) {\n  if (l_intfitsf(i))\n    return luai_numlt(cast_num(i), f);  /* compare them as floats */\n  else {  /* i < f <=> i < ceil(f) */\n    lua_Integer fi;\n    if (luaV_flttointeger(f, &fi, F2Iceil))  /* fi = ceil(f) */\n      return i < fi;   /* compare them as integers */\n    else  /* 'f' is either greater or less than all integers */\n      return f > 0;  /* greater? */\n  }\n}\n\n\n/*\n** Check whether integer 'i' is less than or equal to float 'f'.\n** See comments on previous function.\n*/\nstatic int LEintfloat (lua_Integer i, lua_Number f) {\n  if (l_intfitsf(i))\n    return luai_numle(cast_num(i), f);  /* compare them as floats */\n  else {  /* i <= f <=> i <= floor(f) */\n    lua_Integer fi;\n    if (luaV_flttointeger(f, &fi, F2Ifloor))  /* fi = floor(f) */\n      return i <= fi;   /* compare them as integers */\n    else  /* 'f' is either greater or less than all integers */\n      return f > 0;  /* greater? */\n  }\n}\n\n\n/*\n** Check whether float 'f' is less than integer 'i'.\n** See comments on previous function.\n*/\nstatic int LTfloatint (lua_Number f, lua_Integer i) {\n  if (l_intfitsf(i))\n    return luai_numlt(f, cast_num(i));  /* compare them as floats */\n  else {  /* f < i <=> floor(f) < i */\n    lua_Integer fi;\n    if (luaV_flttointeger(f, &fi, F2Ifloor))  /* fi = floor(f) */\n      return fi < i;   /* compare them as integers */\n    else  /* 'f' is either greater or less than all integers */\n      return f < 0;  /* less? */\n  }\n}\n\n\n/*\n** Check whether float 'f' is less than or equal to integer 'i'.\n** See comments on previous function.\n*/\nstatic int LEfloatint (lua_Number f, lua_Integer i) {\n  if (l_intfitsf(i))\n    return luai_numle(f, cast_num(i));  /* compare them as floats */\n  else {  /* f <= i <=> ceil(f) <= i */\n    lua_Integer fi;\n    if (luaV_flttointeger(f, &fi, F2Iceil))  /* fi = ceil(f) */\n      return fi <= i;   /* compare them as integers */\n    else  /* 'f' is either greater or less than all integers */\n      return f < 0;  /* less? */\n  }\n}\n\n\n/*\n** Return 'l < r', for numbers.\n*/\nstatic int LTnum (const TValue *l, const TValue *r) {\n  lua_assert(ttisnumber(l) && ttisnumber(r));\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li < ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LTintfloat(li, fltvalue(r));  /* l < r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numlt(lf, fltvalue(r));  /* both are float */\n    else  /* 'l' is float and 'r' is int */\n      return LTfloatint(lf, ivalue(r));\n  }\n}\n\n\n/*\n** Return 'l <= r', for numbers.\n*/\nstatic int LEnum (const TValue *l, const TValue *r) {\n  lua_assert(ttisnumber(l) && ttisnumber(r));\n  if (ttisinteger(l)) {\n    lua_Integer li = ivalue(l);\n    if (ttisinteger(r))\n      return li <= ivalue(r);  /* both are integers */\n    else  /* 'l' is int and 'r' is float */\n      return LEintfloat(li, fltvalue(r));  /* l <= r ? */\n  }\n  else {\n    lua_Number lf = fltvalue(l);  /* 'l' must be float */\n    if (ttisfloat(r))\n      return luai_numle(lf, fltvalue(r));  /* both are float */\n    else  /* 'l' is float and 'r' is int */\n      return LEfloatint(lf, ivalue(r));\n  }\n}\n\n\n/*\n** return 'l < r' for non-numbers.\n*/\nstatic int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {\n  lua_assert(!ttisnumber(l) || !ttisnumber(r));\n  if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) < 0;\n  else\n    return luaT_callorderTM(L, l, r, TM_LT);\n}\n\n\n/*\n** Main operation less than; return 'l < r'.\n*/\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LTnum(l, r);\n  else return lessthanothers(L, l, r);\n}\n\n\n/*\n** return 'l <= r' for non-numbers.\n*/\nstatic int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {\n  lua_assert(!ttisnumber(l) || !ttisnumber(r));\n  if (ttisstring(l) && ttisstring(r))  /* both are strings? */\n    return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;\n  else\n    return luaT_callorderTM(L, l, r, TM_LE);\n}\n\n\n/*\n** Main operation less than or equal to; return 'l <= r'.\n*/\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  if (ttisnumber(l) && ttisnumber(r))  /* both operands are numbers? */\n    return LEnum(l, r);\n  else return lessequalothers(L, l, r);\n}\n\n\n/*\n** Main operation for equality of Lua values; return 't1 == t2'.\n** L == NULL means raw equality (no metamethods)\n*/\nint luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  if (ttypetag(t1) != ttypetag(t2)) {  /* not the same variant? */\n    if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)\n      return 0;  /* only numbers can be equal with different variants */\n    else {  /* two numbers with different variants */\n      lua_Integer i1, i2;  /* compare them as integers */\n      return (tointegerns(t1, &i1) && tointegerns(t2, &i2) && i1 == i2);\n    }\n  }\n  /* values have same type and same variant */\n  switch (ttypetag(t1)) {\n    case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;\n    case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));\n    case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));\n    case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_VLCF: return fvalue(t1) == fvalue(t2);\n    case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));\n    case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));\n    case LUA_VUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_VTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      else if (L == NULL) return 0;\n      tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);\n      if (tm == NULL)\n        tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default:\n      return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL)  /* no TM? */\n    return 0;  /* objects are different */\n  else {\n    luaT_callTMres(L, tm, t1, t2, L->top);  /* call TM */\n    return !l_isfalse(s2v(L->top));\n  }\n}\n\n\n/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */\n#define tostring(L,o)  \\\n\t(ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))\n\n#define isemptystr(o)\t(ttisshrstring(o) && tsvalue(o)->shrlen == 0)\n\n/* copy strings in stack from top - n up to top - 1 to buffer */\nstatic void copy2buff (StkId top, int n, char *buff) {\n  size_t tl = 0;  /* size already copied */\n  do {\n    size_t l = vslen(s2v(top - n));  /* length of string being copied */\n    memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char));\n    tl += l;\n  } while (--n > 0);\n}\n\n\n/*\n** Main operation for concatenation: concat 'total' values in the stack,\n** from 'L->top - total' up to 'L->top - 1'.\n*/\nvoid luaV_concat (lua_State *L, int total) {\n  if (total == 1)\n    return;  /* \"all\" values already concatenated */\n  do {\n    StkId top = L->top;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||\n        !tostring(L, s2v(top - 1)))\n      luaT_tryconcatTM(L);\n    else if (isemptystr(s2v(top - 1)))  /* second operand is empty? */\n      cast_void(tostring(L, s2v(top - 2)));  /* result is first operand */\n    else if (isemptystr(s2v(top - 2))) {  /* first operand is empty string? */\n      setobjs2s(L, top - 2, top - 1);  /* result is second op. */\n    }\n    else {\n      /* at least two non-empty string values; get as many as possible */\n      size_t tl = vslen(s2v(top - 1));\n      TString *ts;\n      /* collect total length and number of strings */\n      for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {\n        size_t l = vslen(s2v(top - n - 1));\n        if (unlikely(l >= (MAX_SIZE/sizeof(char)) - tl))\n          luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */\n        char buff[LUAI_MAXSHORTLEN];\n        copy2buff(top, n, buff);  /* copy strings to buffer */\n        ts = luaS_newlstr(L, buff, tl);\n      }\n      else {  /* long string; copy strings directly to final result */\n        ts = luaS_createlngstrobj(L, tl);\n        copy2buff(top, n, getstr(ts));\n      }\n      setsvalue2s(L, top - n, ts);  /* create result */\n    }\n    total -= n-1;  /* got 'n' strings to create 1 new */\n    L->top -= n-1;  /* popped 'n' strings and pushed one */\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\n/*\n** Main operation 'ra = #rb'.\n*/\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n  const TValue *tm;\n  switch (ttypetag(rb)) {\n    case LUA_VTABLE: {\n      Table *h = hvalue(rb);\n      tm = fasttm(L, h->metatable, TM_LEN);\n      if (tm) break;  /* metamethod? break switch to call it */\n      setivalue(s2v(ra), luaH_getn(h));  /* else primitive len */\n      return;\n    }\n    case LUA_VSHRSTR: {\n      setivalue(s2v(ra), tsvalue(rb)->shrlen);\n      return;\n    }\n    case LUA_VLNGSTR: {\n      setivalue(s2v(ra), tsvalue(rb)->u.lnglen);\n      return;\n    }\n    default: {  /* try metamethod */\n      tm = luaT_gettmbyobj(L, rb, TM_LEN);\n      if (unlikely(notm(tm)))  /* no metamethod? */\n        luaG_typeerror(L, rb, \"get length of\");\n      break;\n    }\n  }\n  luaT_callTMres(L, tm, rb, rb, ra);\n}\n\n\n/*\n** Integer division; return 'm // n', that is, floor(m/n).\n** C division truncates its result (rounds towards zero).\n** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,\n** otherwise 'floor(q) == trunc(q) - 1'.\n*/\nlua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to divide by zero\");\n    return intop(-, 0, m);   /* n==-1; avoid overflow with 0x80000...//-1 */\n  }\n  else {\n    lua_Integer q = m / n;  /* perform C division */\n    if ((m ^ n) < 0 && m % n != 0)  /* 'm/n' would be negative non-integer? */\n      q -= 1;  /* correct result for different rounding */\n    return q;\n  }\n}\n\n\n/*\n** Integer modulus; return 'm % n'. (Assume that C '%' with\n** negative operands follows C99 behavior. See previous comment\n** about luaV_idiv.)\n*/\nlua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {\n  if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */\n    if (n == 0)\n      luaG_runerror(L, \"attempt to perform 'n%%0'\");\n    return 0;   /* m % -1 == 0; avoid overflow with 0x80000...%-1 */\n  }\n  else {\n    lua_Integer r = m % n;\n    if (r != 0 && (r ^ n) < 0)  /* 'm/n' would be non-integer negative? */\n      r += n;  /* correct result for different rounding */\n    return r;\n  }\n}\n\n\n/*\n** Float modulus\n*/\nlua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {\n  lua_Number r;\n  luai_nummod(L, m, n, r);\n  return r;\n}\n\n\n/* number of bits in an integer */\n#define NBITS\tcast_int(sizeof(lua_Integer) * CHAR_BIT)\n\n/*\n** Shift left operation. (Shift right just negates 'y'.)\n*/\n#define luaV_shiftr(x,y)\tluaV_shiftl(x,-(y))\n\nlua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {\n  if (y < 0) {  /* shift right? */\n    if (y <= -NBITS) return 0;\n    else return intop(>>, x, -y);\n  }\n  else {  /* shift left */\n    if (y >= NBITS) return 0;\n    else return intop(<<, x, y);\n  }\n}\n\n\n/*\n** create a new Lua closure, push it in the stack, and initialize\n** its upvalues.\n*/\nstatic void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,\n                         StkId ra) {\n  int nup = p->sizeupvalues;\n  Upvaldesc *uv = p->upvalues;\n  int i;\n  LClosure *ncl = luaF_newLclosure(L, nup);\n  ncl->p = p;\n  setclLvalue2s(L, ra, ncl);  /* anchor new closure in stack */\n  for (i = 0; i < nup; i++) {  /* fill in its upvalues */\n    if (uv[i].instack)  /* upvalue refers to local variable? */\n      ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);\n    else  /* get upvalue from enclosing function */\n      ncl->upvals[i] = encup[uv[i].idx];\n    luaC_objbarrier(L, ncl, ncl->upvals[i]);\n  }\n}\n\n\n/*\n** finish execution of an opcode interrupted by a yield\n*/\nvoid luaV_finishOp (lua_State *L) {\n  CallInfo *ci = L->ci;\n  StkId base = ci->func + 1;\n  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */\n  OpCode op = GET_OPCODE(inst);\n  switch (op) {  /* finish its execution */\n    case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {\n      setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);\n      break;\n    }\n    case OP_UNM: case OP_BNOT: case OP_LEN:\n    case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:\n    case OP_GETFIELD: case OP_SELF: {\n      setobjs2s(L, base + GETARG_A(inst), --L->top);\n      break;\n    }\n    case OP_LT: case OP_LE:\n    case OP_LTI: case OP_LEI:\n    case OP_GTI: case OP_GEI:\n    case OP_EQ: {  /* note that 'OP_EQI'/'OP_EQK' cannot yield */\n      int res = !l_isfalse(s2v(L->top - 1));\n      L->top--;\n#if defined(LUA_COMPAT_LT_LE)\n      if (ci->callstatus & CIST_LEQ) {  /* \"<=\" using \"<\" instead? */\n        ci->callstatus ^= CIST_LEQ;  /* clear mark */\n        res = !res;  /* negate result */\n      }\n#endif\n      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);\n      if (res != GETARG_k(inst))  /* condition failed? */\n        ci->u.l.savedpc++;  /* skip jump instruction */\n      break;\n    }\n    case OP_CONCAT: {\n      StkId top = L->top - 1;  /* top when 'luaT_tryconcatTM' was called */\n      int a = GETARG_A(inst);      /* first element to concatenate */\n      int total = cast_int(top - 1 - (base + a));  /* yet to concatenate */\n      setobjs2s(L, top - 2, top);  /* put TM result in proper position */\n      L->top = top - 1;  /* top is one after last element (at top-2) */\n      luaV_concat(L, total);  /* concat them (may yield again) */\n      break;\n    }\n    default: {\n      /* only these other opcodes can yield */\n      lua_assert(op == OP_TFORCALL || op == OP_CALL ||\n           op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE ||\n           op == OP_SETI || op == OP_SETFIELD);\n      break;\n    }\n  }\n}\n\n\n\n\n/*\n** {==================================================================\n** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute'\n** ===================================================================\n*/\n\n#define l_addi(L,a,b)\tintop(+, a, b)\n#define l_subi(L,a,b)\tintop(-, a, b)\n#define l_muli(L,a,b)\tintop(*, a, b)\n#define l_band(a,b)\tintop(&, a, b)\n#define l_bor(a,b)\tintop(|, a, b)\n#define l_bxor(a,b)\tintop(^, a, b)\n\n#define l_lti(a,b)\t(a < b)\n#define l_lei(a,b)\t(a <= b)\n#define l_gti(a,b)\t(a > b)\n#define l_gei(a,b)\t(a >= b)\n\n\n/*\n** Arithmetic operations with immediate operands. 'iop' is the integer\n** operation, 'fop' is the float operation.\n*/\n#define op_arithI(L,iop,fop) {  \\\n  TValue *v1 = vRB(i);  \\\n  int imm = GETARG_sC(i);  \\\n  if (ttisinteger(v1)) {  \\\n    lua_Integer iv1 = ivalue(v1);  \\\n    pc++; setivalue(s2v(ra), iop(L, iv1, imm));  \\\n  }  \\\n  else if (ttisfloat(v1)) {  \\\n    lua_Number nb = fltvalue(v1);  \\\n    lua_Number fimm = cast_num(imm);  \\\n    pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \\\n  }}\n\n\n/*\n** Auxiliary function for arithmetic operations over floats and others\n** with two register operands.\n*/\n#define op_arithf_aux(L,v1,v2,fop) {  \\\n  lua_Number n1; lua_Number n2;  \\\n  if (tonumberns(v1, n1) && tonumberns(v2, n2)) {  \\\n    pc++; setfltvalue(s2v(ra), fop(L, n1, n2));  \\\n  }}\n\n\n/*\n** Arithmetic operations over floats and others with register operands.\n*/\n#define op_arithf(L,fop) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = vRC(i);  \\\n  op_arithf_aux(L, v1, v2, fop); }\n\n\n/*\n** Arithmetic operations with K operands for floats.\n*/\n#define op_arithfK(L,fop) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = KC(i);  \\\n  op_arithf_aux(L, v1, v2, fop); }\n\n\n/*\n** Arithmetic operations over integers and floats.\n*/\n#define op_arith_aux(L,v1,v2,iop,fop) {  \\\n  if (ttisinteger(v1) && ttisinteger(v2)) {  \\\n    lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2);  \\\n    pc++; setivalue(s2v(ra), iop(L, i1, i2));  \\\n  }  \\\n  else op_arithf_aux(L, v1, v2, fop); }\n\n\n/*\n** Arithmetic operations with register operands.\n*/\n#define op_arith(L,iop,fop) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = vRC(i);  \\\n  op_arith_aux(L, v1, v2, iop, fop); }\n\n\n/*\n** Arithmetic operations with K operands.\n*/\n#define op_arithK(L,iop,fop) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = KC(i);  \\\n  op_arith_aux(L, v1, v2, iop, fop); }\n\n\n/*\n** Bitwise operations with constant operand.\n*/\n#define op_bitwiseK(L,op) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = KC(i);  \\\n  lua_Integer i1;  \\\n  lua_Integer i2 = ivalue(v2);  \\\n  if (tointegerns(v1, &i1)) {  \\\n    pc++; setivalue(s2v(ra), op(i1, i2));  \\\n  }}\n\n\n/*\n** Bitwise operations with register operands.\n*/\n#define op_bitwise(L,op) {  \\\n  TValue *v1 = vRB(i);  \\\n  TValue *v2 = vRC(i);  \\\n  lua_Integer i1; lua_Integer i2;  \\\n  if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {  \\\n    pc++; setivalue(s2v(ra), op(i1, i2));  \\\n  }}\n\n\n/*\n** Order operations with register operands. 'opn' actually works\n** for all numbers, but the fast track improves performance for\n** integers.\n*/\n#define op_order(L,opi,opn,other) {  \\\n        int cond;  \\\n        TValue *rb = vRB(i);  \\\n        if (ttisinteger(s2v(ra)) && ttisinteger(rb)) {  \\\n          lua_Integer ia = ivalue(s2v(ra));  \\\n          lua_Integer ib = ivalue(rb);  \\\n          cond = opi(ia, ib);  \\\n        }  \\\n        else if (ttisnumber(s2v(ra)) && ttisnumber(rb))  \\\n          cond = opn(s2v(ra), rb);  \\\n        else  \\\n          Protect(cond = other(L, s2v(ra), rb));  \\\n        docondjump(); }\n\n\n/*\n** Order operations with immediate operand. (Immediate operand is\n** always small enough to have an exact representation as a float.)\n*/\n#define op_orderI(L,opi,opf,inv,tm) {  \\\n        int cond;  \\\n        int im = GETARG_sB(i);  \\\n        if (ttisinteger(s2v(ra)))  \\\n          cond = opi(ivalue(s2v(ra)), im);  \\\n        else if (ttisfloat(s2v(ra))) {  \\\n          lua_Number fa = fltvalue(s2v(ra));  \\\n          lua_Number fim = cast_num(im);  \\\n          cond = opf(fa, fim);  \\\n        }  \\\n        else {  \\\n          int isf = GETARG_C(i);  \\\n          Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm));  \\\n        }  \\\n        docondjump(); }\n\n/* }================================================================== */\n\n\n/*\n** {==================================================================\n** Function 'luaV_execute': main interpreter loop\n** ===================================================================\n*/\n\n/*\n** some macros for common tasks in 'luaV_execute'\n*/\n\n\n#define RA(i)\t(base+GETARG_A(i))\n#define RB(i)\t(base+GETARG_B(i))\n#define vRB(i)\ts2v(RB(i))\n#define KB(i)\t(k+GETARG_B(i))\n#define RC(i)\t(base+GETARG_C(i))\n#define vRC(i)\ts2v(RC(i))\n#define KC(i)\t(k+GETARG_C(i))\n#define RKC(i)\t((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i)))\n\n\n\n#define updatetrap(ci)  (trap = ci->u.l.trap)\n\n#define updatebase(ci)\t(base = ci->func + 1)\n\n\n#define updatestack(ci) { if (trap) { updatebase(ci); ra = RA(i); } }\n\n\n/*\n** Execute a jump instruction. The 'updatetrap' allows signals to stop\n** tight loops. (Without it, the local copy of 'trap' could never change.)\n*/\n#define dojump(ci,i,e)\t{ pc += GETARG_sJ(i) + e; updatetrap(ci); }\n\n\n/* for test instructions, execute the jump instruction that follows it */\n#define donextjump(ci)\t{ Instruction ni = *pc; dojump(ci, ni, 1); }\n\n/*\n** do a conditional jump: skip next instruction if 'cond' is not what\n** was expected (parameter 'k'), else do next instruction, which must\n** be a jump.\n*/\n#define docondjump()\tif (cond != GETARG_k(i)) pc++; else donextjump(ci);\n\n\n/*\n** Correct global 'pc'.\n*/\n#define savepc(L)\t(ci->u.l.savedpc = pc)\n\n\n/*\n** Whenever code can raise errors, the global 'pc' and the global\n** 'top' must be correct to report occasional errors.\n*/\n#define savestate(L,ci)\t\t(savepc(L), L->top = ci->top)\n\n\n/*\n** Protect code that, in general, can raise errors, reallocate the\n** stack, and change the hooks.\n*/\n#define Protect(exp)  (savestate(L,ci), (exp), updatetrap(ci))\n\n/* special version that does not change the top */\n#define ProtectNT(exp)  (savepc(L), (exp), updatetrap(ci))\n\n/*\n** Protect code that will finish the loop (returns) or can only raise\n** errors. (That is, it will not return to the interpreter main loop\n** after changing the stack or hooks.)\n*/\n#define halfProtect(exp)  (savestate(L,ci), (exp))\n\n/* idem, but without changing the stack */\n#define halfProtectNT(exp)  (savepc(L), (exp))\n\n/* 'c' is the limit of live values in the stack */\n#define checkGC(L,c)  \\\n\t{ luaC_condGC(L, (savepc(L), L->top = (c)), \\\n                         updatetrap(ci)); \\\n           luai_threadyield(L); }\n\n\n/* fetch an instruction and prepare its execution */\n#define vmfetch()\t{ \\\n  if (trap) {  /* stack reallocation or hooks? */ \\\n    trap = luaG_traceexec(L, pc);  /* handle hooks */ \\\n    updatebase(ci);  /* correct stack */ \\\n  } \\\n  i = *(pc++); \\\n  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \\\n}\n\n#define vmdispatch(o)\tswitch(o)\n#define vmcase(l)\tcase l:\n#define vmbreak\t\tbreak\n\n\nvoid luaV_execute (lua_State *L, CallInfo *ci) {\n  LClosure *cl;\n  TValue *k;\n  StkId base;\n  const Instruction *pc;\n  int trap;\n#if LUA_USE_JUMPTABLE\n#include \"ljumptab.h\"\n#endif\n tailcall:\n  trap = L->hookmask;\n  cl = clLvalue(s2v(ci->func));\n  k = cl->p->k;\n  pc = ci->u.l.savedpc;\n  if (trap) {\n    if (cl->p->is_vararg)\n      trap = 0;  /* hooks will start after VARARGPREP instruction */\n    else if (pc == cl->p->code)  /* first instruction (not resuming)? */\n      luaD_hookcall(L, ci);\n    ci->u.l.trap = 1;  /* there may be other hooks */\n  }\n  base = ci->func + 1;\n  /* main loop of interpreter */\n  for (;;) {\n    Instruction i;  /* instruction being executed */\n    StkId ra;  /* instruction's A register */\n    vmfetch();\n    lua_assert(base == ci->func + 1);\n    lua_assert(base <= L->top && L->top < L->stack + L->stacksize);\n    /* invalidate top for instructions not expecting it */\n    lua_assert(isIT(i) || (cast_void(L->top = base), 1));\n    vmdispatch (GET_OPCODE(i)) {\n      vmcase(OP_MOVE) {\n        setobjs2s(L, ra, RB(i));\n        vmbreak;\n      }\n      vmcase(OP_LOADI) {\n        lua_Integer b = GETARG_sBx(i);\n        setivalue(s2v(ra), b);\n        vmbreak;\n      }\n      vmcase(OP_LOADF) {\n        int b = GETARG_sBx(i);\n        setfltvalue(s2v(ra), cast_num(b));\n        vmbreak;\n      }\n      vmcase(OP_LOADK) {\n        TValue *rb = k + GETARG_Bx(i);\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADKX) {\n        TValue *rb;\n        rb = k + GETARG_Ax(*pc); pc++;\n        setobj2s(L, ra, rb);\n        vmbreak;\n      }\n      vmcase(OP_LOADFALSE) {\n        setbfvalue(s2v(ra));\n        vmbreak;\n      }\n      vmcase(OP_LFALSESKIP) {\n        setbfvalue(s2v(ra));\n        pc++;  /* skip next instruction */\n        vmbreak;\n      }\n      vmcase(OP_LOADTRUE) {\n        setbtvalue(s2v(ra));\n        vmbreak;\n      }\n      vmcase(OP_LOADNIL) {\n        int b = GETARG_B(i);\n        do {\n          setnilvalue(s2v(ra++));\n        } while (b--);\n        vmbreak;\n      }\n      vmcase(OP_GETUPVAL) {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        vmbreak;\n      }\n      vmcase(OP_SETUPVAL) {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, s2v(ra));\n        luaC_barrier(L, uv, s2v(ra));\n        vmbreak;\n      }\n      vmcase(OP_GETTABUP) {\n        const TValue *slot;\n        TValue *upval = cl->upvals[GETARG_B(i)]->v;\n        TValue *rc = KC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {\n          setobj2s(L, ra, slot);\n        }\n        else\n          Protect(luaV_finishget(L, upval, rc, ra, slot));\n        vmbreak;\n      }\n      vmcase(OP_GETTABLE) {\n        const TValue *slot;\n        TValue *rb = vRB(i);\n        TValue *rc = vRC(i);\n        lua_Unsigned n;\n        if (ttisinteger(rc)  /* fast track for integers? */\n            ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))\n            : luaV_fastget(L, rb, rc, slot, luaH_get)) {\n          setobj2s(L, ra, slot);\n        }\n        else\n          Protect(luaV_finishget(L, rb, rc, ra, slot));\n        vmbreak;\n      }\n      vmcase(OP_GETI) {\n        const TValue *slot;\n        TValue *rb = vRB(i);\n        int c = GETARG_C(i);\n        if (luaV_fastgeti(L, rb, c, slot)) {\n          setobj2s(L, ra, slot);\n        }\n        else {\n          TValue key;\n          setivalue(&key, c);\n          Protect(luaV_finishget(L, rb, &key, ra, slot));\n        }\n        vmbreak;\n      }\n      vmcase(OP_GETFIELD) {\n        const TValue *slot;\n        TValue *rb = vRB(i);\n        TValue *rc = KC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {\n          setobj2s(L, ra, slot);\n        }\n        else\n          Protect(luaV_finishget(L, rb, rc, ra, slot));\n        vmbreak;\n      }\n      vmcase(OP_SETTABUP) {\n        const TValue *slot;\n        TValue *upval = cl->upvals[GETARG_A(i)]->v;\n        TValue *rb = KB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rb);  /* key must be a string */\n        if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {\n          luaV_finishfastset(L, upval, slot, rc);\n        }\n        else\n          Protect(luaV_finishset(L, upval, rb, rc, slot));\n        vmbreak;\n      }\n      vmcase(OP_SETTABLE) {\n        const TValue *slot;\n        TValue *rb = vRB(i);  /* key (table is in 'ra') */\n        TValue *rc = RKC(i);  /* value */\n        lua_Unsigned n;\n        if (ttisinteger(rb)  /* fast track for integers? */\n            ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))\n            : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {\n          luaV_finishfastset(L, s2v(ra), slot, rc);\n        }\n        else\n          Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));\n        vmbreak;\n      }\n      vmcase(OP_SETI) {\n        const TValue *slot;\n        int c = GETARG_B(i);\n        TValue *rc = RKC(i);\n        if (luaV_fastgeti(L, s2v(ra), c, slot)) {\n          luaV_finishfastset(L, s2v(ra), slot, rc);\n        }\n        else {\n          TValue key;\n          setivalue(&key, c);\n          Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETFIELD) {\n        const TValue *slot;\n        TValue *rb = KB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rb);  /* key must be a string */\n        if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {\n          luaV_finishfastset(L, s2v(ra), slot, rc);\n        }\n        else\n          Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));\n        vmbreak;\n      }\n      vmcase(OP_NEWTABLE) {\n        int b = GETARG_B(i);  /* log2(hash size) + 1 */\n        int c = GETARG_C(i);  /* array size */\n        Table *t;\n        if (b > 0)\n          b = 1 << (b - 1);  /* size is 2^(b - 1) */\n        lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0));\n        if (TESTARG_k(i))  /* non-zero extra argument? */\n          c += GETARG_Ax(*pc) * (MAXARG_C + 1);  /* add it to size */\n        pc++;  /* skip extra argument */\n        L->top = ra + 1;  /* correct top in case of emergency GC */\n        t = luaH_new(L);  /* memory allocation */\n        sethvalue2s(L, ra, t);\n        if (b != 0 || c != 0)\n          luaH_resize(L, t, c, b);  /* idem */\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_SELF) {\n        const TValue *slot;\n        TValue *rb = vRB(i);\n        TValue *rc = RKC(i);\n        TString *key = tsvalue(rc);  /* key must be a string */\n        setobj2s(L, ra + 1, rb);\n        if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {\n          setobj2s(L, ra, slot);\n        }\n        else\n          Protect(luaV_finishget(L, rb, rc, ra, slot));\n        vmbreak;\n      }\n      vmcase(OP_ADDI) {\n        op_arithI(L, l_addi, luai_numadd);\n        vmbreak;\n      }\n      vmcase(OP_ADDK) {\n        op_arithK(L, l_addi, luai_numadd);\n        vmbreak;\n      }\n      vmcase(OP_SUBK) {\n        op_arithK(L, l_subi, luai_numsub);\n        vmbreak;\n      }\n      vmcase(OP_MULK) {\n        op_arithK(L, l_muli, luai_nummul);\n        vmbreak;\n      }\n      vmcase(OP_MODK) {\n        op_arithK(L, luaV_mod, luaV_modf);\n        vmbreak;\n      }\n      vmcase(OP_POWK) {\n        op_arithfK(L, luai_numpow);\n        vmbreak;\n      }\n      vmcase(OP_DIVK) {\n        op_arithfK(L, luai_numdiv);\n        vmbreak;\n      }\n      vmcase(OP_IDIVK) {\n        op_arithK(L, luaV_idiv, luai_numidiv);\n        vmbreak;\n      }\n      vmcase(OP_BANDK) {\n        op_bitwiseK(L, l_band);\n        vmbreak;\n      }\n      vmcase(OP_BORK) {\n        op_bitwiseK(L, l_bor);\n        vmbreak;\n      }\n      vmcase(OP_BXORK) {\n        op_bitwiseK(L, l_bxor);\n        vmbreak;\n      }\n      vmcase(OP_SHRI) {\n        TValue *rb = vRB(i);\n        int ic = GETARG_sC(i);\n        lua_Integer ib;\n        if (tointegerns(rb, &ib)) {\n          pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));\n        }\n        vmbreak;\n      }\n      vmcase(OP_SHLI) {\n        TValue *rb = vRB(i);\n        int ic = GETARG_sC(i);\n        lua_Integer ib;\n        if (tointegerns(rb, &ib)) {\n          pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));\n        }\n        vmbreak;\n      }\n      vmcase(OP_ADD) {\n        op_arith(L, l_addi, luai_numadd);\n        vmbreak;\n      }\n      vmcase(OP_SUB) {\n        op_arith(L, l_subi, luai_numsub);\n        vmbreak;\n      }\n      vmcase(OP_MUL) {\n        op_arith(L, l_muli, luai_nummul);\n        vmbreak;\n      }\n      vmcase(OP_MOD) {\n        op_arith(L, luaV_mod, luaV_modf);\n        vmbreak;\n      }\n      vmcase(OP_POW) {\n        op_arithf(L, luai_numpow);\n        vmbreak;\n      }\n      vmcase(OP_DIV) {  /* float division (always with floats) */\n        op_arithf(L, luai_numdiv);\n        vmbreak;\n      }\n      vmcase(OP_IDIV) {  /* floor division */\n        op_arith(L, luaV_idiv, luai_numidiv);\n        vmbreak;\n      }\n      vmcase(OP_BAND) {\n        op_bitwise(L, l_band);\n        vmbreak;\n      }\n      vmcase(OP_BOR) {\n        op_bitwise(L, l_bor);\n        vmbreak;\n      }\n      vmcase(OP_BXOR) {\n        op_bitwise(L, l_bxor);\n        vmbreak;\n      }\n      vmcase(OP_SHR) {\n        op_bitwise(L, luaV_shiftr);\n        vmbreak;\n      }\n      vmcase(OP_SHL) {\n        op_bitwise(L, luaV_shiftl);\n        vmbreak;\n      }\n      vmcase(OP_MMBIN) {\n        Instruction pi = *(pc - 2);  /* original arith. expression */\n        TValue *rb = vRB(i);\n        TMS tm = (TMS)GETARG_C(i);\n        StkId result = RA(pi);\n        lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);\n        Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));\n        vmbreak;\n      }\n      vmcase(OP_MMBINI) {\n        Instruction pi = *(pc - 2);  /* original arith. expression */\n        int imm = GETARG_sB(i);\n        TMS tm = (TMS)GETARG_C(i);\n        int flip = GETARG_k(i);\n        StkId result = RA(pi);\n        Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));\n        vmbreak;\n      }\n      vmcase(OP_MMBINK) {\n        Instruction pi = *(pc - 2);  /* original arith. expression */\n        TValue *imm = KB(i);\n        TMS tm = (TMS)GETARG_C(i);\n        int flip = GETARG_k(i);\n        StkId result = RA(pi);\n        Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));\n        vmbreak;\n      }\n      vmcase(OP_UNM) {\n        TValue *rb = vRB(i);\n        lua_Number nb;\n        if (ttisinteger(rb)) {\n          lua_Integer ib = ivalue(rb);\n          setivalue(s2v(ra), intop(-, 0, ib));\n        }\n        else if (tonumberns(rb, nb)) {\n          setfltvalue(s2v(ra), luai_numunm(L, nb));\n        }\n        else\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));\n        vmbreak;\n      }\n      vmcase(OP_BNOT) {\n        TValue *rb = vRB(i);\n        lua_Integer ib;\n        if (tointegerns(rb, &ib)) {\n          setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));\n        }\n        else\n          Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));\n        vmbreak;\n      }\n      vmcase(OP_NOT) {\n        TValue *rb = vRB(i);\n        if (l_isfalse(rb))\n          setbtvalue(s2v(ra));\n        else\n          setbfvalue(s2v(ra));\n        vmbreak;\n      }\n      vmcase(OP_LEN) {\n        Protect(luaV_objlen(L, ra, vRB(i)));\n        vmbreak;\n      }\n      vmcase(OP_CONCAT) {\n        int n = GETARG_B(i);  /* number of elements to concatenate */\n        L->top = ra + n;  /* mark the end of concat operands */\n        ProtectNT(luaV_concat(L, n));\n        checkGC(L, L->top); /* 'luaV_concat' ensures correct top */\n        vmbreak;\n      }\n      vmcase(OP_CLOSE) {\n        Protect(luaF_close(L, ra, LUA_OK));\n        vmbreak;\n      }\n      vmcase(OP_TBC) {\n        /* create new to-be-closed upvalue */\n        halfProtect(luaF_newtbcupval(L, ra));\n        vmbreak;\n      }\n      vmcase(OP_JMP) {\n        dojump(ci, i, 0);\n        vmbreak;\n      }\n      vmcase(OP_EQ) {\n        int cond;\n        TValue *rb = vRB(i);\n        Protect(cond = luaV_equalobj(L, s2v(ra), rb));\n        docondjump();\n        vmbreak;\n      }\n      vmcase(OP_LT) {\n        op_order(L, l_lti, LTnum, lessthanothers);\n        vmbreak;\n      }\n      vmcase(OP_LE) {\n        op_order(L, l_lei, LEnum, lessequalothers);\n        vmbreak;\n      }\n      vmcase(OP_EQK) {\n        TValue *rb = KB(i);\n        /* basic types do not use '__eq'; we can use raw equality */\n        int cond = luaV_rawequalobj(s2v(ra), rb);\n        docondjump();\n        vmbreak;\n      }\n      vmcase(OP_EQI) {\n        int cond;\n        int im = GETARG_sB(i);\n        if (ttisinteger(s2v(ra)))\n          cond = (ivalue(s2v(ra)) == im);\n        else if (ttisfloat(s2v(ra)))\n          cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));\n        else\n          cond = 0;  /* other types cannot be equal to a number */\n        docondjump();\n        vmbreak;\n      }\n      vmcase(OP_LTI) {\n        op_orderI(L, l_lti, luai_numlt, 0, TM_LT);\n        vmbreak;\n      }\n      vmcase(OP_LEI) {\n        op_orderI(L, l_lei, luai_numle, 0, TM_LE);\n        vmbreak;\n      }\n      vmcase(OP_GTI) {\n        op_orderI(L, l_gti, luai_numgt, 1, TM_LT);\n        vmbreak;\n      }\n      vmcase(OP_GEI) {\n        op_orderI(L, l_gei, luai_numge, 1, TM_LE);\n        vmbreak;\n      }\n      vmcase(OP_TEST) {\n        int cond = !l_isfalse(s2v(ra));\n        docondjump();\n        vmbreak;\n      }\n      vmcase(OP_TESTSET) {\n        TValue *rb = vRB(i);\n        if (l_isfalse(rb) == GETARG_k(i))\n          pc++;\n        else {\n          setobj2s(L, ra, rb);\n          donextjump(ci);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CALL) {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0)  /* fixed number of arguments? */\n          L->top = ra + b;  /* top signals number of arguments */\n        /* else previous instruction set top */\n        ProtectNT(luaD_call(L, ra, nresults));\n        vmbreak;\n      }\n      vmcase(OP_TAILCALL) {\n        int b = GETARG_B(i);  /* number of arguments + 1 (function) */\n        int nparams1 = GETARG_C(i);\n        /* delat is virtual 'func' - real 'func' (vararg functions) */\n        int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;\n        if (b != 0)\n          L->top = ra + b;\n        else  /* previous instruction set top */\n          b = cast_int(L->top - ra);\n        savepc(ci);  /* some calls here can raise errors */\n        if (TESTARG_k(i)) {\n          /* close upvalues from current call; the compiler ensures\n             that there are no to-be-closed variables here, so this\n             call cannot change the stack */\n          luaF_close(L, base, NOCLOSINGMETH);\n          lua_assert(base == ci->func + 1);\n        }\n        while (!ttisfunction(s2v(ra))) {  /* not a function? */\n          luaD_tryfuncTM(L, ra);  /* try '__call' metamethod */\n          b++;  /* there is now one extra argument */\n          checkstackGCp(L, 1, ra);\n        }\n        if (!ttisLclosure(s2v(ra))) {  /* C function? */\n          luaD_call(L, ra, LUA_MULTRET);  /* call it */\n          updatetrap(ci);\n          updatestack(ci);  /* stack may have been relocated */\n          ci->func -= delta;\n          luaD_poscall(L, ci, cast_int(L->top - ra));\n          return;\n        }\n        ci->func -= delta;\n        luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */\n        goto tailcall;\n      }\n      vmcase(OP_RETURN) {\n        int n = GETARG_B(i) - 1;  /* number of results */\n        int nparams1 = GETARG_C(i);\n        if (n < 0)  /* not fixed? */\n          n = cast_int(L->top - ra);  /* get what is available */\n        savepc(ci);\n        if (TESTARG_k(i)) {  /* may there be open upvalues? */\n          if (L->top < ci->top)\n            L->top = ci->top;\n          luaF_close(L, base, LUA_OK);\n          updatetrap(ci);\n          updatestack(ci);\n        }\n        if (nparams1)  /* vararg function? */\n          ci->func -= ci->u.l.nextraargs + nparams1;\n        L->top = ra + n;  /* set call for 'luaD_poscall' */\n        luaD_poscall(L, ci, n);\n        return;\n      }\n      vmcase(OP_RETURN0) {\n        if (L->hookmask) {\n          L->top = ra;\n          halfProtectNT(luaD_poscall(L, ci, 0));  /* no hurry... */\n        }\n        else {  /* do the 'poscall' here */\n          int nres = ci->nresults;\n          L->ci = ci->previous;  /* back to caller */\n          L->top = base - 1;\n          while (nres-- > 0)\n            setnilvalue(s2v(L->top++));  /* all results are nil */\n        }\n        return;\n      }\n      vmcase(OP_RETURN1) {\n        if (L->hookmask) {\n          L->top = ra + 1;\n          halfProtectNT(luaD_poscall(L, ci, 1));  /* no hurry... */\n        }\n        else {  /* do the 'poscall' here */\n          int nres = ci->nresults;\n          L->ci = ci->previous;  /* back to caller */\n          if (nres == 0)\n            L->top = base - 1;  /* asked for no results */\n          else {\n            setobjs2s(L, base - 1, ra);  /* at least this result */\n            L->top = base;\n            while (--nres > 0)  /* complete missing results */\n              setnilvalue(s2v(L->top++));\n          }\n        }\n        return;\n      }\n      vmcase(OP_FORLOOP) {\n        if (ttisinteger(s2v(ra + 2))) {  /* integer loop? */\n          lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));\n          if (count > 0) {  /* still more iterations? */\n            lua_Integer step = ivalue(s2v(ra + 2));\n            lua_Integer idx = ivalue(s2v(ra));  /* internal index */\n            chgivalue(s2v(ra + 1), count - 1);  /* update counter */\n            idx = intop(+, idx, step);  /* add step to index */\n            chgivalue(s2v(ra), idx);  /* update internal index */\n            setivalue(s2v(ra + 3), idx);  /* and control variable */\n            pc -= GETARG_Bx(i);  /* jump back */\n          }\n        }\n        else if (floatforloop(ra))  /* float loop */\n          pc -= GETARG_Bx(i);  /* jump back */\n        updatetrap(ci);  /* allows a signal to break the loop */\n        vmbreak;\n      }\n      vmcase(OP_FORPREP) {\n        savestate(L, ci);  /* in case of errors */\n        if (forprep(L, ra))\n          pc += GETARG_Bx(i) + 1;  /* skip the loop */\n        vmbreak;\n      }\n      vmcase(OP_TFORPREP) {\n        /* create to-be-closed upvalue (if needed) */\n        halfProtect(luaF_newtbcupval(L, ra + 3));\n        pc += GETARG_Bx(i);\n        i = *(pc++);  /* go to next instruction */\n        lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));\n        goto l_tforcall;\n      }\n      vmcase(OP_TFORCALL) {\n       l_tforcall:\n        /* 'ra' has the iterator function, 'ra + 1' has the state,\n           'ra + 2' has the control variable, and 'ra + 3' has the\n           to-be-closed variable. The call will use the stack after\n           these values (starting at 'ra + 4')\n        */\n        /* push function, state, and control variable */\n        memcpy(ra + 4, ra, 3 * sizeof(*ra));\n        L->top = ra + 4 + 3;\n        ProtectNT(luaD_call(L, ra + 4, GETARG_C(i)));  /* do the call */\n        updatestack(ci);  /* stack may have changed */\n        i = *(pc++);  /* go to next instruction */\n        lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));\n        goto l_tforloop;\n      }\n      vmcase(OP_TFORLOOP) {\n        l_tforloop:\n        if (!ttisnil(s2v(ra + 4))) {  /* continue loop? */\n          setobjs2s(L, ra + 2, ra + 4);  /* save control variable */\n          pc -= GETARG_Bx(i);  /* jump back */\n        }\n        vmbreak;\n      }\n      vmcase(OP_SETLIST) {\n        int n = GETARG_B(i);\n        unsigned int last = GETARG_C(i);\n        Table *h = hvalue(s2v(ra));\n        if (n == 0)\n          n = cast_int(L->top - ra) - 1;  /* get up to the top */\n        else\n          L->top = ci->top;  /* correct top in case of emergency GC */\n        last += n;\n        if (TESTARG_k(i)) {\n          last += GETARG_Ax(*pc) * (MAXARG_C + 1);\n          pc++;\n        }\n        if (last > luaH_realasize(h))  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* preallocate it at once */\n        for (; n > 0; n--) {\n          TValue *val = s2v(ra + n);\n          setobj2t(L, &h->array[last - 1], val);\n          last--;\n          luaC_barrierback(L, obj2gco(h), val);\n        }\n        vmbreak;\n      }\n      vmcase(OP_CLOSURE) {\n        Proto *p = cl->p->p[GETARG_Bx(i)];\n        halfProtect(pushclosure(L, p, cl->upvals, base, ra));\n        checkGC(L, ra + 1);\n        vmbreak;\n      }\n      vmcase(OP_VARARG) {\n        int n = GETARG_C(i) - 1;  /* required results */\n        Protect(luaT_getvarargs(L, ci, ra, n));\n        vmbreak;\n      }\n      vmcase(OP_VARARGPREP) {\n        ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));\n        if (trap) {\n          luaD_hookcall(L, ci);\n          L->oldpc = 1;  /* next opcode will be seen as a \"new\" line */\n        }\n        updatebase(ci);  /* function has new base after adjustment */\n        vmbreak;\n      }\n      vmcase(OP_EXTRAARG) {\n        lua_assert(0);\n        vmbreak;\n      }\n    }\n  }\n}\n\n/* }================================================================== */\n"
  },
  {
    "path": "build/lua-5.4.1/src/lvm.h",
    "content": "/*\n** $Id: lvm.h $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#if !defined(LUA_NOCVTN2S)\n#define cvt2str(o)\tttisnumber(o)\n#else\n#define cvt2str(o)\t0\t/* no conversion from numbers to strings */\n#endif\n\n\n#if !defined(LUA_NOCVTS2N)\n#define cvt2num(o)\tttisstring(o)\n#else\n#define cvt2num(o)\t0\t/* no conversion from strings to numbers */\n#endif\n\n\n/*\n** You can define LUA_FLOORN2I if you want to convert floats to integers\n** by flooring them (instead of raising an error if they are not\n** integral values)\n*/\n#if !defined(LUA_FLOORN2I)\n#define LUA_FLOORN2I\t\tF2Ieq\n#endif\n\n\n/*\n** Rounding modes for float->integer coercion\n */\ntypedef enum {\n  F2Ieq,     /* no rounding; accepts only integral values */\n  F2Ifloor,  /* takes the floor of the number */\n  F2Iceil    /* takes the ceil of the number */\n} F2Imod;\n\n\n/* convert an object to a float (including string coercion) */\n#define tonumber(o,n) \\\n\t(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))\n\n\n/* convert an object to a float (without string coercion) */\n#define tonumberns(o,n) \\\n\t(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \\\n\t(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))\n\n\n/* convert an object to an integer (including string coercion) */\n#define tointeger(o,i) \\\n  (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n\n\n/* convert an object to an integer (without string coercion) */\n#define tointegerns(o,i) \\\n  (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointegerns(o,i,LUA_FLOORN2I))\n\n\n#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))\n\n#define luaV_rawequalobj(t1,t2)\t\tluaV_equalobj(NULL,t1,t2)\n\n\n/*\n** fast track for 'gettable': if 't' is a table and 't[k]' is present,\n** return 1 with 'slot' pointing to 't[k]' (position of final result).\n** Otherwise, return 0 (meaning it will have to check metamethod)\n** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL\n** (otherwise). 'f' is the raw get function to use.\n*/\n#define luaV_fastget(L,t,k,slot,f) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = f(hvalue(t), k),  /* else, do raw access */  \\\n      !isempty(slot)))  /* result not empty? */\n\n\n/*\n** Special case of 'luaV_fastget' for integers, inlining the fast case\n** of 'luaH_getint'.\n*/\n#define luaV_fastgeti(L,t,k,slot) \\\n  (!ttistable(t)  \\\n   ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \\\n   : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \\\n              ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \\\n      !isempty(slot)))  /* result not empty? */\n\n\n/*\n** Finish a fast set operation (when fast get succeeds). In that case,\n** 'slot' points to the place to put the value.\n*/\n#define luaV_finishfastset(L,t,slot,v) \\\n    { setobj2t(L, cast(TValue *,slot), v); \\\n      luaC_barrierback(L, gcvalue(t), v); }\n\n\n\n\nLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);\nLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);\nLUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,\n                                F2Imod mode);\nLUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);\nLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,\n                               StkId val, const TValue *slot);\nLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,\n                               TValue *val, const TValue *slot);\nLUAI_FUNC void luaV_finishOp (lua_State *L);\nLUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci);\nLUAI_FUNC void luaV_concat (lua_State *L, int total);\nLUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);\nLUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y);\nLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);\nLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);\n\n#endif\n"
  },
  {
    "path": "build/lua-5.4.1/src/lzio.c",
    "content": "/*\n** $Id: lzio.c $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lprefix.h\"\n\n\n#include <string.h>\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0)\n    return EOZ;\n  z->n = size - 1;  /* discount char being returned */\n  z->p = buff;\n  return cast_uchar(*(z->p++));\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (z->n == 0) {  /* no bytes in buffer? */\n      if (luaZ_fill(z) == EOZ)  /* try to read more */\n        return n;  /* no more input; return number of missing bytes */\n      else {\n        z->n++;  /* luaZ_fill consumed first byte; put it back */\n        z->p--;\n      }\n    }\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n"
  },
  {
    "path": "build/lua-5.4.1/src/lzio.h",
    "content": "/*\n** $Id: lzio.h $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))\n\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_buffremove(buff,i)\t((buff)->n -= (i))\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \\\n\t\t\t\t(buff)->buffsize, size), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);\t/* read next n bytes */\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\t\t/* reader function */\n  void *data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "build/luac/CMakeLists.txt",
    "content": "# Tencent is pleased to support the open source community by making xLua available.\r\n# Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\r\n# Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\r\n# http://opensource.org/licenses/MIT\r\n# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\r\n\r\ncmake_minimum_required(VERSION 2.8)\r\n\r\nif ( WIN32 AND NOT CYGWIN AND NOT ( CMAKE_SYSTEM_NAME STREQUAL \"WindowsStore\" ) AND NOT ANDROID)\r\n\tset(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE} /MT\" CACHE STRING \"\")\r\n\tset(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG} /MTd\" CACHE STRING \"\")\r\n\tset(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} /MT\" CACHE STRING \"\")\r\n\tset(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} /MTd\" CACHE STRING \"\")\r\nendif ()\r\n\r\nproject(luac)\r\n\r\n\r\nfind_path(LUAC_PROJECT_DIR NAMES SConstruct\r\n    PATHS \r\n    ${CMAKE_SOURCE_DIR}\r\n    NO_DEFAULT_PATH\r\n    )\r\n\r\nMARK_AS_ADVANCED(LUAC_PROJECT_DIR)\r\n\r\nset(LUA_SRC_PATH ../lua-5.3.5/src)\r\n\r\n\r\nset ( LUA_IDSIZE 120 CACHE NUMBER \"gives the maximum size for the description of the source.\" )\r\n\r\nconfigure_file ( ${LUA_SRC_PATH}/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )\r\n\r\ninclude_directories(\r\n\t${CMAKE_SOURCE_DIR}\r\n\t${LUA_SRC_PATH}\r\n\t${CMAKE_CURRENT_BINARY_DIR}\r\n)\r\n\r\nset ( LUA_CORE ${LUA_SRC_PATH}/lapi.c ${LUA_SRC_PATH}/lcode.c ${LUA_SRC_PATH}/lctype.c ${LUA_SRC_PATH}/ldebug.c ${LUA_SRC_PATH}/ldo.c ${LUA_SRC_PATH}/ldump.c\r\n  ${LUA_SRC_PATH}/lfunc.c ${LUA_SRC_PATH}/lgc.c ${LUA_SRC_PATH}/llex.c ${LUA_SRC_PATH}/lmem.c ${LUA_SRC_PATH}/lobject.c ${LUA_SRC_PATH}/lopcodes.c ${LUA_SRC_PATH}/lparser.c\r\n  ${LUA_SRC_PATH}/lstate.c ${LUA_SRC_PATH}/lstring.c ${LUA_SRC_PATH}/ltable.c ${LUA_SRC_PATH}/ltm.c ${LUA_SRC_PATH}/lundump.c ${LUA_SRC_PATH}/lvm.c ${LUA_SRC_PATH}/lzio.c )\r\nset ( LUA_LIB ${LUA_SRC_PATH}/lauxlib.c ${LUA_SRC_PATH}/lbaselib.c ${LUA_SRC_PATH}/lbitlib.c ${LUA_SRC_PATH}/lcorolib.c ${LUA_SRC_PATH}/ldblib.c\r\n  ${LUA_SRC_PATH}/liolib.c ${LUA_SRC_PATH}/lmathlib.c ${LUA_SRC_PATH}/loslib.c ${LUA_SRC_PATH}/lstrlib.c ${LUA_SRC_PATH}/ltablib.c ${LUA_SRC_PATH}/linit.c\r\n  ${LUA_SRC_PATH}/lutf8lib.c ${LUA_SRC_PATH}/loadlib.c )\r\nset ( LUAC ${LUA_SRC_PATH}/luac.c )\r\nset ( LUA ${LUA_SRC_PATH}/lua.c )\r\n\r\nmacro(source_group_by_dir proj_dir source_files)\r\n    if(MSVC OR APPLE)\r\n        get_filename_component(sgbd_cur_dir ${proj_dir} ABSOLUTE)\r\n        foreach(sgbd_file ${${source_files}})\r\n\t\t\tget_filename_component(sgbd_abs_file ${sgbd_file} ABSOLUTE)\r\n            file(RELATIVE_PATH sgbd_fpath ${sgbd_cur_dir} ${sgbd_abs_file})\r\n            string(REGEX REPLACE \"\\(.*\\)/.*\" \\\\1 sgbd_group_name ${sgbd_fpath})\r\n            string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)\r\n            string(REPLACE \"/\" \"\\\\\" sgbd_group_name ${sgbd_group_name})\r\n            if(sgbd_nogroup)\r\n                set(sgbd_group_name \"\\\\\")\r\n            endif(sgbd_nogroup)\r\n            source_group(${sgbd_group_name} FILES ${sgbd_file})\r\n        endforeach(sgbd_file)\r\n    endif(MSVC OR APPLE)\r\nendmacro(source_group_by_dir)\r\n\r\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUA_CORE)\r\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUA_LIB)\r\nsource_group_by_dir(${CMAKE_CURRENT_SOURCE_DIR} LUAC)\r\n\r\nadd_executable (luac ${LUA_CORE} ${LUA_LIB} ${LUAC})\r\nadd_executable (lua ${LUA_CORE} ${LUA_LIB} ${LUA})\r\n\r\nif (LUAC_COMPATIBLE_FORMAT)\r\ntarget_compile_definitions (luac PRIVATE LUAC_COMPATIBLE_FORMAT)\r\ntarget_compile_definitions (lua PRIVATE LUAC_COMPATIBLE_FORMAT)\r\nendif ()\r\n\r\n"
  },
  {
    "path": "build/luac/make_unix.sh",
    "content": "mkdir -p build_unix && cd build_unix\ncmake -DLUAC_COMPATIBLE_FORMAT=ON ../\ncd ..\ncmake --build build_unix --config Release\n\n"
  },
  {
    "path": "build/luac/make_win32.bat",
    "content": "\r\nset \"__VS=Visual Studio 16 2019\"\r\nset \"__VSWhere=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\r\nset \"__VSDISPLAY=\"\r\nset \"__VSVER=\"\r\nif exist \"%__VSWhere%\" (\r\n    for /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productLineVersion'\r\n\t) do set __VSDISPLAY=%%p\r\n\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productDisplayVersion'\r\n\t) do set __VSVER=%%p\r\n\t\r\n)\r\nif \"%__VSVER%\" neq \"\" (\t\r\n\tset __VS=Visual Studio %__VSVER:~0,2% %__VSDisplay%\r\n)\r\n\r\nmkdir build32 & pushd build32\r\ncmake -DLUAC_COMPATIBLE_FORMAT=ON -G  \"%__VS%\" -A Win32 ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DLUAC_COMPATIBLE_FORMAT=ON -G \"Visual Studio 16 2019\" -A Win32 ..\r\npopd\r\ncmake --build build32 --config Release\r\npause"
  },
  {
    "path": "build/luac/make_win64.bat",
    "content": "\r\nset \"__VS=Visual Studio 16 2019\"\r\nset \"__VSWhere=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\r\nset \"__VSDISPLAY=\"\r\nset \"__VSVER=\"\r\nif exist \"%__VSWhere%\" (\r\n    for /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productLineVersion'\r\n\t) do set __VSDISPLAY=%%p\r\n\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productDisplayVersion'\r\n\t) do set __VSVER=%%p\r\n\t\r\n)\r\nif \"%__VSVER%\" neq \"\" (\t\r\n\tset __VS=Visual Studio %__VSVER:~0,2% %__VSDisplay%\r\n)\r\n\r\nmkdir build64 & pushd build64\r\ncmake -DLUAC_COMPATIBLE_FORMAT=ON -G  \"%__VS%\" -A x64 ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DLUAC_COMPATIBLE_FORMAT=ON -G \"Visual Studio 16 2019\" -A x64 ..\r\npopd\r\ncmake --build build64 --config Release\r\npause"
  },
  {
    "path": "build/luajit-2.1.0b2/COPYRIGHT",
    "content": "===============================================================================\nLuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/\n\nCopyright (C) 2005-2016 Mike Pall. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n[ MIT license: http://www.opensource.org/licenses/mit-license.php ]\n\n===============================================================================\n[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]\n\nCopyright (C) 1994-2012 Lua.org, PUC-Rio.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n===============================================================================\n[ LuaJIT includes code from dlmalloc, which has this license statement: ]\n\nThis is a version (aka dlmalloc) of malloc/free/realloc written by\nDoug Lea and released to the public domain, as explained at\nhttp://creativecommons.org/licenses/publicdomain\n\n===============================================================================\n"
  },
  {
    "path": "build/luajit-2.1.0b2/Makefile",
    "content": "##############################################################################\n# LuaJIT top level Makefile for installation. Requires GNU Make.\n#\n# Please read doc/install.html before changing any variables!\n#\n# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).\n# Note: src/Makefile has many more configurable options.\n#\n# ##### This Makefile is NOT useful for Windows! #####\n# For MSVC, please follow the instructions given in src/msvcbuild.bat.\n# For MinGW and Cygwin, cd to src and run make with the Makefile there.\n#\n# Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n##############################################################################\n\nMAJVER=  2\nMINVER=  1\nRELVER=  0\nPREREL=  -beta2\nVERSION= $(MAJVER).$(MINVER).$(RELVER)$(PREREL)\nABIVER=  5.1\n\n##############################################################################\n#\n# Change the installation path as needed. This automatically adjusts\n# the paths in src/luaconf.h, too. Note: PREFIX must be an absolute path!\n#\nexport PREFIX= /usr/local\nexport MULTILIB= lib\n##############################################################################\n\nDPREFIX= $(DESTDIR)$(PREFIX)\nINSTALL_BIN=   $(DPREFIX)/bin\nINSTALL_LIB=   $(DPREFIX)/$(MULTILIB)\nINSTALL_SHARE= $(DPREFIX)/share\nINSTALL_INC=   $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)\n\nINSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION)\nINSTALL_JITLIB= $(INSTALL_LJLIBD)/jit\nINSTALL_LMODD= $(INSTALL_SHARE)/lua\nINSTALL_LMOD= $(INSTALL_LMODD)/$(ABIVER)\nINSTALL_CMODD= $(INSTALL_LIB)/lua\nINSTALL_CMOD= $(INSTALL_CMODD)/$(ABIVER)\nINSTALL_MAN= $(INSTALL_SHARE)/man/man1\nINSTALL_PKGCONFIG= $(INSTALL_LIB)/pkgconfig\n\nINSTALL_TNAME= luajit-$(VERSION)\nINSTALL_TSYMNAME= luajit\nINSTALL_ANAME= libluajit-$(ABIVER).a\nINSTALL_SONAME= libluajit-$(ABIVER).so.$(MAJVER).$(MINVER).$(RELVER)\nINSTALL_SOSHORT= libluajit-$(ABIVER).so\nINSTALL_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).$(MINVER).$(RELVER).dylib\nINSTALL_DYLIBSHORT1= libluajit-$(ABIVER).dylib\nINSTALL_DYLIBSHORT2= libluajit-$(ABIVER).$(MAJVER).dylib\nINSTALL_PCNAME= luajit.pc\n\nINSTALL_STATIC= $(INSTALL_LIB)/$(INSTALL_ANAME)\nINSTALL_DYN= $(INSTALL_LIB)/$(INSTALL_SONAME)\nINSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_SOSHORT)\nINSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_SOSHORT)\nINSTALL_T= $(INSTALL_BIN)/$(INSTALL_TNAME)\nINSTALL_TSYM= $(INSTALL_BIN)/$(INSTALL_TSYMNAME)\nINSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME)\n\nINSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \\\n  $(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD)\nUNINSTALL_DIRS= $(INSTALL_JITLIB) $(INSTALL_LJLIBD) $(INSTALL_INC) \\\n  $(INSTALL_LMOD) $(INSTALL_LMODD) $(INSTALL_CMOD) $(INSTALL_CMODD)\n\nRM= rm -f\nMKDIR= mkdir -p\nRMDIR= rmdir 2>/dev/null\nSYMLINK= ln -sf\nINSTALL_X= install -m 0755\nINSTALL_F= install -m 0644\nUNINSTALL= $(RM)\nLDCONFIG= ldconfig -n\nSED_PC= sed -e \"s|^prefix=.*|prefix=$(PREFIX)|\" \\\n            -e \"s|^multilib=.*|multilib=$(MULTILIB)|\"\n\nFILE_T= luajit\nFILE_A= libluajit.a\nFILE_SO= libluajit.so\nFILE_MAN= luajit.1\nFILE_PC= luajit.pc\nFILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h\nFILES_JITLIB= bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua \\\n\t      dis_x86.lua dis_x64.lua dis_arm.lua dis_ppc.lua \\\n\t      dis_mips.lua dis_mipsel.lua vmdef.lua\n\nifeq (,$(findstring Windows,$(OS)))\n  ifeq (Darwin,$(shell uname -s))\n    INSTALL_SONAME= $(INSTALL_DYLIBNAME)\n    INSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_DYLIBSHORT1)\n    INSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_DYLIBSHORT2)\n    LDCONFIG= :\n  endif\nendif\n\n##############################################################################\n\nINSTALL_DEP= src/luajit\n\ndefault all $(INSTALL_DEP):\n\t@echo \"==== Building LuaJIT $(VERSION) ====\"\n\t$(MAKE) -C src\n\t@echo \"==== Successfully built LuaJIT $(VERSION) ====\"\n\ninstall: $(INSTALL_DEP)\n\t@echo \"==== Installing LuaJIT $(VERSION) to $(PREFIX) ====\"\n\t$(MKDIR) $(INSTALL_DIRS)\n\tcd src && $(INSTALL_X) $(FILE_T) $(INSTALL_T)\n\tcd src && test -f $(FILE_A) && $(INSTALL_F) $(FILE_A) $(INSTALL_STATIC) || :\n\t$(RM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2)\n\tcd src && test -f $(FILE_SO) && \\\n\t  $(INSTALL_X) $(FILE_SO) $(INSTALL_DYN) && \\\n\t  $(LDCONFIG) $(INSTALL_LIB) && \\\n\t  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \\\n\t  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :\n\tcd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)\n\tcd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \\\n\t  $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \\\n\t  $(RM) $(FILE_PC).tmp\n\tcd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)\n\tcd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)\n\t@echo \"==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ====\"\n\t@echo \"\"\n\t@echo \"Note: the development releases deliberately do NOT install a symlink for luajit\"\n\t@echo \"You can do this now by running this command (with sudo):\"\n\t@echo \"\"\n\t@echo \"  $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)\"\n\t@echo \"\"\n\n\nuninstall:\n\t@echo \"==== Uninstalling LuaJIT $(VERSION) from $(PREFIX) ====\"\n\t$(UNINSTALL) $(INSTALL_T) $(INSTALL_STATIC) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2) $(INSTALL_MAN)/$(FILE_MAN) $(INSTALL_PC)\n\tfor file in $(FILES_JITLIB); do \\\n\t  $(UNINSTALL) $(INSTALL_JITLIB)/$$file; \\\n\t  done\n\tfor file in $(FILES_INC); do \\\n\t  $(UNINSTALL) $(INSTALL_INC)/$$file; \\\n\t  done\n\t$(LDCONFIG) $(INSTALL_LIB)\n\t$(RMDIR) $(UNINSTALL_DIRS) || :\n\t@echo \"==== Successfully uninstalled LuaJIT $(VERSION) from $(PREFIX) ====\"\n\n##############################################################################\n\namalg:\n\t@echo \"Building LuaJIT $(VERSION)\"\n\t$(MAKE) -C src amalg\n\nclean:\n\t$(MAKE) -C src clean\n\n.PHONY: all install amalg clean\n\n##############################################################################\n"
  },
  {
    "path": "build/luajit-2.1.0b2/README",
    "content": "README for LuaJIT 2.1.0-beta2\n-----------------------------\n\nLuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.\n\nProject Homepage: http://luajit.org/\n\nLuaJIT is Copyright (C) 2005-2016 Mike Pall.\nLuaJIT is free software, released under the MIT license.\nSee full Copyright Notice in the COPYRIGHT file or in luajit.h.\n\nDocumentation for LuaJIT is available in HTML format.\nPlease point your favorite browser to:\n\n doc/luajit.html\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/bluequad-print.css",
    "content": "/* Copyright (C) 2004-2016 Mike Pall.\n *\n * You are welcome to use the general ideas of this design for your own sites.\n * But please do not steal the stylesheet, the layout or the color scheme.\n */\nbody {\n  font-family: serif;\n  font-size: 11pt;\n  margin: 0 3em;\n  padding: 0;\n  border: none;\n}\na:link, a:visited, a:hover, a:active {\n  text-decoration: none;\n  background: transparent;\n  color: #0000ff;\n}\nh1, h2, h3 {\n  font-family: sans-serif;\n  font-weight: bold;\n  text-align: left;\n  margin: 0.5em 0;\n  padding: 0;\n}\nh1 {\n  font-size: 200%;\n}\nh2 {\n  font-size: 150%;\n}\nh3 {\n  font-size: 125%;\n}\np {\n  margin: 0 0 0.5em 0;\n  padding: 0;\n}\nul, ol {\n  margin: 0.5em 0;\n  padding: 0 0 0 2em;\n}\nul {\n  list-style: outside square;\n}\nol {\n  list-style: outside decimal;\n}\nli {\n  margin: 0;\n  padding: 0;\n}\ndl {\n  margin: 1em 0;\n  padding: 1em;\n  border: 1px solid black;\n}\ndt {\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n}\ndt sup {\n  float: right;\n  margin-left: 1em;\n}\ndd {\n  margin: 0.5em 0 0 2em;\n  padding: 0;\n}\ntable {\n  table-layout: fixed;\n  width: 100%;\n  margin: 1em 0;\n  padding: 0;\n  border: 1px solid black;\n  border-spacing: 0;\n  border-collapse: collapse;\n}\ntr {\n  margin: 0;\n  padding: 0;\n  border: none;\n}\ntd {\n  text-align: left;\n  margin: 0;\n  padding: 0.2em 0.5em;\n  border-top: 1px solid black;\n  border-bottom: 1px solid black;\n}\ntr.separate td {\n  border-top: double;\n}\ntt, pre, code, kbd, samp {\n  font-family: monospace;\n  font-size: 75%;\n}\nkbd {\n  font-weight: bolder;\n}\nblockquote, pre {\n  margin: 1em 2em;\n  padding: 0;\n}\nimg {\n  border: none;\n  vertical-align: baseline;\n  margin: 0;\n  padding: 0;\n}\nimg.left {\n  float: left;\n  margin: 0.5em 1em 0.5em 0;\n}\nimg.right {\n  float: right;\n  margin: 0.5em 0 0.5em 1em;\n}\n.flush {\n  clear: both;\n  visibility: hidden;\n}\n.hide, .noprint, #nav {\n  display: none !important;\n}\n.pagebreak {\n  page-break-before: always;\n}\n#site {\n  text-align: right;\n  font-family: sans-serif;\n  font-weight: bold;\n  margin: 0 1em;\n  border-bottom: 1pt solid black;\n}\n#site a {\n  font-size: 1.2em;\n}\n#site a:link, #site a:visited {\n  text-decoration: none;\n  font-weight: bold;\n  background: transparent;\n  color: #ffffff;\n}\n#logo {\n  color: #ff8000;\n}\n#head {\n  clear: both;\n  margin: 0 1em;\n}\n#main {\n  line-height: 1.3;\n  text-align: justify;\n  margin: 1em;\n}\n#foot {\n  clear: both;\n  font-size: 80%;\n  text-align: center;\n  margin: 0 1.25em;\n  padding: 0.5em 0 0 0;\n  border-top: 1pt solid black;\n  page-break-before: avoid;\n  page-break-after: avoid;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/bluequad.css",
    "content": "/* Copyright (C) 2004-2016 Mike Pall.\n *\n * You are welcome to use the general ideas of this design for your own sites.\n * But please do not steal the stylesheet, the layout or the color scheme.\n */\n/* colorscheme:\n *\n * site  |  head   #4162bf/white   | #6078bf/#e6ecff\n * ------+------   ----------------+-------------------\n * nav   |  main   #bfcfff         | #e6ecff/black\n *\n * nav:  hiback   loback     #c5d5ff #b9c9f9\n *       hiborder loborder   #e6ecff #97a7d7\n *       link     hover      #2142bf #ff0000\n *\n * link: link visited hover  #2142bf #8122bf #ff0000\n *\n * main: boxback  boxborder  #f0f4ff #bfcfff\n */\nbody {\n  font-family: Verdana, Arial, Helvetica, sans-serif;\n  font-size: 10pt;\n  margin: 0;\n  padding: 0;\n  border: none;\n  background: #e0e0e0;\n  color: #000000;\n}\na:link {\n  text-decoration: none;\n  background: transparent;\n  color: #2142bf;\n}\na:visited {\n  text-decoration: none;\n  background: transparent;\n  color: #8122bf;\n}\na:hover, a:active {\n  text-decoration: underline;\n  background: transparent;\n  color: #ff0000;\n}\nh1, h2, h3 {\n  font-weight: bold;\n  text-align: left;\n  margin: 0.5em 0;\n  padding: 0;\n  background: transparent;\n}\nh1 {\n  font-size: 200%;\n  line-height: 3em; /* really 6em relative to body, match #site span */\n  margin: 0;\n}\nh2 {\n  font-size: 150%;\n  color: #606060;\n}\nh3 {\n  font-size: 125%;\n  color: #404040;\n}\np {\n  max-width: 600px;\n  margin: 0 0 0.5em 0;\n  padding: 0;\n}\nb {\n  color: #404040;\n}\nul, ol {\n  max-width: 600px;\n  margin: 0.5em 0;\n  padding: 0 0 0 2em;\n}\nul {\n  list-style: outside square;\n}\nol {\n  list-style: outside decimal;\n}\nli {\n  margin: 0;\n  padding: 0;\n}\ndl {\n  max-width: 600px;\n  margin: 1em 0;\n  padding: 1em;\n  border: 1px solid #bfcfff;\n  background: #f0f4ff;\n}\ndt {\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n}\ndt sup {\n  float: right;\n  margin-left: 1em;\n  color: #808080;\n}\ndt a:visited {\n  text-decoration: none;\n  color: #2142bf;\n}\ndt a:hover, dt a:active {\n  text-decoration: none;\n  color: #ff0000;\n}\ndd {\n  margin: 0.5em 0 0 2em;\n  padding: 0;\n}\ndiv.tablewrap { /* for IE *sigh* */\n  max-width: 600px;\n}\ntable {\n  table-layout: fixed;\n  border-spacing: 0;\n  border-collapse: collapse;\n  max-width: 600px;\n  width: 100%;\n  margin: 1em 0;\n  padding: 0;\n  border: 1px solid #bfcfff;\n}\ntr {\n  margin: 0;\n  padding: 0;\n  border: none;\n}\ntr.odd {\n  background: #f0f4ff;\n}\ntr.separate td {\n  border-top: 1px solid #bfcfff;\n}\ntd {\n  text-align: left;\n  margin: 0;\n  padding: 0.2em 0.5em;\n  border: none;\n}\ntt, code, kbd, samp {\n  font-family: Courier New, Courier, monospace;\n  line-height: 1.2;\n  font-size: 110%;\n}\nkbd {\n  font-weight: bolder;\n}\nblockquote, pre {\n  max-width: 600px;\n  margin: 1em 2em;\n  padding: 0;\n}\npre {\n  line-height: 1.1;\n}\npre.code {\n  line-height: 1.4;\n  margin: 0.5em 0 1em 0.5em;\n  padding: 0.5em 1em;\n  border: 1px solid #bfcfff;\n  background: #f0f4ff;\n}\npre.mark {\n  padding-left: 2em;\n}\nspan.codemark {\n  position:absolute;\n  left: 16em;\n  color: #4040c0;\n}\nspan.mark {\n  color: #4040c0;\n  font-family: Courier New, Courier, monospace;\n  line-height: 1.1;\n}\nimg {\n  border: none;\n  vertical-align: baseline;\n  margin: 0;\n  padding: 0;\n}\nimg.left {\n  float: left;\n  margin: 0.5em 1em 0.5em 0;\n}\nimg.right {\n  float: right;\n  margin: 0.5em 0 0.5em 1em;\n}\n.indent {\n  padding-left: 1em;\n}\n.flush {\n  clear: both;\n  visibility: hidden;\n}\n.hide, .noscreen {\n  display: none !important;\n}\n.ext {\n  color: #ff8000;\n}\n.new {\n  font-size: 6pt;\n  vertical-align: middle;\n  background: #ff8000;\n  color: #ffffff;\n}\n#site {\n  clear: both;\n  float: left;\n  width: 13em;\n  text-align: center;\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n  background: transparent;\n  color: #ffffff;\n}\n#site a {\n  font-size: 200%;\n}\n#site a:link, #site a:visited {\n  text-decoration: none;\n  font-weight: bold;\n  background: transparent;\n  color: #ffffff;\n}\n#site span {\n  line-height: 3em; /* really 6em relative to body, match h1 */\n}\n#logo {\n  color: #ffb380;\n}\n#head {\n  margin: 0;\n  padding: 0 0 0 2em;\n  border-left: solid 13em #4162bf;\n  border-right: solid 3em #6078bf;\n  background: #6078bf;\n  color: #e6ecff;\n}\n#nav {\n  clear: both;\n  float: left;\n  overflow: hidden;\n  text-align: left;\n  line-height: 1.5;\n  width: 13em;\n  padding-top: 1em;\n  background: transparent;\n}\n#nav ul {\n  list-style: none outside;\n  margin: 0;\n  padding: 0;\n}\n#nav li {\n  margin: 0;\n  padding: 0;\n}\n#nav a {\n  display: block;\n  text-decoration: none;\n  font-weight: bold;\n  margin: 0;\n  padding: 2px 1em;\n  border-top: 1px solid transparent;\n  border-bottom: 1px solid transparent;\n  background: transparent;\n  color: #2142bf;\n}\n#nav a:hover, #nav a:active {\n  text-decoration: none;\n  border-top: 1px solid #97a7d7;\n  border-bottom: 1px solid #e6ecff;\n  background: #b9c9f9;\n  color: #ff0000;\n}\n#nav a.current, #nav a.current:hover, #nav a.current:active {\n  border-top: 1px solid #e6ecff;\n  border-bottom: 1px solid #97a7d7;\n  background: #c5d5ff;\n  color: #2142bf;\n}\n#nav ul ul a {\n  padding: 0 1em 0 1.7em;\n}\n#nav ul ul ul a {\n  padding: 0 0.5em 0 2.4em;\n}\n#main {\n  line-height: 1.5;\n  text-align: left;\n  margin: 0;\n  padding: 1em 2em;\n  border-left: solid 13em #bfcfff;\n  border-right: solid 3em #e6ecff;\n  background: #e6ecff;\n}\n#foot {\n  clear: both;\n  font-size: 80%;\n  text-align: center;\n  margin: 0;\n  padding: 0.5em;\n  background: #6078bf;\n  color: #ffffff;\n}\n#foot a:link, #foot a:visited {\n  text-decoration: underline;\n  background: transparent;\n  color: #ffffff;\n}\n#foot a:hover, #foot a:active {\n  text-decoration: underline;\n  background: transparent;\n  color: #bfcfff;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/changes.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>LuaJIT Change History</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ndiv.major { max-width: 600px; padding: 1em; margin: 1em 0 1em 0; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>LuaJIT Change History</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a class=\"current\" href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis is a list of changes between the released versions of LuaJIT.<br>\nThe current <span style=\"color: #0000c0;\">stable version</span> is <strong>LuaJIT&nbsp;2.0.4</strong>.<br>\n</p>\n<p>\nPlease check the\n<a href=\"http://luajit.org/changes.html\"><span class=\"ext\">&raquo;</span>&nbsp;Online Change History</a>\nto see whether newer versions are available.\n</p>\n\n<div class=\"major\" style=\"background: #d0d0ff;\">\n<h2 id=\"LuaJIT-2.1.0-beta2\">LuaJIT 2.1.0-beta2 &mdash; 2016-03-03</h2>\n<ul>\n<li>Enable trace stitching.</li>\n<li>Use internal implementation for converting FP numbers to strings.</li>\n<li>Parse Unicode escape <tt>'\\u{XX...}'</tt> in string literals.</li>\n<li>Add MIPS soft-float support.</li>\n<li>Switch MIPS port to dual-number mode.</li>\n<li>x86/x64: Add support for AES-NI, AVX and AVX2 to DynASM.</li>\n<li>FFI: Add <tt>ssize_t</tt> declaration.</li>\n<li>FFI: Parse <tt>#line NN</tt> and <tt>#NN</tt>.</li>\n<li>Various minor fixes.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.1.0-beta1\">LuaJIT 2.1.0-beta1 &mdash; 2015-08-25</h2>\n<p>\nThis is a brief summary of the major changes in LuaJIT 2.1 compared to 2.0.\nPlease take a look at the commit history for more details.\n</p>\n<ul>\n<li>Changes to the VM core:\n<ul>\n<li>Add low-overhead profiler (<tt>-jp</tt>).</li>\n<li>Add <tt>LJ_GC64</tt> mode: 64 bit GC object references (really: 47 bit). Interpreter-only for now.</li>\n<li>Add <tt>LJ_FR2</tt> mode: Two-slot frame info. Required by <tt>LJ_GC64</tt> mode.</li>\n<li>Add <tt>table.new()</tt> and <tt>table.clear()</tt>.</li>\n<li>Parse binary number literals (<tt>0bxxx</tt>).</li>\n</ul></li>\n<li>Improvements to the JIT compiler:\n<ul>\n<li>Add trace stitching (disabled for now).</li>\n<li>Compile various builtins: <tt>string.char()</tt>, <tt>string.reverse()</tt>, <tt>string.lower()</tt>, <tt>string.upper()</tt>, <tt>string.rep()</tt>, <tt>string.format()</tt>, <tt>table.concat()</tt>, <tt>bit.tohex()</tt>, <tt>getfenv(0)</tt>, <tt>debug.getmetatable()</tt>.</li>\n<li>Compile <tt>string.find()</tt> for fixed string searches (no patterns).</li>\n<li>Compile <tt>BC_TSETM</tt>, e.g. <tt>{1,2,3,f()}</tt>.</li>\n<li>Compile string concatenations (<tt>BC_CAT</tt>).</li>\n<li>Compile <tt>__concat</tt> metamethod.</li>\n<li>Various minor optimizations.</li>\n</ul></li>\n<li>Internal Changes:\n<ul>\n<li>Add support for embedding LuaJIT bytecode for builtins.</li>\n<li>Replace various builtins with embedded bytecode.</li>\n<li>Refactor string buffers and string formatting.</li>\n<li>Remove obsolete non-truncating number to integer conversions.</li>\n</ul></li>\n<li>Ports:\n<ul>\n<li>Add Xbox One port (<tt>LJ_GC64</tt> mode).</li>\n<li>ARM64: Add port of the interpreter (<tt>LJ_GC64</tt> mode).</li>\n<li>x64: Add separate port of the interpreter to <tt>LJ_GC64</tt> mode.</li>\n<li>x86/x64: Drop internal x87 math functions. Use libm functions.</li>\n<li>x86: Remove x87 support from interpreter. SSE2 is mandatory now.</li>\n<li>PPC/e500: Drop support for this architecture.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>FFI: Add 64 bit bitwise operations.</li>\n<li>FFI: Compile VLA/VLS and large cdata allocations with default initialization.</li>\n<li>FFI: Compile conversions from functions to function pointers.</li>\n<li>FFI: Compile lightuserdata to <tt>void *</tt> conversion.</li>\n<li>FFI: Compile <tt>ffi.gc(cdata, nil)</tt>, too.</li>\n<li>FFI: Add <tt>ffi.typeinfo()</tt>.</li>\n</ul></li>\n</ul>\n</div>\n\n<div class=\"major\" style=\"background: #ffffd0;\">\n<h2 id=\"LuaJIT-2.0.4\">LuaJIT 2.0.4 &mdash; 2015-05-14</h2>\n<ul>\n<li>Fix stack check in narrowing optimization.</li>\n<li>Fix Lua/C API typecheck error for special indexes.</li>\n<li>Fix string to number conversion.</li>\n<li>Fix lexer error for chunks without tokens.</li>\n<li>Don't compile <tt>IR_RETF</tt> after <tt>CALLT</tt> to ff with-side effects.</li>\n<li>Fix <tt>BC_UCLO</tt>/<tt>BC_JMP</tt> join optimization in Lua parser.</li>\n<li>Fix corner case in string to number conversion.</li>\n<li>Gracefully handle <tt>lua_error()</tt> for a suspended coroutine.</li>\n<li>Avoid error messages when building with Clang.</li>\n<li>Fix snapshot #0 handling for traces with a stack check on entry.</li>\n<li>Fix fused constant loads under high register pressure.</li>\n<li>Invalidate backpropagation cache after DCE.</li>\n<li>Fix ABC elimination.</li>\n<li>Fix debug info for main chunk of stripped bytecode.</li>\n<li>Fix FOLD rule for <tt>string.sub(s, ...) == k</tt>.</li>\n<li>Fix FOLD rule for <tt>STRREF</tt> of <tt>SNEW</tt>.</li>\n<li>Fix frame traversal while searching for error function.</li>\n<li>Prevent GC estimate miscalculation due to buffer growth.</li>\n<li>Prevent adding side traces for stack checks.</li>\n<li>Fix top slot calculation for snapshots with continuations.</li>\n<li>Fix check for reuse of SCEV results in <tt>FORL</tt>.</li>\n<li>Add PS Vita port.</li>\n<li>Fix compatibility issues with Illumos.</li>\n<li>Fix DragonFly build (unsupported).</li>\n<li>OpenBSD/x86: Better executable memory allocation for W^X mode.</li>\n<li>x86: Fix argument checks for <tt>ipairs()</tt> iterator.</li>\n<li>x86: <tt>lj_math_random_step()</tt> clobbers XMM regs on OSX Clang.</li>\n<li>x86: Fix code generation for unused result of <tt>math.random()</tt>.</li>\n<li>x64: Allow building with <tt>LUAJIT_USE_SYSMALLOC</tt> and <tt>LUAJIT_USE_VALGRIND</tt>.</li>\n<li>x86/x64: Fix argument check for bit shifts.</li>\n<li>x86/x64: Fix code generation for fused test/arith ops.</li>\n<li>ARM: Fix write barrier check in <tt>BC_USETS</tt>.</li>\n<li>PPC: Fix red zone overflow in machine code generation.</li>\n<li>PPC: Don't use <tt>mcrxr</tt> on PPE.</li>\n<li>Various archs: Fix excess stack growth in interpreter.</li>\n<li>FFI: Fix FOLD rule for <tt>TOBIT</tt> + <tt>CONV num.u32</tt>.</li>\n<li>FFI: Prevent DSE across <tt>ffi.string()</tt>.</li>\n<li>FFI: No meta fallback when indexing pointer to incomplete struct.</li>\n<li>FFI: Fix initialization of unions of subtypes.</li>\n<li>FFI: Fix cdata vs. non-cdata arithmetic and comparisons.</li>\n<li>FFI: Fix <tt>__index</tt>/<tt>__newindex</tt> metamethod resolution for ctypes.</li>\n<li>FFI: Fix compilation of reference field access.</li>\n<li>FFI: Fix frame traversal for backtraces with FFI callbacks.</li>\n<li>FFI: Fix recording of indexing a struct pointer ctype object itself.</li>\n<li>FFI: Allow non-scalar cdata to be compared for equality by address.</li>\n<li>FFI: Fix pseudo type conversions for type punning.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.3\">LuaJIT 2.0.3 &mdash; 2014-03-12</h2>\n<ul>\n<li>Add PS4 port.</li>\n<li>Add support for multilib distro builds.</li>\n<li>Fix OSX build.</li>\n<li>Fix MinGW build.</li>\n<li>Fix Xbox 360 build.</li>\n<li>Improve ULOAD forwarding for open upvalues.</li>\n<li>Fix GC steps threshold handling when called by JIT-compiled code.</li>\n<li>Fix argument checks for <tt>math.deg()</tt> and <tt>math.rad()</tt>.</li>\n<li>Fix <tt>jit.flush(func|true)</tt>.</li>\n<li>Respect <tt>jit.off(func)</tt> when returning to a function, too.</li>\n<li>Fix compilation of <tt>string.byte(s, nil, n)</tt>.</li>\n<li>Fix line number for relocated bytecode after closure fixup</li>\n<li>Fix frame traversal for backtraces.</li>\n<li>Fix ABC elimination.</li>\n<li>Fix handling of redundant PHIs.</li>\n<li>Fix snapshot restore for exit to function header.</li>\n<li>Fix type punning alias analysis for constified pointers</li>\n<li>Fix call unroll checks in the presence of metamethod frames.</li>\n<li>Fix initial maxslot for down-recursive traces.</li>\n<li>Prevent BASE register coalescing if parent uses <tt>IR_RETF</tt>.</li>\n<li>Don't purge modified function from stack slots in <tt>BC_RET</tt>.</li>\n<li>Fix recording of <tt>BC_VARG</tt>.</li>\n<li>Don't access dangling reference to reallocated IR.</li>\n<li>Fix frame depth display for bytecode dump in <tt>-jdump</tt>.</li>\n<li>ARM: Fix register allocation when rematerializing FPRs.</li>\n<li>x64: Fix store to upvalue for lightuserdata values.</li>\n<li>FFI: Add missing GC steps for callback argument conversions.</li>\n<li>FFI: Properly unload loaded DLLs.</li>\n<li>FFI: Fix argument checks for <tt>ffi.string()</tt>.</li>\n<li>FFI/x64: Fix passing of vector arguments to calls.</li>\n<li>FFI: Rehash finalizer table after GC cycle, if needed.</li>\n<li>FFI: Fix <tt>cts-&gt;L</tt> for cdata unsinking in snapshot restore.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.2\">LuaJIT 2.0.2 &mdash; 2013-06-03</h2>\n<ul>\n<li>Fix memory access check for fast string interning.</li>\n<li>Fix MSVC intrinsics for older versions.</li>\n<li>Add missing GC steps for <tt>io.*</tt> functions.</li>\n<li>Fix spurious red zone overflows in machine code generation.</li>\n<li>Fix jump-range constrained mcode allocation.</li>\n<li>Inhibit DSE for implicit loads via calls.</li>\n<li>Fix builtin string to number conversion for overflow digits.</li>\n<li>Fix optional argument handling while recording builtins.</li>\n<li>Fix optional argument handling in <tt>table.concat()</tt>.</li>\n<li>Add partial support for building with MingW64 GCC 4.8-SEH.</li>\n<li>Add missing PHI barrier to <tt>string.sub(str, a, b) == kstr</tt> FOLD rule.</li>\n<li>Fix compatibility issues with Illumos.</li>\n<li>ARM: Fix cache flush/sync for exit stubs of JIT-compiled code.</li>\n<li>MIPS: Fix cache flush/sync for JIT-compiled code jump area.</li>\n<li>PPC: Add <tt>plt</tt> suffix for external calls from assembler code.</li>\n<li>FFI: Fix snapshot substitution in SPLIT pass.</li>\n<li>FFI/x86: Fix register allocation for 64 bit comparisons.</li>\n<li>FFI: Fix tailcall in lowest frame to C&nbsp;function with bool result.</li>\n<li>FFI: Ignore <tt>long</tt> type specifier in <tt>ffi.istype()</tt>.</li>\n<li>FFI: Fix calling conventions for 32 bit OSX and iOS simulator (struct returns).</li>\n<li>FFI: Fix calling conventions for ARM hard-float EABI (nested structs).</li>\n<li>FFI: Improve error messages for arithmetic and comparison operators.</li>\n<li>FFI: Insert no-op type conversion for pointer to integer cast.</li>\n<li>FFI: Fix unroll limit for <tt>ffi.fill()</tt>.</li>\n<li>FFI: Must sink <tt>XBAR</tt> together with <tt>XSTORE</tt>s.</li>\n<li>FFI: Preserve intermediate string for <tt>const&nbsp;char&nbsp;*</tt> conversion.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.1\">LuaJIT 2.0.1 &mdash; 2013-02-19</h2>\n<ul>\n<li>Don't clear frame for out-of-memory error.</li>\n<li>Leave hook when resume catches error thrown from hook.</li>\n<li>Add missing GC steps for template table creation.</li>\n<li>Fix discharge order of comparisons in Lua parser.</li>\n<li>Improve buffer handling for <tt>io.read()</tt>.</li>\n<li>OSX: Add support for Mach-O object files to <tt>-b</tt> option.</li>\n<li>Fix PS3 port.</li>\n<li>Fix/enable Xbox 360 port.</li>\n<li>x86/x64: Always mark ref for shift count as non-weak.</li>\n<li>x64: Don't fuse implicitly 32-to-64 extended operands.</li>\n<li>ARM: Fix armhf call argument handling.</li>\n<li>ARM: Fix code generation for integer math.min/math.max.</li>\n<li>PPC/e500: Fix <tt>lj_vm_floor()</tt> for Inf/NaN.</li>\n<li>FFI: Change priority of table initializer variants for structs.</li>\n<li>FFI: Fix code generation for bool call result check on x86/x64.</li>\n<li>FFI: Load FFI library on-demand for bytecode with cdata literals.</li>\n<li>FFI: Fix handling of qualified transparent structs/unions.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0\">LuaJIT 2.0.0 &mdash; 2012-11-08</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n  <li>Fix Android/x86 build.</li>\n  <li>Fix recording of equality comparisons with <tt>__eq</tt> metamethods.</li>\n  <li>Fix detection of immutable upvalues.</li>\n  <li>Replace error with PANIC for callbacks from JIT-compiled code.</li>\n  <li>Fix builtin string to number conversion for <tt>INT_MIN</tt>.</li>\n  <li>Don't create unneeded array part for template tables.</li>\n  <li>Fix <tt>CONV.num.int</tt> sinking.</li>\n  <li>Don't propagate implicitly widened number to index metamethods.</li>\n  <li>ARM: Fix ordered comparisons of number vs. non-number.</li>\n  <li>FFI: Fix code generation for replay of sunk float fields.</li>\n  <li>FFI: Fix signedness of bool.</li>\n  <li>FFI: Fix recording of bool call result check on x86/x64.</li>\n  <li>FFI: Fix stack-adjustment for <tt>__thiscall</tt> callbacks.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta11\">LuaJIT 2.0.0-beta11 &mdash; 2012-10-16</h2>\n<ul>\n<li>New features:\n<ul>\n  <li>Use ARM VFP instructions, if available (build-time detection).</li>\n  <li>Add support for ARM hard-float EABI (<tt>armhf</tt>).</li>\n  <li>Add PS3 port.</li>\n  <li>Add many features from Lua&nbsp;5.2, e.g. <tt>goto</tt>/labels.\n  Refer to <a href=\"extensions.html#lua52\">this list</a>.</li>\n  <li>FFI: Add parameterized C types.</li>\n  <li>FFI: Add support for copy constructors.</li>\n  <li>FFI: Equality comparisons never raise an error (treat as unequal instead).</li>\n  <li>FFI: Box all accessed or returned enums.</li>\n  <li>FFI: Check for <tt>__new</tt> metamethod when calling a constructor.</li>\n  <li>FFI: Handle <tt>__pairs</tt>/<tt>__ipairs</tt> metamethods for cdata objects.</li>\n  <li>FFI: Convert <tt>io.*</tt> file handle to <tt>FILE *</tt> pointer (but as a <tt>void *</tt>).</li>\n  <li>FFI: Detect and support type punning through unions.</li>\n  <li>FFI: Improve various error messages.</li>\n</ul></li>\n<li>Build-system reorganization:\n<ul>\n  <li>Reorganize directory layout:<br>\n  <tt>lib/*</tt> &rarr; <tt>src/jit/*</tt><br>\n  <tt>src/buildvm_*.dasc</tt> &rarr; <tt>src/vm_*.dasc</tt><br>\n  <tt>src/buildvm_*.h</tt> &rarr; removed<br>\n  <tt>src/buildvm*</tt> &rarr; <tt>src/host/*</tt></li>\n  <li>Add minified Lua interpreter plus Lua BitOp (<tt>minilua</tt>) to run DynASM.</li>\n  <li>Change DynASM bit operations to use Lua BitOp</li>\n  <li>Translate only <tt>vm_*.dasc</tt> for detected target architecture.</li>\n  <li>Improve target detection for <tt>msvcbuild.bat</tt>.</li>\n  <li>Fix build issues on Cygwin and MinGW with optional MSys.</li>\n  <li>Handle cross-compiles with FPU/no-FPU or hard-fp/soft-fp ABI mismatch.</li>\n  <li>Remove some library functions for no-JIT/no-FFI builds.</li>\n  <li>Add uninstall target to top-level Makefile.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n  <li>Preserve snapshot #0 PC for all traces.</li>\n  <li>Fix argument checks for <tt>coroutine.create()</tt>.</li>\n  <li>Command line prints version and JIT status to <tt>stdout</tt>, not <tt>stderr</tt>.</li>\n  <li>Fix userdata <tt>__gc</tt> separations at Lua state close.</li>\n  <li>Fix <tt>TDUP</tt> to <tt>HLOAD</tt> forwarding for <tt>LJ_DUALNUM</tt> builds.</li>\n  <li>Fix buffer check in bytecode writer.</li>\n  <li>Make <tt>os.date()</tt> thread-safe.</li>\n  <li>Add missing declarations for MSVC intrinsics.</li>\n  <li>Fix dispatch table modifications for return hooks.</li>\n  <li>Workaround for MSVC conversion bug (<tt>double</tt> &rarr; <tt>uint32_t</tt> &rarr; <tt>int32_t</tt>).</li>\n  <li>Fix FOLD rule <tt>(i-j)-i => 0-j</tt>.</li>\n  <li>Never use DWARF unwinder on Windows.</li>\n  <li>Fix shrinking of direct mapped blocks in builtin allocator.</li>\n  <li>Limit recursion depth in <tt>string.match()</tt> et al.</li>\n  <li>Fix late despecialization of <tt>ITERN</tt> after loop has been entered.</li>\n  <li>Fix <tt>'f'</tt> and <tt>'L'</tt> options for <tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt>.</li>\n  <li>Fix <tt>package.searchpath()</tt>.</li>\n  <li>OSX: Change dylib names to be consistent with other platforms.</li>\n  <li>Android: Workaround for broken <tt>sprintf(\"%g\",&nbsp;-0.0)</tt>.</li>\n  <li>x86: Remove support for ancient CPUs without <tt>CMOV</tt> (before Pentium Pro).</li>\n  <li>x86: Fix register allocation for calls returning register pair.</li>\n  <li>x86/x64: Fix fusion of unsigned byte comparisons with swapped operands.</li>\n  <li>ARM: Fix <tt>tonumber()</tt> argument check.</li>\n  <li>ARM: Fix modulo operator and <tt>math.floor()</tt>/<tt>math.ceil()</tt> for <tt>inf</tt>/<tt>nan</tt>.</li>\n  <li>ARM: Invoke SPLIT pass for leftover <tt>IR_TOBIT</tt>.</li>\n  <li>ARM: Fix BASE register coalescing.</li>\n  <li>PPC: Fix interpreter state setup in callbacks.</li>\n  <li>PPC: Fix <tt>string.sub()</tt> range check.</li>\n  <li>MIPS: Support generation of MIPS/MIPSEL bytecode object files.</li>\n  <li>MIPS: Fix calls to <tt>floor()</tt>/<tt>ceil()</tt><tt>/trunc()</tt>.</li>\n  <li>ARM/PPC: Detect more target architecture variants.</li>\n  <li>ARM/PPC/e500/MIPS: Fix tailcalls from fast functions, esp. <tt>tostring()</tt>.</li>\n  <li>ARM/PPC/MIPS: Fix rematerialization of FP constants.</li>\n  <li>FFI: Don't call <tt>FreeLibrary()</tt> on our own EXE/DLL.</li>\n  <li>FFI: Resolve metamethods for constructors, too.</li>\n  <li>FFI: Properly disable callbacks on iOS (would require executable memory).</li>\n  <li>FFI: Fix cdecl string parsing during recording.</li>\n  <li>FFI: Show address pointed to for <tt>tostring(ref)</tt>, too.</li>\n  <li>FFI: Fix alignment of C call argument/return structure.</li>\n  <li>FFI: Initialize all fields of standard types.</li>\n  <li>FFI: Fix callback handling when new C&nbsp;types are declared in callback.</li>\n  <li>FFI: Fix recording of constructors for pointers.</li>\n  <li>FFI: Always resolve metamethods for pointers to structs.</li>\n  <li>FFI: Correctly propagate alignment when interning nested types.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n  <li>Add allocation sinking and store sinking optimization.</li>\n  <li>Constify immutable upvalues.</li>\n  <li>Add builtin string to integer or FP number conversion. Improves cross-platform consistency and correctness.</li>\n  <li>Create string hash slots in template tables for non-const values, too. Avoids later table resizes.</li>\n  <li>Eliminate <tt>HREFK</tt> guard for template table references.</li>\n  <li>Add various new FOLD rules.</li>\n  <li>Don't use stack unwinding for <tt>lua_yield()</tt> (slow on x64).</li>\n  <li>ARM, PPC, MIPS: Improve <tt>XLOAD</tt> operand fusion and register hinting.</li>\n  <li>PPC, MIPS: Compile <tt>math.sqrt()</tt> to sqrt instruction, if available.</li>\n  <li>FFI: Fold <tt>KPTR</tt> + constant offset in SPLIT pass.</li>\n  <li>FFI: Optimize/inline <tt>ffi.copy()</tt> and <tt>ffi.fill()</tt>.</li>\n  <li>FFI: Compile and optimize array/struct copies.</li>\n  <li>FFI: Compile <tt>ffi.typeof(cdata|ctype)</tt>, <tt>ffi.sizeof()</tt>, <tt>ffi.alignof()</tt>, <tt>ffi.offsetof()</tt> and <tt>ffi.gc()</tt>.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta10\">LuaJIT 2.0.0-beta10 &mdash; 2012-05-09</h2>\n<ul>\n<li>New features:\n<ul>\n<li>The MIPS of LuaJIT is complete. It requires a CPU conforming to the\nMIPS32&nbsp;R1 architecture with hardware FPU. O32 hard-fp ABI,\nlittle-endian or big-endian.</li>\n<li>Auto-detect target arch via cross-compiler. No need for\n<tt>TARGET=arch</tt> anymore.</li>\n<li>Make DynASM compatible with Lua 5.2.</li>\n<li>From Lua 5.2: Try <tt>__tostring</tt> metamethod on non-string error\nmessages..</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix parsing of hex literals with exponents.</li>\n<li>Fix bytecode dump for certain number constants.</li>\n<li>Fix argument type in error message for relative arguments.</li>\n<li>Fix argument error handling on Lua stacks without a frame.</li>\n<li>Add missing mcode limit check in assembler backend.</li>\n<li>Fix compilation on OpenBSD.</li>\n<li>Avoid recursive GC steps after GC-triggered trace exit.</li>\n<li>Replace <tt>&lt;unwind.h&gt;</tt> definitions with our own.</li>\n<li>Fix OSX build issues. Bump minimum required OSX version to 10.4.</li>\n<li>Fix discharge order of comparisons in Lua parser.</li>\n<li>Ensure running <tt>__gc</tt> of userdata created in <tt>__gc</tt>\nat state close.</li>\n<li>Limit number of userdata <tt>__gc</tt> separations at state close.</li>\n<li>Fix bytecode <tt>JMP</tt> slot range when optimizing\n<tt>and</tt>/<tt>or</tt> with constant LHS.</li>\n<li>Fix DSE of <tt>USTORE</tt>.</li>\n<li>Make <tt>lua_concat()</tt> work from C&nbsp;hook with partial frame.</li>\n<li>Add required PHIs for implicit conversions, e.g. via <tt>XREF</tt>\nforwarding.</li>\n<li>Add more comparison variants to Valgrind suppressions file.</li>\n<li>Disable loading bytecode with an extra header (BOM or <tt>#!</tt>).</li>\n<li>Fix PHI stack slot syncing.</li>\n<li>ARM: Reorder type/value tests to silence Valgrind.</li>\n<li>ARM: Fix register allocation for <tt>ldrd</tt>-optimized\n<tt>HREFK</tt>.</li>\n<li>ARM: Fix conditional branch fixup for <tt>OBAR</tt>.</li>\n<li>ARM: Invoke SPLIT pass for <tt>double</tt> args in FFI call.</li>\n<li>ARM: Handle all <tt>CALL*</tt> ops with <tt>double</tt> results in\nSPLIT pass.</li>\n<li>ARM: Fix rejoin of <tt>POW</tt> in SPLIT pass.</li>\n<li>ARM: Fix compilation of <tt>math.sinh</tt>, <tt>math.cosh</tt>,\n<tt>math.tanh</tt>.</li>\n<li>ARM, PPC: Avoid pointless arg clearing in <tt>BC_IFUNCF</tt>.</li>\n<li>PPC: Fix resume after yield from hook.</li>\n<li>PPC: Fix argument checking for <tt>rawget()</tt>.</li>\n<li>PPC: Fix fusion of floating-point <tt>XLOAD</tt>/<tt>XSTORE</tt>.</li>\n<li>PPC: Fix <tt>HREFK</tt> code generation for huge tables.</li>\n<li>PPC: Use builtin D-Cache/I-Cache sync code.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Ignore empty statements in <tt>ffi.cdef()</tt>.</li>\n<li>Ignore number parsing errors while skipping definitions.</li>\n<li>Don't touch frame in callbacks with tailcalls to fast functions.</li>\n<li>Fix library unloading on POSIX systems.</li>\n<li>Finalize cdata before userdata when closing the state.</li>\n<li>Change <tt>ffi.load()</tt> library name resolution for Cygwin.</li>\n<li>Fix resolving of function name redirects on Windows/x86.</li>\n<li>Fix symbol resolving error messages on Windows.</li>\n<li>Fix blacklisting of C functions calling callbacks.</li>\n<li>Fix result type of pointer difference.</li>\n<li>Use correct PC in FFI metamethod error message.</li>\n<li>Allow <tt>'typedef _Bool int BOOL;'</tt> for the Windows API.</li>\n<li>Don't record test for bool result of call, if ignored.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta9\">LuaJIT 2.0.0-beta9 &mdash; 2011-12-14</h2>\n<ul>\n<li>New features:\n<ul>\n<li>PPC port of LuaJIT is complete. Default is the dual-number port\n(usually faster). Single-number port selectable via <tt>src/Makefile</tt>\nat build time.</li>\n<li>Add FFI callback support.</li>\n<li>Extend <tt>-b</tt> to generate <tt>.c</tt>, <tt>.h</tt> or <tt>.obj/.o</tt>\nfiles with embedded bytecode.</li>\n<li>Allow loading embedded bytecode with <tt>require()</tt>.</li>\n<li>From Lua 5.2: Change to <tt>'\\z'</tt> escape. Reject undefined escape\nsequences.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix OSX 10.7 build. Fix <tt>install_name</tt> and versioning on OSX.</li>\n<li>Fix iOS build.</li>\n<li>Install <tt>dis_arm.lua</tt>, too.</li>\n<li>Mark installed shared library as executable.</li>\n<li>Add debug option to <tt>msvcbuild.bat</tt> and improve error handling.</li>\n<li>Fix data-flow analysis for iterators.</li>\n<li>Fix forced unwinding triggered by external unwinder.</li>\n<li>Record missing <tt>for</tt> loop slot loads (return to lower frame).</li>\n<li>Always use ANSI variants of Windows system functions.</li>\n<li>Fix GC barrier for multi-result table constructor (<tt>TSETM</tt>).</li>\n<li>Fix/add various FOLD rules.</li>\n<li>Add potential PHI for number conversions due to type instability.</li>\n<li>Do not eliminate PHIs only referenced from other PHIs.</li>\n<li>Correctly anchor implicit number to string conversions in Lua/C API.</li>\n<li>Fix various stack limit checks.</li>\n<li>x64: Use thread-safe exceptions for external unwinding (GCC platforms).</li>\n<li>x64: Fix result type of cdata index conversions.</li>\n<li>x64: Fix <tt>math.random()</tt> and <tt>bit.bswap()</tt> code generation.</li>\n<li>x64: Fix <tt>lightuserdata</tt> comparisons.</li>\n<li>x64: Always extend stack-passed arguments to pointer size.</li>\n<li>ARM: Many fixes to code generation backend.</li>\n<li>PPC/e500: Fix dispatch for binop metamethods.</li>\n<li>PPC/e500: Save/restore condition registers when entering/leaving the VM.</li>\n<li>PPC/e500: Fix write barrier in stores of strings to upvalues.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Fix C comment parsing.</li>\n<li>Fix snapshot optimization for cdata comparisons.</li>\n<li>Fix recording of const/enum lookups in namespaces.</li>\n<li>Fix call argument and return handling for <tt>I8/U8/I16/U16</tt> types.</li>\n<li>Fix unfused loads of float fields.</li>\n<li>Fix <tt>ffi.string()</tt> recording.</li>\n<li>Save <tt>GetLastError()</tt> around <tt>ffi.load()</tt> and symbol\nresolving, too.</li>\n<li>Improve ld script detection in <tt>ffi.load()</tt>.</li>\n<li>Record loads/stores to external variables in namespaces.</li>\n<li>Compile calls to stdcall, fastcall and vararg functions.</li>\n<li>Treat function ctypes like pointers in comparisons.</li>\n<li>Resolve <tt>__call</tt> metamethod for pointers, too.</li>\n<li>Record C function calls with bool return values.</li>\n<li>Record <tt>ffi.errno()</tt>.</li>\n<li>x86: Fix number to <tt>uint32_t</tt> conversion rounding.</li>\n<li>x86: Fix 64 bit arithmetic in assembler backend.</li>\n<li>x64: Fix struct-by-value calling conventions.</li>\n<li>ARM: Ensure invocation of SPLIT pass for float conversions.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Display trace types with <tt>-jv</tt> and <tt>-jdump</tt>.</li>\n<li>Record isolated calls. But prefer recording loops over calls.</li>\n<li>Specialize to prototype for non-monomorphic functions. Solves the\ntrace-explosion problem for closure-heavy programming styles.</li>\n<li>Always generate a portable <tt>vmdef.lua</tt>. Easier for distros.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta8\">LuaJIT 2.0.0-beta8 &mdash; 2011-06-23</h2>\n<ul>\n<li>New features:\n<ul>\n<li>Soft-float ARM port of LuaJIT is complete.</li>\n<li>Add support for bytecode loading/saving and <tt>-b</tt> command line\noption.</li>\n<li>From Lua 5.2: <tt>__len</tt> metamethod for tables\n(disabled by default).</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>ARM: Misc. fixes for interpreter.</li>\n<li>x86/x64: Fix <tt>bit.*</tt> argument checking in interpreter.</li>\n<li>Catch early out-of-memory in memory allocator initialization.</li>\n<li>Fix data-flow analysis for paths leading to an upvalue close.</li>\n<li>Fix check for missing arguments in <tt>string.format()</tt>.</li>\n<li>Fix Solaris/x86 build (note: not a supported target).</li>\n<li>Fix recording of loops with instable directions in side traces.</li>\n<li>x86/x64: Fix fusion of comparisons with <tt>u8</tt>/<tt>u16</tt>\n<tt>XLOAD</tt>.</li>\n<li>x86/x64: Fix register allocation for variable shifts.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Add <tt>ffi.errno()</tt>. Save <tt>errno</tt>/<tt>GetLastError()</tt>\naround allocations etc.</li>\n<li>Fix <tt>__gc</tt> for VLA/VLS cdata objects.</li>\n<li>Fix recording of casts from 32 bit cdata pointers to integers.</li>\n<li><tt>tonumber(cdata)</tt> returns <tt>nil</tt> for non-numbers.</li>\n<li>Show address pointed to for <tt>tostring(pointer)</tt>.</li>\n<li>Print <tt>NULL</tt> pointers as <tt>\"cdata&lt;... *&gt;: NULL\"</tt>.</li>\n<li>Support <tt>__tostring</tt> metamethod for pointers to structs, too.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>More tuning for loop unrolling heuristics.</li>\n<li>Flatten and compress in-memory debug info (saves ~70%).</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta7\">LuaJIT 2.0.0-beta7 &mdash; 2011-05-05</h2>\n<ul>\n<li>New features:\n<ul>\n<li>ARM port of the LuaJIT interpreter is complete.</li>\n<li>FFI library: Add <tt>ffi.gc()</tt>, <tt>ffi.metatype()</tt>,\n<tt>ffi.istype()</tt>.</li>\n<li>FFI library: Resolve ld script redirection in <tt>ffi.load()</tt>.</li>\n<li>From Lua 5.2: <tt>package.searchpath()</tt>, <tt>fp:read(\"*L\")</tt>,\n<tt>load(string)</tt>.</li>\n<li>From Lua 5.2, disabled by default: empty statement,\n<tt>table.unpack()</tt>, modified <tt>coroutine.running()</tt>.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>FFI library: numerous fixes.</li>\n<li>Fix type mismatches in store-to-load forwarding.</li>\n<li>Fix error handling within metamethods.</li>\n<li>Fix <tt>table.maxn()</tt>.</li>\n<li>Improve accuracy of <tt>x^-k</tt> on x64.</li>\n<li>Fix code generation for Intel Atom in x64 mode.</li>\n<li>Fix narrowing of POW.</li>\n<li>Fix recording of retried fast functions.</li>\n<li>Fix code generation for <tt>bit.bnot()</tt> and multiplies.</li>\n<li>Fix error location within cpcall frames.</li>\n<li>Add workaround for old libgcc unwind bug.</li>\n<li>Fix <tt>lua_yield()</tt> and <tt>getmetatable(lightuserdata)</tt> on x64.</li>\n<li>Misc. fixes for PPC/e500 interpreter.</li>\n<li>Fix stack slot updates for down-recursion.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Add dual-number mode (int/double) for the VM. Enabled for ARM.</li>\n<li>Improve narrowing of arithmetic operators and <tt>for</tt> loops.</li>\n<li>Tune loop unrolling heuristics and increase trace recorder limits.</li>\n<li>Eliminate dead slots in snapshots using bytecode data-flow analysis.</li>\n<li>Avoid phantom stores to proxy tables.</li>\n<li>Optimize lookups in empty proxy tables.</li>\n<li>Improve bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta6\">LuaJIT 2.0.0-beta6 &mdash; 2011-02-11</h2>\n<ul>\n<li>New features:\n<ul>\n<li>PowerPC/e500v2 port of the LuaJIT interpreter is complete.</li>\n<li>Various minor features from Lua 5.2: Hex escapes in literals,\n<tt>'\\*'</tt> escape, reversible <tt>string.format(\"%q\",s)</tt>,\n<tt>\"%g\"</tt> pattern, <tt>table.sort</tt> checks callbacks,\n<tt>os.exit(status|true|false[,close])</tt>.</li>\n<li>Lua 5.2 <tt>__pairs</tt> and <tt>__ipairs</tt> metamethods\n(disabled by default).</li>\n<li>Initial release of the FFI library.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix <tt>string.format()</tt> for non-finite numbers.</li>\n<li>Fix memory leak when compiled to use the built-in allocator.</li>\n<li>x86/x64: Fix unnecessary resize in <tt>TSETM</tt> bytecode.</li>\n<li>Fix various GC issues with traces and <tt>jit.flush()</tt>.</li>\n<li>x64: Fix fusion of indexes for array references.</li>\n<li>x86/x64: Fix stack overflow handling for coroutine results.</li>\n<li>Enable low-2GB memory allocation on FreeBSD/x64.</li>\n<li>Fix <tt>collectgarbage(\"count\")</tt> result if more than 2GB is in use.</li>\n<li>Fix parsing of hex floats.</li>\n<li>x86/x64: Fix loop branch inversion with trailing\n<tt>HREF+NE/EQ</tt>.</li>\n<li>Add <tt>jit.os</tt> string.</li>\n<li><tt>coroutine.create()</tt> permits running C functions, too.</li>\n<li>Fix OSX build to work with newer ld64 versions.</li>\n<li>Fix bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Emit specialized bytecode for <tt>pairs()</tt>/<tt>next()</tt>.</li>\n<li>Improve bytecode coalescing of <tt>nil</tt> constants.</li>\n<li>Compile calls to vararg functions.</li>\n<li>Compile <tt>select()</tt>.</li>\n<li>Improve alias analysis, esp. for loads from allocations.</li>\n<li>Tuning of various compiler heuristics.</li>\n<li>Refactor and extend IR conversion instructions.</li>\n<li>x86/x64: Various backend enhancements related to the FFI.</li>\n<li>Add SPLIT pass to split 64 bit IR instructions for 32 bit CPUs.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta5\">LuaJIT 2.0.0-beta5 &mdash; 2010-08-24</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n<li>Fix trace exit dispatch to function headers.</li>\n<li>Fix Windows and OSX builds with LUAJIT_DISABLE_JIT.</li>\n<li>Reorganize and fix placement of generated machine code on x64.</li>\n<li>Fix TNEW in x64 interpreter.</li>\n<li>Do not eliminate PHIs for values only referenced from side exits.</li>\n<li>OS-independent canonicalization of strings for non-finite numbers.</li>\n<li>Fix <tt>string.char()</tt> range check on x64.</li>\n<li>Fix <tt>tostring()</tt> resolving within <tt>print()</tt>.</li>\n<li>Fix error handling for <tt>next()</tt>.</li>\n<li>Fix passing of constant arguments to external calls on x64.</li>\n<li>Fix interpreter argument check for two-argument SSE math functions.</li>\n<li>Fix C frame chain corruption caused by <tt>lua_cpcall()</tt>.</li>\n<li>Fix return from <tt>pcall()</tt> within active hook.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Replace on-trace GC frame syncing with interpreter exit.</li>\n<li>Improve hash lookup specialization by not removing dead keys during GC.</li>\n<li>Turn traces into true GC objects.</li>\n<li>Avoid starting a GC cycle immediately after library init.</li>\n<li>Add weak guards to improve dead-code elimination.</li>\n<li>Speed up string interning.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta4\">LuaJIT 2.0.0-beta4 &mdash; 2010-03-28</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n<li>Fix precondition for on-trace creation of table keys.</li>\n<li>Fix <tt>{f()}</tt> on x64 when table is resized.</li>\n<li>Fix folding of ordered comparisons with same references.</li>\n<li>Fix snapshot restores for multi-result bytecodes.</li>\n<li>Fix potential hang when recording bytecode with nested closures.</li>\n<li>Fix recording of <tt>getmetatable()</tt>, <tt>tonumber()</tt> and bad argument types.</li>\n<li>Fix SLOAD fusion across returns to lower frames.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Add array bounds check elimination. <tt>-Oabc</tt> is enabled by default.</li>\n<li>More tuning for x64, e.g. smaller table objects.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta3\">LuaJIT 2.0.0-beta3 &mdash; 2010-03-07</h2>\n<ul>\n<li>LuaJIT x64 port:\n<ul>\n<li>Port integrated memory allocator to Linux/x64, Windows/x64 and OSX/x64.</li>\n<li>Port interpreter and JIT compiler to x64.</li>\n<li>Port DynASM to x64.</li>\n<li>Many 32/64 bit cleanups in the VM.</li>\n<li>Allow building the interpreter with either x87 or SSE2 arithmetics.</li>\n<li>Add external unwinding and C++ exception interop (default on x64).</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix constructor bytecode generation for certain conditional values.</li>\n<li>Fix some cases of ordered string comparisons.</li>\n<li>Fix <tt>lua_tocfunction()</tt>.</li>\n<li>Fix cutoff register in JMP bytecode for some conditional expressions.</li>\n<li>Fix PHI marking algorithm for references from variant slots.</li>\n<li>Fix <tt>package.cpath</tt> for non-default PREFIX.</li>\n<li>Fix DWARF2 frame unwind information for interpreter on OSX.</li>\n<li>Drive the GC forward on string allocations in the parser.</li>\n<li>Implement call/return hooks (zero-cost if disabled).</li>\n<li>Implement yield from C hooks.</li>\n<li>Disable JIT compiler on older non-SSE2 CPUs instead of aborting.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Compile recursive code (tail-, up- and down-recursion).</li>\n<li>Improve heuristics for bytecode penalties and blacklisting.</li>\n<li>Split CALL/FUNC recording and clean up fast function call semantics.</li>\n<li>Major redesign of internal function call handling.</li>\n<li>Improve FOR loop const specialization and integerness checks.</li>\n<li>Switch to pre-initialized stacks. Avoid frame-clearing.</li>\n<li>Colocation of prototypes and related data: bytecode, constants, debug info.</li>\n<li>Cleanup parser and streamline bytecode generation.</li>\n<li>Add support for weak IR references to register allocator.</li>\n<li>Switch to compressed, extensible snapshots.</li>\n<li>Compile returns to frames below the start frame.</li>\n<li>Improve alias analysis of upvalues using a disambiguation hash value.</li>\n<li>Compile floor/ceil/trunc to SSE2 helper calls or SSE4.1 instructions.</li>\n<li>Add generic C call handling to IR and backend.</li>\n<li>Improve KNUM fuse vs. load heuristics.</li>\n<li>Compile various <tt>io.*()</tt> functions.</li>\n<li>Compile <tt>math.sinh()</tt>, <tt>math.cosh()</tt>, <tt>math.tanh()</tt>\nand <tt>math.random()</tt>.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta2\">LuaJIT 2.0.0-beta2 &mdash; 2009-11-09</h2>\n<ul>\n<li>Reorganize build system. Build static+shared library on POSIX.</li>\n<li>Allow C++ exception conversion on all platforms\nusing a wrapper function.</li>\n<li>Automatically catch C++ exceptions and rethrow Lua error\n(DWARF2 only).</li>\n<li>Check for the correct x87 FPU precision at strategic points.</li>\n<li>Always use wrappers for libm functions.</li>\n<li>Resurrect metamethod name strings before copying them.</li>\n<li>Mark current trace, even if compiler is idle.</li>\n<li>Ensure FILE metatable is created only once.</li>\n<li>Fix type comparisons when different integer types are involved.</li>\n<li>Fix <tt>getmetatable()</tt> recording.</li>\n<li>Fix TDUP with dead keys in template table.</li>\n<li><tt>jit.flush(tr)</tt> returns status.\nPrevent manual flush of a trace that's still linked.</li>\n<li>Improve register allocation heuristics for invariant references.</li>\n<li>Compile the push/pop variants of <tt>table.insert()</tt> and\n<tt>table.remove()</tt>.</li>\n<li>Compatibility with MSVC <tt>link&nbsp/debug</tt>.</li>\n<li>Fix <tt>lua_iscfunction()</tt>.</li>\n<li>Fix <tt>math.random()</tt> when compiled with <tt>-fpic</tt> (OSX).</li>\n<li>Fix <tt>table.maxn()</tt>.</li>\n<li>Bump <tt>MACOSX_DEPLOYMENT_TARGET</tt> to <tt>10.4</tt></li>\n<li><tt>luaL_check*()</tt> and <tt>luaL_opt*()</tt> now support\nnegative arguments, too.<br>\nThis matches the behavior of Lua 5.1, but not the specification.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta1\">LuaJIT 2.0.0-beta1 &mdash; 2009-10-31</h2>\n<ul>\n<li>This is the first public release of LuaJIT 2.0.</li>\n<li>The whole VM has been rewritten from the ground up, so there's\nno point in listing differences over earlier versions.</li>\n</ul>\n</div>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/contact.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Contact</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Contact</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nPlease send general questions to the\n<a href=\"http://luajit.org/list.html\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT mailing list</a>.\nYou can also send any questions you have directly to me:\n</p>\n\n<script type=\"text/javascript\">\n<!--\nvar xS=\"@-:\\\" .0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<abc>defghijklmnopqrstuvwxyz\";function xD(s)\n{var len=s.length;var r=\"\";for(var i=0;i<len;i++)\n{var c=s.charAt(i);var n=xS.indexOf(c);if(n!=-1)c=xS.charAt(69-n);r+=c;}\ndocument.write(\"<\"+\"p>\"+r+\"<\"+\"/p>\\n\");}\n//-->\n</script>\n<script type=\"text/javascript\">\n<!--\nxD(\"fyZKB8xv\\\"FJytmz8.KAB0u52D\")\n//--></script>\n<noscript>\n<p><img src=\"img/contact.png\" alt=\"Contact info in image\" width=\"170\" height=\"13\">\n</p>\n</noscript>\n\n<h2>Copyright</h2>\n<p>\nAll documentation is\nCopyright &copy; 2005-2016 Mike Pall.\n</p>\n\n\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_c_api.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Lua/C API Extensions</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Lua/C API Extensions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a class=\"current\" href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT adds some extensions to the standard Lua/C API. The LuaJIT include\ndirectory must be in the compiler search path (<tt>-I<i>path</i></tt>)\nto be able to include the required header for C code:\n</p>\n<pre class=\"code\">\n#include \"luajit.h\"\n</pre>\n<p>\nOr for C++ code:\n</p>\n<pre class=\"code\">\n#include \"lua.hpp\"\n</pre>\n\n<h2 id=\"luaJIT_setmode\"><tt>luaJIT_setmode(L, idx, mode)</tt>\n&mdash; Control VM</h2>\n<p>\nThis is a C API extension to allow control of the VM from C code. The\nfull prototype of <tt>LuaJIT_setmode</tt> is:\n</p>\n<pre class=\"code\">\nLUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);\n</pre>\n<p>\nThe returned status is either success (<tt>1</tt>) or failure (<tt>0</tt>).\nThe second argument is either <tt>0</tt> or a stack index (similar to the\nother Lua/C API functions).\n</p>\n<p>\nThe third argument specifies the mode, which is 'or'ed with a flag.\nThe flag can be <tt>LUAJIT_MODE_OFF</tt> to turn a feature on,\n<tt>LUAJIT_MODE_ON</tt> to turn a feature off, or\n<tt>LUAJIT_MODE_FLUSH</tt> to flush cached code.\n</p>\n<p>\nThe following modes are defined:\n</p>\n\n<h3 id=\"mode_engine\"><tt>luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|flag)</tt></h3>\n<p>\nTurn the whole JIT compiler on or off or flush the whole cache of compiled code.\n</p>\n\n<h3 id=\"mode_func\"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_FUNC|flag)</tt><br>\n<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLFUNC|flag)</tt><br>\n<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLSUBFUNC|flag)</tt></h3>\n<p>\nThis sets the mode for the function at the stack index <tt>idx</tt> or\nthe parent of the calling function (<tt>idx = 0</tt>). It either\nenables JIT compilation for a function, disables it and flushes any\nalready compiled code or only flushes already compiled code. This\napplies recursively to all sub-functions of the function with\n<tt>LUAJIT_MODE_ALLFUNC</tt> or only to the sub-functions with\n<tt>LUAJIT_MODE_ALLSUBFUNC</tt>.\n</p>\n\n<h3 id=\"mode_trace\"><tt>luaJIT_setmode(L, trace,<br>\n&nbsp;&nbsp;LUAJIT_MODE_TRACE|LUAJIT_MODE_FLUSH)</tt></h3>\n<p>\nFlushes the specified root trace and all of its side traces from the cache.\nThe code for the trace will be retained as long as there are any other\ntraces which link to it.\n</p>\n\n<h3 id=\"mode_wrapcfunc\"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</tt></h3>\n<p>\nThis mode defines a wrapper function for calls to C functions. If\ncalled with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt>\nmust be a <tt>lightuserdata</tt> object holding a pointer to the wrapper\nfunction. From now on all C functions are called through the wrapper\nfunction. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned\noff and all C functions are directly called.\n</p>\n<p>\nThe wrapper function can be used for debugging purposes or to catch\nand convert foreign exceptions. But please read the section on\n<a href=\"extensions.html#exceptions\">C++&nbsp;exception interoperability</a>\nfirst. Recommended usage can be seen in this C++ code excerpt:\n</p>\n<pre class=\"code\">\n#include &lt;exception&gt;\n#include \"lua.hpp\"\n\n// Catch C++ exceptions and convert them to Lua error messages.\n// Customize as needed for your own exception classes.\nstatic int wrap_exceptions(lua_State *L, lua_CFunction f)\n{\n  try {\n    return f(L);  // Call wrapped function and return result.\n  } catch (const char *s) {  // Catch and convert exceptions.\n    lua_pushstring(L, s);\n  } catch (std::exception& e) {\n    lua_pushstring(L, e.what());\n  } catch (...) {\n    lua_pushliteral(L, \"caught (...)\");\n  }\n  return lua_error(L);  // Rethrow as a Lua error.\n}\n\nstatic int myinit(lua_State *L)\n{\n  ...\n  // Define wrapper function and enable it.\n  lua_pushlightuserdata(L, (void *)wrap_exceptions);\n  luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);\n  lua_pop(L, 1);\n  ...\n}\n</pre>\n<p>\nNote that you can only define <b>a single global wrapper function</b>,\nso be careful when using this mechanism from multiple C++ modules.\nAlso note that this mechanism is not without overhead.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_ffi.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>FFI Library</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Library</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a class=\"current\" href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\n\nThe FFI library allows <b>calling external C&nbsp;functions</b> and\n<b>using C&nbsp;data structures</b> from pure Lua code.\n\n</p>\n<p>\n\nThe FFI library largely obviates the need to write tedious manual\nLua/C bindings in C. No need to learn a separate binding language\n&mdash; <b>it parses plain C&nbsp;declarations!</b> These can be\ncut-n-pasted from C&nbsp;header files or reference manuals. It's up to\nthe task of binding large libraries without the need for dealing with\nfragile binding generators.\n\n</p>\n<p>\nThe FFI library is tightly integrated into LuaJIT (it's not available\nas a separate module). The code generated by the JIT-compiler for\naccesses to C&nbsp;data structures from Lua code is on par with the\ncode a C&nbsp;compiler would generate. Calls to C&nbsp;functions can\nbe inlined in JIT-compiled code, unlike calls to functions bound via\nthe classic Lua/C API.\n</p>\n<p>\nThis page gives a short introduction to the usage of the FFI library.\n<em>Please use the FFI sub-topics in the navigation bar to learn more.</em>\n</p>\n\n<h2 id=\"call\">Motivating Example: Calling External C Functions</h2>\n<p>\nIt's really easy to call an external C&nbsp;library function:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&#9312;\n&#9313;\n\n\n&#9314;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">int printf(const char *fmt, ...);</span>\n]]\nffi.C.printf(\"Hello %s!\", \"world\")\n</pre>\n<p>\nSo, let's pick that apart:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> Load the FFI library.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> Add a C&nbsp;declaration\nfor the function. The part inside the double-brackets (in green) is\njust standard C&nbsp;syntax.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Call the named\nC&nbsp;function &mdash; Yes, it's that simple!\n</p>\n<p style=\"font-size: 8pt;\">\nActually, what goes on behind the scenes is far from simple: <span\nstyle=\"color:#4040c0;\">&#9314;</span> makes use of the standard\nC&nbsp;library namespace <tt>ffi.C</tt>. Indexing this namespace with\na symbol name (<tt>\"printf\"</tt>) automatically binds it to the\nstandard C&nbsp;library. The result is a special kind of object which,\nwhen called, runs the <tt>printf</tt> function. The arguments passed\nto this function are automatically converted from Lua objects to the\ncorresponding C&nbsp;types.\n</p>\n<p>\nOk, so maybe the use of <tt>printf()</tt> wasn't such a spectacular\nexample. You could have done that with <tt>io.write()</tt> and\n<tt>string.format()</tt>, too. But you get the idea ...\n</p>\n<p>\nSo here's something to pop up a message box on Windows:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">int MessageBoxA(void *w, const char *txt, const char *cap, int type);</span>\n]]\nffi.C.MessageBoxA(nil, \"Hello world!\", \"Test\", 0)\n</pre>\n<p>\nBing! Again, that was far too easy, no?\n</p>\n<p style=\"font-size: 8pt;\">\nCompare this with the effort required to bind that function using the\nclassic Lua/C API: create an extra C&nbsp;file, add a C&nbsp;function\nthat retrieves and checks the argument types passed from Lua and calls\nthe actual C&nbsp;function, add a list of module functions and their\nnames, add a <tt>luaopen_*</tt> function and register all module\nfunctions, compile and link it into a shared library (DLL), move it to\nthe proper path, add Lua code that loads the module aaaand ... finally\ncall the binding function. Phew!\n</p>\n\n<h2 id=\"cdata\">Motivating Example: Using C Data Structures</h2>\n<p>\nThe FFI library allows you to create and access C&nbsp;data\nstructures. Of course the main use for this is for interfacing with\nC&nbsp;functions. But they can be used stand-alone, too.\n</p>\n<p>\nLua is built upon high-level data types. They are flexible, extensible\nand dynamic. That's why we all love Lua so much. Alas, this can be\ninefficient for certain tasks, where you'd really want a low-level\ndata type. E.g. a large array of a fixed structure needs to be\nimplemented with a big table holding lots of tiny tables. This imposes\nboth a substantial memory overhead as well as a performance overhead.\n</p>\n<p>\nHere's a sketch of a library that operates on color images plus a\nsimple benchmark. First, the plain Lua version:\n</p>\n<pre class=\"code\">\nlocal floor = math.floor\n\nlocal function image_ramp_green(n)\n  local img = {}\n  local f = 255/(n-1)\n  for i=1,n do\n    img[i] = { red = 0, green = floor((i-1)*f), blue = 0, alpha = 255 }\n  end\n  return img\nend\n\nlocal function image_to_grey(img, n)\n  for i=1,n do\n    local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)\n    img[i].red = y; img[i].green = y; img[i].blue = y\n  end\nend\n\nlocal N = 400*400\nlocal img = image_ramp_green(N)\nfor i=1,1000 do\n  image_to_grey(img, N)\nend\n</pre>\n<p>\nThis creates a table with 160.000 pixels, each of which is a table\nholding four number values in the range of 0-255. First an image with\na green ramp is created (1D for simplicity), then the image is\nconverted to greyscale 1000 times. Yes, that's silly, but I was in\nneed of a simple example ...\n</p>\n<p>\nAnd here's the FFI version. The modified parts have been marked in\nbold:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&#9312;\n\n\n\n\n\n&#9313;\n\n&#9314;\n&#9315;\n\n\n\n\n\n\n&#9314;\n&#9316;</span><b>local ffi = require(\"ffi\")\nffi.cdef[[\n</b><span style=\"color:#00a000;\">typedef struct { uint8_t red, green, blue, alpha; } rgba_pixel;</span><b>\n]]</b>\n\nlocal function image_ramp_green(n)\n  <b>local img = ffi.new(\"rgba_pixel[?]\", n)</b>\n  local f = 255/(n-1)\n  for i=<b>0,n-1</b> do\n    <b>img[i].green = i*f</b>\n    <b>img[i].alpha = 255</b>\n  end\n  return img\nend\n\nlocal function image_to_grey(img, n)\n  for i=<b>0,n-1</b> do\n    local y = <b>0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue</b>\n    img[i].red = y; img[i].green = y; img[i].blue = y\n  end\nend\n\nlocal N = 400*400\nlocal img = image_ramp_green(N)\nfor i=1,1000 do\n  image_to_grey(img, N)\nend\n</pre>\n<p>\nOk, so that wasn't too difficult:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> First, load the FFI\nlibrary and declare the low-level data type. Here we choose a\n<tt>struct</tt> which holds four byte fields, one for each component\nof a 4x8&nbsp;bit RGBA pixel.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> Creating the data\nstructure with <tt>ffi.new()</tt> is straightforward &mdash; the\n<tt>'?'</tt> is a placeholder for the number of elements of a\nvariable-length array.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> C&nbsp;arrays are\nzero-based, so the indexes have to run from <tt>0</tt> to\n<tt>n-1</tt>. One might want to allocate one more element instead to\nsimplify converting legacy code.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> Since <tt>ffi.new()</tt>\nzero-fills the array by default, we only need to set the green and the\nalpha fields.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> The calls to\n<tt>math.floor()</tt> can be omitted here, because floating-point\nnumbers are already truncated towards zero when converting them to an\ninteger. This happens implicitly when the number is stored in the\nfields of each pixel.\n</p>\n<p>\nNow let's have a look at the impact of the changes: first, memory\nconsumption for the image is down from 22&nbsp;Megabytes to\n640&nbsp;Kilobytes (400*400*4 bytes). That's a factor of 35x less! So,\nyes, tables do have a noticeable overhead. BTW: The original program\nwould consume 40&nbsp;Megabytes in plain Lua (on x64).\n</p>\n<p>\nNext, performance: the pure Lua version runs in 9.57 seconds (52.9\nseconds with the Lua interpreter) and the FFI version runs in 0.48\nseconds on my machine (YMMV). That's a factor of 20x faster (110x\nfaster than the Lua interpreter).\n</p>\n<p style=\"font-size: 8pt;\">\nThe avid reader may notice that converting the pure Lua version over\nto use array indexes for the colors (<tt>[1]</tt> instead of\n<tt>.red</tt>, <tt>[2]</tt> instead of <tt>.green</tt> etc.) ought to\nbe more compact and faster. This is certainly true (by a factor of\n~1.7x). Switching to a struct-of-arrays would help, too.\n</p>\n<p style=\"font-size: 8pt;\">\nHowever the resulting code would be less idiomatic and rather\nerror-prone. And it still doesn't get even close to the performance of\nthe FFI version of the code. Also, high-level data structures cannot\nbe easily passed to other C&nbsp;functions, especially I/O functions,\nwithout undue conversion penalties.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_ffi_api.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>ffi.* API Functions</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.abitable { width: 30em; line-height: 1.2; }\ntr.abihead td { font-weight: bold; }\ntd.abiparam { font-weight: bold; width: 6em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1><tt>ffi.*</tt> API Functions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a class=\"current\" href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page describes the API functions provided by the FFI library in\ndetail. It's recommended to read through the\n<a href=\"ext_ffi.html\">introduction</a> and the\n<a href=\"ext_ffi_tutorial.html\">FFI tutorial</a> first.\n</p>\n\n<h2 id=\"glossary\">Glossary</h2>\n<ul>\n<li><b>cdecl</b> &mdash; An abstract C&nbsp;type declaration (a Lua\nstring).</li>\n<li><b>ctype</b> &mdash; A C&nbsp;type object. This is a special kind of\n<b>cdata</b> returned by <tt>ffi.typeof()</tt>. It serves as a\n<b>cdata</b> <a href=\"#ffi_new\">constructor</a> when called.</li>\n<li><b>cdata</b> &mdash; A C&nbsp;data object. It holds a value of the\ncorresponding <b>ctype</b>.</li>\n<li><b>ct</b> &mdash; A C&nbsp;type specification which can be used for\nmost of the API functions. Either a <b>cdecl</b>, a <b>ctype</b> or a\n<b>cdata</b> serving as a template type.</li>\n<li><b>cb</b> &mdash; A callback object. This is a C&nbsp;data object\nholding a special function pointer. Calling this function from\nC&nbsp;code runs an associated Lua function.</li>\n<li><b>VLA</b> &mdash; A variable-length array is declared with a\n<tt>?</tt> instead of the number of elements, e.g. <tt>\"int[?]\"</tt>.\nThe number of elements (<tt>nelem</tt>) must be given when it's\n<a href=\"#ffi_new\">created</a>.</li>\n<li><b>VLS</b> &mdash; A variable-length struct is a <tt>struct</tt> C\ntype where the last element is a <b>VLA</b>. The same rules for\ndeclaration and creation apply.</li>\n</ul>\n\n<h2 id=\"decl\">Declaring and Accessing External Symbols</h2>\n<p>\nExternal symbols must be declared first and can then be accessed by\nindexing a <a href=\"ext_ffi_semantics.html#clib\">C&nbsp;library\nnamespace</a>, which automatically binds the symbol to a specific\nlibrary.\n</p>\n\n<h3 id=\"ffi_cdef\"><tt>ffi.cdef(def)</tt></h3>\n<p>\nAdds multiple C&nbsp;declarations for types or external symbols (named\nvariables or functions). <tt>def</tt> must be a Lua string. It's\nrecommended to use the syntactic sugar for string arguments as\nfollows:\n</p>\n<pre class=\"code\">\nffi.cdef[[\n<span style=\"color:#00a000;\">typedef struct foo { int a, b; } foo_t;  // Declare a struct and typedef.\nint dofoo(foo_t *f, int n);  /* Declare an external C function. */</span>\n]]\n</pre>\n<p>\nThe contents of the string (the part in green above) must be a\nsequence of\n<a href=\"ext_ffi_semantics.html#clang\">C&nbsp;declarations</a>,\nseparated by semicolons. The trailing semicolon for a single\ndeclaration may be omitted.\n</p>\n<p>\nPlease note that external symbols are only <em>declared</em>, but they\nare <em>not bound</em> to any specific address, yet. Binding is\nachieved with C&nbsp;library namespaces (see below).\n</p>\n<p style=\"color: #c00000;\">\nC&nbsp;declarations are not passed through a C&nbsp;pre-processor,\nyet. No pre-processor tokens are allowed, except for\n<tt>#pragma&nbsp;pack</tt>. Replace <tt>#define</tt> in existing\nC&nbsp;header files with <tt>enum</tt>, <tt>static&nbsp;const</tt>\nor <tt>typedef</tt> and/or pass the files through an external\nC&nbsp;pre-processor (once). Be careful not to include unneeded or\nredundant declarations from unrelated header files.\n</p>\n\n<h3 id=\"ffi_C\"><tt>ffi.C</tt></h3>\n<p>\nThis is the default C&nbsp;library namespace &mdash; note the\nuppercase <tt>'C'</tt>. It binds to the default set of symbols or\nlibraries on the target system. These are more or less the same as a\nC&nbsp;compiler would offer by default, without specifying extra link\nlibraries.\n</p>\n<p>\nOn POSIX systems, this binds to symbols in the default or global\nnamespace. This includes all exported symbols from the executable and\nany libraries loaded into the global namespace. This includes at least\n<tt>libc</tt>, <tt>libm</tt>, <tt>libdl</tt> (on Linux),\n<tt>libgcc</tt> (if compiled with GCC), as well as any exported\nsymbols from the Lua/C&nbsp;API provided by LuaJIT itself.\n</p>\n<p>\nOn Windows systems, this binds to symbols exported from the\n<tt>*.exe</tt>, the <tt>lua51.dll</tt> (i.e. the Lua/C&nbsp;API\nprovided by LuaJIT itself), the C&nbsp;runtime library LuaJIT was linked\nwith (<tt>msvcrt*.dll</tt>), <tt>kernel32.dll</tt>,\n<tt>user32.dll</tt> and <tt>gdi32.dll</tt>.\n</p>\n\n<h3 id=\"ffi_load\"><tt>clib = ffi.load(name [,global])</tt></h3>\n<p>\nThis loads the dynamic library given by <tt>name</tt> and returns\na new C&nbsp;library namespace which binds to its symbols. On POSIX\nsystems, if <tt>global</tt> is <tt>true</tt>, the library symbols are\nloaded into the global namespace, too.\n</p>\n<p>\nIf <tt>name</tt> is a path, the library is loaded from this path.\nOtherwise <tt>name</tt> is canonicalized in a system-dependent way and\nsearched in the default search path for dynamic libraries:\n</p>\n<p>\nOn POSIX systems, if the name contains no dot, the extension\n<tt>.so</tt> is appended. Also, the <tt>lib</tt> prefix is prepended\nif necessary. So <tt>ffi.load(\"z\")</tt> looks for <tt>\"libz.so\"</tt>\nin the default shared library search path.\n</p>\n<p>\nOn Windows systems, if the name contains no dot, the extension\n<tt>.dll</tt> is appended. So <tt>ffi.load(\"ws2_32\")</tt> looks for\n<tt>\"ws2_32.dll\"</tt> in the default DLL search path.\n</p>\n\n<h2 id=\"create\">Creating cdata Objects</h2>\n<p>\nThe following API functions create cdata objects (<tt>type()</tt>\nreturns <tt>\"cdata\"</tt>). All created cdata objects are\n<a href=\"ext_ffi_semantics.html#gc\">garbage collected</a>.\n</p>\n\n<h3 id=\"ffi_new\"><tt>cdata = ffi.new(ct [,nelem] [,init...])<br>\ncdata = <em>ctype</em>([nelem,] [init...])</tt></h3>\n<p>\nCreates a cdata object for the given <tt>ct</tt>. VLA/VLS types\nrequire the <tt>nelem</tt> argument. The second syntax uses a ctype as\na constructor and is otherwise fully equivalent.\n</p>\n<p>\nThe cdata object is initialized according to the\n<a href=\"ext_ffi_semantics.html#init\">rules for initializers</a>,\nusing the optional <tt>init</tt> arguments. Excess initializers cause\nan error.\n</p>\n<p>\nPerformance notice: if you want to create many objects of one kind,\nparse the cdecl only once and get its ctype with\n<tt>ffi.typeof()</tt>. Then use the ctype as a constructor repeatedly.\n</p>\n<p style=\"font-size: 8pt;\">\nPlease note that an anonymous <tt>struct</tt> declaration implicitly\ncreates a new and distinguished ctype every time you use it for\n<tt>ffi.new()</tt>. This is probably <b>not</b> what you want,\nespecially if you create more than one cdata object. Different anonymous\n<tt>structs</tt> are not considered assignment-compatible by the\nC&nbsp;standard, even though they may have the same fields! Also, they\nare considered different types by the JIT-compiler, which may cause an\nexcessive number of traces. It's strongly suggested to either declare\na named <tt>struct</tt> or <tt>typedef</tt> with <tt>ffi.cdef()</tt>\nor to create a single ctype object for an anonymous <tt>struct</tt>\nwith <tt>ffi.typeof()</tt>.\n</p>\n\n<h3 id=\"ffi_typeof\"><tt>ctype = ffi.typeof(ct)</tt></h3>\n<p>\nCreates a ctype object for the given <tt>ct</tt>.\n</p>\n<p>\nThis function is especially useful to parse a cdecl only once and then\nuse the resulting ctype object as a <a href=\"#ffi_new\">constructor</a>.\n</p>\n\n<h3 id=\"ffi_cast\"><tt>cdata = ffi.cast(ct, init)</tt></h3>\n<p>\nCreates a scalar cdata object for the given <tt>ct</tt>. The cdata\nobject is initialized with <tt>init</tt> using the \"cast\" variant of\nthe <a href=\"ext_ffi_semantics.html#convert\">C&nbsp;type conversion\nrules</a>.\n</p>\n<p>\nThis functions is mainly useful to override the pointer compatibility\nchecks or to convert pointers to addresses or vice versa.\n</p>\n\n<h3 id=\"ffi_metatype\"><tt>ctype = ffi.metatype(ct, metatable)</tt></h3>\n<p>\nCreates a ctype object for the given <tt>ct</tt> and associates it with\na metatable. Only <tt>struct</tt>/<tt>union</tt> types, complex numbers\nand vectors are allowed. Other types may be wrapped in a\n<tt>struct</tt>, if needed.\n</p>\n<p>\nThe association with a metatable is permanent and cannot be changed\nafterwards. Neither the contents of the <tt>metatable</tt> nor the\ncontents of an <tt>__index</tt> table (if any) may be modified\nafterwards. The associated metatable automatically applies to all uses\nof this type, no matter how the objects are created or where they\noriginate from. Note that pre-defined operations on types have\nprecedence (e.g. declared field names cannot be overriden).\n</p>\n<p>\nAll standard Lua metamethods are implemented. These are called directly,\nwithout shortcuts and on any mix of types. For binary operations, the\nleft operand is checked first for a valid ctype metamethod. The\n<tt>__gc</tt> metamethod only applies to <tt>struct</tt>/<tt>union</tt>\ntypes and performs an implicit <a href=\"#ffi_gc\"><tt>ffi.gc()</tt></a>\ncall during creation of an instance.\n</p>\n\n<h3 id=\"ffi_gc\"><tt>cdata = ffi.gc(cdata, finalizer)</tt></h3>\n<p>\nAssociates a finalizer with a pointer or aggregate cdata object. The\ncdata object is returned unchanged.\n</p>\n<p>\nThis function allows safe integration of unmanaged resources into the\nautomatic memory management of the LuaJIT garbage collector. Typical\nusage:\n</p>\n<pre class=\"code\">\nlocal p = ffi.gc(ffi.C.malloc(n), ffi.C.free)\n...\np = nil -- Last reference to p is gone.\n-- GC will eventually run finalizer: ffi.C.free(p)\n</pre>\n<p>\nA cdata finalizer works like the <tt>__gc</tt> metamethod for userdata\nobjects: when the last reference to a cdata object is gone, the\nassociated finalizer is called with the cdata object as an argument. The\nfinalizer can be a Lua function or a cdata function or cdata function\npointer. An existing finalizer can be removed by setting a <tt>nil</tt>\nfinalizer, e.g. right before explicitly deleting a resource:\n</p>\n<pre class=\"code\">\nffi.C.free(ffi.gc(p, nil)) -- Manually free the memory.\n</pre>\n\n<h2 id=\"info\">C&nbsp;Type Information</h2>\n<p>\nThe following API functions return information about C&nbsp;types.\nThey are most useful for inspecting cdata objects.\n</p>\n\n<h3 id=\"ffi_sizeof\"><tt>size = ffi.sizeof(ct [,nelem])</tt></h3>\n<p>\nReturns the size of <tt>ct</tt> in bytes. Returns <tt>nil</tt> if\nthe size is not known (e.g. for <tt>\"void\"</tt> or function types).\nRequires <tt>nelem</tt> for VLA/VLS types, except for cdata objects.\n</p>\n\n<h3 id=\"ffi_alignof\"><tt>align = ffi.alignof(ct)</tt></h3>\n<p>\nReturns the minimum required alignment for <tt>ct</tt> in bytes.\n</p>\n\n<h3 id=\"ffi_offsetof\"><tt>ofs [,bpos,bsize] = ffi.offsetof(ct, field)</tt></h3>\n<p>\nReturns the offset (in bytes) of <tt>field</tt> relative to the start\nof <tt>ct</tt>, which must be a <tt>struct</tt>. Additionally returns\nthe position and the field size (in bits) for bit fields.\n</p>\n\n<h3 id=\"ffi_istype\"><tt>status = ffi.istype(ct, obj)</tt></h3>\n<p>\nReturns <tt>true</tt> if <tt>obj</tt> has the C&nbsp;type given by\n<tt>ct</tt>. Returns <tt>false</tt> otherwise.\n</p>\n<p>\nC&nbsp;type qualifiers (<tt>const</tt> etc.) are ignored. Pointers are\nchecked with the standard pointer compatibility rules, but without any\nspecial treatment for <tt>void&nbsp;*</tt>. If <tt>ct</tt> specifies a\n<tt>struct</tt>/<tt>union</tt>, then a pointer to this type is accepted,\ntoo. Otherwise the types must match exactly.\n</p>\n<p>\nNote: this function accepts all kinds of Lua objects for the\n<tt>obj</tt> argument, but always returns <tt>false</tt> for non-cdata\nobjects.\n</p>\n\n<h2 id=\"util\">Utility Functions</h2>\n\n<h3 id=\"ffi_errno\"><tt>err = ffi.errno([newerr])</tt></h3>\n<p>\nReturns the error number set by the last C&nbsp;function call which\nindicated an error condition. If the optional <tt>newerr</tt> argument\nis present, the error number is set to the new value and the previous\nvalue is returned.\n</p>\n<p>\nThis function offers a portable and OS-independent way to get and set the\nerror number. Note that only <em>some</em> C&nbsp;functions set the error\nnumber. And it's only significant if the function actually indicated an\nerror condition (e.g. with a return value of <tt>-1</tt> or\n<tt>NULL</tt>). Otherwise, it may or may not contain any previously set\nvalue.\n</p>\n<p>\nYou're advised to call this function only when needed and as close as\npossible after the return of the related C&nbsp;function. The\n<tt>errno</tt> value is preserved across hooks, memory allocations,\ninvocations of the JIT compiler and other internal VM activity. The same\napplies to the value returned by <tt>GetLastError()</tt> on Windows, but\nyou need to declare and call it yourself.\n</p>\n\n<h3 id=\"ffi_string\"><tt>str = ffi.string(ptr [,len])</tt></h3>\n<p>\nCreates an interned Lua string from the data pointed to by\n<tt>ptr</tt>.\n</p>\n<p>\nIf the optional argument <tt>len</tt> is missing, <tt>ptr</tt> is\nconverted to a <tt>\"char&nbsp;*\"</tt> and the data is assumed to be\nzero-terminated. The length of the string is computed with\n<tt>strlen()</tt>.\n</p>\n<p>\nOtherwise <tt>ptr</tt> is converted to a <tt>\"void&nbsp;*\"</tt> and\n<tt>len</tt> gives the length of the data. The data may contain\nembedded zeros and need not be byte-oriented (though this may cause\nendianess issues).\n</p>\n<p>\nThis function is mainly useful to convert (temporary)\n<tt>\"const&nbsp;char&nbsp;*\"</tt> pointers returned by\nC&nbsp;functions to Lua strings and store them or pass them to other\nfunctions expecting a Lua string. The Lua string is an (interned) copy\nof the data and bears no relation to the original data area anymore.\nLua strings are 8&nbsp;bit clean and may be used to hold arbitrary,\nnon-character data.\n</p>\n<p>\nPerformance notice: it's faster to pass the length of the string, if\nit's known. E.g. when the length is returned by a C&nbsp;call like\n<tt>sprintf()</tt>.\n</p>\n\n<h3 id=\"ffi_copy\"><tt>ffi.copy(dst, src, len)<br>\nffi.copy(dst, str)</tt></h3>\n<p>\nCopies the data pointed to by <tt>src</tt> to <tt>dst</tt>.\n<tt>dst</tt> is converted to a <tt>\"void&nbsp;*\"</tt> and <tt>src</tt>\nis converted to a <tt>\"const void&nbsp;*\"</tt>.\n</p>\n<p>\nIn the first syntax, <tt>len</tt> gives the number of bytes to copy.\nCaveat: if <tt>src</tt> is a Lua string, then <tt>len</tt> must not\nexceed <tt>#src+1</tt>.\n</p>\n<p>\nIn the second syntax, the source of the copy must be a Lua string. All\nbytes of the string <em>plus a zero-terminator</em> are copied to\n<tt>dst</tt> (i.e. <tt>#src+1</tt> bytes).\n</p>\n<p>\nPerformance notice: <tt>ffi.copy()</tt> may be used as a faster\n(inlinable) replacement for the C&nbsp;library functions\n<tt>memcpy()</tt>, <tt>strcpy()</tt> and <tt>strncpy()</tt>.\n</p>\n\n<h3 id=\"ffi_fill\"><tt>ffi.fill(dst, len [,c])</tt></h3>\n<p>\nFills the data pointed to by <tt>dst</tt> with <tt>len</tt> constant\nbytes, given by <tt>c</tt>. If <tt>c</tt> is omitted, the data is\nzero-filled.\n</p>\n<p>\nPerformance notice: <tt>ffi.fill()</tt> may be used as a faster\n(inlinable) replacement for the C&nbsp;library function\n<tt>memset(dst,&nbsp;c,&nbsp;len)</tt>. Please note the different\norder of arguments!\n</p>\n\n<h2 id=\"target\">Target-specific Information</h2>\n\n<h3 id=\"ffi_abi\"><tt>status = ffi.abi(param)</tt></h3>\n<p>\nReturns <tt>true</tt> if <tt>param</tt> (a Lua string) applies for the\ntarget ABI (Application Binary Interface). Returns <tt>false</tt>\notherwise. The following parameters are currently defined:\n</p>\n<table class=\"abitable\">\n<tr class=\"abihead\">\n<td class=\"abiparam\">Parameter</td>\n<td class=\"abidesc\">Description</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">32bit</td><td class=\"abidesc\">32 bit architecture</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">64bit</td><td class=\"abidesc\">64 bit architecture</td></tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">le</td><td class=\"abidesc\">Little-endian architecture</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">be</td><td class=\"abidesc\">Big-endian architecture</td></tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">fpu</td><td class=\"abidesc\">Target has a hardware FPU</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">softfp</td><td class=\"abidesc\">softfp calling conventions</td></tr>\n<tr class=\"odd\">\n<td class=\"abiparam\">hardfp</td><td class=\"abidesc\">hardfp calling conventions</td></tr>\n<tr class=\"even separate\">\n<td class=\"abiparam\">eabi</td><td class=\"abidesc\">EABI variant of the standard ABI</td></tr>\n<tr class=\"odd\">\n<td class=\"abiparam\">win</td><td class=\"abidesc\">Windows variant of the standard ABI</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">gc64</td><td class=\"abidesc\">64 bit GC references</td></tr>\n</table>\n\n<h3 id=\"ffi_os\"><tt>ffi.os</tt></h3>\n<p>\nContains the target OS name. Same contents as\n<a href=\"ext_jit.html#jit_os\"><tt>jit.os</tt></a>.\n</p>\n\n<h3 id=\"ffi_arch\"><tt>ffi.arch</tt></h3>\n<p>\nContains the target architecture name. Same contents as\n<a href=\"ext_jit.html#jit_arch\"><tt>jit.arch</tt></a>.\n</p>\n\n<h2 id=\"callback\">Methods for Callbacks</h2>\n<p>\nThe C&nbsp;types for <a href=\"ext_ffi_semantics.html#callback\">callbacks</a>\nhave some extra methods:\n</p>\n\n<h3 id=\"callback_free\"><tt>cb:free()</tt></h3>\n<p>\nFree the resources associated with a callback. The associated Lua\nfunction is unanchored and may be garbage collected. The callback\nfunction pointer is no longer valid and must not be called anymore\n(it may be reused by a subsequently created callback).\n</p>\n\n<h3 id=\"callback_set\"><tt>cb:set(func)</tt></h3>\n<p>\nAssociate a new Lua function with a callback. The C&nbsp;type of the\ncallback and the callback function pointer are unchanged.\n</p>\n<p>\nThis method is useful to dynamically switch the receiver of callbacks\nwithout creating a new callback each time and registering it again (e.g.\nwith a GUI library).\n</p>\n\n<h2 id=\"extended\">Extended Standard Library Functions</h2>\n<p>\nThe following standard library functions have been extended to work\nwith cdata objects:\n</p>\n\n<h3 id=\"tonumber\"><tt>n = tonumber(cdata)</tt></h3>\n<p>\nConverts a number cdata object to a <tt>double</tt> and returns it as\na Lua number. This is particularly useful for boxed 64&nbsp;bit\ninteger values. Caveat: this conversion may incur a precision loss.\n</p>\n\n<h3 id=\"tostring\"><tt>s = tostring(cdata)</tt></h3>\n<p>\nReturns a string representation of the value of 64&nbsp;bit integers\n(<tt><b>\"</b>nnn<b>LL\"</b></tt> or <tt><b>\"</b>nnn<b>ULL\"</b></tt>) or\ncomplex numbers (<tt><b>\"</b>re&plusmn;im<b>i\"</b></tt>). Otherwise\nreturns a string representation of the C&nbsp;type of a ctype object\n(<tt><b>\"ctype&lt;</b>type<b>&gt;\"</b></tt>) or a cdata object\n(<tt><b>\"cdata&lt;</b>type<b>&gt;:&nbsp;</b>address\"</tt>), unless you\noverride it with a <tt>__tostring</tt> metamethod (see\n<a href=\"#ffi_metatype\"><tt>ffi.metatype()</tt></a>).\n</p>\n\n<h3 id=\"pairs\"><tt>iter, obj, start = pairs(cdata)<br>\niter, obj, start = ipairs(cdata)<br></tt></h3>\n<p>\nCalls the <tt>__pairs</tt> or <tt>__ipairs</tt> metamethod of the\ncorresponding ctype.\n</p>\n\n<h2 id=\"literals\">Extensions to the Lua Parser</h2>\n<p>\nThe parser for Lua source code treats numeric literals with the\nsuffixes <tt>LL</tt> or <tt>ULL</tt> as signed or unsigned 64&nbsp;bit\nintegers. Case doesn't matter, but uppercase is recommended for\nreadability. It handles decimal (<tt>42LL</tt>), hexadecimal\n(<tt>0x2aLL</tt>) and binary (<tt>0b101010LL</tt>) literals.\n</p>\n<p>\nThe imaginary part of complex numbers can be specified by suffixing\nnumber literals with <tt>i</tt> or <tt>I</tt>, e.g. <tt>12.5i</tt>.\nCaveat: you'll need to use <tt>1i</tt> to get an imaginary part with\nthe value one, since <tt>i</tt> itself still refers to a variable\nnamed <tt>i</tt>.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_ffi_semantics.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>FFI Semantics</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.convtable { line-height: 1.2; }\ntr.convhead td { font-weight: bold; }\ntd.convop { font-style: italic; width: 40%; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Semantics</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a class=\"current\" href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page describes the detailed semantics underlying the FFI library\nand its interaction with both Lua and C&nbsp;code.\n</p>\n<p>\nGiven that the FFI library is designed to interface with C&nbsp;code\nand that declarations can be written in plain C&nbsp;syntax, <b>it\nclosely follows the C&nbsp;language semantics</b>, wherever possible.\nSome minor concessions are needed for smoother interoperation with Lua\nlanguage semantics.\n</p>\n<p>\nPlease don't be overwhelmed by the contents of this page &mdash; this\nis a reference and you may need to consult it, if in doubt. It doesn't\nhurt to skim this page, but most of the semantics \"just work\" as you'd\nexpect them to work. It should be straightforward to write\napplications using the LuaJIT FFI for developers with a C or C++\nbackground.\n</p>\n\n<h2 id=\"clang\">C Language Support</h2>\n<p>\nThe FFI library has a built-in C&nbsp;parser with a minimal memory\nfootprint. It's used by the <a href=\"ext_ffi_api.html\">ffi.* library\nfunctions</a> to declare C&nbsp;types or external symbols.\n</p>\n<p>\nIt's only purpose is to parse C&nbsp;declarations, as found e.g. in\nC&nbsp;header files. Although it does evaluate constant expressions,\nit's <em>not</em> a C&nbsp;compiler. The body of <tt>inline</tt>\nC&nbsp;function definitions is simply ignored.\n</p>\n<p>\nAlso, this is <em>not</em> a validating C&nbsp;parser. It expects and\naccepts correctly formed C&nbsp;declarations, but it may choose to\nignore bad declarations or show rather generic error messages. If in\ndoubt, please check the input against your favorite C&nbsp;compiler.\n</p>\n<p>\nThe C&nbsp;parser complies to the <b>C99 language standard</b> plus\nthe following extensions:\n</p>\n<ul>\n\n<li>The <tt>'\\e'</tt> escape in character and string literals.</li>\n\n<li>The C99/C++ boolean type, declared with the keywords <tt>bool</tt>\nor <tt>_Bool</tt>.</li>\n\n<li>Complex numbers, declared with the keywords <tt>complex</tt> or\n<tt>_Complex</tt>.</li>\n\n<li>Two complex number types: <tt>complex</tt> (aka\n<tt>complex&nbsp;double</tt>) and <tt>complex&nbsp;float</tt>.</li>\n\n<li>Vector types, declared with the GCC <tt>mode</tt> or\n<tt>vector_size</tt> attribute.</li>\n\n<li>Unnamed ('transparent') <tt>struct</tt>/<tt>union</tt> fields\ninside a <tt>struct</tt>/<tt>union</tt>.</li>\n\n<li>Incomplete <tt>enum</tt> declarations, handled like incomplete\n<tt>struct</tt> declarations.</li>\n\n<li>Unnamed <tt>enum</tt> fields inside a\n<tt>struct</tt>/<tt>union</tt>. This is similar to a scoped C++\n<tt>enum</tt>, except that declared constants are visible in the\nglobal namespace, too.</li>\n\n<li>Scoped <tt>static&nbsp;const</tt> declarations inside a\n<tt>struct</tt>/<tt>union</tt> (from C++).</li>\n\n<li>Zero-length arrays (<tt>[0]</tt>), empty\n<tt>struct</tt>/<tt>union</tt>, variable-length arrays (VLA,\n<tt>[?]</tt>) and variable-length structs (VLS, with a trailing\nVLA).</li>\n\n<li>C++ reference types (<tt>int&nbsp;&amp;x</tt>).</li>\n\n<li>Alternate GCC keywords with '<tt>__</tt>', e.g.\n<tt>__const__</tt>.</li>\n\n<li>GCC <tt>__attribute__</tt> with the following attributes:\n<tt>aligned</tt>, <tt>packed</tt>, <tt>mode</tt>,\n<tt>vector_size</tt>, <tt>cdecl</tt>, <tt>fastcall</tt>,\n<tt>stdcall</tt>, <tt>thiscall</tt>.</li>\n\n<li>The GCC <tt>__extension__</tt> keyword and the GCC\n<tt>__alignof__</tt> operator.</li>\n\n<li>GCC <tt>__asm__(\"symname\")</tt> symbol name redirection for\nfunction declarations.</li>\n\n<li>MSVC keywords for fixed-length types: <tt>__int8</tt>,\n<tt>__int16</tt>, <tt>__int32</tt> and <tt>__int64</tt>.</li>\n\n<li>MSVC <tt>__cdecl</tt>, <tt>__fastcall</tt>, <tt>__stdcall</tt>,\n<tt>__thiscall</tt>, <tt>__ptr32</tt>, <tt>__ptr64</tt>,\n<tt>__declspec(align(n))</tt> and <tt>#pragma&nbsp;pack</tt>.</li>\n\n<li>All other GCC/MSVC-specific attributes are ignored.</li>\n\n</ul>\n<p>\nThe following C&nbsp;types are pre-defined by the C&nbsp;parser (like\na <tt>typedef</tt>, except re-declarations will be ignored):\n</p>\n<ul>\n\n<li>Vararg handling: <tt>va_list</tt>, <tt>__builtin_va_list</tt>,\n<tt>__gnuc_va_list</tt>.</li>\n\n<li>From <tt>&lt;stddef.h&gt;</tt>: <tt>ptrdiff_t</tt>,\n<tt>size_t</tt>, <tt>wchar_t</tt>.</li>\n\n<li>From <tt>&lt;stdint.h&gt;</tt>: <tt>int8_t</tt>, <tt>int16_t</tt>,\n<tt>int32_t</tt>, <tt>int64_t</tt>, <tt>uint8_t</tt>,\n<tt>uint16_t</tt>, <tt>uint32_t</tt>, <tt>uint64_t</tt>,\n<tt>intptr_t</tt>, <tt>uintptr_t</tt>.</li>\n\n<li>From <tt>&lt;unistd.h&gt;</tt> (POSIX): <tt>ssize_t</tt>.</li>\n\n</ul>\n<p>\nYou're encouraged to use these types in preference to\ncompiler-specific extensions or target-dependent standard types.\nE.g. <tt>char</tt> differs in signedness and <tt>long</tt> differs in\nsize, depending on the target architecture and platform ABI.\n</p>\n<p>\nThe following C&nbsp;features are <b>not</b> supported:\n</p>\n<ul>\n\n<li>A declaration must always have a type specifier; it doesn't\ndefault to an <tt>int</tt> type.</li>\n\n<li>Old-style empty function declarations (K&amp;R) are not allowed.\nAll C&nbsp;functions must have a proper prototype declaration. A\nfunction declared without parameters (<tt>int&nbsp;foo();</tt>) is\ntreated as a function taking zero arguments, like in C++.</li>\n\n<li>The <tt>long double</tt> C&nbsp;type is parsed correctly, but\nthere's no support for the related conversions, accesses or arithmetic\noperations.</li>\n\n<li>Wide character strings and character literals are not\nsupported.</li>\n\n<li><a href=\"#status\">See below</a> for features that are currently\nnot implemented.</li>\n\n</ul>\n\n<h2 id=\"convert\">C Type Conversion Rules</h2>\n\n<h3 id=\"convert_tolua\">Conversions from C&nbsp;types to Lua objects</h3>\n<p>\nThese conversion rules apply for <em>read accesses</em> to\nC&nbsp;types: indexing pointers, arrays or\n<tt>struct</tt>/<tt>union</tt> types; reading external variables or\nconstant values; retrieving return values from C&nbsp;calls:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>int8_t</tt>, <tt>int16_t</tt></td><td class=\"convop\">&rarr;<sup>sign-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>uint8_t</tt>, <tt>uint16_t</tt></td><td class=\"convop\">&rarr;<sup>zero-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>int32_t</tt>, <tt>uint32_t</tt></td><td class=\"convop\">&rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>int64_t</tt>, <tt>uint64_t</tt></td><td class=\"convop\">boxed value</td><td class=\"convout\">64 bit int cdata</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\"><tt>bool</tt></td><td class=\"convop\">0 &rarr; <tt>false</tt>, otherwise <tt>true</tt></td><td class=\"convout\">boolean</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>enum</tt></td><td class=\"convop\">boxed value</td><td class=\"convout\">enum cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">boxed value</td><td class=\"convout\">complex cdata</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Vector</td><td class=\"convop\">boxed value</td><td class=\"convout\">vector cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">boxed value</td><td class=\"convout\">pointer cdata</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Array</td><td class=\"convop\">boxed reference</td><td class=\"convout\">reference cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">boxed reference</td><td class=\"convout\">reference cdata</td></tr>\n</table>\n<p>\nBitfields are treated like their underlying type.\n</p>\n<p>\nReference types are dereferenced <em>before</em> a conversion can take\nplace &mdash; the conversion is applied to the C&nbsp;type pointed to\nby the reference.\n</p>\n\n<h3 id=\"convert_fromlua\">Conversions from Lua objects to C&nbsp;types</h3>\n<p>\nThese conversion rules apply for <em>write accesses</em> to\nC&nbsp;types: indexing pointers, arrays or\n<tt>struct</tt>/<tt>union</tt> types; initializing cdata objects;\ncasts to C&nbsp;types; writing to external variables; passing\narguments to C&nbsp;calls:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">number</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">boolean</td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">nil</td><td class=\"convop\"><tt>NULL</tt> &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">lightuserdata</td><td class=\"convop\">lightuserdata address &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">userdata</td><td class=\"convop\">userdata payload &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">io.* file</td><td class=\"convop\">get FILE * handle &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">string</td><td class=\"convop\">match against <tt>enum</tt> constant</td><td class=\"convout\"><tt>enum</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">string</td><td class=\"convop\">copy string data + zero-byte</td><td class=\"convout\"><tt>int8_t[]</tt>, <tt>uint8_t[]</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">string</td><td class=\"convop\">string data &rarr;</td><td class=\"convout\"><tt>const char[]</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">function</td><td class=\"convop\"><a href=\"#callback\">create callback</a> &rarr;</td><td class=\"convout\">C function type</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">table</td><td class=\"convop\"><a href=\"#init_table\">table initializer</a></td><td class=\"convout\">Array</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">table</td><td class=\"convop\"><a href=\"#init_table\">table initializer</a></td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">cdata</td><td class=\"convop\">cdata payload &rarr;</td><td class=\"convout\">C type</td></tr>\n</table>\n<p>\nIf the result type of this conversion doesn't match the\nC&nbsp;type of the destination, the\n<a href=\"#convert_between\">conversion rules between C&nbsp;types</a>\nare applied.\n</p>\n<p>\nReference types are immutable after initialization (\"no re-seating of\nreferences\"). For initialization purposes or when passing values to\nreference parameters, they are treated like pointers. Note that unlike\nin C++, there's no way to implement automatic reference generation of\nvariables under the Lua language semantics. If you want to call a\nfunction with a reference parameter, you need to explicitly pass a\none-element array.\n</p>\n\n<h3 id=\"convert_between\">Conversions between C&nbsp;types</h3>\n<p>\nThese conversion rules are more or less the same as the standard\nC&nbsp;conversion rules. Some rules only apply to casts, or require\npointer or type compatibility:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Signed integer</td><td class=\"convop\">&rarr;<sup>narrow or sign-extend</sup></td><td class=\"convout\">Integer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Unsigned integer</td><td class=\"convop\">&rarr;<sup>narrow or zero-extend</sup></td><td class=\"convout\">Integer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Integer</td><td class=\"convop\">&rarr;<sup>round</sup></td><td class=\"convout\"><tt>double</tt>, <tt>float</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>trunc</sup> <tt>int32_t</tt> &rarr;<sup>narrow</sup></td><td class=\"convout\"><tt>(u)int8_t</tt>, <tt>(u)int16_t</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>trunc</sup></td><td class=\"convout\"><tt>(u)int32_t</tt>, <tt>(u)int64_t</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>round</sup></td><td class=\"convout\"><tt>float</tt>, <tt>double</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">n == 0 &rarr; 0, otherwise 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>bool</tt></td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\">Number</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">convert real part</td><td class=\"convout\">Number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert real part, imag = 0</td><td class=\"convout\">Complex number</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">convert real and imag part</td><td class=\"convout\">Complex number</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert scalar and replicate</td><td class=\"convout\">Vector</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Vector</td><td class=\"convop\">copy (same size)</td><td class=\"convout\">Vector</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">take base address (compat)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Array</td><td class=\"convop\">take base address (compat)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Function</td><td class=\"convop\">take function address</td><td class=\"convout\">Function pointer</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert via <tt>uintptr_t</tt> (cast)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">convert address (compat/cast)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">convert address (cast)</td><td class=\"convout\">Integer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Array</td><td class=\"convop\">convert base address (cast)</td><td class=\"convout\">Integer</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Array</td><td class=\"convop\">copy (compat)</td><td class=\"convout\">Array</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">copy (identical type)</td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt></td></tr>\n</table>\n<p>\nBitfields or <tt>enum</tt> types are treated like their underlying\ntype.\n</p>\n<p>\nConversions not listed above will raise an error. E.g. it's not\npossible to convert a pointer to a complex number or vice versa.\n</p>\n\n<h3 id=\"convert_vararg\">Conversions for vararg C&nbsp;function arguments</h3>\n<p>\nThe following default conversion rules apply when passing Lua objects\nto the variable argument part of vararg C&nbsp;functions:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">number</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">boolean</td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">nil</td><td class=\"convop\"><tt>NULL</tt> &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">userdata</td><td class=\"convop\">userdata payload &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">lightuserdata</td><td class=\"convop\">lightuserdata address &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">string</td><td class=\"convop\">string data &rarr;</td><td class=\"convout\"><tt>const char *</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>float</tt> cdata</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Array cdata</td><td class=\"convop\">take base address</td><td class=\"convout\">Element pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt> cdata</td><td class=\"convop\">take base address</td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt> pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Function cdata</td><td class=\"convop\">take function address</td><td class=\"convout\">Function pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Any other cdata</td><td class=\"convop\">no conversion</td><td class=\"convout\">C type</td></tr>\n</table>\n<p>\nTo pass a Lua object, other than a cdata object, as a specific type,\nyou need to override the conversion rules: create a temporary cdata\nobject with a constructor or a cast and initialize it with the value\nto pass:\n</p>\n<p>\nAssuming <tt>x</tt> is a Lua number, here's how to pass it as an\ninteger to a vararg function:\n</p>\n<pre class=\"code\">\nffi.cdef[[\nint printf(const char *fmt, ...);\n]]\nffi.C.printf(\"integer value: %d\\n\", ffi.new(\"int\", x))\n</pre>\n<p>\nIf you don't do this, the default Lua number &rarr; <tt>double</tt>\nconversion rule applies. A vararg C&nbsp;function expecting an integer\nwill see a garbled or uninitialized value.\n</p>\n\n<h2 id=\"init\">Initializers</h2>\n<p>\nCreating a cdata object with\n<a href=\"ext_ffi_api.html#ffi_new\"><tt>ffi.new()</tt></a> or the\nequivalent constructor syntax always initializes its contents, too.\nDifferent rules apply, depending on the number of optional\ninitializers and the C&nbsp;types involved:\n</p>\n<ul>\n<li>If no initializers are given, the object is filled with zero bytes.</li>\n\n<li>Scalar types (numbers and pointers) accept a single initializer.\nThe Lua object is <a href=\"#convert_fromlua\">converted to the scalar\nC&nbsp;type</a>.</li>\n\n<li>Valarrays (complex numbers and vectors) are treated like scalars\nwhen a single initializer is given. Otherwise they are treated like\nregular arrays.</li>\n\n<li>Aggregate types (arrays and structs) accept either a single cdata\ninitializer of the same type (copy constructor), a single\n<a href=\"#init_table\">table initializer</a>, or a flat list of\ninitializers.</li>\n\n<li>The elements of an array are initialized, starting at index zero.\nIf a single initializer is given for an array, it's repeated for all\nremaining elements. This doesn't happen if two or more initializers\nare given: all remaining uninitialized elements are filled with zero\nbytes.</li>\n\n<li>Byte arrays may also be initialized with a Lua string. This copies\nthe whole string plus a terminating zero-byte. The copy stops early only\nif the array has a known, fixed size.</li>\n\n<li>The fields of a <tt>struct</tt> are initialized in the order of\ntheir declaration. Uninitialized fields are filled with zero\nbytes.</li>\n\n<li>Only the first field of a <tt>union</tt> can be initialized with a\nflat initializer.</li>\n\n<li>Elements or fields which are aggregates themselves are initialized\nwith a <em>single</em> initializer, but this may be a table\ninitializer or a compatible aggregate.</li>\n\n<li>Excess initializers cause an error.</li>\n\n</ul>\n\n<h2 id=\"init_table\">Table Initializers</h2>\n<p>\nThe following rules apply if a Lua table is used to initialize an\nArray or a <tt>struct</tt>/<tt>union</tt>:\n</p>\n<ul>\n\n<li>If the table index <tt>[0]</tt> is non-<tt>nil</tt>, then the\ntable is assumed to be zero-based. Otherwise it's assumed to be\none-based.</li>\n\n<li>Array elements, starting at index zero, are initialized one-by-one\nwith the consecutive table elements, starting at either index\n<tt>[0]</tt> or <tt>[1]</tt>. This process stops at the first\n<tt>nil</tt> table element.</li>\n\n<li>If exactly one array element was initialized, it's repeated for\nall the remaining elements. Otherwise all remaining uninitialized\nelements are filled with zero bytes.</li>\n\n<li>The above logic only applies to arrays with a known fixed size.\nA VLA is only initialized with the element(s) given in the table.\nDepending on the use case, you may need to explicitly add a\n<tt>NULL</tt> or <tt>0</tt> terminator to a VLA.</li>\n\n<li>A <tt>struct</tt>/<tt>union</tt> can be initialized in the\norder of the declaration of its fields. Each field is initialized with\nconsecutive table elements, starting at either index <tt>[0]</tt>\nor <tt>[1]</tt>. This process stops at the first <tt>nil</tt> table\nelement.</li>\n\n<li>Otherwise, if neither index <tt>[0]</tt> nor <tt>[1]</tt> is present,\na <tt>struct</tt>/<tt>union</tt> is initialized by looking up each field\nname (as a string key) in the table. Each non-<tt>nil</tt> value is\nused to initialize the corresponding field.</li>\n\n<li>Uninitialized fields of a <tt>struct</tt> are filled with zero\nbytes, except for the trailing VLA of a VLS.</li>\n\n<li>Initialization of a <tt>union</tt> stops after one field has been\ninitialized. If no field has been initialized, the <tt>union</tt> is\nfilled with zero bytes.</li>\n\n<li>Elements or fields which are aggregates themselves are initialized\nwith a <em>single</em> initializer, but this may be a nested table\ninitializer (or a compatible aggregate).</li>\n\n<li>Excess initializers for an array cause an error. Excess\ninitializers for a <tt>struct</tt>/<tt>union</tt> are ignored.\nUnrelated table entries are ignored, too.</li>\n\n</ul>\n<p>\nExample:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\n\nffi.cdef[[\nstruct foo { int a, b; };\nunion bar { int i; double d; };\nstruct nested { int x; struct foo y; };\n]]\n\nffi.new(\"int[3]\", {})            --> 0, 0, 0\nffi.new(\"int[3]\", {1})           --> 1, 1, 1\nffi.new(\"int[3]\", {1,2})         --> 1, 2, 0\nffi.new(\"int[3]\", {1,2,3})       --> 1, 2, 3\nffi.new(\"int[3]\", {[0]=1})       --> 1, 1, 1\nffi.new(\"int[3]\", {[0]=1,2})     --> 1, 2, 0\nffi.new(\"int[3]\", {[0]=1,2,3})   --> 1, 2, 3\nffi.new(\"int[3]\", {[0]=1,2,3,4}) --> error: too many initializers\n\nffi.new(\"struct foo\", {})            --> a = 0, b = 0\nffi.new(\"struct foo\", {1})           --> a = 1, b = 0\nffi.new(\"struct foo\", {1,2})         --> a = 1, b = 2\nffi.new(\"struct foo\", {[0]=1,2})     --> a = 1, b = 2\nffi.new(\"struct foo\", {b=2})         --> a = 0, b = 2\nffi.new(\"struct foo\", {a=1,b=2,c=3}) --> a = 1, b = 2  'c' is ignored\n\nffi.new(\"union bar\", {})        --> i = 0, d = 0.0\nffi.new(\"union bar\", {1})       --> i = 1, d = ?\nffi.new(\"union bar\", {[0]=1,2}) --> i = 1, d = ?    '2' is ignored\nffi.new(\"union bar\", {d=2})     --> i = ?, d = 2.0\n\nffi.new(\"struct nested\", {1,{2,3}})     --> x = 1, y.a = 2, y.b = 3\nffi.new(\"struct nested\", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3\n</pre>\n\n<h2 id=\"cdata_ops\">Operations on cdata Objects</h2>\n<p>\nAll of the standard Lua operators can be applied to cdata objects or a\nmix of a cdata object and another Lua object. The following list shows\nthe pre-defined operations.\n</p>\n<p>\nReference types are dereferenced <em>before</em> performing each of\nthe operations below &mdash; the operation is applied to the\nC&nbsp;type pointed to by the reference.\n</p>\n<p>\nThe pre-defined operations are always tried first before deferring to a\nmetamethod or index table (if any) for the corresponding ctype (except\nfor <tt>__new</tt>). An error is raised if the metamethod lookup or\nindex table lookup fails.\n</p>\n\n<h3 id=\"cdata_array\">Indexing a cdata object</h3>\n<ul>\n\n<li><b>Indexing a pointer/array</b>: a cdata pointer/array can be\nindexed by a cdata number or a Lua number. The element address is\ncomputed as the base address plus the number value multiplied by the\nelement size in bytes. A read access loads the element value and\n<a href=\"#convert_tolua\">converts it to a Lua object</a>. A write\naccess <a href=\"#convert_fromlua\">converts a Lua object to the element\ntype</a> and stores the converted value to the element. An error is\nraised if the element size is undefined or a write access to a\nconstant element is attempted.</li>\n\n<li><b>Dereferencing a <tt>struct</tt>/<tt>union</tt> field</b>: a\ncdata <tt>struct</tt>/<tt>union</tt> or a pointer to a\n<tt>struct</tt>/<tt>union</tt> can be dereferenced by a string key,\ngiving the field name. The field address is computed as the base\naddress plus the relative offset of the field. A read access loads the\nfield value and <a href=\"#convert_tolua\">converts it to a Lua\nobject</a>. A write access <a href=\"#convert_fromlua\">converts a Lua\nobject to the field type</a> and stores the converted value to the\nfield. An error is raised if a write access to a constant\n<tt>struct</tt>/<tt>union</tt> or a constant field is attempted.\nScoped enum constants or static constants are treated like a constant\nfield.</li>\n\n<li><b>Indexing a complex number</b>: a complex number can be indexed\neither by a cdata number or a Lua number with the values 0 or 1, or by\nthe strings <tt>\"re\"</tt> or <tt>\"im\"</tt>. A read access loads the\nreal part (<tt>[0]</tt>, <tt>.re</tt>) or the imaginary part\n(<tt>[1]</tt>, <tt>.im</tt>) part of a complex number and\n<a href=\"#convert_tolua\">converts it to a Lua number</a>. The\nsub-parts of a complex number are immutable &mdash; assigning to an\nindex of a complex number raises an error. Accessing out-of-bound\nindexes returns unspecified results, but is guaranteed not to trigger\nmemory access violations.</li>\n\n<li><b>Indexing a vector</b>: a vector is treated like an array for\nindexing purposes, except the vector elements are immutable &mdash;\nassigning to an index of a vector raises an error.</li>\n\n</ul>\n<p>\nA ctype object can be indexed with a string key, too. The only\npre-defined operation is reading scoped constants of\n<tt>struct</tt>/<tt>union</tt> types. All other accesses defer\nto the corresponding metamethods or index tables (if any).\n</p>\n<p>\nNote: since there's (deliberately) no address-of operator, a cdata\nobject holding a value type is effectively immutable after\ninitialization. The JIT compiler benefits from this fact when applying\ncertain optimizations.\n</p>\n<p>\nAs a consequence, the <em>elements</em> of complex numbers and\nvectors are immutable. But the elements of an aggregate holding these\ntypes <em>may</em> be modified of course. I.e. you cannot assign to\n<tt>foo.c.im</tt>, but you can assign a (newly created) complex number\nto <tt>foo.c</tt>.\n</p>\n<p>\nThe JIT compiler implements strict aliasing rules: accesses to different\ntypes do <b>not</b> alias, except for differences in signedness (this\napplies even to <tt>char</tt> pointers, unlike C99). Type punning\nthrough unions is explicitly detected and allowed.\n</p>\n\n<h3 id=\"cdata_call\">Calling a cdata object</h3>\n<ul>\n\n<li><b>Constructor</b>: a ctype object can be called and used as a\n<a href=\"ext_ffi_api.html#ffi_new\">constructor</a>. This is equivalent\nto <tt>ffi.new(ct, ...)</tt>, unless a <tt>__new</tt> metamethod is\ndefined. The <tt>__new</tt> metamethod is called with the ctype object\nplus any other arguments passed to the contructor. Note that you have to\nuse <tt>ffi.new</tt> inside of it, since calling <tt>ct(...)</tt> would\ncause infinite recursion.</li>\n\n<li><b>C&nbsp;function call</b>: a cdata function or cdata function\npointer can be called. The passed arguments are\n<a href=\"#convert_fromlua\">converted to the C&nbsp;types</a> of the\nparameters given by the function declaration. Arguments passed to the\nvariable argument part of vararg C&nbsp;function use\n<a href=\"#convert_vararg\">special conversion rules</a>. This\nC&nbsp;function is called and the return value (if any) is\n<a href=\"#convert_tolua\">converted to a Lua object</a>.<br>\nOn Windows/x86 systems, <tt>__stdcall</tt> functions are automatically\ndetected and a function declared as <tt>__cdecl</tt> (the default) is\nsilently fixed up after the first call.</li>\n\n</ul>\n\n<h3 id=\"cdata_arith\">Arithmetic on cdata objects</h3>\n<ul>\n\n<li><b>Pointer arithmetic</b>: a cdata pointer/array and a cdata\nnumber or a Lua number can be added or subtracted. The number must be\non the right hand side for a subtraction. The result is a pointer of\nthe same type with an address plus or minus the number value\nmultiplied by the element size in bytes. An error is raised if the\nelement size is undefined.</li>\n\n<li><b>Pointer difference</b>: two compatible cdata pointers/arrays\ncan be subtracted. The result is the difference between their\naddresses, divided by the element size in bytes. An error is raised if\nthe element size is undefined or zero.</li>\n\n<li><b>64&nbsp;bit integer arithmetic</b>: the standard arithmetic\noperators (<tt>+&nbsp;-&nbsp;*&nbsp;/&nbsp;%&nbsp;^</tt> and unary\nminus) can be applied to two cdata numbers, or a cdata number and a\nLua number. If one of them is an <tt>uint64_t</tt>, the other side is\nconverted to an <tt>uint64_t</tt> and an unsigned arithmetic operation\nis performed. Otherwise both sides are converted to an\n<tt>int64_t</tt> and a signed arithmetic operation is performed. The\nresult is a boxed 64&nbsp;bit cdata object.<br>\n\nIf one of the operands is an <tt>enum</tt> and the other operand is a\nstring, the string is converted to the value of a matching <tt>enum</tt>\nconstant before the above conversion.<br>\n\nThese rules ensure that 64&nbsp;bit integers are \"sticky\". Any\nexpression involving at least one 64&nbsp;bit integer operand results\nin another one. The undefined cases for the division, modulo and power\noperators return <tt>2LL&nbsp;^&nbsp;63</tt> or\n<tt>2ULL&nbsp;^&nbsp;63</tt>.<br>\n\nYou'll have to explicitly convert a 64&nbsp;bit integer to a Lua\nnumber (e.g. for regular floating-point calculations) with\n<tt>tonumber()</tt>. But note this may incur a precision loss.</li>\n\n<li><b>64&nbsp;bit bitwise operations</b>: the rules for 64&nbsp;bit\narithmetic operators apply analogously.<br>\n\nUnlike the other <tt>bit.*</tt> operations, <tt>bit.tobit()</tt>\nconverts a cdata number via <tt>int64_t</tt> to <tt>int32_t</tt> and\nreturns a Lua number.<br>\n\nFor <tt>bit.band()</tt>, <tt>bit.bor()</tt> and <tt>bit.bxor()</tt>, the\nconversion to <tt>int64_t</tt> or <tt>uint64_t</tt> applies to\n<em>all</em> arguments, if <em>any</em> argument is a cdata number.<br>\n\nFor all other operations, only the first argument is used to determine\nthe output type. This implies that a cdata number as a shift count for\nshifts and rotates is accepted, but that alone does <em>not</em> cause\na cdata number output.\n\n</ul>\n\n<h3 id=\"cdata_comp\">Comparisons of cdata objects</h3>\n<ul>\n\n<li><b>Pointer comparison</b>: two compatible cdata pointers/arrays\ncan be compared. The result is the same as an unsigned comparison of\ntheir addresses. <tt>nil</tt> is treated like a <tt>NULL</tt> pointer,\nwhich is compatible with any other pointer type.</li>\n\n<li><b>64&nbsp;bit integer comparison</b>: two cdata numbers, or a\ncdata number and a Lua number can be compared with each other. If one\nof them is an <tt>uint64_t</tt>, the other side is converted to an\n<tt>uint64_t</tt> and an unsigned comparison is performed. Otherwise\nboth sides are converted to an <tt>int64_t</tt> and a signed\ncomparison is performed.<br>\n\nIf one of the operands is an <tt>enum</tt> and the other operand is a\nstring, the string is converted to the value of a matching <tt>enum</tt>\nconstant before the above conversion.<br>\n\n<li><b>Comparisons for equality/inequality</b> never raise an error.\nEven incompatible pointers can be compared for equality by address. Any\nother incompatible comparison (also with non-cdata objects) treats the\ntwo sides as unequal.</li>\n\n</ul>\n\n<h3 id=\"cdata_key\">cdata objects as table keys</h3>\n<p>\nLua tables may be indexed by cdata objects, but this doesn't provide\nany useful semantics &mdash; <b>cdata objects are unsuitable as table\nkeys!</b>\n</p>\n<p>\nA cdata object is treated like any other garbage-collected object and\nis hashed and compared by its address for table indexing. Since\nthere's no interning for cdata value types, the same value may be\nboxed in different cdata objects with different addresses. Thus\n<tt>t[1LL+1LL]</tt> and <tt>t[2LL]</tt> usually <b>do not</b> point to\nthe same hash slot and they certainly <b>do not</b> point to the same\nhash slot as <tt>t[2]</tt>.\n</p>\n<p>\nIt would seriously drive up implementation complexity and slow down\nthe common case, if one were to add extra handling for by-value\nhashing and comparisons to Lua tables. Given the ubiquity of their use\ninside the VM, this is not acceptable.\n</p>\n<p>\nThere are three viable alternatives, if you really need to use cdata\nobjects as keys:\n</p>\n<ul>\n\n<li>If you can get by with the precision of Lua numbers\n(52&nbsp;bits), then use <tt>tonumber()</tt> on a cdata number or\ncombine multiple fields of a cdata aggregate to a Lua number. Then use\nthe resulting Lua number as a key when indexing tables.<br>\nOne obvious benefit: <tt>t[tonumber(2LL)]</tt> <b>does</b> point to\nthe same slot as <tt>t[2]</tt>.</li>\n\n<li>Otherwise use either <tt>tostring()</tt> on 64&nbsp;bit integers\nor complex numbers or combine multiple fields of a cdata aggregate to\na Lua string (e.g. with\n<a href=\"ext_ffi_api.html#ffi_string\"><tt>ffi.string()</tt></a>). Then\nuse the resulting Lua string as a key when indexing tables.</li>\n\n<li>Create your own specialized hash table implementation using the\nC&nbsp;types provided by the FFI library, just like you would in\nC&nbsp;code. Ultimately this may give much better performance than the\nother alternatives or what a generic by-value hash table could\npossibly provide.</li>\n\n</ul>\n\n<h2 id=\"param\">Parameterized Types</h2>\n<p>\nTo facilitate some abstractions, the two functions\n<a href=\"ext_ffi_api.html#ffi_typeof\"><tt>ffi.typeof</tt></a> and\n<a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a> support\nparameterized types in C&nbsp;declarations. Note: none of the other API\nfunctions taking a cdecl allow this.\n</p>\n<p>\nAny place you can write a <b><tt>typedef</tt> name</b>, an\n<b>identifier</b> or a <b>number</b> in a declaration, you can write\n<tt>$</tt> (the dollar sign) instead. These placeholders are replaced in\norder of appearance with the arguments following the cdecl string:\n</p>\n<pre class=\"code\">\n-- Declare a struct with a parameterized field type and name:\nffi.cdef([[\ntypedef struct { $ $; } foo_t;\n]], type1, name1)\n\n-- Anonymous struct with dynamic names:\nlocal bar_t = ffi.typeof(\"struct { int $, $; }\", name1, name2)\n-- Derived pointer type:\nlocal bar_ptr_t = ffi.typeof(\"$ *\", bar_t)\n\n-- Parameterized dimensions work even where a VLA won't work:\nlocal matrix_t = ffi.typeof(\"uint8_t[$][$]\", width, height)\n</pre>\n<p>\nCaveat: this is <em>not</em> simple text substitution! A passed ctype or\ncdata object is treated like the underlying type, a passed string is\nconsidered an identifier and a number is considered a number. You must\nnot mix this up: e.g. passing <tt>\"int\"</tt> as a string doesn't work in\nplace of a type, you'd need to use <tt>ffi.typeof(\"int\")</tt> instead.\n</p>\n<p>\nThe main use for parameterized types are libraries implementing abstract\ndata types\n(<a href=\"http://www.freelists.org/post/luajit/ffi-type-of-pointer-to,8\"><span class=\"ext\">&raquo;</span>&nbsp;example</a>),\nsimilar to what can be achieved with C++ template metaprogramming.\nAnother use case are derived types of anonymous structs, which avoids\npollution of the global struct namespace.\n</p>\n<p>\nPlease note that parameterized types are a nice tool and indispensable\nfor certain use cases. But you'll want to use them sparingly in regular\ncode, e.g. when all types are actually fixed.\n</p>\n\n<h2 id=\"gc\">Garbage Collection of cdata Objects</h2>\n<p>\nAll explicitly (<tt>ffi.new()</tt>, <tt>ffi.cast()</tt> etc.) or\nimplicitly (accessors) created cdata objects are garbage collected.\nYou need to ensure to retain valid references to cdata objects\nsomewhere on a Lua stack, an upvalue or in a Lua table while they are\nstill in use. Once the last reference to a cdata object is gone, the\ngarbage collector will automatically free the memory used by it (at\nthe end of the next GC cycle).\n</p>\n<p>\nPlease note that pointers themselves are cdata objects, however they\nare <b>not</b> followed by the garbage collector. So e.g. if you\nassign a cdata array to a pointer, you must keep the cdata object\nholding the array alive as long as the pointer is still in use:\n</p>\n<pre class=\"code\">\nffi.cdef[[\ntypedef struct { int *a; } foo_t;\n]]\n\nlocal s = ffi.new(\"foo_t\", ffi.new(\"int[10]\")) -- <span style=\"color:#c00000;\">WRONG!</span>\n\nlocal a = ffi.new(\"int[10]\") -- <span style=\"color:#00a000;\">OK</span>\nlocal s = ffi.new(\"foo_t\", a)\n-- Now do something with 's', but keep 'a' alive until you're done.\n</pre>\n<p>\nSimilar rules apply for Lua strings which are implicitly converted to\n<tt>\"const&nbsp;char&nbsp;*\"</tt>: the string object itself must be\nreferenced somewhere or it'll be garbage collected eventually. The\npointer will then point to stale data, which may have already been\noverwritten. Note that <em>string literals</em> are automatically kept\nalive as long as the function containing it (actually its prototype)\nis not garbage collected.\n</p>\n<p>\nObjects which are passed as an argument to an external C&nbsp;function\nare kept alive until the call returns. So it's generally safe to\ncreate temporary cdata objects in argument lists. This is a common\nidiom for <a href=\"#convert_vararg\">passing specific C&nbsp;types to\nvararg functions</a>.\n</p>\n<p>\nMemory areas returned by C functions (e.g. from <tt>malloc()</tt>)\nmust be manually managed, of course (or use\n<a href=\"ext_ffi_api.html#ffi_gc\"><tt>ffi.gc()</tt></a>). Pointers to\ncdata objects are indistinguishable from pointers returned by C\nfunctions (which is one of the reasons why the GC cannot follow them).\n</p>\n\n<h2 id=\"callback\">Callbacks</h2>\n<p>\nThe LuaJIT FFI automatically generates special callback functions\nwhenever a Lua function is converted to a C&nbsp;function pointer. This\nassociates the generated callback function pointer with the C&nbsp;type\nof the function pointer and the Lua function object (closure).\n</p>\n<p>\nThis can happen implicitly due to the usual conversions, e.g. when\npassing a Lua function to a function pointer argument. Or you can use\n<tt>ffi.cast()</tt> to explicitly cast a Lua function to a\nC&nbsp;function pointer.\n</p>\n<p>\nCurrently only certain C&nbsp;function types can be used as callback\nfunctions. Neither C&nbsp;vararg functions nor functions with\npass-by-value aggregate argument or result types are supported. There\nare no restrictions for the kind of Lua functions that can be called\nfrom the callback &mdash; no checks for the proper number of arguments\nare made. The return value of the Lua function will be converted to the\nresult type and an error will be thrown for invalid conversions.\n</p>\n<p>\nIt's allowed to throw errors across a callback invocation, but it's not\nadvisable in general. Do this only if you know the C&nbsp;function, that\ncalled the callback, copes with the forced stack unwinding and doesn't\nleak resources.\n</p>\n<p>\nOne thing that's not allowed, is to let an FFI call into a C&nbsp;function\nget JIT-compiled, which in turn calls a callback, calling into Lua again.\nUsually this attempt is caught by the interpreter first and the\nC&nbsp;function is blacklisted for compilation.\n</p>\n<p>\nHowever, this heuristic may fail under specific circumstances: e.g. a\nmessage polling function might not run Lua callbacks right away and the call\ngets JIT-compiled. If it later happens to call back into Lua (e.g. a rarely\ninvoked error callback), you'll get a VM PANIC with the message\n<tt>\"bad callback\"</tt>. Then you'll need to manually turn off\nJIT-compilation with\n<a href=\"ext_jit.html#jit_onoff_func\"><tt>jit.off()</tt></a> for the\nsurrounding Lua function that invokes such a message polling function (or\nsimilar).\n</p>\n\n<h3 id=\"callback_resources\">Callback resource handling</h3>\n<p>\nCallbacks take up resources &mdash; you can only have a limited number\nof them at the same time (500&nbsp;-&nbsp;1000, depending on the\narchitecture). The associated Lua functions are anchored to prevent\ngarbage collection, too.\n</p>\n<p>\n<b>Callbacks due to implicit conversions are permanent!</b> There is no\nway to guess their lifetime, since the C&nbsp;side might store the\nfunction pointer for later use (typical for GUI toolkits). The associated\nresources cannot be reclaimed until termination:\n</p>\n<pre class=\"code\">\nffi.cdef[[\ntypedef int (__stdcall *WNDENUMPROC)(void *hwnd, intptr_t l);\nint EnumWindows(WNDENUMPROC func, intptr_t l);\n]]\n\n-- Implicit conversion to a callback via function pointer argument.\nlocal count = 0\nffi.C.EnumWindows(function(hwnd, l)\n  count = count + 1\n  return true\nend, 0)\n-- The callback is permanent and its resources cannot be reclaimed!\n-- Ok, so this may not be a problem, if you do this only once.\n</pre>\n<p>\nNote: this example shows that you <em>must</em> properly declare\n<tt>__stdcall</tt> callbacks on Windows/x86 systems. The calling\nconvention cannot be automatically detected, unlike for\n<tt>__stdcall</tt> calls <em>to</em> Windows functions.\n</p>\n<p>\nFor some use cases it's necessary to free up the resources or to\ndynamically redirect callbacks. Use an explicit cast to a\nC&nbsp;function pointer and keep the resulting cdata object. Then use\nthe <a href=\"ext_ffi_api.html#callback_free\"><tt>cb:free()</tt></a>\nor <a href=\"ext_ffi_api.html#callback_set\"><tt>cb:set()</tt></a> methods\non the cdata object:\n</p>\n<pre class=\"code\">\n-- Explicitly convert to a callback via cast.\nlocal count = 0\nlocal cb = ffi.cast(\"WNDENUMPROC\", function(hwnd, l)\n  count = count + 1\n  return true\nend)\n\n-- Pass it to a C function.\nffi.C.EnumWindows(cb, 0)\n-- EnumWindows doesn't need the callback after it returns, so free it.\n\ncb:free()\n-- The callback function pointer is no longer valid and its resources\n-- will be reclaimed. The created Lua closure will be garbage collected.\n</pre>\n\n<h3 id=\"callback_performance\">Callback performance</h3>\n<p>\n<b>Callbacks are slow!</b> First, the C&nbsp;to Lua transition itself\nhas an unavoidable cost, similar to a <tt>lua_call()</tt> or\n<tt>lua_pcall()</tt>. Argument and result marshalling add to that cost.\nAnd finally, neither the C&nbsp;compiler nor LuaJIT can inline or\noptimize across the language barrier and hoist repeated computations out\nof a callback function.\n</p>\n<p>\nDo not use callbacks for performance-sensitive work: e.g. consider a\nnumerical integration routine which takes a user-defined function to\nintegrate over. It's a bad idea to call a user-defined Lua function from\nC&nbsp;code millions of times. The callback overhead will be absolutely\ndetrimental for performance.\n</p>\n<p>\nIt's considerably faster to write the numerical integration routine\nitself in Lua &mdash; the JIT compiler will be able to inline the\nuser-defined function and optimize it together with its calling context,\nwith very competitive performance.\n</p>\n<p>\nAs a general guideline: <b>use callbacks only when you must</b>, because\nof existing C&nbsp;APIs. E.g. callback performance is irrelevant for a\nGUI application, which waits for user input most of the time, anyway.\n</p>\n<p>\nFor new designs <b>avoid push-style APIs</b>: a C&nbsp;function repeatedly\ncalling a callback for each result. Instead <b>use pull-style APIs</b>:\ncall a C&nbsp;function repeatedly to get a new result. Calls from Lua\nto C via the FFI are much faster than the other way round. Most well-designed\nlibraries already use pull-style APIs (read/write, get/put).\n</p>\n\n<h2 id=\"clib\">C Library Namespaces</h2>\n<p>\nA C&nbsp;library namespace is a special kind of object which allows\naccess to the symbols contained in shared libraries or the default\nsymbol namespace. The default\n<a href=\"ext_ffi_api.html#ffi_C\"><tt>ffi.C</tt></a> namespace is\nautomatically created when the FFI library is loaded. C&nbsp;library\nnamespaces for specific shared libraries may be created with the\n<a href=\"ext_ffi_api.html#ffi_load\"><tt>ffi.load()</tt></a> API\nfunction.\n</p>\n<p>\nIndexing a C&nbsp;library namespace object with a symbol name (a Lua\nstring) automatically binds it to the library. First the symbol type\nis resolved &mdash; it must have been declared with\n<a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a>. Then the\nsymbol address is resolved by searching for the symbol name in the\nassociated shared libraries or the default symbol namespace. Finally,\nthe resulting binding between the symbol name, the symbol type and its\naddress is cached. Missing symbol declarations or nonexistent symbol\nnames cause an error.\n</p>\n<p>\nThis is what happens on a <b>read access</b> for the different kinds of\nsymbols:\n</p>\n<ul>\n\n<li>External functions: a cdata object with the type of the function\nand its address is returned.</li>\n\n<li>External variables: the symbol address is dereferenced and the\nloaded value is <a href=\"#convert_tolua\">converted to a Lua object</a>\nand returned.</li>\n\n<li>Constant values (<tt>static&nbsp;const</tt> or <tt>enum</tt>\nconstants): the constant is <a href=\"#convert_tolua\">converted to a\nLua object</a> and returned.</li>\n\n</ul>\n<p>\nThis is what happens on a <b>write access</b>:\n</p>\n<ul>\n\n<li>External variables: the value to be written is\n<a href=\"#convert_fromlua\">converted to the C&nbsp;type</a> of the\nvariable and then stored at the symbol address.</li>\n\n<li>Writing to constant variables or to any other symbol type causes\nan error, like any other attempted write to a constant location.</li>\n\n</ul>\n<p>\nC&nbsp;library namespaces themselves are garbage collected objects. If\nthe last reference to the namespace object is gone, the garbage\ncollector will eventually release the shared library reference and\nremove all memory associated with the namespace. Since this may\ntrigger the removal of the shared library from the memory of the\nrunning process, it's generally <em>not safe</em> to use function\ncdata objects obtained from a library if the namespace object may be\nunreferenced.\n</p>\n<p>\nPerformance notice: the JIT compiler specializes to the identity of\nnamespace objects and to the strings used to index it. This\neffectively turns function cdata objects into constants. It's not\nuseful and actually counter-productive to explicitly cache these\nfunction objects, e.g. <tt>local strlen = ffi.C.strlen</tt>. OTOH it\n<em>is</em> useful to cache the namespace itself, e.g. <tt>local C =\nffi.C</tt>.\n</p>\n\n<h2 id=\"policy\">No Hand-holding!</h2>\n<p>\nThe FFI library has been designed as <b>a low-level library</b>. The\ngoal is to interface with C&nbsp;code and C&nbsp;data types with a\nminimum of overhead. This means <b>you can do anything you can do\nfrom&nbsp;C</b>: access all memory, overwrite anything in memory, call\nmachine code at any memory address and so on.\n</p>\n<p>\nThe FFI library provides <b>no memory safety</b>, unlike regular Lua\ncode. It will happily allow you to dereference a <tt>NULL</tt>\npointer, to access arrays out of bounds or to misdeclare\nC&nbsp;functions. If you make a mistake, your application might crash,\njust like equivalent C&nbsp;code would.\n</p>\n<p>\nThis behavior is inevitable, since the goal is to provide full\ninteroperability with C&nbsp;code. Adding extra safety measures, like\nbounds checks, would be futile. There's no way to detect\nmisdeclarations of C&nbsp;functions, since shared libraries only\nprovide symbol names, but no type information. Likewise there's no way\nto infer the valid range of indexes for a returned pointer.\n</p>\n<p>\nAgain: the FFI library is a low-level library. This implies it needs\nto be used with care, but it's flexibility and performance often\noutweigh this concern. If you're a C or C++ developer, it'll be easy\nto apply your existing knowledge. OTOH writing code for the FFI\nlibrary is not for the faint of heart and probably shouldn't be the\nfirst exercise for someone with little experience in Lua, C or C++.\n</p>\n<p>\nAs a corollary of the above, the FFI library is <b>not safe for use by\nuntrusted Lua code</b>. If you're sandboxing untrusted Lua code, you\ndefinitely don't want to give this code access to the FFI library or\nto <em>any</em> cdata object (except 64&nbsp;bit integers or complex\nnumbers). Any properly engineered Lua sandbox needs to provide safety\nwrappers for many of the standard Lua library functions &mdash;\nsimilar wrappers need to be written for high-level operations on FFI\ndata types, too.\n</p>\n\n<h2 id=\"status\">Current Status</h2>\n<p>\nThe initial release of the FFI library has some limitations and is\nmissing some features. Most of these will be fixed in future releases.\n</p>\n<p>\n<a href=\"#clang\">C language support</a> is\ncurrently incomplete:\n</p>\n<ul>\n<li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor,\nyet.</li>\n<li>The C&nbsp;parser is able to evaluate most constant expressions\ncommonly found in C&nbsp;header files. However it doesn't handle the\nfull range of C&nbsp;expression semantics and may fail for some\nobscure constructs.</li>\n<li><tt>static const</tt> declarations only work for integer types\nup to 32&nbsp;bits. Neither declaring string constants nor\nfloating-point constants is supported.</li>\n<li>Packed <tt>struct</tt> bitfields that cross container boundaries\nare not implemented.</li>\n<li>Native vector types may be defined with the GCC <tt>mode</tt> or\n<tt>vector_size</tt> attribute. But no operations other than loading,\nstoring and initializing them are supported, yet.</li>\n<li>The <tt>volatile</tt> type qualifier is currently ignored by\ncompiled code.</li>\n<li><a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a> silently\nignores most re-declarations. Note: avoid re-declarations which do not\nconform to C99. The implementation will eventually be changed to\nperform strict checks.</li>\n</ul>\n<p>\nThe JIT compiler already handles a large subset of all FFI operations.\nIt automatically falls back to the interpreter for unimplemented\noperations (you can check for this with the\n<a href=\"running.html#opt_j\"><tt>-jv</tt></a> command line option).\nThe following operations are currently not compiled and may exhibit\nsuboptimal performance, especially when used in inner loops:\n</p>\n<ul>\n<li>Bitfield accesses and initializations.</li>\n<li>Vector operations.</li>\n<li>Table initializers.</li>\n<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>\n<li>Non-default initialization of VLA/VLS or large C&nbsp;types\n(&gt; 128&nbsp;bytes or &gt; 16 array elements.</li>\n<li>Conversions from lightuserdata to <tt>void&nbsp;*</tt>.</li>\n<li>Pointer differences for element sizes that are not a power of\ntwo.</li>\n<li>Calls to C&nbsp;functions with aggregates passed or returned by\nvalue.</li>\n<li>Calls to ctype metamethods which are not plain functions.</li>\n<li>ctype <tt>__newindex</tt> tables and non-string lookups in ctype\n<tt>__index</tt> tables.</li>\n<li><tt>tostring()</tt> for cdata types.</li>\n<li>Calls to <tt>ffi.cdef()</tt>, <tt>ffi.load()</tt> and\n<tt>ffi.metatype()</tt>.</li>\n</ul>\n<p>\nOther missing features:\n</p>\n<ul>\n<li>Arithmetic for <tt>complex</tt> numbers.</li>\n<li>Passing structs by value to vararg C&nbsp;functions.</li>\n<li><a href=\"extensions.html#exceptions\">C++ exception interoperability</a>\ndoes not extend to C&nbsp;functions called via the FFI, if the call is\ncompiled.</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_ffi_tutorial.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>FFI Tutorial</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.idiomtable { font-size: 90%; line-height: 1.2; }\ntable.idiomtable tt { font-size: 100%; }\ntable.idiomtable td { vertical-align: top; }\ntr.idiomhead td { font-weight: bold; }\ntd.idiomlua b { font-weight: normal; color: #2142bf; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Tutorial</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a class=\"current\" href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page is intended to give you an overview of the features of the FFI\nlibrary by presenting a few use cases and guidelines.\n</p>\n<p>\nThis page makes no attempt to explain all of the FFI library, though.\nYou'll want to have a look at the <a href=\"ext_ffi_api.html\">ffi.* API\nfunction reference</a> and the <a href=\"ext_ffi_semantics.html\">FFI\nsemantics</a> to learn more.\n</p>\n\n<h2 id=\"load\">Loading the FFI Library</h2>\n<p>\nThe FFI library is built into LuaJIT by default, but it's not loaded\nand initialized by default. The suggested way to use the FFI library\nis to add the following to the start of every Lua file that needs one\nof its functions:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\n</pre>\n<p>\nPlease note this doesn't define an <tt>ffi</tt> variable in the table\nof globals &mdash; you really need to use the local variable. The\n<tt>require</tt> function ensures the library is only loaded once.\n</p>\n<p style=\"font-size: 8pt;\">\nNote: If you want to experiment with the FFI from the interactive prompt\nof the command line executable, omit the <tt>local</tt>, as it doesn't\npreserve local variables across lines.\n</p>\n\n<h2 id=\"sleep\">Accessing Standard System Functions</h2>\n<p>\nThe following code explains how to access standard system functions.\nWe slowly print two lines of dots by sleeping for 10&nbsp;milliseconds\nafter each dot:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n\n\n&#9313;\n&#9314;\n&#9315;\n\n\n\n&#9316;\n\n\n\n\n\n&#9317;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">void Sleep(int ms);\nint poll(struct pollfd *fds, unsigned long nfds, int timeout);</span>\n]]\n\nlocal sleep\nif ffi.os == \"Windows\" then\n  function sleep(s)\n    ffi.C.Sleep(s*1000)\n  end\nelse\n  function sleep(s)\n    ffi.C.poll(nil, 0, s*1000)\n  end\nend\n\nfor i=1,160 do\n  io.write(\".\"); io.flush()\n  sleep(0.01)\nend\nio.write(\"\\n\")\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines the\nC&nbsp;library functions we're going to use. The part inside the\ndouble-brackets (in green) is just standard C&nbsp;syntax. You can\nusually get this info from the C&nbsp;header files or the\ndocumentation provided by each C&nbsp;library or C&nbsp;compiler.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> The difficulty we're\nfacing here, is that there are different standards to choose from.\nWindows has a simple <tt>Sleep()</tt> function. On other systems there\nare a variety of functions available to achieve sub-second sleeps, but\nwith no clear consensus. Thankfully <tt>poll()</tt> can be used for\nthis task, too, and it's present on most non-Windows systems. The\ncheck for <tt>ffi.os</tt> makes sure we use the Windows-specific\nfunction only on Windows systems.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Here we're wrapping the\ncall to the C&nbsp;function in a Lua function. This isn't strictly\nnecessary, but it's helpful to deal with system-specific issues only\nin one part of the code. The way we're wrapping it ensures the check\nfor the OS is only done during initialization and not for every call.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> A more subtle point is\nthat we defined our <tt>sleep()</tt> function (for the sake of this\nexample) as taking the number of seconds, but accepting fractional\nseconds. Multiplying this by 1000 gets us milliseconds, but that still\nleaves it a Lua number, which is a floating-point value. Alas, the\n<tt>Sleep()</tt> function only accepts an integer value. Luckily for\nus, the FFI library automatically performs the conversion when calling\nthe function (truncating the FP value towards zero, like in C).\n</p>\n<p style=\"font-size: 8pt;\">\nSome readers will notice that <tt>Sleep()</tt> is part of\n<tt>KERNEL32.DLL</tt> and is also a <tt>stdcall</tt> function. So how\ncan this possibly work? The FFI library provides the <tt>ffi.C</tt>\ndefault C&nbsp;library namespace, which allows calling functions from\nthe default set of libraries, like a C&nbsp;compiler would. Also, the\nFFI library automatically detects <tt>stdcall</tt> functions, so you\ndon't need to declare them as such.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> The <tt>poll()</tt>\nfunction takes a couple more arguments we're not going to use. You can\nsimply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt>\nfor the <tt>nfds</tt> parameter. Please note that the\nnumber&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>,\nunlike in C++. You really have to pass pointers to pointer arguments\nand numbers to number arguments.\n</p>\n<p style=\"font-size: 8pt;\">\nThe page on <a href=\"ext_ffi_semantics.html\">FFI semantics</a> has all\nof the gory details about\n<a href=\"ext_ffi_semantics.html#convert\">conversions between Lua\nobjects and C&nbsp;types</a>. For the most part you don't have to deal\nwith this, as it's performed automatically and it's carefully designed\nto bridge the semantic differences between Lua and C.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> Now that we have defined\nour own <tt>sleep()</tt> function, we can just call it from plain Lua\ncode. That wasn't so bad, huh? Turning these boring animated dots into\na fascinating best-selling game is left as an exercise for the reader.\n:-)\n</p>\n\n<h2 id=\"zlib\">Accessing the zlib Compression Library</h2>\n<p>\nThe following code shows how to access the <a\nhref=\"http://zlib.net/\">zlib</a> compression library from Lua code.\nWe'll define two convenience wrapper functions that take a string and\ncompress or uncompress it to another string:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n\n\n\n&#9313;\n\n\n&#9314;\n\n&#9315;\n\n\n&#9316;\n\n\n&#9317;\n\n\n\n\n\n\n\n&#9318;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">unsigned long compressBound(unsigned long sourceLen);\nint compress2(uint8_t *dest, unsigned long *destLen,\n\t      const uint8_t *source, unsigned long sourceLen, int level);\nint uncompress(uint8_t *dest, unsigned long *destLen,\n\t       const uint8_t *source, unsigned long sourceLen);</span>\n]]\nlocal zlib = ffi.load(ffi.os == \"Windows\" and \"zlib1\" or \"z\")\n\nlocal function compress(txt)\n  local n = zlib.compressBound(#txt)\n  local buf = ffi.new(\"uint8_t[?]\", n)\n  local buflen = ffi.new(\"unsigned long[1]\", n)\n  local res = zlib.compress2(buf, buflen, txt, #txt, 9)\n  assert(res == 0)\n  return ffi.string(buf, buflen[0])\nend\n\nlocal function uncompress(comp, n)\n  local buf = ffi.new(\"uint8_t[?]\", n)\n  local buflen = ffi.new(\"unsigned long[1]\", n)\n  local res = zlib.uncompress(buf, buflen, comp, #comp)\n  assert(res == 0)\n  return ffi.string(buf, buflen[0])\nend\n\n-- Simple test code.\nlocal txt = string.rep(\"abcd\", 1000)\nprint(\"Uncompressed size: \", #txt)\nlocal c = compress(txt)\nprint(\"Compressed size: \", #c)\nlocal txt2 = uncompress(c, #txt)\nassert(txt2 == txt)\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines some of the\nC&nbsp;functions provided by zlib. For the sake of this example, some\ntype indirections have been reduced and it uses the pre-defined\nfixed-size integer types, while still adhering to the zlib API/ABI.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> This loads the zlib shared\nlibrary. On POSIX systems it's named <tt>libz.so</tt> and usually\ncomes pre-installed. Since <tt>ffi.load()</tt> automatically adds any\nmissing standard prefixes/suffixes, we can simply load the\n<tt>\"z\"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and\nyou'll have to download it first from the\n<a href=\"http://zlib.net/\"><span class=\"ext\">&raquo;</span>&nbsp;zlib site</a>. The check for\n<tt>ffi.os</tt> makes sure we pass the right name to\n<tt>ffi.load()</tt>.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> First, the maximum size of\nthe compression buffer is obtained by calling the\n<tt>zlib.compressBound</tt> function with the length of the\nuncompressed string. The next line allocates a byte buffer of this\nsize. The <tt>[?]</tt> in the type specification indicates a\nvariable-length array (VLA). The actual number of elements of this\narray is given as the 2nd argument to <tt>ffi.new()</tt>.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> This may look strange at\nfirst, but have a look at the declaration of the <tt>compress2</tt>\nfunction from zlib: the destination length is defined as a pointer!\nThis is because you pass in the maximum buffer size and get back the\nactual length that was used.\n</p>\n<p>\nIn C you'd pass in the address of a local variable\n(<tt>&amp;buflen</tt>). But since there's no address-of operator in\nLua, we'll just pass in a one-element array. Conveniently it can be\ninitialized with the maximum buffer size in one step. Calling the\nactual <tt>zlib.compress2</tt> function is then straightforward.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> We want to return the\ncompressed data as a Lua string, so we'll use <tt>ffi.string()</tt>.\nIt needs a pointer to the start of the data and the actual length. The\nlength has been returned in the <tt>buflen</tt> array, so we'll just\nget it from there.\n</p>\n<p style=\"font-size: 8pt;\">\nNote that since the function returns now, the <tt>buf</tt> and\n<tt>buflen</tt> variables will eventually be garbage collected. This\nis fine, because <tt>ffi.string()</tt> has copied the contents to a\nnewly created (interned) Lua string. If you plan to call this function\nlots of times, consider reusing the buffers and/or handing back the\nresults in buffers instead of strings. This will reduce the overhead\nfor garbage collection and string interning.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> The <tt>uncompress</tt>\nfunctions does the exact opposite of the <tt>compress</tt> function.\nThe compressed data doesn't include the size of the original string,\nso this needs to be passed in. Otherwise no surprises here.\n</p>\n<p>\n<span class=\"mark\">&#9318;</span> The code, that makes use\nof the functions we just defined, is just plain Lua code. It doesn't\nneed to know anything about the LuaJIT FFI &mdash; the convenience\nwrapper functions completely hide it.\n</p>\n<p>\nOne major advantage of the LuaJIT FFI is that you are now able to\nwrite those wrappers <em>in Lua</em>. And at a fraction of the time it\nwould cost you to create an extra C&nbsp;module using the Lua/C API.\nMany of the simpler C&nbsp;functions can probably be used directly\nfrom your Lua code, without any wrappers.\n</p>\n<p style=\"font-size: 8pt;\">\nSide note: the zlib API uses the <tt>long</tt> type for passing\nlengths and sizes around. But all those zlib functions actually only\ndeal with 32&nbsp;bit values. This is an unfortunate choice for a\npublic API, but may be explained by zlib's history &mdash; we'll just\nhave to deal with it.\n</p>\n<p style=\"font-size: 8pt;\">\nFirst, you should know that a <tt>long</tt> is a 64&nbsp;bit type e.g.\non POSIX/x64 systems, but a 32&nbsp;bit type on Windows/x64 and on\n32&nbsp;bit systems. Thus a <tt>long</tt> result can be either a plain\nLua number or a boxed 64&nbsp;bit integer cdata object, depending on\nthe target system.\n</p>\n<p style=\"font-size: 8pt;\">\nOk, so the <tt>ffi.*</tt> functions generally accept cdata objects\nwherever you'd want to use a number. That's why we get a away with\npassing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua\nlibrary functions or modules don't know how to deal with this. So for\nmaximum portability one needs to use <tt>tonumber()</tt> on returned\n<tt>long</tt> results before passing them on. Otherwise the\napplication might work on some systems, but would fail in a POSIX/x64\nenvironment.\n</p>\n\n<h2 id=\"metatype\">Defining Metamethods for a C&nbsp;Type</h2>\n<p>\nThe following code explains how to define metamethods for a C type.\nWe define a simple point type and add some operations to it:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n&#9313;\n\n&#9314;\n\n&#9315;\n\n\n\n&#9316;\n\n&#9317;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">typedef struct { double x, y; } point_t;</span>\n]]\n\nlocal point\nlocal mt = {\n  __add = function(a, b) return point(a.x+b.x, a.y+b.y) end,\n  __len = function(a) return math.sqrt(a.x*a.x + a.y*a.y) end,\n  __index = {\n    area = function(a) return a.x*a.x + a.y*a.y end,\n  },\n}\npoint = ffi.metatype(\"point_t\", mt)\n\nlocal a = point(3, 4)\nprint(a.x, a.y)  --> 3  4\nprint(#a)        --> 5\nprint(a:area())  --> 25\nlocal b = a + point(0.5, 8)\nprint(#b)        --> 12.5\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines the C&nbsp;type for a\ntwo-dimensional point object.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> We have to declare the variable\nholding the point constructor first, because it's used inside of a\nmetamethod.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Let's define an <tt>__add</tt>\nmetamethod which adds the coordinates of two points and creates a new\npoint object. For simplicity, this function assumes that both arguments\nare points. But it could be any mix of objects, if at least one operand\nis of the required type (e.g. adding a point plus a number or vice\nversa). Our <tt>__len</tt> metamethod returns the distance of a point to\nthe origin.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> If we run out of operators, we can\ndefine named methods, too. Here the <tt>__index</tt> table defines an\n<tt>area</tt> function. For custom indexing needs, one might want to\ndefine <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> This associates the metamethods with\nour C&nbsp;type. This only needs to be done once. For convenience, a\nconstructor is returned by\n<a href=\"ext_ffi_api.html#ffi_metatype\"><tt>ffi.metatype()</tt></a>.\nWe're not required to use it, though. The original C&nbsp;type can still\nbe used e.g. to create an array of points. The metamethods automatically\napply to any and all uses of this type.\n</p>\n<p>\nPlease note that the association with a metatable is permanent and\n<b>the metatable must not be modified afterwards!</b> Ditto for the\n<tt>__index</tt> table.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> Here are some simple usage examples\nfor the point type and their expected results. The pre-defined\noperations (such as <tt>a.x</tt>) can be freely mixed with the newly\ndefined metamethods. Note that <tt>area</tt> is a method and must be\ncalled with the Lua syntax for methods: <tt>a:area()</tt>, not\n<tt>a.area()</tt>.\n</p>\n<p>\nThe C&nbsp;type metamethod mechanism is most useful when used in\nconjunction with C&nbsp;libraries that are written in an object-oriented\nstyle. Creators return a pointer to a new instance and methods take an\ninstance pointer as the first argument. Sometimes you can just point\n<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the\ndestructor and you're done. But often enough you'll want to add\nconvenience wrappers, e.g. to return actual Lua strings or when\nreturning multiple values.\n</p>\n<p>\nSome C libraries only declare instance pointers as an opaque\n<tt>void&nbsp;*</tt> type. In this case you can use a fake type for all\ndeclarations, e.g. a pointer to a named (incomplete) struct will do:\n<tt>typedef struct foo_type *foo_handle</tt>. The C&nbsp;side doesn't\nknow what you declare with the LuaJIT FFI, but as long as the underlying\ntypes are compatible, everything still works.\n</p>\n\n<h2 id=\"idioms\">Translating C&nbsp;Idioms</h2>\n<p>\nHere's a list of common C&nbsp;idioms and their translation to the\nLuaJIT FFI:\n</p>\n<table class=\"idiomtable\">\n<tr class=\"idiomhead\">\n<td class=\"idiomdesc\">Idiom</td>\n<td class=\"idiomc\">C&nbsp;code</td>\n<td class=\"idiomlua\">Lua code</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"idiomdesc\">Pointer dereference<br><tt>int *p;</tt></td><td class=\"idiomc\"><tt>x = *p;<br>*p = y;</tt></td><td class=\"idiomlua\"><tt>x = <b>p[0]</b><br><b>p[0]</b> = y</tt></td></tr>\n<tr class=\"even\">\n<td class=\"idiomdesc\">Pointer indexing<br><tt>int i, *p;</tt></td><td class=\"idiomc\"><tt>x = p[i];<br>p[i+1] = y;</tt></td><td class=\"idiomlua\"><tt>x = p[i]<br>p[i+1] = y</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Array indexing<br><tt>int i, a[];</tt></td><td class=\"idiomc\"><tt>x = a[i];<br>a[i+1] = y;</tt></td><td class=\"idiomlua\"><tt>x = a[i]<br>a[i+1] = y</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\"><tt>struct</tt>/<tt>union</tt> dereference<br><tt>struct foo s;</tt></td><td class=\"idiomc\"><tt>x = s.field;<br>s.field = y;</tt></td><td class=\"idiomlua\"><tt>x = s.field<br>s.field = y</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\"><tt>struct</tt>/<tt>union</tt> pointer deref.<br><tt>struct foo *sp;</tt></td><td class=\"idiomc\"><tt>x = sp->field;<br>sp->field = y;</tt></td><td class=\"idiomlua\"><tt>x = <b>s.field</b><br><b>s.field</b> = y</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\">Pointer arithmetic<br><tt>int i, *p;</tt></td><td class=\"idiomc\"><tt>x = p + i;<br>y = p - i;</tt></td><td class=\"idiomlua\"><tt>x = p + i<br>y = p - i</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Pointer difference<br><tt>int *p1, *p2;</tt></td><td class=\"idiomc\"><tt>x = p1 - p2;</tt></td><td class=\"idiomlua\"><tt>x = p1 - p2</tt></td></tr>\n<tr class=\"even\">\n<td class=\"idiomdesc\">Array element pointer<br><tt>int i, a[];</tt></td><td class=\"idiomc\"><tt>x = &amp;a[i];</tt></td><td class=\"idiomlua\"><tt>x = <b>a+i</b></tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Cast pointer to address<br><tt>int *p;</tt></td><td class=\"idiomc\"><tt>x = (intptr_t)p;</tt></td><td class=\"idiomlua\"><tt>x = <b>tonumber(<br>&nbsp;ffi.cast(\"intptr_t\",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p))</b></tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\">Functions with outargs<br><tt>void foo(int *inoutlen);</tt></td><td class=\"idiomc\"><tt>int len = x;<br>foo(&amp;len);<br>y = len;</tt></td><td class=\"idiomlua\"><tt><b>local len =<br>&nbsp;&nbsp;ffi.new(\"int[1]\", x)<br>foo(len)<br>y = len[0]</b></tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\"><a href=\"ext_ffi_semantics.html#convert_vararg\">Vararg conversions</a><br><tt>int printf(char *fmt, ...);</tt></td><td class=\"idiomc\"><tt>printf(\"%g\", 1.0);<br>printf(\"%d\", 1);<br>&nbsp;</tt></td><td class=\"idiomlua\"><tt>printf(\"%g\", 1);<br>printf(\"%d\",<br>&nbsp;&nbsp;<b>ffi.new(\"int\", 1)</b>)</tt></td></tr>\n</table>\n\n<h2 id=\"cache\">To Cache or Not to Cache</h2>\n<p>\nIt's a common Lua idiom to cache library functions in local variables\nor upvalues, e.g.:\n</p>\n<pre class=\"code\">\nlocal byte, char = string.byte, string.char\nlocal function foo(x)\n  return char(byte(x)+1)\nend\n</pre>\n<p>\nThis replaces several hash-table lookups with a (faster) direct use of\na local or an upvalue. This is less important with LuaJIT, since the\nJIT compiler optimizes hash-table lookups a lot and is even able to\nhoist most of them out of the inner loops. It can't eliminate\n<em>all</em> of them, though, and it saves some typing for often-used\nfunctions. So there's still a place for this, even with LuaJIT.\n</p>\n<p>\nThe situation is a bit different with C&nbsp;function calls via the\nFFI library. The JIT compiler has special logic to eliminate <em>all\nof the lookup overhead</em> for functions resolved from a\n<a href=\"ext_ffi_semantics.html#clib\">C&nbsp;library namespace</a>!\nThus it's not helpful and actually counter-productive to cache\nindividual C&nbsp;functions like this:\n</p>\n<pre class=\"code\">\nlocal <b>funca</b>, <b>funcb</b> = ffi.C.funca, ffi.C.funcb -- <span style=\"color:#c00000;\">Not helpful!</span>\nlocal function foo(x, n)\n  for i=1,n do <b>funcb</b>(<b>funca</b>(x, i), 1) end\nend\n</pre>\n<p>\nThis turns them into indirect calls and generates bigger and slower\nmachine code. Instead you'll want to cache the namespace itself and\nrely on the JIT compiler to eliminate the lookups:\n</p>\n<pre class=\"code\">\nlocal <b>C</b> = ffi.C          -- <span style=\"color:#00a000;\">Instead use this!</span>\nlocal function foo(x, n)\n  for i=1,n do <b>C.funcb</b>(<b>C.funca</b>(x, i), 1) end\nend\n</pre>\n<p>\nThis generates both shorter and faster code. So <b>don't cache\nC&nbsp;functions</b>, but <b>do</b> cache namespaces! Most often the\nnamespace is already in a local variable at an outer scope, e.g. from\n<tt>local&nbsp;lib&nbsp;=&nbsp;ffi.load(...)</tt>. Note that copying\nit to a local variable in the function scope is unnecessary.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_jit.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>jit.* Library</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1><tt>jit.*</tt> Library</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThe functions in this built-in module control the behavior of the JIT\ncompiler engine. Note that JIT-compilation is fully automatic &mdash;\nyou probably won't need to use any of the following functions unless\nyou have special needs.\n</p>\n\n<h3 id=\"jit_onoff\"><tt>jit.on()<br>\njit.off()</tt></h3>\n<p>\nTurns the whole JIT compiler on (default) or off.\n</p>\n<p>\nThese functions are typically used with the command line options\n<tt>-j on</tt> or <tt>-j off</tt>.\n</p>\n\n<h3 id=\"jit_flush\"><tt>jit.flush()</tt></h3>\n<p>\nFlushes the whole cache of compiled code.\n</p>\n\n<h3 id=\"jit_onoff_func\"><tt>jit.on(func|true [,true|false])<br>\njit.off(func|true [,true|false])<br>\njit.flush(func|true [,true|false])</tt></h3>\n<p>\n<tt>jit.on</tt> enables JIT compilation for a Lua function (this is\nthe default).\n</p>\n<p>\n<tt>jit.off</tt> disables JIT compilation for a Lua function and\nflushes any already compiled code from the code cache.\n</p>\n<p>\n<tt>jit.flush</tt> flushes the code, but doesn't affect the\nenable/disable status.\n</p>\n<p>\nThe current function, i.e. the Lua function calling this library\nfunction, can also be specified by passing <tt>true</tt> as the first\nargument.\n</p>\n<p>\nIf the second argument is <tt>true</tt>, JIT compilation is also\nenabled, disabled or flushed recursively for all sub-functions of a\nfunction. With <tt>false</tt> only the sub-functions are affected.\n</p>\n<p>\nThe <tt>jit.on</tt> and <tt>jit.off</tt> functions only set a flag\nwhich is checked when the function is about to be compiled. They do\nnot trigger immediate compilation.\n</p>\n<p>\nTypical usage is <tt>jit.off(true, true)</tt> in the main chunk\nof a module to turn off JIT compilation for the whole module for\ndebugging purposes.\n</p>\n\n<h3 id=\"jit_flush_tr\"><tt>jit.flush(tr)</tt></h3>\n<p>\nFlushes the root trace, specified by its number, and all of its side\ntraces from the cache. The code for the trace will be retained as long\nas there are any other traces which link to it.\n</p>\n\n<h3 id=\"jit_status\"><tt>status, ... = jit.status()</tt></h3>\n<p>\nReturns the current status of the JIT compiler. The first result is\neither <tt>true</tt> or <tt>false</tt> if the JIT compiler is turned\non or off. The remaining results are strings for CPU-specific features\nand enabled optimizations.\n</p>\n\n<h3 id=\"jit_version\"><tt>jit.version</tt></h3>\n<p>\nContains the LuaJIT version string.\n</p>\n\n<h3 id=\"jit_version_num\"><tt>jit.version_num</tt></h3>\n<p>\nContains the version number of the LuaJIT core. Version xx.yy.zz\nis represented by the decimal number xxyyzz.\n</p>\n\n<h3 id=\"jit_os\"><tt>jit.os</tt></h3>\n<p>\nContains the target OS name:\n\"Windows\", \"Linux\", \"OSX\", \"BSD\", \"POSIX\" or \"Other\".\n</p>\n\n<h3 id=\"jit_arch\"><tt>jit.arch</tt></h3>\n<p>\nContains the target architecture name:\n\"x86\", \"x64\", \"arm\", \"ppc\", or \"mips\".\n</p>\n\n<h2 id=\"jit_opt\"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>\n<p>\nThis sub-module provides the backend for the <tt>-O</tt> command line\noption.\n</p>\n<p>\nYou can also use it programmatically, e.g.:\n</p>\n<pre class=\"code\">\njit.opt.start(2) -- same as -O2\njit.opt.start(\"-dce\")\njit.opt.start(\"hotloop=10\", \"hotexit=2\")\n</pre>\n<p>\nUnlike in LuaJIT 1.x, the module is built-in and\n<b>optimization is turned on by default!</b>\nIt's no longer necessary to run <tt>require(\"jit.opt\").start()</tt>,\nwhich was one of the ways to enable optimization.\n</p>\n\n<h2 id=\"jit_util\"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>\n<p>\nThis sub-module holds functions to introspect the bytecode, generated\ntraces, the IR and the generated machine code. The functionality\nprovided by this module is still in flux and therefore undocumented.\n</p>\n<p>\nThe debug modules <tt>-jbc</tt>, <tt>-jv</tt> and <tt>-jdump</tt> make\nextensive use of these functions. Please check out their source code,\nif you want to know more.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/ext_profiler.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Profiler</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Profiler</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a class=\"current\" href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT has an integrated statistical profiler with very low overhead. It\nallows sampling the currently executing stack and other parameters in\nregular intervals.\n</p>\n<p>\nThe integrated profiler can be accessed from three levels:\n</p>\n<ul>\n<li>The <a href=\"#hl_profiler\">bundled high-level profiler</a>, invoked by the\n<a href=\"#j_p\"><tt>-jp</tt></a> command line option.</li>\n<li>A <a href=\"#ll_lua_api\">low-level Lua API</a> to control the profiler.</li>\n<li>A <a href=\"#ll_c_api\">low-level C API</a> to control the profiler.</li>\n</ul>\n\n<h2 id=\"hl_profiler\">High-Level Profiler</h2>\n<p>\nThe bundled high-level profiler offers basic profiling functionality. It\ngenerates simple textual summaries or source code annotations. It can be\naccessed with the <a href=\"#j_p\"><tt>-jp</tt></a> command line option\nor from Lua code by loading the underlying <tt>jit.p</tt> module.\n</p>\n<p>\nTo cut to the chase &mdash; run this to get a CPU usage profile by\nfunction name:\n</p>\n<pre class=\"code\">\nluajit -jp myapp.lua\n</pre>\n<p>\nIt's <em>not</em> a stated goal of the bundled profiler to add every\npossible option or to cater for special profiling needs. The low-level\nprofiler APIs are documented below. They may be used by third-party\nauthors to implement advanced functionality, e.g. IDE integration or\ngraphical profilers.\n</p>\n<p>\nNote: Sampling works for both interpreted and JIT-compiled code. The\nresults for JIT-compiled code may sometimes be surprising. LuaJIT\nheavily optimizes and inlines Lua code &mdash; there's no simple\none-to-one correspondence between source code lines and the sampled\nmachine code.\n</p>\n\n<h3 id=\"j_p\"><tt>-jp=[options[,output]]</tt></h3>\n<p>\nThe <tt>-jp</tt> command line option starts the high-level profiler.\nWhen the application run by the command line terminates, the profiler\nstops and writes the results to <tt>stdout</tt> or to the specified\n<tt>output</tt> file.\n</p>\n<p>\nThe <tt>options</tt> argument specifies how the profiling is to be\nperformed:\n</p>\n<ul>\n<li><tt>f</tt> &mdash; Stack dump: function name, otherwise module:line.\nThis is the default mode.</li>\n<li><tt>F</tt> &mdash; Stack dump: ditto, but dump module:name.</li>\n<li><tt>l</tt> &mdash; Stack dump: module:line.</li>\n<li><tt>&lt;number&gt;</tt> &mdash; stack dump depth (callee &larr;\ncaller). Default: 1.</li>\n<li><tt>-&lt;number&gt;</tt> &mdash; Inverse stack dump depth (caller\n&rarr; callee).</li>\n<li><tt>s</tt> &mdash; Split stack dump after first stack level. Implies\ndepth&nbsp;&ge;&nbsp;2 or depth&nbsp;&le;&nbsp;-2.</li>\n<li><tt>p</tt> &mdash; Show full path for module names.</li>\n<li><tt>v</tt> &mdash; Show VM states.</li>\n<li><tt>z</tt> &mdash; Show <a href=\"#jit_zone\">zones</a>.</li>\n<li><tt>r</tt> &mdash; Show raw sample counts. Default: show percentages.</li>\n<li><tt>a</tt> &mdash; Annotate excerpts from source code files.</li>\n<li><tt>A</tt> &mdash; Annotate complete source code files.</li>\n<li><tt>G</tt> &mdash; Produce raw output suitable for graphical tools.</li>\n<li><tt>m&lt;number&gt;</tt> &mdash; Minimum sample percentage to be shown.\nDefault: 3%.</li>\n<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds.\nDefault: 10ms.<br>\nNote: The actual sampling precision is OS-dependent.</li>\n</ul>\n<p>\nThe default output for <tt>-jp</tt> is a list of the most CPU consuming\nspots in the application. Increasing the stack dump depth with (say)\n<tt>-jp=2</tt> may help to point out the main callers or callees of\nhotspots. But sample aggregation is still flat per unique stack dump.\n</p>\n<p>\nTo get a two-level view (split view) of callers/callees, use\n<tt>-jp=s</tt> or <tt>-jp=-s</tt>. The percentages shown for the second\nlevel are relative to the first level.\n</p>\n<p>\nTo see how much time is spent in each line relative to a function, use\n<tt>-jp=fl</tt>.\n</p>\n<p>\nTo see how much time is spent in different VM states or\n<a href=\"#jit_zone\">zones</a>, use <tt>-jp=v</tt> or <tt>-jp=z</tt>.\n</p>\n<p>\nCombinations of <tt>v/z</tt> with <tt>f/F/l</tt> produce two-level\nviews, e.g. <tt>-jp=vf</tt> or <tt>-jp=fv</tt>. This shows the time\nspent in a VM state or zone vs. hotspots. This can be used to answer\nquestions like \"Which time consuming functions are only interpreted?\" or\n\"What's the garbage collector overhead for a specific function?\".\n</p>\n<p>\nMultiple options can be combined &mdash; but not all combinations make\nsense, see above. E.g. <tt>-jp=3si4m1</tt> samples three stack levels\ndeep in 4ms intervals and shows a split view of the CPU consuming\nfunctions and their callers with a 1% threshold.\n</p>\n<p>\nSource code annotations produced by <tt>-jp=a</tt> or <tt>-jp=A</tt> are\nalways flat and at the line level. Obviously, the source code files need\nto be readable by the profiler script.\n</p>\n<p>\nThe high-level profiler can also be started and stopped from Lua code with:\n</p>\n<pre class=\"code\">\nrequire(\"jit.p\").start(options, output)\n...\nrequire(\"jit.p\").stop()\n</pre>\n\n<h3 id=\"jit_zone\"><tt>jit.zone</tt> &mdash; Zones</h3>\n<p>\nZones can be used to provide information about different parts of an\napplication to the high-level profiler. E.g. a game could make use of an\n<tt>\"AI\"</tt> zone, a <tt>\"PHYS\"</tt> zone, etc. Zones are hierarchical,\norganized as a stack.\n</p>\n<p>\nThe <tt>jit.zone</tt> module needs to be loaded explicitly:\n</p>\n<pre class=\"code\">\nlocal zone = require(\"jit.zone\")\n</pre>\n<ul>\n<li><tt>zone(\"name\")</tt> pushes a named zone to the zone stack.</li>\n<li><tt>zone()</tt> pops the current zone from the zone stack and\nreturns its name.</li>\n<li><tt>zone:get()</tt> returns the current zone name or <tt>nil</tt>.</li>\n<li><tt>zone:flush()</tt> flushes the zone stack.</li>\n</ul>\n<p>\nTo show the time spent in each zone use <tt>-jp=z</tt>. To show the time\nspent relative to hotspots use e.g. <tt>-jp=zf</tt> or <tt>-jp=fz</tt>.\n</p>\n\n<h2 id=\"ll_lua_api\">Low-level Lua API</h2>\n<p>\nThe <tt>jit.profile</tt> module gives access to the low-level API of the\nprofiler from Lua code. This module needs to be loaded explicitly:\n<pre class=\"code\">\nlocal profile = require(\"jit.profile\")\n</pre>\n<p>\nThis module can be used to implement your own higher-level profiler.\nA typical profiling run starts the profiler, captures stack dumps in\nthe profiler callback, adds them to a hash table to aggregate the number\nof samples, stops the profiler and then analyzes all of the captured\nstack dumps. Other parameters can be sampled in the profiler callback,\ntoo. But it's important not to spend too much time in the callback,\nsince this may skew the statistics.\n</p>\n\n<h3 id=\"profile_start\"><tt>profile.start(mode, cb)</tt>\n&mdash; Start profiler</h3>\n<p>\nThis function starts the profiler. The <tt>mode</tt> argument is a\nstring holding options:\n</p>\n<ul>\n<li><tt>f</tt> &mdash; Profile with precision down to the function level.</li>\n<li><tt>l</tt> &mdash; Profile with precision down to the line level.</li>\n<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds (default\n10ms).</br>\nNote: The actual sampling precision is OS-dependent.\n</li>\n</ul>\n<p>\nThe <tt>cb</tt> argument is a callback function which is called with\nthree arguments: <tt>(thread, samples, vmstate)</tt>. The callback is\ncalled on a separate coroutine, the <tt>thread</tt> argument is the\nstate that holds the stack to sample for profiling. Note: do\n<em>not</em> modify the stack of that state or call functions on it.\n</p>\n<p>\n<tt>samples</tt> gives the number of accumulated samples since the last\ncallback (usually 1).\n</p>\n<p>\n<tt>vmstate</tt> holds the VM state at the time the profiling timer\ntriggered. This may or may not correspond to the state of the VM when\nthe profiling callback is called. The state is either <tt>'N'</tt>\nnative (compiled) code, <tt>'I'</tt> interpreted code, <tt>'C'</tt>\nC&nbsp;code, <tt>'G'</tt> the garbage collector, or <tt>'J'</tt> the JIT\ncompiler.\n</p>\n\n<h3 id=\"profile_stop\"><tt>profile.stop()</tt>\n&mdash; Stop profiler</h3>\n<p>\nThis function stops the profiler.\n</p>\n\n<h3 id=\"profile_dump\"><tt>dump = profile.dumpstack([thread,] fmt, depth)</tt>\n&mdash; Dump stack </h3>\n<p>\nThis function allows taking stack dumps in an efficient manner. It\nreturns a string with a stack dump for the <tt>thread</tt> (coroutine),\nformatted according to the <tt>fmt</tt> argument:\n</p>\n<ul>\n<li><tt>p</tt> &mdash; Preserve the full path for module names. Otherwise\nonly the file name is used.</li>\n<li><tt>f</tt> &mdash; Dump the function name if it can be derived. Otherwise\nuse module:line.</li>\n<li><tt>F</tt> &mdash; Ditto, but dump module:name.</li>\n<li><tt>l</tt> &mdash; Dump module:line.</li>\n<li><tt>Z</tt> &mdash; Zap the following characters for the last dumped\nframe.</li>\n<li>All other characters are added verbatim to the output string.</li>\n</ul>\n<p>\nThe <tt>depth</tt> argument gives the number of frames to dump, starting\nat the topmost frame of the thread. A negative number dumps the frames in\ninverse order.\n</p>\n<p>\nThe first example prints a list of the current module names and line\nnumbers of up to 10 frames in separate lines. The second example prints\nsemicolon-separated function names for all frames (up to 100) in inverse\norder:\n</p>\n<pre class=\"code\">\nprint(profile.dumpstack(thread, \"l\\n\", 10))\nprint(profile.dumpstack(thread, \"lZ;\", -100))\n</pre>\n\n<h2 id=\"ll_c_api\">Low-level C API</h2>\n<p>\nThe profiler can be controlled directly from C&nbsp;code, e.g. for\nuse by IDEs. The declarations are in <tt>\"luajit.h\"</tt> (see\n<a href=\"ext_c_api.html\">Lua/C API</a> extensions).\n</p>\n\n<h3 id=\"luaJIT_profile_start\"><tt>luaJIT_profile_start(L, mode, cb, data)</tt>\n&mdash; Start profiler</h3>\n<p>\nThis function starts the profiler. <a href=\"#profile_start\">See\nabove</a> for a description of the <tt>mode</tt> argument.\n</p>\n<p>\nThe <tt>cb</tt> argument is a callback function with the following\ndeclaration:\n</p>\n<pre class=\"code\">\ntypedef void (*luaJIT_profile_callback)(void *data, lua_State *L,\n                                        int samples, int vmstate);\n</pre>\n<p>\n<tt>data</tt> is available for use by the callback. <tt>L</tt> is the\nstate that holds the stack to sample for profiling. Note: do\n<em>not</em> modify this stack or call functions on this stack &mdash;\nuse a separate coroutine for this purpose. <a href=\"#profile_start\">See\nabove</a> for a description of <tt>samples</tt> and <tt>vmstate</tt>.\n</p>\n\n<h3 id=\"luaJIT_profile_stop\"><tt>luaJIT_profile_stop(L)</tt>\n&mdash; Stop profiler</h3>\n<p>\nThis function stops the profiler.\n</p>\n\n<h3 id=\"luaJIT_profile_dumpstack\"><tt>p = luaJIT_profile_dumpstack(L, fmt, depth, len)</tt>\n&mdash; Dump stack </h3>\n<p>\nThis function allows taking stack dumps in an efficient manner.\n<a href=\"#profile_dump\">See above</a> for a description of <tt>fmt</tt>\nand <tt>depth</tt>.\n</p>\n<p>\nThis function returns a <tt>const&nbsp;char&nbsp;*</tt> pointing to a\nprivate string buffer of the profiler. The <tt>int&nbsp;*len</tt>\nargument returns the length of the output string. The buffer is\noverwritten on the next call and deallocated when the profiler stops.\nYou either need to consume the content immediately or copy it for later\nuse.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/extensions.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Extensions</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.exc {\n  line-height: 1.2;\n}\ntr.exchead td {\n  font-weight: bold;\n}\ntd.excplatform {\n  width: 48%;\n}\ntd.exccompiler {\n  width: 29%;\n}\ntd.excinterop {\n  width: 23%;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Extensions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is fully upwards-compatible with Lua 5.1. It supports all\n<a href=\"http://www.lua.org/manual/5.1/manual.html#5\"><span class=\"ext\">&raquo;</span>&nbsp;standard Lua\nlibrary functions</a> and the full set of\n<a href=\"http://www.lua.org/manual/5.1/manual.html#3\"><span class=\"ext\">&raquo;</span>&nbsp;Lua/C API\nfunctions</a>.\n</p>\n<p>\nLuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic\nloader level. This means you can compile a C&nbsp;module against the\nstandard Lua headers and load the same shared library from either Lua\nor LuaJIT.\n</p>\n<p>\nLuaJIT extends the standard Lua VM with new functionality and adds\nseveral extension modules. Please note this page is only about\n<em>functional</em> enhancements and not about performance enhancements,\nsuch as the optimized VM, the faster interpreter or the JIT compiler.\n</p>\n\n<h2 id=\"modules\">Extensions Modules</h2>\n<p>\nLuaJIT comes with several built-in extension modules:\n</p>\n\n<h3 id=\"bit\"><tt>bit.*</tt> &mdash; Bitwise operations</h3>\n<p>\nLuaJIT supports all bitwise operations as defined by\n<a href=\"http://bitop.luajit.org\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp</a>:\n</p>\n<pre class=\"code\">\nbit.tobit  bit.tohex  bit.bnot    bit.band bit.bor  bit.bxor\nbit.lshift bit.rshift bit.arshift bit.rol  bit.ror  bit.bswap\n</pre>\n<p>\nThis module is a LuaJIT built-in &mdash; you don't need to download or\ninstall Lua BitOp. The Lua BitOp site has full documentation for all\n<a href=\"http://bitop.luajit.org/api.html\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp API functions</a>.\nThe FFI adds support for\n<a href=\"ext_ffi_semantics.html#cdata_arith\">64&nbsp;bit bitwise operations</a>,\nusing the same API functions.\n</p>\n<p>\nPlease make sure to <tt>require</tt> the module before using any of\nits functions:\n</p>\n<pre class=\"code\">\nlocal bit = require(\"bit\")\n</pre>\n<p>\nAn already installed Lua BitOp module is ignored by LuaJIT.\nThis way you can use bit operations from both Lua and LuaJIT on a\nshared installation.\n</p>\n\n<h3 id=\"ffi\"><tt>ffi.*</tt> &mdash; FFI library</h3>\n<p>\nThe <a href=\"ext_ffi.html\">FFI library</a> allows calling external\nC&nbsp;functions and the use of C&nbsp;data structures from pure Lua\ncode.\n</p>\n\n<h3 id=\"jit\"><tt>jit.*</tt> &mdash; JIT compiler control</h3>\n<p>\nThe functions in this module\n<a href=\"ext_jit.html\">control the behavior of the JIT compiler engine</a>.\n</p>\n\n<h3 id=\"c_api\">C API extensions</h3>\n<p>\nLuaJIT adds some\n<a href=\"ext_c_api.html\">extra functions to the Lua/C API</a>.\n</p>\n\n<h3 id=\"profiler\">Profiler</h3>\n<p>\nLuaJIT has an <a href=\"ext_profiler.html\">integrated profiler</a>.\n</p>\n\n<h2 id=\"library\">Enhanced Standard Library Functions</h2>\n\n<h3 id=\"xpcall\"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>\n<p>\nUnlike the standard implementation in Lua 5.1, <tt>xpcall()</tt>\npasses any arguments after the error function to the function\nwhich is called in a protected context.\n</p>\n\n<h3 id=\"load\"><tt>loadfile()</tt> etc. handle UTF-8 source code</h3>\n<p>\nNon-ASCII characters are handled transparently by the Lua source code parser.\nThis allows the use of UTF-8 characters in identifiers and strings.\nA UTF-8 BOM is skipped at the start of the source code.\n</p>\n\n<h3 id=\"tostring\"><tt>tostring()</tt> etc. canonicalize NaN and &plusmn;Inf</h3>\n<p>\nAll number-to-string conversions consistently convert non-finite numbers\nto the same strings on all platforms. NaN results in <tt>\"nan\"</tt>,\npositive infinity results in <tt>\"inf\"</tt> and negative infinity results\nin <tt>\"-inf\"</tt>.\n</p>\n\n<h3 id=\"tonumber\"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3>\n<p>\nAll string-to-number conversions consistently convert integer and\nfloating-point inputs in decimal, hexadecimal and binary on all platforms.\n<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous\nproblems with poor C library implementations. The builtin conversion\nfunction provides full precision according to the IEEE-754 standard, it\nworks independently of the current locale and it supports hex floating-point\nnumbers (e.g. <tt>0x1.5p-3</tt>).\n</p>\n\n<h3 id=\"string_dump\"><tt>string.dump(f [,strip])</tt> generates portable bytecode</h3>\n<p>\nAn extra argument has been added to <tt>string.dump()</tt>. If set to\n<tt>true</tt>, 'stripped' bytecode without debug information is\ngenerated. This speeds up later bytecode loading and reduces memory\nusage. See also the\n<a href=\"running.html#opt_b\"><tt>-b</tt> command line option</a>.\n</p>\n<p>\nThe generated bytecode is portable and can be loaded on any architecture\nthat LuaJIT supports, independent of word size or endianess. However the\nbytecode compatibility versions must match. Bytecode stays compatible\nfor dot releases (x.y.0 &rarr; x.y.1), but may change with major or\nminor releases (2.0 &rarr; 2.1) or between any beta release. Foreign\nbytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.\n</p>\n<p>\nNote: <tt>LJ_GC64</tt> mode requires a different frame layout, which implies\na different, incompatible bytecode format for ports that use this mode (e.g.\nARM64). This may be rectified in the future.\n</p>\n\n<h3 id=\"table_new\"><tt>table.new(narray, nhash)</tt> allocates a pre-sized table</h3>\n<p>\nAn extra library function <tt>table.new()</tt> can be made available via\n<tt>require(\"table.new\")</tt>. This creates a pre-sized table, just like\nthe C API equivalent <tt>lua_createtable()</tt>. This is useful for big\ntables if the final table size is known and automatic table resizing is\ntoo expensive.\n</p>\n\n<h3 id=\"table_clear\"><tt>table.clear(tab)</tt> clears a table</h3>\n<p>\nAn extra library function <tt>table.clear()</tt> can be made available\nvia <tt>require(\"table.clear\")</tt>. This clears all keys and values\nfrom a table, but preserves the allocated array/hash sizes. This is\nuseful when a table, which is linked from multiple places, needs to be\ncleared and/or when recycling a table for use by the same context. This\navoids managing backlinks, saves an allocation and the overhead of\nincremental array/hash part growth.\n</p>\n<p>\nPlease note this function is meant for very specific situations. In most\ncases it's better to replace the (usually single) link with a new table\nand let the GC do its work.\n</p>\n\n<h3 id=\"math_random\">Enhanced PRNG for <tt>math.random()</tt></h3>\n<p>\nLuaJIT uses a Tausworthe PRNG with period 2^223 to implement\n<tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of\nthe PRNG results is much superior compared to the standard Lua\nimplementation which uses the platform-specific ANSI rand().\n</p>\n<p>\nThe PRNG generates the same sequences from the same seeds on all\nplatforms and makes use of all bits in the seed argument.\n<tt>math.random()</tt> without arguments generates 52 pseudo-random bits\nfor every call. The result is uniformly distributed between 0.0 and 1.0.\nIt's correctly scaled up and rounded for <tt>math.random(n&nbsp;[,m])</tt> to\npreserve uniformity.\n</p>\n\n<h3 id=\"io\"><tt>io.*</tt> functions handle 64&nbsp;bit file offsets</h3>\n<p>\nThe file I/O functions in the standard <tt>io.*</tt> library handle\n64&nbsp;bit file offsets. In particular this means it's possible\nto open files larger than 2&nbsp;Gigabytes and to reposition or obtain\nthe current file position for offsets beyond 2&nbsp;GB\n(<tt>fp:seek()</tt> method).\n</p>\n\n<h3 id=\"debug_meta\"><tt>debug.*</tt> functions identify metamethods</h3>\n<p>\n<tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt> also return information\nabout invoked metamethods. The <tt>namewhat</tt> field is set to\n<tt>\"metamethod\"</tt> and the <tt>name</tt> field has the name of\nthe corresponding metamethod (e.g. <tt>\"__index\"</tt>).\n</p>\n\n<h2 id=\"resumable\">Fully Resumable VM</h2>\n<p>\nThe LuaJIT VM is fully resumable. This means you can yield from a\ncoroutine even across contexts, where this would not possible with\nthe standard Lua&nbsp;5.1 VM: e.g. you can yield across <tt>pcall()</tt>\nand <tt>xpcall()</tt>, across iterators and across metamethods.\n</p>\n\n<h2 id=\"lua52\">Extensions from Lua 5.2</h2>\n<p>\nLuaJIT supports some language and library extensions from Lua&nbsp;5.2.\nFeatures that are unlikely to break existing code are unconditionally\nenabled:\n</p>\n<ul>\n<li><tt>goto</tt> and <tt>::labels::</tt>.</li>\n<li>Hex escapes <tt>'\\x3F'</tt> and <tt>'\\*'</tt> escape in strings.</li>\n<li><tt>load(string|reader [, chunkname [,mode [,env]]])</tt>.</li>\n<li><tt>loadstring()</tt> is an alias for <tt>load()</tt>.</li>\n<li><tt>loadfile(filename [,mode [,env]])</tt>.</li>\n<li><tt>math.log(x [,base])</tt>.\n<li><tt>string.rep(s, n [,sep])</tt>.\n<li><tt>string.format()</tt>: <tt>%q</tt> reversible.\n<tt>%s</tt> checks <tt>__tostring</tt>.\n<tt>%a</tt> and <tt>\"%A</tt> added.</li>\n<li>String matching pattern <tt>%g</tt> added.</li>\n<li><tt>io.read(\"*L\")</tt>.</li>\n<li><tt>io.lines()</tt> and <tt>file:lines()</tt> process\n<tt>io.read()</tt> options.</li>\n<li><tt>os.exit(status|true|false [,close])</tt>.</li>\n<li><tt>package.searchpath(name, path [, sep [, rep]])</tt>.</li>\n<li><tt>package.loadlib(name, \"*\")</tt>.</li>\n<li><tt>debug.getinfo()</tt> returns <tt>nparams</tt> and <tt>isvararg</tt>\nfor option <tt>\"u\"</tt>.</li>\n<li><tt>debug.getlocal()</tt> accepts function instead of level.</li>\n<li><tt>debug.getlocal()</tt> and <tt>debug.setlocal()</tt> accept negative\nindexes for varargs.</li>\n<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle\nC&nbsp;functions.</li>\n<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>\n<li>Command line option <tt>-E</tt>.</li>\n<li>Command line checks <tt>__tostring</tt> for errors.</li>\n</ul>\n<p>\nOther features are only enabled, if LuaJIT is built with\n<tt>-DLUAJIT_ENABLE_LUA52COMPAT</tt>:\n</p>\n<ul>\n<li><tt>goto</tt> is a keyword and not a valid variable name anymore.</li>\n<li><tt>break</tt> can be placed anywhere. Empty statements (<tt>;;</tt>)\nare allowed.</li>\n<li><tt>__lt</tt>, <tt>__le</tt> are invoked for mixed types.</li>\n<li><tt>__len</tt> for tables. <tt>rawlen()</tt> library function.</li>\n<li><tt>pairs()</tt> and <tt>ipairs()</tt> check for <tt>__pairs</tt> and\n<tt>__ipairs</tt>.</li>\n<li><tt>coroutine.running()</tt> returns two results.</li>\n<li><tt>table.pack()</tt> and <tt>table.unpack()</tt>\n(same as <tt>unpack()</tt>).</li>\n<li><tt>io.write()</tt> and <tt>file:write()</tt> return file handle\ninstead of <tt>true</tt>.</li>\n<li><tt>os.execute()</tt> and <tt>pipe:close()</tt> return detailed\nexit status.</li>\n<li><tt>debug.setmetatable()</tt> returns object.</li>\n<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>\n<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.\n</ul>\n<p>\nNote: this provides only partial compatibility with Lua 5.2 at the\nlanguage and Lua library level. LuaJIT is API+ABI-compatible with\nLua&nbsp;5.1, which prevents implementing features that would otherwise\nbreak the Lua/C API and ABI (e.g. <tt>_ENV</tt>).\n</p>\n\n<h2 id=\"lua53\">Extensions from Lua 5.3</h2>\n<p>\nLuaJIT supports some extensions from Lua&nbsp;5.3:\n<ul>\n<li>Unicode escape <tt>'\\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.</li>\n</ul>\n\n<h2 id=\"exceptions\">C++ Exception Interoperability</h2>\n<p>\nLuaJIT has built-in support for interoperating with C++&nbsp;exceptions.\nThe available range of features depends on the target platform and\nthe toolchain used to compile LuaJIT:\n</p>\n<table class=\"exc\">\n<tr class=\"exchead\">\n<td class=\"excplatform\">Platform</td>\n<td class=\"exccompiler\">Compiler</td>\n<td class=\"excinterop\">Interoperability</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"excplatform\">POSIX/x64, DWARF2 unwinding</td>\n<td class=\"exccompiler\">GCC 4.3+</td>\n<td class=\"excinterop\"><b style=\"color: #00a000;\">Full</b></td>\n</tr>\n<tr class=\"even\">\n<td class=\"excplatform\">Other platforms, DWARF2 unwinding</td>\n<td class=\"exccompiler\">GCC</td>\n<td class=\"excinterop\"><b style=\"color: #c06000;\">Limited</b></td>\n</tr>\n<tr class=\"odd\">\n<td class=\"excplatform\">Windows/x64</td>\n<td class=\"exccompiler\">MSVC or WinSDK</td>\n<td class=\"excinterop\"><b style=\"color: #00a000;\">Full</b></td>\n</tr>\n<tr class=\"even\">\n<td class=\"excplatform\">Windows/x86</td>\n<td class=\"exccompiler\">Any</td>\n<td class=\"excinterop\"><b style=\"color: #a00000;\">No</b></td>\n</tr>\n<tr class=\"odd\">\n<td class=\"excplatform\">Other platforms</td>\n<td class=\"exccompiler\">Other compilers</td>\n<td class=\"excinterop\"><b style=\"color: #a00000;\">No</b></td>\n</tr>\n</table>\n<p>\n<b style=\"color: #00a000;\">Full interoperability</b> means:\n</p>\n<ul>\n<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,\n<tt>lua_pcall()</tt> etc.</li>\n<li>C++&nbsp;exceptions will be converted to the generic Lua error\n<tt>\"C++&nbsp;exception\"</tt>, unless you use the\n<a href=\"ext_c_api.html#mode_wrapcfunc\">C&nbsp;call wrapper</a> feature.</li>\n<li>It's safe to throw C++&nbsp;exceptions across non-protected Lua frames\non the C&nbsp;stack. The contents of the C++&nbsp;exception object\npass through unmodified.</li>\n<li>Lua errors can be caught on the C++ side with <tt>catch(...)</tt>.\nThe corresponding Lua error message can be retrieved from the Lua stack.</li>\n<li>Throwing Lua errors across C++ frames is safe. C++ destructors\nwill be called.</li>\n</ul>\n<p>\n<b style=\"color: #c06000;\">Limited interoperability</b> means:\n</p>\n<ul>\n<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,\n<tt>lua_pcall()</tt> etc.</li>\n<li>C++&nbsp;exceptions will be converted to the generic Lua error\n<tt>\"C++&nbsp;exception\"</tt>, unless you use the\n<a href=\"ext_c_api.html#mode_wrapcfunc\">C&nbsp;call wrapper</a> feature.</li>\n<li>C++&nbsp;exceptions will be caught by non-protected Lua frames and\nare rethrown as a generic Lua error. The C++&nbsp;exception object will\nbe destroyed.</li>\n<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>\n<li>Throwing Lua errors across C++ frames will <b>not</b> call\nC++ destructors.</li>\n</ul>\n\n<p>\n<b style=\"color: #a00000;\">No interoperability</b> means:\n</p>\n<ul>\n<li>It's <b>not</b> safe to throw C++&nbsp;exceptions across Lua frames.</li>\n<li>C++&nbsp;exceptions <b>cannot</b> be caught on the Lua side.</li>\n<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>\n<li>Throwing Lua errors across C++ frames will <b>not</b> call\nC++ destructors.</li>\n<li>Additionally, on Windows/x86 with SEH-based C++&nbsp;exceptions:\nit's <b>not</b> safe to throw a Lua error across any frames containing\na C++ function with any try/catch construct or using variables with\n(implicit) destructors. This also applies to any functions which may be\ninlined in such a function. It doesn't matter whether <tt>lua_error()</tt>\nis called inside or outside of a try/catch or whether any object actually\nneeds to be destroyed: the SEH chain is corrupted and this will eventually\nlead to the termination of the process.</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/faq.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Frequently Asked Questions (FAQ)</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ndd { margin-left: 1.5em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Frequently Asked Questions (FAQ)</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<dl>\n<dt>Q: Where can I learn more about LuaJIT and Lua?</dt>\n<dd>\n<ul style=\"padding: 0;\">\n<li>The <a href=\"http://luajit.org/list.html\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics\nrelated to LuaJIT.</li>\n<li>The <a href=\"http://wiki.luajit.org/\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT wiki</a> gathers community\nresources about LuaJIT.</li>\n<li>News about Lua itself can be found at the\n<a href=\"http://www.lua.org/lua-l.html\"><span class=\"ext\">&raquo;</span>&nbsp;Lua mailing list</a>.\nThe mailing list archives are worth checking out for older postings\nabout LuaJIT.</li>\n<li>The <a href=\"http://lua.org\"><span class=\"ext\">&raquo;</span>&nbsp;main Lua.org site</a> has complete\n<a href=\"http://www.lua.org/docs.html\"><span class=\"ext\">&raquo;</span>&nbsp;documentation</a> of the language\nand links to books and papers about Lua.</li>\n<li>The community-managed <a href=\"http://lua-users.org/wiki/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua Wiki</a>\nhas information about diverse topics.</li>\n</ul>\n</dl>\n\n<dl>\n<dt>Q: Where can I learn more about the compiler technology used by LuaJIT?</dt>\n<dd>\nI'm planning to write more documentation about the internals of LuaJIT.\nIn the meantime, please use the following Google Scholar searches\nto find relevant papers:<br>\nSearch for: <a href=\"http://scholar.google.com/scholar?q=Trace+Compiler\"><span class=\"ext\">&raquo;</span>&nbsp;Trace Compiler</a><br>\nSearch for: <a href=\"http://scholar.google.com/scholar?q=JIT+Compiler\"><span class=\"ext\">&raquo;</span>&nbsp;JIT Compiler</a><br>\nSearch for: <a href=\"http://scholar.google.com/scholar?q=Dynamic+Language+Optimizations\"><span class=\"ext\">&raquo;</span>&nbsp;Dynamic Language Optimizations</a><br>\nSearch for: <a href=\"http://scholar.google.com/scholar?q=SSA+Form\"><span class=\"ext\">&raquo;</span>&nbsp;SSA Form</a><br>\nSearch for: <a href=\"http://scholar.google.com/scholar?q=Linear+Scan+Register+Allocation\"><span class=\"ext\">&raquo;</span>&nbsp;Linear Scan Register Allocation</a><br>\nHere is a list of the <a href=\"http://article.gmane.org/gmane.comp.lang.lua.general/58908\"><span class=\"ext\">&raquo;</span>&nbsp;innovative features in LuaJIT</a>.<br>\nAnd, you know, reading the source is of course the only way to enlightenment. :-)\n</dd>\n</dl>\n\n<dl>\n<dt>Q: Why do I get this error: \"attempt to index global 'arg' (a nil value)\"?<br>\nQ: My vararg functions fail after switching to LuaJIT!</dt>\n<dd>LuaJIT is compatible to the Lua 5.1 language standard. It doesn't\nsupport the implicit <tt>arg</tt> parameter for old-style vararg\nfunctions from Lua 5.0.<br>Please convert your code to the\n<a href=\"http://www.lua.org/manual/5.1/manual.html#2.5.9\"><span class=\"ext\">&raquo;</span>&nbsp;Lua 5.1\nvararg syntax</a>.</dd>\n</dl>\n\n<dl>\n<dt>Q: Why do I get this error: \"bad FPU precision\"?<br>\n<dt>Q: I get weird behavior after initializing Direct3D.<br>\n<dt>Q: Some FPU operations crash after I load a Delphi DLL.<br>\n</dt>\n<dd>\n\nDirectX/Direct3D (up to version 9) sets the x87 FPU to single-precision\nmode by default. This violates the Windows ABI and interferes with the\noperation of many programs &mdash; LuaJIT is affected, too. Please make\nsure you always use the <tt>D3DCREATE_FPU_PRESERVE</tt> flag when\ninitializing Direct3D.<br>\n\nDirect3D version 10 or higher do not show this behavior anymore.\nConsider testing your application with older versions, too.<br>\n\nSimilarly, the Borland/Delphi runtime modifies the FPU control word and\nenables FP exceptions. Of course this violates the Windows ABI, too.\nPlease check the Delphi docs for the Set8087CW method.\n\n</dl>\n\n<dl>\n<dt>Q: Sometimes Ctrl-C fails to stop my Lua program. Why?</dt>\n<dd>The interrupt signal handler sets a Lua debug hook. But this is\ncurrently ignored by compiled code (this will eventually be fixed). If\nyour program is running in a tight loop and never falls back to the\ninterpreter, the debug hook never runs and can't throw the\n\"interrupted!\" error.<br> In the meantime you have to press Ctrl-C\ntwice to get stop your program. That's similar to when it's stuck\nrunning inside a C function under the Lua interpreter.</dd>\n</dl>\n\n<dl>\n<dt>Q: Why doesn't my favorite power-patch for Lua apply against LuaJIT?</dt>\n<dd>Because it's a completely redesigned VM and has very little code\nin common with Lua anymore. Also, if the patch introduces changes to\nthe Lua semantics, these would need to be reflected everywhere in the\nVM, from the interpreter up to all stages of the compiler.<br> Please\nuse only standard Lua language constructs. For many common needs you\ncan use source transformations or use wrapper or proxy functions.\nThe compiler will happily optimize away such indirections.</dd>\n</dl>\n\n<dl>\n<dt>Q: Lua runs everywhere. Why doesn't LuaJIT support my CPU?</dt>\n<dd>Because it's a compiler &mdash; it needs to generate native\nmachine code. This means the code generator must be ported to each\narchitecture. And the fast interpreter is written in assembler and\nmust be ported, too. This is quite an undertaking.<br>\nThe <a href=\"install.html\">install documentation</a> shows the supported\narchitectures. Other architectures will follow based on sufficient user\ndemand and/or sponsoring.</dd>\n</dl>\n\n<dl>\n<dt>Q: When will feature X be added? When will the next version be released?</dt>\n<dd>When it's ready.<br>\nC'mon, it's open source &mdash; I'm doing it on my own time and you're\ngetting it for free. You can either contribute a patch or sponsor\nthe development of certain features, if they are important to you.\n</dd>\n</dl>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/install.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Installation</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.compat {\n  line-height: 1.2;\n  font-size: 80%;\n}\ntable.compat td {\n  border: 1px solid #bfcfff;\n  height: 2.5em;\n}\ntable.compat tr.compathead td {\n  font-weight: bold;\n  border-bottom: 2px solid #bfcfff;\n}\ntr.compathead td.compatos {\n  vertical-align: top;\n}\ntable.compat td.compatcpu {\n  width: 18%;\n  border-right: 2px solid #bfcfff;\n}\ntd.compatos {\n  width: 21%;\n  vertical-align: middle;\n}\ntd.compatno {\n  background-color: #d0d0d0;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Installation</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a class=\"current\" href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is only distributed as a source package. This page explains\nhow to build and install LuaJIT with different operating systems\nand C&nbsp;compilers.\n</p>\n<p>\nFor the impatient (on POSIX systems):\n</p>\n<pre class=\"code\">\nmake &amp;&amp; sudo make install\n</pre>\n<p>\nLuaJIT currently builds out-of-the box on most systems.\nHere's the compatibility matrix for the supported combinations of\noperating systems, CPUs and compilers:\n</p>\n<table class=\"compat\">\n<tr class=\"compathead\">\n<td class=\"compatcpu\">CPU / OS</td>\n<td class=\"compatos\"><a href=\"#posix\">Linux</a> or<br><a href=\"#android\">Android</a></td>\n<td class=\"compatos\"><a href=\"#posix\">*BSD, Other</a></td>\n<td class=\"compatos\"><a href=\"#posix\">OSX 10.4+</a> or<br><a href=\"#ios\">iOS 3.0+</a></td>\n<td class=\"compatos\"><a href=\"#windows\">Windows<br>XP/Vista/7</a></td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"compatcpu\">x86 (32 bit)</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos\">MSVC, MSVC/EE<br>WinSDK<br>MinGW, Cygwin</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\">x64 (64 bit)</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">ORBIS (<a href=\"#ps4\">PS4</a>)</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos\">MSVC + SDK v7.0<br>WinSDK v7.0<br>Durango (<a href=\"#xboxone\">Xbox One</a>)</td>\n</tr>\n<tr class=\"odd\">\n<td class=\"compatcpu\"><a href=\"#cross2\">ARMv5+<br>ARM9E+</a></td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">GCC 4.2+<br>PSP2 (<a href=\"#psvita\">PS VITA</a>)</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\"><a href=\"#cross2\">ARM64</a></td>\n<td class=\"compatos\">GCC 4.8+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos\">XCode 6.0+<br>Clang 3.5+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n<tr class=\"odd\">\n<td class=\"compatcpu\"><a href=\"#cross2\">PPC</a></td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos\">GCC 4.3+<br>GCC 4.1 (<a href=\"#ps3\">PS3</a>)</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos\">XEDK (<a href=\"#xbox360\">Xbox 360</a>)</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\"><a href=\"#cross2\">MIPS</a></td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n</table>\n\n<h2>Configuring LuaJIT</h2>\n<p>\nThe standard configuration should work fine for most installations.\nUsually there is no need to tweak the settings. The following files\nhold all user-configurable settings:\n</p>\n<ul>\n<li><tt>src/luaconf.h</tt> sets some configuration variables.</li>\n<li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX\nonly).</li>\n<li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT\nunder POSIX, MinGW or Cygwin.</li>\n<li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with\nMSVC or WinSDK.</li>\n</ul>\n<p>\nPlease read the instructions given in these files, before changing\nany settings.\n</p>\n\n<h2 id=\"posix\">POSIX Systems (Linux, OSX, *BSD etc.)</h2>\n<h3>Prerequisites</h3>\n<p>\nDepending on your distribution, you may need to install a package for\nGCC, the development headers and/or a complete SDK. E.g. on a current\nDebian/Ubuntu, install <tt>libc6-dev</tt> with the package manager.\n</p>\n<p>\nDownload the current source package of LuaJIT (pick the .tar.gz),\nif you haven't already done so. Move it to a directory of your choice,\nopen a terminal window and change to this directory. Now unpack the archive\nand change to the newly created directory:\n</p>\n<pre class=\"code\">\ntar zxf LuaJIT-2.0.4.tar.gz\ncd LuaJIT-2.0.4</pre>\n<h3>Building LuaJIT</h3>\n<p>\nThe supplied Makefiles try to auto-detect the settings needed for your\noperating system and your compiler. They need to be run with GNU Make,\nwhich is probably the default on your system, anyway. Simply run:\n</p>\n<pre class=\"code\">\nmake\n</pre>\n<p>\nThis always builds a native x86, x64 or PPC binary, depending on the host OS\nyou're running this command on. Check the section on\n<a href=\"#cross\">cross-compilation</a> for more options.\n</p>\n<p>\nBy default, modules are only searched under the prefix <tt>/usr/local</tt>.\nYou can add an extra prefix to the search paths by appending the\n<tt>PREFIX</tt> option, e.g.:\n</p>\n<pre class=\"code\">\nmake PREFIX=/home/myself/lj2\n</pre>\n<p>\nNote for OSX: if the <tt>MACOSX_DEPLOYMENT_TARGET</tt> environment\nvariable is not set, then it's forced to <tt>10.4</tt>.\n</p>\n<h3>Installing LuaJIT</h3>\n<p>\nThe top-level Makefile installs LuaJIT by default under\n<tt>/usr/local</tt>, i.e. the executable ends up in\n<tt>/usr/local/bin</tt> and so on. You need root privileges\nto write to this path. So, assuming sudo is installed on your system,\nrun the following command and enter your sudo password:\n</p>\n<pre class=\"code\">\nsudo make install\n</pre>\n<p>\nOtherwise specify the directory prefix as an absolute path, e.g.:\n</p>\n<pre class=\"code\">\nmake install PREFIX=/home/myself/lj2\n</pre>\n<p>\nObviously the prefixes given during build and installation need to be the same.\n</p>\n\n<h2 id=\"windows\">Windows Systems</h2>\n<h3>Prerequisites</h3>\n<p>\nEither install one of the open source SDKs\n(<a href=\"http://mingw.org/\"><span class=\"ext\">&raquo;</span>&nbsp;MinGW</a> or\n<a href=\"http://www.cygwin.com/\"><span class=\"ext\">&raquo;</span>&nbsp;Cygwin</a>), which come with a modified\nGCC plus the required development headers.\n</p>\n<p>\nOr install Microsoft's Visual C++ (MSVC). The freely downloadable\n<a href=\"http://www.microsoft.com/Express/VC/\"><span class=\"ext\">&raquo;</span>&nbsp;Express Edition</a>\nworks just fine, but only contains an x86 compiler.\n</p>\n<p>\nThe freely downloadable\n<a href=\"http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx\"><span class=\"ext\">&raquo;</span>&nbsp;Windows SDK</a>\nonly comes with command line tools, but this is all you need to build LuaJIT.\nIt contains x86 and x64 compilers.\n</p>\n<p>\nNext, download the source package and unpack it using an archive manager\n(e.g. the Windows Explorer) to a directory of your choice.\n</p>\n<h3>Building with MSVC</h3>\n<p>\nOpen a \"Visual Studio .NET Command Prompt\", <tt>cd</tt> to the\ndirectory where you've unpacked the sources and run these commands:\n</p>\n<pre class=\"code\">\ncd src\nmsvcbuild\n</pre>\n<p>\nThen follow the installation instructions below.\n</p>\n<h3>Building with the Windows SDK</h3>\n<p>\nOpen a \"Windows SDK Command Shell\" and select the x86 compiler:\n</p>\n<pre class=\"code\">\nsetenv /release /x86\n</pre>\n<p>\nOr select the x64 compiler:\n</p>\n<pre class=\"code\">\nsetenv /release /x64\n</pre>\n<p>\nThen <tt>cd</tt> to the directory where you've unpacked the sources\nand run these commands:\n</p>\n<pre class=\"code\">\ncd src\nmsvcbuild\n</pre>\n<p>\nThen follow the installation instructions below.\n</p>\n<h3>Building with MinGW or Cygwin</h3>\n<p>\nOpen a command prompt window and make sure the MinGW or Cygwin programs\nare in your path. Then <tt>cd</tt> to the directory where\nyou've unpacked the sources and run this command for MinGW:\n</p>\n<pre class=\"code\">\nmingw32-make\n</pre>\n<p>\nOr this command for Cygwin:\n</p>\n<pre class=\"code\">\nmake\n</pre>\n<p>\nThen follow the installation instructions below.\n</p>\n<h3>Installing LuaJIT</h3>\n<p>\nCopy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt>\ndirectory) to a newly created directory (any location is ok).\nAdd <tt>lua</tt> and <tt>lua\\jit</tt> directories below it and copy\nall Lua files from the <tt>src\\jit</tt> directory of the distribution\nto the latter directory.\n</p>\n<p>\nThere are no hardcoded\nabsolute path names &mdash; all modules are loaded relative to the\ndirectory where <tt>luajit.exe</tt> is installed\n(see <tt>src/luaconf.h</tt>).\n</p>\n\n<h2 id=\"cross\">Cross-compiling LuaJIT</h2>\n<p>\nThe GNU Makefile-based build system allows cross-compiling on any host\nfor any supported target, as long as both architectures have the same\npointer size. If you want to cross-compile to any 32 bit target on an\nx64 OS, you need to install the multilib development package (e.g.\n<tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part\n(<tt>HOST_CC=\"gcc -m32\"</tt>).\n</p>\n<p>\nYou need to specify <tt>TARGET_SYS</tt> whenever the host OS and the\ntarget OS differ, or you'll get assembler or linker errors. E.g. if\nyou're compiling on a Windows or OSX host for embedded Linux or Android,\nyou need to add <tt>TARGET_SYS=Linux</tt> to the examples below. For a\nminimal target OS, you may need to disable the built-in allocator in\n<tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>. The examples\nbelow only show some popular targets &mdash; please check the comments\nin <tt>src/Makefile</tt> for more details.\n</p>\n<pre class=\"code\">\n# Cross-compile to a 32 bit binary on a multilib x64 OS\nmake CC=\"gcc -m32\"\n\n# Cross-compile on Debian/Ubuntu for Windows (mingw32 package)\nmake HOST_CC=\"gcc -m32\" CROSS=i586-mingw32msvc- TARGET_SYS=Windows\n</pre>\n<p id=\"cross2\">\nThe <tt>CROSS</tt> prefix allows specifying a standard GNU cross-compile\ntoolchain (Binutils, GCC and a matching libc). The prefix may vary\ndepending on the <tt>--target</tt> the toolchain was built for (note the\n<tt>CROSS</tt> prefix has a trailing <tt>\"-\"</tt>). The examples below\nuse the canonical toolchain triplets for Linux.\n</p>\n<p>\nSince there's often no easy way to detect CPU features at runtime, it's\nimportant to compile with the proper CPU or architecture settings. You\ncan specify these when building the toolchain yourself. Or add\n<tt>-mcpu=...</tt> or <tt>-march=...</tt> to <tt>TARGET_CFLAGS</tt>. For\nARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting,\ntoo. Otherwise LuaJIT may not run at the full performance of your target\nCPU.\n</p>\n<pre class=\"code\">\n# ARM soft-float\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabi- \\\n     TARGET_CFLAGS=\"-mfloat-abi=soft\"\n\n# ARM soft-float ABI with VFP (example for Cortex-A8)\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabi- \\\n     TARGET_CFLAGS=\"-mcpu=cortex-a8 -mfloat-abi=softfp\"\n\n# ARM hard-float ABI with VFP (armhf, requires recent toolchain)\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabihf-\n\n# ARM64 (requires x64 host)\nmake CROSS=aarch64-linux-\n\n# PPC\nmake HOST_CC=\"gcc -m32\" CROSS=powerpc-linux-gnu-\n\n# MIPS big-endian\nmake HOST_CC=\"gcc -m32\" CROSS=mips-linux-\n# MIPS little-endian\nmake HOST_CC=\"gcc -m32\" CROSS=mipsel-linux-\n</pre>\n<p>\nYou can cross-compile for <b id=\"android\">Android</b> using the <a href=\"http://developer.android.com/sdk/ndk/index.html\"><span class=\"ext\">&raquo;</span>&nbsp;Android NDK</a>.\nThe environment variables need to match the install locations and the\ndesired target platform. E.g. Android&nbsp;4.0 corresponds to ABI level&nbsp;14.\nFor details check the folder <tt>docs</tt> in the NDK directory.\n</p>\n<p>\nOnly a few common variations for the different CPUs, ABIs and platforms\nare listed. Please use your own judgement for which combination you want\nto build/deploy or which lowest common denominator you want to pick:\n</p>\n<pre class=\"code\">\n# Android/ARM, armeabi (ARMv5TE soft-float), Android 2.2+ (Froyo)\nNDK=/opt/android/ndk\nNDKABI=8\nNDKVER=$NDK/toolchains/arm-linux-androideabi-4.6\nNDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-\nNDKF=\"--sysroot $NDK/platforms/android-$NDKABI/arch-arm\"\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_FLAGS=\"$NDKF\"\n\n# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS)\nNDK=/opt/android/ndk\nNDKABI=14\nNDKVER=$NDK/toolchains/arm-linux-androideabi-4.6\nNDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-\nNDKF=\"--sysroot $NDK/platforms/android-$NDKABI/arch-arm\"\nNDKARCH=\"-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8\"\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_FLAGS=\"$NDKF $NDKARCH\"\n\n# Android/MIPS, mips (MIPS32R1 hard-float), Android 4.0+ (ICS)\nNDK=/opt/android/ndk\nNDKABI=14\nNDKVER=$NDK/toolchains/mipsel-linux-android-4.6\nNDKP=$NDKVER/prebuilt/linux-x86/bin/mipsel-linux-android-\nNDKF=\"--sysroot $NDK/platforms/android-$NDKABI/arch-mips\"\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_FLAGS=\"$NDKF\"\n\n# Android/x86, x86 (i686 SSE3), Android 4.0+ (ICS)\nNDK=/opt/android/ndk\nNDKABI=14\nNDKVER=$NDK/toolchains/x86-4.6\nNDKP=$NDKVER/prebuilt/linux-x86/bin/i686-linux-android-\nNDKF=\"--sysroot $NDK/platforms/android-$NDKABI/arch-x86\"\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_FLAGS=\"$NDKF\"\n</pre>\n<p>\nYou can cross-compile for <b id=\"ios\">iOS 3.0+</b> (iPhone/iPad) using the <a href=\"http://developer.apple.com/devcenter/ios/index.action\"><span class=\"ext\">&raquo;</span>&nbsp;iOS SDK</a>:\n</p>\n<p style=\"font-size: 8pt;\">\nNote: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps\nare not allowed to generate code at runtime. You'll only get the performance\nof the LuaJIT interpreter on iOS. This is still faster than plain Lua, but\nmuch slower than the JIT compiler. Please complain to Apple, not me.\nOr use Android. :-p\n</p>\n<pre class=\"code\">\n# iOS/ARM (32 bit)\nISDKP=$(xcrun --sdk iphoneos --show-sdk-path)\nICC=$(xcrun --sdk iphoneos --find clang)\nISDKF=\"-arch armv7 -isysroot $ISDKP\"\nmake HOST_CC=\"clang -m32 -arch i386\" CROSS=\"$(dirname $ICC)/\" \\\n     TARGET_FLAGS=\"$ISDKF\" TARGET_SYS=iOS\n\n# iOS/ARM64\nISDKP=$(xcrun --sdk iphoneos --show-sdk-path)\nICC=$(xcrun --sdk iphoneos --find clang)\nISDKF=\"-arch arm64 -isysroot $ISDKP\"\nmake CROSS=\"$(dirname $ICC)/\" TARGET_FLAGS=\"$ISDKF\" TARGET_SYS=iOS\n</pre>\n\n<h3 id=\"consoles\">Cross-compiling for consoles</h3>\n<p>\nBuilding LuaJIT for consoles requires both a supported host compiler\n(x86 or x64) and a cross-compiler (to PPC or ARM) from the official\nconsole SDK.\n</p>\n<p>\nDue to restrictions on consoles, the JIT compiler is disabled and only\nthe fast interpreter is built. This is still faster than plain Lua,\nbut much slower than the JIT compiler. The FFI is disabled, too, since\nit's not very useful in such an environment.\n</p>\n<p>\nThe following commands build a static library <tt>libluajit.a</tt>,\nwhich can be linked against your game, just like the Lua library.\n</p>\n<p>\nTo cross-compile for <b id=\"ps3\">PS3</b> from a Linux host (requires\n32&nbsp;bit GCC, i.e. multilib Linux/x64) or a Windows host (requires\n32&nbsp;bit MinGW), run this command:\n</p>\n<pre class=\"code\">\nmake HOST_CC=\"gcc -m32\" CROSS=ppu-lv2-\n</pre>\n<p>\nTo cross-compile for <b id=\"ps4\">PS4</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (64&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and\nrun the following commands:\n</p>\n<pre class=\"code\">\ncd src\nps4build\n</pre>\n<p>\nTo cross-compile for <b id=\"psvita\">PS Vita</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (32&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and\nrun the following commands:\n</p>\n<pre class=\"code\">\ncd src\npsvitabuild\n</pre>\n<p>\nTo cross-compile for <b id=\"xbox360\">Xbox 360</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (32&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and run\nthe following commands:\n</p>\n<pre class=\"code\">\ncd src\nxedkbuild\n</pre>\n<p>\nTo cross-compile for <b id=\"xboxone\">Xbox One</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (64&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and run\nthe following commands:\n</p>\n<pre class=\"code\">\ncd src\nxb1build\n</pre>\n\n<h2 id=\"embed\">Embedding LuaJIT</h2>\n<p>\nLuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua\ninto your application, you probably don't need to do anything to switch\nto LuaJIT, except link with a different library:\n</p>\n<ul>\n<li>It's strongly suggested to build LuaJIT separately using the supplied\nbuild system. Please do <em>not</em> attempt to integrate the individual\nsource files into your build tree. You'll most likely get the internal build\ndependencies wrong or mess up the compiler flags. Treat LuaJIT like any\nother external library and link your application with either the dynamic\nor static library, depending on your needs.</li>\n<li>If you want to load C modules compiled for plain Lua\nwith <tt>require()</tt>, you need to make sure the public symbols\n(e.g. <tt>lua_pushnumber</tt>) are exported, too:\n<ul><li>On POSIX systems you can either link to the shared library\nor link the static library into your application. In the latter case\nyou'll need to export all public symbols from your main executable\n(e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies\n(e.g. <tt>-lm -ldl</tt> on Linux).</li>\n<li>Since Windows symbols are bound to a specific DLL name, you need to\nlink to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename\nthe DLL). You may link LuaJIT statically on Windows only if you don't\nintend to load Lua/C modules at runtime.\n</li></ul>\n</li>\n<li>\nIf you're building a 64 bit application on OSX which links directly or\nindirectly against LuaJIT, you need to link your main executable\nwith these flags:\n<pre class=\"code\">\n-pagezero_size 10000 -image_base 100000000\n</pre>\nAlso, it's recommended to <tt>rebase</tt> all (self-compiled) shared libraries\nwhich are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).\nSee: <tt>man rebase</tt>\n</li>\n</ul>\n<p>Additional hints for initializing LuaJIT using the C API functions:</p>\n<ul>\n<li>Here's a\n<a href=\"http://lua-users.org/wiki/SimpleLuaApiExample\"><span class=\"ext\">&raquo;</span>&nbsp;simple example</a>\nfor embedding Lua or LuaJIT into your application.</li>\n<li>Make sure you use <tt>luaL_newstate</tt>. Avoid using\n<tt>lua_newstate</tt>, since this uses the (slower) default memory\nallocator from your system (no support for this on x64).</li>\n<li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style\nof calling <tt>luaopen_base</tt> etc. directly.</li>\n<li>To change or extend the list of standard libraries to load, copy\n<tt>src/lib_init.c</tt> to your project and modify it accordingly.\nMake sure the <tt>jit</tt> library is loaded or the JIT compiler\nwill not be activated.</li>\n<li>The <tt>bit.*</tt> module for bitwise operations\nis already built-in. There's no need to statically link\n<a href=\"http://bitop.luajit.org/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp</a> to your application.</li>\n</ul>\n\n<h2 id=\"distro\">Hints for Distribution Maintainers</h2>\n<p>\nThe LuaJIT build system has extra provisions for the needs of most\nPOSIX-based distributions. If you're a package maintainer for\na distribution, <em>please</em> make use of these features and\navoid patching, subverting, autotoolizing or messing up the build system\nin unspeakable ways.\n</p>\n<p>\nThere should be absolutely no need to patch <tt>luaconf.h</tt> or any\nof the Makefiles. And please do not hand-pick files for your packages &mdash;\nsimply use whatever <tt>make install</tt> creates. There's a reason\nfor all of the files <em>and</em> directories it creates.\n</p>\n<p>\nThe build system uses GNU make and auto-detects most settings based on\nthe host you're building it on. This should work fine for native builds,\neven when sandboxed. You may need to pass some of the following flags to\n<em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines\nfor a regular distribution build:\n</p>\n<ul>\n<li><tt>PREFIX</tt> overrides the installation path and should usually\nbe set to <tt>/usr</tt>. Setting this also changes the module paths and\nthe paths needed to locate the shared library.</li>\n<li><tt>DESTDIR</tt> is an absolute path which allows you to install\nto a shadow tree instead of the root tree of the build system.</li>\n<li><tt>MULTILIB</tt> sets the architecture-specific library path component\nfor multilib systems. The default is <tt>lib</tt>.</li>\n<li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt>\nfor additional variables to tweak. The following variables <em>may</em> be\noverridden, but it's <em>not</em> recommended, except for special needs\nlike cross-builds:\n<tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,\nTARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,\nTARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS\n</tt></li>\n</ul>\n<p>\nThe build system has a special target for an amalgamated build, i.e.\n<tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file\nand allows GCC to generate faster and shorter code. Alas, this requires\nlots of memory during the build. This may be a problem for some users,\nthat's why it's not enabled by default. But it shouldn't be a problem for\nmost build farms. It's recommended that binary distributions use this\ntarget for their LuaJIT builds.\n</p>\n<p>\nThe tl;dr version of the above:\n</p>\n<pre class=\"code\">\nmake amalg PREFIX=/usr && \\\nmake install PREFIX=/usr DESTDIR=/tmp/buildroot\n</pre>\n<p>\nFinally, if you encounter any difficulties, please\n<a href=\"contact.html\">contact me</a> first, instead of releasing a broken\npackage onto unsuspecting users. Because they'll usually gonna complain\nto me (the upstream) and not you (the package maintainer), anyway.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/luajit.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>LuaJIT</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<meta name=\"description\" content=\"LuaJIT is a Just-In-Time (JIT) compiler for the Lua language.\">\n<style type=\"text/css\">\ntable.feature {\n  width: inherit;\n  line-height: 1.2;\n  margin: 0;\n}\ntable.feature td {\n  width: 80px;\n  height: 40px;\n  vertical-align: middle;\n  text-align: center;\n  font-weight: bold;\n  border: 4px solid #e6ecff;\n  border-radius: 12px;\n}\ntable.os td {\n  background: #7080d0;\n  background-image: linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -moz-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -webkit-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -o-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -ms-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n}\ntable.os1 td {\n  color: #ffff80;\n}\ntable.os2 td {\n  color: #ffa040;\n}\ntable.os3 td {\n  color: #40ffff;\n}\ntable.compiler td {\n  color: #2080ff;\n  background: #62bf41;\n  background-image: linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -moz-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -webkit-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -o-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -ms-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n}\ntable.cpu td {\n  color: #ffff00;\n  background: #cf7251;\n  background-image: linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -moz-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -webkit-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -o-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -ms-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n}\ntable.fcompat td {\n  color: #2060e0;\n  background: #61cfcf;\n  background-image: linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -moz-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -webkit-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -o-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -ms-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n}\ntable.stats td {\n  color: #ffffff;\n  background: #a0a0a0;\n  background-image: linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -moz-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -webkit-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -o-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -ms-linear-gradient(#808080 10%, #d0d0d0 95%);\n}\ntable.stats td.speed {\n  color: #ff4020;\n}\ntable.stats td.kb {\n  color: #ffff80;\n  background: #808080;\n  background-image: linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -moz-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -webkit-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -o-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -ms-linear-gradient(#606060 10%, #c0c0c0 95%);\n}\ntable.feature small {\n  font-size: 50%;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>LuaJIT</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a class=\"current\" href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is a <b>Just-In-Time Compiler</b> (JIT) for the\n<a href=\"http://www.lua.org/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua</a> programming language.\nLua is a powerful, dynamic and light-weight programming language.\nIt may be embedded or used as a general-purpose, stand-alone language.\n</p>\n<p>\nLuaJIT is Copyright &copy; 2005-2016 Mike Pall, released under the\n<a href=\"http://www.opensource.org/licenses/mit-license.php\"><span class=\"ext\">&raquo;</span>&nbsp;MIT open source license</a>.\n</p>\n<p>\n</p>\n\n<h2>Compatibility</h2>\n<table class=\"feature os os1\">\n<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr>\n</table>\n<table class=\"feature os os2\">\n<tr><td><span style=\"font-size:90%;\">Embedded</span></td><td>Android</td><td>iOS</td></tr>\n</table>\n<table class=\"feature os os3\">\n<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr>\n</table>\n<table class=\"feature compiler\">\n<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>\n</table>\n<table class=\"feature cpu\">\n<tr><td>x86</td><td>x64</td><td>ARM</td><td>ARM64</td><td>PPC</td><td>MIPS</td></tr>\n</table>\n<table class=\"feature fcompat\">\n<tr><td>Lua&nbsp;5.1<br>API+ABI</td><td>+&nbsp;JIT</td><td>+&nbsp;BitOp</td><td>+&nbsp;FFI</td><td>Drop-in<br>DLL/.so</td></tr>\n</table>\n\n<h2>Overview</h2>\n<table class=\"feature stats\">\n<tr>\n<td class=\"speed\">3x<br>-&nbsp;&nbsp;100x</td>\n<td class=\"kb\">115&nbsp;<small>KB</small><br>VM</td>\n<td class=\"kb\">90&nbsp;<small>KB</small><br>JIT</td>\n<td class=\"kloc\">63&nbsp;<small>KLOC</small><br>C</td>\n<td class=\"kloc\">24&nbsp;<small>KLOC</small><br>ASM</td>\n<td class=\"kloc\">11&nbsp;<small>KLOC</small><br>Lua</td>\n</tr>\n</table>\n<p style=\"margin-top: 1em;\">\nLuaJIT has been successfully used as a <b>scripting middleware</b> in\ngames, appliances, network and graphics apps, numerical simulations,\ntrading platforms and many other specialty applications. It scales from\nembedded devices, smartphones, desktops up to server farms. It combines\nhigh flexibility with <a href=\"http://luajit.org/performance.html\"><span class=\"ext\">&raquo;</span>&nbsp;high performance</a>\nand an unmatched <b>low memory footprint</b>.\n</p>\n<p>\nLuaJIT has been in continuous development since 2005. It's widely\nconsidered to be <b>one of the fastest dynamic language\nimplementations</b>. It has outperformed other dynamic languages on many\ncross-language benchmarks since its first release &mdash; often by a\nsubstantial margin.\n</p>\n<p>\nFor <b>LuaJIT 2.0</b>, the whole VM has been rewritten from the ground up\nand relentlessly optimized for performance. It combines a <b>high-speed\ninterpreter</b>, written in assembler, with a <b>state-of-the-art JIT\ncompiler</b>.\n</p>\n<p>\nAn innovative <b>trace compiler</b> is integrated with advanced,\nSSA-based optimizations and highly tuned code generation backends.\nA substantial reduction of the overhead associated with dynamic languages\nallows it to break into the performance range traditionally reserved for\noffline, static language compilers.\n</p>\n\n<h2>More ...</h2>\n<p>\nPlease select a sub-topic in the navigation bar to learn more about LuaJIT.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/running.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Running LuaJIT</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.opt {\n  line-height: 1.2;\n}\ntr.opthead td {\n  font-weight: bold;\n}\ntd.flag_name {\n  width: 4em;\n}\ntd.flag_level {\n  width: 2em;\n  text-align: center;\n}\ntd.param_name {\n  width: 6em;\n}\ntd.param_default {\n  width: 4em;\n  text-align: right;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Running LuaJIT</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a class=\"current\" href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT has only a single stand-alone executable, called <tt>luajit</tt> on\nPOSIX systems or <tt>luajit.exe</tt> on Windows. It can be used to run simple\nLua statements or whole Lua applications from the command line. It has an\ninteractive mode, too.\n</p>\n\n<h2 id=\"options\">Command Line Options</h2>\n<p>\nThe <tt>luajit</tt> stand-alone executable is just a slightly modified\nversion of the regular <tt>lua</tt> stand-alone executable.\nIt supports the same basic options, too. <tt>luajit&nbsp;-h</tt>\nprints a short list of the available options. Please have a look at the\n<a href=\"http://www.lua.org/manual/5.1/manual.html#6\"><span class=\"ext\">&raquo;</span>&nbsp;Lua manual</a>\nfor details.\n</p>\n<p>\nLuaJIT has some additional options:\n</p>\n\n<h3 id=\"opt_b\"><tt>-b[options] input output</tt></h3>\n<p>\nThis option saves or lists bytecode. The following additional options\nare accepted:\n</p>\n<ul>\n<li><tt>-l</tt> &mdash; Only list bytecode.</li>\n<li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>\n<li><tt>-g</tt> &mdash; Keep debug info.</li>\n<li><tt>-n name</tt> &mdash; Set module name (default: auto-detect from input name)</li>\n<li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>\n<li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>\n<li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li>\n<li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>\n<li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>\n</ul>\n<p>\nThe output file type is auto-detected from the extension of the output\nfile name:\n</p>\n<ul>\n<li><tt>c</tt> &mdash; C source file, exported bytecode data.</li>\n<li><tt>h</tt> &mdash; C header file, static bytecode data.</li>\n<li><tt>obj</tt> or <tt>o</tt> &mdash; Object file, exported bytecode data\n(OS- and architecture-specific).</li>\n<li><tt>raw</tt> or any other extension &mdash; Raw bytecode file (portable).\n</ul>\n<p>\nNotes:\n</p>\n<ul>\n<li>See also <a href=\"extensions.html#string_dump\">string.dump()</a>\nfor information on bytecode portability and compatibility.</li>\n<li>A file in raw bytecode format is auto-detected and can be loaded like\nany Lua source file. E.g. directly from the command line or with\n<tt>loadfile()</tt>, <tt>dofile()</tt> etc.</li>\n<li>To statically embed the bytecode of a module in your application,\ngenerate an object file and just link it with your application.</li>\n<li>On most ELF-based systems (e.g. Linux) you need to explicitly export the\nglobal symbols when linking your application, e.g. with: <tt>-Wl,-E</tt></li>\n<li><tt>require()</tt> tries to load embedded bytecode data from exported\nsymbols (in <tt>*.exe</tt> or <tt>lua51.dll</tt> on Windows) and from\nshared libraries in <tt>package.cpath</tt>.</li>\n</ul>\n<p>\nTypical usage examples:\n</p>\n<pre class=\"code\">\nluajit -b test.lua test.out                 # Save bytecode to test.out\nluajit -bg test.lua test.out                # Keep debug info\nluajit -be \"print('hello world')\" test.out  # Save cmdline script\n\nluajit -bl test.lua                         # List to stdout\nluajit -bl test.lua test.txt                # List to test.txt\nluajit -ble \"print('hello world')\"          # List cmdline script\n\nluajit -b test.lua test.obj                 # Generate object file\n# Link test.obj with your application and load it with require(\"test\")\n</pre>\n\n<h3 id=\"opt_j\"><tt>-j cmd[=arg[,arg...]]</tt></h3>\n<p>\nThis option performs a LuaJIT control command or activates one of the\nloadable extension modules. The command is first looked up in the\n<tt>jit.*</tt> library. If no matching function is found, a module\nnamed <tt>jit.&lt;cmd&gt;</tt> is loaded and the <tt>start()</tt>\nfunction of the module is called with the specified arguments (if\nany). The space between <tt>-j</tt> and <tt>cmd</tt> is optional.\n</p>\n<p>\nHere are the available LuaJIT control commands:\n</p>\n<ul>\n<li id=\"j_on\"><tt>-jon</tt> &mdash; Turns the JIT compiler on (default).</li>\n<li id=\"j_off\"><tt>-joff</tt> &mdash; Turns the JIT compiler off (only use the interpreter).</li>\n<li id=\"j_flush\"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>\n<li id=\"j_v\"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>\n<li id=\"j_dump\"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>\n<li id=\"j_p\"><tt>-jp</tt> &mdash; Start the <a href=\"ext_profiler.html\">integrated profiler</a>.</li>\n</ul>\n<p>\nThe <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules\nwritten in Lua. They are mainly used for debugging the JIT compiler\nitself. For a description of their options and output format, please\nread the comment block at the start of their source.\nThey can be found in the <tt>lib</tt> directory of the source\ndistribution or installed under the <tt>jit</tt> directory. By default\nthis is <tt>/usr/local/share/luajit-2.0.4/jit</tt> on POSIX\nsystems.\n</p>\n\n<h3 id=\"opt_O\"><tt>-O[level]</tt><br>\n<tt>-O[+]flag</tt>&nbsp;&nbsp;&nbsp;<tt>-O-flag</tt><br>\n<tt>-Oparam=value</tt></h3>\n<p>\nThis options allows fine-tuned control of the optimizations used by\nthe JIT compiler. This is mainly intended for debugging LuaJIT itself.\nPlease note that the JIT compiler is extremely fast (we are talking\nabout the microsecond to millisecond range). Disabling optimizations\ndoesn't have any visible impact on its overhead, but usually generates\ncode that runs slower.\n</p>\n<p>\nThe first form sets an optimization level &mdash; this enables a\nspecific mix of optimization flags. <tt>-O0</tt> turns off all\noptimizations and higher numbers enable more optimizations. Omitting\nthe level (i.e. just <tt>-O</tt>) sets the default optimization level,\nwhich is <tt>-O3</tt> in the current version.\n</p>\n<p>\nThe second form adds or removes individual optimization flags.\nThe third form sets a parameter for the VM or the JIT compiler\nto a specific value.\n</p>\n<p>\nYou can either use this option multiple times (like <tt>-Ocse\n-O-dce -Ohotloop=10</tt>) or separate several settings with a comma\n(like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from\nleft to right and later settings override earlier ones. You can freely\nmix the three forms, but note that setting an optimization level\noverrides all earlier flags.\n</p>\n<p>\nHere are the available flags and at what optimization levels they\nare enabled:\n</p>\n<table class=\"opt\">\n<tr class=\"opthead\">\n<td class=\"flag_name\">Flag</td>\n<td class=\"flag_level\">-O1</td>\n<td class=\"flag_level\">-O2</td>\n<td class=\"flag_level\">-O3</td>\n<td class=\"flag_desc\">&nbsp;</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"flag_name\">fold</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Constant Folding, Simplifications and Reassociation</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">cse</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Common-Subexpression Elimination</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">dce</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Dead-Code Elimination</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">narrow</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Narrowing of numbers to integers</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">loop</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Loop Optimizations (code hoisting)</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">fwd</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Load Forwarding (L2L) and Store Forwarding (S2L)</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">dse</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Dead-Store Elimination</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">abc</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Array Bounds Check Elimination</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">sink</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Allocation/Store Sinking</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">fuse</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Fusion of operands into instructions</td></tr>\n</table>\n<p>\nHere are the parameters and their default settings:\n</p>\n<table class=\"opt\">\n<tr class=\"opthead\">\n<td class=\"param_name\">Parameter</td>\n<td class=\"param_default\">Default</td>\n<td class=\"param_desc\">&nbsp;</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">maxtrace</td><td class=\"param_default\">1000</td><td class=\"param_desc\">Max. number of traces in the cache</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxrecord</td><td class=\"param_default\">4000</td><td class=\"param_desc\">Max. number of recorded IR instructions</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">maxirconst</td><td class=\"param_default\">500</td><td class=\"param_desc\">Max. number of IR constants of a trace</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxside</td><td class=\"param_default\">100</td><td class=\"param_desc\">Max. number of side traces of a root trace</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">maxsnap</td><td class=\"param_default\">500</td><td class=\"param_desc\">Max. number of snapshots for a trace</td></tr>\n<tr class=\"even separate\">\n<td class=\"param_name\">hotloop</td><td class=\"param_default\">56</td><td class=\"param_desc\">Number of iterations to detect a hot loop or hot call</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">hotexit</td><td class=\"param_default\">10</td><td class=\"param_desc\">Number of taken exits to start a side trace</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">tryside</td><td class=\"param_default\">4</td><td class=\"param_desc\">Number of attempts to compile a side trace</td></tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">instunroll</td><td class=\"param_default\">4</td><td class=\"param_desc\">Max. unroll factor for instable loops</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">loopunroll</td><td class=\"param_default\">15</td><td class=\"param_desc\">Max. unroll factor for loop ops in side traces</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">callunroll</td><td class=\"param_default\">3</td><td class=\"param_desc\">Max. unroll factor for pseudo-recursive calls</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">recunroll</td><td class=\"param_default\">2</td><td class=\"param_desc\">Min. unroll factor for true recursion</td></tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">sizemcode</td><td class=\"param_default\">32</td><td class=\"param_desc\">Size of each machine code area in KBytes (Windows: 64K)</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxmcode</td><td class=\"param_default\">512</td><td class=\"param_desc\">Max. total size of all machine code areas in KBytes</td></tr>\n</table>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/doc/status.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>Status</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2016, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\nul li { padding-bottom: 0.3em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Status</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"status.html\">Status</a>\n<ul><li>\n<a href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\n<span style=\"color: #0000c0;\">LuaJIT&nbsp;2.0</span> is the current\n<span style=\"color: #0000c0;\">stable branch</span>. This branch is in\nfeature-freeze &mdash; new features will only be added to LuaJIT&nbsp;2.1.\n</p>\n\n<h2>Current Status</h2>\n<p>\nLuaJIT ought to run all Lua&nbsp;5.1-compatible source code just fine.\nIt's considered a serious bug if the VM crashes or produces unexpected\nresults &mdash; please report this.\n</p>\n<p>\nKnown incompatibilities and issues in LuaJIT&nbsp;2.0:\n</p>\n<ul>\n<li>\nThere are some differences in <b>implementation-defined</b> behavior.\nThese either have a good reason, are arbitrary design choices\nor are due to quirks in the VM. The latter cases may get fixed if a\ndemonstrable need is shown.\n</li>\n<li>\nThe Lua <b>debug API</b> is missing a couple of features (return\nhooks for non-Lua functions) and shows slightly different behavior\nin LuaJIT (no per-coroutine hooks, no tail call counting).\n</li>\n<li>\nSome checks are missing in the JIT-compiled code for obscure situations\nwith <b>open upvalues aliasing</b> one of the SSA slots later on (or\nvice versa). Bonus points, if you can find a real world test case for\nthis.\n</li>\n<li>\nCurrently some <b>out-of-memory</b> errors from <b>on-trace code</b> are not\nhandled correctly. The error may fall through an on-trace\n<tt>pcall</tt> or it may be passed on to the function set with\n<tt>lua_atpanic</tt> on x64. This issue will be fixed with the new\ngarbage collector.\n</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2016 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_arm.h",
    "content": "/*\n** DynASM ARM encoding engine.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"arm\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC,\n  DASM_IMM, DASM_IMM12, DASM_IMM16, DASM_IMML8, DASM_IMML12, DASM_IMMV8,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\nstatic int dasm_imm12(unsigned int n)\n{\n  int i;\n  for (i = 0; i < 16; i++, n = (n << 2) | (n >> 30))\n    if (n <= 255) return (int)(n + (i << 8));\n  return -1;\n}\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n      case DASM_IMM16:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n\tif ((ins & 0x8000))\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMMV8:\n\tCK((n & 3) == 0, RANGE_I);\n\tn >>= 2;\n      case DASM_IMML8:\n      case DASM_IMML12:\n\tCK(n >= 0 ? ((n>>((ins>>5)&31)) == 0) :\n\t\t    (((-n)>>((ins>>5)&31)) == 0), RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM12:\n\tCK(dasm_imm12((unsigned int)n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMM12: case DASM_IMM16:\n\tcase DASM_IMML8: case DASM_IMML12: case DASM_IMMV8: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048));\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  CK(n >= 0, UNDEF_LG);\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) - 4;\n\tpatchrel:\n\t  if ((ins & 0x800) == 0) {\n\t    CK((n & 3) == 0 && ((n+0x02000000) >> 26) == 0, RANGE_REL);\n\t    cp[-1] |= ((n >> 2) & 0x00ffffff);\n\t  } else if ((ins & 0x1000)) {\n\t    CK((n & 3) == 0 && -256 <= n && n <= 256, RANGE_REL);\n\t    goto patchimml8;\n\t  } else if ((ins & 0x2000) == 0) {\n\t    CK((n & 3) == 0 && -4096 <= n && n <= 4096, RANGE_REL);\n\t    goto patchimml;\n\t  } else {\n\t    CK((n & 3) == 0 && -1020 <= n && n <= 1020, RANGE_REL);\n\t    n >>= 2;\n\t    goto patchimml;\n\t  }\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= ((n>>((ins>>10)&31)) & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMM12:\n\t  cp[-1] |= dasm_imm12((unsigned int)n);\n\t  break;\n\tcase DASM_IMM16:\n\t  cp[-1] |= ((n & 0xf000) << 4) | (n & 0x0fff);\n\t  break;\n\tcase DASM_IMML8: patchimml8:\n\t  cp[-1] |= n >= 0 ? (0x00800000 | (n & 0x0f) | ((n & 0xf0) << 4)) :\n\t\t\t     ((-n & 0x0f) | ((-n & 0xf0) << 4));\n\t  break;\n\tcase DASM_IMML12: case DASM_IMMV8: patchimml:\n\t  cp[-1] |= n >= 0 ? (0x00800000 | n) : (-n);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_arm.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM ARM module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"arm\",\n  description =\t\"DynASM ARM module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable, rawget = assert, setmetatable, rawget\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, insert = table.concat, table.sort, table.insert\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal ror, tohex = bit.ror, bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMM12\", \"IMM16\", \"IMML8\", \"IMML12\", \"IMMV8\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0x000fffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  if n <= 0x000fffff then\n    insert(actlist, pos+1, n)\n    n = map_action.ESC * 0x10000\n  end\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\n\n-- Ext. register name -> int. name.\nlocal map_archdef = { sp = \"r13\", lr = \"r14\", pc = \"r15\", }\n\n-- Int. register name -> ext. name.\nlocal map_reg_rev = { r13 = \"sp\", r14 = \"lr\", r15 = \"pc\", }\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return map_reg_rev[s] or s\nend\n\nlocal map_shift = { lsl = 0, lsr = 1, asr = 2, ror = 3, }\n\nlocal map_cond = {\n  eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,\n  hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,\n  hs = 2, lo = 3,\n}\n\n------------------------------------------------------------------------------\n\n-- Template strings for ARM instructions.\nlocal map_op = {\n  -- Basic data processing instructions.\n  and_3 = \"e0000000DNPs\",\n  eor_3 = \"e0200000DNPs\",\n  sub_3 = \"e0400000DNPs\",\n  rsb_3 = \"e0600000DNPs\",\n  add_3 = \"e0800000DNPs\",\n  adc_3 = \"e0a00000DNPs\",\n  sbc_3 = \"e0c00000DNPs\",\n  rsc_3 = \"e0e00000DNPs\",\n  tst_2 = \"e1100000NP\",\n  teq_2 = \"e1300000NP\",\n  cmp_2 = \"e1500000NP\",\n  cmn_2 = \"e1700000NP\",\n  orr_3 = \"e1800000DNPs\",\n  mov_2 = \"e1a00000DPs\",\n  bic_3 = \"e1c00000DNPs\",\n  mvn_2 = \"e1e00000DPs\",\n\n  and_4 = \"e0000000DNMps\",\n  eor_4 = \"e0200000DNMps\",\n  sub_4 = \"e0400000DNMps\",\n  rsb_4 = \"e0600000DNMps\",\n  add_4 = \"e0800000DNMps\",\n  adc_4 = \"e0a00000DNMps\",\n  sbc_4 = \"e0c00000DNMps\",\n  rsc_4 = \"e0e00000DNMps\",\n  tst_3 = \"e1100000NMp\",\n  teq_3 = \"e1300000NMp\",\n  cmp_3 = \"e1500000NMp\",\n  cmn_3 = \"e1700000NMp\",\n  orr_4 = \"e1800000DNMps\",\n  mov_3 = \"e1a00000DMps\",\n  bic_4 = \"e1c00000DNMps\",\n  mvn_3 = \"e1e00000DMps\",\n\n  lsl_3 = \"e1a00000DMws\",\n  lsr_3 = \"e1a00020DMws\",\n  asr_3 = \"e1a00040DMws\",\n  ror_3 = \"e1a00060DMws\",\n  rrx_2 = \"e1a00060DMs\",\n\n  -- Multiply and multiply-accumulate.\n  mul_3 = \"e0000090NMSs\",\n  mla_4 = \"e0200090NMSDs\",\n  umaal_4 = \"e0400090DNMSs\",\t-- v6\n  mls_4 = \"e0600090DNMSs\",\t-- v6T2\n  umull_4 = \"e0800090DNMSs\",\n  umlal_4 = \"e0a00090DNMSs\",\n  smull_4 = \"e0c00090DNMSs\",\n  smlal_4 = \"e0e00090DNMSs\",\n\n  -- Halfword multiply and multiply-accumulate.\n  smlabb_4 = \"e1000080NMSD\",\t-- v5TE\n  smlatb_4 = \"e10000a0NMSD\",\t-- v5TE\n  smlabt_4 = \"e10000c0NMSD\",\t-- v5TE\n  smlatt_4 = \"e10000e0NMSD\",\t-- v5TE\n  smlawb_4 = \"e1200080NMSD\",\t-- v5TE\n  smulwb_3 = \"e12000a0NMS\",\t-- v5TE\n  smlawt_4 = \"e12000c0NMSD\",\t-- v5TE\n  smulwt_3 = \"e12000e0NMS\",\t-- v5TE\n  smlalbb_4 = \"e1400080NMSD\",\t-- v5TE\n  smlaltb_4 = \"e14000a0NMSD\",\t-- v5TE\n  smlalbt_4 = \"e14000c0NMSD\",\t-- v5TE\n  smlaltt_4 = \"e14000e0NMSD\",\t-- v5TE\n  smulbb_3 = \"e1600080NMS\",\t-- v5TE\n  smultb_3 = \"e16000a0NMS\",\t-- v5TE\n  smulbt_3 = \"e16000c0NMS\",\t-- v5TE\n  smultt_3 = \"e16000e0NMS\",\t-- v5TE\n\n  -- Miscellaneous data processing instructions.\n  clz_2 = \"e16f0f10DM\", -- v5T\n  rev_2 = \"e6bf0f30DM\", -- v6\n  rev16_2 = \"e6bf0fb0DM\", -- v6\n  revsh_2 = \"e6ff0fb0DM\", -- v6\n  sel_3 = \"e6800fb0DNM\", -- v6\n  usad8_3 = \"e780f010NMS\", -- v6\n  usada8_4 = \"e7800010NMSD\", -- v6\n  rbit_2 = \"e6ff0f30DM\", -- v6T2\n  movw_2 = \"e3000000DW\", -- v6T2\n  movt_2 = \"e3400000DW\", -- v6T2\n  -- Note: the X encodes width-1, not width.\n  sbfx_4 = \"e7a00050DMvX\", -- v6T2\n  ubfx_4 = \"e7e00050DMvX\", -- v6T2\n  -- Note: the X encodes the msb field, not the width.\n  bfc_3 = \"e7c0001fDvX\", -- v6T2\n  bfi_4 = \"e7c00010DMvX\", -- v6T2\n\n  -- Packing and unpacking instructions.\n  pkhbt_3 = \"e6800010DNM\", pkhbt_4 = \"e6800010DNMv\", -- v6\n  pkhtb_3 = \"e6800050DNM\", pkhtb_4 = \"e6800050DNMv\", -- v6\n  sxtab_3 = \"e6a00070DNM\", sxtab_4 = \"e6a00070DNMv\", -- v6\n  sxtab16_3 = \"e6800070DNM\", sxtab16_4 = \"e6800070DNMv\", -- v6\n  sxtah_3 = \"e6b00070DNM\", sxtah_4 = \"e6b00070DNMv\", -- v6\n  sxtb_2 = \"e6af0070DM\", sxtb_3 = \"e6af0070DMv\", -- v6\n  sxtb16_2 = \"e68f0070DM\", sxtb16_3 = \"e68f0070DMv\", -- v6\n  sxth_2 = \"e6bf0070DM\", sxth_3 = \"e6bf0070DMv\", -- v6\n  uxtab_3 = \"e6e00070DNM\", uxtab_4 = \"e6e00070DNMv\", -- v6\n  uxtab16_3 = \"e6c00070DNM\", uxtab16_4 = \"e6c00070DNMv\", -- v6\n  uxtah_3 = \"e6f00070DNM\", uxtah_4 = \"e6f00070DNMv\", -- v6\n  uxtb_2 = \"e6ef0070DM\", uxtb_3 = \"e6ef0070DMv\", -- v6\n  uxtb16_2 = \"e6cf0070DM\", uxtb16_3 = \"e6cf0070DMv\", -- v6\n  uxth_2 = \"e6ff0070DM\", uxth_3 = \"e6ff0070DMv\", -- v6\n\n  -- Saturating instructions.\n  qadd_3 = \"e1000050DMN\",\t-- v5TE\n  qsub_3 = \"e1200050DMN\",\t-- v5TE\n  qdadd_3 = \"e1400050DMN\",\t-- v5TE\n  qdsub_3 = \"e1600050DMN\",\t-- v5TE\n  -- Note: the X for ssat* encodes sat_imm-1, not sat_imm.\n  ssat_3 = \"e6a00010DXM\", ssat_4 = \"e6a00010DXMp\", -- v6\n  usat_3 = \"e6e00010DXM\", usat_4 = \"e6e00010DXMp\", -- v6\n  ssat16_3 = \"e6a00f30DXM\", -- v6\n  usat16_3 = \"e6e00f30DXM\", -- v6\n\n  -- Parallel addition and subtraction.\n  sadd16_3 = \"e6100f10DNM\", -- v6\n  sasx_3 = \"e6100f30DNM\", -- v6\n  ssax_3 = \"e6100f50DNM\", -- v6\n  ssub16_3 = \"e6100f70DNM\", -- v6\n  sadd8_3 = \"e6100f90DNM\", -- v6\n  ssub8_3 = \"e6100ff0DNM\", -- v6\n  qadd16_3 = \"e6200f10DNM\", -- v6\n  qasx_3 = \"e6200f30DNM\", -- v6\n  qsax_3 = \"e6200f50DNM\", -- v6\n  qsub16_3 = \"e6200f70DNM\", -- v6\n  qadd8_3 = \"e6200f90DNM\", -- v6\n  qsub8_3 = \"e6200ff0DNM\", -- v6\n  shadd16_3 = \"e6300f10DNM\", -- v6\n  shasx_3 = \"e6300f30DNM\", -- v6\n  shsax_3 = \"e6300f50DNM\", -- v6\n  shsub16_3 = \"e6300f70DNM\", -- v6\n  shadd8_3 = \"e6300f90DNM\", -- v6\n  shsub8_3 = \"e6300ff0DNM\", -- v6\n  uadd16_3 = \"e6500f10DNM\", -- v6\n  uasx_3 = \"e6500f30DNM\", -- v6\n  usax_3 = \"e6500f50DNM\", -- v6\n  usub16_3 = \"e6500f70DNM\", -- v6\n  uadd8_3 = \"e6500f90DNM\", -- v6\n  usub8_3 = \"e6500ff0DNM\", -- v6\n  uqadd16_3 = \"e6600f10DNM\", -- v6\n  uqasx_3 = \"e6600f30DNM\", -- v6\n  uqsax_3 = \"e6600f50DNM\", -- v6\n  uqsub16_3 = \"e6600f70DNM\", -- v6\n  uqadd8_3 = \"e6600f90DNM\", -- v6\n  uqsub8_3 = \"e6600ff0DNM\", -- v6\n  uhadd16_3 = \"e6700f10DNM\", -- v6\n  uhasx_3 = \"e6700f30DNM\", -- v6\n  uhsax_3 = \"e6700f50DNM\", -- v6\n  uhsub16_3 = \"e6700f70DNM\", -- v6\n  uhadd8_3 = \"e6700f90DNM\", -- v6\n  uhsub8_3 = \"e6700ff0DNM\", -- v6\n\n  -- Load/store instructions.\n  str_2 = \"e4000000DL\", str_3 = \"e4000000DL\", str_4 = \"e4000000DL\",\n  strb_2 = \"e4400000DL\", strb_3 = \"e4400000DL\", strb_4 = \"e4400000DL\",\n  ldr_2 = \"e4100000DL\", ldr_3 = \"e4100000DL\", ldr_4 = \"e4100000DL\",\n  ldrb_2 = \"e4500000DL\", ldrb_3 = \"e4500000DL\", ldrb_4 = \"e4500000DL\",\n  strh_2 = \"e00000b0DL\", strh_3 = \"e00000b0DL\",\n  ldrh_2 = \"e01000b0DL\", ldrh_3 = \"e01000b0DL\",\n  ldrd_2 = \"e00000d0DL\", ldrd_3 = \"e00000d0DL\", -- v5TE\n  ldrsb_2 = \"e01000d0DL\", ldrsb_3 = \"e01000d0DL\",\n  strd_2 = \"e00000f0DL\", strd_3 = \"e00000f0DL\", -- v5TE\n  ldrsh_2 = \"e01000f0DL\", ldrsh_3 = \"e01000f0DL\",\n\n  ldm_2 = \"e8900000oR\", ldmia_2 = \"e8900000oR\", ldmfd_2 = \"e8900000oR\",\n  ldmda_2 = \"e8100000oR\", ldmfa_2 = \"e8100000oR\",\n  ldmdb_2 = \"e9100000oR\", ldmea_2 = \"e9100000oR\",\n  ldmib_2 = \"e9900000oR\", ldmed_2 = \"e9900000oR\",\n  stm_2 = \"e8800000oR\", stmia_2 = \"e8800000oR\", stmfd_2 = \"e8800000oR\",\n  stmda_2 = \"e8000000oR\", stmfa_2 = \"e8000000oR\",\n  stmdb_2 = \"e9000000oR\", stmea_2 = \"e9000000oR\",\n  stmib_2 = \"e9800000oR\", stmed_2 = \"e9800000oR\",\n  pop_1 = \"e8bd0000R\", push_1 = \"e92d0000R\",\n\n  -- Branch instructions.\n  b_1 = \"ea000000B\",\n  bl_1 = \"eb000000B\",\n  blx_1 = \"e12fff30C\",\n  bx_1 = \"e12fff10M\",\n\n  -- Miscellaneous instructions.\n  nop_0 = \"e1a00000\",\n  mrs_1 = \"e10f0000D\",\n  bkpt_1 = \"e1200070K\", -- v5T\n  svc_1 = \"ef000000T\", swi_1 = \"ef000000T\",\n  ud_0 = \"e7f001f0\",\n\n  -- VFP instructions.\n  [\"vadd.f32_3\"] = \"ee300a00dnm\",\n  [\"vadd.f64_3\"] = \"ee300b00Gdnm\",\n  [\"vsub.f32_3\"] = \"ee300a40dnm\",\n  [\"vsub.f64_3\"] = \"ee300b40Gdnm\",\n  [\"vmul.f32_3\"] = \"ee200a00dnm\",\n  [\"vmul.f64_3\"] = \"ee200b00Gdnm\",\n  [\"vnmul.f32_3\"] = \"ee200a40dnm\",\n  [\"vnmul.f64_3\"] = \"ee200b40Gdnm\",\n  [\"vmla.f32_3\"] = \"ee000a00dnm\",\n  [\"vmla.f64_3\"] = \"ee000b00Gdnm\",\n  [\"vmls.f32_3\"] = \"ee000a40dnm\",\n  [\"vmls.f64_3\"] = \"ee000b40Gdnm\",\n  [\"vnmla.f32_3\"] = \"ee100a40dnm\",\n  [\"vnmla.f64_3\"] = \"ee100b40Gdnm\",\n  [\"vnmls.f32_3\"] = \"ee100a00dnm\",\n  [\"vnmls.f64_3\"] = \"ee100b00Gdnm\",\n  [\"vdiv.f32_3\"] = \"ee800a00dnm\",\n  [\"vdiv.f64_3\"] = \"ee800b00Gdnm\",\n\n  [\"vabs.f32_2\"] = \"eeb00ac0dm\",\n  [\"vabs.f64_2\"] = \"eeb00bc0Gdm\",\n  [\"vneg.f32_2\"] = \"eeb10a40dm\",\n  [\"vneg.f64_2\"] = \"eeb10b40Gdm\",\n  [\"vsqrt.f32_2\"] = \"eeb10ac0dm\",\n  [\"vsqrt.f64_2\"] = \"eeb10bc0Gdm\",\n  [\"vcmp.f32_2\"] = \"eeb40a40dm\",\n  [\"vcmp.f64_2\"] = \"eeb40b40Gdm\",\n  [\"vcmpe.f32_2\"] = \"eeb40ac0dm\",\n  [\"vcmpe.f64_2\"] = \"eeb40bc0Gdm\",\n  [\"vcmpz.f32_1\"] = \"eeb50a40d\",\n  [\"vcmpz.f64_1\"] = \"eeb50b40Gd\",\n  [\"vcmpze.f32_1\"] = \"eeb50ac0d\",\n  [\"vcmpze.f64_1\"] = \"eeb50bc0Gd\",\n\n  vldr_2 = \"ed100a00dl|ed100b00Gdl\",\n  vstr_2 = \"ed000a00dl|ed000b00Gdl\",\n  vldm_2 = \"ec900a00or\",\n  vldmia_2 = \"ec900a00or\",\n  vldmdb_2 = \"ed100a00or\",\n  vpop_1 = \"ecbd0a00r\",\n  vstm_2 = \"ec800a00or\",\n  vstmia_2 = \"ec800a00or\",\n  vstmdb_2 = \"ed000a00or\",\n  vpush_1 = \"ed2d0a00r\",\n\n  [\"vmov.f32_2\"] = \"eeb00a40dm|eeb00a00dY\",\t-- #imm is VFPv3 only\n  [\"vmov.f64_2\"] = \"eeb00b40Gdm|eeb00b00GdY\",\t-- #imm is VFPv3 only\n  vmov_2 = \"ee100a10Dn|ee000a10nD\",\n  vmov_3 = \"ec500a10DNm|ec400a10mDN|ec500b10GDNm|ec400b10GmDN\",\n\n  vmrs_0 = \"eef1fa10\",\n  vmrs_1 = \"eef10a10D\",\n  vmsr_1 = \"eee10a10D\",\n\n  [\"vcvt.s32.f32_2\"] = \"eebd0ac0dm\",\n  [\"vcvt.s32.f64_2\"] = \"eebd0bc0dGm\",\n  [\"vcvt.u32.f32_2\"] = \"eebc0ac0dm\",\n  [\"vcvt.u32.f64_2\"] = \"eebc0bc0dGm\",\n  [\"vcvtr.s32.f32_2\"] = \"eebd0a40dm\",\n  [\"vcvtr.s32.f64_2\"] = \"eebd0b40dGm\",\n  [\"vcvtr.u32.f32_2\"] = \"eebc0a40dm\",\n  [\"vcvtr.u32.f64_2\"] = \"eebc0b40dGm\",\n  [\"vcvt.f32.s32_2\"] = \"eeb80ac0dm\",\n  [\"vcvt.f64.s32_2\"] = \"eeb80bc0GdFm\",\n  [\"vcvt.f32.u32_2\"] = \"eeb80a40dm\",\n  [\"vcvt.f64.u32_2\"] = \"eeb80b40GdFm\",\n  [\"vcvt.f32.f64_2\"] = \"eeb70bc0dGm\",\n  [\"vcvt.f64.f32_2\"] = \"eeb70ac0GdFm\",\n\n  -- VFPv4 only:\n  [\"vfma.f32_3\"] = \"eea00a00dnm\",\n  [\"vfma.f64_3\"] = \"eea00b00Gdnm\",\n  [\"vfms.f32_3\"] = \"eea00a40dnm\",\n  [\"vfms.f64_3\"] = \"eea00b40Gdnm\",\n  [\"vfnma.f32_3\"] = \"ee900a40dnm\",\n  [\"vfnma.f64_3\"] = \"ee900b40Gdnm\",\n  [\"vfnms.f32_3\"] = \"ee900a00dnm\",\n  [\"vfnms.f64_3\"] = \"ee900b00Gdnm\",\n\n  -- NYI: Advanced SIMD instructions.\n\n  -- NYI: I have no need for these instructions right now:\n  -- swp, swpb, strex, ldrex, strexd, ldrexd, strexb, ldrexb, strexh, ldrexh\n  -- msr, nopv6, yield, wfe, wfi, sev, dbg, bxj, smc, srs, rfe\n  -- cps, setend, pli, pld, pldw, clrex, dsb, dmb, isb\n  -- stc, ldc, mcr, mcr2, mrc, mrc2, mcrr, mcrr2, mrrc, mrrc2, cdp, cdp2\n}\n\n-- Add mnemonics for \"s\" variants.\ndo\n  local t = {}\n  for k,v in pairs(map_op) do\n    if sub(v, -1) == \"s\" then\n      local v2 = sub(v, 1, 2)..char(byte(v, 3)+1)..sub(v, 4, -2)\n      t[sub(k, 1, -3)..\"s\"..sub(k, -2)] = v2\n    end\n  end\n  for k,v in pairs(t) do\n    map_op[k] = v\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r1?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r(1?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 15 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_gpr_pm(expr)\n  local pm, expr2 = match(expr, \"^([+-]?)(.*)$\")\n  return parse_gpr(expr2), (pm == \"-\")\nend\n\nlocal function parse_vr(expr, tp)\n  local t, r = match(expr, \"^([sd])([0-9]+)$\")\n  if t == tp then\n    r = tonumber(r)\n    if r <= 31 then\n      if t == \"s\" then return shr(r, 1), band(r, 1) end\n      return band(r, 15), shr(r, 4)\n    end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_reglist(reglist)\n  reglist = match(reglist, \"^{%s*([^}]*)}$\")\n  if not reglist then werror(\"register list expected\") end\n  local rr = 0\n  for p in gmatch(reglist..\",\", \"%s*([^,]*),\") do\n    local rbit = shl(1, parse_gpr(gsub(p, \"%s+$\", \"\")))\n    if band(rr, rbit) ~= 0 then\n      werror(\"duplicate register `\"..p..\"'\")\n    end\n    rr = rr + rbit\n  end\n  return rr\nend\n\nlocal function parse_vrlist(reglist)\n  local ta, ra, tb, rb = match(reglist,\n\t\t\t   \"^{%s*([sd])([0-9]+)%s*%-%s*([sd])([0-9]+)%s*}$\")\n  ra, rb = tonumber(ra), tonumber(rb)\n  if ta and ta == tb and ra and rb and ra <= 31 and rb <= 31 and ra <= rb then\n    local nr = rb+1 - ra\n    if ta == \"s\" then\n      return shl(shr(ra,1),12)+shl(band(ra,1),22) + nr\n    else\n      return shl(band(ra,15),12)+shl(shr(ra,4),22) + nr*2 + 0x100\n    end\n  end\n  werror(\"register list expected\")\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = tonumber(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm12(imm)\n  local n = tonumber(imm)\n  if n then\n    local m = band(n)\n    for i=0,-15,-1 do\n      if shr(m, 8) == 0 then return m + shl(band(i, 15), 8) end\n      m = ror(m, 2)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM12\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm16(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = tonumber(imm)\n  if n then\n    if shr(n, 16) == 0 then return band(n, 0x0fff) + shl(band(n, 0xf000), 4) end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM16\", 32*16, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm_load(imm, ext)\n  local n = tonumber(imm)\n  if n then\n    if ext then\n      if n >= -255 and n <= 255 then\n\tlocal up = 0x00800000\n\tif n < 0 then n = -n; up = 0 end\n\treturn shl(band(n, 0xf0), 4) + band(n, 0x0f) + up\n      end\n    else\n      if n >= -4095 and n <= 4095 then\n\tif n >= 0 then return n+0x00800000 end\n\treturn -n\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(ext and \"IMML8\" or \"IMML12\", 32768 + shl(ext and 8 or 12, 5), imm)\n    return 0\n  end\nend\n\nlocal function parse_shift(shift, gprok)\n  if shift == \"rrx\" then\n    return 3 * 32\n  else\n    local s, s2 = match(shift, \"^(%S+)%s*(.*)$\")\n    s = map_shift[s]\n    if not s then werror(\"expected shift operand\") end\n    if sub(s2, 1, 1) == \"#\" then\n      return parse_imm(s2, 5, 7, 0, false) + shl(s, 5)\n    else\n      if not gprok then werror(\"expected immediate shift operand\") end\n      return shl(parse_gpr(s2), 8) + shl(s, 5) + 16\n    end\n  end\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\nlocal function parse_load(params, nparams, n, op)\n  local oplo = band(op, 255)\n  local ext, ldrd = (oplo ~= 0), (oplo == 208)\n  local d\n  if (ldrd or oplo == 240) then\n    d = band(shr(op, 12), 15)\n    if band(d, 1) ~= 0 then werror(\"odd destination register\") end\n  end\n  local pn = params[n]\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  local p2 = params[n+1]\n  if not p1 then\n    if not p2 then\n      if match(pn, \"^[<>=%-]\") or match(pn, \"^extern%s+\") then\n\tlocal mode, n, s = parse_label(pn, false)\n\twaction(\"REL_\"..mode, n + (ext and 0x1800 or 0x0800), s, 1)\n\treturn op + 15 * 65536 + 0x01000000 + (ext and 0x00400000 or 0)\n      end\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal d, tp = parse_gpr(reg)\n\tif tp then\n\t  waction(ext and \"IMML8\" or \"IMML12\", 32768 + 32*(ext and 8 or 12),\n\t\t  format(tp.ctypefmt, tailr))\n\t  return op + shl(d, 16) + 0x01000000 + (ext and 0x00400000 or 0)\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  if wb == \"!\" then op = op + 0x00200000 end\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    local p3 = params[n+2]\n    op = op + shl(parse_gpr(p1), 16)\n    local imm = match(p2, \"^#(.*)$\")\n    if imm then\n      local m = parse_imm_load(imm, ext)\n      if p3 then werror(\"too many parameters\") end\n      op = op + m + (ext and 0x00400000 or 0)\n    else\n      local m, neg = parse_gpr_pm(p2)\n      if ldrd and (m == d or m-1 == d) then werror(\"register conflict\") end\n      op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)\n      if p3 then op = op + parse_shift(p3) end\n    end\n  else\n    local p1a, p2 = match(p1, \"^([^,%s]*)%s*(.*)$\")\n    op = op + shl(parse_gpr(p1a), 16) + 0x01000000\n    if p2 ~= \"\" then\n      local imm = match(p2, \"^,%s*#(.*)$\")\n      if imm then\n\tlocal m = parse_imm_load(imm, ext)\n\top = op + m + (ext and 0x00400000 or 0)\n      else\n\tlocal p2a, p3 = match(p2, \"^,%s*([^,%s]*)%s*,?%s*(.*)$\")\n\tlocal m, neg = parse_gpr_pm(p2a)\n\tif ldrd and (m == d or m-1 == d) then werror(\"register conflict\") end\n\top = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)\n\tif p3 ~= \"\" then\n\t  if ext then werror(\"too many parameters\") end\n\t  op = op + parse_shift(p3)\n\tend\n      end\n    else\n      if wb == \"!\" then werror(\"bad use of '!'\") end\n      op = op + (ext and 0x00c00000 or 0x00800000)\n    end\n  end\n  return op\nend\n\nlocal function parse_vload(q)\n  local reg, imm = match(q, \"^%[%s*([^,%s]*)%s*(.*)%]$\")\n  if reg then\n    local d = shl(parse_gpr(reg), 16)\n    if imm == \"\" then return d end\n    imm = match(imm, \"^,%s*#(.*)$\")\n    if imm then\n      local n = tonumber(imm)\n      if n then\n\tif n >= -1020 and n <= 1020 and n%4 == 0 then\n\t  return d + (n >= 0 and n/4+0x00800000 or -n/4)\n\tend\n\twerror(\"out of range immediate `\"..imm..\"'\")\n      else\n\twaction(\"IMMV8\", 32768 + 32*8, imm)\n\treturn d\n      end\n    end\n  else\n    if match(q, \"^[<>=%-]\") or match(q, \"^extern%s+\") then\n      local mode, n, s = parse_label(q, false)\n      waction(\"REL_\"..mode, n + 0x2800, s, 1)\n      return 15 * 65536\n    end\n    local reg, tailr = match(q, \"^([%w_:]+)%s*(.*)$\")\n    if reg and tailr ~= \"\" then\n      local d, tp = parse_gpr(reg)\n      if tp then\n\twaction(\"IMMV8\", 32768 + 32*8, format(tp.ctypefmt, tailr))\n\treturn shl(d, 16)\n      end\n    end\n  end\n  werror(\"expected address operand\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nlocal function parse_template(params, template, nparams, pos)\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n = 1\n  local vr = \"s\"\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    local q = params[n]\n    if p == \"D\" then\n      op = op + shl(parse_gpr(q), 12); n = n + 1\n    elseif p == \"N\" then\n      op = op + shl(parse_gpr(q), 16); n = n + 1\n    elseif p == \"S\" then\n      op = op + shl(parse_gpr(q), 8); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_gpr(q); n = n + 1\n    elseif p == \"d\" then\n      local r,h = parse_vr(q, vr); op = op+shl(r,12)+shl(h,22); n = n + 1\n    elseif p == \"n\" then\n      local r,h = parse_vr(q, vr); op = op+shl(r,16)+shl(h,7); n = n + 1\n    elseif p == \"m\" then\n      local r,h = parse_vr(q, vr); op = op+r+shl(h,5); n = n + 1\n    elseif p == \"P\" then\n      local imm = match(q, \"^#(.*)$\")\n      if imm then\n\top = op + parse_imm12(imm) + 0x02000000\n      else\n\top = op + parse_gpr(q)\n      end\n      n = n + 1\n    elseif p == \"p\" then\n      op = op + parse_shift(q, true); n = n + 1\n    elseif p == \"L\" then\n      op = parse_load(params, nparams, n, op)\n    elseif p == \"l\" then\n      op = op + parse_vload(q)\n    elseif p == \"B\" then\n      local mode, n, s = parse_label(q, false)\n      waction(\"REL_\"..mode, n, s, 1)\n    elseif p == \"C\" then -- blx gpr vs. blx label.\n      if match(q, \"^([%w_]+):(r1?[0-9])$\") or match(q, \"^r(1?[0-9])$\") then\n\top = op + parse_gpr(q)\n      else\n\tif op < 0xe0000000 then werror(\"unconditional instruction\") end\n\tlocal mode, n, s = parse_label(q, false)\n\twaction(\"REL_\"..mode, n, s, 1)\n\top = 0xfa000000\n      end\n    elseif p == \"F\" then\n      vr = \"s\"\n    elseif p == \"G\" then\n      vr = \"d\"\n    elseif p == \"o\" then\n      local r, wb = match(q, \"^([^!]*)(!?)$\")\n      op = op + shl(parse_gpr(r), 16) + (wb == \"!\" and 0x00200000 or 0)\n      n = n + 1\n    elseif p == \"R\" then\n      op = op + parse_reglist(q); n = n + 1\n    elseif p == \"r\" then\n      op = op + parse_vrlist(q); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm16(q); n = n + 1\n    elseif p == \"v\" then\n      op = op + parse_imm(q, 5, 7, 0, false); n = n + 1\n    elseif p == \"w\" then\n      local imm = match(q, \"^#(.*)$\")\n      if imm then\n\top = op + parse_imm(q, 5, 7, 0, false); n = n + 1\n      else\n\top = op + shl(parse_gpr(q), 8) + 16\n      end\n    elseif p == \"X\" then\n      op = op + parse_imm(q, 5, 16, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      local imm = tonumber(match(q, \"^#(.*)$\")); n = n + 1\n      if not imm or shr(imm, 8) ~= 0 then\n\twerror(\"bad immediate operand\")\n      end\n      op = op + shl(band(imm, 0xf0), 12) + band(imm, 0x0f)\n    elseif p == \"K\" then\n      local imm = tonumber(match(q, \"^#(.*)$\")); n = n + 1\n      if not imm or shr(imm, 16) ~= 0 then\n\twerror(\"bad immediate operand\")\n      end\n      op = op + shl(band(imm, 0xfff0), 4) + band(imm, 0x000f)\n    elseif p == \"T\" then\n      op = op + parse_imm(q, 24, 0, 0, false); n = n + 1\n    elseif p == \"s\" then\n      -- Ignored.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return template:gsub(\"%x%x%x%x%x%x%x%x\", \"\") end\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 3 positions.\n  if secpos+3 > maxsecpos then wflush() end\n  local pos = wpos()\n  local lpos, apos, spos = #actlist, #actargs, secpos\n\n  local ok, err\n  for t in gmatch(template, \"[^|]+\") do\n    ok, err = pcall(parse_template, params, t, nparams, pos)\n    if ok then return end\n    secpos = spos\n    actlist[lpos+1] = nil\n    actlist[lpos+2] = nil\n    actlist[lpos+3] = nil\n    actargs[apos+1] = nil\n    actargs[apos+2] = nil\n    actargs[apos+3] = nil\n  end\n  error(err, 0)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = function(t, k)\n    local v = map_coreop[k]\n    if v then return v end\n    local k1, cc, k2 = match(k, \"^(.-)(..)([._].*)$\")\n    local cv = map_cond[cc]\n    if cv then\n      local v = rawget(t, k1..k2)\n      if type(v) == \"string\" then\n\tlocal scv = format(\"%x\", cv)\n\treturn gsub(scv..sub(v, 2), \"|e\", \"|\"..scv)\n      end\n    end\n  end })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_arm64.h",
    "content": "/*\n** DynASM ARM64 encoding engine.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"arm64\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC,\n  DASM_IMM, DASM_IMM6, DASM_IMM12, DASM_IMM13W, DASM_IMM13X, DASM_IMML,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\nstatic int dasm_imm12(unsigned int n)\n{\n  if ((n >> 12) == 0)\n    return n;\n  else if ((n & 0xff000fff) == 0)\n    return (n >> 12) | 0x1000;\n  else\n    return -1;\n}\n\nstatic int dasm_ffs(unsigned long long x)\n{\n  int n = -1;\n  while (x) { x >>= 1; n++; }\n  return n;\n}\n\nstatic int dasm_imm13(int lo, int hi)\n{\n  int inv = 0, w = 64, s = 0xfff, xa, xb;\n  unsigned long long n = (((unsigned long long)hi) << 32) | (unsigned int)lo;\n  unsigned long long m = 1ULL, a, b, c;\n  if (n & 1) { n = ~n; inv = 1; }\n  a = n & -n; b = (n+a)&-(n+a); c = (n+a-b)&-(n+a-b);\n  xa = dasm_ffs(a); xb = dasm_ffs(b);\n  if (c) {\n    w = dasm_ffs(c) - xa;\n    if (w == 32) m = 0x0000000100000001UL;\n    else if (w == 16) m = 0x0001000100010001UL;\n    else if (w == 8) m = 0x0101010101010101UL;\n    else if (w == 4) m = 0x1111111111111111UL;\n    else if (w == 2) m = 0x5555555555555555UL;\n    else return -1;\n    s = (-2*w & 0x3f) - 1;\n  } else if (!a) {\n    return -1;\n  } else if (xb == -1) {\n    xb = 64;\n  }\n  if ((b-a) * m != n) return -1;\n  if (inv) {\n    return ((w - xb) << 6) | (s+w+xa-xb);\n  } else {\n    return ((w - xa) << 6) | (s+xb-xa);\n  }\n  return -1;\n}\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif ((ins & 0x8000))\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM6:\n\tCK((n >> 6) == 0, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM12:\n\tCK(dasm_imm12((unsigned int)n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM13W:\n\tCK(dasm_imm13(n, n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM13X: {\n\tint m = va_arg(ap, int);\n\tCK(dasm_imm13(n, m) != -1, RANGE_I);\n\tb[pos++] = n;\n\tb[pos++] = m;\n\tbreak;\n\t}\n      case DASM_IMML: {\n#ifdef DASM_CHECKS\n\tint scale = (p[-2] >> 30);\n\tCK((!(n & ((1<<scale)-1)) && (unsigned int)(n>>scale) < 4096) ||\n\t   (unsigned int)(n+256) < 512, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n\t}\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMM6: case DASM_IMM12: case DASM_IMM13W:\n\tcase DASM_IMML: pos++; break;\n\tcase DASM_IMM13X: pos += 2; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048));\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  CK(n >= 0, UNDEF_LG);\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) + 4;\n\tpatchrel:\n\t  if (!(ins & 0xf800)) {  /* B, BL */\n\t    CK((n & 3) == 0 && ((n+0x08000000) >> 28) == 0, RANGE_REL);\n\t    cp[-1] |= ((n >> 2) & 0x03ffffff);\n\t  } else if ((ins & 0x800)) {  /* B.cond, CBZ, CBNZ, LDR* literal */\n\t    CK((n & 3) == 0 && ((n+0x00100000) >> 21) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x00ffffe0);\n\t  } else if ((ins & 0x3000) == 0x2000) {  /* ADR */\n\t    CK(((n+0x00100000) >> 21) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x00ffffe0) | ((n & 3) << 29);\n\t  } else if ((ins & 0x3000) == 0x3000) {  /* ADRP */\n\t    cp[-1] |= ((n >> 9) & 0x00ffffe0) | (((n >> 12) & 3) << 29);\n\t  } else if ((ins & 0x1000)) {  /* TBZ, TBNZ */\n\t    CK((n & 3) == 0 && ((n+0x00008000) >> 16) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x0007ffe0);\n\t  }\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMM6:\n\t  cp[-1] |= ((n&31) << 19) | ((n&32) << 26);\n\t  break;\n\tcase DASM_IMM12:\n\t  cp[-1] |= (dasm_imm12((unsigned int)n) << 10);\n\t  break;\n\tcase DASM_IMM13W:\n\t  cp[-1] |= (dasm_imm13(n, n) << 10);\n\t  break;\n\tcase DASM_IMM13X:\n\t  cp[-1] |= (dasm_imm13(n, *b++) << 10);\n\t  break;\n\tcase DASM_IMML: {\n\t  int scale = (p[-2] >> 30);\n\t  cp[-1] |= (!(n & ((1<<scale)-1)) && (unsigned int)(n>>scale) < 4096) ?\n\t    ((n << (10-scale)) | 0x01000000) : ((n & 511) << 12);\n\t  break;\n\t  }\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_arm64.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM ARM64 module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"arm\",\n  description =\t\"DynASM ARM64 module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable, rawget = assert, setmetatable, rawget\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, insert = table.concat, table.sort, table.insert\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal ror, tohex = bit.ror, bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMM6\", \"IMM12\", \"IMM13W\", \"IMM13X\", \"IMML\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0x000fffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  if n <= 0x000fffff then\n    insert(actlist, pos+1, n)\n    n = map_action.ESC * 0x10000\n  end\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\n\n-- Ext. register name -> int. name.\nlocal map_archdef = { xzr = \"@x31\", wzr = \"@w31\", lr = \"x30\", }\n\n-- Int. register name -> ext. name.\nlocal map_reg_rev = { [\"@x31\"] = \"xzr\", [\"@w31\"] = \"wzr\", x30 = \"lr\", }\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return map_reg_rev[s] or s\nend\n\nlocal map_shift = { lsl = 0, lsr = 1, asr = 2, }\n\nlocal map_extend = {\n  uxtb = 0, uxth = 1, uxtw = 2, uxtx = 3,\n  sxtb = 4, sxth = 5, sxtw = 6, sxtx = 7,\n}\n\nlocal map_cond = {\n  eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,\n  hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,\n  hs = 2, lo = 3,\n}\n\n------------------------------------------------------------------------------\n\nlocal parse_reg_type\n\nlocal function parse_reg(expr)\n  if not expr then werror(\"expected register name\") end\n  local tname, ovreg = match(expr, \"^([%w_]+):(@?%l%d+)$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local ok31, rt, r = match(expr, \"^(@?)([xwqdshb])([123]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 30 or (r == 31 and ok31 ~= \"\" or (rt ~= \"w\" and rt ~= \"x\")) then\n      if not parse_reg_type then\n\tparse_reg_type = rt\n      elseif parse_reg_type ~= rt then\n\twerror(\"register size mismatch\")\n      end\n      return r, tp\n    end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_reg_base(expr)\n  if expr == \"sp\" then return 0x3e0 end\n  local base, tp = parse_reg(expr)\n  if parse_reg_type ~= \"x\" then werror(\"bad register type\") end\n  parse_reg_type = false\n  return shl(base, 5), tp\nend\n\nlocal parse_ctx = {}\n\nlocal loadenv = setfenv and function(s)\n  local code = loadstring(s, \"\")\n  if code then setfenv(code, parse_ctx) end\n  return code\nend or function(s)\n  return load(s, \"\", nil, parse_ctx)\nend\n\n-- Try to parse simple arithmetic, too, since some basic ops are aliases.\nlocal function parse_number(n)\n  local x = tonumber(n)\n  if x then return x end\n  local code = loadenv(\"return \"..n)\n  if code then\n    local ok, y = pcall(code)\n    if ok then return y end\n  end\n  return nil\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm12(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    if shr(n, 12) == 0 then\n      return shl(n, 10)\n    elseif band(n, 0xff000fff) == 0 then\n      return shr(n, 2) + 0x00400000\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM12\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm13(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  local r64 = parse_reg_type == \"x\"\n  if n and n % 1 == 0 and n >= 0 and n <= 0xffffffff then\n    local inv = false\n    if band(n, 1) == 1 then n = bit.bnot(n); inv = true end\n    local t = {}\n    for i=1,32 do t[i] = band(n, 1); n = shr(n, 1) end\n    local b = table.concat(t)\n    b = b..(r64 and (inv and \"1\" or \"0\"):rep(32) or b)\n    local p0, p1, p0a, p1a = b:match(\"^(0+)(1+)(0*)(1*)\")\n    if p0 then\n      local w = p1a == \"\" and (r64 and 64 or 32) or #p1+#p0a\n      if band(w, w-1) == 0 and b == b:sub(1, w):rep(64/w) then\n\tlocal s = band(-2*w, 0x3f) - 1\n\tif w == 64 then s = s + 0x1000 end\n\tif inv then\n\t  return shl(w-#p1-#p0, 16) + shl(s+w-#p1, 10)\n\telse\n\t  return shl(w-#p0, 16) + shl(s+#p1, 10)\n\tend\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif r64 then\n    waction(\"IMM13X\", 0, format(\"(unsigned int)(%s)\", imm))\n    actargs[#actargs+1] = format(\"(unsigned int)((unsigned long long)(%s)>>32)\", imm)\n    return 0\n  else\n    waction(\"IMM13W\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm6(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    if n >= 0 and n <= 63 then\n      return shl(band(n, 0x1f), 19) + (n >= 32 and 0x80000000 or 0)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM6\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm_load(imm, scale)\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n and m >= 0 and m < 0x1000 then\n      return shl(m, 10) + 0x01000000 -- Scaled, unsigned 12 bit offset.\n    elseif n >= -256 and n < 256 then\n      return shl(band(n, 511), 12) -- Unscaled, signed 9 bit offset.\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMML\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_fpimm(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    local m, e = math.frexp(n)\n    local s, e2 = 0, band(e-2, 7)\n    if m < 0 then m = -m; s = 0x00100000 end\n    m = m*32-16\n    if m % 1 == 0 and m >= 0 and m <= 15 and sar(shl(e2, 29), 29)+2 == e then\n      return s + shl(e2, 17) + shl(m, 13)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    werror(\"NYI fpimm action\")\n  end\nend\n\nlocal function parse_shift(expr)\n  local s, s2 = match(expr, \"^(%S+)%s*(.*)$\")\n  s = map_shift[s]\n  if not s then werror(\"expected shift operand\") end\n  return parse_imm(s2, 6, 10, 0, false) + shl(s, 22)\nend\n\nlocal function parse_lslx16(expr)\n  local n = match(expr, \"^lsl%s*#(%d+)$\")\n  n = tonumber(n)\n  if not n then werror(\"expected shift operand\") end\n  if band(n, parse_reg_type == \"x\" and 0xffffffcf or 0xffffffef) ~= 0 then\n    werror(\"bad shift amount\")\n  end\n  return shl(n, 17)\nend\n\nlocal function parse_extend(expr)\n  local s, s2 = match(expr, \"^(%S+)%s*(.*)$\")\n  if s == \"lsl\" then\n    s = parse_reg_type == \"x\" and 3 or 2\n  else\n    s = map_extend[s]\n  end\n  if not s then werror(\"expected extend operand\") end\n  return (s2 == \"\" and 0 or parse_imm(s2, 3, 10, 0, false)) + shl(s, 13)\nend\n\nlocal function parse_cond(expr, inv)\n  local c = map_cond[expr]\n  if not c then werror(\"expected condition operand\") end\n  return shl(bit.bxor(c, inv), 12)\nend\n\nlocal function parse_load(params, nparams, n, op)\n  if params[n+2] then werror(\"too many operands\") end\n  local pn, p2 = params[n], params[n+1]\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  if not p1 then\n    if not p2 then\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal base, tp = parse_reg_base(reg)\n\tif tp then\n\t  waction(\"IMML\", 0, format(tp.ctypefmt, tailr))\n\t  return op + base\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  local scale = shr(op, 30)\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    op = op + parse_reg_base(p1) + parse_imm(p2, 9, 12, 0, true) + 0x400\n  elseif wb == \"!\" then\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*,%s*(.*)$\")\n    if not p1a then werror(\"bad use of '!'\") end\n    op = op + parse_reg_base(p1a) + parse_imm(p2a, 9, 12, 0, true) + 0xc00\n  else\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*(.*)$\")\n    op = op + parse_reg_base(p1a)\n    if p2a ~= \"\" then\n      local imm = match(p2a, \"^,%s*#(.*)$\")\n      if imm then\n\top = op + parse_imm_load(imm, scale)\n      else\n\tlocal p2b, p3b, p3s = match(p2a, \"^,%s*([^,%s]*)%s*,?%s*(%S*)%s*(.*)$\")\n\top = op + shl(parse_reg(p2b), 16) + 0x00200800\n\tif parse_reg_type ~= \"x\" and parse_reg_type ~= \"w\" then\n\t  werror(\"bad index register type\")\n\tend\n\tif p3b == \"\" then\n\t  if parse_reg_type ~= \"x\" then werror(\"bad index register type\") end\n\t  op = op + 0x6000\n\telse\n\t  if p3s == \"\" or p3s == \"#0\" then\n\t  elseif p3s == \"#\"..scale then\n\t    op = op + 0x1000\n\t  else\n\t    werror(\"bad scale\")\n\t  end\n\t  if parse_reg_type == \"x\" then\n\t    if p3b == \"lsl\" and p3s ~= \"\" then op = op + 0x6000\n\t    elseif p3b == \"sxtx\" then op = op + 0xe000\n\t    else\n\t      werror(\"bad extend/shift specifier\")\n\t    end\n\t  else\n\t    if p3b == \"uxtw\" then op = op + 0x4000\n\t    elseif p3b == \"sxtw\" then op = op + 0xc000\n\t    else\n\t      werror(\"bad extend/shift specifier\")\n\t    end\n\t  end\n\tend\n      end\n    else\n      if wb == \"!\" then werror(\"bad use of '!'\") end\n      op = op + 0x01000000\n    end\n  end\n  return op\nend\n\nlocal function parse_load_pair(params, nparams, n, op)\n  if params[n+2] then werror(\"too many operands\") end\n  local pn, p2 = params[n], params[n+1]\n  local scale = shr(op, 30) == 0 and 2 or 3\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  if not p1 then\n    if not p2 then\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal base, tp = parse_reg_base(reg)\n\tif tp then\n\t  waction(\"IMM\", 32768+7*32+15+scale*1024, format(tp.ctypefmt, tailr))\n\t  return op + base + 0x01000000\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    op = op + 0x00800000\n  else\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*,%s*(.*)$\")\n    if p1a then p1, p2 = p1a, p2a else p2 = \"#0\" end\n    op = op + (wb == \"!\" and 0x01800000 or 0x01000000)\n  end\n  return op + parse_reg_base(p1) + parse_imm(p2, 7, 15, scale, true)\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\nlocal function branch_type(op)\n  if band(op, 0x7c000000) == 0x14000000 then return 0 -- B, BL\n  elseif shr(op, 24) == 0x54 or band(op, 0x7e000000) == 0x34000000 or\n\t band(op, 0x3b000000) == 0x18000000 then\n    return 0x800 -- B.cond, CBZ, CBNZ, LDR* literal\n  elseif band(op, 0x7e000000) == 0x36000000 then return 0x1000 -- TBZ, TBNZ\n  elseif band(op, 0x9f000000) == 0x10000000 then return 0x2000 -- ADR\n  elseif band(op, 0x9f000000) == band(0x90000000) then return 0x3000 -- ADRP\n  else\n    assert(false, \"unknown branch type\")\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal map_op, op_template\n\nlocal function op_alias(opname, f)\n  return function(params, nparams)\n    if not params then return \"-> \"..opname:sub(1, -3) end\n    f(params, nparams)\n    op_template(params, map_op[opname], nparams)\n  end\nend\n\nlocal function alias_bfx(p)\n  p[4] = \"#(\"..p[3]:sub(2)..\")+(\"..p[4]:sub(2)..\")-1\"\nend\n\nlocal function alias_bfiz(p)\n  parse_reg(p[1])\n  if parse_reg_type == \"w\" then\n    p[3] = \"#-(\"..p[3]:sub(2)..\")%32\"\n    p[4] = \"#(\"..p[4]:sub(2)..\")-1\"\n  else\n    p[3] = \"#-(\"..p[3]:sub(2)..\")%64\"\n    p[4] = \"#(\"..p[4]:sub(2)..\")-1\"\n  end\nend\n\nlocal alias_lslimm = op_alias(\"ubfm_4\", function(p)\n  parse_reg(p[1])\n  local sh = p[3]:sub(2)\n  if parse_reg_type == \"w\" then\n    p[3] = \"#-(\"..sh..\")%32\"\n    p[4] = \"#31-(\"..sh..\")\"\n  else\n    p[3] = \"#-(\"..sh..\")%64\"\n    p[4] = \"#63-(\"..sh..\")\"\n  end\nend)\n\n-- Template strings for ARM instructions.\nmap_op = {\n  -- Basic data processing instructions.\n  add_3  = \"0b000000DNMg|11000000pDpNIg|8b206000pDpNMx\",\n  add_4  = \"0b000000DNMSg|0b200000DNMXg|8b200000pDpNMXx|8b200000pDpNxMwX\",\n  adds_3 = \"2b000000DNMg|31000000DpNIg|ab206000DpNMx\",\n  adds_4 = \"2b000000DNMSg|2b200000DNMXg|ab200000DpNMXx|ab200000DpNxMwX\",\n  cmn_2  = \"2b00001fNMg|3100001fpNIg|ab20601fpNMx\",\n  cmn_3  = \"2b00001fNMSg|2b20001fNMXg|ab20001fpNMXx|ab20001fpNxMwX\",\n\n  sub_3  = \"4b000000DNMg|51000000pDpNIg|cb206000pDpNMx\",\n  sub_4  = \"4b000000DNMSg|4b200000DNMXg|cb200000pDpNMXx|cb200000pDpNxMwX\",\n  subs_3 = \"6b000000DNMg|71000000DpNIg|eb206000DpNMx\",\n  subs_4 = \"6b000000DNMSg|6b200000DNMXg|eb200000DpNMXx|eb200000DpNxMwX\",\n  cmp_2  = \"6b00001fNMg|7100001fpNIg|eb20601fpNMx\",\n  cmp_3  = \"6b00001fNMSg|6b20001fNMXg|eb20001fpNMXx|eb20001fpNxMwX\",\n\n  neg_2  = \"4b0003e0DMg\",\n  neg_3  = \"4b0003e0DMSg\",\n  negs_2 = \"6b0003e0DMg\",\n  negs_3 = \"6b0003e0DMSg\",\n\n  adc_3  = \"1a000000DNMg\",\n  adcs_3 = \"3a000000DNMg\",\n  sbc_3  = \"5a000000DNMg\",\n  sbcs_3 = \"7a000000DNMg\",\n  ngc_2  = \"5a0003e0DMg\",\n  ngcs_2 = \"7a0003e0DMg\",\n\n  and_3  = \"0a000000DNMg|12000000pDNig\",\n  and_4  = \"0a000000DNMSg\",\n  orr_3  = \"2a000000DNMg|32000000pDNig\",\n  orr_4  = \"2a000000DNMSg\",\n  eor_3  = \"4a000000DNMg|52000000pDNig\",\n  eor_4  = \"4a000000DNMSg\",\n  ands_3 = \"6a000000DNMg|72000000DNig\",\n  ands_4 = \"6a000000DNMSg\",\n  tst_2  = \"6a00001fNMg|7200001fNig\",\n  tst_3  = \"6a00001fNMSg\",\n\n  bic_3  = \"0a200000DNMg\",\n  bic_4  = \"0a200000DNMSg\",\n  orn_3  = \"2a200000DNMg\",\n  orn_4  = \"2a200000DNMSg\",\n  eon_3  = \"4a200000DNMg\",\n  eon_4  = \"4a200000DNMSg\",\n  bics_3 = \"6a200000DNMg\",\n  bics_4 = \"6a200000DNMSg\",\n\n  movn_2 = \"12800000DWg\",\n  movn_3 = \"12800000DWRg\",\n  movz_2 = \"52800000DWg\",\n  movz_3 = \"52800000DWRg\",\n  movk_2 = \"72800000DWg\",\n  movk_3 = \"72800000DWRg\",\n\n  -- TODO: this doesn't cover all valid immediates for mov reg, #imm.\n  mov_2  = \"2a0003e0DMg|52800000DW|320003e0pDig|11000000pDpNg\",\n  mov_3  = \"2a0003e0DMSg\",\n  mvn_2  = \"2a2003e0DMg\",\n  mvn_3  = \"2a2003e0DMSg\",\n\n  adr_2  = \"10000000DBx\",\n  adrp_2 = \"90000000DBx\",\n\n  csel_4  = \"1a800000DNMCg\",\n  csinc_4 = \"1a800400DNMCg\",\n  csinv_4 = \"5a800000DNMCg\",\n  csneg_4 = \"5a800400DNMCg\",\n  cset_2  = \"1a9f07e0Dcg\",\n  csetm_2 = \"5a9f03e0Dcg\",\n  cinc_3  = \"1a800400DNmcg\",\n  cinv_3  = \"5a800000DNmcg\",\n  cneg_3  = \"5a800400DNmcg\",\n\n  ccmn_4 = \"3a400000NMVCg|3a400800N5VCg\",\n  ccmp_4 = \"7a400000NMVCg|7a400800N5VCg\",\n\n  madd_4 = \"1b000000DNMAg\",\n  msub_4 = \"1b008000DNMAg\",\n  mul_3  = \"1b007c00DNMg\",\n  mneg_3 = \"1b00fc00DNMg\",\n\n  smaddl_4 = \"9b200000DxNMwAx\",\n  smsubl_4 = \"9b208000DxNMwAx\",\n  smull_3  = \"9b207c00DxNMw\",\n  smnegl_3 = \"9b20fc00DxNMw\",\n  smulh_3  = \"9b407c00DNMx\",\n  umaddl_4 = \"9ba00000DxNMwAx\",\n  umsubl_4 = \"9ba08000DxNMwAx\",\n  umull_3  = \"9ba07c00DxNMw\",\n  umnegl_3 = \"9ba0fc00DxNMw\",\n  umulh_3  = \"9bc07c00DNMx\",\n\n  udiv_3 = \"1ac00800DNMg\",\n  sdiv_3 = \"1ac00c00DNMg\",\n\n  -- Bit operations.\n  sbfm_4 = \"13000000DN12w|93400000DN12x\",\n  bfm_4  = \"33000000DN12w|b3400000DN12x\",\n  ubfm_4 = \"53000000DN12w|d3400000DN12x\",\n  extr_4 = \"13800000DNM2w|93c00000DNM2x\",\n\n  sxtb_2 = \"13001c00DNw|93401c00DNx\",\n  sxth_2 = \"13003c00DNw|93403c00DNx\",\n  sxtw_2 = \"93407c00DxNw\",\n  uxtb_2 = \"53001c00DNw\",\n  uxth_2 = \"53003c00DNw\",\n\n  sbfx_4  = op_alias(\"sbfm_4\", alias_bfx),\n  bfxil_4 = op_alias(\"bfm_4\", alias_bfx),\n  ubfx_4  = op_alias(\"ubfm_4\", alias_bfx),\n  sbfiz_4 = op_alias(\"sbfm_4\", alias_bfiz),\n  bfi_4   = op_alias(\"bfm_4\", alias_bfiz),\n  ubfiz_4 = op_alias(\"ubfm_4\", alias_bfiz),\n\n  lsl_3  = function(params, nparams)\n    if params and params[3]:byte() == 35 then\n      return alias_lslimm(params, nparams)\n    else\n      return op_template(params, \"1ac02000DNMg\", nparams)\n    end\n  end,\n  lsr_3  = \"1ac02400DNMg|53007c00DN1w|d340fc00DN1x\",\n  asr_3  = \"1ac02800DNMg|13007c00DN1w|9340fc00DN1x\",\n  ror_3  = \"1ac02c00DNMg|13800000DNm2w|93c00000DNm2x\",\n\n  clz_2   = \"5ac01000DNg\",\n  cls_2   = \"5ac01400DNg\",\n  rbit_2  = \"5ac00000DNg\",\n  rev_2   = \"5ac00800DNw|dac00c00DNx\",\n  rev16_2 = \"5ac00400DNg\",\n  rev32_2 = \"dac00800DNx\",\n\n  -- Loads and stores.\n  [\"strb_*\"]  = \"38000000DwL\",\n  [\"ldrb_*\"]  = \"38400000DwL\",\n  [\"ldrsb_*\"] = \"38c00000DwL|38800000DxL\",\n  [\"strh_*\"]  = \"78000000DwL\",\n  [\"ldrh_*\"]  = \"78400000DwL\",\n  [\"ldrsh_*\"] = \"78c00000DwL|78800000DxL\",\n  [\"str_*\"]   = \"b8000000DwL|f8000000DxL|bc000000DsL|fc000000DdL\",\n  [\"ldr_*\"]   = \"18000000DwB|58000000DxB|1c000000DsB|5c000000DdB|b8400000DwL|f8400000DxL|bc400000DsL|fc400000DdL\",\n  [\"ldrsw_*\"] = \"98000000DxB|b8800000DxL\",\n  -- NOTE: ldur etc. are handled by ldr et al.\n\n  [\"stp_*\"]   = \"28000000DAwP|a8000000DAxP|2c000000DAsP|6c000000DAdP\",\n  [\"ldp_*\"]   = \"28400000DAwP|a8400000DAxP|2c400000DAsP|6c400000DAdP\",\n  [\"ldpsw_*\"] = \"68400000DAxP\",\n\n  -- Branches.\n  b_1    = \"14000000B\",\n  bl_1   = \"94000000B\",\n  blr_1  = \"d63f0000Nx\",\n  br_1   = \"d61f0000Nx\",\n  ret_0  = \"d65f03c0\",\n  ret_1  = \"d65f0000Nx\",\n  -- b.cond is added below.\n  cbz_2  = \"34000000DBg\",\n  cbnz_2 = \"35000000DBg\",\n  tbz_3  = \"36000000DTBw|36000000DTBx\",\n  tbnz_3 = \"37000000DTBw|37000000DTBx\",\n\n  -- Miscellaneous instructions.\n  -- TODO: hlt, hvc, smc, svc, eret, dcps[123], drps, mrs, msr\n  -- TODO: sys, sysl, ic, dc, at, tlbi\n  -- TODO: hint, yield, wfe, wfi, sev, sevl\n  -- TODO: clrex, dsb, dmb, isb\n  nop_0  = \"d503201f\",\n  brk_0  = \"d4200000\",\n  brk_1  = \"d4200000W\",\n\n  -- Floating point instructions.\n  fmov_2  = \"1e204000DNf|1e260000DwNs|1e270000DsNw|9e660000DxNd|9e670000DdNx|1e201000DFf\",\n  fabs_2  = \"1e20c000DNf\",\n  fneg_2  = \"1e214000DNf\",\n  fsqrt_2 = \"1e21c000DNf\",\n\n  fcvt_2  = \"1e22c000DdNs|1e624000DsNd\",\n\n  -- TODO: half-precision and fixed-point conversions.\n  fcvtas_2 = \"1e240000DwNs|9e240000DxNs|1e640000DwNd|9e640000DxNd\",\n  fcvtau_2 = \"1e250000DwNs|9e250000DxNs|1e650000DwNd|9e650000DxNd\",\n  fcvtms_2 = \"1e300000DwNs|9e300000DxNs|1e700000DwNd|9e700000DxNd\",\n  fcvtmu_2 = \"1e310000DwNs|9e310000DxNs|1e710000DwNd|9e710000DxNd\",\n  fcvtns_2 = \"1e200000DwNs|9e200000DxNs|1e600000DwNd|9e600000DxNd\",\n  fcvtnu_2 = \"1e210000DwNs|9e210000DxNs|1e610000DwNd|9e610000DxNd\",\n  fcvtps_2 = \"1e280000DwNs|9e280000DxNs|1e680000DwNd|9e680000DxNd\",\n  fcvtpu_2 = \"1e290000DwNs|9e290000DxNs|1e690000DwNd|9e690000DxNd\",\n  fcvtzs_2 = \"1e380000DwNs|9e380000DxNs|1e780000DwNd|9e780000DxNd\",\n  fcvtzu_2 = \"1e390000DwNs|9e390000DxNs|1e790000DwNd|9e790000DxNd\",\n\n  scvtf_2  = \"1e220000DsNw|9e220000DsNx|1e620000DdNw|9e620000DdNx\",\n  ucvtf_2  = \"1e230000DsNw|9e230000DsNx|1e630000DdNw|9e630000DdNx\",\n\n  frintn_2 = \"1e244000DNf\",\n  frintp_2 = \"1e24c000DNf\",\n  frintm_2 = \"1e254000DNf\",\n  frintz_2 = \"1e25c000DNf\",\n  frinta_2 = \"1e264000DNf\",\n  frintx_2 = \"1e274000DNf\",\n  frinti_2 = \"1e27c000DNf\",\n\n  fadd_3   = \"1e202800DNMf\",\n  fsub_3   = \"1e203800DNMf\",\n  fmul_3   = \"1e200800DNMf\",\n  fnmul_3  = \"1e208800DNMf\",\n  fdiv_3   = \"1e201800DNMf\",\n\n  fmadd_4  = \"1f000000DNMAf\",\n  fmsub_4  = \"1f008000DNMAf\",\n  fnmadd_4 = \"1f200000DNMAf\",\n  fnmsub_4 = \"1f208000DNMAf\",\n\n  fmax_3   = \"1e204800DNMf\",\n  fmaxnm_3 = \"1e206800DNMf\",\n  fmin_3   = \"1e205800DNMf\",\n  fminnm_3 = \"1e207800DNMf\",\n\n  fcmp_2   = \"1e202000NMf|1e202008NZf\",\n  fcmpe_2  = \"1e202010NMf|1e202018NZf\",\n\n  fccmp_4  = \"1e200400NMVCf\",\n  fccmpe_4 = \"1e200410NMVCf\",\n\n  fcsel_4  = \"1e200c00DNMCf\",\n\n  -- TODO: crc32*, aes*, sha*, pmull\n  -- TODO: SIMD instructions.\n}\n\nfor cond,c in pairs(map_cond) do\n  map_op[\"b\"..cond..\"_1\"] = tohex(0x54000000+c)..\"B\"\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nlocal function parse_template(params, template, nparams, pos)\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n = 1\n  local rtt = {}\n\n  parse_reg_type = false\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    local q = params[n]\n    if p == \"D\" then\n      op = op + parse_reg(q); n = n + 1\n    elseif p == \"N\" then\n      op = op + shl(parse_reg(q), 5); n = n + 1\n    elseif p == \"M\" then\n      op = op + shl(parse_reg(q), 16); n = n + 1\n    elseif p == \"A\" then\n      op = op + shl(parse_reg(q), 10); n = n + 1\n    elseif p == \"m\" then\n      op = op + shl(parse_reg(params[n-1]), 16)\n\n    elseif p == \"p\" then\n      if q == \"sp\" then params[n] = \"@x31\" end\n    elseif p == \"g\" then\n      if parse_reg_type == \"x\" then\n\top = op + 0x80000000\n      elseif parse_reg_type ~= \"w\" then\n\twerror(\"bad register type\")\n      end\n      parse_reg_type = false\n    elseif p == \"f\" then\n      if parse_reg_type == \"d\" then\n\top = op + 0x00400000\n      elseif parse_reg_type ~= \"s\" then\n\twerror(\"bad register type\")\n      end\n      parse_reg_type = false\n    elseif p == \"x\" or p == \"w\" or p == \"d\" or p == \"s\" then\n      if parse_reg_type ~= p then\n\twerror(\"register size mismatch\")\n      end\n      parse_reg_type = false\n\n    elseif p == \"L\" then\n      op = parse_load(params, nparams, n, op)\n    elseif p == \"P\" then\n      op = parse_load_pair(params, nparams, n, op)\n\n    elseif p == \"B\" then\n      local mode, v, s = parse_label(q, false); n = n + 1\n      local m = branch_type(op)\n      waction(\"REL_\"..mode, v+m, s, 1)\n\n    elseif p == \"I\" then\n      op = op + parse_imm12(q); n = n + 1\n    elseif p == \"i\" then\n      op = op + parse_imm13(q); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm(q, 16, 5, 0, false); n = n + 1\n    elseif p == \"T\" then\n      op = op + parse_imm6(q); n = n + 1\n    elseif p == \"1\" then\n      op = op + parse_imm(q, 6, 16, 0, false); n = n + 1\n    elseif p == \"2\" then\n      op = op + parse_imm(q, 6, 10, 0, false); n = n + 1\n    elseif p == \"5\" then\n      op = op + parse_imm(q, 5, 16, 0, false); n = n + 1\n    elseif p == \"V\" then\n      op = op + parse_imm(q, 4, 0, 0, false); n = n + 1\n    elseif p == \"F\" then\n      op = op + parse_fpimm(q); n = n + 1\n    elseif p == \"Z\" then\n      if q ~= \"#0\" and q ~= \"#0.0\" then werror(\"expected zero immediate\") end\n      n = n + 1\n\n    elseif p == \"S\" then\n      op = op + parse_shift(q); n = n + 1\n    elseif p == \"X\" then\n      op = op + parse_extend(q); n = n + 1\n    elseif p == \"R\" then\n      op = op + parse_lslx16(q); n = n + 1\n    elseif p == \"C\" then\n      op = op + parse_cond(q, 0); n = n + 1\n    elseif p == \"c\" then\n      op = op + parse_cond(q, 1); n = n + 1\n\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nfunction op_template(params, template, nparams)\n  if not params then return template:gsub(\"%x%x%x%x%x%x%x%x\", \"\") end\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 3 positions.\n  if secpos+3 > maxsecpos then wflush() end\n  local pos = wpos()\n  local lpos, apos, spos = #actlist, #actargs, secpos\n\n  local ok, err\n  for t in gmatch(template, \"[^|]+\") do\n    ok, err = pcall(parse_template, params, t, nparams, pos)\n    if ok then return end\n    secpos = spos\n    actlist[lpos+1] = nil\n    actlist[lpos+2] = nil\n    actlist[lpos+3] = nil\n    actargs[apos+1] = nil\n    actargs[apos+2] = nil\n    actargs[apos+3] = nil\n  end\n  error(err, 0)\nend\n\nmap_op[\".template__\"] = op_template\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_mips.h",
    "content": "/*\n** DynASM MIPS encoding engine.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"mips\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC, DASM_IMM,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16) - 0xff00;\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n#endif\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif (ins & 0x8000)\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16) - 0xff00;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16) - 0xff00;\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1);\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  CK(n >= 0, UNDEF_LG);\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n);\n\t  if (ins & 2048)\n\t    n = n - (int)((char *)cp - base);\n\t  else\n\t    n = (n + (int)base) & 0x0fffffff;\n\tpatchrel:\n\t  CK((n & 3) == 0 &&\n\t     ((n + ((ins & 2048) ? 0x00020000 : 0)) >>\n\t       ((ins & 2048) ? 18 : 28)) == 0, RANGE_REL);\n\t  cp[-1] |= ((n>>2) & ((ins & 2048) ? 0x0000ffff: 0x03ffffff));\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_mips.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM MIPS module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"mips\",\n  description =\t\"DynASM MIPS module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable = assert, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch = _s.match, _s.gmatch\nlocal concat, sort = table.concat, table.sort\nlocal bit = bit or require(\"bit\")\nlocal band, shl, sar, tohex = bit.band, bit.lshift, bit.arshift, bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(0xff000000 + w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n >= 0xff000000 then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = { sp=\"r29\", ra=\"r31\" } -- Ext. register name -> int. name.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  if s == \"r29\" then return \"sp\"\n  elseif s == \"r31\" then return \"ra\" end\n  return s\nend\n\n------------------------------------------------------------------------------\n\n-- Template strings for MIPS instructions.\nlocal map_op = {\n  -- First-level opcodes.\n  j_1 =\t\t\"08000000J\",\n  jal_1 =\t\"0c000000J\",\n  b_1 =\t\t\"10000000B\",\n  beqz_2 =\t\"10000000SB\",\n  beq_3 =\t\"10000000STB\",\n  bnez_2 =\t\"14000000SB\",\n  bne_3 =\t\"14000000STB\",\n  blez_2 =\t\"18000000SB\",\n  bgtz_2 =\t\"1c000000SB\",\n  addi_3 =\t\"20000000TSI\",\n  li_2 =\t\"24000000TI\",\n  addiu_3 =\t\"24000000TSI\",\n  slti_3 =\t\"28000000TSI\",\n  sltiu_3 =\t\"2c000000TSI\",\n  andi_3 =\t\"30000000TSU\",\n  lu_2 =\t\"34000000TU\",\n  ori_3 =\t\"34000000TSU\",\n  xori_3 =\t\"38000000TSU\",\n  lui_2 =\t\"3c000000TU\",\n  beqzl_2 =\t\"50000000SB\",\n  beql_3 =\t\"50000000STB\",\n  bnezl_2 =\t\"54000000SB\",\n  bnel_3 =\t\"54000000STB\",\n  blezl_2 =\t\"58000000SB\",\n  bgtzl_2 =\t\"5c000000SB\",\n  lb_2 =\t\"80000000TO\",\n  lh_2 =\t\"84000000TO\",\n  lwl_2 =\t\"88000000TO\",\n  lw_2 =\t\"8c000000TO\",\n  lbu_2 =\t\"90000000TO\",\n  lhu_2 =\t\"94000000TO\",\n  lwr_2 =\t\"98000000TO\",\n  sb_2 =\t\"a0000000TO\",\n  sh_2 =\t\"a4000000TO\",\n  swl_2 =\t\"a8000000TO\",\n  sw_2 =\t\"ac000000TO\",\n  swr_2 =\t\"b8000000TO\",\n  cache_2 =\t\"bc000000NO\",\n  ll_2 =\t\"c0000000TO\",\n  lwc1_2 =\t\"c4000000HO\",\n  pref_2 =\t\"cc000000NO\",\n  ldc1_2 =\t\"d4000000HO\",\n  sc_2 =\t\"e0000000TO\",\n  swc1_2 =\t\"e4000000HO\",\n  sdc1_2 =\t\"f4000000HO\",\n\n  -- Opcode SPECIAL.\n  nop_0 =\t\"00000000\",\n  sll_3 =\t\"00000000DTA\",\n  movf_2 =\t\"00000001DS\",\n  movf_3 =\t\"00000001DSC\",\n  movt_2 =\t\"00010001DS\",\n  movt_3 =\t\"00010001DSC\",\n  srl_3 =\t\"00000002DTA\",\n  rotr_3 =\t\"00200002DTA\",\n  sra_3 =\t\"00000003DTA\",\n  sllv_3 =\t\"00000004DTS\",\n  srlv_3 =\t\"00000006DTS\",\n  rotrv_3 =\t\"00000046DTS\",\n  srav_3 =\t\"00000007DTS\",\n  jr_1 =\t\"00000008S\",\n  jalr_1 =\t\"0000f809S\",\n  jalr_2 =\t\"00000009DS\",\n  movz_3 =\t\"0000000aDST\",\n  movn_3 =\t\"0000000bDST\",\n  syscall_0 =\t\"0000000c\",\n  syscall_1 =\t\"0000000cY\",\n  break_0 =\t\"0000000d\",\n  break_1 =\t\"0000000dY\",\n  sync_0 =\t\"0000000f\",\n  mfhi_1 =\t\"00000010D\",\n  mthi_1 =\t\"00000011S\",\n  mflo_1 =\t\"00000012D\",\n  mtlo_1 =\t\"00000013S\",\n  mult_2 =\t\"00000018ST\",\n  multu_2 =\t\"00000019ST\",\n  div_2 =\t\"0000001aST\",\n  divu_2 =\t\"0000001bST\",\n  add_3 =\t\"00000020DST\",\n  move_2 =\t\"00000021DS\",\n  addu_3 =\t\"00000021DST\",\n  sub_3 =\t\"00000022DST\",\n  negu_2 =\t\"00000023DT\",\n  subu_3 =\t\"00000023DST\",\n  and_3 =\t\"00000024DST\",\n  or_3 =\t\"00000025DST\",\n  xor_3 =\t\"00000026DST\",\n  not_2 =\t\"00000027DS\",\n  nor_3 =\t\"00000027DST\",\n  slt_3 =\t\"0000002aDST\",\n  sltu_3 =\t\"0000002bDST\",\n  tge_2 =\t\"00000030ST\",\n  tge_3 =\t\"00000030STZ\",\n  tgeu_2 =\t\"00000031ST\",\n  tgeu_3 =\t\"00000031STZ\",\n  tlt_2 =\t\"00000032ST\",\n  tlt_3 =\t\"00000032STZ\",\n  tltu_2 =\t\"00000033ST\",\n  tltu_3 =\t\"00000033STZ\",\n  teq_2 =\t\"00000034ST\",\n  teq_3 =\t\"00000034STZ\",\n  tne_2 =\t\"00000036ST\",\n  tne_3 =\t\"00000036STZ\",\n\n  -- Opcode REGIMM.\n  bltz_2 =\t\"04000000SB\",\n  bgez_2 =\t\"04010000SB\",\n  bltzl_2 =\t\"04020000SB\",\n  bgezl_2 =\t\"04030000SB\",\n  tgei_2 =\t\"04080000SI\",\n  tgeiu_2 =\t\"04090000SI\",\n  tlti_2 =\t\"040a0000SI\",\n  tltiu_2 =\t\"040b0000SI\",\n  teqi_2 =\t\"040c0000SI\",\n  tnei_2 =\t\"040e0000SI\",\n  bltzal_2 =\t\"04100000SB\",\n  bal_1 =\t\"04110000B\",\n  bgezal_2 =\t\"04110000SB\",\n  bltzall_2 =\t\"04120000SB\",\n  bgezall_2 =\t\"04130000SB\",\n  synci_1 =\t\"041f0000O\",\n\n  -- Opcode SPECIAL2.\n  madd_2 =\t\"70000000ST\",\n  maddu_2 =\t\"70000001ST\",\n  mul_3 =\t\"70000002DST\",\n  msub_2 =\t\"70000004ST\",\n  msubu_2 =\t\"70000005ST\",\n  clz_2 =\t\"70000020DS=\",\n  clo_2 =\t\"70000021DS=\",\n  sdbbp_0 =\t\"7000003f\",\n  sdbbp_1 =\t\"7000003fY\",\n\n  -- Opcode SPECIAL3.\n  ext_4 =\t\"7c000000TSAM\", -- Note: last arg is msbd = size-1\n  ins_4 =\t\"7c000004TSAM\", -- Note: last arg is msb = pos+size-1\n  wsbh_2 =\t\"7c0000a0DT\",\n  seb_2 =\t\"7c000420DT\",\n  seh_2 =\t\"7c000620DT\",\n  rdhwr_2 =\t\"7c00003bTD\",\n\n  -- Opcode COP0.\n  mfc0_2 =\t\"40000000TD\",\n  mfc0_3 =\t\"40000000TDW\",\n  mtc0_2 =\t\"40800000TD\",\n  mtc0_3 =\t\"40800000TDW\",\n  rdpgpr_2 =\t\"41400000DT\",\n  di_0 =\t\"41606000\",\n  di_1 =\t\"41606000T\",\n  ei_0 =\t\"41606020\",\n  ei_1 =\t\"41606020T\",\n  wrpgpr_2 =\t\"41c00000DT\",\n  tlbr_0 =\t\"42000001\",\n  tlbwi_0 =\t\"42000002\",\n  tlbwr_0 =\t\"42000006\",\n  tlbp_0 =\t\"42000008\",\n  eret_0 =\t\"42000018\",\n  deret_0 =\t\"4200001f\",\n  wait_0 =\t\"42000020\",\n\n  -- Opcode COP1.\n  mfc1_2 =\t\"44000000TG\",\n  cfc1_2 =\t\"44400000TG\",\n  mfhc1_2 =\t\"44600000TG\",\n  mtc1_2 =\t\"44800000TG\",\n  ctc1_2 =\t\"44c00000TG\",\n  mthc1_2 =\t\"44e00000TG\",\n\n  bc1f_1 =\t\"45000000B\",\n  bc1f_2 =\t\"45000000CB\",\n  bc1t_1 =\t\"45010000B\",\n  bc1t_2 =\t\"45010000CB\",\n  bc1fl_1 =\t\"45020000B\",\n  bc1fl_2 =\t\"45020000CB\",\n  bc1tl_1 =\t\"45030000B\",\n  bc1tl_2 =\t\"45030000CB\",\n\n  [\"add.s_3\"] =\t\t\"46000000FGH\",\n  [\"sub.s_3\"] =\t\t\"46000001FGH\",\n  [\"mul.s_3\"] =\t\t\"46000002FGH\",\n  [\"div.s_3\"] =\t\t\"46000003FGH\",\n  [\"sqrt.s_2\"] =\t\"46000004FG\",\n  [\"abs.s_2\"] =\t\t\"46000005FG\",\n  [\"mov.s_2\"] =\t\t\"46000006FG\",\n  [\"neg.s_2\"] =\t\t\"46000007FG\",\n  [\"round.l.s_2\"] =\t\"46000008FG\",\n  [\"trunc.l.s_2\"] =\t\"46000009FG\",\n  [\"ceil.l.s_2\"] =\t\"4600000aFG\",\n  [\"floor.l.s_2\"] =\t\"4600000bFG\",\n  [\"round.w.s_2\"] =\t\"4600000cFG\",\n  [\"trunc.w.s_2\"] =\t\"4600000dFG\",\n  [\"ceil.w.s_2\"] =\t\"4600000eFG\",\n  [\"floor.w.s_2\"] =\t\"4600000fFG\",\n  [\"movf.s_2\"] =\t\"46000011FG\",\n  [\"movf.s_3\"] =\t\"46000011FGC\",\n  [\"movt.s_2\"] =\t\"46010011FG\",\n  [\"movt.s_3\"] =\t\"46010011FGC\",\n  [\"movz.s_3\"] =\t\"46000012FGT\",\n  [\"movn.s_3\"] =\t\"46000013FGT\",\n  [\"recip.s_2\"] =\t\"46000015FG\",\n  [\"rsqrt.s_2\"] =\t\"46000016FG\",\n  [\"cvt.d.s_2\"] =\t\"46000021FG\",\n  [\"cvt.w.s_2\"] =\t\"46000024FG\",\n  [\"cvt.l.s_2\"] =\t\"46000025FG\",\n  [\"cvt.ps.s_3\"] =\t\"46000026FGH\",\n  [\"c.f.s_2\"] =\t\t\"46000030GH\",\n  [\"c.f.s_3\"] =\t\t\"46000030VGH\",\n  [\"c.un.s_2\"] =\t\"46000031GH\",\n  [\"c.un.s_3\"] =\t\"46000031VGH\",\n  [\"c.eq.s_2\"] =\t\"46000032GH\",\n  [\"c.eq.s_3\"] =\t\"46000032VGH\",\n  [\"c.ueq.s_2\"] =\t\"46000033GH\",\n  [\"c.ueq.s_3\"] =\t\"46000033VGH\",\n  [\"c.olt.s_2\"] =\t\"46000034GH\",\n  [\"c.olt.s_3\"] =\t\"46000034VGH\",\n  [\"c.ult.s_2\"] =\t\"46000035GH\",\n  [\"c.ult.s_3\"] =\t\"46000035VGH\",\n  [\"c.ole.s_2\"] =\t\"46000036GH\",\n  [\"c.ole.s_3\"] =\t\"46000036VGH\",\n  [\"c.ule.s_2\"] =\t\"46000037GH\",\n  [\"c.ule.s_3\"] =\t\"46000037VGH\",\n  [\"c.sf.s_2\"] =\t\"46000038GH\",\n  [\"c.sf.s_3\"] =\t\"46000038VGH\",\n  [\"c.ngle.s_2\"] =\t\"46000039GH\",\n  [\"c.ngle.s_3\"] =\t\"46000039VGH\",\n  [\"c.seq.s_2\"] =\t\"4600003aGH\",\n  [\"c.seq.s_3\"] =\t\"4600003aVGH\",\n  [\"c.ngl.s_2\"] =\t\"4600003bGH\",\n  [\"c.ngl.s_3\"] =\t\"4600003bVGH\",\n  [\"c.lt.s_2\"] =\t\"4600003cGH\",\n  [\"c.lt.s_3\"] =\t\"4600003cVGH\",\n  [\"c.nge.s_2\"] =\t\"4600003dGH\",\n  [\"c.nge.s_3\"] =\t\"4600003dVGH\",\n  [\"c.le.s_2\"] =\t\"4600003eGH\",\n  [\"c.le.s_3\"] =\t\"4600003eVGH\",\n  [\"c.ngt.s_2\"] =\t\"4600003fGH\",\n  [\"c.ngt.s_3\"] =\t\"4600003fVGH\",\n\n  [\"add.d_3\"] =\t\t\"46200000FGH\",\n  [\"sub.d_3\"] =\t\t\"46200001FGH\",\n  [\"mul.d_3\"] =\t\t\"46200002FGH\",\n  [\"div.d_3\"] =\t\t\"46200003FGH\",\n  [\"sqrt.d_2\"] =\t\"46200004FG\",\n  [\"abs.d_2\"] =\t\t\"46200005FG\",\n  [\"mov.d_2\"] =\t\t\"46200006FG\",\n  [\"neg.d_2\"] =\t\t\"46200007FG\",\n  [\"round.l.d_2\"] =\t\"46200008FG\",\n  [\"trunc.l.d_2\"] =\t\"46200009FG\",\n  [\"ceil.l.d_2\"] =\t\"4620000aFG\",\n  [\"floor.l.d_2\"] =\t\"4620000bFG\",\n  [\"round.w.d_2\"] =\t\"4620000cFG\",\n  [\"trunc.w.d_2\"] =\t\"4620000dFG\",\n  [\"ceil.w.d_2\"] =\t\"4620000eFG\",\n  [\"floor.w.d_2\"] =\t\"4620000fFG\",\n  [\"movf.d_2\"] =\t\"46200011FG\",\n  [\"movf.d_3\"] =\t\"46200011FGC\",\n  [\"movt.d_2\"] =\t\"46210011FG\",\n  [\"movt.d_3\"] =\t\"46210011FGC\",\n  [\"movz.d_3\"] =\t\"46200012FGT\",\n  [\"movn.d_3\"] =\t\"46200013FGT\",\n  [\"recip.d_2\"] =\t\"46200015FG\",\n  [\"rsqrt.d_2\"] =\t\"46200016FG\",\n  [\"cvt.s.d_2\"] =\t\"46200020FG\",\n  [\"cvt.w.d_2\"] =\t\"46200024FG\",\n  [\"cvt.l.d_2\"] =\t\"46200025FG\",\n  [\"c.f.d_2\"] =\t\t\"46200030GH\",\n  [\"c.f.d_3\"] =\t\t\"46200030VGH\",\n  [\"c.un.d_2\"] =\t\"46200031GH\",\n  [\"c.un.d_3\"] =\t\"46200031VGH\",\n  [\"c.eq.d_2\"] =\t\"46200032GH\",\n  [\"c.eq.d_3\"] =\t\"46200032VGH\",\n  [\"c.ueq.d_2\"] =\t\"46200033GH\",\n  [\"c.ueq.d_3\"] =\t\"46200033VGH\",\n  [\"c.olt.d_2\"] =\t\"46200034GH\",\n  [\"c.olt.d_3\"] =\t\"46200034VGH\",\n  [\"c.ult.d_2\"] =\t\"46200035GH\",\n  [\"c.ult.d_3\"] =\t\"46200035VGH\",\n  [\"c.ole.d_2\"] =\t\"46200036GH\",\n  [\"c.ole.d_3\"] =\t\"46200036VGH\",\n  [\"c.ule.d_2\"] =\t\"46200037GH\",\n  [\"c.ule.d_3\"] =\t\"46200037VGH\",\n  [\"c.sf.d_2\"] =\t\"46200038GH\",\n  [\"c.sf.d_3\"] =\t\"46200038VGH\",\n  [\"c.ngle.d_2\"] =\t\"46200039GH\",\n  [\"c.ngle.d_3\"] =\t\"46200039VGH\",\n  [\"c.seq.d_2\"] =\t\"4620003aGH\",\n  [\"c.seq.d_3\"] =\t\"4620003aVGH\",\n  [\"c.ngl.d_2\"] =\t\"4620003bGH\",\n  [\"c.ngl.d_3\"] =\t\"4620003bVGH\",\n  [\"c.lt.d_2\"] =\t\"4620003cGH\",\n  [\"c.lt.d_3\"] =\t\"4620003cVGH\",\n  [\"c.nge.d_2\"] =\t\"4620003dGH\",\n  [\"c.nge.d_3\"] =\t\"4620003dVGH\",\n  [\"c.le.d_2\"] =\t\"4620003eGH\",\n  [\"c.le.d_3\"] =\t\"4620003eVGH\",\n  [\"c.ngt.d_2\"] =\t\"4620003fGH\",\n  [\"c.ngt.d_3\"] =\t\"4620003fVGH\",\n\n  [\"add.ps_3\"] =\t\"46c00000FGH\",\n  [\"sub.ps_3\"] =\t\"46c00001FGH\",\n  [\"mul.ps_3\"] =\t\"46c00002FGH\",\n  [\"abs.ps_2\"] =\t\"46c00005FG\",\n  [\"mov.ps_2\"] =\t\"46c00006FG\",\n  [\"neg.ps_2\"] =\t\"46c00007FG\",\n  [\"movf.ps_2\"] =\t\"46c00011FG\",\n  [\"movf.ps_3\"] =\t\"46c00011FGC\",\n  [\"movt.ps_2\"] =\t\"46c10011FG\",\n  [\"movt.ps_3\"] =\t\"46c10011FGC\",\n  [\"movz.ps_3\"] =\t\"46c00012FGT\",\n  [\"movn.ps_3\"] =\t\"46c00013FGT\",\n  [\"cvt.s.pu_2\"] =\t\"46c00020FG\",\n  [\"cvt.s.pl_2\"] =\t\"46c00028FG\",\n  [\"pll.ps_3\"] =\t\"46c0002cFGH\",\n  [\"plu.ps_3\"] =\t\"46c0002dFGH\",\n  [\"pul.ps_3\"] =\t\"46c0002eFGH\",\n  [\"puu.ps_3\"] =\t\"46c0002fFGH\",\n  [\"c.f.ps_2\"] =\t\"46c00030GH\",\n  [\"c.f.ps_3\"] =\t\"46c00030VGH\",\n  [\"c.un.ps_2\"] =\t\"46c00031GH\",\n  [\"c.un.ps_3\"] =\t\"46c00031VGH\",\n  [\"c.eq.ps_2\"] =\t\"46c00032GH\",\n  [\"c.eq.ps_3\"] =\t\"46c00032VGH\",\n  [\"c.ueq.ps_2\"] =\t\"46c00033GH\",\n  [\"c.ueq.ps_3\"] =\t\"46c00033VGH\",\n  [\"c.olt.ps_2\"] =\t\"46c00034GH\",\n  [\"c.olt.ps_3\"] =\t\"46c00034VGH\",\n  [\"c.ult.ps_2\"] =\t\"46c00035GH\",\n  [\"c.ult.ps_3\"] =\t\"46c00035VGH\",\n  [\"c.ole.ps_2\"] =\t\"46c00036GH\",\n  [\"c.ole.ps_3\"] =\t\"46c00036VGH\",\n  [\"c.ule.ps_2\"] =\t\"46c00037GH\",\n  [\"c.ule.ps_3\"] =\t\"46c00037VGH\",\n  [\"c.sf.ps_2\"] =\t\"46c00038GH\",\n  [\"c.sf.ps_3\"] =\t\"46c00038VGH\",\n  [\"c.ngle.ps_2\"] =\t\"46c00039GH\",\n  [\"c.ngle.ps_3\"] =\t\"46c00039VGH\",\n  [\"c.seq.ps_2\"] =\t\"46c0003aGH\",\n  [\"c.seq.ps_3\"] =\t\"46c0003aVGH\",\n  [\"c.ngl.ps_2\"] =\t\"46c0003bGH\",\n  [\"c.ngl.ps_3\"] =\t\"46c0003bVGH\",\n  [\"c.lt.ps_2\"] =\t\"46c0003cGH\",\n  [\"c.lt.ps_3\"] =\t\"46c0003cVGH\",\n  [\"c.nge.ps_2\"] =\t\"46c0003dGH\",\n  [\"c.nge.ps_3\"] =\t\"46c0003dVGH\",\n  [\"c.le.ps_2\"] =\t\"46c0003eGH\",\n  [\"c.le.ps_3\"] =\t\"46c0003eVGH\",\n  [\"c.ngt.ps_2\"] =\t\"46c0003fGH\",\n  [\"c.ngt.ps_3\"] =\t\"46c0003fVGH\",\n\n  [\"cvt.s.w_2\"] =\t\"46800020FG\",\n  [\"cvt.d.w_2\"] =\t\"46800021FG\",\n\n  [\"cvt.s.l_2\"] =\t\"46a00020FG\",\n  [\"cvt.d.l_2\"] =\t\"46a00021FG\",\n\n  -- Opcode COP1X.\n  lwxc1_2 =\t\t\"4c000000FX\",\n  ldxc1_2 =\t\t\"4c000001FX\",\n  luxc1_2 =\t\t\"4c000005FX\",\n  swxc1_2 =\t\t\"4c000008FX\",\n  sdxc1_2 =\t\t\"4c000009FX\",\n  suxc1_2 =\t\t\"4c00000dFX\",\n  prefx_2 =\t\t\"4c00000fMX\",\n  [\"alnv.ps_4\"] =\t\"4c00001eFGHS\",\n  [\"madd.s_4\"] =\t\"4c000020FRGH\",\n  [\"madd.d_4\"] =\t\"4c000021FRGH\",\n  [\"madd.ps_4\"] =\t\"4c000026FRGH\",\n  [\"msub.s_4\"] =\t\"4c000028FRGH\",\n  [\"msub.d_4\"] =\t\"4c000029FRGH\",\n  [\"msub.ps_4\"] =\t\"4c00002eFRGH\",\n  [\"nmadd.s_4\"] =\t\"4c000030FRGH\",\n  [\"nmadd.d_4\"] =\t\"4c000031FRGH\",\n  [\"nmadd.ps_4\"] =\t\"4c000036FRGH\",\n  [\"nmsub.s_4\"] =\t\"4c000038FRGH\",\n  [\"nmsub.d_4\"] =\t\"4c000039FRGH\",\n  [\"nmsub.ps_4\"] =\t\"4c00003eFRGH\",\n}\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r[1-3]?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_fpr(expr)\n  local r = match(expr, \"^f([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  local n = tonumber(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^[rf]([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):([rf][1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_disp(disp)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = shl(parse_gpr(reg), 21)\n    local extname = match(imm, \"^extern%s+(%S+)$\")\n    if extname then\n      waction(\"REL_EXT\", map_extern[extname], nil, 1)\n      return r\n    else\n      return r + parse_imm(imm, 16, 0, 0, true)\n    end\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if tp then\n      waction(\"IMM\", 32768+16*32, format(tp.ctypefmt, tailr))\n      return shl(r, 21)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_index(idx)\n  local rt, rs = match(idx, \"^(.*)%(([%w_:]+)%)$\")\n  if rt then\n    rt = parse_gpr(rt)\n    rs = parse_gpr(rs)\n    return shl(rt, 16) + shl(rs, 21)\n  end\n  werror(\"bad index `\"..idx..\"'\")\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return sub(template, 9) end\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n = 1\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 2 positions (ins/ext).\n  if secpos+2 > maxsecpos then wflush() end\n  local pos = wpos()\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    if p == \"D\" then\n      op = op + shl(parse_gpr(params[n]), 11); n = n + 1\n    elseif p == \"T\" then\n      op = op + shl(parse_gpr(params[n]), 16); n = n + 1\n    elseif p == \"S\" then\n      op = op + shl(parse_gpr(params[n]), 21); n = n + 1\n    elseif p == \"F\" then\n      op = op + shl(parse_fpr(params[n]), 6); n = n + 1\n    elseif p == \"G\" then\n      op = op + shl(parse_fpr(params[n]), 11); n = n + 1\n    elseif p == \"H\" then\n      op = op + shl(parse_fpr(params[n]), 16); n = n + 1\n    elseif p == \"R\" then\n      op = op + shl(parse_fpr(params[n]), 21); n = n + 1\n    elseif p == \"I\" then\n      op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1\n    elseif p == \"U\" then\n      op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1\n    elseif p == \"O\" then\n      op = op + parse_disp(params[n]); n = n + 1\n    elseif p == \"X\" then\n      op = op + parse_index(params[n]); n = n + 1\n    elseif p == \"B\" or p == \"J\" then\n      local mode, n, s = parse_label(params[n], false)\n      if p == \"B\" then n = n + 2048 end\n      waction(\"REL_\"..mode, n, s, 1)\n      n = n + 1\n    elseif p == \"A\" then\n      op = op + parse_imm(params[n], 5, 6, 0, false); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_imm(params[n], 5, 11, 0, false); n = n + 1\n    elseif p == \"N\" then\n      op = op + parse_imm(params[n], 5, 16, 0, false); n = n + 1\n    elseif p == \"C\" then\n      op = op + parse_imm(params[n], 3, 18, 0, false); n = n + 1\n    elseif p == \"V\" then\n      op = op + parse_imm(params[n], 3, 8, 0, false); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm(params[n], 3, 0, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      op = op + parse_imm(params[n], 20, 6, 0, false); n = n + 1\n    elseif p == \"Z\" then\n      op = op + parse_imm(params[n], 10, 6, 0, false); n = n + 1\n    elseif p == \"=\" then\n      op = op + shl(band(op, 0xf800), 5) -- Copy D to T for clz, clo.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_ppc.h",
    "content": "/*\n** DynASM PPC/PPC64 encoding engine.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"ppc\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC, DASM_IMM, DASM_IMMSH,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n#endif\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif (ins & 0x8000)\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMMSH:\n\tCK((n >> 6) == 0, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMMSH: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  CK(n >= 0, UNDEF_LG);\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);\n\tpatchrel:\n\t  CK((n & 3) == 0 &&\n\t      (((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>\n\t       ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);\n\t  cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMMSH:\n\t  cp[-1] |= (ins & 1) ? ((n&31)<<11)|((n&32)>>4) : ((n&31)<<6)|(n&32);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_ppc.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM PPC/PPC64 module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n--\n-- Support for various extensions contributed by Caio Souza Oliveira.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"ppc\",\n  description =\t\"DynASM PPC module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable = assert, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch = _s.match, _s.gmatch\nlocal concat, sort = table.concat, table.sort\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal tohex = bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMMSH\"\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0xffffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = { sp = \"r1\" } -- Ext. register name -> int. name.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  if s == \"r1\" then return \"sp\" end\n  return s\nend\n\nlocal map_cond = {\n  lt = 0, gt = 1, eq = 2, so = 3,\n  ge = 4, le = 5, ne = 6, ns = 7,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_op, op_template\n\nlocal function op_alias(opname, f)\n  return function(params, nparams)\n    if not params then return \"-> \"..opname:sub(1, -3) end\n    f(params, nparams)\n    op_template(params, map_op[opname], nparams)\n  end\nend\n\n-- Template strings for PPC instructions.\nmap_op = {\n  tdi_3 =\t\"08000000ARI\",\n  twi_3 =\t\"0c000000ARI\",\n  mulli_3 =\t\"1c000000RRI\",\n  subfic_3 =\t\"20000000RRI\",\n  cmplwi_3 =\t\"28000000XRU\",\n  cmplwi_2 =\t\"28000000-RU\",\n  cmpldi_3 =\t\"28200000XRU\",\n  cmpldi_2 =\t\"28200000-RU\",\n  cmpwi_3 =\t\"2c000000XRI\",\n  cmpwi_2 =\t\"2c000000-RI\",\n  cmpdi_3 =\t\"2c200000XRI\",\n  cmpdi_2 =\t\"2c200000-RI\",\n  addic_3 =\t\"30000000RRI\",\n  [\"addic._3\"] = \"34000000RRI\",\n  addi_3 =\t\"38000000RR0I\",\n  li_2 =\t\"38000000RI\",\n  la_2 =\t\"38000000RD\",\n  addis_3 =\t\"3c000000RR0I\",\n  lis_2 =\t\"3c000000RI\",\n  lus_2 =\t\"3c000000RU\",\n  bc_3 =\t\"40000000AAK\",\n  bcl_3 =\t\"40000001AAK\",\n  bdnz_1 =\t\"42000000K\",\n  bdz_1 =\t\"42400000K\",\n  sc_0 =\t\"44000000\",\n  b_1 =\t\t\"48000000J\",\n  bl_1 =\t\"48000001J\",\n  rlwimi_5 =\t\"50000000RR~AAA.\",\n  rlwinm_5 =\t\"54000000RR~AAA.\",\n  rlwnm_5 =\t\"5c000000RR~RAA.\",\n  ori_3 =\t\"60000000RR~U\",\n  nop_0 =\t\"60000000\",\n  oris_3 =\t\"64000000RR~U\",\n  xori_3 =\t\"68000000RR~U\",\n  xoris_3 =\t\"6c000000RR~U\",\n  [\"andi._3\"] =\t\"70000000RR~U\",\n  [\"andis._3\"] = \"74000000RR~U\",\n  lwz_2 =\t\"80000000RD\",\n  lwzu_2 =\t\"84000000RD\",\n  lbz_2 =\t\"88000000RD\",\n  lbzu_2 =\t\"8c000000RD\",\n  stw_2 =\t\"90000000RD\",\n  stwu_2 =\t\"94000000RD\",\n  stb_2 =\t\"98000000RD\",\n  stbu_2 =\t\"9c000000RD\",\n  lhz_2 =\t\"a0000000RD\",\n  lhzu_2 =\t\"a4000000RD\",\n  lha_2 =\t\"a8000000RD\",\n  lhau_2 =\t\"ac000000RD\",\n  sth_2 =\t\"b0000000RD\",\n  sthu_2 =\t\"b4000000RD\",\n  lmw_2 =\t\"b8000000RD\",\n  stmw_2 =\t\"bc000000RD\",\n  lfs_2 =\t\"c0000000FD\",\n  lfsu_2 =\t\"c4000000FD\",\n  lfd_2 =\t\"c8000000FD\",\n  lfdu_2 =\t\"cc000000FD\",\n  stfs_2 =\t\"d0000000FD\",\n  stfsu_2 =\t\"d4000000FD\",\n  stfd_2 =\t\"d8000000FD\",\n  stfdu_2 =\t\"dc000000FD\",\n  ld_2 =\t\"e8000000RD\", -- NYI: displacement must be divisible by 4.\n  ldu_2 =\t\"e8000001RD\",\n  lwa_2 =\t\"e8000002RD\",\n  std_2 =\t\"f8000000RD\",\n  stdu_2 =\t\"f8000001RD\",\n\n  subi_3 =\top_alias(\"addi_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  subis_3 =\top_alias(\"addis_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  subic_3 =\top_alias(\"addic_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  [\"subic._3\"] = op_alias(\"addic._3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n\n  rotlwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = \"0\"; p[5] = \"31\"\n  end),\n  rotrwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[3] = \"32-(\"..p[3]..\")\"; p[4] = \"0\"; p[5] = \"31\"\n  end),\n  rotlw_3 =\top_alias(\"rlwnm_5\", function(p)\n    p[4] = \"0\"; p[5] = \"31\"\n  end),\n  slwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[5] = \"31-(\"..p[3]..\")\"; p[4] = \"0\"\n  end),\n  srwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = p[3]; p[3] = \"32-(\"..p[3]..\")\"; p[5] = \"31\"\n  end),\n  clrlwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = p[3]; p[3] = \"0\"; p[5] = \"31\"\n  end),\n  clrrwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[5] = \"31-(\"..p[3]..\")\"; p[3] = \"0\"; p[4] = \"0\"\n  end),\n\n  -- Primary opcode 4:\n  mulhhwu_3 =\t\t\"10000010RRR.\",\n  machhwu_3 =\t\t\"10000018RRR.\",\n  mulhhw_3 =\t\t\"10000050RRR.\",\n  nmachhw_3 =\t\t\"1000005cRRR.\",\n  machhwsu_3 =\t\t\"10000098RRR.\",\n  machhws_3 =\t\t\"100000d8RRR.\",\n  nmachhws_3 =\t\t\"100000dcRRR.\",\n  mulchwu_3 =\t\t\"10000110RRR.\",\n  macchwu_3 =\t\t\"10000118RRR.\",\n  mulchw_3 =\t\t\"10000150RRR.\",\n  macchw_3 =\t\t\"10000158RRR.\",\n  nmacchw_3 =\t\t\"1000015cRRR.\",\n  macchwsu_3 =\t\t\"10000198RRR.\",\n  macchws_3 =\t\t\"100001d8RRR.\",\n  nmacchws_3 =\t\t\"100001dcRRR.\",\n  mullhw_3 =\t\t\"10000350RRR.\",\n  maclhw_3 =\t\t\"10000358RRR.\",\n  nmaclhw_3 =\t\t\"1000035cRRR.\",\n  maclhwsu_3 =\t\t\"10000398RRR.\",\n  maclhws_3 =\t\t\"100003d8RRR.\",\n  nmaclhws_3 =\t\t\"100003dcRRR.\",\n  machhwuo_3 =\t\t\"10000418RRR.\",\n  nmachhwo_3 =\t\t\"1000045cRRR.\",\n  machhwsuo_3 =\t\t\"10000498RRR.\",\n  machhwso_3 =\t\t\"100004d8RRR.\",\n  nmachhwso_3 =\t\t\"100004dcRRR.\",\n  macchwuo_3 =\t\t\"10000518RRR.\",\n  macchwo_3 =\t\t\"10000558RRR.\",\n  nmacchwo_3 =\t\t\"1000055cRRR.\",\n  macchwsuo_3 =\t\t\"10000598RRR.\",\n  macchwso_3 =\t\t\"100005d8RRR.\",\n  nmacchwso_3 =\t\t\"100005dcRRR.\",\n  maclhwo_3 =\t\t\"10000758RRR.\",\n  nmaclhwo_3 =\t\t\"1000075cRRR.\",\n  maclhwsuo_3 =\t\t\"10000798RRR.\",\n  maclhwso_3 =\t\t\"100007d8RRR.\",\n  nmaclhwso_3 =\t\t\"100007dcRRR.\",\n\n  vaddubm_3 =\t\t\"10000000VVV\",\n  vmaxub_3 =\t\t\"10000002VVV\",\n  vrlb_3 =\t\t\"10000004VVV\",\n  vcmpequb_3 =\t\t\"10000006VVV\",\n  vmuloub_3 =\t\t\"10000008VVV\",\n  vaddfp_3 =\t\t\"1000000aVVV\",\n  vmrghb_3 =\t\t\"1000000cVVV\",\n  vpkuhum_3 =\t\t\"1000000eVVV\",\n  vmhaddshs_4 =\t\t\"10000020VVVV\",\n  vmhraddshs_4 =\t\"10000021VVVV\",\n  vmladduhm_4 =\t\t\"10000022VVVV\",\n  vmsumubm_4 =\t\t\"10000024VVVV\",\n  vmsummbm_4 =\t\t\"10000025VVVV\",\n  vmsumuhm_4 =\t\t\"10000026VVVV\",\n  vmsumuhs_4 =\t\t\"10000027VVVV\",\n  vmsumshm_4 =\t\t\"10000028VVVV\",\n  vmsumshs_4 =\t\t\"10000029VVVV\",\n  vsel_4 =\t\t\"1000002aVVVV\",\n  vperm_4 =\t\t\"1000002bVVVV\",\n  vsldoi_4 =\t\t\"1000002cVVVP\",\n  vpermxor_4 =\t\t\"1000002dVVVV\",\n  vmaddfp_4 =\t\t\"1000002eVVVV~\",\n  vnmsubfp_4 =\t\t\"1000002fVVVV~\",\n  vaddeuqm_4 =\t\t\"1000003cVVVV\",\n  vaddecuq_4 =\t\t\"1000003dVVVV\",\n  vsubeuqm_4 =\t\t\"1000003eVVVV\",\n  vsubecuq_4 =\t\t\"1000003fVVVV\",\n  vadduhm_3 =\t\t\"10000040VVV\",\n  vmaxuh_3 =\t\t\"10000042VVV\",\n  vrlh_3 =\t\t\"10000044VVV\",\n  vcmpequh_3 =\t\t\"10000046VVV\",\n  vmulouh_3 =\t\t\"10000048VVV\",\n  vsubfp_3 =\t\t\"1000004aVVV\",\n  vmrghh_3 =\t\t\"1000004cVVV\",\n  vpkuwum_3 =\t\t\"1000004eVVV\",\n  vadduwm_3 =\t\t\"10000080VVV\",\n  vmaxuw_3 =\t\t\"10000082VVV\",\n  vrlw_3 =\t\t\"10000084VVV\",\n  vcmpequw_3 =\t\t\"10000086VVV\",\n  vmulouw_3 =\t\t\"10000088VVV\",\n  vmuluwm_3 =\t\t\"10000089VVV\",\n  vmrghw_3 =\t\t\"1000008cVVV\",\n  vpkuhus_3 =\t\t\"1000008eVVV\",\n  vaddudm_3 =\t\t\"100000c0VVV\",\n  vmaxud_3 =\t\t\"100000c2VVV\",\n  vrld_3 =\t\t\"100000c4VVV\",\n  vcmpeqfp_3 =\t\t\"100000c6VVV\",\n  vcmpequd_3 =\t\t\"100000c7VVV\",\n  vpkuwus_3 =\t\t\"100000ceVVV\",\n  vadduqm_3 =\t\t\"10000100VVV\",\n  vmaxsb_3 =\t\t\"10000102VVV\",\n  vslb_3 =\t\t\"10000104VVV\",\n  vmulosb_3 =\t\t\"10000108VVV\",\n  vrefp_2 =\t\t\"1000010aV-V\",\n  vmrglb_3 =\t\t\"1000010cVVV\",\n  vpkshus_3 =\t\t\"1000010eVVV\",\n  vaddcuq_3 =\t\t\"10000140VVV\",\n  vmaxsh_3 =\t\t\"10000142VVV\",\n  vslh_3 =\t\t\"10000144VVV\",\n  vmulosh_3 =\t\t\"10000148VVV\",\n  vrsqrtefp_2 =\t\t\"1000014aV-V\",\n  vmrglh_3 =\t\t\"1000014cVVV\",\n  vpkswus_3 =\t\t\"1000014eVVV\",\n  vaddcuw_3 =\t\t\"10000180VVV\",\n  vmaxsw_3 =\t\t\"10000182VVV\",\n  vslw_3 =\t\t\"10000184VVV\",\n  vmulosw_3 =\t\t\"10000188VVV\",\n  vexptefp_2 =\t\t\"1000018aV-V\",\n  vmrglw_3 =\t\t\"1000018cVVV\",\n  vpkshss_3 =\t\t\"1000018eVVV\",\n  vmaxsd_3 =\t\t\"100001c2VVV\",\n  vsl_3 =\t\t\"100001c4VVV\",\n  vcmpgefp_3 =\t\t\"100001c6VVV\",\n  vlogefp_2 =\t\t\"100001caV-V\",\n  vpkswss_3 =\t\t\"100001ceVVV\",\n  vadduhs_3 =\t\t\"10000240VVV\",\n  vminuh_3 =\t\t\"10000242VVV\",\n  vsrh_3 =\t\t\"10000244VVV\",\n  vcmpgtuh_3 =\t\t\"10000246VVV\",\n  vmuleuh_3 =\t\t\"10000248VVV\",\n  vrfiz_2 =\t\t\"1000024aV-V\",\n  vsplth_3 =\t\t\"1000024cVV3\",\n  vupkhsh_2 =\t\t\"1000024eV-V\",\n  vminuw_3 =\t\t\"10000282VVV\",\n  vminud_3 =\t\t\"100002c2VVV\",\n  vcmpgtud_3 =\t\t\"100002c7VVV\",\n  vrfim_2 =\t\t\"100002caV-V\",\n  vcmpgtsb_3 =\t\t\"10000306VVV\",\n  vcfux_3 =\t\t\"1000030aVVA~\",\n  vaddshs_3 =\t\t\"10000340VVV\",\n  vminsh_3 =\t\t\"10000342VVV\",\n  vsrah_3 =\t\t\"10000344VVV\",\n  vcmpgtsh_3 =\t\t\"10000346VVV\",\n  vmulesh_3 =\t\t\"10000348VVV\",\n  vcfsx_3 =\t\t\"1000034aVVA~\",\n  vspltish_2 =\t\t\"1000034cVS\",\n  vupkhpx_2 =\t\t\"1000034eV-V\",\n  vaddsws_3 =\t\t\"10000380VVV\",\n  vminsw_3 =\t\t\"10000382VVV\",\n  vsraw_3 =\t\t\"10000384VVV\",\n  vcmpgtsw_3 =\t\t\"10000386VVV\",\n  vmulesw_3 =\t\t\"10000388VVV\",\n  vctuxs_3 =\t\t\"1000038aVVA~\",\n  vspltisw_2 =\t\t\"1000038cVS\",\n  vminsd_3 =\t\t\"100003c2VVV\",\n  vsrad_3 =\t\t\"100003c4VVV\",\n  vcmpbfp_3 =\t\t\"100003c6VVV\",\n  vcmpgtsd_3 =\t\t\"100003c7VVV\",\n  vctsxs_3 =\t\t\"100003caVVA~\",\n  vupklpx_2 =\t\t\"100003ceV-V\",\n  vsububm_3 =\t\t\"10000400VVV\",\n  [\"bcdadd._4\"] =\t\"10000401VVVy.\",\n  vavgub_3 =\t\t\"10000402VVV\",\n  vand_3 =\t\t\"10000404VVV\",\n  [\"vcmpequb._3\"] =\t\"10000406VVV\",\n  vmaxfp_3 =\t\t\"1000040aVVV\",\n  vsubuhm_3 =\t\t\"10000440VVV\",\n  [\"bcdsub._4\"] =\t\"10000441VVVy.\",\n  vavguh_3 =\t\t\"10000442VVV\",\n  vandc_3 =\t\t\"10000444VVV\",\n  [\"vcmpequh._3\"] =\t\"10000446VVV\",\n  vminfp_3 =\t\t\"1000044aVVV\",\n  vpkudum_3 =\t\t\"1000044eVVV\",\n  vsubuwm_3 =\t\t\"10000480VVV\",\n  vavguw_3 =\t\t\"10000482VVV\",\n  vor_3 =\t\t\"10000484VVV\",\n  [\"vcmpequw._3\"] =\t\"10000486VVV\",\n  vpmsumw_3 =\t\t\"10000488VVV\",\n  [\"vcmpeqfp._3\"] =\t\"100004c6VVV\",\n  [\"vcmpequd._3\"] =\t\"100004c7VVV\",\n  vpkudus_3 =\t\t\"100004ceVVV\",\n  vavgsb_3 =\t\t\"10000502VVV\",\n  vavgsh_3 =\t\t\"10000542VVV\",\n  vorc_3 =\t\t\"10000544VVV\",\n  vbpermq_3 =\t\t\"1000054cVVV\",\n  vpksdus_3 =\t\t\"1000054eVVV\",\n  vavgsw_3 =\t\t\"10000582VVV\",\n  vsld_3 =\t\t\"100005c4VVV\",\n  [\"vcmpgefp._3\"] =\t\"100005c6VVV\",\n  vpksdss_3 =\t\t\"100005ceVVV\",\n  vsububs_3 =\t\t\"10000600VVV\",\n  mfvscr_1 =\t\t\"10000604V--\",\n  vsum4ubs_3 =\t\t\"10000608VVV\",\n  vsubuhs_3 =\t\t\"10000640VVV\",\n  mtvscr_1 =\t\t\"10000644--V\",\n  [\"vcmpgtuh._3\"] =\t\"10000646VVV\",\n  vsum4shs_3 =\t\t\"10000648VVV\",\n  vupkhsw_2 =\t\t\"1000064eV-V\",\n  vsubuws_3 =\t\t\"10000680VVV\",\n  vshasigmaw_4 =\t\"10000682VVYp\",\n  veqv_3 =\t\t\"10000684VVV\",\n  vsum2sws_3 =\t\t\"10000688VVV\",\n  vmrgow_3 =\t\t\"1000068cVVV\",\n  vshasigmad_4 =\t\"100006c2VVYp\",\n  vsrd_3 =\t\t\"100006c4VVV\",\n  [\"vcmpgtud._3\"] =\t\"100006c7VVV\",\n  vupklsw_2 =\t\t\"100006ceV-V\",\n  vupkslw_2 =\t\t\"100006ceV-V\",\n  vsubsbs_3 =\t\t\"10000700VVV\",\n  vclzb_2 =\t\t\"10000702V-V\",\n  vpopcntb_2 =\t\t\"10000703V-V\",\n  [\"vcmpgtsb._3\"] =\t\"10000706VVV\",\n  vsum4sbs_3 =\t\t\"10000708VVV\",\n  vsubshs_3 =\t\t\"10000740VVV\",\n  vclzh_2 =\t\t\"10000742V-V\",\n  vpopcnth_2 =\t\t\"10000743V-V\",\n  [\"vcmpgtsh._3\"] =\t\"10000746VVV\",\n  vsubsws_3 =\t\t\"10000780VVV\",\n  vclzw_2 =\t\t\"10000782V-V\",\n  vpopcntw_2 =\t\t\"10000783V-V\",\n  [\"vcmpgtsw._3\"] =\t\"10000786VVV\",\n  vsumsws_3 =\t\t\"10000788VVV\",\n  vmrgew_3 =\t\t\"1000078cVVV\",\n  vclzd_2 =\t\t\"100007c2V-V\",\n  vpopcntd_2 =\t\t\"100007c3V-V\",\n  [\"vcmpbfp._3\"] =\t\"100007c6VVV\",\n  [\"vcmpgtsd._3\"] =\t\"100007c7VVV\",\n\n  -- Primary opcode 19:\n  mcrf_2 =\t\"4c000000XX\",\n  isync_0 =\t\"4c00012c\",\n  crnor_3 =\t\"4c000042CCC\",\n  crnot_2 =\t\"4c000042CC=\",\n  crandc_3 =\t\"4c000102CCC\",\n  crxor_3 =\t\"4c000182CCC\",\n  crclr_1 =\t\"4c000182C==\",\n  crnand_3 =\t\"4c0001c2CCC\",\n  crand_3 =\t\"4c000202CCC\",\n  creqv_3 =\t\"4c000242CCC\",\n  crset_1 =\t\"4c000242C==\",\n  crorc_3 =\t\"4c000342CCC\",\n  cror_3 =\t\"4c000382CCC\",\n  crmove_2 =\t\"4c000382CC=\",\n  bclr_2 =\t\"4c000020AA\",\n  bclrl_2 =\t\"4c000021AA\",\n  bcctr_2 =\t\"4c000420AA\",\n  bcctrl_2 =\t\"4c000421AA\",\n  bctar_2 =\t\"4c000460AA\",\n  bctarl_2 =\t\"4c000461AA\",\n  blr_0 =\t\"4e800020\",\n  blrl_0 =\t\"4e800021\",\n  bctr_0 =\t\"4e800420\",\n  bctrl_0 =\t\"4e800421\",\n\n  -- Primary opcode 31:\n  cmpw_3 =\t\"7c000000XRR\",\n  cmpw_2 =\t\"7c000000-RR\",\n  cmpd_3 =\t\"7c200000XRR\",\n  cmpd_2 =\t\"7c200000-RR\",\n  tw_3 =\t\"7c000008ARR\",\n  lvsl_3 =\t\"7c00000cVRR\",\n  subfc_3 =\t\"7c000010RRR.\",\n  subc_3 =\t\"7c000010RRR~.\",\n  mulhdu_3 =\t\"7c000012RRR.\",\n  addc_3 =\t\"7c000014RRR.\",\n  mulhwu_3 =\t\"7c000016RRR.\",\n  isel_4 =\t\"7c00001eRRRC\",\n  isellt_3 =\t\"7c00001eRRR\",\n  iselgt_3 =\t\"7c00005eRRR\",\n  iseleq_3 =\t\"7c00009eRRR\",\n  mfcr_1 =\t\"7c000026R\",\n  mfocrf_2 =\t\"7c100026RG\",\n  mtcrf_2 =\t\"7c000120GR\",\n  mtocrf_2 =\t\"7c100120GR\",\n  lwarx_3 =\t\"7c000028RR0R\",\n  ldx_3 =\t\"7c00002aRR0R\",\n  lwzx_3 =\t\"7c00002eRR0R\",\n  slw_3 =\t\"7c000030RR~R.\",\n  cntlzw_2 =\t\"7c000034RR~\",\n  sld_3 =\t\"7c000036RR~R.\",\n  and_3 =\t\"7c000038RR~R.\",\n  cmplw_3 =\t\"7c000040XRR\",\n  cmplw_2 =\t\"7c000040-RR\",\n  cmpld_3 =\t\"7c200040XRR\",\n  cmpld_2 =\t\"7c200040-RR\",\n  lvsr_3 =\t\"7c00004cVRR\",\n  subf_3 =\t\"7c000050RRR.\",\n  sub_3 =\t\"7c000050RRR~.\",\n  lbarx_3 =\t\"7c000068RR0R\",\n  ldux_3 =\t\"7c00006aRR0R\",\n  dcbst_2 =\t\"7c00006c-RR\",\n  lwzux_3 =\t\"7c00006eRR0R\",\n  cntlzd_2 =\t\"7c000074RR~\",\n  andc_3 =\t\"7c000078RR~R.\",\n  td_3 =\t\"7c000088ARR\",\n  lvewx_3 =\t\"7c00008eVRR\",\n  mulhd_3 =\t\"7c000092RRR.\",\n  addg6s_3 =\t\"7c000094RRR\",\n  mulhw_3 =\t\"7c000096RRR.\",\n  dlmzb_3 =\t\"7c00009cRR~R.\",\n  ldarx_3 =\t\"7c0000a8RR0R\",\n  dcbf_2 =\t\"7c0000ac-RR\",\n  lbzx_3 =\t\"7c0000aeRR0R\",\n  lvx_3 =\t\"7c0000ceVRR\",\n  neg_2 =\t\"7c0000d0RR.\",\n  lharx_3 =\t\"7c0000e8RR0R\",\n  lbzux_3 =\t\"7c0000eeRR0R\",\n  popcntb_2 =\t\"7c0000f4RR~\",\n  not_2 =\t\"7c0000f8RR~%.\",\n  nor_3 =\t\"7c0000f8RR~R.\",\n  stvebx_3 =\t\"7c00010eVRR\",\n  subfe_3 =\t\"7c000110RRR.\",\n  sube_3 =\t\"7c000110RRR~.\",\n  adde_3 =\t\"7c000114RRR.\",\n  stdx_3 =\t\"7c00012aRR0R\",\n  [\"stwcx._3\"] =\t\"7c00012dRR0R.\",\n  stwx_3 =\t\"7c00012eRR0R\",\n  prtyw_2 =\t\"7c000134RR~\",\n  stvehx_3 =\t\"7c00014eVRR\",\n  stdux_3 =\t\"7c00016aRR0R\",\n  [\"stqcx._3\"] =\t\"7c00016dR:R0R.\",\n  stwux_3 =\t\"7c00016eRR0R\",\n  prtyd_2 =\t\"7c000174RR~\",\n  stvewx_3 =\t\"7c00018eVRR\",\n  subfze_2 =\t\"7c000190RR.\",\n  addze_2 =\t\"7c000194RR.\",\n  [\"stdcx._3\"] =\t\"7c0001adRR0R.\",\n  stbx_3 =\t\"7c0001aeRR0R\",\n  stvx_3 =\t\"7c0001ceVRR\",\n  subfme_2 =\t\"7c0001d0RR.\",\n  mulld_3 =\t\"7c0001d2RRR.\",\n  addme_2 =\t\"7c0001d4RR.\",\n  mullw_3 =\t\"7c0001d6RRR.\",\n  dcbtst_2 =\t\"7c0001ec-RR\",\n  stbux_3 =\t\"7c0001eeRR0R\",\n  bpermd_3 =\t\"7c0001f8RR~R\",\n  lvepxl_3 =\t\"7c00020eVRR\",\n  add_3 =\t\"7c000214RRR.\",\n  lqarx_3 =\t\"7c000228R:R0R\",\n  dcbt_2 =\t\"7c00022c-RR\",\n  lhzx_3 =\t\"7c00022eRR0R\",\n  cdtbcd_2 =\t\"7c000234RR~\",\n  eqv_3 =\t\"7c000238RR~R.\",\n  lvepx_3 =\t\"7c00024eVRR\",\n  eciwx_3 =\t\"7c00026cRR0R\",\n  lhzux_3 =\t\"7c00026eRR0R\",\n  cbcdtd_2 =\t\"7c000274RR~\",\n  xor_3 =\t\"7c000278RR~R.\",\n  mfspefscr_1 =\t\"7c0082a6R\",\n  mfxer_1 =\t\"7c0102a6R\",\n  mflr_1 =\t\"7c0802a6R\",\n  mfctr_1 =\t\"7c0902a6R\",\n  lwax_3 =\t\"7c0002aaRR0R\",\n  lhax_3 =\t\"7c0002aeRR0R\",\n  mftb_1 =\t\"7c0c42e6R\",\n  mftbu_1 =\t\"7c0d42e6R\",\n  lvxl_3 =\t\"7c0002ceVRR\",\n  lwaux_3 =\t\"7c0002eaRR0R\",\n  lhaux_3 =\t\"7c0002eeRR0R\",\n  popcntw_2 =\t\"7c0002f4RR~\",\n  divdeu_3 =\t\"7c000312RRR.\",\n  divweu_3 =\t\"7c000316RRR.\",\n  sthx_3 =\t\"7c00032eRR0R\",\n  orc_3 =\t\"7c000338RR~R.\",\n  ecowx_3 =\t\"7c00036cRR0R\",\n  sthux_3 =\t\"7c00036eRR0R\",\n  or_3 =\t\"7c000378RR~R.\",\n  mr_2 =\t\"7c000378RR~%.\",\n  divdu_3 =\t\"7c000392RRR.\",\n  divwu_3 =\t\"7c000396RRR.\",\n  mtspefscr_1 =\t\"7c0083a6R\",\n  mtxer_1 =\t\"7c0103a6R\",\n  mtlr_1 =\t\"7c0803a6R\",\n  mtctr_1 =\t\"7c0903a6R\",\n  dcbi_2 =\t\"7c0003ac-RR\",\n  nand_3 =\t\"7c0003b8RR~R.\",\n  dsn_2 =\t\"7c0003c6-RR\",\n  stvxl_3 =\t\"7c0003ceVRR\",\n  divd_3 =\t\"7c0003d2RRR.\",\n  divw_3 =\t\"7c0003d6RRR.\",\n  popcntd_2 =\t\"7c0003f4RR~\",\n  cmpb_3 =\t\"7c0003f8RR~R.\",\n  mcrxr_1 =\t\"7c000400X\",\n  lbdx_3 =\t\"7c000406RRR\",\n  subfco_3 =\t\"7c000410RRR.\",\n  subco_3 =\t\"7c000410RRR~.\",\n  addco_3 =\t\"7c000414RRR.\",\n  ldbrx_3 =\t\"7c000428RR0R\",\n  lswx_3 =\t\"7c00042aRR0R\",\n  lwbrx_3 =\t\"7c00042cRR0R\",\n  lfsx_3 =\t\"7c00042eFR0R\",\n  srw_3 =\t\"7c000430RR~R.\",\n  srd_3 =\t\"7c000436RR~R.\",\n  lhdx_3 =\t\"7c000446RRR\",\n  subfo_3 =\t\"7c000450RRR.\",\n  subo_3 =\t\"7c000450RRR~.\",\n  lfsux_3 =\t\"7c00046eFR0R\",\n  lwdx_3 =\t\"7c000486RRR\",\n  lswi_3 =\t\"7c0004aaRR0A\",\n  sync_0 =\t\"7c0004ac\",\n  lwsync_0 =\t\"7c2004ac\",\n  ptesync_0 =\t\"7c4004ac\",\n  lfdx_3 =\t\"7c0004aeFR0R\",\n  lddx_3 =\t\"7c0004c6RRR\",\n  nego_2 =\t\"7c0004d0RR.\",\n  lfdux_3 =\t\"7c0004eeFR0R\",\n  stbdx_3 =\t\"7c000506RRR\",\n  subfeo_3 =\t\"7c000510RRR.\",\n  subeo_3 =\t\"7c000510RRR~.\",\n  addeo_3 =\t\"7c000514RRR.\",\n  stdbrx_3 =\t\"7c000528RR0R\",\n  stswx_3 =\t\"7c00052aRR0R\",\n  stwbrx_3 =\t\"7c00052cRR0R\",\n  stfsx_3 =\t\"7c00052eFR0R\",\n  sthdx_3 =\t\"7c000546RRR\",\n  [\"stbcx._3\"] =\t\"7c00056dRRR\",\n  stfsux_3 =\t\"7c00056eFR0R\",\n  stwdx_3 =\t\"7c000586RRR\",\n  subfzeo_2 =\t\"7c000590RR.\",\n  addzeo_2 =\t\"7c000594RR.\",\n  stswi_3 =\t\"7c0005aaRR0A\",\n  [\"sthcx._3\"] =\t\"7c0005adRRR\",\n  stfdx_3 =\t\"7c0005aeFR0R\",\n  stddx_3 =\t\"7c0005c6RRR\",\n  subfmeo_2 =\t\"7c0005d0RR.\",\n  mulldo_3 =\t\"7c0005d2RRR.\",\n  addmeo_2 =\t\"7c0005d4RR.\",\n  mullwo_3 =\t\"7c0005d6RRR.\",\n  dcba_2 =\t\"7c0005ec-RR\",\n  stfdux_3 =\t\"7c0005eeFR0R\",\n  stvepxl_3 =\t\"7c00060eVRR\",\n  addo_3 =\t\"7c000614RRR.\",\n  lhbrx_3 =\t\"7c00062cRR0R\",\n  lfdpx_3 =\t\"7c00062eF:RR\",\n  sraw_3 =\t\"7c000630RR~R.\",\n  srad_3 =\t\"7c000634RR~R.\",\n  lfddx_3 =\t\"7c000646FRR\",\n  stvepx_3 =\t\"7c00064eVRR\",\n  srawi_3 =\t\"7c000670RR~A.\",\n  sradi_3 =\t\"7c000674RR~H.\",\n  eieio_0 =\t\"7c0006ac\",\n  lfiwax_3 =\t\"7c0006aeFR0R\",\n  divdeuo_3 =\t\"7c000712RRR.\",\n  divweuo_3 =\t\"7c000716RRR.\",\n  sthbrx_3 =\t\"7c00072cRR0R\",\n  stfdpx_3 =\t\"7c00072eF:RR\",\n  extsh_2 =\t\"7c000734RR~.\",\n  stfddx_3 =\t\"7c000746FRR\",\n  divdeo_3 =\t\"7c000752RRR.\",\n  divweo_3 =\t\"7c000756RRR.\",\n  extsb_2 =\t\"7c000774RR~.\",\n  divduo_3 =\t\"7c000792RRR.\",\n  divwou_3 =\t\"7c000796RRR.\",\n  icbi_2 =\t\"7c0007ac-RR\",\n  stfiwx_3 =\t\"7c0007aeFR0R\",\n  extsw_2 =\t\"7c0007b4RR~.\",\n  divdo_3 =\t\"7c0007d2RRR.\",\n  divwo_3 =\t\"7c0007d6RRR.\",\n  dcbz_2 =\t\"7c0007ec-RR\",\n\n  [\"tbegin._1\"] =\t\"7c00051d1\",\n  [\"tbegin._0\"] =\t\"7c00051d\",\n  [\"tend._1\"] =\t\t\"7c00055dY\",\n  [\"tend._0\"] =\t\t\"7c00055d\",\n  [\"tendall._0\"] =\t\"7e00055d\",\n  tcheck_1 =\t\t\"7c00059cX\",\n  [\"tsr._1\"] =\t\t\"7c0005dd1\",\n  [\"tsuspend._0\"] =\t\"7c0005dd\",\n  [\"tresume._0\"] =\t\"7c2005dd\",\n  [\"tabortwc._3\"] =\t\"7c00061dARR\",\n  [\"tabortdc._3\"] =\t\"7c00065dARR\",\n  [\"tabortwci._3\"] =\t\"7c00069dARS\",\n  [\"tabortdci._3\"] =\t\"7c0006ddARS\",\n  [\"tabort._1\"] =\t\"7c00071d-R-\",\n  [\"treclaim._1\"] =\t\"7c00075d-R\",\n  [\"trechkpt._0\"] =\t\"7c0007dd\",\n\n  lxsiwzx_3 =\t\"7c000018QRR\",\n  lxsiwax_3 =\t\"7c000098QRR\",\n  mfvsrd_2 =\t\"7c000066-Rq\",\n  mfvsrwz_2 =\t\"7c0000e6-Rq\",\n  stxsiwx_3 =\t\"7c000118QRR\",\n  mtvsrd_2 =\t\"7c000166QR\",\n  mtvsrwa_2 =\t\"7c0001a6QR\",\n  lxvdsx_3 =\t\"7c000298QRR\",\n  lxsspx_3 =\t\"7c000418QRR\",\n  lxsdx_3 =\t\"7c000498QRR\",\n  stxsspx_3 =\t\"7c000518QRR\",\n  stxsdx_3 =\t\"7c000598QRR\",\n  lxvw4x_3 =\t\"7c000618QRR\",\n  lxvd2x_3 =\t\"7c000698QRR\",\n  stxvw4x_3 =\t\"7c000718QRR\",\n  stxvd2x_3 =\t\"7c000798QRR\",\n\n  -- Primary opcode 30:\n  rldicl_4 =\t\"78000000RR~HM.\",\n  rldicr_4 =\t\"78000004RR~HM.\",\n  rldic_4 =\t\"78000008RR~HM.\",\n  rldimi_4 =\t\"7800000cRR~HM.\",\n  rldcl_4 =\t\"78000010RR~RM.\",\n  rldcr_4 =\t\"78000012RR~RM.\",\n\n  rotldi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = \"0\"\n  end),\n  rotrdi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[3] = \"64-(\"..p[3]..\")\"; p[4] = \"0\"\n  end),\n  rotld_3 =\top_alias(\"rldcl_4\", function(p)\n    p[4] = \"0\"\n  end),\n  sldi_3 =\top_alias(\"rldicr_4\", function(p)\n    p[4] = \"63-(\"..p[3]..\")\"\n  end),\n  srdi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = p[3]; p[3] = \"64-(\"..p[3]..\")\"\n  end),\n  clrldi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = p[3]; p[3] = \"0\"\n  end),\n  clrrdi_3 =\top_alias(\"rldicr_4\", function(p)\n    p[4] = \"63-(\"..p[3]..\")\"; p[3] = \"0\"\n  end),\n\n  -- Primary opcode 56:\n  lq_2 =\t\"e0000000R:D\", -- NYI: displacement must be divisible by 8.\n\n  -- Primary opcode 57:\n  lfdp_2 =\t\"e4000000F:D\", -- NYI: displacement must be divisible by 4.\n\n  -- Primary opcode 59:\n  fdivs_3 =\t\"ec000024FFF.\",\n  fsubs_3 =\t\"ec000028FFF.\",\n  fadds_3 =\t\"ec00002aFFF.\",\n  fsqrts_2 =\t\"ec00002cF-F.\",\n  fres_2 =\t\"ec000030F-F.\",\n  fmuls_3 =\t\"ec000032FF-F.\",\n  frsqrtes_2 =\t\"ec000034F-F.\",\n  fmsubs_4 =\t\"ec000038FFFF~.\",\n  fmadds_4 =\t\"ec00003aFFFF~.\",\n  fnmsubs_4 =\t\"ec00003cFFFF~.\",\n  fnmadds_4 =\t\"ec00003eFFFF~.\",\n  fcfids_2 =\t\"ec00069cF-F.\",\n  fcfidus_2 =\t\"ec00079cF-F.\",\n\n  dadd_3 =\t\"ec000004FFF.\",\n  dqua_4 =\t\"ec000006FFFZ.\",\n  dmul_3 =\t\"ec000044FFF.\",\n  drrnd_4 =\t\"ec000046FFFZ.\",\n  dscli_3 =\t\"ec000084FF6.\",\n  dquai_4 =\t\"ec000086SF~FZ.\",\n  dscri_3 =\t\"ec0000c4FF6.\",\n  drintx_4 =\t\"ec0000c61F~FZ.\",\n  dcmpo_3 =\t\"ec000104XFF\",\n  dtstex_3 =\t\"ec000144XFF\",\n  dtstdc_3 =\t\"ec000184XF6\",\n  dtstdg_3 =\t\"ec0001c4XF6\",\n  drintn_4 =\t\"ec0001c61F~FZ.\",\n  dctdp_2 =\t\"ec000204F-F.\",\n  dctfix_2 =\t\"ec000244F-F.\",\n  ddedpd_3 =\t\"ec000284ZF~F.\",\n  dxex_2 =\t\"ec0002c4F-F.\",\n  dsub_3 =\t\"ec000404FFF.\",\n  ddiv_3 =\t\"ec000444FFF.\",\n  dcmpu_3 =\t\"ec000504XFF\",\n  dtstsf_3 =\t\"ec000544XFF\",\n  drsp_2 =\t\"ec000604F-F.\",\n  dcffix_2 =\t\"ec000644F-F.\",\n  denbcd_3 =\t\"ec000684YF~F.\",\n  diex_3 =\t\"ec0006c4FFF.\",\n\n  -- Primary opcode 60:\n  xsaddsp_3 =\t\t\"f0000000QQQ\",\n  xsmaddasp_3 =\t\t\"f0000008QQQ\",\n  xxsldwi_4 =\t\t\"f0000010QQQz\",\n  xsrsqrtesp_2 =\t\"f0000028Q-Q\",\n  xssqrtsp_2 =\t\t\"f000002cQ-Q\",\n  xxsel_4 =\t\t\"f0000030QQQQ\",\n  xssubsp_3 =\t\t\"f0000040QQQ\",\n  xsmaddmsp_3 =\t\t\"f0000048QQQ\",\n  xxpermdi_4 =\t\t\"f0000050QQQz\",\n  xsresp_2 =\t\t\"f0000068Q-Q\",\n  xsmulsp_3 =\t\t\"f0000080QQQ\",\n  xsmsubasp_3 =\t\t\"f0000088QQQ\",\n  xxmrghw_3 =\t\t\"f0000090QQQ\",\n  xsdivsp_3 =\t\t\"f00000c0QQQ\",\n  xsmsubmsp_3 =\t\t\"f00000c8QQQ\",\n  xsadddp_3 =\t\t\"f0000100QQQ\",\n  xsmaddadp_3 =\t\t\"f0000108QQQ\",\n  xscmpudp_3 =\t\t\"f0000118XQQ\",\n  xscvdpuxws_2 =\t\"f0000120Q-Q\",\n  xsrdpi_2 =\t\t\"f0000124Q-Q\",\n  xsrsqrtedp_2 =\t\"f0000128Q-Q\",\n  xssqrtdp_2 =\t\t\"f000012cQ-Q\",\n  xssubdp_3 =\t\t\"f0000140QQQ\",\n  xsmaddmdp_3 =\t\t\"f0000148QQQ\",\n  xscmpodp_3 =\t\t\"f0000158XQQ\",\n  xscvdpsxws_2 =\t\"f0000160Q-Q\",\n  xsrdpiz_2 =\t\t\"f0000164Q-Q\",\n  xsredp_2 =\t\t\"f0000168Q-Q\",\n  xsmuldp_3 =\t\t\"f0000180QQQ\",\n  xsmsubadp_3 =\t\t\"f0000188QQQ\",\n  xxmrglw_3 =\t\t\"f0000190QQQ\",\n  xsrdpip_2 =\t\t\"f00001a4Q-Q\",\n  xstsqrtdp_2 =\t\t\"f00001a8X-Q\",\n  xsrdpic_2 =\t\t\"f00001acQ-Q\",\n  xsdivdp_3 =\t\t\"f00001c0QQQ\",\n  xsmsubmdp_3 =\t\t\"f00001c8QQQ\",\n  xsrdpim_2 =\t\t\"f00001e4Q-Q\",\n  xstdivdp_3 =\t\t\"f00001e8XQQ\",\n  xvaddsp_3 =\t\t\"f0000200QQQ\",\n  xvmaddasp_3 =\t\t\"f0000208QQQ\",\n  xvcmpeqsp_3 =\t\t\"f0000218QQQ\",\n  xvcvspuxws_2 =\t\"f0000220Q-Q\",\n  xvrspi_2 =\t\t\"f0000224Q-Q\",\n  xvrsqrtesp_2 =\t\"f0000228Q-Q\",\n  xvsqrtsp_2 =\t\t\"f000022cQ-Q\",\n  xvsubsp_3 =\t\t\"f0000240QQQ\",\n  xvmaddmsp_3 =\t\t\"f0000248QQQ\",\n  xvcmpgtsp_3 =\t\t\"f0000258QQQ\",\n  xvcvspsxws_2 =\t\"f0000260Q-Q\",\n  xvrspiz_2 =\t\t\"f0000264Q-Q\",\n  xvresp_2 =\t\t\"f0000268Q-Q\",\n  xvmulsp_3 =\t\t\"f0000280QQQ\",\n  xvmsubasp_3 =\t\t\"f0000288QQQ\",\n  xxspltw_3 =\t\t\"f0000290QQg~\",\n  xvcmpgesp_3 =\t\t\"f0000298QQQ\",\n  xvcvuxwsp_2 =\t\t\"f00002a0Q-Q\",\n  xvrspip_2 =\t\t\"f00002a4Q-Q\",\n  xvtsqrtsp_2 =\t\t\"f00002a8X-Q\",\n  xvrspic_2 =\t\t\"f00002acQ-Q\",\n  xvdivsp_3 =\t\t\"f00002c0QQQ\",\n  xvmsubmsp_3 =\t\t\"f00002c8QQQ\",\n  xvcvsxwsp_2 =\t\t\"f00002e0Q-Q\",\n  xvrspim_2 =\t\t\"f00002e4Q-Q\",\n  xvtdivsp_3 =\t\t\"f00002e8XQQ\",\n  xvadddp_3 =\t\t\"f0000300QQQ\",\n  xvmaddadp_3 =\t\t\"f0000308QQQ\",\n  xvcmpeqdp_3 =\t\t\"f0000318QQQ\",\n  xvcvdpuxws_2 =\t\"f0000320Q-Q\",\n  xvrdpi_2 =\t\t\"f0000324Q-Q\",\n  xvrsqrtedp_2 =\t\"f0000328Q-Q\",\n  xvsqrtdp_2 =\t\t\"f000032cQ-Q\",\n  xvsubdp_3 =\t\t\"f0000340QQQ\",\n  xvmaddmdp_3 =\t\t\"f0000348QQQ\",\n  xvcmpgtdp_3 =\t\t\"f0000358QQQ\",\n  xvcvdpsxws_2 =\t\"f0000360Q-Q\",\n  xvrdpiz_2 =\t\t\"f0000364Q-Q\",\n  xvredp_2 =\t\t\"f0000368Q-Q\",\n  xvmuldp_3 =\t\t\"f0000380QQQ\",\n  xvmsubadp_3 =\t\t\"f0000388QQQ\",\n  xvcmpgedp_3 =\t\t\"f0000398QQQ\",\n  xvcvuxwdp_2 =\t\t\"f00003a0Q-Q\",\n  xvrdpip_2 =\t\t\"f00003a4Q-Q\",\n  xvtsqrtdp_2 =\t\t\"f00003a8X-Q\",\n  xvrdpic_2 =\t\t\"f00003acQ-Q\",\n  xvdivdp_3 =\t\t\"f00003c0QQQ\",\n  xvmsubmdp_3 =\t\t\"f00003c8QQQ\",\n  xvcvsxwdp_2 =\t\t\"f00003e0Q-Q\",\n  xvrdpim_2 =\t\t\"f00003e4Q-Q\",\n  xvtdivdp_3 =\t\t\"f00003e8XQQ\",\n  xsnmaddasp_3 =\t\"f0000408QQQ\",\n  xxland_3 =\t\t\"f0000410QQQ\",\n  xscvdpsp_2 =\t\t\"f0000424Q-Q\",\n  xscvdpspn_2 =\t\t\"f000042cQ-Q\",\n  xsnmaddmsp_3 =\t\"f0000448QQQ\",\n  xxlandc_3 =\t\t\"f0000450QQQ\",\n  xsrsp_2 =\t\t\"f0000464Q-Q\",\n  xsnmsubasp_3 =\t\"f0000488QQQ\",\n  xxlor_3 =\t\t\"f0000490QQQ\",\n  xscvuxdsp_2 =\t\t\"f00004a0Q-Q\",\n  xsnmsubmsp_3 =\t\"f00004c8QQQ\",\n  xxlxor_3 =\t\t\"f00004d0QQQ\",\n  xscvsxdsp_2 =\t\t\"f00004e0Q-Q\",\n  xsmaxdp_3 =\t\t\"f0000500QQQ\",\n  xsnmaddadp_3 =\t\"f0000508QQQ\",\n  xxlnor_3 =\t\t\"f0000510QQQ\",\n  xscvdpuxds_2 =\t\"f0000520Q-Q\",\n  xscvspdp_2 =\t\t\"f0000524Q-Q\",\n  xscvspdpn_2 =\t\t\"f000052cQ-Q\",\n  xsmindp_3 =\t\t\"f0000540QQQ\",\n  xsnmaddmdp_3 =\t\"f0000548QQQ\",\n  xxlorc_3 =\t\t\"f0000550QQQ\",\n  xscvdpsxds_2 =\t\"f0000560Q-Q\",\n  xsabsdp_2 =\t\t\"f0000564Q-Q\",\n  xscpsgndp_3 =\t\t\"f0000580QQQ\",\n  xsnmsubadp_3 =\t\"f0000588QQQ\",\n  xxlnand_3 =\t\t\"f0000590QQQ\",\n  xscvuxddp_2 =\t\t\"f00005a0Q-Q\",\n  xsnabsdp_2 =\t\t\"f00005a4Q-Q\",\n  xsnmsubmdp_3 =\t\"f00005c8QQQ\",\n  xxleqv_3 =\t\t\"f00005d0QQQ\",\n  xscvsxddp_2 =\t\t\"f00005e0Q-Q\",\n  xsnegdp_2 =\t\t\"f00005e4Q-Q\",\n  xvmaxsp_3 =\t\t\"f0000600QQQ\",\n  xvnmaddasp_3 =\t\"f0000608QQQ\",\n  [\"xvcmpeqsp._3\"] =\t\"f0000618QQQ\",\n  xvcvspuxds_2 =\t\"f0000620Q-Q\",\n  xvcvdpsp_2 =\t\t\"f0000624Q-Q\",\n  xvminsp_3 =\t\t\"f0000640QQQ\",\n  xvnmaddmsp_3 =\t\"f0000648QQQ\",\n  [\"xvcmpgtsp._3\"] =\t\"f0000658QQQ\",\n  xvcvspsxds_2 =\t\"f0000660Q-Q\",\n  xvabssp_2 =\t\t\"f0000664Q-Q\",\n  xvcpsgnsp_3 =\t\t\"f0000680QQQ\",\n  xvnmsubasp_3 =\t\"f0000688QQQ\",\n  [\"xvcmpgesp._3\"] =\t\"f0000698QQQ\",\n  xvcvuxdsp_2 =\t\t\"f00006a0Q-Q\",\n  xvnabssp_2 =\t\t\"f00006a4Q-Q\",\n  xvnmsubmsp_3 =\t\"f00006c8QQQ\",\n  xvcvsxdsp_2 =\t\t\"f00006e0Q-Q\",\n  xvnegsp_2 =\t\t\"f00006e4Q-Q\",\n  xvmaxdp_3 =\t\t\"f0000700QQQ\",\n  xvnmaddadp_3 =\t\"f0000708QQQ\",\n  [\"xvcmpeqdp._3\"] =\t\"f0000718QQQ\",\n  xvcvdpuxds_2 =\t\"f0000720Q-Q\",\n  xvcvspdp_2 =\t\t\"f0000724Q-Q\",\n  xvmindp_3 =\t\t\"f0000740QQQ\",\n  xvnmaddmdp_3 =\t\"f0000748QQQ\",\n  [\"xvcmpgtdp._3\"] =\t\"f0000758QQQ\",\n  xvcvdpsxds_2 =\t\"f0000760Q-Q\",\n  xvabsdp_2 =\t\t\"f0000764Q-Q\",\n  xvcpsgndp_3 =\t\t\"f0000780QQQ\",\n  xvnmsubadp_3 =\t\"f0000788QQQ\",\n  [\"xvcmpgedp._3\"] =\t\"f0000798QQQ\",\n  xvcvuxddp_2 =\t\t\"f00007a0Q-Q\",\n  xvnabsdp_2 =\t\t\"f00007a4Q-Q\",\n  xvnmsubmdp_3 =\t\"f00007c8QQQ\",\n  xvcvsxddp_2 =\t\t\"f00007e0Q-Q\",\n  xvnegdp_2 =\t\t\"f00007e4Q-Q\",\n\n  -- Primary opcode 61:\n  stfdp_2 =\t\"f4000000F:D\", -- NYI: displacement must be divisible by 4.\n\n  -- Primary opcode 62:\n  stq_2 =\t\"f8000002R:D\", -- NYI: displacement must be divisible by 8.\n\n  -- Primary opcode 63:\n  fdiv_3 =\t\"fc000024FFF.\",\n  fsub_3 =\t\"fc000028FFF.\",\n  fadd_3 =\t\"fc00002aFFF.\",\n  fsqrt_2 =\t\"fc00002cF-F.\",\n  fsel_4 =\t\"fc00002eFFFF~.\",\n  fre_2 =\t\"fc000030F-F.\",\n  fmul_3 =\t\"fc000032FF-F.\",\n  frsqrte_2 =\t\"fc000034F-F.\",\n  fmsub_4 =\t\"fc000038FFFF~.\",\n  fmadd_4 =\t\"fc00003aFFFF~.\",\n  fnmsub_4 =\t\"fc00003cFFFF~.\",\n  fnmadd_4 =\t\"fc00003eFFFF~.\",\n  fcmpu_3 =\t\"fc000000XFF\",\n  fcpsgn_3 =\t\"fc000010FFF.\",\n  fcmpo_3 =\t\"fc000040XFF\",\n  mtfsb1_1 =\t\"fc00004cA\",\n  fneg_2 =\t\"fc000050F-F.\",\n  mcrfs_2 =\t\"fc000080XX\",\n  mtfsb0_1 =\t\"fc00008cA\",\n  fmr_2 =\t\"fc000090F-F.\",\n  frsp_2 =\t\"fc000018F-F.\",\n  fctiw_2 =\t\"fc00001cF-F.\",\n  fctiwz_2 =\t\"fc00001eF-F.\",\n  ftdiv_2 =\t\"fc000100X-F.\",\n  fctiwu_2 =\t\"fc00011cF-F.\",\n  fctiwuz_2 =\t\"fc00011eF-F.\",\n  mtfsfi_2 =\t\"fc00010cAA\", -- NYI: upshift.\n  fnabs_2 =\t\"fc000110F-F.\",\n  ftsqrt_2 =\t\"fc000140X-F.\",\n  fabs_2 =\t\"fc000210F-F.\",\n  frin_2 =\t\"fc000310F-F.\",\n  friz_2 =\t\"fc000350F-F.\",\n  frip_2 =\t\"fc000390F-F.\",\n  frim_2 =\t\"fc0003d0F-F.\",\n  mffs_1 =\t\"fc00048eF.\",\n  -- NYI: mtfsf, mtfsb0, mtfsb1.\n  fctid_2 =\t\"fc00065cF-F.\",\n  fctidz_2 =\t\"fc00065eF-F.\",\n  fmrgow_3 =\t\"fc00068cFFF\",\n  fcfid_2 =\t\"fc00069cF-F.\",\n  fctidu_2 =\t\"fc00075cF-F.\",\n  fctiduz_2 =\t\"fc00075eF-F.\",\n  fmrgew_3 =\t\"fc00078cFFF\",\n  fcfidu_2 =\t\"fc00079cF-F.\",\n\n  daddq_3 =\t\"fc000004F:F:F:.\",\n  dquaq_4 =\t\"fc000006F:F:F:Z.\",\n  dmulq_3 =\t\"fc000044F:F:F:.\",\n  drrndq_4 =\t\"fc000046F:F:F:Z.\",\n  dscliq_3 =\t\"fc000084F:F:6.\",\n  dquaiq_4 =\t\"fc000086SF:~F:Z.\",\n  dscriq_3 =\t\"fc0000c4F:F:6.\",\n  drintxq_4 =\t\"fc0000c61F:~F:Z.\",\n  dcmpoq_3 =\t\"fc000104XF:F:\",\n  dtstexq_3 =\t\"fc000144XF:F:\",\n  dtstdcq_3 =\t\"fc000184XF:6\",\n  dtstdgq_3 =\t\"fc0001c4XF:6\",\n  drintnq_4 =\t\"fc0001c61F:~F:Z.\",\n  dctqpq_2 =\t\"fc000204F:-F:.\",\n  dctfixq_2 =\t\"fc000244F:-F:.\",\n  ddedpdq_3 =\t\"fc000284ZF:~F:.\",\n  dxexq_2 =\t\"fc0002c4F:-F:.\",\n  dsubq_3 =\t\"fc000404F:F:F:.\",\n  ddivq_3 =\t\"fc000444F:F:F:.\",\n  dcmpuq_3 =\t\"fc000504XF:F:\",\n  dtstsfq_3 =\t\"fc000544XF:F:\",\n  drdpq_2 =\t\"fc000604F:-F:.\",\n  dcffixq_2 =\t\"fc000644F:-F:.\",\n  denbcdq_3 =\t\"fc000684YF:~F:.\",\n  diexq_3 =\t\"fc0006c4F:FF:.\",\n\n  -- Primary opcode 4, SPE APU extension:\n  evaddw_3 =\t\t\"10000200RRR\",\n  evaddiw_3 =\t\t\"10000202RAR~\",\n  evsubw_3 =\t\t\"10000204RRR~\",\n  evsubiw_3 =\t\t\"10000206RAR~\",\n  evabs_2 =\t\t\"10000208RR\",\n  evneg_2 =\t\t\"10000209RR\",\n  evextsb_2 =\t\t\"1000020aRR\",\n  evextsh_2 =\t\t\"1000020bRR\",\n  evrndw_2 =\t\t\"1000020cRR\",\n  evcntlzw_2 =\t\t\"1000020dRR\",\n  evcntlsw_2 =\t\t\"1000020eRR\",\n  brinc_3 =\t\t\"1000020fRRR\",\n  evand_3 =\t\t\"10000211RRR\",\n  evandc_3 =\t\t\"10000212RRR\",\n  evxor_3 =\t\t\"10000216RRR\",\n  evor_3 =\t\t\"10000217RRR\",\n  evmr_2 =\t\t\"10000217RR=\",\n  evnor_3 =\t\t\"10000218RRR\",\n  evnot_2 =\t\t\"10000218RR=\",\n  eveqv_3 =\t\t\"10000219RRR\",\n  evorc_3 =\t\t\"1000021bRRR\",\n  evnand_3 =\t\t\"1000021eRRR\",\n  evsrwu_3 =\t\t\"10000220RRR\",\n  evsrws_3 =\t\t\"10000221RRR\",\n  evsrwiu_3 =\t\t\"10000222RRA\",\n  evsrwis_3 =\t\t\"10000223RRA\",\n  evslw_3 =\t\t\"10000224RRR\",\n  evslwi_3 =\t\t\"10000226RRA\",\n  evrlw_3 =\t\t\"10000228RRR\",\n  evsplati_2 =\t\t\"10000229RS\",\n  evrlwi_3 =\t\t\"1000022aRRA\",\n  evsplatfi_2 =\t\t\"1000022bRS\",\n  evmergehi_3 =\t\t\"1000022cRRR\",\n  evmergelo_3 =\t\t\"1000022dRRR\",\n  evcmpgtu_3 =\t\t\"10000230XRR\",\n  evcmpgtu_2 =\t\t\"10000230-RR\",\n  evcmpgts_3 =\t\t\"10000231XRR\",\n  evcmpgts_2 =\t\t\"10000231-RR\",\n  evcmpltu_3 =\t\t\"10000232XRR\",\n  evcmpltu_2 =\t\t\"10000232-RR\",\n  evcmplts_3 =\t\t\"10000233XRR\",\n  evcmplts_2 =\t\t\"10000233-RR\",\n  evcmpeq_3 =\t\t\"10000234XRR\",\n  evcmpeq_2 =\t\t\"10000234-RR\",\n  evsel_4 =\t\t\"10000278RRRW\",\n  evsel_3 =\t\t\"10000278RRR\",\n  evfsadd_3 =\t\t\"10000280RRR\",\n  evfssub_3 =\t\t\"10000281RRR\",\n  evfsabs_2 =\t\t\"10000284RR\",\n  evfsnabs_2 =\t\t\"10000285RR\",\n  evfsneg_2 =\t\t\"10000286RR\",\n  evfsmul_3 =\t\t\"10000288RRR\",\n  evfsdiv_3 =\t\t\"10000289RRR\",\n  evfscmpgt_3 =\t\t\"1000028cXRR\",\n  evfscmpgt_2 =\t\t\"1000028c-RR\",\n  evfscmplt_3 =\t\t\"1000028dXRR\",\n  evfscmplt_2 =\t\t\"1000028d-RR\",\n  evfscmpeq_3 =\t\t\"1000028eXRR\",\n  evfscmpeq_2 =\t\t\"1000028e-RR\",\n  evfscfui_2 =\t\t\"10000290R-R\",\n  evfscfsi_2 =\t\t\"10000291R-R\",\n  evfscfuf_2 =\t\t\"10000292R-R\",\n  evfscfsf_2 =\t\t\"10000293R-R\",\n  evfsctui_2 =\t\t\"10000294R-R\",\n  evfsctsi_2 =\t\t\"10000295R-R\",\n  evfsctuf_2 =\t\t\"10000296R-R\",\n  evfsctsf_2 =\t\t\"10000297R-R\",\n  evfsctuiz_2 =\t\t\"10000298R-R\",\n  evfsctsiz_2 =\t\t\"1000029aR-R\",\n  evfststgt_3 =\t\t\"1000029cXRR\",\n  evfststgt_2 =\t\t\"1000029c-RR\",\n  evfststlt_3 =\t\t\"1000029dXRR\",\n  evfststlt_2 =\t\t\"1000029d-RR\",\n  evfststeq_3 =\t\t\"1000029eXRR\",\n  evfststeq_2 =\t\t\"1000029e-RR\",\n  efsadd_3 =\t\t\"100002c0RRR\",\n  efssub_3 =\t\t\"100002c1RRR\",\n  efsabs_2 =\t\t\"100002c4RR\",\n  efsnabs_2 =\t\t\"100002c5RR\",\n  efsneg_2 =\t\t\"100002c6RR\",\n  efsmul_3 =\t\t\"100002c8RRR\",\n  efsdiv_3 =\t\t\"100002c9RRR\",\n  efscmpgt_3 =\t\t\"100002ccXRR\",\n  efscmpgt_2 =\t\t\"100002cc-RR\",\n  efscmplt_3 =\t\t\"100002cdXRR\",\n  efscmplt_2 =\t\t\"100002cd-RR\",\n  efscmpeq_3 =\t\t\"100002ceXRR\",\n  efscmpeq_2 =\t\t\"100002ce-RR\",\n  efscfd_2 =\t\t\"100002cfR-R\",\n  efscfui_2 =\t\t\"100002d0R-R\",\n  efscfsi_2 =\t\t\"100002d1R-R\",\n  efscfuf_2 =\t\t\"100002d2R-R\",\n  efscfsf_2 =\t\t\"100002d3R-R\",\n  efsctui_2 =\t\t\"100002d4R-R\",\n  efsctsi_2 =\t\t\"100002d5R-R\",\n  efsctuf_2 =\t\t\"100002d6R-R\",\n  efsctsf_2 =\t\t\"100002d7R-R\",\n  efsctuiz_2 =\t\t\"100002d8R-R\",\n  efsctsiz_2 =\t\t\"100002daR-R\",\n  efststgt_3 =\t\t\"100002dcXRR\",\n  efststgt_2 =\t\t\"100002dc-RR\",\n  efststlt_3 =\t\t\"100002ddXRR\",\n  efststlt_2 =\t\t\"100002dd-RR\",\n  efststeq_3 =\t\t\"100002deXRR\",\n  efststeq_2 =\t\t\"100002de-RR\",\n  efdadd_3 =\t\t\"100002e0RRR\",\n  efdsub_3 =\t\t\"100002e1RRR\",\n  efdcfuid_2 =\t\t\"100002e2R-R\",\n  efdcfsid_2 =\t\t\"100002e3R-R\",\n  efdabs_2 =\t\t\"100002e4RR\",\n  efdnabs_2 =\t\t\"100002e5RR\",\n  efdneg_2 =\t\t\"100002e6RR\",\n  efdmul_3 =\t\t\"100002e8RRR\",\n  efddiv_3 =\t\t\"100002e9RRR\",\n  efdctuidz_2 =\t\t\"100002eaR-R\",\n  efdctsidz_2 =\t\t\"100002ebR-R\",\n  efdcmpgt_3 =\t\t\"100002ecXRR\",\n  efdcmpgt_2 =\t\t\"100002ec-RR\",\n  efdcmplt_3 =\t\t\"100002edXRR\",\n  efdcmplt_2 =\t\t\"100002ed-RR\",\n  efdcmpeq_3 =\t\t\"100002eeXRR\",\n  efdcmpeq_2 =\t\t\"100002ee-RR\",\n  efdcfs_2 =\t\t\"100002efR-R\",\n  efdcfui_2 =\t\t\"100002f0R-R\",\n  efdcfsi_2 =\t\t\"100002f1R-R\",\n  efdcfuf_2 =\t\t\"100002f2R-R\",\n  efdcfsf_2 =\t\t\"100002f3R-R\",\n  efdctui_2 =\t\t\"100002f4R-R\",\n  efdctsi_2 =\t\t\"100002f5R-R\",\n  efdctuf_2 =\t\t\"100002f6R-R\",\n  efdctsf_2 =\t\t\"100002f7R-R\",\n  efdctuiz_2 =\t\t\"100002f8R-R\",\n  efdctsiz_2 =\t\t\"100002faR-R\",\n  efdtstgt_3 =\t\t\"100002fcXRR\",\n  efdtstgt_2 =\t\t\"100002fc-RR\",\n  efdtstlt_3 =\t\t\"100002fdXRR\",\n  efdtstlt_2 =\t\t\"100002fd-RR\",\n  efdtsteq_3 =\t\t\"100002feXRR\",\n  efdtsteq_2 =\t\t\"100002fe-RR\",\n  evlddx_3 =\t\t\"10000300RR0R\",\n  evldd_2 =\t\t\"10000301R8\",\n  evldwx_3 =\t\t\"10000302RR0R\",\n  evldw_2 =\t\t\"10000303R8\",\n  evldhx_3 =\t\t\"10000304RR0R\",\n  evldh_2 =\t\t\"10000305R8\",\n  evlwhex_3 =\t\t\"10000310RR0R\",\n  evlwhe_2 =\t\t\"10000311R4\",\n  evlwhoux_3 =\t\t\"10000314RR0R\",\n  evlwhou_2 =\t\t\"10000315R4\",\n  evlwhosx_3 =\t\t\"10000316RR0R\",\n  evlwhos_2 =\t\t\"10000317R4\",\n  evstddx_3 =\t\t\"10000320RR0R\",\n  evstdd_2 =\t\t\"10000321R8\",\n  evstdwx_3 =\t\t\"10000322RR0R\",\n  evstdw_2 =\t\t\"10000323R8\",\n  evstdhx_3 =\t\t\"10000324RR0R\",\n  evstdh_2 =\t\t\"10000325R8\",\n  evstwhex_3 =\t\t\"10000330RR0R\",\n  evstwhe_2 =\t\t\"10000331R4\",\n  evstwhox_3 =\t\t\"10000334RR0R\",\n  evstwho_2 =\t\t\"10000335R4\",\n  evstwwex_3 =\t\t\"10000338RR0R\",\n  evstwwe_2 =\t\t\"10000339R4\",\n  evstwwox_3 =\t\t\"1000033cRR0R\",\n  evstwwo_2 =\t\t\"1000033dR4\",\n  evmhessf_3 =\t\t\"10000403RRR\",\n  evmhossf_3 =\t\t\"10000407RRR\",\n  evmheumi_3 =\t\t\"10000408RRR\",\n  evmhesmi_3 =\t\t\"10000409RRR\",\n  evmhesmf_3 =\t\t\"1000040bRRR\",\n  evmhoumi_3 =\t\t\"1000040cRRR\",\n  evmhosmi_3 =\t\t\"1000040dRRR\",\n  evmhosmf_3 =\t\t\"1000040fRRR\",\n  evmhessfa_3 =\t\t\"10000423RRR\",\n  evmhossfa_3 =\t\t\"10000427RRR\",\n  evmheumia_3 =\t\t\"10000428RRR\",\n  evmhesmia_3 =\t\t\"10000429RRR\",\n  evmhesmfa_3 =\t\t\"1000042bRRR\",\n  evmhoumia_3 =\t\t\"1000042cRRR\",\n  evmhosmia_3 =\t\t\"1000042dRRR\",\n  evmhosmfa_3 =\t\t\"1000042fRRR\",\n  evmwhssf_3 =\t\t\"10000447RRR\",\n  evmwlumi_3 =\t\t\"10000448RRR\",\n  evmwhumi_3 =\t\t\"1000044cRRR\",\n  evmwhsmi_3 =\t\t\"1000044dRRR\",\n  evmwhsmf_3 =\t\t\"1000044fRRR\",\n  evmwssf_3 =\t\t\"10000453RRR\",\n  evmwumi_3 =\t\t\"10000458RRR\",\n  evmwsmi_3 =\t\t\"10000459RRR\",\n  evmwsmf_3 =\t\t\"1000045bRRR\",\n  evmwhssfa_3 =\t\t\"10000467RRR\",\n  evmwlumia_3 =\t\t\"10000468RRR\",\n  evmwhumia_3 =\t\t\"1000046cRRR\",\n  evmwhsmia_3 =\t\t\"1000046dRRR\",\n  evmwhsmfa_3 =\t\t\"1000046fRRR\",\n  evmwssfa_3 =\t\t\"10000473RRR\",\n  evmwumia_3 =\t\t\"10000478RRR\",\n  evmwsmia_3 =\t\t\"10000479RRR\",\n  evmwsmfa_3 =\t\t\"1000047bRRR\",\n  evmra_2 =\t\t\"100004c4RR\",\n  evdivws_3 =\t\t\"100004c6RRR\",\n  evdivwu_3 =\t\t\"100004c7RRR\",\n  evmwssfaa_3 =\t\t\"10000553RRR\",\n  evmwumiaa_3 =\t\t\"10000558RRR\",\n  evmwsmiaa_3 =\t\t\"10000559RRR\",\n  evmwsmfaa_3 =\t\t\"1000055bRRR\",\n  evmwssfan_3 =\t\t\"100005d3RRR\",\n  evmwumian_3 =\t\t\"100005d8RRR\",\n  evmwsmian_3 =\t\t\"100005d9RRR\",\n  evmwsmfan_3 =\t\t\"100005dbRRR\",\n  evmergehilo_3 =\t\"1000022eRRR\",\n  evmergelohi_3 =\t\"1000022fRRR\",\n  evlhhesplatx_3 =\t\"10000308RR0R\",\n  evlhhesplat_2 =\t\"10000309R2\",\n  evlhhousplatx_3 =\t\"1000030cRR0R\",\n  evlhhousplat_2 =\t\"1000030dR2\",\n  evlhhossplatx_3 =\t\"1000030eRR0R\",\n  evlhhossplat_2 =\t\"1000030fR2\",\n  evlwwsplatx_3 =\t\"10000318RR0R\",\n  evlwwsplat_2 =\t\"10000319R4\",\n  evlwhsplatx_3 =\t\"1000031cRR0R\",\n  evlwhsplat_2 =\t\"1000031dR4\",\n  evaddusiaaw_2 =\t\"100004c0RR\",\n  evaddssiaaw_2 =\t\"100004c1RR\",\n  evsubfusiaaw_2 =\t\"100004c2RR\",\n  evsubfssiaaw_2 =\t\"100004c3RR\",\n  evaddumiaaw_2 =\t\"100004c8RR\",\n  evaddsmiaaw_2 =\t\"100004c9RR\",\n  evsubfumiaaw_2 =\t\"100004caRR\",\n  evsubfsmiaaw_2 =\t\"100004cbRR\",\n  evmheusiaaw_3 =\t\"10000500RRR\",\n  evmhessiaaw_3 =\t\"10000501RRR\",\n  evmhessfaaw_3 =\t\"10000503RRR\",\n  evmhousiaaw_3 =\t\"10000504RRR\",\n  evmhossiaaw_3 =\t\"10000505RRR\",\n  evmhossfaaw_3 =\t\"10000507RRR\",\n  evmheumiaaw_3 =\t\"10000508RRR\",\n  evmhesmiaaw_3 =\t\"10000509RRR\",\n  evmhesmfaaw_3 =\t\"1000050bRRR\",\n  evmhoumiaaw_3 =\t\"1000050cRRR\",\n  evmhosmiaaw_3 =\t\"1000050dRRR\",\n  evmhosmfaaw_3 =\t\"1000050fRRR\",\n  evmhegumiaa_3 =\t\"10000528RRR\",\n  evmhegsmiaa_3 =\t\"10000529RRR\",\n  evmhegsmfaa_3 =\t\"1000052bRRR\",\n  evmhogumiaa_3 =\t\"1000052cRRR\",\n  evmhogsmiaa_3 =\t\"1000052dRRR\",\n  evmhogsmfaa_3 =\t\"1000052fRRR\",\n  evmwlusiaaw_3 =\t\"10000540RRR\",\n  evmwlssiaaw_3 =\t\"10000541RRR\",\n  evmwlumiaaw_3 =\t\"10000548RRR\",\n  evmwlsmiaaw_3 =\t\"10000549RRR\",\n  evmheusianw_3 =\t\"10000580RRR\",\n  evmhessianw_3 =\t\"10000581RRR\",\n  evmhessfanw_3 =\t\"10000583RRR\",\n  evmhousianw_3 =\t\"10000584RRR\",\n  evmhossianw_3 =\t\"10000585RRR\",\n  evmhossfanw_3 =\t\"10000587RRR\",\n  evmheumianw_3 =\t\"10000588RRR\",\n  evmhesmianw_3 =\t\"10000589RRR\",\n  evmhesmfanw_3 =\t\"1000058bRRR\",\n  evmhoumianw_3 =\t\"1000058cRRR\",\n  evmhosmianw_3 =\t\"1000058dRRR\",\n  evmhosmfanw_3 =\t\"1000058fRRR\",\n  evmhegumian_3 =\t\"100005a8RRR\",\n  evmhegsmian_3 =\t\"100005a9RRR\",\n  evmhegsmfan_3 =\t\"100005abRRR\",\n  evmhogumian_3 =\t\"100005acRRR\",\n  evmhogsmian_3 =\t\"100005adRRR\",\n  evmhogsmfan_3 =\t\"100005afRRR\",\n  evmwlusianw_3 =\t\"100005c0RRR\",\n  evmwlssianw_3 =\t\"100005c1RRR\",\n  evmwlumianw_3 =\t\"100005c8RRR\",\n  evmwlsmianw_3 =\t\"100005c9RRR\",\n\n  -- NYI: Book E instructions.\n}\n\n-- Add mnemonics for \".\" variants.\ndo\n  local t = {}\n  for k,v in pairs(map_op) do\n    if type(v) == \"string\" and sub(v, -1) == \".\" then\n      local v2 = sub(v, 1, 7)..char(byte(v, 8)+1)..sub(v, 9, -2)\n      t[sub(k, 1, -3)..\".\"..sub(k, -2)] = v2\n    end\n  end\n  for k,v in pairs(t) do\n    map_op[k] = v\n  end\nend\n\n-- Add more branch mnemonics.\nfor cond,c in pairs(map_cond) do\n  local b1 = \"b\"..cond\n  local c1 = shl(band(c, 3), 16) + (c < 4 and 0x01000000 or 0)\n  -- bX[l]\n  map_op[b1..\"_1\"] = tohex(0x40800000 + c1)..\"K\"\n  map_op[b1..\"y_1\"] = tohex(0x40a00000 + c1)..\"K\"\n  map_op[b1..\"l_1\"] = tohex(0x40800001 + c1)..\"K\"\n  map_op[b1..\"_2\"] = tohex(0x40800000 + c1)..\"-XK\"\n  map_op[b1..\"y_2\"] = tohex(0x40a00000 + c1)..\"-XK\"\n  map_op[b1..\"l_2\"] = tohex(0x40800001 + c1)..\"-XK\"\n  -- bXlr[l]\n  map_op[b1..\"lr_0\"] = tohex(0x4c800020 + c1)\n  map_op[b1..\"lrl_0\"] = tohex(0x4c800021 + c1)\n  map_op[b1..\"ctr_0\"] = tohex(0x4c800420 + c1)\n  map_op[b1..\"ctrl_0\"] = tohex(0x4c800421 + c1)\n  -- bXctr[l]\n  map_op[b1..\"lr_1\"] = tohex(0x4c800020 + c1)..\"-X\"\n  map_op[b1..\"lrl_1\"] = tohex(0x4c800021 + c1)..\"-X\"\n  map_op[b1..\"ctr_1\"] = tohex(0x4c800420 + c1)..\"-X\"\n  map_op[b1..\"ctrl_1\"] = tohex(0x4c800421 + c1)..\"-X\"\nend\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r[1-3]?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_fpr(expr)\n  local r = match(expr, \"^f([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_vr(expr)\n  local r = match(expr, \"^v([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_vs(expr)\n  local r = match(expr, \"^vs([1-6]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 63 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_cr(expr)\n  local r = match(expr, \"^cr([0-7])$\")\n  if r then return tonumber(r) end\n  werror(\"bad condition register name `\"..expr..\"'\")\nend\n\nlocal function parse_cond(expr)\n  local r, cond = match(expr, \"^4%*cr([0-7])%+(%w%w)$\")\n  if r then\n    r = tonumber(r)\n    local c = map_cond[cond]\n    if c and c < 4 then return r*4+c end\n  end\n  werror(\"bad condition bit name `\"..expr..\"'\")\nend\n\nlocal parse_ctx = {}\n\nlocal loadenv = setfenv and function(s)\n  local code = loadstring(s, \"\")\n  if code then setfenv(code, parse_ctx) end\n  return code\nend or function(s)\n  return load(s, \"\", nil, parse_ctx)\nend\n\n-- Try to parse simple arithmetic, too, since some basic ops are aliases.\nlocal function parse_number(n)\n  local x = tonumber(n)\n  if x then return x end\n  local code = loadenv(\"return \"..n)\n  if code then\n    local ok, y = pcall(code)\n    if ok then return y end\n  end\n  return nil\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^[rfv]([1-3]?[0-9])$\") or\n\t match(imm, \"^vs([1-6]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r[1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_shiftmask(imm, isshift)\n  local n = parse_number(imm)\n  if n then\n    if shr(n, 6) == 0 then\n      local lsb = band(n, 31)\n      local msb = n - lsb\n      return isshift and (shl(lsb, 11)+shr(msb, 4)) or (shl(lsb, 6)+msb)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^r([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r[1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMMSH\", isshift and 1 or 0, imm)\n    return 0;\n  end\nend\n\nlocal function parse_disp(disp)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    return shl(r, 16) + parse_imm(imm, 16, 0, 0, true)\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    if tp then\n      waction(\"IMM\", 32768+16*32, format(tp.ctypefmt, tailr))\n      return shl(r, 16)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_u5disp(disp, scale)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    return shl(r, 16) + parse_imm(imm, 5, 11, scale, false)\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    if tp then\n      waction(\"IMM\", scale*1024+5*32+11, format(tp.ctypefmt, tailr))\n      return shl(r, 16)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nop_template = function(params, template, nparams)\n  if not params then return sub(template, 9) end\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n, rs = 1, 26\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 3 positions (rlwinm).\n  if secpos+3 > maxsecpos then wflush() end\n  local pos = wpos()\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    if p == \"R\" then\n      rs = rs - 5; op = op + shl(parse_gpr(params[n]), rs); n = n + 1\n    elseif p == \"F\" then\n      rs = rs - 5; op = op + shl(parse_fpr(params[n]), rs); n = n + 1\n    elseif p == \"V\" then\n      rs = rs - 5; op = op + shl(parse_vr(params[n]), rs); n = n + 1\n    elseif p == \"Q\" then\n      local vs = parse_vs(params[n]); n = n + 1; rs = rs - 5\n      local sh = rs == 6 and 2 or 3 + band(shr(rs, 1), 3)\n      op = op + shl(band(vs, 31), rs) + shr(band(vs, 32), sh)\n    elseif p == \"q\" then\n      local vs = parse_vs(params[n]); n = n + 1\n      op = op + shl(band(vs, 31), 21) + shr(band(vs, 32), 5)\n    elseif p == \"A\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, false); n = n + 1\n    elseif p == \"S\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, true); n = n + 1\n    elseif p == \"I\" then\n      op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1\n    elseif p == \"U\" then\n      op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1\n    elseif p == \"D\" then\n      op = op + parse_disp(params[n]); n = n + 1\n    elseif p == \"2\" then\n      op = op + parse_u5disp(params[n], 1); n = n + 1\n    elseif p == \"4\" then\n      op = op + parse_u5disp(params[n], 2); n = n + 1\n    elseif p == \"8\" then\n      op = op + parse_u5disp(params[n], 3); n = n + 1\n    elseif p == \"C\" then\n      rs = rs - 5; op = op + shl(parse_cond(params[n]), rs); n = n + 1\n    elseif p == \"X\" then\n      rs = rs - 5; op = op + shl(parse_cr(params[n]), rs+2); n = n + 1\n    elseif p == \"1\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs, 0, false); n = n + 1\n    elseif p == \"g\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs, 0, false); n = n + 1\n    elseif p == \"3\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 3, rs, 0, false); n = n + 1\n    elseif p == \"P\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 4, rs, 0, false); n = n + 1\n    elseif p == \"p\" then\n      op = op + parse_imm(params[n], 4, rs, 0, false); n = n + 1\n    elseif p == \"6\" then\n      rs = rs - 6; op = op + parse_imm(params[n], 6, rs, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs+4, 0, false); n = n + 1\n    elseif p == \"y\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs+3, 0, false); n = n + 1\n    elseif p == \"Z\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs+3, 0, false); n = n + 1\n    elseif p == \"z\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs+2, 0, false); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_cr(params[n]); n = n + 1\n    elseif p == \"G\" then\n      op = op + parse_imm(params[n], 8, 12, 0, false); n = n + 1\n    elseif p == \"H\" then\n      op = op + parse_shiftmask(params[n], true); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_shiftmask(params[n], false); n = n + 1\n    elseif p == \"J\" or p == \"K\" then\n      local mode, n, s = parse_label(params[n], false)\n      if p == \"K\" then n = n + 2048 end\n      waction(\"REL_\"..mode, n, s, 1)\n      n = n + 1\n    elseif p == \"0\" then\n      if band(shr(op, rs), 31) == 0 then werror(\"cannot use r0\") end\n    elseif p == \"=\" or p == \"%\" then\n      local t = band(shr(op, p == \"%\" and rs+5 or rs), 31)\n      rs = rs - 5\n      op = op + shl(t, rs)\n    elseif p == \"~\" then\n      local mm = shl(31, rs)\n      local lo = band(op, mm)\n      local hi = band(op, shl(mm, 5))\n      op = op - lo - hi + shl(lo, 5) + shr(hi, 5)\n    elseif p == \":\" then\n      if band(shr(op, rs), 1) ~= 0 then werror(\"register pair expected\") end\n    elseif p == \"-\" then\n      rs = rs - 5\n    elseif p == \".\" then\n      -- Ignored.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nmap_op[\".template__\"] = op_template\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_proto.h",
    "content": "/*\n** DynASM encoding engine prototypes.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#ifndef _DASM_PROTO_H\n#define _DASM_PROTO_H\n\n#include <stddef.h>\n#include <stdarg.h>\n\n#define DASM_IDENT\t\"DynASM 1.4.0\"\n#define DASM_VERSION\t10400\t/* 1.4.0 */\n\n#ifndef Dst_DECL\n#define Dst_DECL\tdasm_State **Dst\n#endif\n\n#ifndef Dst_REF\n#define Dst_REF\t\t(*Dst)\n#endif\n\n#ifndef DASM_FDEF\n#define DASM_FDEF\textern\n#endif\n\n#ifndef DASM_M_GROW\n#define DASM_M_GROW(ctx, t, p, sz, need) \\\n  do { \\\n    size_t _sz = (sz), _need = (need); \\\n    if (_sz < _need) { \\\n      if (_sz < 16) _sz = 16; \\\n      while (_sz < _need) _sz += _sz; \\\n      (p) = (t *)realloc((p), _sz); \\\n      if ((p) == NULL) exit(1); \\\n      (sz) = _sz; \\\n    } \\\n  } while(0)\n#endif\n\n#ifndef DASM_M_FREE\n#define DASM_M_FREE(ctx, p, sz)\tfree(p)\n#endif\n\n/* Internal DynASM encoder state. */\ntypedef struct dasm_State dasm_State;\n\n\n/* Initialize and free DynASM state. */\nDASM_FDEF void dasm_init(Dst_DECL, int maxsection);\nDASM_FDEF void dasm_free(Dst_DECL);\n\n/* Setup global array. Must be called before dasm_setup(). */\nDASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nDASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);\n\n/* Setup encoder. */\nDASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);\n\n/* Feed encoder with actions. Calls are generated by pre-processor. */\nDASM_FDEF void dasm_put(Dst_DECL, int start, ...);\n\n/* Link sections and return the resulting size. */\nDASM_FDEF int dasm_link(Dst_DECL, size_t *szp);\n\n/* Encode sections into buffer. */\nDASM_FDEF int dasm_encode(Dst_DECL, void *buffer);\n\n/* Get PC label offset. */\nDASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nDASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);\n#else\n#define dasm_checkstep(a, b)\t0\n#endif\n\n\n#endif /* _DASM_PROTO_H */\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_x64.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM x64 module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n-- This module just sets 64 bit mode for the combined x86/x64 module.\n-- All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nx64 = true -- Using a global is an ugly, but effective solution.\nreturn require(\"dasm_x86\")\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_x86.h",
    "content": "/*\n** DynASM x86 encoding engine.\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"x86\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. DASM_STOP must be 255. */\nenum {\n  DASM_DISP = 233,\n  DASM_IMM_S, DASM_IMM_B, DASM_IMM_W, DASM_IMM_D, DASM_IMM_WB, DASM_IMM_DB,\n  DASM_VREG, DASM_SPACE, DASM_SETLABEL, DASM_REL_A, DASM_REL_LG, DASM_REL_PC,\n  DASM_IMM_LG, DASM_IMM_PC, DASM_LABEL_LG, DASM_LABEL_PC, DASM_ALIGN,\n  DASM_EXTERN, DASM_ESC, DASM_MARK, DASM_SECTION, DASM_STOP\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_VREG\t0x15000000\n#define DASM_S_UNDEF_L\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned char *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status=DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs, mrm = -1;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    int action = *p++;\n    if (action < DASM_DISP) {\n      ofs++;\n    } else if (action <= DASM_REL_A) {\n      int n = va_arg(ap, int);\n      b[pos++] = n;\n      switch (action) {\n      case DASM_DISP:\n\tif (n == 0) { if (mrm < 0) mrm = p[-2]; if ((mrm&7) != 5) break; }\n      case DASM_IMM_DB: if (((n+128)&-256) == 0) goto ob;\n      case DASM_REL_A: /* Assumes ptrdiff_t is int. !x64 */\n      case DASM_IMM_D: ofs += 4; break;\n      case DASM_IMM_S: CK(((n+128)&-256) == 0, RANGE_I); goto ob;\n      case DASM_IMM_B: CK((n&-256) == 0, RANGE_I); ob: ofs++; break;\n      case DASM_IMM_WB: if (((n+128)&-256) == 0) goto ob;\n      case DASM_IMM_W: CK((n&-65536) == 0, RANGE_I); ofs += 2; break;\n      case DASM_SPACE: p++; ofs += n; break;\n      case DASM_SETLABEL: b[pos-2] = -0x40000000; break;  /* Neg. label ofs. */\n      case DASM_VREG: CK((n&-16) == 0 && (n != 4 || (*p>>5) != 2), RANGE_VREG);\n\tif (*p < 0x40 && p[1] == DASM_DISP) mrm = n;\n\tif (*p < 0x20 && (n&7) == 4) ofs++;\n\tswitch ((*p++ >> 3) & 3) {\n\tcase 3: n |= b[pos-3];\n\tcase 2: n |= b[pos-2];\n\tcase 1: if (n <= 7) { b[pos-1] |= 0x10; ofs--; }\n\t}\n\tcontinue;\n      }\n      mrm = -1;\n    } else {\n      int *pl, n;\n      switch (action) {\n      case DASM_REL_LG:\n      case DASM_IMM_LG:\n\tn = *p++; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n <= 246) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl -= 246; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n      case DASM_IMM_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tofs += 4;  /* Maximum offset needed. */\n\tif (action == DASM_REL_LG || action == DASM_REL_PC)\n\t  b[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; }\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_ALIGN:\n\tofs += *p++;  /* Maximum alignment needed (arg is 2**n-1). */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_EXTERN: p += 2; ofs += 4; break;\n      case DASM_ESC: p++; ofs++; break;\n      case DASM_MARK: mrm = p[-2]; break;\n      case DASM_SECTION:\n\tn = *p; CK(n < D->maxsection, RANGE_SEC); D->section = &D->sections[n];\n      case DASM_STOP: goto stop;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink branches/aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tint op, action = *p++;\n\tswitch (action) {\n\tcase DASM_REL_LG: p++; op = p[-3]; goto rel_pc;\n\tcase DASM_REL_PC: op = p[-2]; rel_pc: {\n\t  int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0);\n\t  if (shrink) {  /* Shrinkable branch opcode? */\n\t    int lofs, lpos = b[pos];\n\t    if (lpos < 0) goto noshrink;  /* Ext global? */\n\t    lofs = *DASM_POS2PTR(D, lpos);\n\t    if (lpos > pos) {  /* Fwd label: add cumulative section offsets. */\n\t      int i;\n\t      for (i = secnum; i < DASM_POS2SEC(lpos); i++)\n\t\tlofs += D->sections[i].ofs;\n\t    } else {\n\t      lofs -= ofs;  /* Bkwd label: unfix offset. */\n\t    }\n\t    lofs -= b[pos+1];  /* Short branch ok? */\n\t    if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink;  /* Yes. */\n\t    else { noshrink: shrink = 0; }  /* No, cannot shrink op. */\n\t  }\n\t  b[pos+1] = shrink;\n\t  pos += 2;\n\t  break;\n\t}\n\tcase DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++;\n\tcase DASM_DISP: case DASM_IMM_S: case DASM_IMM_B: case DASM_IMM_W:\n\tcase DASM_IMM_D: case DASM_IMM_WB: case DASM_IMM_DB:\n\tcase DASM_SETLABEL: case DASM_REL_A: case DASM_IMM_PC: pos++; break;\n\tcase DASM_LABEL_LG: p++;\n\tcase DASM_LABEL_PC: b[pos++] += ofs; break; /* Fix label offset. */\n\tcase DASM_ALIGN: ofs -= (b[pos++]+ofs)&*p++; break; /* Adjust ofs. */\n\tcase DASM_EXTERN: p += 2; break;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_MARK: break;\n\tcase DASM_SECTION: case DASM_STOP: goto stop;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#define dasmb(x)\t*cp++ = (unsigned char)(x)\n#ifndef DASM_ALIGNED_WRITES\n#define dasmw(x) \\\n  do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0)\n#define dasmd(x) \\\n  do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0)\n#else\n#define dasmw(x)\tdo { dasmb(x); dasmb((x)>>8); } while (0)\n#define dasmd(x)\tdo { dasmw(x); dasmw((x)>>16); } while (0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  unsigned char *base = (unsigned char *)buffer;\n  unsigned char *cp = base;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      unsigned char *mark = NULL;\n      while (1) {\n\tint action = *p++;\n\tint n = (action >= DASM_DISP && action <= DASM_ALIGN) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_DISP: if (!mark) mark = cp; {\n\t  unsigned char *mm = mark;\n\t  if (*p != DASM_IMM_DB && *p != DASM_IMM_WB) mark = NULL;\n\t  if (n == 0) { int mrm = mm[-1]&7; if (mrm == 4) mrm = mm[0]&7;\n\t    if (mrm != 5) { mm[-1] -= 0x80; break; } }\n\t  if (((n+128) & -256) != 0) goto wd; else mm[-1] -= 0x40;\n\t}\n\tcase DASM_IMM_S: case DASM_IMM_B: wb: dasmb(n); break;\n\tcase DASM_IMM_DB: if (((n+128)&-256) == 0) {\n\t    db: if (!mark) mark = cp; mark[-2] += 2; mark = NULL; goto wb;\n\t  } else mark = NULL;\n\tcase DASM_IMM_D: wd: dasmd(n); break;\n\tcase DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL;\n\tcase DASM_IMM_W: dasmw(n); break;\n\tcase DASM_VREG: {\n\t  int t = *p++;\n\t  unsigned char *ex = cp - (t&7);\n\t  if ((n & 8) && t < 0xa0) {\n\t    if (*ex & 0x80) ex[1] ^= 0x20 << (t>>6); else *ex ^= 1 << (t>>6);\n\t    n &= 7;\n\t  } else if (n & 0x10) {\n\t    if (*ex & 0x80) {\n\t      *ex = 0xc5; ex[1] = (ex[1] & 0x80) | ex[2]; ex += 2;\n\t    }\n\t    while (++ex < cp) ex[-1] = *ex;\n\t    if (mark) mark--;\n\t    cp--;\n\t    n &= 7;\n\t  }\n\t  if (t >= 0xc0) n <<= 4;\n\t  else if (t >= 0x40) n <<= 3;\n\t  else if (n == 4 && t < 0x20) { cp[-1] ^= n; *cp++ = 0x20; }\n\t  cp[-1] ^= n;\n\t  break;\n\t}\n\tcase DASM_REL_LG: p++; if (n >= 0) goto rel_pc;\n\t  b++; n = (int)(ptrdiff_t)D->globals[-n];\n\tcase DASM_REL_A: rel_a: n -= (int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */\n\tcase DASM_REL_PC: rel_pc: {\n\t  int shrink = *b++;\n\t  int *pb = DASM_POS2PTR(D, n); if (*pb < 0) { n = pb[1]; goto rel_a; }\n\t  n = *pb - ((int)(cp-base) + 4-shrink);\n\t  if (shrink == 0) goto wd;\n\t  if (shrink == 4) { cp--; cp[-1] = *cp-0x10; } else cp[-1] = 0xeb;\n\t  goto wb;\n\t}\n\tcase DASM_IMM_LG:\n\t  p++; if (n < 0) { n = (int)(ptrdiff_t)D->globals[-n]; goto wd; }\n\tcase DASM_IMM_PC: {\n\t  int *pb = DASM_POS2PTR(D, n);\n\t  n = *pb < 0 ? pb[1] : (*pb + (int)(ptrdiff_t)base);\n\t  goto wd;\n\t}\n\tcase DASM_LABEL_LG: {\n\t  int idx = *p++;\n\t  if (idx >= 10)\n\t    D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));\n\t  break;\n\t}\n\tcase DASM_LABEL_PC: case DASM_SETLABEL: break;\n\tcase DASM_SPACE: { int fill = *p++; while (n--) *cp++ = fill; break; }\n\tcase DASM_ALIGN:\n\t  n = *p++;\n\t  while (((cp-base) & n)) *cp++ = 0x90; /* nop */\n\t  break;\n\tcase DASM_EXTERN: n = DASM_EXTERN(Dst, cp, p[1], *p); p += 2; goto wd;\n\tcase DASM_MARK: mark = cp; break;\n\tcase DASM_ESC: action = *p++;\n\tdefault: *cp++ = action; break;\n\tcase DASM_SECTION: case DASM_STOP: goto stop;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_L|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dasm_x86.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM x86/x64 module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\nlocal x64 = x64\n\n-- Module information:\nlocal _info = {\n  arch =\tx64 and \"x64\" or \"x86\",\n  description =\t\"DynASM x86/x64 module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, unpack, setmetatable = assert, unpack or table.unpack, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal find, match, gmatch, gsub = _s.find, _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, remove = table.concat, table.sort, table.remove\nlocal bit = bit or require(\"bit\")\nlocal band, bxor, shl, shr = bit.band, bit.bxor, bit.lshift, bit.rshift\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  -- int arg, 1 buffer pos:\n  \"DISP\",  \"IMM_S\", \"IMM_B\", \"IMM_W\", \"IMM_D\",  \"IMM_WB\", \"IMM_DB\",\n  -- action arg (1 byte), int arg, 1 buffer pos (reg/num):\n  \"VREG\", \"SPACE\",\n  -- ptrdiff_t arg, 1 buffer pos (address): !x64\n  \"SETLABEL\", \"REL_A\",\n  -- action arg (1 byte) or int arg, 2 buffer pos (link, offset):\n  \"REL_LG\", \"REL_PC\",\n  -- action arg (1 byte) or int arg, 1 buffer pos (link):\n  \"IMM_LG\", \"IMM_PC\",\n  -- action arg (1 byte) or int arg, 1 buffer pos (offset):\n  \"LABEL_LG\", \"LABEL_PC\",\n  -- action arg (1 byte), 1 buffer pos (offset):\n  \"ALIGN\",\n  -- action args (2 bytes), no buffer pos.\n  \"EXTERN\",\n  -- action arg (1 byte), no buffer pos.\n  \"ESC\",\n  -- no action arg, no buffer pos.\n  \"MARK\",\n  -- action arg (1 byte), no buffer pos, terminal action:\n  \"SECTION\",\n  -- no args, no buffer pos, terminal action:\n  \"STOP\"\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number (dynamically generated below).\nlocal map_action = {}\n-- First action number. Everything below does not need to be escaped.\nlocal actfirst = 256-#action_names\n\n-- Action list buffer and string (only used to remove dupes).\nlocal actlist = {}\nlocal actstr = \"\"\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n-- VREG kind encodings, pre-shifted by 5 bits.\nlocal map_vreg = {\n  [\"modrm.rm.m\"] = 0x00,\n  [\"modrm.rm.r\"] = 0x20,\n  [\"opcode\"] =     0x20,\n  [\"sib.base\"] =   0x20,\n  [\"sib.index\"] =  0x40,\n  [\"modrm.reg\"] =  0x80,\n  [\"vex.v\"] =      0xa0,\n  [\"imm.hi\"] =     0xc0,\n}\n\n-- Current number of VREG actions contributing to REX/VEX shrinkage.\nlocal vreg_shrink_count = 0\n\n------------------------------------------------------------------------------\n\n-- Compute action numbers for action names.\nfor n,name in ipairs(action_names) do\n  local num = actfirst + n - 1\n  map_action[name] = num\nend\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  local last = actlist[nn] or 255\n  actlist[nn] = nil -- Remove last byte.\n  if nn == 0 then nn = 1 end\n  out:write(\"static const unsigned char \", name, \"[\", nn, \"] = {\\n\")\n  local s = \"  \"\n  for n,b in ipairs(actlist) do\n    s = s..b..\",\"\n    if #s >= 75 then\n      assert(out:write(s, \"\\n\"))\n      s = \"  \"\n    end\n  end\n  out:write(s, last, \"\\n};\\n\\n\") -- Add last byte back.\nend\n\n------------------------------------------------------------------------------\n\n-- Add byte to action list.\nlocal function wputxb(n)\n  assert(n >= 0 and n <= 255 and n % 1 == 0, \"byte out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, a, num)\n  wputxb(assert(map_action[action], \"bad action name `\"..action..\"'\"))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Optionally add a VREG action.\nlocal function wvreg(kind, vreg, psz, sk, defer)\n  if not vreg then return end\n  waction(\"VREG\", vreg)\n  local b = assert(map_vreg[kind], \"bad vreg kind `\"..vreg..\"'\")\n  if b < (sk or 0) then\n    vreg_shrink_count = vreg_shrink_count + 1\n  end\n  if not defer then\n    b = b + vreg_shrink_count * 8\n    vreg_shrink_count = 0\n  end\n  wputxb(b + (psz or 0))\nend\n\n-- Add call to embedded DynASM C code.\nlocal function wcall(func, args)\n  wline(format(\"dasm_%s(Dst, %s);\", func, concat(args, \", \")), true)\nend\n\n-- Delete duplicate action list chunks. A tad slow, but so what.\nlocal function dedupechunk(offset)\n  local al, as = actlist, actstr\n  local chunk = char(unpack(al, offset+1, #al))\n  local orig = find(as, chunk, 1, true)\n  if orig then\n    actargs[1] = orig-1 -- Replace with original offset.\n    for i=offset+1,#al do al[i] = nil end -- Kill dupe.\n  else\n    actstr = as..chunk\n  end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  local offset = actargs[1]\n  if #actlist == offset then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  dedupechunk(offset)\n  wcall(\"put\", actargs) -- Add call to dasm_put().\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped byte.\nlocal function wputb(n)\n  if n >= actfirst then waction(\"ESC\") end -- Need to escape byte.\n  wputxb(n)\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 10\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_@]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 246 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=10,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=10,next_global-1 do\n    out:write(\"  \", prefix, gsub(t[i], \"@.*\", \"\"), \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=10,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = -1\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n < -256 then werror(\"too many extern labels\") end\n  next_extern = n - 1\n  t[name] = n\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  local t = {}\n  for name, n in pairs(map_extern) do t[-n] = name end\n  out:write(\"Extern labels:\\n\")\n  for i=1,-next_extern-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  local t = {}\n  for name, n in pairs(map_extern) do t[-n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=1,-next_extern-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = {}\t\t-- Ext. register name -> int. name.\nlocal map_reg_rev = {}\t\t-- Int. register name -> ext. name.\nlocal map_reg_num = {}\t\t-- Int. register name -> register number.\nlocal map_reg_opsize = {}\t-- Int. register name -> operand size.\nlocal map_reg_valid_base = {}\t-- Int. register name -> valid base register?\nlocal map_reg_valid_index = {}\t-- Int. register name -> valid index register?\nlocal map_reg_needrex = {}\t-- Int. register name -> need rex vs. no rex.\nlocal reg_list = {}\t\t-- Canonical list of int. register names.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for _PTx macros).\n\nlocal addrsize = x64 and \"q\" or \"d\"\t-- Size for address operands.\n\n-- Helper functions to fill register maps.\nlocal function mkrmap(sz, cl, names)\n  local cname = format(\"@%s\", sz)\n  reg_list[#reg_list+1] = cname\n  map_archdef[cl] = cname\n  map_reg_rev[cname] = cl\n  map_reg_num[cname] = -1\n  map_reg_opsize[cname] = sz\n  if sz == addrsize or sz == \"d\" then\n    map_reg_valid_base[cname] = true\n    map_reg_valid_index[cname] = true\n  end\n  if names then\n    for n,name in ipairs(names) do\n      local iname = format(\"@%s%x\", sz, n-1)\n      reg_list[#reg_list+1] = iname\n      map_archdef[name] = iname\n      map_reg_rev[iname] = name\n      map_reg_num[iname] = n-1\n      map_reg_opsize[iname] = sz\n      if sz == \"b\" and n > 4 then map_reg_needrex[iname] = false end\n      if sz == addrsize or sz == \"d\" then\n\tmap_reg_valid_base[iname] = true\n\tmap_reg_valid_index[iname] = true\n      end\n    end\n  end\n  for i=0,(x64 and sz ~= \"f\") and 15 or 7 do\n    local needrex = sz == \"b\" and i > 3\n    local iname = format(\"@%s%x%s\", sz, i, needrex and \"R\" or \"\")\n    if needrex then map_reg_needrex[iname] = true end\n    local name\n    if sz == \"o\" or sz == \"y\" then name = format(\"%s%d\", cl, i)\n    elseif sz == \"f\" then name = format(\"st%d\", i)\n    else name = format(\"r%d%s\", i, sz == addrsize and \"\" or sz) end\n    map_archdef[name] = iname\n    if not map_reg_rev[iname] then\n      reg_list[#reg_list+1] = iname\n      map_reg_rev[iname] = name\n      map_reg_num[iname] = i\n      map_reg_opsize[iname] = sz\n      if sz == addrsize or sz == \"d\" then\n\tmap_reg_valid_base[iname] = true\n\tmap_reg_valid_index[iname] = true\n      end\n    end\n  end\n  reg_list[#reg_list+1] = \"\"\nend\n\n-- Integer registers (qword, dword, word and byte sized).\nif x64 then\n  mkrmap(\"q\", \"Rq\", {\"rax\", \"rcx\", \"rdx\", \"rbx\", \"rsp\", \"rbp\", \"rsi\", \"rdi\"})\nend\nmkrmap(\"d\", \"Rd\", {\"eax\", \"ecx\", \"edx\", \"ebx\", \"esp\", \"ebp\", \"esi\", \"edi\"})\nmkrmap(\"w\", \"Rw\", {\"ax\", \"cx\", \"dx\", \"bx\", \"sp\", \"bp\", \"si\", \"di\"})\nmkrmap(\"b\", \"Rb\", {\"al\", \"cl\", \"dl\", \"bl\", \"ah\", \"ch\", \"dh\", \"bh\"})\nmap_reg_valid_index[map_archdef.esp] = false\nif x64 then map_reg_valid_index[map_archdef.rsp] = false end\nif x64 then map_reg_needrex[map_archdef.Rb] = true end\nmap_archdef[\"Ra\"] = \"@\"..addrsize\n\n-- FP registers (internally tword sized, but use \"f\" as operand size).\nmkrmap(\"f\", \"Rf\")\n\n-- SSE registers (oword sized, but qword and dword accessible).\nmkrmap(\"o\", \"xmm\")\n\n-- AVX registers (yword sized, but oword, qword and dword accessible).\nmkrmap(\"y\", \"ymm\")\n\n-- Operand size prefixes to codes.\nlocal map_opsize = {\n  byte = \"b\", word = \"w\", dword = \"d\", qword = \"q\", oword = \"o\", yword = \"y\",\n  tword = \"t\", aword = addrsize,\n}\n\n-- Operand size code to number.\nlocal map_opsizenum = {\n  b = 1, w = 2, d = 4, q = 8, o = 16, y = 32, t = 10,\n}\n\n-- Operand size code to name.\nlocal map_opsizename = {\n  b = \"byte\", w = \"word\", d = \"dword\", q = \"qword\", o = \"oword\", y = \"yword\",\n  t = \"tword\", f = \"fpword\",\n}\n\n-- Valid index register scale factors.\nlocal map_xsc = {\n  [\"1\"] = 0, [\"2\"] = 1, [\"4\"] = 2, [\"8\"] = 3,\n}\n\n-- Condition codes.\nlocal map_cc = {\n  o = 0, no = 1, b = 2, nb = 3, e = 4, ne = 5, be = 6, nbe = 7,\n  s = 8, ns = 9, p = 10, np = 11, l = 12, nl = 13, le = 14, nle = 15,\n  c = 2, nae = 2, nc = 3, ae = 3, z = 4, nz = 5, na = 6, a = 7,\n  pe = 10, po = 11, nge = 12, ge = 13, ng = 14, g = 15,\n}\n\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return gsub(s, \"@%w+\", map_reg_rev)\nend\n\n-- Dump register names and numbers\nlocal function dumpregs(out)\n  out:write(\"Register names, sizes and internal numbers:\\n\")\n  for _,reg in ipairs(reg_list) do\n    if reg == \"\" then\n      out:write(\"\\n\")\n    else\n      local name = map_reg_rev[reg]\n      local num = map_reg_num[reg]\n      local opsize = map_opsizename[map_reg_opsize[reg]]\n      out:write(format(\"  %-5s %-8s %s\\n\", name, opsize,\n\t\t       num < 0 and \"(variable)\" or num))\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Put action for label arg (IMM_LG, IMM_PC, REL_LG, REL_PC).\nlocal function wputlabel(aprefix, imm, num)\n  if type(imm) == \"number\" then\n    if imm < 0 then\n      waction(\"EXTERN\")\n      wputxb(aprefix == \"IMM_\" and 0 or 1)\n      imm = -imm-1\n    else\n      waction(aprefix..\"LG\", nil, num);\n    end\n    wputxb(imm)\n  else\n    waction(aprefix..\"PC\", imm, num)\n  end\nend\n\n-- Put signed byte or arg.\nlocal function wputsbarg(n)\n  if type(n) == \"number\" then\n    if n < -128 or n > 127 then\n      werror(\"signed immediate byte out of range\")\n    end\n    if n < 0 then n = n + 256 end\n    wputb(n)\n  else waction(\"IMM_S\", n) end\nend\n\n-- Put unsigned byte or arg.\nlocal function wputbarg(n)\n  if type(n) == \"number\" then\n    if n < 0 or n > 255 then\n      werror(\"unsigned immediate byte out of range\")\n    end\n    wputb(n)\n  else waction(\"IMM_B\", n) end\nend\n\n-- Put unsigned word or arg.\nlocal function wputwarg(n)\n  if type(n) == \"number\" then\n    if shr(n, 16) ~= 0 then\n      werror(\"unsigned immediate word out of range\")\n    end\n    wputb(band(n, 255)); wputb(shr(n, 8));\n  else waction(\"IMM_W\", n) end\nend\n\n-- Put signed or unsigned dword or arg.\nlocal function wputdarg(n)\n  local tn = type(n)\n  if tn == \"number\" then\n    wputb(band(n, 255))\n    wputb(band(shr(n, 8), 255))\n    wputb(band(shr(n, 16), 255))\n    wputb(shr(n, 24))\n  elseif tn == \"table\" then\n    wputlabel(\"IMM_\", n[1], 1)\n  else\n    waction(\"IMM_D\", n)\n  end\nend\n\n-- Put operand-size dependent number or arg (defaults to dword).\nlocal function wputszarg(sz, n)\n  if not sz or sz == \"d\" or sz == \"q\" then wputdarg(n)\n  elseif sz == \"w\" then wputwarg(n)\n  elseif sz == \"b\" then wputbarg(n)\n  elseif sz == \"s\" then wputsbarg(n)\n  else werror(\"bad operand size\") end\nend\n\n-- Put multi-byte opcode with operand-size dependent modifications.\nlocal function wputop(sz, op, rex, vex, vregr, vregxb)\n  local psz, sk = 0, nil\n  if vex then\n    local tail\n    if vex.m == 1 and band(rex, 11) == 0 then\n      if x64 and vregxb then\n\tsk = map_vreg[\"modrm.reg\"]\n      else\n\twputb(0xc5)\n      tail = shl(bxor(band(rex, 4), 4), 5)\n      psz = 3\n      end\n    end\n    if not tail then\n      wputb(0xc4)\n      wputb(shl(bxor(band(rex, 7), 7), 5) + vex.m)\n      tail = shl(band(rex, 8), 4)\n      psz = 4\n    end\n    local reg, vreg = 0, nil\n    if vex.v then\n      reg = vex.v.reg\n      if not reg then werror(\"bad vex operand\") end\n      if reg < 0 then reg = 0; vreg = vex.v.vreg end\n    end\n    if sz == \"y\" or vex.l then tail = tail + 4 end\n    wputb(tail + shl(bxor(reg, 15), 3) + vex.p)\n    wvreg(\"vex.v\", vreg)\n    rex = 0\n    if op >= 256 then werror(\"bad vex opcode\") end\n  else\n    if rex ~= 0 then\n      if not x64 then werror(\"bad operand size\") end\n    elseif (vregr or vregxb) and x64 then\n      rex = 0x10\n      sk = map_vreg[\"vex.v\"]\n    end\n  end\n  local r\n  if sz == \"w\" then wputb(102) end\n  -- Needs >32 bit numbers, but only for crc32 eax, word [ebx]\n  if op >= 4294967296 then r = op%4294967296 wputb((op-r)/4294967296) op = r end\n  if op >= 16777216 then wputb(shr(op, 24)); op = band(op, 0xffffff) end\n  if op >= 65536 then\n    if rex ~= 0 then\n      local opc3 = band(op, 0xffff00)\n      if opc3 == 0x0f3a00 or opc3 == 0x0f3800 then\n\twputb(64 + band(rex, 15)); rex = 0; psz = 2\n      end\n    end\n    wputb(shr(op, 16)); op = band(op, 0xffff); psz = psz + 1\n  end\n  if op >= 256 then\n    local b = shr(op, 8)\n    if b == 15 and rex ~= 0 then wputb(64 + band(rex, 15)); rex = 0; psz = 2 end\n    wputb(b); op = band(op, 255); psz = psz + 1\n  end\n  if rex ~= 0 then wputb(64 + band(rex, 15)); psz = 2 end\n  if sz == \"b\" then op = op - 1 end\n  wputb(op)\n  return psz, sk\nend\n\n-- Put ModRM or SIB formatted byte.\nlocal function wputmodrm(m, s, rm, vs, vrm)\n  assert(m < 4 and s < 16 and rm < 16, \"bad modrm operands\")\n  wputb(shl(m, 6) + shl(band(s, 7), 3) + band(rm, 7))\nend\n\n-- Put ModRM/SIB plus optional displacement.\nlocal function wputmrmsib(t, imark, s, vsreg, psz, sk)\n  local vreg, vxreg\n  local reg, xreg = t.reg, t.xreg\n  if reg and reg < 0 then reg = 0; vreg = t.vreg end\n  if xreg and xreg < 0 then xreg = 0; vxreg = t.vxreg end\n  if s < 0 then s = 0 end\n\n  -- Register mode.\n  if sub(t.mode, 1, 1) == \"r\" then\n    wputmodrm(3, s, reg)\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vreg)\n    wvreg(\"modrm.rm.r\", vreg, psz+1, sk)\n    return\n  end\n\n  local disp = t.disp\n  local tdisp = type(disp)\n  -- No base register?\n  if not reg then\n    local riprel = false\n    if xreg then\n      -- Indexed mode with index register only.\n      -- [xreg*xsc+disp] -> (0, s, esp) (xsc, xreg, ebp)\n      wputmodrm(0, s, 4)\n      if imark == \"I\" then waction(\"MARK\") end\n      wvreg(\"modrm.reg\", vsreg, psz+1, sk, vxreg)\n      wputmodrm(t.xsc, xreg, 5)\n      wvreg(\"sib.index\", vxreg, psz+2, sk)\n    else\n      -- Pure 32 bit displacement.\n      if x64 and tdisp ~= \"table\" then\n\twputmodrm(0, s, 4) -- [disp] -> (0, s, esp) (0, esp, ebp)\n\twvreg(\"modrm.reg\", vsreg, psz+1, sk)\n\tif imark == \"I\" then waction(\"MARK\") end\n\twputmodrm(0, 4, 5)\n      else\n\triprel = x64\n\twputmodrm(0, s, 5) -- [disp|rip-label] -> (0, s, ebp)\n\twvreg(\"modrm.reg\", vsreg, psz+1, sk)\n\tif imark == \"I\" then waction(\"MARK\") end\n      end\n    end\n    if riprel then -- Emit rip-relative displacement.\n      if match(\"UWSiI\", imark) then\n\twerror(\"NYI: rip-relative displacement followed by immediate\")\n      end\n      -- The previous byte in the action buffer cannot be 0xe9 or 0x80-0x8f.\n      wputlabel(\"REL_\", disp[1], 2)\n    else\n      wputdarg(disp)\n    end\n    return\n  end\n\n  local m\n  if tdisp == \"number\" then -- Check displacement size at assembly time.\n    if disp == 0 and band(reg, 7) ~= 5 then -- [ebp] -> [ebp+0] (in SIB, too)\n      if not vreg then m = 0 end -- Force DISP to allow [Rd(5)] -> [ebp+0]\n    elseif disp >= -128 and disp <= 127 then m = 1\n    else m = 2 end\n  elseif tdisp == \"table\" then\n    m = 2\n  end\n\n  -- Index register present or esp as base register: need SIB encoding.\n  if xreg or band(reg, 7) == 4 then\n    wputmodrm(m or 2, s, 4) -- ModRM.\n    if m == nil or imark == \"I\" then waction(\"MARK\") end\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vxreg or vreg)\n    wputmodrm(t.xsc or 0, xreg or 4, reg) -- SIB.\n    wvreg(\"sib.index\", vxreg, psz+2, sk, vreg)\n    wvreg(\"sib.base\", vreg, psz+2, sk)\n  else\n    wputmodrm(m or 2, s, reg) -- ModRM.\n    if (imark == \"I\" and (m == 1 or m == 2)) or\n       (m == nil and (vsreg or vreg)) then waction(\"MARK\") end\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vreg)\n    wvreg(\"modrm.rm.m\", vreg, psz+1, sk)\n  end\n\n  -- Put displacement.\n  if m == 1 then wputsbarg(disp)\n  elseif m == 2 then wputdarg(disp)\n  elseif m == nil then waction(\"DISP\", disp) end\nend\n\n------------------------------------------------------------------------------\n\n-- Return human-readable operand mode string.\nlocal function opmodestr(op, args)\n  local m = {}\n  for i=1,#args do\n    local a = args[i]\n    m[#m+1] = sub(a.mode, 1, 1)..(a.opsize or \"?\")\n  end\n  return op..\" \"..concat(m, \",\")\nend\n\n-- Convert number to valid integer or nil.\nlocal function toint(expr)\n  local n = tonumber(expr)\n  if n then\n    if n % 1 ~= 0 or n < -2147483648 or n > 4294967295 then\n      werror(\"bad integer number `\"..expr..\"'\")\n    end\n    return n\n  end\nend\n\n-- Parse immediate expression.\nlocal function immexpr(expr)\n  -- &expr (pointer)\n  if sub(expr, 1, 1) == \"&\" then\n    return \"iPJ\", format(\"(ptrdiff_t)(%s)\", sub(expr,2))\n  end\n\n  local prefix = sub(expr, 1, 2)\n  -- =>expr (pc label reference)\n  if prefix == \"=>\" then\n    return \"iJ\", sub(expr, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"iJ\", map_global[sub(expr, 3)]\n  end\n\n  -- [<>][1-9] (local label reference)\n  local dir, lnum = match(expr, \"^([<>])([1-9])$\")\n  if dir then -- Fwd: 247-255, Bkwd: 1-9.\n    return \"iJ\", lnum + (dir == \">\" and 246 or 0)\n  end\n\n  local extname = match(expr, \"^extern%s+(%S+)$\")\n  if extname then\n    return \"iJ\", map_extern[extname]\n  end\n\n  -- expr (interpreted as immediate)\n  return \"iI\", expr\nend\n\n-- Parse displacement expression: +-num, +-expr, +-opsize*num\nlocal function dispexpr(expr)\n  local disp = expr == \"\" and 0 or toint(expr)\n  if disp then return disp end\n  local c, dispt = match(expr, \"^([+-])%s*(.+)$\")\n  if c == \"+\" then\n    expr = dispt\n  elseif not c then\n    werror(\"bad displacement expression `\"..expr..\"'\")\n  end\n  local opsize, tailops = match(dispt, \"^(%w+)%s*%*%s*(.+)$\")\n  local ops, imm = map_opsize[opsize], toint(tailops)\n  if ops and imm then\n    if c == \"-\" then imm = -imm end\n    return imm*map_opsizenum[ops]\n  end\n  local mode, iexpr = immexpr(dispt)\n  if mode == \"iJ\" then\n    if c == \"-\" then werror(\"cannot invert label reference\") end\n    return { iexpr }\n  end\n  return expr -- Need to return original signed expression.\nend\n\n-- Parse register or type expression.\nlocal function rtexpr(expr)\n  if not expr then return end\n  local tname, ovreg = match(expr, \"^([%w_]+):(@[%w_]+)$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    local rnum = map_reg_num[reg]\n    if not rnum then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    if not map_reg_valid_base[reg] then\n      werror(\"bad base register override `\"..(map_reg_rev[reg] or reg)..\"'\")\n    end\n    return reg, rnum, tp\n  end\n  return expr, map_reg_num[expr]\nend\n\n-- Parse operand and return { mode, opsize, reg, xreg, xsc, disp, imm }.\nlocal function parseoperand(param)\n  local t = {}\n\n  local expr = param\n  local opsize, tailops = match(param, \"^(%w+)%s*(.+)$\")\n  if opsize then\n    t.opsize = map_opsize[opsize]\n    if t.opsize then expr = tailops end\n  end\n\n  local br = match(expr, \"^%[%s*(.-)%s*%]$\")\n  repeat\n    if br then\n      t.mode = \"xm\"\n\n      -- [disp]\n      t.disp = toint(br)\n      if t.disp then\n\tt.mode = x64 and \"xm\" or \"xmO\"\n\tbreak\n      end\n\n      -- [reg...]\n      local tp\n      local reg, tailr = match(br, \"^([@%w_:]+)%s*(.*)$\")\n      reg, t.reg, tp = rtexpr(reg)\n      if not t.reg then\n\t-- [expr]\n\tt.mode = x64 and \"xm\" or \"xmO\"\n\tt.disp = dispexpr(\"+\"..br)\n\tbreak\n      end\n\n      if t.reg == -1 then\n\tt.vreg, tailr = match(tailr, \"^(%b())(.*)$\")\n\tif not t.vreg then werror(\"bad variable register expression\") end\n      end\n\n      -- [xreg*xsc] or [xreg*xsc+-disp] or [xreg*xsc+-expr]\n      local xsc, tailsc = match(tailr, \"^%*%s*([1248])%s*(.*)$\")\n      if xsc then\n\tif not map_reg_valid_index[reg] then\n\t  werror(\"bad index register `\"..map_reg_rev[reg]..\"'\")\n\tend\n\tt.xsc = map_xsc[xsc]\n\tt.xreg = t.reg\n\tt.vxreg = t.vreg\n\tt.reg = nil\n\tt.vreg = nil\n\tt.disp = dispexpr(tailsc)\n\tbreak\n      end\n      if not map_reg_valid_base[reg] then\n\twerror(\"bad base register `\"..map_reg_rev[reg]..\"'\")\n      end\n\n      -- [reg] or [reg+-disp]\n      t.disp = toint(tailr) or (tailr == \"\" and 0)\n      if t.disp then break end\n\n      -- [reg+xreg...]\n      local xreg, tailx = match(tailr, \"^+%s*([@%w_:]+)%s*(.*)$\")\n      xreg, t.xreg, tp = rtexpr(xreg)\n      if not t.xreg then\n\t-- [reg+-expr]\n\tt.disp = dispexpr(tailr)\n\tbreak\n      end\n      if not map_reg_valid_index[xreg] then\n\twerror(\"bad index register `\"..map_reg_rev[xreg]..\"'\")\n      end\n\n      if t.xreg == -1 then\n\tt.vxreg, tailx = match(tailx, \"^(%b())(.*)$\")\n\tif not t.vxreg then werror(\"bad variable register expression\") end\n      end\n\n      -- [reg+xreg*xsc...]\n      local xsc, tailsc = match(tailx, \"^%*%s*([1248])%s*(.*)$\")\n      if xsc then\n\tt.xsc = map_xsc[xsc]\n\ttailx = tailsc\n      end\n\n      -- [...] or [...+-disp] or [...+-expr]\n      t.disp = dispexpr(tailx)\n    else\n      -- imm or opsize*imm\n      local imm = toint(expr)\n      if not imm and sub(expr, 1, 1) == \"*\" and t.opsize then\n\timm = toint(sub(expr, 2))\n\tif imm then\n\t  imm = imm * map_opsizenum[t.opsize]\n\t  t.opsize = nil\n\tend\n      end\n      if imm then\n\tif t.opsize then werror(\"bad operand size override\") end\n\tlocal m = \"i\"\n\tif imm == 1 then m = m..\"1\" end\n\tif imm >= 4294967168 and imm <= 4294967295 then imm = imm-4294967296 end\n\tif imm >= -128 and imm <= 127 then m = m..\"S\" end\n\tt.imm = imm\n\tt.mode = m\n\tbreak\n      end\n\n      local tp\n      local reg, tailr = match(expr, \"^([@%w_:]+)%s*(.*)$\")\n      reg, t.reg, tp = rtexpr(reg)\n      if t.reg then\n\tif t.reg == -1 then\n\t  t.vreg, tailr = match(tailr, \"^(%b())(.*)$\")\n\t  if not t.vreg then werror(\"bad variable register expression\") end\n\tend\n\t-- reg\n\tif tailr == \"\" then\n\t  if t.opsize then werror(\"bad operand size override\") end\n\t  t.opsize = map_reg_opsize[reg]\n\t  if t.opsize == \"f\" then\n\t    t.mode = t.reg == 0 and \"fF\" or \"f\"\n\t  else\n\t    if reg == \"@w4\" or (x64 and reg == \"@d4\") then\n\t      wwarn(\"bad idea, try again with `\"..(x64 and \"rsp'\" or \"esp'\"))\n\t    end\n\t    t.mode = t.reg == 0 and \"rmR\" or (reg == \"@b1\" and \"rmC\" or \"rm\")\n\t  end\n\t  t.needrex = map_reg_needrex[reg]\n\t  break\n\tend\n\n\t-- type[idx], type[idx].field, type->field -> [reg+offset_expr]\n\tif not tp then werror(\"bad operand `\"..param..\"'\") end\n\tt.mode = \"xm\"\n\tt.disp = format(tp.ctypefmt, tailr)\n      else\n\tt.mode, t.imm = immexpr(expr)\n\tif sub(t.mode, -1) == \"J\" then\n\t  if t.opsize and t.opsize ~= addrsize then\n\t    werror(\"bad operand size override\")\n\t  end\n\t  t.opsize = addrsize\n\tend\n      end\n    end\n  until true\n  return t\nend\n\n------------------------------------------------------------------------------\n-- x86 Template String Description\n-- ===============================\n--\n-- Each template string is a list of [match:]pattern pairs,\n-- separated by \"|\". The first match wins. No match means a\n-- bad or unsupported combination of operand modes or sizes.\n--\n-- The match part and the \":\" is omitted if the operation has\n-- no operands. Otherwise the first N characters are matched\n-- against the mode strings of each of the N operands.\n--\n-- The mode string for each operand type is (see parseoperand()):\n--   Integer register: \"rm\", +\"R\" for eax, ax, al, +\"C\" for cl\n--   FP register:      \"f\",  +\"F\" for st0\n--   Index operand:    \"xm\", +\"O\" for [disp] (pure offset)\n--   Immediate:        \"i\",  +\"S\" for signed 8 bit, +\"1\" for 1,\n--                     +\"I\" for arg, +\"P\" for pointer\n--   Any:              +\"J\" for valid jump targets\n--\n-- So a match character \"m\" (mixed) matches both an integer register\n-- and an index operand (to be encoded with the ModRM/SIB scheme).\n-- But \"r\" matches only a register and \"x\" only an index operand\n-- (e.g. for FP memory access operations).\n--\n-- The operand size match string starts right after the mode match\n-- characters and ends before the \":\". \"dwb\" or \"qdwb\" is assumed, if empty.\n-- The effective data size of the operation is matched against this list.\n--\n-- If only the regular \"b\", \"w\", \"d\", \"q\", \"t\" operand sizes are\n-- present, then all operands must be the same size. Unspecified sizes\n-- are ignored, but at least one operand must have a size or the pattern\n-- won't match (use the \"byte\", \"word\", \"dword\", \"qword\", \"tword\"\n-- operand size overrides. E.g.: mov dword [eax], 1).\n--\n-- If the list has a \"1\" or \"2\" prefix, the operand size is taken\n-- from the respective operand and any other operand sizes are ignored.\n-- If the list contains only \".\", all operand sizes are ignored.\n-- If the list has a \"/\" prefix, the concatenated (mixed) operand sizes\n-- are compared to the match.\n--\n-- E.g. \"rrdw\" matches for either two dword registers or two word\n-- registers. \"Fx2dq\" matches an st0 operand plus an index operand\n-- pointing to a dword (float) or qword (double).\n--\n-- Every character after the \":\" is part of the pattern string:\n--   Hex chars are accumulated to form the opcode (left to right).\n--   \"n\"       disables the standard opcode mods\n--             (otherwise: -1 for \"b\", o16 prefix for \"w\", rex.w for \"q\")\n--   \"X\"       Force REX.W.\n--   \"r\"/\"R\"   adds the reg. number from the 1st/2nd operand to the opcode.\n--   \"m\"/\"M\"   generates ModRM/SIB from the 1st/2nd operand.\n--             The spare 3 bits are either filled with the last hex digit or\n--             the result from a previous \"r\"/\"R\". The opcode is restored.\n--   \"u\"       Use VEX encoding, vvvv unused.\n--   \"v\"/\"V\"   Use VEX encoding, vvvv from 1st/2nd operand (the operand is\n--             removed from the list used by future characters).\n--   \"L\"       Force VEX.L\n--\n-- All of the following characters force a flush of the opcode:\n--   \"o\"/\"O\"   stores a pure 32 bit disp (offset) from the 1st/2nd operand.\n--   \"s\"       stores a 4 bit immediate from the last register operand,\n--             followed by 4 zero bits.\n--   \"S\"       stores a signed 8 bit immediate from the last operand.\n--   \"U\"       stores an unsigned 8 bit immediate from the last operand.\n--   \"W\"       stores an unsigned 16 bit immediate from the last operand.\n--   \"i\"       stores an operand sized immediate from the last operand.\n--   \"I\"       dito, but generates an action code to optionally modify\n--             the opcode (+2) for a signed 8 bit immediate.\n--   \"J\"       generates one of the REL action codes from the last operand.\n--\n------------------------------------------------------------------------------\n\n-- Template strings for x86 instructions. Ordered by first opcode byte.\n-- Unimplemented opcodes (deliberate omissions) are marked with *.\nlocal map_op = {\n  -- 00-05: add...\n  -- 06: *push es\n  -- 07: *pop es\n  -- 08-0D: or...\n  -- 0E: *push cs\n  -- 0F: two byte opcode prefix\n  -- 10-15: adc...\n  -- 16: *push ss\n  -- 17: *pop ss\n  -- 18-1D: sbb...\n  -- 1E: *push ds\n  -- 1F: *pop ds\n  -- 20-25: and...\n  es_0 =\t\"26\",\n  -- 27: *daa\n  -- 28-2D: sub...\n  cs_0 =\t\"2E\",\n  -- 2F: *das\n  -- 30-35: xor...\n  ss_0 =\t\"36\",\n  -- 37: *aaa\n  -- 38-3D: cmp...\n  ds_0 =\t\"3E\",\n  -- 3F: *aas\n  inc_1 =\tx64 and \"m:FF0m\" or \"rdw:40r|m:FF0m\",\n  dec_1 =\tx64 and \"m:FF1m\" or \"rdw:48r|m:FF1m\",\n  push_1 =\t(x64 and \"rq:n50r|rw:50r|mq:nFF6m|mw:FF6m\" or\n\t\t\t \"rdw:50r|mdw:FF6m\")..\"|S.:6AS|ib:n6Ai|i.:68i\",\n  pop_1 =\tx64 and \"rq:n58r|rw:58r|mq:n8F0m|mw:8F0m\" or \"rdw:58r|mdw:8F0m\",\n  -- 60: *pusha, *pushad, *pushaw\n  -- 61: *popa, *popad, *popaw\n  -- 62: *bound rdw,x\n  -- 63: x86: *arpl mw,rw\n  movsxd_2 =\tx64 and \"rm/qd:63rM\",\n  fs_0 =\t\"64\",\n  gs_0 =\t\"65\",\n  o16_0 =\t\"66\",\n  a16_0 =\tnot x64 and \"67\" or nil,\n  a32_0 =\tx64 and \"67\",\n  -- 68: push idw\n  -- 69: imul rdw,mdw,idw\n  -- 6A: push ib\n  -- 6B: imul rdw,mdw,S\n  -- 6C: *insb\n  -- 6D: *insd, *insw\n  -- 6E: *outsb\n  -- 6F: *outsd, *outsw\n  -- 70-7F: jcc lb\n  -- 80: add... mb,i\n  -- 81: add... mdw,i\n  -- 82: *undefined\n  -- 83: add... mdw,S\n  test_2 =\t\"mr:85Rm|rm:85rM|Ri:A9ri|mi:F70mi\",\n  -- 86: xchg rb,mb\n  -- 87: xchg rdw,mdw\n  -- 88: mov mb,r\n  -- 89: mov mdw,r\n  -- 8A: mov r,mb\n  -- 8B: mov r,mdw\n  -- 8C: *mov mdw,seg\n  lea_2 =\t\"rx1dq:8DrM\",\n  -- 8E: *mov seg,mdw\n  -- 8F: pop mdw\n  nop_0 =\t\"90\",\n  xchg_2 =\t\"Rrqdw:90R|rRqdw:90r|rm:87rM|mr:87Rm\",\n  cbw_0 =\t\"6698\",\n  cwde_0 =\t\"98\",\n  cdqe_0 =\t\"4898\",\n  cwd_0 =\t\"6699\",\n  cdq_0 =\t\"99\",\n  cqo_0 =\t\"4899\",\n  -- 9A: *call iw:idw\n  wait_0 =\t\"9B\",\n  fwait_0 =\t\"9B\",\n  pushf_0 =\t\"9C\",\n  pushfd_0 =\tnot x64 and \"9C\",\n  pushfq_0 =\tx64 and \"9C\",\n  popf_0 =\t\"9D\",\n  popfd_0 =\tnot x64 and \"9D\",\n  popfq_0 =\tx64 and \"9D\",\n  sahf_0 =\t\"9E\",\n  lahf_0 =\t\"9F\",\n  mov_2 =\t\"OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi\",\n  movsb_0 =\t\"A4\",\n  movsw_0 =\t\"66A5\",\n  movsd_0 =\t\"A5\",\n  cmpsb_0 =\t\"A6\",\n  cmpsw_0 =\t\"66A7\",\n  cmpsd_0 =\t\"A7\",\n  -- A8: test Rb,i\n  -- A9: test Rdw,i\n  stosb_0 =\t\"AA\",\n  stosw_0 =\t\"66AB\",\n  stosd_0 =\t\"AB\",\n  lodsb_0 =\t\"AC\",\n  lodsw_0 =\t\"66AD\",\n  lodsd_0 =\t\"AD\",\n  scasb_0 =\t\"AE\",\n  scasw_0 =\t\"66AF\",\n  scasd_0 =\t\"AF\",\n  -- B0-B7: mov rb,i\n  -- B8-BF: mov rdw,i\n  -- C0: rol... mb,i\n  -- C1: rol... mdw,i\n  ret_1 =\t\"i.:nC2W\",\n  ret_0 =\t\"C3\",\n  -- C4: *les rdw,mq\n  -- C5: *lds rdw,mq\n  -- C6: mov mb,i\n  -- C7: mov mdw,i\n  -- C8: *enter iw,ib\n  leave_0 =\t\"C9\",\n  -- CA: *retf iw\n  -- CB: *retf\n  int3_0 =\t\"CC\",\n  int_1 =\t\"i.:nCDU\",\n  into_0 =\t\"CE\",\n  -- CF: *iret\n  -- D0: rol... mb,1\n  -- D1: rol... mdw,1\n  -- D2: rol... mb,cl\n  -- D3: rol... mb,cl\n  -- D4: *aam ib\n  -- D5: *aad ib\n  -- D6: *salc\n  -- D7: *xlat\n  -- D8-DF: floating point ops\n  -- E0: *loopne\n  -- E1: *loope\n  -- E2: *loop\n  -- E3: *jcxz, *jecxz\n  -- E4: *in Rb,ib\n  -- E5: *in Rdw,ib\n  -- E6: *out ib,Rb\n  -- E7: *out ib,Rdw\n  call_1 =\tx64 and \"mq:nFF2m|J.:E8nJ\" or \"md:FF2m|J.:E8J\",\n  jmp_1 =\tx64 and \"mq:nFF4m|J.:E9nJ\" or \"md:FF4m|J.:E9J\", -- short: EB\n  -- EA: *jmp iw:idw\n  -- EB: jmp ib\n  -- EC: *in Rb,dx\n  -- ED: *in Rdw,dx\n  -- EE: *out dx,Rb\n  -- EF: *out dx,Rdw\n  lock_0 =\t\"F0\",\n  int1_0 =\t\"F1\",\n  repne_0 =\t\"F2\",\n  repnz_0 =\t\"F2\",\n  rep_0 =\t\"F3\",\n  repe_0 =\t\"F3\",\n  repz_0 =\t\"F3\",\n  -- F4: *hlt\n  cmc_0 =\t\"F5\",\n  -- F6: test... mb,i; div... mb\n  -- F7: test... mdw,i; div... mdw\n  clc_0 =\t\"F8\",\n  stc_0 =\t\"F9\",\n  -- FA: *cli\n  cld_0 =\t\"FC\",\n  std_0 =\t\"FD\",\n  -- FE: inc... mb\n  -- FF: inc... mdw\n\n  -- misc ops\n  not_1 =\t\"m:F72m\",\n  neg_1 =\t\"m:F73m\",\n  mul_1 =\t\"m:F74m\",\n  imul_1 =\t\"m:F75m\",\n  div_1 =\t\"m:F76m\",\n  idiv_1 =\t\"m:F77m\",\n\n  imul_2 =\t\"rmqdw:0FAFrM|rIqdw:69rmI|rSqdw:6BrmS|riqdw:69rmi\",\n  imul_3 =\t\"rmIqdw:69rMI|rmSqdw:6BrMS|rmiqdw:69rMi\",\n\n  movzx_2 =\t\"rm/db:0FB6rM|rm/qb:|rm/wb:0FB6rM|rm/dw:0FB7rM|rm/qw:\",\n  movsx_2 =\t\"rm/db:0FBErM|rm/qb:|rm/wb:0FBErM|rm/dw:0FBFrM|rm/qw:\",\n\n  bswap_1 =\t\"rqd:0FC8r\",\n  bsf_2 =\t\"rmqdw:0FBCrM\",\n  bsr_2 =\t\"rmqdw:0FBDrM\",\n  bt_2 =\t\"mrqdw:0FA3Rm|miqdw:0FBA4mU\",\n  btc_2 =\t\"mrqdw:0FBBRm|miqdw:0FBA7mU\",\n  btr_2 =\t\"mrqdw:0FB3Rm|miqdw:0FBA6mU\",\n  bts_2 =\t\"mrqdw:0FABRm|miqdw:0FBA5mU\",\n\n  shld_3 =\t\"mriqdw:0FA4RmU|mrC/qq:0FA5Rm|mrC/dd:|mrC/ww:\",\n  shrd_3 =\t\"mriqdw:0FACRmU|mrC/qq:0FADRm|mrC/dd:|mrC/ww:\",\n\n  rdtsc_0 =\t\"0F31\", -- P1+\n  rdpmc_0 =\t\"0F33\", -- P6+\n  cpuid_0 =\t\"0FA2\", -- P1+\n\n  -- floating point ops\n  fst_1 =\t\"ff:DDD0r|xd:D92m|xq:nDD2m\",\n  fstp_1 =\t\"ff:DDD8r|xd:D93m|xq:nDD3m|xt:DB7m\",\n  fld_1 =\t\"ff:D9C0r|xd:D90m|xq:nDD0m|xt:DB5m\",\n\n  fpop_0 =\t\"DDD8\", -- Alias for fstp st0.\n\n  fist_1 =\t\"xw:nDF2m|xd:DB2m\",\n  fistp_1 =\t\"xw:nDF3m|xd:DB3m|xq:nDF7m\",\n  fild_1 =\t\"xw:nDF0m|xd:DB0m|xq:nDF5m\",\n\n  fxch_0 =\t\"D9C9\",\n  fxch_1 =\t\"ff:D9C8r\",\n  fxch_2 =\t\"fFf:D9C8r|Fff:D9C8R\",\n\n  fucom_1 =\t\"ff:DDE0r\",\n  fucom_2 =\t\"Fff:DDE0R\",\n  fucomp_1 =\t\"ff:DDE8r\",\n  fucomp_2 =\t\"Fff:DDE8R\",\n  fucomi_1 =\t\"ff:DBE8r\", -- P6+\n  fucomi_2 =\t\"Fff:DBE8R\", -- P6+\n  fucomip_1 =\t\"ff:DFE8r\", -- P6+\n  fucomip_2 =\t\"Fff:DFE8R\", -- P6+\n  fcomi_1 =\t\"ff:DBF0r\", -- P6+\n  fcomi_2 =\t\"Fff:DBF0R\", -- P6+\n  fcomip_1 =\t\"ff:DFF0r\", -- P6+\n  fcomip_2 =\t\"Fff:DFF0R\", -- P6+\n  fucompp_0 =\t\"DAE9\",\n  fcompp_0 =\t\"DED9\",\n\n  fldenv_1 =\t\"x.:D94m\",\n  fnstenv_1 =\t\"x.:D96m\",\n  fstenv_1 =\t\"x.:9BD96m\",\n  fldcw_1 =\t\"xw:nD95m\",\n  fstcw_1 =\t\"xw:n9BD97m\",\n  fnstcw_1 =\t\"xw:nD97m\",\n  fstsw_1 =\t\"Rw:n9BDFE0|xw:n9BDD7m\",\n  fnstsw_1 =\t\"Rw:nDFE0|xw:nDD7m\",\n  fclex_0 =\t\"9BDBE2\",\n  fnclex_0 =\t\"DBE2\",\n\n  fnop_0 =\t\"D9D0\",\n  -- D9D1-D9DF: unassigned\n\n  fchs_0 =\t\"D9E0\",\n  fabs_0 =\t\"D9E1\",\n  -- D9E2: unassigned\n  -- D9E3: unassigned\n  ftst_0 =\t\"D9E4\",\n  fxam_0 =\t\"D9E5\",\n  -- D9E6: unassigned\n  -- D9E7: unassigned\n  fld1_0 =\t\"D9E8\",\n  fldl2t_0 =\t\"D9E9\",\n  fldl2e_0 =\t\"D9EA\",\n  fldpi_0 =\t\"D9EB\",\n  fldlg2_0 =\t\"D9EC\",\n  fldln2_0 =\t\"D9ED\",\n  fldz_0 =\t\"D9EE\",\n  -- D9EF: unassigned\n\n  f2xm1_0 =\t\"D9F0\",\n  fyl2x_0 =\t\"D9F1\",\n  fptan_0 =\t\"D9F2\",\n  fpatan_0 =\t\"D9F3\",\n  fxtract_0 =\t\"D9F4\",\n  fprem1_0 =\t\"D9F5\",\n  fdecstp_0 =\t\"D9F6\",\n  fincstp_0 =\t\"D9F7\",\n  fprem_0 =\t\"D9F8\",\n  fyl2xp1_0 =\t\"D9F9\",\n  fsqrt_0 =\t\"D9FA\",\n  fsincos_0 =\t\"D9FB\",\n  frndint_0 =\t\"D9FC\",\n  fscale_0 =\t\"D9FD\",\n  fsin_0 =\t\"D9FE\",\n  fcos_0 =\t\"D9FF\",\n\n  -- SSE, SSE2\n  andnpd_2 =\t\"rmo:660F55rM\",\n  andnps_2 =\t\"rmo:0F55rM\",\n  andpd_2 =\t\"rmo:660F54rM\",\n  andps_2 =\t\"rmo:0F54rM\",\n  clflush_1 =\t\"x.:0FAE7m\",\n  cmppd_3 =\t\"rmio:660FC2rMU\",\n  cmpps_3 =\t\"rmio:0FC2rMU\",\n  cmpsd_3 =\t\"rrio:F20FC2rMU|rxi/oq:\",\n  cmpss_3 =\t\"rrio:F30FC2rMU|rxi/od:\",\n  comisd_2 =\t\"rro:660F2FrM|rx/oq:\",\n  comiss_2 =\t\"rro:0F2FrM|rx/od:\",\n  cvtdq2pd_2 =\t\"rro:F30FE6rM|rx/oq:\",\n  cvtdq2ps_2 =\t\"rmo:0F5BrM\",\n  cvtpd2dq_2 =\t\"rmo:F20FE6rM\",\n  cvtpd2ps_2 =\t\"rmo:660F5ArM\",\n  cvtpi2pd_2 =\t\"rx/oq:660F2ArM\",\n  cvtpi2ps_2 =\t\"rx/oq:0F2ArM\",\n  cvtps2dq_2 =\t\"rmo:660F5BrM\",\n  cvtps2pd_2 =\t\"rro:0F5ArM|rx/oq:\",\n  cvtsd2si_2 =\t\"rr/do:F20F2DrM|rr/qo:|rx/dq:|rxq:\",\n  cvtsd2ss_2 =\t\"rro:F20F5ArM|rx/oq:\",\n  cvtsi2sd_2 =\t\"rm/od:F20F2ArM|rm/oq:F20F2ArXM\",\n  cvtsi2ss_2 =\t\"rm/od:F30F2ArM|rm/oq:F30F2ArXM\",\n  cvtss2sd_2 =\t\"rro:F30F5ArM|rx/od:\",\n  cvtss2si_2 =\t\"rr/do:F30F2DrM|rr/qo:|rxd:|rx/qd:\",\n  cvttpd2dq_2 =\t\"rmo:660FE6rM\",\n  cvttps2dq_2 =\t\"rmo:F30F5BrM\",\n  cvttsd2si_2 =\t\"rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:\",\n  cvttss2si_2 =\t\"rr/do:F30F2CrM|rr/qo:|rxd:|rx/qd:\",\n  fxsave_1 =\t\"x.:0FAE0m\",\n  fxrstor_1 =\t\"x.:0FAE1m\",\n  ldmxcsr_1 =\t\"xd:0FAE2m\",\n  lfence_0 =\t\"0FAEE8\",\n  maskmovdqu_2 = \"rro:660FF7rM\",\n  mfence_0 =\t\"0FAEF0\",\n  movapd_2 =\t\"rmo:660F28rM|mro:660F29Rm\",\n  movaps_2 =\t\"rmo:0F28rM|mro:0F29Rm\",\n  movd_2 =\t\"rm/od:660F6ErM|rm/oq:660F6ErXM|mr/do:660F7ERm|mr/qo:\",\n  movdqa_2 =\t\"rmo:660F6FrM|mro:660F7FRm\",\n  movdqu_2 =\t\"rmo:F30F6FrM|mro:F30F7FRm\",\n  movhlps_2 =\t\"rro:0F12rM\",\n  movhpd_2 =\t\"rx/oq:660F16rM|xr/qo:n660F17Rm\",\n  movhps_2 =\t\"rx/oq:0F16rM|xr/qo:n0F17Rm\",\n  movlhps_2 =\t\"rro:0F16rM\",\n  movlpd_2 =\t\"rx/oq:660F12rM|xr/qo:n660F13Rm\",\n  movlps_2 =\t\"rx/oq:0F12rM|xr/qo:n0F13Rm\",\n  movmskpd_2 =\t\"rr/do:660F50rM\",\n  movmskps_2 =\t\"rr/do:0F50rM\",\n  movntdq_2 =\t\"xro:660FE7Rm\",\n  movnti_2 =\t\"xrqd:0FC3Rm\",\n  movntpd_2 =\t\"xro:660F2BRm\",\n  movntps_2 =\t\"xro:0F2BRm\",\n  movq_2 =\t\"rro:F30F7ErM|rx/oq:|xr/qo:n660FD6Rm\",\n  movsd_2 =\t\"rro:F20F10rM|rx/oq:|xr/qo:nF20F11Rm\",\n  movss_2 =\t\"rro:F30F10rM|rx/od:|xr/do:F30F11Rm\",\n  movupd_2 =\t\"rmo:660F10rM|mro:660F11Rm\",\n  movups_2 =\t\"rmo:0F10rM|mro:0F11Rm\",\n  orpd_2 =\t\"rmo:660F56rM\",\n  orps_2 =\t\"rmo:0F56rM\",\n  pause_0 =\t\"F390\",\n  pextrw_3 =\t\"rri/do:660FC5rMU|xri/wo:660F3A15nRmU\", -- Mem op: SSE4.1 only.\n  pinsrw_3 =\t\"rri/od:660FC4rMU|rxi/ow:\",\n  pmovmskb_2 =\t\"rr/do:660FD7rM\",\n  prefetchnta_1 = \"xb:n0F180m\",\n  prefetcht0_1 = \"xb:n0F181m\",\n  prefetcht1_1 = \"xb:n0F182m\",\n  prefetcht2_1 = \"xb:n0F183m\",\n  pshufd_3 =\t\"rmio:660F70rMU\",\n  pshufhw_3 =\t\"rmio:F30F70rMU\",\n  pshuflw_3 =\t\"rmio:F20F70rMU\",\n  pslld_2 =\t\"rmo:660FF2rM|rio:660F726mU\",\n  pslldq_2 =\t\"rio:660F737mU\",\n  psllq_2 =\t\"rmo:660FF3rM|rio:660F736mU\",\n  psllw_2 =\t\"rmo:660FF1rM|rio:660F716mU\",\n  psrad_2 =\t\"rmo:660FE2rM|rio:660F724mU\",\n  psraw_2 =\t\"rmo:660FE1rM|rio:660F714mU\",\n  psrld_2 =\t\"rmo:660FD2rM|rio:660F722mU\",\n  psrldq_2 =\t\"rio:660F733mU\",\n  psrlq_2 =\t\"rmo:660FD3rM|rio:660F732mU\",\n  psrlw_2 =\t\"rmo:660FD1rM|rio:660F712mU\",\n  rcpps_2 =\t\"rmo:0F53rM\",\n  rcpss_2 =\t\"rro:F30F53rM|rx/od:\",\n  rsqrtps_2 =\t\"rmo:0F52rM\",\n  rsqrtss_2 =\t\"rmo:F30F52rM\",\n  sfence_0 =\t\"0FAEF8\",\n  shufpd_3 =\t\"rmio:660FC6rMU\",\n  shufps_3 =\t\"rmio:0FC6rMU\",\n  stmxcsr_1 =   \"xd:0FAE3m\",\n  ucomisd_2 =\t\"rro:660F2ErM|rx/oq:\",\n  ucomiss_2 =\t\"rro:0F2ErM|rx/od:\",\n  unpckhpd_2 =\t\"rmo:660F15rM\",\n  unpckhps_2 =\t\"rmo:0F15rM\",\n  unpcklpd_2 =\t\"rmo:660F14rM\",\n  unpcklps_2 =\t\"rmo:0F14rM\",\n  xorpd_2 =\t\"rmo:660F57rM\",\n  xorps_2 =\t\"rmo:0F57rM\",\n\n  -- SSE3 ops\n  fisttp_1 =\t\"xw:nDF1m|xd:DB1m|xq:nDD1m\",\n  addsubpd_2 =\t\"rmo:660FD0rM\",\n  addsubps_2 =\t\"rmo:F20FD0rM\",\n  haddpd_2 =\t\"rmo:660F7CrM\",\n  haddps_2 =\t\"rmo:F20F7CrM\",\n  hsubpd_2 =\t\"rmo:660F7DrM\",\n  hsubps_2 =\t\"rmo:F20F7DrM\",\n  lddqu_2 =\t\"rxo:F20FF0rM\",\n  movddup_2 =\t\"rmo:F20F12rM\",\n  movshdup_2 =\t\"rmo:F30F16rM\",\n  movsldup_2 =\t\"rmo:F30F12rM\",\n\n  -- SSSE3 ops\n  pabsb_2 =\t\"rmo:660F381CrM\",\n  pabsd_2 =\t\"rmo:660F381ErM\",\n  pabsw_2 =\t\"rmo:660F381DrM\",\n  palignr_3 =\t\"rmio:660F3A0FrMU\",\n  phaddd_2 =\t\"rmo:660F3802rM\",\n  phaddsw_2 =\t\"rmo:660F3803rM\",\n  phaddw_2 =\t\"rmo:660F3801rM\",\n  phsubd_2 =\t\"rmo:660F3806rM\",\n  phsubsw_2 =\t\"rmo:660F3807rM\",\n  phsubw_2 =\t\"rmo:660F3805rM\",\n  pmaddubsw_2 =\t\"rmo:660F3804rM\",\n  pmulhrsw_2 =\t\"rmo:660F380BrM\",\n  pshufb_2 =\t\"rmo:660F3800rM\",\n  psignb_2 =\t\"rmo:660F3808rM\",\n  psignd_2 =\t\"rmo:660F380ArM\",\n  psignw_2 =\t\"rmo:660F3809rM\",\n\n  -- SSE4.1 ops\n  blendpd_3 =\t\"rmio:660F3A0DrMU\",\n  blendps_3 =\t\"rmio:660F3A0CrMU\",\n  blendvpd_3 =\t\"rmRo:660F3815rM\",\n  blendvps_3 =\t\"rmRo:660F3814rM\",\n  dppd_3 =\t\"rmio:660F3A41rMU\",\n  dpps_3 =\t\"rmio:660F3A40rMU\",\n  extractps_3 =\t\"mri/do:660F3A17RmU|rri/qo:660F3A17RXmU\",\n  insertps_3 =\t\"rrio:660F3A41rMU|rxi/od:\",\n  movntdqa_2 =\t\"rxo:660F382ArM\",\n  mpsadbw_3 =\t\"rmio:660F3A42rMU\",\n  packusdw_2 =\t\"rmo:660F382BrM\",\n  pblendvb_3 =\t\"rmRo:660F3810rM\",\n  pblendw_3 =\t\"rmio:660F3A0ErMU\",\n  pcmpeqq_2 =\t\"rmo:660F3829rM\",\n  pextrb_3 =\t\"rri/do:660F3A14nRmU|rri/qo:|xri/bo:\",\n  pextrd_3 =\t\"mri/do:660F3A16RmU\",\n  pextrq_3 =\t\"mri/qo:660F3A16RmU\",\n  -- pextrw is SSE2, mem operand is SSE4.1 only\n  phminposuw_2 = \"rmo:660F3841rM\",\n  pinsrb_3 =\t\"rri/od:660F3A20nrMU|rxi/ob:\",\n  pinsrd_3 =\t\"rmi/od:660F3A22rMU\",\n  pinsrq_3 =\t\"rmi/oq:660F3A22rXMU\",\n  pmaxsb_2 =\t\"rmo:660F383CrM\",\n  pmaxsd_2 =\t\"rmo:660F383DrM\",\n  pmaxud_2 =\t\"rmo:660F383FrM\",\n  pmaxuw_2 =\t\"rmo:660F383ErM\",\n  pminsb_2 =\t\"rmo:660F3838rM\",\n  pminsd_2 =\t\"rmo:660F3839rM\",\n  pminud_2 =\t\"rmo:660F383BrM\",\n  pminuw_2 =\t\"rmo:660F383ArM\",\n  pmovsxbd_2 =\t\"rro:660F3821rM|rx/od:\",\n  pmovsxbq_2 =\t\"rro:660F3822rM|rx/ow:\",\n  pmovsxbw_2 =\t\"rro:660F3820rM|rx/oq:\",\n  pmovsxdq_2 =\t\"rro:660F3825rM|rx/oq:\",\n  pmovsxwd_2 =\t\"rro:660F3823rM|rx/oq:\",\n  pmovsxwq_2 =\t\"rro:660F3824rM|rx/od:\",\n  pmovzxbd_2 =\t\"rro:660F3831rM|rx/od:\",\n  pmovzxbq_2 =\t\"rro:660F3832rM|rx/ow:\",\n  pmovzxbw_2 =\t\"rro:660F3830rM|rx/oq:\",\n  pmovzxdq_2 =\t\"rro:660F3835rM|rx/oq:\",\n  pmovzxwd_2 =\t\"rro:660F3833rM|rx/oq:\",\n  pmovzxwq_2 =\t\"rro:660F3834rM|rx/od:\",\n  pmuldq_2 =\t\"rmo:660F3828rM\",\n  pmulld_2 =\t\"rmo:660F3840rM\",\n  ptest_2 =\t\"rmo:660F3817rM\",\n  roundpd_3 =\t\"rmio:660F3A09rMU\",\n  roundps_3 =\t\"rmio:660F3A08rMU\",\n  roundsd_3 =\t\"rrio:660F3A0BrMU|rxi/oq:\",\n  roundss_3 =\t\"rrio:660F3A0ArMU|rxi/od:\",\n\n  -- SSE4.2 ops\n  crc32_2 =\t\"rmqd:F20F38F1rM|rm/dw:66F20F38F1rM|rm/db:F20F38F0rM|rm/qb:\",\n  pcmpestri_3 =\t\"rmio:660F3A61rMU\",\n  pcmpestrm_3 =\t\"rmio:660F3A60rMU\",\n  pcmpgtq_2 =\t\"rmo:660F3837rM\",\n  pcmpistri_3 =\t\"rmio:660F3A63rMU\",\n  pcmpistrm_3 =\t\"rmio:660F3A62rMU\",\n  popcnt_2 =\t\"rmqdw:F30FB8rM\",\n\n  -- SSE4a\n  extrq_2 =\t\"rro:660F79rM\",\n  extrq_3 =\t\"riio:660F780mUU\",\n  insertq_2 =\t\"rro:F20F79rM\",\n  insertq_4 =\t\"rriio:F20F78rMUU\",\n  lzcnt_2 =\t\"rmqdw:F30FBDrM\",\n  movntsd_2 =\t\"xr/qo:nF20F2BRm\",\n  movntss_2 =\t\"xr/do:F30F2BRm\",\n  -- popcnt is also in SSE4.2\n\n  -- AES-NI\n  aesdec_2 =\t\"rmo:660F38DErM\",\n  aesdeclast_2 = \"rmo:660F38DFrM\",\n  aesenc_2 =\t\"rmo:660F38DCrM\",\n  aesenclast_2 = \"rmo:660F38DDrM\",\n  aesimc_2 =\t\"rmo:660F38DBrM\",\n  aeskeygenassist_3 = \"rmio:660F3ADFrMU\",\n  pclmulqdq_3 =\t\"rmio:660F3A44rMU\",\n\n   -- AVX FP ops\n  vaddsubpd_3 =\t\"rrmoy:660FVD0rM\",\n  vaddsubps_3 =\t\"rrmoy:F20FVD0rM\",\n  vandpd_3 =\t\"rrmoy:660FV54rM\",\n  vandps_3 =\t\"rrmoy:0FV54rM\",\n  vandnpd_3 =\t\"rrmoy:660FV55rM\",\n  vandnps_3 =\t\"rrmoy:0FV55rM\",\n  vblendpd_4 =\t\"rrmioy:660F3AV0DrMU\",\n  vblendps_4 =\t\"rrmioy:660F3AV0CrMU\",\n  vblendvpd_4 =\t\"rrmroy:660F3AV4BrMs\",\n  vblendvps_4 =\t\"rrmroy:660F3AV4ArMs\",\n  vbroadcastf128_2 = \"rx/yo:660F38u1ArM\",\n  vcmppd_4 =\t\"rrmioy:660FVC2rMU\",\n  vcmpps_4 =\t\"rrmioy:0FVC2rMU\",\n  vcmpsd_4 =\t\"rrrio:F20FVC2rMU|rrxi/ooq:\",\n  vcmpss_4 =\t\"rrrio:F30FVC2rMU|rrxi/ood:\",\n  vcomisd_2 =\t\"rro:660Fu2FrM|rx/oq:\",\n  vcomiss_2 =\t\"rro:0Fu2FrM|rx/od:\",\n  vcvtdq2pd_2 =\t\"rro:F30FuE6rM|rx/oq:|rm/yo:\",\n  vcvtdq2ps_2 =\t\"rmoy:0Fu5BrM\",\n  vcvtpd2dq_2 =\t\"rmoy:F20FuE6rM\",\n  vcvtpd2ps_2 =\t\"rmoy:660Fu5ArM\",\n  vcvtps2dq_2 =\t\"rmoy:660Fu5BrM\",\n  vcvtps2pd_2 =\t\"rro:0Fu5ArM|rx/oq:|rm/yo:\",\n  vcvtsd2si_2 =\t\"rr/do:F20Fu2DrM|rx/dq:|rr/qo:|rxq:\",\n  vcvtsd2ss_3 =\t\"rrro:F20FV5ArM|rrx/ooq:\",\n  vcvtsi2sd_3 =\t\"rrm/ood:F20FV2ArM|rrm/ooq:F20FVX2ArM\",\n  vcvtsi2ss_3 =\t\"rrm/ood:F30FV2ArM|rrm/ooq:F30FVX2ArM\",\n  vcvtss2sd_3 =\t\"rrro:F30FV5ArM|rrx/ood:\",\n  vcvtss2si_2 =\t\"rr/do:F30Fu2DrM|rxd:|rr/qo:|rx/qd:\",\n  vcvttpd2dq_2 = \"rmo:660FuE6rM|rm/oy:660FuLE6rM\",\n  vcvttps2dq_2 = \"rmoy:F30Fu5BrM\",\n  vcvttsd2si_2 = \"rr/do:F20Fu2CrM|rx/dq:|rr/qo:|rxq:\",\n  vcvttss2si_2 = \"rr/do:F30Fu2CrM|rxd:|rr/qo:|rx/qd:\",\n  vdppd_4 =\t\"rrmio:660F3AV41rMU\",\n  vdpps_4 =\t\"rrmioy:660F3AV40rMU\",\n  vextractf128_3 = \"mri/oy:660F3AuL19RmU\",\n  vextractps_3 = \"mri/do:660F3Au17RmU\",\n  vhaddpd_3 =\t\"rrmoy:660FV7CrM\",\n  vhaddps_3 =\t\"rrmoy:F20FV7CrM\",\n  vhsubpd_3 =\t\"rrmoy:660FV7DrM\",\n  vhsubps_3 =\t\"rrmoy:F20FV7DrM\",\n  vinsertf128_4 = \"rrmi/yyo:660F3AV18rMU\",\n  vinsertps_4 =\t\"rrrio:660F3AV21rMU|rrxi/ood:\",\n  vldmxcsr_1 =\t\"xd:0FuAE2m\",\n  vmaskmovps_3 = \"rrxoy:660F38V2CrM|xrroy:660F38V2ERm\",\n  vmaskmovpd_3 = \"rrxoy:660F38V2DrM|xrroy:660F38V2FRm\",\n  vmovapd_2 =\t\"rmoy:660Fu28rM|mroy:660Fu29Rm\",\n  vmovaps_2 =\t\"rmoy:0Fu28rM|mroy:0Fu29Rm\",\n  vmovd_2 =\t\"rm/od:660Fu6ErM|rm/oq:660FuX6ErM|mr/do:660Fu7ERm|mr/qo:\",\n  vmovq_2 =\t\"rro:F30Fu7ErM|rx/oq:|xr/qo:660FuD6Rm\",\n  vmovddup_2 =\t\"rmy:F20Fu12rM|rro:|rx/oq:\",\n  vmovhlps_3 =\t\"rrro:0FV12rM\",\n  vmovhpd_2 =\t\"xr/qo:660Fu17Rm\",\n  vmovhpd_3 =\t\"rrx/ooq:660FV16rM\",\n  vmovhps_2 =\t\"xr/qo:0Fu17Rm\",\n  vmovhps_3 =\t\"rrx/ooq:0FV16rM\",\n  vmovlhps_3 =\t\"rrro:0FV16rM\",\n  vmovlpd_2 =\t\"xr/qo:660Fu13Rm\",\n  vmovlpd_3 =\t\"rrx/ooq:660FV12rM\",\n  vmovlps_2 =\t\"xr/qo:0Fu13Rm\",\n  vmovlps_3 =\t\"rrx/ooq:0FV12rM\",\n  vmovmskpd_2 =\t\"rr/do:660Fu50rM|rr/dy:660FuL50rM\",\n  vmovmskps_2 =\t\"rr/do:0Fu50rM|rr/dy:0FuL50rM\",\n  vmovntpd_2 =\t\"xroy:660Fu2BRm\",\n  vmovntps_2 =\t\"xroy:0Fu2BRm\",\n  vmovsd_2 =\t\"rx/oq:F20Fu10rM|xr/qo:F20Fu11Rm\",\n  vmovsd_3 =\t\"rrro:F20FV10rM\",\n  vmovshdup_2 =\t\"rmoy:F30Fu16rM\",\n  vmovsldup_2 =\t\"rmoy:F30Fu12rM\",\n  vmovss_2 =\t\"rx/od:F30Fu10rM|xr/do:F30Fu11Rm\",\n  vmovss_3 =\t\"rrro:F30FV10rM\",\n  vmovupd_2 =\t\"rmoy:660Fu10rM|mroy:660Fu11Rm\",\n  vmovups_2 =\t\"rmoy:0Fu10rM|mroy:0Fu11Rm\",\n  vorpd_3 =\t\"rrmoy:660FV56rM\",\n  vorps_3 =\t\"rrmoy:0FV56rM\",\n  vpermilpd_3 =\t\"rrmoy:660F38V0DrM|rmioy:660F3Au05rMU\",\n  vpermilps_3 =\t\"rrmoy:660F38V0CrM|rmioy:660F3Au04rMU\",\n  vperm2f128_4 = \"rrmiy:660F3AV06rMU\",\n  vptestpd_2 =\t\"rmoy:660F38u0FrM\",\n  vptestps_2 =\t\"rmoy:660F38u0ErM\",\n  vrcpps_2 =\t\"rmoy:0Fu53rM\",\n  vrcpss_3 =\t\"rrro:F30FV53rM|rrx/ood:\",\n  vrsqrtps_2 =\t\"rmoy:0Fu52rM\",\n  vrsqrtss_3 =\t\"rrro:F30FV52rM|rrx/ood:\",\n  vroundpd_3 =\t\"rmioy:660F3AV09rMU\",\n  vroundps_3 =\t\"rmioy:660F3AV08rMU\",\n  vroundsd_4 =\t\"rrrio:660F3AV0BrMU|rrxi/ooq:\",\n  vroundss_4 =\t\"rrrio:660F3AV0ArMU|rrxi/ood:\",\n  vshufpd_4 =\t\"rrmioy:660FVC6rMU\",\n  vshufps_4 =\t\"rrmioy:0FVC6rMU\",\n  vsqrtps_2 =\t\"rmoy:0Fu51rM\",\n  vsqrtss_2 =\t\"rro:F30Fu51rM|rx/od:\",\n  vsqrtpd_2 =\t\"rmoy:660Fu51rM\",\n  vsqrtsd_2 =\t\"rro:F20Fu51rM|rx/oq:\",\n  vstmxcsr_1 =\t\"xd:0FuAE3m\",\n  vucomisd_2 =\t\"rro:660Fu2ErM|rx/oq:\",\n  vucomiss_2 =\t\"rro:0Fu2ErM|rx/od:\",\n  vunpckhpd_3 =\t\"rrmoy:660FV15rM\",\n  vunpckhps_3 =\t\"rrmoy:0FV15rM\",\n  vunpcklpd_3 =\t\"rrmoy:660FV14rM\",\n  vunpcklps_3 =\t\"rrmoy:0FV14rM\",\n  vxorpd_3 =\t\"rrmoy:660FV57rM\",\n  vxorps_3 =\t\"rrmoy:0FV57rM\",\n  vzeroall_0 =\t\"0FuL77\",\n  vzeroupper_0 = \"0Fu77\",\n\n  -- AVX2 FP ops\n  vbroadcastss_2 = \"rx/od:660F38u18rM|rx/yd:|rro:|rr/yo:\",\n  vbroadcastsd_2 = \"rx/yq:660F38u19rM|rr/yo:\",\n  -- *vgather* (!vsib)\n  vpermpd_3 =\t\"rmiy:660F3AuX01rMU\",\n  vpermps_3 =\t\"rrmy:660F38V16rM\",\n\n  -- AVX, AVX2 integer ops\n  -- In general, xmm requires AVX, ymm requires AVX2.\n  vaesdec_3 =  \"rrmo:660F38VDErM\",\n  vaesdeclast_3 = \"rrmo:660F38VDFrM\",\n  vaesenc_3 =  \"rrmo:660F38VDCrM\",\n  vaesenclast_3 = \"rrmo:660F38VDDrM\",\n  vaesimc_2 =  \"rmo:660F38uDBrM\",\n  vaeskeygenassist_3 = \"rmio:660F3AuDFrMU\",\n  vlddqu_2 =\t\"rxoy:F20FuF0rM\",\n  vmaskmovdqu_2 = \"rro:660FuF7rM\",\n  vmovdqa_2 =\t\"rmoy:660Fu6FrM|mroy:660Fu7FRm\",\n  vmovdqu_2 =\t\"rmoy:F30Fu6FrM|mroy:F30Fu7FRm\",\n  vmovntdq_2 =\t\"xroy:660FuE7Rm\",\n  vmovntdqa_2 =\t\"rxoy:660F38u2ArM\",\n  vmpsadbw_4 =\t\"rrmioy:660F3AV42rMU\",\n  vpabsb_2 =\t\"rmoy:660F38u1CrM\",\n  vpabsd_2 =\t\"rmoy:660F38u1ErM\",\n  vpabsw_2 =\t\"rmoy:660F38u1DrM\",\n  vpackusdw_3 =\t\"rrmoy:660F38V2BrM\",\n  vpalignr_4 =\t\"rrmioy:660F3AV0FrMU\",\n  vpblendvb_4 =\t\"rrmroy:660F3AV4CrMs\",\n  vpblendw_4 =\t\"rrmioy:660F3AV0ErMU\",\n  vpclmulqdq_4 = \"rrmio:660F3AV44rMU\",\n  vpcmpeqq_3 =\t\"rrmoy:660F38V29rM\",\n  vpcmpestri_3 = \"rmio:660F3Au61rMU\",\n  vpcmpestrm_3 = \"rmio:660F3Au60rMU\",\n  vpcmpgtq_3 =\t\"rrmoy:660F38V37rM\",\n  vpcmpistri_3 = \"rmio:660F3Au63rMU\",\n  vpcmpistrm_3 = \"rmio:660F3Au62rMU\",\n  vpextrb_3 =\t\"rri/do:660F3Au14nRmU|rri/qo:|xri/bo:\",\n  vpextrw_3 =\t\"rri/do:660FuC5rMU|xri/wo:660F3Au15nRmU\",\n  vpextrd_3 =\t\"mri/do:660F3Au16RmU\",\n  vpextrq_3 =\t\"mri/qo:660F3Au16RmU\",\n  vphaddw_3 =\t\"rrmoy:660F38V01rM\",\n  vphaddd_3 =\t\"rrmoy:660F38V02rM\",\n  vphaddsw_3 =\t\"rrmoy:660F38V03rM\",\n  vphminposuw_2 = \"rmo:660F38u41rM\",\n  vphsubw_3 =\t\"rrmoy:660F38V05rM\",\n  vphsubd_3 =\t\"rrmoy:660F38V06rM\",\n  vphsubsw_3 =\t\"rrmoy:660F38V07rM\",\n  vpinsrb_4 =\t\"rrri/ood:660F3AV20rMU|rrxi/oob:\",\n  vpinsrw_4 =\t\"rrri/ood:660FVC4rMU|rrxi/oow:\",\n  vpinsrd_4 =\t\"rrmi/ood:660F3AV22rMU\",\n  vpinsrq_4 =\t\"rrmi/ooq:660F3AVX22rMU\",\n  vpmaddubsw_3 = \"rrmoy:660F38V04rM\",\n  vpmaxsb_3 =\t\"rrmoy:660F38V3CrM\",\n  vpmaxsd_3 =\t\"rrmoy:660F38V3DrM\",\n  vpmaxuw_3 =\t\"rrmoy:660F38V3ErM\",\n  vpmaxud_3 =\t\"rrmoy:660F38V3FrM\",\n  vpminsb_3 =\t\"rrmoy:660F38V38rM\",\n  vpminsd_3 =\t\"rrmoy:660F38V39rM\",\n  vpminuw_3 =\t\"rrmoy:660F38V3ArM\",\n  vpminud_3 =\t\"rrmoy:660F38V3BrM\",\n  vpmovmskb_2 =\t\"rr/do:660FuD7rM|rr/dy:660FuLD7rM\",\n  vpmovsxbw_2 =\t\"rroy:660F38u20rM|rx/oq:|rx/yo:\",\n  vpmovsxbd_2 =\t\"rroy:660F38u21rM|rx/od:|rx/yq:\",\n  vpmovsxbq_2 =\t\"rroy:660F38u22rM|rx/ow:|rx/yd:\",\n  vpmovsxwd_2 =\t\"rroy:660F38u23rM|rx/oq:|rx/yo:\",\n  vpmovsxwq_2 =\t\"rroy:660F38u24rM|rx/od:|rx/yq:\",\n  vpmovsxdq_2 =\t\"rroy:660F38u25rM|rx/oq:|rx/yo:\",\n  vpmovzxbw_2 =\t\"rroy:660F38u30rM|rx/oq:|rx/yo:\",\n  vpmovzxbd_2 =\t\"rroy:660F38u31rM|rx/od:|rx/yq:\",\n  vpmovzxbq_2 =\t\"rroy:660F38u32rM|rx/ow:|rx/yd:\",\n  vpmovzxwd_2 =\t\"rroy:660F38u33rM|rx/oq:|rx/yo:\",\n  vpmovzxwq_2 =\t\"rroy:660F38u34rM|rx/od:|rx/yq:\",\n  vpmovzxdq_2 =\t\"rroy:660F38u35rM|rx/oq:|rx/yo:\",\n  vpmuldq_3 =\t\"rrmoy:660F38V28rM\",\n  vpmulhrsw_3 =\t\"rrmoy:660F38V0BrM\",\n  vpmulld_3 =\t\"rrmoy:660F38V40rM\",\n  vpshufb_3 =\t\"rrmoy:660F38V00rM\",\n  vpshufd_3 =\t\"rmioy:660Fu70rMU\",\n  vpshufhw_3 =\t\"rmioy:F30Fu70rMU\",\n  vpshuflw_3 =\t\"rmioy:F20Fu70rMU\",\n  vpsignb_3 =\t\"rrmoy:660F38V08rM\",\n  vpsignw_3 =\t\"rrmoy:660F38V09rM\",\n  vpsignd_3 =\t\"rrmoy:660F38V0ArM\",\n  vpslldq_3 =\t\"rrioy:660Fv737mU\",\n  vpsllw_3 =\t\"rrmoy:660FVF1rM|rrioy:660Fv716mU\",\n  vpslld_3 =\t\"rrmoy:660FVF2rM|rrioy:660Fv726mU\",\n  vpsllq_3 =\t\"rrmoy:660FVF3rM|rrioy:660Fv736mU\",\n  vpsraw_3 =\t\"rrmoy:660FVE1rM|rrioy:660Fv714mU\",\n  vpsrad_3 =\t\"rrmoy:660FVE2rM|rrioy:660Fv724mU\",\n  vpsrldq_3 =\t\"rrioy:660Fv733mU\",\n  vpsrlw_3 =\t\"rrmoy:660FVD1rM|rrioy:660Fv712mU\",\n  vpsrld_3 =\t\"rrmoy:660FVD2rM|rrioy:660Fv722mU\",\n  vpsrlq_3 =\t\"rrmoy:660FVD3rM|rrioy:660Fv732mU\",\n  vptest_2 =\t\"rmoy:660F38u17rM\",\n\n  -- AVX2 integer ops\n  vbroadcasti128_2 = \"rx/yo:660F38u5ArM\",\n  vinserti128_4 = \"rrmi/yyo:660F3AV38rMU\",\n  vextracti128_3 = \"mri/oy:660F3AuL39RmU\",\n  vpblendd_4 =\t\"rrmioy:660F3AV02rMU\",\n  vpbroadcastb_2 = \"rro:660F38u78rM|rx/ob:|rr/yo:|rx/yb:\",\n  vpbroadcastw_2 = \"rro:660F38u79rM|rx/ow:|rr/yo:|rx/yw:\",\n  vpbroadcastd_2 = \"rro:660F38u58rM|rx/od:|rr/yo:|rx/yd:\",\n  vpbroadcastq_2 = \"rro:660F38u59rM|rx/oq:|rr/yo:|rx/yq:\",\n  vpermd_3 =\t\"rrmy:660F38V36rM\",\n  vpermq_3 =\t\"rmiy:660F3AuX00rMU\",\n  -- *vpgather* (!vsib)\n  vperm2i128_4 = \"rrmiy:660F3AV46rMU\",\n  vpmaskmovd_3 = \"rrxoy:660F38V8CrM|xrroy:660F38V8ERm\",\n  vpmaskmovq_3 = \"rrxoy:660F38VX8CrM|xrroy:660F38VX8ERm\",\n  vpsllvd_3 =\t\"rrmoy:660F38V47rM\",\n  vpsllvq_3 =\t\"rrmoy:660F38VX47rM\",\n  vpsravd_3 =\t\"rrmoy:660F38V46rM\",\n  vpsrlvd_3 =\t\"rrmoy:660F38V45rM\",\n  vpsrlvq_3 =\t\"rrmoy:660F38VX45rM\",\n}\n\n------------------------------------------------------------------------------\n\n-- Arithmetic ops.\nfor name,n in pairs{ add = 0, [\"or\"] = 1, adc = 2, sbb = 3,\n\t\t     [\"and\"] = 4, sub = 5, xor = 6, cmp = 7 } do\n  local n8 = shl(n, 3)\n  map_op[name..\"_2\"] = format(\n    \"mr:%02XRm|rm:%02XrM|mI1qdw:81%XmI|mS1qdw:83%XmS|Ri1qdwb:%02Xri|mi1qdwb:81%Xmi\",\n    1+n8, 3+n8, n, n, 5+n8, n)\nend\n\n-- Shift ops.\nfor name,n in pairs{ rol = 0, ror = 1, rcl = 2, rcr = 3,\n\t\t     shl = 4, shr = 5,          sar = 7, sal = 4 } do\n  map_op[name..\"_2\"] = format(\"m1:D1%Xm|mC1qdwb:D3%Xm|mi:C1%XmU\", n, n, n)\nend\n\n-- Conditional ops.\nfor cc,n in pairs(map_cc) do\n  map_op[\"j\"..cc..\"_1\"] = format(\"J.:n0F8%XJ\", n) -- short: 7%X\n  map_op[\"set\"..cc..\"_1\"] = format(\"mb:n0F9%X2m\", n)\n  map_op[\"cmov\"..cc..\"_2\"] = format(\"rmqdw:0F4%XrM\", n) -- P6+\nend\n\n-- FP arithmetic ops.\nfor name,n in pairs{ add = 0, mul = 1, com = 2, comp = 3,\n\t\t     sub = 4, subr = 5, div = 6, divr = 7 } do\n  local nc = 0xc0 + shl(n, 3)\n  local nr = nc + (n < 4 and 0 or (n % 2 == 0 and 8 or -8))\n  local fn = \"f\"..name\n  map_op[fn..\"_1\"] = format(\"ff:D8%02Xr|xd:D8%Xm|xq:nDC%Xm\", nc, n, n)\n  if n == 2 or n == 3 then\n    map_op[fn..\"_2\"] = format(\"Fff:D8%02XR|Fx2d:D8%XM|Fx2q:nDC%XM\", nc, n, n)\n  else\n    map_op[fn..\"_2\"] = format(\"Fff:D8%02XR|fFf:DC%02Xr|Fx2d:D8%XM|Fx2q:nDC%XM\", nc, nr, n, n)\n    map_op[fn..\"p_1\"] = format(\"ff:DE%02Xr\", nr)\n    map_op[fn..\"p_2\"] = format(\"fFf:DE%02Xr\", nr)\n  end\n  map_op[\"fi\"..name..\"_1\"] = format(\"xd:DA%Xm|xw:nDE%Xm\", n, n)\nend\n\n-- FP conditional moves.\nfor cc,n in pairs{ b=0, e=1, be=2, u=3, nb=4, ne=5, nbe=6, nu=7 } do\n  local nc = 0xdac0 + shl(band(n, 3), 3) + shl(band(n, 4), 6)\n  map_op[\"fcmov\"..cc..\"_1\"] = format(\"ff:%04Xr\", nc) -- P6+\n  map_op[\"fcmov\"..cc..\"_2\"] = format(\"Fff:%04XR\", nc) -- P6+\nend\n\n-- SSE / AVX FP arithmetic ops.\nfor name,n in pairs{ sqrt = 1, add = 8, mul = 9,\n\t\t     sub = 12, min = 13, div = 14, max = 15 } do\n  map_op[name..\"ps_2\"] = format(\"rmo:0F5%XrM\", n)\n  map_op[name..\"ss_2\"] = format(\"rro:F30F5%XrM|rx/od:\", n)\n  map_op[name..\"pd_2\"] = format(\"rmo:660F5%XrM\", n)\n  map_op[name..\"sd_2\"] = format(\"rro:F20F5%XrM|rx/oq:\", n)\n  if n ~= 1 then\n    map_op[\"v\"..name..\"ps_3\"] = format(\"rrmoy:0FV5%XrM\", n)\n    map_op[\"v\"..name..\"ss_3\"] = format(\"rrro:F30FV5%XrM|rrx/ood:\", n)\n    map_op[\"v\"..name..\"pd_3\"] = format(\"rrmoy:660FV5%XrM\", n)\n    map_op[\"v\"..name..\"sd_3\"] = format(\"rrro:F20FV5%XrM|rrx/ooq:\", n)\n  end\nend\n\n-- SSE2 / AVX / AVX2 integer arithmetic ops (66 0F leaf).\nfor name,n in pairs{\n  paddb = 0xFC, paddw = 0xFD, paddd = 0xFE, paddq = 0xD4,\n  paddsb = 0xEC, paddsw = 0xED, packssdw = 0x6B,\n  packsswb = 0x63, packuswb = 0x67, paddusb = 0xDC,\n  paddusw = 0xDD, pand = 0xDB, pandn = 0xDF, pavgb = 0xE0,\n  pavgw = 0xE3, pcmpeqb = 0x74, pcmpeqd = 0x76,\n  pcmpeqw = 0x75, pcmpgtb = 0x64, pcmpgtd = 0x66,\n  pcmpgtw = 0x65, pmaddwd = 0xF5, pmaxsw = 0xEE,\n  pmaxub = 0xDE, pminsw = 0xEA, pminub = 0xDA,\n  pmulhuw = 0xE4, pmulhw = 0xE5, pmullw = 0xD5,\n  pmuludq = 0xF4, por = 0xEB, psadbw = 0xF6, psubb = 0xF8,\n  psubw = 0xF9, psubd = 0xFA, psubq = 0xFB, psubsb = 0xE8,\n  psubsw = 0xE9, psubusb = 0xD8, psubusw = 0xD9,\n  punpckhbw = 0x68, punpckhwd = 0x69, punpckhdq = 0x6A,\n  punpckhqdq = 0x6D, punpcklbw = 0x60, punpcklwd = 0x61,\n  punpckldq = 0x62, punpcklqdq = 0x6C, pxor = 0xEF\n} do\n  map_op[name..\"_2\"] = format(\"rmo:660F%02XrM\", n)\n  map_op[\"v\"..name..\"_3\"] = format(\"rrmoy:660FV%02XrM\", n)\nend\n\n------------------------------------------------------------------------------\n\nlocal map_vexarg = { u = false, v = 1, V = 2 }\n\n-- Process pattern string.\nlocal function dopattern(pat, args, sz, op, needrex)\n  local digit, addin, vex\n  local opcode = 0\n  local szov = sz\n  local narg = 1\n  local rex = 0\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 6 positions.\n  if secpos+6 > maxsecpos then wflush() end\n\n  -- Process each character.\n  for c in gmatch(pat..\"|\", \".\") do\n    if match(c, \"%x\") then\t-- Hex digit.\n      digit = byte(c) - 48\n      if digit > 48 then digit = digit - 39\n      elseif digit > 16 then digit = digit - 7 end\n      opcode = opcode*16 + digit\n      addin = nil\n    elseif c == \"n\" then\t-- Disable operand size mods for opcode.\n      szov = nil\n    elseif c == \"X\" then\t-- Force REX.W.\n      rex = 8\n    elseif c == \"L\" then\t-- Force VEX.L.\n      vex.l = true\n    elseif c == \"r\" then\t-- Merge 1st operand regno. into opcode.\n      addin = args[1]; opcode = opcode + (addin.reg % 8)\n      if narg < 2 then narg = 2 end\n    elseif c == \"R\" then\t-- Merge 2nd operand regno. into opcode.\n      addin = args[2]; opcode = opcode + (addin.reg % 8)\n      narg = 3\n    elseif c == \"m\" or c == \"M\" then\t-- Encode ModRM/SIB.\n      local s\n      if addin then\n\ts = addin.reg\n\topcode = opcode - band(s, 7)\t-- Undo regno opcode merge.\n      else\n\ts = band(opcode, 15)\t-- Undo last digit.\n\topcode = shr(opcode, 4)\n      end\n      local nn = c == \"m\" and 1 or 2\n      local t = args[nn]\n      if narg <= nn then narg = nn + 1 end\n      if szov == \"q\" and rex == 0 then rex = rex + 8 end\n      if t.reg and t.reg > 7 then rex = rex + 1 end\n      if t.xreg and t.xreg > 7 then rex = rex + 2 end\n      if s > 7 then rex = rex + 4 end\n      if needrex then rex = rex + 16 end\n      local psz, sk = wputop(szov, opcode, rex, vex, s < 0, t.vreg or t.vxreg)\n      opcode = nil\n      local imark = sub(pat, -1) -- Force a mark (ugly).\n      -- Put ModRM/SIB with regno/last digit as spare.\n      wputmrmsib(t, imark, s, addin and addin.vreg, psz, sk)\n      addin = nil\n    elseif map_vexarg[c] ~= nil then -- Encode using VEX prefix\n      local b = band(opcode, 255); opcode = shr(opcode, 8)\n      local m = 1\n      if b == 0x38 then m = 2\n      elseif b == 0x3a then m = 3 end\n      if m ~= 1 then b = band(opcode, 255); opcode = shr(opcode, 8) end\n      if b ~= 0x0f then\n\twerror(\"expected `0F', `0F38', or `0F3A' to precede `\"..c..\n\t  \"' in pattern `\"..pat..\"' for `\"..op..\"'\")\n      end\n      local v = map_vexarg[c]\n      if v then v = remove(args, v) end\n      b = band(opcode, 255)\n      local p = 0\n      if b == 0x66 then p = 1\n      elseif b == 0xf3 then p = 2\n      elseif b == 0xf2 then p = 3 end\n      if p ~= 0 then opcode = shr(opcode, 8) end\n      if opcode ~= 0 then wputop(nil, opcode, 0); opcode = 0 end\n      vex = { m = m, p = p, v = v }\n    else\n      if opcode then -- Flush opcode.\n\tif szov == \"q\" and rex == 0 then rex = rex + 8 end\n\tif needrex then rex = rex + 16 end\n\tif addin and addin.reg == -1 then\n\t  local psz, sk = wputop(szov, opcode - 7, rex, vex, true)\n\t  wvreg(\"opcode\", addin.vreg, psz, sk)\n\telse\n\t  if addin and addin.reg > 7 then rex = rex + 1 end\n\t  wputop(szov, opcode, rex, vex)\n\tend\n\topcode = nil\n      end\n      if c == \"|\" then break end\n      if c == \"o\" then -- Offset (pure 32 bit displacement).\n\twputdarg(args[1].disp); if narg < 2 then narg = 2 end\n      elseif c == \"O\" then\n\twputdarg(args[2].disp); narg = 3\n      else\n\t-- Anything else is an immediate operand.\n\tlocal a = args[narg]\n\tnarg = narg + 1\n\tlocal mode, imm = a.mode, a.imm\n\tif mode == \"iJ\" and not match(\"iIJ\", c) then\n\t  werror(\"bad operand size for label\")\n\tend\n\tif c == \"S\" then\n\t  wputsbarg(imm)\n\telseif c == \"U\" then\n\t  wputbarg(imm)\n\telseif c == \"W\" then\n\t  wputwarg(imm)\n\telseif c == \"i\" or c == \"I\" then\n\t  if mode == \"iJ\" then\n\t    wputlabel(\"IMM_\", imm, 1)\n\t  elseif mode == \"iI\" and c == \"I\" then\n\t    waction(sz == \"w\" and \"IMM_WB\" or \"IMM_DB\", imm)\n\t  else\n\t    wputszarg(sz, imm)\n\t  end\n\telseif c == \"J\" then\n\t  if mode == \"iPJ\" then\n\t    waction(\"REL_A\", imm) -- !x64 (secpos)\n\t  else\n\t    wputlabel(\"REL_\", imm, 2)\n\t  end\n\telseif c == \"s\" then\n\t  local reg = a.reg\n\t  if reg < 0 then\n\t    wputb(0)\n\t    wvreg(\"imm.hi\", a.vreg)\n\t  else\n\t    wputb(shl(reg, 4))\n\t  end\n\telse\n\t  werror(\"bad char `\"..c..\"' in pattern `\"..pat..\"' for `\"..op..\"'\")\n\tend\n      end\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Mapping of operand modes to short names. Suppress output with '#'.\nlocal map_modename = {\n  r = \"reg\", R = \"eax\", C = \"cl\", x = \"mem\", m = \"mrm\", i = \"imm\",\n  f = \"stx\", F = \"st0\", J = \"lbl\", [\"1\"] = \"1\",\n  I = \"#\", S = \"#\", O = \"#\",\n}\n\n-- Return a table/string showing all possible operand modes.\nlocal function templatehelp(template, nparams)\n  if nparams == 0 then return \"\" end\n  local t = {}\n  for tm in gmatch(template, \"[^%|]+\") do\n    local s = map_modename[sub(tm, 1, 1)]\n    s = s..gsub(sub(tm, 2, nparams), \".\", function(c)\n      return \", \"..map_modename[c]\n    end)\n    if not match(s, \"#\") then t[#t+1] = s end\n  end\n  return t\nend\n\n-- Match operand modes against mode match part of template.\nlocal function matchtm(tm, args)\n  for i=1,#args do\n    if not match(args[i].mode, sub(tm, i, i)) then return end\n  end\n  return true\nend\n\n-- Handle opcodes defined with template strings.\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return templatehelp(template, nparams) end\n  local args = {}\n\n  -- Zero-operand opcodes have no match part.\n  if #params == 0 then\n    dopattern(template, args, \"d\", params.op, nil)\n    return\n  end\n\n  -- Determine common operand size (coerce undefined size) or flag as mixed.\n  local sz, szmix, needrex\n  for i,p in ipairs(params) do\n    args[i] = parseoperand(p)\n    local nsz = args[i].opsize\n    if nsz then\n      if sz and sz ~= nsz then szmix = true else sz = nsz end\n    end\n    local nrex = args[i].needrex\n    if nrex ~= nil then\n      if needrex == nil then\n\tneedrex = nrex\n      elseif needrex ~= nrex then\n\twerror(\"bad mix of byte-addressable registers\")\n      end\n    end\n  end\n\n  -- Try all match:pattern pairs (separated by '|').\n  local gotmatch, lastpat\n  for tm in gmatch(template, \"[^%|]+\") do\n    -- Split off size match (starts after mode match) and pattern string.\n    local szm, pat = match(tm, \"^(.-):(.*)$\", #args+1)\n    if pat == \"\" then pat = lastpat else lastpat = pat end\n    if matchtm(tm, args) then\n      local prefix = sub(szm, 1, 1)\n      if prefix == \"/\" then -- Exactly match leading operand sizes.\n\tfor i = #szm,1,-1 do\n\t  if i == 1 then\n\t    dopattern(pat, args, sz, params.op, needrex) -- Process pattern.\n\t    return\n\t  elseif args[i-1].opsize ~= sub(szm, i, i) then\n\t    break\n\t  end\n\tend\n      else -- Match common operand size.\n\tlocal szp = sz\n\tif szm == \"\" then szm = x64 and \"qdwb\" or \"dwb\" end -- Default sizes.\n\tif prefix == \"1\" then szp = args[1].opsize; szmix = nil\n\telseif prefix == \"2\" then szp = args[2].opsize; szmix = nil end\n\tif not szmix and (prefix == \".\" or match(szm, szp or \"#\")) then\n\t  dopattern(pat, args, szp, params.op, needrex) -- Process pattern.\n\t  return\n\tend\n      end\n      gotmatch = true\n    end\n  end\n\n  local msg = \"bad operand mode\"\n  if gotmatch then\n    if szmix then\n      msg = \"mixed operand size\"\n    else\n      msg = sz and \"bad operand size\" or \"missing operand size\"\n    end\n  end\n\n  werror(msg..\" in `\"..opmodestr(params.op, args)..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- x64-specific opcode for 64 bit immediates and displacements.\nif x64 then\n  function map_op.mov64_2(params)\n    if not params then return { \"reg, imm\", \"reg, [disp]\", \"[disp], reg\" } end\n    if secpos+2 > maxsecpos then wflush() end\n    local opcode, op64, sz, rex, vreg\n    local op64 = match(params[1], \"^%[%s*(.-)%s*%]$\")\n    if op64 then\n      local a = parseoperand(params[2])\n      if a.mode ~= \"rmR\" then werror(\"bad operand mode\") end\n      sz = a.opsize\n      rex = sz == \"q\" and 8 or 0\n      opcode = 0xa3\n    else\n      op64 = match(params[2], \"^%[%s*(.-)%s*%]$\")\n      local a = parseoperand(params[1])\n      if op64 then\n\tif a.mode ~= \"rmR\" then werror(\"bad operand mode\") end\n\tsz = a.opsize\n\trex = sz == \"q\" and 8 or 0\n\topcode = 0xa1\n      else\n\tif sub(a.mode, 1, 1) ~= \"r\" or a.opsize ~= \"q\" then\n\t  werror(\"bad operand mode\")\n\tend\n\top64 = params[2]\n\tif a.reg == -1 then\n\t  vreg = a.vreg\n\t  opcode = 0xb8\n\telse\n\t  opcode = 0xb8 + band(a.reg, 7)\n\tend\n\trex = a.reg > 7 and 9 or 8\n      end\n    end\n    local psz, sk = wputop(sz, opcode, rex, nil, vreg)\n    wvreg(\"opcode\", vreg, psz, sk)\n    waction(\"IMM_D\", format(\"(unsigned int)(%s)\", op64))\n    waction(\"IMM_D\", format(\"(unsigned int)((%s)>>32)\", op64))\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nlocal function op_data(params)\n  if not params then return \"imm...\" end\n  local sz = sub(params.op, 2, 2)\n  if sz == \"a\" then sz = addrsize end\n  for _,p in ipairs(params) do\n    local a = parseoperand(p)\n    if sub(a.mode, 1, 1) ~= \"i\" or (a.opsize and a.opsize ~= sz) then\n      werror(\"bad mode or size in `\"..p..\"'\")\n    end\n    if a.mode == \"iJ\" then\n      wputlabel(\"IMM_\", a.imm, 1)\n    else\n      wputszarg(sz, a.imm)\n    end\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\nmap_op[\".byte_*\"] = op_data\nmap_op[\".sbyte_*\"] = op_data\nmap_op[\".word_*\"] = op_data\nmap_op[\".dword_*\"] = op_data\nmap_op[\".aword_*\"] = op_data\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_2\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr  [, addr]\" end\n  if secpos+2 > maxsecpos then wflush() end\n  local a = parseoperand(params[1])\n  local mode, imm = a.mode, a.imm\n  if type(imm) == \"number\" and (mode == \"iJ\" or (imm >= 1 and imm <= 9)) then\n    -- Local label (1: ... 9:) or global label (->global:).\n    waction(\"LABEL_LG\", nil, 1)\n    wputxb(imm)\n  elseif mode == \"iJ\" then\n    -- PC label (=>pcexpr:).\n    waction(\"LABEL_PC\", imm)\n  else\n    werror(\"bad label definition\")\n  end\n  -- SETLABEL must immediately follow LABEL_LG/LABEL_PC.\n  local addr = params[2]\n  if addr then\n    local a = parseoperand(addr)\n    if a.mode == \"iPJ\" then\n      waction(\"SETLABEL\", a.imm)\n    else\n      werror(\"bad label assignment\")\n    end\n  end\nend\nmap_op[\".label_1\"] = map_op[\".label_2\"]\n\n------------------------------------------------------------------------------\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1]) or map_opsizenum[map_opsize[params[1]]]\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", nil, 1)\n\twputxb(align-1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n-- Spacing pseudo-opcode.\nmap_op[\".space_2\"] = function(params)\n  if not params then return \"num [, filler]\" end\n  if secpos+1 > maxsecpos then wflush() end\n  waction(\"SPACE\", params[1])\n  local fill = params[2]\n  if fill then\n    fill = tonumber(fill)\n    if not fill or fill < 0 or fill > 255 then werror(\"bad filler\") end\n  end\n  wputxb(fill or 0)\nend\nmap_op[\".space_1\"] = map_op[\".space_2\"]\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  if reg and not map_reg_valid_base[reg] then\n    werror(\"bad base register `\"..(map_reg_rev[reg] or reg)..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg and map_reg_rev[tp.reg] or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\")\n  wputxb(num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpregs(out)\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/dynasm/dynasm.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM. A dynamic assembler for code generation engines.\n-- Originally designed and implemented for LuaJIT.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- See below for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Application information.\nlocal _info = {\n  name =\t\"DynASM\",\n  description =\t\"A dynamic assembler for code generation engines\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  url =\t\t\"http://luajit.org/dynasm.html\",\n  license =\t\"MIT\",\n  copyright =\t[[\nCopyright (C) 2005-2016 Mike Pall. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[ MIT license: http://www.opensource.org/licenses/mit-license.php ]\n]],\n}\n\n-- Cache library functions.\nlocal type, pairs, ipairs = type, pairs, ipairs\nlocal pcall, error, assert = pcall, error, assert\nlocal _s = string\nlocal sub, match, gmatch, gsub = _s.sub, _s.match, _s.gmatch, _s.gsub\nlocal format, rep, upper = _s.format, _s.rep, _s.upper\nlocal _t = table\nlocal insert, remove, concat, sort = _t.insert, _t.remove, _t.concat, _t.sort\nlocal exit = os.exit\nlocal io = io\nlocal stdin, stdout, stderr = io.stdin, io.stdout, io.stderr\n\n------------------------------------------------------------------------------\n\n-- Program options.\nlocal g_opt = {}\n\n-- Global state for current file.\nlocal g_fname, g_curline, g_indent, g_lineno, g_synclineno, g_arch\nlocal g_errcount = 0\n\n-- Write buffer for output file.\nlocal g_wbuffer, g_capbuffer\n\n------------------------------------------------------------------------------\n\n-- Write an output line (or callback function) to the buffer.\nlocal function wline(line, needindent)\n  local buf = g_capbuffer or g_wbuffer\n  buf[#buf+1] = needindent and g_indent..line or line\n  g_synclineno = g_synclineno + 1\nend\n\n-- Write assembler line as a comment, if requestd.\nlocal function wcomment(aline)\n  if g_opt.comment then\n    wline(g_opt.comment..aline..g_opt.endcomment, true)\n  end\nend\n\n-- Resync CPP line numbers.\nlocal function wsync()\n  if g_synclineno ~= g_lineno and g_opt.cpp then\n    wline(\"#line \"..g_lineno..' \"'..g_fname..'\"')\n    g_synclineno = g_lineno\n  end\nend\n\n-- Dummy action flush function. Replaced with arch-specific function later.\nlocal function wflush(term)\nend\n\n-- Dump all buffered output lines.\nlocal function wdumplines(out, buf)\n  for _,line in ipairs(buf) do\n    if type(line) == \"string\" then\n      assert(out:write(line, \"\\n\"))\n    else\n      -- Special callback to dynamically insert lines after end of processing.\n      line(out)\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Emit an error. Processing continues with next statement.\nlocal function werror(msg)\n  error(format(\"%s:%s: error: %s:\\n%s\", g_fname, g_lineno, msg, g_curline), 0)\nend\n\n-- Emit a fatal error. Processing stops.\nlocal function wfatal(msg)\n  g_errcount = \"fatal\"\n  werror(msg)\nend\n\n-- Print a warning. Processing continues.\nlocal function wwarn(msg)\n  stderr:write(format(\"%s:%s: warning: %s:\\n%s\\n\",\n    g_fname, g_lineno, msg, g_curline))\nend\n\n-- Print caught error message. But suppress excessive errors.\nlocal function wprinterr(...)\n  if type(g_errcount) == \"number\" then\n    -- Regular error.\n    g_errcount = g_errcount + 1\n    if g_errcount < 21 then -- Seems to be a reasonable limit.\n      stderr:write(...)\n    elseif g_errcount == 21 then\n      stderr:write(g_fname,\n\t\":*: warning: too many errors (suppressed further messages).\\n\")\n    end\n  else\n    -- Fatal error.\n    stderr:write(...)\n    return true -- Stop processing.\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Map holding all option handlers.\nlocal opt_map = {}\nlocal opt_current\n\n-- Print error and exit with error status.\nlocal function opterror(...)\n  stderr:write(\"dynasm.lua: ERROR: \", ...)\n  stderr:write(\"\\n\")\n  exit(1)\nend\n\n-- Get option parameter.\nlocal function optparam(args)\n  local argn = args.argn\n  local p = args[argn]\n  if not p then\n    opterror(\"missing parameter for option `\", opt_current, \"'.\")\n  end\n  args.argn = argn + 1\n  return p\nend\n\n------------------------------------------------------------------------------\n\n-- Core pseudo-opcodes.\nlocal map_coreop = {}\n-- Dummy opcode map. Replaced by arch-specific map.\nlocal map_op = {}\n\n-- Forward declarations.\nlocal dostmt\nlocal readfile\n\n------------------------------------------------------------------------------\n\n-- Map for defines (initially empty, chains to arch-specific map).\nlocal map_def = {}\n\n-- Pseudo-opcode to define a substitution.\nmap_coreop[\".define_2\"] = function(params, nparams)\n  if not params then return nparams == 1 and \"name\" or \"name, subst\" end\n  local name, def = params[1], params[2] or \"1\"\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad or duplicate define\") end\n  map_def[name] = def\nend\nmap_coreop[\".define_1\"] = map_coreop[\".define_2\"]\n\n-- Define a substitution on the command line.\nfunction opt_map.D(args)\n  local namesubst = optparam(args)\n  local name, subst = match(namesubst, \"^([%a_][%w_]*)=(.*)$\")\n  if name then\n    map_def[name] = subst\n  elseif match(namesubst, \"^[%a_][%w_]*$\") then\n    map_def[namesubst] = \"1\"\n  else\n    opterror(\"bad define\")\n  end\nend\n\n-- Undefine a substitution on the command line.\nfunction opt_map.U(args)\n  local name = optparam(args)\n  if match(name, \"^[%a_][%w_]*$\") then\n    map_def[name] = nil\n  else\n    opterror(\"bad define\")\n  end\nend\n\n-- Helper for definesubst.\nlocal gotsubst\n\nlocal function definesubst_one(word)\n  local subst = map_def[word]\n  if subst then gotsubst = word; return subst else return word end\nend\n\n-- Iteratively substitute defines.\nlocal function definesubst(stmt)\n  -- Limit number of iterations.\n  for i=1,100 do\n    gotsubst = false\n    stmt = gsub(stmt, \"#?[%w_]+\", definesubst_one)\n    if not gotsubst then break end\n  end\n  if gotsubst then wfatal(\"recursive define involving `\"..gotsubst..\"'\") end\n  return stmt\nend\n\n-- Dump all defines.\nlocal function dumpdefines(out, lvl)\n  local t = {}\n  for name in pairs(map_def) do\n    t[#t+1] = name\n  end\n  sort(t)\n  out:write(\"Defines:\\n\")\n  for _,name in ipairs(t) do\n    local subst = map_def[name]\n    if g_arch then subst = g_arch.revdef(subst) end\n    out:write(format(\"  %-20s %s\\n\", name, subst))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Support variables for conditional assembly.\nlocal condlevel = 0\nlocal condstack = {}\n\n-- Evaluate condition with a Lua expression. Substitutions already performed.\nlocal function cond_eval(cond)\n  local func, err\n  if setfenv then\n    func, err = loadstring(\"return \"..cond, \"=expr\")\n  else\n    -- No globals. All unknown identifiers evaluate to nil.\n    func, err = load(\"return \"..cond, \"=expr\", \"t\", {})\n  end\n  if func then\n    if setfenv then\n      setfenv(func, {}) -- No globals. All unknown identifiers evaluate to nil.\n    end\n    local ok, res = pcall(func)\n    if ok then\n      if res == 0 then return false end -- Oh well.\n      return not not res\n    end\n    err = res\n  end\n  wfatal(\"bad condition: \"..err)\nend\n\n-- Skip statements until next conditional pseudo-opcode at the same level.\nlocal function stmtskip()\n  local dostmt_save = dostmt\n  local lvl = 0\n  dostmt = function(stmt)\n    local op = match(stmt, \"^%s*(%S+)\")\n    if op == \".if\" then\n      lvl = lvl + 1\n    elseif lvl ~= 0 then\n      if op == \".endif\" then lvl = lvl - 1 end\n    elseif op == \".elif\" or op == \".else\" or op == \".endif\" then\n      dostmt = dostmt_save\n      dostmt(stmt)\n    end\n  end\nend\n\n-- Pseudo-opcodes for conditional assembly.\nmap_coreop[\".if_1\"] = function(params)\n  if not params then return \"condition\" end\n  local lvl = condlevel + 1\n  local res = cond_eval(params[1])\n  condlevel = lvl\n  condstack[lvl] = res\n  if not res then stmtskip() end\nend\n\nmap_coreop[\".elif_1\"] = function(params)\n  if not params then return \"condition\" end\n  if condlevel == 0 then wfatal(\".elif without .if\") end\n  local lvl = condlevel\n  local res = condstack[lvl]\n  if res then\n    if res == \"else\" then wfatal(\".elif after .else\") end\n  else\n    res = cond_eval(params[1])\n    if res then\n      condstack[lvl] = res\n      return\n    end\n  end\n  stmtskip()\nend\n\nmap_coreop[\".else_0\"] = function(params)\n  if condlevel == 0 then wfatal(\".else without .if\") end\n  local lvl = condlevel\n  local res = condstack[lvl]\n  condstack[lvl] = \"else\"\n  if res then\n    if res == \"else\" then wfatal(\".else after .else\") end\n    stmtskip()\n  end\nend\n\nmap_coreop[\".endif_0\"] = function(params)\n  local lvl = condlevel\n  if lvl == 0 then wfatal(\".endif without .if\") end\n  condlevel = lvl - 1\nend\n\n-- Check for unfinished conditionals.\nlocal function checkconds()\n  if g_errcount ~= \"fatal\" and condlevel ~= 0 then\n    wprinterr(g_fname, \":*: error: unbalanced conditional\\n\")\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Search for a file in the given path and open it for reading.\nlocal function pathopen(path, name)\n  local dirsep = package and match(package.path, \"\\\\\") and \"\\\\\" or \"/\"\n  for _,p in ipairs(path) do\n    local fullname = p == \"\" and name or p..dirsep..name\n    local fin = io.open(fullname, \"r\")\n    if fin then\n      g_fname = fullname\n      return fin\n    end\n  end\nend\n\n-- Include a file.\nmap_coreop[\".include_1\"] = function(params)\n  if not params then return \"filename\" end\n  local name = params[1]\n  -- Save state. Ugly, I know. but upvalues are fast.\n  local gf, gl, gcl, gi = g_fname, g_lineno, g_curline, g_indent\n  -- Read the included file.\n  local fatal = readfile(pathopen(g_opt.include, name) or\n\t\t\t wfatal(\"include file `\"..name..\"' not found\"))\n  -- Restore state.\n  g_synclineno = -1\n  g_fname, g_lineno, g_curline, g_indent = gf, gl, gcl, gi\n  if fatal then wfatal(\"in include file\") end\nend\n\n-- Make .include and conditionals initially available, too.\nmap_op[\".include_1\"] = map_coreop[\".include_1\"]\nmap_op[\".if_1\"] = map_coreop[\".if_1\"]\nmap_op[\".elif_1\"] = map_coreop[\".elif_1\"]\nmap_op[\".else_0\"] = map_coreop[\".else_0\"]\nmap_op[\".endif_0\"] = map_coreop[\".endif_0\"]\n\n------------------------------------------------------------------------------\n\n-- Support variables for macros.\nlocal mac_capture, mac_lineno, mac_name\nlocal mac_active = {}\nlocal mac_list = {}\n\n-- Pseudo-opcode to define a macro.\nmap_coreop[\".macro_*\"] = function(mparams)\n  if not mparams then return \"name [, params...]\" end\n  -- Split off and validate macro name.\n  local name = remove(mparams, 1)\n  if not name then werror(\"missing macro name\") end\n  if not (match(name, \"^[%a_][%w_%.]*$\") or match(name, \"^%.[%w_%.]*$\")) then\n    wfatal(\"bad macro name `\"..name..\"'\")\n  end\n  -- Validate macro parameter names.\n  local mdup = {}\n  for _,mp in ipairs(mparams) do\n    if not match(mp, \"^[%a_][%w_]*$\") then\n      wfatal(\"bad macro parameter name `\"..mp..\"'\")\n    end\n    if mdup[mp] then wfatal(\"duplicate macro parameter name `\"..mp..\"'\") end\n    mdup[mp] = true\n  end\n  -- Check for duplicate or recursive macro definitions.\n  local opname = name..\"_\"..#mparams\n  if map_op[opname] or map_op[name..\"_*\"] then\n    wfatal(\"duplicate macro `\"..name..\"' (\"..#mparams..\" parameters)\")\n  end\n  if mac_capture then wfatal(\"recursive macro definition\") end\n\n  -- Enable statement capture.\n  local lines = {}\n  mac_lineno = g_lineno\n  mac_name = name\n  mac_capture = function(stmt) -- Statement capture function.\n    -- Stop macro definition with .endmacro pseudo-opcode.\n    if not match(stmt, \"^%s*.endmacro%s*$\") then\n      lines[#lines+1] = stmt\n      return\n    end\n    mac_capture = nil\n    mac_lineno = nil\n    mac_name = nil\n    mac_list[#mac_list+1] = opname\n    -- Add macro-op definition.\n    map_op[opname] = function(params)\n      if not params then return mparams, lines end\n      -- Protect against recursive macro invocation.\n      if mac_active[opname] then wfatal(\"recursive macro invocation\") end\n      mac_active[opname] = true\n      -- Setup substitution map.\n      local subst = {}\n      for i,mp in ipairs(mparams) do subst[mp] = params[i] end\n      local mcom\n      if g_opt.maccomment and g_opt.comment then\n\tmcom = \" MACRO \"..name..\" (\"..#mparams..\")\"\n\twcomment(\"{\"..mcom)\n      end\n      -- Loop through all captured statements\n      for _,stmt in ipairs(lines) do\n\t-- Substitute macro parameters.\n\tlocal st = gsub(stmt, \"[%w_]+\", subst)\n\tst = definesubst(st)\n\tst = gsub(st, \"%s*%.%.%s*\", \"\") -- Token paste a..b.\n\tif mcom and sub(st, 1, 1) ~= \"|\" then wcomment(st) end\n\t-- Emit statement. Use a protected call for better diagnostics.\n\tlocal ok, err = pcall(dostmt, st)\n\tif not ok then\n\t  -- Add the captured statement to the error.\n\t  wprinterr(err, \"\\n\", g_indent, \"|  \", stmt,\n\t\t    \"\\t[MACRO \", name, \" (\", #mparams, \")]\\n\")\n\tend\n      end\n      if mcom then wcomment(\"}\"..mcom) end\n      mac_active[opname] = nil\n    end\n  end\nend\n\n-- An .endmacro pseudo-opcode outside of a macro definition is an error.\nmap_coreop[\".endmacro_0\"] = function(params)\n  wfatal(\".endmacro without .macro\")\nend\n\n-- Dump all macros and their contents (with -PP only).\nlocal function dumpmacros(out, lvl)\n  sort(mac_list)\n  out:write(\"Macros:\\n\")\n  for _,opname in ipairs(mac_list) do\n    local name = sub(opname, 1, -3)\n    local params, lines = map_op[opname]()\n    out:write(format(\"  %-20s %s\\n\", name, concat(params, \", \")))\n    if lvl > 1 then\n      for _,line in ipairs(lines) do\n\tout:write(\"  |\", line, \"\\n\")\n      end\n      out:write(\"\\n\")\n    end\n  end\n  out:write(\"\\n\")\nend\n\n-- Check for unfinished macro definitions.\nlocal function checkmacros()\n  if mac_capture then\n    wprinterr(g_fname, \":\", mac_lineno,\n\t      \": error: unfinished .macro `\", mac_name ,\"'\\n\")\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Support variables for captures.\nlocal cap_lineno, cap_name\nlocal cap_buffers = {}\nlocal cap_used = {}\n\n-- Start a capture.\nmap_coreop[\".capture_1\"] = function(params)\n  if not params then return \"name\" end\n  wflush()\n  local name = params[1]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    wfatal(\"bad capture name `\"..name..\"'\")\n  end\n  if cap_name then\n    wfatal(\"already capturing to `\"..cap_name..\"' since line \"..cap_lineno)\n  end\n  cap_name = name\n  cap_lineno = g_lineno\n  -- Create or continue a capture buffer and start the output line capture.\n  local buf = cap_buffers[name]\n  if not buf then buf = {}; cap_buffers[name] = buf end\n  g_capbuffer = buf\n  g_synclineno = 0\nend\n\n-- Stop a capture.\nmap_coreop[\".endcapture_0\"] = function(params)\n  wflush()\n  if not cap_name then wfatal(\".endcapture without a valid .capture\") end\n  cap_name = nil\n  cap_lineno = nil\n  g_capbuffer = nil\n  g_synclineno = 0\nend\n\n-- Dump a capture buffer.\nmap_coreop[\".dumpcapture_1\"] = function(params)\n  if not params then return \"name\" end\n  wflush()\n  local name = params[1]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    wfatal(\"bad capture name `\"..name..\"'\")\n  end\n  cap_used[name] = true\n  wline(function(out)\n    local buf = cap_buffers[name]\n    if buf then wdumplines(out, buf) end\n  end)\n  g_synclineno = 0\nend\n\n-- Dump all captures and their buffers (with -PP only).\nlocal function dumpcaptures(out, lvl)\n  out:write(\"Captures:\\n\")\n  for name,buf in pairs(cap_buffers) do\n    out:write(format(\"  %-20s %4s)\\n\", name, \"(\"..#buf))\n    if lvl > 1 then\n      local bar = rep(\"=\", 76)\n      out:write(\"  \", bar, \"\\n\")\n      for _,line in ipairs(buf) do\n\tout:write(\"  \", line, \"\\n\")\n      end\n      out:write(\"  \", bar, \"\\n\\n\")\n    end\n  end\n  out:write(\"\\n\")\nend\n\n-- Check for unfinished or unused captures.\nlocal function checkcaptures()\n  if cap_name then\n    wprinterr(g_fname, \":\", cap_lineno,\n\t      \": error: unfinished .capture `\", cap_name,\"'\\n\")\n    return\n  end\n  for name in pairs(cap_buffers) do\n    if not cap_used[name] then\n      wprinterr(g_fname, \":*: error: missing .dumpcapture \", name ,\"\\n\")\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Sections names.\nlocal map_sections = {}\n\n-- Pseudo-opcode to define code sections.\n-- TODO: Data sections, BSS sections. Needs extra C code and API.\nmap_coreop[\".section_*\"] = function(params)\n  if not params then return \"name...\" end\n  if #map_sections > 0 then werror(\"duplicate section definition\") end\n  wflush()\n  for sn,name in ipairs(params) do\n    local opname = \".\"..name..\"_0\"\n    if not match(name, \"^[%a][%w_]*$\") or\n       map_op[opname] or map_op[\".\"..name..\"_*\"] then\n      werror(\"bad section name `\"..name..\"'\")\n    end\n    map_sections[#map_sections+1] = name\n    wline(format(\"#define DASM_SECTION_%s\\t%d\", upper(name), sn-1))\n    map_op[opname] = function(params) g_arch.section(sn-1) end\n  end\n  wline(format(\"#define DASM_MAXSECTION\\t\\t%d\", #map_sections))\nend\n\n-- Dump all sections.\nlocal function dumpsections(out, lvl)\n  out:write(\"Sections:\\n\")\n  for _,name in ipairs(map_sections) do\n    out:write(format(\"  %s\\n\", name))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Replacement for customized Lua, which lacks the package library.\nlocal prefix = \"\"\nif not require then\n  function require(name)\n    local fp = assert(io.open(prefix..name..\".lua\"))\n    local s = fp:read(\"*a\")\n    assert(fp:close())\n    return assert(loadstring(s, \"@\"..name..\".lua\"))()\n  end\nend\n\n-- Load architecture-specific module.\nlocal function loadarch(arch)\n  if not match(arch, \"^[%w_]+$\") then return \"bad arch name\" end\n  local ok, m_arch = pcall(require, \"dasm_\"..arch)\n  if not ok then return \"cannot load module: \"..m_arch end\n  g_arch = m_arch\n  wflush = m_arch.passcb(wline, werror, wfatal, wwarn)\n  m_arch.setup(arch, g_opt)\n  map_op, map_def = m_arch.mergemaps(map_coreop, map_def)\nend\n\n-- Dump architecture description.\nfunction opt_map.dumparch(args)\n  local name = optparam(args)\n  if not g_arch then\n    local err = loadarch(name)\n    if err then opterror(err) end\n  end\n\n  local t = {}\n  for name in pairs(map_coreop) do t[#t+1] = name end\n  for name in pairs(map_op) do t[#t+1] = name end\n  sort(t)\n\n  local out = stdout\n  local _arch = g_arch._info\n  out:write(format(\"%s version %s, released %s, %s\\n\",\n    _info.name, _info.version, _info.release, _info.url))\n  g_arch.dumparch(out)\n\n  local pseudo = true\n  out:write(\"Pseudo-Opcodes:\\n\")\n  for _,sname in ipairs(t) do\n    local name, nparam = match(sname, \"^(.+)_([0-9%*])$\")\n    if name then\n      if pseudo and sub(name, 1, 1) ~= \".\" then\n\tout:write(\"\\nOpcodes:\\n\")\n\tpseudo = false\n      end\n      local f = map_op[sname]\n      local s\n      if nparam ~= \"*\" then nparam = nparam + 0 end\n      if nparam == 0 then\n\ts = \"\"\n      elseif type(f) == \"string\" then\n\ts = map_op[\".template__\"](nil, f, nparam)\n      else\n\ts = f(nil, nparam)\n      end\n      if type(s) == \"table\" then\n\tfor _,s2 in ipairs(s) do\n\t  out:write(format(\"  %-12s %s\\n\", name, s2))\n\tend\n      else\n\tout:write(format(\"  %-12s %s\\n\", name, s))\n      end\n    end\n  end\n  out:write(\"\\n\")\n  exit(0)\nend\n\n-- Pseudo-opcode to set the architecture.\n-- Only initially available (map_op is replaced when called).\nmap_op[\".arch_1\"] = function(params)\n  if not params then return \"name\" end\n  local err = loadarch(params[1])\n  if err then wfatal(err) end\n  wline(format(\"#if DASM_VERSION != %d\", _info.vernum))\n  wline('#error \"Version mismatch between DynASM and included encoding engine\"')\n  wline(\"#endif\")\nend\n\n-- Dummy .arch pseudo-opcode to improve the error report.\nmap_coreop[\".arch_1\"] = function(params)\n  if not params then return \"name\" end\n  wfatal(\"duplicate .arch statement\")\nend\n\n------------------------------------------------------------------------------\n\n-- Dummy pseudo-opcode. Don't confuse '.nop' with 'nop'.\nmap_coreop[\".nop_*\"] = function(params)\n  if not params then return \"[ignored...]\" end\nend\n\n-- Pseudo-opcodes to raise errors.\nmap_coreop[\".error_1\"] = function(params)\n  if not params then return \"message\" end\n  werror(params[1])\nend\n\nmap_coreop[\".fatal_1\"] = function(params)\n  if not params then return \"message\" end\n  wfatal(params[1])\nend\n\n-- Dump all user defined elements.\nlocal function dumpdef(out)\n  local lvl = g_opt.dumpdef\n  if lvl == 0 then return end\n  dumpsections(out, lvl)\n  dumpdefines(out, lvl)\n  if g_arch then g_arch.dumpdef(out, lvl) end\n  dumpmacros(out, lvl)\n  dumpcaptures(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Helper for splitstmt.\nlocal splitlvl\n\nlocal function splitstmt_one(c)\n  if c == \"(\" then\n    splitlvl = \")\"..splitlvl\n  elseif c == \"[\" then\n    splitlvl = \"]\"..splitlvl\n  elseif c == \"{\" then\n    splitlvl = \"}\"..splitlvl\n  elseif c == \")\" or c == \"]\" or c == \"}\" then\n    if sub(splitlvl, 1, 1) ~= c then werror(\"unbalanced (), [] or {}\") end\n    splitlvl = sub(splitlvl, 2)\n  elseif splitlvl == \"\" then\n    return \" \\0 \"\n  end\n  return c\nend\n\n-- Split statement into (pseudo-)opcode and params.\nlocal function splitstmt(stmt)\n  -- Convert label with trailing-colon into .label statement.\n  local label = match(stmt, \"^%s*(.+):%s*$\")\n  if label then return \".label\", {label} end\n\n  -- Split at commas and equal signs, but obey parentheses and brackets.\n  splitlvl = \"\"\n  stmt = gsub(stmt, \"[,%(%)%[%]{}]\", splitstmt_one)\n  if splitlvl ~= \"\" then werror(\"unbalanced () or []\") end\n\n  -- Split off opcode.\n  local op, other = match(stmt, \"^%s*([^%s%z]+)%s*(.*)$\")\n  if not op then werror(\"bad statement syntax\") end\n\n  -- Split parameters.\n  local params = {}\n  for p in gmatch(other, \"%s*(%Z+)%z?\") do\n    params[#params+1] = gsub(p, \"%s+$\", \"\")\n  end\n  if #params > 16 then werror(\"too many parameters\") end\n\n  params.op = op\n  return op, params\nend\n\n-- Process a single statement.\ndostmt = function(stmt)\n  -- Ignore empty statements.\n  if match(stmt, \"^%s*$\") then return end\n\n  -- Capture macro defs before substitution.\n  if mac_capture then return mac_capture(stmt) end\n  stmt = definesubst(stmt)\n\n  -- Emit C code without parsing the line.\n  if sub(stmt, 1, 1) == \"|\" then\n    local tail = sub(stmt, 2)\n    wflush()\n    if sub(tail, 1, 2) == \"//\" then wcomment(tail) else wline(tail, true) end\n    return\n  end\n\n  -- Split into (pseudo-)opcode and params.\n  local op, params = splitstmt(stmt)\n\n  -- Get opcode handler (matching # of parameters or generic handler).\n  local f = map_op[op..\"_\"..#params] or map_op[op..\"_*\"]\n  if not f then\n    if not g_arch then wfatal(\"first statement must be .arch\") end\n    -- Improve error report.\n    for i=0,9 do\n      if map_op[op..\"_\"..i] then\n\twerror(\"wrong number of parameters for `\"..op..\"'\")\n      end\n    end\n    werror(\"unknown statement `\"..op..\"'\")\n  end\n\n  -- Call opcode handler or special handler for template strings.\n  if type(f) == \"string\" then\n    map_op[\".template__\"](params, f)\n  else\n    f(params)\n  end\nend\n\n-- Process a single line.\nlocal function doline(line)\n  if g_opt.flushline then wflush() end\n\n  -- Assembler line?\n  local indent, aline = match(line, \"^(%s*)%|(.*)$\")\n  if not aline then\n    -- No, plain C code line, need to flush first.\n    wflush()\n    wsync()\n    wline(line, false)\n    return\n  end\n\n  g_indent = indent -- Remember current line indentation.\n\n  -- Emit C code (even from macros). Avoids echo and line parsing.\n  if sub(aline, 1, 1) == \"|\" then\n    if not mac_capture then\n      wsync()\n    elseif g_opt.comment then\n      wsync()\n      wcomment(aline)\n    end\n    dostmt(aline)\n    return\n  end\n\n  -- Echo assembler line as a comment.\n  if g_opt.comment then\n    wsync()\n    wcomment(aline)\n  end\n\n  -- Strip assembler comments.\n  aline = gsub(aline, \"//.*$\", \"\")\n\n  -- Split line into statements at semicolons.\n  if match(aline, \";\") then\n    for stmt in gmatch(aline, \"[^;]+\") do dostmt(stmt) end\n  else\n    dostmt(aline)\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Write DynASM header.\nlocal function dasmhead(out)\n  out:write(format([[\n/*\n** This file has been pre-processed with DynASM.\n** %s\n** DynASM version %s, DynASM %s version %s\n** DO NOT EDIT! The original file is in \"%s\".\n*/\n\n]], _info.url,\n    _info.version, g_arch._info.arch, g_arch._info.version,\n    g_fname))\nend\n\n-- Read input file.\nreadfile = function(fin)\n  g_indent = \"\"\n  g_lineno = 0\n  g_synclineno = -1\n\n  -- Process all lines.\n  for line in fin:lines() do\n    g_lineno = g_lineno + 1\n    g_curline = line\n    local ok, err = pcall(doline, line)\n    if not ok and wprinterr(err, \"\\n\") then return true end\n  end\n  wflush()\n\n  -- Close input file.\n  assert(fin == stdin or fin:close())\nend\n\n-- Write output file.\nlocal function writefile(outfile)\n  local fout\n\n  -- Open output file.\n  if outfile == nil or outfile == \"-\" then\n    fout = stdout\n  else\n    fout = assert(io.open(outfile, \"w\"))\n  end\n\n  -- Write all buffered lines\n  wdumplines(fout, g_wbuffer)\n\n  -- Close output file.\n  assert(fout == stdout or fout:close())\n\n  -- Optionally dump definitions.\n  dumpdef(fout == stdout and stderr or stdout)\nend\n\n-- Translate an input file to an output file.\nlocal function translate(infile, outfile)\n  g_wbuffer = {}\n  g_indent = \"\"\n  g_lineno = 0\n  g_synclineno = -1\n\n  -- Put header.\n  wline(dasmhead)\n\n  -- Read input file.\n  local fin\n  if infile == \"-\" then\n    g_fname = \"(stdin)\"\n    fin = stdin\n  else\n    g_fname = infile\n    fin = assert(io.open(infile, \"r\"))\n  end\n  readfile(fin)\n\n  -- Check for errors.\n  if not g_arch then\n    wprinterr(g_fname, \":*: error: missing .arch directive\\n\")\n  end\n  checkconds()\n  checkmacros()\n  checkcaptures()\n\n  if g_errcount ~= 0 then\n    stderr:write(g_fname, \":*: info: \", g_errcount, \" error\",\n      (type(g_errcount) == \"number\" and g_errcount > 1) and \"s\" or \"\",\n      \" in input file -- no output file generated.\\n\")\n    dumpdef(stderr)\n    exit(1)\n  end\n\n  -- Write output file.\n  writefile(outfile)\nend\n\n------------------------------------------------------------------------------\n\n-- Print help text.\nfunction opt_map.help()\n  stdout:write(\"DynASM -- \", _info.description, \".\\n\")\n  stdout:write(\"DynASM \", _info.version, \" \", _info.release, \"  \", _info.url, \"\\n\")\n  stdout:write[[\n\nUsage: dynasm [OPTION]... INFILE.dasc|-\n\n  -h, --help           Display this help text.\n  -V, --version        Display version and copyright information.\n\n  -o, --outfile FILE   Output file name (default is stdout).\n  -I, --include DIR    Add directory to the include search path.\n\n  -c, --ccomment       Use /* */ comments for assembler lines.\n  -C, --cppcomment     Use // comments for assembler lines (default).\n  -N, --nocomment      Suppress assembler lines in output.\n  -M, --maccomment     Show macro expansions as comments (default off).\n\n  -L, --nolineno       Suppress CPP line number information in output.\n  -F, --flushline      Flush action list for every line.\n\n  -D NAME[=SUBST]      Define a substitution.\n  -U NAME              Undefine a substitution.\n\n  -P, --dumpdef        Dump defines, macros, etc. Repeat for more output.\n  -A, --dumparch ARCH  Load architecture ARCH and dump description.\n]]\n  exit(0)\nend\n\n-- Print version information.\nfunction opt_map.version()\n  stdout:write(format(\"%s version %s, released %s\\n%s\\n\\n%s\",\n    _info.name, _info.version, _info.release, _info.url, _info.copyright))\n  exit(0)\nend\n\n-- Misc. options.\nfunction opt_map.outfile(args) g_opt.outfile = optparam(args) end\nfunction opt_map.include(args) insert(g_opt.include, 1, optparam(args)) end\nfunction opt_map.ccomment() g_opt.comment = \"/*|\"; g_opt.endcomment = \" */\" end\nfunction opt_map.cppcomment() g_opt.comment = \"//|\"; g_opt.endcomment = \"\" end\nfunction opt_map.nocomment() g_opt.comment = false end\nfunction opt_map.maccomment() g_opt.maccomment = true end\nfunction opt_map.nolineno() g_opt.cpp = false end\nfunction opt_map.flushline() g_opt.flushline = true end\nfunction opt_map.dumpdef() g_opt.dumpdef = g_opt.dumpdef + 1 end\n\n------------------------------------------------------------------------------\n\n-- Short aliases for long options.\nlocal opt_alias = {\n  h = \"help\", [\"?\"] = \"help\", V = \"version\",\n  o = \"outfile\", I = \"include\",\n  c = \"ccomment\", C = \"cppcomment\", N = \"nocomment\", M = \"maccomment\",\n  L = \"nolineno\", F = \"flushline\",\n  P = \"dumpdef\", A = \"dumparch\",\n}\n\n-- Parse single option.\nlocal function parseopt(opt, args)\n  opt_current = #opt == 1 and \"-\"..opt or \"--\"..opt\n  local f = opt_map[opt] or opt_map[opt_alias[opt]]\n  if not f then\n    opterror(\"unrecognized option `\", opt_current, \"'. Try `--help'.\\n\")\n  end\n  f(args)\nend\n\n-- Parse arguments.\nlocal function parseargs(args)\n  -- Default options.\n  g_opt.comment = \"//|\"\n  g_opt.endcomment = \"\"\n  g_opt.cpp = true\n  g_opt.dumpdef = 0\n  g_opt.include = { \"\" }\n\n  -- Process all option arguments.\n  args.argn = 1\n  repeat\n    local a = args[args.argn]\n    if not a then break end\n    local lopt, opt = match(a, \"^%-(%-?)(.+)\")\n    if not opt then break end\n    args.argn = args.argn + 1\n    if lopt == \"\" then\n      -- Loop through short options.\n      for o in gmatch(opt, \".\") do parseopt(o, args) end\n    else\n      -- Long option.\n      parseopt(opt, args)\n    end\n  until false\n\n  -- Check for proper number of arguments.\n  local nargs = #args - args.argn + 1\n  if nargs ~= 1 then\n    if nargs == 0 then\n      if g_opt.dumpdef > 0 then return dumpdef(stdout) end\n    end\n    opt_map.help()\n  end\n\n  -- Translate a single input file to a single output file\n  -- TODO: Handle multiple files?\n  translate(args[args.argn], g_opt.outfile)\nend\n\n------------------------------------------------------------------------------\n\n-- Add the directory dynasm.lua resides in to the Lua module search path.\nlocal arg = arg\nif arg and arg[0] then\n  prefix = match(arg[0], \"^(.*[/\\\\])\")\n  if package and prefix then package.path = prefix..\"?.lua;\"..package.path end\nend\n\n-- Start DynASM.\nparseargs{...}\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/etc/luajit.1",
    "content": ".TH luajit 1 \"\" \"\" \"LuaJIT documentation\"\n.SH NAME\nluajit \\- Just-In-Time Compiler for the Lua Language\n\\fB\n.SH SYNOPSIS\n.B luajit\n[\\fIoptions\\fR]... [\\fIscript\\fR [\\fIargs\\fR]...]\n.SH \"WEB SITE\"\n.IR http://luajit.org\n.SH DESCRIPTION\n.PP\nThis is the command-line program to run Lua programs with \\fBLuaJIT\\fR.\n.PP\n\\fBLuaJIT\\fR is a just-in-time (JIT) compiler for the Lua language.\nThe virtual machine (VM) is based on a fast interpreter combined with\na trace compiler. It can significantly improve the performance of Lua programs.\n.PP\n\\fBLuaJIT\\fR is API\\- and ABI-compatible with the VM of the standard\nLua\\ 5.1 interpreter. When embedding the VM into an application,\nthe built library can be used as a drop-in replacement.\n.SH OPTIONS\n.TP\n.BI \"\\-e \" chunk\nRun the given chunk of Lua code.\n.TP\n.BI \"\\-l \" library\nLoad the named library, just like \\fBrequire(\"\\fR\\fIlibrary\\fR\\fB\")\\fR.\n.TP\n.BI \"\\-b \" ...\nSave or list bytecode. Run without arguments to get help on options.\n.TP\n.BI \"\\-j \" command\nPerform LuaJIT control command (optional space after \\fB\\-j\\fR).\n.TP\n.BI \"\\-O\" [opt]\nControl LuaJIT optimizations.\n.TP\n.B \"\\-i\"\nRun in interactive mode.\n.TP\n.B \"\\-v\"\nShow \\fBLuaJIT\\fR version.\n.TP\n.B \"\\-E\"\nIgnore environment variables.\n.TP\n.B \"\\-\\-\"\nStop processing options.\n.TP\n.B \"\\-\"\nRead script from stdin instead.\n.PP\nAfter all options are processed, the given \\fIscript\\fR is run.\nThe arguments are passed in the global \\fIarg\\fR table.\n.PP\nInteractive mode is only entered, if no \\fIscript\\fR and no \\fB\\-e\\fR\noption is given. Interactive mode can be left with EOF (\\fICtrl\\-Z\\fB).\n.SH EXAMPLES\n.TP\nluajit hello.lua world\n\nPrints \"Hello world\", assuming \\fIhello.lua\\fR contains:\n.br\n  print(\"Hello\", arg[1])\n.TP\nluajit \\-e \"local x=0; for i=1,1e9 do x=x+i end; print(x)\"\n\nCalculates the sum of the numbers from 1 to 1000000000.\n.br\nAnd finishes in a reasonable amount of time, too.\n.TP\nluajit \\-jv \\-e \"for i=1,10 do for j=1,10 do for k=1,100 do end end end\"\n\nRuns some nested loops and shows the resulting traces.\n.SH COPYRIGHT\n.PP\n\\fBLuaJIT\\fR is Copyright \\(co 2005-2016 Mike Pall.\n.br\n\\fBLuaJIT\\fR is open source software, released under the MIT license.\n.SH SEE ALSO\n.PP\nMore details in the provided HTML docs or at:\n.IR http://luajit.org\n.br\nMore about the Lua language can be found at:\n.IR http://lua.org/docs.html\n.PP\nlua(1)\n"
  },
  {
    "path": "build/luajit-2.1.0b2/etc/luajit.pc",
    "content": "# Package information for LuaJIT to be used by pkg-config.\nmajver=2\nminver=1\nrelver=0\nversion=${majver}.${minver}.${relver}-beta2\nabiver=5.1\n\nprefix=/usr/local\nmultilib=lib\nexec_prefix=${prefix}\nlibdir=${exec_prefix}/${multilib}\nlibname=luajit-${abiver}\nincludedir=${prefix}/include/luajit-${majver}.${minver}\n\nINSTALL_LMOD=${prefix}/share/lua/${abiver}\nINSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}\n\nName: LuaJIT\nDescription: Just-in-time compiler for Lua\nURL: http://luajit.org\nVersion: ${version}\nRequires:\nLibs: -L${libdir} -l${libname}\nLibs.private: -Wl,-E -lm -ldl\nCflags: -I${includedir}\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/Makefile",
    "content": "##############################################################################\n# LuaJIT Makefile. Requires GNU Make.\n#\n# Please read doc/install.html before changing any variables!\n#\n# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).\n# Also works with MinGW and Cygwin on Windows.\n# Please check msvcbuild.bat for building with MSVC on Windows.\n#\n# Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n##############################################################################\n\nMAJVER=  2\nMINVER=  1\nRELVER=  0\nABIVER=  5.1\nNODOTABIVER= 51\n\n##############################################################################\n#############################  COMPILER OPTIONS  #############################\n##############################################################################\n# These options mainly affect the speed of the JIT compiler itself, not the\n# speed of the JIT-compiled code. Turn any of the optional settings on by\n# removing the '#' in front of them. Make sure you force a full recompile\n# with \"make clean\", followed by \"make\" if you change any options.\n#\nDEFAULT_CC = gcc\n#\n# LuaJIT builds as a native 32 or 64 bit binary by default.\nCC= $(DEFAULT_CC)\n#\n# Use this if you want to force a 32 bit build on a 64 bit multilib OS.\n#CC= $(DEFAULT_CC) -m32\n#\n# Since the assembler part does NOT maintain a frame pointer, it's pointless\n# to slow down the C part by not omitting it. Debugging, tracebacks and\n# unwinding are not affected -- the assembler part has frame unwind\n# information and GCC emits it where needed (x64) or with -g (see CCDEBUG).\nCCOPT= -O2 -fomit-frame-pointer\n# Use this if you want to generate a smaller binary (but it's slower):\n#CCOPT= -Os -fomit-frame-pointer\n# Note: it's no longer recommended to use -O3 with GCC 4.x.\n# The I-Cache bloat usually outweighs the benefits from aggressive inlining.\n#\n# Target-specific compiler options:\n#\n# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute\n# the binaries to a different machine you could also use: -march=native\n#\nCCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse\nCCOPT_x64=\nCCOPT_arm=\nCCOPT_arm64=\nCCOPT_ppc=\nCCOPT_mips=\n#\nCCDEBUG=\n# Uncomment the next line to generate debug information:\n#CCDEBUG= -g\n#\nCCWARN= -Wall\n# Uncomment the next line to enable more warnings:\n#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith\n#\n##############################################################################\n\n##############################################################################\n################################  BUILD MODE  ################################\n##############################################################################\n# The default build mode is mixed mode on POSIX. On Windows this is the same\n# as dynamic mode.\n#\n# Mixed mode creates a static + dynamic library and a statically linked luajit.\nBUILDMODE= mixed\n#\n# Static mode creates a static library and a statically linked luajit.\n#BUILDMODE= static\n#\n# Dynamic mode creates a dynamic library and a dynamically linked luajit.\n# Note: this executable will only run when the library is installed!\n#BUILDMODE= dynamic\n#\n##############################################################################\n\n##############################################################################\n#################################  FEATURES  #################################\n##############################################################################\n# Enable/disable these features as needed, but make sure you force a full\n# recompile with \"make clean\", followed by \"make\".\nXCFLAGS=\n#\n# Permanently disable the FFI extension to reduce the size of the LuaJIT\n# executable. But please consider that the FFI library is compiled-in,\n# but NOT loaded by default. It only allocates any memory, if you actually\n# make use of it.\n#XCFLAGS+= -DLUAJIT_DISABLE_FFI\n#\n# Features from Lua 5.2 that are unlikely to break existing code are\n# enabled by default. Some other features that *might* break some existing\n# code (e.g. __pairs or os.execute() return values) can be enabled here.\n# Note: this does not provide full compatibility with Lua 5.2 at this time.\n#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT\n#\n# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.\n#XCFLAGS+= -DLUAJIT_DISABLE_JIT\n#\n# Some architectures (e.g. PPC) can use either single-number (1) or\n# dual-number (2) mode. Uncomment one of these lines to override the\n# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.\n#XCFLAGS+= -DLUAJIT_NUMMODE=1\n#XCFLAGS+= -DLUAJIT_NUMMODE=2\n#\n##############################################################################\n\n##############################################################################\n############################  DEBUGGING SUPPORT  #############################\n##############################################################################\n# Enable these options as needed, but make sure you force a full recompile\n# with \"make clean\", followed by \"make\".\n# Note that most of these are NOT suitable for benchmarking or release mode!\n#\n# Use the system provided memory allocator (realloc) instead of the\n# bundled memory allocator. This is slower, but sometimes helpful for\n# debugging. This option cannot be enabled on x64, since realloc usually\n# doesn't return addresses in the right address range.\n# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and\n# the only way to get useful results from it for all other architectures.\n#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC\n#\n# This define is required to run LuaJIT under Valgrind. The Valgrind\n# header files must be installed. You should enable debug information, too.\n# Use --suppressions=lj.supp to avoid some false positives.\n#XCFLAGS+= -DLUAJIT_USE_VALGRIND\n#\n# This is the client for the GDB JIT API. GDB 7.0 or higher is required\n# to make use of it. See lj_gdbjit.c for details. Enabling this causes\n# a non-negligible overhead, even when not running under GDB.\n#XCFLAGS+= -DLUAJIT_USE_GDBJIT\n#\n# Turn on assertions for the Lua/C API to debug problems with lua_* calls.\n# This is rather slow -- use only while developing C libraries/embeddings.\n#XCFLAGS+= -DLUA_USE_APICHECK\n#\n# Turn on assertions for the whole LuaJIT VM. This significantly slows down\n# everything. Use only if you suspect a problem with LuaJIT itself.\n#XCFLAGS+= -DLUA_USE_ASSERT\n#\n##############################################################################\n# You probably don't need to change anything below this line!\n##############################################################################\n\n##############################################################################\n# Host system detection.\n##############################################################################\n\nifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))\n  HOST_SYS= Windows\n  HOST_RM= del\nelse\n  HOST_SYS:= $(shell uname -s)\n  ifneq (,$(findstring MINGW,$(HOST_SYS)))\n    HOST_SYS= Windows\n    HOST_MSYS= mingw\n  endif\n  ifneq (,$(findstring CYGWIN,$(HOST_SYS)))\n    HOST_SYS= Windows\n    HOST_MSYS= cygwin\n  endif\n  # Use Clang for OSX host.\n  # XXX:remove this when build Android on OSX (mark by u0u0)\n  ifeq (Darwin,$(HOST_SYS))\n    ifneq (Linux, $(TARGET_SYS))\n      DEFAULT_CC= clang\n    endif\n  endif\nendif\n\n##############################################################################\n# Flags and options for host and target.\n##############################################################################\n\n# You can override the following variables at the make command line:\n#   CC       HOST_CC       STATIC_CC       DYNAMIC_CC\n#   CFLAGS   HOST_CFLAGS   TARGET_CFLAGS\n#   LDFLAGS  HOST_LDFLAGS  TARGET_LDFLAGS  TARGET_SHLDFLAGS\n#   LIBS     HOST_LIBS     TARGET_LIBS\n#   CROSS    HOST_SYS      TARGET_SYS      TARGET_FLAGS\n#\n# Cross-compilation examples:\n#   make HOST_CC=\"gcc -m32\" CROSS=i586-mingw32msvc- TARGET_SYS=Windows\n#   make HOST_CC=\"gcc -m32\" CROSS=powerpc-linux-gnu-\n\nASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)\nCCOPTIONS= $(CCDEBUG) $(ASOPTIONS)\nLDOPTIONS= $(CCDEBUG) $(LDFLAGS)\n\nHOST_CC= $(CC)\nHOST_RM= rm -f\n# If left blank, minilua is built and used. You can supply an installed\n# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua\nHOST_LUA=\n\nHOST_XCFLAGS= -I.\nHOST_XLDFLAGS=\nHOST_XLIBS=\nHOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)\nHOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)\nHOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)\n\nSTATIC_CC = $(CROSS)$(CC)\nDYNAMIC_CC = $(CROSS)$(CC) -fPIC\nTARGET_CC= $(STATIC_CC)\nTARGET_STCC= $(STATIC_CC)\nTARGET_DYNCC= $(DYNAMIC_CC)\nTARGET_LD= $(CROSS)$(CC)\nTARGET_AR= $(CROSS)ar rcus\nTARGET_STRIP= $(CROSS)strip\n\nTARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)\nTARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)\nTARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib\nTARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)\nTARGET_DLLNAME= lua$(NODOTABIVER).dll\nTARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)\nTARGET_DYNXLDOPTS=\n\nTARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE\nTARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE\nTARGET_XLDFLAGS=\nTARGET_XLIBS= -lm\nTARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ASFLAGS= $(ASOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)\nTARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)\nTARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)\n\nTARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)\nifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= x64\nelse\nifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= x86\nelse\nifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= arm\nelse\nifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= arm64\nelse\nifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))\n  ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))\n    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_LE\n  else\n    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_BE\n  endif\n  TARGET_LJARCH= ppc\nelse\nifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))\n  ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))\n    TARGET_ARCH= -D__MIPSEL__=1\n  endif\n  TARGET_LJARCH= mips\nelse\n  $(error Unsupported target architecture)\nendif\nendif\nendif\nendif\nendif\nendif\n\nifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))\n  TARGET_SYS= PS3\n  TARGET_ARCH+= -D__CELLOS_LV2__\n  TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC\n  TARGET_XLIBS+= -lpthread\nendif\n\nTARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))\nTARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))\n\nifneq (,$(PREFIX))\nifneq (/usr/local,$(PREFIX))\n  TARGET_XCFLAGS+= -DLUA_ROOT=\\\"$(PREFIX)\\\"\n  ifneq (/usr,$(PREFIX))\n    TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)\n  endif\nendif\nendif\nifneq (,$(MULTILIB))\n  TARGET_XCFLAGS+= -DLUA_MULTILIB=\\\"$(MULTILIB)\\\"\nendif\nifneq (,$(LMULTILIB))\n  TARGET_XCFLAGS+= -DLUA_LMULTILIB=\\\"$(LMULTILIB)\\\"\nendif\n\n##############################################################################\n# Target system detection.\n##############################################################################\n\nTARGET_SYS?= $(HOST_SYS)\nifeq (Windows,$(TARGET_SYS))\n  TARGET_STRIP+= --strip-unneeded\n  TARGET_XSHLDFLAGS= -shared\n  TARGET_DYNXLDOPTS=\nelse\nifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))\n  TARGET_XCFLAGS+= -fno-stack-protector\nendif\nifeq (Darwin,$(TARGET_SYS))\n  ifeq (,$(MACOSX_DEPLOYMENT_TARGET))\n    export MACOSX_DEPLOYMENT_TARGET=10.4\n  endif\n  TARGET_STRIP+= -x\n  TARGET_AR+= 2>/dev/null\n  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC\n  TARGET_DYNXLDOPTS=\n  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)\n  ifeq (x64,$(TARGET_LJARCH))\n    TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000\n    TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000\n  endif\nelse\nifeq (iOS,$(TARGET_SYS))\n  TARGET_STRIP+= -x\n  TARGET_AR+= 2>/dev/null\n  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC\n  TARGET_DYNXLDOPTS=\n  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)\n  ifeq (arm64,$(TARGET_LJARCH))\n    TARGET_XCFLAGS+= -fno-omit-frame-pointer\n  endif\nelse\n  ifneq (SunOS,$(TARGET_SYS))\n    ifneq (PS3,$(TARGET_SYS))\n      TARGET_XLDFLAGS+= -Wl,-E\n    endif\n  endif\n  ifeq (Linux,$(TARGET_SYS))\n    TARGET_XLIBS+= -ldl\n  endif\n  ifeq (GNU/kFreeBSD,$(TARGET_SYS))\n    TARGET_XLIBS+= -ldl\n  endif\nendif\nendif\nendif\n\nifneq ($(HOST_SYS),$(TARGET_SYS))\n  ifeq (Windows,$(TARGET_SYS))\n    HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS\n  else\n  ifeq (Linux,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX\n  else\n  ifeq (Darwin,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX\n  else\n  ifeq (iOS,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX\n  else\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER\n  endif\n  endif\n  endif\n  endif\nendif\n\nifneq (,$(CCDEBUG))\n  TARGET_STRIP= @:\nendif\n\n##############################################################################\n# Files and pathnames.\n##############################################################################\n\nMINILUA_O= host/minilua.o\nMINILUA_LIBS= -lm\nMINILUA_T= host/minilua\nMINILUA_X= $(MINILUA_T)\n\nifeq (,$(HOST_LUA))\n  HOST_LUA= $(MINILUA_X)\n  DASM_DEP= $(MINILUA_T)\nendif\n\nDASM_DIR= ../dynasm\nDASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua\nDASM_XFLAGS=\nDASM_AFLAGS=\nDASM_ARCH= $(TARGET_LJARCH)\n\nifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D ENDIAN_LE\nelse\n  DASM_AFLAGS+= -D ENDIAN_BE\nendif\nifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D P64\nendif\nifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D JIT\nendif\nifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D FFI\nendif\nifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D DUALNUM\nendif\nifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D FPU\n  TARGET_ARCH+= -DLJ_ARCH_HASFPU=1\nelse\n  TARGET_ARCH+= -DLJ_ARCH_HASFPU=0\nendif\nifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D HFABI\n  TARGET_ARCH+= -DLJ_ABI_SOFTFP=0\nelse\n  TARGET_ARCH+= -DLJ_ABI_SOFTFP=1\nendif\nifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D NO_UNWIND\n  TARGET_ARCH+= -DLUAJIT_NO_UNWIND\nendif\nDASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))\nifeq (Windows,$(TARGET_SYS))\n  DASM_AFLAGS+= -D WIN\nendif\nifeq (x64,$(TARGET_LJARCH))\n  ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))\n    DASM_ARCH= x86\n  endif\nelse\nifeq (arm,$(TARGET_LJARCH))\n  ifeq (iOS,$(TARGET_SYS))\n    DASM_AFLAGS+= -D IOS\n  endif\nelse\nifeq (ppc,$(TARGET_LJARCH))\n  ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D SQRT\n  endif\n  ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D ROUND\n  endif\n  ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D GPR64\n  endif\n  ifeq (PS3,$(TARGET_SYS))\n    DASM_AFLAGS+= -D PPE -D TOC\n  endif\n  ifneq (,$(findstring LJ_ARCH_PPC64 ,$(TARGET_TESTARCH)))\n    DASM_ARCH= ppc64\n  endif\nendif\nendif\nendif\n\nDASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)\nDASM_DASC= vm_$(DASM_ARCH).dasc\n\nBUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \\\n\t   host/buildvm_lib.o host/buildvm_fold.o\nBUILDVM_T= host/buildvm\nBUILDVM_X= $(BUILDVM_T)\n\nHOST_O= $(MINILUA_O) $(BUILDVM_O)\nHOST_T= $(MINILUA_T) $(BUILDVM_T)\n\nLJVM_S= lj_vm.S\nLJVM_O= lj_vm.o\nLJVM_BOUT= $(LJVM_S)\nLJVM_MODE= elfasm\n\nLJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \\\n\t lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o\nLJLIB_C= $(LJLIB_O:.o=.c)\n\nLJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \\\n\t  lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \\\n\t  lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \\\n\t  lj_strfmt.o lj_strfmt_num.o lj_api.o lj_profile.o \\\n\t  lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \\\n\t  lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \\\n\t  lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \\\n\t  lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \\\n\t  lj_asm.o lj_trace.o lj_gdbjit.o \\\n\t  lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \\\n\t  lj_carith.o lj_clib.o lj_cparse.o \\\n\t  lj_lib.o lj_alloc.o lib_aux.o \\\n\t  $(LJLIB_O) lib_init.o\n\nLJVMCORE_O= $(LJVM_O) $(LJCORE_O)\nLJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)\n\nLIB_VMDEF= jit/vmdef.lua\nLIB_VMDEFP= $(LIB_VMDEF)\n\nLUAJIT_O= luajit.o\nLUAJIT_A= libluajit.a\nLUAJIT_SO= libluajit.so\nLUAJIT_T= luajit\n\nALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)\nALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \\\n\t    host/buildvm_arch.h\nALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)\nWIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk\nALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)\n\n##############################################################################\n# Build mode handling.\n##############################################################################\n\n# Mixed mode defaults.\nTARGET_O= $(LUAJIT_A)\nTARGET_T= $(LUAJIT_T) $(LUAJIT_SO)\nTARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)\n\nifeq (Windows,$(TARGET_SYS))\n  TARGET_DYNCC= $(STATIC_CC)\n  LJVM_MODE= peobj\n  LJVM_BOUT= $(LJVM_O)\n  LUAJIT_T= luajit.exe\n  ifeq (cygwin,$(HOST_MSYS))\n    LUAJIT_SO= cyg$(TARGET_DLLNAME)\n  else\n    LUAJIT_SO= $(TARGET_DLLNAME)\n  endif\n  # Mixed mode is not supported on Windows. And static mode doesn't work well.\n  # C modules cannot be loaded, because they bind to lua51.dll.\n  ifneq (static,$(BUILDMODE))\n    BUILDMODE= dynamic\n    TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL\n  endif\nendif\nifeq (Darwin,$(TARGET_SYS))\n  LJVM_MODE= machasm\nendif\nifeq (iOS,$(TARGET_SYS))\n  LJVM_MODE= machasm\nendif\nifeq (SunOS,$(TARGET_SYS))\n  BUILDMODE= static\nendif\nifeq (PS3,$(TARGET_SYS))\n  BUILDMODE= static\nendif\n\nifeq (Windows,$(HOST_SYS))\n  MINILUA_T= host/minilua.exe\n  BUILDVM_T= host/buildvm.exe\n  ifeq (,$(HOST_MSYS))\n    MINILUA_X= host\\minilua\n    BUILDVM_X= host\\buildvm\n    ALL_RM:= $(subst /,\\,$(ALL_RM))\n  endif\nendif\n\nifeq (static,$(BUILDMODE))\n  TARGET_DYNCC= @:\n  TARGET_T= $(LUAJIT_T)\n  TARGET_DEP= $(LIB_VMDEF)\nelse\nifeq (dynamic,$(BUILDMODE))\n  ifneq (Windows,$(TARGET_SYS))\n    TARGET_CC= $(DYNAMIC_CC)\n  endif\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\n  TARGET_O= $(LUAJIT_SO)\n  TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)\nelse\nifeq (Darwin,$(TARGET_SYS))\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\nendif\nifeq (iOS,$(TARGET_SYS))\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\nendif\nendif\nendif\n\nQ= @\nE= @echo\n#Q=\n#E= @:\n\n##############################################################################\n# Make targets.\n##############################################################################\n\ndefault all:\t$(TARGET_T)\n\namalg:\n\t@grep \"^[+|]\" ljamalg.c\n\t$(MAKE) all \"LJCORE_O=ljamalg.o\"\n\nclean:\n\t$(HOST_RM) $(ALL_RM)\n\nlibbc:\n\t./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)\n\t$(MAKE) all\n\ndepend:\n\t@for file in $(ALL_HDRGEN); do \\\n\t  test -f $$file || touch $$file; \\\n\t  done\n\t@$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \\\n\t  sed -e \"s| [^ ]*/dasm_\\S*\\.h||g\" \\\n\t      -e \"s|^\\([^l ]\\)|host/\\1|\" \\\n\t      -e \"s| lj_target_\\S*\\.h| lj_target_*.h|g\" \\\n\t      -e \"s| lj_emit_\\S*\\.h| lj_emit_*.h|g\" \\\n\t      -e \"s| lj_asm_\\S*\\.h| lj_asm_*.h|g\" >Makefile.dep\n\t@for file in $(ALL_HDRGEN); do \\\n\t  test -s $$file || $(HOST_RM) $$file; \\\n\t  done\n\n.PHONY: default all amalg clean libbc depend\n\n##############################################################################\n# Rules for generated files.\n##############################################################################\n\n$(MINILUA_T): $(MINILUA_O)\n\t$(E) \"HOSTLINK  $@\"\n\t$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)\n\nhost/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua\n\t$(E) \"DYNASM    $@\"\n\t$(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)\n\nhost/buildvm.o: $(DASM_DIR)/dasm_*.h\n\n$(BUILDVM_T): $(BUILDVM_O)\n\t$(E) \"HOSTLINK  $@\"\n\t$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)\n\n$(LJVM_BOUT): $(BUILDVM_T)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@\n\nlj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)\n\nlj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)\n\nlj_libdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)\n\nlj_recdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)\n\n$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)\n\nlj_folddef.h: $(BUILDVM_T) lj_opt_fold.c\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c\n\n##############################################################################\n# Object file rules.\n##############################################################################\n\n%.o: %.c\n\t$(E) \"CC        $@\"\n\t$(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<\n\t$(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<\n\n%.o: %.S\n\t$(E) \"ASM       $@\"\n\t$(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<\n\t$(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<\n\n$(LUAJIT_O):\n\t$(E) \"CC        $@\"\n\t$(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<\n\n$(HOST_O): %.o: %.c\n\t$(E) \"HOSTCC    $@\"\n\t$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<\n\ninclude Makefile.dep\n\n##############################################################################\n# Target file rules.\n##############################################################################\n\n$(LUAJIT_A): $(LJVMCORE_O)\n\t$(E) \"AR        $@\"\n\t$(Q)$(TARGET_AR) $@ $(LJVMCORE_O)\n\n# The dependency on _O, but linking with _DYNO is intentional.\n$(LUAJIT_SO): $(LJVMCORE_O)\n\t$(E) \"DYNLINK   $@\"\n\t$(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)\n\t$(Q)$(TARGET_STRIP) $@\n\n$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)\n\t$(E) \"LINK      $@\"\n\t$(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)\n\t$(Q)$(TARGET_STRIP) $@\n\t$(E) \"OK        Successfully built LuaJIT\"\n\n##############################################################################\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/Makefile.dep",
    "content": "lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_state.h lj_trace.h lj_jit.h lj_ir.h \\\n lj_dispatch.h lj_bc.h lj_traceerr.h lj_lib.h lj_alloc.h\nlib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h \\\n lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \\\n lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \\\n lj_strfmt.h lj_lib.h lj_libdef.h\nlib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \\\n lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \\\n lj_ffdef.h lj_lib.h lj_libdef.h\nlib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \\\n lj_libdef.h\nlib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \\\n lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \\\n lj_ccallback.h lj_clib.h lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h \\\n lj_libdef.h\nlib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h\nlib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_state.h \\\n lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h\nlib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \\\n lj_state.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \\\n lj_target.h lj_target_*.h lj_trace.h lj_dispatch.h lj_traceerr.h \\\n lj_vm.h lj_vmevent.h lj_lib.h luajit.h lj_libdef.h\nlib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_libdef.h\nlib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_lib.h \\\n lj_libdef.h\nlib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h\nlib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \\\n lj_tab.h lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h \\\n lj_char.h lj_strfmt.h lj_lib.h lj_libdef.h\nlib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \\\n lj_tab.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h\nlj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h\nlj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \\\n lj_meta.h lj_state.h lj_bc.h lj_frame.h lj_trace.h lj_jit.h lj_ir.h \\\n lj_dispatch.h lj_traceerr.h lj_vm.h lj_strscan.h lj_strfmt.h\nlj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h \\\n lj_ircall.h lj_iropt.h lj_mcode.h lj_trace.h lj_dispatch.h lj_traceerr.h \\\n lj_snap.h lj_asm.h lj_vm.h lj_target.h lj_target_*.h lj_emit_*.h \\\n lj_asm_*.h\nlj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \\\n lj_bcdef.h\nlj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_bc.h \\\n lj_ctype.h lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h \\\n lj_strfmt.h\nlj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_buf.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h \\\n lj_ir.h lj_strfmt.h lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h\nlj_buf.o: lj_buf.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_strfmt.h\nlj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ir.h lj_ctype.h \\\n lj_cconv.h lj_cdata.h lj_carith.h lj_strscan.h\nlj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h \\\n lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \\\n lj_traceerr.h\nlj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \\\n lj_bc.h lj_ctype.h lj_cconv.h lj_ccall.h lj_ccallback.h lj_target.h \\\n lj_target_*.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h\nlj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \\\n lj_ccallback.h\nlj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h\nlj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h\nlj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \\\n lj_cdata.h lj_clib.h lj_strfmt.h\nlj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_ctype.h lj_cparse.h \\\n lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h\nlj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_gc.h \\\n lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \\\n lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \\\n lj_crecord.h lj_strfmt.h\nlj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \\\n lj_ccallback.h lj_buf.h\nlj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \\\n lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h\nlj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \\\n lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \\\n lj_strfmt.h lj_jit.h lj_ir.h lj_ccallback.h lj_ctype.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_profile.h lj_vm.h luajit.h\nlj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \\\n lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \\\n lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h lj_strfmt.h\nlj_ffrecord.o: lj_ffrecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \\\n lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_crecord.h \\\n lj_vm.h lj_strscan.h lj_strfmt.h lj_recdef.h\nlj_func.o: lj_func.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_func.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \\\n lj_traceerr.h lj_vm.h\nlj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_func.h lj_udata.h \\\n lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h \\\n lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h\nlj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_buf.h \\\n lj_str.h lj_strfmt.h lj_jit.h lj_ir.h lj_dispatch.h\nlj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_buf.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \\\n lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h \\\n lj_carith.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lib.h\nlj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h \\\n lualib.h lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h \\\n lj_strfmt.h\nlj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \\\n lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lex.h \\\n lj_bcdump.h lj_lib.h\nlj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_func.h \\\n lj_frame.h lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h\nlj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_jit.h lj_ir.h lj_mcode.h lj_trace.h \\\n lj_dispatch.h lj_bc.h lj_traceerr.h lj_vm.h\nlj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_meta.h lj_frame.h \\\n lj_bc.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lib.h\nlj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h\nlj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_jit.h lj_iropt.h\nlj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \\\n lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \\\n lj_carith.h lj_vm.h lj_strscan.h lj_strfmt.h lj_folddef.h\nlj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \\\n lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \\\n lj_vm.h\nlj_opt_mem.o: lj_opt_mem.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_ircall.h\nlj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h lj_strscan.h\nlj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h\nlj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h \\\n lj_jit.h lj_ircall.h lj_iropt.h lj_vm.h\nlj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \\\n lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_strfmt.h lj_lex.h lj_parse.h \\\n lj_vm.h lj_vmevent.h\nlj_profile.o: lj_profile.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_buf.h lj_gc.h lj_str.h lj_frame.h lj_bc.h lj_debug.h lj_dispatch.h \\\n lj_jit.h lj_ir.h lj_trace.h lj_traceerr.h lj_profile.h luajit.h\nlj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \\\n lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_debug.h lj_ir.h lj_jit.h \\\n lj_ircall.h lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h \\\n lj_record.h lj_ffrecord.h lj_snap.h lj_vm.h\nlj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \\\n lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \\\n lj_target_*.h lj_ctype.h lj_cdata.h\nlj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_func.h \\\n lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h \\\n lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h luajit.h\nlj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_str.h lj_char.h\nlj_strfmt.o: lj_strfmt.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_buf.h lj_gc.h lj_str.h lj_state.h lj_char.h lj_strfmt.h\nlj_strfmt_num.o: lj_strfmt_num.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_buf.h lj_gc.h lj_str.h lj_strfmt.h\nlj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_char.h lj_strscan.h\nlj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_tab.h\nlj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_frame.h lj_bc.h \\\n lj_state.h lj_ir.h lj_jit.h lj_iropt.h lj_mcode.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_snap.h lj_gdbjit.h lj_record.h lj_asm.h \\\n lj_vm.h lj_vmevent.h lj_target.h lj_target_*.h\nlj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_udata.h\nlj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \\\n lj_vm.h lj_vmevent.h\nlj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_vm.h\nljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h \\\n lj_func.h lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h \\\n lj_cdata.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h \\\n lj_vm.h lj_err.c lj_debug.h lj_ff.h lj_ffdef.h lj_strfmt.h lj_char.c \\\n lj_char.h lj_bc.c lj_bcdef.h lj_obj.c lj_buf.c lj_str.c lj_tab.c \\\n lj_func.c lj_udata.c lj_meta.c lj_strscan.h lj_lib.h lj_debug.c \\\n lj_state.c lj_lex.h lj_alloc.h luajit.h lj_dispatch.c lj_ccallback.h \\\n lj_profile.h lj_vmevent.c lj_vmevent.h lj_vmmath.c lj_strscan.c \\\n lj_strfmt.c lj_api.c lj_profile.c lj_lex.c lualib.h lj_parse.h \\\n lj_parse.c lj_bcread.c lj_bcdump.h lj_bcwrite.c lj_load.c lj_ctype.c \\\n lj_cdata.c lj_cconv.h lj_cconv.c lj_ccall.c lj_ccall.h lj_ccallback.c \\\n lj_target.h lj_target_*.h lj_mcode.h lj_carith.c lj_carith.h lj_clib.c \\\n lj_clib.h lj_cparse.c lj_cparse.h lj_lib.c lj_ir.c lj_ircall.h \\\n lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \\\n lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_opt_split.c lj_opt_sink.c \\\n lj_mcode.c lj_snap.c lj_record.c lj_record.h lj_ffrecord.h lj_crecord.c \\\n lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h lj_emit_*.h \\\n lj_asm_*.h lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c \\\n lib_base.c lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \\\n lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c \\\n lib_init.c\nluajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h\nhost/buildvm.o: host/buildvm.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_gc.h lj_obj.h lj_bc.h lj_ir.h \\\n lj_ircall.h lj_ir.h lj_jit.h lj_frame.h lj_bc.h lj_dispatch.h lj_ctype.h \\\n lj_gc.h lj_ccall.h lj_ctype.h luajit.h \\\n host/buildvm_arch.h lj_traceerr.h\nhost/buildvm_asm.o: host/buildvm_asm.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_bc.h lj_def.h lj_arch.h\nhost/buildvm_fold.o: host/buildvm_fold.c host/buildvm.h lj_def.h lua.h \\\n luaconf.h lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_ir.h lj_obj.h\nhost/buildvm_lib.o: host/buildvm_lib.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_bc.h lj_lib.h lj_obj.h \\\n host/buildvm_libbc.h\nhost/buildvm_peobj.o: host/buildvm_peobj.c host/buildvm.h lj_def.h lua.h \\\n luaconf.h lj_arch.h lj_bc.h lj_def.h lj_arch.h\nhost/minilua.o: host/minilua.c\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/README",
    "content": "The files in this directory are only used during the build process of LuaJIT.\nFor cross-compilation, they must be executed on the host, not on the target.\n\nThese files should NOT be installed!\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm.c",
    "content": "/*\n** LuaJIT VM builder.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** This is a tool to build the hand-tuned assembler code required for\n** LuaJIT's bytecode interpreter. It supports a variety of output formats\n** to feed different toolchains (see usage() below).\n**\n** This tool is not particularly optimized because it's only used while\n** _building_ LuaJIT. There's no point in distributing or installing it.\n** Only the object code generated by this tool is linked into LuaJIT.\n**\n** Caveat: some memory is not free'd, error handling is lazy.\n** It's a one-shot tool -- any effort fixing this would be wasted.\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_ircall.h\"\n#include \"lj_frame.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_ccall.h\"\n#endif\n#include \"luajit.h\"\n\n#if defined(_WIN32)\n#include <fcntl.h>\n#include <io.h>\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n/* DynASM glue definitions. */\n#define Dst\t\tctx\n#define Dst_DECL\tBuildCtx *ctx\n#define Dst_REF\t\t(ctx->D)\n#define DASM_CHECKS\t1\n\n#include \"../dynasm/dasm_proto.h\"\n\n/* Glue macros for DynASM. */\nstatic int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);\n\n#define DASM_EXTERN(ctx, addr, idx, type) \\\n  collect_reloc(ctx, addr, idx, type)\n\n/* ------------------------------------------------------------------------ */\n\n/* Avoid trouble if cross-compiling for an x86 target. Speed doesn't matter. */\n#define DASM_ALIGNED_WRITES\t1\n\n/* Embed architecture-specific DynASM encoder. */\n#if LJ_TARGET_X86ORX64\n#include \"../dynasm/dasm_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"../dynasm/dasm_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"../dynasm/dasm_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"../dynasm/dasm_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"../dynasm/dasm_mips.h\"\n#else\n#error \"No support for this architecture (yet)\"\n#endif\n\n/* Embed generated architecture-specific backend. */\n#include \"buildvm_arch.h\"\n\n/* ------------------------------------------------------------------------ */\n\nvoid owrite(BuildCtx *ctx, const void *ptr, size_t sz)\n{\n  if (fwrite(ptr, 1, sz, ctx->fp) != sz) {\n    fprintf(stderr, \"Error: cannot write to output file: %s\\n\",\n\t    strerror(errno));\n    exit(1);\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Emit code as raw bytes. Only used for DynASM debugging. */\nstatic void emit_raw(BuildCtx *ctx)\n{\n  owrite(ctx, ctx->code, ctx->codesz);\n}\n\n/* -- Build machine code -------------------------------------------------- */\n\nstatic const char *sym_decorate(BuildCtx *ctx,\n\t\t\t\tconst char *prefix, const char *suffix)\n{\n  char name[256];\n  char *p;\n#if LJ_64\n  const char *symprefix = ctx->mode == BUILD_machasm ? \"_\" : \"\";\n#elif LJ_TARGET_XBOX360\n  const char *symprefix = \"\";\n#else\n  const char *symprefix = ctx->mode != BUILD_elfasm ? \"_\" : \"\";\n#endif\n  sprintf(name, \"%s%s%s\", symprefix, prefix, suffix);\n  p = strchr(name, '@');\n  if (p) {\n#if LJ_TARGET_X86ORX64\n    if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj))\n      name[0] = '@';\n    else\n      *p = '\\0';\n#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE\n    /* Keep @plt etc. */\n#else\n    *p = '\\0';\n#endif\n  }\n  p = (char *)malloc(strlen(name)+1);  /* MSVC doesn't like strdup. */\n  strcpy(p, name);\n  return p;\n}\n\n#define NRELOCSYM\t(sizeof(extnames)/sizeof(extnames[0])-1)\n\nstatic int relocmap[NRELOCSYM];\n\n/* Collect external relocations. */\nstatic int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)\n{\n  if (ctx->nreloc >= BUILD_MAX_RELOC) {\n    fprintf(stderr, \"Error: too many relocations, increase BUILD_MAX_RELOC.\\n\");\n    exit(1);\n  }\n  if (relocmap[idx] < 0) {\n    relocmap[idx] = ctx->nrelocsym;\n    ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, \"\", extnames[idx]);\n    ctx->nrelocsym++;\n  }\n  ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code);\n  ctx->reloc[ctx->nreloc].sym = relocmap[idx];\n  ctx->reloc[ctx->nreloc].type = type;\n  ctx->nreloc++;\n#if LJ_TARGET_XBOX360\n  return (int)(ctx->code - addr) + 4;  /* Encode symbol offset of .text. */\n#else\n  return 0;  /* Encode symbol offset of 0. */\n#endif\n}\n\n/* Naive insertion sort. Performance doesn't matter here. */\nstatic void sym_insert(BuildCtx *ctx, int32_t ofs,\n\t\t       const char *prefix, const char *suffix)\n{\n  ptrdiff_t i = ctx->nsym++;\n  while (i > 0) {\n    if (ctx->sym[i-1].ofs <= ofs)\n      break;\n    ctx->sym[i] = ctx->sym[i-1];\n    i--;\n  }\n  ctx->sym[i].ofs = ofs;\n  ctx->sym[i].name = sym_decorate(ctx, prefix, suffix);\n}\n\n/* Build the machine code. */\nstatic int build_code(BuildCtx *ctx)\n{\n  int status;\n  int i;\n\n  /* Initialize DynASM structures. */\n  ctx->nglob = GLOB__MAX;\n  ctx->glob = (void **)malloc(ctx->nglob*sizeof(void *));\n  memset(ctx->glob, 0, ctx->nglob*sizeof(void *));\n  ctx->nreloc = 0;\n\n  ctx->globnames = globnames;\n  ctx->extnames = extnames;\n  ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *));\n  ctx->nrelocsym = 0;\n  for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1;\n\n  ctx->dasm_ident = DASM_IDENT;\n  ctx->dasm_arch = DASM_ARCH;\n\n  dasm_init(Dst, DASM_MAXSECTION);\n  dasm_setupglobal(Dst, ctx->glob, ctx->nglob);\n  dasm_setup(Dst, build_actionlist);\n\n  /* Call arch-specific backend to emit the code. */\n  ctx->npc = build_backend(ctx);\n\n  /* Finalize the code. */\n  (void)dasm_checkstep(Dst, -1);\n  if ((status = dasm_link(Dst, &ctx->codesz))) return status;\n  ctx->code = (uint8_t *)malloc(ctx->codesz);\n  if ((status = dasm_encode(Dst, (void *)ctx->code))) return status;\n\n  /* Allocate symbol table and bytecode offsets. */\n  ctx->beginsym = sym_decorate(ctx, \"\", LABEL_PREFIX \"vm_asm_begin\");\n  ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym));\n  ctx->nsym = 0;\n  ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t));\n\n  /* Collect the opcodes (PC labels). */\n  for (i = 0; i < ctx->npc; i++) {\n    int32_t ofs = dasm_getpclabel(Dst, i);\n    if (ofs < 0) return 0x22000000|i;\n    ctx->bc_ofs[i] = ofs;\n    if ((LJ_HASJIT ||\n\t !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP ||\n\t   i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) &&\n\t(LJ_HASFFI || i != BC_KCDATA))\n      sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]);\n  }\n\n  /* Collect the globals (named labels). */\n  for (i = 0; i < ctx->nglob; i++) {\n    const char *gl = globnames[i];\n    int len = (int)strlen(gl);\n    if (!ctx->glob[i]) {\n      fprintf(stderr, \"Error: undefined global %s\\n\", gl);\n      exit(2);\n    }\n    /* Skip the _Z symbols. */\n    if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z'))\n      sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code),\n\t\t LABEL_PREFIX, globnames[i]);\n  }\n\n  /* Close the address range. */\n  sym_insert(ctx, (int32_t)ctx->codesz, \"\", \"\");\n  ctx->nsym--;\n\n  dasm_free(Dst);\n\n  return 0;\n}\n\n/* -- Generate VM enums --------------------------------------------------- */\n\nconst char *const bc_names[] = {\n#define BCNAME(name, ma, mb, mc, mt)       #name,\nBCDEF(BCNAME)\n#undef BCNAME\n  NULL\n};\n\nconst char *const ir_names[] = {\n#define IRNAME(name, m, m1, m2)\t#name,\nIRDEF(IRNAME)\n#undef IRNAME\n  NULL\n};\n\nconst char *const irt_names[] = {\n#define IRTNAME(name, size)\t#name,\nIRTDEF(IRTNAME)\n#undef IRTNAME\n  NULL\n};\n\nconst char *const irfpm_names[] = {\n#define FPMNAME(name)\t\t#name,\nIRFPMDEF(FPMNAME)\n#undef FPMNAME\n  NULL\n};\n\nconst char *const irfield_names[] = {\n#define FLNAME(name, ofs)\t#name,\nIRFLDEF(FLNAME)\n#undef FLNAME\n  NULL\n};\n\nconst char *const ircall_names[] = {\n#define IRCALLNAME(cond, name, nargs, kind, type, flags)\t#name,\nIRCALLDEF(IRCALLNAME)\n#undef IRCALLNAME\n  NULL\n};\n\nstatic const char *const trace_errors[] = {\n#define TREDEF(name, msg)\tmsg,\n#include \"lj_traceerr.h\"\n  NULL\n};\n\nstatic const char *lower(char *buf, const char *s)\n{\n  char *p = buf;\n  while (*s) {\n    *p++ = (*s >= 'A' && *s <= 'Z') ? *s+0x20 : *s;\n    s++;\n  }\n  *p = '\\0';\n  return buf;\n}\n\n/* Emit C source code for bytecode-related definitions. */\nstatic void emit_bcdef(BuildCtx *ctx)\n{\n  int i;\n  fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  fprintf(ctx->fp, \"LJ_DATADEF const uint16_t lj_bc_ofs[] = {\\n\");\n  for (i = 0; i < ctx->npc; i++) {\n    if (i != 0)\n      fprintf(ctx->fp, \",\\n\");\n    fprintf(ctx->fp, \"%d\", ctx->bc_ofs[i]);\n  }\n}\n\n/* Emit VM definitions as Lua code for debug modules. */\nstatic void emit_vmdef(BuildCtx *ctx)\n{\n  char buf[80];\n  int i;\n  fprintf(ctx->fp, \"-- This is a generated file. DO NOT EDIT!\\n\\n\");\n  fprintf(ctx->fp, \"return {\\n\\n\");\n\n  fprintf(ctx->fp, \"bcnames = \\\"\");\n  for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, \"%-6s\", bc_names[i]);\n  fprintf(ctx->fp, \"\\\",\\n\\n\");\n\n  fprintf(ctx->fp, \"irnames = \\\"\");\n  for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, \"%-6s\", ir_names[i]);\n  fprintf(ctx->fp, \"\\\",\\n\\n\");\n\n  fprintf(ctx->fp, \"irfpm = { [0]=\");\n  for (i = 0; irfpm_names[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\", \", lower(buf, irfpm_names[i]));\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"irfield = { [0]=\");\n  for (i = 0; irfield_names[i]; i++) {\n    char *p;\n    lower(buf, irfield_names[i]);\n    p = strchr(buf, '_');\n    if (p) *p = '.';\n    fprintf(ctx->fp, \"\\\"%s\\\", \", buf);\n  }\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"ircall = {\\n[0]=\");\n  for (i = 0; ircall_names[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", ircall_names[i]);\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"traceerr = {\\n[0]=\");\n  for (i = 0; trace_errors[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", trace_errors[i]);\n  fprintf(ctx->fp, \"},\\n\\n\");\n}\n\n/* -- Argument parsing ---------------------------------------------------- */\n\n/* Build mode names. */\nstatic const char *const modenames[] = {\n#define BUILDNAME(name)\t\t#name,\nBUILDDEF(BUILDNAME)\n#undef BUILDNAME\n  NULL\n};\n\n/* Print usage information and exit. */\nstatic void usage(void)\n{\n  int i;\n  fprintf(stderr, LUAJIT_VERSION \" VM builder.\\n\");\n  fprintf(stderr, LUAJIT_COPYRIGHT \", \" LUAJIT_URL \"\\n\");\n  fprintf(stderr, \"Target architecture: \" LJ_ARCH_NAME \"\\n\\n\");\n  fprintf(stderr, \"Usage: buildvm -m mode [-o outfile] [infiles...]\\n\\n\");\n  fprintf(stderr, \"Available modes:\\n\");\n  for (i = 0; i < BUILD__MAX; i++)\n    fprintf(stderr, \"  %s\\n\", modenames[i]);\n  exit(1);\n}\n\n/* Parse the output mode name. */\nstatic BuildMode parsemode(const char *mode)\n{\n  int i;\n  for (i = 0; modenames[i]; i++)\n    if (!strcmp(mode, modenames[i]))\n      return (BuildMode)i;\n  usage();\n  return (BuildMode)-1;\n}\n\n/* Parse arguments. */\nstatic void parseargs(BuildCtx *ctx, char **argv)\n{\n  const char *a;\n  int i;\n  ctx->mode = (BuildMode)-1;\n  ctx->outname = \"-\";\n  for (i = 1; (a = argv[i]) != NULL; i++) {\n    if (a[0] != '-')\n      break;\n    switch (a[1]) {\n    case '-':\n      if (a[2]) goto err;\n      i++;\n      goto ok;\n    case '\\0':\n      goto ok;\n    case 'm':\n      i++;\n      if (a[2] || argv[i] == NULL) goto err;\n      ctx->mode = parsemode(argv[i]);\n      break;\n    case 'o':\n      i++;\n      if (a[2] || argv[i] == NULL) goto err;\n      ctx->outname = argv[i];\n      break;\n    default: err:\n      usage();\n      break;\n    }\n  }\nok:\n  ctx->args = argv+i;\n  if (ctx->mode == (BuildMode)-1) goto err;\n}\n\nint main(int argc, char **argv)\n{\n  BuildCtx ctx_;\n  BuildCtx *ctx = &ctx_;\n  int status, binmode;\n\n  if (sizeof(void *) != 4*LJ_32+8*LJ_64) {\n    fprintf(stderr,\"Error: pointer size mismatch in cross-build.\\n\");\n    fprintf(stderr,\"Try: make HOST_CC=\\\"gcc -m32\\\" CROSS=...\\n\\n\");\n    return 1;\n  }\n\n  UNUSED(argc);\n  parseargs(ctx, argv);\n\n  if ((status = build_code(ctx))) {\n    fprintf(stderr,\"Error: DASM error %08x\\n\", status);\n    return 1;\n  }\n\n  switch (ctx->mode) {\n  case BUILD_peobj:\n  case BUILD_raw:\n    binmode = 1;\n    break;\n  default:\n    binmode = 0;\n    break;\n  }\n\n  if (ctx->outname[0] == '-' && ctx->outname[1] == '\\0') {\n    ctx->fp = stdout;\n#if defined(_WIN32)\n    if (binmode)\n      _setmode(_fileno(stdout), _O_BINARY);  /* Yuck. */\n#endif\n  } else if (!(ctx->fp = fopen(ctx->outname, binmode ? \"wb\" : \"w\"))) {\n    fprintf(stderr, \"Error: cannot open output file '%s': %s\\n\",\n\t    ctx->outname, strerror(errno));\n    exit(1);\n  }\n\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n  case BUILD_coffasm:\n  case BUILD_machasm:\n    emit_asm(ctx);\n    emit_asm_debug(ctx);\n    break;\n  case BUILD_peobj:\n    emit_peobj(ctx);\n    break;\n  case BUILD_raw:\n    emit_raw(ctx);\n    break;\n  case BUILD_bcdef:\n    emit_bcdef(ctx);\n    emit_lib(ctx);\n    break;\n  case BUILD_vmdef:\n    emit_vmdef(ctx);\n    emit_lib(ctx);\n    fprintf(ctx->fp, \"}\\n\\n\");\n    break;\n  case BUILD_ffdef:\n  case BUILD_libdef:\n  case BUILD_recdef:\n    emit_lib(ctx);\n    break;\n  case BUILD_folddef:\n    emit_fold(ctx);\n    break;\n  default:\n    break;\n  }\n\n  fflush(ctx->fp);\n  if (ferror(ctx->fp)) {\n    fprintf(stderr, \"Error: cannot write to output file: %s\\n\",\n\t    strerror(errno));\n    exit(1);\n  }\n  fclose(ctx->fp);\n\n  return 0;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm.h",
    "content": "/*\n** LuaJIT VM builder.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _BUILDVM_H\n#define _BUILDVM_H\n\n#include <sys/types.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* Hardcoded limits. Increase as needed. */\n#define BUILD_MAX_RELOC\t\t200\t/* Max. number of relocations. */\n#define BUILD_MAX_FOLD\t\t4096\t/* Max. number of fold rules. */\n\n/* Prefix for scanned library definitions. */\n#define LIBDEF_PREFIX\t\t\"LJLIB_\"\n\n/* Prefix for scanned fold definitions. */\n#define FOLDDEF_PREFIX\t\t\"LJFOLD\"\n\n/* Prefixes for generated labels. */\n#define LABEL_PREFIX\t\t\"lj_\"\n#define LABEL_PREFIX_BC\t\tLABEL_PREFIX \"BC_\"\n#define LABEL_PREFIX_FF\t\tLABEL_PREFIX \"ff_\"\n#define LABEL_PREFIX_CF\t\tLABEL_PREFIX \"cf_\"\n#define LABEL_PREFIX_FFH\tLABEL_PREFIX \"ffh_\"\n#define LABEL_PREFIX_LIBCF\tLABEL_PREFIX \"lib_cf_\"\n#define LABEL_PREFIX_LIBINIT\tLABEL_PREFIX \"lib_init_\"\n\n/* Forward declaration. */\nstruct dasm_State;\n\n/* Build modes. */\n#define BUILDDEF(_) \\\n  _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \\\n  _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \\\n  _(folddef)\n\ntypedef enum {\n#define BUILDENUM(name)\t\tBUILD_##name,\nBUILDDEF(BUILDENUM)\n#undef BUILDENUM\n  BUILD__MAX\n} BuildMode;\n\n/* Code relocation. */\ntypedef struct BuildReloc {\n  int32_t ofs;\n  int sym;\n  int type;\n} BuildReloc;\n\ntypedef struct BuildSym {\n  const char *name;\n  int32_t ofs;\n} BuildSym;\n\n/* Build context structure. */\ntypedef struct BuildCtx {\n  /* DynASM state pointer. Should be first member. */\n  struct dasm_State *D;\n  /* Parsed command line. */\n  BuildMode mode;\n  FILE *fp;\n  const char *outname;\n  char **args;\n  /* Code and symbols generated by DynASM. */\n  uint8_t *code;\n  size_t codesz;\n  int npc, nglob, nsym, nreloc, nrelocsym;\n  void **glob;\n  BuildSym *sym;\n  const char **relocsym;\n  int32_t *bc_ofs;\n  const char *beginsym;\n  /* Strings generated by DynASM. */\n  const char *const *globnames;\n  const char *const *extnames;\n  const char *dasm_ident;\n  const char *dasm_arch;\n  /* Relocations. */\n  BuildReloc reloc[BUILD_MAX_RELOC];\n} BuildCtx;\n\nextern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);\nextern void emit_asm(BuildCtx *ctx);\nextern void emit_peobj(BuildCtx *ctx);\nextern void emit_lib(BuildCtx *ctx);\nextern void emit_fold(BuildCtx *ctx);\n\nextern const char *const bc_names[];\nextern const char *const ir_names[];\nextern const char *const irt_names[];\nextern const char *const irfpm_names[];\nextern const char *const irfield_names[];\nextern const char *const ircall_names[];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm_asm.c",
    "content": "/*\n** LuaJIT VM builder: Assembler source code emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_bc.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#if LJ_TARGET_X86ORX64\n/* Emit bytes piecewise as assembler text. */\nstatic void emit_asm_bytes(BuildCtx *ctx, uint8_t *p, int n)\n{\n  int i;\n  for (i = 0; i < n; i++) {\n    if ((i & 15) == 0)\n      fprintf(ctx->fp, \"\\t.byte %d\", p[i]);\n    else\n      fprintf(ctx->fp, \",%d\", p[i]);\n    if ((i & 15) == 15) putc('\\n', ctx->fp);\n  }\n  if ((n & 15) != 0) putc('\\n', ctx->fp);\n}\n\n/* Emit relocation */\nstatic void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    if (type)\n      fprintf(ctx->fp, \"\\t.long %s-.-4\\n\", sym);\n    else\n      fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.def %s; .scl 3; .type 32; .endef\\n\", sym);\n    if (type)\n      fprintf(ctx->fp, \"\\t.long %s-.-4\\n\", sym);\n    else\n      fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  default:  /* BUILD_machasm for relative relocations handled below. */\n    fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  }\n}\n\nstatic const char *const jccnames[] = {\n  \"jo\", \"jno\", \"jb\", \"jnb\", \"jz\", \"jnz\", \"jbe\", \"ja\",\n  \"js\", \"jns\", \"jpe\", \"jpo\", \"jl\", \"jge\", \"jle\", \"jg\"\n};\n\n/* Emit x86/x64 text relocations. */\nstatic void emit_asm_reloc_text(BuildCtx *ctx, uint8_t *cp, int n,\n\t\t\t\tconst char *sym)\n{\n  const char *opname = NULL;\n  if (--n < 0) goto err;\n  if (cp[n] == 0xe8) {\n    opname = \"call\";\n  } else if (cp[n] == 0xe9) {\n    opname = \"jmp\";\n  } else if (cp[n] >= 0x80 && cp[n] <= 0x8f && n > 0 && cp[n-1] == 0x0f) {\n    opname = jccnames[cp[n]-0x80];\n    n--;\n  } else {\nerr:\n    fprintf(stderr, \"Error: unsupported opcode for %s symbol relocation.\\n\",\n\t    sym);\n    exit(1);\n  }\n  emit_asm_bytes(ctx, cp, n);\n  if (strncmp(sym+(*sym == '_'), LABEL_PREFIX, sizeof(LABEL_PREFIX)-1)) {\n    /* Various fixups for external symbols outside of our binary. */\n    if (ctx->mode == BUILD_elfasm) {\n      if (LJ_32)\n\tfprintf(ctx->fp, \"#if __PIC__\\n\\t%s lj_wrap_%s\\n#else\\n\", opname, sym);\n      fprintf(ctx->fp, \"\\t%s %s@PLT\\n\", opname, sym);\n      if (LJ_32)\n\tfprintf(ctx->fp, \"#endif\\n\");\n      return;\n    } else if (LJ_32 && ctx->mode == BUILD_machasm) {\n      fprintf(ctx->fp, \"\\t%s L%s$stub\\n\", opname, sym);\n      return;\n    }\n  }\n  fprintf(ctx->fp, \"\\t%s %s\\n\", opname, sym);\n}\n#else\n/* Emit words piecewise as assembler text. */\nstatic void emit_asm_words(BuildCtx *ctx, uint8_t *p, int n)\n{\n  int i;\n  for (i = 0; i < n; i += 4) {\n    if ((i & 15) == 0)\n      fprintf(ctx->fp, \"\\t.long 0x%08x\", *(uint32_t *)(p+i));\n    else\n      fprintf(ctx->fp, \",0x%08x\", *(uint32_t *)(p+i));\n    if ((i & 15) == 12) putc('\\n', ctx->fp);\n  }\n  if ((n & 15) != 0) putc('\\n', ctx->fp);\n}\n\n/* Emit relocation as part of an instruction. */\nstatic void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n,\n\t\t\t       const char *sym)\n{\n  uint32_t ins;\n  emit_asm_words(ctx, p, n-4);\n  ins = *(uint32_t *)(p+n-4);\n#if LJ_TARGET_ARM\n  if ((ins & 0xff000000u) == 0xfa000000u) {\n    fprintf(ctx->fp, \"\\tblx %s\\n\", sym);\n  } else if ((ins & 0x0e000000u) == 0x0a000000u) {\n    fprintf(ctx->fp, \"\\t%s%.2s %s\\n\", (ins & 0x01000000u) ? \"bl\" : \"b\",\n\t    &\"eqnecsccmiplvsvchilsgeltgtle\"[2*(ins >> 28)], sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_ARM64\n  if ((ins >> 26) == 0x25u) {\n    fprintf(ctx->fp, \"\\tbl %s\\n\", sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_PPC\n#if LJ_TARGET_PS3\n#define TOCPREFIX \".\"\n#else\n#define TOCPREFIX \"\"\n#endif\n  if ((ins >> 26) == 16) {\n    fprintf(ctx->fp, \"\\t%s %d, %d, \" TOCPREFIX \"%s\\n\",\n\t    (ins & 1) ? \"bcl\" : \"bc\", (ins >> 21) & 31, (ins >> 16) & 31, sym);\n  } else if ((ins >> 26) == 18) {\n#if LJ_ARCH_PPC64\n    const char *suffix = strchr(sym, '@');\n    if (suffix && suffix[1] == 'h') {\n      fprintf(ctx->fp, \"\\taddis 11, 2, %s\\n\", sym);\n    } else if (suffix && suffix[1] == 'l') {\n      fprintf(ctx->fp, \"\\tld 12, %s\\n\", sym);\n    } else\n#endif\n    fprintf(ctx->fp, \"\\t%s \" TOCPREFIX \"%s\\n\", (ins & 1) ? \"bl\" : \"b\", sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_MIPS\n  fprintf(stderr,\n\t  \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t  ins, sym);\n  exit(1);\n#else\n#error \"missing relocation support for this architecture\"\n#endif\n}\n#endif\n\n#if LJ_TARGET_ARM\n#define ELFASM_PX\t\"%%\"\n#else\n#define ELFASM_PX\t\"@\"\n#endif\n\n/* Emit an assembler label. */\nstatic void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n#if LJ_TARGET_PS3\n    if (!strncmp(name, \"lj_vm_\", 6) &&\n\tstrcmp(name, ctx->beginsym) &&\n\t!strstr(name, \"hook\")) {\n      fprintf(ctx->fp,\n\t\"\\n\\t.globl %s\\n\"\n\t\"\\t.section \\\".opd\\\",\\\"aw\\\"\\n\"\n\t\"%s:\\n\"\n\t\"\\t.long .%s,.TOC.@tocbase32\\n\"\n\t\"\\t.size %s,8\\n\"\n\t\"\\t.previous\\n\"\n\t\"\\t.globl .%s\\n\"\n\t\"\\t.hidden .%s\\n\"\n\t\"\\t.type .%s, \" ELFASM_PX \"function\\n\"\n\t\"\\t.size .%s, %d\\n\"\n\t\".%s:\\n\",\n\tname, name, name, name, name, name, name, name, size, name);\n      break;\n    }\n#endif\n    fprintf(ctx->fp,\n      \"\\n\\t.globl %s\\n\"\n      \"\\t.hidden %s\\n\"\n      \"\\t.type %s, \" ELFASM_PX \"%s\\n\"\n      \"\\t.size %s, %d\\n\"\n      \"%s:\\n\",\n      name, name, name, isfunc ? \"function\" : \"object\", name, size, name);\n    break;\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\n\\t.globl %s\\n\", name);\n    if (isfunc)\n      fprintf(ctx->fp, \"\\t.def %s; .scl 3; .type 32; .endef\\n\", name);\n    fprintf(ctx->fp, \"%s:\\n\", name);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp,\n      \"\\n\\t.private_extern %s\\n\"\n      \"%s:\\n\", name, name);\n    break;\n  default:\n    break;\n  }\n}\n\n/* Emit alignment. */\nstatic void emit_asm_align(BuildCtx *ctx, int bits)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.p2align %d\\n\", bits);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp, \"\\t.align %d\\n\", bits);\n    break;\n  default:\n    break;\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Emit assembler source code. */\nvoid emit_asm(BuildCtx *ctx)\n{\n  int i, rel;\n\n  fprintf(ctx->fp, \"\\t.file \\\"buildvm_%s.dasc\\\"\\n\", ctx->dasm_arch);\n#if LJ_ARCH_PPC64\n  fprintf(ctx->fp, \"\\t.abiversion 2\\n\");\n#endif\n  fprintf(ctx->fp, \"\\t.text\\n\");\n  emit_asm_align(ctx, 4);\n\n#if LJ_TARGET_PS3\n  emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0);\n#else\n  emit_asm_label(ctx, ctx->beginsym, 0, 0);\n#endif\n  if (ctx->mode != BUILD_machasm)\n    fprintf(ctx->fp, \".Lbegin:\\n\");\n\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND\n  /* This should really be moved into buildvm_arm.dasc. */\n#if LJ_ARCH_HASFPU\n  fprintf(ctx->fp,\n\t  \".fnstart\\n\"\n\t  \".save {r5, r6, r7, r8, r9, r10, r11, lr}\\n\"\n\t  \".vsave {d8-d15}\\n\"\n\t  \".save {r4}\\n\"\n\t  \".pad #28\\n\");\n#else\n  fprintf(ctx->fp,\n\t  \".fnstart\\n\"\n\t  \".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\\n\"\n\t  \".pad #28\\n\");\n#endif\n#endif\n#if LJ_TARGET_MIPS\n  fprintf(ctx->fp, \".set nomips16\\n.abicalls\\n.set noreorder\\n.set nomacro\\n\");\n#endif\n\n  for (i = rel = 0; i < ctx->nsym; i++) {\n    int32_t ofs = ctx->sym[i].ofs;\n    int32_t next = ctx->sym[i+1].ofs;\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI\n    if (!strcmp(ctx->sym[i].name, \"lj_vm_ffi_call\"))\n      fprintf(ctx->fp,\n\t      \".globl lj_err_unwind_arm\\n\"\n\t      \".personality lj_err_unwind_arm\\n\"\n\t      \".fnend\\n\"\n\t      \".fnstart\\n\"\n\t      \".save {r4, r5, r11, lr}\\n\"\n\t      \".setfp r11, sp\\n\");\n#endif\n    emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);\n    while (rel < ctx->nreloc && ctx->reloc[rel].ofs <= next) {\n      BuildReloc *r = &ctx->reloc[rel];\n      int n = r->ofs - ofs;\n#if LJ_TARGET_X86ORX64\n      if (r->type != 0 &&\n\t  (ctx->mode == BUILD_elfasm || ctx->mode == BUILD_machasm)) {\n\temit_asm_reloc_text(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);\n      } else {\n\temit_asm_bytes(ctx, ctx->code+ofs, n);\n\temit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);\n      }\n      ofs += n+4;\n#else\n      emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);\n      ofs += n;\n#endif\n      rel++;\n    }\n#if LJ_TARGET_X86ORX64\n    emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);\n#else\n    emit_asm_words(ctx, ctx->code+ofs, next-ofs);\n#endif\n  }\n\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND\n  fprintf(ctx->fp,\n#if !LJ_HASFFI\n\t  \".globl lj_err_unwind_arm\\n\"\n\t  \".personality lj_err_unwind_arm\\n\"\n#endif\n\t  \".fnend\\n\");\n#endif\n\n  fprintf(ctx->fp, \"\\n\");\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA)\n    fprintf(ctx->fp, \"\\t.section .note.GNU-stack,\\\"\\\",\" ELFASM_PX \"progbits\\n\");\n#endif\n#if LJ_TARGET_PPC && !LJ_TARGET_PS3\n    /* Hard-float ABI. */\n    fprintf(ctx->fp, \"\\t.gnu_attribute 4, 1\\n\");\n#endif\n    /* fallthrough */\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.ident \\\"%s\\\"\\n\", ctx->dasm_ident);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp,\n      \"\\t.cstring\\n\"\n      \"\\t.ascii \\\"%s\\\\0\\\"\\n\", ctx->dasm_ident);\n    break;\n  default:\n    break;\n  }\n  fprintf(ctx->fp, \"\\n\");\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm_fold.c",
    "content": "/*\n** LuaJIT VM builder: IR folding hash table generator.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n\n/* Context for the folding hash table generator. */\nstatic int lineno;\nstatic int funcidx;\nstatic uint32_t foldkeys[BUILD_MAX_FOLD];\nstatic uint32_t nkeys;\n\n/* Try to fill the hash table with keys using the hash parameters. */\nstatic int tryhash(uint32_t *htab, uint32_t sz, uint32_t r, int dorol)\n{\n  uint32_t i;\n  if (dorol && ((r & 31) == 0 || (r>>5) == 0))\n    return 0;  /* Avoid zero rotates. */\n  memset(htab, 0xff, (sz+1)*sizeof(uint32_t));\n  for (i = 0; i < nkeys; i++) {\n    uint32_t key = foldkeys[i];\n    uint32_t k = key & 0xffffff;\n    uint32_t h = (dorol ? lj_rol(lj_rol(k, r>>5) - k, r&31) :\n\t\t\t  (((k << (r>>5)) - k) << (r&31))) % sz;\n    if (htab[h] != 0xffffffff) {  /* Collision on primary slot. */\n      if (htab[h+1] != 0xffffffff) {  /* Collision on secondary slot. */\n\t/* Try to move the colliding key, if possible. */\n\tif (h < sz-1 && htab[h+2] == 0xffffffff) {\n\t  uint32_t k2 = htab[h+1] & 0xffffff;\n\t  uint32_t h2 = (dorol ? lj_rol(lj_rol(k2, r>>5) - k2, r&31) :\n\t\t\t\t (((k2 << (r>>5)) - k2) << (r&31))) % sz;\n\t  if (h2 != h+1) return 0;  /* Cannot resolve collision. */\n\t  htab[h+2] = htab[h+1];  /* Move colliding key to secondary slot. */\n\t} else {\n\t  return 0;  /* Collision. */\n\t}\n      }\n      htab[h+1] = key;\n    } else {\n      htab[h] = key;\n    }\n  }\n  return 1;  /* Success, all keys could be stored. */\n}\n\n/* Print the generated hash table. */\nstatic void printhash(BuildCtx *ctx, uint32_t *htab, uint32_t sz)\n{\n  uint32_t i;\n  fprintf(ctx->fp, \"static const uint32_t fold_hash[%d] = {\\n0x%08x\",\n\t  sz+1, htab[0]);\n  for (i = 1; i < sz+1; i++)\n    fprintf(ctx->fp, \",\\n0x%08x\", htab[i]);\n  fprintf(ctx->fp, \"\\n};\\n\\n\");\n}\n\n/* Exhaustive search for the shortest semi-perfect hash table. */\nstatic void makehash(BuildCtx *ctx)\n{\n  uint32_t htab[BUILD_MAX_FOLD*2+1];\n  uint32_t sz, r;\n  /* Search for the smallest hash table with an odd size. */\n  for (sz = (nkeys|1); sz < BUILD_MAX_FOLD*2; sz += 2) {\n    /* First try all shift hash combinations. */\n    for (r = 0; r < 32*32; r++) {\n      if (tryhash(htab, sz, r, 0)) {\n\tprinthash(ctx, htab, sz);\n\tfprintf(ctx->fp,\n\t\t\"#define fold_hashkey(k)\\t(((((k)<<%u)-(k))<<%u)%%%u)\\n\\n\",\n\t\tr>>5, r&31, sz);\n\treturn;\n      }\n    }\n    /* Then try all rotate hash combinations. */\n    for (r = 0; r < 32*32; r++) {\n      if (tryhash(htab, sz, r, 1)) {\n\tprinthash(ctx, htab, sz);\n\tfprintf(ctx->fp,\n\t  \"#define fold_hashkey(k)\\t(lj_rol(lj_rol((k),%u)-(k),%u)%%%u)\\n\\n\",\n\t\tr>>5, r&31, sz);\n\treturn;\n      }\n    }\n  }\n  fprintf(stderr, \"Error: search for perfect hash failed\\n\");\n  exit(1);\n}\n\n/* Parse one token of a fold rule. */\nstatic uint32_t nexttoken(char **pp, int allowlit, int allowany)\n{\n  char *p = *pp;\n  if (p) {\n    uint32_t i;\n    char *q = strchr(p, ' ');\n    if (q) *q++ = '\\0';\n    *pp = q;\n    if (allowlit && !strncmp(p, \"IRFPM_\", 6)) {\n      for (i = 0; irfpm_names[i]; i++)\n\tif (!strcmp(irfpm_names[i], p+6))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRFL_\", 5)) {\n      for (i = 0; irfield_names[i]; i++)\n\tif (!strcmp(irfield_names[i], p+5))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRCALL_\", 7)) {\n      for (i = 0; ircall_names[i]; i++)\n\tif (!strcmp(ircall_names[i], p+7))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRCONV_\", 7)) {\n      for (i = 0; irt_names[i]; i++) {\n\tconst char *r = strchr(p+7, '_');\n\tif (r && !strncmp(irt_names[i], p+7, r-(p+7))) {\n\t  uint32_t j;\n\t  for (j = 0; irt_names[j]; j++)\n\t    if (!strcmp(irt_names[j], r+1))\n\t      return (i << 5) + j;\n\t}\n      }\n    } else if (allowlit && *p >= '0' && *p <= '9') {\n      for (i = 0; *p >= '0' && *p <= '9'; p++)\n\ti = i*10 + (*p - '0');\n      if (*p == '\\0')\n\treturn i;\n    } else if (allowany && !strcmp(\"any\", p)) {\n      return allowany;\n    } else {\n      for (i = 0; ir_names[i]; i++)\n\tif (!strcmp(ir_names[i], p))\n\t  return i;\n    }\n    fprintf(stderr, \"Error: bad fold definition token \\\"%s\\\" at line %d\\n\", p, lineno);\n    exit(1);\n  }\n  return 0;\n}\n\n/* Parse a fold rule. */\nstatic void foldrule(char *p)\n{\n  uint32_t op = nexttoken(&p, 0, 0);\n  uint32_t left = nexttoken(&p, 0, 0x7f);\n  uint32_t right = nexttoken(&p, 1, 0x3ff);\n  uint32_t key = (funcidx << 24) | (op << 17) | (left << 10) | right;\n  uint32_t i;\n  if (nkeys >= BUILD_MAX_FOLD) {\n    fprintf(stderr, \"Error: too many fold rules, increase BUILD_MAX_FOLD.\\n\");\n    exit(1);\n  }\n  /* Simple insertion sort to detect duplicates. */\n  for (i = nkeys; i > 0; i--) {\n    if ((foldkeys[i-1]&0xffffff) < (key & 0xffffff))\n      break;\n    if ((foldkeys[i-1]&0xffffff) == (key & 0xffffff)) {\n      fprintf(stderr, \"Error: duplicate fold definition at line %d\\n\", lineno);\n      exit(1);\n    }\n    foldkeys[i] = foldkeys[i-1];\n  }\n  foldkeys[i] = key;\n  nkeys++;\n}\n\n/* Emit C source code for IR folding hash table. */\nvoid emit_fold(BuildCtx *ctx)\n{\n  char buf[256];  /* We don't care about analyzing lines longer than that. */\n  const char *fname = ctx->args[0];\n  FILE *fp;\n\n  if (fname == NULL) {\n    fprintf(stderr, \"Error: missing input filename\\n\");\n    exit(1);\n  }\n\n  if (fname[0] == '-' && fname[1] == '\\0') {\n    fp = stdin;\n  } else {\n    fp = fopen(fname, \"r\");\n    if (!fp) {\n      fprintf(stderr, \"Error: cannot open input file '%s': %s\\n\",\n\t      fname, strerror(errno));\n      exit(1);\n    }\n  }\n\n  fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  fprintf(ctx->fp, \"static const FoldFunc fold_func[] = {\\n\");\n\n  lineno = 0;\n  funcidx = 0;\n  nkeys = 0;\n  while (fgets(buf, sizeof(buf), fp) != NULL) {\n    lineno++;\n    /* The prefix must be at the start of a line, otherwise it's ignored. */\n    if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) {\n      char *p = buf+sizeof(FOLDDEF_PREFIX)-1;\n      char *q = strchr(p, ')');\n      if (p[0] == '(' && q) {\n\tp++;\n\t*q = '\\0';\n\tfoldrule(p);\n      } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) {\n\tp += 2;\n\t*q = '\\0';\n\tif (funcidx)\n\t  fprintf(ctx->fp, \",\\n\");\n\tif (p[-2] == 'X')\n\t  fprintf(ctx->fp, \"  %s\", p);\n\telse\n\t  fprintf(ctx->fp, \"  fold_%s\", p);\n\tfuncidx++;\n      } else {\n\tbuf[strlen(buf)-1] = '\\0';\n\tfprintf(stderr, \"Error: unknown fold definition tag %s%s at line %d\\n\",\n\t\tFOLDDEF_PREFIX, p, lineno);\n\texit(1);\n      }\n    }\n  }\n  fclose(fp);\n  fprintf(ctx->fp, \"\\n};\\n\\n\");\n\n  makehash(ctx);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm_lib.c",
    "content": "/*\n** LuaJIT VM builder: library definition compiler.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n#include \"lj_lib.h\"\n#include \"buildvm_libbc.h\"\n\n/* Context for library definitions. */\nstatic uint8_t obuf[8192];\nstatic uint8_t *optr;\nstatic char modname[80];\nstatic size_t modnamelen;\nstatic char funcname[80];\nstatic int modstate, regfunc;\nstatic int ffid, recffid, ffasmfunc;\n\nenum {\n  REGFUNC_OK,\n  REGFUNC_NOREG,\n  REGFUNC_NOREGUV\n};\n\nstatic void libdef_name(const char *p, int kind)\n{\n  size_t n = strlen(p);\n  if (kind != LIBINIT_STRING) {\n    if (n > modnamelen && p[modnamelen] == '_' &&\n\t!strncmp(p, modname, modnamelen)) {\n      p += modnamelen+1;\n      n -= modnamelen+1;\n    }\n  }\n  if (n > LIBINIT_MAXSTR) {\n    fprintf(stderr, \"Error: string too long: '%s'\\n\",  p);\n    exit(1);\n  }\n  if (optr+1+n+2 > obuf+sizeof(obuf)) {  /* +2 for caller. */\n    fprintf(stderr, \"Error: output buffer overflow\\n\");\n    exit(1);\n  }\n  *optr++ = (uint8_t)(n | kind);\n  memcpy(optr, p, n);\n  optr += n;\n}\n\nstatic void libdef_endmodule(BuildCtx *ctx)\n{\n  if (modstate != 0) {\n    char line[80];\n    const uint8_t *p;\n    int n;\n    if (modstate == 1)\n      fprintf(ctx->fp, \"  (lua_CFunction)0\");\n    fprintf(ctx->fp, \"\\n};\\n\");\n    fprintf(ctx->fp, \"static const uint8_t %s%s[] = {\\n\",\n\t    LABEL_PREFIX_LIBINIT, modname);\n    line[0] = '\\0';\n    for (n = 0, p = obuf; p < optr; p++) {\n      n += sprintf(line+n, \"%d,\", *p);\n      if (n >= 75) {\n\tfprintf(ctx->fp, \"%s\\n\", line);\n\tn = 0;\n\tline[0] = '\\0';\n      }\n    }\n    fprintf(ctx->fp, \"%s%d\\n};\\n#endif\\n\\n\", line, LIBINIT_END);\n  }\n}\n\nstatic void libdef_module(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    libdef_endmodule(ctx);\n    optr = obuf;\n    *optr++ = (uint8_t)ffid;\n    *optr++ = (uint8_t)ffasmfunc;\n    *optr++ = 0;  /* Hash table size. */\n    modstate = 1;\n    fprintf(ctx->fp, \"#ifdef %sMODULE_%s\\n\", LIBDEF_PREFIX, p);\n    fprintf(ctx->fp, \"#undef %sMODULE_%s\\n\", LIBDEF_PREFIX, p);\n    fprintf(ctx->fp, \"static const lua_CFunction %s%s[] = {\\n\",\n\t    LABEL_PREFIX_LIBCF, p);\n  }\n  modnamelen = strlen(p);\n  if (modnamelen > sizeof(modname)-1) {\n    fprintf(stderr, \"Error: module name too long: '%s'\\n\", p);\n    exit(1);\n  }\n  strcpy(modname, p);\n}\n\nstatic int find_ffofs(BuildCtx *ctx, const char *name)\n{\n  int i;\n  for (i = 0; i < ctx->nglob; i++) {\n    const char *gl = ctx->globnames[i];\n    if (gl[0] == 'f' && gl[1] == 'f' && gl[2] == '_' && !strcmp(gl+3, name)) {\n      return (int)((uint8_t *)ctx->glob[i] - ctx->code);\n    }\n  }\n  fprintf(stderr, \"Error: undefined fast function %s%s\\n\",\n\t  LABEL_PREFIX_FF, name);\n  exit(1);\n}\n\nstatic void libdef_func(BuildCtx *ctx, char *p, int arg)\n{\n  if (arg != LIBINIT_CF)\n    ffasmfunc++;\n  if (ctx->mode == BUILD_libdef) {\n    if (modstate == 0) {\n      fprintf(stderr, \"Error: no module for function definition %s\\n\", p);\n      exit(1);\n    }\n    if (regfunc == REGFUNC_NOREG) {\n      if (optr+1 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_FFID;\n    } else {\n      if (arg != LIBINIT_ASM_) {\n\tif (modstate != 1) fprintf(ctx->fp, \",\\n\");\n\tmodstate = 2;\n\tfprintf(ctx->fp, \"  %s%s\", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p);\n      }\n      if (regfunc != REGFUNC_NOREGUV) obuf[2]++;  /* Bump hash table size. */\n      libdef_name(regfunc == REGFUNC_NOREGUV ? \"\" : p, arg);\n    }\n  } else if (ctx->mode == BUILD_ffdef) {\n    fprintf(ctx->fp, \"FFDEF(%s)\\n\", p);\n  } else if (ctx->mode == BUILD_recdef) {\n    if (strlen(p) > sizeof(funcname)-1) {\n      fprintf(stderr, \"Error: function name too long: '%s'\\n\", p);\n      exit(1);\n    }\n    strcpy(funcname, p);\n  } else if (ctx->mode == BUILD_vmdef) {\n    int i;\n    for (i = 1; p[i] && modname[i-1]; i++)\n      if (p[i] == '_') p[i] = '.';\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", p);\n  } else if (ctx->mode == BUILD_bcdef) {\n    if (arg != LIBINIT_CF)\n      fprintf(ctx->fp, \",\\n%d\", find_ffofs(ctx, p));\n  }\n  ffid++;\n  regfunc = REGFUNC_OK;\n}\n\nstatic uint8_t *libdef_uleb128(uint8_t *p, uint32_t *vv)\n{\n  uint32_t v = *p++;\n  if (v >= 0x80) {\n    int sh = 0; v &= 0x7f;\n    do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80);\n  }\n  *vv = v;\n  return p;\n}\n\nstatic void libdef_fixupbc(uint8_t *p)\n{\n  uint32_t i, sizebc;\n  p += 4;\n  p = libdef_uleb128(p, &sizebc);\n  p = libdef_uleb128(p, &sizebc);\n  p = libdef_uleb128(p, &sizebc);\n  for (i = 0; i < sizebc; i++, p += 4) {\n    uint8_t op = p[libbc_endian ? 3 : 0];\n    uint8_t ra = p[libbc_endian ? 2 : 1];\n    uint8_t rc = p[libbc_endian ? 1 : 2];\n    uint8_t rb = p[libbc_endian ? 0 : 3];\n    if (!LJ_DUALNUM && op == BC_ISTYPE && rc == ~LJ_TNUMX+1) {\n      op = BC_ISNUM; rc++;\n    }\n    p[LJ_ENDIAN_SELECT(0, 3)] = op;\n    p[LJ_ENDIAN_SELECT(1, 2)] = ra;\n    p[LJ_ENDIAN_SELECT(2, 1)] = rc;\n    p[LJ_ENDIAN_SELECT(3, 0)] = rb;\n  }\n}\n\nstatic void libdef_lua(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    int i;\n    for (i = 0; libbc_map[i].name != NULL; i++) {\n      if (!strcmp(libbc_map[i].name, p)) {\n\tint ofs = libbc_map[i].ofs;\n\tint len = libbc_map[i+1].ofs - ofs;\n\tobuf[2]++;  /* Bump hash table size. */\n\t*optr++ = LIBINIT_LUA;\n\tlibdef_name(p, 0);\n\tmemcpy(optr, libbc_code + ofs, len);\n\tlibdef_fixupbc(optr);\n\toptr += len;\n\treturn;\n      }\n    }\n    fprintf(stderr, \"Error: missing libbc definition for %s\\n\", p);\n    exit(1);\n  }\n}\n\nstatic uint32_t find_rec(char *name)\n{\n  char *p = (char *)obuf;\n  uint32_t n;\n  for (n = 2; *p; n++) {\n    if (strcmp(p, name) == 0)\n      return n;\n    p += strlen(p)+1;\n  }\n  if (p+strlen(name)+1 >= (char *)obuf+sizeof(obuf)) {\n    fprintf(stderr, \"Error: output buffer overflow\\n\");\n    exit(1);\n  }\n  strcpy(p, name);\n  return n;\n}\n\nstatic void libdef_rec(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_recdef) {\n    char *q;\n    uint32_t n;\n    for (; recffid+1 < ffid; recffid++)\n      fprintf(ctx->fp, \",\\n0\");\n    recffid = ffid;\n    if (*p == '.') p = funcname;\n    q = strchr(p, ' ');\n    if (q) *q++ = '\\0';\n    n = find_rec(p);\n    if (q)\n      fprintf(ctx->fp, \",\\n0x%02x00+(%s)\", n, q);\n    else\n      fprintf(ctx->fp, \",\\n0x%02x00\", n);\n  }\n}\n\nstatic void memcpy_endian(void *dst, void *src, size_t n)\n{\n  union { uint8_t b; uint32_t u; } host_endian;\n  host_endian.u = 1;\n  if (host_endian.b == LJ_ENDIAN_SELECT(1, 0)) {\n    memcpy(dst, src, n);\n  } else {\n    size_t i;\n    for (i = 0; i < n; i++)\n      ((uint8_t *)dst)[i] = ((uint8_t *)src)[n-i-1];\n  }\n}\n\nstatic void libdef_push(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    int len = (int)strlen(p);\n    if (*p == '\"') {\n      if (len > 1 && p[len-1] == '\"') {\n\tp[len-1] = '\\0';\n\tlibdef_name(p+1, LIBINIT_STRING);\n\treturn;\n      }\n    } else if (*p >= '0' && *p <= '9') {\n      char *ep;\n      double d = strtod(p, &ep);\n      if (*ep == '\\0') {\n\tif (optr+1+sizeof(double) > obuf+sizeof(obuf)) {\n\t  fprintf(stderr, \"Error: output buffer overflow\\n\");\n\t  exit(1);\n\t}\n\t*optr++ = LIBINIT_NUMBER;\n\tmemcpy_endian(optr, &d, sizeof(double));\n\toptr += sizeof(double);\n\treturn;\n      }\n    } else if (!strcmp(p, \"lastcl\")) {\n      if (optr+1 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_LASTCL;\n      return;\n    } else if (len > 4 && !strncmp(p, \"top-\", 4)) {\n      if (optr+2 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_COPY;\n      *optr++ = (uint8_t)atoi(p+4);\n      return;\n    }\n    fprintf(stderr, \"Error: bad value for %sPUSH(%s)\\n\", LIBDEF_PREFIX, p);\n    exit(1);\n  }\n}\n\nstatic void libdef_set(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    if (p[0] == '!' && p[1] == '\\0') p[0] = '\\0';  /* Set env. */\n    libdef_name(p, LIBINIT_STRING);\n    *optr++ = LIBINIT_SET;\n    obuf[2]++;  /* Bump hash table size. */\n  }\n}\n\nstatic void libdef_regfunc(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(ctx); UNUSED(p);\n  regfunc = arg;\n}\n\ntypedef void (*LibDefFunc)(BuildCtx *ctx, char *p, int arg);\n\ntypedef struct LibDefHandler {\n  const char *suffix;\n  const char *stop;\n  const LibDefFunc func;\n  const int arg;\n} LibDefHandler;\n\nstatic const LibDefHandler libdef_handlers[] = {\n  { \"MODULE_\",\t\" \\t\\r\\n\",\tlibdef_module,\t\t0 },\n  { \"CF(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_CF },\n  { \"ASM(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_ASM },\n  { \"ASM_(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_ASM_ },\n  { \"LUA(\",\t\")\",\t\tlibdef_lua,\t\t0 },\n  { \"REC(\",\t\")\",\t\tlibdef_rec,\t\t0 },\n  { \"PUSH(\",\t\")\",\t\tlibdef_push,\t\t0 },\n  { \"SET(\",\t\")\",\t\tlibdef_set,\t\t0 },\n  { \"NOREGUV\",\tNULL,\t\tlibdef_regfunc,\t\tREGFUNC_NOREGUV },\n  { \"NOREG\",\tNULL,\t\tlibdef_regfunc,\t\tREGFUNC_NOREG },\n  { NULL,\tNULL,\t\t(LibDefFunc)0,\t\t0 }\n};\n\n/* Emit C source code for library function definitions. */\nvoid emit_lib(BuildCtx *ctx)\n{\n  const char *fname;\n\n  if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef ||\n      ctx->mode == BUILD_recdef)\n    fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  else if (ctx->mode == BUILD_vmdef)\n    fprintf(ctx->fp, \"ffnames = {\\n[0]=\\\"Lua\\\",\\n\\\"C\\\",\\n\");\n  if (ctx->mode == BUILD_recdef)\n    fprintf(ctx->fp, \"static const uint16_t recff_idmap[] = {\\n0,\\n0x0100\");\n  recffid = ffid = FF_C+1;\n  ffasmfunc = 0;\n\n  while ((fname = *ctx->args++)) {\n    char buf[256];  /* We don't care about analyzing lines longer than that. */\n    FILE *fp;\n    if (fname[0] == '-' && fname[1] == '\\0') {\n      fp = stdin;\n    } else {\n      fp = fopen(fname, \"r\");\n      if (!fp) {\n\tfprintf(stderr, \"Error: cannot open input file '%s': %s\\n\",\n\t\tfname, strerror(errno));\n\texit(1);\n      }\n    }\n    modstate = 0;\n    regfunc = REGFUNC_OK;\n    while (fgets(buf, sizeof(buf), fp) != NULL) {\n      char *p;\n      /* Simplistic pre-processor. Only handles top-level #if/#endif. */\n      if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {\n\tint ok = 1;\n\tif (!strcmp(buf, \"#if LJ_52\\n\"))\n\t  ok = LJ_52;\n\telse if (!strcmp(buf, \"#if LJ_HASJIT\\n\"))\n\t  ok = LJ_HASJIT;\n\telse if (!strcmp(buf, \"#if LJ_HASFFI\\n\"))\n\t  ok = LJ_HASFFI;\n\tif (!ok) {\n\t  int lvl = 1;\n\t  while (fgets(buf, sizeof(buf), fp) != NULL) {\n\t    if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') {\n\t      if (--lvl == 0) break;\n\t    } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {\n\t      lvl++;\n\t    }\n\t  }\n\t  continue;\n\t}\n      }\n      for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) {\n\tconst LibDefHandler *ldh;\n\tp += sizeof(LIBDEF_PREFIX)-1;\n\tfor (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) {\n\t  size_t n, len = strlen(ldh->suffix);\n\t  if (!strncmp(p, ldh->suffix, len)) {\n\t    p += len;\n\t    n = ldh->stop ? strcspn(p, ldh->stop) : 0;\n\t    if (!p[n]) break;\n\t    p[n] = '\\0';\n\t    ldh->func(ctx, p, ldh->arg);\n\t    p += n+1;\n\t    break;\n\t  }\n\t}\n\tif (ldh->suffix == NULL) {\n\t  buf[strlen(buf)-1] = '\\0';\n\t  fprintf(stderr, \"Error: unknown library definition tag %s%s\\n\",\n\t\t  LIBDEF_PREFIX, p);\n\t  exit(1);\n\t}\n      }\n    }\n    fclose(fp);\n    if (ctx->mode == BUILD_libdef) {\n      libdef_endmodule(ctx);\n    }\n  }\n\n  if (ctx->mode == BUILD_ffdef) {\n    fprintf(ctx->fp, \"\\n#undef FFDEF\\n\\n\");\n    fprintf(ctx->fp,\n      \"#ifndef FF_NUM_ASMFUNC\\n#define FF_NUM_ASMFUNC %d\\n#endif\\n\\n\",\n      ffasmfunc);\n  } else if (ctx->mode == BUILD_vmdef) {\n    fprintf(ctx->fp, \"},\\n\\n\");\n  } else if (ctx->mode == BUILD_bcdef) {\n    int i;\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n    fprintf(ctx->fp, \"LJ_DATADEF const uint16_t lj_bc_mode[] = {\\n\");\n    fprintf(ctx->fp, \"BCDEF(BCMODE)\\n\");\n    for (i = ffasmfunc-1; i > 0; i--)\n      fprintf(ctx->fp, \"BCMODE_FF,\\n\");\n    fprintf(ctx->fp, \"BCMODE_FF\\n};\\n\\n\");\n  } else if (ctx->mode == BUILD_recdef) {\n    char *p = (char *)obuf;\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n    fprintf(ctx->fp, \"static const RecordFunc recff_func[] = {\\n\"\n\t    \"recff_nyi,\\n\"\n\t    \"recff_c\");\n    while (*p) {\n      fprintf(ctx->fp, \",\\nrecff_%s\", p);\n      p += strlen(p)+1;\n    }\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm_libbc.h",
    "content": "/* This is a generated file. DO NOT EDIT! */\n\nstatic const int libbc_endian = 0;\n\nstatic const uint8_t libbc_code[] = {\n#if LJ_FR2\n0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0,\n0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0,1,2,0,0,0,3,\n16,0,5,0,21,1,0,0,76,1,2,0,0,2,10,0,0,0,15,16,0,12,0,16,1,9,0,41,2,1,0,21,3,\n0,0,41,4,1,0,77,2,8,128,18,6,1,0,18,8,5,0,59,9,5,0,66,6,3,2,10,6,0,0,88,7,1,\n128,76,6,2,0,79,2,248,127,75,0,1,0,0,2,11,0,0,0,16,16,0,12,0,16,1,9,0,43,2,\n0,0,18,3,0,0,41,4,0,0,88,5,7,128,18,7,1,0,18,9,5,0,18,10,6,0,66,7,3,2,10,7,\n0,0,88,8,1,128,76,7,2,0,70,5,3,3,82,5,247,127,75,0,1,0,0,1,2,0,0,0,3,16,0,12,\n0,21,1,0,0,76,1,2,0,0,2,10,0,0,2,30,16,0,12,0,21,2,0,0,11,1,0,0,88,3,7,128,\n8,2,0,0,88,3,23,128,59,3,2,0,43,4,0,0,64,4,2,0,76,3,2,0,88,3,18,128,16,1,14,\n0,41,3,1,0,3,3,1,0,88,3,14,128,3,1,2,0,88,3,12,128,59,3,1,0,22,4,1,1,18,5,2,\n0,41,6,1,0,77,4,4,128,23,8,1,7,59,9,7,0,64,9,8,0,79,4,252,127,43,4,0,0,64,4,\n2,0,76,3,2,0,75,0,1,0,0,2,0\n#else\n0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0,\n0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0,1,2,0,0,0,3,\n16,0,5,0,21,1,0,0,76,1,2,0,0,2,9,0,0,0,15,16,0,12,0,16,1,9,0,41,2,1,0,21,3,\n0,0,41,4,1,0,77,2,8,128,18,6,1,0,18,7,5,0,59,8,5,0,66,6,3,2,10,6,0,0,88,7,1,\n128,76,6,2,0,79,2,248,127,75,0,1,0,0,2,10,0,0,0,16,16,0,12,0,16,1,9,0,43,2,\n0,0,18,3,0,0,41,4,0,0,88,5,7,128,18,7,1,0,18,8,5,0,18,9,6,0,66,7,3,2,10,7,0,\n0,88,8,1,128,76,7,2,0,70,5,3,3,82,5,247,127,75,0,1,0,0,1,2,0,0,0,3,16,0,12,\n0,21,1,0,0,76,1,2,0,0,2,10,0,0,2,30,16,0,12,0,21,2,0,0,11,1,0,0,88,3,7,128,\n8,2,0,0,88,3,23,128,59,3,2,0,43,4,0,0,64,4,2,0,76,3,2,0,88,3,18,128,16,1,14,\n0,41,3,1,0,3,3,1,0,88,3,14,128,3,1,2,0,88,3,12,128,59,3,1,0,22,4,1,1,18,5,2,\n0,41,6,1,0,77,4,4,128,23,8,1,7,59,9,7,0,64,9,8,0,79,4,252,127,43,4,0,0,64,4,\n2,0,76,3,2,0,75,0,1,0,0,2,0\n#endif\n};\n\nstatic const struct { const char *name; int ofs; } libbc_map[] = {\n{\"math_deg\",0},\n{\"math_rad\",25},\n{\"string_len\",50},\n{\"table_foreachi\",69},\n{\"table_foreach\",136},\n{\"table_getn\",207},\n{\"table_remove\",226},\n{NULL,355}\n};\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/buildvm_peobj.c",
    "content": "/*\n** LuaJIT VM builder: PE object emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Only used for building on Windows, since we cannot assume the presence\n** of a suitable assembler. The host and target byte order must match.\n*/\n\n#include \"buildvm.h\"\n#include \"lj_bc.h\"\n\n#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC\n\n/* Context for PE object emitter. */\nstatic char *strtab;\nstatic size_t strtabofs;\n\n/* -- PE object definitions ----------------------------------------------- */\n\n/* PE header. */\ntypedef struct PEheader {\n  uint16_t arch;\n  uint16_t nsects;\n  uint32_t time;\n  uint32_t symtabofs;\n  uint32_t nsyms;\n  uint16_t opthdrsz;\n  uint16_t flags;\n} PEheader;\n\n/* PE section. */\ntypedef struct PEsection {\n  char name[8];\n  uint32_t vsize;\n  uint32_t vaddr;\n  uint32_t size;\n  uint32_t ofs;\n  uint32_t relocofs;\n  uint32_t lineofs;\n  uint16_t nreloc;\n  uint16_t nline;\n  uint32_t flags;\n} PEsection;\n\n/* PE relocation. */\ntypedef struct PEreloc {\n  uint32_t vaddr;\n  uint32_t symidx;\n  uint16_t type;\n} PEreloc;\n\n/* Cannot use sizeof, because it pads up to the max. alignment. */\n#define PEOBJ_RELOC_SIZE\t(4+4+2)\n\n/* PE symbol table entry. */\ntypedef struct PEsym {\n  union {\n    char name[8];\n    uint32_t nameref[2];\n  } n;\n  uint32_t value;\n  int16_t sect;\n  uint16_t type;\n  uint8_t scl;\n  uint8_t naux;\n} PEsym;\n\n/* PE symbol table auxiliary entry for a section. */\ntypedef struct PEsymaux {\n  uint32_t size;\n  uint16_t nreloc;\n  uint16_t nline;\n  uint32_t cksum;\n  uint16_t assoc;\n  uint8_t comdatsel;\n  uint8_t unused[3];\n} PEsymaux;\n\n/* Cannot use sizeof, because it pads up to the max. alignment. */\n#define PEOBJ_SYM_SIZE\t(8+4+2+2+1+1)\n\n/* PE object CPU specific defines. */\n#if LJ_TARGET_X86\n#define PEOBJ_ARCH_TARGET\t0x014c\n#define PEOBJ_RELOC_REL32\t0x14  /* MS: REL32, GNU: DISP32. */\n#define PEOBJ_RELOC_DIR32\t0x06\n#define PEOBJ_RELOC_OFS\t\t0\n#define PEOBJ_TEXT_FLAGS\t0x60500020  /* 60=r+x, 50=align16, 20=code. */\n#elif LJ_TARGET_X64\n#define PEOBJ_ARCH_TARGET\t0x8664\n#define PEOBJ_RELOC_REL32\t0x04  /* MS: REL32, GNU: DISP32. */\n#define PEOBJ_RELOC_DIR32\t0x02\n#define PEOBJ_RELOC_ADDR32NB\t0x03\n#define PEOBJ_RELOC_OFS\t\t0\n#define PEOBJ_TEXT_FLAGS\t0x60500020  /* 60=r+x, 50=align16, 20=code. */\n#elif LJ_TARGET_PPC\n#define PEOBJ_ARCH_TARGET\t0x01f2\n#define PEOBJ_RELOC_REL32\t0x06\n#define PEOBJ_RELOC_DIR32\t0x02\n#define PEOBJ_RELOC_OFS\t\t(-4)\n#define PEOBJ_TEXT_FLAGS\t0x60400020  /* 60=r+x, 40=align8, 20=code. */\n#endif\n\n/* Section numbers (0-based). */\nenum {\n  PEOBJ_SECT_ABS = -2,\n  PEOBJ_SECT_UNDEF = -1,\n  PEOBJ_SECT_TEXT,\n#if LJ_TARGET_X64\n  PEOBJ_SECT_PDATA,\n  PEOBJ_SECT_XDATA,\n#endif\n  PEOBJ_SECT_RDATA_Z,\n  PEOBJ_NSECTIONS\n};\n\n/* Symbol types. */\n#define PEOBJ_TYPE_NULL\t\t0\n#define PEOBJ_TYPE_FUNC\t\t0x20\n\n/* Symbol storage class. */\n#define PEOBJ_SCL_EXTERN\t2\n#define PEOBJ_SCL_STATIC\t3\n\n/* -- PE object emitter --------------------------------------------------- */\n\n/* Emit PE object symbol. */\nstatic void emit_peobj_sym(BuildCtx *ctx, const char *name, uint32_t value,\n\t\t\t   int sect, int type, int scl)\n{\n  PEsym sym;\n  size_t len = strlen(name);\n  if (!strtab) {  /* Pass 1: only calculate string table length. */\n    if (len > 8) strtabofs += len+1;\n    return;\n  }\n  if (len <= 8) {\n    memcpy(sym.n.name, name, len);\n    memset(sym.n.name+len, 0, 8-len);\n  } else {\n    sym.n.nameref[0] = 0;\n    sym.n.nameref[1] = (uint32_t)strtabofs;\n    memcpy(strtab + strtabofs, name, len);\n    strtab[strtabofs+len] = 0;\n    strtabofs += len+1;\n  }\n  sym.value = value;\n  sym.sect = (int16_t)(sect+1);  /* 1-based section number. */\n  sym.type = (uint16_t)type;\n  sym.scl = (uint8_t)scl;\n  sym.naux = 0;\n  owrite(ctx, &sym, PEOBJ_SYM_SIZE);\n}\n\n/* Emit PE object section symbol. */\nstatic void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect)\n{\n  PEsym sym;\n  PEsymaux aux;\n  if (!strtab) return;  /* Pass 1: no output. */\n  memcpy(sym.n.name, pesect[sect].name, 8);\n  sym.value = 0;\n  sym.sect = (int16_t)(sect+1);  /* 1-based section number. */\n  sym.type = PEOBJ_TYPE_NULL;\n  sym.scl = PEOBJ_SCL_STATIC;\n  sym.naux = 1;\n  owrite(ctx, &sym, PEOBJ_SYM_SIZE);\n  memset(&aux, 0, sizeof(PEsymaux));\n  aux.size = pesect[sect].size;\n  aux.nreloc = pesect[sect].nreloc;\n  owrite(ctx, &aux, PEOBJ_SYM_SIZE);\n}\n\n/* Emit Windows PE object file. */\nvoid emit_peobj(BuildCtx *ctx)\n{\n  PEheader pehdr;\n  PEsection pesect[PEOBJ_NSECTIONS];\n  uint32_t sofs;\n  int i, nrsym;\n  union { uint8_t b; uint32_t u; } host_endian;\n\n  sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection);\n\n  /* Fill in PE sections. */\n  memset(&pesect, 0, PEOBJ_NSECTIONS*sizeof(PEsection));\n  memcpy(pesect[PEOBJ_SECT_TEXT].name, \".text\", sizeof(\".text\")-1);\n  pesect[PEOBJ_SECT_TEXT].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_TEXT].size = (uint32_t)ctx->codesz);\n  pesect[PEOBJ_SECT_TEXT].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE;\n  /* Flags: 60 = read+execute, 50 = align16, 20 = code. */\n  pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS;\n\n#if LJ_TARGET_X64\n  memcpy(pesect[PEOBJ_SECT_PDATA].name, \".pdata\", sizeof(\".pdata\")-1);\n  pesect[PEOBJ_SECT_PDATA].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_PDATA].size = 6*4);\n  pesect[PEOBJ_SECT_PDATA].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_PDATA].nreloc = 6) * PEOBJ_RELOC_SIZE;\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_PDATA].flags = 0x40300040;\n\n  memcpy(pesect[PEOBJ_SECT_XDATA].name, \".xdata\", sizeof(\".xdata\")-1);\n  pesect[PEOBJ_SECT_XDATA].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_XDATA].size = 8*2+4+6*2);  /* See below. */\n  pesect[PEOBJ_SECT_XDATA].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_XDATA].nreloc = 1) * PEOBJ_RELOC_SIZE;\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_XDATA].flags = 0x40300040;\n#endif\n\n  memcpy(pesect[PEOBJ_SECT_RDATA_Z].name, \".rdata$Z\", sizeof(\".rdata$Z\")-1);\n  pesect[PEOBJ_SECT_RDATA_Z].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_RDATA_Z].size = (uint32_t)strlen(ctx->dasm_ident)+1);\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_RDATA_Z].flags = 0x40300040;\n\n  /* Fill in PE header. */\n  pehdr.arch = PEOBJ_ARCH_TARGET;\n  pehdr.nsects = PEOBJ_NSECTIONS;\n  pehdr.time = 0;  /* Timestamp is optional. */\n  pehdr.symtabofs = sofs;\n  pehdr.opthdrsz = 0;\n  pehdr.flags = 0;\n\n  /* Compute the size of the symbol table:\n  ** @feat.00 + nsections*2\n  ** + asm_start + nsym\n  ** + nrsym\n  */\n  nrsym = ctx->nrelocsym;\n  pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym;\n#if LJ_TARGET_X64\n  pehdr.nsyms += 1;  /* Symbol for lj_err_unwind_win64. */\n#endif\n\n  /* Write PE object header and all sections. */\n  owrite(ctx, &pehdr, sizeof(PEheader));\n  owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS);\n\n  /* Write .text section. */\n  host_endian.u = 1;\n  if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) {\n#if LJ_TARGET_PPC\n    uint32_t *p = (uint32_t *)ctx->code;\n    int n = (int)(ctx->codesz >> 2);\n    for (i = 0; i < n; i++, p++)\n      *p = lj_bswap(*p);  /* Byteswap .text section. */\n#else\n    fprintf(stderr, \"Error: different byte order for host and target\\n\");\n    exit(1);\n#endif\n  }\n  owrite(ctx, ctx->code, ctx->codesz);\n  for (i = 0; i < ctx->nreloc; i++) {\n    PEreloc reloc;\n    reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS;\n    reloc.symidx = 1+2+ctx->reloc[i].sym;  /* Reloc syms are after .text sym. */\n    reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n\n#if LJ_TARGET_X64\n  { /* Write .pdata section. */\n    uint32_t fcofs = (uint32_t)ctx->sym[ctx->nsym-1].ofs;\n    uint32_t pdata[3];  /* Start of .text, end of .text and .xdata. */\n    PEreloc reloc;\n    pdata[0] = 0; pdata[1] = fcofs; pdata[2] = 0;\n    owrite(ctx, &pdata, sizeof(pdata));\n    pdata[0] = fcofs; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 20;\n    owrite(ctx, &pdata, sizeof(pdata));\n    reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 12; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 16; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 20; reloc.symidx = 1+2+nrsym+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n  { /* Write .xdata section. */\n    uint16_t xdata[8+2+6];\n    PEreloc reloc;\n    xdata[0] = 0x01|0x08|0x10;  /* Ver. 1, uhandler/ehandler, prolog size 0. */\n    xdata[1] = 0x0005;  /* Number of unwind codes, no frame pointer. */\n    xdata[2] = 0x4200;  /* Stack offset 4*8+8 = aword*5. */\n    xdata[3] = 0x3000;  /* Push rbx. */\n    xdata[4] = 0x6000;  /* Push rsi. */\n    xdata[5] = 0x7000;  /* Push rdi. */\n    xdata[6] = 0x5000;  /* Push rbp. */\n    xdata[7] = 0;  /* Alignment. */\n    xdata[8] = xdata[9] = 0;  /* Relocated address of exception handler. */\n    xdata[10] = 0x01;  /* Ver. 1, no handler, prolog size 0. */\n    xdata[11] = 0x1504;  /* Number of unwind codes, fp = rbp, fpofs = 16. */\n    xdata[12] = 0x0300;  /* set_fpreg. */\n    xdata[13] = 0x0200;  /* stack offset 0*8+8 = aword*1. */\n    xdata[14] = 0x3000;  /* Push rbx. */\n    xdata[15] = 0x5000;  /* Push rbp. */\n    owrite(ctx, &xdata, sizeof(xdata));\n    reloc.vaddr = 2*8; reloc.symidx = 1+2+nrsym+2+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n#endif\n\n  /* Write .rdata$Z section. */\n  owrite(ctx, ctx->dasm_ident, strlen(ctx->dasm_ident)+1);\n\n  /* Write symbol table. */\n  strtab = NULL;  /* 1st pass: collect string sizes. */\n  for (;;) {\n    strtabofs = 4;\n    /* Mark as SafeSEH compliant. */\n    emit_peobj_sym(ctx, \"@feat.00\", 1,\n\t\t   PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC);\n\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT);\n    for (i = 0; i < nrsym; i++)\n      emit_peobj_sym(ctx, ctx->relocsym[i], 0,\n\t\t     PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n\n#if LJ_TARGET_X64\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA);\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA);\n    emit_peobj_sym(ctx, \"lj_err_unwind_win64\", 0,\n\t\t   PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n#endif\n\n    emit_peobj_sym(ctx, ctx->beginsym, 0,\n\t\t   PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN);\n    for (i = 0; i < ctx->nsym; i++)\n      emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs,\n\t\t     PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z);\n\n    if (strtab)\n      break;\n    /* 2nd pass: alloc strtab, write syms and copy strings. */\n    strtab = (char *)malloc(strtabofs);\n    *(uint32_t *)strtab = (uint32_t)strtabofs;\n  }\n\n  /* Write string table. */\n  owrite(ctx, strtab, strtabofs);\n}\n\n#else\n\nvoid emit_peobj(BuildCtx *ctx)\n{\n  UNUSED(ctx);\n  fprintf(stderr, \"Error: no PE object support for this target\\n\");\n  exit(1);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/genlibbc.lua",
    "content": "----------------------------------------------------------------------------\n-- Lua script to dump the bytecode of the library functions written in Lua.\n-- The resulting 'buildvm_libbc.h' is used for the build process of LuaJIT.\n----------------------------------------------------------------------------\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n\nlocal ffi = require(\"ffi\")\nlocal bit = require(\"bit\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal bcnames = vmdef.bcnames\n\nlocal format = string.format\n\nlocal isbe = (string.byte(string.dump(function() end), 5) % 2 == 1)\n\nlocal function usage(arg)\n  io.stderr:write(\"Usage: \", arg and arg[0] or \"genlibbc\",\n\t\t  \" [-o buildvm_libbc.h] lib_*.c\\n\")\n  os.exit(1)\nend\n\nlocal function parse_arg(arg)\n  local outfile = \"-\"\n  if not (arg and arg[1]) then\n    usage(arg)\n  end\n  if arg[1] == \"-o\" then\n    outfile = arg[2]\n    if not outfile then usage(arg) end\n    table.remove(arg, 1)\n    table.remove(arg, 1)\n  end\n  return outfile\nend\n\nlocal function read_files(names)\n  local src = \"\"\n  for _,name in ipairs(names) do\n    local fp = assert(io.open(name))\n    src = src .. fp:read(\"*a\")\n    fp:close()\n  end\n  return src\nend\n\nlocal function transform_lua(code)\n  local fixup = {}\n  local n = -30000\n  code = string.gsub(code, \"CHECK_(%w*)%((.-)%)\", function(tp, var)\n    n = n + 1\n    fixup[n] = { \"CHECK\", tp }\n    return format(\"%s=%d\", var, n)\n  end)\n  code = string.gsub(code, \"PAIRS%((.-)%)\", function(var)\n    fixup.PAIRS = true\n    return format(\"nil, %s, 0\", var)\n  end)\n  return \"return \"..code, fixup\nend\n\nlocal function read_uleb128(p)\n  local v = p[0]; p = p + 1\n  if v >= 128 then\n    local sh = 7; v = v - 128\n    repeat\n      local r = p[0]\n      v = v + bit.lshift(bit.band(r, 127), sh)\n      sh = sh + 7\n      p = p + 1\n    until r < 128\n  end\n  return p, v\nend\n\n-- ORDER LJ_T\nlocal name2itype = {\n  str = 5, func = 9, tab = 12, int = 14, num = 15\n}\n\nlocal BC = {}\nfor i=0,#bcnames/6-1 do\n  BC[string.gsub(string.sub(bcnames, i*6+1, i*6+6), \" \", \"\")] = i\nend\nlocal xop, xra = isbe and 3 or 0, isbe and 2 or 1\nlocal xrc, xrb = isbe and 1 or 2, isbe and 0 or 3\n\nlocal function fixup_dump(dump, fixup)\n  local buf = ffi.new(\"uint8_t[?]\", #dump+1, dump)\n  local p = buf+5\n  local n, sizebc\n  p, n = read_uleb128(p)\n  local start = p\n  p = p + 4\n  p = read_uleb128(p)\n  p = read_uleb128(p)\n  p, sizebc = read_uleb128(p)\n  local rawtab = {}\n  for i=0,sizebc-1 do\n    local op = p[xop]\n    if op == BC.KSHORT then\n      local rd = p[xrc] + 256*p[xrb]\n      rd = bit.arshift(bit.lshift(rd, 16), 16)\n      local f = fixup[rd]\n      if f then\n\tif f[1] == \"CHECK\" then\n\t  local tp = f[2]\n\t  if tp == \"tab\" then rawtab[p[xra]] = true end\n\t  p[xop] = tp == \"num\" and BC.ISNUM or BC.ISTYPE\n\t  p[xrb] = 0\n\t  p[xrc] = name2itype[tp]\n\telse\n\t  error(\"unhandled fixup type: \"..f[1])\n\tend\n      end\n    elseif op == BC.TGETV then\n      if rawtab[p[xrb]] then\n\tp[xop] = BC.TGETR\n      end\n    elseif op == BC.TSETV then\n      if rawtab[p[xrb]] then\n\tp[xop] = BC.TSETR\n      end\n    elseif op == BC.ITERC then\n      if fixup.PAIRS then\n\tp[xop] = BC.ITERN\n      end\n    end\n    p = p + 4\n  end\n  return ffi.string(start, n)\nend\n\nlocal function find_defs(src)\n  local defs = {}\n  for name, code in string.gmatch(src, \"LJLIB_LUA%(([^)]*)%)%s*/%*(.-)%*/\") do\n    local env = {}\n    local tcode, fixup = transform_lua(code)\n    local func = assert(load(tcode, \"\", nil, env))()\n    defs[name] = fixup_dump(string.dump(func, true), fixup)\n    defs[#defs+1] = name\n  end\n  return defs\nend\n\nlocal function gen_header(defs)\n  local t = {}\n  local function w(x) t[#t+1] = x end\n  w(\"/* This is a generated file. DO NOT EDIT! */\\n\\n\")\n  w(\"static const int libbc_endian = \") w(isbe and 1 or 0) w(\";\\n\\n\")\n  local s = \"\"\n  for _,name in ipairs(defs) do\n    s = s .. defs[name]\n  end\n  w(\"static const uint8_t libbc_code[] = {\\n\")\n  local n = 0\n  for i=1,#s do\n    local x = string.byte(s, i)\n    w(x); w(\",\")\n    n = n + (x < 10 and 2 or (x < 100 and 3 or 4))\n    if n >= 75 then n = 0; w(\"\\n\") end\n  end\n  w(\"0\\n};\\n\\n\")\n  w(\"static const struct { const char *name; int ofs; } libbc_map[] = {\\n\")\n  local m = 0\n  for _,name in ipairs(defs) do\n    w('{\"'); w(name); w('\",'); w(m) w('},\\n')\n    m = m + #defs[name]\n  end\n  w(\"{NULL,\"); w(m); w(\"}\\n};\\n\\n\")\n  return table.concat(t)\nend\n\nlocal function write_file(name, data)\n  if name == \"-\" then\n    assert(io.write(data))\n    assert(io.flush())\n  else\n    local fp = io.open(name)\n    if fp then\n      local old = fp:read(\"*a\")\n      fp:close()\n      if data == old then return end\n    end\n    fp = assert(io.open(name, \"w\"))\n    assert(fp:write(data))\n    assert(fp:close())\n  end\nend\n\nlocal outfile = parse_arg(arg)\nlocal src = read_files(arg)\nlocal defs = find_defs(src)\nlocal hdr = gen_header(defs)\nwrite_file(outfile, hdr)\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/genminilua.lua",
    "content": "----------------------------------------------------------------------------\n-- Lua script to generate a customized, minified version of Lua.\n-- The resulting 'minilua' is used for the build process of LuaJIT.\n----------------------------------------------------------------------------\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n\nlocal sub, match, gsub = string.sub, string.match, string.gsub\n\nlocal LUA_VERSION = \"5.1.5\"\nlocal LUA_SOURCE\n\nlocal function usage()\n  io.stderr:write(\"Usage: \", arg and arg[0] or \"genminilua\",\n\t\t  \" lua-\", LUA_VERSION, \"-source-dir\\n\")\n  os.exit(1)\nend\n\nlocal function find_sources()\n  LUA_SOURCE = arg and arg[1]\n  if not LUA_SOURCE then usage() end\n  if sub(LUA_SOURCE, -1) ~= \"/\" then LUA_SOURCE = LUA_SOURCE..\"/\" end\n  local fp = io.open(LUA_SOURCE .. \"lua.h\")\n  if not fp then\n    LUA_SOURCE = LUA_SOURCE..\"src/\"\n    fp = io.open(LUA_SOURCE .. \"lua.h\")\n    if not fp then usage() end\n  end\n  local all = fp:read(\"*a\")\n  fp:close()\n  if not match(all, 'LUA_RELEASE%s*\"Lua '..LUA_VERSION..'\"') then\n    io.stderr:write(\"Error: version mismatch\\n\")\n    usage()\n  end\nend\n\nlocal LUA_FILES = {\n\"lmem.c\", \"lobject.c\", \"ltm.c\", \"lfunc.c\", \"ldo.c\", \"lstring.c\", \"ltable.c\",\n\"lgc.c\", \"lstate.c\", \"ldebug.c\", \"lzio.c\", \"lopcodes.c\",\n\"llex.c\", \"lcode.c\", \"lparser.c\", \"lvm.c\", \"lapi.c\", \"lauxlib.c\",\n\"lbaselib.c\", \"ltablib.c\", \"liolib.c\", \"loslib.c\", \"lstrlib.c\", \"linit.c\",\n}\n\nlocal REMOVE_LIB = {}\ngsub([[\ncollectgarbage dofile gcinfo getfenv getmetatable load print rawequal rawset\nselect tostring xpcall\nforeach foreachi getn maxn setn\npopen tmpfile seek setvbuf __tostring\nclock date difftime execute getenv rename setlocale time tmpname\ndump gfind len reverse\nLUA_LOADLIBNAME LUA_MATHLIBNAME LUA_DBLIBNAME\n]], \"%S+\", function(name)\n  REMOVE_LIB[name] = true\nend)\n\nlocal REMOVE_EXTINC = { [\"<assert.h>\"] = true, [\"<locale.h>\"] = true, }\n\nlocal CUSTOM_MAIN = [[\ntypedef unsigned int UB;\nstatic UB barg(lua_State *L,int idx){\nunion{lua_Number n;U64 b;}bn;\nbn.n=lua_tonumber(L,idx)+6755399441055744.0;\nif (bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,\"number\");\nreturn(UB)bn.b;\n}\n#define BRET(b) lua_pushnumber(L,(lua_Number)(int)(b));return 1;\nstatic int tobit(lua_State *L){\nBRET(barg(L,1))}\nstatic int bnot(lua_State *L){\nBRET(~barg(L,1))}\nstatic int band(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}\nstatic int bor(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}\nstatic int bxor(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}\nstatic int lshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}\nstatic int rshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}\nstatic int arshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}\nstatic int rol(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}\nstatic int ror(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}\nstatic int bswap(lua_State *L){\nUB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}\nstatic int tohex(lua_State *L){\nUB b=barg(L,1);\nint n=lua_isnone(L,2)?8:(int)barg(L,2);\nconst char *hexdigits=\"0123456789abcdef\";\nchar buf[8];\nint i;\nif(n<0){n=-n;hexdigits=\"0123456789ABCDEF\";}\nif(n>8)n=8;\nfor(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}\nlua_pushlstring(L,buf,(size_t)n);\nreturn 1;\n}\nstatic const struct luaL_Reg bitlib[] = {\n{\"tobit\",tobit},\n{\"bnot\",bnot},\n{\"band\",band},\n{\"bor\",bor},\n{\"bxor\",bxor},\n{\"lshift\",lshift},\n{\"rshift\",rshift},\n{\"arshift\",arshift},\n{\"rol\",rol},\n{\"ror\",ror},\n{\"bswap\",bswap},\n{\"tohex\",tohex},\n{NULL,NULL}\n};\nint main(int argc, char **argv){\n  lua_State *L = luaL_newstate();\n  int i;\n  luaL_openlibs(L);\n  luaL_register(L, \"bit\", bitlib);\n  if (argc < 2) return sizeof(void *);\n  lua_createtable(L, 0, 1);\n  lua_pushstring(L, argv[1]);\n  lua_rawseti(L, -2, 0);\n  lua_setglobal(L, \"arg\");\n  if (luaL_loadfile(L, argv[1]))\n    goto err;\n  for (i = 2; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  if (lua_pcall(L, argc - 2, 0, 0)) {\n  err:\n    fprintf(stderr, \"Error: %s\\n\", lua_tostring(L, -1));\n    return 1;\n  }\n  lua_close(L);\n  return 0;\n}\n]]\n\nlocal function read_sources()\n  local t = {}\n  for i, name in ipairs(LUA_FILES) do\n    local fp = assert(io.open(LUA_SOURCE..name, \"r\"))\n    t[i] = fp:read(\"*a\")\n    assert(fp:close())\n  end\n  t[#t+1] = CUSTOM_MAIN\n  return table.concat(t)\nend\n\nlocal includes = {}\n\nlocal function merge_includes(src)\n  return gsub(src, '#include%s*\"([^\"]*)\"%s*\\n', function(name)\n    if includes[name] then return \"\" end\n    includes[name] = true\n    local fp = assert(io.open(LUA_SOURCE..name, \"r\"))\n    local src = fp:read(\"*a\")\n    assert(fp:close())\n    src = gsub(src, \"#ifndef%s+%w+_h\\n#define%s+%w+_h\\n\", \"\")\n    src = gsub(src, \"#endif%s*$\", \"\")\n    return merge_includes(src)\n  end)\nend\n\nlocal function get_license(src)\n  return match(src, \"/%*+\\n%* Copyright %(.-%*/\\n\")\nend\n\nlocal function fold_lines(src)\n  return gsub(src, \"\\\\\\n\", \" \")\nend\n\nlocal strings = {}\n\nlocal function save_str(str)\n  local n = #strings+1\n  strings[n] = str\n  return \"\\1\"..n..\"\\2\"\nend\n\nlocal function save_strings(src)\n  src = gsub(src, '\"[^\"\\n]*\"', save_str)\n  return gsub(src, \"'[^'\\n]*'\", save_str)\nend\n\nlocal function restore_strings(src)\n  return gsub(src, \"\\1(%d+)\\2\", function(numstr)\n    return strings[tonumber(numstr)]\n  end)\nend\n\nlocal function def_istrue(def)\n  return def == \"INT_MAX > 2147483640L\" or\n\t def == \"LUAI_BITSINT >= 32\" or\n\t def == \"SIZE_Bx < LUAI_BITSINT-1\" or\n\t def == \"cast\" or\n\t def == \"defined(LUA_CORE)\" or\n\t def == \"MINSTRTABSIZE\" or\n\t def == \"LUA_MINBUFFER\" or\n\t def == \"HARDSTACKTESTS\" or\n\t def == \"UNUSED\"\nend\n\nlocal head, defs = {[[\n#ifdef _MSC_VER\ntypedef unsigned __int64 U64;\n#else\ntypedef unsigned long long U64;\n#endif\nint _CRT_glob = 0;\n]]}, {}\n\nlocal function preprocess(src)\n  local t = { match(src, \"^(.-)#\") }\n  local lvl, on, oldon = 0, true, {}\n  for pp, def, txt in string.gmatch(src, \"#(%w+) *([^\\n]*)\\n([^#]*)\") do\n    if pp == \"if\" or pp == \"ifdef\" or pp == \"ifndef\" then\n      lvl = lvl + 1\n      oldon[lvl] = on\n      on = def_istrue(def)\n    elseif pp == \"else\" then\n      if oldon[lvl] then\n\tif on == false then on = true else on = false end\n      end\n    elseif pp == \"elif\" then\n      if oldon[lvl] then\n\ton = def_istrue(def)\n      end\n    elseif pp == \"endif\" then\n      on = oldon[lvl]\n      lvl = lvl - 1\n    elseif on then\n      if pp == \"include\" then\n\tif not head[def] and not REMOVE_EXTINC[def] then\n\t  head[def] = true\n\t  head[#head+1] = \"#include \"..def..\"\\n\"\n\tend\n      elseif pp == \"define\" then\n\tlocal k, sp, v = match(def, \"([%w_]+)(%s*)(.*)\")\n\tif k and not (sp == \"\" and sub(v, 1, 1) == \"(\") then\n\t  defs[k] = gsub(v, \"%a[%w_]*\", function(tok)\n\t    return defs[tok] or tok\n\t  end)\n\telse\n\t  t[#t+1] = \"#define \"..def..\"\\n\"\n\tend\n      elseif pp ~= \"undef\" then\n\terror(\"unexpected directive: \"..pp..\" \"..def)\n      end\n    end\n    if on then t[#t+1] = txt end\n  end\n  return gsub(table.concat(t), \"%a[%w_]*\", function(tok)\n    return defs[tok] or tok\n  end)\nend\n\nlocal function merge_header(src, license)\n  local hdr = string.format([[\n/* This is a heavily customized and minimized copy of Lua %s. */\n/* It's only used to build LuaJIT. It does NOT have all standard functions! */\n]], LUA_VERSION)\n  return hdr..license..table.concat(head)..src\nend\n\nlocal function strip_unused1(src)\n  return gsub(src, '(  {\"?([%w_]+)\"?,%s+%a[%w_]*},\\n)', function(line, func)\n    return REMOVE_LIB[func] and \"\" or line\n  end)\nend\n\nlocal function strip_unused2(src)\n  return gsub(src, \"Symbolic Execution.-}=\", \"\")\nend\n\nlocal function strip_unused3(src)\n  src = gsub(src, \"extern\", \"static\")\n  src = gsub(src, \"\\nstatic([^\\n]-)%(([^)]*)%)%(\", \"\\nstatic%1 %2(\")\n  src = gsub(src, \"#define lua_assert[^\\n]*\\n\", \"\")\n  src = gsub(src, \"lua_assert%b();?\", \"\")\n  src = gsub(src, \"default:\\n}\", \"default:;\\n}\")\n  src = gsub(src, \"lua_lock%b();\", \"\")\n  src = gsub(src, \"lua_unlock%b();\", \"\")\n  src = gsub(src, \"luai_threadyield%b();\", \"\")\n  src = gsub(src, \"luai_userstateopen%b();\", \"{}\")\n  src = gsub(src, \"luai_userstate%w+%b();\", \"\")\n  src = gsub(src, \"%(%(c==.*luaY_parser%)\", \"luaY_parser\")\n  src = gsub(src, \"trydecpoint%(ls,seminfo%)\",\n\t\t  \"luaX_lexerror(ls,\\\"malformed number\\\",TK_NUMBER)\")\n  src = gsub(src, \"int c=luaZ_lookahead%b();\", \"\")\n  src = gsub(src, \"luaL_register%(L,[^,]*,co_funcs%);\\nreturn 2;\",\n\t\t  \"return 1;\")\n  src = gsub(src, \"getfuncname%b():\", \"NULL:\")\n  src = gsub(src, \"getobjname%b():\", \"NULL:\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*%)\\n[^\\n]*\\n\", \"\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*%)%b{}\\n\", \"\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*&&\\n[^\\n]*%b{}\\n\", \"\")\n  src = gsub(src, \"(twoto%b()%()\", \"%1(size_t)\")\n  src = gsub(src, \"i<sizenode\", \"i<(int)sizenode\")\n  return gsub(src, \"\\n\\n+\", \"\\n\")\nend\n\nlocal function strip_comments(src)\n  return gsub(src, \"/%*.-%*/\", \" \")\nend\n\nlocal function strip_whitespace(src)\n  src = gsub(src, \"^%s+\", \"\")\n  src = gsub(src, \"%s*\\n%s*\", \"\\n\")\n  src = gsub(src, \"[ \\t]+\", \" \")\n  src = gsub(src, \"(%W) \", \"%1\")\n  return gsub(src, \" (%W)\", \"%1\")\nend\n\nlocal function rename_tokens1(src)\n  src = gsub(src, \"getline\", \"getline_\")\n  src = gsub(src, \"struct ([%w_]+)\", \"ZX%1\")\n  return gsub(src, \"union ([%w_]+)\", \"ZY%1\")\nend\n\nlocal function rename_tokens2(src)\n  src = gsub(src, \"ZX([%w_]+)\", \"struct %1\")\n  return gsub(src, \"ZY([%w_]+)\", \"union %1\")\nend\n\nlocal function func_gather(src)\n  local nodes, list = {}, {}\n  local pos, len = 1, #src\n  while pos < len do\n    local d, w = match(src, \"^(#define ([%w_]+)[^\\n]*\\n)\", pos)\n    if d then\n      local n = #list+1\n      list[n] = d\n      nodes[w] = n\n    else\n      local s\n      d, w, s = match(src, \"^(([%w_]+)[^\\n]*([{;])\\n)\", pos)\n      if not d then\n\td, w, s = match(src, \"^(([%w_]+)[^(]*%b()([{;])\\n)\", pos)\n\tif not d then d = match(src, \"^[^\\n]*\\n\", pos) end\n      end\n      if s == \"{\" then\n\td = d..sub(match(src, \"^%b{}[^;\\n]*;?\\n\", pos+#d-2), 3)\n\tif sub(d, -2) == \"{\\n\" then\n\t  d = d..sub(match(src, \"^%b{}[^;\\n]*;?\\n\", pos+#d-2), 3)\n\tend\n      end\n      local k, v = nil, d\n      if w == \"typedef\" then\n\tif match(d, \"^typedef enum\") then\n\t  head[#head+1] = d\n\telse\n\t  k = match(d, \"([%w_]+);\\n$\")\n\t  if not k then k = match(d, \"^.-%(.-([%w_]+)%)%(\") end\n\tend\n      elseif w == \"enum\" then\n\thead[#head+1] = v\n      elseif w ~= nil then\n\tk = match(d, \"^[^\\n]-([%w_]+)[(%[=]\")\n\tif k then\n\t  if w ~= \"static\" and k ~= \"main\" then v = \"static \"..d end\n\telse\n\t  k = w\n\tend\n      end\n      if w and k then\n\tlocal o = nodes[k]\n\tif o then nodes[\"*\"..k] = o end\n\tlocal n = #list+1\n\tlist[n] = v\n\tnodes[k] = n\n      end\n    end\n    pos = pos + #d\n  end\n  return nodes, list\nend\n\nlocal function func_visit(nodes, list, used, n)\n  local i = nodes[n]\n  for m in string.gmatch(list[i], \"[%w_]+\") do\n    if nodes[m] then\n      local j = used[m]\n      if not j then\n\tused[m] = i\n\tfunc_visit(nodes, list, used, m)\n      elseif i < j then\n\tused[m] = i\n      end\n    end\n  end\nend\n\nlocal function func_collect(src)\n  local nodes, list = func_gather(src)\n  local used = {}\n  func_visit(nodes, list, used, \"main\")\n  for n,i in pairs(nodes) do\n    local j = used[n]\n    if j and j < i then used[\"*\"..n] = j end\n  end\n  for n,i in pairs(nodes) do\n    if not used[n] then list[i] = \"\" end\n  end\n  return table.concat(list)\nend\n\nfind_sources()\nlocal src = read_sources()\nsrc = merge_includes(src)\nlocal license = get_license(src)\nsrc = fold_lines(src)\nsrc = strip_unused1(src)\nsrc = save_strings(src)\nsrc = strip_unused2(src)\nsrc = strip_comments(src)\nsrc = preprocess(src)\nsrc = strip_whitespace(src)\nsrc = strip_unused3(src)\nsrc = rename_tokens1(src)\nsrc = func_collect(src)\nsrc = rename_tokens2(src)\nsrc = restore_strings(src)\nsrc = merge_header(src, license)\nio.write(src)\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/host/minilua.c",
    "content": "/* This is a heavily customized and minimized copy of Lua 5.1.5. */\n/* It's only used to build LuaJIT. It does NOT have all standard functions! */\n/******************************************************************************\n* Copyright (C) 1994-2012 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n#ifdef _MSC_VER\ntypedef unsigned __int64 U64;\n#else\ntypedef unsigned long long U64;\n#endif\nint _CRT_glob = 0;\n#include <stddef.h>\n#include <stdarg.h>\n#include <limits.h>\n#include <math.h>\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <setjmp.h>\n#include <errno.h>\n#include <time.h>\ntypedef enum{\nTM_INDEX,\nTM_NEWINDEX,\nTM_GC,\nTM_MODE,\nTM_EQ,\nTM_ADD,\nTM_SUB,\nTM_MUL,\nTM_DIV,\nTM_MOD,\nTM_POW,\nTM_UNM,\nTM_LEN,\nTM_LT,\nTM_LE,\nTM_CONCAT,\nTM_CALL,\nTM_N\n}TMS;\nenum OpMode{iABC,iABx,iAsBx};\ntypedef enum{\nOP_MOVE,\nOP_LOADK,\nOP_LOADBOOL,\nOP_LOADNIL,\nOP_GETUPVAL,\nOP_GETGLOBAL,\nOP_GETTABLE,\nOP_SETGLOBAL,\nOP_SETUPVAL,\nOP_SETTABLE,\nOP_NEWTABLE,\nOP_SELF,\nOP_ADD,\nOP_SUB,\nOP_MUL,\nOP_DIV,\nOP_MOD,\nOP_POW,\nOP_UNM,\nOP_NOT,\nOP_LEN,\nOP_CONCAT,\nOP_JMP,\nOP_EQ,\nOP_LT,\nOP_LE,\nOP_TEST,\nOP_TESTSET,\nOP_CALL,\nOP_TAILCALL,\nOP_RETURN,\nOP_FORLOOP,\nOP_FORPREP,\nOP_TFORLOOP,\nOP_SETLIST,\nOP_CLOSE,\nOP_CLOSURE,\nOP_VARARG\n}OpCode;\nenum OpArgMask{\nOpArgN,\nOpArgU,\nOpArgR,\nOpArgK\n};\ntypedef enum{\nVVOID,\nVNIL,\nVTRUE,\nVFALSE,\nVK,\nVKNUM,\nVLOCAL,\nVUPVAL,\nVGLOBAL,\nVINDEXED,\nVJMP,\nVRELOCABLE,\nVNONRELOC,\nVCALL,\nVVARARG\n}expkind;\nenum RESERVED{\nTK_AND=257,TK_BREAK,\nTK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION,\nTK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT,\nTK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE,\nTK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER,\nTK_NAME,TK_STRING,TK_EOS\n};\ntypedef enum BinOpr{\nOPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW,\nOPR_CONCAT,\nOPR_NE,OPR_EQ,\nOPR_LT,OPR_LE,OPR_GT,OPR_GE,\nOPR_AND,OPR_OR,\nOPR_NOBINOPR\n}BinOpr;\ntypedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr;\n#define LUA_QL(x)\"'\"x\"'\"\n#define luai_apicheck(L,o){(void)L;}\n#define lua_number2str(s,n)sprintf((s),\"%.14g\",(n))\n#define lua_str2number(s,p)strtod((s),(p))\n#define luai_numadd(a,b)((a)+(b))\n#define luai_numsub(a,b)((a)-(b))\n#define luai_nummul(a,b)((a)*(b))\n#define luai_numdiv(a,b)((a)/(b))\n#define luai_nummod(a,b)((a)-floor((a)/(b))*(b))\n#define luai_numpow(a,b)(pow(a,b))\n#define luai_numunm(a)(-(a))\n#define luai_numeq(a,b)((a)==(b))\n#define luai_numlt(a,b)((a)<(b))\n#define luai_numle(a,b)((a)<=(b))\n#define luai_numisnan(a)(!luai_numeq((a),(a)))\n#define lua_number2int(i,d)((i)=(int)(d))\n#define lua_number2integer(i,d)((i)=(lua_Integer)(d))\n#define LUAI_THROW(L,c)longjmp((c)->b,1)\n#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a}\n#define lua_pclose(L,file)((void)((void)L,file),0)\n#define lua_upvalueindex(i)((-10002)-(i))\ntypedef struct lua_State lua_State;\ntypedef int(*lua_CFunction)(lua_State*L);\ntypedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz);\ntypedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize);\ntypedef double lua_Number;\ntypedef ptrdiff_t lua_Integer;\nstatic void lua_settop(lua_State*L,int idx);\nstatic int lua_type(lua_State*L,int idx);\nstatic const char* lua_tolstring(lua_State*L,int idx,size_t*len);\nstatic size_t lua_objlen(lua_State*L,int idx);\nstatic void lua_pushlstring(lua_State*L,const char*s,size_t l);\nstatic void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n);\nstatic void lua_createtable(lua_State*L,int narr,int nrec);\nstatic void lua_setfield(lua_State*L,int idx,const char*k);\n#define lua_pop(L,n)lua_settop(L,-(n)-1)\n#define lua_newtable(L)lua_createtable(L,0,0)\n#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0)\n#define lua_strlen(L,i)lua_objlen(L,(i))\n#define lua_isfunction(L,n)(lua_type(L,(n))==6)\n#define lua_istable(L,n)(lua_type(L,(n))==5)\n#define lua_isnil(L,n)(lua_type(L,(n))==0)\n#define lua_isboolean(L,n)(lua_type(L,(n))==1)\n#define lua_isnone(L,n)(lua_type(L,(n))==(-1))\n#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0)\n#define lua_pushliteral(L,s)lua_pushlstring(L,\"\"s,(sizeof(s)/sizeof(char))-1)\n#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s))\n#define lua_tostring(L,i)lua_tolstring(L,(i),NULL)\ntypedef struct lua_Debug lua_Debug;\ntypedef void(*lua_Hook)(lua_State*L,lua_Debug*ar);\nstruct lua_Debug{\nint event;\nconst char*name;\nconst char*namewhat;\nconst char*what;\nconst char*source;\nint currentline;\nint nups;\nint linedefined;\nint lastlinedefined;\nchar short_src[60];\nint i_ci;\n};\ntypedef unsigned int lu_int32;\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\ntypedef unsigned char lu_byte;\n#define IntPoint(p)((unsigned int)(lu_mem)(p))\ntypedef union{double u;void*s;long l;}L_Umaxalign;\ntypedef double l_uacNumber;\n#define check_exp(c,e)(e)\n#define UNUSED(x)((void)(x))\n#define cast(t,exp)((t)(exp))\n#define cast_byte(i)cast(lu_byte,(i))\n#define cast_num(i)cast(lua_Number,(i))\n#define cast_int(i)cast(int,(i))\ntypedef lu_int32 Instruction;\n#define condhardstacktests(x)((void)0)\ntypedef union GCObject GCObject;\ntypedef struct GCheader{\nGCObject*next;lu_byte tt;lu_byte marked;\n}GCheader;\ntypedef union{\nGCObject*gc;\nvoid*p;\nlua_Number n;\nint b;\n}Value;\ntypedef struct lua_TValue{\nValue value;int tt;\n}TValue;\n#define ttisnil(o)(ttype(o)==0)\n#define ttisnumber(o)(ttype(o)==3)\n#define ttisstring(o)(ttype(o)==4)\n#define ttistable(o)(ttype(o)==5)\n#define ttisfunction(o)(ttype(o)==6)\n#define ttisboolean(o)(ttype(o)==1)\n#define ttisuserdata(o)(ttype(o)==7)\n#define ttisthread(o)(ttype(o)==8)\n#define ttislightuserdata(o)(ttype(o)==2)\n#define ttype(o)((o)->tt)\n#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc)\n#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p)\n#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n)\n#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts)\n#define tsvalue(o)(&rawtsvalue(o)->tsv)\n#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u)\n#define uvalue(o)(&rawuvalue(o)->uv)\n#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl)\n#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h)\n#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b)\n#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th)\n#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0))\n#define checkconsistency(obj)\n#define checkliveness(g,obj)\n#define setnilvalue(obj)((obj)->tt=0)\n#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;}\n#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;}\n#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);}\n#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);}\n#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);}\n#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);}\n#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);}\n#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);}\n#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);}\n#define setttype(obj,tt)(ttype(obj)=(tt))\n#define iscollectable(o)(ttype(o)>=4)\ntypedef TValue*StkId;\ntypedef union TString{\nL_Umaxalign dummy;\nstruct{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte reserved;\nunsigned int hash;\nsize_t len;\n}tsv;\n}TString;\n#define getstr(ts)cast(const char*,(ts)+1)\n#define svalue(o)getstr(rawtsvalue(o))\ntypedef union Udata{\nL_Umaxalign dummy;\nstruct{\nGCObject*next;lu_byte tt;lu_byte marked;\nstruct Table*metatable;\nstruct Table*env;\nsize_t len;\n}uv;\n}Udata;\ntypedef struct Proto{\nGCObject*next;lu_byte tt;lu_byte marked;\nTValue*k;\nInstruction*code;\nstruct Proto**p;\nint*lineinfo;\nstruct LocVar*locvars;\nTString**upvalues;\nTString*source;\nint sizeupvalues;\nint sizek;\nint sizecode;\nint sizelineinfo;\nint sizep;\nint sizelocvars;\nint linedefined;\nint lastlinedefined;\nGCObject*gclist;\nlu_byte nups;\nlu_byte numparams;\nlu_byte is_vararg;\nlu_byte maxstacksize;\n}Proto;\ntypedef struct LocVar{\nTString*varname;\nint startpc;\nint endpc;\n}LocVar;\ntypedef struct UpVal{\nGCObject*next;lu_byte tt;lu_byte marked;\nTValue*v;\nunion{\nTValue value;\nstruct{\nstruct UpVal*prev;\nstruct UpVal*next;\n}l;\n}u;\n}UpVal;\ntypedef struct CClosure{\nGCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;\nlua_CFunction f;\nTValue upvalue[1];\n}CClosure;\ntypedef struct LClosure{\nGCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;\nstruct Proto*p;\nUpVal*upvals[1];\n}LClosure;\ntypedef union Closure{\nCClosure c;\nLClosure l;\n}Closure;\n#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC)\ntypedef union TKey{\nstruct{\nValue value;int tt;\nstruct Node*next;\n}nk;\nTValue tvk;\n}TKey;\ntypedef struct Node{\nTValue i_val;\nTKey i_key;\n}Node;\ntypedef struct Table{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte flags;\nlu_byte lsizenode;\nstruct Table*metatable;\nTValue*array;\nNode*node;\nNode*lastfree;\nGCObject*gclist;\nint sizearray;\n}Table;\n#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1)))))\n#define twoto(x)((size_t)1<<(x))\n#define sizenode(t)(twoto((t)->lsizenode))\nstatic const TValue luaO_nilobject_;\n#define ceillog2(x)(luaO_log2((x)-1)+1)\nstatic int luaO_log2(unsigned int x);\n#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e]))\n#define fasttm(l,et,e)gfasttm(G(l),et,e)\nstatic const TValue*luaT_gettm(Table*events,TMS event,TString*ename);\n#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L))\n#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0)\n#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0)\n#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t))\n#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t))\n#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t)))\n#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t)))\n#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t))))\nstatic void*luaM_realloc_(lua_State*L,void*block,size_t oldsize,\nsize_t size);\nstatic void*luaM_toobig(lua_State*L);\nstatic void*luaM_growaux_(lua_State*L,void*block,int*size,\nsize_t size_elem,int limit,\nconst char*errormsg);\ntypedef struct Zio ZIO;\n#define char2int(c)cast(int,cast(unsigned char,(c)))\n#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z))\ntypedef struct Mbuffer{\nchar*buffer;\nsize_t n;\nsize_t buffsize;\n}Mbuffer;\n#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0)\n#define luaZ_buffer(buff)((buff)->buffer)\n#define luaZ_sizebuffer(buff)((buff)->buffsize)\n#define luaZ_bufflen(buff)((buff)->n)\n#define luaZ_resetbuffer(buff)((buff)->n=0)\n#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size)\n#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0)\nstruct Zio{\nsize_t n;\nconst char*p;\nlua_Reader reader;\nvoid*data;\nlua_State*L;\n};\nstatic int luaZ_fill(ZIO*z);\nstruct lua_longjmp;\n#define gt(L)(&L->l_gt)\n#define registry(L)(&G(L)->l_registry)\ntypedef struct stringtable{\nGCObject**hash;\nlu_int32 nuse;\nint size;\n}stringtable;\ntypedef struct CallInfo{\nStkId base;\nStkId func;\nStkId top;\nconst Instruction*savedpc;\nint nresults;\nint tailcalls;\n}CallInfo;\n#define curr_func(L)(clvalue(L->ci->func))\n#define ci_func(ci)(clvalue((ci)->func))\n#define f_isLua(ci)(!ci_func(ci)->c.isC)\n#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci))\ntypedef struct global_State{\nstringtable strt;\nlua_Alloc frealloc;\nvoid*ud;\nlu_byte currentwhite;\nlu_byte gcstate;\nint sweepstrgc;\nGCObject*rootgc;\nGCObject**sweepgc;\nGCObject*gray;\nGCObject*grayagain;\nGCObject*weak;\nGCObject*tmudata;\nMbuffer buff;\nlu_mem GCthreshold;\nlu_mem totalbytes;\nlu_mem estimate;\nlu_mem gcdept;\nint gcpause;\nint gcstepmul;\nlua_CFunction panic;\nTValue l_registry;\nstruct lua_State*mainthread;\nUpVal uvhead;\nstruct Table*mt[(8+1)];\nTString*tmname[TM_N];\n}global_State;\nstruct lua_State{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte status;\nStkId top;\nStkId base;\nglobal_State*l_G;\nCallInfo*ci;\nconst Instruction*savedpc;\nStkId stack_last;\nStkId stack;\nCallInfo*end_ci;\nCallInfo*base_ci;\nint stacksize;\nint size_ci;\nunsigned short nCcalls;\nunsigned short baseCcalls;\nlu_byte hookmask;\nlu_byte allowhook;\nint basehookcount;\nint hookcount;\nlua_Hook hook;\nTValue l_gt;\nTValue env;\nGCObject*openupval;\nGCObject*gclist;\nstruct lua_longjmp*errorJmp;\nptrdiff_t errfunc;\n};\n#define G(L)(L->l_G)\nunion GCObject{\nGCheader gch;\nunion TString ts;\nunion Udata u;\nunion Closure cl;\nstruct Table h;\nstruct Proto p;\nstruct UpVal uv;\nstruct lua_State th;\n};\n#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts))\n#define gco2ts(o)(&rawgco2ts(o)->tsv)\n#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u))\n#define gco2u(o)(&rawgco2u(o)->uv)\n#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl))\n#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h))\n#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p))\n#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv))\n#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv))\n#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th))\n#define obj2gco(v)(cast(GCObject*,(v)))\nstatic void luaE_freethread(lua_State*L,lua_State*L1);\n#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1)\n#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0)\n#define resethookcount(L)(L->hookcount=L->basehookcount)\nstatic void luaG_typeerror(lua_State*L,const TValue*o,\nconst char*opname);\nstatic void luaG_runerror(lua_State*L,const char*fmt,...);\n#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));\n#define incr_top(L){luaD_checkstack(L,1);L->top++;}\n#define savestack(L,p)((char*)(p)-(char*)L->stack)\n#define restorestack(L,n)((TValue*)((char*)L->stack+(n)))\n#define saveci(L,p)((char*)(p)-(char*)L->base_ci)\n#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n)))\ntypedef void(*Pfunc)(lua_State*L,void*ud);\nstatic int luaD_poscall(lua_State*L,StkId firstResult);\nstatic void luaD_reallocCI(lua_State*L,int newsize);\nstatic void luaD_reallocstack(lua_State*L,int newsize);\nstatic void luaD_growstack(lua_State*L,int n);\nstatic void luaD_throw(lua_State*L,int errcode);\nstatic void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems,\nint limit,const char*errormsg){\nvoid*newblock;\nint newsize;\nif(*size>=limit/2){\nif(*size>=limit)\nluaG_runerror(L,errormsg);\nnewsize=limit;\n}\nelse{\nnewsize=(*size)*2;\nif(newsize<4)\nnewsize=4;\n}\nnewblock=luaM_reallocv(L,block,*size,newsize,size_elems);\n*size=newsize;\nreturn newblock;\n}\nstatic void*luaM_toobig(lua_State*L){\nluaG_runerror(L,\"memory allocation error: block too big\");\nreturn NULL;\n}\nstatic void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){\nglobal_State*g=G(L);\nblock=(*g->frealloc)(g->ud,block,osize,nsize);\nif(block==NULL&&nsize>0)\nluaD_throw(L,4);\ng->totalbytes=(g->totalbytes-osize)+nsize;\nreturn block;\n}\n#define resetbits(x,m)((x)&=cast(lu_byte,~(m)))\n#define setbits(x,m)((x)|=(m))\n#define testbits(x,m)((x)&(m))\n#define bitmask(b)(1<<(b))\n#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2))\n#define l_setbit(x,b)setbits(x,bitmask(b))\n#define resetbit(x,b)resetbits(x,bitmask(b))\n#define testbit(x,b)testbits(x,bitmask(b))\n#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2)))\n#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2)))\n#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2)))\n#define iswhite(x)test2bits((x)->gch.marked,0,1)\n#define isblack(x)testbit((x)->gch.marked,2)\n#define isgray(x)(!isblack(x)&&!iswhite(x))\n#define otherwhite(g)(g->currentwhite^bit2mask(0,1))\n#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1))\n#define changewhite(x)((x)->gch.marked^=bit2mask(0,1))\n#define gray2black(x)l_setbit((x)->gch.marked,2)\n#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x)))\n#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1))\n#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);}\n#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));}\n#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);}\n#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));}\n#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);}\nstatic void luaC_step(lua_State*L);\nstatic void luaC_link(lua_State*L,GCObject*o,lu_byte tt);\nstatic void luaC_linkupval(lua_State*L,UpVal*uv);\nstatic void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v);\nstatic void luaC_barrierback(lua_State*L,Table*t);\n#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char))\n#define sizeudata(u)(sizeof(union Udata)+(u)->len)\n#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s)))\n#define luaS_newliteral(L,s)(luaS_newlstr(L,\"\"s,(sizeof(s)/sizeof(char))-1))\n#define luaS_fix(s)l_setbit((s)->tsv.marked,5)\nstatic TString*luaS_newlstr(lua_State*L,const char*str,size_t l);\n#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o)))\n#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL))\n#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2))\nstatic int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2);\nstatic const TValue*luaV_tonumber(const TValue*obj,TValue*n);\nstatic int luaV_tostring(lua_State*L,StkId obj);\nstatic void luaV_execute(lua_State*L,int nexeccalls);\nstatic void luaV_concat(lua_State*L,int total,int last);\nstatic const TValue luaO_nilobject_={{NULL},0};\nstatic int luaO_int2fb(unsigned int x){\nint e=0;\nwhile(x>=16){\nx=(x+1)>>1;\ne++;\n}\nif(x<8)return x;\nelse return((e+1)<<3)|(cast_int(x)-8);\n}\nstatic int luaO_fb2int(int x){\nint e=(x>>3)&31;\nif(e==0)return x;\nelse return((x&7)+8)<<(e-1);\n}\nstatic int luaO_log2(unsigned int x){\nstatic const lu_byte log_2[256]={\n0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n};\nint l=-1;\nwhile(x>=256){l+=8;x>>=8;}\nreturn l+log_2[x];\n}\nstatic int luaO_rawequalObj(const TValue*t1,const TValue*t2){\nif(ttype(t1)!=ttype(t2))return 0;\nelse switch(ttype(t1)){\ncase 0:\nreturn 1;\ncase 3:\nreturn luai_numeq(nvalue(t1),nvalue(t2));\ncase 1:\nreturn bvalue(t1)==bvalue(t2);\ncase 2:\nreturn pvalue(t1)==pvalue(t2);\ndefault:\nreturn gcvalue(t1)==gcvalue(t2);\n}\n}\nstatic int luaO_str2d(const char*s,lua_Number*result){\nchar*endptr;\n*result=lua_str2number(s,&endptr);\nif(endptr==s)return 0;\nif(*endptr=='x'||*endptr=='X')\n*result=cast_num(strtoul(s,&endptr,16));\nif(*endptr=='\\0')return 1;\nwhile(isspace(cast(unsigned char,*endptr)))endptr++;\nif(*endptr!='\\0')return 0;\nreturn 1;\n}\nstatic void pushstr(lua_State*L,const char*str){\nsetsvalue(L,L->top,luaS_new(L,str));\nincr_top(L);\n}\nstatic const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){\nint n=1;\npushstr(L,\"\");\nfor(;;){\nconst char*e=strchr(fmt,'%');\nif(e==NULL)break;\nsetsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt));\nincr_top(L);\nswitch(*(e+1)){\ncase's':{\nconst char*s=va_arg(argp,char*);\nif(s==NULL)s=\"(null)\";\npushstr(L,s);\nbreak;\n}\ncase'c':{\nchar buff[2];\nbuff[0]=cast(char,va_arg(argp,int));\nbuff[1]='\\0';\npushstr(L,buff);\nbreak;\n}\ncase'd':{\nsetnvalue(L->top,cast_num(va_arg(argp,int)));\nincr_top(L);\nbreak;\n}\ncase'f':{\nsetnvalue(L->top,cast_num(va_arg(argp,l_uacNumber)));\nincr_top(L);\nbreak;\n}\ncase'p':{\nchar buff[4*sizeof(void*)+8];\nsprintf(buff,\"%p\",va_arg(argp,void*));\npushstr(L,buff);\nbreak;\n}\ncase'%':{\npushstr(L,\"%\");\nbreak;\n}\ndefault:{\nchar buff[3];\nbuff[0]='%';\nbuff[1]=*(e+1);\nbuff[2]='\\0';\npushstr(L,buff);\nbreak;\n}\n}\nn+=2;\nfmt=e+2;\n}\npushstr(L,fmt);\nluaV_concat(L,n+1,cast_int(L->top-L->base)-1);\nL->top-=n;\nreturn svalue(L->top-1);\n}\nstatic const char*luaO_pushfstring(lua_State*L,const char*fmt,...){\nconst char*msg;\nva_list argp;\nva_start(argp,fmt);\nmsg=luaO_pushvfstring(L,fmt,argp);\nva_end(argp);\nreturn msg;\n}\nstatic void luaO_chunkid(char*out,const char*source,size_t bufflen){\nif(*source=='='){\nstrncpy(out,source+1,bufflen);\nout[bufflen-1]='\\0';\n}\nelse{\nif(*source=='@'){\nsize_t l;\nsource++;\nbufflen-=sizeof(\" '...' \");\nl=strlen(source);\nstrcpy(out,\"\");\nif(l>bufflen){\nsource+=(l-bufflen);\nstrcat(out,\"...\");\n}\nstrcat(out,source);\n}\nelse{\nsize_t len=strcspn(source,\"\\n\\r\");\nbufflen-=sizeof(\" [string \\\"...\\\"] \");\nif(len>bufflen)len=bufflen;\nstrcpy(out,\"[string \\\"\");\nif(source[len]!='\\0'){\nstrncat(out,source,len);\nstrcat(out,\"...\");\n}\nelse\nstrcat(out,source);\nstrcat(out,\"\\\"]\");\n}\n}\n}\n#define gnode(t,i)(&(t)->node[i])\n#define gkey(n)(&(n)->i_key.nk)\n#define gval(n)(&(n)->i_val)\n#define gnext(n)((n)->i_key.nk.next)\n#define key2tval(n)(&(n)->i_key.tvk)\nstatic TValue*luaH_setnum(lua_State*L,Table*t,int key);\nstatic const TValue*luaH_getstr(Table*t,TString*key);\nstatic TValue*luaH_set(lua_State*L,Table*t,const TValue*key);\nstatic const char*const luaT_typenames[]={\n\"nil\",\"boolean\",\"userdata\",\"number\",\n\"string\",\"table\",\"function\",\"userdata\",\"thread\",\n\"proto\",\"upval\"\n};\nstatic void luaT_init(lua_State*L){\nstatic const char*const luaT_eventname[]={\n\"__index\",\"__newindex\",\n\"__gc\",\"__mode\",\"__eq\",\n\"__add\",\"__sub\",\"__mul\",\"__div\",\"__mod\",\n\"__pow\",\"__unm\",\"__len\",\"__lt\",\"__le\",\n\"__concat\",\"__call\"\n};\nint i;\nfor(i=0;i<TM_N;i++){\nG(L)->tmname[i]=luaS_new(L,luaT_eventname[i]);\nluaS_fix(G(L)->tmname[i]);\n}\n}\nstatic const TValue*luaT_gettm(Table*events,TMS event,TString*ename){\nconst TValue*tm=luaH_getstr(events,ename);\nif(ttisnil(tm)){\nevents->flags|=cast_byte(1u<<event);\nreturn NULL;\n}\nelse return tm;\n}\nstatic const TValue*luaT_gettmbyobj(lua_State*L,const TValue*o,TMS event){\nTable*mt;\nswitch(ttype(o)){\ncase 5:\nmt=hvalue(o)->metatable;\nbreak;\ncase 7:\nmt=uvalue(o)->metatable;\nbreak;\ndefault:\nmt=G(L)->mt[ttype(o)];\n}\nreturn(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_));\n}\n#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1)))\n#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1)))\nstatic Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){\nClosure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems)));\nluaC_link(L,obj2gco(c),6);\nc->c.isC=1;\nc->c.env=e;\nc->c.nupvalues=cast_byte(nelems);\nreturn c;\n}\nstatic Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){\nClosure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems)));\nluaC_link(L,obj2gco(c),6);\nc->l.isC=0;\nc->l.env=e;\nc->l.nupvalues=cast_byte(nelems);\nwhile(nelems--)c->l.upvals[nelems]=NULL;\nreturn c;\n}\nstatic UpVal*luaF_newupval(lua_State*L){\nUpVal*uv=luaM_new(L,UpVal);\nluaC_link(L,obj2gco(uv),(8+2));\nuv->v=&uv->u.value;\nsetnilvalue(uv->v);\nreturn uv;\n}\nstatic UpVal*luaF_findupval(lua_State*L,StkId level){\nglobal_State*g=G(L);\nGCObject**pp=&L->openupval;\nUpVal*p;\nUpVal*uv;\nwhile(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){\nif(p->v==level){\nif(isdead(g,obj2gco(p)))\nchangewhite(obj2gco(p));\nreturn p;\n}\npp=&p->next;\n}\nuv=luaM_new(L,UpVal);\nuv->tt=(8+2);\nuv->marked=luaC_white(g);\nuv->v=level;\nuv->next=*pp;\n*pp=obj2gco(uv);\nuv->u.l.prev=&g->uvhead;\nuv->u.l.next=g->uvhead.u.l.next;\nuv->u.l.next->u.l.prev=uv;\ng->uvhead.u.l.next=uv;\nreturn uv;\n}\nstatic void unlinkupval(UpVal*uv){\nuv->u.l.next->u.l.prev=uv->u.l.prev;\nuv->u.l.prev->u.l.next=uv->u.l.next;\n}\nstatic void luaF_freeupval(lua_State*L,UpVal*uv){\nif(uv->v!=&uv->u.value)\nunlinkupval(uv);\nluaM_free(L,uv);\n}\nstatic void luaF_close(lua_State*L,StkId level){\nUpVal*uv;\nglobal_State*g=G(L);\nwhile(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){\nGCObject*o=obj2gco(uv);\nL->openupval=uv->next;\nif(isdead(g,o))\nluaF_freeupval(L,uv);\nelse{\nunlinkupval(uv);\nsetobj(L,&uv->u.value,uv->v);\nuv->v=&uv->u.value;\nluaC_linkupval(L,uv);\n}\n}\n}\nstatic Proto*luaF_newproto(lua_State*L){\nProto*f=luaM_new(L,Proto);\nluaC_link(L,obj2gco(f),(8+1));\nf->k=NULL;\nf->sizek=0;\nf->p=NULL;\nf->sizep=0;\nf->code=NULL;\nf->sizecode=0;\nf->sizelineinfo=0;\nf->sizeupvalues=0;\nf->nups=0;\nf->upvalues=NULL;\nf->numparams=0;\nf->is_vararg=0;\nf->maxstacksize=0;\nf->lineinfo=NULL;\nf->sizelocvars=0;\nf->locvars=NULL;\nf->linedefined=0;\nf->lastlinedefined=0;\nf->source=NULL;\nreturn f;\n}\nstatic void luaF_freeproto(lua_State*L,Proto*f){\nluaM_freearray(L,f->code,f->sizecode,Instruction);\nluaM_freearray(L,f->p,f->sizep,Proto*);\nluaM_freearray(L,f->k,f->sizek,TValue);\nluaM_freearray(L,f->lineinfo,f->sizelineinfo,int);\nluaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar);\nluaM_freearray(L,f->upvalues,f->sizeupvalues,TString*);\nluaM_free(L,f);\n}\nstatic void luaF_freeclosure(lua_State*L,Closure*c){\nint size=(c->c.isC)?sizeCclosure(c->c.nupvalues):\nsizeLclosure(c->l.nupvalues);\nluaM_freemem(L,c,size);\n}\n#define MASK1(n,p)((~((~(Instruction)0)<<n))<<p)\n#define MASK0(n,p)(~MASK1(n,p))\n#define GET_OPCODE(i)(cast(OpCode,((i)>>0)&MASK1(6,0)))\n#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0))))\n#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0)))\n#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6)))))\n#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0)))\n#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9)))))\n#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0)))\n#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8)))))\n#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0)))\n#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8)))))\n#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1))\n#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1)))\n#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8)))\n#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8)))\n#define ISK(x)((x)&(1<<(9-1)))\n#define INDEXK(r)((int)(r)&~(1<<(9-1)))\n#define RKASK(x)((x)|(1<<(9-1)))\nstatic const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)];\n#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3))\n#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3))\n#define testTMode(m)(luaP_opmodes[m]&(1<<7))\ntypedef struct expdesc{\nexpkind k;\nunion{\nstruct{int info,aux;}s;\nlua_Number nval;\n}u;\nint t;\nint f;\n}expdesc;\ntypedef struct upvaldesc{\nlu_byte k;\nlu_byte info;\n}upvaldesc;\nstruct BlockCnt;\ntypedef struct FuncState{\nProto*f;\nTable*h;\nstruct FuncState*prev;\nstruct LexState*ls;\nstruct lua_State*L;\nstruct BlockCnt*bl;\nint pc;\nint lasttarget;\nint jpc;\nint freereg;\nint nk;\nint np;\nshort nlocvars;\nlu_byte nactvar;\nupvaldesc upvalues[60];\nunsigned short actvar[200];\n}FuncState;\nstatic Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,\nconst char*name);\nstruct lua_longjmp{\nstruct lua_longjmp*previous;\njmp_buf b;\nvolatile int status;\n};\nstatic void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){\nswitch(errcode){\ncase 4:{\nsetsvalue(L,oldtop,luaS_newliteral(L,\"not enough memory\"));\nbreak;\n}\ncase 5:{\nsetsvalue(L,oldtop,luaS_newliteral(L,\"error in error handling\"));\nbreak;\n}\ncase 3:\ncase 2:{\nsetobj(L,oldtop,L->top-1);\nbreak;\n}\n}\nL->top=oldtop+1;\n}\nstatic void restore_stack_limit(lua_State*L){\nif(L->size_ci>20000){\nint inuse=cast_int(L->ci-L->base_ci);\nif(inuse+1<20000)\nluaD_reallocCI(L,20000);\n}\n}\nstatic void resetstack(lua_State*L,int status){\nL->ci=L->base_ci;\nL->base=L->ci->base;\nluaF_close(L,L->base);\nluaD_seterrorobj(L,status,L->base);\nL->nCcalls=L->baseCcalls;\nL->allowhook=1;\nrestore_stack_limit(L);\nL->errfunc=0;\nL->errorJmp=NULL;\n}\nstatic void luaD_throw(lua_State*L,int errcode){\nif(L->errorJmp){\nL->errorJmp->status=errcode;\nLUAI_THROW(L,L->errorJmp);\n}\nelse{\nL->status=cast_byte(errcode);\nif(G(L)->panic){\nresetstack(L,errcode);\nG(L)->panic(L);\n}\nexit(EXIT_FAILURE);\n}\n}\nstatic int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){\nstruct lua_longjmp lj;\nlj.status=0;\nlj.previous=L->errorJmp;\nL->errorJmp=&lj;\nLUAI_TRY(L,&lj,\n(*f)(L,ud);\n);\nL->errorJmp=lj.previous;\nreturn lj.status;\n}\nstatic void correctstack(lua_State*L,TValue*oldstack){\nCallInfo*ci;\nGCObject*up;\nL->top=(L->top-oldstack)+L->stack;\nfor(up=L->openupval;up!=NULL;up=up->gch.next)\ngco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack;\nfor(ci=L->base_ci;ci<=L->ci;ci++){\nci->top=(ci->top-oldstack)+L->stack;\nci->base=(ci->base-oldstack)+L->stack;\nci->func=(ci->func-oldstack)+L->stack;\n}\nL->base=(L->base-oldstack)+L->stack;\n}\nstatic void luaD_reallocstack(lua_State*L,int newsize){\nTValue*oldstack=L->stack;\nint realsize=newsize+1+5;\nluaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue);\nL->stacksize=realsize;\nL->stack_last=L->stack+newsize;\ncorrectstack(L,oldstack);\n}\nstatic void luaD_reallocCI(lua_State*L,int newsize){\nCallInfo*oldci=L->base_ci;\nluaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo);\nL->size_ci=newsize;\nL->ci=(L->ci-oldci)+L->base_ci;\nL->end_ci=L->base_ci+L->size_ci-1;\n}\nstatic void luaD_growstack(lua_State*L,int n){\nif(n<=L->stacksize)\nluaD_reallocstack(L,2*L->stacksize);\nelse\nluaD_reallocstack(L,L->stacksize+n);\n}\nstatic CallInfo*growCI(lua_State*L){\nif(L->size_ci>20000)\nluaD_throw(L,5);\nelse{\nluaD_reallocCI(L,2*L->size_ci);\nif(L->size_ci>20000)\nluaG_runerror(L,\"stack overflow\");\n}\nreturn++L->ci;\n}\nstatic StkId adjust_varargs(lua_State*L,Proto*p,int actual){\nint i;\nint nfixargs=p->numparams;\nTable*htab=NULL;\nStkId base,fixed;\nfor(;actual<nfixargs;++actual)\nsetnilvalue(L->top++);\nfixed=L->top-actual;\nbase=L->top;\nfor(i=0;i<nfixargs;i++){\nsetobj(L,L->top++,fixed+i);\nsetnilvalue(fixed+i);\n}\nif(htab){\nsethvalue(L,L->top++,htab);\n}\nreturn base;\n}\nstatic StkId tryfuncTM(lua_State*L,StkId func){\nconst TValue*tm=luaT_gettmbyobj(L,func,TM_CALL);\nStkId p;\nptrdiff_t funcr=savestack(L,func);\nif(!ttisfunction(tm))\nluaG_typeerror(L,func,\"call\");\nfor(p=L->top;p>func;p--)setobj(L,p,p-1);\nincr_top(L);\nfunc=restorestack(L,funcr);\nsetobj(L,func,tm);\nreturn func;\n}\n#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci))\nstatic int luaD_precall(lua_State*L,StkId func,int nresults){\nLClosure*cl;\nptrdiff_t funcr;\nif(!ttisfunction(func))\nfunc=tryfuncTM(L,func);\nfuncr=savestack(L,func);\ncl=&clvalue(func)->l;\nL->ci->savedpc=L->savedpc;\nif(!cl->isC){\nCallInfo*ci;\nStkId st,base;\nProto*p=cl->p;\nluaD_checkstack(L,p->maxstacksize);\nfunc=restorestack(L,funcr);\nif(!p->is_vararg){\nbase=func+1;\nif(L->top>base+p->numparams)\nL->top=base+p->numparams;\n}\nelse{\nint nargs=cast_int(L->top-func)-1;\nbase=adjust_varargs(L,p,nargs);\nfunc=restorestack(L,funcr);\n}\nci=inc_ci(L);\nci->func=func;\nL->base=ci->base=base;\nci->top=L->base+p->maxstacksize;\nL->savedpc=p->code;\nci->tailcalls=0;\nci->nresults=nresults;\nfor(st=L->top;st<ci->top;st++)\nsetnilvalue(st);\nL->top=ci->top;\nreturn 0;\n}\nelse{\nCallInfo*ci;\nint n;\nluaD_checkstack(L,20);\nci=inc_ci(L);\nci->func=restorestack(L,funcr);\nL->base=ci->base=ci->func+1;\nci->top=L->top+20;\nci->nresults=nresults;\nn=(*curr_func(L)->c.f)(L);\nif(n<0)\nreturn 2;\nelse{\nluaD_poscall(L,L->top-n);\nreturn 1;\n}\n}\n}\nstatic int luaD_poscall(lua_State*L,StkId firstResult){\nStkId res;\nint wanted,i;\nCallInfo*ci;\nci=L->ci--;\nres=ci->func;\nwanted=ci->nresults;\nL->base=(ci-1)->base;\nL->savedpc=(ci-1)->savedpc;\nfor(i=wanted;i!=0&&firstResult<L->top;i--)\nsetobj(L,res++,firstResult++);\nwhile(i-->0)\nsetnilvalue(res++);\nL->top=res;\nreturn(wanted-(-1));\n}\nstatic void luaD_call(lua_State*L,StkId func,int nResults){\nif(++L->nCcalls>=200){\nif(L->nCcalls==200)\nluaG_runerror(L,\"C stack overflow\");\nelse if(L->nCcalls>=(200+(200>>3)))\nluaD_throw(L,5);\n}\nif(luaD_precall(L,func,nResults)==0)\nluaV_execute(L,1);\nL->nCcalls--;\nluaC_checkGC(L);\n}\nstatic int luaD_pcall(lua_State*L,Pfunc func,void*u,\nptrdiff_t old_top,ptrdiff_t ef){\nint status;\nunsigned short oldnCcalls=L->nCcalls;\nptrdiff_t old_ci=saveci(L,L->ci);\nlu_byte old_allowhooks=L->allowhook;\nptrdiff_t old_errfunc=L->errfunc;\nL->errfunc=ef;\nstatus=luaD_rawrunprotected(L,func,u);\nif(status!=0){\nStkId oldtop=restorestack(L,old_top);\nluaF_close(L,oldtop);\nluaD_seterrorobj(L,status,oldtop);\nL->nCcalls=oldnCcalls;\nL->ci=restoreci(L,old_ci);\nL->base=L->ci->base;\nL->savedpc=L->ci->savedpc;\nL->allowhook=old_allowhooks;\nrestore_stack_limit(L);\n}\nL->errfunc=old_errfunc;\nreturn status;\n}\nstruct SParser{\nZIO*z;\nMbuffer buff;\nconst char*name;\n};\nstatic void f_parser(lua_State*L,void*ud){\nint i;\nProto*tf;\nClosure*cl;\nstruct SParser*p=cast(struct SParser*,ud);\nluaC_checkGC(L);\ntf=luaY_parser(L,p->z,\n&p->buff,p->name);\ncl=luaF_newLclosure(L,tf->nups,hvalue(gt(L)));\ncl->l.p=tf;\nfor(i=0;i<tf->nups;i++)\ncl->l.upvals[i]=luaF_newupval(L);\nsetclvalue(L,L->top,cl);\nincr_top(L);\n}\nstatic int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){\nstruct SParser p;\nint status;\np.z=z;p.name=name;\nluaZ_initbuffer(L,&p.buff);\nstatus=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc);\nluaZ_freebuffer(L,&p.buff);\nreturn status;\n}\nstatic void luaS_resize(lua_State*L,int newsize){\nGCObject**newhash;\nstringtable*tb;\nint i;\nif(G(L)->gcstate==2)\nreturn;\nnewhash=luaM_newvector(L,newsize,GCObject*);\ntb=&G(L)->strt;\nfor(i=0;i<newsize;i++)newhash[i]=NULL;\nfor(i=0;i<tb->size;i++){\nGCObject*p=tb->hash[i];\nwhile(p){\nGCObject*next=p->gch.next;\nunsigned int h=gco2ts(p)->hash;\nint h1=lmod(h,newsize);\np->gch.next=newhash[h1];\nnewhash[h1]=p;\np=next;\n}\n}\nluaM_freearray(L,tb->hash,tb->size,TString*);\ntb->size=newsize;\ntb->hash=newhash;\n}\nstatic TString*newlstr(lua_State*L,const char*str,size_t l,\nunsigned int h){\nTString*ts;\nstringtable*tb;\nif(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char))\nluaM_toobig(L);\nts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString)));\nts->tsv.len=l;\nts->tsv.hash=h;\nts->tsv.marked=luaC_white(G(L));\nts->tsv.tt=4;\nts->tsv.reserved=0;\nmemcpy(ts+1,str,l*sizeof(char));\n((char*)(ts+1))[l]='\\0';\ntb=&G(L)->strt;\nh=lmod(h,tb->size);\nts->tsv.next=tb->hash[h];\ntb->hash[h]=obj2gco(ts);\ntb->nuse++;\nif(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2)\nluaS_resize(L,tb->size*2);\nreturn ts;\n}\nstatic TString*luaS_newlstr(lua_State*L,const char*str,size_t l){\nGCObject*o;\nunsigned int h=cast(unsigned int,l);\nsize_t step=(l>>5)+1;\nsize_t l1;\nfor(l1=l;l1>=step;l1-=step)\nh=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1]));\nfor(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)];\no!=NULL;\no=o->gch.next){\nTString*ts=rawgco2ts(o);\nif(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){\nif(isdead(G(L),o))changewhite(o);\nreturn ts;\n}\n}\nreturn newlstr(L,str,l,h);\n}\nstatic Udata*luaS_newudata(lua_State*L,size_t s,Table*e){\nUdata*u;\nif(s>((size_t)(~(size_t)0)-2)-sizeof(Udata))\nluaM_toobig(L);\nu=cast(Udata*,luaM_malloc(L,s+sizeof(Udata)));\nu->uv.marked=luaC_white(G(L));\nu->uv.tt=7;\nu->uv.len=s;\nu->uv.metatable=NULL;\nu->uv.env=e;\nu->uv.next=G(L)->mainthread->next;\nG(L)->mainthread->next=obj2gco(u);\nreturn u;\n}\n#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t))))\n#define hashstr(t,str)hashpow2(t,(str)->tsv.hash)\n#define hashboolean(t,p)hashpow2(t,p)\n#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1))))\n#define hashpointer(t,p)hashmod(t,IntPoint(p))\nstatic const Node dummynode_={\n{{NULL},0},\n{{{NULL},0,NULL}}\n};\nstatic Node*hashnum(const Table*t,lua_Number n){\nunsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))];\nint i;\nif(luai_numeq(n,0))\nreturn gnode(t,0);\nmemcpy(a,&n,sizeof(a));\nfor(i=1;i<cast_int(sizeof(lua_Number)/sizeof(int));i++)a[0]+=a[i];\nreturn hashmod(t,a[0]);\n}\nstatic Node*mainposition(const Table*t,const TValue*key){\nswitch(ttype(key)){\ncase 3:\nreturn hashnum(t,nvalue(key));\ncase 4:\nreturn hashstr(t,rawtsvalue(key));\ncase 1:\nreturn hashboolean(t,bvalue(key));\ncase 2:\nreturn hashpointer(t,pvalue(key));\ndefault:\nreturn hashpointer(t,gcvalue(key));\n}\n}\nstatic int arrayindex(const TValue*key){\nif(ttisnumber(key)){\nlua_Number n=nvalue(key);\nint k;\nlua_number2int(k,n);\nif(luai_numeq(cast_num(k),n))\nreturn k;\n}\nreturn-1;\n}\nstatic int findindex(lua_State*L,Table*t,StkId key){\nint i;\nif(ttisnil(key))return-1;\ni=arrayindex(key);\nif(0<i&&i<=t->sizearray)\nreturn i-1;\nelse{\nNode*n=mainposition(t,key);\ndo{\nif(luaO_rawequalObj(key2tval(n),key)||\n(ttype(gkey(n))==(8+3)&&iscollectable(key)&&\ngcvalue(gkey(n))==gcvalue(key))){\ni=cast_int(n-gnode(t,0));\nreturn i+t->sizearray;\n}\nelse n=gnext(n);\n}while(n);\nluaG_runerror(L,\"invalid key to \"LUA_QL(\"next\"));\nreturn 0;\n}\n}\nstatic int luaH_next(lua_State*L,Table*t,StkId key){\nint i=findindex(L,t,key);\nfor(i++;i<t->sizearray;i++){\nif(!ttisnil(&t->array[i])){\nsetnvalue(key,cast_num(i+1));\nsetobj(L,key+1,&t->array[i]);\nreturn 1;\n}\n}\nfor(i-=t->sizearray;i<(int)sizenode(t);i++){\nif(!ttisnil(gval(gnode(t,i)))){\nsetobj(L,key,key2tval(gnode(t,i)));\nsetobj(L,key+1,gval(gnode(t,i)));\nreturn 1;\n}\n}\nreturn 0;\n}\nstatic int computesizes(int nums[],int*narray){\nint i;\nint twotoi;\nint a=0;\nint na=0;\nint n=0;\nfor(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){\nif(nums[i]>0){\na+=nums[i];\nif(a>twotoi/2){\nn=twotoi;\nna=a;\n}\n}\nif(a==*narray)break;\n}\n*narray=n;\nreturn na;\n}\nstatic int countint(const TValue*key,int*nums){\nint k=arrayindex(key);\nif(0<k&&k<=(1<<(32-2))){\nnums[ceillog2(k)]++;\nreturn 1;\n}\nelse\nreturn 0;\n}\nstatic int numusearray(const Table*t,int*nums){\nint lg;\nint ttlg;\nint ause=0;\nint i=1;\nfor(lg=0,ttlg=1;lg<=(32-2);lg++,ttlg*=2){\nint lc=0;\nint lim=ttlg;\nif(lim>t->sizearray){\nlim=t->sizearray;\nif(i>lim)\nbreak;\n}\nfor(;i<=lim;i++){\nif(!ttisnil(&t->array[i-1]))\nlc++;\n}\nnums[lg]+=lc;\nause+=lc;\n}\nreturn ause;\n}\nstatic int numusehash(const Table*t,int*nums,int*pnasize){\nint totaluse=0;\nint ause=0;\nint i=sizenode(t);\nwhile(i--){\nNode*n=&t->node[i];\nif(!ttisnil(gval(n))){\nause+=countint(key2tval(n),nums);\ntotaluse++;\n}\n}\n*pnasize+=ause;\nreturn totaluse;\n}\nstatic void setarrayvector(lua_State*L,Table*t,int size){\nint i;\nluaM_reallocvector(L,t->array,t->sizearray,size,TValue);\nfor(i=t->sizearray;i<size;i++)\nsetnilvalue(&t->array[i]);\nt->sizearray=size;\n}\nstatic void setnodevector(lua_State*L,Table*t,int size){\nint lsize;\nif(size==0){\nt->node=cast(Node*,(&dummynode_));\nlsize=0;\n}\nelse{\nint i;\nlsize=ceillog2(size);\nif(lsize>(32-2))\nluaG_runerror(L,\"table overflow\");\nsize=twoto(lsize);\nt->node=luaM_newvector(L,size,Node);\nfor(i=0;i<size;i++){\nNode*n=gnode(t,i);\ngnext(n)=NULL;\nsetnilvalue(gkey(n));\nsetnilvalue(gval(n));\n}\n}\nt->lsizenode=cast_byte(lsize);\nt->lastfree=gnode(t,size);\n}\nstatic void resize(lua_State*L,Table*t,int nasize,int nhsize){\nint i;\nint oldasize=t->sizearray;\nint oldhsize=t->lsizenode;\nNode*nold=t->node;\nif(nasize>oldasize)\nsetarrayvector(L,t,nasize);\nsetnodevector(L,t,nhsize);\nif(nasize<oldasize){\nt->sizearray=nasize;\nfor(i=nasize;i<oldasize;i++){\nif(!ttisnil(&t->array[i]))\nsetobj(L,luaH_setnum(L,t,i+1),&t->array[i]);\n}\nluaM_reallocvector(L,t->array,oldasize,nasize,TValue);\n}\nfor(i=twoto(oldhsize)-1;i>=0;i--){\nNode*old=nold+i;\nif(!ttisnil(gval(old)))\nsetobj(L,luaH_set(L,t,key2tval(old)),gval(old));\n}\nif(nold!=(&dummynode_))\nluaM_freearray(L,nold,twoto(oldhsize),Node);\n}\nstatic void luaH_resizearray(lua_State*L,Table*t,int nasize){\nint nsize=(t->node==(&dummynode_))?0:sizenode(t);\nresize(L,t,nasize,nsize);\n}\nstatic void rehash(lua_State*L,Table*t,const TValue*ek){\nint nasize,na;\nint nums[(32-2)+1];\nint i;\nint totaluse;\nfor(i=0;i<=(32-2);i++)nums[i]=0;\nnasize=numusearray(t,nums);\ntotaluse=nasize;\ntotaluse+=numusehash(t,nums,&nasize);\nnasize+=countint(ek,nums);\ntotaluse++;\nna=computesizes(nums,&nasize);\nresize(L,t,nasize,totaluse-na);\n}\nstatic Table*luaH_new(lua_State*L,int narray,int nhash){\nTable*t=luaM_new(L,Table);\nluaC_link(L,obj2gco(t),5);\nt->metatable=NULL;\nt->flags=cast_byte(~0);\nt->array=NULL;\nt->sizearray=0;\nt->lsizenode=0;\nt->node=cast(Node*,(&dummynode_));\nsetarrayvector(L,t,narray);\nsetnodevector(L,t,nhash);\nreturn t;\n}\nstatic void luaH_free(lua_State*L,Table*t){\nif(t->node!=(&dummynode_))\nluaM_freearray(L,t->node,sizenode(t),Node);\nluaM_freearray(L,t->array,t->sizearray,TValue);\nluaM_free(L,t);\n}\nstatic Node*getfreepos(Table*t){\nwhile(t->lastfree-->t->node){\nif(ttisnil(gkey(t->lastfree)))\nreturn t->lastfree;\n}\nreturn NULL;\n}\nstatic TValue*newkey(lua_State*L,Table*t,const TValue*key){\nNode*mp=mainposition(t,key);\nif(!ttisnil(gval(mp))||mp==(&dummynode_)){\nNode*othern;\nNode*n=getfreepos(t);\nif(n==NULL){\nrehash(L,t,key);\nreturn luaH_set(L,t,key);\n}\nothern=mainposition(t,key2tval(mp));\nif(othern!=mp){\nwhile(gnext(othern)!=mp)othern=gnext(othern);\ngnext(othern)=n;\n*n=*mp;\ngnext(mp)=NULL;\nsetnilvalue(gval(mp));\n}\nelse{\ngnext(n)=gnext(mp);\ngnext(mp)=n;\nmp=n;\n}\n}\ngkey(mp)->value=key->value;gkey(mp)->tt=key->tt;\nluaC_barriert(L,t,key);\nreturn gval(mp);\n}\nstatic const TValue*luaH_getnum(Table*t,int key){\nif(cast(unsigned int,key-1)<cast(unsigned int,t->sizearray))\nreturn&t->array[key-1];\nelse{\nlua_Number nk=cast_num(key);\nNode*n=hashnum(t,nk);\ndo{\nif(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk))\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\n}\nstatic const TValue*luaH_getstr(Table*t,TString*key){\nNode*n=hashstr(t,key);\ndo{\nif(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key)\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\nstatic const TValue*luaH_get(Table*t,const TValue*key){\nswitch(ttype(key)){\ncase 0:return(&luaO_nilobject_);\ncase 4:return luaH_getstr(t,rawtsvalue(key));\ncase 3:{\nint k;\nlua_Number n=nvalue(key);\nlua_number2int(k,n);\nif(luai_numeq(cast_num(k),nvalue(key)))\nreturn luaH_getnum(t,k);\n}\ndefault:{\nNode*n=mainposition(t,key);\ndo{\nif(luaO_rawequalObj(key2tval(n),key))\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\n}\n}\nstatic TValue*luaH_set(lua_State*L,Table*t,const TValue*key){\nconst TValue*p=luaH_get(t,key);\nt->flags=0;\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nif(ttisnil(key))luaG_runerror(L,\"table index is nil\");\nelse if(ttisnumber(key)&&luai_numisnan(nvalue(key)))\nluaG_runerror(L,\"table index is NaN\");\nreturn newkey(L,t,key);\n}\n}\nstatic TValue*luaH_setnum(lua_State*L,Table*t,int key){\nconst TValue*p=luaH_getnum(t,key);\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nTValue k;\nsetnvalue(&k,cast_num(key));\nreturn newkey(L,t,&k);\n}\n}\nstatic TValue*luaH_setstr(lua_State*L,Table*t,TString*key){\nconst TValue*p=luaH_getstr(t,key);\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nTValue k;\nsetsvalue(L,&k,key);\nreturn newkey(L,t,&k);\n}\n}\nstatic int unbound_search(Table*t,unsigned int j){\nunsigned int i=j;\nj++;\nwhile(!ttisnil(luaH_getnum(t,j))){\ni=j;\nj*=2;\nif(j>cast(unsigned int,(INT_MAX-2))){\ni=1;\nwhile(!ttisnil(luaH_getnum(t,i)))i++;\nreturn i-1;\n}\n}\nwhile(j-i>1){\nunsigned int m=(i+j)/2;\nif(ttisnil(luaH_getnum(t,m)))j=m;\nelse i=m;\n}\nreturn i;\n}\nstatic int luaH_getn(Table*t){\nunsigned int j=t->sizearray;\nif(j>0&&ttisnil(&t->array[j-1])){\nunsigned int i=0;\nwhile(j-i>1){\nunsigned int m=(i+j)/2;\nif(ttisnil(&t->array[m-1]))j=m;\nelse i=m;\n}\nreturn i;\n}\nelse if(t->node==(&dummynode_))\nreturn j;\nelse return unbound_search(t,j);\n}\n#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g)))\n#define white2gray(x)reset2bits((x)->gch.marked,0,1)\n#define black2gray(x)resetbit((x)->gch.marked,2)\n#define stringmark(s)reset2bits((s)->tsv.marked,0,1)\n#define isfinalized(u)testbit((u)->marked,3)\n#define markfinalized(u)l_setbit((u)->marked,3)\n#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));}\n#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));}\n#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause)\nstatic void removeentry(Node*n){\nif(iscollectable(gkey(n)))\nsetttype(gkey(n),(8+3));\n}\nstatic void reallymarkobject(global_State*g,GCObject*o){\nwhite2gray(o);\nswitch(o->gch.tt){\ncase 4:{\nreturn;\n}\ncase 7:{\nTable*mt=gco2u(o)->metatable;\ngray2black(o);\nif(mt)markobject(g,mt);\nmarkobject(g,gco2u(o)->env);\nreturn;\n}\ncase(8+2):{\nUpVal*uv=gco2uv(o);\nmarkvalue(g,uv->v);\nif(uv->v==&uv->u.value)\ngray2black(o);\nreturn;\n}\ncase 6:{\ngco2cl(o)->c.gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase 5:{\ngco2h(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase 8:{\ngco2th(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase(8+1):{\ngco2p(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ndefault:;\n}\n}\nstatic void marktmu(global_State*g){\nGCObject*u=g->tmudata;\nif(u){\ndo{\nu=u->gch.next;\nmakewhite(g,u);\nreallymarkobject(g,u);\n}while(u!=g->tmudata);\n}\n}\nstatic size_t luaC_separateudata(lua_State*L,int all){\nglobal_State*g=G(L);\nsize_t deadmem=0;\nGCObject**p=&g->mainthread->next;\nGCObject*curr;\nwhile((curr=*p)!=NULL){\nif(!(iswhite(curr)||all)||isfinalized(gco2u(curr)))\np=&curr->gch.next;\nelse if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){\nmarkfinalized(gco2u(curr));\np=&curr->gch.next;\n}\nelse{\ndeadmem+=sizeudata(gco2u(curr));\nmarkfinalized(gco2u(curr));\n*p=curr->gch.next;\nif(g->tmudata==NULL)\ng->tmudata=curr->gch.next=curr;\nelse{\ncurr->gch.next=g->tmudata->gch.next;\ng->tmudata->gch.next=curr;\ng->tmudata=curr;\n}\n}\n}\nreturn deadmem;\n}\nstatic int traversetable(global_State*g,Table*h){\nint i;\nint weakkey=0;\nint weakvalue=0;\nconst TValue*mode;\nif(h->metatable)\nmarkobject(g,h->metatable);\nmode=gfasttm(g,h->metatable,TM_MODE);\nif(mode&&ttisstring(mode)){\nweakkey=(strchr(svalue(mode),'k')!=NULL);\nweakvalue=(strchr(svalue(mode),'v')!=NULL);\nif(weakkey||weakvalue){\nh->marked&=~(bitmask(3)|bitmask(4));\nh->marked|=cast_byte((weakkey<<3)|\n(weakvalue<<4));\nh->gclist=g->weak;\ng->weak=obj2gco(h);\n}\n}\nif(weakkey&&weakvalue)return 1;\nif(!weakvalue){\ni=h->sizearray;\nwhile(i--)\nmarkvalue(g,&h->array[i]);\n}\ni=sizenode(h);\nwhile(i--){\nNode*n=gnode(h,i);\nif(ttisnil(gval(n)))\nremoveentry(n);\nelse{\nif(!weakkey)markvalue(g,gkey(n));\nif(!weakvalue)markvalue(g,gval(n));\n}\n}\nreturn weakkey||weakvalue;\n}\nstatic void traverseproto(global_State*g,Proto*f){\nint i;\nif(f->source)stringmark(f->source);\nfor(i=0;i<f->sizek;i++)\nmarkvalue(g,&f->k[i]);\nfor(i=0;i<f->sizeupvalues;i++){\nif(f->upvalues[i])\nstringmark(f->upvalues[i]);\n}\nfor(i=0;i<f->sizep;i++){\nif(f->p[i])\nmarkobject(g,f->p[i]);\n}\nfor(i=0;i<f->sizelocvars;i++){\nif(f->locvars[i].varname)\nstringmark(f->locvars[i].varname);\n}\n}\nstatic void traverseclosure(global_State*g,Closure*cl){\nmarkobject(g,cl->c.env);\nif(cl->c.isC){\nint i;\nfor(i=0;i<cl->c.nupvalues;i++)\nmarkvalue(g,&cl->c.upvalue[i]);\n}\nelse{\nint i;\nmarkobject(g,cl->l.p);\nfor(i=0;i<cl->l.nupvalues;i++)\nmarkobject(g,cl->l.upvals[i]);\n}\n}\nstatic void checkstacksizes(lua_State*L,StkId max){\nint ci_used=cast_int(L->ci-L->base_ci);\nint s_used=cast_int(max-L->stack);\nif(L->size_ci>20000)\nreturn;\nif(4*ci_used<L->size_ci&&2*8<L->size_ci)\nluaD_reallocCI(L,L->size_ci/2);\ncondhardstacktests(luaD_reallocCI(L,ci_used+1));\nif(4*s_used<L->stacksize&&\n2*((2*20)+5)<L->stacksize)\nluaD_reallocstack(L,L->stacksize/2);\ncondhardstacktests(luaD_reallocstack(L,s_used));\n}\nstatic void traversestack(global_State*g,lua_State*l){\nStkId o,lim;\nCallInfo*ci;\nmarkvalue(g,gt(l));\nlim=l->top;\nfor(ci=l->base_ci;ci<=l->ci;ci++){\nif(lim<ci->top)lim=ci->top;\n}\nfor(o=l->stack;o<l->top;o++)\nmarkvalue(g,o);\nfor(;o<=lim;o++)\nsetnilvalue(o);\ncheckstacksizes(l,lim);\n}\nstatic l_mem propagatemark(global_State*g){\nGCObject*o=g->gray;\ngray2black(o);\nswitch(o->gch.tt){\ncase 5:{\nTable*h=gco2h(o);\ng->gray=h->gclist;\nif(traversetable(g,h))\nblack2gray(o);\nreturn sizeof(Table)+sizeof(TValue)*h->sizearray+\nsizeof(Node)*sizenode(h);\n}\ncase 6:{\nClosure*cl=gco2cl(o);\ng->gray=cl->c.gclist;\ntraverseclosure(g,cl);\nreturn(cl->c.isC)?sizeCclosure(cl->c.nupvalues):\nsizeLclosure(cl->l.nupvalues);\n}\ncase 8:{\nlua_State*th=gco2th(o);\ng->gray=th->gclist;\nth->gclist=g->grayagain;\ng->grayagain=o;\nblack2gray(o);\ntraversestack(g,th);\nreturn sizeof(lua_State)+sizeof(TValue)*th->stacksize+\nsizeof(CallInfo)*th->size_ci;\n}\ncase(8+1):{\nProto*p=gco2p(o);\ng->gray=p->gclist;\ntraverseproto(g,p);\nreturn sizeof(Proto)+sizeof(Instruction)*p->sizecode+\nsizeof(Proto*)*p->sizep+\nsizeof(TValue)*p->sizek+\nsizeof(int)*p->sizelineinfo+\nsizeof(LocVar)*p->sizelocvars+\nsizeof(TString*)*p->sizeupvalues;\n}\ndefault:return 0;\n}\n}\nstatic size_t propagateall(global_State*g){\nsize_t m=0;\nwhile(g->gray)m+=propagatemark(g);\nreturn m;\n}\nstatic int iscleared(const TValue*o,int iskey){\nif(!iscollectable(o))return 0;\nif(ttisstring(o)){\nstringmark(rawtsvalue(o));\nreturn 0;\n}\nreturn iswhite(gcvalue(o))||\n(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o))));\n}\nstatic void cleartable(GCObject*l){\nwhile(l){\nTable*h=gco2h(l);\nint i=h->sizearray;\nif(testbit(h->marked,4)){\nwhile(i--){\nTValue*o=&h->array[i];\nif(iscleared(o,0))\nsetnilvalue(o);\n}\n}\ni=sizenode(h);\nwhile(i--){\nNode*n=gnode(h,i);\nif(!ttisnil(gval(n))&&\n(iscleared(key2tval(n),1)||iscleared(gval(n),0))){\nsetnilvalue(gval(n));\nremoveentry(n);\n}\n}\nl=h->gclist;\n}\n}\nstatic void freeobj(lua_State*L,GCObject*o){\nswitch(o->gch.tt){\ncase(8+1):luaF_freeproto(L,gco2p(o));break;\ncase 6:luaF_freeclosure(L,gco2cl(o));break;\ncase(8+2):luaF_freeupval(L,gco2uv(o));break;\ncase 5:luaH_free(L,gco2h(o));break;\ncase 8:{\nluaE_freethread(L,gco2th(o));\nbreak;\n}\ncase 4:{\nG(L)->strt.nuse--;\nluaM_freemem(L,o,sizestring(gco2ts(o)));\nbreak;\n}\ncase 7:{\nluaM_freemem(L,o,sizeudata(gco2u(o)));\nbreak;\n}\ndefault:;\n}\n}\n#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2))\nstatic GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){\nGCObject*curr;\nglobal_State*g=G(L);\nint deadmask=otherwhite(g);\nwhile((curr=*p)!=NULL&&count-->0){\nif(curr->gch.tt==8)\nsweepwholelist(L,&gco2th(curr)->openupval);\nif((curr->gch.marked^bit2mask(0,1))&deadmask){\nmakewhite(g,curr);\np=&curr->gch.next;\n}\nelse{\n*p=curr->gch.next;\nif(curr==g->rootgc)\ng->rootgc=curr->gch.next;\nfreeobj(L,curr);\n}\n}\nreturn p;\n}\nstatic void checkSizes(lua_State*L){\nglobal_State*g=G(L);\nif(g->strt.nuse<cast(lu_int32,g->strt.size/4)&&\ng->strt.size>32*2)\nluaS_resize(L,g->strt.size/2);\nif(luaZ_sizebuffer(&g->buff)>32*2){\nsize_t newsize=luaZ_sizebuffer(&g->buff)/2;\nluaZ_resizebuffer(L,&g->buff,newsize);\n}\n}\nstatic void GCTM(lua_State*L){\nglobal_State*g=G(L);\nGCObject*o=g->tmudata->gch.next;\nUdata*udata=rawgco2u(o);\nconst TValue*tm;\nif(o==g->tmudata)\ng->tmudata=NULL;\nelse\ng->tmudata->gch.next=udata->uv.next;\nudata->uv.next=g->mainthread->next;\ng->mainthread->next=o;\nmakewhite(g,o);\ntm=fasttm(L,udata->uv.metatable,TM_GC);\nif(tm!=NULL){\nlu_byte oldah=L->allowhook;\nlu_mem oldt=g->GCthreshold;\nL->allowhook=0;\ng->GCthreshold=2*g->totalbytes;\nsetobj(L,L->top,tm);\nsetuvalue(L,L->top+1,udata);\nL->top+=2;\nluaD_call(L,L->top-2,0);\nL->allowhook=oldah;\ng->GCthreshold=oldt;\n}\n}\nstatic void luaC_callGCTM(lua_State*L){\nwhile(G(L)->tmudata)\nGCTM(L);\n}\nstatic void luaC_freeall(lua_State*L){\nglobal_State*g=G(L);\nint i;\ng->currentwhite=bit2mask(0,1)|bitmask(6);\nsweepwholelist(L,&g->rootgc);\nfor(i=0;i<g->strt.size;i++)\nsweepwholelist(L,&g->strt.hash[i]);\n}\nstatic void markmt(global_State*g){\nint i;\nfor(i=0;i<(8+1);i++)\nif(g->mt[i])markobject(g,g->mt[i]);\n}\nstatic void markroot(lua_State*L){\nglobal_State*g=G(L);\ng->gray=NULL;\ng->grayagain=NULL;\ng->weak=NULL;\nmarkobject(g,g->mainthread);\nmarkvalue(g,gt(g->mainthread));\nmarkvalue(g,registry(L));\nmarkmt(g);\ng->gcstate=1;\n}\nstatic void remarkupvals(global_State*g){\nUpVal*uv;\nfor(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){\nif(isgray(obj2gco(uv)))\nmarkvalue(g,uv->v);\n}\n}\nstatic void atomic(lua_State*L){\nglobal_State*g=G(L);\nsize_t udsize;\nremarkupvals(g);\npropagateall(g);\ng->gray=g->weak;\ng->weak=NULL;\nmarkobject(g,L);\nmarkmt(g);\npropagateall(g);\ng->gray=g->grayagain;\ng->grayagain=NULL;\npropagateall(g);\nudsize=luaC_separateudata(L,0);\nmarktmu(g);\nudsize+=propagateall(g);\ncleartable(g->weak);\ng->currentwhite=cast_byte(otherwhite(g));\ng->sweepstrgc=0;\ng->sweepgc=&g->rootgc;\ng->gcstate=2;\ng->estimate=g->totalbytes-udsize;\n}\nstatic l_mem singlestep(lua_State*L){\nglobal_State*g=G(L);\nswitch(g->gcstate){\ncase 0:{\nmarkroot(L);\nreturn 0;\n}\ncase 1:{\nif(g->gray)\nreturn propagatemark(g);\nelse{\natomic(L);\nreturn 0;\n}\n}\ncase 2:{\nlu_mem old=g->totalbytes;\nsweepwholelist(L,&g->strt.hash[g->sweepstrgc++]);\nif(g->sweepstrgc>=g->strt.size)\ng->gcstate=3;\ng->estimate-=old-g->totalbytes;\nreturn 10;\n}\ncase 3:{\nlu_mem old=g->totalbytes;\ng->sweepgc=sweeplist(L,g->sweepgc,40);\nif(*g->sweepgc==NULL){\ncheckSizes(L);\ng->gcstate=4;\n}\ng->estimate-=old-g->totalbytes;\nreturn 40*10;\n}\ncase 4:{\nif(g->tmudata){\nGCTM(L);\nif(g->estimate>100)\ng->estimate-=100;\nreturn 100;\n}\nelse{\ng->gcstate=0;\ng->gcdept=0;\nreturn 0;\n}\n}\ndefault:return 0;\n}\n}\nstatic void luaC_step(lua_State*L){\nglobal_State*g=G(L);\nl_mem lim=(1024u/100)*g->gcstepmul;\nif(lim==0)\nlim=(((lu_mem)(~(lu_mem)0)-2)-1)/2;\ng->gcdept+=g->totalbytes-g->GCthreshold;\ndo{\nlim-=singlestep(L);\nif(g->gcstate==0)\nbreak;\n}while(lim>0);\nif(g->gcstate!=0){\nif(g->gcdept<1024u)\ng->GCthreshold=g->totalbytes+1024u;\nelse{\ng->gcdept-=1024u;\ng->GCthreshold=g->totalbytes;\n}\n}\nelse{\nsetthreshold(g);\n}\n}\nstatic void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){\nglobal_State*g=G(L);\nif(g->gcstate==1)\nreallymarkobject(g,v);\nelse\nmakewhite(g,o);\n}\nstatic void luaC_barrierback(lua_State*L,Table*t){\nglobal_State*g=G(L);\nGCObject*o=obj2gco(t);\nblack2gray(o);\nt->gclist=g->grayagain;\ng->grayagain=o;\n}\nstatic void luaC_link(lua_State*L,GCObject*o,lu_byte tt){\nglobal_State*g=G(L);\no->gch.next=g->rootgc;\ng->rootgc=o;\no->gch.marked=luaC_white(g);\no->gch.tt=tt;\n}\nstatic void luaC_linkupval(lua_State*L,UpVal*uv){\nglobal_State*g=G(L);\nGCObject*o=obj2gco(uv);\no->gch.next=g->rootgc;\ng->rootgc=o;\nif(isgray(o)){\nif(g->gcstate==1){\ngray2black(o);\nluaC_barrier(L,uv,uv->v);\n}\nelse{\nmakewhite(g,o);\n}\n}\n}\ntypedef union{\nlua_Number r;\nTString*ts;\n}SemInfo;\ntypedef struct Token{\nint token;\nSemInfo seminfo;\n}Token;\ntypedef struct LexState{\nint current;\nint linenumber;\nint lastline;\nToken t;\nToken lookahead;\nstruct FuncState*fs;\nstruct lua_State*L;\nZIO*z;\nMbuffer*buff;\nTString*source;\nchar decpoint;\n}LexState;\nstatic void luaX_init(lua_State*L);\nstatic void luaX_lexerror(LexState*ls,const char*msg,int token);\n#define state_size(x)(sizeof(x)+0)\n#define fromstate(l)(cast(lu_byte*,(l))-0)\n#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0))\ntypedef struct LG{\nlua_State l;\nglobal_State g;\n}LG;\nstatic void stack_init(lua_State*L1,lua_State*L){\nL1->base_ci=luaM_newvector(L,8,CallInfo);\nL1->ci=L1->base_ci;\nL1->size_ci=8;\nL1->end_ci=L1->base_ci+L1->size_ci-1;\nL1->stack=luaM_newvector(L,(2*20)+5,TValue);\nL1->stacksize=(2*20)+5;\nL1->top=L1->stack;\nL1->stack_last=L1->stack+(L1->stacksize-5)-1;\nL1->ci->func=L1->top;\nsetnilvalue(L1->top++);\nL1->base=L1->ci->base=L1->top;\nL1->ci->top=L1->top+20;\n}\nstatic void freestack(lua_State*L,lua_State*L1){\nluaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo);\nluaM_freearray(L,L1->stack,L1->stacksize,TValue);\n}\nstatic void f_luaopen(lua_State*L,void*ud){\nglobal_State*g=G(L);\nUNUSED(ud);\nstack_init(L,L);\nsethvalue(L,gt(L),luaH_new(L,0,2));\nsethvalue(L,registry(L),luaH_new(L,0,2));\nluaS_resize(L,32);\nluaT_init(L);\nluaX_init(L);\nluaS_fix(luaS_newliteral(L,\"not enough memory\"));\ng->GCthreshold=4*g->totalbytes;\n}\nstatic void preinit_state(lua_State*L,global_State*g){\nG(L)=g;\nL->stack=NULL;\nL->stacksize=0;\nL->errorJmp=NULL;\nL->hook=NULL;\nL->hookmask=0;\nL->basehookcount=0;\nL->allowhook=1;\nresethookcount(L);\nL->openupval=NULL;\nL->size_ci=0;\nL->nCcalls=L->baseCcalls=0;\nL->status=0;\nL->base_ci=L->ci=NULL;\nL->savedpc=NULL;\nL->errfunc=0;\nsetnilvalue(gt(L));\n}\nstatic void close_state(lua_State*L){\nglobal_State*g=G(L);\nluaF_close(L,L->stack);\nluaC_freeall(L);\nluaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*);\nluaZ_freebuffer(L,&g->buff);\nfreestack(L,L);\n(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0);\n}\nstatic void luaE_freethread(lua_State*L,lua_State*L1){\nluaF_close(L1,L1->stack);\nfreestack(L,L1);\nluaM_freemem(L,fromstate(L1),state_size(lua_State));\n}\nstatic lua_State*lua_newstate(lua_Alloc f,void*ud){\nint i;\nlua_State*L;\nglobal_State*g;\nvoid*l=(*f)(ud,NULL,0,state_size(LG));\nif(l==NULL)return NULL;\nL=tostate(l);\ng=&((LG*)L)->g;\nL->next=NULL;\nL->tt=8;\ng->currentwhite=bit2mask(0,5);\nL->marked=luaC_white(g);\nset2bits(L->marked,5,6);\npreinit_state(L,g);\ng->frealloc=f;\ng->ud=ud;\ng->mainthread=L;\ng->uvhead.u.l.prev=&g->uvhead;\ng->uvhead.u.l.next=&g->uvhead;\ng->GCthreshold=0;\ng->strt.size=0;\ng->strt.nuse=0;\ng->strt.hash=NULL;\nsetnilvalue(registry(L));\nluaZ_initbuffer(L,&g->buff);\ng->panic=NULL;\ng->gcstate=0;\ng->rootgc=obj2gco(L);\ng->sweepstrgc=0;\ng->sweepgc=&g->rootgc;\ng->gray=NULL;\ng->grayagain=NULL;\ng->weak=NULL;\ng->tmudata=NULL;\ng->totalbytes=sizeof(LG);\ng->gcpause=200;\ng->gcstepmul=200;\ng->gcdept=0;\nfor(i=0;i<(8+1);i++)g->mt[i]=NULL;\nif(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){\nclose_state(L);\nL=NULL;\n}\nelse\n{}\nreturn L;\n}\nstatic void callallgcTM(lua_State*L,void*ud){\nUNUSED(ud);\nluaC_callGCTM(L);\n}\nstatic void lua_close(lua_State*L){\nL=G(L)->mainthread;\nluaF_close(L,L->stack);\nluaC_separateudata(L,1);\nL->errfunc=0;\ndo{\nL->ci=L->base_ci;\nL->base=L->top=L->ci->base;\nL->nCcalls=L->baseCcalls=0;\n}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0);\nclose_state(L);\n}\n#define getcode(fs,e)((fs)->f->code[(e)->u.s.info])\n#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1))\n#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1))\nstatic int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx);\nstatic int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C);\nstatic void luaK_setreturns(FuncState*fs,expdesc*e,int nresults);\nstatic void luaK_patchtohere(FuncState*fs,int list);\nstatic void luaK_concat(FuncState*fs,int*l1,int l2);\nstatic int currentpc(lua_State*L,CallInfo*ci){\nif(!isLua(ci))return-1;\nif(ci==L->ci)\nci->savedpc=L->savedpc;\nreturn pcRel(ci->savedpc,ci_func(ci)->l.p);\n}\nstatic int currentline(lua_State*L,CallInfo*ci){\nint pc=currentpc(L,ci);\nif(pc<0)\nreturn-1;\nelse\nreturn getline_(ci_func(ci)->l.p,pc);\n}\nstatic int lua_getstack(lua_State*L,int level,lua_Debug*ar){\nint status;\nCallInfo*ci;\nfor(ci=L->ci;level>0&&ci>L->base_ci;ci--){\nlevel--;\nif(f_isLua(ci))\nlevel-=ci->tailcalls;\n}\nif(level==0&&ci>L->base_ci){\nstatus=1;\nar->i_ci=cast_int(ci-L->base_ci);\n}\nelse if(level<0){\nstatus=1;\nar->i_ci=0;\n}\nelse status=0;\nreturn status;\n}\nstatic Proto*getluaproto(CallInfo*ci){\nreturn(isLua(ci)?ci_func(ci)->l.p:NULL);\n}\nstatic void funcinfo(lua_Debug*ar,Closure*cl){\nif(cl->c.isC){\nar->source=\"=[C]\";\nar->linedefined=-1;\nar->lastlinedefined=-1;\nar->what=\"C\";\n}\nelse{\nar->source=getstr(cl->l.p->source);\nar->linedefined=cl->l.p->linedefined;\nar->lastlinedefined=cl->l.p->lastlinedefined;\nar->what=(ar->linedefined==0)?\"main\":\"Lua\";\n}\nluaO_chunkid(ar->short_src,ar->source,60);\n}\nstatic void info_tailcall(lua_Debug*ar){\nar->name=ar->namewhat=\"\";\nar->what=\"tail\";\nar->lastlinedefined=ar->linedefined=ar->currentline=-1;\nar->source=\"=(tail call)\";\nluaO_chunkid(ar->short_src,ar->source,60);\nar->nups=0;\n}\nstatic void collectvalidlines(lua_State*L,Closure*f){\nif(f==NULL||f->c.isC){\nsetnilvalue(L->top);\n}\nelse{\nTable*t=luaH_new(L,0,0);\nint*lineinfo=f->l.p->lineinfo;\nint i;\nfor(i=0;i<f->l.p->sizelineinfo;i++)\nsetbvalue(luaH_setnum(L,t,lineinfo[i]),1);\nsethvalue(L,L->top,t);\n}\nincr_top(L);\n}\nstatic int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar,\nClosure*f,CallInfo*ci){\nint status=1;\nif(f==NULL){\ninfo_tailcall(ar);\nreturn status;\n}\nfor(;*what;what++){\nswitch(*what){\ncase'S':{\nfuncinfo(ar,f);\nbreak;\n}\ncase'l':{\nar->currentline=(ci)?currentline(L,ci):-1;\nbreak;\n}\ncase'u':{\nar->nups=f->c.nupvalues;\nbreak;\n}\ncase'n':{\nar->namewhat=(ci)?NULL:NULL;\nif(ar->namewhat==NULL){\nar->namewhat=\"\";\nar->name=NULL;\n}\nbreak;\n}\ncase'L':\ncase'f':\nbreak;\ndefault:status=0;\n}\n}\nreturn status;\n}\nstatic int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){\nint status;\nClosure*f=NULL;\nCallInfo*ci=NULL;\nif(*what=='>'){\nStkId func=L->top-1;\nluai_apicheck(L,ttisfunction(func));\nwhat++;\nf=clvalue(func);\nL->top--;\n}\nelse if(ar->i_ci!=0){\nci=L->base_ci+ar->i_ci;\nf=clvalue(ci->func);\n}\nstatus=auxgetinfo(L,what,ar,f,ci);\nif(strchr(what,'f')){\nif(f==NULL)setnilvalue(L->top);\nelse setclvalue(L,L->top,f);\nincr_top(L);\n}\nif(strchr(what,'L'))\ncollectvalidlines(L,f);\nreturn status;\n}\nstatic int isinstack(CallInfo*ci,const TValue*o){\nStkId p;\nfor(p=ci->base;p<ci->top;p++)\nif(o==p)return 1;\nreturn 0;\n}\nstatic void luaG_typeerror(lua_State*L,const TValue*o,const char*op){\nconst char*name=NULL;\nconst char*t=luaT_typenames[ttype(o)];\nconst char*kind=(isinstack(L->ci,o))?\nNULL:\nNULL;\nif(kind)\nluaG_runerror(L,\"attempt to %s %s \"LUA_QL(\"%s\")\" (a %s value)\",\nop,kind,name,t);\nelse\nluaG_runerror(L,\"attempt to %s a %s value\",op,t);\n}\nstatic void luaG_concaterror(lua_State*L,StkId p1,StkId p2){\nif(ttisstring(p1)||ttisnumber(p1))p1=p2;\nluaG_typeerror(L,p1,\"concatenate\");\n}\nstatic void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){\nTValue temp;\nif(luaV_tonumber(p1,&temp)==NULL)\np2=p1;\nluaG_typeerror(L,p2,\"perform arithmetic on\");\n}\nstatic int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){\nconst char*t1=luaT_typenames[ttype(p1)];\nconst char*t2=luaT_typenames[ttype(p2)];\nif(t1[2]==t2[2])\nluaG_runerror(L,\"attempt to compare two %s values\",t1);\nelse\nluaG_runerror(L,\"attempt to compare %s with %s\",t1,t2);\nreturn 0;\n}\nstatic void addinfo(lua_State*L,const char*msg){\nCallInfo*ci=L->ci;\nif(isLua(ci)){\nchar buff[60];\nint line=currentline(L,ci);\nluaO_chunkid(buff,getstr(getluaproto(ci)->source),60);\nluaO_pushfstring(L,\"%s:%d: %s\",buff,line,msg);\n}\n}\nstatic void luaG_errormsg(lua_State*L){\nif(L->errfunc!=0){\nStkId errfunc=restorestack(L,L->errfunc);\nif(!ttisfunction(errfunc))luaD_throw(L,5);\nsetobj(L,L->top,L->top-1);\nsetobj(L,L->top-1,errfunc);\nincr_top(L);\nluaD_call(L,L->top-2,1);\n}\nluaD_throw(L,2);\n}\nstatic void luaG_runerror(lua_State*L,const char*fmt,...){\nva_list argp;\nva_start(argp,fmt);\naddinfo(L,luaO_pushvfstring(L,fmt,argp));\nva_end(argp);\nluaG_errormsg(L);\n}\nstatic int luaZ_fill(ZIO*z){\nsize_t size;\nlua_State*L=z->L;\nconst char*buff;\nbuff=z->reader(L,z->data,&size);\nif(buff==NULL||size==0)return(-1);\nz->n=size-1;\nz->p=buff;\nreturn char2int(*(z->p++));\n}\nstatic void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){\nz->L=L;\nz->reader=reader;\nz->data=data;\nz->n=0;\nz->p=NULL;\n}\nstatic char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){\nif(n>buff->buffsize){\nif(n<32)n=32;\nluaZ_resizebuffer(L,buff,n);\n}\nreturn buff->buffer;\n}\n#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m))\nstatic const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={\nopmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgK,OpArgN,iABx)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgU,OpArgN,iABC)\n,opmode(0,1,OpArgK,OpArgN,iABx)\n,opmode(0,1,OpArgR,OpArgK,iABC)\n,opmode(0,0,OpArgK,OpArgN,iABx)\n,opmode(0,0,OpArgU,OpArgN,iABC)\n,opmode(0,0,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgR,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgR,iABC)\n,opmode(0,0,OpArgR,OpArgN,iAsBx)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,1,OpArgR,OpArgU,iABC)\n,opmode(1,1,OpArgR,OpArgU,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,0,OpArgU,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iAsBx)\n,opmode(0,1,OpArgR,OpArgN,iAsBx)\n,opmode(1,0,OpArgN,OpArgU,iABC)\n,opmode(0,0,OpArgU,OpArgU,iABC)\n,opmode(0,0,OpArgN,OpArgN,iABC)\n,opmode(0,1,OpArgU,OpArgN,iABx)\n,opmode(0,1,OpArgU,OpArgN,iABC)\n};\n#define next(ls)(ls->current=zgetc(ls->z))\n#define currIsNewline(ls)(ls->current=='\\n'||ls->current=='\\r')\nstatic const char*const luaX_tokens[]={\n\"and\",\"break\",\"do\",\"else\",\"elseif\",\n\"end\",\"false\",\"for\",\"function\",\"if\",\n\"in\",\"local\",\"nil\",\"not\",\"or\",\"repeat\",\n\"return\",\"then\",\"true\",\"until\",\"while\",\n\"..\",\"...\",\"==\",\">=\",\"<=\",\"~=\",\n\"<number>\",\"<name>\",\"<string>\",\"<eof>\",\nNULL\n};\n#define save_and_next(ls)(save(ls,ls->current),next(ls))\nstatic void save(LexState*ls,int c){\nMbuffer*b=ls->buff;\nif(b->n+1>b->buffsize){\nsize_t newsize;\nif(b->buffsize>=((size_t)(~(size_t)0)-2)/2)\nluaX_lexerror(ls,\"lexical element too long\",0);\nnewsize=b->buffsize*2;\nluaZ_resizebuffer(ls->L,b,newsize);\n}\nb->buffer[b->n++]=cast(char,c);\n}\nstatic void luaX_init(lua_State*L){\nint i;\nfor(i=0;i<(cast(int,TK_WHILE-257+1));i++){\nTString*ts=luaS_new(L,luaX_tokens[i]);\nluaS_fix(ts);\nts->tsv.reserved=cast_byte(i+1);\n}\n}\nstatic const char*luaX_token2str(LexState*ls,int token){\nif(token<257){\nreturn(iscntrl(token))?luaO_pushfstring(ls->L,\"char(%d)\",token):\nluaO_pushfstring(ls->L,\"%c\",token);\n}\nelse\nreturn luaX_tokens[token-257];\n}\nstatic const char*txtToken(LexState*ls,int token){\nswitch(token){\ncase TK_NAME:\ncase TK_STRING:\ncase TK_NUMBER:\nsave(ls,'\\0');\nreturn luaZ_buffer(ls->buff);\ndefault:\nreturn luaX_token2str(ls,token);\n}\n}\nstatic void luaX_lexerror(LexState*ls,const char*msg,int token){\nchar buff[80];\nluaO_chunkid(buff,getstr(ls->source),80);\nmsg=luaO_pushfstring(ls->L,\"%s:%d: %s\",buff,ls->linenumber,msg);\nif(token)\nluaO_pushfstring(ls->L,\"%s near \"LUA_QL(\"%s\"),msg,txtToken(ls,token));\nluaD_throw(ls->L,3);\n}\nstatic void luaX_syntaxerror(LexState*ls,const char*msg){\nluaX_lexerror(ls,msg,ls->t.token);\n}\nstatic TString*luaX_newstring(LexState*ls,const char*str,size_t l){\nlua_State*L=ls->L;\nTString*ts=luaS_newlstr(L,str,l);\nTValue*o=luaH_setstr(L,ls->fs->h,ts);\nif(ttisnil(o)){\nsetbvalue(o,1);\nluaC_checkGC(L);\n}\nreturn ts;\n}\nstatic void inclinenumber(LexState*ls){\nint old=ls->current;\nnext(ls);\nif(currIsNewline(ls)&&ls->current!=old)\nnext(ls);\nif(++ls->linenumber>=(INT_MAX-2))\nluaX_syntaxerror(ls,\"chunk has too many lines\");\n}\nstatic void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){\nls->decpoint='.';\nls->L=L;\nls->lookahead.token=TK_EOS;\nls->z=z;\nls->fs=NULL;\nls->linenumber=1;\nls->lastline=1;\nls->source=source;\nluaZ_resizebuffer(ls->L,ls->buff,32);\nnext(ls);\n}\nstatic int check_next(LexState*ls,const char*set){\nif(!strchr(set,ls->current))\nreturn 0;\nsave_and_next(ls);\nreturn 1;\n}\nstatic void buffreplace(LexState*ls,char from,char to){\nsize_t n=luaZ_bufflen(ls->buff);\nchar*p=luaZ_buffer(ls->buff);\nwhile(n--)\nif(p[n]==from)p[n]=to;\n}\nstatic void read_numeral(LexState*ls,SemInfo*seminfo){\ndo{\nsave_and_next(ls);\n}while(isdigit(ls->current)||ls->current=='.');\nif(check_next(ls,\"Ee\"))\ncheck_next(ls,\"+-\");\nwhile(isalnum(ls->current)||ls->current=='_')\nsave_and_next(ls);\nsave(ls,'\\0');\nbuffreplace(ls,'.',ls->decpoint);\nif(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r))\nluaX_lexerror(ls,\"malformed number\",TK_NUMBER);\n}\nstatic int skip_sep(LexState*ls){\nint count=0;\nint s=ls->current;\nsave_and_next(ls);\nwhile(ls->current=='='){\nsave_and_next(ls);\ncount++;\n}\nreturn(ls->current==s)?count:(-count)-1;\n}\nstatic void read_long_string(LexState*ls,SemInfo*seminfo,int sep){\nint cont=0;\n(void)(cont);\nsave_and_next(ls);\nif(currIsNewline(ls))\ninclinenumber(ls);\nfor(;;){\nswitch(ls->current){\ncase(-1):\nluaX_lexerror(ls,(seminfo)?\"unfinished long string\":\n\"unfinished long comment\",TK_EOS);\nbreak;\ncase']':{\nif(skip_sep(ls)==sep){\nsave_and_next(ls);\ngoto endloop;\n}\nbreak;\n}\ncase'\\n':\ncase'\\r':{\nsave(ls,'\\n');\ninclinenumber(ls);\nif(!seminfo)luaZ_resetbuffer(ls->buff);\nbreak;\n}\ndefault:{\nif(seminfo)save_and_next(ls);\nelse next(ls);\n}\n}\n}endloop:\nif(seminfo)\nseminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep),\nluaZ_bufflen(ls->buff)-2*(2+sep));\n}\nstatic void read_string(LexState*ls,int del,SemInfo*seminfo){\nsave_and_next(ls);\nwhile(ls->current!=del){\nswitch(ls->current){\ncase(-1):\nluaX_lexerror(ls,\"unfinished string\",TK_EOS);\ncontinue;\ncase'\\n':\ncase'\\r':\nluaX_lexerror(ls,\"unfinished string\",TK_STRING);\ncontinue;\ncase'\\\\':{\nint c;\nnext(ls);\nswitch(ls->current){\ncase'a':c='\\a';break;\ncase'b':c='\\b';break;\ncase'f':c='\\f';break;\ncase'n':c='\\n';break;\ncase'r':c='\\r';break;\ncase't':c='\\t';break;\ncase'v':c='\\v';break;\ncase'\\n':\ncase'\\r':save(ls,'\\n');inclinenumber(ls);continue;\ncase(-1):continue;\ndefault:{\nif(!isdigit(ls->current))\nsave_and_next(ls);\nelse{\nint i=0;\nc=0;\ndo{\nc=10*c+(ls->current-'0');\nnext(ls);\n}while(++i<3&&isdigit(ls->current));\nif(c>UCHAR_MAX)\nluaX_lexerror(ls,\"escape sequence too large\",TK_STRING);\nsave(ls,c);\n}\ncontinue;\n}\n}\nsave(ls,c);\nnext(ls);\ncontinue;\n}\ndefault:\nsave_and_next(ls);\n}\n}\nsave_and_next(ls);\nseminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1,\nluaZ_bufflen(ls->buff)-2);\n}\nstatic int llex(LexState*ls,SemInfo*seminfo){\nluaZ_resetbuffer(ls->buff);\nfor(;;){\nswitch(ls->current){\ncase'\\n':\ncase'\\r':{\ninclinenumber(ls);\ncontinue;\n}\ncase'-':{\nnext(ls);\nif(ls->current!='-')return'-';\nnext(ls);\nif(ls->current=='['){\nint sep=skip_sep(ls);\nluaZ_resetbuffer(ls->buff);\nif(sep>=0){\nread_long_string(ls,NULL,sep);\nluaZ_resetbuffer(ls->buff);\ncontinue;\n}\n}\nwhile(!currIsNewline(ls)&&ls->current!=(-1))\nnext(ls);\ncontinue;\n}\ncase'[':{\nint sep=skip_sep(ls);\nif(sep>=0){\nread_long_string(ls,seminfo,sep);\nreturn TK_STRING;\n}\nelse if(sep==-1)return'[';\nelse luaX_lexerror(ls,\"invalid long string delimiter\",TK_STRING);\n}\ncase'=':{\nnext(ls);\nif(ls->current!='=')return'=';\nelse{next(ls);return TK_EQ;}\n}\ncase'<':{\nnext(ls);\nif(ls->current!='=')return'<';\nelse{next(ls);return TK_LE;}\n}\ncase'>':{\nnext(ls);\nif(ls->current!='=')return'>';\nelse{next(ls);return TK_GE;}\n}\ncase'~':{\nnext(ls);\nif(ls->current!='=')return'~';\nelse{next(ls);return TK_NE;}\n}\ncase'\"':\ncase'\\'':{\nread_string(ls,ls->current,seminfo);\nreturn TK_STRING;\n}\ncase'.':{\nsave_and_next(ls);\nif(check_next(ls,\".\")){\nif(check_next(ls,\".\"))\nreturn TK_DOTS;\nelse return TK_CONCAT;\n}\nelse if(!isdigit(ls->current))return'.';\nelse{\nread_numeral(ls,seminfo);\nreturn TK_NUMBER;\n}\n}\ncase(-1):{\nreturn TK_EOS;\n}\ndefault:{\nif(isspace(ls->current)){\nnext(ls);\ncontinue;\n}\nelse if(isdigit(ls->current)){\nread_numeral(ls,seminfo);\nreturn TK_NUMBER;\n}\nelse if(isalpha(ls->current)||ls->current=='_'){\nTString*ts;\ndo{\nsave_and_next(ls);\n}while(isalnum(ls->current)||ls->current=='_');\nts=luaX_newstring(ls,luaZ_buffer(ls->buff),\nluaZ_bufflen(ls->buff));\nif(ts->tsv.reserved>0)\nreturn ts->tsv.reserved-1+257;\nelse{\nseminfo->ts=ts;\nreturn TK_NAME;\n}\n}\nelse{\nint c=ls->current;\nnext(ls);\nreturn c;\n}\n}\n}\n}\n}\nstatic void luaX_next(LexState*ls){\nls->lastline=ls->linenumber;\nif(ls->lookahead.token!=TK_EOS){\nls->t=ls->lookahead;\nls->lookahead.token=TK_EOS;\n}\nelse\nls->t.token=llex(ls,&ls->t.seminfo);\n}\nstatic void luaX_lookahead(LexState*ls){\nls->lookahead.token=llex(ls,&ls->lookahead.seminfo);\n}\n#define hasjumps(e)((e)->t!=(e)->f)\nstatic int isnumeral(expdesc*e){\nreturn(e->k==VKNUM&&e->t==(-1)&&e->f==(-1));\n}\nstatic void luaK_nil(FuncState*fs,int from,int n){\nInstruction*previous;\nif(fs->pc>fs->lasttarget){\nif(fs->pc==0){\nif(from>=fs->nactvar)\nreturn;\n}\nelse{\nprevious=&fs->f->code[fs->pc-1];\nif(GET_OPCODE(*previous)==OP_LOADNIL){\nint pfrom=GETARG_A(*previous);\nint pto=GETARG_B(*previous);\nif(pfrom<=from&&from<=pto+1){\nif(from+n-1>pto)\nSETARG_B(*previous,from+n-1);\nreturn;\n}\n}\n}\n}\nluaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0);\n}\nstatic int luaK_jump(FuncState*fs){\nint jpc=fs->jpc;\nint j;\nfs->jpc=(-1);\nj=luaK_codeAsBx(fs,OP_JMP,0,(-1));\nluaK_concat(fs,&j,jpc);\nreturn j;\n}\nstatic void luaK_ret(FuncState*fs,int first,int nret){\nluaK_codeABC(fs,OP_RETURN,first,nret+1,0);\n}\nstatic int condjump(FuncState*fs,OpCode op,int A,int B,int C){\nluaK_codeABC(fs,op,A,B,C);\nreturn luaK_jump(fs);\n}\nstatic void fixjump(FuncState*fs,int pc,int dest){\nInstruction*jmp=&fs->f->code[pc];\nint offset=dest-(pc+1);\nif(abs(offset)>(((1<<(9+9))-1)>>1))\nluaX_syntaxerror(fs->ls,\"control structure too long\");\nSETARG_sBx(*jmp,offset);\n}\nstatic int luaK_getlabel(FuncState*fs){\nfs->lasttarget=fs->pc;\nreturn fs->pc;\n}\nstatic int getjump(FuncState*fs,int pc){\nint offset=GETARG_sBx(fs->f->code[pc]);\nif(offset==(-1))\nreturn(-1);\nelse\nreturn(pc+1)+offset;\n}\nstatic Instruction*getjumpcontrol(FuncState*fs,int pc){\nInstruction*pi=&fs->f->code[pc];\nif(pc>=1&&testTMode(GET_OPCODE(*(pi-1))))\nreturn pi-1;\nelse\nreturn pi;\n}\nstatic int need_value(FuncState*fs,int list){\nfor(;list!=(-1);list=getjump(fs,list)){\nInstruction i=*getjumpcontrol(fs,list);\nif(GET_OPCODE(i)!=OP_TESTSET)return 1;\n}\nreturn 0;\n}\nstatic int patchtestreg(FuncState*fs,int node,int reg){\nInstruction*i=getjumpcontrol(fs,node);\nif(GET_OPCODE(*i)!=OP_TESTSET)\nreturn 0;\nif(reg!=((1<<8)-1)&&reg!=GETARG_B(*i))\nSETARG_A(*i,reg);\nelse\n*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i));\nreturn 1;\n}\nstatic void removevalues(FuncState*fs,int list){\nfor(;list!=(-1);list=getjump(fs,list))\npatchtestreg(fs,list,((1<<8)-1));\n}\nstatic void patchlistaux(FuncState*fs,int list,int vtarget,int reg,\nint dtarget){\nwhile(list!=(-1)){\nint next=getjump(fs,list);\nif(patchtestreg(fs,list,reg))\nfixjump(fs,list,vtarget);\nelse\nfixjump(fs,list,dtarget);\nlist=next;\n}\n}\nstatic void dischargejpc(FuncState*fs){\npatchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc);\nfs->jpc=(-1);\n}\nstatic void luaK_patchlist(FuncState*fs,int list,int target){\nif(target==fs->pc)\nluaK_patchtohere(fs,list);\nelse{\npatchlistaux(fs,list,target,((1<<8)-1),target);\n}\n}\nstatic void luaK_patchtohere(FuncState*fs,int list){\nluaK_getlabel(fs);\nluaK_concat(fs,&fs->jpc,list);\n}\nstatic void luaK_concat(FuncState*fs,int*l1,int l2){\nif(l2==(-1))return;\nelse if(*l1==(-1))\n*l1=l2;\nelse{\nint list=*l1;\nint next;\nwhile((next=getjump(fs,list))!=(-1))\nlist=next;\nfixjump(fs,list,l2);\n}\n}\nstatic void luaK_checkstack(FuncState*fs,int n){\nint newstack=fs->freereg+n;\nif(newstack>fs->f->maxstacksize){\nif(newstack>=250)\nluaX_syntaxerror(fs->ls,\"function or expression too complex\");\nfs->f->maxstacksize=cast_byte(newstack);\n}\n}\nstatic void luaK_reserveregs(FuncState*fs,int n){\nluaK_checkstack(fs,n);\nfs->freereg+=n;\n}\nstatic void freereg(FuncState*fs,int reg){\nif(!ISK(reg)&&reg>=fs->nactvar){\nfs->freereg--;\n}\n}\nstatic void freeexp(FuncState*fs,expdesc*e){\nif(e->k==VNONRELOC)\nfreereg(fs,e->u.s.info);\n}\nstatic int addk(FuncState*fs,TValue*k,TValue*v){\nlua_State*L=fs->L;\nTValue*idx=luaH_set(L,fs->h,k);\nProto*f=fs->f;\nint oldsize=f->sizek;\nif(ttisnumber(idx)){\nreturn cast_int(nvalue(idx));\n}\nelse{\nsetnvalue(idx,cast_num(fs->nk));\nluaM_growvector(L,f->k,fs->nk,f->sizek,TValue,\n((1<<(9+9))-1),\"constant table overflow\");\nwhile(oldsize<f->sizek)setnilvalue(&f->k[oldsize++]);\nsetobj(L,&f->k[fs->nk],v);\nluaC_barrier(L,f,v);\nreturn fs->nk++;\n}\n}\nstatic int luaK_stringK(FuncState*fs,TString*s){\nTValue o;\nsetsvalue(fs->L,&o,s);\nreturn addk(fs,&o,&o);\n}\nstatic int luaK_numberK(FuncState*fs,lua_Number r){\nTValue o;\nsetnvalue(&o,r);\nreturn addk(fs,&o,&o);\n}\nstatic int boolK(FuncState*fs,int b){\nTValue o;\nsetbvalue(&o,b);\nreturn addk(fs,&o,&o);\n}\nstatic int nilK(FuncState*fs){\nTValue k,v;\nsetnilvalue(&v);\nsethvalue(fs->L,&k,fs->h);\nreturn addk(fs,&k,&v);\n}\nstatic void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){\nif(e->k==VCALL){\nSETARG_C(getcode(fs,e),nresults+1);\n}\nelse if(e->k==VVARARG){\nSETARG_B(getcode(fs,e),nresults+1);\nSETARG_A(getcode(fs,e),fs->freereg);\nluaK_reserveregs(fs,1);\n}\n}\nstatic void luaK_setoneret(FuncState*fs,expdesc*e){\nif(e->k==VCALL){\ne->k=VNONRELOC;\ne->u.s.info=GETARG_A(getcode(fs,e));\n}\nelse if(e->k==VVARARG){\nSETARG_B(getcode(fs,e),2);\ne->k=VRELOCABLE;\n}\n}\nstatic void luaK_dischargevars(FuncState*fs,expdesc*e){\nswitch(e->k){\ncase VLOCAL:{\ne->k=VNONRELOC;\nbreak;\n}\ncase VUPVAL:{\ne->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VGLOBAL:{\ne->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VINDEXED:{\nfreereg(fs,e->u.s.aux);\nfreereg(fs,e->u.s.info);\ne->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VVARARG:\ncase VCALL:{\nluaK_setoneret(fs,e);\nbreak;\n}\ndefault:break;\n}\n}\nstatic int code_label(FuncState*fs,int A,int b,int jump){\nluaK_getlabel(fs);\nreturn luaK_codeABC(fs,OP_LOADBOOL,A,b,jump);\n}\nstatic void discharge2reg(FuncState*fs,expdesc*e,int reg){\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:{\nluaK_nil(fs,reg,1);\nbreak;\n}\ncase VFALSE:case VTRUE:{\nluaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0);\nbreak;\n}\ncase VK:{\nluaK_codeABx(fs,OP_LOADK,reg,e->u.s.info);\nbreak;\n}\ncase VKNUM:{\nluaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval));\nbreak;\n}\ncase VRELOCABLE:{\nInstruction*pc=&getcode(fs,e);\nSETARG_A(*pc,reg);\nbreak;\n}\ncase VNONRELOC:{\nif(reg!=e->u.s.info)\nluaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0);\nbreak;\n}\ndefault:{\nreturn;\n}\n}\ne->u.s.info=reg;\ne->k=VNONRELOC;\n}\nstatic void discharge2anyreg(FuncState*fs,expdesc*e){\nif(e->k!=VNONRELOC){\nluaK_reserveregs(fs,1);\ndischarge2reg(fs,e,fs->freereg-1);\n}\n}\nstatic void exp2reg(FuncState*fs,expdesc*e,int reg){\ndischarge2reg(fs,e,reg);\nif(e->k==VJMP)\nluaK_concat(fs,&e->t,e->u.s.info);\nif(hasjumps(e)){\nint final;\nint p_f=(-1);\nint p_t=(-1);\nif(need_value(fs,e->t)||need_value(fs,e->f)){\nint fj=(e->k==VJMP)?(-1):luaK_jump(fs);\np_f=code_label(fs,reg,0,1);\np_t=code_label(fs,reg,1,0);\nluaK_patchtohere(fs,fj);\n}\nfinal=luaK_getlabel(fs);\npatchlistaux(fs,e->f,final,reg,p_f);\npatchlistaux(fs,e->t,final,reg,p_t);\n}\ne->f=e->t=(-1);\ne->u.s.info=reg;\ne->k=VNONRELOC;\n}\nstatic void luaK_exp2nextreg(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nfreeexp(fs,e);\nluaK_reserveregs(fs,1);\nexp2reg(fs,e,fs->freereg-1);\n}\nstatic int luaK_exp2anyreg(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nif(e->k==VNONRELOC){\nif(!hasjumps(e))return e->u.s.info;\nif(e->u.s.info>=fs->nactvar){\nexp2reg(fs,e,e->u.s.info);\nreturn e->u.s.info;\n}\n}\nluaK_exp2nextreg(fs,e);\nreturn e->u.s.info;\n}\nstatic void luaK_exp2val(FuncState*fs,expdesc*e){\nif(hasjumps(e))\nluaK_exp2anyreg(fs,e);\nelse\nluaK_dischargevars(fs,e);\n}\nstatic int luaK_exp2RK(FuncState*fs,expdesc*e){\nluaK_exp2val(fs,e);\nswitch(e->k){\ncase VKNUM:\ncase VTRUE:\ncase VFALSE:\ncase VNIL:{\nif(fs->nk<=((1<<(9-1))-1)){\ne->u.s.info=(e->k==VNIL)?nilK(fs):\n(e->k==VKNUM)?luaK_numberK(fs,e->u.nval):\nboolK(fs,(e->k==VTRUE));\ne->k=VK;\nreturn RKASK(e->u.s.info);\n}\nelse break;\n}\ncase VK:{\nif(e->u.s.info<=((1<<(9-1))-1))\nreturn RKASK(e->u.s.info);\nelse break;\n}\ndefault:break;\n}\nreturn luaK_exp2anyreg(fs,e);\n}\nstatic void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){\nswitch(var->k){\ncase VLOCAL:{\nfreeexp(fs,ex);\nexp2reg(fs,ex,var->u.s.info);\nreturn;\n}\ncase VUPVAL:{\nint e=luaK_exp2anyreg(fs,ex);\nluaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0);\nbreak;\n}\ncase VGLOBAL:{\nint e=luaK_exp2anyreg(fs,ex);\nluaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info);\nbreak;\n}\ncase VINDEXED:{\nint e=luaK_exp2RK(fs,ex);\nluaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e);\nbreak;\n}\ndefault:{\nbreak;\n}\n}\nfreeexp(fs,ex);\n}\nstatic void luaK_self(FuncState*fs,expdesc*e,expdesc*key){\nint func;\nluaK_exp2anyreg(fs,e);\nfreeexp(fs,e);\nfunc=fs->freereg;\nluaK_reserveregs(fs,2);\nluaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key));\nfreeexp(fs,key);\ne->u.s.info=func;\ne->k=VNONRELOC;\n}\nstatic void invertjump(FuncState*fs,expdesc*e){\nInstruction*pc=getjumpcontrol(fs,e->u.s.info);\nSETARG_A(*pc,!(GETARG_A(*pc)));\n}\nstatic int jumponcond(FuncState*fs,expdesc*e,int cond){\nif(e->k==VRELOCABLE){\nInstruction ie=getcode(fs,e);\nif(GET_OPCODE(ie)==OP_NOT){\nfs->pc--;\nreturn condjump(fs,OP_TEST,GETARG_B(ie),0,!cond);\n}\n}\ndischarge2anyreg(fs,e);\nfreeexp(fs,e);\nreturn condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond);\n}\nstatic void luaK_goiftrue(FuncState*fs,expdesc*e){\nint pc;\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VK:case VKNUM:case VTRUE:{\npc=(-1);\nbreak;\n}\ncase VJMP:{\ninvertjump(fs,e);\npc=e->u.s.info;\nbreak;\n}\ndefault:{\npc=jumponcond(fs,e,0);\nbreak;\n}\n}\nluaK_concat(fs,&e->f,pc);\nluaK_patchtohere(fs,e->t);\ne->t=(-1);\n}\nstatic void luaK_goiffalse(FuncState*fs,expdesc*e){\nint pc;\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:case VFALSE:{\npc=(-1);\nbreak;\n}\ncase VJMP:{\npc=e->u.s.info;\nbreak;\n}\ndefault:{\npc=jumponcond(fs,e,1);\nbreak;\n}\n}\nluaK_concat(fs,&e->t,pc);\nluaK_patchtohere(fs,e->f);\ne->f=(-1);\n}\nstatic void codenot(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:case VFALSE:{\ne->k=VTRUE;\nbreak;\n}\ncase VK:case VKNUM:case VTRUE:{\ne->k=VFALSE;\nbreak;\n}\ncase VJMP:{\ninvertjump(fs,e);\nbreak;\n}\ncase VRELOCABLE:\ncase VNONRELOC:{\ndischarge2anyreg(fs,e);\nfreeexp(fs,e);\ne->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0);\ne->k=VRELOCABLE;\nbreak;\n}\ndefault:{\nbreak;\n}\n}\n{int temp=e->f;e->f=e->t;e->t=temp;}\nremovevalues(fs,e->f);\nremovevalues(fs,e->t);\n}\nstatic void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){\nt->u.s.aux=luaK_exp2RK(fs,k);\nt->k=VINDEXED;\n}\nstatic int constfolding(OpCode op,expdesc*e1,expdesc*e2){\nlua_Number v1,v2,r;\nif(!isnumeral(e1)||!isnumeral(e2))return 0;\nv1=e1->u.nval;\nv2=e2->u.nval;\nswitch(op){\ncase OP_ADD:r=luai_numadd(v1,v2);break;\ncase OP_SUB:r=luai_numsub(v1,v2);break;\ncase OP_MUL:r=luai_nummul(v1,v2);break;\ncase OP_DIV:\nif(v2==0)return 0;\nr=luai_numdiv(v1,v2);break;\ncase OP_MOD:\nif(v2==0)return 0;\nr=luai_nummod(v1,v2);break;\ncase OP_POW:r=luai_numpow(v1,v2);break;\ncase OP_UNM:r=luai_numunm(v1);break;\ncase OP_LEN:return 0;\ndefault:r=0;break;\n}\nif(luai_numisnan(r))return 0;\ne1->u.nval=r;\nreturn 1;\n}\nstatic void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){\nif(constfolding(op,e1,e2))\nreturn;\nelse{\nint o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0;\nint o1=luaK_exp2RK(fs,e1);\nif(o1>o2){\nfreeexp(fs,e1);\nfreeexp(fs,e2);\n}\nelse{\nfreeexp(fs,e2);\nfreeexp(fs,e1);\n}\ne1->u.s.info=luaK_codeABC(fs,op,0,o1,o2);\ne1->k=VRELOCABLE;\n}\n}\nstatic void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1,\nexpdesc*e2){\nint o1=luaK_exp2RK(fs,e1);\nint o2=luaK_exp2RK(fs,e2);\nfreeexp(fs,e2);\nfreeexp(fs,e1);\nif(cond==0&&op!=OP_EQ){\nint temp;\ntemp=o1;o1=o2;o2=temp;\ncond=1;\n}\ne1->u.s.info=condjump(fs,op,cond,o1,o2);\ne1->k=VJMP;\n}\nstatic void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){\nexpdesc e2;\ne2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0;\nswitch(op){\ncase OPR_MINUS:{\nif(!isnumeral(e))\nluaK_exp2anyreg(fs,e);\ncodearith(fs,OP_UNM,e,&e2);\nbreak;\n}\ncase OPR_NOT:codenot(fs,e);break;\ncase OPR_LEN:{\nluaK_exp2anyreg(fs,e);\ncodearith(fs,OP_LEN,e,&e2);\nbreak;\n}\ndefault:;\n}\n}\nstatic void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){\nswitch(op){\ncase OPR_AND:{\nluaK_goiftrue(fs,v);\nbreak;\n}\ncase OPR_OR:{\nluaK_goiffalse(fs,v);\nbreak;\n}\ncase OPR_CONCAT:{\nluaK_exp2nextreg(fs,v);\nbreak;\n}\ncase OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV:\ncase OPR_MOD:case OPR_POW:{\nif(!isnumeral(v))luaK_exp2RK(fs,v);\nbreak;\n}\ndefault:{\nluaK_exp2RK(fs,v);\nbreak;\n}\n}\n}\nstatic void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){\nswitch(op){\ncase OPR_AND:{\nluaK_dischargevars(fs,e2);\nluaK_concat(fs,&e2->f,e1->f);\n*e1=*e2;\nbreak;\n}\ncase OPR_OR:{\nluaK_dischargevars(fs,e2);\nluaK_concat(fs,&e2->t,e1->t);\n*e1=*e2;\nbreak;\n}\ncase OPR_CONCAT:{\nluaK_exp2val(fs,e2);\nif(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){\nfreeexp(fs,e1);\nSETARG_B(getcode(fs,e2),e1->u.s.info);\ne1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info;\n}\nelse{\nluaK_exp2nextreg(fs,e2);\ncodearith(fs,OP_CONCAT,e1,e2);\n}\nbreak;\n}\ncase OPR_ADD:codearith(fs,OP_ADD,e1,e2);break;\ncase OPR_SUB:codearith(fs,OP_SUB,e1,e2);break;\ncase OPR_MUL:codearith(fs,OP_MUL,e1,e2);break;\ncase OPR_DIV:codearith(fs,OP_DIV,e1,e2);break;\ncase OPR_MOD:codearith(fs,OP_MOD,e1,e2);break;\ncase OPR_POW:codearith(fs,OP_POW,e1,e2);break;\ncase OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break;\ncase OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break;\ncase OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break;\ncase OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break;\ncase OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break;\ncase OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break;\ndefault:;\n}\n}\nstatic void luaK_fixline(FuncState*fs,int line){\nfs->f->lineinfo[fs->pc-1]=line;\n}\nstatic int luaK_code(FuncState*fs,Instruction i,int line){\nProto*f=fs->f;\ndischargejpc(fs);\nluaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction,\n(INT_MAX-2),\"code size overflow\");\nf->code[fs->pc]=i;\nluaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int,\n(INT_MAX-2),\"code size overflow\");\nf->lineinfo[fs->pc]=line;\nreturn fs->pc++;\n}\nstatic int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){\nreturn luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline);\n}\nstatic int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){\nreturn luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline);\n}\nstatic void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){\nint c=(nelems-1)/50+1;\nint b=(tostore==(-1))?0:tostore;\nif(c<=((1<<9)-1))\nluaK_codeABC(fs,OP_SETLIST,base,b,c);\nelse{\nluaK_codeABC(fs,OP_SETLIST,base,b,0);\nluaK_code(fs,cast(Instruction,c),fs->ls->lastline);\n}\nfs->freereg=base+1;\n}\n#define hasmultret(k)((k)==VCALL||(k)==VVARARG)\n#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]])\n#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m)\ntypedef struct BlockCnt{\nstruct BlockCnt*previous;\nint breaklist;\nlu_byte nactvar;\nlu_byte upval;\nlu_byte isbreakable;\n}BlockCnt;\nstatic void chunk(LexState*ls);\nstatic void expr(LexState*ls,expdesc*v);\nstatic void anchor_token(LexState*ls){\nif(ls->t.token==TK_NAME||ls->t.token==TK_STRING){\nTString*ts=ls->t.seminfo.ts;\nluaX_newstring(ls,getstr(ts),ts->tsv.len);\n}\n}\nstatic void error_expected(LexState*ls,int token){\nluaX_syntaxerror(ls,\nluaO_pushfstring(ls->L,LUA_QL(\"%s\")\" expected\",luaX_token2str(ls,token)));\n}\nstatic void errorlimit(FuncState*fs,int limit,const char*what){\nconst char*msg=(fs->f->linedefined==0)?\nluaO_pushfstring(fs->L,\"main function has more than %d %s\",limit,what):\nluaO_pushfstring(fs->L,\"function at line %d has more than %d %s\",\nfs->f->linedefined,limit,what);\nluaX_lexerror(fs->ls,msg,0);\n}\nstatic int testnext(LexState*ls,int c){\nif(ls->t.token==c){\nluaX_next(ls);\nreturn 1;\n}\nelse return 0;\n}\nstatic void check(LexState*ls,int c){\nif(ls->t.token!=c)\nerror_expected(ls,c);\n}\nstatic void checknext(LexState*ls,int c){\ncheck(ls,c);\nluaX_next(ls);\n}\n#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);}\nstatic void check_match(LexState*ls,int what,int who,int where){\nif(!testnext(ls,what)){\nif(where==ls->linenumber)\nerror_expected(ls,what);\nelse{\nluaX_syntaxerror(ls,luaO_pushfstring(ls->L,\nLUA_QL(\"%s\")\" expected (to close \"LUA_QL(\"%s\")\" at line %d)\",\nluaX_token2str(ls,what),luaX_token2str(ls,who),where));\n}\n}\n}\nstatic TString*str_checkname(LexState*ls){\nTString*ts;\ncheck(ls,TK_NAME);\nts=ls->t.seminfo.ts;\nluaX_next(ls);\nreturn ts;\n}\nstatic void init_exp(expdesc*e,expkind k,int i){\ne->f=e->t=(-1);\ne->k=k;\ne->u.s.info=i;\n}\nstatic void codestring(LexState*ls,expdesc*e,TString*s){\ninit_exp(e,VK,luaK_stringK(ls->fs,s));\n}\nstatic void checkname(LexState*ls,expdesc*e){\ncodestring(ls,e,str_checkname(ls));\n}\nstatic int registerlocalvar(LexState*ls,TString*varname){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint oldsize=f->sizelocvars;\nluaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars,\nLocVar,SHRT_MAX,\"too many local variables\");\nwhile(oldsize<f->sizelocvars)f->locvars[oldsize++].varname=NULL;\nf->locvars[fs->nlocvars].varname=varname;\nluaC_objbarrier(ls->L,f,varname);\nreturn fs->nlocvars++;\n}\n#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,\"\"v,(sizeof(v)/sizeof(char))-1),n)\nstatic void new_localvar(LexState*ls,TString*name,int n){\nFuncState*fs=ls->fs;\nluaY_checklimit(fs,fs->nactvar+n+1,200,\"local variables\");\nfs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name));\n}\nstatic void adjustlocalvars(LexState*ls,int nvars){\nFuncState*fs=ls->fs;\nfs->nactvar=cast_byte(fs->nactvar+nvars);\nfor(;nvars;nvars--){\ngetlocvar(fs,fs->nactvar-nvars).startpc=fs->pc;\n}\n}\nstatic void removevars(LexState*ls,int tolevel){\nFuncState*fs=ls->fs;\nwhile(fs->nactvar>tolevel)\ngetlocvar(fs,--fs->nactvar).endpc=fs->pc;\n}\nstatic int indexupvalue(FuncState*fs,TString*name,expdesc*v){\nint i;\nProto*f=fs->f;\nint oldsize=f->sizeupvalues;\nfor(i=0;i<f->nups;i++){\nif(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){\nreturn i;\n}\n}\nluaY_checklimit(fs,f->nups+1,60,\"upvalues\");\nluaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues,\nTString*,(INT_MAX-2),\"\");\nwhile(oldsize<f->sizeupvalues)f->upvalues[oldsize++]=NULL;\nf->upvalues[f->nups]=name;\nluaC_objbarrier(fs->L,f,name);\nfs->upvalues[f->nups].k=cast_byte(v->k);\nfs->upvalues[f->nups].info=cast_byte(v->u.s.info);\nreturn f->nups++;\n}\nstatic int searchvar(FuncState*fs,TString*n){\nint i;\nfor(i=fs->nactvar-1;i>=0;i--){\nif(n==getlocvar(fs,i).varname)\nreturn i;\n}\nreturn-1;\n}\nstatic void markupval(FuncState*fs,int level){\nBlockCnt*bl=fs->bl;\nwhile(bl&&bl->nactvar>level)bl=bl->previous;\nif(bl)bl->upval=1;\n}\nstatic int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){\nif(fs==NULL){\ninit_exp(var,VGLOBAL,((1<<8)-1));\nreturn VGLOBAL;\n}\nelse{\nint v=searchvar(fs,n);\nif(v>=0){\ninit_exp(var,VLOCAL,v);\nif(!base)\nmarkupval(fs,v);\nreturn VLOCAL;\n}\nelse{\nif(singlevaraux(fs->prev,n,var,0)==VGLOBAL)\nreturn VGLOBAL;\nvar->u.s.info=indexupvalue(fs,n,var);\nvar->k=VUPVAL;\nreturn VUPVAL;\n}\n}\n}\nstatic void singlevar(LexState*ls,expdesc*var){\nTString*varname=str_checkname(ls);\nFuncState*fs=ls->fs;\nif(singlevaraux(fs,varname,var,1)==VGLOBAL)\nvar->u.s.info=luaK_stringK(fs,varname);\n}\nstatic void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){\nFuncState*fs=ls->fs;\nint extra=nvars-nexps;\nif(hasmultret(e->k)){\nextra++;\nif(extra<0)extra=0;\nluaK_setreturns(fs,e,extra);\nif(extra>1)luaK_reserveregs(fs,extra-1);\n}\nelse{\nif(e->k!=VVOID)luaK_exp2nextreg(fs,e);\nif(extra>0){\nint reg=fs->freereg;\nluaK_reserveregs(fs,extra);\nluaK_nil(fs,reg,extra);\n}\n}\n}\nstatic void enterlevel(LexState*ls){\nif(++ls->L->nCcalls>200)\nluaX_lexerror(ls,\"chunk has too many syntax levels\",0);\n}\n#define leavelevel(ls)((ls)->L->nCcalls--)\nstatic void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){\nbl->breaklist=(-1);\nbl->isbreakable=isbreakable;\nbl->nactvar=fs->nactvar;\nbl->upval=0;\nbl->previous=fs->bl;\nfs->bl=bl;\n}\nstatic void leaveblock(FuncState*fs){\nBlockCnt*bl=fs->bl;\nfs->bl=bl->previous;\nremovevars(fs->ls,bl->nactvar);\nif(bl->upval)\nluaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);\nfs->freereg=fs->nactvar;\nluaK_patchtohere(fs,bl->breaklist);\n}\nstatic void pushclosure(LexState*ls,FuncState*func,expdesc*v){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint oldsize=f->sizep;\nint i;\nluaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*,\n((1<<(9+9))-1),\"constant table overflow\");\nwhile(oldsize<f->sizep)f->p[oldsize++]=NULL;\nf->p[fs->np++]=func->f;\nluaC_objbarrier(ls->L,f,func->f);\ninit_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1));\nfor(i=0;i<func->f->nups;i++){\nOpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL;\nluaK_codeABC(fs,o,0,func->upvalues[i].info,0);\n}\n}\nstatic void open_func(LexState*ls,FuncState*fs){\nlua_State*L=ls->L;\nProto*f=luaF_newproto(L);\nfs->f=f;\nfs->prev=ls->fs;\nfs->ls=ls;\nfs->L=L;\nls->fs=fs;\nfs->pc=0;\nfs->lasttarget=-1;\nfs->jpc=(-1);\nfs->freereg=0;\nfs->nk=0;\nfs->np=0;\nfs->nlocvars=0;\nfs->nactvar=0;\nfs->bl=NULL;\nf->source=ls->source;\nf->maxstacksize=2;\nfs->h=luaH_new(L,0,0);\nsethvalue(L,L->top,fs->h);\nincr_top(L);\nsetptvalue(L,L->top,f);\nincr_top(L);\n}\nstatic void close_func(LexState*ls){\nlua_State*L=ls->L;\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nremovevars(ls,0);\nluaK_ret(fs,0,0);\nluaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction);\nf->sizecode=fs->pc;\nluaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int);\nf->sizelineinfo=fs->pc;\nluaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue);\nf->sizek=fs->nk;\nluaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*);\nf->sizep=fs->np;\nluaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar);\nf->sizelocvars=fs->nlocvars;\nluaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*);\nf->sizeupvalues=f->nups;\nls->fs=fs->prev;\nif(fs)anchor_token(ls);\nL->top-=2;\n}\nstatic Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){\nstruct LexState lexstate;\nstruct FuncState funcstate;\nlexstate.buff=buff;\nluaX_setinput(L,&lexstate,z,luaS_new(L,name));\nopen_func(&lexstate,&funcstate);\nfuncstate.f->is_vararg=2;\nluaX_next(&lexstate);\nchunk(&lexstate);\ncheck(&lexstate,TK_EOS);\nclose_func(&lexstate);\nreturn funcstate.f;\n}\nstatic void field(LexState*ls,expdesc*v){\nFuncState*fs=ls->fs;\nexpdesc key;\nluaK_exp2anyreg(fs,v);\nluaX_next(ls);\ncheckname(ls,&key);\nluaK_indexed(fs,v,&key);\n}\nstatic void yindex(LexState*ls,expdesc*v){\nluaX_next(ls);\nexpr(ls,v);\nluaK_exp2val(ls->fs,v);\nchecknext(ls,']');\n}\nstruct ConsControl{\nexpdesc v;\nexpdesc*t;\nint nh;\nint na;\nint tostore;\n};\nstatic void recfield(LexState*ls,struct ConsControl*cc){\nFuncState*fs=ls->fs;\nint reg=ls->fs->freereg;\nexpdesc key,val;\nint rkkey;\nif(ls->t.token==TK_NAME){\nluaY_checklimit(fs,cc->nh,(INT_MAX-2),\"items in a constructor\");\ncheckname(ls,&key);\n}\nelse\nyindex(ls,&key);\ncc->nh++;\nchecknext(ls,'=');\nrkkey=luaK_exp2RK(fs,&key);\nexpr(ls,&val);\nluaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val));\nfs->freereg=reg;\n}\nstatic void closelistfield(FuncState*fs,struct ConsControl*cc){\nif(cc->v.k==VVOID)return;\nluaK_exp2nextreg(fs,&cc->v);\ncc->v.k=VVOID;\nif(cc->tostore==50){\nluaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);\ncc->tostore=0;\n}\n}\nstatic void lastlistfield(FuncState*fs,struct ConsControl*cc){\nif(cc->tostore==0)return;\nif(hasmultret(cc->v.k)){\nluaK_setmultret(fs,&cc->v);\nluaK_setlist(fs,cc->t->u.s.info,cc->na,(-1));\ncc->na--;\n}\nelse{\nif(cc->v.k!=VVOID)\nluaK_exp2nextreg(fs,&cc->v);\nluaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);\n}\n}\nstatic void listfield(LexState*ls,struct ConsControl*cc){\nexpr(ls,&cc->v);\nluaY_checklimit(ls->fs,cc->na,(INT_MAX-2),\"items in a constructor\");\ncc->na++;\ncc->tostore++;\n}\nstatic void constructor(LexState*ls,expdesc*t){\nFuncState*fs=ls->fs;\nint line=ls->linenumber;\nint pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0);\nstruct ConsControl cc;\ncc.na=cc.nh=cc.tostore=0;\ncc.t=t;\ninit_exp(t,VRELOCABLE,pc);\ninit_exp(&cc.v,VVOID,0);\nluaK_exp2nextreg(ls->fs,t);\nchecknext(ls,'{');\ndo{\nif(ls->t.token=='}')break;\ncloselistfield(fs,&cc);\nswitch(ls->t.token){\ncase TK_NAME:{\nluaX_lookahead(ls);\nif(ls->lookahead.token!='=')\nlistfield(ls,&cc);\nelse\nrecfield(ls,&cc);\nbreak;\n}\ncase'[':{\nrecfield(ls,&cc);\nbreak;\n}\ndefault:{\nlistfield(ls,&cc);\nbreak;\n}\n}\n}while(testnext(ls,',')||testnext(ls,';'));\ncheck_match(ls,'}','{',line);\nlastlistfield(fs,&cc);\nSETARG_B(fs->f->code[pc],luaO_int2fb(cc.na));\nSETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh));\n}\nstatic void parlist(LexState*ls){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint nparams=0;\nf->is_vararg=0;\nif(ls->t.token!=')'){\ndo{\nswitch(ls->t.token){\ncase TK_NAME:{\nnew_localvar(ls,str_checkname(ls),nparams++);\nbreak;\n}\ncase TK_DOTS:{\nluaX_next(ls);\nf->is_vararg|=2;\nbreak;\n}\ndefault:luaX_syntaxerror(ls,\"<name> or \"LUA_QL(\"...\")\" expected\");\n}\n}while(!f->is_vararg&&testnext(ls,','));\n}\nadjustlocalvars(ls,nparams);\nf->numparams=cast_byte(fs->nactvar-(f->is_vararg&1));\nluaK_reserveregs(fs,fs->nactvar);\n}\nstatic void body(LexState*ls,expdesc*e,int needself,int line){\nFuncState new_fs;\nopen_func(ls,&new_fs);\nnew_fs.f->linedefined=line;\nchecknext(ls,'(');\nif(needself){\nnew_localvarliteral(ls,\"self\",0);\nadjustlocalvars(ls,1);\n}\nparlist(ls);\nchecknext(ls,')');\nchunk(ls);\nnew_fs.f->lastlinedefined=ls->linenumber;\ncheck_match(ls,TK_END,TK_FUNCTION,line);\nclose_func(ls);\npushclosure(ls,&new_fs,e);\n}\nstatic int explist1(LexState*ls,expdesc*v){\nint n=1;\nexpr(ls,v);\nwhile(testnext(ls,',')){\nluaK_exp2nextreg(ls->fs,v);\nexpr(ls,v);\nn++;\n}\nreturn n;\n}\nstatic void funcargs(LexState*ls,expdesc*f){\nFuncState*fs=ls->fs;\nexpdesc args;\nint base,nparams;\nint line=ls->linenumber;\nswitch(ls->t.token){\ncase'(':{\nif(line!=ls->lastline)\nluaX_syntaxerror(ls,\"ambiguous syntax (function call x new statement)\");\nluaX_next(ls);\nif(ls->t.token==')')\nargs.k=VVOID;\nelse{\nexplist1(ls,&args);\nluaK_setmultret(fs,&args);\n}\ncheck_match(ls,')','(',line);\nbreak;\n}\ncase'{':{\nconstructor(ls,&args);\nbreak;\n}\ncase TK_STRING:{\ncodestring(ls,&args,ls->t.seminfo.ts);\nluaX_next(ls);\nbreak;\n}\ndefault:{\nluaX_syntaxerror(ls,\"function arguments expected\");\nreturn;\n}\n}\nbase=f->u.s.info;\nif(hasmultret(args.k))\nnparams=(-1);\nelse{\nif(args.k!=VVOID)\nluaK_exp2nextreg(fs,&args);\nnparams=fs->freereg-(base+1);\n}\ninit_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2));\nluaK_fixline(fs,line);\nfs->freereg=base+1;\n}\nstatic void prefixexp(LexState*ls,expdesc*v){\nswitch(ls->t.token){\ncase'(':{\nint line=ls->linenumber;\nluaX_next(ls);\nexpr(ls,v);\ncheck_match(ls,')','(',line);\nluaK_dischargevars(ls->fs,v);\nreturn;\n}\ncase TK_NAME:{\nsinglevar(ls,v);\nreturn;\n}\ndefault:{\nluaX_syntaxerror(ls,\"unexpected symbol\");\nreturn;\n}\n}\n}\nstatic void primaryexp(LexState*ls,expdesc*v){\nFuncState*fs=ls->fs;\nprefixexp(ls,v);\nfor(;;){\nswitch(ls->t.token){\ncase'.':{\nfield(ls,v);\nbreak;\n}\ncase'[':{\nexpdesc key;\nluaK_exp2anyreg(fs,v);\nyindex(ls,&key);\nluaK_indexed(fs,v,&key);\nbreak;\n}\ncase':':{\nexpdesc key;\nluaX_next(ls);\ncheckname(ls,&key);\nluaK_self(fs,v,&key);\nfuncargs(ls,v);\nbreak;\n}\ncase'(':case TK_STRING:case'{':{\nluaK_exp2nextreg(fs,v);\nfuncargs(ls,v);\nbreak;\n}\ndefault:return;\n}\n}\n}\nstatic void simpleexp(LexState*ls,expdesc*v){\nswitch(ls->t.token){\ncase TK_NUMBER:{\ninit_exp(v,VKNUM,0);\nv->u.nval=ls->t.seminfo.r;\nbreak;\n}\ncase TK_STRING:{\ncodestring(ls,v,ls->t.seminfo.ts);\nbreak;\n}\ncase TK_NIL:{\ninit_exp(v,VNIL,0);\nbreak;\n}\ncase TK_TRUE:{\ninit_exp(v,VTRUE,0);\nbreak;\n}\ncase TK_FALSE:{\ninit_exp(v,VFALSE,0);\nbreak;\n}\ncase TK_DOTS:{\nFuncState*fs=ls->fs;\ncheck_condition(ls,fs->f->is_vararg,\n\"cannot use \"LUA_QL(\"...\")\" outside a vararg function\");\nfs->f->is_vararg&=~4;\ninit_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0));\nbreak;\n}\ncase'{':{\nconstructor(ls,v);\nreturn;\n}\ncase TK_FUNCTION:{\nluaX_next(ls);\nbody(ls,v,0,ls->linenumber);\nreturn;\n}\ndefault:{\nprimaryexp(ls,v);\nreturn;\n}\n}\nluaX_next(ls);\n}\nstatic UnOpr getunopr(int op){\nswitch(op){\ncase TK_NOT:return OPR_NOT;\ncase'-':return OPR_MINUS;\ncase'#':return OPR_LEN;\ndefault:return OPR_NOUNOPR;\n}\n}\nstatic BinOpr getbinopr(int op){\nswitch(op){\ncase'+':return OPR_ADD;\ncase'-':return OPR_SUB;\ncase'*':return OPR_MUL;\ncase'/':return OPR_DIV;\ncase'%':return OPR_MOD;\ncase'^':return OPR_POW;\ncase TK_CONCAT:return OPR_CONCAT;\ncase TK_NE:return OPR_NE;\ncase TK_EQ:return OPR_EQ;\ncase'<':return OPR_LT;\ncase TK_LE:return OPR_LE;\ncase'>':return OPR_GT;\ncase TK_GE:return OPR_GE;\ncase TK_AND:return OPR_AND;\ncase TK_OR:return OPR_OR;\ndefault:return OPR_NOBINOPR;\n}\n}\nstatic const struct{\nlu_byte left;\nlu_byte right;\n}priority[]={\n{6,6},{6,6},{7,7},{7,7},{7,7},\n{10,9},{5,4},\n{3,3},{3,3},\n{3,3},{3,3},{3,3},{3,3},\n{2,2},{1,1}\n};\nstatic BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){\nBinOpr op;\nUnOpr uop;\nenterlevel(ls);\nuop=getunopr(ls->t.token);\nif(uop!=OPR_NOUNOPR){\nluaX_next(ls);\nsubexpr(ls,v,8);\nluaK_prefix(ls->fs,uop,v);\n}\nelse simpleexp(ls,v);\nop=getbinopr(ls->t.token);\nwhile(op!=OPR_NOBINOPR&&priority[op].left>limit){\nexpdesc v2;\nBinOpr nextop;\nluaX_next(ls);\nluaK_infix(ls->fs,op,v);\nnextop=subexpr(ls,&v2,priority[op].right);\nluaK_posfix(ls->fs,op,v,&v2);\nop=nextop;\n}\nleavelevel(ls);\nreturn op;\n}\nstatic void expr(LexState*ls,expdesc*v){\nsubexpr(ls,v,0);\n}\nstatic int block_follow(int token){\nswitch(token){\ncase TK_ELSE:case TK_ELSEIF:case TK_END:\ncase TK_UNTIL:case TK_EOS:\nreturn 1;\ndefault:return 0;\n}\n}\nstatic void block(LexState*ls){\nFuncState*fs=ls->fs;\nBlockCnt bl;\nenterblock(fs,&bl,0);\nchunk(ls);\nleaveblock(fs);\n}\nstruct LHS_assign{\nstruct LHS_assign*prev;\nexpdesc v;\n};\nstatic void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){\nFuncState*fs=ls->fs;\nint extra=fs->freereg;\nint conflict=0;\nfor(;lh;lh=lh->prev){\nif(lh->v.k==VINDEXED){\nif(lh->v.u.s.info==v->u.s.info){\nconflict=1;\nlh->v.u.s.info=extra;\n}\nif(lh->v.u.s.aux==v->u.s.info){\nconflict=1;\nlh->v.u.s.aux=extra;\n}\n}\n}\nif(conflict){\nluaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0);\nluaK_reserveregs(fs,1);\n}\n}\nstatic void assignment(LexState*ls,struct LHS_assign*lh,int nvars){\nexpdesc e;\ncheck_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED,\n\"syntax error\");\nif(testnext(ls,',')){\nstruct LHS_assign nv;\nnv.prev=lh;\nprimaryexp(ls,&nv.v);\nif(nv.v.k==VLOCAL)\ncheck_conflict(ls,lh,&nv.v);\nluaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls,\n\"variables in assignment\");\nassignment(ls,&nv,nvars+1);\n}\nelse{\nint nexps;\nchecknext(ls,'=');\nnexps=explist1(ls,&e);\nif(nexps!=nvars){\nadjust_assign(ls,nvars,nexps,&e);\nif(nexps>nvars)\nls->fs->freereg-=nexps-nvars;\n}\nelse{\nluaK_setoneret(ls->fs,&e);\nluaK_storevar(ls->fs,&lh->v,&e);\nreturn;\n}\n}\ninit_exp(&e,VNONRELOC,ls->fs->freereg-1);\nluaK_storevar(ls->fs,&lh->v,&e);\n}\nstatic int cond(LexState*ls){\nexpdesc v;\nexpr(ls,&v);\nif(v.k==VNIL)v.k=VFALSE;\nluaK_goiftrue(ls->fs,&v);\nreturn v.f;\n}\nstatic void breakstat(LexState*ls){\nFuncState*fs=ls->fs;\nBlockCnt*bl=fs->bl;\nint upval=0;\nwhile(bl&&!bl->isbreakable){\nupval|=bl->upval;\nbl=bl->previous;\n}\nif(!bl)\nluaX_syntaxerror(ls,\"no loop to break\");\nif(upval)\nluaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);\nluaK_concat(fs,&bl->breaklist,luaK_jump(fs));\n}\nstatic void whilestat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nint whileinit;\nint condexit;\nBlockCnt bl;\nluaX_next(ls);\nwhileinit=luaK_getlabel(fs);\ncondexit=cond(ls);\nenterblock(fs,&bl,1);\nchecknext(ls,TK_DO);\nblock(ls);\nluaK_patchlist(fs,luaK_jump(fs),whileinit);\ncheck_match(ls,TK_END,TK_WHILE,line);\nleaveblock(fs);\nluaK_patchtohere(fs,condexit);\n}\nstatic void repeatstat(LexState*ls,int line){\nint condexit;\nFuncState*fs=ls->fs;\nint repeat_init=luaK_getlabel(fs);\nBlockCnt bl1,bl2;\nenterblock(fs,&bl1,1);\nenterblock(fs,&bl2,0);\nluaX_next(ls);\nchunk(ls);\ncheck_match(ls,TK_UNTIL,TK_REPEAT,line);\ncondexit=cond(ls);\nif(!bl2.upval){\nleaveblock(fs);\nluaK_patchlist(ls->fs,condexit,repeat_init);\n}\nelse{\nbreakstat(ls);\nluaK_patchtohere(ls->fs,condexit);\nleaveblock(fs);\nluaK_patchlist(ls->fs,luaK_jump(fs),repeat_init);\n}\nleaveblock(fs);\n}\nstatic int exp1(LexState*ls){\nexpdesc e;\nint k;\nexpr(ls,&e);\nk=e.k;\nluaK_exp2nextreg(ls->fs,&e);\nreturn k;\n}\nstatic void forbody(LexState*ls,int base,int line,int nvars,int isnum){\nBlockCnt bl;\nFuncState*fs=ls->fs;\nint prep,endfor;\nadjustlocalvars(ls,3);\nchecknext(ls,TK_DO);\nprep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs);\nenterblock(fs,&bl,0);\nadjustlocalvars(ls,nvars);\nluaK_reserveregs(fs,nvars);\nblock(ls);\nleaveblock(fs);\nluaK_patchtohere(fs,prep);\nendfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)):\nluaK_codeABC(fs,OP_TFORLOOP,base,0,nvars);\nluaK_fixline(fs,line);\nluaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1);\n}\nstatic void fornum(LexState*ls,TString*varname,int line){\nFuncState*fs=ls->fs;\nint base=fs->freereg;\nnew_localvarliteral(ls,\"(for index)\",0);\nnew_localvarliteral(ls,\"(for limit)\",1);\nnew_localvarliteral(ls,\"(for step)\",2);\nnew_localvar(ls,varname,3);\nchecknext(ls,'=');\nexp1(ls);\nchecknext(ls,',');\nexp1(ls);\nif(testnext(ls,','))\nexp1(ls);\nelse{\nluaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1));\nluaK_reserveregs(fs,1);\n}\nforbody(ls,base,line,1,1);\n}\nstatic void forlist(LexState*ls,TString*indexname){\nFuncState*fs=ls->fs;\nexpdesc e;\nint nvars=0;\nint line;\nint base=fs->freereg;\nnew_localvarliteral(ls,\"(for generator)\",nvars++);\nnew_localvarliteral(ls,\"(for state)\",nvars++);\nnew_localvarliteral(ls,\"(for control)\",nvars++);\nnew_localvar(ls,indexname,nvars++);\nwhile(testnext(ls,','))\nnew_localvar(ls,str_checkname(ls),nvars++);\nchecknext(ls,TK_IN);\nline=ls->linenumber;\nadjust_assign(ls,3,explist1(ls,&e),&e);\nluaK_checkstack(fs,3);\nforbody(ls,base,line,nvars-3,0);\n}\nstatic void forstat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nTString*varname;\nBlockCnt bl;\nenterblock(fs,&bl,1);\nluaX_next(ls);\nvarname=str_checkname(ls);\nswitch(ls->t.token){\ncase'=':fornum(ls,varname,line);break;\ncase',':case TK_IN:forlist(ls,varname);break;\ndefault:luaX_syntaxerror(ls,LUA_QL(\"=\")\" or \"LUA_QL(\"in\")\" expected\");\n}\ncheck_match(ls,TK_END,TK_FOR,line);\nleaveblock(fs);\n}\nstatic int test_then_block(LexState*ls){\nint condexit;\nluaX_next(ls);\ncondexit=cond(ls);\nchecknext(ls,TK_THEN);\nblock(ls);\nreturn condexit;\n}\nstatic void ifstat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nint flist;\nint escapelist=(-1);\nflist=test_then_block(ls);\nwhile(ls->t.token==TK_ELSEIF){\nluaK_concat(fs,&escapelist,luaK_jump(fs));\nluaK_patchtohere(fs,flist);\nflist=test_then_block(ls);\n}\nif(ls->t.token==TK_ELSE){\nluaK_concat(fs,&escapelist,luaK_jump(fs));\nluaK_patchtohere(fs,flist);\nluaX_next(ls);\nblock(ls);\n}\nelse\nluaK_concat(fs,&escapelist,flist);\nluaK_patchtohere(fs,escapelist);\ncheck_match(ls,TK_END,TK_IF,line);\n}\nstatic void localfunc(LexState*ls){\nexpdesc v,b;\nFuncState*fs=ls->fs;\nnew_localvar(ls,str_checkname(ls),0);\ninit_exp(&v,VLOCAL,fs->freereg);\nluaK_reserveregs(fs,1);\nadjustlocalvars(ls,1);\nbody(ls,&b,0,ls->linenumber);\nluaK_storevar(fs,&v,&b);\ngetlocvar(fs,fs->nactvar-1).startpc=fs->pc;\n}\nstatic void localstat(LexState*ls){\nint nvars=0;\nint nexps;\nexpdesc e;\ndo{\nnew_localvar(ls,str_checkname(ls),nvars++);\n}while(testnext(ls,','));\nif(testnext(ls,'='))\nnexps=explist1(ls,&e);\nelse{\ne.k=VVOID;\nnexps=0;\n}\nadjust_assign(ls,nvars,nexps,&e);\nadjustlocalvars(ls,nvars);\n}\nstatic int funcname(LexState*ls,expdesc*v){\nint needself=0;\nsinglevar(ls,v);\nwhile(ls->t.token=='.')\nfield(ls,v);\nif(ls->t.token==':'){\nneedself=1;\nfield(ls,v);\n}\nreturn needself;\n}\nstatic void funcstat(LexState*ls,int line){\nint needself;\nexpdesc v,b;\nluaX_next(ls);\nneedself=funcname(ls,&v);\nbody(ls,&b,needself,line);\nluaK_storevar(ls->fs,&v,&b);\nluaK_fixline(ls->fs,line);\n}\nstatic void exprstat(LexState*ls){\nFuncState*fs=ls->fs;\nstruct LHS_assign v;\nprimaryexp(ls,&v.v);\nif(v.v.k==VCALL)\nSETARG_C(getcode(fs,&v.v),1);\nelse{\nv.prev=NULL;\nassignment(ls,&v,1);\n}\n}\nstatic void retstat(LexState*ls){\nFuncState*fs=ls->fs;\nexpdesc e;\nint first,nret;\nluaX_next(ls);\nif(block_follow(ls->t.token)||ls->t.token==';')\nfirst=nret=0;\nelse{\nnret=explist1(ls,&e);\nif(hasmultret(e.k)){\nluaK_setmultret(fs,&e);\nif(e.k==VCALL&&nret==1){\nSET_OPCODE(getcode(fs,&e),OP_TAILCALL);\n}\nfirst=fs->nactvar;\nnret=(-1);\n}\nelse{\nif(nret==1)\nfirst=luaK_exp2anyreg(fs,&e);\nelse{\nluaK_exp2nextreg(fs,&e);\nfirst=fs->nactvar;\n}\n}\n}\nluaK_ret(fs,first,nret);\n}\nstatic int statement(LexState*ls){\nint line=ls->linenumber;\nswitch(ls->t.token){\ncase TK_IF:{\nifstat(ls,line);\nreturn 0;\n}\ncase TK_WHILE:{\nwhilestat(ls,line);\nreturn 0;\n}\ncase TK_DO:{\nluaX_next(ls);\nblock(ls);\ncheck_match(ls,TK_END,TK_DO,line);\nreturn 0;\n}\ncase TK_FOR:{\nforstat(ls,line);\nreturn 0;\n}\ncase TK_REPEAT:{\nrepeatstat(ls,line);\nreturn 0;\n}\ncase TK_FUNCTION:{\nfuncstat(ls,line);\nreturn 0;\n}\ncase TK_LOCAL:{\nluaX_next(ls);\nif(testnext(ls,TK_FUNCTION))\nlocalfunc(ls);\nelse\nlocalstat(ls);\nreturn 0;\n}\ncase TK_RETURN:{\nretstat(ls);\nreturn 1;\n}\ncase TK_BREAK:{\nluaX_next(ls);\nbreakstat(ls);\nreturn 1;\n}\ndefault:{\nexprstat(ls);\nreturn 0;\n}\n}\n}\nstatic void chunk(LexState*ls){\nint islast=0;\nenterlevel(ls);\nwhile(!islast&&!block_follow(ls->t.token)){\nislast=statement(ls);\ntestnext(ls,';');\nls->fs->freereg=ls->fs->nactvar;\n}\nleavelevel(ls);\n}\nstatic const TValue*luaV_tonumber(const TValue*obj,TValue*n){\nlua_Number num;\nif(ttisnumber(obj))return obj;\nif(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){\nsetnvalue(n,num);\nreturn n;\n}\nelse\nreturn NULL;\n}\nstatic int luaV_tostring(lua_State*L,StkId obj){\nif(!ttisnumber(obj))\nreturn 0;\nelse{\nchar s[32];\nlua_Number n=nvalue(obj);\nlua_number2str(s,n);\nsetsvalue(L,obj,luaS_new(L,s));\nreturn 1;\n}\n}\nstatic void callTMres(lua_State*L,StkId res,const TValue*f,\nconst TValue*p1,const TValue*p2){\nptrdiff_t result=savestack(L,res);\nsetobj(L,L->top,f);\nsetobj(L,L->top+1,p1);\nsetobj(L,L->top+2,p2);\nluaD_checkstack(L,3);\nL->top+=3;\nluaD_call(L,L->top-3,1);\nres=restorestack(L,result);\nL->top--;\nsetobj(L,res,L->top);\n}\nstatic void callTM(lua_State*L,const TValue*f,const TValue*p1,\nconst TValue*p2,const TValue*p3){\nsetobj(L,L->top,f);\nsetobj(L,L->top+1,p1);\nsetobj(L,L->top+2,p2);\nsetobj(L,L->top+3,p3);\nluaD_checkstack(L,4);\nL->top+=4;\nluaD_call(L,L->top-4,0);\n}\nstatic void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){\nint loop;\nfor(loop=0;loop<100;loop++){\nconst TValue*tm;\nif(ttistable(t)){\nTable*h=hvalue(t);\nconst TValue*res=luaH_get(h,key);\nif(!ttisnil(res)||\n(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){\nsetobj(L,val,res);\nreturn;\n}\n}\nelse if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX)))\nluaG_typeerror(L,t,\"index\");\nif(ttisfunction(tm)){\ncallTMres(L,val,tm,t,key);\nreturn;\n}\nt=tm;\n}\nluaG_runerror(L,\"loop in gettable\");\n}\nstatic void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){\nint loop;\nTValue temp;\nfor(loop=0;loop<100;loop++){\nconst TValue*tm;\nif(ttistable(t)){\nTable*h=hvalue(t);\nTValue*oldval=luaH_set(L,h,key);\nif(!ttisnil(oldval)||\n(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){\nsetobj(L,oldval,val);\nh->flags=0;\nluaC_barriert(L,h,val);\nreturn;\n}\n}\nelse if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX)))\nluaG_typeerror(L,t,\"index\");\nif(ttisfunction(tm)){\ncallTM(L,tm,t,key,val);\nreturn;\n}\nsetobj(L,&temp,tm);\nt=&temp;\n}\nluaG_runerror(L,\"loop in settable\");\n}\nstatic int call_binTM(lua_State*L,const TValue*p1,const TValue*p2,\nStkId res,TMS event){\nconst TValue*tm=luaT_gettmbyobj(L,p1,event);\nif(ttisnil(tm))\ntm=luaT_gettmbyobj(L,p2,event);\nif(ttisnil(tm))return 0;\ncallTMres(L,res,tm,p1,p2);\nreturn 1;\n}\nstatic const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2,\nTMS event){\nconst TValue*tm1=fasttm(L,mt1,event);\nconst TValue*tm2;\nif(tm1==NULL)return NULL;\nif(mt1==mt2)return tm1;\ntm2=fasttm(L,mt2,event);\nif(tm2==NULL)return NULL;\nif(luaO_rawequalObj(tm1,tm2))\nreturn tm1;\nreturn NULL;\n}\nstatic int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2,\nTMS event){\nconst TValue*tm1=luaT_gettmbyobj(L,p1,event);\nconst TValue*tm2;\nif(ttisnil(tm1))return-1;\ntm2=luaT_gettmbyobj(L,p2,event);\nif(!luaO_rawequalObj(tm1,tm2))\nreturn-1;\ncallTMres(L,L->top,tm1,p1,p2);\nreturn!l_isfalse(L->top);\n}\nstatic int l_strcmp(const TString*ls,const TString*rs){\nconst char*l=getstr(ls);\nsize_t ll=ls->tsv.len;\nconst char*r=getstr(rs);\nsize_t lr=rs->tsv.len;\nfor(;;){\nint temp=strcoll(l,r);\nif(temp!=0)return temp;\nelse{\nsize_t len=strlen(l);\nif(len==lr)\nreturn(len==ll)?0:1;\nelse if(len==ll)\nreturn-1;\nlen++;\nl+=len;ll-=len;r+=len;lr-=len;\n}\n}\n}\nstatic int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){\nint res;\nif(ttype(l)!=ttype(r))\nreturn luaG_ordererror(L,l,r);\nelse if(ttisnumber(l))\nreturn luai_numlt(nvalue(l),nvalue(r));\nelse if(ttisstring(l))\nreturn l_strcmp(rawtsvalue(l),rawtsvalue(r))<0;\nelse if((res=call_orderTM(L,l,r,TM_LT))!=-1)\nreturn res;\nreturn luaG_ordererror(L,l,r);\n}\nstatic int lessequal(lua_State*L,const TValue*l,const TValue*r){\nint res;\nif(ttype(l)!=ttype(r))\nreturn luaG_ordererror(L,l,r);\nelse if(ttisnumber(l))\nreturn luai_numle(nvalue(l),nvalue(r));\nelse if(ttisstring(l))\nreturn l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0;\nelse if((res=call_orderTM(L,l,r,TM_LE))!=-1)\nreturn res;\nelse if((res=call_orderTM(L,r,l,TM_LT))!=-1)\nreturn!res;\nreturn luaG_ordererror(L,l,r);\n}\nstatic int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){\nconst TValue*tm;\nswitch(ttype(t1)){\ncase 0:return 1;\ncase 3:return luai_numeq(nvalue(t1),nvalue(t2));\ncase 1:return bvalue(t1)==bvalue(t2);\ncase 2:return pvalue(t1)==pvalue(t2);\ncase 7:{\nif(uvalue(t1)==uvalue(t2))return 1;\ntm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable,\nTM_EQ);\nbreak;\n}\ncase 5:{\nif(hvalue(t1)==hvalue(t2))return 1;\ntm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ);\nbreak;\n}\ndefault:return gcvalue(t1)==gcvalue(t2);\n}\nif(tm==NULL)return 0;\ncallTMres(L,L->top,tm,t1,t2);\nreturn!l_isfalse(L->top);\n}\nstatic void luaV_concat(lua_State*L,int total,int last){\ndo{\nStkId top=L->base+last+1;\nint n=2;\nif(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){\nif(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT))\nluaG_concaterror(L,top-2,top-1);\n}else if(tsvalue(top-1)->len==0)\n(void)tostring(L,top-2);\nelse{\nsize_t tl=tsvalue(top-1)->len;\nchar*buffer;\nint i;\nfor(n=1;n<total&&tostring(L,top-n-1);n++){\nsize_t l=tsvalue(top-n-1)->len;\nif(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,\"string length overflow\");\ntl+=l;\n}\nbuffer=luaZ_openspace(L,&G(L)->buff,tl);\ntl=0;\nfor(i=n;i>0;i--){\nsize_t l=tsvalue(top-i)->len;\nmemcpy(buffer+tl,svalue(top-i),l);\ntl+=l;\n}\nsetsvalue(L,top-n,luaS_newlstr(L,buffer,tl));\n}\ntotal-=n-1;\nlast-=n-1;\n}while(total>1);\n}\nstatic void Arith(lua_State*L,StkId ra,const TValue*rb,\nconst TValue*rc,TMS op){\nTValue tempb,tempc;\nconst TValue*b,*c;\nif((b=luaV_tonumber(rb,&tempb))!=NULL&&\n(c=luaV_tonumber(rc,&tempc))!=NULL){\nlua_Number nb=nvalue(b),nc=nvalue(c);\nswitch(op){\ncase TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break;\ncase TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break;\ncase TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break;\ncase TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break;\ncase TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break;\ncase TM_POW:setnvalue(ra,luai_numpow(nb,nc));break;\ncase TM_UNM:setnvalue(ra,luai_numunm(nb));break;\ndefault:break;\n}\n}\nelse if(!call_binTM(L,rb,rc,ra,op))\nluaG_aritherror(L,rb,rc);\n}\n#define runtime_check(L,c){if(!(c))break;}\n#define RA(i)(base+GETARG_A(i))\n#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i))\n#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i))\n#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i))\n#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i))\n#define dojump(L,pc,i){(pc)+=(i);}\n#define Protect(x){L->savedpc=pc;{x;};base=L->base;}\n#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));}\nstatic void luaV_execute(lua_State*L,int nexeccalls){\nLClosure*cl;\nStkId base;\nTValue*k;\nconst Instruction*pc;\nreentry:\npc=L->savedpc;\ncl=&clvalue(L->ci->func)->l;\nbase=L->base;\nk=cl->p->k;\nfor(;;){\nconst Instruction i=*pc++;\nStkId ra;\nra=RA(i);\nswitch(GET_OPCODE(i)){\ncase OP_MOVE:{\nsetobj(L,ra,RB(i));\ncontinue;\n}\ncase OP_LOADK:{\nsetobj(L,ra,KBx(i));\ncontinue;\n}\ncase OP_LOADBOOL:{\nsetbvalue(ra,GETARG_B(i));\nif(GETARG_C(i))pc++;\ncontinue;\n}\ncase OP_LOADNIL:{\nTValue*rb=RB(i);\ndo{\nsetnilvalue(rb--);\n}while(rb>=ra);\ncontinue;\n}\ncase OP_GETUPVAL:{\nint b=GETARG_B(i);\nsetobj(L,ra,cl->upvals[b]->v);\ncontinue;\n}\ncase OP_GETGLOBAL:{\nTValue g;\nTValue*rb=KBx(i);\nsethvalue(L,&g,cl->env);\nProtect(luaV_gettable(L,&g,rb,ra));\ncontinue;\n}\ncase OP_GETTABLE:{\nProtect(luaV_gettable(L,RB(i),RKC(i),ra));\ncontinue;\n}\ncase OP_SETGLOBAL:{\nTValue g;\nsethvalue(L,&g,cl->env);\nProtect(luaV_settable(L,&g,KBx(i),ra));\ncontinue;\n}\ncase OP_SETUPVAL:{\nUpVal*uv=cl->upvals[GETARG_B(i)];\nsetobj(L,uv->v,ra);\nluaC_barrier(L,uv,ra);\ncontinue;\n}\ncase OP_SETTABLE:{\nProtect(luaV_settable(L,ra,RKB(i),RKC(i)));\ncontinue;\n}\ncase OP_NEWTABLE:{\nint b=GETARG_B(i);\nint c=GETARG_C(i);\nsethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c)));\nProtect(luaC_checkGC(L));\ncontinue;\n}\ncase OP_SELF:{\nStkId rb=RB(i);\nsetobj(L,ra+1,rb);\nProtect(luaV_gettable(L,rb,RKC(i),ra));\ncontinue;\n}\ncase OP_ADD:{\narith_op(luai_numadd,TM_ADD);\ncontinue;\n}\ncase OP_SUB:{\narith_op(luai_numsub,TM_SUB);\ncontinue;\n}\ncase OP_MUL:{\narith_op(luai_nummul,TM_MUL);\ncontinue;\n}\ncase OP_DIV:{\narith_op(luai_numdiv,TM_DIV);\ncontinue;\n}\ncase OP_MOD:{\narith_op(luai_nummod,TM_MOD);\ncontinue;\n}\ncase OP_POW:{\narith_op(luai_numpow,TM_POW);\ncontinue;\n}\ncase OP_UNM:{\nTValue*rb=RB(i);\nif(ttisnumber(rb)){\nlua_Number nb=nvalue(rb);\nsetnvalue(ra,luai_numunm(nb));\n}\nelse{\nProtect(Arith(L,ra,rb,rb,TM_UNM));\n}\ncontinue;\n}\ncase OP_NOT:{\nint res=l_isfalse(RB(i));\nsetbvalue(ra,res);\ncontinue;\n}\ncase OP_LEN:{\nconst TValue*rb=RB(i);\nswitch(ttype(rb)){\ncase 5:{\nsetnvalue(ra,cast_num(luaH_getn(hvalue(rb))));\nbreak;\n}\ncase 4:{\nsetnvalue(ra,cast_num(tsvalue(rb)->len));\nbreak;\n}\ndefault:{\nProtect(\nif(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN))\nluaG_typeerror(L,rb,\"get length of\");\n)\n}\n}\ncontinue;\n}\ncase OP_CONCAT:{\nint b=GETARG_B(i);\nint c=GETARG_C(i);\nProtect(luaV_concat(L,c-b+1,c);luaC_checkGC(L));\nsetobj(L,RA(i),base+b);\ncontinue;\n}\ncase OP_JMP:{\ndojump(L,pc,GETARG_sBx(i));\ncontinue;\n}\ncase OP_EQ:{\nTValue*rb=RKB(i);\nTValue*rc=RKC(i);\nProtect(\nif(equalobj(L,rb,rc)==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_LT:{\nProtect(\nif(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_LE:{\nProtect(\nif(lessequal(L,RKB(i),RKC(i))==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_TEST:{\nif(l_isfalse(ra)!=GETARG_C(i))\ndojump(L,pc,GETARG_sBx(*pc));\npc++;\ncontinue;\n}\ncase OP_TESTSET:{\nTValue*rb=RB(i);\nif(l_isfalse(rb)!=GETARG_C(i)){\nsetobj(L,ra,rb);\ndojump(L,pc,GETARG_sBx(*pc));\n}\npc++;\ncontinue;\n}\ncase OP_CALL:{\nint b=GETARG_B(i);\nint nresults=GETARG_C(i)-1;\nif(b!=0)L->top=ra+b;\nL->savedpc=pc;\nswitch(luaD_precall(L,ra,nresults)){\ncase 0:{\nnexeccalls++;\ngoto reentry;\n}\ncase 1:{\nif(nresults>=0)L->top=L->ci->top;\nbase=L->base;\ncontinue;\n}\ndefault:{\nreturn;\n}\n}\n}\ncase OP_TAILCALL:{\nint b=GETARG_B(i);\nif(b!=0)L->top=ra+b;\nL->savedpc=pc;\nswitch(luaD_precall(L,ra,(-1))){\ncase 0:{\nCallInfo*ci=L->ci-1;\nint aux;\nStkId func=ci->func;\nStkId pfunc=(ci+1)->func;\nif(L->openupval)luaF_close(L,ci->base);\nL->base=ci->base=ci->func+((ci+1)->base-pfunc);\nfor(aux=0;pfunc+aux<L->top;aux++)\nsetobj(L,func+aux,pfunc+aux);\nci->top=L->top=func+aux;\nci->savedpc=L->savedpc;\nci->tailcalls++;\nL->ci--;\ngoto reentry;\n}\ncase 1:{\nbase=L->base;\ncontinue;\n}\ndefault:{\nreturn;\n}\n}\n}\ncase OP_RETURN:{\nint b=GETARG_B(i);\nif(b!=0)L->top=ra+b-1;\nif(L->openupval)luaF_close(L,base);\nL->savedpc=pc;\nb=luaD_poscall(L,ra);\nif(--nexeccalls==0)\nreturn;\nelse{\nif(b)L->top=L->ci->top;\ngoto reentry;\n}\n}\ncase OP_FORLOOP:{\nlua_Number step=nvalue(ra+2);\nlua_Number idx=luai_numadd(nvalue(ra),step);\nlua_Number limit=nvalue(ra+1);\nif(luai_numlt(0,step)?luai_numle(idx,limit)\n:luai_numle(limit,idx)){\ndojump(L,pc,GETARG_sBx(i));\nsetnvalue(ra,idx);\nsetnvalue(ra+3,idx);\n}\ncontinue;\n}\ncase OP_FORPREP:{\nconst TValue*init=ra;\nconst TValue*plimit=ra+1;\nconst TValue*pstep=ra+2;\nL->savedpc=pc;\nif(!tonumber(init,ra))\nluaG_runerror(L,LUA_QL(\"for\")\" initial value must be a number\");\nelse if(!tonumber(plimit,ra+1))\nluaG_runerror(L,LUA_QL(\"for\")\" limit must be a number\");\nelse if(!tonumber(pstep,ra+2))\nluaG_runerror(L,LUA_QL(\"for\")\" step must be a number\");\nsetnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep)));\ndojump(L,pc,GETARG_sBx(i));\ncontinue;\n}\ncase OP_TFORLOOP:{\nStkId cb=ra+3;\nsetobj(L,cb+2,ra+2);\nsetobj(L,cb+1,ra+1);\nsetobj(L,cb,ra);\nL->top=cb+3;\nProtect(luaD_call(L,cb,GETARG_C(i)));\nL->top=L->ci->top;\ncb=RA(i)+3;\nif(!ttisnil(cb)){\nsetobj(L,cb-1,cb);\ndojump(L,pc,GETARG_sBx(*pc));\n}\npc++;\ncontinue;\n}\ncase OP_SETLIST:{\nint n=GETARG_B(i);\nint c=GETARG_C(i);\nint last;\nTable*h;\nif(n==0){\nn=cast_int(L->top-ra)-1;\nL->top=L->ci->top;\n}\nif(c==0)c=cast_int(*pc++);\nruntime_check(L,ttistable(ra));\nh=hvalue(ra);\nlast=((c-1)*50)+n;\nif(last>h->sizearray)\nluaH_resizearray(L,h,last);\nfor(;n>0;n--){\nTValue*val=ra+n;\nsetobj(L,luaH_setnum(L,h,last--),val);\nluaC_barriert(L,h,val);\n}\ncontinue;\n}\ncase OP_CLOSE:{\nluaF_close(L,ra);\ncontinue;\n}\ncase OP_CLOSURE:{\nProto*p;\nClosure*ncl;\nint nup,j;\np=cl->p->p[GETARG_Bx(i)];\nnup=p->nups;\nncl=luaF_newLclosure(L,nup,cl->env);\nncl->l.p=p;\nfor(j=0;j<nup;j++,pc++){\nif(GET_OPCODE(*pc)==OP_GETUPVAL)\nncl->l.upvals[j]=cl->upvals[GETARG_B(*pc)];\nelse{\nncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc));\n}\n}\nsetclvalue(L,ra,ncl);\nProtect(luaC_checkGC(L));\ncontinue;\n}\ncase OP_VARARG:{\nint b=GETARG_B(i)-1;\nint j;\nCallInfo*ci=L->ci;\nint n=cast_int(ci->base-ci->func)-cl->p->numparams-1;\nif(b==(-1)){\nProtect(luaD_checkstack(L,n));\nra=RA(i);\nb=n;\nL->top=ra+n;\n}\nfor(j=0;j<b;j++){\nif(j<n){\nsetobj(L,ra+j,ci->base-n+j);\n}\nelse{\nsetnilvalue(ra+j);\n}\n}\ncontinue;\n}\n}\n}\n}\n#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base))\n#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_))\n#define api_incr_top(L){luai_apicheck(L,L->top<L->ci->top);L->top++;}\nstatic TValue*index2adr(lua_State*L,int idx){\nif(idx>0){\nTValue*o=L->base+(idx-1);\nluai_apicheck(L,idx<=L->ci->top-L->base);\nif(o>=L->top)return cast(TValue*,(&luaO_nilobject_));\nelse return o;\n}\nelse if(idx>(-10000)){\nluai_apicheck(L,idx!=0&&-idx<=L->top-L->base);\nreturn L->top+idx;\n}\nelse switch(idx){\ncase(-10000):return registry(L);\ncase(-10001):{\nClosure*func=curr_func(L);\nsethvalue(L,&L->env,func->c.env);\nreturn&L->env;\n}\ncase(-10002):return gt(L);\ndefault:{\nClosure*func=curr_func(L);\nidx=(-10002)-idx;\nreturn(idx<=func->c.nupvalues)\n?&func->c.upvalue[idx-1]\n:cast(TValue*,(&luaO_nilobject_));\n}\n}\n}\nstatic Table*getcurrenv(lua_State*L){\nif(L->ci==L->base_ci)\nreturn hvalue(gt(L));\nelse{\nClosure*func=curr_func(L);\nreturn func->c.env;\n}\n}\nstatic int lua_checkstack(lua_State*L,int size){\nint res=1;\nif(size>8000||(L->top-L->base+size)>8000)\nres=0;\nelse if(size>0){\nluaD_checkstack(L,size);\nif(L->ci->top<L->top+size)\nL->ci->top=L->top+size;\n}\nreturn res;\n}\nstatic lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){\nlua_CFunction old;\nold=G(L)->panic;\nG(L)->panic=panicf;\nreturn old;\n}\nstatic int lua_gettop(lua_State*L){\nreturn cast_int(L->top-L->base);\n}\nstatic void lua_settop(lua_State*L,int idx){\nif(idx>=0){\nluai_apicheck(L,idx<=L->stack_last-L->base);\nwhile(L->top<L->base+idx)\nsetnilvalue(L->top++);\nL->top=L->base+idx;\n}\nelse{\nluai_apicheck(L,-(idx+1)<=(L->top-L->base));\nL->top+=idx+1;\n}\n}\nstatic void lua_remove(lua_State*L,int idx){\nStkId p;\np=index2adr(L,idx);\napi_checkvalidindex(L,p);\nwhile(++p<L->top)setobj(L,p-1,p);\nL->top--;\n}\nstatic void lua_insert(lua_State*L,int idx){\nStkId p;\nStkId q;\np=index2adr(L,idx);\napi_checkvalidindex(L,p);\nfor(q=L->top;q>p;q--)setobj(L,q,q-1);\nsetobj(L,p,L->top);\n}\nstatic void lua_replace(lua_State*L,int idx){\nStkId o;\nif(idx==(-10001)&&L->ci==L->base_ci)\nluaG_runerror(L,\"no calling environment\");\napi_checknelems(L,1);\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nif(idx==(-10001)){\nClosure*func=curr_func(L);\nluai_apicheck(L,ttistable(L->top-1));\nfunc->c.env=hvalue(L->top-1);\nluaC_barrier(L,func,L->top-1);\n}\nelse{\nsetobj(L,o,L->top-1);\nif(idx<(-10002))\nluaC_barrier(L,curr_func(L),L->top-1);\n}\nL->top--;\n}\nstatic void lua_pushvalue(lua_State*L,int idx){\nsetobj(L,L->top,index2adr(L,idx));\napi_incr_top(L);\n}\nstatic int lua_type(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn(o==(&luaO_nilobject_))?(-1):ttype(o);\n}\nstatic const char*lua_typename(lua_State*L,int t){\nUNUSED(L);\nreturn(t==(-1))?\"no value\":luaT_typenames[t];\n}\nstatic int lua_iscfunction(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn iscfunction(o);\n}\nstatic int lua_isnumber(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nreturn tonumber(o,&n);\n}\nstatic int lua_isstring(lua_State*L,int idx){\nint t=lua_type(L,idx);\nreturn(t==4||t==3);\n}\nstatic int lua_rawequal(lua_State*L,int index1,int index2){\nStkId o1=index2adr(L,index1);\nStkId o2=index2adr(L,index2);\nreturn(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0\n:luaO_rawequalObj(o1,o2);\n}\nstatic int lua_lessthan(lua_State*L,int index1,int index2){\nStkId o1,o2;\nint i;\no1=index2adr(L,index1);\no2=index2adr(L,index2);\ni=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0\n:luaV_lessthan(L,o1,o2);\nreturn i;\n}\nstatic lua_Number lua_tonumber(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nif(tonumber(o,&n))\nreturn nvalue(o);\nelse\nreturn 0;\n}\nstatic lua_Integer lua_tointeger(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nif(tonumber(o,&n)){\nlua_Integer res;\nlua_Number num=nvalue(o);\nlua_number2integer(res,num);\nreturn res;\n}\nelse\nreturn 0;\n}\nstatic int lua_toboolean(lua_State*L,int idx){\nconst TValue*o=index2adr(L,idx);\nreturn!l_isfalse(o);\n}\nstatic const char*lua_tolstring(lua_State*L,int idx,size_t*len){\nStkId o=index2adr(L,idx);\nif(!ttisstring(o)){\nif(!luaV_tostring(L,o)){\nif(len!=NULL)*len=0;\nreturn NULL;\n}\nluaC_checkGC(L);\no=index2adr(L,idx);\n}\nif(len!=NULL)*len=tsvalue(o)->len;\nreturn svalue(o);\n}\nstatic size_t lua_objlen(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nswitch(ttype(o)){\ncase 4:return tsvalue(o)->len;\ncase 7:return uvalue(o)->len;\ncase 5:return luaH_getn(hvalue(o));\ncase 3:{\nsize_t l;\nl=(luaV_tostring(L,o)?tsvalue(o)->len:0);\nreturn l;\n}\ndefault:return 0;\n}\n}\nstatic lua_CFunction lua_tocfunction(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn(!iscfunction(o))?NULL:clvalue(o)->c.f;\n}\nstatic void*lua_touserdata(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nswitch(ttype(o)){\ncase 7:return(rawuvalue(o)+1);\ncase 2:return pvalue(o);\ndefault:return NULL;\n}\n}\nstatic void lua_pushnil(lua_State*L){\nsetnilvalue(L->top);\napi_incr_top(L);\n}\nstatic void lua_pushnumber(lua_State*L,lua_Number n){\nsetnvalue(L->top,n);\napi_incr_top(L);\n}\nstatic void lua_pushinteger(lua_State*L,lua_Integer n){\nsetnvalue(L->top,cast_num(n));\napi_incr_top(L);\n}\nstatic void lua_pushlstring(lua_State*L,const char*s,size_t len){\nluaC_checkGC(L);\nsetsvalue(L,L->top,luaS_newlstr(L,s,len));\napi_incr_top(L);\n}\nstatic void lua_pushstring(lua_State*L,const char*s){\nif(s==NULL)\nlua_pushnil(L);\nelse\nlua_pushlstring(L,s,strlen(s));\n}\nstatic const char*lua_pushvfstring(lua_State*L,const char*fmt,\nva_list argp){\nconst char*ret;\nluaC_checkGC(L);\nret=luaO_pushvfstring(L,fmt,argp);\nreturn ret;\n}\nstatic const char*lua_pushfstring(lua_State*L,const char*fmt,...){\nconst char*ret;\nva_list argp;\nluaC_checkGC(L);\nva_start(argp,fmt);\nret=luaO_pushvfstring(L,fmt,argp);\nva_end(argp);\nreturn ret;\n}\nstatic void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){\nClosure*cl;\nluaC_checkGC(L);\napi_checknelems(L,n);\ncl=luaF_newCclosure(L,n,getcurrenv(L));\ncl->c.f=fn;\nL->top-=n;\nwhile(n--)\nsetobj(L,&cl->c.upvalue[n],L->top+n);\nsetclvalue(L,L->top,cl);\napi_incr_top(L);\n}\nstatic void lua_pushboolean(lua_State*L,int b){\nsetbvalue(L->top,(b!=0));\napi_incr_top(L);\n}\nstatic int lua_pushthread(lua_State*L){\nsetthvalue(L,L->top,L);\napi_incr_top(L);\nreturn(G(L)->mainthread==L);\n}\nstatic void lua_gettable(lua_State*L,int idx){\nStkId t;\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nluaV_gettable(L,t,L->top-1,L->top-1);\n}\nstatic void lua_getfield(lua_State*L,int idx,const char*k){\nStkId t;\nTValue key;\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nsetsvalue(L,&key,luaS_new(L,k));\nluaV_gettable(L,t,&key,L->top);\napi_incr_top(L);\n}\nstatic void lua_rawget(lua_State*L,int idx){\nStkId t;\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nsetobj(L,L->top-1,luaH_get(hvalue(t),L->top-1));\n}\nstatic void lua_rawgeti(lua_State*L,int idx,int n){\nStkId o;\no=index2adr(L,idx);\nluai_apicheck(L,ttistable(o));\nsetobj(L,L->top,luaH_getnum(hvalue(o),n));\napi_incr_top(L);\n}\nstatic void lua_createtable(lua_State*L,int narray,int nrec){\nluaC_checkGC(L);\nsethvalue(L,L->top,luaH_new(L,narray,nrec));\napi_incr_top(L);\n}\nstatic int lua_getmetatable(lua_State*L,int objindex){\nconst TValue*obj;\nTable*mt=NULL;\nint res;\nobj=index2adr(L,objindex);\nswitch(ttype(obj)){\ncase 5:\nmt=hvalue(obj)->metatable;\nbreak;\ncase 7:\nmt=uvalue(obj)->metatable;\nbreak;\ndefault:\nmt=G(L)->mt[ttype(obj)];\nbreak;\n}\nif(mt==NULL)\nres=0;\nelse{\nsethvalue(L,L->top,mt);\napi_incr_top(L);\nres=1;\n}\nreturn res;\n}\nstatic void lua_getfenv(lua_State*L,int idx){\nStkId o;\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nswitch(ttype(o)){\ncase 6:\nsethvalue(L,L->top,clvalue(o)->c.env);\nbreak;\ncase 7:\nsethvalue(L,L->top,uvalue(o)->env);\nbreak;\ncase 8:\nsetobj(L,L->top,gt(thvalue(o)));\nbreak;\ndefault:\nsetnilvalue(L->top);\nbreak;\n}\napi_incr_top(L);\n}\nstatic void lua_settable(lua_State*L,int idx){\nStkId t;\napi_checknelems(L,2);\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nluaV_settable(L,t,L->top-2,L->top-1);\nL->top-=2;\n}\nstatic void lua_setfield(lua_State*L,int idx,const char*k){\nStkId t;\nTValue key;\napi_checknelems(L,1);\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nsetsvalue(L,&key,luaS_new(L,k));\nluaV_settable(L,t,&key,L->top-1);\nL->top--;\n}\nstatic void lua_rawset(lua_State*L,int idx){\nStkId t;\napi_checknelems(L,2);\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nsetobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1);\nluaC_barriert(L,hvalue(t),L->top-1);\nL->top-=2;\n}\nstatic void lua_rawseti(lua_State*L,int idx,int n){\nStkId o;\napi_checknelems(L,1);\no=index2adr(L,idx);\nluai_apicheck(L,ttistable(o));\nsetobj(L,luaH_setnum(L,hvalue(o),n),L->top-1);\nluaC_barriert(L,hvalue(o),L->top-1);\nL->top--;\n}\nstatic int lua_setmetatable(lua_State*L,int objindex){\nTValue*obj;\nTable*mt;\napi_checknelems(L,1);\nobj=index2adr(L,objindex);\napi_checkvalidindex(L,obj);\nif(ttisnil(L->top-1))\nmt=NULL;\nelse{\nluai_apicheck(L,ttistable(L->top-1));\nmt=hvalue(L->top-1);\n}\nswitch(ttype(obj)){\ncase 5:{\nhvalue(obj)->metatable=mt;\nif(mt)\nluaC_objbarriert(L,hvalue(obj),mt);\nbreak;\n}\ncase 7:{\nuvalue(obj)->metatable=mt;\nif(mt)\nluaC_objbarrier(L,rawuvalue(obj),mt);\nbreak;\n}\ndefault:{\nG(L)->mt[ttype(obj)]=mt;\nbreak;\n}\n}\nL->top--;\nreturn 1;\n}\nstatic int lua_setfenv(lua_State*L,int idx){\nStkId o;\nint res=1;\napi_checknelems(L,1);\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nluai_apicheck(L,ttistable(L->top-1));\nswitch(ttype(o)){\ncase 6:\nclvalue(o)->c.env=hvalue(L->top-1);\nbreak;\ncase 7:\nuvalue(o)->env=hvalue(L->top-1);\nbreak;\ncase 8:\nsethvalue(L,gt(thvalue(o)),hvalue(L->top-1));\nbreak;\ndefault:\nres=0;\nbreak;\n}\nif(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1));\nL->top--;\nreturn res;\n}\n#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;}\n#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na)))\nstatic void lua_call(lua_State*L,int nargs,int nresults){\nStkId func;\napi_checknelems(L,nargs+1);\ncheckresults(L,nargs,nresults);\nfunc=L->top-(nargs+1);\nluaD_call(L,func,nresults);\nadjustresults(L,nresults);\n}\nstruct CallS{\nStkId func;\nint nresults;\n};\nstatic void f_call(lua_State*L,void*ud){\nstruct CallS*c=cast(struct CallS*,ud);\nluaD_call(L,c->func,c->nresults);\n}\nstatic int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){\nstruct CallS c;\nint status;\nptrdiff_t func;\napi_checknelems(L,nargs+1);\ncheckresults(L,nargs,nresults);\nif(errfunc==0)\nfunc=0;\nelse{\nStkId o=index2adr(L,errfunc);\napi_checkvalidindex(L,o);\nfunc=savestack(L,o);\n}\nc.func=L->top-(nargs+1);\nc.nresults=nresults;\nstatus=luaD_pcall(L,f_call,&c,savestack(L,c.func),func);\nadjustresults(L,nresults);\nreturn status;\n}\nstatic int lua_load(lua_State*L,lua_Reader reader,void*data,\nconst char*chunkname){\nZIO z;\nint status;\nif(!chunkname)chunkname=\"?\";\nluaZ_init(L,&z,reader,data);\nstatus=luaD_protectedparser(L,&z,chunkname);\nreturn status;\n}\nstatic int lua_error(lua_State*L){\napi_checknelems(L,1);\nluaG_errormsg(L);\nreturn 0;\n}\nstatic int lua_next(lua_State*L,int idx){\nStkId t;\nint more;\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nmore=luaH_next(L,hvalue(t),L->top-1);\nif(more){\napi_incr_top(L);\n}\nelse\nL->top-=1;\nreturn more;\n}\nstatic void lua_concat(lua_State*L,int n){\napi_checknelems(L,n);\nif(n>=2){\nluaC_checkGC(L);\nluaV_concat(L,n,cast_int(L->top-L->base)-1);\nL->top-=(n-1);\n}\nelse if(n==0){\nsetsvalue(L,L->top,luaS_newlstr(L,\"\",0));\napi_incr_top(L);\n}\n}\nstatic void*lua_newuserdata(lua_State*L,size_t size){\nUdata*u;\nluaC_checkGC(L);\nu=luaS_newudata(L,size,getcurrenv(L));\nsetuvalue(L,L->top,u);\napi_incr_top(L);\nreturn u+1;\n}\n#define luaL_getn(L,i)((int)lua_objlen(L,i))\n#define luaL_setn(L,i,j)((void)0)\ntypedef struct luaL_Reg{\nconst char*name;\nlua_CFunction func;\n}luaL_Reg;\nstatic void luaI_openlib(lua_State*L,const char*libname,\nconst luaL_Reg*l,int nup);\nstatic int luaL_argerror(lua_State*L,int numarg,const char*extramsg);\nstatic const char* luaL_checklstring(lua_State*L,int numArg,\nsize_t*l);\nstatic const char* luaL_optlstring(lua_State*L,int numArg,\nconst char*def,size_t*l);\nstatic lua_Integer luaL_checkinteger(lua_State*L,int numArg);\nstatic lua_Integer luaL_optinteger(lua_State*L,int nArg,\nlua_Integer def);\nstatic int luaL_error(lua_State*L,const char*fmt,...);\nstatic const char* luaL_findtable(lua_State*L,int idx,\nconst char*fname,int szhint);\n#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg))))\n#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL))\n#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL))\n#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n)))\n#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d)))\n#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i)))\n#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n)))\n#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n)))\ntypedef struct luaL_Buffer{\nchar*p;\nint lvl;\nlua_State*L;\nchar buffer[BUFSIZ];\n}luaL_Buffer;\n#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c)))\n#define luaL_addsize(B,n)((B)->p+=(n))\nstatic char* luaL_prepbuffer(luaL_Buffer*B);\nstatic int luaL_argerror(lua_State*L,int narg,const char*extramsg){\nlua_Debug ar;\nif(!lua_getstack(L,0,&ar))\nreturn luaL_error(L,\"bad argument #%d (%s)\",narg,extramsg);\nlua_getinfo(L,\"n\",&ar);\nif(strcmp(ar.namewhat,\"method\")==0){\nnarg--;\nif(narg==0)\nreturn luaL_error(L,\"calling \"LUA_QL(\"%s\")\" on bad self (%s)\",\nar.name,extramsg);\n}\nif(ar.name==NULL)\nar.name=\"?\";\nreturn luaL_error(L,\"bad argument #%d to \"LUA_QL(\"%s\")\" (%s)\",\nnarg,ar.name,extramsg);\n}\nstatic int luaL_typerror(lua_State*L,int narg,const char*tname){\nconst char*msg=lua_pushfstring(L,\"%s expected, got %s\",\ntname,luaL_typename(L,narg));\nreturn luaL_argerror(L,narg,msg);\n}\nstatic void tag_error(lua_State*L,int narg,int tag){\nluaL_typerror(L,narg,lua_typename(L,tag));\n}\nstatic void luaL_where(lua_State*L,int level){\nlua_Debug ar;\nif(lua_getstack(L,level,&ar)){\nlua_getinfo(L,\"Sl\",&ar);\nif(ar.currentline>0){\nlua_pushfstring(L,\"%s:%d: \",ar.short_src,ar.currentline);\nreturn;\n}\n}\nlua_pushliteral(L,\"\");\n}\nstatic int luaL_error(lua_State*L,const char*fmt,...){\nva_list argp;\nva_start(argp,fmt);\nluaL_where(L,1);\nlua_pushvfstring(L,fmt,argp);\nva_end(argp);\nlua_concat(L,2);\nreturn lua_error(L);\n}\nstatic int luaL_newmetatable(lua_State*L,const char*tname){\nlua_getfield(L,(-10000),tname);\nif(!lua_isnil(L,-1))\nreturn 0;\nlua_pop(L,1);\nlua_newtable(L);\nlua_pushvalue(L,-1);\nlua_setfield(L,(-10000),tname);\nreturn 1;\n}\nstatic void*luaL_checkudata(lua_State*L,int ud,const char*tname){\nvoid*p=lua_touserdata(L,ud);\nif(p!=NULL){\nif(lua_getmetatable(L,ud)){\nlua_getfield(L,(-10000),tname);\nif(lua_rawequal(L,-1,-2)){\nlua_pop(L,2);\nreturn p;\n}\n}\n}\nluaL_typerror(L,ud,tname);\nreturn NULL;\n}\nstatic void luaL_checkstack(lua_State*L,int space,const char*mes){\nif(!lua_checkstack(L,space))\nluaL_error(L,\"stack overflow (%s)\",mes);\n}\nstatic void luaL_checktype(lua_State*L,int narg,int t){\nif(lua_type(L,narg)!=t)\ntag_error(L,narg,t);\n}\nstatic void luaL_checkany(lua_State*L,int narg){\nif(lua_type(L,narg)==(-1))\nluaL_argerror(L,narg,\"value expected\");\n}\nstatic const char*luaL_checklstring(lua_State*L,int narg,size_t*len){\nconst char*s=lua_tolstring(L,narg,len);\nif(!s)tag_error(L,narg,4);\nreturn s;\n}\nstatic const char*luaL_optlstring(lua_State*L,int narg,\nconst char*def,size_t*len){\nif(lua_isnoneornil(L,narg)){\nif(len)\n*len=(def?strlen(def):0);\nreturn def;\n}\nelse return luaL_checklstring(L,narg,len);\n}\nstatic lua_Number luaL_checknumber(lua_State*L,int narg){\nlua_Number d=lua_tonumber(L,narg);\nif(d==0&&!lua_isnumber(L,narg))\ntag_error(L,narg,3);\nreturn d;\n}\nstatic lua_Integer luaL_checkinteger(lua_State*L,int narg){\nlua_Integer d=lua_tointeger(L,narg);\nif(d==0&&!lua_isnumber(L,narg))\ntag_error(L,narg,3);\nreturn d;\n}\nstatic lua_Integer luaL_optinteger(lua_State*L,int narg,\nlua_Integer def){\nreturn luaL_opt(L,luaL_checkinteger,narg,def);\n}\nstatic int luaL_getmetafield(lua_State*L,int obj,const char*event){\nif(!lua_getmetatable(L,obj))\nreturn 0;\nlua_pushstring(L,event);\nlua_rawget(L,-2);\nif(lua_isnil(L,-1)){\nlua_pop(L,2);\nreturn 0;\n}\nelse{\nlua_remove(L,-2);\nreturn 1;\n}\n}\nstatic void luaL_register(lua_State*L,const char*libname,\nconst luaL_Reg*l){\nluaI_openlib(L,libname,l,0);\n}\nstatic int libsize(const luaL_Reg*l){\nint size=0;\nfor(;l->name;l++)size++;\nreturn size;\n}\nstatic void luaI_openlib(lua_State*L,const char*libname,\nconst luaL_Reg*l,int nup){\nif(libname){\nint size=libsize(l);\nluaL_findtable(L,(-10000),\"_LOADED\",1);\nlua_getfield(L,-1,libname);\nif(!lua_istable(L,-1)){\nlua_pop(L,1);\nif(luaL_findtable(L,(-10002),libname,size)!=NULL)\nluaL_error(L,\"name conflict for module \"LUA_QL(\"%s\"),libname);\nlua_pushvalue(L,-1);\nlua_setfield(L,-3,libname);\n}\nlua_remove(L,-2);\nlua_insert(L,-(nup+1));\n}\nfor(;l->name;l++){\nint i;\nfor(i=0;i<nup;i++)\nlua_pushvalue(L,-nup);\nlua_pushcclosure(L,l->func,nup);\nlua_setfield(L,-(nup+2),l->name);\n}\nlua_pop(L,nup);\n}\nstatic const char*luaL_findtable(lua_State*L,int idx,\nconst char*fname,int szhint){\nconst char*e;\nlua_pushvalue(L,idx);\ndo{\ne=strchr(fname,'.');\nif(e==NULL)e=fname+strlen(fname);\nlua_pushlstring(L,fname,e-fname);\nlua_rawget(L,-2);\nif(lua_isnil(L,-1)){\nlua_pop(L,1);\nlua_createtable(L,0,(*e=='.'?1:szhint));\nlua_pushlstring(L,fname,e-fname);\nlua_pushvalue(L,-2);\nlua_settable(L,-4);\n}\nelse if(!lua_istable(L,-1)){\nlua_pop(L,2);\nreturn fname;\n}\nlua_remove(L,-2);\nfname=e+1;\n}while(*e=='.');\nreturn NULL;\n}\n#define bufflen(B)((B)->p-(B)->buffer)\n#define bufffree(B)((size_t)(BUFSIZ-bufflen(B)))\nstatic int emptybuffer(luaL_Buffer*B){\nsize_t l=bufflen(B);\nif(l==0)return 0;\nelse{\nlua_pushlstring(B->L,B->buffer,l);\nB->p=B->buffer;\nB->lvl++;\nreturn 1;\n}\n}\nstatic void adjuststack(luaL_Buffer*B){\nif(B->lvl>1){\nlua_State*L=B->L;\nint toget=1;\nsize_t toplen=lua_strlen(L,-1);\ndo{\nsize_t l=lua_strlen(L,-(toget+1));\nif(B->lvl-toget+1>=(20/2)||toplen>l){\ntoplen+=l;\ntoget++;\n}\nelse break;\n}while(toget<B->lvl);\nlua_concat(L,toget);\nB->lvl=B->lvl-toget+1;\n}\n}\nstatic char*luaL_prepbuffer(luaL_Buffer*B){\nif(emptybuffer(B))\nadjuststack(B);\nreturn B->buffer;\n}\nstatic void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){\nwhile(l--)\nluaL_addchar(B,*s++);\n}\nstatic void luaL_pushresult(luaL_Buffer*B){\nemptybuffer(B);\nlua_concat(B->L,B->lvl);\nB->lvl=1;\n}\nstatic void luaL_addvalue(luaL_Buffer*B){\nlua_State*L=B->L;\nsize_t vl;\nconst char*s=lua_tolstring(L,-1,&vl);\nif(vl<=bufffree(B)){\nmemcpy(B->p,s,vl);\nB->p+=vl;\nlua_pop(L,1);\n}\nelse{\nif(emptybuffer(B))\nlua_insert(L,-2);\nB->lvl++;\nadjuststack(B);\n}\n}\nstatic void luaL_buffinit(lua_State*L,luaL_Buffer*B){\nB->L=L;\nB->p=B->buffer;\nB->lvl=0;\n}\ntypedef struct LoadF{\nint extraline;\nFILE*f;\nchar buff[BUFSIZ];\n}LoadF;\nstatic const char*getF(lua_State*L,void*ud,size_t*size){\nLoadF*lf=(LoadF*)ud;\n(void)L;\nif(lf->extraline){\nlf->extraline=0;\n*size=1;\nreturn\"\\n\";\n}\nif(feof(lf->f))return NULL;\n*size=fread(lf->buff,1,sizeof(lf->buff),lf->f);\nreturn(*size>0)?lf->buff:NULL;\n}\nstatic int errfile(lua_State*L,const char*what,int fnameindex){\nconst char*serr=strerror(errno);\nconst char*filename=lua_tostring(L,fnameindex)+1;\nlua_pushfstring(L,\"cannot %s %s: %s\",what,filename,serr);\nlua_remove(L,fnameindex);\nreturn(5+1);\n}\nstatic int luaL_loadfile(lua_State*L,const char*filename){\nLoadF lf;\nint status,readstatus;\nint c;\nint fnameindex=lua_gettop(L)+1;\nlf.extraline=0;\nif(filename==NULL){\nlua_pushliteral(L,\"=stdin\");\nlf.f=stdin;\n}\nelse{\nlua_pushfstring(L,\"@%s\",filename);\nlf.f=fopen(filename,\"r\");\nif(lf.f==NULL)return errfile(L,\"open\",fnameindex);\n}\nc=getc(lf.f);\nif(c=='#'){\nlf.extraline=1;\nwhile((c=getc(lf.f))!=EOF&&c!='\\n');\nif(c=='\\n')c=getc(lf.f);\n}\nif(c==\"\\033Lua\"[0]&&filename){\nlf.f=freopen(filename,\"rb\",lf.f);\nif(lf.f==NULL)return errfile(L,\"reopen\",fnameindex);\nwhile((c=getc(lf.f))!=EOF&&c!=\"\\033Lua\"[0]);\nlf.extraline=0;\n}\nungetc(c,lf.f);\nstatus=lua_load(L,getF,&lf,lua_tostring(L,-1));\nreadstatus=ferror(lf.f);\nif(filename)fclose(lf.f);\nif(readstatus){\nlua_settop(L,fnameindex);\nreturn errfile(L,\"read\",fnameindex);\n}\nlua_remove(L,fnameindex);\nreturn status;\n}\ntypedef struct LoadS{\nconst char*s;\nsize_t size;\n}LoadS;\nstatic const char*getS(lua_State*L,void*ud,size_t*size){\nLoadS*ls=(LoadS*)ud;\n(void)L;\nif(ls->size==0)return NULL;\n*size=ls->size;\nls->size=0;\nreturn ls->s;\n}\nstatic int luaL_loadbuffer(lua_State*L,const char*buff,size_t size,\nconst char*name){\nLoadS ls;\nls.s=buff;\nls.size=size;\nreturn lua_load(L,getS,&ls,name);\n}\nstatic void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){\n(void)ud;\n(void)osize;\nif(nsize==0){\nfree(ptr);\nreturn NULL;\n}\nelse\nreturn realloc(ptr,nsize);\n}\nstatic int panic(lua_State*L){\n(void)L;\nfprintf(stderr,\"PANIC: unprotected error in call to Lua API (%s)\\n\",\nlua_tostring(L,-1));\nreturn 0;\n}\nstatic lua_State*luaL_newstate(void){\nlua_State*L=lua_newstate(l_alloc,NULL);\nif(L)lua_atpanic(L,&panic);\nreturn L;\n}\nstatic int luaB_tonumber(lua_State*L){\nint base=luaL_optint(L,2,10);\nif(base==10){\nluaL_checkany(L,1);\nif(lua_isnumber(L,1)){\nlua_pushnumber(L,lua_tonumber(L,1));\nreturn 1;\n}\n}\nelse{\nconst char*s1=luaL_checkstring(L,1);\nchar*s2;\nunsigned long n;\nluaL_argcheck(L,2<=base&&base<=36,2,\"base out of range\");\nn=strtoul(s1,&s2,base);\nif(s1!=s2){\nwhile(isspace((unsigned char)(*s2)))s2++;\nif(*s2=='\\0'){\nlua_pushnumber(L,(lua_Number)n);\nreturn 1;\n}\n}\n}\nlua_pushnil(L);\nreturn 1;\n}\nstatic int luaB_error(lua_State*L){\nint level=luaL_optint(L,2,1);\nlua_settop(L,1);\nif(lua_isstring(L,1)&&level>0){\nluaL_where(L,level);\nlua_pushvalue(L,1);\nlua_concat(L,2);\n}\nreturn lua_error(L);\n}\nstatic int luaB_setmetatable(lua_State*L){\nint t=lua_type(L,2);\nluaL_checktype(L,1,5);\nluaL_argcheck(L,t==0||t==5,2,\n\"nil or table expected\");\nif(luaL_getmetafield(L,1,\"__metatable\"))\nluaL_error(L,\"cannot change a protected metatable\");\nlua_settop(L,2);\nlua_setmetatable(L,1);\nreturn 1;\n}\nstatic void getfunc(lua_State*L,int opt){\nif(lua_isfunction(L,1))lua_pushvalue(L,1);\nelse{\nlua_Debug ar;\nint level=opt?luaL_optint(L,1,1):luaL_checkint(L,1);\nluaL_argcheck(L,level>=0,1,\"level must be non-negative\");\nif(lua_getstack(L,level,&ar)==0)\nluaL_argerror(L,1,\"invalid level\");\nlua_getinfo(L,\"f\",&ar);\nif(lua_isnil(L,-1))\nluaL_error(L,\"no function environment for tail call at level %d\",\nlevel);\n}\n}\nstatic int luaB_setfenv(lua_State*L){\nluaL_checktype(L,2,5);\ngetfunc(L,0);\nlua_pushvalue(L,2);\nif(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){\nlua_pushthread(L);\nlua_insert(L,-2);\nlua_setfenv(L,-2);\nreturn 0;\n}\nelse if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0)\nluaL_error(L,\nLUA_QL(\"setfenv\")\" cannot change environment of given object\");\nreturn 1;\n}\nstatic int luaB_rawget(lua_State*L){\nluaL_checktype(L,1,5);\nluaL_checkany(L,2);\nlua_settop(L,2);\nlua_rawget(L,1);\nreturn 1;\n}\nstatic int luaB_type(lua_State*L){\nluaL_checkany(L,1);\nlua_pushstring(L,luaL_typename(L,1));\nreturn 1;\n}\nstatic int luaB_next(lua_State*L){\nluaL_checktype(L,1,5);\nlua_settop(L,2);\nif(lua_next(L,1))\nreturn 2;\nelse{\nlua_pushnil(L);\nreturn 1;\n}\n}\nstatic int luaB_pairs(lua_State*L){\nluaL_checktype(L,1,5);\nlua_pushvalue(L,lua_upvalueindex(1));\nlua_pushvalue(L,1);\nlua_pushnil(L);\nreturn 3;\n}\nstatic int ipairsaux(lua_State*L){\nint i=luaL_checkint(L,2);\nluaL_checktype(L,1,5);\ni++;\nlua_pushinteger(L,i);\nlua_rawgeti(L,1,i);\nreturn(lua_isnil(L,-1))?0:2;\n}\nstatic int luaB_ipairs(lua_State*L){\nluaL_checktype(L,1,5);\nlua_pushvalue(L,lua_upvalueindex(1));\nlua_pushvalue(L,1);\nlua_pushinteger(L,0);\nreturn 3;\n}\nstatic int load_aux(lua_State*L,int status){\nif(status==0)\nreturn 1;\nelse{\nlua_pushnil(L);\nlua_insert(L,-2);\nreturn 2;\n}\n}\nstatic int luaB_loadstring(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nconst char*chunkname=luaL_optstring(L,2,s);\nreturn load_aux(L,luaL_loadbuffer(L,s,l,chunkname));\n}\nstatic int luaB_loadfile(lua_State*L){\nconst char*fname=luaL_optstring(L,1,NULL);\nreturn load_aux(L,luaL_loadfile(L,fname));\n}\nstatic int luaB_assert(lua_State*L){\nluaL_checkany(L,1);\nif(!lua_toboolean(L,1))\nreturn luaL_error(L,\"%s\",luaL_optstring(L,2,\"assertion failed!\"));\nreturn lua_gettop(L);\n}\nstatic int luaB_unpack(lua_State*L){\nint i,e,n;\nluaL_checktype(L,1,5);\ni=luaL_optint(L,2,1);\ne=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1));\nif(i>e)return 0;\nn=e-i+1;\nif(n<=0||!lua_checkstack(L,n))\nreturn luaL_error(L,\"too many results to unpack\");\nlua_rawgeti(L,1,i);\nwhile(i++<e)\nlua_rawgeti(L,1,i);\nreturn n;\n}\nstatic int luaB_pcall(lua_State*L){\nint status;\nluaL_checkany(L,1);\nstatus=lua_pcall(L,lua_gettop(L)-1,(-1),0);\nlua_pushboolean(L,(status==0));\nlua_insert(L,1);\nreturn lua_gettop(L);\n}\nstatic int luaB_newproxy(lua_State*L){\nlua_settop(L,1);\nlua_newuserdata(L,0);\nif(lua_toboolean(L,1)==0)\nreturn 1;\nelse if(lua_isboolean(L,1)){\nlua_newtable(L);\nlua_pushvalue(L,-1);\nlua_pushboolean(L,1);\nlua_rawset(L,lua_upvalueindex(1));\n}\nelse{\nint validproxy=0;\nif(lua_getmetatable(L,1)){\nlua_rawget(L,lua_upvalueindex(1));\nvalidproxy=lua_toboolean(L,-1);\nlua_pop(L,1);\n}\nluaL_argcheck(L,validproxy,1,\"boolean or proxy expected\");\nlua_getmetatable(L,1);\n}\nlua_setmetatable(L,2);\nreturn 1;\n}\nstatic const luaL_Reg base_funcs[]={\n{\"assert\",luaB_assert},\n{\"error\",luaB_error},\n{\"loadfile\",luaB_loadfile},\n{\"loadstring\",luaB_loadstring},\n{\"next\",luaB_next},\n{\"pcall\",luaB_pcall},\n{\"rawget\",luaB_rawget},\n{\"setfenv\",luaB_setfenv},\n{\"setmetatable\",luaB_setmetatable},\n{\"tonumber\",luaB_tonumber},\n{\"type\",luaB_type},\n{\"unpack\",luaB_unpack},\n{NULL,NULL}\n};\nstatic void auxopen(lua_State*L,const char*name,\nlua_CFunction f,lua_CFunction u){\nlua_pushcfunction(L,u);\nlua_pushcclosure(L,f,1);\nlua_setfield(L,-2,name);\n}\nstatic void base_open(lua_State*L){\nlua_pushvalue(L,(-10002));\nlua_setglobal(L,\"_G\");\nluaL_register(L,\"_G\",base_funcs);\nlua_pushliteral(L,\"Lua 5.1\");\nlua_setglobal(L,\"_VERSION\");\nauxopen(L,\"ipairs\",luaB_ipairs,ipairsaux);\nauxopen(L,\"pairs\",luaB_pairs,luaB_next);\nlua_createtable(L,0,1);\nlua_pushvalue(L,-1);\nlua_setmetatable(L,-2);\nlua_pushliteral(L,\"kv\");\nlua_setfield(L,-2,\"__mode\");\nlua_pushcclosure(L,luaB_newproxy,1);\nlua_setglobal(L,\"newproxy\");\n}\nstatic int luaopen_base(lua_State*L){\nbase_open(L);\nreturn 1;\n}\n#define aux_getn(L,n)(luaL_checktype(L,n,5),luaL_getn(L,n))\nstatic int tinsert(lua_State*L){\nint e=aux_getn(L,1)+1;\nint pos;\nswitch(lua_gettop(L)){\ncase 2:{\npos=e;\nbreak;\n}\ncase 3:{\nint i;\npos=luaL_checkint(L,2);\nif(pos>e)e=pos;\nfor(i=e;i>pos;i--){\nlua_rawgeti(L,1,i-1);\nlua_rawseti(L,1,i);\n}\nbreak;\n}\ndefault:{\nreturn luaL_error(L,\"wrong number of arguments to \"LUA_QL(\"insert\"));\n}\n}\nluaL_setn(L,1,e);\nlua_rawseti(L,1,pos);\nreturn 0;\n}\nstatic int tremove(lua_State*L){\nint e=aux_getn(L,1);\nint pos=luaL_optint(L,2,e);\nif(!(1<=pos&&pos<=e))\nreturn 0;\nluaL_setn(L,1,e-1);\nlua_rawgeti(L,1,pos);\nfor(;pos<e;pos++){\nlua_rawgeti(L,1,pos+1);\nlua_rawseti(L,1,pos);\n}\nlua_pushnil(L);\nlua_rawseti(L,1,e);\nreturn 1;\n}\nstatic void addfield(lua_State*L,luaL_Buffer*b,int i){\nlua_rawgeti(L,1,i);\nif(!lua_isstring(L,-1))\nluaL_error(L,\"invalid value (%s) at index %d in table for \"\nLUA_QL(\"concat\"),luaL_typename(L,-1),i);\nluaL_addvalue(b);\n}\nstatic int tconcat(lua_State*L){\nluaL_Buffer b;\nsize_t lsep;\nint i,last;\nconst char*sep=luaL_optlstring(L,2,\"\",&lsep);\nluaL_checktype(L,1,5);\ni=luaL_optint(L,3,1);\nlast=luaL_opt(L,luaL_checkint,4,luaL_getn(L,1));\nluaL_buffinit(L,&b);\nfor(;i<last;i++){\naddfield(L,&b,i);\nluaL_addlstring(&b,sep,lsep);\n}\nif(i==last)\naddfield(L,&b,i);\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic void set2(lua_State*L,int i,int j){\nlua_rawseti(L,1,i);\nlua_rawseti(L,1,j);\n}\nstatic int sort_comp(lua_State*L,int a,int b){\nif(!lua_isnil(L,2)){\nint res;\nlua_pushvalue(L,2);\nlua_pushvalue(L,a-1);\nlua_pushvalue(L,b-2);\nlua_call(L,2,1);\nres=lua_toboolean(L,-1);\nlua_pop(L,1);\nreturn res;\n}\nelse\nreturn lua_lessthan(L,a,b);\n}\nstatic void auxsort(lua_State*L,int l,int u){\nwhile(l<u){\nint i,j;\nlua_rawgeti(L,1,l);\nlua_rawgeti(L,1,u);\nif(sort_comp(L,-1,-2))\nset2(L,l,u);\nelse\nlua_pop(L,2);\nif(u-l==1)break;\ni=(l+u)/2;\nlua_rawgeti(L,1,i);\nlua_rawgeti(L,1,l);\nif(sort_comp(L,-2,-1))\nset2(L,i,l);\nelse{\nlua_pop(L,1);\nlua_rawgeti(L,1,u);\nif(sort_comp(L,-1,-2))\nset2(L,i,u);\nelse\nlua_pop(L,2);\n}\nif(u-l==2)break;\nlua_rawgeti(L,1,i);\nlua_pushvalue(L,-1);\nlua_rawgeti(L,1,u-1);\nset2(L,i,u-1);\ni=l;j=u-1;\nfor(;;){\nwhile(lua_rawgeti(L,1,++i),sort_comp(L,-1,-2)){\nif(i>u)luaL_error(L,\"invalid order function for sorting\");\nlua_pop(L,1);\n}\nwhile(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){\nif(j<l)luaL_error(L,\"invalid order function for sorting\");\nlua_pop(L,1);\n}\nif(j<i){\nlua_pop(L,3);\nbreak;\n}\nset2(L,i,j);\n}\nlua_rawgeti(L,1,u-1);\nlua_rawgeti(L,1,i);\nset2(L,u-1,i);\nif(i-l<u-i){\nj=l;i=i-1;l=i+2;\n}\nelse{\nj=i+1;i=u;u=j-2;\n}\nauxsort(L,j,i);\n}\n}\nstatic int sort(lua_State*L){\nint n=aux_getn(L,1);\nluaL_checkstack(L,40,\"\");\nif(!lua_isnoneornil(L,2))\nluaL_checktype(L,2,6);\nlua_settop(L,2);\nauxsort(L,1,n);\nreturn 0;\n}\nstatic const luaL_Reg tab_funcs[]={\n{\"concat\",tconcat},\n{\"insert\",tinsert},\n{\"remove\",tremove},\n{\"sort\",sort},\n{NULL,NULL}\n};\nstatic int luaopen_table(lua_State*L){\nluaL_register(L,\"table\",tab_funcs);\nreturn 1;\n}\nstatic const char*const fnames[]={\"input\",\"output\"};\nstatic int pushresult(lua_State*L,int i,const char*filename){\nint en=errno;\nif(i){\nlua_pushboolean(L,1);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nif(filename)\nlua_pushfstring(L,\"%s: %s\",filename,strerror(en));\nelse\nlua_pushfstring(L,\"%s\",strerror(en));\nlua_pushinteger(L,en);\nreturn 3;\n}\n}\nstatic void fileerror(lua_State*L,int arg,const char*filename){\nlua_pushfstring(L,\"%s: %s\",filename,strerror(errno));\nluaL_argerror(L,arg,lua_tostring(L,-1));\n}\n#define tofilep(L)((FILE**)luaL_checkudata(L,1,\"FILE*\"))\nstatic int io_type(lua_State*L){\nvoid*ud;\nluaL_checkany(L,1);\nud=lua_touserdata(L,1);\nlua_getfield(L,(-10000),\"FILE*\");\nif(ud==NULL||!lua_getmetatable(L,1)||!lua_rawequal(L,-2,-1))\nlua_pushnil(L);\nelse if(*((FILE**)ud)==NULL)\nlua_pushliteral(L,\"closed file\");\nelse\nlua_pushliteral(L,\"file\");\nreturn 1;\n}\nstatic FILE*tofile(lua_State*L){\nFILE**f=tofilep(L);\nif(*f==NULL)\nluaL_error(L,\"attempt to use a closed file\");\nreturn*f;\n}\nstatic FILE**newfile(lua_State*L){\nFILE**pf=(FILE**)lua_newuserdata(L,sizeof(FILE*));\n*pf=NULL;\nluaL_getmetatable(L,\"FILE*\");\nlua_setmetatable(L,-2);\nreturn pf;\n}\nstatic int io_noclose(lua_State*L){\nlua_pushnil(L);\nlua_pushliteral(L,\"cannot close standard file\");\nreturn 2;\n}\nstatic int io_pclose(lua_State*L){\nFILE**p=tofilep(L);\nint ok=lua_pclose(L,*p);\n*p=NULL;\nreturn pushresult(L,ok,NULL);\n}\nstatic int io_fclose(lua_State*L){\nFILE**p=tofilep(L);\nint ok=(fclose(*p)==0);\n*p=NULL;\nreturn pushresult(L,ok,NULL);\n}\nstatic int aux_close(lua_State*L){\nlua_getfenv(L,1);\nlua_getfield(L,-1,\"__close\");\nreturn(lua_tocfunction(L,-1))(L);\n}\nstatic int io_close(lua_State*L){\nif(lua_isnone(L,1))\nlua_rawgeti(L,(-10001),2);\ntofile(L);\nreturn aux_close(L);\n}\nstatic int io_gc(lua_State*L){\nFILE*f=*tofilep(L);\nif(f!=NULL)\naux_close(L);\nreturn 0;\n}\nstatic int io_open(lua_State*L){\nconst char*filename=luaL_checkstring(L,1);\nconst char*mode=luaL_optstring(L,2,\"r\");\nFILE**pf=newfile(L);\n*pf=fopen(filename,mode);\nreturn(*pf==NULL)?pushresult(L,0,filename):1;\n}\nstatic FILE*getiofile(lua_State*L,int findex){\nFILE*f;\nlua_rawgeti(L,(-10001),findex);\nf=*(FILE**)lua_touserdata(L,-1);\nif(f==NULL)\nluaL_error(L,\"standard %s file is closed\",fnames[findex-1]);\nreturn f;\n}\nstatic int g_iofile(lua_State*L,int f,const char*mode){\nif(!lua_isnoneornil(L,1)){\nconst char*filename=lua_tostring(L,1);\nif(filename){\nFILE**pf=newfile(L);\n*pf=fopen(filename,mode);\nif(*pf==NULL)\nfileerror(L,1,filename);\n}\nelse{\ntofile(L);\nlua_pushvalue(L,1);\n}\nlua_rawseti(L,(-10001),f);\n}\nlua_rawgeti(L,(-10001),f);\nreturn 1;\n}\nstatic int io_input(lua_State*L){\nreturn g_iofile(L,1,\"r\");\n}\nstatic int io_output(lua_State*L){\nreturn g_iofile(L,2,\"w\");\n}\nstatic int io_readline(lua_State*L);\nstatic void aux_lines(lua_State*L,int idx,int toclose){\nlua_pushvalue(L,idx);\nlua_pushboolean(L,toclose);\nlua_pushcclosure(L,io_readline,2);\n}\nstatic int f_lines(lua_State*L){\ntofile(L);\naux_lines(L,1,0);\nreturn 1;\n}\nstatic int io_lines(lua_State*L){\nif(lua_isnoneornil(L,1)){\nlua_rawgeti(L,(-10001),1);\nreturn f_lines(L);\n}\nelse{\nconst char*filename=luaL_checkstring(L,1);\nFILE**pf=newfile(L);\n*pf=fopen(filename,\"r\");\nif(*pf==NULL)\nfileerror(L,1,filename);\naux_lines(L,lua_gettop(L),1);\nreturn 1;\n}\n}\nstatic int read_number(lua_State*L,FILE*f){\nlua_Number d;\nif(fscanf(f,\"%lf\",&d)==1){\nlua_pushnumber(L,d);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nreturn 0;\n}\n}\nstatic int test_eof(lua_State*L,FILE*f){\nint c=getc(f);\nungetc(c,f);\nlua_pushlstring(L,NULL,0);\nreturn(c!=EOF);\n}\nstatic int read_line(lua_State*L,FILE*f){\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nfor(;;){\nsize_t l;\nchar*p=luaL_prepbuffer(&b);\nif(fgets(p,BUFSIZ,f)==NULL){\nluaL_pushresult(&b);\nreturn(lua_objlen(L,-1)>0);\n}\nl=strlen(p);\nif(l==0||p[l-1]!='\\n')\nluaL_addsize(&b,l);\nelse{\nluaL_addsize(&b,l-1);\nluaL_pushresult(&b);\nreturn 1;\n}\n}\n}\nstatic int read_chars(lua_State*L,FILE*f,size_t n){\nsize_t rlen;\nsize_t nr;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nrlen=BUFSIZ;\ndo{\nchar*p=luaL_prepbuffer(&b);\nif(rlen>n)rlen=n;\nnr=fread(p,sizeof(char),rlen,f);\nluaL_addsize(&b,nr);\nn-=nr;\n}while(n>0&&nr==rlen);\nluaL_pushresult(&b);\nreturn(n==0||lua_objlen(L,-1)>0);\n}\nstatic int g_read(lua_State*L,FILE*f,int first){\nint nargs=lua_gettop(L)-1;\nint success;\nint n;\nclearerr(f);\nif(nargs==0){\nsuccess=read_line(L,f);\nn=first+1;\n}\nelse{\nluaL_checkstack(L,nargs+20,\"too many arguments\");\nsuccess=1;\nfor(n=first;nargs--&&success;n++){\nif(lua_type(L,n)==3){\nsize_t l=(size_t)lua_tointeger(L,n);\nsuccess=(l==0)?test_eof(L,f):read_chars(L,f,l);\n}\nelse{\nconst char*p=lua_tostring(L,n);\nluaL_argcheck(L,p&&p[0]=='*',n,\"invalid option\");\nswitch(p[1]){\ncase'n':\nsuccess=read_number(L,f);\nbreak;\ncase'l':\nsuccess=read_line(L,f);\nbreak;\ncase'a':\nread_chars(L,f,~((size_t)0));\nsuccess=1;\nbreak;\ndefault:\nreturn luaL_argerror(L,n,\"invalid format\");\n}\n}\n}\n}\nif(ferror(f))\nreturn pushresult(L,0,NULL);\nif(!success){\nlua_pop(L,1);\nlua_pushnil(L);\n}\nreturn n-first;\n}\nstatic int io_read(lua_State*L){\nreturn g_read(L,getiofile(L,1),1);\n}\nstatic int f_read(lua_State*L){\nreturn g_read(L,tofile(L),2);\n}\nstatic int io_readline(lua_State*L){\nFILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1));\nint sucess;\nif(f==NULL)\nluaL_error(L,\"file is already closed\");\nsucess=read_line(L,f);\nif(ferror(f))\nreturn luaL_error(L,\"%s\",strerror(errno));\nif(sucess)return 1;\nelse{\nif(lua_toboolean(L,lua_upvalueindex(2))){\nlua_settop(L,0);\nlua_pushvalue(L,lua_upvalueindex(1));\naux_close(L);\n}\nreturn 0;\n}\n}\nstatic int g_write(lua_State*L,FILE*f,int arg){\nint nargs=lua_gettop(L)-1;\nint status=1;\nfor(;nargs--;arg++){\nif(lua_type(L,arg)==3){\nstatus=status&&\nfprintf(f,\"%.14g\",lua_tonumber(L,arg))>0;\n}\nelse{\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nstatus=status&&(fwrite(s,sizeof(char),l,f)==l);\n}\n}\nreturn pushresult(L,status,NULL);\n}\nstatic int io_write(lua_State*L){\nreturn g_write(L,getiofile(L,2),1);\n}\nstatic int f_write(lua_State*L){\nreturn g_write(L,tofile(L),2);\n}\nstatic int io_flush(lua_State*L){\nreturn pushresult(L,fflush(getiofile(L,2))==0,NULL);\n}\nstatic int f_flush(lua_State*L){\nreturn pushresult(L,fflush(tofile(L))==0,NULL);\n}\nstatic const luaL_Reg iolib[]={\n{\"close\",io_close},\n{\"flush\",io_flush},\n{\"input\",io_input},\n{\"lines\",io_lines},\n{\"open\",io_open},\n{\"output\",io_output},\n{\"read\",io_read},\n{\"type\",io_type},\n{\"write\",io_write},\n{NULL,NULL}\n};\nstatic const luaL_Reg flib[]={\n{\"close\",io_close},\n{\"flush\",f_flush},\n{\"lines\",f_lines},\n{\"read\",f_read},\n{\"write\",f_write},\n{\"__gc\",io_gc},\n{NULL,NULL}\n};\nstatic void createmeta(lua_State*L){\nluaL_newmetatable(L,\"FILE*\");\nlua_pushvalue(L,-1);\nlua_setfield(L,-2,\"__index\");\nluaL_register(L,NULL,flib);\n}\nstatic void createstdfile(lua_State*L,FILE*f,int k,const char*fname){\n*newfile(L)=f;\nif(k>0){\nlua_pushvalue(L,-1);\nlua_rawseti(L,(-10001),k);\n}\nlua_pushvalue(L,-2);\nlua_setfenv(L,-2);\nlua_setfield(L,-3,fname);\n}\nstatic void newfenv(lua_State*L,lua_CFunction cls){\nlua_createtable(L,0,1);\nlua_pushcfunction(L,cls);\nlua_setfield(L,-2,\"__close\");\n}\nstatic int luaopen_io(lua_State*L){\ncreatemeta(L);\nnewfenv(L,io_fclose);\nlua_replace(L,(-10001));\nluaL_register(L,\"io\",iolib);\nnewfenv(L,io_noclose);\ncreatestdfile(L,stdin,1,\"stdin\");\ncreatestdfile(L,stdout,2,\"stdout\");\ncreatestdfile(L,stderr,0,\"stderr\");\nlua_pop(L,1);\nlua_getfield(L,-1,\"popen\");\nnewfenv(L,io_pclose);\nlua_setfenv(L,-2);\nlua_pop(L,1);\nreturn 1;\n}\nstatic int os_pushresult(lua_State*L,int i,const char*filename){\nint en=errno;\nif(i){\nlua_pushboolean(L,1);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nlua_pushfstring(L,\"%s: %s\",filename,strerror(en));\nlua_pushinteger(L,en);\nreturn 3;\n}\n}\nstatic int os_remove(lua_State*L){\nconst char*filename=luaL_checkstring(L,1);\nreturn os_pushresult(L,remove(filename)==0,filename);\n}\nstatic int os_exit(lua_State*L){\nexit(luaL_optint(L,1,EXIT_SUCCESS));\n}\nstatic const luaL_Reg syslib[]={\n{\"exit\",os_exit},\n{\"remove\",os_remove},\n{NULL,NULL}\n};\nstatic int luaopen_os(lua_State*L){\nluaL_register(L,\"os\",syslib);\nreturn 1;\n}\n#define uchar(c)((unsigned char)(c))\nstatic ptrdiff_t posrelat(ptrdiff_t pos,size_t len){\nif(pos<0)pos+=(ptrdiff_t)len+1;\nreturn(pos>=0)?pos:0;\n}\nstatic int str_sub(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nptrdiff_t start=posrelat(luaL_checkinteger(L,2),l);\nptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l);\nif(start<1)start=1;\nif(end>(ptrdiff_t)l)end=(ptrdiff_t)l;\nif(start<=end)\nlua_pushlstring(L,s+start-1,end-start+1);\nelse lua_pushliteral(L,\"\");\nreturn 1;\n}\nstatic int str_lower(lua_State*L){\nsize_t l;\nsize_t i;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nluaL_buffinit(L,&b);\nfor(i=0;i<l;i++)\nluaL_addchar(&b,tolower(uchar(s[i])));\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_upper(lua_State*L){\nsize_t l;\nsize_t i;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nluaL_buffinit(L,&b);\nfor(i=0;i<l;i++)\nluaL_addchar(&b,toupper(uchar(s[i])));\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_rep(lua_State*L){\nsize_t l;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nint n=luaL_checkint(L,2);\nluaL_buffinit(L,&b);\nwhile(n-->0)\nluaL_addlstring(&b,s,l);\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_byte(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l);\nptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l);\nint n,i;\nif(posi<=0)posi=1;\nif((size_t)pose>l)pose=l;\nif(posi>pose)return 0;\nn=(int)(pose-posi+1);\nif(posi+n<=pose)\nluaL_error(L,\"string slice too long\");\nluaL_checkstack(L,n,\"string slice too long\");\nfor(i=0;i<n;i++)\nlua_pushinteger(L,uchar(s[posi+i-1]));\nreturn n;\n}\nstatic int str_char(lua_State*L){\nint n=lua_gettop(L);\nint i;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nfor(i=1;i<=n;i++){\nint c=luaL_checkint(L,i);\nluaL_argcheck(L,uchar(c)==c,i,\"invalid value\");\nluaL_addchar(&b,uchar(c));\n}\nluaL_pushresult(&b);\nreturn 1;\n}\ntypedef struct MatchState{\nconst char*src_init;\nconst char*src_end;\nlua_State*L;\nint level;\nstruct{\nconst char*init;\nptrdiff_t len;\n}capture[32];\n}MatchState;\nstatic int check_capture(MatchState*ms,int l){\nl-='1';\nif(l<0||l>=ms->level||ms->capture[l].len==(-1))\nreturn luaL_error(ms->L,\"invalid capture index\");\nreturn l;\n}\nstatic int capture_to_close(MatchState*ms){\nint level=ms->level;\nfor(level--;level>=0;level--)\nif(ms->capture[level].len==(-1))return level;\nreturn luaL_error(ms->L,\"invalid pattern capture\");\n}\nstatic const char*classend(MatchState*ms,const char*p){\nswitch(*p++){\ncase'%':{\nif(*p=='\\0')\nluaL_error(ms->L,\"malformed pattern (ends with \"LUA_QL(\"%%\")\")\");\nreturn p+1;\n}\ncase'[':{\nif(*p=='^')p++;\ndo{\nif(*p=='\\0')\nluaL_error(ms->L,\"malformed pattern (missing \"LUA_QL(\"]\")\")\");\nif(*(p++)=='%'&&*p!='\\0')\np++;\n}while(*p!=']');\nreturn p+1;\n}\ndefault:{\nreturn p;\n}\n}\n}\nstatic int match_class(int c,int cl){\nint res;\nswitch(tolower(cl)){\ncase'a':res=isalpha(c);break;\ncase'c':res=iscntrl(c);break;\ncase'd':res=isdigit(c);break;\ncase'l':res=islower(c);break;\ncase'p':res=ispunct(c);break;\ncase's':res=isspace(c);break;\ncase'u':res=isupper(c);break;\ncase'w':res=isalnum(c);break;\ncase'x':res=isxdigit(c);break;\ncase'z':res=(c==0);break;\ndefault:return(cl==c);\n}\nreturn(islower(cl)?res:!res);\n}\nstatic int matchbracketclass(int c,const char*p,const char*ec){\nint sig=1;\nif(*(p+1)=='^'){\nsig=0;\np++;\n}\nwhile(++p<ec){\nif(*p=='%'){\np++;\nif(match_class(c,uchar(*p)))\nreturn sig;\n}\nelse if((*(p+1)=='-')&&(p+2<ec)){\np+=2;\nif(uchar(*(p-2))<=c&&c<=uchar(*p))\nreturn sig;\n}\nelse if(uchar(*p)==c)return sig;\n}\nreturn!sig;\n}\nstatic int singlematch(int c,const char*p,const char*ep){\nswitch(*p){\ncase'.':return 1;\ncase'%':return match_class(c,uchar(*(p+1)));\ncase'[':return matchbracketclass(c,p,ep-1);\ndefault:return(uchar(*p)==c);\n}\n}\nstatic const char*match(MatchState*ms,const char*s,const char*p);\nstatic const char*matchbalance(MatchState*ms,const char*s,\nconst char*p){\nif(*p==0||*(p+1)==0)\nluaL_error(ms->L,\"unbalanced pattern\");\nif(*s!=*p)return NULL;\nelse{\nint b=*p;\nint e=*(p+1);\nint cont=1;\nwhile(++s<ms->src_end){\nif(*s==e){\nif(--cont==0)return s+1;\n}\nelse if(*s==b)cont++;\n}\n}\nreturn NULL;\n}\nstatic const char*max_expand(MatchState*ms,const char*s,\nconst char*p,const char*ep){\nptrdiff_t i=0;\nwhile((s+i)<ms->src_end&&singlematch(uchar(*(s+i)),p,ep))\ni++;\nwhile(i>=0){\nconst char*res=match(ms,(s+i),ep+1);\nif(res)return res;\ni--;\n}\nreturn NULL;\n}\nstatic const char*min_expand(MatchState*ms,const char*s,\nconst char*p,const char*ep){\nfor(;;){\nconst char*res=match(ms,s,ep+1);\nif(res!=NULL)\nreturn res;\nelse if(s<ms->src_end&&singlematch(uchar(*s),p,ep))\ns++;\nelse return NULL;\n}\n}\nstatic const char*start_capture(MatchState*ms,const char*s,\nconst char*p,int what){\nconst char*res;\nint level=ms->level;\nif(level>=32)luaL_error(ms->L,\"too many captures\");\nms->capture[level].init=s;\nms->capture[level].len=what;\nms->level=level+1;\nif((res=match(ms,s,p))==NULL)\nms->level--;\nreturn res;\n}\nstatic const char*end_capture(MatchState*ms,const char*s,\nconst char*p){\nint l=capture_to_close(ms);\nconst char*res;\nms->capture[l].len=s-ms->capture[l].init;\nif((res=match(ms,s,p))==NULL)\nms->capture[l].len=(-1);\nreturn res;\n}\nstatic const char*match_capture(MatchState*ms,const char*s,int l){\nsize_t len;\nl=check_capture(ms,l);\nlen=ms->capture[l].len;\nif((size_t)(ms->src_end-s)>=len&&\nmemcmp(ms->capture[l].init,s,len)==0)\nreturn s+len;\nelse return NULL;\n}\nstatic const char*match(MatchState*ms,const char*s,const char*p){\ninit:\nswitch(*p){\ncase'(':{\nif(*(p+1)==')')\nreturn start_capture(ms,s,p+2,(-2));\nelse\nreturn start_capture(ms,s,p+1,(-1));\n}\ncase')':{\nreturn end_capture(ms,s,p+1);\n}\ncase'%':{\nswitch(*(p+1)){\ncase'b':{\ns=matchbalance(ms,s,p+2);\nif(s==NULL)return NULL;\np+=4;goto init;\n}\ncase'f':{\nconst char*ep;char previous;\np+=2;\nif(*p!='[')\nluaL_error(ms->L,\"missing \"LUA_QL(\"[\")\" after \"\nLUA_QL(\"%%f\")\" in pattern\");\nep=classend(ms,p);\nprevious=(s==ms->src_init)?'\\0':*(s-1);\nif(matchbracketclass(uchar(previous),p,ep-1)||\n!matchbracketclass(uchar(*s),p,ep-1))return NULL;\np=ep;goto init;\n}\ndefault:{\nif(isdigit(uchar(*(p+1)))){\ns=match_capture(ms,s,uchar(*(p+1)));\nif(s==NULL)return NULL;\np+=2;goto init;\n}\ngoto dflt;\n}\n}\n}\ncase'\\0':{\nreturn s;\n}\ncase'$':{\nif(*(p+1)=='\\0')\nreturn(s==ms->src_end)?s:NULL;\nelse goto dflt;\n}\ndefault:dflt:{\nconst char*ep=classend(ms,p);\nint m=s<ms->src_end&&singlematch(uchar(*s),p,ep);\nswitch(*ep){\ncase'?':{\nconst char*res;\nif(m&&((res=match(ms,s+1,ep+1))!=NULL))\nreturn res;\np=ep+1;goto init;\n}\ncase'*':{\nreturn max_expand(ms,s,p,ep);\n}\ncase'+':{\nreturn(m?max_expand(ms,s+1,p,ep):NULL);\n}\ncase'-':{\nreturn min_expand(ms,s,p,ep);\n}\ndefault:{\nif(!m)return NULL;\ns++;p=ep;goto init;\n}\n}\n}\n}\n}\nstatic const char*lmemfind(const char*s1,size_t l1,\nconst char*s2,size_t l2){\nif(l2==0)return s1;\nelse if(l2>l1)return NULL;\nelse{\nconst char*init;\nl2--;\nl1=l1-l2;\nwhile(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){\ninit++;\nif(memcmp(init,s2+1,l2)==0)\nreturn init-1;\nelse{\nl1-=init-s1;\ns1=init;\n}\n}\nreturn NULL;\n}\n}\nstatic void push_onecapture(MatchState*ms,int i,const char*s,\nconst char*e){\nif(i>=ms->level){\nif(i==0)\nlua_pushlstring(ms->L,s,e-s);\nelse\nluaL_error(ms->L,\"invalid capture index\");\n}\nelse{\nptrdiff_t l=ms->capture[i].len;\nif(l==(-1))luaL_error(ms->L,\"unfinished capture\");\nif(l==(-2))\nlua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1);\nelse\nlua_pushlstring(ms->L,ms->capture[i].init,l);\n}\n}\nstatic int push_captures(MatchState*ms,const char*s,const char*e){\nint i;\nint nlevels=(ms->level==0&&s)?1:ms->level;\nluaL_checkstack(ms->L,nlevels,\"too many captures\");\nfor(i=0;i<nlevels;i++)\npush_onecapture(ms,i,s,e);\nreturn nlevels;\n}\nstatic int str_find_aux(lua_State*L,int find){\nsize_t l1,l2;\nconst char*s=luaL_checklstring(L,1,&l1);\nconst char*p=luaL_checklstring(L,2,&l2);\nptrdiff_t init=posrelat(luaL_optinteger(L,3,1),l1)-1;\nif(init<0)init=0;\nelse if((size_t)(init)>l1)init=(ptrdiff_t)l1;\nif(find&&(lua_toboolean(L,4)||\nstrpbrk(p,\"^$*+?.([%-\")==NULL)){\nconst char*s2=lmemfind(s+init,l1-init,p,l2);\nif(s2){\nlua_pushinteger(L,s2-s+1);\nlua_pushinteger(L,s2-s+l2);\nreturn 2;\n}\n}\nelse{\nMatchState ms;\nint anchor=(*p=='^')?(p++,1):0;\nconst char*s1=s+init;\nms.L=L;\nms.src_init=s;\nms.src_end=s+l1;\ndo{\nconst char*res;\nms.level=0;\nif((res=match(&ms,s1,p))!=NULL){\nif(find){\nlua_pushinteger(L,s1-s+1);\nlua_pushinteger(L,res-s);\nreturn push_captures(&ms,NULL,0)+2;\n}\nelse\nreturn push_captures(&ms,s1,res);\n}\n}while(s1++<ms.src_end&&!anchor);\n}\nlua_pushnil(L);\nreturn 1;\n}\nstatic int str_find(lua_State*L){\nreturn str_find_aux(L,1);\n}\nstatic int str_match(lua_State*L){\nreturn str_find_aux(L,0);\n}\nstatic int gmatch_aux(lua_State*L){\nMatchState ms;\nsize_t ls;\nconst char*s=lua_tolstring(L,lua_upvalueindex(1),&ls);\nconst char*p=lua_tostring(L,lua_upvalueindex(2));\nconst char*src;\nms.L=L;\nms.src_init=s;\nms.src_end=s+ls;\nfor(src=s+(size_t)lua_tointeger(L,lua_upvalueindex(3));\nsrc<=ms.src_end;\nsrc++){\nconst char*e;\nms.level=0;\nif((e=match(&ms,src,p))!=NULL){\nlua_Integer newstart=e-s;\nif(e==src)newstart++;\nlua_pushinteger(L,newstart);\nlua_replace(L,lua_upvalueindex(3));\nreturn push_captures(&ms,src,e);\n}\n}\nreturn 0;\n}\nstatic int gmatch(lua_State*L){\nluaL_checkstring(L,1);\nluaL_checkstring(L,2);\nlua_settop(L,2);\nlua_pushinteger(L,0);\nlua_pushcclosure(L,gmatch_aux,3);\nreturn 1;\n}\nstatic void add_s(MatchState*ms,luaL_Buffer*b,const char*s,\nconst char*e){\nsize_t l,i;\nconst char*news=lua_tolstring(ms->L,3,&l);\nfor(i=0;i<l;i++){\nif(news[i]!='%')\nluaL_addchar(b,news[i]);\nelse{\ni++;\nif(!isdigit(uchar(news[i])))\nluaL_addchar(b,news[i]);\nelse if(news[i]=='0')\nluaL_addlstring(b,s,e-s);\nelse{\npush_onecapture(ms,news[i]-'1',s,e);\nluaL_addvalue(b);\n}\n}\n}\n}\nstatic void add_value(MatchState*ms,luaL_Buffer*b,const char*s,\nconst char*e){\nlua_State*L=ms->L;\nswitch(lua_type(L,3)){\ncase 3:\ncase 4:{\nadd_s(ms,b,s,e);\nreturn;\n}\ncase 6:{\nint n;\nlua_pushvalue(L,3);\nn=push_captures(ms,s,e);\nlua_call(L,n,1);\nbreak;\n}\ncase 5:{\npush_onecapture(ms,0,s,e);\nlua_gettable(L,3);\nbreak;\n}\n}\nif(!lua_toboolean(L,-1)){\nlua_pop(L,1);\nlua_pushlstring(L,s,e-s);\n}\nelse if(!lua_isstring(L,-1))\nluaL_error(L,\"invalid replacement value (a %s)\",luaL_typename(L,-1));\nluaL_addvalue(b);\n}\nstatic int str_gsub(lua_State*L){\nsize_t srcl;\nconst char*src=luaL_checklstring(L,1,&srcl);\nconst char*p=luaL_checkstring(L,2);\nint tr=lua_type(L,3);\nint max_s=luaL_optint(L,4,srcl+1);\nint anchor=(*p=='^')?(p++,1):0;\nint n=0;\nMatchState ms;\nluaL_Buffer b;\nluaL_argcheck(L,tr==3||tr==4||\ntr==6||tr==5,3,\n\"string/function/table expected\");\nluaL_buffinit(L,&b);\nms.L=L;\nms.src_init=src;\nms.src_end=src+srcl;\nwhile(n<max_s){\nconst char*e;\nms.level=0;\ne=match(&ms,src,p);\nif(e){\nn++;\nadd_value(&ms,&b,src,e);\n}\nif(e&&e>src)\nsrc=e;\nelse if(src<ms.src_end)\nluaL_addchar(&b,*src++);\nelse break;\nif(anchor)break;\n}\nluaL_addlstring(&b,src,ms.src_end-src);\nluaL_pushresult(&b);\nlua_pushinteger(L,n);\nreturn 2;\n}\nstatic void addquoted(lua_State*L,luaL_Buffer*b,int arg){\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nluaL_addchar(b,'\"');\nwhile(l--){\nswitch(*s){\ncase'\"':case'\\\\':case'\\n':{\nluaL_addchar(b,'\\\\');\nluaL_addchar(b,*s);\nbreak;\n}\ncase'\\r':{\nluaL_addlstring(b,\"\\\\r\",2);\nbreak;\n}\ncase'\\0':{\nluaL_addlstring(b,\"\\\\000\",4);\nbreak;\n}\ndefault:{\nluaL_addchar(b,*s);\nbreak;\n}\n}\ns++;\n}\nluaL_addchar(b,'\"');\n}\nstatic const char*scanformat(lua_State*L,const char*strfrmt,char*form){\nconst char*p=strfrmt;\nwhile(*p!='\\0'&&strchr(\"-+ #0\",*p)!=NULL)p++;\nif((size_t)(p-strfrmt)>=sizeof(\"-+ #0\"))\nluaL_error(L,\"invalid format (repeated flags)\");\nif(isdigit(uchar(*p)))p++;\nif(isdigit(uchar(*p)))p++;\nif(*p=='.'){\np++;\nif(isdigit(uchar(*p)))p++;\nif(isdigit(uchar(*p)))p++;\n}\nif(isdigit(uchar(*p)))\nluaL_error(L,\"invalid format (width or precision too long)\");\n*(form++)='%';\nstrncpy(form,strfrmt,p-strfrmt+1);\nform+=p-strfrmt+1;\n*form='\\0';\nreturn p;\n}\nstatic void addintlen(char*form){\nsize_t l=strlen(form);\nchar spec=form[l-1];\nstrcpy(form+l-1,\"l\");\nform[l+sizeof(\"l\")-2]=spec;\nform[l+sizeof(\"l\")-1]='\\0';\n}\nstatic int str_format(lua_State*L){\nint top=lua_gettop(L);\nint arg=1;\nsize_t sfl;\nconst char*strfrmt=luaL_checklstring(L,arg,&sfl);\nconst char*strfrmt_end=strfrmt+sfl;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nwhile(strfrmt<strfrmt_end){\nif(*strfrmt!='%')\nluaL_addchar(&b,*strfrmt++);\nelse if(*++strfrmt=='%')\nluaL_addchar(&b,*strfrmt++);\nelse{\nchar form[(sizeof(\"-+ #0\")+sizeof(\"l\")+10)];\nchar buff[512];\nif(++arg>top)\nluaL_argerror(L,arg,\"no value\");\nstrfrmt=scanformat(L,strfrmt,form);\nswitch(*strfrmt++){\ncase'c':{\nsprintf(buff,form,(int)luaL_checknumber(L,arg));\nbreak;\n}\ncase'd':case'i':{\naddintlen(form);\nsprintf(buff,form,(long)luaL_checknumber(L,arg));\nbreak;\n}\ncase'o':case'u':case'x':case'X':{\naddintlen(form);\nsprintf(buff,form,(unsigned long)luaL_checknumber(L,arg));\nbreak;\n}\ncase'e':case'E':case'f':\ncase'g':case'G':{\nsprintf(buff,form,(double)luaL_checknumber(L,arg));\nbreak;\n}\ncase'q':{\naddquoted(L,&b,arg);\ncontinue;\n}\ncase's':{\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nif(!strchr(form,'.')&&l>=100){\nlua_pushvalue(L,arg);\nluaL_addvalue(&b);\ncontinue;\n}\nelse{\nsprintf(buff,form,s);\nbreak;\n}\n}\ndefault:{\nreturn luaL_error(L,\"invalid option \"LUA_QL(\"%%%c\")\" to \"\nLUA_QL(\"format\"),*(strfrmt-1));\n}\n}\nluaL_addlstring(&b,buff,strlen(buff));\n}\n}\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic const luaL_Reg strlib[]={\n{\"byte\",str_byte},\n{\"char\",str_char},\n{\"find\",str_find},\n{\"format\",str_format},\n{\"gmatch\",gmatch},\n{\"gsub\",str_gsub},\n{\"lower\",str_lower},\n{\"match\",str_match},\n{\"rep\",str_rep},\n{\"sub\",str_sub},\n{\"upper\",str_upper},\n{NULL,NULL}\n};\nstatic void createmetatable(lua_State*L){\nlua_createtable(L,0,1);\nlua_pushliteral(L,\"\");\nlua_pushvalue(L,-2);\nlua_setmetatable(L,-2);\nlua_pop(L,1);\nlua_pushvalue(L,-2);\nlua_setfield(L,-2,\"__index\");\nlua_pop(L,1);\n}\nstatic int luaopen_string(lua_State*L){\nluaL_register(L,\"string\",strlib);\ncreatemetatable(L);\nreturn 1;\n}\nstatic const luaL_Reg lualibs[]={\n{\"\",luaopen_base},\n{\"table\",luaopen_table},\n{\"io\",luaopen_io},\n{\"os\",luaopen_os},\n{\"string\",luaopen_string},\n{NULL,NULL}\n};\nstatic void luaL_openlibs(lua_State*L){\nconst luaL_Reg*lib=lualibs;\nfor(;lib->func;lib++){\nlua_pushcfunction(L,lib->func);\nlua_pushstring(L,lib->name);\nlua_call(L,1,0);\n}\n}\ntypedef unsigned int UB;\nstatic UB barg(lua_State*L,int idx){\nunion{lua_Number n;U64 b;}bn;\nbn.n=lua_tonumber(L,idx)+6755399441055744.0;\nif(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,\"number\");\nreturn(UB)bn.b;\n}\n#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1;\nstatic int tobit(lua_State*L){\nBRET(barg(L,1))}\nstatic int bnot(lua_State*L){\nBRET(~barg(L,1))}\nstatic int band(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}\nstatic int bor(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}\nstatic int bxor(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}\nstatic int lshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}\nstatic int rshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}\nstatic int arshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}\nstatic int rol(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}\nstatic int ror(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}\nstatic int bswap(lua_State*L){\nUB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}\nstatic int tohex(lua_State*L){\nUB b=barg(L,1);\nint n=lua_isnone(L,2)?8:(int)barg(L,2);\nconst char*hexdigits=\"0123456789abcdef\";\nchar buf[8];\nint i;\nif(n<0){n=-n;hexdigits=\"0123456789ABCDEF\";}\nif(n>8)n=8;\nfor(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}\nlua_pushlstring(L,buf,(size_t)n);\nreturn 1;\n}\nstatic const struct luaL_Reg bitlib[]={\n{\"tobit\",tobit},\n{\"bnot\",bnot},\n{\"band\",band},\n{\"bor\",bor},\n{\"bxor\",bxor},\n{\"lshift\",lshift},\n{\"rshift\",rshift},\n{\"arshift\",arshift},\n{\"rol\",rol},\n{\"ror\",ror},\n{\"bswap\",bswap},\n{\"tohex\",tohex},\n{NULL,NULL}\n};\nint main(int argc,char**argv){\nlua_State*L=luaL_newstate();\nint i;\nluaL_openlibs(L);\nluaL_register(L,\"bit\",bitlib);\nif(argc<2)return sizeof(void*);\nlua_createtable(L,0,1);\nlua_pushstring(L,argv[1]);\nlua_rawseti(L,-2,0);\nlua_setglobal(L,\"arg\");\nif(luaL_loadfile(L,argv[1]))\ngoto err;\nfor(i=2;i<argc;i++)\nlua_pushstring(L,argv[i]);\nif(lua_pcall(L,argc-2,0,0)){\nerr:\nfprintf(stderr,\"Error: %s\\n\",lua_tostring(L,-1));\nreturn 1;\n}\nlua_close(L);\nreturn 0;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/bc.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT bytecode listing module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module lists the bytecode of a Lua function. If it's loaded by -jbc\n-- it hooks into the parser and lists all functions of a chunk as they\n-- are parsed.\n--\n-- Example usage:\n--\n--   luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; print(x)'\n--   luajit -jbc=- foo.lua\n--   luajit -jbc=foo.list foo.lua\n--\n-- Default output is to stderr. To redirect the output to a file, pass a\n-- filename as an argument (use '-' for stdout) or set the environment\n-- variable LUAJIT_LISTFILE. The file is overwritten every time the module\n-- is started.\n--\n-- This module can also be used programmatically:\n--\n--   local bc = require(\"jit.bc\")\n--\n--   local function foo() print(\"hello\") end\n--\n--   bc.dump(foo)           --> -- BYTECODE -- [...]\n--   print(bc.line(foo, 2)) --> 0002    KSTR     1   1      ; \"hello\"\n--\n--   local out = {\n--     -- Do something with each line:\n--     write = function(t, ...) io.write(...) end,\n--     close = function(t) end,\n--     flush = function(t) end,\n--   }\n--   bc.dump(foo, out)\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal bit = require(\"bit\")\nlocal sub, gsub, format = string.sub, string.gsub, string.format\nlocal byte, band, shr = string.byte, bit.band, bit.rshift\nlocal funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck\nlocal funcuvname = jutil.funcuvname\nlocal bcnames = vmdef.bcnames\nlocal stdout, stderr = io.stdout, io.stderr\n\n------------------------------------------------------------------------------\n\nlocal function ctlsub(c)\n  if c == \"\\n\" then return \"\\\\n\"\n  elseif c == \"\\r\" then return \"\\\\r\"\n  elseif c == \"\\t\" then return \"\\\\t\"\n  else return format(\"\\\\%03d\", byte(c))\n  end\nend\n\n-- Return one bytecode line.\nlocal function bcline(func, pc, prefix)\n  local ins, m = funcbc(func, pc)\n  if not ins then return end\n  local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128)\n  local a = band(shr(ins, 8), 0xff)\n  local oidx = 6*band(ins, 0xff)\n  local op = sub(bcnames, oidx+1, oidx+6)\n  local s = format(\"%04d %s %-6s %3s \",\n    pc, prefix or \"  \", op, ma == 0 and \"\" or a)\n  local d = shr(ins, 16)\n  if mc == 13*128 then -- BCMjump\n    return format(\"%s=> %04d\\n\", s, pc+d-0x7fff)\n  end\n  if mb ~= 0 then\n    d = band(d, 0xff)\n  elseif mc == 0 then\n    return s..\"\\n\"\n  end\n  local kc\n  if mc == 10*128 then -- BCMstr\n    kc = funck(func, -d-1)\n    kc = format(#kc > 40 and '\"%.40s\"~' or '\"%s\"', gsub(kc, \"%c\", ctlsub))\n  elseif mc == 9*128 then -- BCMnum\n    kc = funck(func, d)\n    if op == \"TSETM \" then kc = kc - 2^52 end\n  elseif mc == 12*128 then -- BCMfunc\n    local fi = funcinfo(funck(func, -d-1))\n    if fi.ffid then\n      kc = vmdef.ffnames[fi.ffid]\n    else\n      kc = fi.loc\n    end\n  elseif mc == 5*128 then -- BCMuv\n    kc = funcuvname(func, d)\n  end\n  if ma == 5 then -- BCMuv\n    local ka = funcuvname(func, a)\n    if kc then kc = ka..\" ; \"..kc else kc = ka end\n  end\n  if mb ~= 0 then\n    local b = shr(ins, 24)\n    if kc then return format(\"%s%3d %3d  ; %s\\n\", s, b, d, kc) end\n    return format(\"%s%3d %3d\\n\", s, b, d)\n  end\n  if kc then return format(\"%s%3d      ; %s\\n\", s, d, kc) end\n  if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits\n  return format(\"%s%3d\\n\", s, d)\nend\n\n-- Collect branch targets of a function.\nlocal function bctargets(func)\n  local target = {}\n  for pc=1,1000000000 do\n    local ins, m = funcbc(func, pc)\n    if not ins then break end\n    if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end\n  end\n  return target\nend\n\n-- Dump bytecode instructions of a function.\nlocal function bcdump(func, out, all)\n  if not out then out = stdout end\n  local fi = funcinfo(func)\n  if all and fi.children then\n    for n=-1,-1000000000,-1 do\n      local k = funck(func, n)\n      if not k then break end\n      if type(k) == \"proto\" then bcdump(k, out, true) end\n    end\n  end\n  out:write(format(\"-- BYTECODE -- %s-%d\\n\", fi.loc, fi.lastlinedefined))\n  local target = bctargets(func)\n  for pc=1,1000000000 do\n    local s = bcline(func, pc, target[pc] and \"=>\")\n    if not s then break end\n    out:write(s)\n  end\n  out:write(\"\\n\")\n  out:flush()\nend\n\n------------------------------------------------------------------------------\n\n-- Active flag and output file handle.\nlocal active, out\n\n-- List handler.\nlocal function h_list(func)\n  return bcdump(func, out)\nend\n\n-- Detach list handler.\nlocal function bclistoff()\n  if active then\n    active = false\n    jit.attach(h_list)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach list handler.\nlocal function bcliston(outfile)\n  if active then bclistoff() end\n  if not outfile then outfile = os.getenv(\"LUAJIT_LISTFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stderr\n  end\n  jit.attach(h_list, \"bc\")\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  line = bcline,\n  dump = bcdump,\n  targets = bctargets,\n  on = bcliston,\n  off = bclistoff,\n  start = bcliston -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/bcsave.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT module to save/list bytecode.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module saves or lists the bytecode for an input file.\n-- It's run by the -b command line option.\n--\n------------------------------------------------------------------------------\n\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal bit = require(\"bit\")\n\n-- Symbol name prefix for LuaJIT bytecode.\nlocal LJBC_PREFIX = \"luaJIT_BC_\"\n\n------------------------------------------------------------------------------\n\nlocal function usage()\n  io.stderr:write[[\nSave LuaJIT bytecode: luajit -b[options] input output\n  -l        Only list bytecode.\n  -s        Strip debug info (default).\n  -g        Keep debug info.\n  -n name   Set module name (default: auto-detect from input name).\n  -t type   Set output file type (default: auto-detect from output name).\n  -a arch   Override architecture for object files (default: native).\n  -o os     Override OS for object files (default: native).\n  -e chunk  Use chunk string as input.\n  --        Stop handling options.\n  -         Use stdin as input and/or stdout as output.\n\nFile types: c h obj o raw (default)\n]]\n  os.exit(1)\nend\n\nlocal function check(ok, ...)\n  if ok then return ok, ... end\n  io.stderr:write(\"luajit: \", ...)\n  io.stderr:write(\"\\n\")\n  os.exit(1)\nend\n\nlocal function readfile(input)\n  if type(input) == \"function\" then return input end\n  if input == \"-\" then input = nil end\n  return check(loadfile(input))\nend\n\nlocal function savefile(name, mode)\n  if name == \"-\" then return io.stdout end\n  return check(io.open(name, mode))\nend\n\n------------------------------------------------------------------------------\n\nlocal map_type = {\n  raw = \"raw\", c = \"c\", h = \"h\", o = \"obj\", obj = \"obj\",\n}\n\nlocal map_arch = {\n  x86 = true, x64 = true, arm = true, arm64 = true, ppc = true,\n  mips = true, mipsel = true,\n}\n\nlocal map_os = {\n  linux = true, windows = true, osx = true, freebsd = true, netbsd = true,\n  openbsd = true, dragonfly = true, solaris = true,\n}\n\nlocal function checkarg(str, map, err)\n  str = string.lower(str)\n  local s = check(map[str], \"unknown \", err)\n  return s == true and str or s\nend\n\nlocal function detecttype(str)\n  local ext = string.match(string.lower(str), \"%.(%a+)$\")\n  return map_type[ext] or \"raw\"\nend\n\nlocal function checkmodname(str)\n  check(string.match(str, \"^[%w_.%-]+$\"), \"bad module name\")\n  return string.gsub(str, \"[%.%-]\", \"_\")\nend\n\nlocal function detectmodname(str)\n  if type(str) == \"string\" then\n    local tail = string.match(str, \"[^/\\\\]+$\")\n    if tail then str = tail end\n    local head = string.match(str, \"^(.*)%.[^.]*$\")\n    if head then str = head end\n    str = string.match(str, \"^[%w_.%-]+\")\n  else\n    str = nil\n  end\n  check(str, \"cannot derive module name, use -n name\")\n  return string.gsub(str, \"[%.%-]\", \"_\")\nend\n\n------------------------------------------------------------------------------\n\nlocal function bcsave_tail(fp, output, s)\n  local ok, err = fp:write(s)\n  if ok and output ~= \"-\" then ok, err = fp:close() end\n  check(ok, \"cannot write \", output, \": \", err)\nend\n\nlocal function bcsave_raw(output, s)\n  local fp = savefile(output, \"wb\")\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_c(ctx, output, s)\n  local fp = savefile(output, \"w\")\n  if ctx.type == \"c\" then\n    fp:write(string.format([[\n#ifdef _cplusplus\nextern \"C\"\n#endif\n#ifdef _WIN32\n__declspec(dllexport)\n#endif\nconst char %s%s[] = {\n]], LJBC_PREFIX, ctx.modname))\n  else\n    fp:write(string.format([[\n#define %s%s_SIZE %d\nstatic const char %s%s[] = {\n]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname))\n  end\n  local t, n, m = {}, 0, 0\n  for i=1,#s do\n    local b = tostring(string.byte(s, i))\n    m = m + #b + 1\n    if m > 78 then\n      fp:write(table.concat(t, \",\", 1, n), \",\\n\")\n      n, m = 0, #b + 1\n    end\n    n = n + 1\n    t[n] = b\n  end\n  bcsave_tail(fp, output, table.concat(t, \",\", 1, n)..\"\\n};\\n\")\nend\n\nlocal function bcsave_elfobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct {\n  uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];\n  uint16_t type, machine;\n  uint32_t version;\n  uint32_t entry, phofs, shofs;\n  uint32_t flags;\n  uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;\n} ELF32header;\ntypedef struct {\n  uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];\n  uint16_t type, machine;\n  uint32_t version;\n  uint64_t entry, phofs, shofs;\n  uint32_t flags;\n  uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;\n} ELF64header;\ntypedef struct {\n  uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize;\n} ELF32sectheader;\ntypedef struct {\n  uint32_t name, type;\n  uint64_t flags, addr, ofs, size;\n  uint32_t link, info;\n  uint64_t align, entsize;\n} ELF64sectheader;\ntypedef struct {\n  uint32_t name, value, size;\n  uint8_t info, other;\n  uint16_t sectidx;\n} ELF32symbol;\ntypedef struct {\n  uint32_t name;\n  uint8_t info, other;\n  uint16_t sectidx;\n  uint64_t value, size;\n} ELF64symbol;\ntypedef struct {\n  ELF32header hdr;\n  ELF32sectheader sect[6];\n  ELF32symbol sym[2];\n  uint8_t space[4096];\n} ELF32obj;\ntypedef struct {\n  ELF64header hdr;\n  ELF64sectheader sect[6];\n  ELF64symbol sym[2];\n  uint8_t space[4096];\n} ELF64obj;\n]]\n  local symname = LJBC_PREFIX..ctx.modname\n  local is64, isbe = false, false\n  if ctx.arch == \"x64\" or ctx.arch == \"arm64\" then\n    is64 = true\n  elseif ctx.arch == \"ppc\" or ctx.arch == \"mips\" then\n    isbe = true\n  end\n\n  -- Handle different host/target endianess.\n  local function f32(x) return x end\n  local f16, fofs = f32, f32\n  if ffi.abi(\"be\") ~= isbe then\n    f32 = bit.bswap\n    function f16(x) return bit.rshift(bit.bswap(x), 16) end\n    if is64 then\n      local two32 = ffi.cast(\"int64_t\", 2^32)\n      function fofs(x) return bit.bswap(x)*two32 end\n    else\n      fofs = f32\n    end\n  end\n\n  -- Create ELF object and fill in header.\n  local o = ffi.new(is64 and \"ELF64obj\" or \"ELF32obj\")\n  local hdr = o.hdr\n  if ctx.os == \"bsd\" or ctx.os == \"other\" then -- Determine native hdr.eosabi.\n    local bf = assert(io.open(\"/bin/ls\", \"rb\"))\n    local bs = bf:read(9)\n    bf:close()\n    ffi.copy(o, bs, 9)\n    check(hdr.emagic[0] == 127, \"no support for writing native object files\")\n  else\n    hdr.emagic = \"\\127ELF\"\n    hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0\n  end\n  hdr.eclass = is64 and 2 or 1\n  hdr.eendian = isbe and 2 or 1\n  hdr.eversion = 1\n  hdr.type = f16(1)\n  hdr.machine = f16(({ x86=3, x64=62, arm=40, arm64=183, ppc=20, mips=8, mipsel=8 })[ctx.arch])\n  if ctx.arch == \"mips\" or ctx.arch == \"mipsel\" then\n    hdr.flags = 0x50001006\n  end\n  hdr.version = f32(1)\n  hdr.shofs = fofs(ffi.offsetof(o, \"sect\"))\n  hdr.ehsize = f16(ffi.sizeof(hdr))\n  hdr.shentsize = f16(ffi.sizeof(o.sect[0]))\n  hdr.shnum = f16(6)\n  hdr.shstridx = f16(2)\n\n  -- Fill in sections and symbols.\n  local sofs, ofs = ffi.offsetof(o, \"space\"), 1\n  for i,name in ipairs{\n      \".symtab\", \".shstrtab\", \".strtab\", \".rodata\", \".note.GNU-stack\",\n    } do\n    local sect = o.sect[i]\n    sect.align = fofs(1)\n    sect.name = f32(ofs)\n    ffi.copy(o.space+ofs, name)\n    ofs = ofs + #name+1\n  end\n  o.sect[1].type = f32(2) -- .symtab\n  o.sect[1].link = f32(3)\n  o.sect[1].info = f32(1)\n  o.sect[1].align = fofs(8)\n  o.sect[1].ofs = fofs(ffi.offsetof(o, \"sym\"))\n  o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0]))\n  o.sect[1].size = fofs(ffi.sizeof(o.sym))\n  o.sym[1].name = f32(1)\n  o.sym[1].sectidx = f16(4)\n  o.sym[1].size = fofs(#s)\n  o.sym[1].info = 17\n  o.sect[2].type = f32(3) -- .shstrtab\n  o.sect[2].ofs = fofs(sofs)\n  o.sect[2].size = fofs(ofs)\n  o.sect[3].type = f32(3) -- .strtab\n  o.sect[3].ofs = fofs(sofs + ofs)\n  o.sect[3].size = fofs(#symname+1)\n  ffi.copy(o.space+ofs+1, symname)\n  ofs = ofs + #symname + 2\n  o.sect[4].type = f32(1) -- .rodata\n  o.sect[4].flags = fofs(2)\n  o.sect[4].ofs = fofs(sofs + ofs)\n  o.sect[4].size = fofs(#s)\n  o.sect[5].type = f32(1) -- .note.GNU-stack\n  o.sect[5].ofs = fofs(sofs + ofs + #s)\n\n  -- Write ELF object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_peobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct {\n  uint16_t arch, nsects;\n  uint32_t time, symtabofs, nsyms;\n  uint16_t opthdrsz, flags;\n} PEheader;\ntypedef struct {\n  char name[8];\n  uint32_t vsize, vaddr, size, ofs, relocofs, lineofs;\n  uint16_t nreloc, nline;\n  uint32_t flags;\n} PEsection;\ntypedef struct __attribute((packed)) {\n  union {\n    char name[8];\n    uint32_t nameref[2];\n  };\n  uint32_t value;\n  int16_t sect;\n  uint16_t type;\n  uint8_t scl, naux;\n} PEsym;\ntypedef struct __attribute((packed)) {\n  uint32_t size;\n  uint16_t nreloc, nline;\n  uint32_t cksum;\n  uint16_t assoc;\n  uint8_t comdatsel, unused[3];\n} PEsymaux;\ntypedef struct {\n  PEheader hdr;\n  PEsection sect[2];\n  // Must be an even number of symbol structs.\n  PEsym sym0;\n  PEsymaux sym0aux;\n  PEsym sym1;\n  PEsymaux sym1aux;\n  PEsym sym2;\n  PEsym sym3;\n  uint32_t strtabsize;\n  uint8_t space[4096];\n} PEobj;\n]]\n  local symname = LJBC_PREFIX..ctx.modname\n  local is64 = false\n  if ctx.arch == \"x86\" then\n    symname = \"_\"..symname\n  elseif ctx.arch == \"x64\" then\n    is64 = true\n  end\n  local symexport = \"   /EXPORT:\"..symname..\",DATA \"\n\n  -- The file format is always little-endian. Swap if the host is big-endian.\n  local function f32(x) return x end\n  local f16 = f32\n  if ffi.abi(\"be\") then\n    f32 = bit.bswap\n    function f16(x) return bit.rshift(bit.bswap(x), 16) end\n  end\n\n  -- Create PE object and fill in header.\n  local o = ffi.new(\"PEobj\")\n  local hdr = o.hdr\n  hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2, mips=0x366, mipsel=0x366 })[ctx.arch])\n  hdr.nsects = f16(2)\n  hdr.symtabofs = f32(ffi.offsetof(o, \"sym0\"))\n  hdr.nsyms = f32(6)\n\n  -- Fill in sections and symbols.\n  o.sect[0].name = \".drectve\"\n  o.sect[0].size = f32(#symexport)\n  o.sect[0].flags = f32(0x00100a00)\n  o.sym0.sect = f16(1)\n  o.sym0.scl = 3\n  o.sym0.name = \".drectve\"\n  o.sym0.naux = 1\n  o.sym0aux.size = f32(#symexport)\n  o.sect[1].name = \".rdata\"\n  o.sect[1].size = f32(#s)\n  o.sect[1].flags = f32(0x40300040)\n  o.sym1.sect = f16(2)\n  o.sym1.scl = 3\n  o.sym1.name = \".rdata\"\n  o.sym1.naux = 1\n  o.sym1aux.size = f32(#s)\n  o.sym2.sect = f16(2)\n  o.sym2.scl = 2\n  o.sym2.nameref[1] = f32(4)\n  o.sym3.sect = f16(-1)\n  o.sym3.scl = 2\n  o.sym3.value = f32(1)\n  o.sym3.name = \"@feat.00\" -- Mark as SafeSEH compliant.\n  ffi.copy(o.space, symname)\n  local ofs = #symname + 1\n  o.strtabsize = f32(ofs + 4)\n  o.sect[0].ofs = f32(ffi.offsetof(o, \"space\") + ofs)\n  ffi.copy(o.space + ofs, symexport)\n  ofs = ofs + #symexport\n  o.sect[1].ofs = f32(ffi.offsetof(o, \"space\") + ofs)\n\n  -- Write PE object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_machobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct\n{\n  uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags;\n} mach_header;\ntypedef struct\n{\n  mach_header; uint32_t reserved;\n} mach_header_64;\ntypedef struct {\n  uint32_t cmd, cmdsize;\n  char segname[16];\n  uint32_t vmaddr, vmsize, fileoff, filesize;\n  uint32_t maxprot, initprot, nsects, flags;\n} mach_segment_command;\ntypedef struct {\n  uint32_t cmd, cmdsize;\n  char segname[16];\n  uint64_t vmaddr, vmsize, fileoff, filesize;\n  uint32_t maxprot, initprot, nsects, flags;\n} mach_segment_command_64;\ntypedef struct {\n  char sectname[16], segname[16];\n  uint32_t addr, size;\n  uint32_t offset, align, reloff, nreloc, flags;\n  uint32_t reserved1, reserved2;\n} mach_section;\ntypedef struct {\n  char sectname[16], segname[16];\n  uint64_t addr, size;\n  uint32_t offset, align, reloff, nreloc, flags;\n  uint32_t reserved1, reserved2, reserved3;\n} mach_section_64;\ntypedef struct {\n  uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize;\n} mach_symtab_command;\ntypedef struct {\n  int32_t strx;\n  uint8_t type, sect;\n  int16_t desc;\n  uint32_t value;\n} mach_nlist;\ntypedef struct {\n  uint32_t strx;\n  uint8_t type, sect;\n  uint16_t desc;\n  uint64_t value;\n} mach_nlist_64;\ntypedef struct\n{\n  uint32_t magic, nfat_arch;\n} mach_fat_header;\ntypedef struct\n{\n  uint32_t cputype, cpusubtype, offset, size, align;\n} mach_fat_arch;\ntypedef struct {\n  struct {\n    mach_header hdr;\n    mach_segment_command seg;\n    mach_section sec;\n    mach_symtab_command sym;\n  } arch[1];\n  mach_nlist sym_entry;\n  uint8_t space[4096];\n} mach_obj;\ntypedef struct {\n  struct {\n    mach_header_64 hdr;\n    mach_segment_command_64 seg;\n    mach_section_64 sec;\n    mach_symtab_command sym;\n  } arch[1];\n  mach_nlist_64 sym_entry;\n  uint8_t space[4096];\n} mach_obj_64;\ntypedef struct {\n  mach_fat_header fat;\n  mach_fat_arch fat_arch[2];\n  struct {\n    mach_header hdr;\n    mach_segment_command seg;\n    mach_section sec;\n    mach_symtab_command sym;\n  } arch[2];\n  mach_nlist sym_entry;\n  uint8_t space[4096];\n} mach_fat_obj;\n]]\n  local symname = '_'..LJBC_PREFIX..ctx.modname\n  local isfat, is64, align, mobj = false, false, 4, \"mach_obj\"\n  if ctx.arch == \"x64\" then\n    is64, align, mobj = true, 8, \"mach_obj_64\"\n  elseif ctx.arch == \"arm\" then\n    isfat, mobj = true, \"mach_fat_obj\"\n  elseif ctx.arch == \"arm64\" then\n    is64, align, isfat, mobj = true, 8, true, \"mach_fat_obj\"\n  else\n    check(ctx.arch == \"x86\", \"unsupported architecture for OSX\")\n  end\n  local function aligned(v, a) return bit.band(v+a-1, -a) end\n  local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE.\n\n  -- Create Mach-O object and fill in header.\n  local o = ffi.new(mobj)\n  local mach_size = aligned(ffi.offsetof(o, \"space\")+#symname+2, align)\n  local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12}, arm64={0x01000007,0x0100000c} })[ctx.arch]\n  local cpusubtype = ({ x86={3}, x64={3}, arm={3,9}, arm64={3,0} })[ctx.arch]\n  if isfat then\n    o.fat.magic = be32(0xcafebabe)\n    o.fat.nfat_arch = be32(#cpusubtype)\n  end\n\n  -- Fill in sections and symbols.\n  for i=0,#cpusubtype-1 do\n    local ofs = 0\n    if isfat then\n      local a = o.fat_arch[i]\n      a.cputype = be32(cputype[i+1])\n      a.cpusubtype = be32(cpusubtype[i+1])\n      -- Subsequent slices overlap each other to share data.\n      ofs = ffi.offsetof(o, \"arch\") + i*ffi.sizeof(o.arch[0])\n      a.offset = be32(ofs)\n      a.size = be32(mach_size-ofs+#s)\n    end\n    local a = o.arch[i]\n    a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface\n    a.hdr.cputype = cputype[i+1]\n    a.hdr.cpusubtype = cpusubtype[i+1]\n    a.hdr.filetype = 1\n    a.hdr.ncmds = 2\n    a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym)\n    a.seg.cmd = is64 and 0x19 or 0x1\n    a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)\n    a.seg.vmsize = #s\n    a.seg.fileoff = mach_size-ofs\n    a.seg.filesize = #s\n    a.seg.maxprot = 1\n    a.seg.initprot = 1\n    a.seg.nsects = 1\n    ffi.copy(a.sec.sectname, \"__data\")\n    ffi.copy(a.sec.segname, \"__DATA\")\n    a.sec.size = #s\n    a.sec.offset = mach_size-ofs\n    a.sym.cmd = 2\n    a.sym.cmdsize = ffi.sizeof(a.sym)\n    a.sym.symoff = ffi.offsetof(o, \"sym_entry\")-ofs\n    a.sym.nsyms = 1\n    a.sym.stroff = ffi.offsetof(o, \"sym_entry\")+ffi.sizeof(o.sym_entry)-ofs\n    a.sym.strsize = aligned(#symname+2, align)\n  end\n  o.sym_entry.type = 0xf\n  o.sym_entry.sect = 1\n  o.sym_entry.strx = 1\n  ffi.copy(o.space+1, symname)\n\n  -- Write Macho-O object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, mach_size))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_obj(ctx, output, s)\n  local ok, ffi = pcall(require, \"ffi\")\n  check(ok, \"FFI library required to write this file type\")\n  if ctx.os == \"windows\" then\n    return bcsave_peobj(ctx, output, s, ffi)\n  elseif ctx.os == \"osx\" then\n    return bcsave_machobj(ctx, output, s, ffi)\n  else\n    return bcsave_elfobj(ctx, output, s, ffi)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal function bclist(input, output)\n  local f = readfile(input)\n  require(\"jit.bc\").dump(f, savefile(output, \"w\"), true)\nend\n\nlocal function bcsave(ctx, input, output)\n  local f = readfile(input)\n  local s = string.dump(f, ctx.strip)\n  local t = ctx.type\n  if not t then\n    t = detecttype(output)\n    ctx.type = t\n  end\n  if t == \"raw\" then\n    bcsave_raw(output, s)\n  else\n    if not ctx.modname then ctx.modname = detectmodname(input) end\n    if t == \"obj\" then\n      bcsave_obj(ctx, output, s)\n    else\n      bcsave_c(ctx, output, s)\n    end\n  end\nend\n\nlocal function docmd(...)\n  local arg = {...}\n  local n = 1\n  local list = false\n  local ctx = {\n    strip = true, arch = jit.arch, os = string.lower(jit.os),\n    type = false, modname = false,\n  }\n  while n <= #arg do\n    local a = arg[n]\n    if type(a) == \"string\" and string.sub(a, 1, 1) == \"-\" and a ~= \"-\" then\n      table.remove(arg, n)\n      if a == \"--\" then break end\n      for m=2,#a do\n\tlocal opt = string.sub(a, m, m)\n\tif opt == \"l\" then\n\t  list = true\n\telseif opt == \"s\" then\n\t  ctx.strip = true\n\telseif opt == \"g\" then\n\t  ctx.strip = false\n\telse\n\t  if arg[n] == nil or m ~= #a then usage() end\n\t  if opt == \"e\" then\n\t    if n ~= 1 then usage() end\n\t    arg[1] = check(loadstring(arg[1]))\n\t  elseif opt == \"n\" then\n\t    ctx.modname = checkmodname(table.remove(arg, n))\n\t  elseif opt == \"t\" then\n\t    ctx.type = checkarg(table.remove(arg, n), map_type, \"file type\")\n\t  elseif opt == \"a\" then\n\t    ctx.arch = checkarg(table.remove(arg, n), map_arch, \"architecture\")\n\t  elseif opt == \"o\" then\n\t    ctx.os = checkarg(table.remove(arg, n), map_os, \"OS name\")\n\t  else\n\t    usage()\n\t  end\n\tend\n      end\n    else\n      n = n + 1\n    end\n  end\n  if list then\n    if #arg == 0 or #arg > 2 then usage() end\n    bclist(arg[1], arg[2] or \"-\")\n  else\n    if #arg ~= 2 then usage() end\n    bcsave(ctx, arg[1], arg[2])\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Public module functions.\nreturn {\n  start = docmd -- Process -b command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_arm.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT ARM disassembler module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles most user-mode ARMv7 instructions\n-- NYI: Advanced SIMD and VFP instructions.\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, ror, tohex = bit.band, bit.bor, bit.ror, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Opcode maps\n------------------------------------------------------------------------------\n\nlocal map_loadc = {\n  shift = 8, mask = 15,\n  [10] = {\n    shift = 20, mask = 1,\n    [0] = {\n      shift = 23, mask = 3,\n      [0] = \"vmovFmDN\", \"vstmFNdr\",\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vstrFdl\",\n\t{ shift = 16, mask = 15, [13] = \"vpushFdr\", _ = \"vstmdbFNdr\", }\n      },\n    },\n    {\n      shift = 23, mask = 3,\n      [0] = \"vmovFDNm\",\n      { shift = 16, mask = 15, [13] = \"vpopFdr\", _ = \"vldmFNdr\", },\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vldrFdl\", \"vldmdbFNdr\",\n      },\n    },\n  },\n  [11] = {\n    shift = 20, mask = 1,\n    [0] = {\n      shift = 23, mask = 3,\n      [0] = \"vmovGmDN\", \"vstmGNdr\",\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vstrGdl\",\n\t{ shift = 16, mask = 15, [13] = \"vpushGdr\", _ = \"vstmdbGNdr\", }\n      },\n    },\n    {\n      shift = 23, mask = 3,\n      [0] = \"vmovGDNm\",\n      { shift = 16, mask = 15, [13] = \"vpopGdr\", _ = \"vldmGNdr\", },\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vldrGdl\", \"vldmdbGNdr\",\n      },\n    },\n  },\n  _ = {\n    shift = 0, mask = 0 -- NYI ldc, mcrr, mrrc.\n  },\n}\n\nlocal map_vfps = {\n  shift = 6, mask = 0x2c001,\n  [0] = \"vmlaF.dnm\", \"vmlsF.dnm\",\n  [0x04000] = \"vnmlsF.dnm\", [0x04001] = \"vnmlaF.dnm\",\n  [0x08000] = \"vmulF.dnm\", [0x08001] = \"vnmulF.dnm\",\n  [0x0c000] = \"vaddF.dnm\", [0x0c001] = \"vsubF.dnm\",\n  [0x20000] = \"vdivF.dnm\",\n  [0x24000] = \"vfnmsF.dnm\", [0x24001] = \"vfnmaF.dnm\",\n  [0x28000] = \"vfmaF.dnm\", [0x28001] = \"vfmsF.dnm\",\n  [0x2c000] = \"vmovF.dY\",\n  [0x2c001] = {\n    shift = 7, mask = 0x1e01,\n    [0] = \"vmovF.dm\", \"vabsF.dm\",\n    [0x0200] = \"vnegF.dm\", [0x0201] = \"vsqrtF.dm\",\n    [0x0800] = \"vcmpF.dm\", [0x0801] = \"vcmpeF.dm\",\n    [0x0a00] = \"vcmpzF.d\", [0x0a01] = \"vcmpzeF.d\",\n    [0x0e01] = \"vcvtG.dF.m\",\n    [0x1000] = \"vcvt.f32.u32Fdm\", [0x1001] = \"vcvt.f32.s32Fdm\",\n    [0x1800] = \"vcvtr.u32F.dm\", [0x1801] = \"vcvt.u32F.dm\",\n    [0x1a00] = \"vcvtr.s32F.dm\", [0x1a01] = \"vcvt.s32F.dm\",\n  },\n}\n\nlocal map_vfpd = {\n  shift = 6, mask = 0x2c001,\n  [0] = \"vmlaG.dnm\", \"vmlsG.dnm\",\n  [0x04000] = \"vnmlsG.dnm\", [0x04001] = \"vnmlaG.dnm\",\n  [0x08000] = \"vmulG.dnm\", [0x08001] = \"vnmulG.dnm\",\n  [0x0c000] = \"vaddG.dnm\", [0x0c001] = \"vsubG.dnm\",\n  [0x20000] = \"vdivG.dnm\",\n  [0x24000] = \"vfnmsG.dnm\", [0x24001] = \"vfnmaG.dnm\",\n  [0x28000] = \"vfmaG.dnm\", [0x28001] = \"vfmsG.dnm\",\n  [0x2c000] = \"vmovG.dY\",\n  [0x2c001] = {\n    shift = 7, mask = 0x1e01,\n    [0] = \"vmovG.dm\", \"vabsG.dm\",\n    [0x0200] = \"vnegG.dm\", [0x0201] = \"vsqrtG.dm\",\n    [0x0800] = \"vcmpG.dm\", [0x0801] = \"vcmpeG.dm\",\n    [0x0a00] = \"vcmpzG.d\", [0x0a01] = \"vcmpzeG.d\",\n    [0x0e01] = \"vcvtF.dG.m\",\n    [0x1000] = \"vcvt.f64.u32GdFm\", [0x1001] = \"vcvt.f64.s32GdFm\",\n    [0x1800] = \"vcvtr.u32FdG.m\", [0x1801] = \"vcvt.u32FdG.m\",\n    [0x1a00] = \"vcvtr.s32FdG.m\", [0x1a01] = \"vcvt.s32FdG.m\",\n  },\n}\n\nlocal map_datac = {\n  shift = 24, mask = 1,\n  [0] = {\n    shift = 4, mask = 1,\n    [0] = {\n      shift = 8, mask = 15,\n      [10] = map_vfps,\n      [11] = map_vfpd,\n      -- NYI cdp, mcr, mrc.\n    },\n    {\n      shift = 8, mask = 15,\n      [10] = {\n\tshift = 20, mask = 15,\n\t[0] = \"vmovFnD\", \"vmovFDn\",\n\t[14] = \"vmsrD\",\n\t[15] = { shift = 12, mask = 15, [15] = \"vmrs\", _ = \"vmrsD\", },\n      },\n    },\n  },\n  \"svcT\",\n}\n\nlocal map_loadcu = {\n  shift = 0, mask = 0, -- NYI unconditional CP load/store.\n}\n\nlocal map_datacu = {\n  shift = 0, mask = 0, -- NYI unconditional CP data.\n}\n\nlocal map_simddata = {\n  shift = 0, mask = 0, -- NYI SIMD data.\n}\n\nlocal map_simdload = {\n  shift = 0, mask = 0, -- NYI SIMD load/store, preload.\n}\n\nlocal map_preload = {\n  shift = 0, mask = 0, -- NYI preload.\n}\n\nlocal map_media = {\n  shift = 20, mask = 31,\n  [0] = false,\n  { --01\n    shift = 5, mask = 7,\n    [0] = \"sadd16DNM\", \"sasxDNM\", \"ssaxDNM\", \"ssub16DNM\",\n    \"sadd8DNM\", false, false, \"ssub8DNM\",\n  },\n  { --02\n    shift = 5, mask = 7,\n    [0] = \"qadd16DNM\", \"qasxDNM\", \"qsaxDNM\", \"qsub16DNM\",\n    \"qadd8DNM\", false, false, \"qsub8DNM\",\n  },\n  { --03\n    shift = 5, mask = 7,\n    [0] = \"shadd16DNM\", \"shasxDNM\", \"shsaxDNM\", \"shsub16DNM\",\n    \"shadd8DNM\", false, false, \"shsub8DNM\",\n  },\n  false,\n  { --05\n    shift = 5, mask = 7,\n    [0] = \"uadd16DNM\", \"uasxDNM\", \"usaxDNM\", \"usub16DNM\",\n    \"uadd8DNM\", false, false, \"usub8DNM\",\n  },\n  { --06\n    shift = 5, mask = 7,\n    [0] = \"uqadd16DNM\", \"uqasxDNM\", \"uqsaxDNM\", \"uqsub16DNM\",\n    \"uqadd8DNM\", false, false, \"uqsub8DNM\",\n  },\n  { --07\n    shift = 5, mask = 7,\n    [0] = \"uhadd16DNM\", \"uhasxDNM\", \"uhsaxDNM\", \"uhsub16DNM\",\n    \"uhadd8DNM\", false, false, \"uhsub8DNM\",\n  },\n  { --08\n    shift = 5, mask = 7,\n    [0] = \"pkhbtDNMU\", false, \"pkhtbDNMU\",\n    { shift = 16, mask = 15, [15] = \"sxtb16DMU\", _ = \"sxtab16DNMU\", },\n    \"pkhbtDNMU\", \"selDNM\", \"pkhtbDNMU\",\n  },\n  false,\n  { --0a\n    shift = 5, mask = 7,\n    [0] = \"ssatDxMu\", \"ssat16DxM\", \"ssatDxMu\",\n    { shift = 16, mask = 15, [15] = \"sxtbDMU\", _ = \"sxtabDNMU\", },\n    \"ssatDxMu\", false, \"ssatDxMu\",\n  },\n  { --0b\n    shift = 5, mask = 7,\n    [0] = \"ssatDxMu\", \"revDM\", \"ssatDxMu\",\n    { shift = 16, mask = 15, [15] = \"sxthDMU\", _ = \"sxtahDNMU\", },\n    \"ssatDxMu\", \"rev16DM\", \"ssatDxMu\",\n  },\n  { --0c\n    shift = 5, mask = 7,\n    [3] = { shift = 16, mask = 15, [15] = \"uxtb16DMU\", _ = \"uxtab16DNMU\", },\n  },\n  false,\n  { --0e\n    shift = 5, mask = 7,\n    [0] = \"usatDwMu\", \"usat16DwM\", \"usatDwMu\",\n    { shift = 16, mask = 15, [15] = \"uxtbDMU\", _ = \"uxtabDNMU\", },\n    \"usatDwMu\", false, \"usatDwMu\",\n  },\n  { --0f\n    shift = 5, mask = 7,\n    [0] = \"usatDwMu\", \"rbitDM\", \"usatDwMu\",\n    { shift = 16, mask = 15, [15] = \"uxthDMU\", _ = \"uxtahDNMU\", },\n    \"usatDwMu\", \"revshDM\", \"usatDwMu\",\n  },\n  { --10\n    shift = 12, mask = 15,\n    [15] = {\n      shift = 5, mask = 7,\n      \"smuadNMS\", \"smuadxNMS\", \"smusdNMS\", \"smusdxNMS\",\n    },\n    _ = {\n      shift = 5, mask = 7,\n      [0] = \"smladNMSD\", \"smladxNMSD\", \"smlsdNMSD\", \"smlsdxNMSD\",\n    },\n  },\n  false, false, false,\n  { --14\n    shift = 5, mask = 7,\n    [0] = \"smlaldDNMS\", \"smlaldxDNMS\", \"smlsldDNMS\", \"smlsldxDNMS\",\n  },\n  { --15\n    shift = 5, mask = 7,\n    [0] = { shift = 12, mask = 15, [15] = \"smmulNMS\", _ = \"smmlaNMSD\", },\n    { shift = 12, mask = 15, [15] = \"smmulrNMS\", _ = \"smmlarNMSD\", },\n    false, false, false, false,\n    \"smmlsNMSD\", \"smmlsrNMSD\",\n  },\n  false, false,\n  { --18\n    shift = 5, mask = 7,\n    [0] = { shift = 12, mask = 15, [15] = \"usad8NMS\", _ = \"usada8NMSD\", },\n  },\n  false,\n  { --1a\n    shift = 5, mask = 3, [2] = \"sbfxDMvw\",\n  },\n  { --1b\n    shift = 5, mask = 3, [2] = \"sbfxDMvw\",\n  },\n  { --1c\n    shift = 5, mask = 3,\n    [0] = { shift = 0, mask = 15, [15] = \"bfcDvX\", _ = \"bfiDMvX\", },\n  },\n  { --1d\n    shift = 5, mask = 3,\n    [0] = { shift = 0, mask = 15, [15] = \"bfcDvX\", _ = \"bfiDMvX\", },\n  },\n  { --1e\n    shift = 5, mask = 3, [2] = \"ubfxDMvw\",\n  },\n  { --1f\n    shift = 5, mask = 3, [2] = \"ubfxDMvw\",\n  },\n}\n\nlocal map_load = {\n  shift = 21, mask = 9,\n  {\n    shift = 20, mask = 5,\n    [0] = \"strtDL\", \"ldrtDL\", [4] = \"strbtDL\", [5] = \"ldrbtDL\",\n  },\n  _ = {\n    shift = 20, mask = 5,\n    [0] = \"strDL\", \"ldrDL\", [4] = \"strbDL\", [5] = \"ldrbDL\",\n  }\n}\n\nlocal map_load1 = {\n  shift = 4, mask = 1,\n  [0] = map_load, map_media,\n}\n\nlocal map_loadm = {\n  shift = 20, mask = 1,\n  [0] = {\n    shift = 23, mask = 3,\n    [0] = \"stmdaNR\", \"stmNR\",\n    { shift = 16, mask = 63, [45] = \"pushR\", _ = \"stmdbNR\", }, \"stmibNR\",\n  },\n  {\n    shift = 23, mask = 3,\n    [0] = \"ldmdaNR\", { shift = 16, mask = 63, [61] = \"popR\", _ = \"ldmNR\", },\n    \"ldmdbNR\", \"ldmibNR\",\n  },\n}\n\nlocal map_data = {\n  shift = 21, mask = 15,\n  [0] = \"andDNPs\", \"eorDNPs\", \"subDNPs\", \"rsbDNPs\",\n  \"addDNPs\", \"adcDNPs\", \"sbcDNPs\", \"rscDNPs\",\n  \"tstNP\", \"teqNP\", \"cmpNP\", \"cmnNP\",\n  \"orrDNPs\", \"movDPs\", \"bicDNPs\", \"mvnDPs\",\n}\n\nlocal map_mul = {\n  shift = 21, mask = 7,\n  [0] = \"mulNMSs\", \"mlaNMSDs\", \"umaalDNMS\", \"mlsDNMS\",\n  \"umullDNMSs\", \"umlalDNMSs\", \"smullDNMSs\", \"smlalDNMSs\",\n}\n\nlocal map_sync = {\n  shift = 20, mask = 15, -- NYI: brackets around N. R(D+1) for ldrexd/strexd.\n  [0] = \"swpDMN\", false, false, false,\n  \"swpbDMN\", false, false, false,\n  \"strexDMN\", \"ldrexDN\", \"strexdDN\", \"ldrexdDN\",\n  \"strexbDMN\", \"ldrexbDN\", \"strexhDN\", \"ldrexhDN\",\n}\n\nlocal map_mulh = {\n  shift = 21, mask = 3,\n  [0] = { shift = 5, mask = 3,\n    [0] = \"smlabbNMSD\", \"smlatbNMSD\", \"smlabtNMSD\", \"smlattNMSD\", },\n  { shift = 5, mask = 3,\n    [0] = \"smlawbNMSD\", \"smulwbNMS\", \"smlawtNMSD\", \"smulwtNMS\", },\n  { shift = 5, mask = 3,\n    [0] = \"smlalbbDNMS\", \"smlaltbDNMS\", \"smlalbtDNMS\", \"smlalttDNMS\", },\n  { shift = 5, mask = 3,\n    [0] = \"smulbbNMS\", \"smultbNMS\", \"smulbtNMS\", \"smulttNMS\", },\n}\n\nlocal map_misc = {\n  shift = 4, mask = 7,\n  -- NYI: decode PSR bits of msr.\n  [0] = { shift = 21, mask = 1, [0] = \"mrsD\", \"msrM\", },\n  { shift = 21, mask = 3, \"bxM\", false, \"clzDM\", },\n  { shift = 21, mask = 3, \"bxjM\", },\n  { shift = 21, mask = 3, \"blxM\", },\n  false,\n  { shift = 21, mask = 3, [0] = \"qaddDMN\", \"qsubDMN\", \"qdaddDMN\", \"qdsubDMN\", },\n  false,\n  { shift = 21, mask = 3, \"bkptK\", },\n}\n\nlocal map_datar = {\n  shift = 4, mask = 9,\n  [9] = {\n    shift = 5, mask = 3,\n    [0] = { shift = 24, mask = 1, [0] = map_mul, map_sync, },\n    { shift = 20, mask = 1, [0] = \"strhDL\", \"ldrhDL\", },\n    { shift = 20, mask = 1, [0] = \"ldrdDL\", \"ldrsbDL\", },\n    { shift = 20, mask = 1, [0] = \"strdDL\", \"ldrshDL\", },\n  },\n  _ = {\n    shift = 20, mask = 25,\n    [16] = { shift = 7, mask = 1, [0] = map_misc, map_mulh, },\n    _ = {\n      shift = 0, mask = 0xffffffff,\n      [bor(0xe1a00000)] = \"nop\",\n      _ = map_data,\n    }\n  },\n}\n\nlocal map_datai = {\n  shift = 20, mask = 31, -- NYI: decode PSR bits of msr. Decode imm12.\n  [16] = \"movwDW\", [20] = \"movtDW\",\n  [18] = { shift = 0, mask = 0xf00ff, [0] = \"nopv6\", _ = \"msrNW\", },\n  [22] = \"msrNW\",\n  _ = map_data,\n}\n\nlocal map_branch = {\n  shift = 24, mask = 1,\n  [0] = \"bB\", \"blB\"\n}\n\nlocal map_condins = {\n  [0] = map_datar, map_datai, map_load, map_load1,\n  map_loadm, map_branch, map_loadc, map_datac\n}\n\n-- NYI: setend.\nlocal map_uncondins = {\n  [0] = false, map_simddata, map_simdload, map_preload,\n  false, \"blxB\", map_loadcu, map_datacu,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"r1\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"sp\", \"lr\", \"pc\",\n}\n\nlocal map_cond = {\n  [0] = \"eq\", \"ne\", \"hs\", \"lo\", \"mi\", \"pl\", \"vs\", \"vc\",\n  \"hi\", \"ls\", \"ge\", \"lt\", \"gt\", \"le\", \"al\",\n}\n\nlocal map_shift = { [0] = \"lsl\", \"lsr\", \"asr\", \"ror\", }\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then\n      extra = \"\\t->\"..sym\n    elseif band(ctx.op, 0x0e000000) ~= 0x0a000000 then\n      extra = \"\\t; 0x\"..tohex(ctx.rel)\n    end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-5s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-5s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\n-- Format operand 2 of load/store opcodes.\nlocal function fmtload(ctx, op, pos)\n  local base = map_gpr[band(rshift(op, 16), 15)]\n  local x, ofs\n  local ext = (band(op, 0x04000000) == 0)\n  if not ext and band(op, 0x02000000) == 0 then\n    ofs = band(op, 4095)\n    if band(op, 0x00800000) == 0 then ofs = -ofs end\n    if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n    ofs = \"#\"..ofs\n  elseif ext and band(op, 0x00400000) ~= 0 then\n    ofs = band(op, 15) + band(rshift(op, 4), 0xf0)\n    if band(op, 0x00800000) == 0 then ofs = -ofs end\n    if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n    ofs = \"#\"..ofs\n  else\n    ofs = map_gpr[band(op, 15)]\n    if ext or band(op, 0xfe0) == 0 then\n    elseif band(op, 0xfe0) == 0x60 then\n      ofs = format(\"%s, rrx\", ofs)\n    else\n      local sh = band(rshift(op, 7), 31)\n      if sh == 0 then sh = 32 end\n      ofs = format(\"%s, %s #%d\", ofs, map_shift[band(rshift(op, 5), 3)], sh)\n    end\n    if band(op, 0x00800000) == 0 then ofs = \"-\"..ofs end\n  end\n  if ofs == \"#0\" then\n    x = format(\"[%s]\", base)\n  elseif band(op, 0x01000000) == 0 then\n    x = format(\"[%s], %s\", base, ofs)\n  else\n    x = format(\"[%s, %s]\", base, ofs)\n  end\n  if band(op, 0x01200000) == 0x01200000 then x = x..\"!\" end\n  return x\nend\n\n-- Format operand 2 of vector load/store opcodes.\nlocal function fmtvload(ctx, op, pos)\n  local base = map_gpr[band(rshift(op, 16), 15)]\n  local ofs = band(op, 255)*4\n  if band(op, 0x00800000) == 0 then ofs = -ofs end\n  if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n  if ofs == 0 then\n    return format(\"[%s]\", base)\n  else\n    return format(\"[%s, #%d]\", base, ofs)\n  end\nend\n\nlocal function fmtvr(op, vr, sh0, sh1)\n  if vr == \"s\" then\n    return format(\"s%d\", 2*band(rshift(op, sh0), 15)+band(rshift(op, sh1), 1))\n  else\n    return format(\"d%d\", band(rshift(op, sh0), 15)+band(rshift(op, sh1-4), 16))\n  end\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)\n  local operands = {}\n  local suffix = \"\"\n  local last, name, pat\n  local vr\n  ctx.op = op\n  ctx.rel = nil\n\n  local cond = rshift(op, 28)\n  local opat\n  if cond == 15 then\n    opat = map_uncondins[band(rshift(op, 25), 7)]\n  else\n    if cond ~= 14 then suffix = map_cond[cond] end\n    opat = map_condins[band(rshift(op, 25), 7)]\n  end\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._\n  end\n  name, pat = match(opat, \"^([a-z0-9]*)(.*)\")\n  if sub(pat, 1, 1) == \".\" then\n    local s2, p2 = match(pat, \"^([a-z0-9.]*)(.*)\")\n    suffix = suffix..s2\n    pat = p2\n  end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"D\" then\n      x = map_gpr[band(rshift(op, 12), 15)]\n    elseif p == \"N\" then\n      x = map_gpr[band(rshift(op, 16), 15)]\n    elseif p == \"S\" then\n      x = map_gpr[band(rshift(op, 8), 15)]\n    elseif p == \"M\" then\n      x = map_gpr[band(op, 15)]\n    elseif p == \"d\" then\n      x = fmtvr(op, vr, 12, 22)\n    elseif p == \"n\" then\n      x = fmtvr(op, vr, 16, 7)\n    elseif p == \"m\" then\n      x = fmtvr(op, vr, 0, 5)\n    elseif p == \"P\" then\n      if band(op, 0x02000000) ~= 0 then\n\tx = ror(band(op, 255), 2*band(rshift(op, 8), 15))\n      else\n\tx = map_gpr[band(op, 15)]\n\tif band(op, 0xff0) ~= 0 then\n\t  operands[#operands+1] = x\n\t  local s = map_shift[band(rshift(op, 5), 3)]\n\t  local r = nil\n\t  if band(op, 0xf90) == 0 then\n\t    if s == \"ror\" then s = \"rrx\" else r = \"#32\" end\n\t  elseif band(op, 0x10) == 0 then\n\t    r = \"#\"..band(rshift(op, 7), 31)\n\t  else\n\t    r = map_gpr[band(rshift(op, 8), 15)]\n\t  end\n\t  if name == \"mov\" then name = s; x = r\n\t  elseif r then x = format(\"%s %s\", s, r)\n\t  else x = s end\n\tend\n      end\n    elseif p == \"L\" then\n      x = fmtload(ctx, op, pos)\n    elseif p == \"l\" then\n      x = fmtvload(ctx, op, pos)\n    elseif p == \"B\" then\n      local addr = ctx.addr + pos + 8 + arshift(lshift(op, 8), 6)\n      if cond == 15 then addr = addr + band(rshift(op, 23), 2) end\n      ctx.rel = addr\n      x = \"0x\"..tohex(addr)\n    elseif p == \"F\" then\n      vr = \"s\"\n    elseif p == \"G\" then\n      vr = \"d\"\n    elseif p == \".\" then\n      suffix = suffix..(vr == \"s\" and \".f32\" or \".f64\")\n    elseif p == \"R\" then\n      if band(op, 0x00200000) ~= 0 and #operands == 1 then\n\toperands[1] = operands[1]..\"!\"\n      end\n      local t = {}\n      for i=0,15 do\n\tif band(rshift(op, i), 1) == 1 then t[#t+1] = map_gpr[i] end\n      end\n      x = \"{\"..concat(t, \", \")..\"}\"\n    elseif p == \"r\" then\n      if band(op, 0x00200000) ~= 0 and #operands == 2 then\n\toperands[1] = operands[1]..\"!\"\n      end\n      local s = tonumber(sub(last, 2))\n      local n = band(op, 255)\n      if vr == \"d\" then n = rshift(n, 1) end\n      operands[#operands] = format(\"{%s-%s%d}\", last, vr, s+n-1)\n    elseif p == \"W\" then\n      x = band(op, 0x0fff) + band(rshift(op, 4), 0xf000)\n    elseif p == \"T\" then\n      x = \"#0x\"..tohex(band(op, 0x00ffffff), 6)\n    elseif p == \"U\" then\n      x = band(rshift(op, 7), 31)\n      if x == 0 then x = nil end\n    elseif p == \"u\" then\n      x = band(rshift(op, 7), 31)\n      if band(op, 0x40) == 0 then\n\tif x == 0 then x = nil else x = \"lsl #\"..x end\n      else\n\tif x == 0 then x = \"asr #32\" else x = \"asr #\"..x end\n      end\n    elseif p == \"v\" then\n      x = band(rshift(op, 7), 31)\n    elseif p == \"w\" then\n      x = band(rshift(op, 16), 31)\n    elseif p == \"x\" then\n      x = band(rshift(op, 16), 31) + 1\n    elseif p == \"X\" then\n      x = band(rshift(op, 16), 31) - last + 1\n    elseif p == \"Y\" then\n      x = band(rshift(op, 12), 0xf0) + band(op, 0x0f)\n    elseif p == \"K\" then\n      x = \"#0x\"..tohex(band(rshift(op, 4), 0x0000fff0) + band(op, 15), 4)\n    elseif p == \"s\" then\n      if band(op, 0x00100000) ~= 0 then suffix = \"s\"..suffix end\n    else\n      assert(false)\n    end\n    if x then\n      last = x\n      if type(x) == \"number\" then x = \"#\"..x end\n      operands[#operands+1] = x\n    end\n  end\n\n  return putop(ctx, name..suffix, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  ctx.pos = ofs\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 16 then return map_gpr[r] end\n  return \"d\"..(r-16)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  disass = disass,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_mips.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS disassembler module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT/X license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles all standard MIPS32R1/R2 instructions.\n-- Default mode is big-endian, but see: dis_mipsel.lua\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, tohex = bit.band, bit.bor, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Primary and extended opcode maps\n------------------------------------------------------------------------------\n\nlocal map_movci = { shift = 16, mask = 1, [0] = \"movfDSC\", \"movtDSC\", }\nlocal map_srl = { shift = 21, mask = 1, [0] = \"srlDTA\", \"rotrDTA\", }\nlocal map_srlv = { shift = 6, mask = 1, [0] = \"srlvDTS\", \"rotrvDTS\", }\n\nlocal map_special = {\n  shift = 0, mask = 63,\n  [0] = { shift = 0, mask = -1, [0] = \"nop\", _ = \"sllDTA\" },\n  map_movci,\tmap_srl,\t\"sraDTA\",\n  \"sllvDTS\",\tfalse,\t\tmap_srlv,\t\"sravDTS\",\n  \"jrS\",\t\"jalrD1S\",\t\"movzDST\",\t\"movnDST\",\n  \"syscallY\",\t\"breakY\",\tfalse,\t\t\"sync\",\n  \"mfhiD\",\t\"mthiS\",\t\"mfloD\",\t\"mtloS\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"multST\",\t\"multuST\",\t\"divST\",\t\"divuST\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"addDST\",\t\"addu|moveDST0\", \"subDST\",\t\"subu|neguDS0T\",\n  \"andDST\",\t\"orDST\",\t\"xorDST\",\t\"nor|notDST0\",\n  false,\tfalse,\t\t\"sltDST\",\t\"sltuDST\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"tgeSTZ\",\t\"tgeuSTZ\",\t\"tltSTZ\",\t\"tltuSTZ\",\n  \"teqSTZ\",\tfalse,\t\t\"tneSTZ\",\n}\n\nlocal map_special2 = {\n  shift = 0, mask = 63,\n  [0] = \"maddST\", \"madduST\",\t\"mulDST\",\tfalse,\n  \"msubST\",\t\"msubuST\",\n  [32] = \"clzDS\", [33] = \"cloDS\",\n  [63] = \"sdbbpY\",\n}\n\nlocal map_bshfl = {\n  shift = 6, mask = 31,\n  [2] = \"wsbhDT\",\n  [16] = \"sebDT\",\n  [24] = \"sehDT\",\n}\n\nlocal map_special3 = {\n  shift = 0, mask = 63,\n  [0] = \"extTSAK\", [4] = \"insTSAL\",\n  [32] = map_bshfl,\n  [59] = \"rdhwrTD\",\n}\n\nlocal map_regimm = {\n  shift = 16, mask = 31,\n  [0] = \"bltzSB\",\t\"bgezSB\",\t\"bltzlSB\",\t\"bgezlSB\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"tgeiSI\",\t\"tgeiuSI\",\t\"tltiSI\",\t\"tltiuSI\",\n  \"teqiSI\",\tfalse,\t\t\"tneiSI\",\tfalse,\n  \"bltzalSB\",\t\"bgezalSB\",\t\"bltzallSB\",\t\"bgezallSB\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\t\"synciSO\",\n}\n\nlocal map_cop0 = {\n  shift = 25, mask = 1,\n  [0] = {\n    shift = 21, mask = 15,\n    [0] = \"mfc0TDW\", [4] = \"mtc0TDW\",\n    [10] = \"rdpgprDT\",\n    [11] = { shift = 5, mask = 1, [0] = \"diT0\", \"eiT0\", },\n    [14] = \"wrpgprDT\",\n  }, {\n    shift = 0, mask = 63,\n    [1] = \"tlbr\", [2] = \"tlbwi\", [6] = \"tlbwr\", [8] = \"tlbp\",\n    [24] = \"eret\", [31] = \"deret\",\n    [32] = \"wait\",\n  },\n}\n\nlocal map_cop1s = {\n  shift = 0, mask = 63,\n  [0] = \"add.sFGH\",\t\"sub.sFGH\",\t\"mul.sFGH\",\t\"div.sFGH\",\n  \"sqrt.sFG\",\t\t\"abs.sFG\",\t\"mov.sFG\",\t\"neg.sFG\",\n  \"round.l.sFG\",\t\"trunc.l.sFG\",\t\"ceil.l.sFG\",\t\"floor.l.sFG\",\n  \"round.w.sFG\",\t\"trunc.w.sFG\",\t\"ceil.w.sFG\",\t\"floor.w.sFG\",\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.sFGC\", \"movt.sFGC\" },\n  \"movz.sFGT\",\t\"movn.sFGT\",\n  false,\t\"recip.sFG\",\t\"rsqrt.sFG\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\"cvt.d.sFG\",\tfalse,\t\tfalse,\n  \"cvt.w.sFG\",\t\"cvt.l.sFG\",\t\"cvt.ps.sFGH\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"c.f.sVGH\",\t\"c.un.sVGH\",\t\"c.eq.sVGH\",\t\"c.ueq.sVGH\",\n  \"c.olt.sVGH\",\t\"c.ult.sVGH\",\t\"c.ole.sVGH\",\t\"c.ule.sVGH\",\n  \"c.sf.sVGH\",\t\"c.ngle.sVGH\",\t\"c.seq.sVGH\",\t\"c.ngl.sVGH\",\n  \"c.lt.sVGH\",\t\"c.nge.sVGH\",\t\"c.le.sVGH\",\t\"c.ngt.sVGH\",\n}\n\nlocal map_cop1d = {\n  shift = 0, mask = 63,\n  [0] = \"add.dFGH\",\t\"sub.dFGH\",\t\"mul.dFGH\",\t\"div.dFGH\",\n  \"sqrt.dFG\",\t\t\"abs.dFG\",\t\"mov.dFG\",\t\"neg.dFG\",\n  \"round.l.dFG\",\t\"trunc.l.dFG\",\t\"ceil.l.dFG\",\t\"floor.l.dFG\",\n  \"round.w.dFG\",\t\"trunc.w.dFG\",\t\"ceil.w.dFG\",\t\"floor.w.dFG\",\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.dFGC\", \"movt.dFGC\" },\n  \"movz.dFGT\",\t\"movn.dFGT\",\n  false,\t\"recip.dFG\",\t\"rsqrt.dFG\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.dFG\",\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.w.dFG\",\t\"cvt.l.dFG\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"c.f.dVGH\",\t\"c.un.dVGH\",\t\"c.eq.dVGH\",\t\"c.ueq.dVGH\",\n  \"c.olt.dVGH\",\t\"c.ult.dVGH\",\t\"c.ole.dVGH\",\t\"c.ule.dVGH\",\n  \"c.df.dVGH\",\t\"c.ngle.dVGH\",\t\"c.deq.dVGH\",\t\"c.ngl.dVGH\",\n  \"c.lt.dVGH\",\t\"c.nge.dVGH\",\t\"c.le.dVGH\",\t\"c.ngt.dVGH\",\n}\n\nlocal map_cop1ps = {\n  shift = 0, mask = 63,\n  [0] = \"add.psFGH\",\t\"sub.psFGH\",\t\"mul.psFGH\",\tfalse,\n  false,\t\t\"abs.psFG\",\t\"mov.psFG\",\t\"neg.psFG\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.psFGC\", \"movt.psFGC\" },\n  \"movz.psFGT\",\t\"movn.psFGT\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.puFG\",\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.plFG\",\tfalse,\t\tfalse,\t\tfalse,\n  \"pll.psFGH\",\t\"plu.psFGH\",\t\"pul.psFGH\",\t\"puu.psFGH\",\n  \"c.f.psVGH\",\t\"c.un.psVGH\",\t\"c.eq.psVGH\",\t\"c.ueq.psVGH\",\n  \"c.olt.psVGH\", \"c.ult.psVGH\",\t\"c.ole.psVGH\",\t\"c.ule.psVGH\",\n  \"c.psf.psVGH\", \"c.ngle.psVGH\", \"c.pseq.psVGH\", \"c.ngl.psVGH\",\n  \"c.lt.psVGH\",\t\"c.nge.psVGH\",\t\"c.le.psVGH\",\t\"c.ngt.psVGH\",\n}\n\nlocal map_cop1w = {\n  shift = 0, mask = 63,\n  [32] = \"cvt.s.wFG\", [33] = \"cvt.d.wFG\",\n}\n\nlocal map_cop1l = {\n  shift = 0, mask = 63,\n  [32] = \"cvt.s.lFG\", [33] = \"cvt.d.lFG\",\n}\n\nlocal map_cop1bc = {\n  shift = 16, mask = 3,\n  [0] = \"bc1fCB\", \"bc1tCB\",\t\"bc1flCB\",\t\"bc1tlCB\",\n}\n\nlocal map_cop1 = {\n  shift = 21, mask = 31,\n  [0] = \"mfc1TG\", false,\t\"cfc1TG\",\t\"mfhc1TG\",\n  \"mtc1TG\",\tfalse,\t\t\"ctc1TG\",\t\"mthc1TG\",\n  map_cop1bc,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  map_cop1s,\tmap_cop1d,\tfalse,\t\tfalse,\n  map_cop1w,\tmap_cop1l,\tmap_cop1ps,\n}\n\nlocal map_cop1x = {\n  shift = 0, mask = 63,\n  [0] = \"lwxc1FSX\",\t\"ldxc1FSX\",\tfalse,\t\tfalse,\n  false,\t\"luxc1FSX\",\tfalse,\t\tfalse,\n  \"swxc1FSX\",\t\"sdxc1FSX\",\tfalse,\t\tfalse,\n  false,\t\"suxc1FSX\",\tfalse,\t\t\"prefxMSX\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"alnv.psFGHS\",\tfalse,\n  \"madd.sFRGH\",\t\"madd.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"madd.psFRGH\",\tfalse,\n  \"msub.sFRGH\",\t\"msub.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"msub.psFRGH\",\tfalse,\n  \"nmadd.sFRGH\", \"nmadd.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"nmadd.psFRGH\",\tfalse,\n  \"nmsub.sFRGH\", \"nmsub.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"nmsub.psFRGH\",\tfalse,\n}\n\nlocal map_pri = {\n  [0] = map_special,\tmap_regimm,\t\"jJ\",\t\"jalJ\",\n  \"beq|beqz|bST00B\",\t\"bne|bnezST0B\",\t\t\"blezSB\",\t\"bgtzSB\",\n  \"addiTSI\",\t\"addiu|liTS0I\",\t\"sltiTSI\",\t\"sltiuTSI\",\n  \"andiTSU\",\t\"ori|liTS0U\",\t\"xoriTSU\",\t\"luiTU\",\n  map_cop0,\tmap_cop1,\tfalse,\t\tmap_cop1x,\n  \"beql|beqzlST0B\",\t\"bnel|bnezlST0B\",\t\"blezlSB\",\t\"bgtzlSB\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  map_special2,\tfalse,\t\tfalse,\t\tmap_special3,\n  \"lbTSO\",\t\"lhTSO\",\t\"lwlTSO\",\t\"lwTSO\",\n  \"lbuTSO\",\t\"lhuTSO\",\t\"lwrTSO\",\tfalse,\n  \"sbTSO\",\t\"shTSO\",\t\"swlTSO\",\t\"swTSO\",\n  false,\tfalse,\t\t\"swrTSO\",\t\"cacheNSO\",\n  \"llTSO\",\t\"lwc1HSO\",\t\"lwc2TSO\",\t\"prefNSO\",\n  false,\t\"ldc1HSO\",\t\"ldc2TSO\",\tfalse,\n  \"scTSO\",\t\"swc1HSO\",\t\"swc2TSO\",\tfalse,\n  false,\t\"sdc1HSO\",\t\"sdc2TSO\",\tfalse,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"r1\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\",\n  \"r16\", \"r17\", \"r18\", \"r19\", \"r20\", \"r21\", \"r22\", \"r23\",\n  \"r24\", \"r25\", \"r26\", \"r27\", \"r28\", \"sp\", \"r30\", \"ra\",\n}\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then extra = \"\\t->\"..sym end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-7s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-7s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\nlocal function get_be(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)\nend\n\nlocal function get_le(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local op = ctx:get()\n  local operands = {}\n  local last = nil\n  ctx.op = op\n  ctx.rel = nil\n\n  local opat = map_pri[rshift(op, 26)]\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._\n  end\n  local name, pat = match(opat, \"^([a-z0-9_.]*)(.*)\")\n  local altname, pat2 = match(pat, \"|([a-z0-9_.|]*)(.*)\")\n  if altname then pat = pat2 end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"S\" then\n      x = map_gpr[band(rshift(op, 21), 31)]\n    elseif p == \"T\" then\n      x = map_gpr[band(rshift(op, 16), 31)]\n    elseif p == \"D\" then\n      x = map_gpr[band(rshift(op, 11), 31)]\n    elseif p == \"F\" then\n      x = \"f\"..band(rshift(op, 6), 31)\n    elseif p == \"G\" then\n      x = \"f\"..band(rshift(op, 11), 31)\n    elseif p == \"H\" then\n      x = \"f\"..band(rshift(op, 16), 31)\n    elseif p == \"R\" then\n      x = \"f\"..band(rshift(op, 21), 31)\n    elseif p == \"A\" then\n      x = band(rshift(op, 6), 31)\n    elseif p == \"M\" then\n      x = band(rshift(op, 11), 31)\n    elseif p == \"N\" then\n      x = band(rshift(op, 16), 31)\n    elseif p == \"C\" then\n      x = band(rshift(op, 18), 7)\n      if x == 0 then x = nil end\n    elseif p == \"K\" then\n      x = band(rshift(op, 11), 31) + 1\n    elseif p == \"L\" then\n      x = band(rshift(op, 11), 31) - last + 1\n    elseif p == \"I\" then\n      x = arshift(lshift(op, 16), 16)\n    elseif p == \"U\" then\n      x = band(op, 0xffff)\n    elseif p == \"O\" then\n      local disp = arshift(lshift(op, 16), 16)\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p == \"X\" then\n      local index = map_gpr[band(rshift(op, 16), 31)]\n      operands[#operands] = format(\"%s(%s)\", index, last)\n    elseif p == \"B\" then\n      x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4\n      ctx.rel = x\n      x = \"0x\"..tohex(x)\n    elseif p == \"J\" then\n      x = band(ctx.addr + ctx.pos, 0xf0000000) + band(op, 0x03ffffff)*4\n      ctx.rel = x\n      x = \"0x\"..tohex(x)\n    elseif p == \"V\" then\n      x = band(rshift(op, 8), 7)\n      if x == 0 then x = nil end\n    elseif p == \"W\" then\n      x = band(op, 7)\n      if x == 0 then x = nil end\n    elseif p == \"Y\" then\n      x = band(rshift(op, 6), 0x000fffff)\n      if x == 0 then x = nil end\n    elseif p == \"Z\" then\n      x = band(rshift(op, 6), 1023)\n      if x == 0 then x = nil end\n    elseif p == \"0\" then\n      if last == \"r0\" or last == 0 then\n\tlocal n = #operands\n\toperands[n] = nil\n\tlast = operands[n-1]\n\tif altname then\n\t  local a1, a2 = match(altname, \"([^|]*)|(.*)\")\n\t  if a1 then name, altname = a1, a2\n\t  else name = altname end\n\tend\n      end\n    elseif p == \"1\" then\n      if last == \"ra\" then\n\toperands[#operands] = nil\n      end\n    else\n      assert(false)\n    end\n    if x then operands[#operands+1] = x; last = x end\n  end\n\n  return putop(ctx, name, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  stop = stop - stop % 4\n  ctx.pos = ofs - ofs % 4\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  ctx.get = get_be\n  return ctx\nend\n\nlocal function create_el(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.get = get_le\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\nlocal function disass_el(code, addr, out)\n  create_el(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 32 then return map_gpr[r] end\n  return \"f\"..(r-32)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  create_el = create_el,\n  disass = disass,\n  disass_el = disass_el,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_mipsel.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPSEL disassembler wrapper module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the little-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create_el,\n  disass = dis_mips.disass_el,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_ppc.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT PPC disassembler module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT/X license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles all common, non-privileged 32/64 bit PowerPC instructions\n-- plus the e500 SPE instructions and some Cell/Xenon extensions.\n--\n-- NYI: VMX, VMX128\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, tohex = bit.band, bit.bor, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Primary and extended opcode maps\n------------------------------------------------------------------------------\n\nlocal map_crops = {\n  shift = 1, mask = 1023,\n  [0] = \"mcrfXX\",\n  [33] = \"crnor|crnotCCC=\", [129] = \"crandcCCC\",\n  [193] = \"crxor|crclrCCC%\", [225] = \"crnandCCC\",\n  [257] = \"crandCCC\", [289] = \"creqv|crsetCCC%\",\n  [417] = \"crorcCCC\", [449] = \"cror|crmoveCCC=\",\n  [16] = \"b_lrKB\", [528] = \"b_ctrKB\",\n  [150] = \"isync\",\n}\n\nlocal map_rlwinm = setmetatable({\n  shift = 0, mask = -1,\n},\n{ __index = function(t, x)\n    local rot = band(rshift(x, 11), 31)\n    local mb = band(rshift(x, 6), 31)\n    local me = band(rshift(x, 1), 31)\n    if mb == 0 and me == 31-rot then\n      return \"slwiRR~A.\"\n    elseif me == 31 and mb == 32-rot then\n      return \"srwiRR~-A.\"\n    else\n      return \"rlwinmRR~AAA.\"\n    end\n  end\n})\n\nlocal map_rld = {\n  shift = 2, mask = 7,\n  [0] = \"rldiclRR~HM.\", \"rldicrRR~HM.\", \"rldicRR~HM.\", \"rldimiRR~HM.\",\n  {\n    shift = 1, mask = 1,\n    [0] = \"rldclRR~RM.\", \"rldcrRR~RM.\",\n  },\n}\n\nlocal map_ext = setmetatable({\n  shift = 1, mask = 1023,\n\n  [0] = \"cmp_YLRR\", [32] = \"cmpl_YLRR\",\n  [4] = \"twARR\", [68] = \"tdARR\",\n\n  [8] = \"subfcRRR.\", [40] = \"subfRRR.\",\n  [104] = \"negRR.\", [136] = \"subfeRRR.\",\n  [200] = \"subfzeRR.\", [232] = \"subfmeRR.\",\n  [520] = \"subfcoRRR.\", [552] = \"subfoRRR.\",\n  [616] = \"negoRR.\", [648] = \"subfeoRRR.\",\n  [712] = \"subfzeoRR.\", [744] = \"subfmeoRR.\",\n\n  [9] = \"mulhduRRR.\", [73] = \"mulhdRRR.\", [233] = \"mulldRRR.\",\n  [457] = \"divduRRR.\", [489] = \"divdRRR.\",\n  [745] = \"mulldoRRR.\",\n  [969] = \"divduoRRR.\", [1001] = \"divdoRRR.\",\n\n  [10] = \"addcRRR.\", [138] = \"addeRRR.\",\n  [202] = \"addzeRR.\", [234] = \"addmeRR.\", [266] = \"addRRR.\",\n  [522] = \"addcoRRR.\", [650] = \"addeoRRR.\",\n  [714] = \"addzeoRR.\", [746] = \"addmeoRR.\", [778] = \"addoRRR.\",\n\n  [11] = \"mulhwuRRR.\", [75] = \"mulhwRRR.\", [235] = \"mullwRRR.\",\n  [459] = \"divwuRRR.\", [491] = \"divwRRR.\",\n  [747] = \"mullwoRRR.\",\n  [971] = \"divwouRRR.\", [1003] = \"divwoRRR.\",\n\n  [15] = \"iselltRRR\", [47] = \"iselgtRRR\", [79] = \"iseleqRRR\",\n\n  [144] = { shift = 20, mask = 1, [0] = \"mtcrfRZ~\", \"mtocrfRZ~\", },\n  [19] = { shift = 20, mask = 1, [0] = \"mfcrR\", \"mfocrfRZ\", },\n  [371] = { shift = 11, mask = 1023, [392] = \"mftbR\", [424] = \"mftbuR\", },\n  [339] = {\n    shift = 11, mask = 1023,\n    [32] = \"mferR\", [256] = \"mflrR\", [288] = \"mfctrR\", [16] = \"mfspefscrR\",\n  },\n  [467] = {\n    shift = 11, mask = 1023,\n    [32] = \"mtxerR\", [256] = \"mtlrR\", [288] = \"mtctrR\", [16] = \"mtspefscrR\",\n  },\n\n  [20] = \"lwarxRR0R\", [84] = \"ldarxRR0R\",\n\n  [21] = \"ldxRR0R\", [53] = \"lduxRRR\",\n  [149] = \"stdxRR0R\", [181] = \"stduxRRR\",\n  [341] = \"lwaxRR0R\", [373] = \"lwauxRRR\",\n\n  [23] = \"lwzxRR0R\", [55] = \"lwzuxRRR\",\n  [87] = \"lbzxRR0R\", [119] = \"lbzuxRRR\",\n  [151] = \"stwxRR0R\", [183] = \"stwuxRRR\",\n  [215] = \"stbxRR0R\", [247] = \"stbuxRRR\",\n  [279] = \"lhzxRR0R\", [311] = \"lhzuxRRR\",\n  [343] = \"lhaxRR0R\", [375] = \"lhauxRRR\",\n  [407] = \"sthxRR0R\", [439] = \"sthuxRRR\",\n\n  [54] = \"dcbst-R0R\", [86] = \"dcbf-R0R\",\n  [150] = \"stwcxRR0R.\", [214] = \"stdcxRR0R.\",\n  [246] = \"dcbtst-R0R\", [278] = \"dcbt-R0R\",\n  [310] = \"eciwxRR0R\", [438] = \"ecowxRR0R\",\n  [470] = \"dcbi-RR\",\n\n  [598] = {\n    shift = 21, mask = 3,\n    [0] = \"sync\", \"lwsync\", \"ptesync\",\n  },\n  [758] = \"dcba-RR\",\n  [854] = \"eieio\", [982] = \"icbi-R0R\", [1014] = \"dcbz-R0R\",\n\n  [26] = \"cntlzwRR~\", [58] = \"cntlzdRR~\",\n  [122] = \"popcntbRR~\",\n  [154] = \"prtywRR~\", [186] = \"prtydRR~\",\n\n  [28] = \"andRR~R.\", [60] = \"andcRR~R.\", [124] = \"nor|notRR~R=.\",\n  [284] = \"eqvRR~R.\", [316] = \"xorRR~R.\",\n  [412] = \"orcRR~R.\", [444] = \"or|mrRR~R=.\", [476] = \"nandRR~R.\",\n  [508] = \"cmpbRR~R\",\n\n  [512] = \"mcrxrX\",\n\n  [532] = \"ldbrxRR0R\", [660] = \"stdbrxRR0R\",\n\n  [533] = \"lswxRR0R\", [597] = \"lswiRR0A\",\n  [661] = \"stswxRR0R\", [725] = \"stswiRR0A\",\n\n  [534] = \"lwbrxRR0R\", [662] = \"stwbrxRR0R\",\n  [790] = \"lhbrxRR0R\", [918] = \"sthbrxRR0R\",\n\n  [535] = \"lfsxFR0R\", [567] = \"lfsuxFRR\",\n  [599] = \"lfdxFR0R\", [631] = \"lfduxFRR\",\n  [663] = \"stfsxFR0R\", [695] = \"stfsuxFRR\",\n  [727] = \"stfdxFR0R\", [759] = \"stfduxFR0R\",\n  [855] = \"lfiwaxFR0R\",\n  [983] = \"stfiwxFR0R\",\n\n  [24] = \"slwRR~R.\",\n\n  [27] = \"sldRR~R.\", [536] = \"srwRR~R.\",\n  [792] = \"srawRR~R.\", [824] = \"srawiRR~A.\",\n\n  [794] = \"sradRR~R.\", [826] = \"sradiRR~H.\", [827] = \"sradiRR~H.\",\n  [922] = \"extshRR~.\", [954] = \"extsbRR~.\", [986] = \"extswRR~.\",\n\n  [539] = \"srdRR~R.\",\n},\n{ __index = function(t, x)\n    if band(x, 31) == 15 then return \"iselRRRC\" end\n  end\n})\n\nlocal map_ld = {\n  shift = 0, mask = 3,\n  [0] = \"ldRRE\", \"lduRRE\", \"lwaRRE\",\n}\n\nlocal map_std = {\n  shift = 0, mask = 3,\n  [0] = \"stdRRE\", \"stduRRE\",\n}\n\nlocal map_fps = {\n  shift = 5, mask = 1,\n  {\n    shift = 1, mask = 15,\n    [0] = false, false, \"fdivsFFF.\", false,\n    \"fsubsFFF.\", \"faddsFFF.\", \"fsqrtsF-F.\", false,\n    \"fresF-F.\", \"fmulsFF-F.\", \"frsqrtesF-F.\", false,\n    \"fmsubsFFFF~.\", \"fmaddsFFFF~.\", \"fnmsubsFFFF~.\", \"fnmaddsFFFF~.\",\n  }\n}\n\nlocal map_fpd = {\n  shift = 5, mask = 1,\n  [0] = {\n    shift = 1, mask = 1023,\n    [0] = \"fcmpuXFF\", [32] = \"fcmpoXFF\", [64] = \"mcrfsXX\",\n    [38] = \"mtfsb1A.\", [70] = \"mtfsb0A.\", [134] = \"mtfsfiA>>-A>\",\n    [8] = \"fcpsgnFFF.\", [40] = \"fnegF-F.\", [72] = \"fmrF-F.\",\n    [136] = \"fnabsF-F.\", [264] = \"fabsF-F.\",\n    [12] = \"frspF-F.\",\n    [14] = \"fctiwF-F.\", [15] = \"fctiwzF-F.\",\n    [583] = \"mffsF.\", [711] = \"mtfsfZF.\",\n    [392] = \"frinF-F.\", [424] = \"frizF-F.\",\n    [456] = \"fripF-F.\", [488] = \"frimF-F.\",\n    [814] = \"fctidF-F.\", [815] = \"fctidzF-F.\", [846] = \"fcfidF-F.\",\n  },\n  {\n    shift = 1, mask = 15,\n    [0] = false, false, \"fdivFFF.\", false,\n    \"fsubFFF.\", \"faddFFF.\", \"fsqrtF-F.\", \"fselFFFF~.\",\n    \"freF-F.\", \"fmulFF-F.\", \"frsqrteF-F.\", false,\n    \"fmsubFFFF~.\", \"fmaddFFFF~.\", \"fnmsubFFFF~.\", \"fnmaddFFFF~.\",\n  }\n}\n\nlocal map_spe = {\n  shift = 0, mask = 2047,\n\n  [512] = \"evaddwRRR\", [514] = \"evaddiwRAR~\",\n  [516] = \"evsubwRRR~\", [518] = \"evsubiwRAR~\",\n  [520] = \"evabsRR\", [521] = \"evnegRR\",\n  [522] = \"evextsbRR\", [523] = \"evextshRR\", [524] = \"evrndwRR\",\n  [525] = \"evcntlzwRR\", [526] = \"evcntlswRR\",\n\n  [527] = \"brincRRR\",\n\n  [529] = \"evandRRR\", [530] = \"evandcRRR\", [534] = \"evxorRRR\",\n  [535] = \"evor|evmrRRR=\", [536] = \"evnor|evnotRRR=\",\n  [537] = \"eveqvRRR\", [539] = \"evorcRRR\", [542] = \"evnandRRR\",\n\n  [544] = \"evsrwuRRR\", [545] = \"evsrwsRRR\",\n  [546] = \"evsrwiuRRA\", [547] = \"evsrwisRRA\",\n  [548] = \"evslwRRR\", [550] = \"evslwiRRA\",\n  [552] = \"evrlwRRR\", [553] = \"evsplatiRS\",\n  [554] = \"evrlwiRRA\", [555] = \"evsplatfiRS\",\n  [556] = \"evmergehiRRR\", [557] = \"evmergeloRRR\",\n  [558] = \"evmergehiloRRR\", [559] = \"evmergelohiRRR\",\n\n  [560] = \"evcmpgtuYRR\", [561] = \"evcmpgtsYRR\",\n  [562] = \"evcmpltuYRR\", [563] = \"evcmpltsYRR\",\n  [564] = \"evcmpeqYRR\",\n\n  [632] = \"evselRRR\", [633] = \"evselRRRW\",\n  [634] = \"evselRRRW\", [635] = \"evselRRRW\",\n  [636] = \"evselRRRW\", [637] = \"evselRRRW\",\n  [638] = \"evselRRRW\", [639] = \"evselRRRW\",\n\n  [640] = \"evfsaddRRR\", [641] = \"evfssubRRR\",\n  [644] = \"evfsabsRR\", [645] = \"evfsnabsRR\", [646] = \"evfsnegRR\",\n  [648] = \"evfsmulRRR\", [649] = \"evfsdivRRR\",\n  [652] = \"evfscmpgtYRR\", [653] = \"evfscmpltYRR\", [654] = \"evfscmpeqYRR\",\n  [656] = \"evfscfuiR-R\", [657] = \"evfscfsiR-R\",\n  [658] = \"evfscfufR-R\", [659] = \"evfscfsfR-R\",\n  [660] = \"evfsctuiR-R\", [661] = \"evfsctsiR-R\",\n  [662] = \"evfsctufR-R\", [663] = \"evfsctsfR-R\",\n  [664] = \"evfsctuizR-R\", [666] = \"evfsctsizR-R\",\n  [668] = \"evfststgtYRR\", [669] = \"evfststltYRR\", [670] = \"evfststeqYRR\",\n\n  [704] = \"efsaddRRR\", [705] = \"efssubRRR\",\n  [708] = \"efsabsRR\", [709] = \"efsnabsRR\", [710] = \"efsnegRR\",\n  [712] = \"efsmulRRR\", [713] = \"efsdivRRR\",\n  [716] = \"efscmpgtYRR\", [717] = \"efscmpltYRR\", [718] = \"efscmpeqYRR\",\n  [719] = \"efscfdR-R\",\n  [720] = \"efscfuiR-R\", [721] = \"efscfsiR-R\",\n  [722] = \"efscfufR-R\", [723] = \"efscfsfR-R\",\n  [724] = \"efsctuiR-R\", [725] = \"efsctsiR-R\",\n  [726] = \"efsctufR-R\", [727] = \"efsctsfR-R\",\n  [728] = \"efsctuizR-R\", [730] = \"efsctsizR-R\",\n  [732] = \"efststgtYRR\", [733] = \"efststltYRR\", [734] = \"efststeqYRR\",\n\n  [736] = \"efdaddRRR\", [737] = \"efdsubRRR\",\n  [738] = \"efdcfuidR-R\", [739] = \"efdcfsidR-R\",\n  [740] = \"efdabsRR\", [741] = \"efdnabsRR\", [742] = \"efdnegRR\",\n  [744] = \"efdmulRRR\", [745] = \"efddivRRR\",\n  [746] = \"efdctuidzR-R\", [747] = \"efdctsidzR-R\",\n  [748] = \"efdcmpgtYRR\", [749] = \"efdcmpltYRR\", [750] = \"efdcmpeqYRR\",\n  [751] = \"efdcfsR-R\",\n  [752] = \"efdcfuiR-R\", [753] = \"efdcfsiR-R\",\n  [754] = \"efdcfufR-R\", [755] = \"efdcfsfR-R\",\n  [756] = \"efdctuiR-R\", [757] = \"efdctsiR-R\",\n  [758] = \"efdctufR-R\", [759] = \"efdctsfR-R\",\n  [760] = \"efdctuizR-R\", [762] = \"efdctsizR-R\",\n  [764] = \"efdtstgtYRR\", [765] = \"efdtstltYRR\", [766] = \"efdtsteqYRR\",\n\n  [768] = \"evlddxRR0R\", [769] = \"evlddRR8\",\n  [770] = \"evldwxRR0R\", [771] = \"evldwRR8\",\n  [772] = \"evldhxRR0R\", [773] = \"evldhRR8\",\n  [776] = \"evlhhesplatxRR0R\", [777] = \"evlhhesplatRR2\",\n  [780] = \"evlhhousplatxRR0R\", [781] = \"evlhhousplatRR2\",\n  [782] = \"evlhhossplatxRR0R\", [783] = \"evlhhossplatRR2\",\n  [784] = \"evlwhexRR0R\", [785] = \"evlwheRR4\",\n  [788] = \"evlwhouxRR0R\", [789] = \"evlwhouRR4\",\n  [790] = \"evlwhosxRR0R\", [791] = \"evlwhosRR4\",\n  [792] = \"evlwwsplatxRR0R\", [793] = \"evlwwsplatRR4\",\n  [796] = \"evlwhsplatxRR0R\", [797] = \"evlwhsplatRR4\",\n\n  [800] = \"evstddxRR0R\", [801] = \"evstddRR8\",\n  [802] = \"evstdwxRR0R\", [803] = \"evstdwRR8\",\n  [804] = \"evstdhxRR0R\", [805] = \"evstdhRR8\",\n  [816] = \"evstwhexRR0R\", [817] = \"evstwheRR4\",\n  [820] = \"evstwhoxRR0R\", [821] = \"evstwhoRR4\",\n  [824] = \"evstwwexRR0R\", [825] = \"evstwweRR4\",\n  [828] = \"evstwwoxRR0R\", [829] = \"evstwwoRR4\",\n\n  [1027] = \"evmhessfRRR\", [1031] = \"evmhossfRRR\", [1032] = \"evmheumiRRR\",\n  [1033] = \"evmhesmiRRR\", [1035] = \"evmhesmfRRR\", [1036] = \"evmhoumiRRR\",\n  [1037] = \"evmhosmiRRR\", [1039] = \"evmhosmfRRR\", [1059] = \"evmhessfaRRR\",\n  [1063] = \"evmhossfaRRR\", [1064] = \"evmheumiaRRR\", [1065] = \"evmhesmiaRRR\",\n  [1067] = \"evmhesmfaRRR\", [1068] = \"evmhoumiaRRR\", [1069] = \"evmhosmiaRRR\",\n  [1071] = \"evmhosmfaRRR\", [1095] = \"evmwhssfRRR\", [1096] = \"evmwlumiRRR\",\n  [1100] = \"evmwhumiRRR\", [1101] = \"evmwhsmiRRR\", [1103] = \"evmwhsmfRRR\",\n  [1107] = \"evmwssfRRR\", [1112] = \"evmwumiRRR\", [1113] = \"evmwsmiRRR\",\n  [1115] = \"evmwsmfRRR\", [1127] = \"evmwhssfaRRR\", [1128] = \"evmwlumiaRRR\",\n  [1132] = \"evmwhumiaRRR\", [1133] = \"evmwhsmiaRRR\", [1135] = \"evmwhsmfaRRR\",\n  [1139] = \"evmwssfaRRR\", [1144] = \"evmwumiaRRR\", [1145] = \"evmwsmiaRRR\",\n  [1147] = \"evmwsmfaRRR\",\n\n  [1216] = \"evaddusiaawRR\", [1217] = \"evaddssiaawRR\",\n  [1218] = \"evsubfusiaawRR\", [1219] = \"evsubfssiaawRR\",\n  [1220] = \"evmraRR\",\n  [1222] = \"evdivwsRRR\", [1223] = \"evdivwuRRR\",\n  [1224] = \"evaddumiaawRR\", [1225] = \"evaddsmiaawRR\",\n  [1226] = \"evsubfumiaawRR\", [1227] = \"evsubfsmiaawRR\",\n\n  [1280] = \"evmheusiaawRRR\", [1281] = \"evmhessiaawRRR\",\n  [1283] = \"evmhessfaawRRR\", [1284] = \"evmhousiaawRRR\",\n  [1285] = \"evmhossiaawRRR\", [1287] = \"evmhossfaawRRR\",\n  [1288] = \"evmheumiaawRRR\", [1289] = \"evmhesmiaawRRR\",\n  [1291] = \"evmhesmfaawRRR\", [1292] = \"evmhoumiaawRRR\",\n  [1293] = \"evmhosmiaawRRR\", [1295] = \"evmhosmfaawRRR\",\n  [1320] = \"evmhegumiaaRRR\", [1321] = \"evmhegsmiaaRRR\",\n  [1323] = \"evmhegsmfaaRRR\", [1324] = \"evmhogumiaaRRR\",\n  [1325] = \"evmhogsmiaaRRR\", [1327] = \"evmhogsmfaaRRR\",\n  [1344] = \"evmwlusiaawRRR\", [1345] = \"evmwlssiaawRRR\",\n  [1352] = \"evmwlumiaawRRR\", [1353] = \"evmwlsmiaawRRR\",\n  [1363] = \"evmwssfaaRRR\", [1368] = \"evmwumiaaRRR\",\n  [1369] = \"evmwsmiaaRRR\", [1371] = \"evmwsmfaaRRR\",\n  [1408] = \"evmheusianwRRR\", [1409] = \"evmhessianwRRR\",\n  [1411] = \"evmhessfanwRRR\", [1412] = \"evmhousianwRRR\",\n  [1413] = \"evmhossianwRRR\", [1415] = \"evmhossfanwRRR\",\n  [1416] = \"evmheumianwRRR\", [1417] = \"evmhesmianwRRR\",\n  [1419] = \"evmhesmfanwRRR\", [1420] = \"evmhoumianwRRR\",\n  [1421] = \"evmhosmianwRRR\", [1423] = \"evmhosmfanwRRR\",\n  [1448] = \"evmhegumianRRR\", [1449] = \"evmhegsmianRRR\",\n  [1451] = \"evmhegsmfanRRR\", [1452] = \"evmhogumianRRR\",\n  [1453] = \"evmhogsmianRRR\", [1455] = \"evmhogsmfanRRR\",\n  [1472] = \"evmwlusianwRRR\", [1473] = \"evmwlssianwRRR\",\n  [1480] = \"evmwlumianwRRR\", [1481] = \"evmwlsmianwRRR\",\n  [1491] = \"evmwssfanRRR\", [1496] = \"evmwumianRRR\",\n  [1497] = \"evmwsmianRRR\", [1499] = \"evmwsmfanRRR\",\n}\n\nlocal map_pri = {\n  [0] = false,\tfalse,\t\t\"tdiARI\",\t\"twiARI\",\n  map_spe,\tfalse,\t\tfalse,\t\t\"mulliRRI\",\n  \"subficRRI\",\tfalse,\t\t\"cmpl_iYLRU\",\t\"cmp_iYLRI\",\n  \"addicRRI\",\t\"addic.RRI\",\t\"addi|liRR0I\",\t\"addis|lisRR0I\",\n  \"b_KBJ\",\t\"sc\",\t\t \"bKJ\",\t\tmap_crops,\n  \"rlwimiRR~AAA.\", map_rlwinm,\tfalse,\t\t\"rlwnmRR~RAA.\",\n  \"oriNRR~U\",\t\"orisRR~U\",\t\"xoriRR~U\",\t\"xorisRR~U\",\n  \"andi.RR~U\",\t\"andis.RR~U\",\tmap_rld,\tmap_ext,\n  \"lwzRRD\",\t\"lwzuRRD\",\t\"lbzRRD\",\t\"lbzuRRD\",\n  \"stwRRD\",\t\"stwuRRD\",\t\"stbRRD\",\t\"stbuRRD\",\n  \"lhzRRD\",\t\"lhzuRRD\",\t\"lhaRRD\",\t\"lhauRRD\",\n  \"sthRRD\",\t\"sthuRRD\",\t\"lmwRRD\",\t\"stmwRRD\",\n  \"lfsFRD\",\t\"lfsuFRD\",\t\"lfdFRD\",\t\"lfduFRD\",\n  \"stfsFRD\",\t\"stfsuFRD\",\t\"stfdFRD\",\t\"stfduFRD\",\n  false,\tfalse,\t\tmap_ld,\t\tmap_fps,\n  false,\tfalse,\t\tmap_std,\tmap_fpd,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"sp\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\",\n  \"r16\", \"r17\", \"r18\", \"r19\", \"r20\", \"r21\", \"r22\", \"r23\",\n  \"r24\", \"r25\", \"r26\", \"r27\", \"r28\", \"r29\", \"r30\", \"r31\",\n}\n\nlocal map_cond = { [0] = \"lt\", \"gt\", \"eq\", \"so\", \"ge\", \"le\", \"ne\", \"ns\", }\n\n-- Format a condition bit.\nlocal function condfmt(cond)\n  if cond <= 3 then\n    return map_cond[band(cond, 3)]\n  else\n    return format(\"4*cr%d+%s\", rshift(cond, 2), map_cond[band(cond, 3)])\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then extra = \"\\t->\"..sym end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-7s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-7s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  local op = bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)\n  local operands = {}\n  local last = nil\n  local rs = 21\n  ctx.op = op\n  ctx.rel = nil\n\n  local opat = map_pri[rshift(b0, 2)]\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)]\n  end\n  local name, pat = match(opat, \"^([a-z0-9_.]*)(.*)\")\n  local altname, pat2 = match(pat, \"|([a-z0-9_.]*)(.*)\")\n  if altname then pat = pat2 end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"R\" then\n      x = map_gpr[band(rshift(op, rs), 31)]\n      rs = rs - 5\n    elseif p == \"F\" then\n      x = \"f\"..band(rshift(op, rs), 31)\n      rs = rs - 5\n    elseif p == \"A\" then\n      x = band(rshift(op, rs), 31)\n      rs = rs - 5\n    elseif p == \"S\" then\n      x = arshift(lshift(op, 27-rs), 27)\n      rs = rs - 5\n    elseif p == \"I\" then\n      x = arshift(lshift(op, 16), 16)\n    elseif p == \"U\" then\n      x = band(op, 0xffff)\n    elseif p == \"D\" or p == \"E\" then\n      local disp = arshift(lshift(op, 16), 16)\n      if p == \"E\" then disp = band(disp, -4) end\n      if last == \"r0\" then last = \"0\" end\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p >= \"2\" and p <= \"8\" then\n      local disp = band(rshift(op, rs), 31) * p\n      if last == \"r0\" then last = \"0\" end\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p == \"H\" then\n      x = band(rshift(op, rs), 31) + lshift(band(op, 2), 4)\n      rs = rs - 5\n    elseif p == \"M\" then\n      x = band(rshift(op, rs), 31) + band(op, 0x20)\n    elseif p == \"C\" then\n      x = condfmt(band(rshift(op, rs), 31))\n      rs = rs - 5\n    elseif p == \"B\" then\n      local bo = rshift(op, 21)\n      local cond = band(rshift(op, 16), 31)\n      local cn = \"\"\n      rs = rs - 10\n      if band(bo, 4) == 0 then\n\tcn = band(bo, 2) == 0 and \"dnz\" or \"dz\"\n\tif band(bo, 0x10) == 0 then\n\t  cn = cn..(band(bo, 8) == 0 and \"f\" or \"t\")\n\tend\n\tif band(bo, 0x10) == 0 then x = condfmt(cond) end\n\tname = name..(band(bo, 1) == band(rshift(op, 15), 1) and \"-\" or \"+\")\n      elseif band(bo, 0x10) == 0 then\n\tcn = map_cond[band(cond, 3) + (band(bo, 8) == 0 and 4 or 0)]\n\tif cond > 3 then x = \"cr\"..rshift(cond, 2) end\n\tname = name..(band(bo, 1) == band(rshift(op, 15), 1) and \"-\" or \"+\")\n      end\n      name = gsub(name, \"_\", cn)\n    elseif p == \"J\" then\n      x = arshift(lshift(op, 27-rs), 29-rs)*4\n      if band(op, 2) == 0 then x = ctx.addr + pos + x end\n      ctx.rel = x\n      x = \"0x\"..tohex(x)\n    elseif p == \"K\" then\n      if band(op, 1) ~= 0 then name = name..\"l\" end\n      if band(op, 2) ~= 0 then name = name..\"a\" end\n    elseif p == \"X\" or p == \"Y\" then\n      x = band(rshift(op, rs+2), 7)\n      if x == 0 and p == \"Y\" then x = nil else x = \"cr\"..x end\n      rs = rs - 5\n    elseif p == \"W\" then\n      x = \"cr\"..band(op, 7)\n    elseif p == \"Z\" then\n      x = band(rshift(op, rs-4), 255)\n      rs = rs - 10\n    elseif p == \">\" then\n      operands[#operands] = rshift(operands[#operands], 1)\n    elseif p == \"0\" then\n      if last == \"r0\" then\n\toperands[#operands] = nil\n\tif altname then name = altname end\n      end\n    elseif p == \"L\" then\n      name = gsub(name, \"_\", band(op, 0x00200000) ~= 0 and \"d\" or \"w\")\n    elseif p == \".\" then\n      if band(op, 1) == 1 then name = name..\".\" end\n    elseif p == \"N\" then\n      if op == 0x60000000 then name = \"nop\"; break end\n    elseif p == \"~\" then\n      local n = #operands\n      operands[n-1],  operands[n] = operands[n], operands[n-1]\n    elseif p == \"=\" then\n      local n = #operands\n      if last == operands[n-1] then\n\toperands[n] = nil\n\tname = altname\n      end\n    elseif p == \"%\" then\n      local n = #operands\n      if last == operands[n-1] and last == operands[n-2] then\n\toperands[n] = nil\n\toperands[n-1] = nil\n\tname = altname\n      end\n    elseif p == \"-\" then\n      rs = rs - 5\n    else\n      assert(false)\n    end\n    if x then operands[#operands+1] = x; last = x end\n  end\n\n  return putop(ctx, name, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  stop = stop - stop % 4\n  ctx.pos = ofs - ofs % 4\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 32 then return map_gpr[r] end\n  return \"f\"..(r-32)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  disass = disass,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_x64.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT x64 disassembler wrapper module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the 64 bit functions from the combined\n-- x86/x64 disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_x86 = require((string.match(..., \".*%.\") or \"\")..\"dis_x86\")\nreturn {\n  create = dis_x86.create64,\n  disass = dis_x86.disass64,\n  regname = dis_x86.regname64\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dis_x86.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT x86/x64 disassembler module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- Sending small code snippets to an external disassembler and mixing the\n-- output with our own stuff was too fragile. So I had to bite the bullet\n-- and write yet another x86 disassembler. Oh well ...\n--\n-- The output format is very similar to what ndisasm generates. But it has\n-- been developed independently by looking at the opcode tables from the\n-- Intel and AMD manuals. The supported instruction set is quite extensive\n-- and reflects what a current generation Intel or AMD CPU implements in\n-- 32 bit and 64 bit mode. Yes, this includes MMX, SSE, SSE2, SSE3, SSSE3,\n-- SSE4.1, SSE4.2, SSE4a, AVX, AVX2 and even privileged and hypervisor\n-- (VMX/SVM) instructions.\n--\n-- Notes:\n-- * The (useless) a16 prefix, 3DNow and pre-586 opcodes are unsupported.\n-- * No attempt at optimization has been made -- it's fast enough for my needs.\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal lower, rep = string.lower, string.rep\nlocal bit = require(\"bit\")\nlocal tohex = bit.tohex\n\n-- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on.\nlocal map_opc1_32 = {\n--0x\n[0]=\"addBmr\",\"addVmr\",\"addBrm\",\"addVrm\",\"addBai\",\"addVai\",\"push es\",\"pop es\",\n\"orBmr\",\"orVmr\",\"orBrm\",\"orVrm\",\"orBai\",\"orVai\",\"push cs\",\"opc2*\",\n--1x\n\"adcBmr\",\"adcVmr\",\"adcBrm\",\"adcVrm\",\"adcBai\",\"adcVai\",\"push ss\",\"pop ss\",\n\"sbbBmr\",\"sbbVmr\",\"sbbBrm\",\"sbbVrm\",\"sbbBai\",\"sbbVai\",\"push ds\",\"pop ds\",\n--2x\n\"andBmr\",\"andVmr\",\"andBrm\",\"andVrm\",\"andBai\",\"andVai\",\"es:seg\",\"daa\",\n\"subBmr\",\"subVmr\",\"subBrm\",\"subVrm\",\"subBai\",\"subVai\",\"cs:seg\",\"das\",\n--3x\n\"xorBmr\",\"xorVmr\",\"xorBrm\",\"xorVrm\",\"xorBai\",\"xorVai\",\"ss:seg\",\"aaa\",\n\"cmpBmr\",\"cmpVmr\",\"cmpBrm\",\"cmpVrm\",\"cmpBai\",\"cmpVai\",\"ds:seg\",\"aas\",\n--4x\n\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\n\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\n--5x\n\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\n\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\n--6x\n\"sz*pushaw,pusha\",\"sz*popaw,popa\",\"boundVrm\",\"arplWmr\",\n\"fs:seg\",\"gs:seg\",\"o16:\",\"a16\",\n\"pushUi\",\"imulVrmi\",\"pushBs\",\"imulVrms\",\n\"insb\",\"insVS\",\"outsb\",\"outsVS\",\n--7x\n\"joBj\",\"jnoBj\",\"jbBj\",\"jnbBj\",\"jzBj\",\"jnzBj\",\"jbeBj\",\"jaBj\",\n\"jsBj\",\"jnsBj\",\"jpeBj\",\"jpoBj\",\"jlBj\",\"jgeBj\",\"jleBj\",\"jgBj\",\n--8x\n\"arith!Bmi\",\"arith!Vmi\",\"arith!Bmi\",\"arith!Vms\",\n\"testBmr\",\"testVmr\",\"xchgBrm\",\"xchgVrm\",\n\"movBmr\",\"movVmr\",\"movBrm\",\"movVrm\",\n\"movVmg\",\"leaVrm\",\"movWgm\",\"popUm\",\n--9x\n\"nop*xchgVaR|pause|xchgWaR|repne nop\",\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\n\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\n\"sz*cbw,cwde,cdqe\",\"sz*cwd,cdq,cqo\",\"call farViw\",\"wait\",\n\"sz*pushfw,pushf\",\"sz*popfw,popf\",\"sahf\",\"lahf\",\n--Ax\n\"movBao\",\"movVao\",\"movBoa\",\"movVoa\",\n\"movsb\",\"movsVS\",\"cmpsb\",\"cmpsVS\",\n\"testBai\",\"testVai\",\"stosb\",\"stosVS\",\n\"lodsb\",\"lodsVS\",\"scasb\",\"scasVS\",\n--Bx\n\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\n\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\n--Cx\n\"shift!Bmu\",\"shift!Vmu\",\"retBw\",\"ret\",\"vex*3$lesVrm\",\"vex*2$ldsVrm\",\"movBmi\",\"movVmi\",\n\"enterBwu\",\"leave\",\"retfBw\",\"retf\",\"int3\",\"intBu\",\"into\",\"iretVS\",\n--Dx\n\"shift!Bm1\",\"shift!Vm1\",\"shift!Bmc\",\"shift!Vmc\",\"aamBu\",\"aadBu\",\"salc\",\"xlatb\",\n\"fp*0\",\"fp*1\",\"fp*2\",\"fp*3\",\"fp*4\",\"fp*5\",\"fp*6\",\"fp*7\",\n--Ex\n\"loopneBj\",\"loopeBj\",\"loopBj\",\"sz*jcxzBj,jecxzBj,jrcxzBj\",\n\"inBau\",\"inVau\",\"outBua\",\"outVua\",\n\"callVj\",\"jmpVj\",\"jmp farViw\",\"jmpBj\",\"inBad\",\"inVad\",\"outBda\",\"outVda\",\n--Fx\n\"lock:\",\"int1\",\"repne:rep\",\"rep:\",\"hlt\",\"cmc\",\"testb!Bm\",\"testv!Vm\",\n\"clc\",\"stc\",\"cli\",\"sti\",\"cld\",\"std\",\"incb!Bm\",\"incd!Vm\",\n}\nassert(#map_opc1_32 == 255)\n\n-- Map for 1st opcode byte in 64 bit mode (overrides only).\nlocal map_opc1_64 = setmetatable({\n  [0x06]=false, [0x07]=false, [0x0e]=false,\n  [0x16]=false, [0x17]=false, [0x1e]=false, [0x1f]=false,\n  [0x27]=false, [0x2f]=false, [0x37]=false, [0x3f]=false,\n  [0x60]=false, [0x61]=false, [0x62]=false, [0x63]=\"movsxdVrDmt\", [0x67]=\"a32:\",\n  [0x40]=\"rex*\",   [0x41]=\"rex*b\",   [0x42]=\"rex*x\",   [0x43]=\"rex*xb\",\n  [0x44]=\"rex*r\",  [0x45]=\"rex*rb\",  [0x46]=\"rex*rx\",  [0x47]=\"rex*rxb\",\n  [0x48]=\"rex*w\",  [0x49]=\"rex*wb\",  [0x4a]=\"rex*wx\",  [0x4b]=\"rex*wxb\",\n  [0x4c]=\"rex*wr\", [0x4d]=\"rex*wrb\", [0x4e]=\"rex*wrx\", [0x4f]=\"rex*wrxb\",\n  [0x82]=false, [0x9a]=false, [0xc4]=\"vex*3\", [0xc5]=\"vex*2\", [0xce]=false,\n  [0xd4]=false, [0xd5]=false, [0xd6]=false, [0xea]=false,\n}, { __index = map_opc1_32 })\n\n-- Map for 2nd opcode byte (0F xx). True CISC hell. Hey, I told you.\n-- Prefix dependent MMX/SSE opcodes: (none)|rep|o16|repne, -|F3|66|F2\nlocal map_opc2 = {\n--0x\n[0]=\"sldt!Dmp\",\"sgdt!Ump\",\"larVrm\",\"lslVrm\",nil,\"syscall\",\"clts\",\"sysret\",\n\"invd\",\"wbinvd\",nil,\"ud1\",nil,\"$prefetch!Bm\",\"femms\",\"3dnowMrmu\",\n--1x\n\"movupsXrm|movssXrvm|movupdXrm|movsdXrvm\",\n\"movupsXmr|movssXmvr|movupdXmr|movsdXmvr\",\n\"movhlpsXrm$movlpsXrm|movsldupXrm|movlpdXrm|movddupXrm\",\n\"movlpsXmr||movlpdXmr\",\n\"unpcklpsXrvm||unpcklpdXrvm\",\n\"unpckhpsXrvm||unpckhpdXrvm\",\n\"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm\",\n\"movhpsXmr||movhpdXmr\",\n\"$prefetcht!Bm\",\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\n\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\n--2x\n\"movUmx$\",\"movUmy$\",\"movUxm$\",\"movUym$\",\"movUmz$\",nil,\"movUzm$\",nil,\n\"movapsXrm||movapdXrm\",\n\"movapsXmr||movapdXmr\",\n\"cvtpi2psXrMm|cvtsi2ssXrvVmt|cvtpi2pdXrMm|cvtsi2sdXrvVmt\",\n\"movntpsXmr|movntssXmr|movntpdXmr|movntsdXmr\",\n\"cvttps2piMrXm|cvttss2siVrXm|cvttpd2piMrXm|cvttsd2siVrXm\",\n\"cvtps2piMrXm|cvtss2siVrXm|cvtpd2piMrXm|cvtsd2siVrXm\",\n\"ucomissXrm||ucomisdXrm\",\n\"comissXrm||comisdXrm\",\n--3x\n\"wrmsr\",\"rdtsc\",\"rdmsr\",\"rdpmc\",\"sysenter\",\"sysexit\",nil,\"getsec\",\n\"opc3*38\",nil,\"opc3*3a\",nil,nil,nil,nil,nil,\n--4x\n\"cmovoVrm\",\"cmovnoVrm\",\"cmovbVrm\",\"cmovnbVrm\",\n\"cmovzVrm\",\"cmovnzVrm\",\"cmovbeVrm\",\"cmovaVrm\",\n\"cmovsVrm\",\"cmovnsVrm\",\"cmovpeVrm\",\"cmovpoVrm\",\n\"cmovlVrm\",\"cmovgeVrm\",\"cmovleVrm\",\"cmovgVrm\",\n--5x\n\"movmskpsVrXm$||movmskpdVrXm$\",\"sqrtpsXrm|sqrtssXrm|sqrtpdXrm|sqrtsdXrm\",\n\"rsqrtpsXrm|rsqrtssXrvm\",\"rcppsXrm|rcpssXrvm\",\n\"andpsXrvm||andpdXrvm\",\"andnpsXrvm||andnpdXrvm\",\n\"orpsXrvm||orpdXrvm\",\"xorpsXrvm||xorpdXrvm\",\n\"addpsXrvm|addssXrvm|addpdXrvm|addsdXrvm\",\"mulpsXrvm|mulssXrvm|mulpdXrvm|mulsdXrvm\",\n\"cvtps2pdXrm|cvtss2sdXrvm|cvtpd2psXrm|cvtsd2ssXrvm\",\n\"cvtdq2psXrm|cvttps2dqXrm|cvtps2dqXrm\",\n\"subpsXrvm|subssXrvm|subpdXrvm|subsdXrvm\",\"minpsXrvm|minssXrvm|minpdXrvm|minsdXrvm\",\n\"divpsXrvm|divssXrvm|divpdXrvm|divsdXrvm\",\"maxpsXrvm|maxssXrvm|maxpdXrvm|maxsdXrvm\",\n--6x\n\"punpcklbwPrvm\",\"punpcklwdPrvm\",\"punpckldqPrvm\",\"packsswbPrvm\",\n\"pcmpgtbPrvm\",\"pcmpgtwPrvm\",\"pcmpgtdPrvm\",\"packuswbPrvm\",\n\"punpckhbwPrvm\",\"punpckhwdPrvm\",\"punpckhdqPrvm\",\"packssdwPrvm\",\n\"||punpcklqdqXrvm\",\"||punpckhqdqXrvm\",\n\"movPrVSm\",\"movqMrm|movdquXrm|movdqaXrm\",\n--7x\n\"pshufwMrmu|pshufhwXrmu|pshufdXrmu|pshuflwXrmu\",\"pshiftw!Pvmu\",\n\"pshiftd!Pvmu\",\"pshiftq!Mvmu||pshiftdq!Xvmu\",\n\"pcmpeqbPrvm\",\"pcmpeqwPrvm\",\"pcmpeqdPrvm\",\"emms*|\",\n\"vmreadUmr||extrqXmuu$|insertqXrmuu$\",\"vmwriteUrm||extrqXrm$|insertqXrm$\",\nnil,nil,\n\"||haddpdXrvm|haddpsXrvm\",\"||hsubpdXrvm|hsubpsXrvm\",\n\"movVSmMr|movqXrm|movVSmXr\",\"movqMmr|movdquXmr|movdqaXmr\",\n--8x\n\"joVj\",\"jnoVj\",\"jbVj\",\"jnbVj\",\"jzVj\",\"jnzVj\",\"jbeVj\",\"jaVj\",\n\"jsVj\",\"jnsVj\",\"jpeVj\",\"jpoVj\",\"jlVj\",\"jgeVj\",\"jleVj\",\"jgVj\",\n--9x\n\"setoBm\",\"setnoBm\",\"setbBm\",\"setnbBm\",\"setzBm\",\"setnzBm\",\"setbeBm\",\"setaBm\",\n\"setsBm\",\"setnsBm\",\"setpeBm\",\"setpoBm\",\"setlBm\",\"setgeBm\",\"setleBm\",\"setgBm\",\n--Ax\n\"push fs\",\"pop fs\",\"cpuid\",\"btVmr\",\"shldVmru\",\"shldVmrc\",nil,nil,\n\"push gs\",\"pop gs\",\"rsm\",\"btsVmr\",\"shrdVmru\",\"shrdVmrc\",\"fxsave!Dmp\",\"imulVrm\",\n--Bx\n\"cmpxchgBmr\",\"cmpxchgVmr\",\"$lssVrm\",\"btrVmr\",\n\"$lfsVrm\",\"$lgsVrm\",\"movzxVrBmt\",\"movzxVrWmt\",\n\"|popcntVrm\",\"ud2Dp\",\"bt!Vmu\",\"btcVmr\",\n\"bsfVrm\",\"bsrVrm|lzcntVrm|bsrWrm\",\"movsxVrBmt\",\"movsxVrWmt\",\n--Cx\n\"xaddBmr\",\"xaddVmr\",\n\"cmppsXrvmu|cmpssXrvmu|cmppdXrvmu|cmpsdXrvmu\",\"$movntiVmr|\",\n\"pinsrwPrvWmu\",\"pextrwDrPmu\",\n\"shufpsXrvmu||shufpdXrvmu\",\"$cmpxchg!Qmp\",\n\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\n--Dx\n\"||addsubpdXrvm|addsubpsXrvm\",\"psrlwPrvm\",\"psrldPrvm\",\"psrlqPrvm\",\n\"paddqPrvm\",\"pmullwPrvm\",\n\"|movq2dqXrMm|movqXmr|movdq2qMrXm$\",\"pmovmskbVrMm||pmovmskbVrXm\",\n\"psubusbPrvm\",\"psubuswPrvm\",\"pminubPrvm\",\"pandPrvm\",\n\"paddusbPrvm\",\"padduswPrvm\",\"pmaxubPrvm\",\"pandnPrvm\",\n--Ex\n\"pavgbPrvm\",\"psrawPrvm\",\"psradPrvm\",\"pavgwPrvm\",\n\"pmulhuwPrvm\",\"pmulhwPrvm\",\n\"|cvtdq2pdXrm|cvttpd2dqXrm|cvtpd2dqXrm\",\"$movntqMmr||$movntdqXmr\",\n\"psubsbPrvm\",\"psubswPrvm\",\"pminswPrvm\",\"porPrvm\",\n\"paddsbPrvm\",\"paddswPrvm\",\"pmaxswPrvm\",\"pxorPrvm\",\n--Fx\n\"|||lddquXrm\",\"psllwPrvm\",\"pslldPrvm\",\"psllqPrvm\",\n\"pmuludqPrvm\",\"pmaddwdPrvm\",\"psadbwPrvm\",\"maskmovqMrm||maskmovdquXrm$\",\n\"psubbPrvm\",\"psubwPrvm\",\"psubdPrvm\",\"psubqPrvm\",\n\"paddbPrvm\",\"paddwPrvm\",\"padddPrvm\",\"ud\",\n}\nassert(map_opc2[255] == \"ud\")\n\n-- Map for three-byte opcodes. Can't wait for their next invention.\nlocal map_opc3 = {\n[\"38\"] = { -- [66] 0f 38 xx\n--0x\n[0]=\"pshufbPrvm\",\"phaddwPrvm\",\"phadddPrvm\",\"phaddswPrvm\",\n\"pmaddubswPrvm\",\"phsubwPrvm\",\"phsubdPrvm\",\"phsubswPrvm\",\n\"psignbPrvm\",\"psignwPrvm\",\"psigndPrvm\",\"pmulhrswPrvm\",\n\"||permilpsXrvm\",\"||permilpdXrvm\",nil,nil,\n--1x\n\"||pblendvbXrma\",nil,nil,nil,\n\"||blendvpsXrma\",\"||blendvpdXrma\",\"||permpsXrvm\",\"||ptestXrm\",\n\"||broadcastssXrm\",\"||broadcastsdXrm\",\"||broadcastf128XrlXm\",nil,\n\"pabsbPrm\",\"pabswPrm\",\"pabsdPrm\",nil,\n--2x\n\"||pmovsxbwXrm\",\"||pmovsxbdXrm\",\"||pmovsxbqXrm\",\"||pmovsxwdXrm\",\n\"||pmovsxwqXrm\",\"||pmovsxdqXrm\",nil,nil,\n\"||pmuldqXrvm\",\"||pcmpeqqXrvm\",\"||$movntdqaXrm\",\"||packusdwXrvm\",\n\"||maskmovpsXrvm\",\"||maskmovpdXrvm\",\"||maskmovpsXmvr\",\"||maskmovpdXmvr\",\n--3x\n\"||pmovzxbwXrm\",\"||pmovzxbdXrm\",\"||pmovzxbqXrm\",\"||pmovzxwdXrm\",\n\"||pmovzxwqXrm\",\"||pmovzxdqXrm\",\"||permdXrvm\",\"||pcmpgtqXrvm\",\n\"||pminsbXrvm\",\"||pminsdXrvm\",\"||pminuwXrvm\",\"||pminudXrvm\",\n\"||pmaxsbXrvm\",\"||pmaxsdXrvm\",\"||pmaxuwXrvm\",\"||pmaxudXrvm\",\n--4x\n\"||pmulddXrvm\",\"||phminposuwXrm\",nil,nil,\nnil,\"||psrlvVSXrvm\",\"||psravdXrvm\",\"||psllvVSXrvm\",\n--5x\n[0x58] = \"||pbroadcastdXrlXm\",[0x59] = \"||pbroadcastqXrlXm\",\n[0x5a] = \"||broadcasti128XrlXm\",\n--7x\n[0x78] = \"||pbroadcastbXrlXm\",[0x79] = \"||pbroadcastwXrlXm\",\n--8x\n[0x8c] = \"||pmaskmovXrvVSm\",\n[0x8e] = \"||pmaskmovVSmXvr\",\n--Dx\n[0xdc] = \"||aesencXrvm\", [0xdd] = \"||aesenclastXrvm\",\n[0xde] = \"||aesdecXrvm\", [0xdf] = \"||aesdeclastXrvm\",\n--Fx\n[0xf0] = \"|||crc32TrBmt\",[0xf1] = \"|||crc32TrVmt\",\n},\n\n[\"3a\"] = { -- [66] 0f 3a xx\n--0x\n[0x00]=\"||permqXrmu\",\"||permpdXrmu\",\"||pblenddXrvmu\",nil,\n\"||permilpsXrmu\",\"||permilpdXrmu\",\"||perm2f128Xrvmu\",nil,\n\"||roundpsXrmu\",\"||roundpdXrmu\",\"||roundssXrvmu\",\"||roundsdXrvmu\",\n\"||blendpsXrvmu\",\"||blendpdXrvmu\",\"||pblendwXrvmu\",\"palignrPrvmu\",\n--1x\nnil,nil,nil,nil,\n\"||pextrbVmXru\",\"||pextrwVmXru\",\"||pextrVmSXru\",\"||extractpsVmXru\",\n\"||insertf128XrvlXmu\",\"||extractf128XlXmYru\",nil,nil,\nnil,nil,nil,nil,\n--2x\n\"||pinsrbXrvVmu\",\"||insertpsXrvmu\",\"||pinsrXrvVmuS\",nil,\n--3x\n[0x38] = \"||inserti128Xrvmu\",[0x39] = \"||extracti128XlXmYru\",\n--4x\n[0x40] = \"||dppsXrvmu\",\n[0x41] = \"||dppdXrvmu\",\n[0x42] = \"||mpsadbwXrvmu\",\n[0x44] = \"||pclmulqdqXrvmu\",\n[0x46] = \"||perm2i128Xrvmu\",\n[0x4a] = \"||blendvpsXrvmb\",[0x4b] = \"||blendvpdXrvmb\",\n[0x4c] = \"||pblendvbXrvmb\",\n--6x\n[0x60] = \"||pcmpestrmXrmu\",[0x61] = \"||pcmpestriXrmu\",\n[0x62] = \"||pcmpistrmXrmu\",[0x63] = \"||pcmpistriXrmu\",\n[0xdf] = \"||aeskeygenassistXrmu\",\n},\n}\n\n-- Map for VMX/SVM opcodes 0F 01 C0-FF (sgdt group with register operands).\nlocal map_opcvm = {\n[0xc1]=\"vmcall\",[0xc2]=\"vmlaunch\",[0xc3]=\"vmresume\",[0xc4]=\"vmxoff\",\n[0xc8]=\"monitor\",[0xc9]=\"mwait\",\n[0xd8]=\"vmrun\",[0xd9]=\"vmmcall\",[0xda]=\"vmload\",[0xdb]=\"vmsave\",\n[0xdc]=\"stgi\",[0xdd]=\"clgi\",[0xde]=\"skinit\",[0xdf]=\"invlpga\",\n[0xf8]=\"swapgs\",[0xf9]=\"rdtscp\",\n}\n\n-- Map for FP opcodes. And you thought stack machines are simple?\nlocal map_opcfp = {\n-- D8-DF 00-BF: opcodes with a memory operand.\n-- D8\n[0]=\"faddFm\",\"fmulFm\",\"fcomFm\",\"fcompFm\",\"fsubFm\",\"fsubrFm\",\"fdivFm\",\"fdivrFm\",\n\"fldFm\",nil,\"fstFm\",\"fstpFm\",\"fldenvVm\",\"fldcwWm\",\"fnstenvVm\",\"fnstcwWm\",\n-- DA\n\"fiaddDm\",\"fimulDm\",\"ficomDm\",\"ficompDm\",\n\"fisubDm\",\"fisubrDm\",\"fidivDm\",\"fidivrDm\",\n-- DB\n\"fildDm\",\"fisttpDm\",\"fistDm\",\"fistpDm\",nil,\"fld twordFmp\",nil,\"fstp twordFmp\",\n-- DC\n\"faddGm\",\"fmulGm\",\"fcomGm\",\"fcompGm\",\"fsubGm\",\"fsubrGm\",\"fdivGm\",\"fdivrGm\",\n-- DD\n\"fldGm\",\"fisttpQm\",\"fstGm\",\"fstpGm\",\"frstorDmp\",nil,\"fnsaveDmp\",\"fnstswWm\",\n-- DE\n\"fiaddWm\",\"fimulWm\",\"ficomWm\",\"ficompWm\",\n\"fisubWm\",\"fisubrWm\",\"fidivWm\",\"fidivrWm\",\n-- DF\n\"fildWm\",\"fisttpWm\",\"fistWm\",\"fistpWm\",\n\"fbld twordFmp\",\"fildQm\",\"fbstp twordFmp\",\"fistpQm\",\n-- xx C0-FF: opcodes with a pseudo-register operand.\n-- D8\n\"faddFf\",\"fmulFf\",\"fcomFf\",\"fcompFf\",\"fsubFf\",\"fsubrFf\",\"fdivFf\",\"fdivrFf\",\n-- D9\n\"fldFf\",\"fxchFf\",{\"fnop\"},nil,\n{\"fchs\",\"fabs\",nil,nil,\"ftst\",\"fxam\"},\n{\"fld1\",\"fldl2t\",\"fldl2e\",\"fldpi\",\"fldlg2\",\"fldln2\",\"fldz\"},\n{\"f2xm1\",\"fyl2x\",\"fptan\",\"fpatan\",\"fxtract\",\"fprem1\",\"fdecstp\",\"fincstp\"},\n{\"fprem\",\"fyl2xp1\",\"fsqrt\",\"fsincos\",\"frndint\",\"fscale\",\"fsin\",\"fcos\"},\n-- DA\n\"fcmovbFf\",\"fcmoveFf\",\"fcmovbeFf\",\"fcmovuFf\",nil,{nil,\"fucompp\"},nil,nil,\n-- DB\n\"fcmovnbFf\",\"fcmovneFf\",\"fcmovnbeFf\",\"fcmovnuFf\",\n{nil,nil,\"fnclex\",\"fninit\"},\"fucomiFf\",\"fcomiFf\",nil,\n-- DC\n\"fadd toFf\",\"fmul toFf\",nil,nil,\n\"fsub toFf\",\"fsubr toFf\",\"fdivr toFf\",\"fdiv toFf\",\n-- DD\n\"ffreeFf\",nil,\"fstFf\",\"fstpFf\",\"fucomFf\",\"fucompFf\",nil,nil,\n-- DE\n\"faddpFf\",\"fmulpFf\",nil,{nil,\"fcompp\"},\n\"fsubrpFf\",\"fsubpFf\",\"fdivrpFf\",\"fdivpFf\",\n-- DF\nnil,nil,nil,nil,{\"fnstsw ax\"},\"fucomipFf\",\"fcomipFf\",nil,\n}\nassert(map_opcfp[126] == \"fcomipFf\")\n\n-- Map for opcode groups. The subkey is sp from the ModRM byte.\nlocal map_opcgroup = {\n  arith = { \"add\", \"or\", \"adc\", \"sbb\", \"and\", \"sub\", \"xor\", \"cmp\" },\n  shift = { \"rol\", \"ror\", \"rcl\", \"rcr\", \"shl\", \"shr\", \"sal\", \"sar\" },\n  testb = { \"testBmi\", \"testBmi\", \"not\", \"neg\", \"mul\", \"imul\", \"div\", \"idiv\" },\n  testv = { \"testVmi\", \"testVmi\", \"not\", \"neg\", \"mul\", \"imul\", \"div\", \"idiv\" },\n  incb = { \"inc\", \"dec\" },\n  incd = { \"inc\", \"dec\", \"callUmp\", \"$call farDmp\",\n\t   \"jmpUmp\", \"$jmp farDmp\", \"pushUm\" },\n  sldt = { \"sldt\", \"str\", \"lldt\", \"ltr\", \"verr\", \"verw\" },\n  sgdt = { \"vm*$sgdt\", \"vm*$sidt\", \"$lgdt\", \"vm*$lidt\",\n\t   \"smsw\", nil, \"lmsw\", \"vm*$invlpg\" },\n  bt = { nil, nil, nil, nil, \"bt\", \"bts\", \"btr\", \"btc\" },\n  cmpxchg = { nil, \"sz*,cmpxchg8bQmp,cmpxchg16bXmp\", nil, nil,\n\t      nil, nil, \"vmptrld|vmxon|vmclear\", \"vmptrst\" },\n  pshiftw = { nil, nil, \"psrlw\", nil, \"psraw\", nil, \"psllw\" },\n  pshiftd = { nil, nil, \"psrld\", nil, \"psrad\", nil, \"pslld\" },\n  pshiftq = { nil, nil, \"psrlq\", nil, nil, nil, \"psllq\" },\n  pshiftdq = { nil, nil, \"psrlq\", \"psrldq\", nil, nil, \"psllq\", \"pslldq\" },\n  fxsave = { \"$fxsave\", \"$fxrstor\", \"$ldmxcsr\", \"$stmxcsr\",\n\t     nil, \"lfenceDp$\", \"mfenceDp$\", \"sfenceDp$clflush\" },\n  prefetch = { \"prefetch\", \"prefetchw\" },\n  prefetcht = { \"prefetchnta\", \"prefetcht0\", \"prefetcht1\", \"prefetcht2\" },\n}\n\n------------------------------------------------------------------------------\n\n-- Maps for register names.\nlocal map_regs = {\n  B = { \"al\", \"cl\", \"dl\", \"bl\", \"ah\", \"ch\", \"dh\", \"bh\",\n\t\"r8b\", \"r9b\", \"r10b\", \"r11b\", \"r12b\", \"r13b\", \"r14b\", \"r15b\" },\n  B64 = { \"al\", \"cl\", \"dl\", \"bl\", \"spl\", \"bpl\", \"sil\", \"dil\",\n\t  \"r8b\", \"r9b\", \"r10b\", \"r11b\", \"r12b\", \"r13b\", \"r14b\", \"r15b\" },\n  W = { \"ax\", \"cx\", \"dx\", \"bx\", \"sp\", \"bp\", \"si\", \"di\",\n\t\"r8w\", \"r9w\", \"r10w\", \"r11w\", \"r12w\", \"r13w\", \"r14w\", \"r15w\" },\n  D = { \"eax\", \"ecx\", \"edx\", \"ebx\", \"esp\", \"ebp\", \"esi\", \"edi\",\n\t\"r8d\", \"r9d\", \"r10d\", \"r11d\", \"r12d\", \"r13d\", \"r14d\", \"r15d\" },\n  Q = { \"rax\", \"rcx\", \"rdx\", \"rbx\", \"rsp\", \"rbp\", \"rsi\", \"rdi\",\n\t\"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\" },\n  M = { \"mm0\", \"mm1\", \"mm2\", \"mm3\", \"mm4\", \"mm5\", \"mm6\", \"mm7\",\n\t\"mm0\", \"mm1\", \"mm2\", \"mm3\", \"mm4\", \"mm5\", \"mm6\", \"mm7\" }, -- No x64 ext!\n  X = { \"xmm0\", \"xmm1\", \"xmm2\", \"xmm3\", \"xmm4\", \"xmm5\", \"xmm6\", \"xmm7\",\n\t\"xmm8\", \"xmm9\", \"xmm10\", \"xmm11\", \"xmm12\", \"xmm13\", \"xmm14\", \"xmm15\" },\n  Y = { \"ymm0\", \"ymm1\", \"ymm2\", \"ymm3\", \"ymm4\", \"ymm5\", \"ymm6\", \"ymm7\",\n\t\"ymm8\", \"ymm9\", \"ymm10\", \"ymm11\", \"ymm12\", \"ymm13\", \"ymm14\", \"ymm15\" },\n}\nlocal map_segregs = { \"es\", \"cs\", \"ss\", \"ds\", \"fs\", \"gs\", \"segr6\", \"segr7\" }\n\n-- Maps for size names.\nlocal map_sz2n = {\n  B = 1, W = 2, D = 4, Q = 8, M = 8, X = 16, Y = 32,\n}\nlocal map_sz2prefix = {\n  B = \"byte\", W = \"word\", D = \"dword\",\n  Q = \"qword\",\n  M = \"qword\", X = \"xword\", Y = \"yword\",\n  F = \"dword\", G = \"qword\", -- No need for sizes/register names for these two.\n}\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local code, pos, hex = ctx.code, ctx.pos, \"\"\n  local hmax = ctx.hexdump\n  if hmax > 0 then\n    for i=ctx.start,pos-1 do\n      hex = hex..format(\"%02X\", byte(code, i, i))\n    end\n    if #hex > hmax then hex = sub(hex, 1, hmax)..\". \"\n    else hex = hex..rep(\" \", hmax-#hex+2) end\n  end\n  if operands then text = text..\" \"..operands end\n  if ctx.o16 then text = \"o16 \"..text; ctx.o16 = false end\n  if ctx.a32 then text = \"a32 \"..text; ctx.a32 = false end\n  if ctx.rep then text = ctx.rep..\" \"..text; ctx.rep = false end\n  if ctx.rex then\n    local t = (ctx.rexw and \"w\" or \"\")..(ctx.rexr and \"r\" or \"\")..\n\t      (ctx.rexx and \"x\" or \"\")..(ctx.rexb and \"b\" or \"\")..\n\t      (ctx.vexl and \"l\" or \"\")\n    if ctx.vexv and ctx.vexv ~= 0 then t = t..\"v\"..ctx.vexv end\n    if t ~= \"\" then text = ctx.rex..\".\"..t..\" \"..text\n    elseif ctx.rex == \"vex\" then text = \"v\"..text end\n    ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false\n    ctx.rex = false; ctx.vexl = false; ctx.vexv = false\n  end\n  if ctx.seg then\n    local text2, n = gsub(text, \"%[\", \"[\"..ctx.seg..\":\")\n    if n == 0 then text = ctx.seg..\" \"..text else text = text2 end\n    ctx.seg = false\n  end\n  if ctx.lock then text = \"lock \"..text; ctx.lock = false end\n  local imm = ctx.imm\n  if imm then\n    local sym = ctx.symtab[imm]\n    if sym then text = text..\"\\t->\"..sym end\n  end\n  ctx.out(format(\"%08x  %s%s\\n\", ctx.addr+ctx.start, hex, text))\n  ctx.mrm = false\n  ctx.vexv = false\n  ctx.start = pos\n  ctx.imm = nil\nend\n\n-- Clear all prefix flags.\nlocal function clearprefixes(ctx)\n  ctx.o16 = false; ctx.seg = false; ctx.lock = false; ctx.rep = false\n  ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false\n  ctx.rex = false; ctx.a32 = false; ctx.vexl = false\nend\n\n-- Fallback for incomplete opcodes at the end.\nlocal function incomplete(ctx)\n  ctx.pos = ctx.stop+1\n  clearprefixes(ctx)\n  return putop(ctx, \"(incomplete)\")\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  clearprefixes(ctx)\n  return putop(ctx, \"(unknown)\")\nend\n\n-- Return an immediate of the specified size.\nlocal function getimm(ctx, pos, n)\n  if pos+n-1 > ctx.stop then return incomplete(ctx) end\n  local code = ctx.code\n  if n == 1 then\n    local b1 = byte(code, pos, pos)\n    return b1\n  elseif n == 2 then\n    local b1, b2 = byte(code, pos, pos+1)\n    return b1+b2*256\n  else\n    local b1, b2, b3, b4 = byte(code, pos, pos+3)\n    local imm = b1+b2*256+b3*65536+b4*16777216\n    ctx.imm = imm\n    return imm\n  end\nend\n\n-- Process pattern string and generate the operands.\nlocal function putpat(ctx, name, pat)\n  local operands, regs, sz, mode, sp, rm, sc, rx, sdisp\n  local code, pos, stop, vexl = ctx.code, ctx.pos, ctx.stop, ctx.vexl\n\n  -- Chars used: 1DFGIMPQRSTUVWXYabcdfgijlmoprstuvwxyz\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"V\" or p == \"U\" then\n      if ctx.rexw then sz = \"Q\"; ctx.rexw = false\n      elseif ctx.o16 then sz = \"W\"; ctx.o16 = false\n      elseif p == \"U\" and ctx.x64 then sz = \"Q\"\n      else sz = \"D\" end\n      regs = map_regs[sz]\n    elseif p == \"T\" then\n      if ctx.rexw then sz = \"Q\"; ctx.rexw = false else sz = \"D\" end\n      regs = map_regs[sz]\n    elseif p == \"B\" then\n      sz = \"B\"\n      regs = ctx.rex and map_regs.B64 or map_regs.B\n    elseif match(p, \"[WDQMXYFG]\") then\n      sz = p\n      if sz == \"X\" and vexl then sz = \"Y\"; ctx.vexl = false end\n      regs = map_regs[sz]\n    elseif p == \"P\" then\n      sz = ctx.o16 and \"X\" or \"M\"; ctx.o16 = false\n      if sz == \"X\" and vexl then sz = \"Y\"; ctx.vexl = false end\n      regs = map_regs[sz]\n    elseif p == \"S\" then\n      name = name..lower(sz)\n    elseif p == \"s\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = imm <= 127 and format(\"+0x%02x\", imm)\n\t\t     or format(\"-0x%02x\", 256-imm)\n      pos = pos+1\n    elseif p == \"u\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = format(\"0x%02x\", imm)\n      pos = pos+1\n    elseif p == \"b\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = regs[imm/16+1]\n      pos = pos+1\n    elseif p == \"w\" then\n      local imm = getimm(ctx, pos, 2); if not imm then return end\n      x = format(\"0x%x\", imm)\n      pos = pos+2\n    elseif p == \"o\" then -- [offset]\n      if ctx.x64 then\n\tlocal imm1 = getimm(ctx, pos, 4); if not imm1 then return end\n\tlocal imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end\n\tx = format(\"[0x%08x%08x]\", imm2, imm1)\n\tpos = pos+8\n      else\n\tlocal imm = getimm(ctx, pos, 4); if not imm then return end\n\tx = format(\"[0x%08x]\", imm)\n\tpos = pos+4\n      end\n    elseif p == \"i\" or p == \"I\" then\n      local n = map_sz2n[sz]\n      if n == 8 and ctx.x64 and p == \"I\" then\n\tlocal imm1 = getimm(ctx, pos, 4); if not imm1 then return end\n\tlocal imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end\n\tx = format(\"0x%08x%08x\", imm2, imm1)\n      else\n\tif n == 8 then n = 4 end\n\tlocal imm = getimm(ctx, pos, n); if not imm then return end\n\tif sz == \"Q\" and (imm < 0 or imm > 0x7fffffff) then\n\t  imm = (0xffffffff+1)-imm\n\t  x = format(imm > 65535 and \"-0x%08x\" or \"-0x%x\", imm)\n\telse\n\t  x = format(imm > 65535 and \"0x%08x\" or \"0x%x\", imm)\n\tend\n      end\n      pos = pos+n\n    elseif p == \"j\" then\n      local n = map_sz2n[sz]\n      if n == 8 then n = 4 end\n      local imm = getimm(ctx, pos, n); if not imm then return end\n      if sz == \"B\" and imm > 127 then imm = imm-256\n      elseif imm > 2147483647 then imm = imm-4294967296 end\n      pos = pos+n\n      imm = imm + pos + ctx.addr\n      if imm > 4294967295 and not ctx.x64 then imm = imm-4294967296 end\n      ctx.imm = imm\n      if sz == \"W\" then\n\tx = format(\"word 0x%04x\", imm%65536)\n      elseif ctx.x64 then\n\tlocal lo = imm % 0x1000000\n\tx = format(\"0x%02x%06x\", (imm-lo) / 0x1000000, lo)\n      else\n\tx = \"0x\"..tohex(imm)\n      end\n    elseif p == \"R\" then\n      local r = byte(code, pos-1, pos-1)%8\n      if ctx.rexb then r = r + 8; ctx.rexb = false end\n      x = regs[r+1]\n    elseif p == \"a\" then x = regs[1]\n    elseif p == \"c\" then x = \"cl\"\n    elseif p == \"d\" then x = \"dx\"\n    elseif p == \"1\" then x = \"1\"\n    else\n      if not mode then\n\tmode = ctx.mrm\n\tif not mode then\n\t  if pos > stop then return incomplete(ctx) end\n\t  mode = byte(code, pos, pos)\n\t  pos = pos+1\n\tend\n\trm = mode%8; mode = (mode-rm)/8\n\tsp = mode%8; mode = (mode-sp)/8\n\tsdisp = \"\"\n\tif mode < 3 then\n\t  if rm == 4 then\n\t    if pos > stop then return incomplete(ctx) end\n\t    sc = byte(code, pos, pos)\n\t    pos = pos+1\n\t    rm = sc%8; sc = (sc-rm)/8\n\t    rx = sc%8; sc = (sc-rx)/8\n\t    if ctx.rexx then rx = rx + 8; ctx.rexx = false end\n\t    if rx == 4 then rx = nil end\n\t  end\n\t  if mode > 0 or rm == 5 then\n\t    local dsz = mode\n\t    if dsz ~= 1 then dsz = 4 end\n\t    local disp = getimm(ctx, pos, dsz); if not disp then return end\n\t    if mode == 0 then rm = nil end\n\t    if rm or rx or (not sc and ctx.x64 and not ctx.a32) then\n\t      if dsz == 1 and disp > 127 then\n\t\tsdisp = format(\"-0x%x\", 256-disp)\n\t      elseif disp >= 0 and disp <= 0x7fffffff then\n\t\tsdisp = format(\"+0x%x\", disp)\n\t      else\n\t\tsdisp = format(\"-0x%x\", (0xffffffff+1)-disp)\n\t      end\n\t    else\n\t      sdisp = format(ctx.x64 and not ctx.a32 and\n\t\tnot (disp >= 0 and disp <= 0x7fffffff)\n\t\tand \"0xffffffff%08x\" or \"0x%08x\", disp)\n\t    end\n\t    pos = pos+dsz\n\t  end\n\tend\n\tif rm and ctx.rexb then rm = rm + 8; ctx.rexb = false end\n\tif ctx.rexr then sp = sp + 8; ctx.rexr = false end\n      end\n      if p == \"m\" then\n\tif mode == 3 then x = regs[rm+1]\n\telse\n\t  local aregs = ctx.a32 and map_regs.D or ctx.aregs\n\t  local srm, srx = \"\", \"\"\n\t  if rm then srm = aregs[rm+1]\n\t  elseif not sc and ctx.x64 and not ctx.a32 then srm = \"rip\" end\n\t  ctx.a32 = false\n\t  if rx then\n\t    if rm then srm = srm..\"+\" end\n\t    srx = aregs[rx+1]\n\t    if sc > 0 then srx = srx..\"*\"..(2^sc) end\n\t  end\n\t  x = format(\"[%s%s%s]\", srm, srx, sdisp)\n\tend\n\tif mode < 3 and\n\t   (not match(pat, \"[aRrgp]\") or match(pat, \"t\")) then -- Yuck.\n\t  x = map_sz2prefix[sz]..\" \"..x\n\tend\n      elseif p == \"r\" then x = regs[sp+1]\n      elseif p == \"g\" then x = map_segregs[sp+1]\n      elseif p == \"p\" then -- Suppress prefix.\n      elseif p == \"f\" then x = \"st\"..rm\n      elseif p == \"x\" then\n\tif sp == 0 and ctx.lock and not ctx.x64 then\n\t  x = \"CR8\"; ctx.lock = false\n\telse\n\t  x = \"CR\"..sp\n\tend\n      elseif p == \"v\" then\n\tif ctx.vexv then\n\t  x = regs[ctx.vexv+1]; ctx.vexv = false\n\tend\n      elseif p == \"y\" then x = \"DR\"..sp\n      elseif p == \"z\" then x = \"TR\"..sp\n      elseif p == \"l\" then vexl = false\n      elseif p == \"t\" then\n      else\n\terror(\"bad pattern `\"..pat..\"'\")\n      end\n    end\n    if x then operands = operands and operands..\", \"..x or x end\n  end\n  ctx.pos = pos\n  return putop(ctx, name, operands)\nend\n\n-- Forward declaration.\nlocal map_act\n\n-- Fetch and cache MRM byte.\nlocal function getmrm(ctx)\n  local mrm = ctx.mrm\n  if not mrm then\n    local pos = ctx.pos\n    if pos > ctx.stop then return nil end\n    mrm = byte(ctx.code, pos, pos)\n    ctx.pos = pos+1\n    ctx.mrm = mrm\n  end\n  return mrm\nend\n\n-- Dispatch to handler depending on pattern.\nlocal function dispatch(ctx, opat, patgrp)\n  if not opat then return unknown(ctx) end\n  if match(opat, \"%|\") then -- MMX/SSE variants depending on prefix.\n    local p\n    if ctx.rep then\n      p = ctx.rep==\"rep\" and \"%|([^%|]*)\" or \"%|[^%|]*%|[^%|]*%|([^%|]*)\"\n      ctx.rep = false\n    elseif ctx.o16 then p = \"%|[^%|]*%|([^%|]*)\"; ctx.o16 = false\n    else p = \"^[^%|]*\" end\n    opat = match(opat, p)\n    if not opat then return unknown(ctx) end\n--    ctx.rep = false; ctx.o16 = false\n    --XXX fails for 66 f2 0f 38 f1 06  crc32 eax,WORD PTR [esi]\n    --XXX remove in branches?\n  end\n  if match(opat, \"%$\") then -- reg$mem variants.\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    opat = match(opat, mrm >= 192 and \"^[^%$]*\" or \"%$(.*)\")\n    if opat == \"\" then return unknown(ctx) end\n  end\n  if opat == \"\" then return unknown(ctx) end\n  local name, pat = match(opat, \"^([a-z0-9 ]*)(.*)\")\n  if pat == \"\" and patgrp then pat = patgrp end\n  return map_act[sub(pat, 1, 1)](ctx, name, pat)\nend\n\n-- Get a pattern from an opcode map and dispatch to handler.\nlocal function dispatchmap(ctx, opcmap)\n  local pos = ctx.pos\n  local opat = opcmap[byte(ctx.code, pos, pos)]\n  pos = pos + 1\n  ctx.pos = pos\n  return dispatch(ctx, opat)\nend\n\n-- Map for action codes. The key is the first char after the name.\nmap_act = {\n  -- Simple opcodes without operands.\n  [\"\"] = function(ctx, name, pat)\n    return putop(ctx, name)\n  end,\n\n  -- Operand size chars fall right through.\n  B = putpat, W = putpat, D = putpat, Q = putpat,\n  V = putpat, U = putpat, T = putpat,\n  M = putpat, X = putpat, P = putpat,\n  F = putpat, G = putpat, Y = putpat,\n\n  -- Collect prefixes.\n  [\":\"] = function(ctx, name, pat)\n    ctx[pat == \":\" and name or sub(pat, 2)] = name\n    if ctx.pos - ctx.start > 5 then return unknown(ctx) end -- Limit #prefixes.\n  end,\n\n  -- Chain to special handler specified by name.\n  [\"*\"] = function(ctx, name, pat)\n    return map_act[name](ctx, name, sub(pat, 2))\n  end,\n\n  -- Use named subtable for opcode group.\n  [\"!\"] = function(ctx, name, pat)\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    return dispatch(ctx, map_opcgroup[name][((mrm-(mrm%8))/8)%8+1], sub(pat, 2))\n  end,\n\n  -- o16,o32[,o64] variants.\n  sz = function(ctx, name, pat)\n    if ctx.o16 then ctx.o16 = false\n    else\n      pat = match(pat, \",(.*)\")\n      if ctx.rexw then\n\tlocal p = match(pat, \",(.*)\")\n\tif p then pat = p; ctx.rexw = false end\n      end\n    end\n    pat = match(pat, \"^[^,]*\")\n    return dispatch(ctx, pat)\n  end,\n\n  -- Two-byte opcode dispatch.\n  opc2 = function(ctx, name, pat)\n    return dispatchmap(ctx, map_opc2)\n  end,\n\n  -- Three-byte opcode dispatch.\n  opc3 = function(ctx, name, pat)\n    return dispatchmap(ctx, map_opc3[pat])\n  end,\n\n  -- VMX/SVM dispatch.\n  vm = function(ctx, name, pat)\n    return dispatch(ctx, map_opcvm[ctx.mrm])\n  end,\n\n  -- Floating point opcode dispatch.\n  fp = function(ctx, name, pat)\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    local rm = mrm%8\n    local idx = pat*8 + ((mrm-rm)/8)%8\n    if mrm >= 192 then idx = idx + 64 end\n    local opat = map_opcfp[idx]\n    if type(opat) == \"table\" then opat = opat[rm+1] end\n    return dispatch(ctx, opat)\n  end,\n\n  -- REX prefix.\n  rex = function(ctx, name, pat)\n    if ctx.rex then return unknown(ctx) end -- Only 1 REX or VEX prefix allowed.\n    for p in gmatch(pat, \".\") do ctx[\"rex\"..p] = true end\n    ctx.rex = \"rex\"\n  end,\n\n  -- VEX prefix.\n  vex = function(ctx, name, pat)\n    if ctx.rex then return unknown(ctx) end -- Only 1 REX or VEX prefix allowed.\n    ctx.rex = \"vex\"\n    local pos = ctx.pos\n    if ctx.mrm then\n      ctx.mrm = nil\n      pos = pos-1\n    end\n    local b = byte(ctx.code, pos, pos)\n    if not b then return incomplete(ctx) end\n    pos = pos+1\n    if b < 128 then ctx.rexr = true end\n    local m = 1\n    if pat == \"3\" then\n      m = b%32; b = (b-m)/32\n      local nb = b%2; b = (b-nb)/2\n      if nb == 0 then ctx.rexb = true end\n      local nx = b%2; b = (b-nx)/2\n      if nx == 0 then ctx.rexx = true end\n      b = byte(ctx.code, pos, pos)\n      if not b then return incomplete(ctx) end\n      pos = pos+1\n      if b >= 128 then ctx.rexw = true end\n    end\n    ctx.pos = pos\n    local map\n    if m == 1 then map = map_opc2\n    elseif m == 2 then map = map_opc3[\"38\"]\n    elseif m == 3 then map = map_opc3[\"3a\"]\n    else return unknown(ctx) end\n    local p = b%4; b = (b-p)/4\n    if p == 1 then ctx.o16 = \"o16\"\n    elseif p == 2 then ctx.rep = \"rep\"\n    elseif p == 3 then ctx.rep = \"repne\" end\n    local l = b%2; b = (b-l)/2\n    if l ~= 0 then ctx.vexl = true end\n    ctx.vexv = (-1-b)%16\n    return dispatchmap(ctx, map)\n  end,\n\n  -- Special case for nop with REX prefix.\n  nop = function(ctx, name, pat)\n    return dispatch(ctx, ctx.rex and pat or \"nop\")\n  end,\n\n  -- Special case for 0F 77.\n  emms = function(ctx, name, pat)\n    if ctx.rex ~= \"vex\" then\n      return putop(ctx, \"emms\")\n    elseif ctx.vexl then\n      ctx.vexl = false\n      return putop(ctx, \"zeroall\")\n    else\n      return putop(ctx, \"zeroupper\")\n    end\n  end,\n}\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  ofs = ofs + 1\n  ctx.start = ofs\n  ctx.pos = ofs\n  ctx.stop = stop\n  ctx.imm = nil\n  ctx.mrm = false\n  clearprefixes(ctx)\n  while ctx.pos <= stop do dispatchmap(ctx, ctx.map1) end\n  if ctx.pos ~= ctx.start then incomplete(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = (addr or 0) - 1\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 16\n  ctx.x64 = false\n  ctx.map1 = map_opc1_32\n  ctx.aregs = map_regs.D\n  return ctx\nend\n\nlocal function create64(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.x64 = true\n  ctx.map1 = map_opc1_64\n  ctx.aregs = map_regs.Q\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\nlocal function disass64(code, addr, out)\n  create64(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 8 then return map_regs.D[r+1] end\n  return map_regs.X[r-7]\nend\n\nlocal function regname64(r)\n  if r < 16 then return map_regs.Q[r+1] end\n  return map_regs.X[r-15]\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  create64 = create64,\n  disass = disass,\n  disass64 = disass64,\n  regname = regname,\n  regname64 = regname64\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/dump.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT compiler dump module.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module can be used to debug the JIT compiler itself. It dumps the\n-- code representations and structures used in various compiler stages.\n--\n-- Example usage:\n--\n--   luajit -jdump -e \"local x=0; for i=1,1e6 do x=x+i end; print(x)\"\n--   luajit -jdump=im -e \"for i=1,1000 do for j=1,1000 do end end\" | less -R\n--   luajit -jdump=is myapp.lua | less -R\n--   luajit -jdump=-b myapp.lua\n--   luajit -jdump=+aH,myapp.html myapp.lua\n--   luajit -jdump=ixT,myapp.dump myapp.lua\n--\n-- The first argument specifies the dump mode. The second argument gives\n-- the output file name. Default output is to stdout, unless the environment\n-- variable LUAJIT_DUMPFILE is set. The file is overwritten every time the\n-- module is started.\n--\n-- Different features can be turned on or off with the dump mode. If the\n-- mode starts with a '+', the following features are added to the default\n-- set of features; a '-' removes them. Otherwise the features are replaced.\n--\n-- The following dump features are available (* marks the default):\n--\n--  * t  Print a line for each started, ended or aborted trace (see also -jv).\n--  * b  Dump the traced bytecode.\n--  * i  Dump the IR (intermediate representation).\n--    r  Augment the IR with register/stack slots.\n--    s  Dump the snapshot map.\n--  * m  Dump the generated machine code.\n--    x  Print each taken trace exit.\n--    X  Print each taken trace exit and the contents of all registers.\n--    a  Print the IR of aborted traces, too.\n--\n-- The output format can be set with the following characters:\n--\n--    T  Plain text output.\n--    A  ANSI-colored text output\n--    H  Colorized HTML + CSS output.\n--\n-- The default output format is plain text. It's set to ANSI-colored text\n-- if the COLORTERM variable is set. Note: this is independent of any output\n-- redirection, which is actually considered a feature.\n--\n-- You probably want to use less -R to enjoy viewing ANSI-colored text from\n-- a pipe or a file. Add this to your ~/.bashrc: export LESS=\"-R\"\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal funcinfo, funcbc = jutil.funcinfo, jutil.funcbc\nlocal traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek\nlocal tracemc, tracesnap = jutil.tracemc, jutil.tracesnap\nlocal traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr\nlocal bit = require(\"bit\")\nlocal band, shl, shr, tohex = bit.band, bit.lshift, bit.rshift, bit.tohex\nlocal sub, gsub, format = string.sub, string.gsub, string.format\nlocal byte, char, rep = string.byte, string.char, string.rep\nlocal type, tostring = type, tostring\nlocal stdout, stderr = io.stdout, io.stderr\n\n-- Load other modules on-demand.\nlocal bcline, disass\n\n-- Active flag, output file handle and dump mode.\nlocal active, out, dumpmode\n\n------------------------------------------------------------------------------\n\nlocal symtabmt = { __index = false }\nlocal symtab = {}\nlocal nexitsym = 0\n\n-- Fill nested symbol table with per-trace exit stub addresses.\nlocal function fillsymtab_tr(tr, nexit)\n  local t = {}\n  symtabmt.__index = t\n  if jit.arch == \"mips\" or jit.arch == \"mipsel\" then\n    t[traceexitstub(tr, 0)] = \"exit\"\n    return\n  end\n  for i=0,nexit-1 do\n    local addr = traceexitstub(tr, i)\n    if addr < 0 then addr = addr + 2^32 end\n    t[addr] = tostring(i)\n  end\n  local addr = traceexitstub(tr, nexit)\n  if addr then t[addr] = \"stack_check\" end\nend\n\n-- Fill symbol table with trace exit stub addresses.\nlocal function fillsymtab(tr, nexit)\n  local t = symtab\n  if nexitsym == 0 then\n    local ircall = vmdef.ircall\n    for i=0,#ircall do\n      local addr = ircalladdr(i)\n      if addr ~= 0 then\n\tif addr < 0 then addr = addr + 2^32 end\n\tt[addr] = ircall[i]\n      end\n    end\n  end\n  if nexitsym == 1000000 then -- Per-trace exit stubs.\n    fillsymtab_tr(tr, nexit)\n  elseif nexit > nexitsym then -- Shared exit stubs.\n    for i=nexitsym,nexit-1 do\n      local addr = traceexitstub(i)\n      if addr == nil then -- Fall back to per-trace exit stubs.\n\tfillsymtab_tr(tr, nexit)\n\tsetmetatable(symtab, symtabmt)\n\tnexit = 1000000\n\tbreak\n      end\n      if addr < 0 then addr = addr + 2^32 end\n      t[addr] = tostring(i)\n    end\n    nexitsym = nexit\n  end\n  return t\nend\n\nlocal function dumpwrite(s)\n  out:write(s)\nend\n\n-- Disassemble machine code.\nlocal function dump_mcode(tr)\n  local info = traceinfo(tr)\n  if not info then return end\n  local mcode, addr, loop = tracemc(tr)\n  if not mcode then return end\n  if not disass then disass = require(\"jit.dis_\"..jit.arch) end\n  if addr < 0 then addr = addr + 2^32 end\n  out:write(\"---- TRACE \", tr, \" mcode \", #mcode, \"\\n\")\n  local ctx = disass.create(mcode, addr, dumpwrite)\n  ctx.hexdump = 0\n  ctx.symtab = fillsymtab(tr, info.nexit)\n  if loop ~= 0 then\n    symtab[addr+loop] = \"LOOP\"\n    ctx:disass(0, loop)\n    out:write(\"->LOOP:\\n\")\n    ctx:disass(loop, #mcode-loop)\n    symtab[addr+loop] = nil\n  else\n    ctx:disass(0, #mcode)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal irtype_text = {\n  [0] = \"nil\",\n  \"fal\",\n  \"tru\",\n  \"lud\",\n  \"str\",\n  \"p32\",\n  \"thr\",\n  \"pro\",\n  \"fun\",\n  \"p64\",\n  \"cdt\",\n  \"tab\",\n  \"udt\",\n  \"flt\",\n  \"num\",\n  \"i8 \",\n  \"u8 \",\n  \"i16\",\n  \"u16\",\n  \"int\",\n  \"u32\",\n  \"i64\",\n  \"u64\",\n  \"sfp\",\n}\n\nlocal colortype_ansi = {\n  [0] = \"%s\",\n  \"%s\",\n  \"%s\",\n  \"\\027[36m%s\\027[m\",\n  \"\\027[32m%s\\027[m\",\n  \"%s\",\n  \"\\027[1m%s\\027[m\",\n  \"%s\",\n  \"\\027[1m%s\\027[m\",\n  \"%s\",\n  \"\\027[33m%s\\027[m\",\n  \"\\027[31m%s\\027[m\",\n  \"\\027[36m%s\\027[m\",\n  \"\\027[34m%s\\027[m\",\n  \"\\027[34m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n}\n\nlocal function colorize_text(s, t)\n  return s\nend\n\nlocal function colorize_ansi(s, t)\n  return format(colortype_ansi[t], s)\nend\n\nlocal irtype_ansi = setmetatable({},\n  { __index = function(tab, t)\n      local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end })\n\nlocal html_escape = { [\"<\"] = \"&lt;\", [\">\"] = \"&gt;\", [\"&\"] = \"&amp;\", }\n\nlocal function colorize_html(s, t)\n  s = gsub(s, \"[<>&]\", html_escape)\n  return format('<span class=\"irt_%s\">%s</span>', irtype_text[t], s)\nend\n\nlocal irtype_html = setmetatable({},\n  { __index = function(tab, t)\n      local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end })\n\nlocal header_html = [[\n<style type=\"text/css\">\nbackground { background: #ffffff; color: #000000; }\npre.ljdump {\nfont-size: 10pt;\nbackground: #f0f4ff;\ncolor: #000000;\nborder: 1px solid #bfcfff;\npadding: 0.5em;\nmargin-left: 2em;\nmargin-right: 2em;\n}\nspan.irt_str { color: #00a000; }\nspan.irt_thr, span.irt_fun { color: #404040; font-weight: bold; }\nspan.irt_tab { color: #c00000; }\nspan.irt_udt, span.irt_lud { color: #00c0c0; }\nspan.irt_num { color: #4040c0; }\nspan.irt_int, span.irt_i8, span.irt_u8, span.irt_i16, span.irt_u16 { color: #b040b0; }\n</style>\n]]\n\nlocal colorize, irtype\n\n-- Lookup tables to convert some literals into names.\nlocal litname = {\n  [\"SLOAD \"] = setmetatable({}, { __index = function(t, mode)\n    local s = \"\"\n    if band(mode, 1) ~= 0 then s = s..\"P\" end\n    if band(mode, 2) ~= 0 then s = s..\"F\" end\n    if band(mode, 4) ~= 0 then s = s..\"T\" end\n    if band(mode, 8) ~= 0 then s = s..\"C\" end\n    if band(mode, 16) ~= 0 then s = s..\"R\" end\n    if band(mode, 32) ~= 0 then s = s..\"I\" end\n    t[mode] = s\n    return s\n  end}),\n  [\"XLOAD \"] = { [0] = \"\", \"R\", \"V\", \"RV\", \"U\", \"RU\", \"VU\", \"RVU\", },\n  [\"CONV  \"] = setmetatable({}, { __index = function(t, mode)\n    local s = irtype[band(mode, 31)]\n    s = irtype[band(shr(mode, 5), 31)]..\".\"..s\n    if band(mode, 0x800) ~= 0 then s = s..\" sext\" end\n    local c = shr(mode, 14)\n    if c == 2 then s = s..\" index\" elseif c == 3 then s = s..\" check\" end\n    t[mode] = s\n    return s\n  end}),\n  [\"FLOAD \"] = vmdef.irfield,\n  [\"FREF  \"] = vmdef.irfield,\n  [\"FPMATH\"] = vmdef.irfpm,\n  [\"BUFHDR\"] = { [0] = \"RESET\", \"APPEND\" },\n  [\"TOSTR \"] = { [0] = \"INT\", \"NUM\", \"CHAR\" },\n}\n\nlocal function ctlsub(c)\n  if c == \"\\n\" then return \"\\\\n\"\n  elseif c == \"\\r\" then return \"\\\\r\"\n  elseif c == \"\\t\" then return \"\\\\t\"\n  else return format(\"\\\\%03d\", byte(c))\n  end\nend\n\nlocal function fmtfunc(func, pc)\n  local fi = funcinfo(func, pc)\n  if fi.loc then\n    return fi.loc\n  elseif fi.ffid then\n    return vmdef.ffnames[fi.ffid]\n  elseif fi.addr then\n    return format(\"C:%x\", fi.addr)\n  else\n    return \"(?)\"\n  end\nend\n\nlocal function formatk(tr, idx)\n  local k, t, slot = tracek(tr, idx)\n  local tn = type(k)\n  local s\n  if tn == \"number\" then\n    if k == 2^52+2^51 then\n      s = \"bias\"\n    else\n      s = format(\"%+.14g\", k)\n    end\n  elseif tn == \"string\" then\n    s = format(#k > 20 and '\"%.20s\"~' or '\"%s\"', gsub(k, \"%c\", ctlsub))\n  elseif tn == \"function\" then\n    s = fmtfunc(k)\n  elseif tn == \"table\" then\n    s = format(\"{%p}\", k)\n  elseif tn == \"userdata\" then\n    if t == 12 then\n      s = format(\"userdata:%p\", k)\n    else\n      s = format(\"[%p]\", k)\n      if s == \"[0x00000000]\" then s = \"NULL\" end\n    end\n  elseif t == 21 then -- int64_t\n    s = sub(tostring(k), 1, -3)\n    if sub(s, 1, 1) ~= \"-\" then s = \"+\"..s end\n  else\n    s = tostring(k) -- For primitives.\n  end\n  s = colorize(format(\"%-4s\", s), t)\n  if slot then\n    s = format(\"%s @%d\", s, slot)\n  end\n  return s\nend\n\nlocal function printsnap(tr, snap)\n  local n = 2\n  for s=0,snap[1]-1 do\n    local sn = snap[n]\n    if shr(sn, 24) == s then\n      n = n + 1\n      local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS\n      if ref < 0 then\n\tout:write(formatk(tr, ref))\n      elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM\n\tout:write(colorize(format(\"%04d/%04d\", ref, ref+1), 14))\n      else\n\tlocal m, ot, op1, op2 = traceir(tr, ref)\n\tout:write(colorize(format(\"%04d\", ref), band(ot, 31)))\n      end\n      out:write(band(sn, 0x10000) == 0 and \" \" or \"|\") -- SNAP_FRAME\n    else\n      out:write(\"---- \")\n    end\n  end\n  out:write(\"]\\n\")\nend\n\n-- Dump snapshots (not interleaved with IR).\nlocal function dump_snap(tr)\n  out:write(\"---- TRACE \", tr, \" snapshots\\n\")\n  for i=0,1000000000 do\n    local snap = tracesnap(tr, i)\n    if not snap then break end\n    out:write(format(\"#%-3d %04d [ \", i, snap[0]))\n    printsnap(tr, snap)\n  end\nend\n\n-- Return a register name or stack slot for a rid/sp location.\nlocal function ridsp_name(ridsp, ins)\n  if not disass then disass = require(\"jit.dis_\"..jit.arch) end\n  local rid, slot = band(ridsp, 0xff), shr(ridsp, 8)\n  if rid == 253 or rid == 254 then\n    return (slot == 0 or slot == 255) and \" {sink\" or format(\" {%04d\", ins-slot)\n  end\n  if ridsp > 255 then return format(\"[%x]\", slot*4) end\n  if rid < 128 then return disass.regname(rid) end\n  return \"\"\nend\n\n-- Dump CALL* function ref and return optional ctype.\nlocal function dumpcallfunc(tr, ins)\n  local ctype\n  if ins > 0 then\n    local m, ot, op1, op2 = traceir(tr, ins)\n    if band(ot, 31) == 0 then -- nil type means CARG(func, ctype).\n      ins = op1\n      ctype = formatk(tr, op2)\n    end\n  end\n  if ins < 0 then\n    out:write(format(\"[0x%x](\", tonumber((tracek(tr, ins)))))\n  else\n    out:write(format(\"%04d (\", ins))\n  end\n  return ctype\nend\n\n-- Recursively gather CALL* args and dump them.\nlocal function dumpcallargs(tr, ins)\n  if ins < 0 then\n    out:write(formatk(tr, ins))\n  else\n    local m, ot, op1, op2 = traceir(tr, ins)\n    local oidx = 6*shr(ot, 8)\n    local op = sub(vmdef.irnames, oidx+1, oidx+6)\n    if op == \"CARG  \" then\n      dumpcallargs(tr, op1)\n      if op2 < 0 then\n\tout:write(\" \", formatk(tr, op2))\n      else\n\tout:write(\" \", format(\"%04d\", op2))\n      end\n    else\n      out:write(format(\"%04d\", ins))\n    end\n  end\nend\n\n-- Dump IR and interleaved snapshots.\nlocal function dump_ir(tr, dumpsnap, dumpreg)\n  local info = traceinfo(tr)\n  if not info then return end\n  local nins = info.nins\n  out:write(\"---- TRACE \", tr, \" IR\\n\")\n  local irnames = vmdef.irnames\n  local snapref = 65536\n  local snap, snapno\n  if dumpsnap then\n    snap = tracesnap(tr, 0)\n    snapref = snap[0]\n    snapno = 0\n  end\n  for ins=1,nins do\n    if ins >= snapref then\n      if dumpreg then\n\tout:write(format(\"....              SNAP   #%-3d [ \", snapno))\n      else\n\tout:write(format(\"....        SNAP   #%-3d [ \", snapno))\n      end\n      printsnap(tr, snap)\n      snapno = snapno + 1\n      snap = tracesnap(tr, snapno)\n      snapref = snap and snap[0] or 65536\n    end\n    local m, ot, op1, op2, ridsp = traceir(tr, ins)\n    local oidx, t = 6*shr(ot, 8), band(ot, 31)\n    local op = sub(irnames, oidx+1, oidx+6)\n    if op == \"LOOP  \" then\n      if dumpreg then\n\tout:write(format(\"%04d ------------ LOOP ------------\\n\", ins))\n      else\n\tout:write(format(\"%04d ------ LOOP ------------\\n\", ins))\n      end\n    elseif op ~= \"NOP   \" and op ~= \"CARG  \" and\n\t   (dumpreg or op ~= \"RENAME\") then\n      local rid = band(ridsp, 255)\n      if dumpreg then\n\tout:write(format(\"%04d %-6s\", ins, ridsp_name(ridsp, ins)))\n      else\n\tout:write(format(\"%04d \", ins))\n      end\n      out:write(format(\"%s%s %s %s \",\n\t\t       (rid == 254 or rid == 253) and \"}\" or\n\t\t       (band(ot, 128) == 0 and \" \" or \">\"),\n\t\t       band(ot, 64) == 0 and \" \" or \"+\",\n\t\t       irtype[t], op))\n      local m1, m2 = band(m, 3), band(m, 3*4)\n      if sub(op, 1, 4) == \"CALL\" then\n\tlocal ctype\n\tif m2 == 1*4 then -- op2 == IRMlit\n\t  out:write(format(\"%-10s  (\", vmdef.ircall[op2]))\n\telse\n\t  ctype = dumpcallfunc(tr, op2)\n\tend\n\tif op1 ~= -1 then dumpcallargs(tr, op1) end\n\tout:write(\")\")\n\tif ctype then out:write(\" ctype \", ctype) end\n      elseif op == \"CNEW  \" and op2 == -1 then\n\tout:write(formatk(tr, op1))\n      elseif m1 ~= 3 then -- op1 != IRMnone\n\tif op1 < 0 then\n\t  out:write(formatk(tr, op1))\n\telse\n\t  out:write(format(m1 == 0 and \"%04d\" or \"#%-3d\", op1))\n\tend\n\tif m2 ~= 3*4 then -- op2 != IRMnone\n\t  if m2 == 1*4 then -- op2 == IRMlit\n\t    local litn = litname[op]\n\t    if litn and litn[op2] then\n\t      out:write(\"  \", litn[op2])\n\t    elseif op == \"UREFO \" or op == \"UREFC \" then\n\t      out:write(format(\"  #%-3d\", shr(op2, 8)))\n\t    else\n\t      out:write(format(\"  #%-3d\", op2))\n\t    end\n\t  elseif op2 < 0 then\n\t    out:write(\"  \", formatk(tr, op2))\n\t  else\n\t    out:write(format(\"  %04d\", op2))\n\t  end\n\tend\n      end\n      out:write(\"\\n\")\n    end\n  end\n  if snap then\n    if dumpreg then\n      out:write(format(\"....              SNAP   #%-3d [ \", snapno))\n    else\n      out:write(format(\"....        SNAP   #%-3d [ \", snapno))\n    end\n    printsnap(tr, snap)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal recprefix = \"\"\nlocal recdepth = 0\n\n-- Format trace error message.\nlocal function fmterr(err, info)\n  if type(err) == \"number\" then\n    if type(info) == \"function\" then info = fmtfunc(info) end\n    err = format(vmdef.traceerr[err], info)\n  end\n  return err\nend\n\n-- Dump trace states.\nlocal function dump_trace(what, tr, func, pc, otr, oex)\n  if what == \"stop\" or (what == \"abort\" and dumpmode.a) then\n    if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == \"stop\")\n    elseif dumpmode.s then dump_snap(tr) end\n    if dumpmode.m then dump_mcode(tr) end\n  end\n  if what == \"start\" then\n    if dumpmode.H then out:write('<pre class=\"ljdump\">\\n') end\n    out:write(\"---- TRACE \", tr, \" \", what)\n    if otr then out:write(\" \", otr, \"/\", oex) end\n    out:write(\" \", fmtfunc(func, pc), \"\\n\")\n  elseif what == \"stop\" or what == \"abort\" then\n    out:write(\"---- TRACE \", tr, \" \", what)\n    if what == \"abort\" then\n      out:write(\" \", fmtfunc(func, pc), \" -- \", fmterr(otr, oex), \"\\n\")\n    else\n      local info = traceinfo(tr)\n      local link, ltype = info.link, info.linktype\n      if link == tr or link == 0 then\n\tout:write(\" -> \", ltype, \"\\n\")\n      elseif ltype == \"root\" then\n\tout:write(\" -> \", link, \"\\n\")\n      else\n\tout:write(\" -> \", link, \" \", ltype, \"\\n\")\n      end\n    end\n    if dumpmode.H then out:write(\"</pre>\\n\\n\") else out:write(\"\\n\") end\n  else\n    if what == \"flush\" then symtab, nexitsym = {}, 0 end\n    out:write(\"---- TRACE \", what, \"\\n\\n\")\n  end\n  out:flush()\nend\n\n-- Dump recorded bytecode.\nlocal function dump_record(tr, func, pc, depth, callee)\n  if depth ~= recdepth then\n    recdepth = depth\n    recprefix = rep(\" .\", depth)\n  end\n  local line\n  if pc >= 0 then\n    line = bcline(func, pc, recprefix)\n    if dumpmode.H then line = gsub(line, \"[<>&]\", html_escape) end\n  else\n    line = \"0000 \"..recprefix..\" FUNCC      \\n\"\n    callee = func\n  end\n  if pc <= 0 then\n    out:write(sub(line, 1, -2), \"         ; \", fmtfunc(func), \"\\n\")\n  else\n    out:write(line)\n  end\n  if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC\n    out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond.\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Dump taken trace exits.\nlocal function dump_texit(tr, ex, ngpr, nfpr, ...)\n  out:write(\"---- TRACE \", tr, \" exit \", ex, \"\\n\")\n  if dumpmode.X then\n    local regs = {...}\n    if jit.arch == \"x64\" then\n      for i=1,ngpr do\n\tout:write(format(\" %016x\", regs[i]))\n\tif i % 4 == 0 then out:write(\"\\n\") end\n      end\n    else\n      for i=1,ngpr do\n\tout:write(\" \", tohex(regs[i]))\n\tif i % 8 == 0 then out:write(\"\\n\") end\n      end\n    end\n    if jit.arch == \"mips\" or jit.arch == \"mipsel\" then\n      for i=1,nfpr,2 do\n\tout:write(format(\" %+17.14g\", regs[ngpr+i]))\n\tif i % 8 == 7 then out:write(\"\\n\") end\n      end\n    else\n      for i=1,nfpr do\n\tout:write(format(\" %+17.14g\", regs[ngpr+i]))\n\tif i % 4 == 0 then out:write(\"\\n\") end\n      end\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Detach dump handlers.\nlocal function dumpoff()\n  if active then\n    active = false\n    jit.attach(dump_texit)\n    jit.attach(dump_record)\n    jit.attach(dump_trace)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach dump handlers.\nlocal function dumpon(opt, outfile)\n  if active then dumpoff() end\n\n  local colormode = os.getenv(\"COLORTERM\") and \"A\" or \"T\"\n  if opt then\n    opt = gsub(opt, \"[TAH]\", function(mode) colormode = mode; return \"\"; end)\n  end\n\n  local m = { t=true, b=true, i=true, m=true, }\n  if opt and opt ~= \"\" then\n    local o = sub(opt, 1, 1)\n    if o ~= \"+\" and o ~= \"-\" then m = {} end\n    for i=1,#opt do m[sub(opt, i, i)] = (o ~= \"-\") end\n  end\n  dumpmode = m\n\n  if m.t or m.b or m.i or m.s or m.m then\n    jit.attach(dump_trace, \"trace\")\n  end\n  if m.b then\n    jit.attach(dump_record, \"record\")\n    if not bcline then bcline = require(\"jit.bc\").line end\n  end\n  if m.x or m.X then\n    jit.attach(dump_texit, \"texit\")\n  end\n\n  if not outfile then outfile = os.getenv(\"LUAJIT_DUMPFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stdout\n  end\n\n  m[colormode] = true\n  if colormode == \"A\" then\n    colorize = colorize_ansi\n    irtype = irtype_ansi\n  elseif colormode == \"H\" then\n    colorize = colorize_html\n    irtype = irtype_html\n    out:write(header_html)\n  else\n    colorize = colorize_text\n    irtype = irtype_text\n  end\n\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  on = dumpon,\n  off = dumpoff,\n  start = dumpon -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/p.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT profiler.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module is a simple command line interface to the built-in\n-- low-overhead profiler of LuaJIT.\n--\n-- The lower-level API of the profiler is accessible via the \"jit.profile\"\n-- module or the luaJIT_profile_* C API.\n--\n-- Example usage:\n--\n--   luajit -jp myapp.lua\n--   luajit -jp=s myapp.lua\n--   luajit -jp=-s myapp.lua\n--   luajit -jp=vl myapp.lua\n--   luajit -jp=G,profile.txt myapp.lua\n--\n-- The following dump features are available:\n--\n--   f  Stack dump: function name, otherwise module:line. Default mode.\n--   F  Stack dump: ditto, but always prepend module.\n--   l  Stack dump: module:line.\n--   <number> stack dump depth (callee < caller). Default: 1.\n--   -<number> Inverse stack dump depth (caller > callee).\n--   s  Split stack dump after first stack level. Implies abs(depth) >= 2.\n--   p  Show full path for module names.\n--   v  Show VM states. Can be combined with stack dumps, e.g. vf or fv.\n--   z  Show zones. Can be combined with stack dumps, e.g. zf or fz.\n--   r  Show raw sample counts. Default: show percentages.\n--   a  Annotate excerpts from source code files.\n--   A  Annotate complete source code files.\n--   G  Produce raw output suitable for graphical tools (e.g. flame graphs).\n--   m<number> Minimum sample percentage to be shown. Default: 3.\n--   i<number> Sampling interval in milliseconds. Default: 10.\n--\n----------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal profile = require(\"jit.profile\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal math = math\nlocal pairs, ipairs, tonumber, floor = pairs, ipairs, tonumber, math.floor\nlocal sort, format = table.sort, string.format\nlocal stdout = io.stdout\nlocal zone -- Load jit.zone module on demand.\n\n-- Output file handle.\nlocal out\n\n------------------------------------------------------------------------------\n\nlocal prof_ud\nlocal prof_states, prof_split, prof_min, prof_raw, prof_fmt, prof_depth\nlocal prof_ann, prof_count1, prof_count2, prof_samples\n\nlocal map_vmmode = {\n  N = \"Compiled\",\n  I = \"Interpreted\",\n  C = \"C code\",\n  G = \"Garbage Collector\",\n  J = \"JIT Compiler\",\n}\n\n-- Profiler callback.\nlocal function prof_cb(th, samples, vmmode)\n  prof_samples = prof_samples + samples\n  local key_stack, key_stack2, key_state\n  -- Collect keys for sample.\n  if prof_states then\n    if prof_states == \"v\" then\n      key_state = map_vmmode[vmmode] or vmmode\n    else\n      key_state = zone:get() or \"(none)\"\n    end\n  end\n  if prof_fmt then\n    key_stack = profile.dumpstack(th, prof_fmt, prof_depth)\n    key_stack = key_stack:gsub(\"%[builtin#(%d+)%]\", function(x)\n      return vmdef.ffnames[tonumber(x)]\n    end)\n    if prof_split == 2 then\n      local k1, k2 = key_stack:match(\"(.-) [<>] (.*)\")\n      if k2 then key_stack, key_stack2 = k1, k2 end\n    elseif prof_split == 3 then\n      key_stack2 = profile.dumpstack(th, \"l\", 1)\n    end\n  end\n  -- Order keys.\n  local k1, k2\n  if prof_split == 1 then\n    if key_state then\n      k1 = key_state\n      if key_stack then k2 = key_stack end\n    end\n  elseif key_stack then\n    k1 = key_stack\n    if key_stack2 then k2 = key_stack2 elseif key_state then k2 = key_state end\n  end\n  -- Coalesce samples in one or two levels.\n  if k1 then\n    local t1 = prof_count1\n    t1[k1] = (t1[k1] or 0) + samples\n    if k2 then\n      local t2 = prof_count2\n      local t3 = t2[k1]\n      if not t3 then t3 = {}; t2[k1] = t3 end\n      t3[k2] = (t3[k2] or 0) + samples\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Show top N list.\nlocal function prof_top(count1, count2, samples, indent)\n  local t, n = {}, 0\n  for k, v in pairs(count1) do\n    n = n + 1\n    t[n] = k\n  end\n  sort(t, function(a, b) return count1[a] > count1[b] end)\n  for i=1,n do\n    local k = t[i]\n    local v = count1[k]\n    local pct = floor(v*100/samples + 0.5)\n    if pct < prof_min then break end\n    if not prof_raw then\n      out:write(format(\"%s%2d%%  %s\\n\", indent, pct, k))\n    elseif prof_raw == \"r\" then\n      out:write(format(\"%s%5d  %s\\n\", indent, v, k))\n    else\n      out:write(format(\"%s %d\\n\", k, v))\n    end\n    if count2 then\n      local r = count2[k]\n      if r then\n\tprof_top(r, nil, v, (prof_split == 3 or prof_split == 1) and \"  -- \" or\n\t\t\t    (prof_depth < 0 and \"  -> \" or \"  <- \"))\n      end\n    end\n  end\nend\n\n-- Annotate source code\nlocal function prof_annotate(count1, samples)\n  local files = {}\n  local ms = 0\n  for k, v in pairs(count1) do\n    local pct = floor(v*100/samples + 0.5)\n    ms = math.max(ms, v)\n    if pct >= prof_min then\n      local file, line = k:match(\"^(.*):(%d+)$\")\n      local fl = files[file]\n      if not fl then fl = {}; files[file] = fl; files[#files+1] = file end\n      line = tonumber(line)\n      fl[line] = prof_raw and v or pct\n    end\n  end\n  sort(files)\n  local fmtv, fmtn = \" %3d%% | %s\\n\", \"      | %s\\n\"\n  if prof_raw then\n    local n = math.max(5, math.ceil(math.log10(ms)))\n    fmtv = \"%\"..n..\"d | %s\\n\"\n    fmtn = (\" \"):rep(n)..\" | %s\\n\"\n  end\n  local ann = prof_ann\n  for _, file in ipairs(files) do\n    local f0 = file:byte()\n    if f0 == 40 or f0 == 91 then\n      out:write(format(\"\\n====== %s ======\\n[Cannot annotate non-file]\\n\", file))\n      break\n    end\n    local fp, err = io.open(file)\n    if not fp then\n      out:write(format(\"====== ERROR: %s: %s\\n\", file, err))\n      break\n    end\n    out:write(format(\"\\n====== %s ======\\n\", file))\n    local fl = files[file]\n    local n, show = 1, false\n    if ann ~= 0 then\n      for i=1,ann do\n\tif fl[i] then show = true; out:write(\"@@ 1 @@\\n\"); break end\n      end\n    end\n    for line in fp:lines() do\n      if line:byte() == 27 then\n\tout:write(\"[Cannot annotate bytecode file]\\n\")\n\tbreak\n      end\n      local v = fl[n]\n      if ann ~= 0 then\n\tlocal v2 = fl[n+ann]\n\tif show then\n\t  if v2 then show = n+ann elseif v then show = n\n\t  elseif show+ann < n then show = false end\n\telseif v2 then\n\t  show = n+ann\n\t  out:write(format(\"@@ %d @@\\n\", n))\n\tend\n\tif not show then goto next end\n      end\n      if v then\n\tout:write(format(fmtv, v, line))\n      else\n\tout:write(format(fmtn, line))\n      end\n    ::next::\n      n = n + 1\n    end\n    fp:close()\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Finish profiling and dump result.\nlocal function prof_finish()\n  if prof_ud then\n    profile.stop()\n    local samples = prof_samples\n    if samples == 0 then\n      if prof_raw ~= true then out:write(\"[No samples collected]\\n\") end\n      return\n    end\n    if prof_ann then\n      prof_annotate(prof_count1, samples)\n    else\n      prof_top(prof_count1, prof_count2, samples, \"\")\n    end\n    prof_count1 = nil\n    prof_count2 = nil\n    prof_ud = nil\n  end\nend\n\n-- Start profiling.\nlocal function prof_start(mode)\n  local interval = \"\"\n  mode = mode:gsub(\"i%d*\", function(s) interval = s; return \"\" end)\n  prof_min = 3\n  mode = mode:gsub(\"m(%d+)\", function(s) prof_min = tonumber(s); return \"\" end)\n  prof_depth = 1\n  mode = mode:gsub(\"%-?%d+\", function(s) prof_depth = tonumber(s); return \"\" end)\n  local m = {}\n  for c in mode:gmatch(\".\") do m[c] = c end\n  prof_states = m.z or m.v\n  if prof_states == \"z\" then zone = require(\"jit.zone\") end\n  local scope = m.l or m.f or m.F or (prof_states and \"\" or \"f\")\n  local flags = (m.p or \"\")\n  prof_raw = m.r\n  if m.s then\n    prof_split = 2\n    if prof_depth == -1 or m[\"-\"] then prof_depth = -2\n    elseif prof_depth == 1 then prof_depth = 2 end\n  elseif mode:find(\"[fF].*l\") then\n    scope = \"l\"\n    prof_split = 3\n  else\n    prof_split = (scope == \"\" or mode:find(\"[zv].*[lfF]\")) and 1 or 0\n  end\n  prof_ann = m.A and 0 or (m.a and 3)\n  if prof_ann then\n    scope = \"l\"\n    prof_fmt = \"pl\"\n    prof_split = 0\n    prof_depth = 1\n  elseif m.G and scope ~= \"\" then\n    prof_fmt = flags..scope..\"Z;\"\n    prof_depth = -100\n    prof_raw = true\n    prof_min = 0\n  elseif scope == \"\" then\n    prof_fmt = false\n  else\n    local sc = prof_split == 3 and m.f or m.F or scope\n    prof_fmt = flags..sc..(prof_depth >= 0 and \"Z < \" or \"Z > \")\n  end\n  prof_count1 = {}\n  prof_count2 = {}\n  prof_samples = 0\n  profile.start(scope:lower()..interval, prof_cb)\n  prof_ud = newproxy(true)\n  getmetatable(prof_ud).__gc = prof_finish\nend\n\n------------------------------------------------------------------------------\n\nlocal function start(mode, outfile)\n  if not outfile then outfile = os.getenv(\"LUAJIT_PROFILEFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stdout\n  end\n  prof_start(mode or \"f\")\nend\n\n-- Public module functions.\nreturn {\n  start = start, -- For -j command line option.\n  stop = prof_finish\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/v.lua",
    "content": "----------------------------------------------------------------------------\n-- Verbose mode of the LuaJIT compiler.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module shows verbose information about the progress of the\n-- JIT compiler. It prints one line for each generated trace. This module\n-- is useful to see which code has been compiled or where the compiler\n-- punts and falls back to the interpreter.\n--\n-- Example usage:\n--\n--   luajit -jv -e \"for i=1,1000 do for j=1,1000 do end end\"\n--   luajit -jv=myapp.out myapp.lua\n--\n-- Default output is to stderr. To redirect the output to a file, pass a\n-- filename as an argument (use '-' for stdout) or set the environment\n-- variable LUAJIT_VERBOSEFILE. The file is overwritten every time the\n-- module is started.\n--\n-- The output from the first example should look like this:\n--\n-- [TRACE   1 (command line):1 loop]\n-- [TRACE   2 (1/3) (command line):1 -> 1]\n--\n-- The first number in each line is the internal trace number. Next are\n-- the file name ('(command line)') and the line number (':1') where the\n-- trace has started. Side traces also show the parent trace number and\n-- the exit number where they are attached to in parentheses ('(1/3)').\n-- An arrow at the end shows where the trace links to ('-> 1'), unless\n-- it loops to itself.\n--\n-- In this case the inner loop gets hot and is traced first, generating\n-- a root trace. Then the last exit from the 1st trace gets hot, too,\n-- and triggers generation of the 2nd trace. The side trace follows the\n-- path along the outer loop and *around* the inner loop, back to its\n-- start, and then links to the 1st trace. Yes, this may seem unusual,\n-- if you know how traditional compilers work. Trace compilers are full\n-- of surprises like this -- have fun! :-)\n--\n-- Aborted traces are shown like this:\n--\n-- [TRACE --- foo.lua:44 -- leaving loop in root trace at foo:lua:50]\n--\n-- Don't worry -- trace aborts are quite common, even in programs which\n-- can be fully compiled. The compiler may retry several times until it\n-- finds a suitable trace.\n--\n-- Of course this doesn't work with features that are not-yet-implemented\n-- (NYI error messages). The VM simply falls back to the interpreter. This\n-- may not matter at all if the particular trace is not very high up in\n-- the CPU usage profile. Oh, and the interpreter is quite fast, too.\n--\n-- Also check out the -jdump module, which prints all the gory details.\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo\nlocal type, format = type, string.format\nlocal stdout, stderr = io.stdout, io.stderr\n\n-- Active flag and output file handle.\nlocal active, out\n\n------------------------------------------------------------------------------\n\nlocal startloc, startex\n\nlocal function fmtfunc(func, pc)\n  local fi = funcinfo(func, pc)\n  if fi.loc then\n    return fi.loc\n  elseif fi.ffid then\n    return vmdef.ffnames[fi.ffid]\n  elseif fi.addr then\n    return format(\"C:%x\", fi.addr)\n  else\n    return \"(?)\"\n  end\nend\n\n-- Format trace error message.\nlocal function fmterr(err, info)\n  if type(err) == \"number\" then\n    if type(info) == \"function\" then info = fmtfunc(info) end\n    err = format(vmdef.traceerr[err], info)\n  end\n  return err\nend\n\n-- Dump trace states.\nlocal function dump_trace(what, tr, func, pc, otr, oex)\n  if what == \"start\" then\n    startloc = fmtfunc(func, pc)\n    startex = otr and \"(\"..otr..\"/\"..oex..\") \" or \"\"\n  else\n    if what == \"abort\" then\n      local loc = fmtfunc(func, pc)\n      if loc ~= startloc then\n\tout:write(format(\"[TRACE --- %s%s -- %s at %s]\\n\",\n\t  startex, startloc, fmterr(otr, oex), loc))\n      else\n\tout:write(format(\"[TRACE --- %s%s -- %s]\\n\",\n\t  startex, startloc, fmterr(otr, oex)))\n      end\n    elseif what == \"stop\" then\n      local info = traceinfo(tr)\n      local link, ltype = info.link, info.linktype\n      if ltype == \"interpreter\" then\n\tout:write(format(\"[TRACE %3s %s%s -- fallback to interpreter]\\n\",\n\t  tr, startex, startloc))\n      elseif ltype == \"stitch\" then\n\tout:write(format(\"[TRACE %3s %s%s %s %s]\\n\",\n\t  tr, startex, startloc, ltype, fmtfunc(func, pc)))\n      elseif link == tr or link == 0 then\n\tout:write(format(\"[TRACE %3s %s%s %s]\\n\",\n\t  tr, startex, startloc, ltype))\n      elseif ltype == \"root\" then\n\tout:write(format(\"[TRACE %3s %s%s -> %d]\\n\",\n\t  tr, startex, startloc, link))\n      else\n\tout:write(format(\"[TRACE %3s %s%s -> %d %s]\\n\",\n\t  tr, startex, startloc, link, ltype))\n      end\n    else\n      out:write(format(\"[TRACE %s]\\n\", what))\n    end\n    out:flush()\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Detach dump handlers.\nlocal function dumpoff()\n  if active then\n    active = false\n    jit.attach(dump_trace)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach dump handlers.\nlocal function dumpon(outfile)\n  if active then dumpoff() end\n  if not outfile then outfile = os.getenv(\"LUAJIT_VERBOSEFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stderr\n  end\n  jit.attach(dump_trace, \"trace\")\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  on = dumpon,\n  off = dumpoff,\n  start = dumpon -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/jit/zone.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT profiler zones.\n--\n-- Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module implements a simple hierarchical zone model.\n--\n-- Example usage:\n--\n--   local zone = require(\"jit.zone\")\n--   zone(\"AI\")\n--   ...\n--     zone(\"A*\")\n--     ...\n--     print(zone:get()) --> \"A*\"\n--     ...\n--     zone()\n--   ...\n--   print(zone:get()) --> \"AI\"\n--   ...\n--   zone()\n--\n----------------------------------------------------------------------------\n\nlocal remove = table.remove\n\nreturn setmetatable({\n  flush = function(t)\n    for i=#t,1,-1 do t[i] = nil end\n  end,\n  get = function(t)\n    return t[#t]\n  end\n}, {\n  __call = function(t, zone)\n    if zone then\n      t[#t+1] = zone\n    else\n      return (assert(remove(t), \"empty zone stack\"))\n    end\n  end\n})\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n#define luaL_getn(L,i)          ((int)lua_objlen(L, i))\n#define luaL_setn(L,i,j)        ((void)0)  /* no op! */\n\n/* extra error code for `luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l);\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);\nLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int narg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);\nLUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,\n                                  const char *name);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,\n                                         const char *fname, int szhint);\n\n/* From Lua 5.2. */\nLUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);\nLUALIB_API int luaL_execresult(lua_State *L, int stat);\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n\t\t\t\t const char *mode);\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n\t\t\t\t   const char *name, const char *mode);\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n\t\t\t\tint level);\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define luaL_argcheck(L, cond,numarg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n\ntypedef struct luaL_Buffer {\n  char *p;\t\t\t/* current position in buffer */\n  int lvl;  /* number of strings in the stack (level) */\n  lua_State *L;\n  char buffer[LUAL_BUFFERSIZE];\n} luaL_Buffer;\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \\\n   (*(B)->p++ = (char)(c)))\n\n/* compatibility only */\n#define luaL_putchar(B,c)\tluaL_addchar(B,c)\n\n#define luaL_addsize(B,n)\t((B)->p += (n))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\n\n\n/* }====================================================== */\n\n\n/* compatibility with ref system */\n\n/* pre-defined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\n#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \\\n      (lua_pushstring(L, \"unlocked references are obsolete\"), lua_error(L), 0))\n\n#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))\n\n#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))\n\n\n#define luaL_reg\tluaL_Reg\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_aux.c",
    "content": "/*\n** Auxiliary library for the Lua/C API.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major parts taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n\n#define lib_aux_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_state.h\"\n#include \"lj_trace.h\"\n#include \"lj_lib.h\"\n\n#if LJ_TARGET_POSIX\n#include <sys/wait.h>\n#endif\n\n/* -- I/O error handling -------------------------------------------------- */\n\nLUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)\n{\n  if (stat) {\n    setboolV(L->top++, 1);\n    return 1;\n  } else {\n    int en = errno;  /* Lua API calls may change this value. */\n    setnilV(L->top++);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushfstring(L, \"%s\", strerror(en));\n    setintV(L->top++, en);\n    lj_trace_abort(G(L));\n    return 3;\n  }\n}\n\nLUALIB_API int luaL_execresult(lua_State *L, int stat)\n{\n  if (stat != -1) {\n#if LJ_TARGET_POSIX\n    if (WIFSIGNALED(stat)) {\n      stat = WTERMSIG(stat);\n      setnilV(L->top++);\n      lua_pushliteral(L, \"signal\");\n    } else {\n      if (WIFEXITED(stat))\n\tstat = WEXITSTATUS(stat);\n      if (stat == 0)\n\tsetboolV(L->top++, 1);\n      else\n\tsetnilV(L->top++);\n      lua_pushliteral(L, \"exit\");\n    }\n#else\n    if (stat == 0)\n      setboolV(L->top++, 1);\n    else\n      setnilV(L->top++);\n    lua_pushliteral(L, \"exit\");\n#endif\n    setintV(L->top++, stat);\n    return 3;\n  }\n  return luaL_fileresult(L, 0, NULL);\n}\n\n/* -- Module registration ------------------------------------------------- */\n\nLUALIB_API const char *luaL_findtable(lua_State *L, int idx,\n\t\t\t\t      const char *fname, int szhint)\n{\n  const char *e;\n  lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, (size_t)(e - fname));\n    lua_rawget(L, -2);\n    if (lua_isnil(L, -1)) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, (size_t)(e - fname));\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    } else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\nstatic int libsize(const luaL_Reg *l)\n{\n  int size = 0;\n  for (; l->name; l++) size++;\n  return size;\n}\n\nLUALIB_API void luaL_openlib(lua_State *L, const char *libname,\n\t\t\t     const luaL_Reg *l, int nup)\n{\n  lj_lib_checkfpu(L);\n  if (libname) {\n    int size = libsize(l);\n    /* check whether lib already exists */\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n    lua_getfield(L, -1, libname);  /* get _LOADED[libname] */\n    if (!lua_istable(L, -1)) {  /* not found? */\n      lua_pop(L, 1);  /* remove previous result */\n      /* try global variable (and create one if it does not exist) */\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)\n\tlj_err_callerv(L, LJ_ERR_BADMODN, libname);\n      lua_pushvalue(L, -1);\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    lua_remove(L, -2);  /* remove _LOADED table */\n    lua_insert(L, -(nup+1));  /* move library table to below upvalues */\n  }\n  for (; l->name; l++) {\n    int i;\n    for (i = 0; i < nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);\n    lua_setfield(L, -(nup+2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\nLUALIB_API void luaL_register(lua_State *L, const char *libname,\n\t\t\t      const luaL_Reg *l)\n{\n  luaL_openlib(L, libname, l, 0);\n}\n\nLUALIB_API const char *luaL_gsub(lua_State *L, const char *s,\n\t\t\t\t const char *p, const char *r)\n{\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, (size_t)(wild - s));  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after `p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n/* -- Buffer handling ----------------------------------------------------- */\n\n#define bufflen(B)\t((size_t)((B)->p - (B)->buffer))\n#define bufffree(B)\t((size_t)(LUAL_BUFFERSIZE - bufflen(B)))\n\nstatic int emptybuffer(luaL_Buffer *B)\n{\n  size_t l = bufflen(B);\n  if (l == 0)\n    return 0;  /* put nothing on stack */\n  lua_pushlstring(B->L, B->buffer, l);\n  B->p = B->buffer;\n  B->lvl++;\n  return 1;\n}\n\nstatic void adjuststack(luaL_Buffer *B)\n{\n  if (B->lvl > 1) {\n    lua_State *L = B->L;\n    int toget = 1;  /* number of levels to concat */\n    size_t toplen = lua_strlen(L, -1);\n    do {\n      size_t l = lua_strlen(L, -(toget+1));\n      if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l))\n\tbreak;\n      toplen += l;\n      toget++;\n    } while (toget < B->lvl);\n    lua_concat(L, toget);\n    B->lvl = B->lvl - toget + 1;\n  }\n}\n\nLUALIB_API char *luaL_prepbuffer(luaL_Buffer *B)\n{\n  if (emptybuffer(B))\n    adjuststack(B);\n  return B->buffer;\n}\n\nLUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)\n{\n  while (l--)\n    luaL_addchar(B, *s++);\n}\n\nLUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)\n{\n  luaL_addlstring(B, s, strlen(s));\n}\n\nLUALIB_API void luaL_pushresult(luaL_Buffer *B)\n{\n  emptybuffer(B);\n  lua_concat(B->L, B->lvl);\n  B->lvl = 1;\n}\n\nLUALIB_API void luaL_addvalue(luaL_Buffer *B)\n{\n  lua_State *L = B->L;\n  size_t vl;\n  const char *s = lua_tolstring(L, -1, &vl);\n  if (vl <= bufffree(B)) {  /* fit into buffer? */\n    memcpy(B->p, s, vl);  /* put it there */\n    B->p += vl;\n    lua_pop(L, 1);  /* remove from stack */\n  } else {\n    if (emptybuffer(B))\n      lua_insert(L, -2);  /* put buffer before new value */\n    B->lvl++;  /* add new value into B stack */\n    adjuststack(B);\n  }\n}\n\nLUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)\n{\n  B->L = L;\n  B->p = B->buffer;\n  B->lvl = 0;\n}\n\n/* -- Reference management ------------------------------------------------ */\n\n#define FREELIST_REF\t0\n\n/* Convert a stack index to an absolute index. */\n#define abs_index(L, i) \\\n  ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)\n\nLUALIB_API int luaL_ref(lua_State *L, int t)\n{\n  int ref;\n  t = abs_index(L, t);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* `nil' has a unique fixed reference */\n  }\n  lua_rawgeti(L, t, FREELIST_REF);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[FREELIST_REF] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, FREELIST_REF);  /* (t[FREELIST_REF] = t[ref]) */\n  } else {  /* no free elements */\n    ref = (int)lua_objlen(L, t);\n    ref++;  /* create new reference */\n  }\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\nLUALIB_API void luaL_unref(lua_State *L, int t, int ref)\n{\n  if (ref >= 0) {\n    t = abs_index(L, t);\n    lua_rawgeti(L, t, FREELIST_REF);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */\n  }\n}\n\n/* -- Default allocator and panic function -------------------------------- */\n\nstatic int panic(lua_State *L)\n{\n  const char *s = lua_tostring(L, -1);\n  fputs(\"PANIC: unprotected error in call to Lua API (\", stderr);\n  fputs(s ? s : \"?\", stderr);\n  fputc(')', stderr); fputc('\\n', stderr);\n  fflush(stderr);\n  return 0;\n}\n\n#ifdef LUAJIT_USE_SYSMALLOC\n\n#if LJ_64 && !defined(LUAJIT_USE_VALGRIND)\n#error \"Must use builtin allocator for 64 bit target\"\n#endif\n\nstatic void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)\n{\n  (void)ud;\n  (void)osize;\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  } else {\n    return realloc(ptr, nsize);\n  }\n}\n\nLUALIB_API lua_State *luaL_newstate(void)\n{\n  lua_State *L = lua_newstate(mem_alloc, NULL);\n  if (L) G(L)->panic = panic;\n  return L;\n}\n\n#else\n\n#include \"lj_alloc.h\"\n\nLUALIB_API lua_State *luaL_newstate(void)\n{\n  lua_State *L;\n  void *ud = lj_alloc_create();\n  if (ud == NULL) return NULL;\n#if LJ_64\n  L = lj_state_newstate(lj_alloc_f, ud);\n#else\n  L = lua_newstate(lj_alloc_f, ud);\n#endif\n  if (L) G(L)->panic = panic;\n  return L;\n}\n\n#if LJ_64\nLUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)\n{\n  UNUSED(f); UNUSED(ud);\n  fputs(\"Must use luaL_newstate() for 64 bit target\\n\", stderr);\n  return NULL;\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_base.c",
    "content": "/*\n** Base and coroutine library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <stdio.h>\n\n#define lib_base_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#endif\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* -- Base library: checks ------------------------------------------------ */\n\n#define LJLIB_MODULE_base\n\nLJLIB_ASM(assert)\t\tLJLIB_REC(.)\n{\n  GCstr *s;\n  lj_lib_checkany(L, 1);\n  s = lj_lib_optstr(L, 2);\n  if (s)\n    lj_err_callermsg(L, strdata(s));\n  else\n    lj_err_caller(L, LJ_ERR_ASSERT);\n  return FFH_UNREACHABLE;\n}\n\n/* ORDER LJ_T */\nLJLIB_PUSH(\"nil\")\nLJLIB_PUSH(\"boolean\")\nLJLIB_PUSH(top-1)  /* boolean */\nLJLIB_PUSH(\"userdata\")\nLJLIB_PUSH(\"string\")\nLJLIB_PUSH(\"upval\")\nLJLIB_PUSH(\"thread\")\nLJLIB_PUSH(\"proto\")\nLJLIB_PUSH(\"function\")\nLJLIB_PUSH(\"trace\")\nLJLIB_PUSH(\"cdata\")\nLJLIB_PUSH(\"table\")\nLJLIB_PUSH(top-9)  /* userdata */\nLJLIB_PUSH(\"number\")\nLJLIB_ASM_(type)\t\tLJLIB_REC(.)\n/* Recycle the lj_lib_checkany(L, 1) from assert. */\n\n/* -- Base library: iterators --------------------------------------------- */\n\n/* This solves a circular dependency problem -- change FF_next_N as needed. */\nLJ_STATIC_ASSERT((int)FF_next == FF_next_N);\n\nLJLIB_ASM(next)\n{\n  lj_lib_checktab(L, 1);\n  return FFH_UNREACHABLE;\n}\n\n#if LJ_52 || LJ_HASFFI\nstatic int ffh_pairs(lua_State *L, MMS mm)\n{\n  TValue *o = lj_lib_checkany(L, 1);\n  cTValue *mo = lj_meta_lookup(L, o, mm);\n  if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {\n    L->top = o+1;  /* Only keep one argument. */\n    copyTV(L, L->base-1-LJ_FR2, mo);  /* Replace callable. */\n    return FFH_TAILCALL;\n  } else {\n    if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);\n    if (LJ_FR2) { copyTV(L, o-1, o); o--; }\n    setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));\n    if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);\n    return FFH_RES(3);\n  }\n}\n#else\n#define ffh_pairs(L, mm)\t(lj_lib_checktab(L, 1), FFH_UNREACHABLE)\n#endif\n\nLJLIB_PUSH(lastcl)\nLJLIB_ASM(pairs)\t\tLJLIB_REC(xpairs 0)\n{\n  return ffh_pairs(L, MM_pairs);\n}\n\nLJLIB_NOREGUV LJLIB_ASM(ipairs_aux)\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkint(L, 2);\n  return FFH_UNREACHABLE;\n}\n\nLJLIB_PUSH(lastcl)\nLJLIB_ASM(ipairs)\t\tLJLIB_REC(xpairs 1)\n{\n  return ffh_pairs(L, MM_ipairs);\n}\n\n/* -- Base library: getters and setters ----------------------------------- */\n\nLJLIB_ASM_(getmetatable)\tLJLIB_REC(.)\n/* Recycle the lj_lib_checkany(L, 1) from assert. */\n\nLJLIB_ASM(setmetatable)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  GCtab *mt = lj_lib_checktabornil(L, 2);\n  if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable)))\n    lj_err_caller(L, LJ_ERR_PROTMT);\n  setgcref(t->metatable, obj2gco(mt));\n  if (mt) { lj_gc_objbarriert(L, t, mt); }\n  settabV(L, L->base-1-LJ_FR2, t);\n  return FFH_RES(1);\n}\n\nLJLIB_CF(getfenv)\t\tLJLIB_REC(.)\n{\n  GCfunc *fn;\n  cTValue *o = L->base;\n  if (!(o < L->top && tvisfunc(o))) {\n    int level = lj_lib_optint(L, 1, 1);\n    o = lj_debug_frame(L, level, &level);\n    if (o == NULL)\n      lj_err_arg(L, 1, LJ_ERR_INVLVL);\n    if (LJ_FR2) o--;\n  }\n  fn = &gcval(o)->fn;\n  settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env));\n  return 1;\n}\n\nLJLIB_CF(setfenv)\n{\n  GCfunc *fn;\n  GCtab *t = lj_lib_checktab(L, 2);\n  cTValue *o = L->base;\n  if (!(o < L->top && tvisfunc(o))) {\n    int level = lj_lib_checkint(L, 1);\n    if (level == 0) {\n      /* NOBARRIER: A thread (i.e. L) is never black. */\n      setgcref(L->env, obj2gco(t));\n      return 0;\n    }\n    o = lj_debug_frame(L, level, &level);\n    if (o == NULL)\n      lj_err_arg(L, 1, LJ_ERR_INVLVL);\n    if (LJ_FR2) o--;\n  }\n  fn = &gcval(o)->fn;\n  if (!isluafunc(fn))\n    lj_err_caller(L, LJ_ERR_SETFENV);\n  setgcref(fn->l.env, obj2gco(t));\n  lj_gc_objbarrier(L, obj2gco(fn), t);\n  setfuncV(L, L->top++, fn);\n  return 1;\n}\n\nLJLIB_ASM(rawget)\t\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkany(L, 2);\n  return FFH_UNREACHABLE;\n}\n\nLJLIB_CF(rawset)\t\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkany(L, 2);\n  L->top = 1+lj_lib_checkany(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\nLJLIB_CF(rawequal)\t\tLJLIB_REC(.)\n{\n  cTValue *o1 = lj_lib_checkany(L, 1);\n  cTValue *o2 = lj_lib_checkany(L, 2);\n  setboolV(L->top-1, lj_obj_equal(o1, o2));\n  return 1;\n}\n\n#if LJ_52\nLJLIB_CF(rawlen)\t\tLJLIB_REC(.)\n{\n  cTValue *o = L->base;\n  int32_t len;\n  if (L->top > o && tvisstr(o))\n    len = (int32_t)strV(o)->len;\n  else\n    len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1));\n  setintV(L->top-1, len);\n  return 1;\n}\n#endif\n\nLJLIB_CF(unpack)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n, i = lj_lib_optint(L, 2, 1);\n  int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?\n\t      lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t);\n  if (i > e) return 0;\n  n = e - i + 1;\n  if (n <= 0 || !lua_checkstack(L, n))\n    lj_err_caller(L, LJ_ERR_UNPACK);\n  do {\n    cTValue *tv = lj_tab_getint(t, i);\n    if (tv) {\n      copyTV(L, L->top++, tv);\n    } else {\n      setnilV(L->top++);\n    }\n  } while (i++ < e);\n  return n;\n}\n\nLJLIB_CF(select)\t\tLJLIB_REC(.)\n{\n  int32_t n = (int32_t)(L->top - L->base);\n  if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') {\n    setintV(L->top-1, n-1);\n    return 1;\n  } else {\n    int32_t i = lj_lib_checkint(L, 1);\n    if (i < 0) i = n + i; else if (i > n) i = n;\n    if (i < 1)\n      lj_err_arg(L, 1, LJ_ERR_IDXRNG);\n    return n - i;\n  }\n}\n\n/* -- Base library: conversions ------------------------------------------- */\n\nLJLIB_ASM(tonumber)\t\tLJLIB_REC(.)\n{\n  int32_t base = lj_lib_optint(L, 2, 10);\n  if (base == 10) {\n    TValue *o = lj_lib_checkany(L, 1);\n    if (lj_strscan_numberobj(o)) {\n      copyTV(L, L->base-1-LJ_FR2, o);\n      return FFH_RES(1);\n    }\n#if LJ_HASFFI\n    if (tviscdata(o)) {\n      CTState *cts = ctype_cts(L);\n      CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid);\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {\n\tif (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) &&\n\t    ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) {\n\t  int32_t i;\n\t  lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0);\n\t  setintV(L->base-1-LJ_FR2, i);\n\t  return FFH_RES(1);\n\t}\n\tlj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE),\n\t\t       (uint8_t *)&(L->base-1-LJ_FR2)->n, o, 0);\n\treturn FFH_RES(1);\n      }\n    }\n#endif\n  } else {\n    const char *p = strdata(lj_lib_checkstr(L, 1));\n    char *ep;\n    unsigned long ul;\n    if (base < 2 || base > 36)\n      lj_err_arg(L, 2, LJ_ERR_BASERNG);\n    ul = strtoul(p, &ep, base);\n    if (p != ep) {\n      while (lj_char_isspace((unsigned char)(*ep))) ep++;\n      if (*ep == '\\0') {\n\tif (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u))\n\t  setintV(L->base-1-LJ_FR2, (int32_t)ul);\n\telse\n\t  setnumV(L->base-1-LJ_FR2, (lua_Number)ul);\n\treturn FFH_RES(1);\n      }\n    }\n  }\n  setnilV(L->base-1-LJ_FR2);\n  return FFH_RES(1);\n}\n\nLJLIB_ASM(tostring)\t\tLJLIB_REC(.)\n{\n  TValue *o = lj_lib_checkany(L, 1);\n  cTValue *mo;\n  L->top = o+1;  /* Only keep one argument. */\n  if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {\n    copyTV(L, L->base-1-LJ_FR2, mo);  /* Replace callable. */\n    return FFH_TAILCALL;\n  }\n  lj_gc_check(L);\n  setstrV(L, L->base-1-LJ_FR2, lj_strfmt_obj(L, L->base));\n  return FFH_RES(1);\n}\n\n/* -- Base library: throw and catch errors -------------------------------- */\n\nLJLIB_CF(error)\n{\n  int32_t level = lj_lib_optint(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_isstring(L, 1) && level > 0) {\n    luaL_where(L, level);\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\nLJLIB_ASM(pcall)\t\tLJLIB_REC(.)\n{\n  lj_lib_checkany(L, 1);\n  lj_lib_checkfunc(L, 2);  /* For xpcall only. */\n  return FFH_UNREACHABLE;\n}\nLJLIB_ASM_(xpcall)\t\tLJLIB_REC(.)\n\n/* -- Base library: load Lua code ----------------------------------------- */\n\nstatic int load_aux(lua_State *L, int status, int envarg)\n{\n  if (status == 0) {\n    if (tvistab(L->base+envarg-1)) {\n      GCfunc *fn = funcV(L->top-1);\n      GCtab *t = tabV(L->base+envarg-1);\n      setgcref(fn->c.env, obj2gco(t));\n      lj_gc_objbarrier(L, fn, t);\n    }\n    return 1;\n  } else {\n    setnilV(L->top-2);\n    return 2;\n  }\n}\n\nLJLIB_CF(loadfile)\n{\n  GCstr *fname = lj_lib_optstr(L, 1);\n  GCstr *mode = lj_lib_optstr(L, 2);\n  int status;\n  lua_settop(L, 3);  /* Ensure env arg exists. */\n  status = luaL_loadfilex(L, fname ? strdata(fname) : NULL,\n\t\t\t  mode ? strdata(mode) : NULL);\n  return load_aux(L, status, 3);\n}\n\nstatic const char *reader_func(lua_State *L, void *ud, size_t *size)\n{\n  UNUSED(ud);\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  copyTV(L, L->top++, L->base);\n  lua_call(L, 0, 1);  /* Call user-supplied function. */\n  L->top--;\n  if (tvisnil(L->top)) {\n    *size = 0;\n    return NULL;\n  } else if (tvisstr(L->top) || tvisnumber(L->top)) {\n    copyTV(L, L->base+4, L->top);  /* Anchor string in reserved stack slot. */\n    return lua_tolstring(L, 5, size);\n  } else {\n    lj_err_caller(L, LJ_ERR_RDRSTR);\n    return NULL;\n  }\n}\n\nLJLIB_CF(load)\n{\n  GCstr *name = lj_lib_optstr(L, 2);\n  GCstr *mode = lj_lib_optstr(L, 3);\n  int status;\n  if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) {\n    GCstr *s = lj_lib_checkstr(L, 1);\n    lua_settop(L, 4);  /* Ensure env arg exists. */\n    status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s),\n\t\t\t      mode ? strdata(mode) : NULL);\n  } else {\n    lj_lib_checkfunc(L, 1);\n    lua_settop(L, 5);  /* Reserve a slot for the string from the reader. */\n    status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : \"=(load)\",\n\t\t       mode ? strdata(mode) : NULL);\n  }\n  return load_aux(L, status, 4);\n}\n\nLJLIB_CF(loadstring)\n{\n  return lj_cf_load(L);\n}\n\nLJLIB_CF(dofile)\n{\n  GCstr *fname = lj_lib_optstr(L, 1);\n  setnilV(L->top);\n  L->top = L->base+1;\n  if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0)\n    lua_error(L);\n  lua_call(L, 0, LUA_MULTRET);\n  return (int)(L->top - L->base) - 1;\n}\n\n/* -- Base library: GC control -------------------------------------------- */\n\nLJLIB_CF(gcinfo)\n{\n  setintV(L->top++, (int32_t)(G(L)->gc.total >> 10));\n  return 1;\n}\n\nLJLIB_CF(collectgarbage)\n{\n  int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT,  /* ORDER LUA_GC* */\n    \"\\4stop\\7restart\\7collect\\5count\\1\\377\\4step\\10setpause\\12setstepmul\\1\\377\\11isrunning\");\n  int32_t data = lj_lib_optint(L, 2, 0);\n  if (opt == LUA_GCCOUNT) {\n    setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);\n  } else {\n    int res = lua_gc(L, opt, data);\n    if (opt == LUA_GCSTEP || opt == LUA_GCISRUNNING)\n      setboolV(L->top, res);\n    else\n      setintV(L->top, res);\n  }\n  L->top++;\n  return 1;\n}\n\n/* -- Base library: miscellaneous functions ------------------------------- */\n\nLJLIB_PUSH(top-2)  /* Upvalue holds weak table. */\nLJLIB_CF(newproxy)\n{\n  lua_settop(L, 1);\n  lua_newuserdata(L, 0);\n  if (lua_toboolean(L, 1) == 0) {  /* newproxy(): without metatable. */\n    return 1;\n  } else if (lua_isboolean(L, 1)) {  /* newproxy(true): with metatable. */\n    lua_newtable(L);\n    lua_pushvalue(L, -1);\n    lua_pushboolean(L, 1);\n    lua_rawset(L, lua_upvalueindex(1));  /* Remember mt in weak table. */\n  } else {  /* newproxy(proxy): inherit metatable. */\n    int validproxy = 0;\n    if (lua_getmetatable(L, 1)) {\n      lua_rawget(L, lua_upvalueindex(1));\n      validproxy = lua_toboolean(L, -1);\n      lua_pop(L, 1);\n    }\n    if (!validproxy)\n      lj_err_arg(L, 1, LJ_ERR_NOPROXY);\n    lua_getmetatable(L, 1);\n  }\n  lua_setmetatable(L, 2);\n  return 1;\n}\n\nLJLIB_PUSH(\"tostring\")\nLJLIB_CF(print)\n{\n  ptrdiff_t i, nargs = L->top - L->base;\n  cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1)));\n  int shortcut;\n  if (tv && !tvisnil(tv)) {\n    copyTV(L, L->top++, tv);\n  } else {\n    setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1)));\n    lua_gettable(L, LUA_GLOBALSINDEX);\n    tv = L->top-1;\n  }\n  shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);\n  for (i = 0; i < nargs; i++) {\n    cTValue *o = &L->base[i];\n    const char *str;\n    size_t size;\n    MSize len;\n    if (shortcut && (str = lj_strfmt_wstrnum(L, o, &len)) != NULL) {\n      size = len;\n    } else {\n      copyTV(L, L->top+1, o);\n      copyTV(L, L->top, L->top-1);\n      L->top += 2;\n      lua_call(L, 1, 1);\n      str = lua_tolstring(L, -1, &size);\n      if (!str)\n\tlj_err_caller(L, LJ_ERR_PRTOSTR);\n      L->top--;\n    }\n    if (i)\n      putchar('\\t');\n    fwrite(str, 1, size, stdout);\n  }\n  putchar('\\n');\n  return 0;\n}\n\nLJLIB_PUSH(top-3)\nLJLIB_SET(_VERSION)\n\n#include \"lj_libdef.h\"\n\n/* -- Coroutine library --------------------------------------------------- */\n\n#define LJLIB_MODULE_coroutine\n\nLJLIB_CF(coroutine_status)\n{\n  const char *s;\n  lua_State *co;\n  if (!(L->top > L->base && tvisthread(L->base)))\n    lj_err_arg(L, 1, LJ_ERR_NOCORO);\n  co = threadV(L->base);\n  if (co == L) s = \"running\";\n  else if (co->status == LUA_YIELD) s = \"suspended\";\n  else if (co->status != 0) s = \"dead\";\n  else if (co->base > tvref(co->stack)+1+LJ_FR2) s = \"normal\";\n  else if (co->top == co->base) s = \"dead\";\n  else s = \"suspended\";\n  lua_pushstring(L, s);\n  return 1;\n}\n\nLJLIB_CF(coroutine_running)\n{\n#if LJ_52\n  int ismain = lua_pushthread(L);\n  setboolV(L->top++, ismain);\n  return 2;\n#else\n  if (lua_pushthread(L))\n    setnilV(L->top++);\n  return 1;\n#endif\n}\n\nLJLIB_CF(coroutine_create)\n{\n  lua_State *L1;\n  if (!(L->base < L->top && tvisfunc(L->base)))\n    lj_err_argt(L, 1, LUA_TFUNCTION);\n  L1 = lua_newthread(L);\n  setfuncV(L, L1->top++, funcV(L->base));\n  return 1;\n}\n\nLJLIB_ASM(coroutine_yield)\n{\n  lj_err_caller(L, LJ_ERR_CYIELD);\n  return FFH_UNREACHABLE;\n}\n\nstatic int ffh_resume(lua_State *L, lua_State *co, int wrap)\n{\n  if (co->cframe != NULL || co->status > LUA_YIELD ||\n      (co->status == 0 && co->top == co->base)) {\n    ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD;\n    if (wrap) lj_err_caller(L, em);\n    setboolV(L->base-1-LJ_FR2, 0);\n    setstrV(L, L->base-LJ_FR2, lj_err_str(L, em));\n    return FFH_RES(2);\n  }\n  lj_state_growstack(co, (MSize)(L->top - L->base));\n  return FFH_RETRY;\n}\n\nLJLIB_ASM(coroutine_resume)\n{\n  if (!(L->top > L->base && tvisthread(L->base)))\n    lj_err_arg(L, 1, LJ_ERR_NOCORO);\n  return ffh_resume(L, threadV(L->base), 0);\n}\n\nLJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)\n{\n  return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1);\n}\n\n/* Inline declarations. */\nLJ_ASMF void lj_ff_coroutine_wrap_aux(void);\n#if !(LJ_TARGET_MIPS && defined(ljamalg_c))\nLJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,\n\t\t\t\t\t\t\t  lua_State *co);\n#endif\n\n/* Error handler, called from assembler VM. */\nvoid LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)\n{\n  co->top--; copyTV(L, L->top, co->top); L->top++;\n  if (tvisstr(L->top-1))\n    lj_err_callermsg(L, strVdata(L->top-1));\n  else\n    lj_err_run(L);\n}\n\n/* Forward declaration. */\nstatic void setpc_wrap_aux(lua_State *L, GCfunc *fn);\n\nLJLIB_CF(coroutine_wrap)\n{\n  GCfunc *fn;\n  lj_cf_coroutine_create(L);\n  fn = lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1);\n  setpc_wrap_aux(L, fn);\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\n/* Fix the PC of wrap_aux. Really ugly workaround. */\nstatic void setpc_wrap_aux(lua_State *L, GCfunc *fn)\n{\n  setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]);\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void newproxy_weaktable(lua_State *L)\n{\n  /* NOBARRIER: The table is new (marked white). */\n  GCtab *t = lj_tab_new(L, 0, 1);\n  settabV(L, L->top++, t);\n  setgcref(t->metatable, obj2gco(t));\n  setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"__mode\")),\n\t    lj_str_newlit(L, \"kv\"));\n  t->nomm = (uint8_t)(~(1u<<MM_mode));\n}\n\nLUALIB_API int luaopen_base(lua_State *L)\n{\n  /* NOBARRIER: Table and value are the same. */\n  GCtab *env = tabref(L->env);\n  settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, \"_G\")), env);\n  lua_pushliteral(L, LUA_VERSION);  /* top-3. */\n  newproxy_weaktable(L);  /* top-2. */\n  LJ_LIB_REG(L, \"_G\", base);\n  LJ_LIB_REG(L, LUA_COLIBNAME, coroutine);\n  return 2;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_bit.c",
    "content": "/*\n** Bit manipulation library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_bit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_bit\n\n#if LJ_HASFFI\nstatic int bit_result64(lua_State *L, CTypeID id, uint64_t x)\n{\n  GCcdata *cd = lj_cdata_new_(L, id, 8);\n  *(uint64_t *)cdataptr(cd) = x;\n  setcdataV(L, L->base-1-LJ_FR2, cd);\n  return FFH_RES(1);\n}\n#else\nstatic int32_t bit_checkbit(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else {\n    int32_t i = lj_num2bit(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return i;\n  }\n}\n#endif\n\nLJLIB_ASM(bit_tobit)\t\tLJLIB_REC(bit_tobit)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  setintV(L->base-1-LJ_FR2, (int32_t)lj_carith_check64(L, 1, &id));\n  return FFH_RES(1);\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_bnot)\t\tLJLIB_REC(bit_unary IR_BNOT)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  return id ? bit_result64(L, id, ~x) : FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_bswap)\t\tLJLIB_REC(bit_unary IR_BSWAP)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  return id ? bit_result64(L, id, lj_bswap64(x)) : FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_lshift)\t\tLJLIB_REC(bit_shift IR_BSHL)\n{\n#if LJ_HASFFI\n  CTypeID id = 0, id2 = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  int32_t sh = (int32_t)lj_carith_check64(L, 2, &id2);\n  if (id) {\n    x = lj_carith_shift64(x, sh, curr_func(L)->c.ffid - (int)FF_bit_lshift);\n    return bit_result64(L, id, x);\n  }\n  if (id2) setintV(L->base+1, sh);\n  return FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  bit_checkbit(L, 2);\n  return FFH_RETRY;\n#endif\n}\nLJLIB_ASM_(bit_rshift)\t\tLJLIB_REC(bit_shift IR_BSHR)\nLJLIB_ASM_(bit_arshift)\t\tLJLIB_REC(bit_shift IR_BSAR)\nLJLIB_ASM_(bit_rol)\t\tLJLIB_REC(bit_shift IR_BROL)\nLJLIB_ASM_(bit_ror)\t\tLJLIB_REC(bit_shift IR_BROR)\n\nLJLIB_ASM(bit_band)\t\tLJLIB_REC(bit_nary IR_BAND)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  TValue *o = L->base, *top = L->top;\n  int i = 0;\n  do { lj_carith_check64(L, ++i, &id); } while (++o < top);\n  if (id) {\n    CTState *cts = ctype_cts(L);\n    CType *ct = ctype_get(cts, id);\n    int op = curr_func(L)->c.ffid - (int)FF_bit_bor;\n    uint64_t x, y = op >= 0 ? 0 : ~(uint64_t)0;\n    o = L->base;\n    do {\n      lj_cconv_ct_tv(cts, ct, (uint8_t *)&x, o, 0);\n      if (op < 0) y &= x; else if (op == 0) y |= x; else y ^= x;\n    } while (++o < top);\n    return bit_result64(L, id, y);\n  }\n  return FFH_RETRY;\n#else\n  int i = 0;\n  do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);\n  return FFH_RETRY;\n#endif\n}\nLJLIB_ASM_(bit_bor)\t\tLJLIB_REC(bit_nary IR_BOR)\nLJLIB_ASM_(bit_bxor)\t\tLJLIB_REC(bit_nary IR_BXOR)\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(bit_tohex)\t\tLJLIB_REC(.)\n{\n#if LJ_HASFFI\n  CTypeID id = 0, id2 = 0;\n  uint64_t b = lj_carith_check64(L, 1, &id);\n  int32_t n = L->base+1>=L->top ? (id ? 16 : 8) :\n\t\t\t\t  (int32_t)lj_carith_check64(L, 2, &id2);\n#else\n  uint32_t b = (uint32_t)bit_checkbit(L, 1);\n  int32_t n = L->base+1>=L->top ? 8 : bit_checkbit(L, 2);\n#endif\n  SBuf *sb = lj_buf_tmp_(L);\n  SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);\n  if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }\n  sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);\n#if LJ_HASFFI\n  if (n < 16) b &= ((uint64_t)1 << 4*n)-1;\n#else\n  if (n < 8) b &= (1u << 4*n)-1;\n#endif\n  sb = lj_strfmt_putfxint(sb, sf, b);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_bit(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_BITLIBNAME, bit);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_debug.c",
    "content": "/*\n** Debug library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_debug_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_debug\n\nLJLIB_CF(debug_getregistry)\n{\n  copyTV(L, L->top++, registry(L));\n  return 1;\n}\n\nLJLIB_CF(debug_getmetatable)\tLJLIB_REC(.)\n{\n  lj_lib_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    setnilV(L->top-1);\n  }\n  return 1;\n}\n\nLJLIB_CF(debug_setmetatable)\n{\n  lj_lib_checktabornil(L, 2);\n  L->top = L->base+2;\n  lua_setmetatable(L, 1);\n#if !LJ_52\n  setboolV(L->top-1, 1);\n#endif\n  return 1;\n}\n\nLJLIB_CF(debug_getfenv)\n{\n  lj_lib_checkany(L, 1);\n  lua_getfenv(L, 1);\n  return 1;\n}\n\nLJLIB_CF(debug_setfenv)\n{\n  lj_lib_checktab(L, 2);\n  L->top = L->base+2;\n  if (!lua_setfenv(L, 1))\n    lj_err_caller(L, LJ_ERR_SETFENV);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void settabss(lua_State *L, const char *i, const char *v)\n{\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic void settabsi(lua_State *L, const char *i, int v)\n{\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic void settabsb(lua_State *L, const char *i, int v)\n{\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic lua_State *getthread(lua_State *L, int *arg)\n{\n  if (L->base < L->top && tvisthread(L->base)) {\n    *arg = 1;\n    return threadV(L->base);\n  } else {\n    *arg = 0;\n    return L;\n  }\n}\n\nstatic void treatstackoption(lua_State *L, lua_State *L1, const char *fname)\n{\n  if (L == L1) {\n    lua_pushvalue(L, -2);\n    lua_remove(L, -3);\n  }\n  else\n    lua_xmove(L1, L, 1);\n  lua_setfield(L, -2, fname);\n}\n\nLJLIB_CF(debug_getinfo)\n{\n  lj_Debug ar;\n  int arg, opt_f = 0, opt_L = 0;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnSu\");\n  if (lua_isnumber(L, arg+1)) {\n    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) {\n      setnilV(L->top-1);\n      return 1;\n    }\n  } else if (L->base+arg < L->top && tvisfunc(L->base+arg)) {\n    options = lua_pushfstring(L, \">%s\", options);\n    setfuncV(L1, L1->top++, funcV(L->base+arg));\n  } else {\n    lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL);\n  }\n  if (!lj_debug_getinfo(L1, options, &ar, 1))\n    lj_err_arg(L, arg+2, LJ_ERR_INVOPT);\n  lua_createtable(L, 0, 16);  /* Create result table. */\n  for (; *options; options++) {\n    switch (*options) {\n    case 'S':\n      settabss(L, \"source\", ar.source);\n      settabss(L, \"short_src\", ar.short_src);\n      settabsi(L, \"linedefined\", ar.linedefined);\n      settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n      settabss(L, \"what\", ar.what);\n      break;\n    case 'l':\n      settabsi(L, \"currentline\", ar.currentline);\n      break;\n    case 'u':\n      settabsi(L, \"nups\", ar.nups);\n      settabsi(L, \"nparams\", ar.nparams);\n      settabsb(L, \"isvararg\", ar.isvararg);\n      break;\n    case 'n':\n      settabss(L, \"name\", ar.name);\n      settabss(L, \"namewhat\", ar.namewhat);\n      break;\n    case 'f': opt_f = 1; break;\n    case 'L': opt_L = 1; break;\n    default: break;\n    }\n  }\n  if (opt_L) treatstackoption(L, L1, \"activelines\");\n  if (opt_f) treatstackoption(L, L1, \"func\");\n  return 1;  /* Return result table. */\n}\n\nLJLIB_CF(debug_getlocal)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int slot = lj_lib_checkint(L, arg+2);\n  if (tvisfunc(L->base+arg)) {\n    L->top = L->base+arg+1;\n    lua_pushstring(L, lua_getlocal(L, NULL, slot));\n    return 1;\n  }\n  if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))\n    lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);\n  name = lua_getlocal(L1, &ar, slot);\n  if (name) {\n    lua_xmove(L1, L, 1);\n    lua_pushstring(L, name);\n    lua_pushvalue(L, -2);\n    return 2;\n  } else {\n    setnilV(L->top-1);\n    return 1;\n  }\n}\n\nLJLIB_CF(debug_setlocal)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  TValue *tv;\n  if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))\n    lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);\n  tv = lj_lib_checkany(L, arg+3);\n  copyTV(L1, L1->top++, tv);\n  lua_pushstring(L, lua_setlocal(L1, &ar, lj_lib_checkint(L, arg+2)));\n  return 1;\n}\n\nstatic int debug_getupvalue(lua_State *L, int get)\n{\n  int32_t n = lj_lib_checkint(L, 2);\n  const char *name;\n  lj_lib_checkfunc(L, 1);\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name) {\n    lua_pushstring(L, name);\n    if (!get) return 1;\n    copyTV(L, L->top, L->top-2);\n    L->top++;\n    return 2;\n  }\n  return 0;\n}\n\nLJLIB_CF(debug_getupvalue)\n{\n  return debug_getupvalue(L, 1);\n}\n\nLJLIB_CF(debug_setupvalue)\n{\n  lj_lib_checkany(L, 3);\n  return debug_getupvalue(L, 0);\n}\n\nLJLIB_CF(debug_upvalueid)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  int32_t n = lj_lib_checkint(L, 2) - 1;\n  if ((uint32_t)n >= fn->l.nupvalues)\n    lj_err_arg(L, 2, LJ_ERR_IDXRNG);\n  setlightudV(L->top-1, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :\n\t\t\t\t\t(void *)&fn->c.upvalue[n]);\n  return 1;\n}\n\nLJLIB_CF(debug_upvaluejoin)\n{\n  GCfunc *fn[2];\n  GCRef *p[2];\n  int i;\n  for (i = 0; i < 2; i++) {\n    int32_t n;\n    fn[i] = lj_lib_checkfunc(L, 2*i+1);\n    if (!isluafunc(fn[i]))\n      lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC);\n    n = lj_lib_checkint(L, 2*i+2) - 1;\n    if ((uint32_t)n >= fn[i]->l.nupvalues)\n      lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG);\n    p[i] = &fn[i]->l.uvptr[n];\n  }\n  setgcrefr(*p[0], *p[1]);\n  lj_gc_objbarrier(L, fn[0], gcref(*p[1]));\n  return 0;\n}\n\n#if LJ_52\nLJLIB_CF(debug_getuservalue)\n{\n  TValue *o = L->base;\n  if (o < L->top && tvisudata(o))\n    settabV(L, o, tabref(udataV(o)->env));\n  else\n    setnilV(o);\n  L->top = o+1;\n  return 1;\n}\n\nLJLIB_CF(debug_setuservalue)\n{\n  TValue *o = L->base;\n  if (!(o < L->top && tvisudata(o)))\n    lj_err_argt(L, 1, LUA_TUSERDATA);\n  if (!(o+1 < L->top && tvistab(o+1)))\n    lj_err_argt(L, 2, LUA_TTABLE);\n  L->top = o+2;\n  lua_setfenv(L, 1);\n  return 1;\n}\n#endif\n\n/* ------------------------------------------------------------------------ */\n\nstatic const char KEY_HOOK = 'h';\n\nstatic void hookf(lua_State *L, lua_Debug *ar)\n{\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  if (lua_isfunction(L, -1)) {\n    lua_pushstring(L, hooknames[(int)ar->event]);\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);\n    else lua_pushnil(L);\n    lua_call(L, 2, 0);\n  }\n}\n\nstatic int makemask(const char *smask, int count)\n{\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\nstatic char *unmakemask(int mask, char *smask)\n{\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\nLJLIB_CF(debug_sethook)\n{\n  int arg, mask, count;\n  lua_Hook func;\n  (void)getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  } else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = luaL_optint(L, arg+3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_pushvalue(L, arg+1);\n  lua_rawset(L, LUA_REGISTRYINDEX);\n  lua_sethook(L, func, mask, count);\n  return 0;\n}\n\nLJLIB_CF(debug_gethook)\n{\n  char buff[5];\n  int mask = lua_gethookmask(L);\n  lua_Hook hook = lua_gethook(L);\n  if (hook != NULL && hook != hookf) {  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  } else {\n    lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n    lua_rawget(L, LUA_REGISTRYINDEX);   /* get hook */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));\n  lua_pushinteger(L, lua_gethookcount(L));\n  return 3;\n}\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(debug_debug)\n{\n  for (;;) {\n    char buffer[250];\n    fputs(\"lua_debug> \", stderr);\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n\tstrcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n\tlua_pcall(L, 0, 0, 0)) {\n      fputs(lua_tostring(L, -1), stderr);\n      fputs(\"\\n\", stderr);\n    }\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n#define LEVELS1\t12\t/* size of the first part of the stack */\n#define LEVELS2\t10\t/* size of the second part of the stack */\n\nLJLIB_CF(debug_traceback)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg+1);\n  if (msg == NULL && L->top > L->base+arg)\n    L->top = L->base+arg+1;\n  else\n    luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1)));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_debug(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_DBLIBNAME, debug);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_ffi.c",
    "content": "/*\n** FFI library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_ffi_c\n#define LUA_LIB\n\n#include <errno.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cparse.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_clib.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* -- C type checks ------------------------------------------------------- */\n\n/* Check first argument for a C type and returns its ID. */\nstatic CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param)\n{\n  TValue *o = L->base;\n  if (!(o < L->top)) {\n  err_argtype:\n    lj_err_argtype(L, 1, \"C type\");\n  }\n  if (tvisstr(o)) {  /* Parse an abstract C type declaration. */\n    GCstr *s = strV(o);\n    CPState cp;\n    int errcode;\n    cp.L = L;\n    cp.cts = cts;\n    cp.srcname = strdata(s);\n    cp.p = strdata(s);\n    cp.param = param;\n    cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;\n    errcode = lj_cparse(&cp);\n    if (errcode) lj_err_throw(L, errcode);  /* Propagate errors. */\n    return cp.val.id;\n  } else {\n    GCcdata *cd;\n    if (!tviscdata(o)) goto err_argtype;\n    if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM);\n    cd = cdataV(o);\n    return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid;\n  }\n}\n\n/* Check argument for C data and return it. */\nstatic GCcdata *ffi_checkcdata(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tviscdata(o)))\n    lj_err_argt(L, narg, LUA_TCDATA);\n  return cdataV(o);\n}\n\n/* Convert argument to C pointer. */\nstatic void *ffi_checkptr(lua_State *L, int narg, CTypeID id)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = L->base + narg-1;\n  void *p;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg));\n  return p;\n}\n\n/* Convert argument to int32_t. */\nstatic int32_t ffi_checkint(lua_State *L, int narg)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = L->base + narg-1;\n  int32_t i;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o,\n\t\t CCF_ARG(narg));\n  return i;\n}\n\n/* -- C type metamethods -------------------------------------------------- */\n\n#define LJLIB_MODULE_ffi_meta\n\n/* Handle ctype __index/__newindex metamethods. */\nstatic int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  cTValue *tv = lj_ctype_meta(cts, id, mm);\n  TValue *base = L->base;\n  if (!tv) {\n    const char *s;\n  err_index:\n    s = strdata(lj_ctype_repr(L, id, NULL));\n    if (tvisstr(L->base+1)) {\n      lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1));\n    } else {\n      const char *key = tviscdata(L->base+1) ?\n\tstrdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) :\n\tlj_typename(L->base+1);\n      lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key);\n    }\n  }\n  if (!tvisfunc(tv)) {\n    if (mm == MM_index) {\n      cTValue *o = lj_meta_tget(L, tv, base+1);\n      if (o) {\n\tif (tvisnil(o)) goto err_index;\n\tcopyTV(L, L->top-1, o);\n\treturn 1;\n      }\n    } else {\n      TValue *o = lj_meta_tset(L, tv, base+1);\n      if (o) {\n\tcopyTV(L, o, base+2);\n\treturn 0;\n      }\n    }\n    copyTV(L, base, L->top);\n    tv = L->top-1-LJ_FR2;\n  }\n  return lj_meta_tailcall(L, tv);\n}\n\nLJLIB_CF(ffi_meta___index)\tLJLIB_REC(cdata_index 0)\n{\n  CTState *cts = ctype_cts(L);\n  CTInfo qual = 0;\n  CType *ct;\n  uint8_t *p;\n  TValue *o = L->base;\n  if (!(o+1 < L->top && tviscdata(o)))  /* Also checks for presence of key. */\n    lj_err_argt(L, 1, LUA_TCDATA);\n  ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);\n  if ((qual & 1))\n    return ffi_index_meta(L, cts, ct, MM_index);\n  if (lj_cdata_get(cts, ct, L->top-1, p))\n    lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_meta___newindex)\tLJLIB_REC(cdata_index 1)\n{\n  CTState *cts = ctype_cts(L);\n  CTInfo qual = 0;\n  CType *ct;\n  uint8_t *p;\n  TValue *o = L->base;\n  if (!(o+2 < L->top && tviscdata(o)))  /* Also checks for key and value. */\n    lj_err_argt(L, 1, LUA_TCDATA);\n  ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);\n  if ((qual & 1)) {\n    if ((qual & CTF_CONST))\n      lj_err_caller(L, LJ_ERR_FFI_WRCONST);\n    return ffi_index_meta(L, cts, ct, MM_newindex);\n  }\n  lj_cdata_set(cts, ct, p, o+2, qual);\n  return 0;\n}\n\n/* Common handler for cdata arithmetic. */\nstatic int ffi_arith(lua_State *L)\n{\n  MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq);\n  return lj_carith_op(L, mm);\n}\n\n/* The following functions must be in contiguous ORDER MM. */\nLJLIB_CF(ffi_meta___eq)\t\tLJLIB_REC(cdata_arith MM_eq)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___len)\tLJLIB_REC(cdata_arith MM_len)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___lt)\t\tLJLIB_REC(cdata_arith MM_lt)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___le)\t\tLJLIB_REC(cdata_arith MM_le)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___concat)\tLJLIB_REC(cdata_arith MM_concat)\n{\n  return ffi_arith(L);\n}\n\n/* Forward declaration. */\nstatic int lj_cf_ffi_new(lua_State *L);\n\nLJLIB_CF(ffi_meta___call)\tLJLIB_REC(cdata_call)\n{\n  CTState *cts = ctype_cts(L);\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  CTypeID id = cd->ctypeid;\n  CType *ct;\n  cTValue *tv;\n  MMS mm = MM_call;\n  if (cd->ctypeid == CTID_CTYPEID) {\n    id = *(CTypeID *)cdataptr(cd);\n    mm = MM_new;\n  } else {\n    int ret = lj_ccall_func(L, cd);\n    if (ret >= 0)\n      return ret;\n  }\n  /* Handle ctype __call/__new metamethod. */\n  ct = ctype_raw(cts, id);\n  if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n  tv = lj_ctype_meta(cts, id, mm);\n  if (tv)\n    return lj_meta_tailcall(L, tv);\n  else if (mm == MM_call)\n    lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL)));\n  return lj_cf_ffi_new(L);\n}\n\nLJLIB_CF(ffi_meta___add)\tLJLIB_REC(cdata_arith MM_add)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___sub)\tLJLIB_REC(cdata_arith MM_sub)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___mul)\tLJLIB_REC(cdata_arith MM_mul)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___div)\tLJLIB_REC(cdata_arith MM_div)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___mod)\tLJLIB_REC(cdata_arith MM_mod)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___pow)\tLJLIB_REC(cdata_arith MM_pow)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___unm)\tLJLIB_REC(cdata_arith MM_unm)\n{\n  return ffi_arith(L);\n}\n/* End of contiguous ORDER MM. */\n\nLJLIB_CF(ffi_meta___tostring)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  const char *msg = \"cdata<%s>: %p\";\n  CTypeID id = cd->ctypeid;\n  void *p = cdataptr(cd);\n  if (id == CTID_CTYPEID) {\n    msg = \"ctype<%s>\";\n    id = *(CTypeID *)p;\n  } else {\n    CTState *cts = ctype_cts(L);\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isref(ct->info)) {\n      p = *(void **)p;\n      ct = ctype_rawchild(cts, ct);\n    }\n    if (ctype_iscomplex(ct->info)) {\n      setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size));\n      goto checkgc;\n    } else if (ct->size == 8 && ctype_isinteger(ct->info)) {\n      setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd),\n\t\t\t\t\t       (ct->info & CTF_UNSIGNED)));\n      goto checkgc;\n    } else if (ctype_isfunc(ct->info)) {\n      p = *(void **)p;\n    } else if (ctype_isenum(ct->info)) {\n      msg = \"cdata<%s>: %d\";\n      p = (void *)(uintptr_t)*(uint32_t **)p;\n    } else {\n      if (ctype_isptr(ct->info)) {\n\tp = cdata_getptr(p, ct->size);\n\tct = ctype_rawchild(cts, ct);\n      }\n      if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) {\n\t/* Handle ctype __tostring metamethod. */\n\tcTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring);\n\tif (tv)\n\t  return lj_meta_tailcall(L, tv);\n      }\n    }\n  }\n  lj_strfmt_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);\ncheckgc:\n  lj_gc_check(L);\n  return 1;\n}\n\nstatic int ffi_pairs(lua_State *L, MMS mm)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkcdata(L, 1)->ctypeid;\n  CType *ct = ctype_raw(cts, id);\n  cTValue *tv;\n  if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n  tv = lj_ctype_meta(cts, id, mm);\n  if (!tv)\n    lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)),\n\t\t   strdata(mmname_str(G(L), mm)));\n  return lj_meta_tailcall(L, tv);\n}\n\nLJLIB_CF(ffi_meta___pairs)\n{\n  return ffi_pairs(L, MM_pairs);\n}\n\nLJLIB_CF(ffi_meta___ipairs)\n{\n  return ffi_pairs(L, MM_ipairs);\n}\n\nLJLIB_PUSH(\"ffi\") LJLIB_SET(__metatable)\n\n#include \"lj_libdef.h\"\n\n/* -- C library metamethods ----------------------------------------------- */\n\n#define LJLIB_MODULE_ffi_clib\n\n/* Index C library by a name. */\nstatic TValue *ffi_clib_index(lua_State *L)\n{\n  TValue *o = L->base;\n  CLibrary *cl;\n  if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB))\n    lj_err_argt(L, 1, LUA_TUSERDATA);\n  cl = (CLibrary *)uddata(udataV(o));\n  if (!(o+1 < L->top && tvisstr(o+1)))\n    lj_err_argt(L, 2, LUA_TSTRING);\n  return lj_clib_index(L, cl, strV(o+1));\n}\n\nLJLIB_CF(ffi_clib___index)\tLJLIB_REC(clib_index 1)\n{\n  TValue *tv = ffi_clib_index(L);\n  if (tviscdata(tv)) {\n    CTState *cts = ctype_cts(L);\n    GCcdata *cd = cdataV(tv);\n    CType *s = ctype_get(cts, cd->ctypeid);\n    if (ctype_isextern(s->info)) {\n      CTypeID sid = ctype_cid(s->info);\n      void *sp = *(void **)cdataptr(cd);\n      CType *ct = ctype_raw(cts, sid);\n      if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp))\n\tlj_gc_check(L);\n      return 1;\n    }\n  }\n  copyTV(L, L->top-1, tv);\n  return 1;\n}\n\nLJLIB_CF(ffi_clib___newindex)\tLJLIB_REC(clib_index 0)\n{\n  TValue *tv = ffi_clib_index(L);\n  TValue *o = L->base+2;\n  if (o < L->top && tviscdata(tv)) {\n    CTState *cts = ctype_cts(L);\n    GCcdata *cd = cdataV(tv);\n    CType *d = ctype_get(cts, cd->ctypeid);\n    if (ctype_isextern(d->info)) {\n      CTInfo qual = 0;\n      for (;;) {  /* Skip attributes and collect qualifiers. */\n\td = ctype_child(cts, d);\n\tif (!ctype_isattrib(d->info)) break;\n\tif (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;\n      }\n      if (!((d->info|qual) & CTF_CONST)) {\n\tlj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0);\n\treturn 0;\n      }\n    }\n  }\n  lj_err_caller(L, LJ_ERR_FFI_WRCONST);\n  return 0;  /* unreachable */\n}\n\nLJLIB_CF(ffi_clib___gc)\n{\n  TValue *o = L->base;\n  if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)\n    lj_clib_unload((CLibrary *)uddata(udataV(o)));\n  return 0;\n}\n\n#include \"lj_libdef.h\"\n\n/* -- Callback function metamethods --------------------------------------- */\n\n#define LJLIB_MODULE_ffi_callback\n\nstatic int ffi_callback_set(lua_State *L, GCfunc *fn)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) {\n    MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd));\n    if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) {\n      GCtab *t = cts->miscmap;\n      TValue *tv = lj_tab_setint(L, t, (int32_t)slot);\n      if (fn) {\n\tsetfuncV(L, tv, fn);\n\tlj_gc_anybarriert(L, t);\n      } else {\n\tsetnilV(tv);\n\tcts->cb.cbid[slot] = 0;\n\tcts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid;\n      }\n      return 0;\n    }\n  }\n  lj_err_caller(L, LJ_ERR_FFI_BADCBACK);\n  return 0;\n}\n\nLJLIB_CF(ffi_callback_free)\n{\n  return ffi_callback_set(L, NULL);\n}\n\nLJLIB_CF(ffi_callback_set)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 2);\n  return ffi_callback_set(L, fn);\n}\n\nLJLIB_PUSH(top-1) LJLIB_SET(__index)\n\n#include \"lj_libdef.h\"\n\n/* -- FFI library functions ----------------------------------------------- */\n\n#define LJLIB_MODULE_ffi\n\nLJLIB_CF(ffi_cdef)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  CPState cp;\n  int errcode;\n  cp.L = L;\n  cp.cts = ctype_cts(L);\n  cp.srcname = strdata(s);\n  cp.p = strdata(s);\n  cp.param = L->base+1;\n  cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT;\n  errcode = lj_cparse(&cp);\n  if (errcode) lj_err_throw(L, errcode);  /* Propagate errors. */\n  lj_gc_check(L);\n  return 0;\n}\n\nLJLIB_CF(ffi_new)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CType *ct = ctype_raw(cts, id);\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  TValue *o = L->base+1;\n  GCcdata *cd;\n  if ((info & CTF_VLA)) {\n    o++;\n    sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));\n  }\n  if (sz == CTSIZE_INVALID)\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE);\n  cd = lj_cdata_newx(cts, id, sz, info);\n  setcdataV(L, o-1, cd);  /* Anchor the uninitialized cdata. */\n  lj_cconv_ct_init(cts, ct, sz, cdataptr(cd),\n\t\t   o, (MSize)(L->top - o));  /* Initialize cdata. */\n  if (ctype_isstruct(ct->info)) {\n    /* Handle ctype __gc metamethod. Use the fast lookup here. */\n    cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);\n    if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) {\n      GCtab *t = cts->finalizer;\n      if (gcref(t->metatable)) {\n\t/* Add to finalizer table, if still enabled. */\n\tcopyTV(L, lj_tab_set(L, t, o-1), tv);\n\tlj_gc_anybarriert(L, t);\n\tcd->marked |= LJ_GC_CDATA_FIN;\n      }\n    }\n  }\n  L->top = o;  /* Only return the cdata itself. */\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_cast)\tLJLIB_REC(ffi_new)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CType *d = ctype_raw(cts, id);\n  TValue *o = lj_lib_checkany(L, 2);\n  L->top = o+1;  /* Make sure this is the last item on the stack. */\n  if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) {\n    GCcdata *cd = lj_cdata_new(cts, id, d->size);\n    lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST);\n    setcdataV(L, o, cd);\n    lj_gc_check(L);\n  }\n  return 1;\n}\n\nLJLIB_CF(ffi_typeof)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, L->base+1);\n  GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4);\n  *(CTypeID *)cdataptr(cd) = id;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\n/* Internal and unsupported API. */\nLJLIB_CF(ffi_typeinfo)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = (CTypeID)ffi_checkint(L, 1);\n  if (id > 0 && id < cts->top) {\n    CType *ct = ctype_get(cts, id);\n    GCtab *t;\n    lua_createtable(L, 0, 4);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"info\")), (int32_t)ct->info);\n    if (ct->size != CTSIZE_INVALID)\n      setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"size\")), (int32_t)ct->size);\n    if (ct->sib)\n      setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"sib\")), (int32_t)ct->sib);\n    if (gcref(ct->name)) {\n      GCstr *s = gco2str(gcref(ct->name));\n      setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"name\")), s);\n    }\n    lj_gc_check(L);\n    return 1;\n  }\n  return 0;\n}\n\nLJLIB_CF(ffi_istype)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id1 = ffi_checkctype(L, cts, NULL);\n  TValue *o = lj_lib_checkany(L, 2);\n  int b = 0;\n  if (tviscdata(o)) {\n    GCcdata *cd = cdataV(o);\n    CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) :\n\t\t\t\t\t\tcd->ctypeid;\n    CType *ct1 = lj_ctype_rawref(cts, id1);\n    CType *ct2 = lj_ctype_rawref(cts, id2);\n    if (ct1 == ct2) {\n      b = 1;\n    } else if (ctype_type(ct1->info) == ctype_type(ct2->info) &&\n\t       ct1->size == ct2->size) {\n      if (ctype_ispointer(ct1->info))\n\tb = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL);\n      else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info))\n\tb = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0);\n    } else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) &&\n\t       ct1 == ctype_rawchild(cts, ct2)) {\n      b = 1;\n    }\n  }\n  setboolV(L->top-1, b);\n  setboolV(&G(L)->tmptv2, b);  /* Remember for trace recorder. */\n  return 1;\n}\n\nLJLIB_CF(ffi_sizeof)\tLJLIB_REC(ffi_xof FF_ffi_sizeof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CTSize sz;\n  if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) {\n    sz = cdatavlen(cdataV(L->base));\n  } else {\n    CType *ct = lj_ctype_rawref(cts, id);\n    if (ctype_isvltype(ct->info))\n      sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));\n    else\n      sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;\n    if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) {\n      setnilV(L->top-1);\n      return 1;\n    }\n  }\n  setintV(L->top-1, (int32_t)sz);\n  return 1;\n}\n\nLJLIB_CF(ffi_alignof)\tLJLIB_REC(ffi_xof FF_ffi_alignof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CTSize sz = 0;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  setintV(L->top-1, 1 << ctype_align(info));\n  return 1;\n}\n\nLJLIB_CF(ffi_offsetof)\tLJLIB_REC(ffi_xof FF_ffi_offsetof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  GCstr *name = lj_lib_checkstr(L, 2);\n  CType *ct = lj_ctype_rawref(cts, id);\n  CTSize ofs;\n  if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) {\n    CType *fct = lj_ctype_getfield(cts, ct, name, &ofs);\n    if (fct) {\n      setintV(L->top-1, ofs);\n      if (ctype_isfield(fct->info)) {\n\treturn 1;\n      } else if (ctype_isbitfield(fct->info)) {\n\tsetintV(L->top++, ctype_bitpos(fct->info));\n\tsetintV(L->top++, ctype_bitbsz(fct->info));\n\treturn 3;\n      }\n    }\n  }\n  return 0;\n}\n\nLJLIB_CF(ffi_errno)\tLJLIB_REC(.)\n{\n  int err = errno;\n  if (L->top > L->base)\n    errno = ffi_checkint(L, 1);\n  setintV(L->top++, err);\n  return 1;\n}\n\nLJLIB_CF(ffi_string)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = lj_lib_checkany(L, 1);\n  const char *p;\n  size_t len;\n  if (o+1 < L->top && !tvisnil(o+1)) {\n    len = (size_t)ffi_checkint(L, 2);\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o,\n\t\t   CCF_ARG(1));\n  } else {\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o,\n\t\t   CCF_ARG(1));\n    len = strlen(p);\n  }\n  L->top = o+1;  /* Make sure this is the last item on the stack. */\n  setstrV(L, o, lj_str_new(L, p, len));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_copy)\tLJLIB_REC(.)\n{\n  void *dp = ffi_checkptr(L, 1, CTID_P_VOID);\n  void *sp = ffi_checkptr(L, 2, CTID_P_CVOID);\n  TValue *o = L->base+1;\n  CTSize len;\n  if (tvisstr(o) && o+1 >= L->top)\n    len = strV(o)->len+1;  /* Copy Lua string including trailing '\\0'. */\n  else\n    len = (CTSize)ffi_checkint(L, 3);\n  memcpy(dp, sp, len);\n  return 0;\n}\n\nLJLIB_CF(ffi_fill)\tLJLIB_REC(.)\n{\n  void *dp = ffi_checkptr(L, 1, CTID_P_VOID);\n  CTSize len = (CTSize)ffi_checkint(L, 2);\n  int32_t fill = 0;\n  if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3);\n  memset(dp, fill, len);\n  return 0;\n}\n\n#define H_(le, be)\tLJ_ENDIAN_SELECT(0x##le, 0x##be)\n\n/* Test ABI string. */\nLJLIB_CF(ffi_abi)\tLJLIB_REC(.)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int b = 0;\n  switch (s->hash) {\n#if LJ_64\n  case H_(849858eb,ad35fd06): b = 1; break;  /* 64bit */\n#else\n  case H_(662d3c79,d0e22477): b = 1; break;  /* 32bit */\n#endif\n#if LJ_ARCH_HASFPU\n  case H_(e33ee463,e33ee463): b = 1; break;  /* fpu */\n#endif\n#if LJ_ABI_SOFTFP\n  case H_(61211a23,c2e8c81c): b = 1; break;  /* softfp */\n#else\n  case H_(539417a8,8ce0812f): b = 1; break;  /* hardfp */\n#endif\n#if LJ_ABI_EABI\n  case H_(2182df8f,f2ed1152): b = 1; break;  /* eabi */\n#endif\n#if LJ_ABI_WIN\n  case H_(4ab624a8,4ab624a8): b = 1; break;  /* win */\n#endif\n  case H_(3af93066,1f001464): b = 1; break;  /* le/be */\n#if LJ_GC64\n  case H_(9e89d2c9,13c83c92): b = 1; break;  /* gc64 */\n#endif\n  default:\n    break;\n  }\n  setboolV(L->top-1, b);\n  setboolV(&G(L)->tmptv2, b);  /* Remember for trace recorder. */\n  return 1;\n}\n\n#undef H_\n\nLJLIB_PUSH(top-8) LJLIB_SET(!)  /* Store reference to miscmap table. */\n\nLJLIB_CF(ffi_metatype)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  GCtab *mt = lj_lib_checktab(L, 2);\n  GCtab *t = cts->miscmap;\n  CType *ct = ctype_get(cts, id);  /* Only allow raw types. */\n  TValue *tv;\n  GCcdata *cd;\n  if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||\n\tctype_isvector(ct->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  tv = lj_tab_setinth(L, t, -(int32_t)id);\n  if (!tvisnil(tv))\n    lj_err_caller(L, LJ_ERR_PROTMT);\n  settabV(L, tv, mt);\n  lj_gc_anybarriert(L, t);\n  cd = lj_cdata_new(cts, CTID_CTYPEID, 4);\n  *(CTypeID *)cdataptr(cd) = id;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_PUSH(top-7) LJLIB_SET(!)  /* Store reference to finalizer table. */\n\nLJLIB_CF(ffi_gc)\tLJLIB_REC(.)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  TValue *fin = lj_lib_checkany(L, 2);\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||\n\tctype_isrefarray(ct->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  lj_cdata_setfin(L, cd, gcval(fin), itype(fin));\n  L->top = L->base+1;  /* Pass through the cdata object. */\n  return 1;\n}\n\nLJLIB_PUSH(top-5) LJLIB_SET(!)  /* Store clib metatable in func environment. */\n\nLJLIB_CF(ffi_load)\n{\n  GCstr *name = lj_lib_checkstr(L, 1);\n  int global = (L->base+1 < L->top && tvistruecond(L->base+1));\n  lj_clib_load(L, tabref(curr_func(L)->c.env), name, global);\n  return 1;\n}\n\nLJLIB_PUSH(top-4) LJLIB_SET(C)\nLJLIB_PUSH(top-3) LJLIB_SET(os)\nLJLIB_PUSH(top-2) LJLIB_SET(arch)\n\n#include \"lj_libdef.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Create special weak-keyed finalizer table. */\nstatic GCtab *ffi_finalizer(lua_State *L)\n{\n  /* NOBARRIER: The table is new (marked white). */\n  GCtab *t = lj_tab_new(L, 0, 1);\n  settabV(L, L->top++, t);\n  setgcref(t->metatable, obj2gco(t));\n  setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"__mode\")),\n\t  lj_str_newlit(L, \"K\"));\n  t->nomm = (uint8_t)(~(1u<<MM_mode));\n  return t;\n}\n\n/* Register FFI module as loaded. */\nstatic void ffi_register_module(lua_State *L)\n{\n  cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, \"_LOADED\"));\n  if (tmp && tvistab(tmp)) {\n    GCtab *t = tabV(tmp);\n    copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1);\n    lj_gc_anybarriert(L, t);\n  }\n}\n\nLUALIB_API int luaopen_ffi(lua_State *L)\n{\n  CTState *cts = lj_ctype_init(L);\n  settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1)));\n  cts->finalizer = ffi_finalizer(L);\n  LJ_LIB_REG(L, NULL, ffi_meta);\n  /* NOBARRIER: basemt is a GC root. */\n  setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1)));\n  LJ_LIB_REG(L, NULL, ffi_clib);\n  LJ_LIB_REG(L, NULL, ffi_callback);\n  /* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */\n  settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1));\n  L->top--;\n  lj_clib_default(L, tabV(L->top-1));  /* Create ffi.C default namespace. */\n  lua_pushliteral(L, LJ_OS_NAME);\n  lua_pushliteral(L, LJ_ARCH_NAME);\n  LJ_LIB_REG(L, NULL, ffi);  /* Note: no global \"ffi\" created! */\n  ffi_register_module(L);\n  return 1;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_init.c",
    "content": "/*\n** Library initialization.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major parts taken verbatim from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_init_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_arch.h\"\n\nstatic const luaL_Reg lj_lib_load[] = {\n  { \"\",\t\t\tluaopen_base },\n  { LUA_LOADLIBNAME,\tluaopen_package },\n  { LUA_TABLIBNAME,\tluaopen_table },\n  { LUA_IOLIBNAME,\tluaopen_io },\n  { LUA_OSLIBNAME,\tluaopen_os },\n  { LUA_STRLIBNAME,\tluaopen_string },\n  { LUA_MATHLIBNAME,\tluaopen_math },\n  { LUA_DBLIBNAME,\tluaopen_debug },\n  { LUA_BITLIBNAME,\tluaopen_bit },\n  { LUA_JITLIBNAME,\tluaopen_jit },\n  { NULL,\t\tNULL }\n};\n\nstatic const luaL_Reg lj_lib_preload[] = {\n#if LJ_HASFFI\n  { LUA_FFILIBNAME,\tluaopen_ffi },\n#endif\n  { NULL,\t\tNULL }\n};\n\nLUALIB_API void luaL_openlibs(lua_State *L)\n{\n  const luaL_Reg *lib;\n  for (lib = lj_lib_load; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_pushstring(L, lib->name);\n    lua_call(L, 1, 0);\n  }\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\",\n\t\t sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);\n  for (lib = lj_lib_preload; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_setfield(L, -2, lib->name);\n  }\n  lua_pop(L, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_io.c",
    "content": "/*\n** I/O library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n\n#define lib_io_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_state.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* Userdata payload for I/O file. */\ntypedef struct IOFileUD {\n  FILE *fp;\t\t/* File handle. */\n  uint32_t type;\t/* File type. */\n} IOFileUD;\n\n#define IOFILE_TYPE_FILE\t0\t/* Regular file. */\n#define IOFILE_TYPE_PIPE\t1\t/* Pipe. */\n#define IOFILE_TYPE_STDF\t2\t/* Standard file handle. */\n#define IOFILE_TYPE_MASK\t3\n\n#define IOFILE_FLAG_CLOSE\t4\t/* Close after io.lines() iterator. */\n\n#define IOSTDF_UD(L, id)\t(&gcref(G(L)->gcroot[(id)])->ud)\n#define IOSTDF_IOF(L, id)\t((IOFileUD *)uddata(IOSTDF_UD(L, (id))))\n\n/* -- Open/close helpers -------------------------------------------------- */\n\nstatic IOFileUD *io_tofilep(lua_State *L)\n{\n  if (!(L->base < L->top && tvisudata(L->base) &&\n\tudataV(L->base)->udtype == UDTYPE_IO_FILE))\n    lj_err_argtype(L, 1, \"FILE*\");\n  return (IOFileUD *)uddata(udataV(L->base));\n}\n\nstatic IOFileUD *io_tofile(lua_State *L)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOCLFL);\n  return iof;\n}\n\nstatic FILE *io_stdfile(lua_State *L, ptrdiff_t id)\n{\n  IOFileUD *iof = IOSTDF_IOF(L, id);\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOSTDCL);\n  return iof->fp;\n}\n\nstatic IOFileUD *io_file_new(lua_State *L)\n{\n  IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));\n  GCudata *ud = udataV(L->top-1);\n  ud->udtype = UDTYPE_IO_FILE;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcrefr(ud->metatable, curr_func(L)->c.env);\n  iof->fp = NULL;\n  iof->type = IOFILE_TYPE_FILE;\n  return iof;\n}\n\nstatic IOFileUD *io_file_open(lua_State *L, const char *mode)\n{\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  IOFileUD *iof = io_file_new(L);\n  iof->fp = fopen(fname, mode);\n  if (iof->fp == NULL)\n    luaL_argerror(L, 1, lj_strfmt_pushf(L, \"%s: %s\", fname, strerror(errno)));\n  return iof;\n}\n\nstatic int io_file_close(lua_State *L, IOFileUD *iof)\n{\n  int ok;\n  if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) {\n    ok = (fclose(iof->fp) == 0);\n  } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {\n    int stat = -1;\n#if LJ_TARGET_POSIX\n    stat = pclose(iof->fp);\n#elif LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE\n    stat = _pclose(iof->fp);\n#else\n    lua_assert(0);\n    return 0;\n#endif\n#if LJ_52\n    iof->fp = NULL;\n    return luaL_execresult(L, stat);\n#else\n    ok = (stat != -1);\n#endif\n  } else {\n    lua_assert((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_STDF);\n    setnilV(L->top++);\n    lua_pushliteral(L, \"cannot close standard file\");\n    return 2;\n  }\n  iof->fp = NULL;\n  return luaL_fileresult(L, ok, NULL);\n}\n\n/* -- Read/write helpers -------------------------------------------------- */\n\nstatic int io_file_readnum(lua_State *L, FILE *fp)\n{\n  lua_Number d;\n  if (fscanf(fp, LUA_NUMBER_SCAN, &d) == 1) {\n    if (LJ_DUALNUM) {\n      int32_t i = lj_num2int(d);\n      if (d == (lua_Number)i && !tvismzero((cTValue *)&d)) {\n\tsetintV(L->top++, i);\n\treturn 1;\n      }\n    }\n    setnumV(L->top++, d);\n    return 1;\n  } else {\n    setnilV(L->top++);\n    return 0;\n  }\n}\n\nstatic int io_file_readline(lua_State *L, FILE *fp, MSize chop)\n{\n  MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0;\n  char *buf;\n  for (;;) {\n    buf = lj_buf_tmp(L, m);\n    if (fgets(buf+n, m-n, fp) == NULL) break;\n    n += (MSize)strlen(buf+n);\n    ok |= n;\n    if (n && buf[n-1] == '\\n') { n -= chop; break; }\n    if (n >= m - 64) m += m;\n  }\n  setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n  lj_gc_check(L);\n  return (int)ok;\n}\n\nstatic void io_file_readall(lua_State *L, FILE *fp)\n{\n  MSize m, n;\n  for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {\n    char *buf = lj_buf_tmp(L, m);\n    n += (MSize)fread(buf+n, 1, m-n, fp);\n    if (n != m) {\n      setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n      lj_gc_check(L);\n      return;\n    }\n  }\n}\n\nstatic int io_file_readlen(lua_State *L, FILE *fp, MSize m)\n{\n  if (m) {\n    char *buf = lj_buf_tmp(L, m);\n    MSize n = (MSize)fread(buf, 1, m, fp);\n    setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n    lj_gc_check(L);\n    return (n > 0 || m == 0);\n  } else {\n    int c = getc(fp);\n    ungetc(c, fp);\n    setstrV(L, L->top++, &G(L)->strempty);\n    return (c != EOF);\n  }\n}\n\nstatic int io_file_read(lua_State *L, FILE *fp, int start)\n{\n  int ok, n, nargs = (int)(L->top - L->base) - start;\n  clearerr(fp);\n  if (nargs == 0) {\n    ok = io_file_readline(L, fp, 1);\n    n = start+1;  /* Return 1 result. */\n  } else {\n    /* The results plus the buffers go on top of the args. */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    ok = 1;\n    for (n = start; nargs-- && ok; n++) {\n      if (tvisstr(L->base+n)) {\n\tconst char *p = strVdata(L->base+n);\n\tif (p[0] != '*')\n\t  lj_err_arg(L, n+1, LJ_ERR_INVOPT);\n\tif (p[1] == 'n')\n\t  ok = io_file_readnum(L, fp);\n\telse if ((p[1] & ~0x20) == 'L')\n\t  ok = io_file_readline(L, fp, (p[1] == 'l'));\n\telse if (p[1] == 'a')\n\t  io_file_readall(L, fp);\n\telse\n\t  lj_err_arg(L, n+1, LJ_ERR_INVFMT);\n      } else if (tvisnumber(L->base+n)) {\n\tok = io_file_readlen(L, fp, (MSize)lj_lib_checkint(L, n+1));\n      } else {\n\tlj_err_arg(L, n+1, LJ_ERR_INVOPT);\n      }\n    }\n  }\n  if (ferror(fp))\n    return luaL_fileresult(L, 0, NULL);\n  if (!ok)\n    setnilV(L->top-1);  /* Replace last result with nil. */\n  return n - start;\n}\n\nstatic int io_file_write(lua_State *L, FILE *fp, int start)\n{\n  cTValue *tv;\n  int status = 1;\n  for (tv = L->base+start; tv < L->top; tv++) {\n    MSize len;\n    const char *p = lj_strfmt_wstrnum(L, tv, &len);\n    if (!p)\n      lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING);\n    status = status && (fwrite(p, 1, len, fp) == len);\n  }\n  if (LJ_52 && status) {\n    L->top = L->base+1;\n    if (start == 0)\n      setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT));\n    return 1;\n  }\n  return luaL_fileresult(L, status, NULL);\n}\n\nstatic int io_file_iter(lua_State *L)\n{\n  GCfunc *fn = curr_func(L);\n  IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0]));\n  int n = fn->c.nupvalues - 1;\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOCLFL);\n  L->top = L->base;\n  if (n) {  /* Copy upvalues with options to stack. */\n    if (n > LUAI_MAXCSTACK)\n      lj_err_caller(L, LJ_ERR_STKOV);\n    lj_state_checkstack(L, (MSize)n);\n    memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue));\n    L->top += n;\n  }\n  n = io_file_read(L, iof->fp, 0);\n  if (ferror(iof->fp))\n    lj_err_callermsg(L, strVdata(L->top-2));\n  if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) {\n    io_file_close(L, iof);  /* Return values are ignored. */\n    return 0;\n  }\n  return n;\n}\n\nstatic int io_file_lines(lua_State *L)\n{\n  int n = (int)(L->top - L->base);\n  if (n > LJ_MAX_UPVAL)\n    lj_err_caller(L, LJ_ERR_UNPACK);\n  lua_pushcclosure(L, io_file_iter, n);\n  return 1;\n}\n\n/* -- I/O file methods ---------------------------------------------------- */\n\n#define LJLIB_MODULE_io_method\n\nLJLIB_CF(io_method_close)\n{\n  IOFileUD *iof = L->base < L->top ? io_tofile(L) :\n\t\t  IOSTDF_IOF(L, GCROOT_IO_OUTPUT);\n  return io_file_close(L, iof);\n}\n\nLJLIB_CF(io_method_read)\n{\n  return io_file_read(L, io_tofile(L)->fp, 1);\n}\n\nLJLIB_CF(io_method_write)\t\tLJLIB_REC(io_write 0)\n{\n  return io_file_write(L, io_tofile(L)->fp, 1);\n}\n\nLJLIB_CF(io_method_flush)\t\tLJLIB_REC(io_flush 0)\n{\n  return luaL_fileresult(L, fflush(io_tofile(L)->fp) == 0, NULL);\n}\n\nLJLIB_CF(io_method_seek)\n{\n  FILE *fp = io_tofile(L)->fp;\n  int opt = lj_lib_checkopt(L, 2, 1, \"\\3set\\3cur\\3end\");\n  int64_t ofs = 0;\n  cTValue *o;\n  int res;\n  if (opt == 0) opt = SEEK_SET;\n  else if (opt == 1) opt = SEEK_CUR;\n  else if (opt == 2) opt = SEEK_END;\n  o = L->base+2;\n  if (o < L->top) {\n    if (tvisint(o))\n      ofs = (int64_t)intV(o);\n    else if (tvisnum(o))\n      ofs = (int64_t)numV(o);\n    else if (!tvisnil(o))\n      lj_err_argt(L, 3, LUA_TNUMBER);\n  }\n#if LJ_TARGET_POSIX\n  res = fseeko(fp, ofs, opt);\n#elif _MSC_VER >= 1400\n  res = _fseeki64(fp, ofs, opt);\n#elif defined(__MINGW32__)\n  res = fseeko64(fp, ofs, opt);\n#else\n  res = fseek(fp, (long)ofs, opt);\n#endif\n  if (res)\n    return luaL_fileresult(L, 0, NULL);\n#if LJ_TARGET_POSIX\n  ofs = ftello(fp);\n#elif _MSC_VER >= 1400\n  ofs = _ftelli64(fp);\n#elif defined(__MINGW32__)\n  ofs = ftello64(fp);\n#else\n  ofs = (int64_t)ftell(fp);\n#endif\n  setint64V(L->top-1, ofs);\n  return 1;\n}\n\nLJLIB_CF(io_method_setvbuf)\n{\n  FILE *fp = io_tofile(L)->fp;\n  int opt = lj_lib_checkopt(L, 2, -1, \"\\4full\\4line\\2no\");\n  size_t sz = (size_t)lj_lib_optint(L, 3, LUAL_BUFFERSIZE);\n  if (opt == 0) opt = _IOFBF;\n  else if (opt == 1) opt = _IOLBF;\n  else if (opt == 2) opt = _IONBF;\n  return luaL_fileresult(L, setvbuf(fp, NULL, opt, sz) == 0, NULL);\n}\n\nLJLIB_CF(io_method_lines)\n{\n  io_tofile(L);\n  return io_file_lines(L);\n}\n\nLJLIB_CF(io_method___gc)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp != NULL && (iof->type & IOFILE_TYPE_MASK) != IOFILE_TYPE_STDF)\n    io_file_close(L, iof);\n  return 0;\n}\n\nLJLIB_CF(io_method___tostring)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp != NULL)\n    lua_pushfstring(L, \"file (%p)\", iof->fp);\n  else\n    lua_pushliteral(L, \"file (closed)\");\n  return 1;\n}\n\nLJLIB_PUSH(top-1) LJLIB_SET(__index)\n\n#include \"lj_libdef.h\"\n\n/* -- I/O library functions ----------------------------------------------- */\n\n#define LJLIB_MODULE_io\n\nLJLIB_PUSH(top-2) LJLIB_SET(!)  /* Set environment. */\n\nLJLIB_CF(io_open)\n{\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  GCstr *s = lj_lib_optstr(L, 2);\n  const char *mode = s ? strdata(s) : \"r\";\n  IOFileUD *iof = io_file_new(L);\n  iof->fp = fopen(fname, mode);\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);\n}\n\nLJLIB_CF(io_popen)\n{\n#if LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE)\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  GCstr *s = lj_lib_optstr(L, 2);\n  const char *mode = s ? strdata(s) : \"r\";\n  IOFileUD *iof = io_file_new(L);\n  iof->type = IOFILE_TYPE_PIPE;\n#if LJ_TARGET_POSIX\n  fflush(NULL);\n  iof->fp = popen(fname, mode);\n#else\n  iof->fp = _popen(fname, mode);\n#endif\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);\n#else\n  return luaL_error(L, LUA_QL(\"popen\") \" not supported\");\n#endif\n}\n\nLJLIB_CF(io_tmpfile)\n{\n  IOFileUD *iof = io_file_new(L);\n#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n  iof->fp = NULL; errno = ENOSYS;\n#else\n  iof->fp = tmpfile();\n#endif\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL);\n}\n\nLJLIB_CF(io_close)\n{\n  return lj_cf_io_method_close(L);\n}\n\nLJLIB_CF(io_read)\n{\n  return io_file_read(L, io_stdfile(L, GCROOT_IO_INPUT), 0);\n}\n\nLJLIB_CF(io_write)\t\tLJLIB_REC(io_write GCROOT_IO_OUTPUT)\n{\n  return io_file_write(L, io_stdfile(L, GCROOT_IO_OUTPUT), 0);\n}\n\nLJLIB_CF(io_flush)\t\tLJLIB_REC(io_flush GCROOT_IO_OUTPUT)\n{\n  return luaL_fileresult(L, fflush(io_stdfile(L, GCROOT_IO_OUTPUT)) == 0, NULL);\n}\n\nstatic int io_std_getset(lua_State *L, ptrdiff_t id, const char *mode)\n{\n  if (L->base < L->top && !tvisnil(L->base)) {\n    if (tvisudata(L->base)) {\n      io_tofile(L);\n      L->top = L->base+1;\n    } else {\n      io_file_open(L, mode);\n    }\n    /* NOBARRIER: The standard I/O handles are GC roots. */\n    setgcref(G(L)->gcroot[id], gcV(L->top-1));\n  } else {\n    setudataV(L, L->top++, IOSTDF_UD(L, id));\n  }\n  return 1;\n}\n\nLJLIB_CF(io_input)\n{\n  return io_std_getset(L, GCROOT_IO_INPUT, \"r\");\n}\n\nLJLIB_CF(io_output)\n{\n  return io_std_getset(L, GCROOT_IO_OUTPUT, \"w\");\n}\n\nLJLIB_CF(io_lines)\n{\n  if (L->base == L->top) setnilV(L->top++);\n  if (!tvisnil(L->base)) {  /* io.lines(fname) */\n    IOFileUD *iof = io_file_open(L, \"r\");\n    iof->type = IOFILE_TYPE_FILE|IOFILE_FLAG_CLOSE;\n    L->top--;\n    setudataV(L, L->base, udataV(L->top));\n  } else {  /* io.lines() iterates over stdin. */\n    setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT));\n  }\n  return io_file_lines(L);\n}\n\nLJLIB_CF(io_type)\n{\n  cTValue *o = lj_lib_checkany(L, 1);\n  if (!(tvisudata(o) && udataV(o)->udtype == UDTYPE_IO_FILE))\n    setnilV(L->top++);\n  else if (((IOFileUD *)uddata(udataV(o)))->fp != NULL)\n    lua_pushliteral(L, \"file\");\n  else\n    lua_pushliteral(L, \"closed file\");\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\n/* ------------------------------------------------------------------------ */\n\nstatic GCobj *io_std_new(lua_State *L, FILE *fp, const char *name)\n{\n  IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));\n  GCudata *ud = udataV(L->top-1);\n  ud->udtype = UDTYPE_IO_FILE;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcref(ud->metatable, gcV(L->top-3));\n  iof->fp = fp;\n  iof->type = IOFILE_TYPE_STDF;\n  lua_setfield(L, -2, name);\n  return obj2gco(ud);\n}\n\nLUALIB_API int luaopen_io(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, io_method);\n  copyTV(L, L->top, L->top-1); L->top++;\n  lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);\n  LJ_LIB_REG(L, LUA_IOLIBNAME, io);\n  setgcref(G(L)->gcroot[GCROOT_IO_INPUT], io_std_new(L, stdin, \"stdin\"));\n  setgcref(G(L)->gcroot[GCROOT_IO_OUTPUT], io_std_new(L, stdout, \"stdout\"));\n  io_std_new(L, stderr, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_jit.c",
    "content": "/*\n** JIT library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_jit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#if LJ_HASJIT\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_target.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n#include \"lj_lib.h\"\n\n#include \"luajit.h\"\n\n/* -- jit.* functions ----------------------------------------------------- */\n\n#define LJLIB_MODULE_jit\n\nstatic int setjitmode(lua_State *L, int mode)\n{\n  int idx = 0;\n  if (L->base == L->top || tvisnil(L->base)) {  /* jit.on/off/flush([nil]) */\n    mode |= LUAJIT_MODE_ENGINE;\n  } else {\n    /* jit.on/off/flush(func|proto, nil|true|false) */\n    if (tvisfunc(L->base) || tvisproto(L->base))\n      idx = 1;\n    else if (!tvistrue(L->base))  /* jit.on/off/flush(true, nil|true|false) */\n      goto err;\n    if (L->base+1 < L->top && tvisbool(L->base+1))\n      mode |= boolV(L->base+1) ? LUAJIT_MODE_ALLFUNC : LUAJIT_MODE_ALLSUBFUNC;\n    else\n      mode |= LUAJIT_MODE_FUNC;\n  }\n  if (luaJIT_setmode(L, idx, mode) != 1) {\n    if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE)\n      lj_err_caller(L, LJ_ERR_NOJIT);\n  err:\n    lj_err_argt(L, 1, LUA_TFUNCTION);\n  }\n  return 0;\n}\n\nLJLIB_CF(jit_on)\n{\n  return setjitmode(L, LUAJIT_MODE_ON);\n}\n\nLJLIB_CF(jit_off)\n{\n  return setjitmode(L, LUAJIT_MODE_OFF);\n}\n\nLJLIB_CF(jit_flush)\n{\n#if LJ_HASJIT\n  if (L->base < L->top && tvisnumber(L->base)) {\n    int traceno = lj_lib_checkint(L, 1);\n    luaJIT_setmode(L, traceno, LUAJIT_MODE_FLUSH|LUAJIT_MODE_TRACE);\n    return 0;\n  }\n#endif\n  return setjitmode(L, LUAJIT_MODE_FLUSH);\n}\n\n#if LJ_HASJIT\n/* Push a string for every flag bit that is set. */\nstatic void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base,\n\t\t\t\tconst char *str)\n{\n  for (; *str; base <<= 1, str += 1+*str)\n    if (flags & base)\n      setstrV(L, L->top++, lj_str_new(L, str+1, *(uint8_t *)str));\n}\n#endif\n\nLJLIB_CF(jit_status)\n{\n#if LJ_HASJIT\n  jit_State *J = L2J(L);\n  L->top = L->base;\n  setboolV(L->top++, (J->flags & JIT_F_ON) ? 1 : 0);\n  flagbits_to_strings(L, J->flags, JIT_F_CPU_FIRST, JIT_F_CPUSTRING);\n  flagbits_to_strings(L, J->flags, JIT_F_OPT_FIRST, JIT_F_OPTSTRING);\n  return (int)(L->top - L->base);\n#else\n  setboolV(L->top++, 0);\n  return 1;\n#endif\n}\n\nLJLIB_CF(jit_attach)\n{\n#ifdef LUAJIT_DISABLE_VMEVENT\n  luaL_error(L, \"vmevent API disabled\");\n#else\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  GCstr *s = lj_lib_optstr(L, 2);\n  luaL_findtable(L, LUA_REGISTRYINDEX, LJ_VMEVENTS_REGKEY, LJ_VMEVENTS_HSIZE);\n  if (s) {  /* Attach to given event. */\n    const uint8_t *p = (const uint8_t *)strdata(s);\n    uint32_t h = s->len;\n    while (*p) h = h ^ (lj_rol(h, 6) + *p++);\n    lua_pushvalue(L, 1);\n    lua_rawseti(L, -2, VMEVENT_HASHIDX(h));\n    G(L)->vmevmask = VMEVENT_NOCACHE;  /* Invalidate cache. */\n  } else {  /* Detach if no event given. */\n    setnilV(L->top++);\n    while (lua_next(L, -2)) {\n      L->top--;\n      if (tvisfunc(L->top) && funcV(L->top) == fn) {\n\tsetnilV(lj_tab_set(L, tabV(L->top-2), L->top-1));\n      }\n    }\n  }\n#endif\n  return 0;\n}\n\nLJLIB_PUSH(top-5) LJLIB_SET(os)\nLJLIB_PUSH(top-4) LJLIB_SET(arch)\nLJLIB_PUSH(top-3) LJLIB_SET(version_num)\nLJLIB_PUSH(top-2) LJLIB_SET(version)\n\n#include \"lj_libdef.h\"\n\n/* -- jit.util.* functions ------------------------------------------------ */\n\n#define LJLIB_MODULE_jit_util\n\n/* -- Reflection API for Lua functions ------------------------------------ */\n\n/* Return prototype of first argument (Lua function or prototype object) */\nstatic GCproto *check_Lproto(lua_State *L, int nolua)\n{\n  TValue *o = L->base;\n  if (L->top > o) {\n    if (tvisproto(o)) {\n      return protoV(o);\n    } else if (tvisfunc(o)) {\n      if (isluafunc(funcV(o)))\n\treturn funcproto(funcV(o));\n      else if (nolua)\n\treturn NULL;\n    }\n  }\n  lj_err_argt(L, 1, LUA_TFUNCTION);\n  return NULL;  /* unreachable */\n}\n\nstatic void setintfield(lua_State *L, GCtab *t, const char *name, int32_t val)\n{\n  setintV(lj_tab_setstr(L, t, lj_str_newz(L, name)), val);\n}\n\n/* local info = jit.util.funcinfo(func [,pc]) */\nLJLIB_CF(jit_util_funcinfo)\n{\n  GCproto *pt = check_Lproto(L, 1);\n  if (pt) {\n    BCPos pc = (BCPos)lj_lib_optint(L, 2, 0);\n    GCtab *t;\n    lua_createtable(L, 0, 16);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintfield(L, t, \"linedefined\", pt->firstline);\n    setintfield(L, t, \"lastlinedefined\", pt->firstline + pt->numline);\n    setintfield(L, t, \"stackslots\", pt->framesize);\n    setintfield(L, t, \"params\", pt->numparams);\n    setintfield(L, t, \"bytecodes\", (int32_t)pt->sizebc);\n    setintfield(L, t, \"gcconsts\", (int32_t)pt->sizekgc);\n    setintfield(L, t, \"nconsts\", (int32_t)pt->sizekn);\n    setintfield(L, t, \"upvalues\", (int32_t)pt->sizeuv);\n    if (pc < pt->sizebc)\n      setintfield(L, t, \"currentline\", lj_debug_line(pt, pc));\n    lua_pushboolean(L, (pt->flags & PROTO_VARARG));\n    lua_setfield(L, -2, \"isvararg\");\n    lua_pushboolean(L, (pt->flags & PROTO_CHILD));\n    lua_setfield(L, -2, \"children\");\n    setstrV(L, L->top++, proto_chunkname(pt));\n    lua_setfield(L, -2, \"source\");\n    lj_debug_pushloc(L, pt, pc);\n    lua_setfield(L, -2, \"loc\");\n  } else {\n    GCfunc *fn = funcV(L->base);\n    GCtab *t;\n    lua_createtable(L, 0, 4);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    if (!iscfunc(fn))\n      setintfield(L, t, \"ffid\", fn->c.ffid);\n    setintptrV(lj_tab_setstr(L, t, lj_str_newlit(L, \"addr\")),\n\t       (intptr_t)(void *)fn->c.f);\n    setintfield(L, t, \"upvalues\", fn->c.nupvalues);\n  }\n  return 1;\n}\n\n/* local ins, m = jit.util.funcbc(func, pc) */\nLJLIB_CF(jit_util_funcbc)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  BCPos pc = (BCPos)lj_lib_checkint(L, 2);\n  if (pc < pt->sizebc) {\n    BCIns ins = proto_bc(pt)[pc];\n    BCOp op = bc_op(ins);\n    lua_assert(op < BC__MAX);\n    setintV(L->top, ins);\n    setintV(L->top+1, lj_bc_mode[op]);\n    L->top += 2;\n    return 2;\n  }\n  return 0;\n}\n\n/* local k = jit.util.funck(func, idx) */\nLJLIB_CF(jit_util_funck)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2);\n  if (idx >= 0) {\n    if (idx < (ptrdiff_t)pt->sizekn) {\n      copyTV(L, L->top-1, proto_knumtv(pt, idx));\n      return 1;\n    }\n  } else {\n    if (~idx < (ptrdiff_t)pt->sizekgc) {\n      GCobj *gc = proto_kgc(pt, idx);\n      setgcV(L, L->top-1, gc, ~gc->gch.gct);\n      return 1;\n    }\n  }\n  return 0;\n}\n\n/* local name = jit.util.funcuvname(func, idx) */\nLJLIB_CF(jit_util_funcuvname)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  uint32_t idx = (uint32_t)lj_lib_checkint(L, 2);\n  if (idx < pt->sizeuv) {\n    setstrV(L, L->top-1, lj_str_newz(L, lj_debug_uvname(pt, idx)));\n    return 1;\n  }\n  return 0;\n}\n\n/* -- Reflection API for traces ------------------------------------------- */\n\n#if LJ_HASJIT\n\n/* Check trace argument. Must not throw for non-existent trace numbers. */\nstatic GCtrace *jit_checktrace(lua_State *L)\n{\n  TraceNo tr = (TraceNo)lj_lib_checkint(L, 1);\n  jit_State *J = L2J(L);\n  if (tr > 0 && tr < J->sizetrace)\n    return traceref(J, tr);\n  return NULL;\n}\n\n/* Names of link types. ORDER LJ_TRLINK */\nstatic const char *const jit_trlinkname[] = {\n  \"none\", \"root\", \"loop\", \"tail-recursion\", \"up-recursion\", \"down-recursion\",\n  \"interpreter\", \"return\", \"stitch\"\n};\n\n/* local info = jit.util.traceinfo(tr) */\nLJLIB_CF(jit_util_traceinfo)\n{\n  GCtrace *T = jit_checktrace(L);\n  if (T) {\n    GCtab *t;\n    lua_createtable(L, 0, 8);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintfield(L, t, \"nins\", (int32_t)T->nins - REF_BIAS - 1);\n    setintfield(L, t, \"nk\", REF_BIAS - (int32_t)T->nk);\n    setintfield(L, t, \"link\", T->link);\n    setintfield(L, t, \"nexit\", T->nsnap);\n    setstrV(L, L->top++, lj_str_newz(L, jit_trlinkname[T->linktype]));\n    lua_setfield(L, -2, \"linktype\");\n    /* There are many more fields. Add them only when needed. */\n    return 1;\n  }\n  return 0;\n}\n\n/* local m, ot, op1, op2, prev = jit.util.traceir(tr, idx) */\nLJLIB_CF(jit_util_traceir)\n{\n  GCtrace *T = jit_checktrace(L);\n  IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;\n  if (T && ref >= REF_BIAS && ref < T->nins) {\n    IRIns *ir = &T->ir[ref];\n    int32_t m = lj_ir_mode[ir->o];\n    setintV(L->top-2, m);\n    setintV(L->top-1, ir->ot);\n    setintV(L->top++, (int32_t)ir->op1 - (irm_op1(m)==IRMref ? REF_BIAS : 0));\n    setintV(L->top++, (int32_t)ir->op2 - (irm_op2(m)==IRMref ? REF_BIAS : 0));\n    setintV(L->top++, ir->prev);\n    return 5;\n  }\n  return 0;\n}\n\n/* local k, t [, slot] = jit.util.tracek(tr, idx) */\nLJLIB_CF(jit_util_tracek)\n{\n  GCtrace *T = jit_checktrace(L);\n  IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;\n  if (T && ref >= T->nk && ref < REF_BIAS) {\n    IRIns *ir = &T->ir[ref];\n    int32_t slot = -1;\n    if (ir->o == IR_KSLOT) {\n      slot = ir->op2;\n      ir = &T->ir[ir->op1];\n    }\n#if LJ_HASFFI\n    if (ir->o == IR_KINT64 && !ctype_ctsG(G(L))) {\n      ptrdiff_t oldtop = savestack(L, L->top);\n      luaopen_ffi(L);  /* Load FFI library on-demand. */\n      L->top = restorestack(L, oldtop);\n    }\n#endif\n    lj_ir_kvalue(L, L->top-2, ir);\n    setintV(L->top-1, (int32_t)irt_type(ir->t));\n    if (slot == -1)\n      return 2;\n    setintV(L->top++, slot);\n    return 3;\n  }\n  return 0;\n}\n\n/* local snap = jit.util.tracesnap(tr, sn) */\nLJLIB_CF(jit_util_tracesnap)\n{\n  GCtrace *T = jit_checktrace(L);\n  SnapNo sn = (SnapNo)lj_lib_checkint(L, 2);\n  if (T && sn < T->nsnap) {\n    SnapShot *snap = &T->snap[sn];\n    SnapEntry *map = &T->snapmap[snap->mapofs];\n    MSize n, nent = snap->nent;\n    GCtab *t;\n    lua_createtable(L, nent+2, 0);\n    t = tabV(L->top-1);\n    setintV(lj_tab_setint(L, t, 0), (int32_t)snap->ref - REF_BIAS);\n    setintV(lj_tab_setint(L, t, 1), (int32_t)snap->nslots);\n    for (n = 0; n < nent; n++)\n      setintV(lj_tab_setint(L, t, (int32_t)(n+2)), (int32_t)map[n]);\n    setintV(lj_tab_setint(L, t, (int32_t)(nent+2)), (int32_t)SNAP(255, 0, 0));\n    return 1;\n  }\n  return 0;\n}\n\n/* local mcode, addr, loop = jit.util.tracemc(tr) */\nLJLIB_CF(jit_util_tracemc)\n{\n  GCtrace *T = jit_checktrace(L);\n  if (T && T->mcode != NULL) {\n    setstrV(L, L->top-1, lj_str_new(L, (const char *)T->mcode, T->szmcode));\n    setintptrV(L->top++, (intptr_t)(void *)T->mcode);\n    setintV(L->top++, T->mcloop);\n    return 3;\n  }\n  return 0;\n}\n\n/* local addr = jit.util.traceexitstub([tr,] exitno) */\nLJLIB_CF(jit_util_traceexitstub)\n{\n#ifdef EXITSTUBS_PER_GROUP\n  ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1);\n  jit_State *J = L2J(L);\n  if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) {\n    setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno));\n    return 1;\n  }\n#else\n  if (L->top > L->base+1) {  /* Don't throw for one-argument variant. */\n    GCtrace *T = jit_checktrace(L);\n    ExitNo exitno = (ExitNo)lj_lib_checkint(L, 2);\n    ExitNo maxexit = T->root ? T->nsnap+1 : T->nsnap;\n    if (T && T->mcode != NULL && exitno < maxexit) {\n      setintptrV(L->top-1, (intptr_t)(void *)exitstub_trace_addr(T, exitno));\n      return 1;\n    }\n  }\n#endif\n  return 0;\n}\n\n/* local addr = jit.util.ircalladdr(idx) */\nLJLIB_CF(jit_util_ircalladdr)\n{\n  uint32_t idx = (uint32_t)lj_lib_checkint(L, 1);\n  if (idx < IRCALL__MAX) {\n    setintptrV(L->top-1, (intptr_t)(void *)lj_ir_callinfo[idx].func);\n    return 1;\n  }\n  return 0;\n}\n\n#endif\n\n#include \"lj_libdef.h\"\n\nstatic int luaopen_jit_util(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, jit_util);\n  return 1;\n}\n\n/* -- jit.opt module ------------------------------------------------------ */\n\n#if LJ_HASJIT\n\n#define LJLIB_MODULE_jit_opt\n\n/* Parse optimization level. */\nstatic int jitopt_level(jit_State *J, const char *str)\n{\n  if (str[0] >= '0' && str[0] <= '9' && str[1] == '\\0') {\n    uint32_t flags;\n    if (str[0] == '0') flags = JIT_F_OPT_0;\n    else if (str[0] == '1') flags = JIT_F_OPT_1;\n    else if (str[0] == '2') flags = JIT_F_OPT_2;\n    else flags = JIT_F_OPT_3;\n    J->flags = (J->flags & ~JIT_F_OPT_MASK) | flags;\n    return 1;  /* Ok. */\n  }\n  return 0;  /* No match. */\n}\n\n/* Parse optimization flag. */\nstatic int jitopt_flag(jit_State *J, const char *str)\n{\n  const char *lst = JIT_F_OPTSTRING;\n  uint32_t opt;\n  int set = 1;\n  if (str[0] == '+') {\n    str++;\n  } else if (str[0] == '-') {\n    str++;\n    set = 0;\n  } else if (str[0] == 'n' && str[1] == 'o') {\n    str += str[2] == '-' ? 3 : 2;\n    set = 0;\n  }\n  for (opt = JIT_F_OPT_FIRST; ; opt <<= 1) {\n    size_t len = *(const uint8_t *)lst;\n    if (len == 0)\n      break;\n    if (strncmp(str, lst+1, len) == 0 && str[len] == '\\0') {\n      if (set) J->flags |= opt; else J->flags &= ~opt;\n      return 1;  /* Ok. */\n    }\n    lst += 1+len;\n  }\n  return 0;  /* No match. */\n}\n\n/* Parse optimization parameter. */\nstatic int jitopt_param(jit_State *J, const char *str)\n{\n  const char *lst = JIT_P_STRING;\n  int i;\n  for (i = 0; i < JIT_P__MAX; i++) {\n    size_t len = *(const uint8_t *)lst;\n    lua_assert(len != 0);\n    if (strncmp(str, lst+1, len) == 0 && str[len] == '=') {\n      int32_t n = 0;\n      const char *p = &str[len+1];\n      while (*p >= '0' && *p <= '9')\n\tn = n*10 + (*p++ - '0');\n      if (*p) return 0;  /* Malformed number. */\n      J->param[i] = n;\n      if (i == JIT_P_hotloop)\n\tlj_dispatch_init_hotcount(J2G(J));\n      return 1;  /* Ok. */\n    }\n    lst += 1+len;\n  }\n  return 0;  /* No match. */\n}\n\n/* jit.opt.start(flags...) */\nLJLIB_CF(jit_opt_start)\n{\n  jit_State *J = L2J(L);\n  int nargs = (int)(L->top - L->base);\n  if (nargs == 0) {\n    J->flags = (J->flags & ~JIT_F_OPT_MASK) | JIT_F_OPT_DEFAULT;\n  } else {\n    int i;\n    for (i = 1; i <= nargs; i++) {\n      const char *str = strdata(lj_lib_checkstr(L, i));\n      if (!jitopt_level(J, str) &&\n\t  !jitopt_flag(J, str) &&\n\t  !jitopt_param(J, str))\n\tlj_err_callerv(L, LJ_ERR_JITOPT, str);\n    }\n  }\n  return 0;\n}\n\n#include \"lj_libdef.h\"\n\n#endif\n\n/* -- jit.profile module -------------------------------------------------- */\n\n#if LJ_HASPROFILE\n\n#define LJLIB_MODULE_jit_profile\n\n/* Not loaded by default, use: local profile = require(\"jit.profile\") */\n\nstatic const char KEY_PROFILE_THREAD = 't';\nstatic const char KEY_PROFILE_FUNC = 'f';\n\nstatic void jit_profile_callback(lua_State *L2, lua_State *L, int samples,\n\t\t\t\t int vmstate)\n{\n  TValue key;\n  cTValue *tv;\n  setlightudV(&key, (void *)&KEY_PROFILE_FUNC);\n  tv = lj_tab_get(L, tabV(registry(L)), &key);\n  if (tvisfunc(tv)) {\n    char vmst = (char)vmstate;\n    int status;\n    setfuncV(L2, L2->top++, funcV(tv));\n    setthreadV(L2, L2->top++, L);\n    setintV(L2->top++, samples);\n    setstrV(L2, L2->top++, lj_str_new(L2, &vmst, 1));\n    status = lua_pcall(L2, 3, 0, 0);  /* callback(thread, samples, vmstate) */\n    if (status) {\n      if (G(L2)->panic) G(L2)->panic(L2);\n      exit(EXIT_FAILURE);\n    }\n    lj_trace_abort(G(L2));\n  }\n}\n\n/* profile.start(mode, cb) */\nLJLIB_CF(jit_profile_start)\n{\n  GCtab *registry = tabV(registry(L));\n  GCstr *mode = lj_lib_optstr(L, 1);\n  GCfunc *func = lj_lib_checkfunc(L, 2);\n  lua_State *L2 = lua_newthread(L);  /* Thread that runs profiler callback. */\n  TValue key;\n  /* Anchor thread and function in registry. */\n  setlightudV(&key, (void *)&KEY_PROFILE_THREAD);\n  setthreadV(L, lj_tab_set(L, registry, &key), L2);\n  setlightudV(&key, (void *)&KEY_PROFILE_FUNC);\n  setfuncV(L, lj_tab_set(L, registry, &key), func);\n  lj_gc_anybarriert(L, registry);\n  luaJIT_profile_start(L, mode ? strdata(mode) : \"\",\n\t\t       (luaJIT_profile_callback)jit_profile_callback, L2);\n  return 0;\n}\n\n/* profile.stop() */\nLJLIB_CF(jit_profile_stop)\n{\n  GCtab *registry;\n  TValue key;\n  luaJIT_profile_stop(L);\n  registry = tabV(registry(L));\n  setlightudV(&key, (void *)&KEY_PROFILE_THREAD);\n  setnilV(lj_tab_set(L, registry, &key));\n  setlightudV(&key, (void *)&KEY_PROFILE_FUNC);\n  setnilV(lj_tab_set(L, registry, &key));\n  lj_gc_anybarriert(L, registry);\n  return 0;\n}\n\n/* dump = profile.dumpstack([thread,] fmt, depth) */\nLJLIB_CF(jit_profile_dumpstack)\n{\n  lua_State *L2 = L;\n  int arg = 0;\n  size_t len;\n  int depth;\n  GCstr *fmt;\n  const char *p;\n  if (L->top > L->base && tvisthread(L->base)) {\n    L2 = threadV(L->base);\n    arg = 1;\n  }\n  fmt = lj_lib_checkstr(L, arg+1);\n  depth = lj_lib_checkint(L, arg+2);\n  p = luaJIT_profile_dumpstack(L2, strdata(fmt), depth, &len);\n  lua_pushlstring(L, p, len);\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\nstatic int luaopen_jit_profile(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, jit_profile);\n  return 1;\n}\n\n#endif\n\n/* -- JIT compiler initialization ----------------------------------------- */\n\n#if LJ_HASJIT\n/* Default values for JIT parameters. */\nstatic const int32_t jit_param_default[JIT_P__MAX+1] = {\n#define JIT_PARAMINIT(len, name, value)\t(value),\nJIT_PARAMDEF(JIT_PARAMINIT)\n#undef JIT_PARAMINIT\n  0\n};\n#endif\n\n#if LJ_TARGET_ARM && LJ_TARGET_LINUX\n#include <sys/utsname.h>\n#endif\n\n/* Arch-dependent CPU detection. */\nstatic uint32_t jit_cpudetect(lua_State *L)\n{\n  uint32_t flags = 0;\n#if LJ_TARGET_X86ORX64\n  uint32_t vendor[4];\n  uint32_t features[4];\n  if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) {\n#if !LJ_HASJIT\n#define JIT_F_SSE2\t2\n#endif\n    flags |= ((features[3] >> 26)&1) * JIT_F_SSE2;\n#if LJ_HASJIT\n    flags |= ((features[2] >> 0)&1) * JIT_F_SSE3;\n    flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1;\n    if (vendor[2] == 0x6c65746e) {  /* Intel. */\n      if ((features[0] & 0x0fff0ff0) == 0x000106c0)  /* Atom. */\n\tflags |= JIT_F_LEA_AGU;\n    } else if (vendor[2] == 0x444d4163) {  /* AMD. */\n      uint32_t fam = (features[0] & 0x0ff00f00);\n      if (fam >= 0x00000f00)  /* K8, K10. */\n\tflags |= JIT_F_PREFER_IMUL;\n    }\n#endif\n  }\n  /* Check for required instruction set support on x86 (unnecessary on x64). */\n#if LJ_TARGET_X86\n  if (!(flags & JIT_F_SSE2))\n    luaL_error(L, \"CPU with SSE2 required\");\n#endif\n#elif LJ_TARGET_ARM\n#if LJ_HASJIT\n  int ver = LJ_ARCH_VERSION;  /* Compile-time ARM CPU detection. */\n#if LJ_TARGET_LINUX\n  if (ver < 70) {  /* Runtime ARM CPU detection. */\n    struct utsname ut;\n    uname(&ut);\n    if (strncmp(ut.machine, \"armv\", 4) == 0) {\n      if (ut.machine[4] >= '7')\n\tver = 70;\n      else if (ut.machine[4] == '6')\n\tver = 60;\n    }\n  }\n#endif\n  flags |= ver >= 70 ? JIT_F_ARMV7 :\n\t   ver >= 61 ? JIT_F_ARMV6T2_ :\n\t   ver >= 60 ? JIT_F_ARMV6_ : 0;\n  flags |= LJ_ARCH_HASFPU == 0 ? 0 : ver >= 70 ? JIT_F_VFPV3 : JIT_F_VFPV2;\n#endif\n#elif LJ_TARGET_ARM64\n  /* No optional CPU features to detect (for now). */\n#elif LJ_TARGET_PPC\n#if LJ_HASJIT\n#if LJ_ARCH_SQRT\n  flags |= JIT_F_SQRT;\n#endif\n#if LJ_ARCH_ROUND\n  flags |= JIT_F_ROUND;\n#endif\n#endif\n#elif LJ_TARGET_MIPS\n#if LJ_HASJIT\n  /* Compile-time MIPS CPU detection. */\n#if LJ_ARCH_VERSION >= 20\n  flags |= JIT_F_MIPS32R2;\n#endif\n  /* Runtime MIPS CPU detection. */\n#if defined(__GNUC__)\n  if (!(flags & JIT_F_MIPS32R2)) {\n    int x;\n    /* On MIPS32R1 rotr is treated as srl. rotr r2,r2,1 -> srl r2,r2,1. */\n    __asm__(\"li $2, 1\\n\\t.long 0x00221042\\n\\tmove %0, $2\" : \"=r\"(x) : : \"$2\");\n    if (x) flags |= JIT_F_MIPS32R2;  /* Either 0x80000000 (R2) or 0 (R1). */\n  }\n#endif\n#endif\n#else\n#error \"Missing CPU detection for this architecture\"\n#endif\n  UNUSED(L);\n  return flags;\n}\n\n/* Initialize JIT compiler. */\nstatic void jit_init(lua_State *L)\n{\n  uint32_t flags = jit_cpudetect(L);\n#if LJ_HASJIT\n  jit_State *J = L2J(L);\n  J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT;\n  memcpy(J->param, jit_param_default, sizeof(J->param));\n  lj_dispatch_update(G(L));\n#else\n  UNUSED(flags);\n#endif\n}\n\nLUALIB_API int luaopen_jit(lua_State *L)\n{\n  jit_init(L);\n  lua_pushliteral(L, LJ_OS_NAME);\n  lua_pushliteral(L, LJ_ARCH_NAME);\n  lua_pushinteger(L, LUAJIT_VERSION_NUM);\n  lua_pushliteral(L, LUAJIT_VERSION);\n  LJ_LIB_REG(L, LUA_JITLIBNAME, jit);\n#if LJ_HASPROFILE\n  lj_lib_prereg(L, LUA_JITLIBNAME \".profile\", luaopen_jit_profile,\n\t\ttabref(L->env));\n#endif\n#ifndef LUAJIT_DISABLE_JITUTIL\n  lj_lib_prereg(L, LUA_JITLIBNAME \".util\", luaopen_jit_util, tabref(L->env));\n#endif\n#if LJ_HASJIT\n  LJ_LIB_REG(L, \"jit.opt\", jit_opt);\n#endif\n  L->top -= 2;\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_math.c",
    "content": "/*\n** Math library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <math.h>\n\n#define lib_math_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_lib.h\"\n#include \"lj_vm.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_math\n\nLJLIB_ASM(math_abs)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_floor)\t\tLJLIB_REC(math_round IRFPM_FLOOR)\nLJLIB_ASM_(math_ceil)\t\tLJLIB_REC(math_round IRFPM_CEIL)\n\nLJLIB_ASM(math_sqrt)\t\tLJLIB_REC(math_unary IRFPM_SQRT)\n{\n  lj_lib_checknum(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_log10)\t\tLJLIB_REC(math_unary IRFPM_LOG10)\nLJLIB_ASM_(math_exp)\t\tLJLIB_REC(math_unary IRFPM_EXP)\nLJLIB_ASM_(math_sin)\t\tLJLIB_REC(math_unary IRFPM_SIN)\nLJLIB_ASM_(math_cos)\t\tLJLIB_REC(math_unary IRFPM_COS)\nLJLIB_ASM_(math_tan)\t\tLJLIB_REC(math_unary IRFPM_TAN)\nLJLIB_ASM_(math_asin)\t\tLJLIB_REC(math_atrig FF_math_asin)\nLJLIB_ASM_(math_acos)\t\tLJLIB_REC(math_atrig FF_math_acos)\nLJLIB_ASM_(math_atan)\t\tLJLIB_REC(math_atrig FF_math_atan)\nLJLIB_ASM_(math_sinh)\t\tLJLIB_REC(math_htrig IRCALL_sinh)\nLJLIB_ASM_(math_cosh)\t\tLJLIB_REC(math_htrig IRCALL_cosh)\nLJLIB_ASM_(math_tanh)\t\tLJLIB_REC(math_htrig IRCALL_tanh)\nLJLIB_ASM_(math_frexp)\nLJLIB_ASM_(math_modf)\t\tLJLIB_REC(.)\n\nLJLIB_ASM(math_log)\t\tLJLIB_REC(math_log)\n{\n  double x = lj_lib_checknum(L, 1);\n  if (L->base+1 < L->top) {\n    double y = lj_lib_checknum(L, 2);\n#ifdef LUAJIT_NO_LOG2\n    x = log(x); y = 1.0 / log(y);\n#else\n    x = lj_vm_log2(x); y = 1.0 / lj_vm_log2(y);\n#endif\n    setnumV(L->base-1-LJ_FR2, x*y);  /* Do NOT join the expression to x / y. */\n    return FFH_RES(1);\n  }\n  return FFH_RETRY;\n}\n\nLJLIB_LUA(math_deg) /* function(x) return x * 57.29577951308232 end */\nLJLIB_LUA(math_rad) /* function(x) return x * 0.017453292519943295 end */\n\nLJLIB_ASM(math_atan2)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknum(L, 1);\n  lj_lib_checknum(L, 2);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_pow)\t\tLJLIB_REC(.)\nLJLIB_ASM_(math_fmod)\n\nLJLIB_ASM(math_ldexp)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknum(L, 1);\n#if LJ_DUALNUM && !LJ_TARGET_X86ORX64\n  lj_lib_checkint(L, 2);\n#else\n  lj_lib_checknum(L, 2);\n#endif\n  return FFH_RETRY;\n}\n\nLJLIB_ASM(math_min)\t\tLJLIB_REC(math_minmax IR_MIN)\n{\n  int i = 0;\n  do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_max)\t\tLJLIB_REC(math_minmax IR_MAX)\n\nLJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi)\nLJLIB_PUSH(1e310) LJLIB_SET(huge)\n\n/* ------------------------------------------------------------------------ */\n\n/* This implements a Tausworthe PRNG with period 2^223. Based on:\n**   Tables of maximally-equidistributed combined LFSR generators,\n**   Pierre L'Ecuyer, 1991, table 3, 1st entry.\n** Full-period ME-CF generator with L=64, J=4, k=223, N1=49.\n*/\n\n/* PRNG state. */\nstruct RandomState {\n  uint64_t gen[4];\t/* State of the 4 LFSR generators. */\n  int valid;\t\t/* State is valid. */\n};\n\n/* Union needed for bit-pattern conversion between uint64_t and double. */\ntypedef union { uint64_t u64; double d; } U64double;\n\n/* Update generator i and compute a running xor of all states. */\n#define TW223_GEN(i, k, q, s) \\\n  z = rs->gen[i]; \\\n  z = (((z<<q)^z) >> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<<s); \\\n  r ^= z; rs->gen[i] = z;\n\n/* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */\nLJ_NOINLINE uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs)\n{\n  uint64_t z, r = 0;\n  TW223_GEN(0, 63, 31, 18)\n  TW223_GEN(1, 58, 19, 28)\n  TW223_GEN(2, 55, 24,  7)\n  TW223_GEN(3, 47, 21,  8)\n  return (r & U64x(000fffff,ffffffff)) | U64x(3ff00000,00000000);\n}\n\n/* PRNG initialization function. */\nstatic void random_init(RandomState *rs, double d)\n{\n  uint32_t r = 0x11090601;  /* 64-k[i] as four 8 bit constants. */\n  int i;\n  for (i = 0; i < 4; i++) {\n    U64double u;\n    uint32_t m = 1u << (r&255);\n    r >>= 8;\n    u.d = d = d * 3.14159265358979323846 + 2.7182818284590452354;\n    if (u.u64 < m) u.u64 += m;  /* Ensure k[i] MSB of gen[i] are non-zero. */\n    rs->gen[i] = u.u64;\n  }\n  rs->valid = 1;\n  for (i = 0; i < 10; i++)\n    lj_math_random_step(rs);\n}\n\n/* PRNG extract function. */\nLJLIB_PUSH(top-2)  /* Upvalue holds userdata with RandomState. */\nLJLIB_CF(math_random)\t\tLJLIB_REC(.)\n{\n  int n = (int)(L->top - L->base);\n  RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1))));\n  U64double u;\n  double d;\n  if (LJ_UNLIKELY(!rs->valid)) random_init(rs, 0.0);\n  u.u64 = lj_math_random_step(rs);\n  d = u.d - 1.0;\n  if (n > 0) {\n#if LJ_DUALNUM\n    int isint = 1;\n    double r1;\n    lj_lib_checknumber(L, 1);\n    if (tvisint(L->base)) {\n      r1 = (lua_Number)intV(L->base);\n    } else {\n      isint = 0;\n      r1 = numV(L->base);\n    }\n#else\n    double r1 = lj_lib_checknum(L, 1);\n#endif\n    if (n == 1) {\n      d = lj_vm_floor(d*r1) + 1.0;  /* d is an int in range [1, r1] */\n    } else {\n#if LJ_DUALNUM\n      double r2;\n      lj_lib_checknumber(L, 2);\n      if (tvisint(L->base+1)) {\n\tr2 = (lua_Number)intV(L->base+1);\n      } else {\n\tisint = 0;\n\tr2 = numV(L->base+1);\n      }\n#else\n      double r2 = lj_lib_checknum(L, 2);\n#endif\n      d = lj_vm_floor(d*(r2-r1+1.0)) + r1;  /* d is an int in range [r1, r2] */\n    }\n#if LJ_DUALNUM\n    if (isint) {\n      setintV(L->top-1, lj_num2int(d));\n      return 1;\n    }\n#endif\n  }  /* else: d is a double in range [0, 1] */\n  setnumV(L->top++, d);\n  return 1;\n}\n\n/* PRNG seed function. */\nLJLIB_PUSH(top-2)  /* Upvalue holds userdata with RandomState. */\nLJLIB_CF(math_randomseed)\n{\n  RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1))));\n  random_init(rs, lj_lib_checknum(L, 1));\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_math(lua_State *L)\n{\n  RandomState *rs;\n  rs = (RandomState *)lua_newuserdata(L, sizeof(RandomState));\n  rs->valid = 0;  /* Use lazy initialization to save some time on startup. */\n  LJ_LIB_REG(L, LUA_MATHLIBNAME, math);\n#if defined(LUA_COMPAT_MOD) && !LJ_52\n  lua_getfield(L, -1, \"fmod\");\n  lua_setfield(L, -2, \"mod\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_os.c",
    "content": "/*\n** OS library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <time.h>\n\n#define lib_os_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_lib.h\"\n\n#if LJ_TARGET_POSIX\n#include <unistd.h>\n#else\n#include <stdio.h>\n#endif\n\n#if !LJ_TARGET_PSVITA\n#include <locale.h>\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_os\n\nLJLIB_CF(os_execute)\n{\n//#if LJ_NO_SYSTEM\n#if LJ_52\n  errno = ENOSYS;\n  return luaL_fileresult(L, 0, NULL);\n#else\n  lua_pushinteger(L, -1);\n  return 1;\n#endif\n//#else\n//  const char *cmd = luaL_optstring(L, 1, NULL);\n//  int stat = system(cmd);\n//#if LJ_52\n//  if (cmd)\n//    return luaL_execresult(L, stat);\n//  setboolV(L->top++, 1);\n//#else\n//  setintV(L->top++, stat);\n//#endif\n//  return 1;\n//#endif\n}\n\nLJLIB_CF(os_remove)\n{\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\nLJLIB_CF(os_rename)\n{\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);\n}\n\nLJLIB_CF(os_tmpname)\n{\n#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n  lj_err_caller(L, LJ_ERR_OSUNIQF);\n  return 0;\n#else\n#if LJ_TARGET_POSIX\n  char buf[15+1];\n  int fp;\n  strcpy(buf, \"/tmp/lua_XXXXXX\");\n  fp = mkstemp(buf);\n  if (fp != -1)\n    close(fp);\n  else\n    lj_err_caller(L, LJ_ERR_OSUNIQF);\n#else\n  char buf[L_tmpnam];\n  if (tmpnam(buf) == NULL)\n    lj_err_caller(L, LJ_ERR_OSUNIQF);\n#endif\n  lua_pushstring(L, buf);\n  return 1;\n#endif\n}\n\nLJLIB_CF(os_getenv)\n{\n#if LJ_TARGET_CONSOLE\n  lua_pushnil(L);\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n#endif\n  return 1;\n}\n\nLJLIB_CF(os_exit)\n{\n  int status;\n  if (L->base < L->top && tvisbool(L->base))\n    status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE;\n  else\n    status = lj_lib_optint(L, 1, EXIT_SUCCESS);\n  if (L->base+1 < L->top && tvistruecond(L->base+1))\n    lua_close(L);\n  exit(status);\n  return 0;  /* Unreachable. */\n}\n\nLJLIB_CF(os_clock)\n{\n  setnumV(L->top++, ((lua_Number)clock())*(1.0/(lua_Number)CLOCKS_PER_SEC));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void setfield(lua_State *L, const char *key, int value)\n{\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield(lua_State *L, const char *key, int value)\n{\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic int getboolfield(lua_State *L, const char *key)\n{\n  int res;\n  lua_getfield(L, -1, key);\n  res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\nstatic int getfield(lua_State *L, const char *key, int d)\n{\n  int res;\n  lua_getfield(L, -1, key);\n  if (lua_isnumber(L, -1)) {\n    res = (int)lua_tointeger(L, -1);\n  } else {\n    if (d < 0)\n      lj_err_callerv(L, LJ_ERR_OSDATEF, key);\n    res = d;\n  }\n  lua_pop(L, 1);\n  return res;\n}\n\nLJLIB_CF(os_date)\n{\n  const char *s = luaL_optstring(L, 1, \"%c\");\n  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));\n  struct tm *stm;\n#if LJ_TARGET_POSIX\n  struct tm rtm;\n#endif\n  if (*s == '!') {  /* UTC? */\n    s++;  /* Skip '!' */\n#if LJ_TARGET_POSIX\n    stm = gmtime_r(&t, &rtm);\n#else\n    stm = gmtime(&t);\n#endif\n  } else {\n#if LJ_TARGET_POSIX\n    stm = localtime_r(&t, &rtm);\n#else\n    stm = localtime(&t);\n#endif\n  }\n  if (stm == NULL) {  /* Invalid date? */\n    setnilV(L->top++);\n  } else if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setfield(L, \"sec\", stm->tm_sec);\n    setfield(L, \"min\", stm->tm_min);\n    setfield(L, \"hour\", stm->tm_hour);\n    setfield(L, \"day\", stm->tm_mday);\n    setfield(L, \"month\", stm->tm_mon+1);\n    setfield(L, \"year\", stm->tm_year+1900);\n    setfield(L, \"wday\", stm->tm_wday+1);\n    setfield(L, \"yday\", stm->tm_yday+1);\n    setboolfield(L, \"isdst\", stm->tm_isdst);\n  } else if (*s) {\n    SBuf *sb = &G(L)->tmpbuf;\n    MSize sz = 0;\n    const char *q;\n    for (q = s; *q; q++)\n      sz += (*q == '%') ? 30 : 1;  /* Overflow doesn't matter. */\n    setsbufL(sb, L);\n    for (;;) {\n      char *buf = lj_buf_need(sb, sz);\n      size_t len = strftime(buf, sbufsz(sb), s, stm);\n      if (len) {\n\tsetstrV(L, L->top++, lj_str_new(L, buf, len));\n\tlj_gc_check(L);\n\tbreak;\n      }\n      sz += (sz|1);\n    }\n  } else {\n    setstrV(L, L->top++, &G(L)->strempty);\n  }\n  return 1;\n}\n\nLJLIB_CF(os_time)\n{\n  time_t t;\n  if (lua_isnoneornil(L, 1)) {  /* called without args? */\n    t = time(NULL);  /* get current time */\n  } else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0);\n    ts.tm_min = getfield(L, \"min\", 0);\n    ts.tm_hour = getfield(L, \"hour\", 12);\n    ts.tm_mday = getfield(L, \"day\", -1);\n    ts.tm_mon = getfield(L, \"month\", -1) - 1;\n    ts.tm_year = getfield(L, \"year\", -1) - 1900;\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n  }\n  if (t == (time_t)(-1))\n    lua_pushnil(L);\n  else\n    lua_pushnumber(L, (lua_Number)t);\n  return 1;\n}\n\nLJLIB_CF(os_difftime)\n{\n  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),\n\t\t\t     (time_t)(luaL_optnumber(L, 2, (lua_Number)0))));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(os_setlocale)\n{\n#if LJ_TARGET_PSVITA\n  lua_pushliteral(L, \"C\");\n#else\n  GCstr *s = lj_lib_optstr(L, 1);\n  const char *str = s ? strdata(s) : NULL;\n  int opt = lj_lib_checkopt(L, 2, 6,\n    \"\\5ctype\\7numeric\\4time\\7collate\\10monetary\\1\\377\\3all\");\n  if (opt == 0) opt = LC_CTYPE;\n  else if (opt == 1) opt = LC_NUMERIC;\n  else if (opt == 2) opt = LC_TIME;\n  else if (opt == 3) opt = LC_COLLATE;\n  else if (opt == 4) opt = LC_MONETARY;\n  else if (opt == 6) opt = LC_ALL;\n  lua_pushstring(L, setlocale(opt, str));\n#endif\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_os(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_OSLIBNAME, os);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_package.c",
    "content": "/*\n** Package library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_package_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Error codes for ll_loadfunc. */\n#define PACKAGE_ERR_LIB\t\t1\n#define PACKAGE_ERR_FUNC\t2\n#define PACKAGE_ERR_LOAD\t3\n\n/* Redefined in platform specific part. */\n#define PACKAGE_LIB_FAIL\t\"open\"\n#define setprogdir(L)\t\t((void)0)\n\n/* Symbol name prefixes. */\n#define SYMPREFIX_CF\t\t\"luaopen_%s\"\n#define SYMPREFIX_BC\t\t\"luaJIT_BC_%s\"\n\n#if LJ_TARGET_DLOPEN\n\n#include <dlfcn.h>\n\nstatic void ll_unloadlib(void *lib)\n{\n  dlclose(lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  lua_CFunction f = (lua_CFunction)dlsym(lib, sym);\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n#if defined(RTLD_DEFAULT)\n  if (lib == NULL) lib = RTLD_DEFAULT;\n#elif LJ_TARGET_OSX || LJ_TARGET_BSD\n  if (lib == NULL) lib = (void *)(intptr_t)-2;\n#endif\n  return (const char *)dlsym(lib, sym);\n}\n\n#elif LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\n#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS  4\n#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT  2\nBOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);\n#endif\n\n#undef setprogdir\n\nstatic void setprogdir(lua_State *L)\n{\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL) {\n    luaL_error(L, \"unable to get ModuleFileName\");\n  } else {\n    *lb = '\\0';\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\nstatic void pusherror(lua_State *L)\n{\n  DWORD error = GetLastError();\n#if LJ_TARGET_XBOXONE\n  wchar_t wbuffer[128];\n  char buffer[128*2];\n  if (FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, wbuffer, sizeof(wbuffer)/sizeof(wchar_t), NULL) &&\n      WideCharToMultiByte(CP_ACP, 0, wbuffer, 128, buffer, 128*2, NULL, NULL))\n#else\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer), NULL))\n#endif\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void ll_unloadlib(void *lib)\n{\n  FreeLibrary((HINSTANCE)lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  HINSTANCE lib = LoadLibraryExA(path, NULL, 0);\n  if (lib == NULL) pusherror(L);\n  UNUSED(gl);\n  return lib;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n  if (lib) {\n    return (const char *)GetProcAddress((HINSTANCE)lib, sym);\n  } else {\n    HINSTANCE h = GetModuleHandleA(NULL);\n    const char *p = (const char *)GetProcAddress(h, sym);\n    if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t\t\t(const char *)ll_bcsym, &h))\n      p = (const char *)GetProcAddress(h, sym);\n    return p;\n  }\n}\n\n#else\n\n#undef PACKAGE_LIB_FAIL\n#define PACKAGE_LIB_FAIL\t\"absent\"\n\n#define DLMSG\t\"dynamic libraries not enabled; no support for target OS\"\n\nstatic void ll_unloadlib(void *lib)\n{\n  UNUSED(lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  UNUSED(path); UNUSED(gl);\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  UNUSED(lib); UNUSED(sym);\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n  UNUSED(lib); UNUSED(sym);\n  return NULL;\n}\n\n#endif\n\n/* ------------------------------------------------------------------------ */\n\nstatic void **ll_register(lua_State *L, const char *path)\n{\n  void **plib;\n  lua_pushfstring(L, \"LOADLIB: %s\", path);\n  lua_gettable(L, LUA_REGISTRYINDEX);  /* check library in registry? */\n  if (!lua_isnil(L, -1)) {  /* is there an entry? */\n    plib = (void **)lua_touserdata(L, -1);\n  } else {  /* no entry yet; create one */\n    lua_pop(L, 1);\n    plib = (void **)lua_newuserdata(L, sizeof(void *));\n    *plib = NULL;\n    luaL_getmetatable(L, \"_LOADLIB\");\n    lua_setmetatable(L, -2);\n    lua_pushfstring(L, \"LOADLIB: %s\", path);\n    lua_pushvalue(L, -2);\n    lua_settable(L, LUA_REGISTRYINDEX);\n  }\n  return plib;\n}\n\nstatic const char *mksymname(lua_State *L, const char *modname,\n\t\t\t     const char *prefix)\n{\n  const char *funcname;\n  const char *mark = strchr(modname, *LUA_IGMARK);\n  if (mark) modname = mark + 1;\n  funcname = luaL_gsub(L, modname, \".\", \"_\");\n  funcname = lua_pushfstring(L, prefix, funcname);\n  lua_remove(L, -2);  /* remove 'gsub' result */\n  return funcname;\n}\n\nstatic int ll_loadfunc(lua_State *L, const char *path, const char *name, int r)\n{\n  void **reg = ll_register(L, path);\n  if (*reg == NULL) *reg = ll_load(L, path, (*name == '*'));\n  if (*reg == NULL) {\n    return PACKAGE_ERR_LIB;  /* Unable to load library. */\n  } else if (*name == '*') {  /* Only load library into global namespace. */\n    lua_pushboolean(L, 1);\n    return 0;\n  } else {\n    const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF);\n    lua_CFunction f = ll_sym(L, *reg, sym);\n    if (f) {\n      lua_pushcfunction(L, f);\n      return 0;\n    }\n    if (!r) {\n      const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC));\n      lua_pop(L, 1);\n      if (bcdata) {\n\tif (luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)\n\t  return PACKAGE_ERR_LOAD;\n\treturn 0;\n      }\n    }\n    return PACKAGE_ERR_FUNC;  /* Unable to find function. */\n  }\n}\n\nstatic int lj_cf_package_loadlib(lua_State *L)\n{\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int st = ll_loadfunc(L, path, init, 1);\n  if (st == 0) {  /* no errors? */\n    return 1;  /* return the loaded function */\n  } else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (st == PACKAGE_ERR_LIB) ?  PACKAGE_LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\nstatic int lj_cf_package_unloadlib(lua_State *L)\n{\n  void **lib = (void **)luaL_checkudata(L, 1, \"_LOADLIB\");\n  if (*lib) ll_unloadlib(*lib);\n  *lib = NULL;  /* mark library as closed */\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic int readable(const char *filename)\n{\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\nstatic const char *pushnexttemplate(lua_State *L, const char *path)\n{\n  const char *l;\n  while (*path == *LUA_PATHSEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATHSEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, (size_t)(l - path));  /* template */\n  return l;\n}\n\nstatic const char *searchpath (lua_State *L, const char *name,\n\t\t\t       const char *path, const char *sep,\n\t\t\t       const char *dirsep)\n{\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n\t\t\t\t     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file \" LUA_QS, filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\nstatic int lj_cf_package_searchpath(lua_State *L)\n{\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n\t\t\t\tluaL_checkstring(L, 2),\n\t\t\t\tluaL_optstring(L, 3, \".\"),\n\t\t\t\tluaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) {\n    return 1;\n  } else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\nstatic const char *findfile(lua_State *L, const char *name,\n\t\t\t    const char *pname)\n{\n  const char *path;\n  lua_getfield(L, LUA_ENVIRONINDEX, pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, LUA_QL(\"package.%s\") \" must be a string\", pname);\n  return searchpath(L, name, path, \".\", LUA_DIRSEP);\n}\n\nstatic void loaderror(lua_State *L, const char *filename)\n{\n  luaL_error(L, \"error loading module \" LUA_QS \" from file \" LUA_QS \":\\n\\t%s\",\n\t     lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\nstatic int lj_cf_package_loader_lua(lua_State *L)\n{\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (luaL_loadfile(L, filename) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\nstatic int lj_cf_package_loader_c(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (ll_loadfunc(L, filename, name, 0) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\nstatic int lj_cf_package_loader_croot(lua_State *L)\n{\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int st;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, (size_t)(p - name));\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\");\n  if (filename == NULL) return 1;  /* root not found */\n  if ((st = ll_loadfunc(L, filename, name, 0)) != 0) {\n    if (st != PACKAGE_ERR_FUNC) loaderror(L, filename);  /* real error */\n    lua_pushfstring(L, \"\\n\\tno module \" LUA_QS \" in file \" LUA_QS,\n\t\t    name, filename);\n    return 1;  /* function not found */\n  }\n  return 1;\n}\n\nstatic int lj_cf_package_loader_preload(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_ENVIRONINDEX, \"preload\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.preload\") \" must be a table\");\n  lua_getfield(L, -1, name);\n  if (lua_isnil(L, -1)) {  /* Not found? */\n    const char *bcname = mksymname(L, name, SYMPREFIX_BC);\n    const char *bcdata = ll_bcsym(NULL, bcname);\n    if (bcdata == NULL || luaL_loadbuffer(L, bcdata, LJ_MAX_BUF, name) != 0)\n      lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  }\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic const int sentinel_ = 0;\n#define sentinel\t((void *)&sentinel_)\n\nstatic int lj_cf_package_require(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  int i;\n  lua_settop(L, 1);  /* _LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, 2, name);\n  if (lua_toboolean(L, -1)) {  /* is it there? */\n    if (lua_touserdata(L, -1) == sentinel)  /* check loops */\n      luaL_error(L, \"loop or previous error loading module \" LUA_QS, name);\n    return 1;  /* package is already loaded */\n  }\n  /* else must load it; iterate over available loaders */\n  lua_getfield(L, LUA_ENVIRONINDEX, \"loaders\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.loaders\") \" must be a table\");\n  lua_pushliteral(L, \"\");  /* error message accumulator */\n  for (i = 1; ; i++) {\n    lua_rawgeti(L, -2, i);  /* get a loader */\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"module \" LUA_QS \" not found:%s\",\n\t\t name, lua_tostring(L, -2));\n    lua_pushstring(L, name);\n    lua_call(L, 1, 1);  /* call it */\n    if (lua_isfunction(L, -1))  /* did it find module? */\n      break;  /* module loaded successfully */\n    else if (lua_isstring(L, -1))  /* loader returned error message? */\n      lua_concat(L, 2);  /* accumulate it */\n    else\n      lua_pop(L, 1);\n  }\n  lua_pushlightuserdata(L, sentinel);\n  lua_setfield(L, 2, name);  /* _LOADED[name] = sentinel */\n  lua_pushstring(L, name);  /* pass name as argument to module */\n  lua_call(L, 1, 1);  /* run loaded module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  lua_getfield(L, 2, name);\n  if (lua_touserdata(L, -1) == sentinel) {   /* module did not set a value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  lj_lib_checkfpu(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void setfenv(lua_State *L)\n{\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, LUA_QL(\"module\") \" not called from a Lua function\");\n  lua_pushvalue(L, -2);\n  lua_setfenv(L, -2);\n  lua_pop(L, 1);\n}\n\nstatic void dooptions(lua_State *L, int n)\n{\n  int i;\n  for (i = 2; i <= n; i++) {\n    lua_pushvalue(L, i);  /* get option (a function) */\n    lua_pushvalue(L, -2);  /* module */\n    lua_call(L, 1, 0);\n  }\n}\n\nstatic void modinit(lua_State *L, const char *modname)\n{\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname; else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, (size_t)(dot - modname));\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\nstatic int lj_cf_package_module(lua_State *L)\n{\n  const char *modname = luaL_checkstring(L, 1);\n  int loaded = lua_gettop(L) + 1;  /* index of _LOADED table */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, loaded, modname);  /* get _LOADED[modname] */\n  if (!lua_istable(L, -1)) {  /* not found? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)\n      lj_err_callerv(L, LJ_ERR_BADMODN, modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, loaded, modname);  /* _LOADED[modname] = new table */\n  }\n  /* check whether table already has a _NAME field */\n  lua_getfield(L, -1, \"_NAME\");\n  if (!lua_isnil(L, -1)) {  /* is table an initialized module? */\n    lua_pop(L, 1);\n  } else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  setfenv(L);\n  dooptions(L, loaded - 1);\n  return 0;\n}\n\nstatic int lj_cf_package_seeall(lua_State *L)\n{\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#define AUXMARK\t\t\"\\1\"\n\nstatic void setpath(lua_State *L, const char *fieldname, const char *envname,\n\t\t    const char *def, int noenv)\n{\n#if LJ_TARGET_CONSOLE\n  const char *path = NULL;\n  UNUSED(envname);\n#else\n  const char *path = getenv(envname);\n#endif\n  if (path == NULL || noenv) {\n    lua_pushstring(L, def);\n  } else {\n    path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,\n\t\t\t      LUA_PATHSEP AUXMARK LUA_PATHSEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\nstatic const luaL_Reg package_lib[] = {\n  { \"loadlib\",\tlj_cf_package_loadlib },\n  { \"searchpath\",  lj_cf_package_searchpath },\n  { \"seeall\",\tlj_cf_package_seeall },\n  { NULL, NULL }\n};\n\nstatic const luaL_Reg package_global[] = {\n  { \"module\",\tlj_cf_package_module },\n  { \"require\",\tlj_cf_package_require },\n  { NULL, NULL }\n};\n\nstatic const lua_CFunction package_loaders[] =\n{\n  lj_cf_package_loader_preload,\n  lj_cf_package_loader_lua,\n  lj_cf_package_loader_c,\n  lj_cf_package_loader_croot,\n  NULL\n};\n\nLUALIB_API int luaopen_package(lua_State *L)\n{\n  int i;\n  int noenv;\n  luaL_newmetatable(L, \"_LOADLIB\");\n  lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);\n  lua_setfield(L, -2, \"__gc\");\n  luaL_register(L, LUA_LOADLIBNAME, package_lib);\n  lua_pushvalue(L, -1);\n  lua_replace(L, LUA_ENVIRONINDEX);\n  lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0);\n  for (i = 0; package_loaders[i] != NULL; i++) {\n    lj_lib_pushcf(L, package_loaders[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n  lua_setfield(L, -2, \"loaders\");\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  noenv = lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  setpath(L, \"path\", LUA_PATH, LUA_PATH_DEFAULT, noenv);\n  setpath(L, \"cpath\", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);\n  lua_pushliteral(L, LUA_PATH_CONFIG);\n  lua_setfield(L, -2, \"config\");\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n  lua_setfield(L, -2, \"loaded\");\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\", 4);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  luaL_register(L, NULL, package_global);\n  lua_pop(L, 1);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_string.c",
    "content": "/*\n** String library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_string_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_ff.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_char.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_string\n\nLJLIB_LUA(string_len) /*\n  function(s)\n    CHECK_str(s)\n    return #s\n  end\n*/\n\nLJLIB_ASM(string_byte)\t\tLJLIB_REC(string_range 0)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int32_t len = (int32_t)s->len;\n  int32_t start = lj_lib_optint(L, 2, 1);\n  int32_t stop = lj_lib_optint(L, 3, start);\n  int32_t n, i;\n  const unsigned char *p;\n  if (stop < 0) stop += len+1;\n  if (start < 0) start += len+1;\n  if (start <= 0) start = 1;\n  if (stop > len) stop = len;\n  if (start > stop) return FFH_RES(0);  /* Empty interval: return no results. */\n  start--;\n  n = stop - start;\n  if ((uint32_t)n > LUAI_MAXCSTACK)\n    lj_err_caller(L, LJ_ERR_STRSLC);\n  lj_state_checkstack(L, (MSize)n);\n  p = (const unsigned char *)strdata(s) + start;\n  for (i = 0; i < n; i++)\n    setintV(L->base + i-1-LJ_FR2, p[i]);\n  return FFH_RES(n);\n}\n\nLJLIB_ASM(string_char)\t\tLJLIB_REC(.)\n{\n  int i, nargs = (int)(L->top - L->base);\n  char *buf = lj_buf_tmp(L, (MSize)nargs);\n  for (i = 1; i <= nargs; i++) {\n    int32_t k = lj_lib_checkint(L, i);\n    if (!checku8(k))\n      lj_err_arg(L, i, LJ_ERR_BADVAL);\n    buf[i-1] = (char)k;\n  }\n  setstrV(L, L->base-1-LJ_FR2, lj_str_new(L, buf, (size_t)nargs));\n  return FFH_RES(1);\n}\n\nLJLIB_ASM(string_sub)\t\tLJLIB_REC(string_range 1)\n{\n  lj_lib_checkstr(L, 1);\n  lj_lib_checkint(L, 2);\n  setintV(L->base+2, lj_lib_optint(L, 3, -1));\n  return FFH_RETRY;\n}\n\nLJLIB_CF(string_rep)\t\tLJLIB_REC(.)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int32_t rep = lj_lib_checkint(L, 2);\n  GCstr *sep = lj_lib_optstr(L, 3);\n  SBuf *sb = lj_buf_tmp_(L);\n  if (sep && rep > 1) {\n    GCstr *s2 = lj_buf_cat2str(L, sep, s);\n    lj_buf_reset(sb);\n    lj_buf_putstr(sb, s);\n    s = s2;\n    rep--;\n  }\n  sb = lj_buf_putstr_rep(sb, s, rep);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_ASM(string_reverse)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_reverse)\n{\n  lj_lib_checkstr(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(string_lower)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_lower)\nLJLIB_ASM_(string_upper)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_upper)\n\n/* ------------------------------------------------------------------------ */\n\nstatic int writer_buf(lua_State *L, const void *p, size_t size, void *sb)\n{\n  lj_buf_putmem((SBuf *)sb, p, (MSize)size);\n  UNUSED(L);\n  return 0;\n}\n\nLJLIB_CF(string_dump)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  int strip = L->base+1 < L->top && tvistruecond(L->base+1);\n  SBuf *sb = lj_buf_tmp_(L);  /* Assumes lj_bcwrite() doesn't use tmpbuf. */\n  L->top = L->base+1;\n  if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, sb, strip))\n    lj_err_caller(L, LJ_ERR_STRDUMP);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* macro to `unsign' a character */\n#define uchar(c)        ((unsigned char)(c))\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end (`\\0') of source string */\n  lua_State *L;\n  int level;  /* total number of captures (finished or unfinished) */\n  int depth;\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n#define L_ESC\t\t'%'\n\nstatic int check_capture(MatchState *ms, int l)\n{\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    lj_err_caller(ms->L, LJ_ERR_STRCAPI);\n  return l;\n}\n\nstatic int capture_to_close(MatchState *ms)\n{\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  lj_err_caller(ms->L, LJ_ERR_STRPATC);\n  return 0;  /* unreachable */\n}\n\nstatic const char *classend(MatchState *ms, const char *p)\n{\n  switch (*p++) {\n  case L_ESC:\n    if (*p == '\\0')\n      lj_err_caller(ms->L, LJ_ERR_STRPATE);\n    return p+1;\n  case '[':\n    if (*p == '^') p++;\n    do {  /* look for a `]' */\n      if (*p == '\\0')\n\tlj_err_caller(ms->L, LJ_ERR_STRPATM);\n      if (*(p++) == L_ESC && *p != '\\0')\n\tp++;  /* skip escapes (e.g. `%]') */\n    } while (*p != ']');\n    return p+1;\n  default:\n    return p;\n  }\n}\n\nstatic const unsigned char match_class_map[32] = {\n  0,LJ_CHAR_ALPHA,0,LJ_CHAR_CNTRL,LJ_CHAR_DIGIT,0,0,LJ_CHAR_GRAPH,0,0,0,0,\n  LJ_CHAR_LOWER,0,0,0,LJ_CHAR_PUNCT,0,0,LJ_CHAR_SPACE,0,\n  LJ_CHAR_UPPER,0,LJ_CHAR_ALNUM,LJ_CHAR_XDIGIT,0,0,0,0,0,0,0\n};\n\nstatic int match_class(int c, int cl)\n{\n  if ((cl & 0xc0) == 0x40) {\n    int t = match_class_map[(cl&0x1f)];\n    if (t) {\n      t = lj_char_isa(c, t);\n      return (cl & 0x20) ? t : !t;\n    }\n    if (cl == 'z') return c == 0;\n    if (cl == 'Z') return c != 0;\n  }\n  return (cl == c);\n}\n\nstatic int matchbracketclass(int c, const char *p, const char *ec)\n{\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the `^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n\treturn sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n\treturn sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\nstatic int singlematch(int c, const char *p, const char *ep)\n{\n  switch (*p) {\n  case '.': return 1;  /* matches any char */\n  case L_ESC: return match_class(c, uchar(*(p+1)));\n  case '[': return matchbracketclass(c, p, ep-1);\n  default:  return (uchar(*p) == c);\n  }\n}\n\nstatic const char *match(MatchState *ms, const char *s, const char *p);\n\nstatic const char *matchbalance(MatchState *ms, const char *s, const char *p)\n{\n  if (*p == 0 || *(p+1) == 0)\n    lj_err_caller(ms->L, LJ_ERR_STRPATU);\n  if (*s != *p) {\n    return NULL;\n  } else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n\tif (--cont == 0) return s+1;\n      } else if (*s == b) {\n\tcont++;\n      }\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\nstatic const char *max_expand(MatchState *ms, const char *s,\n\t\t\t      const char *p, const char *ep)\n{\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\nstatic const char *min_expand(MatchState *ms, const char *s,\n\t\t\t      const char *p, const char *ep)\n{\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (s<ms->src_end && singlematch(uchar(*s), p, ep))\n      s++;  /* try with one more repetition */\n    else\n      return NULL;\n  }\n}\n\nstatic const char *start_capture(MatchState *ms, const char *s,\n\t\t\t\t const char *p, int what)\n{\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) lj_err_caller(ms->L, LJ_ERR_STRCAPN);\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\nstatic const char *end_capture(MatchState *ms, const char *s,\n\t\t\t       const char *p)\n{\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\nstatic const char *match_capture(MatchState *ms, const char *s, int l)\n{\n  size_t len;\n  l = check_capture(ms, l);\n  len = (size_t)ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else\n    return NULL;\n}\n\nstatic const char *match(MatchState *ms, const char *s, const char *p)\n{\n  if (++ms->depth > LJ_MAX_XLEVEL)\n    lj_err_caller(ms->L, LJ_ERR_STRPATX);\n  init: /* using goto's to optimize tail recursion */\n  switch (*p) {\n  case '(':  /* start capture */\n    if (*(p+1) == ')')  /* position capture? */\n      s = start_capture(ms, s, p+2, CAP_POSITION);\n    else\n      s = start_capture(ms, s, p+1, CAP_UNFINISHED);\n    break;\n  case ')':  /* end capture */\n    s = end_capture(ms, s, p+1);\n    break;\n  case L_ESC:\n    switch (*(p+1)) {\n    case 'b':  /* balanced string? */\n      s = matchbalance(ms, s, p+2);\n      if (s == NULL) break;\n      p+=4;\n      goto init;  /* else s = match(ms, s, p+4); */\n    case 'f': {  /* frontier? */\n      const char *ep; char previous;\n      p += 2;\n      if (*p != '[')\n\tlj_err_caller(ms->L, LJ_ERR_STRPATB);\n      ep = classend(ms, p);  /* points to what is next */\n      previous = (s == ms->src_init) ? '\\0' : *(s-1);\n      if (matchbracketclass(uchar(previous), p, ep-1) ||\n\t !matchbracketclass(uchar(*s), p, ep-1)) { s = NULL; break; }\n      p=ep;\n      goto init;  /* else s = match(ms, s, ep); */\n      }\n    default:\n      if (lj_char_isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */\n\ts = match_capture(ms, s, uchar(*(p+1)));\n\tif (s == NULL) break;\n\tp+=2;\n\tgoto init;  /* else s = match(ms, s, p+2) */\n      }\n      goto dflt;  /* case default */\n    }\n    break;\n  case '\\0':  /* end of pattern */\n    break;  /* match succeeded */\n  case '$':\n    /* is the `$' the last char in pattern? */\n    if (*(p+1) != '\\0') goto dflt;\n    if (s != ms->src_end) s = NULL;  /* check end of string */\n    break;\n  default: dflt: {  /* it is a pattern item */\n    const char *ep = classend(ms, p);  /* points to what is next */\n    int m = s<ms->src_end && singlematch(uchar(*s), p, ep);\n    switch (*ep) {\n    case '?': {  /* optional */\n      const char *res;\n      if (m && ((res=match(ms, s+1, ep+1)) != NULL)) {\n\ts = res;\n\tbreak;\n      }\n      p=ep+1;\n      goto init;  /* else s = match(ms, s, ep+1); */\n      }\n    case '*':  /* 0 or more repetitions */\n      s = max_expand(ms, s, p, ep);\n      break;\n    case '+':  /* 1 or more repetitions */\n      s = (m ? max_expand(ms, s+1, p, ep) : NULL);\n      break;\n    case '-':  /* 0 or more repetitions (minimum) */\n      s = min_expand(ms, s, p, ep);\n      break;\n    default:\n      if (m) { s++; p=ep; goto init; }  /* else s = match(ms, s+1, ep); */\n      s = NULL;\n      break;\n    }\n    break;\n    }\n  }\n  ms->depth--;\n  return s;\n}\n\nstatic void push_onecapture(MatchState *ms, int i, const char *s, const char *e)\n{\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, (size_t)(e - s));  /* add whole match */\n    else\n      lj_err_caller(ms->L, LJ_ERR_STRCAPI);\n  } else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) lj_err_caller(ms->L, LJ_ERR_STRCAPU);\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, (size_t)l);\n  }\n}\n\nstatic int push_captures(MatchState *ms, const char *s, const char *e)\n{\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\nstatic int str_find_aux(lua_State *L, int find)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  GCstr *p = lj_lib_checkstr(L, 2);\n  int32_t start = lj_lib_optint(L, 3, 1);\n  MSize st;\n  if (start < 0) start += (int32_t)s->len; else start--;\n  if (start < 0) start = 0;\n  st = (MSize)start;\n  if (st > s->len) {\n#if LJ_52\n    setnilV(L->top-1);\n    return 1;\n#else\n    st = s->len;\n#endif\n  }\n  if (find && ((L->base+3 < L->top && tvistruecond(L->base+3)) ||\n\t       !lj_str_haspattern(p))) {  /* Search for fixed string. */\n    const char *q = lj_str_find(strdata(s)+st, strdata(p), s->len-st, p->len);\n    if (q) {\n      setintV(L->top-2, (int32_t)(q-strdata(s)) + 1);\n      setintV(L->top-1, (int32_t)(q-strdata(s)) + (int32_t)p->len);\n      return 2;\n    }\n  } else {  /* Search for pattern. */\n    MatchState ms;\n    const char *pstr = strdata(p);\n    const char *sstr = strdata(s) + st;\n    int anchor = 0;\n    if (*pstr == '^') { pstr++; anchor = 1; }\n    ms.L = L;\n    ms.src_init = strdata(s);\n    ms.src_end = strdata(s) + s->len;\n    do {  /* Loop through string and try to match the pattern. */\n      const char *q;\n      ms.level = ms.depth = 0;\n      q = match(&ms, sstr, pstr);\n      if (q) {\n\tif (find) {\n\t  setintV(L->top++, (int32_t)(sstr-(strdata(s)-1)));\n\t  setintV(L->top++, (int32_t)(q-strdata(s)));\n\t  return push_captures(&ms, NULL, NULL) + 2;\n\t} else {\n\t  return push_captures(&ms, sstr, q);\n\t}\n      }\n    } while (sstr++ < ms.src_end && !anchor);\n  }\n  setnilV(L->top-1);  /* Not found. */\n  return 1;\n}\n\nLJLIB_CF(string_find)\t\tLJLIB_REC(.)\n{\n  return str_find_aux(L, 1);\n}\n\nLJLIB_CF(string_match)\n{\n  return str_find_aux(L, 0);\n}\n\nLJLIB_NOREG LJLIB_CF(string_gmatch_aux)\n{\n  const char *p = strVdata(lj_lib_upvalue(L, 2));\n  GCstr *str = strV(lj_lib_upvalue(L, 1));\n  const char *s = strdata(str);\n  TValue *tvpos = lj_lib_upvalue(L, 3);\n  const char *src = s + tvpos->u32.lo;\n  MatchState ms;\n  ms.L = L;\n  ms.src_init = s;\n  ms.src_end = s + str->len;\n  for (; src <= ms.src_end; src++) {\n    const char *e;\n    ms.level = ms.depth = 0;\n    if ((e = match(&ms, src, p)) != NULL) {\n      int32_t pos = (int32_t)(e - s);\n      if (e == src) pos++;  /* Ensure progress for empty match. */\n      tvpos->u32.lo = (uint32_t)pos;\n      return push_captures(&ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\nLJLIB_CF(string_gmatch)\n{\n  lj_lib_checkstr(L, 1);\n  lj_lib_checkstr(L, 2);\n  L->top = L->base+3;\n  (L->top-1)->u64 = 0;\n  lj_lib_pushcc(L, lj_cf_string_gmatch_aux, FF_string_gmatch_aux, 3);\n  return 1;\n}\n\nstatic void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)\n{\n  size_t l, i;\n  const char *news = lua_tolstring(ms->L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC) {\n      luaL_addchar(b, news[i]);\n    } else {\n      i++;  /* skip ESC */\n      if (!lj_char_isdigit(uchar(news[i]))) {\n\tluaL_addchar(b, news[i]);\n      } else if (news[i] == '0') {\n\tluaL_addlstring(b, s, (size_t)(e - s));\n      } else {\n\tpush_onecapture(ms, news[i] - '1', s, e);\n\tluaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\nstatic void add_value(MatchState *ms, luaL_Buffer *b,\n\t\t      const char *s, const char *e)\n{\n  lua_State *L = ms->L;\n  switch (lua_type(L, 3)) {\n    case LUA_TNUMBER:\n    case LUA_TSTRING: {\n      add_s(ms, b, s, e);\n      return;\n    }\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, (size_t)(e - s));  /* keep original text */\n  } else if (!lua_isstring(L, -1)) {\n    lj_err_callerv(L, LJ_ERR_STRGSRV, luaL_typename(L, -1));\n  }\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\nLJLIB_CF(string_gsub)\n{\n  size_t srcl;\n  const char *src = luaL_checklstring(L, 1, &srcl);\n  const char *p = luaL_checkstring(L, 2);\n  int  tr = lua_type(L, 3);\n  int max_s = luaL_optint(L, 4, (int)(srcl+1));\n  int anchor = (*p == '^') ? (p++, 1) : 0;\n  int n = 0;\n  MatchState ms;\n  luaL_Buffer b;\n  if (!(tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n\ttr == LUA_TFUNCTION || tr == LUA_TTABLE))\n    lj_err_arg(L, 3, LJ_ERR_NOSFT);\n  luaL_buffinit(L, &b);\n  ms.L = L;\n  ms.src_init = src;\n  ms.src_end = src+srcl;\n  while (n < max_s) {\n    const char *e;\n    ms.level = ms.depth = 0;\n    e = match(&ms, src, p);\n    if (e) {\n      n++;\n      add_value(&ms, &b, src, e);\n    }\n    if (e && e>src) /* non empty match? */\n      src = e;  /* skip it */\n    else if (src < ms.src_end)\n      luaL_addchar(&b, *src++);\n    else\n      break;\n    if (anchor)\n      break;\n  }\n  luaL_addlstring(&b, src, (size_t)(ms.src_end-src));\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Emulate tostring() inline. */\nstatic GCstr *string_fmt_tostring(lua_State *L, int arg, int retry)\n{\n  TValue *o = L->base+arg-1;\n  cTValue *mo;\n  lua_assert(o < L->top);  /* Caller already checks for existence. */\n  if (LJ_LIKELY(tvisstr(o)))\n    return strV(o);\n  if (retry != 2 && !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {\n    copyTV(L, L->top++, mo);\n    copyTV(L, L->top++, o);\n    lua_call(L, 1, 1);\n    copyTV(L, L->base+arg-1, --L->top);\n    return NULL;  /* Buffer may be overwritten, retry. */\n  }\n  return lj_strfmt_obj(L, o);\n}\n\nLJLIB_CF(string_format)\t\tLJLIB_REC(.)\n{\n  int arg, top = (int)(L->top - L->base);\n  GCstr *fmt;\n  SBuf *sb;\n  FormatState fs;\n  SFormat sf;\n  int retry = 0;\nagain:\n  arg = 1;\n  sb = lj_buf_tmp_(L);\n  fmt = lj_lib_checkstr(L, arg);\n  lj_strfmt_init(&fs, strdata(fmt), fmt->len);\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {\n    if (sf == STRFMT_LIT) {\n      lj_buf_putmem(sb, fs.str, fs.len);\n    } else if (sf == STRFMT_ERR) {\n      lj_err_callerv(L, LJ_ERR_STRFMT, strdata(lj_str_new(L, fs.str, fs.len)));\n    } else {\n      if (++arg > top)\n\tluaL_argerror(L, arg, lj_obj_typename[0]);\n      switch (STRFMT_TYPE(sf)) {\n      case STRFMT_INT:\n\tif (tvisint(L->base+arg-1)) {\n\t  int32_t k = intV(L->base+arg-1);\n\t  if (sf == STRFMT_INT)\n\t    lj_strfmt_putint(sb, k);  /* Shortcut for plain %d. */\n\t  else\n\t    lj_strfmt_putfxint(sb, sf, k);\n\t} else {\n\t  lj_strfmt_putfnum_int(sb, sf, lj_lib_checknum(L, arg));\n\t}\n\tbreak;\n      case STRFMT_UINT:\n\tif (tvisint(L->base+arg-1))\n\t  lj_strfmt_putfxint(sb, sf, intV(L->base+arg-1));\n\telse\n\t  lj_strfmt_putfnum_uint(sb, sf, lj_lib_checknum(L, arg));\n\tbreak;\n      case STRFMT_NUM:\n\tlj_strfmt_putfnum(sb, sf, lj_lib_checknum(L, arg));\n\tbreak;\n      case STRFMT_STR: {\n\tGCstr *str = string_fmt_tostring(L, arg, retry);\n\tif (str == NULL)\n\t  retry = 1;\n\telse if ((sf & STRFMT_T_QUOTED))\n\t  lj_strfmt_putquoted(sb, str);  /* No formatting. */\n\telse\n\t  lj_strfmt_putfstr(sb, sf, str);\n\tbreak;\n\t}\n      case STRFMT_CHAR:\n\tlj_strfmt_putfchar(sb, sf, lj_lib_checkint(L, arg));\n\tbreak;\n      case STRFMT_PTR:  /* No formatting. */\n\tlj_strfmt_putptr(sb, lj_obj_ptr(L->base+arg-1));\n\tbreak;\n      default:\n\tlua_assert(0);\n\tbreak;\n      }\n    }\n  }\n  if (retry++ == 1) goto again;\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_string(lua_State *L)\n{\n  GCtab *mt;\n  global_State *g;\n  LJ_LIB_REG(L, LUA_STRLIBNAME, string);\n#if defined(LUA_COMPAT_GFIND) && !LJ_52\n  lua_getfield(L, -1, \"gmatch\");\n  lua_setfield(L, -2, \"gfind\");\n#endif\n  mt = lj_tab_new(L, 0, 1);\n  /* NOBARRIER: basemt is a GC root. */\n  g = G(L);\n  setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt));\n  settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1));\n  mt->nomm = (uint8_t)(~(1u<<MM_index));\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lib_table.c",
    "content": "/*\n** Table library.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_table_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_tab.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_table\n\nLJLIB_LUA(table_foreachi) /*\n  function(t, f)\n    CHECK_tab(t)\n    CHECK_func(f)\n    for i=1,#t do\n      local r = f(i, t[i])\n      if r ~= nil then return r end\n    end\n  end\n*/\n\nLJLIB_LUA(table_foreach) /*\n  function(t, f)\n    CHECK_tab(t)\n    CHECK_func(f)\n    for k, v in PAIRS(t) do\n      local r = f(k, v)\n      if r ~= nil then return r end\n    end\n  end\n*/\n\nLJLIB_LUA(table_getn) /*\n  function(t)\n    CHECK_tab(t)\n    return #t\n  end\n*/\n\nLJLIB_CF(table_maxn)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  TValue *array = tvref(t->array);\n  Node *node;\n  lua_Number m = 0;\n  ptrdiff_t i;\n  for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--)\n    if (!tvisnil(&array[i])) {\n      m = (lua_Number)(int32_t)i;\n      break;\n    }\n  node = noderef(t->node);\n  for (i = (ptrdiff_t)t->hmask; i >= 0; i--)\n    if (!tvisnil(&node[i].val) && tvisnumber(&node[i].key)) {\n      lua_Number n = numberVnum(&node[i].key);\n      if (n > m) m = n;\n    }\n  setnumV(L->top-1, m);\n  return 1;\n}\n\nLJLIB_CF(table_insert)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n, i = (int32_t)lj_tab_len(t) + 1;\n  int nargs = (int)((char *)L->top - (char *)L->base);\n  if (nargs != 2*sizeof(TValue)) {\n    if (nargs != 3*sizeof(TValue))\n      lj_err_caller(L, LJ_ERR_TABINS);\n    /* NOBARRIER: This just moves existing elements around. */\n    for (n = lj_lib_checkint(L, 2); i > n; i--) {\n      /* The set may invalidate the get pointer, so need to do it first! */\n      TValue *dst = lj_tab_setint(L, t, i);\n      cTValue *src = lj_tab_getint(t, i-1);\n      if (src) {\n\tcopyTV(L, dst, src);\n      } else {\n\tsetnilV(dst);\n      }\n    }\n    i = n;\n  }\n  {\n    TValue *dst = lj_tab_setint(L, t, i);\n    copyTV(L, dst, L->top-1);  /* Set new value. */\n    lj_gc_barriert(L, t, dst);\n  }\n  return 0;\n}\n\nLJLIB_LUA(table_remove) /*\n  function(t, pos)\n    CHECK_tab(t)\n    local len = #t\n    if pos == nil then\n      if len ~= 0 then\n\tlocal old = t[len]\n\tt[len] = nil\n\treturn old\n      end\n    else\n      CHECK_int(pos)\n      if pos >= 1 and pos <= len then\n\tlocal old = t[pos]\n\tfor i=pos+1,len do\n\t  t[i-1] = t[i]\n\tend\n\tt[len] = nil\n\treturn old\n      end\n    end\n  end\n*/\n\nLJLIB_CF(table_concat)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  GCstr *sep = lj_lib_optstr(L, 2);\n  int32_t i = lj_lib_optint(L, 3, 1);\n  int32_t e = (L->base+3 < L->top && !tvisnil(L->base+3)) ?\n\t      lj_lib_checkint(L, 4) : (int32_t)lj_tab_len(t);\n  SBuf *sb = lj_buf_tmp_(L);\n  SBuf *sbx = lj_buf_puttab(sb, t, sep, i, e);\n  if (LJ_UNLIKELY(!sbx)) {  /* Error: bad element type. */\n    int32_t idx = (int32_t)(intptr_t)sbufP(sb);\n    cTValue *o = lj_tab_getint(t, idx);\n    lj_err_callerv(L, LJ_ERR_TABCAT,\n\t\t   lj_obj_itypename[o ? itypemap(o) : ~LJ_TNIL], idx);\n  }\n  setstrV(L, L->top-1, lj_buf_str(L, sbx));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void set2(lua_State *L, int i, int j)\n{\n  lua_rawseti(L, 1, i);\n  lua_rawseti(L, 1, j);\n}\n\nstatic int sort_comp(lua_State *L, int a, int b)\n{\n  if (!lua_isnil(L, 2)) {  /* function? */\n    int res;\n    lua_pushvalue(L, 2);\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */\n    lua_call(L, 2, 1);\n    res = lua_toboolean(L, -1);\n    lua_pop(L, 1);\n    return res;\n  } else {  /* a < b? */\n    return lua_lessthan(L, a, b);\n  }\n}\n\nstatic void auxsort(lua_State *L, int l, int u)\n{\n  while (l < u) {  /* for tail recursion */\n    int i, j;\n    /* sort elements a[l], a[(l+u)/2] and a[u] */\n    lua_rawgeti(L, 1, l);\n    lua_rawgeti(L, 1, u);\n    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */\n      set2(L, l, u);  /* swap a[l] - a[u] */\n    else\n      lua_pop(L, 2);\n    if (u-l == 1) break;  /* only 2 elements */\n    i = (l+u)/2;\n    lua_rawgeti(L, 1, i);\n    lua_rawgeti(L, 1, l);\n    if (sort_comp(L, -2, -1)) {  /* a[i]<a[l]? */\n      set2(L, i, l);\n    } else {\n      lua_pop(L, 1);  /* remove a[l] */\n      lua_rawgeti(L, 1, u);\n      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */\n\tset2(L, i, u);\n      else\n\tlua_pop(L, 2);\n    }\n    if (u-l == 2) break;  /* only 3 elements */\n    lua_rawgeti(L, 1, i);  /* Pivot */\n    lua_pushvalue(L, -1);\n    lua_rawgeti(L, 1, u-1);\n    set2(L, i, u-1);\n    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */\n    i = l; j = u-1;\n    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */\n      /* repeat ++i until a[i] >= P */\n      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {\n\tif (i>=u) lj_err_caller(L, LJ_ERR_TABSORT);\n\tlua_pop(L, 1);  /* remove a[i] */\n      }\n      /* repeat --j until a[j] <= P */\n      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {\n\tif (j<=l) lj_err_caller(L, LJ_ERR_TABSORT);\n\tlua_pop(L, 1);  /* remove a[j] */\n      }\n      if (j<i) {\n\tlua_pop(L, 3);  /* pop pivot, a[i], a[j] */\n\tbreak;\n      }\n      set2(L, i, j);\n    }\n    lua_rawgeti(L, 1, u-1);\n    lua_rawgeti(L, 1, i);\n    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */\n    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */\n    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */\n    if (i-l < u-i) {\n      j=l; i=i-1; l=i+2;\n    } else {\n      j=i+1; i=u; u=j-2;\n    }\n    auxsort(L, j, i);  /* call recursively the smaller one */\n  }  /* repeat the routine for the larger one */\n}\n\nLJLIB_CF(table_sort)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n = (int32_t)lj_tab_len(t);\n  lua_settop(L, 2);\n  if (!tvisnil(L->base+1))\n    lj_lib_checkfunc(L, 2);\n  auxsort(L, 1, n);\n  return 0;\n}\n\n#if LJ_52\nLJLIB_PUSH(\"n\")\nLJLIB_CF(table_pack)\n{\n  TValue *array, *base = L->base;\n  MSize i, n = (uint32_t)(L->top - base);\n  GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1);\n  /* NOBARRIER: The table is new (marked white). */\n  setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n);\n  for (array = tvref(t->array) + 1, i = 0; i < n; i++)\n    copyTV(L, &array[i], &base[i]);\n  settabV(L, base, t);\n  L->top = base+1;\n  lj_gc_check(L);\n  return 1;\n}\n#endif\n\nLJLIB_NOREG LJLIB_CF(table_new)\t\tLJLIB_REC(.)\n{\n  int32_t a = lj_lib_checkint(L, 1);\n  int32_t h = lj_lib_checkint(L, 2);\n  lua_createtable(L, a, h);\n  return 1;\n}\n\nLJLIB_NOREG LJLIB_CF(table_clear)\tLJLIB_REC(.)\n{\n  lj_tab_clear(lj_lib_checktab(L, 1));\n  return 0;\n}\n\nstatic int luaopen_table_new(lua_State *L)\n{\n  return lj_lib_postreg(L, lj_cf_table_new, FF_table_new, \"new\");\n}\n\nstatic int luaopen_table_clear(lua_State *L)\n{\n  return lj_lib_postreg(L, lj_cf_table_clear, FF_table_clear, \"clear\");\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_table(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_TABLIBNAME, table);\n#if LJ_52\n  lua_getglobal(L, \"unpack\");\n  lua_setfield(L, -2, \"unpack\");\n#endif\n  lj_lib_prereg(L, LUA_TABLIBNAME \".new\", luaopen_table_new, tabV(L->top-1));\n  lj_lib_prereg(L, LUA_TABLIBNAME \".clear\", luaopen_table_clear, tabV(L->top-1));\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj.supp",
    "content": "# Valgrind suppression file for LuaJIT 2.0.\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:lj_str_cmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:lj_str_cmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Cond\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:lj_str_fastcmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:lj_str_fastcmp\n}\n{\n   Optimized string compare\n   Memcheck:Cond\n   fun:lj_str_fastcmp\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_alloc.c",
    "content": "/*\n** Bundled memory allocator.\n**\n** Beware: this is a HEAVILY CUSTOMIZED version of dlmalloc.\n** The original bears the following remark:\n**\n**   This is a version (aka dlmalloc) of malloc/free/realloc written by\n**   Doug Lea and released to the public domain, as explained at\n**   http://creativecommons.org/licenses/publicdomain.\n**\n**   * Version pre-2.8.4 Wed Mar 29 19:46:29 2006    (dl at gee)\n**\n** No additional copyright is claimed over the customizations.\n** Please do NOT bother the original author about this version here!\n**\n** If you want to use dlmalloc in another project, you should get\n** the original from: ftp://gee.cs.oswego.edu/pub/misc/\n** For thread-safe derivatives, take a look at:\n** - ptmalloc: http://www.malloc.de/\n** - nedmalloc: http://www.nedprod.com/programs/portable/nedmalloc/\n*/\n\n#define lj_alloc_c\n#define LUA_CORE\n\n/* To get the mremap prototype. Must be defined before any system includes. */\n#if defined(__linux__) && !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n#include \"lj_alloc.h\"\n\n#ifndef LUAJIT_USE_SYSMALLOC\n\n#define MAX_SIZE_T\t\t(~(size_t)0)\n#define MALLOC_ALIGNMENT\t((size_t)8U)\n\n#define DEFAULT_GRANULARITY\t((size_t)128U * (size_t)1024U)\n#define DEFAULT_TRIM_THRESHOLD\t((size_t)2U * (size_t)1024U * (size_t)1024U)\n#define DEFAULT_MMAP_THRESHOLD\t((size_t)128U * (size_t)1024U)\n#define MAX_RELEASE_CHECK_RATE\t255\n\n/* ------------------- size_t and alignment properties -------------------- */\n\n/* The byte and bit size of a size_t */\n#define SIZE_T_SIZE\t\t(sizeof(size_t))\n#define SIZE_T_BITSIZE\t\t(sizeof(size_t) << 3)\n\n/* Some constants coerced to size_t */\n/* Annoying but necessary to avoid errors on some platforms */\n#define SIZE_T_ZERO\t\t((size_t)0)\n#define SIZE_T_ONE\t\t((size_t)1)\n#define SIZE_T_TWO\t\t((size_t)2)\n#define TWO_SIZE_T_SIZES\t(SIZE_T_SIZE<<1)\n#define FOUR_SIZE_T_SIZES\t(SIZE_T_SIZE<<2)\n#define SIX_SIZE_T_SIZES\t(FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)\n\n/* The bit mask value corresponding to MALLOC_ALIGNMENT */\n#define CHUNK_ALIGN_MASK\t(MALLOC_ALIGNMENT - SIZE_T_ONE)\n\n/* the number of bytes to offset an address to align it */\n#define align_offset(A)\\\n ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\\\n  ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))\n\n/* -------------------------- MMAP support ------------------------------- */\n\n#define MFAIL\t\t\t((void *)(MAX_SIZE_T))\n#define CMFAIL\t\t\t((char *)(MFAIL)) /* defined for convenience */\n\n#define IS_DIRECT_BIT\t\t(SIZE_T_ONE)\n\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#if LJ_64 && !LJ_GC64\n\n/* Undocumented, but hey, that's what we all love so much about Windows. */\ntypedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits,\n\t\t       size_t *size, ULONG alloctype, ULONG prot);\nstatic PNTAVM ntavm;\n\n/* Number of top bits of the lower 32 bits of an address that must be zero.\n** Apparently 0 gives us full 64 bit addresses and 1 gives us the lower 2GB.\n*/\n#define NTAVM_ZEROBITS\t\t1\n\nstatic void INIT_MMAP(void)\n{\n  ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA(\"ntdll.dll\"),\n\t\t\t\t \"NtAllocateVirtualMemory\");\n}\n\n/* Win64 32 bit MMAP via NtAllocateVirtualMemory. */\nstatic LJ_AINLINE void *CALL_MMAP(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = NULL;\n  long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,\n\t\t  MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  SetLastError(olderr);\n  return st == 0 ? ptr : MFAIL;\n}\n\n/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */\nstatic LJ_AINLINE void *DIRECT_MMAP(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = NULL;\n  long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,\n\t\t  MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE);\n  SetLastError(olderr);\n  return st == 0 ? ptr : MFAIL;\n}\n\n#else\n\n#define INIT_MMAP()\t\t((void)0)\n\n/* Win32 MMAP via VirtualAlloc */\nstatic LJ_AINLINE void *CALL_MMAP(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  SetLastError(olderr);\n  return ptr ? ptr : MFAIL;\n}\n\n/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */\nstatic LJ_AINLINE void *DIRECT_MMAP(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,\n\t\t\t   PAGE_READWRITE);\n  SetLastError(olderr);\n  return ptr ? ptr : MFAIL;\n}\n\n#endif\n\n/* This function supports releasing coalesed segments */\nstatic LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)\n{\n  DWORD olderr = GetLastError();\n  MEMORY_BASIC_INFORMATION minfo;\n  char *cptr = (char *)ptr;\n  while (size) {\n    if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)\n      return -1;\n    if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||\n\tminfo.State != MEM_COMMIT || minfo.RegionSize > size)\n      return -1;\n    if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)\n      return -1;\n    cptr += minfo.RegionSize;\n    size -= minfo.RegionSize;\n  }\n  SetLastError(olderr);\n  return 0;\n}\n\n#else\n\n#include <errno.h>\n#include <sys/mman.h>\n\n#define MMAP_PROT\t\t(PROT_READ|PROT_WRITE)\n#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)\n#define MAP_ANONYMOUS\t\tMAP_ANON\n#endif\n#define MMAP_FLAGS\t\t(MAP_PRIVATE|MAP_ANONYMOUS)\n\n#if LJ_64 && !LJ_GC64\n/* 64 bit mode with 32 bit pointers needs special support for allocating\n** memory in the lower 2GB.\n*/\n\n#if defined(MAP_32BIT)\n\n#if defined(__sun__)\n#define MMAP_REGION_START\t((uintptr_t)0x1000)\n#else\n/* Actually this only gives us max. 1GB in current Linux kernels. */\n#define MMAP_REGION_START\t((uintptr_t)0)\n#endif\n\nstatic LJ_AINLINE void *CALL_MMAP(size_t size)\n{\n  int olderr = errno;\n  void *ptr = mmap((void *)MMAP_REGION_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);\n  errno = olderr;\n  return ptr;\n}\n\n#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__CYGWIN__)\n\n/* OSX and FreeBSD mmap() use a naive first-fit linear search.\n** That's perfect for us. Except that -pagezero_size must be set for OSX,\n** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs\n** to be reduced to 250MB on FreeBSD.\n*/\n#if LJ_TARGET_OSX || defined(__DragonFly__)\n#define MMAP_REGION_START\t((uintptr_t)0x10000)\n#elif LJ_TARGET_PS4\n#define MMAP_REGION_START\t((uintptr_t)0x4000)\n#else\n#define MMAP_REGION_START\t((uintptr_t)0x10000000)\n#endif\n#define MMAP_REGION_END\t\t((uintptr_t)0x80000000)\n\n#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4\n#include <sys/resource.h>\n#endif\n\nstatic LJ_AINLINE void *CALL_MMAP(size_t size)\n{\n  int olderr = errno;\n  /* Hint for next allocation. Doesn't need to be thread-safe. */\n  static uintptr_t alloc_hint = MMAP_REGION_START;\n  int retry = 0;\n#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4\n  static int rlimit_modified = 0;\n  if (LJ_UNLIKELY(rlimit_modified == 0)) {\n    struct rlimit rlim;\n    rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START;\n    setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail below. */\n    rlimit_modified = 1;\n  }\n#endif\n  for (;;) {\n    void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0);\n    if ((uintptr_t)p >= MMAP_REGION_START &&\n\t(uintptr_t)p + size < MMAP_REGION_END) {\n      alloc_hint = (uintptr_t)p + size;\n      errno = olderr;\n      return p;\n    }\n    if (p != CMFAIL) munmap(p, size);\n#if defined(__sun__) || defined(__DragonFly__)\n    alloc_hint += 0x1000000;  /* Need near-exhaustive linear scan. */\n    if (alloc_hint + size < MMAP_REGION_END) continue;\n#endif\n    if (retry) break;\n    retry = 1;\n    alloc_hint = MMAP_REGION_START;\n  }\n  errno = olderr;\n  return CMFAIL;\n}\n\n#else\n\n#error \"NYI: need an equivalent of MAP_32BIT for this 64 bit OS\"\n\n#endif\n\n#else\n\n/* 32 bit mode and GC64 mode is easy. */\nstatic LJ_AINLINE void *CALL_MMAP(size_t size)\n{\n  int olderr = errno;\n  void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0);\n  errno = olderr;\n  return ptr;\n}\n\n#endif\n\n#define INIT_MMAP()\t\t((void)0)\n#define DIRECT_MMAP(s)\t\tCALL_MMAP(s)\n\nstatic LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)\n{\n  int olderr = errno;\n  int ret = munmap(ptr, size);\n  errno = olderr;\n  return ret;\n}\n\n#if LJ_TARGET_LINUX\n/* Need to define _GNU_SOURCE to get the mremap prototype. */\nstatic LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz,\n\t\t\t\t     int flags)\n{\n  int olderr = errno;\n  ptr = mremap(ptr, osz, nsz, flags);\n  errno = olderr;\n  return ptr;\n}\n\n#define CALL_MREMAP(addr, osz, nsz, mv) CALL_MREMAP_((addr), (osz), (nsz), (mv))\n#define CALL_MREMAP_NOMOVE\t0\n#define CALL_MREMAP_MAYMOVE\t1\n#if LJ_64 && !LJ_GC64\n#define CALL_MREMAP_MV\t\tCALL_MREMAP_NOMOVE\n#else\n#define CALL_MREMAP_MV\t\tCALL_MREMAP_MAYMOVE\n#endif\n#endif\n\n#endif\n\n#ifndef CALL_MREMAP\n#define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL)\n#endif\n\n/* -----------------------  Chunk representations ------------------------ */\n\nstruct malloc_chunk {\n  size_t               prev_foot;  /* Size of previous chunk (if free).  */\n  size_t               head;       /* Size and inuse bits. */\n  struct malloc_chunk *fd;         /* double links -- used only if free. */\n  struct malloc_chunk *bk;\n};\n\ntypedef struct malloc_chunk  mchunk;\ntypedef struct malloc_chunk *mchunkptr;\ntypedef struct malloc_chunk *sbinptr;  /* The type of bins of chunks */\ntypedef size_t bindex_t;               /* Described below */\ntypedef unsigned int binmap_t;         /* Described below */\ntypedef unsigned int flag_t;           /* The type of various bit flag sets */\n\n/* ------------------- Chunks sizes and alignments ----------------------- */\n\n#define MCHUNK_SIZE\t\t(sizeof(mchunk))\n\n#define CHUNK_OVERHEAD\t\t(SIZE_T_SIZE)\n\n/* Direct chunks need a second word of overhead ... */\n#define DIRECT_CHUNK_OVERHEAD\t(TWO_SIZE_T_SIZES)\n/* ... and additional padding for fake next-chunk at foot */\n#define DIRECT_FOOT_PAD\t\t(FOUR_SIZE_T_SIZES)\n\n/* The smallest size we can malloc is an aligned minimal chunk */\n#define MIN_CHUNK_SIZE\\\n  ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)\n\n/* conversion from malloc headers to user pointers, and back */\n#define chunk2mem(p)\t\t((void *)((char *)(p) + TWO_SIZE_T_SIZES))\n#define mem2chunk(mem)\t\t((mchunkptr)((char *)(mem) - TWO_SIZE_T_SIZES))\n/* chunk associated with aligned address A */\n#define align_as_chunk(A)\t(mchunkptr)((A) + align_offset(chunk2mem(A)))\n\n/* Bounds on request (not chunk) sizes. */\n#define MAX_REQUEST\t\t((~MIN_CHUNK_SIZE+1) << 2)\n#define MIN_REQUEST\t\t(MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)\n\n/* pad request bytes into a usable size */\n#define pad_request(req) \\\n   (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)\n\n/* pad request, checking for minimum (but not maximum) */\n#define request2size(req) \\\n  (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))\n\n/* ------------------ Operations on head and foot fields ----------------- */\n\n#define PINUSE_BIT\t\t(SIZE_T_ONE)\n#define CINUSE_BIT\t\t(SIZE_T_TWO)\n#define INUSE_BITS\t\t(PINUSE_BIT|CINUSE_BIT)\n\n/* Head value for fenceposts */\n#define FENCEPOST_HEAD\t\t(INUSE_BITS|SIZE_T_SIZE)\n\n/* extraction of fields from head words */\n#define cinuse(p)\t\t((p)->head & CINUSE_BIT)\n#define pinuse(p)\t\t((p)->head & PINUSE_BIT)\n#define chunksize(p)\t\t((p)->head & ~(INUSE_BITS))\n\n#define clear_pinuse(p)\t\t((p)->head &= ~PINUSE_BIT)\n#define clear_cinuse(p)\t\t((p)->head &= ~CINUSE_BIT)\n\n/* Treat space at ptr +/- offset as a chunk */\n#define chunk_plus_offset(p, s)\t\t((mchunkptr)(((char *)(p)) + (s)))\n#define chunk_minus_offset(p, s)\t((mchunkptr)(((char *)(p)) - (s)))\n\n/* Ptr to next or previous physical malloc_chunk. */\n#define next_chunk(p)\t((mchunkptr)(((char *)(p)) + ((p)->head & ~INUSE_BITS)))\n#define prev_chunk(p)\t((mchunkptr)(((char *)(p)) - ((p)->prev_foot) ))\n\n/* extract next chunk's pinuse bit */\n#define next_pinuse(p)\t((next_chunk(p)->head) & PINUSE_BIT)\n\n/* Get/set size at footer */\n#define get_foot(p, s)\t(((mchunkptr)((char *)(p) + (s)))->prev_foot)\n#define set_foot(p, s)\t(((mchunkptr)((char *)(p) + (s)))->prev_foot = (s))\n\n/* Set size, pinuse bit, and foot */\n#define set_size_and_pinuse_of_free_chunk(p, s)\\\n  ((p)->head = (s|PINUSE_BIT), set_foot(p, s))\n\n/* Set size, pinuse bit, foot, and clear next pinuse */\n#define set_free_with_pinuse(p, s, n)\\\n  (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))\n\n#define is_direct(p)\\\n  (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_DIRECT_BIT))\n\n/* Get the internal overhead associated with chunk p */\n#define overhead_for(p)\\\n (is_direct(p)? DIRECT_CHUNK_OVERHEAD : CHUNK_OVERHEAD)\n\n/* ---------------------- Overlaid data structures ----------------------- */\n\nstruct malloc_tree_chunk {\n  /* The first four fields must be compatible with malloc_chunk */\n  size_t                    prev_foot;\n  size_t                    head;\n  struct malloc_tree_chunk *fd;\n  struct malloc_tree_chunk *bk;\n\n  struct malloc_tree_chunk *child[2];\n  struct malloc_tree_chunk *parent;\n  bindex_t                  index;\n};\n\ntypedef struct malloc_tree_chunk  tchunk;\ntypedef struct malloc_tree_chunk *tchunkptr;\ntypedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */\n\n/* A little helper macro for trees */\n#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])\n\n/* ----------------------------- Segments -------------------------------- */\n\nstruct malloc_segment {\n  char        *base;             /* base address */\n  size_t       size;             /* allocated size */\n  struct malloc_segment *next;   /* ptr to next segment */\n};\n\ntypedef struct malloc_segment  msegment;\ntypedef struct malloc_segment *msegmentptr;\n\n/* ---------------------------- malloc_state ----------------------------- */\n\n/* Bin types, widths and sizes */\n#define NSMALLBINS\t\t(32U)\n#define NTREEBINS\t\t(32U)\n#define SMALLBIN_SHIFT\t\t(3U)\n#define SMALLBIN_WIDTH\t\t(SIZE_T_ONE << SMALLBIN_SHIFT)\n#define TREEBIN_SHIFT\t\t(8U)\n#define MIN_LARGE_SIZE\t\t(SIZE_T_ONE << TREEBIN_SHIFT)\n#define MAX_SMALL_SIZE\t\t(MIN_LARGE_SIZE - SIZE_T_ONE)\n#define MAX_SMALL_REQUEST  (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)\n\nstruct malloc_state {\n  binmap_t   smallmap;\n  binmap_t   treemap;\n  size_t     dvsize;\n  size_t     topsize;\n  mchunkptr  dv;\n  mchunkptr  top;\n  size_t     trim_check;\n  size_t     release_checks;\n  mchunkptr  smallbins[(NSMALLBINS+1)*2];\n  tbinptr    treebins[NTREEBINS];\n  msegment   seg;\n};\n\ntypedef struct malloc_state *mstate;\n\n#define is_initialized(M)\t((M)->top != 0)\n\n/* -------------------------- system alloc setup ------------------------- */\n\n/* page-align a size */\n#define page_align(S)\\\n (((S) + (LJ_PAGESIZE - SIZE_T_ONE)) & ~(LJ_PAGESIZE - SIZE_T_ONE))\n\n/* granularity-align a size */\n#define granularity_align(S)\\\n  (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\\\n   & ~(DEFAULT_GRANULARITY - SIZE_T_ONE))\n\n#if LJ_TARGET_WINDOWS\n#define mmap_align(S)\tgranularity_align(S)\n#else\n#define mmap_align(S)\tpage_align(S)\n#endif\n\n/*  True if segment S holds address A */\n#define segment_holds(S, A)\\\n  ((char *)(A) >= S->base && (char *)(A) < S->base + S->size)\n\n/* Return segment holding given address */\nstatic msegmentptr segment_holding(mstate m, char *addr)\n{\n  msegmentptr sp = &m->seg;\n  for (;;) {\n    if (addr >= sp->base && addr < sp->base + sp->size)\n      return sp;\n    if ((sp = sp->next) == 0)\n      return 0;\n  }\n}\n\n/* Return true if segment contains a segment link */\nstatic int has_segment_link(mstate m, msegmentptr ss)\n{\n  msegmentptr sp = &m->seg;\n  for (;;) {\n    if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size)\n      return 1;\n    if ((sp = sp->next) == 0)\n      return 0;\n  }\n}\n\n/*\n  TOP_FOOT_SIZE is padding at the end of a segment, including space\n  that may be needed to place segment records and fenceposts when new\n  noncontiguous segments are added.\n*/\n#define TOP_FOOT_SIZE\\\n  (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)\n\n/* ---------------------------- Indexing Bins ---------------------------- */\n\n#define is_small(s)\t\t(((s) >> SMALLBIN_SHIFT) < NSMALLBINS)\n#define small_index(s)\t\t((s)  >> SMALLBIN_SHIFT)\n#define small_index2size(i)\t((i)  << SMALLBIN_SHIFT)\n#define MIN_SMALL_INDEX\t\t(small_index(MIN_CHUNK_SIZE))\n\n/* addressing by index. See above about smallbin repositioning */\n#define smallbin_at(M, i)\t((sbinptr)((char *)&((M)->smallbins[(i)<<1])))\n#define treebin_at(M,i)\t\t(&((M)->treebins[i]))\n\n/* assign tree index for size S to variable I */\n#define compute_tree_index(S, I)\\\n{\\\n  unsigned int X = (unsigned int)(S >> TREEBIN_SHIFT);\\\n  if (X == 0) {\\\n    I = 0;\\\n  } else if (X > 0xFFFF) {\\\n    I = NTREEBINS-1;\\\n  } else {\\\n    unsigned int K = lj_fls(X);\\\n    I =  (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\\\n  }\\\n}\n\n/* Bit representing maximum resolved size in a treebin at i */\n#define bit_for_tree_index(i) \\\n   (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)\n\n/* Shift placing maximum resolved bit in a treebin at i as sign bit */\n#define leftshift_for_tree_index(i) \\\n   ((i == NTREEBINS-1)? 0 : \\\n    ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))\n\n/* The size of the smallest chunk held in bin with index i */\n#define minsize_for_tree_index(i) \\\n   ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) |  \\\n   (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))\n\n/* ------------------------ Operations on bin maps ----------------------- */\n\n/* bit corresponding to given index */\n#define idx2bit(i)\t\t((binmap_t)(1) << (i))\n\n/* Mark/Clear bits with given index */\n#define mark_smallmap(M,i)\t((M)->smallmap |=  idx2bit(i))\n#define clear_smallmap(M,i)\t((M)->smallmap &= ~idx2bit(i))\n#define smallmap_is_marked(M,i)\t((M)->smallmap &   idx2bit(i))\n\n#define mark_treemap(M,i)\t((M)->treemap  |=  idx2bit(i))\n#define clear_treemap(M,i)\t((M)->treemap  &= ~idx2bit(i))\n#define treemap_is_marked(M,i)\t((M)->treemap  &   idx2bit(i))\n\n/* mask with all bits to left of least bit of x on */\n#define left_bits(x)\t\t((x<<1) | (~(x<<1)+1))\n\n/* Set cinuse bit and pinuse bit of next chunk */\n#define set_inuse(M,p,s)\\\n  ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\\\n  ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)\n\n/* Set cinuse and pinuse of this chunk and pinuse of next chunk */\n#define set_inuse_and_pinuse(M,p,s)\\\n  ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\\\n  ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)\n\n/* Set size, cinuse and pinuse bit of this chunk */\n#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\\\n  ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))\n\n/* ----------------------- Operations on smallbins ----------------------- */\n\n/* Link a free chunk into a smallbin  */\n#define insert_small_chunk(M, P, S) {\\\n  bindex_t I = small_index(S);\\\n  mchunkptr B = smallbin_at(M, I);\\\n  mchunkptr F = B;\\\n  if (!smallmap_is_marked(M, I))\\\n    mark_smallmap(M, I);\\\n  else\\\n    F = B->fd;\\\n  B->fd = P;\\\n  F->bk = P;\\\n  P->fd = F;\\\n  P->bk = B;\\\n}\n\n/* Unlink a chunk from a smallbin  */\n#define unlink_small_chunk(M, P, S) {\\\n  mchunkptr F = P->fd;\\\n  mchunkptr B = P->bk;\\\n  bindex_t I = small_index(S);\\\n  if (F == B) {\\\n    clear_smallmap(M, I);\\\n  } else {\\\n    F->bk = B;\\\n    B->fd = F;\\\n  }\\\n}\n\n/* Unlink the first chunk from a smallbin */\n#define unlink_first_small_chunk(M, B, P, I) {\\\n  mchunkptr F = P->fd;\\\n  if (B == F) {\\\n    clear_smallmap(M, I);\\\n  } else {\\\n    B->fd = F;\\\n    F->bk = B;\\\n  }\\\n}\n\n/* Replace dv node, binning the old one */\n/* Used only when dvsize known to be small */\n#define replace_dv(M, P, S) {\\\n  size_t DVS = M->dvsize;\\\n  if (DVS != 0) {\\\n    mchunkptr DV = M->dv;\\\n    insert_small_chunk(M, DV, DVS);\\\n  }\\\n  M->dvsize = S;\\\n  M->dv = P;\\\n}\n\n/* ------------------------- Operations on trees ------------------------- */\n\n/* Insert chunk into tree */\n#define insert_large_chunk(M, X, S) {\\\n  tbinptr *H;\\\n  bindex_t I;\\\n  compute_tree_index(S, I);\\\n  H = treebin_at(M, I);\\\n  X->index = I;\\\n  X->child[0] = X->child[1] = 0;\\\n  if (!treemap_is_marked(M, I)) {\\\n    mark_treemap(M, I);\\\n    *H = X;\\\n    X->parent = (tchunkptr)H;\\\n    X->fd = X->bk = X;\\\n  } else {\\\n    tchunkptr T = *H;\\\n    size_t K = S << leftshift_for_tree_index(I);\\\n    for (;;) {\\\n      if (chunksize(T) != S) {\\\n\ttchunkptr *C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\\\n\tK <<= 1;\\\n\tif (*C != 0) {\\\n\t  T = *C;\\\n\t} else {\\\n\t  *C = X;\\\n\t  X->parent = T;\\\n\t  X->fd = X->bk = X;\\\n\t  break;\\\n\t}\\\n      } else {\\\n\ttchunkptr F = T->fd;\\\n\tT->fd = F->bk = X;\\\n\tX->fd = F;\\\n\tX->bk = T;\\\n\tX->parent = 0;\\\n\tbreak;\\\n      }\\\n    }\\\n  }\\\n}\n\n#define unlink_large_chunk(M, X) {\\\n  tchunkptr XP = X->parent;\\\n  tchunkptr R;\\\n  if (X->bk != X) {\\\n    tchunkptr F = X->fd;\\\n    R = X->bk;\\\n    F->bk = R;\\\n    R->fd = F;\\\n  } else {\\\n    tchunkptr *RP;\\\n    if (((R = *(RP = &(X->child[1]))) != 0) ||\\\n\t((R = *(RP = &(X->child[0]))) != 0)) {\\\n      tchunkptr *CP;\\\n      while ((*(CP = &(R->child[1])) != 0) ||\\\n\t     (*(CP = &(R->child[0])) != 0)) {\\\n\tR = *(RP = CP);\\\n      }\\\n      *RP = 0;\\\n    }\\\n  }\\\n  if (XP != 0) {\\\n    tbinptr *H = treebin_at(M, X->index);\\\n    if (X == *H) {\\\n      if ((*H = R) == 0) \\\n\tclear_treemap(M, X->index);\\\n    } else {\\\n      if (XP->child[0] == X) \\\n\tXP->child[0] = R;\\\n      else \\\n\tXP->child[1] = R;\\\n    }\\\n    if (R != 0) {\\\n      tchunkptr C0, C1;\\\n      R->parent = XP;\\\n      if ((C0 = X->child[0]) != 0) {\\\n\tR->child[0] = C0;\\\n\tC0->parent = R;\\\n      }\\\n      if ((C1 = X->child[1]) != 0) {\\\n\tR->child[1] = C1;\\\n\tC1->parent = R;\\\n      }\\\n    }\\\n  }\\\n}\n\n/* Relays to large vs small bin operations */\n\n#define insert_chunk(M, P, S)\\\n  if (is_small(S)) { insert_small_chunk(M, P, S)\\\n  } else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }\n\n#define unlink_chunk(M, P, S)\\\n  if (is_small(S)) { unlink_small_chunk(M, P, S)\\\n  } else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }\n\n/* -----------------------  Direct-mmapping chunks ----------------------- */\n\nstatic void *direct_alloc(size_t nb)\n{\n  size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n  if (LJ_LIKELY(mmsize > nb)) {     /* Check for wrap around 0 */\n    char *mm = (char *)(DIRECT_MMAP(mmsize));\n    if (mm != CMFAIL) {\n      size_t offset = align_offset(chunk2mem(mm));\n      size_t psize = mmsize - offset - DIRECT_FOOT_PAD;\n      mchunkptr p = (mchunkptr)(mm + offset);\n      p->prev_foot = offset | IS_DIRECT_BIT;\n      p->head = psize|CINUSE_BIT;\n      chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;\n      chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;\n      return chunk2mem(p);\n    }\n  }\n  return NULL;\n}\n\nstatic mchunkptr direct_resize(mchunkptr oldp, size_t nb)\n{\n  size_t oldsize = chunksize(oldp);\n  if (is_small(nb)) /* Can't shrink direct regions below small size */\n    return NULL;\n  /* Keep old chunk if big enough but not too big */\n  if (oldsize >= nb + SIZE_T_SIZE &&\n      (oldsize - nb) <= (DEFAULT_GRANULARITY >> 1)) {\n    return oldp;\n  } else {\n    size_t offset = oldp->prev_foot & ~IS_DIRECT_BIT;\n    size_t oldmmsize = oldsize + offset + DIRECT_FOOT_PAD;\n    size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n    char *cp = (char *)CALL_MREMAP((char *)oldp - offset,\n\t\t\t\t   oldmmsize, newmmsize, CALL_MREMAP_MV);\n    if (cp != CMFAIL) {\n      mchunkptr newp = (mchunkptr)(cp + offset);\n      size_t psize = newmmsize - offset - DIRECT_FOOT_PAD;\n      newp->head = psize|CINUSE_BIT;\n      chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;\n      chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0;\n      return newp;\n    }\n  }\n  return NULL;\n}\n\n/* -------------------------- mspace management -------------------------- */\n\n/* Initialize top chunk and its size */\nstatic void init_top(mstate m, mchunkptr p, size_t psize)\n{\n  /* Ensure alignment */\n  size_t offset = align_offset(chunk2mem(p));\n  p = (mchunkptr)((char *)p + offset);\n  psize -= offset;\n\n  m->top = p;\n  m->topsize = psize;\n  p->head = psize | PINUSE_BIT;\n  /* set size of fake trailing chunk holding overhead space only once */\n  chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;\n  m->trim_check = DEFAULT_TRIM_THRESHOLD; /* reset on each update */\n}\n\n/* Initialize bins for a new mstate that is otherwise zeroed out */\nstatic void init_bins(mstate m)\n{\n  /* Establish circular links for smallbins */\n  bindex_t i;\n  for (i = 0; i < NSMALLBINS; i++) {\n    sbinptr bin = smallbin_at(m,i);\n    bin->fd = bin->bk = bin;\n  }\n}\n\n/* Allocate chunk and prepend remainder with chunk in successor base. */\nstatic void *prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)\n{\n  mchunkptr p = align_as_chunk(newbase);\n  mchunkptr oldfirst = align_as_chunk(oldbase);\n  size_t psize = (size_t)((char *)oldfirst - (char *)p);\n  mchunkptr q = chunk_plus_offset(p, nb);\n  size_t qsize = psize - nb;\n  set_size_and_pinuse_of_inuse_chunk(m, p, nb);\n\n  /* consolidate remainder with first chunk of old base */\n  if (oldfirst == m->top) {\n    size_t tsize = m->topsize += qsize;\n    m->top = q;\n    q->head = tsize | PINUSE_BIT;\n  } else if (oldfirst == m->dv) {\n    size_t dsize = m->dvsize += qsize;\n    m->dv = q;\n    set_size_and_pinuse_of_free_chunk(q, dsize);\n  } else {\n    if (!cinuse(oldfirst)) {\n      size_t nsize = chunksize(oldfirst);\n      unlink_chunk(m, oldfirst, nsize);\n      oldfirst = chunk_plus_offset(oldfirst, nsize);\n      qsize += nsize;\n    }\n    set_free_with_pinuse(q, qsize, oldfirst);\n    insert_chunk(m, q, qsize);\n  }\n\n  return chunk2mem(p);\n}\n\n/* Add a segment to hold a new noncontiguous region */\nstatic void add_segment(mstate m, char *tbase, size_t tsize)\n{\n  /* Determine locations and sizes of segment, fenceposts, old top */\n  char *old_top = (char *)m->top;\n  msegmentptr oldsp = segment_holding(m, old_top);\n  char *old_end = oldsp->base + oldsp->size;\n  size_t ssize = pad_request(sizeof(struct malloc_segment));\n  char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n  size_t offset = align_offset(chunk2mem(rawsp));\n  char *asp = rawsp + offset;\n  char *csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp;\n  mchunkptr sp = (mchunkptr)csp;\n  msegmentptr ss = (msegmentptr)(chunk2mem(sp));\n  mchunkptr tnext = chunk_plus_offset(sp, ssize);\n  mchunkptr p = tnext;\n\n  /* reset top to new space */\n  init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);\n\n  /* Set up segment record */\n  set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);\n  *ss = m->seg; /* Push current record */\n  m->seg.base = tbase;\n  m->seg.size = tsize;\n  m->seg.next = ss;\n\n  /* Insert trailing fenceposts */\n  for (;;) {\n    mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);\n    p->head = FENCEPOST_HEAD;\n    if ((char *)(&(nextp->head)) < old_end)\n      p = nextp;\n    else\n      break;\n  }\n\n  /* Insert the rest of old top into a bin as an ordinary free chunk */\n  if (csp != old_top) {\n    mchunkptr q = (mchunkptr)old_top;\n    size_t psize = (size_t)(csp - old_top);\n    mchunkptr tn = chunk_plus_offset(q, psize);\n    set_free_with_pinuse(q, psize, tn);\n    insert_chunk(m, q, psize);\n  }\n}\n\n/* -------------------------- System allocation -------------------------- */\n\nstatic void *alloc_sys(mstate m, size_t nb)\n{\n  char *tbase = CMFAIL;\n  size_t tsize = 0;\n\n  /* Directly map large chunks */\n  if (LJ_UNLIKELY(nb >= DEFAULT_MMAP_THRESHOLD)) {\n    void *mem = direct_alloc(nb);\n    if (mem != 0)\n      return mem;\n  }\n\n  {\n    size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;\n    size_t rsize = granularity_align(req);\n    if (LJ_LIKELY(rsize > nb)) { /* Fail if wraps around zero */\n      char *mp = (char *)(CALL_MMAP(rsize));\n      if (mp != CMFAIL) {\n\ttbase = mp;\n\ttsize = rsize;\n      }\n    }\n  }\n\n  if (tbase != CMFAIL) {\n    msegmentptr sp = &m->seg;\n    /* Try to merge with an existing segment */\n    while (sp != 0 && tbase != sp->base + sp->size)\n      sp = sp->next;\n    if (sp != 0 && segment_holds(sp, m->top)) { /* append */\n      sp->size += tsize;\n      init_top(m, m->top, m->topsize + tsize);\n    } else {\n      sp = &m->seg;\n      while (sp != 0 && sp->base != tbase + tsize)\n\tsp = sp->next;\n      if (sp != 0) {\n\tchar *oldbase = sp->base;\n\tsp->base = tbase;\n\tsp->size += tsize;\n\treturn prepend_alloc(m, tbase, oldbase, nb);\n      } else {\n\tadd_segment(m, tbase, tsize);\n      }\n    }\n\n    if (nb < m->topsize) { /* Allocate from new or extended top space */\n      size_t rsize = m->topsize -= nb;\n      mchunkptr p = m->top;\n      mchunkptr r = m->top = chunk_plus_offset(p, nb);\n      r->head = rsize | PINUSE_BIT;\n      set_size_and_pinuse_of_inuse_chunk(m, p, nb);\n      return chunk2mem(p);\n    }\n  }\n\n  return NULL;\n}\n\n/* -----------------------  system deallocation -------------------------- */\n\n/* Unmap and unlink any mmapped segments that don't contain used chunks */\nstatic size_t release_unused_segments(mstate m)\n{\n  size_t released = 0;\n  size_t nsegs = 0;\n  msegmentptr pred = &m->seg;\n  msegmentptr sp = pred->next;\n  while (sp != 0) {\n    char *base = sp->base;\n    size_t size = sp->size;\n    msegmentptr next = sp->next;\n    nsegs++;\n    {\n      mchunkptr p = align_as_chunk(base);\n      size_t psize = chunksize(p);\n      /* Can unmap if first chunk holds entire segment and not pinned */\n      if (!cinuse(p) && (char *)p + psize >= base + size - TOP_FOOT_SIZE) {\n\ttchunkptr tp = (tchunkptr)p;\n\tif (p == m->dv) {\n\t  m->dv = 0;\n\t  m->dvsize = 0;\n\t} else {\n\t  unlink_large_chunk(m, tp);\n\t}\n\tif (CALL_MUNMAP(base, size) == 0) {\n\t  released += size;\n\t  /* unlink obsoleted record */\n\t  sp = pred;\n\t  sp->next = next;\n\t} else { /* back out if cannot unmap */\n\t  insert_large_chunk(m, tp, psize);\n\t}\n      }\n    }\n    pred = sp;\n    sp = next;\n  }\n  /* Reset check counter */\n  m->release_checks = nsegs > MAX_RELEASE_CHECK_RATE ?\n\t\t      nsegs : MAX_RELEASE_CHECK_RATE;\n  return released;\n}\n\nstatic int alloc_trim(mstate m, size_t pad)\n{\n  size_t released = 0;\n  if (pad < MAX_REQUEST && is_initialized(m)) {\n    pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */\n\n    if (m->topsize > pad) {\n      /* Shrink top space in granularity-size units, keeping at least one */\n      size_t unit = DEFAULT_GRANULARITY;\n      size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -\n\t\t      SIZE_T_ONE) * unit;\n      msegmentptr sp = segment_holding(m, (char *)m->top);\n\n      if (sp->size >= extra &&\n\t  !has_segment_link(m, sp)) { /* can't shrink if pinned */\n\tsize_t newsize = sp->size - extra;\n\t/* Prefer mremap, fall back to munmap */\n\tif ((CALL_MREMAP(sp->base, sp->size, newsize, CALL_MREMAP_NOMOVE) != MFAIL) ||\n\t    (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {\n\t  released = extra;\n\t}\n      }\n\n      if (released != 0) {\n\tsp->size -= released;\n\tinit_top(m, m->top, m->topsize - released);\n      }\n    }\n\n    /* Unmap any unused mmapped segments */\n    released += release_unused_segments(m);\n\n    /* On failure, disable autotrim to avoid repeated failed future calls */\n    if (released == 0 && m->topsize > m->trim_check)\n      m->trim_check = MAX_SIZE_T;\n  }\n\n  return (released != 0)? 1 : 0;\n}\n\n/* ---------------------------- malloc support --------------------------- */\n\n/* allocate a large request from the best fitting chunk in a treebin */\nstatic void *tmalloc_large(mstate m, size_t nb)\n{\n  tchunkptr v = 0;\n  size_t rsize = ~nb+1; /* Unsigned negation */\n  tchunkptr t;\n  bindex_t idx;\n  compute_tree_index(nb, idx);\n\n  if ((t = *treebin_at(m, idx)) != 0) {\n    /* Traverse tree for this bin looking for node with size == nb */\n    size_t sizebits = nb << leftshift_for_tree_index(idx);\n    tchunkptr rst = 0;  /* The deepest untaken right subtree */\n    for (;;) {\n      tchunkptr rt;\n      size_t trem = chunksize(t) - nb;\n      if (trem < rsize) {\n\tv = t;\n\tif ((rsize = trem) == 0)\n\t  break;\n      }\n      rt = t->child[1];\n      t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];\n      if (rt != 0 && rt != t)\n\trst = rt;\n      if (t == 0) {\n\tt = rst; /* set t to least subtree holding sizes > nb */\n\tbreak;\n      }\n      sizebits <<= 1;\n    }\n  }\n\n  if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */\n    binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;\n    if (leftbits != 0)\n      t = *treebin_at(m, lj_ffs(leftbits));\n  }\n\n  while (t != 0) { /* find smallest of tree or subtree */\n    size_t trem = chunksize(t) - nb;\n    if (trem < rsize) {\n      rsize = trem;\n      v = t;\n    }\n    t = leftmost_child(t);\n  }\n\n  /*  If dv is a better fit, return NULL so malloc will use it */\n  if (v != 0 && rsize < (size_t)(m->dvsize - nb)) {\n    mchunkptr r = chunk_plus_offset(v, nb);\n    unlink_large_chunk(m, v);\n    if (rsize < MIN_CHUNK_SIZE) {\n      set_inuse_and_pinuse(m, v, (rsize + nb));\n    } else {\n      set_size_and_pinuse_of_inuse_chunk(m, v, nb);\n      set_size_and_pinuse_of_free_chunk(r, rsize);\n      insert_chunk(m, r, rsize);\n    }\n    return chunk2mem(v);\n  }\n  return NULL;\n}\n\n/* allocate a small request from the best fitting chunk in a treebin */\nstatic void *tmalloc_small(mstate m, size_t nb)\n{\n  tchunkptr t, v;\n  mchunkptr r;\n  size_t rsize;\n  bindex_t i = lj_ffs(m->treemap);\n\n  v = t = *treebin_at(m, i);\n  rsize = chunksize(t) - nb;\n\n  while ((t = leftmost_child(t)) != 0) {\n    size_t trem = chunksize(t) - nb;\n    if (trem < rsize) {\n      rsize = trem;\n      v = t;\n    }\n  }\n\n  r = chunk_plus_offset(v, nb);\n  unlink_large_chunk(m, v);\n  if (rsize < MIN_CHUNK_SIZE) {\n    set_inuse_and_pinuse(m, v, (rsize + nb));\n  } else {\n    set_size_and_pinuse_of_inuse_chunk(m, v, nb);\n    set_size_and_pinuse_of_free_chunk(r, rsize);\n    replace_dv(m, r, rsize);\n  }\n  return chunk2mem(v);\n}\n\n/* ----------------------------------------------------------------------- */\n\nvoid *lj_alloc_create(void)\n{\n  size_t tsize = DEFAULT_GRANULARITY;\n  char *tbase;\n  INIT_MMAP();\n  tbase = (char *)(CALL_MMAP(tsize));\n  if (tbase != CMFAIL) {\n    size_t msize = pad_request(sizeof(struct malloc_state));\n    mchunkptr mn;\n    mchunkptr msp = align_as_chunk(tbase);\n    mstate m = (mstate)(chunk2mem(msp));\n    memset(m, 0, msize);\n    msp->head = (msize|PINUSE_BIT|CINUSE_BIT);\n    m->seg.base = tbase;\n    m->seg.size = tsize;\n    m->release_checks = MAX_RELEASE_CHECK_RATE;\n    init_bins(m);\n    mn = next_chunk(mem2chunk(m));\n    init_top(m, mn, (size_t)((tbase + tsize) - (char *)mn) - TOP_FOOT_SIZE);\n    return m;\n  }\n  return NULL;\n}\n\nvoid lj_alloc_destroy(void *msp)\n{\n  mstate ms = (mstate)msp;\n  msegmentptr sp = &ms->seg;\n  while (sp != 0) {\n    char *base = sp->base;\n    size_t size = sp->size;\n    sp = sp->next;\n    CALL_MUNMAP(base, size);\n  }\n}\n\nstatic LJ_NOINLINE void *lj_alloc_malloc(void *msp, size_t nsize)\n{\n  mstate ms = (mstate)msp;\n  void *mem;\n  size_t nb;\n  if (nsize <= MAX_SMALL_REQUEST) {\n    bindex_t idx;\n    binmap_t smallbits;\n    nb = (nsize < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(nsize);\n    idx = small_index(nb);\n    smallbits = ms->smallmap >> idx;\n\n    if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */\n      mchunkptr b, p;\n      idx += ~smallbits & 1;       /* Uses next bin if idx empty */\n      b = smallbin_at(ms, idx);\n      p = b->fd;\n      unlink_first_small_chunk(ms, b, p, idx);\n      set_inuse_and_pinuse(ms, p, small_index2size(idx));\n      mem = chunk2mem(p);\n      return mem;\n    } else if (nb > ms->dvsize) {\n      if (smallbits != 0) { /* Use chunk in next nonempty smallbin */\n\tmchunkptr b, p, r;\n\tsize_t rsize;\n\tbinmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx));\n\tbindex_t i = lj_ffs(leftbits);\n\tb = smallbin_at(ms, i);\n\tp = b->fd;\n\tunlink_first_small_chunk(ms, b, p, i);\n\trsize = small_index2size(i) - nb;\n\t/* Fit here cannot be remainderless if 4byte sizes */\n\tif (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) {\n\t  set_inuse_and_pinuse(ms, p, small_index2size(i));\n\t} else {\n\t  set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n\t  r = chunk_plus_offset(p, nb);\n\t  set_size_and_pinuse_of_free_chunk(r, rsize);\n\t  replace_dv(ms, r, rsize);\n\t}\n\tmem = chunk2mem(p);\n\treturn mem;\n      } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) {\n\treturn mem;\n      }\n    }\n  } else if (nsize >= MAX_REQUEST) {\n    nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */\n  } else {\n    nb = pad_request(nsize);\n    if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) {\n      return mem;\n    }\n  }\n\n  if (nb <= ms->dvsize) {\n    size_t rsize = ms->dvsize - nb;\n    mchunkptr p = ms->dv;\n    if (rsize >= MIN_CHUNK_SIZE) { /* split dv */\n      mchunkptr r = ms->dv = chunk_plus_offset(p, nb);\n      ms->dvsize = rsize;\n      set_size_and_pinuse_of_free_chunk(r, rsize);\n      set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n    } else { /* exhaust dv */\n      size_t dvs = ms->dvsize;\n      ms->dvsize = 0;\n      ms->dv = 0;\n      set_inuse_and_pinuse(ms, p, dvs);\n    }\n    mem = chunk2mem(p);\n    return mem;\n  } else if (nb < ms->topsize) { /* Split top */\n    size_t rsize = ms->topsize -= nb;\n    mchunkptr p = ms->top;\n    mchunkptr r = ms->top = chunk_plus_offset(p, nb);\n    r->head = rsize | PINUSE_BIT;\n    set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n    mem = chunk2mem(p);\n    return mem;\n  }\n  return alloc_sys(ms, nb);\n}\n\nstatic LJ_NOINLINE void *lj_alloc_free(void *msp, void *ptr)\n{\n  if (ptr != 0) {\n    mchunkptr p = mem2chunk(ptr);\n    mstate fm = (mstate)msp;\n    size_t psize = chunksize(p);\n    mchunkptr next = chunk_plus_offset(p, psize);\n    if (!pinuse(p)) {\n      size_t prevsize = p->prev_foot;\n      if ((prevsize & IS_DIRECT_BIT) != 0) {\n\tprevsize &= ~IS_DIRECT_BIT;\n\tpsize += prevsize + DIRECT_FOOT_PAD;\n\tCALL_MUNMAP((char *)p - prevsize, psize);\n\treturn NULL;\n      } else {\n\tmchunkptr prev = chunk_minus_offset(p, prevsize);\n\tpsize += prevsize;\n\tp = prev;\n\t/* consolidate backward */\n\tif (p != fm->dv) {\n\t  unlink_chunk(fm, p, prevsize);\n\t} else if ((next->head & INUSE_BITS) == INUSE_BITS) {\n\t  fm->dvsize = psize;\n\t  set_free_with_pinuse(p, psize, next);\n\t  return NULL;\n\t}\n      }\n    }\n    if (!cinuse(next)) {  /* consolidate forward */\n      if (next == fm->top) {\n\tsize_t tsize = fm->topsize += psize;\n\tfm->top = p;\n\tp->head = tsize | PINUSE_BIT;\n\tif (p == fm->dv) {\n\t  fm->dv = 0;\n\t  fm->dvsize = 0;\n\t}\n\tif (tsize > fm->trim_check)\n\t  alloc_trim(fm, 0);\n\treturn NULL;\n      } else if (next == fm->dv) {\n\tsize_t dsize = fm->dvsize += psize;\n\tfm->dv = p;\n\tset_size_and_pinuse_of_free_chunk(p, dsize);\n\treturn NULL;\n      } else {\n\tsize_t nsize = chunksize(next);\n\tpsize += nsize;\n\tunlink_chunk(fm, next, nsize);\n\tset_size_and_pinuse_of_free_chunk(p, psize);\n\tif (p == fm->dv) {\n\t  fm->dvsize = psize;\n\t  return NULL;\n\t}\n      }\n    } else {\n      set_free_with_pinuse(p, psize, next);\n    }\n\n    if (is_small(psize)) {\n      insert_small_chunk(fm, p, psize);\n    } else {\n      tchunkptr tp = (tchunkptr)p;\n      insert_large_chunk(fm, tp, psize);\n      if (--fm->release_checks == 0)\n\trelease_unused_segments(fm);\n    }\n  }\n  return NULL;\n}\n\nstatic LJ_NOINLINE void *lj_alloc_realloc(void *msp, void *ptr, size_t nsize)\n{\n  if (nsize >= MAX_REQUEST) {\n    return NULL;\n  } else {\n    mstate m = (mstate)msp;\n    mchunkptr oldp = mem2chunk(ptr);\n    size_t oldsize = chunksize(oldp);\n    mchunkptr next = chunk_plus_offset(oldp, oldsize);\n    mchunkptr newp = 0;\n    size_t nb = request2size(nsize);\n\n    /* Try to either shrink or extend into top. Else malloc-copy-free */\n    if (is_direct(oldp)) {\n      newp = direct_resize(oldp, nb);  /* this may return NULL. */\n    } else if (oldsize >= nb) { /* already big enough */\n      size_t rsize = oldsize - nb;\n      newp = oldp;\n      if (rsize >= MIN_CHUNK_SIZE) {\n\tmchunkptr rem = chunk_plus_offset(newp, nb);\n\tset_inuse(m, newp, nb);\n\tset_inuse(m, rem, rsize);\n\tlj_alloc_free(m, chunk2mem(rem));\n      }\n    } else if (next == m->top && oldsize + m->topsize > nb) {\n      /* Expand into top */\n      size_t newsize = oldsize + m->topsize;\n      size_t newtopsize = newsize - nb;\n      mchunkptr newtop = chunk_plus_offset(oldp, nb);\n      set_inuse(m, oldp, nb);\n      newtop->head = newtopsize |PINUSE_BIT;\n      m->top = newtop;\n      m->topsize = newtopsize;\n      newp = oldp;\n    }\n\n    if (newp != 0) {\n      return chunk2mem(newp);\n    } else {\n      void *newmem = lj_alloc_malloc(m, nsize);\n      if (newmem != 0) {\n\tsize_t oc = oldsize - overhead_for(oldp);\n\tmemcpy(newmem, ptr, oc < nsize ? oc : nsize);\n\tlj_alloc_free(m, ptr);\n      }\n      return newmem;\n    }\n  }\n}\n\nvoid *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize)\n{\n  (void)osize;\n  if (nsize == 0) {\n    return lj_alloc_free(msp, ptr);\n  } else if (ptr == NULL) {\n    return lj_alloc_malloc(msp, nsize);\n  } else {\n    return lj_alloc_realloc(msp, ptr, nsize);\n  }\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_alloc.h",
    "content": "/*\n** Bundled memory allocator.\n** Donated to the public domain.\n*/\n\n#ifndef _LJ_ALLOC_H\n#define _LJ_ALLOC_H\n\n#include \"lj_def.h\"\n\n#ifndef LUAJIT_USE_SYSMALLOC\nLJ_FUNC void *lj_alloc_create(void);\nLJ_FUNC void lj_alloc_destroy(void *msp);\nLJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_api.c",
    "content": "/*\n** Public Lua/C API.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_api_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_udata.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#include \"lj_frame.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Common helper functions --------------------------------------------- */\n\n#define api_checknelems(L, n)\t\tapi_check(L, (n) <= (L->top - L->base))\n#define api_checkvalidindex(L, i)\tapi_check(L, (i) != niltv(L))\n\nstatic TValue *index2adr(lua_State *L, int idx)\n{\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    return o < L->top ? o : niltv(L);\n  } else if (idx > LUA_REGISTRYINDEX) {\n    api_check(L, idx != 0 && -idx <= L->top - L->base);\n    return L->top + idx;\n  } else if (idx == LUA_GLOBALSINDEX) {\n    TValue *o = &G(L)->tmptv;\n    settabV(L, o, tabref(L->env));\n    return o;\n  } else if (idx == LUA_REGISTRYINDEX) {\n    return registry(L);\n  } else {\n    GCfunc *fn = curr_func(L);\n    api_check(L, fn->c.gct == ~LJ_TFUNC && !isluafunc(fn));\n    if (idx == LUA_ENVIRONINDEX) {\n      TValue *o = &G(L)->tmptv;\n      settabV(L, o, tabref(fn->c.env));\n      return o;\n    } else {\n      idx = LUA_GLOBALSINDEX - idx;\n      return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L);\n    }\n  }\n}\n\nstatic TValue *stkindex2adr(lua_State *L, int idx)\n{\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    return o < L->top ? o : niltv(L);\n  } else {\n    api_check(L, idx != 0 && -idx <= L->top - L->base);\n    return L->top + idx;\n  }\n}\n\nstatic GCtab *getcurrenv(lua_State *L)\n{\n  GCfunc *fn = curr_func(L);\n  return fn->c.gct == ~LJ_TFUNC ? tabref(fn->c.env) : tabref(L->env);\n}\n\n/* -- Miscellaneous API functions ----------------------------------------- */\n\nLUA_API int lua_status(lua_State *L)\n{\n  return L->status;\n}\n\nLUA_API int lua_checkstack(lua_State *L, int size)\n{\n  if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) {\n    return 0;  /* Stack overflow. */\n  } else if (size > 0) {\n    lj_state_checkstack(L, (MSize)size);\n  }\n  return 1;\n}\n\nLUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg)\n{\n  if (!lua_checkstack(L, size))\n    lj_err_callerv(L, LJ_ERR_STKOVM, msg);\n}\n\nLUA_API void lua_xmove(lua_State *from, lua_State *to, int n)\n{\n  TValue *f, *t;\n  if (from == to) return;\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to));\n  lj_state_checkstack(to, (MSize)n);\n  f = from->top;\n  t = to->top = to->top + n;\n  while (--n >= 0) copyTV(to, --t, --f);\n  from->top = f;\n}\n\n/* -- Stack manipulation -------------------------------------------------- */\n\nLUA_API int lua_gettop(lua_State *L)\n{\n  return (int)(L->top - L->base);\n}\n\nLUA_API void lua_settop(lua_State *L, int idx)\n{\n  if (idx >= 0) {\n    api_check(L, idx <= tvref(L->maxstack) - L->base);\n    if (L->base + idx > L->top) {\n      if (L->base + idx >= tvref(L->maxstack))\n\tlj_state_growstack(L, (MSize)idx - (MSize)(L->top - L->base));\n      do { setnilV(L->top++); } while (L->top < L->base + idx);\n    } else {\n      L->top = L->base + idx;\n    }\n  } else {\n    api_check(L, -(idx+1) <= (L->top - L->base));\n    L->top += idx+1;  /* Shrinks top (idx < 0). */\n  }\n}\n\nLUA_API void lua_remove(lua_State *L, int idx)\n{\n  TValue *p = stkindex2adr(L, idx);\n  api_checkvalidindex(L, p);\n  while (++p < L->top) copyTV(L, p-1, p);\n  L->top--;\n}\n\nLUA_API void lua_insert(lua_State *L, int idx)\n{\n  TValue *q, *p = stkindex2adr(L, idx);\n  api_checkvalidindex(L, p);\n  for (q = L->top; q > p; q--) copyTV(L, q, q-1);\n  copyTV(L, p, L->top);\n}\n\nLUA_API void lua_replace(lua_State *L, int idx)\n{\n  api_checknelems(L, 1);\n  if (idx == LUA_GLOBALSINDEX) {\n    api_check(L, tvistab(L->top-1));\n    /* NOBARRIER: A thread (i.e. L) is never black. */\n    setgcref(L->env, obj2gco(tabV(L->top-1)));\n  } else if (idx == LUA_ENVIRONINDEX) {\n    GCfunc *fn = curr_func(L);\n    if (fn->c.gct != ~LJ_TFUNC)\n      lj_err_msg(L, LJ_ERR_NOENV);\n    api_check(L, tvistab(L->top-1));\n    setgcref(fn->c.env, obj2gco(tabV(L->top-1)));\n    lj_gc_barrier(L, fn, L->top-1);\n  } else {\n    TValue *o = index2adr(L, idx);\n    api_checkvalidindex(L, o);\n    copyTV(L, o, L->top-1);\n    if (idx < LUA_GLOBALSINDEX)  /* Need a barrier for upvalues. */\n      lj_gc_barrier(L, curr_func(L), L->top-1);\n  }\n  L->top--;\n}\n\nLUA_API void lua_pushvalue(lua_State *L, int idx)\n{\n  copyTV(L, L->top, index2adr(L, idx));\n  incr_top(L);\n}\n\n/* -- Stack getters ------------------------------------------------------- */\n\nLUA_API int lua_type(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisnumber(o)) {\n    return LUA_TNUMBER;\n#if LJ_64 && !LJ_GC64\n  } else if (tvislightud(o)) {\n    return LUA_TLIGHTUSERDATA;\n#endif\n  } else if (o == niltv(L)) {\n    return LUA_TNONE;\n  } else {  /* Magic internal/external tag conversion. ORDER LJ_T */\n    uint32_t t = ~itype(o);\n#if LJ_64\n    int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u);\n#else\n    int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u);\n#endif\n    lua_assert(tt != LUA_TNIL || tvisnil(o));\n    return tt;\n  }\n}\n\nLUALIB_API void luaL_checktype(lua_State *L, int idx, int tt)\n{\n  if (lua_type(L, idx) != tt)\n    lj_err_argt(L, idx, tt);\n}\n\nLUALIB_API void luaL_checkany(lua_State *L, int idx)\n{\n  if (index2adr(L, idx) == niltv(L))\n    lj_err_arg(L, idx, LJ_ERR_NOVAL);\n}\n\nLUA_API const char *lua_typename(lua_State *L, int t)\n{\n  UNUSED(L);\n  return lj_obj_typename[t+1];\n}\n\nLUA_API int lua_iscfunction(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return tvisfunc(o) && !isluafunc(funcV(o));\n}\n\nLUA_API int lua_isnumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  return (tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), &tmp)));\n}\n\nLUA_API int lua_isstring(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (tvisstr(o) || tvisnumber(o));\n}\n\nLUA_API int lua_isuserdata(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (tvisudata(o) || tvislightud(o));\n}\n\nLUA_API int lua_rawequal(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  return (o1 == niltv(L) || o2 == niltv(L)) ? 0 : lj_obj_equal(o1, o2);\n}\n\nLUA_API int lua_equal(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  if (tvisint(o1) && tvisint(o2)) {\n    return intV(o1) == intV(o2);\n  } else if (tvisnumber(o1) && tvisnumber(o2)) {\n    return numberVnum(o1) == numberVnum(o2);\n  } else if (itype(o1) != itype(o2)) {\n    return 0;\n  } else if (tvispri(o1)) {\n    return o1 != niltv(L) && o2 != niltv(L);\n#if LJ_64 && !LJ_GC64\n  } else if (tvislightud(o1)) {\n    return o1->u64 == o2->u64;\n#endif\n  } else if (gcrefeq(o1->gcr, o2->gcr)) {\n    return 1;\n  } else if (!tvistabud(o1)) {\n    return 0;\n  } else {\n    TValue *base = lj_meta_equal(L, gcV(o1), gcV(o2), 0);\n    if ((uintptr_t)base <= 1) {\n      return (int)(uintptr_t)base;\n    } else {\n      L->top = base+2;\n      lj_vm_call(L, base, 1+1);\n      L->top -= 2+LJ_FR2;\n      return tvistruecond(L->top+1+LJ_FR2);\n    }\n  }\n}\n\nLUA_API int lua_lessthan(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  if (o1 == niltv(L) || o2 == niltv(L)) {\n    return 0;\n  } else if (tvisint(o1) && tvisint(o2)) {\n    return intV(o1) < intV(o2);\n  } else if (tvisnumber(o1) && tvisnumber(o2)) {\n    return numberVnum(o1) < numberVnum(o2);\n  } else {\n    TValue *base = lj_meta_comp(L, o1, o2, 0);\n    if ((uintptr_t)base <= 1) {\n      return (int)(uintptr_t)base;\n    } else {\n      L->top = base+2;\n      lj_vm_call(L, base, 1+1);\n      L->top -= 2+LJ_FR2;\n      return tvistruecond(L->top+1+LJ_FR2);\n    }\n  }\n}\n\nLUA_API lua_Number lua_tonumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp))\n    return numV(&tmp);\n  else\n    return 0;\n}\n\nLUALIB_API lua_Number luaL_checknumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))\n    lj_err_argt(L, idx, LUA_TNUMBER);\n  return numV(&tmp);\n}\n\nLUALIB_API lua_Number luaL_optnumber(lua_State *L, int idx, lua_Number def)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (tvisnil(o))\n    return def;\n  else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))\n    lj_err_argt(L, idx, LUA_TNUMBER);\n  return numV(&tmp);\n}\n\nLUA_API lua_Integer lua_tointeger(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      return 0;\n    if (tvisint(&tmp))\n      return (lua_Integer)intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      lj_err_argt(L, idx, LUA_TNUMBER);\n    if (tvisint(&tmp))\n      return (lua_Integer)intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else if (tvisnil(o)) {\n    return def;\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      lj_err_argt(L, idx, LUA_TNUMBER);\n    if (tvisint(&tmp))\n      return (lua_Integer)intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUA_API int lua_toboolean(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return tvistruecond(o);\n}\n\nLUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    if (len != NULL) *len = 0;\n    return NULL;\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    lj_err_argt(L, idx, LUA_TSTRING);\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API const char *luaL_optlstring(lua_State *L, int idx,\n\t\t\t\t       const char *def, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnil(o)) {\n    if (len != NULL) *len = def ? strlen(def) : 0;\n    return def;\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    lj_err_argt(L, idx, LUA_TSTRING);\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def,\n\t\t\t\tconst char *const lst[])\n{\n  ptrdiff_t i;\n  const char *s = lua_tolstring(L, idx, NULL);\n  if (s == NULL && (s = def) == NULL)\n    lj_err_argt(L, idx, LUA_TSTRING);\n  for (i = 0; lst[i]; i++)\n    if (strcmp(lst[i], s) == 0)\n      return (int)i;\n  lj_err_argv(L, idx, LJ_ERR_INVOPTM, s);\n}\n\nLUA_API size_t lua_objlen(lua_State *L, int idx)\n{\n  TValue *o = index2adr(L, idx);\n  if (tvisstr(o)) {\n    return strV(o)->len;\n  } else if (tvistab(o)) {\n    return (size_t)lj_tab_len(tabV(o));\n  } else if (tvisudata(o)) {\n    return udataV(o)->len;\n  } else if (tvisnumber(o)) {\n    GCstr *s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n    return s->len;\n  } else {\n    return 0;\n  }\n}\n\nLUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisfunc(o)) {\n    BCOp op = bc_op(*mref(funcV(o)->c.pc, BCIns));\n    if (op == BC_FUNCC || op == BC_FUNCCW)\n      return funcV(o)->c.f;\n  }\n  return NULL;\n}\n\nLUA_API void *lua_touserdata(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisudata(o))\n    return uddata(udataV(o));\n  else if (tvislightud(o))\n    return lightudV(o);\n  else\n    return NULL;\n}\n\nLUA_API lua_State *lua_tothread(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (!tvisthread(o)) ? NULL : threadV(o);\n}\n\nLUA_API const void *lua_topointer(lua_State *L, int idx)\n{\n  return lj_obj_ptr(index2adr(L, idx));\n}\n\n/* -- Stack setters (object creation) ------------------------------------- */\n\nLUA_API void lua_pushnil(lua_State *L)\n{\n  setnilV(L->top);\n  incr_top(L);\n}\n\nLUA_API void lua_pushnumber(lua_State *L, lua_Number n)\n{\n  setnumV(L->top, n);\n  if (LJ_UNLIKELY(tvisnan(L->top)))\n    setnanV(L->top);  /* Canonicalize injected NaNs. */\n  incr_top(L);\n}\n\nLUA_API void lua_pushinteger(lua_State *L, lua_Integer n)\n{\n  setintptrV(L->top, n);\n  incr_top(L);\n}\n\nLUA_API void lua_pushlstring(lua_State *L, const char *str, size_t len)\n{\n  GCstr *s;\n  lj_gc_check(L);\n  s = lj_str_new(L, str, len);\n  setstrV(L, L->top, s);\n  incr_top(L);\n}\n\nLUA_API void lua_pushstring(lua_State *L, const char *str)\n{\n  if (str == NULL) {\n    setnilV(L->top);\n  } else {\n    GCstr *s;\n    lj_gc_check(L);\n    s = lj_str_newz(L, str);\n    setstrV(L, L->top, s);\n  }\n  incr_top(L);\n}\n\nLUA_API const char *lua_pushvfstring(lua_State *L, const char *fmt,\n\t\t\t\t     va_list argp)\n{\n  lj_gc_check(L);\n  return lj_strfmt_pushvf(L, fmt, argp);\n}\n\nLUA_API const char *lua_pushfstring(lua_State *L, const char *fmt, ...)\n{\n  const char *ret;\n  va_list argp;\n  lj_gc_check(L);\n  va_start(argp, fmt);\n  ret = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  return ret;\n}\n\nLUA_API void lua_pushcclosure(lua_State *L, lua_CFunction f, int n)\n{\n  GCfunc *fn;\n  lj_gc_check(L);\n  api_checknelems(L, n);\n  fn = lj_func_newC(L, (MSize)n, getcurrenv(L));\n  fn->c.f = f;\n  L->top -= n;\n  while (n--)\n    copyTV(L, &fn->c.upvalue[n], L->top+n);\n  setfuncV(L, L->top, fn);\n  lua_assert(iswhite(obj2gco(fn)));\n  incr_top(L);\n}\n\nLUA_API void lua_pushboolean(lua_State *L, int b)\n{\n  setboolV(L->top, (b != 0));\n  incr_top(L);\n}\n\nLUA_API void lua_pushlightuserdata(lua_State *L, void *p)\n{\n  setlightudV(L->top, checklightudptr(L, p));\n  incr_top(L);\n}\n\nLUA_API void lua_createtable(lua_State *L, int narray, int nrec)\n{\n  lj_gc_check(L);\n  settabV(L, L->top, lj_tab_new_ah(L, narray, nrec));\n  incr_top(L);\n}\n\nLUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)\n{\n  GCtab *regt = tabV(registry(L));\n  TValue *tv = lj_tab_setstr(L, regt, lj_str_newz(L, tname));\n  if (tvisnil(tv)) {\n    GCtab *mt = lj_tab_new(L, 0, 1);\n    settabV(L, tv, mt);\n    settabV(L, L->top++, mt);\n    lj_gc_anybarriert(L, regt);\n    return 1;\n  } else {\n    copyTV(L, L->top++, tv);\n    return 0;\n  }\n}\n\nLUA_API int lua_pushthread(lua_State *L)\n{\n  setthreadV(L, L->top, L);\n  incr_top(L);\n  return (mainthread(G(L)) == L);\n}\n\nLUA_API lua_State *lua_newthread(lua_State *L)\n{\n  lua_State *L1;\n  lj_gc_check(L);\n  L1 = lj_state_new(L);\n  setthreadV(L, L->top, L1);\n  incr_top(L);\n  return L1;\n}\n\nLUA_API void *lua_newuserdata(lua_State *L, size_t size)\n{\n  GCudata *ud;\n  lj_gc_check(L);\n  if (size > LJ_MAX_UDATA)\n    lj_err_msg(L, LJ_ERR_UDATAOV);\n  ud = lj_udata_new(L, (MSize)size, getcurrenv(L));\n  setudataV(L, L->top, ud);\n  incr_top(L);\n  return uddata(ud);\n}\n\nLUA_API void lua_concat(lua_State *L, int n)\n{\n  api_checknelems(L, n);\n  if (n >= 2) {\n    n--;\n    do {\n      TValue *top = lj_meta_cat(L, L->top-1, -n);\n      if (top == NULL) {\n\tL->top -= n;\n\tbreak;\n      }\n      n -= (int)(L->top - top);\n      L->top = top+2;\n      lj_vm_call(L, top, 1+1);\n      L->top -= 1+LJ_FR2;\n      copyTV(L, L->top-1, L->top+LJ_FR2);\n    } while (--n > 0);\n  } else if (n == 0) {  /* Push empty string. */\n    setstrV(L, L->top, &G(L)->strempty);\n    incr_top(L);\n  }\n  /* else n == 1: nothing to do. */\n}\n\n/* -- Object getters ------------------------------------------------------ */\n\nLUA_API void lua_gettable(lua_State *L, int idx)\n{\n  cTValue *v, *t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  v = lj_meta_tget(L, t, L->top-1);\n  if (v == NULL) {\n    L->top += 2;\n    lj_vm_call(L, L->top-2, 1+1);\n    L->top -= 2+LJ_FR2;\n    v = L->top+1+LJ_FR2;\n  }\n  copyTV(L, L->top-1, v);\n}\n\nLUA_API void lua_getfield(lua_State *L, int idx, const char *k)\n{\n  cTValue *v, *t = index2adr(L, idx);\n  TValue key;\n  api_checkvalidindex(L, t);\n  setstrV(L, &key, lj_str_newz(L, k));\n  v = lj_meta_tget(L, t, &key);\n  if (v == NULL) {\n    L->top += 2;\n    lj_vm_call(L, L->top-2, 1+1);\n    L->top -= 2+LJ_FR2;\n    v = L->top+1+LJ_FR2;\n  }\n  copyTV(L, L->top, v);\n  incr_top(L);\n}\n\nLUA_API void lua_rawget(lua_State *L, int idx)\n{\n  cTValue *t = index2adr(L, idx);\n  api_check(L, tvistab(t));\n  copyTV(L, L->top-1, lj_tab_get(L, tabV(t), L->top-1));\n}\n\nLUA_API void lua_rawgeti(lua_State *L, int idx, int n)\n{\n  cTValue *v, *t = index2adr(L, idx);\n  api_check(L, tvistab(t));\n  v = lj_tab_getint(tabV(t), n);\n  if (v) {\n    copyTV(L, L->top, v);\n  } else {\n    setnilV(L->top);\n  }\n  incr_top(L);\n}\n\nLUA_API int lua_getmetatable(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  GCtab *mt = NULL;\n  if (tvistab(o))\n    mt = tabref(tabV(o)->metatable);\n  else if (tvisudata(o))\n    mt = tabref(udataV(o)->metatable);\n  else\n    mt = tabref(basemt_obj(G(L), o));\n  if (mt == NULL)\n    return 0;\n  settabV(L, L->top, mt);\n  incr_top(L);\n  return 1;\n}\n\nLUALIB_API int luaL_getmetafield(lua_State *L, int idx, const char *field)\n{\n  if (lua_getmetatable(L, idx)) {\n    cTValue *tv = lj_tab_getstr(tabV(L->top-1), lj_str_newz(L, field));\n    if (tv && !tvisnil(tv)) {\n      copyTV(L, L->top-1, tv);\n      return 1;\n    }\n    L->top--;\n  }\n  return 0;\n}\n\nLUA_API void lua_getfenv(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  if (tvisfunc(o)) {\n    settabV(L, L->top, tabref(funcV(o)->c.env));\n  } else if (tvisudata(o)) {\n    settabV(L, L->top, tabref(udataV(o)->env));\n  } else if (tvisthread(o)) {\n    settabV(L, L->top, tabref(threadV(o)->env));\n  } else {\n    setnilV(L->top);\n  }\n  incr_top(L);\n}\n\nLUA_API int lua_next(lua_State *L, int idx)\n{\n  cTValue *t = index2adr(L, idx);\n  int more;\n  api_check(L, tvistab(t));\n  more = lj_tab_next(L, tabV(t), L->top-1);\n  if (more) {\n    incr_top(L);  /* Return new key and value slot. */\n  } else {  /* End of traversal. */\n    L->top--;  /* Remove key slot. */\n  }\n  return more;\n}\n\nLUA_API const char *lua_getupvalue(lua_State *L, int idx, int n)\n{\n  TValue *val;\n  const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val);\n  if (name) {\n    copyTV(L, L->top, val);\n    incr_top(L);\n  }\n  return name;\n}\n\nLUA_API void *lua_upvalueid(lua_State *L, int idx, int n)\n{\n  GCfunc *fn = funcV(index2adr(L, idx));\n  n--;\n  api_check(L, (uint32_t)n < fn->l.nupvalues);\n  return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :\n\t\t\t (void *)&fn->c.upvalue[n];\n}\n\nLUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2)\n{\n  GCfunc *fn1 = funcV(index2adr(L, idx1));\n  GCfunc *fn2 = funcV(index2adr(L, idx2));\n  n1--; n2--;\n  api_check(L, isluafunc(fn1) && (uint32_t)n1 < fn1->l.nupvalues);\n  api_check(L, isluafunc(fn2) && (uint32_t)n2 < fn2->l.nupvalues);\n  setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]);\n  lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1]));\n}\n\nLUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisudata(o)) {\n    GCudata *ud = udataV(o);\n    cTValue *tv = lj_tab_getstr(tabV(registry(L)), lj_str_newz(L, tname));\n    if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable))\n      return uddata(ud);\n  }\n  lj_err_argtype(L, idx, tname);\n  return NULL;  /* unreachable */\n}\n\n/* -- Object setters ------------------------------------------------------ */\n\nLUA_API void lua_settable(lua_State *L, int idx)\n{\n  TValue *o;\n  cTValue *t = index2adr(L, idx);\n  api_checknelems(L, 2);\n  api_checkvalidindex(L, t);\n  o = lj_meta_tset(L, t, L->top-2);\n  if (o) {\n    /* NOBARRIER: lj_meta_tset ensures the table is not black. */\n    L->top -= 2;\n    copyTV(L, o, L->top+1);\n  } else {\n    TValue *base = L->top;\n    copyTV(L, base+2, base-3-2*LJ_FR2);\n    L->top = base+3;\n    lj_vm_call(L, base, 0+1);\n    L->top -= 3+LJ_FR2;\n  }\n}\n\nLUA_API void lua_setfield(lua_State *L, int idx, const char *k)\n{\n  TValue *o;\n  TValue key;\n  cTValue *t = index2adr(L, idx);\n  api_checknelems(L, 1);\n  api_checkvalidindex(L, t);\n  setstrV(L, &key, lj_str_newz(L, k));\n  o = lj_meta_tset(L, t, &key);\n  if (o) {\n    /* NOBARRIER: lj_meta_tset ensures the table is not black. */\n    copyTV(L, o, --L->top);\n  } else {\n    TValue *base = L->top;\n    copyTV(L, base+2, base-3-2*LJ_FR2);\n    L->top = base+3;\n    lj_vm_call(L, base, 0+1);\n    L->top -= 2+LJ_FR2;\n  }\n}\n\nLUA_API void lua_rawset(lua_State *L, int idx)\n{\n  GCtab *t = tabV(index2adr(L, idx));\n  TValue *dst, *key;\n  api_checknelems(L, 2);\n  key = L->top-2;\n  dst = lj_tab_set(L, t, key);\n  copyTV(L, dst, key+1);\n  lj_gc_anybarriert(L, t);\n  L->top = key;\n}\n\nLUA_API void lua_rawseti(lua_State *L, int idx, int n)\n{\n  GCtab *t = tabV(index2adr(L, idx));\n  TValue *dst, *src;\n  api_checknelems(L, 1);\n  dst = lj_tab_setint(L, t, n);\n  src = L->top-1;\n  copyTV(L, dst, src);\n  lj_gc_barriert(L, t, dst);\n  L->top = src;\n}\n\nLUA_API int lua_setmetatable(lua_State *L, int idx)\n{\n  global_State *g;\n  GCtab *mt;\n  cTValue *o = index2adr(L, idx);\n  api_checknelems(L, 1);\n  api_checkvalidindex(L, o);\n  if (tvisnil(L->top-1)) {\n    mt = NULL;\n  } else {\n    api_check(L, tvistab(L->top-1));\n    mt = tabV(L->top-1);\n  }\n  g = G(L);\n  if (tvistab(o)) {\n    setgcref(tabV(o)->metatable, obj2gco(mt));\n    if (mt)\n      lj_gc_objbarriert(L, tabV(o), mt);\n  } else if (tvisudata(o)) {\n    setgcref(udataV(o)->metatable, obj2gco(mt));\n    if (mt)\n      lj_gc_objbarrier(L, udataV(o), mt);\n  } else {\n    /* Flush cache, since traces specialize to basemt. But not during __gc. */\n    if (lj_trace_flushall(L))\n      lj_err_caller(L, LJ_ERR_NOGCMM);\n    if (tvisbool(o)) {\n      /* NOBARRIER: basemt is a GC root. */\n      setgcref(basemt_it(g, LJ_TTRUE), obj2gco(mt));\n      setgcref(basemt_it(g, LJ_TFALSE), obj2gco(mt));\n    } else {\n      /* NOBARRIER: basemt is a GC root. */\n      setgcref(basemt_obj(g, o), obj2gco(mt));\n    }\n  }\n  L->top--;\n  return 1;\n}\n\nLUA_API int lua_setfenv(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  GCtab *t;\n  api_checknelems(L, 1);\n  api_checkvalidindex(L, o);\n  api_check(L, tvistab(L->top-1));\n  t = tabV(L->top-1);\n  if (tvisfunc(o)) {\n    setgcref(funcV(o)->c.env, obj2gco(t));\n  } else if (tvisudata(o)) {\n    setgcref(udataV(o)->env, obj2gco(t));\n  } else if (tvisthread(o)) {\n    setgcref(threadV(o)->env, obj2gco(t));\n  } else {\n    L->top--;\n    return 0;\n  }\n  lj_gc_objbarrier(L, gcV(o), t);\n  L->top--;\n  return 1;\n}\n\nLUA_API const char *lua_setupvalue(lua_State *L, int idx, int n)\n{\n  cTValue *f = index2adr(L, idx);\n  TValue *val;\n  const char *name;\n  api_checknelems(L, 1);\n  name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val);\n  if (name) {\n    L->top--;\n    copyTV(L, val, L->top);\n    lj_gc_barrier(L, funcV(f), L->top);\n  }\n  return name;\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n#if LJ_FR2\nstatic TValue *api_call_base(lua_State *L, int nargs)\n{\n  TValue *o = L->top, *base = o - nargs;\n  L->top = o+1;\n  for (; o > base; o--) copyTV(L, o, o-1);\n  setnilV(o);\n  return o+1;\n}\n#else\n#define api_call_base(L, nargs)\t(L->top - (nargs))\n#endif\n\nLUA_API void lua_call(lua_State *L, int nargs, int nresults)\n{\n  api_check(L, L->status == 0 || L->status == LUA_ERRERR);\n  api_checknelems(L, nargs+1);\n  lj_vm_call(L, api_call_base(L, nargs), nresults+1);\n}\n\nLUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)\n{\n  global_State *g = G(L);\n  uint8_t oldh = hook_save(g);\n  ptrdiff_t ef;\n  int status;\n  api_check(L, L->status == 0 || L->status == LUA_ERRERR);\n  api_checknelems(L, nargs+1);\n  if (errfunc == 0) {\n    ef = 0;\n  } else {\n    cTValue *o = stkindex2adr(L, errfunc);\n    api_checkvalidindex(L, o);\n    ef = savestack(L, o);\n  }\n  status = lj_vm_pcall(L, api_call_base(L, nargs), nresults+1, ef);\n  if (status) hook_restore(g, oldh);\n  return status;\n}\n\nstatic TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)\n{\n  GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L));\n  TValue *top = L->top;\n  fn->c.f = func;\n  setfuncV(L, top++, fn);\n  if (LJ_FR2) setnilV(top++);\n  setlightudV(top++, checklightudptr(L, ud));\n  cframe_nres(L->cframe) = 1+0;  /* Zero results. */\n  L->top = top;\n  return top-1;  /* Now call the newly allocated C function. */\n}\n\nLUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud)\n{\n  global_State *g = G(L);\n  uint8_t oldh = hook_save(g);\n  int status;\n  api_check(L, L->status == 0 || L->status == LUA_ERRERR);\n  status = lj_vm_cpcall(L, func, ud, cpcall);\n  if (status) hook_restore(g, oldh);\n  return status;\n}\n\nLUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field)\n{\n  if (luaL_getmetafield(L, idx, field)) {\n    TValue *top = L->top--;\n    if (LJ_FR2) setnilV(top++);\n    copyTV(L, top++, index2adr(L, idx));\n    L->top = top;\n    lj_vm_call(L, top-1, 1+1);\n    return 1;\n  }\n  return 0;\n}\n\n/* -- Coroutine yield and resume ------------------------------------------ */\n\nLUA_API int lua_yield(lua_State *L, int nresults)\n{\n  void *cf = L->cframe;\n  global_State *g = G(L);\n  if (cframe_canyield(cf)) {\n    cf = cframe_raw(cf);\n    if (!hook_active(g)) {  /* Regular yield: move results down if needed. */\n      cTValue *f = L->top - nresults;\n      if (f > L->base) {\n\tTValue *t = L->base;\n\twhile (--nresults >= 0) copyTV(L, t++, f++);\n\tL->top = t;\n      }\n      L->cframe = NULL;\n      L->status = LUA_YIELD;\n      return -1;\n    } else {  /* Yield from hook: add a pseudo-frame. */\n      TValue *top = L->top;\n      hook_leave(g);\n      (top++)->u64 = cframe_multres(cf);\n      setcont(top, lj_cont_hook);\n      if (LJ_FR2) top++;\n      setframe_pc(top, cframe_pc(cf)-1);\n      if (LJ_FR2) top++;\n      setframe_gc(top, obj2gco(L), LJ_TTHREAD);\n      setframe_ftsz(top, ((char *)(top+1)-(char *)L->base)+FRAME_CONT);\n      L->top = L->base = top+1;\n#if LJ_TARGET_X64\n      lj_err_throw(L, LUA_YIELD);\n#else\n      L->cframe = NULL;\n      L->status = LUA_YIELD;\n      lj_vm_unwind_c(cf, LUA_YIELD);\n#endif\n    }\n  }\n  lj_err_msg(L, LJ_ERR_CYIELD);\n  return 0;  /* unreachable */\n}\n\nLUA_API int lua_resume(lua_State *L, int nargs)\n{\n  if (L->cframe == NULL && L->status <= LUA_YIELD)\n    return lj_vm_resume(L,\n      L->status == 0 ? api_call_base(L, nargs) : L->top - nargs,\n      0, 0);\n  L->top = L->base;\n  setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP));\n  incr_top(L);\n  return LUA_ERRRUN;\n}\n\n/* -- GC and memory management -------------------------------------------- */\n\nLUA_API int lua_gc(lua_State *L, int what, int data)\n{\n  global_State *g = G(L);\n  int res = 0;\n  switch (what) {\n  case LUA_GCSTOP:\n    g->gc.threshold = LJ_MAX_MEM;\n    break;\n  case LUA_GCRESTART:\n    g->gc.threshold = data == -1 ? (g->gc.total/100)*g->gc.pause : g->gc.total;\n    break;\n  case LUA_GCCOLLECT:\n    lj_gc_fullgc(L);\n    break;\n  case LUA_GCCOUNT:\n    res = (int)(g->gc.total >> 10);\n    break;\n  case LUA_GCCOUNTB:\n    res = (int)(g->gc.total & 0x3ff);\n    break;\n  case LUA_GCSTEP: {\n    GCSize a = (GCSize)data << 10;\n    g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0;\n    while (g->gc.total >= g->gc.threshold)\n      if (lj_gc_step(L) > 0) {\n\tres = 1;\n\tbreak;\n      }\n    break;\n  }\n  case LUA_GCSETPAUSE:\n    res = (int)(g->gc.pause);\n    g->gc.pause = (MSize)data;\n    break;\n  case LUA_GCSETSTEPMUL:\n    res = (int)(g->gc.stepmul);\n    g->gc.stepmul = (MSize)data;\n    break;\n  case LUA_GCISRUNNING:\n    res = (g->gc.threshold != LJ_MAX_MEM);\n    break;\n  default:\n    res = -1;  /* Invalid option. */\n  }\n  return res;\n}\n\nLUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)\n{\n  global_State *g = G(L);\n  if (ud) *ud = g->allocd;\n  return g->allocf;\n}\n\nLUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud)\n{\n  global_State *g = G(L);\n  g->allocd = ud;\n  g->allocf = f;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_arch.h",
    "content": "/*\n** Target architecture selection.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ARCH_H\n#define _LJ_ARCH_H\n\n#include \"lua.h\"\n\n/* Target endianess. */\n#define LUAJIT_LE\t0\n#define LUAJIT_BE\t1\n\n/* Target architectures. */\n#define LUAJIT_ARCH_X86\t\t1\n#define LUAJIT_ARCH_x86\t\t1\n#define LUAJIT_ARCH_X64\t\t2\n#define LUAJIT_ARCH_x64\t\t2\n#define LUAJIT_ARCH_ARM\t\t3\n#define LUAJIT_ARCH_arm\t\t3\n#define LUAJIT_ARCH_ARM64\t4\n#define LUAJIT_ARCH_arm64\t4\n#define LUAJIT_ARCH_PPC\t\t5\n#define LUAJIT_ARCH_ppc\t\t5\n#define LUAJIT_ARCH_MIPS\t6\n#define LUAJIT_ARCH_mips\t6\n\n/* Target OS. */\n#define LUAJIT_OS_OTHER\t\t0\n#define LUAJIT_OS_WINDOWS\t1\n#define LUAJIT_OS_LINUX\t\t2\n#define LUAJIT_OS_OSX\t\t3\n#define LUAJIT_OS_BSD\t\t4\n#define LUAJIT_OS_POSIX\t\t5\n\n/* Select native target if no target defined. */\n#ifndef LUAJIT_TARGET\n\n#if defined(__i386) || defined(__i386__) || defined(_M_IX86)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_X86\n#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_X64\n#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_ARM\n#elif defined(__aarch64__)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_ARM64\n#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_PPC\n#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_MIPS\n#else\n#error \"No support for this architecture (yet)\"\n#endif\n\n#endif\n\n/* Select native OS if no target OS defined. */\n#ifndef LUAJIT_OS\n\n#if defined(_WIN32) && !defined(_XBOX_VER)\n#define LUAJIT_OS\tLUAJIT_OS_WINDOWS\n#elif defined(__linux__)\n#define LUAJIT_OS\tLUAJIT_OS_LINUX\n#elif defined(__MACH__) && defined(__APPLE__)\n#define LUAJIT_OS\tLUAJIT_OS_OSX\n#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \\\n       defined(__NetBSD__) || defined(__OpenBSD__) || \\\n       defined(__DragonFly__)) && !defined(__ORBIS__)\n#define LUAJIT_OS\tLUAJIT_OS_BSD\n#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)\n#define LUAJIT_OS\tLUAJIT_OS_POSIX\n#else\n#define LUAJIT_OS\tLUAJIT_OS_OTHER\n#endif\n\n#endif\n\n/* Set target OS properties. */\n#if LUAJIT_OS == LUAJIT_OS_WINDOWS\n#define LJ_OS_NAME\t\"Windows\"\n#elif LUAJIT_OS == LUAJIT_OS_LINUX\n#define LJ_OS_NAME\t\"Linux\"\n#elif LUAJIT_OS == LUAJIT_OS_OSX\n#define LJ_OS_NAME\t\"OSX\"\n#elif LUAJIT_OS == LUAJIT_OS_BSD\n#define LJ_OS_NAME\t\"BSD\"\n#elif LUAJIT_OS == LUAJIT_OS_POSIX\n#define LJ_OS_NAME\t\"POSIX\"\n#else\n#define LJ_OS_NAME\t\"Other\"\n#endif\n\n#define LJ_TARGET_WINDOWS\t(LUAJIT_OS == LUAJIT_OS_WINDOWS)\n#define LJ_TARGET_LINUX\t\t(LUAJIT_OS == LUAJIT_OS_LINUX)\n#define LJ_TARGET_OSX\t\t(LUAJIT_OS == LUAJIT_OS_OSX)\n#define LJ_TARGET_IOS\t\t(LJ_TARGET_OSX && (LUAJIT_TARGET == LUAJIT_ARCH_ARM || LUAJIT_TARGET == LUAJIT_ARCH_ARM64))\n#define LJ_TARGET_POSIX\t\t(LUAJIT_OS > LUAJIT_OS_WINDOWS)\n#if LJ_TARGET_IOS\n#define LJ_TARGET_DLOPEN\t0\n#else\n#define LJ_TARGET_DLOPEN\tLJ_TARGET_POSIX\n#endif\n\n#ifdef __CELLOS_LV2__\n#define LJ_TARGET_PS3\t\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#ifdef __ORBIS__\n#define LJ_TARGET_PS4\t\t1\n#define LJ_TARGET_CONSOLE\t1\n#undef NULL\n#define NULL ((void*)0)\n#endif\n\n#ifdef __psp2__\n#define LJ_TARGET_PSVITA\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#if _XBOX_VER >= 200\n#define LJ_TARGET_XBOX360\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#ifdef _DURANGO\n#define LJ_TARGET_XBOXONE\t1\n#define LJ_TARGET_CONSOLE\t1\n#define LJ_TARGET_GC64\t\t1\n#endif\n\n#define LJ_NUMMODE_SINGLE\t0\t/* Single-number mode only. */\n#define LJ_NUMMODE_SINGLE_DUAL\t1\t/* Default to single-number mode. */\n#define LJ_NUMMODE_DUAL\t\t2\t/* Dual-number mode only. */\n#define LJ_NUMMODE_DUAL_SINGLE\t3\t/* Default to dual-number mode. */\n\n/* Set target architecture properties. */\n#if LUAJIT_TARGET == LUAJIT_ARCH_X86\n\n#define LJ_ARCH_NAME\t\t\"x86\"\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#if LJ_TARGET_WINDOWS || __CYGWIN__\n#define LJ_ABI_WIN\t\t1\n#else\n#define LJ_ABI_WIN\t\t0\n#endif\n#define LJ_TARGET_X86\t\t1\n#define LJ_TARGET_X86ORX64\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNALIGNED\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_SINGLE_DUAL\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_X64\n\n#define LJ_ARCH_NAME\t\t\"x64\"\n#define LJ_ARCH_BITS\t\t64\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#if LJ_TARGET_WINDOWS || __CYGWIN__\n#define LJ_ABI_WIN\t\t1\n#else\n#define LJ_ABI_WIN\t\t0\n#endif\n#define LJ_TARGET_X64\t\t1\n#define LJ_TARGET_X86ORX64\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_JUMPRANGE\t31\t/* +-2^31 = +-2GB */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNALIGNED\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_SINGLE_DUAL\n#ifdef LUAJIT_ENABLE_GC64\n#define LJ_TARGET_GC64\t\t1\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM\n\n#define LJ_ARCH_NAME\t\t\"arm\"\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__\n#define LJ_ARCH_HASFPU\t\t0\n#endif\n#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP\n#define LJ_ABI_SOFTFP\t\t1\n#endif\n#define LJ_ABI_EABI\t\t1\n#define LJ_TARGET_ARM\t\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_JUMPRANGE\t25\t/* +-2^25 = +-32MB */\n#define LJ_TARGET_MASKSHIFT\t0\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n\n#if __ARM_ARCH____ARM_ARCH_8__ || __ARM_ARCH_8A__\n#define LJ_ARCH_VERSION\t\t80\n#elif __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__\n#define LJ_ARCH_VERSION\t\t70\n#elif __ARM_ARCH_6T2__\n#define LJ_ARCH_VERSION\t\t61\n#elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__\n#define LJ_ARCH_VERSION\t\t60\n#else\n#define LJ_ARCH_VERSION\t\t50\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64\n\n#define LJ_ARCH_NAME\t\t\"arm64\"\n#define LJ_ARCH_BITS\t\t64\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#define LJ_TARGET_ARM64\t\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_JUMPRANGE\t27\t/* +-2^27 = +-128MB */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_TARGET_GC64\t\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n#define LJ_ARCH_NOJIT\t\t1\t/* NYI */\n\n#define LJ_ARCH_VERSION\t\t80\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC\n\n#ifndef LJ_ARCH_ENDIAN\n#if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#else\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_BE\n#endif\n#endif\n\n#if _LP64\n#define LJ_ARCH_BITS\t\t64\n#if LJ_ARCH_ENDIAN == LUAJIT_LE\n#define LJ_ARCH_NAME\t\t\"ppc64le\"\n#else\n#define LJ_ARCH_NAME\t\t\"ppc64\"\n#endif\n#else\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_NAME\t\t\"ppc\"\n#endif\n\n#define LJ_TARGET_PPC\t\t1\n#define LJ_TARGET_EHRETREG\t3\n#define LJ_TARGET_JUMPRANGE\t25\t/* +-2^25 = +-32MB */\n#define LJ_TARGET_MASKSHIFT\t0\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t1\t/* Want only IR_BROL. */\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL_SINGLE\n\n#if LJ_TARGET_CONSOLE\n#define LJ_ARCH_PPC32ON64\t1\n#define LJ_ARCH_NOFFI\t\t1\n#elif LJ_ARCH_BITS == 64\n#define LJ_ARCH_PPC64\t\t1\n#define LJ_TARGET_GC64\t\t1\n#define LJ_ARCH_NOJIT\t\t1\t/* NYI */\n#endif\n\n#if _ARCH_PWR7\n#define LJ_ARCH_VERSION\t\t70\n#elif _ARCH_PWR6\n#define LJ_ARCH_VERSION\t\t60\n#elif _ARCH_PWR5X\n#define LJ_ARCH_VERSION\t\t51\n#elif _ARCH_PWR5\n#define LJ_ARCH_VERSION\t\t50\n#elif _ARCH_PWR4\n#define LJ_ARCH_VERSION\t\t40\n#else\n#define LJ_ARCH_VERSION\t\t0\n#endif\n#if _ARCH_PPCSQ\n#define LJ_ARCH_SQRT\t\t1\n#endif\n#if _ARCH_PWR5X\n#define LJ_ARCH_ROUND\t\t1\n#endif\n#if __PPU__\n#define LJ_ARCH_CELL\t\t1\n#endif\n#if LJ_TARGET_XBOX360\n#define LJ_ARCH_XENON\t\t1\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS\n\n#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)\n#define LJ_ARCH_NAME\t\t\"mipsel\"\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#else\n#define LJ_ARCH_NAME\t\t\"mips\"\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_BE\n#endif\n\n#if !defined(LJ_ARCH_HASFPU)\n#ifdef __mips_soft_float\n#define LJ_ARCH_HASFPU\t\t0\n#else\n#define LJ_ARCH_HASFPU\t\t1\n#endif\n#endif\n\n/* Temporarily disable features until the code has been merged. */\n#if !defined(LUAJIT_NO_UNWIND) && __GNU_COMPACT_EH__\n#define LUAJIT_NO_UNWIND\t1\n#endif\n\n#if !defined(LJ_ABI_SOFTFP)\n#ifdef __mips_soft_float\n#define LJ_ABI_SOFTFP\t\t1\n#else\n#define LJ_ABI_SOFTFP\t\t0\n#endif\n#endif\n\n#define LJ_ARCH_BITS\t\t32\n#define LJ_TARGET_MIPS\t\t1\n#define LJ_TARGET_EHRETREG\t4\n#define LJ_TARGET_JUMPRANGE\t27\t/* 2*2^27 = 256MB-aligned region */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n\n#if _MIPS_ARCH_MIPS32R2\n#define LJ_ARCH_VERSION\t\t20\n#else\n#define LJ_ARCH_VERSION\t\t10\n#endif\n\n#else\n#error \"No target architecture defined\"\n#endif\n\n#ifndef LJ_PAGESIZE\n#define LJ_PAGESIZE\t\t4096\n#endif\n\n/* Check for minimum required compiler versions. */\n#if defined(__GNUC__)\n#if LJ_TARGET_X86\n#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)\n#error \"Need at least GCC 3.4 or newer\"\n#endif\n#elif LJ_TARGET_X64\n#if __GNUC__ < 4\n#error \"Need at least GCC 4.0 or newer\"\n#endif\n#elif LJ_TARGET_ARM\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)\n#error \"Need at least GCC 4.2 or newer\"\n#endif\n#elif LJ_TARGET_ARM64\n#if __clang__\n#if (__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)\n#error \"Need at least Clang 3.5 or newer\"\n#endif\n#else\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)\n#error \"Need at least GCC 4.8 or newer\"\n#endif\n#endif\n#elif !LJ_TARGET_PS3\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)\n#error \"Need at least GCC 4.3 or newer\"\n#endif\n#endif\n#endif\n\n/* Check target-specific constraints. */\n#ifndef _BUILDVM_H\n#if LJ_TARGET_X64\n#if __USING_SJLJ_EXCEPTIONS__\n#error \"Need a C compiler with native exception handling on x64\"\n#endif\n#elif LJ_TARGET_ARM\n#if defined(__ARMEB__)\n#error \"No support for big-endian ARM\"\n#endif\n#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__\n#error \"No support for Cortex-M CPUs\"\n#endif\n#if !(__ARM_EABI__ || LJ_TARGET_IOS)\n#error \"Only ARM EABI or iOS 3.0+ ABI is supported\"\n#endif\n#elif LJ_TARGET_ARM64\n#if defined(__AARCH64EB__)\n#error \"No support for big-endian ARM64\"\n#endif\n#if defined(_ILP32)\n#error \"No support for ILP32 model on ARM64\"\n#endif\n#elif LJ_TARGET_PPC\n#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)\n#error \"No support for PowerPC CPUs without double-precision FPU\"\n#endif\n#if !LJ_ARCH_PPC64 && LJ_ARCH_ENDIAN == LUAJIT_LE\n#error \"No support for little-endian PPC32\"\n#endif\n#if LJ_ARCH_PPC64\n#error \"No support for PowerPC 64 bit mode (yet)\"\n#endif\n#ifdef __NO_FPRS__\n#error \"No support for PPC/e500 anymore (use LuaJIT 2.0)\"\n#endif\n#elif LJ_TARGET_MIPS\n#if defined(_LP64)\n#error \"No support for MIPS64\"\n#endif\n#endif\n#endif\n\n/* Enable or disable the dual-number mode for the VM. */\n#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)\n#error \"No support for this number mode on this architecture\"\n#endif\n#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)\n#define LJ_DUALNUM\t\t1\n#else\n#define LJ_DUALNUM\t\t0\n#endif\n\n#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE\n/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */\n/* Ditto for the consoles. Complain to Sony or MS, not me. */\n#ifndef LUAJIT_ENABLE_JIT\n#define LJ_OS_NOJIT\t\t1\n#endif\n#endif\n\n/* 64 bit GC references. */\n#if LJ_TARGET_GC64\n#define LJ_GC64\t\t\t1\n#else\n#define LJ_GC64\t\t\t0\n#endif\n\n/* 2-slot frame info. */\n#if LJ_GC64\n#define LJ_FR2\t\t\t1\n#else\n#define LJ_FR2\t\t\t0\n#endif\n\n/* Disable or enable the JIT compiler. */\n#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT) || LJ_FR2 || LJ_GC64\n#define LJ_HASJIT\t\t0\n#else\n#define LJ_HASJIT\t\t1\n#endif\n\n/* Disable or enable the FFI extension. */\n#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)\n#define LJ_HASFFI\t\t0\n#else\n#define LJ_HASFFI\t\t1\n#endif\n\n#if defined(LUAJIT_DISABLE_PROFILE)\n#define LJ_HASPROFILE\t\t0\n#elif LJ_TARGET_POSIX\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_SIGPROF\t1\n#elif LJ_TARGET_PS3\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_PTHREAD\t1\n#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_WTHREAD\t1\n#else\n#define LJ_HASPROFILE\t\t0\n#endif\n\n#ifndef LJ_ARCH_HASFPU\n#define LJ_ARCH_HASFPU\t\t1\n#endif\n#ifndef LJ_ABI_SOFTFP\n#define LJ_ABI_SOFTFP\t\t0\n#endif\n#define LJ_SOFTFP\t\t(!LJ_ARCH_HASFPU)\n\n#if LJ_ARCH_ENDIAN == LUAJIT_BE\n#define LJ_LE\t\t\t0\n#define LJ_BE\t\t\t1\n#define LJ_ENDIAN_SELECT(le, be)\tbe\n#define LJ_ENDIAN_LOHI(lo, hi)\t\thi lo\n#else\n#define LJ_LE\t\t\t1\n#define LJ_BE\t\t\t0\n#define LJ_ENDIAN_SELECT(le, be)\tle\n#define LJ_ENDIAN_LOHI(lo, hi)\t\tlo hi\n#endif\n\n#if LJ_ARCH_BITS == 32\n#define LJ_32\t\t\t1\n#define LJ_64\t\t\t0\n#else\n#define LJ_32\t\t\t0\n#define LJ_64\t\t\t1\n#endif\n\n#ifndef LJ_TARGET_UNALIGNED\n#define LJ_TARGET_UNALIGNED\t0\n#endif\n\n/* Various workarounds for embedded operating systems or weak C runtimes. */\n#if defined(__ANDROID__) || defined(__symbian__) || LJ_TARGET_XBOX360 || LJ_TARGET_WINDOWS\n#define LUAJIT_NO_LOG2\n#endif\n#if defined(__symbian__) || LJ_TARGET_WINDOWS\n#define LUAJIT_NO_EXP2\n#endif\n#if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)\n#define LJ_NO_SYSTEM\t\t1\n#endif\n\n#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4\n#define LJ_NO_UNWIND\t\t1\n#endif\n\n/* Compatibility with Lua 5.1 vs. 5.2. */\n#ifdef LUAJIT_ENABLE_LUA52COMPAT\n#define LJ_52\t\t\t1\n#else\n#define LJ_52\t\t\t0\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm.c",
    "content": "/*\n** IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_asm_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_mcode.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_asm.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_target.h\"\n\n#ifdef LUA_USE_ASSERT\n#include <stdio.h>\n#endif\n\n/* -- Assembler state and common macros ----------------------------------- */\n\n/* Assembler state. */\ntypedef struct ASMState {\n  RegCost cost[RID_MAX];  /* Reference and blended allocation cost for regs. */\n\n  MCode *mcp;\t\t/* Current MCode pointer (grows down). */\n  MCode *mclim;\t\t/* Lower limit for MCode memory + red zone. */\n#ifdef LUA_USE_ASSERT\n  MCode *mcp_prev;\t/* Red zone overflow check. */\n#endif\n\n  IRIns *ir;\t\t/* Copy of pointer to IR instructions/constants. */\n  jit_State *J;\t\t/* JIT compiler state. */\n\n#if LJ_TARGET_X86ORX64\n  x86ModRM mrm;\t\t/* Fused x86 address operand. */\n#endif\n\n  RegSet freeset;\t/* Set of free registers. */\n  RegSet modset;\t/* Set of registers modified inside the loop. */\n  RegSet weakset;\t/* Set of weakly referenced registers. */\n  RegSet phiset;\t/* Set of PHI registers. */\n\n  uint32_t flags;\t/* Copy of JIT compiler flags. */\n  int loopinv;\t\t/* Loop branch inversion (0:no, 1:yes, 2:yes+CC_P). */\n\n  int32_t evenspill;\t/* Next even spill slot. */\n  int32_t oddspill;\t/* Next odd spill slot (or 0). */\n\n  IRRef curins;\t\t/* Reference of current instruction. */\n  IRRef stopins;\t/* Stop assembly before hitting this instruction. */\n  IRRef orignins;\t/* Original T->nins. */\n\n  IRRef snapref;\t/* Current snapshot is active after this reference. */\n  IRRef snaprename;\t/* Rename highwater mark for snapshot check. */\n  SnapNo snapno;\t/* Current snapshot number. */\n  SnapNo loopsnapno;\t/* Loop snapshot number. */\n\n  IRRef fuseref;\t/* Fusion limit (loopref, 0 or FUSE_DISABLED). */\n  IRRef sectref;\t/* Section base reference (loopref or 0). */\n  IRRef loopref;\t/* Reference of LOOP instruction (or 0). */\n\n  BCReg topslot;\t/* Number of slots for stack check (unless 0). */\n  int32_t gcsteps;\t/* Accumulated number of GC steps (per section). */\n\n  GCtrace *T;\t\t/* Trace to assemble. */\n  GCtrace *parent;\t/* Parent trace (or NULL). */\n\n  MCode *mcbot;\t\t/* Bottom of reserved MCode. */\n  MCode *mctop;\t\t/* Top of generated MCode. */\n  MCode *mcloop;\t/* Pointer to loop MCode (or NULL). */\n  MCode *invmcp;\t/* Points to invertible loop branch (or NULL). */\n  MCode *flagmcp;\t/* Pending opportunity to merge flag setting ins. */\n  MCode *realign;\t/* Realign loop if not NULL. */\n\n#ifdef RID_NUM_KREF\n  int32_t krefk[RID_NUM_KREF];\n#endif\n  IRRef1 phireg[RID_MAX];  /* PHI register references. */\n  uint16_t parentmap[LJ_MAX_JSLOTS];  /* Parent instruction to RegSP map. */\n} ASMState;\n\n#define IR(ref)\t\t\t(&as->ir[(ref)])\n\n#define ASMREF_TMP1\t\tREF_TRUE\t/* Temp. register. */\n#define ASMREF_TMP2\t\tREF_FALSE\t/* Temp. register. */\n#define ASMREF_L\t\tREF_NIL\t\t/* Stores register for L. */\n\n/* Check for variant to invariant references. */\n#define iscrossref(as, ref)\t((ref) < as->sectref)\n\n/* Inhibit memory op fusion from variant to invariant references. */\n#define FUSE_DISABLED\t\t(~(IRRef)0)\n#define mayfuse(as, ref)\t((ref) > as->fuseref)\n#define neverfuse(as)\t\t(as->fuseref == FUSE_DISABLED)\n#define canfuse(as, ir)\t\t(!neverfuse(as) && !irt_isphi((ir)->t))\n#define opisfusableload(o) \\\n  ((o) == IR_ALOAD || (o) == IR_HLOAD || (o) == IR_ULOAD || \\\n   (o) == IR_FLOAD || (o) == IR_XLOAD || (o) == IR_SLOAD || (o) == IR_VLOAD)\n\n/* Sparse limit checks using a red zone before the actual limit. */\n#define MCLIM_REDZONE\t64\n\nstatic LJ_NORET LJ_NOINLINE void asm_mclimit(ASMState *as)\n{\n  lj_mcode_limiterr(as->J, (size_t)(as->mctop - as->mcp + 4*MCLIM_REDZONE));\n}\n\nstatic LJ_AINLINE void checkmclim(ASMState *as)\n{\n#ifdef LUA_USE_ASSERT\n  if (as->mcp + MCLIM_REDZONE < as->mcp_prev) {\n    IRIns *ir = IR(as->curins+1);\n    fprintf(stderr, \"RED ZONE OVERFLOW: %p IR %04d  %02d %04d %04d\\n\", as->mcp,\n\t    as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS);\n    lua_assert(0);\n  }\n#endif\n  if (LJ_UNLIKELY(as->mcp < as->mclim)) asm_mclimit(as);\n#ifdef LUA_USE_ASSERT\n  as->mcp_prev = as->mcp;\n#endif\n}\n\n#ifdef RID_NUM_KREF\n#define ra_iskref(ref)\t\t((ref) < RID_NUM_KREF)\n#define ra_krefreg(ref)\t\t((Reg)(RID_MIN_KREF + (Reg)(ref)))\n#define ra_krefk(as, ref)\t(as->krefk[(ref)])\n\nstatic LJ_AINLINE void ra_setkref(ASMState *as, Reg r, int32_t k)\n{\n  IRRef ref = (IRRef)(r - RID_MIN_KREF);\n  as->krefk[ref] = k;\n  as->cost[r] = REGCOST(ref, ref);\n}\n\n#else\n#define ra_iskref(ref)\t\t0\n#define ra_krefreg(ref)\t\tRID_MIN_GPR\n#define ra_krefk(as, ref)\t0\n#endif\n\n/* Arch-specific field offsets. */\nstatic const uint8_t field_ofs[IRFL__MAX+1] = {\n#define FLOFS(name, ofs)\t(uint8_t)(ofs),\nIRFLDEF(FLOFS)\n#undef FLOFS\n  0\n};\n\n/* -- Target-specific instruction emitter --------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_emit_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_emit_arm.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_emit_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_emit_mips.h\"\n#else\n#error \"Missing instruction emitter for target CPU\"\n#endif\n\n/* Generic load/store of register from/to stack slot. */\n#define emit_spload(as, ir, r, ofs) \\\n  emit_loadofs(as, ir, (r), RID_SP, (ofs))\n#define emit_spstore(as, ir, r, ofs) \\\n  emit_storeofs(as, ir, (r), RID_SP, (ofs))\n\n/* -- Register allocator debugging ---------------------------------------- */\n\n/* #define LUAJIT_DEBUG_RA */\n\n#ifdef LUAJIT_DEBUG_RA\n\n#include <stdio.h>\n#include <stdarg.h>\n\n#define RIDNAME(name)\t#name,\nstatic const char *const ra_regname[] = {\n  GPRDEF(RIDNAME)\n  FPRDEF(RIDNAME)\n  VRIDDEF(RIDNAME)\n  NULL\n};\n#undef RIDNAME\n\nstatic char ra_dbg_buf[65536];\nstatic char *ra_dbg_p;\nstatic char *ra_dbg_merge;\nstatic MCode *ra_dbg_mcp;\n\nstatic void ra_dstart(void)\n{\n  ra_dbg_p = ra_dbg_buf;\n  ra_dbg_merge = NULL;\n  ra_dbg_mcp = NULL;\n}\n\nstatic void ra_dflush(void)\n{\n  fwrite(ra_dbg_buf, 1, (size_t)(ra_dbg_p-ra_dbg_buf), stdout);\n  ra_dstart();\n}\n\nstatic void ra_dprintf(ASMState *as, const char *fmt, ...)\n{\n  char *p;\n  va_list argp;\n  va_start(argp, fmt);\n  p = ra_dbg_mcp == as->mcp ? ra_dbg_merge : ra_dbg_p;\n  ra_dbg_mcp = NULL;\n  p += sprintf(p, \"%08x  \\e[36m%04d \", (uintptr_t)as->mcp, as->curins-REF_BIAS);\n  for (;;) {\n    const char *e = strchr(fmt, '$');\n    if (e == NULL) break;\n    memcpy(p, fmt, (size_t)(e-fmt));\n    p += e-fmt;\n    if (e[1] == 'r') {\n      Reg r = va_arg(argp, Reg) & RID_MASK;\n      if (r <= RID_MAX) {\n\tconst char *q;\n\tfor (q = ra_regname[r]; *q; q++)\n\t  *p++ = *q >= 'A' && *q <= 'Z' ? *q + 0x20 : *q;\n      } else {\n\t*p++ = '?';\n\tlua_assert(0);\n      }\n    } else if (e[1] == 'f' || e[1] == 'i') {\n      IRRef ref;\n      if (e[1] == 'f')\n\tref = va_arg(argp, IRRef);\n      else\n\tref = va_arg(argp, IRIns *) - as->ir;\n      if (ref >= REF_BIAS)\n\tp += sprintf(p, \"%04d\", ref - REF_BIAS);\n      else\n\tp += sprintf(p, \"K%03d\", REF_BIAS - ref);\n    } else if (e[1] == 's') {\n      uint32_t slot = va_arg(argp, uint32_t);\n      p += sprintf(p, \"[sp+0x%x]\", sps_scale(slot));\n    } else if (e[1] == 'x') {\n      p += sprintf(p, \"%08x\", va_arg(argp, int32_t));\n    } else {\n      lua_assert(0);\n    }\n    fmt = e+2;\n  }\n  va_end(argp);\n  while (*fmt)\n    *p++ = *fmt++;\n  *p++ = '\\e'; *p++ = '['; *p++ = 'm'; *p++ = '\\n';\n  if (p > ra_dbg_buf+sizeof(ra_dbg_buf)-256) {\n    fwrite(ra_dbg_buf, 1, (size_t)(p-ra_dbg_buf), stdout);\n    p = ra_dbg_buf;\n  }\n  ra_dbg_p = p;\n}\n\n#define RA_DBG_START()\tra_dstart()\n#define RA_DBG_FLUSH()\tra_dflush()\n#define RA_DBG_REF() \\\n  do { char *_p = ra_dbg_p; ra_dprintf(as, \"\"); \\\n       ra_dbg_merge = _p; ra_dbg_mcp = as->mcp; } while (0)\n#define RA_DBGX(x)\tra_dprintf x\n\n#else\n#define RA_DBG_START()\t((void)0)\n#define RA_DBG_FLUSH()\t((void)0)\n#define RA_DBG_REF()\t((void)0)\n#define RA_DBGX(x)\t((void)0)\n#endif\n\n/* -- Register allocator -------------------------------------------------- */\n\n#define ra_free(as, r)\t\trset_set(as->freeset, (r))\n#define ra_modified(as, r)\trset_set(as->modset, (r))\n#define ra_weak(as, r)\t\trset_set(as->weakset, (r))\n#define ra_noweak(as, r)\trset_clear(as->weakset, (r))\n\n#define ra_used(ir)\t\t(ra_hasreg((ir)->r) || ra_hasspill((ir)->s))\n\n/* Setup register allocator. */\nstatic void ra_setup(ASMState *as)\n{\n  Reg r;\n  /* Initially all regs (except the stack pointer) are free for use. */\n  as->freeset = RSET_INIT;\n  as->modset = RSET_EMPTY;\n  as->weakset = RSET_EMPTY;\n  as->phiset = RSET_EMPTY;\n  memset(as->phireg, 0, sizeof(as->phireg));\n  for (r = RID_MIN_GPR; r < RID_MAX; r++)\n    as->cost[r] = REGCOST(~0u, 0u);\n}\n\n/* Rematerialize constants. */\nstatic Reg ra_rematk(ASMState *as, IRRef ref)\n{\n  IRIns *ir;\n  Reg r;\n  if (ra_iskref(ref)) {\n    r = ra_krefreg(ref);\n    lua_assert(!rset_test(as->freeset, r));\n    ra_free(as, r);\n    ra_modified(as, r);\n    emit_loadi(as, r, ra_krefk(as, ref));\n    return r;\n  }\n  ir = IR(ref);\n  r = ir->r;\n  lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s));\n  ra_free(as, r);\n  ra_modified(as, r);\n  ir->r = RID_INIT;  /* Do not keep any hint. */\n  RA_DBGX((as, \"remat     $i $r\", ir, r));\n#if !LJ_SOFTFP\n  if (ir->o == IR_KNUM) {\n    emit_loadn(as, r, ir_knum(ir));\n  } else\n#endif\n  if (emit_canremat(REF_BASE) && ir->o == IR_BASE) {\n    ra_sethint(ir->r, RID_BASE);  /* Restore BASE register hint. */\n    emit_getgl(as, r, jit_base);\n  } else if (emit_canremat(ASMREF_L) && ir->o == IR_KPRI) {\n    lua_assert(irt_isnil(ir->t));  /* REF_NIL stores ASMREF_L register. */\n    emit_getgl(as, r, cur_L);\n#if LJ_64\n  } else if (ir->o == IR_KINT64) {\n    emit_loadu64(as, r, ir_kint64(ir)->u64);\n#endif\n  } else {\n    lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||\n\t       ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);\n    emit_loadi(as, r, ir->i);\n  }\n  return r;\n}\n\n/* Force a spill. Allocate a new spill slot if needed. */\nstatic int32_t ra_spill(ASMState *as, IRIns *ir)\n{\n  int32_t slot = ir->s;\n  lua_assert(ir >= as->ir + REF_TRUE);\n  if (!ra_hasspill(slot)) {\n    if (irt_is64(ir->t)) {\n      slot = as->evenspill;\n      as->evenspill += 2;\n    } else if (as->oddspill) {\n      slot = as->oddspill;\n      as->oddspill = 0;\n    } else {\n      slot = as->evenspill;\n      as->oddspill = slot+1;\n      as->evenspill += 2;\n    }\n    if (as->evenspill > 256)\n      lj_trace_err(as->J, LJ_TRERR_SPILLOV);\n    ir->s = (uint8_t)slot;\n  }\n  return sps_scale(slot);\n}\n\n/* Release the temporarily allocated register in ASMREF_TMP1/ASMREF_TMP2. */\nstatic Reg ra_releasetmp(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  Reg r = ir->r;\n  lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s));\n  ra_free(as, r);\n  ra_modified(as, r);\n  ir->r = RID_INIT;\n  return r;\n}\n\n/* Restore a register (marked as free). Rematerialize or force a spill. */\nstatic Reg ra_restore(ASMState *as, IRRef ref)\n{\n  if (emit_canremat(ref)) {\n    return ra_rematk(as, ref);\n  } else {\n    IRIns *ir = IR(ref);\n    int32_t ofs = ra_spill(as, ir);  /* Force a spill slot. */\n    Reg r = ir->r;\n    lua_assert(ra_hasreg(r));\n    ra_sethint(ir->r, r);  /* Keep hint. */\n    ra_free(as, r);\n    if (!rset_test(as->weakset, r)) {  /* Only restore non-weak references. */\n      ra_modified(as, r);\n      RA_DBGX((as, \"restore   $i $r\", ir, r));\n      emit_spload(as, ir, r, ofs);\n    }\n    return r;\n  }\n}\n\n/* Save a register to a spill slot. */\nstatic void ra_save(ASMState *as, IRIns *ir, Reg r)\n{\n  RA_DBGX((as, \"save      $i $r\", ir, r));\n  emit_spstore(as, ir, r, sps_scale(ir->s));\n}\n\n#define MINCOST(name) \\\n  if (rset_test(RSET_ALL, RID_##name) && \\\n      LJ_LIKELY(allow&RID2RSET(RID_##name)) && as->cost[RID_##name] < cost) \\\n    cost = as->cost[RID_##name];\n\n/* Evict the register with the lowest cost, forcing a restore. */\nstatic Reg ra_evict(ASMState *as, RegSet allow)\n{\n  IRRef ref;\n  RegCost cost = ~(RegCost)0;\n  lua_assert(allow != RSET_EMPTY);\n  if (RID_NUM_FPR == 0 || allow < RID2RSET(RID_MAX_GPR)) {\n    GPRDEF(MINCOST)\n  } else {\n    FPRDEF(MINCOST)\n  }\n  ref = regcost_ref(cost);\n  lua_assert(ra_iskref(ref) || (ref >= as->T->nk && ref < as->T->nins));\n  /* Preferably pick any weak ref instead of a non-weak, non-const ref. */\n  if (!irref_isk(ref) && (as->weakset & allow)) {\n    IRIns *ir = IR(ref);\n    if (!rset_test(as->weakset, ir->r))\n      ref = regcost_ref(as->cost[rset_pickbot((as->weakset & allow))]);\n  }\n  return ra_restore(as, ref);\n}\n\n/* Pick any register (marked as free). Evict on-demand. */\nstatic Reg ra_pick(ASMState *as, RegSet allow)\n{\n  RegSet pick = as->freeset & allow;\n  if (!pick)\n    return ra_evict(as, allow);\n  else\n    return rset_picktop(pick);\n}\n\n/* Get a scratch register (marked as free). */\nstatic Reg ra_scratch(ASMState *as, RegSet allow)\n{\n  Reg r = ra_pick(as, allow);\n  ra_modified(as, r);\n  RA_DBGX((as, \"scratch        $r\", r));\n  return r;\n}\n\n/* Evict all registers from a set (if not free). */\nstatic void ra_evictset(ASMState *as, RegSet drop)\n{\n  RegSet work;\n  as->modset |= drop;\n#if !LJ_SOFTFP\n  work = (drop & ~as->freeset) & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n#endif\n  work = (drop & ~as->freeset);\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n}\n\n/* Evict (rematerialize) all registers allocated to constants. */\nstatic void ra_evictk(ASMState *as)\n{\n  RegSet work;\n#if !LJ_SOFTFP\n  work = ~as->freeset & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    if (emit_canremat(ref) && irref_isk(ref)) {\n      ra_rematk(as, ref);\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n#endif\n  work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    if (emit_canremat(ref) && irref_isk(ref)) {\n      ra_rematk(as, ref);\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n}\n\n#ifdef RID_NUM_KREF\n/* Allocate a register for a constant. */\nstatic Reg ra_allock(ASMState *as, int32_t k, RegSet allow)\n{\n  /* First try to find a register which already holds the same constant. */\n  RegSet pick, work = ~as->freeset & RSET_GPR;\n  Reg r;\n  while (work) {\n    IRRef ref;\n    r = rset_pickbot(work);\n    ref = regcost_ref(as->cost[r]);\n    if (ref < ASMREF_L &&\n\tk == (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i))\n      return r;\n    rset_clear(work, r);\n  }\n  pick = as->freeset & allow;\n  if (pick) {\n    /* Constants should preferably get unmodified registers. */\n    if ((pick & ~as->modset))\n      pick &= ~as->modset;\n    r = rset_pickbot(pick);  /* Reduce conflicts with inverse allocation. */\n  } else {\n    r = ra_evict(as, allow);\n  }\n  RA_DBGX((as, \"allock    $x $r\", k, r));\n  ra_setkref(as, r, k);\n  rset_clear(as->freeset, r);\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a specific register for a constant. */\nstatic void ra_allockreg(ASMState *as, int32_t k, Reg r)\n{\n  Reg kr = ra_allock(as, k, RID2RSET(r));\n  if (kr != r) {\n    IRIns irdummy;\n    irdummy.t.irt = IRT_INT;\n    ra_scratch(as, RID2RSET(r));\n    emit_movrr(as, &irdummy, r, kr);\n  }\n}\n#else\n#define ra_allockreg(as, k, r)\t\temit_loadi(as, (r), (k))\n#endif\n\n/* Allocate a register for ref from the allowed set of registers.\n** Note: this function assumes the ref does NOT have a register yet!\n** Picks an optimal register, sets the cost and marks the register as non-free.\n*/\nstatic Reg ra_allocref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  RegSet pick = as->freeset & allow;\n  Reg r;\n  lua_assert(ra_noreg(ir->r));\n  if (pick) {\n    /* First check register hint from propagation or PHI. */\n    if (ra_hashint(ir->r)) {\n      r = ra_gethint(ir->r);\n      if (rset_test(pick, r))  /* Use hint register if possible. */\n\tgoto found;\n      /* Rematerialization is cheaper than missing a hint. */\n      if (rset_test(allow, r) && emit_canremat(regcost_ref(as->cost[r]))) {\n\tra_rematk(as, regcost_ref(as->cost[r]));\n\tgoto found;\n      }\n      RA_DBGX((as, \"hintmiss  $f $r\", ref, r));\n    }\n    /* Invariants should preferably get unmodified registers. */\n    if (ref < as->loopref && !irt_isphi(ir->t)) {\n      if ((pick & ~as->modset))\n\tpick &= ~as->modset;\n      r = rset_pickbot(pick);  /* Reduce conflicts with inverse allocation. */\n    } else {\n      /* We've got plenty of regs, so get callee-save regs if possible. */\n      if (RID_NUM_GPR > 8 && (pick & ~RSET_SCRATCH))\n\tpick &= ~RSET_SCRATCH;\n      r = rset_picktop(pick);\n    }\n  } else {\n    r = ra_evict(as, allow);\n  }\nfound:\n  RA_DBGX((as, \"alloc     $f $r\", ref, r));\n  ir->r = (uint8_t)r;\n  rset_clear(as->freeset, r);\n  ra_noweak(as, r);\n  as->cost[r] = REGCOST_REF_T(ref, irt_t(ir->t));\n  return r;\n}\n\n/* Allocate a register on-demand. */\nstatic Reg ra_alloc1(ASMState *as, IRRef ref, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  /* Note: allow is ignored if the register is already allocated. */\n  if (ra_noreg(r)) r = ra_allocref(as, ref, allow);\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Rename register allocation and emit move. */\nstatic void ra_rename(ASMState *as, Reg down, Reg up)\n{\n  IRRef ren, ref = regcost_ref(as->cost[up] = as->cost[down]);\n  IRIns *ir = IR(ref);\n  ir->r = (uint8_t)up;\n  as->cost[down] = 0;\n  lua_assert((down < RID_MAX_GPR) == (up < RID_MAX_GPR));\n  lua_assert(!rset_test(as->freeset, down) && rset_test(as->freeset, up));\n  ra_free(as, down);  /* 'down' is free ... */\n  ra_modified(as, down);\n  rset_clear(as->freeset, up);  /* ... and 'up' is now allocated. */\n  ra_noweak(as, up);\n  RA_DBGX((as, \"rename    $f $r $r\", regcost_ref(as->cost[up]), down, up));\n  emit_movrr(as, ir, down, up);  /* Backwards codegen needs inverse move. */\n  if (!ra_hasspill(IR(ref)->s)) {  /* Add the rename to the IR. */\n    lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), ref, as->snapno);\n    ren = tref_ref(lj_ir_emit(as->J));\n    as->ir = as->T->ir;  /* The IR may have been reallocated. */\n    IR(ren)->r = (uint8_t)down;\n    IR(ren)->s = SPS_NONE;\n  }\n}\n\n/* Pick a destination register (marked as free).\n** Caveat: allow is ignored if there's already a destination register.\n** Use ra_destreg() to get a specific register.\n*/\nstatic Reg ra_dest(ASMState *as, IRIns *ir, RegSet allow)\n{\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n  } else {\n    if (ra_hashint(dest) && rset_test((as->freeset&allow), ra_gethint(dest))) {\n      dest = ra_gethint(dest);\n      ra_modified(as, dest);\n      RA_DBGX((as, \"dest           $r\", dest));\n    } else {\n      dest = ra_scratch(as, allow);\n    }\n    ir->r = dest;\n  }\n  if (LJ_UNLIKELY(ra_hasspill(ir->s))) ra_save(as, ir, dest);\n  return dest;\n}\n\n/* Force a specific destination register (marked as free). */\nstatic void ra_destreg(ASMState *as, IRIns *ir, Reg r)\n{\n  Reg dest = ra_dest(as, ir, RID2RSET(r));\n  if (dest != r) {\n    lua_assert(rset_test(as->freeset, r));\n    ra_modified(as, r);\n    emit_movrr(as, ir, dest, r);\n  }\n}\n\n#if LJ_TARGET_X86ORX64\n/* Propagate dest register to left reference. Emit moves as needed.\n** This is a required fixup step for all 2-operand machine instructions.\n*/\nstatic void ra_left(ASMState *as, Reg dest, IRRef lref)\n{\n  IRIns *ir = IR(lref);\n  Reg left = ir->r;\n  if (ra_noreg(left)) {\n    if (irref_isk(lref)) {\n      if (ir->o == IR_KNUM) {\n\tcTValue *tv = ir_knum(ir);\n\t/* FP remat needs a load except for +0. Still better than eviction. */\n\tif (tvispzero(tv) || !(as->freeset & RSET_FPR)) {\n\t  emit_loadn(as, dest, tv);\n\t  return;\n\t}\n#if LJ_64\n      } else if (ir->o == IR_KINT64) {\n\temit_loadu64(as, dest, ir_kint64(ir)->u64);\n\treturn;\n#endif\n      } else if (ir->o != IR_KPRI) {\n\tlua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||\n\t\t   ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);\n\temit_loadi(as, dest, ir->i);\n\treturn;\n      }\n    }\n    if (!ra_hashint(left) && !iscrossref(as, lref))\n      ra_sethint(ir->r, dest);  /* Propagate register hint. */\n    left = ra_allocref(as, lref, dest < RID_MAX_GPR ? RSET_GPR : RSET_FPR);\n  }\n  ra_noweak(as, left);\n  /* Move needed for true 3-operand instruction: y=a+b ==> y=a; y+=b. */\n  if (dest != left) {\n    /* Use register renaming if dest is the PHI reg. */\n    if (irt_isphi(ir->t) && as->phireg[dest] == lref) {\n      ra_modified(as, left);\n      ra_rename(as, left, dest);\n    } else {\n      emit_movrr(as, ir, dest, left);\n    }\n  }\n}\n#else\n/* Similar to ra_left, except we override any hints. */\nstatic void ra_leftov(ASMState *as, Reg dest, IRRef lref)\n{\n  IRIns *ir = IR(lref);\n  Reg left = ir->r;\n  if (ra_noreg(left)) {\n    ra_sethint(ir->r, dest);  /* Propagate register hint. */\n    left = ra_allocref(as, lref,\n\t\t       (LJ_SOFTFP || dest < RID_MAX_GPR) ? RSET_GPR : RSET_FPR);\n  }\n  ra_noweak(as, left);\n  if (dest != left) {\n    /* Use register renaming if dest is the PHI reg. */\n    if (irt_isphi(ir->t) && as->phireg[dest] == lref) {\n      ra_modified(as, left);\n      ra_rename(as, left, dest);\n    } else {\n      emit_movrr(as, ir, dest, left);\n    }\n  }\n}\n#endif\n\n#if !LJ_64\n/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */\nstatic void ra_destpair(ASMState *as, IRIns *ir)\n{\n  Reg destlo = ir->r, desthi = (ir+1)->r;\n  /* First spill unrelated refs blocking the destination registers. */\n  if (!rset_test(as->freeset, RID_RETLO) &&\n      destlo != RID_RETLO && desthi != RID_RETLO)\n    ra_restore(as, regcost_ref(as->cost[RID_RETLO]));\n  if (!rset_test(as->freeset, RID_RETHI) &&\n      destlo != RID_RETHI && desthi != RID_RETHI)\n    ra_restore(as, regcost_ref(as->cost[RID_RETHI]));\n  /* Next free the destination registers (if any). */\n  if (ra_hasreg(destlo)) {\n    ra_free(as, destlo);\n    ra_modified(as, destlo);\n  } else {\n    destlo = RID_RETLO;\n  }\n  if (ra_hasreg(desthi)) {\n    ra_free(as, desthi);\n    ra_modified(as, desthi);\n  } else {\n    desthi = RID_RETHI;\n  }\n  /* Check for conflicts and shuffle the registers as needed. */\n  if (destlo == RID_RETHI) {\n    if (desthi == RID_RETLO) {\n#if LJ_TARGET_X86\n      *--as->mcp = XI_XCHGa + RID_RETHI;\n#else\n      emit_movrr(as, ir, RID_RETHI, RID_TMP);\n      emit_movrr(as, ir, RID_RETLO, RID_RETHI);\n      emit_movrr(as, ir, RID_TMP, RID_RETLO);\n#endif\n    } else {\n      emit_movrr(as, ir, RID_RETHI, RID_RETLO);\n      if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);\n    }\n  } else if (desthi == RID_RETLO) {\n    emit_movrr(as, ir, RID_RETLO, RID_RETHI);\n    if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);\n  } else {\n    if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);\n    if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);\n  }\n  /* Restore spill slots (if any). */\n  if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI);\n  if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO);\n}\n#endif\n\n/* -- Snapshot handling --------- ----------------------------------------- */\n\n/* Can we rematerialize a KNUM instead of forcing a spill? */\nstatic int asm_snap_canremat(ASMState *as)\n{\n  Reg r;\n  for (r = RID_MIN_FPR; r < RID_MAX_FPR; r++)\n    if (irref_isk(regcost_ref(as->cost[r])))\n      return 1;\n  return 0;\n}\n\n/* Check whether a sunk store corresponds to an allocation. */\nstatic int asm_sunk_store(ASMState *as, IRIns *ira, IRIns *irs)\n{\n  if (irs->s == 255) {\n    if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\tirs->o == IR_FSTORE || irs->o == IR_XSTORE) {\n      IRIns *irk = IR(irs->op1);\n      if (irk->o == IR_AREF || irk->o == IR_HREFK)\n\tirk = IR(irk->op1);\n      return (IR(irk->op1) == ira);\n    }\n    return 0;\n  } else {\n    return (ira + irs->s == irs);  /* Quick check. */\n  }\n}\n\n/* Allocate register or spill slot for a ref that escapes to a snapshot. */\nstatic void asm_snap_alloc1(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (!irref_isk(ref) && (!(ra_used(ir) || ir->r == RID_SUNK))) {\n    if (ir->r == RID_SINK) {\n      ir->r = RID_SUNK;\n#if LJ_HASFFI\n      if (ir->o == IR_CNEWI) {  /* Allocate CNEWI value. */\n\tasm_snap_alloc1(as, ir->op2);\n\tif (LJ_32 && (ir+1)->o == IR_HIOP)\n\t  asm_snap_alloc1(as, (ir+1)->op2);\n      } else\n#endif\n      {  /* Allocate stored values for TNEW, TDUP and CNEW. */\n\tIRIns *irs;\n\tlua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW);\n\tfor (irs = IR(as->snapref-1); irs > ir; irs--)\n\t  if (irs->r == RID_SINK && asm_sunk_store(as, ir, irs)) {\n\t    lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\t\t       irs->o == IR_FSTORE || irs->o == IR_XSTORE);\n\t    asm_snap_alloc1(as, irs->op2);\n\t    if (LJ_32 && (irs+1)->o == IR_HIOP)\n\t      asm_snap_alloc1(as, (irs+1)->op2);\n\t  }\n      }\n    } else {\n      RegSet allow;\n      if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) {\n\tIRIns *irc;\n\tfor (irc = IR(as->curins); irc > ir; irc--)\n\t  if ((irc->op1 == ref || irc->op2 == ref) &&\n\t      !(irc->r == RID_SINK || irc->r == RID_SUNK))\n\t    goto nosink;  /* Don't sink conversion if result is used. */\n\tasm_snap_alloc1(as, ir->op1);\n\treturn;\n      }\n    nosink:\n      allow = (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR;\n      if ((as->freeset & allow) ||\n\t       (allow == RSET_FPR && asm_snap_canremat(as))) {\n\t/* Get a weak register if we have a free one or can rematerialize. */\n\tReg r = ra_allocref(as, ref, allow);  /* Allocate a register. */\n\tif (!irt_isphi(ir->t))\n\t  ra_weak(as, r);  /* But mark it as weakly referenced. */\n\tcheckmclim(as);\n\tRA_DBGX((as, \"snapreg   $f $r\", ref, ir->r));\n      } else {\n\tra_spill(as, ir);  /* Otherwise force a spill slot. */\n\tRA_DBGX((as, \"snapspill $f $s\", ref, ir->s));\n      }\n    }\n  }\n}\n\n/* Allocate refs escaping to a snapshot. */\nstatic void asm_snap_alloc(ASMState *as)\n{\n  SnapShot *snap = &as->T->snap[as->snapno];\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    IRRef ref = snap_ref(sn);\n    if (!irref_isk(ref)) {\n      asm_snap_alloc1(as, ref);\n      if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) {\n\tlua_assert(irt_type(IR(ref+1)->t) == IRT_SOFTFP);\n\tasm_snap_alloc1(as, ref+1);\n      }\n    }\n  }\n}\n\n/* All guards for a snapshot use the same exitno. This is currently the\n** same as the snapshot number. Since the exact origin of the exit cannot\n** be determined, all guards for the same snapshot must exit with the same\n** RegSP mapping.\n** A renamed ref which has been used in a prior guard for the same snapshot\n** would cause an inconsistency. The easy way out is to force a spill slot.\n*/\nstatic int asm_snap_checkrename(ASMState *as, IRRef ren)\n{\n  SnapShot *snap = &as->T->snap[as->snapno];\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    IRRef ref = snap_ref(sn);\n    if (ref == ren || (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && ++ref == ren)) {\n      IRIns *ir = IR(ref);\n      ra_spill(as, ir);  /* Register renamed, so force a spill slot. */\n      RA_DBGX((as, \"snaprensp $f $s\", ref, ir->s));\n      return 1;  /* Found. */\n    }\n  }\n  return 0;  /* Not found. */\n}\n\n/* Prepare snapshot for next guard instruction. */\nstatic void asm_snap_prep(ASMState *as)\n{\n  if (as->curins < as->snapref) {\n    do {\n      if (as->snapno == 0) return;  /* Called by sunk stores before snap #0. */\n      as->snapno--;\n      as->snapref = as->T->snap[as->snapno].ref;\n    } while (as->curins < as->snapref);\n    asm_snap_alloc(as);\n    as->snaprename = as->T->nins;\n  } else {\n    /* Process any renames above the highwater mark. */\n    for (; as->snaprename < as->T->nins; as->snaprename++) {\n      IRIns *ir = IR(as->snaprename);\n      if (asm_snap_checkrename(as, ir->op1))\n\tir->op2 = REF_BIAS-1;  /* Kill rename. */\n    }\n  }\n}\n\n/* -- Miscellaneous helpers ----------------------------------------------- */\n\n/* Calculate stack adjustment. */\nstatic int32_t asm_stack_adjust(ASMState *as)\n{\n  if (as->evenspill <= SPS_FIXED)\n    return 0;\n  return sps_scale(sps_align(as->evenspill));\n}\n\n/* Must match with hash*() in lj_tab.c. */\nstatic uint32_t ir_khash(IRIns *ir)\n{\n  uint32_t lo, hi;\n  if (irt_isstr(ir->t)) {\n    return ir_kstr(ir)->hash;\n  } else if (irt_isnum(ir->t)) {\n    lo = ir_knum(ir)->u32.lo;\n    hi = ir_knum(ir)->u32.hi << 1;\n  } else if (irt_ispri(ir->t)) {\n    lua_assert(!irt_isnil(ir->t));\n    return irt_type(ir->t)-IRT_FALSE;\n  } else {\n    lua_assert(irt_isgcv(ir->t));\n    lo = u32ptr(ir_kgc(ir));\n    hi = lo + HASH_BIAS;\n  }\n  return hashrot(lo, hi);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args);\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci);\n\nstatic void asm_snew(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_new];\n  IRRef args[3];\n  args[0] = ASMREF_L;  /* lua_State *L    */\n  args[1] = ir->op1;   /* const char *str */\n  args[2] = ir->op2;   /* size_t len      */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_tnew(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_new1];\n  IRRef args[2];\n  args[0] = ASMREF_L;     /* lua_State *L    */\n  args[1] = ASMREF_TMP1;  /* uint32_t ahsize */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCtab * */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, ir->op1 | (ir->op2 << 24), ra_releasetmp(as, ASMREF_TMP1));\n}\n\nstatic void asm_tdup(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_dup];\n  IRRef args[2];\n  args[0] = ASMREF_L;  /* lua_State *L    */\n  args[1] = ir->op1;   /* const GCtab *kt */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCtab * */\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_gc_check(ASMState *as);\n\n/* Explicit GC step. */\nstatic void asm_gcstep(ASMState *as, IRIns *ir)\n{\n  IRIns *ira;\n  for (ira = IR(as->stopins+1); ira < ir; ira++)\n    if ((ira->o == IR_TNEW || ira->o == IR_TDUP ||\n\t (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI))) &&\n\tra_used(ira))\n      as->gcsteps++;\n  if (as->gcsteps)\n    asm_gc_check(as);\n  as->gcsteps = 0x80000000;  /* Prevent implicit GC check further up. */\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref);\n\nstatic void asm_bufhdr(ASMState *as, IRIns *ir)\n{\n  Reg sb = ra_dest(as, ir, RSET_GPR);\n  if ((ir->op2 & IRBUFHDR_APPEND)) {\n    /* Rematerialize const buffer pointer instead of likely spill. */\n    IRIns *irp = IR(ir->op1);\n    if (!(ra_hasreg(irp->r) || irp == ir-1 ||\n\t  (irp == ir-2 && !ra_used(ir-1)))) {\n      while (!(irp->o == IR_BUFHDR && !(irp->op2 & IRBUFHDR_APPEND)))\n\tirp = IR(irp->op1);\n      if (irref_isk(irp->op1)) {\n\tra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));\n\tir = irp;\n      }\n    }\n  } else {\n    Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n    /* Passing ir isn't strictly correct, but it's an IRT_P32, too. */\n    emit_storeofs(as, ir, tmp, sb, offsetof(SBuf, p));\n    emit_loadofs(as, ir, tmp, sb, offsetof(SBuf, b));\n  }\n#if LJ_TARGET_X86ORX64\n  ra_left(as, sb, ir->op1);\n#else\n  ra_leftov(as, sb, ir->op1);\n#endif\n}\n\nstatic void asm_bufput(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_buf_putstr];\n  IRRef args[3];\n  IRIns *irs;\n  int kchar = -1;\n  args[0] = ir->op1;  /* SBuf * */\n  args[1] = ir->op2;  /* GCstr * */\n  irs = IR(ir->op2);\n  lua_assert(irt_isstr(irs->t));\n  if (irs->o == IR_KGC) {\n    GCstr *s = ir_kstr(irs);\n    if (s->len == 1) {  /* Optimize put of single-char string constant. */\n      kchar = strdata(s)[0];\n      args[1] = ASMREF_TMP1;  /* int, truncated to char */\n      ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar];\n    }\n  } else if (mayfuse(as, ir->op2) && ra_noreg(irs->r)) {\n    if (irs->o == IR_TOSTR) {  /* Fuse number to string conversions. */\n      if (irs->op2 == IRTOSTR_NUM) {\n\targs[1] = ASMREF_TMP1;  /* TValue * */\n\tci = &lj_ir_callinfo[IRCALL_lj_strfmt_putnum];\n      } else {\n\tlua_assert(irt_isinteger(IR(irs->op1)->t));\n\targs[1] = irs->op1;  /* int */\n\tif (irs->op2 == IRTOSTR_INT)\n\t  ci = &lj_ir_callinfo[IRCALL_lj_strfmt_putint];\n\telse\n\t  ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar];\n      }\n    } else if (irs->o == IR_SNEW) {  /* Fuse string allocation. */\n      args[1] = irs->op1;  /* const void * */\n      args[2] = irs->op2;  /* MSize */\n      ci = &lj_ir_callinfo[IRCALL_lj_buf_putmem];\n    }\n  }\n  asm_setupresult(as, ir, ci);  /* SBuf * */\n  asm_gencall(as, ci, args);\n  if (args[1] == ASMREF_TMP1) {\n    Reg tmp = ra_releasetmp(as, ASMREF_TMP1);\n    if (kchar == -1)\n      asm_tvptr(as, tmp, irs->op1);\n    else\n      ra_allockreg(as, kchar, tmp);\n  }\n}\n\nstatic void asm_bufstr(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_buf_tostr];\n  IRRef args[1];\n  args[0] = ir->op1;  /* SBuf *sb */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tostr(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci;\n  IRRef args[2];\n  args[0] = ASMREF_L;\n  as->gcsteps++;\n  if (ir->op2 == IRTOSTR_NUM) {\n    args[1] = ASMREF_TMP1;  /* cTValue * */\n    ci = &lj_ir_callinfo[IRCALL_lj_strfmt_num];\n  } else {\n    args[1] = ir->op1;  /* int32_t k */\n    if (ir->op2 == IRTOSTR_INT)\n      ci = &lj_ir_callinfo[IRCALL_lj_strfmt_int];\n    else\n      ci = &lj_ir_callinfo[IRCALL_lj_strfmt_char];\n  }\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n  if (ir->op2 == IRTOSTR_NUM)\n    asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);\n}\n\n#if LJ_32 && LJ_HASFFI && !LJ_SOFTFP && !LJ_TARGET_X86\nstatic void asm_conv64(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);\n  IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);\n  IRCallID id;\n  IRRef args[2];\n  lua_assert((ir-1)->o == IR_CONV && ir->o == IR_HIOP);\n  args[LJ_BE] = (ir-1)->op1;\n  args[LJ_LE] = ir->op1;\n  if (st == IRT_NUM || st == IRT_FLOAT) {\n    id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);\n    ir--;\n  } else {\n    id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);\n  }\n  {\n#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP\n    CCallInfo cim = lj_ir_callinfo[id], *ci = &cim;\n    cim.flags |= CCI_VARARG;  /* These calls don't use the hard-float ABI! */\n#else\n    const CCallInfo *ci = &lj_ir_callinfo[id];\n#endif\n    asm_setupresult(as, ir, ci);\n    asm_gencall(as, ci, args);\n  }\n}\n#endif\n\n/* -- Memory references --------------------------------------------------- */\n\nstatic void asm_newref(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];\n  IRRef args[3];\n  if (ir->r == RID_SINK)\n    return;\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ir->op1;      /* GCtab *t     */\n  args[2] = ASMREF_TMP1;  /* cTValue *key */\n  asm_setupresult(as, ir, ci);  /* TValue * */\n  asm_gencall(as, ci, args);\n  asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);\n}\n\nstatic void asm_lref(ASMState *as, IRIns *ir)\n{\n  Reg r = ra_dest(as, ir, RSET_GPR);\n#if LJ_TARGET_X86ORX64\n  ra_left(as, r, ASMREF_L);\n#else\n  ra_leftov(as, r, ASMREF_L);\n#endif\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Collect arguments from CALL* and CARG instructions. */\nstatic void asm_collectargs(ASMState *as, IRIns *ir,\n\t\t\t    const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n = CCI_XNARGS(ci);\n  lua_assert(n <= CCI_NARGS_MAX*2);  /* Account for split args. */\n  if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; }\n  while (n-- > 1) {\n    ir = IR(ir->op1);\n    lua_assert(ir->o == IR_CARG);\n    args[n] = ir->op2 == REF_NIL ? 0 : ir->op2;\n  }\n  args[0] = ir->op1 == REF_NIL ? 0 : ir->op1;\n  lua_assert(IR(ir->op1)->o != IR_CARG);\n}\n\n/* Reconstruct CCallInfo flags for CALLX*. */\nstatic uint32_t asm_callx_flags(ASMState *as, IRIns *ir)\n{\n  uint32_t nargs = 0;\n  if (ir->op1 != REF_NIL) {  /* Count number of arguments first. */\n    IRIns *ira = IR(ir->op1);\n    nargs++;\n    while (ira->o == IR_CARG) { nargs++; ira = IR(ira->op1); }\n  }\n#if LJ_HASFFI\n  if (IR(ir->op2)->o == IR_CARG) {  /* Copy calling convention info. */\n    CTypeID id = (CTypeID)IR(IR(ir->op2)->op2)->i;\n    CType *ct = ctype_get(ctype_ctsG(J2G(as->J)), id);\n    nargs |= ((ct->info & CTF_VARARG) ? CCI_VARARG : 0);\n#if LJ_TARGET_X86\n    nargs |= (ctype_cconv(ct->info) << CCI_CC_SHIFT);\n#endif\n  }\n#endif\n  return (nargs | (ir->t.irt << CCI_OTSHIFT));\n}\n\nstatic void asm_callid(ASMState *as, IRIns *ir, IRCallID id)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[id];\n  IRRef args[2];\n  args[0] = ir->op1;\n  args[1] = ir->op2;\n  asm_setupresult(as, ir, ci);\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_call(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX];\n  const CCallInfo *ci = &lj_ir_callinfo[ir->op2];\n  asm_collectargs(as, ir, ci, args);\n  asm_setupresult(as, ir, ci);\n  asm_gencall(as, ci, args);\n}\n\n#if !LJ_SOFTFP\nstatic void asm_fppow(ASMState *as, IRIns *ir, IRRef lref, IRRef rref)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];\n  IRRef args[2];\n  args[0] = lref;\n  args[1] = rref;\n  asm_setupresult(as, ir, ci);\n  asm_gencall(as, ci, args);\n}\n\nstatic int asm_fpjoin_pow(ASMState *as, IRIns *ir)\n{\n  IRIns *irp = IR(ir->op1);\n  if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {\n    IRIns *irpp = IR(irp->op1);\n    if (irpp == ir-2 && irpp->o == IR_FPMATH &&\n\tirpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {\n      asm_fppow(as, ir, irpp->op1, irp->op2);\n      return 1;\n    }\n  }\n  return 0;\n}\n#endif\n\n/* -- PHI and loop handling ----------------------------------------------- */\n\n/* Break a PHI cycle by renaming to a free register (evict if needed). */\nstatic void asm_phi_break(ASMState *as, RegSet blocked, RegSet blockedby,\n\t\t\t  RegSet allow)\n{\n  RegSet candidates = blocked & allow;\n  if (candidates) {  /* If this register file has candidates. */\n    /* Note: the set for ra_pick cannot be empty, since each register file\n    ** has some registers never allocated to PHIs.\n    */\n    Reg down, up = ra_pick(as, ~blocked & allow);  /* Get a free register. */\n    if (candidates & ~blockedby)  /* Optimize shifts, else it's a cycle. */\n      candidates = candidates & ~blockedby;\n    down = rset_picktop(candidates);  /* Pick candidate PHI register. */\n    ra_rename(as, down, up);  /* And rename it to the free register. */\n  }\n}\n\n/* PHI register shuffling.\n**\n** The allocator tries hard to preserve PHI register assignments across\n** the loop body. Most of the time this loop does nothing, since there\n** are no register mismatches.\n**\n** If a register mismatch is detected and ...\n** - the register is currently free: rename it.\n** - the register is blocked by an invariant: restore/remat and rename it.\n** - Otherwise the register is used by another PHI, so mark it as blocked.\n**\n** The renames are order-sensitive, so just retry the loop if a register\n** is marked as blocked, but has been freed in the meantime. A cycle is\n** detected if all of the blocked registers are allocated. To break the\n** cycle rename one of them to a free register and retry.\n**\n** Note that PHI spill slots are kept in sync and don't need to be shuffled.\n*/\nstatic void asm_phi_shuffle(ASMState *as)\n{\n  RegSet work;\n\n  /* Find and resolve PHI register mismatches. */\n  for (;;) {\n    RegSet blocked = RSET_EMPTY;\n    RegSet blockedby = RSET_EMPTY;\n    RegSet phiset = as->phiset;\n    while (phiset) {  /* Check all left PHI operand registers. */\n      Reg r = rset_pickbot(phiset);\n      IRIns *irl = IR(as->phireg[r]);\n      Reg left = irl->r;\n      if (r != left) {  /* Mismatch? */\n\tif (!rset_test(as->freeset, r)) {  /* PHI register blocked? */\n\t  IRRef ref = regcost_ref(as->cost[r]);\n\t  /* Blocked by other PHI (w/reg)? */\n\t  if (!ra_iskref(ref) && irt_ismarked(IR(ref)->t)) {\n\t    rset_set(blocked, r);\n\t    if (ra_hasreg(left))\n\t      rset_set(blockedby, left);\n\t    left = RID_NONE;\n\t  } else {  /* Otherwise grab register from invariant. */\n\t    ra_restore(as, ref);\n\t    checkmclim(as);\n\t  }\n\t}\n\tif (ra_hasreg(left)) {\n\t  ra_rename(as, left, r);\n\t  checkmclim(as);\n\t}\n      }\n      rset_clear(phiset, r);\n    }\n    if (!blocked) break;  /* Finished. */\n    if (!(as->freeset & blocked)) {  /* Break cycles if none are free. */\n      asm_phi_break(as, blocked, blockedby, RSET_GPR);\n      if (!LJ_SOFTFP) asm_phi_break(as, blocked, blockedby, RSET_FPR);\n      checkmclim(as);\n    }  /* Else retry some more renames. */\n  }\n\n  /* Restore/remat invariants whose registers are modified inside the loop. */\n#if !LJ_SOFTFP\n  work = as->modset & ~(as->freeset | as->phiset) & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n#endif\n  work = as->modset & ~(as->freeset | as->phiset);\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n\n  /* Allocate and save all unsaved PHI regs and clear marks. */\n  work = as->phiset;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef lref = as->phireg[r];\n    IRIns *ir = IR(lref);\n    if (ra_hasspill(ir->s)) {  /* Left PHI gained a spill slot? */\n      irt_clearmark(ir->t);  /* Handled here, so clear marker now. */\n      ra_alloc1(as, lref, RID2RSET(r));\n      ra_save(as, ir, r);  /* Save to spill slot inside the loop. */\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n}\n\n/* Copy unsynced left/right PHI spill slots. Rarely needed. */\nstatic void asm_phi_copyspill(ASMState *as)\n{\n  int need = 0;\n  IRIns *ir;\n  for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--)\n    if (ra_hasspill(ir->s) && ra_hasspill(IR(ir->op1)->s))\n      need |= irt_isfp(ir->t) ? 2 : 1;  /* Unsynced spill slot? */\n  if ((need & 1)) {  /* Copy integer spill slots. */\n#if !LJ_TARGET_X86ORX64\n    Reg r = RID_TMP;\n#else\n    Reg r = RID_RET;\n    if ((as->freeset & RSET_GPR))\n      r = rset_pickbot((as->freeset & RSET_GPR));\n    else\n      emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n#endif\n    for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {\n      if (ra_hasspill(ir->s)) {\n\tIRIns *irl = IR(ir->op1);\n\tif (ra_hasspill(irl->s) && !irt_isfp(ir->t)) {\n\t  emit_spstore(as, irl, r, sps_scale(irl->s));\n\t  emit_spload(as, ir, r, sps_scale(ir->s));\n\t  checkmclim(as);\n\t}\n      }\n    }\n#if LJ_TARGET_X86ORX64\n    if (!rset_test(as->freeset, r))\n      emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n#endif\n  }\n#if !LJ_SOFTFP\n  if ((need & 2)) {  /* Copy FP spill slots. */\n#if LJ_TARGET_X86\n    Reg r = RID_XMM0;\n#else\n    Reg r = RID_FPRET;\n#endif\n    if ((as->freeset & RSET_FPR))\n      r = rset_pickbot((as->freeset & RSET_FPR));\n    if (!rset_test(as->freeset, r))\n      emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n    for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {\n      if (ra_hasspill(ir->s)) {\n\tIRIns *irl = IR(ir->op1);\n\tif (ra_hasspill(irl->s) && irt_isfp(ir->t)) {\n\t  emit_spstore(as, irl, r, sps_scale(irl->s));\n\t  emit_spload(as, ir, r, sps_scale(ir->s));\n\t  checkmclim(as);\n\t}\n      }\n    }\n    if (!rset_test(as->freeset, r))\n      emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n  }\n#endif\n}\n\n/* Emit renames for left PHIs which are only spilled outside the loop. */\nstatic void asm_phi_fixup(ASMState *as)\n{\n  RegSet work = as->phiset;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef lref = as->phireg[r];\n    IRIns *ir = IR(lref);\n    if (irt_ismarked(ir->t)) {\n      irt_clearmark(ir->t);\n      /* Left PHI gained a spill slot before the loop? */\n      if (ra_hasspill(ir->s)) {\n\tIRRef ren;\n\tlj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), lref, as->loopsnapno);\n\tren = tref_ref(lj_ir_emit(as->J));\n\tas->ir = as->T->ir;  /* The IR may have been reallocated. */\n\tIR(ren)->r = (uint8_t)r;\n\tIR(ren)->s = SPS_NONE;\n      }\n    }\n    rset_clear(work, r);\n  }\n}\n\n/* Setup right PHI reference. */\nstatic void asm_phi(ASMState *as, IRIns *ir)\n{\n  RegSet allow = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) &\n\t\t ~as->phiset;\n  RegSet afree = (as->freeset & allow);\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  if (ir->r == RID_SINK)  /* Sink PHI. */\n    return;\n  /* Spill slot shuffling is not implemented yet (but rarely needed). */\n  if (ra_hasspill(irl->s) || ra_hasspill(irr->s))\n    lj_trace_err(as->J, LJ_TRERR_NYIPHI);\n  /* Leave at least one register free for non-PHIs (and PHI cycle breaking). */\n  if ((afree & (afree-1))) {  /* Two or more free registers? */\n    Reg r;\n    if (ra_noreg(irr->r)) {  /* Get a register for the right PHI. */\n      r = ra_allocref(as, ir->op2, allow);\n    } else {  /* Duplicate right PHI, need a copy (rare). */\n      r = ra_scratch(as, allow);\n      emit_movrr(as, irr, r, irr->r);\n    }\n    ir->r = (uint8_t)r;\n    rset_set(as->phiset, r);\n    as->phireg[r] = (IRRef1)ir->op1;\n    irt_setmark(irl->t);  /* Marks left PHIs _with_ register. */\n    if (ra_noreg(irl->r))\n      ra_sethint(irl->r, r); /* Set register hint for left PHI. */\n  } else {  /* Otherwise allocate a spill slot. */\n    /* This is overly restrictive, but it triggers only on synthetic code. */\n    if (ra_hasreg(irl->r) || ra_hasreg(irr->r))\n      lj_trace_err(as->J, LJ_TRERR_NYIPHI);\n    ra_spill(as, ir);\n    irr->s = ir->s;  /* Set right PHI spill slot. Sync left slot later. */\n  }\n}\n\nstatic void asm_loop_fixup(ASMState *as);\n\n/* Middle part of a loop. */\nstatic void asm_loop(ASMState *as)\n{\n  MCode *mcspill;\n  /* LOOP is a guard, so the snapno is up to date. */\n  as->loopsnapno = as->snapno;\n  if (as->gcsteps)\n    asm_gc_check(as);\n  /* LOOP marks the transition from the variant to the invariant part. */\n  as->flagmcp = as->invmcp = NULL;\n  as->sectref = 0;\n  if (!neverfuse(as)) as->fuseref = 0;\n  asm_phi_shuffle(as);\n  mcspill = as->mcp;\n  asm_phi_copyspill(as);\n  asm_loop_fixup(as);\n  as->mcloop = as->mcp;\n  RA_DBGX((as, \"===== LOOP =====\"));\n  if (!as->realign) RA_DBG_FLUSH();\n  if (as->mcp != mcspill)\n    emit_jmp(as, mcspill);\n}\n\n/* -- Target-specific assembler ------------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_asm_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_asm_arm.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_asm_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_asm_mips.h\"\n#else\n#error \"Missing assembler for target CPU\"\n#endif\n\n/* -- Instruction dispatch ------------------------------------------------ */\n\n/* Assemble a single instruction. */\nstatic void asm_ir(ASMState *as, IRIns *ir)\n{\n  switch ((IROp)ir->o) {\n  /* Miscellaneous ops. */\n  case IR_LOOP: asm_loop(as); break;\n  case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;\n  case IR_USE:\n    ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;\n  case IR_PHI: asm_phi(as, ir); break;\n  case IR_HIOP: asm_hiop(as, ir); break;\n  case IR_GCSTEP: asm_gcstep(as, ir); break;\n  case IR_PROF: asm_prof(as, ir); break;\n\n  /* Guarded assertions. */\n  case IR_LT: case IR_GE: case IR_LE: case IR_GT:\n  case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:\n  case IR_ABC:\n    asm_comp(as, ir);\n    break;\n  case IR_EQ: case IR_NE:\n    if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {\n      as->curins--;\n      asm_href(as, ir-1, (IROp)ir->o);\n    } else {\n      asm_equal(as, ir);\n    }\n    break;\n\n  case IR_RETF: asm_retf(as, ir); break;\n\n  /* Bit ops. */\n  case IR_BNOT: asm_bnot(as, ir); break;\n  case IR_BSWAP: asm_bswap(as, ir); break;\n  case IR_BAND: asm_band(as, ir); break;\n  case IR_BOR: asm_bor(as, ir); break;\n  case IR_BXOR: asm_bxor(as, ir); break;\n  case IR_BSHL: asm_bshl(as, ir); break;\n  case IR_BSHR: asm_bshr(as, ir); break;\n  case IR_BSAR: asm_bsar(as, ir); break;\n  case IR_BROL: asm_brol(as, ir); break;\n  case IR_BROR: asm_bror(as, ir); break;\n\n  /* Arithmetic ops. */\n  case IR_ADD: asm_add(as, ir); break;\n  case IR_SUB: asm_sub(as, ir); break;\n  case IR_MUL: asm_mul(as, ir); break;\n  case IR_MOD: asm_mod(as, ir); break;\n  case IR_NEG: asm_neg(as, ir); break;\n#if LJ_SOFTFP\n  case IR_DIV: case IR_POW: case IR_ABS:\n  case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:\n    lua_assert(0);  /* Unused for LJ_SOFTFP. */\n    break;\n#else\n  case IR_DIV: asm_div(as, ir); break;\n  case IR_POW: asm_pow(as, ir); break;\n  case IR_ABS: asm_abs(as, ir); break;\n  case IR_ATAN2: asm_atan2(as, ir); break;\n  case IR_LDEXP: asm_ldexp(as, ir); break;\n  case IR_FPMATH: asm_fpmath(as, ir); break;\n  case IR_TOBIT: asm_tobit(as, ir); break;\n#endif\n  case IR_MIN: asm_min(as, ir); break;\n  case IR_MAX: asm_max(as, ir); break;\n\n  /* Overflow-checking arithmetic ops. */\n  case IR_ADDOV: asm_addov(as, ir); break;\n  case IR_SUBOV: asm_subov(as, ir); break;\n  case IR_MULOV: asm_mulov(as, ir); break;\n\n  /* Memory references. */\n  case IR_AREF: asm_aref(as, ir); break;\n  case IR_HREF: asm_href(as, ir, 0); break;\n  case IR_HREFK: asm_hrefk(as, ir); break;\n  case IR_NEWREF: asm_newref(as, ir); break;\n  case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;\n  case IR_FREF: asm_fref(as, ir); break;\n  case IR_STRREF: asm_strref(as, ir); break;\n  case IR_LREF: asm_lref(as, ir); break;\n\n  /* Loads and stores. */\n  case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n    asm_ahuvload(as, ir);\n    break;\n  case IR_FLOAD: asm_fload(as, ir); break;\n  case IR_XLOAD: asm_xload(as, ir); break;\n  case IR_SLOAD: asm_sload(as, ir); break;\n\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;\n  case IR_FSTORE: asm_fstore(as, ir); break;\n  case IR_XSTORE: asm_xstore(as, ir); break;\n\n  /* Allocations. */\n  case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;\n  case IR_TNEW: asm_tnew(as, ir); break;\n  case IR_TDUP: asm_tdup(as, ir); break;\n  case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;\n\n  /* Buffer operations. */\n  case IR_BUFHDR: asm_bufhdr(as, ir); break;\n  case IR_BUFPUT: asm_bufput(as, ir); break;\n  case IR_BUFSTR: asm_bufstr(as, ir); break;\n\n  /* Write barriers. */\n  case IR_TBAR: asm_tbar(as, ir); break;\n  case IR_OBAR: asm_obar(as, ir); break;\n\n  /* Type conversions. */\n  case IR_CONV: asm_conv(as, ir); break;\n  case IR_TOSTR: asm_tostr(as, ir); break;\n  case IR_STRTO: asm_strto(as, ir); break;\n\n  /* Calls. */\n  case IR_CALLA:\n    as->gcsteps++;\n    /* fallthrough */\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;\n  case IR_CALLXS: asm_callx(as, ir); break;\n  case IR_CARG: break;\n\n  default:\n    setintV(&as->J->errinfo, ir->o);\n    lj_trace_err_info(as->J, LJ_TRERR_NYIIR);\n    break;\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Head of a root trace. */\nstatic void asm_head_root(ASMState *as)\n{\n  int32_t spadj;\n  asm_head_root_base(as);\n  emit_setvmstate(as, (int32_t)as->T->traceno);\n  spadj = asm_stack_adjust(as);\n  as->T->spadjust = (uint16_t)spadj;\n  emit_spsub(as, spadj);\n  /* Root traces assume a checked stack for the starting proto. */\n  as->T->topslot = gcref(as->T->startpt)->pt.framesize;\n}\n\n/* Head of a side trace.\n**\n** The current simplistic algorithm requires that all slots inherited\n** from the parent are live in a register between pass 2 and pass 3. This\n** avoids the complexity of stack slot shuffling. But of course this may\n** overflow the register set in some cases and cause the dreaded error:\n** \"NYI: register coalescing too complex\". A refined algorithm is needed.\n*/\nstatic void asm_head_side(ASMState *as)\n{\n  IRRef1 sloadins[RID_MAX];\n  RegSet allow = RSET_ALL;  /* Inverse of all coalesced registers. */\n  RegSet live = RSET_EMPTY;  /* Live parent registers. */\n  IRIns *irp = &as->parent->ir[REF_BASE];  /* Parent base. */\n  int32_t spadj, spdelta;\n  int pass2 = 0;\n  int pass3 = 0;\n  IRRef i;\n\n  if (as->snapno && as->topslot > as->parent->topslot) {\n    /* Force snap #0 alloc to prevent register overwrite in stack check. */\n    as->snapno = 0;\n    asm_snap_alloc(as);\n  }\n  allow = asm_head_side_base(as, irp, allow);\n\n  /* Scan all parent SLOADs and collect register dependencies. */\n  for (i = as->stopins; i > REF_BASE; i--) {\n    IRIns *ir = IR(i);\n    RegSP rs;\n    lua_assert((ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_PARENT)) ||\n\t       (LJ_SOFTFP && ir->o == IR_HIOP) || ir->o == IR_PVAL);\n    rs = as->parentmap[i - REF_FIRST];\n    if (ra_hasreg(ir->r)) {\n      rset_clear(allow, ir->r);\n      if (ra_hasspill(ir->s)) {\n\tra_save(as, ir, ir->r);\n\tcheckmclim(as);\n      }\n    } else if (ra_hasspill(ir->s)) {\n      irt_setmark(ir->t);\n      pass2 = 1;\n    }\n    if (ir->r == rs) {  /* Coalesce matching registers right now. */\n      ra_free(as, ir->r);\n    } else if (ra_hasspill(regsp_spill(rs))) {\n      if (ra_hasreg(ir->r))\n\tpass3 = 1;\n    } else if (ra_used(ir)) {\n      sloadins[rs] = (IRRef1)i;\n      rset_set(live, rs);  /* Block live parent register. */\n    }\n  }\n\n  /* Calculate stack frame adjustment. */\n  spadj = asm_stack_adjust(as);\n  spdelta = spadj - (int32_t)as->parent->spadjust;\n  if (spdelta < 0) {  /* Don't shrink the stack frame. */\n    spadj = (int32_t)as->parent->spadjust;\n    spdelta = 0;\n  }\n  as->T->spadjust = (uint16_t)spadj;\n\n  /* Reload spilled target registers. */\n  if (pass2) {\n    for (i = as->stopins; i > REF_BASE; i--) {\n      IRIns *ir = IR(i);\n      if (irt_ismarked(ir->t)) {\n\tRegSet mask;\n\tReg r;\n\tRegSP rs;\n\tirt_clearmark(ir->t);\n\trs = as->parentmap[i - REF_FIRST];\n\tif (!ra_hasspill(regsp_spill(rs)))\n\t  ra_sethint(ir->r, rs);  /* Hint may be gone, set it again. */\n\telse if (sps_scale(regsp_spill(rs))+spdelta == sps_scale(ir->s))\n\t  continue;  /* Same spill slot, do nothing. */\n\tmask = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & allow;\n\tif (mask == RSET_EMPTY)\n\t  lj_trace_err(as->J, LJ_TRERR_NYICOAL);\n\tr = ra_allocref(as, i, mask);\n\tra_save(as, ir, r);\n\trset_clear(allow, r);\n\tif (r == rs) {  /* Coalesce matching registers right now. */\n\t  ra_free(as, r);\n\t  rset_clear(live, r);\n\t} else if (ra_hasspill(regsp_spill(rs))) {\n\t  pass3 = 1;\n\t}\n\tcheckmclim(as);\n      }\n    }\n  }\n\n  /* Store trace number and adjust stack frame relative to the parent. */\n  emit_setvmstate(as, (int32_t)as->T->traceno);\n  emit_spsub(as, spdelta);\n\n#if !LJ_TARGET_X86ORX64\n  /* Restore BASE register from parent spill slot. */\n  if (ra_hasspill(irp->s))\n    emit_spload(as, IR(REF_BASE), IR(REF_BASE)->r, sps_scale(irp->s));\n#endif\n\n  /* Restore target registers from parent spill slots. */\n  if (pass3) {\n    RegSet work = ~as->freeset & RSET_ALL;\n    while (work) {\n      Reg r = rset_pickbot(work);\n      IRRef ref = regcost_ref(as->cost[r]);\n      RegSP rs = as->parentmap[ref - REF_FIRST];\n      rset_clear(work, r);\n      if (ra_hasspill(regsp_spill(rs))) {\n\tint32_t ofs = sps_scale(regsp_spill(rs));\n\tra_free(as, r);\n\temit_spload(as, IR(ref), r, ofs);\n\tcheckmclim(as);\n      }\n    }\n  }\n\n  /* Shuffle registers to match up target regs with parent regs. */\n  for (;;) {\n    RegSet work;\n\n    /* Repeatedly coalesce free live registers by moving to their target. */\n    while ((work = as->freeset & live) != RSET_EMPTY) {\n      Reg rp = rset_pickbot(work);\n      IRIns *ir = IR(sloadins[rp]);\n      rset_clear(live, rp);\n      rset_clear(allow, rp);\n      ra_free(as, ir->r);\n      emit_movrr(as, ir, ir->r, rp);\n      checkmclim(as);\n    }\n\n    /* We're done if no live registers remain. */\n    if (live == RSET_EMPTY)\n      break;\n\n    /* Break cycles by renaming one target to a temp. register. */\n    if (live & RSET_GPR) {\n      RegSet tmpset = as->freeset & ~live & allow & RSET_GPR;\n      if (tmpset == RSET_EMPTY)\n\tlj_trace_err(as->J, LJ_TRERR_NYICOAL);\n      ra_rename(as, rset_pickbot(live & RSET_GPR), rset_pickbot(tmpset));\n    }\n    if (!LJ_SOFTFP && (live & RSET_FPR)) {\n      RegSet tmpset = as->freeset & ~live & allow & RSET_FPR;\n      if (tmpset == RSET_EMPTY)\n\tlj_trace_err(as->J, LJ_TRERR_NYICOAL);\n      ra_rename(as, rset_pickbot(live & RSET_FPR), rset_pickbot(tmpset));\n    }\n    checkmclim(as);\n    /* Continue with coalescing to fix up the broken cycle(s). */\n  }\n\n  /* Inherit top stack slot already checked by parent trace. */\n  as->T->topslot = as->parent->topslot;\n  if (as->topslot > as->T->topslot) {  /* Need to check for higher slot? */\n#ifdef EXITSTATE_CHECKEXIT\n    /* Highest exit + 1 indicates stack check. */\n    ExitNo exitno = as->T->nsnap;\n#else\n    /* Reuse the parent exit in the context of the parent trace. */\n    ExitNo exitno = as->J->exitno;\n#endif\n    as->T->topslot = (uint8_t)as->topslot;  /* Remember for child traces. */\n    asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno);\n  }\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Get base slot for a snapshot. */\nstatic BCReg asm_baseslot(ASMState *as, SnapShot *snap, int *gotframe)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  MSize n;\n  for (n = snap->nent; n > 0; n--) {\n    SnapEntry sn = map[n-1];\n    if ((sn & SNAP_FRAME)) {\n      *gotframe = 1;\n      return snap_slot(sn);\n    }\n  }\n  return 0;\n}\n\n/* Link to another trace. */\nstatic void asm_tail_link(ASMState *as)\n{\n  SnapNo snapno = as->T->nsnap-1;  /* Last snapshot. */\n  SnapShot *snap = &as->T->snap[snapno];\n  int gotframe = 0;\n  BCReg baseslot = asm_baseslot(as, snap, &gotframe);\n\n  as->topslot = snap->topslot;\n  checkmclim(as);\n  ra_allocref(as, REF_BASE, RID2RSET(RID_BASE));\n\n  if (as->T->link == 0) {\n    /* Setup fixed registers for exit to interpreter. */\n    const BCIns *pc = snap_pc(as->T->snapmap[snap->mapofs + snap->nent]);\n    int32_t mres;\n    if (bc_op(*pc) == BC_JLOOP) {  /* NYI: find a better way to do this. */\n      BCIns *retpc = &traceref(as->J, bc_d(*pc))->startins;\n      if (bc_isret(bc_op(*retpc)))\n\tpc = retpc;\n    }\n    ra_allockreg(as, i32ptr(J2GG(as->J)->dispatch), RID_DISPATCH);\n    ra_allockreg(as, i32ptr(pc), RID_LPC);\n    mres = (int32_t)(snap->nslots - baseslot);\n    switch (bc_op(*pc)) {\n    case BC_CALLM: case BC_CALLMT:\n      mres -= (int32_t)(1 + LJ_FR2 + bc_a(*pc) + bc_c(*pc)); break;\n    case BC_RETM: mres -= (int32_t)(bc_a(*pc) + bc_d(*pc)); break;\n    case BC_TSETM: mres -= (int32_t)bc_a(*pc); break;\n    default: if (bc_op(*pc) < BC_FUNCF) mres = 0; break;\n    }\n    ra_allockreg(as, mres, RID_RET);  /* Return MULTRES or 0. */\n  } else if (baseslot) {\n    /* Save modified BASE for linking to trace with higher start frame. */\n    emit_setgl(as, RID_BASE, jit_base);\n  }\n  emit_addptr(as, RID_BASE, 8*(int32_t)baseslot);\n\n  /* Sync the interpreter state with the on-trace state. */\n  asm_stack_restore(as, snap);\n\n  /* Root traces that add frames need to check the stack at the end. */\n  if (!as->parent && gotframe)\n    asm_stack_check(as, as->topslot, NULL, as->freeset & RSET_GPR, snapno);\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Clear reg/sp for all instructions and add register hints. */\nstatic void asm_setup_regsp(ASMState *as)\n{\n  GCtrace *T = as->T;\n  int sink = T->sinktags;\n  IRRef nins = T->nins;\n  IRIns *ir, *lastir;\n  int inloop;\n#if LJ_TARGET_ARM\n  uint32_t rload = 0xa6402a64;\n#endif\n\n  ra_setup(as);\n\n  /* Clear reg/sp for constants. */\n  for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++)\n    ir->prev = REGSP_INIT;\n\n  /* REF_BASE is used for implicit references to the BASE register. */\n  lastir->prev = REGSP_HINT(RID_BASE);\n\n  ir = IR(nins-1);\n  if (ir->o == IR_RENAME) {\n    do { ir--; nins--; } while (ir->o == IR_RENAME);\n    T->nins = nins;  /* Remove any renames left over from ASM restart. */\n  }\n  as->snaprename = nins;\n  as->snapref = nins;\n  as->snapno = T->nsnap;\n\n  as->stopins = REF_BASE;\n  as->orignins = nins;\n  as->curins = nins;\n\n  /* Setup register hints for parent link instructions. */\n  ir = IR(REF_FIRST);\n  if (as->parent) {\n    uint16_t *p;\n    lastir = lj_snap_regspmap(as->parent, as->J->exitno, ir);\n    if (lastir - ir > LJ_MAX_JSLOTS)\n      lj_trace_err(as->J, LJ_TRERR_NYICOAL);\n    as->stopins = (IRRef)((lastir-1) - as->ir);\n    for (p = as->parentmap; ir < lastir; ir++) {\n      RegSP rs = ir->prev;\n      *p++ = (uint16_t)rs;  /* Copy original parent RegSP to parentmap. */\n      if (!ra_hasspill(regsp_spill(rs)))\n\tir->prev = (uint16_t)REGSP_HINT(regsp_reg(rs));\n      else\n\tir->prev = REGSP_INIT;\n    }\n  }\n\n  inloop = 0;\n  as->evenspill = SPS_FIRST;\n  for (lastir = IR(nins); ir < lastir; ir++) {\n    if (sink) {\n      if (ir->r == RID_SINK)\n\tcontinue;\n      if (ir->r == RID_SUNK) {  /* Revert after ASM restart. */\n\tir->r = RID_SINK;\n\tcontinue;\n      }\n    }\n    switch (ir->o) {\n    case IR_LOOP:\n      inloop = 1;\n      break;\n#if LJ_TARGET_ARM\n    case IR_SLOAD:\n      if (!((ir->op2 & IRSLOAD_TYPECHECK) || (ir+1)->o == IR_HIOP))\n\tbreak;\n      /* fallthrough */\n    case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n      if (!LJ_SOFTFP && irt_isnum(ir->t)) break;\n      ir->prev = (uint16_t)REGSP_HINT((rload & 15));\n      rload = lj_ror(rload, 4);\n      continue;\n#endif\n    case IR_CALLXS: {\n      CCallInfo ci;\n      ci.flags = asm_callx_flags(as, ir);\n      ir->prev = asm_setup_call_slots(as, ir, &ci);\n      if (inloop)\n\tas->modset |= RSET_SCRATCH;\n      continue;\n      }\n    case IR_CALLN: case IR_CALLA: case IR_CALLL: case IR_CALLS: {\n      const CCallInfo *ci = &lj_ir_callinfo[ir->op2];\n      ir->prev = asm_setup_call_slots(as, ir, ci);\n      if (inloop)\n\tas->modset |= (ci->flags & CCI_NOFPRCLOBBER) ?\n\t\t      (RSET_SCRATCH & ~RSET_FPR) : RSET_SCRATCH;\n      continue;\n      }\n#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)\n    case IR_HIOP:\n      switch ((ir-1)->o) {\n#if LJ_SOFTFP && LJ_TARGET_ARM\n      case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n\tif (ra_hashint((ir-1)->r)) {\n\t  ir->prev = (ir-1)->prev + 1;\n\t  continue;\n\t}\n\tbreak;\n#endif\n#if !LJ_SOFTFP && LJ_NEED_FP64\n      case IR_CONV:\n\tif (irt_isfp((ir-1)->t)) {\n\t  ir->prev = REGSP_HINT(RID_FPRET);\n\t  continue;\n\t}\n\t/* fallthrough */\n#endif\n      case IR_CALLN: case IR_CALLXS:\n#if LJ_SOFTFP\n      case IR_MIN: case IR_MAX:\n#endif\n\t(ir-1)->prev = REGSP_HINT(RID_RETLO);\n\tir->prev = REGSP_HINT(RID_RETHI);\n\tcontinue;\n      default:\n\tbreak;\n      }\n      break;\n#endif\n#if LJ_SOFTFP\n    case IR_MIN: case IR_MAX:\n      if ((ir+1)->o != IR_HIOP) break;\n      /* fallthrough */\n#endif\n    /* C calls evict all scratch regs and return results in RID_RET. */\n    case IR_SNEW: case IR_XSNEW: case IR_NEWREF: case IR_BUFPUT:\n      if (REGARG_NUMGPR < 3 && as->evenspill < 3)\n\tas->evenspill = 3;  /* lj_str_new and lj_tab_newkey need 3 args. */\n#if LJ_TARGET_X86 && LJ_HASFFI\n      if (0) {\n    case IR_CNEW:\n\tif (ir->op2 != REF_NIL && as->evenspill < 4)\n\t  as->evenspill = 4;  /* lj_cdata_newv needs 4 args. */\n      }\n#else\n    case IR_CNEW:\n#endif\n    case IR_TNEW: case IR_TDUP: case IR_CNEWI: case IR_TOSTR:\n    case IR_BUFSTR:\n      ir->prev = REGSP_HINT(RID_RET);\n      if (inloop)\n\tas->modset = RSET_SCRATCH;\n      continue;\n    case IR_STRTO: case IR_OBAR:\n      if (inloop)\n\tas->modset = RSET_SCRATCH;\n      break;\n#if !LJ_SOFTFP\n    case IR_ATAN2:\n#if LJ_TARGET_X86\n      if (as->evenspill < 4)  /* Leave room to call atan2(). */\n\tas->evenspill = 4;\n#endif\n#if !LJ_TARGET_X86ORX64\n    case IR_LDEXP:\n#endif\n#endif\n    case IR_POW:\n      if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n\tif (inloop)\n\t  as->modset |= RSET_SCRATCH;\n#if LJ_TARGET_X86\n\tbreak;\n#else\n\tir->prev = REGSP_HINT(RID_FPRET);\n\tcontinue;\n#endif\n      }\n      /* fallthrough for integer POW */\n    case IR_DIV: case IR_MOD:\n      if (!irt_isnum(ir->t)) {\n\tir->prev = REGSP_HINT(RID_RET);\n\tif (inloop)\n\t  as->modset |= (RSET_SCRATCH & RSET_GPR);\n\tcontinue;\n      }\n      break;\n    case IR_FPMATH:\n#if LJ_TARGET_X86ORX64\n      if (ir->op2 <= IRFPM_TRUNC) {\n\tif (!(as->flags & JIT_F_SSE4_1)) {\n\t  ir->prev = REGSP_HINT(RID_XMM0);\n\t  if (inloop)\n\t    as->modset |= RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);\n\t  continue;\n\t}\n\tbreak;\n      } else if (ir->op2 == IRFPM_EXP2 && !LJ_64) {\n\tif (as->evenspill < 4)  /* Leave room to call pow(). */\n\t  as->evenspill = 4;\n      }\n#endif\n      if (inloop)\n\tas->modset |= RSET_SCRATCH;\n#if LJ_TARGET_X86\n      break;\n#else\n      ir->prev = REGSP_HINT(RID_FPRET);\n      continue;\n#endif\n#if LJ_TARGET_X86ORX64\n    /* Non-constant shift counts need to be in RID_ECX on x86/x64. */\n    case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR:\n      if (!irref_isk(ir->op2) && !ra_hashint(IR(ir->op2)->r)) {\n\tIR(ir->op2)->r = REGSP_HINT(RID_ECX);\n\tif (inloop)\n\t  rset_set(as->modset, RID_ECX);\n      }\n      break;\n#endif\n    /* Do not propagate hints across type conversions or loads. */\n    case IR_TOBIT:\n    case IR_XLOAD:\n#if !LJ_TARGET_ARM\n    case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n#endif\n      break;\n    case IR_CONV:\n      if (irt_isfp(ir->t) || (ir->op2 & IRCONV_SRCMASK) == IRT_NUM ||\n\t  (ir->op2 & IRCONV_SRCMASK) == IRT_FLOAT)\n\tbreak;\n      /* fallthrough */\n    default:\n      /* Propagate hints across likely 'op reg, imm' or 'op reg'. */\n      if (irref_isk(ir->op2) && !irref_isk(ir->op1) &&\n\t  ra_hashint(regsp_reg(IR(ir->op1)->prev))) {\n\tir->prev = IR(ir->op1)->prev;\n\tcontinue;\n      }\n      break;\n    }\n    ir->prev = REGSP_INIT;\n  }\n  if ((as->evenspill & 1))\n    as->oddspill = as->evenspill++;\n  else\n    as->oddspill = 0;\n}\n\n/* -- Assembler core ------------------------------------------------------ */\n\n/* Assemble a trace. */\nvoid lj_asm_trace(jit_State *J, GCtrace *T)\n{\n  ASMState as_;\n  ASMState *as = &as_;\n  MCode *origtop;\n\n  /* Ensure an initialized instruction beyond the last one for HIOP checks. */\n  J->cur.nins = lj_ir_nextins(J);\n  J->cur.ir[J->cur.nins].o = IR_NOP;\n\n  /* Setup initial state. Copy some fields to reduce indirections. */\n  as->J = J;\n  as->T = T;\n  as->ir = T->ir;\n  as->flags = J->flags;\n  as->loopref = J->loopref;\n  as->realign = NULL;\n  as->loopinv = 0;\n  as->parent = J->parent ? traceref(J, J->parent) : NULL;\n\n  /* Reserve MCode memory. */\n  as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot);\n  as->mcp = as->mctop;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  asm_setup_target(as);\n\n  do {\n    as->mcp = as->mctop;\n#ifdef LUA_USE_ASSERT\n    as->mcp_prev = as->mcp;\n#endif\n    as->curins = T->nins;\n    RA_DBG_START();\n    RA_DBGX((as, \"===== STOP =====\"));\n\n    /* General trace setup. Emit tail of trace. */\n    asm_tail_prep(as);\n    as->mcloop = NULL;\n    as->flagmcp = NULL;\n    as->topslot = 0;\n    as->gcsteps = 0;\n    as->sectref = as->loopref;\n    as->fuseref = (as->flags & JIT_F_OPT_FUSE) ? as->loopref : FUSE_DISABLED;\n    asm_setup_regsp(as);\n    if (!as->loopref)\n      asm_tail_link(as);\n\n    /* Assemble a trace in linear backwards order. */\n    for (as->curins--; as->curins > as->stopins; as->curins--) {\n      IRIns *ir = IR(as->curins);\n      lua_assert(!(LJ_32 && irt_isint64(ir->t)));  /* Handled by SPLIT. */\n      if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE))\n\tcontinue;  /* Dead-code elimination can be soooo easy. */\n      if (irt_isguard(ir->t))\n\tasm_snap_prep(as);\n      RA_DBG_REF();\n      checkmclim(as);\n      asm_ir(as, ir);\n    }\n  } while (as->realign);  /* Retry in case the MCode needs to be realigned. */\n\n  /* Emit head of trace. */\n  RA_DBG_REF();\n  checkmclim(as);\n  if (as->gcsteps > 0) {\n    as->curins = as->T->snap[0].ref;\n    asm_snap_prep(as);  /* The GC check is a guard. */\n    asm_gc_check(as);\n  }\n  ra_evictk(as);\n  if (as->parent)\n    asm_head_side(as);\n  else\n    asm_head_root(as);\n  asm_phi_fixup(as);\n\n  RA_DBGX((as, \"===== START ====\"));\n  RA_DBG_FLUSH();\n  if (as->freeset != RSET_ALL)\n    lj_trace_err(as->J, LJ_TRERR_BADRA);  /* Ouch! Should never happen. */\n\n  /* Set trace entry point before fixing up tail to allow link to self. */\n  T->mcode = as->mcp;\n  T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0;\n  if (!as->loopref)\n    asm_tail_fixup(as, T->link);  /* Note: this may change as->mctop! */\n  T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp);\n  lj_mcode_sync(T->mcode, origtop);\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm.h",
    "content": "/*\n** IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ASM_H\n#define _LJ_ASM_H\n\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\nLJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T);\nLJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno,\n\t\t\t      MCode *target);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm_arm.h",
    "content": "/*\n** ARM IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a scratch register pair. */\nstatic Reg ra_scratchpair(ASMState *as, RegSet allow)\n{\n  RegSet pick1 = as->freeset & allow;\n  RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN;\n  Reg r;\n  if (pick2) {\n    r = rset_picktop(pick2);\n  } else {\n    RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN;\n    if (pick) {\n      r = rset_picktop(pick);\n      ra_restore(as, regcost_ref(as->cost[r+1]));\n    } else {\n      pick = pick1 & (allow << 1) & RSET_GPRODD;\n      if (pick) {\n\tr = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1]));\n      } else {\n\tr = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN);\n\tra_restore(as, regcost_ref(as->cost[r+1]));\n      }\n    }\n  }\n  lua_assert(rset_test(RSET_GPREVEN, r));\n  ra_modified(as, r);\n  ra_modified(as, r+1);\n  RA_DBGX((as, \"scratchpair    $r $r\", r, r+1));\n  return r;\n}\n\n#if !LJ_SOFTFP\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_allocref(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_allocref(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_allocref(as, ir->op2, allow);\n    left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_allocref(as, ir->op1, allow);\n    right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n#endif\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Generate an exit stub group at the bottom of the reserved MCode memory. */\nstatic MCode *asm_exitstub_gen(ASMState *as, ExitNo group)\n{\n  MCode *mxp = as->mcbot;\n  int i;\n  if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop)\n    asm_mclimit(as);\n  /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */\n  *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP);\n  *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu);\n  mxp++;\n  *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch);  /* DISPATCH address */\n  *mxp++ = group*EXITSTUBS_PER_GROUP;\n  for (i = 0; i < EXITSTUBS_PER_GROUP; i++)\n    *mxp++ = ARMI_B|((-6-i)&0x00ffffffu);\n  lj_mcode_sync(as->mcbot, mxp);\n  lj_mcode_commitbot(as->J, mxp);\n  as->mcbot = mxp;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  return mxp - EXITSTUBS_PER_GROUP;\n}\n\n/* Setup all needed exit stubs. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)\n    lj_trace_err(as->J, LJ_TRERR_SNAPOV);\n  for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)\n    if (as->J->exitstubgroup[i] == NULL)\n      as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);\n}\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guardcc(ASMState *as, ARMCC cc)\n{\n  MCode *target = exitstub_addr(as->J, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = ARMI_BL | ((target-p-2) & 0x00ffffffu);\n    emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1);\n    return;\n  }\n  emit_branch(as, ARMF_CC(ARMI_BL, cc), target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow,\n\t\t\t  int lim)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (ofs > -lim && ofs < lim) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (ofs < lim) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tint32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);\n\t*ofsp = (ofs & 255);  /* Mask out less bits to allow LDRD. */\n\treturn ra_allock(as, (ofs & ~255), allow);\n      }\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse m operand into arithmetic/logic instructions. */\nstatic uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_hasreg(ir->r)) {\n    ra_noweak(as, ir->r);\n    return ARMF_M(ir->r);\n  } else if (irref_isk(ref)) {\n    uint32_t k = emit_isk12(ai, ir->i);\n    if (k)\n      return k;\n  } else if (mayfuse(as, ref)) {\n    if (ir->o >= IR_BSHL && ir->o <= IR_BROR) {\n      Reg m = ra_alloc1(as, ir->op1, allow);\n      ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL :\n\t\t    ir->o == IR_BSHR ? ARMSH_LSR :\n\t\t    ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR;\n      if (irref_isk(ir->op2)) {\n\treturn m | ARMF_SH(sh, (IR(ir->op2)->i & 31));\n      } else {\n\tReg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m));\n\treturn m | ARMF_RSH(sh, s);\n      }\n    } else if (ir->o == IR_ADD && ir->op1 == ir->op2) {\n      Reg m = ra_alloc1(as, ir->op1, allow);\n      return m | ARMF_SH(ARMSH_LSL, 1);\n    }\n  }\n  return ra_allocref(as, ref, allow);\n}\n\n/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */\nstatic IRRef asm_fuselsl2(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL &&\n      irref_isk(ir->op2) && IR(ir->op2)->i == 2)\n    return ir->op1;\n  return 0;  /* No fusion. */\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 :\n\t\t   (ai & 0x04000000) ? 4096 : 256;\n    if (ir->o == IR_ADD) {\n      int32_t ofs2;\n      if (irref_isk(ir->op2) &&\n\t  (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim &&\n\t  (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) {\n\tofs = ofs2;\n\tref = ir->op1;\n      } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) {\n\tIRRef lref = ir->op1, rref = ir->op2;\n\tReg rn, rm;\n\tif ((ai & 0x04000000)) {\n\t  IRRef sref = asm_fuselsl2(as, rref);\n\t  if (sref) {\n\t    rref = sref;\n\t    ai |= ARMF_SH(ARMSH_LSL, 2);\n\t  } else if ((sref = asm_fuselsl2(as, lref)) != 0) {\n\t    lref = rref;\n\t    rref = sref;\n\t    ai |= ARMF_SH(ARMSH_LSL, 2);\n\t  }\n\t}\n\trn = ra_alloc1(as, lref, allow);\n\trm = ra_alloc1(as, rref, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000)) ai |= ARMI_LS_R;\n\temit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);\n\treturn;\n      }\n    } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) {\n      lua_assert(ofs == 0);\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs += IR(ir->op2)->i;\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs += IR(ir->op1)->i;\n\tref = ir->op2;\n      } else {\n\t/* NYI: Fuse ADD with constant. */\n\tReg rn = ra_alloc1(as, ir->op1, allow);\n\tuint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000))\n\t  emit_lso(as, ai, rd, rd, ofs);\n\telse\n\t  emit_lsox(as, ai, rd, rd, ofs);\n\temit_dn(as, ARMI_ADD^m, rd, rn);\n\treturn;\n      }\n      if (ofs <= -lim || ofs >= lim) {\n\tReg rn = ra_alloc1(as, ref, allow);\n\tReg rm = ra_allock(as, ofs, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000)) ai |= ARMI_LS_R;\n\temit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);\n\treturn;\n      }\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n#if !LJ_SOFTFP\n  if ((ai & 0x08000000))\n    emit_vlso(as, ai, rd, base, ofs);\n  else\n#endif\n  if ((ai & 0x04000000))\n    emit_lso(as, ai, rd, base, ofs);\n  else\n    emit_lsox(as, ai, rd, base, ofs);\n}\n\n#if !LJ_SOFTFP\n/* Fuse to multiply-add/sub instruction. */\nstatic int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irm;\n  if (lref != rref &&\n      ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&\n\tra_noreg(irm->r)) ||\n       (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&\n\t(rref = lref, ai = air, ra_noreg(irm->r))))) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg add = ra_hintalloc(as, rref, dest, RSET_FPR);\n    Reg right, left = ra_alloc2(as, irm,\n\t\t\trset_exclude(rset_exclude(RSET_FPR, dest), add));\n    right = (left >> 8); left &= 255;\n    emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));\n    if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15));\n    return 1;\n  }\n  return 0;\n}\n#endif\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 0;\n#if LJ_SOFTFP\n  Reg gpr = REGARG_FIRSTGPR;\n#else\n  Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0;\n#endif\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func);\n#if !LJ_SOFTFP\n  for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)\n    as->cost[gpr] = REGCOST(~0u, ASMREF_L);\n  gpr = REGARG_FIRSTGPR;\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    IRIns *ir = IR(ref);\n#if !LJ_SOFTFP\n    if (ref && irt_isfp(ir->t)) {\n      RegSet of = as->freeset;\n      Reg src;\n      if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {\n\tif (irt_isnum(ir->t)) {\n\t  if (fpr <= REGARG_LASTFPR) {\n\t    ra_leftov(as, fpr, ref);\n\t    fpr++;\n\t    continue;\n\t  }\n\t} else if (fprodd) {  /* Ick. */\n\t  src = ra_alloc1(as, ref, RSET_FPR);\n\t  emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000);\n\t  fprodd = 0;\n\t  continue;\n\t} else if (fpr <= REGARG_LASTFPR) {\n\t  ra_leftov(as, fpr, ref);\n\t  fprodd = fpr++;\n\t  continue;\n\t}\n\t/* Workaround to protect argument GPRs from being used for remat. */\n\tas->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n\tsrc = ra_alloc1(as, ref, RSET_FPR);  /* May alloc GPR to remat FPR. */\n\tas->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n\tfprodd = 0;\n\tgoto stackfp;\n      }\n      /* Workaround to protect argument GPRs from being used for remat. */\n      as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n      src = ra_alloc1(as, ref, RSET_FPR);  /* May alloc GPR to remat FPR. */\n      as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n      if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u;\n      if (gpr <= REGARG_LASTGPR) {\n\tlua_assert(rset_test(as->freeset, gpr));  /* Must have been evicted. */\n\tif (irt_isnum(ir->t)) {\n\t  lua_assert(rset_test(as->freeset, gpr+1));  /* Ditto. */\n\t  emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15));\n\t  gpr += 2;\n\t} else {\n\t  emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15));\n\t  gpr++;\n\t}\n      } else {\n      stackfp:\n\tif (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\temit_spstore(as, ir, src, ofs);\n\tofs += irt_isnum(ir->t) ? 8 : 4;\n      }\n    } else\n#endif\n    {\n      if (gpr <= REGARG_LASTGPR) {\n\tlua_assert(rset_test(as->freeset, gpr));  /* Must have been evicted. */\n\tif (ref) ra_leftov(as, gpr, ref);\n\tgpr++;\n      } else {\n\tif (ref) {\n\t  Reg r = ra_alloc1(as, ref, RSET_GPR);\n\t  emit_spstore(as, ir, r, ofs);\n\t}\n\tofs += 4;\n      }\n    }\n  }\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lua_assert(!irt_ispri(ir->t));\n    if (!LJ_SOFTFP && irt_isfp(ir->t)) {\n      if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) {\n\tReg dest = (ra_dest(as, ir, RSET_FPR) & 15);\n\tif (irt_isnum(ir->t))\n\t  emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest);\n\telse\n\t  emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n  UNUSED(ci);\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)(irf->i);\n  } else {  /* Need a non-argument register for indirect calls. */\n    Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1));\n    emit_m(as, ARMI_BLXr, freg);\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  /* Need to force a spill on REF_BASE now to update the stack slot. */\n  emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE)));\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_nm(as, ARMI_CMP, RID_TMP,\n\t  ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_lso(as, ARMI_LDR, RID_TMP, base, -4);\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guardcc(as, CC_NE);\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15));\n  emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15));\n  emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n  emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15));\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n  emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15));\n}\n#endif\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if !LJ_SOFTFP\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n#endif\n  IRRef lref = ir->op1;\n  /* 64 bit integer conversions are handled by SPLIT. */\n  lua_assert(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64));\n#if LJ_SOFTFP\n  /* FP conversions are handled by SPLIT. */\n  lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT));\n  /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */\n#else\n  lua_assert(irt_type(ir->t) != st);\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32,\n\t      (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15));\n    } else {  /* Integer to FP conversion. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      ARMIns ai = irt_isfloat(ir->t) ?\n\t(st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) :\n\t(st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32);\n      emit_dm(as, ai, (dest & 15), (dest & 15));\n      emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15));\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lua_assert(irt_isint(ir->t) && st == IRT_NUM);\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      ARMIns ai;\n      emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n      ai = irt_isint(ir->t) ?\n\t(st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) :\n\t(st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32);\n      emit_dm(as, ai, (tmp & 15), (left & 15));\n    }\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));\n      if ((as->flags & JIT_F_ARMV6)) {\n\tARMIns ai = st == IRT_I8 ? ARMI_SXTB :\n\t\t    st == IRT_U8 ? ARMI_UXTB :\n\t\t    st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH;\n\temit_dm(as, ai, dest, left);\n      } else if (st == IRT_U8) {\n\temit_dn(as, ARMI_AND|ARMI_K12|255, dest, left);\n      } else {\n\tuint32_t shift = st == IRT_I8 ? 24 : 16;\n\tARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR;\n\temit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP);\n\temit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left);\n      }\n    } else {  /* Handle 32/32 bit no-op (cast). */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  Reg rlo = 0, rhi = 0, tmp;\n  int destused = ra_used(ir);\n  int32_t ofs = 0;\n  ra_evictset(as, RSET_SCRATCH);\n#if LJ_SOFTFP\n  if (destused) {\n    if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&\n\t(ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) {\n      int i;\n      for (i = 0; i < 2; i++) {\n\tReg r = (ir+i)->r;\n\tif (ra_hasreg(r)) {\n\t  ra_free(as, r);\n\t  ra_modified(as, r);\n\t  emit_spload(as, ir+i, r, sps_scale((ir+i)->s));\n\t}\n      }\n      ofs = sps_scale(ir->s);\n      destused = 0;\n    } else {\n      rhi = ra_dest(as, ir+1, RSET_GPR);\n      rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));\n    }\n  }\n  asm_guardcc(as, CC_EQ);\n  if (destused) {\n    emit_lso(as, ARMI_LDR, rhi, RID_SP, 4);\n    emit_lso(as, ARMI_LDR, rlo, RID_SP, 0);\n  }\n#else\n  UNUSED(rhi);\n  if (destused) {\n    if (ra_hasspill(ir->s)) {\n      ofs = sps_scale(ir->s);\n      destused = 0;\n      if (ra_hasreg(ir->r)) {\n\tra_free(as, ir->r);\n\tra_modified(as, ir->r);\n\temit_spload(as, ir, ir->r, ofs);\n      }\n    } else {\n      rlo = ra_dest(as, ir, RSET_FPR);\n    }\n  }\n  asm_guardcc(as, CC_EQ);\n  if (destused)\n    emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0);\n#endif\n  emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  tmp = ra_releasetmp(as, ASMREF_TMP1);\n  if (ofs == 0)\n    emit_dm(as, ARMI_MOV, tmp, RID_SP);\n  else\n    emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isnum(ir->t)) {\n    if (irref_isk(ref)) {\n      /* Use the number constant itself as a TValue. */\n      ra_allockreg(as, i32ptr(ir_knum(ir)), dest);\n    } else {\n#if LJ_SOFTFP\n      lua_assert(0);\n#else\n      /* Otherwise force a spill and use the spill slot. */\n      emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR);\n#endif\n    }\n  } else {\n    /* Otherwise use [sp] and [sp+4] to hold the TValue. */\n    RegSet allow = rset_exclude(RSET_GPR, dest);\n    Reg type;\n    emit_dm(as, ARMI_MOV, dest, RID_SP);\n    if (!irt_ispri(ir->t)) {\n      Reg src = ra_alloc1(as, ref, allow);\n      emit_lso(as, ARMI_STR, src, RID_SP, 0);\n    }\n    if (LJ_SOFTFP && (ir+1)->o == IR_HIOP)\n      type = ra_alloc1(as, ref+1, allow);\n    else\n      type = ra_allock(as, irt_toitype(ir->t), allow);\n    emit_lso(as, ARMI_STR, type, RID_SP, 4);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i);\n    if (k) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_dn(as, ARMI_ADD^k, dest, base);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  IRType1 kt = irkey->t;\n  int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt));\n  uint32_t khash;\n  MCLabel l_end, l_loop;\n  rset_clear(allow, tab);\n  if (!irref_isk(refkey) || irt_isstr(kt)) {\n#if LJ_SOFTFP\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n    if (irkey[1].o == IR_HIOP) {\n      if (ra_hasreg((irkey+1)->r)) {\n\tkeynumhi = (irkey+1)->r;\n\tkeyhi = RID_TMP;\n\tra_noweak(as, keynumhi);\n      } else {\n\tkeyhi = keynumhi = ra_allocref(as, refkey+1, allow);\n      }\n      rset_clear(allow, keynumhi);\n      khi = 0;\n    }\n#else\n    if (irt_isnum(kt)) {\n      key = ra_scratch(as, allow);\n      rset_clear(allow, key);\n      keyhi = keynumhi = ra_scratch(as, allow);\n      rset_clear(allow, keyhi);\n      khi = 0;\n    } else {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n#endif\n  } else if (irt_isnum(kt)) {\n    int32_t val = (int32_t)ir_knum(irkey)->u32.lo;\n    k = emit_isk12(ARMI_CMP, val);\n    if (!k) {\n      key = ra_allock(as, val, allow);\n      rset_clear(allow, key);\n    }\n    val = (int32_t)ir_knum(irkey)->u32.hi;\n    khi = emit_isk12(ARMI_CMP, val);\n    if (!khi) {\n      keyhi = ra_allock(as, val, allow);\n      rset_clear(allow, keyhi);\n    }\n  } else if (!irt_ispri(kt)) {\n    k = emit_isk12(ARMI_CMP, irkey->i);\n    if (!k) {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n  }\n  if (!irt_ispri(kt))\n    tmp = ra_scratchpair(as, allow);\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_AL);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = --as->mcp;\n  emit_n(as, ARMI_CMP|ARMI_K12|0, dest);\n  emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next));\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_EQ);\n  else\n    emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  if (!irt_ispri(kt)) {\n    emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key);\n    emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi);\n    emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key));\n  } else {\n    emit_n(as, ARMI_CMP^khi, tmp);\n    emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it));\n  }\n  *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = irref_isk(refkey) ? ir_khash(irkey) : 1;\n  if (khash == 0) {\n    emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp);\n    emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp);\n    if (irt_isstr(kt)) {  /* Fetch of str->hash is cheaper than ra_allock. */\n      emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP);\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, hash));\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n    } else if (irref_isk(refkey)) {\n      emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash,\n\t       rset_exclude(rset_exclude(RSET_GPR, tab), dest));\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      if (ra_hasreg(keynumhi)) {  /* Canonicalize +-0.0 to 0.0. */\n\tif (keyhi == RID_TMP)\n\t  emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi);\n\temit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi);\n      }\n      emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP);\n      emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1);\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)),\n\t       tmp, tmp+1, tmp);\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n      emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp);\n      if (ra_hasreg(keynumhi)) {\n\temit_dnm(as, ARMI_EOR, tmp+1, tmp, key);\n\temit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key);  /* Test for +-0.0. */\n\temit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi);\n#if !LJ_SOFTFP\n\temit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi,\n\t\t (ra_alloc1(as, refkey, RSET_FPR) & 15));\n#endif\n      } else {\n\temit_dnm(as, ARMI_EOR, tmp+1, tmp, key);\n\temit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS,\n\t\t rset_exclude(rset_exclude(RSET_GPR, tab), key));\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key = RID_NONE, type = RID_TMP, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  lua_assert(ofs % sizeof(Node) == 0);\n  if (ofs > 4095) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_opk(as, ARMI_ADD, dest, node, ofs, allow);\n  }\n  asm_guardcc(as, CC_NE);\n  if (!irt_ispri(irkey->t)) {\n    RegSet even = (as->freeset & allow);\n    even = even & (even >> 1) & RSET_GPREVEN;\n    if (even) {\n      key = ra_scratch(as, even);\n      if (rset_test(as->freeset, key+1)) {\n\ttype = key+1;\n\tra_modified(as, type);\n      }\n    } else {\n      key = ra_scratch(as, allow);\n    }\n    rset_clear(allow, key);\n  }\n  rset_clear(allow, type);\n  if (irt_isnum(irkey->t)) {\n    emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type,\n\t     (int32_t)ir_knum(irkey)->u32.hi, allow);\n    emit_opk(as, ARMI_CMP, 0, key,\n\t     (int32_t)ir_knum(irkey)->u32.lo, allow);\n  } else {\n    if (ra_hasreg(key))\n      emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow);\n    emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type);\n  }\n  emit_lso(as, ARMI_LDR, type, idx, kofs+4);\n  if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs);\n  if (ofs > 4095)\n    emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR);\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  /* NYI: Check that UREFO is still open and not aliasing a slot. */\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, ARMI_LDR, dest, v);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guardcc(as, CC_NE);\n      emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP);\n      emit_opk(as, ARMI_ADD, dest, uv,\n\t       (int32_t)offsetof(GCupval, tv), RSET_GPR);\n      emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_lso(as, ARMI_LDR, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lua_assert(!ra_used(ir));\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    uint32_t k, m = ARMI_K12|sizeof(GCstr);\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       (k = emit_isk12(ARMI_ADD,\n\t\t\t       (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) {\n      m = k;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_dn(as, ARMI_ADD^m, dest, dest);\n    emit_dnm(as, ARMI_ADD, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  emit_opk(as, ARMI_ADD, dest, r,\n\t   sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r));\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic ARMIns asm_fxloadins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return ARMI_LDRSB;\n  case IRT_U8: return ARMI_LDRB;\n  case IRT_I16: return ARMI_LDRSH;\n  case IRT_U16: return ARMI_LDRH;\n  case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VLDR_D;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S;\n  default: return ARMI_LDR;\n  }\n}\n\nstatic ARMIns asm_fxstoreins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return ARMI_STRB;\n  case IRT_I16: case IRT_U16: return ARMI_STRH;\n  case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VSTR_D;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S;\n  default: return ARMI_STR;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);\n  ARMIns ai = asm_fxloadins(ir);\n  int32_t ofs;\n  if (ir->op2 == IRFL_TAB_ARRAY) {\n    ofs = asm_fuseabase(as, ir->op1);\n    if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n      emit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx);\n      return;\n    }\n  }\n  ofs = field_ofs[ir->op2];\n  if ((ai & 0x04000000))\n    emit_lso(as, ai, dest, idx, ofs);\n  else\n    emit_lsox(as, ai, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    ARMIns ai = asm_fxstoreins(ir);\n    if ((ai & 0x04000000))\n      emit_lso(as, ai, src, idx, ofs);\n    else\n      emit_lsox(as, ai, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir,\n\t\t     (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n  lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));\n  asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2,\n\t\t\t(!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_NONE, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = 0;\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n  if (ra_used(ir)) {\n    lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow,\n\t\t       (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096);\n  if (!hiop || type == RID_NONE) {\n    rset_clear(allow, idx);\n    if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&\n\trset_test((as->freeset & allow), dest+1)) {\n      type = dest+1;\n      ra_modified(as, type);\n    } else {\n      type = RID_TMP;\n    }\n  }\n  asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);\n  emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);\n  if (ra_hasreg(dest)) {\n#if !LJ_SOFTFP\n    if (t == IRT_NUM)\n      emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs);\n    else\n#endif\n      emit_lso(as, ARMI_LDR, dest, idx, ofs);\n  }\n  emit_lso(as, ARMI_LDR, type, idx, ofs+4);\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    RegSet allow = RSET_GPR;\n    Reg idx, src = RID_NONE, type = RID_NONE;\n    int32_t ofs = 0;\n#if !LJ_SOFTFP\n    if (irt_isnum(ir->t)) {\n      src = ra_alloc1(as, ir->op2, RSET_FPR);\n      idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024);\n      emit_vlso(as, ARMI_VSTR_D, src, idx, ofs);\n    } else\n#endif\n    {\n      int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n      if (!irt_ispri(ir->t)) {\n\tsrc = ra_alloc1(as, ir->op2, allow);\n\trset_clear(allow, src);\n      }\n      if (hiop)\n\ttype = ra_alloc1(as, (ir+1)->op2, allow);\n      else\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096);\n      if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs);\n      emit_lso(as, ARMI_STR, type, idx, ofs+4);\n    }\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  lua_assert(!(ir->op2 & IRSLOAD_PARENT));  /* Handled by asm_head_side(). */\n  lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK));\n#if LJ_SOFTFP\n  lua_assert(!(ir->op2 & IRSLOAD_CONVERT));  /* Handled by LJ_SOFTFP SPLIT. */\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n#else\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t = IRT_NUM;  /* Continue with a regular number type check. */\n  } else\n#endif\n  if (ra_used(ir)) {\n    Reg tmp = RID_NONE;\n    if ((ir->op2 & IRSLOAD_CONVERT))\n      tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR);\n    lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    if ((ir->op2 & IRSLOAD_CONVERT)) {\n      if (t == IRT_INT) {\n\temit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n\temit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15));\n\tt = IRT_NUM;  /* Check for original type. */\n      } else {\n\temit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15));\n\temit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15));\n\tt = IRT_INT;  /* Check for original type. */\n      }\n      dest = tmp;\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\ndotypecheck:\n  rset_clear(allow, base);\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    if (ra_noreg(type)) {\n      if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&\n\t  rset_test((as->freeset & allow), dest+1)) {\n\ttype = dest+1;\n\tra_modified(as, type);\n      } else {\n\ttype = RID_TMP;\n      }\n    }\n    asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);\n    emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);\n  }\n  if (ra_hasreg(dest)) {\n#if !LJ_SOFTFP\n    if (t == IRT_NUM) {\n      if (ofs < 1024) {\n\temit_vlso(as, ARMI_VLDR_D, dest, base, ofs);\n      } else {\n\tif (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);\n\temit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0);\n\temit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow);\n\treturn;\n      }\n    } else\n#endif\n      emit_lso(as, ARMI_LDR, dest, base, ofs);\n  }\n  if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n  RegSet drop = RSET_SCRATCH;\n  lua_assert(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL));\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    int32_t ofs = sizeof(GCcdata);\n    lua_assert(sz == 4 || sz == 8);\n    if (sz == 8) {\n      ofs += 4; ir++;\n      lua_assert(ir->o == IR_HIOP);\n    }\n    for (;;) {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_lso(as, ARMI_STR, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir--;\n    }\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  {\n    uint32_t k = emit_isk12(ARMI_MOV, id);\n    Reg r = k ? RID_R1 : ra_allock(as, id, allow);\n    emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct));\n    emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid));\n    emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP);\n    if (k) emit_d(as, ARMI_MOV^k, RID_R1);\n  }\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#else\n#define asm_cnew(as, ir)\t((void)0)\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg gr = ra_allock(as, i32ptr(J2G(as->J)),\n\t\t     rset_exclude(rset_exclude(RSET_GPR, tab), link));\n  Reg mark = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_lso(as, ARMI_STR, tab, gr,\n\t   (int32_t)offsetof(global_State, gc.grayagain));\n  emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark);\n  emit_lso(as, ARMI_LDR, link, gr,\n\t   (int32_t)offsetof(global_State, gc.grayagain));\n  emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark);\n  emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lua_assert(IR(ir->op1)->o == IR_UREFC);\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  if ((l_end[-1] >> 28) == CC_AL)\n    l_end[-1] = ARMF_CC(l_end[-1], CC_NE);\n  else\n    emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1));\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp);\n  emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_lso(as, ARMI_LDRB, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_dm(as, ai, (dest & 15), (left & 15));\n}\n\nstatic void asm_callround(ASMState *as, IRIns *ir, int id)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)|\n\t\tRID2RSET(RID_R3)|RID2RSET(RID_R12);\n  RegSet of;\n  Reg dest, src;\n  ra_evictset(as, drop);\n  dest = ra_dest(as, ir, RSET_FPR);\n  emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15));\n  emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf :\n\t\tid == IRFPM_CEIL ? (void *)lj_vm_ceil_sf :\n\t\t\t\t   (void *)lj_vm_trunc_sf);\n  /* Workaround to protect argument GPRs from being used for remat. */\n  of = as->freeset;\n  as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1);\n  as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L);\n  src = ra_alloc1(as, ir->op1, RSET_FPR);  /* May alloc GPR to remat FPR. */\n  as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1));\n  emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15));\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))\n    return;\n  if (ir->op2 <= IRFPM_TRUNC)\n    asm_callround(as, ir, ir->op2);\n  else if (ir->op2 == IRFPM_SQRT)\n    asm_fpunary(as, ir, ARMI_VSQRT_D);\n  else\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n#endif\n\nstatic int asm_swapops(ASMState *as, IRRef lref, IRRef rref)\n{\n  IRIns *ir;\n  if (irref_isk(rref))\n    return 0;  /* Don't swap constants to the left. */\n  if (irref_isk(lref))\n    return 1;  /* But swap constants to the right. */\n  ir = IR(rref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2))\n    return 0;  /* Don't swap fusable operands to the left. */\n  ir = IR(lref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2))\n    return 1;  /* But swap fusable operands to the right. */\n  return 0;  /* Otherwise don't swap. */\n}\n\nstatic void asm_intop(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left, dest = ra_dest(as, ir, RSET_GPR);\n  uint32_t m;\n  if (asm_swapops(as, lref, rref)) {\n    IRRef tmp = lref; lref = rref; rref = tmp;\n    if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC)\n      ai ^= (ARMI_SUB^ARMI_RSB);\n  }\n  left = ra_hintalloc(as, lref, dest, RSET_GPR);\n  m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));\n  if (irt_isguard(ir->t)) {  /* For IR_ADDOV etc. */\n    asm_guardcc(as, CC_VS);\n    ai |= ARMI_S;\n  }\n  emit_dn(as, ai^m, dest, left);\n}\n\nstatic void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  if (as->flagmcp == as->mcp) {  /* Drop cmp r, #0. */\n    as->flagmcp = NULL;\n    as->mcp++;\n    ai |= ARMI_S;\n  }\n  asm_intop(as, ir, ai);\n}\n\nstatic void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  emit_dn(as, ai|ARMI_K12|0, dest, left);\n}\n\n/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */\nstatic void asm_intmul(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest));\n  Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  Reg tmp = RID_NONE;\n  /* ARMv5 restriction: dest != left and dest_hi != left. */\n  if (dest == left && left != right) { left = right; right = dest; }\n  if (irt_isguard(ir->t)) {  /* IR_MULOV */\n    if (!(as->flags & JIT_F_ARMV6) && dest == left)\n      tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left));\n    asm_guardcc(as, CC_NE);\n    emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest);\n    emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left);\n  } else {\n    if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP;\n    emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left);\n  }\n  /* Only need this for the dest == left == right case. */\n  if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right);\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D))\n      asm_fparith(as, ir, ARMI_VADD_D);\n    return;\n  }\n#endif\n  asm_intop_s(as, ir, ARMI_ADD);\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D))\n      asm_fparith(as, ir, ARMI_VSUB_D);\n    return;\n  }\n#endif\n  asm_intop_s(as, ir, ARMI_SUB);\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, ARMI_VMUL_D);\n    return;\n  }\n#endif\n  asm_intmul(as, ir);\n}\n\n#define asm_addov(as, ir)\tasm_add(as, ir)\n#define asm_subov(as, ir)\tasm_sub(as, ir)\n#define asm_mulov(as, ir)\tasm_mul(as, ir)\n\n#if !LJ_SOFTFP\n#define asm_div(as, ir)\t\tasm_fparith(as, ir, ARMI_VDIV_D)\n#define asm_pow(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_powi)\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, ARMI_VABS_D)\n#define asm_atan2(as, ir)\tasm_callid(as, ir, IRCALL_atan2)\n#define asm_ldexp(as, ir)\tasm_callid(as, ir, IRCALL_ldexp)\n#endif\n\n#define asm_mod(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_modi)\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, ARMI_VNEG_D);\n    return;\n  }\n#endif\n  asm_intneg(as, ir, ARMI_RSB);\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  if (as->flagmcp == as->mcp) {  /* Try to drop cmp r, #0. */\n    uint32_t cc = (as->mcp[1] >> 28);\n    as->flagmcp = NULL;\n    if (cc <= CC_NE) {\n      as->mcp++;\n      ai |= ARMI_S;\n    } else if (cc == CC_GE) {\n      *++as->mcp ^= ((CC_GE^CC_PL) << 28);\n      ai |= ARMI_S;\n    } else if (cc == CC_LT) {\n      *++as->mcp ^= ((CC_LT^CC_MI) << 28);\n      ai |= ARMI_S;\n    }  /* else: other conds don't work with bit ops. */\n  }\n  if (ir->op2 == 0) {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);\n    emit_d(as, ai^m, dest);\n  } else {\n    /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */\n    asm_intop(as, ir, ai);\n  }\n}\n\n#define asm_bnot(as, ir)\tasm_bitop(as, ir, ARMI_MVN)\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if ((as->flags & JIT_F_ARMV6)) {\n    emit_dm(as, ARMI_REV, dest, left);\n  } else {\n    Reg tmp2 = dest;\n    if (tmp2 == left)\n      tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left));\n    emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP);\n    emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left);\n    emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP);\n    emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left);\n  }\n}\n\n#define asm_band(as, ir)\tasm_bitop(as, ir, ARMI_AND)\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, ARMI_ORR)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, ARMI_EOR)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh)\n{\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */\n    /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    int32_t shift = (IR(ir->op2)->i & 31);\n    emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left);\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, ARMSH_LSL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, ARMSH_LSR)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, ARMSH_ASR)\n#define asm_bror(as, ir)\tasm_bitshift(as, ir, ARMSH_ROR)\n#define asm_brol(as, ir)\tlua_assert(0)\n\nstatic void asm_intmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  uint32_t kcmp = 0, kmov = 0;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  Reg right = 0;\n  if (irref_isk(ir->op2)) {\n    kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i);\n    if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i);\n  }\n  if (!kmov) {\n    kcmp = 0;\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  }\n  if (kmov || dest != right) {\n    emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right);\n    cc ^= 1;  /* Must use opposite conditions for paired moves. */\n  } else {\n    cc ^= (CC_LT^CC_GT);  /* Otherwise may swap CC_LT <-> CC_GT. */\n  }\n  if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left);\n  emit_nm(as, ARMI_CMP^kcmp, left, right);\n}\n\n#if LJ_SOFTFP\nstatic void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  args[0] = ir->op1; args[1] = (ir+1)->op1;\n  args[2] = ir->op2; args[3] = (ir+1)->op2;\n  /* __aeabi_cdcmple preserves r0-r3. */\n  if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);\n  if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r);\n  if (!rset_test(as->freeset, RID_R2) &&\n      regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2);\n  if (!rset_test(as->freeset, RID_R3) &&\n      regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3);\n  ra_evictset(as, drop);\n  ra_destpair(as, ir);\n  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3);\n  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2);\n  emit_call(as, (void *)ci->func);\n  for (r = RID_R0; r <= RID_R3; r++)\n    ra_leftov(as, r, args[r-RID_R0]);\n}\n#else\nstatic void asm_fpmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = ((left >> 8) & 15); left &= 15;\n  if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left);\n  if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right);\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ARMI_VCMP_D, left, right);\n}\n#endif\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc)\n{\n#if LJ_SOFTFP\n  UNUSED(fcc);\n#else\n  if (irt_isnum(ir->t))\n    asm_fpmin_max(as, ir, fcc);\n  else\n#endif\n    asm_intmin_max(as, ir, cc);\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, CC_GT, CC_HI)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, CC_LT, CC_LO)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n/* Map of comparisons to flags. ORDER IR. */\nstatic const uint8_t asm_compmap[IR_ABC+1] = {\n  /* op  FP swp  int cc   FP cc */\n  /* LT       */ CC_GE + (CC_HS << 4),\n  /* GE    x  */ CC_LT + (CC_HI << 4),\n  /* LE       */ CC_GT + (CC_HI << 4),\n  /* GT    x  */ CC_LE + (CC_HS << 4),\n  /* ULT   x  */ CC_HS + (CC_LS << 4),\n  /* UGE      */ CC_LO + (CC_LO << 4),\n  /* ULE   x  */ CC_HI + (CC_LO << 4),\n  /* UGT      */ CC_LS + (CC_LS << 4),\n  /* EQ       */ CC_NE + (CC_NE << 4),\n  /* NE       */ CC_EQ + (CC_EQ << 4),\n  /* ABC      */ CC_LS + (CC_LS << 4)  /* Same as UGT. */\n};\n\n#if LJ_SOFTFP\n/* FP comparisons. */\nstatic void asm_sfpcomp(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1);\n  args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1;\n  args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2;\n  /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */\n  for (r = RID_R0; r <= RID_R3; r++)\n    if (!rset_test(as->freeset, r) &&\n\tregcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r);\n  ra_evictset(as, drop);\n  asm_guardcc(as, (asm_compmap[ir->o] >> 4));\n  emit_call(as, (void *)ci->func);\n  for (r = RID_R0; r <= RID_R3; r++)\n    ra_leftov(as, r, args[r-RID_R0]);\n}\n#else\n/* FP comparisons. */\nstatic void asm_fpcomp(ASMState *as, IRIns *ir)\n{\n  Reg left, right;\n  ARMIns ai;\n  int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1);\n  if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) {\n    left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15);\n    right = 0;\n    ai = ARMI_VCMPZ_D;\n  } else {\n    left = ra_alloc2(as, ir, RSET_FPR);\n    if (swp) {\n      right = (left & 15); left = ((left >> 8) & 15);\n    } else {\n      right = ((left >> 8) & 15); left &= 15;\n    }\n    ai = ARMI_VCMP_D;\n  }\n  asm_guardcc(as, (asm_compmap[ir->o] >> 4));\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ai, left, right);\n}\n#endif\n\n/* Integer comparisons. */\nstatic void asm_intcomp(ASMState *as, IRIns *ir)\n{\n  ARMCC cc = (asm_compmap[ir->o] & 15);\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left;\n  uint32_t m;\n  int cmpprev0 = 0;\n  lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));\n  if (asm_swapops(as, lref, rref)) {\n    Reg tmp = lref; lref = rref; rref = tmp;\n    if (cc >= CC_GE) cc ^= 7;  /* LT <-> GT, LE <-> GE */\n    else if (cc > CC_NE) cc ^= 11;  /* LO <-> HI, LS <-> HS */\n  }\n  if (irref_isk(rref) && IR(rref)->i == 0) {\n    IRIns *irl = IR(lref);\n    cmpprev0 = (irl+1 == ir);\n    /* Combine comp(BAND(left, right), 0) into tst left, right. */\n    if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) {\n      IRRef blref = irl->op1, brref = irl->op2;\n      uint32_t m2 = 0;\n      Reg bleft;\n      if (asm_swapops(as, blref, brref)) {\n\tReg tmp = blref; blref = brref; brref = tmp;\n      }\n      if (irref_isk(brref)) {\n\tm2 = emit_isk12(ARMI_AND, IR(brref)->i);\n\tif ((m2 & (ARMI_AND^ARMI_BIC)))\n\t  goto notst;  /* Not beneficial if we miss a constant operand. */\n      }\n      if (cc == CC_GE) cc = CC_PL;\n      else if (cc == CC_LT) cc = CC_MI;\n      else if (cc > CC_NE) goto notst;  /* Other conds don't work with tst. */\n      bleft = ra_alloc1(as, blref, RSET_GPR);\n      if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft));\n      asm_guardcc(as, cc);\n      emit_n(as, ARMI_TST^m2, bleft);\n      return;\n    }\n  }\nnotst:\n  left = ra_alloc1(as, lref, RSET_GPR);\n  m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left));\n  asm_guardcc(as, cc);\n  emit_n(as, ARMI_CMP^m, left);\n  /* Signed comparison with zero and referencing previous ins? */\n  if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE))\n    as->flagmcp = as->mcp;  /* Allow elimination of the compare. */\n}\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t))\n    asm_fpcomp(as, ir);\n  else\n#endif\n    asm_intcomp(as, ir);\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_int64comp(ASMState *as, IRIns *ir)\n{\n  int signedcomp = (ir->o <= IR_GT);\n  ARMCC cclo, cchi;\n  Reg leftlo, lefthi;\n  uint32_t mlo, mhi;\n  RegSet allow = RSET_GPR, oldfree;\n\n  /* Always use unsigned comparison for loword. */\n  cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15;\n  leftlo = ra_alloc1(as, ir->op1, allow);\n  oldfree = as->freeset;\n  mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo));\n  allow &= ~(oldfree & ~as->freeset);  /* Update for allocs of asm_fuseopm. */\n\n  /* Use signed or unsigned comparison for hiword. */\n  cchi = asm_compmap[ir->o] & 15;\n  lefthi = ra_alloc1(as, (ir+1)->op1, allow);\n  mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi));\n\n  /* All register allocations must be performed _before_ this point. */\n  if (signedcomp) {\n    MCLabel l_around = emit_label(as);\n    asm_guardcc(as, cclo);\n    emit_n(as, ARMI_CMP^mlo, leftlo);\n    emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around);\n    if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6;  /* GE -> GT, LE -> LT */\n    asm_guardcc(as, cchi);\n  } else {\n    asm_guardcc(as, cclo);\n    emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo);\n  }\n  emit_n(as, ARMI_CMP^mhi, lefthi);\n}\n#endif\n\n/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */\n\n/* Hiword op of a split 64 bit op. Previous op must be the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n#if LJ_HASFFI || LJ_SOFTFP\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n  if ((ir-1)->o <= IR_NE) {  /* 64 bit integer or FP comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_int64comp(as, ir-1);\n#endif\n    return;\n#if LJ_SOFTFP\n  } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {\n    as->curins--;  /* Always skip the loword min/max. */\n    if (uselo || usehi)\n      asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_HI : CC_LO);\n    return;\n#elif LJ_HASFFI\n  } else if ((ir-1)->o == IR_CONV) {\n    as->curins--;  /* Always skip the CONV. */\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n#endif\n  } else if ((ir-1)->o == IR_XSTORE) {\n    if ((ir-1)->r != RID_SINK)\n      asm_xstore_(as, ir, 4);\n    return;\n  }\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_HASFFI\n  case IR_ADD:\n    as->curins--;\n    asm_intop(as, ir, ARMI_ADC);\n    asm_intop(as, ir-1, ARMI_ADD|ARMI_S);\n    break;\n  case IR_SUB:\n    as->curins--;\n    asm_intop(as, ir, ARMI_SBC);\n    asm_intop(as, ir-1, ARMI_SUB|ARMI_S);\n    break;\n  case IR_NEG:\n    as->curins--;\n    asm_intneg(as, ir, ARMI_RSC);\n    asm_intneg(as, ir-1, ARMI_RSB|ARMI_S);\n    break;\n#endif\n#if LJ_SOFTFP\n  case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n  case IR_STRTO:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RSET_GPR);  /* Mark lo op as used. */\n    break;\n#endif\n  case IR_CALLN:\n  case IR_CALLS:\n  case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n#if LJ_SOFTFP\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR:\n#endif\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n  default: lua_assert(0); break;\n  }\n#else\n  UNUSED(as); UNUSED(ir); lua_assert(0);\n#endif\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_n(as, ARMI_TST|ARMI_K12|HOOK_PROFILE, RID_TMP);\n  emit_lsptr(as, ARMI_LDRB, RID_TMP, (void *)&J2G(as->J)->hookmask);\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  Reg pbase;\n  uint32_t k;\n  if (irp) {\n    if (!ra_hasspill(irp->s)) {\n      pbase = irp->r;\n      lua_assert(ra_hasreg(pbase));\n    } else if (allow) {\n      pbase = rset_pickbot(allow);\n    } else {\n      pbase = RID_RET;\n      emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0);  /* Restore temp. register. */\n    }\n  } else {\n    pbase = RID_BASE;\n  }\n  emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno));\n  k = emit_isk12(0, (int32_t)(8*topslot));\n  lua_assert(k);\n  emit_n(as, ARMI_CMP^k, RID_TMP);\n  emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase);\n  emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP,\n\t   (int32_t)offsetof(lua_State, maxstack));\n  if (irp) {  /* Must not spill arbitrary registers in head of side trace. */\n    int32_t i = i32ptr(&J2G(as->J)->cur_L);\n    if (ra_hasspill(irp->s))\n      emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s));\n    emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095));\n    if (ra_hasspill(irp->s) && !allow)\n      emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0);  /* Save temp. register. */\n    emit_loadi(as, RID_TMP, (i & ~4095));\n  } else {\n    emit_getgl(as, RID_TMP, cur_L);\n  }\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n      RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);\n      Reg tmp;\n      lua_assert(irref_isk(ref));  /* LJ_SOFTFP: must be a number constant. */\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo,\n\t\t      rset_exclude(RSET_GPREVEN, RID_BASE));\n      emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs);\n      if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1);\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd);\n      emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4);\n#else\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs);\n#endif\n    } else {\n      RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);\n      Reg type;\n      lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE));\n\temit_lso(as, ARMI_STR, src, RID_BASE, ofs);\n\tif (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1);\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), odd);\n#if LJ_SOFTFP\n      } else if ((sn & SNAP_SOFTFPNUM)) {\n\ttype = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE));\n#endif\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), odd);\n      }\n      emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4);\n    }\n    checkmclim(as);\n  }\n  lua_assert(map + nent == flinks);\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp1, tmp2;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  tmp1 = ra_releasetmp(as, ASMREF_TMP1);\n  tmp2 = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp2, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end);\n  emit_nm(as, ARMI_CMP, RID_TMP, tmp2);\n  emit_lso(as, ARMI_LDR, tmp2, tmp1,\n\t   (int32_t)offsetof(global_State, gc.threshold));\n  emit_lso(as, ARMI_LDR, RID_TMP, tmp1,\n\t   (int32_t)offsetof(global_State, gc.total));\n  ra_allockreg(as, i32ptr(J2G(as->J)), tmp1);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guardcc already inverted the bcc and patched the final bl. */\n    p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu);\n  } else {\n    p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu);\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Reload L register from g->cur_L. */\nstatic void asm_head_lreg(ASMState *as)\n{\n  IRIns *ir = IR(ASMREF_L);\n  if (ra_used(ir)) {\n    Reg r = ra_dest(as, ir, RSET_GPR);\n    emit_getgl(as, r, cur_L);\n    ra_evictk(as);\n  }\n}\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  ra_destreg(as, ir, RID_BASE);\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  if (ra_hasspill(irp->s)) {\n    rset_clear(allow, ra_dest(as, ir, allow));\n  } else {\n    Reg r = irp->r;\n    lua_assert(ra_hasreg(r));\n    rset_clear(allow, r);\n    if (r != ir->r && !rset_test(as->freeset, r))\n      ra_restore(as, regcost_ref(as->cost[r]));\n    ra_destreg(as, ir, r);\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *p = as->mctop;\n  MCode *target;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    as->mctop = --p;\n  } else {\n    /* Patch stack adjustment. */\n    uint32_t k = emit_isk12(ARMI_ADD, spadj);\n    lua_assert(k);\n    p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP);\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop - 1;  /* Leave room for exit branch. */\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    as->mcp = p-1;  /* Leave room for stack pointer adjustment. */\n    as->invmcp = NULL;\n  }\n  *p = 0;  /* Prevent load/store merging. */\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++) {\n    if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) {\n      if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {\n\tif (irt_isnum(IR(args[i])->t)) {\n\t  if (nfpr > 0) nfpr--;\n\t  else fprodd = 0, nslots = (nslots + 3) & ~1;\n\t} else {\n\t  if (fprodd) fprodd--;\n\t  else if (nfpr > 0) fprodd = 1, nfpr--;\n\t  else nslots++;\n\t}\n      } else if (irt_isnum(IR(args[i])->t)) {\n\tngpr &= ~1;\n\tif (ngpr > 0) ngpr -= 2; else nslots += 2;\n      } else {\n\tif (ngpr > 0) ngpr--; else nslots++;\n      }\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n  }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  /* May need extra exit for asm_stack_check on side traces. */\n  asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *cstart = NULL, *cend = p;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MCode *px = exitstub_addr(J, exitno) - 2;\n  for (; p < pe; p++) {\n    /* Look for bl_cc exitstub, replace with b_cc target. */\n    uint32_t ins = *p;\n    if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u &&\n\t((ins ^ (px-p)) & 0x00ffffffu) == 0) {\n      *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu);\n      cend = p+1;\n      if (!cstart) cstart = p;\n    }\n  }\n  lua_assert(cstart != NULL);\n  lj_mcode_sync(cstart, cend);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm_mips.h",
    "content": "/*\n** MIPS IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a register or RID_ZERO. */\nstatic Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!(allow & RSET_FPR) && irref_isk(ref) && IR(ref)->i == 0)\n      return RID_ZERO;\n    r = ra_allocref(as, ref, allow);\n  } else {\n    ra_noweak(as, r);\n  }\n  return r;\n}\n\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_alloc1z(as, ir->op2, allow);\n    left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_alloc1z(as, ir->op1, allow);\n    right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Need some spare long-range jump slots, for out-of-range branches. */\n#define MIPS_SPAREJUMP\t\t4\n\n/* Setup spare long-range jump slots per mcarea. */\nstatic void asm_sparejump_setup(ASMState *as)\n{\n  MCode *mxp = as->mcbot;\n  /* Assumes sizeof(MCLink) == 8. */\n  if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == 8) {\n    lua_assert(MIPSI_NOP == 0);\n    memset(mxp+2, 0, MIPS_SPAREJUMP*8);\n    mxp += MIPS_SPAREJUMP*2;\n    lua_assert(mxp < as->mctop);\n    lj_mcode_sync(as->mcbot, mxp);\n    lj_mcode_commitbot(as->J, mxp);\n    as->mcbot = mxp;\n    as->mclim = as->mcbot + MCLIM_REDZONE;\n  }\n}\n\n/* Setup exit stub after the end of each trace. */\nstatic void asm_exitstub_setup(ASMState *as)\n{\n  MCode *mxp = as->mctop;\n  /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */\n  *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno;\n  *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu);\n  lua_assert(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0);\n  *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0;\n  as->mctop = mxp;\n}\n\n/* Keep this in-sync with exitstub_trace_addr(). */\n#define asm_exitstub_addr(as)\t((as)->mctop)\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt)\n{\n  MCode *target = asm_exitstub_addr(as);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->invmcp = NULL;\n    as->loopinv = 1;\n    as->mcp = p+1;\n    mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u);  /* Invert cond. */\n    target = p;  /* Patch target later in asm_loop_fixup. */\n  }\n  emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);\n  emit_branch(as, mi, rs, rt, target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (checki16(ofs)) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (checki16(ofs)) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tint32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);\n\tint32_t jgl = (intptr_t)J2G(as->J);\n\tif ((uint32_t)(ofs-jgl) < 65536) {\n\t  *ofsp = ofs-jgl-32768;\n\t  return RID_JGL;\n\t} else {\n\t  *ofsp = (int16_t)ofs;\n\t  return ra_allock(as, ofs-(int16_t)ofs, allow);\n\t}\n      }\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    if (ir->o == IR_ADD) {\n      int32_t ofs2;\n      if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {\n\tref = ir->op1;\n\tofs = ofs2;\n      }\n    } else if (ir->o == IR_STRREF) {\n      int32_t ofs2 = 65536;\n      lua_assert(ofs == 0);\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs2 = ofs + IR(ir->op2)->i;\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs2 = ofs + IR(ir->op1)->i;\n\tref = ir->op2;\n      }\n      if (!checki16(ofs2)) {\n\t/* NYI: Fuse ADD with constant. */\n\tReg right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\temit_hsi(as, mi, rt, RID_TMP, ofs);\n\temit_dst(as, MIPSI_ADDU, RID_TMP, left, right);\n\treturn;\n      }\n      ofs = ofs2;\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n  emit_hsi(as, mi, rt, base, ofs);\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 16;\n#if LJ_SOFTFP\n  Reg gpr = REGARG_FIRSTGPR;\n#else\n  Reg gpr, fpr = REGARG_FIRSTFPR;\n#endif\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func, 1);\n#if !LJ_SOFTFP\n  for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)\n    as->cost[gpr] = REGCOST(~0u, ASMREF_L);\n  gpr = REGARG_FIRSTGPR;\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    if (ref) {\n      IRIns *ir = IR(ref);\n#if !LJ_SOFTFP\n      if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR &&\n\t  !(ci->flags & CCI_VARARG)) {\n\tlua_assert(rset_test(as->freeset, fpr));  /* Already evicted. */\n\tra_leftov(as, fpr, ref);\n\tfpr += 2;\n\tgpr += irt_isnum(ir->t) ? 2 : 1;\n      } else\n#endif\n      {\n#if !LJ_SOFTFP\n\tfpr = REGARG_LASTFPR+1;\n#endif\n\tif (irt_isnum(ir->t)) gpr = (gpr+1) & ~1;\n\tif (gpr <= REGARG_LASTGPR) {\n\t  lua_assert(rset_test(as->freeset, gpr));  /* Already evicted. */\n#if !LJ_SOFTFP\n\t  if (irt_isfp(ir->t)) {\n\t    RegSet of = as->freeset;\n\t    Reg r;\n\t    /* Workaround to protect argument GPRs from being used for remat. */\n\t    as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n\t    r = ra_alloc1(as, ref, RSET_FPR);\n\t    as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n\t    if (irt_isnum(ir->t)) {\n\t      emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1);\n\t      emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r);\n\t      lua_assert(rset_test(as->freeset, gpr+1));  /* Already evicted. */\n\t      gpr += 2;\n\t    } else if (irt_isfloat(ir->t)) {\n\t      emit_tg(as, MIPSI_MFC1, gpr, r);\n\t      gpr++;\n\t    }\n\t  } else\n#endif\n\t  {\n\t    ra_leftov(as, gpr, ref);\n\t    gpr++;\n\t  }\n\t} else {\n\t  Reg r = ra_alloc1z(as, ref, !LJ_SOFTFP && irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n\t  if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += irt_isnum(ir->t) ? 8 : 4;\n\t}\n      }\n    } else {\n#if !LJ_SOFTFP\n      fpr = REGARG_LASTFPR+1;\n#endif\n      if (gpr <= REGARG_LASTGPR)\n\tgpr++;\n      else\n\tofs += 4;\n    }\n    checkmclim(as);\n  }\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n#if !LJ_SOFTFP\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n#endif\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lua_assert(!irt_ispri(ir->t));\n    if (!LJ_SOFTFP && irt_isfp(ir->t)) {\n      if ((ci->flags & CCI_CASTU64)) {\n\tint32_t ofs = sps_scale(ir->s);\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n\t  emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1);\n\t  emit_tg(as, MIPSI_MTC1, RID_RETLO, dest);\n\t}\n\tif (ofs) {\n\t  emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0));\n\t  emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4));\n\t}\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)(irf->i);\n  } else {  /* Need specific register for indirect calls. */\n    Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR));\n    MCode *p = as->mcp;\n    if (r == RID_CFUNCADDR)\n      *--p = MIPSI_NOP;\n    else\n      *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r);\n    *--p = MIPSI_JALR | MIPSF_S(r);\n    as->mcp = p;\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n#if !LJ_SOFTFP\nstatic void asm_callround(ASMState *as, IRIns *ir, IRCallID id)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)|\n\t\tRID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR);\n  if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);\n  ra_evictset(as, drop);\n  ra_destreg(as, ir, RID_FPRET);\n  emit_call(as, (void *)lj_ir_callinfo[id].func, 0);\n  ra_leftov(as, REGARG_FIRSTFPR, ir->op1);\n}\n#endif\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guard(as, MIPSI_BNE, RID_TMP,\n\t    ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_tsi(as, MIPSI_LW, RID_TMP, base, -8);\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guard(as, MIPSI_BC1F, 0, 0);\n  emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left);\n  emit_fg(as, MIPSI_CVT_D_W, tmp, tmp);\n  emit_tg(as, MIPSI_MFC1, dest, tmp);\n  emit_fg(as, MIPSI_CVT_W_D, tmp, left);\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  emit_tg(as, MIPSI_MFC1, dest, tmp);\n  emit_fgh(as, MIPSI_ADD_D, tmp, left, right);\n}\n#endif\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if !LJ_SOFTFP\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n#endif\n  IRRef lref = ir->op1;\n  lua_assert(!(irt_isint64(ir->t) ||\n\t       (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */\n#if LJ_SOFTFP\n  /* FP conversions are handled by SPLIT. */\n  lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT));\n  /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */\n#else\n  lua_assert(irt_type(ir->t) != st);\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S,\n\t      dest, ra_alloc1(as, lref, RSET_FPR));\n    } else if (st == IRT_U32) {  /* U32 to FP conversion. */\n      /* y = (x ^ 0x8000000) + 2147483648.0 */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      emit_fgh(as, irt_isfloat(ir->t) ? MIPSI_ADD_S : MIPSI_ADD_D,\n\t       dest, dest, tmp);\n      emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,\n\t      dest, dest);\n      if (irt_isfloat(ir->t))\n\temit_lsptr(as, MIPSI_LWC1, (tmp & 31),\n\t\t   (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)),\n\t\t   RSET_GPR);\n      else\n\temit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t   (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),\n\t\t   RSET_GPR);\n      emit_tg(as, MIPSI_MTC1, RID_TMP, dest);\n      emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left);\n      emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);\n    } else {  /* Integer to FP conversion. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,\n\t      dest, dest);\n      emit_tg(as, MIPSI_MTC1, left, dest);\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lua_assert(irt_isint(ir->t) && st == IRT_NUM);\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      if (irt_isu32(ir->t)) {\n\t/* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */\n\temit_dst(as, MIPSI_XOR, dest, dest, RID_TMP);\n\temit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D,\n\t\ttmp, tmp);\n\temit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D,\n\t\t tmp, left, tmp);\n\tif (st == IRT_FLOAT)\n\t  emit_lsptr(as, MIPSI_LWC1, (tmp & 31),\n\t\t     (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)),\n\t\t     RSET_GPR);\n\telse\n\t  emit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t     (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),\n\t\t     RSET_GPR);\n      } else {\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D,\n\t\ttmp, left);\n      }\n    }\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n      lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));\n      if ((ir->op2 & IRCONV_SEXT)) {\n\tif ((as->flags & JIT_F_MIPS32R2)) {\n\t  emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left);\n\t} else {\n\t  uint32_t shift = st == IRT_I8 ? 24 : 16;\n\t  emit_dta(as, MIPSI_SRA, dest, dest, shift);\n\t  emit_dta(as, MIPSI_SLL, dest, left, shift);\n\t}\n      } else {\n\temit_tsi(as, MIPSI_ANDI, dest, left,\n\t\t (int32_t)(st == IRT_U8 ? 0xff : 0xffff));\n      }\n    } else {  /* 32/64 bit integer conversions. */\n      /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  int32_t ofs = 0;\n#if LJ_SOFTFP\n  ra_evictset(as, RSET_SCRATCH);\n  if (ra_used(ir)) {\n    if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&\n\t(ir->s & 1) == LJ_BE && (ir->s ^ 1) == (ir+1)->s) {\n      int i;\n      for (i = 0; i < 2; i++) {\n\tReg r = (ir+i)->r;\n\tif (ra_hasreg(r)) {\n\t  ra_free(as, r);\n\t  ra_modified(as, r);\n\t  emit_spload(as, ir+i, r, sps_scale((ir+i)->s));\n\t}\n      }\n      ofs = sps_scale(ir->s & ~1);\n    } else {\n      Reg rhi = ra_dest(as, ir+1, RSET_GPR);\n      Reg rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));\n      emit_tsi(as, MIPSI_LW, rhi, RID_SP, ofs+(LJ_BE?0:4));\n      emit_tsi(as, MIPSI_LW, rlo, RID_SP, ofs+(LJ_BE?4:0));\n    }\n  }\n#else\n  RegSet drop = RSET_SCRATCH;\n  if (ra_hasreg(ir->r)) rset_set(drop, ir->r);  /* Spill dest reg (if any). */\n  ra_evictset(as, drop);\n  ofs = sps_scale(ir->s);\n#endif\n  asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1),\n\t   RID_SP, ofs);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isnum(ir->t)) {\n    if (irref_isk(ref))  /* Use the number constant itself as a TValue. */\n      ra_allockreg(as, i32ptr(ir_knum(ir)), dest);\n    else  /* Otherwise force a spill and use the spill slot. */\n      emit_tsi(as, MIPSI_ADDIU, dest, RID_SP, ra_spill(as, ir));\n  } else {\n    /* Otherwise use g->tmptv to hold the TValue. */\n    RegSet allow = rset_exclude(RSET_GPR, dest);\n    Reg type;\n    emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, (int32_t)(offsetof(global_State, tmptv)-32768));\n    if (!irt_ispri(ir->t)) {\n      Reg src = ra_alloc1(as, ref, allow);\n      emit_setgl(as, src, tmptv.gcr);\n    }\n    if (LJ_SOFTFP && (ir+1)->o == IR_HIOP)\n      type = ra_alloc1(as, ref+1, allow);\n    else\n      type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n    emit_setgl(as, type, tmptv.it);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    ofs += 8*IR(ir->op2)->i;\n    if (checki16(ofs)) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_tsi(as, MIPSI_ADDIU, dest, base, ofs);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_dst(as, MIPSI_ADDU, dest, RID_TMP, base);\n  emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  rset_clear(allow, tab);\n#if LJ_SOFTFP\n  if (!irref_isk(refkey)) {\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n    if (irkey[1].o == IR_HIOP) {\n      if (ra_hasreg((irkey+1)->r)) {\n\ttmpnum = (irkey+1)->r;\n\ttype = RID_TMP;\n\ttmp1 = ra_scratch(as, allow);\n\trset_clear(allow, tmp1);\n\tra_noweak(as, tmpnum);\n      } else {\n\ttype = tmpnum = ra_allocref(as, refkey+1, allow);\n      }\n      rset_clear(allow, tmpnum);\n    } else {\n      type = ra_allock(as, (int32_t)irt_toitype(irkey->t), allow);\n      rset_clear(allow, type);\n    }\n  }\n#else\n  if (irt_isnum(kt)) {\n    key = ra_alloc1(as, refkey, RSET_FPR);\n    tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));\n  } else if (!irt_ispri(kt)) {\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n    type = ra_allock(as, (int32_t)irt_toitype(irkey->t), allow);\n    rset_clear(allow, type);\n  }\n#endif\n  tmp2 = ra_scratch(as, allow);\n  rset_clear(allow, tmp2);\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guard(as, MIPSI_B, RID_ZERO, RID_ZERO);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n  /* Follow hash chain until the end. */\n  emit_move(as, dest, tmp2);\n  l_loop = --as->mcp;\n  emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ) {  /* Must match asm_guard(). */\n    emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);\n    l_end = asm_exitstub_addr(as);\n  }\n  if (!LJ_SOFTFP && irt_isnum(kt)) {\n    emit_branch(as, MIPSI_BC1T, 0, 0, l_end);\n    emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key);\n    *--as->mcp = MIPSI_NOP;  /* Avoid NaN comparison overhead. */\n    emit_branch(as, MIPSI_BEQ, tmp2, RID_ZERO, l_next);\n    emit_tsi(as, MIPSI_SLTIU, tmp2, tmp2, (int32_t)LJ_TISNUM);\n    emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n));\n  } else {\n    if (irt_ispri(kt)) {\n      emit_branch(as, MIPSI_BEQ, tmp2, type, l_end);\n    } else {\n      emit_branch(as, MIPSI_BEQ, tmp1, key, l_end);\n      emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.gcr));\n      emit_branch(as, MIPSI_BNE, tmp2, type, l_next);\n    }\n  }\n  emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.it));\n  *l_loop = MIPSI_BNE | MIPSF_S(tmp2) | ((as->mcp-l_loop-1) & 0xffffu);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = irref_isk(refkey) ? ir_khash(irkey) : 1;\n  if (khash == 0) {\n    emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    Reg tmphash = tmp1;\n    if (irref_isk(refkey))\n      tmphash = ra_allock(as, khash, allow);\n    emit_dst(as, MIPSI_ADDU, dest, dest, tmp1);\n    lua_assert(sizeof(Node) == 24);\n    emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1);\n    emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3);\n    emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5);\n    emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash);\n    emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));\n    emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask));\n    if (irref_isk(refkey)) {\n      /* Nothing to do. */\n    } else if (irt_isstr(kt)) {\n      emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, hash));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2);\n      emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31);\n      emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2);\n      emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31);\n      emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest);\n      if (LJ_SOFTFP ? (irkey[1].o == IR_HIOP) : irt_isnum(kt)) {\n\temit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1);\n\tif ((as->flags & JIT_F_MIPS32R2)) {\n\t  emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31);\n\t} else {\n\t  emit_dst(as, MIPSI_OR, dest, dest, tmp1);\n\t  emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1);\n\t  emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31);\n\t}\n\temit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1);\n#if LJ_SOFTFP\n\temit_ds(as, MIPSI_MOVE, tmp1, type);\n\temit_ds(as, MIPSI_MOVE, tmp2, key);\n#else\n\temit_tg(as, MIPSI_MFC1, tmp2, key);\n\temit_tg(as, MIPSI_MFC1, tmp1, key+1);\n#endif\n      } else {\n\temit_dst(as, MIPSI_XOR, tmp2, key, tmp1);\n\temit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31);\n\temit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow));\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key = RID_NONE, type = RID_TMP, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  int32_t lo, hi;\n  lua_assert(ofs % sizeof(Node) == 0);\n  if (ofs > 32736) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_tsi(as, MIPSI_ADDIU, dest, node, ofs);\n  }\n  if (!irt_ispri(irkey->t)) {\n    key = ra_scratch(as, allow);\n    rset_clear(allow, key);\n  }\n  if (irt_isnum(irkey->t)) {\n    lo = (int32_t)ir_knum(irkey)->u32.lo;\n    hi = (int32_t)ir_knum(irkey)->u32.hi;\n  } else {\n    lo = irkey->i;\n    hi = irt_toitype(irkey->t);\n    if (!ra_hasreg(key))\n      goto nolo;\n  }\n  asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO);\nnolo:\n  asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO);\n  if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0));\n  emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4));\n  if (ofs > 32736)\n    emit_tsi(as, MIPSI_ADDU, dest, node, ra_allock(as, ofs, allow));\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  /* NYI: Check that UREFO is still open and not aliasing a slot. */\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, MIPSI_LW, dest, v, RSET_GPR);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_tsi(as, MIPSI_ADDIU, dest, uv, (int32_t)offsetof(GCupval, tv));\n      emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_tsi(as, MIPSI_LW, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_tsi(as, MIPSI_LW, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lua_assert(!ra_used(ir));\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  int32_t ofs = (int32_t)sizeof(GCstr);\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       checki16(ofs + IR(irr->op2)->i)) {\n      ofs += IR(irr->op2)->i;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs);\n    emit_dst(as, MIPSI_ADDU, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  ofs += IR(refk)->i;\n  if (checki16(ofs))\n    emit_tsi(as, MIPSI_ADDIU, dest, r, ofs);\n  else\n    emit_dst(as, MIPSI_ADDU, dest, r,\n\t     ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic MIPSIns asm_fxloadins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return MIPSI_LB;\n  case IRT_U8: return MIPSI_LBU;\n  case IRT_I16: return MIPSI_LH;\n  case IRT_U16: return MIPSI_LHU;\n  case IRT_NUM: lua_assert(!LJ_SOFTFP); return MIPSI_LDC1;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return MIPSI_LWC1;\n  default: return MIPSI_LW;\n  }\n}\n\nstatic MIPSIns asm_fxstoreins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return MIPSI_SB;\n  case IRT_I16: case IRT_U16: return MIPSI_SH;\n  case IRT_NUM: lua_assert(!LJ_SOFTFP); return MIPSI_SDC1;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return MIPSI_SWC1;\n  default: return MIPSI_SW;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);\n  MIPSIns mi = asm_fxloadins(ir);\n  int32_t ofs;\n  if (ir->op2 == IRFL_TAB_ARRAY) {\n    ofs = asm_fuseabase(as, ir->op1);\n    if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n      emit_tsi(as, MIPSI_ADDIU, dest, idx, ofs);\n      return;\n    }\n  }\n  ofs = field_ofs[ir->op2];\n  lua_assert(!irt_isfp(ir->t));\n  emit_tsi(as, mi, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1z(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    MIPSIns mi = asm_fxstoreins(ir);\n    lua_assert(!irt_isfp(ir->t));\n    emit_tsi(as, mi, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir,\n    (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n  lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));\n  asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1z(as, ir->op2,\n      (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_TMP, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = 0;\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n  if (ra_used(ir)) {\n    lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  rset_clear(allow, idx);\n  if (t == IRT_NUM) {\n    asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n    emit_tsi(as, MIPSI_SLTIU, RID_TMP, type, (int32_t)LJ_TISNUM);\n  } else {\n    asm_guard(as, MIPSI_BNE, type, ra_allock(as, irt_toitype_(t), allow));\n  }\n  if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && t == IRT_NUM)\n      emit_hsi(as, MIPSI_LDC1, dest, idx, ofs);\n    else\n      emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0));\n  }\n  emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4));\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg idx, src = RID_NONE, type = RID_NONE;\n  int32_t ofs = 0;\n  if (ir->r == RID_SINK)\n    return;\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    src = ra_alloc1(as, ir->op2, RSET_FPR);\n  } else {\n    int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n    if (!irt_ispri(ir->t)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n    }\n    if (hiop)\n      type = ra_alloc1(as, (ir+1)->op2, allow);\n    else\n      type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n    rset_clear(allow, type);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    emit_hsi(as, MIPSI_SDC1, src, idx, ofs);\n  } else {\n    if (ra_hasreg(src))\n      emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0));\n    emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4));\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  lua_assert(!(ir->op2 & IRSLOAD_PARENT));  /* Handled by asm_head_side(). */\n  lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK));\n#if LJ_SOFTFP\n  lua_assert(!(ir->op2 & IRSLOAD_CONVERT));  /* Handled by LJ_SOFTFP SPLIT. */\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n#else\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t = IRT_NUM;  /* Continue with a regular number type check. */\n  } else\n#endif\n  if (ra_used(ir)) {\n    lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    rset_clear(allow, base);\n    if (!LJ_SOFTFP && (ir->op2 & IRSLOAD_CONVERT)) {\n      if (t == IRT_INT) {\n\tReg tmp = ra_scratch(as, RSET_FPR);\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, MIPSI_TRUNC_W_D, tmp, tmp);\n\tdest = tmp;\n\tt = IRT_NUM;  /* Check for original type. */\n      } else {\n\tReg tmp = ra_scratch(as, RSET_GPR);\n\temit_fg(as, MIPSI_CVT_D_W, dest, dest);\n\temit_tg(as, MIPSI_MTC1, tmp, dest);\n\tdest = tmp;\n\tt = IRT_INT;  /* Check for original type. */\n      }\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\n  rset_clear(allow, base);\ndotypecheck:\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    if (ra_noreg(type)) {\n      if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&\n\t  rset_test((as->freeset & allow), dest+1)) {\n\ttype = dest+1;\n\tra_modified(as, type);\n      } else {\n\ttype = RID_TMP;\n      }\n    }\n    if (t == IRT_NUM) {\n      asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_tsi(as, MIPSI_SLTIU, RID_TMP, type, (int32_t)LJ_TISNUM);\n    } else {\n      Reg ktype = ra_allock(as, irt_toitype_(t), allow);\n      asm_guard(as, MIPSI_BNE, type, ktype);\n    }\n  }\n  if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && t == IRT_NUM)\n      emit_hsi(as, MIPSI_LDC1, dest, base, ofs);\n    else\n      emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0));\n  }\n  if (ra_hasreg(type))\n    emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4));\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet drop = RSET_SCRATCH;\n  lua_assert(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL));\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n    int32_t ofs = sizeof(GCcdata);\n    lua_assert(sz == 4 || sz == 8);\n    if (sz == 8) {\n      ofs += 4;\n      lua_assert((ir+1)->o == IR_HIOP);\n      if (LJ_LE) ir++;\n    }\n    for (;;) {\n      Reg r = ra_alloc1z(as, ir->op2, allow);\n      emit_tsi(as, MIPSI_SW, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; if (LJ_BE) ir++; else ir--;\n    }\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));\n  emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));\n  emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA);\n  emit_ti(as, MIPSI_LI, RID_TMP, id); /* Lower 16 bit used. Sign-ext ok. */\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#else\n#define asm_cnew(as, ir)\t((void)0)\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg link = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_tsi(as, MIPSI_SW, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_setgl(as, tab, gc.grayagain);\n  emit_getgl(as, link, gc.grayagain);\n  emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP);  /* Clear black bit. */\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK);\n  emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lua_assert(IR(ir->op1)->o == IR_UREFC);\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK);\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_tsi(as, MIPSI_LBU, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  emit_fgh(as, mi, dest, left, right);\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_fg(as, mi, dest, left);\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))\n    return;\n  if (ir->op2 <= IRFPM_TRUNC)\n    asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);\n  else if (ir->op2 == IRFPM_SQRT)\n    asm_fpunary(as, ir, MIPSI_SQRT_D);\n  else\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n#endif\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, MIPSI_ADD_D);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    if (irref_isk(ir->op2)) {\n      int32_t k = IR(ir->op2)->i;\n      if (checki16(k)) {\n\temit_tsi(as, MIPSI_ADDIU, dest, left, k);\n\treturn;\n      }\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_dst(as, MIPSI_ADDU, dest, left, right);\n  }\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, MIPSI_SUB_D);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    emit_dst(as, MIPSI_SUBU, dest, left, right);\n  }\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, MIPSI_MUL_D);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    emit_dst(as, MIPSI_MUL, dest, left, right);\n  }\n}\n\n#define asm_div(as, ir)\t\tasm_fparith(as, ir, MIPSI_DIV_D)\n#define asm_mod(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_modi)\n#define asm_pow(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_powi)\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, MIPSI_NEG_D);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);\n  }\n}\n\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, MIPSI_ABS_D)\n#define asm_atan2(as, ir)\tasm_callid(as, ir, IRCALL_atan2)\n#define asm_ldexp(as, ir)\tasm_callid(as, ir, IRCALL_ldexp)\n\nstatic void asm_arithov(ASMState *as, IRIns *ir)\n{\n  Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int k = IR(ir->op2)->i;\n    if (ir->o == IR_SUBOV) k = -k;\n    if (checki16(k)) {  /* (dest < left) == (k >= 0 ? 1 : 0) */\n      left = ra_alloc1(as, ir->op1, RSET_GPR);\n      asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      if (dest == left) emit_move(as, RID_TMP, left);\n      return;\n    }\n  }\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),\n\t\t\t\t\t\t right), dest));\n  asm_guard(as, MIPSI_BLTZ, RID_TMP, 0);\n  emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp);\n  if (ir->o == IR_ADDOV) {  /* ((dest^left) & (dest^right)) < 0 */\n    emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right);\n  } else {  /* ((dest^left) & (dest^~right)) < 0 */\n    emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest);\n    emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO);\n  }\n  emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left);\n  emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right);\n  if (dest == left || dest == right)\n    emit_move(as, RID_TMP, dest == left ? left : right);\n}\n\n#define asm_addov(as, ir)\tasm_arithov(as, ir)\n#define asm_subov(as, ir)\tasm_arithov(as, ir)\n\nstatic void asm_mulov(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),\n\t\t\t\t\t\t right), dest));\n  asm_guard(as, MIPSI_BNE, RID_TMP, tmp);\n  emit_dta(as, MIPSI_SRA, RID_TMP, dest, 31);\n  emit_dst(as, MIPSI_MFHI, tmp, 0, 0);\n  emit_dst(as, MIPSI_MFLO, dest, 0, 0);\n  emit_dst(as, MIPSI_MULT, 0, left, right);\n}\n\n#if LJ_HASFFI\nstatic void asm_add64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0) {\n      emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP);\n      goto loarith;\n    } else if (checki16(k)) {\n      emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      goto loarith;\n    }\n  }\n  emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_dst(as, MIPSI_ADDU, dest, left, right);\nloarith:\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0) {\n      if (dest != left)\n\temit_move(as, dest, left);\n      return;\n    } else if (checki16(k)) {\n      if (dest == left) {\n\tReg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left));\n\temit_move(as, dest, tmp);\n\tdest = tmp;\n      }\n      emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  if (dest == left && dest == right) {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n    emit_move(as, dest, tmp);\n    dest = tmp;\n  }\n  emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left);\n  emit_dst(as, MIPSI_ADDU, dest, left, right);\n}\n\nstatic void asm_sub64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);\n  emit_dst(as, MIPSI_SUBU, dest, left, right);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (dest == left) {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n    emit_move(as, dest, tmp);\n    dest = tmp;\n  }\n  emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest);\n  emit_dst(as, MIPSI_SUBU, dest, left, right);\n}\n\nstatic void asm_neg64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);\n  emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest);\n  emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);\n}\n#endif\n\nstatic void asm_bnot(ASMState *as, IRIns *ir)\n{\n  Reg left, right, dest = ra_dest(as, ir, RSET_GPR);\n  IRIns *irl = IR(ir->op1);\n  if (mayfuse(as, ir->op1) && irl->o == IR_BOR) {\n    left = ra_alloc2(as, irl, RSET_GPR);\n    right = (left >> 8); left &= 255;\n  } else {\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    right = RID_ZERO;\n  }\n  emit_dst(as, MIPSI_NOR, dest, left, right);\n}\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if ((as->flags & JIT_F_MIPS32R2)) {\n    emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16);\n    emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left);\n  } else {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest));\n    emit_dst(as, MIPSI_OR, dest, dest, tmp);\n    emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);\n    emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00);\n    emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8);\n    emit_dta(as, MIPSI_SRL, dest, left, 8);\n    emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00);\n    emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP);\n    emit_dta(as, MIPSI_SRL, tmp, left, 24);\n    emit_dta(as, MIPSI_SLL, RID_TMP, left, 24);\n  }\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (checku16(k)) {\n      emit_tsi(as, mik, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_dst(as, mi, dest, left, right);\n}\n\n#define asm_band(as, ir)\tasm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI)\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, MIPSI_OR, MIPSI_ORI)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);\n    emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR), shift);\n  } else {\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    emit_dst(as, mi, dest, right, left);  /* Shift amount is in rs. */\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA)\n#define asm_brol(as, ir)\tlua_assert(0)\n\nstatic void asm_bror(ASMState *as, IRIns *ir)\n{\n  if ((as->flags & JIT_F_MIPS32R2)) {\n    asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (irref_isk(ir->op2)) {  /* Constant shifts. */\n      uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);\n      Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n      emit_rotr(as, dest, left, RID_TMP, shift);\n    } else {\n      Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n      right = (left >> 8); left &= 255;\n      emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);\n      emit_dst(as, MIPSI_SRLV, dest, right, left);\n      emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left);\n      emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right);\n    }\n  }\n}\n\n#if LJ_SOFTFP\nstatic void asm_sfpmin_max(ASMState *as, IRIns *ir)\n{\n  CCallInfo ci = lj_ir_callinfo[(IROp)ir->o == IR_MIN ? IRCALL_lj_vm_sfmin : IRCALL_lj_vm_sfmax];\n  IRRef args[4];\n  args[0^LJ_BE] = ir->op1;\n  args[1^LJ_BE] = (ir+1)->op1;\n  args[2^LJ_BE] = ir->op2;\n  args[3^LJ_BE] = (ir+1)->op2;\n  asm_setupresult(as, ir, &ci);\n  emit_call(as, (void *)ci.func, 0);\n  ci.func = NULL;\n  asm_gencall(as, &ci, args);\n}\n#endif\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int ismax)\n{\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    if (dest == left) {\n      emit_fg(as, MIPSI_MOVT_D, dest, right);\n    } else {\n      emit_fg(as, MIPSI_MOVF_D, dest, left);\n      if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right);\n    }\n    emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? left : right, ismax ? right : left);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (dest == left) {\n      emit_dst(as, MIPSI_MOVN, dest, right, RID_TMP);\n    } else {\n      emit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP);\n      if (dest != right) emit_move(as, dest, right);\n    }\n    emit_dst(as, MIPSI_SLT, RID_TMP,\n\t     ismax ? left : right, ismax ? right : left);\n  }\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, 0)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, 1)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n#if LJ_SOFTFP\n/* SFP comparisons. */\nstatic void asm_sfpcomp(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  args[LJ_LE ? 0 : 1] = ir->op1; args[LJ_LE ? 1 : 0] = (ir+1)->op1;\n  args[LJ_LE ? 2 : 3] = ir->op2; args[LJ_LE ? 3 : 2] = (ir+1)->op2;\n\n  for (r = REGARG_FIRSTGPR; r <= REGARG_FIRSTGPR+3; r++) {\n    if (!rset_test(as->freeset, r) &&\n\tregcost_ref(as->cost[r]) == args[r-REGARG_FIRSTGPR])\n      rset_clear(drop, r);\n  }\n  ra_evictset(as, drop);\n\n  asm_setupresult(as, ir, ci);\n\n  switch ((IROp)ir->o) {\n  case IR_LT:\n    asm_guard(as, MIPSI_BGEZ, RID_RET, 0);\n    break;\n  case IR_ULT:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 1);\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO);\n    break;\n  case IR_GE:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 2);\n    asm_guard(as, MIPSI_BLTZ, RID_RET, 0);\n    break;\n  case IR_LE:\n    asm_guard(as, MIPSI_BGTZ, RID_RET, 0);\n    break;\n  case IR_GT:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 2);\n    asm_guard(as, MIPSI_BLEZ, RID_RET, 0);\n    break;\n  case IR_UGE:\n    asm_guard(as, MIPSI_BLTZ, RID_RET, 0);\n    break;\n  case IR_ULE:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 1);\n    break;\n  case IR_UGT: case IR_ABC:\n    asm_guard(as, MIPSI_BLEZ, RID_RET, 0);\n    break;\n  case IR_EQ: case IR_NE:\n    asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_RET, RID_ZERO);\n  default:\n    break;\n  }\n  asm_gencall(as, ci, args);\n}\n#endif\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  /* ORDER IR: LT GE LE GT  ULT UGE ULE UGT. */\n  IROp op = ir->o;\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);\n    emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right);\n  } else {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (op == IR_ABC) op = IR_UGT;\n    if ((op&4) == 0 && irref_isk(ir->op2) && IR(ir->op2)->i == 0) {\n      MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) :\n\t\t\t    ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ);\n      asm_guard(as, mi, left, 0);\n    } else {\n      if (irref_isk(ir->op2)) {\n\tint32_t k = IR(ir->op2)->i;\n\tif ((op&2)) k++;\n\tif (checki16(k)) {\n\t  asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n\t  emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI,\n\t\t   RID_TMP, left, k);\n\t  return;\n\t}\n      }\n      right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n      asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT,\n\t       RID_TMP, (op&2) ? right : left, (op&2) ? left : right);\n    }\n  }\n}\n\nstatic void asm_equal(ASMState *as, IRIns *ir)\n{\n  Reg right, left = ra_alloc2(as, ir, (!LJ_SOFTFP && irt_isnum(ir->t)) ? RSET_FPR : RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);\n    emit_fgh(as, MIPSI_C_EQ_D, 0, left, right);\n  } else {\n    asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right);\n  }\n}\n\n#if LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_comp64(ASMState *as, IRIns *ir)\n{\n  /* ORDER IR: LT GE LE GT  ULT UGE ULE UGT. */\n  IROp op = (ir-1)->o;\n  MCLabel l_end;\n  Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR);\n  righthi = (lefthi >> 8); lefthi &= 255;\n  leftlo = ra_alloc2(as, ir-1,\n\t\t     rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi));\n  rightlo = (leftlo >> 8); leftlo &= 255;\n  asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n  l_end = emit_label(as);\n  if (lefthi != righthi)\n    emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP,\n\t     (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi);\n  emit_dst(as, MIPSI_SLTU, RID_TMP,\n\t   (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo);\n  if (lefthi != righthi)\n    emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end);\n}\n\nstatic void asm_comp64eq(ASMState *as, IRIns *ir)\n{\n  Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO);\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n  emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp);\n  emit_dst(as, MIPSI_XOR, tmp, left, right);\n  left = ra_alloc2(as, ir-1, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  emit_dst(as, MIPSI_XOR, RID_TMP, left, right);\n}\n#endif\n\n/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */\n\n/* Hiword op of a split 64 bit op. Previous op must be the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n#if LJ_HASFFI || LJ_SOFTFP\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n#if LJ_HASFFI && !LJ_SOFTFP\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n#endif\n  } else if ((ir-1)->o < IR_EQ) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_comp64(as, ir);\n#endif\n    return;\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_comp64eq(as, ir);\n#endif\n    return;\n#if LJ_SOFTFP\n  } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {\n      as->curins--;  /* Always skip the loword min/max. */\n    if (uselo || usehi)\n      asm_sfpmin_max(as, ir-1);\n    return;\n#endif\n  } else if ((ir-1)->o == IR_XSTORE) {\n    as->curins--;  /* Handle both stores here. */\n    if ((ir-1)->r != RID_SINK) {\n      asm_xstore_(as, ir, LJ_LE ? 4 : 0);\n      asm_xstore_(as, ir-1, LJ_LE ? 0 : 4);\n    }\n    return;\n  }\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_HASFFI\n  case IR_ADD: as->curins--; asm_add64(as, ir); break;\n  case IR_SUB: as->curins--; asm_sub64(as, ir); break;\n  case IR_NEG: as->curins--; asm_neg64(as, ir); break;\n#endif\n#if LJ_SOFTFP\n  case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n  case IR_STRTO:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RSET_GPR);  /* Mark lo op as used. */\n    break;\n#endif\n  case IR_CALLN:\n  case IR_CALLS:\n  case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n#if LJ_SOFTFP\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR:\n#endif\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n  default: lua_assert(0); break;\n  }\n#else\n  UNUSED(as); UNUSED(ir); lua_assert(0);  /* Unused without FFI. */\n#endif\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, HOOK_PROFILE);\n  emit_lsglptr(as, MIPSI_LBU, RID_TMP,\n\t       (int32_t)offsetof(global_State, hookmask));\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */\n  Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;\n  ExitNo oldsnap = as->snapno;\n  rset_clear(allow, pbase);\n  tmp = allow ? rset_pickbot(allow) :\n\t\t(pbase == RID_RETHI ? RID_RETLO : RID_RETHI);\n  as->snapno = exitno;\n  asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);\n  as->snapno = oldsnap;\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_tsi(as, MIPSI_LW, tmp, RID_SP, 0);\n  else\n    ra_modified(as, tmp);\n  emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot));\n  emit_dst(as, MIPSI_SUBU, RID_TMP, tmp, pbase);\n  emit_tsi(as, MIPSI_LW, tmp, tmp, offsetof(lua_State, maxstack));\n  if (pbase == RID_TMP)\n    emit_getgl(as, RID_TMP, jit_base);\n  emit_getgl(as, tmp, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_tsi(as, MIPSI_SW, tmp, RID_SP, 0);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n      Reg tmp;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      lua_assert(irref_isk(ref));  /* LJ_SOFTFP: must be a number constant. */\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, allow);\n      emit_tsi(as, MIPSI_SW, tmp, RID_BASE, ofs+(LJ_BE?4:0));\n      if (rset_test(as->freeset, tmp+1)) allow = RID2RSET(tmp+1);\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, allow);\n      emit_tsi(as, MIPSI_SW, tmp, RID_BASE, ofs+(LJ_BE?0:4));\n#else\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs);\n#endif\n    } else {\n      Reg type;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, allow);\n\trset_clear(allow, src);\n\temit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0));\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), allow);\n#if LJ_SOFTFP\n      } else if ((sn & SNAP_SOFTFPNUM)) {\n\ttype = ra_alloc1(as, ref+1, rset_exclude(RSET_GPR, RID_BASE));\n#endif\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      }\n      emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4));\n    }\n    checkmclim(as);\n  }\n  lua_assert(map + nent == flinks);\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  /* Assumes asm_snap_prep() already done. */\n  asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  tmp = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end);\n  emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp);\n  emit_getgl(as, tmp, gc.threshold);\n  emit_getgl(as, RID_TMP, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  p[-1] = MIPSI_NOP;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guard already inverted the cond branch. Only patch the target. */\n    p[-3] |= ((target-p+2) & 0x0000ffffu);\n  } else {\n    p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (as->loopinv) as->mctop--;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_move(as, r, RID_BASE);\n  }\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (as->loopinv) as->mctop--;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      rset_clear(allow, irp->r);\n      emit_move(as, r, irp->r);  /* Move from coalesced parent reg. */\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  int32_t spadj = as->T->spadjust;\n  MCode *p = as->mctop-1;\n  *p = spadj ? (MIPSI_ADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP;\n  p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  as->mcp = as->mctop-2;  /* Leave room for branch plus nop or stack adj. */\n  as->invmcp = as->loopref ? as->mcp : NULL;\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++) {\n    if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t) &&\n\tnfpr > 0 && !(ci->flags & CCI_VARARG)) {\n      nfpr--;\n      ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1;\n    } else if (!LJ_SOFTFP && args[i] && irt_isnum(IR(args[i])->t)) {\n      nfpr = 0;\n      ngpr = ngpr & ~1;\n      if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1;\n    } else {\n      nfpr = 0;\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n  }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_sparejump_setup(as);\n  asm_exitstub_setup(as);\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *px = exitstub_trace_addr(T, exitno);\n  MCode *cstart = NULL, *cstop = NULL;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno;\n  MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n  for (p++; p < pe; p++) {\n    if (*p == exitload) {  /* Look for load of exit number. */\n      if (((p[-1] ^ (px-p)) & 0xffffu) == 0) {  /* Look for exitstub branch. */\n\tptrdiff_t delta = target - p;\n\tif (((delta + 0x8000) >> 16) == 0) {  /* Patch in-range branch. */\n\tpatchbranch:\n\t  p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu);\n\t  *p = MIPSI_NOP;  /* Replace the load of the exit number. */\n\t  cstop = p;\n\t  if (!cstart) cstart = p-1;\n\t} else {  /* Branch out of range. Use spare jump slot in mcarea. */\n\t  int i;\n\t  for (i = 2; i < 2+MIPS_SPAREJUMP*2; i += 2) {\n\t    if (mcarea[i] == tjump) {\n\t      delta = mcarea+i - p;\n\t      goto patchbranch;\n\t    } else if (mcarea[i] == MIPSI_NOP) {\n\t      mcarea[i] = tjump;\n\t      cstart = mcarea+i;\n\t      delta = mcarea+i - p;\n\t      goto patchbranch;\n\t    }\n\t  }\n\t  /* Ignore jump slot overflow. Child trace is simply not attached. */\n\t}\n      } else if (p+1 == pe) {\n\t/* Patch NOP after code for inverted loop branch. Use of J is ok. */\n\tlua_assert(p[1] == MIPSI_NOP);\n\tp[1] = tjump;\n\t*p = MIPSI_NOP;  /* Replace the load of the exit number. */\n\tcstop = p+2;\n\tif (!cstart) cstart = p+1;\n      }\n    }\n  }\n  if (cstart) lj_mcode_sync(cstart, cstop);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm_ppc.h",
    "content": "/*\n** PPC IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_allocref(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_allocref(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_allocref(as, ir->op2, allow);\n    left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_allocref(as, ir->op1, allow);\n    right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Setup exit stubs after the end of each trace. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  MCode *mxp = as->mctop;\n  if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim)\n    asm_mclimit(as);\n  /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */\n  for (i = nexits-1; (int32_t)i >= 0; i--)\n    *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2);\n  *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno;  /* Read by exit handler. */\n  mxp--;\n  *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2);\n  *--mxp = PPCI_MFLR|PPCF_T(RID_TMP);\n  as->mctop = mxp;\n}\n\nstatic MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno)\n{\n  /* Keep this in-sync with exitstub_trace_addr(). */\n  return as->mctop + exitno + 3;\n}\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guardcc(ASMState *as, PPCCC cc)\n{\n  MCode *target = asm_exitstub_addr(as, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2);\n    emit_condbranch(as, PPCI_BC, cc^4, p);\n    return;\n  }\n  emit_condbranch(as, PPCI_BC, cc, target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Indicates load/store indexed is ok. */\n#define AHUREF_LSX\t((int32_t)0x80000000)\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (checki16(ofs)) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n\tif (*ofsp == AHUREF_LSX) {\n\t  Reg base = ra_alloc1(as, ir->op1, allow);\n\t  Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n\t  return base | (idx << 8);\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (checki16(ofs)) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tint32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);\n\tint32_t jgl = (intptr_t)J2G(as->J);\n\tif ((uint32_t)(ofs-jgl) < 65536) {\n\t  *ofsp = ofs-jgl-32768;\n\t  return RID_JGL;\n\t} else {\n\t  *ofsp = (int16_t)ofs;\n\t  return ra_allock(as, ofs-(int16_t)ofs, allow);\n\t}\n      }\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    if (ir->o == IR_ADD) {\n      int32_t ofs2;\n      if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {\n\tofs = ofs2;\n\tref = ir->op1;\n      } else if (ofs == 0) {\n\tReg right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\temit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);\n\treturn;\n      }\n    } else if (ir->o == IR_STRREF) {\n      lua_assert(ofs == 0);\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs += IR(ir->op2)->i;\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs += IR(ir->op1)->i;\n\tref = ir->op2;\n      } else {\n\t/* NYI: Fuse ADD with constant. */\n\tReg tmp, right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\ttmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right));\n\temit_fai(as, pi, rt, tmp, ofs);\n\temit_tab(as, PPCI_ADD, tmp, left, right);\n\treturn;\n      }\n      if (!checki16(ofs)) {\n\tReg left = ra_alloc1(as, ref, allow);\n\tReg right = ra_allock(as, ofs, rset_exclude(allow, left));\n\temit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);\n\treturn;\n      }\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n  emit_fai(as, pi, rt, base, ofs);\n}\n\n/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */\nstatic void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref,\n\t\t\t  RegSet allow)\n{\n  IRIns *ira = IR(ref);\n  Reg right, left;\n  if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) {\n    left = ra_alloc2(as, ira, allow);\n    right = (left >> 8); left &= 255;\n  } else {\n    right = ra_alloc1(as, ref, allow);\n    left = RID_R0;\n  }\n  emit_tab(as, pi, rt, left, right);\n}\n\n/* Fuse to multiply-add/sub instruction. */\nstatic int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irm;\n  if (lref != rref &&\n      ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&\n\tra_noreg(irm->r)) ||\n       (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&\n\t(rref = lref, pi = pir, ra_noreg(irm->r))))) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg add = ra_alloc1(as, rref, RSET_FPR);\n    Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add));\n    right = (left >> 8); left &= 255;\n    emit_facb(as, pi, dest, left, right, add);\n    return 1;\n  }\n  return 0;\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 8;\n  Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR;\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func);\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    if (ref) {\n      IRIns *ir = IR(ref);\n      if (irt_isfp(ir->t)) {\n\tif (fpr <= REGARG_LASTFPR) {\n\t  lua_assert(rset_test(as->freeset, fpr));  /* Already evicted. */\n\t  ra_leftov(as, fpr, ref);\n\t  fpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_FPR);\n\t  if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += irt_isnum(ir->t) ? 8 : 4;\n\t}\n      } else {\n\tif (gpr <= REGARG_LASTGPR) {\n\t  lua_assert(rset_test(as->freeset, gpr));  /* Already evicted. */\n\t  ra_leftov(as, gpr, ref);\n\t  gpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_GPR);\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += 4;\n\t}\n      }\n    } else {\n      if (gpr <= REGARG_LASTGPR)\n\tgpr++;\n      else\n\tofs += 4;\n    }\n    checkmclim(as);\n  }\n  if ((ci->flags & CCI_VARARG))  /* Vararg calls need to know about FPR use. */\n    emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6);\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lua_assert(!irt_ispri(ir->t));\n    if (irt_isfp(ir->t)) {\n      if ((ci->flags & CCI_CASTU64)) {\n\t/* Use spill slot or temp slots. */\n\tint32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n\t  emit_fai(as, PPCI_LFD, dest, RID_SP, ofs);\n\t}\n\temit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs);\n\temit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n#if LJ_32\n    } else if (hiop) {\n      ra_destpair(as, ir);\n#endif\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)(intptr_t)(irf->i);\n  } else {  /* Need a non-argument register for indirect calls. */\n    RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);\n    Reg freg = ra_alloc1(as, func, allow);\n    *--as->mcp = PPCI_BCTRL;\n    *--as->mcp = PPCI_MTCTR | PPCF_T(freg);\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_ab(as, PPCI_CMPW, RID_TMP,\n\t  ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_tai(as, PPCI_LWZ, RID_TMP, base, -8);\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  RegSet allow = RSET_FPR;\n  Reg tmp = ra_scratch(as, rset_clear(allow, left));\n  Reg fbias = ra_scratch(as, rset_clear(allow, tmp));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest));\n  asm_guardcc(as, CC_NE);\n  emit_fab(as, PPCI_FCMPU, 0, tmp, left);\n  emit_fab(as, PPCI_FSUB, tmp, tmp, fbias);\n  emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP);\n  emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO);\n  emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n  emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000);\n  emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n  emit_lsptr(as, PPCI_LFS, (fbias & 31),\n\t     (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),\n\t     RSET_GPR);\n  emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n  emit_fb(as, PPCI_FCTIWZ, tmp, left);\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n  emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n  emit_fab(as, PPCI_FADD, tmp, left, right);\n}\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n  IRRef lref = ir->op1;\n  lua_assert(irt_type(ir->t) != st);\n  lua_assert(!(irt_isint64(ir->t) ||\n\t       (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      if (st == IRT_NUM)  /* double -> float conversion. */\n\temit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR));\n      else  /* float -> double conversion is a no-op on PPC. */\n\tra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    } else {  /* Integer to FP conversion. */\n      /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */\n      /* IRT_U32: Bias with 2^52, subtract 2^52. */\n      RegSet allow = RSET_GPR;\n      Reg left = ra_alloc1(as, lref, allow);\n      Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left));\n      Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      const float *kbias;\n      if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest);\n      emit_fab(as, PPCI_FSUB, dest, dest, fbias);\n      emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);\n      kbias = (const float *)lj_ir_k64_find(as->J, U64x(59800004,59800000));\n      if (st == IRT_U32) kbias++;\n      emit_lsptr(as, PPCI_LFS, (fbias & 31), (void *)kbias,\n\t\t rset_clear(allow, hibias));\n      emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP,\n\t       RID_SP, SPOFS_TMPLO);\n      emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n      if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000);\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lua_assert(irt_isint(ir->t) && st == IRT_NUM);\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      if (irt_isu32(ir->t)) {\n\t/* Convert both x and x-2^31 to int and merge results. */\n\tReg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest));\n\temit_asb(as, PPCI_OR, dest, dest, tmpi);  /* Select with mask idiom. */\n\temit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP);\n\temit_asb(as, PPCI_ANDC, dest, dest, RID_TMP);\n\temit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO);  /* tmp = (int)(x) */\n\temit_tai(as, PPCI_ADDIS, dest, dest, 0x8000);  /* dest += 2^31 */\n\temit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31);  /* mask = -(dest < 0) */\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_tai(as, PPCI_LWZ, dest,\n\t\t RID_SP, SPOFS_TMPLO);  /* dest = (int)(x-2^31) */\n\temit_fb(as, PPCI_FCTIWZ, tmp, left);\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, tmp, tmp);\n\temit_fab(as, PPCI_FSUB, tmp, left, tmp);\n\temit_lsptr(as, PPCI_LFS, (tmp & 31),\n\t\t   (void *)lj_ir_k64_find(as->J, U64x(4f000000,00000000)),\n\t\t   RSET_GPR);\n      } else {\n\temit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, tmp, left);\n      }\n    }\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n      lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));\n      if ((ir->op2 & IRCONV_SEXT))\n\temit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left);\n      else\n\temit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31);\n    } else {  /* 32/64 bit integer conversions. */\n      /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  int32_t ofs;\n  RegSet drop = RSET_SCRATCH;\n  if (ra_hasreg(ir->r)) rset_set(drop, ir->r);  /* Spill dest reg (if any). */\n  ra_evictset(as, drop);\n  asm_guardcc(as, CC_EQ);\n  emit_ai(as, PPCI_CMPWI, RID_RET, 0);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isnum(ir->t)) {\n    if (irref_isk(ref))  /* Use the number constant itself as a TValue. */\n      ra_allockreg(as, i32ptr(ir_knum(ir)), dest);\n    else  /* Otherwise force a spill and use the spill slot. */\n      emit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir));\n  } else {\n    /* Otherwise use g->tmptv to hold the TValue. */\n    RegSet allow = rset_exclude(RSET_GPR, dest);\n    Reg type;\n    emit_tai(as, PPCI_ADDI, dest, RID_JGL, (int32_t)offsetof(global_State, tmptv)-32768);\n    if (!irt_ispri(ir->t)) {\n      Reg src = ra_alloc1(as, ref, allow);\n      emit_setgl(as, src, tmptv.gcr);\n    }\n    type = ra_allock(as, irt_toitype(ir->t), allow);\n    emit_setgl(as, type, tmptv.it);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    ofs += 8*IR(ir->op2)->i;\n    if (checki16(ofs)) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_tai(as, PPCI_ADDI, dest, base, ofs);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_tab(as, PPCI_ADD, dest, RID_TMP, base);\n  emit_slwi(as, RID_TMP, idx, 3);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, tmp1 = RID_TMP, tmp2;\n  Reg tisnum = RID_NONE, tmpnum = RID_NONE;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  rset_clear(allow, tab);\n  if (irt_isnum(kt)) {\n    key = ra_alloc1(as, refkey, RSET_FPR);\n    tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));\n    tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);\n    rset_clear(allow, tisnum);\n  } else if (!irt_ispri(kt)) {\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n  }\n  tmp2 = ra_scratch(as, allow);\n  rset_clear(allow, tmp2);\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_EQ);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = --as->mcp;\n  emit_ai(as, PPCI_CMPWI, dest, 0);\n  emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_EQ);\n  else\n    emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  if (irt_isnum(kt)) {\n    emit_fab(as, PPCI_FCMPU, 0, tmpnum, key);\n    emit_condbranch(as, PPCI_BC, CC_GE, l_next);\n    emit_ab(as, PPCI_CMPLW, tmp1, tisnum);\n    emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n));\n  } else {\n    if (!irt_ispri(kt)) {\n      emit_ab(as, PPCI_CMPW, tmp2, key);\n      emit_condbranch(as, PPCI_BC, CC_NE, l_next);\n    }\n    emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t));\n    if (!irt_ispri(kt))\n      emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr));\n  }\n  emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it));\n  *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) |\n\t    (((char *)as->mcp-(char *)l_loop) & 0xffffu);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = irref_isk(refkey) ? ir_khash(irkey) : 1;\n  if (khash == 0) {\n    emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    Reg tmphash = tmp1;\n    if (irref_isk(refkey))\n      tmphash = ra_allock(as, khash, allow);\n    emit_tab(as, PPCI_ADD, dest, dest, tmp1);\n    emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node));\n    emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash);\n    emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));\n    emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask));\n    if (irref_isk(refkey)) {\n      /* Nothing to do. */\n    } else if (irt_isstr(kt)) {\n      emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, hash));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1);\n      emit_rotlwi(as, tmp2, tmp2, HASH_ROT3);\n      emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2);\n      emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31);\n      emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2);\n      if (irt_isnum(kt)) {\n\tint32_t ofs = ra_spill(as, irkey);\n\temit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1);\n\temit_rotlwi(as, dest, tmp1, HASH_ROT1);\n\temit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1);\n\temit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4);\n\temit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs);\n      } else {\n\temit_asb(as, PPCI_XOR, tmp2, key, tmp1);\n\temit_rotlwi(as, dest, tmp1, HASH_ROT1);\n\temit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS);\n\temit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16);\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key = RID_NONE, type = RID_TMP, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  lua_assert(ofs % sizeof(Node) == 0);\n  if (ofs > 32736) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_tai(as, PPCI_ADDI, dest, node, ofs);\n  }\n  asm_guardcc(as, CC_NE);\n  if (!irt_ispri(irkey->t)) {\n    key = ra_scratch(as, allow);\n    rset_clear(allow, key);\n  }\n  rset_clear(allow, type);\n  if (irt_isnum(irkey->t)) {\n    emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo);\n    asm_guardcc(as, CC_NE);\n    emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi);\n  } else {\n    if (ra_hasreg(key)) {\n      emit_cmpi(as, key, irkey->i);  /* May use RID_TMP, i.e. type. */\n      asm_guardcc(as, CC_NE);\n    }\n    emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t));\n  }\n  if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4);\n  emit_tai(as, PPCI_LWZ, type, idx, kofs);\n  if (ofs > 32736) {\n    emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16);\n    emit_tai(as, PPCI_ADDI, dest, node, ofs);\n  }\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  /* NYI: Check that UREFO is still open and not aliasing a slot. */\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guardcc(as, CC_NE);\n      emit_ai(as, PPCI_CMPWI, RID_TMP, 1);\n      emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv));\n      emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_tai(as, PPCI_LWZ, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lua_assert(!ra_used(ir));\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  int32_t ofs = (int32_t)sizeof(GCstr);\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       checki16(ofs + IR(irr->op2)->i)) {\n      ofs += IR(irr->op2)->i;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_tai(as, PPCI_ADDI, dest, dest, ofs);\n    emit_tab(as, PPCI_ADD, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  ofs += IR(refk)->i;\n  if (checki16(ofs))\n    emit_tai(as, PPCI_ADDI, dest, r, ofs);\n  else\n    emit_tab(as, PPCI_ADD, dest, r,\n\t     ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic PPCIns asm_fxloadins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return PPCI_LBZ;  /* Needs sign-extension. */\n  case IRT_U8: return PPCI_LBZ;\n  case IRT_I16: return PPCI_LHA;\n  case IRT_U16: return PPCI_LHZ;\n  case IRT_NUM: return PPCI_LFD;\n  case IRT_FLOAT: return PPCI_LFS;\n  default: return PPCI_LWZ;\n  }\n}\n\nstatic PPCIns asm_fxstoreins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return PPCI_STB;\n  case IRT_I16: case IRT_U16: return PPCI_STH;\n  case IRT_NUM: return PPCI_STFD;\n  case IRT_FLOAT: return PPCI_STFS;\n  default: return PPCI_STW;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);\n  PPCIns pi = asm_fxloadins(ir);\n  int32_t ofs;\n  if (ir->op2 == IRFL_TAB_ARRAY) {\n    ofs = asm_fuseabase(as, ir->op1);\n    if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n      emit_tai(as, PPCI_ADDI, dest, idx, ofs);\n      return;\n    }\n  }\n  ofs = field_ofs[ir->op2];\n  lua_assert(!irt_isi8(ir->t));\n  emit_tai(as, pi, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    PPCIns pi = asm_fxstoreins(ir);\n    emit_tai(as, pi, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n  lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));\n  if (irt_isi8(ir->t))\n    emit_as(as, PPCI_EXTSB, dest, dest);\n  asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  IRIns *irb;\n  if (ir->r == RID_SINK)\n    return;\n  if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP &&\n      ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) {\n    /* Fuse BSWAP with XSTORE to stwbrx. */\n    Reg src = ra_alloc1(as, irb->op1, RSET_GPR);\n    asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src));\n  } else {\n    Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  IRType1 t = ir->t;\n  Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = AHUREF_LSX;\n  if (ra_used(ir)) {\n    lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));\n    if (!irt_isnum(t)) ofs = 0;\n    dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);\n    rset_clear(allow, dest);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (irt_isnum(t)) {\n    Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx));\n    asm_guardcc(as, CC_GE);\n    emit_ab(as, PPCI_CMPLW, type, tisnum);\n    if (ra_hasreg(dest)) {\n      if (ofs == AHUREF_LSX) {\n\ttmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR,\n\t\t\t\t\t\t       (idx&255)), (idx>>8)));\n\temit_fab(as, PPCI_LFDX, dest, (idx&255), tmp);\n      } else {\n\temit_fai(as, PPCI_LFD, dest, idx, ofs);\n      }\n    }\n  } else {\n    asm_guardcc(as, CC_NE);\n    emit_ai(as, PPCI_CMPWI, type, irt_toitype(t));\n    if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4);\n  }\n  if (ofs == AHUREF_LSX) {\n    emit_tab(as, PPCI_LWZX, type, (idx&255), tmp);\n    emit_slwi(as, tmp, (idx>>8), 3);\n  } else {\n    emit_tai(as, PPCI_LWZ, type, idx, ofs);\n  }\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg idx, src = RID_NONE, type = RID_NONE;\n  int32_t ofs = AHUREF_LSX;\n  if (ir->r == RID_SINK)\n    return;\n  if (irt_isnum(ir->t)) {\n    src = ra_alloc1(as, ir->op2, RSET_FPR);\n  } else {\n    if (!irt_ispri(ir->t)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n      ofs = 0;\n    }\n    type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n    rset_clear(allow, type);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (irt_isnum(ir->t)) {\n    if (ofs == AHUREF_LSX) {\n      emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP);\n      emit_slwi(as, RID_TMP, (idx>>8), 3);\n    } else {\n      emit_fai(as, PPCI_STFD, src, idx, ofs);\n    }\n  } else {\n    if (ra_hasreg(src))\n      emit_tai(as, PPCI_STW, src, idx, ofs+4);\n    if (ofs == AHUREF_LSX) {\n      emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP);\n      emit_slwi(as, RID_TMP, (idx>>8), 3);\n    } else {\n      emit_tai(as, PPCI_STW, type, idx, ofs);\n    }\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4);\n  IRType1 t = ir->t;\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  lua_assert(!(ir->op2 & IRSLOAD_PARENT));  /* Handled by asm_head_side(). */\n  lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));\n  lua_assert(LJ_DUALNUM ||\n\t     !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n  } else if (ra_used(ir)) {\n    lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));\n    dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    rset_clear(allow, base);\n    if ((ir->op2 & IRSLOAD_CONVERT)) {\n      if (irt_isint(t)) {\n\temit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n\tdest = ra_scratch(as, RSET_FPR);\n\temit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, dest, dest);\n\tt.irt = IRT_NUM;  /* Check for original type. */\n      } else {\n\tReg tmp = ra_scratch(as, allow);\n\tReg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp));\n\tReg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n\temit_fab(as, PPCI_FSUB, dest, dest, fbias);\n\temit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);\n\temit_lsptr(as, PPCI_LFS, (fbias & 31),\n\t\t   (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),\n\t\t   rset_clear(allow, hibias));\n\temit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO);\n\temit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n\temit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000);\n\tdest = tmp;\n\tt.irt = IRT_INT;  /* Check for original type. */\n      }\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\n  rset_clear(allow, base);\ndotypecheck:\n  if (irt_isnum(t)) {\n    if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n      Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);\n      asm_guardcc(as, CC_GE);\n      emit_ab(as, PPCI_CMPLW, RID_TMP, tisnum);\n      type = RID_TMP;\n    }\n    if (ra_hasreg(dest)) emit_fai(as, PPCI_LFD, dest, base, ofs-4);\n  } else {\n    if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n      asm_guardcc(as, CC_NE);\n      emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t));\n      type = RID_TMP;\n    }\n    if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs);\n  }\n  if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet drop = RSET_SCRATCH;\n  lua_assert(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL));\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n    int32_t ofs = sizeof(GCcdata);\n    lua_assert(sz == 4 || sz == 8);\n    if (sz == 8) {\n      ofs += 4;\n      lua_assert((ir+1)->o == IR_HIOP);\n    }\n    for (;;) {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_tai(as, PPCI_STW, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir++;\n    }\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));\n  emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));\n  emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA);\n  emit_ti(as, PPCI_LI, RID_TMP, id);  /* Lower 16 bit used. Sign-ext ok. */\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#else\n#define asm_cnew(as, ir)\t((void)0)\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg link = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_setgl(as, tab, gc.grayagain);\n  lua_assert(LJ_GC_BLACK == 0x04);\n  emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28);  /* Clear black bit. */\n  emit_getgl(as, link, gc.grayagain);\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK);\n  emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lua_assert(IR(ir->op1)->o == IR_UREFC);\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK);\n  emit_condbranch(as, PPCI_BC, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_tai(as, PPCI_LBZ, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\nstatic void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  if (pi == PPCI_FMUL)\n    emit_fac(as, pi, dest, left, right);\n  else\n    emit_fab(as, pi, dest, left, right);\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_fb(as, pi, dest, left);\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))\n    return;\n  if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT))\n    asm_fpunary(as, ir, PPCI_FSQRT);\n  else\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD))\n      asm_fparith(as, ir, PPCI_FADD);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    PPCIns pi;\n    if (irref_isk(ir->op2)) {\n      int32_t k = IR(ir->op2)->i;\n      if (checki16(k)) {\n\tpi = PPCI_ADDI;\n\t/* May fail due to spills/restores above, but simplifies the logic. */\n\tif (as->flagmcp == as->mcp) {\n\t  as->flagmcp = NULL;\n\t  as->mcp++;\n\t  pi = PPCI_ADDICDOT;\n\t}\n\temit_tai(as, pi, dest, left, k);\n\treturn;\n      } else if ((k & 0xffff) == 0) {\n\temit_tai(as, PPCI_ADDIS, dest, left, (k >> 16));\n\treturn;\n      } else if (!as->sectref) {\n\temit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16);\n\temit_tai(as, PPCI_ADDI, dest, left, k);\n\treturn;\n      }\n    }\n    pi = PPCI_ADD;\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, left, right);\n  }\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB))\n      asm_fparith(as, ir, PPCI_FSUB);\n  } else {\n    PPCIns pi = PPCI_SUBF;\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left, right;\n    if (irref_isk(ir->op1)) {\n      int32_t k = IR(ir->op1)->i;\n      if (checki16(k)) {\n\tright = ra_alloc1(as, ir->op2, RSET_GPR);\n\temit_tai(as, PPCI_SUBFIC, dest, right, k);\n\treturn;\n      }\n    }\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, right, left);  /* Subtract right _from_ left. */\n  }\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, PPCI_FMUL);\n  } else {\n    PPCIns pi = PPCI_MULLW;\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    if (irref_isk(ir->op2)) {\n      int32_t k = IR(ir->op2)->i;\n      if (checki16(k)) {\n\temit_tai(as, PPCI_MULLI, dest, left, k);\n\treturn;\n      }\n    }\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, left, right);\n  }\n}\n\n#define asm_div(as, ir)\t\tasm_fparith(as, ir, PPCI_FDIV)\n#define asm_mod(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_modi)\n#define asm_pow(as, ir)\t\tasm_callid(as, ir, IRCALL_lj_vm_powi)\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, PPCI_FNEG);\n  } else {\n    Reg dest, left;\n    PPCIns pi = PPCI_NEG;\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    dest = ra_dest(as, ir, RSET_GPR);\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    emit_tab(as, pi, dest, left, 0);\n  }\n}\n\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, PPCI_FABS)\n#define asm_atan2(as, ir)\tasm_callid(as, ir, IRCALL_atan2)\n#define asm_ldexp(as, ir)\tasm_callid(as, ir, IRCALL_ldexp)\n\nstatic void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest, left, right;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n  }\n  asm_guardcc(as, CC_SO);\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; }\n  emit_tab(as, pi|PPCF_DOT, dest, left, right);\n}\n\n#define asm_addov(as, ir)\tasm_arithov(as, ir, PPCI_ADDO)\n#define asm_subov(as, ir)\tasm_arithov(as, ir, PPCI_SUBFO)\n#define asm_mulov(as, ir)\tasm_arithov(as, ir, PPCI_MULLWO)\n\n#if LJ_HASFFI\nstatic void asm_add64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n  PPCIns pi = PPCI_ADDE;\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0)\n      pi = PPCI_ADDZE;\n    else if (k == -1)\n      pi = PPCI_ADDME;\n    else\n      goto needright;\n    right = 0;\n  } else {\n  needright:\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  }\n  emit_tab(as, pi, dest, left, right);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (checki16(k)) {\n      emit_tai(as, PPCI_ADDIC, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_tab(as, PPCI_ADDC, dest, left, right);\n}\n\nstatic void asm_sub64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR);\n  PPCIns pi = PPCI_SUBFE;\n  if (irref_isk(ir->op1)) {\n    int32_t k = IR(ir->op1)->i;\n    if (k == 0)\n      pi = PPCI_SUBFZE;\n    else if (k == -1)\n      pi = PPCI_SUBFME;\n    else\n      goto needleft;\n    left = 0;\n  } else {\n  needleft:\n    left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));\n  }\n  emit_tab(as, pi, dest, right, left);  /* Subtract right _from_ left. */\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  right = ra_alloc1(as, ir->op2, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    int32_t k = IR(ir->op1)->i;\n    if (checki16(k)) {\n      emit_tai(as, PPCI_SUBFIC, dest, right, k);\n      return;\n    }\n  }\n  left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));\n  emit_tab(as, PPCI_SUBFC, dest, right, left);\n}\n\nstatic void asm_neg64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_tab(as, PPCI_SUBFZE, dest, left, 0);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_tai(as, PPCI_SUBFIC, dest, left, 0);\n}\n#endif\n\nstatic void asm_bnot(ASMState *as, IRIns *ir)\n{\n  Reg dest, left, right;\n  PPCIns pi = PPCI_NOR;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    pi |= PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  if (mayfuse(as, ir->op1)) {\n    IRIns *irl = IR(ir->op1);\n    if (irl->o == IR_BAND)\n      pi ^= (PPCI_NOR ^ PPCI_NAND);\n    else if (irl->o == IR_BXOR)\n      pi ^= (PPCI_NOR ^ PPCI_EQV);\n    else if (irl->o != IR_BOR)\n      goto nofuse;\n    left = ra_hintalloc(as, irl->op1, dest, RSET_GPR);\n    right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left));\n  } else {\nnofuse:\n    left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  }\n  emit_asb(as, pi, dest, left, right);\n}\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRIns *irx;\n  if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD &&\n      ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) {\n    /* Fuse BSWAP with XLOAD to lwbrx. */\n    asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR);\n  } else {\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    Reg tmp = dest;\n    if (tmp == left) {\n      tmp = RID_TMP;\n      emit_mr(as, dest, RID_TMP);\n    }\n    emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23);\n    emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7);\n    emit_rotlwi(as, tmp, left, 8);\n  }\n}\n\n/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */\nstatic void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref)\n{\n  IRIns *ir;\n  Reg left;\n  if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) &&\n      irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) {\n    int32_t sh = (IR(ir->op2)->i & 31);\n    switch (ir->o) {\n    case IR_BSHL:\n      if ((mask & ((1u<<sh)-1))) goto nofuse;\n      break;\n    case IR_BSHR:\n      if ((mask & ~((~0u)>>sh))) goto nofuse;\n      sh = ((32-sh)&31);\n      break;\n    case IR_BROL:\n      break;\n    default:\n      goto nofuse;\n    }\n    left = ra_alloc1(as, ir->op1, RSET_GPR);\n    *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh);\n    return;\n  }\nnofuse:\n  left = ra_alloc1(as, ref, RSET_GPR);\n  *--as->mcp = pi | PPCF_T(left);\n}\n\nstatic void asm_band(ASMState *as, IRIns *ir)\n{\n  Reg dest, left, right;\n  IRRef lref = ir->op1;\n  PPCIns dot = 0;\n  IRRef op2;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    dot = PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k) {\n      /* First check for a contiguous bitmask as used by rlwinm. */\n      uint32_t s1 = lj_ffs((uint32_t)k);\n      uint32_t k1 = ((uint32_t)k >> s1);\n      if ((k1 & (k1+1)) == 0) {\n\tasm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |\n\t\t\t  PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1),\n\t\t\t  k, lref);\n\treturn;\n      }\n      if (~(uint32_t)k) {\n\tuint32_t s2 = lj_ffs(~(uint32_t)k);\n\tuint32_t k2 = (~(uint32_t)k >> s2);\n\tif ((k2 & (k2+1)) == 0) {\n\t  asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |\n\t\t\t    PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)),\n\t\t\t    k, lref);\n\t  return;\n\t}\n      }\n    }\n    if (checku16(k)) {\n      left = ra_alloc1(as, lref, RSET_GPR);\n      emit_asi(as, PPCI_ANDIDOT, dest, left, k);\n      return;\n    } else if ((k & 0xffff) == 0) {\n      left = ra_alloc1(as, lref, RSET_GPR);\n      emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16));\n      return;\n    }\n  }\n  op2 = ir->op2;\n  if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) {\n    dot ^= (PPCI_AND ^ PPCI_ANDC);\n    op2 = IR(op2)->op1;\n  }\n  left = ra_hintalloc(as, lref, dest, RSET_GPR);\n  right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left));\n  emit_asb(as, PPCI_AND ^ dot, dest, left, right);\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    Reg tmp = left;\n    if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) {\n      if (!checku16(k)) {\n\temit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16));\n\tif ((k & 0xffff) == 0) return;\n      }\n      emit_asi(as, pik, dest, left, k);\n      return;\n    }\n  }\n  /* May fail due to spills/restores above, but simplifies the logic. */\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    pi |= PPCF_DOT;\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_asb(as, pi, dest, left, right);\n}\n\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, PPCI_OR, PPCI_ORI)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, PPCI_XOR, PPCI_XORI)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)\n{\n  Reg dest, left;\n  Reg dot = 0;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    dot = PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    int32_t shift = (IR(ir->op2)->i & 31);\n    if (pik == 0)  /* SLWI */\n      emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift);\n    else if (pik == 1)  /* SRWI */\n      emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31);\n    else\n      emit_asb(as, pik|dot, dest, left, shift);\n  } else {\n    Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_asb(as, pi|dot, dest, left, right);\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, PPCI_SLW, 0)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, PPCI_SRW, 1)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI)\n#define asm_brol(as, ir) \\\n  asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31), \\\n\t\t       PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31))\n#define asm_bror(as, ir)\tlua_assert(0)\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int ismax)\n{\n  if (irt_isnum(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg tmp = dest;\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    if (tmp == left || tmp == right)\n      tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR,\n\t\t\t\t\tdest), left), right));\n    emit_facb(as, PPCI_FSEL, dest, tmp,\n\t      ismax ? left : right, ismax ? right : left);\n    emit_fab(as, PPCI_FSUB, tmp, left, right);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg tmp1 = RID_TMP, tmp2 = dest;\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (tmp2 == left || tmp2 == right)\n      tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR,\n\t\t\t\t\t dest), left), right));\n    emit_tab(as, PPCI_ADD, dest, tmp2, right);\n    emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1);\n    emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1);\n    emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1);\n    emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000);\n    emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000);\n  }\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, 0)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, 1)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n#define CC_UNSIGNED\t0x08\t/* Unsigned integer comparison. */\n#define CC_TWO\t\t0x80\t/* Check two flags for FP comparison. */\n\n/* Map of comparisons to flags. ORDER IR. */\nstatic const uint8_t asm_compmap[IR_ABC+1] = {\n  /* op     int cc                 FP cc */\n  /* LT  */ CC_GE               + (CC_GE<<4),\n  /* GE  */ CC_LT               + (CC_LE<<4) + CC_TWO,\n  /* LE  */ CC_GT               + (CC_GE<<4) + CC_TWO,\n  /* GT  */ CC_LE               + (CC_LE<<4),\n  /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO,\n  /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4),\n  /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4),\n  /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO,\n  /* EQ  */ CC_NE               + (CC_NE<<4),\n  /* NE  */ CC_EQ               + (CC_EQ<<4),\n  /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO  /* Same as UGT. */\n};\n\nstatic void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc)\n{\n  Reg right, left = ra_alloc1(as, lref, RSET_GPR);\n  if (irref_isk(rref)) {\n    int32_t k = IR(rref)->i;\n    if ((cc & CC_UNSIGNED) == 0) {  /* Signed comparison with constant. */\n      if (checki16(k)) {\n\temit_tai(as, PPCI_CMPWI, cr, left, k);\n\t/* Signed comparison with zero and referencing previous ins? */\n\tif (k == 0 && lref == as->curins-1)\n\t  as->flagmcp = as->mcp;  /* Allow elimination of the compare. */\n\treturn;\n      } else if ((cc & 3) == (CC_EQ & 3)) {  /* Use CMPLWI for EQ or NE. */\n\tif (checku16(k)) {\n\t  emit_tai(as, PPCI_CMPLWI, cr, left, k);\n\t  return;\n\t} else if (!as->sectref && ra_noreg(IR(rref)->r)) {\n\t  emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k);\n\t  emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16));\n\t  return;\n\t}\n      }\n    } else {  /* Unsigned comparison with constant. */\n      if (checku16(k)) {\n\temit_tai(as, PPCI_CMPLWI, cr, left, k);\n\treturn;\n      }\n    }\n  }\n  right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left));\n  emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right);\n}\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  PPCCC cc = asm_compmap[ir->o];\n  if (irt_isnum(ir->t)) {\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    asm_guardcc(as, (cc >> 4));\n    if ((cc & CC_TWO))\n      emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3));\n    emit_fab(as, PPCI_FCMPU, 0, left, right);\n  } else {\n    IRRef lref = ir->op1, rref = ir->op2;\n    if (irref_isk(lref) && !irref_isk(rref)) {\n      /* Swap constants to the right (only for ABC). */\n      IRRef tmp = lref; lref = rref; rref = tmp;\n      if ((cc & 2) == 0) cc ^= 1;  /* LT <-> GT, LE <-> GE */\n    }\n    asm_guardcc(as, cc);\n    asm_intcomp_(as, lref, rref, 0, cc);\n  }\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_comp64(ASMState *as, IRIns *ir)\n{\n  PPCCC cc = asm_compmap[(ir-1)->o];\n  if ((cc&3) == (CC_EQ&3)) {\n    asm_guardcc(as, cc);\n    emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR,\n\t     (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3));\n  } else {\n    asm_guardcc(as, CC_EQ);\n    emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1));\n    emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC,\n\t     (CC_EQ&3), (CC_EQ&3), 4+(cc&3));\n  }\n  /* Loword comparison sets cr1 and is unsigned, except for equality. */\n  asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4,\n\t       cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED));\n  /* Hiword comparison sets cr0. */\n  asm_intcomp_(as, ir->op1, ir->op2, 0, cc);\n  as->flagmcp = NULL;  /* Doesn't work here. */\n}\n#endif\n\n/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */\n\n/* Hiword op of a split 64 bit op. Previous op must be the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n#if LJ_HASFFI\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n    asm_comp64(as, ir);\n    return;\n  } else if ((ir-1)->o == IR_XSTORE) {\n    as->curins--;  /* Handle both stores here. */\n    if ((ir-1)->r != RID_SINK) {\n      asm_xstore_(as, ir, 0);\n      asm_xstore_(as, ir-1, 4);\n    }\n    return;\n  }\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n  case IR_ADD: as->curins--; asm_add64(as, ir); break;\n  case IR_SUB: as->curins--; asm_sub64(as, ir); break;\n  case IR_NEG: as->curins--; asm_neg64(as, ir); break;\n  case IR_CALLN:\n  case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n  default: lua_assert(0); break;\n  }\n#else\n  UNUSED(as); UNUSED(ir); lua_assert(0);  /* Unused without FFI. */\n#endif\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, HOOK_PROFILE);\n  emit_lsglptr(as, PPCI_LBZ, RID_TMP,\n\t       (int32_t)offsetof(global_State, hookmask));\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */\n  Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;\n  rset_clear(allow, pbase);\n  tmp = allow ? rset_pickbot(allow) :\n\t\t(pbase == RID_RETHI ? RID_RETLO : RID_RETHI);\n  emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno));\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW);\n  else\n    ra_modified(as, tmp);\n  emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot));\n  emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp);\n  emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack));\n  if (pbase == RID_TMP)\n    emit_getgl(as, RID_TMP, jit_base);\n  emit_getgl(as, tmp, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_fai(as, PPCI_STFD, src, RID_BASE, ofs);\n    } else {\n      Reg type;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, allow);\n\trset_clear(allow, src);\n\temit_tai(as, PPCI_STW, src, RID_BASE, ofs+4);\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), allow);\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      }\n      emit_tai(as, PPCI_STW, type, RID_BASE, ofs);\n    }\n    checkmclim(as);\n  }\n  lua_assert(map + nent == flinks);\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  emit_ai(as, PPCI_CMPWI, RID_RET, 0);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  tmp = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end);\n  emit_ab(as, PPCI_CMPLW, RID_TMP, tmp);\n  emit_getgl(as, tmp, gc.threshold);\n  emit_getgl(as, RID_TMP, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guardcc already inverted the cond branch and patched the final b. */\n    p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2);\n  } else {\n    p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_mr(as, r, RID_BASE);\n  }\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      rset_clear(allow, irp->r);\n      emit_mr(as, r, irp->r);  /* Move from coalesced parent reg. */\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *p = as->mctop;\n  MCode *target;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    *--p = PPCI_NOP;\n    *--p = PPCI_NOP;\n    as->mctop = p;\n  } else {\n    /* Patch stack adjustment. */\n    lua_assert(checki16(CFRAME_SIZE+spadj));\n    p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj);\n    p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj;\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop - 1;  /* Leave room for exit branch. */\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    as->mcp = p-2;  /* Leave room for stack pointer adjustment. */\n    as->invmcp = NULL;\n  }\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++)\n    if (args[i] && irt_isfp(IR(args[i])->t)) {\n      if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1;\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *px = exitstub_trace_addr(T, exitno);\n  MCode *cstart = NULL;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  int clearso = 0;\n  for (; p < pe; p++) {\n    /* Look for exitstub branch, try to replace with branch to target. */\n    uint32_t ins = *p;\n    if ((ins & 0xfc000000u) == 0x40000000u &&\n\t((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) {\n      ptrdiff_t delta = (char *)target - (char *)p;\n      if (((ins >> 16) & 3) == (CC_SO&3)) {\n\tclearso = sizeof(MCode);\n\tdelta -= sizeof(MCode);\n      }\n      /* Many, but not all short-range branches can be patched directly. */\n      if (((delta + 0x8000) >> 16) == 0) {\n\t*p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) |\n\t     ((delta & 0x8000) * (PPCF_Y/0x8000));\n\tif (!cstart) cstart = p;\n      }\n    } else if ((ins & 0xfc000000u) == PPCI_B &&\n\t       ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) {\n      ptrdiff_t delta = (char *)target - (char *)p;\n      lua_assert(((delta + 0x02000000) >> 26) == 0);\n      *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu);\n      if (!cstart) cstart = p;\n    }\n  }\n  {  /* Always patch long-range branch in exit stub itself. */\n    ptrdiff_t delta = (char *)target - (char *)px - clearso;\n    lua_assert(((delta + 0x02000000) >> 26) == 0);\n    *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu);\n  }\n  if (!cstart) cstart = px;\n  lj_mcode_sync(cstart, px+1);\n  if (clearso) {  /* Extend the current trace. Ugly workaround. */\n    MCode *pp = J->cur.mcode;\n    J->cur.szmcode += sizeof(MCode);\n    *--pp = PPCI_MCRXR;  /* Clear SO flag. */\n    J->cur.mcode = pp;\n    lj_mcode_sync(pp, pp+1);\n  }\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_asm_x86.h",
    "content": "/*\n** x86/x64 IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Generate an exit stub group at the bottom of the reserved MCode memory. */\nstatic MCode *asm_exitstub_gen(ASMState *as, ExitNo group)\n{\n  ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff;\n  MCode *mxp = as->mcbot;\n  MCode *mxpstart = mxp;\n  if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop)\n    asm_mclimit(as);\n  /* Push low byte of exitno for each exit stub. */\n  *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs;\n  for (i = 1; i < EXITSTUBS_PER_GROUP; i++) {\n    *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2);\n    *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i);\n  }\n  /* Push the high byte of the exitno for each exit stub group. */\n  *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8);\n  /* Store DISPATCH at original stack slot 0. Account for the two push ops. */\n  *mxp++ = XI_MOVmi;\n  *mxp++ = MODRM(XM_OFS8, 0, RID_ESP);\n  *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n  *mxp++ = 2*sizeof(void *);\n  *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4;\n  /* Jump to exit handler which fills in the ExitState. */\n  *mxp++ = XI_JMP; mxp += 4;\n  *((int32_t *)(mxp-4)) = jmprel(mxp, (MCode *)(void *)lj_vm_exit_handler);\n  /* Commit the code for this group (even if assembly fails later on). */\n  lj_mcode_commitbot(as->J, mxp);\n  as->mcbot = mxp;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  return mxpstart;\n}\n\n/* Setup all needed exit stubs. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)\n    lj_trace_err(as->J, LJ_TRERR_SNAPOV);\n  for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)\n    if (as->J->exitstubgroup[i] == NULL)\n      as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);\n}\n\n/* Emit conditional branch to exit for guard.\n** It's important to emit this *after* all registers have been allocated,\n** because rematerializations may invalidate the flags.\n*/\nstatic void asm_guardcc(ASMState *as, int cc)\n{\n  MCode *target = exitstub_addr(as->J, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *(int32_t *)(p+1) = jmprel(p+5, target);\n    target = p;\n    cc ^= 1;\n    if (as->realign) {\n      emit_sjcc(as, cc, target);\n      return;\n    }\n  }\n  emit_jcc(as, cc, target);\n}\n\n/* -- Memory operand fusion ----------------------------------------------- */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if a reference is a signed 32 bit constant. */\nstatic int asm_isk32(ASMState *as, IRRef ref, int32_t *k)\n{\n  if (irref_isk(ref)) {\n    IRIns *ir = IR(ref);\n    if (ir->o != IR_KINT64) {\n      *k = ir->i;\n      return 1;\n    } else if (checki32((int64_t)ir_kint64(ir)->u64)) {\n      *k = (int32_t)ir_kint64(ir)->u64;\n      return 1;\n    }\n  }\n  return 0;\n}\n\n/* Check if there's no conflicting instruction between curins and ref.\n** Also avoid fusing loads if there are multiple references.\n*/\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref) {\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n    else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref))\n      return 0;\n  }\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse array base into memory operand. */\nstatic IRRef asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *irb = IR(ref);\n  as->mrm.ofs = 0;\n  if (irb->o == IR_FLOAD) {\n    IRIns *ira = IR(irb->op1);\n    lua_assert(irb->op2 == IRFL_TAB_ARRAY);\n    /* We can avoid the FLOAD of t->array for colocated arrays. */\n    if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE &&\n\t!neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) {\n      as->mrm.ofs = (int32_t)sizeof(GCtab);  /* Ofs to colocated array. */\n      return irb->op1;  /* Table obj. */\n    }\n  } else if (irb->o == IR_ADD && irref_isk(irb->op2)) {\n    /* Fuse base offset (vararg load). */\n    as->mrm.ofs = IR(irb->op2)->i;\n    return irb->op1;\n  }\n  return ref;  /* Otherwise use the given array base. */\n}\n\n/* Fuse array reference into memory operand. */\nstatic void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irx;\n  lua_assert(ir->o == IR_AREF);\n  as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow);\n  irx = IR(ir->op2);\n  if (irref_isk(ir->op2)) {\n    as->mrm.ofs += 8*irx->i;\n    as->mrm.idx = RID_NONE;\n  } else {\n    rset_clear(allow, as->mrm.base);\n    as->mrm.scale = XM_SCALE8;\n    /* Fuse a constant ADD (e.g. t[i+1]) into the offset.\n    ** Doesn't help much without ABCelim, but reduces register pressure.\n    */\n    if (!LJ_64 &&  /* Has bad effects with negative index on x64. */\n\tmayfuse(as, ir->op2) && ra_noreg(irx->r) &&\n\tirx->o == IR_ADD && irref_isk(irx->op2)) {\n      as->mrm.ofs += 8*IR(irx->op2)->i;\n      as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow);\n    } else {\n      as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow);\n    }\n  }\n}\n\n/* Fuse array/hash/upvalue reference into memory operand.\n** Caveat: this may allocate GPRs for the base/idx registers. Be sure to\n** pass the final allow mask, excluding any GPRs used for other inputs.\n** In particular: 2-operand GPR instructions need to call ra_dest() first!\n*/\nstatic void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    switch ((IROp)ir->o) {\n    case IR_AREF:\n      if (mayfuse(as, ref)) {\n\tasm_fusearef(as, ir, allow);\n\treturn;\n      }\n      break;\n    case IR_HREFK:\n      if (mayfuse(as, ref)) {\n\tas->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);\n\tas->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tas->mrm.idx = RID_NONE;\n\treturn;\n      }\n      break;\n    case IR_UREFC:\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tGCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv;\n\tas->mrm.ofs = ptr2addr(&uv->tv);\n\tas->mrm.base = as->mrm.idx = RID_NONE;\n\treturn;\n      }\n      break;\n    default:\n      lua_assert(ir->o == IR_HREF || ir->o == IR_NEWREF || ir->o == IR_UREFO ||\n\t\t ir->o == IR_KKPTR);\n      break;\n    }\n  }\n  as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);\n  as->mrm.ofs = 0;\n  as->mrm.idx = RID_NONE;\n}\n\n/* Fuse FLOAD/FREF reference into memory operand. */\nstatic void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow)\n{\n  lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF);\n  as->mrm.ofs = field_ofs[ir->op2];\n  as->mrm.idx = RID_NONE;\n  if (irref_isk(ir->op1)) {\n    as->mrm.ofs += IR(ir->op1)->i;\n    as->mrm.base = RID_NONE;\n  } else {\n    as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);\n  }\n}\n\n/* Fuse string reference into memory operand. */\nstatic void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irr;\n  lua_assert(ir->o == IR_STRREF);\n  as->mrm.base = as->mrm.idx = RID_NONE;\n  as->mrm.scale = XM_SCALE1;\n  as->mrm.ofs = sizeof(GCstr);\n  if (irref_isk(ir->op1)) {\n    as->mrm.ofs += IR(ir->op1)->i;\n  } else {\n    Reg r = ra_alloc1(as, ir->op1, allow);\n    rset_clear(allow, r);\n    as->mrm.base = (uint8_t)r;\n  }\n  irr = IR(ir->op2);\n  if (irref_isk(ir->op2)) {\n    as->mrm.ofs += irr->i;\n  } else {\n    Reg r;\n    /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */\n    if (!LJ_64 &&  /* Has bad effects with negative index on x64. */\n\tmayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) {\n      as->mrm.ofs += IR(irr->op2)->i;\n      r = ra_alloc1(as, irr->op1, allow);\n    } else {\n      r = ra_alloc1(as, ir->op2, allow);\n    }\n    if (as->mrm.base == RID_NONE)\n      as->mrm.base = (uint8_t)r;\n    else\n      as->mrm.idx = (uint8_t)r;\n  }\n}\n\nstatic void asm_fusexref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  as->mrm.idx = RID_NONE;\n  if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n    as->mrm.ofs = ir->i;\n    as->mrm.base = RID_NONE;\n  } else if (ir->o == IR_STRREF) {\n    asm_fusestrref(as, ir, allow);\n  } else {\n    as->mrm.ofs = 0;\n    if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) {\n      /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */\n      IRIns *irx;\n      IRRef idx;\n      Reg r;\n      if (asm_isk32(as, ir->op2, &as->mrm.ofs)) {  /* Recognize x+ofs. */\n\tref = ir->op1;\n\tir = IR(ref);\n\tif (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r)))\n\t  goto noadd;\n      }\n      as->mrm.scale = XM_SCALE1;\n      idx = ir->op1;\n      ref = ir->op2;\n      irx = IR(idx);\n      if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) {  /* Try other operand. */\n\tidx = ir->op2;\n\tref = ir->op1;\n\tirx = IR(idx);\n      }\n      if (canfuse(as, irx) && ra_noreg(irx->r)) {\n\tif (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) {\n\t  /* Recognize idx<<b with b = 0-3, corresponding to sz = (1),2,4,8. */\n\t  idx = irx->op1;\n\t  as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6);\n\t} else if (irx->o == IR_ADD && irx->op1 == irx->op2) {\n\t  /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */\n\t  idx = irx->op1;\n\t  as->mrm.scale = XM_SCALE2;\n\t}\n      }\n      r = ra_alloc1(as, idx, allow);\n      rset_clear(allow, r);\n      as->mrm.idx = (uint8_t)r;\n    }\n  noadd:\n    as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);\n  }\n}\n\n/* Fuse load into memory operand. */\nstatic Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_hasreg(ir->r)) {\n    if (allow != RSET_EMPTY) {  /* Fast path. */\n      ra_noweak(as, ir->r);\n      return ir->r;\n    }\n  fusespill:\n    /* Force a spill if only memory operands are allowed (asm_x87load). */\n    as->mrm.base = RID_ESP;\n    as->mrm.ofs = ra_spill(as, ir);\n    as->mrm.idx = RID_NONE;\n    return RID_MRM;\n  }\n  if (ir->o == IR_KNUM) {\n    RegSet avail = as->freeset & ~as->modset & RSET_FPR;\n    lua_assert(allow != RSET_EMPTY);\n    if (!(avail & (avail-1))) {  /* Fuse if less than two regs available. */\n      as->mrm.ofs = ptr2addr(ir_knum(ir));\n      as->mrm.base = as->mrm.idx = RID_NONE;\n      return RID_MRM;\n    }\n  } else if (ir->o == IR_KINT64) {\n    RegSet avail = as->freeset & ~as->modset & RSET_GPR;\n    lua_assert(allow != RSET_EMPTY);\n    if (!(avail & (avail-1))) {  /* Fuse if less than two regs available. */\n      as->mrm.ofs = ptr2addr(ir_kint64(ir));\n      as->mrm.base = as->mrm.idx = RID_NONE;\n      return RID_MRM;\n    }\n  } else if (mayfuse(as, ref)) {\n    RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR;\n    if (ir->o == IR_SLOAD) {\n      if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) &&\n\t  noconflict(as, ref, IR_RETF, 0)) {\n\tas->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow);\n\tas->mrm.ofs = 8*((int32_t)ir->op1-1) + ((ir->op2&IRSLOAD_FRAME)?4:0);\n\tas->mrm.idx = RID_NONE;\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_FLOAD) {\n      /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */\n      if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) &&\n\t  noconflict(as, ref, IR_FSTORE, 0)) {\n\tasm_fusefref(as, ir, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) {\n      if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0)) {\n\tasm_fuseahuref(as, ir->op1, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_XLOAD) {\n      /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp).\n      ** Fusing unaligned memory operands is ok on x86 (except for SIMD types).\n      */\n      if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) &&\n\t  noconflict(as, ref, IR_XSTORE, 0)) {\n\tasm_fusexref(as, ir->op1, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_VLOAD) {\n      asm_fuseahuref(as, ir->op1, xallow);\n      return RID_MRM;\n    }\n  }\n  if (!(as->freeset & allow) && !irref_isk(ref) &&\n      (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref)))\n    goto fusespill;\n  return ra_allocref(as, ref, allow);\n}\n\n#if LJ_64\n/* Don't fuse a 32 bit load into a 64 bit operation. */\nstatic Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64)\n{\n  if (is64 && !irt_is64(IR(ref)->t))\n    return ra_alloc1(as, ref, allow);\n  return asm_fuseload(as, ref, allow);\n}\n#else\n#define asm_fuseloadm(as, ref, allow, is64)  asm_fuseload(as, (ref), (allow))\n#endif\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Count the required number of stack slots for a call. */\nstatic int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 0;\n#if LJ_64\n  if (LJ_ABI_WIN) {\n    nslots = (int)(nargs*2);  /* Only matters for more than four args. */\n  } else {\n    int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n    for (i = 0; i < nargs; i++)\n      if (args[i] && irt_isfp(IR(args[i])->t)) {\n\tif (nfpr > 0) nfpr--; else nslots += 2;\n      } else {\n\tif (ngpr > 0) ngpr--; else nslots += 2;\n      }\n  }\n#else\n  int ngpr = 0;\n  if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)\n    ngpr = 2;\n  else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)\n    ngpr = 1;\n  for (i = 0; i < nargs; i++)\n    if (args[i] && irt_isfp(IR(args[i])->t)) {\n      nslots += irt_isnum(IR(args[i])->t) ? 2 : 1;\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n#endif\n  return nslots;\n}\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = STACKARG_OFS;\n#if LJ_64\n  uint32_t gprs = REGARG_GPRS;\n  Reg fpr = REGARG_FIRSTFPR;\n#if !LJ_ABI_WIN\n  MCode *patchnfpr = NULL;\n#endif\n#else\n  uint32_t gprs = 0;\n  if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) {\n    if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)\n      gprs = (REGARG_GPRS & 31);\n    else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)\n      gprs = REGARG_GPRS;\n  }\n#endif\n  if ((void *)ci->func)\n    emit_call(as, ci->func);\n#if LJ_64\n  if ((ci->flags & CCI_VARARG)) {  /* Special handling for vararg calls. */\n#if LJ_ABI_WIN\n    for (n = 0; n < 4 && n < nargs; n++) {\n      IRIns *ir = IR(args[n]);\n      if (irt_isfp(ir->t))  /* Duplicate FPRs in GPRs. */\n\temit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n),\n\t\t((gprs >> (n*5)) & 31));  /* Either MOVD or MOVQ. */\n    }\n#else\n    patchnfpr = --as->mcp;  /* Indicate number of used FPRs in register al. */\n    *--as->mcp = XI_MOVrib | RID_EAX;\n#endif\n  }\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    IRIns *ir = IR(ref);\n    Reg r;\n#if LJ_64 && LJ_ABI_WIN\n    /* Windows/x64 argument registers are strictly positional. */\n    r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);\n    fpr++; gprs >>= 5;\n#elif LJ_64\n    /* POSIX/x64 argument registers are used in order of appearance. */\n    if (irt_isfp(ir->t)) {\n      r = fpr <= REGARG_LASTFPR ? fpr++ : 0;\n    } else {\n      r = gprs & 31; gprs >>= 5;\n    }\n#else\n    if (ref && irt_isfp(ir->t)) {\n      r = 0;\n    } else {\n      r = gprs & 31; gprs >>= 5;\n      if (!ref) continue;\n    }\n#endif\n    if (r) {  /* Argument is in a register. */\n      if (r < RID_MAX_GPR && ref < ASMREF_TMP1) {\n#if LJ_64\n\tif (ir->o == IR_KINT64)\n\t  emit_loadu64(as, r, ir_kint64(ir)->u64);\n\telse\n#endif\n\t  emit_loadi(as, r, ir->i);\n      } else {\n\tlua_assert(rset_test(as->freeset, r));  /* Must have been evicted. */\n\tif (ra_hasreg(ir->r)) {\n\t  ra_noweak(as, ir->r);\n\t  emit_movrr(as, ir, r, ir->r);\n\t} else {\n\t  ra_allocref(as, ref, RID2RSET(r));\n\t}\n      }\n    } else if (irt_isfp(ir->t)) {  /* FP argument is on stack. */\n      lua_assert(!(irt_isfloat(ir->t) && irref_isk(ref)));  /* No float k. */\n      if (LJ_32 && (ofs & 4) && irref_isk(ref)) {\n\t/* Split stores for unaligned FP consts. */\n\temit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo);\n\temit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi);\n      } else {\n\tr = ra_alloc1(as, ref, RSET_FPR);\n\temit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto,\n\t\t  r, RID_ESP, ofs);\n      }\n      ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8;\n    } else {  /* Non-FP argument is on stack. */\n      if (LJ_32 && ref < ASMREF_TMP1) {\n\temit_movmroi(as, RID_ESP, ofs, ir->i);\n      } else {\n\tr = ra_alloc1(as, ref, RSET_GPR);\n\temit_movtomro(as, REX_64 + r, RID_ESP, ofs);\n      }\n      ofs += sizeof(intptr_t);\n    }\n    checkmclim(as);\n  }\n#if LJ_64 && !LJ_ABI_WIN\n  if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR;\n#endif\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = (LJ_32 && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    if (irt_isfp(ir->t)) {\n      int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n#if LJ_64\n      if ((ci->flags & CCI_CASTU64)) {\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n\t  emit_rr(as, XO_MOVD, dest|REX_64, RID_RET);  /* Really MOVQ. */\n\t}\n\tif (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n#else\n      /* Number result is in x87 st0 for x86 calling convention. */\n      Reg dest = ir->r;\n      if (ra_hasreg(dest)) {\n\tra_free(as, dest);\n\tra_modified(as, dest);\n\temit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS,\n\t\t  dest, RID_ESP, ofs);\n      }\n      if ((ci->flags & CCI_CASTU64)) {\n\temit_movtomro(as, RID_RETLO, RID_ESP, ofs);\n\temit_movtomro(as, RID_RETHI, RID_ESP, ofs+4);\n      } else {\n\temit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,\n\t\t  irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);\n      }\n#endif\n#if LJ_32\n    } else if (hiop) {\n      ra_destpair(as, ir);\n#endif\n    } else {\n      lua_assert(!irt_ispri(ir->t));\n      ra_destreg(as, ir, RID_RET);\n    }\n  } else if (LJ_32 && irt_isfp(ir->t) && !(ci->flags & CCI_CASTU64)) {\n    emit_x87op(as, XI_FPOP);  /* Pop unused result from x87 st0. */\n  }\n}\n\n/* Return a constant function pointer or NULL for indirect calls. */\nstatic void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func)\n{\n#if LJ_32\n  UNUSED(as);\n  if (irref_isk(func))\n    return (void *)irf->i;\n#else\n  if (irref_isk(func)) {\n    MCode *p;\n    if (irf->o == IR_KINT64)\n      p = (MCode *)(void *)ir_k64(irf)->u64;\n    else\n      p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i;\n    if (p - as->mcp == (int32_t)(p - as->mcp))\n      return p;  /* Call target is still in +-2GB range. */\n    /* Avoid the indirect case of emit_call(). Try to hoist func addr. */\n  }\n#endif\n  return NULL;\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  int32_t spadj = 0;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n#if LJ_32\n  /* Have to readjust stack after non-cdecl calls due to callee cleanup. */\n  if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)\n    spadj = 4 * asm_count_call_slots(as, &ci, args);\n#endif\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  ci.func = (ASMFunction)asm_callx_func(as, irf, func);\n  if (!(void *)ci.func) {\n    /* Use a (hoistable) non-scratch register for indirect calls. */\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n    Reg r = ra_alloc1(as, func, allow);\n    if (LJ_32) emit_spsub(as, spadj);  /* Above code may cause restores! */\n    emit_rr(as, XO_GROUP5, XOg_CALL, r);\n  } else if (LJ_32) {\n    emit_spsub(as, spadj);\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc));\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guardcc(as, CC_P);\n  asm_guardcc(as, CC_NE);\n  emit_rr(as, XO_UCOMISD, left, tmp);\n  emit_rr(as, XO_CVTSI2SD, tmp, dest);\n  emit_rr(as, XO_XORPS, tmp, tmp);  /* Avoid partial register stall. */\n  emit_rr(as, XO_CVTTSD2SI, dest, left);\n  /* Can't fuse since left is needed twice. */\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg tmp = ra_noreg(IR(ir->op1)->r) ?\n\t      ra_alloc1(as, ir->op1, RSET_FPR) :\n\t      ra_scratch(as, RSET_FPR);\n  Reg right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp));\n  emit_rr(as, XO_MOVDto, tmp, dest);\n  emit_mrm(as, XO_ADDSD, tmp, right);\n  ra_left(as, tmp, ir->op1);\n}\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n  int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64));\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n  IRRef lref = ir->op1;\n  lua_assert(irt_type(ir->t) != st);\n  lua_assert(!(LJ_32 && (irt_isint64(ir->t) || st64)));  /* Handled by SPLIT. */\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      Reg left = asm_fuseload(as, lref, RSET_FPR);\n      emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left);\n      if (left == dest) return;  /* Avoid the XO_XORPS. */\n    } else if (LJ_32 && st == IRT_U32) {  /* U32 to FP conversion on x86. */\n      /* number = (2^52+2^51 .. u32) - (2^52+2^51) */\n      cTValue *k = lj_ir_k64_find(as->J, U64x(43380000,00000000));\n      Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      if (irt_isfloat(ir->t))\n\temit_rr(as, XO_CVTSD2SS, dest, dest);\n      emit_rr(as, XO_SUBSD, dest, bias);  /* Subtract 2^52+2^51 bias. */\n      emit_rr(as, XO_XORPS, dest, bias);  /* Merge bias and integer. */\n      emit_loadn(as, bias, k);\n      emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR));\n      return;\n    } else {  /* Integer to FP conversion. */\n      Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ?\n\t\t ra_alloc1(as, lref, RSET_GPR) :\n\t\t asm_fuseloadm(as, lref, RSET_GPR, st64);\n      if (LJ_64 && st == IRT_U64) {\n\tMCLabel l_end = emit_label(as);\n\tconst void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000));\n\temit_rma(as, XO_ADDSD, dest, k);  /* Add 2^64 to compensate. */\n\temit_sjcc(as, CC_NS, l_end);\n\temit_rr(as, XO_TEST, left|REX_64, left);  /* Check if u64 >= 2^63. */\n      }\n      emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS,\n\t       dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left);\n    }\n    emit_rr(as, XO_XORPS, dest, dest);  /* Avoid partial register stall. */\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lua_assert(irt_isint(ir->t) && st == IRT_NUM);\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      x86Op op = st == IRT_NUM ? XO_CVTTSD2SI : XO_CVTTSS2SI;\n      if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) {\n\t/* LJ_64: For inputs >= 2^63 add -2^64, convert again. */\n\t/* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */\n\tReg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) :\n\t\t\t\t\t  ra_scratch(as, RSET_FPR);\n\tMCLabel l_end = emit_label(as);\n\tif (LJ_32)\n\t  emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000);\n\temit_rr(as, op, dest|REX_64, tmp);\n\tif (st == IRT_NUM)\n\t  emit_rma(as, XO_ADDSD, tmp, lj_ir_k64_find(as->J,\n\t\t   LJ_64 ? U64x(c3f00000,00000000) : U64x(c1e00000,00000000)));\n\telse\n\t  emit_rma(as, XO_ADDSS, tmp, lj_ir_k64_find(as->J,\n\t\t   LJ_64 ? U64x(00000000,df800000) : U64x(00000000,cf000000)));\n\temit_sjcc(as, CC_NS, l_end);\n\temit_rr(as, XO_TEST, dest|REX_64, dest);  /* Check if dest negative. */\n\temit_rr(as, op, dest|REX_64, tmp);\n\tra_left(as, tmp, lref);\n      } else {\n\tReg left = asm_fuseload(as, lref, RSET_FPR);\n\tif (LJ_64 && irt_isu32(ir->t))\n\t  emit_rr(as, XO_MOV, dest, dest);  /* Zero hiword. */\n\temit_mrm(as, op,\n\t\t dest|((LJ_64 &&\n\t\t\t(irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0),\n\t\t left);\n      }\n    }\n  } else if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n    Reg left, dest = ra_dest(as, ir, RSET_GPR);\n    RegSet allow = RSET_GPR;\n    x86Op op;\n    lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));\n    if (st == IRT_I8) {\n      op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX;\n    } else if (st == IRT_U8) {\n      op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX;\n    } else if (st == IRT_I16) {\n      op = XO_MOVSXw;\n    } else {\n      op = XO_MOVZXw;\n    }\n    left = asm_fuseload(as, lref, allow);\n    /* Add extra MOV if source is already in wrong register. */\n    if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) {\n      Reg tmp = ra_scratch(as, allow);\n      emit_rr(as, op, dest, tmp);\n      emit_rr(as, XO_MOV, tmp, left);\n    } else {\n      emit_mrm(as, op, dest, left);\n    }\n  } else {  /* 32/64 bit integer conversions. */\n    if (LJ_32) {  /* Only need to handle 32/32 bit no-op (cast) on x86. */\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      ra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    } else if (irt_is64(ir->t)) {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      if (st64 || !(ir->op2 & IRCONV_SEXT)) {\n\t/* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */\n\tra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      } else {  /* 32 to 64 bit sign extension. */\n\tReg left = asm_fuseload(as, lref, RSET_GPR);\n\temit_mrm(as, XO_MOVSXd, dest|REX_64, left);\n      }\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      if (st64) {\n\tReg left = asm_fuseload(as, lref, RSET_GPR);\n\t/* This is either a 32 bit reg/reg mov which zeroes the hiword\n\t** or a load of the loword from a 64 bit address.\n\t*/\n\temit_mrm(as, XO_MOV, dest, left);\n      } else {  /* 32/32 bit no-op (cast). */\n\tra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      }\n    }\n  }\n}\n\n#if LJ_32 && LJ_HASFFI\n/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */\n\n/* 64 bit integer to FP conversion in 32 bit mode. */\nstatic void asm_conv_fp_int64(ASMState *as, IRIns *ir)\n{\n  Reg hi = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi));\n  int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS, dest, RID_ESP, ofs);\n  }\n  emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,\n\t    irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);\n  if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) {\n    /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */\n    MCLabel l_end = emit_label(as);\n    emit_rma(as, XO_FADDq, XOg_FADDq,\n\t     lj_ir_k64_find(as->J, U64x(43f00000,00000000)));\n    emit_sjcc(as, CC_NS, l_end);\n    emit_rr(as, XO_TEST, hi, hi);  /* Check if u64 >= 2^63. */\n  } else {\n    lua_assert(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64);\n  }\n  emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0);\n  /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */\n  emit_rmro(as, XO_MOVto, hi, RID_ESP, 4);\n  emit_rmro(as, XO_MOVto, lo, RID_ESP, 0);\n}\n\n/* FP to 64 bit integer conversion in 32 bit mode. */\nstatic void asm_conv_int64_fp(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);\n  IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);\n  Reg lo, hi;\n  lua_assert(st == IRT_NUM || st == IRT_FLOAT);\n  lua_assert(dt == IRT_I64 || dt == IRT_U64);\n  hi = ra_dest(as, ir, RSET_GPR);\n  lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi));\n  if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0);\n  /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */\n  if (!(as->flags & JIT_F_SSE3)) {  /* Set FPU rounding mode to default. */\n    emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4);\n    emit_rmro(as, XO_MOVto, lo, RID_ESP, 4);\n    emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff);\n  }\n  if (dt == IRT_U64) {\n    /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */\n    MCLabel l_pop, l_end = emit_label(as);\n    emit_x87op(as, XI_FPOP);\n    l_pop = emit_label(as);\n    emit_sjmp(as, l_end);\n    emit_rmro(as, XO_MOV, hi, RID_ESP, 4);\n    if ((as->flags & JIT_F_SSE3))\n      emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);\n    else\n      emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);\n    emit_rma(as, XO_FADDq, XOg_FADDq,\n\t     lj_ir_k64_find(as->J, U64x(c3f00000,00000000)));\n    emit_sjcc(as, CC_NS, l_pop);\n    emit_rr(as, XO_TEST, hi, hi);  /* Check if out-of-range (2^63). */\n  }\n  emit_rmro(as, XO_MOV, hi, RID_ESP, 4);\n  if ((as->flags & JIT_F_SSE3)) {  /* Truncation is easy with SSE3. */\n    emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);\n  } else {  /* Otherwise set FPU rounding mode to truncate before the store. */\n    emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);\n    emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0);\n    emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0);\n    emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0);\n    emit_loadi(as, lo, 0xc00);\n    emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0);\n  }\n  if (dt == IRT_U64)\n    emit_x87op(as, XI_FDUP);\n  emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd,\n\t   st == IRT_NUM ? XOg_FLDq: XOg_FLDd,\n\t   asm_fuseload(as, ir->op1, RSET_EMPTY));\n}\n\nstatic void asm_conv64(ASMState *as, IRIns *ir)\n{\n  if (irt_isfp(ir->t))\n    asm_conv_fp_int64(as, ir);\n  else\n    asm_conv_int64_fp(as, ir);\n}\n#endif\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  /* Force a spill slot for the destination register (if any). */\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  RegSet drop = RSET_SCRATCH;\n  if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r))\n    rset_set(drop, ir->r);  /* WIN64 doesn't spill all FPRs. */\n  ra_evictset(as, drop);\n  asm_guardcc(as, CC_E);\n  emit_rr(as, XO_TEST, RID_RET, RID_RET);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,\n\t    RID_ESP, sps_scale(ir->s));\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isnum(ir->t)) {\n    /* For numbers use the constant itself or a spill slot as a TValue. */\n    if (irref_isk(ref))\n      emit_loada(as, dest, ir_knum(ir));\n    else\n      emit_rmro(as, XO_LEA, dest|REX_64, RID_ESP, ra_spill(as, ir));\n  } else {\n    /* Otherwise use g->tmptv to hold the TValue. */\n    if (!irref_isk(ref)) {\n      Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, dest));\n      emit_movtomro(as, REX_64IR(ir, src), dest, 0);\n    } else if (!irt_ispri(ir->t)) {\n      emit_movmroi(as, dest, 0, ir->i);\n    }\n    if (!(LJ_64 && irt_islightud(ir->t)))\n      emit_movmroi(as, dest, 4, irt_toitype(ir->t));\n    emit_loada(as, dest, &J2G(as->J)->tmptv);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusearef(as, ir, RSET_GPR);\n  if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0))\n    emit_mrm(as, XO_LEA, dest, RID_MRM);\n  else if (as->mrm.base != dest)\n    emit_rr(as, XO_MOV, dest, as->mrm.base);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, tmp = RID_NONE;\n  IRIns *irkey = IR(ir->op2);\n  int isk = irref_isk(ir->op2);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  if (!isk) {\n    rset_clear(allow, tab);\n    key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow);\n    if (!irt_isstr(kt))\n      tmp = ra_scratch(as, rset_exclude(allow, key));\n  }\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_E);  /* XI_JMP is not found by lj_asm_patchexit. */\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = emit_sjcc_label(as, CC_NZ);\n  emit_rr(as, XO_TEST, dest, dest);\n  emit_rmro(as, XO_MOV, dest, dest, offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_E);\n  else\n    emit_sjcc(as, CC_E, l_end);\n  if (irt_isnum(kt)) {\n    if (isk) {\n      /* Assumes -0.0 is already canonicalized to +0.0. */\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo),\n\t\t (int32_t)ir_knum(irkey)->u32.lo);\n      emit_sjcc(as, CC_NE, l_next);\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi),\n\t\t (int32_t)ir_knum(irkey)->u32.hi);\n    } else {\n      emit_sjcc(as, CC_P, l_next);\n      emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n));\n      emit_sjcc(as, CC_AE, l_next);\n      /* The type check avoids NaN penalties and complaints from Valgrind. */\n#if LJ_64\n      emit_u32(as, LJ_TISNUM);\n      emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it));\n#else\n      emit_i8(as, LJ_TISNUM);\n      emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));\n#endif\n    }\n#if LJ_64\n  } else if (irt_islightud(kt)) {\n    emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64));\n#endif\n  } else {\n    if (!irt_ispri(kt)) {\n      lua_assert(irt_isaddr(kt));\n      if (isk)\n\temit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr),\n\t\t   ptr2addr(ir_kgc(irkey)));\n      else\n\temit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr));\n      emit_sjcc(as, CC_NE, l_next);\n    }\n    lua_assert(!irt_isnil(kt));\n    emit_i8(as, irt_toitype(kt));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));\n  }\n  emit_sfixup(as, l_loop);\n  checkmclim(as);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = isk ? ir_khash(irkey) : 1;\n  if (khash == 0) {\n    emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, node));\n  } else {\n    emit_rmro(as, XO_ARITH(XOg_ADD), dest, tab, offsetof(GCtab, node));\n    if ((as->flags & JIT_F_PREFER_IMUL)) {\n      emit_i8(as, sizeof(Node));\n      emit_rr(as, XO_IMULi8, dest, dest);\n    } else {\n      emit_shifti(as, XOg_SHL, dest, 3);\n      emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0);\n    }\n    if (isk) {\n      emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash);\n      emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));\n    } else if (irt_isstr(kt)) {\n      emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, hash));\n      emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));\n    } else {  /* Must match with hashrot() in lj_tab.c. */\n      emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask));\n      emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp);\n      emit_shifti(as, XOg_ROL, tmp, HASH_ROT3);\n      emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp);\n      emit_shifti(as, XOg_ROL, dest, HASH_ROT2);\n      emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest);\n      emit_shifti(as, XOg_ROL, dest, HASH_ROT1);\n      emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest);\n      if (irt_isnum(kt)) {\n\temit_rr(as, XO_ARITH(XOg_ADD), dest, dest);\n#if LJ_64\n\temit_shifti(as, XOg_SHR|REX_64, dest, 32);\n\temit_rr(as, XO_MOV, tmp, dest);\n\temit_rr(as, XO_MOVDto, key|REX_64, dest);\n#else\n\temit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4);\n\temit_rr(as, XO_MOVDto, key, tmp);\n#endif\n      } else {\n\temit_rr(as, XO_MOV, tmp, key);\n\temit_rmro(as, XO_LEA, dest, key, HASH_BIAS);\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n#if !LJ_64\n  MCLabel l_exit;\n#endif\n  lua_assert(ofs % sizeof(Node) == 0);\n  if (ra_hasreg(dest)) {\n    if (ofs != 0) {\n      if (dest == node && !(as->flags & JIT_F_LEA_AGU))\n\temit_gri(as, XG_ARITHi(XOg_ADD), dest, ofs);\n      else\n\temit_rmro(as, XO_LEA, dest, node, ofs);\n    } else if (dest != node) {\n      emit_rr(as, XO_MOV, dest, node);\n    }\n  }\n  asm_guardcc(as, CC_NE);\n#if LJ_64\n  if (!irt_ispri(irkey->t)) {\n    Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node));\n    emit_rmro(as, XO_CMP, key|REX_64, node,\n\t       ofs + (int32_t)offsetof(Node, key.u64));\n    lua_assert(irt_isnum(irkey->t) || irt_isgcv(irkey->t));\n    /* Assumes -0.0 is already canonicalized to +0.0. */\n    emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 :\n\t\t\t  ((uint64_t)irt_toitype(irkey->t) << 32) |\n\t\t\t  (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey)));\n  } else {\n    lua_assert(!irt_isnil(irkey->t));\n    emit_i8(as, irt_toitype(irkey->t));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, node,\n\t      ofs + (int32_t)offsetof(Node, key.it));\n  }\n#else\n  l_exit = emit_label(as);\n  if (irt_isnum(irkey->t)) {\n    /* Assumes -0.0 is already canonicalized to +0.0. */\n    emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t       ofs + (int32_t)offsetof(Node, key.u32.lo),\n\t       (int32_t)ir_knum(irkey)->u32.lo);\n    emit_sjcc(as, CC_NE, l_exit);\n    emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t       ofs + (int32_t)offsetof(Node, key.u32.hi),\n\t       (int32_t)ir_knum(irkey)->u32.hi);\n  } else {\n    if (!irt_ispri(irkey->t)) {\n      lua_assert(irt_isgcv(irkey->t));\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t\t ofs + (int32_t)offsetof(Node, key.gcr),\n\t\t ptr2addr(ir_kgc(irkey)));\n      emit_sjcc(as, CC_NE, l_exit);\n    }\n    lua_assert(!irt_isnil(irkey->t));\n    emit_i8(as, irt_toitype(irkey->t));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, node,\n\t      ofs + (int32_t)offsetof(Node, key.it));\n  }\n#endif\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  /* NYI: Check that UREFO is still open and not aliasing a slot. */\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_rma(as, XO_MOV, dest, v);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      emit_rmro(as, XO_LEA, dest, uv, offsetof(GCupval, tv));\n      asm_guardcc(as, CC_NE);\n      emit_i8(as, 1);\n      emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed));\n    } else {\n      emit_rmro(as, XO_MOV, dest, uv, offsetof(GCupval, v));\n    }\n    emit_rmro(as, XO_MOV, uv, func,\n\t      (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusefref(as, ir, RSET_GPR);\n  emit_mrm(as, XO_LEA, dest, RID_MRM);\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusestrref(as, ir, RSET_GPR);\n  if (as->mrm.base == RID_NONE)\n    emit_loadi(as, dest, as->mrm.ofs);\n  else if (as->mrm.base == dest && as->mrm.idx == RID_NONE)\n    emit_gri(as, XG_ARITHi(XOg_ADD), dest, as->mrm.ofs);\n  else\n    emit_mrm(as, XO_LEA, dest, RID_MRM);\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic void asm_fxload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n  x86Op xo;\n  if (ir->o == IR_FLOAD)\n    asm_fusefref(as, ir, RSET_GPR);\n  else\n    asm_fusexref(as, ir->op1, RSET_GPR);\n  /* ir->op2 is ignored -- unaligned loads are ok on x86. */\n  switch (irt_type(ir->t)) {\n  case IRT_I8: xo = XO_MOVSXb; break;\n  case IRT_U8: xo = XO_MOVZXb; break;\n  case IRT_I16: xo = XO_MOVSXw; break;\n  case IRT_U16: xo = XO_MOVZXw; break;\n  case IRT_NUM: xo = XO_MOVSD; break;\n  case IRT_FLOAT: xo = XO_MOVSS; break;\n  default:\n    if (LJ_64 && irt_is64(ir->t))\n      dest |= REX_64;\n    else\n      lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));\n    xo = XO_MOV;\n    break;\n  }\n  emit_mrm(as, xo, dest, RID_MRM);\n}\n\n#define asm_fload(as, ir)\tasm_fxload(as, ir)\n#define asm_xload(as, ir)\tasm_fxload(as, ir)\n\nstatic void asm_fxstore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg src = RID_NONE, osrc = RID_NONE;\n  int32_t k = 0;\n  if (ir->r == RID_SINK)\n    return;\n  /* The IRT_I16/IRT_U16 stores should never be simplified for constant\n  ** values since mov word [mem], imm16 has a length-changing prefix.\n  */\n  if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) ||\n      !asm_isk32(as, ir->op2, &k)) {\n    RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR :\n\t\t    (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR;\n    src = osrc = ra_alloc1(as, ir->op2, allow8);\n    if (!LJ_64 && !rset_test(allow8, src)) {  /* Already in wrong register. */\n      rset_clear(allow, osrc);\n      src = ra_scratch(as, allow8);\n    }\n    rset_clear(allow, src);\n  }\n  if (ir->o == IR_FSTORE) {\n    asm_fusefref(as, IR(ir->op1), allow);\n  } else {\n    asm_fusexref(as, ir->op1, allow);\n    if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4;\n  }\n  if (ra_hasreg(src)) {\n    x86Op xo;\n    switch (irt_type(ir->t)) {\n    case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break;\n    case IRT_I16: case IRT_U16: xo = XO_MOVtow; break;\n    case IRT_NUM: xo = XO_MOVSDto; break;\n    case IRT_FLOAT: xo = XO_MOVSSto; break;\n#if LJ_64\n    case IRT_LIGHTUD: lua_assert(0);  /* NYI: mask 64 bit lightuserdata. */\n#endif\n    default:\n      if (LJ_64 && irt_is64(ir->t))\n\tsrc |= REX_64;\n      else\n\tlua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));\n      xo = XO_MOVto;\n      break;\n    }\n    emit_mrm(as, xo, src, RID_MRM);\n    if (!LJ_64 && src != osrc) {\n      ra_noweak(as, osrc);\n      emit_rr(as, XO_MOV, src, osrc);\n    }\n  } else {\n    if (irt_isi8(ir->t) || irt_isu8(ir->t)) {\n      emit_i8(as, k);\n      emit_mrm(as, XO_MOVmib, 0, RID_MRM);\n    } else {\n      lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) ||\n\t\t irt_isaddr(ir->t));\n      emit_i32(as, k);\n      emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM);\n    }\n  }\n}\n\n#define asm_fstore(as, ir)\tasm_fxstore(as, ir)\n#define asm_xstore(as, ir)\tasm_fxstore(as, ir)\n\n#if LJ_64\nstatic Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck)\n{\n  if (ra_used(ir) || typecheck) {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (typecheck) {\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest));\n      asm_guardcc(as, CC_NE);\n      emit_i8(as, -2);\n      emit_rr(as, XO_ARITHi8, XOg_CMP, tmp);\n      emit_shifti(as, XOg_SAR|REX_64, tmp, 47);\n      emit_rr(as, XO_MOV, tmp|REX_64, dest);\n    }\n    return dest;\n  } else {\n    return RID_NONE;\n  }\n}\n#endif\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  lua_assert(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) ||\n\t     (LJ_DUALNUM && irt_isint(ir->t)));\n#if LJ_64\n  if (irt_islightud(ir->t)) {\n    Reg dest = asm_load_lightud64(as, ir, 1);\n    if (ra_hasreg(dest)) {\n      asm_fuseahuref(as, ir->op1, RSET_GPR);\n      emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM);\n    }\n    return;\n  } else\n#endif\n  if (ra_used(ir)) {\n    RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR;\n    Reg dest = ra_dest(as, ir, allow);\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n    emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XO_MOVSD, dest, RID_MRM);\n  } else {\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n  }\n  /* Always do the type check, even if the load result is unused. */\n  as->mrm.ofs += 4;\n  asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE);\n  if (LJ_64 && irt_type(ir->t) >= IRT_NUM) {\n    lua_assert(irt_isinteger(ir->t) || irt_isnum(ir->t));\n    emit_u32(as, LJ_TISNUM);\n    emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM);\n  } else {\n    emit_i8(as, irt_toitype(ir->t));\n    emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM);\n  }\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  if (ir->r == RID_SINK)\n    return;\n  if (irt_isnum(ir->t)) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_FPR);\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n    emit_mrm(as, XO_MOVSDto, src, RID_MRM);\n#if LJ_64\n  } else if (irt_islightud(ir->t)) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src));\n    emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM);\n#endif\n  } else {\n    IRIns *irr = IR(ir->op2);\n    RegSet allow = RSET_GPR;\n    Reg src = RID_NONE;\n    if (!irref_isk(ir->op2)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n    }\n    asm_fuseahuref(as, ir->op1, allow);\n    if (ra_hasreg(src)) {\n      emit_mrm(as, XO_MOVto, src, RID_MRM);\n    } else if (!irt_ispri(irr->t)) {\n      lua_assert(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t)));\n      emit_i32(as, irr->i);\n      emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n    }\n    as->mrm.ofs += 4;\n    emit_i32(as, (int32_t)irt_toitype(ir->t));\n    emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  IRType1 t = ir->t;\n  Reg base;\n  lua_assert(!(ir->op2 & IRSLOAD_PARENT));  /* Handled by asm_head_side(). */\n  lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));\n  lua_assert(LJ_DUALNUM ||\n\t     !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    Reg left = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, left);  /* Frees dest reg. Do this before base alloc. */\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n    emit_rmro(as, XO_MOVSD, left, base, ofs);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n#if LJ_64\n  } else if (irt_islightud(t)) {\n    Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK));\n    if (ra_hasreg(dest)) {\n      base = ra_alloc1(as, REF_BASE, RSET_GPR);\n      emit_rmro(as, XO_MOV, dest|REX_64, base, ofs);\n    }\n    return;\n#endif\n  } else if (ra_used(ir)) {\n    RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR;\n    Reg dest = ra_dest(as, ir, allow);\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n    lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));\n    if ((ir->op2 & IRSLOAD_CONVERT)) {\n      t.irt = irt_isint(t) ? IRT_NUM : IRT_INT;  /* Check for original type. */\n      emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTTSD2SI, dest, base, ofs);\n    } else {\n      emit_rmro(as, irt_isnum(t) ? XO_MOVSD : XO_MOV, dest, base, ofs);\n    }\n  } else {\n    if (!(ir->op2 & IRSLOAD_TYPECHECK))\n      return;  /* No type check: avoid base alloc. */\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  }\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    /* Need type check, even if the load result is unused. */\n    asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE);\n    if (LJ_64 && irt_type(t) >= IRT_NUM) {\n      lua_assert(irt_isinteger(t) || irt_isnum(t));\n      emit_u32(as, LJ_TISNUM);\n      emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4);\n    } else {\n      emit_i8(as, irt_toitype(t));\n      emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4);\n    }\n  }\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  lua_assert(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL));\n\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n#if LJ_64\n    Reg r64 = sz == 8 ? REX_64 : 0;\n    if (irref_isk(ir->op2)) {\n      IRIns *irk = IR(ir->op2);\n      uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 :\n\t\t\t\t\t (uint64_t)(uint32_t)irk->i;\n      if (sz == 4 || checki32((int64_t)k)) {\n\temit_i32(as, (int32_t)k);\n\temit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata));\n      } else {\n\temit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata));\n\temit_loadu64(as, RID_ECX, k);\n      }\n    } else {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata));\n    }\n#else\n    int32_t ofs = sizeof(GCcdata);\n    if (sz == 8) {\n      ofs += 4; ir++;\n      lua_assert(ir->o == IR_HIOP);\n    }\n    do {\n      if (irref_isk(ir->op2)) {\n\temit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i);\n      } else {\n\tReg r = ra_alloc1(as, ir->op2, allow);\n\temit_movtomro(as, r, RID_RET, ofs);\n\trset_clear(allow, r);\n      }\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir--;\n    } while (1);\n#endif\n    lua_assert(sz == 4 || sz == 8);\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Combine initialization of marked, gct and ctypeid. */\n  emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));\n  emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,\n\t   (int32_t)((~LJ_TCDATA<<8)+(id<<16)));\n  emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES);\n  emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite);\n\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata)));\n}\n#else\n#define asm_cnew(as, ir)\t((void)0)\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  MCLabel l_end = emit_label(as);\n  emit_movtomro(as, tmp, tab, offsetof(GCtab, gclist));\n  emit_setgl(as, tab, gc.grayagain);\n  emit_getgl(as, tmp, gc.grayagain);\n  emit_i8(as, ~LJ_GC_BLACK);\n  emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked));\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_BLACK);\n  emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj;\n  /* No need for other object barriers (yet). */\n  lua_assert(IR(ir->op1)->o == IR_UREFC);\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J));\n  obj = IR(ir->op1)->r;\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_WHITES);\n  if (irref_isk(ir->op2)) {\n    GCobj *vp = ir_kgc(IR(ir->op2));\n    emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked);\n  } else {\n    Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj));\n    emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked));\n  }\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_BLACK);\n  emit_rmro(as, XO_GROUP3b, XOg_TEST, obj,\n\t    (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n}\n\n/* -- FP/int arithmetic and logic operations ------------------------------ */\n\n/* Load reference onto x87 stack. Force a spill to memory if needed. */\nstatic void asm_x87load(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_KNUM) {\n    cTValue *tv = ir_knum(ir);\n    if (tvispzero(tv))  /* Use fldz only for +0. */\n      emit_x87op(as, XI_FLDZ);\n    else if (tvispone(tv))\n      emit_x87op(as, XI_FLD1);\n    else\n      emit_rma(as, XO_FLDq, XOg_FLDq, tv);\n  } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) &&\n\t     !irref_isk(ir->op1) && mayfuse(as, ir->op1)) {\n    IRIns *iri = IR(ir->op1);\n    emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri));\n  } else {\n    emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY));\n  }\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  IRFPMathOp fpm = (IRFPMathOp)ir->op2;\n  if (fpm == IRFPM_SQRT) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg left = asm_fuseload(as, ir->op1, RSET_FPR);\n    emit_mrm(as, XO_SQRTSD, dest, left);\n  } else if (fpm <= IRFPM_TRUNC) {\n    if (as->flags & JIT_F_SSE4_1) {  /* SSE4.1 has a rounding instruction. */\n      Reg dest = ra_dest(as, ir, RSET_FPR);\n      Reg left = asm_fuseload(as, ir->op1, RSET_FPR);\n      /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op.\n      ** Let's pretend it's a 3-byte opcode, and compensate afterwards.\n      ** This is atrocious, but the alternatives are much worse.\n      */\n      /* Round down/up/trunc == 1001/1010/1011. */\n      emit_i8(as, 0x09 + fpm);\n      emit_mrm(as, XO_ROUNDSD, dest, left);\n      if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) {\n\tas->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f;  /* Swap 0F and REX. */\n      }\n      *--as->mcp = 0x66;  /* 1st byte of ROUNDSD opcode. */\n    } else {  /* Call helper functions for SSE2 variant. */\n      /* The modified regs must match with the *.dasc implementation. */\n      RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);\n      if (ra_hasreg(ir->r))\n\trset_clear(drop, ir->r);  /* Dest reg handled below. */\n      ra_evictset(as, drop);\n      ra_destreg(as, ir, RID_XMM0);\n      emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse :\n\t\t    fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse);\n      ra_left(as, RID_XMM0, ir->op1);\n    }\n  } else if (fpm == IRFPM_EXP2 && asm_fpjoin_pow(as, ir)) {\n    /* Rejoined to pow(). */\n  } else {\n    asm_callid(as, ir, IRCALL_lj_vm_floor + fpm);\n  }\n}\n\n#define asm_atan2(as, ir)\tasm_callid(as, ir, IRCALL_atan2)\n\nstatic void asm_ldexp(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n    emit_rmro(as, XO_MOVSD, dest, RID_ESP, ofs);\n  }\n  emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs);\n  emit_x87op(as, XI_FPOP1);\n  emit_x87op(as, XI_FSCALE);\n  asm_x87load(as, ir->op1);\n  asm_x87load(as, ir->op2);\n}\n\nstatic void asm_fppowi(ASMState *as, IRIns *ir)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX);\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  ra_destreg(as, ir, RID_XMM0);\n  emit_call(as, lj_vm_powi_sse);\n  ra_left(as, RID_XMM0, ir->op1);\n  ra_left(as, RID_EAX, ir->op2);\n}\n\nstatic void asm_pow(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isnum(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :\n\t\t\t\t\t  IRCALL_lj_carith_powu64);\n  else\n#endif\n    asm_fppowi(as, ir);\n}\n\nstatic int asm_swapops(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  lua_assert(ra_noreg(irr->r));\n  if (!irm_iscomm(lj_ir_mode[ir->o]))\n    return 0;  /* Can't swap non-commutative operations. */\n  if (irref_isk(ir->op2))\n    return 0;  /* Don't swap constants to the left. */\n  if (ra_hasreg(irl->r))\n    return 1;  /* Swap if left already has a register. */\n  if (ra_samehint(ir->r, irr->r))\n    return 1;  /* Swap if dest and right have matching hints. */\n  if (as->curins > as->loopref) {  /* In variant part? */\n    if (ir->op2 < as->loopref && !irt_isphi(irr->t))\n      return 0;  /* Keep invariants on the right. */\n    if (ir->op1 < as->loopref && !irt_isphi(irl->t))\n      return 1;  /* Swap invariants to the right. */\n  }\n  if (opisfusableload(irl->o))\n    return 1;  /* Swap fusable loads to the right. */\n  return 0;  /* Otherwise don't swap. */\n}\n\nstatic void asm_fparith(ASMState *as, IRIns *ir, x86Op xo)\n{\n  IRRef lref = ir->op1;\n  IRRef rref = ir->op2;\n  RegSet allow = RSET_FPR;\n  Reg dest;\n  Reg right = IR(rref)->r;\n  if (ra_hasreg(right)) {\n    rset_clear(allow, right);\n    ra_noweak(as, right);\n  }\n  dest = ra_dest(as, ir, allow);\n  if (lref == rref) {\n    right = dest;\n  } else if (ra_noreg(right)) {\n    if (asm_swapops(as, ir)) {\n      IRRef tmp = lref; lref = rref; rref = tmp;\n    }\n    right = asm_fuseload(as, rref, rset_clear(allow, dest));\n  }\n  emit_mrm(as, xo, dest, right);\n  ra_left(as, dest, lref);\n}\n\nstatic void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa)\n{\n  IRRef lref = ir->op1;\n  IRRef rref = ir->op2;\n  RegSet allow = RSET_GPR;\n  Reg dest, right;\n  int32_t k = 0;\n  if (as->flagmcp == as->mcp) {  /* Drop test r,r instruction. */\n    MCode *p = as->mcp + ((LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2);\n    if ((p[1] & 15) < 14) {\n      if ((p[1] & 15) >= 12) p[1] -= 4;  /* L <->S, NL <-> NS */\n      as->flagmcp = NULL;\n      as->mcp = p;\n    }  /* else: cannot transform LE/NLE to cc without use of OF. */\n  }\n  right = IR(rref)->r;\n  if (ra_hasreg(right)) {\n    rset_clear(allow, right);\n    ra_noweak(as, right);\n  }\n  dest = ra_dest(as, ir, allow);\n  if (lref == rref) {\n    right = dest;\n  } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) {\n    if (asm_swapops(as, ir)) {\n      IRRef tmp = lref; lref = rref; rref = tmp;\n    }\n    right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t));\n  }\n  if (irt_isguard(ir->t))  /* For IR_ADDOV etc. */\n    asm_guardcc(as, CC_O);\n  if (xa != XOg_X_IMUL) {\n    if (ra_hasreg(right))\n      emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right);\n    else\n      emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k);\n  } else if (ra_hasreg(right)) {  /* IMUL r, mrm. */\n    emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right);\n  } else {  /* IMUL r, r, k. */\n    /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */\n    Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t));\n    x86Op xo;\n    if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8;\n    } else { emit_i32(as, k); xo = XO_IMULi; }\n    emit_mrm(as, xo, REX_64IR(ir, dest), left);\n    return;\n  }\n  ra_left(as, dest, lref);\n}\n\n/* LEA is really a 4-operand ADD with an independent destination register,\n** up to two source registers and an immediate. One register can be scaled\n** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several\n** instructions.\n**\n** Currently only a few common cases are supported:\n** - 3-operand ADD:    y = a+b; y = a+k   with a and b already allocated\n** - Left ADD fusion:  y = (a+b)+k; y = (a+k)+b\n** - Right ADD fusion: y = a+(b+k)\n** The ommited variants have already been reduced by FOLD.\n**\n** There are more fusion opportunities, like gathering shifts or joining\n** common references. But these are probably not worth the trouble, since\n** array indexing is not decomposed and already makes use of all fields\n** of the ModRM operand.\n*/\nstatic int asm_lea(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  RegSet allow = RSET_GPR;\n  Reg dest;\n  as->mrm.base = as->mrm.idx = RID_NONE;\n  as->mrm.scale = XM_SCALE1;\n  as->mrm.ofs = 0;\n  if (ra_hasreg(irl->r)) {\n    rset_clear(allow, irl->r);\n    ra_noweak(as, irl->r);\n    as->mrm.base = irl->r;\n    if (irref_isk(ir->op2) || ra_hasreg(irr->r)) {\n      /* The PHI renaming logic does a better job in some cases. */\n      if (ra_hasreg(ir->r) &&\n\t  ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) ||\n\t   (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2)))\n\treturn 0;\n      if (irref_isk(ir->op2)) {\n\tas->mrm.ofs = irr->i;\n      } else {\n\trset_clear(allow, irr->r);\n\tra_noweak(as, irr->r);\n\tas->mrm.idx = irr->r;\n      }\n    } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) &&\n\t       irref_isk(irr->op2)) {\n      Reg idx = ra_alloc1(as, irr->op1, allow);\n      rset_clear(allow, idx);\n      as->mrm.idx = (uint8_t)idx;\n      as->mrm.ofs = IR(irr->op2)->i;\n    } else {\n      return 0;\n    }\n  } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) &&\n\t     (irref_isk(ir->op2) || irref_isk(irl->op2))) {\n    Reg idx, base = ra_alloc1(as, irl->op1, allow);\n    rset_clear(allow, base);\n    as->mrm.base = (uint8_t)base;\n    if (irref_isk(ir->op2)) {\n      as->mrm.ofs = irr->i;\n      idx = ra_alloc1(as, irl->op2, allow);\n    } else {\n      as->mrm.ofs = IR(irl->op2)->i;\n      idx = ra_alloc1(as, ir->op2, allow);\n    }\n    rset_clear(allow, idx);\n    as->mrm.idx = (uint8_t)idx;\n  } else {\n    return 0;\n  }\n  dest = ra_dest(as, ir, allow);\n  emit_mrm(as, XO_LEA, dest, RID_MRM);\n  return 1;  /* Success. */\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_ADDSD);\n  else if ((as->flags & JIT_F_LEA_AGU) || as->flagmcp == as->mcp ||\n\t   irt_is64(ir->t) || !asm_lea(as, ir))\n    asm_intarith(as, ir, XOg_ADD);\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_SUBSD);\n  else  /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */\n    asm_intarith(as, ir, XOg_SUB);\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MULSD);\n  else\n    asm_intarith(as, ir, XOg_X_IMUL);\n}\n\nstatic void asm_div(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isnum(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :\n\t\t\t\t\t  IRCALL_lj_carith_divu64);\n  else\n#endif\n    asm_fparith(as, ir, XO_DIVSD);\n}\n\nstatic void asm_mod(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isint(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :\n\t\t\t\t\t  IRCALL_lj_carith_modu64);\n  else\n#endif\n    asm_callid(as, ir, IRCALL_lj_vm_modi);\n}\n\nstatic void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest);\n  ra_left(as, dest, ir->op1);\n}\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_XORPS);\n  else\n    asm_neg_not(as, ir, XOg_NEG);\n}\n\n#define asm_abs(as, ir)\t\tasm_fparith(as, ir, XO_ANDPS)\n\nstatic void asm_intmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  Reg right, dest = ra_dest(as, ir, RSET_GPR);\n  IRRef lref = ir->op1, rref = ir->op2;\n  if (irref_isk(rref)) { lref = rref; rref = ir->op1; }\n  right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest));\n  emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right);\n  emit_rr(as, XO_CMP, REX_64IR(ir, dest), right);\n  ra_left(as, dest, lref);\n}\n\nstatic void asm_min(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MINSD);\n  else\n    asm_intmin_max(as, ir, CC_G);\n}\n\nstatic void asm_max(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MAXSD);\n  else\n    asm_intmin_max(as, ir, CC_L);\n}\n\n/* Note: don't use LEA for overflow-checking arithmetic! */\n#define asm_addov(as, ir)\tasm_intarith(as, ir, XOg_ADD)\n#define asm_subov(as, ir)\tasm_intarith(as, ir, XOg_SUB)\n#define asm_mulov(as, ir)\tasm_intarith(as, ir, XOg_X_IMUL)\n\n#define asm_bnot(as, ir)\tasm_neg_not(as, ir, XOg_NOT)\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24),\n\t\t    REX_64IR(ir, 0), dest, 0, as->mcp, 1);\n  ra_left(as, dest, ir->op1);\n}\n\n#define asm_band(as, ir)\tasm_intarith(as, ir, XOg_AND)\n#define asm_bor(as, ir)\t\tasm_intarith(as, ir, XOg_OR)\n#define asm_bxor(as, ir)\tasm_intarith(as, ir, XOg_XOR)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs)\n{\n  IRRef rref = ir->op2;\n  IRIns *irr = IR(rref);\n  Reg dest;\n  if (irref_isk(rref)) {  /* Constant shifts. */\n    int shift;\n    dest = ra_dest(as, ir, RSET_GPR);\n    shift = irr->i & (irt_is64(ir->t) ? 63 : 31);\n    switch (shift) {\n    case 0: break;\n    case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break;\n    default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break;\n    }\n  } else {  /* Variable shifts implicitly use register cl (i.e. ecx). */\n    Reg right;\n    dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX));\n    if (dest == RID_ECX) {\n      dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX));\n      emit_rr(as, XO_MOV, RID_ECX, dest);\n    }\n    right = irr->r;\n    if (ra_noreg(right))\n      right = ra_allocref(as, rref, RID2RSET(RID_ECX));\n    else if (right != RID_ECX)\n      ra_scratch(as, RID2RSET(RID_ECX));\n    emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest);\n    ra_noweak(as, right);\n    if (right != RID_ECX)\n      emit_rr(as, XO_MOV, RID_ECX, right);\n  }\n  ra_left(as, dest, ir->op1);\n  /*\n  ** Note: avoid using the flags resulting from a shift or rotate!\n  ** All of them cause a partial flag stall, except for r,1 shifts\n  ** (but not rotates). And a shift count of 0 leaves the flags unmodified.\n  */\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, XOg_SHL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, XOg_SHR)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, XOg_SAR)\n#define asm_brol(as, ir)\tasm_bitshift(as, ir, XOg_ROL)\n#define asm_bror(as, ir)\tasm_bitshift(as, ir, XOg_ROR)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n/* Virtual flags for unordered FP comparisons. */\n#define VCC_U\t0x1000\t\t/* Unordered. */\n#define VCC_P\t0x2000\t\t/* Needs extra CC_P branch. */\n#define VCC_S\t0x4000\t\t/* Swap avoids CC_P branch. */\n#define VCC_PS\t(VCC_P|VCC_S)\n\n/* Map of comparisons to flags. ORDER IR. */\n#define COMPFLAGS(ci, cin, cu, cf)\t((ci)+((cu)<<4)+((cin)<<8)+(cf))\nstatic const uint16_t asm_compmap[IR_ABC+1] = {\n  /*                 signed non-eq unsigned flags */\n  /* LT  */ COMPFLAGS(CC_GE, CC_G,  CC_AE, VCC_PS),\n  /* GE  */ COMPFLAGS(CC_L,  CC_L,  CC_B,  0),\n  /* LE  */ COMPFLAGS(CC_G,  CC_G,  CC_A,  VCC_PS),\n  /* GT  */ COMPFLAGS(CC_LE, CC_L,  CC_BE, 0),\n  /* ULT */ COMPFLAGS(CC_AE, CC_A,  CC_AE, VCC_U),\n  /* UGE */ COMPFLAGS(CC_B,  CC_B,  CC_B,  VCC_U|VCC_PS),\n  /* ULE */ COMPFLAGS(CC_A,  CC_A,  CC_A,  VCC_U),\n  /* UGT */ COMPFLAGS(CC_BE, CC_B,  CC_BE, VCC_U|VCC_PS),\n  /* EQ  */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P),\n  /* NE  */ COMPFLAGS(CC_E,  CC_E,  CC_E,  VCC_U|VCC_P),\n  /* ABC */ COMPFLAGS(CC_BE, CC_B,  CC_BE, VCC_U|VCC_PS)  /* Same as UGT. */\n};\n\n/* FP and integer comparisons. */\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  uint32_t cc = asm_compmap[ir->o];\n  if (irt_isnum(ir->t)) {\n    IRRef lref = ir->op1;\n    IRRef rref = ir->op2;\n    Reg left, right;\n    MCLabel l_around;\n    /*\n    ** An extra CC_P branch is required to preserve ordered/unordered\n    ** semantics for FP comparisons. This can be avoided by swapping\n    ** the operands and inverting the condition (except for EQ and UNE).\n    ** So always try to swap if possible.\n    **\n    ** Another option would be to swap operands to achieve better memory\n    ** operand fusion. But it's unlikely that this outweighs the cost\n    ** of the extra branches.\n    */\n    if (cc & VCC_S) {  /* Swap? */\n      IRRef tmp = lref; lref = rref; rref = tmp;\n      cc ^= (VCC_PS|(5<<4));  /* A <-> B, AE <-> BE, PS <-> none */\n    }\n    left = ra_alloc1(as, lref, RSET_FPR);\n    right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left));\n    l_around = emit_label(as);\n    asm_guardcc(as, cc >> 4);\n    if (cc & VCC_P) {  /* Extra CC_P branch required? */\n      if (!(cc & VCC_U)) {\n\tasm_guardcc(as, CC_P);  /* Branch to exit for ordered comparisons. */\n      } else if (l_around != as->invmcp) {\n\temit_sjcc(as, CC_P, l_around);  /* Branch around for unordered. */\n      } else {\n\t/* Patched to mcloop by asm_loop_fixup. */\n\tas->loopinv = 2;\n\tif (as->realign)\n\t  emit_sjcc(as, CC_P, as->mcp);\n\telse\n\t  emit_jcc(as, CC_P, as->mcp);\n      }\n    }\n    emit_mrm(as, XO_UCOMISD, left, right);\n  } else {\n    IRRef lref = ir->op1, rref = ir->op2;\n    IROp leftop = (IROp)(IR(lref)->o);\n    Reg r64 = REX_64IR(ir, 0);\n    int32_t imm = 0;\n    lua_assert(irt_is64(ir->t) || irt_isint(ir->t) ||\n\t       irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t));\n    /* Swap constants (only for ABC) and fusable loads to the right. */\n    if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) {\n      if ((cc & 0xc) == 0xc) cc ^= 0x53;  /* L <-> G, LE <-> GE */\n      else if ((cc & 0xa) == 0x2) cc ^= 0x55;  /* A <-> B, AE <-> BE */\n      lref = ir->op2; rref = ir->op1;\n    }\n    if (asm_isk32(as, rref, &imm)) {\n      IRIns *irl = IR(lref);\n      /* Check wether we can use test ins. Not for unsigned, since CF=0. */\n      int usetest = (imm == 0 && (cc & 0xa) != 0x2);\n      if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) {\n\t/* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */\n\tReg right, left = RID_NONE;\n\tRegSet allow = RSET_GPR;\n\tif (!asm_isk32(as, irl->op2, &imm)) {\n\t  left = ra_alloc1(as, irl->op2, allow);\n\t  rset_clear(allow, left);\n\t} else {  /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */\n\t  IRIns *irll = IR(irl->op1);\n\t  if (opisfusableload((IROp)irll->o) &&\n\t      (irt_isi8(irll->t) || irt_isu8(irll->t))) {\n\t    IRType1 origt = irll->t;  /* Temporarily flip types. */\n\t    irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT;\n\t    as->curins--;  /* Skip to BAND to avoid failing in noconflict(). */\n\t    right = asm_fuseload(as, irl->op1, RSET_GPR);\n\t    as->curins++;\n\t    irll->t = origt;\n\t    if (right != RID_MRM) goto test_nofuse;\n\t    /* Fusion succeeded, emit test byte mrm, imm8. */\n\t    asm_guardcc(as, cc);\n\t    emit_i8(as, (imm & 0xff));\n\t    emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM);\n\t    return;\n\t  }\n\t}\n\tas->curins--;  /* Skip to BAND to avoid failing in noconflict(). */\n\tright = asm_fuseloadm(as, irl->op1, allow, r64);\n\tas->curins++;  /* Undo the above. */\n      test_nofuse:\n\tasm_guardcc(as, cc);\n\tif (ra_noreg(left)) {\n\t  emit_i32(as, imm);\n\t  emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right);\n\t} else {\n\t  emit_mrm(as, XO_TEST, r64 + left, right);\n\t}\n      } else {\n\tReg left;\n\tif (opisfusableload((IROp)irl->o) &&\n\t    ((irt_isu8(irl->t) && checku8(imm)) ||\n\t     ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) ||\n\t     (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) {\n\t  /* Only the IRT_INT case is fused by asm_fuseload.\n\t  ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads\n\t  ** are handled here.\n\t  ** Note that cmp word [mem], imm16 should not be generated,\n\t  ** since it has a length-changing prefix. Compares of a word\n\t  ** against a sign-extended imm8 are ok, however.\n\t  */\n\t  IRType1 origt = irl->t;  /* Temporarily flip types. */\n\t  irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT;\n\t  left = asm_fuseload(as, lref, RSET_GPR);\n\t  irl->t = origt;\n\t  if (left == RID_MRM) {  /* Fusion succeeded? */\n\t    if (irt_isu8(irl->t) || irt_isu16(irl->t))\n\t      cc >>= 4;  /* Need unsigned compare. */\n\t    asm_guardcc(as, cc);\n\t    emit_i8(as, imm);\n\t    emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ?\n\t\t\t XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM);\n\t    return;\n\t  }  /* Otherwise handle register case as usual. */\n\t} else {\n\t  left = asm_fuseloadm(as, lref,\n\t\t\t       irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64);\n\t}\n\tasm_guardcc(as, cc);\n\tif (usetest && left != RID_MRM) {\n\t  /* Use test r,r instead of cmp r,0. */\n\t  x86Op xo = XO_TEST;\n\t  if (irt_isu8(ir->t)) {\n\t    lua_assert(ir->o == IR_EQ || ir->o == IR_NE);\n\t    xo = XO_TESTb;\n\t    if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) {\n\t      if (LJ_64) {\n\t\tleft |= FORCE_REX;\n\t      } else {\n\t\temit_i32(as, 0xff);\n\t\temit_mrm(as, XO_GROUP3, XOg_TEST, left);\n\t\treturn;\n\t      }\n\t    }\n\t  }\n\t  emit_rr(as, xo, r64 + left, left);\n\t  if (irl+1 == ir)  /* Referencing previous ins? */\n\t    as->flagmcp = as->mcp;  /* Set flag to drop test r,r if possible. */\n\t} else {\n\t  emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm);\n\t}\n      }\n    } else {\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64);\n      asm_guardcc(as, cc);\n      emit_mrm(as, XO_CMP, r64 + left, right);\n    }\n  }\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_32 && LJ_HASFFI\n/* 64 bit integer comparisons in 32 bit mode. */\nstatic void asm_comp_int64(ASMState *as, IRIns *ir)\n{\n  uint32_t cc = asm_compmap[(ir-1)->o];\n  RegSet allow = RSET_GPR;\n  Reg lefthi = RID_NONE, leftlo = RID_NONE;\n  Reg righthi = RID_NONE, rightlo = RID_NONE;\n  MCLabel l_around;\n  x86ModRM mrm;\n\n  as->curins--;  /* Skip loword ins. Avoids failing in noconflict(), too. */\n\n  /* Allocate/fuse hiword operands. */\n  if (irref_isk(ir->op2)) {\n    lefthi = asm_fuseload(as, ir->op1, allow);\n  } else {\n    lefthi = ra_alloc1(as, ir->op1, allow);\n    rset_clear(allow, lefthi);\n    righthi = asm_fuseload(as, ir->op2, allow);\n    if (righthi == RID_MRM) {\n      if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base);\n      if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx);\n    } else {\n      rset_clear(allow, righthi);\n    }\n  }\n  mrm = as->mrm;  /* Save state for hiword instruction. */\n\n  /* Allocate/fuse loword operands. */\n  if (irref_isk((ir-1)->op2)) {\n    leftlo = asm_fuseload(as, (ir-1)->op1, allow);\n  } else {\n    leftlo = ra_alloc1(as, (ir-1)->op1, allow);\n    rset_clear(allow, leftlo);\n    rightlo = asm_fuseload(as, (ir-1)->op2, allow);\n  }\n\n  /* All register allocations must be performed _before_ this point. */\n  l_around = emit_label(as);\n  as->invmcp = as->flagmcp = NULL;  /* Cannot use these optimizations. */\n\n  /* Loword comparison and branch. */\n  asm_guardcc(as, cc >> 4);  /* Always use unsigned compare for loword. */\n  if (ra_noreg(rightlo)) {\n    int32_t imm = IR((ir-1)->op2)->i;\n    if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM)\n      emit_rr(as, XO_TEST, leftlo, leftlo);\n    else\n      emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm);\n  } else {\n    emit_mrm(as, XO_CMP, leftlo, rightlo);\n  }\n\n  /* Hiword comparison and branches. */\n  if ((cc & 15) != CC_NE)\n    emit_sjcc(as, CC_NE, l_around);  /* Hiword unequal: skip loword compare. */\n  if ((cc & 15) != CC_E)\n    asm_guardcc(as, cc >> 8);  /* Hiword compare without equality check. */\n  as->mrm = mrm;  /* Restore state. */\n  if (ra_noreg(righthi)) {\n    int32_t imm = IR(ir->op2)->i;\n    if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM)\n      emit_rr(as, XO_TEST, lefthi, lefthi);\n    else\n      emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm);\n  } else {\n    emit_mrm(as, XO_CMP, lefthi, righthi);\n  }\n}\n#endif\n\n/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */\n\n/* Hiword op of a split 64 bit op. Previous op must be the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n#if LJ_32 && LJ_HASFFI\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    asm_comp_int64(as, ir);\n    return;\n  } else if ((ir-1)->o == IR_XSTORE) {\n    if ((ir-1)->r != RID_SINK)\n      asm_fxstore(as, ir);\n    return;\n  }\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n  case IR_ADD:\n    as->flagmcp = NULL;\n    as->curins--;\n    asm_intarith(as, ir, XOg_ADC);\n    asm_intarith(as, ir-1, XOg_ADD);\n    break;\n  case IR_SUB:\n    as->flagmcp = NULL;\n    as->curins--;\n    asm_intarith(as, ir, XOg_SBB);\n    asm_intarith(as, ir-1, XOg_SUB);\n    break;\n  case IR_NEG: {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    emit_rr(as, XO_GROUP3, XOg_NEG, dest);\n    emit_i8(as, 0);\n    emit_rr(as, XO_ARITHi8, XOg_ADC, dest);\n    ra_left(as, dest, ir->op1);\n    as->curins--;\n    asm_neg_not(as, ir-1, XOg_NEG);\n    break;\n    }\n  case IR_CALLN:\n  case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by CNEWI itself. */\n    break;\n  default: lua_assert(0); break;\n  }\n#else\n  UNUSED(as); UNUSED(ir); lua_assert(0);  /* Unused on x64 or without FFI. */\n#endif\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_i8(as, HOOK_PROFILE);\n  emit_rma(as, XO_GROUP3b, XOg_TEST, &J2G(as->J)->hookmask);\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore eax. */\n  Reg pbase = irp ? irp->r : RID_BASE;\n  Reg r = allow ? rset_pickbot(allow) : RID_EAX;\n  emit_jcc(as, CC_B, exitstub_addr(as->J, exitno));\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0);\n  else\n    ra_modified(as, r);\n  emit_gri(as, XG_ARITHi(XOg_CMP), r, (int32_t)(8*topslot));\n  if (ra_hasreg(pbase) && pbase != r)\n    emit_rr(as, XO_ARITH(XOg_SUB), r, pbase);\n  else\n    emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE,\n\t      ptr2addr(&J2G(as->J)->jit_base));\n  emit_rmro(as, XO_MOV, r, r, offsetof(lua_State, maxstack));\n  emit_getgl(as, r, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs);\n    } else {\n      lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) ||\n\t\t (LJ_DUALNUM && irt_isinteger(ir->t)));\n      if (!irref_isk(ref)) {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));\n\temit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs);\n      } else if (!irt_ispri(ir->t)) {\n\temit_movmroi(as, RID_BASE, ofs, ir->i);\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s != 0)  /* Do not overwrite link to previous frame. */\n\t  emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--));\n      } else {\n\tif (!(LJ_64 && irt_islightud(ir->t)))\n\t  emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t));\n      }\n    }\n    checkmclim(as);\n  }\n  lua_assert(map + nent == flinks);\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  emit_rr(as, XO_TEST, RID_RET, RID_RET);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  tmp = ra_releasetmp(as, ASMREF_TMP1);\n  emit_loada(as, tmp, J2G(as->J));\n  emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_sjcc(as, CC_B, l_end);\n  emit_opgl(as, XO_ARITH(XOg_CMP), tmp, gc.threshold);\n  emit_getgl(as, tmp, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->realign) {  /* Realigned loops use short jumps. */\n    as->realign = NULL;  /* Stop another retry. */\n    lua_assert(((intptr_t)target & 15) == 0);\n    if (as->loopinv) {  /* Inverted loop branch? */\n      p -= 5;\n      p[0] = XI_JMP;\n      lua_assert(target - p >= -128);\n      p[-1] = (MCode)(target - p);  /* Patch sjcc. */\n      if (as->loopinv == 2)\n\tp[-3] = (MCode)(target - p + 2);  /* Patch opt. short jp. */\n    } else {\n      lua_assert(target - p >= -128);\n      p[-1] = (MCode)(int8_t)(target - p);  /* Patch short jmp. */\n      p[-2] = XI_JMPs;\n    }\n  } else {\n    MCode *newloop;\n    p[-5] = XI_JMP;\n    if (as->loopinv) {  /* Inverted loop branch? */\n      /* asm_guardcc already inverted the jcc and patched the jmp. */\n      p -= 5;\n      newloop = target+4;\n      *(int32_t *)(p-4) = (int32_t)(target - p);  /* Patch jcc. */\n      if (as->loopinv == 2) {\n\t*(int32_t *)(p-10) = (int32_t)(target - p + 6);  /* Patch opt. jp. */\n\tnewloop = target+8;\n      }\n    } else {  /* Otherwise just patch jmp. */\n      *(int32_t *)(p-4) = (int32_t)(target - p);\n      newloop = target+3;\n    }\n    /* Realign small loops and shorten the loop branch. */\n    if (newloop >= p - 128) {\n      as->realign = newloop;  /* Force a retry and remember alignment. */\n      as->curins = as->stopins;  /* Abort asm_trace now. */\n      as->T->nins = as->orignins;  /* Remove any added renames. */\n    }\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_rr(as, XO_MOV, r, RID_BASE);\n  }\n}\n\n/* Coalesce or reload BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      rset_clear(allow, irp->r);\n      emit_rr(as, XO_MOV, r, irp->r);  /* Move from coalesced parent reg. */\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */\n  MCode *p = as->mctop;\n  MCode *target, *q;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    p -= ((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0);\n  } else {\n    MCode *p1;\n    /* Patch stack adjustment. */\n    if (checki8(spadj)) {\n      p -= 3;\n      p1 = p-6;\n      *p1 = (MCode)spadj;\n    } else {\n      p1 = p-9;\n      *(int32_t *)p1 = spadj;\n    }\n    if ((as->flags & JIT_F_LEA_AGU)) {\n#if LJ_64\n      p1[-4] = 0x48;\n#endif\n      p1[-3] = (MCode)XI_LEA;\n      p1[-2] = MODRM(checki8(spadj) ? XM_OFS8 : XM_OFS32, RID_ESP, RID_ESP);\n      p1[-1] = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n    } else {\n#if LJ_64\n      p1[-3] = 0x48;\n#endif\n      p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi);\n      p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP);\n    }\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  *(int32_t *)(p-4) = jmprel(p, target);\n  p[-5] = XI_JMP;\n  /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */\n  for (q = as->mctop-1; q >= p; q--)\n    *q = XI_NOP;\n  as->mctop = p;\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop;\n  /* Realign and leave room for backwards loop branch or exit branch. */\n  if (as->realign) {\n    int i = ((int)(intptr_t)as->realign) & 15;\n    /* Fill unused mcode tail with NOPs to make the prefetcher happy. */\n    while (i-- > 0)\n      *--p = XI_NOP;\n    as->mctop = p;\n    p -= (as->loopinv ? 5 : 2);  /* Space for short/near jmp. */\n  } else {\n    p -= 5;  /* Space for exit branch (near jmp). */\n  }\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */\n    as->mcp = p - (((as->flags & JIT_F_LEA_AGU) ? 7 : 6)  + (LJ_64 ? 1 : 0));\n    as->invmcp = NULL;\n  }\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  int nslots;\n  asm_collectargs(as, ir, ci, args);\n  nslots = asm_count_call_slots(as, ci, args);\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n#if LJ_64\n  return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);\n#else\n  return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET);\n#endif\n}\n\n/* Target-specific setup. */\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_exitstub_setup(as, as->T->nsnap);\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MSize len = T->szmcode;\n  MCode *px = exitstub_addr(J, exitno) - 6;\n  MCode *pe = p+len-6;\n  uint32_t stateaddr = u32ptr(&J2G(J)->vmstate);\n  if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px)\n    *(int32_t *)(p+len-4) = jmprel(p+len, target);\n  /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */\n  for (; p < pe; p++)\n    if (*(uint32_t *)(p+(LJ_64 ? 3 : 2)) == stateaddr && p[0] == XI_MOVmi) {\n      p += LJ_64 ? 11 : 10;\n      break;\n    }\n  lua_assert(p < pe);\n  for (; p < pe; p++) {\n    if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px) {\n      *(int32_t *)(p+2) = jmprel(p+6, target);\n      p += 5;\n    }\n  }\n  lj_mcode_sync(T->mcode, T->mcode + T->szmcode);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_bc.c",
    "content": "/*\n** Bytecode instruction modes.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bc_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n\n/* Bytecode offsets and bytecode instruction modes. */\n#include \"lj_bcdef.h\"\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_bc.h",
    "content": "/*\n** Bytecode instruction format.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BC_H\n#define _LJ_BC_H\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit:\n**\n** +----+----+----+----+\n** | B  | C  | A  | OP | Format ABC\n** +----+----+----+----+\n** |    D    | A  | OP | Format AD\n** +--------------------\n** MSB               LSB\n**\n** In-memory instructions are always stored in host byte order.\n*/\n\n/* Operand ranges and related constants. */\n#define BCMAX_A\t\t0xff\n#define BCMAX_B\t\t0xff\n#define BCMAX_C\t\t0xff\n#define BCMAX_D\t\t0xffff\n#define BCBIAS_J\t0x8000\n#define NO_REG\t\tBCMAX_A\n#define NO_JMP\t\t(~(BCPos)0)\n\n/* Macros to get instruction fields. */\n#define bc_op(i)\t((BCOp)((i)&0xff))\n#define bc_a(i)\t\t((BCReg)(((i)>>8)&0xff))\n#define bc_b(i)\t\t((BCReg)((i)>>24))\n#define bc_c(i)\t\t((BCReg)(((i)>>16)&0xff))\n#define bc_d(i)\t\t((BCReg)((i)>>16))\n#define bc_j(i)\t\t((ptrdiff_t)bc_d(i)-BCBIAS_J)\n\n/* Macros to set instruction fields. */\n#define setbc_byte(p, x, ofs) \\\n  ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x)\n#define setbc_op(p, x)\tsetbc_byte(p, (x), 0)\n#define setbc_a(p, x)\tsetbc_byte(p, (x), 1)\n#define setbc_b(p, x)\tsetbc_byte(p, (x), 3)\n#define setbc_c(p, x)\tsetbc_byte(p, (x), 2)\n#define setbc_d(p, x) \\\n  ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x)\n#define setbc_j(p, x)\tsetbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J))\n\n/* Macros to compose instructions. */\n#define BCINS_ABC(o, a, b, c) \\\n  (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16))\n#define BCINS_AD(o, a, d) \\\n  (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16))\n#define BCINS_AJ(o, a, j)\tBCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J))\n\n/* Bytecode instruction definition. Order matters, see below.\n**\n** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod)\n**\n** The opcode name suffixes specify the type for RB/RC or RD:\n** V = variable slot\n** S = string const\n** N = number const\n** P = primitive type (~itype)\n** B = unsigned byte literal\n** M = multiple args/results\n*/\n#define BCDEF(_) \\\n  /* Comparison ops. ORDER OPR. */ \\\n  _(ISLT,\tvar,\t___,\tvar,\tlt) \\\n  _(ISGE,\tvar,\t___,\tvar,\tlt) \\\n  _(ISLE,\tvar,\t___,\tvar,\tle) \\\n  _(ISGT,\tvar,\t___,\tvar,\tle) \\\n  \\\n  _(ISEQV,\tvar,\t___,\tvar,\teq) \\\n  _(ISNEV,\tvar,\t___,\tvar,\teq) \\\n  _(ISEQS,\tvar,\t___,\tstr,\teq) \\\n  _(ISNES,\tvar,\t___,\tstr,\teq) \\\n  _(ISEQN,\tvar,\t___,\tnum,\teq) \\\n  _(ISNEN,\tvar,\t___,\tnum,\teq) \\\n  _(ISEQP,\tvar,\t___,\tpri,\teq) \\\n  _(ISNEP,\tvar,\t___,\tpri,\teq) \\\n  \\\n  /* Unary test and copy ops. */ \\\n  _(ISTC,\tdst,\t___,\tvar,\t___) \\\n  _(ISFC,\tdst,\t___,\tvar,\t___) \\\n  _(IST,\t___,\t___,\tvar,\t___) \\\n  _(ISF,\t___,\t___,\tvar,\t___) \\\n  _(ISTYPE,\tvar,\t___,\tlit,\t___) \\\n  _(ISNUM,\tvar,\t___,\tlit,\t___) \\\n  \\\n  /* Unary ops. */ \\\n  _(MOV,\tdst,\t___,\tvar,\t___) \\\n  _(NOT,\tdst,\t___,\tvar,\t___) \\\n  _(UNM,\tdst,\t___,\tvar,\tunm) \\\n  _(LEN,\tdst,\t___,\tvar,\tlen) \\\n  \\\n  /* Binary ops. ORDER OPR. VV last, POW must be next. */ \\\n  _(ADDVN,\tdst,\tvar,\tnum,\tadd) \\\n  _(SUBVN,\tdst,\tvar,\tnum,\tsub) \\\n  _(MULVN,\tdst,\tvar,\tnum,\tmul) \\\n  _(DIVVN,\tdst,\tvar,\tnum,\tdiv) \\\n  _(MODVN,\tdst,\tvar,\tnum,\tmod) \\\n  \\\n  _(ADDNV,\tdst,\tvar,\tnum,\tadd) \\\n  _(SUBNV,\tdst,\tvar,\tnum,\tsub) \\\n  _(MULNV,\tdst,\tvar,\tnum,\tmul) \\\n  _(DIVNV,\tdst,\tvar,\tnum,\tdiv) \\\n  _(MODNV,\tdst,\tvar,\tnum,\tmod) \\\n  \\\n  _(ADDVV,\tdst,\tvar,\tvar,\tadd) \\\n  _(SUBVV,\tdst,\tvar,\tvar,\tsub) \\\n  _(MULVV,\tdst,\tvar,\tvar,\tmul) \\\n  _(DIVVV,\tdst,\tvar,\tvar,\tdiv) \\\n  _(MODVV,\tdst,\tvar,\tvar,\tmod) \\\n  \\\n  _(POW,\tdst,\tvar,\tvar,\tpow) \\\n  _(CAT,\tdst,\trbase,\trbase,\tconcat) \\\n  \\\n  /* Constant ops. */ \\\n  _(KSTR,\tdst,\t___,\tstr,\t___) \\\n  _(KCDATA,\tdst,\t___,\tcdata,\t___) \\\n  _(KSHORT,\tdst,\t___,\tlits,\t___) \\\n  _(KNUM,\tdst,\t___,\tnum,\t___) \\\n  _(KPRI,\tdst,\t___,\tpri,\t___) \\\n  _(KNIL,\tbase,\t___,\tbase,\t___) \\\n  \\\n  /* Upvalue and function ops. */ \\\n  _(UGET,\tdst,\t___,\tuv,\t___) \\\n  _(USETV,\tuv,\t___,\tvar,\t___) \\\n  _(USETS,\tuv,\t___,\tstr,\t___) \\\n  _(USETN,\tuv,\t___,\tnum,\t___) \\\n  _(USETP,\tuv,\t___,\tpri,\t___) \\\n  _(UCLO,\trbase,\t___,\tjump,\t___) \\\n  _(FNEW,\tdst,\t___,\tfunc,\tgc) \\\n  \\\n  /* Table ops. */ \\\n  _(TNEW,\tdst,\t___,\tlit,\tgc) \\\n  _(TDUP,\tdst,\t___,\ttab,\tgc) \\\n  _(GGET,\tdst,\t___,\tstr,\tindex) \\\n  _(GSET,\tvar,\t___,\tstr,\tnewindex) \\\n  _(TGETV,\tdst,\tvar,\tvar,\tindex) \\\n  _(TGETS,\tdst,\tvar,\tstr,\tindex) \\\n  _(TGETB,\tdst,\tvar,\tlit,\tindex) \\\n  _(TGETR,\tdst,\tvar,\tvar,\tindex) \\\n  _(TSETV,\tvar,\tvar,\tvar,\tnewindex) \\\n  _(TSETS,\tvar,\tvar,\tstr,\tnewindex) \\\n  _(TSETB,\tvar,\tvar,\tlit,\tnewindex) \\\n  _(TSETM,\tbase,\t___,\tnum,\tnewindex) \\\n  _(TSETR,\tvar,\tvar,\tvar,\tnewindex) \\\n  \\\n  /* Calls and vararg handling. T = tail call. */ \\\n  _(CALLM,\tbase,\tlit,\tlit,\tcall) \\\n  _(CALL,\tbase,\tlit,\tlit,\tcall) \\\n  _(CALLMT,\tbase,\t___,\tlit,\tcall) \\\n  _(CALLT,\tbase,\t___,\tlit,\tcall) \\\n  _(ITERC,\tbase,\tlit,\tlit,\tcall) \\\n  _(ITERN,\tbase,\tlit,\tlit,\tcall) \\\n  _(VARG,\tbase,\tlit,\tlit,\t___) \\\n  _(ISNEXT,\tbase,\t___,\tjump,\t___) \\\n  \\\n  /* Returns. */ \\\n  _(RETM,\tbase,\t___,\tlit,\t___) \\\n  _(RET,\trbase,\t___,\tlit,\t___) \\\n  _(RET0,\trbase,\t___,\tlit,\t___) \\\n  _(RET1,\trbase,\t___,\tlit,\t___) \\\n  \\\n  /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \\\n  _(FORI,\tbase,\t___,\tjump,\t___) \\\n  _(JFORI,\tbase,\t___,\tjump,\t___) \\\n  \\\n  _(FORL,\tbase,\t___,\tjump,\t___) \\\n  _(IFORL,\tbase,\t___,\tjump,\t___) \\\n  _(JFORL,\tbase,\t___,\tlit,\t___) \\\n  \\\n  _(ITERL,\tbase,\t___,\tjump,\t___) \\\n  _(IITERL,\tbase,\t___,\tjump,\t___) \\\n  _(JITERL,\tbase,\t___,\tlit,\t___) \\\n  \\\n  _(LOOP,\trbase,\t___,\tjump,\t___) \\\n  _(ILOOP,\trbase,\t___,\tjump,\t___) \\\n  _(JLOOP,\trbase,\t___,\tlit,\t___) \\\n  \\\n  _(JMP,\trbase,\t___,\tjump,\t___) \\\n  \\\n  /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \\\n  _(FUNCF,\trbase,\t___,\t___,\t___) \\\n  _(IFUNCF,\trbase,\t___,\t___,\t___) \\\n  _(JFUNCF,\trbase,\t___,\tlit,\t___) \\\n  _(FUNCV,\trbase,\t___,\t___,\t___) \\\n  _(IFUNCV,\trbase,\t___,\t___,\t___) \\\n  _(JFUNCV,\trbase,\t___,\tlit,\t___) \\\n  _(FUNCC,\trbase,\t___,\t___,\t___) \\\n  _(FUNCCW,\trbase,\t___,\t___,\t___)\n\n/* Bytecode opcode numbers. */\ntypedef enum {\n#define BCENUM(name, ma, mb, mc, mt)\tBC_##name,\nBCDEF(BCENUM)\n#undef BCENUM\n  BC__MAX\n} BCOp;\n\nLJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV);\nLJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV);\nLJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES);\nLJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN);\nLJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP);\nLJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE);\nLJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT);\nLJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT);\nLJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC);\nLJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM);\nLJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT);\nLJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET);\nLJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL);\nLJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL);\nLJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL);\nLJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL);\nLJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP);\nLJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP);\nLJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF);\nLJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF);\nLJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);\nLJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);\n\n/* This solves a circular dependency problem, change as needed. */\n#define FF_next_N\t4\n\n/* Stack slots used by FORI/FORL, relative to operand A. */\nenum {\n  FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT\n};\n\n/* Bytecode operand modes. ORDER BCMode */\ntypedef enum {\n  BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv,  /* Mode A must be <= 7 */\n  BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata,\n  BCM_max\n} BCMode;\n#define BCM___\t\tBCMnone\n\n#define bcmode_a(op)\t((BCMode)(lj_bc_mode[op] & 7))\n#define bcmode_b(op)\t((BCMode)((lj_bc_mode[op]>>3) & 15))\n#define bcmode_c(op)\t((BCMode)((lj_bc_mode[op]>>7) & 15))\n#define bcmode_d(op)\tbcmode_c(op)\n#define bcmode_hasd(op)\t((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3))\n#define bcmode_mm(op)\t((MMS)(lj_bc_mode[op]>>11))\n\n#define BCMODE(name, ma, mb, mc, mm) \\\n  (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)),\n#define BCMODE_FF\t0\n\nstatic LJ_AINLINE int bc_isret(BCOp op)\n{\n  return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1);\n}\n\nLJ_DATA const uint16_t lj_bc_mode[];\nLJ_DATA const uint16_t lj_bc_ofs[];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_bcdump.h",
    "content": "/*\n** Bytecode dump definitions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BCDUMP_H\n#define _LJ_BCDUMP_H\n\n#include \"lj_obj.h\"\n#include \"lj_lex.h\"\n\n/* -- Bytecode dump format ------------------------------------------------ */\n\n/*\n** dump   = header proto+ 0U\n** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]\n** proto  = lengthU pdata\n** pdata  = phead bcinsW* uvdataH* kgc* knum* [debugB*]\n** phead  = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU\n**          [debuglenU [firstlineU numlineU]]\n** kgc    = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }\n** knum   = intU0 | (loU1 hiU)\n** ktab   = narrayU nhashU karray* khash*\n** karray = ktabk\n** khash  = ktabk ktabk\n** ktabk  = ktabtypeU { intU | (loU hiU) | strB* }\n**\n** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1\n*/\n\n/* Bytecode dump header. */\n#define BCDUMP_HEAD1\t\t0x1b\n#define BCDUMP_HEAD2\t\t0x4c\n#define BCDUMP_HEAD3\t\t0x4a\n\n/* If you perform *any* kind of private modifications to the bytecode itself\n** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.\n*/\n#define BCDUMP_VERSION\t\t2\n\n/* Compatibility flags. */\n#define BCDUMP_F_BE\t\t0x01\n#define BCDUMP_F_STRIP\t\t0x02\n#define BCDUMP_F_FFI\t\t0x04\n#define BCDUMP_F_FR2\t\t0x08\n\n#define BCDUMP_F_KNOWN\t\t(BCDUMP_F_FR2*2-1)\n\n/* Type codes for the GC constants of a prototype. Plus length for strings. */\nenum {\n  BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,\n  BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR\n};\n\n/* Type codes for the keys/values of a constant table. */\nenum {\n  BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,\n  BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR\n};\n\n/* -- Bytecode reader/writer ---------------------------------------------- */\n\nLJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,\n\t\t       void *data, int strip);\nLJ_FUNC GCproto *lj_bcread_proto(LexState *ls);\nLJ_FUNC GCproto *lj_bcread(LexState *ls);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_bcread.c",
    "content": "/*\n** Bytecode reader.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bcread_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lualib.h\"\n#endif\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_state.h\"\n#include \"lj_strfmt.h\"\n\n/* Reuse some lexer fields for our own purposes. */\n#define bcread_flags(ls)\tls->level\n#define bcread_swap(ls) \\\n  ((bcread_flags(ls) & BCDUMP_F_BE) != LJ_BE*BCDUMP_F_BE)\n#define bcread_oldtop(L, ls)\trestorestack(L, ls->lastline)\n#define bcread_savetop(L, ls, top) \\\n  ls->lastline = (BCLine)savestack(L, (top))\n\n/* -- Input buffer handling ----------------------------------------------- */\n\n/* Throw reader error. */\nstatic LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em)\n{\n  lua_State *L = ls->L;\n  const char *name = ls->chunkarg;\n  if (*name == BCDUMP_HEAD1) name = \"(binary)\";\n  else if (*name == '@' || *name == '=') name++;\n  lj_strfmt_pushf(L, \"%s: %s\", name, err2msg(em));\n  lj_err_throw(L, LUA_ERRSYNTAX);\n}\n\n/* Refill buffer. */\nstatic LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need)\n{\n  lua_assert(len != 0);\n  if (len > LJ_MAX_BUF || ls->c < 0)\n    bcread_error(ls, LJ_ERR_BCBAD);\n  do {\n    const char *buf;\n    size_t sz;\n    char *p = sbufB(&ls->sb);\n    MSize n = (MSize)(ls->pe - ls->p);\n    if (n) {  /* Copy remainder to buffer. */\n      if (sbuflen(&ls->sb)) {  /* Move down in buffer. */\n\tlua_assert(ls->pe == sbufP(&ls->sb));\n\tif (ls->p != p) memmove(p, ls->p, n);\n      } else {  /* Copy from buffer provided by reader. */\n\tp = lj_buf_need(&ls->sb, len);\n\tmemcpy(p, ls->p, n);\n      }\n      ls->p = p;\n      ls->pe = p + n;\n    }\n    setsbufP(&ls->sb, p + n);\n    buf = ls->rfunc(ls->L, ls->rdata, &sz);  /* Get more data from reader. */\n    if (buf == NULL || sz == 0) {  /* EOF? */\n      if (need) bcread_error(ls, LJ_ERR_BCBAD);\n      ls->c = -1;  /* Only bad if we get called again. */\n      break;\n    }\n    if (n) {  /* Append to buffer. */\n      n += (MSize)sz;\n      p = lj_buf_need(&ls->sb, n < len ? len : n);\n      memcpy(sbufP(&ls->sb), buf, sz);\n      setsbufP(&ls->sb, p + n);\n      ls->p = p;\n      ls->pe = p + n;\n    } else {  /* Return buffer provided by reader. */\n      ls->p = buf;\n      ls->pe = buf + sz;\n    }\n  } while (ls->p + len > ls->pe);\n}\n\n/* Need a certain number of bytes. */\nstatic LJ_AINLINE void bcread_need(LexState *ls, MSize len)\n{\n  if (LJ_UNLIKELY(ls->p + len > ls->pe))\n    bcread_fill(ls, len, 1);\n}\n\n/* Want to read up to a certain number of bytes, but may need less. */\nstatic LJ_AINLINE void bcread_want(LexState *ls, MSize len)\n{\n  if (LJ_UNLIKELY(ls->p + len > ls->pe))\n    bcread_fill(ls, len, 0);\n}\n\n/* Return memory block from buffer. */\nstatic LJ_AINLINE uint8_t *bcread_mem(LexState *ls, MSize len)\n{\n  uint8_t *p = (uint8_t *)ls->p;\n  ls->p += len;\n  lua_assert(ls->p <= ls->pe);\n  return p;\n}\n\n/* Copy memory block from buffer. */\nstatic void bcread_block(LexState *ls, void *q, MSize len)\n{\n  memcpy(q, bcread_mem(ls, len), len);\n}\n\n/* Read byte from buffer. */\nstatic LJ_AINLINE uint32_t bcread_byte(LexState *ls)\n{\n  lua_assert(ls->p < ls->pe);\n  return (uint32_t)(uint8_t)*ls->p++;\n}\n\n/* Read ULEB128 value from buffer. */\nstatic LJ_AINLINE uint32_t bcread_uleb128(LexState *ls)\n{\n  uint32_t v = lj_buf_ruleb128(&ls->p);\n  lua_assert(ls->p <= ls->pe);\n  return v;\n}\n\n/* Read top 32 bits of 33 bit ULEB128 value from buffer. */\nstatic uint32_t bcread_uleb128_33(LexState *ls)\n{\n  const uint8_t *p = (const uint8_t *)ls->p;\n  uint32_t v = (*p++ >> 1);\n  if (LJ_UNLIKELY(v >= 0x40)) {\n    int sh = -1;\n    v &= 0x3f;\n    do {\n     v |= ((*p & 0x7f) << (sh += 7));\n   } while (*p++ >= 0x80);\n  }\n  ls->p = (char *)p;\n  lua_assert(ls->p <= ls->pe);\n  return v;\n}\n\n/* -- Bytecode reader ----------------------------------------------------- */\n\n/* Read debug info of a prototype. */\nstatic void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)\n{\n  void *lineinfo = (void *)proto_lineinfo(pt);\n  bcread_block(ls, lineinfo, sizedbg);\n  /* Swap lineinfo if the endianess differs. */\n  if (bcread_swap(ls) && pt->numline >= 256) {\n    MSize i, n = pt->sizebc-1;\n    if (pt->numline < 65536) {\n      uint16_t *p = (uint16_t *)lineinfo;\n      for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8));\n    } else {\n      uint32_t *p = (uint32_t *)lineinfo;\n      for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]);\n    }\n  }\n}\n\n/* Find pointer to varinfo. */\nstatic const void *bcread_varinfo(GCproto *pt)\n{\n  const uint8_t *p = proto_uvinfo(pt);\n  MSize n = pt->sizeuv;\n  if (n) while (*p++ || --n) ;\n  return p;\n}\n\n/* Read a single constant key/value of a template table. */\nstatic void bcread_ktabk(LexState *ls, TValue *o)\n{\n  MSize tp = bcread_uleb128(ls);\n  if (tp >= BCDUMP_KTAB_STR) {\n    MSize len = tp - BCDUMP_KTAB_STR;\n    const char *p = (const char *)bcread_mem(ls, len);\n    setstrV(ls->L, o, lj_str_new(ls->L, p, len));\n  } else if (tp == BCDUMP_KTAB_INT) {\n    setintV(o, (int32_t)bcread_uleb128(ls));\n  } else if (tp == BCDUMP_KTAB_NUM) {\n    o->u32.lo = bcread_uleb128(ls);\n    o->u32.hi = bcread_uleb128(ls);\n  } else {\n    lua_assert(tp <= BCDUMP_KTAB_TRUE);\n    setpriV(o, ~tp);\n  }\n}\n\n/* Read a template table. */\nstatic GCtab *bcread_ktab(LexState *ls)\n{\n  MSize narray = bcread_uleb128(ls);\n  MSize nhash = bcread_uleb128(ls);\n  GCtab *t = lj_tab_new(ls->L, narray, hsize2hbits(nhash));\n  if (narray) {  /* Read array entries. */\n    MSize i;\n    TValue *o = tvref(t->array);\n    for (i = 0; i < narray; i++, o++)\n      bcread_ktabk(ls, o);\n  }\n  if (nhash) {  /* Read hash entries. */\n    MSize i;\n    for (i = 0; i < nhash; i++) {\n      TValue key;\n      bcread_ktabk(ls, &key);\n      lua_assert(!tvisnil(&key));\n      bcread_ktabk(ls, lj_tab_set(ls->L, t, &key));\n    }\n  }\n  return t;\n}\n\n/* Read GC constants of a prototype. */\nstatic void bcread_kgc(LexState *ls, GCproto *pt, MSize sizekgc)\n{\n  MSize i;\n  GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;\n  for (i = 0; i < sizekgc; i++, kr++) {\n    MSize tp = bcread_uleb128(ls);\n    if (tp >= BCDUMP_KGC_STR) {\n      MSize len = tp - BCDUMP_KGC_STR;\n      const char *p = (const char *)bcread_mem(ls, len);\n      setgcref(*kr, obj2gco(lj_str_new(ls->L, p, len)));\n    } else if (tp == BCDUMP_KGC_TAB) {\n      setgcref(*kr, obj2gco(bcread_ktab(ls)));\n#if LJ_HASFFI\n    } else if (tp != BCDUMP_KGC_CHILD) {\n      CTypeID id = tp == BCDUMP_KGC_COMPLEX ? CTID_COMPLEX_DOUBLE :\n\t\t   tp == BCDUMP_KGC_I64 ? CTID_INT64 : CTID_UINT64;\n      CTSize sz = tp == BCDUMP_KGC_COMPLEX ? 16 : 8;\n      GCcdata *cd = lj_cdata_new_(ls->L, id, sz);\n      TValue *p = (TValue *)cdataptr(cd);\n      setgcref(*kr, obj2gco(cd));\n      p[0].u32.lo = bcread_uleb128(ls);\n      p[0].u32.hi = bcread_uleb128(ls);\n      if (tp == BCDUMP_KGC_COMPLEX) {\n\tp[1].u32.lo = bcread_uleb128(ls);\n\tp[1].u32.hi = bcread_uleb128(ls);\n      }\n#endif\n    } else {\n      lua_State *L = ls->L;\n      lua_assert(tp == BCDUMP_KGC_CHILD);\n      if (L->top <= bcread_oldtop(L, ls))  /* Stack underflow? */\n\tbcread_error(ls, LJ_ERR_BCBAD);\n      L->top--;\n      setgcref(*kr, obj2gco(protoV(L->top)));\n    }\n  }\n}\n\n/* Read number constants of a prototype. */\nstatic void bcread_knum(LexState *ls, GCproto *pt, MSize sizekn)\n{\n  MSize i;\n  TValue *o = mref(pt->k, TValue);\n  for (i = 0; i < sizekn; i++, o++) {\n    int isnum = (ls->p[0] & 1);\n    uint32_t lo = bcread_uleb128_33(ls);\n    if (isnum) {\n      o->u32.lo = lo;\n      o->u32.hi = bcread_uleb128(ls);\n    } else {\n      setintV(o, lo);\n    }\n  }\n}\n\n/* Read bytecode instructions. */\nstatic void bcread_bytecode(LexState *ls, GCproto *pt, MSize sizebc)\n{\n  BCIns *bc = proto_bc(pt);\n  bc[0] = BCINS_AD((pt->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,\n\t\t   pt->framesize, 0);\n  bcread_block(ls, bc+1, (sizebc-1)*(MSize)sizeof(BCIns));\n  /* Swap bytecode instructions if the endianess differs. */\n  if (bcread_swap(ls)) {\n    MSize i;\n    for (i = 1; i < sizebc; i++) bc[i] = lj_bswap(bc[i]);\n  }\n}\n\n/* Read upvalue refs. */\nstatic void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv)\n{\n  if (sizeuv) {\n    uint16_t *uv = proto_uv(pt);\n    bcread_block(ls, uv, sizeuv*2);\n    /* Swap upvalue refs if the endianess differs. */\n    if (bcread_swap(ls)) {\n      MSize i;\n      for (i = 0; i < sizeuv; i++)\n\tuv[i] = (uint16_t)((uv[i] >> 8)|(uv[i] << 8));\n    }\n  }\n}\n\n/* Read a prototype. */\nGCproto *lj_bcread_proto(LexState *ls)\n{\n  GCproto *pt;\n  MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept;\n  MSize ofsk, ofsuv, ofsdbg;\n  MSize sizedbg = 0;\n  BCLine firstline = 0, numline = 0;\n\n  /* Read prototype header. */\n  flags = bcread_byte(ls);\n  numparams = bcread_byte(ls);\n  framesize = bcread_byte(ls);\n  sizeuv = bcread_byte(ls);\n  sizekgc = bcread_uleb128(ls);\n  sizekn = bcread_uleb128(ls);\n  sizebc = bcread_uleb128(ls) + 1;\n  if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) {\n    sizedbg = bcread_uleb128(ls);\n    if (sizedbg) {\n      firstline = bcread_uleb128(ls);\n      numline = bcread_uleb128(ls);\n    }\n  }\n\n  /* Calculate total size of prototype including all colocated arrays. */\n  sizept = (MSize)sizeof(GCproto) +\n\t   sizebc*(MSize)sizeof(BCIns) +\n\t   sizekgc*(MSize)sizeof(GCRef);\n  sizept = (sizept + (MSize)sizeof(TValue)-1) & ~((MSize)sizeof(TValue)-1);\n  ofsk = sizept; sizept += sizekn*(MSize)sizeof(TValue);\n  ofsuv = sizept; sizept += ((sizeuv+1)&~1)*2;\n  ofsdbg = sizept; sizept += sizedbg;\n\n  /* Allocate prototype object and initialize its fields. */\n  pt = (GCproto *)lj_mem_newgco(ls->L, (MSize)sizept);\n  pt->gct = ~LJ_TPROTO;\n  pt->numparams = (uint8_t)numparams;\n  pt->framesize = (uint8_t)framesize;\n  pt->sizebc = sizebc;\n  setmref(pt->k, (char *)pt + ofsk);\n  setmref(pt->uv, (char *)pt + ofsuv);\n  pt->sizekgc = 0;  /* Set to zero until fully initialized. */\n  pt->sizekn = sizekn;\n  pt->sizept = sizept;\n  pt->sizeuv = (uint8_t)sizeuv;\n  pt->flags = (uint8_t)flags;\n  pt->trace = 0;\n  setgcref(pt->chunkname, obj2gco(ls->chunkname));\n\n  /* Close potentially uninitialized gap between bc and kgc. */\n  *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(sizekgc+1)) = 0;\n\n  /* Read bytecode instructions and upvalue refs. */\n  bcread_bytecode(ls, pt, sizebc);\n  bcread_uv(ls, pt, sizeuv);\n\n  /* Read constants. */\n  bcread_kgc(ls, pt, sizekgc);\n  pt->sizekgc = sizekgc;\n  bcread_knum(ls, pt, sizekn);\n\n  /* Read and initialize debug info. */\n  pt->firstline = firstline;\n  pt->numline = numline;\n  if (sizedbg) {\n    MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);\n    setmref(pt->lineinfo, (char *)pt + ofsdbg);\n    setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);\n    bcread_dbg(ls, pt, sizedbg);\n    setmref(pt->varinfo, bcread_varinfo(pt));\n  } else {\n    setmref(pt->lineinfo, NULL);\n    setmref(pt->uvinfo, NULL);\n    setmref(pt->varinfo, NULL);\n  }\n  return pt;\n}\n\n/* Read and check header of bytecode dump. */\nstatic int bcread_header(LexState *ls)\n{\n  uint32_t flags;\n  bcread_want(ls, 3+5+5);\n  if (bcread_byte(ls) != BCDUMP_HEAD2 ||\n      bcread_byte(ls) != BCDUMP_HEAD3 ||\n      bcread_byte(ls) != BCDUMP_VERSION) return 0;\n  bcread_flags(ls) = flags = bcread_uleb128(ls);\n  if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0;\n  if ((flags & BCDUMP_F_FR2) != LJ_FR2*BCDUMP_F_FR2) return 0;\n  if ((flags & BCDUMP_F_FFI)) {\n#if LJ_HASFFI\n    lua_State *L = ls->L;\n    if (!ctype_ctsG(G(L))) {\n      ptrdiff_t oldtop = savestack(L, L->top);\n      luaopen_ffi(L);  /* Load FFI library on-demand. */\n      L->top = restorestack(L, oldtop);\n    }\n#else\n    return 0;\n#endif\n  }\n  if ((flags & BCDUMP_F_STRIP)) {\n    ls->chunkname = lj_str_newz(ls->L, ls->chunkarg);\n  } else {\n    MSize len = bcread_uleb128(ls);\n    bcread_need(ls, len);\n    ls->chunkname = lj_str_new(ls->L, (const char *)bcread_mem(ls, len), len);\n  }\n  return 1;  /* Ok. */\n}\n\n/* Read a bytecode dump. */\nGCproto *lj_bcread(LexState *ls)\n{\n  lua_State *L = ls->L;\n  lua_assert(ls->c == BCDUMP_HEAD1);\n  bcread_savetop(L, ls, L->top);\n  lj_buf_reset(&ls->sb);\n  /* Check for a valid bytecode dump header. */\n  if (!bcread_header(ls))\n    bcread_error(ls, LJ_ERR_BCFMT);\n  for (;;) {  /* Process all prototypes in the bytecode dump. */\n    GCproto *pt;\n    MSize len;\n    const char *startp;\n    /* Read length. */\n    if (ls->p < ls->pe && ls->p[0] == 0) {  /* Shortcut EOF. */\n      ls->p++;\n      break;\n    }\n    bcread_want(ls, 5);\n    len = bcread_uleb128(ls);\n    if (!len) break;  /* EOF */\n    bcread_need(ls, len);\n    startp = ls->p;\n    pt = lj_bcread_proto(ls);\n    if (ls->p != startp + len)\n      bcread_error(ls, LJ_ERR_BCBAD);\n    setprotoV(L, L->top, pt);\n    incr_top(L);\n  }\n  if ((int32_t)(2*(uint32_t)(ls->pe - ls->p)) > 0 ||\n      L->top-1 != bcread_oldtop(L, ls))\n    bcread_error(ls, LJ_ERR_BCBAD);\n  /* Pop off last prototype. */\n  L->top--;\n  return protoV(L->top);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_bcwrite.c",
    "content": "/*\n** Bytecode writer.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bcwrite_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_buf.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#if LJ_HASJIT\n#include \"lj_dispatch.h\"\n#include \"lj_jit.h\"\n#endif\n#include \"lj_strfmt.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_vm.h\"\n\n/* Context for bytecode writer. */\ntypedef struct BCWriteCtx {\n  SBuf sb;\t\t\t/* Output buffer. */\n  GCproto *pt;\t\t\t/* Root prototype. */\n  lua_Writer wfunc;\t\t/* Writer callback. */\n  void *wdata;\t\t\t/* Writer callback data. */\n  int strip;\t\t\t/* Strip debug info. */\n  int status;\t\t\t/* Status from writer callback. */\n} BCWriteCtx;\n\n/* -- Bytecode writer ----------------------------------------------------- */\n\n/* Write a single constant key/value of a template table. */\nstatic void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow)\n{\n  char *p = lj_buf_more(&ctx->sb, 1+10);\n  if (tvisstr(o)) {\n    const GCstr *str = strV(o);\n    MSize len = str->len;\n    p = lj_buf_more(&ctx->sb, 5+len);\n    p = lj_strfmt_wuleb128(p, BCDUMP_KTAB_STR+len);\n    p = lj_buf_wmem(p, strdata(str), len);\n  } else if (tvisint(o)) {\n    *p++ = BCDUMP_KTAB_INT;\n    p = lj_strfmt_wuleb128(p, intV(o));\n  } else if (tvisnum(o)) {\n    if (!LJ_DUALNUM && narrow) {  /* Narrow number constants to integers. */\n      lua_Number num = numV(o);\n      int32_t k = lj_num2int(num);\n      if (num == (lua_Number)k) {  /* -0 is never a constant. */\n\t*p++ = BCDUMP_KTAB_INT;\n\tp = lj_strfmt_wuleb128(p, k);\n\tsetsbufP(&ctx->sb, p);\n\treturn;\n      }\n    }\n    *p++ = BCDUMP_KTAB_NUM;\n    p = lj_strfmt_wuleb128(p, o->u32.lo);\n    p = lj_strfmt_wuleb128(p, o->u32.hi);\n  } else {\n    lua_assert(tvispri(o));\n    *p++ = BCDUMP_KTAB_NIL+~itype(o);\n  }\n  setsbufP(&ctx->sb, p);\n}\n\n/* Write a template table. */\nstatic void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t)\n{\n  MSize narray = 0, nhash = 0;\n  if (t->asize > 0) {  /* Determine max. length of array part. */\n    ptrdiff_t i;\n    TValue *array = tvref(t->array);\n    for (i = (ptrdiff_t)t->asize-1; i >= 0; i--)\n      if (!tvisnil(&array[i]))\n\tbreak;\n    narray = (MSize)(i+1);\n  }\n  if (t->hmask > 0) {  /* Count number of used hash slots. */\n    MSize i, hmask = t->hmask;\n    Node *node = noderef(t->node);\n    for (i = 0; i <= hmask; i++)\n      nhash += !tvisnil(&node[i].val);\n  }\n  /* Write number of array slots and hash slots. */\n  p = lj_strfmt_wuleb128(p, narray);\n  p = lj_strfmt_wuleb128(p, nhash);\n  setsbufP(&ctx->sb, p);\n  if (narray) {  /* Write array entries (may contain nil). */\n    MSize i;\n    TValue *o = tvref(t->array);\n    for (i = 0; i < narray; i++, o++)\n      bcwrite_ktabk(ctx, o, 1);\n  }\n  if (nhash) {  /* Write hash entries. */\n    MSize i = nhash;\n    Node *node = noderef(t->node) + t->hmask;\n    for (;; node--)\n      if (!tvisnil(&node->val)) {\n\tbcwrite_ktabk(ctx, &node->key, 0);\n\tbcwrite_ktabk(ctx, &node->val, 1);\n\tif (--i == 0) break;\n      }\n  }\n}\n\n/* Write GC constants of a prototype. */\nstatic void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize i, sizekgc = pt->sizekgc;\n  GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;\n  for (i = 0; i < sizekgc; i++, kr++) {\n    GCobj *o = gcref(*kr);\n    MSize tp, need = 1;\n    char *p;\n    /* Determine constant type and needed size. */\n    if (o->gch.gct == ~LJ_TSTR) {\n      tp = BCDUMP_KGC_STR + gco2str(o)->len;\n      need = 5+gco2str(o)->len;\n    } else if (o->gch.gct == ~LJ_TPROTO) {\n      lua_assert((pt->flags & PROTO_CHILD));\n      tp = BCDUMP_KGC_CHILD;\n#if LJ_HASFFI\n    } else if (o->gch.gct == ~LJ_TCDATA) {\n      CTypeID id = gco2cd(o)->ctypeid;\n      need = 1+4*5;\n      if (id == CTID_INT64) {\n\ttp = BCDUMP_KGC_I64;\n      } else if (id == CTID_UINT64) {\n\ttp = BCDUMP_KGC_U64;\n      } else {\n\tlua_assert(id == CTID_COMPLEX_DOUBLE);\n\ttp = BCDUMP_KGC_COMPLEX;\n      }\n#endif\n    } else {\n      lua_assert(o->gch.gct == ~LJ_TTAB);\n      tp = BCDUMP_KGC_TAB;\n      need = 1+2*5;\n    }\n    /* Write constant type. */\n    p = lj_buf_more(&ctx->sb, need);\n    p = lj_strfmt_wuleb128(p, tp);\n    /* Write constant data (if any). */\n    if (tp >= BCDUMP_KGC_STR) {\n      p = lj_buf_wmem(p, strdata(gco2str(o)), gco2str(o)->len);\n    } else if (tp == BCDUMP_KGC_TAB) {\n      bcwrite_ktab(ctx, p, gco2tab(o));\n      continue;\n#if LJ_HASFFI\n    } else if (tp != BCDUMP_KGC_CHILD) {\n      cTValue *q = (TValue *)cdataptr(gco2cd(o));\n      p = lj_strfmt_wuleb128(p, q[0].u32.lo);\n      p = lj_strfmt_wuleb128(p, q[0].u32.hi);\n      if (tp == BCDUMP_KGC_COMPLEX) {\n\tp = lj_strfmt_wuleb128(p, q[1].u32.lo);\n\tp = lj_strfmt_wuleb128(p, q[1].u32.hi);\n      }\n#endif\n    }\n    setsbufP(&ctx->sb, p);\n  }\n}\n\n/* Write number constants of a prototype. */\nstatic void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize i, sizekn = pt->sizekn;\n  cTValue *o = mref(pt->k, TValue);\n  char *p = lj_buf_more(&ctx->sb, 10*sizekn);\n  for (i = 0; i < sizekn; i++, o++) {\n    int32_t k;\n    if (tvisint(o)) {\n      k = intV(o);\n      goto save_int;\n    } else {\n      /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */\n      if (!LJ_DUALNUM) {  /* Narrow number constants to integers. */\n\tlua_Number num = numV(o);\n\tk = lj_num2int(num);\n\tif (num == (lua_Number)k) {  /* -0 is never a constant. */\n\tsave_int:\n\t  p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u));\n\t  if (k < 0)\n\t    p[-1] = (p[-1] & 7) | ((k>>27) & 0x18);\n\t  continue;\n\t}\n      }\n      p = lj_strfmt_wuleb128(p, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u)));\n      if (o->u32.lo >= 0x80000000u)\n\tp[-1] = (p[-1] & 7) | ((o->u32.lo>>27) & 0x18);\n      p = lj_strfmt_wuleb128(p, o->u32.hi);\n    }\n  }\n  setsbufP(&ctx->sb, p);\n}\n\n/* Write bytecode instructions. */\nstatic char *bcwrite_bytecode(BCWriteCtx *ctx, char *p, GCproto *pt)\n{\n  MSize nbc = pt->sizebc-1;  /* Omit the [JI]FUNC* header. */\n#if LJ_HASJIT\n  uint8_t *q = (uint8_t *)p;\n#endif\n  p = lj_buf_wmem(p, proto_bc(pt)+1, nbc*(MSize)sizeof(BCIns));\n  UNUSED(ctx);\n#if LJ_HASJIT\n  /* Unpatch modified bytecode containing ILOOP/JLOOP etc. */\n  if ((pt->flags & PROTO_ILOOP) || pt->trace) {\n    jit_State *J = L2J(sbufL(&ctx->sb));\n    MSize i;\n    for (i = 0; i < nbc; i++, q += sizeof(BCIns)) {\n      BCOp op = (BCOp)q[LJ_ENDIAN_SELECT(0, 3)];\n      if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP ||\n\t  op == BC_JFORI) {\n\tq[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_IFORL+BC_FORL);\n      } else if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {\n\tBCReg rd = q[LJ_ENDIAN_SELECT(2, 1)] + (q[LJ_ENDIAN_SELECT(3, 0)] << 8);\n\tBCIns ins = traceref(J, rd)->startins;\n\tq[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_JFORL+BC_FORL);\n\tq[LJ_ENDIAN_SELECT(2, 1)] = bc_c(ins);\n\tq[LJ_ENDIAN_SELECT(3, 0)] = bc_b(ins);\n      }\n    }\n  }\n#endif\n  return p;\n}\n\n/* Write prototype. */\nstatic void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize sizedbg = 0;\n  char *p;\n\n  /* Recursively write children of prototype. */\n  if ((pt->flags & PROTO_CHILD)) {\n    ptrdiff_t i, n = pt->sizekgc;\n    GCRef *kr = mref(pt->k, GCRef) - 1;\n    for (i = 0; i < n; i++, kr--) {\n      GCobj *o = gcref(*kr);\n      if (o->gch.gct == ~LJ_TPROTO)\n\tbcwrite_proto(ctx, gco2pt(o));\n    }\n  }\n\n  /* Start writing the prototype info to a buffer. */\n  p = lj_buf_need(&ctx->sb,\n\t\t  5+4+6*5+(pt->sizebc-1)*(MSize)sizeof(BCIns)+pt->sizeuv*2);\n  p += 5;  /* Leave room for final size. */\n\n  /* Write prototype header. */\n  *p++ = (pt->flags & (PROTO_CHILD|PROTO_VARARG|PROTO_FFI));\n  *p++ = pt->numparams;\n  *p++ = pt->framesize;\n  *p++ = pt->sizeuv;\n  p = lj_strfmt_wuleb128(p, pt->sizekgc);\n  p = lj_strfmt_wuleb128(p, pt->sizekn);\n  p = lj_strfmt_wuleb128(p, pt->sizebc-1);\n  if (!ctx->strip) {\n    if (proto_lineinfo(pt))\n      sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt);\n    p = lj_strfmt_wuleb128(p, sizedbg);\n    if (sizedbg) {\n      p = lj_strfmt_wuleb128(p, pt->firstline);\n      p = lj_strfmt_wuleb128(p, pt->numline);\n    }\n  }\n\n  /* Write bytecode instructions and upvalue refs. */\n  p = bcwrite_bytecode(ctx, p, pt);\n  p = lj_buf_wmem(p, proto_uv(pt), pt->sizeuv*2);\n  setsbufP(&ctx->sb, p);\n\n  /* Write constants. */\n  bcwrite_kgc(ctx, pt);\n  bcwrite_knum(ctx, pt);\n\n  /* Write debug info, if not stripped. */\n  if (sizedbg) {\n    p = lj_buf_more(&ctx->sb, sizedbg);\n    p = lj_buf_wmem(p, proto_lineinfo(pt), sizedbg);\n    setsbufP(&ctx->sb, p);\n  }\n\n  /* Pass buffer to writer function. */\n  if (ctx->status == 0) {\n    MSize n = sbuflen(&ctx->sb) - 5;\n    MSize nn = (lj_fls(n)+8)*9 >> 6;\n    char *q = sbufB(&ctx->sb) + (5 - nn);\n    p = lj_strfmt_wuleb128(q, n);  /* Fill in final size. */\n    lua_assert(p == sbufB(&ctx->sb) + 5);\n    ctx->status = ctx->wfunc(sbufL(&ctx->sb), q, nn+n, ctx->wdata);\n  }\n}\n\n/* Write header of bytecode dump. */\nstatic void bcwrite_header(BCWriteCtx *ctx)\n{\n  GCstr *chunkname = proto_chunkname(ctx->pt);\n  const char *name = strdata(chunkname);\n  MSize len = chunkname->len;\n  char *p = lj_buf_need(&ctx->sb, 5+5+len);\n  *p++ = BCDUMP_HEAD1;\n  *p++ = BCDUMP_HEAD2;\n  *p++ = BCDUMP_HEAD3;\n  *p++ = BCDUMP_VERSION;\n  *p++ = (ctx->strip ? BCDUMP_F_STRIP : 0) +\n\t LJ_BE*BCDUMP_F_BE +\n\t ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0) +\n\t LJ_FR2*BCDUMP_F_FR2;\n  if (!ctx->strip) {\n    p = lj_strfmt_wuleb128(p, len);\n    p = lj_buf_wmem(p, name, len);\n  }\n  ctx->status = ctx->wfunc(sbufL(&ctx->sb), sbufB(&ctx->sb),\n\t\t\t   (MSize)(p - sbufB(&ctx->sb)), ctx->wdata);\n}\n\n/* Write footer of bytecode dump. */\nstatic void bcwrite_footer(BCWriteCtx *ctx)\n{\n  if (ctx->status == 0) {\n    uint8_t zero = 0;\n    ctx->status = ctx->wfunc(sbufL(&ctx->sb), &zero, 1, ctx->wdata);\n  }\n}\n\n/* Protected callback for bytecode writer. */\nstatic TValue *cpwriter(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  BCWriteCtx *ctx = (BCWriteCtx *)ud;\n  UNUSED(L); UNUSED(dummy);\n  lj_buf_need(&ctx->sb, 1024);  /* Avoids resize for most prototypes. */\n  bcwrite_header(ctx);\n  bcwrite_proto(ctx, ctx->pt);\n  bcwrite_footer(ctx);\n  return NULL;\n}\n\n/* Write bytecode for a prototype. */\nint lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, void *data,\n\t      int strip)\n{\n  BCWriteCtx ctx;\n  int status;\n  ctx.pt = pt;\n  ctx.wfunc = writer;\n  ctx.wdata = data;\n  ctx.strip = strip;\n  ctx.status = 0;\n  lj_buf_init(L, &ctx.sb);\n  status = lj_vm_cpcall(L, NULL, &ctx, cpwriter);\n  if (status == 0) status = ctx.status;\n  lj_buf_free(G(sbufL(&ctx.sb)), &ctx.sb);\n  return status;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_buf.c",
    "content": "/*\n** Buffer handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_buf_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Buffer management --------------------------------------------------- */\n\nstatic void buf_grow(SBuf *sb, MSize sz)\n{\n  MSize osz = sbufsz(sb), len = sbuflen(sb), nsz = osz;\n  char *b;\n  if (nsz < LJ_MIN_SBUF) nsz = LJ_MIN_SBUF;\n  while (nsz < sz) nsz += nsz;\n  b = (char *)lj_mem_realloc(sbufL(sb), sbufB(sb), osz, nsz);\n  setmref(sb->b, b);\n  setmref(sb->p, b + len);\n  setmref(sb->e, b + nsz);\n}\n\nLJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz)\n{\n  lua_assert(sz > sbufsz(sb));\n  if (LJ_UNLIKELY(sz > LJ_MAX_BUF))\n    lj_err_mem(sbufL(sb));\n  buf_grow(sb, sz);\n  return sbufB(sb);\n}\n\nLJ_NOINLINE char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz)\n{\n  MSize len = sbuflen(sb);\n  lua_assert(sz > sbufleft(sb));\n  if (LJ_UNLIKELY(sz > LJ_MAX_BUF || len + sz > LJ_MAX_BUF))\n    lj_err_mem(sbufL(sb));\n  buf_grow(sb, len + sz);\n  return sbufP(sb);\n}\n\nvoid LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb)\n{\n  char *b = sbufB(sb);\n  MSize osz = (MSize)(sbufE(sb) - b);\n  if (osz > 2*LJ_MIN_SBUF) {\n    MSize n = (MSize)(sbufP(sb) - b);\n    b = lj_mem_realloc(L, b, osz, (osz >> 1));\n    setmref(sb->b, b);\n    setmref(sb->p, b + n);\n    setmref(sb->e, b + (osz >> 1));\n  }\n}\n\nchar * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz)\n{\n  SBuf *sb = &G(L)->tmpbuf;\n  setsbufL(sb, L);\n  return lj_buf_need(sb, sz);\n}\n\n/* -- Low-level buffer put operations ------------------------------------- */\n\nSBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len)\n{\n  char *p = lj_buf_more(sb, len);\n  p = lj_buf_wmem(p, q, len);\n  setsbufP(sb, p);\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c)\n{\n  char *p = lj_buf_more(sb, 1);\n  *p++ = (char)c;\n  setsbufP(sb, p);\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *p = lj_buf_more(sb, len);\n  p = lj_buf_wmem(p, strdata(s), len);\n  setsbufP(sb, p);\n  return sb;\n}\n\n/* -- High-level buffer put operations ------------------------------------ */\n\nSBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *p = lj_buf_more(sb, len), *e = p+len;\n  const char *q = strdata(s)+len-1;\n  while (p < e)\n    *p++ = *q--;\n  setsbufP(sb, p);\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *p = lj_buf_more(sb, len), *e = p+len;\n  const char *q = strdata(s);\n  for (; p < e; p++, q++) {\n    uint32_t c = *(unsigned char *)q;\n#if LJ_TARGET_PPC\n    *p = c + ((c >= 'A' && c <= 'Z') << 5);\n#else\n    if (c >= 'A' && c <= 'Z') c += 0x20;\n    *p = c;\n#endif\n  }\n  setsbufP(sb, p);\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *p = lj_buf_more(sb, len), *e = p+len;\n  const char *q = strdata(s);\n  for (; p < e; p++, q++) {\n    uint32_t c = *(unsigned char *)q;\n#if LJ_TARGET_PPC\n    *p = c - ((c >= 'a' && c <= 'z') << 5);\n#else\n    if (c >= 'a' && c <= 'z') c -= 0x20;\n    *p = c;\n#endif\n  }\n  setsbufP(sb, p);\n  return sb;\n}\n\nSBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep)\n{\n  MSize len = s->len;\n  if (rep > 0 && len) {\n    uint64_t tlen = (uint64_t)rep * len;\n    char *p;\n    if (LJ_UNLIKELY(tlen > LJ_MAX_STR))\n      lj_err_mem(sbufL(sb));\n    p = lj_buf_more(sb, (MSize)tlen);\n    if (len == 1) {  /* Optimize a common case. */\n      uint32_t c = strdata(s)[0];\n      do { *p++ = c; } while (--rep > 0);\n    } else {\n      const char *e = strdata(s) + len;\n      do {\n\tconst char *q = strdata(s);\n\tdo { *p++ = *q++; } while (q < e);\n      } while (--rep > 0);\n    }\n    setsbufP(sb, p);\n  }\n  return sb;\n}\n\nSBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e)\n{\n  MSize seplen = sep ? sep->len : 0;\n  if (i <= e) {\n    for (;;) {\n      cTValue *o = lj_tab_getint(t, i);\n      char *p;\n      if (!o) {\n      badtype:  /* Error: bad element type. */\n\tsetsbufP(sb, (void *)(intptr_t)i);  /* Store failing index. */\n\treturn NULL;\n      } else if (tvisstr(o)) {\n\tMSize len = strV(o)->len;\n\tp = lj_buf_wmem(lj_buf_more(sb, len + seplen), strVdata(o), len);\n      } else if (tvisint(o)) {\n\tp = lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT+seplen), intV(o));\n      } else if (tvisnum(o)) {\n\tp = lj_buf_more(lj_strfmt_putfnum(sb, STRFMT_G14, numV(o)), seplen);\n      } else {\n\tgoto badtype;\n      }\n      if (i++ == e) {\n\tsetsbufP(sb, p);\n\tbreak;\n      }\n      if (seplen) p = lj_buf_wmem(p, strdata(sep), seplen);\n      setsbufP(sb, p);\n    }\n  }\n  return sb;\n}\n\n/* -- Miscellaneous buffer operations ------------------------------------- */\n\nGCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb)\n{\n  return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb));\n}\n\n/* Concatenate two strings. */\nGCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2)\n{\n  MSize len1 = s1->len, len2 = s2->len;\n  char *buf = lj_buf_tmp(L, len1 + len2);\n  memcpy(buf, strdata(s1), len1);\n  memcpy(buf+len1, strdata(s2), len2);\n  return lj_str_new(L, buf, len1 + len2);\n}\n\n/* Read ULEB128 from buffer. */\nuint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp)\n{\n  const uint8_t *p = (const uint8_t *)*pp;\n  uint32_t v = *p++;\n  if (LJ_UNLIKELY(v >= 0x80)) {\n    int sh = 0;\n    v &= 0x7f;\n    do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80);\n  }\n  *pp = (const char *)p;\n  return v;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_buf.h",
    "content": "/*\n** Buffer handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BUF_H\n#define _LJ_BUF_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_str.h\"\n\n/* Resizable string buffers. Struct definition in lj_obj.h. */\n#define sbufB(sb)\t(mref((sb)->b, char))\n#define sbufP(sb)\t(mref((sb)->p, char))\n#define sbufE(sb)\t(mref((sb)->e, char))\n#define sbufL(sb)\t(mref((sb)->L, lua_State))\n#define sbufsz(sb)\t((MSize)(sbufE((sb)) - sbufB((sb))))\n#define sbuflen(sb)\t((MSize)(sbufP((sb)) - sbufB((sb))))\n#define sbufleft(sb)\t((MSize)(sbufE((sb)) - sbufP((sb))))\n#define setsbufP(sb, q)\t(setmref((sb)->p, (q)))\n#define setsbufL(sb, l)\t(setmref((sb)->L, (l)))\n\n/* Buffer management */\nLJ_FUNC char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz);\nLJ_FUNC char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz);\nLJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb);\nLJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz);\n\nstatic LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb)\n{\n  setsbufL(sb, L);\n  setmref(sb->p, NULL); setmref(sb->e, NULL); setmref(sb->b, NULL);\n}\n\nstatic LJ_AINLINE void lj_buf_reset(SBuf *sb)\n{\n  setmrefr(sb->p, sb->b);\n}\n\nstatic LJ_AINLINE SBuf *lj_buf_tmp_(lua_State *L)\n{\n  SBuf *sb = &G(L)->tmpbuf;\n  setsbufL(sb, L);\n  lj_buf_reset(sb);\n  return sb;\n}\n\nstatic LJ_AINLINE void lj_buf_free(global_State *g, SBuf *sb)\n{\n  lj_mem_free(g, sbufB(sb), sbufsz(sb));\n}\n\nstatic LJ_AINLINE char *lj_buf_need(SBuf *sb, MSize sz)\n{\n  if (LJ_UNLIKELY(sz > sbufsz(sb)))\n    return lj_buf_need2(sb, sz);\n  return sbufB(sb);\n}\n\nstatic LJ_AINLINE char *lj_buf_more(SBuf *sb, MSize sz)\n{\n  if (LJ_UNLIKELY(sz > sbufleft(sb)))\n    return lj_buf_more2(sb, sz);\n  return sbufP(sb);\n}\n\n/* Low-level buffer put operations */\nLJ_FUNC SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len);\nLJ_FUNC SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c);\nLJ_FUNC SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s);\n\nstatic LJ_AINLINE char *lj_buf_wmem(char *p, const void *q, MSize len)\n{\n  return (char *)memcpy(p, q, len) + len;\n}\n\nstatic LJ_AINLINE void lj_buf_putb(SBuf *sb, int c)\n{\n  char *p = lj_buf_more(sb, 1);\n  *p++ = (char)c;\n  setsbufP(sb, p);\n}\n\n/* High-level buffer put operations */\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s);\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s);\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s);\nLJ_FUNC SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep);\nLJ_FUNC SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep,\n\t\t\t    int32_t i, int32_t e);\n\n/* Miscellaneous buffer operations */\nLJ_FUNCA GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb);\nLJ_FUNC GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2);\nLJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp);\n\nstatic LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb)\n{\n  return lj_str_new(L, sbufB(sb), sbuflen(sb));\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_carith.c",
    "content": "/*\n** C data arithmetic.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_ir.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_carith.h\"\n#include \"lj_strscan.h\"\n\n/* -- C data arithmetic --------------------------------------------------- */\n\n/* Binary operands of an operator converted to ctypes. */\ntypedef struct CDArith {\n  uint8_t *p[2];\n  CType *ct[2];\n} CDArith;\n\n/* Check arguments for arithmetic metamethods. */\nstatic int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca)\n{\n  TValue *o = L->base;\n  int ok = 1;\n  MSize i;\n  if (o+1 >= L->top)\n    lj_err_argt(L, 1, LUA_TCDATA);\n  for (i = 0; i < 2; i++, o++) {\n    if (tviscdata(o)) {\n      GCcdata *cd = cdataV(o);\n      CTypeID id = (CTypeID)cd->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      uint8_t *p = (uint8_t *)cdataptr(cd);\n      if (ctype_isptr(ct->info)) {\n\tp = (uint8_t *)cdata_getptr(p, ct->size);\n\tif (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);\n      } else if (ctype_isfunc(ct->info)) {\n\tp = (uint8_t *)*(void **)p;\n\tct = ctype_get(cts,\n\t  lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));\n      }\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      ca->ct[i] = ct;\n      ca->p[i] = p;\n    } else if (tvisint(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_INT32);\n      ca->p[i] = (uint8_t *)&o->i;\n    } else if (tvisnum(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_DOUBLE);\n      ca->p[i] = (uint8_t *)&o->n;\n    } else if (tvisnil(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_P_VOID);\n      ca->p[i] = (uint8_t *)0;\n    } else if (tvisstr(o)) {\n      TValue *o2 = i == 0 ? o+1 : o-1;\n      CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid);\n      ca->ct[i] = NULL;\n      ca->p[i] = (uint8_t *)strVdata(o);\n      ok = 0;\n      if (ctype_isenum(ct->info)) {\n\tCTSize ofs;\n\tCType *cct = lj_ctype_getfield(cts, ct, strV(o), &ofs);\n\tif (cct && ctype_isconstval(cct->info)) {\n\t  ca->ct[i] = ctype_child(cts, cct);\n\t  ca->p[i] = (uint8_t *)&cct->size;  /* Assumes ct does not grow. */\n\t  ok = 1;\n\t} else {\n\t  ca->ct[1-i] = ct;  /* Use enum to improve error message. */\n\t  ca->p[1-i] = NULL;\n\t  break;\n\t}\n      }\n    } else {\n      ca->ct[i] = NULL;\n      ca->p[i] = (void *)(intptr_t)1;  /* To make it unequal. */\n      ok = 0;\n    }\n  }\n  return ok;\n}\n\n/* Pointer arithmetic. */\nstatic int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  CType *ctp = ca->ct[0];\n  uint8_t *pp = ca->p[0];\n  ptrdiff_t idx;\n  CTSize sz;\n  CTypeID id;\n  GCcdata *cd;\n  if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {\n    if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&\n\t(ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {\n      uint8_t *pp2 = ca->p[1];\n      if (mm == MM_eq) {  /* Pointer equality. Incompatible pointers are ok. */\n\tsetboolV(L->top-1, (pp == pp2));\n\treturn 1;\n      }\n      if (!lj_cconv_compatptr(cts, ctp, ca->ct[1], CCF_IGNQUAL))\n\treturn 0;\n      if (mm == MM_sub) {  /* Pointer difference. */\n\tintptr_t diff;\n\tsz = lj_ctype_size(cts, ctype_cid(ctp->info));  /* Element size. */\n\tif (sz == 0 || sz == CTSIZE_INVALID)\n\t  return 0;\n\tdiff = ((intptr_t)pp - (intptr_t)pp2) / (int32_t)sz;\n\t/* All valid pointer differences on x64 are in (-2^47, +2^47),\n\t** which fits into a double without loss of precision.\n\t*/\n\tsetintptrV(L->top-1, (int32_t)diff);\n\treturn 1;\n      } else if (mm == MM_lt) {  /* Pointer comparison (unsigned). */\n\tsetboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2));\n\treturn 1;\n      } else {\n\tlua_assert(mm == MM_le);\n\tsetboolV(L->top-1, ((uintptr_t)pp <= (uintptr_t)pp2));\n\treturn 1;\n      }\n    }\n    if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(ca->ct[1]->info)))\n      return 0;\n    lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[1],\n\t\t   (uint8_t *)&idx, ca->p[1], 0);\n    if (mm == MM_sub) idx = -idx;\n  } else if (mm == MM_add && ctype_isnum(ctp->info) &&\n      (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {\n    /* Swap pointer and index. */\n    ctp = ca->ct[1]; pp = ca->p[1];\n    lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[0],\n\t\t   (uint8_t *)&idx, ca->p[0], 0);\n  } else {\n    return 0;\n  }\n  sz = lj_ctype_size(cts, ctype_cid(ctp->info));  /* Element size. */\n  if (sz == CTSIZE_INVALID)\n    return 0;\n  pp += idx*(int32_t)sz;  /* Compute pointer + index. */\n  id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),\n\t\t       CTSIZE_PTR);\n  cd = lj_cdata_new(cts, id, CTSIZE_PTR);\n  *(uint8_t **)cdataptr(cd) = pp;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\n/* 64 bit integer arithmetic. */\nstatic int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  if (ctype_isnum(ca->ct[0]->info) && ca->ct[0]->size <= 8 &&\n      ctype_isnum(ca->ct[1]->info) && ca->ct[1]->size <= 8) {\n    CTypeID id = (((ca->ct[0]->info & CTF_UNSIGNED) && ca->ct[0]->size == 8) ||\n\t\t  ((ca->ct[1]->info & CTF_UNSIGNED) && ca->ct[1]->size == 8)) ?\n\t\t CTID_UINT64 : CTID_INT64;\n    CType *ct = ctype_get(cts, id);\n    GCcdata *cd;\n    uint64_t u0, u1, *up;\n    lj_cconv_ct_ct(cts, ct, ca->ct[0], (uint8_t *)&u0, ca->p[0], 0);\n    if (mm != MM_unm)\n      lj_cconv_ct_ct(cts, ct, ca->ct[1], (uint8_t *)&u1, ca->p[1], 0);\n    switch (mm) {\n    case MM_eq:\n      setboolV(L->top-1, (u0 == u1));\n      return 1;\n    case MM_lt:\n      setboolV(L->top-1,\n\t       id == CTID_INT64 ? ((int64_t)u0 < (int64_t)u1) : (u0 < u1));\n      return 1;\n    case MM_le:\n      setboolV(L->top-1,\n\t       id == CTID_INT64 ? ((int64_t)u0 <= (int64_t)u1) : (u0 <= u1));\n      return 1;\n    default: break;\n    }\n    cd = lj_cdata_new(cts, id, 8);\n    up = (uint64_t *)cdataptr(cd);\n    setcdataV(L, L->top-1, cd);\n    switch (mm) {\n    case MM_add: *up = u0 + u1; break;\n    case MM_sub: *up = u0 - u1; break;\n    case MM_mul: *up = u0 * u1; break;\n    case MM_div:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_divi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_divu64(u0, u1);\n      break;\n    case MM_mod:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_modi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_modu64(u0, u1);\n      break;\n    case MM_pow:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_powi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_powu64(u0, u1);\n      break;\n    case MM_unm: *up = (uint64_t)-(int64_t)u0; break;\n    default: lua_assert(0); break;\n    }\n    lj_gc_check(L);\n    return 1;\n  }\n  return 0;\n}\n\n/* Handle ctype arithmetic metamethods. */\nstatic int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  cTValue *tv = NULL;\n  if (tviscdata(L->base)) {\n    CTypeID id = cdataV(L->base)->ctypeid;\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n    tv = lj_ctype_meta(cts, id, mm);\n  }\n  if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) {\n    CTypeID id = cdataV(L->base+1)->ctypeid;\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n    tv = lj_ctype_meta(cts, id, mm);\n  }\n  if (!tv) {\n    const char *repr[2];\n    int i, isenum = -1, isstr = -1;\n    if (mm == MM_eq) {  /* Equality checks never raise an error. */\n      int eq = ca->p[0] == ca->p[1];\n      setboolV(L->top-1, eq);\n      setboolV(&G(L)->tmptv2, eq);  /* Remember for trace recorder. */\n      return 1;\n    }\n    for (i = 0; i < 2; i++) {\n      if (ca->ct[i] && tviscdata(L->base+i)) {\n\tif (ctype_isenum(ca->ct[i]->info)) isenum = i;\n\trepr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL));\n      } else {\n\tif (tvisstr(&L->base[i])) isstr = i;\n\trepr[i] = lj_typename(&L->base[i]);\n      }\n    }\n    if ((isenum ^ isstr) == 1)\n      lj_err_callerv(L, LJ_ERR_FFI_BADCONV, repr[isstr], repr[isenum]);\n    lj_err_callerv(L, mm == MM_len ? LJ_ERR_FFI_BADLEN :\n\t\t      mm == MM_concat ? LJ_ERR_FFI_BADCONCAT :\n\t\t      mm < MM_add ? LJ_ERR_FFI_BADCOMP : LJ_ERR_FFI_BADARITH,\n\t\t   repr[0], repr[1]);\n  }\n  return lj_meta_tailcall(L, tv);\n}\n\n/* Arithmetic operators for cdata. */\nint lj_carith_op(lua_State *L, MMS mm)\n{\n  CTState *cts = ctype_cts(L);\n  CDArith ca;\n  if (carith_checkarg(L, cts, &ca)) {\n    if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) {\n      copyTV(L, &G(L)->tmptv2, L->top-1);  /* Remember for trace recorder. */\n      return 1;\n    }\n  }\n  return lj_carith_meta(L, cts, &ca, mm);\n}\n\n/* -- 64 bit bit operations helpers --------------------------------------- */\n\n#if LJ_64\n#define B64DEF(name) \\\n  static LJ_AINLINE uint64_t lj_carith_##name(uint64_t x, int32_t sh)\n#else\n/* Not inlined on 32 bit archs, since some of these are quite lengthy. */\n#define B64DEF(name) \\\n  uint64_t LJ_NOINLINE lj_carith_##name(uint64_t x, int32_t sh)\n#endif\n\nB64DEF(shl64) { return x << (sh&63); }\nB64DEF(shr64) { return x >> (sh&63); }\nB64DEF(sar64) { return (uint64_t)((int64_t)x >> (sh&63)); }\nB64DEF(rol64) { return lj_rol(x, (sh&63)); }\nB64DEF(ror64) { return lj_ror(x, (sh&63)); }\n\n#undef B64DEF\n\nuint64_t lj_carith_shift64(uint64_t x, int32_t sh, int op)\n{\n  switch (op) {\n  case IR_BSHL-IR_BSHL: x = lj_carith_shl64(x, sh); break;\n  case IR_BSHR-IR_BSHL: x = lj_carith_shr64(x, sh); break;\n  case IR_BSAR-IR_BSHL: x = lj_carith_sar64(x, sh); break;\n  case IR_BROL-IR_BSHL: x = lj_carith_rol64(x, sh); break;\n  case IR_BROR-IR_BSHL: x = lj_carith_ror64(x, sh); break;\n  default: lua_assert(0); break;\n  }\n  return x;\n}\n\n/* Equivalent to lj_lib_checkbit(), but handles cdata. */\nuint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id)\n{\n  TValue *o = L->base + narg-1;\n  if (o >= L->top) {\n  err:\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  } else if (LJ_LIKELY(tvisnumber(o))) {\n    /* Handled below. */\n  } else if (tviscdata(o)) {\n    CTState *cts = ctype_cts(L);\n    uint8_t *sp = (uint8_t *)cdataptr(cdataV(o));\n    CTypeID sid = cdataV(o)->ctypeid;\n    CType *s = ctype_get(cts, sid);\n    uint64_t x;\n    if (ctype_isref(s->info)) {\n      sp = *(void **)sp;\n      sid = ctype_cid(s->info);\n    }\n    s = ctype_raw(cts, sid);\n    if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n    if ((s->info & (CTMASK_NUM|CTF_BOOL|CTF_FP|CTF_UNSIGNED)) ==\n\tCTINFO(CT_NUM, CTF_UNSIGNED) && s->size == 8)\n      *id = CTID_UINT64;  /* Use uint64_t, since it has the highest rank. */\n    else if (!*id)\n      *id = CTID_INT64;  /* Use int64_t, unless already set. */\n    lj_cconv_ct_ct(cts, ctype_get(cts, *id), s,\n\t\t   (uint8_t *)&x, sp, CCF_ARG(narg));\n    return x;\n  } else if (!(tvisstr(o) && lj_strscan_number(strV(o), o))) {\n    goto err;\n  }\n  if (LJ_LIKELY(tvisint(o))) {\n    return (uint32_t)intV(o);\n  } else {\n    int32_t i = lj_num2bit(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return (uint32_t)i;\n  }\n}\n\n\n/* -- 64 bit integer arithmetic helpers ----------------------------------- */\n\n#if LJ_32 && LJ_HASJIT\n/* Signed/unsigned 64 bit multiplication. */\nint64_t lj_carith_mul64(int64_t a, int64_t b)\n{\n  return a * b;\n}\n#endif\n\n/* Unsigned 64 bit division. */\nuint64_t lj_carith_divu64(uint64_t a, uint64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  return a / b;\n}\n\n/* Signed 64 bit division. */\nint64_t lj_carith_divi64(int64_t a, int64_t b)\n{\n  if (b == 0 || (a == (int64_t)U64x(80000000,00000000) && b == -1))\n    return U64x(80000000,00000000);\n  return a / b;\n}\n\n/* Unsigned 64 bit modulo. */\nuint64_t lj_carith_modu64(uint64_t a, uint64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  return a % b;\n}\n\n/* Signed 64 bit modulo. */\nint64_t lj_carith_modi64(int64_t a, int64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  if (a == (int64_t)U64x(80000000,00000000) && b == -1) return 0;\n  return a % b;\n}\n\n/* Unsigned 64 bit x^k. */\nuint64_t lj_carith_powu64(uint64_t x, uint64_t k)\n{\n  uint64_t y;\n  if (k == 0)\n    return 1;\n  for (; (k & 1) == 0; k >>= 1) x *= x;\n  y = x;\n  if ((k >>= 1) != 0) {\n    for (;;) {\n      x *= x;\n      if (k == 1) break;\n      if (k & 1) y *= x;\n      k >>= 1;\n    }\n    y *= x;\n  }\n  return y;\n}\n\n/* Signed 64 bit x^k. */\nint64_t lj_carith_powi64(int64_t x, int64_t k)\n{\n  if (k == 0)\n    return 1;\n  if (k < 0) {\n    if (x == 0)\n      return U64x(7fffffff,ffffffff);\n    else if (x == 1)\n      return 1;\n    else if (x == -1)\n      return (k & 1) ? -1 : 1;\n    else\n      return 0;\n  }\n  return (int64_t)lj_carith_powu64((uint64_t)x, (uint64_t)k);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_carith.h",
    "content": "/*\n** C data arithmetic.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CARITH_H\n#define _LJ_CARITH_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\nLJ_FUNC int lj_carith_op(lua_State *L, MMS mm);\n\n#if LJ_32\nLJ_FUNC uint64_t lj_carith_shl64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_shr64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_sar64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_rol64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_ror64(uint64_t x, int32_t sh);\n#endif\nLJ_FUNC uint64_t lj_carith_shift64(uint64_t x, int32_t sh, int op);\nLJ_FUNC uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id);\n\n#if LJ_32 && LJ_HASJIT\nLJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);\n#endif\nLJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);\nLJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);\nLJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);\nLJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);\nLJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);\nLJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ccall.c",
    "content": "/*\n** FFI C call handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_ccall.h\"\n#include \"lj_trace.h\"\n\n/* Target-specific handling of register arguments. */\n#if LJ_TARGET_X86\n/* -- x86 calling conventions --------------------------------------------- */\n\n#if LJ_ABI_WIN\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs bigger than 8 by reference (on stack only). */ \\\n  cc->retref = (sz > 8); \\\n  if (cc->retref) cc->stack[nsp++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET\n\n#else\n\n#if LJ_TARGET_OSX\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size 1, 2, 4 or 8 in registers. */ \\\n  cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \\\n  if (cc->retref) { \\\n    if (ngpr < maxgpr) \\\n      cc->gpr[ngpr++] = (GPRArg)dp; \\\n    else \\\n      cc->stack[nsp++] = (GPRArg)dp; \\\n  } else {  /* Struct with single FP field ends up in FPR. */ \\\n    cc->resx87 = ccall_classify_struct(cts, ctr); \\\n  }\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \\\n  memcpy(dp, sp, ctr->size);\n\n#else\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference (in reg or on stack). */ \\\n  if (ngpr < maxgpr) \\\n    cc->gpr[ngpr++] = (GPRArg)dp; \\\n  else \\\n    cc->stack[nsp++] = (GPRArg)dp;\n\n#endif\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Return complex float in GPRs and complex double by reference. */ \\\n  cc->retref = (sz > 8); \\\n  if (cc->retref) { \\\n    if (ngpr < maxgpr) \\\n      cc->gpr[ngpr++] = (GPRArg)dp; \\\n    else \\\n      cc->stack[nsp++] = (GPRArg)dp; \\\n  }\n\n#endif\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!cc->retref) \\\n    *(int64_t *)dp = *(int64_t *)sp;  /* Copy complex float from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  ngpr = maxgpr;  /* Pass all structs by value on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 1;  /* Pass complex by value on stack. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (!isfp) {  /* Only non-FP values may be passed in registers. */ \\\n    if (n > 1) {  /* Anything > 32 bit is passed on the stack. */ \\\n      if (!LJ_ABI_WIN) ngpr = maxgpr;  /* Prevent reordering. */ \\\n    } else if (ngpr + 1 <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_X64 && LJ_ABI_WIN\n/* -- Windows/x64 calling conventions ------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \\\n  cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!cc->retref) \\\n    *(int64_t *)dp = *(int64_t *)sp;  /* Copy complex float from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \\\n  if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR;  /* Pass all other structs by reference. */ \\\n  }\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex float in a GPR and complex double by reference. */ \\\n  if (sz != 2*sizeof(float)) { \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR; \\\n  }\n\n/* Windows/x64 argument registers are strictly positional (use ngpr). */\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \\\n  } else { \\\n    if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \\\n  }\n\n#elif LJ_TARGET_X64\n/* -- POSIX/x64 calling conventions --------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  if (ccall_classify_struct(cts, ctr, rcl, 0)) { \\\n    cc->retref = 1;  /* Return struct by reference. */ \\\n    cc->gpr[ngpr++] = (GPRArg)dp; \\\n  } else { \\\n    cc->retref = 0;  /* Return small structs in registers. */ \\\n  }\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  ccall_classify_struct(cts, ctr, rcl, 0); \\\n  ccall_struct_ret(cc, rcl, dp, ctr->size);\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in one or two FPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPR. */ \\\n    *(int64_t *)dp = cc->fpr[0].l[0]; \\\n  } else {  /* Copy non-contiguous complex double from FPRs. */ \\\n    ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \\\n    ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \\\n  }\n\n#define CCALL_HANDLE_STRUCTARG \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  if (!ccall_classify_struct(cts, d, rcl, 0)) { \\\n    cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \\\n    if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \\\n    nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \\\n    continue; \\\n  }  /* Pass all other structs by value on stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 2;  /* Pass complex in FPRs or on stack. Needs postprocessing. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    int n2 = ctype_isvector(d->info) ? 1 : n; \\\n    if (nfpr + n2 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += n2; \\\n      goto done; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    /* Note that reordering is explicitly allowed in the x64 ABI. */ \\\n    if (n <= 2 && ngpr + n <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_ARM\n/* -- ARM calling conventions --------------------------------------------- */\n\n#if LJ_ABI_SOFTFP\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size <= 4 in a GPR. */ \\\n  cc->retref = !(sz <= 4); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  cc->retref = 1;  /* Return all complex values by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  UNUSED(dp); /* Nothing to do. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_REGARG_FP1\n#define CCALL_HANDLE_REGARG_FP2\n\n#else\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = !ccall_classify_struct(cts, ctr, ct); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \\\n  memcpy(dp, sp, ctr->size);\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  if (!(ct->info & CTF_VARARG)) cc->retref = 0;  /* Return complex in FPRs. */\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size);\n\n#define CCALL_HANDLE_STRUCTARG \\\n  isfp = (ccall_classify_struct(cts, d, ct) > 1);\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 1;  /* Pass complex by value in FPRs or on stack. */\n\n#define CCALL_HANDLE_REGARG_FP1 \\\n  if (isfp && !(ct->info & CTF_VARARG)) { \\\n    if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \\\n      if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \\\n\tdp = &cc->fpr[nfpr]; \\\n\tnfpr += (n >> 1); \\\n\tgoto done; \\\n      } \\\n    } else { \\\n      if (sz > 1 && fprodd != nfpr) fprodd = 0; \\\n      if (fprodd) { \\\n\tif (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \\\n\t  dp = (void *)&cc->fpr[fprodd-1].f[1]; \\\n\t  nfpr += (n >> 1); \\\n\t  if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \\\n\t  goto done; \\\n\t} \\\n      } else { \\\n\tif (2*nfpr+n <= 2*CCALL_NARG_FPR) { \\\n\t  dp = (void *)&cc->fpr[nfpr]; \\\n\t  nfpr += (n >> 1); \\\n\t  if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \\\n\t  goto done; \\\n\t} \\\n      } \\\n    } \\\n    fprodd = 0;  /* No reordering after the first FP value is on stack. */ \\\n  } else {\n\n#define CCALL_HANDLE_REGARG_FP2\t}\n\n#endif\n\n#define CCALL_HANDLE_REGARG \\\n  CCALL_HANDLE_REGARG_FP1 \\\n  if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \\\n    if (ngpr < maxgpr) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  } \\\n  if (ngpr < maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    if (ngpr + n > maxgpr) { \\\n      nsp += ngpr + n - maxgpr;  /* Assumes contiguous gpr/stack fields. */ \\\n      if (nsp > CCALL_MAXSTACK) goto err_nyi;  /* Too many arguments. */ \\\n      ngpr = maxgpr; \\\n    } else { \\\n      ngpr += n; \\\n    } \\\n    goto done; \\\n  } CCALL_HANDLE_REGARG_FP2\n\n#define CCALL_HANDLE_RET \\\n  if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0];\n\n#elif LJ_TARGET_ARM64\n/* -- ARM64 calling conventions ------------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = !ccall_classify_struct(cts, ctr); \\\n  if (cc->retref) cc->retp = dp;\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  unsigned int cl = ccall_classify_struct(cts, ctr); \\\n  if ((cl & 4)) { /* Combine float HFA from separate registers. */ \\\n    CTSize i = (cl >> 8) - 1; \\\n    do { ((uint32_t *)dp)[i] = cc->fpr[i].u32; } while (i--); \\\n  } else { \\\n    if (cl > 1) sp = (uint8_t *)&cc->fpr[0]; \\\n    memcpy(dp, sp, ctr->size); \\\n  }\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in one or two FPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPRs. */ \\\n    ((float *)dp)[0] = cc->fpr[0].f; \\\n    ((float *)dp)[1] = cc->fpr[1].f; \\\n  } else {  /* Copy complex double from FPRs. */ \\\n    ((double *)dp)[0] = cc->fpr[0].d; \\\n    ((double *)dp)[1] = cc->fpr[1].d; \\\n  }\n\n#define CCALL_HANDLE_STRUCTARG \\\n  unsigned int cl = ccall_classify_struct(cts, d); \\\n  if (cl == 0) {  /* Pass struct by reference. */ \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR; \\\n  } else if (cl > 1) {  /* Pass struct in FPRs or on stack. */ \\\n    isfp = (cl & 4) ? 2 : 1; \\\n  }  /* else: Pass struct in GPRs or on stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in separate (!) FPRs or on stack. */ \\\n  isfp = ctr->size == 2*sizeof(float) ? 2 : 1;\n\n#define CCALL_HANDLE_REGARG \\\n  if (LJ_TARGET_IOS && isva) { \\\n    /* IOS: All variadic arguments are on the stack. */ \\\n  } else if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    int n2 = ctype_isvector(d->info) ? 1 : n*isfp; \\\n    if (nfpr + n2 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += n2; \\\n      goto done; \\\n    } else { \\\n      nfpr = CCALL_NARG_FPR;  /* Prevent reordering. */ \\\n      if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    if (!LJ_TARGET_IOS && (d->info & CTF_ALIGN) > CTALIGN_PTR) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n    if (ngpr + n <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } else { \\\n      ngpr = maxgpr;  /* Prevent reordering. */ \\\n      if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \\\n    } \\\n  }\n\n#elif LJ_TARGET_PPC\n/* -- PPC calling conventions --------------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in 2 or 4 GPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  memcpy(dp, sp, ctr->size);  /* Copy complex from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n  sz = CTSIZE_PTR;  /* Pass all structs by reference. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += 1; \\\n      d = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */ \\\n      goto done; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    if (n > 1) { \\\n      lua_assert(n == 2 || n == 4);  /* int64_t or complex (float). */ \\\n      if (ctype_isinteger(d->info)) \\\n\tngpr = (ngpr + 1u) & ~1u;  /* Align int64_t to regpair. */ \\\n      else if (ngpr + n > maxgpr) \\\n\tngpr = maxgpr;  /* Prevent reordering. */ \\\n    } \\\n    if (ngpr + n <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    ctr = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */\n\n#elif LJ_TARGET_MIPS\n/* -- MIPS calling conventions -------------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in 1 or 2 FPRs. */ \\\n  cc->retref = 0;\n\n#if LJ_ABI_SOFTFP\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n    ((intptr_t *)dp)[1] = cc->gpr[1]; \\\n  } else {  /* Copy complex double from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n    ((intptr_t *)dp)[1] = cc->gpr[1]; \\\n    ((intptr_t *)dp)[2] = cc->gpr[2]; \\\n    ((intptr_t *)dp)[3] = cc->gpr[3]; \\\n  }\n#else\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPRs. */ \\\n    ((float *)dp)[0] = cc->fpr[0].f; \\\n    ((float *)dp)[1] = cc->fpr[1].f; \\\n  } else {  /* Copy complex double from FPRs. */ \\\n    ((double *)dp)[0] = cc->fpr[0].d; \\\n    ((double *)dp)[1] = cc->fpr[1].d; \\\n  }\n#endif\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_GPR \\\n  if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \\\n    ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr < maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    if (ngpr + n > maxgpr) { \\\n     nsp += ngpr + n - maxgpr;  /* Assumes contiguous gpr/stack fields. */ \\\n     if (nsp > CCALL_MAXSTACK) goto err_nyi;  /* Too many arguments. */ \\\n     ngpr = maxgpr; \\\n    } else { \\\n     ngpr += n; \\\n    } \\\n    goto done; \\\n  }\n\n#if !LJ_ABI_SOFTFP\t/* MIPS32 hard-float */\n#define CCALL_HANDLE_REGARG \\\n  if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \\\n    /* Try to pass argument in FPRs. */ \\\n    dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \\\n    nfpr++; ngpr += n; \\\n    goto done; \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    nfpr = CCALL_NARG_FPR; \\\n    CCALL_HANDLE_GPR \\\n  }\n#else\t\t\t/* MIPS32 soft-float */\n#define CCALL_HANDLE_REGARG CCALL_HANDLE_GPR\n#endif\n\n#if !LJ_ABI_SOFTFP\n/* On MIPS64 soft-float, position of float return values is endian-dependant. */\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    sp = (uint8_t *)&cc->fpr[0].f;\n#endif\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n#ifndef CCALL_HANDLE_STRUCTRET2\n#define CCALL_HANDLE_STRUCTRET2 \\\n  memcpy(dp, sp, ctr->size);  /* Copy struct return value from GPRs. */\n#endif\n\n/* -- x86 OSX ABI struct classification ----------------------------------- */\n\n#if LJ_TARGET_X86 && LJ_TARGET_OSX\n\n/* Check for struct with single FP field. */\nstatic int ccall_classify_struct(CTState *cts, CType *ct)\n{\n  CTSize sz = ct->size;\n  if (!(sz == sizeof(float) || sz == sizeof(double))) return 0;\n  if ((ct->info & CTF_UNION)) return 0;\n  while (ct->sib) {\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      CType *sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tif (sct->size == sz)\n\t  return (sz >> 2);  /* Return 1 for float or 2 for double. */\n      } else if (ctype_isstruct(sct->info)) {\n\tif (sct->size)\n\t  return ccall_classify_struct(cts, sct);\n      } else {\n\tbreak;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      break;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      CType *sct = ctype_rawchild(cts, ct);\n      if (sct->size)\n\treturn ccall_classify_struct(cts, sct);\n    }\n  }\n  return 0;\n}\n\n#endif\n\n/* -- x64 struct classification ------------------------------------------- */\n\n#if LJ_TARGET_X64 && !LJ_ABI_WIN\n\n/* Register classes for x64 struct classification. */\n#define CCALL_RCL_INT\t1\n#define CCALL_RCL_SSE\t2\n#define CCALL_RCL_MEM\t4\n/* NYI: classify vectors. */\n\nstatic int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs);\n\n/* Classify a C type. */\nstatic void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs)\n{\n  if (ctype_isarray(ct->info)) {\n    CType *cct = ctype_rawchild(cts, ct);\n    CTSize eofs, esz = cct->size, asz = ct->size;\n    for (eofs = 0; eofs < asz; eofs += esz)\n      ccall_classify_ct(cts, cct, rcl, ofs+eofs);\n  } else if (ctype_isstruct(ct->info)) {\n    ccall_classify_struct(cts, ct, rcl, ofs);\n  } else {\n    int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT;\n    lua_assert(ctype_hassize(ct->info));\n    if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM;  /* Unaligned. */\n    rcl[(ofs >= 8)] |= cl;\n  }\n}\n\n/* Recursively classify a struct based on its fields. */\nstatic int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs)\n{\n  if (ct->size > 16) return CCALL_RCL_MEM;  /* Too big, gets memory class. */\n  while (ct->sib) {\n    CTSize fofs;\n    ct = ctype_get(cts, ct->sib);\n    fofs = ofs+ct->size;\n    if (ctype_isfield(ct->info))\n      ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs);\n    else if (ctype_isbitfield(ct->info))\n      rcl[(fofs >= 8)] |= CCALL_RCL_INT;  /* NYI: unaligned bitfields? */\n    else if (ctype_isxattrib(ct->info, CTA_SUBTYPE))\n      ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs);\n  }\n  return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM);  /* Memory class? */\n}\n\n/* Try to split up a small struct into registers. */\nstatic int ccall_struct_reg(CCallState *cc, GPRArg *dp, int *rcl)\n{\n  MSize ngpr = cc->ngpr, nfpr = cc->nfpr;\n  uint32_t i;\n  for (i = 0; i < 2; i++) {\n    lua_assert(!(rcl[i] & CCALL_RCL_MEM));\n    if ((rcl[i] & CCALL_RCL_INT)) {  /* Integer class takes precedence. */\n      if (ngpr >= CCALL_NARG_GPR) return 1;  /* Register overflow. */\n      cc->gpr[ngpr++] = dp[i];\n    } else if ((rcl[i] & CCALL_RCL_SSE)) {\n      if (nfpr >= CCALL_NARG_FPR) return 1;  /* Register overflow. */\n      cc->fpr[nfpr++].l[0] = dp[i];\n    }\n  }\n  cc->ngpr = ngpr; cc->nfpr = nfpr;\n  return 0;  /* Ok. */\n}\n\n/* Pass a small struct argument. */\nstatic int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl,\n\t\t\t    TValue *o, int narg)\n{\n  GPRArg dp[2];\n  dp[0] = dp[1] = 0;\n  /* Convert to temp. struct. */\n  lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));\n  if (ccall_struct_reg(cc, dp, rcl)) {  /* Register overflow? Pass on stack. */\n    MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1;\n    if (nsp + n > CCALL_MAXSTACK) return 1;  /* Too many arguments. */\n    cc->nsp = nsp + n;\n    memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR);\n  }\n  return 0;  /* Ok. */\n}\n\n/* Combine returned small struct. */\nstatic void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz)\n{\n  GPRArg sp[2];\n  MSize ngpr = 0, nfpr = 0;\n  uint32_t i;\n  for (i = 0; i < 2; i++) {\n    if ((rcl[i] & CCALL_RCL_INT)) {  /* Integer class takes precedence. */\n      sp[i] = cc->gpr[ngpr++];\n    } else if ((rcl[i] & CCALL_RCL_SSE)) {\n      sp[i] = cc->fpr[nfpr++].l[0];\n    }\n  }\n  memcpy(dp, sp, sz);\n}\n#endif\n\n/* -- ARM hard-float ABI struct classification ---------------------------- */\n\n#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP\n\n/* Classify a struct based on its fields. */\nstatic unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf)\n{\n  CTSize sz = ct->size;\n  unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);\n  if ((ctf->info & CTF_VARARG)) goto noth;\n  while (ct->sib) {\n    CType *sct;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tr |= sct->size;\n\tif (!isu) n++; else if (n == 0) n = 1;\n      } else if (ctype_iscomplex(sct->info)) {\n\tr |= (sct->size >> 1);\n\tif (!isu) n += 2; else if (n < 2) n = 2;\n      } else if (ctype_isstruct(sct->info)) {\n\tgoto substruct;\n      } else {\n\tgoto noth;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      goto noth;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      sct = ctype_rawchild(cts, ct);\n    substruct:\n      if (sct->size > 0) {\n\tunsigned int s = ccall_classify_struct(cts, sct, ctf);\n\tif (s <= 1) goto noth;\n\tr |= (s & 255);\n\tif (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);\n      }\n    }\n  }\n  if ((r == 4 || r == 8) && n <= 4)\n    return r + (n << 8);\nnoth:  /* Not a homogeneous float/double aggregate. */\n  return (sz <= 4);  /* Return structs of size <= 4 in a GPR. */\n}\n\n#endif\n\n/* -- ARM64 ABI struct classification ------------------------------------- */\n\n#if LJ_TARGET_ARM64\n\n/* Classify a struct based on its fields. */\nstatic unsigned int ccall_classify_struct(CTState *cts, CType *ct)\n{\n  CTSize sz = ct->size;\n  unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);\n  while (ct->sib) {\n    CType *sct;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tr |= sct->size;\n\tif (!isu) n++; else if (n == 0) n = 1;\n      } else if (ctype_iscomplex(sct->info)) {\n\tr |= (sct->size >> 1);\n\tif (!isu) n += 2; else if (n < 2) n = 2;\n      } else if (ctype_isstruct(sct->info)) {\n\tgoto substruct;\n      } else {\n\tgoto noth;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      goto noth;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      sct = ctype_rawchild(cts, ct);\n    substruct:\n      if (sct->size > 0) {\n\tunsigned int s = ccall_classify_struct(cts, sct);\n\tif (s <= 1) goto noth;\n\tr |= (s & 255);\n\tif (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);\n      }\n    }\n  }\n  if ((r == 4 || r == 8) && n <= 4)\n    return r + (n << 8);\nnoth:  /* Not a homogeneous float/double aggregate. */\n  return (sz <= 16);  /* Return structs of size <= 16 in GPRs. */\n}\n\n#endif\n\n/* -- Common C call handling ---------------------------------------------- */\n\n/* Infer the destination CTypeID for a vararg argument. */\nCTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o)\n{\n  if (tvisnumber(o)) {\n    return CTID_DOUBLE;\n  } else if (tviscdata(o)) {\n    CTypeID id = cdataV(o)->ctypeid;\n    CType *s = ctype_get(cts, id);\n    if (ctype_isrefarray(s->info)) {\n      return lj_ctype_intern(cts,\n\t       CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR);\n    } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) {\n      /* NYI: how to pass a struct by value in a vararg argument? */\n      return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR);\n    } else if (ctype_isfp(s->info) && s->size == sizeof(float)) {\n      return CTID_DOUBLE;\n    } else {\n      return id;\n    }\n  } else if (tvisstr(o)) {\n    return CTID_P_CCHAR;\n  } else if (tvisbool(o)) {\n    return CTID_BOOL;\n  } else {\n    return CTID_P_VOID;\n  }\n}\n\n/* Setup arguments for C call. */\nstatic int ccall_set_args(lua_State *L, CTState *cts, CType *ct,\n\t\t\t  CCallState *cc)\n{\n  int gcsteps = 0;\n  TValue *o, *top = L->top;\n  CTypeID fid;\n  CType *ctr;\n  MSize maxgpr, ngpr = 0, nsp = 0, narg;\n#if CCALL_NARG_FPR\n  MSize nfpr = 0;\n#if LJ_TARGET_ARM\n  MSize fprodd = 0;\n#endif\n#endif\n\n  /* Clear unused regs to get some determinism in case of misdeclaration. */\n  memset(cc->gpr, 0, sizeof(cc->gpr));\n#if CCALL_NUM_FPR\n  memset(cc->fpr, 0, sizeof(cc->fpr));\n#endif\n\n#if LJ_TARGET_X86\n  /* x86 has several different calling conventions. */\n  cc->resx87 = 0;\n  switch (ctype_cconv(ct->info)) {\n  case CTCC_FASTCALL: maxgpr = 2; break;\n  case CTCC_THISCALL: maxgpr = 1; break;\n  default: maxgpr = 0; break;\n  }\n#else\n  maxgpr = CCALL_NARG_GPR;\n#endif\n\n  /* Perform required setup for some result types. */\n  ctr = ctype_rawchild(cts, ct);\n  if (ctype_isvector(ctr->info)) {\n    if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16)))\n      goto err_nyi;\n  } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) {\n    /* Preallocate cdata object and anchor it after arguments. */\n    CTSize sz = ctr->size;\n    GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz);\n    void *dp = cdataptr(cd);\n    setcdataV(L, L->top++, cd);\n    if (ctype_isstruct(ctr->info)) {\n      CCALL_HANDLE_STRUCTRET\n    } else {\n      CCALL_HANDLE_COMPLEXRET\n    }\n#if LJ_TARGET_X86\n  } else if (ctype_isfp(ctr->info)) {\n    cc->resx87 = ctr->size == sizeof(float) ? 1 : 2;\n#endif\n  }\n\n  /* Skip initial attributes. */\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) break;\n    fid = ctf->sib;\n  }\n\n  /* Walk through all passed arguments. */\n  for (o = L->base+1, narg = 1; o < top; o++, narg++) {\n    CTypeID did;\n    CType *d;\n    CTSize sz;\n    MSize n, isfp = 0, isva = 0;\n    void *dp, *rp = NULL;\n\n    if (fid) {  /* Get argument type from field. */\n      CType *ctf = ctype_get(cts, fid);\n      fid = ctf->sib;\n      lua_assert(ctype_isfield(ctf->info));\n      did = ctype_cid(ctf->info);\n    } else {\n      if (!(ct->info & CTF_VARARG))\n\tlj_err_caller(L, LJ_ERR_FFI_NUMARG);  /* Too many arguments. */\n      did = lj_ccall_ctid_vararg(cts, o);  /* Infer vararg type. */\n      isva = 1;\n    }\n    d = ctype_raw(cts, did);\n    sz = d->size;\n\n    /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */\n    if (ctype_isnum(d->info)) {\n      if (sz > 8) goto err_nyi;\n      if ((d->info & CTF_FP))\n\tisfp = 1;\n    } else if (ctype_isvector(d->info)) {\n      if (CCALL_VECTOR_REG && (sz == 8 || sz == 16))\n\tisfp = 1;\n      else\n\tgoto err_nyi;\n    } else if (ctype_isstruct(d->info)) {\n      CCALL_HANDLE_STRUCTARG\n    } else if (ctype_iscomplex(d->info)) {\n      CCALL_HANDLE_COMPLEXARG\n    } else {\n      sz = CTSIZE_PTR;\n    }\n    sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);\n    n = sz / CTSIZE_PTR;  /* Number of GPRs or stack slots needed. */\n\n    CCALL_HANDLE_REGARG  /* Handle register arguments. */\n\n    /* Otherwise pass argument on stack. */\n    if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) {\n      MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1;\n      nsp = (nsp + align) & ~align;  /* Align argument on stack. */\n    }\n    if (nsp + n > CCALL_MAXSTACK) {  /* Too many arguments. */\n    err_nyi:\n      lj_err_caller(L, LJ_ERR_FFI_NYICALL);\n    }\n    dp = &cc->stack[nsp];\n    nsp += n;\n    isva = 0;\n\n  done:\n    if (rp) {  /* Pass by reference. */\n      gcsteps++;\n      *(void **)dp = rp;\n      dp = rp;\n    }\n    lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));\n    /* Extend passed integers to 32 bits at least. */\n    if (ctype_isinteger_or_bool(d->info) && d->size < 4) {\n      if (d->info & CTF_UNSIGNED)\n\t*(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp :\n\t\t\t\t\t (uint32_t)*(uint16_t *)dp;\n      else\n\t*(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp :\n\t\t\t\t\t(int32_t)*(int16_t *)dp;\n    }\n#if LJ_TARGET_X64 && LJ_ABI_WIN\n    if (isva) {  /* Windows/x64 mirrors varargs in both register sets. */\n      if (nfpr == ngpr)\n\tcc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0];\n      else\n\tcc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1];\n    }\n#else\n    UNUSED(isva);\n#endif\n#if LJ_TARGET_X64 && !LJ_ABI_WIN\n    if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) {\n      cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1];  /* Split complex double. */\n      cc->fpr[nfpr-2].d[1] = 0;\n    }\n#elif LJ_TARGET_ARM64\n    if (isfp == 2 && (uint8_t *)dp < (uint8_t *)cc->stack) {\n      /* Split float HFA or complex float into separate registers. */\n      CTSize i = (sz >> 2) - 1;\n      do { ((uint64_t *)dp)[i] = ((uint32_t *)dp)[i]; } while (i--);\n    }\n#else\n    UNUSED(isfp);\n#endif\n  }\n  if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG);  /* Too few arguments. */\n\n#if LJ_TARGET_X64 || LJ_TARGET_PPC\n  cc->nfpr = nfpr;  /* Required for vararg functions. */\n#endif\n  cc->nsp = nsp;\n  cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR;\n  if (nsp > CCALL_SPS_FREE)\n    cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u);\n  return gcsteps;\n}\n\n/* Get results from C call. */\nstatic int ccall_get_results(lua_State *L, CTState *cts, CType *ct,\n\t\t\t     CCallState *cc, int *ret)\n{\n  CType *ctr = ctype_rawchild(cts, ct);\n  uint8_t *sp = (uint8_t *)&cc->gpr[0];\n  if (ctype_isvoid(ctr->info)) {\n    *ret = 0;  /* Zero results. */\n    return 0;  /* No additional GC step. */\n  }\n  *ret = 1;  /* One result. */\n  if (ctype_isstruct(ctr->info)) {\n    /* Return cdata object which is already on top of stack. */\n    if (!cc->retref) {\n      void *dp = cdataptr(cdataV(L->top-1));  /* Use preallocated object. */\n      CCALL_HANDLE_STRUCTRET2\n    }\n    return 1;  /* One GC step. */\n  }\n  if (ctype_iscomplex(ctr->info)) {\n    /* Return cdata object which is already on top of stack. */\n    void *dp = cdataptr(cdataV(L->top-1));  /* Use preallocated object. */\n    CCALL_HANDLE_COMPLEXRET2\n    return 1;  /* One GC step. */\n  }\n  if (LJ_BE && ctype_isinteger_or_bool(ctr->info) && ctr->size < CTSIZE_PTR)\n    sp += (CTSIZE_PTR - ctr->size);\n#if CCALL_NUM_FPR\n  if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info))\n    sp = (uint8_t *)&cc->fpr[0];\n#endif\n#ifdef CCALL_HANDLE_RET\n  CCALL_HANDLE_RET\n#endif\n  /* No reference types end up here, so there's no need for the CTypeID. */\n  lua_assert(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info)));\n  return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp);\n}\n\n/* Call C function. */\nint lj_ccall_func(lua_State *L, GCcdata *cd)\n{\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  CTSize sz = CTSIZE_PTR;\n  if (ctype_isptr(ct->info)) {\n    sz = ct->size;\n    ct = ctype_rawchild(cts, ct);\n  }\n  if (ctype_isfunc(ct->info)) {\n    CCallState cc;\n    int gcsteps, ret;\n    cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz);\n    gcsteps = ccall_set_args(L, cts, ct, &cc);\n    ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab);\n    cts->cb.slot = ~0u;\n    lj_vm_ffi_call(&cc);\n    if (cts->cb.slot != ~0u) {  /* Blacklist function that called a callback. */\n      TValue tv;\n      setlightudV(&tv, (void *)cc.func);\n      setboolV(lj_tab_set(L, cts->miscmap, &tv), 1);\n    }\n    ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab);  /* May be reallocated. */\n    gcsteps += ccall_get_results(L, cts, ct, &cc, &ret);\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n    /* Automatically detect __stdcall and fix up C function declaration. */\n    if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) {\n      CTF_INSERT(ct->info, CCONV, CTCC_STDCALL);\n      lj_trace_abort(G(L));\n    }\n#endif\n    while (gcsteps-- > 0)\n      lj_gc_check(L);\n    return ret;\n  }\n  return -1;  /* Not a function. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ccall.h",
    "content": "/*\n** FFI C call handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCALL_H\n#define _LJ_CCALL_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* -- C calling conventions ----------------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n\n#if LJ_TARGET_X86\n#define CCALL_NARG_GPR\t\t2\t/* For fastcall arguments. */\n#define CCALL_NARG_FPR\t\t0\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t1\t/* For FP results on x87 stack. */\n#define CCALL_ALIGN_STACKARG\t0\t/* Don't align argument on stack. */\n#elif LJ_ABI_WIN\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NARG_FPR\t\t4\n#define CCALL_NRET_GPR\t\t1\n#define CCALL_NRET_FPR\t\t1\n#define CCALL_SPS_EXTRA\t\t4\n#else\n#define CCALL_NARG_GPR\t\t6\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t2\n#define CCALL_VECTOR_REG\t1\t/* Pass vectors in registers. */\n#endif\n\n#define CCALL_SPS_FREE\t\t1\n#define CCALL_ALIGN_CALLSTATE\t16\n\ntypedef LJ_ALIGN(16) union FPRArg {\n  double d[2];\n  float f[4];\n  uint8_t b[16];\n  uint16_t s[8];\n  int i[4];\n  int64_t l[2];\n} FPRArg;\n\ntypedef intptr_t GPRArg;\n\n#elif LJ_TARGET_ARM\n\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NRET_GPR\t\t2\t/* For softfp double. */\n#if LJ_ABI_SOFTFP\n#define CCALL_NARG_FPR\t\t0\n#define CCALL_NRET_FPR\t\t0\n#else\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_FPR\t\t4\n#endif\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  float f[2];\n} FPRArg;\n\n#elif LJ_TARGET_ARM64\n\n#define CCALL_NARG_GPR\t\t8\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_FPR\t\t4\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  float f;\n  uint32_t u32;\n} FPRArg;\n\n#elif LJ_TARGET_PPC\n\n#define CCALL_NARG_GPR\t\t8\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_GPR\t\t4\t/* For complex double. */\n#define CCALL_NRET_FPR\t\t1\n#define CCALL_SPS_EXTRA\t\t4\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef double FPRArg;\n\n#elif LJ_TARGET_MIPS\n\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NARG_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 2)\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 2)\n#define CCALL_SPS_EXTRA\t\t7\n#define CCALL_SPS_FREE\t\t1\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  struct { LJ_ENDIAN_LOHI(float f; , float g;) };\n} FPRArg;\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n#ifndef CCALL_SPS_EXTRA\n#define CCALL_SPS_EXTRA\t\t0\n#endif\n#ifndef CCALL_VECTOR_REG\n#define CCALL_VECTOR_REG\t0\n#endif\n#ifndef CCALL_ALIGN_STACKARG\n#define CCALL_ALIGN_STACKARG\t1\n#endif\n#ifndef CCALL_ALIGN_CALLSTATE\n#define CCALL_ALIGN_CALLSTATE\t8\n#endif\n\n#define CCALL_NUM_GPR \\\n  (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR)\n#define CCALL_NUM_FPR \\\n  (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR)\n\n/* Check against constants in lj_ctype.h. */\nLJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR);\nLJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR);\n\n#define CCALL_MAXSTACK\t\t32\n\n/* -- C call state -------------------------------------------------------- */\n\ntypedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState {\n  void (*func)(void);\t\t/* Pointer to called function. */\n  uint32_t spadj;\t\t/* Stack pointer adjustment. */\n  uint8_t nsp;\t\t\t/* Number of stack slots. */\n  uint8_t retref;\t\t/* Return value by reference. */\n#if LJ_TARGET_X64\n  uint8_t ngpr;\t\t\t/* Number of arguments in GPRs. */\n  uint8_t nfpr;\t\t\t/* Number of arguments in FPRs. */\n#elif LJ_TARGET_X86\n  uint8_t resx87;\t\t/* Result on x87 stack: 1:float, 2:double. */\n#elif LJ_TARGET_ARM64\n  void *retp;\t\t\t/* Aggregate return pointer in x8. */\n#elif LJ_TARGET_PPC\n  uint8_t nfpr;\t\t\t/* Number of arguments in FPRs. */\n#endif\n#if LJ_32\n  int32_t align1;\n#endif\n#if CCALL_NUM_FPR\n  FPRArg fpr[CCALL_NUM_FPR];\t/* Arguments/results in FPRs. */\n#endif\n  GPRArg gpr[CCALL_NUM_GPR];\t/* Arguments/results in GPRs. */\n  GPRArg stack[CCALL_MAXSTACK];\t/* Stack slots. */\n} CCallState;\n\n/* -- C call handling ----------------------------------------------------- */\n\n/* Really belongs to lj_vm.h. */\nLJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);\n\nLJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);\nLJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ccallback.c",
    "content": "/*\n** FFI C callback handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_target.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n\n/* -- Target-specific handling of callback slots -------------------------- */\n\n#define CALLBACK_MCODE_SIZE\t(LJ_PAGESIZE * LJ_NUM_CBPAGE)\n\n#if LJ_OS_NOJIT\n\n/* Callbacks disabled. */\n#define CALLBACK_SLOT2OFS(slot)\t(0*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t(0*(ofs))\n#define CALLBACK_MAX_SLOT\t0\n\n#elif LJ_TARGET_X86ORX64\n\n#define CALLBACK_MCODE_HEAD\t(LJ_64 ? 8 : 0)\n#define CALLBACK_MCODE_GROUP\t(-2+1+2+(LJ_GC64 ? 10 : 5)+(LJ_64 ? 6 : 5))\n\n#define CALLBACK_SLOT2OFS(slot) \\\n  (CALLBACK_MCODE_HEAD + CALLBACK_MCODE_GROUP*((slot)/32) + 4*(slot))\n\nstatic MSize CALLBACK_OFS2SLOT(MSize ofs)\n{\n  MSize group;\n  ofs -= CALLBACK_MCODE_HEAD;\n  group = ofs / (32*4 + CALLBACK_MCODE_GROUP);\n  return (ofs % (32*4 + CALLBACK_MCODE_GROUP))/4 + group*32;\n}\n\n#define CALLBACK_MAX_SLOT \\\n  (((CALLBACK_MCODE_SIZE-CALLBACK_MCODE_HEAD)/(CALLBACK_MCODE_GROUP+4*32))*32)\n\n#elif LJ_TARGET_ARM\n\n#define CALLBACK_MCODE_HEAD\t\t32\n\n#elif LJ_TARGET_ARM64\n\n#define CALLBACK_MCODE_HEAD\t\t32\n\n#elif LJ_TARGET_PPC\n\n#define CALLBACK_MCODE_HEAD\t\t24\n\n#elif LJ_TARGET_MIPS\n\n#define CALLBACK_MCODE_HEAD\t\t24\n\n#else\n\n/* Missing support for this architecture. */\n#define CALLBACK_SLOT2OFS(slot)\t(0*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t(0*(ofs))\n#define CALLBACK_MAX_SLOT\t0\n\n#endif\n\n#ifndef CALLBACK_SLOT2OFS\n#define CALLBACK_SLOT2OFS(slot)\t\t(CALLBACK_MCODE_HEAD + 8*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t\t(((ofs)-CALLBACK_MCODE_HEAD)/8)\n#define CALLBACK_MAX_SLOT\t\t(CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))\n#endif\n\n/* Convert callback slot number to callback function pointer. */\nstatic void *callback_slot2ptr(CTState *cts, MSize slot)\n{\n  return (uint8_t *)cts->cb.mcode + CALLBACK_SLOT2OFS(slot);\n}\n\n/* Convert callback function pointer to slot number. */\nMSize lj_ccallback_ptr2slot(CTState *cts, void *p)\n{\n  uintptr_t ofs = (uintptr_t)((uint8_t *)p -(uint8_t *)cts->cb.mcode);\n  if (ofs < CALLBACK_MCODE_SIZE) {\n    MSize slot = CALLBACK_OFS2SLOT((MSize)ofs);\n    if (CALLBACK_SLOT2OFS(slot) == (MSize)ofs)\n      return slot;\n  }\n  return ~0u;  /* Not a known callback function pointer. */\n}\n\n/* Initialize machine code for callback function pointers. */\n#if LJ_OS_NOJIT\n/* Disabled callback support. */\n#define callback_mcode_init(g, p)\tUNUSED(p)\n#elif LJ_TARGET_X86ORX64\nstatic void callback_mcode_init(global_State *g, uint8_t *page)\n{\n  uint8_t *p = page;\n  uint8_t *target = (uint8_t *)(void *)lj_vm_ffi_callback;\n  MSize slot;\n#if LJ_64\n  *(void **)p = target; p += 8;\n#endif\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    /* mov al, slot; jmp group */\n    *p++ = XI_MOVrib | RID_EAX; *p++ = (uint8_t)slot;\n    if ((slot & 31) == 31 || slot == CALLBACK_MAX_SLOT-1) {\n      /* push ebp/rbp; mov ah, slot>>8; mov ebp, &g. */\n      *p++ = XI_PUSH + RID_EBP;\n      *p++ = XI_MOVrib | (RID_EAX+4); *p++ = (uint8_t)(slot >> 8);\n#if LJ_GC64\n      *p++ = 0x48; *p++ = XI_MOVri | RID_EBP;\n      *(uint64_t *)p = (uint64_t)(g); p += 8;\n#else\n      *p++ = XI_MOVri | RID_EBP;\n      *(int32_t *)p = i32ptr(g); p += 4;\n#endif\n#if LJ_64\n      /* jmp [rip-pageofs] where lj_vm_ffi_callback is stored. */\n      *p++ = XI_GROUP5; *p++ = XM_OFS0 + (XOg_JMP<<3) + RID_EBP;\n      *(int32_t *)p = (int32_t)(page-(p+4)); p += 4;\n#else\n      /* jmp lj_vm_ffi_callback. */\n      *p++ = XI_JMP; *(int32_t *)p = target-(p+4); p += 4;\n#endif\n    } else {\n      *p++ = XI_JMPs; *p++ = (uint8_t)((2+2)*(31-(slot&31)) - 2);\n    }\n  }\n  lua_assert(p - page <= CALLBACK_MCODE_SIZE);\n}\n#elif LJ_TARGET_ARM\nstatic void callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  /* This must match with the saveregs macro in buildvm_arm.dasc. */\n  *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC);\n  *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR);\n  *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD;\n  *p++ = ARMI_STR|ARMI_LS_P|ARMI_LS_W|ARMF_D(RID_R12)|ARMF_N(RID_SP)|(CFRAME_SIZE-4*9);\n  *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_R12)|ARMF_N(RID_PC);\n  *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_PC)|ARMF_N(RID_PC);\n  *p++ = u32ptr(g);\n  *p++ = u32ptr(target);\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = ARMI_MOV|ARMF_D(RID_R12)|ARMF_M(RID_PC);\n    *p = ARMI_B | ((page-p-2) & 0x00ffffffu);\n    p++;\n  }\n  lua_assert(p - page <= CALLBACK_MCODE_SIZE);\n}\n#elif LJ_TARGET_ARM64\nstatic void callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  *p++ = A64I_LDRLx | A64F_D(RID_X11) | A64F_S19(4);\n  *p++ = A64I_LDRLx | A64F_D(RID_X10) | A64F_S19(5);\n  *p++ = A64I_BR | A64F_N(RID_X11);\n  *p++ = A64I_NOP;\n  ((void **)p)[0] = target;\n  ((void **)p)[1] = g;\n  p += 4;\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = A64I_MOVZw | A64F_D(RID_X9) | A64F_U16(slot);\n    *p = A64I_B | A64F_S26((page-p) & 0x03ffffffu);\n    p++;\n  }\n  lua_assert(p - page <= CALLBACK_MCODE_SIZE);\n}\n#elif LJ_TARGET_PPC\nstatic void callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  *p++ = PPCI_LIS | PPCF_T(RID_TMP) | (u32ptr(target) >> 16);\n  *p++ = PPCI_LIS | PPCF_T(RID_R12) | (u32ptr(g) >> 16);\n  *p++ = PPCI_ORI | PPCF_A(RID_TMP)|PPCF_T(RID_TMP) | (u32ptr(target) & 0xffff);\n  *p++ = PPCI_ORI | PPCF_A(RID_R12)|PPCF_T(RID_R12) | (u32ptr(g) & 0xffff);\n  *p++ = PPCI_MTCTR | PPCF_T(RID_TMP);\n  *p++ = PPCI_BCTR;\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = PPCI_LI | PPCF_T(RID_R11) | slot;\n    *p = PPCI_B | (((page-p) & 0x00ffffffu) << 2);\n    p++;\n  }\n  lua_assert(p - page <= CALLBACK_MCODE_SIZE);\n}\n#elif LJ_TARGET_MIPS\nstatic void callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  *p++ = MIPSI_SW | MIPSF_T(RID_R1)|MIPSF_S(RID_SP) | 0;\n  *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (u32ptr(target) >> 16);\n  *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (u32ptr(g) >> 16);\n  *p++ = MIPSI_ORI | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) |(u32ptr(target)&0xffff);\n  *p++ = MIPSI_JR | MIPSF_S(RID_R3);\n  *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (u32ptr(g)&0xffff);\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p = MIPSI_B | ((page-p-1) & 0x0000ffffu);\n    p++;\n    *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot;\n  }\n  lua_assert(p - page <= CALLBACK_MCODE_SIZE);\n}\n#else\n/* Missing support for this architecture. */\n#define callback_mcode_init(g, p)\tUNUSED(p)\n#endif\n\n/* -- Machine code management --------------------------------------------- */\n\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#elif LJ_TARGET_POSIX\n\n#include <sys/mman.h>\n#ifndef MAP_ANONYMOUS\n#define MAP_ANONYMOUS   MAP_ANON\n#endif\n\n#endif\n\n/* Allocate and initialize area for callback function pointers. */\nstatic void callback_mcode_new(CTState *cts)\n{\n  size_t sz = (size_t)CALLBACK_MCODE_SIZE;\n  void *p;\n  if (CALLBACK_MAX_SLOT == 0)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#if LJ_TARGET_WINDOWS\n  p = VirtualAlloc(NULL, sz, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  if (!p)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#elif LJ_TARGET_POSIX\n  p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS,\n\t   -1, 0);\n  if (p == MAP_FAILED)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#else\n  /* Fallback allocator. Fails if memory is not executable by default. */\n  p = lj_mem_new(cts->L, sz);\n#endif\n  cts->cb.mcode = p;\n  callback_mcode_init(cts->g, p);\n  lj_mcode_sync(p, (char *)p + sz);\n#if LJ_TARGET_WINDOWS\n  {\n    DWORD oprot;\n    VirtualProtect(p, sz, PAGE_EXECUTE_READ, &oprot);\n  }\n#elif LJ_TARGET_POSIX\n  mprotect(p, sz, (PROT_READ|PROT_EXEC));\n#endif\n}\n\n/* Free area for callback function pointers. */\nvoid lj_ccallback_mcode_free(CTState *cts)\n{\n  size_t sz = (size_t)CALLBACK_MCODE_SIZE;\n  void *p = cts->cb.mcode;\n  if (p == NULL) return;\n#if LJ_TARGET_WINDOWS\n  VirtualFree(p, 0, MEM_RELEASE);\n  UNUSED(sz);\n#elif LJ_TARGET_POSIX\n  munmap(p, sz);\n#else\n  lj_mem_free(cts->g, p, sz);\n#endif\n}\n\n/* -- C callback entry ---------------------------------------------------- */\n\n/* Target-specific handling of register arguments. Similar to lj_ccall.c. */\n#if LJ_TARGET_X86\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (!isfp) {  /* Only non-FP values may be passed in registers. */ \\\n    if (n > 1) {  /* Anything > 32 bit is passed on the stack. */ \\\n      if (!LJ_ABI_WIN) ngpr = maxgpr;  /* Prevent reordering. */ \\\n    } else if (ngpr + 1 <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_X64 && LJ_ABI_WIN\n\n/* Windows/x64 argument registers are strictly positional (use ngpr). */\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (ngpr < maxgpr) { sp = &cts->cb.fpr[ngpr++]; UNUSED(nfpr); goto done; } \\\n  } else { \\\n    if (ngpr < maxgpr) { sp = &cts->cb.gpr[ngpr++]; goto done; } \\\n  }\n\n#elif LJ_TARGET_X64\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + n <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr]; \\\n      nfpr += n; \\\n      goto done; \\\n    } \\\n  } else { \\\n    if (ngpr + n <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_ARM\n\n#if LJ_ABI_SOFTFP\n\n#define CALLBACK_HANDLE_REGARG_FP1\tUNUSED(isfp);\n#define CALLBACK_HANDLE_REGARG_FP2\n\n#else\n\n#define CALLBACK_HANDLE_REGARG_FP1 \\\n  if (isfp) { \\\n    if (n == 1) { \\\n      if (fprodd) { \\\n\tsp = &cts->cb.fpr[fprodd-1]; \\\n\tfprodd = 0; \\\n\tgoto done; \\\n      } else if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n\tsp = &cts->cb.fpr[nfpr++]; \\\n\tfprodd = nfpr; \\\n\tgoto done; \\\n      } \\\n    } else { \\\n      if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n\tsp = &cts->cb.fpr[nfpr++]; \\\n\tgoto done; \\\n      } \\\n    } \\\n    fprodd = 0;  /* No reordering after the first FP value is on stack. */ \\\n  } else {\n\n#define CALLBACK_HANDLE_REGARG_FP2\t}\n\n#endif\n\n#define CALLBACK_HANDLE_REGARG \\\n  CALLBACK_HANDLE_REGARG_FP1 \\\n  if (n > 1) ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  } CALLBACK_HANDLE_REGARG_FP2\n\n#elif LJ_TARGET_ARM64\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + n <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr]; \\\n      nfpr += n; \\\n      goto done; \\\n    } else { \\\n      nfpr = CCALL_NARG_FPR;  /* Prevent reordering. */ \\\n    } \\\n  } else { \\\n    if (!LJ_TARGET_IOS && n > 1) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n    if (ngpr + n <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } else { \\\n      ngpr = CCALL_NARG_GPR;  /* Prevent reordering. */ \\\n    } \\\n  }\n\n#elif LJ_TARGET_PPC\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr++]; \\\n      cta = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */ \\\n      goto done; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    if (n > 1) { \\\n      lua_assert(ctype_isinteger(cta->info) && n == 2);  /* int64_t. */ \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align int64_t to regpair. */ \\\n    } \\\n    if (ngpr + n <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#define CALLBACK_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    *(double *)dp = *(float *)dp;  /* FPRs always hold doubles. */\n\n#elif LJ_TARGET_MIPS\n\n#define CALLBACK_HANDLE_GPR \\\n  if (n > 1) ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  }\n\n#if !LJ_ABI_SOFTFP\t/* MIPS32 hard-float */\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp && nfpr < CCALL_NARG_FPR) {  /* Try to pass argument in FPRs. */ \\\n    sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \\\n    nfpr++; ngpr += n; \\\n    goto done; \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    nfpr = CCALL_NARG_FPR; \\\n    CALLBACK_HANDLE_GPR \\\n  }\n#else\t\t\t/* MIPS32 soft-float */\n#define CALLBACK_HANDLE_REGARG \\\n  CALLBACK_HANDLE_GPR \\\n  UNUSED(isfp);\n#endif\n\n#define CALLBACK_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    ((float *)dp)[1] = *(float *)dp;\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n/* Convert and push callback arguments to Lua stack. */\nstatic void callback_conv_args(CTState *cts, lua_State *L)\n{\n  TValue *o = L->top;\n  intptr_t *stack = cts->cb.stack;\n  MSize slot = cts->cb.slot;\n  CTypeID id = 0, rid, fid;\n  int gcsteps = 0;\n  CType *ct;\n  GCfunc *fn;\n  int fntp;\n  MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR;\n#if CCALL_NARG_FPR\n  MSize nfpr = 0;\n#if LJ_TARGET_ARM\n  MSize fprodd = 0;\n#endif\n#endif\n\n  if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) {\n    ct = ctype_get(cts, id);\n    rid = ctype_cid(ct->info);  /* Return type. x86: +(spadj<<16). */\n    fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot));\n    fntp = LJ_TFUNC;\n  } else {  /* Must set up frame first, before throwing the error. */\n    ct = NULL;\n    rid = 0;\n    fn = (GCfunc *)L;\n    fntp = LJ_TTHREAD;\n  }\n  /* Continuation returns from callback. */\n  if (LJ_FR2) {\n    (o++)->u64 = LJ_CONT_FFI_CALLBACK;\n    (o++)->u64 = rid;\n    o++;\n  } else {\n    o->u32.lo = LJ_CONT_FFI_CALLBACK;\n    o->u32.hi = rid;\n    o++;\n  }\n  setframe_gc(o, obj2gco(fn), fntp);\n  setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT);\n  L->top = L->base = ++o;\n  if (!ct)\n    lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK);\n  if (isluafunc(fn))\n    setcframe_pc(L->cframe, proto_bc(funcproto(fn))+1);\n  lj_state_checkstack(L, LUA_MINSTACK);  /* May throw. */\n  o = L->base;  /* Might have been reallocated. */\n\n#if LJ_TARGET_X86\n  /* x86 has several different calling conventions. */\n  switch (ctype_cconv(ct->info)) {\n  case CTCC_FASTCALL: maxgpr = 2; break;\n  case CTCC_THISCALL: maxgpr = 1; break;\n  default: maxgpr = 0; break;\n  }\n#endif\n\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) {\n      CType *cta;\n      void *sp;\n      CTSize sz;\n      int isfp;\n      MSize n;\n      lua_assert(ctype_isfield(ctf->info));\n      cta = ctype_rawchild(cts, ctf);\n      isfp = ctype_isfp(cta->info);\n      sz = (cta->size + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);\n      n = sz / CTSIZE_PTR;  /* Number of GPRs or stack slots needed. */\n\n      CALLBACK_HANDLE_REGARG  /* Handle register arguments. */\n\n      /* Otherwise pass argument on stack. */\n      if (CCALL_ALIGN_STACKARG && LJ_32 && sz == 8)\n\tnsp = (nsp + 1) & ~1u;  /* Align 64 bit argument on stack. */\n      sp = &stack[nsp];\n      nsp += n;\n\n    done:\n      if (LJ_BE && cta->size < CTSIZE_PTR)\n\tsp = (void *)((uint8_t *)sp + CTSIZE_PTR-cta->size);\n      gcsteps += lj_cconv_tv_ct(cts, cta, 0, o++, sp);\n    }\n    fid = ctf->sib;\n  }\n  L->top = o;\n#if LJ_TARGET_X86\n  /* Store stack adjustment for returns from non-cdecl callbacks. */\n  if (ctype_cconv(ct->info) != CTCC_CDECL) {\n#if LJ_FR2\n    (L->base-3)->u64 |= (nsp << (16+2));\n#else\n    (L->base-2)->u32.hi |= (nsp << (16+2));\n#endif\n  }\n#endif\n  while (gcsteps-- > 0)\n    lj_gc_check(L);\n}\n\n/* Convert Lua object to callback result. */\nstatic void callback_conv_result(CTState *cts, lua_State *L, TValue *o)\n{\n#if LJ_FR2\n  CType *ctr = ctype_raw(cts, (uint16_t)(L->base-3)->u64);\n#else\n  CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi);\n#endif\n#if LJ_TARGET_X86\n  cts->cb.gpr[2] = 0;\n#endif\n  if (!ctype_isvoid(ctr->info)) {\n    uint8_t *dp = (uint8_t *)&cts->cb.gpr[0];\n#if CCALL_NUM_FPR\n    if (ctype_isfp(ctr->info))\n      dp = (uint8_t *)&cts->cb.fpr[0];\n#endif\n    lj_cconv_ct_tv(cts, ctr, dp, o, 0);\n#ifdef CALLBACK_HANDLE_RET\n    CALLBACK_HANDLE_RET\n#endif\n    /* Extend returned integers to (at least) 32 bits. */\n    if (ctype_isinteger_or_bool(ctr->info) && ctr->size < 4) {\n      if (ctr->info & CTF_UNSIGNED)\n\t*(uint32_t *)dp = ctr->size == 1 ? (uint32_t)*(uint8_t *)dp :\n\t\t\t\t\t   (uint32_t)*(uint16_t *)dp;\n      else\n\t*(int32_t *)dp = ctr->size == 1 ? (int32_t)*(int8_t *)dp :\n\t\t\t\t\t  (int32_t)*(int16_t *)dp;\n    }\n#if LJ_TARGET_X86\n    if (ctype_isfp(ctr->info))\n      cts->cb.gpr[2] = ctr->size == sizeof(float) ? 1 : 2;\n#endif\n  }\n}\n\n/* Enter callback. */\nlua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf)\n{\n  lua_State *L = cts->L;\n  global_State *g = cts->g;\n  lua_assert(L != NULL);\n  if (tvref(g->jit_base)) {\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_FFI_BADCBACK));\n    if (g->panic) g->panic(L);\n    exit(EXIT_FAILURE);\n  }\n  lj_trace_abort(g);  /* Never record across callback. */\n  /* Setup C frame. */\n  cframe_prev(cf) = L->cframe;\n  setcframe_L(cf, L);\n  cframe_errfunc(cf) = -1;\n  cframe_nres(cf) = 0;\n  L->cframe = cf;\n  callback_conv_args(cts, L);\n  return L;  /* Now call the function on this stack. */\n}\n\n/* Leave callback. */\nvoid LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o)\n{\n  lua_State *L = cts->L;\n  GCfunc *fn;\n  TValue *obase = L->base;\n  L->base = L->top;  /* Keep continuation frame for throwing errors. */\n  if (o >= L->base) {\n    /* PC of RET* is lost. Point to last line for result conv. errors. */\n    fn = curr_func(L);\n    if (isluafunc(fn)) {\n      GCproto *pt = funcproto(fn);\n      setcframe_pc(L->cframe, proto_bc(pt)+pt->sizebc+1);\n    }\n  }\n  callback_conv_result(cts, L, o);\n  /* Finally drop C frame and continuation frame. */\n  L->top -= 2+2*LJ_FR2;\n  L->base = obase;\n  L->cframe = cframe_prev(L->cframe);\n  cts->cb.slot = 0;  /* Blacklist C function that called the callback. */\n}\n\n/* -- C callback management ----------------------------------------------- */\n\n/* Get an unused slot in the callback slot table. */\nstatic MSize callback_slot_new(CTState *cts, CType *ct)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  CTypeID1 *cbid = cts->cb.cbid;\n  MSize top;\n  for (top = cts->cb.topid; top < cts->cb.sizeid; top++)\n    if (LJ_LIKELY(cbid[top] == 0))\n      goto found;\n#if CALLBACK_MAX_SLOT\n  if (top >= CALLBACK_MAX_SLOT)\n#endif\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n  if (!cts->cb.mcode)\n    callback_mcode_new(cts);\n  lj_mem_growvec(cts->L, cbid, cts->cb.sizeid, CALLBACK_MAX_SLOT, CTypeID1);\n  cts->cb.cbid = cbid;\n  memset(cbid+top, 0, (cts->cb.sizeid-top)*sizeof(CTypeID1));\nfound:\n  cbid[top] = id;\n  cts->cb.topid = top+1;\n  return top;\n}\n\n/* Check for function pointer and supported argument/result types. */\nstatic CType *callback_checkfunc(CTState *cts, CType *ct)\n{\n  int narg = 0;\n  if (!ctype_isptr(ct->info) || (LJ_64 && ct->size != CTSIZE_PTR))\n    return NULL;\n  ct = ctype_rawchild(cts, ct);\n  if (ctype_isfunc(ct->info)) {\n    CType *ctr = ctype_rawchild(cts, ct);\n    CTypeID fid = ct->sib;\n    if (!(ctype_isvoid(ctr->info) || ctype_isenum(ctr->info) ||\n\t  ctype_isptr(ctr->info) || (ctype_isnum(ctr->info) && ctr->size <= 8)))\n      return NULL;\n    if ((ct->info & CTF_VARARG))\n      return NULL;\n    while (fid) {\n      CType *ctf = ctype_get(cts, fid);\n      if (!ctype_isattrib(ctf->info)) {\n\tCType *cta;\n\tlua_assert(ctype_isfield(ctf->info));\n\tcta = ctype_rawchild(cts, ctf);\n\tif (!(ctype_isenum(cta->info) || ctype_isptr(cta->info) ||\n\t      (ctype_isnum(cta->info) && cta->size <= 8)) ||\n\t    ++narg >= LUA_MINSTACK-3)\n\t  return NULL;\n      }\n      fid = ctf->sib;\n    }\n    return ct;\n  }\n  return NULL;\n}\n\n/* Create a new callback and return the callback function pointer. */\nvoid *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn)\n{\n  ct = callback_checkfunc(cts, ct);\n  if (ct) {\n    MSize slot = callback_slot_new(cts, ct);\n    GCtab *t = cts->miscmap;\n    setfuncV(cts->L, lj_tab_setint(cts->L, t, (int32_t)slot), fn);\n    lj_gc_anybarriert(cts->L, t);\n    return callback_slot2ptr(cts, slot);\n  }\n  return NULL;  /* Bad conversion. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ccallback.h",
    "content": "/*\n** FFI C callback handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCALLBACK_H\n#define _LJ_CCALLBACK_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Really belongs to lj_vm.h. */\nLJ_ASMF void lj_vm_ffi_callback(void);\n\nLJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);\nLJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);\nLJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);\nLJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);\nLJ_FUNC void lj_ccallback_mcode_free(CTState *cts);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cconv.c",
    "content": "/*\n** C type conversions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_ccallback.h\"\n\n/* -- Conversion errors --------------------------------------------------- */\n\n/* Bad conversion. */\nLJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s,\n\t\t\t\t    CTInfo flags)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  const char *src;\n  if ((flags & CCF_FROMTV))\n    src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER :\n\t\t\t     ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)];\n  else\n    src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL));\n  if (CCF_GETARG(flags))\n    lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);\n  else\n    lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);\n}\n\n/* Bad conversion from TValue. */\nLJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o,\n\t\t\t\t      CTInfo flags)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  const char *src = lj_typename(o);\n  if (CCF_GETARG(flags))\n    lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);\n  else\n    lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);\n}\n\n/* Initializer overflow. */\nLJ_NORET static void cconv_err_initov(CTState *cts, CType *d)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst);\n}\n\n/* -- C type compatibility checks ----------------------------------------- */\n\n/* Get raw type and qualifiers for a child type. Resolves enums, too. */\nstatic CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual)\n{\n  ct = ctype_child(cts, ct);\n  for (;;) {\n    if (ctype_isattrib(ct->info)) {\n      if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;\n    } else if (!ctype_isenum(ct->info)) {\n      break;\n    }\n    ct = ctype_child(cts, ct);\n  }\n  *qual |= (ct->info & CTF_QUAL);\n  return ct;\n}\n\n/* Check for compatible types when converting to a pointer.\n** Note: these checks are more relaxed than what C99 mandates.\n*/\nint lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags)\n{\n  if (!((flags & CCF_CAST) || d == s)) {\n    CTInfo dqual = 0, squal = 0;\n    d = cconv_childqual(cts, d, &dqual);\n    if (!ctype_isstruct(s->info))\n      s = cconv_childqual(cts, s, &squal);\n    if ((flags & CCF_SAME)) {\n      if (dqual != squal)\n\treturn 0;  /* Different qualifiers. */\n    } else if (!(flags & CCF_IGNQUAL)) {\n      if ((dqual & squal) != squal)\n\treturn 0;  /* Discarded qualifiers. */\n      if (ctype_isvoid(d->info) || ctype_isvoid(s->info))\n\treturn 1;  /* Converting to/from void * is always ok. */\n    }\n    if (ctype_type(d->info) != ctype_type(s->info) ||\n\td->size != s->size)\n      return 0;  /* Different type or different size. */\n    if (ctype_isnum(d->info)) {\n      if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP)))\n\treturn 0;  /* Different numeric types. */\n    } else if (ctype_ispointer(d->info)) {\n      /* Check child types for compatibility. */\n      return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME);\n    } else if (ctype_isstruct(d->info)) {\n      if (d != s)\n\treturn 0;  /* Must be exact same type for struct/union. */\n    } else if (ctype_isfunc(d->info)) {\n      /* NYI: structural equality of functions. */\n    }\n  }\n  return 1;  /* Types are compatible. */\n}\n\n/* -- C type to C type conversion ----------------------------------------- */\n\n/* Convert C type to C type. Caveat: expects to get the raw CType!\n**\n** Note: This is only used by the interpreter and not optimized at all.\n** The JIT compiler will do a much better job specializing for each case.\n*/\nvoid lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,\n\t\t    uint8_t *dp, uint8_t *sp, CTInfo flags)\n{\n  CTSize dsize = d->size, ssize = s->size;\n  CTInfo dinfo = d->info, sinfo = s->info;\n  void *tmpptr;\n\n  lua_assert(!ctype_isenum(dinfo) && !ctype_isenum(sinfo));\n  lua_assert(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo));\n\n  if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)\n    goto err_conv;\n\n  /* Some basic sanity checks. */\n  lua_assert(!ctype_isnum(dinfo) || dsize > 0);\n  lua_assert(!ctype_isnum(sinfo) || ssize > 0);\n  lua_assert(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4);\n  lua_assert(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4);\n  lua_assert(!ctype_isinteger(dinfo) || (1u<<lj_fls(dsize)) == dsize);\n  lua_assert(!ctype_isinteger(sinfo) || (1u<<lj_fls(ssize)) == ssize);\n\n  switch (cconv_idx2(dinfo, sinfo)) {\n  /* Destination is a bool. */\n  case CCX(B, B):\n    /* Source operand is already normalized. */\n    if (dsize == 1) *dp = *sp; else *(int *)dp = *sp;\n    break;\n  case CCX(B, I): {\n    MSize i;\n    uint8_t b = 0;\n    for (i = 0; i < ssize; i++) b |= sp[i];\n    b = (b != 0);\n    if (dsize == 1) *dp = b; else *(int *)dp = b;\n    break;\n    }\n  case CCX(B, F): {\n    uint8_t b;\n    if (ssize == sizeof(double)) b = (*(double *)sp != 0);\n    else if (ssize == sizeof(float)) b = (*(float *)sp != 0);\n    else goto err_conv;  /* NYI: long double. */\n    if (dsize == 1) *dp = b; else *(int *)dp = b;\n    break;\n    }\n\n  /* Destination is an integer. */\n  case CCX(I, B):\n  case CCX(I, I):\n  conv_I_I:\n    if (dsize > ssize) {  /* Zero-extend or sign-extend LSB. */\n#if LJ_LE\n      uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0;\n      memcpy(dp, sp, ssize);\n      memset(dp + ssize, fill, dsize-ssize);\n#else\n      uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0;\n      memset(dp, fill, dsize-ssize);\n      memcpy(dp + (dsize-ssize), sp, ssize);\n#endif\n    } else {  /* Copy LSB. */\n#if LJ_LE\n      memcpy(dp, sp, dsize);\n#else\n      memcpy(dp, sp + (ssize-dsize), dsize);\n#endif\n    }\n    break;\n  case CCX(I, F): {\n    double n;  /* Always convert via double. */\n  conv_I_F:\n    /* Convert source to double. */\n    if (ssize == sizeof(double)) n = *(double *)sp;\n    else if (ssize == sizeof(float)) n = (double)*(float *)sp;\n    else goto err_conv;  /* NYI: long double. */\n    /* Then convert double to integer. */\n    /* The conversion must exactly match the semantics of JIT-compiled code! */\n    if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) {\n      int32_t i = (int32_t)n;\n      if (dsize == 4) *(int32_t *)dp = i;\n      else if (dsize == 2) *(int16_t *)dp = (int16_t)i;\n      else *(int8_t *)dp = (int8_t)i;\n    } else if (dsize == 4) {\n      *(uint32_t *)dp = (uint32_t)n;\n    } else if (dsize == 8) {\n      if (!(dinfo & CTF_UNSIGNED))\n\t*(int64_t *)dp = (int64_t)n;\n      else\n\t*(uint64_t *)dp = lj_num2u64(n);\n    } else {\n      goto err_conv;  /* NYI: conversion to >64 bit integers. */\n    }\n    break;\n    }\n  case CCX(I, C):\n    s = ctype_child(cts, s);\n    sinfo = s->info;\n    ssize = s->size;\n    goto conv_I_F;  /* Just convert re. */\n  case CCX(I, P):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    goto conv_I_I;\n  case CCX(I, A):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    ssize = CTSIZE_PTR;\n    tmpptr = sp;\n    sp = (uint8_t *)&tmpptr;\n    goto conv_I_I;\n\n  /* Destination is a floating-point number. */\n  case CCX(F, B):\n  case CCX(F, I): {\n    double n;  /* Always convert via double. */\n  conv_F_I:\n    /* First convert source to double. */\n    /* The conversion must exactly match the semantics of JIT-compiled code! */\n    if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) {\n      int32_t i;\n      if (ssize == 4) {\n\ti = *(int32_t *)sp;\n      } else if (!(sinfo & CTF_UNSIGNED)) {\n\tif (ssize == 2) i = *(int16_t *)sp;\n\telse i = *(int8_t *)sp;\n      } else {\n\tif (ssize == 2) i = *(uint16_t *)sp;\n\telse i = *(uint8_t *)sp;\n      }\n      n = (double)i;\n    } else if (ssize == 4) {\n      n = (double)*(uint32_t *)sp;\n    } else if (ssize == 8) {\n      if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp;\n      else n = (double)*(uint64_t *)sp;\n    } else {\n      goto err_conv;  /* NYI: conversion from >64 bit integers. */\n    }\n    /* Convert double to destination. */\n    if (dsize == sizeof(double)) *(double *)dp = n;\n    else if (dsize == sizeof(float)) *(float *)dp = (float)n;\n    else goto err_conv;  /* NYI: long double. */\n    break;\n    }\n  case CCX(F, F): {\n    double n;  /* Always convert via double. */\n  conv_F_F:\n    if (ssize == dsize) goto copyval;\n    /* Convert source to double. */\n    if (ssize == sizeof(double)) n = *(double *)sp;\n    else if (ssize == sizeof(float)) n = (double)*(float *)sp;\n    else goto err_conv;  /* NYI: long double. */\n    /* Convert double to destination. */\n    if (dsize == sizeof(double)) *(double *)dp = n;\n    else if (dsize == sizeof(float)) *(float *)dp = (float)n;\n    else goto err_conv;  /* NYI: long double. */\n    break;\n    }\n  case CCX(F, C):\n    s = ctype_child(cts, s);\n    sinfo = s->info;\n    ssize = s->size;\n    goto conv_F_F;  /* Ignore im, and convert from re. */\n\n  /* Destination is a complex number. */\n  case CCX(C, I):\n    d = ctype_child(cts, d);\n    dinfo = d->info;\n    dsize = d->size;\n    memset(dp + dsize, 0, dsize);  /* Clear im. */\n    goto conv_F_I;  /* Convert to re. */\n  case CCX(C, F):\n    d = ctype_child(cts, d);\n    dinfo = d->info;\n    dsize = d->size;\n    memset(dp + dsize, 0, dsize);  /* Clear im. */\n    goto conv_F_F;  /* Convert to re. */\n\n  case CCX(C, C):\n    if (dsize != ssize) {  /* Different types: convert re/im separately. */\n      CType *dc = ctype_child(cts, d);\n      CType *sc = ctype_child(cts, s);\n      lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags);\n      lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags);\n      return;\n    }\n    goto copyval;  /* Otherwise this is easy. */\n\n  /* Destination is a vector. */\n  case CCX(V, I):\n  case CCX(V, F):\n  case CCX(V, C): {\n    CType *dc = ctype_child(cts, d);\n    CTSize esize;\n    /* First convert the scalar to the first element. */\n    lj_cconv_ct_ct(cts, dc, s, dp, sp, flags);\n    /* Then replicate it to the other elements (splat). */\n    for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) {\n      dp += esize;\n      memcpy(dp, sp, esize);\n    }\n    break;\n    }\n\n  case CCX(V, V):\n    /* Copy same-sized vectors, even for different lengths/element-types. */\n    if (dsize != ssize) goto err_conv;\n    goto copyval;\n\n  /* Destination is a pointer. */\n  case CCX(P, I):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    dinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    goto conv_I_I;\n\n  case CCX(P, F):\n    if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv;\n    /* The signed conversion is cheaper. x64 really has 47 bit pointers. */\n    dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED);\n    goto conv_I_F;\n\n  case CCX(P, P):\n    if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;\n    cdata_setptr(dp, dsize, cdata_getptr(sp, ssize));\n    break;\n\n  case CCX(P, A):\n  case CCX(P, S):\n    if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;\n    cdata_setptr(dp, dsize, sp);\n    break;\n\n  /* Destination is an array. */\n  case CCX(A, A):\n    if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize ||\n\td->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))\n      goto err_conv;\n    goto copyval;\n\n  /* Destination is a struct/union. */\n  case CCX(S, S):\n    if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s)\n      goto err_conv;  /* Must be exact same type. */\ncopyval:  /* Copy value. */\n    lua_assert(dsize == ssize);\n    memcpy(dp, sp, dsize);\n    break;\n\n  default:\n  err_conv:\n    cconv_err_conv(cts, d, s, flags);\n  }\n}\n\n/* -- C type to TValue conversion ----------------------------------------- */\n\n/* Convert C type to TValue. Caveat: expects to get the raw CType! */\nint lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,\n\t\t   TValue *o, uint8_t *sp)\n{\n  CTInfo sinfo = s->info;\n  if (ctype_isnum(sinfo)) {\n    if (!ctype_isbool(sinfo)) {\n      if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;\n      if (LJ_DUALNUM && ctype_isinteger(sinfo)) {\n\tint32_t i;\n\tlj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s,\n\t\t       (uint8_t *)&i, sp, 0);\n\tif ((sinfo & CTF_UNSIGNED) && i < 0)\n\t  setnumV(o, (lua_Number)(uint32_t)i);\n\telse\n\t  setintV(o, i);\n      } else {\n\tlj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s,\n\t\t       (uint8_t *)&o->n, sp, 0);\n\t/* Numbers are NOT canonicalized here! Beware of uninitialized data. */\n\tlua_assert(tvisnum(o));\n      }\n    } else {\n      uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0);\n      setboolV(o, b);\n      setboolV(&cts->g->tmptv2, b);  /* Remember for trace recorder. */\n    }\n    return 0;\n  } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {\n    /* Create reference. */\n    setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid));\n    return 1;  /* Need GC step. */\n  } else {\n    GCcdata *cd;\n    CTSize sz;\n  copyval:  /* Copy value. */\n    sz = s->size;\n    lua_assert(sz != CTSIZE_INVALID);\n    /* Attributes are stripped, qualifiers are kept (but mostly ignored). */\n    cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz);\n    setcdataV(cts->L, o, cd);\n    memcpy(cdataptr(cd), sp, sz);\n    return 1;  /* Need GC step. */\n  }\n}\n\n/* Convert bitfield to TValue. */\nint lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp)\n{\n  CTInfo info = s->info;\n  CTSize pos, bsz;\n  uint32_t val;\n  lua_assert(ctype_isbitfield(info));\n  /* NYI: packed bitfields may cause misaligned reads. */\n  switch (ctype_bitcsz(info)) {\n  case 4: val = *(uint32_t *)sp; break;\n  case 2: val = *(uint16_t *)sp; break;\n  case 1: val = *(uint8_t *)sp; break;\n  default: lua_assert(0); val = 0; break;\n  }\n  /* Check if a packed bitfield crosses a container boundary. */\n  pos = ctype_bitpos(info);\n  bsz = ctype_bitbsz(info);\n  lua_assert(pos < 8*ctype_bitcsz(info));\n  lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));\n  if (pos + bsz > 8*ctype_bitcsz(info))\n    lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);\n  if (!(info & CTF_BOOL)) {\n    CTSize shift = 32 - bsz;\n    if (!(info & CTF_UNSIGNED)) {\n      setintV(o, (int32_t)(val << (shift-pos)) >> shift);\n    } else {\n      val = (val << (shift-pos)) >> shift;\n      if (!LJ_DUALNUM || (int32_t)val < 0)\n\tsetnumV(o, (lua_Number)(uint32_t)val);\n      else\n\tsetintV(o, (int32_t)val);\n    }\n  } else {\n    lua_assert(bsz == 1);\n    setboolV(o, (val >> pos) & 1);\n  }\n  return 0;  /* No GC step needed. */\n}\n\n/* -- TValue to C type conversion ----------------------------------------- */\n\n/* Convert table to array. */\nstatic void cconv_array_tab(CTState *cts, CType *d,\n\t\t\t    uint8_t *dp, GCtab *t, CTInfo flags)\n{\n  int32_t i;\n  CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n  CTSize size = d->size, esize = dc->size, ofs = 0;\n  for (i = 0; ; i++) {\n    TValue *tv = (TValue *)lj_tab_getint(t, i);\n    if (!tv || tvisnil(tv)) {\n      if (i == 0) continue;  /* Try again for 1-based tables. */\n      break;  /* Stop at first nil. */\n    }\n    if (ofs >= size)\n      cconv_err_initov(cts, d);\n    lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags);\n    ofs += esize;\n  }\n  if (size != CTSIZE_INVALID) {  /* Only fill up arrays with known size. */\n    if (ofs == esize) {  /* Replicate a single element. */\n      for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize);\n    } else {  /* Otherwise fill the remainder with zero. */\n      memset(dp + ofs, 0, size - ofs);\n    }\n  }\n}\n\n/* Convert table to sub-struct/union. */\nstatic void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp,\n\t\t\t\tGCtab *t, int32_t *ip, CTInfo flags)\n{\n  CTypeID id = d->sib;\n  while (id) {\n    CType *df = ctype_get(cts, id);\n    id = df->sib;\n    if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {\n      TValue *tv;\n      int32_t i = *ip, iz = i;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      if (i >= 0) {\n      retry:\n\ttv = (TValue *)lj_tab_getint(t, i);\n\tif (!tv || tvisnil(tv)) {\n\t  if (i == 0) { i = 1; goto retry; }  /* 1-based tables. */\n\t  if (iz == 0) { *ip = i = -1; goto tryname; }  /* Init named fields. */\n\t  break;  /* Stop at first nil. */\n\t}\n\t*ip = i + 1;\n      } else {\n      tryname:\n\ttv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name)));\n\tif (!tv || tvisnil(tv)) continue;\n      }\n      if (ctype_isfield(df->info))\n\tlj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags);\n      else\n\tlj_cconv_bf_tv(cts, df, dp+df->size, tv);\n      if ((d->info & CTF_UNION)) break;\n    } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {\n      cconv_substruct_tab(cts, ctype_rawchild(cts, df),\n\t\t\t  dp+df->size, t, ip, flags);\n    }  /* Ignore all other entries in the chain. */\n  }\n}\n\n/* Convert table to struct/union. */\nstatic void cconv_struct_tab(CTState *cts, CType *d,\n\t\t\t     uint8_t *dp, GCtab *t, CTInfo flags)\n{\n  int32_t i = 0;\n  memset(dp, 0, d->size);  /* Much simpler to clear the struct first. */\n  cconv_substruct_tab(cts, d, dp, t, &i, flags);\n}\n\n/* Convert TValue to C type. Caveat: expects to get the raw CType! */\nvoid lj_cconv_ct_tv(CTState *cts, CType *d,\n\t\t    uint8_t *dp, TValue *o, CTInfo flags)\n{\n  CTypeID sid = CTID_P_VOID;\n  CType *s;\n  void *tmpptr;\n  uint8_t tmpbool, *sp = (uint8_t *)&tmpptr;\n  if (LJ_LIKELY(tvisint(o))) {\n    sp = (uint8_t *)&o->i;\n    sid = CTID_INT32;\n    flags |= CCF_FROMTV;\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    sp = (uint8_t *)&o->n;\n    sid = CTID_DOUBLE;\n    flags |= CCF_FROMTV;\n  } else if (tviscdata(o)) {\n    sp = cdataptr(cdataV(o));\n    sid = cdataV(o)->ctypeid;\n    s = ctype_get(cts, sid);\n    if (ctype_isref(s->info)) {  /* Resolve reference for value. */\n      lua_assert(s->size == CTSIZE_PTR);\n      sp = *(void **)sp;\n      sid = ctype_cid(s->info);\n    }\n    s = ctype_raw(cts, sid);\n    if (ctype_isfunc(s->info)) {\n      sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);\n    } else {\n      if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n      goto doconv;\n    }\n  } else if (tvisstr(o)) {\n    GCstr *str = strV(o);\n    if (ctype_isenum(d->info)) {  /* Match string against enum constant. */\n      CTSize ofs;\n      CType *cct = lj_ctype_getfield(cts, d, str, &ofs);\n      if (!cct || !ctype_isconstval(cct->info))\n\tgoto err_conv;\n      lua_assert(d->size == 4);\n      sp = (uint8_t *)&cct->size;\n      sid = ctype_cid(cct->info);\n    } else if (ctype_isrefarray(d->info)) {  /* Copy string to array. */\n      CType *dc = ctype_rawchild(cts, d);\n      CTSize sz = str->len+1;\n      if (!ctype_isinteger(dc->info) || dc->size != 1)\n\tgoto err_conv;\n      if (d->size != 0 && d->size < sz)\n\tsz = d->size;\n      memcpy(dp, strdata(str), sz);\n      return;\n    } else {  /* Otherwise pass it as a const char[]. */\n      sp = (uint8_t *)strdata(str);\n      sid = CTID_A_CCHAR;\n      flags |= CCF_FROMTV;\n    }\n  } else if (tvistab(o)) {\n    if (ctype_isarray(d->info)) {\n      cconv_array_tab(cts, d, dp, tabV(o), flags);\n      return;\n    } else if (ctype_isstruct(d->info)) {\n      cconv_struct_tab(cts, d, dp, tabV(o), flags);\n      return;\n    } else {\n      goto err_conv;\n    }\n  } else if (tvisbool(o)) {\n    tmpbool = boolV(o);\n    sp = &tmpbool;\n    sid = CTID_BOOL;\n  } else if (tvisnil(o)) {\n    tmpptr = (void *)0;\n    flags |= CCF_FROMTV;\n  } else if (tvisudata(o)) {\n    GCudata *ud = udataV(o);\n    tmpptr = uddata(ud);\n    if (ud->udtype == UDTYPE_IO_FILE)\n      tmpptr = *(void **)tmpptr;\n  } else if (tvislightud(o)) {\n    tmpptr = lightudV(o);\n  } else if (tvisfunc(o)) {\n    void *p = lj_ccallback_new(cts, d, funcV(o));\n    if (p) {\n      *(void **)dp = p;\n      return;\n    }\n    goto err_conv;\n  } else {\n  err_conv:\n    cconv_err_convtv(cts, d, o, flags);\n  }\n  s = ctype_get(cts, sid);\ndoconv:\n  if (ctype_isenum(d->info)) d = ctype_child(cts, d);\n  lj_cconv_ct_ct(cts, d, s, dp, sp, flags);\n}\n\n/* Convert TValue to bitfield. */\nvoid lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o)\n{\n  CTInfo info = d->info;\n  CTSize pos, bsz;\n  uint32_t val, mask;\n  lua_assert(ctype_isbitfield(info));\n  if ((info & CTF_BOOL)) {\n    uint8_t tmpbool;\n    lua_assert(ctype_bitbsz(info) == 1);\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0);\n    val = tmpbool;\n  } else {\n    CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32;\n    lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0);\n  }\n  pos = ctype_bitpos(info);\n  bsz = ctype_bitbsz(info);\n  lua_assert(pos < 8*ctype_bitcsz(info));\n  lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));\n  /* Check if a packed bitfield crosses a container boundary. */\n  if (pos + bsz > 8*ctype_bitcsz(info))\n    lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);\n  mask = ((1u << bsz) - 1u) << pos;\n  val = (val << pos) & mask;\n  /* NYI: packed bitfields may cause misaligned reads/writes. */\n  switch (ctype_bitcsz(info)) {\n  case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break;\n  case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break;\n  case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break;\n  default: lua_assert(0); break;\n  }\n}\n\n/* -- Initialize C type with TValues -------------------------------------- */\n\n/* Initialize an array with TValues. */\nstatic void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,\n\t\t\t     TValue *o, MSize len)\n{\n  CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n  CTSize ofs, esize = dc->size;\n  MSize i;\n  if (len*esize > sz)\n    cconv_err_initov(cts, d);\n  for (i = 0, ofs = 0; i < len; i++, ofs += esize)\n    lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0);\n  if (ofs == esize) {  /* Replicate a single element. */\n    for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize);\n  } else {  /* Otherwise fill the remainder with zero. */\n    memset(dp + ofs, 0, sz - ofs);\n  }\n}\n\n/* Initialize a sub-struct/union with TValues. */\nstatic void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp,\n\t\t\t\t TValue *o, MSize len, MSize *ip)\n{\n  CTypeID id = d->sib;\n  while (id) {\n    CType *df = ctype_get(cts, id);\n    id = df->sib;\n    if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {\n      MSize i = *ip;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      if (i >= len) break;\n      *ip = i + 1;\n      if (ctype_isfield(df->info))\n\tlj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0);\n      else\n\tlj_cconv_bf_tv(cts, df, dp+df->size, o + i);\n      if ((d->info & CTF_UNION)) break;\n    } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {\n      cconv_substruct_init(cts, ctype_rawchild(cts, df),\n\t\t\t   dp+df->size, o, len, ip);\n      if ((d->info & CTF_UNION)) break;\n    }  /* Ignore all other entries in the chain. */\n  }\n}\n\n/* Initialize a struct/union with TValues. */\nstatic void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,\n\t\t\t      TValue *o, MSize len)\n{\n  MSize i = 0;\n  memset(dp, 0, sz);  /* Much simpler to clear the struct first. */\n  cconv_substruct_init(cts, d, dp, o, len, &i);\n  if (i < len)\n    cconv_err_initov(cts, d);\n}\n\n/* Check whether to use a multi-value initializer.\n** This is true if an aggregate is to be initialized with a value.\n** Valarrays are treated as values here so ct_tv handles (V|C, I|F).\n*/\nint lj_cconv_multi_init(CTState *cts, CType *d, TValue *o)\n{\n  if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))\n    return 0;  /* Destination is not an aggregate. */\n  if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))\n    return 0;  /* Initializer is not a value. */\n  if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d)\n    return 0;  /* Source and destination are identical aggregates. */\n  return 1;  /* Otherwise the initializer is a value. */\n}\n\n/* Initialize C type with TValues. Caveat: expects to get the raw CType! */\nvoid lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,\n\t\t      uint8_t *dp, TValue *o, MSize len)\n{\n  if (len == 0)\n    memset(dp, 0, sz);\n  else if (len == 1 && !lj_cconv_multi_init(cts, d, o))\n    lj_cconv_ct_tv(cts, d, dp, o, 0);\n  else if (ctype_isarray(d->info))  /* Also handles valarray init with len>1. */\n    cconv_array_init(cts, d, sz, dp, o, len);\n  else if (ctype_isstruct(d->info))\n    cconv_struct_init(cts, d, sz, dp, o, len);\n  else\n    cconv_err_initov(cts, d);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cconv.h",
    "content": "/*\n** C type conversions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCONV_H\n#define _LJ_CCONV_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Compressed C type index. ORDER CCX. */\nenum {\n  CCX_B,\t/* Bool. */\n  CCX_I,\t/* Integer. */\n  CCX_F,\t/* Floating-point number. */\n  CCX_C,\t/* Complex. */\n  CCX_V,\t/* Vector. */\n  CCX_P,\t/* Pointer. */\n  CCX_A,\t/* Refarray. */\n  CCX_S\t\t/* Struct/union. */\n};\n\n/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */\nstatic LJ_AINLINE uint32_t cconv_idx(CTInfo info)\n{\n  uint32_t idx = ((info >> 26) & 15u);  /* Dispatch bits. */\n  lua_assert(ctype_type(info) <= CT_MAYCONVERT);\n#if LJ_64\n  idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);\n#else\n  idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);\n#endif\n  lua_assert(idx < 8);\n  return idx;\n}\n\n#define cconv_idx2(dinfo, sinfo) \\\n  ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))\n\n#define CCX(dst, src)\t\t((CCX_##dst << 3) + CCX_##src)\n\n/* Conversion flags. */\n#define CCF_CAST\t0x00000001u\n#define CCF_FROMTV\t0x00000002u\n#define CCF_SAME\t0x00000004u\n#define CCF_IGNQUAL\t0x00000008u\n\n#define CCF_ARG_SHIFT\t8\n#define CCF_ARG(n)\t((n) << CCF_ARG_SHIFT)\n#define CCF_GETARG(f)\t((f) >> CCF_ARG_SHIFT)\n\nLJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);\nLJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,\n\t\t\t    uint8_t *dp, uint8_t *sp, CTInfo flags);\nLJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,\n\t\t\t   TValue *o, uint8_t *sp);\nLJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);\nLJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,\n\t\t\t    uint8_t *dp, TValue *o, CTInfo flags);\nLJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);\nLJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);\nLJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,\n\t\t\t      uint8_t *dp, TValue *o, MSize len);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cdata.c",
    "content": "/*\n** C data management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n\n/* -- C data allocation --------------------------------------------------- */\n\n/* Allocate a new C data object holding a reference to another object. */\nGCcdata *lj_cdata_newref(CTState *cts, const void *p, CTypeID id)\n{\n  CTypeID refid = lj_ctype_intern(cts, CTINFO_REF(id), CTSIZE_PTR);\n  GCcdata *cd = lj_cdata_new(cts, refid, CTSIZE_PTR);\n  *(const void **)cdataptr(cd) = p;\n  return cd;\n}\n\n/* Allocate variable-sized or specially aligned C data object. */\nGCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz, CTSize align)\n{\n  global_State *g;\n  MSize extra = sizeof(GCcdataVar) + sizeof(GCcdata) +\n\t\t(align > CT_MEMALIGN ? (1u<<align) - (1u<<CT_MEMALIGN) : 0);\n  char *p = lj_mem_newt(L, extra + sz, char);\n  uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata);\n  uintptr_t almask = (1u << align) - 1u;\n  GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata));\n  lua_assert((char *)cd - p < 65536);\n  cdatav(cd)->offset = (uint16_t)((char *)cd - p);\n  cdatav(cd)->extra = extra;\n  cdatav(cd)->len = sz;\n  g = G(L);\n  setgcrefr(cd->nextgc, g->gc.root);\n  setgcref(g->gc.root, obj2gco(cd));\n  newwhite(g, obj2gco(cd));\n  cd->marked |= 0x80;\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = id;\n  return cd;\n}\n\n/* Allocate arbitrary C data object. */\nGCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz, CTInfo info)\n{\n  if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN)\n    return lj_cdata_new(cts, id, sz);\n  else\n    return lj_cdata_newv(cts->L, id, sz, ctype_align(info));\n}\n\n/* Free a C data object. */\nvoid LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)\n{\n  if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) {\n    GCobj *root;\n    makewhite(g, obj2gco(cd));\n    markfinalized(obj2gco(cd));\n    if ((root = gcref(g->gc.mmudata)) != NULL) {\n      setgcrefr(cd->nextgc, root->gch.nextgc);\n      setgcref(root->gch.nextgc, obj2gco(cd));\n      setgcref(g->gc.mmudata, obj2gco(cd));\n    } else {\n      setgcref(cd->nextgc, obj2gco(cd));\n      setgcref(g->gc.mmudata, obj2gco(cd));\n    }\n  } else if (LJ_LIKELY(!cdataisv(cd))) {\n    CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid);\n    CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR;\n    lua_assert(ctype_hassize(ct->info) || ctype_isfunc(ct->info) ||\n\t       ctype_isextern(ct->info));\n    lj_mem_free(g, cd, sizeof(GCcdata) + sz);\n  } else {\n    lj_mem_free(g, memcdatav(cd), sizecdatav(cd));\n  }\n}\n\nvoid lj_cdata_setfin(lua_State *L, GCcdata *cd, GCobj *obj, uint32_t it)\n{\n  GCtab *t = ctype_ctsG(G(L))->finalizer;\n  if (gcref(t->metatable)) {\n    /* Add cdata to finalizer table, if still enabled. */\n    TValue *tv, tmp;\n    setcdataV(L, &tmp, cd);\n    lj_gc_anybarriert(L, t);\n    tv = lj_tab_set(L, t, &tmp);\n    setgcV(L, tv, obj, it);\n    if (!tvisnil(tv))\n      cd->marked |= LJ_GC_CDATA_FIN;\n    else\n      cd->marked &= ~LJ_GC_CDATA_FIN;\n  }\n}\n\n/* -- C data indexing ----------------------------------------------------- */\n\n/* Index C data by a TValue. Return CType and pointer. */\nCType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,\n\t\t      CTInfo *qual)\n{\n  uint8_t *p = (uint8_t *)cdataptr(cd);\n  CType *ct = ctype_get(cts, cd->ctypeid);\n  ptrdiff_t idx;\n\n  /* Resolve reference for cdata object. */\n  if (ctype_isref(ct->info)) {\n    lua_assert(ct->size == CTSIZE_PTR);\n    p = *(uint8_t **)p;\n    ct = ctype_child(cts, ct);\n  }\n\ncollect_attrib:\n  /* Skip attributes and collect qualifiers. */\n  while (ctype_isattrib(ct->info)) {\n    if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;\n    ct = ctype_child(cts, ct);\n  }\n  lua_assert(!ctype_isref(ct->info));  /* Interning rejects refs to refs. */\n\n  if (tvisint(key)) {\n    idx = (ptrdiff_t)intV(key);\n    goto integer_key;\n  } else if (tvisnum(key)) {  /* Numeric key. */\n#ifdef _MSC_VER\n    /* Workaround for MSVC bug. */\n    volatile\n#endif\n    lua_Number n = numV(key);\n    idx = LJ_64 ? (ptrdiff_t)n : (ptrdiff_t)lj_num2int(n);\n  integer_key:\n    if (ctype_ispointer(ct->info)) {\n      CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info));  /* Element size. */\n      if (sz == CTSIZE_INVALID)\n\tlj_err_caller(cts->L, LJ_ERR_FFI_INVSIZE);\n      if (ctype_isptr(ct->info)) {\n\tp = (uint8_t *)cdata_getptr(p, ct->size);\n      } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {\n\tif ((ct->info & CTF_COMPLEX)) idx &= 1;\n\t*qual |= CTF_CONST;  /* Valarray elements are constant. */\n      }\n      *pp = p + idx*(int32_t)sz;\n      return ct;\n    }\n  } else if (tviscdata(key)) {  /* Integer cdata key. */\n    GCcdata *cdk = cdataV(key);\n    CType *ctk = ctype_raw(cts, cdk->ctypeid);\n    if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk);\n    if (ctype_isinteger(ctk->info)) {\n      lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk,\n\t\t     (uint8_t *)&idx, cdataptr(cdk), 0);\n      goto integer_key;\n    }\n  } else if (tvisstr(key)) {  /* String key. */\n    GCstr *name = strV(key);\n    if (ctype_isstruct(ct->info)) {\n      CTSize ofs;\n      CType *fct = lj_ctype_getfieldq(cts, ct, name, &ofs, qual);\n      if (fct) {\n\t*pp = p + ofs;\n\treturn fct;\n      }\n    } else if (ctype_iscomplex(ct->info)) {\n      if (name->len == 2) {\n\t*qual |= CTF_CONST;  /* Complex fields are constant. */\n\tif (strdata(name)[0] == 'r' && strdata(name)[1] == 'e') {\n\t  *pp = p;\n\t  return ct;\n\t} else if (strdata(name)[0] == 'i' && strdata(name)[1] == 'm') {\n\t  *pp = p + (ct->size >> 1);\n\t  return ct;\n\t}\n      }\n    } else if (cd->ctypeid == CTID_CTYPEID) {\n      /* Allow indexing a (pointer to) struct constructor to get constants. */\n      CType *sct = ctype_raw(cts, *(CTypeID *)p);\n      if (ctype_isptr(sct->info))\n\tsct = ctype_rawchild(cts, sct);\n      if (ctype_isstruct(sct->info)) {\n\tCTSize ofs;\n\tCType *fct = lj_ctype_getfield(cts, sct, name, &ofs);\n\tif (fct && ctype_isconstval(fct->info))\n\t  return fct;\n      }\n      ct = sct;  /* Allow resolving metamethods for constructors, too. */\n    }\n  }\n  if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */\n    if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) {\n      p = (uint8_t *)cdata_getptr(p, ct->size);\n      ct = ctype_child(cts, ct);\n      goto collect_attrib;\n    }\n  }\n  *qual |= 1;  /* Lookup failed. */\n  return ct;  /* But return the resolved raw type. */\n}\n\n/* -- C data getters ------------------------------------------------------ */\n\n/* Get constant value and convert to TValue. */\nstatic void cdata_getconst(CTState *cts, TValue *o, CType *ct)\n{\n  CType *ctt = ctype_child(cts, ct);\n  lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4);\n  /* Constants are already zero-extended/sign-extended to 32 bits. */\n  if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)\n    setnumV(o, (lua_Number)(uint32_t)ct->size);\n  else\n    setintV(o, (int32_t)ct->size);\n}\n\n/* Get C data value and convert to TValue. */\nint lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp)\n{\n  CTypeID sid;\n\n  if (ctype_isconstval(s->info)) {\n    cdata_getconst(cts, o, s);\n    return 0;  /* No GC step needed. */\n  } else if (ctype_isbitfield(s->info)) {\n    return lj_cconv_tv_bf(cts, s, o, sp);\n  }\n\n  /* Get child type of pointer/array/field. */\n  lua_assert(ctype_ispointer(s->info) || ctype_isfield(s->info));\n  sid = ctype_cid(s->info);\n  s = ctype_get(cts, sid);\n\n  /* Resolve reference for field. */\n  if (ctype_isref(s->info)) {\n    lua_assert(s->size == CTSIZE_PTR);\n    sp = *(uint8_t **)sp;\n    sid = ctype_cid(s->info);\n    s = ctype_get(cts, sid);\n  }\n\n  /* Skip attributes. */\n  while (ctype_isattrib(s->info))\n    s = ctype_child(cts, s);\n\n  return lj_cconv_tv_ct(cts, s, sid, o, sp);\n}\n\n/* -- C data setters ------------------------------------------------------ */\n\n/* Convert TValue and set C data value. */\nvoid lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual)\n{\n  if (ctype_isconstval(d->info)) {\n    goto err_const;\n  } else if (ctype_isbitfield(d->info)) {\n    if (((d->info|qual) & CTF_CONST)) goto err_const;\n    lj_cconv_bf_tv(cts, d, dp, o);\n    return;\n  }\n\n  /* Get child type of pointer/array/field. */\n  lua_assert(ctype_ispointer(d->info) || ctype_isfield(d->info));\n  d = ctype_child(cts, d);\n\n  /* Resolve reference for field. */\n  if (ctype_isref(d->info)) {\n    lua_assert(d->size == CTSIZE_PTR);\n    dp = *(uint8_t **)dp;\n    d = ctype_child(cts, d);\n  }\n\n  /* Skip attributes and collect qualifiers. */\n  for (;;) {\n    if (ctype_isattrib(d->info)) {\n      if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;\n    } else {\n      break;\n    }\n    d = ctype_child(cts, d);\n  }\n\n  lua_assert(ctype_hassize(d->info) && !ctype_isvoid(d->info));\n\n  if (((d->info|qual) & CTF_CONST)) {\n  err_const:\n    lj_err_caller(cts->L, LJ_ERR_FFI_WRCONST);\n  }\n\n  lj_cconv_ct_tv(cts, d, dp, o, 0);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cdata.h",
    "content": "/*\n** C data management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CDATA_H\n#define _LJ_CDATA_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Get C data pointer. */\nstatic LJ_AINLINE void *cdata_getptr(void *p, CTSize sz)\n{\n  if (LJ_64 && sz == 4) {  /* Support 32 bit pointers on 64 bit targets. */\n    return ((void *)(uintptr_t)*(uint32_t *)p);\n  } else {\n    lua_assert(sz == CTSIZE_PTR);\n    return *(void **)p;\n  }\n}\n\n/* Set C data pointer. */\nstatic LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v)\n{\n  if (LJ_64 && sz == 4) {  /* Support 32 bit pointers on 64 bit targets. */\n    *(uint32_t *)p = (uint32_t)(uintptr_t)v;\n  } else {\n    lua_assert(sz == CTSIZE_PTR);\n    *(void **)p = (void *)v;\n  }\n}\n\n/* Allocate fixed-size C data object. */\nstatic LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz)\n{\n  GCcdata *cd;\n#ifdef LUA_USE_ASSERT\n  CType *ct = ctype_raw(cts, id);\n  lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz);\n#endif\n  cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz);\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = ctype_check(cts, id);\n  return cd;\n}\n\n/* Variant which works without a valid CTState. */\nstatic LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz)\n{\n  GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz);\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = id;\n  return cd;\n}\n\nLJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id);\nLJ_FUNC GCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz,\n\t\t\t       CTSize align);\nLJ_FUNC GCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz,\n\t\t\t       CTInfo info);\n\nLJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);\nLJ_FUNC void lj_cdata_setfin(lua_State *L, GCcdata *cd, GCobj *obj,\n\t\t\t     uint32_t it);\n\nLJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key,\n\t\t\t      uint8_t **pp, CTInfo *qual);\nLJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp);\nLJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o,\n\t\t\t  CTInfo qual);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_char.c",
    "content": "/*\n** Character types.\n** Donated to the public domain.\n**\n** This is intended to replace the problematic libc single-byte NLS functions.\n** These just don't make sense anymore with UTF-8 locales becoming the norm\n** on POSIX systems. It never worked too well on Windows systems since hardly\n** anyone bothered to call setlocale().\n**\n** This table is hardcoded for ASCII. Identifiers include the characters\n** 128-255, too. This allows for the use of all non-ASCII chars as identifiers\n** in the lexer. This is a broad definition, but works well in practice\n** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*).\n**\n** If you really need proper character types for UTF-8 strings, please use\n** an add-on library such as slnunicode: http://luaforge.net/projects/sln/\n*/\n\n#define lj_char_c\n#define LUA_CORE\n\n#include \"lj_char.h\"\n\nLJ_DATADEF const uint8_t lj_char_bits[257] = {\n    0,\n    1,  1,  1,  1,  1,  1,  1,  1,  1,  3,  3,  3,  3,  3,  1,  1,\n    1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,\n    2,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,\n  152,152,152,152,152,152,152,152,152,152,  4,  4,  4,  4,  4,  4,\n    4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160,\n  160,160,160,160,160,160,160,160,160,160,160,  4,  4,  4,  4,132,\n    4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,\n  192,192,192,192,192,192,192,192,192,192,192,  4,  4,  4,  4,  1,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128\n};\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_char.h",
    "content": "/*\n** Character types.\n** Donated to the public domain.\n*/\n\n#ifndef _LJ_CHAR_H\n#define _LJ_CHAR_H\n\n#include \"lj_def.h\"\n\n#define LJ_CHAR_CNTRL\t0x01\n#define LJ_CHAR_SPACE\t0x02\n#define LJ_CHAR_PUNCT\t0x04\n#define LJ_CHAR_DIGIT\t0x08\n#define LJ_CHAR_XDIGIT\t0x10\n#define LJ_CHAR_UPPER\t0x20\n#define LJ_CHAR_LOWER\t0x40\n#define LJ_CHAR_IDENT\t0x80\n#define LJ_CHAR_ALPHA\t(LJ_CHAR_LOWER|LJ_CHAR_UPPER)\n#define LJ_CHAR_ALNUM\t(LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)\n#define LJ_CHAR_GRAPH\t(LJ_CHAR_ALNUM|LJ_CHAR_PUNCT)\n\n/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */\n#define lj_char_isa(c, t)\t((lj_char_bits+1)[(c)] & t)\n#define lj_char_iscntrl(c)\tlj_char_isa((c), LJ_CHAR_CNTRL)\n#define lj_char_isspace(c)\tlj_char_isa((c), LJ_CHAR_SPACE)\n#define lj_char_ispunct(c)\tlj_char_isa((c), LJ_CHAR_PUNCT)\n#define lj_char_isdigit(c)\tlj_char_isa((c), LJ_CHAR_DIGIT)\n#define lj_char_isxdigit(c)\tlj_char_isa((c), LJ_CHAR_XDIGIT)\n#define lj_char_isupper(c)\tlj_char_isa((c), LJ_CHAR_UPPER)\n#define lj_char_islower(c)\tlj_char_isa((c), LJ_CHAR_LOWER)\n#define lj_char_isident(c)\tlj_char_isa((c), LJ_CHAR_IDENT)\n#define lj_char_isalpha(c)\tlj_char_isa((c), LJ_CHAR_ALPHA)\n#define lj_char_isalnum(c)\tlj_char_isa((c), LJ_CHAR_ALNUM)\n#define lj_char_isgraph(c)\tlj_char_isa((c), LJ_CHAR_GRAPH)\n\n#define lj_char_toupper(c)\t((c) - (lj_char_islower(c) >> 1))\n#define lj_char_tolower(c)\t((c) + lj_char_isupper(c))\n\nLJ_DATA const uint8_t lj_char_bits[257];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_clib.c",
    "content": "/*\n** FFI C library loader.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_str.h\"\n#include \"lj_udata.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_clib.h\"\n#include \"lj_strfmt.h\"\n\n/* -- OS-specific functions ----------------------------------------------- */\n\n#if LJ_TARGET_DLOPEN\n\n#include <dlfcn.h>\n#include <stdio.h>\n\n#if defined(RTLD_DEFAULT)\n#define CLIB_DEFHANDLE\tRTLD_DEFAULT\n#elif LJ_TARGET_OSX || LJ_TARGET_BSD\n#define CLIB_DEFHANDLE\t((void *)(intptr_t)-2)\n#else\n#define CLIB_DEFHANDLE\tNULL\n#endif\n\nLJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L)\n{\n  lj_err_callermsg(L, dlerror());\n}\n\n#define clib_error(L, fmt, name)\tclib_error_(L)\n\n#if defined(__CYGWIN__)\n#define CLIB_SOPREFIX\t\"cyg\"\n#else\n#define CLIB_SOPREFIX\t\"lib\"\n#endif\n\n#if LJ_TARGET_OSX\n#define CLIB_SOEXT\t\"%s.dylib\"\n#elif defined(__CYGWIN__)\n#define CLIB_SOEXT\t\"%s.dll\"\n#else\n#define CLIB_SOEXT\t\"%s.so\"\n#endif\n\nstatic const char *clib_extname(lua_State *L, const char *name)\n{\n  if (!strchr(name, '/')\n#ifdef __CYGWIN__\n      && !strchr(name, '\\\\')\n#endif\n     ) {\n    if (!strchr(name, '.')) {\n      name = lj_strfmt_pushf(L, CLIB_SOEXT, name);\n      L->top--;\n#ifdef __CYGWIN__\n    } else {\n      return name;\n#endif\n    }\n    if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] &&\n\t  name[2] == CLIB_SOPREFIX[2])) {\n      name = lj_strfmt_pushf(L, CLIB_SOPREFIX \"%s\", name);\n      L->top--;\n    }\n  }\n  return name;\n}\n\n/* Check for a recognized ld script line. */\nstatic const char *clib_check_lds(lua_State *L, const char *buf)\n{\n  char *p, *e;\n  if ((!strncmp(buf, \"GROUP\", 5) || !strncmp(buf, \"INPUT\", 5)) &&\n      (p = strchr(buf, '('))) {\n    while (*++p == ' ') ;\n    for (e = p; *e && *e != ' ' && *e != ')'; e++) ;\n    return strdata(lj_str_new(L, p, e-p));\n  }\n  return NULL;\n}\n\n/* Quick and dirty solution to resolve shared library name from ld script. */\nstatic const char *clib_resolve_lds(lua_State *L, const char *name)\n{\n  FILE *fp = fopen(name, \"r\");\n  const char *p = NULL;\n  if (fp) {\n    char buf[256];\n    if (fgets(buf, sizeof(buf), fp)) {\n      if (!strncmp(buf, \"/* GNU ld script\", 16)) {  /* ld script magic? */\n\twhile (fgets(buf, sizeof(buf), fp)) {  /* Check all lines. */\n\t  p = clib_check_lds(L, buf);\n\t  if (p) break;\n\t}\n      } else {  /* Otherwise check only the first line. */\n\tp = clib_check_lds(L, buf);\n      }\n    }\n    fclose(fp);\n  }\n  return p;\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  void *h = dlopen(clib_extname(L, name),\n\t\t   RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));\n  if (!h) {\n    const char *e, *err = dlerror();\n    if (*err == '/' && (e = strchr(err, ':')) &&\n\t(name = clib_resolve_lds(L, strdata(lj_str_new(L, err, e-err))))) {\n      h = dlopen(name, RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));\n      if (h) return h;\n      err = dlerror();\n    }\n    lj_err_callermsg(L, err);\n  }\n  return h;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  if (cl->handle && cl->handle != CLIB_DEFHANDLE)\n    dlclose(cl->handle);\n}\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  void *p = dlsym(cl->handle, name);\n  return p;\n}\n\n#elif LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\n#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\t4\n#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT\t2\nBOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);\n#endif\n\n#define CLIB_DEFHANDLE\t((void *)-1)\n\n/* Default libraries. */\nenum {\n  CLIB_HANDLE_EXE,\n  CLIB_HANDLE_DLL,\n  CLIB_HANDLE_CRT,\n  CLIB_HANDLE_KERNEL32,\n  CLIB_HANDLE_USER32,\n  CLIB_HANDLE_GDI32,\n  CLIB_HANDLE_MAX\n};\n\nstatic void *clib_def_handle[CLIB_HANDLE_MAX];\n\nLJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,\n\t\t\t\t\t    const char *name)\n{\n  DWORD err = GetLastError();\n#if LJ_TARGET_XBOXONE\n  wchar_t wbuf[128];\n  char buf[128*2];\n  if (!FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,\n\t\t      NULL, err, 0, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL) ||\n      !WideCharToMultiByte(CP_ACP, 0, wbuf, 128, buf, 128*2, NULL, NULL))\n#else\n  char buf[128];\n  if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,\n\t\t      NULL, err, 0, buf, sizeof(buf), NULL))\n#endif\n    buf[0] = '\\0';\n  lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, buf));\n}\n\nstatic int clib_needext(const char *s)\n{\n  while (*s) {\n    if (*s == '/' || *s == '\\\\' || *s == '.') return 0;\n    s++;\n  }\n  return 1;\n}\n\nstatic const char *clib_extname(lua_State *L, const char *name)\n{\n  if (clib_needext(name)) {\n    name = lj_strfmt_pushf(L, \"%s.dll\", name);\n    L->top--;\n  }\n  return name;\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  DWORD oldwerr = GetLastError();\n  void *h = (void *)LoadLibraryExA(clib_extname(L, name), NULL, 0);\n  if (!h) clib_error(L, \"cannot load module \" LUA_QS \": %s\", name);\n  SetLastError(oldwerr);\n  UNUSED(global);\n  return h;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  if (cl->handle == CLIB_DEFHANDLE) {\n    MSize i;\n    for (i = CLIB_HANDLE_KERNEL32; i < CLIB_HANDLE_MAX; i++) {\n      void *h = clib_def_handle[i];\n      if (h) {\n\tclib_def_handle[i] = NULL;\n\tFreeLibrary((HINSTANCE)h);\n      }\n    }\n  } else if (cl->handle) {\n    FreeLibrary((HINSTANCE)cl->handle);\n  }\n}\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  void *p = NULL;\n  if (cl->handle == CLIB_DEFHANDLE) {  /* Search default libraries. */\n    MSize i;\n    for (i = 0; i < CLIB_HANDLE_MAX; i++) {\n      HINSTANCE h = (HINSTANCE)clib_def_handle[i];\n      if (!(void *)h) {  /* Resolve default library handles (once). */\n\tswitch (i) {\n\tcase CLIB_HANDLE_EXE: GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, &h); break;\n\tcase CLIB_HANDLE_DLL:\n\t  GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t     (const char *)clib_def_handle, &h);\n\t  break;\n\tcase CLIB_HANDLE_CRT:\n\t  GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t     (const char *)&_fmode, &h);\n\t  break;\n\tcase CLIB_HANDLE_KERNEL32: h = LoadLibraryExA(\"kernel32.dll\", NULL, 0); break;\n\tcase CLIB_HANDLE_USER32: h = LoadLibraryExA(\"user32.dll\", NULL, 0); break;\n\tcase CLIB_HANDLE_GDI32: h = LoadLibraryExA(\"gdi32.dll\", NULL, 0); break;\n\t}\n\tif (!h) continue;\n\tclib_def_handle[i] = (void *)h;\n      }\n      p = (void *)GetProcAddress(h, name);\n      if (p) break;\n    }\n  } else {\n    p = (void *)GetProcAddress((HINSTANCE)cl->handle, name);\n  }\n  return p;\n}\n\n#else\n\n#define CLIB_DEFHANDLE\tNULL\n\nLJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,\n\t\t\t\t\t    const char *name)\n{\n  lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, \"no support for this OS\"));\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  lj_err_callermsg(L, \"no support for loading dynamic libraries for this OS\");\n  UNUSED(name); UNUSED(global);\n  return NULL;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  UNUSED(cl);\n}\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  UNUSED(cl); UNUSED(name);\n  return NULL;\n}\n\n#endif\n\n/* -- C library indexing -------------------------------------------------- */\n\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n/* Compute argument size for fastcall/stdcall functions. */\nstatic CTSize clib_func_argsize(CTState *cts, CType *ct)\n{\n  CTSize n = 0;\n  while (ct->sib) {\n    CType *d;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      d = ctype_rawchild(cts, ct);\n      n += ((d->size + 3) & ~3);\n    }\n  }\n  return n;\n}\n#endif\n\n/* Get redirected or mangled external symbol. */\nstatic const char *clib_extsym(CTState *cts, CType *ct, GCstr *name)\n{\n  if (ct->sib) {\n    CType *ctf = ctype_get(cts, ct->sib);\n    if (ctype_isxattrib(ctf->info, CTA_REDIR))\n      return strdata(gco2str(gcref(ctf->name)));\n  }\n  return strdata(name);\n}\n\n/* Index a C library by name. */\nTValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name)\n{\n  TValue *tv = lj_tab_setstr(L, cl->cache, name);\n  if (LJ_UNLIKELY(tvisnil(tv))) {\n    CTState *cts = ctype_cts(L);\n    CType *ct;\n    CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);\n    if (!id)\n      lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name));\n    if (ctype_isconstval(ct->info)) {\n      CType *ctt = ctype_child(cts, ct);\n      lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4);\n      if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)\n\tsetnumV(tv, (lua_Number)(uint32_t)ct->size);\n      else\n\tsetintV(tv, (int32_t)ct->size);\n    } else {\n      const char *sym = clib_extsym(cts, ct, name);\n#if LJ_TARGET_WINDOWS\n      DWORD oldwerr = GetLastError();\n#endif\n      void *p = clib_getsym(cl, sym);\n      GCcdata *cd;\n      lua_assert(ctype_isfunc(ct->info) || ctype_isextern(ct->info));\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n      /* Retry with decorated name for fastcall/stdcall functions. */\n      if (!p && ctype_isfunc(ct->info)) {\n\tCTInfo cconv = ctype_cconv(ct->info);\n\tif (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) {\n\t  CTSize sz = clib_func_argsize(cts, ct);\n\t  const char *symd = lj_strfmt_pushf(L,\n\t\t\t       cconv == CTCC_FASTCALL ? \"@%s@%d\" : \"_%s@%d\",\n\t\t\t       sym, sz);\n\t  L->top--;\n\t  p = clib_getsym(cl, symd);\n\t}\n      }\n#endif\n      if (!p)\n\tclib_error(L, \"cannot resolve symbol \" LUA_QS \": %s\", sym);\n#if LJ_TARGET_WINDOWS\n      SetLastError(oldwerr);\n#endif\n      cd = lj_cdata_new(cts, id, CTSIZE_PTR);\n      *(void **)cdataptr(cd) = p;\n      setcdataV(L, tv, cd);\n    }\n  }\n  return tv;\n}\n\n/* -- C library management ------------------------------------------------ */\n\n/* Create a new CLibrary object and push it on the stack. */\nstatic CLibrary *clib_new(lua_State *L, GCtab *mt)\n{\n  GCtab *t = lj_tab_new(L, 0, 0);\n  GCudata *ud = lj_udata_new(L, sizeof(CLibrary), t);\n  CLibrary *cl = (CLibrary *)uddata(ud);\n  cl->cache = t;\n  ud->udtype = UDTYPE_FFI_CLIB;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcref(ud->metatable, obj2gco(mt));\n  setudataV(L, L->top++, ud);\n  return cl;\n}\n\n/* Load a C library. */\nvoid lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global)\n{\n  void *handle = clib_loadlib(L, strdata(name), global);\n  CLibrary *cl = clib_new(L, mt);\n  cl->handle = handle;\n}\n\n/* Unload a C library. */\nvoid lj_clib_unload(CLibrary *cl)\n{\n  clib_unloadlib(cl);\n  cl->handle = NULL;\n}\n\n/* Create the default C library object. */\nvoid lj_clib_default(lua_State *L, GCtab *mt)\n{\n  CLibrary *cl = clib_new(L, mt);\n  cl->handle = CLIB_DEFHANDLE;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_clib.h",
    "content": "/*\n** FFI C library loader.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CLIB_H\n#define _LJ_CLIB_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n/* Namespace for C library indexing. */\n#define CLNS_INDEX\t((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))\n\n/* C library namespace. */\ntypedef struct CLibrary {\n  void *handle;\t\t/* Opaque handle for dynamic library loader. */\n  GCtab *cache;\t\t/* Cache for resolved symbols. Anchored in ud->env. */\n} CLibrary;\n\nLJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name);\nLJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global);\nLJ_FUNC void lj_clib_unload(CLibrary *cl);\nLJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cparse.c",
    "content": "/*\n** C declaration parser.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cparse.h\"\n#include \"lj_frame.h\"\n#include \"lj_vm.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/*\n** Important note: this is NOT a validating C parser! This is a minimal\n** C declaration parser, solely for use by the LuaJIT FFI.\n**\n** It ought to return correct results for properly formed C declarations,\n** but it may accept some invalid declarations, too (and return nonsense).\n** Also, it shows rather generic error messages to avoid unnecessary bloat.\n** If in doubt, please check the input against your favorite C compiler.\n*/\n\n/* -- C lexer ------------------------------------------------------------- */\n\n/* C lexer token names. */\nstatic const char *const ctoknames[] = {\n#define CTOKSTR(name, str)\tstr,\nCTOKDEF(CTOKSTR)\n#undef CTOKSTR\n  NULL\n};\n\n/* Forward declaration. */\nLJ_NORET static void cp_err(CPState *cp, ErrMsg em);\n\nstatic const char *cp_tok2str(CPState *cp, CPToken tok)\n{\n  lua_assert(tok < CTOK_FIRSTDECL);\n  if (tok > CTOK_OFS)\n    return ctoknames[tok-CTOK_OFS-1];\n  else if (!lj_char_iscntrl(tok))\n    return lj_strfmt_pushf(cp->L, \"%c\", tok);\n  else\n    return lj_strfmt_pushf(cp->L, \"char(%d)\", tok);\n}\n\n/* End-of-line? */\nstatic LJ_AINLINE int cp_iseol(CPChar c)\n{\n  return (c == '\\n' || c == '\\r');\n}\n\n/* Peek next raw character. */\nstatic LJ_AINLINE CPChar cp_rawpeek(CPState *cp)\n{\n  return (CPChar)(uint8_t)(*cp->p);\n}\n\nstatic LJ_NOINLINE CPChar cp_get_bs(CPState *cp);\n\n/* Get next character. */\nstatic LJ_AINLINE CPChar cp_get(CPState *cp)\n{\n  cp->c = (CPChar)(uint8_t)(*cp->p++);\n  if (LJ_LIKELY(cp->c != '\\\\')) return cp->c;\n  return cp_get_bs(cp);\n}\n\n/* Transparently skip backslash-escaped line breaks. */\nstatic LJ_NOINLINE CPChar cp_get_bs(CPState *cp)\n{\n  CPChar c2, c = cp_rawpeek(cp);\n  if (!cp_iseol(c)) return cp->c;\n  cp->p++;\n  c2 = cp_rawpeek(cp);\n  if (cp_iseol(c2) && c2 != c) cp->p++;\n  cp->linenumber++;\n  return cp_get(cp);\n}\n\n/* Save character in buffer. */\nstatic LJ_AINLINE void cp_save(CPState *cp, CPChar c)\n{\n  lj_buf_putb(&cp->sb, c);\n}\n\n/* Skip line break. Handles \"\\n\", \"\\r\", \"\\r\\n\" or \"\\n\\r\". */\nstatic void cp_newline(CPState *cp)\n{\n  CPChar c = cp_rawpeek(cp);\n  if (cp_iseol(c) && c != cp->c) cp->p++;\n  cp->linenumber++;\n}\n\nLJ_NORET static void cp_errmsg(CPState *cp, CPToken tok, ErrMsg em, ...)\n{\n  const char *msg, *tokstr;\n  lua_State *L;\n  va_list argp;\n  if (tok == 0) {\n    tokstr = NULL;\n  } else if (tok == CTOK_IDENT || tok == CTOK_INTEGER || tok == CTOK_STRING ||\n\t     tok >= CTOK_FIRSTDECL) {\n    if (sbufP(&cp->sb) == sbufB(&cp->sb)) cp_save(cp, '$');\n    cp_save(cp, '\\0');\n    tokstr = sbufB(&cp->sb);\n  } else {\n    tokstr = cp_tok2str(cp, tok);\n  }\n  L = cp->L;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  if (tokstr)\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tokstr);\n  if (cp->linenumber > 1)\n    msg = lj_strfmt_pushf(L, \"%s at line %d\", msg, cp->linenumber);\n  lj_err_callermsg(L, msg);\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err_token(CPState *cp, CPToken tok)\n{\n  cp_errmsg(cp, cp->tok, LJ_ERR_XTOKEN, cp_tok2str(cp, tok));\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err_badidx(CPState *cp, CType *ct)\n{\n  GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);\n  cp_errmsg(cp, 0, LJ_ERR_FFI_BADIDX, strdata(s));\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err(CPState *cp, ErrMsg em)\n{\n  cp_errmsg(cp, 0, em);\n}\n\n/* -- Main lexical scanner ------------------------------------------------ */\n\n/* Parse number literal. Only handles int32_t/uint32_t right now. */\nstatic CPToken cp_number(CPState *cp)\n{\n  StrScanFmt fmt;\n  TValue o;\n  do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));\n  cp_save(cp, '\\0');\n  fmt = lj_strscan_scan((const uint8_t *)sbufB(&cp->sb), &o, STRSCAN_OPT_C);\n  if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32;\n  else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32;\n  else if (!(cp->mode & CPARSE_MODE_SKIP))\n    cp_errmsg(cp, CTOK_INTEGER, LJ_ERR_XNUMBER);\n  cp->val.u32 = (uint32_t)o.i;\n  return CTOK_INTEGER;\n}\n\n/* Parse identifier or keyword. */\nstatic CPToken cp_ident(CPState *cp)\n{\n  do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));\n  cp->str = lj_buf_str(cp->L, &cp->sb);\n  cp->val.id = lj_ctype_getname(cp->cts, &cp->ct, cp->str, cp->tmask);\n  if (ctype_type(cp->ct->info) == CT_KW)\n    return ctype_cid(cp->ct->info);\n  return CTOK_IDENT;\n}\n\n/* Parse parameter. */\nstatic CPToken cp_param(CPState *cp)\n{\n  CPChar c = cp_get(cp);\n  TValue *o = cp->param;\n  if (lj_char_isident(c) || c == '$')  /* Reserve $xyz for future extensions. */\n    cp_errmsg(cp, c, LJ_ERR_XSYNTAX);\n  if (!o || o >= cp->L->top)\n    cp_err(cp, LJ_ERR_FFI_NUMPARAM);\n  cp->param = o+1;\n  if (tvisstr(o)) {\n    cp->str = strV(o);\n    cp->val.id = 0;\n    cp->ct = &cp->cts->tab[0];\n    return CTOK_IDENT;\n  } else if (tvisnumber(o)) {\n    cp->val.i32 = numberVint(o);\n    cp->val.id = CTID_INT32;\n    return CTOK_INTEGER;\n  } else {\n    GCcdata *cd;\n    if (!tviscdata(o))\n      lj_err_argtype(cp->L, (int)(o-cp->L->base)+1, \"type parameter\");\n    cd = cdataV(o);\n    if (cd->ctypeid == CTID_CTYPEID)\n      cp->val.id = *(CTypeID *)cdataptr(cd);\n    else\n      cp->val.id = cd->ctypeid;\n    return '$';\n  }\n}\n\n/* Parse string or character constant. */\nstatic CPToken cp_string(CPState *cp)\n{\n  CPChar delim = cp->c;\n  cp_get(cp);\n  while (cp->c != delim) {\n    CPChar c = cp->c;\n    if (c == '\\0') cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR);\n    if (c == '\\\\') {\n      c = cp_get(cp);\n      switch (c) {\n      case '\\0': cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); break;\n      case 'a': c = '\\a'; break;\n      case 'b': c = '\\b'; break;\n      case 'f': c = '\\f'; break;\n      case 'n': c = '\\n'; break;\n      case 'r': c = '\\r'; break;\n      case 't': c = '\\t'; break;\n      case 'v': c = '\\v'; break;\n      case 'e': c = 27; break;\n      case 'x':\n\tc = 0;\n\twhile (lj_char_isxdigit(cp_get(cp)))\n\t  c = (c<<4) + (lj_char_isdigit(cp->c) ? cp->c-'0' : (cp->c&15)+9);\n\tcp_save(cp, (c & 0xff));\n\tcontinue;\n      default:\n\tif (lj_char_isdigit(c)) {\n\t  c -= '0';\n\t  if (lj_char_isdigit(cp_get(cp))) {\n\t    c = c*8 + (cp->c - '0');\n\t    if (lj_char_isdigit(cp_get(cp))) {\n\t      c = c*8 + (cp->c - '0');\n\t      cp_get(cp);\n\t    }\n\t  }\n\t  cp_save(cp, (c & 0xff));\n\t  continue;\n\t}\n\tbreak;\n      }\n    }\n    cp_save(cp, c);\n    cp_get(cp);\n  }\n  cp_get(cp);\n  if (delim == '\"') {\n    cp->str = lj_buf_str(cp->L, &cp->sb);\n    return CTOK_STRING;\n  } else {\n    if (sbuflen(&cp->sb) != 1) cp_err_token(cp, '\\'');\n    cp->val.i32 = (int32_t)(char)*sbufB(&cp->sb);\n    cp->val.id = CTID_INT32;\n    return CTOK_INTEGER;\n  }\n}\n\n/* Skip C comment. */\nstatic void cp_comment_c(CPState *cp)\n{\n  do {\n    if (cp_get(cp) == '*') {\n      do {\n\tif (cp_get(cp) == '/') { cp_get(cp); return; }\n      } while (cp->c == '*');\n    }\n    if (cp_iseol(cp->c)) cp_newline(cp);\n  } while (cp->c != '\\0');\n}\n\n/* Skip C++ comment. */\nstatic void cp_comment_cpp(CPState *cp)\n{\n  while (!cp_iseol(cp_get(cp)) && cp->c != '\\0')\n    ;\n}\n\n/* Lexical scanner for C. Only a minimal subset is implemented. */\nstatic CPToken cp_next_(CPState *cp)\n{\n  lj_buf_reset(&cp->sb);\n  for (;;) {\n    if (lj_char_isident(cp->c))\n      return lj_char_isdigit(cp->c) ? cp_number(cp) : cp_ident(cp);\n    switch (cp->c) {\n    case '\\n': case '\\r': cp_newline(cp);  /* fallthrough. */\n    case ' ': case '\\t': case '\\v': case '\\f': cp_get(cp); break;\n    case '\"': case '\\'': return cp_string(cp);\n    case '/':\n      if (cp_get(cp) == '*') cp_comment_c(cp);\n      else if (cp->c == '/') cp_comment_cpp(cp);\n      else return '/';\n      break;\n    case '|':\n      if (cp_get(cp) != '|') return '|'; cp_get(cp); return CTOK_OROR;\n    case '&':\n      if (cp_get(cp) != '&') return '&'; cp_get(cp); return CTOK_ANDAND;\n    case '=':\n      if (cp_get(cp) != '=') return '='; cp_get(cp); return CTOK_EQ;\n    case '!':\n      if (cp_get(cp) != '=') return '!'; cp_get(cp); return CTOK_NE;\n    case '<':\n      if (cp_get(cp) == '=') { cp_get(cp); return CTOK_LE; }\n      else if (cp->c == '<') { cp_get(cp); return CTOK_SHL; }\n      return '<';\n    case '>':\n      if (cp_get(cp) == '=') { cp_get(cp); return CTOK_GE; }\n      else if (cp->c == '>') { cp_get(cp); return CTOK_SHR; }\n      return '>';\n    case '-':\n      if (cp_get(cp) != '>') return '-'; cp_get(cp); return CTOK_DEREF;\n    case '$':\n      return cp_param(cp);\n    case '\\0': return CTOK_EOF;\n    default: { CPToken c = cp->c; cp_get(cp); return c; }\n    }\n  }\n}\n\nstatic LJ_NOINLINE CPToken cp_next(CPState *cp)\n{\n  return (cp->tok = cp_next_(cp));\n}\n\n/* -- C parser ------------------------------------------------------------ */\n\n/* Namespaces for resolving identifiers. */\n#define CPNS_DEFAULT \\\n  ((1u<<CT_KW)|(1u<<CT_TYPEDEF)|(1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))\n#define CPNS_STRUCT\t((1u<<CT_KW)|(1u<<CT_STRUCT)|(1u<<CT_ENUM))\n\ntypedef CTypeID CPDeclIdx;\t/* Index into declaration stack. */\ntypedef uint32_t CPscl;\t\t/* Storage class flags. */\n\n/* Type declaration context. */\ntypedef struct CPDecl {\n  CPDeclIdx top;\t/* Top of declaration stack. */\n  CPDeclIdx pos;\t/* Insertion position in declaration chain. */\n  CPDeclIdx specpos;\t/* Saved position for declaration specifier. */\n  uint32_t mode;\t/* Declarator mode. */\n  CPState *cp;\t\t/* C parser state. */\n  GCstr *name;\t\t/* Name of declared identifier (if direct). */\n  GCstr *redir;\t\t/* Redirected symbol name. */\n  CTypeID nameid;\t/* Existing typedef for declared identifier. */\n  CTInfo attr;\t\t/* Attributes. */\n  CTInfo fattr;\t\t/* Function attributes. */\n  CTInfo specattr;\t/* Saved attributes. */\n  CTInfo specfattr;\t/* Saved function attributes. */\n  CTSize bits;\t\t/* Field size in bits (if any). */\n  CType stack[CPARSE_MAX_DECLSTACK];  /* Type declaration stack. */\n} CPDecl;\n\n/* Forward declarations. */\nstatic CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl);\nstatic void cp_declarator(CPState *cp, CPDecl *decl);\nstatic CTypeID cp_decl_abstract(CPState *cp);\n\n/* Initialize C parser state. Caller must set up: L, p, srcname, mode. */\nstatic void cp_init(CPState *cp)\n{\n  cp->linenumber = 1;\n  cp->depth = 0;\n  cp->curpack = 0;\n  cp->packstack[0] = 255;\n  lj_buf_init(cp->L, &cp->sb);\n  lua_assert(cp->p != NULL);\n  cp_get(cp);  /* Read-ahead first char. */\n  cp->tok = 0;\n  cp->tmask = CPNS_DEFAULT;\n  cp_next(cp);  /* Read-ahead first token. */\n}\n\n/* Cleanup C parser state. */\nstatic void cp_cleanup(CPState *cp)\n{\n  global_State *g = G(cp->L);\n  lj_buf_free(g, &cp->sb);\n}\n\n/* Check and consume optional token. */\nstatic int cp_opt(CPState *cp, CPToken tok)\n{\n  if (cp->tok == tok) { cp_next(cp); return 1; }\n  return 0;\n}\n\n/* Check and consume token. */\nstatic void cp_check(CPState *cp, CPToken tok)\n{\n  if (cp->tok != tok) cp_err_token(cp, tok);\n  cp_next(cp);\n}\n\n/* Check if the next token may start a type declaration. */\nstatic int cp_istypedecl(CPState *cp)\n{\n  if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECL) return 1;\n  if (cp->tok == CTOK_IDENT && ctype_istypedef(cp->ct->info)) return 1;\n  if (cp->tok == '$') return 1;\n  return 0;\n}\n\n/* -- Constant expression evaluator --------------------------------------- */\n\n/* Forward declarations. */\nstatic void cp_expr_unary(CPState *cp, CPValue *k);\nstatic void cp_expr_sub(CPState *cp, CPValue *k, int pri);\n\n/* Please note that type handling is very weak here. Most ops simply\n** assume integer operands. Accessors are only needed to compute types and\n** return synthetic values. The only purpose of the expression evaluator\n** is to compute the values of constant expressions one would typically\n** find in C header files. And again: this is NOT a validating C parser!\n*/\n\n/* Parse comma separated expression and return last result. */\nstatic void cp_expr_comma(CPState *cp, CPValue *k)\n{\n  do { cp_expr_sub(cp, k, 0); } while (cp_opt(cp, ','));\n}\n\n/* Parse sizeof/alignof operator. */\nstatic void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz)\n{\n  CTSize sz;\n  CTInfo info;\n  if (cp_opt(cp, '(')) {\n    if (cp_istypedecl(cp))\n      k->id = cp_decl_abstract(cp);\n    else\n      cp_expr_comma(cp, k);\n    cp_check(cp, ')');\n  } else {\n    cp_expr_unary(cp, k);\n  }\n  info = lj_ctype_info(cp->cts, k->id, &sz);\n  if (wantsz) {\n    if (sz != CTSIZE_INVALID)\n      k->u32 = sz;\n    else if (k->id != CTID_A_CCHAR)  /* Special case for sizeof(\"string\"). */\n      cp_err(cp, LJ_ERR_FFI_INVSIZE);\n  } else {\n    k->u32 = 1u << ctype_align(info);\n  }\n  k->id = CTID_UINT32;  /* Really size_t. */\n}\n\n/* Parse prefix operators. */\nstatic void cp_expr_prefix(CPState *cp, CPValue *k)\n{\n  if (cp->tok == CTOK_INTEGER) {\n    *k = cp->val; cp_next(cp);\n  } else if (cp_opt(cp, '+')) {\n    cp_expr_unary(cp, k);  /* Nothing to do (well, integer promotion). */\n  } else if (cp_opt(cp, '-')) {\n    cp_expr_unary(cp, k); k->i32 = -k->i32;\n  } else if (cp_opt(cp, '~')) {\n    cp_expr_unary(cp, k); k->i32 = ~k->i32;\n  } else if (cp_opt(cp, '!')) {\n    cp_expr_unary(cp, k); k->i32 = !k->i32; k->id = CTID_INT32;\n  } else if (cp_opt(cp, '(')) {\n    if (cp_istypedecl(cp)) {  /* Cast operator. */\n      CTypeID id = cp_decl_abstract(cp);\n      cp_check(cp, ')');\n      cp_expr_unary(cp, k);\n      k->id = id;  /* No conversion performed. */\n    } else {  /* Sub-expression. */\n      cp_expr_comma(cp, k);\n      cp_check(cp, ')');\n    }\n  } else if (cp_opt(cp, '*')) {  /* Indirection. */\n    CType *ct;\n    cp_expr_unary(cp, k);\n    ct = lj_ctype_rawref(cp->cts, k->id);\n    if (!ctype_ispointer(ct->info))\n      cp_err_badidx(cp, ct);\n    k->u32 = 0; k->id = ctype_cid(ct->info);\n  } else if (cp_opt(cp, '&')) {  /* Address operator. */\n    cp_expr_unary(cp, k);\n    k->id = lj_ctype_intern(cp->cts, CTINFO(CT_PTR, CTALIGN_PTR+k->id),\n\t\t\t    CTSIZE_PTR);\n  } else if (cp_opt(cp, CTOK_SIZEOF)) {\n    cp_expr_sizeof(cp, k, 1);\n  } else if (cp_opt(cp, CTOK_ALIGNOF)) {\n    cp_expr_sizeof(cp, k, 0);\n  } else if (cp->tok == CTOK_IDENT) {\n    if (ctype_type(cp->ct->info) == CT_CONSTVAL) {\n      k->u32 = cp->ct->size; k->id = ctype_cid(cp->ct->info);\n    } else if (ctype_type(cp->ct->info) == CT_EXTERN) {\n      k->u32 = cp->val.id; k->id = ctype_cid(cp->ct->info);\n    } else if (ctype_type(cp->ct->info) == CT_FUNC) {\n      k->u32 = cp->val.id; k->id = cp->val.id;\n    } else {\n      goto err_expr;\n    }\n    cp_next(cp);\n  } else if (cp->tok == CTOK_STRING) {\n    CTSize sz = cp->str->len;\n    while (cp_next(cp) == CTOK_STRING)\n      sz += cp->str->len;\n    k->u32 = sz + 1;\n    k->id = CTID_A_CCHAR;\n  } else {\n  err_expr:\n    cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n  }\n}\n\n/* Parse postfix operators. */\nstatic void cp_expr_postfix(CPState *cp, CPValue *k)\n{\n  for (;;) {\n    CType *ct;\n    if (cp_opt(cp, '[')) {  /* Array/pointer index. */\n      CPValue k2;\n      cp_expr_comma(cp, &k2);\n      ct = lj_ctype_rawref(cp->cts, k->id);\n      if (!ctype_ispointer(ct->info)) {\n\tct = lj_ctype_rawref(cp->cts, k2.id);\n\tif (!ctype_ispointer(ct->info))\n\t  cp_err_badidx(cp, ct);\n      }\n      cp_check(cp, ']');\n      k->u32 = 0;\n    } else if (cp->tok == '.' || cp->tok == CTOK_DEREF) {  /* Struct deref. */\n      CTSize ofs;\n      CType *fct;\n      ct = lj_ctype_rawref(cp->cts, k->id);\n      if (cp->tok == CTOK_DEREF) {\n\tif (!ctype_ispointer(ct->info))\n\t  cp_err_badidx(cp, ct);\n\tct = lj_ctype_rawref(cp->cts, ctype_cid(ct->info));\n      }\n      cp_next(cp);\n      if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n      if (!ctype_isstruct(ct->info) || ct->size == CTSIZE_INVALID ||\n\t  !(fct = lj_ctype_getfield(cp->cts, ct, cp->str, &ofs)) ||\n\t  ctype_isbitfield(fct->info)) {\n\tGCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_BADMEMBER, strdata(s), strdata(cp->str));\n      }\n      ct = fct;\n      k->u32 = ctype_isconstval(ct->info) ? ct->size : 0;\n      cp_next(cp);\n    } else {\n      return;\n    }\n    k->id = ctype_cid(ct->info);\n  }\n}\n\n/* Parse infix operators. */\nstatic void cp_expr_infix(CPState *cp, CPValue *k, int pri)\n{\n  CPValue k2;\n  k2.u32 = 0; k2.id = 0;  /* Silence the compiler. */\n  for (;;) {\n    switch (pri) {\n    case 0:\n      if (cp_opt(cp, '?')) {\n\tCPValue k3;\n\tcp_expr_comma(cp, &k2);  /* Right-associative. */\n\tcp_check(cp, ':');\n\tcp_expr_sub(cp, &k3, 0);\n\tk->u32 = k->u32 ? k2.u32 : k3.u32;\n\tk->id = k2.id > k3.id ? k2.id : k3.id;\n\tcontinue;\n      }\n    case 1:\n      if (cp_opt(cp, CTOK_OROR)) {\n\tcp_expr_sub(cp, &k2, 2); k->i32 = k->u32 || k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n    case 2:\n      if (cp_opt(cp, CTOK_ANDAND)) {\n\tcp_expr_sub(cp, &k2, 3); k->i32 = k->u32 && k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n    case 3:\n      if (cp_opt(cp, '|')) {\n\tcp_expr_sub(cp, &k2, 4); k->u32 = k->u32 | k2.u32; goto arith_result;\n      }\n    case 4:\n      if (cp_opt(cp, '^')) {\n\tcp_expr_sub(cp, &k2, 5); k->u32 = k->u32 ^ k2.u32; goto arith_result;\n      }\n    case 5:\n      if (cp_opt(cp, '&')) {\n\tcp_expr_sub(cp, &k2, 6); k->u32 = k->u32 & k2.u32; goto arith_result;\n      }\n    case 6:\n      if (cp_opt(cp, CTOK_EQ)) {\n\tcp_expr_sub(cp, &k2, 7); k->i32 = k->u32 == k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_NE)) {\n\tcp_expr_sub(cp, &k2, 7); k->i32 = k->u32 != k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n    case 7:\n      if (cp_opt(cp, '<')) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 < k2.i32;\n\telse\n\t  k->i32 = k->u32 < k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, '>')) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 > k2.i32;\n\telse\n\t  k->i32 = k->u32 > k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_LE)) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 <= k2.i32;\n\telse\n\t  k->i32 = k->u32 <= k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_GE)) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 >= k2.i32;\n\telse\n\t  k->i32 = k->u32 >= k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      }\n    case 8:\n      if (cp_opt(cp, CTOK_SHL)) {\n\tcp_expr_sub(cp, &k2, 9); k->u32 = k->u32 << k2.u32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_SHR)) {\n\tcp_expr_sub(cp, &k2, 9);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 >> k2.i32;\n\telse\n\t  k->u32 = k->u32 >> k2.u32;\n\tcontinue;\n      }\n    case 9:\n      if (cp_opt(cp, '+')) {\n\tcp_expr_sub(cp, &k2, 10); k->u32 = k->u32 + k2.u32;\n      arith_result:\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tcontinue;\n      } else if (cp_opt(cp, '-')) {\n\tcp_expr_sub(cp, &k2, 10); k->u32 = k->u32 - k2.u32; goto arith_result;\n      }\n    case 10:\n      if (cp_opt(cp, '*')) {\n\tcp_expr_unary(cp, &k2); k->u32 = k->u32 * k2.u32; goto arith_result;\n      } else if (cp_opt(cp, '/')) {\n\tcp_expr_unary(cp, &k2);\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tif (k2.u32 == 0 ||\n\t    (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))\n\t  cp_err(cp, LJ_ERR_BADVAL);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 / k2.i32;\n\telse\n\t  k->u32 = k->u32 / k2.u32;\n\tcontinue;\n      } else if (cp_opt(cp, '%')) {\n\tcp_expr_unary(cp, &k2);\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tif (k2.u32 == 0 ||\n\t    (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))\n\t  cp_err(cp, LJ_ERR_BADVAL);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 % k2.i32;\n\telse\n\t  k->u32 = k->u32 % k2.u32;\n\tcontinue;\n      }\n    default:\n      return;\n    }\n  }\n}\n\n/* Parse and evaluate unary expression. */\nstatic void cp_expr_unary(CPState *cp, CPValue *k)\n{\n  if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);\n  cp_expr_prefix(cp, k);\n  cp_expr_postfix(cp, k);\n  cp->depth--;\n}\n\n/* Parse and evaluate sub-expression. */\nstatic void cp_expr_sub(CPState *cp, CPValue *k, int pri)\n{\n  cp_expr_unary(cp, k);\n  cp_expr_infix(cp, k, pri);\n}\n\n/* Parse constant integer expression. */\nstatic void cp_expr_kint(CPState *cp, CPValue *k)\n{\n  CType *ct;\n  cp_expr_sub(cp, k, 0);\n  ct = ctype_raw(cp->cts, k->id);\n  if (!ctype_isinteger(ct->info)) cp_err(cp, LJ_ERR_BADVAL);\n}\n\n/* Parse (non-negative) size expression. */\nstatic CTSize cp_expr_ksize(CPState *cp)\n{\n  CPValue k;\n  cp_expr_kint(cp, &k);\n  if (k.u32 >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);\n  return k.u32;\n}\n\n/* -- Type declaration stack management ----------------------------------- */\n\n/* Add declaration element behind the insertion position. */\nstatic CPDeclIdx cp_add(CPDecl *decl, CTInfo info, CTSize size)\n{\n  CPDeclIdx top = decl->top;\n  if (top >= CPARSE_MAX_DECLSTACK) cp_err(decl->cp, LJ_ERR_XLEVELS);\n  decl->stack[top].info = info;\n  decl->stack[top].size = size;\n  decl->stack[top].sib = 0;\n  setgcrefnull(decl->stack[top].name);\n  decl->stack[top].next = decl->stack[decl->pos].next;\n  decl->stack[decl->pos].next = (CTypeID1)top;\n  decl->top = top+1;\n  return top;\n}\n\n/* Push declaration element before the insertion position. */\nstatic CPDeclIdx cp_push(CPDecl *decl, CTInfo info, CTSize size)\n{\n  return (decl->pos = cp_add(decl, info, size));\n}\n\n/* Push or merge attributes. */\nstatic void cp_push_attributes(CPDecl *decl)\n{\n  CType *ct = &decl->stack[decl->pos];\n  if (ctype_isfunc(ct->info)) {  /* Ok to modify in-place. */\n#if LJ_TARGET_X86\n    if ((decl->fattr & CTFP_CCONV))\n      ct->info = (ct->info & (CTMASK_NUM|CTF_VARARG|CTMASK_CID)) +\n\t\t (decl->fattr & ~CTMASK_CID);\n#endif\n  } else {\n    if ((decl->attr & CTFP_ALIGNED) && !(decl->mode & CPARSE_MODE_FIELD))\n      cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_ALIGN)),\n\t      ctype_align(decl->attr));\n  }\n}\n\n/* Push unrolled type to declaration stack and merge qualifiers. */\nstatic void cp_push_type(CPDecl *decl, CTypeID id)\n{\n  CType *ct = ctype_get(decl->cp->cts, id);\n  CTInfo info = ct->info;\n  CTSize size = ct->size;\n  switch (ctype_type(info)) {\n  case CT_STRUCT: case CT_ENUM:\n    cp_push(decl, CTINFO(CT_TYPEDEF, id), 0);  /* Don't copy unique types. */\n    if ((decl->attr & CTF_QUAL)) {  /* Push unmerged qualifiers. */\n      cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_QUAL)),\n\t      (decl->attr & CTF_QUAL));\n      decl->attr &= ~CTF_QUAL;\n    }\n    break;\n  case CT_ATTRIB:\n    if (ctype_isxattrib(info, CTA_QUAL))\n      decl->attr &= ~size;  /* Remove redundant qualifiers. */\n    cp_push_type(decl, ctype_cid(info));  /* Unroll. */\n    cp_push(decl, info & ~CTMASK_CID, size);  /* Copy type. */\n    break;\n  case CT_ARRAY:\n    if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {\n      info |= (decl->attr & CTF_QUAL);\n      decl->attr &= ~CTF_QUAL;\n    }\n    cp_push_type(decl, ctype_cid(info));  /* Unroll. */\n    cp_push(decl, info & ~CTMASK_CID, size);  /* Copy type. */\n    decl->stack[decl->pos].sib = 1;  /* Mark as already checked and sized. */\n    /* Note: this is not copied to the ct->sib in the C type table. */\n    break;\n  case CT_FUNC:\n    /* Copy type, link parameters (shared). */\n    decl->stack[cp_push(decl, info, size)].sib = ct->sib;\n    break;\n  default:\n    /* Copy type, merge common qualifiers. */\n    cp_push(decl, info|(decl->attr & CTF_QUAL), size);\n    decl->attr &= ~CTF_QUAL;\n    break;\n  }\n}\n\n/* Consume the declaration element chain and intern the C type. */\nstatic CTypeID cp_decl_intern(CPState *cp, CPDecl *decl)\n{\n  CTypeID id = 0;\n  CPDeclIdx idx = 0;\n  CTSize csize = CTSIZE_INVALID;\n  CTSize cinfo = 0;\n  do {\n    CType *ct = &decl->stack[idx];\n    CTInfo info = ct->info;\n    CTInfo size = ct->size;\n    /* The cid is already part of info for copies of pointers/functions. */\n    idx = ct->next;\n    if (ctype_istypedef(info)) {\n      lua_assert(id == 0);\n      id = ctype_cid(info);\n      /* Always refetch info/size, since struct/enum may have been completed. */\n      cinfo = ctype_get(cp->cts, id)->info;\n      csize = ctype_get(cp->cts, id)->size;\n      lua_assert(ctype_isstruct(cinfo) || ctype_isenum(cinfo));\n    } else if (ctype_isfunc(info)) {  /* Intern function. */\n      CType *fct;\n      CTypeID fid;\n      CTypeID sib;\n      if (id) {\n\tCType *refct = ctype_raw(cp->cts, id);\n\t/* Reject function or refarray return types. */\n\tif (ctype_isfunc(refct->info) || ctype_isrefarray(refct->info))\n\t  cp_err(cp, LJ_ERR_FFI_INVTYPE);\n      }\n      /* No intervening attributes allowed, skip forward. */\n      while (idx) {\n\tCType *ctn = &decl->stack[idx];\n\tif (!ctype_isattrib(ctn->info)) break;\n\tidx = ctn->next;  /* Skip attribute. */\n      }\n      sib = ct->sib;  /* Next line may reallocate the C type table. */\n      fid = lj_ctype_new(cp->cts, &fct);\n      csize = CTSIZE_INVALID;\n      fct->info = cinfo = info + id;\n      fct->size = size;\n      fct->sib = sib;\n      id = fid;\n    } else if (ctype_isattrib(info)) {\n      if (ctype_isxattrib(info, CTA_QUAL))\n\tcinfo |= size;\n      else if (ctype_isxattrib(info, CTA_ALIGN))\n\tCTF_INSERT(cinfo, ALIGN, size);\n      id = lj_ctype_intern(cp->cts, info+id, size);\n      /* Inherit csize/cinfo from original type. */\n    } else {\n      if (ctype_isnum(info)) {  /* Handle mode/vector-size attributes. */\n\tlua_assert(id == 0);\n\tif (!(info & CTF_BOOL)) {\n\t  CTSize msize = ctype_msizeP(decl->attr);\n\t  CTSize vsize = ctype_vsizeP(decl->attr);\n\t  if (msize && (!(info & CTF_FP) || (msize == 4 || msize == 8))) {\n\t    CTSize malign = lj_fls(msize);\n\t    if (malign > 4) malign = 4;  /* Limit alignment. */\n\t    CTF_INSERT(info, ALIGN, malign);\n\t    size = msize;  /* Override size via mode. */\n\t  }\n\t  if (vsize) {  /* Vector size set? */\n\t    CTSize esize = lj_fls(size);\n\t    if (vsize >= esize) {\n\t      /* Intern the element type first. */\n\t      id = lj_ctype_intern(cp->cts, info, size);\n\t      /* Then create a vector (array) with vsize alignment. */\n\t      size = (1u << vsize);\n\t      if (vsize > 4) vsize = 4;  /* Limit alignment. */\n\t      if (ctype_align(info) > vsize) vsize = ctype_align(info);\n\t      info = CTINFO(CT_ARRAY, (info & CTF_QUAL) + CTF_VECTOR +\n\t\t\t\t      CTALIGN(vsize));\n\t    }\n\t  }\n\t}\n      } else if (ctype_isptr(info)) {\n\t/* Reject pointer/ref to ref. */\n\tif (id && ctype_isref(ctype_raw(cp->cts, id)->info))\n\t  cp_err(cp, LJ_ERR_FFI_INVTYPE);\n\tif (ctype_isref(info)) {\n\t  info &= ~CTF_VOLATILE;  /* Refs are always const, never volatile. */\n\t  /* No intervening attributes allowed, skip forward. */\n\t  while (idx) {\n\t    CType *ctn = &decl->stack[idx];\n\t    if (!ctype_isattrib(ctn->info)) break;\n\t    idx = ctn->next;  /* Skip attribute. */\n\t  }\n\t}\n      } else if (ctype_isarray(info)) {  /* Check for valid array size etc. */\n\tif (ct->sib == 0) {  /* Only check/size arrays not copied by unroll. */\n\t  if (ctype_isref(cinfo))  /* Reject arrays of refs. */\n\t    cp_err(cp, LJ_ERR_FFI_INVTYPE);\n\t  /* Reject VLS or unknown-sized types. */\n\t  if (ctype_isvltype(cinfo) || csize == CTSIZE_INVALID)\n\t    cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\t  /* a[] and a[?] keep their invalid size. */\n\t  if (size != CTSIZE_INVALID) {\n\t    uint64_t xsz = (uint64_t)size * csize;\n\t    if (xsz >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\t    size = (CTSize)xsz;\n\t  }\n\t}\n\tif ((cinfo & CTF_ALIGN) > (info & CTF_ALIGN))  /* Find max. align. */\n\t  info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN);\n\tinfo |= (cinfo & CTF_QUAL);  /* Inherit qual. */\n      } else {\n\tlua_assert(ctype_isvoid(info));\n      }\n      csize = size;\n      cinfo = info+id;\n      id = lj_ctype_intern(cp->cts, info+id, size);\n    }\n  } while (idx);\n  return id;\n}\n\n/* -- C declaration parser ------------------------------------------------ */\n\n#define H_(le, be)\tLJ_ENDIAN_SELECT(0x##le, 0x##be)\n\n/* Reset declaration state to declaration specifier. */\nstatic void cp_decl_reset(CPDecl *decl)\n{\n  decl->pos = decl->specpos;\n  decl->top = decl->specpos+1;\n  decl->stack[decl->specpos].next = 0;\n  decl->attr = decl->specattr;\n  decl->fattr = decl->specfattr;\n  decl->name = NULL;\n  decl->redir = NULL;\n}\n\n/* Parse constant initializer. */\n/* NYI: FP constants and strings as initializers. */\nstatic CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID ctypeid)\n{\n  CType *ctt = ctype_get(cp->cts, ctypeid);\n  CTInfo info;\n  CTSize size;\n  CPValue k;\n  CTypeID constid;\n  while (ctype_isattrib(ctt->info)) {  /* Skip attributes. */\n    ctypeid = ctype_cid(ctt->info);  /* Update ID, too. */\n    ctt = ctype_get(cp->cts, ctypeid);\n  }\n  info = ctt->info;\n  size = ctt->size;\n  if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4)\n    cp_err(cp, LJ_ERR_FFI_INVTYPE);\n  cp_check(cp, '=');\n  cp_expr_sub(cp, &k, 0);\n  constid = lj_ctype_new(cp->cts, ctp);\n  (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|ctypeid);\n  k.u32 <<= 8*(4-size);\n  if ((info & CTF_UNSIGNED))\n    k.u32 >>= 8*(4-size);\n  else\n    k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size));\n  (*ctp)->size = k.u32;\n  return constid;\n}\n\n/* Parse size in parentheses as part of attribute. */\nstatic CTSize cp_decl_sizeattr(CPState *cp)\n{\n  CTSize sz;\n  uint32_t oldtmask = cp->tmask;\n  cp->tmask = CPNS_DEFAULT;  /* Required for expression evaluator. */\n  cp_check(cp, '(');\n  sz = cp_expr_ksize(cp);\n  cp->tmask = oldtmask;\n  cp_check(cp, ')');\n  return sz;\n}\n\n/* Parse alignment attribute. */\nstatic void cp_decl_align(CPState *cp, CPDecl *decl)\n{\n  CTSize al = 4;  /* Unspecified alignment is 16 bytes. */\n  if (cp->tok == '(') {\n    al = cp_decl_sizeattr(cp);\n    al = al ? lj_fls(al) : 0;\n  }\n  CTF_INSERT(decl->attr, ALIGN, al);\n  decl->attr |= CTFP_ALIGNED;\n}\n\n/* Parse GCC asm(\"name\") redirect. */\nstatic void cp_decl_asm(CPState *cp, CPDecl *decl)\n{\n  UNUSED(decl);\n  cp_next(cp);\n  cp_check(cp, '(');\n  if (cp->tok == CTOK_STRING) {\n    GCstr *str = cp->str;\n    while (cp_next(cp) == CTOK_STRING) {\n      lj_strfmt_pushf(cp->L, \"%s%s\", strdata(str), strdata(cp->str));\n      cp->L->top--;\n      str = strV(cp->L->top);\n    }\n    decl->redir = str;\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse GCC __attribute__((mode(...))). */\nstatic void cp_decl_mode(CPState *cp, CPDecl *decl)\n{\n  cp_check(cp, '(');\n  if (cp->tok == CTOK_IDENT) {\n    const char *s = strdata(cp->str);\n    CTSize sz = 0, vlen = 0;\n    if (s[0] == '_' && s[1] == '_') s += 2;\n    if (*s == 'V') {\n      s++;\n      vlen = *s++ - '0';\n      if (*s >= '0' && *s <= '9')\n\tvlen = vlen*10 + (*s++ - '0');\n    }\n    switch (*s++) {\n    case 'Q': sz = 1; break;\n    case 'H': sz = 2; break;\n    case 'S': sz = 4; break;\n    case 'D': sz = 8; break;\n    case 'T': sz = 16; break;\n    case 'O': sz = 32; break;\n    default: goto bad_size;\n    }\n    if (*s == 'I' || *s == 'F') {\n      CTF_INSERT(decl->attr, MSIZEP, sz);\n      if (vlen) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vlen*sz));\n    }\n  bad_size:\n    cp_next(cp);\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse GCC __attribute__((...)). */\nstatic void cp_decl_gccattribute(CPState *cp, CPDecl *decl)\n{\n  cp_next(cp);\n  cp_check(cp, '(');\n  cp_check(cp, '(');\n  while (cp->tok != ')') {\n    if (cp->tok == CTOK_IDENT) {\n      GCstr *attrstr = cp->str;\n      cp_next(cp);\n      switch (attrstr->hash) {\n      case H_(64a9208e,8ce14319): case H_(8e6331b2,95a282af):  /* aligned */\n\tcp_decl_align(cp, decl);\n\tbreak;\n      case H_(42eb47de,f0ede26c): case H_(29f48a09,cf383e0c):  /* packed */\n\tdecl->attr |= CTFP_PACKED;\n\tbreak;\n      case H_(0a84eef6,8dfab04c): case H_(995cf92c,d5696591):  /* mode */\n\tcp_decl_mode(cp, decl);\n\tbreak;\n      case H_(0ab31997,2d5213fa): case H_(bf875611,200e9990):  /* vector_size */\n\t{\n\t  CTSize vsize = cp_decl_sizeattr(cp);\n\t  if (vsize) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vsize));\n\t}\n\tbreak;\n#if LJ_TARGET_X86\n      case H_(5ad22db8,c689b848): case H_(439150fa,65ea78cb):  /* regparm */\n\tCTF_INSERT(decl->fattr, REGPARM, cp_decl_sizeattr(cp));\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case H_(18fc0b98,7ff4c074): case H_(4e62abed,0a747424):  /* cdecl */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_CDECL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case H_(72b2e41b,494c5a44): case H_(f2356d59,f25fc9bd):  /* thiscall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_THISCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case H_(0d0ffc42,ab746f88): case H_(21c54ba1,7f0ca7e3):  /* fastcall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_FASTCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case H_(ef76b040,9412e06a): case H_(de56697b,c750e6e1):  /* stdcall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_STDCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case H_(ea78b622,f234bd8e): case H_(252ffb06,8d50f34b):  /* sseregparm */\n\tdecl->fattr |= CTF_SSEREGPARM;\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n#endif\n      default:  /* Skip all other attributes. */\n\tgoto skip_attr;\n      }\n    } else if (cp->tok >= CTOK_FIRSTDECL) {  /* For __attribute((const)) etc. */\n      cp_next(cp);\n    skip_attr:\n      if (cp_opt(cp, '(')) {\n\twhile (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);\n\tcp_check(cp, ')');\n      }\n    } else {\n      break;\n    }\n    if (!cp_opt(cp, ',')) break;\n  }\n  cp_check(cp, ')');\n  cp_check(cp, ')');\n}\n\n/* Parse MSVC __declspec(...). */\nstatic void cp_decl_msvcattribute(CPState *cp, CPDecl *decl)\n{\n  cp_next(cp);\n  cp_check(cp, '(');\n  while (cp->tok == CTOK_IDENT) {\n    GCstr *attrstr = cp->str;\n    cp_next(cp);\n    switch (attrstr->hash) {\n    case H_(bc2395fa,98f267f8):  /* align */\n      cp_decl_align(cp, decl);\n      break;\n    default:  /* Ignore all other attributes. */\n      if (cp_opt(cp, '(')) {\n\twhile (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);\n\tcp_check(cp, ')');\n      }\n      break;\n    }\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse declaration attributes (and common qualifiers). */\nstatic void cp_decl_attributes(CPState *cp, CPDecl *decl)\n{\n  for (;;) {\n    switch (cp->tok) {\n    case CTOK_CONST: decl->attr |= CTF_CONST; break;\n    case CTOK_VOLATILE: decl->attr |= CTF_VOLATILE; break;\n    case CTOK_RESTRICT: break;  /* Ignore. */\n    case CTOK_EXTENSION: break;  /* Ignore. */\n    case CTOK_ATTRIBUTE: cp_decl_gccattribute(cp, decl); continue;\n    case CTOK_ASM: cp_decl_asm(cp, decl); continue;\n    case CTOK_DECLSPEC: cp_decl_msvcattribute(cp, decl); continue;\n    case CTOK_CCDECL:\n#if LJ_TARGET_X86\n      CTF_INSERT(decl->fattr, CCONV, cp->ct->size);\n      decl->fattr |= CTFP_CCONV;\n#endif\n      break;\n    case CTOK_PTRSZ:\n#if LJ_64\n      CTF_INSERT(decl->attr, MSIZEP, cp->ct->size);\n#endif\n      break;\n    default: return;\n    }\n    cp_next(cp);\n  }\n}\n\n/* Parse struct/union/enum name. */\nstatic CTypeID cp_struct_name(CPState *cp, CPDecl *sdecl, CTInfo info)\n{\n  CTypeID sid;\n  CType *ct;\n  cp->tmask = CPNS_STRUCT;\n  cp_next(cp);\n  cp_decl_attributes(cp, sdecl);\n  cp->tmask = CPNS_DEFAULT;\n  if (cp->tok != '{') {\n    if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n    if (cp->val.id) {  /* Name of existing struct/union/enum. */\n      sid = cp->val.id;\n      ct = cp->ct;\n      if ((ct->info ^ info) & (CTMASK_NUM|CTF_UNION))  /* Wrong type. */\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));\n    } else {  /* Create named, incomplete struct/union/enum. */\n      if ((cp->mode & CPARSE_MODE_NOIMPLICIT))\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_BADTAG, strdata(cp->str));\n      sid = lj_ctype_new(cp->cts, &ct);\n      ct->info = info;\n      ct->size = CTSIZE_INVALID;\n      ctype_setname(ct, cp->str);\n      lj_ctype_addname(cp->cts, ct, sid);\n    }\n    cp_next(cp);\n  } else {  /* Create anonymous, incomplete struct/union/enum. */\n    sid = lj_ctype_new(cp->cts, &ct);\n    ct->info = info;\n    ct->size = CTSIZE_INVALID;\n  }\n  if (cp->tok == '{') {\n    if (ct->size != CTSIZE_INVALID || ct->sib)\n      cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));\n    ct->sib = 1;  /* Indicate the type is currently being defined. */\n  }\n  return sid;\n}\n\n/* Determine field alignment. */\nstatic CTSize cp_field_align(CPState *cp, CType *ct, CTInfo info)\n{\n  CTSize align = ctype_align(info);\n  UNUSED(cp); UNUSED(ct);\n#if (LJ_TARGET_X86 && !LJ_ABI_WIN) || (LJ_TARGET_ARM && __APPLE__)\n  /* The SYSV i386 and iOS ABIs limit alignment of non-vector fields to 2^2. */\n  if (align > 2 && !(info & CTFP_ALIGNED)) {\n    if (ctype_isarray(info) && !(info & CTF_VECTOR)) {\n      do {\n\tct = ctype_rawchild(cp->cts, ct);\n\tinfo = ct->info;\n      } while (ctype_isarray(info) && !(info & CTF_VECTOR));\n    }\n    if (ctype_isnum(info) || ctype_isenum(info))\n      align = 2;\n  }\n#endif\n  return align;\n}\n\n/* Layout struct/union fields. */\nstatic void cp_struct_layout(CPState *cp, CTypeID sid, CTInfo sattr)\n{\n  CTSize bofs = 0, bmaxofs = 0;  /* Bit offset and max. bit offset. */\n  CTSize maxalign = ctype_align(sattr);\n  CType *sct = ctype_get(cp->cts, sid);\n  CTInfo sinfo = sct->info;\n  CTypeID fieldid = sct->sib;\n  while (fieldid) {\n    CType *ct = ctype_get(cp->cts, fieldid);\n    CTInfo attr = ct->size;  /* Field declaration attributes (temp.). */\n\n    if (ctype_isfield(ct->info) ||\n\t(ctype_isxattrib(ct->info, CTA_SUBTYPE) && attr)) {\n      CTSize align, amask;  /* Alignment (pow2) and alignment mask (bits). */\n      CTSize sz;\n      CTInfo info = lj_ctype_info(cp->cts, ctype_cid(ct->info), &sz);\n      CTSize bsz, csz = 8*sz;  /* Field size and container size (in bits). */\n      sinfo |= (info & (CTF_QUAL|CTF_VLA));  /* Merge pseudo-qualifiers. */\n\n      /* Check for size overflow and determine alignment. */\n      if (sz >= 0x20000000u || bofs + csz < bofs || (info & CTF_VLA)) {\n\tif (!(sz == CTSIZE_INVALID && ctype_isarray(info) &&\n\t      !(sinfo & CTF_UNION)))\n\t  cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\tcsz = sz = 0;  /* Treat a[] and a[?] as zero-sized. */\n      }\n      align = cp_field_align(cp, ct, info);\n      if (((attr|sattr) & CTFP_PACKED) ||\n\t  ((attr & CTFP_ALIGNED) && ctype_align(attr) > align))\n\talign = ctype_align(attr);\n      if (cp->packstack[cp->curpack] < align)\n\talign = cp->packstack[cp->curpack];\n      if (align > maxalign) maxalign = align;\n      amask = (8u << align) - 1;\n\n      bsz = ctype_bitcsz(ct->info);  /* Bitfield size (temp.). */\n      if (bsz == CTBSZ_FIELD || !ctype_isfield(ct->info)) {\n\tbsz = csz;  /* Regular fields or subtypes always fill the container. */\n\tbofs = (bofs + amask) & ~amask;  /* Start new aligned field. */\n\tct->size = (bofs >> 3);  /* Store field offset. */\n      } else {  /* Bitfield. */\n\tif (bsz == 0 || (attr & CTFP_ALIGNED) ||\n\t    (!((attr|sattr) & CTFP_PACKED) && (bofs & amask) + bsz > csz))\n\t  bofs = (bofs + amask) & ~amask;  /* Start new aligned field. */\n\n\t/* Prefer regular field over bitfield. */\n\tif (bsz == csz && (bofs & amask) == 0) {\n\t  ct->info = CTINFO(CT_FIELD, ctype_cid(ct->info));\n\t  ct->size = (bofs >> 3);  /* Store field offset. */\n\t} else {\n\t  ct->info = CTINFO(CT_BITFIELD,\n\t    (info & (CTF_QUAL|CTF_UNSIGNED|CTF_BOOL)) +\n\t    (csz << (CTSHIFT_BITCSZ-3)) + (bsz << CTSHIFT_BITBSZ));\n#if LJ_BE\n\t  ct->info += ((csz - (bofs & (csz-1)) - bsz) << CTSHIFT_BITPOS);\n#else\n\t  ct->info += ((bofs & (csz-1)) << CTSHIFT_BITPOS);\n#endif\n\t  ct->size = ((bofs & ~(csz-1)) >> 3);  /* Store container offset. */\n\t}\n      }\n\n      /* Determine next offset or max. offset. */\n      if ((sinfo & CTF_UNION)) {\n\tif (bsz > bmaxofs) bmaxofs = bsz;\n      } else {\n\tbofs += bsz;\n      }\n    }  /* All other fields in the chain are already set up. */\n\n    fieldid = ct->sib;\n  }\n\n  /* Complete struct/union. */\n  sct->info = sinfo + CTALIGN(maxalign);\n  bofs = (sinfo & CTF_UNION) ? bmaxofs : bofs;\n  maxalign = (8u << maxalign) - 1;\n  sct->size = (((bofs + maxalign) & ~maxalign) >> 3);\n}\n\n/* Parse struct/union declaration. */\nstatic CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo)\n{\n  CTypeID sid = cp_struct_name(cp, sdecl, sinfo);\n  if (cp_opt(cp, '{')) {  /* Struct/union definition. */\n    CTypeID lastid = sid;\n    int lastdecl = 0;\n    while (cp->tok != '}') {\n      CPDecl decl;\n      CPscl scl = cp_decl_spec(cp, &decl, CDF_STATIC);\n      decl.mode = scl ? CPARSE_MODE_DIRECT :\n\tCPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD;\n\n      for (;;) {\n\tCTypeID ctypeid;\n\n\tif (lastdecl) cp_err_token(cp, '}');\n\n\t/* Parse field declarator. */\n\tdecl.bits = CTSIZE_INVALID;\n\tcp_declarator(cp, &decl);\n\tctypeid = cp_decl_intern(cp, &decl);\n\n\tif ((scl & CDF_STATIC)) {  /* Static constant in struct namespace. */\n\t  CType *ct;\n\t  CTypeID fieldid = cp_decl_constinit(cp, &ct, ctypeid);\n\t  ctype_get(cp->cts, lastid)->sib = fieldid;\n\t  lastid = fieldid;\n\t  ctype_setname(ct, decl.name);\n\t} else {\n\t  CTSize bsz = CTBSZ_FIELD;  /* Temp. for layout phase. */\n\t  CType *ct;\n\t  CTypeID fieldid = lj_ctype_new(cp->cts, &ct);  /* Do this first. */\n\t  CType *tct = ctype_raw(cp->cts, ctypeid);\n\n\t  if (decl.bits == CTSIZE_INVALID) {  /* Regular field. */\n\t    if (ctype_isarray(tct->info) && tct->size == CTSIZE_INVALID)\n\t      lastdecl = 1;  /* a[] or a[?] must be the last declared field. */\n\n\t    /* Accept transparent struct/union/enum. */\n\t    if (!decl.name) {\n\t      if (!((ctype_isstruct(tct->info) && !(tct->info & CTF_VLA)) ||\n\t\t    ctype_isenum(tct->info)))\n\t\tcp_err_token(cp, CTOK_IDENT);\n\t      ct->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_SUBTYPE) + ctypeid);\n\t      ct->size = ctype_isstruct(tct->info) ?\n\t\t\t (decl.attr|0x80000000u) : 0;  /* For layout phase. */\n\t      goto add_field;\n\t    }\n\t  } else {  /* Bitfield. */\n\t    bsz = decl.bits;\n\t    if (!ctype_isinteger_or_bool(tct->info) ||\n\t\t(bsz == 0 && decl.name) || 8*tct->size > CTBSZ_MAX ||\n\t\tbsz > ((tct->info & CTF_BOOL) ? 1 : 8*tct->size))\n\t      cp_errmsg(cp, ':', LJ_ERR_BADVAL);\n\t  }\n\n\t  /* Create temporary field for layout phase. */\n\t  ct->info = CTINFO(CT_FIELD, ctypeid + (bsz << CTSHIFT_BITCSZ));\n\t  ct->size = decl.attr;\n\t  if (decl.name) ctype_setname(ct, decl.name);\n\n\tadd_field:\n\t  ctype_get(cp->cts, lastid)->sib = fieldid;\n\t  lastid = fieldid;\n\t}\n\tif (!cp_opt(cp, ',')) break;\n\tcp_decl_reset(&decl);\n      }\n      cp_check(cp, ';');\n    }\n    cp_check(cp, '}');\n    ctype_get(cp->cts, lastid)->sib = 0;  /* Drop sib = 1 for empty structs. */\n    cp_decl_attributes(cp, sdecl);  /* Layout phase needs postfix attributes. */\n    cp_struct_layout(cp, sid, sdecl->attr);\n  }\n  return sid;\n}\n\n/* Parse enum declaration. */\nstatic CTypeID cp_decl_enum(CPState *cp, CPDecl *sdecl)\n{\n  CTypeID eid = cp_struct_name(cp, sdecl, CTINFO(CT_ENUM, CTID_VOID));\n  CTInfo einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_UINT32);\n  CTSize esize = 4;  /* Only 32 bit enums are supported. */\n  if (cp_opt(cp, '{')) {  /* Enum definition. */\n    CPValue k;\n    CTypeID lastid = eid;\n    k.u32 = 0;\n    k.id = CTID_INT32;\n    do {\n      GCstr *name = cp->str;\n      if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n      if (cp->val.id) cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(name));\n      cp_next(cp);\n      if (cp_opt(cp, '=')) {\n\tcp_expr_kint(cp, &k);\n\tif (k.id == CTID_UINT32) {\n\t  /* C99 says that enum constants are always (signed) integers.\n\t  ** But since unsigned constants like 0x80000000 are quite common,\n\t  ** those are left as uint32_t.\n\t  */\n\t  if (k.i32 >= 0) k.id = CTID_INT32;\n\t} else {\n\t  /* OTOH it's common practice and even mandated by some ABIs\n\t  ** that the enum type itself is unsigned, unless there are any\n\t  ** negative constants.\n\t  */\n\t  k.id = CTID_INT32;\n\t  if (k.i32 < 0) einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_INT32);\n\t}\n      }\n      /* Add named enum constant. */\n      {\n\tCType *ct;\n\tCTypeID constid = lj_ctype_new(cp->cts, &ct);\n\tctype_get(cp->cts, lastid)->sib = constid;\n\tlastid = constid;\n\tctype_setname(ct, name);\n\tct->info = CTINFO(CT_CONSTVAL, CTF_CONST|k.id);\n\tct->size = k.u32++;\n\tif (k.u32 == 0x80000000u) k.id = CTID_UINT32;\n\tlj_ctype_addname(cp->cts, ct, constid);\n      }\n      if (!cp_opt(cp, ',')) break;\n    } while (cp->tok != '}');  /* Trailing ',' is ok. */\n    cp_check(cp, '}');\n    /* Complete enum. */\n    ctype_get(cp->cts, eid)->info = einfo;\n    ctype_get(cp->cts, eid)->size = esize;\n  }\n  return eid;\n}\n\n/* Parse declaration specifiers. */\nstatic CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl)\n{\n  uint32_t cds = 0, sz = 0;\n  CTypeID tdef = 0;\n\n  decl->cp = cp;\n  decl->mode = cp->mode;\n  decl->name = NULL;\n  decl->redir = NULL;\n  decl->attr = 0;\n  decl->fattr = 0;\n  decl->pos = decl->top = 0;\n  decl->stack[0].next = 0;\n\n  for (;;) {  /* Parse basic types. */\n    cp_decl_attributes(cp, decl);\n    if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) {\n      uint32_t cbit;\n      if (cp->ct->size) {\n\tif (sz) goto end_decl;\n\tsz = cp->ct->size;\n      }\n      cbit = (1u << (cp->tok - CTOK_FIRSTDECL));\n      cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1);\n      if (cp->tok >= CTOK_FIRSTSCL) {\n\tif (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL);\n      } else if (tdef) {\n\tgoto end_decl;\n      }\n      cp_next(cp);\n      continue;\n    }\n    if (sz || tdef ||\n\t(cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX)))\n      break;\n    switch (cp->tok) {\n    case CTOK_STRUCT:\n      tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0));\n      continue;\n    case CTOK_UNION:\n      tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION));\n      continue;\n    case CTOK_ENUM:\n      tdef = cp_decl_enum(cp, decl);\n      continue;\n    case CTOK_IDENT:\n      if (ctype_istypedef(cp->ct->info)) {\n\ttdef = ctype_cid(cp->ct->info);  /* Get typedef. */\n\tcp_next(cp);\n\tcontinue;\n      }\n      break;\n    case '$':\n      tdef = cp->val.id;\n      cp_next(cp);\n      continue;\n    default:\n      break;\n    }\n    break;\n  }\nend_decl:\n\n  if ((cds & CDF_COMPLEX))  /* Use predefined complex types. */\n    tdef = sz == 4 ? CTID_COMPLEX_FLOAT : CTID_COMPLEX_DOUBLE;\n\n  if (tdef) {\n    cp_push_type(decl, tdef);\n  } else if ((cds & CDF_VOID)) {\n    cp_push(decl, CTINFO(CT_VOID, (decl->attr & CTF_QUAL)), CTSIZE_INVALID);\n    decl->attr &= ~CTF_QUAL;\n  } else {\n    /* Determine type info and size. */\n    CTInfo info = CTINFO(CT_NUM, (cds & CDF_UNSIGNED) ? CTF_UNSIGNED : 0);\n    if ((cds & CDF_BOOL)) {\n      if ((cds & ~(CDF_SCL|CDF_BOOL|CDF_INT|CDF_SIGNED|CDF_UNSIGNED)))\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_INVTYPE);\n      info |= CTF_BOOL;\n      if (!(cds & CDF_SIGNED)) info |= CTF_UNSIGNED;\n      if (!sz) {\n\tsz = 1;\n      }\n    } else if ((cds & CDF_FP)) {\n      info = CTINFO(CT_NUM, CTF_FP);\n      if ((cds & CDF_LONG)) sz = sizeof(long double);\n    } else if ((cds & CDF_CHAR)) {\n      if ((cds & (CDF_CHAR|CDF_SIGNED|CDF_UNSIGNED)) == CDF_CHAR)\n\tinfo |= CTF_UCHAR;  /* Handle platforms where char is unsigned. */\n    } else if ((cds & CDF_SHORT)) {\n      sz = sizeof(short);\n    } else if ((cds & CDF_LONGLONG)) {\n      sz = 8;\n    } else if ((cds & CDF_LONG)) {\n      info |= CTF_LONG;\n      sz = sizeof(long);\n    } else if (!sz) {\n      if (!(cds & (CDF_SIGNED|CDF_UNSIGNED)))\n\tcp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC);\n      sz = sizeof(int);\n    }\n    lua_assert(sz != 0);\n    info += CTALIGN(lj_fls(sz));  /* Use natural alignment. */\n    info += (decl->attr & CTF_QUAL);  /* Merge qualifiers. */\n    cp_push(decl, info, sz);\n    decl->attr &= ~CTF_QUAL;\n  }\n  decl->specpos = decl->pos;\n  decl->specattr = decl->attr;\n  decl->specfattr = decl->fattr;\n  return (cds & CDF_SCL);  /* Return storage class. */\n}\n\n/* Parse array declaration. */\nstatic void cp_decl_array(CPState *cp, CPDecl *decl)\n{\n  CTInfo info = CTINFO(CT_ARRAY, 0);\n  CTSize nelem = CTSIZE_INVALID;  /* Default size for a[] or a[?]. */\n  cp_decl_attributes(cp, decl);\n  if (cp_opt(cp, '?'))\n    info |= CTF_VLA;  /* Create variable-length array a[?]. */\n  else if (cp->tok != ']')\n    nelem = cp_expr_ksize(cp);\n  cp_check(cp, ']');\n  cp_add(decl, info, nelem);\n}\n\n/* Parse function declaration. */\nstatic void cp_decl_func(CPState *cp, CPDecl *fdecl)\n{\n  CTSize nargs = 0;\n  CTInfo info = CTINFO(CT_FUNC, 0);\n  CTypeID lastid = 0, anchor = 0;\n  if (cp->tok != ')') {\n    do {\n      CPDecl decl;\n      CTypeID ctypeid, fieldid;\n      CType *ct;\n      if (cp_opt(cp, '.')) {  /* Vararg function. */\n\tcp_check(cp, '.');  /* Workaround for the minimalistic lexer. */\n\tcp_check(cp, '.');\n\tinfo |= CTF_VARARG;\n\tbreak;\n      }\n      cp_decl_spec(cp, &decl, CDF_REGISTER);\n      decl.mode = CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT;\n      cp_declarator(cp, &decl);\n      ctypeid = cp_decl_intern(cp, &decl);\n      ct = ctype_raw(cp->cts, ctypeid);\n      if (ctype_isvoid(ct->info))\n\tbreak;\n      else if (ctype_isrefarray(ct->info))\n\tctypeid = lj_ctype_intern(cp->cts,\n\t  CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ct->info)), CTSIZE_PTR);\n      else if (ctype_isfunc(ct->info))\n\tctypeid = lj_ctype_intern(cp->cts,\n\t  CTINFO(CT_PTR, CTALIGN_PTR|ctypeid), CTSIZE_PTR);\n      /* Add new parameter. */\n      fieldid = lj_ctype_new(cp->cts, &ct);\n      if (anchor)\n\tctype_get(cp->cts, lastid)->sib = fieldid;\n      else\n\tanchor = fieldid;\n      lastid = fieldid;\n      if (decl.name) ctype_setname(ct, decl.name);\n      ct->info = CTINFO(CT_FIELD, ctypeid);\n      ct->size = nargs++;\n    } while (cp_opt(cp, ','));\n  }\n  cp_check(cp, ')');\n  if (cp_opt(cp, '{')) {  /* Skip function definition. */\n    int level = 1;\n    cp->mode |= CPARSE_MODE_SKIP;\n    for (;;) {\n      if (cp->tok == '{') level++;\n      else if (cp->tok == '}' && --level == 0) break;\n      else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}');\n      cp_next(cp);\n    }\n    cp->mode &= ~CPARSE_MODE_SKIP;\n    cp->tok = ';';  /* Ok for cp_decl_multi(), error in cp_decl_single(). */\n  }\n  info |= (fdecl->fattr & ~CTMASK_CID);\n  fdecl->fattr = 0;\n  fdecl->stack[cp_add(fdecl, info, nargs)].sib = anchor;\n}\n\n/* Parse declarator. */\nstatic void cp_declarator(CPState *cp, CPDecl *decl)\n{\n  if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);\n\n  for (;;) {  /* Head of declarator. */\n    if (cp_opt(cp, '*')) {  /* Pointer. */\n      CTSize sz;\n      CTInfo info;\n      cp_decl_attributes(cp, decl);\n      sz = CTSIZE_PTR;\n      info = CTINFO(CT_PTR, CTALIGN_PTR);\n#if LJ_64\n      if (ctype_msizeP(decl->attr) == 4) {\n\tsz = 4;\n\tinfo = CTINFO(CT_PTR, CTALIGN(2));\n      }\n#endif\n      info += (decl->attr & (CTF_QUAL|CTF_REF));\n      decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));\n      cp_push(decl, info, sz);\n    } else if (cp_opt(cp, '&') || cp_opt(cp, CTOK_ANDAND)) {  /* Reference. */\n      decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));\n      cp_push(decl, CTINFO_REF(0), CTSIZE_PTR);\n    } else {\n      break;\n    }\n  }\n\n  if (cp_opt(cp, '(')) {  /* Inner declarator. */\n    CPDeclIdx pos;\n    cp_decl_attributes(cp, decl);\n    /* Resolve ambiguity between inner declarator and 1st function parameter. */\n    if ((decl->mode & CPARSE_MODE_ABSTRACT) &&\n\t(cp->tok == ')' || cp_istypedecl(cp))) goto func_decl;\n    pos = decl->pos;\n    cp_declarator(cp, decl);\n    cp_check(cp, ')');\n    decl->pos = pos;\n  } else if (cp->tok == CTOK_IDENT) {  /* Direct declarator. */\n    if (!(decl->mode & CPARSE_MODE_DIRECT)) cp_err_token(cp, CTOK_EOF);\n    decl->name = cp->str;\n    decl->nameid = cp->val.id;\n    cp_next(cp);\n  } else {  /* Abstract declarator. */\n    if (!(decl->mode & CPARSE_MODE_ABSTRACT)) cp_err_token(cp, CTOK_IDENT);\n  }\n\n  for (;;) {  /* Tail of declarator. */\n    if (cp_opt(cp, '[')) {  /* Array. */\n      cp_decl_array(cp, decl);\n    } else if (cp_opt(cp, '(')) {  /* Function. */\n    func_decl:\n      cp_decl_func(cp, decl);\n    } else {\n      break;\n    }\n  }\n\n  if ((decl->mode & CPARSE_MODE_FIELD) && cp_opt(cp, ':'))  /* Field width. */\n    decl->bits = cp_expr_ksize(cp);\n\n  /* Process postfix attributes. */\n  cp_decl_attributes(cp, decl);\n  cp_push_attributes(decl);\n\n  cp->depth--;\n}\n\n/* Parse an abstract type declaration and return it's C type ID. */\nstatic CTypeID cp_decl_abstract(CPState *cp)\n{\n  CPDecl decl;\n  cp_decl_spec(cp, &decl, 0);\n  decl.mode = CPARSE_MODE_ABSTRACT;\n  cp_declarator(cp, &decl);\n  return cp_decl_intern(cp, &decl);\n}\n\n/* Handle pragmas. */\nstatic void cp_pragma(CPState *cp, BCLine pragmaline)\n{\n  cp_next(cp);\n  if (cp->tok == CTOK_IDENT &&\n      cp->str->hash == H_(e79b999f,42ca3e85))  {  /* pack */\n    cp_next(cp);\n    cp_check(cp, '(');\n    if (cp->tok == CTOK_IDENT) {\n      if (cp->str->hash == H_(738e923c,a1b65954)) {  /* push */\n\tif (cp->curpack < CPARSE_MAX_PACKSTACK) {\n\t  cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack];\n\t  cp->curpack++;\n\t}\n      } else if (cp->str->hash == H_(6c71cf27,6c71cf27)) {  /* pop */\n\tif (cp->curpack > 0) cp->curpack--;\n      } else {\n\tcp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n      }\n      cp_next(cp);\n      if (!cp_opt(cp, ',')) goto end_pack;\n    }\n    if (cp->tok == CTOK_INTEGER) {\n      cp->packstack[cp->curpack] = cp->val.u32 ? lj_fls(cp->val.u32) : 0;\n      cp_next(cp);\n    } else {\n      cp->packstack[cp->curpack] = 255;\n    }\n  end_pack:\n    cp_check(cp, ')');\n  } else {  /* Ignore all other pragmas. */\n    while (cp->tok != CTOK_EOF && cp->linenumber == pragmaline)\n      cp_next(cp);\n  }\n}\n\n/* Handle line number. */\nstatic void cp_line(CPState *cp, BCLine hashline)\n{\n  BCLine newline = cp->val.u32;\n  /* TODO: Handle file name and include it in error messages. */\n  while (cp->tok != CTOK_EOF && cp->linenumber == hashline)\n    cp_next(cp);\n  cp->linenumber = newline;\n}\n\n/* Parse multiple C declarations of types or extern identifiers. */\nstatic void cp_decl_multi(CPState *cp)\n{\n  int first = 1;\n  while (cp->tok != CTOK_EOF) {\n    CPDecl decl;\n    CPscl scl;\n    if (cp_opt(cp, ';')) {  /* Skip empty statements. */\n      first = 0;\n      continue;\n    }\n    if (cp->tok == '#') {  /* Workaround, since we have no preprocessor, yet. */\n      BCLine hashline = cp->linenumber;\n      CPToken tok = cp_next(cp);\n      if (tok == CTOK_INTEGER) {\n\tcp_line(cp, hashline);\n\tcontinue;\n      } else if (tok == CTOK_IDENT &&\n\t\t cp->str->hash == H_(187aab88,fcb60b42)) { /* line */\n\tif (cp_next(cp) != CTOK_INTEGER) cp_err_token(cp, tok);\n\tcp_line(cp, hashline);\n\tcontinue;\n      } else if (tok == CTOK_IDENT &&\n\t  cp->str->hash == H_(f5e6b4f8,1d509107)) { /* pragma */\n\tcp_pragma(cp, hashline);\n\tcontinue;\n      } else {\n\tcp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n      }\n    }\n    scl = cp_decl_spec(cp, &decl, CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC);\n    if ((cp->tok == ';' || cp->tok == CTOK_EOF) &&\n\tctype_istypedef(decl.stack[0].info)) {\n      CTInfo info = ctype_rawchild(cp->cts, &decl.stack[0])->info;\n      if (ctype_isstruct(info) || ctype_isenum(info))\n\tgoto decl_end;  /* Accept empty declaration of struct/union/enum. */\n    }\n    for (;;) {\n      CTypeID ctypeid;\n      cp_declarator(cp, &decl);\n      ctypeid = cp_decl_intern(cp, &decl);\n      if (decl.name && !decl.nameid) {  /* NYI: redeclarations are ignored. */\n\tCType *ct;\n\tCTypeID id;\n\tif ((scl & CDF_TYPEDEF)) {  /* Create new typedef. */\n\t  id = lj_ctype_new(cp->cts, &ct);\n\t  ct->info = CTINFO(CT_TYPEDEF, ctypeid);\n\t  goto noredir;\n\t} else if (ctype_isfunc(ctype_get(cp->cts, ctypeid)->info)) {\n\t  /* Treat both static and extern function declarations as extern. */\n\t  ct = ctype_get(cp->cts, ctypeid);\n\t  /* We always get new anonymous functions (typedefs are copied). */\n\t  lua_assert(gcref(ct->name) == NULL);\n\t  id = ctypeid;  /* Just name it. */\n\t} else if ((scl & CDF_STATIC)) {  /* Accept static constants. */\n\t  id = cp_decl_constinit(cp, &ct, ctypeid);\n\t  goto noredir;\n\t} else {  /* External references have extern or no storage class. */\n\t  id = lj_ctype_new(cp->cts, &ct);\n\t  ct->info = CTINFO(CT_EXTERN, ctypeid);\n\t}\n\tif (decl.redir) {  /* Add attribute for redirected symbol name. */\n\t  CType *cta;\n\t  CTypeID aid = lj_ctype_new(cp->cts, &cta);\n\t  ct = ctype_get(cp->cts, id);  /* Table may have been reallocated. */\n\t  cta->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_REDIR));\n\t  cta->sib = ct->sib;\n\t  ct->sib = aid;\n\t  ctype_setname(cta, decl.redir);\n\t}\n      noredir:\n\tctype_setname(ct, decl.name);\n\tlj_ctype_addname(cp->cts, ct, id);\n      }\n      if (!cp_opt(cp, ',')) break;\n      cp_decl_reset(&decl);\n    }\n  decl_end:\n    if (cp->tok == CTOK_EOF && first) break;  /* May omit ';' for 1 decl. */\n    first = 0;\n    cp_check(cp, ';');\n  }\n}\n\n/* Parse a single C type declaration. */\nstatic void cp_decl_single(CPState *cp)\n{\n  CPDecl decl;\n  cp_decl_spec(cp, &decl, 0);\n  cp_declarator(cp, &decl);\n  cp->val.id = cp_decl_intern(cp, &decl);\n  if (cp->tok != CTOK_EOF) cp_err_token(cp, CTOK_EOF);\n}\n\n#undef H_\n\n/* ------------------------------------------------------------------------ */\n\n/* Protected callback for C parser. */\nstatic TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  CPState *cp = (CPState *)ud;\n  UNUSED(dummy);\n  cframe_errfunc(L->cframe) = -1;  /* Inherit error function. */\n  cp_init(cp);\n  if ((cp->mode & CPARSE_MODE_MULTI))\n    cp_decl_multi(cp);\n  else\n    cp_decl_single(cp);\n  if (cp->param && cp->param != cp->L->top)\n    cp_err(cp, LJ_ERR_FFI_NUMPARAM);\n  lua_assert(cp->depth == 0);\n  return NULL;\n}\n\n/* C parser. */\nint lj_cparse(CPState *cp)\n{\n  LJ_CTYPE_SAVE(cp->cts);\n  int errcode = lj_vm_cpcall(cp->L, NULL, cp, cpcparser);\n  if (errcode)\n    LJ_CTYPE_RESTORE(cp->cts);\n  cp_cleanup(cp);\n  return errcode;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_cparse.h",
    "content": "/*\n** C declaration parser.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CPARSE_H\n#define _LJ_CPARSE_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* C parser limits. */\n#define CPARSE_MAX_BUF\t\t32768\t/* Max. token buffer size. */\n#define CPARSE_MAX_DECLSTACK\t100\t/* Max. declaration stack depth. */\n#define CPARSE_MAX_DECLDEPTH\t20\t/* Max. recursive declaration depth. */\n#define CPARSE_MAX_PACKSTACK\t7\t/* Max. pack pragma stack depth. */\n\n/* Flags for C parser mode. */\n#define CPARSE_MODE_MULTI\t1\t/* Process multiple declarations. */\n#define CPARSE_MODE_ABSTRACT\t2\t/* Accept abstract declarators. */\n#define CPARSE_MODE_DIRECT\t4\t/* Accept direct declarators. */\n#define CPARSE_MODE_FIELD\t8\t/* Accept field width in bits, too. */\n#define CPARSE_MODE_NOIMPLICIT\t16\t/* Reject implicit declarations. */\n#define CPARSE_MODE_SKIP\t32\t/* Skip definitions, ignore errors. */\n\ntypedef int CPChar;\t/* C parser character. Unsigned ext. from char. */\ntypedef int CPToken;\t/* C parser token. */\n\n/* C parser internal value representation. */\ntypedef struct CPValue {\n  union {\n    int32_t i32;\t/* Value for CTID_INT32. */\n    uint32_t u32;\t/* Value for CTID_UINT32. */\n  };\n  CTypeID id;\t\t/* C Type ID of the value. */\n} CPValue;\n\n/* C parser state. */\ntypedef struct CPState {\n  CPChar c;\t\t/* Current character. */\n  CPToken tok;\t\t/* Current token. */\n  CPValue val;\t\t/* Token value. */\n  GCstr *str;\t\t/* Interned string of identifier/keyword. */\n  CType *ct;\t\t/* C type table entry. */\n  const char *p;\t/* Current position in input buffer. */\n  SBuf sb;\t\t/* String buffer for tokens. */\n  lua_State *L;\t\t/* Lua state. */\n  CTState *cts;\t\t/* C type state. */\n  TValue *param;\t/* C type parameters. */\n  const char *srcname;\t/* Current source name. */\n  BCLine linenumber;\t/* Input line counter. */\n  int depth;\t\t/* Recursive declaration depth. */\n  uint32_t tmask;\t/* Type mask for next identifier. */\n  uint32_t mode;\t/* C parser mode. */\n  uint8_t packstack[CPARSE_MAX_PACKSTACK];  /* Stack for pack pragmas. */\n  uint8_t curpack;\t/* Current position in pack pragma stack. */\n} CPState;\n\nLJ_FUNC int lj_cparse(CPState *cp);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_crecord.c",
    "content": "/*\n** Trace recorder for C data operations.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ffrecord_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT && LJ_HASFFI\n\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cparse.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#include \"lj_clib.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ff.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_snap.h\"\n#include \"lj_crecord.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_strfmt.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n#define emitconv(a, dt, st, flags) \\\n  emitir(IRT(IR_CONV, (dt)), (a), (st)|((dt) << 5)|(flags))\n\n/* -- C type checks ------------------------------------------------------- */\n\nstatic GCcdata *argv2cdata(jit_State *J, TRef tr, cTValue *o)\n{\n  GCcdata *cd;\n  TRef trtypeid;\n  if (!tref_iscdata(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  cd = cdataV(o);\n  /* Specialize to the CTypeID. */\n  trtypeid = emitir(IRT(IR_FLOAD, IRT_U16), tr, IRFL_CDATA_CTYPEID);\n  emitir(IRTG(IR_EQ, IRT_INT), trtypeid, lj_ir_kint(J, (int32_t)cd->ctypeid));\n  return cd;\n}\n\n/* Specialize to the CTypeID held by a cdata constructor. */\nstatic CTypeID crec_constructor(jit_State *J, GCcdata *cd, TRef tr)\n{\n  CTypeID id;\n  lua_assert(tref_iscdata(tr) && cd->ctypeid == CTID_CTYPEID);\n  id = *(CTypeID *)cdataptr(cd);\n  tr = emitir(IRT(IR_FLOAD, IRT_INT), tr, IRFL_CDATA_INT);\n  emitir(IRTG(IR_EQ, IRT_INT), tr, lj_ir_kint(J, (int32_t)id));\n  return id;\n}\n\nstatic CTypeID argv2ctype(jit_State *J, TRef tr, cTValue *o)\n{\n  if (tref_isstr(tr)) {\n    GCstr *s = strV(o);\n    CPState cp;\n    CTypeID oldtop;\n    /* Specialize to the string containing the C type declaration. */\n    emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, s));\n    cp.L = J->L;\n    cp.cts = ctype_ctsG(J2G(J));\n    oldtop = cp.cts->top;\n    cp.srcname = strdata(s);\n    cp.p = strdata(s);\n    cp.param = NULL;\n    cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;\n    if (lj_cparse(&cp) || cp.cts->top > oldtop)  /* Avoid new struct defs. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    return cp.val.id;\n  } else {\n    GCcdata *cd = argv2cdata(J, tr, o);\n    return cd->ctypeid == CTID_CTYPEID ? crec_constructor(J, cd, tr) :\n\t\t\t\t\tcd->ctypeid;\n  }\n}\n\n/* Convert CType to IRType (if possible). */\nstatic IRType crec_ct2irt(CTState *cts, CType *ct)\n{\n  if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n  if (LJ_LIKELY(ctype_isnum(ct->info))) {\n    if ((ct->info & CTF_FP)) {\n      if (ct->size == sizeof(double))\n\treturn IRT_NUM;\n      else if (ct->size == sizeof(float))\n\treturn IRT_FLOAT;\n    } else {\n      uint32_t b = lj_fls(ct->size);\n      if (b <= 3)\n\treturn IRT_I8 + 2*b + ((ct->info & CTF_UNSIGNED) ? 1 : 0);\n    }\n  } else if (ctype_isptr(ct->info)) {\n    return (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n  } else if (ctype_iscomplex(ct->info)) {\n    if (ct->size == 2*sizeof(double))\n      return IRT_NUM;\n    else if (ct->size == 2*sizeof(float))\n      return IRT_FLOAT;\n  }\n  return IRT_CDATA;\n}\n\n/* -- Optimized memory fill and copy -------------------------------------- */\n\n/* Maximum length and unroll of inlined copy/fill. */\n#define CREC_COPY_MAXUNROLL\t\t16\n#define CREC_COPY_MAXLEN\t\t128\n\n#define CREC_FILL_MAXUNROLL\t\t16\n\n/* Number of windowed registers used for optimized memory copy. */\n#if LJ_TARGET_X86\n#define CREC_COPY_REGWIN\t\t2\n#elif LJ_TARGET_PPC || LJ_TARGET_MIPS\n#define CREC_COPY_REGWIN\t\t8\n#else\n#define CREC_COPY_REGWIN\t\t4\n#endif\n\n/* List of memory offsets for copy/fill. */\ntypedef struct CRecMemList {\n  CTSize ofs;\t\t/* Offset in bytes. */\n  IRType tp;\t\t/* Type of load/store. */\n  TRef trofs;\t\t/* TRef of interned offset. */\n  TRef trval;\t\t/* TRef of load value. */\n} CRecMemList;\n\n/* Generate copy list for element-wise struct copy. */\nstatic MSize crec_copy_struct(CRecMemList *ml, CTState *cts, CType *ct)\n{\n  CTypeID fid = ct->sib;\n  MSize mlp = 0;\n  while (fid) {\n    CType *df = ctype_get(cts, fid);\n    fid = df->sib;\n    if (ctype_isfield(df->info)) {\n      CType *cct;\n      IRType tp;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      cct = ctype_rawchild(cts, df);  /* Field type. */\n      tp = crec_ct2irt(cts, cct);\n      if (tp == IRT_CDATA) return 0;  /* NYI: aggregates. */\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = df->size;\n      ml[mlp].tp = tp;\n      mlp++;\n      if (ctype_iscomplex(cct->info)) {\n\tif (mlp >= CREC_COPY_MAXUNROLL) return 0;\n\tml[mlp].ofs = df->size + (cct->size >> 1);\n\tml[mlp].tp = tp;\n\tmlp++;\n      }\n    } else if (!ctype_isconstval(df->info)) {\n      /* NYI: bitfields and sub-structures. */\n      return 0;\n    }\n  }\n  return mlp;\n}\n\n/* Generate unrolled copy list, from highest to lowest step size/alignment. */\nstatic MSize crec_copy_unroll(CRecMemList *ml, CTSize len, CTSize step,\n\t\t\t      IRType tp)\n{\n  CTSize ofs = 0;\n  MSize mlp = 0;\n  if (tp == IRT_CDATA) tp = IRT_U8 + 2*lj_fls(step);\n  do {\n    while (ofs + step <= len) {\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = ofs;\n      ml[mlp].tp = tp;\n      mlp++;\n      ofs += step;\n    }\n    step >>= 1;\n    tp -= 2;\n  } while (ofs < len);\n  return mlp;\n}\n\n/*\n** Emit copy list with windowed loads/stores.\n** LJ_TARGET_UNALIGNED: may emit unaligned loads/stores (not marked as such).\n*/\nstatic void crec_copy_emit(jit_State *J, CRecMemList *ml, MSize mlp,\n\t\t\t   TRef trdst, TRef trsrc)\n{\n  MSize i, j, rwin = 0;\n  for (i = 0, j = 0; i < mlp; ) {\n    TRef trofs = lj_ir_kintp(J, ml[i].ofs);\n    TRef trsptr = emitir(IRT(IR_ADD, IRT_PTR), trsrc, trofs);\n    ml[i].trval = emitir(IRT(IR_XLOAD, ml[i].tp), trsptr, 0);\n    ml[i].trofs = trofs;\n    i++;\n    rwin += (LJ_SOFTFP && ml[i].tp == IRT_NUM) ? 2 : 1;\n    if (rwin >= CREC_COPY_REGWIN || i >= mlp) {  /* Flush buffered stores. */\n      rwin = 0;\n      for ( ; j < i; j++) {\n\tTRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, ml[j].trofs);\n\temitir(IRT(IR_XSTORE, ml[j].tp), trdptr, ml[j].trval);\n      }\n    }\n  }\n}\n\n/* Optimized memory copy. */\nstatic void crec_copy(jit_State *J, TRef trdst, TRef trsrc, TRef trlen,\n\t\t      CType *ct)\n{\n  if (tref_isk(trlen)) {  /* Length must be constant. */\n    CRecMemList ml[CREC_COPY_MAXUNROLL];\n    MSize mlp = 0;\n    CTSize step = 1, len = (CTSize)IR(tref_ref(trlen))->i;\n    IRType tp = IRT_CDATA;\n    int needxbar = 0;\n    if (len == 0) return;  /* Shortcut. */\n    if (len > CREC_COPY_MAXLEN) goto fallback;\n    if (ct) {\n      CTState *cts = ctype_ctsG(J2G(J));\n      lua_assert(ctype_isarray(ct->info) || ctype_isstruct(ct->info));\n      if (ctype_isarray(ct->info)) {\n\tCType *cct = ctype_rawchild(cts, ct);\n\ttp = crec_ct2irt(cts, cct);\n\tif (tp == IRT_CDATA) goto rawcopy;\n\tstep = lj_ir_type_size[tp];\n\tlua_assert((len & (step-1)) == 0);\n      } else if ((ct->info & CTF_UNION)) {\n\tstep = (1u << ctype_align(ct->info));\n\tgoto rawcopy;\n      } else {\n\tmlp = crec_copy_struct(ml, cts, ct);\n\tgoto emitcopy;\n      }\n    } else {\n    rawcopy:\n      needxbar = 1;\n      if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)\n\tstep = CTSIZE_PTR;\n    }\n    mlp = crec_copy_unroll(ml, len, step, tp);\n  emitcopy:\n    if (mlp) {\n      crec_copy_emit(J, ml, mlp, trdst, trsrc);\n      if (needxbar)\n\temitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n      return;\n    }\n  }\nfallback:\n  /* Call memcpy. Always needs a barrier to disable alias analysis. */\n  lj_ir_call(J, IRCALL_memcpy, trdst, trsrc, trlen);\n  emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n}\n\n/* Generate unrolled fill list, from highest to lowest step size/alignment. */\nstatic MSize crec_fill_unroll(CRecMemList *ml, CTSize len, CTSize step)\n{\n  CTSize ofs = 0;\n  MSize mlp = 0;\n  IRType tp = IRT_U8 + 2*lj_fls(step);\n  do {\n    while (ofs + step <= len) {\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = ofs;\n      ml[mlp].tp = tp;\n      mlp++;\n      ofs += step;\n    }\n    step >>= 1;\n    tp -= 2;\n  } while (ofs < len);\n  return mlp;\n}\n\n/*\n** Emit stores for fill list.\n** LJ_TARGET_UNALIGNED: may emit unaligned stores (not marked as such).\n*/\nstatic void crec_fill_emit(jit_State *J, CRecMemList *ml, MSize mlp,\n\t\t\t   TRef trdst, TRef trfill)\n{\n  MSize i;\n  for (i = 0; i < mlp; i++) {\n    TRef trofs = lj_ir_kintp(J, ml[i].ofs);\n    TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, trofs);\n    emitir(IRT(IR_XSTORE, ml[i].tp), trdptr, trfill);\n  }\n}\n\n/* Optimized memory fill. */\nstatic void crec_fill(jit_State *J, TRef trdst, TRef trlen, TRef trfill,\n\t\t      CTSize step)\n{\n  if (tref_isk(trlen)) {  /* Length must be constant. */\n    CRecMemList ml[CREC_FILL_MAXUNROLL];\n    MSize mlp;\n    CTSize len = (CTSize)IR(tref_ref(trlen))->i;\n    if (len == 0) return;  /* Shortcut. */\n    if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)\n      step = CTSIZE_PTR;\n    if (step * CREC_FILL_MAXUNROLL < len) goto fallback;\n    mlp = crec_fill_unroll(ml, len, step);\n    if (!mlp) goto fallback;\n    if (tref_isk(trfill) || ml[0].tp != IRT_U8)\n      trfill = emitconv(trfill, IRT_INT, IRT_U8, 0);\n    if (ml[0].tp != IRT_U8) {  /* Scatter U8 to U16/U32/U64. */\n      if (CTSIZE_PTR == 8 && ml[0].tp == IRT_U64) {\n\tif (tref_isk(trfill))  /* Pointless on x64 with zero-extended regs. */\n\t  trfill = emitconv(trfill, IRT_U64, IRT_U32, 0);\n\ttrfill = emitir(IRT(IR_MUL, IRT_U64), trfill,\n\t\t\tlj_ir_kint64(J, U64x(01010101,01010101)));\n      } else {\n\ttrfill = emitir(IRTI(IR_MUL), trfill,\n\t\t   lj_ir_kint(J, ml[0].tp == IRT_U16 ? 0x0101 : 0x01010101));\n      }\n    }\n    crec_fill_emit(J, ml, mlp, trdst, trfill);\n  } else {\nfallback:\n    /* Call memset. Always needs a barrier to disable alias analysis. */\n    lj_ir_call(J, IRCALL_memset, trdst, trfill, trlen);  /* Note: arg order! */\n  }\n  emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n}\n\n/* -- Convert C type to C type -------------------------------------------- */\n\n/*\n** This code mirrors the code in lj_cconv.c. It performs the same steps\n** for the trace recorder that lj_cconv.c does for the interpreter.\n**\n** One major difference is that we can get away with much fewer checks\n** here. E.g. checks for casts, constness or correct types can often be\n** omitted, even if they might fail. The interpreter subsequently throws\n** an error, which aborts the trace.\n**\n** All operations are specialized to their C types, so the on-trace\n** outcome must be the same as the outcome in the interpreter. If the\n** interpreter doesn't throw an error, then the trace is correct, too.\n** Care must be taken not to generate invalid (temporary) IR or to\n** trigger asserts.\n*/\n\n/* Determine whether a passed number or cdata number is non-zero. */\nstatic int crec_isnonzero(CType *s, void *p)\n{\n  if (p == (void *)0)\n    return 0;\n  if (p == (void *)1)\n    return 1;\n  if ((s->info & CTF_FP)) {\n    if (s->size == sizeof(float))\n      return (*(float *)p != 0);\n    else\n      return (*(double *)p != 0);\n  } else {\n    if (s->size == 1)\n      return (*(uint8_t *)p != 0);\n    else if (s->size == 2)\n      return (*(uint16_t *)p != 0);\n    else if (s->size == 4)\n      return (*(uint32_t *)p != 0);\n    else\n      return (*(uint64_t *)p != 0);\n  }\n}\n\nstatic TRef crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp,\n\t\t       void *svisnz)\n{\n  IRType dt = crec_ct2irt(ctype_ctsG(J2G(J)), d);\n  IRType st = crec_ct2irt(ctype_ctsG(J2G(J)), s);\n  CTSize dsize = d->size, ssize = s->size;\n  CTInfo dinfo = d->info, sinfo = s->info;\n\n  if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)\n    goto err_conv;\n\n  /*\n  ** Note: Unlike lj_cconv_ct_ct(), sp holds the _value_ of pointers and\n  ** numbers up to 8 bytes. Otherwise sp holds a pointer.\n  */\n\n  switch (cconv_idx2(dinfo, sinfo)) {\n  /* Destination is a bool. */\n  case CCX(B, B):\n    goto xstore;  /* Source operand is already normalized. */\n  case CCX(B, I):\n  case CCX(B, F):\n    if (st != IRT_CDATA) {\n      /* Specialize to the result of a comparison against 0. */\n      TRef zero = (st == IRT_NUM  || st == IRT_FLOAT) ? lj_ir_knum(J, 0) :\n\t\t  (st == IRT_I64 || st == IRT_U64) ? lj_ir_kint64(J, 0) :\n\t\t  lj_ir_kint(J, 0);\n      int isnz = crec_isnonzero(s, svisnz);\n      emitir(IRTG(isnz ? IR_NE : IR_EQ, st), sp, zero);\n      sp = lj_ir_kint(J, isnz);\n      goto xstore;\n    }\n    goto err_nyi;\n\n  /* Destination is an integer. */\n  case CCX(I, B):\n  case CCX(I, I):\n  conv_I_I:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    /* Extend 32 to 64 bit integer. */\n    if (dsize == 8 && ssize < 8 && !(LJ_64 && (sinfo & CTF_UNSIGNED)))\n      sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st,\n\t\t    (sinfo & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);\n    else if (dsize < 8 && ssize == 8)  /* Truncate from 64 bit integer. */\n      sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, 0);\n    else if (st == IRT_INT)\n      sp = lj_opt_narrow_toint(J, sp);\n  xstore:\n    if (dt == IRT_I64 || dt == IRT_U64) lj_needsplit(J);\n    if (dp == 0) return sp;\n    emitir(IRT(IR_XSTORE, dt), dp, sp);\n    break;\n  case CCX(I, C):\n    sp = emitir(IRT(IR_XLOAD, st), sp, 0);  /* Load re. */\n    /* fallthrough */\n  case CCX(I, F):\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, IRCONV_ANY);\n    goto xstore;\n  case CCX(I, P):\n  case CCX(I, A):\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    ssize = CTSIZE_PTR;\n    st = IRT_UINTP;\n    if (((dsize ^ ssize) & 8) == 0) {  /* Must insert no-op type conversion. */\n      sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, IRT_PTR, 0);\n      goto xstore;\n    }\n    goto conv_I_I;\n\n  /* Destination is a floating-point number. */\n  case CCX(F, B):\n  case CCX(F, I):\n  conv_F_I:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, 0);\n    goto xstore;\n  case CCX(F, C):\n    sp = emitir(IRT(IR_XLOAD, st), sp, 0);  /* Load re. */\n    /* fallthrough */\n  case CCX(F, F):\n  conv_F_F:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    if (dt != st) sp = emitconv(sp, dt, st, 0);\n    goto xstore;\n\n  /* Destination is a complex number. */\n  case CCX(C, I):\n  case CCX(C, F):\n    {  /* Clear im. */\n      TRef ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));\n      emitir(IRT(IR_XSTORE, dt), ptr, lj_ir_knum(J, 0));\n    }\n    /* Convert to re. */\n    if ((sinfo & CTF_FP)) goto conv_F_F; else goto conv_F_I;\n\n  case CCX(C, C):\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    {\n      TRef re, im, ptr;\n      re = emitir(IRT(IR_XLOAD, st), sp, 0);\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, (ssize >> 1)));\n      im = emitir(IRT(IR_XLOAD, st), ptr, 0);\n      if (dt != st) {\n\tre = emitconv(re, dt, st, 0);\n\tim = emitconv(im, dt, st, 0);\n      }\n      emitir(IRT(IR_XSTORE, dt), dp, re);\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));\n      emitir(IRT(IR_XSTORE, dt), ptr, im);\n    }\n    break;\n\n  /* Destination is a vector. */\n  case CCX(V, I):\n  case CCX(V, F):\n  case CCX(V, C):\n  case CCX(V, V):\n    goto err_nyi;\n\n  /* Destination is a pointer. */\n  case CCX(P, P):\n  case CCX(P, A):\n  case CCX(P, S):\n    /* There are only 32 bit pointers/addresses on 32 bit machines.\n    ** Also ok on x64, since all 32 bit ops clear the upper part of the reg.\n    */\n    goto xstore;\n  case CCX(P, I):\n    if (st == IRT_CDATA) goto err_nyi;\n    if (!LJ_64 && ssize == 8)  /* Truncate from 64 bit integer. */\n      sp = emitconv(sp, IRT_U32, st, 0);\n    goto xstore;\n  case CCX(P, F):\n    if (st == IRT_CDATA) goto err_nyi;\n    /* The signed conversion is cheaper. x64 really has 47 bit pointers. */\n    sp = emitconv(sp, (LJ_64 && dsize == 8) ? IRT_I64 : IRT_U32,\n\t\t  st, IRCONV_ANY);\n    goto xstore;\n\n  /* Destination is an array. */\n  case CCX(A, A):\n  /* Destination is a struct/union. */\n  case CCX(S, S):\n    if (dp == 0) goto err_conv;\n    crec_copy(J, dp, sp, lj_ir_kint(J, dsize), d);\n    break;\n\n  default:\n  err_conv:\n  err_nyi:\n    lj_trace_err(J, LJ_TRERR_NYICONV);\n    break;\n  }\n  return 0;\n}\n\n/* -- Convert C type to TValue (load) ------------------------------------- */\n\nstatic TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  IRType t = crec_ct2irt(cts, s);\n  CTInfo sinfo = s->info;\n  if (ctype_isnum(sinfo)) {\n    TRef tr;\n    if (t == IRT_CDATA)\n      goto err_nyi;  /* NYI: copyval of >64 bit integers. */\n    tr = emitir(IRT(IR_XLOAD, t), sp, 0);\n    if (t == IRT_FLOAT || t == IRT_U32) {  /* Keep uint32_t/float as numbers. */\n      return emitconv(tr, IRT_NUM, t, 0);\n    } else if (t == IRT_I64 || t == IRT_U64) {  /* Box 64 bit integer. */\n      sp = tr;\n      lj_needsplit(J);\n    } else if ((sinfo & CTF_BOOL)) {\n      /* Assume not equal to zero. Fixup and emit pending guard later. */\n      lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      return tr;\n    }\n  } else if (ctype_isptr(sinfo) || ctype_isenum(sinfo)) {\n    sp = emitir(IRT(IR_XLOAD, t), sp, 0);  /* Box pointers and enums. */\n  } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {\n    cts->L = J->L;\n    sid = lj_ctype_intern(cts, CTINFO_REF(sid), CTSIZE_PTR);  /* Create ref. */\n  } else if (ctype_iscomplex(sinfo)) {  /* Unbox/box complex. */\n    ptrdiff_t esz = (ptrdiff_t)(s->size >> 1);\n    TRef ptr, tr1, tr2, dp;\n    dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL);\n    tr1 = emitir(IRT(IR_XLOAD, t), sp, 0);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz));\n    tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)));\n    emitir(IRT(IR_XSTORE, t), ptr, tr1);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)+esz));\n    emitir(IRT(IR_XSTORE, t), ptr, tr2);\n    return dp;\n  } else {\n    /* NYI: copyval of vectors. */\n  err_nyi:\n    lj_trace_err(J, LJ_TRERR_NYICONV);\n  }\n  /* Box pointer, ref, enum or 64 bit integer. */\n  return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, sid), sp);\n}\n\n/* -- Convert TValue to C type (store) ------------------------------------ */\n\nstatic TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID sid = CTID_P_VOID;\n  void *svisnz = 0;\n  CType *s;\n  if (LJ_LIKELY(tref_isinteger(sp))) {\n    sid = CTID_INT32;\n    svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));\n  } else if (tref_isnum(sp)) {\n    sid = CTID_DOUBLE;\n    svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));\n  } else if (tref_isbool(sp)) {\n    sp = lj_ir_kint(J, tref_istrue(sp) ? 1 : 0);\n    sid = CTID_BOOL;\n  } else if (tref_isnil(sp)) {\n    sp = lj_ir_kptr(J, NULL);\n  } else if (tref_isudata(sp)) {\n    GCudata *ud = udataV(sval);\n    if (ud->udtype == UDTYPE_IO_FILE) {\n      TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE);\n      emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));\n      sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_UDATA_FILE);\n    } else {\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCudata)));\n    }\n  } else if (tref_isstr(sp)) {\n    if (ctype_isenum(d->info)) {  /* Match string against enum constant. */\n      GCstr *str = strV(sval);\n      CTSize ofs;\n      CType *cct = lj_ctype_getfield(cts, d, str, &ofs);\n      /* Specialize to the name of the enum constant. */\n      emitir(IRTG(IR_EQ, IRT_STR), sp, lj_ir_kstr(J, str));\n      if (cct && ctype_isconstval(cct->info)) {\n\tlua_assert(ctype_child(cts, cct)->size == 4);\n\tsvisnz = (void *)(intptr_t)(ofs != 0);\n\tsp = lj_ir_kint(J, (int32_t)ofs);\n\tsid = ctype_cid(cct->info);\n      }  /* else: interpreter will throw. */\n    } else if (ctype_isrefarray(d->info)) {  /* Copy string to array. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);  /* NYI */\n    } else {  /* Otherwise pass the string data as a const char[]. */\n      /* Don't use STRREF. It folds with SNEW, which loses the trailing NUL. */\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCstr)));\n      sid = CTID_A_CCHAR;\n    }\n  } else if (tref_islightud(sp)) {\n#if LJ_64\n    sp = emitir(IRT(IR_BAND, IRT_P64), sp,\n\t\tlj_ir_kint64(J, U64x(00007fff,ffffffff)));\n#endif\n  } else {  /* NYI: tref_istab(sp). */\n    IRType t;\n    sid = argv2cdata(J, sp, sval)->ctypeid;\n    s = ctype_raw(cts, sid);\n    svisnz = cdataptr(cdataV(sval));\n    if (ctype_isfunc(s->info)) {\n      sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);\n      s = ctype_get(cts, sid);\n      t = IRT_PTR;\n    } else {\n      t = crec_ct2irt(cts, s);\n    }\n    if (ctype_isptr(s->info)) {\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR);\n      if (ctype_isref(s->info)) {\n\tsvisnz = *(void **)svisnz;\n\ts = ctype_rawchild(cts, s);\n\tif (ctype_isenum(s->info)) s = ctype_child(cts, s);\n\tt = crec_ct2irt(cts, s);\n      } else {\n\tgoto doconv;\n      }\n    } else if (t == IRT_I64 || t == IRT_U64) {\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64);\n      lj_needsplit(J);\n      goto doconv;\n    } else if (t == IRT_INT || t == IRT_U32) {\n      if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT);\n      goto doconv;\n    } else {\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata)));\n    }\n    if (ctype_isnum(s->info) && t != IRT_CDATA)\n      sp = emitir(IRT(IR_XLOAD, t), sp, 0);  /* Load number value. */\n    goto doconv;\n  }\n  s = ctype_get(cts, sid);\ndoconv:\n  if (ctype_isenum(d->info)) d = ctype_child(cts, d);\n  return crec_ct_ct(J, d, s, dp, sp, svisnz);\n}\n\n/* -- C data metamethods -------------------------------------------------- */\n\n/* This would be rather difficult in FOLD, so do it here:\n** (base+k)+(idx*sz)+ofs ==> (base+idx*sz)+(ofs+k)\n** (base+(idx+k)*sz)+ofs ==> (base+idx*sz)+(ofs+k*sz)\n*/\nstatic TRef crec_reassoc_ofs(jit_State *J, TRef tr, ptrdiff_t *ofsp, MSize sz)\n{\n  IRIns *ir = IR(tref_ref(tr));\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && irref_isk(ir->op2) &&\n      (ir->o == IR_ADD || ir->o == IR_ADDOV || ir->o == IR_SUBOV)) {\n    IRIns *irk = IR(ir->op2);\n    ptrdiff_t k;\n    if (LJ_64 && irk->o == IR_KINT64)\n      k = (ptrdiff_t)ir_kint64(irk)->u64 * sz;\n    else\n      k = (ptrdiff_t)irk->i * sz;\n    if (ir->o == IR_SUBOV) *ofsp -= k; else *ofsp += k;\n    tr = ir->op1;  /* Not a TRef, but the caller doesn't care. */\n  }\n  return tr;\n}\n\n/* Record ctype __index/__newindex metamethods. */\nstatic void crec_index_meta(jit_State *J, CTState *cts, CType *ct,\n\t\t\t    RecordFFData *rd)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  cTValue *tv = lj_ctype_meta(cts, id, rd->data ? MM_newindex : MM_index);\n  if (!tv)\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  if (tvisfunc(tv)) {\n    J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;\n    rd->nres = -1;  /* Pending tailcall. */\n  } else if (rd->data == 0 && tvistab(tv) && tref_isstr(J->base[1])) {\n    /* Specialize to result of __index lookup. */\n    cTValue *o = lj_tab_get(J->L, tabV(tv), &rd->argv[1]);\n    J->base[0] = lj_record_constify(J, o);\n    if (!J->base[0])\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    /* Always specialize to the key. */\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));\n  } else {\n    /* NYI: resolving of non-function metamethods. */\n    /* NYI: non-string keys for __index table. */\n    /* NYI: stores to __newindex table. */\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n}\n\nvoid LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)\n{\n  TRef idx, ptr = J->base[0];\n  ptrdiff_t ofs = sizeof(GCcdata);\n  GCcdata *cd = argv2cdata(J, ptr, &rd->argv[0]);\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  CTypeID sid = 0;\n\n  /* Resolve pointer or reference for cdata object. */\n  if (ctype_isptr(ct->info)) {\n    IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n    if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);\n    ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR);\n    ofs = 0;\n    ptr = crec_reassoc_ofs(J, ptr, &ofs, 1);\n  }\n\nagain:\n  idx = J->base[1];\n  if (tref_isnumber(idx)) {\n    idx = lj_opt_narrow_cindex(J, idx);\n    if (ctype_ispointer(ct->info)) {\n      CTSize sz;\n  integer_key:\n      if ((ct->info & CTF_COMPLEX))\n\tidx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1));\n      sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));\n      idx = crec_reassoc_ofs(J, idx, &ofs, sz);\n#if LJ_TARGET_ARM || LJ_TARGET_PPC\n      /* Hoist base add to allow fusion of index/shift into operands. */\n      if (LJ_LIKELY(J->flags & JIT_F_OPT_LOOP) && ofs\n#if LJ_TARGET_ARM\n\t  && (sz == 1 || sz == 4)\n#endif\n\t  ) {\n\tptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));\n\tofs = 0;\n      }\n#endif\n      idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz));\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);\n    }\n  } else if (tref_iscdata(idx)) {\n    GCcdata *cdk = cdataV(&rd->argv[1]);\n    CType *ctk = ctype_raw(cts, cdk->ctypeid);\n    IRType t = crec_ct2irt(cts, ctk);\n    if (ctype_ispointer(ct->info) && t >= IRT_I8 && t <= IRT_U64) {\n      if (ctk->size == 8) {\n\tidx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT64);\n      } else if (ctk->size == 4) {\n\tidx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT);\n      } else {\n\tidx = emitir(IRT(IR_ADD, IRT_PTR), idx,\n\t\t     lj_ir_kintp(J, sizeof(GCcdata)));\n\tidx = emitir(IRT(IR_XLOAD, t), idx, 0);\n      }\n      if (LJ_64 && ctk->size < sizeof(intptr_t) && !(ctk->info & CTF_UNSIGNED))\n\tidx = emitconv(idx, IRT_INTP, IRT_INT, IRCONV_SEXT);\n      if (!LJ_64 && ctk->size > sizeof(intptr_t)) {\n\tidx = emitconv(idx, IRT_INTP, t, 0);\n\tlj_needsplit(J);\n      }\n      goto integer_key;\n    }\n  } else if (tref_isstr(idx)) {\n    GCstr *name = strV(&rd->argv[1]);\n    if (cd && cd->ctypeid == CTID_CTYPEID)\n      ct = ctype_raw(cts, crec_constructor(J, cd, ptr));\n    if (ctype_isstruct(ct->info)) {\n      CTSize fofs;\n      CType *fct;\n      fct = lj_ctype_getfield(cts, ct, name, &fofs);\n      if (fct) {\n\t/* Always specialize to the field name. */\n\temitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));\n\tif (ctype_isconstval(fct->info)) {\n\t  if (fct->size >= 0x80000000u &&\n\t      (ctype_child(cts, fct)->info & CTF_UNSIGNED)) {\n\t    J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)fct->size);\n\t    return;\n\t  }\n\t  J->base[0] = lj_ir_kint(J, (int32_t)fct->size);\n\t  return;  /* Interpreter will throw for newindex. */\n\t} else if (ctype_isbitfield(fct->info)) {\n\t  lj_trace_err(J, LJ_TRERR_NYICONV);\n\t} else {\n\t  lua_assert(ctype_isfield(fct->info));\n\t  sid = ctype_cid(fct->info);\n\t}\n\tofs += (ptrdiff_t)fofs;\n      }\n    } else if (ctype_iscomplex(ct->info)) {\n      if (name->len == 2 &&\n\t  ((strdata(name)[0] == 'r' && strdata(name)[1] == 'e') ||\n\t   (strdata(name)[0] == 'i' && strdata(name)[1] == 'm'))) {\n\t/* Always specialize to the field name. */\n\temitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));\n\tif (strdata(name)[0] == 'i') ofs += (ct->size >> 1);\n\tsid = ctype_cid(ct->info);\n      }\n    }\n  }\n  if (!sid) {\n    if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */\n      CType *cct = ctype_rawchild(cts, ct);\n      if (ctype_isstruct(cct->info)) {\n\tct = cct;\n\tcd = NULL;\n\tif (tref_isstr(idx)) goto again;\n      }\n    }\n    crec_index_meta(J, cts, ct, rd);\n    return;\n  }\n\n  if (ofs)\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));\n\n  /* Resolve reference for field. */\n  ct = ctype_get(cts, sid);\n  if (ctype_isref(ct->info)) {\n    ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0);\n    sid = ctype_cid(ct->info);\n    ct = ctype_get(cts, sid);\n  }\n\n  while (ctype_isattrib(ct->info))\n    ct = ctype_child(cts, ct);  /* Skip attributes. */\n\n  if (rd->data == 0) {  /* __index metamethod. */\n    J->base[0] = crec_tv_ct(J, ct, sid, ptr);\n  } else {  /* __newindex metamethod. */\n    rd->nres = 0;\n    J->needsnap = 1;\n    crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);\n  }\n}\n\n/* Record setting a finalizer. */\nstatic void crec_finalizer(jit_State *J, TRef trcd, TRef trfin, cTValue *fin)\n{\n  if (tvisgcv(fin)) {\n    if (!trfin) trfin = lj_ir_kptr(J, gcval(fin));\n  } else if (tvisnil(fin)) {\n    trfin = lj_ir_kptr(J, NULL);\n  } else {\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd,\n\t     trfin, lj_ir_kint(J, (int32_t)itype(fin)));\n  J->needsnap = 1;\n}\n\n/* Record cdata allocation. */\nstatic void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  CType *d = ctype_raw(cts, id);\n  TRef trcd, trid = lj_ir_kint(J, id);\n  cTValue *fin;\n  /* Use special instruction to box pointer or 32/64 bit integer. */\n  if (ctype_isptr(info) || (ctype_isinteger(info) && (sz == 4 || sz == 8))) {\n    TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) :\n\t      ctype_isptr(info) ? lj_ir_kptr(J, NULL) :\n\t      sz == 4 ? lj_ir_kint(J, 0) :\n\t      (lj_needsplit(J), lj_ir_kint64(J, 0));\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, sp);\n    return;\n  } else {\n    TRef trsz = TREF_NIL;\n    if ((info & CTF_VLA)) {  /* Calculate VLA/VLS size at runtime. */\n      CTSize sz0, sz1;\n      if (!J->base[1] || J->base[2])\n\tlj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init VLA/VLS. */\n      trsz = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0,\n\t\t\tJ->base[1], &rd->argv[1]);\n      sz0 = lj_ctype_vlsize(cts, d, 0);\n      sz1 = lj_ctype_vlsize(cts, d, 1);\n      trsz = emitir(IRTGI(IR_MULOV), trsz, lj_ir_kint(J, (int32_t)(sz1-sz0)));\n      trsz = emitir(IRTGI(IR_ADDOV), trsz, lj_ir_kint(J, (int32_t)sz0));\n      J->base[1] = 0;  /* Simplify logic below. */\n    } else if (ctype_align(info) > CT_MEMALIGN) {\n      trsz = lj_ir_kint(J, sz);\n    }\n    trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, trsz);\n    if (sz > 128 || (info & CTF_VLA)) {\n      TRef dp;\n      CTSize align;\n    special:  /* Only handle bulk zero-fill for large/VLA/VLS types. */\n      if (J->base[1])\n\tlj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init large/VLA/VLS types. */\n      dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata)));\n      if (trsz == TREF_NIL) trsz = lj_ir_kint(J, sz);\n      align = ctype_align(info);\n      if (align < CT_MEMALIGN) align = CT_MEMALIGN;\n      crec_fill(J, dp, trsz, lj_ir_kint(J, 0), (1u << align));\n    } else if (J->base[1] && !J->base[2] &&\n\t!lj_cconv_multi_init(cts, d, &rd->argv[1])) {\n      goto single_init;\n    } else if (ctype_isarray(d->info)) {\n      CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n      CTSize ofs, esize = dc->size;\n      TRef sp = 0;\n      TValue tv;\n      TValue *sval = &tv;\n      MSize i;\n      tv.u64 = 0;\n      if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info)) ||\n\t  esize * CREC_FILL_MAXUNROLL < sz)\n\tgoto special;\n      for (i = 1, ofs = 0; ofs < sz; ofs += esize) {\n\tTRef dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,\n\t\t\t lj_ir_kintp(J, ofs + sizeof(GCcdata)));\n\tif (J->base[i]) {\n\t  sp = J->base[i];\n\t  sval = &rd->argv[i];\n\t  i++;\n\t} else if (i != 2) {\n\t  sp = ctype_isnum(dc->info) ? lj_ir_kint(J, 0) : TREF_NIL;\n\t}\n\tcrec_ct_tv(J, dc, dp, sp, sval);\n      }\n    } else if (ctype_isstruct(d->info)) {\n      CTypeID fid = d->sib;\n      MSize i = 1;\n      while (fid) {\n\tCType *df = ctype_get(cts, fid);\n\tfid = df->sib;\n\tif (ctype_isfield(df->info)) {\n\t  CType *dc;\n\t  TRef sp, dp;\n\t  TValue tv;\n\t  TValue *sval = &tv;\n\t  setintV(&tv, 0);\n\t  if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n\t  dc = ctype_rawchild(cts, df);  /* Field type. */\n\t  if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) ||\n\t\tctype_isenum(dc->info)))\n\t    lj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init aggregates. */\n\t  if (J->base[i]) {\n\t    sp = J->base[i];\n\t    sval = &rd->argv[i];\n\t    i++;\n\t  } else {\n\t    sp = ctype_isptr(dc->info) ? TREF_NIL : lj_ir_kint(J, 0);\n\t  }\n\t  dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,\n\t\t      lj_ir_kintp(J, df->size + sizeof(GCcdata)));\n\t  crec_ct_tv(J, dc, dp, sp, sval);\n\t} else if (!ctype_isconstval(df->info)) {\n\t  /* NYI: init bitfields and sub-structures. */\n\t  lj_trace_err(J, LJ_TRERR_NYICONV);\n\t}\n      }\n    } else {\n      TRef dp;\n    single_init:\n      dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata)));\n      if (J->base[1]) {\n\tcrec_ct_tv(J, d, dp, J->base[1], &rd->argv[1]);\n      } else {\n\tTValue tv;\n\ttv.u64 = 0;\n\tcrec_ct_tv(J, d, dp, lj_ir_kint(J, 0), &tv);\n      }\n    }\n  }\n  J->base[0] = trcd;\n  /* Handle __gc metamethod. */\n  fin = lj_ctype_meta(cts, id, MM_gc);\n  if (fin)\n    crec_finalizer(J, trcd, 0, fin);\n}\n\n/* Record argument conversions. */\nstatic TRef crec_call_args(jit_State *J, RecordFFData *rd,\n\t\t\t   CTState *cts, CType *ct)\n{\n  TRef args[CCI_NARGS_MAX];\n  CTypeID fid;\n  MSize i, n;\n  TRef tr, *base;\n  cTValue *o;\n#if LJ_TARGET_X86\n#if LJ_ABI_WIN\n  TRef *arg0 = NULL, *arg1 = NULL;\n#endif\n  int ngpr = 0;\n  if (ctype_cconv(ct->info) == CTCC_THISCALL)\n    ngpr = 1;\n  else if (ctype_cconv(ct->info) == CTCC_FASTCALL)\n    ngpr = 2;\n#endif\n\n  /* Skip initial attributes. */\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) break;\n    fid = ctf->sib;\n  }\n  args[0] = TREF_NIL;\n  for (n = 0, base = J->base+1, o = rd->argv+1; *base; n++, base++, o++) {\n    CTypeID did;\n    CType *d;\n\n    if (n >= CCI_NARGS_MAX)\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n\n    if (fid) {  /* Get argument type from field. */\n      CType *ctf = ctype_get(cts, fid);\n      fid = ctf->sib;\n      lua_assert(ctype_isfield(ctf->info));\n      did = ctype_cid(ctf->info);\n    } else {\n      if (!(ct->info & CTF_VARARG))\n\tlj_trace_err(J, LJ_TRERR_NYICALL);  /* Too many arguments. */\n      did = lj_ccall_ctid_vararg(cts, o);  /* Infer vararg type. */\n    }\n    d = ctype_raw(cts, did);\n    if (!(ctype_isnum(d->info) || ctype_isptr(d->info) ||\n\t  ctype_isenum(d->info)))\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n    tr = crec_ct_tv(J, d, 0, *base, o);\n    if (ctype_isinteger_or_bool(d->info)) {\n      if (d->size < 4) {\n\tif ((d->info & CTF_UNSIGNED))\n\t  tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_U8 : IRT_U16, 0);\n\telse\n\t  tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_I8 : IRT_I16,IRCONV_SEXT);\n      }\n    } else if (LJ_SOFTFP && ctype_isfp(d->info) && d->size > 4) {\n      lj_needsplit(J);\n    }\n#if LJ_TARGET_X86\n    /* 64 bit args must not end up in registers for fastcall/thiscall. */\n#if LJ_ABI_WIN\n    if (!ctype_isfp(d->info)) {\n      /* Sigh, the Windows/x86 ABI allows reordering across 64 bit args. */\n      if (tref_typerange(tr, IRT_I64, IRT_U64)) {\n\tif (ngpr) {\n\t  arg0 = &args[n]; args[n++] = TREF_NIL; ngpr--;\n\t  if (ngpr) {\n\t    arg1 = &args[n]; args[n++] = TREF_NIL; ngpr--;\n\t  }\n\t}\n      } else {\n\tif (arg0) { *arg0 = tr; arg0 = NULL; n--; continue; }\n\tif (arg1) { *arg1 = tr; arg1 = NULL; n--; continue; }\n\tif (ngpr) ngpr--;\n      }\n    }\n#else\n    if (!ctype_isfp(d->info) && ngpr) {\n      if (tref_typerange(tr, IRT_I64, IRT_U64)) {\n\t/* No reordering for other x86 ABIs. Simply add alignment args. */\n\tdo { args[n++] = TREF_NIL; } while (--ngpr);\n      } else {\n\tngpr--;\n      }\n    }\n#endif\n#endif\n    args[n] = tr;\n  }\n  tr = args[0];\n  for (i = 1; i < n; i++)\n    tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]);\n  return tr;\n}\n\n/* Create a snapshot for the caller, simulating a 'false' return value. */\nstatic void crec_snap_caller(jit_State *J)\n{\n  lua_State *L = J->L;\n  TValue *base = L->base, *top = L->top;\n  const BCIns *pc = J->pc;\n  TRef ftr = J->base[-1];\n  ptrdiff_t delta;\n  if (!frame_islua(base-1) || J->framedepth <= 0)\n    lj_trace_err(J, LJ_TRERR_NYICALL);\n  J->pc = frame_pc(base-1); delta = 1+LJ_FR2+bc_a(J->pc[-1]);\n  L->top = base; L->base = base - delta;\n  J->base[-1] = TREF_FALSE;\n  J->base -= delta; J->baseslot -= (BCReg)delta;\n  J->maxslot = (BCReg)delta; J->framedepth--;\n  lj_snap_add(J);\n  L->base = base; L->top = top;\n  J->framedepth++; J->maxslot = 1;\n  J->base += delta; J->baseslot += (BCReg)delta;\n  J->base[-1] = ftr; J->pc = pc;\n}\n\n/* Record function call. */\nstatic int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  IRType tp = IRT_PTR;\n  if (ctype_isptr(ct->info)) {\n    tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n    ct = ctype_rawchild(cts, ct);\n  }\n  if (ctype_isfunc(ct->info)) {\n    TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR);\n    CType *ctr = ctype_rawchild(cts, ct);\n    IRType t = crec_ct2irt(cts, ctr);\n    TRef tr;\n    TValue tv;\n    /* Check for blacklisted C functions that might call a callback. */\n    setlightudV(&tv,\n\t\tcdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4));\n    if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv)))\n      lj_trace_err(J, LJ_TRERR_BLACKL);\n    if (ctype_isvoid(ctr->info)) {\n      t = IRT_NIL;\n      rd->nres = 0;\n    } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) ||\n\t\t ctype_isenum(ctr->info)) || t == IRT_CDATA) {\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n    }\n    if ((ct->info & CTF_VARARG)\n#if LJ_TARGET_X86\n\t|| ctype_cconv(ct->info) != CTCC_CDECL\n#endif\n\t)\n      func = emitir(IRT(IR_CARG, IRT_NIL), func,\n\t\t    lj_ir_kint(J, ctype_typeid(cts, ct)));\n    tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func);\n    if (ctype_isbool(ctr->info)) {\n      if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) {\n\t/* Don't check result if ignored. */\n\ttr = TREF_NIL;\n      } else {\n\tcrec_snap_caller(J);\n#if LJ_TARGET_X86ORX64\n\t/* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */\n\tlj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0));\n#else\n\tlj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));\n#endif\n\tJ->postproc = LJ_POST_FIXGUARDSNAP;\n\ttr = TREF_TRUE;\n      }\n    } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) ||\n\t       t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) {\n      TRef trid = lj_ir_kint(J, ctype_cid(ct->info));\n      tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr);\n      if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);\n    } else if (t == IRT_FLOAT || t == IRT_U32) {\n      tr = emitconv(tr, IRT_NUM, t, 0);\n    } else if (t == IRT_I8 || t == IRT_I16) {\n      tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT);\n    } else if (t == IRT_U8 || t == IRT_U16) {\n      tr = emitconv(tr, IRT_INT, t, 0);\n    }\n    J->base[0] = tr;\n    J->needsnap = 1;\n    return 1;\n  }\n  return 0;\n}\n\nvoid LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]);\n  CTypeID id = cd->ctypeid;\n  CType *ct;\n  cTValue *tv;\n  MMS mm = MM_call;\n  if (id == CTID_CTYPEID) {\n    id = crec_constructor(J, cd, J->base[0]);\n    mm = MM_new;\n  } else if (crec_call(J, rd, cd)) {\n    return;\n  }\n  /* Record ctype __call/__new metamethod. */\n  ct = ctype_raw(cts, id);\n  tv = lj_ctype_meta(cts, ctype_isptr(ct->info) ? ctype_cid(ct->info) : id, mm);\n  if (tv) {\n    if (tvisfunc(tv)) {\n      J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;\n      rd->nres = -1;  /* Pending tailcall. */\n      return;\n    }\n  } else if (mm == MM_new) {\n    crec_alloc(J, rd, id);\n    return;\n  }\n  /* No metamethod or NYI: non-function metamethods. */\n  lj_trace_err(J, LJ_TRERR_BADTYPE);\n}\n\nstatic TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm)\n{\n  if (ctype_isnum(s[0]->info) && ctype_isnum(s[1]->info)) {\n    IRType dt;\n    CTypeID id;\n    TRef tr;\n    MSize i;\n    IROp op;\n    lj_needsplit(J);\n    if (((s[0]->info & CTF_UNSIGNED) && s[0]->size == 8) ||\n\t((s[1]->info & CTF_UNSIGNED) && s[1]->size == 8)) {\n      dt = IRT_U64; id = CTID_UINT64;\n    } else {\n      dt = IRT_I64; id = CTID_INT64;\n      if (mm < MM_add &&\n\t  !((s[0]->info | s[1]->info) & CTF_FP) &&\n\t  s[0]->size == 4 && s[1]->size == 4) {  /* Try to narrow comparison. */\n\tif (!((s[0]->info ^ s[1]->info) & CTF_UNSIGNED) ||\n\t    (tref_isk(sp[1]) && IR(tref_ref(sp[1]))->i >= 0)) {\n\t  dt = (s[0]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;\n\t  goto comp;\n\t} else if (tref_isk(sp[0]) && IR(tref_ref(sp[0]))->i >= 0) {\n\t  dt = (s[1]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;\n\t  goto comp;\n\t}\n      }\n    }\n    for (i = 0; i < 2; i++) {\n      IRType st = tref_type(sp[i]);\n      if (st == IRT_NUM || st == IRT_FLOAT)\n\tsp[i] = emitconv(sp[i], dt, st, IRCONV_ANY);\n      else if (!(st == IRT_I64 || st == IRT_U64))\n\tsp[i] = emitconv(sp[i], dt, IRT_INT,\n\t\t\t (s[i]->info & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);\n    }\n    if (mm < MM_add) {\n    comp:\n      /* Assume true comparison. Fixup and emit pending guard later. */\n      if (mm == MM_eq) {\n\top = IR_EQ;\n      } else {\n\top = mm == MM_lt ? IR_LT : IR_LE;\n\tif (dt == IRT_U32 || dt == IRT_U64)\n\t  op += (IR_ULT-IR_LT);\n      }\n      lj_ir_set(J, IRTG(op, dt), sp[0], sp[1]);\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, dt), sp[0], sp[1]);\n    }\n    return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n  }\n  return 0;\n}\n\nstatic TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ctp = s[0];\n  if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {\n    if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&\n\t(ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {\n      if (mm == MM_sub) {  /* Pointer difference. */\n\tTRef tr;\n\tCTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));\n\tif (sz == 0 || (sz & (sz-1)) != 0)\n\t  return 0;  /* NYI: integer division. */\n\ttr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]);\n\ttr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz)));\n#if LJ_64\n\ttr = emitconv(tr, IRT_NUM, IRT_INTP, 0);\n#endif\n\treturn tr;\n      } else {  /* Pointer comparison (unsigned). */\n\t/* Assume true comparison. Fixup and emit pending guard later. */\n\tIROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE;\n\tlj_ir_set(J, IRTG(op, IRT_PTR), sp[0], sp[1]);\n\tJ->postproc = LJ_POST_FIXGUARD;\n\treturn TREF_TRUE;\n      }\n    }\n    if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(s[1]->info)))\n      return 0;\n  } else if (mm == MM_add && ctype_isnum(ctp->info) &&\n\t     (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {\n    TRef tr = sp[0]; sp[0] = sp[1]; sp[1] = tr;  /* Swap pointer and index. */\n    ctp = s[1];\n  } else {\n    return 0;\n  }\n  {\n    TRef tr = sp[1];\n    IRType t = tref_type(tr);\n    CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));\n    CTypeID id;\n#if LJ_64\n    if (t == IRT_NUM || t == IRT_FLOAT)\n      tr = emitconv(tr, IRT_INTP, t, IRCONV_ANY);\n    else if (!(t == IRT_I64 || t == IRT_U64))\n      tr = emitconv(tr, IRT_INTP, IRT_INT,\n\t\t    ((t - IRT_I8) & 1) ? 0 : IRCONV_SEXT);\n#else\n    if (!tref_typerange(sp[1], IRT_I8, IRT_U32)) {\n      tr = emitconv(tr, IRT_INTP, t,\n\t\t    (t == IRT_NUM || t == IRT_FLOAT) ? IRCONV_ANY : 0);\n    }\n#endif\n    tr = emitir(IRT(IR_MUL, IRT_INTP), tr, lj_ir_kintp(J, sz));\n    tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, IRT_PTR), sp[0], tr);\n    id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),\n\t\t\t CTSIZE_PTR);\n    return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n  }\n}\n\n/* Record ctype arithmetic metamethods. */\nstatic TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts,\n\t\t\t    RecordFFData *rd)\n{\n  cTValue *tv = NULL;\n  if (J->base[0]) {\n    if (tviscdata(&rd->argv[0])) {\n      CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n      tv = lj_ctype_meta(cts, id, (MMS)rd->data);\n    }\n    if (!tv && J->base[1] && tviscdata(&rd->argv[1])) {\n      CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n      tv = lj_ctype_meta(cts, id, (MMS)rd->data);\n    }\n  }\n  if (tv) {\n    if (tvisfunc(tv)) {\n      J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;\n      rd->nres = -1;  /* Pending tailcall. */\n      return 0;\n    }  /* NYI: non-function metamethods. */\n  } else if ((MMS)rd->data == MM_eq) {  /* Fallback cdata pointer comparison. */\n    if (sp[0] && sp[1] && ctype_isnum(s[0]->info) == ctype_isnum(s[1]->info)) {\n      /* Assume true comparison. Fixup and emit pending guard later. */\n      lj_ir_set(J, IRTG(IR_EQ, IRT_PTR), sp[0], sp[1]);\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      return TREF_FALSE;\n    }\n  }\n  lj_trace_err(J, LJ_TRERR_BADTYPE);\n  return 0;\n}\n\nvoid LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef sp[2];\n  CType *s[2];\n  MSize i;\n  for (i = 0; i < 2; i++) {\n    TRef tr = J->base[i];\n    CType *ct = ctype_get(cts, CTID_DOUBLE);\n    if (!tr) {\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    } else if (tref_iscdata(tr)) {\n      CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid;\n      IRType t;\n      ct = ctype_raw(cts, id);\n      t = crec_ct2irt(cts, ct);\n      if (ctype_isptr(ct->info)) {  /* Resolve pointer or reference. */\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR);\n\tif (ctype_isref(ct->info)) {\n\t  ct = ctype_rawchild(cts, ct);\n\t  t = crec_ct2irt(cts, ct);\n\t}\n      } else if (t == IRT_I64 || t == IRT_U64) {\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64);\n\tlj_needsplit(J);\n\tgoto ok;\n      } else if (t == IRT_INT || t == IRT_U32) {\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT);\n\tif (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n\tgoto ok;\n      } else if (ctype_isfunc(ct->info)) {\n\ttr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR);\n\tct = ctype_get(cts,\n\t  lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));\n\tgoto ok;\n      } else {\n\ttr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata)));\n      }\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      if (ctype_isnum(ct->info)) {\n\tif (t == IRT_CDATA) {\n\t  tr = 0;\n\t} else {\n\t  if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);\n\t  tr = emitir(IRT(IR_XLOAD, t), tr, 0);\n\t}\n      }\n    } else if (tref_isnil(tr)) {\n      tr = lj_ir_kptr(J, NULL);\n      ct = ctype_get(cts, CTID_P_VOID);\n    } else if (tref_isinteger(tr)) {\n      ct = ctype_get(cts, CTID_INT32);\n    } else if (tref_isstr(tr)) {\n      TRef tr2 = J->base[1-i];\n      CTypeID id = argv2cdata(J, tr2, &rd->argv[1-i])->ctypeid;\n      ct = ctype_raw(cts, id);\n      if (ctype_isenum(ct->info)) {  /* Match string against enum constant. */\n\tGCstr *str = strV(&rd->argv[i]);\n\tCTSize ofs;\n\tCType *cct = lj_ctype_getfield(cts, ct, str, &ofs);\n\tif (cct && ctype_isconstval(cct->info)) {\n\t  /* Specialize to the name of the enum constant. */\n\t  emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str));\n\t  ct = ctype_child(cts, cct);\n\t  tr = lj_ir_kint(J, (int32_t)ofs);\n\t} else {  /* Interpreter will throw or return false. */\n\t  ct = ctype_get(cts, CTID_P_VOID);\n\t}\n      } else if (ctype_isptr(ct->info)) {\n\ttr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr)));\n      } else {\n\tct = ctype_get(cts, CTID_P_VOID);\n      }\n    } else if (!tref_isnum(tr)) {\n      tr = 0;\n      ct = ctype_get(cts, CTID_P_VOID);\n    }\n  ok:\n    s[i] = ct;\n    sp[i] = tr;\n  }\n  {\n    TRef tr;\n    if (!(tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) &&\n\t!(tr = crec_arith_ptr(J, sp, s, (MMS)rd->data)) &&\n\t!(tr = crec_arith_meta(J, sp, s, cts, rd)))\n      return;\n    J->base[0] = tr;\n    /* Fixup cdata comparisons, too. Avoids some cdata escapes. */\n    if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) &&\n\t!irt_isguard(J->guardemit)) {\n      const BCIns *pc = frame_contpc(J->L->base-1) - 1;\n      if (bc_op(*pc) <= BC_ISNEP) {\n\tJ2G(J)->tmptv.u64 = (uint64_t)(uintptr_t)pc;\n\tJ->postproc = LJ_POST_FIXCOMP;\n      }\n    }\n  }\n}\n\n/* -- C library namespace metamethods ------------------------------------- */\n\nvoid LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) &&\n      udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) {\n    CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0]));\n    GCstr *name = strV(&rd->argv[1]);\n    CType *ct;\n    CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);\n    cTValue *tv = lj_tab_getstr(cl->cache, name);\n    rd->nres = rd->data;\n    if (id && tv && !tvisnil(tv)) {\n      /* Specialize to the symbol name and make the result a constant. */\n      emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name));\n      if (ctype_isconstval(ct->info)) {\n\tif (ct->size >= 0x80000000u &&\n\t    (ctype_child(cts, ct)->info & CTF_UNSIGNED))\n\t  J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size);\n\telse\n\t  J->base[0] = lj_ir_kint(J, (int32_t)ct->size);\n      } else if (ctype_isextern(ct->info)) {\n\tCTypeID sid = ctype_cid(ct->info);\n\tvoid *sp = *(void **)cdataptr(cdataV(tv));\n\tTRef ptr;\n\tct = ctype_raw(cts, sid);\n\tif (LJ_64 && !checkptr32(sp))\n\t  ptr = lj_ir_kintp(J, (uintptr_t)sp);\n\telse\n\t  ptr = lj_ir_kptr(J, sp);\n\tif (rd->data) {\n\t  J->base[0] = crec_tv_ct(J, ct, sid, ptr);\n\t} else {\n\t  J->needsnap = 1;\n\t  crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);\n\t}\n      } else {\n\tJ->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA);\n      }\n    } else {\n      lj_trace_err(J, LJ_TRERR_NOCACHE);\n    }\n  }  /* else: interpreter will throw. */\n}\n\n/* -- FFI library functions ----------------------------------------------- */\n\nstatic TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval)\n{\n  return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval);\n}\n\nvoid LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd)\n{\n  crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0]));\n}\n\nvoid LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd)\n{\n  UNUSED(rd);\n  if (J->base[0])\n    lj_trace_err(J, LJ_TRERR_NYICALL);\n  J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno);\n}\n\nvoid LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef tr = J->base[0];\n  if (tr) {\n    TRef trlen = J->base[1];\n    if (!tref_isnil(trlen)) {\n      trlen = crec_toint(J, cts, trlen, &rd->argv[1]);\n      tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]);\n    } else {\n      tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]);\n      trlen = lj_ir_call(J, IRCALL_strlen, tr);\n    }\n    J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), tr, trlen);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2];\n  if (trdst && trsrc && (trlen || tref_isstr(trsrc))) {\n    trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);\n    trsrc = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, trsrc, &rd->argv[1]);\n    if (trlen) {\n      trlen = crec_toint(J, cts, trlen, &rd->argv[2]);\n    } else {\n      trlen = emitir(IRTI(IR_FLOAD), J->base[1], IRFL_STR_LEN);\n      trlen = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));\n    }\n    rd->nres = 0;\n    crec_copy(J, trdst, trsrc, trlen, NULL);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2];\n  if (trdst && trlen) {\n    CTSize step = 1;\n    if (tviscdata(&rd->argv[0])) {  /* Get alignment of original destination. */\n      CTSize sz;\n      CType *ct = ctype_raw(cts, cdataV(&rd->argv[0])->ctypeid);\n      if (ctype_isptr(ct->info))\n\tct = ctype_rawchild(cts, ct);\n      step = (1u<<ctype_align(lj_ctype_info(cts, ctype_typeid(cts, ct), &sz)));\n    }\n    trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);\n    trlen = crec_toint(J, cts, trlen, &rd->argv[1]);\n    if (trfill)\n      trfill = crec_toint(J, cts, trfill, &rd->argv[2]);\n    else\n      trfill = lj_ir_kint(J, 0);\n    rd->nres = 0;\n    crec_fill(J, trdst, trlen, trfill, step);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd)\n{\n  if (tref_iscdata(J->base[0])) {\n    TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0]));\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA),\n\t\t\tlj_ir_kint(J, CTID_CTYPEID), trid);\n  } else {\n    setfuncV(J->L, &J->errinfo, J->fn);\n    lj_trace_err_info(J, LJ_TRERR_NYIFFU);\n  }\n}\n\nvoid LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd)\n{\n  argv2ctype(J, J->base[0], &rd->argv[0]);\n  if (tref_iscdata(J->base[1])) {\n    argv2ctype(J, J->base[1], &rd->argv[1]);\n    J->postproc = LJ_POST_FIXBOOL;\n    J->base[0] = TREF_TRUE;\n  } else {\n    J->base[0] = TREF_FALSE;\n  }\n}\n\nvoid LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)\n{\n  if (tref_isstr(J->base[0])) {\n    /* Specialize to the ABI string to make the boolean result a constant. */\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0])));\n    J->postproc = LJ_POST_FIXBOOL;\n    J->base[0] = TREF_TRUE;\n  } else {\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n}\n\n/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */\nvoid LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)\n{\n  CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]);\n  if (rd->data == FF_ffi_sizeof) {\n    CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id);\n    if (ctype_isvltype(ct->info))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  } else if (rd->data == FF_ffi_offsetof) {  /* Specialize to the field name. */\n    if (!tref_isstr(J->base[1]))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));\n    rd->nres = 3;  /* Just in case. */\n  }\n  J->postproc = LJ_POST_FIXCONST;\n  J->base[0] = J->base[1] = J->base[2] = TREF_NIL;\n}\n\nvoid LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)\n{\n  argv2cdata(J, J->base[0], &rd->argv[0]);\n  if (!J->base[1])\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  crec_finalizer(J, J->base[0], J->base[1], &rd->argv[1]);\n}\n\n/* -- 64 bit bit.* library functions -------------------------------------- */\n\n/* Determine bit operation type from argument type. */\nstatic CTypeID crec_bit64_type(CTState *cts, cTValue *tv)\n{\n  if (tviscdata(tv)) {\n    CType *ct = lj_ctype_rawref(cts, cdataV(tv)->ctypeid);\n    if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n    if ((ct->info & (CTMASK_NUM|CTF_BOOL|CTF_FP|CTF_UNSIGNED)) ==\n\tCTINFO(CT_NUM, CTF_UNSIGNED) && ct->size == 8)\n      return CTID_UINT64;  /* Use uint64_t, since it has the highest rank. */\n    return CTID_INT64;  /* Otherwise use int64_t. */\n  }\n  return 0;  /* Use regular 32 bit ops. */\n}\n\nvoid LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef tr = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,\n\t\t       J->base[0], &rd->argv[0]);\n  if (!tref_isinteger(tr))\n    tr = emitconv(tr, IRT_INT, tref_type(tr), 0);\n  J->base[0] = tr;\n}\n\nint LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = crec_bit64_type(cts, &rd->argv[0]);\n  if (id) {\n    TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    tr = emitir(IRT(rd->data, id-CTID_INT64+IRT_I64), tr, 0);\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nint LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = 0;\n  MSize i;\n  for (i = 0; J->base[i] != 0; i++) {\n    CTypeID aid = crec_bit64_type(cts, &rd->argv[i]);\n    if (id < aid) id = aid;  /* Determine highest type rank of all arguments. */\n  }\n  if (id) {\n    CType *ct = ctype_get(cts, id);\n    uint32_t ot = IRT(rd->data, id-CTID_INT64+IRT_I64);\n    TRef tr = crec_ct_tv(J, ct, 0, J->base[0], &rd->argv[0]);\n    for (i = 1; J->base[i] != 0; i++) {\n      TRef tr2 = crec_ct_tv(J, ct, 0, J->base[i], &rd->argv[i]);\n      tr = emitir(ot, tr, tr2);\n    }\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nint LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id;\n  TRef tsh = 0;\n  if (J->base[0] && tref_iscdata(J->base[1])) {\n    tsh = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,\n\t\t     J->base[1], &rd->argv[1]);\n    if (!tref_isinteger(tsh))\n      tsh = emitconv(tsh, IRT_INT, tref_type(tsh), 0);\n    J->base[1] = tsh;\n  }\n  id = crec_bit64_type(cts, &rd->argv[0]);\n  if (id) {\n    TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    uint32_t op = rd->data;\n    if (!tsh) tsh = lj_opt_narrow_tobit(J, J->base[1]);\n    if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n\t!tref_isk(tsh))\n      tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 63));\n#ifdef LJ_TARGET_UNIFYROT\n      if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) {\n\top = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR;\n\ttsh = emitir(IRTI(IR_NEG), tsh, tsh);\n      }\n#endif\n    tr = emitir(IRT(op, id-CTID_INT64+IRT_I64), tr, tsh);\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nTRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = crec_bit64_type(cts, &rd->argv[0]);\n  TRef tr, trsf = J->base[1];\n  SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);\n  int32_t n;\n  if (trsf) {\n    CTypeID id2 = 0;\n    n = (int32_t)lj_carith_check64(J->L, 2, &id2);\n    if (id2)\n      trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]);\n    else\n      trsf = lj_opt_narrow_tobit(J, trsf);\n    emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n));  /* Specialize to n. */\n  } else {\n    n = id ? 16 : 8;\n  }\n  if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }\n  sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);\n  if (id) {\n    tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    if (n < 16)\n      tr = emitir(IRT(IR_BAND, IRT_U64), tr,\n\t\t  lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));\n  } else {\n    tr = lj_opt_narrow_tobit(J, J->base[0]);\n    if (n < 8)\n      tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << 4*n)-1)));\n    tr = emitconv(tr, IRT_U64, IRT_INT, 0);  /* No sign-extension. */\n    lj_needsplit(J);\n  }\n  return lj_ir_call(J, IRCALL_lj_strfmt_putfxint, hdr, lj_ir_kint(J, sf), tr);\n}\n\n/* -- Miscellaneous library functions ------------------------------------- */\n\nvoid LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid);\n  if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n  if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {\n    if (ctype_isinteger_or_bool(ct->info) && ct->size <= 4 &&\n\t!(ct->size == 4 && (ct->info & CTF_UNSIGNED)))\n      d = ctype_get(cts, CTID_INT32);\n    else\n      d = ctype_get(cts, CTID_DOUBLE);\n    J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]);\n  } else {\n    J->base[0] = TREF_NIL;\n  }\n}\n\n#undef IR\n#undef emitir\n#undef emitconv\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_crecord.h",
    "content": "/*\n** Trace recorder for C data operations.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CRECORD_H\n#define _LJ_CRECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n#include \"lj_ffrecord.h\"\n\n#if LJ_HASJIT && LJ_HASFFI\nLJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);\n\nLJ_FUNC void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd);\nLJ_FUNC TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr);\n\nLJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ctype.c",
    "content": "/*\n** C type management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ctype.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_buf.h\"\n\n/* -- C type definitions -------------------------------------------------- */\n\n/* Predefined typedefs. */\n#define CTTDDEF(_) \\\n  /* Vararg handling. */ \\\n  _(\"va_list\",\t\t\tP_VOID) \\\n  _(\"__builtin_va_list\",\tP_VOID) \\\n  _(\"__gnuc_va_list\",\t\tP_VOID) \\\n  /* From stddef.h. */ \\\n  _(\"ptrdiff_t\",\t\tINT_PSZ) \\\n  _(\"size_t\",\t\t\tUINT_PSZ) \\\n  _(\"wchar_t\",\t\t\tWCHAR) \\\n  /* Subset of stdint.h. */ \\\n  _(\"int8_t\",\t\t\tINT8) \\\n  _(\"int16_t\",\t\t\tINT16) \\\n  _(\"int32_t\",\t\t\tINT32) \\\n  _(\"int64_t\",\t\t\tINT64) \\\n  _(\"uint8_t\",\t\t\tUINT8) \\\n  _(\"uint16_t\",\t\t\tUINT16) \\\n  _(\"uint32_t\",\t\t\tUINT32) \\\n  _(\"uint64_t\",\t\t\tUINT64) \\\n  _(\"intptr_t\",\t\t\tINT_PSZ) \\\n  _(\"uintptr_t\",\t\tUINT_PSZ) \\\n  /* From POSIX. */ \\\n  _(\"ssize_t\",\t\t\tINT_PSZ) \\\n  /* End of typedef list. */\n\n/* Keywords (only the ones we actually care for). */\n#define CTKWDEF(_) \\\n  /* Type specifiers. */ \\\n  _(\"void\",\t\t-1,\tCTOK_VOID) \\\n  _(\"_Bool\",\t\t0,\tCTOK_BOOL) \\\n  _(\"bool\",\t\t1,\tCTOK_BOOL) \\\n  _(\"char\",\t\t1,\tCTOK_CHAR) \\\n  _(\"int\",\t\t4,\tCTOK_INT) \\\n  _(\"__int8\",\t\t1,\tCTOK_INT) \\\n  _(\"__int16\",\t\t2,\tCTOK_INT) \\\n  _(\"__int32\",\t\t4,\tCTOK_INT) \\\n  _(\"__int64\",\t\t8,\tCTOK_INT) \\\n  _(\"float\",\t\t4,\tCTOK_FP) \\\n  _(\"double\",\t\t8,\tCTOK_FP) \\\n  _(\"long\",\t\t0,\tCTOK_LONG) \\\n  _(\"short\",\t\t0,\tCTOK_SHORT) \\\n  _(\"_Complex\",\t\t0,\tCTOK_COMPLEX) \\\n  _(\"complex\",\t\t0,\tCTOK_COMPLEX) \\\n  _(\"__complex\",\t0,\tCTOK_COMPLEX) \\\n  _(\"__complex__\",\t0,\tCTOK_COMPLEX) \\\n  _(\"signed\",\t\t0,\tCTOK_SIGNED) \\\n  _(\"__signed\",\t\t0,\tCTOK_SIGNED) \\\n  _(\"__signed__\",\t0,\tCTOK_SIGNED) \\\n  _(\"unsigned\",\t\t0,\tCTOK_UNSIGNED) \\\n  /* Type qualifiers. */ \\\n  _(\"const\",\t\t0,\tCTOK_CONST) \\\n  _(\"__const\",\t\t0,\tCTOK_CONST) \\\n  _(\"__const__\",\t0,\tCTOK_CONST) \\\n  _(\"volatile\",\t\t0,\tCTOK_VOLATILE) \\\n  _(\"__volatile\",\t0,\tCTOK_VOLATILE) \\\n  _(\"__volatile__\",\t0,\tCTOK_VOLATILE) \\\n  _(\"restrict\",\t\t0,\tCTOK_RESTRICT) \\\n  _(\"__restrict\",\t0,\tCTOK_RESTRICT) \\\n  _(\"__restrict__\",\t0,\tCTOK_RESTRICT) \\\n  _(\"inline\",\t\t0,\tCTOK_INLINE) \\\n  _(\"__inline\",\t\t0,\tCTOK_INLINE) \\\n  _(\"__inline__\",\t0,\tCTOK_INLINE) \\\n  /* Storage class specifiers. */ \\\n  _(\"typedef\",\t\t0,\tCTOK_TYPEDEF) \\\n  _(\"extern\",\t\t0,\tCTOK_EXTERN) \\\n  _(\"static\",\t\t0,\tCTOK_STATIC) \\\n  _(\"auto\",\t\t0,\tCTOK_AUTO) \\\n  _(\"register\",\t\t0,\tCTOK_REGISTER) \\\n  /* GCC Attributes. */ \\\n  _(\"__extension__\",\t0,\tCTOK_EXTENSION) \\\n  _(\"__attribute\",\t0,\tCTOK_ATTRIBUTE) \\\n  _(\"__attribute__\",\t0,\tCTOK_ATTRIBUTE) \\\n  _(\"asm\",\t\t0,\tCTOK_ASM) \\\n  _(\"__asm\",\t\t0,\tCTOK_ASM) \\\n  _(\"__asm__\",\t\t0,\tCTOK_ASM) \\\n  /* MSVC Attributes. */ \\\n  _(\"__declspec\",\t0,\tCTOK_DECLSPEC) \\\n  _(\"__cdecl\",\t\tCTCC_CDECL,\tCTOK_CCDECL) \\\n  _(\"__thiscall\",\tCTCC_THISCALL,\tCTOK_CCDECL) \\\n  _(\"__fastcall\",\tCTCC_FASTCALL,\tCTOK_CCDECL) \\\n  _(\"__stdcall\",\tCTCC_STDCALL,\tCTOK_CCDECL) \\\n  _(\"__ptr32\",\t\t4,\tCTOK_PTRSZ) \\\n  _(\"__ptr64\",\t\t8,\tCTOK_PTRSZ) \\\n  /* Other type specifiers. */ \\\n  _(\"struct\",\t\t0,\tCTOK_STRUCT) \\\n  _(\"union\",\t\t0,\tCTOK_UNION) \\\n  _(\"enum\",\t\t0,\tCTOK_ENUM) \\\n  /* Operators. */ \\\n  _(\"sizeof\",\t\t0,\tCTOK_SIZEOF) \\\n  _(\"__alignof\",\t0,\tCTOK_ALIGNOF) \\\n  _(\"__alignof__\",\t0,\tCTOK_ALIGNOF) \\\n  /* End of keyword list. */\n\n/* Type info for predefined types. Size merged in. */\nstatic CTInfo lj_ctype_typeinfo[] = {\n#define CTTYINFODEF(id, sz, ct, info)\tCTINFO((ct),(((sz)&0x3fu)<<10)+(info)),\n#define CTTDINFODEF(name, id)\t\tCTINFO(CT_TYPEDEF, CTID_##id),\n#define CTKWINFODEF(name, sz, kw)\tCTINFO(CT_KW,(((sz)&0x3fu)<<10)+(kw)),\nCTTYDEF(CTTYINFODEF)\nCTTDDEF(CTTDINFODEF)\nCTKWDEF(CTKWINFODEF)\n#undef CTTYINFODEF\n#undef CTTDINFODEF\n#undef CTKWINFODEF\n  0\n};\n\n/* Predefined type names collected in a single string. */\nstatic const char * const lj_ctype_typenames =\n#define CTTDNAMEDEF(name, id)\t\tname \"\\0\"\n#define CTKWNAMEDEF(name, sz, cds)\tname \"\\0\"\nCTTDDEF(CTTDNAMEDEF)\nCTKWDEF(CTKWNAMEDEF)\n#undef CTTDNAMEDEF\n#undef CTKWNAMEDEF\n;\n\n#define CTTYPEINFO_NUM\t\t(sizeof(lj_ctype_typeinfo)/sizeof(CTInfo)-1)\n#ifdef LUAJIT_CTYPE_CHECK_ANCHOR\n#define CTTYPETAB_MIN\t\tCTTYPEINFO_NUM\n#else\n#define CTTYPETAB_MIN\t\t128\n#endif\n\n/* -- C type interning ---------------------------------------------------- */\n\n#define ct_hashtype(info, size)\t(hashrot(info, size) & CTHASH_MASK)\n#define ct_hashname(name) \\\n  (hashrot(u32ptr(name), u32ptr(name) + HASH_BIAS) & CTHASH_MASK)\n\n/* Create new type element. */\nCTypeID lj_ctype_new(CTState *cts, CType **ctp)\n{\n  CTypeID id = cts->top;\n  CType *ct;\n  lua_assert(cts->L);\n  if (LJ_UNLIKELY(id >= cts->sizetab)) {\n    if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);\n#ifdef LUAJIT_CTYPE_CHECK_ANCHOR\n    ct = lj_mem_newvec(cts->L, id+1, CType);\n    memcpy(ct, cts->tab, id*sizeof(CType));\n    memset(cts->tab, 0, id*sizeof(CType));\n    lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType);\n    cts->tab = ct;\n    cts->sizetab = id+1;\n#else\n    lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);\n#endif\n  }\n  cts->top = id+1;\n  *ctp = ct = &cts->tab[id];\n  ct->info = 0;\n  ct->size = 0;\n  ct->sib = 0;\n  ct->next = 0;\n  setgcrefnull(ct->name);\n  return id;\n}\n\n/* Intern a type element. */\nCTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size)\n{\n  uint32_t h = ct_hashtype(info, size);\n  CTypeID id = cts->hash[h];\n  lua_assert(cts->L);\n  while (id) {\n    CType *ct = ctype_get(cts, id);\n    if (ct->info == info && ct->size == size)\n      return id;\n    id = ct->next;\n  }\n  id = cts->top;\n  if (LJ_UNLIKELY(id >= cts->sizetab)) {\n    if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);\n    lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);\n  }\n  cts->top = id+1;\n  cts->tab[id].info = info;\n  cts->tab[id].size = size;\n  cts->tab[id].sib = 0;\n  cts->tab[id].next = cts->hash[h];\n  setgcrefnull(cts->tab[id].name);\n  cts->hash[h] = (CTypeID1)id;\n  return id;\n}\n\n/* Add type element to hash table. */\nstatic void ctype_addtype(CTState *cts, CType *ct, CTypeID id)\n{\n  uint32_t h = ct_hashtype(ct->info, ct->size);\n  ct->next = cts->hash[h];\n  cts->hash[h] = (CTypeID1)id;\n}\n\n/* Add named element to hash table. */\nvoid lj_ctype_addname(CTState *cts, CType *ct, CTypeID id)\n{\n  uint32_t h = ct_hashname(gcref(ct->name));\n  ct->next = cts->hash[h];\n  cts->hash[h] = (CTypeID1)id;\n}\n\n/* Get a C type by name, matching the type mask. */\nCTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, uint32_t tmask)\n{\n  CTypeID id = cts->hash[ct_hashname(name)];\n  while (id) {\n    CType *ct = ctype_get(cts, id);\n    if (gcref(ct->name) == obj2gco(name) &&\n\t((tmask >> ctype_type(ct->info)) & 1)) {\n      *ctp = ct;\n      return id;\n    }\n    id = ct->next;\n  }\n  *ctp = &cts->tab[0];  /* Simplify caller logic. ctype_get() would assert. */\n  return 0;\n}\n\n/* Get a struct/union/enum/function field by name. */\nCType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, CTSize *ofs,\n\t\t\t  CTInfo *qual)\n{\n  while (ct->sib) {\n    ct = ctype_get(cts, ct->sib);\n    if (gcref(ct->name) == obj2gco(name)) {\n      *ofs = ct->size;\n      return ct;\n    }\n    if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      CType *fct, *cct = ctype_child(cts, ct);\n      CTInfo q = 0;\n      while (ctype_isattrib(cct->info)) {\n\tif (ctype_attrib(cct->info) == CTA_QUAL) q |= cct->size;\n\tcct = ctype_child(cts, cct);\n      }\n      fct = lj_ctype_getfieldq(cts, cct, name, ofs, qual);\n      if (fct) {\n\tif (qual) *qual |= q;\n\t*ofs += ct->size;\n\treturn fct;\n      }\n    }\n  }\n  return NULL;  /* Not found. */\n}\n\n/* -- C type information -------------------------------------------------- */\n\n/* Follow references and get raw type for a C type ID. */\nCType *lj_ctype_rawref(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_get(cts, id);\n  while (ctype_isattrib(ct->info) || ctype_isref(ct->info))\n    ct = ctype_child(cts, ct);\n  return ct;\n}\n\n/* Get size for a C type ID. Does NOT support VLA/VLS. */\nCTSize lj_ctype_size(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_raw(cts, id);\n  return ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;\n}\n\n/* Get size for a variable-length C type. Does NOT support other C types. */\nCTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem)\n{\n  uint64_t xsz = 0;\n  if (ctype_isstruct(ct->info)) {\n    CTypeID arrid = 0, fid = ct->sib;\n    xsz = ct->size;  /* Add the struct size. */\n    while (fid) {\n      CType *ctf = ctype_get(cts, fid);\n      if (ctype_type(ctf->info) == CT_FIELD)\n\tarrid = ctype_cid(ctf->info);  /* Remember last field of VLS. */\n      fid = ctf->sib;\n    }\n    ct = ctype_raw(cts, arrid);\n  }\n  lua_assert(ctype_isvlarray(ct->info));  /* Must be a VLA. */\n  ct = ctype_rawchild(cts, ct);  /* Get array element. */\n  lua_assert(ctype_hassize(ct->info));\n  /* Calculate actual size of VLA and check for overflow. */\n  xsz += (uint64_t)ct->size * nelem;\n  return xsz < 0x80000000u ? (CTSize)xsz : CTSIZE_INVALID;\n}\n\n/* Get type, qualifiers, size and alignment for a C type ID. */\nCTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp)\n{\n  CTInfo qual = 0;\n  CType *ct = ctype_get(cts, id);\n  for (;;) {\n    CTInfo info = ct->info;\n    if (ctype_isenum(info)) {\n      /* Follow child. Need to look at its attributes, too. */\n    } else if (ctype_isattrib(info)) {\n      if (ctype_isxattrib(info, CTA_QUAL))\n\tqual |= ct->size;\n      else if (ctype_isxattrib(info, CTA_ALIGN) && !(qual & CTFP_ALIGNED))\n\tqual |= CTFP_ALIGNED + CTALIGN(ct->size);\n    } else {\n      if (!(qual & CTFP_ALIGNED)) qual |= (info & CTF_ALIGN);\n      qual |= (info & ~(CTF_ALIGN|CTMASK_CID));\n      lua_assert(ctype_hassize(info) || ctype_isfunc(info));\n      *szp = ctype_isfunc(info) ? CTSIZE_INVALID : ct->size;\n      break;\n    }\n    ct = ctype_get(cts, ctype_cid(info));\n  }\n  return qual;\n}\n\n/* Get ctype metamethod. */\ncTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)\n{\n  CType *ct = ctype_get(cts, id);\n  cTValue *tv;\n  while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) {\n    id = ctype_cid(ct->info);\n    ct = ctype_get(cts, id);\n  }\n  if (ctype_isptr(ct->info) &&\n      ctype_isfunc(ctype_get(cts, ctype_cid(ct->info))->info))\n    tv = lj_tab_getstr(cts->miscmap, &cts->g->strempty);\n  else\n    tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);\n  if (tv && tvistab(tv) &&\n      (tv = lj_tab_getstr(tabV(tv), mmname_str(cts->g, mm))) && !tvisnil(tv))\n    return tv;\n  return NULL;\n}\n\n/* -- C type representation ----------------------------------------------- */\n\n/* Fixed max. length of a C type representation. */\n#define CTREPR_MAX\t\t512\n\ntypedef struct CTRepr {\n  char *pb, *pe;\n  CTState *cts;\n  lua_State *L;\n  int needsp;\n  int ok;\n  char buf[CTREPR_MAX];\n} CTRepr;\n\n/* Prepend string. */\nstatic void ctype_prepstr(CTRepr *ctr, const char *str, MSize len)\n{\n  char *p = ctr->pb;\n  if (ctr->buf + len+1 > p) { ctr->ok = 0; return; }\n  if (ctr->needsp) *--p = ' ';\n  ctr->needsp = 1;\n  p -= len;\n  while (len-- > 0) p[len] = str[len];\n  ctr->pb = p;\n}\n\n#define ctype_preplit(ctr, str)\tctype_prepstr((ctr), \"\" str, sizeof(str)-1)\n\n/* Prepend char. */\nstatic void ctype_prepc(CTRepr *ctr, int c)\n{\n  if (ctr->buf >= ctr->pb) { ctr->ok = 0; return; }\n  *--ctr->pb = c;\n}\n\n/* Prepend number. */\nstatic void ctype_prepnum(CTRepr *ctr, uint32_t n)\n{\n  char *p = ctr->pb;\n  if (ctr->buf + 10+1 > p) { ctr->ok = 0; return; }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  ctr->pb = p;\n  ctr->needsp = 0;\n}\n\n/* Append char. */\nstatic void ctype_appc(CTRepr *ctr, int c)\n{\n  if (ctr->pe >= ctr->buf + CTREPR_MAX) { ctr->ok = 0; return; }\n  *ctr->pe++ = c;\n}\n\n/* Append number. */\nstatic void ctype_appnum(CTRepr *ctr, uint32_t n)\n{\n  char buf[10];\n  char *p = buf+sizeof(buf);\n  char *q = ctr->pe;\n  if (q > ctr->buf + CTREPR_MAX - 10) { ctr->ok = 0; return; }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  do { *q++ = *p++; } while (p < buf+sizeof(buf));\n  ctr->pe = q;\n}\n\n/* Prepend qualifiers. */\nstatic void ctype_prepqual(CTRepr *ctr, CTInfo info)\n{\n  if ((info & CTF_VOLATILE)) ctype_preplit(ctr, \"volatile\");\n  if ((info & CTF_CONST)) ctype_preplit(ctr, \"const\");\n}\n\n/* Prepend named type. */\nstatic void ctype_preptype(CTRepr *ctr, CType *ct, CTInfo qual, const char *t)\n{\n  if (gcref(ct->name)) {\n    GCstr *str = gco2str(gcref(ct->name));\n    ctype_prepstr(ctr, strdata(str), str->len);\n  } else {\n    if (ctr->needsp) ctype_prepc(ctr, ' ');\n    ctype_prepnum(ctr, ctype_typeid(ctr->cts, ct));\n    ctr->needsp = 1;\n  }\n  ctype_prepstr(ctr, t, (MSize)strlen(t));\n  ctype_prepqual(ctr, qual);\n}\n\nstatic void ctype_repr(CTRepr *ctr, CTypeID id)\n{\n  CType *ct = ctype_get(ctr->cts, id);\n  CTInfo qual = 0;\n  int ptrto = 0;\n  for (;;) {\n    CTInfo info = ct->info;\n    CTSize size = ct->size;\n    switch (ctype_type(info)) {\n    case CT_NUM:\n      if ((info & CTF_BOOL)) {\n\tctype_preplit(ctr, \"bool\");\n      } else if ((info & CTF_FP)) {\n\tif (size == sizeof(double)) ctype_preplit(ctr, \"double\");\n\telse if (size == sizeof(float)) ctype_preplit(ctr, \"float\");\n\telse ctype_preplit(ctr, \"long double\");\n      } else if (size == 1) {\n\tif (!((info ^ CTF_UCHAR) & CTF_UNSIGNED)) ctype_preplit(ctr, \"char\");\n\telse if (CTF_UCHAR) ctype_preplit(ctr, \"signed char\");\n\telse ctype_preplit(ctr, \"unsigned char\");\n      } else if (size < 8) {\n\tif (size == 4) ctype_preplit(ctr, \"int\");\n\telse ctype_preplit(ctr, \"short\");\n\tif ((info & CTF_UNSIGNED)) ctype_preplit(ctr, \"unsigned\");\n      } else {\n\tctype_preplit(ctr, \"_t\");\n\tctype_prepnum(ctr, size*8);\n\tctype_preplit(ctr, \"int\");\n\tif ((info & CTF_UNSIGNED)) ctype_prepc(ctr, 'u');\n      }\n      ctype_prepqual(ctr, (qual|info));\n      return;\n    case CT_VOID:\n      ctype_preplit(ctr, \"void\");\n      ctype_prepqual(ctr, (qual|info));\n      return;\n    case CT_STRUCT:\n      ctype_preptype(ctr, ct, qual, (info & CTF_UNION) ? \"union\" : \"struct\");\n      return;\n    case CT_ENUM:\n      if (id == CTID_CTYPEID) {\n\tctype_preplit(ctr, \"ctype\");\n\treturn;\n      }\n      ctype_preptype(ctr, ct, qual, \"enum\");\n      return;\n    case CT_ATTRIB:\n      if (ctype_attrib(info) == CTA_QUAL) qual |= size;\n      break;\n    case CT_PTR:\n      if ((info & CTF_REF)) {\n\tctype_prepc(ctr, '&');\n      } else {\n\tctype_prepqual(ctr, (qual|info));\n\tif (LJ_64 && size == 4) ctype_preplit(ctr, \"__ptr32\");\n\tctype_prepc(ctr, '*');\n      }\n      qual = 0;\n      ptrto = 1;\n      ctr->needsp = 1;\n      break;\n    case CT_ARRAY:\n      if (ctype_isrefarray(info)) {\n\tctr->needsp = 1;\n\tif (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }\n\tctype_appc(ctr, '[');\n\tif (size != CTSIZE_INVALID) {\n\t  CTSize csize = ctype_child(ctr->cts, ct)->size;\n\t  ctype_appnum(ctr, csize ? size/csize : 0);\n\t} else if ((info & CTF_VLA)) {\n\t  ctype_appc(ctr, '?');\n\t}\n\tctype_appc(ctr, ']');\n      } else if ((info & CTF_COMPLEX)) {\n\tif (size == 2*sizeof(float)) ctype_preplit(ctr, \"float\");\n\tctype_preplit(ctr, \"complex\");\n\treturn;\n      } else {\n\tctype_preplit(ctr, \")))\");\n\tctype_prepnum(ctr, size);\n\tctype_preplit(ctr, \"__attribute__((vector_size(\");\n      }\n      break;\n    case CT_FUNC:\n      ctr->needsp = 1;\n      if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }\n      ctype_appc(ctr, '(');\n      ctype_appc(ctr, ')');\n      break;\n    default:\n      lua_assert(0);\n      break;\n    }\n    ct = ctype_get(ctr->cts, ctype_cid(info));\n  }\n}\n\n/* Return a printable representation of a C type. */\nGCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name)\n{\n  global_State *g = G(L);\n  CTRepr ctr;\n  ctr.pb = ctr.pe = &ctr.buf[CTREPR_MAX/2];\n  ctr.cts = ctype_ctsG(g);\n  ctr.L = L;\n  ctr.ok = 1;\n  ctr.needsp = 0;\n  if (name) ctype_prepstr(&ctr, strdata(name), name->len);\n  ctype_repr(&ctr, id);\n  if (LJ_UNLIKELY(!ctr.ok)) return lj_str_newlit(L, \"?\");\n  return lj_str_new(L, ctr.pb, ctr.pe - ctr.pb);\n}\n\n/* Convert int64_t/uint64_t to string with 'LL' or 'ULL' suffix. */\nGCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned)\n{\n  char buf[1+20+3];\n  char *p = buf+sizeof(buf);\n  int sign = 0;\n  *--p = 'L'; *--p = 'L';\n  if (isunsigned) {\n    *--p = 'U';\n  } else if ((int64_t)n < 0) {\n    n = (uint64_t)-(int64_t)n;\n    sign = 1;\n  }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  if (sign) *--p = '-';\n  return lj_str_new(L, p, (size_t)(buf+sizeof(buf)-p));\n}\n\n/* Convert complex to string with 'i' or 'I' suffix. */\nGCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size)\n{\n  SBuf *sb = lj_buf_tmp_(L);\n  TValue re, im;\n  if (size == 2*sizeof(double)) {\n    re.n = *(double *)sp; im.n = ((double *)sp)[1];\n  } else {\n    re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1];\n  }\n  lj_strfmt_putfnum(sb, STRFMT_G14, re.n);\n  if (!(im.u32.hi & 0x80000000u) || im.n != im.n) lj_buf_putchar(sb, '+');\n  lj_strfmt_putfnum(sb, STRFMT_G14, im.n);\n  lj_buf_putchar(sb, sbufP(sb)[-1] >= 'a' ? 'I' : 'i');\n  return lj_buf_str(L, sb);\n}\n\n/* -- C type state -------------------------------------------------------- */\n\n/* Initialize C type table and state. */\nCTState *lj_ctype_init(lua_State *L)\n{\n  CTState *cts = lj_mem_newt(L, sizeof(CTState), CTState);\n  CType *ct = lj_mem_newvec(L, CTTYPETAB_MIN, CType);\n  const char *name = lj_ctype_typenames;\n  CTypeID id;\n  memset(cts, 0, sizeof(CTState));\n  cts->tab = ct;\n  cts->sizetab = CTTYPETAB_MIN;\n  cts->top = CTTYPEINFO_NUM;\n  cts->L = NULL;\n  cts->g = G(L);\n  for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) {\n    CTInfo info = lj_ctype_typeinfo[id];\n    ct->size = (CTSize)((int32_t)(info << 16) >> 26);\n    ct->info = info & 0xffff03ffu;\n    ct->sib = 0;\n    if (ctype_type(info) == CT_KW || ctype_istypedef(info)) {\n      size_t len = strlen(name);\n      GCstr *str = lj_str_new(L, name, len);\n      ctype_setname(ct, str);\n      name += len+1;\n      lj_ctype_addname(cts, ct, id);\n    } else {\n      setgcrefnull(ct->name);\n      ct->next = 0;\n      if (!ctype_isenum(info)) ctype_addtype(cts, ct, id);\n    }\n  }\n  setmref(G(L)->ctype_state, cts);\n  return cts;\n}\n\n/* Free C type table and state. */\nvoid lj_ctype_freestate(global_State *g)\n{\n  CTState *cts = ctype_ctsG(g);\n  if (cts) {\n    lj_ccallback_mcode_free(cts);\n    lj_mem_freevec(g, cts->tab, cts->sizetab, CType);\n    lj_mem_freevec(g, cts->cb.cbid, cts->cb.sizeid, CTypeID1);\n    lj_mem_freet(g, cts);\n  }\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ctype.h",
    "content": "/*\n** C type management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CTYPE_H\n#define _LJ_CTYPE_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n\n#if LJ_HASFFI\n\n/* -- C type definitions -------------------------------------------------- */\n\n/* C type numbers. Highest 4 bits of C type info. ORDER CT. */\nenum {\n  /* Externally visible types. */\n  CT_NUM,\t\t/* Integer or floating-point numbers. */\n  CT_STRUCT,\t\t/* Struct or union. */\n  CT_PTR,\t\t/* Pointer or reference. */\n  CT_ARRAY,\t\t/* Array or complex type. */\n  CT_MAYCONVERT = CT_ARRAY,\n  CT_VOID,\t\t/* Void type. */\n  CT_ENUM,\t\t/* Enumeration. */\n  CT_HASSIZE = CT_ENUM,  /* Last type where ct->size holds the actual size. */\n  CT_FUNC,\t\t/* Function. */\n  CT_TYPEDEF,\t\t/* Typedef. */\n  CT_ATTRIB,\t\t/* Miscellaneous attributes. */\n  /* Internal element types. */\n  CT_FIELD,\t\t/* Struct/union field or function parameter. */\n  CT_BITFIELD,\t\t/* Struct/union bitfield. */\n  CT_CONSTVAL,\t\t/* Constant value. */\n  CT_EXTERN,\t\t/* External reference. */\n  CT_KW\t\t\t/* Keyword. */\n};\n\nLJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR);\nLJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT);\n\n/*\n**  ---------- info ------------\n** |type      flags...  A   cid | size   |  sib  | next  | name  |\n** +----------------------------+--------+-------+-------+-------+--\n** |NUM       BFvcUL..  A       | size   |       | type  |       |\n** |STRUCT    ..vcU..V  A       | size   | field | name? | name? |\n** |PTR       ..vcR...  A   cid | size   |       | type  |       |\n** |ARRAY     VCvc...V  A   cid | size   |       | type  |       |\n** |VOID      ..vc....  A       | size   |       | type  |       |\n** |ENUM                A   cid | size   | const | name? | name? |\n** |FUNC      ....VS.. cc   cid | nargs  | field | name? | name? |\n** |TYPEDEF                 cid |        |       | name  | name  |\n** |ATTRIB        attrnum   cid | attr   | sib?  | type? |       |\n** |FIELD                   cid | offset | field |       | name? |\n** |BITFIELD  B.vcU csz bsz pos | offset | field |       | name? |\n** |CONSTVAL     c          cid | value  | const | name  | name  |\n** |EXTERN                  cid |        | sib?  | name  | name  |\n** |KW                      tok | size   |       | name  | name  |\n** +----------------------------+--------+-------+-------+-------+--\n**        ^^  ^^--- bits used for C type conversion dispatch\n*/\n\n/* C type info flags.     TFFArrrr  */\n#define CTF_BOOL\t0x08000000u\t/* Boolean: NUM, BITFIELD. */\n#define CTF_FP\t\t0x04000000u\t/* Floating-point: NUM. */\n#define CTF_CONST\t0x02000000u\t/* Const qualifier. */\n#define CTF_VOLATILE\t0x01000000u\t/* Volatile qualifier. */\n#define CTF_UNSIGNED\t0x00800000u\t/* Unsigned: NUM, BITFIELD. */\n#define CTF_LONG\t0x00400000u\t/* Long: NUM. */\n#define CTF_VLA\t\t0x00100000u\t/* Variable-length: ARRAY, STRUCT. */\n#define CTF_REF\t\t0x00800000u\t/* Reference: PTR. */\n#define CTF_VECTOR\t0x08000000u\t/* Vector: ARRAY. */\n#define CTF_COMPLEX\t0x04000000u\t/* Complex: ARRAY. */\n#define CTF_UNION\t0x00800000u\t/* Union: STRUCT. */\n#define CTF_VARARG\t0x00800000u\t/* Vararg: FUNC. */\n#define CTF_SSEREGPARM\t0x00400000u\t/* SSE register parameters: FUNC. */\n\n#define CTF_QUAL\t(CTF_CONST|CTF_VOLATILE)\n#define CTF_ALIGN\t(CTMASK_ALIGN<<CTSHIFT_ALIGN)\n#define CTF_UCHAR\t((char)-1 > 0 ? CTF_UNSIGNED : 0)\n\n/* Flags used in parser.  .F.Ammvf   cp->attr  */\n#define CTFP_ALIGNED\t0x00000001u\t/* cp->attr + ALIGN */\n#define CTFP_PACKED\t0x00000002u\t/* cp->attr */\n/*                        ...C...f   cp->fattr */\n#define CTFP_CCONV\t0x00000001u\t/* cp->fattr + CCONV/[SSE]REGPARM */\n\n/* C type info bitfields. */\n#define CTMASK_CID\t0x0000ffffu\t/* Max. 65536 type IDs. */\n#define CTMASK_NUM\t0xf0000000u\t/* Max. 16 type numbers. */\n#define CTSHIFT_NUM\t28\n#define CTMASK_ALIGN\t15\t\t/* Max. alignment is 2^15. */\n#define CTSHIFT_ALIGN\t16\n#define CTMASK_ATTRIB\t255\t\t/* Max. 256 attributes. */\n#define CTSHIFT_ATTRIB\t16\n#define CTMASK_CCONV\t3\t\t/* Max. 4 calling conventions. */\n#define CTSHIFT_CCONV\t16\n#define CTMASK_REGPARM\t3\t\t/* Max. 0-3 regparms. */\n#define CTSHIFT_REGPARM\t18\n/* Bitfields only used in parser. */\n#define CTMASK_VSIZEP\t15\t\t/* Max. vector size is 2^15. */\n#define CTSHIFT_VSIZEP\t4\n#define CTMASK_MSIZEP\t255\t\t/* Max. type size (via mode) is 128. */\n#define CTSHIFT_MSIZEP\t8\n\n/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */\n#define CTBSZ_MAX\t32\t\t/* Max. size of bitfield is 32 bit. */\n#define CTBSZ_FIELD\t127\t\t/* Temp. marker for regular field. */\n#define CTMASK_BITPOS\t127\n#define CTMASK_BITBSZ\t127\n#define CTMASK_BITCSZ\t127\n#define CTSHIFT_BITPOS\t0\n#define CTSHIFT_BITBSZ\t8\n#define CTSHIFT_BITCSZ\t16\n\n#define CTF_INSERT(info, field, val) \\\n  info = (info & ~(CTMASK_##field<<CTSHIFT_##field)) | \\\n\t  (((CTSize)(val) & CTMASK_##field) << CTSHIFT_##field)\n\n/* Calling conventions. ORDER CC */\nenum { CTCC_CDECL, CTCC_THISCALL, CTCC_FASTCALL, CTCC_STDCALL };\n\n/* Attribute numbers. */\nenum {\n  CTA_NONE,\t\t/* Ignored attribute. Must be zero. */\n  CTA_QUAL,\t\t/* Unmerged qualifiers. */\n  CTA_ALIGN,\t\t/* Alignment override. */\n  CTA_SUBTYPE,\t\t/* Transparent sub-type. */\n  CTA_REDIR,\t\t/* Redirected symbol name. */\n  CTA_BAD,\t\t/* To catch bad IDs. */\n  CTA__MAX\n};\n\n/* Special sizes. */\n#define CTSIZE_INVALID\t0xffffffffu\n\ntypedef uint32_t CTInfo;\t/* Type info. */\ntypedef uint32_t CTSize;\t/* Type size. */\ntypedef uint32_t CTypeID;\t/* Type ID. */\ntypedef uint16_t CTypeID1;\t/* Minimum-sized type ID. */\n\n/* C type table element. */\ntypedef struct CType {\n  CTInfo info;\t\t/* Type info. */\n  CTSize size;\t\t/* Type size or other info. */\n  CTypeID1 sib;\t\t/* Sibling element. */\n  CTypeID1 next;\t/* Next element in hash chain. */\n  GCRef name;\t\t/* Element name (GCstr). */\n} CType;\n\n#define CTHASH_SIZE\t128\t/* Number of hash anchors. */\n#define CTHASH_MASK\t(CTHASH_SIZE-1)\n\n/* Simplify target-specific configuration. Checked in lj_ccall.h. */\n#define CCALL_MAX_GPR\t\t8\n#define CCALL_MAX_FPR\t\t8\n\ntypedef LJ_ALIGN(8) union FPRCBArg { double d; float f[2]; } FPRCBArg;\n\n/* C callback state. Defined here, to avoid dragging in lj_ccall.h. */\n\ntypedef LJ_ALIGN(8) struct CCallback {\n  FPRCBArg fpr[CCALL_MAX_FPR];\t/* Arguments/results in FPRs. */\n  intptr_t gpr[CCALL_MAX_GPR];\t/* Arguments/results in GPRs. */\n  intptr_t *stack;\t\t/* Pointer to arguments on stack. */\n  void *mcode;\t\t\t/* Machine code for callback func. pointers. */\n  CTypeID1 *cbid;\t\t/* Callback type table. */\n  MSize sizeid;\t\t\t/* Size of callback type table. */\n  MSize topid;\t\t\t/* Highest unused callback type table slot. */\n  MSize slot;\t\t\t/* Current callback slot. */\n} CCallback;\n\n/* C type state. */\ntypedef struct CTState {\n  CType *tab;\t\t/* C type table. */\n  CTypeID top;\t\t/* Current top of C type table. */\n  MSize sizetab;\t/* Size of C type table. */\n  lua_State *L;\t\t/* Lua state (needed for errors and allocations). */\n  global_State *g;\t/* Global state. */\n  GCtab *finalizer;\t/* Map of cdata to finalizer. */\n  GCtab *miscmap;\t/* Map of -CTypeID to metatable and cb slot to func. */\n  CCallback cb;\t\t/* Temporary callback state. */\n  CTypeID1 hash[CTHASH_SIZE];  /* Hash anchors for C type table. */\n} CTState;\n\n#define CTINFO(ct, flags)\t(((CTInfo)(ct) << CTSHIFT_NUM) + (flags))\n#define CTALIGN(al)\t\t((CTSize)(al) << CTSHIFT_ALIGN)\n#define CTATTRIB(at)\t\t((CTInfo)(at) << CTSHIFT_ATTRIB)\n\n#define ctype_type(info)\t((info) >> CTSHIFT_NUM)\n#define ctype_cid(info)\t\t((CTypeID)((info) & CTMASK_CID))\n#define ctype_align(info)\t(((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN)\n#define ctype_attrib(info)\t(((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB)\n#define ctype_bitpos(info)\t(((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS)\n#define ctype_bitbsz(info)\t(((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ)\n#define ctype_bitcsz(info)\t(((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ)\n#define ctype_vsizeP(info)\t(((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP)\n#define ctype_msizeP(info)\t(((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP)\n#define ctype_cconv(info)\t(((info) >> CTSHIFT_CCONV) & CTMASK_CCONV)\n\n/* Simple type checks. */\n#define ctype_isnum(info)\t(ctype_type((info)) == CT_NUM)\n#define ctype_isvoid(info)\t(ctype_type((info)) == CT_VOID)\n#define ctype_isptr(info)\t(ctype_type((info)) == CT_PTR)\n#define ctype_isarray(info)\t(ctype_type((info)) == CT_ARRAY)\n#define ctype_isstruct(info)\t(ctype_type((info)) == CT_STRUCT)\n#define ctype_isfunc(info)\t(ctype_type((info)) == CT_FUNC)\n#define ctype_isenum(info)\t(ctype_type((info)) == CT_ENUM)\n#define ctype_istypedef(info)\t(ctype_type((info)) == CT_TYPEDEF)\n#define ctype_isattrib(info)\t(ctype_type((info)) == CT_ATTRIB)\n#define ctype_isfield(info)\t(ctype_type((info)) == CT_FIELD)\n#define ctype_isbitfield(info)\t(ctype_type((info)) == CT_BITFIELD)\n#define ctype_isconstval(info)\t(ctype_type((info)) == CT_CONSTVAL)\n#define ctype_isextern(info)\t(ctype_type((info)) == CT_EXTERN)\n#define ctype_hassize(info)\t(ctype_type((info)) <= CT_HASSIZE)\n\n/* Combined type and flag checks. */\n#define ctype_isinteger(info) \\\n  (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0))\n#define ctype_isinteger_or_bool(info) \\\n  (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0))\n#define ctype_isbool(info) \\\n  (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL))\n#define ctype_isfp(info) \\\n  (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP))\n\n#define ctype_ispointer(info) \\\n  ((ctype_type(info) >> 1) == (CT_PTR >> 1))  /* Pointer or array. */\n#define ctype_isref(info) \\\n  (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF))\n\n#define ctype_isrefarray(info) \\\n  (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0))\n#define ctype_isvector(info) \\\n  (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR))\n#define ctype_iscomplex(info) \\\n  (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX))\n\n#define ctype_isvltype(info) \\\n  (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<<CTSHIFT_NUM))) == \\\n   CTINFO(CT_STRUCT, CTF_VLA))  /* VL array or VL struct. */\n#define ctype_isvlarray(info) \\\n  (((info) & (CTMASK_NUM|CTF_VLA)) == CTINFO(CT_ARRAY, CTF_VLA))\n\n#define ctype_isxattrib(info, at) \\\n  (((info) & (CTMASK_NUM|CTATTRIB(CTMASK_ATTRIB))) == \\\n   CTINFO(CT_ATTRIB, CTATTRIB(at)))\n\n/* Target-dependent sizes and alignments. */\n#if LJ_64\n#define CTSIZE_PTR\t8\n#define CTALIGN_PTR\tCTALIGN(3)\n#else\n#define CTSIZE_PTR\t4\n#define CTALIGN_PTR\tCTALIGN(2)\n#endif\n\n#define CTINFO_REF(ref) \\\n  CTINFO(CT_PTR, (CTF_CONST|CTF_REF|CTALIGN_PTR) + (ref))\n\n#define CT_MEMALIGN\t3\t/* Alignment guaranteed by memory allocator. */\n\n/* -- Predefined types ---------------------------------------------------- */\n\n/* Target-dependent types. */\n#if LJ_TARGET_PPC\n#define CTTYDEFP(_) \\\n  _(LINT32,\t\t4,\tCT_NUM, CTF_LONG|CTALIGN(2))\n#else\n#define CTTYDEFP(_)\n#endif\n\n/* Common types. */\n#define CTTYDEF(_) \\\n  _(NONE,\t\t0,\tCT_ATTRIB, CTATTRIB(CTA_BAD)) \\\n  _(VOID,\t\t-1,\tCT_VOID, CTALIGN(0)) \\\n  _(CVOID,\t\t-1,\tCT_VOID, CTF_CONST|CTALIGN(0)) \\\n  _(BOOL,\t\t1,\tCT_NUM, CTF_BOOL|CTF_UNSIGNED|CTALIGN(0)) \\\n  _(CCHAR,\t\t1,\tCT_NUM, CTF_CONST|CTF_UCHAR|CTALIGN(0)) \\\n  _(INT8,\t\t1,\tCT_NUM, CTALIGN(0)) \\\n  _(UINT8,\t\t1,\tCT_NUM, CTF_UNSIGNED|CTALIGN(0)) \\\n  _(INT16,\t\t2,\tCT_NUM, CTALIGN(1)) \\\n  _(UINT16,\t\t2,\tCT_NUM, CTF_UNSIGNED|CTALIGN(1)) \\\n  _(INT32,\t\t4,\tCT_NUM, CTALIGN(2)) \\\n  _(UINT32,\t\t4,\tCT_NUM, CTF_UNSIGNED|CTALIGN(2)) \\\n  _(INT64,\t\t8,\tCT_NUM, CTF_LONG|CTALIGN(3)) \\\n  _(UINT64,\t\t8,\tCT_NUM, CTF_UNSIGNED|CTF_LONG|CTALIGN(3)) \\\n  _(FLOAT,\t\t4,\tCT_NUM, CTF_FP|CTALIGN(2)) \\\n  _(DOUBLE,\t\t8,\tCT_NUM, CTF_FP|CTALIGN(3)) \\\n  _(COMPLEX_FLOAT,\t8,\tCT_ARRAY, CTF_COMPLEX|CTALIGN(2)|CTID_FLOAT) \\\n  _(COMPLEX_DOUBLE,\t16,\tCT_ARRAY, CTF_COMPLEX|CTALIGN(3)|CTID_DOUBLE) \\\n  _(P_VOID,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_VOID) \\\n  _(P_CVOID,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_CVOID) \\\n  _(P_CCHAR,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_CCHAR) \\\n  _(A_CCHAR,\t\t-1,\tCT_ARRAY, CTF_CONST|CTALIGN(0)|CTID_CCHAR) \\\n  _(CTYPEID,\t\t4,\tCT_ENUM, CTALIGN(2)|CTID_INT32) \\\n  CTTYDEFP(_) \\\n  /* End of type list. */\n\n/* Public predefined type IDs. */\nenum {\n#define CTTYIDDEF(id, sz, ct, info)\tCTID_##id,\nCTTYDEF(CTTYIDDEF)\n#undef CTTYIDDEF\n  /* Predefined typedefs and keywords follow. */\n  CTID_MAX = 65536\n};\n\n/* Target-dependent type IDs. */\n#if LJ_64\n#define CTID_INT_PSZ\tCTID_INT64\n#define CTID_UINT_PSZ\tCTID_UINT64\n#else\n#define CTID_INT_PSZ\tCTID_INT32\n#define CTID_UINT_PSZ\tCTID_UINT32\n#endif\n\n#if LJ_ABI_WIN\n#define CTID_WCHAR\tCTID_UINT16\n#elif LJ_TARGET_PPC\n#define CTID_WCHAR\tCTID_LINT32\n#else\n#define CTID_WCHAR\tCTID_INT32\n#endif\n\n/* -- C tokens and keywords ----------------------------------------------- */\n\n/* C lexer keywords. */\n#define CTOKDEF(_) \\\n  _(IDENT, \"<identifier>\") _(STRING, \"<string>\") \\\n  _(INTEGER, \"<integer>\") _(EOF, \"<eof>\") \\\n  _(OROR, \"||\") _(ANDAND, \"&&\") _(EQ, \"==\") _(NE, \"!=\") \\\n  _(LE, \"<=\") _(GE, \">=\") _(SHL, \"<<\") _(SHR, \">>\") _(DEREF, \"->\")\n\n/* Simple declaration specifiers. */\n#define CDSDEF(_) \\\n  _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \\\n  _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \\\n  _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \\\n  _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER)\n\n/* C keywords. */\n#define CKWDEF(_) \\\n  CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \\\n  _(DECLSPEC) _(CCDECL) _(PTRSZ) \\\n  _(STRUCT) _(UNION) _(ENUM) \\\n  _(SIZEOF) _(ALIGNOF)\n\n/* C token numbers. */\nenum {\n  CTOK_OFS = 255,\n#define CTOKNUM(name, sym)\tCTOK_##name,\n#define CKWNUM(name)\t\tCTOK_##name,\nCTOKDEF(CTOKNUM)\nCKWDEF(CKWNUM)\n#undef CTOKNUM\n#undef CKWNUM\n  CTOK_FIRSTDECL = CTOK_VOID,\n  CTOK_FIRSTSCL = CTOK_TYPEDEF,\n  CTOK_LASTDECLFLAG = CTOK_REGISTER,\n  CTOK_LASTDECL = CTOK_ENUM\n};\n\n/* Declaration specifier flags. */\nenum {\n#define CDSFLAG(name)\tCDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)),\nCDSDEF(CDSFLAG)\n#undef CDSFLAG\n  CDF__END\n};\n\n#define CDF_SCL  (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER)\n\n/* -- C type management --------------------------------------------------- */\n\n#define ctype_ctsG(g)\t\t(mref((g)->ctype_state, CTState))\n\n/* Get C type state. */\nstatic LJ_AINLINE CTState *ctype_cts(lua_State *L)\n{\n  CTState *cts = ctype_ctsG(G(L));\n  cts->L = L;  /* Save L for errors and allocations. */\n  return cts;\n}\n\n/* Save and restore state of C type table. */\n#define LJ_CTYPE_SAVE(cts)\tCTState savects_ = *(cts)\n#define LJ_CTYPE_RESTORE(cts) \\\n  ((cts)->top = savects_.top, \\\n   memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash)))\n\n/* Check C type ID for validity when assertions are enabled. */\nstatic LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id)\n{\n  lua_assert(id > 0 && id < cts->top); UNUSED(cts);\n  return id;\n}\n\n/* Get C type for C type ID. */\nstatic LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id)\n{\n  return &cts->tab[ctype_check(cts, id)];\n}\n\n/* Get C type ID for a C type. */\n#define ctype_typeid(cts, ct)\t((CTypeID)((ct) - (cts)->tab))\n\n/* Get child C type. */\nstatic LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct)\n{\n  lua_assert(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) ||\n\t     ctype_isbitfield(ct->info)));  /* These don't have children. */\n  return ctype_get(cts, ctype_cid(ct->info));\n}\n\n/* Get raw type for a C type ID. */\nstatic LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_get(cts, id);\n  while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct);\n  return ct;\n}\n\n/* Get raw type of the child of a C type. */\nstatic LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct)\n{\n  do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info));\n  return ct;\n}\n\n/* Set the name of a C type table element. */\nstatic LJ_AINLINE void ctype_setname(CType *ct, GCstr *s)\n{\n  /* NOBARRIER: mark string as fixed -- the C type table is never collected. */\n  fixstring(s);\n  setgcref(ct->name, obj2gco(s));\n}\n\nLJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp);\nLJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size);\nLJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id);\nLJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name,\n\t\t\t\t uint32_t tmask);\nLJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name,\n\t\t\t\t  CTSize *ofs, CTInfo *qual);\n#define lj_ctype_getfield(cts, ct, name, ofs) \\\n  lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL)\nLJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);\nLJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);\nLJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);\nLJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);\nLJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);\nLJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);\nLJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);\nLJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size);\nLJ_FUNC CTState *lj_ctype_init(lua_State *L);\nLJ_FUNC void lj_ctype_freestate(global_State *g);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_debug.c",
    "content": "/*\n** Debugging and introspection.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_debug_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_buf.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n\n/* -- Frames -------------------------------------------------------------- */\n\n/* Get frame corresponding to a level. */\ncTValue *lj_debug_frame(lua_State *L, int level, int *size)\n{\n  cTValue *frame, *nextframe, *bot = tvref(L->stack)+LJ_FR2;\n  /* Traverse frames backwards. */\n  for (nextframe = frame = L->base-1; frame > bot; ) {\n    if (frame_gc(frame) == obj2gco(L))\n      level++;  /* Skip dummy frames. See lj_err_optype_call(). */\n    if (level-- == 0) {\n      *size = (int)(nextframe - frame);\n      return frame;  /* Level found. */\n    }\n    nextframe = frame;\n    if (frame_islua(frame)) {\n      frame = frame_prevl(frame);\n    } else {\n      if (frame_isvarg(frame))\n\tlevel++;  /* Skip vararg pseudo-frame. */\n      frame = frame_prevd(frame);\n    }\n  }\n  *size = level;\n  return NULL;  /* Level not found. */\n}\n\n/* Invalid bytecode position. */\n#define NO_BCPOS\t(~(BCPos)0)\n\n/* Return bytecode position for function/frame or NO_BCPOS. */\nstatic BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)\n{\n  const BCIns *ins;\n  GCproto *pt;\n  BCPos pos;\n  lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD);\n  if (!isluafunc(fn)) {  /* Cannot derive a PC for non-Lua functions. */\n    return NO_BCPOS;\n  } else if (nextframe == NULL) {  /* Lua function on top. */\n    void *cf = cframe_raw(L->cframe);\n    if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf))\n      return NO_BCPOS;\n    ins = cframe_pc(cf);  /* Only happens during error/hook handling. */\n  } else {\n    if (frame_islua(nextframe)) {\n      ins = frame_pc(nextframe);\n    } else if (frame_iscont(nextframe)) {\n      ins = frame_contpc(nextframe);\n    } else {\n      /* Lua function below errfunc/gc/hook: find cframe to get the PC. */\n      void *cf = cframe_raw(L->cframe);\n      TValue *f = L->base-1;\n      for (;;) {\n\tif (cf == NULL)\n\t  return NO_BCPOS;\n\twhile (cframe_nres(cf) < 0) {\n\t  if (f >= restorestack(L, -cframe_nres(cf)))\n\t    break;\n\t  cf = cframe_raw(cframe_prev(cf));\n\t  if (cf == NULL)\n\t    return NO_BCPOS;\n\t}\n\tif (f < nextframe)\n\t  break;\n\tif (frame_islua(f)) {\n\t  f = frame_prevl(f);\n\t} else {\n\t  if (frame_isc(f) || (frame_iscont(f) && frame_iscont_fficb(f)))\n\t    cf = cframe_raw(cframe_prev(cf));\n\t  f = frame_prevd(f);\n\t}\n      }\n      ins = cframe_pc(cf);\n    }\n  }\n  pt = funcproto(fn);\n  pos = proto_bcpos(pt, ins) - 1;\n#if LJ_HASJIT\n  if (pos > pt->sizebc) {  /* Undo the effects of lj_trace_exit for JLOOP. */\n    GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins));\n    lua_assert(bc_isret(bc_op(ins[-1])));\n    pos = proto_bcpos(pt, mref(T->startpc, const BCIns));\n  }\n#endif\n  return pos;\n}\n\n/* -- Line numbers -------------------------------------------------------- */\n\n/* Get line number for a bytecode position. */\nBCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc)\n{\n  const void *lineinfo = proto_lineinfo(pt);\n  if (pc <= pt->sizebc && lineinfo) {\n    BCLine first = pt->firstline;\n    if (pc == pt->sizebc) return first + pt->numline;\n    if (pc-- == 0) return first;\n    if (pt->numline < 256)\n      return first + (BCLine)((const uint8_t *)lineinfo)[pc];\n    else if (pt->numline < 65536)\n      return first + (BCLine)((const uint16_t *)lineinfo)[pc];\n    else\n      return first + (BCLine)((const uint32_t *)lineinfo)[pc];\n  }\n  return 0;\n}\n\n/* Get line number for function/frame. */\nstatic BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe)\n{\n  BCPos pc = debug_framepc(L, fn, nextframe);\n  if (pc != NO_BCPOS) {\n    GCproto *pt = funcproto(fn);\n    lua_assert(pc <= pt->sizebc);\n    return lj_debug_line(pt, pc);\n  }\n  return -1;\n}\n\n/* -- Variable names ------------------------------------------------------ */\n\n/* Get name of a local variable from slot number and PC. */\nstatic const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot)\n{\n  const char *p = (const char *)proto_varinfo(pt);\n  if (p) {\n    BCPos lastpc = 0;\n    for (;;) {\n      const char *name = p;\n      uint32_t vn = *(const uint8_t *)p;\n      BCPos startpc, endpc;\n      if (vn < VARNAME__MAX) {\n\tif (vn == VARNAME_END) break;  /* End of varinfo. */\n      } else {\n\tdo { p++; } while (*(const uint8_t *)p);  /* Skip over variable name. */\n      }\n      p++;\n      lastpc = startpc = lastpc + lj_buf_ruleb128(&p);\n      if (startpc > pc) break;\n      endpc = startpc + lj_buf_ruleb128(&p);\n      if (pc < endpc && slot-- == 0) {\n\tif (vn < VARNAME__MAX) {\n#define VARNAMESTR(name, str)\tstr \"\\0\"\n\t  name = VARNAMEDEF(VARNAMESTR);\n#undef VARNAMESTR\n\t  if (--vn) while (*name++ || --vn) ;\n\t}\n\treturn name;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Get name of local variable from 1-based slot number and function/frame. */\nstatic TValue *debug_localname(lua_State *L, const lua_Debug *ar,\n\t\t\t       const char **name, BCReg slot1)\n{\n  uint32_t offset = (uint32_t)ar->i_ci & 0xffff;\n  uint32_t size = (uint32_t)ar->i_ci >> 16;\n  TValue *frame = tvref(L->stack) + offset;\n  TValue *nextframe = size ? frame + size : NULL;\n  GCfunc *fn = frame_func(frame);\n  BCPos pc = debug_framepc(L, fn, nextframe);\n  if (!nextframe) nextframe = L->top+LJ_FR2;\n  if ((int)slot1 < 0) {  /* Negative slot number is for varargs. */\n    if (pc != NO_BCPOS) {\n      GCproto *pt = funcproto(fn);\n      if ((pt->flags & PROTO_VARARG)) {\n\tslot1 = pt->numparams + (BCReg)(-(int)slot1);\n\tif (frame_isvarg(frame)) {  /* Vararg frame has been set up? (pc!=0) */\n\t  nextframe = frame;\n\t  frame = frame_prevd(frame);\n\t}\n\tif (frame + slot1+LJ_FR2 < nextframe) {\n\t  *name = \"(*vararg)\";\n\t  return frame+slot1;\n\t}\n      }\n    }\n    return NULL;\n  }\n  if (pc != NO_BCPOS &&\n      (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL)\n    ;\n  else if (slot1 > 0 && frame + slot1+LJ_FR2 < nextframe)\n    *name = \"(*temporary)\";\n  return frame+slot1;\n}\n\n/* Get name of upvalue. */\nconst char *lj_debug_uvname(GCproto *pt, uint32_t idx)\n{\n  const uint8_t *p = proto_uvinfo(pt);\n  lua_assert(idx < pt->sizeuv);\n  if (!p) return \"\";\n  if (idx) while (*p++ || --idx) ;\n  return (const char *)p;\n}\n\n/* Get name and value of upvalue. */\nconst char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp)\n{\n  if (tvisfunc(o)) {\n    GCfunc *fn = funcV(o);\n    if (isluafunc(fn)) {\n      GCproto *pt = funcproto(fn);\n      if (idx < pt->sizeuv) {\n\t*tvp = uvval(&gcref(fn->l.uvptr[idx])->uv);\n\treturn lj_debug_uvname(pt, idx);\n      }\n    } else {\n      if (idx < fn->c.nupvalues) {\n\t*tvp = &fn->c.upvalue[idx];\n\treturn \"\";\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Deduce name of an object from slot number and PC. */\nconst char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot,\n\t\t\t      const char **name)\n{\n  const char *lname;\nrestart:\n  lname = debug_varname(pt, proto_bcpos(pt, ip), slot);\n  if (lname != NULL) { *name = lname; return \"local\"; }\n  while (--ip > proto_bc(pt)) {\n    BCIns ins = *ip;\n    BCOp op = bc_op(ins);\n    BCReg ra = bc_a(ins);\n    if (bcmode_a(op) == BCMbase) {\n      if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins)))\n\treturn NULL;\n    } else if (bcmode_a(op) == BCMdst && ra == slot) {\n      switch (bc_op(ins)) {\n      case BC_MOV:\n\tif (ra == slot) { slot = bc_d(ins); goto restart; }\n\tbreak;\n      case BC_GGET:\n\t*name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins))));\n\treturn \"global\";\n      case BC_TGETS:\n\t*name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins))));\n\tif (ip > proto_bc(pt)) {\n\t  BCIns insp = ip[-1];\n\t  if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1+LJ_FR2 &&\n\t      bc_d(insp) == bc_b(ins))\n\t    return \"method\";\n\t}\n\treturn \"field\";\n      case BC_UGET:\n\t*name = lj_debug_uvname(pt, bc_d(ins));\n\treturn \"upvalue\";\n      default:\n\treturn NULL;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Deduce function name from caller of a frame. */\nconst char *lj_debug_funcname(lua_State *L, cTValue *frame, const char **name)\n{\n  cTValue *pframe;\n  GCfunc *fn;\n  BCPos pc;\n  if (frame <= tvref(L->stack)+LJ_FR2)\n    return NULL;\n  if (frame_isvarg(frame))\n    frame = frame_prevd(frame);\n  pframe = frame_prev(frame);\n  fn = frame_func(pframe);\n  pc = debug_framepc(L, fn, frame);\n  if (pc != NO_BCPOS) {\n    GCproto *pt = funcproto(fn);\n    const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)];\n    MMS mm = bcmode_mm(bc_op(*ip));\n    if (mm == MM_call) {\n      BCReg slot = bc_a(*ip);\n      if (bc_op(*ip) == BC_ITERC) slot -= 3;\n      return lj_debug_slotname(pt, ip, slot, name);\n    } else if (mm != MM__MAX) {\n      *name = strdata(mmname_str(G(L), mm));\n      return \"metamethod\";\n    }\n  }\n  return NULL;\n}\n\n/* -- Source code locations ----------------------------------------------- */\n\n/* Generate shortened source name. */\nvoid lj_debug_shortname(char *out, GCstr *str, BCLine line)\n{\n  const char *src = strdata(str);\n  if (*src == '=') {\n    strncpy(out, src+1, LUA_IDSIZE);  /* Remove first char. */\n    out[LUA_IDSIZE-1] = '\\0';  /* Ensures null termination. */\n  } else if (*src == '@') {  /* Output \"source\", or \"...source\". */\n    size_t len = str->len-1;\n    src++;  /* Skip the `@' */\n    if (len >= LUA_IDSIZE) {\n      src += len-(LUA_IDSIZE-4);  /* Get last part of file name. */\n      *out++ = '.'; *out++ = '.'; *out++ = '.';\n    }\n    strcpy(out, src);\n  } else {  /* Output [string \"string\"] or [builtin:name]. */\n    size_t len;  /* Length, up to first control char. */\n    for (len = 0; len < LUA_IDSIZE-12; len++)\n      if (((const unsigned char *)src)[len] < ' ') break;\n    strcpy(out, line == ~(BCLine)0 ? \"[builtin:\" : \"[string \\\"\"); out += 9;\n    if (src[len] != '\\0') {  /* Must truncate? */\n      if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15;\n      strncpy(out, src, len); out += len;\n      strcpy(out, \"...\"); out += 3;\n    } else {\n      strcpy(out, src); out += len;\n    }\n    strcpy(out, line == ~(BCLine)0 ? \"]\" : \"\\\"]\");\n  }\n}\n\n/* Add current location of a frame to error message. */\nvoid lj_debug_addloc(lua_State *L, const char *msg,\n\t\t     cTValue *frame, cTValue *nextframe)\n{\n  if (frame) {\n    GCfunc *fn = frame_func(frame);\n    if (isluafunc(fn)) {\n      BCLine line = debug_frameline(L, fn, nextframe);\n      if (line >= 0) {\n\tGCproto *pt = funcproto(fn);\n\tchar buf[LUA_IDSIZE];\n\tlj_debug_shortname(buf, proto_chunkname(pt), pt->firstline);\n\tlj_strfmt_pushf(L, \"%s:%d: %s\", buf, line, msg);\n\treturn;\n      }\n    }\n  }\n  lj_strfmt_pushf(L, \"%s\", msg);\n}\n\n/* Push location string for a bytecode position to Lua stack. */\nvoid lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc)\n{\n  GCstr *name = proto_chunkname(pt);\n  const char *s = strdata(name);\n  MSize i, len = name->len;\n  BCLine line = lj_debug_line(pt, pc);\n  if (pt->firstline == ~(BCLine)0) {\n    lj_strfmt_pushf(L, \"builtin:%s\", s);\n  } else if (*s == '@') {\n    s++; len--;\n    for (i = len; i > 0; i--)\n      if (s[i] == '/' || s[i] == '\\\\') {\n\ts += i+1;\n\tbreak;\n      }\n    lj_strfmt_pushf(L, \"%s:%d\", s, line);\n  } else if (len > 40) {\n    lj_strfmt_pushf(L, \"%p:%d\", pt, line);\n  } else if (*s == '=') {\n    lj_strfmt_pushf(L, \"%s:%d\", s+1, line);\n  } else {\n    lj_strfmt_pushf(L, \"\\\"%s\\\":%d\", s, line);\n  }\n}\n\n/* -- Public debug API ---------------------------------------------------- */\n\n/* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */\n\nLUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)\n{\n  const char *name = NULL;\n  if (ar) {\n    TValue *o = debug_localname(L, ar, &name, (BCReg)n);\n    if (name) {\n      copyTV(L, L->top, o);\n      incr_top(L);\n    }\n  } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) {\n    name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1);\n  }\n  return name;\n}\n\nLUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n)\n{\n  const char *name = NULL;\n  TValue *o = debug_localname(L, ar, &name, (BCReg)n);\n  if (name)\n    copyTV(L, o, L->top-1);\n  L->top--;\n  return name;\n}\n\nint lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)\n{\n  int opt_f = 0, opt_L = 0;\n  TValue *frame = NULL;\n  TValue *nextframe = NULL;\n  GCfunc *fn;\n  if (*what == '>') {\n    TValue *func = L->top - 1;\n    api_check(L, tvisfunc(func));\n    fn = funcV(func);\n    L->top--;\n    what++;\n  } else {\n    uint32_t offset = (uint32_t)ar->i_ci & 0xffff;\n    uint32_t size = (uint32_t)ar->i_ci >> 16;\n    lua_assert(offset != 0);\n    frame = tvref(L->stack) + offset;\n    if (size) nextframe = frame + size;\n    lua_assert(frame <= tvref(L->maxstack) &&\n\t       (!nextframe || nextframe <= tvref(L->maxstack)));\n    fn = frame_func(frame);\n    lua_assert(fn->c.gct == ~LJ_TFUNC);\n  }\n  for (; *what; what++) {\n    if (*what == 'S') {\n      if (isluafunc(fn)) {\n\tGCproto *pt = funcproto(fn);\n\tBCLine firstline = pt->firstline;\n\tGCstr *name = proto_chunkname(pt);\n\tar->source = strdata(name);\n\tlj_debug_shortname(ar->short_src, name, pt->firstline);\n\tar->linedefined = (int)firstline;\n\tar->lastlinedefined = (int)(firstline + pt->numline);\n\tar->what = (firstline || !pt->numline) ? \"Lua\" : \"main\";\n      } else {\n\tar->source = \"=[C]\";\n\tar->short_src[0] = '[';\n\tar->short_src[1] = 'C';\n\tar->short_src[2] = ']';\n\tar->short_src[3] = '\\0';\n\tar->linedefined = -1;\n\tar->lastlinedefined = -1;\n\tar->what = \"C\";\n      }\n    } else if (*what == 'l') {\n      ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1;\n    } else if (*what == 'u') {\n      ar->nups = fn->c.nupvalues;\n      if (ext) {\n\tif (isluafunc(fn)) {\n\t  GCproto *pt = funcproto(fn);\n\t  ar->nparams = pt->numparams;\n\t  ar->isvararg = !!(pt->flags & PROTO_VARARG);\n\t} else {\n\t  ar->nparams = 0;\n\t  ar->isvararg = 1;\n\t}\n      }\n    } else if (*what == 'n') {\n      ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL;\n      if (ar->namewhat == NULL) {\n\tar->namewhat = \"\";\n\tar->name = NULL;\n      }\n    } else if (*what == 'f') {\n      opt_f = 1;\n    } else if (*what == 'L') {\n      opt_L = 1;\n    } else {\n      return 0;  /* Bad option. */\n    }\n  }\n  if (opt_f) {\n    setfuncV(L, L->top, fn);\n    incr_top(L);\n  }\n  if (opt_L) {\n    if (isluafunc(fn)) {\n      GCtab *t = lj_tab_new(L, 0, 0);\n      GCproto *pt = funcproto(fn);\n      const void *lineinfo = proto_lineinfo(pt);\n      if (lineinfo) {\n\tBCLine first = pt->firstline;\n\tint sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;\n\tMSize i, szl = pt->sizebc-1;\n\tfor (i = 0; i < szl; i++) {\n\t  BCLine line = first +\n\t    (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :\n\t     sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :\n\t     (BCLine)((const uint32_t *)lineinfo)[i]);\n\t  setboolV(lj_tab_setint(L, t, line), 1);\n\t}\n      }\n      settabV(L, L->top, t);\n    } else {\n      setnilV(L->top);\n    }\n    incr_top(L);\n  }\n  return 1;  /* Ok. */\n}\n\nLUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)\n{\n  return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0);\n}\n\nLUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)\n{\n  int size;\n  cTValue *frame = lj_debug_frame(L, level, &size);\n  if (frame) {\n    ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack));\n    return 1;\n  } else {\n    ar->i_ci = level - size;\n    return 0;\n  }\n}\n\n#if LJ_HASPROFILE\n/* Put the chunkname into a buffer. */\nstatic int debug_putchunkname(SBuf *sb, GCproto *pt, int pathstrip)\n{\n  GCstr *name = proto_chunkname(pt);\n  const char *p = strdata(name);\n  if (pt->firstline == ~(BCLine)0) {\n    lj_buf_putmem(sb, \"[builtin:\", 9);\n    lj_buf_putstr(sb, name);\n    lj_buf_putb(sb, ']');\n    return 0;\n  }\n  if (*p == '=' || *p == '@') {\n    MSize len = name->len-1;\n    p++;\n    if (pathstrip) {\n      int i;\n      for (i = len-1; i >= 0; i--)\n\tif (p[i] == '/' || p[i] == '\\\\') {\n\t  len -= i+1;\n\t  p = p+i+1;\n\t  break;\n\t}\n    }\n    lj_buf_putmem(sb, p, len);\n  } else {\n    lj_buf_putmem(sb, \"[string]\", 8);\n  }\n  return 1;\n}\n\n/* Put a compact stack dump into a buffer. */\nvoid lj_debug_dumpstack(lua_State *L, SBuf *sb, const char *fmt, int depth)\n{\n  int level = 0, dir = 1, pathstrip = 1;\n  MSize lastlen = 0;\n  if (depth < 0) { level = ~depth; depth = dir = -1; }  /* Reverse frames. */\n  while (level != depth) {  /* Loop through all frame. */\n    int size;\n    cTValue *frame = lj_debug_frame(L, level, &size);\n    if (frame) {\n      cTValue *nextframe = size ? frame+size : NULL;\n      GCfunc *fn = frame_func(frame);\n      const uint8_t *p = (const uint8_t *)fmt;\n      int c;\n      while ((c = *p++)) {\n\tswitch (c) {\n\tcase 'p':  /* Preserve full path. */\n\t  pathstrip = 0;\n\t  break;\n\tcase 'F': case 'f': {  /* Dump function name. */\n\t  const char *name;\n\t  const char *what = lj_debug_funcname(L, frame, &name);\n\t  if (what) {\n\t    if (c == 'F' && isluafunc(fn)) {  /* Dump module:name for 'F'. */\n\t      GCproto *pt = funcproto(fn);\n\t      if (pt->firstline != ~(BCLine)0) {  /* Not a bytecode builtin. */\n\t\tdebug_putchunkname(sb, pt, pathstrip);\n\t\tlj_buf_putb(sb, ':');\n\t      }\n\t    }\n\t    lj_buf_putmem(sb, name, (MSize)strlen(name));\n\t    break;\n\t  }  /* else: can't derive a name, dump module:line. */\n\t  }\n\t  /* fallthrough */\n\tcase 'l':  /* Dump module:line. */\n\t  if (isluafunc(fn)) {\n\t    GCproto *pt = funcproto(fn);\n\t    if (debug_putchunkname(sb, pt, pathstrip)) {\n\t      /* Regular Lua function. */\n\t      BCLine line = c == 'l' ? debug_frameline(L, fn, nextframe) :\n\t\t\t\t       pt->firstline;\n\t      lj_buf_putb(sb, ':');\n\t      lj_strfmt_putint(sb, line >= 0 ? line : pt->firstline);\n\t    }\n\t  } else if (isffunc(fn)) {  /* Dump numbered builtins. */\n\t    lj_buf_putmem(sb, \"[builtin#\", 9);\n\t    lj_strfmt_putint(sb, fn->c.ffid);\n\t    lj_buf_putb(sb, ']');\n\t  } else {  /* Dump C function address. */\n\t    lj_buf_putb(sb, '@');\n\t    lj_strfmt_putptr(sb, fn->c.f);\n\t  }\n\t  break;\n\tcase 'Z':  /* Zap trailing separator. */\n\t  lastlen = sbuflen(sb);\n\t  break;\n\tdefault:\n\t  lj_buf_putb(sb, c);\n\t  break;\n\t}\n      }\n    } else if (dir == 1) {\n      break;\n    } else {\n      level -= size;  /* Reverse frame order: quickly skip missing level. */\n    }\n    level += dir;\n  }\n  if (lastlen)\n    setsbufP(sb, sbufB(sb) + lastlen);  /* Zap trailing separator. */\n}\n#endif\n\n/* Number of frames for the leading and trailing part of a traceback. */\n#define TRACEBACK_LEVELS1\t12\n#define TRACEBACK_LEVELS2\t10\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n\t\t\t\tint level)\n{\n  int top = (int)(L->top - L->base);\n  int lim = TRACEBACK_LEVELS1;\n  lua_Debug ar;\n  if (msg) lua_pushfstring(L, \"%s\\n\", msg);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    GCfunc *fn;\n    if (level > lim) {\n      if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) {\n\tlevel--;\n      } else {\n\tlua_pushliteral(L, \"\\n\\t...\");\n\tlua_getstack(L1, -10, &ar);\n\tlevel = ar.i_ci - TRACEBACK_LEVELS2;\n      }\n      lim = 2147483647;\n      continue;\n    }\n    lua_getinfo(L1, \"Snlf\", &ar);\n    fn = funcV(L1->top-1); L1->top--;\n    if (isffunc(fn) && !*ar.namewhat)\n      lua_pushfstring(L, \"\\n\\t[builtin#%d]:\", fn->c.ffid);\n    else\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n    if (ar.currentline > 0)\n      lua_pushfstring(L, \"%d:\", ar.currentline);\n    if (*ar.namewhat) {\n      lua_pushfstring(L, \" in function \" LUA_QS, ar.name);\n    } else {\n      if (*ar.what == 'm') {\n\tlua_pushliteral(L, \" in main chunk\");\n      } else if (*ar.what == 'C') {\n\tlua_pushfstring(L, \" at %p\", fn->c.f);\n      } else {\n\tlua_pushfstring(L, \" in function <%s:%d>\",\n\t\t\tar.short_src, ar.linedefined);\n      }\n    }\n    if ((int)(L->top - L->base) - top >= 15)\n      lua_concat(L, (int)(L->top - L->base) - top);\n  }\n  lua_concat(L, (int)(L->top - L->base) - top);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_debug.h",
    "content": "/*\n** Debugging and introspection.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DEBUG_H\n#define _LJ_DEBUG_H\n\n#include \"lj_obj.h\"\n\ntypedef struct lj_Debug {\n  /* Common fields. Must be in the same order as in lua.h. */\n  int event;\n  const char *name;\n  const char *namewhat;\n  const char *what;\n  const char *source;\n  int currentline;\n  int nups;\n  int linedefined;\n  int lastlinedefined;\n  char short_src[LUA_IDSIZE];\n  int i_ci;\n  /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/\n  int nparams;\n  int isvararg;\n} lj_Debug;\n\nLJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);\nLJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);\nLJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);\nLJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp);\nLJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,\n\t\t\t\t      BCReg slot, const char **name);\nLJ_FUNC const char *lj_debug_funcname(lua_State *L, cTValue *frame,\n\t\t\t\t      const char **name);\nLJ_FUNC void lj_debug_shortname(char *out, GCstr *str, BCLine line);\nLJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,\n\t\t\t     cTValue *frame, cTValue *nextframe);\nLJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);\nLJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,\n\t\t\t     int ext);\n#if LJ_HASPROFILE\nLJ_FUNC void lj_debug_dumpstack(lua_State *L, SBuf *sb, const char *fmt,\n\t\t\t\tint depth);\n#endif\n\n/* Fixed internal variable names. */\n#define VARNAMEDEF(_) \\\n  _(FOR_IDX, \"(for index)\") \\\n  _(FOR_STOP, \"(for limit)\") \\\n  _(FOR_STEP, \"(for step)\") \\\n  _(FOR_GEN, \"(for generator)\") \\\n  _(FOR_STATE, \"(for state)\") \\\n  _(FOR_CTL, \"(for control)\")\n\nenum {\n  VARNAME_END,\n#define VARNAMEENUM(name, str)\tVARNAME_##name,\n  VARNAMEDEF(VARNAMEENUM)\n#undef VARNAMEENUM\n  VARNAME__MAX\n};\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_def.h",
    "content": "/*\n** LuaJIT common internal definitions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DEF_H\n#define _LJ_DEF_H\n\n#include \"lua.h\"\n\n#if defined(_MSC_VER)\n/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */\ntypedef __int8 int8_t;\ntypedef __int16 int16_t;\ntypedef __int32 int32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int8 uint8_t;\ntypedef unsigned __int16 uint16_t;\ntypedef unsigned __int32 uint32_t;\ntypedef unsigned __int64 uint64_t;\n#ifdef _WIN64\ntypedef __int64 intptr_t;\ntypedef unsigned __int64 uintptr_t;\n#else\ntypedef __int32 intptr_t;\ntypedef unsigned __int32 uintptr_t;\n#endif\n#elif defined(__symbian__)\n/* Cough. */\ntypedef signed char int8_t;\ntypedef short int int16_t;\ntypedef int int32_t;\ntypedef long long int64_t;\ntypedef unsigned char uint8_t;\ntypedef unsigned short int uint16_t;\ntypedef unsigned int uint32_t;\ntypedef unsigned long long uint64_t;\ntypedef int intptr_t;\ntypedef unsigned int uintptr_t;\n#else\n#include <stdint.h>\n#endif\n\n/* Needed everywhere. */\n#include <string.h>\n#include <stdlib.h>\n\n/* Various VM limits. */\n#define LJ_MAX_MEM32\t0x7fffff00\t/* Max. 32 bit memory allocation. */\n#define LJ_MAX_MEM64\t((uint64_t)1<<47)  /* Max. 64 bit memory allocation. */\n/* Max. total memory allocation. */\n#define LJ_MAX_MEM\t(LJ_GC64 ? LJ_MAX_MEM64 : LJ_MAX_MEM32)\n#define LJ_MAX_ALLOC\tLJ_MAX_MEM\t/* Max. individual allocation length. */\n#define LJ_MAX_STR\tLJ_MAX_MEM32\t/* Max. string length. */\n#define LJ_MAX_BUF\tLJ_MAX_MEM32\t/* Max. buffer length. */\n#define LJ_MAX_UDATA\tLJ_MAX_MEM32\t/* Max. userdata length. */\n\n#define LJ_MAX_STRTAB\t(1<<26)\t\t/* Max. string table size. */\n#define LJ_MAX_HBITS\t26\t\t/* Max. hash bits. */\n#define LJ_MAX_ABITS\t28\t\t/* Max. bits of array key. */\n#define LJ_MAX_ASIZE\t((1<<(LJ_MAX_ABITS-1))+1)  /* Max. array part size. */\n#define LJ_MAX_COLOSIZE\t16\t\t/* Max. elems for colocated array. */\n\n#define LJ_MAX_LINE\tLJ_MAX_MEM32\t/* Max. source code line number. */\n#define LJ_MAX_XLEVEL\t200\t\t/* Max. syntactic nesting level. */\n#define LJ_MAX_BCINS\t(1<<26)\t\t/* Max. # of bytecode instructions. */\n#define LJ_MAX_SLOTS\t250\t\t/* Max. # of slots in a Lua func. */\n#define LJ_MAX_LOCVAR\t200\t\t/* Max. # of local variables. */\n#define LJ_MAX_UPVAL\t60\t\t/* Max. # of upvalues. */\n\n#define LJ_MAX_IDXCHAIN\t100\t\t/* __index/__newindex chain limit. */\n#define LJ_STACK_EXTRA\t(5+2*LJ_FR2)\t/* Extra stack space (metamethods). */\n\n#define LJ_NUM_CBPAGE\t1\t\t/* Number of FFI callback pages. */\n\n/* Minimum table/buffer sizes. */\n#define LJ_MIN_GLOBAL\t6\t\t/* Min. global table size (hbits). */\n#define LJ_MIN_REGISTRY\t2\t\t/* Min. registry size (hbits). */\n#define LJ_MIN_STRTAB\t256\t\t/* Min. string table size (pow2). */\n#define LJ_MIN_SBUF\t32\t\t/* Min. string buffer length. */\n#define LJ_MIN_VECSZ\t8\t\t/* Min. size for growable vectors. */\n#define LJ_MIN_IRSZ\t32\t\t/* Min. size for growable IR. */\n#define LJ_MIN_K64SZ\t16\t\t/* Min. size for chained K64Array. */\n\n/* JIT compiler limits. */\n#define LJ_MAX_JSLOTS\t250\t\t/* Max. # of stack slots for a trace. */\n#define LJ_MAX_PHI\t64\t\t/* Max. # of PHIs for a loop. */\n#define LJ_MAX_EXITSTUBGR\t16\t/* Max. # of exit stub groups. */\n\n/* Various macros. */\n#ifndef UNUSED\n#define UNUSED(x)\t((void)(x))\t/* to avoid warnings */\n#endif\n\n#define U64x(hi, lo)\t(((uint64_t)0x##hi << 32) + (uint64_t)0x##lo)\n#define i32ptr(p)\t((int32_t)(intptr_t)(void *)(p))\n#define u32ptr(p)\t((uint32_t)(intptr_t)(void *)(p))\n\n#define checki8(x)\t((x) == (int32_t)(int8_t)(x))\n#define checku8(x)\t((x) == (int32_t)(uint8_t)(x))\n#define checki16(x)\t((x) == (int32_t)(int16_t)(x))\n#define checku16(x)\t((x) == (int32_t)(uint16_t)(x))\n#define checki32(x)\t((x) == (int32_t)(x))\n#define checku32(x)\t((x) == (uint32_t)(x))\n#define checkptr32(x)\t((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))\n#define checkptr47(x)\t(((uint64_t)(x) >> 47) == 0)\n#if LJ_GC64\n#define checkptrGC(x)\t(checkptr47((x)))\n#elif LJ_64\n#define checkptrGC(x)\t(checkptr32((x)))\n#else\n#define checkptrGC(x)\t1\n#endif\n\n/* Every half-decent C compiler transforms this into a rotate instruction. */\n#define lj_rol(x, n)\t(((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))\n#define lj_ror(x, n)\t(((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))\n\n/* A really naive Bloom filter. But sufficient for our needs. */\ntypedef uintptr_t BloomFilter;\n#define BLOOM_MASK\t(8*sizeof(BloomFilter) - 1)\n#define bloombit(x)\t((uintptr_t)1 << ((x) & BLOOM_MASK))\n#define bloomset(b, x)\t((b) |= bloombit((x)))\n#define bloomtest(b, x)\t((b) & bloombit((x)))\n\n#if defined(__GNUC__) || defined(__psp2__)\n\n#define LJ_NORET\t__attribute__((noreturn))\n#define LJ_ALIGN(n)\t__attribute__((aligned(n)))\n#define LJ_INLINE\tinline\n#define LJ_AINLINE\tinline __attribute__((always_inline))\n#define LJ_NOINLINE\t__attribute__((noinline))\n\n#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)\n#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))\n#define LJ_NOAPI\textern __attribute__((visibility(\"hidden\")))\n#endif\n#endif\n\n/* Note: it's only beneficial to use fastcall on x86 and then only for up to\n** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only\n** indirect calls and related tail-called C functions are marked as fastcall.\n*/\n#if defined(__i386__)\n#define LJ_FASTCALL\t__attribute__((fastcall))\n#endif\n\n#define LJ_LIKELY(x)\t__builtin_expect(!!(x), 1)\n#define LJ_UNLIKELY(x)\t__builtin_expect(!!(x), 0)\n\n#define lj_ffs(x)\t((uint32_t)__builtin_ctz(x))\n/* Don't ask ... */\n#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__))\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  uint32_t r; __asm__(\"bsrl %1, %0\" : \"=r\" (r) : \"rm\" (x) : \"cc\"); return r;\n}\n#else\n#define lj_fls(x)\t((uint32_t)(__builtin_clz(x)^31))\n#endif\n\n#if defined(__arm__)\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n#if defined(__psp2__)\n  return __builtin_rev(x);\n#else\n  uint32_t r;\n#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\\\n    __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__\n  __asm__(\"rev %0, %1\" : \"=r\" (r) : \"r\" (x));\n  return r;\n#else\n#ifdef __thumb__\n  r = x ^ lj_ror(x, 16);\n#else\n  __asm__(\"eor %0, %1, %1, ror #16\" : \"=r\" (r) : \"r\" (x));\n#endif\n  return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);\n#endif\n#endif\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));\n}\n#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  return (uint32_t)__builtin_bswap32((int32_t)x);\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return (uint64_t)__builtin_bswap64((int64_t)x);\n}\n#elif defined(__i386__) || defined(__x86_64__)\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  uint32_t r; __asm__(\"bswap %0\" : \"=r\" (r) : \"0\" (x)); return r;\n}\n\n#if defined(__i386__)\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));\n}\n#else\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  uint64_t r; __asm__(\"bswap %0\" : \"=r\" (r) : \"0\" (x)); return r;\n}\n#endif\n#else\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24);\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return (uint64_t)lj_bswap((uint32_t)(x >> 32)) |\n\t ((uint64_t)lj_bswap((uint32_t)x) << 32);\n}\n#endif\n\ntypedef union __attribute__((packed)) Unaligned16 {\n  uint16_t u;\n  uint8_t b[2];\n} Unaligned16;\n\ntypedef union __attribute__((packed)) Unaligned32 {\n  uint32_t u;\n  uint8_t b[4];\n} Unaligned32;\n\n/* Unaligned load of uint16_t. */\nstatic LJ_AINLINE uint16_t lj_getu16(const void *p)\n{\n  return ((const Unaligned16 *)p)->u;\n}\n\n/* Unaligned load of uint32_t. */\nstatic LJ_AINLINE uint32_t lj_getu32(const void *p)\n{\n  return ((const Unaligned32 *)p)->u;\n}\n\n#elif defined(_MSC_VER)\n\n#define LJ_NORET\t__declspec(noreturn)\n#define LJ_ALIGN(n)\t__declspec(align(n))\n#define LJ_INLINE\t__inline\n#define LJ_AINLINE\t__forceinline\n#define LJ_NOINLINE\t__declspec(noinline)\n#if defined(_M_IX86)\n#define LJ_FASTCALL\t__fastcall\n#endif\n\n#ifdef _M_PPC\nunsigned int _CountLeadingZeros(long);\n#pragma intrinsic(_CountLeadingZeros)\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  return _CountLeadingZeros(x) ^ 31;\n}\n#else\nunsigned char _BitScanForward(uint32_t *, unsigned long);\nunsigned char _BitScanReverse(uint32_t *, unsigned long);\n#pragma intrinsic(_BitScanForward)\n#pragma intrinsic(_BitScanReverse)\n\nstatic LJ_AINLINE uint32_t lj_ffs(uint32_t x)\n{\n  uint32_t r; _BitScanForward(&r, x); return r;\n}\n\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  uint32_t r; _BitScanReverse(&r, x); return r;\n}\n#endif\n\nunsigned long _byteswap_ulong(unsigned long);\nuint64_t _byteswap_uint64(uint64_t);\n#define lj_bswap(x)\t(_byteswap_ulong((x)))\n#define lj_bswap64(x)\t(_byteswap_uint64((x)))\n\n#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)\n/*\n** Replacement for unaligned loads on Xbox 360. Disabled by default since it's\n** usually more costly than the occasional stall when crossing a cache-line.\n*/\nstatic LJ_AINLINE uint16_t lj_getu16(const void *v)\n{\n  const uint8_t *p = (const uint8_t *)v;\n  return (uint16_t)((p[0]<<8) | p[1]);\n}\nstatic LJ_AINLINE uint32_t lj_getu32(const void *v)\n{\n  const uint8_t *p = (const uint8_t *)v;\n  return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);\n}\n#else\n/* Unaligned loads are generally ok on x86/x64. */\n#define lj_getu16(p)\t(*(uint16_t *)(p))\n#define lj_getu32(p)\t(*(uint32_t *)(p))\n#endif\n\n#else\n#error \"missing defines for your compiler\"\n#endif\n\n/* Optional defines. */\n#ifndef LJ_FASTCALL\n#define LJ_FASTCALL\n#endif\n#ifndef LJ_NORET\n#define LJ_NORET\n#endif\n#ifndef LJ_NOAPI\n#define LJ_NOAPI\textern\n#endif\n#ifndef LJ_LIKELY\n#define LJ_LIKELY(x)\t(x)\n#define LJ_UNLIKELY(x)\t(x)\n#endif\n\n/* Attributes for internal functions. */\n#define LJ_DATA\t\tLJ_NOAPI\n#define LJ_DATADEF\n#define LJ_ASMF\t\tLJ_NOAPI\n#define LJ_FUNCA\tLJ_NOAPI\n#if defined(ljamalg_c)\n#define LJ_FUNC\t\tstatic\n#else\n#define LJ_FUNC\t\tLJ_NOAPI\n#endif\n#define LJ_FUNC_NORET\tLJ_FUNC LJ_NORET\n#define LJ_FUNCA_NORET\tLJ_FUNCA LJ_NORET\n#define LJ_ASMF_NORET\tLJ_ASMF LJ_NORET\n\n/* Runtime assertions. */\n#ifdef lua_assert\n#define check_exp(c, e)\t\t(lua_assert(c), (e))\n#define api_check(l, e)\t\tlua_assert(e)\n#else\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c, e)\t\t(e)\n#define api_check\t\tluai_apicheck\n#endif\n\n/* Static assertions. */\n#define LJ_ASSERT_NAME2(name, line)\tname ## line\n#define LJ_ASSERT_NAME(line)\t\tLJ_ASSERT_NAME2(lj_assert_, line)\n#ifdef __COUNTER__\n#define LJ_STATIC_ASSERT(cond) \\\n  extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])\n#else\n#define LJ_STATIC_ASSERT(cond) \\\n  extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_dispatch.c",
    "content": "/*\n** Instruction dispatch handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_dispatch_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_func.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_debug.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n#if LJ_HASFFI\n#include \"lj_ccallback.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASPROFILE\n#include \"lj_profile.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"luajit.h\"\n\n/* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */\nLJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC);\n\n/* -- Dispatch table management ------------------------------------------- */\n\n#if LJ_TARGET_MIPS\n#include <math.h>\nLJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,\n\t\t\t\t\t\t\t  lua_State *co);\n#if !LJ_HASJIT\n#define lj_dispatch_stitch\tlj_dispatch_ins\n#endif\n#if !LJ_HASPROFILE\n#define lj_dispatch_profile\tlj_dispatch_ins\n#endif\n\n#define GOTFUNC(name)\t(ASMFunction)name,\nstatic const ASMFunction dispatch_got[] = {\n  GOTDEF(GOTFUNC)\n};\n#undef GOTFUNC\n#endif\n\n/* Initialize instruction dispatch table and hot counters. */\nvoid lj_dispatch_init(GG_State *GG)\n{\n  uint32_t i;\n  ASMFunction *disp = GG->dispatch;\n  for (i = 0; i < GG_LEN_SDISP; i++)\n    disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]);\n  for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n    disp[i] = makeasmfunc(lj_bc_ofs[i]);\n  /* The JIT engine is off by default. luaopen_jit() turns it on. */\n  disp[BC_FORL] = disp[BC_IFORL];\n  disp[BC_ITERL] = disp[BC_IITERL];\n  disp[BC_LOOP] = disp[BC_ILOOP];\n  disp[BC_FUNCF] = disp[BC_IFUNCF];\n  disp[BC_FUNCV] = disp[BC_IFUNCV];\n  GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0);\n  for (i = 0; i < GG_NUM_ASMFF; i++)\n    GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0);\n#if LJ_TARGET_MIPS\n  memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);\n#endif\n}\n\n#if LJ_HASJIT\n/* Initialize hotcount table. */\nvoid lj_dispatch_init_hotcount(global_State *g)\n{\n  int32_t hotloop = G2J(g)->param[JIT_P_hotloop];\n  HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1);\n  HotCount *hotcount = G2GG(g)->hotcount;\n  uint32_t i;\n  for (i = 0; i < HOTCOUNT_SIZE; i++)\n    hotcount[i] = start;\n}\n#endif\n\n/* Internal dispatch mode bits. */\n#define DISPMODE_CALL\t0x01\t/* Override call dispatch. */\n#define DISPMODE_RET\t0x02\t/* Override return dispatch. */\n#define DISPMODE_INS\t0x04\t/* Override instruction dispatch. */\n#define DISPMODE_JIT\t0x10\t/* JIT compiler on. */\n#define DISPMODE_REC\t0x20\t/* Recording active. */\n#define DISPMODE_PROF\t0x40\t/* Profiling active. */\n\n/* Update dispatch table depending on various flags. */\nvoid lj_dispatch_update(global_State *g)\n{\n  uint8_t oldmode = g->dispatchmode;\n  uint8_t mode = 0;\n#if LJ_HASJIT\n  mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0;\n  mode |= G2J(g)->state != LJ_TRACE_IDLE ?\n\t    (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0;\n#endif\n#if LJ_HASPROFILE\n  mode |= (g->hookmask & HOOK_PROFILE) ? (DISPMODE_PROF|DISPMODE_INS) : 0;\n#endif\n  mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0;\n  mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0;\n  mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0;\n  if (oldmode != mode) {  /* Mode changed? */\n    ASMFunction *disp = G2GG(g)->dispatch;\n    ASMFunction f_forl, f_iterl, f_loop, f_funcf, f_funcv;\n    g->dispatchmode = mode;\n\n    /* Hotcount if JIT is on, but not while recording. */\n    if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) {\n      f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]);\n      f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]);\n      f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]);\n      f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]);\n      f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]);\n    } else {  /* Otherwise use the non-hotcounting instructions. */\n      f_forl = disp[GG_LEN_DDISP+BC_IFORL];\n      f_iterl = disp[GG_LEN_DDISP+BC_IITERL];\n      f_loop = disp[GG_LEN_DDISP+BC_ILOOP];\n      f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]);\n      f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]);\n    }\n    /* Init static counting instruction dispatch first (may be copied below). */\n    disp[GG_LEN_DDISP+BC_FORL] = f_forl;\n    disp[GG_LEN_DDISP+BC_ITERL] = f_iterl;\n    disp[GG_LEN_DDISP+BC_LOOP] = f_loop;\n\n    /* Set dynamic instruction dispatch. */\n    if ((oldmode ^ mode) & (DISPMODE_PROF|DISPMODE_REC|DISPMODE_INS)) {\n      /* Need to update the whole table. */\n      if (!(mode & DISPMODE_INS)) {  /* No ins dispatch? */\n\t/* Copy static dispatch table to dynamic dispatch table. */\n\tmemcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction));\n\t/* Overwrite with dynamic return dispatch. */\n\tif ((mode & DISPMODE_RET)) {\n\t  disp[BC_RETM] = lj_vm_rethook;\n\t  disp[BC_RET] = lj_vm_rethook;\n\t  disp[BC_RET0] = lj_vm_rethook;\n\t  disp[BC_RET1] = lj_vm_rethook;\n\t}\n      } else {\n\t/* The recording dispatch also checks for hooks. */\n\tASMFunction f = (mode & DISPMODE_PROF) ? lj_vm_profhook :\n\t\t\t(mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;\n\tuint32_t i;\n\tfor (i = 0; i < GG_LEN_SDISP; i++)\n\t  disp[i] = f;\n      }\n    } else if (!(mode & DISPMODE_INS)) {\n      /* Otherwise set dynamic counting ins. */\n      disp[BC_FORL] = f_forl;\n      disp[BC_ITERL] = f_iterl;\n      disp[BC_LOOP] = f_loop;\n      /* Set dynamic return dispatch. */\n      if ((mode & DISPMODE_RET)) {\n\tdisp[BC_RETM] = lj_vm_rethook;\n\tdisp[BC_RET] = lj_vm_rethook;\n\tdisp[BC_RET0] = lj_vm_rethook;\n\tdisp[BC_RET1] = lj_vm_rethook;\n      } else {\n\tdisp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM];\n\tdisp[BC_RET] = disp[GG_LEN_DDISP+BC_RET];\n\tdisp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0];\n\tdisp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1];\n      }\n    }\n\n    /* Set dynamic call dispatch. */\n    if ((oldmode ^ mode) & DISPMODE_CALL) {  /* Update the whole table? */\n      uint32_t i;\n      if ((mode & DISPMODE_CALL) == 0) {  /* No call hooks? */\n\tfor (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n\t  disp[i] = makeasmfunc(lj_bc_ofs[i]);\n      } else {\n\tfor (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n\t  disp[i] = lj_vm_callhook;\n      }\n    }\n    if (!(mode & DISPMODE_CALL)) {  /* Overwrite dynamic counting ins. */\n      disp[BC_FUNCF] = f_funcf;\n      disp[BC_FUNCV] = f_funcv;\n    }\n\n#if LJ_HASJIT\n    /* Reset hotcounts for JIT off to on transition. */\n    if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT))\n      lj_dispatch_init_hotcount(g);\n#endif\n  }\n}\n\n/* -- JIT mode setting ---------------------------------------------------- */\n\n#if LJ_HASJIT\n/* Set JIT mode for a single prototype. */\nstatic void setptmode(global_State *g, GCproto *pt, int mode)\n{\n  if ((mode & LUAJIT_MODE_ON)) {  /* (Re-)enable JIT compilation. */\n    pt->flags &= ~PROTO_NOJIT;\n    lj_trace_reenableproto(pt);  /* Unpatch all ILOOP etc. bytecodes. */\n  } else {  /* Flush and/or disable JIT compilation. */\n    if (!(mode & LUAJIT_MODE_FLUSH))\n      pt->flags |= PROTO_NOJIT;\n    lj_trace_flushproto(g, pt);  /* Flush all traces of prototype. */\n  }\n}\n\n/* Recursively set the JIT mode for all children of a prototype. */\nstatic void setptmode_all(global_State *g, GCproto *pt, int mode)\n{\n  ptrdiff_t i;\n  if (!(pt->flags & PROTO_CHILD)) return;\n  for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) {\n    GCobj *o = proto_kgc(pt, i);\n    if (o->gch.gct == ~LJ_TPROTO) {\n      setptmode(g, gco2pt(o), mode);\n      setptmode_all(g, gco2pt(o), mode);\n    }\n  }\n}\n#endif\n\n/* Public API function: control the JIT engine. */\nint luaJIT_setmode(lua_State *L, int idx, int mode)\n{\n  global_State *g = G(L);\n  int mm = mode & LUAJIT_MODE_MASK;\n  lj_trace_abort(g);  /* Abort recording on any state change. */\n  /* Avoid pulling the rug from under our own feet. */\n  if ((g->hookmask & HOOK_GC))\n    lj_err_caller(L, LJ_ERR_NOGCMM);\n  switch (mm) {\n#if LJ_HASJIT\n  case LUAJIT_MODE_ENGINE:\n    if ((mode & LUAJIT_MODE_FLUSH)) {\n      lj_trace_flushall(L);\n    } else {\n      if (!(mode & LUAJIT_MODE_ON))\n\tG2J(g)->flags &= ~(uint32_t)JIT_F_ON;\n#if LJ_TARGET_X86ORX64\n      else if ((G2J(g)->flags & JIT_F_SSE2))\n\tG2J(g)->flags |= (uint32_t)JIT_F_ON;\n      else\n\treturn 0;  /* Don't turn on JIT compiler without SSE2 support. */\n#else\n      else\n\tG2J(g)->flags |= (uint32_t)JIT_F_ON;\n#endif\n      lj_dispatch_update(g);\n    }\n    break;\n  case LUAJIT_MODE_FUNC:\n  case LUAJIT_MODE_ALLFUNC:\n  case LUAJIT_MODE_ALLSUBFUNC: {\n    cTValue *tv = idx == 0 ? frame_prev(L->base-1) :\n\t\t  idx > 0 ? L->base + (idx-1) : L->top + idx;\n    GCproto *pt;\n    if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn))\n      pt = funcproto(&gcval(tv)->fn);  /* Cannot use funcV() for frame slot. */\n    else if (tvisproto(tv))\n      pt = protoV(tv);\n    else\n      return 0;  /* Failed. */\n    if (mm != LUAJIT_MODE_ALLSUBFUNC)\n      setptmode(g, pt, mode);\n    if (mm != LUAJIT_MODE_FUNC)\n      setptmode_all(g, pt, mode);\n    break;\n    }\n  case LUAJIT_MODE_TRACE:\n    if (!(mode & LUAJIT_MODE_FLUSH))\n      return 0;  /* Failed. */\n    lj_trace_flush(G2J(g), idx);\n    break;\n#else\n  case LUAJIT_MODE_ENGINE:\n  case LUAJIT_MODE_FUNC:\n  case LUAJIT_MODE_ALLFUNC:\n  case LUAJIT_MODE_ALLSUBFUNC:\n    UNUSED(idx);\n    if ((mode & LUAJIT_MODE_ON))\n      return 0;  /* Failed. */\n    break;\n#endif\n  case LUAJIT_MODE_WRAPCFUNC:\n    if ((mode & LUAJIT_MODE_ON)) {\n      if (idx != 0) {\n\tcTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx;\n\tif (tvislightud(tv))\n\t  g->wrapf = (lua_CFunction)lightudV(tv);\n\telse\n\t  return 0;  /* Failed. */\n      } else {\n\treturn 0;  /* Failed. */\n      }\n      g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0);\n    } else {\n      g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0);\n    }\n    break;\n  default:\n    return 0;  /* Failed. */\n  }\n  return 1;  /* OK. */\n}\n\n/* Enforce (dynamic) linker error for version mismatches. See luajit.c. */\nLUA_API void LUAJIT_VERSION_SYM(void)\n{\n}\n\n/* -- Hooks --------------------------------------------------------------- */\n\n/* This function can be called asynchronously (e.g. during a signal). */\nLUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)\n{\n  global_State *g = G(L);\n  mask &= HOOK_EVENTMASK;\n  if (func == NULL || mask == 0) { mask = 0; func = NULL; }  /* Consistency. */\n  g->hookf = func;\n  g->hookcount = g->hookcstart = (int32_t)count;\n  g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask);\n  lj_trace_abort(g);  /* Abort recording on any hook change. */\n  lj_dispatch_update(g);\n  return 1;\n}\n\nLUA_API lua_Hook lua_gethook(lua_State *L)\n{\n  return G(L)->hookf;\n}\n\nLUA_API int lua_gethookmask(lua_State *L)\n{\n  return G(L)->hookmask & HOOK_EVENTMASK;\n}\n\nLUA_API int lua_gethookcount(lua_State *L)\n{\n  return (int)G(L)->hookcstart;\n}\n\n/* Call a hook. */\nstatic void callhook(lua_State *L, int event, BCLine line)\n{\n  global_State *g = G(L);\n  lua_Hook hookf = g->hookf;\n  if (hookf && !hook_active(g)) {\n    lua_Debug ar;\n    lj_trace_abort(g);  /* Abort recording on any hook call. */\n    ar.event = event;\n    ar.currentline = line;\n    /* Top frame, nextframe = NULL. */\n    ar.i_ci = (int)((L->base-1) - tvref(L->stack));\n    lj_state_checkstack(L, 1+LUA_MINSTACK);\n#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF\n    lj_profile_hook_enter(g);\n#else\n    hook_enter(g);\n#endif\n    hookf(L, &ar);\n    lua_assert(hook_active(g));\n    setgcref(g->cur_L, obj2gco(L));\n#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF\n    lj_profile_hook_leave(g);\n#else\n    hook_leave(g);\n#endif\n  }\n}\n\n/* -- Dispatch callbacks -------------------------------------------------- */\n\n/* Calculate number of used stack slots in the current frame. */\nstatic BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres)\n{\n  BCIns ins = pc[-1];\n  if (bc_op(ins) == BC_UCLO)\n    ins = pc[bc_j(ins)];\n  switch (bc_op(ins)) {\n  case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1+LJ_FR2;\n  case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1;\n  case BC_TSETM: return bc_a(ins) + nres-1;\n  default: return pt->framesize;\n  }\n}\n\n/* Instruction dispatch. Used by instr/line/return hooks or when recording. */\nvoid LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  GCproto *pt = funcproto(fn);\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  global_State *g = G(L);\n  BCReg slots;\n  setcframe_pc(cf, pc);\n  slots = cur_topslot(pt, pc, cframe_multres_n(cf));\n  L->top = L->base + slots;  /* Fix top. */\n#if LJ_HASJIT\n  {\n    jit_State *J = G2J(g);\n    if (J->state != LJ_TRACE_IDLE) {\n#ifdef LUA_USE_ASSERT\n      ptrdiff_t delta = L->top - L->base;\n#endif\n      J->L = L;\n      lj_trace_ins(J, pc-1);  /* The interpreter bytecode PC is offset by 1. */\n      lua_assert(L->top - L->base == delta);\n    }\n  }\n#endif\n  if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {\n    g->hookcount = g->hookcstart;\n    callhook(L, LUA_HOOKCOUNT, -1);\n    L->top = L->base + slots;  /* Fix top again. */\n  }\n  if ((g->hookmask & LUA_MASKLINE)) {\n    BCPos npc = proto_bcpos(pt, pc) - 1;\n    BCPos opc = proto_bcpos(pt, oldpc) - 1;\n    BCLine line = lj_debug_line(pt, npc);\n    if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) {\n      callhook(L, LUA_HOOKLINE, line);\n      L->top = L->base + slots;  /* Fix top again. */\n    }\n  }\n  if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1])))\n    callhook(L, LUA_HOOKRET, -1);\n  ERRNO_RESTORE\n}\n\n/* Initialize call. Ensure stack space and return # of missing parameters. */\nstatic int call_init(lua_State *L, GCfunc *fn)\n{\n  if (isluafunc(fn)) {\n    GCproto *pt = funcproto(fn);\n    int numparams = pt->numparams;\n    int gotparams = (int)(L->top - L->base);\n    int need = pt->framesize;\n    if ((pt->flags & PROTO_VARARG)) need += 1+gotparams;\n    lj_state_checkstack(L, (MSize)need);\n    numparams -= gotparams;\n    return numparams >= 0 ? numparams : 0;\n  } else {\n    lj_state_checkstack(L, LUA_MINSTACK);\n    return 0;\n  }\n}\n\n/* Call dispatch. Used by call hooks, hot calls or when recording. */\nASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  BCOp op;\n  global_State *g = G(L);\n#if LJ_HASJIT\n  jit_State *J = G2J(g);\n#endif\n  int missing = call_init(L, fn);\n#if LJ_HASJIT\n  J->L = L;\n  if ((uintptr_t)pc & 1) {  /* Marker for hot call. */\n#ifdef LUA_USE_ASSERT\n    ptrdiff_t delta = L->top - L->base;\n#endif\n    pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1);\n    lj_trace_hot(J, pc);\n    lua_assert(L->top - L->base == delta);\n    goto out;\n  } else if (J->state != LJ_TRACE_IDLE &&\n\t     !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n#ifdef LUA_USE_ASSERT\n    ptrdiff_t delta = L->top - L->base;\n#endif\n    /* Record the FUNC* bytecodes, too. */\n    lj_trace_ins(J, pc-1);  /* The interpreter bytecode PC is offset by 1. */\n    lua_assert(L->top - L->base == delta);\n  }\n#endif\n  if ((g->hookmask & LUA_MASKCALL)) {\n    int i;\n    for (i = 0; i < missing; i++)  /* Add missing parameters. */\n      setnilV(L->top++);\n    callhook(L, LUA_HOOKCALL, -1);\n    /* Preserve modifications of missing parameters by lua_setlocal(). */\n    while (missing-- > 0 && tvisnil(L->top - 1))\n      L->top--;\n  }\n#if LJ_HASJIT\nout:\n#endif\n  op = bc_op(pc[-1]);  /* Get FUNC* op. */\n#if LJ_HASJIT\n  /* Use the non-hotcounting variants if JIT is off or while recording. */\n  if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) &&\n      (op == BC_FUNCF || op == BC_FUNCV))\n    op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF);\n#endif\n  ERRNO_RESTORE\n  return makeasmfunc(lj_bc_ofs[op]);  /* Return static dispatch target. */\n}\n\n#if LJ_HASJIT\n/* Stitch a new trace. */\nvoid LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc)\n{\n  ERRNO_SAVE\n  lua_State *L = J->L;\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  setcframe_pc(cf, pc);\n  /* Before dispatch, have to bias PC by 1. */\n  L->top = L->base + cur_topslot(curr_proto(L), pc+1, cframe_multres_n(cf));\n  lj_trace_stitch(J, pc-1);  /* Point to the CALL instruction. */\n  setcframe_pc(cf, oldpc);\n  ERRNO_RESTORE\n}\n#endif\n\n#if LJ_HASPROFILE\n/* Profile dispatch. */\nvoid LJ_FASTCALL lj_dispatch_profile(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  GCproto *pt = funcproto(fn);\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  global_State *g;\n  setcframe_pc(cf, pc);\n  L->top = L->base + cur_topslot(pt, pc, cframe_multres_n(cf));\n  lj_profile_interpreter(L);\n  setcframe_pc(cf, oldpc);\n  g = G(L);\n  setgcref(g->cur_L, obj2gco(L));\n  setvmstate(g, INTERP);\n  ERRNO_RESTORE\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_dispatch.h",
    "content": "/*\n** Instruction dispatch handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DISPATCH_H\n#define _LJ_DISPATCH_H\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n\n#if LJ_TARGET_MIPS\n/* Need our own global offset table for the dreaded MIPS calling conventions. */\n\n#ifndef _LJ_VM_H\nLJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b);\n#endif\n\n#if LJ_SOFTFP\n#ifndef _LJ_IRCALL_H\nextern double __adddf3(double a, double b);\nextern double __subdf3(double a, double b);\nextern double __muldf3(double a, double b);\nextern double __divdf3(double a, double b);\n#endif\n#define SFGOTDEF(_)\t_(sqrt) _(__adddf3) _(__subdf3) _(__muldf3) _(__divdf3)\n#else\n#define SFGOTDEF(_)\n#endif\n#if LJ_HASJIT\n#define JITGOTDEF(_)\t_(lj_trace_exit) _(lj_trace_hot)\n#else\n#define JITGOTDEF(_)\n#endif\n#if LJ_HASFFI\n#define FFIGOTDEF(_) \\\n  _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave)\n#else\n#define FFIGOTDEF(_)\n#endif\n#define GOTDEF(_) \\\n  _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \\\n  _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \\\n  _(pow) _(fmod) _(ldexp) _(lj_vm_modi) \\\n  _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_dispatch_stitch) \\\n  _(lj_dispatch_profile) _(lj_err_throw) \\\n  _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \\\n  _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \\\n  _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \\\n  _(lj_meta_for) _(lj_meta_istype) _(lj_meta_len) _(lj_meta_tget) \\\n  _(lj_meta_tset) _(lj_state_growstack) _(lj_strfmt_number) \\\n  _(lj_str_new) _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) \\\n  _(lj_tab_new) _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \\\n  _(lj_tab_setinth) _(lj_buf_putstr_reverse) _(lj_buf_putstr_lower) \\\n  _(lj_buf_putstr_upper) _(lj_buf_tostr) \\\n  JITGOTDEF(_) FFIGOTDEF(_) SFGOTDEF(_)\n\nenum {\n#define GOTENUM(name) LJ_GOT_##name,\nGOTDEF(GOTENUM)\n#undef GOTENUM\n  LJ_GOT__MAX\n};\n#endif\n\n/* Type of hot counter. Must match the code in the assembler VM. */\n/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */\ntypedef uint16_t HotCount;\n\n/* Number of hot counter hash table entries (must be a power of two). */\n#define HOTCOUNT_SIZE\t\t64\n#define HOTCOUNT_PCMASK\t\t((HOTCOUNT_SIZE-1)*sizeof(HotCount))\n\n/* Hotcount decrements. */\n#define HOTCOUNT_LOOP\t\t2\n#define HOTCOUNT_CALL\t\t1\n\n/* This solves a circular dependency problem -- bump as needed. Sigh. */\n#define GG_NUM_ASMFF\t57\n\n#define GG_LEN_DDISP\t(BC__MAX + GG_NUM_ASMFF)\n#define GG_LEN_SDISP\tBC_FUNCF\n#define GG_LEN_DISP\t(GG_LEN_DDISP + GG_LEN_SDISP)\n\n/* Global state, main thread and extra fields are allocated together. */\ntypedef struct GG_State {\n  lua_State L;\t\t\t\t/* Main thread. */\n  global_State g;\t\t\t/* Global state. */\n#if LJ_TARGET_MIPS\n  ASMFunction got[LJ_GOT__MAX];\t\t/* Global offset table. */\n#endif\n#if LJ_HASJIT\n  jit_State J;\t\t\t\t/* JIT state. */\n  HotCount hotcount[HOTCOUNT_SIZE];\t/* Hot counters. */\n#endif\n  ASMFunction dispatch[GG_LEN_DISP];\t/* Instruction dispatch tables. */\n  BCIns bcff[GG_NUM_ASMFF];\t\t/* Bytecode for ASM fast functions. */\n} GG_State;\n\n#define GG_OFS(field)\t((int)offsetof(GG_State, field))\n#define G2GG(gl)\t((GG_State *)((char *)(gl) - GG_OFS(g)))\n#define J2GG(j)\t\t((GG_State *)((char *)(j) - GG_OFS(J)))\n#define L2GG(L)\t\t(G2GG(G(L)))\n#define J2G(J)\t\t(&J2GG(J)->g)\n#define G2J(gl)\t\t(&G2GG(gl)->J)\n#define L2J(L)\t\t(&L2GG(L)->J)\n#define GG_G2DISP\t(GG_OFS(dispatch) - GG_OFS(g))\n#define GG_DISP2G\t(GG_OFS(g) - GG_OFS(dispatch))\n#define GG_DISP2J\t(GG_OFS(J) - GG_OFS(dispatch))\n#define GG_DISP2HOT\t(GG_OFS(hotcount) - GG_OFS(dispatch))\n#define GG_DISP2STATIC\t(GG_LEN_DDISP*(int)sizeof(ASMFunction))\n\n#define hotcount_get(gg, pc) \\\n  (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)]\n#define hotcount_set(gg, pc, val) \\\n  (hotcount_get((gg), (pc)) = (HotCount)(val))\n\n/* Dispatch table management. */\nLJ_FUNC void lj_dispatch_init(GG_State *GG);\n#if LJ_HASJIT\nLJ_FUNC void lj_dispatch_init_hotcount(global_State *g);\n#endif\nLJ_FUNC void lj_dispatch_update(global_State *g);\n\n/* Instruction dispatch callback for hooks or when recording. */\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc);\nLJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc);\n#if LJ_HASJIT\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc);\n#endif\n#if LJ_HASPROFILE\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_profile(lua_State *L, const BCIns *pc);\n#endif\n\n#if LJ_HASFFI && !defined(_BUILDVM_H)\n/* Save/restore errno and GetLastError() around hooks, exits and recording. */\n#include <errno.h>\n#if LJ_TARGET_WINDOWS\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n#define ERRNO_SAVE\tint olderr = errno; DWORD oldwerr = GetLastError();\n#define ERRNO_RESTORE\terrno = olderr; SetLastError(oldwerr);\n#else\n#define ERRNO_SAVE\tint olderr = errno;\n#define ERRNO_RESTORE\terrno = olderr;\n#endif\n#else\n#define ERRNO_SAVE\n#define ERRNO_RESTORE\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_emit_arm.h",
    "content": "/*\n** ARM instruction emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Constant encoding --------------------------------------------------- */\n\nstatic uint8_t emit_invai[16] = {\n  /* AND */ (ARMI_AND^ARMI_BIC) >> 21,\n  /* EOR */ 0,\n  /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21,\n  /* RSB */ 0,\n  /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21,\n  /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21,\n  /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21,\n  /* RSC */ 0,\n  /* TST */ 0,\n  /* TEQ */ 0,\n  /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21,\n  /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21,\n  /* ORR */ 0,\n  /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21,\n  /* BIC */ (ARMI_BIC^ARMI_AND) >> 21,\n  /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21\n};\n\n/* Encode constant in K12 format for data processing instructions. */\nstatic uint32_t emit_isk12(ARMIns ai, int32_t n)\n{\n  uint32_t invai, i, m = (uint32_t)n;\n  /* K12: unsigned 8 bit value, rotated in steps of two bits. */\n  for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))\n    if (m <= 255) return ARMI_K12|m|i;\n  /* Otherwise try negation/complement with the inverse instruction. */\n  invai = emit_invai[((ai >> 21) & 15)];\n  if (!invai) return 0;  /* Failed. No inverse instruction. */\n  m = ~(uint32_t)n;\n  if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) ||\n      invai == (ARMI_CMP^ARMI_CMN) >> 21) m++;\n  for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))\n    if (m <= 255) return ARMI_K12|(invai<<21)|m|i;\n  return 0;  /* Failed. */\n}\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm);\n}\n\nstatic void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm);\n}\n\nstatic void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn);\n}\n\nstatic void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm);\n}\n\nstatic void emit_d(ASMState *as, ARMIns ai, Reg rd)\n{\n  *--as->mcp = ai | ARMF_D(rd);\n}\n\nstatic void emit_n(ASMState *as, ARMIns ai, Reg rn)\n{\n  *--as->mcp = ai | ARMF_N(rn);\n}\n\nstatic void emit_m(ASMState *as, ARMIns ai, Reg rm)\n{\n  *--as->mcp = ai | ARMF_M(rm);\n}\n\nstatic void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lua_assert(ofs >= -255 && ofs <= 255);\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) |\n\t       ((ofs & 0xf0) << 4) | (ofs & 0x0f);\n}\n\nstatic void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lua_assert(ofs >= -4095 && ofs <= 4095);\n  /* Combine LDR/STR pairs to LDRD/STRD. */\n  if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) &&\n      (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn &&\n      (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) &&\n      as->mcp != as->mcloop) {\n    as->mcp++;\n    emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4);\n    return;\n  }\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs;\n}\n\n#if !LJ_SOFTFP\nstatic void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lua_assert(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0);\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2);\n}\n#endif\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer spills of BASE/L. */\n#define emit_canremat(ref)\t((ref) < ASMREF_L)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg d, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lua_assert(r != d);\n    if (emit_canremat(ref)) {\n      int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);\n      uint32_t k = emit_isk12(ARMI_ADD, delta);\n      if (k) {\n\tif (k == ARMI_K12)\n\t  emit_dm(as, ARMI_MOV, d, r);\n\telse\n\t  emit_dn(as, ARMI_ADD^k, d, r);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Try to find a two step delta relative to another constant. */\nstatic int emit_kdelta2(ASMState *as, Reg d, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lua_assert(r != d);\n    if (emit_canremat(ref)) {\n      int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i;\n      if (other) {\n\tint32_t delta = i - other;\n\tuint32_t sh, inv = 0, k2, k;\n\tif (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; }\n\tsh = lj_ffs(delta) & ~1;\n\tk2 = emit_isk12(0, delta & (255 << sh));\n\tk = emit_isk12(0, delta & ~(255 << sh));\n\tif (k) {\n\t  emit_dn(as, ARMI_ADD^k2^inv, d, d);\n\t  emit_dn(as, ARMI_ADD^k^inv, d, r);\n\t  return 1;\n\t}\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  uint32_t k = emit_isk12(ARMI_MOV, i);\n  lua_assert(rset_test(as->freeset, r) || r == RID_TMP);\n  if (k) {\n    /* Standard K12 constant. */\n    emit_d(as, ARMI_MOV^k, r);\n  } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) {\n    /* 16 bit loword constant for ARMv6T2. */\n    emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);\n  } else if (emit_kdelta1(as, r, i)) {\n    /* One step delta relative to another constant. */\n  } else if ((as->flags & JIT_F_ARMV6T2)) {\n    /* 32 bit hiword/loword constant for ARMv6T2. */\n    emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), r);\n    emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);\n  } else if (emit_kdelta2(as, r, i)) {\n    /* Two step delta relative to another constant. */\n  } else {\n    /* Otherwise construct the constant with up to 4 instructions. */\n    /* NYI: use mvn+bic, use pc-relative loads. */\n    for (;;) {\n      uint32_t sh = lj_ffs(i) & ~1;\n      int32_t m = i & (255 << sh);\n      i &= ~(255 << sh);\n      if (i == 0) {\n\temit_d(as, ARMI_MOV ^ emit_isk12(0, m), r);\n\tbreak;\n      }\n      emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), r, r);\n    }\n  }\n}\n\n#define emit_loada(as, r, addr)\t\temit_loadi(as, (r), i32ptr((addr)))\n\nstatic Reg ra_allock(ASMState *as, int32_t k, RegSet allow);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p)\n{\n  int32_t i = i32ptr(p);\n  emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)),\n\t   (i & 4095));\n}\n\n#if !LJ_SOFTFP\n/* Load a number constant into an FPR. */\nstatic void emit_loadn(ASMState *as, Reg r, cTValue *tv)\n{\n  int32_t i;\n  if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) {\n    uint32_t hi = tv->u32.hi;\n    uint32_t b = ((hi >> 22) & 0x1ff);\n    if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) {\n      *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) |\n\t\t   ((tv->u32.hi >> 12) & 0x00080000) |\n\t\t   ((tv->u32.hi >> 4) & 0x00070000) |\n\t\t   ((tv->u32.hi >> 16) & 0x0000000f);\n      return;\n    }\n  }\n  i = i32ptr(tv);\n  emit_vlso(as, ARMI_VLDR_D, r,\n\t    ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020));\n}\n#endif\n\n/* Get/set global_State fields. */\n#define emit_getgl(as, r, field) \\\n  emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field)\n#define emit_setgl(as, r, field) \\\n  emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field)\n\n/* Trace number is determined from pc of exit instruction. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_branch(ASMState *as, ARMIns ai, MCode *target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = (target - p) - 1;\n  lua_assert(((delta + 0x00800000) >> 24) == 0);\n  *--p = ai | ((uint32_t)delta & 0x00ffffffu);\n  as->mcp = p;\n}\n\n#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target))\n\nstatic void emit_call(ASMState *as, void *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = ((char *)target - (char *)p) - 8;\n  if ((((delta>>2) + 0x00800000) >> 24) == 0) {\n    if ((delta & 1))\n      *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 27);\n    else\n      *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu);\n  } else {  /* Target out of range: need indirect call. But don't use R0-R3. */\n    Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1));\n    *p = ARMI_BLXr | ARMF_M(r);\n  }\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n#if LJ_SOFTFP\n  lua_assert(!irt_isnum(ir->t)); UNUSED(ir);\n#else\n  if (dst >= RID_MAX_GPR) {\n    emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S,\n\t    (dst & 15), (src & 15));\n    return;\n  }\n#endif\n  if (as->mcp != as->mcloop) {  /* Swap early registers for loads/stores. */\n    MCode ins = *as->mcp, swp = (src^dst);\n    if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) {\n      if (!((ins ^ (dst << 16)) & 0x000f0000))\n\t*as->mcp = ins ^ (swp << 16);  /* Swap N in load/store. */\n      if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000))\n\t*as->mcp = ins ^ (swp << 12);  /* Swap D in store. */\n    }\n  }\n  emit_dm(as, ARMI_MOV, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n#if LJ_SOFTFP\n  lua_assert(!irt_isnum(ir->t)); UNUSED(ir);\n#else\n  if (r >= RID_MAX_GPR)\n    emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, base, ofs);\n  else\n#endif\n    emit_lso(as, ARMI_LDR, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n#if LJ_SOFTFP\n  lua_assert(!irt_isnum(ir->t)); UNUSED(ir);\n#else\n  if (r >= RID_MAX_GPR)\n    emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, base, ofs);\n  else\n#endif\n    emit_lso(as, ARMI_STR, r, base, ofs);\n}\n\n/* Emit an arithmetic/logic operation with a constant operand. */\nstatic void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src,\n\t\t     int32_t i, RegSet allow)\n{\n  uint32_t k = emit_isk12(ai, i);\n  if (k)\n    emit_dn(as, ai^k, dest, src);\n  else\n    emit_dnm(as, ai, dest, src, ra_allock(as, i, allow));\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs)\n    emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r));\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_SP, -(ofs))\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_emit_mips.h",
    "content": "/*\n** MIPS instruction emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt)\n{\n  *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt);\n}\n\nstatic void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a)\n{\n  *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a);\n}\n\n#define emit_ds(as, mi, rd, rs)\t\temit_dst(as, (mi), (rd), (rs), 0)\n#define emit_tg(as, mi, rt, rg)\t\temit_dst(as, (mi), (rg)&31, 0, (rt))\n\nstatic void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i)\n{\n  *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff);\n}\n\n#define emit_ti(as, mi, rt, i)\t\temit_tsi(as, (mi), (rt), 0, (i))\n#define emit_hsi(as, mi, rh, rs, i)\temit_tsi(as, (mi), (rh) & 31, (rs), (i))\n\nstatic void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh)\n{\n  *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31);\n}\n\n#define emit_fg(as, mi, rf, rg)\t\temit_fgh(as, (mi), (rf), (rg), 0)\n\nstatic void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift)\n{\n  if ((as->flags & JIT_F_MIPS32R2)) {\n    emit_dta(as, MIPSI_ROTR, dest, src, shift);\n  } else {\n    emit_dst(as, MIPSI_OR, dest, dest, tmp);\n    emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31);\n    emit_dta(as, MIPSI_SRL, tmp, src, shift);\n  }\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg t, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lua_assert(r != t);\n    if (ref < ASMREF_L) {\n      int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);\n      if (checki16(delta)) {\n\temit_tsi(as, MIPSI_ADDIU, t, r, delta);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  if (checki16(i)) {\n    emit_ti(as, MIPSI_LI, r, i);\n  } else {\n    if ((i & 0xffff)) {\n      int32_t jgl = i32ptr(J2G(as->J));\n      if ((uint32_t)(i-jgl) < 65536) {\n\temit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768);\n\treturn;\n      } else if (emit_kdelta1(as, r, i)) {\n\treturn;\n      } else if ((i >> 16) == 0) {\n\temit_tsi(as, MIPSI_ORI, r, RID_ZERO, i);\n\treturn;\n      }\n      emit_tsi(as, MIPSI_ORI, r, r, i);\n    }\n    emit_ti(as, MIPSI_LUI, r, (i >> 16));\n  }\n}\n\n#define emit_loada(as, r, addr)\t\temit_loadi(as, (r), i32ptr((addr)))\n\nstatic Reg ra_allock(ASMState *as, int32_t k, RegSet allow);\nstatic void ra_allockreg(ASMState *as, int32_t k, Reg r);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow)\n{\n  int32_t jgl = i32ptr(J2G(as->J));\n  int32_t i = i32ptr(p);\n  Reg base;\n  if ((uint32_t)(i-jgl) < 65536) {\n    i = i-jgl-32768;\n    base = RID_JGL;\n  } else {\n    base = ra_allock(as, i-(int16_t)i, allow);\n  }\n  emit_tsi(as, mi, r, base, i);\n}\n\n#define emit_loadn(as, r, tv) \\\n  emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)(tv), RSET_GPR)\n\n/* Get/set global_State fields. */\nstatic void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs)\n{\n  emit_tsi(as, mi, r, RID_JGL, ofs-32768);\n}\n\n#define emit_getgl(as, r, field) \\\n  emit_lsglptr(as, MIPSI_LW, (r), (int32_t)offsetof(global_State, field))\n#define emit_setgl(as, r, field) \\\n  emit_lsglptr(as, MIPSI_SW, (r), (int32_t)offsetof(global_State, field))\n\n/* Trace number is determined from per-trace exit stubs. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lua_assert(((delta + 0x8000) >> 16) == 0);\n  *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu);\n  as->mcp = p;\n}\n\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  *--as->mcp = MIPSI_NOP;\n  emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target));\n}\n\nstatic void emit_call(ASMState *as, void *target, int needcfa)\n{\n  MCode *p = as->mcp;\n  *--p = MIPSI_NOP;\n  if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0) {\n    *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu);\n  } else {  /* Target out of range: need indirect call. */\n    *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR);\n    needcfa = 1;\n  }\n  as->mcp = p;\n  if (needcfa) ra_allockreg(as, i32ptr(target), RID_CFUNCADDR);\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n#define emit_move(as, dst, src) \\\n  emit_ds(as, MIPSI_MOVE, (dst), (src))\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  if (dst < RID_MAX_GPR)\n    emit_move(as, dst, src);\n  else\n    emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tsi(as, MIPSI_LW, r, base, ofs);\n  else\n    emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1,\n\t     (r & 31), base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tsi(as, MIPSI_SW, r, base, ofs);\n  else\n    emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1,\n\t     (r&31), base, ofs);\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    lua_assert(checki16(ofs));\n    emit_tsi(as, MIPSI_ADDIU, r, r, ofs);\n  }\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_SP, -(ofs))\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_emit_ppc.h",
    "content": "/*\n** PPC instruction emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb)\n{\n  *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb);\n}\n\n#define emit_asb(as, pi, ra, rs, rb)\temit_tab(as, (pi), (rs), (ra), (rb))\n#define emit_as(as, pi, ra, rs)\t\temit_tab(as, (pi), (rs), (ra), 0)\n#define emit_ab(as, pi, ra, rb)\t\temit_tab(as, (pi), 0, (ra), (rb))\n\nstatic void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i)\n{\n  *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff);\n}\n\n#define emit_ti(as, pi, rt, i)\t\temit_tai(as, (pi), (rt), 0, (i))\n#define emit_ai(as, pi, ra, i)\t\temit_tai(as, (pi), 0, (ra), (i))\n#define emit_asi(as, pi, ra, rs, i)\temit_tai(as, (pi), (rs), (ra), (i))\n\n#define emit_fab(as, pi, rf, ra, rb) \\\n  emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31)\n#define emit_fb(as, pi, rf, rb)\t\temit_tab(as, (pi), (rf)&31, 0, (rb)&31)\n#define emit_fac(as, pi, rf, ra, rc) \\\n  emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0)\n#define emit_facb(as, pi, rf, ra, rc, rb) \\\n  emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31)\n#define emit_fai(as, pi, rf, ra, i)\temit_tai(as, (pi), (rf)&31, (ra), (i))\n\nstatic void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs,\n\t\t     int32_t n, int32_t b, int32_t e)\n{\n  *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) |\n\t       PPCF_MB(b) | PPCF_ME(e);\n}\n\nstatic void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n)\n{\n  lua_assert(n >= 0 && n < 32);\n  emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n);\n}\n\nstatic void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n)\n{\n  lua_assert(n >= 0 && n < 32);\n  emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31);\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg t, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lua_assert(r != t);\n    if (ref < ASMREF_L) {\n      int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);\n      if (checki16(delta)) {\n\temit_tai(as, PPCI_ADDI, t, r, delta);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  if (checki16(i)) {\n    emit_ti(as, PPCI_LI, r, i);\n  } else {\n    if ((i & 0xffff)) {\n      int32_t jgl = i32ptr(J2G(as->J));\n      if ((uint32_t)(i-jgl) < 65536) {\n\temit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768);\n\treturn;\n      } else if (emit_kdelta1(as, r, i)) {\n\treturn;\n      }\n      emit_asi(as, PPCI_ORI, r, r, i);\n    }\n    emit_ti(as, PPCI_LIS, r, (i >> 16));\n  }\n}\n\n#define emit_loada(as, r, addr)\t\temit_loadi(as, (r), i32ptr((addr)))\n\nstatic Reg ra_allock(ASMState *as, int32_t k, RegSet allow);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow)\n{\n  int32_t jgl = i32ptr(J2G(as->J));\n  int32_t i = i32ptr(p);\n  Reg base;\n  if ((uint32_t)(i-jgl) < 65536) {\n    i = i-jgl-32768;\n    base = RID_JGL;\n  } else {\n    base = ra_allock(as, i-(int16_t)i, allow);\n  }\n  emit_tai(as, pi, r, base, i);\n}\n\n#define emit_loadn(as, r, tv) \\\n  emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)(tv), RSET_GPR)\n\n/* Get/set global_State fields. */\nstatic void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs)\n{\n  emit_tai(as, pi, r, RID_JGL, ofs-32768);\n}\n\n#define emit_getgl(as, r, field) \\\n  emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field))\n#define emit_setgl(as, r, field) \\\n  emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field))\n\n/* Trace number is determined from per-trace exit stubs. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  lua_assert(((delta + 0x8000) >> 16) == 0);\n  pi ^= (delta & 0x8000) * (PPCF_Y/0x8000);\n  *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu);\n}\n\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  *p = PPCI_B | (delta & 0x03fffffcu);\n}\n\nstatic void emit_call(ASMState *as, void *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  if ((((delta>>2) + 0x00800000) >> 24) == 0) {\n    *p = PPCI_BL | (delta & 0x03fffffcu);\n  } else {  /* Target out of range: need indirect call. Don't use arg reg. */\n    RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);\n    Reg r = ra_allock(as, i32ptr(target), allow);\n    *p = PPCI_BCTRL;\n    p[-1] = PPCI_MTCTR | PPCF_T(r);\n    as->mcp = p-1;\n  }\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n#define emit_mr(as, dst, src) \\\n  emit_asb(as, PPCI_MR, (dst), (src), (src))\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  UNUSED(ir);\n  if (dst < RID_MAX_GPR)\n    emit_mr(as, dst, src);\n  else\n    emit_fb(as, PPCI_FMR, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tai(as, PPCI_LWZ, r, base, ofs);\n  else\n    emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tai(as, PPCI_STW, r, base, ofs);\n  else\n    emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, base, ofs);\n}\n\n/* Emit a compare (for equality) with a constant operand. */\nstatic void emit_cmpi(ASMState *as, Reg r, int32_t k)\n{\n  if (checki16(k)) {\n    emit_ai(as, PPCI_CMPWI, r, k);\n  } else if (checku16(k)) {\n    emit_ai(as, PPCI_CMPLWI, r, k);\n  } else {\n    emit_ai(as, PPCI_CMPLWI, RID_TMP, k);\n    emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16));\n  }\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    emit_tai(as, PPCI_ADDI, r, r, ofs);\n    if (!checki16(ofs))\n      emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16);\n  }\n}\n\nstatic void emit_spsub(ASMState *as, int32_t ofs)\n{\n  if (ofs) {\n    emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs);\n    emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP,\n\t     CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0));\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_emit_x86.h",
    "content": "/*\n** x86/x64 instruction emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Emit basic instructions --------------------------------------------- */\n\n#define MODRM(mode, r1, r2)\t((MCode)((mode)+(((r1)&7)<<3)+((r2)&7)))\n\n#if LJ_64\n#define REXRB(p, rr, rb) \\\n    { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \\\n      if (rex != 0x40) *--(p) = rex; }\n#define FORCE_REX\t\t0x200\n#define REX_64\t\t\t(FORCE_REX|0x080000)\n#else\n#define REXRB(p, rr, rb)\t((void)0)\n#define FORCE_REX\t\t0\n#define REX_64\t\t\t0\n#endif\n\n#define emit_i8(as, i)\t\t(*--as->mcp = (MCode)(i))\n#define emit_i32(as, i)\t\t(*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4)\n#define emit_u32(as, u)\t\t(*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4)\n\n#define emit_x87op(as, xo) \\\n  (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2)\n\n/* op */\nstatic LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx,\n\t\t\t\t MCode *p, int delta)\n{\n  int n = (int8_t)xo;\n#if defined(__GNUC__)\n  if (__builtin_constant_p(xo) && n == -2)\n    p[delta-2] = (MCode)(xo >> 24);\n  else if (__builtin_constant_p(xo) && n == -3)\n    *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16);\n  else\n#endif\n    *(uint32_t *)(p+delta-5) = (uint32_t)xo;\n  p += n + delta;\n#if LJ_64\n  {\n    uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1);\n    if (rex != 0x40) {\n      rex |= (rr >> 16);\n      if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); }\n      else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; }\n      *--p = (MCode)rex;\n    }\n  }\n#else\n  UNUSED(rr); UNUSED(rb); UNUSED(rx);\n#endif\n  return p;\n}\n\n/* op + modrm */\n#define emit_opm(xo, mode, rr, rb, p, delta) \\\n  (p[(delta)-1] = MODRM((mode), (rr), (rb)), \\\n   emit_op((xo), (rr), (rb), 0, (p), (delta)))\n\n/* op + modrm + sib */\n#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \\\n  (p[-1] = MODRM((scale), (rx), (rb)), \\\n   p[-2] = MODRM((mode), (rr), RID_ESP), \\\n   emit_op((xo), (rr), (rb), (rx), (p), -1))\n\n/* op r1, r2 */\nstatic void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2)\n{\n  MCode *p = as->mcp;\n  as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0);\n}\n\n#if LJ_64 && defined(LUA_USE_ASSERT)\n/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */\nstatic int32_t ptr2addr(const void *p)\n{\n  lua_assert((uintptr_t)p < (uintptr_t)0x80000000);\n  return i32ptr(p);\n}\n#else\n#define ptr2addr(p)\t(i32ptr((p)))\n#endif\n\n/* op r, [addr] */\nstatic void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr)\n{\n  MCode *p = as->mcp;\n  *(int32_t *)(p-4) = ptr2addr(addr);\n#if LJ_64\n  p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n  as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5);\n#else\n  as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4);\n#endif\n}\n\n/* op r, [base+ofs] */\nstatic void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs)\n{\n  MCode *p = as->mcp;\n  x86Mode mode;\n  if (ra_hasreg(rb)) {\n    if (ofs == 0 && (rb&7) != RID_EBP) {\n      mode = XM_OFS0;\n    } else if (checki8(ofs)) {\n      *--p = (MCode)ofs;\n      mode = XM_OFS8;\n    } else {\n      p -= 4;\n      *(int32_t *)p = ofs;\n      mode = XM_OFS32;\n    }\n    if ((rb&7) == RID_ESP)\n      *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n  } else {\n    *(int32_t *)(p-4) = ofs;\n#if LJ_64\n    p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n    p -= 5;\n    rb = RID_ESP;\n#else\n    p -= 4;\n    rb = RID_EBP;\n#endif\n    mode = XM_OFS0;\n  }\n  as->mcp = emit_opm(xo, mode, rr, rb, p, 0);\n}\n\n/* op r, [base+idx*scale+ofs] */\nstatic void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx,\n\t\t       x86Mode scale, int32_t ofs)\n{\n  MCode *p = as->mcp;\n  x86Mode mode;\n  if (ofs == 0 && (rb&7) != RID_EBP) {\n    mode = XM_OFS0;\n  } else if (checki8(ofs)) {\n    mode = XM_OFS8;\n    *--p = (MCode)ofs;\n  } else {\n    mode = XM_OFS32;\n    p -= 4;\n    *(int32_t *)p = ofs;\n  }\n  as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p);\n}\n\n/* op r, i */\nstatic void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i)\n{\n  MCode *p = as->mcp;\n  x86Op xo;\n  if (checki8(i)) {\n    *--p = (MCode)i;\n    xo = XG_TOXOi8(xg);\n  } else {\n    p -= 4;\n    *(int32_t *)p = i;\n    xo = XG_TOXOi(xg);\n  }\n  as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0);\n}\n\n/* op [base+ofs], i */\nstatic void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs,\n\t\t       int32_t i)\n{\n  x86Op xo;\n  if (checki8(i)) {\n    emit_i8(as, i);\n    xo = XG_TOXOi8(xg);\n  } else {\n    emit_i32(as, i);\n    xo = XG_TOXOi(xg);\n  }\n  emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs);\n}\n\n#define emit_shifti(as, xg, r, i) \\\n  (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r)))\n\n/* op r, rm/mrm */\nstatic void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb)\n{\n  MCode *p = as->mcp;\n  x86Mode mode = XM_REG;\n  if (rb == RID_MRM) {\n    rb = as->mrm.base;\n    if (rb == RID_NONE) {\n      rb = RID_EBP;\n      mode = XM_OFS0;\n      p -= 4;\n      *(int32_t *)p = as->mrm.ofs;\n      if (as->mrm.idx != RID_NONE)\n\tgoto mrmidx;\n#if LJ_64\n      *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n      rb = RID_ESP;\n#endif\n    } else {\n      if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) {\n\tmode = XM_OFS0;\n      } else if (checki8(as->mrm.ofs)) {\n\t*--p = (MCode)as->mrm.ofs;\n\tmode = XM_OFS8;\n      } else {\n\tp -= 4;\n\t*(int32_t *)p = as->mrm.ofs;\n\tmode = XM_OFS32;\n      }\n      if (as->mrm.idx != RID_NONE) {\n      mrmidx:\n\tas->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p);\n\treturn;\n      }\n      if ((rb&7) == RID_ESP)\n\t*--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n    }\n  }\n  as->mcp = emit_opm(xo, mode, rr, rb, p, 0);\n}\n\n/* op rm/mrm, i */\nstatic void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i)\n{\n  x86Op xo;\n  if (checki8(i)) {\n    emit_i8(as, i);\n    xo = XG_TOXOi8(xg);\n  } else {\n    emit_i32(as, i);\n    xo = XG_TOXOi(xg);\n  }\n  emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64));\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* mov [base+ofs], i */\nstatic void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i)\n{\n  emit_i32(as, i);\n  emit_rmro(as, XO_MOVmi, 0, base, ofs);\n}\n\n/* mov [base+ofs], r */\n#define emit_movtomro(as, r, base, ofs) \\\n  emit_rmro(as, XO_MOVto, (r), (base), (ofs))\n\n/* Get/set global_State fields. */\n#define emit_opgl(as, xo, r, field) \\\n  emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field)\n#define emit_getgl(as, r, field)\temit_opgl(as, XO_MOV, (r), field)\n#define emit_setgl(as, r, field)\temit_opgl(as, XO_MOVto, (r), field)\n\n#define emit_setvmstate(as, i) \\\n  (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate))\n\n/* mov r, i / xor r, r */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP. */\n  if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP ||\n\t\t\t    (as->curins+1 < as->T->nins &&\n\t\t\t     IR(as->curins+1)->o == IR_HIOP)))) {\n    emit_rr(as, XO_ARITH(XOg_XOR), r, r);\n  } else {\n    MCode *p = as->mcp;\n    *(int32_t *)(p-4) = i;\n    p[-5] = (MCode)(XI_MOVri+(r&7));\n    p -= 5;\n    REXRB(p, 0, r);\n    as->mcp = p;\n  }\n}\n\n/* mov r, addr */\n#define emit_loada(as, r, addr) \\\n  emit_loadi(as, (r), ptr2addr((addr)))\n\n#if LJ_64\n/* mov r, imm64 or shorter 32 bit extended load. */\nstatic void emit_loadu64(ASMState *as, Reg r, uint64_t u64)\n{\n  if (checku32(u64)) {  /* 32 bit load clears upper 32 bits. */\n    emit_loadi(as, r, (int32_t)u64);\n  } else if (checki32((int64_t)u64)) {  /* Sign-extended 32 bit load. */\n    MCode *p = as->mcp;\n    *(int32_t *)(p-4) = (int32_t)u64;\n    as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4);\n  } else {  /* Full-size 64 bit load. */\n    MCode *p = as->mcp;\n    *(uint64_t *)(p-8) = u64;\n    p[-9] = (MCode)(XI_MOVri+(r&7));\n    p[-10] = 0x48 + ((r>>3)&1);\n    p -= 10;\n    as->mcp = p;\n  }\n}\n#endif\n\n/* movsd r, [&tv->n] / xorps r, r */\nstatic void emit_loadn(ASMState *as, Reg r, cTValue *tv)\n{\n  if (tvispzero(tv))  /* Use xor only for +0. */\n    emit_rr(as, XO_XORPS, r, r);\n  else\n    emit_rma(as, XO_MOVSD, r, &tv->n);\n}\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for short jumps. */\ntypedef MCode *MCLabel;\n\n#if LJ_32 && LJ_HASFFI\n/* jmp short target */\nstatic void emit_sjmp(ASMState *as, MCLabel target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lua_assert(delta == (int8_t)delta);\n  p[-1] = (MCode)(int8_t)delta;\n  p[-2] = XI_JMPs;\n  as->mcp = p - 2;\n}\n#endif\n\n/* jcc short target */\nstatic void emit_sjcc(ASMState *as, int cc, MCLabel target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lua_assert(delta == (int8_t)delta);\n  p[-1] = (MCode)(int8_t)delta;\n  p[-2] = (MCode)(XI_JCCs+(cc&15));\n  as->mcp = p - 2;\n}\n\n/* jcc short (pending target) */\nstatic MCLabel emit_sjcc_label(ASMState *as, int cc)\n{\n  MCode *p = as->mcp;\n  p[-1] = 0;\n  p[-2] = (MCode)(XI_JCCs+(cc&15));\n  as->mcp = p - 2;\n  return p;\n}\n\n/* Fixup jcc short target. */\nstatic void emit_sfixup(ASMState *as, MCLabel source)\n{\n  source[-1] = (MCode)(as->mcp-source);\n}\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\n/* Compute relative 32 bit offset for jump and call instructions. */\nstatic LJ_AINLINE int32_t jmprel(MCode *p, MCode *target)\n{\n  ptrdiff_t delta = target - p;\n  lua_assert(delta == (int32_t)delta);\n  return (int32_t)delta;\n}\n\n/* jcc target */\nstatic void emit_jcc(ASMState *as, int cc, MCode *target)\n{\n  MCode *p = as->mcp;\n  *(int32_t *)(p-4) = jmprel(p, target);\n  p[-5] = (MCode)(XI_JCCn+(cc&15));\n  p[-6] = 0x0f;\n  as->mcp = p - 6;\n}\n\n/* jmp target */\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  MCode *p = as->mcp;\n  *(int32_t *)(p-4) = jmprel(p, target);\n  p[-5] = XI_JMP;\n  as->mcp = p - 5;\n}\n\n/* call target */\nstatic void emit_call_(ASMState *as, MCode *target)\n{\n  MCode *p = as->mcp;\n#if LJ_64\n  if (target-p != (int32_t)(target-p)) {\n    /* Assumes RID_RET is never an argument to calls and always clobbered. */\n    emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET);\n    emit_loadu64(as, RID_RET, (uint64_t)target);\n    return;\n  }\n#endif\n  *(int32_t *)(p-4) = jmprel(p, target);\n  p[-5] = XI_CALL;\n  as->mcp = p - 5;\n}\n\n#define emit_call(as, f)\temit_call_(as, (MCode *)(void *)(f))\n\n/* -- Emit generic operations --------------------------------------------- */\n\n/* Use 64 bit operations to handle 64 bit IR types. */\n#if LJ_64\n#define REX_64IR(ir, r)\t\t((r) + (irt_is64((ir)->t) ? REX_64 : 0))\n#else\n#define REX_64IR(ir, r)\t\t(r)\n#endif\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  UNUSED(ir);\n  if (dst < RID_MAX_GPR)\n    emit_rr(as, XO_MOV, REX_64IR(ir, dst), src);\n  else\n    emit_rr(as, XO_MOVAPS, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_rmro(as, XO_MOV, REX_64IR(ir, r), base, ofs);\n  else\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_rmro(as, XO_MOVto, REX_64IR(ir, r), base, ofs);\n  else\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, base, ofs);\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    if ((as->flags & JIT_F_LEA_AGU))\n      emit_rmro(as, XO_LEA, r, r, ofs);\n    else\n      emit_gri(as, XG_ARITHi(XOg_ADD), r, ofs);\n  }\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_ESP|REX_64, -(ofs))\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_err.c",
    "content": "/*\n** Error handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_err_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_func.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_ff.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strfmt.h\"\n\n/*\n** LuaJIT can either use internal or external frame unwinding:\n**\n** - Internal frame unwinding (INT) is free-standing and doesn't require\n**   any OS or library support.\n**\n** - External frame unwinding (EXT) uses the system-provided unwind handler.\n**\n** Pros and Cons:\n**\n** - EXT requires unwind tables for *all* functions on the C stack between\n**   the pcall/catch and the error/throw. This is the default on x64,\n**   but needs to be manually enabled on x86/PPC for non-C++ code.\n**\n** - INT is faster when actually throwing errors (but this happens rarely).\n**   Setting up error handlers is zero-cost in any case.\n**\n** - EXT provides full interoperability with C++ exceptions. You can throw\n**   Lua errors or C++ exceptions through a mix of Lua frames and C++ frames.\n**   C++ destructors are called as needed. C++ exceptions caught by pcall\n**   are converted to the string \"C++ exception\". Lua errors can be caught\n**   with catch (...) in C++.\n**\n** - INT has only limited support for automatically catching C++ exceptions\n**   on POSIX systems using DWARF2 stack unwinding. Other systems may use\n**   the wrapper function feature. Lua errors thrown through C++ frames\n**   cannot be caught by C++ code and C++ destructors are not run.\n**\n** EXT is the default on x64 systems, INT is the default on all other systems.\n**\n** EXT can be manually enabled on POSIX systems using GCC and DWARF2 stack\n** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled\n** with -funwind-tables (or -fexceptions). This includes LuaJIT itself (set\n** TARGET_CFLAGS), all of your C/Lua binding code, all loadable C modules\n** and all C libraries that have callbacks which may be used to call back\n** into Lua. C++ code must *not* be compiled with -fno-exceptions.\n**\n** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH.\n** EXT is mandatory on WIN64 since the calling convention has an abundance\n** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15).\n** The POSIX/x64 interpreter only saves r12/r13 for INT (e.g. PS4).\n*/\n\n#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND\n#define LJ_UNWIND_EXT\t1\n#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS\n#define LJ_UNWIND_EXT\t1\n#endif\n\n/* -- Error messages ------------------------------------------------------ */\n\n/* Error message strings. */\nLJ_DATADEF const char *lj_err_allmsg =\n#define ERRDEF(name, msg)\tmsg \"\\0\"\n#include \"lj_errmsg.h\"\n;\n\n/* -- Internal frame unwinding -------------------------------------------- */\n\n/* Unwind Lua stack and move error message to new top. */\nLJ_NOINLINE static void unwindstack(lua_State *L, TValue *top)\n{\n  lj_func_closeuv(L, top);\n  if (top < L->top-1) {\n    copyTV(L, top, L->top-1);\n    L->top = top+1;\n  }\n  lj_state_relimitstack(L);\n}\n\n/* Unwind until stop frame. Optionally cleanup frames. */\nstatic void *err_unwind(lua_State *L, void *stopcf, int errcode)\n{\n  TValue *frame = L->base-1;\n  void *cf = L->cframe;\n  while (cf) {\n    int32_t nres = cframe_nres(cframe_raw(cf));\n    if (nres < 0) {  /* C frame without Lua frame? */\n      TValue *top = restorestack(L, -nres);\n      if (frame < top) {  /* Frame reached? */\n\tif (errcode) {\n\t  L->base = frame+1;\n\t  L->cframe = cframe_prev(cf);\n\t  unwindstack(L, top);\n\t}\n\treturn cf;\n      }\n    }\n    if (frame <= tvref(L->stack)+LJ_FR2)\n      break;\n    switch (frame_typep(frame)) {\n    case FRAME_LUA:  /* Lua frame. */\n    case FRAME_LUAP:\n      frame = frame_prevl(frame);\n      break;\n    case FRAME_C:  /* C frame. */\n    unwind_c:\n#if LJ_UNWIND_EXT\n      if (errcode) {\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cframe_prev(cf);\n\tunwindstack(L, frame - LJ_FR2);\n      } else if (cf != stopcf) {\n\tcf = cframe_prev(cf);\n\tframe = frame_prevd(frame);\n\tbreak;\n      }\n      return NULL;  /* Continue unwinding. */\n#else\n      UNUSED(stopcf);\n      cf = cframe_prev(cf);\n      frame = frame_prevd(frame);\n      break;\n#endif\n    case FRAME_CP:  /* Protected C frame. */\n      if (cframe_canyield(cf)) {  /* Resume? */\n\tif (errcode) {\n\t  hook_leave(G(L));  /* Assumes nobody uses coroutines inside hooks. */\n\t  L->cframe = NULL;\n\t  L->status = (uint8_t)errcode;\n\t}\n\treturn cf;\n      }\n      if (errcode) {\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cframe_prev(cf);\n\tunwindstack(L, frame - LJ_FR2);\n      }\n      return cf;\n    case FRAME_CONT:  /* Continuation frame. */\n      if (frame_iscont_fficb(frame))\n\tgoto unwind_c;\n    case FRAME_VARG:  /* Vararg frame. */\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_PCALL:  /* FF pcall() frame. */\n    case FRAME_PCALLH:  /* FF pcall() frame inside hook. */\n      if (errcode) {\n\tif (errcode == LUA_YIELD) {\n\t  frame = frame_prevd(frame);\n\t  break;\n\t}\n\tif (frame_typep(frame) == FRAME_PCALL)\n\t  hook_leave(G(L));\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cf;\n\tunwindstack(L, L->base);\n      }\n      return (void *)((intptr_t)cf | CFRAME_UNWIND_FF);\n    }\n  }\n  /* No C frame. */\n  if (errcode) {\n    L->base = tvref(L->stack)+1+LJ_FR2;\n    L->cframe = NULL;\n    unwindstack(L, L->base);\n    if (G(L)->panic)\n      G(L)->panic(L);\n    exit(EXIT_FAILURE);\n  }\n  return L;  /* Anything non-NULL will do. */\n}\n\n/* -- External frame unwinding -------------------------------------------- */\n\n#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_ABI_WIN\n\n/*\n** We have to use our own definitions instead of the mandatory (!) unwind.h,\n** since various OS, distros and compilers mess up the header installation.\n*/\n\ntypedef struct _Unwind_Context _Unwind_Context;\n\n#define _URC_OK\t\t\t0\n#define _URC_FATAL_PHASE1_ERROR\t3\n#define _URC_HANDLER_FOUND\t6\n#define _URC_INSTALL_CONTEXT\t7\n#define _URC_CONTINUE_UNWIND\t8\n#define _URC_FAILURE\t\t9\n\n#define LJ_UEXCLASS\t\t0x4c55414a49543200ULL\t/* LUAJIT2\\0 */\n#define LJ_UEXCLASS_MAKE(c)\t(LJ_UEXCLASS | (uint64_t)(c))\n#define LJ_UEXCLASS_CHECK(cl)\t(((cl) ^ LJ_UEXCLASS) <= 0xff)\n#define LJ_UEXCLASS_ERRCODE(cl)\t((int)((cl) & 0xff))\n\n#if !LJ_TARGET_ARM\n\ntypedef struct _Unwind_Exception\n{\n  uint64_t exclass;\n  void (*excleanup)(int, struct _Unwind_Exception *);\n  uintptr_t p1, p2;\n} __attribute__((__aligned__)) _Unwind_Exception;\n\nextern uintptr_t _Unwind_GetCFA(_Unwind_Context *);\nextern void _Unwind_SetGR(_Unwind_Context *, int, uintptr_t);\nextern void _Unwind_SetIP(_Unwind_Context *, uintptr_t);\nextern void _Unwind_DeleteException(_Unwind_Exception *);\nextern int _Unwind_RaiseException(_Unwind_Exception *);\n\n#define _UA_SEARCH_PHASE\t1\n#define _UA_CLEANUP_PHASE\t2\n#define _UA_HANDLER_FRAME\t4\n#define _UA_FORCE_UNWIND\t8\n\n/* DWARF2 personality handler referenced from interpreter .eh_frame. */\nLJ_FUNCA int lj_err_unwind_dwarf(int version, int actions,\n  uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx)\n{\n  void *cf;\n  lua_State *L;\n  if (version != 1)\n    return _URC_FATAL_PHASE1_ERROR;\n  UNUSED(uexclass);\n  cf = (void *)_Unwind_GetCFA(ctx);\n  L = cframe_L(cf);\n  if ((actions & _UA_SEARCH_PHASE)) {\n#if LJ_UNWIND_EXT\n    if (err_unwind(L, cf, 0) == NULL)\n      return _URC_CONTINUE_UNWIND;\n#endif\n    if (!LJ_UEXCLASS_CHECK(uexclass)) {\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n    }\n    return _URC_HANDLER_FOUND;\n  }\n  if ((actions & _UA_CLEANUP_PHASE)) {\n    int errcode;\n    if (LJ_UEXCLASS_CHECK(uexclass)) {\n      errcode = LJ_UEXCLASS_ERRCODE(uexclass);\n    } else {\n      if ((actions & _UA_HANDLER_FRAME))\n\t_Unwind_DeleteException(uex);\n      errcode = LUA_ERRRUN;\n    }\n#if LJ_UNWIND_EXT\n    cf = err_unwind(L, cf, errcode);\n    if ((actions & _UA_FORCE_UNWIND)) {\n      return _URC_CONTINUE_UNWIND;\n    } else if (cf) {\n      _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);\n      _Unwind_SetIP(ctx, (uintptr_t)(cframe_unwind_ff(cf) ?\n\t\t\t\t     lj_vm_unwind_ff_eh :\n\t\t\t\t     lj_vm_unwind_c_eh));\n      return _URC_INSTALL_CONTEXT;\n    }\n#if LJ_TARGET_X86ORX64\n    else if ((actions & _UA_HANDLER_FRAME)) {\n      /* Workaround for ancient libgcc bug. Still present in RHEL 5.5. :-/\n      ** Real fix: http://gcc.gnu.org/viewcvs/trunk/gcc/unwind-dw2.c?r1=121165&r2=124837&pathrev=153877&diff_format=h\n      */\n      _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);\n      _Unwind_SetIP(ctx, (uintptr_t)lj_vm_unwind_rethrow);\n      return _URC_INSTALL_CONTEXT;\n    }\n#endif\n#else\n    /* This is not the proper way to escape from the unwinder. We get away with\n    ** it on non-x64 because the interpreter restores all callee-saved regs.\n    */\n    lj_err_throw(L, errcode);\n#endif\n  }\n  return _URC_CONTINUE_UNWIND;\n}\n\n#if LJ_UNWIND_EXT\n#if LJ_TARGET_OSX || defined(__OpenBSD__)\n/* Sorry, no thread safety for OSX. Complain to Apple, not me. */\nstatic _Unwind_Exception static_uex;\n#else\nstatic __thread _Unwind_Exception static_uex;\n#endif\n\n/* Raise DWARF2 exception. */\nstatic void err_raise_ext(int errcode)\n{\n  static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);\n  static_uex.excleanup = NULL;\n  _Unwind_RaiseException(&static_uex);\n}\n#endif\n\n#else /* LJ_TARGET_ARM */\n\n#define _US_VIRTUAL_UNWIND_FRAME\t0\n#define _US_UNWIND_FRAME_STARTING\t1\n#define _US_ACTION_MASK\t\t\t3\n#define _US_FORCE_UNWIND\t\t8\n\ntypedef struct _Unwind_Control_Block _Unwind_Control_Block;\ntypedef struct _Unwind_Context _Unwind_Context;\n\nstruct _Unwind_Control_Block {\n  uint64_t exclass;\n  uint32_t misc[20];\n};\n\nextern int _Unwind_RaiseException(_Unwind_Control_Block *);\nextern int __gnu_unwind_frame(_Unwind_Control_Block *, _Unwind_Context *);\nextern int _Unwind_VRS_Set(_Unwind_Context *, int, uint32_t, int, void *);\nextern int _Unwind_VRS_Get(_Unwind_Context *, int, uint32_t, int, void *);\n\nstatic inline uint32_t _Unwind_GetGR(_Unwind_Context *ctx, int r)\n{\n  uint32_t v;\n  _Unwind_VRS_Get(ctx, 0, r, 0, &v);\n  return v;\n}\n\nstatic inline void _Unwind_SetGR(_Unwind_Context *ctx, int r, uint32_t v)\n{\n  _Unwind_VRS_Set(ctx, 0, r, 0, &v);\n}\n\nextern void lj_vm_unwind_ext(void);\n\n/* ARM unwinder personality handler referenced from interpreter .ARM.extab. */\nLJ_FUNCA int lj_err_unwind_arm(int state, _Unwind_Control_Block *ucb,\n\t\t\t       _Unwind_Context *ctx)\n{\n  void *cf = (void *)_Unwind_GetGR(ctx, 13);\n  lua_State *L = cframe_L(cf);\n  int errcode;\n\n  switch ((state & _US_ACTION_MASK)) {\n  case _US_VIRTUAL_UNWIND_FRAME:\n    if ((state & _US_FORCE_UNWIND)) break;\n    return _URC_HANDLER_FOUND;\n  case _US_UNWIND_FRAME_STARTING:\n    if (LJ_UEXCLASS_CHECK(ucb->exclass)) {\n      errcode = LJ_UEXCLASS_ERRCODE(ucb->exclass);\n    } else {\n      errcode = LUA_ERRRUN;\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n    }\n    cf = err_unwind(L, cf, errcode);\n    if ((state & _US_FORCE_UNWIND) || cf == NULL) break;\n    _Unwind_SetGR(ctx, 15, (uint32_t)lj_vm_unwind_ext);\n    _Unwind_SetGR(ctx, 0, (uint32_t)ucb);\n    _Unwind_SetGR(ctx, 1, (uint32_t)errcode);\n    _Unwind_SetGR(ctx, 2, cframe_unwind_ff(cf) ?\n\t\t\t    (uint32_t)lj_vm_unwind_ff_eh :\n\t\t\t    (uint32_t)lj_vm_unwind_c_eh);\n    return _URC_INSTALL_CONTEXT;\n  default:\n    return _URC_FAILURE;\n  }\n  if (__gnu_unwind_frame(ucb, ctx) != _URC_OK)\n    return _URC_FAILURE;\n  return _URC_CONTINUE_UNWIND;\n}\n\n#if LJ_UNWIND_EXT\nstatic __thread _Unwind_Control_Block static_uex;\n\nstatic void err_raise_ext(int errcode)\n{\n  memset(&static_uex, 0, sizeof(static_uex));\n  static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);\n  _Unwind_RaiseException(&static_uex);\n}\n#endif\n\n#endif /* LJ_TARGET_ARM */\n\n#elif LJ_TARGET_X64 && LJ_ABI_WIN\n\n/*\n** Someone in Redmond owes me several days of my life. A lot of this is\n** undocumented or just plain wrong on MSDN. Some of it can be gathered\n** from 3rd party docs or must be found by trial-and-error. They really\n** don't want you to write your own language-specific exception handler\n** or to interact gracefully with MSVC. :-(\n**\n** Apparently MSVC doesn't call C++ destructors for foreign exceptions\n** unless you compile your C++ code with /EHa. Unfortunately this means\n** catch (...) also catches things like access violations. The use of\n** _set_se_translator doesn't really help, because it requires /EHa, too.\n*/\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n/* Taken from: http://www.nynaeve.net/?p=99 */\ntypedef struct UndocumentedDispatcherContext {\n  ULONG64 ControlPc;\n  ULONG64 ImageBase;\n  PRUNTIME_FUNCTION FunctionEntry;\n  ULONG64 EstablisherFrame;\n  ULONG64 TargetIp;\n  PCONTEXT ContextRecord;\n  void (*LanguageHandler)(void);\n  PVOID HandlerData;\n  PUNWIND_HISTORY_TABLE HistoryTable;\n  ULONG ScopeIndex;\n  ULONG Fill0;\n} UndocumentedDispatcherContext;\n\n/* Another wild guess. */\nextern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow);\n\n#ifdef MINGW_SDK_INIT\n/* Workaround for broken MinGW64 declaration. */\nVOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm(\"RtlUnwindEx\");\n#define RtlUnwindEx RtlUnwindEx_FIXED\n#endif\n\n#define LJ_MSVC_EXCODE\t\t((DWORD)0xe06d7363)\n#define LJ_GCC_EXCODE\t\t((DWORD)0x20474343)\n\n#define LJ_EXCODE\t\t((DWORD)0xe24c4a00)\n#define LJ_EXCODE_MAKE(c)\t(LJ_EXCODE | (DWORD)(c))\n#define LJ_EXCODE_CHECK(cl)\t(((cl) ^ LJ_EXCODE) <= 0xff)\n#define LJ_EXCODE_ERRCODE(cl)\t((int)((cl) & 0xff))\n\n/* Win64 exception handler for interpreter frame. */\nLJ_FUNCA EXCEPTION_DISPOSITION lj_err_unwind_win64(EXCEPTION_RECORD *rec,\n  void *cf, CONTEXT *ctx, UndocumentedDispatcherContext *dispatch)\n{\n  lua_State *L = cframe_L(cf);\n  int errcode = LJ_EXCODE_CHECK(rec->ExceptionCode) ?\n\t\tLJ_EXCODE_ERRCODE(rec->ExceptionCode) : LUA_ERRRUN;\n  if ((rec->ExceptionFlags & 6)) {  /* EH_UNWINDING|EH_EXIT_UNWIND */\n    /* Unwind internal frames. */\n    err_unwind(L, cf, errcode);\n  } else {\n    void *cf2 = err_unwind(L, cf, 0);\n    if (cf2) {  /* We catch it, so start unwinding the upper frames. */\n      if (rec->ExceptionCode == LJ_MSVC_EXCODE ||\n\t  rec->ExceptionCode == LJ_GCC_EXCODE) {\n#if LJ_TARGET_WINDOWS\n\t__DestructExceptionObject(rec, 1);\n#endif\n\tsetstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n      } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) {\n\t/* Don't catch access violations etc. */\n\treturn ExceptionContinueSearch;\n      }\n      /* Unwind the stack and call all handlers for all lower C frames\n      ** (including ourselves) again with EH_UNWINDING set. Then set\n      ** rsp = cf, rax = errcode and jump to the specified target.\n      */\n      RtlUnwindEx(cf, (void *)((cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ?\n\t\t\t       lj_vm_unwind_ff_eh :\n\t\t\t       lj_vm_unwind_c_eh),\n\t\t  rec, (void *)(uintptr_t)errcode, ctx, dispatch->HistoryTable);\n      /* RtlUnwindEx should never return. */\n    }\n  }\n  return ExceptionContinueSearch;\n}\n\n/* Raise Windows exception. */\nstatic void err_raise_ext(int errcode)\n{\n  RaiseException(LJ_EXCODE_MAKE(errcode), 1 /* EH_NONCONTINUABLE */, 0, NULL);\n}\n\n#endif\n\n/* -- Error handling ------------------------------------------------------ */\n\n/* Throw error. Find catch frame, unwind stack and continue. */\nLJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode)\n{\n  global_State *g = G(L);\n  lj_trace_abort(g);\n  setmref(g->jit_base, NULL);\n  L->status = 0;\n#if LJ_UNWIND_EXT\n  err_raise_ext(errcode);\n  /*\n  ** A return from this function signals a corrupt C stack that cannot be\n  ** unwound. We have no choice but to call the panic function and exit.\n  **\n  ** Usually this is caused by a C function without unwind information.\n  ** This should never happen on x64, but may happen if you've manually\n  ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every*\n  ** non-C++ file with -funwind-tables.\n  */\n  if (G(L)->panic)\n    G(L)->panic(L);\n#else\n  {\n    void *cf = err_unwind(L, NULL, errcode);\n    if (cframe_unwind_ff(cf))\n      lj_vm_unwind_ff(cframe_raw(cf));\n    else\n      lj_vm_unwind_c(cframe_raw(cf), errcode);\n  }\n#endif\n  exit(EXIT_FAILURE);\n}\n\n/* Return string object for error message. */\nLJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em)\n{\n  return lj_str_newz(L, err2msg(em));\n}\n\n/* Out-of-memory error. */\nLJ_NOINLINE void lj_err_mem(lua_State *L)\n{\n  if (L->status == LUA_ERRERR+1)  /* Don't touch the stack during lua_open. */\n    lj_vm_unwind_c(L->cframe, LUA_ERRMEM);\n  setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM));\n  lj_err_throw(L, LUA_ERRMEM);\n}\n\n/* Find error function for runtime errors. Requires an extra stack traversal. */\nstatic ptrdiff_t finderrfunc(lua_State *L)\n{\n  cTValue *frame = L->base-1, *bot = tvref(L->stack)+LJ_FR2;\n  void *cf = L->cframe;\n  while (frame > bot && cf) {\n    while (cframe_nres(cframe_raw(cf)) < 0) {  /* cframe without frame? */\n      if (frame >= restorestack(L, -cframe_nres(cf)))\n\tbreak;\n      if (cframe_errfunc(cf) >= 0)  /* Error handler not inherited (-1)? */\n\treturn cframe_errfunc(cf);\n      cf = cframe_prev(cf);  /* Else unwind cframe and continue searching. */\n      if (cf == NULL)\n\treturn 0;\n    }\n    switch (frame_typep(frame)) {\n    case FRAME_LUA:\n    case FRAME_LUAP:\n      frame = frame_prevl(frame);\n      break;\n    case FRAME_C:\n      cf = cframe_prev(cf);\n      /* fallthrough */\n    case FRAME_VARG:\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_CONT:\n      if (frame_iscont_fficb(frame))\n\tcf = cframe_prev(cf);\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_CP:\n      if (cframe_canyield(cf)) return 0;\n      if (cframe_errfunc(cf) >= 0)\n\treturn cframe_errfunc(cf);\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_PCALL:\n    case FRAME_PCALLH:\n      if (frame_func(frame_prevd(frame))->c.ffid == FF_xpcall)\n\treturn savestack(L, frame_prevd(frame)+1);  /* xpcall's errorfunc. */\n      return 0;\n    default:\n      lua_assert(0);\n      return 0;\n    }\n  }\n  return 0;\n}\n\n/* Runtime error. */\nLJ_NOINLINE void lj_err_run(lua_State *L)\n{\n  ptrdiff_t ef = finderrfunc(L);\n  if (ef) {\n    TValue *errfunc = restorestack(L, ef);\n    TValue *top = L->top;\n    lj_trace_abort(G(L));\n    if (!tvisfunc(errfunc) || L->status == LUA_ERRERR) {\n      setstrV(L, top-1, lj_err_str(L, LJ_ERR_ERRERR));\n      lj_err_throw(L, LUA_ERRERR);\n    }\n    L->status = LUA_ERRERR;\n    copyTV(L, top+LJ_FR2, top-1);\n    copyTV(L, top-1, errfunc);\n    if (LJ_FR2) setnilV(top++);\n    L->top = top+1;\n    lj_vm_call(L, top, 1+1);  /* Stack: |errfunc|msg| -> |msg| */\n  }\n  lj_err_throw(L, LUA_ERRRUN);\n}\n\n/* Formatted runtime error message. */\nLJ_NORET LJ_NOINLINE static void err_msgv(lua_State *L, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  if (curr_funcisL(L)) L->top = curr_topL(L);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  lj_debug_addloc(L, msg, L->base-1, NULL);\n  lj_err_run(L);\n}\n\n/* Non-vararg variant for better calling conventions. */\nLJ_NOINLINE void lj_err_msg(lua_State *L, ErrMsg em)\n{\n  err_msgv(L, em);\n}\n\n/* Lexer error. */\nLJ_NOINLINE void lj_err_lex(lua_State *L, GCstr *src, const char *tok,\n\t\t\t    BCLine line, ErrMsg em, va_list argp)\n{\n  char buff[LUA_IDSIZE];\n  const char *msg;\n  lj_debug_shortname(buff, src, line);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  msg = lj_strfmt_pushf(L, \"%s:%d: %s\", buff, line, msg);\n  if (tok)\n    lj_strfmt_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tok);\n  lj_err_throw(L, LUA_ERRSYNTAX);\n}\n\n/* Typecheck error for operands. */\nLJ_NOINLINE void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm)\n{\n  const char *tname = lj_typename(o);\n  const char *opname = err2msg(opm);\n  if (curr_funcisL(L)) {\n    GCproto *pt = curr_proto(L);\n    const BCIns *pc = cframe_Lpc(L) - 1;\n    const char *oname = NULL;\n    const char *kind = lj_debug_slotname(pt, pc, (BCReg)(o-L->base), &oname);\n    if (kind)\n      err_msgv(L, LJ_ERR_BADOPRT, opname, kind, oname, tname);\n  }\n  err_msgv(L, LJ_ERR_BADOPRV, opname, tname);\n}\n\n/* Typecheck error for ordered comparisons. */\nLJ_NOINLINE void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2)\n{\n  const char *t1 = lj_typename(o1);\n  const char *t2 = lj_typename(o2);\n  err_msgv(L, t1 == t2 ? LJ_ERR_BADCMPV : LJ_ERR_BADCMPT, t1, t2);\n  /* This assumes the two \"boolean\" entries are commoned by the C compiler. */\n}\n\n/* Typecheck error for __call. */\nLJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o)\n{\n  /* Gross hack if lua_[p]call or pcall/xpcall fail for a non-callable object:\n  ** L->base still points to the caller. So add a dummy frame with L instead\n  ** of a function. See lua_getstack().\n  */\n  const BCIns *pc = cframe_Lpc(L);\n  if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) {\n    const char *tname = lj_typename(o);\n    if (LJ_FR2) o++;\n    setframe_pc(o, pc);\n    setframe_gc(o, obj2gco(L), LJ_TTHREAD);\n    L->top = L->base = o+1;\n    err_msgv(L, LJ_ERR_BADCALL, tname);\n  }\n  lj_err_optype(L, o, LJ_ERR_OPCALL);\n}\n\n/* Error in context of caller. */\nLJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg)\n{\n  TValue *frame = L->base-1;\n  TValue *pframe = NULL;\n  if (frame_islua(frame)) {\n    pframe = frame_prevl(frame);\n  } else if (frame_iscont(frame)) {\n    if (frame_iscont_fficb(frame)) {\n      pframe = frame;\n      frame = NULL;\n    } else {\n      pframe = frame_prevd(frame);\n#if LJ_HASFFI\n      /* Remove frame for FFI metamethods. */\n      if (frame_func(frame)->c.ffid >= FF_ffi_meta___index &&\n\t  frame_func(frame)->c.ffid <= FF_ffi_meta___tostring) {\n\tL->base = pframe+1;\n\tL->top = frame;\n\tsetcframe_pc(cframe_raw(L->cframe), frame_contpc(frame));\n      }\n#endif\n    }\n  }\n  lj_debug_addloc(L, msg, pframe, frame);\n  lj_err_run(L);\n}\n\n/* Formatted error in context of caller. */\nLJ_NOINLINE void lj_err_callerv(lua_State *L, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  lj_err_callermsg(L, msg);\n}\n\n/* Error in context of caller. */\nLJ_NOINLINE void lj_err_caller(lua_State *L, ErrMsg em)\n{\n  lj_err_callermsg(L, err2msg(em));\n}\n\n/* Argument error message. */\nLJ_NORET LJ_NOINLINE static void err_argmsg(lua_State *L, int narg,\n\t\t\t\t\t    const char *msg)\n{\n  const char *fname = \"?\";\n  const char *ftype = lj_debug_funcname(L, L->base - 1, &fname);\n  if (narg < 0 && narg > LUA_REGISTRYINDEX)\n    narg = (int)(L->top - L->base) + narg + 1;\n  if (ftype && ftype[3] == 'h' && --narg == 0)  /* Check for \"method\". */\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADSELF), fname, msg);\n  else\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADARG), narg, fname, msg);\n  lj_err_callermsg(L, msg);\n}\n\n/* Formatted argument error. */\nLJ_NOINLINE void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  err_argmsg(L, narg, msg);\n}\n\n/* Argument error. */\nLJ_NOINLINE void lj_err_arg(lua_State *L, int narg, ErrMsg em)\n{\n  err_argmsg(L, narg, err2msg(em));\n}\n\n/* Typecheck error for arguments. */\nLJ_NOINLINE void lj_err_argtype(lua_State *L, int narg, const char *xname)\n{\n  const char *tname, *msg;\n  if (narg <= LUA_REGISTRYINDEX) {\n    if (narg >= LUA_GLOBALSINDEX) {\n      tname = lj_obj_itypename[~LJ_TTAB];\n    } else {\n      GCfunc *fn = curr_func(L);\n      int idx = LUA_GLOBALSINDEX - narg;\n      if (idx <= fn->c.nupvalues)\n\ttname = lj_typename(&fn->c.upvalue[idx-1]);\n      else\n\ttname = lj_obj_typename[0];\n    }\n  } else {\n    TValue *o = narg < 0 ? L->top + narg : L->base + narg-1;\n    tname = o < L->top ? lj_typename(o) : lj_obj_typename[0];\n  }\n  msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADTYPE), xname, tname);\n  err_argmsg(L, narg, msg);\n}\n\n/* Typecheck error for arguments. */\nLJ_NOINLINE void lj_err_argt(lua_State *L, int narg, int tt)\n{\n  lj_err_argtype(L, narg, lj_obj_typename[tt+1]);\n}\n\n/* -- Public error handling API ------------------------------------------- */\n\nLUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)\n{\n  lua_CFunction old = G(L)->panic;\n  G(L)->panic = panicf;\n  return old;\n}\n\n/* Forwarders for the public API (C calling convention and no LJ_NORET). */\nLUA_API int lua_error(lua_State *L)\n{\n  lj_err_run(L);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API int luaL_argerror(lua_State *L, int narg, const char *msg)\n{\n  err_argmsg(L, narg, msg);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API int luaL_typerror(lua_State *L, int narg, const char *xname)\n{\n  lj_err_argtype(L, narg, xname);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API void luaL_where(lua_State *L, int level)\n{\n  int size;\n  cTValue *frame = lj_debug_frame(L, level, &size);\n  lj_debug_addloc(L, \"\", frame, size ? frame+size : NULL);\n}\n\nLUALIB_API int luaL_error(lua_State *L, const char *fmt, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  lj_err_callermsg(L, msg);\n  return 0;  /* unreachable */\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_err.h",
    "content": "/*\n** Error handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ERR_H\n#define _LJ_ERR_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n\ntypedef enum {\n#define ERRDEF(name, msg) \\\n  LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1,\n#include \"lj_errmsg.h\"\n  LJ_ERR__MAX\n} ErrMsg;\n\nLJ_DATA const char *lj_err_allmsg;\n#define err2msg(em)\t(lj_err_allmsg+(int)(em))\n\nLJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em);\nLJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode);\nLJ_FUNC_NORET void lj_err_mem(lua_State *L);\nLJ_FUNC_NORET void lj_err_run(lua_State *L);\nLJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em);\nLJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok,\n\t\t\t      BCLine line, ErrMsg em, va_list argp);\nLJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm);\nLJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2);\nLJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o);\nLJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg);\nLJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...);\nLJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em);\nLJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em);\nLJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...);\nLJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname);\nLJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_errmsg.h",
    "content": "/*\n** VM error messages.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* This file may be included multiple times with different ERRDEF macros. */\n\n/* Basic error handling. */\nERRDEF(ERRMEM,\t\"not enough memory\")\nERRDEF(ERRERR,\t\"error in error handling\")\nERRDEF(ERRCPP,\t\"C++ exception\")\n\n/* Allocations. */\nERRDEF(STROV,\t\"string length overflow\")\nERRDEF(UDATAOV,\t\"userdata length overflow\")\nERRDEF(STKOV,\t\"stack overflow\")\nERRDEF(STKOVM,\t\"stack overflow (%s)\")\nERRDEF(TABOV,\t\"table overflow\")\n\n/* Table indexing. */\nERRDEF(NANIDX,\t\"table index is NaN\")\nERRDEF(NILIDX,\t\"table index is nil\")\nERRDEF(NEXTIDX,\t\"invalid key to \" LUA_QL(\"next\"))\n\n/* Metamethod resolving. */\nERRDEF(BADCALL,\t\"attempt to call a %s value\")\nERRDEF(BADOPRT,\t\"attempt to %s %s \" LUA_QS \" (a %s value)\")\nERRDEF(BADOPRV,\t\"attempt to %s a %s value\")\nERRDEF(BADCMPT,\t\"attempt to compare %s with %s\")\nERRDEF(BADCMPV,\t\"attempt to compare two %s values\")\nERRDEF(GETLOOP,\t\"loop in gettable\")\nERRDEF(SETLOOP,\t\"loop in settable\")\nERRDEF(OPCALL,\t\"call\")\nERRDEF(OPINDEX,\t\"index\")\nERRDEF(OPARITH,\t\"perform arithmetic on\")\nERRDEF(OPCAT,\t\"concatenate\")\nERRDEF(OPLEN,\t\"get length of\")\n\n/* Type checks. */\nERRDEF(BADSELF,\t\"calling \" LUA_QS \" on bad self (%s)\")\nERRDEF(BADARG,\t\"bad argument #%d to \" LUA_QS \" (%s)\")\nERRDEF(BADTYPE,\t\"%s expected, got %s\")\nERRDEF(BADVAL,\t\"invalid value\")\nERRDEF(NOVAL,\t\"value expected\")\nERRDEF(NOCORO,\t\"coroutine expected\")\nERRDEF(NOTABN,\t\"nil or table expected\")\nERRDEF(NOLFUNC,\t\"Lua function expected\")\nERRDEF(NOFUNCL,\t\"function or level expected\")\nERRDEF(NOSFT,\t\"string/function/table expected\")\nERRDEF(NOPROXY,\t\"boolean or proxy expected\")\nERRDEF(FORINIT,\tLUA_QL(\"for\") \" initial value must be a number\")\nERRDEF(FORLIM,\tLUA_QL(\"for\") \" limit must be a number\")\nERRDEF(FORSTEP,\tLUA_QL(\"for\") \" step must be a number\")\n\n/* C API checks. */\nERRDEF(NOENV,\t\"no calling environment\")\nERRDEF(CYIELD,\t\"attempt to yield across C-call boundary\")\nERRDEF(BADLU,\t\"bad light userdata pointer\")\nERRDEF(NOGCMM,\t\"bad action while in __gc metamethod\")\n#if LJ_TARGET_WINDOWS\nERRDEF(BADFPU,\t\"bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)\")\n#endif\n\n/* Standard library function errors. */\nERRDEF(ASSERT,\t\"assertion failed!\")\nERRDEF(PROTMT,\t\"cannot change a protected metatable\")\nERRDEF(UNPACK,\t\"too many results to unpack\")\nERRDEF(RDRSTR,\t\"reader function must return a string\")\nERRDEF(PRTOSTR,\tLUA_QL(\"tostring\") \" must return a string to \" LUA_QL(\"print\"))\nERRDEF(IDXRNG,\t\"index out of range\")\nERRDEF(BASERNG,\t\"base out of range\")\nERRDEF(LVLRNG,\t\"level out of range\")\nERRDEF(INVLVL,\t\"invalid level\")\nERRDEF(INVOPT,\t\"invalid option\")\nERRDEF(INVOPTM,\t\"invalid option \" LUA_QS)\nERRDEF(INVFMT,\t\"invalid format\")\nERRDEF(SETFENV,\tLUA_QL(\"setfenv\") \" cannot change environment of given object\")\nERRDEF(CORUN,\t\"cannot resume running coroutine\")\nERRDEF(CODEAD,\t\"cannot resume dead coroutine\")\nERRDEF(COSUSP,\t\"cannot resume non-suspended coroutine\")\nERRDEF(TABINS,\t\"wrong number of arguments to \" LUA_QL(\"insert\"))\nERRDEF(TABCAT,\t\"invalid value (%s) at index %d in table for \" LUA_QL(\"concat\"))\nERRDEF(TABSORT,\t\"invalid order function for sorting\")\nERRDEF(IOCLFL,\t\"attempt to use a closed file\")\nERRDEF(IOSTDCL,\t\"standard file is closed\")\nERRDEF(OSUNIQF,\t\"unable to generate a unique filename\")\nERRDEF(OSDATEF,\t\"field \" LUA_QS \" missing in date table\")\nERRDEF(STRDUMP,\t\"unable to dump given function\")\nERRDEF(STRSLC,\t\"string slice too long\")\nERRDEF(STRPATB,\t\"missing \" LUA_QL(\"[\") \" after \" LUA_QL(\"%f\") \" in pattern\")\nERRDEF(STRPATC,\t\"invalid pattern capture\")\nERRDEF(STRPATE,\t\"malformed pattern (ends with \" LUA_QL(\"%\") \")\")\nERRDEF(STRPATM,\t\"malformed pattern (missing \" LUA_QL(\"]\") \")\")\nERRDEF(STRPATU,\t\"unbalanced pattern\")\nERRDEF(STRPATX,\t\"pattern too complex\")\nERRDEF(STRCAPI,\t\"invalid capture index\")\nERRDEF(STRCAPN,\t\"too many captures\")\nERRDEF(STRCAPU,\t\"unfinished capture\")\nERRDEF(STRFMT,\t\"invalid option \" LUA_QS \" to \" LUA_QL(\"format\"))\nERRDEF(STRGSRV,\t\"invalid replacement value (a %s)\")\nERRDEF(BADMODN,\t\"name conflict for module \" LUA_QS)\n#if LJ_HASJIT\nERRDEF(JITPROT,\t\"runtime code generation failed, restricted kernel?\")\n#if LJ_TARGET_X86ORX64\nERRDEF(NOJIT,\t\"JIT compiler disabled, CPU does not support SSE2\")\n#else\nERRDEF(NOJIT,\t\"JIT compiler disabled\")\n#endif\n#elif defined(LJ_ARCH_NOJIT)\nERRDEF(NOJIT,\t\"no JIT compiler for this architecture (yet)\")\n#else\nERRDEF(NOJIT,\t\"JIT compiler permanently disabled by build option\")\n#endif\nERRDEF(JITOPT,\t\"unknown or malformed optimization flag \" LUA_QS)\n\n/* Lexer/parser errors. */\nERRDEF(XMODE,\t\"attempt to load chunk with wrong mode\")\nERRDEF(XNEAR,\t\"%s near \" LUA_QS)\nERRDEF(XLINES,\t\"chunk has too many lines\")\nERRDEF(XLEVELS,\t\"chunk has too many syntax levels\")\nERRDEF(XNUMBER,\t\"malformed number\")\nERRDEF(XLSTR,\t\"unfinished long string\")\nERRDEF(XLCOM,\t\"unfinished long comment\")\nERRDEF(XSTR,\t\"unfinished string\")\nERRDEF(XESC,\t\"invalid escape sequence\")\nERRDEF(XLDELIM,\t\"invalid long string delimiter\")\nERRDEF(XTOKEN,\tLUA_QS \" expected\")\nERRDEF(XJUMP,\t\"control structure too long\")\nERRDEF(XSLOTS,\t\"function or expression too complex\")\nERRDEF(XLIMC,\t\"chunk has more than %d local variables\")\nERRDEF(XLIMM,\t\"main function has more than %d %s\")\nERRDEF(XLIMF,\t\"function at line %d has more than %d %s\")\nERRDEF(XMATCH,\tLUA_QS \" expected (to close \" LUA_QS \" at line %d)\")\nERRDEF(XFIXUP,\t\"function too long for return fixup\")\nERRDEF(XPARAM,\t\"<name> or \" LUA_QL(\"...\") \" expected\")\n#if !LJ_52\nERRDEF(XAMBIG,\t\"ambiguous syntax (function call x new statement)\")\n#endif\nERRDEF(XFUNARG,\t\"function arguments expected\")\nERRDEF(XSYMBOL,\t\"unexpected symbol\")\nERRDEF(XDOTS,\t\"cannot use \" LUA_QL(\"...\") \" outside a vararg function\")\nERRDEF(XSYNTAX,\t\"syntax error\")\nERRDEF(XFOR,\tLUA_QL(\"=\") \" or \" LUA_QL(\"in\") \" expected\")\nERRDEF(XBREAK,\t\"no loop to break\")\nERRDEF(XLUNDEF,\t\"undefined label \" LUA_QS)\nERRDEF(XLDUP,\t\"duplicate label \" LUA_QS)\nERRDEF(XGSCOPE,\t\"<goto %s> jumps into the scope of local \" LUA_QS)\n\n/* Bytecode reader errors. */\nERRDEF(BCFMT,\t\"cannot load incompatible bytecode\")\nERRDEF(BCBAD,\t\"cannot load malformed bytecode\")\n\n#if LJ_HASFFI\n/* FFI errors. */\nERRDEF(FFI_INVTYPE,\t\"invalid C type\")\nERRDEF(FFI_INVSIZE,\t\"size of C type is unknown or too large\")\nERRDEF(FFI_BADSCL,\t\"bad storage class\")\nERRDEF(FFI_DECLSPEC,\t\"declaration specifier expected\")\nERRDEF(FFI_BADTAG,\t\"undeclared or implicit tag \" LUA_QS)\nERRDEF(FFI_REDEF,\t\"attempt to redefine \" LUA_QS)\nERRDEF(FFI_NUMPARAM,\t\"wrong number of type parameters\")\nERRDEF(FFI_INITOV,\t\"too many initializers for \" LUA_QS)\nERRDEF(FFI_BADCONV,\t\"cannot convert \" LUA_QS \" to \" LUA_QS)\nERRDEF(FFI_BADLEN,\t\"attempt to get length of \" LUA_QS)\nERRDEF(FFI_BADCONCAT,\t\"attempt to concatenate \" LUA_QS \" and \" LUA_QS)\nERRDEF(FFI_BADARITH,\t\"attempt to perform arithmetic on \" LUA_QS \" and \" LUA_QS)\nERRDEF(FFI_BADCOMP,\t\"attempt to compare \" LUA_QS \" with \" LUA_QS)\nERRDEF(FFI_BADCALL,\tLUA_QS \" is not callable\")\nERRDEF(FFI_NUMARG,\t\"wrong number of arguments for function call\")\nERRDEF(FFI_BADMEMBER,\tLUA_QS \" has no member named \" LUA_QS)\nERRDEF(FFI_BADIDX,\tLUA_QS \" cannot be indexed\")\nERRDEF(FFI_BADIDXW,\tLUA_QS \" cannot be indexed with \" LUA_QS)\nERRDEF(FFI_BADMM,\tLUA_QS \" has no \" LUA_QS \" metamethod\")\nERRDEF(FFI_WRCONST,\t\"attempt to write to constant location\")\nERRDEF(FFI_NODECL,\t\"missing declaration for symbol \" LUA_QS)\nERRDEF(FFI_BADCBACK,\t\"bad callback\")\n#if LJ_OS_NOJIT\nERRDEF(FFI_CBACKOV,\t\"no support for callbacks on this OS\")\n#else\nERRDEF(FFI_CBACKOV,\t\"too many callbacks\")\n#endif\nERRDEF(FFI_NYIPACKBIT,\t\"NYI: packed bit fields\")\nERRDEF(FFI_NYICALL,\t\"NYI: cannot call this C function (yet)\")\n#endif\n\n#undef ERRDEF\n\n/* Detecting unused error messages:\n   awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, \"\"); printf \"grep -q LJ_ERR_%s *.[ch] || echo %s\\n\", $1, $1}' lj_errmsg.h | sh\n*/\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ff.h",
    "content": "/*\n** Fast function IDs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FF_H\n#define _LJ_FF_H\n\n/* Fast function ID. */\ntypedef enum {\n  FF_LUA_ = FF_LUA,\t/* Lua function (must be 0). */\n  FF_C_ = FF_C,\t\t/* Regular C function (must be 1). */\n#define FFDEF(name)\tFF_##name,\n#include \"lj_ffdef.h\"\n  FF__MAX\n} FastFunc;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ffrecord.c",
    "content": "/*\n** Fast function call recorder.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ffrecord_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_crecord.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* -- Fast function recording handlers ------------------------------------ */\n\n/* Conventions for fast function call handlers:\n**\n** The argument slots start at J->base[0]. All of them are guaranteed to be\n** valid and type-specialized references. J->base[J->maxslot] is set to 0\n** as a sentinel. The runtime argument values start at rd->argv[0].\n**\n** In general fast functions should check for presence of all of their\n** arguments and for the correct argument types. Some simplifications\n** are allowed if the interpreter throws instead. But even if recording\n** is aborted, the generated IR must be consistent (no zero-refs).\n**\n** The number of results in rd->nres is set to 1. Handlers that return\n** a different number of results need to override it. A negative value\n** prevents return processing (e.g. for pending calls).\n**\n** Results need to be stored starting at J->base[0]. Return processing\n** moves them to the right slots later.\n**\n** The per-ffid auxiliary data is the value of the 2nd part of the\n** LJLIB_REC() annotation. This allows handling similar functionality\n** in a common handler.\n*/\n\n/* Type of handler to record a fast function. */\ntypedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd);\n\n/* Get runtime value of int argument. */\nstatic int32_t argv2int(jit_State *J, TValue *o)\n{\n  if (!lj_strscan_numberobj(o))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  return tvisint(o) ? intV(o) : lj_num2int(numV(o));\n}\n\n/* Get runtime value of string argument. */\nstatic GCstr *argv2str(jit_State *J, TValue *o)\n{\n  if (LJ_LIKELY(tvisstr(o))) {\n    return strV(o);\n  } else {\n    GCstr *s;\n    if (!tvisnumber(o))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    s = lj_strfmt_number(J->L, o);\n    setstrV(J->L, o, s);\n    return s;\n  }\n}\n\n/* Return number of results wanted by caller. */\nstatic ptrdiff_t results_wanted(jit_State *J)\n{\n  TValue *frame = J->L->base-1;\n  if (frame_islua(frame))\n    return (ptrdiff_t)bc_b(frame_pc(frame)[-1]) - 1;\n  else\n    return -1;\n}\n\n/* Trace stitching: add continuation below frame to start a new trace. */\nstatic void recff_stitch(jit_State *J)\n{\n  ASMFunction cont = lj_cont_stitch;\n  lua_State *L = J->L;\n  TValue *base = L->base;\n  const BCIns *pc = frame_pc(base-1);\n  TValue *pframe = frame_prevl(base-1);\n  TRef trcont;\n\n  lua_assert(!LJ_FR2);  /* TODO_FR2: handle frame shift. */\n  /* Move func + args up in Lua stack and insert continuation. */\n  memmove(&base[1], &base[-1], sizeof(TValue)*(J->maxslot+1));\n  setframe_ftsz(base+1, ((char *)(base+1) - (char *)pframe) + FRAME_CONT);\n  setcont(base, cont);\n  setframe_pc(base, pc);\n  setnilV(base-1);  /* Incorrect, but rec_check_slots() won't run anymore. */\n  L->base += 2;\n  L->top += 2;\n\n  /* Ditto for the IR. */\n  memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1));\n#if LJ_64\n  trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin));\n#else\n  trcont = lj_ir_kptr(J, (void *)cont);\n#endif\n  J->base[0] = trcont | TREF_CONT;\n  J->ktracep = lj_ir_k64_reserve(J);\n  lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE);\n  J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0);\n  J->base += 2;\n  J->baseslot += 2;\n  J->framedepth++;\n\n  lj_record_stop(J, LJ_TRLINK_STITCH, 0);\n\n  /* Undo Lua stack changes. */\n  memmove(&base[-1], &base[1], sizeof(TValue)*(J->maxslot+1));\n  setframe_pc(base-1, pc);\n  L->base -= 2;\n  L->top -= 2;\n}\n\n/* Fallback handler for fast functions that are not recorded (yet). */\nstatic void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd)\n{\n  if (J->cur.nins < (IRRef)J->param[JIT_P_minstitch] + REF_BASE) {\n    lj_trace_err_info(J, LJ_TRERR_TRACEUV);\n  } else {\n    /* Can only stitch from Lua call. */\n    if (J->framedepth && frame_islua(J->L->base-1)) {\n      BCOp op = bc_op(*frame_pc(J->L->base-1));\n      /* Stitched trace cannot start with *M op with variable # of args. */\n      if (!(op == BC_CALLM || op == BC_CALLMT ||\n\t    op == BC_RETM || op == BC_TSETM)) {\n\tswitch (J->fn->c.ffid) {\n\tcase FF_error:\n\tcase FF_debug_sethook:\n\tcase FF_jit_flush:\n\t  break;  /* Don't stitch across special builtins. */\n\tdefault:\n\t  recff_stitch(J);  /* Use trace stitching. */\n\t  rd->nres = -1;\n\t  return;\n\t}\n      }\n    }\n    /* Otherwise stop trace and return to interpreter. */\n    lj_record_stop(J, LJ_TRLINK_RETURN, 0);\n    rd->nres = -1;\n  }\n}\n\n/* Fallback handler for unsupported variants of fast functions. */\n#define recff_nyiu\trecff_nyi\n\n/* Must stop the trace for classic C functions with arbitrary side-effects. */\n#define recff_c\t\trecff_nyi\n\n/* Emit BUFHDR for the global temporary buffer. */\nstatic TRef recff_bufhdr(jit_State *J)\n{\n  return emitir(IRT(IR_BUFHDR, IRT_P32),\n\t\tlj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);\n}\n\n/* -- Base library fast functions ----------------------------------------- */\n\nstatic void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd)\n{\n  /* Arguments already specialized. The interpreter throws for nil/false. */\n  rd->nres = J->maxslot;  /* Pass through all arguments. */\n}\n\nstatic void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd)\n{\n  /* Arguments already specialized. Result is a constant string. Neat, huh? */\n  uint32_t t;\n  if (tvisnumber(&rd->argv[0]))\n    t = ~LJ_TNUMX;\n  else if (LJ_64 && !LJ_GC64 && tvislightud(&rd->argv[0]))\n    t = ~LJ_TLIGHTUD;\n  else\n    t = ~itype(&rd->argv[0]);\n  J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[t]));\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tr) {\n    RecordIndex ix;\n    ix.tab = tr;\n    copyTV(J->L, &ix.tabv, &rd->argv[0]);\n    if (lj_record_mm_lookup(J, &ix, MM_metatable))\n      J->base[0] = ix.mobj;\n    else\n      J->base[0] = ix.mt;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  TRef mt = J->base[1];\n  if (tref_istab(tr) && (tref_istab(mt) || (mt && tref_isnil(mt)))) {\n    TRef fref, mtref;\n    RecordIndex ix;\n    ix.tab = tr;\n    copyTV(J->L, &ix.tabv, &rd->argv[0]);\n    lj_record_mm_lookup(J, &ix, MM_metatable); /* Guard for no __metatable. */\n    fref = emitir(IRT(IR_FREF, IRT_P32), tr, IRFL_TAB_META);\n    mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt;\n    emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref);\n    if (!tref_isnil(mt))\n      emitir(IRT(IR_TBAR, IRT_TAB), tr, 0);\n    J->base[0] = tr;\n    J->needsnap = 1;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawget(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0]; ix.key = J->base[1];\n  if (tref_istab(ix.tab) && ix.key) {\n    ix.val = 0; ix.idxchain = 0;\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    copyTV(J->L, &ix.keyv, &rd->argv[1]);\n    J->base[0] = lj_record_idx(J, &ix);\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawset(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0]; ix.key = J->base[1]; ix.val = J->base[2];\n  if (tref_istab(ix.tab) && ix.key && ix.val) {\n    ix.idxchain = 0;\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    copyTV(J->L, &ix.keyv, &rd->argv[1]);\n    copyTV(J->L, &ix.valv, &rd->argv[2]);\n    lj_record_idx(J, &ix);\n    /* Pass through table at J->base[0] as result. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd)\n{\n  TRef tra = J->base[0];\n  TRef trb = J->base[1];\n  if (tra && trb) {\n    int diff = lj_record_objcmp(J, tra, trb, &rd->argv[0], &rd->argv[1]);\n    J->base[0] = diff ? TREF_FALSE : TREF_TRUE;\n  }  /* else: Interpreter will throw. */\n}\n\n#if LJ_52\nstatic void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_isstr(tr))\n    J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);\n  else if (tref_istab(tr))\n    J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr);\n  /* else: Interpreter will throw. */\n  UNUSED(rd);\n}\n#endif\n\n/* Determine mode of select() call. */\nint32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv)\n{\n  if (tref_isstr(tr) && *strVdata(tv) == '#') {  /* select('#', ...) */\n    if (strV(tv)->len == 1) {\n      emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, strV(tv)));\n    } else {\n      TRef trptr = emitir(IRT(IR_STRREF, IRT_P32), tr, lj_ir_kint(J, 0));\n      TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY);\n      emitir(IRTG(IR_EQ, IRT_INT), trchar, lj_ir_kint(J, '#'));\n    }\n    return 0;\n  } else {  /* select(n, ...) */\n    int32_t start = argv2int(J, tv);\n    if (start == 0) lj_trace_err(J, LJ_TRERR_BADTYPE);  /* A bit misleading. */\n    return start;\n  }\n}\n\nstatic void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tr) {\n    ptrdiff_t start = lj_ffrecord_select_mode(J, tr, &rd->argv[0]);\n    if (start == 0) {  /* select('#', ...) */\n      J->base[0] = lj_ir_kint(J, J->maxslot - 1);\n    } else if (tref_isk(tr)) {  /* select(k, ...) */\n      ptrdiff_t n = (ptrdiff_t)J->maxslot;\n      if (start < 0) start += n;\n      else if (start > n) start = n;\n      rd->nres = n - start;\n      if (start >= 1) {\n\tptrdiff_t i;\n\tfor (i = 0; i < n - start; i++)\n\t  J->base[i] = J->base[start+i];\n      }  /* else: Interpreter will throw. */\n    } else {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  TRef base = J->base[1];\n  if (tr && !tref_isnil(base)) {\n    base = lj_opt_narrow_toint(J, base);\n    if (!tref_isk(base) || IR(tref_ref(base))->i != 10) {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n  if (tref_isnumber_str(tr)) {\n    if (tref_isstr(tr)) {\n      TValue tmp;\n      if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) {\n\trecff_nyiu(J, rd);  /* Would need an inverted STRTO for this case. */\n\treturn;\n      }\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    }\n#if LJ_HASFFI\n  } else if (tref_iscdata(tr)) {\n    lj_crecord_tonumber(J, rd);\n    return;\n#endif\n  } else {\n    tr = TREF_NIL;\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\nstatic TValue *recff_metacall_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  lj_record_tailcall(J, 0, 1);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\nstatic int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  copyTV(J->L, &ix.tabv, &rd->argv[0]);\n  if (lj_record_mm_lookup(J, &ix, mm)) {  /* Has metamethod? */\n    int errcode;\n    TValue argv0;\n    /* Temporarily insert metamethod below object. */\n    J->base[1] = J->base[0];\n    J->base[0] = ix.mobj;\n    copyTV(J->L, &argv0, &rd->argv[0]);\n    copyTV(J->L, &rd->argv[1], &rd->argv[0]);\n    copyTV(J->L, &rd->argv[0], &ix.mobjv);\n    /* Need to protect lj_record_tailcall because it may throw. */\n    errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp);\n    /* Always undo Lua stack changes to avoid confusing the interpreter. */\n    copyTV(J->L, &rd->argv[0], &argv0);\n    if (errcode)\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    rd->nres = -1;  /* Pending call. */\n    return 1;  /* Tailcalled to metamethod. */\n  }\n  return 0;\n}\n\nstatic void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_isstr(tr)) {\n    /* Ignore __tostring in the string base metatable. */\n    /* Pass on result in J->base[0]. */\n  } else if (tr && !recff_metacall(J, rd, MM_tostring)) {\n    if (tref_isnumber(tr)) {\n      J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr,\n\t\t\t  tref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT);\n    } else if (tref_ispri(tr)) {\n      J->base[0] = lj_ir_kstr(J, lj_strfmt_obj(J->L, &rd->argv[0]));\n    } else {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n}\n\nstatic void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  if (tref_istab(ix.tab)) {\n    if (!tvisnumber(&rd->argv[1]))  /* No support for string coercion. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    setintV(&ix.keyv, numberVint(&rd->argv[1])+1);\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    ix.val = 0; ix.idxchain = 0;\n    ix.key = lj_opt_narrow_toint(J, J->base[1]);\n    J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1));\n    J->base[1] = lj_record_idx(J, &ix);\n    rd->nres = tref_isnil(J->base[1]) ? 0 : 2;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_xpairs(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) &&\n\trecff_metacall(J, rd, MM_pairs + rd->data))) {\n    if (tref_istab(tr)) {\n      J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0]));\n      J->base[1] = tr;\n      J->base[2] = rd->data ? lj_ir_kint(J, 0) : TREF_NIL;\n      rd->nres = 3;\n    }  /* else: Interpreter will throw. */\n  }\n}\n\nstatic void LJ_FASTCALL recff_pcall(jit_State *J, RecordFFData *rd)\n{\n  if (J->maxslot >= 1) {\n    lj_record_call(J, 0, J->maxslot - 1);\n    rd->nres = -1;  /* Pending call. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic TValue *recff_xpcall_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  lj_record_call(J, 1, J->maxslot - 2);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\nstatic void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd)\n{\n  if (J->maxslot >= 2) {\n    TValue argv0, argv1;\n    TRef tmp;\n    int errcode;\n    lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n    /* Swap function and traceback. */\n    tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp;\n    copyTV(J->L, &argv0, &rd->argv[0]);\n    copyTV(J->L, &argv1, &rd->argv[1]);\n    copyTV(J->L, &rd->argv[0], &argv1);\n    copyTV(J->L, &rd->argv[1], &argv0);\n    /* Need to protect lj_record_call because it may throw. */\n    errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp);\n    /* Always undo Lua stack swap to avoid confusing the interpreter. */\n    copyTV(J->L, &rd->argv[0], &argv0);\n    copyTV(J->L, &rd->argv[1], &argv1);\n    if (errcode)\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    rd->nres = -1;  /* Pending call. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_getfenv(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  /* Only support getfenv(0) for now. */\n  if (tref_isint(tr) && tref_isk(tr) && IR(tref_ref(tr))->i == 0) {\n    TRef trl = emitir(IRT(IR_LREF, IRT_THREAD), 0, 0);\n    J->base[0] = emitir(IRT(IR_FLOAD, IRT_TAB), trl, IRFL_THREAD_ENV);\n    return;\n  }\n  recff_nyiu(J, rd);\n}\n\n/* -- Math library fast functions ----------------------------------------- */\n\nstatic void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  J->base[0] = emitir(IRTN(IR_ABS), tr, lj_ir_knum_abs(J));\n  UNUSED(rd);\n}\n\n/* Record rounding functions math.floor and math.ceil. */\nstatic void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (!tref_isinteger(tr)) {  /* Pass through integers unmodified. */\n    tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data);\n    /* Result is integral (or NaN/Inf), but may not fit an int32_t. */\n    if (LJ_DUALNUM) {  /* Try to narrow using a guarded conversion to int. */\n      lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data);\n      if (n == (lua_Number)lj_num2int(n))\n\ttr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK);\n    }\n    J->base[0] = tr;\n  }\n}\n\n/* Record unary math.* functions, mapped to IR_FPMATH opcode. */\nstatic void LJ_FASTCALL recff_math_unary(jit_State *J, RecordFFData *rd)\n{\n  J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data);\n}\n\n/* Record math.log. */\nstatic void LJ_FASTCALL recff_math_log(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  if (J->base[1]) {\n#ifdef LUAJIT_NO_LOG2\n    uint32_t fpm = IRFPM_LOG;\n#else\n    uint32_t fpm = IRFPM_LOG2;\n#endif\n    TRef trb = lj_ir_tonum(J, J->base[1]);\n    tr = emitir(IRTN(IR_FPMATH), tr, fpm);\n    trb = emitir(IRTN(IR_FPMATH), trb, fpm);\n    trb = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), trb);\n    tr = emitir(IRTN(IR_MUL), tr, trb);\n  } else {\n    tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_LOG);\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\n/* Record math.atan2. */\nstatic void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  TRef tr2 = lj_ir_tonum(J, J->base[1]);\n  J->base[0] = emitir(IRTN(IR_ATAN2), tr, tr2);\n  UNUSED(rd);\n}\n\n/* Record math.ldexp. */\nstatic void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n#if LJ_TARGET_X86ORX64\n  TRef tr2 = lj_ir_tonum(J, J->base[1]);\n#else\n  TRef tr2 = lj_opt_narrow_toint(J, J->base[1]);\n#endif\n  J->base[0] = emitir(IRTN(IR_LDEXP), tr, tr2);\n  UNUSED(rd);\n}\n\n/* Record math.asin, math.acos, math.atan. */\nstatic void LJ_FASTCALL recff_math_atrig(jit_State *J, RecordFFData *rd)\n{\n  TRef y = lj_ir_tonum(J, J->base[0]);\n  TRef x = lj_ir_knum_one(J);\n  uint32_t ffid = rd->data;\n  if (ffid != FF_math_atan) {\n    TRef tmp = emitir(IRTN(IR_MUL), y, y);\n    tmp = emitir(IRTN(IR_SUB), x, tmp);\n    tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_SQRT);\n    if (ffid == FF_math_asin) { x = tmp; } else { x = y; y = tmp; }\n  }\n  J->base[0] = emitir(IRTN(IR_ATAN2), y, x);\n}\n\nstatic void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data);\n}\n\nstatic void LJ_FASTCALL recff_math_modf(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_isinteger(tr)) {\n    J->base[0] = tr;\n    J->base[1] = lj_ir_kint(J, 0);\n  } else {\n    TRef trt;\n    tr = lj_ir_tonum(J, tr);\n    trt = emitir(IRTN(IR_FPMATH), tr, IRFPM_TRUNC);\n    J->base[0] = trt;\n    J->base[1] = emitir(IRTN(IR_SUB), tr, trt);\n  }\n  rd->nres = 2;\n}\n\nstatic void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  if (!tref_isnumber_str(J->base[1]))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  J->base[0] = lj_opt_narrow_pow(J, tr, J->base[1], &rd->argv[1]);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_math_minmax(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonumber(J, J->base[0]);\n  uint32_t op = rd->data;\n  BCReg i;\n  for (i = 1; J->base[i] != 0; i++) {\n    TRef tr2 = lj_ir_tonumber(J, J->base[i]);\n    IRType t = IRT_INT;\n    if (!(tref_isinteger(tr) && tref_isinteger(tr2))) {\n      if (tref_isinteger(tr)) tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n      if (tref_isinteger(tr2)) tr2 = emitir(IRTN(IR_CONV), tr2, IRCONV_NUM_INT);\n      t = IRT_NUM;\n    }\n    tr = emitir(IRT(op, t), tr, tr2);\n  }\n  J->base[0] = tr;\n}\n\nstatic void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd)\n{\n  GCudata *ud = udataV(&J->fn->c.upvalue[0]);\n  TRef tr, one;\n  lj_ir_kgc(J, obj2gco(ud), IRT_UDATA);  /* Prevent collection. */\n  tr = lj_ir_call(J, IRCALL_lj_math_random_step, lj_ir_kptr(J, uddata(ud)));\n  one = lj_ir_knum_one(J);\n  tr = emitir(IRTN(IR_SUB), tr, one);\n  if (J->base[0]) {\n    TRef tr1 = lj_ir_tonum(J, J->base[0]);\n    if (J->base[1]) {  /* d = floor(d*(r2-r1+1.0)) + r1 */\n      TRef tr2 = lj_ir_tonum(J, J->base[1]);\n      tr2 = emitir(IRTN(IR_SUB), tr2, tr1);\n      tr2 = emitir(IRTN(IR_ADD), tr2, one);\n      tr = emitir(IRTN(IR_MUL), tr, tr2);\n      tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);\n      tr = emitir(IRTN(IR_ADD), tr, tr1);\n    } else {  /* d = floor(d*r1) + 1.0 */\n      tr = emitir(IRTN(IR_MUL), tr, tr1);\n      tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);\n      tr = emitir(IRTN(IR_ADD), tr, one);\n    }\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\n/* -- Bit library fast functions ------------------------------------------ */\n\n/* Record bit.tobit. */\nstatic void LJ_FASTCALL recff_bit_tobit(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n#if LJ_HASFFI\n  if (tref_iscdata(tr)) { recff_bit64_tobit(J, rd); return; }\n#endif\n  J->base[0] = lj_opt_narrow_tobit(J, tr);\n  UNUSED(rd);\n}\n\n/* Record unary bit.bnot, bit.bswap. */\nstatic void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_unary(J, rd))\n    return;\n#endif\n  J->base[0] = emitir(IRTI(rd->data), lj_opt_narrow_tobit(J, J->base[0]), 0);\n}\n\n/* Record N-ary bit.band, bit.bor, bit.bxor. */\nstatic void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_nary(J, rd))\n    return;\n#endif\n  {\n    TRef tr = lj_opt_narrow_tobit(J, J->base[0]);\n    uint32_t ot = IRTI(rd->data);\n    BCReg i;\n    for (i = 1; J->base[i] != 0; i++)\n      tr = emitir(ot, tr, lj_opt_narrow_tobit(J, J->base[i]));\n    J->base[0] = tr;\n  }\n}\n\n/* Record bit shifts. */\nstatic void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_shift(J, rd))\n    return;\n#endif\n  {\n    TRef tr = lj_opt_narrow_tobit(J, J->base[0]);\n    TRef tsh = lj_opt_narrow_tobit(J, J->base[1]);\n    IROp op = (IROp)rd->data;\n    if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n\t!tref_isk(tsh))\n      tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31));\n#ifdef LJ_TARGET_UNIFYROT\n    if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) {\n      op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR;\n      tsh = emitir(IRTI(IR_NEG), tsh, tsh);\n    }\n#endif\n    J->base[0] = emitir(IRTI(op), tr, tsh);\n  }\n}\n\nstatic void LJ_FASTCALL recff_bit_tohex(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  TRef hdr = recff_bufhdr(J);\n  TRef tr = recff_bit64_tohex(J, rd, hdr);\n  J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n#else\n  recff_nyiu(J, rd);  /* Don't bother working around this NYI. */\n#endif\n}\n\n/* -- String library fast functions --------------------------------------- */\n\n/* Specialize to relative starting position for string. */\nstatic TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr,\n\t\t\t       TRef trlen, TRef tr0)\n{\n  int32_t start = *st;\n  if (start < 0) {\n    emitir(IRTGI(IR_LT), tr, tr0);\n    tr = emitir(IRTI(IR_ADD), trlen, tr);\n    start = start + (int32_t)s->len;\n    emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), tr, tr0);\n    if (start < 0) {\n      tr = tr0;\n      start = 0;\n    }\n  } else if (start == 0) {\n    emitir(IRTGI(IR_EQ), tr, tr0);\n    tr = tr0;\n  } else {\n    tr = emitir(IRTI(IR_ADD), tr, lj_ir_kint(J, -1));\n    emitir(IRTGI(IR_GE), tr, tr0);\n    start--;\n  }\n  *st = start;\n  return tr;\n}\n\n/* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */\nstatic void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)\n{\n  TRef trstr = lj_ir_tostr(J, J->base[0]);\n  TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN);\n  TRef tr0 = lj_ir_kint(J, 0);\n  TRef trstart, trend;\n  GCstr *str = argv2str(J, &rd->argv[0]);\n  int32_t start, end;\n  if (rd->data) {  /* string.sub(str, start [,end]) */\n    start = argv2int(J, &rd->argv[1]);\n    trstart = lj_opt_narrow_toint(J, J->base[1]);\n    trend = J->base[2];\n    if (tref_isnil(trend)) {\n      trend = lj_ir_kint(J, -1);\n      end = -1;\n    } else {\n      trend = lj_opt_narrow_toint(J, trend);\n      end = argv2int(J, &rd->argv[2]);\n    }\n  } else {  /* string.byte(str, [,start [,end]]) */\n    if (tref_isnil(J->base[1])) {\n      start = 1;\n      trstart = lj_ir_kint(J, 1);\n    } else {\n      start = argv2int(J, &rd->argv[1]);\n      trstart = lj_opt_narrow_toint(J, J->base[1]);\n    }\n    if (J->base[1] && !tref_isnil(J->base[2])) {\n      trend = lj_opt_narrow_toint(J, J->base[2]);\n      end = argv2int(J, &rd->argv[2]);\n    } else {\n      trend = trstart;\n      end = start;\n    }\n  }\n  if (end < 0) {\n    emitir(IRTGI(IR_LT), trend, tr0);\n    trend = emitir(IRTI(IR_ADD), emitir(IRTI(IR_ADD), trlen, trend),\n\t\t   lj_ir_kint(J, 1));\n    end = end+(int32_t)str->len+1;\n  } else if ((MSize)end <= str->len) {\n    emitir(IRTGI(IR_ULE), trend, trlen);\n  } else {\n    emitir(IRTGI(IR_UGT), trend, trlen);\n    end = (int32_t)str->len;\n    trend = trlen;\n  }\n  trstart = recff_string_start(J, str, &start, trstart, trlen, tr0);\n  if (rd->data) {  /* Return string.sub result. */\n    if (end - start >= 0) {\n      /* Also handle empty range here, to avoid extra traces. */\n      TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart);\n      emitir(IRTGI(IR_GE), trslen, tr0);\n      trptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart);\n      J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen);\n    } else {  /* Range underflow: return empty string. */\n      emitir(IRTGI(IR_LT), trend, trstart);\n      J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty);\n    }\n  } else {  /* Return string.byte result(s). */\n    ptrdiff_t i, len = end - start;\n    if (len > 0) {\n      TRef trslen = emitir(IRTI(IR_SUB), trend, trstart);\n      emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len));\n      if (J->baseslot + len > LJ_MAX_JSLOTS)\n\tlj_trace_err_info(J, LJ_TRERR_STACKOV);\n      rd->nres = len;\n      for (i = 0; i < len; i++) {\n\tTRef tmp = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, (int32_t)i));\n\ttmp = emitir(IRT(IR_STRREF, IRT_P32), trstr, tmp);\n\tJ->base[i] = emitir(IRT(IR_XLOAD, IRT_U8), tmp, IRXLOAD_READONLY);\n      }\n    } else {  /* Empty range or range underflow: return no results. */\n      emitir(IRTGI(IR_LE), trend, trstart);\n      rd->nres = 0;\n    }\n  }\n}\n\nstatic void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd)\n{\n  TRef k255 = lj_ir_kint(J, 255);\n  BCReg i;\n  for (i = 0; J->base[i] != 0; i++) {  /* Convert char values to strings. */\n    TRef tr = lj_opt_narrow_toint(J, J->base[i]);\n    emitir(IRTGI(IR_ULE), tr, k255);\n    J->base[i] = emitir(IRT(IR_TOSTR, IRT_STR), tr, IRTOSTR_CHAR);\n  }\n  if (i > 1) {  /* Concatenate the strings, if there's more than one. */\n    TRef hdr = recff_bufhdr(J), tr = hdr;\n    for (i = 0; J->base[i] != 0; i++)\n      tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, J->base[i]);\n    J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n  }\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd)\n{\n  TRef str = lj_ir_tostr(J, J->base[0]);\n  TRef rep = lj_opt_narrow_toint(J, J->base[1]);\n  TRef hdr, tr, str2 = 0;\n  if (!tref_isnil(J->base[2])) {\n    TRef sep = lj_ir_tostr(J, J->base[2]);\n    int32_t vrep = argv2int(J, &rd->argv[1]);\n    emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1));\n    if (vrep > 1) {\n      TRef hdr2 = recff_bufhdr(J);\n      TRef tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), hdr2, sep);\n      tr2 = emitir(IRT(IR_BUFPUT, IRT_P32), tr2, str);\n      str2 = emitir(IRT(IR_BUFSTR, IRT_STR), tr2, hdr2);\n    }\n  }\n  tr = hdr = recff_bufhdr(J);\n  if (str2) {\n    tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, str);\n    str = str2;\n    rep = emitir(IRTI(IR_ADD), rep, lj_ir_kint(J, -1));\n  }\n  tr = lj_ir_call(J, IRCALL_lj_buf_putstr_rep, tr, str, rep);\n  J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n}\n\nstatic void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd)\n{\n  TRef str = lj_ir_tostr(J, J->base[0]);\n  TRef hdr = recff_bufhdr(J);\n  TRef tr = lj_ir_call(J, rd->data, hdr, str);\n  J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n}\n\nstatic void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd)\n{\n  TRef trstr = lj_ir_tostr(J, J->base[0]);\n  TRef trpat = lj_ir_tostr(J, J->base[1]);\n  TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN);\n  TRef tr0 = lj_ir_kint(J, 0);\n  TRef trstart;\n  GCstr *str = argv2str(J, &rd->argv[0]);\n  GCstr *pat = argv2str(J, &rd->argv[1]);\n  int32_t start;\n  J->needsnap = 1;\n  if (tref_isnil(J->base[2])) {\n    trstart = lj_ir_kint(J, 1);\n    start = 1;\n  } else {\n    trstart = lj_opt_narrow_toint(J, J->base[2]);\n    start = argv2int(J, &rd->argv[2]);\n  }\n  trstart = recff_string_start(J, str, &start, trstart, trlen, tr0);\n  if ((MSize)start <= str->len) {\n    emitir(IRTGI(IR_ULE), trstart, trlen);\n  } else {\n    emitir(IRTGI(IR_UGT), trstart, trlen);\n#if LJ_52\n    J->base[0] = TREF_NIL;\n    return;\n#else\n    trstart = trlen;\n    start = str->len;\n#endif\n  }\n  /* Fixed arg or no pattern matching chars? (Specialized to pattern string.) */\n  if ((J->base[2] && tref_istruecond(J->base[3])) ||\n      (emitir(IRTG(IR_EQ, IRT_STR), trpat, lj_ir_kstr(J, pat)),\n       !lj_str_haspattern(pat))) {  /* Search for fixed string. */\n    TRef trsptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart);\n    TRef trpptr = emitir(IRT(IR_STRREF, IRT_P32), trpat, tr0);\n    TRef trslen = emitir(IRTI(IR_SUB), trlen, trstart);\n    TRef trplen = emitir(IRTI(IR_FLOAD), trpat, IRFL_STR_LEN);\n    TRef tr = lj_ir_call(J, IRCALL_lj_str_find, trsptr, trpptr, trslen, trplen);\n    TRef trp0 = lj_ir_kkptr(J, NULL);\n    if (lj_str_find(strdata(str)+(MSize)start, strdata(pat),\n\t\t    str->len-(MSize)start, pat->len)) {\n      TRef pos;\n      emitir(IRTG(IR_NE, IRT_P32), tr, trp0);\n      pos = emitir(IRTI(IR_SUB), tr, emitir(IRT(IR_STRREF, IRT_P32), trstr, tr0));\n      J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1));\n      J->base[1] = emitir(IRTI(IR_ADD), pos, trplen);\n      rd->nres = 2;\n    } else {\n      emitir(IRTG(IR_EQ, IRT_P32), tr, trp0);\n      J->base[0] = TREF_NIL;\n    }\n  } else {  /* Search for pattern. */\n    recff_nyiu(J, rd);\n    return;\n  }\n}\n\nstatic void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)\n{\n  TRef trfmt = lj_ir_tostr(J, J->base[0]);\n  GCstr *fmt = argv2str(J, &rd->argv[0]);\n  int arg = 1;\n  TRef hdr, tr;\n  FormatState fs;\n  SFormat sf;\n  /* Specialize to the format string. */\n  emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt));\n  tr = hdr = recff_bufhdr(J);\n  lj_strfmt_init(&fs, strdata(fmt), fmt->len);\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {  /* Parse format. */\n    TRef tra = sf == STRFMT_LIT ? 0 : J->base[arg++];\n    TRef trsf = lj_ir_kint(J, (int32_t)sf);\n    IRCallID id;\n    switch (STRFMT_TYPE(sf)) {\n    case STRFMT_LIT:\n      tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr,\n\t\t  lj_ir_kstr(J, lj_str_new(J->L, fs.str, fs.len)));\n      break;\n    case STRFMT_INT:\n      id = IRCALL_lj_strfmt_putfnum_int;\n    handle_int:\n      if (!tref_isinteger(tra))\n\tgoto handle_num;\n      if (sf == STRFMT_INT) { /* Shortcut for plain %d. */\n\ttr = emitir(IRT(IR_BUFPUT, IRT_P32), tr,\n\t\t    emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_INT));\n      } else {\n#if LJ_HASFFI\n\ttra = emitir(IRT(IR_CONV, IRT_U64), tra,\n\t\t     (IRT_INT|(IRT_U64<<5)|IRCONV_SEXT));\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfxint, tr, trsf, tra);\n\tlj_needsplit(J);\n#else\n\trecff_nyiu(J, rd);  /* Don't bother working around this NYI. */\n\treturn;\n#endif\n      }\n      break;\n    case STRFMT_UINT:\n      id = IRCALL_lj_strfmt_putfnum_uint;\n      goto handle_int;\n    case STRFMT_NUM:\n      id = IRCALL_lj_strfmt_putfnum;\n    handle_num:\n      tra = lj_ir_tonum(J, tra);\n      tr = lj_ir_call(J, id, tr, trsf, tra);\n      if (LJ_SOFTFP) lj_needsplit(J);\n      break;\n    case STRFMT_STR:\n      if (!tref_isstr(tra)) {\n\trecff_nyiu(J, rd);  /* NYI: __tostring and non-string types for %s. */\n\treturn;\n      }\n      if (sf == STRFMT_STR)  /* Shortcut for plain %s. */\n\ttr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, tra);\n      else if ((sf & STRFMT_T_QUOTED))\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putquoted, tr, tra);\n      else\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfstr, tr, trsf, tra);\n      break;\n    case STRFMT_CHAR:\n      tra = lj_opt_narrow_toint(J, tra);\n      if (sf == STRFMT_CHAR)  /* Shortcut for plain %c. */\n\ttr = emitir(IRT(IR_BUFPUT, IRT_P32), tr,\n\t\t    emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_CHAR));\n      else\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfchar, tr, trsf, tra);\n      break;\n    case STRFMT_PTR:  /* NYI */\n    case STRFMT_ERR:\n    default:\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n  J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n}\n\n/* -- Table library fast functions ---------------------------------------- */\n\nstatic void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  ix.val = J->base[1];\n  rd->nres = 0;\n  if (tref_istab(ix.tab) && ix.val) {\n    if (!J->base[2]) {  /* Simple push: t[#t+1] = v */\n      TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, ix.tab);\n      GCtab *t = tabV(&rd->argv[0]);\n      ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));\n      settabV(J->L, &ix.tabv, t);\n      setintV(&ix.keyv, lj_tab_len(t) + 1);\n      ix.idxchain = 0;\n      lj_record_idx(J, &ix);  /* Set new value. */\n    } else {  /* Complex case: insert in the middle. */\n      recff_nyiu(J, rd);\n      return;\n    }\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_table_concat(jit_State *J, RecordFFData *rd)\n{\n  TRef tab = J->base[0];\n  if (tref_istab(tab)) {\n    TRef sep = !tref_isnil(J->base[1]) ?\n\t       lj_ir_tostr(J, J->base[1]) : lj_ir_knull(J, IRT_STR);\n    TRef tri = (J->base[1] && !tref_isnil(J->base[2])) ?\n\t       lj_opt_narrow_toint(J, J->base[2]) : lj_ir_kint(J, 1);\n    TRef tre = (J->base[1] && J->base[2] && !tref_isnil(J->base[3])) ?\n\t       lj_opt_narrow_toint(J, J->base[3]) :\n\t       lj_ir_call(J, IRCALL_lj_tab_len, tab);\n    TRef hdr = recff_bufhdr(J);\n    TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre);\n    emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL));\n    J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n  }  /* else: Interpreter will throw. */\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_table_new(jit_State *J, RecordFFData *rd)\n{\n  TRef tra = lj_opt_narrow_toint(J, J->base[0]);\n  TRef trh = lj_opt_narrow_toint(J, J->base[1]);\n  J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_table_clear(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_istab(tr)) {\n    rd->nres = 0;\n    lj_ir_call(J, IRCALL_lj_tab_clear, tr);\n    J->needsnap = 1;\n  }  /* else: Interpreter will throw. */\n}\n\n/* -- I/O library fast functions ------------------------------------------ */\n\n/* Get FILE* for I/O function. Any I/O error aborts recording, so there's\n** no need to encode the alternate cases for any of the guards.\n*/\nstatic TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id)\n{\n  TRef tr, ud, fp;\n  if (id) {  /* io.func() */\n    tr = lj_ir_kptr(J, &J2G(J)->gcroot[id]);\n    ud = emitir(IRT(IR_XLOAD, IRT_UDATA), tr, 0);\n  } else {  /* fp:method() */\n    ud = J->base[0];\n    if (!tref_isudata(ud))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE);\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));\n  }\n  *udp = ud;\n  fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE);\n  emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR));\n  return fp;\n}\n\nstatic void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd)\n{\n  TRef ud, fp = recff_io_fp(J, &ud, rd->data);\n  TRef zero = lj_ir_kint(J, 0);\n  TRef one = lj_ir_kint(J, 1);\n  ptrdiff_t i = rd->data == 0 ? 1 : 0;\n  for (; J->base[i]; i++) {\n    TRef str = lj_ir_tostr(J, J->base[i]);\n    TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero);\n    TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN);\n    if (tref_isk(len) && IR(tref_ref(len))->i == 1) {\n      IRIns *irs = IR(tref_ref(str));\n      TRef tr = (irs->o == IR_TOSTR && irs->op2 == IRTOSTR_CHAR) ?\n\t\tirs->op1 :\n\t\temitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY);\n      tr = lj_ir_call(J, IRCALL_fputc, tr, fp);\n      if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n\temitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1));\n    } else {\n      TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp);\n      if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n\temitir(IRTGI(IR_EQ), tr, len);\n    }\n  }\n  J->base[0] = LJ_52 ? ud : TREF_TRUE;\n}\n\nstatic void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd)\n{\n  TRef ud, fp = recff_io_fp(J, &ud, rd->data);\n  TRef tr = lj_ir_call(J, IRCALL_fflush, fp);\n  if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));\n  J->base[0] = TREF_TRUE;\n}\n\n/* -- Debug library fast functions ---------------------------------------- */\n\nstatic void LJ_FASTCALL recff_debug_getmetatable(jit_State *J, RecordFFData *rd)\n{\n  GCtab *mt;\n  TRef mtref;\n  TRef tr = J->base[0];\n  if (tref_istab(tr)) {\n    mt = tabref(tabV(&rd->argv[0])->metatable);\n    mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_TAB_META);\n  } else if (tref_isudata(tr)) {\n    mt = tabref(udataV(&rd->argv[0])->metatable);\n    mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_UDATA_META);\n  } else {\n    mt = tabref(basemt_obj(J2G(J), &rd->argv[0]));\n    J->base[0] = mt ? lj_ir_ktab(J, mt) : TREF_NIL;\n    return;\n  }\n  emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB));\n  J->base[0] = mt ? mtref : TREF_NIL;\n}\n\n/* -- Record calls to fast functions -------------------------------------- */\n\n#include \"lj_recdef.h\"\n\nstatic uint32_t recdef_lookup(GCfunc *fn)\n{\n  if (fn->c.ffid < sizeof(recff_idmap)/sizeof(recff_idmap[0]))\n    return recff_idmap[fn->c.ffid];\n  else\n    return 0;\n}\n\n/* Record entry to a fast function or C function. */\nvoid lj_ffrecord_func(jit_State *J)\n{\n  RecordFFData rd;\n  uint32_t m = recdef_lookup(J->fn);\n  rd.data = m & 0xff;\n  rd.nres = 1;  /* Default is one result. */\n  rd.argv = J->L->base;\n  J->base[J->maxslot] = 0;  /* Mark end of arguments. */\n  (recff_func[m >> 8])(J, &rd);  /* Call recff_* handler. */\n  if (rd.nres >= 0) {\n    if (J->postproc == LJ_POST_NONE) J->postproc = LJ_POST_FFRETRY;\n    lj_record_ret(J, 0, rd.nres);\n  }\n}\n\n#undef IR\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ffrecord.h",
    "content": "/*\n** Fast function call recorder.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FFRECORD_H\n#define _LJ_FFRECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* Data used by handlers to record a fast function. */\ntypedef struct RecordFFData {\n  TValue *argv;\t\t/* Runtime argument values. */\n  ptrdiff_t nres;\t/* Number of returned results (defaults to 1). */\n  uint32_t data;\t/* Per-ffid auxiliary data (opcode, literal etc.). */\n} RecordFFData;\n\nLJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv);\nLJ_FUNC void lj_ffrecord_func(jit_State *J);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_frame.h",
    "content": "/*\n** Stack frames.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FRAME_H\n#define _LJ_FRAME_H\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n\n/* -- Lua stack frame ----------------------------------------------------- */\n\n/* Frame type markers in LSB of PC (4-byte aligned) or delta (8-byte aligned:\n**\n**    PC  00  Lua frame\n** delta 001  C frame\n** delta 010  Continuation frame\n** delta 011  Lua vararg frame\n** delta 101  cpcall() frame\n** delta 110  ff pcall() frame\n** delta 111  ff pcall() frame with active hook\n*/\nenum {\n  FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,\n  FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH\n};\n#define FRAME_TYPE\t\t3\n#define FRAME_P\t\t\t4\n#define FRAME_TYPEP\t\t(FRAME_TYPE|FRAME_P)\n\n/* Macros to access and modify Lua frames. */\n#if LJ_FR2\n/* Two-slot frame info, required for 64 bit PC/GCRef:\n**\n**                   base-2  base-1      |  base  base+1 ...\n**                  [func   PC/delta/ft] | [slots ...]\n**                  ^-- frame            | ^-- base   ^-- top\n**\n** Continuation frames:\n**\n**   base-4  base-3  base-2  base-1      |  base  base+1 ...\n**  [cont      PC ] [func   PC/delta/ft] | [slots ...]\n**                  ^-- frame            | ^-- base   ^-- top\n*/\n#define frame_gc(f)\t\t(gcval((f)-1))\n#define frame_ftsz(f)\t\t((ptrdiff_t)(f)->ftsz)\n#define frame_pc(f)\t\t((const BCIns *)frame_ftsz(f))\n#define setframe_gc(f, p, tp)\t(setgcVraw((f)-1, (p), (tp)))\n#define setframe_ftsz(f, sz)\t((f)->ftsz = (sz))\n#define setframe_pc(f, pc)\t((f)->ftsz = (int64_t)(intptr_t)(pc))\n#else\n/* One-slot frame info, sufficient for 32 bit PC/GCRef:\n**\n**              base-1              |  base  base+1 ...\n**              lo     hi           |\n**             [func | PC/delta/ft] | [slots ...]\n**             ^-- frame            | ^-- base   ^-- top\n**\n** Continuation frames:\n**\n**  base-2      base-1              |  base  base+1 ...\n**  lo     hi   lo     hi           |\n** [cont | PC] [func | PC/delta/ft] | [slots ...]\n**             ^-- frame            | ^-- base   ^-- top\n*/\n#define frame_gc(f)\t\t(gcref((f)->fr.func))\n#define frame_ftsz(f)\t\t((ptrdiff_t)(f)->fr.tp.ftsz)\n#define frame_pc(f)\t\t(mref((f)->fr.tp.pcr, const BCIns))\n#define setframe_gc(f, p, tp)\t(setgcref((f)->fr.func, (p)), UNUSED(tp))\n#define setframe_ftsz(f, sz)\t((f)->fr.tp.ftsz = (int32_t)(sz))\n#define setframe_pc(f, pc)\t(setmref((f)->fr.tp.pcr, (pc)))\n#endif\n\n#define frame_type(f)\t\t(frame_ftsz(f) & FRAME_TYPE)\n#define frame_typep(f)\t\t(frame_ftsz(f) & FRAME_TYPEP)\n#define frame_islua(f)\t\t(frame_type(f) == FRAME_LUA)\n#define frame_isc(f)\t\t(frame_type(f) == FRAME_C)\n#define frame_iscont(f)\t\t(frame_typep(f) == FRAME_CONT)\n#define frame_isvarg(f)\t\t(frame_typep(f) == FRAME_VARG)\n#define frame_ispcall(f)\t((frame_ftsz(f) & 6) == FRAME_PCALL)\n\n#define frame_func(f)\t\t(&frame_gc(f)->fn)\n#define frame_delta(f)\t\t(frame_ftsz(f) >> 3)\n#define frame_sized(f)\t\t(frame_ftsz(f) & ~FRAME_TYPEP)\n\nenum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK };  /* Special continuations. */\n\n#if LJ_FR2\n#define frame_contpc(f)\t\t(frame_pc((f)-2))\n#define frame_contv(f)\t\t(((f)-3)->u64)\n#else\n#define frame_contpc(f)\t\t(frame_pc((f)-1))\n#define frame_contv(f)\t\t(((f)-1)->u32.lo)\n#endif\n#if LJ_FR2\n#define frame_contf(f)\t\t((ASMFunction)(uintptr_t)((f)-3)->u64)\n#elif LJ_64\n#define frame_contf(f) \\\n  ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \\\n\t\t\t (intptr_t)(int32_t)((f)-1)->u32.lo))\n#else\n#define frame_contf(f)\t\t((ASMFunction)gcrefp(((f)-1)->gcr, void))\n#endif\n#define frame_iscont_fficb(f) \\\n  (LJ_HASFFI && frame_contv(f) == LJ_CONT_FFI_CALLBACK)\n\n#define frame_prevl(f)\t\t((f) - (1+LJ_FR2+bc_a(frame_pc(f)[-1])))\n#define frame_prevd(f)\t\t((TValue *)((char *)(f) - frame_sized(f)))\n#define frame_prev(f)\t\t(frame_islua(f)?frame_prevl(f):frame_prevd(f))\n/* Note: this macro does not skip over FRAME_VARG. */\n\n/* -- C stack frame ------------------------------------------------------- */\n\n/* Macros to access and modify the C stack frame chain. */\n\n/* These definitions must match with the arch-specific *.dasc files. */\n#if LJ_TARGET_X86\n#define CFRAME_OFS_ERRF\t\t(15*4)\n#define CFRAME_OFS_NRES\t\t(14*4)\n#define CFRAME_OFS_PREV\t\t(13*4)\n#define CFRAME_OFS_L\t\t(12*4)\n#define CFRAME_OFS_PC\t\t(6*4)\n#define CFRAME_OFS_MULTRES\t(5*4)\n#define CFRAME_SIZE\t\t(12*4)\n#define CFRAME_SHIFT_MULTRES\t0\n#elif LJ_TARGET_X64\n#if LJ_ABI_WIN\n#define CFRAME_OFS_PREV\t\t(13*8)\n#if LJ_GC64\n#define CFRAME_OFS_PC\t\t(12*8)\n#define CFRAME_OFS_L\t\t(11*8)\n#define CFRAME_OFS_ERRF\t\t(21*4)\n#define CFRAME_OFS_NRES\t\t(20*4)\n#define CFRAME_OFS_MULTRES\t(8*4)\n#else\n#define CFRAME_OFS_PC\t\t(25*4)\n#define CFRAME_OFS_L\t\t(24*4)\n#define CFRAME_OFS_ERRF\t\t(23*4)\n#define CFRAME_OFS_NRES\t\t(22*4)\n#define CFRAME_OFS_MULTRES\t(21*4)\n#endif\n#define CFRAME_SIZE\t\t(10*8)\n#define CFRAME_SIZE_JIT\t\t(CFRAME_SIZE + 9*16 + 4*8)\n#define CFRAME_SHIFT_MULTRES\t0\n#else\n#define CFRAME_OFS_PREV\t\t(4*8)\n#if LJ_GC64\n#define CFRAME_OFS_PC\t\t(3*8)\n#define CFRAME_OFS_L\t\t(2*8)\n#define CFRAME_OFS_ERRF\t\t(3*4)\n#define CFRAME_OFS_NRES\t\t(2*4)\n#define CFRAME_OFS_MULTRES\t(0*4)\n#else\n#define CFRAME_OFS_PC\t\t(7*4)\n#define CFRAME_OFS_L\t\t(6*4)\n#define CFRAME_OFS_ERRF\t\t(5*4)\n#define CFRAME_OFS_NRES\t\t(4*4)\n#define CFRAME_OFS_MULTRES\t(1*4)\n#endif\n#if LJ_NO_UNWIND\n#define CFRAME_SIZE\t\t(12*8)\n#else\n#define CFRAME_SIZE\t\t(10*8)\n#endif\n#define CFRAME_SIZE_JIT\t\t(CFRAME_SIZE + 16)\n#define CFRAME_SHIFT_MULTRES\t0\n#endif\n#elif LJ_TARGET_ARM\n#define CFRAME_OFS_ERRF\t\t24\n#define CFRAME_OFS_NRES\t\t20\n#define CFRAME_OFS_PREV\t\t16\n#define CFRAME_OFS_L\t\t12\n#define CFRAME_OFS_PC\t\t8\n#define CFRAME_OFS_MULTRES\t4\n#if LJ_ARCH_HASFPU\n#define CFRAME_SIZE\t\t128\n#else\n#define CFRAME_SIZE\t\t64\n#endif\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_TARGET_ARM64\n#define CFRAME_OFS_ERRF\t\t196\n#define CFRAME_OFS_NRES\t\t200\n#define CFRAME_OFS_PREV\t\t160\n#define CFRAME_OFS_L\t\t176\n#define CFRAME_OFS_PC\t\t168\n#define CFRAME_OFS_MULTRES\t192\n#define CFRAME_SIZE\t\t208\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_TARGET_PPC\n#if LJ_TARGET_XBOX360\n#define CFRAME_OFS_ERRF\t\t424\n#define CFRAME_OFS_NRES\t\t420\n#define CFRAME_OFS_PREV\t\t400\n#define CFRAME_OFS_L\t\t416\n#define CFRAME_OFS_PC\t\t412\n#define CFRAME_OFS_MULTRES\t408\n#define CFRAME_SIZE\t\t384\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_ARCH_PPC32ON64\n#define CFRAME_OFS_ERRF\t\t472\n#define CFRAME_OFS_NRES\t\t468\n#define CFRAME_OFS_PREV\t\t448\n#define CFRAME_OFS_L\t\t464\n#define CFRAME_OFS_PC\t\t460\n#define CFRAME_OFS_MULTRES\t456\n#define CFRAME_SIZE\t\t400\n#define CFRAME_SHIFT_MULTRES\t3\n#else\n#define CFRAME_OFS_ERRF\t\t48\n#define CFRAME_OFS_NRES\t\t44\n#define CFRAME_OFS_PREV\t\t40\n#define CFRAME_OFS_L\t\t36\n#define CFRAME_OFS_PC\t\t32\n#define CFRAME_OFS_MULTRES\t28\n#define CFRAME_SIZE\t\t272\n#define CFRAME_SHIFT_MULTRES\t3\n#endif\n#elif LJ_TARGET_MIPS\n#if LJ_ARCH_HASFPU\n#define CFRAME_OFS_ERRF\t\t124\n#define CFRAME_OFS_NRES\t\t120\n#define CFRAME_OFS_PREV\t\t116\n#define CFRAME_OFS_L\t\t112\n#define CFRAME_OFS_PC\t\t20\n#define CFRAME_OFS_MULTRES\t16\n#define CFRAME_SIZE\t\t112\n#define CFRAME_SHIFT_MULTRES\t3\n#else\n#define CFRAME_OFS_ERRF\t\t76\n#define CFRAME_OFS_NRES\t\t72\n#define CFRAME_OFS_PREV\t\t68\n#define CFRAME_OFS_L\t\t64\n#define CFRAME_OFS_PC\t\t20\n#define CFRAME_OFS_MULTRES\t16\n#define CFRAME_SIZE\t\t64\n#define CFRAME_SHIFT_MULTRES\t3\n#endif\n#else\n#error \"Missing CFRAME_* definitions for this architecture\"\n#endif\n\n#ifndef CFRAME_SIZE_JIT\n#define CFRAME_SIZE_JIT\t\tCFRAME_SIZE\n#endif\n\n#define CFRAME_RESUME\t\t1\n#define CFRAME_UNWIND_FF\t2  /* Only used in unwinder. */\n#define CFRAME_RAWMASK\t\t(~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF))\n\n#define cframe_errfunc(cf)\t(*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF))\n#define cframe_nres(cf)\t\t(*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES))\n#define cframe_prev(cf)\t\t(*(void **)(((char *)(cf))+CFRAME_OFS_PREV))\n#define cframe_multres(cf)  (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES))\n#define cframe_multres_n(cf)\t(cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES)\n#define cframe_L(cf) \\\n  (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th)\n#define cframe_pc(cf) \\\n  (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns))\n#define setcframe_L(cf, L) \\\n  (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L)))\n#define setcframe_pc(cf, pc) \\\n  (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc)))\n#define cframe_canyield(cf)\t((intptr_t)(cf) & CFRAME_RESUME)\n#define cframe_unwind_ff(cf)\t((intptr_t)(cf) & CFRAME_UNWIND_FF)\n#define cframe_raw(cf)\t\t((void *)((intptr_t)(cf) & CFRAME_RAWMASK))\n#define cframe_Lpc(L)\t\tcframe_pc(cframe_raw(L->cframe))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_func.c",
    "content": "/*\n** Function handling (prototypes, functions and upvalues).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_func_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_func.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n\n/* -- Prototypes ---------------------------------------------------------- */\n\nvoid LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt)\n{\n  lj_mem_free(g, pt, pt->sizept);\n}\n\n/* -- Upvalues ------------------------------------------------------------ */\n\nstatic void unlinkuv(GCupval *uv)\n{\n  lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);\n  setgcrefr(uvnext(uv)->prev, uv->prev);\n  setgcrefr(uvprev(uv)->next, uv->next);\n}\n\n/* Find existing open upvalue for a stack slot or create a new one. */\nstatic GCupval *func_finduv(lua_State *L, TValue *slot)\n{\n  global_State *g = G(L);\n  GCRef *pp = &L->openupval;\n  GCupval *p;\n  GCupval *uv;\n  /* Search the sorted list of open upvalues. */\n  while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) {\n    lua_assert(!p->closed && uvval(p) != &p->tv);\n    if (uvval(p) == slot) {  /* Found open upvalue pointing to same slot? */\n      if (isdead(g, obj2gco(p)))  /* Resurrect it, if it's dead. */\n\tflipwhite(obj2gco(p));\n      return p;\n    }\n    pp = &p->nextgc;\n  }\n  /* No matching upvalue found. Create a new one. */\n  uv = lj_mem_newt(L, sizeof(GCupval), GCupval);\n  newwhite(g, uv);\n  uv->gct = ~LJ_TUPVAL;\n  uv->closed = 0;  /* Still open. */\n  setmref(uv->v, slot);  /* Pointing to the stack slot. */\n  /* NOBARRIER: The GCupval is new (marked white) and open. */\n  setgcrefr(uv->nextgc, *pp);  /* Insert into sorted list of open upvalues. */\n  setgcref(*pp, obj2gco(uv));\n  setgcref(uv->prev, obj2gco(&g->uvhead));  /* Insert into GC list, too. */\n  setgcrefr(uv->next, g->uvhead.next);\n  setgcref(uvnext(uv)->prev, obj2gco(uv));\n  setgcref(g->uvhead.next, obj2gco(uv));\n  lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);\n  return uv;\n}\n\n/* Create an empty and closed upvalue. */\nstatic GCupval *func_emptyuv(lua_State *L)\n{\n  GCupval *uv = (GCupval *)lj_mem_newgco(L, sizeof(GCupval));\n  uv->gct = ~LJ_TUPVAL;\n  uv->closed = 1;\n  setnilV(&uv->tv);\n  setmref(uv->v, &uv->tv);\n  return uv;\n}\n\n/* Close all open upvalues pointing to some stack level or above. */\nvoid LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level)\n{\n  GCupval *uv;\n  global_State *g = G(L);\n  while (gcref(L->openupval) != NULL &&\n\t uvval((uv = gco2uv(gcref(L->openupval)))) >= level) {\n    GCobj *o = obj2gco(uv);\n    lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv);\n    setgcrefr(L->openupval, uv->nextgc);  /* No longer in open list. */\n    if (isdead(g, o)) {\n      lj_func_freeuv(g, uv);\n    } else {\n      unlinkuv(uv);\n      lj_gc_closeuv(g, uv);\n    }\n  }\n}\n\nvoid LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv)\n{\n  if (!uv->closed)\n    unlinkuv(uv);\n  lj_mem_freet(g, uv);\n}\n\n/* -- Functions (closures) ------------------------------------------------ */\n\nGCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env)\n{\n  GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeCfunc(nelems));\n  fn->c.gct = ~LJ_TFUNC;\n  fn->c.ffid = FF_C;\n  fn->c.nupvalues = (uint8_t)nelems;\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  setmref(fn->c.pc, &G(L)->bc_cfunc_ext);\n  setgcref(fn->c.env, obj2gco(env));\n  return fn;\n}\n\nstatic GCfunc *func_newL(lua_State *L, GCproto *pt, GCtab *env)\n{\n  uint32_t count;\n  GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeLfunc((MSize)pt->sizeuv));\n  fn->l.gct = ~LJ_TFUNC;\n  fn->l.ffid = FF_LUA;\n  fn->l.nupvalues = 0;  /* Set to zero until upvalues are initialized. */\n  /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */\n  setmref(fn->l.pc, proto_bc(pt));\n  setgcref(fn->l.env, obj2gco(env));\n  /* Saturating 3 bit counter (0..7) for created closures. */\n  count = (uint32_t)pt->flags + PROTO_CLCOUNT;\n  pt->flags = (uint8_t)(count - ((count >> PROTO_CLC_BITS) & PROTO_CLCOUNT));\n  return fn;\n}\n\n/* Create a new Lua function with empty upvalues. */\nGCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env)\n{\n  GCfunc *fn = func_newL(L, pt, env);\n  MSize i, nuv = pt->sizeuv;\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  for (i = 0; i < nuv; i++) {\n    GCupval *uv = func_emptyuv(L);\n    uv->dhash = (uint32_t)(uintptr_t)pt ^ ((uint32_t)proto_uv(pt)[i] << 24);\n    setgcref(fn->l.uvptr[i], obj2gco(uv));\n  }\n  fn->l.nupvalues = (uint8_t)nuv;\n  return fn;\n}\n\n/* Do a GC check and create a new Lua function with inherited upvalues. */\nGCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)\n{\n  GCfunc *fn;\n  GCRef *puv;\n  MSize i, nuv;\n  TValue *base;\n  lj_gc_check_fixtop(L);\n  fn = func_newL(L, pt, tabref(parent->env));\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  puv = parent->uvptr;\n  nuv = pt->sizeuv;\n  base = L->base;\n  for (i = 0; i < nuv; i++) {\n    uint32_t v = proto_uv(pt)[i];\n    GCupval *uv;\n    if ((v & PROTO_UV_LOCAL)) {\n      uv = func_finduv(L, base + (v & 0xff));\n      uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1);\n      uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24);\n    } else {\n      uv = &gcref(puv[v])->uv;\n    }\n    setgcref(fn->l.uvptr[i], obj2gco(uv));\n  }\n  fn->l.nupvalues = (uint8_t)nuv;\n  return fn;\n}\n\nvoid LJ_FASTCALL lj_func_free(global_State *g, GCfunc *fn)\n{\n  MSize size = isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :\n\t\t\t       sizeCfunc((MSize)fn->c.nupvalues);\n  lj_mem_free(g, fn, size);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_func.h",
    "content": "/*\n** Function handling (prototypes, functions and upvalues).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FUNC_H\n#define _LJ_FUNC_H\n\n#include \"lj_obj.h\"\n\n/* Prototypes. */\nLJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt);\n\n/* Upvalues. */\nLJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level);\nLJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv);\n\n/* Functions (closures). */\nLJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env);\nLJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env);\nLJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent);\nLJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_gc.c",
    "content": "/*\n** Garbage collector.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_gc_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_udata.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n\n#define GCSTEPSIZE\t1024u\n#define GCSWEEPMAX\t40\n#define GCSWEEPCOST\t10\n#define GCFINALIZECOST\t100\n\n/* Macros to set GCobj colors and flags. */\n#define white2gray(x)\t\t((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES)\n#define gray2black(x)\t\t((x)->gch.marked |= LJ_GC_BLACK)\n#define isfinalized(u)\t\t((u)->marked & LJ_GC_FINALIZED)\n\n/* -- Mark phase ---------------------------------------------------------- */\n\n/* Mark a TValue (if needed). */\n#define gc_marktv(g, tv) \\\n  { lua_assert(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct)); \\\n    if (tviswhite(tv)) gc_mark(g, gcV(tv)); }\n\n/* Mark a GCobj (if needed). */\n#define gc_markobj(g, o) \\\n  { if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); }\n\n/* Mark a string object. */\n#define gc_mark_str(s)\t\t((s)->marked &= (uint8_t)~LJ_GC_WHITES)\n\n/* Mark a white GCobj. */\nstatic void gc_mark(global_State *g, GCobj *o)\n{\n  int gct = o->gch.gct;\n  lua_assert(iswhite(o) && !isdead(g, o));\n  white2gray(o);\n  if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) {\n    GCtab *mt = tabref(gco2ud(o)->metatable);\n    gray2black(o);  /* Userdata are never gray. */\n    if (mt) gc_markobj(g, mt);\n    gc_markobj(g, tabref(gco2ud(o)->env));\n  } else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) {\n    GCupval *uv = gco2uv(o);\n    gc_marktv(g, uvval(uv));\n    if (uv->closed)\n      gray2black(o);  /* Closed upvalues are never gray. */\n  } else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) {\n    lua_assert(gct == ~LJ_TFUNC || gct == ~LJ_TTAB ||\n\t       gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO || gct == ~LJ_TTRACE);\n    setgcrefr(o->gch.gclist, g->gc.gray);\n    setgcref(g->gc.gray, o);\n  }\n}\n\n/* Mark GC roots. */\nstatic void gc_mark_gcroot(global_State *g)\n{\n  ptrdiff_t i;\n  for (i = 0; i < GCROOT_MAX; i++)\n    if (gcref(g->gcroot[i]) != NULL)\n      gc_markobj(g, gcref(g->gcroot[i]));\n}\n\n/* Start a GC cycle and mark the root set. */\nstatic void gc_mark_start(global_State *g)\n{\n  setgcrefnull(g->gc.gray);\n  setgcrefnull(g->gc.grayagain);\n  setgcrefnull(g->gc.weak);\n  gc_markobj(g, mainthread(g));\n  gc_markobj(g, tabref(mainthread(g)->env));\n  gc_marktv(g, &g->registrytv);\n  gc_mark_gcroot(g);\n  g->gc.state = GCSpropagate;\n}\n\n/* Mark open upvalues. */\nstatic void gc_mark_uv(global_State *g)\n{\n  GCupval *uv;\n  for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {\n    lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);\n    if (isgray(obj2gco(uv)))\n      gc_marktv(g, uvval(uv));\n  }\n}\n\n/* Mark userdata in mmudata list. */\nstatic void gc_mark_mmudata(global_State *g)\n{\n  GCobj *root = gcref(g->gc.mmudata);\n  GCobj *u = root;\n  if (u) {\n    do {\n      u = gcnext(u);\n      makewhite(g, u);  /* Could be from previous GC. */\n      gc_mark(g, u);\n    } while (u != root);\n  }\n}\n\n/* Separate userdata objects to be finalized to mmudata list. */\nsize_t lj_gc_separateudata(global_State *g, int all)\n{\n  size_t m = 0;\n  GCRef *p = &mainthread(g)->nextgc;\n  GCobj *o;\n  while ((o = gcref(*p)) != NULL) {\n    if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) {\n      p = &o->gch.nextgc;  /* Nothing to do. */\n    } else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) {\n      markfinalized(o);  /* Done, as there's no __gc metamethod. */\n      p = &o->gch.nextgc;\n    } else {  /* Otherwise move userdata to be finalized to mmudata list. */\n      m += sizeudata(gco2ud(o));\n      markfinalized(o);\n      *p = o->gch.nextgc;\n      if (gcref(g->gc.mmudata)) {  /* Link to end of mmudata list. */\n\tGCobj *root = gcref(g->gc.mmudata);\n\tsetgcrefr(o->gch.nextgc, root->gch.nextgc);\n\tsetgcref(root->gch.nextgc, o);\n\tsetgcref(g->gc.mmudata, o);\n      } else {  /* Create circular list. */\n\tsetgcref(o->gch.nextgc, o);\n\tsetgcref(g->gc.mmudata, o);\n      }\n    }\n  }\n  return m;\n}\n\n/* -- Propagation phase --------------------------------------------------- */\n\n/* Traverse a table. */\nstatic int gc_traverse_tab(global_State *g, GCtab *t)\n{\n  int weak = 0;\n  cTValue *mode;\n  GCtab *mt = tabref(t->metatable);\n  if (mt)\n    gc_markobj(g, mt);\n  mode = lj_meta_fastg(g, mt, MM_mode);\n  if (mode && tvisstr(mode)) {  /* Valid __mode field? */\n    const char *modestr = strVdata(mode);\n    int c;\n    while ((c = *modestr++)) {\n      if (c == 'k') weak |= LJ_GC_WEAKKEY;\n      else if (c == 'v') weak |= LJ_GC_WEAKVAL;\n      else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL);\n    }\n    if (weak > 0) {  /* Weak tables are cleared in the atomic phase. */\n      t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);\n      setgcrefr(t->gclist, g->gc.weak);\n      setgcref(g->gc.weak, obj2gco(t));\n    }\n  }\n  if (weak == LJ_GC_WEAK)  /* Nothing to mark if both keys/values are weak. */\n    return 1;\n  if (!(weak & LJ_GC_WEAKVAL)) {  /* Mark array part. */\n    MSize i, asize = t->asize;\n    for (i = 0; i < asize; i++)\n      gc_marktv(g, arrayslot(t, i));\n  }\n  if (t->hmask > 0) {  /* Mark hash part. */\n    Node *node = noderef(t->node);\n    MSize i, hmask = t->hmask;\n    for (i = 0; i <= hmask; i++) {\n      Node *n = &node[i];\n      if (!tvisnil(&n->val)) {  /* Mark non-empty slot. */\n\tlua_assert(!tvisnil(&n->key));\n\tif (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key);\n\tif (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val);\n      }\n    }\n  }\n  return weak;\n}\n\n/* Traverse a function. */\nstatic void gc_traverse_func(global_State *g, GCfunc *fn)\n{\n  gc_markobj(g, tabref(fn->c.env));\n  if (isluafunc(fn)) {\n    uint32_t i;\n    lua_assert(fn->l.nupvalues <= funcproto(fn)->sizeuv);\n    gc_markobj(g, funcproto(fn));\n    for (i = 0; i < fn->l.nupvalues; i++)  /* Mark Lua function upvalues. */\n      gc_markobj(g, &gcref(fn->l.uvptr[i])->uv);\n  } else {\n    uint32_t i;\n    for (i = 0; i < fn->c.nupvalues; i++)  /* Mark C function upvalues. */\n      gc_marktv(g, &fn->c.upvalue[i]);\n  }\n}\n\n#if LJ_HASJIT\n/* Mark a trace. */\nstatic void gc_marktrace(global_State *g, TraceNo traceno)\n{\n  GCobj *o = obj2gco(traceref(G2J(g), traceno));\n  lua_assert(traceno != G2J(g)->cur.traceno);\n  if (iswhite(o)) {\n    white2gray(o);\n    setgcrefr(o->gch.gclist, g->gc.gray);\n    setgcref(g->gc.gray, o);\n  }\n}\n\n/* Traverse a trace. */\nstatic void gc_traverse_trace(global_State *g, GCtrace *T)\n{\n  IRRef ref;\n  if (T->traceno == 0) return;\n  for (ref = T->nk; ref < REF_TRUE; ref++) {\n    IRIns *ir = &T->ir[ref];\n    if (ir->o == IR_KGC)\n      gc_markobj(g, ir_kgc(ir));\n  }\n  if (T->link) gc_marktrace(g, T->link);\n  if (T->nextroot) gc_marktrace(g, T->nextroot);\n  if (T->nextside) gc_marktrace(g, T->nextside);\n  gc_markobj(g, gcref(T->startpt));\n}\n\n/* The current trace is a GC root while not anchored in the prototype (yet). */\n#define gc_traverse_curtrace(g)\tgc_traverse_trace(g, &G2J(g)->cur)\n#else\n#define gc_traverse_curtrace(g)\tUNUSED(g)\n#endif\n\n/* Traverse a prototype. */\nstatic void gc_traverse_proto(global_State *g, GCproto *pt)\n{\n  ptrdiff_t i;\n  gc_mark_str(proto_chunkname(pt));\n  for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++)  /* Mark collectable consts. */\n    gc_markobj(g, proto_kgc(pt, i));\n#if LJ_HASJIT\n  if (pt->trace) gc_marktrace(g, pt->trace);\n#endif\n}\n\n/* Traverse the frame structure of a stack. */\nstatic MSize gc_traverse_frames(global_State *g, lua_State *th)\n{\n  TValue *frame, *top = th->top-1, *bot = tvref(th->stack);\n  /* Note: extra vararg frame not skipped, marks function twice (harmless). */\n  for (frame = th->base-1; frame > bot+LJ_FR2; frame = frame_prev(frame)) {\n    GCfunc *fn = frame_func(frame);\n    TValue *ftop = frame;\n    if (isluafunc(fn)) ftop += funcproto(fn)->framesize;\n    if (ftop > top) top = ftop;\n    if (!LJ_FR2) gc_markobj(g, fn);  /* Need to mark hidden function (or L). */\n  }\n  top++;  /* Correct bias of -1 (frame == base-1). */\n  if (top > tvref(th->maxstack)) top = tvref(th->maxstack);\n  return (MSize)(top - bot);  /* Return minimum needed stack size. */\n}\n\n/* Traverse a thread object. */\nstatic void gc_traverse_thread(global_State *g, lua_State *th)\n{\n  TValue *o, *top = th->top;\n  for (o = tvref(th->stack)+1+LJ_FR2; o < top; o++)\n    gc_marktv(g, o);\n  if (g->gc.state == GCSatomic) {\n    top = tvref(th->stack) + th->stacksize;\n    for (; o < top; o++)  /* Clear unmarked slots. */\n      setnilV(o);\n  }\n  gc_markobj(g, tabref(th->env));\n  lj_state_shrinkstack(th, gc_traverse_frames(g, th));\n}\n\n/* Propagate one gray object. Traverse it and turn it black. */\nstatic size_t propagatemark(global_State *g)\n{\n  GCobj *o = gcref(g->gc.gray);\n  int gct = o->gch.gct;\n  lua_assert(isgray(o));\n  gray2black(o);\n  setgcrefr(g->gc.gray, o->gch.gclist);  /* Remove from gray list. */\n  if (LJ_LIKELY(gct == ~LJ_TTAB)) {\n    GCtab *t = gco2tab(o);\n    if (gc_traverse_tab(g, t) > 0)\n      black2gray(o);  /* Keep weak tables gray. */\n    return sizeof(GCtab) + sizeof(TValue) * t->asize +\n\t\t\t   sizeof(Node) * (t->hmask + 1);\n  } else if (LJ_LIKELY(gct == ~LJ_TFUNC)) {\n    GCfunc *fn = gco2func(o);\n    gc_traverse_func(g, fn);\n    return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :\n\t\t\t   sizeCfunc((MSize)fn->c.nupvalues);\n  } else if (LJ_LIKELY(gct == ~LJ_TPROTO)) {\n    GCproto *pt = gco2pt(o);\n    gc_traverse_proto(g, pt);\n    return pt->sizept;\n  } else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) {\n    lua_State *th = gco2th(o);\n    setgcrefr(th->gclist, g->gc.grayagain);\n    setgcref(g->gc.grayagain, o);\n    black2gray(o);  /* Threads are never black. */\n    gc_traverse_thread(g, th);\n    return sizeof(lua_State) + sizeof(TValue) * th->stacksize;\n  } else {\n#if LJ_HASJIT\n    GCtrace *T = gco2trace(o);\n    gc_traverse_trace(g, T);\n    return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +\n\t   T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry);\n#else\n    lua_assert(0);\n    return 0;\n#endif\n  }\n}\n\n/* Propagate all gray objects. */\nstatic size_t gc_propagate_gray(global_State *g)\n{\n  size_t m = 0;\n  while (gcref(g->gc.gray) != NULL)\n    m += propagatemark(g);\n  return m;\n}\n\n/* -- Sweep phase --------------------------------------------------------- */\n\n/* Type of GC free functions. */\ntypedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o);\n\n/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */\nstatic const GCFreeFunc gc_freefunc[] = {\n  (GCFreeFunc)lj_str_free,\n  (GCFreeFunc)lj_func_freeuv,\n  (GCFreeFunc)lj_state_free,\n  (GCFreeFunc)lj_func_freeproto,\n  (GCFreeFunc)lj_func_free,\n#if LJ_HASJIT\n  (GCFreeFunc)lj_trace_free,\n#else\n  (GCFreeFunc)0,\n#endif\n#if LJ_HASFFI\n  (GCFreeFunc)lj_cdata_free,\n#else\n  (GCFreeFunc)0,\n#endif\n  (GCFreeFunc)lj_tab_free,\n  (GCFreeFunc)lj_udata_free\n};\n\n/* Full sweep of a GC list. */\n#define gc_fullsweep(g, p)\tgc_sweep(g, (p), ~(uint32_t)0)\n\n/* Partial sweep of a GC list. */\nstatic GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim)\n{\n  /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */\n  int ow = otherwhite(g);\n  GCobj *o;\n  while ((o = gcref(*p)) != NULL && lim-- > 0) {\n    if (o->gch.gct == ~LJ_TTHREAD)  /* Need to sweep open upvalues, too. */\n      gc_fullsweep(g, &gco2th(o)->openupval);\n    if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) {  /* Black or current white? */\n      lua_assert(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED));\n      makewhite(g, o);  /* Value is alive, change to the current white. */\n      p = &o->gch.nextgc;\n    } else {  /* Otherwise value is dead, free it. */\n      lua_assert(isdead(g, o) || ow == LJ_GC_SFIXED);\n      setgcrefr(*p, o->gch.nextgc);\n      if (o == gcref(g->gc.root))\n\tsetgcrefr(g->gc.root, o->gch.nextgc);  /* Adjust list anchor. */\n      gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o);\n    }\n  }\n  return p;\n}\n\n/* Check whether we can clear a key or a value slot from a table. */\nstatic int gc_mayclear(cTValue *o, int val)\n{\n  if (tvisgcv(o)) {  /* Only collectable objects can be weak references. */\n    if (tvisstr(o)) {  /* But strings cannot be used as weak references. */\n      gc_mark_str(strV(o));  /* And need to be marked. */\n      return 0;\n    }\n    if (iswhite(gcV(o)))\n      return 1;  /* Object is about to be collected. */\n    if (tvisudata(o) && val && isfinalized(udataV(o)))\n      return 1;  /* Finalized userdata is dropped only from values. */\n  }\n  return 0;  /* Cannot clear. */\n}\n\n/* Clear collected entries from weak tables. */\nstatic void gc_clearweak(GCobj *o)\n{\n  while (o) {\n    GCtab *t = gco2tab(o);\n    lua_assert((t->marked & LJ_GC_WEAK));\n    if ((t->marked & LJ_GC_WEAKVAL)) {\n      MSize i, asize = t->asize;\n      for (i = 0; i < asize; i++) {\n\t/* Clear array slot when value is about to be collected. */\n\tTValue *tv = arrayslot(t, i);\n\tif (gc_mayclear(tv, 1))\n\t  setnilV(tv);\n      }\n    }\n    if (t->hmask > 0) {\n      Node *node = noderef(t->node);\n      MSize i, hmask = t->hmask;\n      for (i = 0; i <= hmask; i++) {\n\tNode *n = &node[i];\n\t/* Clear hash slot when key or value is about to be collected. */\n\tif (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) ||\n\t\t\t\t  gc_mayclear(&n->val, 1)))\n\t  setnilV(&n->val);\n      }\n    }\n    o = gcref(t->gclist);\n  }\n}\n\n/* Call a userdata or cdata finalizer. */\nstatic void gc_call_finalizer(global_State *g, lua_State *L,\n\t\t\t      cTValue *mo, GCobj *o)\n{\n  /* Save and restore lots of state around the __gc callback. */\n  uint8_t oldh = hook_save(g);\n  GCSize oldt = g->gc.threshold;\n  int errcode;\n  TValue *top;\n  lj_trace_abort(g);\n  hook_entergc(g);  /* Disable hooks and new traces during __gc. */\n  g->gc.threshold = LJ_MAX_MEM;  /* Prevent GC steps. */\n  top = L->top;\n  copyTV(L, top++, mo);\n  if (LJ_FR2) setnilV(top++);\n  setgcV(L, top, o, ~o->gch.gct);\n  L->top = top+1;\n  errcode = lj_vm_pcall(L, top, 1+0, -1);  /* Stack: |mo|o| -> | */\n  hook_restore(g, oldh);\n  g->gc.threshold = oldt;  /* Restore GC threshold. */\n  if (errcode)\n    lj_err_throw(L, errcode);  /* Propagate errors. */\n}\n\n/* Finalize one userdata or cdata object from the mmudata list. */\nstatic void gc_finalize(lua_State *L)\n{\n  global_State *g = G(L);\n  GCobj *o = gcnext(gcref(g->gc.mmudata));\n  cTValue *mo;\n  lua_assert(tvref(g->jit_base) == NULL);  /* Must not be called on trace. */\n  /* Unchain from list of userdata to be finalized. */\n  if (o == gcref(g->gc.mmudata))\n    setgcrefnull(g->gc.mmudata);\n  else\n    setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc);\n#if LJ_HASFFI\n  if (o->gch.gct == ~LJ_TCDATA) {\n    TValue tmp, *tv;\n    /* Add cdata back to the GC list and make it white. */\n    setgcrefr(o->gch.nextgc, g->gc.root);\n    setgcref(g->gc.root, o);\n    makewhite(g, o);\n    o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;\n    /* Resolve finalizer. */\n    setcdataV(L, &tmp, gco2cd(o));\n    tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp);\n    if (!tvisnil(tv)) {\n      g->gc.nocdatafin = 0;\n      copyTV(L, &tmp, tv);\n      setnilV(tv);  /* Clear entry in finalizer table. */\n      gc_call_finalizer(g, L, &tmp, o);\n    }\n    return;\n  }\n#endif\n  /* Add userdata back to the main userdata list and make it white. */\n  setgcrefr(o->gch.nextgc, mainthread(g)->nextgc);\n  setgcref(mainthread(g)->nextgc, o);\n  makewhite(g, o);\n  /* Resolve the __gc metamethod. */\n  mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc);\n  if (mo)\n    gc_call_finalizer(g, L, mo, o);\n}\n\n/* Finalize all userdata objects from mmudata list. */\nvoid lj_gc_finalize_udata(lua_State *L)\n{\n  while (gcref(G(L)->gc.mmudata) != NULL)\n    gc_finalize(L);\n}\n\n#if LJ_HASFFI\n/* Finalize all cdata objects from finalizer table. */\nvoid lj_gc_finalize_cdata(lua_State *L)\n{\n  global_State *g = G(L);\n  CTState *cts = ctype_ctsG(g);\n  if (cts) {\n    GCtab *t = cts->finalizer;\n    Node *node = noderef(t->node);\n    ptrdiff_t i;\n    setgcrefnull(t->metatable);  /* Mark finalizer table as disabled. */\n    for (i = (ptrdiff_t)t->hmask; i >= 0; i--)\n      if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) {\n\tGCobj *o = gcV(&node[i].key);\n\tTValue tmp;\n\tmakewhite(g, o);\n\to->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;\n\tcopyTV(L, &tmp, &node[i].val);\n\tsetnilV(&node[i].val);\n\tgc_call_finalizer(g, L, &tmp, o);\n      }\n  }\n}\n#endif\n\n/* Free all remaining GC objects. */\nvoid lj_gc_freeall(global_State *g)\n{\n  MSize i, strmask;\n  /* Free everything, except super-fixed objects (the main thread). */\n  g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED;\n  gc_fullsweep(g, &g->gc.root);\n  strmask = g->strmask;\n  for (i = 0; i <= strmask; i++)  /* Free all string hash chains. */\n    gc_fullsweep(g, &g->strhash[i]);\n}\n\n/* -- Collector ----------------------------------------------------------- */\n\n/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */\nstatic void atomic(global_State *g, lua_State *L)\n{\n  size_t udsize;\n\n  gc_mark_uv(g);  /* Need to remark open upvalues (the thread may be dead). */\n  gc_propagate_gray(g);  /* Propagate any left-overs. */\n\n  setgcrefr(g->gc.gray, g->gc.weak);  /* Empty the list of weak tables. */\n  setgcrefnull(g->gc.weak);\n  lua_assert(!iswhite(obj2gco(mainthread(g))));\n  gc_markobj(g, L);  /* Mark running thread. */\n  gc_traverse_curtrace(g);  /* Traverse current trace. */\n  gc_mark_gcroot(g);  /* Mark GC roots (again). */\n  gc_propagate_gray(g);  /* Propagate all of the above. */\n\n  setgcrefr(g->gc.gray, g->gc.grayagain);  /* Empty the 2nd chance list. */\n  setgcrefnull(g->gc.grayagain);\n  gc_propagate_gray(g);  /* Propagate it. */\n\n  udsize = lj_gc_separateudata(g, 0);  /* Separate userdata to be finalized. */\n  gc_mark_mmudata(g);  /* Mark them. */\n  udsize += gc_propagate_gray(g);  /* And propagate the marks. */\n\n  /* All marking done, clear weak tables. */\n  gc_clearweak(gcref(g->gc.weak));\n\n  lj_buf_shrink(L, &g->tmpbuf);  /* Shrink temp buffer. */\n\n  /* Prepare for sweep phase. */\n  g->gc.currentwhite = (uint8_t)otherwhite(g);  /* Flip current white. */\n  g->strempty.marked = g->gc.currentwhite;\n  setmref(g->gc.sweep, &g->gc.root);\n  g->gc.estimate = g->gc.total - (GCSize)udsize;  /* Initial estimate. */\n}\n\n/* GC state machine. Returns a cost estimate for each step performed. */\nstatic size_t gc_onestep(lua_State *L)\n{\n  global_State *g = G(L);\n  switch (g->gc.state) {\n  case GCSpause:\n    gc_mark_start(g);  /* Start a new GC cycle by marking all GC roots. */\n    return 0;\n  case GCSpropagate:\n    if (gcref(g->gc.gray) != NULL)\n      return propagatemark(g);  /* Propagate one gray object. */\n    g->gc.state = GCSatomic;  /* End of mark phase. */\n    return 0;\n  case GCSatomic:\n    if (tvref(g->jit_base))  /* Don't run atomic phase on trace. */\n      return LJ_MAX_MEM;\n    atomic(g, L);\n    g->gc.state = GCSsweepstring;  /* Start of sweep phase. */\n    g->gc.sweepstr = 0;\n    return 0;\n  case GCSsweepstring: {\n    GCSize old = g->gc.total;\n    gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]);  /* Sweep one chain. */\n    if (g->gc.sweepstr > g->strmask)\n      g->gc.state = GCSsweep;  /* All string hash chains sweeped. */\n    lua_assert(old >= g->gc.total);\n    g->gc.estimate -= old - g->gc.total;\n    return GCSWEEPCOST;\n    }\n  case GCSsweep: {\n    GCSize old = g->gc.total;\n    setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));\n    lua_assert(old >= g->gc.total);\n    g->gc.estimate -= old - g->gc.total;\n    if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {\n      if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)\n\tlj_str_resize(L, g->strmask >> 1);  /* Shrink string table. */\n      if (gcref(g->gc.mmudata)) {  /* Need any finalizations? */\n\tg->gc.state = GCSfinalize;\n#if LJ_HASFFI\n\tg->gc.nocdatafin = 1;\n#endif\n      } else {  /* Otherwise skip this phase to help the JIT. */\n\tg->gc.state = GCSpause;  /* End of GC cycle. */\n\tg->gc.debt = 0;\n      }\n    }\n    return GCSWEEPMAX*GCSWEEPCOST;\n    }\n  case GCSfinalize:\n    if (gcref(g->gc.mmudata) != NULL) {\n      if (tvref(g->jit_base))  /* Don't call finalizers on trace. */\n\treturn LJ_MAX_MEM;\n      gc_finalize(L);  /* Finalize one userdata object. */\n      if (g->gc.estimate > GCFINALIZECOST)\n\tg->gc.estimate -= GCFINALIZECOST;\n      return GCFINALIZECOST;\n    }\n#if LJ_HASFFI\n    if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer);\n#endif\n    g->gc.state = GCSpause;  /* End of GC cycle. */\n    g->gc.debt = 0;\n    return 0;\n  default:\n    lua_assert(0);\n    return 0;\n  }\n}\n\n/* Perform a limited amount of incremental GC steps. */\nint LJ_FASTCALL lj_gc_step(lua_State *L)\n{\n  global_State *g = G(L);\n  GCSize lim;\n  int32_t ostate = g->vmstate;\n  setvmstate(g, GC);\n  lim = (GCSTEPSIZE/100) * g->gc.stepmul;\n  if (lim == 0)\n    lim = LJ_MAX_MEM;\n  if (g->gc.total > g->gc.threshold)\n    g->gc.debt += g->gc.total - g->gc.threshold;\n  do {\n    lim -= (GCSize)gc_onestep(L);\n    if (g->gc.state == GCSpause) {\n      g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;\n      g->vmstate = ostate;\n      return 1;  /* Finished a GC cycle. */\n    }\n  } while (sizeof(lim) == 8 ? ((int64_t)lim > 0) : ((int32_t)lim > 0));\n  if (g->gc.debt < GCSTEPSIZE) {\n    g->gc.threshold = g->gc.total + GCSTEPSIZE;\n    g->vmstate = ostate;\n    return -1;\n  } else {\n    g->gc.debt -= GCSTEPSIZE;\n    g->gc.threshold = g->gc.total;\n    g->vmstate = ostate;\n    return 0;\n  }\n}\n\n/* Ditto, but fix the stack top first. */\nvoid LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)\n{\n  if (curr_funcisL(L)) L->top = curr_topL(L);\n  lj_gc_step(L);\n}\n\n#if LJ_HASJIT\n/* Perform multiple GC steps. Called from JIT-compiled code. */\nint LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)\n{\n  lua_State *L = gco2th(gcref(g->cur_L));\n  L->base = tvref(G(L)->jit_base);\n  L->top = curr_topL(L);\n  while (steps-- > 0 && lj_gc_step(L) == 0)\n    ;\n  /* Return 1 to force a trace exit. */\n  return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize);\n}\n#endif\n\n/* Perform a full GC cycle. */\nvoid lj_gc_fullgc(lua_State *L)\n{\n  global_State *g = G(L);\n  int32_t ostate = g->vmstate;\n  setvmstate(g, GC);\n  if (g->gc.state <= GCSatomic) {  /* Caught somewhere in the middle. */\n    setmref(g->gc.sweep, &g->gc.root);  /* Sweep everything (preserving it). */\n    setgcrefnull(g->gc.gray);  /* Reset lists from partial propagation. */\n    setgcrefnull(g->gc.grayagain);\n    setgcrefnull(g->gc.weak);\n    g->gc.state = GCSsweepstring;  /* Fast forward to the sweep phase. */\n    g->gc.sweepstr = 0;\n  }\n  while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep)\n    gc_onestep(L);  /* Finish sweep. */\n  lua_assert(g->gc.state == GCSfinalize || g->gc.state == GCSpause);\n  /* Now perform a full GC. */\n  g->gc.state = GCSpause;\n  do { gc_onestep(L); } while (g->gc.state != GCSpause);\n  g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;\n  g->vmstate = ostate;\n}\n\n/* -- Write barriers ------------------------------------------------------ */\n\n/* Move the GC propagation frontier forward. */\nvoid lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v)\n{\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);\n  lua_assert(o->gch.gct != ~LJ_TTAB);\n  /* Preserve invariant during propagation. Otherwise it doesn't matter. */\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_mark(g, v);  /* Move frontier forward. */\n  else\n    makewhite(g, o);  /* Make it white to avoid the following barrier. */\n}\n\n/* Specialized barrier for closed upvalue. Pass &uv->tv. */\nvoid LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv)\n{\n#define TV2MARKED(x) \\\n  (*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked)))\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_mark(g, gcV(tv));\n  else\n    TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g);\n#undef TV2MARKED\n}\n\n/* Close upvalue. Also needs a write barrier. */\nvoid lj_gc_closeuv(global_State *g, GCupval *uv)\n{\n  GCobj *o = obj2gco(uv);\n  /* Copy stack slot to upvalue itself and point to the copy. */\n  copyTV(mainthread(g), &uv->tv, uvval(uv));\n  setmref(uv->v, &uv->tv);\n  uv->closed = 1;\n  setgcrefr(o->gch.nextgc, g->gc.root);\n  setgcref(g->gc.root, o);\n  if (isgray(o)) {  /* A closed upvalue is never gray, so fix this. */\n    if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) {\n      gray2black(o);  /* Make it black and preserve invariant. */\n      if (tviswhite(&uv->tv))\n\tlj_gc_barrierf(g, o, gcV(&uv->tv));\n    } else {\n      makewhite(g, o);  /* Make it white, i.e. sweep the upvalue. */\n      lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);\n    }\n  }\n}\n\n#if LJ_HASJIT\n/* Mark a trace if it's saved during the propagation phase. */\nvoid lj_gc_barriertrace(global_State *g, uint32_t traceno)\n{\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_marktrace(g, traceno);\n}\n#endif\n\n/* -- Allocator ----------------------------------------------------------- */\n\n/* Call pluggable memory allocator to allocate or resize a fragment. */\nvoid *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz)\n{\n  global_State *g = G(L);\n  lua_assert((osz == 0) == (p == NULL));\n  p = g->allocf(g->allocd, p, osz, nsz);\n  if (p == NULL && nsz > 0)\n    lj_err_mem(L);\n  lua_assert((nsz == 0) == (p == NULL));\n  lua_assert(checkptrGC(p));\n  g->gc.total = (g->gc.total - osz) + nsz;\n  return p;\n}\n\n/* Allocate new GC object and link it to the root set. */\nvoid * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size)\n{\n  global_State *g = G(L);\n  GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size);\n  if (o == NULL)\n    lj_err_mem(L);\n  lua_assert(checkptrGC(o));\n  g->gc.total += size;\n  setgcrefr(o->gch.nextgc, g->gc.root);\n  setgcref(g->gc.root, o);\n  newwhite(g, o);\n  return o;\n}\n\n/* Resize growable vector. */\nvoid *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz)\n{\n  MSize sz = (*szp) << 1;\n  if (sz < LJ_MIN_VECSZ)\n    sz = LJ_MIN_VECSZ;\n  if (sz > lim)\n    sz = lim;\n  p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz);\n  *szp = sz;\n  return p;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_gc.h",
    "content": "/*\n** Garbage collector.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_GC_H\n#define _LJ_GC_H\n\n#include \"lj_obj.h\"\n\n/* Garbage collector states. Order matters. */\nenum {\n  GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize\n};\n\n/* Bitmasks for marked field of GCobj. */\n#define LJ_GC_WHITE0\t0x01\n#define LJ_GC_WHITE1\t0x02\n#define LJ_GC_BLACK\t0x04\n#define LJ_GC_FINALIZED\t0x08\n#define LJ_GC_WEAKKEY\t0x08\n#define LJ_GC_WEAKVAL\t0x10\n#define LJ_GC_CDATA_FIN\t0x10\n#define LJ_GC_FIXED\t0x20\n#define LJ_GC_SFIXED\t0x40\n\n#define LJ_GC_WHITES\t(LJ_GC_WHITE0 | LJ_GC_WHITE1)\n#define LJ_GC_COLORS\t(LJ_GC_WHITES | LJ_GC_BLACK)\n#define LJ_GC_WEAK\t(LJ_GC_WEAKKEY | LJ_GC_WEAKVAL)\n\n/* Macros to test and set GCobj colors. */\n#define iswhite(x)\t((x)->gch.marked & LJ_GC_WHITES)\n#define isblack(x)\t((x)->gch.marked & LJ_GC_BLACK)\n#define isgray(x)\t(!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES)))\n#define tviswhite(x)\t(tvisgcv(x) && iswhite(gcV(x)))\n#define otherwhite(g)\t(g->gc.currentwhite ^ LJ_GC_WHITES)\n#define isdead(g, v)\t((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES)\n\n#define curwhite(g)\t((g)->gc.currentwhite & LJ_GC_WHITES)\n#define newwhite(g, x)\t(obj2gco(x)->gch.marked = (uint8_t)curwhite(g))\n#define makewhite(g, x) \\\n  ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))\n#define flipwhite(x)\t((x)->gch.marked ^= LJ_GC_WHITES)\n#define black2gray(x)\t((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)\n#define fixstring(s)\t((s)->marked |= LJ_GC_FIXED)\n#define markfinalized(x)\t((x)->gch.marked |= LJ_GC_FINALIZED)\n\n/* Collector. */\nLJ_FUNC size_t lj_gc_separateudata(global_State *g, int all);\nLJ_FUNC void lj_gc_finalize_udata(lua_State *L);\n#if LJ_HASFFI\nLJ_FUNC void lj_gc_finalize_cdata(lua_State *L);\n#else\n#define lj_gc_finalize_cdata(L)\t\tUNUSED(L)\n#endif\nLJ_FUNC void lj_gc_freeall(global_State *g);\nLJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L);\nLJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L);\n#if LJ_HASJIT\nLJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps);\n#endif\nLJ_FUNC void lj_gc_fullgc(lua_State *L);\n\n/* GC check: drive collector forward if the GC threshold has been reached. */\n#define lj_gc_check(L) \\\n  { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \\\n      lj_gc_step(L); }\n#define lj_gc_check_fixtop(L) \\\n  { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \\\n      lj_gc_step_fixtop(L); }\n\n/* Write barriers. */\nLJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v);\nLJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv);\nLJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv);\n#if LJ_HASJIT\nLJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno);\n#endif\n\n/* Move the GC propagation frontier back for tables (make it gray again). */\nstatic LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)\n{\n  GCobj *o = obj2gco(t);\n  lua_assert(isblack(o) && !isdead(g, o));\n  lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);\n  black2gray(o);\n  setgcrefr(t->gclist, g->gc.grayagain);\n  setgcref(g->gc.grayagain, o);\n}\n\n/* Barrier for stores to table objects. TValue and GCobj variant. */\n#define lj_gc_anybarriert(L, t)  \\\n  { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); }\n#define lj_gc_barriert(L, t, tv) \\\n  { if (tviswhite(tv) && isblack(obj2gco(t))) \\\n      lj_gc_barrierback(G(L), (t)); }\n#define lj_gc_objbarriert(L, t, o)  \\\n  { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \\\n      lj_gc_barrierback(G(L), (t)); }\n\n/* Barrier for stores to any other object. TValue and GCobj variant. */\n#define lj_gc_barrier(L, p, tv) \\\n  { if (tviswhite(tv) && isblack(obj2gco(p))) \\\n      lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); }\n#define lj_gc_objbarrier(L, p, o) \\\n  { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \\\n      lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }\n\n/* Allocator. */\nLJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz);\nLJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size);\nLJ_FUNC void *lj_mem_grow(lua_State *L, void *p,\n\t\t\t  MSize *szp, MSize lim, MSize esz);\n\n#define lj_mem_new(L, s)\tlj_mem_realloc(L, NULL, 0, (s))\n\nstatic LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)\n{\n  g->gc.total -= (GCSize)osize;\n  g->allocf(g->allocd, p, osize, 0);\n}\n\n#define lj_mem_newvec(L, n, t)\t((t *)lj_mem_new(L, (GCSize)((n)*sizeof(t))))\n#define lj_mem_reallocvec(L, p, on, n, t) \\\n  ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (GCSize)((n)*sizeof(t))))\n#define lj_mem_growvec(L, p, n, m, t) \\\n  ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))\n#define lj_mem_freevec(g, p, n, t)\tlj_mem_free(g, (p), (n)*sizeof(t))\n\n#define lj_mem_newobj(L, t)\t((t *)lj_mem_newgco(L, sizeof(t)))\n#define lj_mem_newt(L, s, t)\t((t *)lj_mem_new(L, (s)))\n#define lj_mem_freet(g, p)\tlj_mem_free(g, (p), sizeof(*(p)))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_gdbjit.c",
    "content": "/*\n** Client for the GDB JIT API.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_gdbjit_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_frame.h\"\n#include \"lj_buf.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_jit.h\"\n#include \"lj_dispatch.h\"\n\n/* This is not compiled in by default.\n** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything.\n*/\n#ifdef LUAJIT_USE_GDBJIT\n\n/* The GDB JIT API allows JIT compilers to pass debug information about\n** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher\n** to see it in action.\n**\n** This is a passive API, so it works even when not running under GDB\n** or when attaching to an already running process. Alas, this implies\n** enabling it always has a non-negligible overhead -- do not use in\n** release mode!\n**\n** The LuaJIT GDB JIT client is rather minimal at the moment. It gives\n** each trace a symbol name and adds a source location and frame unwind\n** information. Obviously LuaJIT itself and any embedding C application\n** should be compiled with debug symbols, too (see the Makefile).\n**\n** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace\n** numbers from -jv or -jdump. Use \"break TRACE_1\" or \"tbreak TRACE_1\" etc.\n** to set breakpoints on specific traces (even ahead of their creation).\n**\n** The source location for each trace allows listing the corresponding\n** source lines with the GDB command \"list\" (but only if the Lua source\n** has been loaded from a file). Currently this is always set to the\n** location where the trace has been started.\n**\n** Frame unwind information can be inspected with the GDB command\n** \"info frame\". This also allows proper backtraces across JIT-compiled\n** code with the GDB command \"bt\".\n**\n** You probably want to add the following settings to a .gdbinit file\n** (or add them to ~/.gdbinit):\n**   set disassembly-flavor intel\n**   set breakpoint pending on\n**\n** Here's a sample GDB session:\n** ------------------------------------------------------------------------\n\n$ cat >x.lua\nfor outer=1,100 do\n  for inner=1,100 do end\nend\n^D\n\n$ luajit -jv x.lua\n[TRACE   1 x.lua:2]\n[TRACE   2 (1/3) x.lua:1 -> 1]\n\n$ gdb --quiet --args luajit x.lua\n(gdb) tbreak TRACE_1\nFunction \"TRACE_1\" not defined.\nTemporary breakpoint 1 (TRACE_1) pending.\n(gdb) run\nStarting program: luajit x.lua\n\nTemporary breakpoint 1, TRACE_1 () at x.lua:2\n2\t  for inner=1,100 do end\n(gdb) list\n1\tfor outer=1,100 do\n2\t  for inner=1,100 do end\n3\tend\n(gdb) bt\n#0  TRACE_1 () at x.lua:2\n#1  0x08053690 in lua_pcall [...]\n[...]\n#7  0x0806ff90 in main [...]\n(gdb) disass TRACE_1\nDump of assembler code for function TRACE_1:\n0xf7fd9fba <TRACE_1+0>:\tmov    DWORD PTR ds:0xf7e0e2a0,0x1\n0xf7fd9fc4 <TRACE_1+10>:\tmovsd  xmm7,QWORD PTR [edx+0x20]\n[...]\n0xf7fd9ff8 <TRACE_1+62>:\tjmp    0xf7fd2014\nEnd of assembler dump.\n(gdb) tbreak TRACE_2\nFunction \"TRACE_2\" not defined.\nTemporary breakpoint 2 (TRACE_2) pending.\n(gdb) cont\nContinuing.\n\nTemporary breakpoint 2, TRACE_2 () at x.lua:1\n1\tfor outer=1,100 do\n(gdb) info frame\nStack level 0, frame at 0xffffd7c0:\n eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690\n called by frame at 0xffffd7e0\n source language unknown.\n Arglist at 0xffffd78c, args:\n Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0\n Saved registers:\n  ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4,\n  eip at 0xffffd7bc\n(gdb)\n\n** ------------------------------------------------------------------------\n*/\n\n/* -- GDB JIT API --------------------------------------------------------- */\n\n/* GDB JIT actions. */\nenum {\n  GDBJIT_NOACTION = 0,\n  GDBJIT_REGISTER,\n  GDBJIT_UNREGISTER\n};\n\n/* GDB JIT entry. */\ntypedef struct GDBJITentry {\n  struct GDBJITentry *next_entry;\n  struct GDBJITentry *prev_entry;\n  const char *symfile_addr;\n  uint64_t symfile_size;\n} GDBJITentry;\n\n/* GDB JIT descriptor. */\ntypedef struct GDBJITdesc {\n  uint32_t version;\n  uint32_t action_flag;\n  GDBJITentry *relevant_entry;\n  GDBJITentry *first_entry;\n} GDBJITdesc;\n\nGDBJITdesc __jit_debug_descriptor = {\n  1, GDBJIT_NOACTION, NULL, NULL\n};\n\n/* GDB sets a breakpoint at this function. */\nvoid LJ_NOINLINE __jit_debug_register_code()\n{\n  __asm__ __volatile__(\"\");\n};\n\n/* -- In-memory ELF object definitions ------------------------------------ */\n\n/* ELF definitions. */\ntypedef struct ELFheader {\n  uint8_t emagic[4];\n  uint8_t eclass;\n  uint8_t eendian;\n  uint8_t eversion;\n  uint8_t eosabi;\n  uint8_t eabiversion;\n  uint8_t epad[7];\n  uint16_t type;\n  uint16_t machine;\n  uint32_t version;\n  uintptr_t entry;\n  uintptr_t phofs;\n  uintptr_t shofs;\n  uint32_t flags;\n  uint16_t ehsize;\n  uint16_t phentsize;\n  uint16_t phnum;\n  uint16_t shentsize;\n  uint16_t shnum;\n  uint16_t shstridx;\n} ELFheader;\n\ntypedef struct ELFsectheader {\n  uint32_t name;\n  uint32_t type;\n  uintptr_t flags;\n  uintptr_t addr;\n  uintptr_t ofs;\n  uintptr_t size;\n  uint32_t link;\n  uint32_t info;\n  uintptr_t align;\n  uintptr_t entsize;\n} ELFsectheader;\n\n#define ELFSECT_IDX_ABS\t\t0xfff1\n\nenum {\n  ELFSECT_TYPE_PROGBITS = 1,\n  ELFSECT_TYPE_SYMTAB = 2,\n  ELFSECT_TYPE_STRTAB = 3,\n  ELFSECT_TYPE_NOBITS = 8\n};\n\n#define ELFSECT_FLAGS_WRITE\t1\n#define ELFSECT_FLAGS_ALLOC\t2\n#define ELFSECT_FLAGS_EXEC\t4\n\ntypedef struct ELFsymbol {\n#if LJ_64\n  uint32_t name;\n  uint8_t info;\n  uint8_t other;\n  uint16_t sectidx;\n  uintptr_t value;\n  uint64_t size;\n#else\n  uint32_t name;\n  uintptr_t value;\n  uint32_t size;\n  uint8_t info;\n  uint8_t other;\n  uint16_t sectidx;\n#endif\n} ELFsymbol;\n\nenum {\n  ELFSYM_TYPE_FUNC = 2,\n  ELFSYM_TYPE_FILE = 4,\n  ELFSYM_BIND_LOCAL = 0 << 4,\n  ELFSYM_BIND_GLOBAL = 1 << 4,\n};\n\n/* DWARF definitions. */\n#define DW_CIE_VERSION\t1\n\nenum {\n  DW_CFA_nop = 0x0,\n  DW_CFA_offset_extended = 0x5,\n  DW_CFA_def_cfa = 0xc,\n  DW_CFA_def_cfa_offset = 0xe,\n  DW_CFA_offset_extended_sf = 0x11,\n  DW_CFA_advance_loc = 0x40,\n  DW_CFA_offset = 0x80\n};\n\nenum {\n  DW_EH_PE_udata4 = 3,\n  DW_EH_PE_textrel = 0x20\n};\n\nenum {\n  DW_TAG_compile_unit = 0x11\n};\n\nenum {\n  DW_children_no = 0,\n  DW_children_yes = 1\n};\n\nenum {\n  DW_AT_name = 0x03,\n  DW_AT_stmt_list = 0x10,\n  DW_AT_low_pc = 0x11,\n  DW_AT_high_pc = 0x12\n};\n\nenum {\n  DW_FORM_addr = 0x01,\n  DW_FORM_data4 = 0x06,\n  DW_FORM_string = 0x08\n};\n\nenum {\n  DW_LNS_extended_op = 0,\n  DW_LNS_copy = 1,\n  DW_LNS_advance_pc = 2,\n  DW_LNS_advance_line = 3\n};\n\nenum {\n  DW_LNE_end_sequence = 1,\n  DW_LNE_set_address = 2\n};\n\nenum {\n#if LJ_TARGET_X86\n  DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX,\n  DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI,\n  DW_REG_RA,\n#elif LJ_TARGET_X64\n  /* Yes, the order is strange, but correct. */\n  DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX,\n  DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP,\n  DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11,\n  DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15,\n  DW_REG_RA,\n#elif LJ_TARGET_ARM\n  DW_REG_SP = 13,\n  DW_REG_RA = 14,\n#elif LJ_TARGET_PPC\n  DW_REG_SP = 1,\n  DW_REG_RA = 65,\n  DW_REG_CR = 70,\n#elif LJ_TARGET_MIPS\n  DW_REG_SP = 29,\n  DW_REG_RA = 31,\n#else\n#error \"Unsupported target architecture\"\n#endif\n};\n\n/* Minimal list of sections for the in-memory ELF object. */\nenum {\n  GDBJIT_SECT_NULL,\n  GDBJIT_SECT_text,\n  GDBJIT_SECT_eh_frame,\n  GDBJIT_SECT_shstrtab,\n  GDBJIT_SECT_strtab,\n  GDBJIT_SECT_symtab,\n  GDBJIT_SECT_debug_info,\n  GDBJIT_SECT_debug_abbrev,\n  GDBJIT_SECT_debug_line,\n  GDBJIT_SECT__MAX\n};\n\nenum {\n  GDBJIT_SYM_UNDEF,\n  GDBJIT_SYM_FILE,\n  GDBJIT_SYM_FUNC,\n  GDBJIT_SYM__MAX\n};\n\n/* In-memory ELF object. */\ntypedef struct GDBJITobj {\n  ELFheader hdr;\t\t\t/* ELF header. */\n  ELFsectheader sect[GDBJIT_SECT__MAX];\t/* ELF sections. */\n  ELFsymbol sym[GDBJIT_SYM__MAX];\t/* ELF symbol table. */\n  uint8_t space[4096];\t\t\t/* Space for various section data. */\n} GDBJITobj;\n\n/* Combined structure for GDB JIT entry and ELF object. */\ntypedef struct GDBJITentryobj {\n  GDBJITentry entry;\n  size_t sz;\n  GDBJITobj obj;\n} GDBJITentryobj;\n\n/* Template for in-memory ELF header. */\nstatic const ELFheader elfhdr_template = {\n  .emagic = { 0x7f, 'E', 'L', 'F' },\n  .eclass = LJ_64 ? 2 : 1,\n  .eendian = LJ_ENDIAN_SELECT(1, 2),\n  .eversion = 1,\n#if LJ_TARGET_LINUX\n  .eosabi = 0,  /* Nope, it's not 3. */\n#elif defined(__FreeBSD__)\n  .eosabi = 9,\n#elif defined(__NetBSD__)\n  .eosabi = 2,\n#elif defined(__OpenBSD__)\n  .eosabi = 12,\n#elif defined(__DragonFly__)\n  .eosabi = 0,\n#elif (defined(__sun__) && defined(__svr4__))\n  .eosabi = 6,\n#else\n  .eosabi = 0,\n#endif\n  .eabiversion = 0,\n  .epad = { 0, 0, 0, 0, 0, 0, 0 },\n  .type = 1,\n#if LJ_TARGET_X86\n  .machine = 3,\n#elif LJ_TARGET_X64\n  .machine = 62,\n#elif LJ_TARGET_ARM\n  .machine = 40,\n#elif LJ_TARGET_PPC\n  .machine = 20,\n#elif LJ_TARGET_MIPS\n  .machine = 8,\n#else\n#error \"Unsupported target architecture\"\n#endif\n  .version = 1,\n  .entry = 0,\n  .phofs = 0,\n  .shofs = offsetof(GDBJITobj, sect),\n  .flags = 0,\n  .ehsize = sizeof(ELFheader),\n  .phentsize = 0,\n  .phnum = 0,\n  .shentsize = sizeof(ELFsectheader),\n  .shnum = GDBJIT_SECT__MAX,\n  .shstridx = GDBJIT_SECT_shstrtab\n};\n\n/* -- In-memory ELF object generation ------------------------------------- */\n\n/* Context for generating the ELF object for the GDB JIT API. */\ntypedef struct GDBJITctx {\n  uint8_t *p;\t\t/* Pointer to next address in obj.space. */\n  uint8_t *startp;\t/* Pointer to start address in obj.space. */\n  GCtrace *T;\t\t/* Generate symbols for this trace. */\n  uintptr_t mcaddr;\t/* Machine code address. */\n  MSize szmcode;\t/* Size of machine code. */\n  MSize spadjp;\t\t/* Stack adjustment for parent trace or interpreter. */\n  MSize spadj;\t\t/* Stack adjustment for trace itself. */\n  BCLine lineno;\t/* Starting line number. */\n  const char *filename;\t/* Starting file name. */\n  size_t objsize;\t/* Final size of ELF object. */\n  GDBJITobj obj;\t/* In-memory ELF object. */\n} GDBJITctx;\n\n/* Add a zero-terminated string. */\nstatic uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str)\n{\n  uint8_t *p = ctx->p;\n  uint32_t ofs = (uint32_t)(p - ctx->startp);\n  do {\n    *p++ = (uint8_t)*str;\n  } while (*str++);\n  ctx->p = p;\n  return ofs;\n}\n\n/* Append a decimal number. */\nstatic void gdbjit_catnum(GDBJITctx *ctx, uint32_t n)\n{\n  if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); }\n  *ctx->p++ = '0' + n;\n}\n\n/* Add a SLEB128 value. */\nstatic void gdbjit_sleb128(GDBJITctx *ctx, int32_t v)\n{\n  uint8_t *p = ctx->p;\n  for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7)\n    *p++ = (uint8_t)((v & 0x7f) | 0x80);\n  *p++ = (uint8_t)(v & 0x7f);\n  ctx->p = p;\n}\n\n/* Shortcuts to generate DWARF structures. */\n#define DB(x)\t\t(*p++ = (x))\n#define DI8(x)\t\t(*(int8_t *)p = (x), p++)\n#define DU16(x)\t\t(*(uint16_t *)p = (x), p += 2)\n#define DU32(x)\t\t(*(uint32_t *)p = (x), p += 4)\n#define DADDR(x)\t(*(uintptr_t *)p = (x), p += sizeof(uintptr_t))\n#define DUV(x)\t\t(p = (uint8_t *)lj_strfmt_wuleb128((char *)p, (x)))\n#define DSV(x)\t\t(ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p)\n#define DSTR(str)\t(ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p)\n#define DALIGNNOP(s)\twhile ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop\n#define DSECT(name, stmt) \\\n  { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \\\n    *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \\\n\n/* Initialize ELF section headers. */\nstatic void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx)\n{\n  ELFsectheader *sect;\n\n  *ctx->p++ = '\\0';  /* Empty string at start of string table. */\n\n#define SECTDEF(id, tp, al) \\\n  sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \\\n  sect->name = gdbjit_strz(ctx, \".\" #id); \\\n  sect->type = ELFSECT_TYPE_##tp; \\\n  sect->align = (al)\n\n  SECTDEF(text, NOBITS, 16);\n  sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC;\n  sect->addr = ctx->mcaddr;\n  sect->ofs = 0;\n  sect->size = ctx->szmcode;\n\n  SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t));\n  sect->flags = ELFSECT_FLAGS_ALLOC;\n\n  SECTDEF(shstrtab, STRTAB, 1);\n  SECTDEF(strtab, STRTAB, 1);\n\n  SECTDEF(symtab, SYMTAB, sizeof(uintptr_t));\n  sect->ofs = offsetof(GDBJITobj, sym);\n  sect->size = sizeof(ctx->obj.sym);\n  sect->link = GDBJIT_SECT_strtab;\n  sect->entsize = sizeof(ELFsymbol);\n  sect->info = GDBJIT_SYM_FUNC;\n\n  SECTDEF(debug_info, PROGBITS, 1);\n  SECTDEF(debug_abbrev, PROGBITS, 1);\n  SECTDEF(debug_line, PROGBITS, 1);\n\n#undef SECTDEF\n}\n\n/* Initialize symbol table. */\nstatic void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx)\n{\n  ELFsymbol *sym;\n\n  *ctx->p++ = '\\0';  /* Empty string at start of string table. */\n\n  sym = &ctx->obj.sym[GDBJIT_SYM_FILE];\n  sym->name = gdbjit_strz(ctx, \"JIT mcode\");\n  sym->sectidx = ELFSECT_IDX_ABS;\n  sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;\n\n  sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];\n  sym->name = gdbjit_strz(ctx, \"TRACE_\"); ctx->p--;\n  gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\\0';\n  sym->sectidx = GDBJIT_SECT_text;\n  sym->value = 0;\n  sym->size = ctx->szmcode;\n  sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL;\n}\n\n/* Initialize .eh_frame section. */\nstatic void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n  uint8_t *framep = p;\n\n  /* Emit DWARF EH CIE. */\n  DSECT(CIE,\n    DU32(0);\t\t\t/* Offset to CIE itself. */\n    DB(DW_CIE_VERSION);\n    DSTR(\"zR\");\t\t\t/* Augmentation. */\n    DUV(1);\t\t\t/* Code alignment factor. */\n    DSV(-(int32_t)sizeof(uintptr_t));  /* Data alignment factor. */\n    DB(DW_REG_RA);\t\t/* Return address register. */\n    DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4);  /* Augmentation data. */\n    DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t));\n#if LJ_TARGET_PPC\n    DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1);\n#else\n    DB(DW_CFA_offset|DW_REG_RA); DUV(1);\n#endif\n    DALIGNNOP(sizeof(uintptr_t));\n  )\n\n  /* Emit DWARF EH FDE. */\n  DSECT(FDE,\n    DU32((uint32_t)(p-framep));\t/* Offset to CIE. */\n    DU32(0);\t\t\t/* Machine code offset relative to .text. */\n    DU32(ctx->szmcode);\t\t/* Machine code length. */\n    DB(0);\t\t\t/* Augmentation data. */\n    /* Registers saved in CFRAME. */\n#if LJ_TARGET_X86\n    DB(DW_CFA_offset|DW_REG_BP); DUV(2);\n    DB(DW_CFA_offset|DW_REG_DI); DUV(3);\n    DB(DW_CFA_offset|DW_REG_SI); DUV(4);\n    DB(DW_CFA_offset|DW_REG_BX); DUV(5);\n#elif LJ_TARGET_X64\n    DB(DW_CFA_offset|DW_REG_BP); DUV(2);\n    DB(DW_CFA_offset|DW_REG_BX); DUV(3);\n    DB(DW_CFA_offset|DW_REG_15); DUV(4);\n    DB(DW_CFA_offset|DW_REG_14); DUV(5);\n    /* Extra registers saved for JIT-compiled code. */\n    DB(DW_CFA_offset|DW_REG_13); DUV(LJ_GC64 ? 10 : 9);\n    DB(DW_CFA_offset|DW_REG_12); DUV(LJ_GC64 ? 11 : 10);\n#elif LJ_TARGET_ARM\n    {\n      int i;\n      for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); }\n    }\n#elif LJ_TARGET_PPC\n    {\n      int i;\n      DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55);\n      for (i = 14; i <= 31; i++) {\n\tDB(DW_CFA_offset|i); DUV(37+(31-i));\n\tDB(DW_CFA_offset|32|i); DUV(2+2*(31-i));\n      }\n    }\n#elif LJ_TARGET_MIPS\n    {\n      int i;\n      DB(DW_CFA_offset|30); DUV(2);\n      for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }\n      for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }\n    }\n#else\n#error \"Unsupported target architecture\"\n#endif\n    if (ctx->spadjp != ctx->spadj) {  /* Parent/interpreter stack frame size. */\n      DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp);\n      DB(DW_CFA_advance_loc|1);  /* Only an approximation. */\n    }\n    DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj);  /* Trace stack frame size. */\n    DALIGNNOP(sizeof(uintptr_t));\n  )\n\n  ctx->p = p;\n}\n\n/* Initialize .debug_info section. */\nstatic void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  DSECT(info,\n    DU16(2);\t\t\t/* DWARF version. */\n    DU32(0);\t\t\t/* Abbrev offset. */\n    DB(sizeof(uintptr_t));\t/* Pointer size. */\n\n    DUV(1);\t\t\t/* Abbrev #1: DW_TAG_compile_unit. */\n    DSTR(ctx->filename);\t/* DW_AT_name. */\n    DADDR(ctx->mcaddr);\t\t/* DW_AT_low_pc. */\n    DADDR(ctx->mcaddr + ctx->szmcode);  /* DW_AT_high_pc. */\n    DU32(0);\t\t\t/* DW_AT_stmt_list. */\n  )\n\n  ctx->p = p;\n}\n\n/* Initialize .debug_abbrev section. */\nstatic void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  /* Abbrev #1: DW_TAG_compile_unit. */\n  DUV(1); DUV(DW_TAG_compile_unit);\n  DB(DW_children_no);\n  DUV(DW_AT_name);\tDUV(DW_FORM_string);\n  DUV(DW_AT_low_pc);\tDUV(DW_FORM_addr);\n  DUV(DW_AT_high_pc);\tDUV(DW_FORM_addr);\n  DUV(DW_AT_stmt_list);\tDUV(DW_FORM_data4);\n  DB(0); DB(0);\n\n  ctx->p = p;\n}\n\n#define DLNE(op, s)\t(DB(DW_LNS_extended_op), DUV(1+(s)), DB((op)))\n\n/* Initialize .debug_line section. */\nstatic void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  DSECT(line,\n    DU16(2);\t\t\t/* DWARF version. */\n    DSECT(header,\n      DB(1);\t\t\t/* Minimum instruction length. */\n      DB(1);\t\t\t/* is_stmt. */\n      DI8(0);\t\t\t/* Line base for special opcodes. */\n      DB(2);\t\t\t/* Line range for special opcodes. */\n      DB(3+1);\t\t\t/* Opcode base at DW_LNS_advance_line+1. */\n      DB(0); DB(1); DB(1);\t/* Standard opcode lengths. */\n      /* Directory table. */\n      DB(0);\n      /* File name table. */\n      DSTR(ctx->filename); DUV(0); DUV(0); DUV(0);\n      DB(0);\n    )\n\n    DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr);\n    if (ctx->lineno) {\n      DB(DW_LNS_advance_line); DSV(ctx->lineno-1);\n    }\n    DB(DW_LNS_copy);\n    DB(DW_LNS_advance_pc); DUV(ctx->szmcode);\n    DLNE(DW_LNE_end_sequence, 0);\n  )\n\n  ctx->p = p;\n}\n\n#undef DLNE\n\n/* Undef shortcuts. */\n#undef DB\n#undef DI8\n#undef DU16\n#undef DU32\n#undef DADDR\n#undef DUV\n#undef DSV\n#undef DSTR\n#undef DALIGNNOP\n#undef DSECT\n\n/* Type of a section initializer callback. */\ntypedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx);\n\n/* Call section initializer and set the section offset and size. */\nstatic void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf)\n{\n  ctx->startp = ctx->p;\n  ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj);\n  initf(ctx);\n  ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp);\n}\n\n#define SECTALIGN(p, a) \\\n  ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1)))\n\n/* Build in-memory ELF object. */\nstatic void gdbjit_buildobj(GDBJITctx *ctx)\n{\n  GDBJITobj *obj = &ctx->obj;\n  /* Fill in ELF header and clear structures. */\n  memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader));\n  memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX);\n  memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX);\n  /* Initialize sections. */\n  ctx->p = obj->space;\n  gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr);\n  gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline);\n  SECTALIGN(ctx->p, sizeof(uintptr_t));\n  gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe);\n  ctx->objsize = (size_t)((char *)ctx->p - (char *)obj);\n  lua_assert(ctx->objsize < sizeof(GDBJITobj));\n}\n\n#undef SECTALIGN\n\n/* -- Interface to GDB JIT API -------------------------------------------- */\n\n/* Add new entry to GDB JIT symbol chain. */\nstatic void gdbjit_newentry(lua_State *L, GDBJITctx *ctx)\n{\n  /* Allocate memory for GDB JIT entry and ELF object. */\n  MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize);\n  GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj);\n  memcpy(&eo->obj, &ctx->obj, ctx->objsize);  /* Copy ELF object. */\n  eo->sz = sz;\n  ctx->T->gdbjit_entry = (void *)eo;\n  /* Link new entry to chain and register it. */\n  eo->entry.prev_entry = NULL;\n  eo->entry.next_entry = __jit_debug_descriptor.first_entry;\n  if (eo->entry.next_entry)\n    eo->entry.next_entry->prev_entry = &eo->entry;\n  eo->entry.symfile_addr = (const char *)&eo->obj;\n  eo->entry.symfile_size = ctx->objsize;\n  __jit_debug_descriptor.first_entry = &eo->entry;\n  __jit_debug_descriptor.relevant_entry = &eo->entry;\n  __jit_debug_descriptor.action_flag = GDBJIT_REGISTER;\n  __jit_debug_register_code();\n}\n\n/* Add debug info for newly compiled trace and notify GDB. */\nvoid lj_gdbjit_addtrace(jit_State *J, GCtrace *T)\n{\n  GDBJITctx ctx;\n  GCproto *pt = &gcref(T->startpt)->pt;\n  TraceNo parent = T->ir[REF_BASE].op1;\n  const BCIns *startpc = mref(T->startpc, const BCIns);\n  ctx.T = T;\n  ctx.mcaddr = (uintptr_t)T->mcode;\n  ctx.szmcode = T->szmcode;\n  ctx.spadjp = CFRAME_SIZE_JIT +\n\t       (MSize)(parent ? traceref(J, parent)->spadjust : 0);\n  ctx.spadj = CFRAME_SIZE_JIT + T->spadjust;\n  lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);\n  ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));\n  ctx.filename = proto_chunknamestr(pt);\n  if (*ctx.filename == '@' || *ctx.filename == '=')\n    ctx.filename++;\n  else\n    ctx.filename = \"(string)\";\n  gdbjit_buildobj(&ctx);\n  gdbjit_newentry(J->L, &ctx);\n}\n\n/* Delete debug info for trace and notify GDB. */\nvoid lj_gdbjit_deltrace(jit_State *J, GCtrace *T)\n{\n  GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry;\n  if (eo) {\n    if (eo->entry.prev_entry)\n      eo->entry.prev_entry->next_entry = eo->entry.next_entry;\n    else\n      __jit_debug_descriptor.first_entry = eo->entry.next_entry;\n    if (eo->entry.next_entry)\n      eo->entry.next_entry->prev_entry = eo->entry.prev_entry;\n    __jit_debug_descriptor.relevant_entry = &eo->entry;\n    __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER;\n    __jit_debug_register_code();\n    lj_mem_free(J2G(J), eo, eo->sz);\n  }\n}\n\n#endif\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_gdbjit.h",
    "content": "/*\n** Client for the GDB JIT API.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_GDBJIT_H\n#define _LJ_GDBJIT_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT)\n\nLJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T);\nLJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T);\n\n#else\n#define lj_gdbjit_addtrace(J, T)\tUNUSED(T)\n#define lj_gdbjit_deltrace(J, T)\tUNUSED(T)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ir.c",
    "content": "/*\n** SSA IR (Intermediate Representation) emitter.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ir_c\n#define LUA_CORE\n\n/* For pointers to libc/libm functions. */\n#include <stdio.h>\n#include <math.h>\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n#define fins\t\t\t(&J->fold.ins)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)        (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* -- IR tables ----------------------------------------------------------- */\n\n/* IR instruction modes. */\nLJ_DATADEF const uint8_t lj_ir_mode[IR__MAX+1] = {\nIRDEF(IRMODE)\n  0\n};\n\n/* IR type sizes. */\nLJ_DATADEF const uint8_t lj_ir_type_size[IRT__MAX+1] = {\n#define IRTSIZE(name, size)\tsize,\nIRTDEF(IRTSIZE)\n#undef IRTSIZE\n  0\n};\n\n/* C call info for CALL* instructions. */\nLJ_DATADEF const CCallInfo lj_ir_callinfo[] = {\n#define IRCALLCI(cond, name, nargs, kind, type, flags) \\\n  { (ASMFunction)IRCALLCOND_##cond(name), \\\n    (nargs)|(CCI_CALL_##kind)|(IRT_##type<<CCI_OTSHIFT)|(flags) },\nIRCALLDEF(IRCALLCI)\n#undef IRCALLCI\n  { NULL, 0 }\n};\n\n/* -- IR emitter ---------------------------------------------------------- */\n\n/* Grow IR buffer at the top. */\nvoid LJ_FASTCALL lj_ir_growtop(jit_State *J)\n{\n  IRIns *baseir = J->irbuf + J->irbotlim;\n  MSize szins = J->irtoplim - J->irbotlim;\n  if (szins) {\n    baseir = (IRIns *)lj_mem_realloc(J->L, baseir, szins*sizeof(IRIns),\n\t\t\t\t     2*szins*sizeof(IRIns));\n    J->irtoplim = J->irbotlim + 2*szins;\n  } else {\n    baseir = (IRIns *)lj_mem_realloc(J->L, NULL, 0, LJ_MIN_IRSZ*sizeof(IRIns));\n    J->irbotlim = REF_BASE - LJ_MIN_IRSZ/4;\n    J->irtoplim = J->irbotlim + LJ_MIN_IRSZ;\n  }\n  J->cur.ir = J->irbuf = baseir - J->irbotlim;\n}\n\n/* Grow IR buffer at the bottom or shift it up. */\nstatic void lj_ir_growbot(jit_State *J)\n{\n  IRIns *baseir = J->irbuf + J->irbotlim;\n  MSize szins = J->irtoplim - J->irbotlim;\n  lua_assert(szins != 0);\n  lua_assert(J->cur.nk == J->irbotlim);\n  if (J->cur.nins + (szins >> 1) < J->irtoplim) {\n    /* More than half of the buffer is free on top: shift up by a quarter. */\n    MSize ofs = szins >> 2;\n    memmove(baseir + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));\n    J->irbotlim -= ofs;\n    J->irtoplim -= ofs;\n    J->cur.ir = J->irbuf = baseir - J->irbotlim;\n  } else {\n    /* Double the buffer size, but split the growth amongst top/bottom. */\n    IRIns *newbase = lj_mem_newt(J->L, 2*szins*sizeof(IRIns), IRIns);\n    MSize ofs = szins >= 256 ? 128 : (szins >> 1);  /* Limit bottom growth. */\n    memcpy(newbase + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));\n    lj_mem_free(G(J->L), baseir, szins*sizeof(IRIns));\n    J->irbotlim -= ofs;\n    J->irtoplim = J->irbotlim + 2*szins;\n    J->cur.ir = J->irbuf = newbase - J->irbotlim;\n  }\n}\n\n/* Emit IR without any optimizations. */\nTRef LJ_FASTCALL lj_ir_emit(jit_State *J)\n{\n  IRRef ref = lj_ir_nextins(J);\n  IRIns *ir = IR(ref);\n  IROp op = fins->o;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\n  ir->o = op;\n  ir->op1 = fins->op1;\n  ir->op2 = fins->op2;\n  J->guardemit.irt |= fins->t.irt;\n  return TREF(ref, irt_t((ir->t = fins->t)));\n}\n\n/* Emit call to a C function. */\nTRef lj_ir_call(jit_State *J, IRCallID id, ...)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[id];\n  uint32_t n = CCI_NARGS(ci);\n  TRef tr = TREF_NIL;\n  va_list argp;\n  va_start(argp, id);\n  if ((ci->flags & CCI_L)) n--;\n  if (n > 0)\n    tr = va_arg(argp, IRRef);\n  while (n-- > 1)\n    tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef));\n  va_end(argp);\n  if (CCI_OP(ci) == IR_CALLS)\n    J->needsnap = 1;  /* Need snapshot after call with side effect. */\n  return emitir(CCI_OPTYPE(ci), tr, id);\n}\n\n/* -- Interning of constants ---------------------------------------------- */\n\n/*\n** IR instructions for constants are kept between J->cur.nk >= ref < REF_BIAS.\n** They are chained like all other instructions, but grow downwards.\n** The are interned (like strings in the VM) to facilitate reference\n** comparisons. The same constant must get the same reference.\n*/\n\n/* Get ref of next IR constant and optionally grow IR.\n** Note: this may invalidate all IRIns *!\n*/\nstatic LJ_AINLINE IRRef ir_nextk(jit_State *J)\n{\n  IRRef ref = J->cur.nk;\n  if (LJ_UNLIKELY(ref <= J->irbotlim)) lj_ir_growbot(J);\n  J->cur.nk = --ref;\n  return ref;\n}\n\n/* Intern int32_t constant. */\nTRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  for (ref = J->chain[IR_KINT]; ref; ref = cir[ref].prev)\n    if (cir[ref].i == k)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->i = k;\n  ir->t.irt = IRT_INT;\n  ir->o = IR_KINT;\n  ir->prev = J->chain[IR_KINT];\n  J->chain[IR_KINT] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_INT);\n}\n\n/* The MRef inside the KNUM/KINT64 IR instructions holds the address of the\n** 64 bit constant. The constants themselves are stored in a chained array\n** and shared across traces.\n**\n** Rationale for choosing this data structure:\n** - The address of the constants is embedded in the generated machine code\n**   and must never move. A resizable array or hash table wouldn't work.\n** - Most apps need very few non-32 bit integer constants (less than a dozen).\n** - Linear search is hard to beat in terms of speed and low complexity.\n*/\ntypedef struct K64Array {\n  MRef next;\t\t\t/* Pointer to next list. */\n  MSize numk;\t\t\t/* Number of used elements in this array. */\n  TValue k[LJ_MIN_K64SZ];\t/* Array of constants. */\n} K64Array;\n\n/* Free all chained arrays. */\nvoid lj_ir_k64_freeall(jit_State *J)\n{\n  K64Array *k;\n  for (k = mref(J->k64, K64Array); k; ) {\n    K64Array *next = mref(k->next, K64Array);\n    lj_mem_free(J2G(J), k, sizeof(K64Array));\n    k = next;\n  }\n  setmref(J->k64, NULL);\n}\n\n/* Get new 64 bit constant slot. */\nstatic TValue *ir_k64_add(jit_State *J, K64Array *kp, uint64_t u64)\n{\n  TValue *ntv;\n  if (!(kp && kp->numk < LJ_MIN_K64SZ)) {  /* Allocate a new array. */\n    K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array);\n    setmref(kn->next, NULL);\n    kn->numk = 0;\n    if (kp)\n      setmref(kp->next, kn);  /* Chain to the end of the list. */\n    else\n      setmref(J->k64, kn);  /* Link first array. */\n    kp = kn;\n  }\n  ntv = &kp->k[kp->numk++];  /* Add to current array. */\n  ntv->u64 = u64;\n  return ntv;\n}\n\n/* Find 64 bit constant in chained array or add it. */\ncTValue *lj_ir_k64_find(jit_State *J, uint64_t u64)\n{\n  K64Array *k, *kp = NULL;\n  MSize idx;\n  /* Search for the constant in the whole chain of arrays. */\n  for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) {\n    kp = k;  /* Remember previous element in list. */\n    for (idx = 0; idx < k->numk; idx++) {  /* Search one array. */\n      TValue *tv = &k->k[idx];\n      if (tv->u64 == u64)  /* Needed for +-0/NaN/absmask. */\n\treturn tv;\n    }\n  }\n  /* Otherwise add a new constant. */\n  return ir_k64_add(J, kp, u64);\n}\n\nTValue *lj_ir_k64_reserve(jit_State *J)\n{\n  K64Array *k, *kp = NULL;\n  lj_ir_k64_find(J, 0);  /* Intern dummy 0 to protect the reserved slot. */\n  /* Find last K64Array, if any. */\n  for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) kp = k;\n  return ir_k64_add(J, kp, 0);  /* Set to 0. Final value is set later. */\n}\n\n/* Intern 64 bit constant, given by its address. */\nTRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64;\n  for (ref = J->chain[op]; ref; ref = cir[ref].prev)\n    if (ir_k64(&cir[ref]) == tv)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  lua_assert(checkptrGC(tv));\n  setmref(ir->ptr, tv);\n  ir->t.irt = t;\n  ir->o = op;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Intern FP constant, given by its 64 bit pattern. */\nTRef lj_ir_knum_u64(jit_State *J, uint64_t u64)\n{\n  return lj_ir_k64(J, IR_KNUM, lj_ir_k64_find(J, u64));\n}\n\n/* Intern 64 bit integer constant. */\nTRef lj_ir_kint64(jit_State *J, uint64_t u64)\n{\n  return lj_ir_k64(J, IR_KINT64, lj_ir_k64_find(J, u64));\n}\n\n/* Check whether a number is int and return it. -0 is NOT considered an int. */\nstatic int numistrueint(lua_Number n, int32_t *kp)\n{\n  int32_t k = lj_num2int(n);\n  if (n == (lua_Number)k) {\n    if (kp) *kp = k;\n    if (k == 0) {  /* Special check for -0. */\n      TValue tv;\n      setnumV(&tv, n);\n      if (tv.u32.hi != 0)\n\treturn 0;\n    }\n    return 1;\n  }\n  return 0;\n}\n\n/* Intern number as int32_t constant if possible, otherwise as FP constant. */\nTRef lj_ir_knumint(jit_State *J, lua_Number n)\n{\n  int32_t k;\n  if (numistrueint(n, &k))\n    return lj_ir_kint(J, k);\n  else\n    return lj_ir_knum(J, n);\n}\n\n/* Intern GC object \"constant\". */\nTRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  lua_assert(!LJ_GC64);  /* TODO_GC64: major changes required. */\n  lua_assert(!isdead(J2G(J), o));\n  for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)\n    if (ir_kgc(&cir[ref]) == o)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  /* NOBARRIER: Current trace is a GC root. */\n  setgcref(ir->gcr, o);\n  ir->t.irt = (uint8_t)t;\n  ir->o = IR_KGC;\n  ir->prev = J->chain[IR_KGC];\n  J->chain[IR_KGC] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Intern 32 bit pointer constant. */\nTRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr);\n  for (ref = J->chain[op]; ref; ref = cir[ref].prev)\n    if (mref(cir[ref].ptr, void) == ptr)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  setmref(ir->ptr, ptr);\n  ir->t.irt = IRT_P32;\n  ir->o = op;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_P32);\n}\n\n/* Intern typed NULL constant. */\nTRef lj_ir_knull(jit_State *J, IRType t)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  for (ref = J->chain[IR_KNULL]; ref; ref = cir[ref].prev)\n    if (irt_t(cir[ref].t) == t)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->i = 0;\n  ir->t.irt = (uint8_t)t;\n  ir->o = IR_KNULL;\n  ir->prev = J->chain[IR_KNULL];\n  J->chain[IR_KNULL] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Intern key slot. */\nTRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot);\n  IRRef ref;\n  /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */\n  lua_assert(tref_isk(key) && slot == (IRRef)(IRRef1)slot);\n  for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev)\n    if (cir[ref].op12 == op12)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->op12 = op12;\n  ir->t.irt = IRT_P32;\n  ir->o = IR_KSLOT;\n  ir->prev = J->chain[IR_KSLOT];\n  J->chain[IR_KSLOT] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_P32);\n}\n\n/* -- Access to IR constants ---------------------------------------------- */\n\n/* Copy value of IR constant. */\nvoid lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)\n{\n  UNUSED(L);\n  lua_assert(ir->o != IR_KSLOT);  /* Common mistake. */\n  switch (ir->o) {\n  case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break;\n  case IR_KINT: setintV(tv, ir->i); break;\n  case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;\n  case IR_KPTR: case IR_KKPTR: case IR_KNULL:\n    setlightudV(tv, mref(ir->ptr, void));\n    break;\n  case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break;\n#if LJ_HASFFI\n  case IR_KINT64: {\n    GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8);\n    *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64;\n    setcdataV(L, tv, cd);\n    break;\n    }\n#endif\n  default: lua_assert(0); break;\n  }\n}\n\n/* -- Convert IR operand types -------------------------------------------- */\n\n/* Convert from string to number. */\nTRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr)\n{\n  if (!tref_isnumber(tr)) {\n    if (tref_isstr(tr))\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    else\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  return tr;\n}\n\n/* Convert from integer or string to number. */\nTRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr)\n{\n  if (!tref_isnum(tr)) {\n    if (tref_isinteger(tr))\n      tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n    else if (tref_isstr(tr))\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    else\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  return tr;\n}\n\n/* Convert from integer or number to string. */\nTRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr)\n{\n  if (!tref_isstr(tr)) {\n    if (!tref_isnumber(tr))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    tr = emitir(IRT(IR_TOSTR, IRT_STR), tr,\n\t\ttref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT);\n  }\n  return tr;\n}\n\n/* -- Miscellaneous IR ops ------------------------------------------------ */\n\n/* Evaluate numeric comparison. */\nint lj_ir_numcmp(lua_Number a, lua_Number b, IROp op)\n{\n  switch (op) {\n  case IR_EQ: return (a == b);\n  case IR_NE: return (a != b);\n  case IR_LT: return (a < b);\n  case IR_GE: return (a >= b);\n  case IR_LE: return (a <= b);\n  case IR_GT: return (a > b);\n  case IR_ULT: return !(a >= b);\n  case IR_UGE: return !(a < b);\n  case IR_ULE: return !(a > b);\n  case IR_UGT: return !(a <= b);\n  default: lua_assert(0); return 0;\n  }\n}\n\n/* Evaluate string comparison. */\nint lj_ir_strcmp(GCstr *a, GCstr *b, IROp op)\n{\n  int res = lj_str_cmp(a, b);\n  switch (op) {\n  case IR_LT: return (res < 0);\n  case IR_GE: return (res >= 0);\n  case IR_LE: return (res <= 0);\n  case IR_GT: return (res > 0);\n  default: lua_assert(0); return 0;\n  }\n}\n\n/* Rollback IR to previous state. */\nvoid lj_ir_rollback(jit_State *J, IRRef ref)\n{\n  IRRef nins = J->cur.nins;\n  while (nins > ref) {\n    IRIns *ir;\n    nins--;\n    ir = IR(nins);\n    J->chain[ir->o] = ir->prev;\n  }\n  J->cur.nins = nins;\n}\n\n#undef IR\n#undef fins\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ir.h",
    "content": "/*\n** SSA IR (Intermediate Representation) format.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IR_H\n#define _LJ_IR_H\n\n#include \"lj_obj.h\"\n\n/* -- IR instructions ----------------------------------------------------- */\n\n/* IR instruction definition. Order matters, see below. ORDER IR */\n#define IRDEF(_) \\\n  /* Guarded assertions. */ \\\n  /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \\\n  _(LT,\t\tN , ref, ref) \\\n  _(GE,\t\tN , ref, ref) \\\n  _(LE,\t\tN , ref, ref) \\\n  _(GT,\t\tN , ref, ref) \\\n  \\\n  _(ULT,\tN , ref, ref) \\\n  _(UGE,\tN , ref, ref) \\\n  _(ULE,\tN , ref, ref) \\\n  _(UGT,\tN , ref, ref) \\\n  \\\n  _(EQ,\t\tC , ref, ref) \\\n  _(NE,\t\tC , ref, ref) \\\n  \\\n  _(ABC,\tN , ref, ref) \\\n  _(RETF,\tS , ref, ref) \\\n  \\\n  /* Miscellaneous ops. */ \\\n  _(NOP,\tN , ___, ___) \\\n  _(BASE,\tN , lit, lit) \\\n  _(PVAL,\tN , lit, ___) \\\n  _(GCSTEP,\tS , ___, ___) \\\n  _(HIOP,\tS , ref, ref) \\\n  _(LOOP,\tS , ___, ___) \\\n  _(USE,\tS , ref, ___) \\\n  _(PHI,\tS , ref, ref) \\\n  _(RENAME,\tS , ref, lit) \\\n  _(PROF,\tS , ___, ___) \\\n  \\\n  /* Constants. */ \\\n  _(KPRI,\tN , ___, ___) \\\n  _(KINT,\tN , cst, ___) \\\n  _(KGC,\tN , cst, ___) \\\n  _(KPTR,\tN , cst, ___) \\\n  _(KKPTR,\tN , cst, ___) \\\n  _(KNULL,\tN , cst, ___) \\\n  _(KNUM,\tN , cst, ___) \\\n  _(KINT64,\tN , cst, ___) \\\n  _(KSLOT,\tN , ref, lit) \\\n  \\\n  /* Bit ops. */ \\\n  _(BNOT,\tN , ref, ___) \\\n  _(BSWAP,\tN , ref, ___) \\\n  _(BAND,\tC , ref, ref) \\\n  _(BOR,\tC , ref, ref) \\\n  _(BXOR,\tC , ref, ref) \\\n  _(BSHL,\tN , ref, ref) \\\n  _(BSHR,\tN , ref, ref) \\\n  _(BSAR,\tN , ref, ref) \\\n  _(BROL,\tN , ref, ref) \\\n  _(BROR,\tN , ref, ref) \\\n  \\\n  /* Arithmetic ops. ORDER ARITH */ \\\n  _(ADD,\tC , ref, ref) \\\n  _(SUB,\tN , ref, ref) \\\n  _(MUL,\tC , ref, ref) \\\n  _(DIV,\tN , ref, ref) \\\n  _(MOD,\tN , ref, ref) \\\n  _(POW,\tN , ref, ref) \\\n  _(NEG,\tN , ref, ref) \\\n  \\\n  _(ABS,\tN , ref, ref) \\\n  _(ATAN2,\tN , ref, ref) \\\n  _(LDEXP,\tN , ref, ref) \\\n  _(MIN,\tC , ref, ref) \\\n  _(MAX,\tC , ref, ref) \\\n  _(FPMATH,\tN , ref, lit) \\\n  \\\n  /* Overflow-checking arithmetic ops. */ \\\n  _(ADDOV,\tCW, ref, ref) \\\n  _(SUBOV,\tNW, ref, ref) \\\n  _(MULOV,\tCW, ref, ref) \\\n  \\\n  /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \\\n  \\\n  /* Memory references. */ \\\n  _(AREF,\tR , ref, ref) \\\n  _(HREFK,\tR , ref, ref) \\\n  _(HREF,\tL , ref, ref) \\\n  _(NEWREF,\tS , ref, ref) \\\n  _(UREFO,\tLW, ref, lit) \\\n  _(UREFC,\tLW, ref, lit) \\\n  _(FREF,\tR , ref, lit) \\\n  _(STRREF,\tN , ref, ref) \\\n  _(LREF,\tL , ___, ___) \\\n  \\\n  /* Loads and Stores. These must be in the same order. */ \\\n  _(ALOAD,\tL , ref, ___) \\\n  _(HLOAD,\tL , ref, ___) \\\n  _(ULOAD,\tL , ref, ___) \\\n  _(FLOAD,\tL , ref, lit) \\\n  _(XLOAD,\tL , ref, lit) \\\n  _(SLOAD,\tL , lit, lit) \\\n  _(VLOAD,\tL , ref, ___) \\\n  \\\n  _(ASTORE,\tS , ref, ref) \\\n  _(HSTORE,\tS , ref, ref) \\\n  _(USTORE,\tS , ref, ref) \\\n  _(FSTORE,\tS , ref, ref) \\\n  _(XSTORE,\tS , ref, ref) \\\n  \\\n  /* Allocations. */ \\\n  _(SNEW,\tN , ref, ref)  /* CSE is ok, not marked as A. */ \\\n  _(XSNEW,\tA , ref, ref) \\\n  _(TNEW,\tAW, lit, lit) \\\n  _(TDUP,\tAW, ref, ___) \\\n  _(CNEW,\tAW, ref, ref) \\\n  _(CNEWI,\tNW, ref, ref)  /* CSE is ok, not marked as A. */ \\\n  \\\n  /* Buffer operations. */ \\\n  _(BUFHDR,\tL , ref, lit) \\\n  _(BUFPUT,\tL , ref, ref) \\\n  _(BUFSTR,\tA , ref, ref) \\\n  \\\n  /* Barriers. */ \\\n  _(TBAR,\tS , ref, ___) \\\n  _(OBAR,\tS , ref, ref) \\\n  _(XBAR,\tS , ___, ___) \\\n  \\\n  /* Type conversions. */ \\\n  _(CONV,\tNW, ref, lit) \\\n  _(TOBIT,\tN , ref, ref) \\\n  _(TOSTR,\tN , ref, lit) \\\n  _(STRTO,\tN , ref, ___) \\\n  \\\n  /* Calls. */ \\\n  _(CALLN,\tN , ref, lit) \\\n  _(CALLA,\tA , ref, lit) \\\n  _(CALLL,\tL , ref, lit) \\\n  _(CALLS,\tS , ref, lit) \\\n  _(CALLXS,\tS , ref, ref) \\\n  _(CARG,\tN , ref, ref) \\\n  \\\n  /* End of list. */\n\n/* IR opcodes (max. 256). */\ntypedef enum {\n#define IRENUM(name, m, m1, m2)\tIR_##name,\nIRDEF(IRENUM)\n#undef IRENUM\n  IR__MAX\n} IROp;\n\n/* Stored opcode. */\ntypedef uint8_t IROp1;\n\nLJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE);\nLJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE);\nLJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT);\nLJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT);\nLJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT);\n\n/* Delta between xLOAD and xSTORE. */\n#define IRDELTA_L2S\t\t((int)IR_ASTORE - (int)IR_ALOAD)\n\nLJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE);\nLJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE);\nLJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE);\nLJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);\n\n/* -- Named IR literals --------------------------------------------------- */\n\n/* FPMATH sub-functions. ORDER FPM. */\n#define IRFPMDEF(_) \\\n  _(FLOOR) _(CEIL) _(TRUNC)  /* Must be first and in this order. */ \\\n  _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \\\n  _(SIN) _(COS) _(TAN) \\\n  _(OTHER)\n\ntypedef enum {\n#define FPMENUM(name)\t\tIRFPM_##name,\nIRFPMDEF(FPMENUM)\n#undef FPMENUM\n  IRFPM__MAX\n} IRFPMathOp;\n\n/* FLOAD fields. */\n#define IRFLDEF(_) \\\n  _(STR_LEN,\toffsetof(GCstr, len)) \\\n  _(FUNC_ENV,\toffsetof(GCfunc, l.env)) \\\n  _(FUNC_PC,\toffsetof(GCfunc, l.pc)) \\\n  _(FUNC_FFID,\toffsetof(GCfunc, l.ffid)) \\\n  _(THREAD_ENV,\toffsetof(lua_State, env)) \\\n  _(TAB_META,\toffsetof(GCtab, metatable)) \\\n  _(TAB_ARRAY,\toffsetof(GCtab, array)) \\\n  _(TAB_NODE,\toffsetof(GCtab, node)) \\\n  _(TAB_ASIZE,\toffsetof(GCtab, asize)) \\\n  _(TAB_HMASK,\toffsetof(GCtab, hmask)) \\\n  _(TAB_NOMM,\toffsetof(GCtab, nomm)) \\\n  _(UDATA_META,\toffsetof(GCudata, metatable)) \\\n  _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \\\n  _(UDATA_FILE,\tsizeof(GCudata)) \\\n  _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \\\n  _(CDATA_PTR,\tsizeof(GCcdata)) \\\n  _(CDATA_INT, sizeof(GCcdata)) \\\n  _(CDATA_INT64, sizeof(GCcdata)) \\\n  _(CDATA_INT64_4, sizeof(GCcdata) + 4)\n\ntypedef enum {\n#define FLENUM(name, ofs)\tIRFL_##name,\nIRFLDEF(FLENUM)\n#undef FLENUM\n  IRFL__MAX\n} IRFieldID;\n\n/* SLOAD mode bits, stored in op2. */\n#define IRSLOAD_PARENT\t\t0x01\t/* Coalesce with parent trace. */\n#define IRSLOAD_FRAME\t\t0x02\t/* Load hiword of frame. */\n#define IRSLOAD_TYPECHECK\t0x04\t/* Needs type check. */\n#define IRSLOAD_CONVERT\t\t0x08\t/* Number to integer conversion. */\n#define IRSLOAD_READONLY\t0x10\t/* Read-only, omit slot store. */\n#define IRSLOAD_INHERIT\t\t0x20\t/* Inherited by exits/side traces. */\n\n/* XLOAD mode, stored in op2. */\n#define IRXLOAD_READONLY\t1\t/* Load from read-only data. */\n#define IRXLOAD_VOLATILE\t2\t/* Load from volatile data. */\n#define IRXLOAD_UNALIGNED\t4\t/* Unaligned load. */\n\n/* BUFHDR mode, stored in op2. */\n#define IRBUFHDR_RESET\t\t0\t/* Reset buffer. */\n#define IRBUFHDR_APPEND\t\t1\t/* Append to buffer. */\n\n/* CONV mode, stored in op2. */\n#define IRCONV_SRCMASK\t\t0x001f\t/* Source IRType. */\n#define IRCONV_DSTMASK\t\t0x03e0\t/* Dest. IRType (also in ir->t). */\n#define IRCONV_DSH\t\t5\n#define IRCONV_NUM_INT\t\t((IRT_NUM<<IRCONV_DSH)|IRT_INT)\n#define IRCONV_INT_NUM\t\t((IRT_INT<<IRCONV_DSH)|IRT_NUM)\n#define IRCONV_SEXT\t\t0x0800\t/* Sign-extend integer to integer. */\n#define IRCONV_MODEMASK\t\t0x0fff\n#define IRCONV_CONVMASK\t\t0xf000\n#define IRCONV_CSH\t\t12\n/* Number to integer conversion mode. Ordered by strength of the checks. */\n#define IRCONV_TOBIT  (0<<IRCONV_CSH)\t/* None. Cache only: TOBIT conv. */\n#define IRCONV_ANY    (1<<IRCONV_CSH)\t/* Any FP number is ok. */\n#define IRCONV_INDEX  (2<<IRCONV_CSH)\t/* Check + special backprop rules. */\n#define IRCONV_CHECK  (3<<IRCONV_CSH)\t/* Number checked for integerness. */\n\n/* TOSTR mode, stored in op2. */\n#define IRTOSTR_INT\t\t0\t/* Convert integer to string. */\n#define IRTOSTR_NUM\t\t1\t/* Convert number to string. */\n#define IRTOSTR_CHAR\t\t2\t/* Convert char value to string. */\n\n/* -- IR operands --------------------------------------------------------- */\n\n/* IR operand mode (2 bit). */\ntypedef enum {\n  IRMref,\t\t/* IR reference. */\n  IRMlit,\t\t/* 16 bit unsigned literal. */\n  IRMcst,\t\t/* Constant literal: i, gcr or ptr. */\n  IRMnone\t\t/* Unused operand. */\n} IRMode;\n#define IRM___\t\tIRMnone\n\n/* Mode bits: Commutative, {Normal/Ref, Alloc, Load, Store}, Non-weak guard. */\n#define IRM_C\t\t\t0x10\n\n#define IRM_N\t\t\t0x00\n#define IRM_R\t\t\tIRM_N\n#define IRM_A\t\t\t0x20\n#define IRM_L\t\t\t0x40\n#define IRM_S\t\t\t0x60\n\n#define IRM_W\t\t\t0x80\n\n#define IRM_NW\t\t\t(IRM_N|IRM_W)\n#define IRM_CW\t\t\t(IRM_C|IRM_W)\n#define IRM_AW\t\t\t(IRM_A|IRM_W)\n#define IRM_LW\t\t\t(IRM_L|IRM_W)\n\n#define irm_op1(m)\t\t((IRMode)((m)&3))\n#define irm_op2(m)\t\t((IRMode)(((m)>>2)&3))\n#define irm_iscomm(m)\t\t((m) & IRM_C)\n#define irm_kind(m)\t\t((m) & IRM_S)\n\n#define IRMODE(name, m, m1, m2)\t(((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W),\n\nLJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];\n\n/* -- IR instruction types ------------------------------------------------ */\n\n/* Map of itypes to non-negative numbers. ORDER LJ_T.\n** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for\n** IRT_P32 and IRT_P64, which never escape the IR.\n** The various integers are only used in the IR and can only escape to\n** a TValue after implicit or explicit conversion. Their types must be\n** contiguous and next to IRT_NUM (see the typerange macros below).\n*/\n#define IRTDEF(_) \\\n  _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \\\n  _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \\\n  _(TAB, 4) _(UDATA, 4) \\\n  _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \\\n  _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \\\n  _(SOFTFP, 4)  /* There is room for 9 more types. */\n\n/* IR result type and flags (8 bit). */\ntypedef enum {\n#define IRTENUM(name, size)\tIRT_##name,\nIRTDEF(IRTENUM)\n#undef IRTENUM\n  IRT__MAX,\n\n  /* Native pointer type and the corresponding integer type. */\n  IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32,\n  IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT,\n  IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32,\n  /* TODO_GC64: major changes required for all uses of IRT_P32. */\n\n  /* Additional flags. */\n  IRT_MARK = 0x20,\t/* Marker for misc. purposes. */\n  IRT_ISPHI = 0x40,\t/* Instruction is left or right PHI operand. */\n  IRT_GUARD = 0x80,\t/* Instruction is a guard. */\n\n  /* Masks. */\n  IRT_TYPE = 0x1f,\n  IRT_T = 0xff\n} IRType;\n\n#define irtype_ispri(irt)\t((uint32_t)(irt) <= IRT_TRUE)\n\n/* Stored IRType. */\ntypedef struct IRType1 { uint8_t irt; } IRType1;\n\n#define IRT(o, t)\t\t((uint32_t)(((o)<<8) | (t)))\n#define IRTI(o)\t\t\t(IRT((o), IRT_INT))\n#define IRTN(o)\t\t\t(IRT((o), IRT_NUM))\n#define IRTG(o, t)\t\t(IRT((o), IRT_GUARD|(t)))\n#define IRTGI(o)\t\t(IRT((o), IRT_GUARD|IRT_INT))\n\n#define irt_t(t)\t\t((IRType)(t).irt)\n#define irt_type(t)\t\t((IRType)((t).irt & IRT_TYPE))\n#define irt_sametype(t1, t2)\t((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0)\n#define irt_typerange(t, first, last) \\\n  ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first))\n\n#define irt_isnil(t)\t\t(irt_type(t) == IRT_NIL)\n#define irt_ispri(t)\t\t((uint32_t)irt_type(t) <= IRT_TRUE)\n#define irt_islightud(t)\t(irt_type(t) == IRT_LIGHTUD)\n#define irt_isstr(t)\t\t(irt_type(t) == IRT_STR)\n#define irt_istab(t)\t\t(irt_type(t) == IRT_TAB)\n#define irt_iscdata(t)\t\t(irt_type(t) == IRT_CDATA)\n#define irt_isfloat(t)\t\t(irt_type(t) == IRT_FLOAT)\n#define irt_isnum(t)\t\t(irt_type(t) == IRT_NUM)\n#define irt_isint(t)\t\t(irt_type(t) == IRT_INT)\n#define irt_isi8(t)\t\t(irt_type(t) == IRT_I8)\n#define irt_isu8(t)\t\t(irt_type(t) == IRT_U8)\n#define irt_isi16(t)\t\t(irt_type(t) == IRT_I16)\n#define irt_isu16(t)\t\t(irt_type(t) == IRT_U16)\n#define irt_isu32(t)\t\t(irt_type(t) == IRT_U32)\n#define irt_isi64(t)\t\t(irt_type(t) == IRT_I64)\n#define irt_isu64(t)\t\t(irt_type(t) == IRT_U64)\n\n#define irt_isfp(t)\t\t(irt_isnum(t) || irt_isfloat(t))\n#define irt_isinteger(t)\t(irt_typerange((t), IRT_I8, IRT_INT))\n#define irt_isgcv(t)\t\t(irt_typerange((t), IRT_STR, IRT_UDATA))\n#define irt_isaddr(t)\t\t(irt_typerange((t), IRT_LIGHTUD, IRT_UDATA))\n#define irt_isint64(t)\t\t(irt_typerange((t), IRT_I64, IRT_U64))\n\n#if LJ_GC64\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|\\\n   (1u<<IRT_LIGHTUD)|(1u<<IRT_STR)|(1u<<IRT_THREAD)|(1u<<IRT_PROTO)|\\\n   (1u<<IRT_FUNC)|(1u<<IRT_CDATA)|(1u<<IRT_TAB)|(1u<<IRT_UDATA))\n#elif LJ_64\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD))\n#else\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64))\n#endif\n\n#define irt_is64(t)\t\t((IRT_IS64 >> irt_type(t)) & 1)\n#define irt_is64orfp(t)\t\t(((IRT_IS64|(1u<<IRT_FLOAT))>>irt_type(t)) & 1)\n\n#define irt_size(t)\t\t(lj_ir_type_size[irt_t((t))])\n\nLJ_DATA const uint8_t lj_ir_type_size[];\n\nstatic LJ_AINLINE IRType itype2irt(const TValue *tv)\n{\n  if (tvisint(tv))\n    return IRT_INT;\n  else if (tvisnum(tv))\n    return IRT_NUM;\n#if LJ_64 && !LJ_GC64\n  else if (tvislightud(tv))\n    return IRT_LIGHTUD;\n#endif\n  else\n    return (IRType)~itype(tv);\n}\n\nstatic LJ_AINLINE uint32_t irt_toitype_(IRType t)\n{\n  lua_assert(!LJ_64 || t != IRT_LIGHTUD);\n  if (LJ_DUALNUM && t > IRT_NUM) {\n    return LJ_TISNUM;\n  } else {\n    lua_assert(t <= IRT_NUM);\n    return ~(uint32_t)t;\n  }\n}\n\n#define irt_toitype(t)\t\tirt_toitype_(irt_type((t)))\n\n#define irt_isguard(t)\t\t((t).irt & IRT_GUARD)\n#define irt_ismarked(t)\t\t((t).irt & IRT_MARK)\n#define irt_setmark(t)\t\t((t).irt |= IRT_MARK)\n#define irt_clearmark(t)\t((t).irt &= ~IRT_MARK)\n#define irt_isphi(t)\t\t((t).irt & IRT_ISPHI)\n#define irt_setphi(t)\t\t((t).irt |= IRT_ISPHI)\n#define irt_clearphi(t)\t\t((t).irt &= ~IRT_ISPHI)\n\n/* Stored combined IR opcode and type. */\ntypedef uint16_t IROpT;\n\n/* -- IR references ------------------------------------------------------- */\n\n/* IR references. */\ntypedef uint16_t IRRef1;\t/* One stored reference. */\ntypedef uint32_t IRRef2;\t/* Two stored references. */\ntypedef uint32_t IRRef;\t\t/* Used to pass around references. */\n\n/* Fixed references. */\nenum {\n  REF_BIAS =\t0x8000,\n  REF_TRUE =\tREF_BIAS-3,\n  REF_FALSE =\tREF_BIAS-2,\n  REF_NIL =\tREF_BIAS-1,\t/* \\--- Constants grow downwards. */\n  REF_BASE =\tREF_BIAS,\t/* /--- IR grows upwards. */\n  REF_FIRST =\tREF_BIAS+1,\n  REF_DROP =\t0xffff\n};\n\n/* Note: IRMlit operands must be < REF_BIAS, too!\n** This allows for fast and uniform manipulation of all operands\n** without looking up the operand mode in lj_ir_mode:\n** - CSE calculates the maximum reference of two operands.\n**   This must work with mixed reference/literal operands, too.\n** - DCE marking only checks for operand >= REF_BIAS.\n** - LOOP needs to substitute reference operands.\n**   Constant references and literals must not be modified.\n*/\n\n#define IRREF2(lo, hi)\t\t((IRRef2)(lo) | ((IRRef2)(hi) << 16))\n\n#define irref_isk(ref)\t\t((ref) < REF_BIAS)\n\n/* Tagged IR references (32 bit).\n**\n** +-------+-------+---------------+\n** |  irt  | flags |      ref      |\n** +-------+-------+---------------+\n**\n** The tag holds a copy of the IRType and speeds up IR type checks.\n*/\ntypedef uint32_t TRef;\n\n#define TREF_REFMASK\t\t0x0000ffff\n#define TREF_FRAME\t\t0x00010000\n#define TREF_CONT\t\t0x00020000\n\n#define TREF(ref, t)\t\t((TRef)((ref) + ((t)<<24)))\n\n#define tref_ref(tr)\t\t((IRRef1)(tr))\n#define tref_t(tr)\t\t((IRType)((tr)>>24))\n#define tref_type(tr)\t\t((IRType)(((tr)>>24) & IRT_TYPE))\n#define tref_typerange(tr, first, last) \\\n  ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first))\n\n#define tref_istype(tr, t)\t(((tr) & (IRT_TYPE<<24)) == ((t)<<24))\n#define tref_isnil(tr)\t\t(tref_istype((tr), IRT_NIL))\n#define tref_isfalse(tr)\t(tref_istype((tr), IRT_FALSE))\n#define tref_istrue(tr)\t\t(tref_istype((tr), IRT_TRUE))\n#define tref_islightud(tr)\t(tref_istype((tr), IRT_LIGHTUD))\n#define tref_isstr(tr)\t\t(tref_istype((tr), IRT_STR))\n#define tref_isfunc(tr)\t\t(tref_istype((tr), IRT_FUNC))\n#define tref_iscdata(tr)\t(tref_istype((tr), IRT_CDATA))\n#define tref_istab(tr)\t\t(tref_istype((tr), IRT_TAB))\n#define tref_isudata(tr)\t(tref_istype((tr), IRT_UDATA))\n#define tref_isnum(tr)\t\t(tref_istype((tr), IRT_NUM))\n#define tref_isint(tr)\t\t(tref_istype((tr), IRT_INT))\n\n#define tref_isbool(tr)\t\t(tref_typerange((tr), IRT_FALSE, IRT_TRUE))\n#define tref_ispri(tr)\t\t(tref_typerange((tr), IRT_NIL, IRT_TRUE))\n#define tref_istruecond(tr)\t(!tref_typerange((tr), IRT_NIL, IRT_FALSE))\n#define tref_isinteger(tr)\t(tref_typerange((tr), IRT_I8, IRT_INT))\n#define tref_isnumber(tr)\t(tref_typerange((tr), IRT_NUM, IRT_INT))\n#define tref_isnumber_str(tr)\t(tref_isnumber((tr)) || tref_isstr((tr)))\n#define tref_isgcv(tr)\t\t(tref_typerange((tr), IRT_STR, IRT_UDATA))\n\n#define tref_isk(tr)\t\t(irref_isk(tref_ref((tr))))\n#define tref_isk2(tr1, tr2)\t(irref_isk(tref_ref((tr1) | (tr2))))\n\n#define TREF_PRI(t)\t\t(TREF(REF_NIL-(t), (t)))\n#define TREF_NIL\t\t(TREF_PRI(IRT_NIL))\n#define TREF_FALSE\t\t(TREF_PRI(IRT_FALSE))\n#define TREF_TRUE\t\t(TREF_PRI(IRT_TRUE))\n\n/* -- IR format ----------------------------------------------------------- */\n\n/* IR instruction format (64 bit).\n**\n**    16      16     8   8   8   8\n** +-------+-------+---+---+---+---+\n** |  op1  |  op2  | t | o | r | s |\n** +-------+-------+---+---+---+---+\n** |  op12/i/gco   |   ot  | prev  | (alternative fields in union)\n** +---------------+-------+-------+\n**        32           16      16\n**\n** prev is only valid prior to register allocation and then reused for r + s.\n*/\n\ntypedef union IRIns {\n  struct {\n    LJ_ENDIAN_LOHI(\n      IRRef1 op1;\t/* IR operand 1. */\n    , IRRef1 op2;\t/* IR operand 2. */\n    )\n    IROpT ot;\t\t/* IR opcode and type (overlaps t and o). */\n    IRRef1 prev;\t/* Previous ins in same chain (overlaps r and s). */\n  };\n  struct {\n    IRRef2 op12;\t/* IR operand 1 and 2 (overlaps op1 and op2). */\n    LJ_ENDIAN_LOHI(\n      IRType1 t;\t/* IR type. */\n    , IROp1 o;\t\t/* IR opcode. */\n    )\n    LJ_ENDIAN_LOHI(\n      uint8_t r;\t/* Register allocation (overlaps prev). */\n    , uint8_t s;\t/* Spill slot allocation (overlaps prev). */\n    )\n  };\n  int32_t i;\t\t/* 32 bit signed integer literal (overlaps op12). */\n  GCRef gcr;\t\t/* GCobj constant (overlaps op12). */\n  MRef ptr;\t\t/* Pointer constant (overlaps op12). */\n} IRIns;\n\n/* TODO_GC64: major changes required. */\n#define ir_kgc(ir)\tcheck_exp((ir)->o == IR_KGC, gcref((ir)->gcr))\n#define ir_kstr(ir)\t(gco2str(ir_kgc((ir))))\n#define ir_ktab(ir)\t(gco2tab(ir_kgc((ir))))\n#define ir_kfunc(ir)\t(gco2func(ir_kgc((ir))))\n#define ir_kcdata(ir)\t(gco2cd(ir_kgc((ir))))\n#define ir_knum(ir)\tcheck_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue))\n#define ir_kint64(ir)\tcheck_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))\n#define ir_k64(ir) \\\n  check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))\n#define ir_kptr(ir) \\\n  check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void))\n\n/* A store or any other op with a non-weak guard has a side-effect. */\nstatic LJ_AINLINE int ir_sideeff(IRIns *ir)\n{\n  return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S);\n}\n\nLJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_ircall.h",
    "content": "/*\n** IR CALL* instruction definitions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IRCALL_H\n#define _LJ_IRCALL_H\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n\n/* C call info for CALL* instructions. */\ntypedef struct CCallInfo {\n  ASMFunction func;\t\t/* Function pointer. */\n  uint32_t flags;\t\t/* Number of arguments and flags. */\n} CCallInfo;\n\n#define CCI_NARGS(ci)\t\t((ci)->flags & 0xff)\t/* # of args. */\n#define CCI_NARGS_MAX\t\t32\t\t\t/* Max. # of args. */\n\n#define CCI_OTSHIFT\t\t16\n#define CCI_OPTYPE(ci)\t\t((ci)->flags >> CCI_OTSHIFT)  /* Get op/type. */\n#define CCI_OPSHIFT\t\t24\n#define CCI_OP(ci)\t\t((ci)->flags >> CCI_OPSHIFT)  /* Get op. */\n\n#define CCI_CALL_N\t\t(IR_CALLN << CCI_OPSHIFT)\n#define CCI_CALL_A\t\t(IR_CALLA << CCI_OPSHIFT)\n#define CCI_CALL_L\t\t(IR_CALLL << CCI_OPSHIFT)\n#define CCI_CALL_S\t\t(IR_CALLS << CCI_OPSHIFT)\n#define CCI_CALL_FN\t\t(CCI_CALL_N|CCI_CC_FASTCALL)\n#define CCI_CALL_FL\t\t(CCI_CALL_L|CCI_CC_FASTCALL)\n#define CCI_CALL_FS\t\t(CCI_CALL_S|CCI_CC_FASTCALL)\n\n/* C call info flags. */\n#define CCI_L\t\t\t0x0100\t/* Implicit L arg. */\n#define CCI_CASTU64\t\t0x0200\t/* Cast u64 result to number. */\n#define CCI_NOFPRCLOBBER\t0x0400\t/* Does not clobber any FPRs. */\n#define CCI_VARARG\t\t0x0800\t/* Vararg function. */\n\n#define CCI_CC_MASK\t\t0x3000\t/* Calling convention mask. */\n#define CCI_CC_SHIFT\t\t12\n/* ORDER CC */\n#define CCI_CC_CDECL\t\t0x0000\t/* Default cdecl calling convention. */\n#define CCI_CC_THISCALL\t\t0x1000\t/* Thiscall calling convention. */\n#define CCI_CC_FASTCALL\t\t0x2000\t/* Fastcall calling convention. */\n#define CCI_CC_STDCALL\t\t0x3000\t/* Stdcall calling convention. */\n\n/* Extra args for SOFTFP, SPLIT 64 bit. */\n#define CCI_XARGS_SHIFT\t\t14\n#define CCI_XARGS(ci)\t\t(((ci)->flags >> CCI_XARGS_SHIFT) & 3)\n#define CCI_XA\t\t\t(1u << CCI_XARGS_SHIFT)\n\n#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)\n#define CCI_XNARGS(ci)\t\t(CCI_NARGS((ci)) + CCI_XARGS((ci)))\n#else\n#define CCI_XNARGS(ci)\t\tCCI_NARGS((ci))\n#endif\n\n/* Helpers for conditional function definitions. */\n#define IRCALLCOND_ANY(x)\t\tx\n\n#if LJ_TARGET_X86ORX64\n#define IRCALLCOND_FPMATH(x)\t\tNULL\n#else\n#define IRCALLCOND_FPMATH(x)\t\tx\n#endif\n\n#if LJ_SOFTFP\n#define IRCALLCOND_SOFTFP(x)\t\tx\n#if LJ_HASFFI\n#define IRCALLCOND_SOFTFP_FFI(x)\tx\n#else\n#define IRCALLCOND_SOFTFP_FFI(x)\tNULL\n#endif\n#else\n#define IRCALLCOND_SOFTFP(x)\t\tNULL\n#define IRCALLCOND_SOFTFP_FFI(x)\tNULL\n#endif\n\n#if LJ_SOFTFP && LJ_TARGET_MIPS\n#define IRCALLCOND_SOFTFP_MIPS(x)\tx\n#else\n#define IRCALLCOND_SOFTFP_MIPS(x)\tNULL\n#endif\n\n#define LJ_NEED_FP64\t(LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS)\n\n#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)\n#define IRCALLCOND_FP64_FFI(x)\t\tx\n#else\n#define IRCALLCOND_FP64_FFI(x)\t\tNULL\n#endif\n\n#if LJ_HASFFI\n#define IRCALLCOND_FFI(x)\t\tx\n#if LJ_32\n#define IRCALLCOND_FFI32(x)\t\tx\n#else\n#define IRCALLCOND_FFI32(x)\t\tNULL\n#endif\n#else\n#define IRCALLCOND_FFI(x)\t\tNULL\n#define IRCALLCOND_FFI32(x)\t\tNULL\n#endif\n\n#if LJ_TARGET_X86\n#define CCI_RANDFPR\t0\t/* Clang on OSX/x86 is overzealous. */\n#else\n#define CCI_RANDFPR\tCCI_NOFPRCLOBBER\n#endif\n\n#if LJ_SOFTFP\n#define XA_FP\t\tCCI_XA\n#define XA2_FP\t\t(CCI_XA+CCI_XA)\n#else\n#define XA_FP\t\t0\n#define XA2_FP\t\t0\n#endif\n\n#if LJ_32\n#define XA_64\t\tCCI_XA\n#define XA2_64\t\t(CCI_XA+CCI_XA)\n#else\n#define XA_64\t\t0\n#define XA2_64\t\t0\n#endif\n\n/* Function definitions for CALL* instructions. */\n#define IRCALLDEF(_) \\\n  _(ANY,\tlj_str_cmp,\t\t2,  FN, INT, CCI_NOFPRCLOBBER) \\\n  _(ANY,\tlj_str_find,\t\t4,   N, P32, 0) \\\n  _(ANY,\tlj_str_new,\t\t3,   S, STR, CCI_L) \\\n  _(ANY,\tlj_strscan_num,\t\t2,  FN, INT, 0) \\\n  _(ANY,\tlj_strfmt_int,\t\t2,  FN, STR, CCI_L) \\\n  _(ANY,\tlj_strfmt_num,\t\t2,  FN, STR, CCI_L) \\\n  _(ANY,\tlj_strfmt_char,\t\t2,  FN, STR, CCI_L) \\\n  _(ANY,\tlj_strfmt_putint,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_strfmt_putnum,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_strfmt_putquoted,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_strfmt_putfxint,\t3,   L, P32, XA_64) \\\n  _(ANY,\tlj_strfmt_putfnum_int,\t3,   L, P32, XA_FP) \\\n  _(ANY,\tlj_strfmt_putfnum_uint,\t3,   L, P32, XA_FP) \\\n  _(ANY,\tlj_strfmt_putfnum,\t3,   L, P32, XA_FP) \\\n  _(ANY,\tlj_strfmt_putfstr,\t3,   L, P32, 0) \\\n  _(ANY,\tlj_strfmt_putfchar,\t3,   L, P32, 0) \\\n  _(ANY,\tlj_buf_putmem,\t\t3,   S, P32, 0) \\\n  _(ANY,\tlj_buf_putstr,\t\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_buf_putchar,\t\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_buf_putstr_reverse,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_buf_putstr_lower,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_buf_putstr_upper,\t2,  FL, P32, 0) \\\n  _(ANY,\tlj_buf_putstr_rep,\t3,   L, P32, 0) \\\n  _(ANY,\tlj_buf_puttab,\t\t5,   L, P32, 0) \\\n  _(ANY,\tlj_buf_tostr,\t\t1,  FL, STR, 0) \\\n  _(ANY,\tlj_tab_new_ah,\t\t3,   A, TAB, CCI_L) \\\n  _(ANY,\tlj_tab_new1,\t\t2,  FS, TAB, CCI_L) \\\n  _(ANY,\tlj_tab_dup,\t\t2,  FS, TAB, CCI_L) \\\n  _(ANY,\tlj_tab_clear,\t\t1,  FS, NIL, 0) \\\n  _(ANY,\tlj_tab_newkey,\t\t3,   S, P32, CCI_L) \\\n  _(ANY,\tlj_tab_len,\t\t1,  FL, INT, 0) \\\n  _(ANY,\tlj_gc_step_jit,\t\t2,  FS, NIL, CCI_L) \\\n  _(ANY,\tlj_gc_barrieruv,\t2,  FS, NIL, 0) \\\n  _(ANY,\tlj_mem_newgco,\t\t2,  FS, P32, CCI_L) \\\n  _(ANY,\tlj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_RANDFPR)\\\n  _(ANY,\tlj_vm_modi,\t\t2,  FN, INT, 0) \\\n  _(ANY,\tsinh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tcosh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\ttanh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tfputc,\t\t\t2,   S, INT, 0) \\\n  _(ANY,\tfwrite,\t\t\t4,   S, INT, 0) \\\n  _(ANY,\tfflush,\t\t\t1,   S, INT, 0) \\\n  /* ORDER FPM */ \\\n  _(FPMATH,\tlj_vm_floor,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tlj_vm_ceil,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tlj_vm_trunc,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tsqrt,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\texp,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlj_vm_exp2,\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlog,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlj_vm_log2,\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlog10,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tsin,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tcos,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\ttan,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlj_vm_powi,\t\t2,   N, NUM, XA_FP) \\\n  _(ANY,\tpow,\t\t\t2,   N, NUM, XA2_FP) \\\n  _(ANY,\tatan2,\t\t\t2,   N, NUM, XA2_FP) \\\n  _(ANY,\tldexp,\t\t\t2,   N, NUM, XA_FP) \\\n  _(SOFTFP,\tlj_vm_tobit,\t\t2,   N, INT, 0) \\\n  _(SOFTFP,\tsoftfp_add,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_sub,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_mul,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_div,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_cmp,\t\t4,   N, NIL, 0) \\\n  _(SOFTFP,\tsoftfp_i2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_d2i,\t\t2,   N, INT, 0) \\\n  _(SOFTFP_MIPS, lj_vm_sfmin,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP_MIPS, lj_vm_sfmax,\t\t4,   N, NUM, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_ui2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_d2ui,\t\t2,   N, INT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_d2f,\t\t2,   N, FLOAT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_i2f,\t\t1,   N, FLOAT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_ui2f,\t\t1,   N, FLOAT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2i,\t\t1,   N, INT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2ui,\t\t1,   N, INT, 0) \\\n  _(FP64_FFI,\tfp64_l2d,\t\t1,   N, NUM, XA_64) \\\n  _(FP64_FFI,\tfp64_ul2d,\t\t1,   N, NUM, XA_64) \\\n  _(FP64_FFI,\tfp64_l2f,\t\t1,   N, FLOAT, XA_64) \\\n  _(FP64_FFI,\tfp64_ul2f,\t\t1,   N, FLOAT, XA_64) \\\n  _(FP64_FFI,\tfp64_d2l,\t\t1,   N, I64, XA_FP) \\\n  _(FP64_FFI,\tfp64_d2ul,\t\t1,   N, U64, XA_FP) \\\n  _(FP64_FFI,\tfp64_f2l,\t\t1,   N, I64, 0) \\\n  _(FP64_FFI,\tfp64_f2ul,\t\t1,   N, U64, 0) \\\n  _(FFI,\tlj_carith_divi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_divu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_modi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_modu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_powi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_powu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_cdata_newv,\t\t4,   S, CDATA, CCI_L) \\\n  _(FFI,\tlj_cdata_setfin,\t4,   S, NIL, CCI_L) \\\n  _(FFI,\tstrlen,\t\t\t1,   L, INTP, 0) \\\n  _(FFI,\tmemcpy,\t\t\t3,   S, PTR, 0) \\\n  _(FFI,\tmemset,\t\t\t3,   S, PTR, 0) \\\n  _(FFI,\tlj_vm_errno,\t\t0,   S, INT, CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_mul64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_shl64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_shr64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_sar64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_rol64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_ror64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  \\\n  /* End of list. */\n\ntypedef enum {\n#define IRCALLENUM(cond, name, nargs, kind, type, flags)\tIRCALL_##name,\nIRCALLDEF(IRCALLENUM)\n#undef IRCALLENUM\n  IRCALL__MAX\n} IRCallID;\n\nLJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);\n\nLJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];\n\n/* Soft-float declarations. */\n#if LJ_SOFTFP\n#if LJ_TARGET_ARM\n#define softfp_add __aeabi_dadd\n#define softfp_sub __aeabi_dsub\n#define softfp_mul __aeabi_dmul\n#define softfp_div __aeabi_ddiv\n#define softfp_cmp __aeabi_cdcmple\n#define softfp_i2d __aeabi_i2d\n#define softfp_d2i __aeabi_d2iz\n#define softfp_ui2d __aeabi_ui2d\n#define softfp_f2d __aeabi_f2d\n#define softfp_d2ui __aeabi_d2uiz\n#define softfp_d2f __aeabi_d2f\n#define softfp_i2f __aeabi_i2f\n#define softfp_ui2f __aeabi_ui2f\n#define softfp_f2i __aeabi_f2iz\n#define softfp_f2ui __aeabi_f2uiz\n#define fp64_l2d __aeabi_l2d\n#define fp64_ul2d __aeabi_ul2d\n#define fp64_l2f __aeabi_l2f\n#define fp64_ul2f __aeabi_ul2f\n#if LJ_TARGET_IOS\n#define fp64_d2l __fixdfdi\n#define fp64_d2ul __fixunsdfdi\n#define fp64_f2l __fixsfdi\n#define fp64_f2ul __fixunssfdi\n#else\n#define fp64_d2l __aeabi_d2lz\n#define fp64_d2ul __aeabi_d2ulz\n#define fp64_f2l __aeabi_f2lz\n#define fp64_f2ul __aeabi_f2ulz\n#endif\n#elif LJ_TARGET_MIPS\n#define softfp_add __adddf3\n#define softfp_sub __subdf3\n#define softfp_mul __muldf3\n#define softfp_div __divdf3\n#define softfp_cmp __ledf2\n#define softfp_i2d __floatsidf\n#define softfp_d2i __fixdfsi\n#define softfp_ui2d __floatunsidf\n#define softfp_f2d __extendsfdf2\n#define softfp_d2ui __fixunsdfsi\n#define softfp_d2f __truncdfsf2\n#define softfp_i2f __floatsisf\n#define softfp_ui2f __floatunsisf\n#define softfp_f2i __fixsfsi\n#define softfp_f2ui __fixunssfsi\n#else\n#error \"Missing soft-float definitions for target architecture\"\n#endif\nextern double softfp_add(double a, double b);\nextern double softfp_sub(double a, double b);\nextern double softfp_mul(double a, double b);\nextern double softfp_div(double a, double b);\nextern void softfp_cmp(double a, double b);\nextern double softfp_i2d(int32_t a);\nextern int32_t softfp_d2i(double a);\n#if LJ_HASFFI\nextern double softfp_ui2d(uint32_t a);\nextern double softfp_f2d(float a);\nextern uint32_t softfp_d2ui(double a);\nextern float softfp_d2f(double a);\nextern float softfp_i2f(int32_t a);\nextern float softfp_ui2f(uint32_t a);\nextern int32_t softfp_f2i(float a);\nextern uint32_t softfp_f2ui(float a);\n#endif\n#if LJ_TARGET_MIPS\nextern double lj_vm_sfmin(double a, double b);\nextern double lj_vm_sfmax(double a, double b);\n#endif\n#endif\n\n#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP)\n#ifdef __GNUC__\n#define fp64_l2d __floatdidf\n#define fp64_ul2d __floatundidf\n#define fp64_l2f __floatdisf\n#define fp64_ul2f __floatundisf\n#define fp64_d2l __fixdfdi\n#define fp64_d2ul __fixunsdfdi\n#define fp64_f2l __fixsfdi\n#define fp64_f2ul __fixunssfdi\n#else\n#error \"Missing fp64 helper definitions for this compiler\"\n#endif\n#endif\n\n#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)\nextern double fp64_l2d(int64_t a);\nextern double fp64_ul2d(uint64_t a);\nextern float fp64_l2f(int64_t a);\nextern float fp64_ul2f(uint64_t a);\nextern int64_t fp64_d2l(double a);\nextern uint64_t fp64_d2ul(double a);\nextern int64_t fp64_f2l(float a);\nextern uint64_t fp64_f2ul(float a);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_iropt.h",
    "content": "/*\n** Common header for IR emitter and optimizations.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IROPT_H\n#define _LJ_IROPT_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* IR emitter. */\nLJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J);\n\n/* Save current IR in J->fold.ins, but do not emit it (yet). */\nstatic LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b)\n{\n  J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b;\n}\n\n#define lj_ir_set(J, ot, a, b) \\\n  lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b))\n\n/* Get ref of next IR instruction and optionally grow IR.\n** Note: this may invalidate all IRIns*!\n*/\nstatic LJ_AINLINE IRRef lj_ir_nextins(jit_State *J)\n{\n  IRRef ref = J->cur.nins;\n  if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J);\n  J->cur.nins = ref + 1;\n  return ref;\n}\n\n/* Interning of constants. */\nLJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k);\nLJ_FUNC void lj_ir_k64_freeall(jit_State *J);\nLJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv);\nLJ_FUNC TValue *lj_ir_k64_reserve(jit_State *J);\nLJ_FUNC cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64);\nLJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64);\nLJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n);\nLJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64);\nLJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);\nLJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);\nLJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);\nLJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);\n\n#if LJ_64\n#define lj_ir_kintp(J, k)\tlj_ir_kint64(J, (uint64_t)(k))\n#else\n#define lj_ir_kintp(J, k)\tlj_ir_kint(J, (int32_t)(k))\n#endif\n\nstatic LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n)\n{\n  TValue tv;\n  tv.n = n;\n  return lj_ir_knum_u64(J, tv.u64);\n}\n\n#define lj_ir_kstr(J, str)\tlj_ir_kgc(J, obj2gco((str)), IRT_STR)\n#define lj_ir_ktab(J, tab)\tlj_ir_kgc(J, obj2gco((tab)), IRT_TAB)\n#define lj_ir_kfunc(J, func)\tlj_ir_kgc(J, obj2gco((func)), IRT_FUNC)\n#define lj_ir_kptr(J, ptr)\tlj_ir_kptr_(J, IR_KPTR, (ptr))\n#define lj_ir_kkptr(J, ptr)\tlj_ir_kptr_(J, IR_KKPTR, (ptr))\n\n/* Special FP constants. */\n#define lj_ir_knum_zero(J)\tlj_ir_knum_u64(J, U64x(00000000,00000000))\n#define lj_ir_knum_one(J)\tlj_ir_knum_u64(J, U64x(3ff00000,00000000))\n#define lj_ir_knum_tobit(J)\tlj_ir_knum_u64(J, U64x(43380000,00000000))\n\n/* Special 128 bit SIMD constants. */\n#define lj_ir_knum_abs(J)\tlj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_ABS))\n#define lj_ir_knum_neg(J)\tlj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_NEG))\n\n/* Access to constants. */\nLJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir);\n\n/* Convert IR operand types. */\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr);\n\n/* Miscellaneous IR ops. */\nLJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op);\nLJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op);\nLJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref);\n\n/* Emit IR instructions with on-the-fly optimizations. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim);\n\n/* Special return values for the fold functions. */\nenum {\n  NEXTFOLD,\t\t/* Couldn't fold, pass on. */\n  RETRYFOLD,\t\t/* Retry fold with modified fins. */\n  KINTFOLD,\t\t/* Return ref for int constant in fins->i. */\n  FAILFOLD,\t\t/* Guard would always fail. */\n  DROPFOLD,\t\t/* Guard eliminated. */\n  MAX_FOLD\n};\n\n#define INTFOLD(k)\t((J->fold.ins.i = (k)), (TRef)KINTFOLD)\n#define INT64FOLD(k)\t(lj_ir_kint64(J, (k)))\n#define CONDFOLD(cond)\t((TRef)FAILFOLD + (TRef)(cond))\n#define LEFTFOLD\t(J->fold.ins.op1)\n#define RIGHTFOLD\t(J->fold.ins.op2)\n#define CSEFOLD\t\t(lj_opt_cse(J))\n#define EMITFOLD\t(lj_ir_emit(J))\n\n/* Load/store forwarding. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J);\nLJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J);\nLJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim);\nLJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref);\n\n/* Dead-store elimination. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J);\n\n/* Narrowing. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr);\n#if LJ_HASFFI\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key);\n#endif\nLJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,\n\t\t\t\t TValue *vb, TValue *vc, IROp op);\nLJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc);\nLJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc);\nLJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc);\nLJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase);\n\n/* Optimization passes. */\nLJ_FUNC void lj_opt_dce(jit_State *J);\nLJ_FUNC int lj_opt_loop(jit_State *J);\n#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)\nLJ_FUNC void lj_opt_split(jit_State *J);\n#else\n#define lj_opt_split(J)\t\tUNUSED(J)\n#endif\nLJ_FUNC void lj_opt_sink(jit_State *J);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_jit.h",
    "content": "/*\n** Common definitions for the JIT compiler.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_JIT_H\n#define _LJ_JIT_H\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n\n/* JIT engine flags. */\n#define JIT_F_ON\t\t0x00000001\n\n/* CPU-specific JIT engine flags. */\n#if LJ_TARGET_X86ORX64\n#define JIT_F_SSE2\t\t0x00000010\n#define JIT_F_SSE3\t\t0x00000020\n#define JIT_F_SSE4_1\t\t0x00000040\n#define JIT_F_PREFER_IMUL\t0x00000080\n#define JIT_F_LEA_AGU\t\t0x00000100\n\n/* Names for the CPU-specific flags. Must match the order above. */\n#define JIT_F_CPU_FIRST\t\tJIT_F_SSE2\n#define JIT_F_CPUSTRING\t\t\"\\4SSE2\\4SSE3\\6SSE4.1\\3AMD\\4ATOM\"\n#elif LJ_TARGET_ARM\n#define JIT_F_ARMV6_\t\t0x00000010\n#define JIT_F_ARMV6T2_\t\t0x00000020\n#define JIT_F_ARMV7\t\t0x00000040\n#define JIT_F_VFPV2\t\t0x00000080\n#define JIT_F_VFPV3\t\t0x00000100\n\n#define JIT_F_ARMV6\t\t(JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7)\n#define JIT_F_ARMV6T2\t\t(JIT_F_ARMV6T2_|JIT_F_ARMV7)\n#define JIT_F_VFP\t\t(JIT_F_VFPV2|JIT_F_VFPV3)\n\n/* Names for the CPU-specific flags. Must match the order above. */\n#define JIT_F_CPU_FIRST\t\tJIT_F_ARMV6_\n#define JIT_F_CPUSTRING\t\t\"\\5ARMv6\\7ARMv6T2\\5ARMv7\\5VFPv2\\5VFPv3\"\n#elif LJ_TARGET_PPC\n#define JIT_F_SQRT\t\t0x00000010\n#define JIT_F_ROUND\t\t0x00000020\n\n/* Names for the CPU-specific flags. Must match the order above. */\n#define JIT_F_CPU_FIRST\t\tJIT_F_SQRT\n#define JIT_F_CPUSTRING\t\t\"\\4SQRT\\5ROUND\"\n#elif LJ_TARGET_MIPS\n#define JIT_F_MIPS32R2\t\t0x00000010\n\n/* Names for the CPU-specific flags. Must match the order above. */\n#define JIT_F_CPU_FIRST\t\tJIT_F_MIPS32R2\n#define JIT_F_CPUSTRING\t\t\"\\010MIPS32R2\"\n#else\n#define JIT_F_CPU_FIRST\t\t0\n#define JIT_F_CPUSTRING\t\t\"\"\n#endif\n\n/* Optimization flags. */\n#define JIT_F_OPT_MASK\t\t0x0fff0000\n\n#define JIT_F_OPT_FOLD\t\t0x00010000\n#define JIT_F_OPT_CSE\t\t0x00020000\n#define JIT_F_OPT_DCE\t\t0x00040000\n#define JIT_F_OPT_FWD\t\t0x00080000\n#define JIT_F_OPT_DSE\t\t0x00100000\n#define JIT_F_OPT_NARROW\t0x00200000\n#define JIT_F_OPT_LOOP\t\t0x00400000\n#define JIT_F_OPT_ABC\t\t0x00800000\n#define JIT_F_OPT_SINK\t\t0x01000000\n#define JIT_F_OPT_FUSE\t\t0x02000000\n\n/* Optimizations names for -O. Must match the order above. */\n#define JIT_F_OPT_FIRST\t\tJIT_F_OPT_FOLD\n#define JIT_F_OPTSTRING\t\\\n  \"\\4fold\\3cse\\3dce\\3fwd\\3dse\\6narrow\\4loop\\3abc\\4sink\\4fuse\"\n\n/* Optimization levels set a fixed combination of flags. */\n#define JIT_F_OPT_0\t0\n#define JIT_F_OPT_1\t(JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE)\n#define JIT_F_OPT_2\t(JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP)\n#define JIT_F_OPT_3\t(JIT_F_OPT_2|\\\n  JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)\n#define JIT_F_OPT_DEFAULT\tJIT_F_OPT_3\n\n#if LJ_TARGET_WINDOWS || LJ_64\n/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */\n#define JIT_P_sizemcode_DEFAULT\t\t64\n#else\n/* Could go as low as 4K, but the mmap() overhead would be rather high. */\n#define JIT_P_sizemcode_DEFAULT\t\t32\n#endif\n\n/* Optimization parameters and their defaults. Length is a char in octal! */\n#define JIT_PARAMDEF(_) \\\n  _(\\010, maxtrace,\t1000)\t/* Max. # of traces in cache. */ \\\n  _(\\011, maxrecord,\t4000)\t/* Max. # of recorded IR instructions. */ \\\n  _(\\012, maxirconst,\t500)\t/* Max. # of IR constants of a trace. */ \\\n  _(\\007, maxside,\t100)\t/* Max. # of side traces of a root trace. */ \\\n  _(\\007, maxsnap,\t500)\t/* Max. # of snapshots for a trace. */ \\\n  _(\\011, minstitch,\t0)\t/* Min. # of IR ins for a stitched trace. */ \\\n  \\\n  _(\\007, hotloop,\t56)\t/* # of iter. to detect a hot loop/call. */ \\\n  _(\\007, hotexit,\t10)\t/* # of taken exits to start a side trace. */ \\\n  _(\\007, tryside,\t4)\t/* # of attempts to compile a side trace. */ \\\n  \\\n  _(\\012, instunroll,\t4)\t/* Max. unroll for instable loops. */ \\\n  _(\\012, loopunroll,\t15)\t/* Max. unroll for loop ops in side traces. */ \\\n  _(\\012, callunroll,\t3)\t/* Max. unroll for recursive calls. */ \\\n  _(\\011, recunroll,\t2)\t/* Min. unroll for true recursion. */ \\\n  \\\n  /* Size of each machine code area (in KBytes). */ \\\n  _(\\011, sizemcode,\tJIT_P_sizemcode_DEFAULT) \\\n  /* Max. total size of all machine code areas (in KBytes). */ \\\n  _(\\010, maxmcode,\t512) \\\n  /* End of list. */\n\nenum {\n#define JIT_PARAMENUM(len, name, value)\tJIT_P_##name,\nJIT_PARAMDEF(JIT_PARAMENUM)\n#undef JIT_PARAMENUM\n  JIT_P__MAX\n};\n\n#define JIT_PARAMSTR(len, name, value)\t#len #name\n#define JIT_P_STRING\tJIT_PARAMDEF(JIT_PARAMSTR)\n\n/* Trace compiler state. */\ntypedef enum {\n  LJ_TRACE_IDLE,\t/* Trace compiler idle. */\n  LJ_TRACE_ACTIVE = 0x10,\n  LJ_TRACE_RECORD,\t/* Bytecode recording active. */\n  LJ_TRACE_START,\t/* New trace started. */\n  LJ_TRACE_END,\t\t/* End of trace. */\n  LJ_TRACE_ASM,\t\t/* Assemble trace. */\n  LJ_TRACE_ERR\t\t/* Trace aborted with error. */\n} TraceState;\n\n/* Post-processing action. */\ntypedef enum {\n  LJ_POST_NONE,\t\t/* No action. */\n  LJ_POST_FIXCOMP,\t/* Fixup comparison and emit pending guard. */\n  LJ_POST_FIXGUARD,\t/* Fixup and emit pending guard. */\n  LJ_POST_FIXGUARDSNAP,\t/* Fixup and emit pending guard and snapshot. */\n  LJ_POST_FIXBOOL,\t/* Fixup boolean result. */\n  LJ_POST_FIXCONST,\t/* Fixup constant results. */\n  LJ_POST_FFRETRY\t/* Suppress recording of retried fast functions. */\n} PostProc;\n\n/* Machine code type. */\n#if LJ_TARGET_X86ORX64\ntypedef uint8_t MCode;\n#else\ntypedef uint32_t MCode;\n#endif\n\n/* Stack snapshot header. */\ntypedef struct SnapShot {\n  uint16_t mapofs;\t/* Offset into snapshot map. */\n  IRRef1 ref;\t\t/* First IR ref for this snapshot. */\n  uint8_t nslots;\t/* Number of valid slots. */\n  uint8_t topslot;\t/* Maximum frame extent. */\n  uint8_t nent;\t\t/* Number of compressed entries. */\n  uint8_t count;\t/* Count of taken exits for this snapshot. */\n} SnapShot;\n\n#define SNAPCOUNT_DONE\t255\t/* Already compiled and linked a side trace. */\n\n/* Compressed snapshot entry. */\ntypedef uint32_t SnapEntry;\n\n#define SNAP_FRAME\t\t0x010000\t/* Frame slot. */\n#define SNAP_CONT\t\t0x020000\t/* Continuation slot. */\n#define SNAP_NORESTORE\t\t0x040000\t/* No need to restore slot. */\n#define SNAP_SOFTFPNUM\t\t0x080000\t/* Soft-float number. */\nLJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME);\nLJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT);\n\n#define SNAP(slot, flags, ref)\t(((SnapEntry)(slot) << 24) + (flags) + (ref))\n#define SNAP_TR(slot, tr) \\\n  (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK)))\n#define SNAP_MKPC(pc)\t\t((SnapEntry)u32ptr(pc))\n#define SNAP_MKFTSZ(ftsz)\t((SnapEntry)(ftsz))\n#define snap_ref(sn)\t\t((sn) & 0xffff)\n#define snap_slot(sn)\t\t((BCReg)((sn) >> 24))\n#define snap_isframe(sn)\t((sn) & SNAP_FRAME)\n#define snap_pc(sn)\t\t((const BCIns *)(uintptr_t)(sn))\n#define snap_setref(sn, ref)\t(((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref))\n\n/* Snapshot and exit numbers. */\ntypedef uint32_t SnapNo;\ntypedef uint32_t ExitNo;\n\n/* Trace number. */\ntypedef uint32_t TraceNo;\t/* Used to pass around trace numbers. */\ntypedef uint16_t TraceNo1;\t/* Stored trace number. */\n\n/* Type of link. ORDER LJ_TRLINK */\ntypedef enum {\n  LJ_TRLINK_NONE,\t\t/* Incomplete trace. No link, yet. */\n  LJ_TRLINK_ROOT,\t\t/* Link to other root trace. */\n  LJ_TRLINK_LOOP,\t\t/* Loop to same trace. */\n  LJ_TRLINK_TAILREC,\t\t/* Tail-recursion. */\n  LJ_TRLINK_UPREC,\t\t/* Up-recursion. */\n  LJ_TRLINK_DOWNREC,\t\t/* Down-recursion. */\n  LJ_TRLINK_INTERP,\t\t/* Fallback to interpreter. */\n  LJ_TRLINK_RETURN,\t\t/* Return to interpreter. */\n  LJ_TRLINK_STITCH\t\t/* Trace stitching. */\n} TraceLink;\n\n/* Trace object. */\ntypedef struct GCtrace {\n  GCHeader;\n  uint8_t topslot;\t/* Top stack slot already checked to be allocated. */\n  uint8_t linktype;\t/* Type of link. */\n  IRRef nins;\t\t/* Next IR instruction. Biased with REF_BIAS. */\n#if LJ_GC64\n  uint32_t unused_gc64;\n#endif\n  GCRef gclist;\n  IRIns *ir;\t\t/* IR instructions/constants. Biased with REF_BIAS. */\n  IRRef nk;\t\t/* Lowest IR constant. Biased with REF_BIAS. */\n  uint16_t nsnap;\t/* Number of snapshots. */\n  uint16_t nsnapmap;\t/* Number of snapshot map elements. */\n  SnapShot *snap;\t/* Snapshot array. */\n  SnapEntry *snapmap;\t/* Snapshot map. */\n  GCRef startpt;\t/* Starting prototype. */\n  MRef startpc;\t\t/* Bytecode PC of starting instruction. */\n  BCIns startins;\t/* Original bytecode of starting instruction. */\n  MSize szmcode;\t/* Size of machine code. */\n  MCode *mcode;\t\t/* Start of machine code. */\n  MSize mcloop;\t\t/* Offset of loop start in machine code. */\n  uint16_t nchild;\t/* Number of child traces (root trace only). */\n  uint16_t spadjust;\t/* Stack pointer adjustment (offset in bytes). */\n  TraceNo1 traceno;\t/* Trace number. */\n  TraceNo1 link;\t/* Linked trace (or self for loops). */\n  TraceNo1 root;\t/* Root trace of side trace (or 0 for root traces). */\n  TraceNo1 nextroot;\t/* Next root trace for same prototype. */\n  TraceNo1 nextside;\t/* Next side trace of same root trace. */\n  uint8_t sinktags;\t/* Trace has SINK tags. */\n  uint8_t unused1;\n#ifdef LUAJIT_USE_GDBJIT\n  void *gdbjit_entry;\t/* GDB JIT entry. */\n#endif\n} GCtrace;\n\n#define gco2trace(o)\tcheck_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o))\n#define traceref(J, n) \\\n  check_exp((n)>0 && (MSize)(n)<J->sizetrace, (GCtrace *)gcref(J->trace[(n)]))\n\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist));\n\nstatic LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)\n{\n  if (snap+1 == &T->snap[T->nsnap])\n    return T->nsnapmap;\n  else\n    return (snap+1)->mapofs;\n}\n\n/* Round-robin penalty cache for bytecodes leading to aborted traces. */\ntypedef struct HotPenalty {\n  MRef pc;\t\t/* Starting bytecode PC. */\n  uint16_t val;\t\t/* Penalty value, i.e. hotcount start. */\n  uint16_t reason;\t/* Abort reason (really TraceErr). */\n} HotPenalty;\n\n#define PENALTY_SLOTS\t64\t/* Penalty cache slot. Must be a power of 2. */\n#define PENALTY_MIN\t(36*2)\t/* Minimum penalty value. */\n#define PENALTY_MAX\t60000\t/* Maximum penalty value. */\n#define PENALTY_RNDBITS\t4\t/* # of random bits to add to penalty value. */\n\n/* Round-robin backpropagation cache for narrowing conversions. */\ntypedef struct BPropEntry {\n  IRRef1 key;\t\t/* Key: original reference. */\n  IRRef1 val;\t\t/* Value: reference after conversion. */\n  IRRef mode;\t\t/* Mode for this entry (currently IRCONV_*). */\n} BPropEntry;\n\n/* Number of slots for the backpropagation cache. Must be a power of 2. */\n#define BPROP_SLOTS\t16\n\n/* Scalar evolution analysis cache. */\ntypedef struct ScEvEntry {\n  MRef pc;\t\t/* Bytecode PC of FORI. */\n  IRRef1 idx;\t\t/* Index reference. */\n  IRRef1 start;\t\t/* Constant start reference. */\n  IRRef1 stop;\t\t/* Constant stop reference. */\n  IRRef1 step;\t\t/* Constant step reference. */\n  IRType1 t;\t\t/* Scalar type. */\n  uint8_t dir;\t\t/* Direction. 1: +, 0: -. */\n} ScEvEntry;\n\n/* Reverse bytecode map (IRRef -> PC). Only for selected instructions. */\ntypedef struct RBCHashEntry {\n  MRef pc;\t\t/* Bytecode PC. */\n  GCRef pt;\t\t/* Prototype. */\n  IRRef ref;\t\t/* IR reference. */\n} RBCHashEntry;\n\n/* Number of slots in the reverse bytecode hash table. Must be a power of 2. */\n#define RBCHASH_SLOTS\t8\n\n/* 128 bit SIMD constants. */\nenum {\n  LJ_KSIMD_ABS,\n  LJ_KSIMD_NEG,\n  LJ_KSIMD__MAX\n};\n\n/* Get 16 byte aligned pointer to SIMD constant. */\n#define LJ_KSIMD(J, n) \\\n  ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))\n\n/* Set/reset flag to activate the SPLIT pass for the current trace. */\n#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)\n#define lj_needsplit(J)\t\t(J->needsplit = 1)\n#define lj_resetsplit(J)\t(J->needsplit = 0)\n#else\n#define lj_needsplit(J)\t\tUNUSED(J)\n#define lj_resetsplit(J)\tUNUSED(J)\n#endif\n\n/* Fold state is used to fold instructions on-the-fly. */\ntypedef struct FoldState {\n  IRIns ins;\t\t/* Currently emitted instruction. */\n  IRIns left;\t\t/* Instruction referenced by left operand. */\n  IRIns right;\t\t/* Instruction referenced by right operand. */\n} FoldState;\n\n/* JIT compiler state. */\ntypedef struct jit_State {\n  GCtrace cur;\t\t/* Current trace. */\n\n  lua_State *L;\t\t/* Current Lua state. */\n  const BCIns *pc;\t/* Current PC. */\n  GCfunc *fn;\t\t/* Current function. */\n  GCproto *pt;\t\t/* Current prototype. */\n  TRef *base;\t\t/* Current frame base, points into J->slots. */\n\n  uint32_t flags;\t/* JIT engine flags. */\n  BCReg maxslot;\t/* Relative to baseslot. */\n  BCReg baseslot;\t/* Current frame base, offset into J->slots. */\n\n  uint8_t mergesnap;\t/* Allowed to merge with next snapshot. */\n  uint8_t needsnap;\t/* Need snapshot before recording next bytecode. */\n  IRType1 guardemit;\t/* Accumulated IRT_GUARD for emitted instructions. */\n  uint8_t bcskip;\t/* Number of bytecode instructions to skip. */\n\n  FoldState fold;\t/* Fold state. */\n\n  const BCIns *bc_min;\t/* Start of allowed bytecode range for root trace. */\n  MSize bc_extent;\t/* Extent of the range. */\n\n  TraceState state;\t/* Trace compiler state. */\n\n  int32_t instunroll;\t/* Unroll counter for instable loops. */\n  int32_t loopunroll;\t/* Unroll counter for loop ops in side traces. */\n  int32_t tailcalled;\t/* Number of successive tailcalls. */\n  int32_t framedepth;\t/* Current frame depth. */\n  int32_t retdepth;\t/* Return frame depth (count of RETF). */\n\n  MRef k64;\t\t/* Pointer to chained array of 64 bit constants. */\n  TValue ksimd[LJ_KSIMD__MAX*2+1];  /* 16 byte aligned SIMD constants. */\n\n  IRIns *irbuf;\t\t/* Temp. IR instruction buffer. Biased with REF_BIAS. */\n  IRRef irtoplim;\t/* Upper limit of instuction buffer (biased). */\n  IRRef irbotlim;\t/* Lower limit of instuction buffer (biased). */\n  IRRef loopref;\t/* Last loop reference or ref of final LOOP (or 0). */\n\n  MSize sizesnap;\t/* Size of temp. snapshot buffer. */\n  SnapShot *snapbuf;\t/* Temp. snapshot buffer. */\n  SnapEntry *snapmapbuf;  /* Temp. snapshot map buffer. */\n  MSize sizesnapmap;\t/* Size of temp. snapshot map buffer. */\n\n  PostProc postproc;\t/* Required post-processing after execution. */\n#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)\n  uint8_t needsplit;\t/* Need SPLIT pass. */\n#endif\n  uint8_t retryrec;\t/* Retry recording. */\n\n  GCRef *trace;\t\t/* Array of traces. */\n  TraceNo freetrace;\t/* Start of scan for next free trace. */\n  MSize sizetrace;\t/* Size of trace array. */\n  TValue *ktracep;\t/* Pointer to K64Array slot with GCtrace pointer. */\n\n  IRRef1 chain[IR__MAX];  /* IR instruction skip-list chain anchors. */\n  TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA];  /* Stack slot map. */\n\n  int32_t param[JIT_P__MAX];  /* JIT engine parameters. */\n\n  MCode *exitstubgroup[LJ_MAX_EXITSTUBGR];  /* Exit stub group addresses. */\n\n  HotPenalty penalty[PENALTY_SLOTS];  /* Penalty slots. */\n  uint32_t penaltyslot;\t/* Round-robin index into penalty slots. */\n  uint32_t prngstate;\t/* PRNG state. */\n\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  RBCHashEntry rbchash[RBCHASH_SLOTS];  /* Reverse bytecode map. */\n#endif\n\n  BPropEntry bpropcache[BPROP_SLOTS];  /* Backpropagation cache slots. */\n  uint32_t bpropslot;\t/* Round-robin index into bpropcache slots. */\n\n  ScEvEntry scev;\t/* Scalar evolution analysis cache slots. */\n\n  const BCIns *startpc;\t/* Bytecode PC of starting instruction. */\n  TraceNo parent;\t/* Parent of current side trace (0 for root traces). */\n  ExitNo exitno;\t/* Exit number in parent of current side trace. */\n\n  BCIns *patchpc;\t/* PC for pending re-patch. */\n  BCIns patchins;\t/* Instruction for pending re-patch. */\n\n  int mcprot;\t\t/* Protection of current mcode area. */\n  MCode *mcarea;\t/* Base of current mcode area. */\n  MCode *mctop;\t\t/* Top of current mcode area. */\n  MCode *mcbot;\t\t/* Bottom of current mcode area. */\n  size_t szmcarea;\t/* Size of current mcode area. */\n  size_t szallmcarea;\t/* Total size of all allocated mcode areas. */\n\n  TValue errinfo;\t/* Additional info element for trace errors. */\n\n#if LJ_HASPROFILE\n  GCproto *prev_pt;\t/* Previous prototype. */\n  BCLine prev_line;\t/* Previous line. */\n  int prof_mode;\t/* Profiling mode: 0, 'f', 'l'. */\n#endif\n}\n#if LJ_TARGET_ARM\nLJ_ALIGN(16)\t\t/* For DISPATCH-relative addresses in assembler part. */\n#endif\njit_State;\n\n/* Trivial PRNG e.g. used for penalty randomization. */\nstatic LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)\n{\n  /* Yes, this LCG is very weak, but that doesn't matter for our use case. */\n  J->prngstate = J->prngstate * 1103515245 + 12345;\n  return J->prngstate >> (32-bits);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_lex.c",
    "content": "/*\n** Lexical analyzer.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_lex_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#if LJ_HASFFI\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lualib.h\"\n#endif\n#include \"lj_state.h\"\n#include \"lj_lex.h\"\n#include \"lj_parse.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* Lua lexer token names. */\nstatic const char *const tokennames[] = {\n#define TKSTR1(name)\t\t#name,\n#define TKSTR2(name, sym)\t#sym,\nTKDEF(TKSTR1, TKSTR2)\n#undef TKSTR1\n#undef TKSTR2\n  NULL\n};\n\n/* -- Buffer handling ----------------------------------------------------- */\n\n#define LEX_EOF\t\t\t(-1)\n#define lex_iseol(ls)\t\t(ls->c == '\\n' || ls->c == '\\r')\n\n/* Get more input from reader. */\nstatic LJ_NOINLINE LexChar lex_more(LexState *ls)\n{\n  size_t sz;\n  const char *p = ls->rfunc(ls->L, ls->rdata, &sz);\n  if (p == NULL || sz == 0) return LEX_EOF;\n  ls->pe = p + sz;\n  ls->p = p + 1;\n  return (LexChar)(uint8_t)p[0];\n}\n\n/* Get next character. */\nstatic LJ_AINLINE LexChar lex_next(LexState *ls)\n{\n  return (ls->c = ls->p < ls->pe ? (LexChar)(uint8_t)*ls->p++ : lex_more(ls));\n}\n\n/* Save character. */\nstatic LJ_AINLINE void lex_save(LexState *ls, LexChar c)\n{\n  lj_buf_putb(&ls->sb, c);\n}\n\n/* Save previous character and get next character. */\nstatic LJ_AINLINE LexChar lex_savenext(LexState *ls)\n{\n  lex_save(ls, ls->c);\n  return lex_next(ls);\n}\n\n/* Skip line break. Handles \"\\n\", \"\\r\", \"\\r\\n\" or \"\\n\\r\". */\nstatic void lex_newline(LexState *ls)\n{\n  LexChar old = ls->c;\n  lua_assert(lex_iseol(ls));\n  lex_next(ls);  /* Skip \"\\n\" or \"\\r\". */\n  if (lex_iseol(ls) && ls->c != old) lex_next(ls);  /* Skip \"\\n\\r\" or \"\\r\\n\". */\n  if (++ls->linenumber >= LJ_MAX_LINE)\n    lj_lex_error(ls, ls->tok, LJ_ERR_XLINES);\n}\n\n/* -- Scanner for terminals ----------------------------------------------- */\n\n/* Parse a number literal. */\nstatic void lex_number(LexState *ls, TValue *tv)\n{\n  StrScanFmt fmt;\n  LexChar c, xp = 'e';\n  lua_assert(lj_char_isdigit(ls->c));\n  if ((c = ls->c) == '0' && (lex_savenext(ls) | 0x20) == 'x')\n    xp = 'p';\n  while (lj_char_isident(ls->c) || ls->c == '.' ||\n\t ((ls->c == '-' || ls->c == '+') && (c | 0x20) == xp)) {\n    c = ls->c;\n    lex_savenext(ls);\n  }\n  lex_save(ls, '\\0');\n  fmt = lj_strscan_scan((const uint8_t *)sbufB(&ls->sb), tv,\n\t  (LJ_DUALNUM ? STRSCAN_OPT_TOINT : STRSCAN_OPT_TONUM) |\n\t  (LJ_HASFFI ? (STRSCAN_OPT_LL|STRSCAN_OPT_IMAG) : 0));\n  if (LJ_DUALNUM && fmt == STRSCAN_INT) {\n    setitype(tv, LJ_TISNUM);\n  } else if (fmt == STRSCAN_NUM) {\n    /* Already in correct format. */\n#if LJ_HASFFI\n  } else if (fmt != STRSCAN_ERROR) {\n    lua_State *L = ls->L;\n    GCcdata *cd;\n    lua_assert(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG);\n    if (!ctype_ctsG(G(L))) {\n      ptrdiff_t oldtop = savestack(L, L->top);\n      luaopen_ffi(L);  /* Load FFI library on-demand. */\n      L->top = restorestack(L, oldtop);\n    }\n    if (fmt == STRSCAN_IMAG) {\n      cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double));\n      ((double *)cdataptr(cd))[0] = 0;\n      ((double *)cdataptr(cd))[1] = numV(tv);\n    } else {\n      cd = lj_cdata_new_(L, fmt==STRSCAN_I64 ? CTID_INT64 : CTID_UINT64, 8);\n      *(uint64_t *)cdataptr(cd) = tv->u64;\n    }\n    lj_parse_keepcdata(ls, tv, cd);\n#endif\n  } else {\n    lua_assert(fmt == STRSCAN_ERROR);\n    lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER);\n  }\n}\n\n/* Skip equal signs for \"[=...=[\" and \"]=...=]\" and return their count. */\nstatic int lex_skipeq(LexState *ls)\n{\n  int count = 0;\n  LexChar s = ls->c;\n  lua_assert(s == '[' || s == ']');\n  while (lex_savenext(ls) == '=')\n    count++;\n  return (ls->c == s) ? count : (-count) - 1;\n}\n\n/* Parse a long string or long comment (tv set to NULL). */\nstatic void lex_longstring(LexState *ls, TValue *tv, int sep)\n{\n  lex_savenext(ls);  /* Skip second '['. */\n  if (lex_iseol(ls))  /* Skip initial newline. */\n    lex_newline(ls);\n  for (;;) {\n    switch (ls->c) {\n    case LEX_EOF:\n      lj_lex_error(ls, TK_eof, tv ? LJ_ERR_XLSTR : LJ_ERR_XLCOM);\n      break;\n    case ']':\n      if (lex_skipeq(ls) == sep) {\n\tlex_savenext(ls);  /* Skip second ']'. */\n\tgoto endloop;\n      }\n      break;\n    case '\\n':\n    case '\\r':\n      lex_save(ls, '\\n');\n      lex_newline(ls);\n      if (!tv) lj_buf_reset(&ls->sb);  /* Don't waste space for comments. */\n      break;\n    default:\n      lex_savenext(ls);\n      break;\n    }\n  } endloop:\n  if (tv) {\n    GCstr *str = lj_parse_keepstr(ls, sbufB(&ls->sb) + (2 + (MSize)sep),\n\t\t\t\t      sbuflen(&ls->sb) - 2*(2 + (MSize)sep));\n    setstrV(ls->L, tv, str);\n  }\n}\n\n/* Parse a string. */\nstatic void lex_string(LexState *ls, TValue *tv)\n{\n  LexChar delim = ls->c;  /* Delimiter is '\\'' or '\"'. */\n  lex_savenext(ls);\n  while (ls->c != delim) {\n    switch (ls->c) {\n    case LEX_EOF:\n      lj_lex_error(ls, TK_eof, LJ_ERR_XSTR);\n      continue;\n    case '\\n':\n    case '\\r':\n      lj_lex_error(ls, TK_string, LJ_ERR_XSTR);\n      continue;\n    case '\\\\': {\n      LexChar c = lex_next(ls);  /* Skip the '\\\\'. */\n      switch (c) {\n      case 'a': c = '\\a'; break;\n      case 'b': c = '\\b'; break;\n      case 'f': c = '\\f'; break;\n      case 'n': c = '\\n'; break;\n      case 'r': c = '\\r'; break;\n      case 't': c = '\\t'; break;\n      case 'v': c = '\\v'; break;\n      case 'x':  /* Hexadecimal escape '\\xXX'. */\n\tc = (lex_next(ls) & 15u) << 4;\n\tif (!lj_char_isdigit(ls->c)) {\n\t  if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t  c += 9 << 4;\n\t}\n\tc += (lex_next(ls) & 15u);\n\tif (!lj_char_isdigit(ls->c)) {\n\t  if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t  c += 9;\n\t}\n\tbreak;\n      case 'u':  /* Unicode escape '\\u{XX...}'. */\n\tif (lex_next(ls) != '{') goto err_xesc;\n\tlex_next(ls);\n\tc = 0;\n\tdo {\n\t  c = (c << 4) | (ls->c & 15u);\n\t  if (!lj_char_isdigit(ls->c)) {\n\t    if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t    c += 9;\n\t  }\n\t  if (c >= 0x110000) goto err_xesc;  /* Out of Unicode range. */\n\t} while (lex_next(ls) != '}');\n\tif (c < 0x800) {\n\t  if (c < 0x80) break;\n\t  lex_save(ls, 0xc0 | (c >> 6));\n\t} else {\n\t  if (c >= 0x10000) {\n\t    lex_save(ls, 0xf0 | (c >> 18));\n\t    lex_save(ls, 0x80 | ((c >> 12) & 0x3f));\n\t  } else {\n\t    if (c >= 0xd800 && c < 0xe000) goto err_xesc;  /* No surrogates. */\n\t    lex_save(ls, 0xe0 | (c >> 12));\n\t  }\n\t  lex_save(ls, 0x80 | ((c >> 6) & 0x3f));\n\t}\n\tc = 0x80 | (c & 0x3f);\n\tbreak;\n      case 'z':  /* Skip whitespace. */\n\tlex_next(ls);\n\twhile (lj_char_isspace(ls->c))\n\t  if (lex_iseol(ls)) lex_newline(ls); else lex_next(ls);\n\tcontinue;\n      case '\\n': case '\\r': lex_save(ls, '\\n'); lex_newline(ls); continue;\n      case '\\\\': case '\\\"': case '\\'': break;\n      case LEX_EOF: continue;\n      default:\n\tif (!lj_char_isdigit(c))\n\t  goto err_xesc;\n\tc -= '0';  /* Decimal escape '\\ddd'. */\n\tif (lj_char_isdigit(lex_next(ls))) {\n\t  c = c*10 + (ls->c - '0');\n\t  if (lj_char_isdigit(lex_next(ls))) {\n\t    c = c*10 + (ls->c - '0');\n\t    if (c > 255) {\n\t    err_xesc:\n\t      lj_lex_error(ls, TK_string, LJ_ERR_XESC);\n\t    }\n\t    lex_next(ls);\n\t  }\n\t}\n\tlex_save(ls, c);\n\tcontinue;\n      }\n      lex_save(ls, c);\n      lex_next(ls);\n      continue;\n      }\n    default:\n      lex_savenext(ls);\n      break;\n    }\n  }\n  lex_savenext(ls);  /* Skip trailing delimiter. */\n  setstrV(ls->L, tv,\n\t  lj_parse_keepstr(ls, sbufB(&ls->sb)+1, sbuflen(&ls->sb)-2));\n}\n\n/* -- Main lexical scanner ------------------------------------------------ */\n\n/* Get next lexical token. */\nstatic LexToken lex_scan(LexState *ls, TValue *tv)\n{\n  lj_buf_reset(&ls->sb);\n  for (;;) {\n    if (lj_char_isident(ls->c)) {\n      GCstr *s;\n      if (lj_char_isdigit(ls->c)) {  /* Numeric literal. */\n\tlex_number(ls, tv);\n\treturn TK_number;\n      }\n      /* Identifier or reserved word. */\n      do {\n\tlex_savenext(ls);\n      } while (lj_char_isident(ls->c));\n      s = lj_parse_keepstr(ls, sbufB(&ls->sb), sbuflen(&ls->sb));\n      setstrV(ls->L, tv, s);\n      if (s->reserved > 0)  /* Reserved word? */\n\treturn TK_OFS + s->reserved;\n      return TK_name;\n    }\n    switch (ls->c) {\n    case '\\n':\n    case '\\r':\n      lex_newline(ls);\n      continue;\n    case ' ':\n    case '\\t':\n    case '\\v':\n    case '\\f':\n      lex_next(ls);\n      continue;\n    case '-':\n      lex_next(ls);\n      if (ls->c != '-') return '-';\n      lex_next(ls);\n      if (ls->c == '[') {  /* Long comment \"--[=*[...]=*]\". */\n\tint sep = lex_skipeq(ls);\n\tlj_buf_reset(&ls->sb);  /* `lex_skipeq' may dirty the buffer */\n\tif (sep >= 0) {\n\t  lex_longstring(ls, NULL, sep);\n\t  lj_buf_reset(&ls->sb);\n\t  continue;\n\t}\n      }\n      /* Short comment \"--.*\\n\". */\n      while (!lex_iseol(ls) && ls->c != LEX_EOF)\n\tlex_next(ls);\n      continue;\n    case '[': {\n      int sep = lex_skipeq(ls);\n      if (sep >= 0) {\n\tlex_longstring(ls, tv, sep);\n\treturn TK_string;\n      } else if (sep == -1) {\n\treturn '[';\n      } else {\n\tlj_lex_error(ls, TK_string, LJ_ERR_XLDELIM);\n\tcontinue;\n      }\n      }\n    case '=':\n      lex_next(ls);\n      if (ls->c != '=') return '='; else { lex_next(ls); return TK_eq; }\n    case '<':\n      lex_next(ls);\n      if (ls->c != '=') return '<'; else { lex_next(ls); return TK_le; }\n    case '>':\n      lex_next(ls);\n      if (ls->c != '=') return '>'; else { lex_next(ls); return TK_ge; }\n    case '~':\n      lex_next(ls);\n      if (ls->c != '=') return '~'; else { lex_next(ls); return TK_ne; }\n    case ':':\n      lex_next(ls);\n      if (ls->c != ':') return ':'; else { lex_next(ls); return TK_label; }\n    case '\"':\n    case '\\'':\n      lex_string(ls, tv);\n      return TK_string;\n    case '.':\n      if (lex_savenext(ls) == '.') {\n\tlex_next(ls);\n\tif (ls->c == '.') {\n\t  lex_next(ls);\n\t  return TK_dots;   /* ... */\n\t}\n\treturn TK_concat;   /* .. */\n      } else if (!lj_char_isdigit(ls->c)) {\n\treturn '.';\n      } else {\n\tlex_number(ls, tv);\n\treturn TK_number;\n      }\n    case LEX_EOF:\n      return TK_eof;\n    default: {\n      LexChar c = ls->c;\n      lex_next(ls);\n      return c;  /* Single-char tokens (+ - / ...). */\n    }\n    }\n  }\n}\n\n/* -- Lexer API ----------------------------------------------------------- */\n\n/* Setup lexer state. */\nint lj_lex_setup(lua_State *L, LexState *ls)\n{\n  int header = 0;\n  ls->L = L;\n  ls->fs = NULL;\n  ls->pe = ls->p = NULL;\n  ls->vstack = NULL;\n  ls->sizevstack = 0;\n  ls->vtop = 0;\n  ls->bcstack = NULL;\n  ls->sizebcstack = 0;\n  ls->tok = 0;\n  ls->lookahead = TK_eof;  /* No look-ahead token. */\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  lex_next(ls);  /* Read-ahead first char. */\n  if (ls->c == 0xef && ls->p + 2 <= ls->pe && (uint8_t)ls->p[0] == 0xbb &&\n      (uint8_t)ls->p[1] == 0xbf) {  /* Skip UTF-8 BOM (if buffered). */\n    ls->p += 2;\n    lex_next(ls);\n    header = 1;\n  }\n  if (ls->c == '#') {  /* Skip POSIX #! header line. */\n    do {\n      lex_next(ls);\n      if (ls->c == LEX_EOF) return 0;\n    } while (!lex_iseol(ls));\n    lex_newline(ls);\n    header = 1;\n  }\n  if (ls->c == LUA_SIGNATURE[0]) {  /* Bytecode dump. */\n    if (header) {\n      /*\n      ** Loading bytecode with an extra header is disabled for security\n      ** reasons. This may circumvent the usual check for bytecode vs.\n      ** Lua code by looking at the first char. Since this is a potential\n      ** security violation no attempt is made to echo the chunkname either.\n      */\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD));\n      lj_err_throw(L, LUA_ERRSYNTAX);\n    }\n    return 1;\n  }\n  return 0;\n}\n\n/* Cleanup lexer state. */\nvoid lj_lex_cleanup(lua_State *L, LexState *ls)\n{\n  global_State *g = G(L);\n  lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine);\n  lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo);\n  lj_buf_free(g, &ls->sb);\n}\n\n/* Return next lexical token. */\nvoid lj_lex_next(LexState *ls)\n{\n  ls->lastline = ls->linenumber;\n  if (LJ_LIKELY(ls->lookahead == TK_eof)) {  /* No lookahead token? */\n    ls->tok = lex_scan(ls, &ls->tokval);  /* Get next token. */\n  } else {  /* Otherwise return lookahead token. */\n    ls->tok = ls->lookahead;\n    ls->lookahead = TK_eof;\n    ls->tokval = ls->lookaheadval;\n  }\n}\n\n/* Look ahead for the next token. */\nLexToken lj_lex_lookahead(LexState *ls)\n{\n  lua_assert(ls->lookahead == TK_eof);\n  ls->lookahead = lex_scan(ls, &ls->lookaheadval);\n  return ls->lookahead;\n}\n\n/* Convert token to string. */\nconst char *lj_lex_token2str(LexState *ls, LexToken tok)\n{\n  if (tok > TK_OFS)\n    return tokennames[tok-TK_OFS-1];\n  else if (!lj_char_iscntrl(tok))\n    return lj_strfmt_pushf(ls->L, \"%c\", tok);\n  else\n    return lj_strfmt_pushf(ls->L, \"char(%d)\", tok);\n}\n\n/* Lexer error. */\nvoid lj_lex_error(LexState *ls, LexToken tok, ErrMsg em, ...)\n{\n  const char *tokstr;\n  va_list argp;\n  if (tok == 0) {\n    tokstr = NULL;\n  } else if (tok == TK_name || tok == TK_string || tok == TK_number) {\n    lex_save(ls, '\\0');\n    tokstr = sbufB(&ls->sb);\n  } else {\n    tokstr = lj_lex_token2str(ls, tok);\n  }\n  va_start(argp, em);\n  lj_err_lex(ls->L, ls->chunkname, tokstr, ls->linenumber, em, argp);\n  va_end(argp);\n}\n\n/* Initialize strings for reserved words. */\nvoid lj_lex_init(lua_State *L)\n{\n  uint32_t i;\n  for (i = 0; i < TK_RESERVED; i++) {\n    GCstr *s = lj_str_newz(L, tokennames[i]);\n    fixstring(s);  /* Reserved words are never collected. */\n    s->reserved = (uint8_t)(i+1);\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_lex.h",
    "content": "/*\n** Lexical analyzer.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_LEX_H\n#define _LJ_LEX_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n\n/* Lua lexer tokens. */\n#define TKDEF(_, __) \\\n  _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \\\n  _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \\\n  _(repeat) _(return) _(then) _(true) _(until) _(while) \\\n  __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \\\n  __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \\\n  __(eof, <eof>)\n\nenum {\n  TK_OFS = 256,\n#define TKENUM1(name)\t\tTK_##name,\n#define TKENUM2(name, sym)\tTK_##name,\nTKDEF(TKENUM1, TKENUM2)\n#undef TKENUM1\n#undef TKENUM2\n  TK_RESERVED = TK_while - TK_OFS\n};\n\ntypedef int LexChar;\t/* Lexical character. Unsigned ext. from char. */\ntypedef int LexToken;\t/* Lexical token. */\n\n/* Combined bytecode ins/line. Only used during bytecode generation. */\ntypedef struct BCInsLine {\n  BCIns ins;\t\t/* Bytecode instruction. */\n  BCLine line;\t\t/* Line number for this bytecode. */\n} BCInsLine;\n\n/* Info for local variables. Only used during bytecode generation. */\ntypedef struct VarInfo {\n  GCRef name;\t\t/* Local variable name or goto/label name. */\n  BCPos startpc;\t/* First point where the local variable is active. */\n  BCPos endpc;\t\t/* First point where the local variable is dead. */\n  uint8_t slot;\t\t/* Variable slot. */\n  uint8_t info;\t\t/* Variable/goto/label info. */\n} VarInfo;\n\n/* Lua lexer state. */\ntypedef struct LexState {\n  struct FuncState *fs;\t/* Current FuncState. Defined in lj_parse.c. */\n  struct lua_State *L;\t/* Lua state. */\n  TValue tokval;\t/* Current token value. */\n  TValue lookaheadval;\t/* Lookahead token value. */\n  const char *p;\t/* Current position in input buffer. */\n  const char *pe;\t/* End of input buffer. */\n  LexChar c;\t\t/* Current character. */\n  LexToken tok;\t\t/* Current token. */\n  LexToken lookahead;\t/* Lookahead token. */\n  SBuf sb;\t\t/* String buffer for tokens. */\n  lua_Reader rfunc;\t/* Reader callback. */\n  void *rdata;\t\t/* Reader callback data. */\n  BCLine linenumber;\t/* Input line counter. */\n  BCLine lastline;\t/* Line of last token. */\n  GCstr *chunkname;\t/* Current chunk name (interned string). */\n  const char *chunkarg;\t/* Chunk name argument. */\n  const char *mode;\t/* Allow loading bytecode (b) and/or source text (t). */\n  VarInfo *vstack;\t/* Stack for names and extents of local variables. */\n  MSize sizevstack;\t/* Size of variable stack. */\n  MSize vtop;\t\t/* Top of variable stack. */\n  BCInsLine *bcstack;\t/* Stack for bytecode instructions/line numbers. */\n  MSize sizebcstack;\t/* Size of bytecode stack. */\n  uint32_t level;\t/* Syntactical nesting level. */\n} LexState;\n\nLJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);\nLJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);\nLJ_FUNC void lj_lex_next(LexState *ls);\nLJ_FUNC LexToken lj_lex_lookahead(LexState *ls);\nLJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken tok);\nLJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken tok, ErrMsg em, ...);\nLJ_FUNC void lj_lex_init(lua_State *L);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_lib.c",
    "content": "/*\n** Library function support.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_lib_c\n#define LUA_CORE\n\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_bc.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_lib.h\"\n\n/* -- Library initialization ---------------------------------------------- */\n\nstatic GCtab *lib_create_table(lua_State *L, const char *libname, int hsize)\n{\n  if (libname) {\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n    lua_getfield(L, -1, libname);\n    if (!tvistab(L->top-1)) {\n      L->top--;\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, hsize) != NULL)\n\tlj_err_callerv(L, LJ_ERR_BADMODN, libname);\n      settabV(L, L->top, tabV(L->top-1));\n      L->top++;\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    L->top--;\n    settabV(L, L->top-1, tabV(L->top));\n  } else {\n    lua_createtable(L, 0, hsize);\n  }\n  return tabV(L->top-1);\n}\n\nstatic const uint8_t *lib_read_lfunc(lua_State *L, const uint8_t *p, GCtab *tab)\n{\n  int len = *p++;\n  GCstr *name = lj_str_new(L, (const char *)p, len);\n  LexState ls;\n  GCproto *pt;\n  GCfunc *fn;\n  memset(&ls, 0, sizeof(ls));\n  ls.L = L;\n  ls.p = (const char *)(p+len);\n  ls.pe = (const char *)~(uintptr_t)0;\n  ls.c = -1;\n  ls.level = (BCDUMP_F_STRIP|(LJ_BE*BCDUMP_F_BE));\n  ls.chunkname = name;\n  pt = lj_bcread_proto(&ls);\n  pt->firstline = ~(BCLine)0;\n  fn = lj_func_newL_empty(L, pt, tabref(L->env));\n  /* NOBARRIER: See below for common barrier. */\n  setfuncV(L, lj_tab_setstr(L, tab, name), fn);\n  return (const uint8_t *)ls.p;\n}\n\nvoid lj_lib_register(lua_State *L, const char *libname,\n\t\t     const uint8_t *p, const lua_CFunction *cf)\n{\n  GCtab *env = tabref(L->env);\n  GCfunc *ofn = NULL;\n  int ffid = *p++;\n  BCIns *bcff = &L2GG(L)->bcff[*p++];\n  GCtab *tab = lib_create_table(L, libname, *p++);\n  ptrdiff_t tpos = L->top - L->base;\n\n  /* Avoid barriers further down. */\n  lj_gc_anybarriert(L, tab);\n  tab->nomm = 0;\n\n  for (;;) {\n    uint32_t tag = *p++;\n    MSize len = tag & LIBINIT_LENMASK;\n    tag &= LIBINIT_TAGMASK;\n    if (tag != LIBINIT_STRING) {\n      const char *name;\n      MSize nuv = (MSize)(L->top - L->base - tpos);\n      GCfunc *fn = lj_func_newC(L, nuv, env);\n      if (nuv) {\n\tL->top = L->base + tpos;\n\tmemcpy(fn->c.upvalue, L->top, sizeof(TValue)*nuv);\n      }\n      fn->c.ffid = (uint8_t)(ffid++);\n      name = (const char *)p;\n      p += len;\n      if (tag == LIBINIT_CF)\n\tsetmref(fn->c.pc, &G(L)->bc_cfunc_int);\n      else\n\tsetmref(fn->c.pc, bcff++);\n      if (tag == LIBINIT_ASM_)\n\tfn->c.f = ofn->c.f;  /* Copy handler from previous function. */\n      else\n\tfn->c.f = *cf++;  /* Get cf or handler from C function table. */\n      if (len) {\n\t/* NOBARRIER: See above for common barrier. */\n\tsetfuncV(L, lj_tab_setstr(L, tab, lj_str_new(L, name, len)), fn);\n      }\n      ofn = fn;\n    } else {\n      switch (tag | len) {\n      case LIBINIT_LUA:\n\tp = lib_read_lfunc(L, p, tab);\n\tbreak;\n      case LIBINIT_SET:\n\tL->top -= 2;\n\tif (tvisstr(L->top+1) && strV(L->top+1)->len == 0)\n\t  env = tabV(L->top);\n\telse  /* NOBARRIER: See above for common barrier. */\n\t  copyTV(L, lj_tab_set(L, tab, L->top+1), L->top);\n\tbreak;\n      case LIBINIT_NUMBER:\n\tmemcpy(&L->top->n, p, sizeof(double));\n\tL->top++;\n\tp += sizeof(double);\n\tbreak;\n      case LIBINIT_COPY:\n\tcopyTV(L, L->top, L->top - *p++);\n\tL->top++;\n\tbreak;\n      case LIBINIT_LASTCL:\n\tsetfuncV(L, L->top++, ofn);\n\tbreak;\n      case LIBINIT_FFID:\n\tffid++;\n\tbreak;\n      case LIBINIT_END:\n\treturn;\n      default:\n\tsetstrV(L, L->top++, lj_str_new(L, (const char *)p, len));\n\tp += len;\n\tbreak;\n      }\n    }\n  }\n}\n\n/* Push internal function on the stack. */\nGCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n)\n{\n  GCfunc *fn;\n  lua_pushcclosure(L, f, n);\n  fn = funcV(L->top-1);\n  fn->c.ffid = (uint8_t)id;\n  setmref(fn->c.pc, &G(L)->bc_cfunc_int);\n  return fn;\n}\n\nvoid lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env)\n{\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\", 4);\n  lua_pushcfunction(L, f);\n  /* NOBARRIER: The function is new (marked white). */\n  setgcref(funcV(L->top-1)->c.env, obj2gco(env));\n  lua_setfield(L, -2, name);\n  L->top--;\n}\n\nint lj_lib_postreg(lua_State *L, lua_CFunction cf, int id, const char *name)\n{\n  GCfunc *fn = lj_lib_pushcf(L, cf, id);\n  GCtab *t = tabref(curr_func(L)->c.env);  /* Reference to parent table. */\n  setfuncV(L, lj_tab_setstr(L, t, lj_str_newz(L, name)), fn);\n  lj_gc_anybarriert(L, t);\n  setfuncV(L, L->top++, fn);\n  return 1;\n}\n\n/* -- Type checks --------------------------------------------------------- */\n\nTValue *lj_lib_checkany(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  return o;\n}\n\nGCstr *lj_lib_checkstr(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o < L->top) {\n    if (LJ_LIKELY(tvisstr(o))) {\n      return strV(o);\n    } else if (tvisnumber(o)) {\n      GCstr *s = lj_strfmt_number(L, o);\n      setstrV(L, o, s);\n      return s;\n    }\n  }\n  lj_err_argt(L, narg, LUA_TSTRING);\n  return NULL;  /* unreachable */\n}\n\nGCstr *lj_lib_optstr(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL;\n}\n\n#if LJ_DUALNUM\nvoid lj_lib_checknumber(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n}\n#endif\n\nlua_Number lj_lib_checknum(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top &&\n\t(tvisnumber(o) || (tvisstr(o) && lj_strscan_num(strV(o), o)))))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_UNLIKELY(tvisint(o))) {\n    lua_Number n = (lua_Number)intV(o);\n    setnumV(o, n);\n    return n;\n  } else {\n    return numV(o);\n  }\n}\n\nint32_t lj_lib_checkint(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else {\n    int32_t i = lj_num2int(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return i;\n  }\n}\n\nint32_t lj_lib_optint(lua_State *L, int narg, int32_t def)\n{\n  TValue *o = L->base + narg-1;\n  return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def;\n}\n\nGCfunc *lj_lib_checkfunc(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tvisfunc(o)))\n    lj_err_argt(L, narg, LUA_TFUNCTION);\n  return funcV(o);\n}\n\nGCtab *lj_lib_checktab(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tvistab(o)))\n    lj_err_argt(L, narg, LUA_TTABLE);\n  return tabV(o);\n}\n\nGCtab *lj_lib_checktabornil(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o < L->top) {\n    if (tvistab(o))\n      return tabV(o);\n    else if (tvisnil(o))\n      return NULL;\n  }\n  lj_err_arg(L, narg, LJ_ERR_NOTABN);\n  return NULL;  /* unreachable */\n}\n\nint lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst)\n{\n  GCstr *s = def >= 0 ? lj_lib_optstr(L, narg) : lj_lib_checkstr(L, narg);\n  if (s) {\n    const char *opt = strdata(s);\n    MSize len = s->len;\n    int i;\n    for (i = 0; *(const uint8_t *)lst; i++) {\n      if (*(const uint8_t *)lst == len && memcmp(opt, lst+1, len) == 0)\n\treturn i;\n      lst += 1+*(const uint8_t *)lst;\n    }\n    lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt);\n  }\n  return def;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_lib.h",
    "content": "/*\n** Library function support.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_LIB_H\n#define _LJ_LIB_H\n\n#include \"lj_obj.h\"\n\n/*\n** A fallback handler is called by the assembler VM if the fast path fails:\n**\n** - too few arguments:   unrecoverable.\n** - wrong argument type:   recoverable, if coercion succeeds.\n** - bad argument value:  unrecoverable.\n** - stack overflow:        recoverable, if stack reallocation succeeds.\n** - extra handling:        recoverable.\n**\n** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(),\n** lj_err_caller() or lj_err_callermsg().\n** The recoverable cases return 0 or the number of results + 1.\n** The assembler VM retries the fast path only if 0 is returned.\n** This time the fallback must not be called again or it gets stuck in a loop.\n*/\n\n/* Return values from fallback handler. */\n#define FFH_RETRY\t0\n#define FFH_UNREACHABLE\tFFH_RETRY\n#define FFH_RES(n)\t((n)+1)\n#define FFH_TAILCALL\t(-1)\n\nLJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg);\nLJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg);\nLJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg);\n#if LJ_DUALNUM\nLJ_FUNC void lj_lib_checknumber(lua_State *L, int narg);\n#else\n#define lj_lib_checknumber(L, narg)\tlj_lib_checknum((L), (narg))\n#endif\nLJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg);\nLJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg);\nLJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def);\nLJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg);\nLJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg);\nLJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg);\nLJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);\n\n/* Avoid including lj_frame.h. */\n#if LJ_GC64\n#define lj_lib_upvalue(L, n) \\\n  (&gcval(L->base-2)->fn.c.upvalue[(n)-1])\n#elif LJ_FR2\n#define lj_lib_upvalue(L, n) \\\n  (&gcref((L->base-2)->gcr)->fn.c.upvalue[(n)-1])\n#else\n#define lj_lib_upvalue(L, n) \\\n  (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])\n#endif\n\n#if LJ_TARGET_WINDOWS\n#define lj_lib_checkfpu(L) \\\n  do { setnumV(L->top++, (lua_Number)1437217655); \\\n    if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \\\n    L->top--; } while (0)\n#else\n#define lj_lib_checkfpu(L)\tUNUSED(L)\n#endif\n\nLJ_FUNC GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n);\n#define lj_lib_pushcf(L, fn, id)\t(lj_lib_pushcc(L, (fn), (id), 0))\n\n/* Library function declarations. Scanned by buildvm. */\n#define LJLIB_CF(name)\t\tstatic int lj_cf_##name(lua_State *L)\n#define LJLIB_ASM(name)\t\tstatic int lj_ffh_##name(lua_State *L)\n#define LJLIB_ASM_(name)\n#define LJLIB_LUA(name)\n#define LJLIB_SET(name)\n#define LJLIB_PUSH(arg)\n#define LJLIB_REC(handler)\n#define LJLIB_NOREGUV\n#define LJLIB_NOREG\n\n#define LJ_LIB_REG(L, regname, name) \\\n  lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name)\n\nLJ_FUNC void lj_lib_register(lua_State *L, const char *libname,\n\t\t\t     const uint8_t *init, const lua_CFunction *cf);\nLJ_FUNC void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f,\n\t\t\t   GCtab *env);\nLJ_FUNC int lj_lib_postreg(lua_State *L, lua_CFunction cf, int id,\n\t\t\t   const char *name);\n\n/* Library init data tags. */\n#define LIBINIT_LENMASK\t0x3f\n#define LIBINIT_TAGMASK\t0xc0\n#define LIBINIT_CF\t0x00\n#define LIBINIT_ASM\t0x40\n#define LIBINIT_ASM_\t0x80\n#define LIBINIT_STRING\t0xc0\n#define LIBINIT_MAXSTR\t0x38\n#define LIBINIT_LUA\t0xf9\n#define LIBINIT_SET\t0xfa\n#define LIBINIT_NUMBER\t0xfb\n#define LIBINIT_COPY\t0xfc\n#define LIBINIT_LASTCL\t0xfd\n#define LIBINIT_FFID\t0xfe\n#define LIBINIT_END\t0xff\n\n/* Exported library functions. */\n\ntypedef struct RandomState RandomState;\nLJ_FUNC uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_load.c",
    "content": "/*\n** Load and dump code.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n\n#define lj_load_c\n#define LUA_CORE\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_func.h\"\n#include \"lj_frame.h\"\n#include \"lj_vm.h\"\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_parse.h\"\n\n/* -- Load Lua source code and bytecode ----------------------------------- */\n\nstatic TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  LexState *ls = (LexState *)ud;\n  GCproto *pt;\n  GCfunc *fn;\n  int bc;\n  UNUSED(dummy);\n  cframe_errfunc(L->cframe) = -1;  /* Inherit error function. */\n  bc = lj_lex_setup(L, ls);\n  if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) {\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE));\n    lj_err_throw(L, LUA_ERRSYNTAX);\n  }\n  pt = bc ? lj_bcread(ls) : lj_parse(ls);\n  fn = lj_func_newL_empty(L, pt, tabref(L->env));\n  /* Don't combine above/below into one statement. */\n  setfuncV(L, L->top++, fn);\n  return NULL;\n}\n\nLUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data,\n\t\t      const char *chunkname, const char *mode)\n{\n  LexState ls;\n  int status;\n  ls.rfunc = reader;\n  ls.rdata = data;\n  ls.chunkarg = chunkname ? chunkname : \"?\";\n  ls.mode = mode;\n  lj_buf_init(L, &ls.sb);\n  status = lj_vm_cpcall(L, NULL, &ls, cpparser);\n  lj_lex_cleanup(L, &ls);\n  lj_gc_check(L);\n  return status;\n}\n\nLUA_API int lua_load(lua_State *L, lua_Reader reader, void *data,\n\t\t     const char *chunkname)\n{\n  return lua_loadx(L, reader, data, chunkname, NULL);\n}\n\ntypedef struct FileReaderCtx {\n  FILE *fp;\n  char buf[LUAL_BUFFERSIZE];\n} FileReaderCtx;\n\nstatic const char *reader_file(lua_State *L, void *ud, size_t *size)\n{\n  FileReaderCtx *ctx = (FileReaderCtx *)ud;\n  UNUSED(L);\n  if (feof(ctx->fp)) return NULL;\n  *size = fread(ctx->buf, 1, sizeof(ctx->buf), ctx->fp);\n  return *size > 0 ? ctx->buf : NULL;\n}\n\nLUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,\n\t\t\t      const char *mode)\n{\n  FileReaderCtx ctx;\n  int status;\n  const char *chunkname;\n  if (filename) {\n    ctx.fp = fopen(filename, \"rb\");\n    if (ctx.fp == NULL) {\n      lua_pushfstring(L, \"cannot open %s: %s\", filename, strerror(errno));\n      return LUA_ERRFILE;\n    }\n    chunkname = lua_pushfstring(L, \"@%s\", filename);\n  } else {\n    ctx.fp = stdin;\n    chunkname = \"=stdin\";\n  }\n  status = lua_loadx(L, reader_file, &ctx, chunkname, mode);\n  if (ferror(ctx.fp)) {\n    L->top -= filename ? 2 : 1;\n    lua_pushfstring(L, \"cannot read %s: %s\", chunkname+1, strerror(errno));\n    if (filename)\n      fclose(ctx.fp);\n    return LUA_ERRFILE;\n  }\n  if (filename) {\n    L->top--;\n    copyTV(L, L->top-1, L->top);\n    fclose(ctx.fp);\n  }\n  return status;\n}\n\nLUALIB_API int luaL_loadfile(lua_State *L, const char *filename)\n{\n  return luaL_loadfilex(L, filename, NULL);\n}\n\ntypedef struct StringReaderCtx {\n  const char *str;\n  size_t size;\n} StringReaderCtx;\n\nstatic const char *reader_string(lua_State *L, void *ud, size_t *size)\n{\n  StringReaderCtx *ctx = (StringReaderCtx *)ud;\n  UNUSED(L);\n  if (ctx->size == 0) return NULL;\n  *size = ctx->size;\n  ctx->size = 0;\n  return ctx->str;\n}\n\nLUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size,\n\t\t\t\tconst char *name, const char *mode)\n{\n  StringReaderCtx ctx;\n  ctx.str = buf;\n  ctx.size = size;\n  return lua_loadx(L, reader_string, &ctx, name, mode);\n}\n\nLUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size,\n\t\t\t       const char *name)\n{\n  return luaL_loadbufferx(L, buf, size, name, NULL);\n}\n\nLUALIB_API int luaL_loadstring(lua_State *L, const char *s)\n{\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* -- Dump bytecode ------------------------------------------------------- */\n\nLUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)\n{\n  cTValue *o = L->top-1;\n  api_check(L, L->top > L->base);\n  if (tvisfunc(o) && isluafunc(funcV(o)))\n    return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0);\n  else\n    return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_mcode.c",
    "content": "/*\n** Machine code management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_mcode_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#if LJ_HASJIT\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_jit.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#endif\n#if LJ_HASJIT || LJ_HASFFI\n#include \"lj_vm.h\"\n#endif\n\n/* -- OS-specific functions ----------------------------------------------- */\n\n#if LJ_HASJIT || LJ_HASFFI\n\n/* Define this if you want to run LuaJIT with Valgrind. */\n#ifdef LUAJIT_USE_VALGRIND\n#include <valgrind/valgrind.h>\n#endif\n\n#if LJ_TARGET_IOS\nvoid sys_icache_invalidate(void *start, size_t len);\n#endif\n\n/* Synchronize data/instruction cache. */\nvoid lj_mcode_sync(void *start, void *end)\n{\n#ifdef LUAJIT_USE_VALGRIND\n  VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start);\n#endif\n#if LJ_TARGET_X86ORX64\n  UNUSED(start); UNUSED(end);\n#elif LJ_TARGET_IOS\n  sys_icache_invalidate(start, (char *)end-(char *)start);\n#elif LJ_TARGET_PPC\n  lj_vm_cachesync(start, end);\n#elif defined(__GNUC__)\n  __clear_cache(start, end);\n#else\n#error \"Missing builtin to flush instruction cache\"\n#endif\n}\n\n#endif\n\n#if LJ_HASJIT\n\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#define MCPROT_RW\tPAGE_READWRITE\n#define MCPROT_RX\tPAGE_EXECUTE_READ\n#define MCPROT_RWX\tPAGE_EXECUTE_READWRITE\n\nstatic void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, DWORD prot)\n{\n  void *p = VirtualAlloc((void *)hint, sz,\n\t\t\t MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, prot);\n  if (!p && !hint)\n    lj_trace_err(J, LJ_TRERR_MCODEAL);\n  return p;\n}\n\nstatic void mcode_free(jit_State *J, void *p, size_t sz)\n{\n  UNUSED(J); UNUSED(sz);\n  VirtualFree(p, 0, MEM_RELEASE);\n}\n\nstatic int mcode_setprot(void *p, size_t sz, DWORD prot)\n{\n  DWORD oprot;\n  return !VirtualProtect(p, sz, prot, &oprot);\n}\n\n#elif LJ_TARGET_POSIX\n\n#include <sys/mman.h>\n\n#ifndef MAP_ANONYMOUS\n#define MAP_ANONYMOUS\tMAP_ANON\n#endif\n\n#define MCPROT_RW\t(PROT_READ|PROT_WRITE)\n#define MCPROT_RX\t(PROT_READ|PROT_EXEC)\n#define MCPROT_RWX\t(PROT_READ|PROT_WRITE|PROT_EXEC)\n\nstatic void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)\n{\n  void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);\n  if (p == MAP_FAILED) {\n    if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);\n    p = NULL;\n  }\n  return p;\n}\n\nstatic void mcode_free(jit_State *J, void *p, size_t sz)\n{\n  UNUSED(J);\n  munmap(p, sz);\n}\n\nstatic int mcode_setprot(void *p, size_t sz, int prot)\n{\n  return mprotect(p, sz, prot);\n}\n\n#elif LJ_64\n\n#error \"Missing OS support for explicit placement of executable memory\"\n\n#else\n\n/* Fallback allocator. This will fail if memory is not executable by default. */\n#define LUAJIT_UNPROTECT_MCODE\n#define MCPROT_RW\t0\n#define MCPROT_RX\t0\n#define MCPROT_RWX\t0\n\nstatic void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)\n{\n  UNUSED(hint); UNUSED(prot);\n  return lj_mem_new(J->L, sz);\n}\n\nstatic void mcode_free(jit_State *J, void *p, size_t sz)\n{\n  lj_mem_free(J2G(J), p, sz);\n}\n\n#endif\n\n/* -- MCode area protection ----------------------------------------------- */\n\n/* Define this ONLY if page protection twiddling becomes a bottleneck. */\n#ifdef LUAJIT_UNPROTECT_MCODE\n\n/* It's generally considered to be a potential security risk to have\n** pages with simultaneous write *and* execute access in a process.\n**\n** Do not even think about using this mode for server processes or\n** apps handling untrusted external data (such as a browser).\n**\n** The security risk is not in LuaJIT itself -- but if an adversary finds\n** any *other* flaw in your C application logic, then any RWX memory page\n** simplifies writing an exploit considerably.\n*/\n#define MCPROT_GEN\tMCPROT_RWX\n#define MCPROT_RUN\tMCPROT_RWX\n\nstatic void mcode_protect(jit_State *J, int prot)\n{\n  UNUSED(J); UNUSED(prot);\n}\n\n#else\n\n/* This is the default behaviour and much safer:\n**\n** Most of the time the memory pages holding machine code are executable,\n** but NONE of them is writable.\n**\n** The current memory area is marked read-write (but NOT executable) only\n** during the short time window while the assembler generates machine code.\n*/\n#define MCPROT_GEN\tMCPROT_RW\n#define MCPROT_RUN\tMCPROT_RX\n\n/* Protection twiddling failed. Probably due to kernel security. */\nstatic LJ_NOINLINE void mcode_protfail(jit_State *J)\n{\n  lua_CFunction panic = J2G(J)->panic;\n  if (panic) {\n    lua_State *L = J->L;\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_JITPROT));\n    panic(L);\n  }\n}\n\n/* Change protection of MCode area. */\nstatic void mcode_protect(jit_State *J, int prot)\n{\n  if (J->mcprot != prot) {\n    if (LJ_UNLIKELY(mcode_setprot(J->mcarea, J->szmcarea, prot)))\n      mcode_protfail(J);\n    J->mcprot = prot;\n  }\n}\n\n#endif\n\n/* -- MCode area allocation ----------------------------------------------- */\n\n#if LJ_TARGET_X64\n#define mcode_validptr(p)\t((p) && (uintptr_t)(p) < (uintptr_t)1<<47)\n#else\n#define mcode_validptr(p)\t((p) && (uintptr_t)(p) < 0xffff0000)\n#endif\n\n#ifdef LJ_TARGET_JUMPRANGE\n\n/* Get memory within relative jump distance of our code in 64 bit mode. */\nstatic void *mcode_alloc(jit_State *J, size_t sz)\n{\n  /* Target an address in the static assembler code (64K aligned).\n  ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB.\n  ** Use half the jump range so every address in the range can reach any other.\n  */\n#if LJ_TARGET_MIPS\n  /* Use the middle of the 256MB-aligned region. */\n  uintptr_t target = ((uintptr_t)(void *)lj_vm_exit_handler & 0xf0000000u) +\n\t\t     0x08000000u;\n#else\n  uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;\n#endif\n  const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21);\n  /* First try a contiguous area below the last one. */\n  uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;\n  int i;\n  for (i = 0; i < 32; i++) {  /* 32 attempts ought to be enough ... */\n    if (mcode_validptr(hint)) {\n      void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);\n\n      if (mcode_validptr(p) &&\n\t  ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range))\n\treturn p;\n      if (p) mcode_free(J, p, sz);  /* Free badly placed area. */\n    }\n    /* Next try probing pseudo-random addresses. */\n    do {\n      hint = (0x78fb ^ LJ_PRNG_BITS(J, 15)) << 16;  /* 64K aligned. */\n    } while (!(hint + sz < range));\n    hint = target + hint - (range>>1);\n  }\n  lj_trace_err(J, LJ_TRERR_MCODEAL);  /* Give up. OS probably ignores hints? */\n  return NULL;\n}\n\n#else\n\n/* All memory addresses are reachable by relative jumps. */\nstatic void *mcode_alloc(jit_State *J, size_t sz)\n{\n#ifdef __OpenBSD__\n  /* Allow better executable memory allocation for OpenBSD W^X mode. */\n  void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN);\n  if (p && mcode_setprot(p, sz, MCPROT_GEN)) {\n    mcode_free(J, p, sz);\n    return NULL;\n  }\n  return p;\n#else\n  return mcode_alloc_at(J, 0, sz, MCPROT_GEN);\n#endif\n}\n\n#endif\n\n/* -- MCode area management ----------------------------------------------- */\n\n/* Linked list of MCode areas. */\ntypedef struct MCLink {\n  MCode *next;\t\t/* Next area. */\n  size_t size;\t\t/* Size of current area. */\n} MCLink;\n\n/* Allocate a new MCode area. */\nstatic void mcode_allocarea(jit_State *J)\n{\n  MCode *oldarea = J->mcarea;\n  size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10;\n  sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);\n  J->mcarea = (MCode *)mcode_alloc(J, sz);\n  J->szmcarea = sz;\n  J->mcprot = MCPROT_GEN;\n  J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea);\n  J->mcbot = (MCode *)((char *)J->mcarea + sizeof(MCLink));\n  ((MCLink *)J->mcarea)->next = oldarea;\n  ((MCLink *)J->mcarea)->size = sz;\n  J->szallmcarea += sz;\n}\n\n/* Free all MCode areas. */\nvoid lj_mcode_free(jit_State *J)\n{\n  MCode *mc = J->mcarea;\n  J->mcarea = NULL;\n  J->szallmcarea = 0;\n  while (mc) {\n    MCode *next = ((MCLink *)mc)->next;\n    mcode_free(J, mc, ((MCLink *)mc)->size);\n    mc = next;\n  }\n}\n\n/* -- MCode transactions -------------------------------------------------- */\n\n/* Reserve the remainder of the current MCode area. */\nMCode *lj_mcode_reserve(jit_State *J, MCode **lim)\n{\n  if (!J->mcarea)\n    mcode_allocarea(J);\n  else\n    mcode_protect(J, MCPROT_GEN);\n  *lim = J->mcbot;\n  return J->mctop;\n}\n\n/* Commit the top part of the current MCode area. */\nvoid lj_mcode_commit(jit_State *J, MCode *top)\n{\n  J->mctop = top;\n  mcode_protect(J, MCPROT_RUN);\n}\n\n/* Abort the reservation. */\nvoid lj_mcode_abort(jit_State *J)\n{\n  if (J->mcarea)\n    mcode_protect(J, MCPROT_RUN);\n}\n\n/* Set/reset protection to allow patching of MCode areas. */\nMCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)\n{\n#ifdef LUAJIT_UNPROTECT_MCODE\n  UNUSED(J); UNUSED(ptr); UNUSED(finish);\n  return NULL;\n#else\n  if (finish) {\n    if (J->mcarea == ptr)\n      mcode_protect(J, MCPROT_RUN);\n    else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN)))\n      mcode_protfail(J);\n    return NULL;\n  } else {\n    MCode *mc = J->mcarea;\n    /* Try current area first to use the protection cache. */\n    if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {\n      mcode_protect(J, MCPROT_GEN);\n      return mc;\n    }\n    /* Otherwise search through the list of MCode areas. */\n    for (;;) {\n      mc = ((MCLink *)mc)->next;\n      lua_assert(mc != NULL);\n      if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {\n\tif (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN)))\n\t  mcode_protfail(J);\n\treturn mc;\n      }\n    }\n  }\n#endif\n}\n\n/* Limit of MCode reservation reached. */\nvoid lj_mcode_limiterr(jit_State *J, size_t need)\n{\n  size_t sizemcode, maxmcode;\n  lj_mcode_abort(J);\n  sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10;\n  sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);\n  maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10;\n  if ((size_t)need > sizemcode)\n    lj_trace_err(J, LJ_TRERR_MCODEOV);  /* Too long for any area. */\n  if (J->szallmcarea + sizemcode > maxmcode)\n    lj_trace_err(J, LJ_TRERR_MCODEAL);\n  mcode_allocarea(J);\n  lj_trace_err(J, LJ_TRERR_MCODELM);  /* Retry with new area. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_mcode.h",
    "content": "/*\n** Machine code management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_MCODE_H\n#define _LJ_MCODE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT || LJ_HASFFI\nLJ_FUNC void lj_mcode_sync(void *start, void *end);\n#endif\n\n#if LJ_HASJIT\n\n#include \"lj_jit.h\"\n\nLJ_FUNC void lj_mcode_free(jit_State *J);\nLJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim);\nLJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m);\nLJ_FUNC void lj_mcode_abort(jit_State *J);\nLJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish);\nLJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need);\n\n#define lj_mcode_commitbot(J, m)\t(J->mcbot = (m))\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_meta.c",
    "content": "/*\n** Metamethod handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_meta_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* -- Metamethod handling ------------------------------------------------- */\n\n/* String interning of metamethod names for fast indexing. */\nvoid lj_meta_init(lua_State *L)\n{\n#define MMNAME(name)\t\"__\" #name\n  const char *metanames = MMDEF(MMNAME);\n#undef MMNAME\n  global_State *g = G(L);\n  const char *p, *q;\n  uint32_t mm;\n  for (mm = 0, p = metanames; *p; mm++, p = q) {\n    GCstr *s;\n    for (q = p+2; *q && *q != '_'; q++) ;\n    s = lj_str_new(L, p, (size_t)(q-p));\n    /* NOBARRIER: g->gcroot[] is a GC root. */\n    setgcref(g->gcroot[GCROOT_MMNAME+mm], obj2gco(s));\n  }\n}\n\n/* Negative caching of a few fast metamethods. See the lj_meta_fast() macro. */\ncTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name)\n{\n  cTValue *mo = lj_tab_getstr(mt, name);\n  lua_assert(mm <= MM_FAST);\n  if (!mo || tvisnil(mo)) {  /* No metamethod? */\n    mt->nomm |= (uint8_t)(1u<<mm);  /* Set negative cache flag. */\n    return NULL;\n  }\n  return mo;\n}\n\n/* Lookup metamethod for object. */\ncTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm)\n{\n  GCtab *mt;\n  if (tvistab(o))\n    mt = tabref(tabV(o)->metatable);\n  else if (tvisudata(o))\n    mt = tabref(udataV(o)->metatable);\n  else\n    mt = tabref(basemt_obj(G(L), o));\n  if (mt) {\n    cTValue *mo = lj_tab_getstr(mt, mmname_str(G(L), mm));\n    if (mo)\n      return mo;\n  }\n  return niltv(L);\n}\n\n#if LJ_HASFFI\n/* Tailcall from C function. */\nint lj_meta_tailcall(lua_State *L, cTValue *tv)\n{\n  TValue *base = L->base;\n  TValue *top = L->top;\n  const BCIns *pc = frame_pc(base-1);  /* Preserve old PC from frame. */\n  copyTV(L, base-1-LJ_FR2, tv);  /* Replace frame with new object. */\n  if (LJ_FR2)\n    (top++)->u64 = LJ_CONT_TAILCALL;\n  else\n    top->u32.lo = LJ_CONT_TAILCALL;\n  setframe_pc(top++, pc);\n  if (LJ_FR2) top++;\n  setframe_gc(top, obj2gco(L), LJ_TTHREAD);  /* Dummy frame object. */\n  setframe_ftsz(top, ((char *)(top+1) - (char *)base) + FRAME_CONT);\n  L->base = L->top = top+1;\n  /*\n  ** before:   [old_mo|PC]    [... ...]\n  **                         ^base     ^top\n  ** after:    [new_mo|itype] [... ...] [NULL|PC] [dummy|delta]\n  **                                                           ^base/top\n  ** tailcall: [new_mo|PC]    [... ...]\n  **                         ^base     ^top\n  */\n  return 0;\n}\n#endif\n\n/* Setup call to metamethod to be run by Assembler VM. */\nstatic TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo,\n\t\t    cTValue *a, cTValue *b)\n{\n  /*\n  **           |-- framesize -> top       top+1       top+2 top+3\n  ** before:   [func slots ...]\n  ** mm setup: [func slots ...] [cont|?]  [mo|tmtype] [a]   [b]\n  ** in asm:   [func slots ...] [cont|PC] [mo|delta]  [a]   [b]\n  **           ^-- func base                          ^-- mm base\n  ** after mm: [func slots ...]           [result]\n  **                ^-- copy to base[PC_RA] --/     for lj_cont_ra\n  **                          istruecond + branch   for lj_cont_cond*\n  **                                       ignore   for lj_cont_nop\n  ** next PC:  [func slots ...]\n  */\n  TValue *top = L->top;\n  if (curr_funcisL(L)) top = curr_topL(L);\n  setcont(top++, cont);  /* Assembler VM stores PC in upper word or FR2. */\n  if (LJ_FR2) setnilV(top++);\n  copyTV(L, top++, mo);  /* Store metamethod and two arguments. */\n  if (LJ_FR2) setnilV(top++);\n  copyTV(L, top, a);\n  copyTV(L, top+1, b);\n  return top;  /* Return new base. */\n}\n\n/* -- C helpers for some instructions, called from assembler VM ----------- */\n\n/* Helper for TGET*. __index chain and metamethod. */\ncTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k)\n{\n  int loop;\n  for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {\n    cTValue *mo;\n    if (LJ_LIKELY(tvistab(o))) {\n      GCtab *t = tabV(o);\n      cTValue *tv = lj_tab_get(L, t, k);\n      if (!tvisnil(tv) ||\n\t  !(mo = lj_meta_fast(L, tabref(t->metatable), MM_index)))\n\treturn tv;\n    } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_index))) {\n      lj_err_optype(L, o, LJ_ERR_OPINDEX);\n      return NULL;  /* unreachable */\n    }\n    if (tvisfunc(mo)) {\n      L->top = mmcall(L, lj_cont_ra, mo, o, k);\n      return NULL;  /* Trigger metamethod call. */\n    }\n    o = mo;\n  }\n  lj_err_msg(L, LJ_ERR_GETLOOP);\n  return NULL;  /* unreachable */\n}\n\n/* Helper for TSET*. __newindex chain and metamethod. */\nTValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k)\n{\n  TValue tmp;\n  int loop;\n  for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {\n    cTValue *mo;\n    if (LJ_LIKELY(tvistab(o))) {\n      GCtab *t = tabV(o);\n      cTValue *tv = lj_tab_get(L, t, k);\n      if (LJ_LIKELY(!tvisnil(tv))) {\n\tt->nomm = 0;  /* Invalidate negative metamethod cache. */\n\tlj_gc_anybarriert(L, t);\n\treturn (TValue *)tv;\n      } else if (!(mo = lj_meta_fast(L, tabref(t->metatable), MM_newindex))) {\n\tt->nomm = 0;  /* Invalidate negative metamethod cache. */\n\tlj_gc_anybarriert(L, t);\n\tif (tv != niltv(L))\n\t  return (TValue *)tv;\n\tif (tvisnil(k)) lj_err_msg(L, LJ_ERR_NILIDX);\n\telse if (tvisint(k)) { setnumV(&tmp, (lua_Number)intV(k)); k = &tmp; }\n\telse if (tvisnum(k) && tvisnan(k)) lj_err_msg(L, LJ_ERR_NANIDX);\n\treturn lj_tab_newkey(L, t, k);\n      }\n    } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_newindex))) {\n      lj_err_optype(L, o, LJ_ERR_OPINDEX);\n      return NULL;  /* unreachable */\n    }\n    if (tvisfunc(mo)) {\n      L->top = mmcall(L, lj_cont_nop, mo, o, k);\n      /* L->top+2 = v filled in by caller. */\n      return NULL;  /* Trigger metamethod call. */\n    }\n    copyTV(L, &tmp, mo);\n    o = &tmp;\n  }\n  lj_err_msg(L, LJ_ERR_SETLOOP);\n  return NULL;  /* unreachable */\n}\n\nstatic cTValue *str2num(cTValue *o, TValue *n)\n{\n  if (tvisnum(o))\n    return o;\n  else if (tvisint(o))\n    return (setnumV(n, (lua_Number)intV(o)), n);\n  else if (tvisstr(o) && lj_strscan_num(strV(o), n))\n    return n;\n  else\n    return NULL;\n}\n\n/* Helper for arithmetic instructions. Coercion, metamethod. */\nTValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, cTValue *rc,\n\t\t      BCReg op)\n{\n  MMS mm = bcmode_mm(op);\n  TValue tempb, tempc;\n  cTValue *b, *c;\n  if ((b = str2num(rb, &tempb)) != NULL &&\n      (c = str2num(rc, &tempc)) != NULL) {  /* Try coercion first. */\n    setnumV(ra, lj_vm_foldarith(numV(b), numV(c), (int)mm-MM_add));\n    return NULL;\n  } else {\n    cTValue *mo = lj_meta_lookup(L, rb, mm);\n    if (tvisnil(mo)) {\n      mo = lj_meta_lookup(L, rc, mm);\n      if (tvisnil(mo)) {\n\tif (str2num(rb, &tempb) == NULL) rc = rb;\n\tlj_err_optype(L, rc, LJ_ERR_OPARITH);\n\treturn NULL;  /* unreachable */\n      }\n    }\n    return mmcall(L, lj_cont_ra, mo, rb, rc);\n  }\n}\n\n/* Helper for CAT. Coercion, iterative concat, __concat metamethod. */\nTValue *lj_meta_cat(lua_State *L, TValue *top, int left)\n{\n  int fromc = 0;\n  if (left < 0) { left = -left; fromc = 1; }\n  do {\n    if (!(tvisstr(top) || tvisnumber(top)) ||\n\t!(tvisstr(top-1) || tvisnumber(top-1))) {\n      cTValue *mo = lj_meta_lookup(L, top-1, MM_concat);\n      if (tvisnil(mo)) {\n\tmo = lj_meta_lookup(L, top, MM_concat);\n\tif (tvisnil(mo)) {\n\t  if (tvisstr(top-1) || tvisnumber(top-1)) top++;\n\t  lj_err_optype(L, top-1, LJ_ERR_OPCAT);\n\t  return NULL;  /* unreachable */\n\t}\n      }\n      /* One of the top two elements is not a string, call __cat metamethod:\n      **\n      ** before:    [...][CAT stack .........................]\n      **                                 top-1     top         top+1 top+2\n      ** pick two:  [...][CAT stack ...] [o1]      [o2]\n      ** setup mm:  [...][CAT stack ...] [cont|?]  [mo|tmtype] [o1]  [o2]\n      ** in asm:    [...][CAT stack ...] [cont|PC] [mo|delta]  [o1]  [o2]\n      **            ^-- func base                              ^-- mm base\n      ** after mm:  [...][CAT stack ...] <--push-- [result]\n      ** next step: [...][CAT stack .............]\n      */\n      copyTV(L, top+2*LJ_FR2+2, top);  /* Carefully ordered stack copies! */\n      copyTV(L, top+2*LJ_FR2+1, top-1);\n      copyTV(L, top+LJ_FR2, mo);\n      setcont(top-1, lj_cont_cat);\n      if (LJ_FR2) { setnilV(top); setnilV(top+2); top += 2; }\n      return top+1;  /* Trigger metamethod call. */\n    } else {\n      /* Pick as many strings as possible from the top and concatenate them:\n      **\n      ** before:    [...][CAT stack ...........................]\n      ** pick str:  [...][CAT stack ...] [...... strings ......]\n      ** concat:    [...][CAT stack ...] [result]\n      ** next step: [...][CAT stack ............]\n      */\n      TValue *e, *o = top;\n      uint64_t tlen = tvisstr(o) ? strV(o)->len : STRFMT_MAXBUF_NUM;\n      SBuf *sb;\n      do {\n\to--; tlen += tvisstr(o) ? strV(o)->len : STRFMT_MAXBUF_NUM;\n      } while (--left > 0 && (tvisstr(o-1) || tvisnumber(o-1)));\n      if (tlen >= LJ_MAX_STR) lj_err_msg(L, LJ_ERR_STROV);\n      sb = lj_buf_tmp_(L);\n      lj_buf_more(sb, (MSize)tlen);\n      for (e = top, top = o; o <= e; o++) {\n\tif (tvisstr(o)) {\n\t  GCstr *s = strV(o);\n\t  MSize len = s->len;\n\t  lj_buf_putmem(sb, strdata(s), len);\n\t} else if (tvisint(o)) {\n\t  lj_strfmt_putint(sb, intV(o));\n\t} else {\n\t  lj_strfmt_putfnum(sb, STRFMT_G14, numV(o));\n\t}\n      }\n      setstrV(L, top, lj_buf_str(L, sb));\n    }\n  } while (left >= 1);\n  if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) {\n    if (!fromc) L->top = curr_topL(L);\n    lj_gc_step(L);\n  }\n  return NULL;\n}\n\n/* Helper for LEN. __len metamethod. */\nTValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o)\n{\n  cTValue *mo = lj_meta_lookup(L, o, MM_len);\n  if (tvisnil(mo)) {\n    if (LJ_52 && tvistab(o))\n      tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<<MM_len);\n    else\n      lj_err_optype(L, o, LJ_ERR_OPLEN);\n    return NULL;\n  }\n  return mmcall(L, lj_cont_ra, mo, o, LJ_52 ? o : niltv(L));\n}\n\n/* Helper for equality comparisons. __eq metamethod. */\nTValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)\n{\n  /* Field metatable must be at same offset for GCtab and GCudata! */\n  cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq);\n  if (mo) {\n    TValue *top;\n    uint32_t it;\n    if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) {\n      cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq);\n      if (mo2 == NULL || !lj_obj_equal(mo, mo2))\n\treturn (TValue *)(intptr_t)ne;\n    }\n    top = curr_top(L);\n    setcont(top++, ne ? lj_cont_condf : lj_cont_condt);\n    if (LJ_FR2) setnilV(top++);\n    copyTV(L, top++, mo);\n    if (LJ_FR2) setnilV(top++);\n    it = ~(uint32_t)o1->gch.gct;\n    setgcV(L, top, o1, it);\n    setgcV(L, top+1, o2, it);\n    return top;  /* Trigger metamethod call. */\n  }\n  return (TValue *)(intptr_t)ne;\n}\n\n#if LJ_HASFFI\nTValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins)\n{\n  ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt;\n  int op = (int)bc_op(ins) & ~1;\n  TValue tv;\n  cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)];\n  cTValue *o1mm = o1;\n  if (op == BC_ISEQV) {\n    o2 = &L->base[bc_d(ins)];\n    if (!tviscdata(o1mm)) o1mm = o2;\n  } else if (op == BC_ISEQS) {\n    setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins))));\n    o2 = &tv;\n  } else if (op == BC_ISEQN) {\n    o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)];\n  } else {\n    lua_assert(op == BC_ISEQP);\n    setpriV(&tv, ~bc_d(ins));\n    o2 = &tv;\n  }\n  mo = lj_meta_lookup(L, o1mm, MM_eq);\n  if (LJ_LIKELY(!tvisnil(mo)))\n    return mmcall(L, cont, mo, o1, o2);\n  else\n    return (TValue *)(intptr_t)(bc_op(ins) & 1);\n}\n#endif\n\n/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */\nTValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op)\n{\n  if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) {\n    ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;\n    MMS mm = (op & 2) ? MM_le : MM_lt;\n    cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm);\n    if (LJ_UNLIKELY(tvisnil(mo))) goto err;\n    return mmcall(L, cont, mo, o1, o2);\n  } else if (LJ_52 || itype(o1) == itype(o2)) {\n    /* Never called with two numbers. */\n    if (tvisstr(o1) && tvisstr(o2)) {\n      int32_t res = lj_str_cmp(strV(o1), strV(o2));\n      return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1));\n    } else {\n    trymt:\n      while (1) {\n\tASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;\n\tMMS mm = (op & 2) ? MM_le : MM_lt;\n\tcTValue *mo = lj_meta_lookup(L, o1, mm);\n#if LJ_52\n\tif (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm))))\n#else\n\tcTValue *mo2 = lj_meta_lookup(L, o2, mm);\n\tif (tvisnil(mo) || !lj_obj_equal(mo, mo2))\n#endif\n\t{\n\t  if (op & 2) {  /* MM_le not found: retry with MM_lt. */\n\t    cTValue *ot = o1; o1 = o2; o2 = ot;  /* Swap operands. */\n\t    op ^= 3;  /* Use LT and flip condition. */\n\t    continue;\n\t  }\n\t  goto err;\n\t}\n\treturn mmcall(L, cont, mo, o1, o2);\n      }\n    }\n  } else if (tvisbool(o1) && tvisbool(o2)) {\n    goto trymt;\n  } else {\n  err:\n    lj_err_comp(L, o1, o2);\n    return NULL;\n  }\n}\n\n/* Helper for ISTYPE and ISNUM. Implicit coercion or error. */\nvoid lj_meta_istype(lua_State *L, BCReg ra, BCReg tp)\n{\n  L->top = curr_topL(L);\n  ra++; tp--;\n  lua_assert(LJ_DUALNUM || tp != ~LJ_TNUMX);  /* ISTYPE -> ISNUM broken. */\n  if (LJ_DUALNUM && tp == ~LJ_TNUMX) lj_lib_checkint(L, ra);\n  else if (tp == ~LJ_TNUMX+1) lj_lib_checknum(L, ra);\n  else if (tp == ~LJ_TSTR) lj_lib_checkstr(L, ra);\n  else lj_err_argtype(L, ra, lj_obj_itypename[tp]);\n}\n\n/* Helper for calls. __call metamethod. */\nvoid lj_meta_call(lua_State *L, TValue *func, TValue *top)\n{\n  cTValue *mo = lj_meta_lookup(L, func, MM_call);\n  TValue *p;\n  if (!tvisfunc(mo))\n    lj_err_optype_call(L, func);\n  for (p = top; p > func+2*LJ_FR2; p--) copyTV(L, p, p-1);\n  if (LJ_FR2) copyTV(L, func+2, func);\n  copyTV(L, func, mo);\n}\n\n/* Helper for FORI. Coercion. */\nvoid LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o)\n{\n  if (!lj_strscan_numberobj(o)) lj_err_msg(L, LJ_ERR_FORINIT);\n  if (!lj_strscan_numberobj(o+1)) lj_err_msg(L, LJ_ERR_FORLIM);\n  if (!lj_strscan_numberobj(o+2)) lj_err_msg(L, LJ_ERR_FORSTEP);\n  if (LJ_DUALNUM) {\n    /* Ensure all slots are integers or all slots are numbers. */\n    int32_t k[3];\n    int nint = 0;\n    ptrdiff_t i;\n    for (i = 0; i <= 2; i++) {\n      if (tvisint(o+i)) {\n\tk[i] = intV(o+i); nint++;\n      } else {\n\tk[i] = lj_num2int(numV(o+i)); nint += ((lua_Number)k[i] == numV(o+i));\n      }\n    }\n    if (nint == 3) {  /* Narrow to integers. */\n      setintV(o, k[0]);\n      setintV(o+1, k[1]);\n      setintV(o+2, k[2]);\n    } else if (nint != 0) {  /* Widen to numbers. */\n      if (tvisint(o)) setnumV(o, (lua_Number)intV(o));\n      if (tvisint(o+1)) setnumV(o+1, (lua_Number)intV(o+1));\n      if (tvisint(o+2)) setnumV(o+2, (lua_Number)intV(o+2));\n    }\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_meta.h",
    "content": "/*\n** Metamethod handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_META_H\n#define _LJ_META_H\n\n#include \"lj_obj.h\"\n\n/* Metamethod handling */\nLJ_FUNC void lj_meta_init(lua_State *L);\nLJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name);\nLJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm);\n#if LJ_HASFFI\nLJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv);\n#endif\n\n#define lj_meta_fastg(g, mt, mm) \\\n  ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \\\n   lj_meta_cache(mt, mm, mmname_str(g, mm)))\n#define lj_meta_fast(L, mt, mm)\tlj_meta_fastg(G(L), mt, mm)\n\n/* C helpers for some instructions, called from assembler VM. */\nLJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k);\nLJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k);\nLJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb,\n\t\t\t       cTValue *rc, BCReg op);\nLJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left);\nLJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o);\nLJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne);\nLJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins);\nLJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op);\nLJ_FUNCA void lj_meta_istype(lua_State *L, BCReg ra, BCReg tp);\nLJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top);\nLJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_obj.c",
    "content": "/*\n** Miscellaneous object handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_obj_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n/* Object type names. */\nLJ_DATADEF const char *const lj_obj_typename[] = {  /* ORDER LUA_T */\n  \"no value\", \"nil\", \"boolean\", \"userdata\", \"number\", \"string\",\n  \"table\", \"function\", \"userdata\", \"thread\", \"proto\", \"cdata\"\n};\n\nLJ_DATADEF const char *const lj_obj_itypename[] = {  /* ORDER LJ_T */\n  \"nil\", \"boolean\", \"boolean\", \"userdata\", \"string\", \"upval\", \"thread\",\n  \"proto\", \"function\", \"trace\", \"cdata\", \"table\", \"userdata\", \"number\"\n};\n\n/* Compare two objects without calling metamethods. */\nint LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2)\n{\n  if (itype(o1) == itype(o2)) {\n    if (tvispri(o1))\n      return 1;\n    if (!tvisnum(o1))\n      return gcrefeq(o1->gcr, o2->gcr);\n  } else if (!tvisnumber(o1) || !tvisnumber(o2)) {\n    return 0;\n  }\n  return numberVnum(o1) == numberVnum(o2);\n}\n\n/* Return pointer to object or its object data. */\nconst void * LJ_FASTCALL lj_obj_ptr(cTValue *o)\n{\n  if (tvisudata(o))\n    return uddata(udataV(o));\n  else if (tvislightud(o))\n    return lightudV(o);\n  else if (LJ_HASFFI && tviscdata(o))\n    return cdataptr(cdataV(o));\n  else if (tvisgcv(o))\n    return gcV(o);\n  else\n    return NULL;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_obj.h",
    "content": "/*\n** LuaJIT VM tags, values and objects.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#ifndef _LJ_OBJ_H\n#define _LJ_OBJ_H\n\n#include \"lua.h\"\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* -- Memory references (32 bit address space) ---------------------------- */\n\n/* Memory and GC object sizes. */\ntypedef uint32_t MSize;\n#if LJ_GC64\ntypedef uint64_t GCSize;\n#else\ntypedef uint32_t GCSize;\n#endif\n\n/* Memory reference */\ntypedef struct MRef {\n#if LJ_GC64\n  uint64_t ptr64;\t/* True 64 bit pointer. */\n#else\n  uint32_t ptr32;\t/* Pseudo 32 bit pointer. */\n#endif\n} MRef;\n\n#if LJ_GC64\n#define mref(r, t)\t((t *)(void *)(r).ptr64)\n\n#define setmref(r, p)\t((r).ptr64 = (uint64_t)(void *)(p))\n#define setmrefr(r, v)\t((r).ptr64 = (v).ptr64)\n#else\n#define mref(r, t)\t((t *)(void *)(uintptr_t)(r).ptr32)\n\n#define setmref(r, p)\t((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p))\n#define setmrefr(r, v)\t((r).ptr32 = (v).ptr32)\n#endif\n\n/* -- GC object references (32 bit address space) ------------------------- */\n\n/* GCobj reference */\ntypedef struct GCRef {\n#if LJ_GC64\n  uint64_t gcptr64;\t/* True 64 bit pointer. */\n#else\n  uint32_t gcptr32;\t/* Pseudo 32 bit pointer. */\n#endif\n} GCRef;\n\n/* Common GC header for all collectable objects. */\n#define GCHeader\tGCRef nextgc; uint8_t marked; uint8_t gct\n/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */\n\n#if LJ_GC64\n#define gcref(r)\t((GCobj *)(r).gcptr64)\n#define gcrefp(r, t)\t((t *)(void *)(r).gcptr64)\n#define gcrefu(r)\t((r).gcptr64)\n#define gcrefeq(r1, r2)\t((r1).gcptr64 == (r2).gcptr64)\n\n#define setgcref(r, gc)\t((r).gcptr64 = (uint64_t)&(gc)->gch)\n#define setgcreft(r, gc, it) \\\n  (r).gcptr64 = (uint64_t)&(gc)->gch | (((uint64_t)(it)) << 47)\n#define setgcrefp(r, p)\t((r).gcptr64 = (uint64_t)(p))\n#define setgcrefnull(r)\t((r).gcptr64 = 0)\n#define setgcrefr(r, v)\t((r).gcptr64 = (v).gcptr64)\n#else\n#define gcref(r)\t((GCobj *)(uintptr_t)(r).gcptr32)\n#define gcrefp(r, t)\t((t *)(void *)(uintptr_t)(r).gcptr32)\n#define gcrefu(r)\t((r).gcptr32)\n#define gcrefeq(r1, r2)\t((r1).gcptr32 == (r2).gcptr32)\n\n#define setgcref(r, gc)\t((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)\n#define setgcrefp(r, p)\t((r).gcptr32 = (uint32_t)(uintptr_t)(p))\n#define setgcrefnull(r)\t((r).gcptr32 = 0)\n#define setgcrefr(r, v)\t((r).gcptr32 = (v).gcptr32)\n#endif\n\n#define gcnext(gc)\t(gcref((gc)->gch.nextgc))\n\n/* IMPORTANT NOTE:\n**\n** All uses of the setgcref* macros MUST be accompanied with a write barrier.\n**\n** This is to ensure the integrity of the incremental GC. The invariant\n** to preserve is that a black object never points to a white object.\n** I.e. never store a white object into a field of a black object.\n**\n** It's ok to LEAVE OUT the write barrier ONLY in the following cases:\n** - The source is not a GC object (NULL).\n** - The target is a GC root. I.e. everything in global_State.\n** - The target is a lua_State field (threads are never black).\n** - The target is a stack slot, see setgcV et al.\n** - The target is an open upvalue, i.e. pointing to a stack slot.\n** - The target is a newly created object (i.e. marked white). But make\n**   sure nothing invokes the GC inbetween.\n** - The target and the source are the same object (self-reference).\n** - The target already contains the object (e.g. moving elements around).\n**\n** The most common case is a store to a stack slot. All other cases where\n** a barrier has been omitted are annotated with a NOBARRIER comment.\n**\n** The same logic applies for stores to table slots (array part or hash\n** part). ALL uses of lj_tab_set* require a barrier for the stored value\n** *and* the stored key, based on the above rules. In practice this means\n** a barrier is needed if *either* of the key or value are a GC object.\n**\n** It's ok to LEAVE OUT the write barrier in the following special cases:\n** - The stored value is nil. The key doesn't matter because it's either\n**   not resurrected or lj_tab_newkey() will take care of the key barrier.\n** - The key doesn't matter if the *previously* stored value is guaranteed\n**   to be non-nil (because the key is kept alive in the table).\n** - The key doesn't matter if it's guaranteed not to be part of the table,\n**   since lj_tab_newkey() takes care of the key barrier. This applies\n**   trivially to new tables, but watch out for resurrected keys. Storing\n**   a nil value leaves the key in the table!\n**\n** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used\n** by the interpreter for all table stores.\n**\n** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark\n** dead keys in tables. The reference is left in, but it's guaranteed to\n** be never dereferenced as long as the value is nil. It's ok if the key is\n** freed or if any object subsequently gets the same address.\n**\n** Not destroying dead keys helps to keep key hash slots stable. This avoids\n** specialization back-off for HREFK when a value flips between nil and\n** non-nil and the GC gets in the way. It also allows safely hoisting\n** HREF/HREFK across GC steps. Dead keys are only removed if a table is\n** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize.\n**\n** The trade-off is that a write barrier for tables must take the key into\n** account, too. Implicitly resurrecting the key by storing a non-nil value\n** may invalidate the incremental GC invariant.\n*/\n\n/* -- Common type definitions --------------------------------------------- */\n\n/* Types for handling bytecodes. Need this here, details in lj_bc.h. */\ntypedef uint32_t BCIns;  /* Bytecode instruction. */\ntypedef uint32_t BCPos;  /* Bytecode position. */\ntypedef uint32_t BCReg;  /* Bytecode register. */\ntypedef int32_t BCLine;  /* Bytecode line number. */\n\n/* Internal assembler functions. Never call these directly from C. */\ntypedef void (*ASMFunction)(void);\n\n/* Resizable string buffer. Need this here, details in lj_buf.h. */\ntypedef struct SBuf {\n  MRef p;\t\t/* String buffer pointer. */\n  MRef e;\t\t/* String buffer end pointer. */\n  MRef b;\t\t/* String buffer base. */\n  MRef L;\t\t/* lua_State, used for buffer resizing. */\n} SBuf;\n\n/* -- Tags and values ----------------------------------------------------- */\n\n/* Frame link. */\ntypedef union {\n  int32_t ftsz;\t\t/* Frame type and size of previous frame. */\n  MRef pcr;\t\t/* Or PC for Lua frames. */\n} FrameLink;\n\n/* Tagged value. */\ntypedef LJ_ALIGN(8) union TValue {\n  uint64_t u64;\t\t/* 64 bit pattern overlaps number. */\n  lua_Number n;\t\t/* Number object overlaps split tag/value object. */\n#if LJ_GC64\n  GCRef gcr;\t\t/* GCobj reference with tag. */\n  int64_t it64;\n  struct {\n    LJ_ENDIAN_LOHI(\n      int32_t i;\t/* Integer value. */\n    , uint32_t it;\t/* Internal object tag. Must overlap MSW of number. */\n    )\n  };\n#else\n  struct {\n    LJ_ENDIAN_LOHI(\n      union {\n\tGCRef gcr;\t/* GCobj reference (if any). */\n\tint32_t i;\t/* Integer value. */\n      };\n    , uint32_t it;\t/* Internal object tag. Must overlap MSW of number. */\n    )\n  };\n#endif\n#if LJ_FR2\n  int64_t ftsz;\t\t/* Frame type and size of previous frame, or PC. */\n#else\n  struct {\n    LJ_ENDIAN_LOHI(\n      GCRef func;\t/* Function for next frame (or dummy L). */\n    , FrameLink tp;\t/* Link to previous frame. */\n    )\n  } fr;\n#endif\n  struct {\n    LJ_ENDIAN_LOHI(\n      uint32_t lo;\t/* Lower 32 bits of number. */\n    , uint32_t hi;\t/* Upper 32 bits of number. */\n    )\n  } u32;\n} TValue;\n\ntypedef const TValue cTValue;\n\n#define tvref(r)\t(mref(r, TValue))\n\n/* More external and GCobj tags for internal objects. */\n#define LAST_TT\t\tLUA_TTHREAD\n#define LUA_TPROTO\t(LAST_TT+1)\n#define LUA_TCDATA\t(LAST_TT+2)\n\n/* Internal object tags.\n**\n** Format for 32 bit GC references (!LJ_GC64):\n**\n** Internal tags overlap the MSW of a number object (must be a double).\n** Interpreted as a double these are special NaNs. The FPU only generates\n** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available\n** for use as internal tags. Small negative numbers are used to shorten the\n** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).\n**\n**                  ---MSW---.---LSW---\n** primitive types |  itype  |         |\n** lightuserdata   |  itype  |  void * |  (32 bit platforms)\n** lightuserdata   |ffff|    void *    |  (64 bit platforms, 47 bit pointers)\n** GC objects      |  itype  |  GCRef  |\n** int (LJ_DUALNUM)|  itype  |   int   |\n** number           -------double------\n**\n** Format for 64 bit GC references (LJ_GC64):\n**\n** The upper 13 bits must be 1 (0xfff8...) for a special NaN. The next\n** 4 bits hold the internal tag. The lowest 47 bits either hold a pointer,\n** a zero-extended 32 bit integer or all bits set to 1 for primitive types.\n**\n**                     ------MSW------.------LSW------\n** primitive types    |1..1|itype|1..................1|\n** GC objects/lightud |1..1|itype|-------GCRef--------|\n** int (LJ_DUALNUM)   |1..1|itype|0..0|-----int-------|\n** number              ------------double-------------\n**\n** ORDER LJ_T\n** Primitive types nil/false/true must be first, lightuserdata next.\n** GC objects are at the end, table/userdata must be lowest.\n** Also check lj_ir.h for similar ordering constraints.\n*/\n#define LJ_TNIL\t\t\t(~0u)\n#define LJ_TFALSE\t\t(~1u)\n#define LJ_TTRUE\t\t(~2u)\n#define LJ_TLIGHTUD\t\t(~3u)\n#define LJ_TSTR\t\t\t(~4u)\n#define LJ_TUPVAL\t\t(~5u)\n#define LJ_TTHREAD\t\t(~6u)\n#define LJ_TPROTO\t\t(~7u)\n#define LJ_TFUNC\t\t(~8u)\n#define LJ_TTRACE\t\t(~9u)\n#define LJ_TCDATA\t\t(~10u)\n#define LJ_TTAB\t\t\t(~11u)\n#define LJ_TUDATA\t\t(~12u)\n/* This is just the canonical number type used in some places. */\n#define LJ_TNUMX\t\t(~13u)\n\n/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */\n#if LJ_64 && !LJ_GC64\n#define LJ_TISNUM\t\t0xfffeffffu\n#else\n#define LJ_TISNUM\t\tLJ_TNUMX\n#endif\n#define LJ_TISTRUECOND\t\tLJ_TFALSE\n#define LJ_TISPRI\t\tLJ_TTRUE\n#define LJ_TISGCV\t\t(LJ_TSTR+1)\n#define LJ_TISTABUD\t\tLJ_TTAB\n\n#if LJ_GC64\n#define LJ_GCVMASK\t\t(((uint64_t)1 << 47) - 1)\n#endif\n\n/* -- String object ------------------------------------------------------- */\n\n/* String object header. String payload follows. */\ntypedef struct GCstr {\n  GCHeader;\n  uint8_t reserved;\t/* Used by lexer for fast lookup of reserved words. */\n  uint8_t unused;\n  MSize hash;\t\t/* Hash of string. */\n  MSize len;\t\t/* Size of string. */\n} GCstr;\n\n#define strref(r)\t(&gcref((r))->str)\n#define strdata(s)\t((const char *)((s)+1))\n#define strdatawr(s)\t((char *)((s)+1))\n#define strVdata(o)\tstrdata(strV(o))\n#define sizestring(s)\t(sizeof(struct GCstr)+(s)->len+1)\n\n/* -- Userdata object ----------------------------------------------------- */\n\n/* Userdata object. Payload follows. */\ntypedef struct GCudata {\n  GCHeader;\n  uint8_t udtype;\t/* Userdata type. */\n  uint8_t unused2;\n  GCRef env;\t\t/* Should be at same offset in GCfunc. */\n  MSize len;\t\t/* Size of payload. */\n  GCRef metatable;\t/* Must be at same offset in GCtab. */\n  uint32_t align1;\t/* To force 8 byte alignment of the payload. */\n} GCudata;\n\n/* Userdata types. */\nenum {\n  UDTYPE_USERDATA,\t/* Regular userdata. */\n  UDTYPE_IO_FILE,\t/* I/O library FILE. */\n  UDTYPE_FFI_CLIB,\t/* FFI C library namespace. */\n  UDTYPE__MAX\n};\n\n#define uddata(u)\t((void *)((u)+1))\n#define sizeudata(u)\t(sizeof(struct GCudata)+(u)->len)\n\n/* -- C data object ------------------------------------------------------- */\n\n/* C data object. Payload follows. */\ntypedef struct GCcdata {\n  GCHeader;\n  uint16_t ctypeid;\t/* C type ID. */\n} GCcdata;\n\n/* Prepended to variable-sized or realigned C data objects. */\ntypedef struct GCcdataVar {\n  uint16_t offset;\t/* Offset to allocated memory (relative to GCcdata). */\n  uint16_t extra;\t/* Extra space allocated (incl. GCcdata + GCcdatav). */\n  MSize len;\t\t/* Size of payload. */\n} GCcdataVar;\n\n#define cdataptr(cd)\t((void *)((cd)+1))\n#define cdataisv(cd)\t((cd)->marked & 0x80)\n#define cdatav(cd)\t((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar)))\n#define cdatavlen(cd)\tcheck_exp(cdataisv(cd), cdatav(cd)->len)\n#define sizecdatav(cd)\t(cdatavlen(cd) + cdatav(cd)->extra)\n#define memcdatav(cd)\t((void *)((char *)(cd) - cdatav(cd)->offset))\n\n/* -- Prototype object ---------------------------------------------------- */\n\n#define SCALE_NUM_GCO\t((int32_t)sizeof(lua_Number)/sizeof(GCRef))\n#define round_nkgc(n)\t(((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1))\n\ntypedef struct GCproto {\n  GCHeader;\n  uint8_t numparams;\t/* Number of parameters. */\n  uint8_t framesize;\t/* Fixed frame size. */\n  MSize sizebc;\t\t/* Number of bytecode instructions. */\n#if LJ_GC64\n  uint32_t unused_gc64;\n#endif\n  GCRef gclist;\n  MRef k;\t\t/* Split constant array (points to the middle). */\n  MRef uv;\t\t/* Upvalue list. local slot|0x8000 or parent uv idx. */\n  MSize sizekgc;\t/* Number of collectable constants. */\n  MSize sizekn;\t\t/* Number of lua_Number constants. */\n  MSize sizept;\t\t/* Total size including colocated arrays. */\n  uint8_t sizeuv;\t/* Number of upvalues. */\n  uint8_t flags;\t/* Miscellaneous flags (see below). */\n  uint16_t trace;\t/* Anchor for chain of root traces. */\n  /* ------ The following fields are for debugging/tracebacks only ------ */\n  GCRef chunkname;\t/* Name of the chunk this function was defined in. */\n  BCLine firstline;\t/* First line of the function definition. */\n  BCLine numline;\t/* Number of lines for the function definition. */\n  MRef lineinfo;\t/* Compressed map from bytecode ins. to source line. */\n  MRef uvinfo;\t\t/* Upvalue names. */\n  MRef varinfo;\t\t/* Names and compressed extents of local variables. */\n} GCproto;\n\n/* Flags for prototype. */\n#define PROTO_CHILD\t\t0x01\t/* Has child prototypes. */\n#define PROTO_VARARG\t\t0x02\t/* Vararg function. */\n#define PROTO_FFI\t\t0x04\t/* Uses BC_KCDATA for FFI datatypes. */\n#define PROTO_NOJIT\t\t0x08\t/* JIT disabled for this function. */\n#define PROTO_ILOOP\t\t0x10\t/* Patched bytecode with ILOOP etc. */\n/* Only used during parsing. */\n#define PROTO_HAS_RETURN\t0x20\t/* Already emitted a return. */\n#define PROTO_FIXUP_RETURN\t0x40\t/* Need to fixup emitted returns. */\n/* Top bits used for counting created closures. */\n#define PROTO_CLCOUNT\t\t0x20\t/* Base of saturating 3 bit counter. */\n#define PROTO_CLC_BITS\t\t3\n#define PROTO_CLC_POLY\t\t(3*PROTO_CLCOUNT)  /* Polymorphic threshold. */\n\n#define PROTO_UV_LOCAL\t\t0x8000\t/* Upvalue for local slot. */\n#define PROTO_UV_IMMUTABLE\t0x4000\t/* Immutable upvalue. */\n\n#define proto_kgc(pt, idx) \\\n  check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \\\n\t    gcref(mref((pt)->k, GCRef)[(idx)]))\n#define proto_knumtv(pt, idx) \\\n  check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)])\n#define proto_bc(pt)\t\t((BCIns *)((char *)(pt) + sizeof(GCproto)))\n#define proto_bcpos(pt, pc)\t((BCPos)((pc) - proto_bc(pt)))\n#define proto_uv(pt)\t\t(mref((pt)->uv, uint16_t))\n\n#define proto_chunkname(pt)\t(strref((pt)->chunkname))\n#define proto_chunknamestr(pt)\t(strdata(proto_chunkname((pt))))\n#define proto_lineinfo(pt)\t(mref((pt)->lineinfo, const void))\n#define proto_uvinfo(pt)\t(mref((pt)->uvinfo, const uint8_t))\n#define proto_varinfo(pt)\t(mref((pt)->varinfo, const uint8_t))\n\n/* -- Upvalue object ------------------------------------------------------ */\n\ntypedef struct GCupval {\n  GCHeader;\n  uint8_t closed;\t/* Set if closed (i.e. uv->v == &uv->u.value). */\n  uint8_t immutable;\t/* Immutable value. */\n  union {\n    TValue tv;\t\t/* If closed: the value itself. */\n    struct {\t\t/* If open: double linked list, anchored at thread. */\n      GCRef prev;\n      GCRef next;\n    };\n  };\n  MRef v;\t\t/* Points to stack slot (open) or above (closed). */\n  uint32_t dhash;\t/* Disambiguation hash: dh1 != dh2 => cannot alias. */\n} GCupval;\n\n#define uvprev(uv_)\t(&gcref((uv_)->prev)->uv)\n#define uvnext(uv_)\t(&gcref((uv_)->next)->uv)\n#define uvval(uv_)\t(mref((uv_)->v, TValue))\n\n/* -- Function object (closures) ------------------------------------------ */\n\n/* Common header for functions. env should be at same offset in GCudata. */\n#define GCfuncHeader \\\n  GCHeader; uint8_t ffid; uint8_t nupvalues; \\\n  GCRef env; GCRef gclist; MRef pc\n\ntypedef struct GCfuncC {\n  GCfuncHeader;\n  lua_CFunction f;\t/* C function to be called. */\n  TValue upvalue[1];\t/* Array of upvalues (TValue). */\n} GCfuncC;\n\ntypedef struct GCfuncL {\n  GCfuncHeader;\n  GCRef uvptr[1];\t/* Array of _pointers_ to upvalue objects (GCupval). */\n} GCfuncL;\n\ntypedef union GCfunc {\n  GCfuncC c;\n  GCfuncL l;\n} GCfunc;\n\n#define FF_LUA\t\t0\n#define FF_C\t\t1\n#define isluafunc(fn)\t((fn)->c.ffid == FF_LUA)\n#define iscfunc(fn)\t((fn)->c.ffid == FF_C)\n#define isffunc(fn)\t((fn)->c.ffid > FF_C)\n#define funcproto(fn) \\\n  check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))\n#define sizeCfunc(n)\t(sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))\n#define sizeLfunc(n)\t(sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))\n\n/* -- Table object -------------------------------------------------------- */\n\n/* Hash node. */\ntypedef struct Node {\n  TValue val;\t\t/* Value object. Must be first field. */\n  TValue key;\t\t/* Key object. */\n  MRef next;\t\t/* Hash chain. */\n#if !LJ_GC64\n  MRef freetop;\t\t/* Top of free elements (stored in t->node[0]). */\n#endif\n} Node;\n\nLJ_STATIC_ASSERT(offsetof(Node, val) == 0);\n\ntypedef struct GCtab {\n  GCHeader;\n  uint8_t nomm;\t\t/* Negative cache for fast metamethods. */\n  int8_t colo;\t\t/* Array colocation. */\n  MRef array;\t\t/* Array part. */\n  GCRef gclist;\n  GCRef metatable;\t/* Must be at same offset in GCudata. */\n  MRef node;\t\t/* Hash part. */\n  uint32_t asize;\t/* Size of array part (keys [0, asize-1]). */\n  uint32_t hmask;\t/* Hash part mask (size of hash part - 1). */\n#if LJ_GC64\n  MRef freetop;\t\t/* Top of free elements. */\n#endif\n} GCtab;\n\n#define sizetabcolo(n)\t((n)*sizeof(TValue) + sizeof(GCtab))\n#define tabref(r)\t(&gcref((r))->tab)\n#define noderef(r)\t(mref((r), Node))\n#define nextnode(n)\t(mref((n)->next, Node))\n#if LJ_GC64\n#define getfreetop(t, n)\t(noderef((t)->freetop))\n#define setfreetop(t, n, v)\t(setmref((t)->freetop, (v)))\n#else\n#define getfreetop(t, n)\t(noderef((n)->freetop))\n#define setfreetop(t, n, v)\t(setmref((n)->freetop, (v)))\n#endif\n\n/* -- State objects ------------------------------------------------------- */\n\n/* VM states. */\nenum {\n  LJ_VMST_INTERP,\t/* Interpreter. */\n  LJ_VMST_C,\t\t/* C function. */\n  LJ_VMST_GC,\t\t/* Garbage collector. */\n  LJ_VMST_EXIT,\t\t/* Trace exit handler. */\n  LJ_VMST_RECORD,\t/* Trace recorder. */\n  LJ_VMST_OPT,\t\t/* Optimizer. */\n  LJ_VMST_ASM,\t\t/* Assembler. */\n  LJ_VMST__MAX\n};\n\n#define setvmstate(g, st)\t((g)->vmstate = ~LJ_VMST_##st)\n\n/* Metamethods. ORDER MM */\n#ifdef LJ_HASFFI\n#define MMDEF_FFI(_) _(new)\n#else\n#define MMDEF_FFI(_)\n#endif\n\n#if LJ_52 || LJ_HASFFI\n#define MMDEF_PAIRS(_) _(pairs) _(ipairs)\n#else\n#define MMDEF_PAIRS(_)\n#define MM_pairs\t255\n#define MM_ipairs\t255\n#endif\n\n#define MMDEF(_) \\\n  _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \\\n  /* Only the above (fast) metamethods are negative cached (max. 8). */ \\\n  _(lt) _(le) _(concat) _(call) \\\n  /* The following must be in ORDER ARITH. */ \\\n  _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \\\n  /* The following are used in the standard libraries. */ \\\n  _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_)\n\ntypedef enum {\n#define MMENUM(name)\tMM_##name,\nMMDEF(MMENUM)\n#undef MMENUM\n  MM__MAX,\n  MM____ = MM__MAX,\n  MM_FAST = MM_len\n} MMS;\n\n/* GC root IDs. */\ntypedef enum {\n  GCROOT_MMNAME,\t/* Metamethod names. */\n  GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,\n  GCROOT_BASEMT,\t/* Metatables for base types. */\n  GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,\n  GCROOT_IO_INPUT,\t/* Userdata for default I/O input file. */\n  GCROOT_IO_OUTPUT,\t/* Userdata for default I/O output file. */\n  GCROOT_MAX\n} GCRootID;\n\n#define basemt_it(g, it)\t((g)->gcroot[GCROOT_BASEMT+~(it)])\n#define basemt_obj(g, o)\t((g)->gcroot[GCROOT_BASEMT+itypemap(o)])\n#define mmname_str(g, mm)\t(strref((g)->gcroot[GCROOT_MMNAME+(mm)]))\n\ntypedef struct GCState {\n  GCSize total;\t\t/* Memory currently allocated. */\n  GCSize threshold;\t/* Memory threshold. */\n  uint8_t currentwhite;\t/* Current white color. */\n  uint8_t state;\t/* GC state. */\n  uint8_t nocdatafin;\t/* No cdata finalizer called. */\n  uint8_t unused2;\n  MSize sweepstr;\t/* Sweep position in string table. */\n  GCRef root;\t\t/* List of all collectable objects. */\n  MRef sweep;\t\t/* Sweep position in root list. */\n  GCRef gray;\t\t/* List of gray objects. */\n  GCRef grayagain;\t/* List of objects for atomic traversal. */\n  GCRef weak;\t\t/* List of weak tables (to be cleared). */\n  GCRef mmudata;\t/* List of userdata (to be finalized). */\n  GCSize debt;\t\t/* Debt (how much GC is behind schedule). */\n  GCSize estimate;\t/* Estimate of memory actually in use. */\n  MSize stepmul;\t/* Incremental GC step granularity. */\n  MSize pause;\t\t/* Pause between successive GC cycles. */\n} GCState;\n\n/* Global state, shared by all threads of a Lua universe. */\ntypedef struct global_State {\n  GCRef *strhash;\t/* String hash table (hash chain anchors). */\n  MSize strmask;\t/* String hash mask (size of hash table - 1). */\n  MSize strnum;\t\t/* Number of strings in hash table. */\n  lua_Alloc allocf;\t/* Memory allocator. */\n  void *allocd;\t\t/* Memory allocator data. */\n  GCState gc;\t\t/* Garbage collector. */\n  volatile int32_t vmstate;  /* VM state or current JIT code trace number. */\n  SBuf tmpbuf;\t\t/* Temporary string buffer. */\n  GCstr strempty;\t/* Empty string. */\n  uint8_t stremptyz;\t/* Zero terminator of empty string. */\n  uint8_t hookmask;\t/* Hook mask. */\n  uint8_t dispatchmode;\t/* Dispatch mode. */\n  uint8_t vmevmask;\t/* VM event mask. */\n  GCRef mainthref;\t/* Link to main thread. */\n  TValue registrytv;\t/* Anchor for registry. */\n  TValue tmptv, tmptv2;\t/* Temporary TValues. */\n  Node nilnode;\t\t/* Fallback 1-element hash part (nil key and value). */\n  GCupval uvhead;\t/* Head of double-linked list of all open upvalues. */\n  int32_t hookcount;\t/* Instruction hook countdown. */\n  int32_t hookcstart;\t/* Start count for instruction hook counter. */\n  lua_Hook hookf;\t/* Hook function. */\n  lua_CFunction wrapf;\t/* Wrapper for C function calls. */\n  lua_CFunction panic;\t/* Called as a last resort for errors. */\n  BCIns bc_cfunc_int;\t/* Bytecode for internal C function calls. */\n  BCIns bc_cfunc_ext;\t/* Bytecode for external C function calls. */\n  GCRef cur_L;\t\t/* Currently executing lua_State. */\n  MRef jit_base;\t/* Current JIT code L->base or NULL. */\n  MRef ctype_state;\t/* Pointer to C type state. */\n  GCRef gcroot[GCROOT_MAX];  /* GC roots. */\n} global_State;\n\n#define mainthread(g)\t(&gcref(g->mainthref)->th)\n#define niltv(L) \\\n  check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val)\n#define niltvg(g) \\\n  check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val)\n\n/* Hook management. Hook event masks are defined in lua.h. */\n#define HOOK_EVENTMASK\t\t0x0f\n#define HOOK_ACTIVE\t\t0x10\n#define HOOK_ACTIVE_SHIFT\t4\n#define HOOK_VMEVENT\t\t0x20\n#define HOOK_GC\t\t\t0x40\n#define HOOK_PROFILE\t\t0x80\n#define hook_active(g)\t\t((g)->hookmask & HOOK_ACTIVE)\n#define hook_enter(g)\t\t((g)->hookmask |= HOOK_ACTIVE)\n#define hook_entergc(g)\t\t((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC))\n#define hook_vmevent(g)\t\t((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))\n#define hook_leave(g)\t\t((g)->hookmask &= ~HOOK_ACTIVE)\n#define hook_save(g)\t\t((g)->hookmask & ~HOOK_EVENTMASK)\n#define hook_restore(g, h) \\\n  ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h))\n\n/* Per-thread state object. */\nstruct lua_State {\n  GCHeader;\n  uint8_t dummy_ffid;\t/* Fake FF_C for curr_funcisL() on dummy frames. */\n  uint8_t status;\t/* Thread status. */\n  MRef glref;\t\t/* Link to global state. */\n  GCRef gclist;\t\t/* GC chain. */\n  TValue *base;\t\t/* Base of currently executing function. */\n  TValue *top;\t\t/* First free slot in the stack. */\n  MRef maxstack;\t/* Last free slot in the stack. */\n  MRef stack;\t\t/* Stack base. */\n  GCRef openupval;\t/* List of open upvalues in the stack. */\n  GCRef env;\t\t/* Thread environment (table of globals). */\n  void *cframe;\t\t/* End of C stack frame chain. */\n  MSize stacksize;\t/* True stack size (incl. LJ_STACK_EXTRA). */\n};\n\n#define G(L)\t\t\t(mref(L->glref, global_State))\n#define registry(L)\t\t(&G(L)->registrytv)\n\n/* Macros to access the currently executing (Lua) function. */\n#if LJ_GC64\n#define curr_func(L)\t\t(&gcval(L->base-2)->fn)\n#elif LJ_FR2\n#define curr_func(L)\t\t(&gcref((L->base-2)->gcr)->fn)\n#else\n#define curr_func(L)\t\t(&gcref((L->base-1)->fr.func)->fn)\n#endif\n#define curr_funcisL(L)\t\t(isluafunc(curr_func(L)))\n#define curr_proto(L)\t\t(funcproto(curr_func(L)))\n#define curr_topL(L)\t\t(L->base + curr_proto(L)->framesize)\n#define curr_top(L)\t\t(curr_funcisL(L) ? curr_topL(L) : L->top)\n\n/* -- GC object definition and conversions -------------------------------- */\n\n/* GC header for generic access to common fields of GC objects. */\ntypedef struct GChead {\n  GCHeader;\n  uint8_t unused1;\n  uint8_t unused2;\n  GCRef env;\n  GCRef gclist;\n  GCRef metatable;\n} GChead;\n\n/* The env field SHOULD be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env));\nLJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env));\n\n/* The metatable field MUST be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable));\nLJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable));\n\n/* The gclist field MUST be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist));\n\ntypedef union GCobj {\n  GChead gch;\n  GCstr str;\n  GCupval uv;\n  lua_State th;\n  GCproto pt;\n  GCfunc fn;\n  GCcdata cd;\n  GCtab tab;\n  GCudata ud;\n} GCobj;\n\n/* Macros to convert a GCobj pointer into a specific value. */\n#define gco2str(o)\tcheck_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str)\n#define gco2uv(o)\tcheck_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv)\n#define gco2th(o)\tcheck_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th)\n#define gco2pt(o)\tcheck_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt)\n#define gco2func(o)\tcheck_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn)\n#define gco2cd(o)\tcheck_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd)\n#define gco2tab(o)\tcheck_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab)\n#define gco2ud(o)\tcheck_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)\n\n/* Macro to convert any collectable object into a GCobj pointer. */\n#define obj2gco(v)\t((GCobj *)(v))\n\n/* -- TValue getters/setters ---------------------------------------------- */\n\n#ifdef LUA_USE_ASSERT\n#include \"lj_gc.h\"\n#endif\n\n/* Macros to test types. */\n#if LJ_GC64\n#define itype(o)\t((uint32_t)((o)->it64 >> 47))\n#define tvisnil(o)\t((o)->it64 == -1)\n#else\n#define itype(o)\t((o)->it)\n#define tvisnil(o)\t(itype(o) == LJ_TNIL)\n#endif\n#define tvisfalse(o)\t(itype(o) == LJ_TFALSE)\n#define tvistrue(o)\t(itype(o) == LJ_TTRUE)\n#define tvisbool(o)\t(tvisfalse(o) || tvistrue(o))\n#if LJ_64 && !LJ_GC64\n#define tvislightud(o)\t(((int32_t)itype(o) >> 15) == -2)\n#else\n#define tvislightud(o)\t(itype(o) == LJ_TLIGHTUD)\n#endif\n#define tvisstr(o)\t(itype(o) == LJ_TSTR)\n#define tvisfunc(o)\t(itype(o) == LJ_TFUNC)\n#define tvisthread(o)\t(itype(o) == LJ_TTHREAD)\n#define tvisproto(o)\t(itype(o) == LJ_TPROTO)\n#define tviscdata(o)\t(itype(o) == LJ_TCDATA)\n#define tvistab(o)\t(itype(o) == LJ_TTAB)\n#define tvisudata(o)\t(itype(o) == LJ_TUDATA)\n#define tvisnumber(o)\t(itype(o) <= LJ_TISNUM)\n#define tvisint(o)\t(LJ_DUALNUM && itype(o) == LJ_TISNUM)\n#define tvisnum(o)\t(itype(o) < LJ_TISNUM)\n\n#define tvistruecond(o)\t(itype(o) < LJ_TISTRUECOND)\n#define tvispri(o)\t(itype(o) >= LJ_TISPRI)\n#define tvistabud(o)\t(itype(o) <= LJ_TISTABUD)  /* && !tvisnum() */\n#define tvisgcv(o)\t((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))\n\n/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */\n#define tvisnan(o)\t((o)->n != (o)->n)\n#if LJ_64\n#define tviszero(o)\t(((o)->u64 << 1) == 0)\n#else\n#define tviszero(o)\t(((o)->u32.lo | ((o)->u32.hi << 1)) == 0)\n#endif\n#define tvispzero(o)\t((o)->u64 == 0)\n#define tvismzero(o)\t((o)->u64 == U64x(80000000,00000000))\n#define tvispone(o)\t((o)->u64 == U64x(3ff00000,00000000))\n#define rawnumequal(o1, o2)\t((o1)->u64 == (o2)->u64)\n\n/* Macros to convert type ids. */\n#if LJ_64 && !LJ_GC64\n#define itypemap(o) \\\n  (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))\n#else\n#define itypemap(o)\t(tvisnumber(o) ? ~LJ_TNUMX : ~itype(o))\n#endif\n\n/* Macros to get tagged values. */\n#if LJ_GC64\n#define gcval(o)\t((GCobj *)(gcrefu((o)->gcr) & LJ_GCVMASK))\n#else\n#define gcval(o)\t(gcref((o)->gcr))\n#endif\n#define boolV(o)\tcheck_exp(tvisbool(o), (LJ_TFALSE - itype(o)))\n#if LJ_64\n#define lightudV(o) \\\n  check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff)))\n#else\n#define lightudV(o)\tcheck_exp(tvislightud(o), gcrefp((o)->gcr, void))\n#endif\n#define gcV(o)\t\tcheck_exp(tvisgcv(o), gcval(o))\n#define strV(o)\t\tcheck_exp(tvisstr(o), &gcval(o)->str)\n#define funcV(o)\tcheck_exp(tvisfunc(o), &gcval(o)->fn)\n#define threadV(o)\tcheck_exp(tvisthread(o), &gcval(o)->th)\n#define protoV(o)\tcheck_exp(tvisproto(o), &gcval(o)->pt)\n#define cdataV(o)\tcheck_exp(tviscdata(o), &gcval(o)->cd)\n#define tabV(o)\t\tcheck_exp(tvistab(o), &gcval(o)->tab)\n#define udataV(o)\tcheck_exp(tvisudata(o), &gcval(o)->ud)\n#define numV(o)\t\tcheck_exp(tvisnum(o), (o)->n)\n#define intV(o)\t\tcheck_exp(tvisint(o), (int32_t)(o)->i)\n\n/* Macros to set tagged values. */\n#if LJ_GC64\n#define setitype(o, i)\t\t((o)->it = ((i) << 15))\n#define setnilV(o)\t\t((o)->it64 = -1)\n#define setpriV(o, x)\t\t((o)->it64 = (int64_t)~((uint64_t)~(x)<<47))\n#define setboolV(o, x)\t\t((o)->it64 = (int64_t)~((uint64_t)((x)+1)<<47))\n#else\n#define setitype(o, i)\t\t((o)->it = (i))\n#define setnilV(o)\t\t((o)->it = LJ_TNIL)\n#define setboolV(o, x)\t\t((o)->it = LJ_TFALSE-(uint32_t)(x))\n#define setpriV(o, i)\t\t(setitype((o), (i)))\n#endif\n\nstatic LJ_AINLINE void setlightudV(TValue *o, void *p)\n{\n#if LJ_GC64\n  o->u64 = (uint64_t)p | (((uint64_t)LJ_TLIGHTUD) << 47);\n#elif LJ_64\n  o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);\n#else\n  setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);\n#endif\n}\n\n#if LJ_64\n#define checklightudptr(L, p) \\\n  (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))\n#else\n#define checklightudptr(L, p)\t(p)\n#endif\n\n#if LJ_FR2\n#define setcont(o, f)\t\t((o)->u64 = (uint64_t)(uintptr_t)(void *)(f))\n#elif LJ_64\n#define setcont(o, f) \\\n  ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)\n#else\n#define setcont(o, f)\t\tsetlightudV((o), (void *)(f))\n#endif\n\n#define tvchecklive(L, o) \\\n  UNUSED(L), lua_assert(!tvisgcv(o) || \\\n  ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o))))\n\nstatic LJ_AINLINE void setgcVraw(TValue *o, GCobj *v, uint32_t itype)\n{\n#if LJ_GC64\n  setgcreft(o->gcr, v, itype);\n#else\n  setgcref(o->gcr, v); setitype(o, itype);\n#endif\n}\n\nstatic LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t it)\n{\n  setgcVraw(o, v, it); tvchecklive(L, o);\n}\n\n#define define_setV(name, type, tag) \\\nstatic LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \\\n{ \\\n  setgcV(L, o, obj2gco(v), tag); \\\n}\ndefine_setV(setstrV, GCstr, LJ_TSTR)\ndefine_setV(setthreadV, lua_State, LJ_TTHREAD)\ndefine_setV(setprotoV, GCproto, LJ_TPROTO)\ndefine_setV(setfuncV, GCfunc, LJ_TFUNC)\ndefine_setV(setcdataV, GCcdata, LJ_TCDATA)\ndefine_setV(settabV, GCtab, LJ_TTAB)\ndefine_setV(setudataV, GCudata, LJ_TUDATA)\n\n#define setnumV(o, x)\t\t((o)->n = (x))\n#define setnanV(o)\t\t((o)->u64 = U64x(fff80000,00000000))\n#define setpinfV(o)\t\t((o)->u64 = U64x(7ff00000,00000000))\n#define setminfV(o)\t\t((o)->u64 = U64x(fff00000,00000000))\n\nstatic LJ_AINLINE void setintV(TValue *o, int32_t i)\n{\n#if LJ_DUALNUM\n  o->i = (uint32_t)i; setitype(o, LJ_TISNUM);\n#else\n  o->n = (lua_Number)i;\n#endif\n}\n\nstatic LJ_AINLINE void setint64V(TValue *o, int64_t i)\n{\n  if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))\n    setintV(o, (int32_t)i);\n  else\n    setnumV(o, (lua_Number)i);\n}\n\n#if LJ_64\n#define setintptrV(o, i)\tsetint64V((o), (i))\n#else\n#define setintptrV(o, i)\tsetintV((o), (i))\n#endif\n\n/* Copy tagged values. */\nstatic LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)\n{\n  *o1 = *o2; tvchecklive(L, o1);\n}\n\n/* -- Number to integer conversion ---------------------------------------- */\n\n#if LJ_SOFTFP\nLJ_ASMF int32_t lj_vm_tobit(double x);\n#endif\n\nstatic LJ_AINLINE int32_t lj_num2bit(lua_Number n)\n{\n#if LJ_SOFTFP\n  return lj_vm_tobit(n);\n#else\n  TValue o;\n  o.n = n + 6755399441055744.0;  /* 2^52 + 2^51 */\n  return (int32_t)o.u32.lo;\n#endif\n}\n\n#define lj_num2int(n)   ((int32_t)(n))\n\nstatic LJ_AINLINE uint64_t lj_num2u64(lua_Number n)\n{\n#ifdef _MSC_VER\n  if (n >= 9223372036854775808.0)  /* They think it's a feature. */\n    return (uint64_t)(int64_t)(n - 18446744073709551616.0);\n  else\n#endif\n    return (uint64_t)n;\n}\n\nstatic LJ_AINLINE int32_t numberVint(cTValue *o)\n{\n  if (LJ_LIKELY(tvisint(o)))\n    return intV(o);\n  else\n    return lj_num2int(numV(o));\n}\n\nstatic LJ_AINLINE lua_Number numberVnum(cTValue *o)\n{\n  if (LJ_UNLIKELY(tvisint(o)))\n    return (lua_Number)intV(o);\n  else\n    return numV(o);\n}\n\n/* -- Miscellaneous object handling --------------------------------------- */\n\n/* Names and maps for internal and external object tags. */\nLJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1];\nLJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];\n\n#define lj_typename(o)\t(lj_obj_itypename[itypemap(o)])\n\n/* Compare two objects without calling metamethods. */\nLJ_FUNC int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2);\nLJ_FUNC const void * LJ_FASTCALL lj_obj_ptr(cTValue *o);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_dce.c",
    "content": "/*\n** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_dce_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Scan through all snapshots and mark all referenced instructions. */\nstatic void dce_marksnap(jit_State *J)\n{\n  SnapNo i, nsnap = J->cur.nsnap;\n  for (i = 0; i < nsnap; i++) {\n    SnapShot *snap = &J->cur.snap[i];\n    SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n    MSize n, nent = snap->nent;\n    for (n = 0; n < nent; n++) {\n      IRRef ref = snap_ref(map[n]);\n      if (ref >= REF_FIRST)\n\tirt_setmark(IR(ref)->t);\n    }\n  }\n}\n\n/* Backwards propagate marks. Replace unused instructions with NOPs. */\nstatic void dce_propagate(jit_State *J)\n{\n  IRRef1 *pchain[IR__MAX];\n  IRRef ins;\n  uint32_t i;\n  for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i];\n  for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) {\n    IRIns *ir = IR(ins);\n    if (irt_ismarked(ir->t)) {\n      irt_clearmark(ir->t);\n      pchain[ir->o] = &ir->prev;\n    } else if (!ir_sideeff(ir)) {\n      *pchain[ir->o] = ir->prev;  /* Reroute original instruction chain. */\n      ir->t.irt = IRT_NIL;\n      ir->o = IR_NOP;  /* Replace instruction with NOP. */\n      ir->op1 = ir->op2 = 0;\n      ir->prev = 0;\n      continue;\n    }\n    if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);\n    if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);\n  }\n}\n\n/* Dead Code Elimination.\n**\n** First backpropagate marks for all used instructions. Then replace\n** the unused ones with a NOP. Note that compressing the IR to eliminate\n** the NOPs does not pay off.\n*/\nvoid lj_opt_dce(jit_State *J)\n{\n  if ((J->flags & JIT_F_OPT_DCE)) {\n    dce_marksnap(J);\n    dce_propagate(J);\n    memset(J->bpropcache, 0, sizeof(J->bpropcache));  /* Invalidate cache. */\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_fold.c",
    "content": "/*\n** FOLD: Constant Folding, Algebraic Simplifications and Reassociation.\n** ABCelim: Array Bounds Check Elimination.\n** CSE: Common-Subexpression Elimination.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_fold_c\n#define LUA_CORE\n\n#include <math.h>\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* Here's a short description how the FOLD engine processes instructions:\n**\n** The FOLD engine receives a single instruction stored in fins (J->fold.ins).\n** The instruction and its operands are used to select matching fold rules.\n** These are applied iteratively until a fixed point is reached.\n**\n** The 8 bit opcode of the instruction itself plus the opcodes of the\n** two instructions referenced by its operands form a 24 bit key\n** 'ins left right' (unused operands -> 0, literals -> lowest 8 bits).\n**\n** This key is used for partial matching against the fold rules. The\n** left/right operand fields of the key are successively masked with\n** the 'any' wildcard, from most specific to least specific:\n**\n**   ins left right\n**   ins any  right\n**   ins left any\n**   ins any  any\n**\n** The masked key is used to lookup a matching fold rule in a semi-perfect\n** hash table. If a matching rule is found, the related fold function is run.\n** Multiple rules can share the same fold function. A fold rule may return\n** one of several special values:\n**\n** - NEXTFOLD means no folding was applied, because an additional test\n**   inside the fold function failed. Matching continues against less\n**   specific fold rules. Finally the instruction is passed on to CSE.\n**\n** - RETRYFOLD means the instruction was modified in-place. Folding is\n**   retried as if this instruction had just been received.\n**\n** All other return values are terminal actions -- no further folding is\n** applied:\n**\n** - INTFOLD(i) returns a reference to the integer constant i.\n**\n** - LEFTFOLD and RIGHTFOLD return the left/right operand reference\n**   without emitting an instruction.\n**\n** - CSEFOLD and EMITFOLD pass the instruction directly to CSE or emit\n**   it without passing through any further optimizations.\n**\n** - FAILFOLD, DROPFOLD and CONDFOLD only apply to instructions which have\n**   no result (e.g. guarded assertions): FAILFOLD means the guard would\n**   always fail, i.e. the current trace is pointless. DROPFOLD means\n**   the guard is always true and has been eliminated. CONDFOLD is a\n**   shortcut for FAILFOLD + cond (i.e. drop if true, otherwise fail).\n**\n** - Any other return value is interpreted as an IRRef or TRef. This\n**   can be a reference to an existing or a newly created instruction.\n**   Only the least-significant 16 bits (IRRef1) are used to form a TRef\n**   which is finally returned to the caller.\n**\n** The FOLD engine receives instructions both from the trace recorder and\n** substituted instructions from LOOP unrolling. This means all types\n** of instructions may end up here, even though the recorder bypasses\n** FOLD in some cases. Thus all loads, stores and allocations must have\n** an any/any rule to avoid being passed on to CSE.\n**\n** Carefully read the following requirements before adding or modifying\n** any fold rules:\n**\n** Requirement #1: All fold rules must preserve their destination type.\n**\n** Consistently use INTFOLD() (KINT result) or lj_ir_knum() (KNUM result).\n** Never use lj_ir_knumint() which can have either a KINT or KNUM result.\n**\n** Requirement #2: Fold rules should not create *new* instructions which\n** reference operands *across* PHIs.\n**\n** E.g. a RETRYFOLD with 'fins->op1 = fleft->op1' is invalid if the\n** left operand is a PHI. Then fleft->op1 would point across the PHI\n** frontier to an invariant instruction. Adding a PHI for this instruction\n** would be counterproductive. The solution is to add a barrier which\n** prevents folding across PHIs, i.e. 'PHIBARRIER(fleft)' in this case.\n** The only exception is for recurrences with high latencies like\n** repeated int->num->int conversions.\n**\n** One could relax this condition a bit if the referenced instruction is\n** a PHI, too. But this often leads to worse code due to excessive\n** register shuffling.\n**\n** Note: returning *existing* instructions (e.g. LEFTFOLD) is ok, though.\n** Even returning fleft->op1 would be ok, because a new PHI will added,\n** if needed. But again, this leads to excessive register shuffling and\n** should be avoided.\n**\n** Requirement #3: The set of all fold rules must be monotonic to guarantee\n** termination.\n**\n** The goal is optimization, so one primarily wants to add strength-reducing\n** rules. This means eliminating an instruction or replacing an instruction\n** with one or more simpler instructions. Don't add fold rules which point\n** into the other direction.\n**\n** Some rules (like commutativity) do not directly reduce the strength of\n** an instruction, but enable other fold rules (e.g. by moving constants\n** to the right operand). These rules must be made unidirectional to avoid\n** cycles.\n**\n** Rule of thumb: the trace recorder expands the IR and FOLD shrinks it.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n#define fins\t\t(&J->fold.ins)\n#define fleft\t\t(&J->fold.left)\n#define fright\t\t(&J->fold.right)\n#define knumleft\t(ir_knum(fleft)->n)\n#define knumright\t(ir_knum(fright)->n)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Fold function type. Fastcall on x86 significantly reduces their size. */\ntypedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J);\n\n/* Macros for the fold specs, so buildvm can recognize them. */\n#define LJFOLD(x)\n#define LJFOLDX(x)\n#define LJFOLDF(name)\tstatic TRef LJ_FASTCALL fold_##name(jit_State *J)\n/* Note: They must be at the start of a line or buildvm ignores them! */\n\n/* Barrier to prevent using operands across PHIs. */\n#define PHIBARRIER(ir)\tif (irt_isphi((ir)->t)) return NEXTFOLD\n\n/* Barrier to prevent folding across a GC step.\n** GC steps can only happen at the head of a trace and at LOOP.\n** And the GC is only driven forward if there's at least one allocation.\n*/\n#define gcstep_barrier(J, ref) \\\n  ((ref) < J->chain[IR_LOOP] && \\\n   (J->chain[IR_SNEW] || J->chain[IR_XSNEW] || \\\n    J->chain[IR_TNEW] || J->chain[IR_TDUP] || \\\n    J->chain[IR_CNEW] || J->chain[IR_CNEWI] || \\\n    J->chain[IR_BUFSTR] || J->chain[IR_TOSTR] || J->chain[IR_CALLA]))\n\n/* -- Constant folding for FP numbers ------------------------------------- */\n\nLJFOLD(ADD KNUM KNUM)\nLJFOLD(SUB KNUM KNUM)\nLJFOLD(MUL KNUM KNUM)\nLJFOLD(DIV KNUM KNUM)\nLJFOLD(NEG KNUM KNUM)\nLJFOLD(ABS KNUM KNUM)\nLJFOLD(ATAN2 KNUM KNUM)\nLJFOLD(LDEXP KNUM KNUM)\nLJFOLD(MIN KNUM KNUM)\nLJFOLD(MAX KNUM KNUM)\nLJFOLDF(kfold_numarith)\n{\n  lua_Number a = knumleft;\n  lua_Number b = knumright;\n  lua_Number y = lj_vm_foldarith(a, b, fins->o - IR_ADD);\n  return lj_ir_knum(J, y);\n}\n\nLJFOLD(LDEXP KNUM KINT)\nLJFOLDF(kfold_ldexp)\n{\n#if LJ_TARGET_X86ORX64\n  UNUSED(J);\n  return NEXTFOLD;\n#else\n  return lj_ir_knum(J, ldexp(knumleft, fright->i));\n#endif\n}\n\nLJFOLD(FPMATH KNUM any)\nLJFOLDF(kfold_fpmath)\n{\n  lua_Number a = knumleft;\n  lua_Number y = lj_vm_foldfpm(a, fins->op2);\n  return lj_ir_knum(J, y);\n}\n\nLJFOLD(POW KNUM KINT)\nLJFOLDF(kfold_numpow)\n{\n  lua_Number a = knumleft;\n  lua_Number b = (lua_Number)fright->i;\n  lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD);\n  return lj_ir_knum(J, y);\n}\n\n/* Must not use kfold_kref for numbers (could be NaN). */\nLJFOLD(EQ KNUM KNUM)\nLJFOLD(NE KNUM KNUM)\nLJFOLD(LT KNUM KNUM)\nLJFOLD(GE KNUM KNUM)\nLJFOLD(LE KNUM KNUM)\nLJFOLD(GT KNUM KNUM)\nLJFOLD(ULT KNUM KNUM)\nLJFOLD(UGE KNUM KNUM)\nLJFOLD(ULE KNUM KNUM)\nLJFOLD(UGT KNUM KNUM)\nLJFOLDF(kfold_numcomp)\n{\n  return CONDFOLD(lj_ir_numcmp(knumleft, knumright, (IROp)fins->o));\n}\n\n/* -- Constant folding for 32 bit integers -------------------------------- */\n\nstatic int32_t kfold_intop(int32_t k1, int32_t k2, IROp op)\n{\n  switch (op) {\n  case IR_ADD: k1 += k2; break;\n  case IR_SUB: k1 -= k2; break;\n  case IR_MUL: k1 *= k2; break;\n  case IR_MOD: k1 = lj_vm_modi(k1, k2); break;\n  case IR_NEG: k1 = -k1; break;\n  case IR_BAND: k1 &= k2; break;\n  case IR_BOR: k1 |= k2; break;\n  case IR_BXOR: k1 ^= k2; break;\n  case IR_BSHL: k1 <<= (k2 & 31); break;\n  case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 31)); break;\n  case IR_BSAR: k1 >>= (k2 & 31); break;\n  case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 31)); break;\n  case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 31)); break;\n  case IR_MIN: k1 = k1 < k2 ? k1 : k2; break;\n  case IR_MAX: k1 = k1 > k2 ? k1 : k2; break;\n  default: lua_assert(0); break;\n  }\n  return k1;\n}\n\nLJFOLD(ADD KINT KINT)\nLJFOLD(SUB KINT KINT)\nLJFOLD(MUL KINT KINT)\nLJFOLD(MOD KINT KINT)\nLJFOLD(NEG KINT KINT)\nLJFOLD(BAND KINT KINT)\nLJFOLD(BOR KINT KINT)\nLJFOLD(BXOR KINT KINT)\nLJFOLD(BSHL KINT KINT)\nLJFOLD(BSHR KINT KINT)\nLJFOLD(BSAR KINT KINT)\nLJFOLD(BROL KINT KINT)\nLJFOLD(BROR KINT KINT)\nLJFOLD(MIN KINT KINT)\nLJFOLD(MAX KINT KINT)\nLJFOLDF(kfold_intarith)\n{\n  return INTFOLD(kfold_intop(fleft->i, fright->i, (IROp)fins->o));\n}\n\nLJFOLD(ADDOV KINT KINT)\nLJFOLD(SUBOV KINT KINT)\nLJFOLD(MULOV KINT KINT)\nLJFOLDF(kfold_intovarith)\n{\n  lua_Number n = lj_vm_foldarith((lua_Number)fleft->i, (lua_Number)fright->i,\n\t\t\t\t fins->o - IR_ADDOV);\n  int32_t k = lj_num2int(n);\n  if (n != (lua_Number)k)\n    return FAILFOLD;\n  return INTFOLD(k);\n}\n\nLJFOLD(BNOT KINT)\nLJFOLDF(kfold_bnot)\n{\n  return INTFOLD(~fleft->i);\n}\n\nLJFOLD(BSWAP KINT)\nLJFOLDF(kfold_bswap)\n{\n  return INTFOLD((int32_t)lj_bswap((uint32_t)fleft->i));\n}\n\nLJFOLD(LT KINT KINT)\nLJFOLD(GE KINT KINT)\nLJFOLD(LE KINT KINT)\nLJFOLD(GT KINT KINT)\nLJFOLD(ULT KINT KINT)\nLJFOLD(UGE KINT KINT)\nLJFOLD(ULE KINT KINT)\nLJFOLD(UGT KINT KINT)\nLJFOLD(ABC KINT KINT)\nLJFOLDF(kfold_intcomp)\n{\n  int32_t a = fleft->i, b = fright->i;\n  switch ((IROp)fins->o) {\n  case IR_LT: return CONDFOLD(a < b);\n  case IR_GE: return CONDFOLD(a >= b);\n  case IR_LE: return CONDFOLD(a <= b);\n  case IR_GT: return CONDFOLD(a > b);\n  case IR_ULT: return CONDFOLD((uint32_t)a < (uint32_t)b);\n  case IR_UGE: return CONDFOLD((uint32_t)a >= (uint32_t)b);\n  case IR_ULE: return CONDFOLD((uint32_t)a <= (uint32_t)b);\n  case IR_ABC:\n  case IR_UGT: return CONDFOLD((uint32_t)a > (uint32_t)b);\n  default: lua_assert(0); return FAILFOLD;\n  }\n}\n\nLJFOLD(UGE any KINT)\nLJFOLDF(kfold_intcomp0)\n{\n  if (fright->i == 0)\n    return DROPFOLD;\n  return NEXTFOLD;\n}\n\n/* -- Constant folding for 64 bit integers -------------------------------- */\n\nstatic uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op)\n{\n  switch (op) {\n#if LJ_HASFFI\n  case IR_ADD: k1 += k2; break;\n  case IR_SUB: k1 -= k2; break;\n  case IR_MUL: k1 *= k2; break;\n  case IR_BAND: k1 &= k2; break;\n  case IR_BOR: k1 |= k2; break;\n  case IR_BXOR: k1 ^= k2; break;\n#endif\n  default: UNUSED(k2); lua_assert(0); break;\n  }\n  return k1;\n}\n\nLJFOLD(ADD KINT64 KINT64)\nLJFOLD(SUB KINT64 KINT64)\nLJFOLD(MUL KINT64 KINT64)\nLJFOLD(BAND KINT64 KINT64)\nLJFOLD(BOR KINT64 KINT64)\nLJFOLD(BXOR KINT64 KINT64)\nLJFOLDF(kfold_int64arith)\n{\n  return INT64FOLD(kfold_int64arith(ir_k64(fleft)->u64,\n\t\t\t\t    ir_k64(fright)->u64, (IROp)fins->o));\n}\n\nLJFOLD(DIV KINT64 KINT64)\nLJFOLD(MOD KINT64 KINT64)\nLJFOLD(POW KINT64 KINT64)\nLJFOLDF(kfold_int64arith2)\n{\n#if LJ_HASFFI\n  uint64_t k1 = ir_k64(fleft)->u64, k2 = ir_k64(fright)->u64;\n  if (irt_isi64(fins->t)) {\n    k1 = fins->o == IR_DIV ? lj_carith_divi64((int64_t)k1, (int64_t)k2) :\n\t fins->o == IR_MOD ? lj_carith_modi64((int64_t)k1, (int64_t)k2) :\n\t\t\t     lj_carith_powi64((int64_t)k1, (int64_t)k2);\n  } else {\n    k1 = fins->o == IR_DIV ? lj_carith_divu64(k1, k2) :\n\t fins->o == IR_MOD ? lj_carith_modu64(k1, k2) :\n\t\t\t     lj_carith_powu64(k1, k2);\n  }\n  return INT64FOLD(k1);\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BSHL KINT64 KINT)\nLJFOLD(BSHR KINT64 KINT)\nLJFOLD(BSAR KINT64 KINT)\nLJFOLD(BROL KINT64 KINT)\nLJFOLD(BROR KINT64 KINT)\nLJFOLDF(kfold_int64shift)\n{\n#if LJ_HASFFI\n  uint64_t k = ir_k64(fleft)->u64;\n  int32_t sh = (fright->i & 63);\n  return INT64FOLD(lj_carith_shift64(k, sh, fins->o - IR_BSHL));\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BNOT KINT64)\nLJFOLDF(kfold_bnot64)\n{\n#if LJ_HASFFI\n  return INT64FOLD(~ir_k64(fleft)->u64);\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BSWAP KINT64)\nLJFOLDF(kfold_bswap64)\n{\n#if LJ_HASFFI\n  return INT64FOLD(lj_bswap64(ir_k64(fleft)->u64));\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(LT KINT64 KINT64)\nLJFOLD(GE KINT64 KINT64)\nLJFOLD(LE KINT64 KINT64)\nLJFOLD(GT KINT64 KINT64)\nLJFOLD(ULT KINT64 KINT64)\nLJFOLD(UGE KINT64 KINT64)\nLJFOLD(ULE KINT64 KINT64)\nLJFOLD(UGT KINT64 KINT64)\nLJFOLDF(kfold_int64comp)\n{\n#if LJ_HASFFI\n  uint64_t a = ir_k64(fleft)->u64, b = ir_k64(fright)->u64;\n  switch ((IROp)fins->o) {\n  case IR_LT: return CONDFOLD(a < b);\n  case IR_GE: return CONDFOLD(a >= b);\n  case IR_LE: return CONDFOLD(a <= b);\n  case IR_GT: return CONDFOLD(a > b);\n  case IR_ULT: return CONDFOLD((uint64_t)a < (uint64_t)b);\n  case IR_UGE: return CONDFOLD((uint64_t)a >= (uint64_t)b);\n  case IR_ULE: return CONDFOLD((uint64_t)a <= (uint64_t)b);\n  case IR_UGT: return CONDFOLD((uint64_t)a > (uint64_t)b);\n  default: lua_assert(0); return FAILFOLD;\n  }\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(UGE any KINT64)\nLJFOLDF(kfold_int64comp0)\n{\n#if LJ_HASFFI\n  if (ir_k64(fright)->u64 == 0)\n    return DROPFOLD;\n  return NEXTFOLD;\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\n/* -- Constant folding for strings ---------------------------------------- */\n\nLJFOLD(SNEW KKPTR KINT)\nLJFOLDF(kfold_snew_kptr)\n{\n  GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i);\n  return lj_ir_kstr(J, s);\n}\n\nLJFOLD(SNEW any KINT)\nLJFOLDF(kfold_snew_empty)\n{\n  if (fright->i == 0)\n    return lj_ir_kstr(J, &J2G(J)->strempty);\n  return NEXTFOLD;\n}\n\nLJFOLD(STRREF KGC KINT)\nLJFOLDF(kfold_strref)\n{\n  GCstr *str = ir_kstr(fleft);\n  lua_assert((MSize)fright->i <= str->len);\n  return lj_ir_kkptr(J, (char *)strdata(str) + fright->i);\n}\n\nLJFOLD(STRREF SNEW any)\nLJFOLDF(kfold_strref_snew)\n{\n  PHIBARRIER(fleft);\n  if (irref_isk(fins->op2) && fright->i == 0) {\n    return fleft->op1;  /* strref(snew(ptr, len), 0) ==> ptr */\n  } else {\n    /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */\n    IRIns *ir = IR(fleft->op1);\n    if (ir->o == IR_STRREF) {\n      IRRef1 str = ir->op1;  /* IRIns * is not valid across emitir. */\n      PHIBARRIER(ir);\n      fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */\n      fins->op1 = str;\n      fins->ot = IRT(IR_STRREF, IRT_P32);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CALLN CARG IRCALL_lj_str_cmp)\nLJFOLDF(kfold_strcmp)\n{\n  if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) {\n    GCstr *a = ir_kstr(IR(fleft->op1));\n    GCstr *b = ir_kstr(IR(fleft->op2));\n    return INTFOLD(lj_str_cmp(a, b));\n  }\n  return NEXTFOLD;\n}\n\n/* -- Constant folding and forwarding for buffers ------------------------- */\n\n/*\n** Buffer ops perform stores, but their effect is limited to the buffer\n** itself. Also, buffer ops are chained: a use of an op implies a use of\n** all other ops up the chain. Conversely, if an op is unused, all ops\n** up the chain can go unsed. This largely eliminates the need to treat\n** them as stores.\n**\n** Alas, treating them as normal (IRM_N) ops doesn't work, because they\n** cannot be CSEd in isolation. CSE for IRM_N is implicitly done in LOOP\n** or if FOLD is disabled.\n**\n** The compromise is to declare them as loads, emit them like stores and\n** CSE whole chains manually when the BUFSTR is to be emitted. Any chain\n** fragments left over from CSE are eliminated by DCE.\n*/\n\n/* BUFHDR is emitted like a store, see below. */\n\nLJFOLD(BUFPUT BUFHDR BUFSTR)\nLJFOLDF(bufput_append)\n{\n  /* New buffer, no other buffer op inbetween and same buffer? */\n  if ((J->flags & JIT_F_OPT_FWD) &&\n      !(fleft->op2 & IRBUFHDR_APPEND) &&\n      fleft->prev == fright->op2 &&\n      fleft->op1 == IR(fright->op2)->op1) {\n    IRRef ref = fins->op1;\n    IR(ref)->op2 = (fleft->op2 | IRBUFHDR_APPEND);  /* Modify BUFHDR. */\n    IR(ref)->op1 = fright->op1;\n    return ref;\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(BUFPUT any any)\nLJFOLDF(bufput_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && fright->o == IR_KGC) {\n    GCstr *s2 = ir_kstr(fright);\n    if (s2->len == 0) {  /* Empty string? */\n      return LEFTFOLD;\n    } else {\n      if (fleft->o == IR_BUFPUT && irref_isk(fleft->op2) &&\n\t  !irt_isphi(fleft->t)) {  /* Join two constant string puts in a row. */\n\tGCstr *s1 = ir_kstr(IR(fleft->op2));\n\tIRRef kref = lj_ir_kstr(J, lj_buf_cat2str(J->L, s1, s2));\n\t/* lj_ir_kstr() may realloc the IR and invalidates any IRIns *. */\n\tIR(fins->op1)->op2 = kref;  /* Modify previous BUFPUT. */\n\treturn fins->op1;\n      }\n    }\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(BUFSTR any any)\nLJFOLDF(bufstr_kfold_cse)\n{\n  lua_assert(fleft->o == IR_BUFHDR || fleft->o == IR_BUFPUT ||\n\t     fleft->o == IR_CALLL);\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    if (fleft->o == IR_BUFHDR) {  /* No put operations? */\n      if (!(fleft->op2 & IRBUFHDR_APPEND))  /* Empty buffer? */\n\treturn lj_ir_kstr(J, &J2G(J)->strempty);\n      fins->op1 = fleft->op1;\n      fins->op2 = fleft->prev;  /* Relies on checks in bufput_append. */\n      return CSEFOLD;\n    } else if (fleft->o == IR_BUFPUT) {\n      IRIns *irb = IR(fleft->op1);\n      if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND))\n\treturn fleft->op2;  /* Shortcut for a single put operation. */\n    }\n  }\n  /* Try to CSE the whole chain. */\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef ref = J->chain[IR_BUFSTR];\n    while (ref) {\n      IRIns *irs = IR(ref), *ira = fleft, *irb = IR(irs->op1);\n      while (ira->o == irb->o && ira->op2 == irb->op2) {\n\tlua_assert(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||\n\t\t   ira->o == IR_CALLL || ira->o == IR_CARG);\n\tif (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND))\n\t  return ref;  /* CSE succeeded. */\n\tif (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)\n\t  break;\n\tira = IR(ira->op1);\n\tirb = IR(irb->op1);\n      }\n      ref = irs->prev;\n    }\n  }\n  return EMITFOLD;  /* No CSE possible. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_reverse)\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_upper)\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_lower)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putquoted)\nLJFOLDF(bufput_kfold_op)\n{\n  if (irref_isk(fleft->op2)) {\n    const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n    SBuf *sb = lj_buf_tmp_(J->L);\n    sb = ((SBuf * (LJ_FASTCALL *)(SBuf *, GCstr *))ci->func)(sb,\n\t\t\t\t\t\t       ir_kstr(IR(fleft->op2)));\n    fins->o = IR_BUFPUT;\n    fins->op1 = fleft->op1;\n    fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n    return RETRYFOLD;\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_rep)\nLJFOLDF(bufput_kfold_rep)\n{\n  if (irref_isk(fleft->op2)) {\n    IRIns *irc = IR(fleft->op1);\n    if (irref_isk(irc->op2)) {\n      SBuf *sb = lj_buf_tmp_(J->L);\n      sb = lj_buf_putstr_rep(sb, ir_kstr(IR(irc->op2)), IR(fleft->op2)->i);\n      fins->o = IR_BUFPUT;\n      fins->op1 = irc->op1;\n      fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n      return RETRYFOLD;\n    }\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfxint)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum_int)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum_uint)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfstr)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfchar)\nLJFOLDF(bufput_kfold_fmt)\n{\n  IRIns *irc = IR(fleft->op1);\n  lua_assert(irref_isk(irc->op2));  /* SFormat must be const. */\n  if (irref_isk(fleft->op2)) {\n    SFormat sf = (SFormat)IR(irc->op2)->i;\n    IRIns *ira = IR(fleft->op2);\n    SBuf *sb = lj_buf_tmp_(J->L);\n    switch (fins->op2) {\n    case IRCALL_lj_strfmt_putfxint:\n      sb = lj_strfmt_putfxint(sb, sf, ir_k64(ira)->u64);\n      break;\n    case IRCALL_lj_strfmt_putfstr:\n      sb = lj_strfmt_putfstr(sb, sf, ir_kstr(ira));\n      break;\n    case IRCALL_lj_strfmt_putfchar:\n      sb = lj_strfmt_putfchar(sb, sf, ira->i);\n      break;\n    case IRCALL_lj_strfmt_putfnum_int:\n    case IRCALL_lj_strfmt_putfnum_uint:\n    case IRCALL_lj_strfmt_putfnum:\n    default: {\n      const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n      sb = ((SBuf * (*)(SBuf *, SFormat, lua_Number))ci->func)(sb, sf,\n\t\t\t\t\t\t\t ir_knum(ira)->n);\n      break;\n      }\n    }\n    fins->o = IR_BUFPUT;\n    fins->op1 = irc->op1;\n    fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n    return RETRYFOLD;\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\n/* -- Constant folding of pointer arithmetic ------------------------------ */\n\nLJFOLD(ADD KGC KINT)\nLJFOLD(ADD KGC KINT64)\nLJFOLDF(kfold_add_kgc)\n{\n  GCobj *o = ir_kgc(fleft);\n#if LJ_64\n  ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;\n#else\n  ptrdiff_t ofs = fright->i;\n#endif\n#if LJ_HASFFI\n  if (irt_iscdata(fleft->t)) {\n    CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid);\n    if (ctype_isnum(ct->info) || ctype_isenum(ct->info) ||\n\tctype_isptr(ct->info) || ctype_isfunc(ct->info) ||\n\tctype_iscomplex(ct->info) || ctype_isvector(ct->info))\n      return lj_ir_kkptr(J, (char *)o + ofs);\n  }\n#endif\n  return lj_ir_kptr(J, (char *)o + ofs);\n}\n\nLJFOLD(ADD KPTR KINT)\nLJFOLD(ADD KPTR KINT64)\nLJFOLD(ADD KKPTR KINT)\nLJFOLD(ADD KKPTR KINT64)\nLJFOLDF(kfold_add_kptr)\n{\n  void *p = ir_kptr(fleft);\n#if LJ_64\n  ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;\n#else\n  ptrdiff_t ofs = fright->i;\n#endif\n  return lj_ir_kptr_(J, fleft->o, (char *)p + ofs);\n}\n\nLJFOLD(ADD any KGC)\nLJFOLD(ADD any KPTR)\nLJFOLD(ADD any KKPTR)\nLJFOLDF(kfold_add_kright)\n{\n  if (fleft->o == IR_KINT || fleft->o == IR_KINT64) {\n    IRRef1 tmp = fins->op1; fins->op1 = fins->op2; fins->op2 = tmp;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* -- Constant folding of conversions ------------------------------------- */\n\nLJFOLD(TOBIT KNUM KNUM)\nLJFOLDF(kfold_tobit)\n{\n  return INTFOLD(lj_num2bit(knumleft));\n}\n\nLJFOLD(CONV KINT IRCONV_NUM_INT)\nLJFOLDF(kfold_conv_kint_num)\n{\n  return lj_ir_knum(J, (lua_Number)fleft->i);\n}\n\nLJFOLD(CONV KINT IRCONV_NUM_U32)\nLJFOLDF(kfold_conv_kintu32_num)\n{\n  return lj_ir_knum(J, (lua_Number)(uint32_t)fleft->i);\n}\n\nLJFOLD(CONV KINT IRCONV_INT_I8)\nLJFOLD(CONV KINT IRCONV_INT_U8)\nLJFOLD(CONV KINT IRCONV_INT_I16)\nLJFOLD(CONV KINT IRCONV_INT_U16)\nLJFOLDF(kfold_conv_kint_ext)\n{\n  int32_t k = fleft->i;\n  if ((fins->op2 & IRCONV_SRCMASK) == IRT_I8) k = (int8_t)k;\n  else if ((fins->op2 & IRCONV_SRCMASK) == IRT_U8) k = (uint8_t)k;\n  else if ((fins->op2 & IRCONV_SRCMASK) == IRT_I16) k = (int16_t)k;\n  else k = (uint16_t)k;\n  return INTFOLD(k);\n}\n\nLJFOLD(CONV KINT IRCONV_I64_INT)\nLJFOLD(CONV KINT IRCONV_U64_INT)\nLJFOLD(CONV KINT IRCONV_I64_U32)\nLJFOLD(CONV KINT IRCONV_U64_U32)\nLJFOLDF(kfold_conv_kint_i64)\n{\n  if ((fins->op2 & IRCONV_SEXT))\n    return INT64FOLD((uint64_t)(int64_t)fleft->i);\n  else\n    return INT64FOLD((uint64_t)(int64_t)(uint32_t)fleft->i);\n}\n\nLJFOLD(CONV KINT64 IRCONV_NUM_I64)\nLJFOLDF(kfold_conv_kint64_num_i64)\n{\n  return lj_ir_knum(J, (lua_Number)(int64_t)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KINT64 IRCONV_NUM_U64)\nLJFOLDF(kfold_conv_kint64_num_u64)\n{\n  return lj_ir_knum(J, (lua_Number)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KINT64 IRCONV_INT_I64)\nLJFOLD(CONV KINT64 IRCONV_U32_I64)\nLJFOLDF(kfold_conv_kint64_int_i64)\n{\n  return INTFOLD((int32_t)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KNUM IRCONV_INT_NUM)\nLJFOLDF(kfold_conv_knum_int_num)\n{\n  lua_Number n = knumleft;\n  int32_t k = lj_num2int(n);\n  if (irt_isguard(fins->t) && n != (lua_Number)k) {\n    /* We're about to create a guard which always fails, like CONV +1.5.\n    ** Some pathological loops cause this during LICM, e.g.:\n    **   local x,k,t = 0,1.5,{1,[1.5]=2}\n    **   for i=1,200 do x = x+ t[k]; k = k == 1 and 1.5 or 1 end\n    **   assert(x == 300)\n    */\n    return FAILFOLD;\n  }\n  return INTFOLD(k);\n}\n\nLJFOLD(CONV KNUM IRCONV_U32_NUM)\nLJFOLDF(kfold_conv_knum_u32_num)\n{\n#ifdef _MSC_VER\n  {  /* Workaround for MSVC bug. */\n    volatile uint32_t u = (uint32_t)knumleft;\n    return INTFOLD((int32_t)u);\n  }\n#else\n  return INTFOLD((int32_t)(uint32_t)knumleft);\n#endif\n}\n\nLJFOLD(CONV KNUM IRCONV_I64_NUM)\nLJFOLDF(kfold_conv_knum_i64_num)\n{\n  return INT64FOLD((uint64_t)(int64_t)knumleft);\n}\n\nLJFOLD(CONV KNUM IRCONV_U64_NUM)\nLJFOLDF(kfold_conv_knum_u64_num)\n{\n  return INT64FOLD(lj_num2u64(knumleft));\n}\n\nLJFOLD(TOSTR KNUM any)\nLJFOLDF(kfold_tostr_knum)\n{\n  return lj_ir_kstr(J, lj_strfmt_num(J->L, ir_knum(fleft)));\n}\n\nLJFOLD(TOSTR KINT any)\nLJFOLDF(kfold_tostr_kint)\n{\n  return lj_ir_kstr(J, fins->op2 == IRTOSTR_INT ?\n\t\t       lj_strfmt_int(J->L, fleft->i) :\n\t\t       lj_strfmt_char(J->L, fleft->i));\n}\n\nLJFOLD(STRTO KGC)\nLJFOLDF(kfold_strto)\n{\n  TValue n;\n  if (lj_strscan_num(ir_kstr(fleft), &n))\n    return lj_ir_knum(J, numV(&n));\n  return FAILFOLD;\n}\n\n/* -- Constant folding of equality checks --------------------------------- */\n\n/* Don't constant-fold away FLOAD checks against KNULL. */\nLJFOLD(EQ FLOAD KNULL)\nLJFOLD(NE FLOAD KNULL)\nLJFOLDX(lj_opt_cse)\n\n/* But fold all other KNULL compares, since only KNULL is equal to KNULL. */\nLJFOLD(EQ any KNULL)\nLJFOLD(NE any KNULL)\nLJFOLD(EQ KNULL any)\nLJFOLD(NE KNULL any)\nLJFOLD(EQ KINT KINT)  /* Constants are unique, so same refs <==> same value. */\nLJFOLD(NE KINT KINT)\nLJFOLD(EQ KINT64 KINT64)\nLJFOLD(NE KINT64 KINT64)\nLJFOLD(EQ KGC KGC)\nLJFOLD(NE KGC KGC)\nLJFOLDF(kfold_kref)\n{\n  return CONDFOLD((fins->op1 == fins->op2) ^ (fins->o == IR_NE));\n}\n\n/* -- Algebraic shortcuts ------------------------------------------------- */\n\nLJFOLD(FPMATH FPMATH IRFPM_FLOOR)\nLJFOLD(FPMATH FPMATH IRFPM_CEIL)\nLJFOLD(FPMATH FPMATH IRFPM_TRUNC)\nLJFOLDF(shortcut_round)\n{\n  IRFPMathOp op = (IRFPMathOp)fleft->op2;\n  if (op == IRFPM_FLOOR || op == IRFPM_CEIL || op == IRFPM_TRUNC)\n    return LEFTFOLD;  /* round(round_left(x)) = round_left(x) */\n  return NEXTFOLD;\n}\n\nLJFOLD(ABS ABS KNUM)\nLJFOLDF(shortcut_left)\n{\n  return LEFTFOLD;  /* f(g(x)) ==> g(x) */\n}\n\nLJFOLD(ABS NEG KNUM)\nLJFOLDF(shortcut_dropleft)\n{\n  PHIBARRIER(fleft);\n  fins->op1 = fleft->op1;  /* abs(neg(x)) ==> abs(x) */\n  return RETRYFOLD;\n}\n\n/* Note: no safe shortcuts with STRTO and TOSTR (\"1e2\" ==> +100 ==> \"100\"). */\nLJFOLD(NEG NEG any)\nLJFOLD(BNOT BNOT)\nLJFOLD(BSWAP BSWAP)\nLJFOLDF(shortcut_leftleft)\n{\n  PHIBARRIER(fleft);  /* See above. Fold would be ok, but not beneficial. */\n  return fleft->op1;  /* f(g(x)) ==> x */\n}\n\n/* -- FP algebraic simplifications ---------------------------------------- */\n\n/* FP arithmetic is tricky -- there's not much to simplify.\n** Please note the following common pitfalls before sending \"improvements\":\n**   x+0 ==> x  is INVALID for x=-0\n**   0-x ==> -x is INVALID for x=+0\n**   x*0 ==> 0  is INVALID for x=-0, x=+-Inf or x=NaN\n*/\n\nLJFOLD(ADD NEG any)\nLJFOLDF(simplify_numadd_negx)\n{\n  PHIBARRIER(fleft);\n  fins->o = IR_SUB;  /* (-a) + b ==> b - a */\n  fins->op1 = fins->op2;\n  fins->op2 = fleft->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(ADD any NEG)\nLJFOLDF(simplify_numadd_xneg)\n{\n  PHIBARRIER(fright);\n  fins->o = IR_SUB;  /* a + (-b) ==> a - b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB any KNUM)\nLJFOLDF(simplify_numsub_k)\n{\n  lua_Number n = knumright;\n  if (n == 0.0)  /* x - (+-0) ==> x */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB NEG KNUM)\nLJFOLDF(simplify_numsub_negk)\n{\n  PHIBARRIER(fleft);\n  fins->op2 = fleft->op1;  /* (-x) - k ==> (-k) - x */\n  fins->op1 = (IRRef1)lj_ir_knum(J, -knumright);\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB any NEG)\nLJFOLDF(simplify_numsub_xneg)\n{\n  PHIBARRIER(fright);\n  fins->o = IR_ADD;  /* a - (-b) ==> a + b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(MUL any KNUM)\nLJFOLD(DIV any KNUM)\nLJFOLDF(simplify_nummuldiv_k)\n{\n  lua_Number n = knumright;\n  if (n == 1.0) {  /* x o 1 ==> x */\n    return LEFTFOLD;\n  } else if (n == -1.0) {  /* x o -1 ==> -x */\n    fins->o = IR_NEG;\n    fins->op2 = (IRRef1)lj_ir_knum_neg(J);\n    return RETRYFOLD;\n  } else if (fins->o == IR_MUL && n == 2.0) {  /* x * 2 ==> x + x */\n    fins->o = IR_ADD;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  } else if (fins->o == IR_DIV) {  /* x / 2^k ==> x * 2^-k */\n    uint64_t u = ir_knum(fright)->u64;\n    uint32_t ex = ((uint32_t)(u >> 52) & 0x7ff);\n    if ((u & U64x(000fffff,ffffffff)) == 0 && ex - 1 < 0x7fd) {\n      u = (u & ((uint64_t)1 << 63)) | ((uint64_t)(0x7fe - ex) << 52);\n      fins->o = IR_MUL;  /* Multiply by exact reciprocal. */\n      fins->op2 = lj_ir_knum_u64(J, u);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL NEG KNUM)\nLJFOLD(DIV NEG KNUM)\nLJFOLDF(simplify_nummuldiv_negk)\n{\n  PHIBARRIER(fleft);\n  fins->op1 = fleft->op1;  /* (-a) o k ==> a o (-k) */\n  fins->op2 = (IRRef1)lj_ir_knum(J, -knumright);\n  return RETRYFOLD;\n}\n\nLJFOLD(MUL NEG NEG)\nLJFOLD(DIV NEG NEG)\nLJFOLDF(simplify_nummuldiv_negneg)\n{\n  PHIBARRIER(fleft);\n  PHIBARRIER(fright);\n  fins->op1 = fleft->op1;  /* (-a) o (-b) ==> a o b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(POW any KINT)\nLJFOLDF(simplify_numpow_xk)\n{\n  int32_t k = fright->i;\n  TRef ref = fins->op1;\n  if (k == 0)  /* x ^ 0 ==> 1 */\n    return lj_ir_knum_one(J);  /* Result must be a number, not an int. */\n  if (k == 1)  /* x ^ 1 ==> x */\n    return LEFTFOLD;\n  if ((uint32_t)(k+65536) > 2*65536u)  /* Limit code explosion. */\n    return NEXTFOLD;\n  if (k < 0) {  /* x ^ (-k) ==> (1/x) ^ k. */\n    ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref);\n    k = -k;\n  }\n  /* Unroll x^k for 1 <= k <= 65536. */\n  for (; (k & 1) == 0; k >>= 1)  /* Handle leading zeros. */\n    ref = emitir(IRTN(IR_MUL), ref, ref);\n  if ((k >>= 1) != 0) {  /* Handle trailing bits. */\n    TRef tmp = emitir(IRTN(IR_MUL), ref, ref);\n    for (; k != 1; k >>= 1) {\n      if (k & 1)\n\tref = emitir(IRTN(IR_MUL), ref, tmp);\n      tmp = emitir(IRTN(IR_MUL), tmp, tmp);\n    }\n    ref = emitir(IRTN(IR_MUL), ref, tmp);\n  }\n  return ref;\n}\n\nLJFOLD(POW KNUM any)\nLJFOLDF(simplify_numpow_kx)\n{\n  lua_Number n = knumleft;\n  if (n == 2.0) {  /* 2.0 ^ i ==> ldexp(1.0, tonum(i)) */\n    fins->o = IR_CONV;\n#if LJ_TARGET_X86ORX64\n    fins->op1 = fins->op2;\n    fins->op2 = IRCONV_NUM_INT;\n    fins->op2 = (IRRef1)lj_opt_fold(J);\n#endif\n    fins->op1 = (IRRef1)lj_ir_knum_one(J);\n    fins->o = IR_LDEXP;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* -- Simplify conversions ------------------------------------------------ */\n\nLJFOLD(CONV CONV IRCONV_NUM_INT)  /* _NUM */\nLJFOLDF(shortcut_conv_num_int)\n{\n  PHIBARRIER(fleft);\n  /* Only safe with a guarded conversion to int. */\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_NUM && irt_isguard(fleft->t))\n    return fleft->op1;  /* f(g(x)) ==> x */\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_INT_NUM)  /* _INT */\nLJFOLD(CONV CONV IRCONV_U32_NUM)  /* _U32*/\nLJFOLDF(simplify_conv_int_num)\n{\n  /* Fold even across PHI to avoid expensive num->int conversions in loop. */\n  if ((fleft->op2 & IRCONV_SRCMASK) ==\n      ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH))\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_I64_NUM)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U64_NUM)  /* _INT or _U32 */\nLJFOLDF(simplify_conv_i64_num)\n{\n  PHIBARRIER(fleft);\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    /* Reduce to a sign-extension. */\n    fins->op1 = fleft->op1;\n    fins->op2 = ((IRT_I64<<5)|IRT_INT|IRCONV_SEXT);\n    return RETRYFOLD;\n  } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {\n#if LJ_TARGET_X64\n    return fleft->op1;\n#else\n    /* Reduce to a zero-extension. */\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRT_I64<<5)|IRT_U32;\n    return RETRYFOLD;\n#endif\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_INT_I64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_INT_U64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U32_I64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U32_U64)  /* _INT or _U32 */\nLJFOLDF(simplify_conv_int_i64)\n{\n  int src;\n  PHIBARRIER(fleft);\n  src = (fleft->op2 & IRCONV_SRCMASK);\n  if (src == IRT_INT || src == IRT_U32) {\n    if (src == ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) {\n      return fleft->op1;\n    } else {\n      fins->op2 = ((fins->op2 & IRCONV_DSTMASK) | src);\n      fins->op1 = fleft->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_FLOAT_NUM)  /* _FLOAT */\nLJFOLDF(simplify_conv_flt_num)\n{\n  PHIBARRIER(fleft);\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_FLOAT)\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\n/* Shortcut TOBIT + IRT_NUM <- IRT_INT/IRT_U32 conversion. */\nLJFOLD(TOBIT CONV KNUM)\nLJFOLDF(simplify_tobit_conv)\n{\n  /* Fold even across PHI to avoid expensive num->int conversions in loop. */\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    lua_assert(irt_isnum(fleft->t));\n    return fleft->op1;\n  } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {\n    lua_assert(irt_isnum(fleft->t));\n    fins->o = IR_CONV;\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRT_INT<<5)|IRT_U32;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */\nLJFOLD(FPMATH CONV IRFPM_FLOOR)\nLJFOLD(FPMATH CONV IRFPM_CEIL)\nLJFOLD(FPMATH CONV IRFPM_TRUNC)\nLJFOLDF(simplify_floor_conv)\n{\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT ||\n      (fleft->op2 & IRCONV_SRCMASK) == IRT_U32)\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\n/* Strength reduction of widening. */\nLJFOLD(CONV any IRCONV_I64_INT)\nLJFOLD(CONV any IRCONV_U64_INT)\nLJFOLDF(simplify_conv_sext)\n{\n  IRRef ref = fins->op1;\n  int64_t ofs = 0;\n  if (!(fins->op2 & IRCONV_SEXT))\n    return NEXTFOLD;\n  PHIBARRIER(fleft);\n  if (fleft->o == IR_XLOAD && (irt_isu8(fleft->t) || irt_isu16(fleft->t)))\n    goto ok_reduce;\n  if (fleft->o == IR_ADD && irref_isk(fleft->op2)) {\n    ofs = (int64_t)IR(fleft->op2)->i;\n    ref = fleft->op1;\n  }\n  /* Use scalar evolution analysis results to strength-reduce sign-extension. */\n  if (ref == J->scev.idx) {\n    IRRef lo = J->scev.dir ? J->scev.start : J->scev.stop;\n    lua_assert(irt_isint(J->scev.t));\n    if (lo && IR(lo)->i + ofs >= 0) {\n    ok_reduce:\n#if LJ_TARGET_X64\n      /* Eliminate widening. All 32 bit ops do an implicit zero-extension. */\n      return LEFTFOLD;\n#else\n      /* Reduce to a (cheaper) zero-extension. */\n      fins->op2 &= ~IRCONV_SEXT;\n      return RETRYFOLD;\n#endif\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* Strength reduction of narrowing. */\nLJFOLD(CONV ADD IRCONV_INT_I64)\nLJFOLD(CONV SUB IRCONV_INT_I64)\nLJFOLD(CONV MUL IRCONV_INT_I64)\nLJFOLD(CONV ADD IRCONV_INT_U64)\nLJFOLD(CONV SUB IRCONV_INT_U64)\nLJFOLD(CONV MUL IRCONV_INT_U64)\nLJFOLD(CONV ADD IRCONV_U32_I64)\nLJFOLD(CONV SUB IRCONV_U32_I64)\nLJFOLD(CONV MUL IRCONV_U32_I64)\nLJFOLD(CONV ADD IRCONV_U32_U64)\nLJFOLD(CONV SUB IRCONV_U32_U64)\nLJFOLD(CONV MUL IRCONV_U32_U64)\nLJFOLDF(simplify_conv_narrow)\n{\n  IROp op = (IROp)fleft->o;\n  IRType t = irt_type(fins->t);\n  IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2;\n  PHIBARRIER(fleft);\n  op1 = emitir(IRTI(IR_CONV), op1, mode);\n  op2 = emitir(IRTI(IR_CONV), op2, mode);\n  fins->ot = IRT(op, t);\n  fins->op1 = op1;\n  fins->op2 = op2;\n  return RETRYFOLD;\n}\n\n/* Special CSE rule for CONV. */\nLJFOLD(CONV any any)\nLJFOLDF(cse_conv)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef op1 = fins->op1, op2 = (fins->op2 & IRCONV_MODEMASK);\n    uint8_t guard = irt_isguard(fins->t);\n    IRRef ref = J->chain[IR_CONV];\n    while (ref > op1) {\n      IRIns *ir = IR(ref);\n      /* Commoning with stronger checks is ok. */\n      if (ir->op1 == op1 && (ir->op2 & IRCONV_MODEMASK) == op2 &&\n\t  irt_isguard(ir->t) >= guard)\n\treturn ref;\n      ref = ir->prev;\n    }\n  }\n  return EMITFOLD;  /* No fallthrough to regular CSE. */\n}\n\n/* FP conversion narrowing. */\nLJFOLD(TOBIT ADD KNUM)\nLJFOLD(TOBIT SUB KNUM)\nLJFOLD(CONV ADD IRCONV_INT_NUM)\nLJFOLD(CONV SUB IRCONV_INT_NUM)\nLJFOLD(CONV ADD IRCONV_I64_NUM)\nLJFOLD(CONV SUB IRCONV_I64_NUM)\nLJFOLDF(narrow_convert)\n{\n  PHIBARRIER(fleft);\n  /* Narrowing ignores PHIs and repeating it inside the loop is not useful. */\n  if (J->chain[IR_LOOP])\n    return NEXTFOLD;\n  lua_assert(fins->o != IR_CONV || (fins->op2&IRCONV_CONVMASK) != IRCONV_TOBIT);\n  return lj_opt_narrow_convert(J);\n}\n\n/* -- Integer algebraic simplifications ----------------------------------- */\n\nLJFOLD(ADD any KINT)\nLJFOLD(ADDOV any KINT)\nLJFOLD(SUBOV any KINT)\nLJFOLDF(simplify_intadd_k)\n{\n  if (fright->i == 0)  /* i o 0 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(MULOV any KINT)\nLJFOLDF(simplify_intmul_k)\n{\n  if (fright->i == 0)  /* i * 0 ==> 0 */\n    return RIGHTFOLD;\n  if (fright->i == 1)  /* i * 1 ==> i */\n    return LEFTFOLD;\n  if (fright->i == 2) {  /* i * 2 ==> i + i */\n    fins->o = IR_ADDOV;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any KINT)\nLJFOLDF(simplify_intsub_k)\n{\n  if (fright->i == 0)  /* i - 0 ==> i */\n    return LEFTFOLD;\n  fins->o = IR_ADD;  /* i - k ==> i + (-k) */\n  fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i);  /* Overflow for -2^31 ok. */\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB KINT any)\nLJFOLD(SUB KINT64 any)\nLJFOLDF(simplify_intsub_kleft)\n{\n  if (fleft->o == IR_KINT ? (fleft->i == 0) : (ir_kint64(fleft)->u64 == 0)) {\n    fins->o = IR_NEG;  /* 0 - i ==> -i */\n    fins->op1 = fins->op2;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(ADD any KINT64)\nLJFOLDF(simplify_intadd_k64)\n{\n  if (ir_kint64(fright)->u64 == 0)  /* i + 0 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any KINT64)\nLJFOLDF(simplify_intsub_k64)\n{\n  uint64_t k = ir_kint64(fright)->u64;\n  if (k == 0)  /* i - 0 ==> i */\n    return LEFTFOLD;\n  fins->o = IR_ADD;  /* i - k ==> i + (-k) */\n  fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k);\n  return RETRYFOLD;\n}\n\nstatic TRef simplify_intmul_k(jit_State *J, int32_t k)\n{\n  /* Note: many more simplifications are possible, e.g. 2^k1 +- 2^k2.\n  ** But this is mainly intended for simple address arithmetic.\n  ** Also it's easier for the backend to optimize the original multiplies.\n  */\n  if (k == 0) {  /* i * 0 ==> 0 */\n    return RIGHTFOLD;\n  } else if (k == 1) {  /* i * 1 ==> i */\n    return LEFTFOLD;\n  } else if ((k & (k-1)) == 0) {  /* i * 2^k ==> i << k */\n    fins->o = IR_BSHL;\n    fins->op2 = lj_ir_kint(J, lj_fls((uint32_t)k));\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL any KINT)\nLJFOLDF(simplify_intmul_k32)\n{\n  if (fright->i >= 0)\n    return simplify_intmul_k(J, fright->i);\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL any KINT64)\nLJFOLDF(simplify_intmul_k64)\n{\n#if LJ_HASFFI\n  if (ir_kint64(fright)->u64 < 0x80000000u)\n    return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64);\n  return NEXTFOLD;\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(MOD any KINT)\nLJFOLDF(simplify_intmod_k)\n{\n  int32_t k = fright->i;\n  lua_assert(k != 0);\n  if (k > 0 && (k & (k-1)) == 0) {  /* i % (2^k) ==> i & (2^k-1) */\n    fins->o = IR_BAND;\n    fins->op2 = lj_ir_kint(J, k-1);\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MOD KINT any)\nLJFOLDF(simplify_intmod_kleft)\n{\n  if (fleft->i == 0)\n    return INTFOLD(0);\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any any)\nLJFOLD(SUBOV any any)\nLJFOLDF(simplify_intsub)\n{\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))  /* i - i ==> 0 */\n    return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB ADD any)\nLJFOLDF(simplify_intsubadd_leftcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    if (fins->op2 == fleft->op1)  /* (i + j) - i ==> j */\n      return fleft->op2;\n    if (fins->op2 == fleft->op2)  /* (i + j) - j ==> i */\n      return fleft->op1;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB SUB any)\nLJFOLDF(simplify_intsubsub_leftcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    if (fins->op2 == fleft->op1) {  /* (i - j) - i ==> 0 - j */\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      fins->op2 = fleft->op2;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any SUB)\nLJFOLDF(simplify_intsubsub_rightcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fright);\n    if (fins->op1 == fright->op1)  /* i - (i - j) ==> j */\n      return fright->op2;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any ADD)\nLJFOLDF(simplify_intsubadd_rightcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fright);\n    if (fins->op1 == fright->op1) {  /* i - (i + j) ==> 0 - j */\n      fins->op2 = fright->op2;\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      return RETRYFOLD;\n    }\n    if (fins->op1 == fright->op2) {  /* i - (j + i) ==> 0 - j */\n      fins->op2 = fright->op1;\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB ADD ADD)\nLJFOLDF(simplify_intsubaddadd_cancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    PHIBARRIER(fright);\n    if (fleft->op1 == fright->op1) {  /* (i + j1) - (i + j2) ==> j1 - j2 */\n      fins->op1 = fleft->op2;\n      fins->op2 = fright->op2;\n      return RETRYFOLD;\n    }\n    if (fleft->op1 == fright->op2) {  /* (i + j1) - (j2 + i) ==> j1 - j2 */\n      fins->op1 = fleft->op2;\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n    if (fleft->op2 == fright->op1) {  /* (j1 + i) - (i + j2) ==> j1 - j2 */\n      fins->op1 = fleft->op1;\n      fins->op2 = fright->op2;\n      return RETRYFOLD;\n    }\n    if (fleft->op2 == fright->op2) {  /* (j1 + i) - (j2 + i) ==> j1 - j2 */\n      fins->op1 = fleft->op1;\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND any KINT)\nLJFOLD(BAND any KINT64)\nLJFOLDF(simplify_band_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i & 0 ==> 0 */\n    return RIGHTFOLD;\n  if (k == -1)  /* i & -1 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BOR any KINT)\nLJFOLD(BOR any KINT64)\nLJFOLDF(simplify_bor_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i | 0 ==> i */\n    return LEFTFOLD;\n  if (k == -1)  /* i | -1 ==> -1 */\n    return RIGHTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BXOR any KINT)\nLJFOLD(BXOR any KINT64)\nLJFOLDF(simplify_bxor_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i xor 0 ==> i */\n    return LEFTFOLD;\n  if (k == -1) {  /* i xor -1 ==> ~i */\n    fins->o = IR_BNOT;\n    fins->op2 = 0;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL any KINT)\nLJFOLD(BSHR any KINT)\nLJFOLD(BSAR any KINT)\nLJFOLD(BROL any KINT)\nLJFOLD(BROR any KINT)\nLJFOLDF(simplify_shift_ik)\n{\n  int32_t mask = irt_is64(fins->t) ? 63 : 31;\n  int32_t k = (fright->i & mask);\n  if (k == 0)  /* i o 0 ==> i */\n    return LEFTFOLD;\n  if (k == 1 && fins->o == IR_BSHL) {  /* i << 1 ==> i + i */\n    fins->o = IR_ADD;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  }\n  if (k != fright->i) {  /* i o k ==> i o (k & mask) */\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;\n  }\n#ifndef LJ_TARGET_UNIFYROT\n  if (fins->o == IR_BROR) {  /* bror(i, k) ==> brol(i, (-k)&mask) */\n    fins->o = IR_BROL;\n    fins->op2 = (IRRef1)lj_ir_kint(J, (-k)&mask);\n    return RETRYFOLD;\n  }\n#endif\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL any BAND)\nLJFOLD(BSHR any BAND)\nLJFOLD(BSAR any BAND)\nLJFOLD(BROL any BAND)\nLJFOLD(BROR any BAND)\nLJFOLDF(simplify_shift_andk)\n{\n  IRIns *irk = IR(fright->op2);\n  PHIBARRIER(fright);\n  if ((fins->o < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n      irk->o == IR_KINT) {  /* i o (j & mask) ==> i o j */\n    int32_t mask = irt_is64(fins->t) ? 63 : 31;\n    int32_t k = irk->i & mask;\n    if (k == mask) {\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL KINT any)\nLJFOLD(BSHR KINT any)\nLJFOLD(BSHL KINT64 any)\nLJFOLD(BSHR KINT64 any)\nLJFOLDF(simplify_shift1_ki)\n{\n  int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :\n\t\t\t\t    (int64_t)ir_k64(fleft)->u64;\n  if (k == 0)  /* 0 o i ==> 0 */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSAR KINT any)\nLJFOLD(BROL KINT any)\nLJFOLD(BROR KINT any)\nLJFOLD(BSAR KINT64 any)\nLJFOLD(BROL KINT64 any)\nLJFOLD(BROR KINT64 any)\nLJFOLDF(simplify_shift2_ki)\n{\n  int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :\n\t\t\t\t    (int64_t)ir_k64(fleft)->u64;\n  if (k == 0 || k == -1)  /* 0 o i ==> 0; -1 o i ==> -1 */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL BAND KINT)\nLJFOLD(BSHR BAND KINT)\nLJFOLD(BROL BAND KINT)\nLJFOLD(BROR BAND KINT)\nLJFOLDF(simplify_shiftk_andk)\n{\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);\n  if (irk->o == IR_KINT) {  /* (i & k1) o k2 ==> (i o k2) & (k1 o k2) */\n    int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);\n    fins->op1 = fleft->op1;\n    fins->op1 = (IRRef1)lj_opt_fold(J);\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    fins->ot = IRTI(IR_BAND);\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND BSHL KINT)\nLJFOLD(BAND BSHR KINT)\nLJFOLDF(simplify_andk_shiftk)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT &&\n      kfold_intop(-1, irk->i, (IROp)fleft->o) == fright->i)\n    return LEFTFOLD;  /* (i o k1) & k2 ==> i, if (-1 o k1) == k2 */\n  return NEXTFOLD;\n}\n\n/* -- Reassociation ------------------------------------------------------- */\n\nLJFOLD(ADD ADD KINT)\nLJFOLD(MUL MUL KINT)\nLJFOLD(BAND BAND KINT)\nLJFOLD(BOR BOR KINT)\nLJFOLD(BXOR BXOR KINT)\nLJFOLDF(reassoc_intarith_k)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT) {\n    int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);\n    if (k == irk->i)  /* (i o k1) o k2 ==> i o k1, if (k1 o k2) == k1. */\n      return LEFTFOLD;\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;  /* (i o k1) o k2 ==> i o (k1 o k2) */\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(ADD ADD KINT64)\nLJFOLD(MUL MUL KINT64)\nLJFOLD(BAND BAND KINT64)\nLJFOLD(BOR BOR KINT64)\nLJFOLD(BXOR BXOR KINT64)\nLJFOLDF(reassoc_intarith_k64)\n{\n#if LJ_HASFFI\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT64) {\n    uint64_t k = kfold_int64arith(ir_k64(irk)->u64,\n\t\t\t\t  ir_k64(fright)->u64, (IROp)fins->o);\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint64(J, k);\n    return RETRYFOLD;  /* (i o k1) o k2 ==> i o (k1 o k2) */\n  }\n  return NEXTFOLD;\n#else\n  UNUSED(J); lua_assert(0); return FAILFOLD;\n#endif\n}\n\nLJFOLD(MIN MIN any)\nLJFOLD(MAX MAX any)\nLJFOLD(BAND BAND any)\nLJFOLD(BOR BOR any)\nLJFOLDF(reassoc_dup)\n{\n  if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2)\n    return LEFTFOLD;  /* (a o b) o a ==> a o b; (a o b) o b ==> a o b */\n  return NEXTFOLD;\n}\n\nLJFOLD(BXOR BXOR any)\nLJFOLDF(reassoc_bxor)\n{\n  PHIBARRIER(fleft);\n  if (fins->op2 == fleft->op1)  /* (a xor b) xor a ==> b */\n    return fleft->op2;\n  if (fins->op2 == fleft->op2)  /* (a xor b) xor b ==> a */\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL BSHL KINT)\nLJFOLD(BSHR BSHR KINT)\nLJFOLD(BSAR BSAR KINT)\nLJFOLD(BROL BROL KINT)\nLJFOLD(BROR BROR KINT)\nLJFOLDF(reassoc_shift)\n{\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);  /* The (shift any KINT) rule covers k2 == 0 and more. */\n  if (irk->o == IR_KINT) {  /* (i o k1) o k2 ==> i o (k1 + k2) */\n    int32_t mask = irt_is64(fins->t) ? 63 : 31;\n    int32_t k = (irk->i & mask) + (fright->i & mask);\n    if (k > mask) {  /* Combined shift too wide? */\n      if (fins->o == IR_BSHL || fins->o == IR_BSHR)\n\treturn mask == 31 ? INTFOLD(0) : INT64FOLD(0);\n      else if (fins->o == IR_BSAR)\n\tk = mask;\n      else\n\tk &= mask;\n    }\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MIN MIN KNUM)\nLJFOLD(MAX MAX KNUM)\nLJFOLD(MIN MIN KINT)\nLJFOLD(MAX MAX KINT)\nLJFOLDF(reassoc_minmax_k)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KNUM) {\n    lua_Number a = ir_knum(irk)->n;\n    lua_Number y = lj_vm_foldarith(a, knumright, fins->o - IR_ADD);\n    if (a == y)  /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */\n      return LEFTFOLD;\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_knum(J, y);\n    return RETRYFOLD;  /* (x o k1) o k2 ==> x o (k1 o k2) */\n  } else if (irk->o == IR_KINT) {\n    int32_t a = irk->i;\n    int32_t y = kfold_intop(a, fright->i, fins->o);\n    if (a == y)  /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */\n      return LEFTFOLD;\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, y);\n    return RETRYFOLD;  /* (x o k1) o k2 ==> x o (k1 o k2) */\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MIN MAX any)\nLJFOLD(MAX MIN any)\nLJFOLDF(reassoc_minmax_left)\n{\n  if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2)\n    return RIGHTFOLD;  /* (b o1 a) o2 b ==> b; (a o1 b) o2 b ==> b */\n  return NEXTFOLD;\n}\n\nLJFOLD(MIN any MAX)\nLJFOLD(MAX any MIN)\nLJFOLDF(reassoc_minmax_right)\n{\n  if (fins->op1 == fright->op1 || fins->op1 == fright->op2)\n    return LEFTFOLD;  /* a o2 (a o1 b) ==> a; a o2 (b o1 a) ==> a */\n  return NEXTFOLD;\n}\n\n/* -- Array bounds check elimination -------------------------------------- */\n\n/* Eliminate ABC across PHIs to handle t[i-1] forwarding case.\n** ABC(asize, (i+k)+(-k)) ==> ABC(asize, i), but only if it already exists.\n** Could be generalized to (i+k1)+k2 ==> i+(k1+k2), but needs better disambig.\n*/\nLJFOLD(ABC any ADD)\nLJFOLDF(abc_fwd)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {\n    if (irref_isk(fright->op2)) {\n      IRIns *add2 = IR(fright->op1);\n      if (add2->o == IR_ADD && irref_isk(add2->op2) &&\n\t  IR(fright->op2)->i == -IR(add2->op2)->i) {\n\tIRRef ref = J->chain[IR_ABC];\n\tIRRef lim = add2->op1;\n\tif (fins->op1 > lim) lim = fins->op1;\n\twhile (ref > lim) {\n\t  IRIns *ir = IR(ref);\n\t  if (ir->op1 == fins->op1 && ir->op2 == add2->op1)\n\t    return DROPFOLD;\n\t  ref = ir->prev;\n\t}\n      }\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* Eliminate ABC for constants.\n** ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2))\n** Drop second ABC if k2 is lower. Otherwise patch first ABC with k2.\n*/\nLJFOLD(ABC any KINT)\nLJFOLDF(abc_k)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {\n    IRRef ref = J->chain[IR_ABC];\n    IRRef asize = fins->op1;\n    while (ref > asize) {\n      IRIns *ir = IR(ref);\n      if (ir->op1 == asize && irref_isk(ir->op2)) {\n\tint32_t k = IR(ir->op2)->i;\n\tif (fright->i > k)\n\t  ir->op2 = fins->op2;\n\treturn DROPFOLD;\n      }\n      ref = ir->prev;\n    }\n    return EMITFOLD;  /* Already performed CSE. */\n  }\n  return NEXTFOLD;\n}\n\n/* Eliminate invariant ABC inside loop. */\nLJFOLD(ABC any any)\nLJFOLDF(abc_invar)\n{\n  /* Invariant ABC marked as PTR. Drop if op1 is invariant, too. */\n  if (!irt_isint(fins->t) && fins->op1 < J->chain[IR_LOOP] &&\n      !irt_isphi(IR(fins->op1)->t))\n    return DROPFOLD;\n  return NEXTFOLD;\n}\n\n/* -- Commutativity ------------------------------------------------------- */\n\n/* The refs of commutative ops are canonicalized. Lower refs go to the right.\n** Rationale behind this:\n** - It (also) moves constants to the right.\n** - It reduces the number of FOLD rules (e.g. (BOR any KINT) suffices).\n** - It helps CSE to find more matches.\n** - The assembler generates better code with constants at the right.\n*/\n\nLJFOLD(ADD any any)\nLJFOLD(MUL any any)\nLJFOLD(ADDOV any any)\nLJFOLD(MULOV any any)\nLJFOLDF(comm_swap)\n{\n  if (fins->op1 < fins->op2) {  /* Move lower ref to the right. */\n    IRRef1 tmp = fins->op1;\n    fins->op1 = fins->op2;\n    fins->op2 = tmp;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(EQ any any)\nLJFOLD(NE any any)\nLJFOLDF(comm_equal)\n{\n  /* For non-numbers only: x == x ==> drop; x ~= x ==> fail */\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))\n    return CONDFOLD(fins->o == IR_EQ);\n  return fold_comm_swap(J);\n}\n\nLJFOLD(LT any any)\nLJFOLD(GE any any)\nLJFOLD(LE any any)\nLJFOLD(GT any any)\nLJFOLD(ULT any any)\nLJFOLD(UGE any any)\nLJFOLD(ULE any any)\nLJFOLD(UGT any any)\nLJFOLDF(comm_comp)\n{\n  /* For non-numbers only: x <=> x ==> drop; x <> x ==> fail */\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))\n    return CONDFOLD((fins->o ^ (fins->o >> 1)) & 1);\n  if (fins->op1 < fins->op2) {  /* Move lower ref to the right. */\n    IRRef1 tmp = fins->op1;\n    fins->op1 = fins->op2;\n    fins->op2 = tmp;\n    fins->o ^= 3; /* GT <-> LT, GE <-> LE, does not affect U */\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND any any)\nLJFOLD(BOR any any)\nLJFOLD(MIN any any)\nLJFOLD(MAX any any)\nLJFOLDF(comm_dup)\n{\n  if (fins->op1 == fins->op2)  /* x o x ==> x */\n    return LEFTFOLD;\n  return fold_comm_swap(J);\n}\n\nLJFOLD(BXOR any any)\nLJFOLDF(comm_bxor)\n{\n  if (fins->op1 == fins->op2)  /* i xor i ==> 0 */\n    return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);\n  return fold_comm_swap(J);\n}\n\n/* -- Simplification of compound expressions ------------------------------ */\n\nstatic TRef kfold_xload(jit_State *J, IRIns *ir, const void *p)\n{\n  int32_t k;\n  switch (irt_type(ir->t)) {\n  case IRT_NUM: return lj_ir_knum_u64(J, *(uint64_t *)p);\n  case IRT_I8: k = (int32_t)*(int8_t *)p; break;\n  case IRT_U8: k = (int32_t)*(uint8_t *)p; break;\n  case IRT_I16: k = (int32_t)(int16_t)lj_getu16(p); break;\n  case IRT_U16: k = (int32_t)(uint16_t)lj_getu16(p); break;\n  case IRT_INT: case IRT_U32: k = (int32_t)lj_getu32(p); break;\n  case IRT_I64: case IRT_U64: return lj_ir_kint64(J, *(uint64_t *)p);\n  default: return 0;\n  }\n  return lj_ir_kint(J, k);\n}\n\n/* Turn: string.sub(str, a, b) == kstr\n** into: string.byte(str, a) == string.byte(kstr, 1) etc.\n** Note: this creates unaligned XLOADs on x86/x64.\n*/\nLJFOLD(EQ SNEW KGC)\nLJFOLD(NE SNEW KGC)\nLJFOLDF(merge_eqne_snew_kgc)\n{\n  GCstr *kstr = ir_kstr(fright);\n  int32_t len = (int32_t)kstr->len;\n  lua_assert(irt_isstr(fins->t));\n\n#if LJ_TARGET_UNALIGNED\n#define FOLD_SNEW_MAX_LEN\t4  /* Handle string lengths 0, 1, 2, 3, 4. */\n#define FOLD_SNEW_TYPE8\t\tIRT_I8\t/* Creates shorter immediates. */\n#else\n#define FOLD_SNEW_MAX_LEN\t1  /* Handle string lengths 0 or 1. */\n#define FOLD_SNEW_TYPE8\t\tIRT_U8  /* Prefer unsigned loads. */\n#endif\n\n  PHIBARRIER(fleft);\n  if (len <= FOLD_SNEW_MAX_LEN) {\n    IROp op = (IROp)fins->o;\n    IRRef strref = fleft->op1;\n    if (IR(strref)->o != IR_STRREF)\n      return NEXTFOLD;\n    if (op == IR_EQ) {\n      emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len));\n      /* Caveat: fins/fleft/fright is no longer valid after emitir. */\n    } else {\n      /* NE is not expanded since this would need an OR of two conds. */\n      if (!irref_isk(fleft->op2))  /* Only handle the constant length case. */\n\treturn NEXTFOLD;\n      if (IR(fleft->op2)->i != len)\n\treturn DROPFOLD;\n    }\n    if (len > 0) {\n      /* A 4 byte load for length 3 is ok -- all strings have an extra NUL. */\n      uint16_t ot = (uint16_t)(len == 1 ? IRT(IR_XLOAD, FOLD_SNEW_TYPE8) :\n\t\t\t       len == 2 ? IRT(IR_XLOAD, IRT_U16) :\n\t\t\t       IRTI(IR_XLOAD));\n      TRef tmp = emitir(ot, strref,\n\t\t\tIRXLOAD_READONLY | (len > 1 ? IRXLOAD_UNALIGNED : 0));\n      TRef val = kfold_xload(J, IR(tref_ref(tmp)), strdata(kstr));\n      if (len == 3)\n\ttmp = emitir(IRTI(IR_BAND), tmp,\n\t\t     lj_ir_kint(J, LJ_ENDIAN_SELECT(0x00ffffff, 0xffffff00)));\n      fins->op1 = (IRRef1)tmp;\n      fins->op2 = (IRRef1)val;\n      fins->ot = (IROpT)IRTGI(op);\n      return RETRYFOLD;\n    } else {\n      return DROPFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* -- Loads --------------------------------------------------------------- */\n\n/* Loads cannot be folded or passed on to CSE in general.\n** Alias analysis is needed to check for forwarding opportunities.\n**\n** Caveat: *all* loads must be listed here or they end up at CSE!\n*/\n\nLJFOLD(ALOAD any)\nLJFOLDX(lj_opt_fwd_aload)\n\n/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */\nLJFOLD(HLOAD KKPTR)\nLJFOLDF(kfold_hload_kkptr)\n{\n  UNUSED(J);\n  lua_assert(ir_kptr(fleft) == niltvg(J2G(J)));\n  return TREF_NIL;\n}\n\nLJFOLD(HLOAD any)\nLJFOLDX(lj_opt_fwd_hload)\n\nLJFOLD(ULOAD any)\nLJFOLDX(lj_opt_fwd_uload)\n\nLJFOLD(CALLL any IRCALL_lj_tab_len)\nLJFOLDX(lj_opt_fwd_tab_len)\n\n/* Upvalue refs are really loads, but there are no corresponding stores.\n** So CSE is ok for them, except for UREFO across a GC step (see below).\n** If the referenced function is const, its upvalue addresses are const, too.\n** This can be used to improve CSE by looking for the same address,\n** even if the upvalues originate from a different function.\n*/\nLJFOLD(UREFO KGC any)\nLJFOLD(UREFC KGC any)\nLJFOLDF(cse_uref)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef ref = J->chain[fins->o];\n    GCfunc *fn = ir_kfunc(fleft);\n    GCupval *uv = gco2uv(gcref(fn->l.uvptr[(fins->op2 >> 8)]));\n    while (ref > 0) {\n      IRIns *ir = IR(ref);\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn2 = ir_kfunc(IR(ir->op1));\n\tif (gco2uv(gcref(fn2->l.uvptr[(ir->op2 >> 8)])) == uv) {\n\t  if (fins->o == IR_UREFO && gcstep_barrier(J, ref))\n\t    break;\n\t  return ref;\n\t}\n      }\n      ref = ir->prev;\n    }\n  }\n  return EMITFOLD;\n}\n\nLJFOLD(HREFK any any)\nLJFOLDX(lj_opt_fwd_hrefk)\n\nLJFOLD(HREF TNEW any)\nLJFOLDF(fwd_href_tnew)\n{\n  if (lj_opt_fwd_href_nokey(J))\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  return NEXTFOLD;\n}\n\nLJFOLD(HREF TDUP KPRI)\nLJFOLD(HREF TDUP KGC)\nLJFOLD(HREF TDUP KNUM)\nLJFOLDF(fwd_href_tdup)\n{\n  TValue keyv;\n  lj_ir_kvalue(J->L, &keyv, fright);\n  if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) &&\n      lj_opt_fwd_href_nokey(J))\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  return NEXTFOLD;\n}\n\n/* We can safely FOLD/CSE array/hash refs and field loads, since there\n** are no corresponding stores. But we need to check for any NEWREF with\n** an aliased table, as it may invalidate all of the pointers and fields.\n** Only HREF needs the NEWREF check -- AREF and HREFK already depend on\n** FLOADs. And NEWREF itself is treated like a store (see below).\n** LREF is constant (per trace) since coroutine switches are not inlined.\n*/\nLJFOLD(FLOAD TNEW IRFL_TAB_ASIZE)\nLJFOLDF(fload_tab_tnew_asize)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD(fleft->op1);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TNEW IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_tnew_hmask)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((1 << fleft->op2)-1);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TDUP IRFL_TAB_ASIZE)\nLJFOLDF(fload_tab_tdup_asize)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->asize);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TDUP IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_tdup_hmask)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->hmask);\n  return NEXTFOLD;\n}\n\nLJFOLD(HREF any any)\nLJFOLD(FLOAD any IRFL_TAB_ARRAY)\nLJFOLD(FLOAD any IRFL_TAB_NODE)\nLJFOLD(FLOAD any IRFL_TAB_ASIZE)\nLJFOLD(FLOAD any IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_ah)\n{\n  TRef tr = lj_opt_cse(J);\n  return lj_opt_fwd_tptr(J, tref_ref(tr)) ? tr : EMITFOLD;\n}\n\n/* Strings are immutable, so we can safely FOLD/CSE the related FLOAD. */\nLJFOLD(FLOAD KGC IRFL_STR_LEN)\nLJFOLDF(fload_str_len_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return INTFOLD((int32_t)ir_kstr(fleft)->len);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD SNEW IRFL_STR_LEN)\nLJFOLDF(fload_str_len_snew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    PHIBARRIER(fleft);\n    return fleft->op2;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TOSTR IRFL_STR_LEN)\nLJFOLDF(fload_str_len_tostr)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && fleft->op2 == IRTOSTR_CHAR)\n    return INTFOLD(1);\n  return NEXTFOLD;\n}\n\n/* The C type ID of cdata objects is immutable. */\nLJFOLD(FLOAD KGC IRFL_CDATA_CTYPEID)\nLJFOLDF(fload_cdata_typeid_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return INTFOLD((int32_t)ir_kcdata(fleft)->ctypeid);\n  return NEXTFOLD;\n}\n\n/* Get the contents of immutable cdata objects. */\nLJFOLD(FLOAD KGC IRFL_CDATA_PTR)\nLJFOLD(FLOAD KGC IRFL_CDATA_INT)\nLJFOLD(FLOAD KGC IRFL_CDATA_INT64)\nLJFOLDF(fload_cdata_int64_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    void *p = cdataptr(ir_kcdata(fleft));\n    if (irt_is64(fins->t))\n      return INT64FOLD(*(uint64_t *)p);\n    else\n      return INTFOLD(*(int32_t *)p);\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD CNEW IRFL_CDATA_CTYPEID)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_CTYPEID)\nLJFOLDF(fload_cdata_typeid_cnew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return fleft->op1;  /* No PHI barrier needed. CNEW/CNEWI op1 is const. */\n  return NEXTFOLD;\n}\n\n/* Pointer, int and int64 cdata objects are immutable. */\nLJFOLD(FLOAD CNEWI IRFL_CDATA_PTR)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_INT)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_INT64)\nLJFOLDF(fload_cdata_ptr_int64_cnew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return fleft->op2;  /* Fold even across PHI to avoid allocations. */\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD any IRFL_STR_LEN)\nLJFOLD(FLOAD any IRFL_FUNC_ENV)\nLJFOLD(FLOAD any IRFL_THREAD_ENV)\nLJFOLD(FLOAD any IRFL_CDATA_CTYPEID)\nLJFOLD(FLOAD any IRFL_CDATA_PTR)\nLJFOLD(FLOAD any IRFL_CDATA_INT)\nLJFOLD(FLOAD any IRFL_CDATA_INT64)\nLJFOLD(VLOAD any any)  /* Vararg loads have no corresponding stores. */\nLJFOLDX(lj_opt_cse)\n\n/* All other field loads need alias analysis. */\nLJFOLD(FLOAD any any)\nLJFOLDX(lj_opt_fwd_fload)\n\n/* This is for LOOP only. Recording handles SLOADs internally. */\nLJFOLD(SLOAD any any)\nLJFOLDF(fwd_sload)\n{\n  if ((fins->op2 & IRSLOAD_FRAME)) {\n    TRef tr = lj_opt_cse(J);\n    return tref_ref(tr) < J->chain[IR_RETF] ? EMITFOLD : tr;\n  } else {\n    lua_assert(J->slot[fins->op1] != 0);\n    return J->slot[fins->op1];\n  }\n}\n\n/* Only fold for KKPTR. The pointer _and_ the contents must be const. */\nLJFOLD(XLOAD KKPTR any)\nLJFOLDF(xload_kptr)\n{\n  TRef tr = kfold_xload(J, fins, ir_kptr(fleft));\n  return tr ? tr : NEXTFOLD;\n}\n\nLJFOLD(XLOAD any any)\nLJFOLDX(lj_opt_fwd_xload)\n\n/* -- Write barriers ------------------------------------------------------ */\n\n/* Write barriers are amenable to CSE, but not across any incremental\n** GC steps.\n**\n** The same logic applies to open upvalue references, because a stack\n** may be resized during a GC step (not the current stack, but maybe that\n** of a coroutine).\n*/\nLJFOLD(TBAR any)\nLJFOLD(OBAR any any)\nLJFOLD(UREFO any any)\nLJFOLDF(barrier_tab)\n{\n  TRef tr = lj_opt_cse(J);\n  if (gcstep_barrier(J, tref_ref(tr)))  /* CSE across GC step? */\n    return EMITFOLD;  /* Raw emit. Assumes fins is left intact by CSE. */\n  return tr;\n}\n\nLJFOLD(TBAR TNEW)\nLJFOLD(TBAR TDUP)\nLJFOLDF(barrier_tnew_tdup)\n{\n  /* New tables are always white and never need a barrier. */\n  if (fins->op1 < J->chain[IR_LOOP])  /* Except across a GC step. */\n    return NEXTFOLD;\n  return DROPFOLD;\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nLJFOLD(PROF any any)\nLJFOLDF(prof)\n{\n  IRRef ref = J->chain[IR_PROF];\n  if (ref+1 == J->cur.nins)  /* Drop neighbouring IR_PROF. */\n    return ref;\n  return EMITFOLD;\n}\n\n/* -- Stores and allocations ---------------------------------------------- */\n\n/* Stores and allocations cannot be folded or passed on to CSE in general.\n** But some stores can be eliminated with dead-store elimination (DSE).\n**\n** Caveat: *all* stores and allocs must be listed here or they end up at CSE!\n*/\n\nLJFOLD(ASTORE any any)\nLJFOLD(HSTORE any any)\nLJFOLDX(lj_opt_dse_ahstore)\n\nLJFOLD(USTORE any any)\nLJFOLDX(lj_opt_dse_ustore)\n\nLJFOLD(FSTORE any any)\nLJFOLDX(lj_opt_dse_fstore)\n\nLJFOLD(XSTORE any any)\nLJFOLDX(lj_opt_dse_xstore)\n\nLJFOLD(NEWREF any any)  /* Treated like a store. */\nLJFOLD(CALLA any any)\nLJFOLD(CALLL any any)  /* Safeguard fallback. */\nLJFOLD(CALLS any any)\nLJFOLD(CALLXS any any)\nLJFOLD(XBAR)\nLJFOLD(RETF any any)  /* Modifies BASE. */\nLJFOLD(TNEW any any)\nLJFOLD(TDUP any)\nLJFOLD(CNEW any any)\nLJFOLD(XSNEW any any)\nLJFOLD(BUFHDR any any)\nLJFOLDX(lj_ir_emit)\n\n/* ------------------------------------------------------------------------ */\n\n/* Every entry in the generated hash table is a 32 bit pattern:\n**\n** xxxxxxxx iiiiiii lllllll rrrrrrrrrr\n**\n**   xxxxxxxx = 8 bit index into fold function table\n**    iiiiiii = 7 bit folded instruction opcode\n**    lllllll = 7 bit left instruction opcode\n** rrrrrrrrrr = 8 bit right instruction opcode or 10 bits from literal field\n*/\n\n#include \"lj_folddef.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Fold IR instruction. */\nTRef LJ_FASTCALL lj_opt_fold(jit_State *J)\n{\n  uint32_t key, any;\n  IRRef ref;\n\n  if (LJ_UNLIKELY((J->flags & JIT_F_OPT_MASK) != JIT_F_OPT_DEFAULT)) {\n    lua_assert(((JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE|JIT_F_OPT_DSE) |\n\t\tJIT_F_OPT_DEFAULT) == JIT_F_OPT_DEFAULT);\n    /* Folding disabled? Chain to CSE, but not for loads/stores/allocs. */\n    if (!(J->flags & JIT_F_OPT_FOLD) && irm_kind(lj_ir_mode[fins->o]) == IRM_N)\n      return lj_opt_cse(J);\n\n    /* No FOLD, forwarding or CSE? Emit raw IR for loads, except for SLOAD. */\n    if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE)) !=\n\t\t    (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE) &&\n\tirm_kind(lj_ir_mode[fins->o]) == IRM_L && fins->o != IR_SLOAD)\n      return lj_ir_emit(J);\n\n    /* No FOLD or DSE? Emit raw IR for stores. */\n    if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_DSE)) !=\n\t\t    (JIT_F_OPT_FOLD|JIT_F_OPT_DSE) &&\n\tirm_kind(lj_ir_mode[fins->o]) == IRM_S)\n      return lj_ir_emit(J);\n  }\n\n  /* Fold engine start/retry point. */\nretry:\n  /* Construct key from opcode and operand opcodes (unless literal/none). */\n  key = ((uint32_t)fins->o << 17);\n  if (fins->op1 >= J->cur.nk) {\n    key += (uint32_t)IR(fins->op1)->o << 10;\n    *fleft = *IR(fins->op1);\n  }\n  if (fins->op2 >= J->cur.nk) {\n    key += (uint32_t)IR(fins->op2)->o;\n    *fright = *IR(fins->op2);\n  } else {\n    key += (fins->op2 & 0x3ffu);  /* Literal mask. Must include IRCONV_*MASK. */\n  }\n\n  /* Check for a match in order from most specific to least specific. */\n  any = 0;\n  for (;;) {\n    uint32_t k = key | (any & 0x1ffff);\n    uint32_t h = fold_hashkey(k);\n    uint32_t fh = fold_hash[h];  /* Lookup key in semi-perfect hash table. */\n    if ((fh & 0xffffff) == k || (fh = fold_hash[h+1], (fh & 0xffffff) == k)) {\n      ref = (IRRef)tref_ref(fold_func[fh >> 24](J));\n      if (ref != NEXTFOLD)\n\tbreak;\n    }\n    if (any == 0xfffff)  /* Exhausted folding. Pass on to CSE. */\n      return lj_opt_cse(J);\n    any = (any | (any >> 10)) ^ 0xffc00;\n  }\n\n  /* Return value processing, ordered by frequency. */\n  if (LJ_LIKELY(ref >= MAX_FOLD))\n    return TREF(ref, irt_t(IR(ref)->t));\n  if (ref == RETRYFOLD)\n    goto retry;\n  if (ref == KINTFOLD)\n    return lj_ir_kint(J, fins->i);\n  if (ref == FAILFOLD)\n    lj_trace_err(J, LJ_TRERR_GFAIL);\n  lua_assert(ref == DROPFOLD);\n  return REF_DROP;\n}\n\n/* -- Common-Subexpression Elimination ------------------------------------ */\n\n/* CSE an IR instruction. This is very fast due to the skip-list chains. */\nTRef LJ_FASTCALL lj_opt_cse(jit_State *J)\n{\n  /* Avoid narrow to wide store-to-load forwarding stall */\n  IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);\n  IROp op = fins->o;\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    /* Limited search for same operands in per-opcode chain. */\n    IRRef ref = J->chain[op];\n    IRRef lim = fins->op1;\n    if (fins->op2 > lim) lim = fins->op2;  /* Relies on lit < REF_BIAS. */\n    while (ref > lim) {\n      if (IR(ref)->op12 == op12)\n\treturn TREF(ref, irt_t(IR(ref)->t));  /* Common subexpression found. */\n      ref = IR(ref)->prev;\n    }\n  }\n  /* Otherwise emit IR (inlined for speed). */\n  {\n    IRRef ref = lj_ir_nextins(J);\n    IRIns *ir = IR(ref);\n    ir->prev = J->chain[op];\n    ir->op12 = op12;\n    J->chain[op] = (IRRef1)ref;\n    ir->o = fins->o;\n    J->guardemit.irt |= fins->t.irt;\n    return TREF(ref, irt_t((ir->t = fins->t)));\n  }\n}\n\n/* CSE with explicit search limit. */\nTRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim)\n{\n  IRRef ref = J->chain[fins->o];\n  IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);\n  while (ref > lim) {\n    if (IR(ref)->op12 == op12)\n      return ref;\n    ref = IR(ref)->prev;\n  }\n  return lj_ir_emit(J);\n}\n\n/* ------------------------------------------------------------------------ */\n\n#undef IR\n#undef fins\n#undef fleft\n#undef fright\n#undef knumleft\n#undef knumright\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_loop.c",
    "content": "/*\n** LOOP: Loop Optimizations.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_loop_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_vm.h\"\n\n/* Loop optimization:\n**\n** Traditional Loop-Invariant Code Motion (LICM) splits the instructions\n** of a loop into invariant and variant instructions. The invariant\n** instructions are hoisted out of the loop and only the variant\n** instructions remain inside the loop body.\n**\n** Unfortunately LICM is mostly useless for compiling dynamic languages.\n** The IR has many guards and most of the subsequent instructions are\n** control-dependent on them. The first non-hoistable guard would\n** effectively prevent hoisting of all subsequent instructions.\n**\n** That's why we use a special form of unrolling using copy-substitution,\n** combined with redundancy elimination:\n**\n** The recorded instruction stream is re-emitted to the compiler pipeline\n** with substituted operands. The substitution table is filled with the\n** refs returned by re-emitting each instruction. This can be done\n** on-the-fly, because the IR is in strict SSA form, where every ref is\n** defined before its use.\n**\n** This aproach generates two code sections, separated by the LOOP\n** instruction:\n**\n** 1. The recorded instructions form a kind of pre-roll for the loop. It\n** contains a mix of invariant and variant instructions and performs\n** exactly one loop iteration (but not necessarily the 1st iteration).\n**\n** 2. The loop body contains only the variant instructions and performs\n** all remaining loop iterations.\n**\n** On first sight that looks like a waste of space, because the variant\n** instructions are present twice. But the key insight is that the\n** pre-roll honors the control-dependencies for *both* the pre-roll itself\n** *and* the loop body!\n**\n** It also means one doesn't have to explicitly model control-dependencies\n** (which, BTW, wouldn't help LICM much). And it's much easier to\n** integrate sparse snapshotting with this approach.\n**\n** One of the nicest aspects of this approach is that all of the\n** optimizations of the compiler pipeline (FOLD, CSE, FWD, etc.) can be\n** reused with only minor restrictions (e.g. one should not fold\n** instructions across loop-carried dependencies).\n**\n** But in general all optimizations can be applied which only need to look\n** backwards into the generated instruction stream. At any point in time\n** during the copy-substitution process this contains both a static loop\n** iteration (the pre-roll) and a dynamic one (from the to-be-copied\n** instruction up to the end of the partial loop body).\n**\n** Since control-dependencies are implicitly kept, CSE also applies to all\n** kinds of guards. The major advantage is that all invariant guards can\n** be hoisted, too.\n**\n** Load/store forwarding works across loop iterations, too. This is\n** important if loop-carried dependencies are kept in upvalues or tables.\n** E.g. 'self.idx = self.idx + 1' deep down in some OO-style method may\n** become a forwarded loop-recurrence after inlining.\n**\n** Since the IR is in SSA form, loop-carried dependencies have to be\n** modeled with PHI instructions. The potential candidates for PHIs are\n** collected on-the-fly during copy-substitution. After eliminating the\n** redundant ones, PHI instructions are emitted *below* the loop body.\n**\n** Note that this departure from traditional SSA form doesn't change the\n** semantics of the PHI instructions themselves. But it greatly simplifies\n** on-the-fly generation of the IR and the machine code.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- PHI elimination ----------------------------------------------------- */\n\n/* Emit or eliminate collected PHIs. */\nstatic void loop_emit_phi(jit_State *J, IRRef1 *subst, IRRef1 *phi, IRRef nphi,\n\t\t\t  SnapNo onsnap)\n{\n  int passx = 0;\n  IRRef i, j, nslots;\n  IRRef invar = J->chain[IR_LOOP];\n  /* Pass #1: mark redundant and potentially redundant PHIs. */\n  for (i = 0, j = 0; i < nphi; i++) {\n    IRRef lref = phi[i];\n    IRRef rref = subst[lref];\n    if (lref == rref || rref == REF_DROP) {  /* Invariants are redundant. */\n      irt_clearphi(IR(lref)->t);\n    } else {\n      phi[j++] = (IRRef1)lref;\n      if (!(IR(rref)->op1 == lref || IR(rref)->op2 == lref)) {\n\t/* Quick check for simple recurrences failed, need pass2. */\n\tirt_setmark(IR(lref)->t);\n\tpassx = 1;\n      }\n    }\n  }\n  nphi = j;\n  /* Pass #2: traverse variant part and clear marks of non-redundant PHIs. */\n  if (passx) {\n    SnapNo s;\n    for (i = J->cur.nins-1; i > invar; i--) {\n      IRIns *ir = IR(i);\n      if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);\n      if (!irref_isk(ir->op1)) {\n\tirt_clearmark(IR(ir->op1)->t);\n\tif (ir->op1 < invar &&\n\t    ir->o >= IR_CALLN && ir->o <= IR_CARG) {  /* ORDER IR */\n\t  ir = IR(ir->op1);\n\t  while (ir->o == IR_CARG) {\n\t    if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);\n\t    if (irref_isk(ir->op1)) break;\n\t    ir = IR(ir->op1);\n\t    irt_clearmark(ir->t);\n\t  }\n\t}\n      }\n    }\n    for (s = J->cur.nsnap-1; s >= onsnap; s--) {\n      SnapShot *snap = &J->cur.snap[s];\n      SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n      MSize n, nent = snap->nent;\n      for (n = 0; n < nent; n++) {\n\tIRRef ref = snap_ref(map[n]);\n\tif (!irref_isk(ref)) irt_clearmark(IR(ref)->t);\n      }\n    }\n  }\n  /* Pass #3: add PHIs for variant slots without a corresponding SLOAD. */\n  nslots = J->baseslot+J->maxslot;\n  for (i = 1; i < nslots; i++) {\n    IRRef ref = tref_ref(J->slot[i]);\n    while (!irref_isk(ref) && ref != subst[ref]) {\n      IRIns *ir = IR(ref);\n      irt_clearmark(ir->t);  /* Unmark potential uses, too. */\n      if (irt_isphi(ir->t) || irt_ispri(ir->t))\n\tbreak;\n      irt_setphi(ir->t);\n      if (nphi >= LJ_MAX_PHI)\n\tlj_trace_err(J, LJ_TRERR_PHIOV);\n      phi[nphi++] = (IRRef1)ref;\n      ref = subst[ref];\n      if (ref > invar)\n\tbreak;\n    }\n  }\n  /* Pass #4: propagate non-redundant PHIs. */\n  while (passx) {\n    passx = 0;\n    for (i = 0; i < nphi; i++) {\n      IRRef lref = phi[i];\n      IRIns *ir = IR(lref);\n      if (!irt_ismarked(ir->t)) {  /* Propagate only from unmarked PHIs. */\n\tIRIns *irr = IR(subst[lref]);\n\tif (irt_ismarked(irr->t)) {  /* Right ref points to other PHI? */\n\t  irt_clearmark(irr->t);  /* Mark that PHI as non-redundant. */\n\t  passx = 1;  /* Retry. */\n\t}\n      }\n    }\n  }\n  /* Pass #5: emit PHI instructions or eliminate PHIs. */\n  for (i = 0; i < nphi; i++) {\n    IRRef lref = phi[i];\n    IRIns *ir = IR(lref);\n    if (!irt_ismarked(ir->t)) {  /* Emit PHI if not marked. */\n      IRRef rref = subst[lref];\n      if (rref > invar)\n\tirt_setphi(IR(rref)->t);\n      emitir_raw(IRT(IR_PHI, irt_type(ir->t)), lref, rref);\n    } else {  /* Otherwise eliminate PHI. */\n      irt_clearmark(ir->t);\n      irt_clearphi(ir->t);\n    }\n  }\n}\n\n/* -- Loop unrolling using copy-substitution ------------------------------ */\n\n/* Copy-substitute snapshot. */\nstatic void loop_subst_snap(jit_State *J, SnapShot *osnap,\n\t\t\t    SnapEntry *loopmap, IRRef1 *subst)\n{\n  SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs];\n  SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)];\n  MSize nmapofs;\n  MSize on, ln, nn, onent = osnap->nent;\n  BCReg nslots = osnap->nslots;\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap];\n  if (irt_isguard(J->guardemit)) {  /* Guard inbetween? */\n    nmapofs = J->cur.nsnapmap;\n    J->cur.nsnap++;  /* Add new snapshot. */\n  } else {  /* Otherwise overwrite previous snapshot. */\n    snap--;\n    nmapofs = snap->mapofs;\n  }\n  J->guardemit.irt = 0;\n  /* Setup new snapshot. */\n  snap->mapofs = (uint16_t)nmapofs;\n  snap->ref = (IRRef1)J->cur.nins;\n  snap->nslots = nslots;\n  snap->topslot = osnap->topslot;\n  snap->count = 0;\n  nmap = &J->cur.snapmap[nmapofs];\n  /* Substitute snapshot slots. */\n  on = ln = nn = 0;\n  while (on < onent) {\n    SnapEntry osn = omap[on], lsn = loopmap[ln];\n    if (snap_slot(lsn) < snap_slot(osn)) {  /* Copy slot from loop map. */\n      nmap[nn++] = lsn;\n      ln++;\n    } else {  /* Copy substituted slot from snapshot map. */\n      if (snap_slot(lsn) == snap_slot(osn)) ln++;  /* Shadowed loop slot. */\n      if (!irref_isk(snap_ref(osn)))\n\tosn = snap_setref(osn, subst[snap_ref(osn)]);\n      nmap[nn++] = osn;\n      on++;\n    }\n  }\n  while (snap_slot(loopmap[ln]) < nslots)  /* Copy remaining loop slots. */\n    nmap[nn++] = loopmap[ln++];\n  snap->nent = (uint8_t)nn;\n  omap += onent;\n  nmap += nn;\n  while (omap < nextmap)  /* Copy PC + frame links. */\n    *nmap++ = *omap++;\n  J->cur.nsnapmap = (uint16_t)(nmap - J->cur.snapmap);\n}\n\ntypedef struct LoopState {\n  jit_State *J;\n  IRRef1 *subst;\n  MSize sizesubst;\n} LoopState;\n\n/* Unroll loop. */\nstatic void loop_unroll(LoopState *lps)\n{\n  jit_State *J = lps->J;\n  IRRef1 phi[LJ_MAX_PHI];\n  uint32_t nphi = 0;\n  IRRef1 *subst;\n  SnapNo onsnap;\n  SnapShot *osnap, *loopsnap;\n  SnapEntry *loopmap, *psentinel;\n  IRRef ins, invar;\n\n  /* Allocate substitution table.\n  ** Only non-constant refs in [REF_BIAS,invar) are valid indexes.\n  */\n  invar = J->cur.nins;\n  lps->sizesubst = invar - REF_BIAS;\n  lps->subst = lj_mem_newvec(J->L, lps->sizesubst, IRRef1);\n  subst = lps->subst - REF_BIAS;\n  subst[REF_BASE] = REF_BASE;\n\n  /* LOOP separates the pre-roll from the loop body. */\n  emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0);\n\n  /* Grow snapshot buffer and map for copy-substituted snapshots.\n  ** Need up to twice the number of snapshots minus #0 and loop snapshot.\n  ** Need up to twice the number of entries plus fallback substitutions\n  ** from the loop snapshot entries for each new snapshot.\n  ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap!\n  */\n  onsnap = J->cur.nsnap;\n  lj_snap_grow_buf(J, 2*onsnap-2);\n  lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent);\n\n  /* The loop snapshot is used for fallback substitutions. */\n  loopsnap = &J->cur.snap[onsnap-1];\n  loopmap = &J->cur.snapmap[loopsnap->mapofs];\n  /* The PC of snapshot #0 and the loop snapshot must match. */\n  psentinel = &loopmap[loopsnap->nent];\n  lua_assert(*psentinel == J->cur.snapmap[J->cur.snap[0].nent]);\n  *psentinel = SNAP(255, 0, 0);  /* Replace PC with temporary sentinel. */\n\n  /* Start substitution with snapshot #1 (#0 is empty for root traces). */\n  osnap = &J->cur.snap[1];\n\n  /* Copy and substitute all recorded instructions and snapshots. */\n  for (ins = REF_FIRST; ins < invar; ins++) {\n    IRIns *ir;\n    IRRef op1, op2;\n\n    if (ins >= osnap->ref)  /* Instruction belongs to next snapshot? */\n      loop_subst_snap(J, osnap++, loopmap, subst);  /* Copy-substitute it. */\n\n    /* Substitute instruction operands. */\n    ir = IR(ins);\n    op1 = ir->op1;\n    if (!irref_isk(op1)) op1 = subst[op1];\n    op2 = ir->op2;\n    if (!irref_isk(op2)) op2 = subst[op2];\n    if (irm_kind(lj_ir_mode[ir->o]) == IRM_N &&\n\top1 == ir->op1 && op2 == ir->op2) {  /* Regular invariant ins? */\n      subst[ins] = (IRRef1)ins;  /* Shortcut. */\n    } else {\n      /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */\n      IRType1 t = ir->t;  /* Get this first, since emitir may invalidate ir. */\n      IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2));\n      subst[ins] = (IRRef1)ref;\n      if (ref != ins) {\n\tIRIns *irr = IR(ref);\n\tif (ref < invar) {  /* Loop-carried dependency? */\n\t  /* Potential PHI? */\n\t  if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) {\n\t    irt_setphi(irr->t);\n\t    if (nphi >= LJ_MAX_PHI)\n\t      lj_trace_err(J, LJ_TRERR_PHIOV);\n\t    phi[nphi++] = (IRRef1)ref;\n\t  }\n\t  /* Check all loop-carried dependencies for type instability. */\n\t  if (!irt_sametype(t, irr->t)) {\n\t    if (irt_isinteger(t) && irt_isinteger(irr->t))\n\t      continue;\n\t    else if (irt_isnum(t) && irt_isinteger(irr->t))  /* Fix int->num. */\n\t      ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT));\n\t    else if (irt_isnum(irr->t) && irt_isinteger(t))  /* Fix num->int. */\n\t      ref = tref_ref(emitir(IRTGI(IR_CONV), ref,\n\t\t\t\t    IRCONV_INT_NUM|IRCONV_CHECK));\n\t    else\n\t      lj_trace_err(J, LJ_TRERR_TYPEINS);\n\t    subst[ins] = (IRRef1)ref;\n\t    irr = IR(ref);\n\t    goto phiconv;\n\t  }\n\t} else if (ref != REF_DROP && irr->o == IR_CONV &&\n\t\t   ref > invar && irr->op1 < invar) {\n\t  /* May need an extra PHI for a CONV. */\n\t  ref = irr->op1;\n\t  irr = IR(ref);\n\tphiconv:\n\t  if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) {\n\t    irt_setphi(irr->t);\n\t    if (nphi >= LJ_MAX_PHI)\n\t      lj_trace_err(J, LJ_TRERR_PHIOV);\n\t    phi[nphi++] = (IRRef1)ref;\n\t  }\n\t}\n      }\n    }\n  }\n  if (!irt_isguard(J->guardemit))  /* Drop redundant snapshot. */\n    J->cur.nsnapmap = (uint16_t)J->cur.snap[--J->cur.nsnap].mapofs;\n  lua_assert(J->cur.nsnapmap <= J->sizesnapmap);\n  *psentinel = J->cur.snapmap[J->cur.snap[0].nent];  /* Restore PC. */\n\n  loop_emit_phi(J, subst, phi, nphi, onsnap);\n}\n\n/* Undo any partial changes made by the loop optimization. */\nstatic void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap)\n{\n  ptrdiff_t i;\n  SnapShot *snap = &J->cur.snap[nsnap-1];\n  SnapEntry *map = J->cur.snapmap;\n  map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent];  /* Restore PC. */\n  J->cur.nsnapmap = (uint16_t)nsnapmap;\n  J->cur.nsnap = nsnap;\n  J->guardemit.irt = 0;\n  lj_ir_rollback(J, ins);\n  for (i = 0; i < BPROP_SLOTS; i++) {  /* Remove backprop. cache entries. */\n    BPropEntry *bp = &J->bpropcache[i];\n    if (bp->val >= ins)\n      bp->key = 0;\n  }\n  for (ins--; ins >= REF_FIRST; ins--) {  /* Remove flags. */\n    IRIns *ir = IR(ins);\n    irt_clearphi(ir->t);\n    irt_clearmark(ir->t);\n  }\n}\n\n/* Protected callback for loop optimization. */\nstatic TValue *cploop_opt(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  UNUSED(L); UNUSED(dummy);\n  loop_unroll((LoopState *)ud);\n  return NULL;\n}\n\n/* Loop optimization. */\nint lj_opt_loop(jit_State *J)\n{\n  IRRef nins = J->cur.nins;\n  SnapNo nsnap = J->cur.nsnap;\n  MSize nsnapmap = J->cur.nsnapmap;\n  LoopState lps;\n  int errcode;\n  lps.J = J;\n  lps.subst = NULL;\n  lps.sizesubst = 0;\n  errcode = lj_vm_cpcall(J->L, NULL, &lps, cploop_opt);\n  lj_mem_freevec(J2G(J), lps.subst, lps.sizesubst, IRRef1);\n  if (LJ_UNLIKELY(errcode)) {\n    lua_State *L = J->L;\n    if (errcode == LUA_ERRRUN && tvisnumber(L->top-1)) {  /* Trace error? */\n      int32_t e = numberVint(L->top-1);\n      switch ((TraceError)e) {\n      case LJ_TRERR_TYPEINS:  /* Type instability. */\n      case LJ_TRERR_GFAIL:  /* Guard would always fail. */\n\t/* Unrolling via recording fixes many cases, e.g. a flipped boolean. */\n\tif (--J->instunroll < 0)  /* But do not unroll forever. */\n\t  break;\n\tL->top--;  /* Remove error object. */\n\tloop_undo(J, nins, nsnap, nsnapmap);\n\treturn 1;  /* Loop optimization failed, continue recording. */\n      default:\n\tbreak;\n      }\n    }\n    lj_err_throw(L, errcode);  /* Propagate all other errors. */\n  }\n  return 0;  /* Loop optimization is ok. */\n}\n\n#undef IR\n#undef emitir\n#undef emitir_raw\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_mem.c",
    "content": "/*\n** Memory access optimizations.\n** AA: Alias Analysis using high-level semantic disambiguation.\n** FWD: Load Forwarding (L2L) + Store Forwarding (S2L).\n** DSE: Dead-Store Elimination.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_mem_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_ircall.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n#define fins\t\t(&J->fold.ins)\n#define fleft\t\t(&J->fold.left)\n#define fright\t\t(&J->fold.right)\n\n/*\n** Caveat #1: return value is not always a TRef -- only use with tref_ref().\n** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold().\n*/\n\n/* Return values from alias analysis. */\ntypedef enum {\n  ALIAS_NO,\t/* The two refs CANNOT alias (exact). */\n  ALIAS_MAY,\t/* The two refs MAY alias (inexact). */\n  ALIAS_MUST\t/* The two refs MUST alias (exact). */\n} AliasRet;\n\n/* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */\n\n/* Simplified escape analysis: check for intervening stores. */\nstatic AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop)\n{\n  IRRef ref = (IRRef)(ir - J->cur.ir);  /* The ref that might be stored. */\n  for (ir++; ir < stop; ir++)\n    if (ir->op2 == ref &&\n\t(ir->o == IR_ASTORE || ir->o == IR_HSTORE ||\n\t ir->o == IR_USTORE || ir->o == IR_FSTORE))\n      return ALIAS_MAY;  /* Reference was stored and might alias. */\n  return ALIAS_NO;  /* Reference was not stored. */\n}\n\n/* Alias analysis for two different table references. */\nstatic AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb)\n{\n  IRIns *taba = IR(ta), *tabb = IR(tb);\n  int newa, newb;\n  lua_assert(ta != tb);\n  lua_assert(irt_istab(taba->t) && irt_istab(tabb->t));\n  /* Disambiguate new allocations. */\n  newa = (taba->o == IR_TNEW || taba->o == IR_TDUP);\n  newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP);\n  if (newa && newb)\n    return ALIAS_NO;  /* Two different allocations never alias. */\n  if (newb) {  /* At least one allocation? */\n    IRIns *tmp = taba; taba = tabb; tabb = tmp;\n  } else if (!newa) {\n    return ALIAS_MAY;  /* Anything else: we just don't know. */\n  }\n  return aa_escape(J, taba, tabb);\n}\n\n/* Alias analysis for array and hash access using key-based disambiguation. */\nstatic AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  IRRef ka = refa->op2;\n  IRRef kb = refb->op2;\n  IRIns *keya, *keyb;\n  IRRef ta, tb;\n  if (refa == refb)\n    return ALIAS_MUST;  /* Shortcut for same refs. */\n  keya = IR(ka);\n  if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); }\n  keyb = IR(kb);\n  if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); }\n  ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1;\n  tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1;\n  if (ka == kb) {\n    /* Same key. Check for same table with different ref (NEWREF vs. HREF). */\n    if (ta == tb)\n      return ALIAS_MUST;  /* Same key, same table. */\n    else\n      return aa_table(J, ta, tb);  /* Same key, possibly different table. */\n  }\n  if (irref_isk(ka) && irref_isk(kb))\n    return ALIAS_NO;  /* Different constant keys. */\n  if (refa->o == IR_AREF) {\n    /* Disambiguate array references based on index arithmetic. */\n    int32_t ofsa = 0, ofsb = 0;\n    IRRef basea = ka, baseb = kb;\n    lua_assert(refb->o == IR_AREF);\n    /* Gather base and offset from t[base] or t[base+-ofs]. */\n    if (keya->o == IR_ADD && irref_isk(keya->op2)) {\n      basea = keya->op1;\n      ofsa = IR(keya->op2)->i;\n      if (basea == kb && ofsa != 0)\n\treturn ALIAS_NO;  /* t[base+-ofs] vs. t[base]. */\n    }\n    if (keyb->o == IR_ADD && irref_isk(keyb->op2)) {\n      baseb = keyb->op1;\n      ofsb = IR(keyb->op2)->i;\n      if (ka == baseb && ofsb != 0)\n\treturn ALIAS_NO;  /* t[base] vs. t[base+-ofs]. */\n    }\n    if (basea == baseb && ofsa != ofsb)\n      return ALIAS_NO;  /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */\n  } else {\n    /* Disambiguate hash references based on the type of their keys. */\n    lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&\n\t       (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF));\n    if (!irt_sametype(keya->t, keyb->t))\n      return ALIAS_NO;  /* Different key types. */\n  }\n  if (ta == tb)\n    return ALIAS_MAY;  /* Same table, cannot disambiguate keys. */\n  else\n    return aa_table(J, ta, tb);  /* Try to disambiguate tables. */\n}\n\n/* Array and hash load forwarding. */\nstatic TRef fwd_ahload(jit_State *J, IRRef xref)\n{\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[fins->o+IRDELTA_L2S];\n  while (ref > xref) {\n    IRIns *store = IR(ref);\n    switch (aa_ahref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\n  /* No conflicting store (yet): const-fold loads from allocations. */\n  {\n    IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr;\n    IRRef tab = ir->op1;\n    ir = IR(tab);\n    if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) {\n      /* A NEWREF with a number key may end up pointing to the array part.\n      ** But it's referenced from HSTORE and not found in the ASTORE chain.\n      ** For now simply consider this a conflict without forwarding anything.\n      */\n      if (xr->o == IR_AREF) {\n\tIRRef ref2 = J->chain[IR_NEWREF];\n\twhile (ref2 > tab) {\n\t  IRIns *newref = IR(ref2);\n\t  if (irt_isnum(IR(newref->op2)->t))\n\t    goto cselim;\n\t  ref2 = newref->prev;\n\t}\n      }\n      /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF.\n      ** But the above search for conflicting stores was limited by xref.\n      ** So continue searching, limited by the TNEW/TDUP. Store forwarding\n      ** is ok, too. A conflict does NOT limit the search for a matching load.\n      */\n      while (ref > tab) {\n\tIRIns *store = IR(ref);\n\tswitch (aa_ahref(J, xr, IR(store->op1))) {\n\tcase ALIAS_NO:   break;  /* Continue searching. */\n\tcase ALIAS_MAY:  goto cselim;  /* Conflicting store. */\n\tcase ALIAS_MUST: return store->op2;  /* Store forwarding. */\n\t}\n\tref = store->prev;\n      }\n      lua_assert(ir->o != IR_TNEW || irt_isnil(fins->t));\n      if (irt_ispri(fins->t)) {\n\treturn TREF_PRI(irt_type(fins->t));\n      } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) ||\n\t\t irt_isstr(fins->t)) {\n\tTValue keyv;\n\tcTValue *tv;\n\tIRIns *key = IR(xr->op2);\n\tif (key->o == IR_KSLOT) key = IR(key->op1);\n\tlj_ir_kvalue(J->L, &keyv, key);\n\ttv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv);\n\tlua_assert(itype2irt(tv) == irt_type(fins->t));\n\tif (irt_isnum(fins->t))\n\t  return lj_ir_knum_u64(J, tv->u64);\n\telse if (LJ_DUALNUM && irt_isint(fins->t))\n\t  return lj_ir_kint(J, intV(tv));\n\telse\n\t  return lj_ir_kstr(J, strV(tv));\n      }\n      /* Othwerwise: don't intern as a constant. */\n    }\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  ref = J->chain[fins->o];\n  while (ref > lim) {\n    IRIns *load = IR(ref);\n    if (load->op1 == xref)\n      return ref;  /* Load forwarding. */\n    ref = load->prev;\n  }\n  return 0;  /* Conflict or no match. */\n}\n\n/* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */\nstatic TRef fwd_aload_reassoc(jit_State *J)\n{\n  IRIns *irx = IR(fins->op1);\n  IRIns *key = IR(irx->op2);\n  if (key->o == IR_ADD && irref_isk(key->op2)) {\n    IRIns *add2 = IR(key->op1);\n    if (add2->o == IR_ADD && irref_isk(add2->op2) &&\n\tIR(key->op2)->i == -IR(add2->op2)->i) {\n      IRRef ref = J->chain[IR_AREF];\n      IRRef lim = add2->op1;\n      if (irx->op1 > lim) lim = irx->op1;\n      while (ref > lim) {\n\tIRIns *ir = IR(ref);\n\tif (ir->op1 == irx->op1 && ir->op2 == add2->op1)\n\t  return fwd_ahload(J, ref);\n\tref = ir->prev;\n      }\n    }\n  }\n  return 0;\n}\n\n/* ALOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J)\n{\n  IRRef ref;\n  if ((ref = fwd_ahload(J, fins->op1)) ||\n      (ref = fwd_aload_reassoc(J)))\n    return ref;\n  return EMITFOLD;\n}\n\n/* HLOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J)\n{\n  IRRef ref = fwd_ahload(J, fins->op1);\n  if (ref)\n    return ref;\n  return EMITFOLD;\n}\n\n/* HREFK forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J)\n{\n  IRRef tab = fleft->op1;\n  IRRef ref = J->chain[IR_NEWREF];\n  while (ref > tab) {\n    IRIns *newref = IR(ref);\n    if (tab == newref->op1) {\n      if (fright->op1 == newref->op2)\n\treturn ref;  /* Forward from NEWREF. */\n      else\n\tgoto docse;\n    } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) {\n      goto docse;\n    }\n    ref = newref->prev;\n  }\n  /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */\n  if (IR(tab)->o == IR_TDUP)\n    fins->t.irt &= ~IRT_GUARD;  /* Drop HREFK guard. */\ndocse:\n  return CSEFOLD;\n}\n\n/* Check whether HREF of TNEW/TDUP can be folded to niltv. */\nint LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J)\n{\n  IRRef lim = fins->op1;  /* Search limit. */\n  IRRef ref;\n\n  /* The key for an ASTORE may end up in the hash part after a NEWREF. */\n  if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) {\n    ref = J->chain[IR_ASTORE];\n    while (ref > lim) {\n      if (ref < J->chain[IR_NEWREF])\n\treturn 0;  /* Conflict. */\n      ref = IR(ref)->prev;\n    }\n  }\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_HSTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO)\n      return 0;  /* Conflict. */\n    ref = store->prev;\n  }\n\n  return 1;  /* No conflict. Can fold to niltv. */\n}\n\n/* Check whether there's no aliasing table.clear. */\nstatic int fwd_aa_tab_clear(jit_State *J, IRRef lim, IRRef ta)\n{\n  IRRef ref = J->chain[IR_CALLS];\n  while (ref > lim) {\n    IRIns *calls = IR(ref);\n    if (calls->op2 == IRCALL_lj_tab_clear &&\n\t(ta == calls->op1 || aa_table(J, ta, calls->op1) != ALIAS_NO))\n      return 0;  /* Conflict. */\n    ref = calls->prev;\n  }\n  return 1;  /* No conflict. Can safely FOLD/CSE. */\n}\n\n/* Check whether there's no aliasing NEWREF/table.clear for the left operand. */\nint LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim)\n{\n  IRRef ta = fins->op1;\n  IRRef ref = J->chain[IR_NEWREF];\n  while (ref > lim) {\n    IRIns *newref = IR(ref);\n    if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO)\n      return 0;  /* Conflict. */\n    ref = newref->prev;\n  }\n  return fwd_aa_tab_clear(J, lim, ta);\n}\n\n/* ASTORE/HSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)\n{\n  IRRef xref = fins->op1;  /* xREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(xref);\n  IRRef1 *refp = &J->chain[fins->o];\n  IRRef ref = *refp;\n  while (ref > xref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_ahref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\t/* Store to MAYBE the same location. */\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\t/* Store to the same location. */\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards (includes conflicting loads). */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || ir->o == IR_CALLL)\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tstore->o = IR_NOP;\n\tstore->t.irt = IRT_NIL;\n\tstore->op1 = store->op2 = 0;\n\tstore->prev = 0;\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- ULOAD forwarding ---------------------------------------------------- */\n\n/* The current alias analysis for upvalues is very simplistic. It only\n** disambiguates between the unique upvalues of the same function.\n** This is good enough for now, since most upvalues are read-only.\n**\n** A more precise analysis would be feasible with the help of the parser:\n** generate a unique key for every upvalue, even across all prototypes.\n** Lacking a realistic use-case, it's unclear whether this is beneficial.\n*/\nstatic AliasRet aa_uref(IRIns *refa, IRIns *refb)\n{\n  if (refa->o != refb->o)\n    return ALIAS_NO;  /* Different UREFx type. */\n  if (refa->op1 == refb->op1) {  /* Same function. */\n    if (refa->op2 == refb->op2)\n      return ALIAS_MUST;  /* Same function, same upvalue idx. */\n    else\n      return ALIAS_NO;  /* Same function, different upvalue idx. */\n  } else {  /* Different functions, check disambiguation hash values. */\n    if (((refa->op2 ^ refb->op2) & 0xff))\n      return ALIAS_NO;  /* Upvalues with different hash values cannot alias. */\n    else\n      return ALIAS_MAY;  /* No conclusion can be drawn for same hash value. */\n  }\n}\n\n/* ULOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J)\n{\n  IRRef uref = fins->op1;\n  IRRef lim = REF_BASE;  /* Search limit. */\n  IRIns *xr = IR(uref);\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_USTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    switch (aa_uref(xr, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n\n  ref = J->chain[IR_ULOAD];\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op1 == uref ||\n\t(IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o))\n      return ref;  /* Match for identical or equal UREFx (non-CSEable UREFO). */\n    ref = ir->prev;\n  }\n  return lj_ir_emit(J);\n}\n\n/* USTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)\n{\n  IRRef xref = fins->op1;  /* xREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(xref);\n  IRRef1 *refp = &J->chain[IR_USTORE];\n  IRRef ref = *refp;\n  while (ref > xref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_uref(xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\t/* Store to MAYBE the same location. */\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\t/* Store to the same location. */\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards (includes conflicting loads). */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t))\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tstore->o = IR_NOP;\n\tstore->t.irt = IRT_NIL;\n\tstore->op1 = store->op2 = 0;\n\tstore->prev = 0;\n\tif (ref+1 < J->cur.nins &&\n\t    store[1].o == IR_OBAR && store[1].op1 == xref) {\n\t  IRRef1 *bp = &J->chain[IR_OBAR];\n\t  IRIns *obar;\n\t  for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp))\n\t    bp = &obar->prev;\n\t  /* Remove OBAR, too. */\n\t  *bp = obar->prev;\n\t  obar->o = IR_NOP;\n\t  obar->t.irt = IRT_NIL;\n\t  obar->op1 = obar->op2 = 0;\n\t  obar->prev = 0;\n\t}\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- FLOAD forwarding and FSTORE elimination ----------------------------- */\n\n/* Alias analysis for field access.\n** Field loads are cheap and field stores are rare.\n** Simple disambiguation based on field types is good enough.\n*/\nstatic AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  if (refa->op2 != refb->op2)\n    return ALIAS_NO;  /* Different fields. */\n  if (refa->op1 == refb->op1)\n    return ALIAS_MUST;  /* Same field, same object. */\n  else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM)\n    return aa_table(J, refa->op1, refb->op1);  /* Disambiguate tables. */\n  else\n    return ALIAS_MAY;  /* Same field, possibly different object. */\n}\n\n/* Only the loads for mutable fields end up here (see FOLD). */\nTRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J)\n{\n  IRRef oref = fins->op1;  /* Object reference. */\n  IRRef fid = fins->op2;  /* Field ID. */\n  IRRef lim = oref;  /* Search limit. */\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_FSTORE];\n  while (ref > oref) {\n    IRIns *store = IR(ref);\n    switch (aa_fref(J, fins, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\n  /* No conflicting store: const-fold field loads from allocations. */\n  if (fid == IRFL_TAB_META) {\n    IRIns *ir = IR(oref);\n    if (ir->o == IR_TNEW || ir->o == IR_TDUP)\n      return lj_ir_knull(J, IRT_TAB);\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  return lj_opt_cselim(J, lim);\n}\n\n/* FSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J)\n{\n  IRRef fref = fins->op1;  /* FREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(fref);\n  IRRef1 *refp = &J->chain[IR_FSTORE];\n  IRRef ref = *refp;\n  while (ref > fref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_fref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards or conflicting loads. */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2))\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tstore->o = IR_NOP;\n\tstore->t.irt = IRT_NIL;\n\tstore->op1 = store->op2 = 0;\n\tstore->prev = 0;\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- XLOAD forwarding and XSTORE elimination ----------------------------- */\n\n/* Find cdata allocation for a reference (if any). */\nstatic IRIns *aa_findcnew(jit_State *J, IRIns *ir)\n{\n  while (ir->o == IR_ADD) {\n    if (!irref_isk(ir->op1)) {\n      IRIns *ir1 = aa_findcnew(J, IR(ir->op1));  /* Left-recursion. */\n      if (ir1) return ir1;\n    }\n    if (irref_isk(ir->op2)) return NULL;\n    ir = IR(ir->op2);  /* Flatten right-recursion. */\n  }\n  return ir->o == IR_CNEW ? ir : NULL;\n}\n\n/* Alias analysis for two cdata allocations. */\nstatic AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  IRIns *cnewa = aa_findcnew(J, refa);\n  IRIns *cnewb = aa_findcnew(J, refb);\n  if (cnewa == cnewb)\n    return ALIAS_MAY;  /* Same allocation or neither is an allocation. */\n  if (cnewa && cnewb)\n    return ALIAS_NO;  /* Two different allocations never alias. */\n  if (cnewb) { cnewa = cnewb; refb = refa; }\n  return aa_escape(J, cnewa, refb);\n}\n\n/* Alias analysis for XLOAD/XSTORE. */\nstatic AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb)\n{\n  ptrdiff_t ofsa = 0, ofsb = 0;\n  IRIns *refb = IR(xb->op1);\n  IRIns *basea = refa, *baseb = refb;\n  if (refa == refb && irt_sametype(xa->t, xb->t))\n    return ALIAS_MUST;  /* Shortcut for same refs with identical type. */\n  /* Offset-based disambiguation. */\n  if (refa->o == IR_ADD && irref_isk(refa->op2)) {\n    IRIns *irk = IR(refa->op2);\n    basea = IR(refa->op1);\n    ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t    (ptrdiff_t)irk->i;\n  }\n  if (refb->o == IR_ADD && irref_isk(refb->op2)) {\n    IRIns *irk = IR(refb->op2);\n    baseb = IR(refb->op1);\n    ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t    (ptrdiff_t)irk->i;\n  }\n  /* Treat constified pointers like base vs. base+offset. */\n  if (basea->o == IR_KPTR && baseb->o == IR_KPTR) {\n    ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea);\n    baseb = basea;\n  }\n  /* This implements (very) strict aliasing rules.\n  ** Different types do NOT alias, except for differences in signedness.\n  ** Type punning through unions is allowed (but forces a reload).\n  */\n  if (basea == baseb) {\n    ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t);\n    if (ofsa == ofsb) {\n      if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t))\n\treturn ALIAS_MUST;  /* Same-sized, same-kind. May need to convert. */\n    } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) {\n      return ALIAS_NO;  /* Non-overlapping base+-o1 vs. base+-o2. */\n    }\n    /* NYI: extract, extend or reinterpret bits (int <-> fp). */\n    return ALIAS_MAY;  /* Overlapping or type punning: force reload. */\n  }\n  if (!irt_sametype(xa->t, xb->t) &&\n      !(irt_typerange(xa->t, IRT_I8, IRT_U64) &&\n\t((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1))\n    return ALIAS_NO;\n  /* NYI: structural disambiguation. */\n  return aa_cnew(J, basea, baseb);  /* Try to disambiguate allocations. */\n}\n\n/* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */\nstatic IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2)\n{\n  IRRef ref = J->chain[op];\n  IRRef lim = op1;\n  if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; }\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op1 == op1 && ir->op2 == op2)\n      return ref;\n    ref = ir->prev;\n  }\n  return 0;\n}\n\n/* Reassociate index references. */\nstatic IRRef reassoc_xref(jit_State *J, IRIns *ir)\n{\n  ptrdiff_t ofs = 0;\n  if (ir->o == IR_ADD && irref_isk(ir->op2)) {  /* Get constant offset. */\n    IRIns *irk = IR(ir->op2);\n    ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t   (ptrdiff_t)irk->i;\n    ir = IR(ir->op1);\n  }\n  if (ir->o == IR_ADD) {  /* Add of base + index. */\n    /* Index ref > base ref for loop-carried dependences. Only check op1. */\n    IRIns *ir2, *ir1 = IR(ir->op1);\n    int32_t shift = 0;\n    IRRef idxref;\n    /* Determine index shifts. Don't bother with IR_MUL here. */\n    if (ir1->o == IR_BSHL && irref_isk(ir1->op2))\n      shift = IR(ir1->op2)->i;\n    else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2)\n      shift = 1;\n    else\n      ir1 = ir;\n    ir2 = IR(ir1->op1);\n    /* A non-reassociated add. Must be a loop-carried dependence. */\n    if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2))\n      ofs += (ptrdiff_t)IR(ir2->op2)->i << shift;\n    else\n      return 0;\n    idxref = ir2->op1;\n    /* Try to CSE the reassociated chain. Give up if not found. */\n    if (ir1 != ir &&\n\t!(idxref = reassoc_trycse(J, ir1->o, idxref,\n\t\t\t\t  ir1->o == IR_BSHL ? ir1->op2 : idxref)))\n      return 0;\n    if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2)))\n      return 0;\n    if (ofs != 0) {\n      IRRef refk = tref_ref(lj_ir_kintp(J, ofs));\n      if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk)))\n\treturn 0;\n    }\n    return idxref;  /* Success, found a reassociated index reference. Phew. */\n  }\n  return 0;  /* Failure. */\n}\n\n/* XLOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J)\n{\n  IRRef xref = fins->op1;\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef ref;\n\n  if ((fins->op2 & IRXLOAD_READONLY))\n    goto cselim;\n  if ((fins->op2 & IRXLOAD_VOLATILE))\n    goto doemit;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_XSTORE];\nretry:\n  if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];\n  if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    switch (aa_xref(J, xr, fins, store)) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST:\n      /* Emit conversion if the loaded type doesn't match the forwarded type. */\n      if (!irt_sametype(fins->t, IR(store->op2)->t)) {\n\tIRType dt = irt_type(fins->t), st = irt_type(IR(store->op2)->t);\n\tif (dt == IRT_I8 || dt == IRT_I16) {  /* Trunc + sign-extend. */\n\t  st = dt | IRCONV_SEXT;\n\t  dt = IRT_INT;\n\t} else if (dt == IRT_U8 || dt == IRT_U16) {  /* Trunc + zero-extend. */\n\t  st = dt;\n\t  dt = IRT_INT;\n\t}\n\tfins->ot = IRT(IR_CONV, dt);\n\tfins->op1 = store->op2;\n\tfins->op2 = (dt<<5)|st;\n\treturn RETRYFOLD;\n      }\n      return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  ref = J->chain[IR_XLOAD];\n  while (ref > lim) {\n    /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */\n    if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t))\n      return ref;\n    ref = IR(ref)->prev;\n  }\n\n  /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */\n  if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] &&\n      xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) {\n    ref = J->chain[IR_XSTORE];\n    while (ref > lim)  /* Skip stores that have already been checked. */\n      ref = IR(ref)->prev;\n    lim = xref;\n    xr = IR(xref);\n    goto retry;  /* Retry with the reassociated reference. */\n  }\ndoemit:\n  return EMITFOLD;\n}\n\n/* XSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J)\n{\n  IRRef xref = fins->op1;\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRRef1 *refp = &J->chain[IR_XSTORE];\n  IRRef ref = *refp;\n  if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];\n  if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];\n  if (J->chain[IR_XSNEW] > lim) lim = J->chain[IR_XSNEW];\n  while (ref > lim) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_xref(J, xr, fins, store)) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards or any XLOADs (no AA performed). */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || ir->o == IR_XLOAD)\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tstore->o = IR_NOP;\n\tstore->t.irt = IRT_NIL;\n\tstore->op1 = store->op2 = 0;\n\tstore->prev = 0;\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- Forwarding of lj_tab_len -------------------------------------------- */\n\n/* This is rather simplistic right now, but better than nothing. */\nTRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J)\n{\n  IRRef tab = fins->op1;  /* Table reference. */\n  IRRef lim = tab;  /* Search limit. */\n  IRRef ref;\n\n  /* Any ASTORE is a conflict and limits the search. */\n  if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE];\n\n  /* Search for conflicting HSTORE with numeric key. */\n  ref = J->chain[IR_HSTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    IRIns *href = IR(store->op1);\n    IRIns *key = IR(href->op2);\n    if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {\n      lim = ref;  /* Conflicting store found, limits search for TLEN. */\n      break;\n    }\n    ref = store->prev;\n  }\n\n  /* Search for aliasing table.clear. */\n  if (!fwd_aa_tab_clear(J, lim, tab))\n    return lj_ir_emit(J);\n\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  return lj_opt_cselim(J, lim);\n}\n\n/* -- ASTORE/HSTORE previous type analysis -------------------------------- */\n\n/* Check whether the previous value for a table store is non-nil.\n** This can be derived either from a previous store or from a previous\n** load (because all loads from tables perform a type check).\n**\n** The result of the analysis can be used to avoid the metatable check\n** and the guard against HREF returning niltv. Both of these are cheap,\n** so let's not spend too much effort on the analysis.\n**\n** A result of 1 is exact: previous value CANNOT be nil.\n** A result of 0 is inexact: previous value MAY be nil.\n*/\nint lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref)\n{\n  /* First check stores. */\n  IRRef ref = J->chain[loadop+IRDELTA_L2S];\n  while (ref > xref) {\n    IRIns *store = IR(ref);\n    if (store->op1 == xref) {  /* Same xREF. */\n      /* A nil store MAY alias, but a non-nil store MUST alias. */\n      return !irt_isnil(store->t);\n    } else if (irt_isnil(store->t)) {  /* Must check any nil store. */\n      IRRef skref = IR(store->op1)->op2;\n      IRRef xkref = IR(xref)->op2;\n      /* Same key type MAY alias. Need ALOAD check due to multiple int types. */\n      if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) {\n\tif (skref == xkref || !irref_isk(skref) || !irref_isk(xkref))\n\t  return 0;  /* A nil store with same const key or var key MAY alias. */\n\t/* Different const keys CANNOT alias. */\n      }  /* Different key types CANNOT alias. */\n    }  /* Other non-nil stores MAY alias. */\n    ref = store->prev;\n  }\n\n  /* Check loads since nothing could be derived from stores. */\n  ref = J->chain[loadop];\n  while (ref > xref) {\n    IRIns *load = IR(ref);\n    if (load->op1 == xref) {  /* Same xREF. */\n      /* A nil load MAY alias, but a non-nil load MUST alias. */\n      return !irt_isnil(load->t);\n    }  /* Other non-nil loads MAY alias. */\n    ref = load->prev;\n  }\n  return 0;  /* Nothing derived at all, previous value MAY be nil. */\n}\n\n/* ------------------------------------------------------------------------ */\n\n#undef IR\n#undef fins\n#undef fleft\n#undef fright\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_narrow.c",
    "content": "/*\n** NARROW: Narrowing of numbers to integers (double to int32_t).\n** STRIPOV: Stripping of overflow checks.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_narrow_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n\n/* Rationale for narrowing optimizations:\n**\n** Lua has only a single number type and this is a FP double by default.\n** Narrowing doubles to integers does not pay off for the interpreter on a\n** current-generation x86/x64 machine. Most FP operations need the same\n** amount of execution resources as their integer counterparts, except\n** with slightly longer latencies. Longer latencies are a non-issue for\n** the interpreter, since they are usually hidden by other overhead.\n**\n** The total CPU execution bandwidth is the sum of the bandwidth of the FP\n** and the integer units, because they execute in parallel. The FP units\n** have an equal or higher bandwidth than the integer units. Not using\n** them means losing execution bandwidth. Moving work away from them to\n** the already quite busy integer units is a losing proposition.\n**\n** The situation for JIT-compiled code is a bit different: the higher code\n** density makes the extra latencies much more visible. Tight loops expose\n** the latencies for updating the induction variables. Array indexing\n** requires narrowing conversions with high latencies and additional\n** guards (to check that the index is really an integer). And many common\n** optimizations only work on integers.\n**\n** One solution would be speculative, eager narrowing of all number loads.\n** This causes many problems, like losing -0 or the need to resolve type\n** mismatches between traces. It also effectively forces the integer type\n** to have overflow-checking semantics. This impedes many basic\n** optimizations and requires adding overflow checks to all integer\n** arithmetic operations (whereas FP arithmetics can do without).\n**\n** Always replacing an FP op with an integer op plus an overflow check is\n** counter-productive on a current-generation super-scalar CPU. Although\n** the overflow check branches are highly predictable, they will clog the\n** execution port for the branch unit and tie up reorder buffers. This is\n** turning a pure data-flow dependency into a different data-flow\n** dependency (with slightly lower latency) *plus* a control dependency.\n** In general, you don't want to do this since latencies due to data-flow\n** dependencies can be well hidden by out-of-order execution.\n**\n** A better solution is to keep all numbers as FP values and only narrow\n** when it's beneficial to do so. LuaJIT uses predictive narrowing for\n** induction variables and demand-driven narrowing for index expressions,\n** integer arguments and bit operations. Additionally it can eliminate or\n** hoist most of the resulting overflow checks. Regular arithmetic\n** computations are never narrowed to integers.\n**\n** The integer type in the IR has convenient wrap-around semantics and\n** ignores overflow. Extra operations have been added for\n** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type.\n** Apart from reducing overall complexity of the compiler, this also\n** nicely solves the problem where you want to apply algebraic\n** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can\n** use lea instead of an add for integer ADD, but not for ADDOV (lea does\n** not affect the flags, but it helps to avoid register moves).\n**\n**\n** All of the above has to be reconsidered for architectures with slow FP\n** operations or without a hardware FPU. The dual-number mode of LuaJIT\n** addresses this issue. Arithmetic operations are performed on integers\n** as far as possible and overflow checks are added as needed.\n**\n** This implies that narrowing for integer arguments and bit operations\n** should also strip overflow checks, e.g. replace ADDOV with ADD. The\n** original overflow guards are weak and can be eliminated by DCE, if\n** there's no other use.\n**\n** A slight twist is that it's usually beneficial to use overflow-checked\n** integer arithmetics if all inputs are already integers. This is the only\n** change that affects the single-number mode, too.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n#define fins\t\t\t(&J->fold.ins)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Elimination of narrowing type conversions --------------------------- */\n\n/* Narrowing of index expressions and bit operations is demand-driven. The\n** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT)\n** in all of these cases (e.g. array indexing or string indexing). FOLD\n** already takes care of eliminating simple redundant conversions like\n** CONV.int.num(CONV.num.int(x)) ==> x.\n**\n** But the surrounding code is FP-heavy and arithmetic operations are\n** performed on FP numbers (for the single-number mode). Consider a common\n** example such as 'x=t[i+1]', with 'i' already an integer (due to induction\n** variable narrowing). The index expression would be recorded as\n**   CONV.int.num(ADD(CONV.num.int(i), 1))\n** which is clearly suboptimal.\n**\n** One can do better by recursively backpropagating the narrowing type\n** conversion across FP arithmetic operations. This turns FP ops into\n** their corresponding integer counterparts. Depending on the semantics of\n** the conversion they also need to check for overflow. Currently only ADD\n** and SUB are supported.\n**\n** The above example can be rewritten as\n**   ADDOV(CONV.int.num(CONV.num.int(i)), 1)\n** and then into ADDOV(i, 1) after folding of the conversions. The original\n** FP ops remain in the IR and are eliminated by DCE since all references to\n** them are gone.\n**\n** [In dual-number mode the trace recorder already emits ADDOV etc., but\n** this can be further reduced. See below.]\n**\n** Special care has to be taken to avoid narrowing across an operation\n** which is potentially operating on non-integral operands. One obvious\n** case is when an expression contains a non-integral constant, but ends\n** up as an integer index at runtime (like t[x+1.5] with x=0.5).\n**\n** Operations with two non-constant operands illustrate a similar problem\n** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there,\n** unless it can be proven that either operand is integral (e.g. by CSEing\n** a previous conversion). As a not-so-obvious corollary this logic also\n** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]).\n**\n** Correctness of the transformation is guaranteed by avoiding to expand\n** the tree by adding more conversions than the one we would need to emit\n** if not backpropagating. TOBIT employs a more optimistic rule, because\n** the conversion has special semantics, designed to make the life of the\n** compiler writer easier. ;-)\n**\n** Using on-the-fly backpropagation of an expression tree doesn't work\n** because it's unknown whether the transform is correct until the end.\n** This either requires IR rollback and cache invalidation for every\n** subtree or a two-pass algorithm. The former didn't work out too well,\n** so the code now combines a recursive collector with a stack-based\n** emitter.\n**\n** [A recursive backpropagation algorithm with backtracking, employing\n** skip-list lookup and round-robin caching, emitting stack operations\n** on-the-fly for a stack-based interpreter -- and all of that in a meager\n** kilobyte? Yep, compilers are a great treasure chest. Throw away your\n** textbooks and read the codebase of a compiler today!]\n**\n** There's another optimization opportunity for array indexing: it's\n** always accompanied by an array bounds-check. The outermost overflow\n** check may be delegated to the ABC operation. This works because ABC is\n** an unsigned comparison and wrap-around due to overflow creates negative\n** numbers.\n**\n** But this optimization is only valid for constants that cannot overflow\n** an int32_t into the range of valid array indexes [0..2^27+1). A check\n** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30\n** wraps to -2^30-1.\n**\n** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are\n** quite common. So the above example finally ends up as ADD(i, 1)!\n**\n** Later on, the assembler is able to fuse the whole array reference and\n** the ADD into the memory operands of loads and other instructions. This\n** is why LuaJIT is able to generate very pretty (and fast) machine code\n** for array indexing. And that, my dear, concludes another story about\n** one of the hidden secrets of LuaJIT ...\n*/\n\n/* Maximum backpropagation depth and maximum stack size. */\n#define NARROW_MAX_BACKPROP\t100\n#define NARROW_MAX_STACK\t256\n\n/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1]\n** The lower 16 bits hold a reference (or 0). The upper 16 bits hold\n** the IR opcode + type or one of the following special opcodes:\n*/\nenum {\n  NARROW_REF,\t\t/* Push ref. */\n  NARROW_CONV,\t\t/* Push conversion of ref. */\n  NARROW_SEXT,\t\t/* Push sign-extension of ref. */\n  NARROW_INT\t\t/* Push KINT ref. The next code holds an int32_t. */\n};\n\ntypedef uint32_t NarrowIns;\n\n#define NARROWINS(op, ref)\t(((op) << 16) + (ref))\n#define narrow_op(ins)\t\t((IROpT)((ins) >> 16))\n#define narrow_ref(ins)\t\t((IRRef1)(ins))\n\n/* Context used for narrowing of type conversions. */\ntypedef struct NarrowConv {\n  jit_State *J;\t\t/* JIT compiler state. */\n  NarrowIns *sp;\t/* Current stack pointer. */\n  NarrowIns *maxsp;\t/* Maximum stack pointer minus redzone. */\n  IRRef mode;\t\t/* Conversion mode (IRCONV_*). */\n  IRType t;\t\t/* Destination type: IRT_INT or IRT_I64. */\n  NarrowIns stack[NARROW_MAX_STACK];  /* Stack holding stack-machine code. */\n} NarrowConv;\n\n/* Lookup a reference in the backpropagation cache. */\nstatic BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode)\n{\n  ptrdiff_t i;\n  for (i = 0; i < BPROP_SLOTS; i++) {\n    BPropEntry *bp = &J->bpropcache[i];\n    /* Stronger checks are ok, too. */\n    if (bp->key == key && bp->mode >= mode &&\n\t((bp->mode ^ mode) & IRCONV_MODEMASK) == 0)\n      return bp;\n  }\n  return NULL;\n}\n\n/* Add an entry to the backpropagation cache. */\nstatic void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode)\n{\n  uint32_t slot = J->bpropslot;\n  BPropEntry *bp = &J->bpropcache[slot];\n  J->bpropslot = (slot + 1) & (BPROP_SLOTS-1);\n  bp->key = key;\n  bp->val = val;\n  bp->mode = mode;\n}\n\n/* Backpropagate overflow stripping. */\nstatic void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth)\n{\n  jit_State *J = nc->J;\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_ADDOV || ir->o == IR_SUBOV ||\n      (ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) {\n    BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT);\n    if (bp) {\n      ref = bp->val;\n    } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {\n      NarrowIns *savesp = nc->sp;\n      narrow_stripov_backprop(nc, ir->op1, depth);\n      if (nc->sp < nc->maxsp) {\n\tnarrow_stripov_backprop(nc, ir->op2, depth);\n\tif (nc->sp < nc->maxsp) {\n\t  *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);\n\t  return;\n\t}\n      }\n      nc->sp = savesp;  /* Path too deep, need to backtrack. */\n    }\n  }\n  *nc->sp++ = NARROWINS(NARROW_REF, ref);\n}\n\n/* Backpropagate narrowing conversion. Return number of needed conversions. */\nstatic int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)\n{\n  jit_State *J = nc->J;\n  IRIns *ir = IR(ref);\n  IRRef cref;\n\n  if (nc->sp >= nc->maxsp) return 10;  /* Path too deep. */\n\n  /* Check the easy cases first. */\n  if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY)\n      narrow_stripov_backprop(nc, ir->op1, depth+1);\n    else\n      *nc->sp++ = NARROWINS(NARROW_REF, ir->op1);  /* Undo conversion. */\n    if (nc->t == IRT_I64)\n      *nc->sp++ = NARROWINS(NARROW_SEXT, 0);  /* Sign-extend integer. */\n    return 0;\n  } else if (ir->o == IR_KNUM) {  /* Narrow FP constant. */\n    lua_Number n = ir_knum(ir)->n;\n    if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) {\n      /* Allows a wider range of constants. */\n      int64_t k64 = (int64_t)n;\n      if (n == (lua_Number)k64) {  /* Only if const doesn't lose precision. */\n\t*nc->sp++ = NARROWINS(NARROW_INT, 0);\n\t*nc->sp++ = (NarrowIns)k64;  /* But always truncate to 32 bits. */\n\treturn 0;\n      }\n    } else {\n      int32_t k = lj_num2int(n);\n      /* Only if constant is a small integer. */\n      if (checki16(k) && n == (lua_Number)k) {\n\t*nc->sp++ = NARROWINS(NARROW_INT, 0);\n\t*nc->sp++ = (NarrowIns)k;\n\treturn 0;\n      }\n    }\n    return 10;  /* Never narrow other FP constants (this is rare). */\n  }\n\n  /* Try to CSE the conversion. Stronger checks are ok, too. */\n  cref = J->chain[fins->o];\n  while (cref > ref) {\n    IRIns *cr = IR(cref);\n    if (cr->op1 == ref &&\n\t(fins->o == IR_TOBIT ||\n\t ((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) &&\n\t  irt_isguard(cr->t) >= irt_isguard(fins->t)))) {\n      *nc->sp++ = NARROWINS(NARROW_REF, cref);\n      return 0;  /* Already there, no additional conversion needed. */\n    }\n    cref = cr->prev;\n  }\n\n  /* Backpropagate across ADD/SUB. */\n  if (ir->o == IR_ADD || ir->o == IR_SUB) {\n    /* Try cache lookup first. */\n    IRRef mode = nc->mode;\n    BPropEntry *bp;\n    /* Inner conversions need a stronger check. */\n    if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0)\n      mode += IRCONV_CHECK-IRCONV_INDEX;\n    bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);\n    if (bp) {\n      *nc->sp++ = NARROWINS(NARROW_REF, bp->val);\n      return 0;\n    } else if (nc->t == IRT_I64) {\n      /* Try sign-extending from an existing (checked) conversion to int. */\n      mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX;\n      bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);\n      if (bp) {\n\t*nc->sp++ = NARROWINS(NARROW_REF, bp->val);\n\t*nc->sp++ = NARROWINS(NARROW_SEXT, 0);\n\treturn 0;\n      }\n    }\n    if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {\n      NarrowIns *savesp = nc->sp;\n      int count = narrow_conv_backprop(nc, ir->op1, depth);\n      count += narrow_conv_backprop(nc, ir->op2, depth);\n      if (count <= 1) {  /* Limit total number of conversions. */\n\t*nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);\n\treturn count;\n      }\n      nc->sp = savesp;  /* Too many conversions, need to backtrack. */\n    }\n  }\n\n  /* Otherwise add a conversion. */\n  *nc->sp++ = NARROWINS(NARROW_CONV, ref);\n  return 1;\n}\n\n/* Emit the conversions collected during backpropagation. */\nstatic IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc)\n{\n  /* The fins fields must be saved now -- emitir() overwrites them. */\n  IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0;\n  IROpT convot = fins->ot;\n  IRRef1 convop2 = fins->op2;\n  NarrowIns *next = nc->stack;  /* List of instructions from backpropagation. */\n  NarrowIns *last = nc->sp;\n  NarrowIns *sp = nc->stack;  /* Recycle the stack to store operands. */\n  while (next < last) {  /* Simple stack machine to process the ins. list. */\n    NarrowIns ref = *next++;\n    IROpT op = narrow_op(ref);\n    if (op == NARROW_REF) {\n      *sp++ = ref;\n    } else if (op == NARROW_CONV) {\n      *sp++ = emitir_raw(convot, ref, convop2);  /* Raw emit avoids a loop. */\n    } else if (op == NARROW_SEXT) {\n      lua_assert(sp >= nc->stack+1);\n      sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1],\n\t\t      (IRT_I64<<5)|IRT_INT|IRCONV_SEXT);\n    } else if (op == NARROW_INT) {\n      lua_assert(next < last);\n      *sp++ = nc->t == IRT_I64 ?\n\t      lj_ir_kint64(J, (int64_t)(int32_t)*next++) :\n\t      lj_ir_kint(J, *next++);\n    } else {  /* Regular IROpT. Pops two operands and pushes one result. */\n      IRRef mode = nc->mode;\n      lua_assert(sp >= nc->stack+2);\n      sp--;\n      /* Omit some overflow checks for array indexing. See comments above. */\n      if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) {\n\tif (next == last && irref_isk(narrow_ref(sp[0])) &&\n\t  (uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u)\n\t  guardot = 0;\n\telse  /* Otherwise cache a stronger check. */\n\t  mode += IRCONV_CHECK-IRCONV_INDEX;\n      }\n      sp[-1] = emitir(op+guardot, sp[-1], sp[0]);\n      /* Add to cache. */\n      if (narrow_ref(ref))\n\tnarrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode);\n    }\n  }\n  lua_assert(sp == nc->stack+1);\n  return nc->stack[0];\n}\n\n/* Narrow a type conversion of an arithmetic operation. */\nTRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J)\n{\n  if ((J->flags & JIT_F_OPT_NARROW)) {\n    NarrowConv nc;\n    nc.J = J;\n    nc.sp = nc.stack;\n    nc.maxsp = &nc.stack[NARROW_MAX_STACK-4];\n    nc.t = irt_type(fins->t);\n    if (fins->o == IR_TOBIT) {\n      nc.mode = IRCONV_TOBIT;  /* Used only in the backpropagation cache. */\n    } else {\n      nc.mode = fins->op2;\n    }\n    if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1)\n      return narrow_conv_emit(J, &nc);\n  }\n  return NEXTFOLD;\n}\n\n/* -- Narrowing of implicit conversions ----------------------------------- */\n\n/* Recursively strip overflow checks. */\nstatic TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode)\n{\n  IRRef ref = tref_ref(tr);\n  IRIns *ir = IR(ref);\n  int op = ir->o;\n  if (op >= IR_ADDOV && op <= lastop) {\n    BPropEntry *bp = narrow_bpc_get(J, ref, mode);\n    if (bp) {\n      return TREF(bp->val, irt_t(IR(bp->val)->t));\n    } else {\n      IRRef op1 = ir->op1, op2 = ir->op2;  /* The IR may be reallocated. */\n      op1 = narrow_stripov(J, op1, lastop, mode);\n      op2 = narrow_stripov(J, op2, lastop, mode);\n      tr = emitir(IRT(op - IR_ADDOV + IR_ADD,\n\t\t      ((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2);\n      narrow_bpc_set(J, ref, tref_ref(tr), mode);\n    }\n  } else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) {\n    tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode);\n  }\n  return tr;\n}\n\n/* Narrow array index. */\nTRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr)\n{\n  IRIns *ir;\n  lua_assert(tref_isnumber(tr));\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX);\n  /* Omit some overflow checks for array indexing. See comments above. */\n  ir = IR(tref_ref(tr));\n  if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) &&\n      (uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u)\n    return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2);\n  return tr;\n}\n\n/* Narrow conversion to integer operand (overflow undefined). */\nTRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr)\n{\n  if (tref_isstr(tr))\n    tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY);\n  if (!tref_isinteger(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  /*\n  ** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV.\n  ** Use IRCONV_TOBIT for the cache entries, since the semantics are the same.\n  */\n  return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);\n}\n\n/* Narrow conversion to bitop operand (overflow wrapped). */\nTRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr)\n{\n  if (tref_isstr(tr))\n    tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J));\n  if (!tref_isinteger(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  /*\n  ** Wrapped overflow semantics allow stripping of ADDOV and SUBOV.\n  ** MULOV cannot be stripped due to precision widening.\n  */\n  return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);\n}\n\n#if LJ_HASFFI\n/* Narrow C array index (overflow undefined). */\nTRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr)\n{\n  lua_assert(tref_isnumber(tr));\n  if (tref_isnum(tr))\n    return emitir(IRT(IR_CONV, IRT_INTP), tr, (IRT_INTP<<5)|IRT_NUM|IRCONV_ANY);\n  /* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */\n  return narrow_stripov(J, tr, IR_MULOV,\n\t\t\tLJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) :\n\t\t\t\t((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT));\n}\n#endif\n\n/* -- Narrowing of arithmetic operators ----------------------------------- */\n\n/* Check whether a number fits into an int32_t (-0 is ok, too). */\nstatic int numisint(lua_Number n)\n{\n  return (n == (lua_Number)lj_num2int(n));\n}\n\n/* Narrowing of arithmetic operations. */\nTRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,\n\t\t\t TValue *vb, TValue *vc, IROp op)\n{\n  if (tref_isstr(rb)) {\n    rb = emitir(IRTG(IR_STRTO, IRT_NUM), rb, 0);\n    lj_strscan_num(strV(vb), vb);\n  }\n  if (tref_isstr(rc)) {\n    rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);\n    lj_strscan_num(strV(vc), vc);\n  }\n  /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */\n  if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) &&\n      tref_isinteger(rb) && tref_isinteger(rc) &&\n      numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc),\n\t\t\t       (int)op - (int)IR_ADD)))\n    return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc);\n  if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT);\n  if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n  return emitir(IRTN(op), rb, rc);\n}\n\n/* Narrowing of unary minus operator. */\nTRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc)\n{\n  if (tref_isstr(rc)) {\n    rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);\n    lj_strscan_num(strV(vc), vc);\n  }\n  if (tref_isinteger(rc)) {\n    if ((uint32_t)numberVint(vc) != 0x80000000u)\n      return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc);\n    rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n  }\n  return emitir(IRTN(IR_NEG), rc, lj_ir_knum_neg(J));\n}\n\n/* Narrowing of modulo operator. */\nTRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc)\n{\n  TRef tmp;\n  if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) &&\n      tref_isinteger(rb) && tref_isinteger(rc) &&\n      (tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) {\n    emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0));\n    return emitir(IRTI(IR_MOD), rb, rc);\n  }\n  /* b % c ==> b - floor(b/c)*c */\n  rb = lj_ir_tonum(J, rb);\n  rc = lj_ir_tonum(J, rc);\n  tmp = emitir(IRTN(IR_DIV), rb, rc);\n  tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR);\n  tmp = emitir(IRTN(IR_MUL), tmp, rc);\n  return emitir(IRTN(IR_SUB), rb, tmp);\n}\n\n/* Narrowing of power operator or math.pow. */\nTRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc)\n{\n  if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  /* Narrowing must be unconditional to preserve (-x)^i semantics. */\n  if (tvisint(vc) || numisint(numV(vc))) {\n    int checkrange = 0;\n    /* Split pow is faster for bigger exponents. But do this only for (+k)^i. */\n    if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) {\n      int32_t k = numberVint(vc);\n      if (!(k >= -65536 && k <= 65536)) goto split_pow;\n      checkrange = 1;\n    }\n    if (!tref_isinteger(rc)) {\n      if (tref_isstr(rc))\n\trc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);\n      /* Guarded conversion to integer! */\n      rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK);\n    }\n    if (checkrange && !tref_isk(rc)) {  /* Range guard: -65536 <= i <= 65536 */\n      TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536));\n      emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536));\n    }\n    return emitir(IRTN(IR_POW), rb, rc);\n  }\nsplit_pow:\n  /* FOLD covers most cases, but some are easier to do here. */\n  if (tref_isk(rb) && tvispone(ir_knum(IR(tref_ref(rb)))))\n    return rb;  /* 1 ^ x ==> 1 */\n  rc = lj_ir_tonum(J, rc);\n  if (tref_isk(rc) && ir_knum(IR(tref_ref(rc)))->n == 0.5)\n    return emitir(IRTN(IR_FPMATH), rb, IRFPM_SQRT);  /* x ^ 0.5 ==> sqrt(x) */\n  /* Split up b^c into exp2(c*log2(b)). Assembler may rejoin later. */\n  rb = emitir(IRTN(IR_FPMATH), rb, IRFPM_LOG2);\n  rc = emitir(IRTN(IR_MUL), rb, rc);\n  return emitir(IRTN(IR_FPMATH), rc, IRFPM_EXP2);\n}\n\n/* -- Predictive narrowing of induction variables ------------------------- */\n\n/* Narrow a single runtime value. */\nstatic int narrow_forl(jit_State *J, cTValue *o)\n{\n  if (tvisint(o)) return 1;\n  if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o));\n  return 0;\n}\n\n/* Narrow the FORL index type by looking at the runtime values. */\nIRType lj_opt_narrow_forl(jit_State *J, cTValue *tv)\n{\n  lua_assert(tvisnumber(&tv[FORL_IDX]) &&\n\t     tvisnumber(&tv[FORL_STOP]) &&\n\t     tvisnumber(&tv[FORL_STEP]));\n  /* Narrow only if the runtime values of start/stop/step are all integers. */\n  if (narrow_forl(J, &tv[FORL_IDX]) &&\n      narrow_forl(J, &tv[FORL_STOP]) &&\n      narrow_forl(J, &tv[FORL_STEP])) {\n    /* And if the loop index can't possibly overflow. */\n    lua_Number step = numberVnum(&tv[FORL_STEP]);\n    lua_Number sum = numberVnum(&tv[FORL_STOP]) + step;\n    if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0))\n      return IRT_INT;\n  }\n  return IRT_NUM;\n}\n\n#undef IR\n#undef fins\n#undef emitir\n#undef emitir_raw\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_sink.c",
    "content": "/*\n** SINK: Allocation Sinking and Store Sinking.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_sink_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_target.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Check whether the store ref points to an eligible allocation. */\nstatic IRIns *sink_checkalloc(jit_State *J, IRIns *irs)\n{\n  IRIns *ir = IR(irs->op1);\n  if (!irref_isk(ir->op2))\n    return NULL;  /* Non-constant key. */\n  if (ir->o == IR_HREFK || ir->o == IR_AREF)\n    ir = IR(ir->op1);\n  else if (!(ir->o == IR_HREF || ir->o == IR_NEWREF ||\n\t     ir->o == IR_FREF || ir->o == IR_ADD))\n    return NULL;  /* Unhandled reference type (for XSTORE). */\n  ir = IR(ir->op1);\n  if (!(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW))\n    return NULL;  /* Not an allocation. */\n  return ir;  /* Return allocation. */\n}\n\n/* Recursively check whether a value depends on a PHI. */\nstatic int sink_phidep(jit_State *J, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isphi(ir->t)) return 1;\n  if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1;\n  if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1;\n  return 0;\n}\n\n/* Check whether a value is a sinkable PHI or loop-invariant. */\nstatic int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref)\n{\n  if (ref >= REF_FIRST) {\n    IRIns *ir = IR(ref);\n    if (irt_isphi(ir->t) || (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT &&\n\t\t\t     irt_isphi(IR(ir->op1)->t))) {\n      ira->prev++;\n      return 1;  /* Sinkable PHI. */\n    }\n    /* Otherwise the value must be loop-invariant. */\n    return ref < J->loopref && !sink_phidep(J, ref);\n  }\n  return 1;  /* Constant (non-PHI). */\n}\n\n/* Mark non-sinkable allocations using single-pass backward propagation.\n**\n** Roots for the marking process are:\n** - Some PHIs or snapshots (see below).\n** - Non-PHI, non-constant values stored to PHI allocations.\n** - All guards.\n** - Any remaining loads not eliminated by store-to-load forwarding.\n** - Stores with non-constant keys.\n** - All stored values.\n*/\nstatic void sink_mark_ins(jit_State *J)\n{\n  IRIns *ir, *irlast = IR(J->cur.nins-1);\n  for (ir = irlast ; ; ir--) {\n    switch (ir->o) {\n    case IR_BASE:\n      return;  /* Finished. */\n    case IR_CALLL:  /* IRCALL_lj_tab_len */\n    case IR_ALOAD: case IR_HLOAD: case IR_XLOAD: case IR_TBAR:\n      irt_setmark(IR(ir->op1)->t);  /* Mark ref for remaining loads. */\n      break;\n    case IR_FLOAD:\n      if (irt_ismarked(ir->t) || ir->op2 == IRFL_TAB_META)\n\tirt_setmark(IR(ir->op1)->t);  /* Mark table for remaining loads. */\n      break;\n    case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {\n      IRIns *ira = sink_checkalloc(J, ir);\n      if (!ira || (irt_isphi(ira->t) && !sink_checkphi(J, ira, ir->op2)))\n\tirt_setmark(IR(ir->op1)->t);  /* Mark ineligible ref. */\n      irt_setmark(IR(ir->op2)->t);  /* Mark stored value. */\n      break;\n      }\n#if LJ_HASFFI\n    case IR_CNEWI:\n      if (irt_isphi(ir->t) &&\n\t  (!sink_checkphi(J, ir, ir->op2) ||\n\t   (LJ_32 && ir+1 < irlast && (ir+1)->o == IR_HIOP &&\n\t    !sink_checkphi(J, ir, (ir+1)->op2))))\n\tirt_setmark(ir->t);  /* Mark ineligible allocation. */\n      /* fallthrough */\n#endif\n    case IR_USTORE:\n      irt_setmark(IR(ir->op2)->t);  /* Mark stored value. */\n      break;\n#if LJ_HASFFI\n    case IR_CALLXS:\n#endif\n    case IR_CALLS:\n      irt_setmark(IR(ir->op1)->t);  /* Mark (potentially) stored values. */\n      break;\n    case IR_PHI: {\n      IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n      irl->prev = irr->prev = 0;  /* Clear PHI value counts. */\n      if (irl->o == irr->o &&\n\t  (irl->o == IR_TNEW || irl->o == IR_TDUP ||\n\t   (LJ_HASFFI && (irl->o == IR_CNEW || irl->o == IR_CNEWI))))\n\tbreak;\n      irt_setmark(irl->t);\n      irt_setmark(irr->t);\n      break;\n      }\n    default:\n      if (irt_ismarked(ir->t) || irt_isguard(ir->t)) {  /* Propagate mark. */\n\tif (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);\n\tif (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);\n      }\n      break;\n    }\n  }\n}\n\n/* Mark all instructions referenced by a snapshot. */\nstatic void sink_mark_snap(jit_State *J, SnapShot *snap)\n{\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    IRRef ref = snap_ref(map[n]);\n    if (!irref_isk(ref))\n      irt_setmark(IR(ref)->t);\n  }\n}\n\n/* Iteratively remark PHI refs with differing marks or PHI value counts. */\nstatic void sink_remark_phi(jit_State *J)\n{\n  IRIns *ir;\n  int remark;\n  do {\n    remark = 0;\n    for (ir = IR(J->cur.nins-1); ir->o == IR_PHI; ir--) {\n      IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n      if (((irl->t.irt ^ irr->t.irt) & IRT_MARK))\n\tremark = 1;\n      else if (irl->prev == irr->prev)\n\tcontinue;\n      irt_setmark(IR(ir->op1)->t);\n      irt_setmark(IR(ir->op2)->t);\n    }\n  } while (remark);\n}\n\n/* Sweep instructions and tag sunken allocations and stores. */\nstatic void sink_sweep_ins(jit_State *J)\n{\n  IRIns *ir, *irfirst = IR(J->cur.nk);\n  for (ir = IR(J->cur.nins-1) ; ir >= irfirst; ir--) {\n    switch (ir->o) {\n    case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {\n      IRIns *ira = sink_checkalloc(J, ir);\n      if (ira && !irt_ismarked(ira->t)) {\n\tint delta = (int)(ir - ira);\n\tir->prev = REGSP(RID_SINK, delta > 255 ? 255 : delta);\n      } else {\n\tir->prev = REGSP_INIT;\n      }\n      break;\n      }\n    case IR_NEWREF:\n      if (!irt_ismarked(IR(ir->op1)->t)) {\n\tir->prev = REGSP(RID_SINK, 0);\n      } else {\n\tirt_clearmark(ir->t);\n\tir->prev = REGSP_INIT;\n      }\n      break;\n#if LJ_HASFFI\n    case IR_CNEW: case IR_CNEWI:\n#endif\n    case IR_TNEW: case IR_TDUP:\n      if (!irt_ismarked(ir->t)) {\n\tir->t.irt &= ~IRT_GUARD;\n\tir->prev = REGSP(RID_SINK, 0);\n\tJ->cur.sinktags = 1;  /* Signal present SINK tags to assembler. */\n      } else {\n\tirt_clearmark(ir->t);\n\tir->prev = REGSP_INIT;\n      }\n      break;\n    case IR_PHI: {\n      IRIns *ira = IR(ir->op2);\n      if (!irt_ismarked(ira->t) &&\n\t  (ira->o == IR_TNEW || ira->o == IR_TDUP ||\n\t   (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI)))) {\n\tir->prev = REGSP(RID_SINK, 0);\n      } else {\n\tir->prev = REGSP_INIT;\n      }\n      break;\n      }\n    default:\n      irt_clearmark(ir->t);\n      ir->prev = REGSP_INIT;\n      break;\n    }\n  }\n}\n\n/* Allocation sinking and store sinking.\n**\n** 1. Mark all non-sinkable allocations.\n** 2. Then sink all remaining allocations and the related stores.\n*/\nvoid lj_opt_sink(jit_State *J)\n{\n  const uint32_t need = (JIT_F_OPT_SINK|JIT_F_OPT_FWD|\n\t\t\t JIT_F_OPT_DCE|JIT_F_OPT_CSE|JIT_F_OPT_FOLD);\n  if ((J->flags & need) == need &&\n      (J->chain[IR_TNEW] || J->chain[IR_TDUP] ||\n       (LJ_HASFFI && (J->chain[IR_CNEW] || J->chain[IR_CNEWI])))) {\n    if (!J->loopref)\n      sink_mark_snap(J, &J->cur.snap[J->cur.nsnap-1]);\n    sink_mark_ins(J);\n    if (J->loopref)\n      sink_remark_phi(J);\n    sink_sweep_ins(J);\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_opt_split.c",
    "content": "/*\n** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_split_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT && (LJ_SOFTFP || (LJ_32 && LJ_HASFFI))\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_vm.h\"\n\n/* SPLIT pass:\n**\n** This pass splits up 64 bit IR instructions into multiple 32 bit IR\n** instructions. It's only active for soft-float targets or for 32 bit CPUs\n** which lack native 64 bit integer operations (the FFI is currently the\n** only emitter for 64 bit integer instructions).\n**\n** Splitting the IR in a separate pass keeps each 32 bit IR assembler\n** backend simple. Only a small amount of extra functionality needs to be\n** implemented. This is much easier than adding support for allocating\n** register pairs to each backend (believe me, I tried). A few simple, but\n** important optimizations can be performed by the SPLIT pass, which would\n** be tedious to do in the backend.\n**\n** The basic idea is to replace each 64 bit IR instruction with its 32 bit\n** equivalent plus an extra HIOP instruction. The splitted IR is not passed\n** through FOLD or any other optimizations, so each HIOP is guaranteed to\n** immediately follow it's counterpart. The actual functionality of HIOP is\n** inferred from the previous instruction.\n**\n** The operands of HIOP hold the hiword input references. The output of HIOP\n** is the hiword output reference, which is also used to hold the hiword\n** register or spill slot information. The register allocator treats this\n** instruction independently of any other instruction, which improves code\n** quality compared to using fixed register pairs.\n**\n** It's easier to split up some instructions into two regular 32 bit\n** instructions. E.g. XLOAD is split up into two XLOADs with two different\n** addresses. Obviously 64 bit constants need to be split up into two 32 bit\n** constants, too. Some hiword instructions can be entirely omitted, e.g.\n** when zero-extending a 32 bit value to 64 bits. 64 bit arguments for calls\n** are split up into two 32 bit arguments each.\n**\n** On soft-float targets, floating-point instructions are directly converted\n** to soft-float calls by the SPLIT pass (except for comparisons and MIN/MAX).\n** HIOP for number results has the type IRT_SOFTFP (\"sfp\" in -jdump).\n**\n** Here's the IR and x64 machine code for 'x.b = x.a + 1' for a struct with\n** two int64_t fields:\n**\n** 0100    p32 ADD    base  +8\n** 0101    i64 XLOAD  0100\n** 0102    i64 ADD    0101  +1\n** 0103    p32 ADD    base  +16\n** 0104    i64 XSTORE 0103  0102\n**\n**         mov rax, [esi+0x8]\n**         add rax, +0x01\n**         mov [esi+0x10], rax\n**\n** Here's the transformed IR and the x86 machine code after the SPLIT pass:\n**\n** 0100    p32 ADD    base  +8\n** 0101    int XLOAD  0100\n** 0102    p32 ADD    base  +12\n** 0103    int XLOAD  0102\n** 0104    int ADD    0101  +1\n** 0105    int HIOP   0103  +0\n** 0106    p32 ADD    base  +16\n** 0107    int XSTORE 0106  0104\n** 0108    int HIOP   0106  0105\n**\n**         mov eax, [esi+0x8]\n**         mov ecx, [esi+0xc]\n**         add eax, +0x01\n**         adc ecx, +0x00\n**         mov [esi+0x10], eax\n**         mov [esi+0x14], ecx\n**\n** You may notice the reassociated hiword address computation, which is\n** later fused into the mov operands by the assembler.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Directly emit the transformed IR without updating chains etc. */\nstatic IRRef split_emit(jit_State *J, uint16_t ot, IRRef1 op1, IRRef1 op2)\n{\n  IRRef nref = lj_ir_nextins(J);\n  IRIns *ir = IR(nref);\n  ir->ot = ot;\n  ir->op1 = op1;\n  ir->op2 = op2;\n  return nref;\n}\n\n#if LJ_SOFTFP\n/* Emit a (checked) number to integer conversion. */\nstatic IRRef split_num2int(jit_State *J, IRRef lo, IRRef hi, int check)\n{\n  IRRef tmp, res;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), lo, hi);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hi, lo);\n#endif\n  res = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_softfp_d2i);\n  if (check) {\n    tmp = split_emit(J, IRTI(IR_CALLN), res, IRCALL_softfp_i2d);\n    split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n    split_emit(J, IRTGI(IR_EQ), tmp, lo);\n    split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), tmp+1, hi);\n  }\n  return res;\n}\n\n/* Emit a CALLN with one split 64 bit argument. */\nstatic IRRef split_call_l(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t  IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n}\n#endif\n\n/* Emit a CALLN with one split 64 bit argument and a 32 bit argument. */\nstatic IRRef split_call_li(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t   IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1, op2 = ir->op2;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n}\n\n/* Emit a CALLN with two split 64 bit arguments. */\nstatic IRRef split_call_ll(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t   IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1, op2 = ir->op2;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n#endif\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J,\n    IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),\n    tmp, tmp);\n}\n\n/* Get a pointer to the other 32 bit word (LE: hiword, BE: loword). */\nstatic IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref)\n{\n  IRRef nref = oir[ref].prev;\n  IRIns *ir = IR(nref);\n  int32_t ofs = 4;\n  if (ir->o == IR_KPTR)\n    return lj_ir_kptr(J, (char *)ir_kptr(ir) + ofs);\n  if (ir->o == IR_ADD && irref_isk(ir->op2) && !irt_isphi(oir[ref].t)) {\n    /* Reassociate address. */\n    ofs += IR(ir->op2)->i;\n    nref = ir->op1;\n    if (ofs == 0) return nref;\n  }\n  return split_emit(J, IRT(IR_ADD, IRT_PTR), nref, lj_ir_kint(J, ofs));\n}\n\n#if LJ_HASFFI\nstatic IRRef split_bitshift(jit_State *J, IRRef1 *hisubst,\n\t\t\t    IRIns *oir, IRIns *nir, IRIns *ir)\n{\n  IROp op = ir->o;\n  IRRef kref = nir->op2;\n  if (irref_isk(kref)) {  /* Optimize constant shifts. */\n    int32_t k = (IR(kref)->i & 63);\n    IRRef lo = nir->op1, hi = hisubst[ir->op1];\n    if (op == IR_BROL || op == IR_BROR) {\n      if (op == IR_BROR) k = (-k & 63);\n      if (k >= 32) { IRRef t = lo; lo = hi; hi = t; k -= 32; }\n      if (k == 0) {\n      passthrough:\n\tJ->cur.nins--;\n\tir->prev = lo;\n\treturn hi;\n      } else {\n\tTRef k1, k2;\n\tIRRef t1, t2, t3, t4;\n\tJ->cur.nins--;\n\tk1 = lj_ir_kint(J, k);\n\tk2 = lj_ir_kint(J, (-k & 31));\n\tt1 = split_emit(J, IRTI(IR_BSHL), lo, k1);\n\tt2 = split_emit(J, IRTI(IR_BSHL), hi, k1);\n\tt3 = split_emit(J, IRTI(IR_BSHR), lo, k2);\n\tt4 = split_emit(J, IRTI(IR_BSHR), hi, k2);\n\tir->prev = split_emit(J, IRTI(IR_BOR), t1, t4);\n\treturn split_emit(J, IRTI(IR_BOR), t2, t3);\n      }\n    } else if (k == 0) {\n      goto passthrough;\n    } else if (k < 32) {\n      if (op == IR_BSHL) {\n\tIRRef t1 = split_emit(J, IRTI(IR_BSHL), hi, kref);\n\tIRRef t2 = split_emit(J, IRTI(IR_BSHR), lo, lj_ir_kint(J, (-k&31)));\n\treturn split_emit(J, IRTI(IR_BOR), t1, t2);\n      } else {\n\tIRRef t1 = ir->prev, t2;\n\tlua_assert(op == IR_BSHR || op == IR_BSAR);\n\tnir->o = IR_BSHR;\n\tt2 = split_emit(J, IRTI(IR_BSHL), hi, lj_ir_kint(J, (-k&31)));\n\tir->prev = split_emit(J, IRTI(IR_BOR), t1, t2);\n\treturn split_emit(J, IRTI(op), hi, kref);\n      }\n    } else {\n      if (op == IR_BSHL) {\n\tif (k == 32)\n\t  J->cur.nins--;\n\telse\n\t  lo = ir->prev;\n\tir->prev = lj_ir_kint(J, 0);\n\treturn lo;\n      } else {\n\tlua_assert(op == IR_BSHR || op == IR_BSAR);\n\tif (k == 32) {\n\t  J->cur.nins--;\n\t  ir->prev = hi;\n\t} else {\n\t  nir->op1 = hi;\n\t}\n\tif (op == IR_BSHR)\n\t  return lj_ir_kint(J, 0);\n\telse\n\t  return split_emit(J, IRTI(IR_BSAR), hi, lj_ir_kint(J, 31));\n      }\n    }\n  }\n  return split_call_li(J, hisubst, oir, ir,\n\t\t       op - IR_BSHL + IRCALL_lj_carith_shl64);\n}\n\nstatic IRRef split_bitop(jit_State *J, IRRef1 *hisubst,\n\t\t\t IRIns *nir, IRIns *ir)\n{\n  IROp op = ir->o;\n  IRRef hi, kref = nir->op2;\n  if (irref_isk(kref)) {  /* Optimize bit operations with lo constant. */\n    int32_t k = IR(kref)->i;\n    if (k == 0 || k == -1) {\n      if (op == IR_BAND) k = ~k;\n      if (k == 0) {\n\tJ->cur.nins--;\n\tir->prev = nir->op1;\n      } else if (op == IR_BXOR) {\n\tnir->o = IR_BNOT;\n\tnir->op2 = 0;\n      } else {\n\tJ->cur.nins--;\n\tir->prev = kref;\n      }\n    }\n  }\n  hi = hisubst[ir->op1];\n  kref = hisubst[ir->op2];\n  if (irref_isk(kref)) {  /* Optimize bit operations with hi constant. */\n    int32_t k = IR(kref)->i;\n    if (k == 0 || k == -1) {\n      if (op == IR_BAND) k = ~k;\n      if (k == 0) {\n\treturn hi;\n      } else if (op == IR_BXOR) {\n\treturn split_emit(J, IRTI(IR_BNOT), hi, 0);\n      } else {\n\treturn kref;\n      }\n    }\n  }\n  return split_emit(J, IRTI(op), hi, kref);\n}\n#endif\n\n/* Substitute references of a snapshot. */\nstatic void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir)\n{\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    IRIns *ir = &oir[snap_ref(sn)];\n    if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn))))\n      map[n] = ((sn & 0xffff0000) | ir->prev);\n  }\n}\n\n/* Transform the old IR to the new IR. */\nstatic void split_ir(jit_State *J)\n{\n  IRRef nins = J->cur.nins, nk = J->cur.nk;\n  MSize irlen = nins - nk;\n  MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1));\n  IRIns *oir = (IRIns *)lj_buf_tmp(J->L, need);\n  IRRef1 *hisubst;\n  IRRef ref, snref;\n  SnapShot *snap;\n\n  /* Copy old IR to buffer. */\n  memcpy(oir, IR(nk), irlen*sizeof(IRIns));\n  /* Bias hiword substitution table and old IR. Loword kept in field prev. */\n  hisubst = (IRRef1 *)&oir[irlen] - nk;\n  oir -= nk;\n\n  /* Remove all IR instructions, but retain IR constants. */\n  J->cur.nins = REF_FIRST;\n  J->loopref = 0;\n\n  /* Process constants and fixed references. */\n  for (ref = nk; ref <= REF_BASE; ref++) {\n    IRIns *ir = &oir[ref];\n    if ((LJ_SOFTFP && ir->o == IR_KNUM) || ir->o == IR_KINT64) {\n      /* Split up 64 bit constant. */\n      TValue tv = *ir_k64(ir);\n      ir->prev = lj_ir_kint(J, (int32_t)tv.u32.lo);\n      hisubst[ref] = lj_ir_kint(J, (int32_t)tv.u32.hi);\n    } else {\n      ir->prev = ref;  /* Identity substitution for loword. */\n      hisubst[ref] = 0;\n    }\n  }\n\n  /* Process old IR instructions. */\n  snap = J->cur.snap;\n  snref = snap->ref;\n  for (ref = REF_FIRST; ref < nins; ref++) {\n    IRIns *ir = &oir[ref];\n    IRRef nref = lj_ir_nextins(J);\n    IRIns *nir = IR(nref);\n    IRRef hi = 0;\n\n    if (ref >= snref) {\n      snap->ref = nref;\n      split_subst_snap(J, snap++, oir);\n      snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0;\n    }\n\n    /* Copy-substitute old instruction to new instruction. */\n    nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev;\n    nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev;\n    ir->prev = nref;  /* Loword substitution. */\n    nir->o = ir->o;\n    nir->t.irt = ir->t.irt & ~(IRT_MARK|IRT_ISPHI);\n    hisubst[ref] = 0;\n\n    /* Split 64 bit instructions. */\n#if LJ_SOFTFP\n    if (irt_isnum(ir->t)) {\n      nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD);  /* Turn into INT op. */\n      /* Note: hi ref = lo ref + 1! Required for SNAP_SOFTFPNUM logic. */\n      switch (ir->o) {\n      case IR_ADD:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_add);\n\tbreak;\n      case IR_SUB:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_sub);\n\tbreak;\n      case IR_MUL:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_mul);\n\tbreak;\n      case IR_DIV:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div);\n\tbreak;\n      case IR_POW:\n\thi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi);\n\tbreak;\n      case IR_FPMATH:\n\t/* Try to rejoin pow from EXP2, MUL and LOG2. */\n\tif (nir->op2 == IRFPM_EXP2 && nir->op1 > J->loopref) {\n\t  IRIns *irp = IR(nir->op1);\n\t  if (irp->o == IR_CALLN && irp->op2 == IRCALL_softfp_mul) {\n\t    IRIns *irm4 = IR(irp->op1);\n\t    IRIns *irm3 = IR(irm4->op1);\n\t    IRIns *irm12 = IR(irm3->op1);\n\t    IRIns *irl1 = IR(irm12->op1);\n\t    if (irm12->op1 > J->loopref && irl1->o == IR_CALLN &&\n\t\tirl1->op2 == IRCALL_lj_vm_log2) {\n\t      IRRef tmp = irl1->op1;  /* Recycle first two args from LOG2. */\n\t      IRRef arg3 = irm3->op2, arg4 = irm4->op2;\n\t      J->cur.nins--;\n\t      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg3);\n\t      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg4);\n\t      ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_pow);\n\t      hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n\t      break;\n\t    }\n\t  }\n\t}\n\thi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2);\n\tbreak;\n      case IR_ATAN2:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_atan2);\n\tbreak;\n      case IR_LDEXP:\n\thi = split_call_li(J, hisubst, oir, ir, IRCALL_ldexp);\n\tbreak;\n      case IR_NEG: case IR_ABS:\n\tnir->o = IR_CONV;  /* Pass through loword. */\n\tnir->op2 = (IRT_INT << 5) | IRT_INT;\n\thi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP),\n\t\t\thisubst[ir->op1], hisubst[ir->op2]);\n\tbreak;\n      case IR_SLOAD:\n\tif ((nir->op2 & IRSLOAD_CONVERT)) {  /* Convert from int to number. */\n\t  nir->op2 &= ~IRSLOAD_CONVERT;\n\t  ir->prev = nref = split_emit(J, IRTI(IR_CALLN), nref,\n\t\t\t\t       IRCALL_softfp_i2d);\n\t  hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\t  break;\n\t}\n\t/* fallthrough */\n      case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n      case IR_STRTO:\n\thi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tbreak;\n      case IR_XLOAD: {\n\tIRIns inslo = *nir;  /* Save/undo the emit of the lo XLOAD. */\n\tJ->cur.nins--;\n\thi = split_ptr(J, oir, ir->op1);  /* Insert the hiref ADD. */\n#if LJ_BE\n\thi = split_emit(J, IRT(IR_XLOAD, IRT_INT), hi, ir->op2);\n\tinslo.t.irt = IRT_SOFTFP | (inslo.t.irt & IRT_GUARD);\n#endif\n\tnref = lj_ir_nextins(J);\n\tnir = IR(nref);\n\t*nir = inslo;  /* Re-emit lo XLOAD. */\n#if LJ_LE\n\thi = split_emit(J, IRT(IR_XLOAD, IRT_SOFTFP), hi, ir->op2);\n\tir->prev = nref;\n#else\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n\t}\n      case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_XSTORE:\n\tsplit_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nir->op1, hisubst[ir->op2]);\n\tbreak;\n      case IR_CONV: {  /* Conversion to number. Others handled below. */\n\tIRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n\tUNUSED(st);\n#if LJ_32 && LJ_HASFFI\n\tif (st == IRT_I64 || st == IRT_U64) {\n\t  hi = split_call_l(J, hisubst, oir, ir,\n\t\t st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d);\n\t  break;\n\t}\n#endif\n\tlua_assert(st == IRT_INT ||\n\t\t   (LJ_32 && LJ_HASFFI && (st == IRT_U32 || st == IRT_FLOAT)));\n\tnir->o = IR_CALLN;\n#if LJ_32 && LJ_HASFFI\n\tnir->op2 = st == IRT_INT ? IRCALL_softfp_i2d :\n\t\t   st == IRT_FLOAT ? IRCALL_softfp_f2d :\n\t\t   IRCALL_softfp_ui2d;\n#else\n\tnir->op2 = IRCALL_softfp_i2d;\n#endif\n\thi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tbreak;\n\t}\n      case IR_CALLN:\n      case IR_CALLL:\n      case IR_CALLS:\n      case IR_CALLXS:\n\tgoto split_call;\n      case IR_PHI:\n\tif (nir->op1 == nir->op2)\n\t  J->cur.nins--;  /* Drop useless PHIs. */\n\tif (hisubst[ir->op1] != hisubst[ir->op2])\n\t  split_emit(J, IRT(IR_PHI, IRT_SOFTFP),\n\t\t     hisubst[ir->op1], hisubst[ir->op2]);\n\tbreak;\n      case IR_HIOP:\n\tJ->cur.nins--;  /* Drop joining HIOP. */\n\tir->prev = nir->op1;\n\thi = nir->op2;\n\tbreak;\n      default:\n\tlua_assert(ir->o <= IR_NE || ir->o == IR_MIN || ir->o == IR_MAX);\n\thi = split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP),\n\t\t\thisubst[ir->op1], hisubst[ir->op2]);\n\tbreak;\n      }\n    } else\n#endif\n#if LJ_32 && LJ_HASFFI\n    if (irt_isint64(ir->t)) {\n      IRRef hiref = hisubst[ir->op1];\n      nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD);  /* Turn into INT op. */\n      switch (ir->o) {\n      case IR_ADD:\n      case IR_SUB:\n\t/* Use plain op for hiword if loword cannot produce a carry/borrow. */\n\tif (irref_isk(nir->op2) && IR(nir->op2)->i == 0) {\n\t  ir->prev = nir->op1;  /* Pass through loword. */\n\t  nir->op1 = hiref; nir->op2 = hisubst[ir->op2];\n\t  hi = nref;\n\t  break;\n\t}\n\t/* fallthrough */\n      case IR_NEG:\n\thi = split_emit(J, IRTI(IR_HIOP), hiref, hisubst[ir->op2]);\n\tbreak;\n      case IR_MUL:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_lj_carith_mul64);\n\tbreak;\n      case IR_DIV:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :\n\t\t\t\t\t      IRCALL_lj_carith_divu64);\n\tbreak;\n      case IR_MOD:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :\n\t\t\t\t\t      IRCALL_lj_carith_modu64);\n\tbreak;\n      case IR_POW:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :\n\t\t\t\t\t      IRCALL_lj_carith_powu64);\n\tbreak;\n      case IR_BNOT:\n\thi = split_emit(J, IRTI(IR_BNOT), hiref, 0);\n\tbreak;\n      case IR_BSWAP:\n\tir->prev = split_emit(J, IRTI(IR_BSWAP), hiref, 0);\n\thi = nref;\n\tbreak;\n      case IR_BAND: case IR_BOR: case IR_BXOR:\n\thi = split_bitop(J, hisubst, nir, ir);\n\tbreak;\n      case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR:\n\thi = split_bitshift(J, hisubst, oir, nir, ir);\n\tbreak;\n      case IR_FLOAD:\n\tlua_assert(ir->op2 == IRFL_CDATA_INT64);\n\thi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4);\n#if LJ_BE\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n      case IR_XLOAD:\n\thi = split_emit(J, IRTI(IR_XLOAD), split_ptr(J, oir, ir->op1), ir->op2);\n#if LJ_BE\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n      case IR_XSTORE:\n\tsplit_emit(J, IRTI(IR_HIOP), nir->op1, hisubst[ir->op2]);\n\tbreak;\n      case IR_CONV: {  /* Conversion to 64 bit integer. Others handled below. */\n\tIRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if LJ_SOFTFP\n\tif (st == IRT_NUM) {  /* NUM to 64 bit int conv. */\n\t  hi = split_call_l(J, hisubst, oir, ir,\n\t\t irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul);\n\t} else if (st == IRT_FLOAT) {  /* FLOAT to 64 bit int conv. */\n\t  nir->o = IR_CALLN;\n\t  nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul;\n\t  hi = split_emit(J, IRTI(IR_HIOP), nref, nref);\n\t}\n#else\n\tif (st == IRT_NUM || st == IRT_FLOAT) {  /* FP to 64 bit int conv. */\n\t  hi = split_emit(J, IRTI(IR_HIOP), nir->op1, nref);\n\t}\n#endif\n\telse if (st == IRT_I64 || st == IRT_U64) {  /* 64/64 bit cast. */\n\t  /* Drop cast, since assembler doesn't care. But fwd both parts. */\n\t  hi = hiref;\n\t  goto fwdlo;\n\t} else if ((ir->op2 & IRCONV_SEXT)) {  /* Sign-extend to 64 bit. */\n\t  IRRef k31 = lj_ir_kint(J, 31);\n\t  nir = IR(nref);  /* May have been reallocated. */\n\t  ir->prev = nir->op1;  /* Pass through loword. */\n\t  nir->o = IR_BSAR;  /* hi = bsar(lo, 31). */\n\t  nir->op2 = k31;\n\t  hi = nref;\n\t} else {  /* Zero-extend to 64 bit. */\n\t  hi = lj_ir_kint(J, 0);\n\t  goto fwdlo;\n\t}\n\tbreak;\n\t}\n      case IR_CALLXS:\n\tgoto split_call;\n      case IR_PHI: {\n\tIRRef hiref2;\n\tif ((irref_isk(nir->op1) && irref_isk(nir->op2)) ||\n\t    nir->op1 == nir->op2)\n\t  J->cur.nins--;  /* Drop useless PHIs. */\n\thiref2 = hisubst[ir->op2];\n\tif (!((irref_isk(hiref) && irref_isk(hiref2)) || hiref == hiref2))\n\t  split_emit(J, IRTI(IR_PHI), hiref, hiref2);\n\tbreak;\n\t}\n      case IR_HIOP:\n\tJ->cur.nins--;  /* Drop joining HIOP. */\n\tir->prev = nir->op1;\n\thi = nir->op2;\n\tbreak;\n      default:\n\tlua_assert(ir->o <= IR_NE);  /* Comparisons. */\n\tsplit_emit(J, IRTGI(IR_HIOP), hiref, hisubst[ir->op2]);\n\tbreak;\n      }\n    } else\n#endif\n#if LJ_SOFTFP\n    if (ir->o == IR_SLOAD) {\n      if ((nir->op2 & IRSLOAD_CONVERT)) {  /* Convert from number to int. */\n\tnir->op2 &= ~IRSLOAD_CONVERT;\n\tif (!(nir->op2 & IRSLOAD_TYPECHECK))\n\t  nir->t.irt = IRT_INT;  /* Drop guard. */\n\tsplit_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tir->prev = split_num2int(J, nref, nref+1, irt_isguard(ir->t));\n      }\n    } else if (ir->o == IR_TOBIT) {\n      IRRef tmp, op1 = ir->op1;\n      J->cur.nins--;\n#if LJ_LE\n      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n      ir->prev = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_lj_vm_tobit);\n    } else if (ir->o == IR_TOSTR) {\n      if (hisubst[ir->op1]) {\n\tif (irref_isk(ir->op1))\n\t  nir->op1 = ir->op1;\n\telse\n\t  split_emit(J, IRT(IR_HIOP, IRT_NIL), hisubst[ir->op1], nref);\n      }\n    } else if (ir->o == IR_HREF || ir->o == IR_NEWREF) {\n      if (irref_isk(ir->op2) && hisubst[ir->op2])\n\tnir->op2 = ir->op2;\n    } else\n#endif\n    if (ir->o == IR_CONV) {  /* See above, too. */\n      IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if LJ_32 && LJ_HASFFI\n      if (st == IRT_I64 || st == IRT_U64) {  /* Conversion from 64 bit int. */\n#if LJ_SOFTFP\n\tif (irt_isfloat(ir->t)) {\n\t  split_call_l(J, hisubst, oir, ir,\n\t\t       st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f);\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t}\n#else\n\tif (irt_isfp(ir->t)) {  /* 64 bit integer to FP conversion. */\n\t  ir->prev = split_emit(J, IRT(IR_HIOP, irt_type(ir->t)),\n\t\t\t\thisubst[ir->op1], nref);\n\t}\n#endif\n\telse {  /* Truncate to lower 32 bits. */\n\tfwdlo:\n\t  ir->prev = nir->op1;  /* Forward loword. */\n\t  /* Replace with NOP to avoid messing up the snapshot logic. */\n\t  nir->ot = IRT(IR_NOP, IRT_NIL);\n\t  nir->op1 = nir->op2 = 0;\n\t}\n      }\n#endif\n#if LJ_SOFTFP && LJ_32 && LJ_HASFFI\n      else if (irt_isfloat(ir->t)) {\n\tif (st == IRT_NUM) {\n\t  split_call_l(J, hisubst, oir, ir, IRCALL_softfp_d2f);\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t} else {\n\t  nir->o = IR_CALLN;\n\t  nir->op2 = st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f;\n\t}\n      } else if (st == IRT_FLOAT) {\n\tnir->o = IR_CALLN;\n\tnir->op2 = irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui;\n      } else\n#endif\n#if LJ_SOFTFP\n      if (st == IRT_NUM || (LJ_32 && LJ_HASFFI && st == IRT_FLOAT)) {\n\tif (irt_isguard(ir->t)) {\n\t  lua_assert(st == IRT_NUM && irt_isint(ir->t));\n\t  J->cur.nins--;\n\t  ir->prev = split_num2int(J, nir->op1, hisubst[ir->op1], 1);\n\t} else {\n\t  split_call_l(J, hisubst, oir, ir,\n#if LJ_32 && LJ_HASFFI\n\t    st == IRT_NUM ?\n\t      (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) :\n\t      (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui)\n#else\n\t    IRCALL_softfp_d2i\n#endif\n\t  );\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t}\n      }\n#endif\n    } else if (ir->o == IR_CALLXS) {\n      IRRef hiref;\n    split_call:\n      hiref = hisubst[ir->op1];\n      if (hiref) {\n\tIROpT ot = nir->ot;\n\tIRRef op2 = nir->op2;\n\tnir->ot = IRT(IR_CARG, IRT_NIL);\n#if LJ_LE\n\tnir->op2 = hiref;\n#else\n\tnir->op2 = nir->op1; nir->op1 = hiref;\n#endif\n\tir->prev = nref = split_emit(J, ot, nref, op2);\n      }\n      if (LJ_SOFTFP ? irt_is64(ir->t) : irt_isint64(ir->t))\n\thi = split_emit(J,\n\t  IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),\n\t  nref, nref);\n    } else if (ir->o == IR_CARG) {\n      IRRef hiref = hisubst[ir->op1];\n      if (hiref) {\n\tIRRef op2 = nir->op2;\n#if LJ_LE\n\tnir->op2 = hiref;\n#else\n\tnir->op2 = nir->op1; nir->op1 = hiref;\n#endif\n\tir->prev = nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);\n\tnir = IR(nref);\n      }\n      hiref = hisubst[ir->op2];\n      if (hiref) {\n#if !LJ_TARGET_X86\n\tint carg = 0;\n\tIRIns *cir;\n\tfor (cir = IR(nir->op1); cir->o == IR_CARG; cir = IR(cir->op1))\n\t  carg++;\n\tif ((carg & 1) == 0) {  /* Align 64 bit arguments. */\n\t  IRRef op2 = nir->op2;\n\t  nir->op2 = REF_NIL;\n\t  nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);\n\t  nir = IR(nref);\n\t}\n#endif\n#if LJ_BE\n\t{ IRRef tmp = nir->op2; nir->op2 = hiref; hiref = tmp; }\n#endif\n\tir->prev = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, hiref);\n      }\n    } else if (ir->o == IR_CNEWI) {\n      if (hisubst[ir->op2])\n\tsplit_emit(J, IRT(IR_HIOP, IRT_NIL), nref, hisubst[ir->op2]);\n    } else if (ir->o == IR_LOOP) {\n      J->loopref = nref;  /* Needed by assembler. */\n    }\n    hisubst[ref] = hi;  /* Store hiword substitution. */\n  }\n  if (snref == nins) {  /* Substitution for last snapshot. */\n    snap->ref = J->cur.nins;\n    split_subst_snap(J, snap, oir);\n  }\n\n  /* Add PHI marks. */\n  for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) {\n    IRIns *ir = IR(ref);\n    if (ir->o != IR_PHI) break;\n    if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t);\n    if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t);\n  }\n}\n\n/* Protected callback for split pass. */\nstatic TValue *cpsplit(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  split_ir(J);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\n#if defined(LUA_USE_ASSERT) || LJ_SOFTFP\n/* Slow, but sure way to check whether a SPLIT pass is needed. */\nstatic int split_needsplit(jit_State *J)\n{\n  IRIns *ir, *irend;\n  IRRef ref;\n  for (ir = IR(REF_FIRST), irend = IR(J->cur.nins); ir < irend; ir++)\n    if (LJ_SOFTFP ? irt_is64orfp(ir->t) : irt_isint64(ir->t))\n      return 1;\n  if (LJ_SOFTFP) {\n    for (ref = J->chain[IR_SLOAD]; ref; ref = IR(ref)->prev)\n      if ((IR(ref)->op2 & IRSLOAD_CONVERT))\n\treturn 1;\n    if (J->chain[IR_TOBIT])\n      return 1;\n  }\n  for (ref = J->chain[IR_CONV]; ref; ref = IR(ref)->prev) {\n    IRType st = (IR(ref)->op2 & IRCONV_SRCMASK);\n    if ((LJ_SOFTFP && (st == IRT_NUM || st == IRT_FLOAT)) ||\n\tst == IRT_I64 || st == IRT_U64)\n      return 1;\n  }\n  return 0;  /* Nope. */\n}\n#endif\n\n/* SPLIT pass. */\nvoid lj_opt_split(jit_State *J)\n{\n#if LJ_SOFTFP\n  if (!J->needsplit)\n    J->needsplit = split_needsplit(J);\n#else\n  lua_assert(J->needsplit >= split_needsplit(J));  /* Verify flag. */\n#endif\n  if (J->needsplit) {\n    int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit);\n    if (errcode) {\n      /* Completely reset the trace to avoid inconsistent dump on abort. */\n      J->cur.nins = J->cur.nk = REF_BASE;\n      J->cur.nsnap = 0;\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    }\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_parse.c",
    "content": "/*\n** Lua parser (source code -> bytecode).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_parse_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_strfmt.h\"\n#include \"lj_lex.h\"\n#include \"lj_parse.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n\n/* -- Parser structures and definitions ----------------------------------- */\n\n/* Expression kinds. */\ntypedef enum {\n  /* Constant expressions must be first and in this order: */\n  VKNIL,\n  VKFALSE,\n  VKTRUE,\n  VKSTR,\t/* sval = string value */\n  VKNUM,\t/* nval = number value */\n  VKLAST = VKNUM,\n  VKCDATA,\t/* nval = cdata value, not treated as a constant expression */\n  /* Non-constant expressions follow: */\n  VLOCAL,\t/* info = local register, aux = vstack index */\n  VUPVAL,\t/* info = upvalue index, aux = vstack index */\n  VGLOBAL,\t/* sval = string value */\n  VINDEXED,\t/* info = table register, aux = index reg/byte/string const */\n  VJMP,\t\t/* info = instruction PC */\n  VRELOCABLE,\t/* info = instruction PC */\n  VNONRELOC,\t/* info = result register */\n  VCALL,\t/* info = instruction PC, aux = base */\n  VVOID\n} ExpKind;\n\n/* Expression descriptor. */\ntypedef struct ExpDesc {\n  union {\n    struct {\n      uint32_t info;\t/* Primary info. */\n      uint32_t aux;\t/* Secondary info. */\n    } s;\n    TValue nval;\t/* Number value. */\n    GCstr *sval;\t/* String value. */\n  } u;\n  ExpKind k;\n  BCPos t;\t\t/* True condition jump list. */\n  BCPos f;\t\t/* False condition jump list. */\n} ExpDesc;\n\n/* Macros for expressions. */\n#define expr_hasjump(e)\t\t((e)->t != (e)->f)\n\n#define expr_isk(e)\t\t((e)->k <= VKLAST)\n#define expr_isk_nojump(e)\t(expr_isk(e) && !expr_hasjump(e))\n#define expr_isnumk(e)\t\t((e)->k == VKNUM)\n#define expr_isnumk_nojump(e)\t(expr_isnumk(e) && !expr_hasjump(e))\n#define expr_isstrk(e)\t\t((e)->k == VKSTR)\n\n#define expr_numtv(e)\t\tcheck_exp(expr_isnumk((e)), &(e)->u.nval)\n#define expr_numberV(e)\t\tnumberVnum(expr_numtv((e)))\n\n/* Initialize expression. */\nstatic LJ_AINLINE void expr_init(ExpDesc *e, ExpKind k, uint32_t info)\n{\n  e->k = k;\n  e->u.s.info = info;\n  e->f = e->t = NO_JMP;\n}\n\n/* Check number constant for +-0. */\nstatic int expr_numiszero(ExpDesc *e)\n{\n  TValue *o = expr_numtv(e);\n  return tvisint(o) ? (intV(o) == 0) : tviszero(o);\n}\n\n/* Per-function linked list of scope blocks. */\ntypedef struct FuncScope {\n  struct FuncScope *prev;\t/* Link to outer scope. */\n  MSize vstart;\t\t\t/* Start of block-local variables. */\n  uint8_t nactvar;\t\t/* Number of active vars outside the scope. */\n  uint8_t flags;\t\t/* Scope flags. */\n} FuncScope;\n\n#define FSCOPE_LOOP\t\t0x01\t/* Scope is a (breakable) loop. */\n#define FSCOPE_BREAK\t\t0x02\t/* Break used in scope. */\n#define FSCOPE_GOLA\t\t0x04\t/* Goto or label used in scope. */\n#define FSCOPE_UPVAL\t\t0x08\t/* Upvalue in scope. */\n#define FSCOPE_NOCLOSE\t\t0x10\t/* Do not close upvalues. */\n\n#define NAME_BREAK\t\t((GCstr *)(uintptr_t)1)\n\n/* Index into variable stack. */\ntypedef uint16_t VarIndex;\n#define LJ_MAX_VSTACK\t\t(65536 - LJ_MAX_UPVAL)\n\n/* Variable/goto/label info. */\n#define VSTACK_VAR_RW\t\t0x01\t/* R/W variable. */\n#define VSTACK_GOTO\t\t0x02\t/* Pending goto. */\n#define VSTACK_LABEL\t\t0x04\t/* Label. */\n\n/* Per-function state. */\ntypedef struct FuncState {\n  GCtab *kt;\t\t\t/* Hash table for constants. */\n  LexState *ls;\t\t\t/* Lexer state. */\n  lua_State *L;\t\t\t/* Lua state. */\n  FuncScope *bl;\t\t/* Current scope. */\n  struct FuncState *prev;\t/* Enclosing function. */\n  BCPos pc;\t\t\t/* Next bytecode position. */\n  BCPos lasttarget;\t\t/* Bytecode position of last jump target. */\n  BCPos jpc;\t\t\t/* Pending jump list to next bytecode. */\n  BCReg freereg;\t\t/* First free register. */\n  BCReg nactvar;\t\t/* Number of active local variables. */\n  BCReg nkn, nkgc;\t\t/* Number of lua_Number/GCobj constants */\n  BCLine linedefined;\t\t/* First line of the function definition. */\n  BCInsLine *bcbase;\t\t/* Base of bytecode stack. */\n  BCPos bclim;\t\t\t/* Limit of bytecode stack. */\n  MSize vbase;\t\t\t/* Base of variable stack for this function. */\n  uint8_t flags;\t\t/* Prototype flags. */\n  uint8_t numparams;\t\t/* Number of parameters. */\n  uint8_t framesize;\t\t/* Fixed frame size. */\n  uint8_t nuv;\t\t\t/* Number of upvalues */\n  VarIndex varmap[LJ_MAX_LOCVAR];  /* Map from register to variable idx. */\n  VarIndex uvmap[LJ_MAX_UPVAL];\t/* Map from upvalue to variable idx. */\n  VarIndex uvtmp[LJ_MAX_UPVAL];\t/* Temporary upvalue map. */\n} FuncState;\n\n/* Binary and unary operators. ORDER OPR */\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,  /* ORDER ARITH */\n  OPR_CONCAT,\n  OPR_NE, OPR_EQ,\n  OPR_LT, OPR_GE, OPR_LE, OPR_GT,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\nLJ_STATIC_ASSERT((int)BC_ISGE-(int)BC_ISLT == (int)OPR_GE-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_ISLE-(int)BC_ISLT == (int)OPR_LE-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_ISGT-(int)BC_ISLT == (int)OPR_GT-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_SUBVV-(int)BC_ADDVV == (int)OPR_SUB-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_MULVV-(int)BC_ADDVV == (int)OPR_MUL-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_DIVVV-(int)BC_ADDVV == (int)OPR_DIV-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_MODVV-(int)BC_ADDVV == (int)OPR_MOD-(int)OPR_ADD);\n\n/* -- Error handling ------------------------------------------------------ */\n\nLJ_NORET LJ_NOINLINE static void err_syntax(LexState *ls, ErrMsg em)\n{\n  lj_lex_error(ls, ls->tok, em);\n}\n\nLJ_NORET LJ_NOINLINE static void err_token(LexState *ls, LexToken tok)\n{\n  lj_lex_error(ls, ls->tok, LJ_ERR_XTOKEN, lj_lex_token2str(ls, tok));\n}\n\nLJ_NORET static void err_limit(FuncState *fs, uint32_t limit, const char *what)\n{\n  if (fs->linedefined == 0)\n    lj_lex_error(fs->ls, 0, LJ_ERR_XLIMM, limit, what);\n  else\n    lj_lex_error(fs->ls, 0, LJ_ERR_XLIMF, fs->linedefined, limit, what);\n}\n\n#define checklimit(fs, v, l, m)\t\tif ((v) >= (l)) err_limit(fs, l, m)\n#define checklimitgt(fs, v, l, m)\tif ((v) > (l)) err_limit(fs, l, m)\n#define checkcond(ls, c, em)\t\t{ if (!(c)) err_syntax(ls, em); }\n\n/* -- Management of constants --------------------------------------------- */\n\n/* Return bytecode encoding for primitive constant. */\n#define const_pri(e)\t\tcheck_exp((e)->k <= VKTRUE, (e)->k)\n\n#define tvhaskslot(o)\t((o)->u32.hi == 0)\n#define tvkslot(o)\t((o)->u32.lo)\n\n/* Add a number constant. */\nstatic BCReg const_num(FuncState *fs, ExpDesc *e)\n{\n  lua_State *L = fs->L;\n  TValue *o;\n  lua_assert(expr_isnumk(e));\n  o = lj_tab_set(L, fs->kt, &e->u.nval);\n  if (tvhaskslot(o))\n    return tvkslot(o);\n  o->u64 = fs->nkn;\n  return fs->nkn++;\n}\n\n/* Add a GC object constant. */\nstatic BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)\n{\n  lua_State *L = fs->L;\n  TValue key, *o;\n  setgcV(L, &key, gc, itype);\n  /* NOBARRIER: the key is new or kept alive. */\n  o = lj_tab_set(L, fs->kt, &key);\n  if (tvhaskslot(o))\n    return tvkslot(o);\n  o->u64 = fs->nkgc;\n  return fs->nkgc++;\n}\n\n/* Add a string constant. */\nstatic BCReg const_str(FuncState *fs, ExpDesc *e)\n{\n  lua_assert(expr_isstrk(e) || e->k == VGLOBAL);\n  return const_gc(fs, obj2gco(e->u.sval), LJ_TSTR);\n}\n\n/* Anchor string constant to avoid GC. */\nGCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len)\n{\n  /* NOBARRIER: the key is new or kept alive. */\n  lua_State *L = ls->L;\n  GCstr *s = lj_str_new(L, str, len);\n  TValue *tv = lj_tab_setstr(L, ls->fs->kt, s);\n  if (tvisnil(tv)) setboolV(tv, 1);\n  lj_gc_check(L);\n  return s;\n}\n\n#if LJ_HASFFI\n/* Anchor cdata to avoid GC. */\nvoid lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd)\n{\n  /* NOBARRIER: the key is new or kept alive. */\n  lua_State *L = ls->L;\n  setcdataV(L, tv, cd);\n  setboolV(lj_tab_set(L, ls->fs->kt, tv), 1);\n}\n#endif\n\n/* -- Jump list handling -------------------------------------------------- */\n\n/* Get next element in jump list. */\nstatic BCPos jmp_next(FuncState *fs, BCPos pc)\n{\n  ptrdiff_t delta = bc_j(fs->bcbase[pc].ins);\n  if ((BCPos)delta == NO_JMP)\n    return NO_JMP;\n  else\n    return (BCPos)(((ptrdiff_t)pc+1)+delta);\n}\n\n/* Check if any of the instructions on the jump list produce no value. */\nstatic int jmp_novalue(FuncState *fs, BCPos list)\n{\n  for (; list != NO_JMP; list = jmp_next(fs, list)) {\n    BCIns p = fs->bcbase[list >= 1 ? list-1 : list].ins;\n    if (!(bc_op(p) == BC_ISTC || bc_op(p) == BC_ISFC || bc_a(p) == NO_REG))\n      return 1;\n  }\n  return 0;\n}\n\n/* Patch register of test instructions. */\nstatic int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg)\n{\n  BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc];\n  BCOp op = bc_op(ilp->ins);\n  if (op == BC_ISTC || op == BC_ISFC) {\n    if (reg != NO_REG && reg != bc_d(ilp->ins)) {\n      setbc_a(&ilp->ins, reg);\n    } else {  /* Nothing to store or already in the right register. */\n      setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC));\n      setbc_a(&ilp->ins, 0);\n    }\n  } else if (bc_a(ilp->ins) == NO_REG) {\n    if (reg == NO_REG) {\n      ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0);\n    } else {\n      setbc_a(&ilp->ins, reg);\n      if (reg >= bc_a(ilp[1].ins))\n\tsetbc_a(&ilp[1].ins, reg+1);\n    }\n  } else {\n    return 0;  /* Cannot patch other instructions. */\n  }\n  return 1;\n}\n\n/* Drop values for all instructions on jump list. */\nstatic void jmp_dropval(FuncState *fs, BCPos list)\n{\n  for (; list != NO_JMP; list = jmp_next(fs, list))\n    jmp_patchtestreg(fs, list, NO_REG);\n}\n\n/* Patch jump instruction to target. */\nstatic void jmp_patchins(FuncState *fs, BCPos pc, BCPos dest)\n{\n  BCIns *jmp = &fs->bcbase[pc].ins;\n  BCPos offset = dest-(pc+1)+BCBIAS_J;\n  lua_assert(dest != NO_JMP);\n  if (offset > BCMAX_D)\n    err_syntax(fs->ls, LJ_ERR_XJUMP);\n  setbc_d(jmp, offset);\n}\n\n/* Append to jump list. */\nstatic void jmp_append(FuncState *fs, BCPos *l1, BCPos l2)\n{\n  if (l2 == NO_JMP) {\n    return;\n  } else if (*l1 == NO_JMP) {\n    *l1 = l2;\n  } else {\n    BCPos list = *l1;\n    BCPos next;\n    while ((next = jmp_next(fs, list)) != NO_JMP)  /* Find last element. */\n      list = next;\n    jmp_patchins(fs, list, l2);\n  }\n}\n\n/* Patch jump list and preserve produced values. */\nstatic void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget,\n\t\t\t BCReg reg, BCPos dtarget)\n{\n  while (list != NO_JMP) {\n    BCPos next = jmp_next(fs, list);\n    if (jmp_patchtestreg(fs, list, reg))\n      jmp_patchins(fs, list, vtarget);  /* Jump to target with value. */\n    else\n      jmp_patchins(fs, list, dtarget);  /* Jump to default target. */\n    list = next;\n  }\n}\n\n/* Jump to following instruction. Append to list of pending jumps. */\nstatic void jmp_tohere(FuncState *fs, BCPos list)\n{\n  fs->lasttarget = fs->pc;\n  jmp_append(fs, &fs->jpc, list);\n}\n\n/* Patch jump list to target. */\nstatic void jmp_patch(FuncState *fs, BCPos list, BCPos target)\n{\n  if (target == fs->pc) {\n    jmp_tohere(fs, list);\n  } else {\n    lua_assert(target < fs->pc);\n    jmp_patchval(fs, list, target, NO_REG, target);\n  }\n}\n\n/* -- Bytecode register allocator ----------------------------------------- */\n\n/* Bump frame size. */\nstatic void bcreg_bump(FuncState *fs, BCReg n)\n{\n  BCReg sz = fs->freereg + n;\n  if (sz > fs->framesize) {\n    if (sz >= LJ_MAX_SLOTS)\n      err_syntax(fs->ls, LJ_ERR_XSLOTS);\n    fs->framesize = (uint8_t)sz;\n  }\n}\n\n/* Reserve registers. */\nstatic void bcreg_reserve(FuncState *fs, BCReg n)\n{\n  bcreg_bump(fs, n);\n  fs->freereg += n;\n}\n\n/* Free register. */\nstatic void bcreg_free(FuncState *fs, BCReg reg)\n{\n  if (reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n/* Free register for expression. */\nstatic void expr_free(FuncState *fs, ExpDesc *e)\n{\n  if (e->k == VNONRELOC)\n    bcreg_free(fs, e->u.s.info);\n}\n\n/* -- Bytecode emitter ---------------------------------------------------- */\n\n/* Emit bytecode instruction. */\nstatic BCPos bcemit_INS(FuncState *fs, BCIns ins)\n{\n  BCPos pc = fs->pc;\n  LexState *ls = fs->ls;\n  jmp_patchval(fs, fs->jpc, pc, NO_REG, pc);\n  fs->jpc = NO_JMP;\n  if (LJ_UNLIKELY(pc >= fs->bclim)) {\n    ptrdiff_t base = fs->bcbase - ls->bcstack;\n    checklimit(fs, ls->sizebcstack, LJ_MAX_BCINS, \"bytecode instructions\");\n    lj_mem_growvec(fs->L, ls->bcstack, ls->sizebcstack, LJ_MAX_BCINS,BCInsLine);\n    fs->bclim = (BCPos)(ls->sizebcstack - base);\n    fs->bcbase = ls->bcstack + base;\n  }\n  fs->bcbase[pc].ins = ins;\n  fs->bcbase[pc].line = ls->lastline;\n  fs->pc = pc+1;\n  return pc;\n}\n\n#define bcemit_ABC(fs, o, a, b, c)\tbcemit_INS(fs, BCINS_ABC(o, a, b, c))\n#define bcemit_AD(fs, o, a, d)\t\tbcemit_INS(fs, BCINS_AD(o, a, d))\n#define bcemit_AJ(fs, o, a, j)\t\tbcemit_INS(fs, BCINS_AJ(o, a, j))\n\n#define bcptr(fs, e)\t\t\t(&(fs)->bcbase[(e)->u.s.info].ins)\n\n/* -- Bytecode emitter for expressions ------------------------------------ */\n\n/* Discharge non-constant expression to any register. */\nstatic void expr_discharge(FuncState *fs, ExpDesc *e)\n{\n  BCIns ins;\n  if (e->k == VUPVAL) {\n    ins = BCINS_AD(BC_UGET, 0, e->u.s.info);\n  } else if (e->k == VGLOBAL) {\n    ins = BCINS_AD(BC_GGET, 0, const_str(fs, e));\n  } else if (e->k == VINDEXED) {\n    BCReg rc = e->u.s.aux;\n    if ((int32_t)rc < 0) {\n      ins = BCINS_ABC(BC_TGETS, 0, e->u.s.info, ~rc);\n    } else if (rc > BCMAX_C) {\n      ins = BCINS_ABC(BC_TGETB, 0, e->u.s.info, rc-(BCMAX_C+1));\n    } else {\n      bcreg_free(fs, rc);\n      ins = BCINS_ABC(BC_TGETV, 0, e->u.s.info, rc);\n    }\n    bcreg_free(fs, e->u.s.info);\n  } else if (e->k == VCALL) {\n    e->u.s.info = e->u.s.aux;\n    e->k = VNONRELOC;\n    return;\n  } else if (e->k == VLOCAL) {\n    e->k = VNONRELOC;\n    return;\n  } else {\n    return;\n  }\n  e->u.s.info = bcemit_INS(fs, ins);\n  e->k = VRELOCABLE;\n}\n\n/* Emit bytecode to set a range of registers to nil. */\nstatic void bcemit_nil(FuncState *fs, BCReg from, BCReg n)\n{\n  if (fs->pc > fs->lasttarget) {  /* No jumps to current position? */\n    BCIns *ip = &fs->bcbase[fs->pc-1].ins;\n    BCReg pto, pfrom = bc_a(*ip);\n    switch (bc_op(*ip)) {  /* Try to merge with the previous instruction. */\n    case BC_KPRI:\n      if (bc_d(*ip) != ~LJ_TNIL) break;\n      if (from == pfrom) {\n\tif (n == 1) return;\n      } else if (from == pfrom+1) {\n\tfrom = pfrom;\n\tn++;\n      } else {\n\tbreak;\n      }\n      *ip = BCINS_AD(BC_KNIL, from, from+n-1);  /* Replace KPRI. */\n      return;\n    case BC_KNIL:\n      pto = bc_d(*ip);\n      if (pfrom <= from && from <= pto+1) {  /* Can we connect both ranges? */\n\tif (from+n-1 > pto)\n\t  setbc_d(ip, from+n-1);  /* Patch previous instruction range. */\n\treturn;\n      }\n      break;\n    default:\n      break;\n    }\n  }\n  /* Emit new instruction or replace old instruction. */\n  bcemit_INS(fs, n == 1 ? BCINS_AD(BC_KPRI, from, VKNIL) :\n\t\t\t  BCINS_AD(BC_KNIL, from, from+n-1));\n}\n\n/* Discharge an expression to a specific register. Ignore branches. */\nstatic void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg)\n{\n  BCIns ins;\n  expr_discharge(fs, e);\n  if (e->k == VKSTR) {\n    ins = BCINS_AD(BC_KSTR, reg, const_str(fs, e));\n  } else if (e->k == VKNUM) {\n#if LJ_DUALNUM\n    cTValue *tv = expr_numtv(e);\n    if (tvisint(tv) && checki16(intV(tv)))\n      ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv));\n    else\n#else\n    lua_Number n = expr_numberV(e);\n    int32_t k = lj_num2int(n);\n    if (checki16(k) && n == (lua_Number)k)\n      ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k);\n    else\n#endif\n      ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e));\n#if LJ_HASFFI\n  } else if (e->k == VKCDATA) {\n    fs->flags |= PROTO_FFI;\n    ins = BCINS_AD(BC_KCDATA, reg,\n\t\t   const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA));\n#endif\n  } else if (e->k == VRELOCABLE) {\n    setbc_a(bcptr(fs, e), reg);\n    goto noins;\n  } else if (e->k == VNONRELOC) {\n    if (reg == e->u.s.info)\n      goto noins;\n    ins = BCINS_AD(BC_MOV, reg, e->u.s.info);\n  } else if (e->k == VKNIL) {\n    bcemit_nil(fs, reg, 1);\n    goto noins;\n  } else if (e->k <= VKTRUE) {\n    ins = BCINS_AD(BC_KPRI, reg, const_pri(e));\n  } else {\n    lua_assert(e->k == VVOID || e->k == VJMP);\n    return;\n  }\n  bcemit_INS(fs, ins);\nnoins:\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n/* Forward declaration. */\nstatic BCPos bcemit_jmp(FuncState *fs);\n\n/* Discharge an expression to a specific register. */\nstatic void expr_toreg(FuncState *fs, ExpDesc *e, BCReg reg)\n{\n  expr_toreg_nobranch(fs, e, reg);\n  if (e->k == VJMP)\n    jmp_append(fs, &e->t, e->u.s.info);  /* Add it to the true jump list. */\n  if (expr_hasjump(e)) {  /* Discharge expression with branches. */\n    BCPos jend, jfalse = NO_JMP, jtrue = NO_JMP;\n    if (jmp_novalue(fs, e->t) || jmp_novalue(fs, e->f)) {\n      BCPos jval = (e->k == VJMP) ? NO_JMP : bcemit_jmp(fs);\n      jfalse = bcemit_AD(fs, BC_KPRI, reg, VKFALSE);\n      bcemit_AJ(fs, BC_JMP, fs->freereg, 1);\n      jtrue = bcemit_AD(fs, BC_KPRI, reg, VKTRUE);\n      jmp_tohere(fs, jval);\n    }\n    jend = fs->pc;\n    fs->lasttarget = jend;\n    jmp_patchval(fs, e->f, jend, reg, jfalse);\n    jmp_patchval(fs, e->t, jend, reg, jtrue);\n  }\n  e->f = e->t = NO_JMP;\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n/* Discharge an expression to the next free register. */\nstatic void expr_tonextreg(FuncState *fs, ExpDesc *e)\n{\n  expr_discharge(fs, e);\n  expr_free(fs, e);\n  bcreg_reserve(fs, 1);\n  expr_toreg(fs, e, fs->freereg - 1);\n}\n\n/* Discharge an expression to any register. */\nstatic BCReg expr_toanyreg(FuncState *fs, ExpDesc *e)\n{\n  expr_discharge(fs, e);\n  if (e->k == VNONRELOC) {\n    if (!expr_hasjump(e)) return e->u.s.info;  /* Already in a register. */\n    if (e->u.s.info >= fs->nactvar) {\n      expr_toreg(fs, e, e->u.s.info);  /* Discharge to temp. register. */\n      return e->u.s.info;\n    }\n  }\n  expr_tonextreg(fs, e);  /* Discharge to next register. */\n  return e->u.s.info;\n}\n\n/* Partially discharge expression to a value. */\nstatic void expr_toval(FuncState *fs, ExpDesc *e)\n{\n  if (expr_hasjump(e))\n    expr_toanyreg(fs, e);\n  else\n    expr_discharge(fs, e);\n}\n\n/* Emit store for LHS expression. */\nstatic void bcemit_store(FuncState *fs, ExpDesc *var, ExpDesc *e)\n{\n  BCIns ins;\n  if (var->k == VLOCAL) {\n    fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;\n    expr_free(fs, e);\n    expr_toreg(fs, e, var->u.s.info);\n    return;\n  } else if (var->k == VUPVAL) {\n    fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;\n    expr_toval(fs, e);\n    if (e->k <= VKTRUE)\n      ins = BCINS_AD(BC_USETP, var->u.s.info, const_pri(e));\n    else if (e->k == VKSTR)\n      ins = BCINS_AD(BC_USETS, var->u.s.info, const_str(fs, e));\n    else if (e->k == VKNUM)\n      ins = BCINS_AD(BC_USETN, var->u.s.info, const_num(fs, e));\n    else\n      ins = BCINS_AD(BC_USETV, var->u.s.info, expr_toanyreg(fs, e));\n  } else if (var->k == VGLOBAL) {\n    BCReg ra = expr_toanyreg(fs, e);\n    ins = BCINS_AD(BC_GSET, ra, const_str(fs, var));\n  } else {\n    BCReg ra, rc;\n    lua_assert(var->k == VINDEXED);\n    ra = expr_toanyreg(fs, e);\n    rc = var->u.s.aux;\n    if ((int32_t)rc < 0) {\n      ins = BCINS_ABC(BC_TSETS, ra, var->u.s.info, ~rc);\n    } else if (rc > BCMAX_C) {\n      ins = BCINS_ABC(BC_TSETB, ra, var->u.s.info, rc-(BCMAX_C+1));\n    } else {\n      /* Free late alloced key reg to avoid assert on free of value reg. */\n      /* This can only happen when called from expr_table(). */\n      lua_assert(e->k != VNONRELOC || ra < fs->nactvar ||\n\t\t rc < ra || (bcreg_free(fs, rc),1));\n      ins = BCINS_ABC(BC_TSETV, ra, var->u.s.info, rc);\n    }\n  }\n  bcemit_INS(fs, ins);\n  expr_free(fs, e);\n}\n\n/* Emit method lookup expression. */\nstatic void bcemit_method(FuncState *fs, ExpDesc *e, ExpDesc *key)\n{\n  BCReg idx, func, obj = expr_toanyreg(fs, e);\n  expr_free(fs, e);\n  func = fs->freereg;\n  bcemit_AD(fs, BC_MOV, func+1+LJ_FR2, obj);  /* Copy object to 1st argument. */\n  lua_assert(expr_isstrk(key));\n  idx = const_str(fs, key);\n  if (idx <= BCMAX_C) {\n    bcreg_reserve(fs, 2+LJ_FR2);\n    bcemit_ABC(fs, BC_TGETS, func, obj, idx);\n  } else {\n    bcreg_reserve(fs, 3+LJ_FR2);\n    bcemit_AD(fs, BC_KSTR, func+2+LJ_FR2, idx);\n    bcemit_ABC(fs, BC_TGETV, func, obj, func+2+LJ_FR2);\n    fs->freereg--;\n  }\n  e->u.s.info = func;\n  e->k = VNONRELOC;\n}\n\n/* -- Bytecode emitter for branches --------------------------------------- */\n\n/* Emit unconditional branch. */\nstatic BCPos bcemit_jmp(FuncState *fs)\n{\n  BCPos jpc = fs->jpc;\n  BCPos j = fs->pc - 1;\n  BCIns *ip = &fs->bcbase[j].ins;\n  fs->jpc = NO_JMP;\n  if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) {\n    setbc_j(ip, NO_JMP);\n    fs->lasttarget = j+1;\n  } else {\n    j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP);\n  }\n  jmp_append(fs, &j, jpc);\n  return j;\n}\n\n/* Invert branch condition of bytecode instruction. */\nstatic void invertcond(FuncState *fs, ExpDesc *e)\n{\n  BCIns *ip = &fs->bcbase[e->u.s.info - 1].ins;\n  setbc_op(ip, bc_op(*ip)^1);\n}\n\n/* Emit conditional branch. */\nstatic BCPos bcemit_branch(FuncState *fs, ExpDesc *e, int cond)\n{\n  BCPos pc;\n  if (e->k == VRELOCABLE) {\n    BCIns *ip = bcptr(fs, e);\n    if (bc_op(*ip) == BC_NOT) {\n      *ip = BCINS_AD(cond ? BC_ISF : BC_IST, 0, bc_d(*ip));\n      return bcemit_jmp(fs);\n    }\n  }\n  if (e->k != VNONRELOC) {\n    bcreg_reserve(fs, 1);\n    expr_toreg_nobranch(fs, e, fs->freereg-1);\n  }\n  bcemit_AD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->u.s.info);\n  pc = bcemit_jmp(fs);\n  expr_free(fs, e);\n  return pc;\n}\n\n/* Emit branch on true condition. */\nstatic void bcemit_branch_t(FuncState *fs, ExpDesc *e)\n{\n  BCPos pc;\n  expr_discharge(fs, e);\n  if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)\n    pc = NO_JMP;  /* Never jump. */\n  else if (e->k == VJMP)\n    invertcond(fs, e), pc = e->u.s.info;\n  else if (e->k == VKFALSE || e->k == VKNIL)\n    expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);\n  else\n    pc = bcemit_branch(fs, e, 0);\n  jmp_append(fs, &e->f, pc);\n  jmp_tohere(fs, e->t);\n  e->t = NO_JMP;\n}\n\n/* Emit branch on false condition. */\nstatic void bcemit_branch_f(FuncState *fs, ExpDesc *e)\n{\n  BCPos pc;\n  expr_discharge(fs, e);\n  if (e->k == VKNIL || e->k == VKFALSE)\n    pc = NO_JMP;  /* Never jump. */\n  else if (e->k == VJMP)\n    pc = e->u.s.info;\n  else if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)\n    expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);\n  else\n    pc = bcemit_branch(fs, e, 1);\n  jmp_append(fs, &e->t, pc);\n  jmp_tohere(fs, e->f);\n  e->f = NO_JMP;\n}\n\n/* -- Bytecode emitter for operators -------------------------------------- */\n\n/* Try constant-folding of arithmetic operators. */\nstatic int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  TValue o;\n  lua_Number n;\n  if (!expr_isnumk_nojump(e1) || !expr_isnumk_nojump(e2)) return 0;\n  n = lj_vm_foldarith(expr_numberV(e1), expr_numberV(e2), (int)opr-OPR_ADD);\n  setnumV(&o, n);\n  if (tvisnan(&o) || tvismzero(&o)) return 0;  /* Avoid NaN and -0 as consts. */\n  if (LJ_DUALNUM) {\n    int32_t k = lj_num2int(n);\n    if ((lua_Number)k == n) {\n      setintV(&e1->u.nval, k);\n      return 1;\n    }\n  }\n  setnumV(&e1->u.nval, n);\n  return 1;\n}\n\n/* Emit arithmetic operator. */\nstatic void bcemit_arith(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  BCReg rb, rc, t;\n  uint32_t op;\n  if (foldarith(opr, e1, e2))\n    return;\n  if (opr == OPR_POW) {\n    op = BC_POW;\n    rc = expr_toanyreg(fs, e2);\n    rb = expr_toanyreg(fs, e1);\n  } else {\n    op = opr-OPR_ADD+BC_ADDVV;\n    /* Must discharge 2nd operand first since VINDEXED might free regs. */\n    expr_toval(fs, e2);\n    if (expr_isnumk(e2) && (rc = const_num(fs, e2)) <= BCMAX_C)\n      op -= BC_ADDVV-BC_ADDVN;\n    else\n      rc = expr_toanyreg(fs, e2);\n    /* 1st operand discharged by bcemit_binop_left, but need KNUM/KSHORT. */\n    lua_assert(expr_isnumk(e1) || e1->k == VNONRELOC);\n    expr_toval(fs, e1);\n    /* Avoid two consts to satisfy bytecode constraints. */\n    if (expr_isnumk(e1) && !expr_isnumk(e2) &&\n\t(t = const_num(fs, e1)) <= BCMAX_B) {\n      rb = rc; rc = t; op -= BC_ADDVV-BC_ADDNV;\n    } else {\n      rb = expr_toanyreg(fs, e1);\n    }\n  }\n  /* Using expr_free might cause asserts if the order is wrong. */\n  if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;\n  if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;\n  e1->u.s.info = bcemit_ABC(fs, op, 0, rb, rc);\n  e1->k = VRELOCABLE;\n}\n\n/* Emit comparison operator. */\nstatic void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  ExpDesc *eret = e1;\n  BCIns ins;\n  expr_toval(fs, e1);\n  if (opr == OPR_EQ || opr == OPR_NE) {\n    BCOp op = opr == OPR_EQ ? BC_ISEQV : BC_ISNEV;\n    BCReg ra;\n    if (expr_isk(e1)) { e1 = e2; e2 = eret; }  /* Need constant in 2nd arg. */\n    ra = expr_toanyreg(fs, e1);  /* First arg must be in a reg. */\n    expr_toval(fs, e2);\n    switch (e2->k) {\n    case VKNIL: case VKFALSE: case VKTRUE:\n      ins = BCINS_AD(op+(BC_ISEQP-BC_ISEQV), ra, const_pri(e2));\n      break;\n    case VKSTR:\n      ins = BCINS_AD(op+(BC_ISEQS-BC_ISEQV), ra, const_str(fs, e2));\n      break;\n    case VKNUM:\n      ins = BCINS_AD(op+(BC_ISEQN-BC_ISEQV), ra, const_num(fs, e2));\n      break;\n    default:\n      ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2));\n      break;\n    }\n  } else {\n    uint32_t op = opr-OPR_LT+BC_ISLT;\n    BCReg ra, rd;\n    if ((op-BC_ISLT) & 1) {  /* GT -> LT, GE -> LE */\n      e1 = e2; e2 = eret;  /* Swap operands. */\n      op = ((op-BC_ISLT)^3)+BC_ISLT;\n      expr_toval(fs, e1);\n    }\n    rd = expr_toanyreg(fs, e2);\n    ra = expr_toanyreg(fs, e1);\n    ins = BCINS_AD(op, ra, rd);\n  }\n  /* Using expr_free might cause asserts if the order is wrong. */\n  if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;\n  if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;\n  bcemit_INS(fs, ins);\n  eret->u.s.info = bcemit_jmp(fs);\n  eret->k = VJMP;\n}\n\n/* Fixup left side of binary operator. */\nstatic void bcemit_binop_left(FuncState *fs, BinOpr op, ExpDesc *e)\n{\n  if (op == OPR_AND) {\n    bcemit_branch_t(fs, e);\n  } else if (op == OPR_OR) {\n    bcemit_branch_f(fs, e);\n  } else if (op == OPR_CONCAT) {\n    expr_tonextreg(fs, e);\n  } else if (op == OPR_EQ || op == OPR_NE) {\n    if (!expr_isk_nojump(e)) expr_toanyreg(fs, e);\n  } else {\n    if (!expr_isnumk_nojump(e)) expr_toanyreg(fs, e);\n  }\n}\n\n/* Emit binary operator. */\nstatic void bcemit_binop(FuncState *fs, BinOpr op, ExpDesc *e1, ExpDesc *e2)\n{\n  if (op <= OPR_POW) {\n    bcemit_arith(fs, op, e1, e2);\n  } else if (op == OPR_AND) {\n    lua_assert(e1->t == NO_JMP);  /* List must be closed. */\n    expr_discharge(fs, e2);\n    jmp_append(fs, &e2->f, e1->f);\n    *e1 = *e2;\n  } else if (op == OPR_OR) {\n    lua_assert(e1->f == NO_JMP);  /* List must be closed. */\n    expr_discharge(fs, e2);\n    jmp_append(fs, &e2->t, e1->t);\n    *e1 = *e2;\n  } else if (op == OPR_CONCAT) {\n    expr_toval(fs, e2);\n    if (e2->k == VRELOCABLE && bc_op(*bcptr(fs, e2)) == BC_CAT) {\n      lua_assert(e1->u.s.info == bc_b(*bcptr(fs, e2))-1);\n      expr_free(fs, e1);\n      setbc_b(bcptr(fs, e2), e1->u.s.info);\n      e1->u.s.info = e2->u.s.info;\n    } else {\n      expr_tonextreg(fs, e2);\n      expr_free(fs, e2);\n      expr_free(fs, e1);\n      e1->u.s.info = bcemit_ABC(fs, BC_CAT, 0, e1->u.s.info, e2->u.s.info);\n    }\n    e1->k = VRELOCABLE;\n  } else {\n    lua_assert(op == OPR_NE || op == OPR_EQ ||\n\t       op == OPR_LT || op == OPR_GE || op == OPR_LE || op == OPR_GT);\n    bcemit_comp(fs, op, e1, e2);\n  }\n}\n\n/* Emit unary operator. */\nstatic void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e)\n{\n  if (op == BC_NOT) {\n    /* Swap true and false lists. */\n    { BCPos temp = e->f; e->f = e->t; e->t = temp; }\n    jmp_dropval(fs, e->f);\n    jmp_dropval(fs, e->t);\n    expr_discharge(fs, e);\n    if (e->k == VKNIL || e->k == VKFALSE) {\n      e->k = VKTRUE;\n      return;\n    } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) {\n      e->k = VKFALSE;\n      return;\n    } else if (e->k == VJMP) {\n      invertcond(fs, e);\n      return;\n    } else if (e->k == VRELOCABLE) {\n      bcreg_reserve(fs, 1);\n      setbc_a(bcptr(fs, e), fs->freereg-1);\n      e->u.s.info = fs->freereg-1;\n      e->k = VNONRELOC;\n    } else {\n      lua_assert(e->k == VNONRELOC);\n    }\n  } else {\n    lua_assert(op == BC_UNM || op == BC_LEN);\n    if (op == BC_UNM && !expr_hasjump(e)) {  /* Constant-fold negations. */\n#if LJ_HASFFI\n      if (e->k == VKCDATA) {  /* Fold in-place since cdata is not interned. */\n\tGCcdata *cd = cdataV(&e->u.nval);\n\tint64_t *p = (int64_t *)cdataptr(cd);\n\tif (cd->ctypeid == CTID_COMPLEX_DOUBLE)\n\t  p[1] ^= (int64_t)U64x(80000000,00000000);\n\telse\n\t  *p = -*p;\n\treturn;\n      } else\n#endif\n      if (expr_isnumk(e) && !expr_numiszero(e)) {  /* Avoid folding to -0. */\n\tTValue *o = expr_numtv(e);\n\tif (tvisint(o)) {\n\t  int32_t k = intV(o);\n\t  if (k == -k)\n\t    setnumV(o, -(lua_Number)k);\n\t  else\n\t    setintV(o, -k);\n\t  return;\n\t} else {\n\t  o->u64 ^= U64x(80000000,00000000);\n\t  return;\n\t}\n      }\n    }\n    expr_toanyreg(fs, e);\n  }\n  expr_free(fs, e);\n  e->u.s.info = bcemit_AD(fs, op, 0, e->u.s.info);\n  e->k = VRELOCABLE;\n}\n\n/* -- Lexer support ------------------------------------------------------- */\n\n/* Check and consume optional token. */\nstatic int lex_opt(LexState *ls, LexToken tok)\n{\n  if (ls->tok == tok) {\n    lj_lex_next(ls);\n    return 1;\n  }\n  return 0;\n}\n\n/* Check and consume token. */\nstatic void lex_check(LexState *ls, LexToken tok)\n{\n  if (ls->tok != tok)\n    err_token(ls, tok);\n  lj_lex_next(ls);\n}\n\n/* Check for matching token. */\nstatic void lex_match(LexState *ls, LexToken what, LexToken who, BCLine line)\n{\n  if (!lex_opt(ls, what)) {\n    if (line == ls->linenumber) {\n      err_token(ls, what);\n    } else {\n      const char *swhat = lj_lex_token2str(ls, what);\n      const char *swho = lj_lex_token2str(ls, who);\n      lj_lex_error(ls, ls->tok, LJ_ERR_XMATCH, swhat, swho, line);\n    }\n  }\n}\n\n/* Check for string token. */\nstatic GCstr *lex_str(LexState *ls)\n{\n  GCstr *s;\n  if (ls->tok != TK_name && (LJ_52 || ls->tok != TK_goto))\n    err_token(ls, TK_name);\n  s = strV(&ls->tokval);\n  lj_lex_next(ls);\n  return s;\n}\n\n/* -- Variable handling --------------------------------------------------- */\n\n#define var_get(ls, fs, i)\t((ls)->vstack[(fs)->varmap[(i)]])\n\n/* Define a new local variable. */\nstatic void var_new(LexState *ls, BCReg n, GCstr *name)\n{\n  FuncState *fs = ls->fs;\n  MSize vtop = ls->vtop;\n  checklimit(fs, fs->nactvar+n, LJ_MAX_LOCVAR, \"local variables\");\n  if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {\n    if (ls->sizevstack >= LJ_MAX_VSTACK)\n      lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);\n    lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);\n  }\n  lua_assert((uintptr_t)name < VARNAME__MAX ||\n\t     lj_tab_getstr(fs->kt, name) != NULL);\n  /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */\n  setgcref(ls->vstack[vtop].name, obj2gco(name));\n  fs->varmap[fs->nactvar+n] = (uint16_t)vtop;\n  ls->vtop = vtop+1;\n}\n\n#define var_new_lit(ls, n, v) \\\n  var_new(ls, (n), lj_parse_keepstr(ls, \"\" v, sizeof(v)-1))\n\n#define var_new_fixed(ls, n, vn) \\\n  var_new(ls, (n), (GCstr *)(uintptr_t)(vn))\n\n/* Add local variables. */\nstatic void var_add(LexState *ls, BCReg nvars)\n{\n  FuncState *fs = ls->fs;\n  BCReg nactvar = fs->nactvar;\n  while (nvars--) {\n    VarInfo *v = &var_get(ls, fs, nactvar);\n    v->startpc = fs->pc;\n    v->slot = nactvar++;\n    v->info = 0;\n  }\n  fs->nactvar = nactvar;\n}\n\n/* Remove local variables. */\nstatic void var_remove(LexState *ls, BCReg tolevel)\n{\n  FuncState *fs = ls->fs;\n  while (fs->nactvar > tolevel)\n    var_get(ls, fs, --fs->nactvar).endpc = fs->pc;\n}\n\n/* Lookup local variable name. */\nstatic BCReg var_lookup_local(FuncState *fs, GCstr *n)\n{\n  int i;\n  for (i = fs->nactvar-1; i >= 0; i--) {\n    if (n == strref(var_get(fs->ls, fs, i).name))\n      return (BCReg)i;\n  }\n  return (BCReg)-1;  /* Not found. */\n}\n\n/* Lookup or add upvalue index. */\nstatic MSize var_lookup_uv(FuncState *fs, MSize vidx, ExpDesc *e)\n{\n  MSize i, n = fs->nuv;\n  for (i = 0; i < n; i++)\n    if (fs->uvmap[i] == vidx)\n      return i;  /* Already exists. */\n  /* Otherwise create a new one. */\n  checklimit(fs, fs->nuv, LJ_MAX_UPVAL, \"upvalues\");\n  lua_assert(e->k == VLOCAL || e->k == VUPVAL);\n  fs->uvmap[n] = (uint16_t)vidx;\n  fs->uvtmp[n] = (uint16_t)(e->k == VLOCAL ? vidx : LJ_MAX_VSTACK+e->u.s.info);\n  fs->nuv = n+1;\n  return n;\n}\n\n/* Forward declaration. */\nstatic void fscope_uvmark(FuncState *fs, BCReg level);\n\n/* Recursively lookup variables in enclosing functions. */\nstatic MSize var_lookup_(FuncState *fs, GCstr *name, ExpDesc *e, int first)\n{\n  if (fs) {\n    BCReg reg = var_lookup_local(fs, name);\n    if ((int32_t)reg >= 0) {  /* Local in this function? */\n      expr_init(e, VLOCAL, reg);\n      if (!first)\n\tfscope_uvmark(fs, reg);  /* Scope now has an upvalue. */\n      return (MSize)(e->u.s.aux = (uint32_t)fs->varmap[reg]);\n    } else {\n      MSize vidx = var_lookup_(fs->prev, name, e, 0);  /* Var in outer func? */\n      if ((int32_t)vidx >= 0) {  /* Yes, make it an upvalue here. */\n\te->u.s.info = (uint8_t)var_lookup_uv(fs, vidx, e);\n\te->k = VUPVAL;\n\treturn vidx;\n      }\n    }\n  } else {  /* Not found in any function, must be a global. */\n    expr_init(e, VGLOBAL, 0);\n    e->u.sval = name;\n  }\n  return (MSize)-1;  /* Global. */\n}\n\n/* Lookup variable name. */\n#define var_lookup(ls, e) \\\n  var_lookup_((ls)->fs, lex_str(ls), (e), 1)\n\n/* -- Goto an label handling ---------------------------------------------- */\n\n/* Add a new goto or label. */\nstatic MSize gola_new(LexState *ls, GCstr *name, uint8_t info, BCPos pc)\n{\n  FuncState *fs = ls->fs;\n  MSize vtop = ls->vtop;\n  if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {\n    if (ls->sizevstack >= LJ_MAX_VSTACK)\n      lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);\n    lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);\n  }\n  lua_assert(name == NAME_BREAK || lj_tab_getstr(fs->kt, name) != NULL);\n  /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */\n  setgcref(ls->vstack[vtop].name, obj2gco(name));\n  ls->vstack[vtop].startpc = pc;\n  ls->vstack[vtop].slot = (uint8_t)fs->nactvar;\n  ls->vstack[vtop].info = info;\n  ls->vtop = vtop+1;\n  return vtop;\n}\n\n#define gola_isgoto(v)\t\t((v)->info & VSTACK_GOTO)\n#define gola_islabel(v)\t\t((v)->info & VSTACK_LABEL)\n#define gola_isgotolabel(v)\t((v)->info & (VSTACK_GOTO|VSTACK_LABEL))\n\n/* Patch goto to jump to label. */\nstatic void gola_patch(LexState *ls, VarInfo *vg, VarInfo *vl)\n{\n  FuncState *fs = ls->fs;\n  BCPos pc = vg->startpc;\n  setgcrefnull(vg->name);  /* Invalidate pending goto. */\n  setbc_a(&fs->bcbase[pc].ins, vl->slot);\n  jmp_patch(fs, pc, vl->startpc);\n}\n\n/* Patch goto to close upvalues. */\nstatic void gola_close(LexState *ls, VarInfo *vg)\n{\n  FuncState *fs = ls->fs;\n  BCPos pc = vg->startpc;\n  BCIns *ip = &fs->bcbase[pc].ins;\n  lua_assert(gola_isgoto(vg));\n  lua_assert(bc_op(*ip) == BC_JMP || bc_op(*ip) == BC_UCLO);\n  setbc_a(ip, vg->slot);\n  if (bc_op(*ip) == BC_JMP) {\n    BCPos next = jmp_next(fs, pc);\n    if (next != NO_JMP) jmp_patch(fs, next, pc);  /* Jump to UCLO. */\n    setbc_op(ip, BC_UCLO);  /* Turn into UCLO. */\n    setbc_j(ip, NO_JMP);\n  }\n}\n\n/* Resolve pending forward gotos for label. */\nstatic void gola_resolve(LexState *ls, FuncScope *bl, MSize idx)\n{\n  VarInfo *vg = ls->vstack + bl->vstart;\n  VarInfo *vl = ls->vstack + idx;\n  for (; vg < vl; vg++)\n    if (gcrefeq(vg->name, vl->name) && gola_isgoto(vg)) {\n      if (vg->slot < vl->slot) {\n\tGCstr *name = strref(var_get(ls, ls->fs, vg->slot).name);\n\tlua_assert((uintptr_t)name >= VARNAME__MAX);\n\tls->linenumber = ls->fs->bcbase[vg->startpc].line;\n\tlua_assert(strref(vg->name) != NAME_BREAK);\n\tlj_lex_error(ls, 0, LJ_ERR_XGSCOPE,\n\t\t     strdata(strref(vg->name)), strdata(name));\n      }\n      gola_patch(ls, vg, vl);\n    }\n}\n\n/* Fixup remaining gotos and labels for scope. */\nstatic void gola_fixup(LexState *ls, FuncScope *bl)\n{\n  VarInfo *v = ls->vstack + bl->vstart;\n  VarInfo *ve = ls->vstack + ls->vtop;\n  for (; v < ve; v++) {\n    GCstr *name = strref(v->name);\n    if (name != NULL) {  /* Only consider remaining valid gotos/labels. */\n      if (gola_islabel(v)) {\n\tVarInfo *vg;\n\tsetgcrefnull(v->name);  /* Invalidate label that goes out of scope. */\n\tfor (vg = v+1; vg < ve; vg++)  /* Resolve pending backward gotos. */\n\t  if (strref(vg->name) == name && gola_isgoto(vg)) {\n\t    if ((bl->flags&FSCOPE_UPVAL) && vg->slot > v->slot)\n\t      gola_close(ls, vg);\n\t    gola_patch(ls, vg, v);\n\t  }\n      } else if (gola_isgoto(v)) {\n\tif (bl->prev) {  /* Propagate goto or break to outer scope. */\n\t  bl->prev->flags |= name == NAME_BREAK ? FSCOPE_BREAK : FSCOPE_GOLA;\n\t  v->slot = bl->nactvar;\n\t  if ((bl->flags & FSCOPE_UPVAL))\n\t    gola_close(ls, v);\n\t} else {  /* No outer scope: undefined goto label or no loop. */\n\t  ls->linenumber = ls->fs->bcbase[v->startpc].line;\n\t  if (name == NAME_BREAK)\n\t    lj_lex_error(ls, 0, LJ_ERR_XBREAK);\n\t  else\n\t    lj_lex_error(ls, 0, LJ_ERR_XLUNDEF, strdata(name));\n\t}\n      }\n    }\n  }\n}\n\n/* Find existing label. */\nstatic VarInfo *gola_findlabel(LexState *ls, GCstr *name)\n{\n  VarInfo *v = ls->vstack + ls->fs->bl->vstart;\n  VarInfo *ve = ls->vstack + ls->vtop;\n  for (; v < ve; v++)\n    if (strref(v->name) == name && gola_islabel(v))\n      return v;\n  return NULL;\n}\n\n/* -- Scope handling ------------------------------------------------------ */\n\n/* Begin a scope. */\nstatic void fscope_begin(FuncState *fs, FuncScope *bl, int flags)\n{\n  bl->nactvar = (uint8_t)fs->nactvar;\n  bl->flags = flags;\n  bl->vstart = fs->ls->vtop;\n  bl->prev = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n/* End a scope. */\nstatic void fscope_end(FuncState *fs)\n{\n  FuncScope *bl = fs->bl;\n  LexState *ls = fs->ls;\n  fs->bl = bl->prev;\n  var_remove(ls, bl->nactvar);\n  fs->freereg = fs->nactvar;\n  lua_assert(bl->nactvar == fs->nactvar);\n  if ((bl->flags & (FSCOPE_UPVAL|FSCOPE_NOCLOSE)) == FSCOPE_UPVAL)\n    bcemit_AJ(fs, BC_UCLO, bl->nactvar, 0);\n  if ((bl->flags & FSCOPE_BREAK)) {\n    if ((bl->flags & FSCOPE_LOOP)) {\n      MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc);\n      ls->vtop = idx;  /* Drop break label immediately. */\n      gola_resolve(ls, bl, idx);\n      return;\n    }  /* else: need the fixup step to propagate the breaks. */\n  } else if (!(bl->flags & FSCOPE_GOLA)) {\n    return;\n  }\n  gola_fixup(ls, bl);\n}\n\n/* Mark scope as having an upvalue. */\nstatic void fscope_uvmark(FuncState *fs, BCReg level)\n{\n  FuncScope *bl;\n  for (bl = fs->bl; bl && bl->nactvar > level; bl = bl->prev)\n    ;\n  if (bl)\n    bl->flags |= FSCOPE_UPVAL;\n}\n\n/* -- Function state management ------------------------------------------- */\n\n/* Fixup bytecode for prototype. */\nstatic void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, MSize n)\n{\n  BCInsLine *base = fs->bcbase;\n  MSize i;\n  pt->sizebc = n;\n  bc[0] = BCINS_AD((fs->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,\n\t\t   fs->framesize, 0);\n  for (i = 1; i < n; i++)\n    bc[i] = base[i].ins;\n}\n\n/* Fixup upvalues for child prototype, step #2. */\nstatic void fs_fixup_uv2(FuncState *fs, GCproto *pt)\n{\n  VarInfo *vstack = fs->ls->vstack;\n  uint16_t *uv = proto_uv(pt);\n  MSize i, n = pt->sizeuv;\n  for (i = 0; i < n; i++) {\n    VarIndex vidx = uv[i];\n    if (vidx >= LJ_MAX_VSTACK)\n      uv[i] = vidx - LJ_MAX_VSTACK;\n    else if ((vstack[vidx].info & VSTACK_VAR_RW))\n      uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL;\n    else\n      uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL | PROTO_UV_IMMUTABLE;\n  }\n}\n\n/* Fixup constants for prototype. */\nstatic void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr)\n{\n  GCtab *kt;\n  TValue *array;\n  Node *node;\n  MSize i, hmask;\n  checklimitgt(fs, fs->nkn, BCMAX_D+1, \"constants\");\n  checklimitgt(fs, fs->nkgc, BCMAX_D+1, \"constants\");\n  setmref(pt->k, kptr);\n  pt->sizekn = fs->nkn;\n  pt->sizekgc = fs->nkgc;\n  kt = fs->kt;\n  array = tvref(kt->array);\n  for (i = 0; i < kt->asize; i++)\n    if (tvhaskslot(&array[i])) {\n      TValue *tv = &((TValue *)kptr)[tvkslot(&array[i])];\n      if (LJ_DUALNUM)\n\tsetintV(tv, (int32_t)i);\n      else\n\tsetnumV(tv, (lua_Number)i);\n    }\n  node = noderef(kt->node);\n  hmask = kt->hmask;\n  for (i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    if (tvhaskslot(&n->val)) {\n      ptrdiff_t kidx = (ptrdiff_t)tvkslot(&n->val);\n      lua_assert(!tvisint(&n->key));\n      if (tvisnum(&n->key)) {\n\tTValue *tv = &((TValue *)kptr)[kidx];\n\tif (LJ_DUALNUM) {\n\t  lua_Number nn = numV(&n->key);\n\t  int32_t k = lj_num2int(nn);\n\t  lua_assert(!tvismzero(&n->key));\n\t  if ((lua_Number)k == nn)\n\t    setintV(tv, k);\n\t  else\n\t    *tv = n->key;\n\t} else {\n\t  *tv = n->key;\n\t}\n      } else {\n\tGCobj *o = gcV(&n->key);\n\tsetgcref(((GCRef *)kptr)[~kidx], o);\n\tlj_gc_objbarrier(fs->L, pt, o);\n\tif (tvisproto(&n->key))\n\t  fs_fixup_uv2(fs, gco2pt(o));\n      }\n    }\n  }\n}\n\n/* Fixup upvalues for prototype, step #1. */\nstatic void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv)\n{\n  setmref(pt->uv, uv);\n  pt->sizeuv = fs->nuv;\n  memcpy(uv, fs->uvtmp, fs->nuv*sizeof(VarIndex));\n}\n\n#ifndef LUAJIT_DISABLE_DEBUGINFO\n/* Prepare lineinfo for prototype. */\nstatic size_t fs_prep_line(FuncState *fs, BCLine numline)\n{\n  return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);\n}\n\n/* Fixup lineinfo for prototype. */\nstatic void fs_fixup_line(FuncState *fs, GCproto *pt,\n\t\t\t  void *lineinfo, BCLine numline)\n{\n  BCInsLine *base = fs->bcbase + 1;\n  BCLine first = fs->linedefined;\n  MSize i = 0, n = fs->pc-1;\n  pt->firstline = fs->linedefined;\n  pt->numline = numline;\n  setmref(pt->lineinfo, lineinfo);\n  if (LJ_LIKELY(numline < 256)) {\n    uint8_t *li = (uint8_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lua_assert(delta >= 0 && delta < 256);\n      li[i] = (uint8_t)delta;\n    } while (++i < n);\n  } else if (LJ_LIKELY(numline < 65536)) {\n    uint16_t *li = (uint16_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lua_assert(delta >= 0 && delta < 65536);\n      li[i] = (uint16_t)delta;\n    } while (++i < n);\n  } else {\n    uint32_t *li = (uint32_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lua_assert(delta >= 0);\n      li[i] = (uint32_t)delta;\n    } while (++i < n);\n  }\n}\n\n/* Prepare variable info for prototype. */\nstatic size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar)\n{\n  VarInfo *vs =ls->vstack, *ve;\n  MSize i, n;\n  BCPos lastpc;\n  lj_buf_reset(&ls->sb);  /* Copy to temp. string buffer. */\n  /* Store upvalue names. */\n  for (i = 0, n = fs->nuv; i < n; i++) {\n    GCstr *s = strref(vs[fs->uvmap[i]].name);\n    MSize len = s->len+1;\n    char *p = lj_buf_more(&ls->sb, len);\n    p = lj_buf_wmem(p, strdata(s), len);\n    setsbufP(&ls->sb, p);\n  }\n  *ofsvar = sbuflen(&ls->sb);\n  lastpc = 0;\n  /* Store local variable names and compressed ranges. */\n  for (ve = vs + ls->vtop, vs += fs->vbase; vs < ve; vs++) {\n    if (!gola_isgotolabel(vs)) {\n      GCstr *s = strref(vs->name);\n      BCPos startpc;\n      char *p;\n      if ((uintptr_t)s < VARNAME__MAX) {\n\tp = lj_buf_more(&ls->sb, 1 + 2*5);\n\t*p++ = (char)(uintptr_t)s;\n      } else {\n\tMSize len = s->len+1;\n\tp = lj_buf_more(&ls->sb, len + 2*5);\n\tp = lj_buf_wmem(p, strdata(s), len);\n      }\n      startpc = vs->startpc;\n      p = lj_strfmt_wuleb128(p, startpc-lastpc);\n      p = lj_strfmt_wuleb128(p, vs->endpc-startpc);\n      setsbufP(&ls->sb, p);\n      lastpc = startpc;\n    }\n  }\n  lj_buf_putb(&ls->sb, '\\0');  /* Terminator for varinfo. */\n  return sbuflen(&ls->sb);\n}\n\n/* Fixup variable info for prototype. */\nstatic void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)\n{\n  setmref(pt->uvinfo, p);\n  setmref(pt->varinfo, (char *)p + ofsvar);\n  memcpy(p, sbufB(&ls->sb), sbuflen(&ls->sb));  /* Copy from temp. buffer. */\n}\n#else\n\n/* Initialize with empty debug info, if disabled. */\n#define fs_prep_line(fs, numline)\t\t(UNUSED(numline), 0)\n#define fs_fixup_line(fs, pt, li, numline) \\\n  pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)\n#define fs_prep_var(ls, fs, ofsvar)\t\t(UNUSED(ofsvar), 0)\n#define fs_fixup_var(ls, pt, p, ofsvar) \\\n  setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL)\n\n#endif\n\n/* Check if bytecode op returns. */\nstatic int bcopisret(BCOp op)\n{\n  switch (op) {\n  case BC_CALLMT: case BC_CALLT:\n  case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:\n    return 1;\n  default:\n    return 0;\n  }\n}\n\n/* Fixup return instruction for prototype. */\nstatic void fs_fixup_ret(FuncState *fs)\n{\n  BCPos lastpc = fs->pc;\n  if (lastpc <= fs->lasttarget || !bcopisret(bc_op(fs->bcbase[lastpc-1].ins))) {\n    if ((fs->bl->flags & FSCOPE_UPVAL))\n      bcemit_AJ(fs, BC_UCLO, 0, 0);\n    bcemit_AD(fs, BC_RET0, 0, 1);  /* Need final return. */\n  }\n  fs->bl->flags |= FSCOPE_NOCLOSE;  /* Handled above. */\n  fscope_end(fs);\n  lua_assert(fs->bl == NULL);\n  /* May need to fixup returns encoded before first function was created. */\n  if (fs->flags & PROTO_FIXUP_RETURN) {\n    BCPos pc;\n    for (pc = 1; pc < lastpc; pc++) {\n      BCIns ins = fs->bcbase[pc].ins;\n      BCPos offset;\n      switch (bc_op(ins)) {\n      case BC_CALLMT: case BC_CALLT:\n      case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:\n\toffset = bcemit_INS(fs, ins);  /* Copy original instruction. */\n\tfs->bcbase[offset].line = fs->bcbase[pc].line;\n\toffset = offset-(pc+1)+BCBIAS_J;\n\tif (offset > BCMAX_D)\n\t  err_syntax(fs->ls, LJ_ERR_XFIXUP);\n\t/* Replace with UCLO plus branch. */\n\tfs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset);\n\tbreak;\n      case BC_UCLO:\n\treturn;  /* We're done. */\n      default:\n\tbreak;\n      }\n    }\n  }\n}\n\n/* Finish a FuncState and return the new prototype. */\nstatic GCproto *fs_finish(LexState *ls, BCLine line)\n{\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  BCLine numline = line - fs->linedefined;\n  size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar;\n  GCproto *pt;\n\n  /* Apply final fixups. */\n  fs_fixup_ret(fs);\n\n  /* Calculate total size of prototype including all colocated arrays. */\n  sizept = sizeof(GCproto) + fs->pc*sizeof(BCIns) + fs->nkgc*sizeof(GCRef);\n  sizept = (sizept + sizeof(TValue)-1) & ~(sizeof(TValue)-1);\n  ofsk = sizept; sizept += fs->nkn*sizeof(TValue);\n  ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2;\n  ofsli = sizept; sizept += fs_prep_line(fs, numline);\n  ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar);\n\n  /* Allocate prototype and initialize its fields. */\n  pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept);\n  pt->gct = ~LJ_TPROTO;\n  pt->sizept = (MSize)sizept;\n  pt->trace = 0;\n  pt->flags = (uint8_t)(fs->flags & ~(PROTO_HAS_RETURN|PROTO_FIXUP_RETURN));\n  pt->numparams = fs->numparams;\n  pt->framesize = fs->framesize;\n  setgcref(pt->chunkname, obj2gco(ls->chunkname));\n\n  /* Close potentially uninitialized gap between bc and kgc. */\n  *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(fs->nkgc+1)) = 0;\n  fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), fs->pc);\n  fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk));\n  fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv));\n  fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline);\n  fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar);\n\n  lj_vmevent_send(L, BC,\n    setprotoV(L, L->top++, pt);\n  );\n\n  L->top--;  /* Pop table of constants. */\n  ls->vtop = fs->vbase;  /* Reset variable stack. */\n  ls->fs = fs->prev;\n  lua_assert(ls->fs != NULL || ls->tok == TK_eof);\n  return pt;\n}\n\n/* Initialize a new FuncState. */\nstatic void fs_init(LexState *ls, FuncState *fs)\n{\n  lua_State *L = ls->L;\n  fs->prev = ls->fs; ls->fs = fs;  /* Append to list. */\n  fs->ls = ls;\n  fs->vbase = ls->vtop;\n  fs->L = L;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JMP;\n  fs->freereg = 0;\n  fs->nkgc = 0;\n  fs->nkn = 0;\n  fs->nactvar = 0;\n  fs->nuv = 0;\n  fs->bl = NULL;\n  fs->flags = 0;\n  fs->framesize = 1;  /* Minimum frame size. */\n  fs->kt = lj_tab_new(L, 0, 0);\n  /* Anchor table of constants in stack to avoid being collected. */\n  settabV(L, L->top, fs->kt);\n  incr_top(L);\n}\n\n/* -- Expressions --------------------------------------------------------- */\n\n/* Forward declaration. */\nstatic void expr(LexState *ls, ExpDesc *v);\n\n/* Return string expression. */\nstatic void expr_str(LexState *ls, ExpDesc *e)\n{\n  expr_init(e, VKSTR, 0);\n  e->u.sval = lex_str(ls);\n}\n\n/* Return index expression. */\nstatic void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e)\n{\n  /* Already called: expr_toval(fs, e). */\n  t->k = VINDEXED;\n  if (expr_isnumk(e)) {\n#if LJ_DUALNUM\n    if (tvisint(expr_numtv(e))) {\n      int32_t k = intV(expr_numtv(e));\n      if (checku8(k)) {\n\tt->u.s.aux = BCMAX_C+1+(uint32_t)k;  /* 256..511: const byte key */\n\treturn;\n      }\n    }\n#else\n    lua_Number n = expr_numberV(e);\n    int32_t k = lj_num2int(n);\n    if (checku8(k) && n == (lua_Number)k) {\n      t->u.s.aux = BCMAX_C+1+(uint32_t)k;  /* 256..511: const byte key */\n      return;\n    }\n#endif\n  } else if (expr_isstrk(e)) {\n    BCReg idx = const_str(fs, e);\n    if (idx <= BCMAX_C) {\n      t->u.s.aux = ~idx;  /* -256..-1: const string key */\n      return;\n    }\n  }\n  t->u.s.aux = expr_toanyreg(fs, e);  /* 0..255: register */\n}\n\n/* Parse index expression with named field. */\nstatic void expr_field(LexState *ls, ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc key;\n  expr_toanyreg(fs, v);\n  lj_lex_next(ls);  /* Skip dot or colon. */\n  expr_str(ls, &key);\n  expr_index(fs, v, &key);\n}\n\n/* Parse index expression with brackets. */\nstatic void expr_bracket(LexState *ls, ExpDesc *v)\n{\n  lj_lex_next(ls);  /* Skip '['. */\n  expr(ls, v);\n  expr_toval(ls->fs, v);\n  lex_check(ls, ']');\n}\n\n/* Get value of constant expression. */\nstatic void expr_kvalue(TValue *v, ExpDesc *e)\n{\n  if (e->k <= VKTRUE) {\n    setpriV(v, ~(uint32_t)e->k);\n  } else if (e->k == VKSTR) {\n    setgcVraw(v, obj2gco(e->u.sval), LJ_TSTR);\n  } else {\n    lua_assert(tvisnumber(expr_numtv(e)));\n    *v = *expr_numtv(e);\n  }\n}\n\n/* Parse table constructor expression. */\nstatic void expr_table(LexState *ls, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  BCLine line = ls->linenumber;\n  GCtab *t = NULL;\n  int vcall = 0, needarr = 0, fixt = 0;\n  uint32_t narr = 1;  /* First array index. */\n  uint32_t nhash = 0;  /* Number of hash entries. */\n  BCReg freg = fs->freereg;\n  BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0);\n  expr_init(e, VNONRELOC, freg);\n  bcreg_reserve(fs, 1);\n  freg++;\n  lex_check(ls, '{');\n  while (ls->tok != '}') {\n    ExpDesc key, val;\n    vcall = 0;\n    if (ls->tok == '[') {\n      expr_bracket(ls, &key);  /* Already calls expr_toval. */\n      if (!expr_isk(&key)) expr_index(fs, e, &key);\n      if (expr_isnumk(&key) && expr_numiszero(&key)) needarr = 1; else nhash++;\n      lex_check(ls, '=');\n    } else if ((ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) &&\n\t       lj_lex_lookahead(ls) == '=') {\n      expr_str(ls, &key);\n      lex_check(ls, '=');\n      nhash++;\n    } else {\n      expr_init(&key, VKNUM, 0);\n      setintV(&key.u.nval, (int)narr);\n      narr++;\n      needarr = vcall = 1;\n    }\n    expr(ls, &val);\n    if (expr_isk(&key) && key.k != VKNIL &&\n\t(key.k == VKSTR || expr_isk_nojump(&val))) {\n      TValue k, *v;\n      if (!t) {  /* Create template table on demand. */\n\tBCReg kidx;\n\tt = lj_tab_new(fs->L, needarr ? narr : 0, hsize2hbits(nhash));\n\tkidx = const_gc(fs, obj2gco(t), LJ_TTAB);\n\tfs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx);\n      }\n      vcall = 0;\n      expr_kvalue(&k, &key);\n      v = lj_tab_set(fs->L, t, &k);\n      lj_gc_anybarriert(fs->L, t);\n      if (expr_isk_nojump(&val)) {  /* Add const key/value to template table. */\n\texpr_kvalue(v, &val);\n      } else {  /* Otherwise create dummy string key (avoids lj_tab_newkey). */\n\tsettabV(fs->L, v, t);  /* Preserve key with table itself as value. */\n\tfixt = 1;   /* Fix this later, after all resizes. */\n\tgoto nonconst;\n      }\n    } else {\n    nonconst:\n      if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; }\n      if (expr_isk(&key)) expr_index(fs, e, &key);\n      bcemit_store(fs, e, &val);\n    }\n    fs->freereg = freg;\n    if (!lex_opt(ls, ',') && !lex_opt(ls, ';')) break;\n  }\n  lex_match(ls, '}', '{', line);\n  if (vcall) {\n    BCInsLine *ilp = &fs->bcbase[fs->pc-1];\n    ExpDesc en;\n    lua_assert(bc_a(ilp->ins) == freg &&\n\t       bc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB));\n    expr_init(&en, VKNUM, 0);\n    en.u.nval.u32.lo = narr-1;\n    en.u.nval.u32.hi = 0x43300000;  /* Biased integer to avoid denormals. */\n    if (narr > 256) { fs->pc--; ilp--; }\n    ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en));\n    setbc_b(&ilp[-1].ins, 0);\n  }\n  if (pc == fs->pc-1) {  /* Make expr relocable if possible. */\n    e->u.s.info = pc;\n    fs->freereg--;\n    e->k = VRELOCABLE;\n  } else {\n    e->k = VNONRELOC;  /* May have been changed by expr_index. */\n  }\n  if (!t) {  /* Construct TNEW RD: hhhhhaaaaaaaaaaa. */\n    BCIns *ip = &fs->bcbase[pc].ins;\n    if (!needarr) narr = 0;\n    else if (narr < 3) narr = 3;\n    else if (narr > 0x7ff) narr = 0x7ff;\n    setbc_d(ip, narr|(hsize2hbits(nhash)<<11));\n  } else {\n    if (needarr && t->asize < narr)\n      lj_tab_reasize(fs->L, t, narr-1);\n    if (fixt) {  /* Fix value for dummy keys in template table. */\n      Node *node = noderef(t->node);\n      uint32_t i, hmask = t->hmask;\n      for (i = 0; i <= hmask; i++) {\n\tNode *n = &node[i];\n\tif (tvistab(&n->val)) {\n\t  lua_assert(tabV(&n->val) == t);\n\t  setnilV(&n->val);  /* Turn value into nil. */\n\t}\n      }\n    }\n    lj_gc_check(fs->L);\n  }\n}\n\n/* Parse function parameters. */\nstatic BCReg parse_params(LexState *ls, int needself)\n{\n  FuncState *fs = ls->fs;\n  BCReg nparams = 0;\n  lex_check(ls, '(');\n  if (needself)\n    var_new_lit(ls, nparams++, \"self\");\n  if (ls->tok != ')') {\n    do {\n      if (ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) {\n\tvar_new(ls, nparams++, lex_str(ls));\n      } else if (ls->tok == TK_dots) {\n\tlj_lex_next(ls);\n\tfs->flags |= PROTO_VARARG;\n\tbreak;\n      } else {\n\terr_syntax(ls, LJ_ERR_XPARAM);\n      }\n    } while (lex_opt(ls, ','));\n  }\n  var_add(ls, nparams);\n  lua_assert(fs->nactvar == nparams);\n  bcreg_reserve(fs, nparams);\n  lex_check(ls, ')');\n  return nparams;\n}\n\n/* Forward declaration. */\nstatic void parse_chunk(LexState *ls);\n\n/* Parse body of a function. */\nstatic void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line)\n{\n  FuncState fs, *pfs = ls->fs;\n  FuncScope bl;\n  GCproto *pt;\n  ptrdiff_t oldbase = pfs->bcbase - ls->bcstack;\n  fs_init(ls, &fs);\n  fscope_begin(&fs, &bl, 0);\n  fs.linedefined = line;\n  fs.numparams = (uint8_t)parse_params(ls, needself);\n  fs.bcbase = pfs->bcbase + pfs->pc;\n  fs.bclim = pfs->bclim - pfs->pc;\n  bcemit_AD(&fs, BC_FUNCF, 0, 0);  /* Placeholder. */\n  parse_chunk(ls);\n  if (ls->tok != TK_end) lex_match(ls, TK_end, TK_function, line);\n  pt = fs_finish(ls, (ls->lastline = ls->linenumber));\n  pfs->bcbase = ls->bcstack + oldbase;  /* May have been reallocated. */\n  pfs->bclim = (BCPos)(ls->sizebcstack - oldbase);\n  /* Store new prototype in the constant array of the parent. */\n  expr_init(e, VRELOCABLE,\n\t    bcemit_AD(pfs, BC_FNEW, 0, const_gc(pfs, obj2gco(pt), LJ_TPROTO)));\n#if LJ_HASFFI\n  pfs->flags |= (fs.flags & PROTO_FFI);\n#endif\n  if (!(pfs->flags & PROTO_CHILD)) {\n    if (pfs->flags & PROTO_HAS_RETURN)\n      pfs->flags |= PROTO_FIXUP_RETURN;\n    pfs->flags |= PROTO_CHILD;\n  }\n  lj_lex_next(ls);\n}\n\n/* Parse expression list. Last expression is left open. */\nstatic BCReg expr_list(LexState *ls, ExpDesc *v)\n{\n  BCReg n = 1;\n  expr(ls, v);\n  while (lex_opt(ls, ',')) {\n    expr_tonextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n/* Parse function argument list. */\nstatic void parse_args(LexState *ls, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc args;\n  BCIns ins;\n  BCReg base;\n  BCLine line = ls->linenumber;\n  if (ls->tok == '(') {\n#if !LJ_52\n    if (line != ls->lastline)\n      err_syntax(ls, LJ_ERR_XAMBIG);\n#endif\n    lj_lex_next(ls);\n    if (ls->tok == ')') {  /* f(). */\n      args.k = VVOID;\n    } else {\n      expr_list(ls, &args);\n      if (args.k == VCALL)  /* f(a, b, g()) or f(a, b, ...). */\n\tsetbc_b(bcptr(fs, &args), 0);  /* Pass on multiple results. */\n    }\n    lex_match(ls, ')', '(', line);\n  } else if (ls->tok == '{') {\n    expr_table(ls, &args);\n  } else if (ls->tok == TK_string) {\n    expr_init(&args, VKSTR, 0);\n    args.u.sval = strV(&ls->tokval);\n    lj_lex_next(ls);\n  } else {\n    err_syntax(ls, LJ_ERR_XFUNARG);\n    return;  /* Silence compiler. */\n  }\n  lua_assert(e->k == VNONRELOC);\n  base = e->u.s.info;  /* Base register for call. */\n  if (args.k == VCALL) {\n    ins = BCINS_ABC(BC_CALLM, base, 2, args.u.s.aux - base - 1 - LJ_FR2);\n  } else {\n    if (args.k != VVOID)\n      expr_tonextreg(fs, &args);\n    ins = BCINS_ABC(BC_CALL, base, 2, fs->freereg - base - LJ_FR2);\n  }\n  expr_init(e, VCALL, bcemit_INS(fs, ins));\n  e->u.s.aux = base;\n  fs->bcbase[fs->pc - 1].line = line;\n  fs->freereg = base+1;  /* Leave one result by default. */\n}\n\n/* Parse primary expression. */\nstatic void expr_primary(LexState *ls, ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  /* Parse prefix expression. */\n  if (ls->tok == '(') {\n    BCLine line = ls->linenumber;\n    lj_lex_next(ls);\n    expr(ls, v);\n    lex_match(ls, ')', '(', line);\n    expr_discharge(ls->fs, v);\n  } else if (ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) {\n    var_lookup(ls, v);\n  } else {\n    err_syntax(ls, LJ_ERR_XSYMBOL);\n  }\n  for (;;) {  /* Parse multiple expression suffixes. */\n    if (ls->tok == '.') {\n      expr_field(ls, v);\n    } else if (ls->tok == '[') {\n      ExpDesc key;\n      expr_toanyreg(fs, v);\n      expr_bracket(ls, &key);\n      expr_index(fs, v, &key);\n    } else if (ls->tok == ':') {\n      ExpDesc key;\n      lj_lex_next(ls);\n      expr_str(ls, &key);\n      bcemit_method(fs, v, &key);\n      parse_args(ls, v);\n    } else if (ls->tok == '(' || ls->tok == TK_string || ls->tok == '{') {\n      expr_tonextreg(fs, v);\n      if (LJ_FR2) bcreg_reserve(fs, 1);\n      parse_args(ls, v);\n    } else {\n      break;\n    }\n  }\n}\n\n/* Parse simple expression. */\nstatic void expr_simple(LexState *ls, ExpDesc *v)\n{\n  switch (ls->tok) {\n  case TK_number:\n    expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokval)) ? VKCDATA : VKNUM, 0);\n    copyTV(ls->L, &v->u.nval, &ls->tokval);\n    break;\n  case TK_string:\n    expr_init(v, VKSTR, 0);\n    v->u.sval = strV(&ls->tokval);\n    break;\n  case TK_nil:\n    expr_init(v, VKNIL, 0);\n    break;\n  case TK_true:\n    expr_init(v, VKTRUE, 0);\n    break;\n  case TK_false:\n    expr_init(v, VKFALSE, 0);\n    break;\n  case TK_dots: {  /* Vararg. */\n    FuncState *fs = ls->fs;\n    BCReg base;\n    checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS);\n    bcreg_reserve(fs, 1);\n    base = fs->freereg-1;\n    expr_init(v, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams));\n    v->u.s.aux = base;\n    break;\n  }\n  case '{':  /* Table constructor. */\n    expr_table(ls, v);\n    return;\n  case TK_function:\n    lj_lex_next(ls);\n    parse_body(ls, v, 0, ls->linenumber);\n    return;\n  default:\n    expr_primary(ls, v);\n    return;\n  }\n  lj_lex_next(ls);\n}\n\n/* Manage syntactic levels to avoid blowing up the stack. */\nstatic void synlevel_begin(LexState *ls)\n{\n  if (++ls->level >= LJ_MAX_XLEVEL)\n    lj_lex_error(ls, 0, LJ_ERR_XLEVELS);\n}\n\n#define synlevel_end(ls)\t((ls)->level--)\n\n/* Convert token to binary operator. */\nstatic BinOpr token2binop(LexToken tok)\n{\n  switch (tok) {\n  case '+':\treturn OPR_ADD;\n  case '-':\treturn OPR_SUB;\n  case '*':\treturn OPR_MUL;\n  case '/':\treturn OPR_DIV;\n  case '%':\treturn OPR_MOD;\n  case '^':\treturn OPR_POW;\n  case TK_concat: return OPR_CONCAT;\n  case TK_ne:\treturn OPR_NE;\n  case TK_eq:\treturn OPR_EQ;\n  case '<':\treturn OPR_LT;\n  case TK_le:\treturn OPR_LE;\n  case '>':\treturn OPR_GT;\n  case TK_ge:\treturn OPR_GE;\n  case TK_and:\treturn OPR_AND;\n  case TK_or:\treturn OPR_OR;\n  default:\treturn OPR_NOBINOPR;\n  }\n}\n\n/* Priorities for each binary operator. ORDER OPR. */\nstatic const struct {\n  uint8_t left;\t\t/* Left priority. */\n  uint8_t right;\t/* Right priority. */\n} priority[] = {\n  {6,6}, {6,6}, {7,7}, {7,7}, {7,7},\t/* ADD SUB MUL DIV MOD */\n  {10,9}, {5,4},\t\t\t/* POW CONCAT (right associative) */\n  {3,3}, {3,3},\t\t\t\t/* EQ NE */\n  {3,3}, {3,3}, {3,3}, {3,3},\t\t/* LT GE GT LE */\n  {2,2}, {1,1}\t\t\t\t/* AND OR */\n};\n\n#define UNARY_PRIORITY\t\t8  /* Priority for unary operators. */\n\n/* Forward declaration. */\nstatic BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit);\n\n/* Parse unary expression. */\nstatic void expr_unop(LexState *ls, ExpDesc *v)\n{\n  BCOp op;\n  if (ls->tok == TK_not) {\n    op = BC_NOT;\n  } else if (ls->tok == '-') {\n    op = BC_UNM;\n  } else if (ls->tok == '#') {\n    op = BC_LEN;\n  } else {\n    expr_simple(ls, v);\n    return;\n  }\n  lj_lex_next(ls);\n  expr_binop(ls, v, UNARY_PRIORITY);\n  bcemit_unop(ls->fs, op, v);\n}\n\n/* Parse binary expressions with priority higher than the limit. */\nstatic BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit)\n{\n  BinOpr op;\n  synlevel_begin(ls);\n  expr_unop(ls, v);\n  op = token2binop(ls->tok);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    ExpDesc v2;\n    BinOpr nextop;\n    lj_lex_next(ls);\n    bcemit_binop_left(ls->fs, op, v);\n    /* Parse binary expression with higher priority. */\n    nextop = expr_binop(ls, &v2, priority[op].right);\n    bcemit_binop(ls->fs, op, v, &v2);\n    op = nextop;\n  }\n  synlevel_end(ls);\n  return op;  /* Return unconsumed binary operator (if any). */\n}\n\n/* Parse expression. */\nstatic void expr(LexState *ls, ExpDesc *v)\n{\n  expr_binop(ls, v, 0);  /* Priority 0: parse whole expression. */\n}\n\n/* Assign expression to the next register. */\nstatic void expr_next(LexState *ls)\n{\n  ExpDesc e;\n  expr(ls, &e);\n  expr_tonextreg(ls->fs, &e);\n}\n\n/* Parse conditional expression. */\nstatic BCPos expr_cond(LexState *ls)\n{\n  ExpDesc v;\n  expr(ls, &v);\n  if (v.k == VKNIL) v.k = VKFALSE;\n  bcemit_branch_t(ls->fs, &v);\n  return v.f;\n}\n\n/* -- Assignments --------------------------------------------------------- */\n\n/* List of LHS variables. */\ntypedef struct LHSVarList {\n  ExpDesc v;\t\t\t/* LHS variable. */\n  struct LHSVarList *prev;\t/* Link to previous LHS variable. */\n} LHSVarList;\n\n/* Eliminate write-after-read hazards for local variable assignment. */\nstatic void assign_hazard(LexState *ls, LHSVarList *lh, const ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  BCReg reg = v->u.s.info;  /* Check against this variable. */\n  BCReg tmp = fs->freereg;  /* Rename to this temp. register (if needed). */\n  int hazard = 0;\n  for (; lh; lh = lh->prev) {\n    if (lh->v.k == VINDEXED) {\n      if (lh->v.u.s.info == reg) {  /* t[i], t = 1, 2 */\n\thazard = 1;\n\tlh->v.u.s.info = tmp;\n      }\n      if (lh->v.u.s.aux == reg) {  /* t[i], i = 1, 2 */\n\thazard = 1;\n\tlh->v.u.s.aux = tmp;\n      }\n    }\n  }\n  if (hazard) {\n    bcemit_AD(fs, BC_MOV, tmp, reg);  /* Rename conflicting variable. */\n    bcreg_reserve(fs, 1);\n  }\n}\n\n/* Adjust LHS/RHS of an assignment. */\nstatic void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  int32_t extra = (int32_t)nvars - (int32_t)nexps;\n  if (e->k == VCALL) {\n    extra++;  /* Compensate for the VCALL itself. */\n    if (extra < 0) extra = 0;\n    setbc_b(bcptr(fs, e), extra+1);  /* Fixup call results. */\n    if (extra > 1) bcreg_reserve(fs, (BCReg)extra-1);\n  } else {\n    if (e->k != VVOID)\n      expr_tonextreg(fs, e);  /* Close last expression. */\n    if (extra > 0) {  /* Leftover LHS are set to nil. */\n      BCReg reg = fs->freereg;\n      bcreg_reserve(fs, (BCReg)extra);\n      bcemit_nil(fs, reg, (BCReg)extra);\n    }\n  }\n}\n\n/* Recursively parse assignment statement. */\nstatic void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars)\n{\n  ExpDesc e;\n  checkcond(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, LJ_ERR_XSYNTAX);\n  if (lex_opt(ls, ',')) {  /* Collect LHS list and recurse upwards. */\n    LHSVarList vl;\n    vl.prev = lh;\n    expr_primary(ls, &vl.v);\n    if (vl.v.k == VLOCAL)\n      assign_hazard(ls, lh, &vl.v);\n    checklimit(ls->fs, ls->level + nvars, LJ_MAX_XLEVEL, \"variable names\");\n    parse_assignment(ls, &vl, nvars+1);\n  } else {  /* Parse RHS. */\n    BCReg nexps;\n    lex_check(ls, '=');\n    nexps = expr_list(ls, &e);\n    if (nexps == nvars) {\n      if (e.k == VCALL) {\n\tif (bc_op(*bcptr(ls->fs, &e)) == BC_VARG) {  /* Vararg assignment. */\n\t  ls->fs->freereg--;\n\t  e.k = VRELOCABLE;\n\t} else {  /* Multiple call results. */\n\t  e.u.s.info = e.u.s.aux;  /* Base of call is not relocatable. */\n\t  e.k = VNONRELOC;\n\t}\n      }\n      bcemit_store(ls->fs, &lh->v, &e);\n      return;\n    }\n    assign_adjust(ls, nvars, nexps, &e);\n    if (nexps > nvars)\n      ls->fs->freereg -= nexps - nvars;  /* Drop leftover regs. */\n  }\n  /* Assign RHS to LHS and recurse downwards. */\n  expr_init(&e, VNONRELOC, ls->fs->freereg-1);\n  bcemit_store(ls->fs, &lh->v, &e);\n}\n\n/* Parse call statement or assignment. */\nstatic void parse_call_assign(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  LHSVarList vl;\n  expr_primary(ls, &vl.v);\n  if (vl.v.k == VCALL) {  /* Function call statement. */\n    setbc_b(bcptr(fs, &vl.v), 1);  /* No results. */\n  } else {  /* Start of an assignment. */\n    vl.prev = NULL;\n    parse_assignment(ls, &vl, 1);\n  }\n}\n\n/* Parse 'local' statement. */\nstatic void parse_local(LexState *ls)\n{\n  if (lex_opt(ls, TK_function)) {  /* Local function declaration. */\n    ExpDesc v, b;\n    FuncState *fs = ls->fs;\n    var_new(ls, 0, lex_str(ls));\n    expr_init(&v, VLOCAL, fs->freereg);\n    v.u.s.aux = fs->varmap[fs->freereg];\n    bcreg_reserve(fs, 1);\n    var_add(ls, 1);\n    parse_body(ls, &b, 0, ls->linenumber);\n    /* bcemit_store(fs, &v, &b) without setting VSTACK_VAR_RW. */\n    expr_free(fs, &b);\n    expr_toreg(fs, &b, v.u.s.info);\n    /* The upvalue is in scope, but the local is only valid after the store. */\n    var_get(ls, fs, fs->nactvar - 1).startpc = fs->pc;\n  } else {  /* Local variable declaration. */\n    ExpDesc e;\n    BCReg nexps, nvars = 0;\n    do {  /* Collect LHS. */\n      var_new(ls, nvars++, lex_str(ls));\n    } while (lex_opt(ls, ','));\n    if (lex_opt(ls, '=')) {  /* Optional RHS. */\n      nexps = expr_list(ls, &e);\n    } else {  /* Or implicitly set to nil. */\n      e.k = VVOID;\n      nexps = 0;\n    }\n    assign_adjust(ls, nvars, nexps, &e);\n    var_add(ls, nvars);\n  }\n}\n\n/* Parse 'function' statement. */\nstatic void parse_func(LexState *ls, BCLine line)\n{\n  FuncState *fs;\n  ExpDesc v, b;\n  int needself = 0;\n  lj_lex_next(ls);  /* Skip 'function'. */\n  /* Parse function name. */\n  var_lookup(ls, &v);\n  while (ls->tok == '.')  /* Multiple dot-separated fields. */\n    expr_field(ls, &v);\n  if (ls->tok == ':') {  /* Optional colon to signify method call. */\n    needself = 1;\n    expr_field(ls, &v);\n  }\n  parse_body(ls, &b, needself, line);\n  fs = ls->fs;\n  bcemit_store(fs, &v, &b);\n  fs->bcbase[fs->pc - 1].line = line;  /* Set line for the store. */\n}\n\n/* -- Control transfer statements ----------------------------------------- */\n\n/* Check for end of block. */\nstatic int parse_isend(LexToken tok)\n{\n  switch (tok) {\n  case TK_else: case TK_elseif: case TK_end: case TK_until: case TK_eof:\n    return 1;\n  default:\n    return 0;\n  }\n}\n\n/* Parse 'return' statement. */\nstatic void parse_return(LexState *ls)\n{\n  BCIns ins;\n  FuncState *fs = ls->fs;\n  lj_lex_next(ls);  /* Skip 'return'. */\n  fs->flags |= PROTO_HAS_RETURN;\n  if (parse_isend(ls->tok) || ls->tok == ';') {  /* Bare return. */\n    ins = BCINS_AD(BC_RET0, 0, 1);\n  } else {  /* Return with one or more values. */\n    ExpDesc e;  /* Receives the _last_ expression in the list. */\n    BCReg nret = expr_list(ls, &e);\n    if (nret == 1) {  /* Return one result. */\n      if (e.k == VCALL) {  /* Check for tail call. */\n\tBCIns *ip = bcptr(fs, &e);\n\t/* It doesn't pay off to add BC_VARGT just for 'return ...'. */\n\tif (bc_op(*ip) == BC_VARG) goto notailcall;\n\tfs->pc--;\n\tins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip));\n      } else {  /* Can return the result from any register. */\n\tins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2);\n      }\n    } else {\n      if (e.k == VCALL) {  /* Append all results from a call. */\n      notailcall:\n\tsetbc_b(bcptr(fs, &e), 0);\n\tins = BCINS_AD(BC_RETM, fs->nactvar, e.u.s.aux - fs->nactvar);\n      } else {\n\texpr_tonextreg(fs, &e);  /* Force contiguous registers. */\n\tins = BCINS_AD(BC_RET, fs->nactvar, nret+1);\n      }\n    }\n  }\n  if (fs->flags & PROTO_CHILD)\n    bcemit_AJ(fs, BC_UCLO, 0, 0);  /* May need to close upvalues first. */\n  bcemit_INS(fs, ins);\n}\n\n/* Parse 'break' statement. */\nstatic void parse_break(LexState *ls)\n{\n  ls->fs->bl->flags |= FSCOPE_BREAK;\n  gola_new(ls, NAME_BREAK, VSTACK_GOTO, bcemit_jmp(ls->fs));\n}\n\n/* Parse 'goto' statement. */\nstatic void parse_goto(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  GCstr *name = lex_str(ls);\n  VarInfo *vl = gola_findlabel(ls, name);\n  if (vl)  /* Treat backwards goto within same scope like a loop. */\n    bcemit_AJ(fs, BC_LOOP, vl->slot, -1);  /* No BC range check. */\n  fs->bl->flags |= FSCOPE_GOLA;\n  gola_new(ls, name, VSTACK_GOTO, bcemit_jmp(fs));\n}\n\n/* Parse label. */\nstatic void parse_label(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  GCstr *name;\n  MSize idx;\n  fs->lasttarget = fs->pc;\n  fs->bl->flags |= FSCOPE_GOLA;\n  lj_lex_next(ls);  /* Skip '::'. */\n  name = lex_str(ls);\n  if (gola_findlabel(ls, name))\n    lj_lex_error(ls, 0, LJ_ERR_XLDUP, strdata(name));\n  idx = gola_new(ls, name, VSTACK_LABEL, fs->pc);\n  lex_check(ls, TK_label);\n  /* Recursively parse trailing statements: labels and ';' (Lua 5.2 only). */\n  for (;;) {\n    if (ls->tok == TK_label) {\n      synlevel_begin(ls);\n      parse_label(ls);\n      synlevel_end(ls);\n    } else if (LJ_52 && ls->tok == ';') {\n      lj_lex_next(ls);\n    } else {\n      break;\n    }\n  }\n  /* Trailing label is considered to be outside of scope. */\n  if (parse_isend(ls->tok) && ls->tok != TK_until)\n    ls->vstack[idx].slot = fs->bl->nactvar;\n  gola_resolve(ls, fs->bl, idx);\n}\n\n/* -- Blocks, loops and conditional statements ---------------------------- */\n\n/* Parse a block. */\nstatic void parse_block(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  FuncScope bl;\n  fscope_begin(fs, &bl, 0);\n  parse_chunk(ls);\n  fscope_end(fs);\n}\n\n/* Parse 'while' statement. */\nstatic void parse_while(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos start, loop, condexit;\n  FuncScope bl;\n  lj_lex_next(ls);  /* Skip 'while'. */\n  start = fs->lasttarget = fs->pc;\n  condexit = expr_cond(ls);\n  fscope_begin(fs, &bl, FSCOPE_LOOP);\n  lex_check(ls, TK_do);\n  loop = bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);\n  parse_block(ls);\n  jmp_patch(fs, bcemit_jmp(fs), start);\n  lex_match(ls, TK_end, TK_while, line);\n  fscope_end(fs);\n  jmp_tohere(fs, condexit);\n  jmp_patchins(fs, loop, fs->pc);\n}\n\n/* Parse 'repeat' statement. */\nstatic void parse_repeat(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos loop = fs->lasttarget = fs->pc;\n  BCPos condexit;\n  FuncScope bl1, bl2;\n  fscope_begin(fs, &bl1, FSCOPE_LOOP);  /* Breakable loop scope. */\n  fscope_begin(fs, &bl2, 0);  /* Inner scope. */\n  lj_lex_next(ls);  /* Skip 'repeat'. */\n  bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);\n  parse_chunk(ls);\n  lex_match(ls, TK_until, TK_repeat, line);\n  condexit = expr_cond(ls);  /* Parse condition (still inside inner scope). */\n  if (!(bl2.flags & FSCOPE_UPVAL)) {  /* No upvalues? Just end inner scope. */\n    fscope_end(fs);\n  } else {  /* Otherwise generate: cond: UCLO+JMP out, !cond: UCLO+JMP loop. */\n    parse_break(ls);  /* Break from loop and close upvalues. */\n    jmp_tohere(fs, condexit);\n    fscope_end(fs);  /* End inner scope and close upvalues. */\n    condexit = bcemit_jmp(fs);\n  }\n  jmp_patch(fs, condexit, loop);  /* Jump backwards if !cond. */\n  jmp_patchins(fs, loop, fs->pc);\n  fscope_end(fs);  /* End loop scope. */\n}\n\n/* Parse numeric 'for'. */\nstatic void parse_for_num(LexState *ls, GCstr *varname, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCReg base = fs->freereg;\n  FuncScope bl;\n  BCPos loop, loopend;\n  /* Hidden control variables. */\n  var_new_fixed(ls, FORL_IDX, VARNAME_FOR_IDX);\n  var_new_fixed(ls, FORL_STOP, VARNAME_FOR_STOP);\n  var_new_fixed(ls, FORL_STEP, VARNAME_FOR_STEP);\n  /* Visible copy of index variable. */\n  var_new(ls, FORL_EXT, varname);\n  lex_check(ls, '=');\n  expr_next(ls);\n  lex_check(ls, ',');\n  expr_next(ls);\n  if (lex_opt(ls, ',')) {\n    expr_next(ls);\n  } else {\n    bcemit_AD(fs, BC_KSHORT, fs->freereg, 1);  /* Default step is 1. */\n    bcreg_reserve(fs, 1);\n  }\n  var_add(ls, 3);  /* Hidden control variables. */\n  lex_check(ls, TK_do);\n  loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP);\n  fscope_begin(fs, &bl, 0);  /* Scope for visible variables. */\n  var_add(ls, 1);\n  bcreg_reserve(fs, 1);\n  parse_block(ls);\n  fscope_end(fs);\n  /* Perform loop inversion. Loop control instructions are at the end. */\n  loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP);\n  fs->bcbase[loopend].line = line;  /* Fix line for control ins. */\n  jmp_patchins(fs, loopend, loop+1);\n  jmp_patchins(fs, loop, fs->pc);\n}\n\n/* Try to predict whether the iterator is next() and specialize the bytecode.\n** Detecting next() and pairs() by name is simplistic, but quite effective.\n** The interpreter backs off if the check for the closure fails at runtime.\n*/\nstatic int predict_next(LexState *ls, FuncState *fs, BCPos pc)\n{\n  BCIns ins = fs->bcbase[pc].ins;\n  GCstr *name;\n  cTValue *o;\n  switch (bc_op(ins)) {\n  case BC_MOV:\n    name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name));\n    break;\n  case BC_UGET:\n    name = gco2str(gcref(ls->vstack[fs->uvmap[bc_d(ins)]].name));\n    break;\n  case BC_GGET:\n    /* There's no inverse index (yet), so lookup the strings. */\n    o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, \"pairs\"));\n    if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))\n      return 1;\n    o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, \"next\"));\n    if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))\n      return 1;\n    return 0;\n  default:\n    return 0;\n  }\n  return (name->len == 5 && !strcmp(strdata(name), \"pairs\")) ||\n\t (name->len == 4 && !strcmp(strdata(name), \"next\"));\n}\n\n/* Parse 'for' iterator. */\nstatic void parse_for_iter(LexState *ls, GCstr *indexname)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc e;\n  BCReg nvars = 0;\n  BCLine line;\n  BCReg base = fs->freereg + 3;\n  BCPos loop, loopend, exprpc = fs->pc;\n  FuncScope bl;\n  int isnext;\n  /* Hidden control variables. */\n  var_new_fixed(ls, nvars++, VARNAME_FOR_GEN);\n  var_new_fixed(ls, nvars++, VARNAME_FOR_STATE);\n  var_new_fixed(ls, nvars++, VARNAME_FOR_CTL);\n  /* Visible variables returned from iterator. */\n  var_new(ls, nvars++, indexname);\n  while (lex_opt(ls, ','))\n    var_new(ls, nvars++, lex_str(ls));\n  lex_check(ls, TK_in);\n  line = ls->linenumber;\n  assign_adjust(ls, 3, expr_list(ls, &e), &e);\n  /* The iterator needs another 3 [4] slots (func [pc] | state ctl). */\n  bcreg_bump(fs, 3+LJ_FR2);\n  isnext = (nvars <= 5 && predict_next(ls, fs, exprpc));\n  var_add(ls, 3);  /* Hidden control variables. */\n  lex_check(ls, TK_do);\n  loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP);\n  fscope_begin(fs, &bl, 0);  /* Scope for visible variables. */\n  var_add(ls, nvars-3);\n  bcreg_reserve(fs, nvars-3);\n  parse_block(ls);\n  fscope_end(fs);\n  /* Perform loop inversion. Loop control instructions are at the end. */\n  jmp_patchins(fs, loop, fs->pc);\n  bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1);\n  loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP);\n  fs->bcbase[loopend-1].line = line;  /* Fix line for control ins. */\n  fs->bcbase[loopend].line = line;\n  jmp_patchins(fs, loopend, loop+1);\n}\n\n/* Parse 'for' statement. */\nstatic void parse_for(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  GCstr *varname;\n  FuncScope bl;\n  fscope_begin(fs, &bl, FSCOPE_LOOP);\n  lj_lex_next(ls);  /* Skip 'for'. */\n  varname = lex_str(ls);  /* Get first variable name. */\n  if (ls->tok == '=')\n    parse_for_num(ls, varname, line);\n  else if (ls->tok == ',' || ls->tok == TK_in)\n    parse_for_iter(ls, varname);\n  else\n    err_syntax(ls, LJ_ERR_XFOR);\n  lex_match(ls, TK_end, TK_for, line);\n  fscope_end(fs);  /* Resolve break list. */\n}\n\n/* Parse condition and 'then' block. */\nstatic BCPos parse_then(LexState *ls)\n{\n  BCPos condexit;\n  lj_lex_next(ls);  /* Skip 'if' or 'elseif'. */\n  condexit = expr_cond(ls);\n  lex_check(ls, TK_then);\n  parse_block(ls);\n  return condexit;\n}\n\n/* Parse 'if' statement. */\nstatic void parse_if(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos flist;\n  BCPos escapelist = NO_JMP;\n  flist = parse_then(ls);\n  while (ls->tok == TK_elseif) {  /* Parse multiple 'elseif' blocks. */\n    jmp_append(fs, &escapelist, bcemit_jmp(fs));\n    jmp_tohere(fs, flist);\n    flist = parse_then(ls);\n  }\n  if (ls->tok == TK_else) {  /* Parse optional 'else' block. */\n    jmp_append(fs, &escapelist, bcemit_jmp(fs));\n    jmp_tohere(fs, flist);\n    lj_lex_next(ls);  /* Skip 'else'. */\n    parse_block(ls);\n  } else {\n    jmp_append(fs, &escapelist, flist);\n  }\n  jmp_tohere(fs, escapelist);\n  lex_match(ls, TK_end, TK_if, line);\n}\n\n/* -- Parse statements ---------------------------------------------------- */\n\n/* Parse a statement. Returns 1 if it must be the last one in a chunk. */\nstatic int parse_stmt(LexState *ls)\n{\n  BCLine line = ls->linenumber;\n  switch (ls->tok) {\n  case TK_if:\n    parse_if(ls, line);\n    break;\n  case TK_while:\n    parse_while(ls, line);\n    break;\n  case TK_do:\n    lj_lex_next(ls);\n    parse_block(ls);\n    lex_match(ls, TK_end, TK_do, line);\n    break;\n  case TK_for:\n    parse_for(ls, line);\n    break;\n  case TK_repeat:\n    parse_repeat(ls, line);\n    break;\n  case TK_function:\n    parse_func(ls, line);\n    break;\n  case TK_local:\n    lj_lex_next(ls);\n    parse_local(ls);\n    break;\n  case TK_return:\n    parse_return(ls);\n    return 1;  /* Must be last. */\n  case TK_break:\n    lj_lex_next(ls);\n    parse_break(ls);\n    return !LJ_52;  /* Must be last in Lua 5.1. */\n#if LJ_52\n  case ';':\n    lj_lex_next(ls);\n    break;\n#endif\n  case TK_label:\n    parse_label(ls);\n    break;\n  case TK_goto:\n    if (LJ_52 || lj_lex_lookahead(ls) == TK_name) {\n      lj_lex_next(ls);\n      parse_goto(ls);\n      break;\n    }  /* else: fallthrough */\n  default:\n    parse_call_assign(ls);\n    break;\n  }\n  return 0;\n}\n\n/* A chunk is a list of statements optionally separated by semicolons. */\nstatic void parse_chunk(LexState *ls)\n{\n  int islast = 0;\n  synlevel_begin(ls);\n  while (!islast && !parse_isend(ls->tok)) {\n    islast = parse_stmt(ls);\n    lex_opt(ls, ';');\n    lua_assert(ls->fs->framesize >= ls->fs->freereg &&\n\t       ls->fs->freereg >= ls->fs->nactvar);\n    ls->fs->freereg = ls->fs->nactvar;  /* Free registers after each stmt. */\n  }\n  synlevel_end(ls);\n}\n\n/* Entry point of bytecode parser. */\nGCproto *lj_parse(LexState *ls)\n{\n  FuncState fs;\n  FuncScope bl;\n  GCproto *pt;\n  lua_State *L = ls->L;\n#ifdef LUAJIT_DISABLE_DEBUGINFO\n  ls->chunkname = lj_str_newlit(L, \"=\");\n#else\n  ls->chunkname = lj_str_newz(L, ls->chunkarg);\n#endif\n  setstrV(L, L->top, ls->chunkname);  /* Anchor chunkname string. */\n  incr_top(L);\n  ls->level = 0;\n  fs_init(ls, &fs);\n  fs.linedefined = 0;\n  fs.numparams = 0;\n  fs.bcbase = NULL;\n  fs.bclim = 0;\n  fs.flags |= PROTO_VARARG;  /* Main chunk is always a vararg func. */\n  fscope_begin(&fs, &bl, 0);\n  bcemit_AD(&fs, BC_FUNCV, 0, 0);  /* Placeholder. */\n  lj_lex_next(ls);  /* Read-ahead first token. */\n  parse_chunk(ls);\n  if (ls->tok != TK_eof)\n    err_token(ls, TK_eof);\n  pt = fs_finish(ls, ls->linenumber);\n  L->top--;  /* Drop chunkname. */\n  lua_assert(fs.prev == NULL);\n  lua_assert(ls->fs == NULL);\n  lua_assert(pt->sizeuv == 0);\n  return pt;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_parse.h",
    "content": "/*\n** Lua parser (source code -> bytecode).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_PARSE_H\n#define _LJ_PARSE_H\n\n#include \"lj_obj.h\"\n#include \"lj_lex.h\"\n\nLJ_FUNC GCproto *lj_parse(LexState *ls);\nLJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l);\n#if LJ_HASFFI\nLJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_profile.c",
    "content": "/*\n** Low-overhead profiling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_profile_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASPROFILE\n\n#include \"lj_buf.h\"\n#include \"lj_frame.h\"\n#include \"lj_debug.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#include \"lj_trace.h\"\n#endif\n#include \"lj_profile.h\"\n\n#include \"luajit.h\"\n\n#if LJ_PROFILE_SIGPROF\n\n#include <sys/time.h>\n#include <signal.h>\n#define profile_lock(ps)\tUNUSED(ps)\n#define profile_unlock(ps)\tUNUSED(ps)\n\n#elif LJ_PROFILE_PTHREAD\n\n#include <pthread.h>\n#include <time.h>\n#if LJ_TARGET_PS3\n#include <sys/timer.h>\n#endif\n#define profile_lock(ps)\tpthread_mutex_lock(&ps->lock)\n#define profile_unlock(ps)\tpthread_mutex_unlock(&ps->lock)\n\n#elif LJ_PROFILE_WTHREAD\n\n#define WIN32_LEAN_AND_MEAN\n#if LJ_TARGET_XBOX360\n#include <xtl.h>\n#include <xbox.h>\n#else\n#include <windows.h>\n#endif\ntypedef unsigned int (WINAPI *WMM_TPFUNC)(unsigned int);\n#define profile_lock(ps)\tEnterCriticalSection(&ps->lock)\n#define profile_unlock(ps)\tLeaveCriticalSection(&ps->lock)\n\n#endif\n\n/* Profiler state. */\ntypedef struct ProfileState {\n  global_State *g;\t\t/* VM state that started the profiler. */\n  luaJIT_profile_callback cb;\t/* Profiler callback. */\n  void *data;\t\t\t/* Profiler callback data. */\n  SBuf sb;\t\t\t/* String buffer for stack dumps. */\n  int interval;\t\t\t/* Sample interval in milliseconds. */\n  int samples;\t\t\t/* Number of samples for next callback. */\n  int vmstate;\t\t\t/* VM state when profile timer triggered. */\n#if LJ_PROFILE_SIGPROF\n  struct sigaction oldsa;\t/* Previous SIGPROF state. */\n#elif LJ_PROFILE_PTHREAD\n  pthread_mutex_t lock;\t\t/* g->hookmask update lock. */\n  pthread_t thread;\t\t/* Timer thread. */\n  int abort;\t\t\t/* Abort timer thread. */\n#elif LJ_PROFILE_WTHREAD\n#if LJ_TARGET_WINDOWS\n  HINSTANCE wmm;\t\t/* WinMM library handle. */\n  WMM_TPFUNC wmm_tbp;\t\t/* WinMM timeBeginPeriod function. */\n  WMM_TPFUNC wmm_tep;\t\t/* WinMM timeEndPeriod function. */\n#endif\n  CRITICAL_SECTION lock;\t/* g->hookmask update lock. */\n  HANDLE thread;\t\t/* Timer thread. */\n  int abort;\t\t\t/* Abort timer thread. */\n#endif\n} ProfileState;\n\n/* Sadly, we have to use a static profiler state.\n**\n** The SIGPROF variant needs a static pointer to the global state, anyway.\n** And it would be hard to extend for multiple threads. You can still use\n** multiple VMs in multiple threads, but only profile one at a time.\n*/\nstatic ProfileState profile_state;\n\n/* Default sample interval in milliseconds. */\n#define LJ_PROFILE_INTERVAL_DEFAULT\t10\n\n/* -- Profiler/hook interaction ------------------------------------------- */\n\n#if !LJ_PROFILE_SIGPROF\nvoid LJ_FASTCALL lj_profile_hook_enter(global_State *g)\n{\n  ProfileState *ps = &profile_state;\n  if (ps->g) {\n    profile_lock(ps);\n    hook_enter(g);\n    profile_unlock(ps);\n  } else {\n    hook_enter(g);\n  }\n}\n\nvoid LJ_FASTCALL lj_profile_hook_leave(global_State *g)\n{\n  ProfileState *ps = &profile_state;\n  if (ps->g) {\n    profile_lock(ps);\n    hook_leave(g);\n    profile_unlock(ps);\n  } else {\n    hook_leave(g);\n  }\n}\n#endif\n\n/* -- Profile callbacks --------------------------------------------------- */\n\n/* Callback from profile hook (HOOK_PROFILE already cleared). */\nvoid LJ_FASTCALL lj_profile_interpreter(lua_State *L)\n{\n  ProfileState *ps = &profile_state;\n  global_State *g = G(L);\n  uint8_t mask;\n  profile_lock(ps);\n  mask = (g->hookmask & ~HOOK_PROFILE);\n  if (!(mask & HOOK_VMEVENT)) {\n    int samples = ps->samples;\n    ps->samples = 0;\n    g->hookmask = HOOK_VMEVENT;\n    lj_dispatch_update(g);\n    profile_unlock(ps);\n    ps->cb(ps->data, L, samples, ps->vmstate);  /* Invoke user callback. */\n    profile_lock(ps);\n    mask |= (g->hookmask & HOOK_PROFILE);\n  }\n  g->hookmask = mask;\n  lj_dispatch_update(g);\n  profile_unlock(ps);\n}\n\n/* Trigger profile hook. Asynchronous call from OS-specific profile timer. */\nstatic void profile_trigger(ProfileState *ps)\n{\n  global_State *g = ps->g;\n  uint8_t mask;\n  profile_lock(ps);\n  ps->samples++;  /* Always increment number of samples. */\n  mask = g->hookmask;\n  if (!(mask & (HOOK_PROFILE|HOOK_VMEVENT))) {  /* Set profile hook. */\n    int st = g->vmstate;\n    ps->vmstate = st >= 0 ? 'N' :\n\t\t  st == ~LJ_VMST_INTERP ? 'I' :\n\t\t  st == ~LJ_VMST_C ? 'C' :\n\t\t  st == ~LJ_VMST_GC ? 'G' : 'J';\n    g->hookmask = (mask | HOOK_PROFILE);\n    lj_dispatch_update(g);\n  }\n  profile_unlock(ps);\n}\n\n/* -- OS-specific profile timer handling ---------------------------------- */\n\n#if LJ_PROFILE_SIGPROF\n\n/* SIGPROF handler. */\nstatic void profile_signal(int sig)\n{\n  UNUSED(sig);\n  profile_trigger(&profile_state);\n}\n\n/* Start profiling timer. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n  int interval = ps->interval;\n  struct itimerval tm;\n  struct sigaction sa;\n  tm.it_value.tv_sec = tm.it_interval.tv_sec = interval / 1000;\n  tm.it_value.tv_usec = tm.it_interval.tv_usec = (interval % 1000) * 1000;\n  setitimer(ITIMER_PROF, &tm, NULL);\n  sa.sa_flags = SA_RESTART;\n  sa.sa_handler = profile_signal;\n  sigemptyset(&sa.sa_mask);\n  sigaction(SIGPROF, &sa, &ps->oldsa);\n}\n\n/* Stop profiling timer. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  struct itimerval tm;\n  tm.it_value.tv_sec = tm.it_interval.tv_sec = 0;\n  tm.it_value.tv_usec = tm.it_interval.tv_usec = 0;\n  setitimer(ITIMER_PROF, &tm, NULL);\n  sigaction(SIGPROF, &ps->oldsa, NULL);\n}\n\n#elif LJ_PROFILE_PTHREAD\n\n/* POSIX timer thread. */\nstatic void *profile_thread(ProfileState *ps)\n{\n  int interval = ps->interval;\n#if !LJ_TARGET_PS3\n  struct timespec ts;\n  ts.tv_sec = interval / 1000;\n  ts.tv_nsec = (interval % 1000) * 1000000;\n#endif\n  while (1) {\n#if LJ_TARGET_PS3\n    sys_timer_usleep(interval * 1000);\n#else\n    nanosleep(&ts, NULL);\n#endif\n    if (ps->abort) break;\n    profile_trigger(ps);\n  }\n  return NULL;\n}\n\n/* Start profiling timer thread. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n  pthread_mutex_init(&ps->lock, 0);\n  ps->abort = 0;\n  pthread_create(&ps->thread, NULL, (void *(*)(void *))profile_thread, ps);\n}\n\n/* Stop profiling timer thread. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  ps->abort = 1;\n  pthread_join(ps->thread, NULL);\n  pthread_mutex_destroy(&ps->lock);\n}\n\n#elif LJ_PROFILE_WTHREAD\n\n/* Windows timer thread. */\nstatic DWORD WINAPI profile_thread(void *psx)\n{\n  ProfileState *ps = (ProfileState *)psx;\n  int interval = ps->interval;\n#if LJ_TARGET_WINDOWS\n  ps->wmm_tbp(interval);\n#endif\n  while (1) {\n    Sleep(interval);\n    if (ps->abort) break;\n    profile_trigger(ps);\n  }\n#if LJ_TARGET_WINDOWS\n  ps->wmm_tep(interval);\n#endif\n  return 0;\n}\n\n/* Start profiling timer thread. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n#if LJ_TARGET_WINDOWS\n  if (!ps->wmm) {  /* Load WinMM library on-demand. */\n    ps->wmm = LoadLibraryExA(\"winmm.dll\", NULL, 0);\n    if (ps->wmm) {\n      ps->wmm_tbp = (WMM_TPFUNC)GetProcAddress(ps->wmm, \"timeBeginPeriod\");\n      ps->wmm_tep = (WMM_TPFUNC)GetProcAddress(ps->wmm, \"timeEndPeriod\");\n      if (!ps->wmm_tbp || !ps->wmm_tep) {\n\tps->wmm = NULL;\n\treturn;\n      }\n    }\n  }\n#endif\n  InitializeCriticalSection(&ps->lock);\n  ps->abort = 0;\n  ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL);\n}\n\n/* Stop profiling timer thread. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  ps->abort = 1;\n  WaitForSingleObject(ps->thread, INFINITE);\n  DeleteCriticalSection(&ps->lock);\n}\n\n#endif\n\n/* -- Public profiling API ------------------------------------------------ */\n\n/* Start profiling. */\nLUA_API void luaJIT_profile_start(lua_State *L, const char *mode,\n\t\t\t\t  luaJIT_profile_callback cb, void *data)\n{\n  ProfileState *ps = &profile_state;\n  int interval = LJ_PROFILE_INTERVAL_DEFAULT;\n  while (*mode) {\n    int m = *mode++;\n    switch (m) {\n    case 'i':\n      interval = 0;\n      while (*mode >= '0' && *mode <= '9')\n\tinterval = interval * 10 + (*mode++ - '0');\n      if (interval <= 0) interval = 1;\n      break;\n#if LJ_HASJIT\n    case 'l': case 'f':\n      L2J(L)->prof_mode = m;\n      lj_trace_flushall(L);\n      break;\n#endif\n    default:  /* Ignore unknown mode chars. */\n      break;\n    }\n  }\n  if (ps->g) {\n    luaJIT_profile_stop(L);\n    if (ps->g) return;  /* Profiler in use by another VM. */\n  }\n  ps->g = G(L);\n  ps->interval = interval;\n  ps->cb = cb;\n  ps->data = data;\n  ps->samples = 0;\n  lj_buf_init(L, &ps->sb);\n  profile_timer_start(ps);\n}\n\n/* Stop profiling. */\nLUA_API void luaJIT_profile_stop(lua_State *L)\n{\n  ProfileState *ps = &profile_state;\n  global_State *g = ps->g;\n  if (G(L) == g) {  /* Only stop profiler if started by this VM. */\n    profile_timer_stop(ps);\n    g->hookmask &= ~HOOK_PROFILE;\n    lj_dispatch_update(g);\n#if LJ_HASJIT\n    G2J(g)->prof_mode = 0;\n    lj_trace_flushall(L);\n#endif\n    lj_buf_free(g, &ps->sb);\n    setmref(ps->sb.b, NULL);\n    setmref(ps->sb.e, NULL);\n    ps->g = NULL;\n  }\n}\n\n/* Return a compact stack dump. */\nLUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt,\n\t\t\t\t\t     int depth, size_t *len)\n{\n  ProfileState *ps = &profile_state;\n  SBuf *sb = &ps->sb;\n  setsbufL(sb, L);\n  lj_buf_reset(sb);\n  lj_debug_dumpstack(L, sb, fmt, depth);\n  *len = (size_t)sbuflen(sb);\n  return sbufB(sb);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_profile.h",
    "content": "/*\n** Low-overhead profiling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_PROFILE_H\n#define _LJ_PROFILE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASPROFILE\n\nLJ_FUNC void LJ_FASTCALL lj_profile_interpreter(lua_State *L);\n#if !LJ_PROFILE_SIGPROF\nLJ_FUNC void LJ_FASTCALL lj_profile_hook_enter(global_State *g);\nLJ_FUNC void LJ_FASTCALL lj_profile_hook_leave(global_State *g);\n#endif\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_record.c",
    "content": "/*\n** Trace recorder (bytecode -> SSA IR).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_record_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#if LJ_HASPROFILE\n#include \"lj_debug.h\"\n#endif\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_snap.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Sanity checks ------------------------------------------------------- */\n\n#ifdef LUA_USE_ASSERT\n/* Sanity check the whole IR -- sloooow. */\nstatic void rec_check_ir(jit_State *J)\n{\n  IRRef i, nins = J->cur.nins, nk = J->cur.nk;\n  lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536);\n  for (i = nins-1; i >= nk; i--) {\n    IRIns *ir = IR(i);\n    uint32_t mode = lj_ir_mode[ir->o];\n    IRRef op1 = ir->op1;\n    IRRef op2 = ir->op2;\n    switch (irm_op1(mode)) {\n    case IRMnone: lua_assert(op1 == 0); break;\n    case IRMref: lua_assert(op1 >= nk);\n      lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break;\n    case IRMlit: break;\n    case IRMcst: lua_assert(i < REF_BIAS); continue;\n    }\n    switch (irm_op2(mode)) {\n    case IRMnone: lua_assert(op2 == 0); break;\n    case IRMref: lua_assert(op2 >= nk);\n      lua_assert(i >= REF_BIAS ? op2 < i : op2 > i); break;\n    case IRMlit: break;\n    case IRMcst: lua_assert(0); break;\n    }\n    if (ir->prev) {\n      lua_assert(ir->prev >= nk);\n      lua_assert(i >= REF_BIAS ? ir->prev < i : ir->prev > i);\n      lua_assert(ir->o == IR_NOP || IR(ir->prev)->o == ir->o);\n    }\n  }\n}\n\n/* Compare stack slots and frames of the recorder and the VM. */\nstatic void rec_check_slots(jit_State *J)\n{\n  BCReg s, nslots = J->baseslot + J->maxslot;\n  int32_t depth = 0;\n  cTValue *base = J->L->base - J->baseslot;\n  lua_assert(J->baseslot >= 1 && J->baseslot < LJ_MAX_JSLOTS);\n  lua_assert(J->baseslot == 1 || (J->slot[J->baseslot-1] & TREF_FRAME));\n  lua_assert(nslots < LJ_MAX_JSLOTS);\n  for (s = 0; s < nslots; s++) {\n    TRef tr = J->slot[s];\n    if (tr) {\n      cTValue *tv = &base[s];\n      IRRef ref = tref_ref(tr);\n      IRIns *ir;\n      lua_assert(ref >= J->cur.nk && ref < J->cur.nins);\n      ir = IR(ref);\n      lua_assert(irt_t(ir->t) == tref_t(tr));\n      if (s == 0) {\n\tlua_assert(tref_isfunc(tr));\n      } else if ((tr & TREF_FRAME)) {\n\tGCfunc *fn = gco2func(frame_gc(tv));\n\tBCReg delta = (BCReg)(tv - frame_prev(tv));\n\tlua_assert(tref_isfunc(tr));\n\tif (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir));\n\tlua_assert(s > delta ? (J->slot[s-delta] & TREF_FRAME) : (s == delta));\n\tdepth++;\n      } else if ((tr & TREF_CONT)) {\n\tlua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void));\n\tlua_assert((J->slot[s+1] & TREF_FRAME));\n\tdepth++;\n      } else {\n\tif (tvisnumber(tv))\n\t  lua_assert(tref_isnumber(tr));  /* Could be IRT_INT etc., too. */\n\telse\n\t  lua_assert(itype2irt(tv) == tref_type(tr));\n\tif (tref_isk(tr)) {  /* Compare constants. */\n\t  TValue tvk;\n\t  lj_ir_kvalue(J->L, &tvk, ir);\n\t  if (!(tvisnum(&tvk) && tvisnan(&tvk)))\n\t    lua_assert(lj_obj_equal(tv, &tvk));\n\t  else\n\t    lua_assert(tvisnum(tv) && tvisnan(tv));\n\t}\n      }\n    }\n  }\n  lua_assert(J->framedepth == depth);\n}\n#endif\n\n/* -- Type handling and specialization ------------------------------------ */\n\n/* Note: these functions return tagged references (TRef). */\n\n/* Specialize a slot to a specific type. Note: slot can be negative! */\nstatic TRef sloadt(jit_State *J, int32_t slot, IRType t, int mode)\n{\n  /* Caller may set IRT_GUARD in t. */\n  TRef ref = emitir_raw(IRT(IR_SLOAD, t), (int32_t)J->baseslot+slot, mode);\n  J->base[slot] = ref;\n  return ref;\n}\n\n/* Specialize a slot to the runtime type. Note: slot can be negative! */\nstatic TRef sload(jit_State *J, int32_t slot)\n{\n  IRType t = itype2irt(&J->L->base[slot]);\n  TRef ref = emitir_raw(IRTG(IR_SLOAD, t), (int32_t)J->baseslot+slot,\n\t\t\tIRSLOAD_TYPECHECK);\n  if (irtype_ispri(t)) ref = TREF_PRI(t);  /* Canonicalize primitive refs. */\n  J->base[slot] = ref;\n  return ref;\n}\n\n/* Get TRef from slot. Load slot and specialize if not done already. */\n#define getslot(J, s)\t(J->base[(s)] ? J->base[(s)] : sload(J, (int32_t)(s)))\n\n/* Get TRef for current function. */\nstatic TRef getcurrf(jit_State *J)\n{\n  if (J->base[-1])\n    return J->base[-1];\n  lua_assert(J->baseslot == 1);\n  return sloadt(J, -1, IRT_FUNC, IRSLOAD_READONLY);\n}\n\n/* Compare for raw object equality.\n** Returns 0 if the objects are the same.\n** Returns 1 if they are different, but the same type.\n** Returns 2 for two different types.\n** Comparisons between primitives always return 1 -- no caller cares about it.\n*/\nint lj_record_objcmp(jit_State *J, TRef a, TRef b, cTValue *av, cTValue *bv)\n{\n  int diff = !lj_obj_equal(av, bv);\n  if (!tref_isk2(a, b)) {  /* Shortcut, also handles primitives. */\n    IRType ta = tref_isinteger(a) ? IRT_INT : tref_type(a);\n    IRType tb = tref_isinteger(b) ? IRT_INT : tref_type(b);\n    if (ta != tb) {\n      /* Widen mixed number/int comparisons to number/number comparison. */\n      if (ta == IRT_INT && tb == IRT_NUM) {\n\ta = emitir(IRTN(IR_CONV), a, IRCONV_NUM_INT);\n\tta = IRT_NUM;\n      } else if (ta == IRT_NUM && tb == IRT_INT) {\n\tb = emitir(IRTN(IR_CONV), b, IRCONV_NUM_INT);\n      } else {\n\treturn 2;  /* Two different types are never equal. */\n      }\n    }\n    emitir(IRTG(diff ? IR_NE : IR_EQ, ta), a, b);\n  }\n  return diff;\n}\n\n/* Constify a value. Returns 0 for non-representable object types. */\nTRef lj_record_constify(jit_State *J, cTValue *o)\n{\n  if (tvisgcv(o))\n    return lj_ir_kgc(J, gcV(o), itype2irt(o));\n  else if (tvisint(o))\n    return lj_ir_kint(J, intV(o));\n  else if (tvisnum(o))\n    return lj_ir_knumint(J, numV(o));\n  else if (tvisbool(o))\n    return TREF_PRI(itype2irt(o));\n  else\n    return 0;  /* Can't represent lightuserdata (pointless). */\n}\n\n/* -- Record loop ops ----------------------------------------------------- */\n\n/* Loop event. */\ntypedef enum {\n  LOOPEV_LEAVE,\t\t/* Loop is left or not entered. */\n  LOOPEV_ENTERLO,\t/* Loop is entered with a low iteration count left. */\n  LOOPEV_ENTER\t\t/* Loop is entered. */\n} LoopEvent;\n\n/* Canonicalize slots: convert integers to numbers. */\nstatic void canonicalize_slots(jit_State *J)\n{\n  BCReg s;\n  if (LJ_DUALNUM) return;\n  for (s = J->baseslot+J->maxslot-1; s >= 1; s--) {\n    TRef tr = J->slot[s];\n    if (tref_isinteger(tr)) {\n      IRIns *ir = IR(tref_ref(tr));\n      if (!(ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_READONLY)))\n\tJ->slot[s] = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n    }\n  }\n}\n\n/* Stop recording. */\nvoid lj_record_stop(jit_State *J, TraceLink linktype, TraceNo lnk)\n{\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  if (J->retryrec)\n    lj_trace_err(J, LJ_TRERR_RETRY);\n#endif\n  lj_trace_end(J);\n  J->cur.linktype = (uint8_t)linktype;\n  J->cur.link = (uint16_t)lnk;\n  /* Looping back at the same stack level? */\n  if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) {\n    if ((J->flags & JIT_F_OPT_LOOP))  /* Shall we try to create a loop? */\n      goto nocanon;  /* Do not canonicalize or we lose the narrowing. */\n    if (J->cur.root)  /* Otherwise ensure we always link to the root trace. */\n      J->cur.link = J->cur.root;\n  }\n  canonicalize_slots(J);\nnocanon:\n  /* Note: all loop ops must set J->pc to the following instruction! */\n  lj_snap_add(J);  /* Add loop snapshot. */\n  J->needsnap = 0;\n  J->mergesnap = 1;  /* In case recording continues. */\n}\n\n/* Search bytecode backwards for a int/num constant slot initializer. */\nstatic TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t)\n{\n  /* This algorithm is rather simplistic and assumes quite a bit about\n  ** how the bytecode is generated. It works fine for FORI initializers,\n  ** but it won't necessarily work in other cases (e.g. iterator arguments).\n  ** It doesn't do anything fancy, either (like backpropagating MOVs).\n  */\n  const BCIns *pc, *startpc = proto_bc(J->pt);\n  for (pc = endpc-1; pc > startpc; pc--) {\n    BCIns ins = *pc;\n    BCOp op = bc_op(ins);\n    /* First try to find the last instruction that stores to this slot. */\n    if (bcmode_a(op) == BCMbase && bc_a(ins) <= slot) {\n      return 0;  /* Multiple results, e.g. from a CALL or KNIL. */\n    } else if (bcmode_a(op) == BCMdst && bc_a(ins) == slot) {\n      if (op == BC_KSHORT || op == BC_KNUM) {  /* Found const. initializer. */\n\t/* Now try to verify there's no forward jump across it. */\n\tconst BCIns *kpc = pc;\n\tfor (; pc > startpc; pc--)\n\t  if (bc_op(*pc) == BC_JMP) {\n\t    const BCIns *target = pc+bc_j(*pc)+1;\n\t    if (target > kpc && target <= endpc)\n\t      return 0;  /* Conditional assignment. */\n\t  }\n\tif (op == BC_KSHORT) {\n\t  int32_t k = (int32_t)(int16_t)bc_d(ins);\n\t  return t == IRT_INT ? lj_ir_kint(J, k) : lj_ir_knum(J, (lua_Number)k);\n\t} else {\n\t  cTValue *tv = proto_knumtv(J->pt, bc_d(ins));\n\t  if (t == IRT_INT) {\n\t    int32_t k = numberVint(tv);\n\t    if (tvisint(tv) || numV(tv) == (lua_Number)k)  /* -0 is ok here. */\n\t      return lj_ir_kint(J, k);\n\t    return 0;  /* Type mismatch. */\n\t  } else {\n\t    return lj_ir_knum(J, numberVnum(tv));\n\t  }\n\t}\n      }\n      return 0;  /* Non-constant initializer. */\n    }\n  }\n  return 0;  /* No assignment to this slot found? */\n}\n\n/* Load and optionally convert a FORI argument from a slot. */\nstatic TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode)\n{\n  int conv = (tvisint(&J->L->base[slot]) != (t==IRT_INT)) ? IRSLOAD_CONVERT : 0;\n  return sloadt(J, (int32_t)slot,\n\t\tt + (((mode & IRSLOAD_TYPECHECK) ||\n\t\t      (conv && t == IRT_INT && !(mode >> 16))) ?\n\t\t     IRT_GUARD : 0),\n\t\tmode + conv);\n}\n\n/* Peek before FORI to find a const initializer. Otherwise load from slot. */\nstatic TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,\n\t\t     IRType t, int mode)\n{\n  TRef tr = J->base[slot];\n  if (!tr) {\n    tr = find_kinit(J, fori, slot, t);\n    if (!tr)\n      tr = fori_load(J, slot, t, mode);\n  }\n  return tr;\n}\n\n/* Return the direction of the FOR loop iterator.\n** It's important to exactly reproduce the semantics of the interpreter.\n*/\nstatic int rec_for_direction(cTValue *o)\n{\n  return (tvisint(o) ? intV(o) : (int32_t)o->u32.hi) >= 0;\n}\n\n/* Simulate the runtime behavior of the FOR loop iterator. */\nstatic LoopEvent rec_for_iter(IROp *op, cTValue *o, int isforl)\n{\n  lua_Number stopv = numberVnum(&o[FORL_STOP]);\n  lua_Number idxv = numberVnum(&o[FORL_IDX]);\n  lua_Number stepv = numberVnum(&o[FORL_STEP]);\n  if (isforl)\n    idxv += stepv;\n  if (rec_for_direction(&o[FORL_STEP])) {\n    if (idxv <= stopv) {\n      *op = IR_LE;\n      return idxv + 2*stepv > stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;\n    }\n    *op = IR_GT; return LOOPEV_LEAVE;\n  } else {\n    if (stopv <= idxv) {\n      *op = IR_GE;\n      return idxv + 2*stepv < stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;\n    }\n    *op = IR_LT; return LOOPEV_LEAVE;\n  }\n}\n\n/* Record checks for FOR loop overflow and step direction. */\nstatic void rec_for_check(jit_State *J, IRType t, int dir,\n\t\t\t  TRef stop, TRef step, int init)\n{\n  if (!tref_isk(step)) {\n    /* Non-constant step: need a guard for the direction. */\n    TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J);\n    emitir(IRTG(dir ? IR_GE : IR_LT, t), step, zero);\n    /* Add hoistable overflow checks for a narrowed FORL index. */\n    if (init && t == IRT_INT) {\n      if (tref_isk(stop)) {\n\t/* Constant stop: optimize check away or to a range check for step. */\n\tint32_t k = IR(tref_ref(stop))->i;\n\tif (dir) {\n\t  if (k > 0)\n\t    emitir(IRTGI(IR_LE), step, lj_ir_kint(J, (int32_t)0x7fffffff-k));\n\t} else {\n\t  if (k < 0)\n\t    emitir(IRTGI(IR_GE), step, lj_ir_kint(J, (int32_t)0x80000000-k));\n\t}\n      } else {\n\t/* Stop+step variable: need full overflow check. */\n\tTRef tr = emitir(IRTGI(IR_ADDOV), step, stop);\n\temitir(IRTI(IR_USE), tr, 0);  /* ADDOV is weak. Avoid dead result. */\n      }\n    }\n  } else if (init && t == IRT_INT && !tref_isk(stop)) {\n    /* Constant step: optimize overflow check to a range check for stop. */\n    int32_t k = IR(tref_ref(step))->i;\n    k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k;\n    emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k));\n  }\n}\n\n/* Record a FORL instruction. */\nstatic void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev,\n\t\t\t int init)\n{\n  BCReg ra = bc_a(*fori);\n  cTValue *tv = &J->L->base[ra];\n  TRef idx = J->base[ra+FORL_IDX];\n  IRType t = idx ? tref_type(idx) :\n\t     (init || LJ_DUALNUM) ? lj_opt_narrow_forl(J, tv) : IRT_NUM;\n  int mode = IRSLOAD_INHERIT +\n    ((!LJ_DUALNUM || tvisint(tv) == (t == IRT_INT)) ? IRSLOAD_READONLY : 0);\n  TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode);\n  TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode);\n  int tc, dir = rec_for_direction(&tv[FORL_STEP]);\n  lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI);\n  scev->t.irt = t;\n  scev->dir = dir;\n  scev->stop = tref_ref(stop);\n  scev->step = tref_ref(step);\n  rec_for_check(J, t, dir, stop, step, init);\n  scev->start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT));\n  tc = (LJ_DUALNUM &&\n\t!(scev->start && irref_isk(scev->stop) && irref_isk(scev->step) &&\n\t  tvisint(&tv[FORL_IDX]) == (t == IRT_INT))) ?\n\tIRSLOAD_TYPECHECK : 0;\n  if (tc) {\n    J->base[ra+FORL_STOP] = stop;\n    J->base[ra+FORL_STEP] = step;\n  }\n  if (!idx)\n    idx = fori_load(J, ra+FORL_IDX, t,\n\t\t    IRSLOAD_INHERIT + tc + (J->scev.start << 16));\n  if (!init)\n    J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step);\n  J->base[ra+FORL_EXT] = idx;\n  scev->idx = tref_ref(idx);\n  setmref(scev->pc, fori);\n  J->maxslot = ra+FORL_EXT+1;\n}\n\n/* Record FORL/JFORL or FORI/JFORI. */\nstatic LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)\n{\n  BCReg ra = bc_a(*fori);\n  TValue *tv = &J->L->base[ra];\n  TRef *tr = &J->base[ra];\n  IROp op;\n  LoopEvent ev;\n  TRef stop;\n  IRType t;\n  if (isforl) {  /* Handle FORL/JFORL opcodes. */\n    TRef idx = tr[FORL_IDX];\n    if (mref(J->scev.pc, const BCIns) == fori && tref_ref(idx) == J->scev.idx) {\n      t = J->scev.t.irt;\n      stop = J->scev.stop;\n      idx = emitir(IRT(IR_ADD, t), idx, J->scev.step);\n      tr[FORL_EXT] = tr[FORL_IDX] = idx;\n    } else {\n      ScEvEntry scev;\n      rec_for_loop(J, fori, &scev, 0);\n      t = scev.t.irt;\n      stop = scev.stop;\n    }\n  } else {  /* Handle FORI/JFORI opcodes. */\n    BCReg i;\n    lj_meta_for(J->L, tv);\n    t = (LJ_DUALNUM || tref_isint(tr[FORL_IDX])) ? lj_opt_narrow_forl(J, tv) :\n\t\t\t\t\t\t   IRT_NUM;\n    for (i = FORL_IDX; i <= FORL_STEP; i++) {\n      if (!tr[i]) sload(J, ra+i);\n      lua_assert(tref_isnumber_str(tr[i]));\n      if (tref_isstr(tr[i]))\n\ttr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);\n      if (t == IRT_INT) {\n\tif (!tref_isinteger(tr[i]))\n\t  tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK);\n      } else {\n\tif (!tref_isnum(tr[i]))\n\t  tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT);\n      }\n    }\n    tr[FORL_EXT] = tr[FORL_IDX];\n    stop = tr[FORL_STOP];\n    rec_for_check(J, t, rec_for_direction(&tv[FORL_STEP]),\n\t\t  stop, tr[FORL_STEP], 1);\n  }\n\n  ev = rec_for_iter(&op, tv, isforl);\n  if (ev == LOOPEV_LEAVE) {\n    J->maxslot = ra+FORL_EXT+1;\n    J->pc = fori+1;\n  } else {\n    J->maxslot = ra;\n    J->pc = fori+bc_j(*fori)+1;\n  }\n  lj_snap_add(J);\n\n  emitir(IRTG(op, t), tr[FORL_IDX], stop);\n\n  if (ev == LOOPEV_LEAVE) {\n    J->maxslot = ra;\n    J->pc = fori+bc_j(*fori)+1;\n  } else {\n    J->maxslot = ra+FORL_EXT+1;\n    J->pc = fori+1;\n  }\n  J->needsnap = 1;\n  return ev;\n}\n\n/* Record ITERL/JITERL. */\nstatic LoopEvent rec_iterl(jit_State *J, const BCIns iterins)\n{\n  BCReg ra = bc_a(iterins);\n  lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n  if (!tref_isnil(getslot(J, ra))) {  /* Looping back? */\n    J->base[ra-1] = J->base[ra];  /* Copy result of ITERC to control var. */\n    J->maxslot = ra-1+bc_b(J->pc[-1]);\n    J->pc += bc_j(iterins)+1;\n    return LOOPEV_ENTER;\n  } else {\n    J->maxslot = ra-3;\n    J->pc++;\n    return LOOPEV_LEAVE;\n  }\n}\n\n/* Record LOOP/JLOOP. Now, that was easy. */\nstatic LoopEvent rec_loop(jit_State *J, BCReg ra)\n{\n  if (ra < J->maxslot) J->maxslot = ra;\n  J->pc++;\n  return LOOPEV_ENTER;\n}\n\n/* Check if a loop repeatedly failed to trace because it didn't loop back. */\nstatic int innerloopleft(jit_State *J, const BCIns *pc)\n{\n  ptrdiff_t i;\n  for (i = 0; i < PENALTY_SLOTS; i++)\n    if (mref(J->penalty[i].pc, const BCIns) == pc) {\n      if ((J->penalty[i].reason == LJ_TRERR_LLEAVE ||\n\t   J->penalty[i].reason == LJ_TRERR_LINNER) &&\n\t  J->penalty[i].val >= 2*PENALTY_MIN)\n\treturn 1;\n      break;\n    }\n  return 0;\n}\n\n/* Handle the case when an interpreted loop op is hit. */\nstatic void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev)\n{\n  if (J->parent == 0 && J->exitno == 0) {\n    if (pc == J->startpc && J->framedepth + J->retdepth == 0) {\n      /* Same loop? */\n      if (ev == LOOPEV_LEAVE)  /* Must loop back to form a root trace. */\n\tlj_trace_err(J, LJ_TRERR_LLEAVE);\n      lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Looping trace. */\n    } else if (ev != LOOPEV_LEAVE) {  /* Entering inner loop? */\n      /* It's usually better to abort here and wait until the inner loop\n      ** is traced. But if the inner loop repeatedly didn't loop back,\n      ** this indicates a low trip count. In this case try unrolling\n      ** an inner loop even in a root trace. But it's better to be a bit\n      ** more conservative here and only do it for very short loops.\n      */\n      if (bc_j(*pc) != -1 && !innerloopleft(J, pc))\n\tlj_trace_err(J, LJ_TRERR_LINNER);  /* Root trace hit an inner loop. */\n      if ((ev != LOOPEV_ENTERLO &&\n\t   J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0)\n\tlj_trace_err(J, LJ_TRERR_LUNROLL);  /* Limit loop unrolling. */\n      J->loopref = J->cur.nins;\n    }\n  } else if (ev != LOOPEV_LEAVE) {  /* Side trace enters an inner loop. */\n    J->loopref = J->cur.nins;\n    if (--J->loopunroll < 0)\n      lj_trace_err(J, LJ_TRERR_LUNROLL);  /* Limit loop unrolling. */\n  }  /* Side trace continues across a loop that's left or not entered. */\n}\n\n/* Handle the case when an already compiled loop op is hit. */\nstatic void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)\n{\n  if (J->parent == 0 && J->exitno == 0) {  /* Root trace hit an inner loop. */\n    /* Better let the inner loop spawn a side trace back here. */\n    lj_trace_err(J, LJ_TRERR_LINNER);\n  } else if (ev != LOOPEV_LEAVE) {  /* Side trace enters a compiled loop. */\n    J->instunroll = 0;  /* Cannot continue across a compiled loop op. */\n    if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)\n      lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Form extra loop. */\n    else\n      lj_record_stop(J, LJ_TRLINK_ROOT, lnk);  /* Link to the loop. */\n  }  /* Side trace continues across a loop that's left or not entered. */\n}\n\n/* -- Record profiler hook checks ----------------------------------------- */\n\n#if LJ_HASPROFILE\n\n/* Need to insert profiler hook check? */\nstatic int rec_profile_need(jit_State *J, GCproto *pt, const BCIns *pc)\n{\n  GCproto *ppt;\n  lua_assert(J->prof_mode == 'f' || J->prof_mode == 'l');\n  if (!pt)\n    return 0;\n  ppt = J->prev_pt;\n  J->prev_pt = pt;\n  if (pt != ppt && ppt) {\n    J->prev_line = -1;\n    return 1;\n  }\n  if (J->prof_mode == 'l') {\n    BCLine line = lj_debug_line(pt, proto_bcpos(pt, pc));\n    BCLine pline = J->prev_line;\n    J->prev_line = line;\n    if (pline != line)\n      return 1;\n  }\n  return 0;\n}\n\nstatic void rec_profile_ins(jit_State *J, const BCIns *pc)\n{\n  if (J->prof_mode && rec_profile_need(J, J->pt, pc)) {\n    emitir(IRTG(IR_PROF, IRT_NIL), 0, 0);\n    lj_snap_add(J);\n  }\n}\n\nstatic void rec_profile_ret(jit_State *J)\n{\n  if (J->prof_mode == 'f') {\n    emitir(IRTG(IR_PROF, IRT_NIL), 0, 0);\n    J->prev_pt = NULL;\n    lj_snap_add(J);\n  }\n}\n\n#endif\n\n/* -- Record calls and returns -------------------------------------------- */\n\n/* Specialize to the runtime value of the called function or its prototype. */\nstatic TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr)\n{\n  TRef kfunc;\n  if (isluafunc(fn)) {\n    GCproto *pt = funcproto(fn);\n    /* Too many closures created? Probably not a monomorphic function. */\n    if (pt->flags >= PROTO_CLC_POLY) {  /* Specialize to prototype instead. */\n      TRef trpt = emitir(IRT(IR_FLOAD, IRT_P32), tr, IRFL_FUNC_PC);\n      emitir(IRTG(IR_EQ, IRT_P32), trpt, lj_ir_kptr(J, proto_bc(pt)));\n      (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);  /* Prevent GC of proto. */\n      return tr;\n    }\n  } else {\n    /* Don't specialize to non-monomorphic builtins. */\n    switch (fn->c.ffid) {\n    case FF_coroutine_wrap_aux:\n    case FF_string_gmatch_aux:\n      /* NYI: io_file_iter doesn't have an ffid, yet. */\n      {  /* Specialize to the ffid. */\n\tTRef trid = emitir(IRT(IR_FLOAD, IRT_U8), tr, IRFL_FUNC_FFID);\n\temitir(IRTG(IR_EQ, IRT_INT), trid, lj_ir_kint(J, fn->c.ffid));\n      }\n      return tr;\n    default:\n      /* NYI: don't specialize to non-monomorphic C functions. */\n      break;\n    }\n  }\n  /* Otherwise specialize to the function (closure) value itself. */\n  kfunc = lj_ir_kfunc(J, fn);\n  emitir(IRTG(IR_EQ, IRT_FUNC), tr, kfunc);\n  return kfunc;\n}\n\n/* Record call setup. */\nstatic void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  RecordIndex ix;\n  TValue *functv = &J->L->base[func];\n  TRef *fbase = &J->base[func];\n  ptrdiff_t i;\n  lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n  for (i = 0; i <= nargs; i++)\n    (void)getslot(J, func+i);  /* Ensure func and all args have a reference. */\n  if (!tref_isfunc(fbase[0])) {  /* Resolve __call metamethod. */\n    ix.tab = fbase[0];\n    copyTV(J->L, &ix.tabv, functv);\n    if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj))\n      lj_trace_err(J, LJ_TRERR_NOMM);\n    for (i = ++nargs; i > 0; i--)  /* Shift arguments up. */\n      fbase[i] = fbase[i-1];\n    fbase[0] = ix.mobj;  /* Replace function. */\n    functv = &ix.mobjv;\n  }\n  fbase[0] = TREF_FRAME | rec_call_specialize(J, funcV(functv), fbase[0]);\n  J->maxslot = (BCReg)nargs;\n}\n\n/* Record call. */\nvoid lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  rec_call_setup(J, func, nargs);\n  /* Bump frame. */\n  J->framedepth++;\n  J->base += func+1;\n  J->baseslot += func+1;\n}\n\n/* Record tail call. */\nvoid lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  rec_call_setup(J, func, nargs);\n  if (frame_isvarg(J->L->base - 1)) {\n    BCReg cbase = (BCReg)frame_delta(J->L->base - 1);\n    if (--J->framedepth < 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    func += cbase;\n  }\n  /* Move func + args down. */\n  memmove(&J->base[-1], &J->base[func], sizeof(TRef)*(J->maxslot+1));\n  /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */\n  /* Tailcalls can form a loop, so count towards the loop unroll limit. */\n  if (++J->tailcalled > J->loopunroll)\n    lj_trace_err(J, LJ_TRERR_LUNROLL);\n}\n\n/* Check unroll limits for down-recursion. */\nstatic int check_downrec_unroll(jit_State *J, GCproto *pt)\n{\n  IRRef ptref;\n  for (ptref = J->chain[IR_KGC]; ptref; ptref = IR(ptref)->prev)\n    if (ir_kgc(IR(ptref)) == obj2gco(pt)) {\n      int count = 0;\n      IRRef ref;\n      for (ref = J->chain[IR_RETF]; ref; ref = IR(ref)->prev)\n\tif (IR(ref)->op1 == ptref)\n\t  count++;\n      if (count) {\n\tif (J->pc == J->startpc) {\n\t  if (count + J->tailcalled > J->param[JIT_P_recunroll])\n\t    return 1;\n\t} else {\n\t  lj_trace_err(J, LJ_TRERR_DOWNREC);\n\t}\n      }\n    }\n  return 0;\n}\n\nstatic TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot);\n\n/* Record return. */\nvoid lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)\n{\n  TValue *frame = J->L->base - 1;\n  ptrdiff_t i;\n  for (i = 0; i < gotresults; i++)\n    (void)getslot(J, rbase+i);  /* Ensure all results have a reference. */\n  while (frame_ispcall(frame)) {  /* Immediately resolve pcall() returns. */\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if (--J->framedepth < 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    lua_assert(J->baseslot > 1);\n    gotresults++;\n    rbase += cbase;\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    J->base[--rbase] = TREF_TRUE;  /* Prepend true to results. */\n    frame = frame_prevd(frame);\n  }\n  /* Return to lower frame via interpreter for unhandled cases. */\n  if (J->framedepth == 0 && J->pt && bc_isret(bc_op(*J->pc)) &&\n       (!frame_islua(frame) ||\n\t(J->parent == 0 && J->exitno == 0 &&\n\t !bc_isret(bc_op(J->cur.startins))))) {\n    /* NYI: specialize to frame type and return directly, not via RET*. */\n    for (i = 0; i < (ptrdiff_t)rbase; i++)\n      J->base[i] = 0;  /* Purge dead slots. */\n    J->maxslot = rbase + (BCReg)gotresults;\n    lj_record_stop(J, LJ_TRLINK_RETURN, 0);  /* Return to interpreter. */\n    return;\n  }\n  if (frame_isvarg(frame)) {\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if (--J->framedepth < 0)  /* NYI: return of vararg func to lower frame. */\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    lua_assert(J->baseslot > 1);\n    rbase += cbase;\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    frame = frame_prevd(frame);\n  }\n  if (frame_islua(frame)) {  /* Return to Lua frame. */\n    BCIns callins = *(frame_pc(frame)-1);\n    ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults;\n    BCReg cbase = bc_a(callins);\n    GCproto *pt = funcproto(frame_func(frame - (cbase+1-LJ_FR2)));\n    lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame teardown. */\n    if ((pt->flags & PROTO_NOJIT))\n      lj_trace_err(J, LJ_TRERR_CJITOFF);\n    if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) {\n      if (check_downrec_unroll(J, pt)) {\n\tJ->maxslot = (BCReg)(rbase + gotresults);\n\tlj_snap_purge(J);\n\tlj_record_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno);  /* Down-rec. */\n\treturn;\n      }\n      lj_snap_add(J);\n    }\n    for (i = 0; i < nresults; i++)  /* Adjust results. */\n      J->base[i-1] = i < gotresults ? J->base[rbase+i] : TREF_NIL;\n    J->maxslot = cbase+(BCReg)nresults;\n    if (J->framedepth > 0) {  /* Return to a frame that is part of the trace. */\n      J->framedepth--;\n      lua_assert(J->baseslot > cbase+1);\n      J->baseslot -= cbase+1;\n      J->base -= cbase+1;\n    } else if (J->parent == 0 && J->exitno == 0 &&\n\t       !bc_isret(bc_op(J->cur.startins))) {\n      /* Return to lower frame would leave the loop in a root trace. */\n      lj_trace_err(J, LJ_TRERR_LLEAVE);\n    } else if (J->needsnap) {  /* Tailcalled to ff with side-effects. */\n      lj_trace_err(J, LJ_TRERR_NYIRETL);  /* No way to insert snapshot here. */\n    } else {  /* Return to lower frame. Guard for the target we return to. */\n      TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);\n      TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame));\n      emitir(IRTG(IR_RETF, IRT_P32), trpt, trpc);\n      J->retdepth++;\n      J->needsnap = 1;\n      lua_assert(J->baseslot == 1);\n      /* Shift result slots up and clear the slots of the new frame below. */\n      memmove(J->base + cbase, J->base-1, sizeof(TRef)*nresults);\n      memset(J->base-1, 0, sizeof(TRef)*(cbase+1));\n    }\n  } else if (frame_iscont(frame)) {  /* Return to continuation frame. */\n    ASMFunction cont = frame_contf(frame);\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if ((J->framedepth -= 2) < 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    J->maxslot = cbase-2;\n    if (cont == lj_cont_ra) {\n      /* Copy result to destination slot. */\n      BCReg dst = bc_a(*(frame_contpc(frame)-1));\n      J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL;\n      if (dst >= J->maxslot) J->maxslot = dst+1;\n    } else if (cont == lj_cont_nop) {\n      /* Nothing to do here. */\n    } else if (cont == lj_cont_cat) {\n      BCReg bslot = bc_b(*(frame_contpc(frame)-1));\n      TRef tr = gotresults ? J->base[cbase+rbase] : TREF_NIL;\n      if (bslot != cbase-2) {  /* Concatenate the remainder. */\n\tTValue *b = J->L->base, save;  /* Simulate lower frame and result. */\n\tJ->base[cbase-2] = tr;\n\tcopyTV(J->L, &save, b-2);\n\tif (gotresults) copyTV(J->L, b-2, b+rbase); else setnilV(b-2);\n\tJ->L->base = b - cbase;\n\ttr = rec_cat(J, bslot, cbase-2);\n\tb = J->L->base + cbase;  /* Undo. */\n\tJ->L->base = b;\n\tcopyTV(J->L, b-2, &save);\n      }\n      if (tr) {  /* Store final result. */\n\tBCReg dst = bc_a(*(frame_contpc(frame)-1));\n\tJ->base[dst] = tr;\n\tif (dst >= J->maxslot) J->maxslot = dst+1;\n      }  /* Otherwise continue with another __concat call. */\n    } else {\n      /* Result type already specialized. */\n      lua_assert(cont == lj_cont_condf || cont == lj_cont_condt);\n    }\n  } else {\n    lj_trace_err(J, LJ_TRERR_NYIRETL);  /* NYI: handle return to C frame. */\n  }\n  lua_assert(J->baseslot >= 1);\n}\n\n/* -- Metamethod handling ------------------------------------------------- */\n\n/* Prepare to record call to metamethod. */\nstatic BCReg rec_mm_prep(jit_State *J, ASMFunction cont)\n{\n  BCReg s, top = cont == lj_cont_cat ? J->maxslot : curr_proto(J->L)->framesize;\n#if LJ_64\n  TRef trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin));\n#else\n  TRef trcont = lj_ir_kptr(J, (void *)cont);\n#endif\n  J->base[top] = trcont | TREF_CONT;\n  J->framedepth++;\n  for (s = J->maxslot; s < top; s++)\n    J->base[s] = 0;  /* Clear frame gap to avoid resurrecting previous refs. */\n  return top+1;\n}\n\n/* Record metamethod lookup. */\nint lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)\n{\n  RecordIndex mix;\n  GCtab *mt;\n  if (tref_istab(ix->tab)) {\n    mt = tabref(tabV(&ix->tabv)->metatable);\n    mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);\n  } else if (tref_isudata(ix->tab)) {\n    int udtype = udataV(&ix->tabv)->udtype;\n    mt = tabref(udataV(&ix->tabv)->metatable);\n    /* The metatables of special userdata objects are treated as immutable. */\n    if (udtype != UDTYPE_USERDATA) {\n      cTValue *mo;\n      if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {\n\t/* Specialize to the C library namespace object. */\n\temitir(IRTG(IR_EQ, IRT_P32), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv)));\n      } else {\n\t/* Specialize to the type of userdata. */\n\tTRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE);\n\temitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, udtype));\n      }\n  immutable_mt:\n      mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm));\n      if (!mo || tvisnil(mo))\n\treturn 0;  /* No metamethod. */\n      /* Treat metamethod or index table as immutable, too. */\n      if (!(tvisfunc(mo) || tvistab(mo)))\n\tlj_trace_err(J, LJ_TRERR_BADTYPE);\n      copyTV(J->L, &ix->mobjv, mo);\n      ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB);\n      ix->mtv = mt;\n      ix->mt = TREF_NIL;  /* Dummy value for comparison semantics. */\n      return 1;  /* Got metamethod or index table. */\n    }\n    mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META);\n  } else {\n    /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */\n    mt = tabref(basemt_obj(J2G(J), &ix->tabv));\n    if (mt == NULL) {\n      ix->mt = TREF_NIL;\n      return 0;  /* No metamethod. */\n    }\n    /* The cdata metatable is treated as immutable. */\n    if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt;\n    ix->mt = mix.tab = lj_ir_ktab(J, mt);\n    goto nocheck;\n  }\n  ix->mt = mt ? mix.tab : TREF_NIL;\n  emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mix.tab, lj_ir_knull(J, IRT_TAB));\nnocheck:\n  if (mt) {\n    GCstr *mmstr = mmname_str(J2G(J), mm);\n    cTValue *mo = lj_tab_getstr(mt, mmstr);\n    if (mo && !tvisnil(mo))\n      copyTV(J->L, &ix->mobjv, mo);\n    ix->mtv = mt;\n    settabV(J->L, &mix.tabv, mt);\n    setstrV(J->L, &mix.keyv, mmstr);\n    mix.key = lj_ir_kstr(J, mmstr);\n    mix.val = 0;\n    mix.idxchain = 0;\n    ix->mobj = lj_record_idx(J, &mix);\n    return !tref_isnil(ix->mobj);  /* 1 if metamethod found, 0 if not. */\n  }\n  return 0;  /* No metamethod. */\n}\n\n/* Record call to arithmetic metamethod. */\nstatic TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm)\n{\n  /* Set up metamethod call first to save ix->tab and ix->tabv. */\n  BCReg func = rec_mm_prep(J, mm == MM_concat ? lj_cont_cat : lj_cont_ra);\n  TRef *base = J->base + func;\n  TValue *basev = J->L->base + func;\n  base[1] = ix->tab; base[2] = ix->key;\n  copyTV(J->L, basev+1, &ix->tabv);\n  copyTV(J->L, basev+2, &ix->keyv);\n  if (!lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n    if (mm != MM_unm) {\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, &ix->keyv);\n      if (lj_record_mm_lookup(J, ix, mm))  /* Lookup mm on 2nd operand. */\n\tgoto ok;\n    }\n    lj_trace_err(J, LJ_TRERR_NOMM);\n  }\nok:\n  lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n  base[0] = ix->mobj;\n  copyTV(J->L, basev+0, &ix->mobjv);\n  lj_record_call(J, func, 2);\n  return 0;  /* No result yet. */\n}\n\n/* Record call to __len metamethod. */\nstatic TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)\n{\n  RecordIndex ix;\n  ix.tab = tr;\n  copyTV(J->L, &ix.tabv, tv);\n  if (lj_record_mm_lookup(J, &ix, MM_len)) {\n    BCReg func = rec_mm_prep(J, lj_cont_ra);\n    TRef *base = J->base + func;\n    TValue *basev = J->L->base + func;\n    lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n    base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv);\n    base[1] = tr; copyTV(J->L, basev+1, tv);\n#if LJ_52\n    base[2] = tr; copyTV(J->L, basev+2, tv);\n#else\n    base[2] = TREF_NIL; setnilV(basev+2);\n#endif\n    lj_record_call(J, func, 2);\n  } else {\n    if (LJ_52 && tref_istab(tr))\n      return lj_ir_call(J, IRCALL_lj_tab_len, tr);\n    lj_trace_err(J, LJ_TRERR_NOMM);\n  }\n  return 0;  /* No result yet. */\n}\n\n/* Call a comparison metamethod. */\nstatic void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op)\n{\n  BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt);\n  TRef *base = J->base + func;\n  TValue *tv = J->L->base + func;\n  lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n  base[0] = ix->mobj; base[1] = ix->val; base[2] = ix->key;\n  copyTV(J->L, tv+0, &ix->mobjv);\n  copyTV(J->L, tv+1, &ix->valv);\n  copyTV(J->L, tv+2, &ix->keyv);\n  lj_record_call(J, func, 2);\n}\n\n/* Record call to equality comparison metamethod (for tab and udata only). */\nstatic void rec_mm_equal(jit_State *J, RecordIndex *ix, int op)\n{\n  ix->tab = ix->val;\n  copyTV(J->L, &ix->tabv, &ix->valv);\n  if (lj_record_mm_lookup(J, ix, MM_eq)) {  /* Lookup mm on 1st operand. */\n    cTValue *bv;\n    TRef mo1 = ix->mobj;\n    TValue mo1v;\n    copyTV(J->L, &mo1v, &ix->mobjv);\n    /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */\n    bv = &ix->keyv;\n    if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {\n      TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);\n      emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n    } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {\n      TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);\n      emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n    } else {  /* Lookup metamethod on 2nd operand and compare both. */\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, bv);\n      if (!lj_record_mm_lookup(J, ix, MM_eq) ||\n\t  lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))\n\treturn;\n    }\n    rec_mm_callcomp(J, ix, op);\n  }\n}\n\n/* Record call to ordered comparison metamethods (for arbitrary objects). */\nstatic void rec_mm_comp(jit_State *J, RecordIndex *ix, int op)\n{\n  ix->tab = ix->val;\n  copyTV(J->L, &ix->tabv, &ix->valv);\n  while (1) {\n    MMS mm = (op & 2) ? MM_le : MM_lt;  /* Try __le + __lt or only __lt. */\n#if LJ_52\n    if (!lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, &ix->keyv);\n      if (!lj_record_mm_lookup(J, ix, mm))  /* Lookup mm on 2nd operand. */\n\tgoto nomatch;\n    }\n    rec_mm_callcomp(J, ix, op);\n    return;\n#else\n    if (lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n      cTValue *bv;\n      TRef mo1 = ix->mobj;\n      TValue mo1v;\n      copyTV(J->L, &mo1v, &ix->mobjv);\n      /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */\n      bv = &ix->keyv;\n      if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {\n\tTRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);\n\temitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n      } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {\n\tTRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);\n\temitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n      } else {  /* Lookup metamethod on 2nd operand and compare both. */\n\tix->tab = ix->key;\n\tcopyTV(J->L, &ix->tabv, bv);\n\tif (!lj_record_mm_lookup(J, ix, mm) ||\n\t    lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))\n\t  goto nomatch;\n      }\n      rec_mm_callcomp(J, ix, op);\n      return;\n    }\n#endif\n  nomatch:\n    /* Lookup failed. Retry with  __lt and swapped operands. */\n    if (!(op & 2)) break;  /* Already at __lt. Interpreter will throw. */\n    ix->tab = ix->key; ix->key = ix->val; ix->val = ix->tab;\n    copyTV(J->L, &ix->tabv, &ix->keyv);\n    copyTV(J->L, &ix->keyv, &ix->valv);\n    copyTV(J->L, &ix->valv, &ix->tabv);\n    op ^= 3;\n  }\n}\n\n#if LJ_HASFFI\n/* Setup call to cdata comparison metamethod. */\nstatic void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm)\n{\n  lj_snap_add(J);\n  if (tref_iscdata(ix->val)) {\n    ix->tab = ix->val;\n    copyTV(J->L, &ix->tabv, &ix->valv);\n  } else {\n    lua_assert(tref_iscdata(ix->key));\n    ix->tab = ix->key;\n    copyTV(J->L, &ix->tabv, &ix->keyv);\n  }\n  lj_record_mm_lookup(J, ix, mm);\n  rec_mm_callcomp(J, ix, op);\n}\n#endif\n\n/* -- Indexed access ------------------------------------------------------ */\n\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n/* Bump table allocations in bytecode when they grow during recording. */\nstatic void rec_idx_bump(jit_State *J, RecordIndex *ix)\n{\n  RBCHashEntry *rbc = &J->rbchash[(ix->tab & (RBCHASH_SLOTS-1))];\n  if (tref_ref(ix->tab) == rbc->ref) {\n    const BCIns *pc = mref(rbc->pc, const BCIns);\n    GCtab *tb = tabV(&ix->tabv);\n    uint32_t nhbits;\n    IRIns *ir;\n    if (!tvisnil(&ix->keyv))\n      (void)lj_tab_set(J->L, tb, &ix->keyv);  /* Grow table right now. */\n    nhbits = tb->hmask > 0 ? lj_fls(tb->hmask)+1 : 0;\n    ir = IR(tref_ref(ix->tab));\n    if (ir->o == IR_TNEW) {\n      uint32_t ah = bc_d(*pc);\n      uint32_t asize = ah & 0x7ff, hbits = ah >> 11;\n      if (nhbits > hbits) hbits = nhbits;\n      if (tb->asize > asize) {\n\tasize = tb->asize <= 0x7ff ? tb->asize : 0x7ff;\n      }\n      if ((asize | (hbits<<11)) != ah) {  /* Has the size changed? */\n\t/* Patch bytecode, but continue recording (for more patching). */\n\tsetbc_d(pc, (asize | (hbits<<11)));\n\t/* Patching TNEW operands is only safe if the trace is aborted. */\n\tir->op1 = asize; ir->op2 = hbits;\n\tJ->retryrec = 1;  /* Abort the trace at the end of recording. */\n      }\n    } else if (ir->o == IR_TDUP) {\n      GCtab *tpl = gco2tab(proto_kgc(&gcref(rbc->pt)->pt, ~(ptrdiff_t)bc_d(*pc)));\n      /* Grow template table, but preserve keys with nil values. */\n      if ((tb->asize > tpl->asize && (1u << nhbits)-1 == tpl->hmask) ||\n\t  (tb->asize == tpl->asize && (1u << nhbits)-1 > tpl->hmask)) {\n\tNode *node = noderef(tpl->node);\n\tuint32_t i, hmask = tpl->hmask, asize;\n\tTValue *array;\n\tfor (i = 0; i <= hmask; i++) {\n\t  if (!tvisnil(&node[i].key) && tvisnil(&node[i].val))\n\t    settabV(J->L, &node[i].val, tpl);\n\t}\n\tif (!tvisnil(&ix->keyv) && tref_isk(ix->key)) {\n\t  TValue *o = lj_tab_set(J->L, tpl, &ix->keyv);\n\t  if (tvisnil(o)) settabV(J->L, o, tpl);\n\t}\n\tlj_tab_resize(J->L, tpl, tb->asize, nhbits);\n\tnode = noderef(tpl->node);\n\thmask = tpl->hmask;\n\tfor (i = 0; i <= hmask; i++) {\n\t  /* This is safe, since template tables only hold immutable values. */\n\t  if (tvistab(&node[i].val))\n\t    setnilV(&node[i].val);\n\t}\n\t/* The shape of the table may have changed. Clean up array part, too. */\n\tasize = tpl->asize;\n\tarray = tvref(tpl->array);\n\tfor (i = 0; i < asize; i++) {\n\t  if (tvistab(&array[i]))\n\t    setnilV(&array[i]);\n\t}\n\tJ->retryrec = 1;  /* Abort the trace at the end of recording. */\n      }\n    }\n  }\n}\n#endif\n\n/* Record bounds-check. */\nstatic void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize)\n{\n  /* Try to emit invariant bounds checks. */\n  if ((J->flags & (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) ==\n      (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) {\n    IRRef ref = tref_ref(ikey);\n    IRIns *ir = IR(ref);\n    int32_t ofs = 0;\n    IRRef ofsref = 0;\n    /* Handle constant offsets. */\n    if (ir->o == IR_ADD && irref_isk(ir->op2)) {\n      ofsref = ir->op2;\n      ofs = IR(ofsref)->i;\n      ref = ir->op1;\n      ir = IR(ref);\n    }\n    /* Got scalar evolution analysis results for this reference? */\n    if (ref == J->scev.idx) {\n      int32_t stop;\n      lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD);\n      stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]);\n      /* Runtime value for stop of loop is within bounds? */\n      if ((uint64_t)stop + ofs < (uint64_t)asize) {\n\t/* Emit invariant bounds check for stop. */\n\temitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop :\n\t       emitir(IRTI(IR_ADD), J->scev.stop, ofsref));\n\t/* Emit invariant bounds check for start, if not const or negative. */\n\tif (!(J->scev.dir && J->scev.start &&\n\t      (int64_t)IR(J->scev.start)->i + ofs >= 0))\n\t  emitir(IRTG(IR_ABC, IRT_P32), asizeref, ikey);\n\treturn;\n      }\n    }\n  }\n  emitir(IRTGI(IR_ABC), asizeref, ikey);  /* Emit regular bounds check. */\n}\n\n/* Record indexed key lookup. */\nstatic TRef rec_idx_key(jit_State *J, RecordIndex *ix, IRRef *rbref,\n\t\t\tIRType1 *rbguard)\n{\n  TRef key;\n  GCtab *t = tabV(&ix->tabv);\n  ix->oldv = lj_tab_get(J->L, t, &ix->keyv);  /* Lookup previous value. */\n  *rbref = 0;\n  rbguard->irt = 0;\n\n  /* Integer keys are looked up in the array part first. */\n  key = ix->key;\n  if (tref_isnumber(key)) {\n    int32_t k = numberVint(&ix->keyv);\n    if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k)\n      k = LJ_MAX_ASIZE;\n    if ((MSize)k < LJ_MAX_ASIZE) {  /* Potential array key? */\n      TRef ikey = lj_opt_narrow_index(J, key);\n      TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);\n      if ((MSize)k < t->asize) {  /* Currently an array key? */\n\tTRef arrayref;\n\trec_idx_abc(J, asizeref, ikey, t->asize);\n\tarrayref = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_ARRAY);\n\treturn emitir(IRT(IR_AREF, IRT_P32), arrayref, ikey);\n      } else {  /* Currently not in array (may be an array extension)? */\n\temitir(IRTGI(IR_ULE), asizeref, ikey);  /* Inv. bounds check. */\n\tif (k == 0 && tref_isk(key))\n\t  key = lj_ir_knum_zero(J);  /* Canonicalize 0 or +-0.0 to +0.0. */\n\t/* And continue with the hash lookup. */\n      }\n    } else if (!tref_isk(key)) {\n      /* We can rule out const numbers which failed the integerness test\n      ** above. But all other numbers are potential array keys.\n      */\n      if (t->asize == 0) {  /* True sparse tables have an empty array part. */\n\t/* Guard that the array part stays empty. */\n\tTRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);\n\temitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));\n      } else {\n\tlj_trace_err(J, LJ_TRERR_NYITMIX);\n      }\n    }\n  }\n\n  /* Otherwise the key is located in the hash part. */\n  if (t->hmask == 0) {  /* Shortcut for empty hash part. */\n    /* Guard that the hash part stays empty. */\n    TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);\n    emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  }\n  if (tref_isinteger(key))  /* Hash keys are based on numbers, not ints. */\n    key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);\n  if (tref_isk(key)) {\n    /* Optimize lookup of constant hash keys. */\n    MSize hslot = (MSize)((char *)ix->oldv - (char *)&noderef(t->node)[0].val);\n    if (t->hmask > 0 && hslot <= t->hmask*(MSize)sizeof(Node) &&\n\thslot <= 65535*(MSize)sizeof(Node)) {\n      TRef node, kslot, hm;\n      *rbref = J->cur.nins;  /* Mark possible rollback point. */\n      *rbguard = J->guardemit;\n      hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);\n      emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask));\n      node = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_NODE);\n      kslot = lj_ir_kslot(J, key, hslot / sizeof(Node));\n      return emitir(IRTG(IR_HREFK, IRT_P32), node, kslot);\n    }\n  }\n  /* Fall back to a regular hash lookup. */\n  return emitir(IRT(IR_HREF, IRT_P32), ix->tab, key);\n}\n\n/* Determine whether a key is NOT one of the fast metamethod names. */\nstatic int nommstr(jit_State *J, TRef key)\n{\n  if (tref_isstr(key)) {\n    if (tref_isk(key)) {\n      GCstr *str = ir_kstr(IR(tref_ref(key)));\n      uint32_t mm;\n      for (mm = 0; mm <= MM_FAST; mm++)\n\tif (mmname_str(J2G(J), mm) == str)\n\t  return 0;  /* MUST be one the fast metamethod names. */\n    } else {\n      return 0;  /* Variable string key MAY be a metamethod name. */\n    }\n  }\n  return 1;  /* CANNOT be a metamethod name. */\n}\n\n/* Record indexed load/store. */\nTRef lj_record_idx(jit_State *J, RecordIndex *ix)\n{\n  TRef xref;\n  IROp xrefop, loadop;\n  IRRef rbref;\n  IRType1 rbguard;\n  cTValue *oldv;\n\n  while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */\n    /* Never call raw lj_record_idx() on non-table. */\n    lua_assert(ix->idxchain != 0);\n    if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index))\n      lj_trace_err(J, LJ_TRERR_NOMM);\n  handlemm:\n    if (tref_isfunc(ix->mobj)) {  /* Handle metamethod call. */\n      BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra);\n      TRef *base = J->base + func;\n      TValue *tv = J->L->base + func;\n      lua_assert(!LJ_FR2);  /* TODO_FR2: handle different frame setup. */\n      base[0] = ix->mobj; base[1] = ix->tab; base[2] = ix->key;\n      setfuncV(J->L, tv+0, funcV(&ix->mobjv));\n      copyTV(J->L, tv+1, &ix->tabv);\n      copyTV(J->L, tv+2, &ix->keyv);\n      if (ix->val) {\n\tbase[3] = ix->val;\n\tcopyTV(J->L, tv+3, &ix->valv);\n\tlj_record_call(J, func, 3);  /* mobj(tab, key, val) */\n\treturn 0;\n      } else {\n\tlj_record_call(J, func, 2);  /* res = mobj(tab, key) */\n\treturn 0;  /* No result yet. */\n      }\n    }\n    /* Otherwise retry lookup with metaobject. */\n    ix->tab = ix->mobj;\n    copyTV(J->L, &ix->tabv, &ix->mobjv);\n    if (--ix->idxchain == 0)\n      lj_trace_err(J, LJ_TRERR_IDXLOOP);\n  }\n\n  /* First catch nil and NaN keys for tables. */\n  if (tvisnil(&ix->keyv) || (tvisnum(&ix->keyv) && tvisnan(&ix->keyv))) {\n    if (ix->val)  /* Better fail early. */\n      lj_trace_err(J, LJ_TRERR_STORENN);\n    if (tref_isk(ix->key)) {\n      if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))\n\tgoto handlemm;\n      return TREF_NIL;\n    }\n  }\n\n  /* Record the key lookup. */\n  xref = rec_idx_key(J, ix, &rbref, &rbguard);\n  xrefop = IR(tref_ref(xref))->o;\n  loadop = xrefop == IR_AREF ? IR_ALOAD : IR_HLOAD;\n  /* The lj_meta_tset() inconsistency is gone, but better play safe. */\n  oldv = xrefop == IR_KKPTR ? (cTValue *)ir_kptr(IR(tref_ref(xref))) : ix->oldv;\n\n  if (ix->val == 0) {  /* Indexed load */\n    IRType t = itype2irt(oldv);\n    TRef res;\n    if (oldv == niltvg(J2G(J))) {\n      emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      res = TREF_NIL;\n    } else {\n      res = emitir(IRTG(loadop, t), xref, 0);\n    }\n    if (tref_ref(res) < rbref) {  /* HREFK + load forwarded? */\n      lj_ir_rollback(J, rbref);  /* Rollback to eliminate hmask guard. */\n      J->guardemit = rbguard;\n    }\n    if (t == IRT_NIL && ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))\n      goto handlemm;\n    if (irtype_ispri(t)) res = TREF_PRI(t);  /* Canonicalize primitives. */\n    return res;\n  } else {  /* Indexed store. */\n    GCtab *mt = tabref(tabV(&ix->tabv)->metatable);\n    int keybarrier = tref_isgcv(ix->key) && !tref_isnil(ix->val);\n    if (tref_ref(xref) < rbref) {  /* HREFK forwarded? */\n      lj_ir_rollback(J, rbref);  /* Rollback to eliminate hmask guard. */\n      J->guardemit = rbguard;\n    }\n    if (tvisnil(oldv)) {  /* Previous value was nil? */\n      /* Need to duplicate the hasmm check for the early guards. */\n      int hasmm = 0;\n      if (ix->idxchain && mt) {\n\tcTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), MM_newindex));\n\thasmm = mo && !tvisnil(mo);\n      }\n      if (hasmm)\n\temitir(IRTG(loadop, IRT_NIL), xref, 0);  /* Guard for nil value. */\n      else if (xrefop == IR_HREF)\n\temitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32),\n\t       xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {\n\tlua_assert(hasmm);\n\tgoto handlemm;\n      }\n      lua_assert(!hasmm);\n      if (oldv == niltvg(J2G(J))) {  /* Need to insert a new key. */\n\tTRef key = ix->key;\n\tif (tref_isinteger(key))  /* NEWREF needs a TValue as a key. */\n\t  key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);\n\txref = emitir(IRT(IR_NEWREF, IRT_P32), ix->tab, key);\n\tkeybarrier = 0;  /* NEWREF already takes care of the key barrier. */\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n\tif ((J->flags & JIT_F_OPT_SINK))  /* Avoid a separate flag. */\n\t  rec_idx_bump(J, ix);\n#endif\n      }\n    } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) {\n      /* Cannot derive that the previous value was non-nil, must do checks. */\n      if (xrefop == IR_HREF)  /* Guard against store to niltv. */\n\temitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      if (ix->idxchain) {  /* Metamethod lookup required? */\n\t/* A check for NULL metatable is cheaper (hoistable) than a load. */\n\tif (!mt) {\n\t  TRef mtref = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);\n\t  emitir(IRTG(IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB));\n\t} else {\n\t  IRType t = itype2irt(oldv);\n\t  emitir(IRTG(loadop, t), xref, 0);  /* Guard for non-nil value. */\n\t}\n      }\n    } else {\n      keybarrier = 0;  /* Previous non-nil value kept the key alive. */\n    }\n    /* Convert int to number before storing. */\n    if (!LJ_DUALNUM && tref_isinteger(ix->val))\n      ix->val = emitir(IRTN(IR_CONV), ix->val, IRCONV_NUM_INT);\n    emitir(IRT(loadop+IRDELTA_L2S, tref_type(ix->val)), xref, ix->val);\n    if (keybarrier || tref_isgcv(ix->val))\n      emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0);\n    /* Invalidate neg. metamethod cache for stores with certain string keys. */\n    if (!nommstr(J, ix->key)) {\n      TRef fref = emitir(IRT(IR_FREF, IRT_P32), ix->tab, IRFL_TAB_NOMM);\n      emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0));\n    }\n    J->needsnap = 1;\n    return 0;\n  }\n}\n\nstatic void rec_tsetm(jit_State *J, BCReg ra, BCReg rn, int32_t i)\n{\n  RecordIndex ix;\n  cTValue *basev = J->L->base;\n  GCtab *t = tabV(&basev[ra-1]);\n  settabV(J->L, &ix.tabv, t);\n  ix.tab = getslot(J, ra-1);\n  ix.idxchain = 0;\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  if ((J->flags & JIT_F_OPT_SINK)) {\n    if (t->asize < i+rn-ra)\n      lj_tab_reasize(J->L, t, i+rn-ra);\n    setnilV(&ix.keyv);\n    rec_idx_bump(J, &ix);\n  }\n#endif\n  for (; ra < rn; i++, ra++) {\n    setintV(&ix.keyv, i);\n    ix.key = lj_ir_kint(J, i);\n    copyTV(J->L, &ix.valv, &basev[ra]);\n    ix.val = getslot(J, ra);\n    lj_record_idx(J, &ix);\n  }\n}\n\n/* -- Upvalue access ------------------------------------------------------ */\n\n/* Check whether upvalue is immutable and ok to constify. */\nstatic int rec_upvalue_constify(jit_State *J, GCupval *uvp)\n{\n  if (uvp->immutable) {\n    cTValue *o = uvval(uvp);\n    /* Don't constify objects that may retain large amounts of memory. */\n#if LJ_HASFFI\n    if (tviscdata(o)) {\n      GCcdata *cd = cdataV(o);\n      if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) {\n\tCType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid);\n\tif (!ctype_hassize(ct->info) || ct->size <= 16)\n\t  return 1;\n      }\n      return 0;\n    }\n#else\n    UNUSED(J);\n#endif\n    if (!(tvistab(o) || tvisudata(o) || tvisthread(o)))\n      return 1;\n  }\n  return 0;\n}\n\n/* Record upvalue load/store. */\nstatic TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)\n{\n  GCupval *uvp = &gcref(J->fn->l.uvptr[uv])->uv;\n  TRef fn = getcurrf(J);\n  IRRef uref;\n  int needbarrier = 0;\n  if (rec_upvalue_constify(J, uvp)) {  /* Try to constify immutable upvalue. */\n    TRef tr, kfunc;\n    lua_assert(val == 0);\n    if (!tref_isk(fn)) {  /* Late specialization of current function. */\n      if (J->pt->flags >= PROTO_CLC_POLY)\n\tgoto noconstify;\n      kfunc = lj_ir_kfunc(J, J->fn);\n      emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc);\n      J->base[-1] = TREF_FRAME | kfunc;\n      fn = kfunc;\n    }\n    tr = lj_record_constify(J, uvval(uvp));\n    if (tr)\n      return tr;\n  }\nnoconstify:\n  /* Note: this effectively limits LJ_MAX_UPVAL to 127. */\n  uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff);\n  if (!uvp->closed) {\n    /* In current stack? */\n    if (uvval(uvp) >= tvref(J->L->stack) &&\n\tuvval(uvp) < tvref(J->L->maxstack)) {\n      int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));\n      if (slot >= 0) {  /* Aliases an SSA slot? */\n\tslot -= (int32_t)J->baseslot;  /* Note: slot number may be negative! */\n\t/* NYI: add IR to guard that it's still aliasing the same slot. */\n\tif (val == 0) {\n\t  return getslot(J, slot);\n\t} else {\n\t  J->base[slot] = val;\n\t  if (slot >= (int32_t)J->maxslot) J->maxslot = (BCReg)(slot+1);\n\t  return 0;\n\t}\n      }\n    }\n    uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_P32), fn, uv));\n  } else {\n    needbarrier = 1;\n    uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_P32), fn, uv));\n  }\n  if (val == 0) {  /* Upvalue load */\n    IRType t = itype2irt(uvval(uvp));\n    TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0);\n    if (irtype_ispri(t)) res = TREF_PRI(t);  /* Canonicalize primitive refs. */\n    return res;\n  } else {  /* Upvalue store. */\n    /* Convert int to number before storing. */\n    if (!LJ_DUALNUM && tref_isinteger(val))\n      val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);\n    emitir(IRT(IR_USTORE, tref_type(val)), uref, val);\n    if (needbarrier && tref_isgcv(val))\n      emitir(IRT(IR_OBAR, IRT_NIL), uref, val);\n    J->needsnap = 1;\n    return 0;\n  }\n}\n\n/* -- Record calls to Lua functions --------------------------------------- */\n\n/* Check unroll limits for calls. */\nstatic void check_call_unroll(jit_State *J, TraceNo lnk)\n{\n  cTValue *frame = J->L->base - 1;\n  void *pc = mref(frame_func(frame)->l.pc, void);\n  int32_t depth = J->framedepth;\n  int32_t count = 0;\n  if ((J->pt->flags & PROTO_VARARG)) depth--;  /* Vararg frame still missing. */\n  for (; depth > 0; depth--) {  /* Count frames with same prototype. */\n    if (frame_iscont(frame)) depth--;\n    frame = frame_prev(frame);\n    if (mref(frame_func(frame)->l.pc, void) == pc)\n      count++;\n  }\n  if (J->pc == J->startpc) {\n    if (count + J->tailcalled > J->param[JIT_P_recunroll]) {\n      J->pc++;\n      if (J->framedepth + J->retdepth == 0)\n\tlj_record_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno);  /* Tail-rec. */\n      else\n\tlj_record_stop(J, LJ_TRLINK_UPREC, J->cur.traceno);  /* Up-recursion. */\n    }\n  } else {\n    if (count > J->param[JIT_P_callunroll]) {\n      if (lnk) {  /* Possible tail- or up-recursion. */\n\tlj_trace_flush(J, lnk);  /* Flush trace that only returns. */\n\t/* Set a small, pseudo-random hotcount for a quick retry of JFUNC*. */\n\thotcount_set(J2GG(J), J->pc+1, LJ_PRNG_BITS(J, 4));\n      }\n      lj_trace_err(J, LJ_TRERR_CUNROLL);\n    }\n  }\n}\n\n/* Record Lua function setup. */\nstatic void rec_func_setup(jit_State *J)\n{\n  GCproto *pt = J->pt;\n  BCReg s, numparams = pt->numparams;\n  if ((pt->flags & PROTO_NOJIT))\n    lj_trace_err(J, LJ_TRERR_CJITOFF);\n  if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n  /* Fill up missing parameters with nil. */\n  for (s = J->maxslot; s < numparams; s++)\n    J->base[s] = TREF_NIL;\n  /* The remaining slots should never be read before they are written. */\n  J->maxslot = numparams;\n}\n\n/* Record Lua vararg function setup. */\nstatic void rec_func_vararg(jit_State *J)\n{\n  GCproto *pt = J->pt;\n  BCReg s, fixargs, vframe = J->maxslot+1;\n  lua_assert((pt->flags & PROTO_VARARG));\n  if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n  J->base[vframe-1] = J->base[-1];  /* Copy function up. */\n  /* Copy fixarg slots up and set their original slots to nil. */\n  fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot;\n  for (s = 0; s < fixargs; s++) {\n    J->base[vframe+s] = J->base[s];\n    J->base[s] = TREF_NIL;\n  }\n  J->maxslot = fixargs;\n  J->framedepth++;\n  J->base += vframe;\n  J->baseslot += vframe;\n}\n\n/* Record entry to a Lua function. */\nstatic void rec_func_lua(jit_State *J)\n{\n  rec_func_setup(J);\n  check_call_unroll(J, 0);\n}\n\n/* Record entry to an already compiled function. */\nstatic void rec_func_jit(jit_State *J, TraceNo lnk)\n{\n  GCtrace *T;\n  rec_func_setup(J);\n  T = traceref(J, lnk);\n  if (T->linktype == LJ_TRLINK_RETURN) {  /* Trace returns to interpreter? */\n    check_call_unroll(J, lnk);\n    /* Temporarily unpatch JFUNC* to continue recording across function. */\n    J->patchins = *J->pc;\n    J->patchpc = (BCIns *)J->pc;\n    *J->patchpc = T->startins;\n    return;\n  }\n  J->instunroll = 0;  /* Cannot continue across a compiled function. */\n  if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)\n    lj_record_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno);  /* Extra tail-rec. */\n  else\n    lj_record_stop(J, LJ_TRLINK_ROOT, lnk);  /* Link to the function. */\n}\n\n/* -- Vararg handling ----------------------------------------------------- */\n\n/* Detect y = select(x, ...) idiom. */\nstatic int select_detect(jit_State *J)\n{\n  BCIns ins = J->pc[1];\n  if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) {\n    cTValue *func = &J->L->base[bc_a(ins)];\n    if (tvisfunc(func) && funcV(func)->c.ffid == FF_select)\n      return 1;\n  }\n  return 0;\n}\n\n/* Record vararg instruction. */\nstatic void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)\n{\n  int32_t numparams = J->pt->numparams;\n  ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1;\n  lua_assert(frame_isvarg(J->L->base-1));\n  if (J->framedepth > 0) {  /* Simple case: varargs defined on-trace. */\n    ptrdiff_t i;\n    if (nvararg < 0) nvararg = 0;\n    if (nresults == -1) {\n      nresults = nvararg;\n      J->maxslot = dst + (BCReg)nvararg;\n    } else if (dst + nresults > J->maxslot) {\n      J->maxslot = dst + (BCReg)nresults;\n    }\n    for (i = 0; i < nresults; i++)\n      J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL;\n  } else {  /* Unknown number of varargs passed to trace. */\n    TRef fr = emitir(IRTI(IR_SLOAD), 0, IRSLOAD_READONLY|IRSLOAD_FRAME);\n    int32_t frofs = 8*(1+numparams)+FRAME_VARG;\n    if (nresults >= 0) {  /* Known fixed number of results. */\n      ptrdiff_t i;\n      if (nvararg > 0) {\n\tptrdiff_t nload = nvararg >= nresults ? nresults : nvararg;\n\tTRef vbase;\n\tif (nvararg >= nresults)\n\t  emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults));\n\telse\n\t  emitir(IRTGI(IR_EQ), fr,\n\t\t lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1)));\n\tvbase = emitir(IRTI(IR_SUB), REF_BASE, fr);\n\tvbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));\n\tfor (i = 0; i < nload; i++) {\n\t  IRType t = itype2irt(&J->L->base[i-1-nvararg]);\n\t  TRef aref = emitir(IRT(IR_AREF, IRT_P32),\n\t\t\t     vbase, lj_ir_kint(J, (int32_t)i));\n\t  TRef tr = emitir(IRTG(IR_VLOAD, t), aref, 0);\n\t  if (irtype_ispri(t)) tr = TREF_PRI(t);  /* Canonicalize primitives. */\n\t  J->base[dst+i] = tr;\n\t}\n      } else {\n\temitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs));\n\tnvararg = 0;\n      }\n      for (i = nvararg; i < nresults; i++)\n\tJ->base[dst+i] = TREF_NIL;\n      if (dst + (BCReg)nresults > J->maxslot)\n\tJ->maxslot = dst + (BCReg)nresults;\n    } else if (select_detect(J)) {  /* y = select(x, ...) */\n      TRef tridx = J->base[dst-1];\n      TRef tr = TREF_NIL;\n      ptrdiff_t idx = lj_ffrecord_select_mode(J, tridx, &J->L->base[dst-1]);\n      if (idx < 0) goto nyivarg;\n      if (idx != 0 && !tref_isinteger(tridx))\n\ttridx = emitir(IRTGI(IR_CONV), tridx, IRCONV_INT_NUM|IRCONV_INDEX);\n      if (idx != 0 && tref_isk(tridx)) {\n\temitir(IRTGI(idx <= nvararg ? IR_GE : IR_LT),\n\t       fr, lj_ir_kint(J, frofs+8*(int32_t)idx));\n\tfrofs -= 8;  /* Bias for 1-based index. */\n      } else if (idx <= nvararg) {  /* Compute size. */\n\tTRef tmp = emitir(IRTI(IR_ADD), fr, lj_ir_kint(J, -frofs));\n\tif (numparams)\n\t  emitir(IRTGI(IR_GE), tmp, lj_ir_kint(J, 0));\n\ttr = emitir(IRTI(IR_BSHR), tmp, lj_ir_kint(J, 3));\n\tif (idx != 0) {\n\t  tridx = emitir(IRTI(IR_ADD), tridx, lj_ir_kint(J, -1));\n\t  rec_idx_abc(J, tr, tridx, (uint32_t)nvararg);\n\t}\n      } else {\n\tTRef tmp = lj_ir_kint(J, frofs);\n\tif (idx != 0) {\n\t  TRef tmp2 = emitir(IRTI(IR_BSHL), tridx, lj_ir_kint(J, 3));\n\t  tmp = emitir(IRTI(IR_ADD), tmp2, tmp);\n\t} else {\n\t  tr = lj_ir_kint(J, 0);\n\t}\n\temitir(IRTGI(IR_LT), fr, tmp);\n      }\n      if (idx != 0 && idx <= nvararg) {\n\tIRType t;\n\tTRef aref, vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);\n\tvbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));\n\tt = itype2irt(&J->L->base[idx-2-nvararg]);\n\taref = emitir(IRT(IR_AREF, IRT_P32), vbase, tridx);\n\ttr = emitir(IRTG(IR_VLOAD, t), aref, 0);\n\tif (irtype_ispri(t)) tr = TREF_PRI(t);  /* Canonicalize primitives. */\n      }\n      J->base[dst-2] = tr;\n      J->maxslot = dst-1;\n      J->bcskip = 2;  /* Skip CALLM + select. */\n    } else {\n    nyivarg:\n      setintV(&J->errinfo, BC_VARG);\n      lj_trace_err_info(J, LJ_TRERR_NYIBC);\n    }\n  }\n}\n\n/* -- Record allocations -------------------------------------------------- */\n\nstatic TRef rec_tnew(jit_State *J, uint32_t ah)\n{\n  uint32_t asize = ah & 0x7ff;\n  uint32_t hbits = ah >> 11;\n  TRef tr;\n  if (asize == 0x7ff) asize = 0x801;\n  tr = emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits);\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  J->rbchash[(tr & (RBCHASH_SLOTS-1))].ref = tref_ref(tr);\n  setmref(J->rbchash[(tr & (RBCHASH_SLOTS-1))].pc, J->pc);\n  setgcref(J->rbchash[(tr & (RBCHASH_SLOTS-1))].pt, obj2gco(J->pt));\n#endif\n  return tr;\n}\n\n/* -- Concatenation ------------------------------------------------------- */\n\nstatic TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)\n{\n  TRef *top = &J->base[topslot];\n  TValue savetv[5];\n  BCReg s;\n  RecordIndex ix;\n  lua_assert(baseslot < topslot);\n  for (s = baseslot; s <= topslot; s++)\n    (void)getslot(J, s);  /* Ensure all arguments have a reference. */\n  if (tref_isnumber_str(top[0]) && tref_isnumber_str(top[-1])) {\n    TRef tr, hdr, *trp, *xbase, *base = &J->base[baseslot];\n    /* First convert numbers to strings. */\n    for (trp = top; trp >= base; trp--) {\n      if (tref_isnumber(*trp))\n\t*trp = emitir(IRT(IR_TOSTR, IRT_STR), *trp,\n\t\t      tref_isnum(*trp) ? IRTOSTR_NUM : IRTOSTR_INT);\n      else if (!tref_isstr(*trp))\n\tbreak;\n    }\n    xbase = ++trp;\n    tr = hdr = emitir(IRT(IR_BUFHDR, IRT_P32),\n\t\t      lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);\n    do {\n      tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, *trp++);\n    } while (trp <= top);\n    tr = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr);\n    J->maxslot = (BCReg)(xbase - J->base);\n    if (xbase == base) return tr;  /* Return simple concatenation result. */\n    /* Pass partial result. */\n    topslot = J->maxslot--;\n    *xbase = tr;\n    top = xbase;\n    setstrV(J->L, &ix.keyv, &J2G(J)->strempty);  /* Simulate string result. */\n  } else {\n    J->maxslot = topslot-1;\n    copyTV(J->L, &ix.keyv, &J->L->base[topslot]);\n  }\n  copyTV(J->L, &ix.tabv, &J->L->base[topslot-1]);\n  ix.tab = top[-1];\n  ix.key = top[0];\n  memcpy(savetv, &J->L->base[topslot-1], sizeof(savetv));  /* Save slots. */\n  rec_mm_arith(J, &ix, MM_concat);  /* Call __concat metamethod. */\n  memcpy(&J->L->base[topslot-1], savetv, sizeof(savetv));  /* Restore slots. */\n  return 0;  /* No result yet. */\n}\n\n/* -- Record bytecode ops ------------------------------------------------- */\n\n/* Prepare for comparison. */\nstatic void rec_comp_prep(jit_State *J)\n{\n  /* Prevent merging with snapshot #0 (GC exit) since we fixup the PC. */\n  if (J->cur.nsnap == 1 && J->cur.snap[0].ref == J->cur.nins)\n    emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);\n  lj_snap_add(J);\n}\n\n/* Fixup comparison. */\nstatic void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond)\n{\n  BCIns jmpins = pc[1];\n  const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0);\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n  /* Set PC to opposite target to avoid re-recording the comp. in side trace. */\n  J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc);\n  J->needsnap = 1;\n  if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins);\n  lj_snap_shrink(J);  /* Shrink last snapshot if possible. */\n}\n\n/* Record the next bytecode instruction (_before_ it's executed). */\nvoid lj_record_ins(jit_State *J)\n{\n  cTValue *lbase;\n  RecordIndex ix;\n  const BCIns *pc;\n  BCIns ins;\n  BCOp op;\n  TRef ra, rb, rc;\n\n  /* Perform post-processing action before recording the next instruction. */\n  if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {\n    switch (J->postproc) {\n    case LJ_POST_FIXCOMP:  /* Fixup comparison. */\n      pc = (const BCIns *)(uintptr_t)J2G(J)->tmptv.u64;\n      rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1)));\n      /* fallthrough */\n    case LJ_POST_FIXGUARD:  /* Fixup and emit pending guard. */\n    case LJ_POST_FIXGUARDSNAP:  /* Fixup and emit pending guard and snapshot. */\n      if (!tvistruecond(&J2G(J)->tmptv2)) {\n\tJ->fold.ins.o ^= 1;  /* Flip guard to opposite. */\n\tif (J->postproc == LJ_POST_FIXGUARDSNAP) {\n\t  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n\t  J->cur.snapmap[snap->mapofs+snap->nent-1]--;  /* False -> true. */\n\t}\n      }\n      lj_opt_fold(J);  /* Emit pending guard. */\n      /* fallthrough */\n    case LJ_POST_FIXBOOL:\n      if (!tvistruecond(&J2G(J)->tmptv2)) {\n\tBCReg s;\n\tTValue *tv = J->L->base;\n\tfor (s = 0; s < J->maxslot; s++)  /* Fixup stack slot (if any). */\n\t  if (J->base[s] == TREF_TRUE && tvisfalse(&tv[s])) {\n\t    J->base[s] = TREF_FALSE;\n\t    break;\n\t  }\n      }\n      break;\n    case LJ_POST_FIXCONST:\n      {\n\tBCReg s;\n\tTValue *tv = J->L->base;\n\tfor (s = 0; s < J->maxslot; s++)  /* Constify stack slots (if any). */\n\t  if (J->base[s] == TREF_NIL && !tvisnil(&tv[s]))\n\t    J->base[s] = lj_record_constify(J, &tv[s]);\n      }\n      break;\n    case LJ_POST_FFRETRY:  /* Suppress recording of retried fast function. */\n      if (bc_op(*J->pc) >= BC__MAX)\n\treturn;\n      break;\n    default: lua_assert(0); break;\n    }\n    J->postproc = LJ_POST_NONE;\n  }\n\n  /* Need snapshot before recording next bytecode (e.g. after a store). */\n  if (J->needsnap) {\n    J->needsnap = 0;\n    lj_snap_purge(J);\n    lj_snap_add(J);\n    J->mergesnap = 1;\n  }\n\n  /* Skip some bytecodes. */\n  if (LJ_UNLIKELY(J->bcskip > 0)) {\n    J->bcskip--;\n    return;\n  }\n\n  /* Record only closed loops for root traces. */\n  pc = J->pc;\n  if (J->framedepth == 0 &&\n     (MSize)((char *)pc - (char *)J->bc_min) >= J->bc_extent)\n    lj_trace_err(J, LJ_TRERR_LLEAVE);\n\n#ifdef LUA_USE_ASSERT\n  rec_check_slots(J);\n  rec_check_ir(J);\n#endif\n\n#if LJ_HASPROFILE\n  rec_profile_ins(J, pc);\n#endif\n\n  /* Keep a copy of the runtime values of var/num/str operands. */\n#define rav\t(&ix.valv)\n#define rbv\t(&ix.tabv)\n#define rcv\t(&ix.keyv)\n\n  lbase = J->L->base;\n  ins = *pc;\n  op = bc_op(ins);\n  ra = bc_a(ins);\n  ix.val = 0;\n  switch (bcmode_a(op)) {\n  case BCMvar:\n    copyTV(J->L, rav, &lbase[ra]); ix.val = ra = getslot(J, ra); break;\n  default: break;  /* Handled later. */\n  }\n  rb = bc_b(ins);\n  rc = bc_c(ins);\n  switch (bcmode_b(op)) {\n  case BCMnone: rb = 0; rc = bc_d(ins); break;  /* Upgrade rc to 'rd'. */\n  case BCMvar:\n    copyTV(J->L, rbv, &lbase[rb]); ix.tab = rb = getslot(J, rb); break;\n  default: break;  /* Handled later. */\n  }\n  switch (bcmode_c(op)) {\n  case BCMvar:\n    copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break;\n  case BCMpri: setpriV(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break;\n  case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc);\n    copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) :\n    lj_ir_knumint(J, numV(tv)); } break;\n  case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc));\n    setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break;\n  default: break;  /* Handled later. */\n  }\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n#if LJ_HASFFI\n    if (tref_iscdata(ra) || tref_iscdata(rc)) {\n      rec_mm_comp_cdata(J, &ix, op, ((int)op & 2) ? MM_le : MM_lt);\n      break;\n    }\n#endif\n    /* Emit nothing for two numeric or string consts. */\n    if (!(tref_isk2(ra,rc) && tref_isnumber_str(ra) && tref_isnumber_str(rc))) {\n      IRType ta = tref_isinteger(ra) ? IRT_INT : tref_type(ra);\n      IRType tc = tref_isinteger(rc) ? IRT_INT : tref_type(rc);\n      int irop;\n      if (ta != tc) {\n\t/* Widen mixed number/int comparisons to number/number comparison. */\n\tif (ta == IRT_INT && tc == IRT_NUM) {\n\t  ra = emitir(IRTN(IR_CONV), ra, IRCONV_NUM_INT);\n\t  ta = IRT_NUM;\n\t} else if (ta == IRT_NUM && tc == IRT_INT) {\n\t  rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n\t} else if (LJ_52) {\n\t  ta = IRT_NIL;  /* Force metamethod for different types. */\n\t} else if (!((ta == IRT_FALSE || ta == IRT_TRUE) &&\n\t\t     (tc == IRT_FALSE || tc == IRT_TRUE))) {\n\t  break;  /* Interpreter will throw for two different types. */\n\t}\n      }\n      rec_comp_prep(J);\n      irop = (int)op - (int)BC_ISLT + (int)IR_LT;\n      if (ta == IRT_NUM) {\n\tif ((irop & 1)) irop ^= 4;  /* ISGE/ISGT are unordered. */\n\tif (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))\n\t  irop ^= 5;\n      } else if (ta == IRT_INT) {\n\tif (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))\n\t  irop ^= 1;\n      } else if (ta == IRT_STR) {\n\tif (!lj_ir_strcmp(strV(rav), strV(rcv), (IROp)irop)) irop ^= 1;\n\tra = lj_ir_call(J, IRCALL_lj_str_cmp, ra, rc);\n\trc = lj_ir_kint(J, 0);\n\tta = IRT_INT;\n      } else {\n\trec_mm_comp(J, &ix, (int)op);\n\tbreak;\n      }\n      emitir(IRTG(irop, ta), ra, rc);\n      rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1);\n    }\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n  case BC_ISEQS: case BC_ISNES:\n  case BC_ISEQN: case BC_ISNEN:\n  case BC_ISEQP: case BC_ISNEP:\n#if LJ_HASFFI\n    if (tref_iscdata(ra) || tref_iscdata(rc)) {\n      rec_mm_comp_cdata(J, &ix, op, MM_eq);\n      break;\n    }\n#endif\n    /* Emit nothing for two non-table, non-udata consts. */\n    if (!(tref_isk2(ra, rc) && !(tref_istab(ra) || tref_isudata(ra)))) {\n      int diff;\n      rec_comp_prep(J);\n      diff = lj_record_objcmp(J, ra, rc, rav, rcv);\n      if (diff == 2 || !(tref_istab(ra) || tref_isudata(ra)))\n\trec_comp_fixup(J, J->pc, ((int)op & 1) == !diff);\n      else if (diff == 1)  /* Only check __eq if different, but same type. */\n\trec_mm_equal(J, &ix, (int)op);\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC:\n    if ((op & 1) == tref_istruecond(rc))\n      rc = 0;  /* Don't store if condition is not true. */\n    /* fallthrough */\n  case BC_IST: case BC_ISF:  /* Type specialization suffices. */\n    if (bc_a(pc[1]) < J->maxslot)\n      J->maxslot = bc_a(pc[1]);  /* Shrink used slots. */\n    break;\n\n  case BC_ISTYPE: case BC_ISNUM:\n    /* These coercions need to correspond with lj_meta_istype(). */\n    if (LJ_DUALNUM && rc == ~LJ_TNUMX+1)\n      ra = lj_opt_narrow_toint(J, ra);\n    else if (rc == ~LJ_TNUMX+2)\n      ra = lj_ir_tonum(J, ra);\n    else if (rc == ~LJ_TSTR+1)\n      ra = lj_ir_tostr(J, ra);\n    /* else: type specialization suffices. */\n    J->base[bc_a(ins)] = ra;\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_NOT:\n    /* Type specialization already forces const result. */\n    rc = tref_istruecond(rc) ? TREF_FALSE : TREF_TRUE;\n    break;\n\n  case BC_LEN:\n    if (tref_isstr(rc))\n      rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN);\n    else if (!LJ_52 && tref_istab(rc))\n      rc = lj_ir_call(J, IRCALL_lj_tab_len, rc);\n    else\n      rc = rec_mm_len(J, rc, rcv);\n    break;\n\n  /* -- Arithmetic ops ---------------------------------------------------- */\n\n  case BC_UNM:\n    if (tref_isnumber_str(rc)) {\n      rc = lj_opt_narrow_unm(J, rc, rcv);\n    } else {\n      ix.tab = rc;\n      copyTV(J->L, &ix.tabv, rcv);\n      rc = rec_mm_arith(J, &ix, MM_unm);\n    }\n    break;\n\n  case BC_ADDNV: case BC_SUBNV: case BC_MULNV: case BC_DIVNV: case BC_MODNV:\n    /* Swap rb/rc and rbv/rcv. rav is temp. */\n    ix.tab = rc; ix.key = rc = rb; rb = ix.tab;\n    copyTV(J->L, rav, rbv);\n    copyTV(J->L, rbv, rcv);\n    copyTV(J->L, rcv, rav);\n    if (op == BC_MODNV)\n      goto recmod;\n    /* fallthrough */\n  case BC_ADDVN: case BC_SUBVN: case BC_MULVN: case BC_DIVVN:\n  case BC_ADDVV: case BC_SUBVV: case BC_MULVV: case BC_DIVVV: {\n    MMS mm = bcmode_mm(op);\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv,\n\t\t\t       (int)mm - (int)MM_add + (int)IR_ADD);\n    else\n      rc = rec_mm_arith(J, &ix, mm);\n    break;\n    }\n\n  case BC_MODVN: case BC_MODVV:\n  recmod:\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_mod(J, rb, rc, rcv);\n    else\n      rc = rec_mm_arith(J, &ix, MM_mod);\n    break;\n\n  case BC_POW:\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_pow(J, lj_ir_tonum(J, rb), rc, rcv);\n    else\n      rc = rec_mm_arith(J, &ix, MM_pow);\n    break;\n\n  /* -- Miscellaneous ops ------------------------------------------------- */\n\n  case BC_CAT:\n    rc = rec_cat(J, rb, rc);\n    break;\n\n  /* -- Constant and move ops --------------------------------------------- */\n\n  case BC_MOV:\n    /* Clear gap of method call to avoid resurrecting previous refs. */\n    if (ra > J->maxslot) J->base[ra-1] = 0;\n    break;\n  case BC_KSTR: case BC_KNUM: case BC_KPRI:\n    break;\n  case BC_KSHORT:\n    rc = lj_ir_kint(J, (int32_t)(int16_t)rc);\n    break;\n  case BC_KNIL:\n    while (ra <= rc)\n      J->base[ra++] = TREF_NIL;\n    if (rc >= J->maxslot) J->maxslot = rc+1;\n    break;\n#if LJ_HASFFI\n  case BC_KCDATA:\n    rc = lj_ir_kgc(J, proto_kgc(J->pt, ~(ptrdiff_t)rc), IRT_CDATA);\n    break;\n#endif\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    rc = rec_upvalue(J, rc, 0);\n    break;\n  case BC_USETV: case BC_USETS: case BC_USETN: case BC_USETP:\n    rec_upvalue(J, ra, rc);\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_GGET: case BC_GSET:\n    settabV(J->L, &ix.tabv, tabref(J->fn->l.env));\n    ix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), getcurrf(J), IRFL_FUNC_ENV);\n    ix.idxchain = LJ_MAX_IDXCHAIN;\n    rc = lj_record_idx(J, &ix);\n    break;\n\n  case BC_TGETB: case BC_TSETB:\n    setintV(&ix.keyv, (int32_t)rc);\n    ix.key = lj_ir_kint(J, (int32_t)rc);\n    /* fallthrough */\n  case BC_TGETV: case BC_TGETS: case BC_TSETV: case BC_TSETS:\n    ix.idxchain = LJ_MAX_IDXCHAIN;\n    rc = lj_record_idx(J, &ix);\n    break;\n  case BC_TGETR: case BC_TSETR:\n    ix.idxchain = 0;\n    rc = lj_record_idx(J, &ix);\n    break;\n\n  case BC_TSETM:\n    rec_tsetm(J, ra, (BCReg)(J->L->top - J->L->base), (int32_t)rcv->u32.lo);\n    break;\n\n  case BC_TNEW:\n    rc = rec_tnew(J, rc);\n    break;\n  case BC_TDUP:\n    rc = emitir(IRTG(IR_TDUP, IRT_TAB),\n\t\tlj_ir_ktab(J, gco2tab(proto_kgc(J->pt, ~(ptrdiff_t)rc))), 0);\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n    J->rbchash[(rc & (RBCHASH_SLOTS-1))].ref = tref_ref(rc);\n    setmref(J->rbchash[(rc & (RBCHASH_SLOTS-1))].pc, pc);\n    setgcref(J->rbchash[(rc & (RBCHASH_SLOTS-1))].pt, obj2gco(J->pt));\n#endif\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_ITERC:\n    J->base[ra] = getslot(J, ra-3-LJ_FR2);\n    J->base[ra+1] = getslot(J, ra-2-LJ_FR2);\n    J->base[ra+2] = getslot(J, ra-1-LJ_FR2);\n    { /* Do the actual copy now because lj_record_call needs the values. */\n      TValue *b = &J->L->base[ra];\n      copyTV(J->L, b, b-3-LJ_FR2);\n      copyTV(J->L, b+1, b-2-LJ_FR2);\n      copyTV(J->L, b+2, b-1-LJ_FR2);\n    }\n    lj_record_call(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  /* L->top is set to L->base+ra+rc+NARGS-1+1. See lj_dispatch_ins(). */\n  case BC_CALLM:\n    rc = (BCReg)(J->L->top - J->L->base) - ra - LJ_FR2;\n    /* fallthrough */\n  case BC_CALL:\n    lj_record_call(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  case BC_CALLMT:\n    rc = (BCReg)(J->L->top - J->L->base) - ra - LJ_FR2;\n    /* fallthrough */\n  case BC_CALLT:\n    lj_record_tailcall(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  case BC_VARG:\n    rec_varg(J, ra, (ptrdiff_t)rb-1);\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    /* L->top is set to L->base+ra+rc+NRESULTS-1, see lj_dispatch_ins(). */\n    rc = (BCReg)(J->L->top - J->L->base) - ra + 1;\n    /* fallthrough */\n  case BC_RET: case BC_RET0: case BC_RET1:\n#if LJ_HASPROFILE\n    rec_profile_ret(J);\n#endif\n    lj_record_ret(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORI:\n    if (rec_for(J, pc, 0) != LOOPEV_LEAVE)\n      J->loopref = J->cur.nins;\n    break;\n  case BC_JFORI:\n    lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL);\n    if (rec_for(J, pc, 0) != LOOPEV_LEAVE)  /* Link to existing loop. */\n      lj_record_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J]));\n    /* Continue tracing if the loop is not entered. */\n    break;\n\n  case BC_FORL:\n    rec_loop_interp(J, pc, rec_for(J, pc+((ptrdiff_t)rc-BCBIAS_J), 1));\n    break;\n  case BC_ITERL:\n    rec_loop_interp(J, pc, rec_iterl(J, *pc));\n    break;\n  case BC_LOOP:\n    rec_loop_interp(J, pc, rec_loop(J, ra));\n    break;\n\n  case BC_JFORL:\n    rec_loop_jit(J, rc, rec_for(J, pc+bc_j(traceref(J, rc)->startins), 1));\n    break;\n  case BC_JITERL:\n    rec_loop_jit(J, rc, rec_iterl(J, traceref(J, rc)->startins));\n    break;\n  case BC_JLOOP:\n    rec_loop_jit(J, rc, rec_loop(J, ra));\n    break;\n\n  case BC_IFORL:\n  case BC_IITERL:\n  case BC_ILOOP:\n  case BC_IFUNCF:\n  case BC_IFUNCV:\n    lj_trace_err(J, LJ_TRERR_BLACKL);\n    break;\n\n  case BC_JMP:\n    if (ra < J->maxslot)\n      J->maxslot = ra;  /* Shrink used slots. */\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    rec_func_lua(J);\n    break;\n  case BC_JFUNCF:\n    rec_func_jit(J, rc);\n    break;\n\n  case BC_FUNCV:\n    rec_func_vararg(J);\n    rec_func_lua(J);\n    break;\n  case BC_JFUNCV:\n    lua_assert(0);  /* Cannot happen. No hotcall counting for varag funcs. */\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    lj_ffrecord_func(J);\n    break;\n\n  default:\n    if (op >= BC__MAX) {\n      lj_ffrecord_func(J);\n      break;\n    }\n    /* fallthrough */\n  case BC_ITERN:\n  case BC_ISNEXT:\n  case BC_UCLO:\n  case BC_FNEW:\n    setintV(&J->errinfo, (int32_t)op);\n    lj_trace_err_info(J, LJ_TRERR_NYIBC);\n    break;\n  }\n\n  /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */\n  if (bcmode_a(op) == BCMdst && rc) {\n    J->base[ra] = rc;\n    if (ra >= J->maxslot) J->maxslot = ra+1;\n  }\n\n#undef rav\n#undef rbv\n#undef rcv\n\n  /* Limit the number of recorded IR instructions. */\n  if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord])\n    lj_trace_err(J, LJ_TRERR_TRACEOV);\n}\n\n/* -- Recording setup ----------------------------------------------------- */\n\n/* Setup recording for a root trace started by a hot loop. */\nstatic const BCIns *rec_setup_root(jit_State *J)\n{\n  /* Determine the next PC and the bytecode range for the loop. */\n  const BCIns *pcj, *pc = J->pc;\n  BCIns ins = *pc;\n  BCReg ra = bc_a(ins);\n  switch (bc_op(ins)) {\n  case BC_FORL:\n    J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    pc += 1+bc_j(ins);\n    J->bc_min = pc;\n    break;\n  case BC_ITERL:\n    lua_assert(bc_op(pc[-1]) == BC_ITERC);\n    J->maxslot = ra + bc_b(pc[-1]) - 1;\n    J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    pc += 1+bc_j(ins);\n    lua_assert(bc_op(pc[-1]) == BC_JMP);\n    J->bc_min = pc;\n    break;\n  case BC_LOOP:\n    /* Only check BC range for real loops, but not for \"repeat until true\". */\n    pcj = pc + bc_j(ins);\n    ins = *pcj;\n    if (bc_op(ins) == BC_JMP && bc_j(ins) < 0) {\n      J->bc_min = pcj+1 + bc_j(ins);\n      J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    }\n    J->maxslot = ra;\n    pc++;\n    break;\n  case BC_RET:\n  case BC_RET0:\n  case BC_RET1:\n    /* No bytecode range check for down-recursive root traces. */\n    J->maxslot = ra + bc_d(ins) - 1;\n    break;\n  case BC_FUNCF:\n    /* No bytecode range check for root traces started by a hot call. */\n    J->maxslot = J->pt->numparams;\n    pc++;\n    break;\n  case BC_CALLM:\n  case BC_CALL:\n  case BC_ITERC:\n    /* No bytecode range check for stitched traces. */\n    pc++;\n    break;\n  default:\n    lua_assert(0);\n    break;\n  }\n  return pc;\n}\n\n/* Setup for recording a new trace. */\nvoid lj_record_setup(jit_State *J)\n{\n  uint32_t i;\n\n  /* Initialize state related to current trace. */\n  memset(J->slot, 0, sizeof(J->slot));\n  memset(J->chain, 0, sizeof(J->chain));\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  memset(J->rbchash, 0, sizeof(J->rbchash));\n#endif\n  memset(J->bpropcache, 0, sizeof(J->bpropcache));\n  J->scev.idx = REF_NIL;\n  setmref(J->scev.pc, NULL);\n\n  J->baseslot = 1;  /* Invoking function is at base[-1]. */\n  J->base = J->slot + J->baseslot;\n  J->maxslot = 0;\n  J->framedepth = 0;\n  J->retdepth = 0;\n\n  J->instunroll = J->param[JIT_P_instunroll];\n  J->loopunroll = J->param[JIT_P_loopunroll];\n  J->tailcalled = 0;\n  J->loopref = 0;\n\n  J->bc_min = NULL;  /* Means no limit. */\n  J->bc_extent = ~(MSize)0;\n\n  /* Emit instructions for fixed references. Also triggers initial IR alloc. */\n  emitir_raw(IRT(IR_BASE, IRT_P32), J->parent, J->exitno);\n  for (i = 0; i <= 2; i++) {\n    IRIns *ir = IR(REF_NIL-i);\n    ir->i = 0;\n    ir->t.irt = (uint8_t)(IRT_NIL+i);\n    ir->o = IR_KPRI;\n    ir->prev = 0;\n  }\n  J->cur.nk = REF_TRUE;\n\n  J->startpc = J->pc;\n  setmref(J->cur.startpc, J->pc);\n  if (J->parent) {  /* Side trace. */\n    GCtrace *T = traceref(J, J->parent);\n    TraceNo root = T->root ? T->root : J->parent;\n    J->cur.root = (uint16_t)root;\n    J->cur.startins = BCINS_AD(BC_JMP, 0, 0);\n    /* Check whether we could at least potentially form an extra loop. */\n    if (J->exitno == 0 && T->snap[0].nent == 0) {\n      /* We can narrow a FORL for some side traces, too. */\n      if (J->pc > proto_bc(J->pt) && bc_op(J->pc[-1]) == BC_JFORI &&\n\t  bc_d(J->pc[bc_j(J->pc[-1])-1]) == root) {\n\tlj_snap_add(J);\n\trec_for_loop(J, J->pc-1, &J->scev, 1);\n\tgoto sidecheck;\n      }\n    } else {\n      J->startpc = NULL;  /* Prevent forming an extra loop. */\n    }\n    lj_snap_replay(J, T);\n  sidecheck:\n    if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] ||\n\tT->snap[J->exitno].count >= J->param[JIT_P_hotexit] +\n\t\t\t\t    J->param[JIT_P_tryside]) {\n      lj_record_stop(J, LJ_TRLINK_INTERP, 0);\n    }\n  } else {  /* Root trace. */\n    J->cur.root = 0;\n    J->cur.startins = *J->pc;\n    J->pc = rec_setup_root(J);\n    /* Note: the loop instruction itself is recorded at the end and not\n    ** at the start! So snapshot #0 needs to point to the *next* instruction.\n    */\n    lj_snap_add(J);\n    if (bc_op(J->cur.startins) == BC_FORL)\n      rec_for_loop(J, J->pc-1, &J->scev, 1);\n    else if (bc_op(J->cur.startins) == BC_ITERC)\n      J->startpc = NULL;\n    if (1 + J->pt->framesize >= LJ_MAX_JSLOTS)\n      lj_trace_err(J, LJ_TRERR_STACKOV);\n  }\n#if LJ_HASPROFILE\n  J->prev_pt = NULL;\n  J->prev_line = -1;\n#endif\n#ifdef LUAJIT_ENABLE_CHECKHOOK\n  /* Regularly check for instruction/line hooks from compiled code and\n  ** exit to the interpreter if the hooks are set.\n  **\n  ** This is a compile-time option and disabled by default, since the\n  ** hook checks may be quite expensive in tight loops.\n  **\n  ** Note this is only useful if hooks are *not* set most of the time.\n  ** Use this only if you want to *asynchronously* interrupt the execution.\n  **\n  ** You can set the instruction hook via lua_sethook() with a count of 1\n  ** from a signal handler or another native thread. Please have a look\n  ** at the first few functions in luajit.c for an example (Ctrl-C handler).\n  */\n  {\n    TRef tr = emitir(IRT(IR_XLOAD, IRT_U8),\n\t\t     lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE);\n    tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT)));\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));\n  }\n#endif\n}\n\n#undef IR\n#undef emitir_raw\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_record.h",
    "content": "/*\n** Trace recorder (bytecode -> SSA IR).\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_RECORD_H\n#define _LJ_RECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* Context for recording an indexed load/store. */\ntypedef struct RecordIndex {\n  TValue tabv;\t\t/* Runtime value of table (or indexed object). */\n  TValue keyv;\t\t/* Runtime value of key. */\n  TValue valv;\t\t/* Runtime value of stored value. */\n  TValue mobjv;\t\t/* Runtime value of metamethod object. */\n  GCtab *mtv;\t\t/* Runtime value of metatable object. */\n  cTValue *oldv;\t/* Runtime value of previously stored value. */\n  TRef tab;\t\t/* Table (or indexed object) reference. */\n  TRef key;\t\t/* Key reference. */\n  TRef val;\t\t/* Value reference for a store or 0 for a load. */\n  TRef mt;\t\t/* Metatable reference. */\n  TRef mobj;\t\t/* Metamethod object reference. */\n  int idxchain;\t\t/* Index indirections left or 0 for raw lookup. */\n} RecordIndex;\n\nLJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,\n\t\t\t     cTValue *av, cTValue *bv);\nLJ_FUNC void lj_record_stop(jit_State *J, TraceLink linktype, TraceNo lnk);\nLJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);\n\nLJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);\nLJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);\nLJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);\n\nLJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);\nLJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);\n\nLJ_FUNC void lj_record_ins(jit_State *J);\nLJ_FUNC void lj_record_setup(jit_State *J);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_snap.c",
    "content": "/*\n** Snapshot handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_snap_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_target.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#endif\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Snapshot buffer allocation ------------------------------------------ */\n\n/* Grow snapshot buffer. */\nvoid lj_snap_grow_buf_(jit_State *J, MSize need)\n{\n  MSize maxsnap = (MSize)J->param[JIT_P_maxsnap];\n  if (need > maxsnap)\n    lj_trace_err(J, LJ_TRERR_SNAPOV);\n  lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot);\n  J->cur.snap = J->snapbuf;\n}\n\n/* Grow snapshot map buffer. */\nvoid lj_snap_grow_map_(jit_State *J, MSize need)\n{\n  if (need < 2*J->sizesnapmap)\n    need = 2*J->sizesnapmap;\n  else if (need < 64)\n    need = 64;\n  J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,\n\t\t    J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry));\n  J->cur.snapmap = J->snapmapbuf;\n  J->sizesnapmap = need;\n}\n\n/* -- Snapshot generation ------------------------------------------------- */\n\n/* Add all modified slots to the snapshot. */\nstatic MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots)\n{\n  IRRef retf = J->chain[IR_RETF];  /* Limits SLOAD restore elimination. */\n  BCReg s;\n  MSize n = 0;\n  for (s = 0; s < nslots; s++) {\n    TRef tr = J->slot[s];\n    IRRef ref = tref_ref(tr);\n    if (ref) {\n      SnapEntry sn = SNAP_TR(s, tr);\n      IRIns *ir = &J->cur.ir[ref];\n      if (!(sn & (SNAP_CONT|SNAP_FRAME)) &&\n\t  ir->o == IR_SLOAD && ir->op1 == s && ref > retf) {\n\t/* No need to snapshot unmodified non-inherited slots. */\n\tif (!(ir->op2 & IRSLOAD_INHERIT))\n\t  continue;\n\t/* No need to restore readonly slots and unmodified non-parent slots. */\n\tif (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) &&\n\t    (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT)\n\t  sn |= SNAP_NORESTORE;\n      }\n      if (LJ_SOFTFP && irt_isnum(ir->t))\n\tsn |= SNAP_SOFTFPNUM;\n      map[n++] = sn;\n    }\n  }\n  return n;\n}\n\n/* Add frame links at the end of the snapshot. */\nstatic BCReg snapshot_framelinks(jit_State *J, SnapEntry *map)\n{\n  cTValue *frame = J->L->base - 1;\n  cTValue *lim = J->L->base - J->baseslot;\n  GCfunc *fn = frame_func(frame);\n  cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top;\n  MSize f = 0;\n  lua_assert(!LJ_FR2);  /* TODO_FR2: store 64 bit PCs. */\n  map[f++] = SNAP_MKPC(J->pc);  /* The current PC is always the first entry. */\n  while (frame > lim) {  /* Backwards traversal of all frames above base. */\n    if (frame_islua(frame)) {\n      map[f++] = SNAP_MKPC(frame_pc(frame));\n      frame = frame_prevl(frame);\n    } else if (frame_iscont(frame)) {\n      map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));\n      map[f++] = SNAP_MKPC(frame_contpc(frame));\n      frame = frame_prevd(frame);\n    } else {\n      lua_assert(!frame_isc(frame));\n      map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));\n      frame = frame_prevd(frame);\n      continue;\n    }\n    if (frame + funcproto(frame_func(frame))->framesize > ftop)\n      ftop = frame + funcproto(frame_func(frame))->framesize;\n  }\n  lua_assert(f == (MSize)(1 + J->framedepth));\n  return (BCReg)(ftop - lim);\n}\n\n/* Take a snapshot of the current stack. */\nstatic void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)\n{\n  BCReg nslots = J->baseslot + J->maxslot;\n  MSize nent;\n  SnapEntry *p;\n  /* Conservative estimate. */\n  lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1);\n  p = &J->cur.snapmap[nsnapmap];\n  nent = snapshot_slots(J, p, nslots);\n  snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent);\n  snap->mapofs = (uint16_t)nsnapmap;\n  snap->ref = (IRRef1)J->cur.nins;\n  snap->nent = (uint8_t)nent;\n  snap->nslots = (uint8_t)nslots;\n  snap->count = 0;\n  J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth);\n}\n\n/* Add or merge a snapshot. */\nvoid lj_snap_add(jit_State *J)\n{\n  MSize nsnap = J->cur.nsnap;\n  MSize nsnapmap = J->cur.nsnapmap;\n  /* Merge if no ins. inbetween or if requested and no guard inbetween. */\n  if ((nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins) ||\n      (J->mergesnap && !irt_isguard(J->guardemit))) {\n    if (nsnap == 1) {  /* But preserve snap #0 PC. */\n      emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);\n      goto nomerge;\n    }\n    nsnapmap = J->cur.snap[--nsnap].mapofs;\n  } else {\n  nomerge:\n    lj_snap_grow_buf(J, nsnap+1);\n    J->cur.nsnap = (uint16_t)(nsnap+1);\n  }\n  J->mergesnap = 0;\n  J->guardemit.irt = 0;\n  snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap);\n}\n\n/* -- Snapshot modification ----------------------------------------------- */\n\n#define SNAP_USEDEF_SLOTS\t(LJ_MAX_JSLOTS+LJ_STACK_EXTRA)\n\n/* Find unused slots with reaching-definitions bytecode data-flow analysis. */\nstatic BCReg snap_usedef(jit_State *J, uint8_t *udf,\n\t\t\t const BCIns *pc, BCReg maxslot)\n{\n  BCReg s;\n  GCobj *o;\n\n  if (maxslot == 0) return 0;\n#ifdef LUAJIT_USE_VALGRIND\n  /* Avoid errors for harmless reads beyond maxslot. */\n  memset(udf, 1, SNAP_USEDEF_SLOTS);\n#else\n  memset(udf, 1, maxslot);\n#endif\n\n  /* Treat open upvalues as used. */\n  o = gcref(J->L->openupval);\n  while (o) {\n    if (uvval(gco2uv(o)) < J->L->base) break;\n    udf[uvval(gco2uv(o)) - J->L->base] = 0;\n    o = gcref(o->gch.nextgc);\n  }\n\n#define USE_SLOT(s)\t\tudf[(s)] &= ~1\n#define DEF_SLOT(s)\t\tudf[(s)] *= 3\n\n  /* Scan through following bytecode and check for uses/defs. */\n  lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);\n  for (;;) {\n    BCIns ins = *pc++;\n    BCOp op = bc_op(ins);\n    switch (bcmode_b(op)) {\n    case BCMvar: USE_SLOT(bc_b(ins)); break;\n    default: break;\n    }\n    switch (bcmode_c(op)) {\n    case BCMvar: USE_SLOT(bc_c(ins)); break;\n    case BCMrbase:\n      lua_assert(op == BC_CAT);\n      for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s);\n      for (; s < maxslot; s++) DEF_SLOT(s);\n      break;\n    case BCMjump:\n    handle_jump: {\n      BCReg minslot = bc_a(ins);\n      if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT;\n      else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1;\n      else if (op == BC_UCLO) { pc += bc_j(ins); break; }\n      for (s = minslot; s < maxslot; s++) DEF_SLOT(s);\n      return minslot < maxslot ? minslot : maxslot;\n      }\n    case BCMlit:\n      if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {\n\tgoto handle_jump;\n      } else if (bc_isret(op)) {\n\tBCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1);\n\tfor (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);\n\tfor (; s < top; s++) USE_SLOT(s);\n\tfor (; s < maxslot; s++) DEF_SLOT(s);\n\treturn 0;\n      }\n      break;\n    case BCMfunc: return maxslot;  /* NYI: will abort, anyway. */\n    default: break;\n    }\n    switch (bcmode_a(op)) {\n    case BCMvar: USE_SLOT(bc_a(ins)); break;\n    case BCMdst:\n       if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins));\n       break;\n    case BCMbase:\n      if (op >= BC_CALLM && op <= BC_VARG) {\n\tBCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ?\n\t\t    maxslot : (bc_a(ins) + bc_c(ins)+LJ_FR2);\n\tif (LJ_FR2) DEF_SLOT(bc_a(ins)+1);\n\ts = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0);\n\tfor (; s < top; s++) USE_SLOT(s);\n\tfor (; s < maxslot; s++) DEF_SLOT(s);\n\tif (op == BC_CALLT || op == BC_CALLMT) {\n\t  for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);\n\t  return 0;\n\t}\n      } else if (op == BC_KNIL) {\n\tfor (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s);\n      } else if (op == BC_TSETM) {\n\tfor (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s);\n      }\n      break;\n    default: break;\n    }\n    lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);\n  }\n\n#undef USE_SLOT\n#undef DEF_SLOT\n\n  return 0;  /* unreachable */\n}\n\n/* Purge dead slots before the next snapshot. */\nvoid lj_snap_purge(jit_State *J)\n{\n  uint8_t udf[SNAP_USEDEF_SLOTS];\n  BCReg maxslot = J->maxslot;\n  BCReg s = snap_usedef(J, udf, J->pc, maxslot);\n  for (; s < maxslot; s++)\n    if (udf[s] != 0)\n      J->base[s] = 0;  /* Purge dead slots. */\n}\n\n/* Shrink last snapshot. */\nvoid lj_snap_shrink(jit_State *J)\n{\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, m, nlim, nent = snap->nent;\n  uint8_t udf[SNAP_USEDEF_SLOTS];\n  BCReg maxslot = J->maxslot;\n  BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot);\n  BCReg baseslot = J->baseslot;\n  maxslot += baseslot;\n  minslot += baseslot;\n  snap->nslots = (uint8_t)maxslot;\n  for (n = m = 0; n < nent; n++) {  /* Remove unused slots from snapshot. */\n    BCReg s = snap_slot(map[n]);\n    if (s < minslot || (s < maxslot && udf[s-baseslot] == 0))\n      map[m++] = map[n];  /* Only copy used slots. */\n  }\n  snap->nent = (uint8_t)m;\n  nlim = J->cur.nsnapmap - snap->mapofs - 1;\n  while (n <= nlim) map[m++] = map[n++];  /* Move PC + frame links down. */\n  J->cur.nsnapmap = (uint16_t)(snap->mapofs + m);  /* Free up space in map. */\n}\n\n/* -- Snapshot access ----------------------------------------------------- */\n\n/* Initialize a Bloom Filter with all renamed refs.\n** There are very few renames (often none), so the filter has\n** very few bits set. This makes it suitable for negative filtering.\n*/\nstatic BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim)\n{\n  BloomFilter rfilt = 0;\n  IRIns *ir;\n  for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)\n    if (ir->op2 <= lim)\n      bloomset(rfilt, ir->op1);\n  return rfilt;\n}\n\n/* Process matching renames to find the original RegSP. */\nstatic RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs)\n{\n  IRIns *ir;\n  for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)\n    if (ir->op1 == ref && ir->op2 <= lim)\n      rs = ir->prev;\n  return rs;\n}\n\n/* Copy RegSP from parent snapshot to the parent links of the IR. */\nIRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir)\n{\n  SnapShot *snap = &T->snap[snapno];\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n  BloomFilter rfilt = snap_renamefilter(T, snapno);\n  MSize n = 0;\n  IRRef ref = 0;\n  for ( ; ; ir++) {\n    uint32_t rs;\n    if (ir->o == IR_SLOAD) {\n      if (!(ir->op2 & IRSLOAD_PARENT)) break;\n      for ( ; ; n++) {\n\tlua_assert(n < snap->nent);\n\tif (snap_slot(map[n]) == ir->op1) {\n\t  ref = snap_ref(map[n++]);\n\t  break;\n\t}\n      }\n    } else if (LJ_SOFTFP && ir->o == IR_HIOP) {\n      ref++;\n    } else if (ir->o == IR_PVAL) {\n      ref = ir->op1 + REF_BIAS;\n    } else {\n      break;\n    }\n    rs = T->ir[ref].prev;\n    if (bloomtest(rfilt, ref))\n      rs = snap_renameref(T, snapno, ref, rs);\n    ir->prev = (uint16_t)rs;\n    lua_assert(regsp_used(rs));\n  }\n  return ir;\n}\n\n/* -- Snapshot replay ----------------------------------------------------- */\n\n/* Replay constant from parent trace. */\nstatic TRef snap_replay_const(jit_State *J, IRIns *ir)\n{\n  /* Only have to deal with constants that can occur in stack slots. */\n  switch ((IROp)ir->o) {\n  case IR_KPRI: return TREF_PRI(irt_type(ir->t));\n  case IR_KINT: return lj_ir_kint(J, ir->i);\n  case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t));\n  case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir));\n  case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir));\n  case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir));  /* Continuation. */\n  default: lua_assert(0); return TREF_NIL; break;\n  }\n}\n\n/* De-duplicate parent reference. */\nstatic TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref)\n{\n  MSize j;\n  for (j = 0; j < nmax; j++)\n    if (snap_ref(map[j]) == ref)\n      return J->slot[snap_slot(map[j])] & ~(SNAP_CONT|SNAP_FRAME);\n  return 0;\n}\n\n/* Emit parent reference with de-duplication. */\nstatic TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax,\n\t\t      BloomFilter seen, IRRef ref)\n{\n  IRIns *ir = &T->ir[ref];\n  TRef tr;\n  if (irref_isk(ref))\n    tr = snap_replay_const(J, ir);\n  else if (!regsp_used(ir->prev))\n    tr = 0;\n  else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0)\n    tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0);\n  return tr;\n}\n\n/* Check whether a sunk store corresponds to an allocation. Slow path. */\nstatic int snap_sunk_store2(GCtrace *T, IRIns *ira, IRIns *irs)\n{\n  if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n      irs->o == IR_FSTORE || irs->o == IR_XSTORE) {\n    IRIns *irk = &T->ir[irs->op1];\n    if (irk->o == IR_AREF || irk->o == IR_HREFK)\n      irk = &T->ir[irk->op1];\n    return (&T->ir[irk->op1] == ira);\n  }\n  return 0;\n}\n\n/* Check whether a sunk store corresponds to an allocation. Fast path. */\nstatic LJ_AINLINE int snap_sunk_store(GCtrace *T, IRIns *ira, IRIns *irs)\n{\n  if (irs->s != 255)\n    return (ira + irs->s == irs);  /* Fast check. */\n  return snap_sunk_store2(T, ira, irs);\n}\n\n/* Replay snapshot state to setup side trace. */\nvoid lj_snap_replay(jit_State *J, GCtrace *T)\n{\n  SnapShot *snap = &T->snap[J->exitno];\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  BloomFilter seen = 0;\n  int pass23 = 0;\n  J->framedepth = 0;\n  /* Emit IR for slots inherited from parent snapshot. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = &T->ir[ref];\n    TRef tr;\n    /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */\n    if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0)\n      goto setslot;\n    bloomset(seen, ref);\n    if (irref_isk(ref)) {\n      tr = snap_replay_const(J, ir);\n    } else if (!regsp_used(ir->prev)) {\n      pass23 = 1;\n      lua_assert(s != 0);\n      tr = s;\n    } else {\n      IRType t = irt_type(ir->t);\n      uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT;\n      if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM;\n      if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY);\n      tr = emitir_raw(IRT(IR_SLOAD, t), s, mode);\n    }\n  setslot:\n    J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME));  /* Same as TREF_* flags. */\n    J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s);\n    if ((sn & SNAP_FRAME))\n      J->baseslot = s+1;\n  }\n  if (pass23) {\n    IRIns *irlast = &T->ir[snap->ref];\n    pass23 = 0;\n    /* Emit dependent PVALs. */\n    for (n = 0; n < nent; n++) {\n      SnapEntry sn = map[n];\n      IRRef refp = snap_ref(sn);\n      IRIns *ir = &T->ir[refp];\n      if (regsp_reg(ir->r) == RID_SUNK) {\n\tif (J->slot[snap_slot(sn)] != snap_slot(sn)) continue;\n\tpass23 = 1;\n\tlua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||\n\t\t   ir->o == IR_CNEW || ir->o == IR_CNEWI);\n\tif (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1);\n\tif (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2);\n\tif (LJ_HASFFI && ir->o == IR_CNEWI) {\n\t  if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP)\n\t    snap_pref(J, T, map, nent, seen, (ir+1)->op2);\n\t} else {\n\t  IRIns *irs;\n\t  for (irs = ir+1; irs < irlast; irs++)\n\t    if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t      if (snap_pref(J, T, map, nent, seen, irs->op2) == 0)\n\t\tsnap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1);\n\t      else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&\n\t\t       irs+1 < irlast && (irs+1)->o == IR_HIOP)\n\t\tsnap_pref(J, T, map, nent, seen, (irs+1)->op2);\n\t    }\n\t}\n      } else if (!irref_isk(refp) && !regsp_used(ir->prev)) {\n\tlua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);\n\tJ->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1);\n      }\n    }\n    /* Replay sunk instructions. */\n    for (n = 0; pass23 && n < nent; n++) {\n      SnapEntry sn = map[n];\n      IRRef refp = snap_ref(sn);\n      IRIns *ir = &T->ir[refp];\n      if (regsp_reg(ir->r) == RID_SUNK) {\n\tTRef op1, op2;\n\tif (J->slot[snap_slot(sn)] != snap_slot(sn)) {  /* De-dup allocs. */\n\t  J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]];\n\t  continue;\n\t}\n\top1 = ir->op1;\n\tif (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1);\n\top2 = ir->op2;\n\tif (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2);\n\tif (LJ_HASFFI && ir->o == IR_CNEWI) {\n\t  if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) {\n\t    lj_needsplit(J);  /* Emit joining HIOP. */\n\t    op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2,\n\t\t\t     snap_pref(J, T, map, nent, seen, (ir+1)->op2));\n\t  }\n\t  J->slot[snap_slot(sn)] = emitir(ir->ot & ~(IRT_MARK|IRT_ISPHI), op1, op2);\n\t} else {\n\t  IRIns *irs;\n\t  TRef tr = emitir(ir->ot, op1, op2);\n\t  J->slot[snap_slot(sn)] = tr;\n\t  for (irs = ir+1; irs < irlast; irs++)\n\t    if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t      IRIns *irr = &T->ir[irs->op1];\n\t      TRef val, key = irr->op2, tmp = tr;\n\t      if (irr->o != IR_FREF) {\n\t\tIRIns *irk = &T->ir[key];\n\t\tif (irr->o == IR_HREFK)\n\t\t  key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]),\n\t\t\t\t    irk->op2);\n\t\telse\n\t\t  key = snap_replay_const(J, irk);\n\t\tif (irr->o == IR_HREFK || irr->o == IR_AREF) {\n\t\t  IRIns *irf = &T->ir[irr->op1];\n\t\t  tmp = emitir(irf->ot, tmp, irf->op2);\n\t\t}\n\t      }\n\t      tmp = emitir(irr->ot, tmp, key);\n\t      val = snap_pref(J, T, map, nent, seen, irs->op2);\n\t      if (val == 0) {\n\t\tIRIns *irc = &T->ir[irs->op2];\n\t\tlua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT);\n\t\tval = snap_pref(J, T, map, nent, seen, irc->op1);\n\t\tval = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);\n\t      } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&\n\t\t\t irs+1 < irlast && (irs+1)->o == IR_HIOP) {\n\t\tIRType t = IRT_I64;\n\t\tif (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP)\n\t\t  t = IRT_NUM;\n\t\tlj_needsplit(J);\n\t\tif (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) {\n\t\t  uint64_t k = (uint32_t)T->ir[irs->op2].i +\n\t\t\t       ((uint64_t)T->ir[(irs+1)->op2].i << 32);\n\t\t  val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM,\n\t\t\t\t  lj_ir_k64_find(J, k));\n\t\t} else {\n\t\t  val = emitir_raw(IRT(IR_HIOP, t), val,\n\t\t\t  snap_pref(J, T, map, nent, seen, (irs+1)->op2));\n\t\t}\n\t\ttmp = emitir(IRT(irs->o, t), tmp, val);\n\t\tcontinue;\n\t      }\n\t      tmp = emitir(irs->ot, tmp, val);\n\t    } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) {\n\t      emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n\t    }\n\t}\n      }\n    }\n  }\n  J->base = J->slot + J->baseslot;\n  J->maxslot = snap->nslots - J->baseslot;\n  lj_snap_add(J);\n  if (pass23)  /* Need explicit GC step _after_ initial snapshot. */\n    emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0);\n}\n\n/* -- Snapshot restore ---------------------------------------------------- */\n\nstatic void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\tSnapNo snapno, BloomFilter rfilt,\n\t\t\tIRIns *ir, TValue *o);\n\n/* Restore a value from the trace exit state. */\nstatic void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\t    SnapNo snapno, BloomFilter rfilt,\n\t\t\t    IRRef ref, TValue *o)\n{\n  IRIns *ir = &T->ir[ref];\n  IRType1 t = ir->t;\n  RegSP rs = ir->prev;\n  if (irref_isk(ref)) {  /* Restore constant slot. */\n    lj_ir_kvalue(J->L, o, ir);\n    return;\n  }\n  if (LJ_UNLIKELY(bloomtest(rfilt, ref)))\n    rs = snap_renameref(T, snapno, ref, rs);\n  lua_assert(!LJ_GC64);  /* TODO_GC64: handle 64 bit references. */\n  if (ra_hasspill(regsp_spill(rs))) {  /* Restore from spill slot. */\n    int32_t *sps = &ex->spill[regsp_spill(rs)];\n    if (irt_isinteger(t)) {\n      setintV(o, *sps);\n#if !LJ_SOFTFP\n    } else if (irt_isnum(t)) {\n      o->u64 = *(uint64_t *)sps;\n#endif\n    } else if (LJ_64 && irt_islightud(t)) {\n      /* 64 bit lightuserdata which may escape already has the tag bits. */\n      o->u64 = *(uint64_t *)sps;\n    } else {\n      lua_assert(!irt_ispri(t));  /* PRI refs never have a spill slot. */\n      setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t));\n    }\n  } else {  /* Restore from register. */\n    Reg r = regsp_reg(rs);\n    if (ra_noreg(r)) {\n      lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);\n      snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o);\n      if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o));\n      return;\n    } else if (irt_isinteger(t)) {\n      setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);\n#if !LJ_SOFTFP\n    } else if (irt_isnum(t)) {\n      setnumV(o, ex->fpr[r-RID_MIN_FPR]);\n#endif\n    } else if (LJ_64 && irt_is64(t)) {\n      /* 64 bit values that already have the tag bits. */\n      o->u64 = ex->gpr[r-RID_MIN_GPR];\n    } else if (irt_ispri(t)) {\n      setpriV(o, irt_toitype(t));\n    } else {\n      setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t));\n    }\n  }\n}\n\n#if LJ_HASFFI\n/* Restore raw data from the trace exit state. */\nstatic void snap_restoredata(GCtrace *T, ExitState *ex,\n\t\t\t     SnapNo snapno, BloomFilter rfilt,\n\t\t\t     IRRef ref, void *dst, CTSize sz)\n{\n  IRIns *ir = &T->ir[ref];\n  RegSP rs = ir->prev;\n  int32_t *src;\n  uint64_t tmp;\n  if (irref_isk(ref)) {\n    if (ir->o == IR_KNUM || ir->o == IR_KINT64) {\n      src = mref(ir->ptr, int32_t);\n    } else if (sz == 8) {\n      tmp = (uint64_t)(uint32_t)ir->i;\n      src = (int32_t *)&tmp;\n    } else {\n      src = &ir->i;\n    }\n  } else {\n    if (LJ_UNLIKELY(bloomtest(rfilt, ref)))\n      rs = snap_renameref(T, snapno, ref, rs);\n    if (ra_hasspill(regsp_spill(rs))) {\n      src = &ex->spill[regsp_spill(rs)];\n      if (sz == 8 && !irt_is64(ir->t)) {\n\ttmp = (uint64_t)(uint32_t)*src;\n\tsrc = (int32_t *)&tmp;\n      }\n    } else {\n      Reg r = regsp_reg(rs);\n      if (ra_noreg(r)) {\n\t/* Note: this assumes CNEWI is never used for SOFTFP split numbers. */\n\tlua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);\n\tsnap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4);\n\t*(lua_Number *)dst = (lua_Number)*(int32_t *)dst;\n\treturn;\n      }\n      src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];\n#if !LJ_SOFTFP\n      if (r >= RID_MAX_GPR) {\n\tsrc = (int32_t *)&ex->fpr[r-RID_MIN_FPR];\n#if LJ_TARGET_PPC\n\tif (sz == 4) {  /* PPC FPRs are always doubles. */\n\t  *(float *)dst = (float)*(double *)src;\n\t  return;\n\t}\n#else\n\tif (LJ_BE && sz == 4) src++;\n#endif\n      }\n#endif\n    }\n  }\n  lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8);\n  if (sz == 4) *(int32_t *)dst = *src;\n  else if (sz == 8) *(int64_t *)dst = *(int64_t *)src;\n  else if (sz == 1) *(int8_t *)dst = (int8_t)*src;\n  else *(int16_t *)dst = (int16_t)*src;\n}\n#endif\n\n/* Unsink allocation from the trace exit state. Unsink sunk stores. */\nstatic void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\tSnapNo snapno, BloomFilter rfilt,\n\t\t\tIRIns *ir, TValue *o)\n{\n  lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||\n\t     ir->o == IR_CNEW || ir->o == IR_CNEWI);\n#if LJ_HASFFI\n  if (ir->o == IR_CNEW || ir->o == IR_CNEWI) {\n    CTState *cts = ctype_cts(J->L);\n    CTypeID id = (CTypeID)T->ir[ir->op1].i;\n    CTSize sz;\n    CTInfo info = lj_ctype_info(cts, id, &sz);\n    GCcdata *cd = lj_cdata_newx(cts, id, sz, info);\n    setcdataV(J->L, o, cd);\n    if (ir->o == IR_CNEWI) {\n      uint8_t *p = (uint8_t *)cdataptr(cd);\n      lua_assert(sz == 4 || sz == 8);\n      if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) {\n\tsnap_restoredata(T, ex, snapno, rfilt, (ir+1)->op2, LJ_LE?p+4:p, 4);\n\tif (LJ_BE) p += 4;\n\tsz = 4;\n      }\n      snap_restoredata(T, ex, snapno, rfilt, ir->op2, p, sz);\n    } else {\n      IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref];\n      for (irs = ir+1; irs < irlast; irs++)\n\tif (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t  IRIns *iro = &T->ir[T->ir[irs->op1].op2];\n\t  uint8_t *p = (uint8_t *)cd;\n\t  CTSize szs;\n\t  lua_assert(irs->o == IR_XSTORE && T->ir[irs->op1].o == IR_ADD);\n\t  lua_assert(iro->o == IR_KINT || iro->o == IR_KINT64);\n\t  if (irt_is64(irs->t)) szs = 8;\n\t  else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1;\n\t  else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2;\n\t  else szs = 4;\n\t  if (LJ_64 && iro->o == IR_KINT64)\n\t    p += (int64_t)ir_k64(iro)->u64;\n\t  else\n\t    p += iro->i;\n\t  lua_assert(p >= (uint8_t *)cdataptr(cd) &&\n\t\t     p + szs <= (uint8_t *)cdataptr(cd) + sz);\n\t  if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {\n\t    lua_assert(szs == 4);\n\t    snap_restoredata(T, ex, snapno, rfilt, (irs+1)->op2, LJ_LE?p+4:p,4);\n\t    if (LJ_BE) p += 4;\n\t  }\n\t  snap_restoredata(T, ex, snapno, rfilt, irs->op2, p, szs);\n\t}\n    }\n  } else\n#endif\n  {\n    IRIns *irs, *irlast;\n    GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) :\n\t\t\t\t  lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1]));\n    settabV(J->L, o, t);\n    irlast = &T->ir[T->snap[snapno].ref];\n    for (irs = ir+1; irs < irlast; irs++)\n      if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\tIRIns *irk = &T->ir[irs->op1];\n\tTValue tmp, *val;\n\tlua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\t\t   irs->o == IR_FSTORE);\n\tif (irk->o == IR_FREF) {\n\t  lua_assert(irk->op2 == IRFL_TAB_META);\n\t  snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp);\n\t  /* NOBARRIER: The table is new (marked white). */\n\t  setgcref(t->metatable, obj2gco(tabV(&tmp)));\n\t} else {\n\t  irk = &T->ir[irk->op2];\n\t  if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1];\n\t  lj_ir_kvalue(J->L, &tmp, irk);\n\t  val = lj_tab_set(J->L, t, &tmp);\n\t  /* NOBARRIER: The table is new (marked white). */\n\t  snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val);\n\t  if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {\n\t    snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp);\n\t    val->u32.hi = tmp.u32.lo;\n\t  }\n\t}\n      }\n  }\n}\n\n/* Restore interpreter state from exit state with the help of a snapshot. */\nconst BCIns *lj_snap_restore(jit_State *J, void *exptr)\n{\n  ExitState *ex = (ExitState *)exptr;\n  SnapNo snapno = J->exitno;  /* For now, snapno == exitno. */\n  GCtrace *T = traceref(J, J->parent);\n  SnapShot *snap = &T->snap[snapno];\n  MSize n, nent = snap->nent;\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1];\n  ptrdiff_t ftsz0;\n  TValue *frame;\n  BloomFilter rfilt = snap_renamefilter(T, snapno);\n  const BCIns *pc = snap_pc(map[nent]);\n  lua_State *L = J->L;\n\n  /* Set interpreter PC to the next PC to get correct error messages. */\n  setcframe_pc(cframe_raw(L->cframe), pc+1);\n\n  /* Make sure the stack is big enough for the slots from the snapshot. */\n  if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) {\n    L->top = curr_topL(L);\n    lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize);\n  }\n\n  /* Fill stack slots with data from the registers and spill slots. */\n  frame = L->base-1;\n  ftsz0 = frame_ftsz(frame);  /* Preserve link to previous frame in slot #0. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    if (!(sn & SNAP_NORESTORE)) {\n      TValue *o = &frame[snap_slot(sn)];\n      IRRef ref = snap_ref(sn);\n      IRIns *ir = &T->ir[ref];\n      if (ir->r == RID_SUNK) {\n\tMSize j;\n\tfor (j = 0; j < n; j++)\n\t  if (snap_ref(map[j]) == ref) {  /* De-duplicate sunk allocations. */\n\t    copyTV(L, o, &frame[snap_slot(map[j])]);\n\t    goto dupslot;\n\t  }\n\tsnap_unsink(J, T, ex, snapno, rfilt, ir, o);\n      dupslot:\n\tcontinue;\n      }\n      snap_restoreval(J, T, ex, snapno, rfilt, ref, o);\n      if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) {\n\tTValue tmp;\n\tsnap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp);\n\to->u32.hi = tmp.u32.lo;\n      } else if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tlua_assert(!LJ_FR2);  /* TODO_FR2: store 64 bit PCs. */\n\t/* Overwrite tag with frame link. */\n\tsetframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0);\n\tL->base = o+1;\n      }\n    }\n  }\n  lua_assert(map + nent == flinks);\n\n  /* Compute current stack top. */\n  switch (bc_op(*pc)) {\n  default:\n    if (bc_op(*pc) < BC_FUNCF) {\n      L->top = curr_topL(L);\n      break;\n    }\n    /* fallthrough */\n  case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM:\n    L->top = frame + snap->nslots;\n    break;\n  }\n  return pc;\n}\n\n#undef emitir_raw\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_snap.h",
    "content": "/*\n** Snapshot handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_SNAP_H\n#define _LJ_SNAP_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\nLJ_FUNC void lj_snap_add(jit_State *J);\nLJ_FUNC void lj_snap_purge(jit_State *J);\nLJ_FUNC void lj_snap_shrink(jit_State *J);\nLJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir);\nLJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T);\nLJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr);\nLJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need);\nLJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need);\n\nstatic LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need)\n{\n  if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need);\n}\n\nstatic LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need)\n{\n  if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need);\n}\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_state.c",
    "content": "/*\n** State and stack handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_state_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_lex.h\"\n#include \"lj_alloc.h\"\n#include \"luajit.h\"\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Stack sizes. */\n#define LJ_STACK_MIN\tLUA_MINSTACK\t/* Min. stack size. */\n#define LJ_STACK_MAX\tLUAI_MAXSTACK\t/* Max. stack size. */\n#define LJ_STACK_START\t(2*LJ_STACK_MIN)\t/* Starting stack size. */\n#define LJ_STACK_MAXEX\t(LJ_STACK_MAX + 1 + LJ_STACK_EXTRA)\n\n/* Explanation of LJ_STACK_EXTRA:\n**\n** Calls to metamethods store their arguments beyond the current top\n** without checking for the stack limit. This avoids stack resizes which\n** would invalidate passed TValue pointers. The stack check is performed\n** later by the function header. This can safely resize the stack or raise\n** an error. Thus we need some extra slots beyond the current stack limit.\n**\n** Most metamethods need 4 slots above top (cont, mobj, arg1, arg2) plus\n** one extra slot if mobj is not a function. Only lj_meta_tset needs 5\n** slots above top, but then mobj is always a function. So we can get by\n** with 5 extra slots.\n** LJ_FR2: We need 2 more slots for the frame PC and the continuation PC.\n*/\n\n/* Resize stack slots and adjust pointers in state. */\nstatic void resizestack(lua_State *L, MSize n)\n{\n  TValue *st, *oldst = tvref(L->stack);\n  ptrdiff_t delta;\n  MSize oldsize = L->stacksize;\n  MSize realsize = n + 1 + LJ_STACK_EXTRA;\n  GCobj *up;\n  lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1);\n  st = (TValue *)lj_mem_realloc(L, tvref(L->stack),\n\t\t\t\t(MSize)(oldsize*sizeof(TValue)),\n\t\t\t\t(MSize)(realsize*sizeof(TValue)));\n  setmref(L->stack, st);\n  delta = (char *)st - (char *)oldst;\n  setmref(L->maxstack, st + n);\n  while (oldsize < realsize)  /* Clear new slots. */\n    setnilV(st + oldsize++);\n  L->stacksize = realsize;\n  if ((size_t)(mref(G(L)->jit_base, char) - (char *)oldst) < oldsize)\n    setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta);\n  L->base = (TValue *)((char *)L->base + delta);\n  L->top = (TValue *)((char *)L->top + delta);\n  for (up = gcref(L->openupval); up != NULL; up = gcnext(up))\n    setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta));\n}\n\n/* Relimit stack after error, in case the limit was overdrawn. */\nvoid lj_state_relimitstack(lua_State *L)\n{\n  if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1)\n    resizestack(L, LJ_STACK_MAX);\n}\n\n/* Try to shrink the stack (called from GC). */\nvoid lj_state_shrinkstack(lua_State *L, MSize used)\n{\n  if (L->stacksize > LJ_STACK_MAXEX)\n    return;  /* Avoid stack shrinking while handling stack overflow. */\n  if (4*used < L->stacksize &&\n      2*(LJ_STACK_START+LJ_STACK_EXTRA) < L->stacksize &&\n      /* Don't shrink stack of live trace. */\n      (tvref(G(L)->jit_base) == NULL || obj2gco(L) != gcref(G(L)->cur_L)))\n    resizestack(L, L->stacksize >> 1);\n}\n\n/* Try to grow stack. */\nvoid LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)\n{\n  MSize n;\n  if (L->stacksize > LJ_STACK_MAXEX)  /* Overflow while handling overflow? */\n    lj_err_throw(L, LUA_ERRERR);\n  n = L->stacksize + need;\n  if (n > LJ_STACK_MAX) {\n    n += 2*LUA_MINSTACK;\n  } else if (n < 2*L->stacksize) {\n    n = 2*L->stacksize;\n    if (n >= LJ_STACK_MAX)\n      n = LJ_STACK_MAX;\n  }\n  resizestack(L, n);\n  if (L->stacksize > LJ_STACK_MAXEX)\n    lj_err_msg(L, LJ_ERR_STKOV);\n}\n\nvoid LJ_FASTCALL lj_state_growstack1(lua_State *L)\n{\n  lj_state_growstack(L, 1);\n}\n\n/* Allocate basic stack for new state. */\nstatic void stack_init(lua_State *L1, lua_State *L)\n{\n  TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue);\n  setmref(L1->stack, st);\n  L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA;\n  stend = st + L1->stacksize;\n  setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1);\n  setthreadV(L1, st++, L1);  /* Needed for curr_funcisL() on empty stack. */\n  if (LJ_FR2) setnilV(st++);\n  L1->base = L1->top = st;\n  while (st < stend)  /* Clear new slots. */\n    setnilV(st++);\n}\n\n/* -- State handling ------------------------------------------------------ */\n\n/* Open parts that may cause memory-allocation errors. */\nstatic TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  global_State *g = G(L);\n  UNUSED(dummy);\n  UNUSED(ud);\n  stack_init(L, L);\n  /* NOBARRIER: State initialization, all objects are white. */\n  setgcref(L->env, obj2gco(lj_tab_new(L, 0, LJ_MIN_GLOBAL)));\n  settabV(L, registry(L), lj_tab_new(L, 0, LJ_MIN_REGISTRY));\n  lj_str_resize(L, LJ_MIN_STRTAB-1);\n  lj_meta_init(L);\n  lj_lex_init(L);\n  fixstring(lj_err_str(L, LJ_ERR_ERRMEM));  /* Preallocate memory error msg. */\n  g->gc.threshold = 4*g->gc.total;\n  lj_trace_initstate(g);\n  return NULL;\n}\n\nstatic void close_state(lua_State *L)\n{\n  global_State *g = G(L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lj_gc_freeall(g);\n  lua_assert(gcref(g->gc.root) == obj2gco(L));\n  lua_assert(g->strnum == 0);\n  lj_trace_freestate(g);\n#if LJ_HASFFI\n  lj_ctype_freestate(g);\n#endif\n  lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);\n  lj_buf_free(g, &g->tmpbuf);\n  lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);\n  lua_assert(g->gc.total == sizeof(GG_State));\n#ifndef LUAJIT_USE_SYSMALLOC\n  if (g->allocf == lj_alloc_f)\n    lj_alloc_destroy(g->allocd);\n  else\n#endif\n    g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0);\n}\n\n#if LJ_64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC))\nlua_State *lj_state_newstate(lua_Alloc f, void *ud)\n#else\nLUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)\n#endif\n{\n  GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State));\n  lua_State *L = &GG->L;\n  global_State *g = &GG->g;\n  if (GG == NULL || !checkptrGC(GG)) return NULL;\n  memset(GG, 0, sizeof(GG_State));\n  L->gct = ~LJ_TTHREAD;\n  L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED;  /* Prevent free. */\n  L->dummy_ffid = FF_C;\n  setmref(L->glref, g);\n  g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED;\n  g->strempty.marked = LJ_GC_WHITE0;\n  g->strempty.gct = ~LJ_TSTR;\n  g->allocf = f;\n  g->allocd = ud;\n  setgcref(g->mainthref, obj2gco(L));\n  setgcref(g->uvhead.prev, obj2gco(&g->uvhead));\n  setgcref(g->uvhead.next, obj2gco(&g->uvhead));\n  g->strmask = ~(MSize)0;\n  setnilV(registry(L));\n  setnilV(&g->nilnode.val);\n  setnilV(&g->nilnode.key);\n#if !LJ_GC64\n  setmref(g->nilnode.freetop, &g->nilnode);\n#endif\n  lj_buf_init(NULL, &g->tmpbuf);\n  g->gc.state = GCSpause;\n  setgcref(g->gc.root, obj2gco(L));\n  setmref(g->gc.sweep, &g->gc.root);\n  g->gc.total = sizeof(GG_State);\n  g->gc.pause = LUAI_GCPAUSE;\n  g->gc.stepmul = LUAI_GCMUL;\n  lj_dispatch_init((GG_State *)L);\n  L->status = LUA_ERRERR+1;  /* Avoid touching the stack upon memory error. */\n  if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {\n    /* Memory allocation error: free partial state. */\n    close_state(L);\n    return NULL;\n  }\n  L->status = 0;\n  return L;\n}\n\nstatic TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  UNUSED(dummy);\n  UNUSED(ud);\n  lj_gc_finalize_cdata(L);\n  lj_gc_finalize_udata(L);\n  /* Frame pop omitted. */\n  return NULL;\n}\n\nLUA_API void lua_close(lua_State *L)\n{\n  global_State *g = G(L);\n  int i;\n  L = mainthread(g);  /* Only the main thread can be closed. */\n#if LJ_HASPROFILE\n  luaJIT_profile_stop(L);\n#endif\n  setgcrefnull(g->cur_L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lj_gc_separateudata(g, 1);  /* Separate udata which have GC metamethods. */\n#if LJ_HASJIT\n  G2J(g)->flags &= ~JIT_F_ON;\n  G2J(g)->state = LJ_TRACE_IDLE;\n  lj_dispatch_update(g);\n#endif\n  for (i = 0;;) {\n    hook_enter(g);\n    L->status = 0;\n    L->base = L->top = tvref(L->stack) + 1 + LJ_FR2;\n    L->cframe = NULL;\n    if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == 0) {\n      if (++i >= 10) break;\n      lj_gc_separateudata(g, 1);  /* Separate udata again. */\n      if (gcref(g->gc.mmudata) == NULL)  /* Until nothing is left to do. */\n\tbreak;\n    }\n  }\n  close_state(L);\n}\n\nlua_State *lj_state_new(lua_State *L)\n{\n  lua_State *L1 = lj_mem_newobj(L, lua_State);\n  L1->gct = ~LJ_TTHREAD;\n  L1->dummy_ffid = FF_C;\n  L1->status = 0;\n  L1->stacksize = 0;\n  setmref(L1->stack, NULL);\n  L1->cframe = NULL;\n  /* NOBARRIER: The lua_State is new (marked white). */\n  setgcrefnull(L1->openupval);\n  setmrefr(L1->glref, L->glref);\n  setgcrefr(L1->env, L->env);\n  stack_init(L1, L);  /* init stack */\n  lua_assert(iswhite(obj2gco(L1)));\n  return L1;\n}\n\nvoid LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)\n{\n  lua_assert(L != mainthread(g));\n  if (obj2gco(L) == gcref(g->cur_L))\n    setgcrefnull(g->cur_L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lua_assert(gcref(L->openupval) == NULL);\n  lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);\n  lj_mem_freet(g, L);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_state.h",
    "content": "/*\n** State and stack handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STATE_H\n#define _LJ_STATE_H\n\n#include \"lj_obj.h\"\n\n#define incr_top(L) \\\n  (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0))\n\n#define savestack(L, p)\t\t((char *)(p) - mref(L->stack, char))\n#define restorestack(L, n)\t((TValue *)(mref(L->stack, char) + (n)))\n\nLJ_FUNC void lj_state_relimitstack(lua_State *L);\nLJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used);\nLJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need);\nLJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L);\n\nstatic LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)\n{\n  if ((mref(L->maxstack, char) - (char *)L->top) <=\n      (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue))\n    lj_state_growstack(L, need);\n}\n\nLJ_FUNC lua_State *lj_state_new(lua_State *L);\nLJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);\n#if LJ_64\nLJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_str.c",
    "content": "/*\n** String handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_str_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_char.h\"\n\n/* -- String helpers ------------------------------------------------------ */\n\n/* Ordered compare of strings. Assumes string data is 4-byte aligned. */\nint32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b)\n{\n  MSize i, n = a->len > b->len ? b->len : a->len;\n  for (i = 0; i < n; i += 4) {\n    /* Note: innocuous access up to end of string + 3. */\n    uint32_t va = *(const uint32_t *)(strdata(a)+i);\n    uint32_t vb = *(const uint32_t *)(strdata(b)+i);\n    if (va != vb) {\n#if LJ_LE\n      va = lj_bswap(va); vb = lj_bswap(vb);\n#endif\n      i -= n;\n      if ((int32_t)i >= -3) {\n\tva >>= 32+(i<<3); vb >>= 32+(i<<3);\n\tif (va == vb) break;\n      }\n      return va < vb ? -1 : 1;\n    }\n  }\n  return (int32_t)(a->len - b->len);\n}\n\n/* Fast string data comparison. Caveat: unaligned access to 1st string! */\nstatic LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len)\n{\n  MSize i = 0;\n  lua_assert(len > 0);\n  lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4);\n  do {  /* Note: innocuous access up to end of string + 3. */\n    uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i);\n    if (v) {\n      i -= len;\n#if LJ_LE\n      return (int32_t)i >= -3 ? (v << (32+(i<<3))) : 1;\n#else\n      return (int32_t)i >= -3 ? (v >> (32+(i<<3))) : 1;\n#endif\n    }\n    i += 4;\n  } while (i < len);\n  return 0;\n}\n\n/* Find fixed string p inside string s. */\nconst char *lj_str_find(const char *s, const char *p, MSize slen, MSize plen)\n{\n  if (plen <= slen) {\n    if (plen == 0) {\n      return s;\n    } else {\n      int c = *(const uint8_t *)p++;\n      plen--; slen -= plen;\n      while (slen) {\n\tconst char *q = (const char *)memchr(s, c, slen);\n\tif (!q) break;\n\tif (memcmp(q+1, p, plen) == 0) return q;\n\tq++; slen -= (MSize)(q-s); s = q;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Check whether a string has a pattern matching character. */\nint lj_str_haspattern(GCstr *s)\n{\n  const char *p = strdata(s), *q = p + s->len;\n  while (p < q) {\n    int c = *(const uint8_t *)p++;\n    if (lj_char_ispunct(c) && strchr(\"^$*+?.([%-\", c))\n      return 1;  /* Found a pattern matching char. */\n  }\n  return 0;  /* No pattern matching chars found. */\n}\n\n/* -- String interning ---------------------------------------------------- */\n\n/* Resize the string hash table (grow and shrink). */\nvoid lj_str_resize(lua_State *L, MSize newmask)\n{\n  global_State *g = G(L);\n  GCRef *newhash;\n  MSize i;\n  if (g->gc.state == GCSsweepstring || newmask >= LJ_MAX_STRTAB-1)\n    return;  /* No resizing during GC traversal or if already too big. */\n  newhash = lj_mem_newvec(L, newmask+1, GCRef);\n  memset(newhash, 0, (newmask+1)*sizeof(GCRef));\n  for (i = g->strmask; i != ~(MSize)0; i--) {  /* Rehash old table. */\n    GCobj *p = gcref(g->strhash[i]);\n    while (p) {  /* Follow each hash chain and reinsert all strings. */\n      MSize h = gco2str(p)->hash & newmask;\n      GCobj *next = gcnext(p);\n      /* NOBARRIER: The string table is a GC root. */\n      setgcrefr(p->gch.nextgc, newhash[h]);\n      setgcref(newhash[h], p);\n      p = next;\n    }\n  }\n  lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);\n  g->strmask = newmask;\n  g->strhash = newhash;\n}\n\n/* Intern a string and return string object. */\nGCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)\n{\n  global_State *g;\n  GCstr *s;\n  GCobj *o;\n  MSize len = (MSize)lenx;\n  MSize a, b, h = len;\n  if (lenx >= LJ_MAX_STR)\n    lj_err_msg(L, LJ_ERR_STROV);\n  g = G(L);\n  /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */\n  if (len >= 4) {  /* Caveat: unaligned access! */\n    a = lj_getu32(str);\n    h ^= lj_getu32(str+len-4);\n    b = lj_getu32(str+(len>>1)-2);\n    h ^= b; h -= lj_rol(b, 14);\n    b += lj_getu32(str+(len>>2)-1);\n  } else if (len > 0) {\n    a = *(const uint8_t *)str;\n    h ^= *(const uint8_t *)(str+len-1);\n    b = *(const uint8_t *)(str+(len>>1));\n    h ^= b; h -= lj_rol(b, 14);\n  } else {\n    return &g->strempty;\n  }\n  a ^= h; a -= lj_rol(h, 11);\n  b ^= a; b -= lj_rol(a, 25);\n  h ^= b; h -= lj_rol(b, 16);\n  /* Check if the string has already been interned. */\n  o = gcref(g->strhash[h & g->strmask]);\n  if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {\n    while (o != NULL) {\n      GCstr *sx = gco2str(o);\n      if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {\n\t/* Resurrect if dead. Can only happen with fixstring() (keywords). */\n\tif (isdead(g, o)) flipwhite(o);\n\treturn sx;  /* Return existing string. */\n      }\n      o = gcnext(o);\n    }\n  } else {  /* Slow path: end of string is too close to a page boundary. */\n    while (o != NULL) {\n      GCstr *sx = gco2str(o);\n      if (sx->len == len && memcmp(str, strdata(sx), len) == 0) {\n\t/* Resurrect if dead. Can only happen with fixstring() (keywords). */\n\tif (isdead(g, o)) flipwhite(o);\n\treturn sx;  /* Return existing string. */\n      }\n      o = gcnext(o);\n    }\n  }\n  /* Nope, create a new string. */\n  s = lj_mem_newt(L, sizeof(GCstr)+len+1, GCstr);\n  newwhite(g, s);\n  s->gct = ~LJ_TSTR;\n  s->len = len;\n  s->hash = h;\n  s->reserved = 0;\n  memcpy(strdatawr(s), str, len);\n  strdatawr(s)[len] = '\\0';  /* Zero-terminate string. */\n  /* Add it to string hash table. */\n  h &= g->strmask;\n  s->nextgc = g->strhash[h];\n  /* NOBARRIER: The string table is a GC root. */\n  setgcref(g->strhash[h], obj2gco(s));\n  if (g->strnum++ > g->strmask)  /* Allow a 100% load factor. */\n    lj_str_resize(L, (g->strmask<<1)+1);  /* Grow string table. */\n  return s;  /* Return newly interned string. */\n}\n\nvoid LJ_FASTCALL lj_str_free(global_State *g, GCstr *s)\n{\n  g->strnum--;\n  lj_mem_free(g, s, sizestring(s));\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_str.h",
    "content": "/*\n** String handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STR_H\n#define _LJ_STR_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n\n/* String helpers. */\nLJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);\nLJ_FUNC const char *lj_str_find(const char *s, const char *f,\n\t\t\t\tMSize slen, MSize flen);\nLJ_FUNC int lj_str_haspattern(GCstr *s);\n\n/* String interning. */\nLJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);\nLJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);\nLJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);\n\n#define lj_str_newz(L, s)\t(lj_str_new(L, s, strlen(s)))\n#define lj_str_newlit(L, s)\t(lj_str_new(L, \"\" s, sizeof(s)-1))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_strfmt.c",
    "content": "/*\n** String formatting.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <stdio.h>\n\n#define lj_strfmt_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_state.h\"\n#include \"lj_char.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Format parser ------------------------------------------------------- */\n\nstatic const uint8_t strfmt_map[('x'-'A')+1] = {\n  STRFMT_A,0,0,0,STRFMT_E,STRFMT_F,STRFMT_G,0,0,0,0,0,0,\n  0,0,0,0,0,0,0,0,0,0,STRFMT_X,0,0,\n  0,0,0,0,0,0,\n  STRFMT_A,0,STRFMT_C,STRFMT_D,STRFMT_E,STRFMT_F,STRFMT_G,0,STRFMT_I,0,0,0,0,\n  0,STRFMT_O,STRFMT_P,STRFMT_Q,0,STRFMT_S,0,STRFMT_U,0,0,STRFMT_X\n};\n\nSFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs)\n{\n  const uint8_t *p = fs->p, *e = fs->e;\n  fs->str = (const char *)p;\n  for (; p < e; p++) {\n    if (*p == '%') {  /* Escape char? */\n      if (p[1] == '%') {  /* '%%'? */\n\tfs->p = ++p+1;\n\tgoto retlit;\n      } else {\n\tSFormat sf = 0;\n\tuint32_t c;\n\tif (p != (const uint8_t *)fs->str)\n\t  break;\n\tfor (p++; (uint32_t)*p - ' ' <= (uint32_t)('0' - ' '); p++) {\n\t  /* Parse flags. */\n\t  if (*p == '-') sf |= STRFMT_F_LEFT;\n\t  else if (*p == '+') sf |= STRFMT_F_PLUS;\n\t  else if (*p == '0') sf |= STRFMT_F_ZERO;\n\t  else if (*p == ' ') sf |= STRFMT_F_SPACE;\n\t  else if (*p == '#') sf |= STRFMT_F_ALT;\n\t  else break;\n\t}\n\tif ((uint32_t)*p - '0' < 10) {  /* Parse width. */\n\t  uint32_t width = (uint32_t)*p++ - '0';\n\t  if ((uint32_t)*p - '0' < 10)\n\t    width = (uint32_t)*p++ - '0' + width*10;\n\t  sf |= (width << STRFMT_SH_WIDTH);\n\t}\n\tif (*p == '.') {  /* Parse precision. */\n\t  uint32_t prec = 0;\n\t  p++;\n\t  if ((uint32_t)*p - '0' < 10) {\n\t    prec = (uint32_t)*p++ - '0';\n\t    if ((uint32_t)*p - '0' < 10)\n\t      prec = (uint32_t)*p++ - '0' + prec*10;\n\t  }\n\t  sf |= ((prec+1) << STRFMT_SH_PREC);\n\t}\n\t/* Parse conversion. */\n\tc = (uint32_t)*p - 'A';\n\tif (LJ_LIKELY(c <= (uint32_t)('x' - 'A'))) {\n\t  uint32_t sx = strfmt_map[c];\n\t  if (sx) {\n\t    fs->p = p+1;\n\t    return (sf | sx | ((c & 0x20) ? 0 : STRFMT_F_UPPER));\n\t  }\n\t}\n\t/* Return error location. */\n\tif (*p >= 32) p++;\n\tfs->len = (MSize)(p - (const uint8_t *)fs->str);\n\tfs->p = fs->e;\n\treturn STRFMT_ERR;\n      }\n    }\n  }\n  fs->p = p;\nretlit:\n  fs->len = (MSize)(p - (const uint8_t *)fs->str);\n  return fs->len ? STRFMT_LIT : STRFMT_EOF;\n}\n\n/* -- Raw conversions ----------------------------------------------------- */\n\n#define WINT_R(x, sh, sc) \\\n  { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); }\n\n/* Write integer to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k)\n{\n  uint32_t u = (uint32_t)k;\n  if (k < 0) { u = (uint32_t)-k; *p++ = '-'; }\n  if (u < 10000) {\n    if (u < 10) goto dig1; if (u < 100) goto dig2; if (u < 1000) goto dig3;\n  } else {\n    uint32_t v = u / 10000; u -= v * 10000;\n    if (v < 10000) {\n      if (v < 10) goto dig5; if (v < 100) goto dig6; if (v < 1000) goto dig7;\n    } else {\n      uint32_t w = v / 10000; v -= w * 10000;\n      if (w >= 10) WINT_R(w, 10, 10)\n      *p++ = (char)('0'+w);\n    }\n    WINT_R(v, 23, 1000)\n    dig7: WINT_R(v, 12, 100)\n    dig6: WINT_R(v, 10, 10)\n    dig5: *p++ = (char)('0'+v);\n  }\n  WINT_R(u, 23, 1000)\n  dig3: WINT_R(u, 12, 100)\n  dig2: WINT_R(u, 10, 10)\n  dig1: *p++ = (char)('0'+u);\n  return p;\n}\n#undef WINT_R\n\n/* Write pointer to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v)\n{\n  ptrdiff_t x = (ptrdiff_t)v;\n  MSize i, n = STRFMT_MAXBUF_PTR;\n  if (x == 0) {\n    *p++ = 'N'; *p++ = 'U'; *p++ = 'L'; *p++ = 'L';\n    return p;\n  }\n#if LJ_64\n  /* Shorten output for 64 bit pointers. */\n  n = 2+2*4+((x >> 32) ? 2+2*(lj_fls((uint32_t)(x >> 32))>>3) : 0);\n#endif\n  p[0] = '0';\n  p[1] = 'x';\n  for (i = n-1; i >= 2; i--, x >>= 4)\n    p[i] = \"0123456789abcdef\"[(x & 15)];\n  return p+n;\n}\n\n/* Write ULEB128 to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v)\n{\n  for (; v >= 0x80; v >>= 7)\n    *p++ = (char)((v & 0x7f) | 0x80);\n  *p++ = (char)v;\n  return p;\n}\n\n/* Return string or write number to tmp buffer and return pointer to start. */\nconst char *lj_strfmt_wstrnum(lua_State *L, cTValue *o, MSize *lenp)\n{\n  SBuf *sb;\n  if (tvisstr(o)) {\n    *lenp = strV(o)->len;\n    return strVdata(o);\n  } else if (tvisint(o)) {\n    sb = lj_strfmt_putint(lj_buf_tmp_(L), intV(o));\n  } else if (tvisnum(o)) {\n    sb = lj_strfmt_putfnum(lj_buf_tmp_(L), STRFMT_G14, o->n);\n  } else {\n    return NULL;\n  }\n  *lenp = sbuflen(sb);\n  return sbufB(sb);\n}\n\n/* -- Unformatted conversions to buffer ----------------------------------- */\n\n/* Add integer to buffer. */\nSBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k)\n{\n  setsbufP(sb, lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT), k));\n  return sb;\n}\n\n#if LJ_HASJIT\n/* Add number to buffer. */\nSBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o)\n{\n  return lj_strfmt_putfnum(sb, STRFMT_G14, o->n);\n}\n#endif\n\nSBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v)\n{\n  setsbufP(sb, lj_strfmt_wptr(lj_buf_more(sb, STRFMT_MAXBUF_PTR), v));\n  return sb;\n}\n\n/* Add quoted string to buffer. */\nSBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str)\n{\n  const char *s = strdata(str);\n  MSize len = str->len;\n  lj_buf_putb(sb, '\"');\n  while (len--) {\n    uint32_t c = (uint32_t)(uint8_t)*s++;\n    char *p = lj_buf_more(sb, 4);\n    if (c == '\"' || c == '\\\\' || c == '\\n') {\n      *p++ = '\\\\';\n    } else if (lj_char_iscntrl(c)) {  /* This can only be 0-31 or 127. */\n      uint32_t d;\n      *p++ = '\\\\';\n      if (c >= 100 || lj_char_isdigit((uint8_t)*s)) {\n\t*p++ = (char)('0'+(c >= 100)); if (c >= 100) c -= 100;\n\tgoto tens;\n      } else if (c >= 10) {\n      tens:\n\td = (c * 205) >> 11; c -= d * 10; *p++ = (char)('0'+d);\n      }\n      c += '0';\n    }\n    *p++ = (char)c;\n    setsbufP(sb, p);\n  }\n  lj_buf_putb(sb, '\"');\n  return sb;\n}\n\n/* -- Formatted conversions to buffer ------------------------------------- */\n\n/* Add formatted char to buffer. */\nSBuf *lj_strfmt_putfchar(SBuf *sb, SFormat sf, int32_t c)\n{\n  MSize width = STRFMT_WIDTH(sf);\n  char *p = lj_buf_more(sb, width > 1 ? width : 1);\n  if ((sf & STRFMT_F_LEFT)) *p++ = (char)c;\n  while (width-- > 1) *p++ = ' ';\n  if (!(sf & STRFMT_F_LEFT)) *p++ = (char)c;\n  setsbufP(sb, p);\n  return sb;\n}\n\n/* Add formatted string to buffer. */\nSBuf *lj_strfmt_putfstr(SBuf *sb, SFormat sf, GCstr *str)\n{\n  MSize len = str->len <= STRFMT_PREC(sf) ? str->len : STRFMT_PREC(sf);\n  MSize width = STRFMT_WIDTH(sf);\n  char *p = lj_buf_more(sb, width > len ? width : len);\n  if ((sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len);\n  while (width-- > len) *p++ = ' ';\n  if (!(sf & STRFMT_F_LEFT)) p = lj_buf_wmem(p, strdata(str), len);\n  setsbufP(sb, p);\n  return sb;\n}\n\n/* Add formatted signed/unsigned integer to buffer. */\nSBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k)\n{\n  char buf[STRFMT_MAXBUF_XINT], *q = buf + sizeof(buf), *p;\n#ifdef LUA_USE_ASSERT\n  char *ps;\n#endif\n  MSize prefix = 0, len, prec, pprec, width, need;\n\n  /* Figure out signed prefixes. */\n  if (STRFMT_TYPE(sf) == STRFMT_INT) {\n    if ((int64_t)k < 0) {\n      k = (uint64_t)-(int64_t)k;\n      prefix = 256 + '-';\n    } else if ((sf & STRFMT_F_PLUS)) {\n      prefix = 256 + '+';\n    } else if ((sf & STRFMT_F_SPACE)) {\n      prefix = 256 + ' ';\n    }\n  }\n\n  /* Convert number and store to fixed-size buffer in reverse order. */\n  prec = STRFMT_PREC(sf);\n  if ((int32_t)prec >= 0) sf &= ~STRFMT_F_ZERO;\n  if (k == 0) {  /* Special-case zero argument. */\n    if (prec != 0 ||\n\t(sf & (STRFMT_T_OCT|STRFMT_F_ALT)) == (STRFMT_T_OCT|STRFMT_F_ALT))\n      *--q = '0';\n  } else if (!(sf & (STRFMT_T_HEX|STRFMT_T_OCT))) {  /* Decimal. */\n    uint32_t k2;\n    while ((k >> 32)) { *--q = (char)('0' + k % 10); k /= 10; }\n    k2 = (uint32_t)k;\n    do { *--q = (char)('0' + k2 % 10); k2 /= 10; } while (k2);\n  } else if ((sf & STRFMT_T_HEX)) {  /* Hex. */\n    const char *hexdig = (sf & STRFMT_F_UPPER) ? \"0123456789ABCDEF\" :\n\t\t\t\t\t\t \"0123456789abcdef\";\n    do { *--q = hexdig[(k & 15)]; k >>= 4; } while (k);\n    if ((sf & STRFMT_F_ALT)) prefix = 512 + ((sf & STRFMT_F_UPPER) ? 'X' : 'x');\n  } else {  /* Octal. */\n    do { *--q = (char)('0' + (uint32_t)(k & 7)); k >>= 3; } while (k);\n    if ((sf & STRFMT_F_ALT)) *--q = '0';\n  }\n\n  /* Calculate sizes. */\n  len = (MSize)(buf + sizeof(buf) - q);\n  if ((int32_t)len >= (int32_t)prec) prec = len;\n  width = STRFMT_WIDTH(sf);\n  pprec = prec + (prefix >> 8);\n  need = width > pprec ? width : pprec;\n  p = lj_buf_more(sb, need);\n#ifdef LUA_USE_ASSERT\n  ps = p;\n#endif\n\n  /* Format number with leading/trailing whitespace and zeros. */\n  if ((sf & (STRFMT_F_LEFT|STRFMT_F_ZERO)) == 0)\n    while (width-- > pprec) *p++ = ' ';\n  if (prefix) {\n    if ((char)prefix >= 'X') *p++ = '0';\n    *p++ = (char)prefix;\n  }\n  if ((sf & (STRFMT_F_LEFT|STRFMT_F_ZERO)) == STRFMT_F_ZERO)\n    while (width-- > pprec) *p++ = '0';\n  while (prec-- > len) *p++ = '0';\n  while (q < buf + sizeof(buf)) *p++ = *q++;  /* Add number itself. */\n  if ((sf & STRFMT_F_LEFT))\n    while (width-- > pprec) *p++ = ' ';\n\n  lua_assert(need == (MSize)(p - ps));\n  setsbufP(sb, p);\n  return sb;\n}\n\n/* Add number formatted as signed integer to buffer. */\nSBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n)\n{\n  int64_t k = (int64_t)n;\n  if (checki32(k) && sf == STRFMT_INT)\n    return lj_strfmt_putint(sb, (int32_t)k);  /* Shortcut for plain %d. */\n  else\n    return lj_strfmt_putfxint(sb, sf, (uint64_t)k);\n}\n\n/* Add number formatted as unsigned integer to buffer. */\nSBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n)\n{\n  int64_t k;\n  if (n >= 9223372036854775808.0)\n    k = (int64_t)(n - 18446744073709551616.0);\n  else\n    k = (int64_t)n;\n  return lj_strfmt_putfxint(sb, sf, (uint64_t)k);\n}\n\n/* -- Conversions to strings ---------------------------------------------- */\n\n/* Convert integer to string. */\nGCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k)\n{\n  char buf[STRFMT_MAXBUF_INT];\n  MSize len = (MSize)(lj_strfmt_wint(buf, k) - buf);\n  return lj_str_new(L, buf, len);\n}\n\n/* Convert integer or number to string. */\nGCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o)\n{\n  return tvisint(o) ? lj_strfmt_int(L, intV(o)) : lj_strfmt_num(L, o);\n}\n\n#if LJ_HASJIT\n/* Convert char value to string. */\nGCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c)\n{\n  char buf[1];\n  buf[0] = c;\n  return lj_str_new(L, buf, 1);\n}\n#endif\n\n/* Raw conversion of object to string. */\nGCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o)\n{\n  if (tvisstr(o)) {\n    return strV(o);\n  } else if (tvisnumber(o)) {\n    return lj_strfmt_number(L, o);\n  } else if (tvisnil(o)) {\n    return lj_str_newlit(L, \"nil\");\n  } else if (tvisfalse(o)) {\n    return lj_str_newlit(L, \"false\");\n  } else if (tvistrue(o)) {\n    return lj_str_newlit(L, \"true\");\n  } else {\n    char buf[8+2+2+16], *p = buf;\n    p = lj_buf_wmem(p, lj_typename(o), (MSize)strlen(lj_typename(o)));\n    *p++ = ':'; *p++ = ' ';\n    if (tvisfunc(o) && isffunc(funcV(o))) {\n      p = lj_buf_wmem(p, \"builtin#\", 8);\n      p = lj_strfmt_wint(p, funcV(o)->c.ffid);\n    } else {\n      p = lj_strfmt_wptr(p, lj_obj_ptr(o));\n    }\n    return lj_str_new(L, buf, (size_t)(p - buf));\n  }\n}\n\n/* -- Internal string formatting ------------------------------------------ */\n\n/*\n** These functions are only used for lua_pushfstring(), lua_pushvfstring()\n** and for internal string formatting (e.g. error messages). Caveat: unlike\n** string.format(), only a limited subset of formats and flags are supported!\n**\n** LuaJIT has support for a couple more formats than Lua 5.1/5.2:\n** - %d %u %o %x with full formatting, 32 bit integers only.\n** - %f and other FP formats are really %.14g.\n** - %s %c %p without formatting.\n*/\n\n/* Push formatted message as a string object to Lua stack. va_list variant. */\nconst char *lj_strfmt_pushvf(lua_State *L, const char *fmt, va_list argp)\n{\n  SBuf *sb = lj_buf_tmp_(L);\n  FormatState fs;\n  SFormat sf;\n  GCstr *str;\n  lj_strfmt_init(&fs, fmt, (MSize)strlen(fmt));\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {\n    switch (STRFMT_TYPE(sf)) {\n    case STRFMT_LIT:\n      lj_buf_putmem(sb, fs.str, fs.len);\n      break;\n    case STRFMT_INT:\n      lj_strfmt_putfxint(sb, sf, va_arg(argp, int32_t));\n      break;\n    case STRFMT_UINT:\n      lj_strfmt_putfxint(sb, sf, va_arg(argp, uint32_t));\n      break;\n    case STRFMT_NUM:\n      lj_strfmt_putfnum(sb, STRFMT_G14, va_arg(argp, lua_Number));\n      break;\n    case STRFMT_STR: {\n      const char *s = va_arg(argp, char *);\n      if (s == NULL) s = \"(null)\";\n      lj_buf_putmem(sb, s, (MSize)strlen(s));\n      break;\n      }\n    case STRFMT_CHAR:\n      lj_buf_putb(sb, va_arg(argp, int));\n      break;\n    case STRFMT_PTR:\n      lj_strfmt_putptr(sb, va_arg(argp, void *));\n      break;\n    case STRFMT_ERR:\n    default:\n      lj_buf_putb(sb, '?');\n      lua_assert(0);\n      break;\n    }\n  }\n  str = lj_buf_str(L, sb);\n  setstrV(L, L->top, str);\n  incr_top(L);\n  return strdata(str);\n}\n\n/* Push formatted message as a string object to Lua stack. Vararg variant. */\nconst char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_strfmt.h",
    "content": "/*\n** String formatting.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STRFMT_H\n#define _LJ_STRFMT_H\n\n#include \"lj_obj.h\"\n\ntypedef uint32_t SFormat;  /* Format indicator. */\n\n/* Format parser state. */\ntypedef struct FormatState {\n  const uint8_t *p;\t/* Current format string pointer. */\n  const uint8_t *e;\t/* End of format string. */\n  const char *str;\t/* Returned literal string. */\n  MSize len;\t\t/* Size of literal string. */\n} FormatState;\n\n/* Format types (max. 16). */\ntypedef enum FormatType {\n  STRFMT_EOF, STRFMT_ERR, STRFMT_LIT,\n  STRFMT_INT, STRFMT_UINT, STRFMT_NUM, STRFMT_STR, STRFMT_CHAR, STRFMT_PTR\n} FormatType;\n\n/* Format subtypes (bits are reused). */\n#define STRFMT_T_HEX\t0x0010\t/* STRFMT_UINT */\n#define STRFMT_T_OCT\t0x0020\t/* STRFMT_UINT */\n#define STRFMT_T_FP_A\t0x0000\t/* STRFMT_NUM */\n#define STRFMT_T_FP_E\t0x0010\t/* STRFMT_NUM */\n#define STRFMT_T_FP_F\t0x0020\t/* STRFMT_NUM */\n#define STRFMT_T_FP_G\t0x0030\t/* STRFMT_NUM */\n#define STRFMT_T_QUOTED\t0x0010\t/* STRFMT_STR */\n\n/* Format flags. */\n#define STRFMT_F_LEFT\t0x0100\n#define STRFMT_F_PLUS\t0x0200\n#define STRFMT_F_ZERO\t0x0400\n#define STRFMT_F_SPACE\t0x0800\n#define STRFMT_F_ALT\t0x1000\n#define STRFMT_F_UPPER\t0x2000\n\n/* Format indicator fields. */\n#define STRFMT_SH_WIDTH\t16\n#define STRFMT_SH_PREC\t24\n\n#define STRFMT_TYPE(sf)\t\t((FormatType)((sf) & 15))\n#define STRFMT_WIDTH(sf)\t(((sf) >> STRFMT_SH_WIDTH) & 255u)\n#define STRFMT_PREC(sf)\t\t((((sf) >> STRFMT_SH_PREC) & 255u) - 1u)\n#define STRFMT_FP(sf)\t\t(((sf) >> 4) & 3)\n\n/* Formats for conversion characters. */\n#define STRFMT_A\t(STRFMT_NUM|STRFMT_T_FP_A)\n#define STRFMT_C\t(STRFMT_CHAR)\n#define STRFMT_D\t(STRFMT_INT)\n#define STRFMT_E\t(STRFMT_NUM|STRFMT_T_FP_E)\n#define STRFMT_F\t(STRFMT_NUM|STRFMT_T_FP_F)\n#define STRFMT_G\t(STRFMT_NUM|STRFMT_T_FP_G)\n#define STRFMT_I\tSTRFMT_D\n#define STRFMT_O\t(STRFMT_UINT|STRFMT_T_OCT)\n#define STRFMT_P\t(STRFMT_PTR)\n#define STRFMT_Q\t(STRFMT_STR|STRFMT_T_QUOTED)\n#define STRFMT_S\t(STRFMT_STR)\n#define STRFMT_U\t(STRFMT_UINT)\n#define STRFMT_X\t(STRFMT_UINT|STRFMT_T_HEX)\n#define STRFMT_G14\t(STRFMT_G | ((14+1) << STRFMT_SH_PREC))\n\n/* Maximum buffer sizes for conversions. */\n#define STRFMT_MAXBUF_XINT\t(1+22)  /* '0' prefix + uint64_t in octal. */\n#define STRFMT_MAXBUF_INT\t(1+10)  /* Sign + int32_t in decimal. */\n#define STRFMT_MAXBUF_NUM\t32  /* Must correspond with STRFMT_G14. */\n#define STRFMT_MAXBUF_PTR\t(2+2*sizeof(ptrdiff_t))  /* \"0x\" + hex ptr. */\n\n/* Format parser. */\nLJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs);\n\nstatic LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len)\n{\n  fs->p = (const uint8_t *)p;\n  fs->e = (const uint8_t *)p + len;\n  lua_assert(*fs->e == 0);  /* Must be NUL-terminated (may have NULs inside). */\n}\n\n/* Raw conversions. */\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k);\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v);\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v);\nLJ_FUNC const char *lj_strfmt_wstrnum(lua_State *L, cTValue *o, MSize *lenp);\n\n/* Unformatted conversions to buffer. */\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k);\n#if LJ_HASJIT\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o);\n#endif\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v);\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str);\n\n/* Formatted conversions to buffer. */\nLJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k);\nLJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c);\nLJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str);\n\n/* Conversions to strings. */\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k);\nLJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o);\nLJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o);\n#if LJ_HASJIT\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c);\n#endif\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o);\n\n/* Internal string formatting. */\nLJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt,\n\t\t\t\t     va_list argp);\nLJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)\n#ifdef __GNUC__\n  __attribute__ ((format (printf, 2, 3)))\n#endif\n  ;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_strfmt_num.c",
    "content": "/*\n** String formatting for floating-point numbers.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n** Contributed by Peter Cawley.\n*/\n\n#include <stdio.h>\n\n#define lj_strfmt_num_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Precomputed tables -------------------------------------------------- */\n\n/* Rescale factors to push the exponent of a number towards zero. */\n#define RESCALE_EXPONENTS(P, N) \\\n  P(308), P(289), P(270), P(250), P(231), P(212), P(193), P(173), P(154), \\\n  P(135), P(115), P(96), P(77), P(58), P(38), P(0), P(0), P(0), N(39), N(58), \\\n  N(77), N(96), N(116), N(135), N(154), N(174), N(193), N(212), N(231), \\\n  N(251), N(270), N(289)\n\n#define ONE_E_P(X) 1e+0 ## X\n#define ONE_E_N(X) 1e-0 ## X\nstatic const int16_t rescale_e[] = { RESCALE_EXPONENTS(-, +) };\nstatic const double rescale_n[] = { RESCALE_EXPONENTS(ONE_E_P, ONE_E_N) };\n#undef ONE_E_N\n#undef ONE_E_P\n\n/*\n** For p in range -70 through 57, this table encodes pairs (m, e) such that\n** 4*2^p <= (uint8_t)m*10^e, and is the smallest value for which this holds.\n*/\nstatic const int8_t four_ulp_m_e[] = {\n  34, -21, 68, -21, 14, -20, 28, -20, 55, -20, 2, -19, 3, -19, 5, -19, 9, -19,\n  -82, -18, 35, -18, 7, -17, -117, -17, 28, -17, 56, -17, 112, -16, -33, -16,\n  45, -16, 89, -16, -78, -15, 36, -15, 72, -15, -113, -14, 29, -14, 57, -14,\n  114, -13, -28, -13, 46, -13, 91, -12, -74, -12, 37, -12, 73, -12, 15, -11, 3,\n  -11, 59, -11, 2, -10, 3, -10, 5, -10, 1, -9, -69, -9, 38, -9, 75, -9, 15, -7,\n  3, -7, 6, -7, 12, -6, -17, -7, 48, -7, 96, -7, -65, -6, 39, -6, 77, -6, -103,\n  -5, 31, -5, 62, -5, 123, -4, -11, -4, 49, -4, 98, -4, -60, -3, 4, -2, 79, -3,\n  16, -2, 32, -2, 63, -2, 2, -1, 25, 0, 5, 1, 1, 2, 2, 2, 4, 2, 8, 2, 16, 2,\n  32, 2, 64, 2, -128, 2, 26, 2, 52, 2, 103, 3, -51, 3, 41, 4, 82, 4, -92, 4,\n  33, 4, 66, 4, -124, 5, 27, 5, 53, 5, 105, 6, 21, 6, 42, 6, 84, 6, 17, 7, 34,\n  7, 68, 7, 2, 8, 3, 8, 6, 8, 108, 9, -41, 9, 43, 10, 86, 9, -84, 10, 35, 10,\n  69, 10, -118, 11, 28, 11, 55, 12, 11, 13, 22, 13, 44, 13, 88, 13, -80, 13,\n  36, 13, 71, 13, -115, 14, 29, 14, 57, 14, 113, 15, -30, 15, 46, 15, 91, 15,\n  19, 16, 37, 16, 73, 16, 2, 17, 3, 17, 6, 17\n};\n\n/* min(2^32-1, 10^e-1) for e in range 0 through 10 */\nstatic uint32_t ndigits_dec_threshold[] = {\n  0, 9U, 99U, 999U, 9999U, 99999U, 999999U,\n  9999999U, 99999999U, 999999999U, 0xffffffffU\n};\n\n/* -- Helper functions ---------------------------------------------------- */\n\n/* Compute the number of digits in the decimal representation of x. */\nstatic MSize ndigits_dec(uint32_t x)\n{\n  MSize t = ((lj_fls(x | 1) * 77) >> 8) + 1; /* 2^8/77 is roughly log2(10) */\n  return t + (x > ndigits_dec_threshold[t]);\n}\n\n#define WINT_R(x, sh, sc) \\\n  { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); }\n\n/* Write 9-digit unsigned integer to buffer. */\nstatic char *lj_strfmt_wuint9(char *p, uint32_t u)\n{\n  uint32_t v = u / 10000, w;\n  u -= v * 10000;\n  w = v / 10000;\n  v -= w * 10000;\n  *p++ = (char)('0'+w);\n  WINT_R(v, 23, 1000)\n  WINT_R(v, 12, 100)\n  WINT_R(v, 10, 10)\n  *p++ = (char)('0'+v);\n  WINT_R(u, 23, 1000)\n  WINT_R(u, 12, 100)\n  WINT_R(u, 10, 10)\n  *p++ = (char)('0'+u);\n  return p;\n}\n#undef WINT_R\n\n/* -- Extended precision arithmetic --------------------------------------- */\n\n/*\n** The \"nd\" format is a fixed-precision decimal representation for numbers. It\n** consists of up to 64 uint32_t values, with each uint32_t storing a value\n** in the range [0, 1e9). A number in \"nd\" format consists of three variables:\n**\n**  uint32_t nd[64];\n**  uint32_t ndlo;\n**  uint32_t ndhi;\n**\n** The integral part of the number is stored in nd[0 ... ndhi], the value of\n** which is sum{i in [0, ndhi] | nd[i] * 10^(9*i)}. If the fractional part of\n** the number is zero, ndlo is zero. Otherwise, the fractional part is stored\n** in nd[ndlo ... 63], the value of which is taken to be\n** sum{i in [ndlo, 63] | nd[i] * 10^(9*(i-64))}.\n**\n** If the array part had 128 elements rather than 64, then every double would\n** have an exact representation in \"nd\" format. With 64 elements, all integral\n** doubles have an exact representation, and all non-integral doubles have\n** enough digits to make both %.99e and %.99f do the right thing.\n*/\n\n#if LJ_64\n#define ND_MUL2K_MAX_SHIFT\t29\n#define ND_MUL2K_DIV1E9(val)\t((uint32_t)((val) / 1000000000))\n#else\n#define ND_MUL2K_MAX_SHIFT\t11\n#define ND_MUL2K_DIV1E9(val)\t((uint32_t)((val) >> 9) / 1953125)\n#endif\n\n/* Multiply nd by 2^k and add carry_in (ndlo is assumed to be zero). */\nstatic uint32_t nd_mul2k(uint32_t* nd, uint32_t ndhi, uint32_t k,\n\t\t\t uint32_t carry_in, SFormat sf)\n{\n  uint32_t i, ndlo = 0, start = 1;\n  /* Performance hacks. */\n  if (k > ND_MUL2K_MAX_SHIFT*2 && STRFMT_FP(sf) != STRFMT_FP(STRFMT_T_FP_F)) {\n    start = ndhi - (STRFMT_PREC(sf) + 17) / 8;\n  }\n  /* Real logic. */\n  while (k >= ND_MUL2K_MAX_SHIFT) {\n    for (i = ndlo; i <= ndhi; i++) {\n      uint64_t val = ((uint64_t)nd[i] << ND_MUL2K_MAX_SHIFT) | carry_in;\n      carry_in = ND_MUL2K_DIV1E9(val);\n      nd[i] = (uint32_t)val - carry_in * 1000000000;\n    }\n    if (carry_in) {\n      nd[++ndhi] = carry_in; carry_in = 0;\n      if(start++ == ndlo) ++ndlo;\n    }\n    k -= ND_MUL2K_MAX_SHIFT;\n  }\n  if (k) {\n    for (i = ndlo; i <= ndhi; i++) {\n      uint64_t val = ((uint64_t)nd[i] << k) | carry_in;\n      carry_in = ND_MUL2K_DIV1E9(val);\n      nd[i] = (uint32_t)val - carry_in * 1000000000;\n    }\n    if (carry_in) nd[++ndhi] = carry_in;\n  }\n  return ndhi;\n}\n\n/* Divide nd by 2^k (ndlo is assumed to be zero). */\nstatic uint32_t nd_div2k(uint32_t* nd, uint32_t ndhi, uint32_t k, SFormat sf)\n{\n  uint32_t ndlo = 0, stop1 = ~0, stop2 = ~0;\n  /* Performance hacks. */\n  if (!ndhi) {\n    if (!nd[0]) {\n      return 0;\n    } else {\n      uint32_t s = lj_ffs(nd[0]);\n      if (s >= k) { nd[0] >>= k; return 0; }\n      nd[0] >>= s; k -= s;\n    }\n  }\n  if (k > 18) {\n    if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_F)) {\n      stop1 = 63 - (int32_t)STRFMT_PREC(sf) / 9;\n    } else {\n      int32_t floorlog2 = ndhi * 29 + lj_fls(nd[ndhi]) - k;\n      int32_t floorlog10 = (int32_t)(floorlog2 * 0.30102999566398114);\n      stop1 = 62 + (floorlog10 - (int32_t)STRFMT_PREC(sf)) / 9;\n      stop2 = 61 + ndhi - (int32_t)STRFMT_PREC(sf) / 8;\n    }\n  }\n  /* Real logic. */\n  while (k >= 9) {\n    uint32_t i = ndhi, carry = 0;\n    for (;;) {\n      uint32_t val = nd[i];\n      nd[i] = (val >> 9) + carry;\n      carry = (val & 0x1ff) * 1953125;\n      if (i == ndlo) break;\n      i = (i - 1) & 0x3f;\n    }\n    if (ndlo != stop1 && ndlo != stop2) {\n      if (carry) { ndlo = (ndlo - 1) & 0x3f; nd[ndlo] = carry; }\n      if (!nd[ndhi]) { ndhi = (ndhi - 1) & 0x3f; stop2--; }\n    } else if (!nd[ndhi]) {\n      if (ndhi != ndlo) { ndhi = (ndhi - 1) & 0x3f; stop2--; }\n      else return ndlo;\n    }\n    k -= 9;\n  }\n  if (k) {\n    uint32_t mask = (1U << k) - 1, mul = 1000000000 >> k, i = ndhi, carry = 0;\n    for (;;) {\n      uint32_t val = nd[i];\n      nd[i] = (val >> k) + carry;\n      carry = (val & mask) * mul;\n      if (i == ndlo) break;\n      i = (i - 1) & 0x3f;\n    }\n    if (carry) { ndlo = (ndlo - 1) & 0x3f; nd[ndlo] = carry; }\n  }\n  return ndlo;\n}\n\n/* Add m*10^e to nd (assumes ndlo <= e/9 <= ndhi and 0 <= m <= 9). */\nstatic uint32_t nd_add_m10e(uint32_t* nd, uint32_t ndhi, uint8_t m, int32_t e)\n{\n  uint32_t i, carry;\n  if (e >= 0) {\n    i = (uint32_t)e/9;\n    carry = m * (ndigits_dec_threshold[e - (int32_t)i*9] + 1);\n  } else {\n    int32_t f = (e-8)/9;\n    i = (uint32_t)(64 + f);\n    carry = m * (ndigits_dec_threshold[e - f*9] + 1);\n  }\n  for (;;) {\n    uint32_t val = nd[i] + carry;\n    if (LJ_UNLIKELY(val >= 1000000000)) {\n      val -= 1000000000;\n      nd[i] = val;\n      if (LJ_UNLIKELY(i == ndhi)) {\n\tndhi = (ndhi + 1) & 0x3f;\n\tnd[ndhi] = 1;\n\tbreak;\n      }\n      carry = 1;\n      i = (i + 1) & 0x3f;\n    } else {\n      nd[i] = val;\n      break;\n    }\n  }\n  return ndhi;\n}\n\n/* Test whether two \"nd\" values are equal in their most significant digits. */\nstatic int nd_similar(uint32_t* nd, uint32_t ndhi, uint32_t* ref, MSize hilen,\n\t\t      MSize prec)\n{\n  char nd9[9], ref9[9];\n  if (hilen <= prec) {\n    if (LJ_UNLIKELY(nd[ndhi] != *ref)) return 0;\n    prec -= hilen; ref--; ndhi = (ndhi - 1) & 0x3f;\n    if (prec >= 9) {\n      if (LJ_UNLIKELY(nd[ndhi] != *ref)) return 0;\n      prec -= 9; ref--; ndhi = (ndhi - 1) & 0x3f;\n    }\n  } else {\n    prec -= hilen - 9;\n  }\n  lua_assert(prec < 9);\n  lj_strfmt_wuint9(nd9, nd[ndhi]);\n  lj_strfmt_wuint9(ref9, *ref);\n  return !memcmp(nd9, ref9, prec) && (nd9[prec] < '5') == (ref9[prec] < '5');\n}\n\n/* -- Formatted conversions to buffer ------------------------------------- */\n\n/* Write formatted floating-point number to either sb or p. */\nstatic char *lj_strfmt_wfnum(SBuf *sb, SFormat sf, lua_Number n, char *p)\n{\n  MSize width = STRFMT_WIDTH(sf), prec = STRFMT_PREC(sf), len;\n  TValue t;\n  t.n = n;\n  if (LJ_UNLIKELY((t.u32.hi << 1) >= 0xffe00000)) {\n    /* Handle non-finite values uniformly for %a, %e, %f, %g. */\n    int prefix = 0, ch = (sf & STRFMT_F_UPPER) ? 0x202020 : 0;\n    if (((t.u32.hi & 0x000fffff) | t.u32.lo) != 0) {\n      ch ^= ('n' << 16) | ('a' << 8) | 'n';\n      if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    } else {\n      ch ^= ('i' << 16) | ('n' << 8) | 'f';\n      if ((t.u32.hi & 0x80000000)) prefix = '-';\n      else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n      else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    }\n    len = 3 + (prefix != 0);\n    if (!p) p = lj_buf_more(sb, width > len ? width : len);\n    if (!(sf & STRFMT_F_LEFT)) while (width-- > len) *p++ = ' ';\n    if (prefix) *p++ = prefix;\n    *p++ = (char)(ch >> 16); *p++ = (char)(ch >> 8); *p++ = (char)ch;\n  } else if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_A)) {\n    /* %a */\n    const char *hexdig = (sf & STRFMT_F_UPPER) ? \"0123456789ABCDEFPX\"\n\t\t\t\t\t       : \"0123456789abcdefpx\";\n    int32_t e = (t.u32.hi >> 20) & 0x7ff;\n    char prefix = 0, eprefix = '+';\n    if (t.u32.hi & 0x80000000) prefix = '-';\n    else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n    else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    t.u32.hi &= 0xfffff;\n    if (e) {\n      t.u32.hi |= 0x100000;\n      e -= 1023;\n    } else if (t.u32.lo | t.u32.hi) {\n      /* Non-zero denormal - normalise it. */\n      uint32_t shift = t.u32.hi ? 20-lj_fls(t.u32.hi) : 52-lj_fls(t.u32.lo);\n      e = -1022 - shift;\n      t.u64 <<= shift;\n    }\n    /* abs(n) == t.u64 * 2^(e - 52) */\n    /* If n != 0, bit 52 of t.u64 is set, and is the highest set bit. */\n    if ((int32_t)prec < 0) {\n      /* Default precision: use smallest precision giving exact result. */\n      prec = t.u32.lo ? 13-lj_ffs(t.u32.lo)/4 : 5-lj_ffs(t.u32.hi|0x100000)/4;\n    } else if (prec < 13) {\n      /* Precision is sufficiently low as to maybe require rounding. */\n      t.u64 += (((uint64_t)1) << (51 - prec*4));\n    }\n    if (e < 0) {\n      eprefix = '-';\n      e = -e;\n    }\n    len = 5 + ndigits_dec((uint32_t)e) + prec + (prefix != 0)\n\t    + ((prec | (sf & STRFMT_F_ALT)) != 0);\n    if (!p) p = lj_buf_more(sb, width > len ? width : len);\n    if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n      while (width-- > len) *p++ = ' ';\n    }\n    if (prefix) *p++ = prefix;\n    *p++ = '0';\n    *p++ = hexdig[17]; /* x or X */\n    if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n      while (width-- > len) *p++ = '0';\n    }\n    *p++ = '0' + (t.u32.hi >> 20); /* Usually '1', sometimes '0' or '2'. */\n    if ((prec | (sf & STRFMT_F_ALT))) {\n      /* Emit fractional part. */\n      char *q = p + 1 + prec;\n      *p = '.';\n      if (prec < 13) t.u64 >>= (52 - prec*4);\n      else while (prec > 13) p[prec--] = '0';\n      while (prec) { p[prec--] = hexdig[t.u64 & 15]; t.u64 >>= 4; }\n      p = q;\n    }\n    *p++ = hexdig[16]; /* p or P */\n    *p++ = eprefix; /* + or - */\n    p = lj_strfmt_wint(p, e);\n  } else {\n    /* %e or %f or %g - begin by converting n to \"nd\" format. */\n    uint32_t nd[64];\n    uint32_t ndhi = 0, ndlo, i;\n    int32_t e = (t.u32.hi >> 20) & 0x7ff, ndebias = 0;\n    char prefix = 0, *q;\n    if (t.u32.hi & 0x80000000) prefix = '-';\n    else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n    else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    prec += ((int32_t)prec >> 31) & 7; /* Default precision is 6. */\n    if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_G)) {\n      /* %g - decrement precision if non-zero (to make it like %e). */\n      prec--;\n      prec ^= (uint32_t)((int32_t)prec >> 31);\n    }\n    if ((sf & STRFMT_T_FP_E) && prec < 14 && n != 0) {\n      /* Precision is sufficiently low that rescaling will probably work. */\n      if ((ndebias = rescale_e[e >> 6])) {\n\tt.n = n * rescale_n[e >> 6];\n\tt.u64 -= 2; /* Convert 2ulp below (later we convert 2ulp above). */\n\tnd[0] = 0x100000 | (t.u32.hi & 0xfffff);\n\te = ((t.u32.hi >> 20) & 0x7ff) - 1075 - (ND_MUL2K_MAX_SHIFT < 29);\n\tgoto load_t_lo; rescale_failed:\n\tt.n = n;\n\te = (t.u32.hi >> 20) & 0x7ff;\n\tndebias = ndhi = 0;\n      }\n    }\n    nd[0] = t.u32.hi & 0xfffff;\n    if (e == 0) e++; else nd[0] |= 0x100000;\n    e -= 1043;\n    if (t.u32.lo) {\n      e -= 32 + (ND_MUL2K_MAX_SHIFT < 29); load_t_lo:\n#if ND_MUL2K_MAX_SHIFT >= 29\n      nd[0] = (nd[0] << 3) | (t.u32.lo >> 29);\n      ndhi = nd_mul2k(nd, ndhi, 29, t.u32.lo & 0x1fffffff, sf);\n#elif ND_MUL2K_MAX_SHIFT >= 11\n      ndhi = nd_mul2k(nd, ndhi, 11, t.u32.lo >> 21, sf);\n      ndhi = nd_mul2k(nd, ndhi, 11, (t.u32.lo >> 10) & 0x7ff, sf);\n      ndhi = nd_mul2k(nd, ndhi, 11, (t.u32.lo <<  1) & 0x7ff, sf);\n#else\n#error \"ND_MUL2K_MAX_SHIFT too small\"\n#endif\n    }\n    if (e >= 0) {\n      ndhi = nd_mul2k(nd, ndhi, (uint32_t)e, 0, sf);\n      ndlo = 0;\n    } else {\n      ndlo = nd_div2k(nd, ndhi, (uint32_t)-e, sf);\n      if (ndhi && !nd[ndhi]) ndhi--;\n    }\n    /* abs(n) == nd * 10^ndebias (for slightly loose interpretation of ==) */\n    if ((sf & STRFMT_T_FP_E)) {\n      /* %e or %g - assume %e and start by calculating nd's exponent (nde). */\n      char eprefix = '+';\n      int32_t nde = -1;\n      MSize hilen;\n      if (ndlo && !nd[ndhi]) {\n\tndhi = 64; do {} while (!nd[--ndhi]);\n\tnde -= 64 * 9;\n      }\n      hilen = ndigits_dec(nd[ndhi]);\n      nde += ndhi * 9 + hilen;\n      if (ndebias) {\n\t/*\n\t** Rescaling was performed, but this introduced some error, and might\n\t** have pushed us across a rounding boundary. We check whether this\n\t** error affected the result by introducing even more error (2ulp in\n\t** either direction), and seeing whether a roundary boundary was\n\t** crossed. Having already converted the -2ulp case, we save off its\n\t** most significant digits, convert the +2ulp case, and compare them.\n\t*/\n\tint32_t eidx = e + 70 + (ND_MUL2K_MAX_SHIFT < 29)\n\t\t\t + (t.u32.lo >= 0xfffffffe && !(~t.u32.hi << 12));\n\tconst int8_t *m_e = four_ulp_m_e + eidx * 2;\n\tlua_assert(0 <= eidx && eidx < 128);\n\tnd[33] = nd[ndhi];\n\tnd[32] = nd[(ndhi - 1) & 0x3f];\n\tnd[31] = nd[(ndhi - 2) & 0x3f];\n\tnd_add_m10e(nd, ndhi, (uint8_t)*m_e, m_e[1]);\n\tif (LJ_UNLIKELY(!nd_similar(nd, ndhi, nd + 33, hilen, prec + 1))) {\n\t  goto rescale_failed;\n\t}\n      }\n      if ((int32_t)(prec - nde) < (0x3f & -(int32_t)ndlo) * 9) {\n\t/* Precision is sufficiently low as to maybe require rounding. */\n\tndhi = nd_add_m10e(nd, ndhi, 5, nde - prec - 1);\n\tnde += (hilen != ndigits_dec(nd[ndhi]));\n      }\n      nde += ndebias;\n      if ((sf & STRFMT_T_FP_F)) {\n\t/* %g */\n\tif ((int32_t)prec >= nde && nde >= -4) {\n\t  if (nde < 0) ndhi = 0;\n\t  prec -= nde;\n\t  goto g_format_like_f;\n\t} else if (!(sf & STRFMT_F_ALT) && prec && width > 5) {\n\t  /* Decrease precision in order to strip trailing zeroes. */\n\t  char tail[9];\n\t  uint32_t maxprec = hilen - 1 + ((ndhi - ndlo) & 0x3f) * 9;\n\t  if (prec >= maxprec) prec = maxprec;\n\t  else ndlo = (ndhi - (((int32_t)(prec - hilen) + 9) / 9)) & 0x3f;\n\t  i = prec - hilen - (((ndhi - ndlo) & 0x3f) * 9) + 10;\n\t  lj_strfmt_wuint9(tail, nd[ndlo]);\n\t  while (prec && tail[--i] == '0') {\n\t    prec--;\n\t    if (!i) {\n\t      if (ndlo == ndhi) { prec = 0; break; }\n\t      lj_strfmt_wuint9(tail, nd[++ndlo]);\n\t      i = 9;\n\t    }\n\t  }\n\t}\n      }\n      if (nde < 0) {\n\t/* Make nde non-negative. */\n\teprefix = '-';\n\tnde = -nde;\n      }\n      len = 3 + prec + (prefix != 0) + ndigits_dec((uint32_t)nde) + (nde < 10)\n\t      + ((prec | (sf & STRFMT_F_ALT)) != 0);\n      if (!p) p = lj_buf_more(sb, (width > len ? width : len) + 5);\n      if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n\twhile (width-- > len) *p++ = ' ';\n      }\n      if (prefix) *p++ = prefix;\n      if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n\twhile (width-- > len) *p++ = '0';\n      }\n      q = lj_strfmt_wint(p + 1, nd[ndhi]);\n      p[0] = p[1]; /* Put leading digit in the correct place. */\n      if ((prec | (sf & STRFMT_F_ALT))) {\n\t/* Emit fractional part. */\n\tp[1] = '.'; p += 2;\n\tprec -= (q - p); p = q; /* Account for the digits already emitted. */\n\t/* Then emit chunks of 9 digits (this may emit 8 digits too many). */\n\tfor (i = ndhi; (int32_t)prec > 0 && i != ndlo; prec -= 9) {\n\t  i = (i - 1) & 0x3f;\n\t  p = lj_strfmt_wuint9(p, nd[i]);\n\t}\n\tif ((sf & STRFMT_T_FP_F) && !(sf & STRFMT_F_ALT)) {\n\t  /* %g (and not %#g) - strip trailing zeroes. */\n\t  p += (int32_t)prec & ((int32_t)prec >> 31);\n\t  while (p[-1] == '0') p--;\n\t  if (p[-1] == '.') p--;\n\t} else {\n\t  /* %e (or %#g) - emit trailing zeroes. */\n\t  while ((int32_t)prec > 0) { *p++ = '0'; prec--; }\n\t  p += (int32_t)prec;\n\t}\n      } else {\n\tp++;\n      }\n      *p++ = (sf & STRFMT_F_UPPER) ? 'E' : 'e';\n      *p++ = eprefix; /* + or - */\n      if (nde < 10) *p++ = '0'; /* Always at least two digits of exponent. */\n      p = lj_strfmt_wint(p, nde);\n    } else {\n      /* %f (or, shortly, %g in %f style) */\n      if (prec < (MSize)(0x3f & -(int32_t)ndlo) * 9) {\n\t/* Precision is sufficiently low as to maybe require rounding. */\n\tndhi = nd_add_m10e(nd, ndhi, 5, 0 - prec - 1);\n      }\n      g_format_like_f:\n      if ((sf & STRFMT_T_FP_E) && !(sf & STRFMT_F_ALT) && prec && width) {\n\t/* Decrease precision in order to strip trailing zeroes. */\n\tif (ndlo) {\n\t  /* nd has a fractional part; we need to look at its digits. */\n\t  char tail[9];\n\t  uint32_t maxprec = (64 - ndlo) * 9;\n\t  if (prec >= maxprec) prec = maxprec;\n\t  else ndlo = 64 - (prec + 8) / 9;\n\t  i = prec - ((63 - ndlo) * 9);\n\t  lj_strfmt_wuint9(tail, nd[ndlo]);\n\t  while (prec && tail[--i] == '0') {\n\t    prec--;\n\t    if (!i) {\n\t      if (ndlo == 63) { prec = 0; break; }\n\t      lj_strfmt_wuint9(tail, nd[++ndlo]);\n\t      i = 9;\n\t    }\n\t  }\n\t} else {\n\t  /* nd has no fractional part, so precision goes straight to zero. */\n\t  prec = 0;\n\t}\n      }\n      len = ndhi * 9 + ndigits_dec(nd[ndhi]) + prec + (prefix != 0)\n\t\t     + ((prec | (sf & STRFMT_F_ALT)) != 0);\n      if (!p) p = lj_buf_more(sb, (width > len ? width : len) + 8);\n      if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n\twhile (width-- > len) *p++ = ' ';\n      }\n      if (prefix) *p++ = prefix;\n      if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n\twhile (width-- > len) *p++ = '0';\n      }\n      /* Emit integer part. */\n      p = lj_strfmt_wint(p, nd[ndhi]);\n      i = ndhi;\n      while (i) p = lj_strfmt_wuint9(p, nd[--i]);\n      if ((prec | (sf & STRFMT_F_ALT))) {\n\t/* Emit fractional part. */\n\t*p++ = '.';\n\t/* Emit chunks of 9 digits (this may emit 8 digits too many). */\n\twhile ((int32_t)prec > 0 && i != ndlo) {\n\t  i = (i - 1) & 0x3f;\n\t  p = lj_strfmt_wuint9(p, nd[i]);\n\t  prec -= 9;\n\t}\n\tif ((sf & STRFMT_T_FP_E) && !(sf & STRFMT_F_ALT)) {\n\t  /* %g (and not %#g) - strip trailing zeroes. */\n\t  p += (int32_t)prec & ((int32_t)prec >> 31);\n\t  while (p[-1] == '0') p--;\n\t  if (p[-1] == '.') p--;\n\t} else {\n\t  /* %f (or %#g) - emit trailing zeroes. */\n\t  while ((int32_t)prec > 0) { *p++ = '0'; prec--; }\n\t  p += (int32_t)prec;\n\t}\n      }\n    }\n  }\n  if ((sf & STRFMT_F_LEFT)) while (width-- > len) *p++ = ' ';\n  return p;\n}\n\n/* Add formatted floating-point number to buffer. */\nSBuf *lj_strfmt_putfnum(SBuf *sb, SFormat sf, lua_Number n)\n{\n  setsbufP(sb, lj_strfmt_wfnum(sb, sf, n, NULL));\n  return sb;\n}\n\n/* -- Conversions to strings ---------------------------------------------- */\n\n/* Convert number to string. */\nGCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o)\n{\n  char buf[STRFMT_MAXBUF_NUM];\n  MSize len = (MSize)(lj_strfmt_wfnum(NULL, STRFMT_G14, o->n, buf) - buf);\n  return lj_str_new(L, buf, len);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_strscan.c",
    "content": "/*\n** String scanning.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <math.h>\n\n#define lj_strscan_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n\n/* -- Scanning numbers ---------------------------------------------------- */\n\n/*\n** Rationale for the builtin string to number conversion library:\n**\n** It removes a dependency on libc's strtod(), which is a true portability\n** nightmare. Mainly due to the plethora of supported OS and toolchain\n** combinations. Sadly, the various implementations\n** a) are often buggy, incomplete (no hex floats) and/or imprecise,\n** b) sometimes crash or hang on certain inputs,\n** c) return non-standard NaNs that need to be filtered out, and\n** d) fail if the locale-specific decimal separator is not a dot,\n**    which can only be fixed with atrocious workarounds.\n**\n** Also, most of the strtod() implementations are hopelessly bloated,\n** which is not just an I-cache hog, but a problem for static linkage\n** on embedded systems, too.\n**\n** OTOH the builtin conversion function is very compact. Even though it\n** does a lot more, like parsing long longs, octal or imaginary numbers\n** and returning the result in different formats:\n** a) It needs less than 3 KB (!) of machine code (on x64 with -Os),\n** b) it doesn't perform any dynamic allocation and,\n** c) it needs only around 600 bytes of stack space.\n**\n** The builtin function is faster than strtod() for typical inputs, e.g.\n** \"123\", \"1.5\" or \"1e6\". Arguably, it's slower for very large exponents,\n** which are not very common (this could be fixed, if needed).\n**\n** And most importantly, the builtin function is equally precise on all\n** platforms. It correctly converts and rounds any input to a double.\n** If this is not the case, please send a bug report -- but PLEASE verify\n** that the implementation you're comparing to is not the culprit!\n**\n** The implementation quickly pre-scans the entire string first and\n** handles simple integers on-the-fly. Otherwise, it dispatches to the\n** base-specific parser. Hex and octal is straightforward.\n**\n** Decimal to binary conversion uses a fixed-length circular buffer in\n** base 100. Some simple cases are handled directly. For other cases, the\n** number in the buffer is up-scaled or down-scaled until the integer part\n** is in the proper range. Then the integer part is rounded and converted\n** to a double which is finally rescaled to the result. Denormals need\n** special treatment to prevent incorrect 'double rounding'.\n*/\n\n/* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */\n#define STRSCAN_DIG\t1024\n#define STRSCAN_MAXDIG\t800\t\t/* 772 + extra are sufficient. */\n#define STRSCAN_DDIG\t(STRSCAN_DIG/2)\n#define STRSCAN_DMASK\t(STRSCAN_DDIG-1)\n\n/* Helpers for circular buffer. */\n#define DNEXT(a)\t(((a)+1) & STRSCAN_DMASK)\n#define DPREV(a)\t(((a)-1) & STRSCAN_DMASK)\n#define DLEN(lo, hi)\t((int32_t)(((lo)-(hi)) & STRSCAN_DMASK))\n\n#define casecmp(c, k)\t(((c) | 0x20) == k)\n\n/* Final conversion to double. */\nstatic void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg)\n{\n  double n;\n\n  /* Avoid double rounding for denormals. */\n  if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) {\n    /* NYI: all of this generates way too much code on 32 bit CPUs. */\n#if defined(__GNUC__) && LJ_64\n    int32_t b = (int32_t)(__builtin_clzll(x)^63);\n#else\n    int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) :\n\t\t\t  (int32_t)lj_fls((uint32_t)x);\n#endif\n    if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) {\n      uint64_t rb = (uint64_t)1 << (-1075-ex2);\n      if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb;\n      x = (x & ~(rb+rb-1));\n    }\n  }\n\n  /* Convert to double using a signed int64_t conversion, then rescale. */\n  lua_assert((int64_t)x >= 0);\n  n = (double)(int64_t)x;\n  if (neg) n = -n;\n  if (ex2) n = ldexp(n, ex2);\n  o->n = n;\n}\n\n/* Parse hexadecimal number. */\nstatic StrScanFmt strscan_hex(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex2, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n  uint32_t i;\n\n  /* Scan hex digits. */\n  for (i = dig > 16 ? 16 : dig ; i; i--, p++) {\n    uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9;\n    x = (x << 4) + (d & 15);\n  }\n\n  /* Summarize rounding-effect of excess digits. */\n  for (i = 16; i < dig; i++, p++)\n    x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4;\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n      o->i = neg ? -(int32_t)x : (int32_t)x;\n      return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n    }\n    if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }\n    /* fallthrough */\n  case STRSCAN_U32:\n    if (dig > 8) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    return STRSCAN_U32;\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    if (dig > 16) return STRSCAN_ERROR;\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    return fmt;\n  default:\n    break;\n  }\n\n  /* Reduce range, then convert to double. */\n  if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }\n  strscan_double(x, o, ex2, neg);\n  return fmt;\n}\n\n/* Parse octal number. */\nstatic StrScanFmt strscan_oct(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n\n  /* Scan octal digits. */\n  if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR;\n  while (dig-- > 0) {\n    if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR;\n    x = (x << 3) + (*p++ & 7);\n  }\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (x >= 0x80000000u+neg) fmt = STRSCAN_U32;\n    /* fallthrough */\n  case STRSCAN_U32:\n    if ((x >> 32)) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    break;\n  default:\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    break;\n  }\n  return fmt;\n}\n\n/* Parse decimal number. */\nstatic StrScanFmt strscan_dec(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex10, int32_t neg, uint32_t dig)\n{\n  uint8_t xi[STRSCAN_DDIG], *xip = xi;\n\n  if (dig) {\n    uint32_t i = dig;\n    if (i > STRSCAN_MAXDIG) {\n      ex10 += (int32_t)(i - STRSCAN_MAXDIG);\n      i = STRSCAN_MAXDIG;\n    }\n    /* Scan unaligned leading digit. */\n    if (((ex10^i) & 1))\n      *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++;\n    /* Scan aligned double-digits. */\n    for ( ; i > 1; i -= 2) {\n      uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++;\n      *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++;\n    }\n    /* Scan and realign trailing digit. */\n    if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, dig++, p++;\n\n    /* Summarize rounding-effect of excess digits. */\n    if (dig > STRSCAN_MAXDIG) {\n      do {\n\tif ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; }\n\tp++;\n      } while (--dig > STRSCAN_MAXDIG);\n      dig = STRSCAN_MAXDIG;\n    } else {  /* Simplify exponent. */\n      while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2;\n    }\n  } else {  /* Only got zeros. */\n    ex10 = 0;\n    xi[0] = 0;\n  }\n\n  /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */\n  if (dig <= 20 && ex10 == 0) {\n    uint8_t *xis;\n    uint64_t x = xi[0];\n    double n;\n    for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis;\n    if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) {  /* No overflow? */\n      /* Format-specific handling. */\n      switch (fmt) {\n      case STRSCAN_INT:\n\tif (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n\t  o->i = neg ? -(int32_t)x : (int32_t)x;\n\t  return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n\t}\n\tif (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }\n\t/* fallthrough */\n      case STRSCAN_U32:\n\tif ((x >> 32) != 0) return STRSCAN_ERROR;\n\to->i = neg ? -(int32_t)x : (int32_t)x;\n\treturn STRSCAN_U32;\n      case STRSCAN_I64:\n      case STRSCAN_U64:\n\to->u64 = neg ? (uint64_t)-(int64_t)x : x;\n\treturn fmt;\n      default:\n      plainnumber:  /* Fast path for plain numbers < 2^63. */\n\tif ((int64_t)x < 0) break;\n\tn = (double)(int64_t)x;\n\tif (neg) n = -n;\n\to->n = n;\n\treturn fmt;\n      }\n    }\n  }\n\n  /* Slow non-integer path. */\n  if (fmt == STRSCAN_INT) {\n    if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;\n    fmt = STRSCAN_NUM;\n  } else if (fmt > STRSCAN_INT) {\n    return STRSCAN_ERROR;\n  }\n  {\n    uint32_t hi = 0, lo = (uint32_t)(xip-xi);\n    int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1);\n\n    lua_assert(lo > 0 && (ex10 & 1) == 0);\n\n    /* Handle simple overflow/underflow. */\n    if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; }\n    else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; }\n\n    /* Scale up until we have at least 17 or 18 integer part digits. */\n    while (idig < 9 && idig < DLEN(lo, hi)) {\n      uint32_t i, cy = 0;\n      ex2 -= 6;\n      for (i = DPREV(lo); ; i = DPREV(i)) {\n\tuint32_t d = (xi[i] << 6) + cy;\n\tcy = (((d >> 2) * 5243) >> 17); d = d - cy * 100;  /* Div/mod 100. */\n\txi[i] = (uint8_t)d;\n\tif (i == hi) break;\n\tif (d == 0 && i == DPREV(lo)) lo = i;\n      }\n      if (cy) {\n\thi = DPREV(hi);\n\tif (xi[DPREV(lo)] == 0) lo = DPREV(lo);\n\telse if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; }\n\txi[hi] = (uint8_t)cy; idig++;\n      }\n    }\n\n    /* Scale down until no more than 17 or 18 integer part digits remain. */\n    while (idig > 9) {\n      uint32_t i = hi, cy = 0;\n      ex2 += 6;\n      do {\n\tcy += xi[i];\n\txi[i] = (cy >> 6);\n\tcy = 100 * (cy & 0x3f);\n\tif (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--;\n\ti = DNEXT(i);\n      } while (i != lo);\n      while (cy) {\n\tif (hi == lo) { xi[DPREV(lo)] |= 1; break; }\n\txi[lo] = (cy >> 6); lo = DNEXT(lo);\n\tcy = 100 * (cy & 0x3f);\n      }\n    }\n\n    /* Collect integer part digits and convert to rescaled double. */\n    {\n      uint64_t x = xi[hi];\n      uint32_t i;\n      for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i))\n\tx = x * 100 + xi[i];\n      if (i == lo) {\n\twhile (--idig >= 0) x = x * 100;\n      } else {  /* Gather round bit from remaining digits. */\n\tx <<= 1; ex2--;\n\tdo {\n\t  if (xi[i]) { x |= 1; break; }\n\t  i = DNEXT(i);\n\t} while (i != lo);\n      }\n      strscan_double(x, o, ex2, neg);\n    }\n  }\n  return fmt;\n}\n\n/* Parse binary number. */\nstatic StrScanFmt strscan_bin(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex2, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n  uint32_t i;\n\n  if (ex2 || dig > 64) return STRSCAN_ERROR;\n\n  /* Scan binary digits. */\n  for (i = dig; i; i--, p++) {\n    if ((*p & ~1) != '0') return STRSCAN_ERROR;\n    x = (x << 1) | (*p & 1);\n  }\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n      o->i = neg ? -(int32_t)x : (int32_t)x;\n      return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n    }\n    if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }\n    /* fallthrough */\n  case STRSCAN_U32:\n    if (dig > 32) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    return STRSCAN_U32;\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    return fmt;\n  default:\n    break;\n  }\n\n  /* Reduce range, then convert to double. */\n  if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }\n  strscan_double(x, o, ex2, neg);\n  return fmt;\n}\n\n/* Scan string containing a number. Returns format. Returns value in o. */\nStrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt)\n{\n  int32_t neg = 0;\n\n  /* Remove leading space, parse sign and non-numbers. */\n  if (LJ_UNLIKELY(!lj_char_isdigit(*p))) {\n    while (lj_char_isspace(*p)) p++;\n    if (*p == '+' || *p == '-') neg = (*p++ == '-');\n    if (LJ_UNLIKELY(*p >= 'A')) {  /* Parse \"inf\", \"infinity\" or \"nan\". */\n      TValue tmp;\n      setnanV(&tmp);\n      if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) {\n\tif (neg) setminfV(&tmp); else setpinfV(&tmp);\n\tp += 3;\n\tif (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') &&\n\t    casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5;\n      } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) {\n\tp += 3;\n      }\n      while (lj_char_isspace(*p)) p++;\n      if (*p) return STRSCAN_ERROR;\n      o->u64 = tmp.u64;\n      return STRSCAN_NUM;\n    }\n  }\n\n  /* Parse regular number. */\n  {\n    StrScanFmt fmt = STRSCAN_INT;\n    int cmask = LJ_CHAR_DIGIT;\n    int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10;\n    const uint8_t *sp, *dp = NULL;\n    uint32_t dig = 0, hasdig = 0, x = 0;\n    int32_t ex = 0;\n\n    /* Determine base and skip leading zeros. */\n    if (LJ_UNLIKELY(*p <= '0')) {\n      if (*p == '0') {\n\tif (casecmp(p[1], 'x'))\n\t  base = 16, cmask = LJ_CHAR_XDIGIT, p += 2;\n\telse if (casecmp(p[1], 'b'))\n\t  base = 2, cmask = LJ_CHAR_DIGIT, p += 2;\n      }\n      for ( ; ; p++) {\n\tif (*p == '0') {\n\t  hasdig = 1;\n\t} else if (*p == '.') {\n\t  if (dp) return STRSCAN_ERROR;\n\t  dp = p;\n\t} else {\n\t  break;\n\t}\n      }\n    }\n\n    /* Preliminary digit and decimal point scan. */\n    for (sp = p; ; p++) {\n      if (LJ_LIKELY(lj_char_isa(*p, cmask))) {\n\tx = x * 10 + (*p & 15);  /* For fast path below. */\n\tdig++;\n      } else if (*p == '.') {\n\tif (dp) return STRSCAN_ERROR;\n\tdp = p;\n      } else {\n\tbreak;\n      }\n    }\n    if (!(hasdig | dig)) return STRSCAN_ERROR;\n\n    /* Handle decimal point. */\n    if (dp) {\n      fmt = STRSCAN_NUM;\n      if (dig) {\n\tex = (int32_t)(dp-(p-1)); dp = p-1;\n\twhile (ex < 0 && *dp-- == '0') ex++, dig--;  /* Skip trailing zeros. */\n\tif (base == 16) ex *= 4;\n      }\n    }\n\n    /* Parse exponent. */\n    if (base >= 10 && casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) {\n      uint32_t xx;\n      int negx = 0;\n      fmt = STRSCAN_NUM; p++;\n      if (*p == '+' || *p == '-') negx = (*p++ == '-');\n      if (!lj_char_isdigit(*p)) return STRSCAN_ERROR;\n      xx = (*p++ & 15);\n      while (lj_char_isdigit(*p)) {\n\tif (xx < 65536) xx = xx * 10 + (*p & 15);\n\tp++;\n      }\n      ex += negx ? -(int32_t)xx : (int32_t)xx;\n    }\n\n    /* Parse suffix. */\n    if (*p) {\n      /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */\n      /* NYI: f (float). Not needed until cp_number() handles non-integers. */\n      if (casecmp(*p, 'i')) {\n\tif (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR;\n\tp++; fmt = STRSCAN_IMAG;\n      } else if (fmt == STRSCAN_INT) {\n\tif (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32;\n\tif (casecmp(*p, 'l')) {\n\t  p++;\n\t  if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT;\n\t  else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;\n\t  else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT;\n\t}\n\tif (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64))\n\t  p++, fmt += STRSCAN_U32 - STRSCAN_INT;\n\tif ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) ||\n\t    (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL)))\n\t  return STRSCAN_ERROR;\n      }\n      while (lj_char_isspace(*p)) p++;\n      if (*p) return STRSCAN_ERROR;\n    }\n\n    /* Fast path for decimal 32 bit integers. */\n    if (fmt == STRSCAN_INT && base == 10 &&\n\t(dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) {\n      int32_t y = neg ? -(int32_t)x : (int32_t)x;\n      if ((opt & STRSCAN_OPT_TONUM)) {\n\to->n = (double)y;\n\treturn STRSCAN_NUM;\n      } else {\n\to->i = y;\n\treturn STRSCAN_INT;\n      }\n    }\n\n    /* Dispatch to base-specific parser. */\n    if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG))\n      return strscan_oct(sp, o, fmt, neg, dig);\n    if (base == 16)\n      fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig);\n    else if (base == 2)\n      fmt = strscan_bin(sp, o, fmt, opt, ex, neg, dig);\n    else\n      fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig);\n\n    /* Try to convert number to integer, if requested. */\n    if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) {\n      double n = o->n;\n      int32_t i = lj_num2int(n);\n      if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; }\n    }\n    return fmt;\n  }\n}\n\nint LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o)\n{\n  StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,\n\t\t\t\t   STRSCAN_OPT_TONUM);\n  lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM);\n  return (fmt != STRSCAN_ERROR);\n}\n\n#if LJ_DUALNUM\nint LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o)\n{\n  StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,\n\t\t\t\t   STRSCAN_OPT_TOINT);\n  lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT);\n  if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM);\n  return (fmt != STRSCAN_ERROR);\n}\n#endif\n\n#undef DNEXT\n#undef DPREV\n#undef DLEN\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_strscan.h",
    "content": "/*\n** String scanning.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STRSCAN_H\n#define _LJ_STRSCAN_H\n\n#include \"lj_obj.h\"\n\n/* Options for accepted/returned formats. */\n#define STRSCAN_OPT_TOINT\t0x01  /* Convert to int32_t, if possible. */\n#define STRSCAN_OPT_TONUM\t0x02  /* Always convert to double. */\n#define STRSCAN_OPT_IMAG\t0x04\n#define STRSCAN_OPT_LL\t\t0x08\n#define STRSCAN_OPT_C\t\t0x10\n\n/* Returned format. */\ntypedef enum {\n  STRSCAN_ERROR,\n  STRSCAN_NUM, STRSCAN_IMAG,\n  STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,\n} StrScanFmt;\n\nLJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt);\nLJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);\n#if LJ_DUALNUM\nLJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);\n#else\n#define lj_strscan_number(s, o)\t\tlj_strscan_num((s), (o))\n#endif\n\n/* Check for number or convert string to number/int in-place (!). */\nstatic LJ_AINLINE int lj_strscan_numberobj(TValue *o)\n{\n  return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_tab.c",
    "content": "/*\n** Table handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_tab_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n\n/* -- Object hashing ------------------------------------------------------ */\n\n/* Hash values are masked with the table hash mask and used as an index. */\nstatic LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash)\n{\n  Node *n = noderef(t->node);\n  return &n[hash & t->hmask];\n}\n\n/* String hashes are precomputed when they are interned. */\n#define hashstr(t, s)\t\thashmask(t, (s)->hash)\n\n#define hashlohi(t, lo, hi)\thashmask((t), hashrot((lo), (hi)))\n#define hashnum(t, o)\t\thashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1))\n#define hashptr(t, p)\t\thashlohi((t), u32ptr(p), u32ptr(p) + HASH_BIAS)\n#if LJ_GC64\n#define hashgcref(t, r) \\\n  hashlohi((t), (uint32_t)gcrefu(r), (uint32_t)(gcrefu(r) >> 32))\n#else\n#define hashgcref(t, r)\t\thashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS)\n#endif\n\n/* Hash an arbitrary key and return its anchor position in the hash table. */\nstatic Node *hashkey(const GCtab *t, cTValue *key)\n{\n  lua_assert(!tvisint(key));\n  if (tvisstr(key))\n    return hashstr(t, strV(key));\n  else if (tvisnum(key))\n    return hashnum(t, key);\n  else if (tvisbool(key))\n    return hashmask(t, boolV(key));\n  else\n    return hashgcref(t, key->gcr);\n  /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */\n}\n\n/* -- Table creation and destruction -------------------------------------- */\n\n/* Create new hash part for table. */\nstatic LJ_AINLINE void newhpart(lua_State *L, GCtab *t, uint32_t hbits)\n{\n  uint32_t hsize;\n  Node *node;\n  lua_assert(hbits != 0);\n  if (hbits > LJ_MAX_HBITS)\n    lj_err_msg(L, LJ_ERR_TABOV);\n  hsize = 1u << hbits;\n  node = lj_mem_newvec(L, hsize, Node);\n  setmref(t->node, node);\n  setfreetop(t, node, &node[hsize]);\n  t->hmask = hsize-1;\n}\n\n/*\n** Q: Why all of these copies of t->hmask, t->node etc. to local variables?\n** A: Because alias analysis for C is _really_ tough.\n**    Even state-of-the-art C compilers won't produce good code without this.\n*/\n\n/* Clear hash part of table. */\nstatic LJ_AINLINE void clearhpart(GCtab *t)\n{\n  uint32_t i, hmask = t->hmask;\n  Node *node = noderef(t->node);\n  lua_assert(t->hmask != 0);\n  for (i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    setmref(n->next, NULL);\n    setnilV(&n->key);\n    setnilV(&n->val);\n  }\n}\n\n/* Clear array part of table. */\nstatic LJ_AINLINE void clearapart(GCtab *t)\n{\n  uint32_t i, asize = t->asize;\n  TValue *array = tvref(t->array);\n  for (i = 0; i < asize; i++)\n    setnilV(&array[i]);\n}\n\n/* Create a new table. Note: the slots are not initialized (yet). */\nstatic GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)\n{\n  GCtab *t;\n  /* First try to colocate the array part. */\n  if (LJ_MAX_COLOSIZE != 0 && asize > 0 && asize <= LJ_MAX_COLOSIZE) {\n    Node *nilnode;\n    lua_assert((sizeof(GCtab) & 7) == 0);\n    t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));\n    t->gct = ~LJ_TTAB;\n    t->nomm = (uint8_t)~0;\n    t->colo = (int8_t)asize;\n    setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));\n    setgcrefnull(t->metatable);\n    t->asize = asize;\n    t->hmask = 0;\n    nilnode = &G(L)->nilnode;\n    setmref(t->node, nilnode);\n#if LJ_GC64\n    setmref(t->freetop, nilnode);\n#endif\n  } else {  /* Otherwise separately allocate the array part. */\n    Node *nilnode;\n    t = lj_mem_newobj(L, GCtab);\n    t->gct = ~LJ_TTAB;\n    t->nomm = (uint8_t)~0;\n    t->colo = 0;\n    setmref(t->array, NULL);\n    setgcrefnull(t->metatable);\n    t->asize = 0;  /* In case the array allocation fails. */\n    t->hmask = 0;\n    nilnode = &G(L)->nilnode;\n    setmref(t->node, nilnode);\n#if LJ_GC64\n    setmref(t->freetop, nilnode);\n#endif\n    if (asize > 0) {\n      if (asize > LJ_MAX_ASIZE)\n\tlj_err_msg(L, LJ_ERR_TABOV);\n      setmref(t->array, lj_mem_newvec(L, asize, TValue));\n      t->asize = asize;\n    }\n  }\n  if (hbits)\n    newhpart(L, t, hbits);\n  return t;\n}\n\n/* Create a new table.\n**\n** IMPORTANT NOTE: The API differs from lua_createtable()!\n**\n** The array size is non-inclusive. E.g. asize=128 creates array slots\n** for 0..127, but not for 128. If you need slots 1..128, pass asize=129\n** (slot 0 is wasted in this case).\n**\n** The hash size is given in hash bits. hbits=0 means no hash part.\n** hbits=1 creates 2 hash slots, hbits=2 creates 4 hash slots and so on.\n*/\nGCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits)\n{\n  GCtab *t = newtab(L, asize, hbits);\n  clearapart(t);\n  if (t->hmask > 0) clearhpart(t);\n  return t;\n}\n\n/* The API of this function conforms to lua_createtable(). */\nGCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h)\n{\n  return lj_tab_new(L, (uint32_t)(a > 0 ? a+1 : 0), hsize2hbits(h));\n}\n\n#if LJ_HASJIT\nGCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize)\n{\n  GCtab *t = newtab(L, ahsize & 0xffffff, ahsize >> 24);\n  clearapart(t);\n  if (t->hmask > 0) clearhpart(t);\n  return t;\n}\n#endif\n\n/* Duplicate a table. */\nGCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt)\n{\n  GCtab *t;\n  uint32_t asize, hmask;\n  t = newtab(L, kt->asize, kt->hmask > 0 ? lj_fls(kt->hmask)+1 : 0);\n  lua_assert(kt->asize == t->asize && kt->hmask == t->hmask);\n  t->nomm = 0;  /* Keys with metamethod names may be present. */\n  asize = kt->asize;\n  if (asize > 0) {\n    TValue *array = tvref(t->array);\n    TValue *karray = tvref(kt->array);\n    if (asize < 64) {  /* An inlined loop beats memcpy for < 512 bytes. */\n      uint32_t i;\n      for (i = 0; i < asize; i++)\n\tcopyTV(L, &array[i], &karray[i]);\n    } else {\n      memcpy(array, karray, asize*sizeof(TValue));\n    }\n  }\n  hmask = kt->hmask;\n  if (hmask > 0) {\n    uint32_t i;\n    Node *node = noderef(t->node);\n    Node *knode = noderef(kt->node);\n    ptrdiff_t d = (char *)node - (char *)knode;\n    setfreetop(t, node, (Node *)((char *)getfreetop(kt, knode) + d));\n    for (i = 0; i <= hmask; i++) {\n      Node *kn = &knode[i];\n      Node *n = &node[i];\n      Node *next = nextnode(kn);\n      /* Don't use copyTV here, since it asserts on a copy of a dead key. */\n      n->val = kn->val; n->key = kn->key;\n      setmref(n->next, next == NULL? next : (Node *)((char *)next + d));\n    }\n  }\n  return t;\n}\n\n/* Clear a table. */\nvoid LJ_FASTCALL lj_tab_clear(GCtab *t)\n{\n  clearapart(t);\n  if (t->hmask > 0) {\n    Node *node = noderef(t->node);\n    setfreetop(t, node, &node[t->hmask+1]);\n    clearhpart(t);\n  }\n}\n\n/* Free a table. */\nvoid LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)\n{\n  if (t->hmask > 0)\n    lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);\n  if (t->asize > 0 && LJ_MAX_COLOSIZE != 0 && t->colo <= 0)\n    lj_mem_freevec(g, tvref(t->array), t->asize, TValue);\n  if (LJ_MAX_COLOSIZE != 0 && t->colo)\n    lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));\n  else\n    lj_mem_freet(g, t);\n}\n\n/* -- Table resizing ------------------------------------------------------ */\n\n/* Resize a table to fit the new array/hash part sizes. */\nvoid lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits)\n{\n  Node *oldnode = noderef(t->node);\n  uint32_t oldasize = t->asize;\n  uint32_t oldhmask = t->hmask;\n  if (asize > oldasize) {  /* Array part grows? */\n    TValue *array;\n    uint32_t i;\n    if (asize > LJ_MAX_ASIZE)\n      lj_err_msg(L, LJ_ERR_TABOV);\n    if (LJ_MAX_COLOSIZE != 0 && t->colo > 0) {\n      /* A colocated array must be separated and copied. */\n      TValue *oarray = tvref(t->array);\n      array = lj_mem_newvec(L, asize, TValue);\n      t->colo = (int8_t)(t->colo | 0x80);  /* Mark as separated (colo < 0). */\n      for (i = 0; i < oldasize; i++)\n\tcopyTV(L, &array[i], &oarray[i]);\n    } else {\n      array = (TValue *)lj_mem_realloc(L, tvref(t->array),\n\t\t\t  oldasize*sizeof(TValue), asize*sizeof(TValue));\n    }\n    setmref(t->array, array);\n    t->asize = asize;\n    for (i = oldasize; i < asize; i++)  /* Clear newly allocated slots. */\n      setnilV(&array[i]);\n  }\n  /* Create new (empty) hash part. */\n  if (hbits) {\n    newhpart(L, t, hbits);\n    clearhpart(t);\n  } else {\n    global_State *g = G(L);\n    setmref(t->node, &g->nilnode);\n#if LJ_GC64\n    setmref(t->freetop, &g->nilnode);\n#endif\n    t->hmask = 0;\n  }\n  if (asize < oldasize) {  /* Array part shrinks? */\n    TValue *array = tvref(t->array);\n    uint32_t i;\n    t->asize = asize;  /* Note: This 'shrinks' even colocated arrays. */\n    for (i = asize; i < oldasize; i++)  /* Reinsert old array values. */\n      if (!tvisnil(&array[i]))\n\tcopyTV(L, lj_tab_setinth(L, t, (int32_t)i), &array[i]);\n    /* Physically shrink only separated arrays. */\n    if (LJ_MAX_COLOSIZE != 0 && t->colo <= 0)\n      setmref(t->array, lj_mem_realloc(L, array,\n\t      oldasize*sizeof(TValue), asize*sizeof(TValue)));\n  }\n  if (oldhmask > 0) {  /* Reinsert pairs from old hash part. */\n    global_State *g;\n    uint32_t i;\n    for (i = 0; i <= oldhmask; i++) {\n      Node *n = &oldnode[i];\n      if (!tvisnil(&n->val))\n\tcopyTV(L, lj_tab_set(L, t, &n->key), &n->val);\n    }\n    g = G(L);\n    lj_mem_freevec(g, oldnode, oldhmask+1, Node);\n  }\n}\n\nstatic uint32_t countint(cTValue *key, uint32_t *bins)\n{\n  lua_assert(!tvisint(key));\n  if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if ((uint32_t)k < LJ_MAX_ASIZE && nk == (lua_Number)k) {\n      bins[(k > 2 ? lj_fls((uint32_t)(k-1)) : 0)]++;\n      return 1;\n    }\n  }\n  return 0;\n}\n\nstatic uint32_t countarray(const GCtab *t, uint32_t *bins)\n{\n  uint32_t na, b, i;\n  if (t->asize == 0) return 0;\n  for (na = i = b = 0; b < LJ_MAX_ABITS; b++) {\n    uint32_t n, top = 2u << b;\n    TValue *array;\n    if (top >= t->asize) {\n      top = t->asize-1;\n      if (i > top)\n\tbreak;\n    }\n    array = tvref(t->array);\n    for (n = 0; i <= top; i++)\n      if (!tvisnil(&array[i]))\n\tn++;\n    bins[b] += n;\n    na += n;\n  }\n  return na;\n}\n\nstatic uint32_t counthash(const GCtab *t, uint32_t *bins, uint32_t *narray)\n{\n  uint32_t total, na, i, hmask = t->hmask;\n  Node *node = noderef(t->node);\n  for (total = na = 0, i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    if (!tvisnil(&n->val)) {\n      na += countint(&n->key, bins);\n      total++;\n    }\n  }\n  *narray += na;\n  return total;\n}\n\nstatic uint32_t bestasize(uint32_t bins[], uint32_t *narray)\n{\n  uint32_t b, sum, na = 0, sz = 0, nn = *narray;\n  for (b = 0, sum = 0; 2*nn > (1u<<b) && sum != nn; b++)\n    if (bins[b] > 0 && 2*(sum += bins[b]) > (1u<<b)) {\n      sz = (2u<<b)+1;\n      na = sum;\n    }\n  *narray = sz;\n  return na;\n}\n\nstatic void rehashtab(lua_State *L, GCtab *t, cTValue *ek)\n{\n  uint32_t bins[LJ_MAX_ABITS];\n  uint32_t total, asize, na, i;\n  for (i = 0; i < LJ_MAX_ABITS; i++) bins[i] = 0;\n  asize = countarray(t, bins);\n  total = 1 + asize;\n  total += counthash(t, bins, &asize);\n  asize += countint(ek, bins);\n  na = bestasize(bins, &asize);\n  total -= na;\n  lj_tab_resize(L, t, asize, hsize2hbits(total));\n}\n\n#if LJ_HASFFI\nvoid lj_tab_rehash(lua_State *L, GCtab *t)\n{\n  rehashtab(L, t, niltv(L));\n}\n#endif\n\nvoid lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize)\n{\n  lj_tab_resize(L, t, nasize+1, t->hmask > 0 ? lj_fls(t->hmask)+1 : 0);\n}\n\n/* -- Table getters ------------------------------------------------------- */\n\ncTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key)\n{\n  TValue k;\n  Node *n;\n  k.n = (lua_Number)key;\n  n = hashnum(t, &k);\n  do {\n    if (tvisnum(&n->key) && n->key.n == k.n)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return NULL;\n}\n\ncTValue *lj_tab_getstr(GCtab *t, GCstr *key)\n{\n  Node *n = hashstr(t, key);\n  do {\n    if (tvisstr(&n->key) && strV(&n->key) == key)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return NULL;\n}\n\ncTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key)\n{\n  if (tvisstr(key)) {\n    cTValue *tv = lj_tab_getstr(t, strV(key));\n    if (tv)\n      return tv;\n  } else if (tvisint(key)) {\n    cTValue *tv = lj_tab_getint(t, intV(key));\n    if (tv)\n      return tv;\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if (nk == (lua_Number)k) {\n      cTValue *tv = lj_tab_getint(t, k);\n      if (tv)\n\treturn tv;\n    } else {\n      goto genlookup;  /* Else use the generic lookup. */\n    }\n  } else if (!tvisnil(key)) {\n    Node *n;\n  genlookup:\n    n = hashkey(t, key);\n    do {\n      if (lj_obj_equal(&n->key, key))\n\treturn &n->val;\n    } while ((n = nextnode(n)));\n  }\n  return niltv(L);\n}\n\n/* -- Table setters ------------------------------------------------------- */\n\n/* Insert new key. Use Brent's variation to optimize the chain length. */\nTValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key)\n{\n  Node *n = hashkey(t, key);\n  if (!tvisnil(&n->val) || t->hmask == 0) {\n    Node *nodebase = noderef(t->node);\n    Node *collide, *freenode = getfreetop(t, nodebase);\n    lua_assert(freenode >= nodebase && freenode <= nodebase+t->hmask+1);\n    do {\n      if (freenode == nodebase) {  /* No free node found? */\n\trehashtab(L, t, key);  /* Rehash table. */\n\treturn lj_tab_set(L, t, key);  /* Retry key insertion. */\n      }\n    } while (!tvisnil(&(--freenode)->key));\n    setfreetop(t, nodebase, freenode);\n    lua_assert(freenode != &G(L)->nilnode);\n    collide = hashkey(t, &n->key);\n    if (collide != n) {  /* Colliding node not the main node? */\n      while (noderef(collide->next) != n)  /* Find predecessor. */\n\tcollide = nextnode(collide);\n      setmref(collide->next, freenode);  /* Relink chain. */\n      /* Copy colliding node into free node and free main node. */\n      freenode->val = n->val;\n      freenode->key = n->key;\n      freenode->next = n->next;\n      setmref(n->next, NULL);\n      setnilV(&n->val);\n      /* Rechain pseudo-resurrected string keys with colliding hashes. */\n      while (nextnode(freenode)) {\n\tNode *nn = nextnode(freenode);\n\tif (tvisstr(&nn->key) && !tvisnil(&nn->val) &&\n\t    hashstr(t, strV(&nn->key)) == n) {\n\t  freenode->next = nn->next;\n\t  nn->next = n->next;\n\t  setmref(n->next, nn);\n\t} else {\n\t  freenode = nn;\n\t}\n      }\n    } else {  /* Otherwise use free node. */\n      setmrefr(freenode->next, n->next);  /* Insert into chain. */\n      setmref(n->next, freenode);\n      n = freenode;\n    }\n  }\n  n->key.u64 = key->u64;\n  if (LJ_UNLIKELY(tvismzero(&n->key)))\n    n->key.u64 = 0;\n  lj_gc_anybarriert(L, t);\n  lua_assert(tvisnil(&n->val));\n  return &n->val;\n}\n\nTValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key)\n{\n  TValue k;\n  Node *n;\n  k.n = (lua_Number)key;\n  n = hashnum(t, &k);\n  do {\n    if (tvisnum(&n->key) && n->key.n == k.n)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return lj_tab_newkey(L, t, &k);\n}\n\nTValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key)\n{\n  TValue k;\n  Node *n = hashstr(t, key);\n  do {\n    if (tvisstr(&n->key) && strV(&n->key) == key)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  setstrV(L, &k, key);\n  return lj_tab_newkey(L, t, &k);\n}\n\nTValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key)\n{\n  Node *n;\n  t->nomm = 0;  /* Invalidate negative metamethod cache. */\n  if (tvisstr(key)) {\n    return lj_tab_setstr(L, t, strV(key));\n  } else if (tvisint(key)) {\n    return lj_tab_setint(L, t, intV(key));\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if (nk == (lua_Number)k)\n      return lj_tab_setint(L, t, k);\n    if (tvisnan(key))\n      lj_err_msg(L, LJ_ERR_NANIDX);\n    /* Else use the generic lookup. */\n  } else if (tvisnil(key)) {\n    lj_err_msg(L, LJ_ERR_NILIDX);\n  }\n  n = hashkey(t, key);\n  do {\n    if (lj_obj_equal(&n->key, key))\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return lj_tab_newkey(L, t, key);\n}\n\n/* -- Table traversal ----------------------------------------------------- */\n\n/* Get the traversal index of a key. */\nstatic uint32_t keyindex(lua_State *L, GCtab *t, cTValue *key)\n{\n  TValue tmp;\n  if (tvisint(key)) {\n    int32_t k = intV(key);\n    if ((uint32_t)k < t->asize)\n      return (uint32_t)k;  /* Array key indexes: [0..t->asize-1] */\n    setnumV(&tmp, (lua_Number)k);\n    key = &tmp;\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if ((uint32_t)k < t->asize && nk == (lua_Number)k)\n      return (uint32_t)k;  /* Array key indexes: [0..t->asize-1] */\n  }\n  if (!tvisnil(key)) {\n    Node *n = hashkey(t, key);\n    do {\n      if (lj_obj_equal(&n->key, key))\n\treturn t->asize + (uint32_t)(n - noderef(t->node));\n\t/* Hash key indexes: [t->asize..t->asize+t->nmask] */\n    } while ((n = nextnode(n)));\n    if (key->u32.hi == 0xfffe7fff)  /* ITERN was despecialized while running. */\n      return key->u32.lo - 1;\n    lj_err_msg(L, LJ_ERR_NEXTIDX);\n    return 0;  /* unreachable */\n  }\n  return ~0u;  /* A nil key starts the traversal. */\n}\n\n/* Advance to the next step in a table traversal. */\nint lj_tab_next(lua_State *L, GCtab *t, TValue *key)\n{\n  uint32_t i = keyindex(L, t, key);  /* Find predecessor key index. */\n  for (i++; i < t->asize; i++)  /* First traverse the array keys. */\n    if (!tvisnil(arrayslot(t, i))) {\n      setintV(key, i);\n      copyTV(L, key+1, arrayslot(t, i));\n      return 1;\n    }\n  for (i -= t->asize; i <= t->hmask; i++) {  /* Then traverse the hash keys. */\n    Node *n = &noderef(t->node)[i];\n    if (!tvisnil(&n->val)) {\n      copyTV(L, key, &n->key);\n      copyTV(L, key+1, &n->val);\n      return 1;\n    }\n  }\n  return 0;  /* End of traversal. */\n}\n\n/* -- Table length calculation -------------------------------------------- */\n\nstatic MSize unbound_search(GCtab *t, MSize j)\n{\n  cTValue *tv;\n  MSize i = j;  /* i is zero or a present index */\n  j++;\n  /* find `i' and `j' such that i is present and j is not */\n  while ((tv = lj_tab_getint(t, (int32_t)j)) && !tvisnil(tv)) {\n    i = j;\n    j *= 2;\n    if (j > (MSize)(INT_MAX-2)) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while ((tv = lj_tab_getint(t, (int32_t)i)) && !tvisnil(tv)) i++;\n      return i - 1;\n    }\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    MSize m = (i+j)/2;\n    cTValue *tvb = lj_tab_getint(t, (int32_t)m);\n    if (tvb && !tvisnil(tvb)) i = m; else j = m;\n  }\n  return i;\n}\n\n/*\n** Try to find a boundary in table `t'. A `boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nMSize LJ_FASTCALL lj_tab_len(GCtab *t)\n{\n  MSize j = (MSize)t->asize;\n  if (j > 1 && tvisnil(arrayslot(t, j-1))) {\n    MSize i = 1;\n    while (j - i > 1) {\n      MSize m = (i+j)/2;\n      if (tvisnil(arrayslot(t, m-1))) j = m; else i = m;\n    }\n    return i-1;\n  }\n  if (j) j--;\n  if (t->hmask <= 0)\n    return j;\n  return unbound_search(t, j);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_tab.h",
    "content": "/*\n** Table handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TAB_H\n#define _LJ_TAB_H\n\n#include \"lj_obj.h\"\n\n/* Hash constants. Tuned using a brute force search. */\n#define HASH_BIAS\t(-0x04c11db7)\n#define HASH_ROT1\t14\n#define HASH_ROT2\t5\n#define HASH_ROT3\t13\n\n/* Scramble the bits of numbers and pointers. */\nstatic LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi)\n{\n#if LJ_TARGET_X86ORX64\n  /* Prefer variant that compiles well for a 2-operand CPU. */\n  lo ^= hi; hi = lj_rol(hi, HASH_ROT1);\n  lo -= hi; hi = lj_rol(hi, HASH_ROT2);\n  hi ^= lo; hi -= lj_rol(lo, HASH_ROT3);\n#else\n  lo ^= hi;\n  lo = lo - lj_rol(hi, HASH_ROT1);\n  hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2);\n  hi = hi - lj_rol(lo, HASH_ROT3);\n#endif\n  return hi;\n}\n\n#define hsize2hbits(s)\t((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)\n\nLJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);\nLJ_FUNC GCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h);\n#if LJ_HASJIT\nLJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);\n#endif\nLJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);\nLJ_FUNC void LJ_FASTCALL lj_tab_clear(GCtab *t);\nLJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);\n#if LJ_HASFFI\nLJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);\n#endif\nLJ_FUNC void lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits);\nLJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);\n\n/* Caveat: all getters except lj_tab_get() can return NULL! */\n\nLJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key);\nLJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key);\nLJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);\n\n/* Caveat: all setters require a write barrier for the stored value. */\n\nLJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);\nLJ_FUNCA TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);\nLJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key);\nLJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);\n\n#define inarray(t, key)\t\t((MSize)(key) < (MSize)(t)->asize)\n#define arrayslot(t, i)\t\t(&tvref((t)->array)[(i)])\n#define lj_tab_getint(t, key) \\\n  (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))\n#define lj_tab_setint(L, t, key) \\\n  (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))\n\nLJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key);\nLJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target.h",
    "content": "/*\n** Definitions for target CPU.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_H\n#define _LJ_TARGET_H\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* -- Registers and spill slots ------------------------------------------- */\n\n/* Register type (uint8_t in ir->r). */\ntypedef uint32_t Reg;\n\n/* The hi-bit is NOT set for an allocated register. This means the value\n** can be directly used without masking. The hi-bit is set for a register\n** allocation hint or for RID_INIT, RID_SINK or RID_SUNK.\n*/\n#define RID_NONE\t\t0x80\n#define RID_MASK\t\t0x7f\n#define RID_INIT\t\t(RID_NONE|RID_MASK)\n#define RID_SINK\t\t(RID_INIT-1)\n#define RID_SUNK\t\t(RID_INIT-2)\n\n#define ra_noreg(r)\t\t((r) & RID_NONE)\n#define ra_hasreg(r)\t\t(!((r) & RID_NONE))\n\n/* The ra_hashint() macro assumes a previous test for ra_noreg(). */\n#define ra_hashint(r)\t\t((r) < RID_SUNK)\n#define ra_gethint(r)\t\t((Reg)((r) & RID_MASK))\n#define ra_sethint(rr, r)\trr = (uint8_t)((r)|RID_NONE)\n#define ra_samehint(r1, r2)\t(ra_gethint((r1)^(r2)) == 0)\n\n/* Spill slot 0 means no spill slot has been allocated. */\n#define SPS_NONE\t\t0\n\n#define ra_hasspill(s)\t\t((s) != SPS_NONE)\n\n/* Combined register and spill slot (uint16_t in ir->prev). */\ntypedef uint32_t RegSP;\n\n#define REGSP(r, s)\t\t((r) + ((s) << 8))\n#define REGSP_HINT(r)\t\t((r)|RID_NONE)\n#define REGSP_INIT\t\tREGSP(RID_INIT, 0)\n\n#define regsp_reg(rs)\t\t((rs) & 255)\n#define regsp_spill(rs)\t\t((rs) >> 8)\n#define regsp_used(rs) \\\n  (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0))\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Bitset for registers. 32 registers suffice for most architectures.\n** Note that one set holds bits for both GPRs and FPRs.\n*/\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS\ntypedef uint64_t RegSet;\n#else\ntypedef uint32_t RegSet;\n#endif\n\n#define RID2RSET(r)\t\t(((RegSet)1) << (r))\n#define RSET_EMPTY\t\t((RegSet)0)\n#define RSET_RANGE(lo, hi)\t((RID2RSET((hi)-(lo))-1) << (lo))\n\n#define rset_test(rs, r)\t((int)((rs) >> (r)) & 1)\n#define rset_set(rs, r)\t\t(rs |= RID2RSET(r))\n#define rset_clear(rs, r)\t(rs &= ~RID2RSET(r))\n#define rset_exclude(rs, r)\t(rs & ~RID2RSET(r))\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS\n#define rset_picktop(rs)\t((Reg)(__builtin_clzll(rs)^63))\n#define rset_pickbot(rs)\t((Reg)__builtin_ctzll(rs))\n#else\n#define rset_picktop(rs)\t((Reg)lj_fls(rs))\n#define rset_pickbot(rs)\t((Reg)lj_ffs(rs))\n#endif\n\n/* -- Register allocation cost -------------------------------------------- */\n\n/* The register allocation heuristic keeps track of the cost for allocating\n** a specific register:\n**\n** A free register (obviously) has a cost of 0 and a 1-bit in the free mask.\n**\n** An already allocated register has the (non-zero) IR reference in the lowest\n** bits and the result of a blended cost-model in the higher bits.\n**\n** The allocator first checks the free mask for a hit. Otherwise an (unrolled)\n** linear search for the minimum cost is used. The search doesn't need to\n** keep track of the position of the minimum, which makes it very fast.\n** The lowest bits of the minimum cost show the desired IR reference whose\n** register is the one to evict.\n**\n** Without the cost-model this degenerates to the standard heuristics for\n** (reverse) linear-scan register allocation. Since code generation is done\n** in reverse, a live interval extends from the last use to the first def.\n** For an SSA IR the IR reference is the first (and only) def and thus\n** trivially marks the end of the interval. The LSRA heuristics says to pick\n** the register whose live interval has the furthest extent, i.e. the lowest\n** IR reference in our case.\n**\n** A cost-model should take into account other factors, like spill-cost and\n** restore- or rematerialization-cost, which depend on the kind of instruction.\n** E.g. constants have zero spill costs, variant instructions have higher\n** costs than invariants and PHIs should preferably never be spilled.\n**\n** Here's a first cut at simple, but effective blended cost-model for R-LSRA:\n** - Due to careful design of the IR, constants already have lower IR\n**   references than invariants and invariants have lower IR references\n**   than variants.\n** - The cost in the upper 16 bits is the sum of the IR reference and a\n**   weighted score. The score currently only takes into account whether\n**   the IRT_ISPHI bit is set in the instruction type.\n** - The PHI weight is the minimum distance (in IR instructions) a PHI\n**   reference has to be further apart from a non-PHI reference to be spilled.\n** - It should be a power of two (for speed) and must be between 2 and 32768.\n**   Good values for the PHI weight seem to be between 40 and 150.\n** - Further study is required.\n*/\n#define REGCOST_PHI_WEIGHT\t64\n\n/* Cost for allocating a specific register. */\ntypedef uint32_t RegCost;\n\n/* Note: assumes 16 bit IRRef1. */\n#define REGCOST(cost, ref)\t((RegCost)(ref) + ((RegCost)(cost) << 16))\n#define regcost_ref(rc)\t\t((IRRef1)(rc))\n\n#define REGCOST_T(t) \\\n  ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI))\n#define REGCOST_REF_T(ref, t)\t(REGCOST((ref), (ref)) + REGCOST_T((t)))\n\n/* -- Target-specific definitions ----------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_target_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_target_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"lj_target_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_target_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_target_mips.h\"\n#else\n#error \"Missing include for target CPU\"\n#endif\n\n#ifdef EXITSTUBS_PER_GROUP\n/* Return the address of an exit stub. */\nstatic LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno)\n{\n  lua_assert(group[exitno / EXITSTUBS_PER_GROUP] != NULL);\n  return (char *)group[exitno / EXITSTUBS_PER_GROUP] +\n\t EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP);\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_addr(J, exitno) \\\n  ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno)))\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target_arm.h",
    "content": "/*\n** Definitions for ARM CPUs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_ARM_H\n#define _LJ_TARGET_ARM_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC)\n#if LJ_SOFTFP\n#define FPRDEF(_)\n#else\n#define FPRDEF(_) \\\n  _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \\\n  _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15)\n#endif\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_LR,\n\n  /* Calling conventions. */\n  RID_RET = RID_R0,\n  RID_RETLO = RID_R0,\n  RID_RETHI = RID_R1,\n#if LJ_SOFTFP\n  RID_FPRET = RID_R0,\n#else\n  RID_FPRET = RID_D0,\n#endif\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R9,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R6,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R7,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R8,\t\t/* Interpreter L. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_PC+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n#if LJ_SOFTFP\n  RID_MAX_FPR = RID_MIN_FPR,\n#else\n  RID_MAX_FPR = RID_D15+1,\n#endif\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except sp, lr and pc. */\n#define RSET_GPR\t\t(RSET_RANGE(RID_MIN_GPR, RID_R12+1))\n#define RSET_GPREVEN \\\n  (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \\\n   RID2RSET(RID_R8)|RID2RSET(RID_R10))\n#define RSET_GPRODD \\\n  (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \\\n   RID2RSET(RID_R9)|RID2RSET(RID_R11))\n#if LJ_SOFTFP\n#define RSET_FPR\t\t0\n#else\n#define RSET_FPR\t\t(RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))\n#endif\n#define RSET_ALL\t\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\t\tRSET_ALL\n\n/* ABI-specific register sets. lr is an implicit scratch register. */\n#define RSET_SCRATCH_GPR_\t(RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12))\n#ifdef __APPLE__\n#define RSET_SCRATCH_GPR\t(RSET_SCRATCH_GPR_|RID2RSET(RID_R9))\n#else\n#define RSET_SCRATCH_GPR\tRSET_SCRATCH_GPR_\n#endif\n#if LJ_SOFTFP\n#define RSET_SCRATCH_FPR\t0\n#else\n#define RSET_SCRATCH_FPR\t(RSET_RANGE(RID_D0, RID_D7+1))\n#endif\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R0\n#define REGARG_LASTGPR\t\tRID_R3\n#define REGARG_NUMGPR\t\t4\n#if LJ_ABI_SOFTFP\n#define REGARG_FIRSTFPR\t\t0\n#define REGARG_LASTFPR\t\t0\n#define REGARG_NUMFPR\t\t0\n#else\n#define REGARG_FIRSTFPR\t\tRID_D0\n#define REGARG_LASTFPR\t\tRID_D7\n#define REGARG_NUMFPR\t\t8\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#define SPS_FIXED\t2\n#define SPS_FIRST\t2\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 1) & ~1)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n#if !LJ_SOFTFP\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n#endif\n  int32_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* PC after instruction that caused an exit. Used to find the trace number. */\n#define EXITSTATE_PCREG\t\tRID_PC\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n#define EXITSTUB_SPACING        4\n#define EXITSTUBS_PER_GROUP     32\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define ARMF_CC(ai, cc)\t(((ai) ^ ARMI_CCAL) | ((cc) << 28))\n#define ARMF_N(r)\t((r) << 16)\n#define ARMF_D(r)\t((r) << 12)\n#define ARMF_S(r)\t((r) << 8)\n#define ARMF_M(r)\t(r)\n#define ARMF_SH(sh, n)\t(((sh) << 5) | ((n) << 7))\n#define ARMF_RSH(sh, r)\t(0x10 | ((sh) << 5) | ARMF_S(r))\n\ntypedef enum ARMIns {\n  ARMI_CCAL = 0xe0000000,\n  ARMI_S = 0x000100000,\n  ARMI_K12 = 0x02000000,\n  ARMI_KNEG = 0x00200000,\n  ARMI_LS_W = 0x00200000,\n  ARMI_LS_U = 0x00800000,\n  ARMI_LS_P = 0x01000000,\n  ARMI_LS_R = 0x02000000,\n  ARMI_LSX_I = 0x00400000,\n\n  ARMI_AND = 0xe0000000,\n  ARMI_EOR = 0xe0200000,\n  ARMI_SUB = 0xe0400000,\n  ARMI_RSB = 0xe0600000,\n  ARMI_ADD = 0xe0800000,\n  ARMI_ADC = 0xe0a00000,\n  ARMI_SBC = 0xe0c00000,\n  ARMI_RSC = 0xe0e00000,\n  ARMI_TST = 0xe1100000,\n  ARMI_TEQ = 0xe1300000,\n  ARMI_CMP = 0xe1500000,\n  ARMI_CMN = 0xe1700000,\n  ARMI_ORR = 0xe1800000,\n  ARMI_MOV = 0xe1a00000,\n  ARMI_BIC = 0xe1c00000,\n  ARMI_MVN = 0xe1e00000,\n\n  ARMI_NOP = 0xe1a00000,\n\n  ARMI_MUL = 0xe0000090,\n  ARMI_SMULL = 0xe0c00090,\n\n  ARMI_LDR = 0xe4100000,\n  ARMI_LDRB = 0xe4500000,\n  ARMI_LDRH = 0xe01000b0,\n  ARMI_LDRSB = 0xe01000d0,\n  ARMI_LDRSH = 0xe01000f0,\n  ARMI_LDRD = 0xe00000d0,\n  ARMI_STR = 0xe4000000,\n  ARMI_STRB = 0xe4400000,\n  ARMI_STRH = 0xe00000b0,\n  ARMI_STRD = 0xe00000f0,\n  ARMI_PUSH = 0xe92d0000,\n\n  ARMI_B = 0xea000000,\n  ARMI_BL = 0xeb000000,\n  ARMI_BLX = 0xfa000000,\n  ARMI_BLXr = 0xe12fff30,\n\n  /* ARMv6 */\n  ARMI_REV = 0xe6bf0f30,\n  ARMI_SXTB = 0xe6af0070,\n  ARMI_SXTH = 0xe6bf0070,\n  ARMI_UXTB = 0xe6ef0070,\n  ARMI_UXTH = 0xe6ff0070,\n\n  /* ARMv6T2 */\n  ARMI_MOVW = 0xe3000000,\n  ARMI_MOVT = 0xe3400000,\n\n  /* VFP */\n  ARMI_VMOV_D = 0xeeb00b40,\n  ARMI_VMOV_S = 0xeeb00a40,\n  ARMI_VMOVI_D = 0xeeb00b00,\n\n  ARMI_VMOV_R_S = 0xee100a10,\n  ARMI_VMOV_S_R = 0xee000a10,\n  ARMI_VMOV_RR_D = 0xec500b10,\n  ARMI_VMOV_D_RR = 0xec400b10,\n\n  ARMI_VADD_D = 0xee300b00,\n  ARMI_VSUB_D = 0xee300b40,\n  ARMI_VMUL_D = 0xee200b00,\n  ARMI_VMLA_D = 0xee000b00,\n  ARMI_VMLS_D = 0xee000b40,\n  ARMI_VNMLS_D = 0xee100b00,\n  ARMI_VDIV_D = 0xee800b00,\n\n  ARMI_VABS_D = 0xeeb00bc0,\n  ARMI_VNEG_D = 0xeeb10b40,\n  ARMI_VSQRT_D = 0xeeb10bc0,\n\n  ARMI_VCMP_D = 0xeeb40b40,\n  ARMI_VCMPZ_D = 0xeeb50b40,\n\n  ARMI_VMRS = 0xeef1fa10,\n\n  ARMI_VCVT_S32_F32 = 0xeebd0ac0,\n  ARMI_VCVT_S32_F64 = 0xeebd0bc0,\n  ARMI_VCVT_U32_F32 = 0xeebc0ac0,\n  ARMI_VCVT_U32_F64 = 0xeebc0bc0,\n  ARMI_VCVT_F32_S32 = 0xeeb80ac0,\n  ARMI_VCVT_F64_S32 = 0xeeb80bc0,\n  ARMI_VCVT_F32_U32 = 0xeeb80a40,\n  ARMI_VCVT_F64_U32 = 0xeeb80b40,\n  ARMI_VCVT_F32_F64 = 0xeeb70bc0,\n  ARMI_VCVT_F64_F32 = 0xeeb70ac0,\n\n  ARMI_VLDR_S = 0xed100a00,\n  ARMI_VLDR_D = 0xed100b00,\n  ARMI_VSTR_S = 0xed000a00,\n  ARMI_VSTR_D = 0xed000b00,\n} ARMIns;\n\ntypedef enum ARMShift {\n  ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR\n} ARMShift;\n\n/* ARM condition codes. */\ntypedef enum ARMCC {\n  CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,\n  CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,\n  CC_HS = CC_CS, CC_LO = CC_CC\n} ARMCC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target_arm64.h",
    "content": "/*\n** Definitions for ARM64 CPUs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_ARM64_H\n#define _LJ_TARGET_ARM64_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(X0) _(X1) _(X2) _(X3) _(X4) _(X5) _(X6) _(X7) \\\n  _(X8) _(X9) _(X10) _(X11) _(X12) _(X13) _(X14) _(X15) \\\n  _(X16) _(X17) _(X18) _(X19) _(X20) _(X21) _(X22) _(X23) \\\n  _(X24) _(X25) _(X26) _(X27) _(X28) _(FP) _(LR) _(SP)\n#define FPRDEF(_) \\\n  _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \\\n  _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15) \\\n  _(D16) _(D17) _(D18) _(D19) _(D20) _(D21) _(D22) _(D23) \\\n  _(D24) _(D25) _(D26) _(D27) _(D28) _(D29) _(D30) _(D31)\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_LR,\n  RID_ZERO = RID_SP,\n\n  /* Calling conventions. */\n  RID_RET = RID_X0,\n  RID_FPRET = RID_D0,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_X19,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_X21,\t\t/* Interpreter PC. */\n  RID_GL = RID_X22,\t\t/* Interpreter GL. */\n  RID_LREG = RID_X23,\t\t/* Interpreter L. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_X0,\n  RID_MAX_GPR = RID_SP+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n  RID_MAX_FPR = RID_D31+1,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_X0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except for x18, fp, lr and sp. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_X18)|RID2RSET(RID_FP)|RID2RSET(RID_LR)|RID2RSET(RID_SP))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#define RSET_FPR\tRSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n/* lr is an implicit scratch register. */\n#define RSET_SCRATCH_GPR\t(RSET_RANGE(RID_X0, RID_X17+1))\n#define RSET_SCRATCH_FPR \\\n  (RSET_RANGE(RID_D0, RID_D7+1)|RSET_RANGE(RID_D16, RID_D31+1))\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_X0\n#define REGARG_LASTGPR\t\tRID_X7\n#define REGARG_NUMGPR\t\t8\n#define REGARG_FIRSTFPR\t\tRID_D0\n#define REGARG_LASTFPR\t\tRID_D7\n#define REGARG_NUMFPR\t\t8\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define A64F_D(r)\t(r)\n#define A64F_N(r)       ((r) << 5)\n#define A64F_A(r)       ((r) << 10)\n#define A64F_M(r)       ((r) << 16)\n#define A64F_U16(x)\t((x) << 5)\n#define A64F_S26(x)\t(x)\n#define A64F_S19(x)\t((x) << 5)\n\ntypedef enum A64Ins {\n  A64I_MOVZw = 0x52800000,\n  A64I_MOVZx = 0xd2800000,\n  A64I_LDRLw = 0x18000000,\n  A64I_LDRLx = 0x58000000,\n  A64I_NOP = 0xd503201f,\n  A64I_B = 0x14000000,\n  A64I_BR = 0xd61f0000,\n} A64Ins;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target_mips.h",
    "content": "/*\n** Definitions for MIPS CPUs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_MIPS_H\n#define _LJ_TARGET_MIPS_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \\\n  _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \\\n  _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA)\n#if LJ_SOFTFP\n#define FPRDEF(_)\n#else\n#define FPRDEF(_) \\\n  _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \\\n  _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \\\n  _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \\\n  _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)\n#endif\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_ZERO = RID_R0,\n  RID_TMP = RID_RA,\n\n  /* Calling conventions. */\n  RID_RET = RID_R2,\n#if LJ_LE\n  RID_RETHI = RID_R3,\n  RID_RETLO = RID_R2,\n#else\n  RID_RETHI = RID_R2,\n  RID_RETLO = RID_R3,\n#endif\n#if LJ_SOFTFP\n  RID_FPRET = RID_R2,\n#else\n  RID_FPRET = RID_F0,\n#endif\n  RID_CFUNCADDR = RID_R25,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R16,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R18,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R19,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R20,\t\t/* Interpreter L. */\n  RID_JGL = RID_R30,\t\t/* On-trace: global_State + 32768. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_RA+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n#if LJ_SOFTFP\n  RID_MAX_FPR = RID_MIN_FPR,\n#else\n  RID_MAX_FPR = RID_F31+1,\n#endif\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\t/* Only even regs are used. */\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2 and JGL. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\\\n   RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#if LJ_SOFTFP\n#define RSET_FPR\t0\n#else\n#define RSET_FPR \\\n  (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\\\n   RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\\\n   RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\\\n   RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30))\n#endif\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n#define RSET_SCRATCH_GPR \\\n  (RSET_RANGE(RID_R1, RID_R15+1)|\\\n   RID2RSET(RID_R24)|RID2RSET(RID_R25)|RID2RSET(RID_R28))\n#if LJ_SOFTFP\n#define RSET_SCRATCH_FPR\t0\n#else\n#define RSET_SCRATCH_FPR \\\n  (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\\\n   RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\\\n   RID2RSET(RID_F16)|RID2RSET(RID_F18))\n#endif\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R4\n#define REGARG_LASTGPR\t\tRID_R7\n#define REGARG_NUMGPR\t\t4\n#if LJ_ABI_SOFTFP\n#define REGARG_FIRSTFPR\t\t0\n#define REGARG_LASTFPR\t\t0\n#define REGARG_NUMFPR\t\t0\n#else\n#define REGARG_FIRSTFPR\t\tRID_F12\n#define REGARG_LASTFPR\t\tRID_F14\n#define REGARG_NUMFPR\t\t2\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use.\n*/\n#define SPS_FIXED\t5\n#define SPS_FIRST\t4\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 1) & ~1)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n#if !LJ_SOFTFP\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n#endif\n  int32_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n/* Return the address of a per-trace exit stub. */\nstatic LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p)\n{\n  while (*p == 0x00000000) p++;  /* Skip MIPSI_NOP. */\n  return p;\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_trace_addr(T, exitno) \\\n  exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode))\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define MIPSF_S(r)\t((r) << 21)\n#define MIPSF_T(r)\t((r) << 16)\n#define MIPSF_D(r)\t((r) << 11)\n#define MIPSF_R(r)\t((r) << 21)\n#define MIPSF_H(r)\t((r) << 16)\n#define MIPSF_G(r)\t((r) << 11)\n#define MIPSF_F(r)\t((r) << 6)\n#define MIPSF_A(n)\t((n) << 6)\n#define MIPSF_M(n)\t((n) << 11)\n\ntypedef enum MIPSIns {\n  /* Integer instructions. */\n  MIPSI_MOVE = 0x00000021,\n  MIPSI_NOP = 0x00000000,\n\n  MIPSI_LI = 0x24000000,\n  MIPSI_LU = 0x34000000,\n  MIPSI_LUI = 0x3c000000,\n\n  MIPSI_ADDIU = 0x24000000,\n  MIPSI_ANDI = 0x30000000,\n  MIPSI_ORI = 0x34000000,\n  MIPSI_XORI = 0x38000000,\n  MIPSI_SLTI = 0x28000000,\n  MIPSI_SLTIU = 0x2c000000,\n\n  MIPSI_ADDU = 0x00000021,\n  MIPSI_SUBU = 0x00000023,\n  MIPSI_MUL = 0x70000002,\n  MIPSI_AND = 0x00000024,\n  MIPSI_OR = 0x00000025,\n  MIPSI_XOR = 0x00000026,\n  MIPSI_NOR = 0x00000027,\n  MIPSI_SLT = 0x0000002a,\n  MIPSI_SLTU = 0x0000002b,\n  MIPSI_MOVZ = 0x0000000a,\n  MIPSI_MOVN = 0x0000000b,\n  MIPSI_MFHI = 0x00000010,\n  MIPSI_MFLO = 0x00000012,\n  MIPSI_MULT = 0x00000018,\n\n  MIPSI_SLL = 0x00000000,\n  MIPSI_SRL = 0x00000002,\n  MIPSI_SRA = 0x00000003,\n  MIPSI_ROTR = 0x00200002,\t/* MIPS32R2 */\n  MIPSI_SLLV = 0x00000004,\n  MIPSI_SRLV = 0x00000006,\n  MIPSI_SRAV = 0x00000007,\n  MIPSI_ROTRV = 0x00000046,\t/* MIPS32R2 */\n\n  MIPSI_SEB = 0x7c000420,\t/* MIPS32R2 */\n  MIPSI_SEH = 0x7c000620,\t/* MIPS32R2 */\n  MIPSI_WSBH = 0x7c0000a0,\t/* MIPS32R2 */\n\n  MIPSI_B = 0x10000000,\n  MIPSI_J = 0x08000000,\n  MIPSI_JAL = 0x0c000000,\n  MIPSI_JR = 0x00000008,\n  MIPSI_JALR = 0x0000f809,\n\n  MIPSI_BEQ = 0x10000000,\n  MIPSI_BNE = 0x14000000,\n  MIPSI_BLEZ = 0x18000000,\n  MIPSI_BGTZ = 0x1c000000,\n  MIPSI_BLTZ = 0x04000000,\n  MIPSI_BGEZ = 0x04010000,\n\n  /* Load/store instructions. */\n  MIPSI_LW = 0x8c000000,\n  MIPSI_SW = 0xac000000,\n  MIPSI_LB = 0x80000000,\n  MIPSI_SB = 0xa0000000,\n  MIPSI_LH = 0x84000000,\n  MIPSI_SH = 0xa4000000,\n  MIPSI_LBU = 0x90000000,\n  MIPSI_LHU = 0x94000000,\n  MIPSI_LWC1 = 0xc4000000,\n  MIPSI_SWC1 = 0xe4000000,\n  MIPSI_LDC1 = 0xd4000000,\n  MIPSI_SDC1 = 0xf4000000,\n\n  /* FP instructions. */\n  MIPSI_MOV_S = 0x46000006,\n  MIPSI_MOV_D = 0x46200006,\n  MIPSI_MOVT_D = 0x46210011,\n  MIPSI_MOVF_D = 0x46200011,\n\n  MIPSI_ABS_D = 0x46200005,\n  MIPSI_NEG_D = 0x46200007,\n\n  MIPSI_ADD_D = 0x46200000,\n  MIPSI_SUB_D = 0x46200001,\n  MIPSI_MUL_D = 0x46200002,\n  MIPSI_DIV_D = 0x46200003,\n  MIPSI_SQRT_D = 0x46200004,\n\n  MIPSI_ADD_S = 0x46000000,\n  MIPSI_SUB_S = 0x46000001,\n\n  MIPSI_CVT_D_S = 0x46000021,\n  MIPSI_CVT_W_S = 0x46000024,\n  MIPSI_CVT_S_D = 0x46200020,\n  MIPSI_CVT_W_D = 0x46200024,\n  MIPSI_CVT_S_W = 0x46800020,\n  MIPSI_CVT_D_W = 0x46800021,\n\n  MIPSI_TRUNC_W_S = 0x4600000d,\n  MIPSI_TRUNC_W_D = 0x4620000d,\n  MIPSI_FLOOR_W_S = 0x4600000f,\n  MIPSI_FLOOR_W_D = 0x4620000f,\n\n  MIPSI_MFC1 = 0x44000000,\n  MIPSI_MTC1 = 0x44800000,\n\n  MIPSI_BC1F = 0x45000000,\n  MIPSI_BC1T = 0x45010000,\n\n  MIPSI_C_EQ_D = 0x46200032,\n  MIPSI_C_OLT_D = 0x46200034,\n  MIPSI_C_ULT_D = 0x46200035,\n  MIPSI_C_OLE_D = 0x46200036,\n  MIPSI_C_ULE_D = 0x46200037,\n\n} MIPSIns;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target_ppc.h",
    "content": "/*\n** Definitions for PPC CPUs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_PPC_H\n#define _LJ_TARGET_PPC_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \\\n  _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \\\n  _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31)\n#define FPRDEF(_) \\\n  _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \\\n  _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \\\n  _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \\\n  _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_R0,\n\n  /* Calling conventions. */\n  RID_RET = RID_R3,\n  RID_RETHI = RID_R3,\n  RID_RETLO = RID_R4,\n  RID_FPRET = RID_F1,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R14,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R16,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R17,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R18,\t\t/* Interpreter L. */\n  RID_JGL = RID_R31,\t\t/* On-trace: global_State + 32768. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_R31+1,\n  RID_MIN_FPR = RID_F0,\n  RID_MAX_FPR = RID_F31+1,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\\\n   RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#define RSET_FPR\tRSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n#define RSET_SCRATCH_GPR\t(RSET_RANGE(RID_R3, RID_R12+1))\n#define RSET_SCRATCH_FPR\t(RSET_RANGE(RID_F0, RID_F13+1))\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R3\n#define REGARG_LASTGPR\t\tRID_R10\n#define REGARG_NUMGPR\t\t8\n#define REGARG_FIRSTFPR\t\tRID_F1\n#define REGARG_LASTFPR\t\tRID_F8\n#define REGARG_NUMFPR\t\t8\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use.\n** [sp+12] tmplo word \\\n** [sp+ 8] tmphi word / tmp dword, parameter area for callee\n** [sp+ 4] tmpw, LR of callee\n** [sp+ 0] stack chain\n*/\n#define SPS_FIXED\t7\n#define SPS_FIRST\t4\n\n/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */\n#define SPOFS_TMPW\t4\n#define SPOFS_TMP\t8\n#define SPOFS_TMPHI\t8\n#define SPOFS_TMPLO\t12\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 3) & ~3)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n/* Return the address of a per-trace exit stub. */\nstatic LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)\n{\n  while (*p == 0x60000000) p++;  /* Skip PPCI_NOP. */\n  return p + 3 + exitno;\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_trace_addr(T, exitno) \\\n  exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define PPCF_CC(cc)\t((((cc) & 3) << 16) | (((cc) & 4) << 22))\n#define PPCF_T(r)\t((r) << 21)\n#define PPCF_A(r)\t((r) << 16)\n#define PPCF_B(r)\t((r) << 11)\n#define PPCF_C(r)\t((r) << 6)\n#define PPCF_MB(n)\t((n) << 6)\n#define PPCF_ME(n)\t((n) << 1)\n#define PPCF_Y\t\t0x00200000\n#define PPCF_DOT\t0x00000001\n\ntypedef enum PPCIns {\n  /* Integer instructions. */\n  PPCI_MR = 0x7c000378,\n  PPCI_NOP = 0x60000000,\n\n  PPCI_LI = 0x38000000,\n  PPCI_LIS = 0x3c000000,\n\n  PPCI_ADD = 0x7c000214,\n  PPCI_ADDC = 0x7c000014,\n  PPCI_ADDO = 0x7c000614,\n  PPCI_ADDE = 0x7c000114,\n  PPCI_ADDZE = 0x7c000194,\n  PPCI_ADDME = 0x7c0001d4,\n  PPCI_ADDI = 0x38000000,\n  PPCI_ADDIS = 0x3c000000,\n  PPCI_ADDIC = 0x30000000,\n  PPCI_ADDICDOT = 0x34000000,\n\n  PPCI_SUBF = 0x7c000050,\n  PPCI_SUBFC = 0x7c000010,\n  PPCI_SUBFO = 0x7c000450,\n  PPCI_SUBFE = 0x7c000110,\n  PPCI_SUBFZE = 0x7c000190,\n  PPCI_SUBFME = 0x7c0001d0,\n  PPCI_SUBFIC = 0x20000000,\n\n  PPCI_NEG = 0x7c0000d0,\n\n  PPCI_AND = 0x7c000038,\n  PPCI_ANDC = 0x7c000078,\n  PPCI_NAND = 0x7c0003b8,\n  PPCI_ANDIDOT = 0x70000000,\n  PPCI_ANDISDOT = 0x74000000,\n\n  PPCI_OR = 0x7c000378,\n  PPCI_NOR = 0x7c0000f8,\n  PPCI_ORI = 0x60000000,\n  PPCI_ORIS = 0x64000000,\n\n  PPCI_XOR = 0x7c000278,\n  PPCI_EQV = 0x7c000238,\n  PPCI_XORI = 0x68000000,\n  PPCI_XORIS = 0x6c000000,\n\n  PPCI_CMPW = 0x7c000000,\n  PPCI_CMPLW = 0x7c000040,\n  PPCI_CMPWI = 0x2c000000,\n  PPCI_CMPLWI = 0x28000000,\n\n  PPCI_MULLW = 0x7c0001d6,\n  PPCI_MULLI = 0x1c000000,\n  PPCI_MULLWO = 0x7c0005d6,\n\n  PPCI_EXTSB = 0x7c000774,\n  PPCI_EXTSH = 0x7c000734,\n\n  PPCI_SLW = 0x7c000030,\n  PPCI_SRW = 0x7c000430,\n  PPCI_SRAW = 0x7c000630,\n  PPCI_SRAWI = 0x7c000670,\n\n  PPCI_RLWNM = 0x5c000000,\n  PPCI_RLWINM = 0x54000000,\n  PPCI_RLWIMI = 0x50000000,\n\n  PPCI_B = 0x48000000,\n  PPCI_BL = 0x48000001,\n  PPCI_BC = 0x40800000,\n  PPCI_BCL = 0x40800001,\n  PPCI_BCTR = 0x4e800420,\n  PPCI_BCTRL = 0x4e800421,\n\n  PPCI_CRANDC = 0x4c000102,\n  PPCI_CRXOR = 0x4c000182,\n  PPCI_CRAND = 0x4c000202,\n  PPCI_CREQV = 0x4c000242,\n  PPCI_CRORC = 0x4c000342,\n  PPCI_CROR = 0x4c000382,\n\n  PPCI_MFLR = 0x7c0802a6,\n  PPCI_MTCTR = 0x7c0903a6,\n\n  PPCI_MCRXR = 0x7c000400,\n\n  /* Load/store instructions. */\n  PPCI_LWZ = 0x80000000,\n  PPCI_LBZ = 0x88000000,\n  PPCI_STW = 0x90000000,\n  PPCI_STB = 0x98000000,\n  PPCI_LHZ = 0xa0000000,\n  PPCI_LHA = 0xa8000000,\n  PPCI_STH = 0xb0000000,\n\n  PPCI_STWU = 0x94000000,\n\n  PPCI_LFS = 0xc0000000,\n  PPCI_LFD = 0xc8000000,\n  PPCI_STFS = 0xd0000000,\n  PPCI_STFD = 0xd8000000,\n\n  PPCI_LWZX = 0x7c00002e,\n  PPCI_LBZX = 0x7c0000ae,\n  PPCI_STWX = 0x7c00012e,\n  PPCI_STBX = 0x7c0001ae,\n  PPCI_LHZX = 0x7c00022e,\n  PPCI_LHAX = 0x7c0002ae,\n  PPCI_STHX = 0x7c00032e,\n\n  PPCI_LWBRX = 0x7c00042c,\n  PPCI_STWBRX = 0x7c00052c,\n\n  PPCI_LFSX = 0x7c00042e,\n  PPCI_LFDX = 0x7c0004ae,\n  PPCI_STFSX = 0x7c00052e,\n  PPCI_STFDX = 0x7c0005ae,\n\n  /* FP instructions. */\n  PPCI_FMR = 0xfc000090,\n  PPCI_FNEG = 0xfc000050,\n  PPCI_FABS = 0xfc000210,\n\n  PPCI_FRSP = 0xfc000018,\n  PPCI_FCTIWZ = 0xfc00001e,\n\n  PPCI_FADD = 0xfc00002a,\n  PPCI_FSUB = 0xfc000028,\n  PPCI_FMUL = 0xfc000032,\n  PPCI_FDIV = 0xfc000024,\n  PPCI_FSQRT = 0xfc00002c,\n\n  PPCI_FMADD = 0xfc00003a,\n  PPCI_FMSUB = 0xfc000038,\n  PPCI_FNMSUB = 0xfc00003c,\n\n  PPCI_FCMPU = 0xfc000000,\n  PPCI_FSEL = 0xfc00002e,\n} PPCIns;\n\ntypedef enum PPCCC {\n  CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO\n} PPCCC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_target_x86.h",
    "content": "/*\n** Definitions for x86 and x64 CPUs.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_X86_H\n#define _LJ_TARGET_X86_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#if LJ_64\n#define GPRDEF(_) \\\n  _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \\\n  _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D)\n#define FPRDEF(_) \\\n  _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \\\n  _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15)\n#else\n#define GPRDEF(_) \\\n  _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI)\n#define FPRDEF(_) \\\n  _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7)\n#endif\n#define VRIDDEF(_) \\\n  _(MRM)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_MRM = RID_MAX,\t\t/* Pseudo-id for ModRM operand. */\n\n  /* Calling conventions. */\n  RID_SP = RID_ESP,\n  RID_RET = RID_EAX,\n#if LJ_64\n  RID_FPRET = RID_XMM0,\n#else\n  RID_RETLO = RID_EAX,\n  RID_RETHI = RID_EDX,\n#endif\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_EDX,\t\t/* Interpreter BASE. */\n#if LJ_64 && !LJ_ABI_WIN\n  RID_LPC = RID_EBX,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R14D,\t/* Interpreter DISPATCH table. */\n#else\n  RID_LPC = RID_ESI,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_EBX,\t/* Interpreter DISPATCH table. */\n#endif\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_EAX,\n  RID_MIN_FPR = RID_XMM0,\n  RID_MAX_GPR = RID_MIN_FPR,\n  RID_MAX_FPR = RID_MAX,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR,\n};\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except the stack pointer. */\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP))\n#define RSET_FPR\t(RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n#if LJ_64\n/* Note: this requires the use of FORCE_REX! */\n#define RSET_GPR8\tRSET_GPR\n#else\n#define RSET_GPR8\t(RSET_RANGE(RID_EAX, RID_EBX+1))\n#endif\n\n/* ABI-specific register sets. */\n#define RSET_ACD\t(RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))\n#if LJ_64\n#if LJ_ABI_WIN\n/* Windows x64 ABI. */\n#define RSET_SCRATCH \\\n  (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))\n#define REGARG_GPRS \\\n  (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5))\n#define REGARG_NUMGPR\t4\n#define REGARG_NUMFPR\t4\n#define REGARG_FIRSTFPR\tRID_XMM0\n#define REGARG_LASTFPR\tRID_XMM3\n#define STACKARG_OFS\t(4*8)\n#else\n/* The rest of the civilized x64 world has a common ABI. */\n#define RSET_SCRATCH \\\n  (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR)\n#define REGARG_GPRS \\\n  (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \\\n   <<5))<<5))<<5))<<5))<<5))\n#define REGARG_NUMGPR\t6\n#define REGARG_NUMFPR\t8\n#define REGARG_FIRSTFPR\tRID_XMM0\n#define REGARG_LASTFPR\tRID_XMM7\n#define STACKARG_OFS\t0\n#endif\n#else\n/* Common x86 ABI. */\n#define RSET_SCRATCH\t(RSET_ACD|RSET_FPR)\n#define REGARG_GPRS\t(RID_ECX|(RID_EDX<<5))  /* Fastcall only. */\n#define REGARG_NUMGPR\t2  /* Fastcall only. */\n#define REGARG_NUMFPR\t0\n#define STACKARG_OFS\t0\n#endif\n\n#if LJ_64\n/* Prefer the low 8 regs of each type to reduce REX prefixes. */\n#undef rset_picktop\n#define rset_picktop(rs)\t(lj_fls(lj_bswap(rs)) ^ 0x18)\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#if LJ_64\n#if LJ_ABI_WIN\n#define SPS_FIXED\t(4*2)\n#define SPS_FIRST\t(4*2)\t/* Don't use callee register save area. */\n#else\n#if LJ_GC64\n#define SPS_FIXED\t2\n#else\n#define SPS_FIXED\t4\n#endif\n#define SPS_FIRST\t2\n#endif\n#else\n#define SPS_FIXED\t6\n#define SPS_FIRST\t2\n#endif\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 3) & ~3)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */\n#define EXITSTUB_SPACING\t(2+2)\n#define EXITSTUBS_PER_GROUP\t32\n\n/* -- x86 ModRM operand encoding ------------------------------------------ */\n\ntypedef enum {\n  XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0,\n  XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0,\n  XM_MASK = 0xc0\n} x86Mode;\n\n/* Structure to hold variable ModRM operand. */\ntypedef struct {\n  int32_t ofs;\t\t/* Offset. */\n  uint8_t base;\t\t/* Base register or RID_NONE. */\n  uint8_t idx;\t\t/* Index register or RID_NONE. */\n  uint8_t scale;\t/* Index scale (XM_SCALE1 .. XM_SCALE8). */\n} x86ModRM;\n\n/* -- Opcodes ------------------------------------------------------------- */\n\n/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */\n#define XO_(o)\t\t((uint32_t)(0x0000fe + (0x##o<<24)))\n#define XO_FPU(a,b)\t((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24)))\n#define XO_0f(o)\t((uint32_t)(0x0f00fd + (0x##o<<24)))\n#define XO_66(o)\t((uint32_t)(0x6600fd + (0x##o<<24)))\n#define XO_660f(o)\t((uint32_t)(0x0f66fc + (0x##o<<24)))\n#define XO_f20f(o)\t((uint32_t)(0x0ff2fc + (0x##o<<24)))\n#define XO_f30f(o)\t((uint32_t)(0x0ff3fc + (0x##o<<24)))\n\n/* This list of x86 opcodes is not intended to be complete. Opcodes are only\n** included when needed. Take a look at DynASM or jit.dis_x86 to see the\n** whole mess.\n*/\ntypedef enum {\n  /* Fixed length opcodes. XI_* prefix. */\n  XI_NOP =\t0x90,\n  XI_XCHGa =\t0x90,\n  XI_CALL =\t0xe8,\n  XI_JMP =\t0xe9,\n  XI_JMPs =\t0xeb,\n  XI_PUSH =\t0x50, /* Really 50+r. */\n  XI_JCCs =\t0x70, /* Really 7x. */\n  XI_JCCn =\t0x80, /* Really 0f8x. */\n  XI_LEA =\t0x8d,\n  XI_MOVrib =\t0xb0, /* Really b0+r. */\n  XI_MOVri =\t0xb8, /* Really b8+r. */\n  XI_ARITHib =\t0x80,\n  XI_ARITHi =\t0x81,\n  XI_ARITHi8 =\t0x83,\n  XI_PUSHi8 =\t0x6a,\n  XI_TESTb =\t0x84,\n  XI_TEST =\t0x85,\n  XI_MOVmi =\t0xc7,\n  XI_GROUP5 =\t0xff,\n\n  /* Note: little-endian byte-order! */\n  XI_FLDZ =\t0xeed9,\n  XI_FLD1 =\t0xe8d9,\n  XI_FLDLG2 =\t0xecd9,\n  XI_FLDLN2 =\t0xedd9,\n  XI_FDUP =\t0xc0d9,  /* Really fld st0. */\n  XI_FPOP =\t0xd8dd,  /* Really fstp st0. */\n  XI_FPOP1 =\t0xd9dd,  /* Really fstp st1. */\n  XI_FRNDINT =\t0xfcd9,\n  XI_FSIN =\t0xfed9,\n  XI_FCOS =\t0xffd9,\n  XI_FPTAN =\t0xf2d9,\n  XI_FPATAN =\t0xf3d9,\n  XI_FSCALE =\t0xfdd9,\n  XI_FYL2X =\t0xf1d9,\n\n  /* Variable-length opcodes. XO_* prefix. */\n  XO_MOV =\tXO_(8b),\n  XO_MOVto =\tXO_(89),\n  XO_MOVtow =\tXO_66(89),\n  XO_MOVtob =\tXO_(88),\n  XO_MOVmi =\tXO_(c7),\n  XO_MOVmib =\tXO_(c6),\n  XO_LEA =\tXO_(8d),\n  XO_ARITHib =\tXO_(80),\n  XO_ARITHi =\tXO_(81),\n  XO_ARITHi8 =\tXO_(83),\n  XO_ARITHiw8 =\tXO_66(83),\n  XO_SHIFTi =\tXO_(c1),\n  XO_SHIFT1 =\tXO_(d1),\n  XO_SHIFTcl =\tXO_(d3),\n  XO_IMUL =\tXO_0f(af),\n  XO_IMULi =\tXO_(69),\n  XO_IMULi8 =\tXO_(6b),\n  XO_CMP =\tXO_(3b),\n  XO_TESTb =\tXO_(84),\n  XO_TEST =\tXO_(85),\n  XO_GROUP3b =\tXO_(f6),\n  XO_GROUP3 =\tXO_(f7),\n  XO_GROUP5b =\tXO_(fe),\n  XO_GROUP5 =\tXO_(ff),\n  XO_MOVZXb =\tXO_0f(b6),\n  XO_MOVZXw =\tXO_0f(b7),\n  XO_MOVSXb =\tXO_0f(be),\n  XO_MOVSXw =\tXO_0f(bf),\n  XO_MOVSXd =\tXO_(63),\n  XO_BSWAP =\tXO_0f(c8),\n  XO_CMOV =\tXO_0f(40),\n\n  XO_MOVSD =\tXO_f20f(10),\n  XO_MOVSDto =\tXO_f20f(11),\n  XO_MOVSS =\tXO_f30f(10),\n  XO_MOVSSto =\tXO_f30f(11),\n  XO_MOVLPD =\tXO_660f(12),\n  XO_MOVAPS =\tXO_0f(28),\n  XO_XORPS =\tXO_0f(57),\n  XO_ANDPS =\tXO_0f(54),\n  XO_ADDSD =\tXO_f20f(58),\n  XO_SUBSD =\tXO_f20f(5c),\n  XO_MULSD =\tXO_f20f(59),\n  XO_DIVSD =\tXO_f20f(5e),\n  XO_SQRTSD =\tXO_f20f(51),\n  XO_MINSD =\tXO_f20f(5d),\n  XO_MAXSD =\tXO_f20f(5f),\n  XO_ROUNDSD =\t0x0b3a0ffc,  /* Really 66 0f 3a 0b. See asm_fpmath. */\n  XO_UCOMISD =\tXO_660f(2e),\n  XO_CVTSI2SD =\tXO_f20f(2a),\n  XO_CVTTSD2SI=\tXO_f20f(2c),\n  XO_CVTSI2SS =\tXO_f30f(2a),\n  XO_CVTTSS2SI=\tXO_f30f(2c),\n  XO_CVTSS2SD =\tXO_f30f(5a),\n  XO_CVTSD2SS =\tXO_f20f(5a),\n  XO_ADDSS =\tXO_f30f(58),\n  XO_MOVD =\tXO_660f(6e),\n  XO_MOVDto =\tXO_660f(7e),\n\n  XO_FLDd =\tXO_(d9), XOg_FLDd = 0,\n  XO_FLDq =\tXO_(dd), XOg_FLDq = 0,\n  XO_FILDd =\tXO_(db), XOg_FILDd = 0,\n  XO_FILDq =\tXO_(df), XOg_FILDq = 5,\n  XO_FSTPd =\tXO_(d9), XOg_FSTPd = 3,\n  XO_FSTPq =\tXO_(dd), XOg_FSTPq = 3,\n  XO_FISTPq =\tXO_(df), XOg_FISTPq = 7,\n  XO_FISTTPq =\tXO_(dd), XOg_FISTTPq = 1,\n  XO_FADDq =\tXO_(dc), XOg_FADDq = 0,\n  XO_FLDCW =\tXO_(d9), XOg_FLDCW = 5,\n  XO_FNSTCW =\tXO_(d9), XOg_FNSTCW = 7\n} x86Op;\n\n/* x86 opcode groups. */\ntypedef uint32_t x86Group;\n\n#define XG_(i8, i, g)\t((x86Group)(((i8) << 16) + ((i) << 8) + (g)))\n#define XG_ARITHi(g)\tXG_(XI_ARITHi8, XI_ARITHi, g)\n#define XG_TOXOi(xg)\t((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000)))\n#define XG_TOXOi8(xg)\t((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000)))\n\n#define XO_ARITH(a)\t((x86Op)(0x030000fe + ((a)<<27)))\n#define XO_ARITHw(a)\t((x86Op)(0x036600fd + ((a)<<27)))\n\ntypedef enum {\n  XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP,\n  XOg_X_IMUL\n} x86Arith;\n\ntypedef enum {\n  XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR\n} x86Shift;\n\ntypedef enum {\n  XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV\n} x86Group3;\n\ntypedef enum {\n  XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH\n} x86Group5;\n\n/* x86 condition codes. */\ntypedef enum {\n  CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE,\n  CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE,\n  CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB,\n  CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE,\n  CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL,\n  CC_NG = CC_LE, CC_G = CC_NLE\n} x86CC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_trace.c",
    "content": "/*\n** Trace management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_trace_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_frame.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_gdbjit.h\"\n#include \"lj_record.h\"\n#include \"lj_asm.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n#include \"lj_target.h\"\n\n/* -- Error handling ------------------------------------------------------ */\n\n/* Synchronous abort with error message. */\nvoid lj_trace_err(jit_State *J, TraceError e)\n{\n  setnilV(&J->errinfo);  /* No error info. */\n  setintV(J->L->top++, (int32_t)e);\n  lj_err_throw(J->L, LUA_ERRRUN);\n}\n\n/* Synchronous abort with error message and error info. */\nvoid lj_trace_err_info(jit_State *J, TraceError e)\n{\n  setintV(J->L->top++, (int32_t)e);\n  lj_err_throw(J->L, LUA_ERRRUN);\n}\n\n/* -- Trace management ---------------------------------------------------- */\n\n/* The current trace is first assembled in J->cur. The variable length\n** arrays point to shared, growable buffers (J->irbuf etc.). When trace\n** recording ends successfully, the current trace and its data structures\n** are copied to a new (compact) GCtrace object.\n*/\n\n/* Find a free trace number. */\nstatic TraceNo trace_findfree(jit_State *J)\n{\n  MSize osz, lim;\n  if (J->freetrace == 0)\n    J->freetrace = 1;\n  for (; J->freetrace < J->sizetrace; J->freetrace++)\n    if (traceref(J, J->freetrace) == NULL)\n      return J->freetrace++;\n  /* Need to grow trace array. */\n  lim = (MSize)J->param[JIT_P_maxtrace] + 1;\n  if (lim < 2) lim = 2; else if (lim > 65535) lim = 65535;\n  osz = J->sizetrace;\n  if (osz >= lim)\n    return 0;  /* Too many traces. */\n  lj_mem_growvec(J->L, J->trace, J->sizetrace, lim, GCRef);\n  for (; osz < J->sizetrace; osz++)\n    setgcrefnull(J->trace[osz]);\n  return J->freetrace;\n}\n\n#define TRACE_APPENDVEC(field, szfield, tp) \\\n  T->field = (tp *)p; \\\n  memcpy(p, J->cur.field, J->cur.szfield*sizeof(tp)); \\\n  p += J->cur.szfield*sizeof(tp);\n\n#ifdef LUAJIT_USE_PERFTOOLS\n/*\n** Create symbol table of JIT-compiled code. For use with Linux perf tools.\n** Example usage:\n**   perf record -f -e cycles luajit test.lua\n**   perf report -s symbol\n**   rm perf.data /tmp/perf-*.map\n*/\n#include <stdio.h>\n#include <unistd.h>\n\nstatic void perftools_addtrace(GCtrace *T)\n{\n  static FILE *fp;\n  GCproto *pt = &gcref(T->startpt)->pt;\n  const BCIns *startpc = mref(T->startpc, const BCIns);\n  const char *name = proto_chunknamestr(pt);\n  BCLine lineno;\n  if (name[0] == '@' || name[0] == '=')\n    name++;\n  else\n    name = \"(string)\";\n  lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);\n  lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));\n  if (!fp) {\n    char fname[40];\n    sprintf(fname, \"/tmp/perf-%d.map\", getpid());\n    if (!(fp = fopen(fname, \"w\"))) return;\n    setlinebuf(fp);\n  }\n  fprintf(fp, \"%lx %x TRACE_%d::%s:%u\\n\",\n\t  (long)T->mcode, T->szmcode, T->traceno, name, lineno);\n}\n#endif\n\n/* Allocate space for copy of trace. */\nstatic GCtrace *trace_save_alloc(jit_State *J)\n{\n  size_t sztr = ((sizeof(GCtrace)+7)&~7);\n  size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);\n  size_t sz = sztr + szins +\n\t      J->cur.nsnap*sizeof(SnapShot) +\n\t      J->cur.nsnapmap*sizeof(SnapEntry);\n  return lj_mem_newt(J->L, (MSize)sz, GCtrace);\n}\n\n/* Save current trace by copying and compacting it. */\nstatic void trace_save(jit_State *J, GCtrace *T)\n{\n  size_t sztr = ((sizeof(GCtrace)+7)&~7);\n  size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);\n  char *p = (char *)T + sztr;\n  memcpy(T, &J->cur, sizeof(GCtrace));\n  setgcrefr(T->nextgc, J2G(J)->gc.root);\n  setgcrefp(J2G(J)->gc.root, T);\n  newwhite(J2G(J), T);\n  T->gct = ~LJ_TTRACE;\n  T->ir = (IRIns *)p - J->cur.nk;\n  memcpy(p, J->cur.ir+J->cur.nk, szins);\n  p += szins;\n  TRACE_APPENDVEC(snap, nsnap, SnapShot)\n  TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry)\n  J->cur.traceno = 0;\n  setgcrefp(J->trace[T->traceno], T);\n  lj_gc_barriertrace(J2G(J), T->traceno);\n  lj_gdbjit_addtrace(J, T);\n#ifdef LUAJIT_USE_PERFTOOLS\n  perftools_addtrace(T);\n#endif\n}\n\nvoid LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T)\n{\n  jit_State *J = G2J(g);\n  if (T->traceno) {\n    lj_gdbjit_deltrace(J, T);\n    if (T->traceno < J->freetrace)\n      J->freetrace = T->traceno;\n    setgcrefnull(J->trace[T->traceno]);\n  }\n  lj_mem_free(g, T,\n    ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +\n    T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry));\n}\n\n/* Re-enable compiling a prototype by unpatching any modified bytecode. */\nvoid lj_trace_reenableproto(GCproto *pt)\n{\n  if ((pt->flags & PROTO_ILOOP)) {\n    BCIns *bc = proto_bc(pt);\n    BCPos i, sizebc = pt->sizebc;;\n    pt->flags &= ~PROTO_ILOOP;\n    if (bc_op(bc[0]) == BC_IFUNCF)\n      setbc_op(&bc[0], BC_FUNCF);\n    for (i = 1; i < sizebc; i++) {\n      BCOp op = bc_op(bc[i]);\n      if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP)\n\tsetbc_op(&bc[i], (int)op+(int)BC_LOOP-(int)BC_ILOOP);\n    }\n  }\n}\n\n/* Unpatch the bytecode modified by a root trace. */\nstatic void trace_unpatch(jit_State *J, GCtrace *T)\n{\n  BCOp op = bc_op(T->startins);\n  BCIns *pc = mref(T->startpc, BCIns);\n  UNUSED(J);\n  if (op == BC_JMP)\n    return;  /* No need to unpatch branches in parent traces (yet). */\n  switch (bc_op(*pc)) {\n  case BC_JFORL:\n    lua_assert(traceref(J, bc_d(*pc)) == T);\n    *pc = T->startins;\n    pc += bc_j(T->startins);\n    lua_assert(bc_op(*pc) == BC_JFORI);\n    setbc_op(pc, BC_FORI);\n    break;\n  case BC_JITERL:\n  case BC_JLOOP:\n    lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op));\n    *pc = T->startins;\n    break;\n  case BC_JMP:\n    lua_assert(op == BC_ITERL);\n    pc += bc_j(*pc)+2;\n    if (bc_op(*pc) == BC_JITERL) {\n      lua_assert(traceref(J, bc_d(*pc)) == T);\n      *pc = T->startins;\n    }\n    break;\n  case BC_JFUNCF:\n    lua_assert(op == BC_FUNCF);\n    *pc = T->startins;\n    break;\n  default:  /* Already unpatched. */\n    break;\n  }\n}\n\n/* Flush a root trace. */\nstatic void trace_flushroot(jit_State *J, GCtrace *T)\n{\n  GCproto *pt = &gcref(T->startpt)->pt;\n  lua_assert(T->root == 0 && pt != NULL);\n  /* First unpatch any modified bytecode. */\n  trace_unpatch(J, T);\n  /* Unlink root trace from chain anchored in prototype. */\n  if (pt->trace == T->traceno) {  /* Trace is first in chain. Easy. */\n    pt->trace = T->nextroot;\n  } else if (pt->trace) {  /* Otherwise search in chain of root traces. */\n    GCtrace *T2 = traceref(J, pt->trace);\n    if (T2) {\n      for (; T2->nextroot; T2 = traceref(J, T2->nextroot))\n\tif (T2->nextroot == T->traceno) {\n\t  T2->nextroot = T->nextroot;  /* Unlink from chain. */\n\t  break;\n\t}\n    }\n  }\n}\n\n/* Flush a trace. Only root traces are considered. */\nvoid lj_trace_flush(jit_State *J, TraceNo traceno)\n{\n  if (traceno > 0 && traceno < J->sizetrace) {\n    GCtrace *T = traceref(J, traceno);\n    if (T && T->root == 0)\n      trace_flushroot(J, T);\n  }\n}\n\n/* Flush all traces associated with a prototype. */\nvoid lj_trace_flushproto(global_State *g, GCproto *pt)\n{\n  while (pt->trace != 0)\n    trace_flushroot(G2J(g), traceref(G2J(g), pt->trace));\n}\n\n/* Flush all traces. */\nint lj_trace_flushall(lua_State *L)\n{\n  jit_State *J = L2J(L);\n  ptrdiff_t i;\n  if ((J2G(J)->hookmask & HOOK_GC))\n    return 1;\n  for (i = (ptrdiff_t)J->sizetrace-1; i > 0; i--) {\n    GCtrace *T = traceref(J, i);\n    if (T) {\n      if (T->root == 0)\n\ttrace_flushroot(J, T);\n      lj_gdbjit_deltrace(J, T);\n      T->traceno = T->link = 0;  /* Blacklist the link for cont_stitch. */\n      setgcrefnull(J->trace[i]);\n    }\n  }\n  J->cur.traceno = 0;\n  J->freetrace = 0;\n  /* Clear penalty cache. */\n  memset(J->penalty, 0, sizeof(J->penalty));\n  /* Free the whole machine code and invalidate all exit stub groups. */\n  lj_mcode_free(J);\n  lj_ir_k64_freeall(J);\n  memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"flush\"));\n  );\n  return 0;\n}\n\n/* Initialize JIT compiler state. */\nvoid lj_trace_initstate(global_State *g)\n{\n  jit_State *J = G2J(g);\n  TValue *tv;\n  /* Initialize SIMD constants. */\n  tv = LJ_KSIMD(J, LJ_KSIMD_ABS);\n  tv[0].u64 = U64x(7fffffff,ffffffff);\n  tv[1].u64 = U64x(7fffffff,ffffffff);\n  tv = LJ_KSIMD(J, LJ_KSIMD_NEG);\n  tv[0].u64 = U64x(80000000,00000000);\n  tv[1].u64 = U64x(80000000,00000000);\n}\n\n/* Free everything associated with the JIT compiler state. */\nvoid lj_trace_freestate(global_State *g)\n{\n  jit_State *J = G2J(g);\n#ifdef LUA_USE_ASSERT\n  {  /* This assumes all traces have already been freed. */\n    ptrdiff_t i;\n    for (i = 1; i < (ptrdiff_t)J->sizetrace; i++)\n      lua_assert(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL);\n  }\n#endif\n  lj_mcode_free(J);\n  lj_ir_k64_freeall(J);\n  lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry);\n  lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot);\n  lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns);\n  lj_mem_freevec(g, J->trace, J->sizetrace, GCRef);\n}\n\n/* -- Penalties and blacklisting ------------------------------------------ */\n\n/* Blacklist a bytecode instruction. */\nstatic void blacklist_pc(GCproto *pt, BCIns *pc)\n{\n  setbc_op(pc, (int)bc_op(*pc)+(int)BC_ILOOP-(int)BC_LOOP);\n  pt->flags |= PROTO_ILOOP;\n}\n\n/* Penalize a bytecode instruction. */\nstatic void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)\n{\n  uint32_t i, val = PENALTY_MIN;\n  for (i = 0; i < PENALTY_SLOTS; i++)\n    if (mref(J->penalty[i].pc, const BCIns) == pc) {  /* Cache slot found? */\n      /* First try to bump its hotcount several times. */\n      val = ((uint32_t)J->penalty[i].val << 1) +\n\t    LJ_PRNG_BITS(J, PENALTY_RNDBITS);\n      if (val > PENALTY_MAX) {\n\tblacklist_pc(pt, pc);  /* Blacklist it, if that didn't help. */\n\treturn;\n      }\n      goto setpenalty;\n    }\n  /* Assign a new penalty cache slot. */\n  i = J->penaltyslot;\n  J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1);\n  setmref(J->penalty[i].pc, pc);\nsetpenalty:\n  J->penalty[i].val = (uint16_t)val;\n  J->penalty[i].reason = e;\n  hotcount_set(J2GG(J), pc+1, val);\n}\n\n/* -- Trace compiler state machine ---------------------------------------- */\n\n/* Start tracing. */\nstatic void trace_start(jit_State *J)\n{\n  lua_State *L;\n  TraceNo traceno;\n\n  if ((J->pt->flags & PROTO_NOJIT)) {  /* JIT disabled for this proto? */\n    if (J->parent == 0 && J->exitno == 0) {\n      /* Lazy bytecode patching to disable hotcount events. */\n      lua_assert(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL ||\n\t\t bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF);\n      setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP);\n      J->pt->flags |= PROTO_ILOOP;\n    }\n    J->state = LJ_TRACE_IDLE;  /* Silently ignored. */\n    return;\n  }\n\n  /* Get a new trace number. */\n  traceno = trace_findfree(J);\n  if (LJ_UNLIKELY(traceno == 0)) {  /* No free trace? */\n    lua_assert((J2G(J)->hookmask & HOOK_GC) == 0);\n    lj_trace_flushall(J->L);\n    J->state = LJ_TRACE_IDLE;  /* Silently ignored. */\n    return;\n  }\n  setgcrefp(J->trace[traceno], &J->cur);\n\n  /* Setup enough of the current trace to be able to send the vmevent. */\n  memset(&J->cur, 0, sizeof(GCtrace));\n  J->cur.traceno = traceno;\n  J->cur.nins = J->cur.nk = REF_BASE;\n  J->cur.ir = J->irbuf;\n  J->cur.snap = J->snapbuf;\n  J->cur.snapmap = J->snapmapbuf;\n  J->mergesnap = 0;\n  J->needsnap = 0;\n  J->bcskip = 0;\n  J->guardemit.irt = 0;\n  J->postproc = LJ_POST_NONE;\n  lj_resetsplit(J);\n  J->retryrec = 0;\n  J->ktracep = NULL;\n  setgcref(J->cur.startpt, obj2gco(J->pt));\n\n  L = J->L;\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"start\"));\n    setintV(L->top++, traceno);\n    setfuncV(L, L->top++, J->fn);\n    setintV(L->top++, proto_bcpos(J->pt, J->pc));\n    if (J->parent) {\n      setintV(L->top++, J->parent);\n      setintV(L->top++, J->exitno);\n    }\n  );\n  lj_record_setup(J);\n}\n\n/* Stop tracing. */\nstatic void trace_stop(jit_State *J)\n{\n  BCIns *pc = mref(J->cur.startpc, BCIns);\n  BCOp op = bc_op(J->cur.startins);\n  GCproto *pt = &gcref(J->cur.startpt)->pt;\n  TraceNo traceno = J->cur.traceno;\n  GCtrace *T = trace_save_alloc(J);  /* Do this first. May throw OOM. */\n  lua_State *L;\n\n  switch (op) {\n  case BC_FORL:\n    setbc_op(pc+bc_j(J->cur.startins), BC_JFORI);  /* Patch FORI, too. */\n    /* fallthrough */\n  case BC_LOOP:\n  case BC_ITERL:\n  case BC_FUNCF:\n    /* Patch bytecode of starting instruction in root trace. */\n    setbc_op(pc, (int)op+(int)BC_JLOOP-(int)BC_LOOP);\n    setbc_d(pc, traceno);\n  addroot:\n    /* Add to root trace chain in prototype. */\n    J->cur.nextroot = pt->trace;\n    pt->trace = (TraceNo1)traceno;\n    break;\n  case BC_RET:\n  case BC_RET0:\n  case BC_RET1:\n    *pc = BCINS_AD(BC_JLOOP, J->cur.snap[0].nslots, traceno);\n    goto addroot;\n  case BC_JMP:\n    /* Patch exit branch in parent to side trace entry. */\n    lua_assert(J->parent != 0 && J->cur.root != 0);\n    lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode);\n    /* Avoid compiling a side trace twice (stack resizing uses parent exit). */\n    traceref(J, J->parent)->snap[J->exitno].count = SNAPCOUNT_DONE;\n    /* Add to side trace chain in root trace. */\n    {\n      GCtrace *root = traceref(J, J->cur.root);\n      root->nchild++;\n      J->cur.nextside = root->nextside;\n      root->nextside = (TraceNo1)traceno;\n    }\n    break;\n  case BC_CALLM:\n  case BC_CALL:\n  case BC_ITERC:\n    /* Trace stitching: patch link of previous trace. */\n    traceref(J, J->exitno)->link = traceno;\n    break;\n  default:\n    lua_assert(0);\n    break;\n  }\n\n  /* Commit new mcode only after all patching is done. */\n  lj_mcode_commit(J, J->cur.mcode);\n  J->postproc = LJ_POST_NONE;\n  trace_save(J, T);\n  if (J->ktracep) {  /* Patch K64Array slot with the final GCtrace pointer. */\n    setgcV(J->L, J->ktracep, obj2gco(T), LJ_TTRACE);\n  }\n\n  L = J->L;\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"stop\"));\n    setintV(L->top++, traceno);\n    setfuncV(L, L->top++, J->fn);\n  );\n}\n\n/* Start a new root trace for down-recursion. */\nstatic int trace_downrec(jit_State *J)\n{\n  /* Restart recording at the return instruction. */\n  lua_assert(J->pt != NULL);\n  lua_assert(bc_isret(bc_op(*J->pc)));\n  if (bc_op(*J->pc) == BC_RETM)\n    return 0;  /* NYI: down-recursion with RETM. */\n  J->parent = 0;\n  J->exitno = 0;\n  J->state = LJ_TRACE_RECORD;\n  trace_start(J);\n  return 1;\n}\n\n/* Abort tracing. */\nstatic int trace_abort(jit_State *J)\n{\n  lua_State *L = J->L;\n  TraceError e = LJ_TRERR_RECERR;\n  TraceNo traceno;\n\n  J->postproc = LJ_POST_NONE;\n  lj_mcode_abort(J);\n  if (tvisnumber(L->top-1))\n    e = (TraceError)numberVint(L->top-1);\n  if (e == LJ_TRERR_MCODELM) {\n    L->top--;  /* Remove error object */\n    J->state = LJ_TRACE_ASM;\n    return 1;  /* Retry ASM with new MCode area. */\n  }\n  /* Penalize or blacklist starting bytecode instruction. */\n  if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) {\n    if (J->exitno == 0) {\n      BCIns *startpc = mref(J->cur.startpc, BCIns);\n      if (e == LJ_TRERR_RETRY)\n\thotcount_set(J2GG(J), startpc+1, 1);  /* Immediate retry. */\n      else\n\tpenalty_pc(J, &gcref(J->cur.startpt)->pt, startpc, e);\n    } else {\n      traceref(J, J->exitno)->link = J->exitno;  /* Self-link is blacklisted. */\n    }\n  }\n\n  /* Is there anything to abort? */\n  traceno = J->cur.traceno;\n  if (traceno) {\n    ptrdiff_t errobj = savestack(L, L->top-1);  /* Stack may be resized. */\n    J->cur.link = 0;\n    J->cur.linktype = LJ_TRLINK_NONE;\n    lj_vmevent_send(L, TRACE,\n      TValue *frame;\n      const BCIns *pc;\n      GCfunc *fn;\n      setstrV(L, L->top++, lj_str_newlit(L, \"abort\"));\n      setintV(L->top++, traceno);\n      /* Find original Lua function call to generate a better error message. */\n      frame = J->L->base-1;\n      pc = J->pc;\n      while (!isluafunc(frame_func(frame))) {\n\tpc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;\n\tframe = frame_prev(frame);\n      }\n      fn = frame_func(frame);\n      setfuncV(L, L->top++, fn);\n      setintV(L->top++, proto_bcpos(funcproto(fn), pc));\n      copyTV(L, L->top++, restorestack(L, errobj));\n      copyTV(L, L->top++, &J->errinfo);\n    );\n    /* Drop aborted trace after the vmevent (which may still access it). */\n    setgcrefnull(J->trace[traceno]);\n    if (traceno < J->freetrace)\n      J->freetrace = traceno;\n    J->cur.traceno = 0;\n  }\n  L->top--;  /* Remove error object */\n  if (e == LJ_TRERR_DOWNREC)\n    return trace_downrec(J);\n  else if (e == LJ_TRERR_MCODEAL)\n    lj_trace_flushall(L);\n  return 0;\n}\n\n/* Perform pending re-patch of a bytecode instruction. */\nstatic LJ_AINLINE void trace_pendpatch(jit_State *J, int force)\n{\n  if (LJ_UNLIKELY(J->patchpc)) {\n    if (force || J->bcskip == 0) {\n      *J->patchpc = J->patchins;\n      J->patchpc = NULL;\n    } else {\n      J->bcskip = 0;\n    }\n  }\n}\n\n/* State machine for the trace compiler. Protected callback. */\nstatic TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  UNUSED(dummy);\n  do {\n  retry:\n    switch (J->state) {\n    case LJ_TRACE_START:\n      J->state = LJ_TRACE_RECORD;  /* trace_start() may change state. */\n      trace_start(J);\n      lj_dispatch_update(J2G(J));\n      break;\n\n    case LJ_TRACE_RECORD:\n      trace_pendpatch(J, 0);\n      setvmstate(J2G(J), RECORD);\n      lj_vmevent_send_(L, RECORD,\n\t/* Save/restore tmptv state for trace recorder. */\n\tTValue savetv = J2G(J)->tmptv;\n\tTValue savetv2 = J2G(J)->tmptv2;\n\tsetintV(L->top++, J->cur.traceno);\n\tsetfuncV(L, L->top++, J->fn);\n\tsetintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1);\n\tsetintV(L->top++, J->framedepth);\n      ,\n\tJ2G(J)->tmptv = savetv;\n\tJ2G(J)->tmptv2 = savetv2;\n      );\n      lj_record_ins(J);\n      break;\n\n    case LJ_TRACE_END:\n      trace_pendpatch(J, 1);\n      J->loopref = 0;\n      if ((J->flags & JIT_F_OPT_LOOP) &&\n\t  J->cur.link == J->cur.traceno && J->framedepth + J->retdepth == 0) {\n\tsetvmstate(J2G(J), OPT);\n\tlj_opt_dce(J);\n\tif (lj_opt_loop(J)) {  /* Loop optimization failed? */\n\t  J->cur.link = 0;\n\t  J->cur.linktype = LJ_TRLINK_NONE;\n\t  J->loopref = J->cur.nins;\n\t  J->state = LJ_TRACE_RECORD;  /* Try to continue recording. */\n\t  break;\n\t}\n\tJ->loopref = J->chain[IR_LOOP];  /* Needed by assembler. */\n      }\n      lj_opt_split(J);\n      lj_opt_sink(J);\n      if (!J->loopref) J->cur.snap[J->cur.nsnap-1].count = SNAPCOUNT_DONE;\n      J->state = LJ_TRACE_ASM;\n      break;\n\n    case LJ_TRACE_ASM:\n      setvmstate(J2G(J), ASM);\n      lj_asm_trace(J, &J->cur);\n      trace_stop(J);\n      setvmstate(J2G(J), INTERP);\n      J->state = LJ_TRACE_IDLE;\n      lj_dispatch_update(J2G(J));\n      return NULL;\n\n    default:  /* Trace aborted asynchronously. */\n      setintV(L->top++, (int32_t)LJ_TRERR_RECERR);\n      /* fallthrough */\n    case LJ_TRACE_ERR:\n      trace_pendpatch(J, 1);\n      if (trace_abort(J))\n\tgoto retry;\n      setvmstate(J2G(J), INTERP);\n      J->state = LJ_TRACE_IDLE;\n      lj_dispatch_update(J2G(J));\n      return NULL;\n    }\n  } while (J->state > LJ_TRACE_RECORD);\n  return NULL;\n}\n\n/* -- Event handling ------------------------------------------------------ */\n\n/* A bytecode instruction is about to be executed. Record it. */\nvoid lj_trace_ins(jit_State *J, const BCIns *pc)\n{\n  /* Note: J->L must already be set. pc is the true bytecode PC here. */\n  J->pc = pc;\n  J->fn = curr_func(J->L);\n  J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL;\n  while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0)\n    J->state = LJ_TRACE_ERR;\n}\n\n/* A hotcount triggered. Start recording a root trace. */\nvoid LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc)\n{\n  /* Note: pc is the interpreter bytecode PC here. It's offset by 1. */\n  ERRNO_SAVE\n  /* Reset hotcount. */\n  hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP);\n  /* Only start a new trace if not recording or inside __gc call or vmevent. */\n  if (J->state == LJ_TRACE_IDLE &&\n      !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n    J->parent = 0;  /* Root trace. */\n    J->exitno = 0;\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc-1);\n  }\n  ERRNO_RESTORE\n}\n\n/* Check for a hot side exit. If yes, start recording a side trace. */\nstatic void trace_hotside(jit_State *J, const BCIns *pc)\n{\n  SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno];\n  if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) &&\n      isluafunc(curr_func(J->L)) &&\n      snap->count != SNAPCOUNT_DONE &&\n      ++snap->count >= J->param[JIT_P_hotexit]) {\n    lua_assert(J->state == LJ_TRACE_IDLE);\n    /* J->parent is non-zero for a side trace. */\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc);\n  }\n}\n\n/* Stitch a new trace to the previous trace. */\nvoid LJ_FASTCALL lj_trace_stitch(jit_State *J, const BCIns *pc)\n{\n  /* Only start a new trace if not recording or inside __gc call or vmevent. */\n  if (J->state == LJ_TRACE_IDLE &&\n      !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n    J->parent = 0;  /* Have to treat it like a root trace. */\n    /* J->exitno is set to the invoking trace. */\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc);\n  }\n}\n\n\n/* Tiny struct to pass data to protected call. */\ntypedef struct ExitDataCP {\n  jit_State *J;\n  void *exptr;\t\t/* Pointer to exit state. */\n  const BCIns *pc;\t/* Restart interpreter at this PC. */\n} ExitDataCP;\n\n/* Need to protect lj_snap_restore because it may throw. */\nstatic TValue *trace_exit_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  ExitDataCP *exd = (ExitDataCP *)ud;\n  cframe_errfunc(L->cframe) = -1;  /* Inherit error function. */\n  exd->pc = lj_snap_restore(exd->J, exd->exptr);\n  UNUSED(dummy);\n  return NULL;\n}\n\n#ifndef LUAJIT_DISABLE_VMEVENT\n/* Push all registers from exit state. */\nstatic void trace_exit_regs(lua_State *L, ExitState *ex)\n{\n  int32_t i;\n  setintV(L->top++, RID_NUM_GPR);\n  setintV(L->top++, RID_NUM_FPR);\n  for (i = 0; i < RID_NUM_GPR; i++) {\n    if (sizeof(ex->gpr[i]) == sizeof(int32_t))\n      setintV(L->top++, (int32_t)ex->gpr[i]);\n    else\n      setnumV(L->top++, (lua_Number)ex->gpr[i]);\n  }\n#if !LJ_SOFTFP\n  for (i = 0; i < RID_NUM_FPR; i++) {\n    setnumV(L->top, ex->fpr[i]);\n    if (LJ_UNLIKELY(tvisnan(L->top)))\n      setnanV(L->top);\n    L->top++;\n  }\n#endif\n}\n#endif\n\n#ifdef EXITSTATE_PCREG\n/* Determine trace number from pc of exit instruction. */\nstatic TraceNo trace_exit_find(jit_State *J, MCode *pc)\n{\n  TraceNo traceno;\n  for (traceno = 1; traceno < J->sizetrace; traceno++) {\n    GCtrace *T = traceref(J, traceno);\n    if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode))\n      return traceno;\n  }\n  lua_assert(0);\n  return 0;\n}\n#endif\n\n/* A trace exited. Restore interpreter state. */\nint LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)\n{\n  ERRNO_SAVE\n  lua_State *L = J->L;\n  ExitState *ex = (ExitState *)exptr;\n  ExitDataCP exd;\n  int errcode;\n  const BCIns *pc;\n  void *cf;\n  GCtrace *T;\n#ifdef EXITSTATE_PCREG\n  J->parent = trace_exit_find(J, (MCode *)(intptr_t)ex->gpr[EXITSTATE_PCREG]);\n#endif\n  T = traceref(J, J->parent); UNUSED(T);\n#ifdef EXITSTATE_CHECKEXIT\n  if (J->exitno == T->nsnap) {  /* Treat stack check like a parent exit. */\n    lua_assert(T->root != 0);\n    J->exitno = T->ir[REF_BASE].op2;\n    J->parent = T->ir[REF_BASE].op1;\n    T = traceref(J, J->parent);\n  }\n#endif\n  lua_assert(T != NULL && J->exitno < T->nsnap);\n  exd.J = J;\n  exd.exptr = exptr;\n  errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp);\n  if (errcode)\n    return -errcode;  /* Return negated error code. */\n\n  if (!(LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)))\n    lj_vmevent_send(L, TEXIT,\n      lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);\n      setintV(L->top++, J->parent);\n      setintV(L->top++, J->exitno);\n      trace_exit_regs(L, ex);\n    );\n\n  pc = exd.pc;\n  cf = cframe_raw(L->cframe);\n  setcframe_pc(cf, pc);\n  if (LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)) {\n    /* Just exit to interpreter. */\n  } else if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {\n    if (!(G(L)->hookmask & HOOK_GC))\n      lj_gc_step(L);  /* Exited because of GC: drive GC forward. */\n  } else {\n    trace_hotside(J, pc);\n  }\n  if (bc_op(*pc) == BC_JLOOP) {\n    BCIns *retpc = &traceref(J, bc_d(*pc))->startins;\n    if (bc_isret(bc_op(*retpc))) {\n      if (J->state == LJ_TRACE_RECORD) {\n\tJ->patchins = *pc;\n\tJ->patchpc = (BCIns *)pc;\n\t*J->patchpc = *retpc;\n\tJ->bcskip = 1;\n      } else {\n\tpc = retpc;\n\tsetcframe_pc(cf, pc);\n      }\n    }\n  }\n  /* Return MULTRES or 0. */\n  ERRNO_RESTORE\n  switch (bc_op(*pc)) {\n  case BC_CALLM: case BC_CALLMT:\n    return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc) + LJ_FR2);\n  case BC_RETM:\n    return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc));\n  case BC_TSETM:\n    return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc));\n  default:\n    if (bc_op(*pc) >= BC_FUNCF)\n      return (int)((BCReg)(L->top - L->base) + 1);\n    return 0;\n  }\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_trace.h",
    "content": "/*\n** Trace management.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TRACE_H\n#define _LJ_TRACE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#include \"lj_dispatch.h\"\n\n/* Trace errors. */\ntypedef enum {\n#define TREDEF(name, msg)\tLJ_TRERR_##name,\n#include \"lj_traceerr.h\"\n  LJ_TRERR__MAX\n} TraceError;\n\nLJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);\nLJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);\n\n/* Trace management. */\nLJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);\nLJ_FUNC void lj_trace_reenableproto(GCproto *pt);\nLJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);\nLJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno);\nLJ_FUNC int lj_trace_flushall(lua_State *L);\nLJ_FUNC void lj_trace_initstate(global_State *g);\nLJ_FUNC void lj_trace_freestate(global_State *g);\n\n/* Event handling. */\nLJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc);\nLJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc);\nLJ_FUNCA void LJ_FASTCALL lj_trace_stitch(jit_State *J, const BCIns *pc);\nLJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);\n\n/* Signal asynchronous abort of trace or end of trace. */\n#define lj_trace_abort(g)\t(G2J(g)->state &= ~LJ_TRACE_ACTIVE)\n#define lj_trace_end(J)\t\t(J->state = LJ_TRACE_END)\n\n#else\n\n#define lj_trace_flushall(L)\t(UNUSED(L), 0)\n#define lj_trace_initstate(g)\tUNUSED(g)\n#define lj_trace_freestate(g)\tUNUSED(g)\n#define lj_trace_abort(g)\tUNUSED(g)\n#define lj_trace_end(J)\t\tUNUSED(J)\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_traceerr.h",
    "content": "/*\n** Trace compiler error messages.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* This file may be included multiple times with different TREDEF macros. */\n\n/* Recording. */\nTREDEF(RECERR,\t\"error thrown or hook called during recording\")\nTREDEF(TRACEUV,\t\"trace too short\")\nTREDEF(TRACEOV,\t\"trace too long\")\nTREDEF(STACKOV,\t\"trace too deep\")\nTREDEF(SNAPOV,\t\"too many snapshots\")\nTREDEF(BLACKL,\t\"blacklisted\")\nTREDEF(RETRY,\t\"retry recording\")\nTREDEF(NYIBC,\t\"NYI: bytecode %d\")\n\n/* Recording loop ops. */\nTREDEF(LLEAVE,\t\"leaving loop in root trace\")\nTREDEF(LINNER,\t\"inner loop in root trace\")\nTREDEF(LUNROLL,\t\"loop unroll limit reached\")\n\n/* Recording calls/returns. */\nTREDEF(BADTYPE,\t\"bad argument type\")\nTREDEF(CJITOFF,\t\"JIT compilation disabled for function\")\nTREDEF(CUNROLL,\t\"call unroll limit reached\")\nTREDEF(DOWNREC,\t\"down-recursion, restarting\")\nTREDEF(NYIFFU,\t\"NYI: unsupported variant of FastFunc %s\")\nTREDEF(NYIRETL,\t\"NYI: return to lower frame\")\n\n/* Recording indexed load/store. */\nTREDEF(STORENN,\t\"store with nil or NaN key\")\nTREDEF(NOMM,\t\"missing metamethod\")\nTREDEF(IDXLOOP,\t\"looping index lookup\")\nTREDEF(NYITMIX,\t\"NYI: mixed sparse/dense table\")\n\n/* Recording C data operations. */\nTREDEF(NOCACHE,\t\"symbol not in cache\")\nTREDEF(NYICONV,\t\"NYI: unsupported C type conversion\")\nTREDEF(NYICALL,\t\"NYI: unsupported C function type\")\n\n/* Optimizations. */\nTREDEF(GFAIL,\t\"guard would always fail\")\nTREDEF(PHIOV,\t\"too many PHIs\")\nTREDEF(TYPEINS,\t\"persistent type instability\")\n\n/* Assembler. */\nTREDEF(MCODEAL,\t\"failed to allocate mcode memory\")\nTREDEF(MCODEOV,\t\"machine code too long\")\nTREDEF(MCODELM,\t\"hit mcode limit (retrying)\")\nTREDEF(SPILLOV,\t\"too many spill slots\")\nTREDEF(BADRA,\t\"inconsistent register allocation\")\nTREDEF(NYIIR,\t\"NYI: cannot assemble IR instruction %d\")\nTREDEF(NYIPHI,\t\"NYI: PHI shuffling too complex\")\nTREDEF(NYICOAL,\t\"NYI: register coalescing too complex\")\n\n#undef TREDEF\n\n/* Detecting unused error messages:\n   awk -F, '/^TREDEF/ { gsub(/TREDEF./, \"\"); printf \"grep -q LJ_TRERR_%s *.[ch] || echo %s\\n\", $1, $1}' lj_traceerr.h | sh\n*/\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_udata.c",
    "content": "/*\n** Userdata handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_udata_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_udata.h\"\n\nGCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)\n{\n  GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata);\n  global_State *g = G(L);\n  newwhite(g, ud);  /* Not finalized. */\n  ud->gct = ~LJ_TUDATA;\n  ud->udtype = UDTYPE_USERDATA;\n  ud->len = sz;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcrefnull(ud->metatable);\n  setgcref(ud->env, obj2gco(env));\n  /* Chain to userdata list (after main thread). */\n  setgcrefr(ud->nextgc, mainthread(g)->nextgc);\n  setgcref(mainthread(g)->nextgc, obj2gco(ud));\n  return ud;\n}\n\nvoid LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)\n{\n  lj_mem_free(g, ud, sizeudata(ud));\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_udata.h",
    "content": "/*\n** Userdata handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_UDATA_H\n#define _LJ_UDATA_H\n\n#include \"lj_obj.h\"\n\nLJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);\nLJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_vm.h",
    "content": "/*\n** Assembler VM interface definitions.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_VM_H\n#define _LJ_VM_H\n\n#include \"lj_obj.h\"\n\n/* Entry points for ASM parts of VM. */\nLJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1);\nLJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);\ntypedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud);\nLJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,\n\t\t\t lua_CPFunction cp);\nLJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);\nLJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);\nLJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);\nLJ_ASMF void lj_vm_unwind_c_eh(void);\nLJ_ASMF void lj_vm_unwind_ff_eh(void);\n#if LJ_TARGET_X86ORX64\nLJ_ASMF void lj_vm_unwind_rethrow(void);\n#endif\n\n/* Miscellaneous functions. */\n#if LJ_TARGET_X86ORX64\nLJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]);\n#endif\n#if LJ_TARGET_PPC\nvoid lj_vm_cachesync(void *start, void *end);\n#endif\nLJ_ASMF double lj_vm_foldarith(double x, double y, int op);\n#if LJ_HASJIT\nLJ_ASMF double lj_vm_foldfpm(double x, int op);\n#endif\n#if !LJ_ARCH_HASFPU\n/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */\n#endif\n\n/* Dispatch targets for recording and hooks. */\nLJ_ASMF void lj_vm_record(void);\nLJ_ASMF void lj_vm_inshook(void);\nLJ_ASMF void lj_vm_rethook(void);\nLJ_ASMF void lj_vm_callhook(void);\nLJ_ASMF void lj_vm_profhook(void);\n\n/* Trace exit handling. */\nLJ_ASMF void lj_vm_exit_handler(void);\nLJ_ASMF void lj_vm_exit_interp(void);\n\n/* Internal math helper functions. */\n#if LJ_TARGET_PPC || LJ_TARGET_ARM64 || (LJ_TARGET_MIPS && LJ_ABI_SOFTFP)\n#define lj_vm_floor\tfloor\n#define lj_vm_ceil\tceil\n#else\nLJ_ASMF double lj_vm_floor(double);\nLJ_ASMF double lj_vm_ceil(double);\n#if LJ_TARGET_ARM\nLJ_ASMF double lj_vm_floor_sf(double);\nLJ_ASMF double lj_vm_ceil_sf(double);\n#endif\n#endif\n#ifdef LUAJIT_NO_LOG2\nLJ_ASMF double lj_vm_log2(double);\n#else\n#define lj_vm_log2\tlog2\n#endif\n#if !(defined(_LJ_DISPATCH_H) && LJ_TARGET_MIPS)\nLJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t);\n#endif\n\n#if LJ_HASJIT\n#if LJ_TARGET_X86ORX64\nLJ_ASMF void lj_vm_floor_sse(void);\nLJ_ASMF void lj_vm_ceil_sse(void);\nLJ_ASMF void lj_vm_trunc_sse(void);\nLJ_ASMF void lj_vm_powi_sse(void);\n#define lj_vm_powi\tNULL\n#else\nLJ_ASMF double lj_vm_powi(double, int32_t);\n#endif\n#if LJ_TARGET_PPC || LJ_TARGET_ARM64\n#define lj_vm_trunc\ttrunc\n#else\nLJ_ASMF double lj_vm_trunc(double);\n#if LJ_TARGET_ARM\nLJ_ASMF double lj_vm_trunc_sf(double);\n#endif\n#endif\n#ifdef LUAJIT_NO_EXP2\nLJ_ASMF double lj_vm_exp2(double);\n#else\n#define lj_vm_exp2\texp2\n#endif\n#if LJ_HASFFI\nLJ_ASMF int lj_vm_errno(void);\n#endif\n#endif\n\n/* Continuations for metamethods. */\nLJ_ASMF void lj_cont_cat(void);  /* Continue with concatenation. */\nLJ_ASMF void lj_cont_ra(void);  /* Store result in RA from instruction. */\nLJ_ASMF void lj_cont_nop(void);  /* Do nothing, just continue execution. */\nLJ_ASMF void lj_cont_condt(void);  /* Branch if result is true. */\nLJ_ASMF void lj_cont_condf(void);  /* Branch if result is false. */\nLJ_ASMF void lj_cont_hook(void);  /* Continue from hook yield. */\nLJ_ASMF void lj_cont_stitch(void);  /* Trace stitching. */\n\n/* Start of the ASM code. */\nLJ_ASMF char lj_vm_asm_begin[];\n\n/* Bytecode offsets are relative to lj_vm_asm_begin. */\n#define makeasmfunc(ofs)\t((ASMFunction)(lj_vm_asm_begin + (ofs)))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_vmevent.c",
    "content": "/*\n** VM event handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <stdio.h>\n\n#define lj_vmevent_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n\nptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)\n{\n  global_State *g = G(L);\n  GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY);\n  cTValue *tv = lj_tab_getstr(tabV(registry(L)), s);\n  if (tvistab(tv)) {\n    int hash = VMEVENT_HASH(ev);\n    tv = lj_tab_getint(tabV(tv), hash);\n    if (tv && tvisfunc(tv)) {\n      lj_state_checkstack(L, LUA_MINSTACK);\n      setfuncV(L, L->top++, funcV(tv));\n      if (LJ_FR2) setnilV(L->top++);\n      return savestack(L, L->top);\n    }\n  }\n  g->vmevmask &= ~VMEVENT_MASK(ev);  /* No handler: cache this fact. */\n  return 0;\n}\n\nvoid lj_vmevent_call(lua_State *L, ptrdiff_t argbase)\n{\n  global_State *g = G(L);\n  uint8_t oldmask = g->vmevmask;\n  uint8_t oldh = hook_save(g);\n  int status;\n  g->vmevmask = 0;  /* Disable all events. */\n  hook_vmevent(g);\n  status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0);\n  if (LJ_UNLIKELY(status)) {\n    /* Really shouldn't use stderr here, but where else to complain? */\n    L->top--;\n    fputs(\"VM handler failed: \", stderr);\n    fputs(tvisstr(L->top) ? strVdata(L->top) : \"?\", stderr);\n    fputc('\\n', stderr);\n  }\n  hook_restore(g, oldh);\n  if (g->vmevmask != VMEVENT_NOCACHE)\n    g->vmevmask = oldmask;  /* Restore event mask, but not if not modified. */\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_vmevent.h",
    "content": "/*\n** VM event handling.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_VMEVENT_H\n#define _LJ_VMEVENT_H\n\n#include \"lj_obj.h\"\n\n/* Registry key for VM event handler table. */\n#define LJ_VMEVENTS_REGKEY\t\"_VMEVENTS\"\n#define LJ_VMEVENTS_HSIZE\t4\n\n#define VMEVENT_MASK(ev)\t((uint8_t)1 << ((int)(ev) & 7))\n#define VMEVENT_HASH(ev)\t((int)(ev) & ~7)\n#define VMEVENT_HASHIDX(h)\t((int)(h) << 3)\n#define VMEVENT_NOCACHE\t\t255\n\n#define VMEVENT_DEF(name, hash) \\\n  LJ_VMEVENT_##name##_, \\\n  LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)\n\n/* VM event IDs. */\ntypedef enum {\n  VMEVENT_DEF(BC,\t0x00003883),\n  VMEVENT_DEF(TRACE,\t0xb2d91467),\n  VMEVENT_DEF(RECORD,\t0x9284bf4f),\n  VMEVENT_DEF(TEXIT,\t0xb29df2b0),\n  LJ_VMEVENT__MAX\n} VMEvent;\n\n#ifdef LUAJIT_DISABLE_VMEVENT\n#define lj_vmevent_send(L, ev, args)\t\tUNUSED(L)\n#define lj_vmevent_send_(L, ev, args, post)\tUNUSED(L)\n#else\n#define lj_vmevent_send(L, ev, args) \\\n  if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \\\n    ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \\\n    if (argbase) { \\\n      args \\\n      lj_vmevent_call(L, argbase); \\\n    } \\\n  }\n#define lj_vmevent_send_(L, ev, args, post) \\\n  if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \\\n    ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \\\n    if (argbase) { \\\n      args \\\n      lj_vmevent_call(L, argbase); \\\n      post \\\n    } \\\n  }\n\nLJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);\nLJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lj_vmmath.c",
    "content": "/*\n** Math helper functions for assembler VM.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_vmmath_c\n#define LUA_CORE\n\n#include <errno.h>\n#include <math.h>\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n#include \"lj_vm.h\"\n\n/* -- Wrapper functions --------------------------------------------------- */\n\n#if LJ_TARGET_X86 && __ELF__ && __PIC__\n/* Wrapper functions to deal with the ELF/x86 PIC disaster. */\nLJ_FUNCA double lj_wrap_log(double x) { return log(x); }\nLJ_FUNCA double lj_wrap_log10(double x) { return log10(x); }\nLJ_FUNCA double lj_wrap_exp(double x) { return exp(x); }\nLJ_FUNCA double lj_wrap_sin(double x) { return sin(x); }\nLJ_FUNCA double lj_wrap_cos(double x) { return cos(x); }\nLJ_FUNCA double lj_wrap_tan(double x) { return tan(x); }\nLJ_FUNCA double lj_wrap_asin(double x) { return asin(x); }\nLJ_FUNCA double lj_wrap_acos(double x) { return acos(x); }\nLJ_FUNCA double lj_wrap_atan(double x) { return atan(x); }\nLJ_FUNCA double lj_wrap_sinh(double x) { return sinh(x); }\nLJ_FUNCA double lj_wrap_cosh(double x) { return cosh(x); }\nLJ_FUNCA double lj_wrap_tanh(double x) { return tanh(x); }\nLJ_FUNCA double lj_wrap_atan2(double x, double y) { return atan2(x, y); }\nLJ_FUNCA double lj_wrap_pow(double x, double y) { return pow(x, y); }\nLJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); }\n#endif\n\n/* -- Helper functions for generated machine code ------------------------- */\n\ndouble lj_vm_foldarith(double x, double y, int op)\n{\n  switch (op) {\n  case IR_ADD - IR_ADD: return x+y; break;\n  case IR_SUB - IR_ADD: return x-y; break;\n  case IR_MUL - IR_ADD: return x*y; break;\n  case IR_DIV - IR_ADD: return x/y; break;\n  case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break;\n  case IR_POW - IR_ADD: return pow(x, y); break;\n  case IR_NEG - IR_ADD: return -x; break;\n  case IR_ABS - IR_ADD: return fabs(x); break;\n#if LJ_HASJIT\n  case IR_ATAN2 - IR_ADD: return atan2(x, y); break;\n  case IR_LDEXP - IR_ADD: return ldexp(x, (int)y); break;\n  case IR_MIN - IR_ADD: return x > y ? y : x; break;\n  case IR_MAX - IR_ADD: return x < y ? y : x; break;\n#endif\n  default: return x;\n  }\n}\n\n#if (LJ_HASJIT && !(LJ_TARGET_ARM || LJ_TARGET_ARM64 || LJ_TARGET_PPC)) || LJ_TARGET_MIPS\nint32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b)\n{\n  uint32_t y, ua, ub;\n  lua_assert(b != 0);  /* This must be checked before using this function. */\n  ua = a < 0 ? (uint32_t)-a : (uint32_t)a;\n  ub = b < 0 ? (uint32_t)-b : (uint32_t)b;\n  y = ua % ub;\n  if (y != 0 && (a^b) < 0) y = y - ub;\n  if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y;\n  return (int32_t)y;\n}\n#endif\n\n#if LJ_HASJIT\n\n#ifdef LUAJIT_NO_LOG2\ndouble lj_vm_log2(double a)\n{\n  return log(a) * 1.4426950408889634074;\n}\n#endif\n\n#ifdef LUAJIT_NO_EXP2\ndouble lj_vm_exp2(double a)\n{\n  return exp(a * 0.6931471805599453);\n}\n#endif\n\n#if !LJ_TARGET_X86ORX64\n/* Unsigned x^k. */\nstatic double lj_vm_powui(double x, uint32_t k)\n{\n  double y;\n  lua_assert(k != 0);\n  for (; (k & 1) == 0; k >>= 1) x *= x;\n  y = x;\n  if ((k >>= 1) != 0) {\n    for (;;) {\n      x *= x;\n      if (k == 1) break;\n      if (k & 1) y *= x;\n      k >>= 1;\n    }\n    y *= x;\n  }\n  return y;\n}\n\n/* Signed x^k. */\ndouble lj_vm_powi(double x, int32_t k)\n{\n  if (k > 1)\n    return lj_vm_powui(x, (uint32_t)k);\n  else if (k == 1)\n    return x;\n  else if (k == 0)\n    return 1.0;\n  else\n    return 1.0 / lj_vm_powui(x, (uint32_t)-k);\n}\n#endif\n\n/* Computes fpm(x) for extended math functions. */\ndouble lj_vm_foldfpm(double x, int fpm)\n{\n  switch (fpm) {\n  case IRFPM_FLOOR: return lj_vm_floor(x);\n  case IRFPM_CEIL: return lj_vm_ceil(x);\n  case IRFPM_TRUNC: return lj_vm_trunc(x);\n  case IRFPM_SQRT: return sqrt(x);\n  case IRFPM_EXP: return exp(x);\n  case IRFPM_EXP2: return lj_vm_exp2(x);\n  case IRFPM_LOG: return log(x);\n  case IRFPM_LOG2: return lj_vm_log2(x);\n  case IRFPM_LOG10: return log10(x);\n  case IRFPM_SIN: return sin(x);\n  case IRFPM_COS: return cos(x);\n  case IRFPM_TAN: return tan(x);\n  default: lua_assert(0);\n  }\n  return 0;\n}\n\n#if LJ_HASFFI\nint lj_vm_errno(void)\n{\n  return errno;\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/ljamalg.c",
    "content": "/*\n** LuaJIT core and libraries amalgamation.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/*\n+--------------------------------------------------------------------------+\n| WARNING: Compiling the amalgamation needs a lot of virtual memory        |\n| (around 300 MB with GCC 4.x)! If you don't have enough physical memory   |\n| your machine will start swapping to disk and the compile will not finish |\n| within a reasonable amount of time.                                      |\n| So either compile on a bigger machine or use the non-amalgamated build.  |\n+--------------------------------------------------------------------------+\n*/\n\n#define ljamalg_c\n#define LUA_CORE\n\n/* To get the mremap prototype. Must be defined before any system includes. */\n#if defined(__linux__) && !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n\n#ifndef WINVER\n#define WINVER 0x0501\n#endif\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_gc.c\"\n#include \"lj_err.c\"\n#include \"lj_char.c\"\n#include \"lj_bc.c\"\n#include \"lj_obj.c\"\n#include \"lj_buf.c\"\n#include \"lj_str.c\"\n#include \"lj_tab.c\"\n#include \"lj_func.c\"\n#include \"lj_udata.c\"\n#include \"lj_meta.c\"\n#include \"lj_debug.c\"\n#include \"lj_state.c\"\n#include \"lj_dispatch.c\"\n#include \"lj_vmevent.c\"\n#include \"lj_vmmath.c\"\n#include \"lj_strscan.c\"\n#include \"lj_strfmt.c\"\n#include \"lj_strfmt_num.c\"\n#include \"lj_api.c\"\n#include \"lj_profile.c\"\n#include \"lj_lex.c\"\n#include \"lj_parse.c\"\n#include \"lj_bcread.c\"\n#include \"lj_bcwrite.c\"\n#include \"lj_load.c\"\n#include \"lj_ctype.c\"\n#include \"lj_cdata.c\"\n#include \"lj_cconv.c\"\n#include \"lj_ccall.c\"\n#include \"lj_ccallback.c\"\n#include \"lj_carith.c\"\n#include \"lj_clib.c\"\n#include \"lj_cparse.c\"\n#include \"lj_lib.c\"\n#include \"lj_ir.c\"\n#include \"lj_opt_mem.c\"\n#include \"lj_opt_fold.c\"\n#include \"lj_opt_narrow.c\"\n#include \"lj_opt_dce.c\"\n#include \"lj_opt_loop.c\"\n#include \"lj_opt_split.c\"\n#include \"lj_opt_sink.c\"\n#include \"lj_mcode.c\"\n#include \"lj_snap.c\"\n#include \"lj_record.c\"\n#include \"lj_crecord.c\"\n#include \"lj_ffrecord.c\"\n#include \"lj_asm.c\"\n#include \"lj_trace.c\"\n#include \"lj_gdbjit.c\"\n#include \"lj_alloc.c\"\n\n#include \"lib_aux.c\"\n#include \"lib_base.c\"\n#include \"lib_math.c\"\n#include \"lib_string.c\"\n#include \"lib_table.c\"\n#include \"lib_io.c\"\n#include \"lib_os.c\"\n#include \"lib_package.c\"\n#include \"lib_debug.c\"\n#include \"lib_bit.c\"\n#include \"lib_jit.c\"\n#include \"lib_ffi.c\"\n#include \"lib_init.c\"\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $\n** Lua - An Extensible Extension Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION\t\"Lua 5.1\"\n#define LUA_RELEASE\t\"Lua 5.1.4\"\n#define LUA_VERSION_NUM\t501\n#define LUA_COPYRIGHT\t\"Copyright (C) 1994-2008 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo & W. Celes\"\n\n\n/* mark for precompiled code (`<esc>Lua') */\n#define\tLUA_SIGNATURE\t\"\\033Lua\"\n\n/* option for multiple returns in `lua_pcall' and `lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** pseudo-indices\n*/\n#define LUA_REGISTRYINDEX\t(-10000)\n#define LUA_ENVIRONINDEX\t(-10001)\n#define LUA_GLOBALSINDEX\t(-10002)\n#define lua_upvalueindex(i)\t(LUA_GLOBALSINDEX-(i))\n\n\n/* thread status; 0 is OK */\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\n\ntypedef int (*lua_CFunction) (lua_State *L);\n\n\n/*\n** functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);\n\n\n/*\n** prototype for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_remove) (lua_State *L, int idx);\nLUA_API void  (lua_insert) (lua_State *L, int idx);\nLUA_API void  (lua_replace) (lua_State *L, int idx);\nLUA_API int   (lua_checkstack) (lua_State *L, int sz);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);\n\nLUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);\nLUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_objlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void  (lua_pushnil) (lua_State *L);\nLUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);\nLUA_API void  (lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API void  (lua_gettable) (lua_State *L, int idx);\nLUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawget) (lua_State *L, int idx);\nLUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_getfenv) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setfenv) (lua_State *L, int idx);\n\n\n/*\n** `load' and `call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);\nLUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);\nLUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                                        const char *chunkname);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yield) (lua_State *L, int nresults);\nLUA_API int  (lua_resume) (lua_State *L, int narg);\nLUA_API int  (lua_status) (lua_State *L);\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_strlen(L,i)\t\tlua_objlen(L, (i))\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\t\\\n\tlua_pushlstring(L, \"\" s, (sizeof(s)/sizeof(char))-1)\n\n#define lua_setglobal(L,s)\tlua_setfield(L, LUA_GLOBALSINDEX, (s))\n#define lua_getglobal(L,s)\tlua_getfield(L, LUA_GLOBALSINDEX, (s))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n\n/*\n** compatibility macros and functions\n*/\n\n#define lua_open()\tluaL_newstate()\n\n#define lua_getregistry(L)\tlua_pushvalue(L, LUA_REGISTRYINDEX)\n\n#define lua_getgccount(L)\tlua_gc(L, LUA_GCCOUNT, 0)\n\n#define lua_Chunkreader\t\tlua_Reader\n#define lua_Chunkwriter\t\tlua_Writer\n\n\n/* hack */\nLUA_API void lua_setlevel\t(lua_State *from, lua_State *to);\n\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILRET 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debuger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook lua_gethook (lua_State *L);\nLUA_API int lua_gethookmask (lua_State *L);\nLUA_API int lua_gethookcount (lua_State *L);\n\n/* From Lua 5.2. */\nLUA_API void *lua_upvalueid (lua_State *L, int idx, int n);\nLUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);\nLUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,\n\t\t       const char *chunkname, const char *mode);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) `global', `local', `field', `method' */\n  const char *what;\t/* (S) `Lua', `C', `main', `tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int nups;\t\t/* (u) number of upvalues */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  int i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lua.hpp",
    "content": "// C++ wrapper for LuaJIT header files.\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include \"luajit.h\"\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/luaconf.h",
    "content": "/*\n** Configuration header.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#ifndef WINVER\n#define WINVER 0x0501\n#endif\n#include <limits.h>\n#include <stddef.h>\n\n/* Default path for loading Lua and C modules with require(). */\n#if defined(_WIN32)\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_PATH_DEFAULT \\\n  \".\\\\?.lua;\" LUA_LDIR\"?.lua;\" LUA_LDIR\"?\\\\init.lua;\"\n#define LUA_CPATH_DEFAULT \\\n  \".\\\\?.dll;\" LUA_CDIR\"?.dll;\" LUA_CDIR\"loadall.dll\"\n#else\n/*\n** Note to distribution maintainers: do NOT patch the following lines!\n** Please read ../doc/install.html#distro and pass PREFIX=/usr instead.\n*/\n#ifndef LUA_MULTILIB\n#define LUA_MULTILIB\t\"lib\"\n#endif\n#ifndef LUA_LMULTILIB\n#define LUA_LMULTILIB\t\"lib\"\n#endif\n#define LUA_LROOT\t\"/usr/local\"\n#define LUA_LUADIR\t\"/lua/5.1/\"\n#define LUA_LJDIR\t\"/luajit-2.1.0-beta2/\"\n\n#ifdef LUA_ROOT\n#define LUA_JROOT\tLUA_ROOT\n#define LUA_RLDIR\tLUA_ROOT \"/share\" LUA_LUADIR\n#define LUA_RCDIR\tLUA_ROOT \"/\" LUA_MULTILIB LUA_LUADIR\n#define LUA_RLPATH\t\";\" LUA_RLDIR \"?.lua;\" LUA_RLDIR \"?/init.lua\"\n#define LUA_RCPATH\t\";\" LUA_RCDIR \"?.so\"\n#else\n#define LUA_JROOT\tLUA_LROOT\n#define LUA_RLPATH\n#define LUA_RCPATH\n#endif\n\n#define LUA_JPATH\t\";\" LUA_JROOT \"/share\" LUA_LJDIR \"?.lua\"\n#define LUA_LLDIR\tLUA_LROOT \"/share\" LUA_LUADIR\n#define LUA_LCDIR\tLUA_LROOT \"/\" LUA_LMULTILIB LUA_LUADIR\n#define LUA_LLPATH\t\";\" LUA_LLDIR \"?.lua;\" LUA_LLDIR \"?/init.lua\"\n#define LUA_LCPATH1\t\";\" LUA_LCDIR \"?.so\"\n#define LUA_LCPATH2\t\";\" LUA_LCDIR \"loadall.so\"\n\n#define LUA_PATH_DEFAULT\t\"./?.lua\" LUA_JPATH LUA_LLPATH LUA_RLPATH\n#define LUA_CPATH_DEFAULT\t\"./?.so\" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2\n#endif\n\n/* Environment variable names for path overrides and initialization code. */\n#define LUA_PATH\t\"LUA_PATH\"\n#define LUA_CPATH\t\"LUA_CPATH\"\n#define LUA_INIT\t\"LUA_INIT\"\n\n/* Special file system characters. */\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n#define LUA_PATHSEP\t\";\"\n#define LUA_PATH_MARK\t\"?\"\n#define LUA_EXECDIR\t\"!\"\n#define LUA_IGMARK\t\"-\"\n#define LUA_PATH_CONFIG \\\n  LUA_DIRSEP \"\\n\" LUA_PATHSEP \"\\n\" LUA_PATH_MARK \"\\n\" \\\n  LUA_EXECDIR \"\\n\" LUA_IGMARK\n\n/* Quoting in error messages. */\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n/* Various tunables. */\n#define LUAI_MAXSTACK\t65500\t/* Max. # of stack slots for a thread (<64K). */\n#define LUAI_MAXCSTACK\t8000\t/* Max. # of stack slots for a C func (<10K). */\n#define LUAI_GCPAUSE\t200\t/* Pause GC until memory is at 200%. */\n#define LUAI_GCMUL\t200\t/* Run GC at 200% of allocation speed. */\n#define LUA_MAXCAPTURES\t32\t/* Max. pattern captures. */\n\n/* Compatibility with older library function names. */\n#define LUA_COMPAT_MOD\t\t/* OLD: math.mod, NEW: math.fmod */\n#define LUA_COMPAT_GFIND\t/* OLD: string.gfind, NEW: string.gmatch */\n\n/* Configuration for the frontend (the luajit executable). */\n#if defined(luajit_c)\n#define LUA_PROGNAME\t\"luajit\"  /* Fallback frontend name. */\n#define LUA_PROMPT\t\"> \"\t/* Interactive prompt. */\n#define LUA_PROMPT2\t\">> \"\t/* Continuation prompt. */\n#define LUA_MAXINPUT\t512\t/* Max. input line length. */\n#endif\n\n/* Note: changing the following defines breaks the Lua 5.1 ABI. */\n#define LUA_INTEGER\tptrdiff_t\n#define LUA_IDSIZE\t256\t/* Size of lua_Debug.short_src. */\n/*\n** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using\n** unreasonable amounts of stack space, but still retain ABI compatibility.\n** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it.\n*/\n#define LUAL_BUFFERSIZE\t(BUFSIZ > 16384 ? 8192 : BUFSIZ)\n\n/* The following defines are here only for compatibility with luaconf.h\n** from the standard Lua distribution. They must not be changed for LuaJIT.\n*/\n#define LUA_NUMBER_DOUBLE\n#define LUA_NUMBER\t\tdouble\n#define LUAI_UACNUMBER\t\tdouble\n#define LUA_NUMBER_SCAN\t\t\"%lf\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n#define lua_number2str(s, n)\tsprintf((s), LUA_NUMBER_FMT, (n))\n#define LUAI_MAXNUMBER2STR\t32\n#define LUA_INTFRMLEN\t\t\"l\"\n#define LUA_INTFRM_T\t\tlong\n\n/* Linkage of public API functions. */\n#if defined(LUA_BUILD_AS_DLL)\n#if defined(LUA_CORE) || defined(LUA_LIB)\n#define LUA_API\t\t__declspec(dllexport)\n#else\n#define LUA_API\t\t__declspec(dllimport)\n#endif\n#else\n#define LUA_API\t\textern\n#endif\n\n#define LUALIB_API\tLUA_API\n\n/* Support for internal assertions. */\n#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)\n#include <assert.h>\n#endif\n#ifdef LUA_USE_ASSERT\n#define lua_assert(x)\t\tassert(x)\n#endif\n#ifdef LUA_USE_APICHECK\n#define luai_apicheck(L, o)\t{ (void)L; assert(o); }\n#else\n#define luai_apicheck(L, o)\t{ (void)L; }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/luajit.c",
    "content": "/*\n** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define luajit_c\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include \"luajit.h\"\n\n#include \"lj_arch.h\"\n\n#if LJ_TARGET_POSIX\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n#elif LJ_TARGET_WINDOWS\n#include <io.h>\n#ifdef __BORLANDC__\n#define lua_stdin_is_tty()\tisatty(_fileno(stdin))\n#else\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n#endif\n#else\n#define lua_stdin_is_tty()\t1\n#endif\n\n#if !LJ_TARGET_CONSOLE\n#include <signal.h>\n#endif\n\nstatic lua_State *globalL = NULL;\nstatic const char *progname = LUA_PROGNAME;\n\n#if !LJ_TARGET_CONSOLE\nstatic void lstop(lua_State *L, lua_Debug *ar)\n{\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);\n  /* Avoid luaL_error -- a C hook doesn't add an extra frame. */\n  luaL_where(L, 0);\n  lua_pushfstring(L, \"%sinterrupted!\", lua_tostring(L, -1));\n  lua_error(L);\n}\n\nstatic void laction(int i)\n{\n  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,\n\t\t\t terminate process (default action) */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n#endif\n\nstatic void print_usage(void)\n{\n  fputs(\"usage: \", stderr);\n  fputs(progname, stderr);\n  fputs(\" [options]... [script [args]...].\\n\"\n  \"Available options are:\\n\"\n  \"  -e chunk  Execute string \" LUA_QL(\"chunk\") \".\\n\"\n  \"  -l name   Require library \" LUA_QL(\"name\") \".\\n\"\n  \"  -b ...    Save or list bytecode.\\n\"\n  \"  -j cmd    Perform LuaJIT control command.\\n\"\n  \"  -O[opt]   Control LuaJIT optimizations.\\n\"\n  \"  -i        Enter interactive mode after executing \" LUA_QL(\"script\") \".\\n\"\n  \"  -v        Show version information.\\n\"\n  \"  -E        Ignore environment variables.\\n\"\n  \"  --        Stop handling options.\\n\"\n  \"  -         Execute stdin and stop handling options.\\n\", stderr);\n  fflush(stderr);\n}\n\nstatic void l_message(const char *pname, const char *msg)\n{\n  if (pname) { fputs(pname, stderr); fputc(':', stderr); fputc(' ', stderr); }\n  fputs(msg, stderr); fputc('\\n', stderr);\n  fflush(stderr);\n}\n\nstatic int report(lua_State *L, int status)\n{\n  if (status && !lua_isnil(L, -1)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg == NULL) msg = \"(error object is not a string)\";\n    l_message(progname, msg);\n    lua_pop(L, 1);\n  }\n  return status;\n}\n\nstatic int traceback(lua_State *L)\n{\n  if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */\n    if (lua_isnoneornil(L, 1) ||\n\t!luaL_callmeta(L, 1, \"__tostring\") ||\n\t!lua_isstring(L, -1))\n      return 1;  /* Return non-string error object. */\n    lua_remove(L, 1);  /* Replace object by result of __tostring metamethod. */\n  }\n  luaL_traceback(L, L, lua_tostring(L, 1), 1);\n  return 1;\n}\n\nstatic int docall(lua_State *L, int narg, int clear)\n{\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, traceback);  /* push traceback function */\n  lua_insert(L, base);  /* put it under chunk and args */\n#if !LJ_TARGET_CONSOLE\n  signal(SIGINT, laction);\n#endif\n  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n#if !LJ_TARGET_CONSOLE\n  signal(SIGINT, SIG_DFL);\n#endif\n  lua_remove(L, base);  /* remove traceback function */\n  /* force a complete garbage collection in case of errors */\n  if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);\n  return status;\n}\n\nstatic void print_version(void)\n{\n  fputs(LUAJIT_VERSION \" -- \" LUAJIT_COPYRIGHT \". \" LUAJIT_URL \"\\n\", stdout);\n}\n\nstatic void print_jit_status(lua_State *L)\n{\n  int n;\n  const char *s;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit\");  /* Get jit.* module table. */\n  lua_remove(L, -2);\n  lua_getfield(L, -1, \"status\");\n  lua_remove(L, -2);\n  n = lua_gettop(L);\n  lua_call(L, 0, LUA_MULTRET);\n  fputs(lua_toboolean(L, n) ? \"JIT: ON\" : \"JIT: OFF\", stdout);\n  for (n++; (s = lua_tostring(L, n)); n++) {\n    putc(' ', stdout);\n    fputs(s, stdout);\n  }\n  putc('\\n', stdout);\n}\n\nstatic int getargs(lua_State *L, char **argv, int n)\n{\n  int narg;\n  int i;\n  int argc = 0;\n  while (argv[argc]) argc++;  /* count total number of arguments */\n  narg = argc - (n + 1);  /* number of arguments to the script */\n  luaL_checkstack(L, narg + 3, \"too many arguments to script\");\n  for (i = n+1; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  lua_createtable(L, narg, n + 1);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - n);\n  }\n  return narg;\n}\n\nstatic int dofile(lua_State *L, const char *name)\n{\n  int status = luaL_loadfile(L, name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\nstatic int dostring(lua_State *L, const char *s, const char *name)\n{\n  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\nstatic int dolibrary(lua_State *L, const char *name)\n{\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  return report(L, docall(L, 1, 1));\n}\n\nstatic void write_prompt(lua_State *L, int firstline)\n{\n  const char *p;\n  lua_getfield(L, LUA_GLOBALSINDEX, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2;\n  fputs(p, stdout);\n  fflush(stdout);\n  lua_pop(L, 1);  /* remove global */\n}\n\nstatic int incomplete(lua_State *L, int status)\n{\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    const char *tp = msg + lmsg - (sizeof(LUA_QL(\"<eof>\")) - 1);\n    if (strstr(msg, LUA_QL(\"<eof>\")) == tp) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\nstatic int pushline(lua_State *L, int firstline)\n{\n  char buf[LUA_MAXINPUT];\n  write_prompt(L, firstline);\n  if (fgets(buf, LUA_MAXINPUT, stdin)) {\n    size_t len = strlen(buf);\n    if (len > 0 && buf[len-1] == '\\n')\n      buf[len-1] = '\\0';\n    if (firstline && buf[0] == '=')\n      lua_pushfstring(L, \"return %s\", buf+1);\n    else\n      lua_pushstring(L, buf);\n    return 1;\n  }\n  return 0;\n}\n\nstatic int loadline(lua_State *L)\n{\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  for (;;) {  /* repeat until gets a complete line */\n    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), \"=stdin\");\n    if (!incomplete(L, status)) break;  /* cannot try to add lines? */\n    if (!pushline(L, 0))  /* no more input? */\n      return -1;\n    lua_pushliteral(L, \"\\n\");  /* add a new line... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n  lua_remove(L, 1);  /* remove line */\n  return status;\n}\n\nstatic void dotty(lua_State *L)\n{\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;\n  while ((status = loadline(L)) != -1) {\n    if (status == 0) status = docall(L, 0, 0);\n    report(L, status);\n    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */\n      lua_getglobal(L, \"print\");\n      lua_insert(L, 1);\n      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)\n\tl_message(progname,\n\t  lua_pushfstring(L, \"error calling \" LUA_QL(\"print\") \" (%s)\",\n\t\t\t      lua_tostring(L, -1)));\n    }\n  }\n  lua_settop(L, 0);  /* clear stack */\n  fputs(\"\\n\", stdout);\n  fflush(stdout);\n  progname = oldprogname;\n}\n\nstatic int handle_script(lua_State *L, char **argv, int n)\n{\n  int status;\n  const char *fname;\n  int narg = getargs(L, argv, n);  /* collect arguments */\n  lua_setglobal(L, \"arg\");\n  fname = argv[n];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[n-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  lua_insert(L, -(narg+1));\n  if (status == 0)\n    status = docall(L, narg, 0);\n  else\n    lua_pop(L, narg);\n  return report(L, status);\n}\n\n/* Load add-on module. */\nstatic int loadjitmodule(lua_State *L)\n{\n  lua_getglobal(L, \"require\");\n  lua_pushliteral(L, \"jit.\");\n  lua_pushvalue(L, -3);\n  lua_concat(L, 2);\n  if (lua_pcall(L, 1, 1, 0)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg && !strncmp(msg, \"module \", 7))\n      goto nomodule;\n    return report(L, 1);\n  }\n  lua_getfield(L, -1, \"start\");\n  if (lua_isnil(L, -1)) {\n  nomodule:\n    l_message(progname,\n\t      \"unknown luaJIT command or jit.* modules not installed\");\n    return 1;\n  }\n  lua_remove(L, -2);  /* Drop module table. */\n  return 0;\n}\n\n/* Run command with options. */\nstatic int runcmdopt(lua_State *L, const char *opt)\n{\n  int narg = 0;\n  if (opt && *opt) {\n    for (;;) {  /* Split arguments. */\n      const char *p = strchr(opt, ',');\n      narg++;\n      if (!p) break;\n      if (p == opt)\n\tlua_pushnil(L);\n      else\n\tlua_pushlstring(L, opt, (size_t)(p - opt));\n      opt = p + 1;\n    }\n    if (*opt)\n      lua_pushstring(L, opt);\n    else\n      lua_pushnil(L);\n  }\n  return report(L, lua_pcall(L, narg, 0, 0));\n}\n\n/* JIT engine control command: try jit library first or load add-on module. */\nstatic int dojitcmd(lua_State *L, const char *cmd)\n{\n  const char *opt = strchr(cmd, '=');\n  lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd));\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit\");  /* Get jit.* module table. */\n  lua_remove(L, -2);\n  lua_pushvalue(L, -2);\n  lua_gettable(L, -2);  /* Lookup library function. */\n  if (!lua_isfunction(L, -1)) {\n    lua_pop(L, 2);  /* Drop non-function and jit.* table, keep module name. */\n    if (loadjitmodule(L))\n      return 1;\n  } else {\n    lua_remove(L, -2);  /* Drop jit.* table. */\n  }\n  lua_remove(L, -2);  /* Drop module name. */\n  return runcmdopt(L, opt ? opt+1 : opt);\n}\n\n/* Optimization flags. */\nstatic int dojitopt(lua_State *L, const char *opt)\n{\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit.opt\");  /* Get jit.opt.* module table. */\n  lua_remove(L, -2);\n  lua_getfield(L, -1, \"start\");\n  lua_remove(L, -2);\n  return runcmdopt(L, opt);\n}\n\n/* Save or list bytecode. */\nstatic int dobytecode(lua_State *L, char **argv)\n{\n  int narg = 0;\n  lua_pushliteral(L, \"bcsave\");\n  if (loadjitmodule(L))\n    return 1;\n  if (argv[0][2]) {\n    narg++;\n    argv[0][1] = '-';\n    lua_pushstring(L, argv[0]+1);\n  }\n  for (argv++; *argv != NULL; narg++, argv++)\n    lua_pushstring(L, *argv);\n  return report(L, lua_pcall(L, narg, 0, 0));\n}\n\n/* check that argument has no extra characters at the end */\n#define notail(x)\t{if ((x)[2] != '\\0') return -1;}\n\n#define FLAGS_INTERACTIVE\t1\n#define FLAGS_VERSION\t\t2\n#define FLAGS_EXEC\t\t4\n#define FLAGS_OPTION\t\t8\n#define FLAGS_NOENV\t\t16\n\nstatic int collectargs(char **argv, int *flags)\n{\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    if (argv[i][0] != '-')  /* Not an option? */\n      return i;\n    switch (argv[i][1]) {  /* Check option. */\n    case '-':\n      notail(argv[i]);\n      return (argv[i+1] != NULL ? i+1 : 0);\n    case '\\0':\n      return i;\n    case 'i':\n      notail(argv[i]);\n      *flags |= FLAGS_INTERACTIVE;\n      /* fallthrough */\n    case 'v':\n      notail(argv[i]);\n      *flags |= FLAGS_VERSION;\n      break;\n    case 'e':\n      *flags |= FLAGS_EXEC;\n    case 'j':  /* LuaJIT extension */\n    case 'l':\n      *flags |= FLAGS_OPTION;\n      if (argv[i][2] == '\\0') {\n\ti++;\n\tif (argv[i] == NULL) return -1;\n      }\n      break;\n    case 'O': break;  /* LuaJIT extension */\n    case 'b':  /* LuaJIT extension */\n      if (*flags) return -1;\n      *flags |= FLAGS_EXEC;\n      return 0;\n    case 'E':\n      *flags |= FLAGS_NOENV;\n      break;\n    default: return -1;  /* invalid option */\n    }\n  }\n  return 0;\n}\n\nstatic int runargs(lua_State *L, char **argv, int n)\n{\n  int i;\n  for (i = 1; i < n; i++) {\n    if (argv[i] == NULL) continue;\n    lua_assert(argv[i][0] == '-');\n    switch (argv[i][1]) {  /* option */\n    case 'e': {\n      const char *chunk = argv[i] + 2;\n      if (*chunk == '\\0') chunk = argv[++i];\n      lua_assert(chunk != NULL);\n      if (dostring(L, chunk, \"=(command line)\") != 0)\n\treturn 1;\n      break;\n      }\n    case 'l': {\n      const char *filename = argv[i] + 2;\n      if (*filename == '\\0') filename = argv[++i];\n      lua_assert(filename != NULL);\n      if (dolibrary(L, filename))\n\treturn 1;  /* stop if file fails */\n      break;\n      }\n    case 'j': {  /* LuaJIT extension */\n      const char *cmd = argv[i] + 2;\n      if (*cmd == '\\0') cmd = argv[++i];\n      lua_assert(cmd != NULL);\n      if (dojitcmd(L, cmd))\n\treturn 1;\n      break;\n      }\n    case 'O':  /* LuaJIT extension */\n      if (dojitopt(L, argv[i] + 2))\n\treturn 1;\n      break;\n    case 'b':  /* LuaJIT extension */\n      return dobytecode(L, argv+i);\n    default: break;\n    }\n  }\n  return 0;\n}\n\nstatic int handle_luainit(lua_State *L)\n{\n#if LJ_TARGET_CONSOLE\n  const char *init = NULL;\n#else\n  const char *init = getenv(LUA_INIT);\n#endif\n  if (init == NULL)\n    return 0;  /* status OK */\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, \"=\" LUA_INIT);\n}\n\nstatic struct Smain {\n  char **argv;\n  int argc;\n  int status;\n} smain;\n\nstatic int pmain(lua_State *L)\n{\n  struct Smain *s = &smain;\n  char **argv = s->argv;\n  int script;\n  int flags = 0;\n  globalL = L;\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  LUAJIT_VERSION_SYM();  /* linker-enforced version check */\n  script = collectargs(argv, &flags);\n  if (script < 0) {  /* invalid args? */\n    print_usage();\n    s->status = 1;\n    return 0;\n  }\n  if ((flags & FLAGS_NOENV)) {\n    lua_pushboolean(L, 1);\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */\n  luaL_openlibs(L);  /* open libraries */\n  lua_gc(L, LUA_GCRESTART, -1);\n  if (!(flags & FLAGS_NOENV)) {\n    s->status = handle_luainit(L);\n    if (s->status != 0) return 0;\n  }\n  if ((flags & FLAGS_VERSION)) print_version();\n  s->status = runargs(L, argv, (script > 0) ? script : s->argc);\n  if (s->status != 0) return 0;\n  if (script) {\n    s->status = handle_script(L, argv, script);\n    if (s->status != 0) return 0;\n  }\n  if ((flags & FLAGS_INTERACTIVE)) {\n    print_jit_status(L);\n    dotty(L);\n  } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {\n    if (lua_stdin_is_tty()) {\n      print_version();\n      print_jit_status(L);\n      dotty(L);\n    } else {\n      dofile(L, NULL);  /* executes stdin as a file */\n    }\n  }\n  return 0;\n}\n\nint main(int argc, char **argv)\n{\n  int status;\n  lua_State *L = lua_open();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  smain.argc = argc;\n  smain.argv = argv;\n  status = lua_cpcall(L, pmain, NULL);\n  report(L, status);\n  lua_close(L);\n  return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/luajit.h",
    "content": "/*\n** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/\n**\n** Copyright (C) 2005-2016 Mike Pall. All rights reserved.\n**\n** Permission is hereby granted, free of charge, to any person obtaining\n** a copy of this software and associated documentation files (the\n** \"Software\"), to deal in the Software without restriction, including\n** without limitation the rights to use, copy, modify, merge, publish,\n** distribute, sublicense, and/or sell copies of the Software, and to\n** permit persons to whom the Software is furnished to do so, subject to\n** the following conditions:\n**\n** The above copyright notice and this permission notice shall be\n** included in all copies or substantial portions of the Software.\n**\n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n**\n** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]\n*/\n\n#ifndef _LUAJIT_H\n#define _LUAJIT_H\n\n#include \"lua.h\"\n\n#define LUAJIT_VERSION\t\t\"LuaJIT 2.1.0-beta2\"\n#define LUAJIT_VERSION_NUM\t20100  /* Version 2.1.0 = 02.01.00. */\n#define LUAJIT_VERSION_SYM\tluaJIT_version_2_1_0_beta2\n#define LUAJIT_COPYRIGHT\t\"Copyright (C) 2005-2016 Mike Pall\"\n#define LUAJIT_URL\t\t\"http://luajit.org/\"\n\n/* Modes for luaJIT_setmode. */\n#define LUAJIT_MODE_MASK\t0x00ff\n\nenum {\n  LUAJIT_MODE_ENGINE,\t\t/* Set mode for whole JIT engine. */\n  LUAJIT_MODE_DEBUG,\t\t/* Set debug mode (idx = level). */\n\n  LUAJIT_MODE_FUNC,\t\t/* Change mode for a function. */\n  LUAJIT_MODE_ALLFUNC,\t\t/* Recurse into subroutine protos. */\n  LUAJIT_MODE_ALLSUBFUNC,\t/* Change only the subroutines. */\n\n  LUAJIT_MODE_TRACE,\t\t/* Flush a compiled trace. */\n\n  LUAJIT_MODE_WRAPCFUNC = 0x10,\t/* Set wrapper mode for C function calls. */\n\n  LUAJIT_MODE_MAX\n};\n\n/* Flags or'ed in to the mode. */\n#define LUAJIT_MODE_OFF\t\t0x0000\t/* Turn feature off. */\n#define LUAJIT_MODE_ON\t\t0x0100\t/* Turn feature on. */\n#define LUAJIT_MODE_FLUSH\t0x0200\t/* Flush JIT-compiled code. */\n\n/* LuaJIT public C API. */\n\n/* Control the JIT engine. */\nLUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);\n\n/* Low-overhead profiling API. */\ntypedef void (*luaJIT_profile_callback)(void *data, lua_State *L,\n\t\t\t\t\tint samples, int vmstate);\nLUA_API void luaJIT_profile_start(lua_State *L, const char *mode,\n\t\t\t\t  luaJIT_profile_callback cb, void *data);\nLUA_API void luaJIT_profile_stop(lua_State *L);\nLUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt,\n\t\t\t\t\t     int depth, size_t *len);\n\n/* Enforce (dynamic) linker error for version mismatches. Call from main. */\nLUA_API void LUAJIT_VERSION_SYM(void);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/lualib.h",
    "content": "/*\n** Standard library header.\n** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LUALIB_H\n#define _LUALIB_H\n\n#include \"lua.h\"\n\n#define LUA_FILEHANDLE\t\"FILE*\"\n\n#define LUA_COLIBNAME\t\"coroutine\"\n#define LUA_MATHLIBNAME\t\"math\"\n#define LUA_STRLIBNAME\t\"string\"\n#define LUA_TABLIBNAME\t\"table\"\n#define LUA_IOLIBNAME\t\"io\"\n#define LUA_OSLIBNAME\t\"os\"\n#define LUA_LOADLIBNAME\t\"package\"\n#define LUA_DBLIBNAME\t\"debug\"\n#define LUA_BITLIBNAME\t\"bit\"\n#define LUA_JITLIBNAME\t\"jit\"\n#define LUA_FFILIBNAME\t\"ffi\"\n\nLUALIB_API int luaopen_base(lua_State *L);\nLUALIB_API int luaopen_math(lua_State *L);\nLUALIB_API int luaopen_string(lua_State *L);\nLUALIB_API int luaopen_table(lua_State *L);\nLUALIB_API int luaopen_io(lua_State *L);\nLUALIB_API int luaopen_os(lua_State *L);\nLUALIB_API int luaopen_package(lua_State *L);\nLUALIB_API int luaopen_debug(lua_State *L);\nLUALIB_API int luaopen_bit(lua_State *L);\nLUALIB_API int luaopen_jit(lua_State *L);\nLUALIB_API int luaopen_ffi(lua_State *L);\n\nLUALIB_API void luaL_openlibs(lua_State *L);\n\n#ifndef lua_assert\n#define lua_assert(x)\t((void)0)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/msvcbuild.bat",
    "content": "@rem Script to build LuaJIT with MSVC.\n@rem Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n@rem\n@rem Either open a \"Visual Studio .NET Command Prompt\"\n@rem (Note that the Express Edition does not contain an x64 compiler)\n@rem -or-\n@rem Open a \"Windows SDK Command Shell\" and set the compiler environment:\n@rem     setenv /release /x86\n@rem   -or-\n@rem     setenv /release /x64\n@rem\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n\n@setlocal\n@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set LJLIB=lib /nologo /nodefaultlib\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set LJDLLNAME=lua51.dll\n@set LJLIBNAME=lua51.lib\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64\n@set LJARCH=x64\n@minilua\n@if errorlevel 8 goto :X64\n@set DASMFLAGS=-D WIN -D JIT -D FFI\n@set LJARCH=x86\n@set LJCOMPILE=%LJCOMPILE% /arch:SSE2\n:X64\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_x86.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m peobj -o lj_vm.obj\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set LJCOMPILE=%LJCOMPILE% /Zi\n@set LJLINK=%LJLINK% /debug\n:NODEBUG\n@if \"%1\"==\"amalg\" goto :AMALGDLL\n@if \"%1\"==\"static\" goto :STATIC\n%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:STATIC\n%LJCOMPILE% lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:AMALGDLL\n%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj\n@if errorlevel 1 goto :BAD\n:MTDLL\nif exist %LJDLLNAME%.manifest^\n  %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2\n\n%LJCOMPILE% luajit.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%\n@if errorlevel 1 goto :BAD\nif exist luajit.exe.manifest^\n  %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe\n\n@del *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for Windows/%LJARCH% ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo You must open a \"Visual Studio .NET Command Prompt\" to run this script\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/msvcbuild_mt.bat",
    "content": "@rem Script to build LuaJIT with MSVC.\n@rem Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n@rem\n@rem Either open a \"Visual Studio .NET Command Prompt\"\n@rem (Note that the Express Edition does not contain an x64 compiler)\n@rem -or-\n@rem Open a \"Windows SDK Command Shell\" and set the compiler environment:\n@rem     setenv /release /x86\n@rem   -or-\n@rem     setenv /release /x64\n@rem\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n\n@setlocal\n@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set LJLIB=lib /nologo /nodefaultlib\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set LJDLLNAME=lua51.dll\n@set LJLIBNAME=lua51.lib\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64\n@set LJARCH=x64\n@minilua\n@if errorlevel 8 goto :X64\n@set DASMFLAGS=-D WIN -D JIT -D FFI\n@set LJARCH=x86\n@set LJCOMPILE=%LJCOMPILE% /arch:SSE2\n:X64\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_x86.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m peobj -o lj_vm.obj\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set LJCOMPILE=%LJCOMPILE% /Zi\n@set LJLINK=%LJLINK% /debug\n:NODEBUG\n@if \"%1\"==\"amalg\" goto :AMALGDLL\n@if \"%1\"==\"static\" goto :STATIC\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:STATIC\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:AMALGDLL\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj\n@if errorlevel 1 goto :BAD\n:MTDLL\nif exist %LJDLLNAME%.manifest^\n  %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2\n\n%LJCOMPILE% luajit.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%\n@if errorlevel 1 goto :BAD\nif exist luajit.exe.manifest^\n  %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe\n\n@del *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for Windows/%LJARCH% ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo You must open a \"Visual Studio .NET Command Prompt\" to run this script\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/msvcbuild_xlua.bat",
    "content": "@rem Script to build LuaJIT with MSVC.\n@rem Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n@rem\n@rem Either open a \"Visual Studio .NET Command Prompt\"\n@rem (Note that the Express Edition does not contain an x64 compiler)\n@rem -or-\n@rem Open a \"Windows SDK Command Shell\" and set the compiler environment:\n@rem     setenv /release /x86\n@rem   -or-\n@rem     setenv /release /x64\n@rem\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n\n@setlocal\n@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set LJLIB=lib /nologo /nodefaultlib\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set LJDLLNAME=lua51.dll\n@set LJLIBNAME=lua51.lib\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64\n@set LJARCH=x64\n@minilua\n@if errorlevel 8 goto :X64\n@set DASMFLAGS=-D WIN -D JIT -D FFI\n@set LJARCH=x86\n@set LJCOMPILE=%LJCOMPILE% /arch:SSE2\n:X64\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_x86.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m peobj -o lj_vm.obj\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set LJCOMPILE=%LJCOMPILE% /Zi\n@set LJLINK=%LJLINK% /debug\n:NODEBUG\n@if \"%1\"==\"amalg\" goto :AMALGDLL\n@if \"%1\"==\"static\" goto :STATIC\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL /I. /I..\\.. /I..\\..\\tdrlua lj_*.c lib_*.c ..\\..\\xlua.c ..\\..\\i64lib.c ..\\..\\perflib.c \n%LJCOMPILE% /MT /DLUA_LIB /DLUA_BUILD_AS_DLL /I..\\..\\luasocket\\ /I. /I..\\..  ..\\..\\luasocket\\auxiliar.c ..\\..\\luasocket\\buffer.c ..\\..\\luasocket\\except.c ..\\..\\luasocket\\inet.c ..\\..\\luasocket\\io.c ..\\..\\luasocket\\luasocket.c ..\\..\\luasocket\\mime.c ..\\..\\luasocket\\options.c ..\\..\\luasocket\\select.c ..\\..\\luasocket\\tcp.c ..\\..\\luasocket\\timeout.c ..\\..\\luasocket\\udp.c ..\\..\\luasocket\\wsocket.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj xlua.obj i64lib.obj perflib.obj auxiliar.obj buffer.obj except.obj inet.obj io.obj luasocket.obj mime.obj options.obj select.obj tcp.obj timeout.obj udp.obj wsocket.obj ws2_32.lib\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:STATIC\n%LJCOMPILE% lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :MTDLL\n:AMALGDLL\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj\n@if errorlevel 1 goto :BAD\n:MTDLL\nif exist %LJDLLNAME%.manifest^\n  %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2\n\n%LJCOMPILE% luajit.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%\n@if errorlevel 1 goto :BAD\nif exist luajit.exe.manifest^\n  %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe\n\n@del *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for Windows/%LJARCH% ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo You must open a \"Visual Studio .NET Command Prompt\" to run this script\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/ps4build.bat",
    "content": "@rem Script to build LuaJIT with the PS4 SDK.\n@rem Donated to the public domain.\n@rem\n@rem Open a \"Visual Studio .NET Command Prompt\" (64 bit host compiler)\n@rem or \"VS2015 x64 Native Tools Command Prompt\".\n@rem\n@rem Then cd to this directory and run this script.\n@rem\n@rem Recommended invocation:\n@rem\n@rem ps4build        release build, amalgamated, 64-bit GC\n@rem ps4build debug    debug build, amalgamated, 64-bit GC\n@rem\n@rem Additional command-line options (not generally recommended):\n@rem\n@rem gc32 (before debug)    32-bit GC\n@rem noamalg (after debug)  non-amalgamated build\n\n@if not defined INCLUDE goto :FAIL\n@if not defined SCE_ORBIS_SDK_DIR goto :FAIL\n\n@setlocal\n@rem ---- Host compiler ----\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n@set GC64=-DLUAJIT_ENABLE_GC64\n@set DASC=vm_x64.dasc\n\n@if \"%1\" neq \"gc32\" goto :NOGC32\n@shift\n@set GC64=\n@set DASC=vm_x86.dasc\n:NOGC32\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@rem Check for 64 bit host compiler.\n@minilua\n@if not errorlevel 8 goto :FAIL\n\n@set DASMFLAGS=-D P64 -D NO_UNWIND\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h %DASC%\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% %GC64% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m elfasm -o lj_vm.s\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@rem ---- Cross compiler ----\n@set LJCOMPILE=\"%SCE_ORBIS_SDK_DIR%\\host_tools\\bin\\orbis-clang\" -c -Wall -DLUAJIT_DISABLE_FFI %GC64%\n@set LJLIB=\"%SCE_ORBIS_SDK_DIR%\\host_tools\\bin\\orbis-ar\" rcus\n@set INCLUDE=\"\"\n\norbis-as -o lj_vm.o lj_vm.s\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set LJCOMPILE=%LJCOMPILE% -g -O0\n@set TARGETLIB=libluajitD_ps4.a\ngoto :BUILD\n:NODEBUG\n@set LJCOMPILE=%LJCOMPILE% -O2\n@set TARGETLIB=libluajit_ps4.a\n:BUILD\ndel %TARGETLIB%\n@if \"%1\" neq \"noamalg\" goto :AMALG\nfor %%f in (lj_*.c lib_*.c) do (\n  %LJCOMPILE% %%f\n  @if errorlevel 1 goto :BAD\n)\n\n%LJLIB% %TARGETLIB% lj_*.o lib_*.o\n@if errorlevel 1 goto :BAD\n@goto :NOAMALG\n:AMALG\n%LJCOMPILE% ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o\n@if errorlevel 1 goto :BAD\n:NOAMALG\n\n@del *.o *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for PS4 ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\n@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too.\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/psvitabuild.bat",
    "content": "@rem Script to build LuaJIT with the PS Vita SDK.\n@rem Donated to the public domain.\n@rem\n@rem Open a \"Visual Studio .NET Command Prompt\" (32 bit host compiler)\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n@if not defined SCE_PSP2_SDK_DIR goto :FAIL\n\n@setlocal\n@rem ---- Host compiler ----\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@rem Check for 32 bit host compiler.\n@minilua\n@if errorlevel 8 goto :FAIL\n\n@set DASMFLAGS=-D FPU -D HFABI\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_arm.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLJ_TARGET_PSVITA=1 host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m elfasm -o lj_vm.s\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@rem ---- Cross compiler ----\n@set LJCOMPILE=\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2snc\" -c -w -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC\n@set LJLIB=\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2ld32\" -r --output=\n@set INCLUDE=\"\"\n\n\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2as\" -o lj_vm.o lj_vm.s\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set LJCOMPILE=%LJCOMPILE% -g -O0\n@set TARGETLIB=libluajitD.a\ngoto :BUILD\n:NODEBUG\n@set LJCOMPILE=%LJCOMPILE% -O2\n@set TARGETLIB=libluajit.a\n:BUILD\ndel %TARGETLIB%\n\n%LJCOMPILE% ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLIB%%TARGETLIB% ljamalg.o lj_vm.o\n@if errorlevel 1 goto :BAD\n\n@del *.o *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for PS Vita ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\n@echo (32 bit host compiler). The PS Vita SDK must be installed, too.\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_arm.dasc",
    "content": "|// Low-level VM code for ARM CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch arm\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|\n|// The following must be C callee-save.\n|.define MASKR8,\tr4\t// 255*8 constant for fast bytecode decoding.\n|.define KBASE,\t\tr5\t// Constants of current Lua function.\n|.define PC,\t\tr6\t// Next PC.\n|.define DISPATCH,\tr7\t// Opcode dispatch table.\n|.define LREG,\t\tr8\t// Register holding lua_State (also in SAVE_L).\n|\n|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.\n|.define BASE,\t\tr9\t// Base of current Lua stack frame.\n|\n|// The following temporaries are not saved across C calls, except for RA/RC.\n|.define RA,\t\tr10\t// Callee-save.\n|.define RC,\t\tr11\t// Callee-save.\n|.define RB,\t\tr12\n|.define OP,\t\tr12\t// Overlaps RB, must not be lr.\n|.define INS,\t\tlr\n|\n|// Calling conventions. Also used as temporaries.\n|.define CARG1,\t\tr0\n|.define CARG2,\t\tr1\n|.define CARG3,\t\tr2\n|.define CARG4,\t\tr3\n|.define CARG12,\tr0\t// For 1st soft-fp double.\n|.define CARG34,\tr2\t// For 2nd soft-fp double.\n|\n|.define CRET1,\t\tr0\n|.define CRET2,\t\tr1\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.define SAVE_R4,\t[sp, #28]\n|.define CFRAME_SPACE,\t#28\n|.define SAVE_ERRF,\t[sp, #24]\n|.define SAVE_NRES,\t[sp, #20]\n|.define SAVE_CFRAME,\t[sp, #16]\n|.define SAVE_L,\t[sp, #12]\n|.define SAVE_PC,\t[sp, #8]\n|.define SAVE_MULTRES,\t[sp, #4]\n|.define ARG5,\t\t[sp]\n|\n|.define TMPDhi,\t[sp, #4]\n|.define TMPDlo,\t[sp]\n|.define TMPD,\t\t[sp]\n|.define TMPDp,\t\tsp\n|\n|.if FPU\n|.macro saveregs\n|  push {r5, r6, r7, r8, r9, r10, r11, lr}\n|  vpush {d8-d15}\n|  sub sp, sp, CFRAME_SPACE+4\n|  str r4, SAVE_R4\n|.endmacro\n|.macro restoreregs_ret\n|  ldr r4, SAVE_R4\n|  add sp, sp, CFRAME_SPACE+4\n|  vpop {d8-d15}\n|  pop {r5, r6, r7, r8, r9, r10, r11, pc}\n|.endmacro\n|.else\n|.macro saveregs\n|  push {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n|  sub sp, sp, CFRAME_SPACE\n|.endmacro\n|.macro restoreregs_ret\n|  add sp, sp, CFRAME_SPACE\n|  pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}\n|.endmacro\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; ud; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_FUNC,\t#-8\n|.define FRAME_PC,\t#-4\n|\n|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro\n|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro\n|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro\n|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro\n|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  ldrb OP, [PC]\n|.endmacro\n|.macro ins_NEXT2\n|   ldr INS, [PC], #4\n|.endmacro\n|// Instruction decode+dispatch.\n|.macro ins_NEXT3\n|  ldr OP, [DISPATCH, OP, lsl #2]\n|   decode_RA8 RA, INS\n|   decode_RD RC, INS\n|  bx OP\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|  ins_NEXT3\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|  .define ins_next3, ins_NEXT3\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|  .endmacro\n|  .macro ins_next3\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Avoid register name substitution for field name.\n#define field_pc\tpc\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  ldr PC, LFUNC:CARG3->field_pc\n|  ldrb OP, [PC]  // STALL: load PC. early PC.\n|   ldr INS, [PC], #4\n|  ldr OP, [DISPATCH, OP, lsl #2]  // STALL: load OP. early OP.\n|   decode_RA8 RA, INS\n|   add RA, RA, BASE\n|  bx OP\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  str PC, [BASE, FRAME_PC]\n|  ins_callt  // STALL: locked PC.\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro\n|.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro\n|.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta\n|  lsr CARG1, PC, #1\n|  and CARG1, CARG1, #126\n|  sub CARG1, CARG1, #-GG_DISP2HOT\n|  ldrh CARG2, [DISPATCH, CARG1]\n|  subs CARG2, CARG2, #delta\n|  strh CARG2, [DISPATCH, CARG1]\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP\n|  blo ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL\n|  blo ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro\n|.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)]\n|   bic mark, mark, #LJ_GC_BLACK\t\t// black2gray(tab)\n|  str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)]\n|   strb mark, tab->marked\n|  str tmp, tab->gclist\n|.endmacro\n|\n|.macro .IOS, a, b\n|.if IOS\n|  a, b\n|.endif\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n#if !LJ_DUALNUM\n#error \"Only dual-number mode supported for ARM target\"\n#endif\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: RB = previous base.\n  |  tst PC, #FRAME_P\n  |  beq ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  ldr PC, [RB, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   mvn CARG2, #~LJ_TTRUE\n  |  mov BASE, RB\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   str CARG2, [RA, FRAME_PC]\t\t// Prepend true to results.\n  |  sub RA, RA, #8\n  |\n  |->vm_returnc:\n  |  adds RC, RC, #8\t\t\t// RC = (nresults+1)*8.\n  |  mov CRET1, #LUA_YIELD\n  |  beq ->vm_unwind_c_eh\n  |  str RC, SAVE_MULTRES\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return\n  |  // CARG1 = PC & FRAME_TYPE\n  |  bic RB, PC, #FRAME_TYPEP\n  |   cmp CARG1, #FRAME_C\n  |  sub RB, BASE, RB\t\t\t// RB = previous base.\n  |   bne ->vm_returnp\n  |\n  |  str RB, L->base\n  |   ldr KBASE, SAVE_NRES\n  |    mv_vmstate CARG4, C\n  |   sub BASE, BASE, #8\n  |  subs CARG3, RC, #8\n  |   lsl KBASE, KBASE, #3\t\t// KBASE = (nresults_wanted+1)*8\n  |    st_vmstate CARG4\n  |  beq >2\n  |1:\n  |  subs CARG3, CARG3, #8\n  |   ldrd CARG12, [RA], #8\n  |   strd CARG12, [BASE], #8\n  |  bne <1\n  |2:\n  |  cmp KBASE, RC\t\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  str BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  ldr RC, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   mov CRET1, #0\t\t\t// Ok return status for vm_pcall.\n  |  str RC, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs_ret\n  |\n  |6:\n  |  blt >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  ldr CARG3, L->maxstack\n  |   mvn CARG2, #~LJ_TNIL\n  |  cmp BASE, CARG3\n  |  bhs >8\n  |   str CARG2, [BASE, #4]\n  |  add RC, RC, #8\n  |  add BASE, BASE, #8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  sub CARG1, RC, KBASE\n  |  cmp KBASE, #0\t\t\t// LUA_MULTRET+1 case?\n  |  subne BASE, BASE, CARG1\t\t// Either keep top or shrink it.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  str BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |  lsr CARG2, KBASE, #3\n  |  mov CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov sp, CARG1\n  |  mov CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mv_vmstate CARG4, C\n  |  ldr GL:CARG3, L->glref\n  |   str CARG4, GL:CARG3->vmstate\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  bic CARG1, CARG1, #~CFRAME_RAWMASK\t// Use two steps: bic sp is deprecated.\n  |  mov sp, CARG1\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mov MASKR8, #255\n  |    mov RC, #16\t\t\t// 2 results: false + error message.\n  |   lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |  ldr BASE, L->base\n  |   ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |    mvn CARG1, #~LJ_TFALSE\n  |  sub RA, BASE, #8\t\t\t// Results start at BASE-8.\n  |  ldr PC, [BASE, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   add DISPATCH, DISPATCH, #GG_G2DISP\n  |   mv_vmstate CARG2, INTERP\n  |    str CARG1, [BASE, #-4]\t\t// Prepend false to error message.\n  |   st_vmstate CARG2\n  |  b ->vm_returnc\n  |\n  |->vm_unwind_ext:\t\t\t// Complete external unwind.\n#if !LJ_NO_UNWIND\n  |  push {r0, r1, r2, lr}\n  |  bl extern _Unwind_Complete\n  |  ldr r0, [sp]\n  |  bl extern _Unwind_DeleteException\n  |  pop {r0, r1, r2, lr}\n  |  mov r0, r1\n  |  bx r2\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  // CARG1 = L\n  |  mov CARG2, #LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |    mov CARG1, L\n  |  str BASE, L->base\n  |   add PC, PC, #4\t\t\t// Must point after first instruction.\n  |  str RC, L->top\n  |   lsr CARG2, RA, #3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  str PC, SAVE_PC\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |   ldr RC, L->top\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L, CARG1\n  |    ldr DISPATCH, L:CARG1->glref\t// Setup pointer to dispatch table.\n  |  mov BASE, CARG2\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |   str L, SAVE_L\n  |  mov PC, #FRAME_CP\n  |   str CARG3, SAVE_NRES\n  |    add CARG2, sp, #CFRAME_RESUME\n  |  ldrb CARG1, L->status\n  |   str CARG3, SAVE_ERRF\n  |   str L, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   str CARG3, SAVE_CFRAME\n  |  cmp CARG1, #0\n  |    str CARG2, L->cframe\n  |  beq >3\n  |\n  |  // Resume after yield (like a return).\n  |  str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  mov RA, BASE\n  |   ldr BASE, L->base\n  |   ldr CARG1, L->top\n  |    mov MASKR8, #255\n  |     strb CARG3, L->status\n  |   sub RC, CARG1, BASE\n  |  ldr PC, [BASE, FRAME_PC]\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |     mv_vmstate CARG2, INTERP\n  |   add RC, RC, #8\n  |  ands CARG1, PC, #FRAME_TYPE\n  |     st_vmstate CARG2\n  |   str RC, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, #FRAME_CP\n  |  str CARG4, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, #FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  ldr RC, L:CARG1->cframe\n  |   str CARG3, SAVE_NRES\n  |    mov L, CARG1\n  |   str CARG1, SAVE_L\n  |    ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     mov BASE, CARG2\n  |   str CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  str RC, SAVE_CFRAME\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |  str sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  ldr RB, L->base\t\t\t// RB = old base (for vmeta_call).\n  |   ldr CARG1, L->top\n  |    mov MASKR8, #255\n  |  add PC, PC, BASE\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |  sub PC, PC, RB\t\t\t// PC = frame delta + frame type\n  |    mv_vmstate CARG2, INTERP\n  |   sub NARGS8:RC, CARG1, BASE\n  |    st_vmstate CARG2\n  |\n  |->vm_call_dispatch:\n  |  // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  ldrd CARG34, [BASE, FRAME_FUNC]\n  |  checkfunc CARG4, ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L, CARG1\n  |   ldr RA, L:CARG1->stack\n  |  str CARG1, SAVE_L\n  |    ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   ldr RB, L->top\n  |  str CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  ldr RC, L->cframe\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |   sub RA, RA, RB\t\t\t// Compute -savestack(L, L->top).\n  |  mov RB, #0\n  |   str RA, SAVE_NRES\t\t\t// Neg. delta means cframe w/o frame.\n  |  str RB, SAVE_ERRF\t\t\t// No error function.\n  |  str RC, SAVE_CFRAME\n  |  str sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  blx CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  movs BASE, CRET1\n  |   mov PC, #FRAME_CP\n  |  bne <3\t\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RC = (nresults+1)*8\n  |  ldr LFUNC:CARG3, [RB, FRAME_FUNC]\n  |    ldr CARG1, [BASE, #-16]\t\t// Get continuation.\n  |   mov CARG4, BASE\n  |   mov BASE, RB\t\t\t// Restore caller BASE.\n  |.if FFI\n  |    cmp CARG1, #1\n  |.endif\n  |   ldr PC, [CARG4, #-12]\t\t// Restore PC from [cont|PC].\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |    mvn INS, #~LJ_TNIL\n  |    add CARG2, RA, RC\n  |    str INS, [CARG2, #-4]\t\t// Ensure one valid arg.\n  |.if FFI\n  |    bls >1\n  |.endif\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  // BASE = base, RA = resultptr, CARG4 = meta base\n  |    bx CARG1\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |  sub CARG4, CARG4, #16\n  |  sub RC, CARG4, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, CARG4 = meta base\n  |  ldr INS, [PC, #-4]\n  |   sub CARG2, CARG4, #16\n  |   ldrd CARG34, [RA]\n  |     str BASE, L->base\n  |  decode_RB8 RC, INS\n  |   decode_RA8 RA, INS\n  |  add CARG1, BASE, RC\n  |  subs CARG1, CARG2, CARG1\n  |   strdne CARG34, [CARG2]\n  |   movne CARG3, CARG1\n  |  bne ->BC_CAT_Z\n  |   strd CARG34, [BASE, RA]\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  add CARG2, BASE, RB\n  |  b >2\n  |\n  |->vmeta_tgets:\n  |  sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)\n  |   mvn CARG4, #~LJ_TTAB\n  |  str TAB:RB, [CARG2]\n  |   str CARG4, [CARG2, #4]\n  |2:\n  |   mvn CARG4, #~LJ_TSTR\n  |  str STR:RC, TMPDlo\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// RC = index\n  |  decode_RB8 RB, INS\n  |   str RC, TMPDlo\n  |   mvn CARG4, #~LJ_TISNUM\n  |  add CARG2, BASE, RB\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tgetv:\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |  beq >3\n  |  ldrd CARG34, [CRET1]\n  |   ins_next1\n  |   ins_next2\n  |  strd CARG34, [BASE, RA]\n  |   ins_next3\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |   rsb CARG1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(t, k).\n  |    str PC, [BASE, #-12]\t\t// [cont|PC]\n  |   add PC, CARG1, BASE\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  .IOS mov RC, BASE\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  .IOS mov BASE, RC\n  |  cmp CRET1, #0\n  |  ldrdne CARG12, [CRET1]\n  |  mvneq CARG2, #~LJ_TNIL\n  |  b ->BC_TGETR_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  add CARG2, BASE, RB\n  |  b >2\n  |\n  |->vmeta_tsets:\n  |  sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)\n  |   mvn CARG4, #~LJ_TTAB\n  |  str TAB:RB, [CARG2]\n  |   str CARG4, [CARG2, #4]\n  |2:\n  |   mvn CARG4, #~LJ_TSTR\n  |  str STR:RC, TMPDlo\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// RC = index\n  |  decode_RB8 RB, INS\n  |   str RC, TMPDlo\n  |   mvn CARG4, #~LJ_TISNUM\n  |  add CARG2, BASE, RB\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |   ldrd CARG34, [BASE, RA]\n  |  beq >3\n  |   ins_next1\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  strd CARG34, [CRET1]\n  |   ins_next2\n  |   ins_next3\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |   rsb CARG1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #24\t\t// 3 args for func(t, k, v).\n  |   strd CARG34, [BASE, #16]\t\t// Copy value to third argument.\n  |    str PC, [BASE, #-12]\t\t// [cont|PC]\n  |   add PC, CARG1, BASE\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  str BASE, L->base\n  |  .IOS mov RC, BASE\n  |  str PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |  .IOS mov BASE, RC\n  |  b ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  mov CARG1, L\n  |   sub PC, PC, #4\n  |  mov CARG2, RA\n  |   str BASE, L->base\n  |  mov CARG3, RC\n  |   str PC, SAVE_PC\n  |  decode_OP CARG4, INS\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #1\n  |  bhi ->vmeta_binop\n  |4:\n  |  ldrh RB, [PC, #2]\n  |   add PC, PC, #4\n  |  add RB, PC, RB, lsl #2\n  |  subhs PC, RB, #0x20000\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  ldr INS, [PC, #-4]\n  |   ldrd CARG12, [RA]\n  |  decode_RA8 CARG3, INS\n  |   strd CARG12, [BASE, CARG3]\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  ldr CARG2, [RA, #4]\n  |   mvn CARG1, #~LJ_TTRUE\n  |  cmp CARG1, CARG2\t\t\t// Branch if result is true.\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  ldr CARG2, [RA, #4]\n  |  checktp CARG2, LJ_TFALSE\t\t// Branch if result is false.\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, INS\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   lsr CARG2, RA, #3\n  |   mov CARG3, RC\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  .IOS ldr BASE, L->base\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vn:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG3, BASE, RB\n  |   add CARG4, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_nv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG4, BASE, RB\n  |   add CARG3, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_unm:\n  |  ldr INS, [PC, #-8]\n  |   sub PC, PC, #4\n  |  add CARG3, BASE, RC\n  |  add CARG4, BASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG3, BASE, RB\n  |   add CARG4, BASE, RC\n  |1:\n  |  decode_OP OP, INS\n  |   add CARG2, BASE, RA\n  |    str BASE, L->base\n  |   mov CARG1, L\n  |    str PC, SAVE_PC\n  |  str OP, ARG5\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |  beq ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub CARG2, CRET1, BASE\n  |   str PC, [CRET1, #-12]\t\t// [cont|PC]\n  |  add PC, CARG2, #FRAME_CONT\n  |   mov BASE, CRET1\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  add CARG2, BASE, RC\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n  |  .IOS ldr BASE, L->base\n#if LJ_52\n  |  cmp CRET1, #0\n  |  bne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  ldr TAB:CARG1, [BASE, RC]\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // RB = old base, BASE = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str RB, L->base\t\t\t// This is the callers base!\n  |  sub CARG2, BASE, #8\n  |   str PC, SAVE_PC\n  |  add CARG3, BASE, NARGS8:RC\n  |  .IOS mov RA, BASE\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  .IOS mov BASE, RA\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  sub CARG2, RA, #8\n  |   str PC, SAVE_PC\n  |  add CARG3, RA, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  .IOS ldr BASE, L->base\n  |  ldr LFUNC:CARG3, [RA, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   ldr PC, [BASE, FRAME_PC]\n  |    add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  b ->BC_CALLT2_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, RA\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  .IOS ldr BASE, L->base\n  |.if JIT\n  |   ldrb OP, [PC, #-4]\n  |.endif\n  |  ldr INS, [PC, #-4]\n  |.if JIT\n  |   cmp OP, #BC_JFORI\n  |.endif\n  |  decode_RA8 RA, INS\n  |  decode_RD RC, INS\n  |.if JIT\n  |   beq =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  ldrd CARG12, [BASE]\n  |   ldrd CARG34, [BASE, #8]\n  |    cmp NARGS8:RC, #16\n  |    blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc_1 name\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc_2 name\n  |  checktp CARG2, LJ_TISNUM\n  |  cmnlo CARG4, #-LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_d, name\n  |  .ffunc name\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |  vldr d0, [BASE]\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_dd, name\n  |  .ffunc name\n  |  ldr CARG2, [BASE, #4]\n  |  ldr CARG4, [BASE, #12]\n  |   cmp NARGS8:RC, #16\n  |  vldr d0, [BASE]\n  |  vldr d1, [BASE, #8]\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  cmnlo CARG4, #-LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.\n  |.macro ffgccheck\n  |  ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)]\n  |  ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)]\n  |  cmp CARG1, CARG2\n  |  blge ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  checktp CARG2, LJ_TTRUE\n  |  bhi ->fff_fallback\n  |   ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |  mov RB, BASE\n  |  subs RA, NARGS8:RC, #8\n  |   add RC, NARGS8:RC, #8\t\t// Compute (nresults+1)*8.\n  |  beq ->fff_res\t\t\t// Done if exactly 1 argument.\n  |1:\n  |   ldrd CARG12, [RB, #8]\n  |  subs RA, RA, #8\n  |   strd CARG12, [RB], #8\n  |  bne <1\n  |  b ->fff_res\n  |\n  |.ffunc type\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  mvnlo CARG2, #~LJ_TISNUM\n  |  rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1\n  |  lsl CARG4, CARG4, #3\n  |  ldrd CARG12, [CFUNC:CARG3, CARG4]\n  |  b ->fff_restv\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  checktp CARG2, LJ_TTAB\n  |  cmnne CARG2, #-LJ_TUDATA\n  |  bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  ldr TAB:RB, TAB:CARG1->metatable\n  |2:\n  |   mvn CARG2, #~LJ_TNIL\n  |   ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])]\n  |  cmp TAB:RB, #0\n  |  beq ->fff_restv\n  |  ldr CARG3, TAB:RB->hmask\n  |   ldr CARG4, STR:RC->hash\n  |    ldr NODE:INS, TAB:RB->node\n  |  and CARG3, CARG3, CARG4\t\t// idx = str->hash & tab->hmask\n  |  add CARG3, CARG3, CARG3, lsl #1\n  |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  ldrd CARG34, NODE:INS->key  // STALL: early NODE:INS.\n  |   ldrd CARG12, NODE:INS->val\n  |    ldr NODE:INS, NODE:INS->next\n  |  checktp CARG4, LJ_TSTR\n  |  cmpeq CARG3, STR:RC\n  |  beq >5\n  |  cmp NODE:INS, #0\n  |  bne <3\n  |4:\n  |  mov CARG1, RB\t\t\t// Use metatable as default result.\n  |  mvn CARG2, #~LJ_TTAB\n  |  b ->fff_restv\n  |5:\n  |  checktp CARG2, LJ_TNIL\n  |  bne ->fff_restv\n  |  b <4\n  |\n  |6:\n  |  checktp CARG2, LJ_TISNUM\n  |  mvnhs CARG2, CARG2\n  |  movlo CARG2, #~LJ_TISNUM\n  |  add CARG4, DISPATCH, CARG2, lsl #2\n  |  ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  checktp CARG2, LJ_TTAB\n  |   ldreq TAB:RB, TAB:CARG1->metatable\n  |  checktpeq CARG4, LJ_TTAB\n  |    ldrbeq CARG4, TAB:CARG1->marked\n  |   cmpeq TAB:RB, #0\n  |  bne ->fff_fallback\n  |    tst CARG4, #LJ_GC_BLACK\t\t// isblack(table)\n  |     str TAB:CARG3, TAB:CARG1->metatable\n  |    beq ->fff_restv\n  |  barrierback TAB:CARG1, CARG4, CARG3\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  ldrd CARG34, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |   mov CARG2, CARG3\n  |  checktab CARG4, ->fff_fallback\n  |   mov CARG1, L\n  |   add CARG3, BASE, #8\n  |  .IOS mov RA, BASE\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |  .IOS mov BASE, RA\n  |  ldrd CARG12, [CRET1]\n  |  b ->fff_restv\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   bne ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bls ->fff_restv\n  |  b ->fff_fallback\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  checktp CARG2, LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])]\n  |   str BASE, L->base\n  |  checktp CARG2, LJ_TISNUM\n  |  cmpls CARG4, #0\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  bhi ->fff_fallback\n  |  ffgccheck\n  |  mov CARG1, L\n  |  mov CARG2, BASE\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |  mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |   mvn CARG4, #~LJ_TNIL\n  |  checktab CARG2, ->fff_fallback\n  |   strd CARG34, [BASE, NARGS8:RC]\t// Set missing 2nd arg to nil.\n  |   ldr PC, [BASE, FRAME_PC]\n  |  mov CARG2, CARG1\n  |    str BASE, L->base\t\t// Add frame since C call can throw.\n  |  mov CARG1, L\n  |    str BASE, L->top\t\t\t// Dummy frame length is ok.\n  |  add CARG3, BASE, #8\n  |   str PC, SAVE_PC\n  |  bl extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Returns 0 at end of traversal.\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |  mvneq CRET2, #~LJ_TNIL\n  |  beq ->fff_restv\t\t\t// End of traversal: return nil.\n  |  ldrd CARG12, [BASE, #8]\t\t// Copy key and value to results.\n  |   ldrd CARG34, [BASE, #16]\n  |    mov RC, #(2+1)*8\n  |  strd CARG12, [BASE, #-8]\n  |   strd CARG34, [BASE]\n  |  b ->fff_res\n  |\n  |.ffunc_1 pairs\n  |  checktab CARG2, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:RB, TAB:CARG1->metatable\n#endif\n  |   ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cmp TAB:RB, #0\n  |  bne ->fff_fallback\n#endif\n  |  mvn CARG2, #~LJ_TNIL\n  |    mov RC, #(3+1)*8\n  |   strd CFUNC:CARG34, [BASE, #-8]\n  |  str CARG2, [BASE, #12]\n  |  b ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  checktp CARG2, LJ_TTAB\n  |  checktpeq CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  ldr RB, TAB:CARG1->asize\n  |   ldr RC, TAB:CARG1->array\n  |  add CARG3, CARG3, #1\n  |    ldr PC, [BASE, FRAME_PC]\n  |  cmp CARG3, RB\n  |   add RC, RC, CARG3, lsl #3\n  |  strd CARG34, [BASE, #-8]\n  |   ldrdlo CARG12, [RC]\n  |   mov RC, #(0+1)*8\n  |  bhs >2\t\t\t\t// Not in array part?\n  |1:\n  |   checktp CARG2, LJ_TNIL\n  |   movne RC, #(2+1)*8\n  |   strdne CARG12, [BASE]\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  ldr RB, TAB:CARG1->hmask\n  |   mov CARG2, CARG3\n  |  cmp RB, #0\n  |  beq ->fff_res\n  |  .IOS mov RA, BASE\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  .IOS mov BASE, RA\n  |  cmp CRET1, #0\n  |  beq ->fff_res\n  |  ldrd CARG12, [CRET1]\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktab CARG2, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:RB, TAB:CARG1->metatable\n#endif\n  |   ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cmp TAB:RB, #0\n  |  bne ->fff_fallback\n#endif\n  |  mov CARG1, #0\n  |  mvn CARG2, #~LJ_TISNUM\n  |    mov RC, #(3+1)*8\n  |   strd CFUNC:CARG34, [BASE, #-8]\n  |  strd CARG12, [BASE, #8]\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |  tst RA, #HOOK_ACTIVE\t\t// Remember active hook before pcall.\n  |   mov RB, BASE\n  |   add BASE, BASE, #8\n  |  moveq PC, #8+FRAME_PCALL\n  |  movne PC, #8+FRAME_PCALLH\n  |   sub NARGS8:RC, NARGS8:RC, #8\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  checkfunc CARG4, ->fff_fallback\t// Traceback must be a function.\n  |   mov RB, BASE\n  |  strd CARG12, [BASE, #8]\t\t// Swap function and traceback.\n  |   strd CARG34, [BASE]\n  |  tst RA, #HOOK_ACTIVE\t\t// Remember active hook before pcall.\n  |   add BASE, BASE, #16\n  |  moveq PC, #16+FRAME_PCALL\n  |  movne PC, #16+FRAME_PCALLH\n  |   sub NARGS8:RC, NARGS8:RC, #16\n  |  b ->vm_call_dispatch\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  checktp CARG2, LJ_TTHREAD\n  |  bne ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr\n  |.endif\n  |   ldr PC, [BASE, FRAME_PC]\n  |     str BASE, L->base\n  |  ldr CARG2, L:CARG1->top\n  |   ldrb RA, L:CARG1->status\n  |    ldr RB, L:CARG1->base\n  |  add CARG3, CARG2, NARGS8:RC\n  |  add CARG4, CARG2, RA\n  |   str PC, SAVE_PC\n  |  cmp CARG4, RB\n  |  beq ->fff_fallback\n  |   ldr CARG4, L:CARG1->maxstack\n  |    ldr RB, L:CARG1->cframe\n  |   cmp RA, #LUA_YIELD\n  |   cmpls CARG3, CARG4\n  |    cmpls RB, #0\n  |    bhi ->fff_fallback\n  |1:\n  |.if resume\n  |  sub CARG3, CARG3, #8\t\t// Keep resumed thread in stack for GC.\n  |  add BASE, BASE, #8\n  |  sub NARGS8:RC, NARGS8:RC, #8\n  |.endif\n  |  str CARG3, L:CARG1->top\n  |  str BASE, L->top\n  |2:  // Move args to coroutine.\n  |   ldrd CARG34, [BASE, RB]\n  |  cmp RB, NARGS8:RC\n  |   strdne CARG34, [CARG2, RB]\n  |  add RB, RB, #8\n  |  bne <2\n  |\n  |  mov CARG3, #0\n  |   mov L:RA, L:CARG1\n  |  mov CARG4, #0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  ldr CARG3, L:RA->base\n  |    mv_vmstate CARG2, INTERP\n  |  ldr CARG4, L:RA->top\n  |   cmp CRET1, #LUA_YIELD\n  |  ldr BASE, L->base\n  |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |    st_vmstate CARG2\n  |   bhi >8\n  |  subs RC, CARG4, CARG3\n  |   ldr CARG1, L->maxstack\n  |   add CARG2, BASE, RC\n  |  beq >6\t\t\t\t// No results?\n  |  cmp CARG2, CARG1\n  |   mov RB, #0\n  |  bhi >9\t\t\t\t// Need to grow stack?\n  |\n  |  sub CARG4, RC, #8\n  |   str CARG3, L:RA->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |   ldrd CARG12, [CARG3, RB]\n  |  cmp RB, CARG4\n  |   strd CARG12, [BASE, RB]\n  |  add RB, RB, #8\n  |  bne <5\n  |6:\n  |.if resume\n  |  mvn CARG3, #~LJ_TTRUE\n  |   add RC, RC, #16\n  |7:\n  |  str CARG3, [BASE, #-4]\t\t// Prepend true/false to results.\n  |   sub RA, BASE, #8\n  |.else\n  |   mov RA, BASE\n  |   add RC, RC, #8\n  |.endif\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str PC, SAVE_PC\n  |   str RC, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  ldrd CARG12, [CARG4, #-8]!\n  |   mvn CARG3, #~LJ_TFALSE\n  |    mov RC, #(2+1)*8\n  |  str CARG4, L:RA->top\t\t// Remove error from coroutine stack.\n  |  strd CARG12, [BASE]\t\t// Copy error message.\n  |  b <7\n  |.else\n  |  mov CARG1, L\n  |  mov CARG2, L:RA\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Never returns.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov CARG1, L\n  |  lsr CARG2, RC, #3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov CRET1, #0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  ldr CARG1, L->cframe\n  |   add CARG2, BASE, NARGS8:RC\n  |   str BASE, L->base\n  |  tst CARG1, #CFRAME_RESUME\n  |   str CARG2, L->top\n  |    mov CRET1, #LUA_YIELD\n  |   mov CARG3, #0\n  |  beq ->fff_fallback\n  |   str CARG3, L->cframe\n  |    strb CRET1, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.macro math_round, func\n  |  .ffunc_1 math_ .. func\n  |  checktp CARG2, LJ_TISNUM\n  |  beq ->fff_restv\n  |  bhi ->fff_fallback\n  |  // Round FP value and normalize result.\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  bpl >2\t\t\t\t// |x| < 1?\n  |  mvn CARG4, #0x3e0\n  |    subs RB, CARG4, RB, asr #21\n  |  lsl CARG4, CARG2, #11\n  |   lsl CARG3, CARG1, #11\n  |  orr CARG4, CARG4, #0x80000000\n  |   rsb INS, RB, #32\n  |  orr CARG4, CARG4, CARG1, lsr #21\n  |    bls >3\t\t\t\t// |x| >= 2^31?\n  |   orr CARG3, CARG3, CARG4, lsl INS\n  |  lsr CARG1, CARG4, RB\n  |.if \"func\" == \"floor\"\n  |   tst CARG3, CARG2, asr #31\n  |   addne CARG1, CARG1, #1\n  |.else\n  |   bics CARG3, CARG3, CARG2, asr #31\n  |   addsne CARG1, CARG1, #1\n  |   ldrdvs CARG12, >9\n  |   bvs ->fff_restv\n  |.endif\n  |    cmp CARG2, #0\n  |    rsblt CARG1, CARG1, #0\n  |1:\n  |   mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |2:  // |x| < 1\n  |  bcs ->fff_restv\t\t\t// |x| is not finite.\n  |  orr CARG3, CARG3, CARG1\t\t// ztest = abs(hi) | lo\n  |.if \"func\" == \"floor\"\n  |  tst CARG3, CARG2, asr #31\t\t// return (ztest & sign) == 0 ? 0 : -1\n  |  moveq CARG1, #0\n  |  mvnne CARG1, #0\n  |.else\n  |  bics CARG3, CARG3, CARG2, asr #31\t// return (ztest & ~sign) == 0 ? 0 : 1\n  |  moveq CARG1, #0\n  |  movne CARG1, #1\n  |.endif\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |3:  // |x| >= 2^31. Check for x == -(2^31).\n  |  cmpeq CARG4, #0x80000000\n  |.if \"func\" == \"floor\"\n  |  cmpeq CARG3, #0\n  |.endif\n  |  bne >4\n  |  cmp CARG2, #0\n  |  movmi CARG1, #0x80000000\n  |  bmi <1\n  |4:\n  |  bl ->vm_..func.._sf\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.align 8\n  |9:\n  |  .long 0x00000000, 0x41e00000\t// 2^31.\n  |\n  |.ffunc_1 math_abs\n  |  checktp CARG2, LJ_TISNUM\n  |  bhi ->fff_fallback\n  |  bicne CARG2, CARG2, #0x80000000\n  |  bne ->fff_restv\n  |  cmp CARG1, #0\n  |  rsbslt CARG1, CARG1, #0\n  |  ldrdvs CARG12, <9\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG12 = TValue result.\n  |  ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |->fff_res1:\n  |  // PC = return.\n  |  mov RC, #(1+1)*8\n  |->fff_res:\n  |  // RC = (nresults+1)*8, PC = return.\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  ldreq INS, [PC, #-4]\n  |   str RC, SAVE_MULTRES\n  |  sub RA, BASE, #8\n  |  bne ->vm_return\n  |  decode_RB8 RB, INS\n  |5:\n  |  cmp RB, RC\t\t\t\t// More results expected?\n  |  bhi >6\n  |  decode_RA8 CARG1, INS\n  |   ins_next1\n  |   ins_next2\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  sub BASE, RA, CARG1\n  |   ins_next3\n  |\n  |6:  // Fill up results with nil.\n  |  add CARG2, RA, RC\n  |  mvn CARG1, #~LJ_TNIL\n  |   add RC, RC, #8\n  |  str CARG1, [CARG2, #-4]\n  |  b <5\n  |\n  |.macro math_extern, func\n  |.if HFABI\n  |  .ffunc_d math_ .. func\n  |.else\n  |  .ffunc_n math_ .. func\n  |.endif\n  |  .IOS mov RA, BASE\n  |  bl extern func\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |.if HFABI\n  |  .ffunc_dd math_ .. func\n  |.else\n  |  .ffunc_nn math_ .. func\n  |.endif\n  |  .IOS mov RA, BASE\n  |  bl extern func\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |.endmacro\n  |\n  |.if FPU\n  |  .ffunc_d math_sqrt\n  |  vsqrt.f64 d0, d0\n  |->fff_resd:\n  |  ldr PC, [BASE, FRAME_PC]\n  |  vstr d0, [BASE, #-8]\n  |  b ->fff_res1\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |.ffunc math_log\n  |.if HFABI\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |  vldr d0, [BASE]\n  |   bne ->fff_fallback\n  |.else\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |   bne ->fff_fallback\n  |.endif\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern log\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if HFABI\n  |  .ffunc math_ldexp\n  |  ldr CARG4, [BASE, #4]\n  |  ldrd CARG12, [BASE, #8]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  vldr d0, [BASE]\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  .IOS mov BASE, RA\n  |  b ->fff_resd\n  |.else\n  |.ffunc_2 math_ldexp\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  checktp CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  .IOS mov BASE, RA\n  |  b ->fff_restv\n  |.endif\n  |\n  |.if HFABI\n  |.ffunc_d math_frexp\n  |  mov CARG1, sp\n  |  .IOS mov RA, BASE\n  |  bl extern frexp\n  |  .IOS mov BASE, RA\n  |   ldr CARG3, [sp]\n  |   mvn CARG4, #~LJ_TISNUM\n  |    ldr PC, [BASE, FRAME_PC]\n  |  vstr d0, [BASE, #-8]\n  |    mov RC, #(2+1)*8\n  |   strd CARG34, [BASE]\n  |  b ->fff_res\n  |.else\n  |.ffunc_n math_frexp\n  |  mov CARG3, sp\n  |  .IOS mov RA, BASE\n  |  bl extern frexp\n  |  .IOS mov BASE, RA\n  |   ldr CARG3, [sp]\n  |   mvn CARG4, #~LJ_TISNUM\n  |    ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |    mov RC, #(2+1)*8\n  |   strd CARG34, [BASE]\n  |  b ->fff_res\n  |.endif\n  |\n  |.if HFABI\n  |.ffunc_d math_modf\n  |  sub CARG1, BASE, #8\n  |   ldr PC, [BASE, FRAME_PC]\n  |  .IOS mov RA, BASE\n  |  bl extern modf\n  |  .IOS mov BASE, RA\n  |   mov RC, #(2+1)*8\n  |  vstr d0, [BASE]\n  |  b ->fff_res\n  |.else\n  |.ffunc_n math_modf\n  |  sub CARG3, BASE, #8\n  |   ldr PC, [BASE, FRAME_PC]\n  |  .IOS mov RA, BASE\n  |  bl extern modf\n  |  .IOS mov BASE, RA\n  |   mov RC, #(2+1)*8\n  |  strd CARG12, [BASE]\n  |  b ->fff_res\n  |.endif\n  |\n  |.macro math_minmax, name, cond, fcond\n  |.if FPU\n  |  .ffunc_1 name\n  |   add RB, BASE, RC\n  |  checktp CARG2, LJ_TISNUM\n  |   add RA, BASE, #8\n  |  bne >4\n  |1:  // Handle integers.\n  |  ldrd CARG34, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bne >3\n  |  cmp CARG1, CARG3\n  |   add RA, RA, #8\n  |  mov..cond CARG1, CARG3\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  vmov s4, CARG1\n  |  bhi ->fff_fallback\n  |  vldr d1, [RA]\n  |  vcvt.f64.s32 d0, s4\n  |  b >6\n  |\n  |4:\n  |  vldr d0, [BASE]\n  |  bhi ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldrd CARG34, [RA]\n  |  vldr d1, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_resd\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs >7\n  |6:\n  |  vcmp.f64 d0, d1\n  |  vmrs\n  |   add RA, RA, #8\n  |  vmov..fcond.f64 d0, d1\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  vmov s4, CARG3\n  |  bhi ->fff_fallback\n  |  vcvt.f64.s32 d1, s4\n  |  b <6\n  |\n  |.else\n  |\n  |  .ffunc_1 name\n  |  checktp CARG2, LJ_TISNUM\n  |   mov RA, #8\n  |  bne >4\n  |1:  // Handle integers.\n  |  ldrd CARG34, [BASE, RA]\n  |   cmp RA, RC\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bne >3\n  |  cmp CARG1, CARG3\n  |   add RA, RA, #8\n  |  mov..cond CARG1, CARG3\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  bhi ->fff_fallback\n  |  bl extern __aeabi_i2d\n  |  ldrd CARG34, [BASE, RA]\n  |  b >6\n  |\n  |4:\n  |  bhi ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldrd CARG34, [BASE, RA]\n  |   cmp RA, RC\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs >7\n  |6:\n  |  bl extern __aeabi_cdcmple\n  |   add RA, RA, #8\n  |  mov..fcond CARG1, CARG3\n  |  mov..fcond CARG2, CARG4\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  bhi ->fff_fallback\n  |  strd CARG12, TMPD\n  |  mov CARG1, CARG3\n  |  bl extern __aeabi_i2d\n  |  ldrd CARG34, TMPD\n  |  b <6\n  |.endif\n  |.endmacro\n  |\n  |  math_minmax math_min, gt, hi\n  |  math_minmax math_max, lt, lo\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  ldrd CARG12, [BASE]\n  |    ldr PC, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\n  |   checktpeq CARG2, LJ_TSTR\t\t// Need exactly 1 argument.\n  |   bne ->fff_fallback\n  |  ldr CARG3, STR:CARG1->len\n  |   ldrb CARG1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   mvn CARG2, #~LJ_TISNUM\n  |  cmp CARG3, #0\n  |  moveq RC, #(0+1)*8\n  |  movne RC, #(1+1)*8\n  |   strd CARG12, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  ldrd CARG12, [BASE]\n  |    ldr PC, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |   checktpeq CARG2, LJ_TISNUM\n  |   bicseq CARG4, CARG1, #255\n  |  mov CARG3, #1\n  |   bne ->fff_fallback\n  |  str CARG1, TMPD\n  |  mov CARG2, TMPDp\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  // CARG2 = str, CARG3 = len.\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |   mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  ldrd CARG12, [BASE]\n  |   ldrd CARG34, [BASE, #16]\n  |    cmp NARGS8:RC, #16\n  |     mvn RB, #0\n  |    beq >1\n  |    blo ->fff_fallback\n  |   checktp CARG4, LJ_TISNUM\n  |    mov RB, CARG3\n  |   bne ->fff_fallback\n  |1:\n  |  ldrd CARG34, [BASE, #8]\n  |  checktp CARG2, LJ_TSTR\n  |   ldreq CARG2, STR:CARG1->len\n  |  checktpeq CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end\n  |  add CARG4, CARG2, #1\n  |  cmp CARG3, #0\t\t\t// if (start < 0) start += len+1\n  |  addlt CARG3, CARG3, CARG4\n  |  cmp CARG3, #1\t\t\t// if (start < 1) start = 1\n  |  movlt CARG3, #1\n  |  cmp RB, #0\t\t\t\t// if (end < 0) end += len+1\n  |  addlt RB, RB, CARG4\n  |  bic RB, RB, RB, asr #31\t\t// if (end < 0) end = 0\n  |  cmp RB, CARG2\t\t\t// if (end > len) end = len\n  |   add CARG1, STR:CARG1, #sizeof(GCstr)-1\n  |  movgt RB, CARG2\n  |   add CARG2, CARG1, CARG3\n  |  subs CARG3, RB, CARG3\t\t// len = end - start\n  |   add CARG3, CARG3, #1\t\t// len += 1\n  |  bge ->fff_newstr\n  |->fff_emptystr:\n  |  sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)\n  |  mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  ldr CARG3, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |  ldr STR:CARG2, [BASE]\n  |   blo ->fff_fallback\n  |  sub SBUF:CARG1, DISPATCH, #-DISPATCH_GL(tmpbuf)\n  |  checkstr CARG3, ->fff_fallback\n  |  ldr CARG4, SBUF:CARG1->b\n  |   str BASE, L->base\n  |   str PC, SAVE_PC\n  |   str L, SBUF:CARG1->L\n  |  str CARG4, SBUF:CARG1->p\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |// FP number to bit conversion for soft-float. Clobbers r0-r3.\n  |->vm_tobit_fb:\n  |  bhi ->fff_fallback\n  |->vm_tobit:\n  |  lsl RB, CARG2, #1\n  |  adds RB, RB, #0x00200000\n  |  movpl CARG1, #0\t\t\t// |x| < 1?\n  |  bxpl lr\n  |  mvn CARG4, #0x3e0\n  |  subs RB, CARG4, RB, asr #21\n  |  bmi >1\t\t\t\t// |x| >= 2^32?\n  |  lsl CARG4, CARG2, #11\n  |  orr CARG4, CARG4, #0x80000000\n  |  orr CARG4, CARG4, CARG1, lsr #21\n  |   cmp CARG2, #0\n  |  lsr CARG1, CARG4, RB\n  |   rsblt CARG1, CARG1, #0\n  |  bx lr\n  |1:\n  |  add RB, RB, #21\n  |  lsr CARG4, CARG1, RB\n  |  rsb RB, RB, #20\n  |  lsl CARG1, CARG2, #12\n  |   cmp CARG2, #0\n  |  orr CARG1, CARG4, CARG1, lsl RB\n  |   rsblt CARG1, CARG1, #0\n  |  bx lr\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |.endmacro\n  |\n  |.ffunc_bit tobit\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  mov CARG3, CARG1\n  |  mov RA, #8\n  |1:\n  |  ldrd CARG12, [BASE, RA]\n  |   cmp RA, NARGS8:RC\n  |    add RA, RA, #8\n  |   bge >2\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |  ins CARG3, CARG3, CARG1\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, orr\n  |.ffunc_bit_op bxor, eor\n  |\n  |2:\n  |  mvn CARG4, #~LJ_TISNUM\n  |   ldr PC, [BASE, FRAME_PC]\n  |  strd CARG34, [BASE, #-8]\n  |  b ->fff_res1\n  |\n  |.ffunc_bit bswap\n  |  eor CARG3, CARG1, CARG1, ror #16\n  |  bic CARG3, CARG3, #0x00ff0000\n  |  ror CARG1, CARG1, #8\n  |   mvn CARG2, #~LJ_TISNUM\n  |  eor CARG1, CARG1, CARG3, lsr #8\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bnot\n  |  mvn CARG1, CARG1\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc bit_..name\n  |  ldrd CARG12, [BASE, #8]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |.if shmod == 0\n  |  and RA, CARG1, #31\n  |.else\n  |  rsb RA, CARG1, #0\n  |.endif\n  |  ldrd CARG12, [BASE]\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |  ins CARG1, CARG1, RA\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, lsl, 0\n  |.ffunc_bit_sh rshift, lsr, 0\n  |.ffunc_bit_sh arshift, asr, 0\n  |.ffunc_bit_sh rol, ror, 1\n  |.ffunc_bit_sh ror, ror, 0\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RC = nargs*8\n  |   ldr CARG3, [BASE, FRAME_FUNC]\n  |  ldr CARG2, L->maxstack\n  |  add CARG1, BASE, NARGS8:RC\n  |    ldr PC, [BASE, FRAME_PC]\t\t// Fallback may overwrite PC.\n  |  str CARG1, L->top\n  |   ldr CARG3, CFUNC:CARG3->f\n  |    str BASE, L->base\n  |  add CARG1, CARG1, #8*LUA_MINSTACK\n  |    str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  cmp CARG1, CARG2\n  |   mov CARG1, L\n  |  bhi >5\t\t\t\t// Need to grow stack.\n  |   blx CARG3\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |   ldr BASE, L->base\n  |  cmp CRET1, #0\n  |   lsl RC, CRET1, #3\n  |   sub RA, BASE, #8\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |   ldr CARG1, L->top\n  |    ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, CARG1, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   bic CARG2, PC, #FRAME_TYPEP\n  |  ldreq INS, [PC, #-4]\n  |  andeq CARG2, MASKR8, INS, lsr #5\t// Conditional decode_RA8.\n  |  addeq CARG2, CARG2, #8\n  |  sub RB, BASE, CARG2\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2, #LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |  cmp CARG1, CARG1\t\t\t// Set zero-flag to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  mov RA, lr\n  |   str BASE, L->base\n  |  add CARG2, BASE, NARGS8:RC\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  str CARG2, L->top\n  |  mov CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |   ldr BASE, L->base\n  |  mov lr, RA\t\t\t\t// Help return address predictor.\n  |   ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  bx lr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  tst CARG1, #HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  bne >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |   ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  tst CARG1, #HOOK_ACTIVE\n  |  bne >1\n  |   sub CARG2, CARG2, #1\n  |  tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT\n  |   strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  b >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  tst CARG1, #HOOK_ACTIVE\t\t// Hook already active?\n  |  beq >1\n  |5:  // Re-dispatch to static ins.\n  |  decode_OP OP, INS\n  |  add OP, DISPATCH, OP, lsl #2\n  |  ldr pc, [OP, #GG_DISP2STATIC]\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |   ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  tst CARG1, #HOOK_ACTIVE\t\t// Hook already active?\n  |  bne <5\n  |  tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT\n  |  beq <5\n  |   subs CARG2, CARG2, #1\n  |   str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |   beq >1\n  |  tst CARG1, #LUA_MASKLINE\n  |  beq <5\n  |1:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  ldr BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  ldrb OP, [PC, #-4]\n  |   ldr INS, [PC, #-4]\n  |  add OP, DISPATCH, OP, lsl #2\n  |  ldr OP, [OP, #GG_DISP2STATIC]\n  |   decode_RA8 RA, INS\n  |   decode_RD RC, INS\n  |  bx OP\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  ldr CARG1, [CARG4, #-24]\n  |   add PC, PC, #4\n  |  str CARG1, SAVE_MULTRES\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Same as curr_topL(L).\n  |   sub CARG1, DISPATCH, #-GG_DISP2J\n  |   str PC, SAVE_PC\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |   mov CARG2, PC\n  |   str L, [DISPATCH, #DISPATCH_J(L)]\n  |  ldrb CARG3, [CARG3, #PC2PROTO(framesize)]\n  |   str BASE, L->base\n  |  add CARG3, BASE, CARG3, lsl #3\n  |  str CARG3, L->top\n  |  bl extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  b <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  orr CARG2, PC, #1\n  |1:\n  |.endif\n  |  add CARG4, BASE, RC\n  |   str PC, SAVE_PC\n  |    mov CARG1, L\n  |   str BASE, L->base\n  |    sub RA, RA, BASE\n  |  str CARG4, L->top\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  ldr BASE, L->base\n  |   ldr CARG4, L->top\n  |    mov CARG2, #0\n  |  add RA, BASE, RA\n  |   sub NARGS8:RC, CARG4, BASE\n  |    str CARG2, SAVE_PC\t\t// Invalidate for subsequent line hook.\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   ldr INS, [PC, #-4]\n  |  bx CRET1\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, CARG4 = meta base\n  |   ldr RB, SAVE_MULTRES\n  |  ldr INS, [PC, #-4]\n  |    ldr TRACE:CARG3, [CARG4, #-24]\t// Save previous trace.\n  |   subs RB, RB, #8\n  |  decode_RA8 RC, INS\t\t\t// Call base.\n  |   beq >2\n  |1:  // Move results down.\n  |  ldrd CARG12, [RA]\n  |    add RA, RA, #8\n  |   subs RB, RB, #8\n  |  strd CARG12, [BASE, RC]\n  |    add RC, RC, #8\n  |   bne <1\n  |2:\n  |   decode_RA8 RA, INS\n  |   decode_RB8 RB, INS\n  |   add RA, RA, RB\n  |3:\n  |   cmp RA, RC\n  |  mvn CARG2, #~LJ_TNIL\n  |   bhi >9\t\t\t\t// More results wanted?\n  |\n  |  ldrh RA, TRACE:CARG3->traceno\n  |  ldrh RC, TRACE:CARG3->link\n  |  cmp RC, RA\n  |  beq ->cont_nop\t\t\t// Blacklisted.\n  |  cmp RC, #0\n  |  bne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  str RA, [DISPATCH, #DISPATCH_J(exitno)]\n  |  str L, [DISPATCH, #DISPATCH_J(L)]\n  |  str BASE, L->base\n  |  sub CARG1, DISPATCH, #-GG_DISP2J\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  ldr BASE, L->base\n  |  b ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  strd CARG12, [BASE, RC]\n  |  add RC, RC, #8\n  |  b <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  ldr BASE, L->base\n  |  sub PC, PC, #4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |  sub sp, sp, #12\n  |  push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}\n  |  ldr CARG1, [sp, #64]\t// Load original value of lr.\n  |   ldr DISPATCH, [lr]\t// Load DISPATCH.\n  |    add CARG3, sp, #64\t// Recompute original value of sp.\n  |   mv_vmstate CARG4, EXIT\n  |    str CARG3, [sp, #52]\t// Store sp in RID_SP\n  |   st_vmstate CARG4\n  |  ldr CARG2, [CARG1, #-4]!\t// Get exit instruction.\n  |   str CARG1, [sp, #56]\t// Store exit pc in RID_LR and RID_PC.\n  |   str CARG1, [sp, #60]\n  |.if FPU\n  |  vpush {d0-d15}\n  |.endif\n  |  lsl CARG2, CARG2, #8\n  |  add CARG1, CARG1, CARG2, asr #6\n  |   ldr CARG2, [lr, #4]\t// Load exit stub group offset.\n  |   sub CARG1, CARG1, lr\n  |  ldr L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |   add CARG1, CARG2, CARG1, lsr #2\t// Compute exit number.\n  |    ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |   str CARG1, [DISPATCH, #DISPATCH_J(exitno)]\n  |   mov CARG4, #0\n  |    str BASE, L->base\n  |  str L, [DISPATCH, #DISPATCH_J(L)]\n  |   str CARG4, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |  sub CARG1, DISPATCH, #-GG_DISP2J\n  |  mov CARG2, sp\n  |  bl extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  ldr CARG2, L->cframe\n  |   ldr BASE, L->base\n  |  bic CARG2, CARG2, #~CFRAME_RAWMASK\t// Use two steps: bic sp is deprecated.\n  |  mov sp, CARG2\n  |   ldr PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  str L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |  b >1\n  |.endif\n  |->vm_exit_interp:\n  |  // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |  ldr L, SAVE_L\n  |1:\n  |  cmp CARG1, #0\n  |  blt >9\t\t\t\t// Check for error from exit.\n  |   lsl RC, CARG1, #3\n  |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n  |   str RC, SAVE_MULTRES\n  |   mov CARG3, #0\n  |   str BASE, L->base\n  |  ldr CARG2, LFUNC:CARG2->field_pc\n  |   str CARG3, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |    mv_vmstate CARG4, INTERP\n  |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  ldrb OP, [PC]\n  |     mov MASKR8, #255\n  |   ldr INS, [PC], #4\n  |     lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |    st_vmstate CARG4\n  |  cmp OP, #BC_FUNCC+2\t\t// Fast function?\n  |  bhs >4\n  |2:\n  |  cmp OP, #BC_FUNCF\t\t\t// Function header?\n  |  ldr OP, [DISPATCH, OP, lsl #2]\n  |   decode_RA8 RA, INS\n  |   lsrlo RC, INS, #16\t// No: Decode operands A*8 and D.\n  |   subhs RC, RC, #8\n  |   addhs RA, RA, BASE\t// Yes: RA = BASE+framesize*8, RC = nargs*8\n  |   ldrhs CARG3, [BASE, FRAME_FUNC]\n  |  bx OP\n  |\n  |4:  // Check frame below fast function.\n  |  ldr CARG1, [BASE, FRAME_PC]\n  |  ands CARG2, CARG1, #FRAME_TYPE\n  |  bne <2\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  ldr CARG3, [CARG1, #-4]\n  |  decode_RA8 CARG1, CARG3\n  |  sub CARG2, BASE, CARG1\n  |  ldr LFUNC:CARG3, [CARG2, #-16]\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  b <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  rsb CARG2, CARG1, #0\n  |  mov CARG1, L\n  |  bl extern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called from JIT code.\n  |//\n  |// double lj_vm_floor/ceil/trunc(double x);\n  |.macro vm_round, func, hf\n  |.if hf == 1\n  |  vmov CARG1, CARG2, d0\n  |.endif\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  bpl >2\t\t\t\t// |x| < 1?\n  |  mvn CARG4, #0x3cc\n  |  subs RB, CARG4, RB, asr #21\t// 2^0: RB = 51, 2^51: RB = 0.\n  |  bxlo lr\t\t\t\t// |x| >= 2^52: done.\n  |  mvn CARG4, #1\n  |   bic CARG3, CARG1, CARG4, lsl RB\t// ztest = lo & ~lomask\n  |  and CARG1, CARG1, CARG4, lsl RB\t// lo &= lomask\n  |  subs RB, RB, #32\n  |   bicpl CARG4, CARG2, CARG4, lsl RB\t// |x| <= 2^20: ztest |= hi & ~himask\n  |   orrpl CARG3, CARG3, CARG4\n  |   mvnpl CARG4, #1\n  |  andpl CARG2, CARG2, CARG4, lsl RB\t// |x| <= 2^20: hi &= himask\n  |.if \"func\" == \"floor\"\n  |   tst CARG3, CARG2, asr #31\t\t// iszero = ((ztest & signmask) == 0)\n  |.else\n  |   bics CARG3, CARG3, CARG2, asr #31\t// iszero = ((ztest & ~signmask) == 0)\n  |.endif\n  |.if hf == 1\n  |  vmoveq d0, CARG1, CARG2\n  |.endif\n  |  bxeq lr\t\t\t\t// iszero: done.\n  |  mvn CARG4, #1\n  |  cmp RB, #0\n  |  lslpl CARG3, CARG4, RB\n  |  mvnmi CARG3, #0\n  |  add RB, RB, #32\n  |  subs CARG1, CARG1, CARG4, lsl RB\t// lo = lo-lomask\n  |  sbc CARG2, CARG2, CARG3\t\t// hi = hi-himask+carry\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |\n  |2:  // |x| < 1:\n  |  bxcs lr\t\t\t\t// |x| is not finite.\n  |  orr CARG3, CARG3, CARG1\t\t// ztest = (2*hi) | lo\n  |.if \"func\" == \"floor\"\n  |  tst CARG3, CARG2, asr #31\t\t// iszero = ((ztest & signmask) == 0)\n  |.else\n  |  bics CARG3, CARG3, CARG2, asr #31\t// iszero = ((ztest & ~signmask) == 0)\n  |.endif\n  |  mov CARG1, #0\t\t\t// lo = 0\n  |  and CARG2, CARG2, #0x80000000\n  |  ldrne CARG4, <9\t\t\t// hi = sign(x) | (iszero ? 0.0 : 1.0)\n  |  orrne CARG2, CARG2, CARG4\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |.endmacro\n  |\n  |9:\n  |  .long 0x3ff00000\t\t\t// hiword(+1.0)\n  |\n  |->vm_floor:\n  |.if HFABI\n  |  vm_round floor, 1\n  |.endif\n  |->vm_floor_sf:\n  |  vm_round floor, 0\n  |\n  |->vm_ceil:\n  |.if HFABI\n  |  vm_round ceil, 1\n  |.endif\n  |->vm_ceil_sf:\n  |  vm_round ceil, 0\n  |\n  |.macro vm_trunc, hf\n  |.if JIT\n  |.if hf == 1\n  |  vmov CARG1, CARG2, d0\n  |.endif\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  andpl CARG2, CARG2, #0x80000000\t// |x| < 1? hi = sign(x), lo = 0.\n  |  movpl CARG1, #0\n  |.if hf == 1\n  |  vmovpl d0, CARG1, CARG2\n  |.endif\n  |  bxpl lr\n  |  mvn CARG4, #0x3cc\n  |  subs RB, CARG4, RB, asr #21\t// 2^0: RB = 51, 2^51: RB = 0.\n  |  bxlo lr\t\t\t\t// |x| >= 2^52: already done.\n  |  mvn CARG4, #1\n  |  and CARG1, CARG1, CARG4, lsl RB\t// lo &= lomask\n  |  subs RB, RB, #32\n  |  andpl CARG2, CARG2, CARG4, lsl RB\t// |x| <= 2^20: hi &= himask\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |.endif\n  |.endmacro\n  |\n  |->vm_trunc:\n  |.if HFABI\n  |  vm_trunc 1\n  |.endif\n  |->vm_trunc_sf:\n  |  vm_trunc 0\n  |\n  |  // double lj_vm_mod(double dividend, double divisor);\n  |->vm_mod:\n  |.if FPU\n  |  // Special calling convention. Also, RC (r11) is not preserved.\n  |  vdiv.f64 d0, d6, d7\n  |   mov RC, lr\n  |  vmov CARG1, CARG2, d0\n  |  bl ->vm_floor_sf\n  |  vmov d0, CARG1, CARG2\n  |  vmul.f64 d0, d0, d7\n  |   mov lr, RC\n  |  vsub.f64 d6, d6, d0\n  |  bx lr\n  |.else\n  |  push {r0, r1, r2, r3, r4, lr}\n  |  bl extern __aeabi_ddiv\n  |  bl ->vm_floor_sf\n  |  ldrd CARG34, [sp, #8]\n  |  bl extern __aeabi_dmul\n  |  ldrd CARG34, [sp]\n  |  eor CARG2, CARG2, #0x80000000\n  |  bl extern __aeabi_dadd\n  |  add sp, sp, #20\n  |  pop {pc}\n  |.endif\n  |\n  |  // int lj_vm_modi(int dividend, int divisor);\n  |->vm_modi:\n  |  ands RB, CARG1, #0x80000000\n  |  rsbmi CARG1, CARG1, #0\t\t// a = |dividend|\n  |  eor RB, RB, CARG2, asr #1\t\t// Keep signdiff and sign(divisor).\n  |  cmp CARG2, #0\n  |  rsbmi CARG2, CARG2, #0\t\t// b = |divisor|\n  |  subs CARG4, CARG2, #1\n  |  cmpne CARG1, CARG2\n  |  moveq CARG1, #0\t\t\t// if (b == 1 || a == b) a = 0\n  |  tsthi CARG2, CARG4\n  |  andeq CARG1, CARG1, CARG4\t\t// else if ((b & (b-1)) == 0) a &= b-1\n  |  bls >1\n  |  // Use repeated subtraction to get the remainder.\n  |  clz CARG3, CARG1\n  |  clz CARG4, CARG2\n  |  sub CARG4, CARG4, CARG3\n  |  rsbs CARG3, CARG4, #31\t\t// entry = (31-(clz(b)-clz(a)))*8\n  |  addne pc, pc, CARG3, lsl #3\t// Duff's device.\n  |  nop\n  {\n    int i;\n    for (i = 31; i >= 0; i--) {\n      |  cmp CARG1, CARG2, lsl #i\n      |  subhs CARG1, CARG1, CARG2, lsl #i\n    }\n  }\n  |1:\n  |  cmp CARG1, #0\n  |  cmpne RB, #0\n  |  submi CARG1, CARG1, CARG2\t\t// if (y != 0 && signdiff) y = y - b\n  |  eors CARG2, CARG1, RB, lsl #1\n  |  rsbmi CARG1, CARG1, #0\t\t// if (sign(divisor) != sign(y)) y = -y\n  |  bx lr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions.\n  |// Saveregs already performed. Callback slot number in [sp], g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  ldr CTSTATE, GL:r12->ctype_state\n  |   add DISPATCH, r12, #GG_G2DISP\n  |.if FPU\n  |  str r4, SAVE_R4\n  |  add r4, sp, CFRAME_SPACE+4+8*8\n  |  vstmdb r4!, {d8-d15}\n  |.endif\n  |.if HFABI\n  |  add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])\n  |.endif\n  |  strd CARG34, CTSTATE->cb.gpr[2]\n  |  strd CARG12, CTSTATE->cb.gpr[0]\n  |.if HFABI\n  |  vstmdb r12!, {d0-d7}\n  |.endif\n  |  ldr CARG4, [sp]\n  |   add CARG3, sp, #CFRAME_SIZE\n  |    mov CARG1, CTSTATE\n  |  lsr CARG4, CARG4, #3\n  |   str CARG3, CTSTATE->cb.stack\n  |    mov CARG2, sp\n  |  str CARG4, CTSTATE->cb.slot\n  |  str CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  ldr BASE, L:CRET1->base\n  |    mv_vmstate CARG2, INTERP\n  |  ldr RC, L:CRET1->top\n  |    mov MASKR8, #255\n  |   ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |    mov L, CRET1\n  |  sub RC, RC, BASE\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |    st_vmstate CARG2\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]\n  |   str BASE, L->base\n  |   str CARG4, L->top\n  |  str L, CTSTATE->L\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RA\n  |  bl extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  ldrd CARG12, CTSTATE->cb.gpr[0]\n  |.if HFABI\n  |  vldr d0, CTSTATE->cb.fpr[0]\n  |.endif\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, r4\n  |  push {CCSTATE, r5, r11, lr}\n  |  mov CCSTATE, CARG1\n  |  ldr CARG1, CCSTATE:CARG1->spadj\n  |   ldrb CARG2, CCSTATE->nsp\n  |    add CARG3, CCSTATE, #offsetof(CCallState, stack)\n  |.if HFABI\n  |  add RB, CCSTATE, #offsetof(CCallState, fpr[0])\n  |.endif\n  |  mov r11, sp\n  |  sub sp, sp, CARG1\t\t\t// Readjust stack.\n  |   subs CARG2, CARG2, #1\n  |.if HFABI\n  |  vldm RB, {d0-d7}\n  |.endif\n  |    ldr RB, CCSTATE->func\n  |   bmi >2\n  |1:  // Copy stack slots.\n  |  ldr CARG4, [CARG3, CARG2, lsl #2]\n  |  str CARG4, [sp, CARG2, lsl #2]\n  |  subs CARG2, CARG2, #1\n  |  bpl <1\n  |2:\n  |  ldrd CARG12, CCSTATE->gpr[0]\n  |  ldrd CARG34, CCSTATE->gpr[2]\n  |  blx RB\n  |  mov sp, r11\n  |.if HFABI\n  |  add r12, CCSTATE, #offsetof(CCallState, fpr[4])\n  |.endif\n  |  strd CRET1, CCSTATE->gpr[0]\n  |.if HFABI\n  |  vstmdb r12!, {d0-d3}\n  |.endif\n  |  pop {CCSTATE, r5, r11, pc}\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RC = src2, JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, BASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TISNUM\n    |  bne >3\n    |  checktp CARG4, LJ_TISNUM\n    |  bne >4\n    |  cmp CARG1, CARG3\n    if (op == BC_ISLT) {\n      |  sublt PC, RB, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subge PC, RB, #0x20000\n    } else if (op == BC_ISLE) {\n      |  suble PC, RB, #0x20000\n    } else {\n      |  subgt PC, RB, #0x20000\n    }\n    |1:\n    |  ins_next\n    |\n    |3: // CARG12 is not an integer.\n    |.if FPU\n    |   vldr d0, [RA]\n    |  bhi ->vmeta_comp\n    |  // d0 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |   vldr d1, [RC]\n    |  blo >5\n    |  bhi ->vmeta_comp\n    |  // d0 is a number, CARG3 is an integer.\n    |  vmov s4, CARG3\n    |  vcvt.f64.s32 d1, s4\n    |  b >5\n    |4:  // CARG1 is an integer, CARG34 is not an integer.\n    |   vldr d1, [RC]\n    |  bhi ->vmeta_comp\n    |  // CARG1 is an integer, d1 is a number.\n    |  vmov s4, CARG1\n    |  vcvt.f64.s32 d0, s4\n    |5:  // d0 and d1 are numbers.\n    |  vcmp.f64 d0, d1\n    |  vmrs\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  sublo PC, RB, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subhs PC, RB, #0x20000\n    } else if (op == BC_ISLE) {\n      |  subls PC, RB, #0x20000\n    } else {\n      |  subhi PC, RB, #0x20000\n    }\n    |  b <1\n    |.else\n    |  bhi ->vmeta_comp\n    |  // CARG12 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |  movlo RA, RB\t\t\t// Save RB.\n    |  blo >5\n    |  bhi ->vmeta_comp\n    |  // CARG12 is a number, CARG3 is an integer.\n    |  mov CARG1, CARG3\n    |  mov RC, RA\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  mov CARG3, CARG1\n    |  mov CARG4, CARG2\n    |  ldrd CARG12, [RC]\t\t// Restore first operand.\n    |  b >5\n    |4:  // CARG1 is an integer, CARG34 is not an integer.\n    |  bhi ->vmeta_comp\n    |  // CARG1 is an integer, CARG34 is a number.\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  ldrd CARG34, [RC]\t\t// Restore second operand.\n    |5:  // CARG12 and CARG34 are numbers.\n    |  bl extern __aeabi_cdcmple\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  sublo PC, RA, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subhs PC, RA, #0x20000\n    } else if (op == BC_ISLE) {\n      |  subls PC, RA, #0x20000\n    } else {\n      |  subhi PC, RA, #0x20000\n    }\n    |  b <1\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RC = src2, JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, BASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TISNUM\n    |  cmnls CARG4, #-LJ_TISNUM\n    if (vk) {\n      |  bls ->BC_ISEQN_Z\n    } else {\n      |  bls ->BC_ISNEN_Z\n    }\n    |  // Either or both types are not numbers.\n    |.if FFI\n    |  checktp CARG2, LJ_TCDATA\n    |  checktpne CARG4, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG2, CARG4\t\t\t// Compare types.\n    |  bne >2\t\t\t\t// Not the same type?\n    |  checktp CARG2, LJ_TISPRI\n    |  bhs >1\t\t\t\t// Same type and primitive type?\n    |\n    |  // Same types and not a primitive type. Compare GCobj or pvalue.\n    |  cmp CARG1, CARG3\n    if (vk) {\n      |  bne >3\t\t\t\t// Different GCobjs or pvalues?\n      |1:  // Branch if same.\n      |  sub PC, RB, #0x20000\n      |2:  // Different.\n      |  ins_next\n      |3:\n      |  checktp CARG2, LJ_TISTABUD\n      |  bhi <2\t\t\t\t// Different objects and not table/ud?\n    } else {\n      |  beq >1\t\t\t\t// Same GCobjs or pvalues?\n      |  checktp CARG2, LJ_TISTABUD\n      |  bhi >2\t\t\t\t// Different objects and not table/ud?\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    if (vk) {\n      |  beq <2\t\t\t// No metatable?\n    } else {\n      |  beq >2\t\t\t// No metatable?\n    }\n    |  ldrb RA, TAB:RA->nomm\n    |   mov CARG4, #1-vk\t\t// ne = 0 or 1.\n    |   mov CARG2, CARG1\n    |  tst RA, #1<<MM_eq\n    |  beq ->vmeta_equal\t\t// 'no __eq' flag not set?\n    if (vk) {\n      |  b <2\n    } else {\n      |2:  // Branch if different.\n      |  sub PC, RB, #0x20000\n      |1:  // Same.\n      |  ins_next\n    }\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RC = str_const (~), JMP with RC = target\n    |   mvn RC, RC\n    |  ldrd CARG12, [BASE, RA]\n    |    ldrh RB, [PC, #2]\n    |   ldr STR:CARG3, [KBASE, RC, lsl #2]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TSTR\n    |.if FFI\n    |  bne >7\n    |  cmp CARG1, CARG3\n    |.else\n    |  cmpeq CARG1, CARG3\n    |.endif\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n      |1:\n    } else {\n      |1:\n      |  subne PC, RB, #0x20000\n    }\n    |  ins_next\n    |\n    |.if FFI\n    |7:\n    |  checktp CARG2, LJ_TCDATA\n    |  bne <1\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RC = num_const (~), JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, KBASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  checktp CARG2, LJ_TISNUM\n    |  bne >3\n    |  checktp CARG4, LJ_TISNUM\n    |  bne >4\n    |  cmp CARG1, CARG3\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n      |1:\n    } else {\n      |1:\n      |  subne PC, RB, #0x20000\n    }\n    |2:\n    |  ins_next\n    |\n    |3:  // CARG12 is not an integer.\n    |.if FFI\n    |  bhi >7\n    |.else\n    if (!vk) {\n      |  subhi PC, RB, #0x20000\n    }\n    |  bhi <2\n    |.endif\n    |.if FPU\n    |  checktp CARG4, LJ_TISNUM\n    |  vmov s4, CARG3\n    |   vldr d0, [RA]\n    |  vldrlo d1, [RC]\n    |  vcvths.f64.s32 d1, s4\n    |  b >5\n    |4:  // CARG1 is an integer, d1 is a number.\n    |  vmov s4, CARG1\n    |   vldr d1, [RC]\n    |  vcvt.f64.s32 d0, s4\n    |5:  // d0 and d1 are numbers.\n    |  vcmp.f64 d0, d1\n    |  vmrs\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n    } else {\n      |  subne PC, RB, #0x20000\n    }\n    |  b <2\n    |.else\n    |  // CARG12 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |  movlo RA, RB\t\t\t// Save RB.\n    |  blo >5\n    |  // CARG12 is a number, CARG3 is an integer.\n    |  mov CARG1, CARG3\n    |  mov RC, RA\n    |4:  // CARG1 is an integer, CARG34 is a number.\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  ldrd CARG34, [RC]\t\t// Restore other operand.\n    |5:  // CARG12 and CARG34 are numbers.\n    |  bl extern __aeabi_cdcmpeq\n    if (vk) {\n      |  subeq PC, RA, #0x20000\n    } else {\n      |  subne PC, RA, #0x20000\n    }\n    |  b <2\n    |.endif\n    |\n    |.if FFI\n    |7:\n    |  checktp CARG2, LJ_TCDATA\n    |  bne <1\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RC = primitive_type (~), JMP with RC = target\n    |  ldrd CARG12, [BASE, RA]\n    |   ldrh RB, [PC, #2]\n    |   add PC, PC, #4\n    |  mvn RC, RC\n    |   add RB, PC, RB, lsl #2\n    |.if FFI\n    |  checktp CARG2, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG2, RC\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n    } else {\n      |  subne PC, RB, #0x20000\n    }\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RC = src, JMP with RC = target\n    |  add RC, BASE, RC, lsl #3\n    |   ldrh RB, [PC, #2]\n    |  ldrd CARG12, [RC]\n    |   add PC, PC, #4\n    |   add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TTRUE\n    if (op == BC_ISTC || op == BC_IST) {\n      |  subls PC, RB, #0x20000\n      if (op == BC_ISTC) {\n\t|  strdls CARG12, [BASE, RA]\n      }\n    } else {\n      |  subhi PC, RB, #0x20000\n      if (op == BC_ISFC) {\n\t|  strdhi CARG12, [BASE, RA]\n      }\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RC = -type\n    |  ldrd CARG12, [BASE, RA]\n    |   ins_next1\n    |  cmn CARG2, RC\n    |   ins_next2\n    |  bne ->vmeta_istype\n    |   ins_next3\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RC = -(TISNUM-1)\n    |  ldrd CARG12, [BASE, RA]\n    |   ins_next1\n    |  checktp CARG2, LJ_TISNUM\n    |   ins_next2\n    |  bhs ->vmeta_istype\n    |   ins_next3\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |   ins_next1\n    |  ldrd CARG12, [BASE, RC]\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RC = src\n    |  add RC, BASE, RC, lsl #3\n    |   ins_next1\n    |  ldr CARG1, [RC, #4]\n    |   add RA, BASE, RA\n    |   ins_next2\n    |  checktp CARG1, LJ_TTRUE\n    |  mvnls CARG2, #~LJ_TFALSE\n    |  mvnhi CARG2, #~LJ_TTRUE\n    |  str CARG2, [RA, #4]\n    |   ins_next3\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |  ldrd CARG12, [BASE, RC]\n    |   ins_next1\n    |   ins_next2\n    |  checktp CARG2, LJ_TISNUM\n    |  bhi ->vmeta_unm\n    |  eorne CARG2, CARG2, #0x80000000\n    |  bne >5\n    |  rsbseq CARG1, CARG1, #0\n    |  ldrdvs CARG12, >9\n    |5:\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |\n    |.align 8\n    |9:\n    |  .long 0x00000000, 0x41e00000\t// 2^31.\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |  ldrd CARG12, [BASE, RC]\n    |  checkstr CARG2, >2\n    |  ldr CARG1, STR:CARG1->len\n    |1:\n    |  mvn CARG2, #~LJ_TISNUM\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |2:\n    |  checktab CARG2, ->vmeta_len\n#if LJ_52\n    |  ldr TAB:CARG3, TAB:CARG1->metatable\n    |  cmp TAB:CARG3, #0\n    |  bne >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  .IOS mov RC, BASE\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  .IOS mov BASE, RC\n    |  b <1\n#if LJ_52\n    |9:\n    |  ldrb CARG4, TAB:CARG3->nomm\n    |  tst CARG4, #1<<MM_len\n    |  bne <3\t\t\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithcheck, cond, ncond, target\n    ||if (vk == 1) {\n    |   cmn CARG4, #-LJ_TISNUM\n    |    cmn..cond CARG2, #-LJ_TISNUM\n    ||} else {\n    |   cmn CARG2, #-LJ_TISNUM\n    |    cmn..cond CARG4, #-LJ_TISNUM\n    ||}\n    |  b..ncond target\n    |.endmacro\n    |.macro ins_arithcheck_int, target\n    |  ins_arithcheck eq, ne, target\n    |.endmacro\n    |.macro ins_arithcheck_num, target\n    |  ins_arithcheck lo, hs, target\n    |.endmacro\n    |\n    |.macro ins_arithpre\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   .if FPU\n    |   ldrd CARG12, [RB, BASE]!\n    |    ldrd CARG34, [RC, KBASE]!\n    |   .else\n    |   ldrd CARG12, [BASE, RB]\n    |    ldrd CARG34, [KBASE, RC]\n    |   .endif\n    ||  break;\n    ||case 1:\n    |   .if FPU\n    |   ldrd CARG34, [RB, BASE]!\n    |    ldrd CARG12, [RC, KBASE]!\n    |   .else\n    |   ldrd CARG34, [BASE, RB]\n    |    ldrd CARG12, [KBASE, RC]\n    |   .endif\n    ||  break;\n    ||default:\n    |   .if FPU\n    |   ldrd CARG12, [RB, BASE]!\n    |    ldrd CARG34, [RC, BASE]!\n    |   .else\n    |   ldrd CARG12, [BASE, RB]\n    |    ldrd CARG34, [BASE, RC]\n    |   .endif\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithpre_fpu, reg1, reg2\n    |.if FPU\n    ||if (vk == 1) {\n    |  vldr reg2, [RB]\n    |  vldr reg1, [RC]\n    ||} else {\n    |  vldr reg1, [RB]\n    |  vldr reg2, [RC]\n    ||}\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithpost_fpu, reg\n    |   ins_next1\n    |  add RA, BASE, RA\n    |   ins_next2\n    |  vstr reg, [RA]\n    |   ins_next3\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins, fpcall\n    |  ins_arithpre\n    |.if \"intins\" ~= \"vm_modi\" and not FPU\n    |   ins_next1\n    |.endif\n    |  ins_arithcheck_int >5\n    |.if \"intins\" == \"smull\"\n    |  smull CARG1, RC, CARG3, CARG1\n    |  cmp RC, CARG1, asr #31\n    |  ins_arithfallback bne\n    |.elif \"intins\" == \"vm_modi\"\n    |  movs CARG2, CARG3\n    |  ins_arithfallback beq\n    |  bl ->vm_modi\n    |  mvn CARG2, #~LJ_TISNUM\n    |.else\n    |  intins CARG1, CARG1, CARG3\n    |  ins_arithfallback bvs\n    |.endif\n    |4:\n    |.if \"intins\" == \"vm_modi\" or FPU\n    |   ins_next1\n    |.endif\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |5:  // FP variant.\n    |  ins_arithpre_fpu d6, d7\n    |  ins_arithfallback ins_arithcheck_num\n    |.if FPU\n    |.if \"intins\" == \"vm_modi\"\n    |  bl fpcall\n    |.else\n    |  fpins d6, d6, d7\n    |.endif\n    |  ins_arithpost_fpu d6\n    |.else\n    |  bl fpcall\n    |.if \"intins\" ~= \"vm_modi\"\n    |  ins_next1\n    |.endif\n    |  b <4\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins, fpcall\n    |  ins_arithpre\n    |.if \"fpins\" ~= \"extern\" or HFABI\n    |  ins_arithpre_fpu d0, d1\n    |.endif\n    |  ins_arithfallback ins_arithcheck_num\n    |.if \"fpins\" == \"extern\"\n    |  .IOS mov RC, BASE\n    |  bl fpcall\n    |  .IOS mov BASE, RC\n    |.elif FPU\n    |  fpins d0, d0, d1\n    |.else\n    |  bl fpcall\n    |.endif\n    |.if (\"fpins\" ~= \"extern\" or HFABI) and FPU\n    |  ins_arithpost_fpu d0\n    |.else\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |.endif\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arithdn adds, vadd.f64, extern __aeabi_dadd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arithdn subs, vsub.f64, extern __aeabi_dsub\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arithdn smull, vmul.f64, extern __aeabi_dmul\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp vdiv.f64, extern __aeabi_ddiv\n    break;\n  case BC_MODVN: case BC_MODNV: case BC_MODVV:\n    |  ins_arithdn vm_modi, vm_mod, ->vm_mod\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  ins_arithfp extern, extern pow\n    break;\n\n  case BC_CAT:\n    |  decode_RB8 RC, INS\n    |   decode_RC8 RB, INS\n    |  // RA = dst*8, RC = src_start*8, RB = src_end*8  (note: RB/RC swapped!)\n    |  sub CARG3, RB, RC\n    |   str BASE, L->base\n    |  add CARG2, BASE, RB\n    |->BC_CAT_Z:\n    |  // RA = dst*8, RC = src_start*8, CARG2 = top-1\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  lsr CARG3, CARG3, #3\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  ldr BASE, L->base\n    |  cmp CRET1, #0\n    |  bne ->vmeta_binop\n    |  ldrd CARG34, [BASE, RC]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\t\t// Copy result to RA.\n    |   ins_next3\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RC = str_const (~)\n    |  mvn RC, RC\n    |   ins_next1\n    |  ldr CARG1, [KBASE, RC, lsl #2]\n    |  mvn CARG2, #~LJ_TSTR\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RC = cdata_const (~)\n    |  mvn RC, RC\n    |   ins_next1\n    |  ldr CARG1, [KBASE, RC, lsl #2]\n    |  mvn CARG2, #~LJ_TCDATA\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, (RC = int16_literal)\n    |  mov CARG1, INS, asr #16\t\t\t// Refetch sign-extended reg.\n    |  mvn CARG2, #~LJ_TISNUM\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RC = num_const\n    |  lsl RC, RC, #3\n    |   ins_next1\n    |  ldrd CARG12, [KBASE, RC]\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RC = primitive_type (~)\n    |  add RA, BASE, RA\n    |  mvn RC, RC\n    |   ins_next1\n    |   ins_next2\n    |  str RC, [RA, #4]\n    |   ins_next3\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RC = end\n    |  add RA, BASE, RA\n    |   add RC, BASE, RC, lsl #3\n    |  mvn CARG1, #~LJ_TNIL\n    |  str CARG1, [RA, #4]\n    |   add RA, RA, #8\n    |1:\n    |  str CARG1, [RA, #4]\n    |  cmp RA, RC\n    |   add RA, RA, #8\n    |  blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RC = uvnum\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsl RC, RC, #2\n    |   add RC, RC, #offsetof(GCfuncL, uvptr)\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RC]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |  ldrd CARG34, [CARG2]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RC = src\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    lsl RC, RC, #3\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldrd CARG34, [BASE, RC]\n    |  ldrb RB, UPVAL:CARG2->marked\n    |  ldrb RC, UPVAL:CARG2->closed\n    |    ldr CARG2, UPVAL:CARG2->v\n    |  tst RB, #LJ_GC_BLACK\t\t// isblack(uv)\n    |   add RB, CARG4, #-LJ_TISGCV\n    |  cmpne RC, #0\n    |   strd CARG34, [CARG2]\n    |  bne >2\t\t\t\t// Upvalue is closed and black?\n    |1:\n    |   ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  cmn RB, #-(LJ_TNUMX - LJ_TISGCV)\n    |   ldrbhi RC, GCOBJ:CARG3->gch.marked\n    |  bls <1\t\t\t\t// tvisgcv(v)\n    |    sub CARG1, DISPATCH, #-GG_DISP2G\n    |   tst RC, #LJ_GC_WHITES\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if IOS\n    |  beq <1\n    |  mov RC, BASE\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RC\n    |.else\n    |  blne extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.endif\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    mvn RC, RC\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldr STR:CARG3, [KBASE, RC, lsl #2]\n    |  ldrb RB, UPVAL:CARG2->marked\n    |     ldrb RC, UPVAL:CARG2->closed\n    |   ldr CARG2, UPVAL:CARG2->v\n    |    mvn CARG4, #~LJ_TSTR\n    |  tst RB, #LJ_GC_BLACK\t\t// isblack(uv)\n    |    ldrb RB, STR:CARG3->marked\n    |   strd CARG34, [CARG2]\n    |  bne >2\n    |1:\n    |   ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  tst RB, #LJ_GC_WHITES\t\t// iswhite(str)\n    |  cmpne RC, #0\n    |   sub CARG1, DISPATCH, #-GG_DISP2G\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if IOS\n    |  beq <1\n    |  mov RC, BASE\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RC\n    |.else\n    |  blne extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.endif\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RC = num_const\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    lsl RC, RC, #3\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldrd CARG34, [KBASE, RC]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [CARG2]\n    |   ins_next3\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RC = primitive_type (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |   mvn RC, RC\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   ins_next1\n    |   ins_next2\n    |  str RC, [CARG2, #4]\n    |   ins_next3\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RC = target\n    |  ldr CARG3, L->openupval\n    |   add RC, PC, RC, lsl #2\n    |   str BASE, L->base\n    |  cmp CARG3, #0\n    |   sub PC, RC, #0x20000\n    |  beq >1\n    |   mov CARG1, L\n    |   add CARG2, BASE, RA\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  ldr BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RC = proto_const (~) (holding function prototype)\n    |  mvn RC, RC\n    |   str BASE, L->base\n    |  ldr CARG2, [KBASE, RC, lsl #2]\n    |   str PC, SAVE_PC\n    |  ldr CARG3, [BASE, FRAME_FUNC]\n    |   mov CARG1, L\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  ldr BASE, L->base\n    |  mvn CARG2, #~LJ_TFUNC\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RC = (hbits|asize) | tab_const (~)\n    if (op == BC_TDUP) {\n      |  mvn RC, RC\n    }\n    |  ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]\n    |   ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]\n    |    str BASE, L->base\n    |    str PC, SAVE_PC\n    |  cmp CARG3, CARG4\n    |   mov CARG1, L\n    |  bhs >5\n    |1:\n    if (op == BC_TNEW) {\n      |  lsl CARG2, RC, #21\n      |   lsr CARG3, RC, #11\n      |  asr RC, CARG2, #21\n      |  lsr CARG2, CARG2, #21\n      |  cmn RC, #1\n      |  addeq CARG2, CARG2, #2\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns GCtab *.\n    } else {\n      |  ldr CARG2, [KBASE, RC, lsl #2]\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns GCtab *.\n    }\n    |  ldr BASE, L->base\n    |  mvn CARG2, #~LJ_TTAB\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |5:\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mov CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RC = str_const (~)\n  case BC_GSET:\n    |  // RA = dst*8, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   mvn RC, RC\n    |  ldr TAB:CARG1, LFUNC:CARG2->env\n    |   ldr STR:RC, [KBASE, RC, lsl #2]\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  ldrd TAB:CARG12, [BASE, RB]\n    |   ldrd CARG34, [BASE, RC]\n    |  checktab CARG2, ->vmeta_tgetv  // STALL: load CARG12.\n    |   checktp CARG4, LJ_TISNUM\t// Integer key?\n    |  ldreq CARG4, TAB:CARG1->array\n    |    ldreq CARG2, TAB:CARG1->asize\n    |   bne >9\n    |\n    |  add CARG4, CARG4, CARG3, lsl #3\n    |    cmp CARG3, CARG2\t\t// In array part?\n    |  ldrdlo CARG34, [CARG4]\n    |    bhs ->vmeta_tgetv\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  beq >5\n    |1:\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cmp TAB:CARG2, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG2->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  decode_RB8 RB, INS\t\t// Restore RB.\n    |  b ->vmeta_tgetv\n    |\n    |9:\n    |  checktp CARG4, LJ_TSTR\t\t// String key?\n    |   moveq STR:RC, CARG3\n    |  beq ->BC_TGETS_Z\n    |  b ->vmeta_tgetv\n    break;\n  case BC_TGETS:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst*8, RB = table*8, RC = str_const (~)\n    |  ldrd CARG12, [BASE, RB]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #2]  // STALL: early RC.\n    |  checktab CARG2, ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  ldr CARG3, TAB:CARG1->hmask\n    |   ldr CARG4, STR:RC->hash\n    |    ldr NODE:INS, TAB:CARG1->node\n    |     mov TAB:RB, TAB:CARG1\n    |  and CARG3, CARG3, CARG4\t\t\t// idx = str->hash & tab->hmask\n    |  add CARG3, CARG3, CARG3, lsl #1\n    |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n    |1:\n    |  ldrd CARG12, NODE:INS->key  // STALL: early NODE:INS.\n    |   ldrd CARG34, NODE:INS->val\n    |    ldr NODE:INS, NODE:INS->next\n    |  checktp CARG2, LJ_TSTR\n    |  cmpeq CARG1, STR:RC\n    |  bne >4\n    |   checktp CARG4, LJ_TNIL\n    |   beq >5\n    |3:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |4:  // Follow hash chain.\n    |  cmp NODE:INS, #0\n    |  bne <1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |   mov CARG3, #0  // Optional clear of undef. value (during load stall).\n    |   mvn CARG4, #~LJ_TNIL\n    |  cmp TAB:CARG1, #0\n    |  beq <3\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG1->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <3\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst*8, RB = table*8, RC = index\n    |  ldrd CARG12, [BASE, RB]\n    |  checktab CARG2, ->vmeta_tgetb  // STALL: load CARG12.\n    |   ldr CARG3, TAB:CARG1->asize\n    |  ldr CARG4, TAB:CARG1->array\n    |  lsl CARG2, RC, #3\n    |   cmp RC, CARG3\n    |  ldrdlo CARG34, [CARG4, CARG2]\n    |   bhs ->vmeta_tgetb\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  beq >5\n    |1:\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cmp TAB:CARG2, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG2->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\n    break;\n  case BC_TGETR:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  ldr TAB:CARG1, [BASE, RB]\n    |   ldr CARG2, [BASE, RC]\n    |  ldr CARG4, TAB:CARG1->array\n    |    ldr CARG3, TAB:CARG1->asize\n    |  add CARG4, CARG4, CARG2, lsl #3\n    |    cmp CARG2, CARG3\t\t// In array part?\n    |    bhs ->vmeta_tgetr\n    |  ldrd CARG12, [CARG4]\n    |->BC_TGETR_Z:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n\n  case BC_TSETV:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  ldrd TAB:CARG12, [BASE, RB]\n    |   ldrd CARG34, [BASE, RC]\n    |  checktab CARG2, ->vmeta_tsetv  // STALL: load CARG12.\n    |   checktp CARG4, LJ_TISNUM\t// Integer key?\n    |  ldreq CARG2, TAB:CARG1->array\n    |    ldreq CARG4, TAB:CARG1->asize\n    |   bne >9\n    |\n    |  add CARG2, CARG2, CARG3, lsl #3\n    |    cmp CARG3, CARG4\t\t// In array part?\n    |  ldrlo INS, [CARG2, #4]\n    |    bhs ->vmeta_tsetv\n    |   ins_next1  // Overwrites RB!\n    |  checktp INS, LJ_TNIL\n    |  ldrb INS, TAB:CARG1->marked\n    |   ldrd CARG34, [BASE, RA]\n    |  beq >5\n    |1:\n    |  tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |   strd CARG34, [CARG2]\n    |  bne >7\n    |2:\n    |   ins_next2\n    |   ins_next3\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb RA, TAB:RA->nomm\n    |  tst RA, #1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  ldr INS, [PC, #-4]\t\t// Restore RA and RB.\n    |  decode_RB8 RB, INS\n    |  decode_RA8 RA, INS\n    |  b ->vmeta_tsetv\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG1, INS, CARG3\n    |  b <2\n    |\n    |9:\n    |  checktp CARG4, LJ_TSTR\t\t// String key?\n    |   moveq STR:RC, CARG3\n    |  beq ->BC_TSETS_Z\n    |  b ->vmeta_tsetv\n    break;\n  case BC_TSETS:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = src*8, RB = table*8, RC = str_const (~)\n    |  ldrd CARG12, [BASE, RB]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #2]  // STALL: early RC.\n    |  checktab CARG2, ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  ldr CARG3, TAB:CARG1->hmask\n    |   ldr CARG4, STR:RC->hash\n    |    ldr NODE:INS, TAB:CARG1->node\n    |     mov TAB:RB, TAB:CARG1\n    |  and CARG3, CARG3, CARG4\t\t\t// idx = str->hash & tab->hmask\n    |  add CARG3, CARG3, CARG3, lsl #1\n    |   mov CARG4, #0\n    |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n    |   strb CARG4, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |1:\n    |  ldrd CARG12, NODE:INS->key\n    |   ldr CARG4, NODE:INS->val.it\n    |    ldr NODE:CARG3, NODE:INS->next\n    |  checktp CARG2, LJ_TSTR\n    |  cmpeq CARG1, STR:RC\n    |  bne >5\n    |  ldrb CARG2, TAB:RB->marked\n    |   checktp CARG4, LJ_TNIL\t\t// Key found, but nil value?\n    |    ldrd CARG34, [BASE, RA]\n    |   beq >4\n    |2:\n    |  tst CARG2, #LJ_GC_BLACK\t\t// isblack(table)\n    |    strd CARG34, NODE:INS->val\n    |  bne >7\n    |3:\n    |   ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |  cmp TAB:CARG1, #0\n    |  beq <2\t\t\t\t// No metatable: done.\n    |  ldrb CARG1, TAB:CARG1->nomm\n    |  tst CARG1, #1<<MM_newindex\n    |  bne <2\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  movs NODE:INS, NODE:CARG3\n    |  bne <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |   mov CARG3, TMPDp\n    |   str PC, SAVE_PC\n    |  cmp TAB:CARG1, #0\t\t// No metatable: continue.\n    |   str BASE, L->base\n    |  ldrbne CARG2, TAB:CARG1->nomm\n    |   mov CARG1, L\n    |  beq >6\n    |  tst CARG2, #1<<MM_newindex\n    |  beq ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mvn CARG4, #~LJ_TSTR\n    |   str STR:RC, TMPDlo\n    |   mov CARG2, TAB:RB\n    |  str CARG4, TMPDhi\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  ldr BASE, L->base\n    |  ldrd CARG34, [BASE, RA]\n    |  strd CARG34, [CRET1]\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, CARG2, CARG3\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = src*8, RB = table*8, RC = index\n    |  ldrd CARG12, [BASE, RB]\n    |  checktab CARG2, ->vmeta_tsetb  // STALL: load CARG12.\n    |   ldr CARG3, TAB:CARG1->asize\n    |  ldr RB, TAB:CARG1->array\n    |  lsl CARG2, RC, #3\n    |   cmp RC, CARG3\n    |  ldrdlo CARG34, [CARG2, RB]!\n    |   bhs ->vmeta_tsetb\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  ldrb INS, TAB:CARG1->marked\n    |   ldrd CARG34, [BASE, RA]\n    |  beq >5\n    |1:\n    |  tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |    strd CARG34, [CARG2]\n    |  bne >7\n    |2:\n    |   ins_next2\n    |   ins_next3\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb RA, TAB:RA->nomm\n    |  tst RA, #1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  ldr INS, [PC, #-4]\t\t// Restore INS.\n    |  decode_RA8 RA, INS\n    |  b ->vmeta_tsetb\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG1, INS, CARG3\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  ldr TAB:CARG2, [BASE, RB]\n    |   ldr CARG3, [BASE, RC]\n    |     ldrb INS, TAB:CARG2->marked\n    |  ldr CARG1, TAB:CARG2->array\n    |    ldr CARG4, TAB:CARG2->asize\n    |     tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |  add CARG1, CARG1, CARG3, lsl #3\n    |     bne >7\n    |2:\n    |    cmp CARG3, CARG4\t\t// In array part?\n    |    bhs ->vmeta_tsetr\n    |->BC_TSETR_Z:\n    |  ldrd CARG34, [BASE, RA]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [CARG1]\n    |   ins_next3\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, INS, RB\n    |  b <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RC = num_const (start index)\n    |  add RA, BASE, RA\n    |1:\n    |   ldr RB, SAVE_MULTRES\n    |  ldr TAB:CARG2, [RA, #-8]\t\t// Guaranteed to be a table.\n    |  ldr CARG1, [KBASE, RC, lsl #3]\t// Integer constant is in lo-word.\n    |   subs RB, RB, #8\n    |  ldr CARG4, TAB:CARG2->asize\n    |   beq >4\t\t\t\t// Nothing to copy?\n    |  add CARG3, CARG1, RB, lsr #3\n    |  cmp CARG3, CARG4\n    |   ldr CARG4, TAB:CARG2->array\n    |    add RB, RA, RB\n    |  bhi >5\n    |   add INS, CARG4, CARG1, lsl #3\n    |    ldrb CARG1, TAB:CARG2->marked\n    |3:  // Copy result slots to table.\n    |   ldrd CARG34, [RA], #8\n    |   strd CARG34, [INS], #8\n    |  cmp RA, RB\n    |  blo <3\n    |    tst CARG1, #LJ_GC_BLACK\t// isblack(table)\n    |    bne >7\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   str BASE, L->base\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  .IOS ldr BASE, L->base\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, CARG1, CARG3\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = nresults+1,) RC = extra_nargs\n    |  ldr CARG1, SAVE_MULTRES\n    |  decode_RC8 NARGS8:RC, INS\n    |  add NARGS8:RC, NARGS8:RC, CARG1\n    |  b ->BC_CALL_Z\n    break;\n  case BC_CALL:\n    |  decode_RC8 NARGS8:RC, INS\n    |  // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8\n    |->BC_CALL_Z:\n    |  mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  ldrd CARG34, [BASE, RA]!\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add BASE, BASE, #8\n    |  checkfunc CARG4, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs\n    |  ldr CARG1, SAVE_MULTRES\n    |  add NARGS8:RC, CARG1, RC, lsl #3\n    |  b ->BC_CALLT1_Z\n    break;\n  case BC_CALLT:\n    |  lsl NARGS8:RC, RC, #3\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |->BC_CALLT1_Z:\n    |  ldrd LFUNC:CARG34, [RA, BASE]!\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add RA, RA, #8\n    |  checkfunc CARG4, ->vmeta_callt\n    |  ldr PC, [BASE, FRAME_PC]\n    |->BC_CALLT2_Z:\n    |   mov RB, #0\n    |   ldrb CARG4, LFUNC:CARG3->ffid\n    |  tst PC, #FRAME_TYPE\n    |  bne >7\n    |1:\n    |  str LFUNC:CARG3, [BASE, FRAME_FUNC]  // Copy function down, but keep PC.\n    |  cmp NARGS8:RC, #0\n    |  beq >3\n    |2:\n    |  ldrd CARG12, [RA, RB]\n    |   add INS, RB, #8\n    |   cmp INS, NARGS8:RC\n    |  strd CARG12, [BASE, RB]\n    |    mov RB, INS\n    |   bne <2\n    |3:\n    |  cmp CARG4, #1\t\t\t// (> FF_C) Calling a fast function?\n    |  bhi >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  ldr INS, [PC, #-4]\n    |  decode_RA8 RA, INS\n    |  sub CARG1, BASE, RA\n    |  ldr LFUNC:CARG1, [CARG1, #-16]\n    |  ldr CARG1, LFUNC:CARG1->field_pc\n    |  ldr KBASE, [CARG1, #PC2PROTO(k)]\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  eor PC, PC, #FRAME_VARG\n    |  tst PC, #FRAME_TYPEP\t\t// Vararg frame below?\n    |  movne CARG4, #0\t\t\t// Clear ffid if no Lua function below.\n    |  bne <1\n    |  sub BASE, BASE, PC\n    |  ldr PC, [BASE, FRAME_PC]\n    |  tst PC, #FRAME_TYPE\n    |  movne CARG4, #0\t\t\t// Clear ffid if no Lua function below.\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA\n    |   mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  ldrd CARG34, [RA, #-16]\n    |   ldrd CARG12, [RA, #-8]\n    |    add BASE, RA, #8\n    |  strd CARG34, [RA, #8]\t\t// Copy state.\n    |   strd CARG12, [RA, #16]\t\t// Copy control var.\n    |  // STALL: locked CARG34.\n    |  ldrd LFUNC:CARG34, [RA, #-24]\n    |    mov NARGS8:RC, #16\t\t// Iterators get 2 arguments.\n    |  // STALL: load CARG34.\n    |  strd LFUNC:CARG34, [RA]\t\t// Copy callable.\n    |  checkfunc CARG4, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  add RA, BASE, RA\n    |  ldr TAB:RB, [RA, #-16]\n    |  ldr CARG1, [RA, #-8]\t\t// Get index from control var.\n    |  ldr INS, TAB:RB->asize\n    |   ldr CARG2, TAB:RB->array\n    |    add PC, PC, #4\n    |1:  // Traverse array part.\n    |  subs RC, CARG1, INS\n    |   add CARG3, CARG2, CARG1, lsl #3\n    |  bhs >5\t\t\t\t// Index points after array part?\n    |   ldrd CARG34, [CARG3]\n    |   checktp CARG4, LJ_TNIL\n    |   addeq CARG1, CARG1, #1\t\t// Skip holes in array part.\n    |   beq <1\n    |  ldrh RC, [PC, #-2]\n    |   mvn CARG2, #~LJ_TISNUM\n    |    strd CARG34, [RA, #8]\n    |  add RC, PC, RC, lsl #2\n    |    add RB, CARG1, #1\n    |   strd CARG12, [RA]\n    |  sub PC, RC, #0x20000\n    |    str RB, [RA, #-8]\t\t// Update control var.\n    |3:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  ldr CARG4, TAB:RB->hmask\n    |   ldr NODE:RB, TAB:RB->node\n    |6:\n    |   add CARG1, RC, RC, lsl #1\n    |  cmp RC, CARG4\t\t\t// End of iteration? Branch to ITERL+1.\n    |   add NODE:CARG3, NODE:RB, CARG1, lsl #3  // node = tab->node + idx*3*8\n    |  bhi <3\n    |   ldrd CARG12, NODE:CARG3->val\n    |   checktp CARG2, LJ_TNIL\n    |   add RC, RC, #1\n    |   beq <6\t\t\t\t// Skip holes in hash part.\n    |  ldrh RB, [PC, #-2]\n    |   add RC, RC, INS\n    |    ldrd CARG34, NODE:CARG3->key\n    |   str RC, [RA, #-8]\t\t// Update control var.\n    |   strd CARG12, [RA, #8]\n    |  add RC, PC, RB, lsl #2\n    |  sub PC, RC, #0x20000\n    |    strd CARG34, [RA]\n    |  b <3\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RC = target (points to ITERN)\n    |  add RA, BASE, RA\n    |     add RC, PC, RC, lsl #2\n    |  ldrd CFUNC:CARG12, [RA, #-24]\n    |   ldr CARG3, [RA, #-12]\n    |    ldr CARG4, [RA, #-4]\n    |  checktp CARG2, LJ_TFUNC\n    |  ldrbeq CARG1, CFUNC:CARG1->ffid\n    |   checktpeq CARG3, LJ_TTAB\n    |    checktpeq CARG4, LJ_TNIL\n    |  cmpeq CARG1, #FF_next_N\n    |     subeq PC, RC, #0x20000\n    |  bne >5\n    |   ins_next1\n    |   ins_next2\n    |  mov CARG1, #0\n    |  mvn CARG2, #0x00018000\n    |  strd CARG1, [RA, #-8]\t\t// Initialize control var.\n    |1:\n    |   ins_next3\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov CARG1, #BC_JMP\n    |   mov OP, #BC_ITERC\n    |  strb CARG1, [PC, #-4]\n    |   sub PC, RC, #0x20000\n    |   strb OP, [PC]\t\t\t// Subsumes ins_next1.\n    |   ins_next2\n    |  b <1\n    break;\n\n  case BC_VARG:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  ldr CARG1, [BASE, FRAME_PC]\n    |  add RC, BASE, RC\n    |   add RA, BASE, RA\n    |  add RC, RC, #FRAME_VARG\n    |   add CARG4, RA, RB\n    |  sub CARG3, BASE, #8\t\t// CARG3 = vtop\n    |  sub RC, RC, CARG1\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  cmp RB, #0\n    |   sub CARG1, CARG3, RC\n    |  beq >5\t\t\t\t// Copy all varargs?\n    |   sub CARG4, CARG4, #16\n    |1:  // Copy vararg slots to destination slots.\n    |  cmp RC, CARG3\n    |  ldrdlo CARG12, [RC], #8\n    |  mvnhs CARG2, #~LJ_TNIL\n    |   cmp RA, CARG4\n    |  strd CARG12, [RA], #8\n    |   blo <1\n    |2:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  ldr CARG4, L->maxstack\n    |   cmp CARG1, #0\n    |   movle RB, #8\t\t\t// MULTRES = (0+1)*8\n    |   addgt RB, CARG1, #8\n    |  add CARG2, RA, CARG1\n    |   str RB, SAVE_MULTRES\n    |   ble <2\n    |  cmp CARG2, CARG4\n    |  bhi >7\n    |6:\n    |   ldrd CARG12, [RC], #8\n    |   strd CARG12, [RA], #8\n    |  cmp RC, CARG3\n    |  blo <6\n    |  b <2\n    |\n    |7:  // Grow stack for varargs.\n    |  lsr CARG2, CARG1, #3\n    |   str RA, L->top\n    |  mov CARG1, L\n    |   str BASE, L->base\n    |  sub RC, RC, BASE\t\t\t// Need delta, because BASE may change.\n    |   str PC, SAVE_PC\n    |  sub RA, RA, BASE\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  ldr BASE, L->base\n    |  add RA, BASE, RA\n    |  add RC, BASE, RC\n    |  sub CARG3, BASE, #8\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RC = extra results\n    |  ldr CARG1, SAVE_MULTRES\n    |   ldr PC, [BASE, FRAME_PC]\n    |    add RA, BASE, RA\n    |  add RC, CARG1, RC, lsl #3\n    |  b ->BC_RETM_Z\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |    add RA, BASE, RA\n    |->BC_RETM_Z:\n    |   str RC, SAVE_MULTRES\n    |1:\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV2_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return\n    |  ldr INS, [PC, #-4]\n    |  subs CARG4, RC, #8\n    |   sub CARG3, BASE, #8\n    |  beq >3\n    |2:\n    |  ldrd CARG12, [RA], #8\n    |   add BASE, BASE, #8\n    |   subs CARG4, CARG4, #8\n    |  strd CARG12, [BASE, #-16]\n    |   bne <2\n    |3:\n    |  decode_RA8 RA, INS\n    |  sub CARG4, CARG3, RA\n    |   decode_RB8 RB, INS\n    |  ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]\n    |5:\n    |  cmp RB, RC\t\t\t// More results expected?\n    |  bhi >6\n    |  mov BASE, CARG4\n    |  ldr CARG2, LFUNC:CARG1->field_pc\n    |   ins_next1\n    |   ins_next2\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next3\n    |\n    |6:  // Fill up results with nil.\n    |  mvn CARG2, #~LJ_TNIL\n    |  add BASE, BASE, #8\n    |   add RC, RC, #8\n    |  str CARG2, [BASE, #-12]\n    |  b <5\n    |\n    |->BC_RETV1_Z:  // Non-standard return case.\n    |  add RA, BASE, RA\n    |->BC_RETV2_Z:\n    |  tst CARG2, #FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, CARG2\n    |  ldr PC, [BASE, FRAME_PC]\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |   str RC, SAVE_MULTRES\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |   ldreq INS, [PC, #-4]\n    |  bne ->BC_RETV1_Z\n    if (op == BC_RET1) {\n      |  ldrd CARG12, [BASE, RA]\n    }\n    |  sub CARG4, BASE, #8\n    |   decode_RA8 RA, INS\n    if (op == BC_RET1) {\n      |  strd CARG12, [CARG4]\n    }\n    |  sub BASE, CARG4, RA\n    |   decode_RB8 RB, INS\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |5:\n    |  cmp RB, RC\n    |  bhi >6\n    |  ldr CARG2, LFUNC:CARG1->field_pc\n    |   ins_next1\n    |   ins_next2\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next3\n    |\n    |6:  // Fill up results with nil.\n    |  sub CARG2, CARG4, #4\n    |  mvn CARG3, #~LJ_TNIL\n    |  str CARG3, [CARG2, RC]\n    |  add RC, RC, #8\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];      .define FOR_TIDX,  [RA, #4]\n  |.define FOR_STOP, [RA, #8];  .define FOR_TSTOP, [RA, #12]\n  |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]\n  |.define FOR_EXT,  [RA, #24]; .define FOR_TEXT,  [RA, #28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RC = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ldrd CARG12, [RA, BASE]!\n    if (op != BC_JFORL) {\n      |   add RC, PC, RC, lsl #2\n    }\n    if (!vk) {\n      |  ldrd CARG34, FOR_STOP\n      |   checktp CARG2, LJ_TISNUM\n      |  ldr RB, FOR_TSTEP\n      |   bne >5\n      |  checktp CARG4, LJ_TISNUM\n      |   ldr CARG4, FOR_STEP\n      |  checktpeq RB, LJ_TISNUM\n      |  bne ->vmeta_for\n      |  cmp CARG4, #0\n      |  blt >4\n      |  cmp CARG1, CARG3\n    } else {\n      |  ldrd CARG34, FOR_STEP\n      |   checktp CARG2, LJ_TISNUM\n      |   bne >5\n      |  adds CARG1, CARG1, CARG3\n      |   ldr CARG4, FOR_STOP\n      if (op == BC_IFORL) {\n\t|  addvs RC, PC, #0x20000\t\t// Overflow: prevent branch.\n      } else {\n\t|  bvs >2\t\t\t\t// Overflow: do not enter mcode.\n      }\n      |  cmp CARG3, #0\n      |  blt >4\n      |  cmp CARG1, CARG4\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  subgt PC, RC, #0x20000\n    } else if (op == BC_JFORI) {\n      |  sub PC, RC, #0x20000\n      |  ldrhle RC, [PC, #-2]\n    } else if (op == BC_IFORL) {\n      |  suble PC, RC, #0x20000\n    }\n    if (vk) {\n      |  strd CARG12, FOR_IDX\n    }\n    |2:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, FOR_EXT\n    if (op == BC_JFORI || op == BC_JFORL) {\n      |  ble =>BC_JLOOP\n    }\n    |3:\n    |   ins_next3\n    |\n    |4:  // Invert check for negative step.\n    if (!vk) {\n      |  cmp CARG3, CARG1\n    } else {\n      |  cmp CARG4, CARG1\n    }\n    |  b <1\n    |\n    |5:  // FP loop.\n    if (!vk) {\n      |  cmnlo CARG4, #-LJ_TISNUM\n      |  cmnlo RB, #-LJ_TISNUM\n      |  bhs ->vmeta_for\n      |.if FPU\n      |  vldr d0, FOR_IDX\n      |  vldr d1, FOR_STOP\n      |  cmp RB, #0\n      |  vstr d0, FOR_EXT\n      |.else\n      |  cmp RB, #0\n      |   strd CARG12, FOR_EXT\n      |  blt >8\n      |.endif\n    } else {\n      |.if FPU\n      |  vldr d0, FOR_IDX\n      |  vldr d2, FOR_STEP\n      |  vldr d1, FOR_STOP\n      |  cmp CARG4, #0\n      |  vadd.f64 d0, d0, d2\n      |.else\n      |  cmp CARG4, #0\n      |  blt >8\n      |  bl extern __aeabi_dadd\n      |   strd CARG12, FOR_IDX\n      |  ldrd CARG34, FOR_STOP\n      |   strd CARG12, FOR_EXT\n      |.endif\n    }\n    |6:\n    |.if FPU\n    |  vcmpge.f64 d0, d1\n    |  vcmplt.f64 d1, d0\n    |  vmrs\n    |.else\n    |  bl extern __aeabi_cdcmple\n    |.endif\n    if (vk) {\n      |.if FPU\n      |  vstr d0, FOR_IDX\n      |  vstr d0, FOR_EXT\n      |.endif\n    }\n    if (op == BC_FORI) {\n      |  subhi PC, RC, #0x20000\n    } else if (op == BC_JFORI) {\n      |  sub PC, RC, #0x20000\n      |  ldrhls RC, [PC, #-2]\n      |  bls =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  subls PC, RC, #0x20000\n    } else {\n      |  bls =>BC_JLOOP\n    }\n    |  ins_next1\n    |  ins_next2\n    |  b <3\n    |\n    |.if not FPU\n    |8:  // Invert check for negative step.\n    if (vk) {\n      |  bl extern __aeabi_dadd\n      |  strd CARG12, FOR_IDX\n      |  strd CARG12, FOR_EXT\n    }\n    |  mov CARG3, CARG1\n    |  mov CARG4, CARG2\n    |  ldrd CARG12, FOR_STOP\n    |  b <6\n    |.endif\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RC = target\n    |  ldrd CARG12, [RA, BASE]!\n    if (op == BC_JITERL) {\n      |  cmn CARG2, #-LJ_TNIL\t\t// Stop if iterator returned nil.\n      |  strdne CARG12, [RA, #-8]\n      |  bne =>BC_JLOOP\n    } else {\n      |   add RC, PC, RC, lsl #2\n      |  // STALL: load CARG12.\n      |  cmn CARG2, #-LJ_TNIL\t\t// Stop if iterator returned nil.\n      |  subne PC, RC, #0x20000\t\t// Otherwise save control var + branch.\n      |  strdne CARG12, [RA, #-8]\n    }\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RC = target (loop extent)\n    |  // Note: RA/RC is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RC = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base (ignored), RC = traceno\n    |  ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]\n    |   mov CARG2, #0  // Traces on ARM don't store the trace number, so use 0.\n    |  ldr TRACE:RC, [CARG1, RC, lsl #2]\n    |   st_vmstate CARG2\n    |  ldr RA, TRACE:RC->mcode\n    |   str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]\n    |   str L, [DISPATCH, #DISPATCH_GL(tmpbuf.L)]\n    |  bx RA\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RC = target\n    |  add RC, PC, RC, lsl #2\n    |  sub PC, RC, #0x20000\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |  bhi ->vm_growstack_l\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n      |  ins_next2\n    }\n    |2:\n    |  cmp NARGS8:RC, CARG2, lsl #3\t// Check for missing parameters.\n    |   mvn CARG4, #~LJ_TNIL\n    |  blo >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD RC, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next3\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  strd CARG34, [BASE, NARGS8:RC]\n    |  add NARGS8:RC, NARGS8:RC, #8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   add CARG4, BASE, RC\n    |  add RA, RA, RC\n    |   str LFUNC:CARG3, [CARG4]\t// Store copy of LFUNC.\n    |   add CARG2, RC, #8+FRAME_VARG\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |   str CARG2, [CARG4, #4]\t\t// Store delta + FRAME_VARG.\n    |  bhs ->vm_growstack_l\n    |  ldrb RB, [PC, #-4+PC2PROTO(numparams)]\n    |   mov RA, BASE\n    |   mov RC, CARG4\n    |  cmp RB, #0\n    |   add BASE, CARG4, #8\n    |  beq >3\n    |  mvn CARG3, #~LJ_TNIL\n    |1:\n    |  cmp RA, RC\t\t\t// Less args than parameters?\n    |   ldrdlo CARG12, [RA], #8\n    |   movhs CARG2, CARG3\n    |    strlo CARG3, [RA, #-4]\t\t// Clear old fixarg slot (help the GC).\n    |2:\n    |  subs RB, RB, #1\n    |   strd CARG12, [CARG4, #8]!\n    |  bne <1\n    |3:\n    |  ins_next\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  ldr CARG4, CFUNC:CARG3->f\n    } else {\n      |  ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]\n    }\n    |   add CARG2, RA, NARGS8:RC\n    |   ldr CARG1, L->maxstack\n    |  add RC, BASE, NARGS8:RC\n    |    str BASE, L->base\n    |   cmp CARG2, CARG1\n    |  str RC, L->top\n    if (op == BC_FUNCCW) {\n      |  ldr CARG2, CFUNC:CARG3->f\n    }\n    |    mv_vmstate CARG3, C\n    |  mov CARG1, L\n    |   bhi ->vm_growstack_c\t\t// Need to grow stack.\n    |    st_vmstate CARG3\n    |  blx CARG4\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  ldr BASE, L->base\n    |    mv_vmstate CARG3, INTERP\n    |   ldr CRET2, L->top\n    |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n    |   lsl RC, CRET1, #3\n    |    st_vmstate CARG3\n    |  ldr PC, [BASE, FRAME_PC]\n    |   sub RA, CRET2, RC\t\t// RA = L->top - nresults*8\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 0xe\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0xd\\n\\t.uleb128 0\\n\"\t/* def_cfa sp */\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 1\\n\",\t\t/* offset lr */\n\tfcofs, CFRAME_SIZE);\n    for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--)  /* offset r4-r11 */\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 2+(11-i));\n#if LJ_ARCH_HASFPU\n    for (i = 15; i >= 8; i--)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 %d, %d\\n\",\n\t64+2*i, 10+2*(15-i));\n    fprintf(ctx->fp, \"\\t.byte 0x84\\n\\t.uleb128 %d\\n\", 25);  /* offset r4 */\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long lj_vm_ffi_call\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 2\\n\"\t\t/* offset r11 */\n\t\"\\t.byte 0x85\\n\\t.uleb128 3\\n\"\t\t/* offset r5 */\n\t\"\\t.byte 0x84\\n\\t.uleb128 4\\n\"\t\t/* offset r4 */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xb\\n\"\t\t/* def_cfa_register r11 */\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_arm64.dasc",
    "content": "|// Low-level VM code for ARM64 CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch arm64\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// ARM64 registers and the AAPCS64 ABI 1.0 at a glance:\n|//\n|// x0-x17 temp, x19-x28 callee-saved, x29 fp, x30 lr\n|// x18 is reserved on most platforms. Don't use it, save it or restore it.\n|// x31 doesn't exist. Register number 31 either means xzr/wzr (zero) or sp,\n|// depending on the instruction.\n|// v0-v7 temp, v8-v15 callee-saved (only d8-d15 preserved), v16-v31 temp\n|//\n|// x0-x7/v0-v7 hold parameters and results.\n|\n|// Fixed register assignments for the interpreter.\n|\n|// The following must be C callee-save.\n|.define BASE,\t\tx19\t// Base of current Lua stack frame.\n|.define KBASE,\t\tx20\t// Constants of current Lua function.\n|.define PC,\t\tx21\t// Next PC.\n|.define GLREG,\t\tx22\t// Global state.\n|.define LREG,\t\tx23\t// Register holding lua_State (also in SAVE_L).\n|.define TISNUM,\tx24\t// Constant LJ_TISNUM << 47.\n|.define TISNUMhi,\tx25\t// Constant LJ_TISNUM << 15.\n|.define TISNIL,\tx26\t// Constant -1LL.\n|.define fp,\t\tx29\t// Yes, we have to maintain a frame pointer.\n|\n|.define ST_INTERP,\tw26\t// Constant -1.\n|\n|// The following temporaries are not saved across C calls, except for RA/RC.\n|.define RA,\t\tx27\n|.define RC,\t\tx28\n|.define RB,\t\tx17\n|.define RAw,\t\tw27\n|.define RCw,\t\tw28\n|.define RBw,\t\tw17\n|.define INS,\t\tx16\n|.define INSw,\t\tw16\n|.define ITYPE,\t\tx15\n|.define TMP0,\t\tx8\n|.define TMP1,\t\tx9\n|.define TMP2,\t\tx10\n|.define TMP3,\t\tx11\n|.define TMP0w,\t\tw8\n|.define TMP1w,\t\tw9\n|.define TMP2w,\t\tw10\n|.define TMP3w,\t\tw11\n|\n|// Calling conventions. Also used as temporaries.\n|.define CARG1,\t\tx0\n|.define CARG2,\t\tx1\n|.define CARG3,\t\tx2\n|.define CARG4,\t\tx3\n|.define CARG5,\t\tx4\n|.define CARG1w,\tw0\n|.define CARG2w,\tw1\n|.define CARG3w,\tw2\n|.define CARG4w,\tw3\n|.define CARG5w,\tw4\n|\n|.define FARG1,\t\td0\n|.define FARG2,\t\td1\n|\n|.define CRET1,\t\tx0\n|.define CRET1w,\tw0\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|\n|.define CFRAME_SPACE,\t208\n|//----- 16 byte aligned, <-- sp entering interpreter\n|// Unused\t\t[sp, #204]\t// 32 bit values\n|.define SAVE_NRES,\t[sp, #200]\n|.define SAVE_ERRF,\t[sp, #196]\n|.define SAVE_MULTRES,\t[sp, #192]\n|.define TMPD,\t\t[sp, #184]\t// 64 bit values\n|.define SAVE_L,\t[sp, #176]\n|.define SAVE_PC,\t[sp, #168]\n|.define SAVE_CFRAME,\t[sp, #160]\n|.define SAVE_FPR_,\t96\t\t// 96+8*8: 64 bit FPR saves\n|.define SAVE_GPR_,\t16\t\t// 16+10*8: 64 bit GPR saves\n|.define SAVE_LR,\t[sp, #8]\n|.define SAVE_FP,\t[sp]\n|//----- 16 byte aligned, <-- sp while in interpreter.\n|\n|.define TMPDofs,\t#184\n|\n|.macro save_, gpr1, gpr2, fpr1, fpr2\n|  stp d..fpr1, d..fpr2, [sp, # SAVE_FPR_+(fpr1-8)*8]\n|  stp x..gpr1, x..gpr2, [sp, # SAVE_GPR_+(gpr1-19)*8]\n|.endmacro\n|.macro rest_, gpr1, gpr2, fpr1, fpr2\n|  ldp d..fpr1, d..fpr2, [sp, # SAVE_FPR_+(fpr1-8)*8]\n|  ldp x..gpr1, x..gpr2, [sp, # SAVE_GPR_+(gpr1-19)*8]\n|.endmacro\n|\n|.macro saveregs\n|  stp fp, lr, [sp, #-CFRAME_SPACE]!\n|  add fp, sp, #0\n|  stp x19, x20, [sp, # SAVE_GPR_]\n|  save_ 21, 22, 8, 9\n|  save_ 23, 24, 10, 11\n|  save_ 25, 26, 12, 13\n|  save_ 27, 28, 14, 15\n|.endmacro\n|.macro restoreregs\n|  ldp x19, x20, [sp, # SAVE_GPR_]\n|  rest_ 21, 22, 8, 9\n|  rest_ 23, 24, 10, 11\n|  rest_ 25, 26, 12, 13\n|  rest_ 27, 28, 14, 15\n|  ldp fp, lr, [sp], # CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State,\tGLREG\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; brk; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_FUNC,\t#-16\n|.define FRAME_PC,\t#-8\n|\n|.macro decode_RA, dst, ins; ubfx dst, ins, #8, #8; .endmacro\n|.macro decode_RB, dst, ins; ubfx dst, ins, #24, #8; .endmacro\n|.macro decode_RC, dst, ins; ubfx dst, ins, #16, #8; .endmacro\n|.macro decode_RD, dst, ins; ubfx dst, ins, #16, #16; .endmacro\n|.macro decode_RC8RD, dst, src; ubfiz dst, src, #3, #8; .endmacro\n|\n|// Instruction decode+dispatch.\n|.macro ins_NEXT\n|  ldr INSw, [PC], #4\n|  add TMP1, GL, INS, uxtb #3\n|   decode_RA RA, INS\n|  ldr TMP0, [TMP1, #GG_G2DISP]\n|   decode_RD RC, INS\n|  br TMP0\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  ldr PC, LFUNC:CARG3->pc\n|  ldr INSw, [PC], #4\n|  add TMP1, GL, INS, uxtb #3\n|   decode_RA RA, INS\n|  ldr TMP0, [TMP1, #GG_G2DISP]\n|   add RA, BASE, RA, lsl #3\n|  br TMP0\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  str PC, [BASE, FRAME_PC]\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to check the TValue type and extract the GCobj. Branch on failure.\n|.macro checktp, reg, tp, target\n|  asr ITYPE, reg, #47\n|  cmn ITYPE, #-tp\n|   and reg, reg, #LJ_GCVMASK\n|  bne target\n|.endmacro\n|.macro checktp, dst, reg, tp, target\n|  asr ITYPE, reg, #47\n|  cmn ITYPE, #-tp\n|   and dst, reg, #LJ_GCVMASK\n|  bne target\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC, target; .endmacro\n|.macro checkint, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  bne target\n|.endmacro\n|.macro checknum, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  bls target\n|.endmacro\n|.macro checknumber, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  blo target\n|.endmacro\n|\n|.macro mov_false, reg; movn reg, #0x8000, lsl #32; .endmacro\n|.macro mov_true, reg; movn reg, #0x0001, lsl #48; .endmacro\n|\n#define GL_J(field)\t(GG_OFS(J) + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta\n|  NYI\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP\n|  blo ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL\n|  blo ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro mv_vmstate, reg, st; movn reg, #LJ_VMST_..st; .endmacro\n|.macro st_vmstate, reg; str reg, GL->vmstate; .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  ldr tmp, GL->gc.grayagain\n|   and mark, mark, #~LJ_GC_BLACK\t// black2gray(tab)\n|  str tab, GL->gc.grayagain\n|   strb mark, tab->marked\n|  str tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n#if !LJ_DUALNUM\n#error \"Only dual-number mode supported for ARM64 target\"\n#endif\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: RB = previous base.\n  |  tbz PC, #2, ->cont_dispatch\t// (PC & FRAME_P) == 0?\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  ldr PC, [RB, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   mov_true TMP0\n  |  mov BASE, RB\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   str TMP0, [RA, #-8]!\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  adds RC, RC, #8\t\t\t// RC = (nresults+1)*8.\n  |  mov CRET1, #LUA_YIELD\n  |  beq ->vm_unwind_c_eh\n  |  str RCw, SAVE_MULTRES\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return\n  |  // CARG1 = PC & FRAME_TYPE\n  |  and RB, PC, #~FRAME_TYPEP\n  |   cmp CARG1, #FRAME_C\n  |  sub RB, BASE, RB\t\t\t// RB = previous base.\n  |   bne ->vm_returnp\n  |\n  |  str RB, L->base\n  |   ldrsw CARG2, SAVE_NRES\t\t// CARG2 = nresults+1.\n  |    mv_vmstate TMP0w, C\n  |   sub BASE, BASE, #16\n  |  subs TMP2, RC, #8\n  |    st_vmstate TMP0w\n  |  beq >2\n  |1:\n  |  subs TMP2, TMP2, #8\n  |   ldr TMP0, [RA], #8\n  |   str TMP0, [BASE], #8\n  |  bne <1\n  |2:\n  |  cmp RC, CARG2, lsl #3\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  str BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  ldr RC, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   mov CRET1, #0\t\t\t// Ok return status for vm_pcall.\n  |  str RC, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  bgt >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  ldr CARG3, L->maxstack\n  |  cmp BASE, CARG3\n  |  bhs >8\n  |   str TISNIL, [BASE], #8\n  |  add RC, RC, #8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  cbz CARG2, <3\t\t\t// LUA_MULTRET+1 case?\n  |  sub CARG1, RC, CARG2, lsl #3\n  |  sub BASE, BASE, CARG1\t\t// Shrink top.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  str BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |  mov CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  ldrsw CARG2, SAVE_NRES\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov sp, CARG1\n  |  mov CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mv_vmstate TMP0w, C\n  |  ldr GL, L->glref\n  |   st_vmstate TMP0w\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  and sp, CARG1, #CFRAME_RAWMASK\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |    movn TISNIL, #0\n  |    mov RC, #16\t\t\t// 2 results: false + error message.\n  |  ldr BASE, L->base\n  |   ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |    mov_false TMP0\n  |  sub RA, BASE, #8\t\t\t// Results start at BASE-8.\n  |  ldr PC, [BASE, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |    str TMP0, [BASE, #-8]\t\t// Prepend false to error message.\n  |   st_vmstate ST_INTERP\n  |  b ->vm_returnc\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  // CARG1 = L\n  |  mov CARG2, #LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |    mov CARG1, L\n  |  stp BASE, RC, L->base\n  |   add PC, PC, #4\t\t\t// Must point after first instruction.\n  |   lsr CARG2, RA, #3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  str PC, SAVE_PC\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldp BASE, RC, L->base\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, RC, BASE\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L, CARG1\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |  mov BASE, CARG2\n  |   str L, SAVE_L\n  |  mov PC, #FRAME_CP\n  |   str wzr, SAVE_NRES\n  |    add TMP0, sp, #CFRAME_RESUME\n  |  ldrb TMP1w, L->status\n  |   str wzr, SAVE_ERRF\n  |   str L, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   str xzr, SAVE_CFRAME\n  |    str TMP0, L->cframe\n  |  cbz TMP1w, >3\n  |\n  |  // Resume after yield (like a return).\n  |  str L, GL->cur_L\n  |  mov RA, BASE\n  |   ldp BASE, CARG1, L->base\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |  ldr PC, [BASE, FRAME_PC]\n  |     strb wzr, L->status\n  |    movn TISNIL, #0\n  |   sub RC, CARG1, BASE\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   add RC, RC, #8\n  |     st_vmstate ST_INTERP\n  |   str RCw, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, #FRAME_CP\n  |  str CARG4w, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, #FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  ldr RC, L:CARG1->cframe\n  |   str CARG3w, SAVE_NRES\n  |    mov L, CARG1\n  |   str CARG1, SAVE_L\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |     mov BASE, CARG2\n  |   str CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  str RC, SAVE_CFRAME\n  |  str fp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  str L, GL->cur_L\n  |  ldp RB, CARG1, L->base\t\t// RB = old base (for vmeta_call).\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |  add PC, PC, BASE\n  |    movn TISNIL, #0\n  |  sub PC, PC, RB\t\t\t// PC = frame delta + frame type\n  |   sub NARGS8:RC, CARG1, BASE\n  |    st_vmstate ST_INTERP\n  |\n  |->vm_call_dispatch:\n  |  // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  ldr CARG3, [BASE, FRAME_FUNC]\n  |  checkfunc CARG3, ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L, CARG1\n  |   ldr RA, L:CARG1->stack\n  |  str CARG1, SAVE_L\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |   ldr RB, L->top\n  |  str CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  ldr RC, L->cframe\n  |   sub RA, RA, RB\t\t\t// Compute -savestack(L, L->top).\n  |   str RAw, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  str wzr, SAVE_ERRF\t\t\t// No error function.\n  |  str RC, SAVE_CFRAME\n  |  str fp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |    str L, GL->cur_L\n  |  blr CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  mov BASE, CRET1\n  |   mov PC, #FRAME_CP\n  |  cbnz BASE, <3\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RC = (nresults+1)*8\n  |  ldr LFUNC:CARG3, [RB, FRAME_FUNC]\n  |    ldr CARG1, [BASE, #-32]\t\t// Get continuation.\n  |   mov CARG4, BASE\n  |   mov BASE, RB\t\t\t// Restore caller BASE.\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |.if FFI\n  |    cmp CARG1, #1\n  |.endif\n  |   ldr PC, [CARG4, #-24]\t\t// Restore PC from [cont|PC].\n  |  ldr CARG3, LFUNC:CARG3->pc\n  |    add TMP0, RA, RC\n  |    str TISNIL, [TMP0, #-8]\t\t// Ensure one valid arg.\n  |.if FFI\n  |    bls >1\n  |.endif\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  // BASE = base, RA = resultptr, CARG4 = meta base\n  |    br CARG1\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |   sub CARG4, CARG4, #32\n  |   sub RC, CARG4, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, CARG4 = meta base\n  |  ldr INSw, [PC, #-4]\n  |   sub CARG2, CARG4, #32\n  |   ldr TMP0, [RA]\n  |     str BASE, L->base\n  |  decode_RB RB, INS\n  |   decode_RA RA, INS\n  |  add TMP1, BASE, RB, lsl #3\n  |  subs TMP1, CARG2, TMP1\n  |  beq >1\n  |   str TMP0, [CARG2]\n  |  lsr CARG3, TMP1, #3\n  |  b ->BC_CAT_Z\n  |\n  |1:\n  |   str TMP0, [BASE, RA, lsl #3]\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  movn CARG4, #~LJ_TSTR\n  |   add CARG2, BASE, RB, lsl #3\n  |  add CARG4, STR:RC, CARG4, lsl #47\n  |  b >2\n  |\n  |->vmeta_tgets:\n  |  movk CARG2, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  str CARG2, GL->tmptv\n  |  add CARG2, GL, #offsetof(global_State, tmptv)\n  |2:\n  |   add CARG3, sp, TMPDofs\n  |  str CARG4, TMPD\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// RB = table, RC = index\n  |  add RC, RC, TISNUM\n  |   add CARG2, BASE, RB, lsl #3\n  |   add CARG3, sp, TMPDofs\n  |  str RC, TMPD\n  |  b >1\n  |\n  |->vmeta_tgetv:\t\t\t// RB = table, RC = key\n  |  add CARG2, BASE, RB, lsl #3\n  |   add CARG3, BASE, RC, lsl #3\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cbz CRET1, >3\n  |  ldr TMP0, [CRET1]\n  |  str TMP0, [BASE, RA, lsl #3]\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |   sub TMP1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(t, k).\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |    str PC, [BASE, #-24]\t\t// [cont|PC]\n  |   sub PC, BASE, TMP1\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  sxtw CARG2, TMP1w\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  mov TMP0, TISNIL\n  |  cbz CRET1, ->BC_TGETR_Z\n  |  ldr TMP0, [CRET1]\n  |  b ->BC_TGETR_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  movn CARG4, #~LJ_TSTR\n  |   add CARG2, BASE, RB, lsl #3\n  |  add CARG4, STR:RC, CARG4, lsl #47\n  |  b >2\n  |\n  |->vmeta_tsets:\n  |  movk CARG2, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  str CARG2, GL->tmptv\n  |  add CARG2, GL, #offsetof(global_State, tmptv)\n  |2:\n  |   add CARG3, sp, TMPDofs\n  |  str CARG4, TMPD\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// RB = table, RC = index\n  |  add RC, RC, TISNUM\n  |   add CARG2, BASE, RB, lsl #3\n  |   add CARG3, sp, TMPDofs\n  |  str RC, TMPD\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  add CARG2, BASE, RB, lsl #3\n  |   add CARG3, BASE, RC, lsl #3\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |   ldr TMP0, [BASE, RA, lsl #3]\n  |  cbz CRET1, >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |   str TMP0, [CRET1]\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |   sub TMP1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #24\t\t// 3 args for func(t, k, v).\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   str TMP0, [BASE, #16]\t\t// Copy value to third argument.\n  |    str PC, [BASE, #-24]\t\t// [cont|PC]\n  |   sub PC, BASE, TMP1\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  sxtw CARG3, TMP1w\n  |  str BASE, L->base\n  |  str PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |  b ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  add CARG2, BASE, RA, lsl #3\n  |   sub PC, PC, #4\n  |  add CARG3, BASE, RC, lsl #3\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  uxtb CARG4w, INSw\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  cmp CRET1, #1\n  |  bhi ->vmeta_binop\n  |4:\n  |   ldrh RBw, [PC, #2]\n  |    add PC, PC, #4\n  |   add RB, PC, RB, lsl #2\n  |   sub RB, RB, #0x20000\n  |  csel PC, PC, RB, lo\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  ldr INSw, [PC, #-4]\n  |   ldr TMP0, [RA]\n  |  decode_RA TMP1, INS\n  |   str TMP0, [BASE, TMP1, lsl #3]\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  ldr TMP0, [RA]\n  |   mov_true TMP1\n  |  cmp TMP1, TMP0\t\t\t// Branch if result is true.\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  ldr TMP0, [RA]\n  |   mov_false TMP1\n  |  cmp TMP0, TMP1\t\t\t// Branch if result is false.\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  and TAB:CARG3, CARG3, #LJ_GCVMASK\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, INS\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, RA\n  |   mov CARG3, RC\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vn:\n  |  add CARG3, BASE, RB, lsl #3\n  |   add CARG4, KBASE, RC, lsl #3\n  |  b >1\n  |\n  |->vmeta_arith_nv:\n  |  add CARG4, BASE, RB, lsl #3\n  |   add CARG3, KBASE, RC, lsl #3\n  |  b >1\n  |\n  |->vmeta_unm:\n  |  add CARG3, BASE, RC, lsl #3\n  |  mov CARG4, CARG3\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  add CARG3, BASE, RB, lsl #3\n  |   add CARG4, BASE, RC, lsl #3\n  |1:\n  |  uxtb CARG5w, INSw\n  |   add CARG2, BASE, RA, lsl #3\n  |    str BASE, L->base\n  |   mov CARG1, L\n  |    str PC, SAVE_PC\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  cbz CRET1, ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub TMP1, CRET1, BASE\n  |   str PC, [CRET1, #-24]\t\t// [cont|PC]\n  |  add PC, TMP1, #FRAME_CONT\n  |  mov BASE, CRET1\n  |   mov NARGS8:RC, #16\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  add CARG2, BASE, RC, lsl #3\n#if LJ_52\n  |  mov TAB:RC, TAB:CARG1\t\t// Save table (ignored for other types).\n#endif\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  cbnz CRET1, ->vmeta_binop\t\t// Binop call for compatibility.\n  |  mov TAB:CARG1, TAB:RC\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // RB = old base, BASE = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str RB, L->base\t\t\t// This is the callers base!\n  |  sub CARG2, BASE, #16\n  |   str PC, SAVE_PC\n  |  add CARG3, BASE, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  sub CARG2, RA, #16\n  |   str PC, SAVE_PC\n  |  add CARG3, RA, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  ldr TMP1, [RA, FRAME_FUNC]\t\t// Guaranteed to be a function here.\n  |   ldr PC, [BASE, FRAME_PC]\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  and LFUNC:CARG3, TMP1, #LJ_GCVMASK\n  |  b ->BC_CALLT2_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, RA\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  ldr INSw, [PC, #-4]\n  |.if JIT\n  |   uxtb TMP0, INS\n  |.endif\n  |  decode_RA RA, INS\n  |  decode_RD RC, INS\n  |.if JIT\n  |   cmp TMP0, #BC_JFORI\n  |   beq =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  ldp CARG1, CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc name\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr FARG1, [BASE]\n  |   blo ->fff_fallback\n  |  checknum CARG1, ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc name\n  |  ldp CARG1, CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |  ldp FARG1, FARG2, [BASE]\n  |   blo ->fff_fallback\n  |  checknum CARG1, ->fff_fallback\n  |  checknum CARG2, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.\n  |.macro ffgccheck\n  |  ldp CARG1, CARG2, GL->gc.total\t// Assumes threshold follows total.\n  |  cmp CARG1, CARG2\n  |  blt >1\n  |  bl ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |   ldr PC, [BASE, FRAME_PC]\n  |  mov_false TMP1\n  |  cmp CARG1, TMP1\n  |  bhs ->fff_fallback\n  |  str CARG1, [BASE, #-16]\n  |  sub RB, BASE, #8\n  |  subs RA, NARGS8:RC, #8\n  |   add RC, NARGS8:RC, #8\t\t// Compute (nresults+1)*8.\n  |  cbz RA, ->fff_res\t\t\t// Done if exactly 1 argument.\n  |1:\n  |   ldr CARG1, [RB, #16]\n  |  sub RA, RA, #8\n  |   str CARG1, [RB], #8\n  |  cbnz RA, <1\n  |  b ->fff_res\n  |\n  |.ffunc_1 type\n  |  mov TMP0, #~LJ_TISNUM\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #~LJ_TISNUM\n  |  csinv TMP1, TMP0, ITYPE, lo\n  |  add TMP1, TMP1, #offsetof(GCfuncC, upvalue)/8\n  |  ldr CARG1, [CFUNC:CARG3, TMP1, lsl #3]\n  |  b ->fff_restv\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #-LJ_TTAB\n  |  ccmn ITYPE, #-LJ_TUDATA, #4, ne\n  |   and TAB:CARG1, CARG1, #LJ_GCVMASK\n  |  bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  ldr TAB:RB, TAB:CARG1->metatable\n  |2:\n  |   mov CARG1, TISNIL\n  |   ldr STR:RC, GL->gcroot[GCROOT_MMNAME+MM_metatable]\n  |  cbz TAB:RB, ->fff_restv\n  |  ldr TMP1w, TAB:RB->hmask\n  |   ldr TMP2w, STR:RC->hash\n  |    ldr NODE:CARG3, TAB:RB->node\n  |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->hash & tab->hmask\n  |  add TMP1, TMP1, TMP1, lsl #1\n  |  movn CARG4, #~LJ_TSTR\n  |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n  |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  ldp CARG1, TMP0, NODE:CARG3->val\n  |   ldr NODE:CARG3, NODE:CARG3->next\n  |  cmp TMP0, CARG4\n  |  beq >5\n  |  cbnz NODE:CARG3, <3\n  |4:\n  |  mov CARG1, RB\t\t\t// Use metatable as default result.\n  |  movk CARG1, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  b ->fff_restv\n  |5:\n  |  cmp TMP0, TISNIL\n  |  bne ->fff_restv\n  |  b <4\n  |\n  |6:\n  |  movn TMP0, #~LJ_TISNUM\n  |  cmp ITYPE, TMP0\n  |  csel ITYPE, ITYPE, TMP0, hs\n  |  sub TMP1, GL, ITYPE, lsl #3\n  |  ldr TAB:RB, [TMP1, #offsetof(global_State, gcroot[GCROOT_BASEMT])-8]\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n  |   ldr TAB:TMP0, TAB:TMP1->metatable\n  |  asr ITYPE, CARG2, #47\n  |   ldrb TMP2w, TAB:TMP1->marked\n  |  cmn ITYPE, #-LJ_TTAB\n  |    and TAB:CARG2, CARG2, #LJ_GCVMASK\n  |  ccmp TAB:TMP0, #0, #0, eq\n  |  bne ->fff_fallback\n  |    str TAB:CARG2, TAB:TMP1->metatable\n  |   tbz TMP2w, #2, ->fff_restv\t// isblack(table)\n  |  barrierback TAB:TMP1, TMP2w, TMP0\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  ldr CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  checktab CARG2, ->fff_fallback\n  |   mov CARG1, L\n  |   add CARG3, BASE, #8\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |  ldr CARG1, [CRET1]\n  |  b ->fff_restv\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   bne ->fff_fallback\n  |  checknumber CARG1, ->fff_fallback\n  |  b ->fff_restv\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #-LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  ldr TMP1, GL->gcroot[GCROOT_BASEMT_NUM]\n  |   str BASE, L->base\n  |  cmn ITYPE, #-LJ_TISNUM\n  |  ccmp TMP1, #0, #0, ls\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  bne ->fff_fallback\n  |  ffgccheck\n  |  mov CARG1, L\n  |  mov CARG2, BASE\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |  // Returns GCstr *.\n  |   movn TMP1, #~LJ_TSTR\n  |  ldr BASE, L->base\n  |   add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  checktp CARG2, CARG1, LJ_TTAB, ->fff_fallback\n  |  str TISNIL, [BASE, NARGS8:RC]\t// Set missing 2nd arg to nil.\n  |  ldr PC, [BASE, FRAME_PC]\n  |   stp BASE, BASE, L->base\t\t// Add frame since C call can throw.\n  |  mov CARG1, L\n  |  add CARG3, BASE, #8\n  |   str PC, SAVE_PC\n  |  bl extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Returns 0 at end of traversal.\n  |  str TISNIL, [BASE, #-16]\n  |  cbz CRET1, ->fff_res1\t\t// End of traversal: return nil.\n  |  ldp CARG1, CARG2, [BASE, #8]\t// Copy key and value to results.\n  |    mov RC, #(2+1)*8\n  |  stp CARG1, CARG2, [BASE, #-16]\n  |  b ->fff_res\n  |\n  |.ffunc_1 pairs\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:CARG2, TAB:TMP1->metatable\n#endif\n  |   ldr CFUNC:CARG4, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cbnz TAB:CARG2, ->fff_fallback\n#endif\n  |  mov RC, #(3+1)*8\n  |  stp CARG1, TISNIL, [BASE, #-8]\n  |   str CFUNC:CARG4, [BASE, #-16]\n  |  b ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  checktab CARG1, ->fff_fallback\n  |   checkint CARG2, ->fff_fallback\n  |  ldr TMP1w, TAB:CARG1->asize\n  |   ldr CARG3, TAB:CARG1->array\n  |    ldr TMP0w, TAB:CARG1->hmask\n  |  add CARG2w, CARG2w, #1\n  |  cmp CARG2w, TMP1w\n  |    ldr PC, [BASE, FRAME_PC]\n  |     add TMP2, CARG2, TISNUM\n  |   mov RC, #(0+1)*8\n  |     str TMP2, [BASE, #-16]\n  |  bhs >2\t\t\t\t// Not in array part?\n  |  ldr TMP0, [CARG3, CARG2, lsl #3]\n  |1:\n  |   mov TMP1, #(2+1)*8\n  |   cmp TMP0, TISNIL\n  |  str TMP0, [BASE, #-8]\n  |   csel RC, RC, TMP1, eq\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cbz TMP0w, ->fff_res\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cbz CRET1, ->fff_res\n  |  ldr TMP0, [CRET1]\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:CARG2, TAB:TMP1->metatable\n#endif\n  |   ldr CFUNC:CARG4, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cbnz TAB:CARG2, ->fff_fallback\n#endif\n  |  mov RC, #(3+1)*8\n  |  stp CARG1, TISNUM, [BASE, #-8]\n  |   str CFUNC:CARG4, [BASE, #-16]\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  ldrb TMP0w, GL->hookmask\n  |   subs NARGS8:RC, NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |    mov RB, BASE\n  |    add BASE, BASE, #16\n  |  ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1\n  |  add PC, TMP0, #16+FRAME_PCALL\n  |   beq ->vm_call_dispatch\n  |1:\n  |   add TMP2, BASE, NARGS8:RC\n  |2:\n  |   ldr TMP0, [TMP2, #-16]\n  |   str TMP0, [TMP2, #-8]!\n  |  cmp TMP2, BASE\n  |  bne <2\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc xpcall\n  |     ldp CARG1, CARG2, [BASE]\n  |  ldrb TMP0w, GL->hookmask\n  |   subs NARGS8:RC, NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |    mov RB, BASE\n  |    add BASE, BASE, #24\n  |     asr ITYPE, CARG2, #47\n  |  ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1\n  |     cmn ITYPE, #-LJ_TFUNC\n  |  add PC, TMP0, #24+FRAME_PCALL\n  |     bne ->fff_fallback\t\t// Traceback must be a function.\n  |     stp CARG2, CARG1, [RB]\t\t// Swap function and traceback.\n  |   cbz NARGS8:RC, ->vm_call_dispatch\n  |  b <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  checktp CARG1, LJ_TTHREAD, ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr\n  |  and L:CARG1, CARG1, #LJ_GCVMASK\n  |.endif\n  |   ldr PC, [BASE, FRAME_PC]\n  |     str BASE, L->base\n  |  ldp RB, CARG2, L:CARG1->base\n  |   ldrb TMP1w, L:CARG1->status\n  |  add TMP0, CARG2, TMP1\n  |   str PC, SAVE_PC\n  |  cmp TMP0, RB\n  |  beq ->fff_fallback\n  |   cmp TMP1, #LUA_YIELD\n  |    add TMP0, CARG2, #8\n  |   csel CARG2, CARG2, TMP0, hs\n  |   ldr CARG4, L:CARG1->maxstack\n  |   add CARG3, CARG2, NARGS8:RC\n  |    ldr RB, L:CARG1->cframe\n  |   ccmp CARG3, CARG4, #2, ls\n  |    ccmp RB, #0, #2, ls\n  |    bhi ->fff_fallback\n  |.if resume\n  |  sub CARG3, CARG3, #8\t\t// Keep resumed thread in stack for GC.\n  |  add BASE, BASE, #8\n  |  sub NARGS8:RC, NARGS8:RC, #8\n  |.endif\n  |  str CARG3, L:CARG1->top\n  |  str BASE, L->top\n  |  cbz NARGS8:RC, >3\n  |2:  // Move args to coroutine.\n  |   ldr TMP0, [BASE, RB]\n  |  cmp RB, NARGS8:RC\n  |   str TMP0, [CARG2, RB]\n  |   add RB, RB, #8\n  |  bne <2\n  |3:\n  |  mov CARG3, #0\n  |   mov L:RA, L:CARG1\n  |  mov CARG4, #0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  ldp CARG3, CARG4, L:RA->base\n  |   cmp CRET1, #LUA_YIELD\n  |  ldr BASE, L->base\n  |    str L, GL->cur_L\n  |    st_vmstate ST_INTERP\n  |   bhi >8\n  |  sub RC, CARG4, CARG3\n  |   ldr CARG1, L->maxstack\n  |   add CARG2, BASE, RC\n  |  cbz RC, >6\t\t\t\t// No results?\n  |  cmp CARG2, CARG1\n  |   mov RB, #0\n  |  bhi >9\t\t\t\t// Need to grow stack?\n  |\n  |  sub CARG4, RC, #8\n  |   str CARG3, L:RA->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |   ldr TMP0, [CARG3, RB]\n  |  cmp RB, CARG4\n  |   str TMP0, [BASE, RB]\n  |   add RB, RB, #8\n  |  bne <5\n  |6:\n  |.if resume\n  |  mov_true TMP1\n  |   add RC, RC, #16\n  |7:\n  |  str TMP1, [BASE, #-8]\t\t// Prepend true/false to results.\n  |   sub RA, BASE, #8\n  |.else\n  |   mov RA, BASE\n  |   add RC, RC, #8\n  |.endif\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str PC, SAVE_PC\n  |   str RCw, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  ldr TMP0, [CARG4, #-8]!\n  |   mov_false TMP1\n  |    mov RC, #(2+1)*8\n  |  str CARG4, L:RA->top\t\t// Remove error from coroutine stack.\n  |  str TMP0, [BASE]\t\t\t// Copy error message.\n  |  b <7\n  |.else\n  |  mov CARG1, L\n  |  mov CARG2, L:RA\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Never returns.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov CARG1, L\n  |  lsr CARG2, RC, #3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov CRET1, #0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  ldr TMP0, L->cframe\n  |   add TMP1, BASE, NARGS8:RC\n  |    mov CRET1, #LUA_YIELD\n  |   stp BASE, TMP1, L->base\n  |  tbz TMP0, #0, ->fff_fallback\n  |   str xzr, L->cframe\n  |    strb CRET1w, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.macro math_round, func, round\n  |  .ffunc math_ .. func\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr d0, [BASE]\n  |   blo ->fff_fallback\n  |  cmp TISNUMhi, CARG1, lsr #32\n  |  beq ->fff_restv\n  |  blo ->fff_fallback\n  |  round d0, d0\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |  math_round floor, frintm\n  |  math_round ceil, frintp\n  |\n  |.ffunc_1 math_abs\n  |  checknumber CARG1, ->fff_fallback\n  |  and CARG1, CARG1, #U64x(7fffffff,ffffffff)\n  |  bne ->fff_restv\n  |  eor CARG2w, CARG1w, CARG1w, asr #31\n  |   movz CARG3, #0x41e0, lsl #48\t// 2^31.\n  |  subs CARG1w, CARG2w, CARG1w, asr #31\n  |   add CARG1, CARG1, TISNUM\n  |  csel CARG1, CARG1, CARG3, pl\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG1 = TValue result.\n  |  ldr PC, [BASE, FRAME_PC]\n  |  str CARG1, [BASE, #-16]\n  |->fff_res1:\n  |  // PC = return.\n  |  mov RC, #(1+1)*8\n  |->fff_res:\n  |  // RC = (nresults+1)*8, PC = return.\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str RCw, SAVE_MULTRES\n  |   sub RA, BASE, #16\n  |  bne ->vm_return\n  |  ldr INSw, [PC, #-4]\n  |  decode_RB RB, INS\n  |5:\n  |  cmp RC, RB, lsl #3\t\t\t// More results expected?\n  |  blo >6\n  |  decode_RA TMP1, INS\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  sub BASE, RA, TMP1, lsl #3\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  add TMP1, RA, RC\n  |   add RC, RC, #8\n  |  str TISNIL, [TMP1, #-8]\n  |  b <5\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  bl extern func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  bl extern func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.ffunc_n math_sqrt\n  |  fsqrt d0, d0\n  |->fff_resn:\n  |  ldr PC, [BASE, FRAME_PC]\n  |  str d0, [BASE, #-16]\n  |  b ->fff_res1\n  |\n  |.ffunc math_log\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr FARG1, [BASE]\n  |   bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |  checknum CARG1, ->fff_fallback\n  |  bl extern log\n  |  b ->fff_resn\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_2 math_ldexp\n  |  ldr FARG1, [BASE]\n  |  checknum CARG1, ->fff_fallback\n  |  checkint CARG2, ->fff_fallback\n  |  sxtw CARG1, CARG2w\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  b ->fff_resn\n  |\n  |.ffunc_n math_frexp\n  |  add CARG1, sp, TMPDofs\n  |  bl extern frexp\n  |   ldr CARG2w, TMPD\n  |    ldr PC, [BASE, FRAME_PC]\n  |  str d0, [BASE, #-16]\n  |    mov RC, #(2+1)*8\n  |   add CARG2, CARG2, TISNUM\n  |   str CARG2, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.ffunc_n math_modf\n  |  sub CARG1, BASE, #16\n  |   ldr PC, [BASE, FRAME_PC]\n  |  bl extern modf\n  |   mov RC, #(2+1)*8\n  |  str d0, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.macro math_minmax, name, cond, fcond\n  |  .ffunc_1 name\n  |   add RB, BASE, RC\n  |   add RA, BASE, #8\n  |  checkint CARG1, >4\n  |1:  // Handle integers.\n  |  ldr CARG2, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_restv\n  |  checkint CARG2, >3\n  |  cmp CARG1w, CARG2w\n  |   add RA, RA, #8\n  |  csel CARG1, CARG2, CARG1, cond\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  scvtf d0, CARG1w\n  |  blo ->fff_fallback\n  |  ldr d1, [RA]\n  |  b >6\n  |\n  |4:\n  |  ldr d0, [BASE]\n  |  blo ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldr CARG2, [RA]\n  |  ldr d1, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_resn\n  |  checknum CARG2, >7\n  |6:\n  |  fcmp d0, d1\n  |   add RA, RA, #8\n  |  fcsel d0, d1, d0, fcond\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  scvtf d1, CARG2w\n  |  blo ->fff_fallback\n  |  b <6\n  |.endmacro\n  |\n  |  math_minmax math_min, gt, hi\n  |  math_minmax math_max, lt, lo\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  ldp PC, CARG1, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\n  |  asr ITYPE, CARG1, #47\n  |  ccmn ITYPE, #-LJ_TSTR, #0, eq\n  |   and STR:CARG1, CARG1, #LJ_GCVMASK\n  |  bne ->fff_fallback\n  |  ldrb TMP0w, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   ldr CARG3w, STR:CARG1->len\n  |  add TMP0, TMP0, TISNUM\n  |  str TMP0, [BASE, #-16]\n  |  mov RC, #(0+1)*8\n  |   cbz CARG3, ->fff_res\n  |  b ->fff_res1\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  ldp PC, CARG1, [BASE, FRAME_PC]\n  |  cmp CARG1w, #255\n  |   ccmp NARGS8:RC, #8, #0, ls\t\t// Need exactly 1 argument.\n  |  bne ->fff_fallback\n  |  checkint CARG1, ->fff_fallback\n  |  mov CARG3, #1\n  |  mov CARG2, BASE\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  // CARG2 = str, CARG3 = len.\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |   movn TMP1, #~LJ_TSTR\n  |  add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  ldr CARG1, [BASE]\n  |    ldr CARG3, [BASE, #16]\n  |   cmp NARGS8:RC, #16\n  |    movn RB, #0\n  |   beq >1\n  |   blo ->fff_fallback\n  |    checkint CARG3, ->fff_fallback\n  |    sxtw RB, CARG3w\n  |1:\n  |  ldr CARG2, [BASE, #8]\n  |  checkstr CARG1, ->fff_fallback\n  |   ldr TMP1w, STR:CARG1->len\n  |  checkint CARG2, ->fff_fallback\n  |  sxtw CARG2, CARG2w\n  |  // CARG1 = str, TMP1 = str->len, CARG2 = start, RB = end\n  |   add TMP2, RB, TMP1\n  |   cmp RB, #0\n  |  add TMP0, CARG2, TMP1\n  |   csinc RB, RB, TMP2, ge\t\t// if (end < 0) end += len+1\n  |  cmp CARG2, #0\n  |  csinc CARG2, CARG2, TMP0, ge\t// if (start < 0) start += len+1\n  |   cmp RB, #0\n  |   csel RB, RB, xzr, ge\t\t// if (end < 0) end = 0\n  |  cmp CARG2, #1\n  |  csinc CARG2, CARG2, xzr, ge\t// if (start < 1) start = 1\n  |   cmp RB, TMP1\n  |   csel RB, RB, TMP1, le\t\t// if (end > len) end = len\n  |  add CARG1, STR:CARG1, #sizeof(GCstr)-1\n  |   subs CARG3, RB, CARG2\t\t// len = end - start\n  |  add CARG2, CARG1, CARG2\n  |   add CARG3, CARG3, #1\t\t// len += 1\n  |   bge ->fff_newstr\n  |  add STR:CARG1, GL, #offsetof(global_State, strempty)\n  |   movn TMP1, #~LJ_TSTR\n  |  add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  ldr CARG2, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  asr ITYPE, CARG2, #47\n  |  ccmn ITYPE, #-LJ_TSTR, #0, hs\n  |   and STR:CARG2, CARG2, #LJ_GCVMASK\n  |  bne ->fff_fallback\n  |  ldr TMP0, GL->tmpbuf.b\n  |   add SBUF:CARG1, GL, #offsetof(global_State, tmpbuf)\n  |   str BASE, L->base\n  |   str PC, SAVE_PC\n  |   str L, GL->tmpbuf.L\n  |  str TMP0, GL->tmpbuf.p\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |// FP number to bit conversion for soft-float. Clobbers CARG1-CARG3\n  |->vm_tobit_fb:\n  |  bls ->fff_fallback\n  |  add CARG2, CARG1, CARG1\n  |  mov CARG3, #1076\n  |  sub CARG3, CARG3, CARG2, lsr #53\n  |  cmp CARG3, #53\n  |  bhi >1\n  |  and CARG2, CARG2, #U64x(001fffff,ffffffff)\n  |  orr CARG2, CARG2, #U64x(00200000,00000000)\n  |   cmp CARG1, #0\n  |  lsr CARG2, CARG2, CARG3\n  |   cneg CARG1w, CARG2w, mi\n  |  br lr\n  |1:\n  |  mov CARG1w, #0\n  |  br lr\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  adr lr, >1\n  |  checkint CARG1, ->vm_tobit_fb\n  |1:\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  mov RA, #8\n  |  mov TMP0w, CARG1w\n  |  adr lr, >2\n  |1:\n  |  ldr CARG1, [BASE, RA]\n  |   cmp RA, NARGS8:RC\n  |    add RA, RA, #8\n  |   bge >9\n  |  checkint CARG1, ->vm_tobit_fb\n  |2:\n  |  ins TMP0w, TMP0w, CARG1w\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, orr\n  |.ffunc_bit_op bxor, eor\n  |\n  |.ffunc_bit tobit\n  |  mov TMP0w, CARG1w\n  |9:  // Label reused by .ffunc_bit_op users.\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bswap\n  |  rev TMP0w, CARG1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bnot\n  |  mvn TMP0w, CARG1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc bit_..name\n  |  ldp TMP0, CARG1, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  adr lr, >1\n  |  checkint CARG1, ->vm_tobit_fb\n  |1:\n  |.if shmod == 0\n  |  mov TMP1, CARG1\n  |.else\n  |  neg TMP1, CARG1\n  |.endif\n  |  mov CARG1, TMP0\n  |  adr lr, >2\n  |  checkint CARG1, ->vm_tobit_fb\n  |2:\n  |  ins TMP0w, CARG1w, TMP1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, lsl, 0\n  |.ffunc_bit_sh rshift, lsr, 0\n  |.ffunc_bit_sh arshift, asr, 0\n  |.ffunc_bit_sh rol, ror, 1\n  |.ffunc_bit_sh ror, ror, 0\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RC = nargs*8\n  |   ldp CFUNC:CARG3, PC, [BASE, FRAME_FUNC]\t// Fallback may overwrite PC.\n  |  ldr TMP2, L->maxstack\n  |  add TMP1, BASE, NARGS8:RC\n  |  stp BASE, TMP1, L->base\n  |   and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  add TMP1, TMP1, #8*LUA_MINSTACK\n  |   ldr CARG3, CFUNC:CARG3->f\n  |    str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  cmp TMP1, TMP2\n  |   mov CARG1, L\n  |  bhi >5\t\t\t\t// Need to grow stack.\n  |   blr CARG3\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |   ldr BASE, L->base\n  |  cmp CRET1w, #0\n  |   lsl RC, CRET1, #3\n  |   sub RA, BASE, #16\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |   ldr CARG1, L->top\n  |    ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, CARG1, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |    and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  ands TMP0, PC, #FRAME_TYPE\n  |   and TMP1, PC, #~FRAME_TYPEP\n  |  bne >3\n  |  ldrb RAw, [PC, #-3]\n  |  lsl RA, RA, #3\n  |  add TMP1, RA, #16\n  |3:\n  |  sub RB, BASE, TMP1\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2, #LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |  cmp CARG1, CARG1\t\t\t// Set zero-flag to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |   add CARG2, BASE, NARGS8:RC\t// Calculate L->top.\n  |  mov RA, lr\n  |   stp BASE, CARG2, L->base\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  mov CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |  ldp BASE, CARG2, L->base\n  |   ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  mov lr, RA\t\t\t\t// Help return address predictor.\n  |  sub NARGS8:RC, CARG2, BASE\t\t// Calculate nargs*8.\n  |   and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |  NYI\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  ldrb TMP2w, GL->hookmask\n  |  tbz TMP2w, #HOOK_ACTIVE_SHIFT, >1\t// Hook already active?\n  |5:  // Re-dispatch to static ins.\n  |  ldr TMP0, [TMP1, #GG_G2DISP+GG_DISP2STATIC]\n  |  br TMP0\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  ldrb TMP2w, GL->hookmask\n  |   ldr TMP3w, GL->hookcount\n  |  tbnz TMP2w, #HOOK_ACTIVE_SHIFT, <5\t// Hook already active?\n  |  tst TMP2w, #LUA_MASKLINE|LUA_MASKCOUNT\n  |  beq <5\n  |   sub TMP3w, TMP3w, #1\n  |   str TMP3w, GL->hookcount\n  |   cbz TMP3w, >1\n  |  tbz TMP2w, #LUA_HOOKLINE, <5\n  |1:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  ldr BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  ldr INSw, [PC, #-4]\n  |  add TMP1, GL, INS, uxtb #3\n  |   decode_RA RA, INS\n  |  ldr TMP0, [TMP1, #GG_G2DISP+GG_DISP2STATIC]\n  |   decode_RD RC, INS\n  |  br TMP0\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  ldr CARG1, [CARG4, #-40]\n  |   add PC, PC, #4\n  |  str CARG1w, SAVE_MULTRES\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |  NYI\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  orr CARG2, PC, #1\n  |1:\n  |.endif\n  |  add TMP1, BASE, NARGS8:RC\n  |   str PC, SAVE_PC\n  |   mov CARG1, L\n  |   sub RA, RA, BASE\n  |  stp BASE, TMP1, L->base\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  ldp BASE, TMP1, L->base\n  |   str xzr, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  add RA, BASE, RA\n  |  sub NARGS8:RC, TMP1, BASE\n  |   ldr INSw, [PC, #-4]\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  br CRET1\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |  NYI\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  ldr BASE, L->base\n  |  sub PC, PC, #4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_exit_handler:\n  |  NYI\n  |->vm_exit_interp:\n  |  NYI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |  // int lj_vm_modi(int dividend, int divisor);\n  |->vm_modi:\n  |    eor CARG4w, CARG1w, CARG2w\n  |    cmp CARG4w, #0\n  |  eor CARG3w, CARG1w, CARG1w, asr #31\n  |   eor CARG4w, CARG2w, CARG2w, asr #31\n  |  sub CARG3w, CARG3w, CARG1w, asr #31\n  |   sub CARG4w, CARG4w, CARG2w, asr #31\n  |  udiv CARG1w, CARG3w, CARG4w\n  |  msub CARG1w, CARG1w, CARG4w, CARG3w\n  |    ccmp CARG1w, #0, #4, mi\n  |    sub CARG3w, CARG1w, CARG4w\n  |    csel CARG1w, CARG1w, CARG3w, eq\n  |  eor CARG3w, CARG1w, CARG2w\n  |  cmp CARG3w, #0\n  |  cneg CARG1w, CARG1w, mi\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions.\n  |// Saveregs already performed. Callback slot number in [sp], g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  ldr CTSTATE, GL:x10->ctype_state\n  |  mov GL, x10\n  |    add x10, sp, # CFRAME_SPACE\n  |  str w9, CTSTATE->cb.slot\n  |  stp x0, x1, CTSTATE->cb.gpr[0]\n  |   stp d0, d1, CTSTATE->cb.fpr[0]\n  |  stp x2, x3, CTSTATE->cb.gpr[2]\n  |   stp d2, d3, CTSTATE->cb.fpr[2]\n  |  stp x4, x5, CTSTATE->cb.gpr[4]\n  |   stp d4, d5, CTSTATE->cb.fpr[4]\n  |  stp x6, x7, CTSTATE->cb.gpr[6]\n  |   stp d6, d7, CTSTATE->cb.fpr[6]\n  |    str x10, CTSTATE->cb.stack\n  |  mov CARG1, CTSTATE\n  |   str CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  mov CARG2, sp\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  ldp BASE, RC, L:CRET1->base\n  |   movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |   movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |   movn TISNIL, #0\n  |   mov L, CRET1\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  sub RC, RC, BASE\n  |   st_vmstate ST_INTERP\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  ldr CTSTATE, GL->ctype_state\n  |   stp BASE, CARG4, L->base\n  |  str L, CTSTATE->L\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RA\n  |  bl extern lj_ccallback_leave       // (CTState *cts, TValue *o)\n  |  ldp x0, x1, CTSTATE->cb.gpr[0]\n  |   ldp d0, d1, CTSTATE->cb.fpr[0]\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, x19\n  |  stp fp, lr, [sp, #-32]!\n  |  add fp, sp, #0\n  |  str CCSTATE, [sp, #16]\n  |  mov CCSTATE, x0\n  |  ldr TMP0w, CCSTATE:x0->spadj\n  |   ldrb TMP1w, CCSTATE->nsp\n  |    add TMP2, CCSTATE, #offsetof(CCallState, stack)\n  |   subs TMP1, TMP1, #1\n  |    ldr TMP3, CCSTATE->func\n  |  sub sp, fp, TMP0\n  |   bmi >2\n  |1:  // Copy stack slots\n  |  ldr TMP0, [TMP2, TMP1, lsl #3]\n  |  str TMP0, [sp, TMP1, lsl #3]\n  |  subs TMP1, TMP1, #1\n  |  bpl <1\n  |2:\n  |  ldp x0, x1, CCSTATE->gpr[0]\n  |   ldp d0, d1, CCSTATE->fpr[0]\n  |  ldp x2, x3, CCSTATE->gpr[2]\n  |   ldp d2, d3, CCSTATE->fpr[2]\n  |  ldp x4, x5, CCSTATE->gpr[4]\n  |   ldp d4, d5, CCSTATE->fpr[4]\n  |  ldp x6, x7, CCSTATE->gpr[6]\n  |   ldp d6, d7, CCSTATE->fpr[6]\n  |  ldr x8, CCSTATE->retp\n  |  blr TMP3\n  |  mov sp, fp\n  |  stp x0, x1, CCSTATE->gpr[0]\n  |   stp d0, d1, CCSTATE->fpr[0]\n  |   stp d2, d3, CCSTATE->fpr[2]\n  |  ldr CCSTATE, [sp, #16]\n  |  ldp fp, lr, [sp], #32\n  |  ret\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RC = src2, JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |    ldrh RBw, [PC, #2]\n    |   ldr CARG2, [BASE, RC, lsl #3]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    |  checkint CARG1, >3\n    |   checkint CARG2, >4\n    |  cmp CARG1w, CARG2w\n    if (op == BC_ISLT) {\n      |  csel PC, RB, PC, lt\n    } else if (op == BC_ISGE) {\n      |  csel PC, RB, PC, ge\n    } else if (op == BC_ISLE) {\n      |  csel PC, RB, PC, le\n    } else {\n      |  csel PC, RB, PC, gt\n    }\n    |1:\n    |  ins_next\n    |\n    |3:  // RA not int.\n    |    ldr FARG1, [BASE, RA, lsl #3]\n    |  blo ->vmeta_comp\n    |    ldr FARG2, [BASE, RC, lsl #3]\n    |   cmp TISNUMhi, CARG2, lsr #32\n    |   bhi >5\n    |   bne ->vmeta_comp\n    |  // RA number, RC int.\n    |  scvtf FARG2, CARG2w\n    |  b >5\n    |\n    |4:  // RA int, RC not int\n    |    ldr FARG2, [BASE, RC, lsl #3]\n    |   blo ->vmeta_comp\n    |  // RA int, RC number.\n    |  scvtf FARG1, CARG1w\n    |\n    |5:  // RA number, RC number\n    |  fcmp FARG1, FARG2\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  csel PC, RB, PC, lo\n    } else if (op == BC_ISGE) {\n      |  csel PC, RB, PC, hs\n    } else if (op == BC_ISLE) {\n      |  csel PC, RB, PC, ls\n    } else {\n      |  csel PC, RB, PC, hi\n    }\n    |  b <1\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1, RC = src2, JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add RC, BASE, RC, lsl #3\n    |    ldrh RBw, [PC, #2]\n    |   ldr CARG3, [RC]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    |  asr ITYPE, CARG3, #47\n    |  cmn ITYPE, #-LJ_TISNUM\n    if (vk) {\n      |  bls ->BC_ISEQN_Z\n    } else {\n      |  bls ->BC_ISNEN_Z\n    }\n    |  // RC is not a number.\n    |   asr TMP0, CARG1, #47\n    |.if FFI\n    |  // Check if RC or RA is a cdata.\n    |  cmn ITYPE, #-LJ_TCDATA\n    |   ccmn TMP0, #-LJ_TCDATA, #4, ne\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG1, CARG3\n    |  bne >2\n    |  // Tag and value are equal.\n    if (vk) {\n      |->BC_ISEQV_Z:\n      |  mov PC, RB\t\t\t// Perform branch.\n    }\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if the tags are the same and it's a table or userdata.\n    |  cmp ITYPE, TMP0\n    |  ccmn ITYPE, #-LJ_TISTABUD, #2, eq\n    if (vk) {\n      |  bhi <1\n    } else {\n      |  bhi ->BC_ISEQV_Z\t\t// Reuse code from opposite instruction.\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  and TAB:CARG2, CARG1, #LJ_GCVMASK\n    |  ldr TAB:TMP2, TAB:CARG2->metatable\n    if (vk) {\n      |  cbz TAB:TMP2, <1\t\t// No metatable?\n      |  ldrb TMP1w, TAB:TMP2->nomm\n      |   mov CARG4, #0\t\t\t// ne = 0\n      |  tbnz TMP1w, #MM_eq, <1\t\t// 'no __eq' flag set: done.\n    } else {\n      |  cbz TAB:TMP2, ->BC_ISEQV_Z\t// No metatable?\n      |  ldrb TMP1w, TAB:TMP2->nomm\n      |   mov CARG4, #1\t\t\t// ne = 1.\n      |  tbnz TMP1w, #MM_eq, ->BC_ISEQV_Z\t// 'no __eq' flag set: done.\n    }\n    |  b ->vmeta_equal\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src, RC = str_const (~), JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   mvn RC, RC\n    |    ldrh RBw, [PC, #2]\n    |   ldr CARG2, [KBASE, RC, lsl #3]\n    |    add PC, PC, #4\n    |   movn TMP0, #~LJ_TSTR\n    |.if FFI\n    |  asr ITYPE, CARG1, #47\n    |.endif\n    |    add RB, PC, RB, lsl #2\n    |   add CARG2, CARG2, TMP0, lsl #47\n    |    sub RB, RB, #0x20000\n    |.if FFI\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG1, CARG2\n    if (vk) {\n      |  csel PC, RB, PC, eq\n    } else {\n      |  csel PC, RB, PC, ne\n    }\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src, RC = num_const (~), JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add RC, KBASE, RC, lsl #3\n    |    ldrh RBw, [PC, #2]\n    |   ldr CARG3, [RC]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  checkint CARG1, >4\n    |   checkint CARG3, >6\n    |  cmp CARG1w, CARG3w\n    |1:\n    if (vk) {\n      |  csel PC, RB, PC, eq\n      |2:\n    } else {\n      |2:\n      |  csel PC, RB, PC, ne\n    }\n    |3:\n    |  ins_next\n    |\n    |4:  // RA not int.\n    |.if FFI\n    |  blo >7\n    |.else\n    |  blo <2\n    |.endif\n    |    ldr FARG1, [BASE, RA, lsl #3]\n    |    ldr FARG2, [RC]\n    |   cmp TISNUMhi, CARG3, lsr #32\n    |   bne >5\n    |  // RA number, RC int.\n    |  scvtf FARG2, CARG3w\n    |5:\n    |  // RA number, RC number.\n    |  fcmp FARG1, FARG2\n    |  b <1\n    |\n    |6:  // RA int, RC number\n    |  ldr FARG2, [RC]\n    |  scvtf FARG1, CARG1w\n    |  fcmp FARG1, FARG2\n    |  b <1\n    |\n    |.if FFI\n    |7:\n    |  asr ITYPE, CARG1, #47\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  bne <2\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src, RC = primitive_type (~), JMP with RC = target\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |   ldrh RBw, [PC, #2]\n    |   add PC, PC, #4\n    |  add RC, RC, #1\n    |   add RB, PC, RB, lsl #2\n    |.if FFI\n    |  asr ITYPE, TMP0, #47\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |  cmn RC, ITYPE\n    |.else\n    |  cmn RC, TMP0, asr #47\n    |.endif\n    |   sub RB, RB, #0x20000\n    if (vk) {\n      |  csel PC, RB, PC, eq\n    } else {\n      |  csel PC, RB, PC, ne\n    }\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst or unused, RC = src, JMP with RC = target\n    |   ldrh RBw, [PC, #2]\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |   add PC, PC, #4\n    |  mov_false TMP1\n    |   add RB, PC, RB, lsl #2\n    |  cmp TMP0, TMP1\n    |   sub RB, RB, #0x20000\n    if (op == BC_ISTC || op == BC_IST) {\n      if (op == BC_ISTC) {\n\t|  csel RA, RA, RC, lo\n      }\n      |  csel PC, RB, PC, lo\n    } else {\n      if (op == BC_ISFC) {\n\t|  csel RA, RA, RC, hs\n      }\n      |  csel PC, RB, PC, hs\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  str TMP0, [BASE, RA, lsl #3]\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src, RC = -type\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |  cmn RC, TMP0, asr #47\n    |  bne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  // RA = src, RC = -(TISNUM-1)\n    |  ldr TMP0, [BASE, RA]\n    |  checknum TMP0, ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_NOT:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |   mov_false TMP1\n    |   mov_true TMP2\n    |  cmp TMP0, TMP1\n    |  csel TMP0, TMP1, TMP2, lo\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |  asr ITYPE, TMP0, #47\n    |  cmn ITYPE, #-LJ_TISNUM\n    |  bhi ->vmeta_unm\n    |  eor TMP0, TMP0, #U64x(80000000,00000000)\n    |  bne >5\n    |  negs TMP0w, TMP0w\n    |   movz CARG3, #0x41e0, lsl #48\t// 2^31.\n    |   add TMP0, TMP0, TISNUM\n    |  csel TMP0, TMP0, CARG3, vc\n    |5:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_LEN:\n    |  // RA = dst, RC = src\n    |  ldr CARG1, [BASE, RC, lsl #3]\n    |  asr ITYPE, CARG1, #47\n    |  cmn ITYPE, #-LJ_TSTR\n    |   and CARG1, CARG1, #LJ_GCVMASK\n    |  bne >2\n    |  ldr CARG1w, STR:CARG1->len\n    |1:\n    |  add CARG1, CARG1, TISNUM\n    |  str CARG1, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |2:\n    |  cmn ITYPE, #-LJ_TTAB\n    |  bne ->vmeta_len\n#if LJ_52\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cbnz TAB:CARG2, >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n    |\n#if LJ_52\n    |9:\n    |  ldrb TMP1w, TAB:CARG2->nomm\n    |  tbnz TMP1w, #MM_len, <3\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithcheck_int, target\n    |  checkint CARG1, target\n    |  checkint CARG2, target\n    |.endmacro\n    |\n    |.macro ins_arithcheck_num, target\n    |  checknum CARG1, target\n    |  checknum CARG2, target\n    |.endmacro\n    |\n    |.macro ins_arithcheck_nzdiv, target\n    |  cbz CARG2w, target\n    |.endmacro\n    |\n    |.macro ins_arithhead\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||if (vk == 1) {\n    |   and RC, RC, #255\n    |    decode_RB RB, INS\n    ||} else {\n    |   decode_RB RB, INS\n    |    and RC, RC, #255\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithload, reg1, reg2\n    |  // RA = dst, RB = src1, RC = src2 | num_const\n    ||switch (vk) {\n    ||case 0:\n    |   ldr reg1, [BASE, RB, lsl #3]\n    |    ldr reg2, [KBASE, RC, lsl #3]\n    ||  break;\n    ||case 1:\n    |   ldr reg1, [KBASE, RC, lsl #3]\n    |    ldr reg2, [BASE, RB, lsl #3]\n    ||  break;\n    ||default:\n    |   ldr reg1, [BASE, RB, lsl #3]\n    |    ldr reg2, [BASE, RC, lsl #3]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithmod, res, reg1, reg2\n    |  fdiv d2, reg1, reg2\n    |  frintm d2, d2\n    |  fmsub res, d2, reg2, reg1\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins\n    |  ins_arithhead\n    |  ins_arithload CARG1, CARG2\n    |  ins_arithcheck_int >5\n    |.if \"intins\" == \"smull\"\n    |  smull CARG1, CARG1w, CARG2w\n    |  cmp CARG1, CARG1, sxtw\n    |   mov CARG1w, CARG1w\n    |  ins_arithfallback bne\n    |.elif \"intins\" == \"ins_arithmodi\"\n    |  ins_arithfallback ins_arithcheck_nzdiv\n    |  bl ->vm_modi\n    |.else\n    |  intins CARG1w, CARG1w, CARG2w\n    |  ins_arithfallback bvs\n    |.endif\n    |  add CARG1, CARG1, TISNUM\n    |  str CARG1, [BASE, RA, lsl #3]\n    |4:\n    |  ins_next\n    |\n    |5:  // FP variant.\n    |  ins_arithload FARG1, FARG2\n    |  ins_arithfallback ins_arithcheck_num\n    |  fpins FARG1, FARG1, FARG2\n    |  str FARG1, [BASE, RA, lsl #3]\n    |  b <4\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins\n    |  ins_arithhead\n    |  ins_arithload CARG1, CARG2\n    |  ins_arithload FARG1, FARG2\n    |  ins_arithfallback ins_arithcheck_num\n    |.if \"fpins\" == \"fpow\"\n    |  bl extern pow\n    |.else\n    |  fpins FARG1, FARG1, FARG2\n    |.endif\n    |  str FARG1, [BASE, RA, lsl #3]\n    |  ins_next\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arithdn adds, fadd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arithdn subs, fsub\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arithdn smull, fmul\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp fdiv\n    break;\n  case BC_MODVN: case BC_MODNV: case BC_MODVV:\n    |  ins_arithdn ins_arithmodi, ins_arithmod\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  ins_arithfp fpow\n    break;\n\n  case BC_CAT:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = src_start, RC = src_end\n    |   str BASE, L->base\n    |  sub CARG3, RC, RB\n    |  add CARG2, BASE, RC, lsl #3\n    |->BC_CAT_Z:\n    |  // RA = dst, CARG2 = top-1, CARG3 = left\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  ldrb RBw, [PC, #-1]\n    |   ldr BASE, L->base\n    |   cbnz CRET1, ->vmeta_binop\n    |  ldr TMP0, [BASE, RB, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\t// Copy result to RA.\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst, RC = str_const (~)\n    |  mvn RC, RC\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |   movn TMP1, #~LJ_TSTR\n    |  add TMP0, TMP0, TMP1, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst, RC = cdata_const (~)\n    |  mvn RC, RC\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |   movn TMP1, #~LJ_TCDATA\n    |  add TMP0, TMP0, TMP1, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst, RC = int16_literal\n    |  sxth RCw, RCw\n    |  add TMP0, RC, TISNUM\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  // RA = dst, RC = num_const\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  // RA = dst, RC = primitive_type (~)\n    |  mvn TMP0, RC, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  // RA = base, RC = end\n    |  add RA, BASE, RA, lsl #3\n    |   add RC, BASE, RC, lsl #3\n    |  str TISNIL, [RA], #8\n    |1:\n    |   cmp RA, RC\n    |  str TISNIL, [RA], #8\n    |   blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst, RC = uvnum\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RC, RC, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RC, lsl #3]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |  ldr TMP0, [CARG2]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_USETV:\n    |  // RA = uvnum, RC = src\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG1, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr CARG3, [BASE, RC, lsl #3]\n    |    ldr CARG2, UPVAL:CARG1->v\n    |  ldrb TMP2w, UPVAL:CARG1->marked\n    |  ldrb TMP0w, UPVAL:CARG1->closed\n    |    asr ITYPE, CARG3, #47\n    |   str CARG3, [CARG2]\n    |    add ITYPE, ITYPE, #-LJ_TISGCV\n    |  tst TMP2w, #LJ_GC_BLACK\t\t// isblack(uv)\n    |  ccmp TMP0w, #0, #4, ne\t\t// && uv->closed\n    |    ccmn ITYPE, #-(LJ_TNUMX - LJ_TISGCV), #0, ne\t// && tvisgcv(v)\n    |  bhi >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is white.\n    |  and GCOBJ:CARG3, CARG3, #LJ_GCVMASK\n    |  ldrb TMP1w, GCOBJ:CARG3->gch.marked\n    |  tst TMP1w, #LJ_GC_WHITES\t\t// iswhite(str)\n    |  beq <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov CARG1, GL\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |    mvn RC, RC\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG1, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr STR:CARG3, [KBASE, RC, lsl #3]\n    |   movn TMP0, #~LJ_TSTR\n    |    ldr CARG2, UPVAL:CARG1->v\n    |  ldrb TMP2w, UPVAL:CARG1->marked\n    |   add TMP0, STR:CARG3, TMP0, lsl #47\n    |    ldrb TMP1w, STR:CARG3->marked\n    |   str TMP0, [CARG2]\n    |  tbnz TMP2w, #2, >2\t\t// isblack(uv)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  ldrb TMP0w, UPVAL:CARG1->closed\n    |    tst TMP1w, #LJ_GC_WHITES\t// iswhite(str)\n    |  ccmp TMP0w, #0, #0, ne\n    |  beq <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov CARG1, GL\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum, RC = num_const\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr TMP0, [KBASE, RC, lsl #3]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   str TMP0, [CARG2]\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  // RA = uvnum, RC = primitive_type (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA, lsl #3]\n    |   mvn TMP0, RC, lsl #47\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   str TMP0, [CARG2]\n    |  ins_next\n    break;\n\n  case BC_UCLO:\n    |  // RA = level, RC = target\n    |  ldr CARG3, L->openupval\n    |   add RC, PC, RC, lsl #2\n    |    str BASE, L->base\n    |   sub PC, RC, #0x20000\n    |  cbz CARG3, >1\n    |  mov CARG1, L\n    |  add CARG2, BASE, RA, lsl #3\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  ldr BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst, RC = proto_const (~) (holding function prototype)\n    |  mvn RC, RC\n    |   str BASE, L->base\n    |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n    |    str PC, SAVE_PC\n    |   ldr CARG2, [KBASE, RC, lsl #3]\n    |    mov CARG1, L\n    |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  ldr BASE, L->base\n    |   movn TMP0, #~LJ_TFUNC\n    |   add CRET1, CRET1, TMP0, lsl #47\n    |  str CRET1, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst, RC = (hbits|asize) | tab_const (~)\n    |  ldp CARG3, CARG4, GL->gc.total\t// Assumes threshold follows total.\n    |   str BASE, L->base\n    |   str PC, SAVE_PC\n    |   mov CARG1, L\n    |  cmp CARG3, CARG4\n    |  bhs >5\n    |1:\n    if (op == BC_TNEW) {\n      |  and CARG2, RC, #0x7ff\n      |   lsr CARG3, RC, #11\n      |  cmp CARG2, #0x7ff\n      |  mov TMP0, #0x801\n      |  csel CARG2, CARG2, TMP0, ne\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns GCtab *.\n    } else {\n      |  mvn RC, RC\n      |  ldr CARG2, [KBASE, RC, lsl #3]\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns GCtab *.\n    }\n    |  ldr BASE, L->base\n    |   movk CRET1, #(LJ_TTAB>>1)&0xffff, lsl #48\n    |  str CRET1, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mov CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst, RC = str_const (~)\n  case BC_GSET:\n    |  // RA = dst, RC = str_const (~)\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |   mvn RC, RC\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr TAB:CARG2, LFUNC:CARG1->env\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tgetv\n    |  checkint TMP1, >9\t\t// Integer key?\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, TMP1, uxtw #3\n    |   cmp TMP1w, CARG1w\t\t// In array part?\n    |   bhs ->vmeta_tgetv\n    |  ldr TMP0, [CARG3]\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |1:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <1\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetv\n    |\n    |9:\n    |  asr ITYPE, TMP1, #47\n    |  cmn ITYPE, #-LJ_TSTR\t\t// String key?\n    |  bne ->vmeta_tgetv\n    |   and STR:RC, TMP1, #LJ_GCVMASK\n    |  b ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = str_const (~)\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // TAB:CARG2 = GCtab *, STR:RC = GCstr *, RA = dst\n    |  ldr TMP1w, TAB:CARG2->hmask\n    |   ldr TMP2w, STR:RC->hash\n    |    ldr NODE:CARG3, TAB:CARG2->node\n    |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->hash & tab->hmask\n    |  add TMP1, TMP1, TMP1, lsl #1\n    |  movn CARG4, #~LJ_TSTR\n    |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n    |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n    |1:\n    |  ldp TMP0, CARG1, NODE:CARG3->val\n    |   ldr NODE:CARG3, NODE:CARG3->next\n    |  cmp CARG1, CARG4\n    |  bne >4\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |3:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  cbnz NODE:CARG3, <1\n    |  // End of hash chain: key not found, nil result.\n    |   mov TMP0, TISNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <3\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <3\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = index\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |  checktab CARG2, ->vmeta_tgetb\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, RC, lsl #3\n    |   cmp RCw, CARG1w\t\t\t// In array part?\n    |   bhs ->vmeta_tgetb\n    |  ldr TMP0, [CARG3]\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |1:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <1\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\n    break;\n  case BC_TGETR:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = key\n    |  ldr CARG1, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  and TAB:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG3, TAB:CARG1->array\n    |   ldr TMP2w, TAB:CARG1->asize\n    |  add CARG3, CARG3, TMP1w, uxtw #3\n    |   cmp TMP1w, TMP2w\t\t// In array part?\n    |   bhs ->vmeta_tgetr\n    |  ldr TMP0, [CARG3]\n    |->BC_TGETR_Z:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tsetv\n    |  checkint TMP1, >9\t\t// Integer key?\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, TMP1, uxtw #3\n    |   cmp TMP1w, CARG1w\t\t// In array part?\n    |   bhs ->vmeta_tsetv\n    |  ldr TMP1, [CARG3]\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >5\n    |1:\n    |   str TMP0, [CARG3]\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <1\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetv\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <2\n    |\n    |9:\n    |  asr ITYPE, TMP1, #47\n    |  cmn ITYPE, #-LJ_TSTR\t\t// String key?\n    |  bne ->vmeta_tsetv\n    |   and STR:RC, TMP1, #LJ_GCVMASK\n    |  b ->BC_TSETS_Z\n    break;\n  case BC_TSETS:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = str_const (~)\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // TAB:CARG2 = GCtab *, STR:RC = GCstr *, RA = src\n    |  ldr TMP1w, TAB:CARG2->hmask\n    |   ldr TMP2w, STR:RC->hash\n    |    ldr NODE:CARG3, TAB:CARG2->node\n    |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->hash & tab->hmask\n    |  add TMP1, TMP1, TMP1, lsl #1\n    |  movn CARG4, #~LJ_TSTR\n    |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n    |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n    |   strb wzr, TAB:CARG2->nomm\t// Clear metamethod cache.\n    |1:\n    |  ldp TMP1, CARG1, NODE:CARG3->val\n    |   ldr NODE:TMP3, NODE:CARG3->next\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp CARG1, CARG4\n    |  bne >5\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >4\n    |2:\n    |   str TMP0, NODE:CARG3->val\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <2\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <2\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:CARG3, NODE:TMP3\n    |  cbnz NODE:TMP3, <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, >6\t\t// No metatable: continue.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  // 'no __newindex' flag NOT set: check.\n    |  tbz TMP1w, #MM_newindex, ->vmeta_tsets\n    |6:\n    |  movn TMP1, #~LJ_TSTR\n    |   str PC, SAVE_PC\n    |  add TMP0, STR:RC, TMP1, lsl #47\n    |   str BASE, L->base\n    |   mov CARG1, L\n    |  str TMP0, TMPD\n    |   add CARG3, sp, TMPDofs\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  ldr BASE, L->base\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |  str TMP0, [CRET1]\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = index\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |  checktab CARG2, ->vmeta_tsetb\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, RC, lsl #3\n    |   cmp RCw, CARG1w\t\t\t// In array part?\n    |   bhs ->vmeta_tsetb\n    |  ldr TMP1, [CARG3]\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >5\n    |1:\n    |   str TMP0, [CARG3]\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <1\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetb\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  and TAB:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr CARG1, TAB:CARG2->array\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |   ldr CARG4w, TAB:CARG2->asize\n    |  add CARG1, CARG1, TMP1, uxtw #3\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   cmp TMP1w, CARG4w\t\t// In array part?\n    |   bhs ->vmeta_tsetr\n    |->BC_TSETR_Z:\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |   str TMP0, [CARG1]\n    |   ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP0\n    |  b <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base (table at base-1), RC = num_const (start index)\n    |  add RA, BASE, RA, lsl #3\n    |1:\n    |   ldr RBw, SAVE_MULTRES\n    |  ldr TAB:CARG2, [RA, #-8]\t\t// Guaranteed to be a table.\n    |   ldr TMP1, [KBASE, RC, lsl #3]\t// Integer constant is in lo-word.\n    |    sub RB, RB, #8\n    |    cbz RB, >4\t\t\t// Nothing to copy?\n    |  and TAB:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr CARG1w, TAB:CARG2->asize\n    |   add CARG3w, TMP1w, RBw, lsr #3\n    |   ldr CARG4, TAB:CARG2->array\n    |  cmp CARG3, CARG1\n    |    add RB, RA, RB\n    |  bhi >5\n    |   add TMP1, CARG4, TMP1w, uxtw #3\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |3:  // Copy result slots to table.\n    |   ldr TMP0, [RA], #8\n    |   str TMP0, [TMP1], #8\n    |  cmp RA, RB\n    |  blo <3\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   str BASE, L->base\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base, (RB = nresults+1,) RC = extra_nargs\n    |  ldr TMP0w, SAVE_MULTRES\n    |  decode_RC8RD NARGS8:RC, RC\n    |  add NARGS8:RC, NARGS8:RC, TMP0\n    |  b ->BC_CALL_Z\n    break;\n  case BC_CALL:\n    |  decode_RC8RD NARGS8:RC, RC\n    |  // RA = base, (RB = nresults+1,) RC = (nargs+1)*8\n    |->BC_CALL_Z:\n    |  mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  add BASE, BASE, RA, lsl #3\n    |  ldr CARG3, [BASE]\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add BASE, BASE, #16\n    |  checkfunc CARG3, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base, (RB = 0,) RC = extra_nargs\n    |  ldr TMP0w, SAVE_MULTRES\n    |  add NARGS8:RC, TMP0, RC, lsl #3\n    |  b ->BC_CALLT1_Z\n    break;\n  case BC_CALLT:\n    |  lsl NARGS8:RC, RC, #3\n    |  // RA = base, (RB = 0,) RC = (nargs+1)*8\n    |->BC_CALLT1_Z:\n    |  add RA, BASE, RA, lsl #3\n    |  ldr TMP1, [RA]\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add RA, RA, #16\n    |  checktp CARG3, TMP1, LJ_TFUNC, ->vmeta_callt\n    |  ldr PC, [BASE, FRAME_PC]\n    |->BC_CALLT2_Z:\n    |   mov RB, #0\n    |   ldrb TMP2w, LFUNC:CARG3->ffid\n    |  tst PC, #FRAME_TYPE\n    |  bne >7\n    |1:\n    |  str TMP1, [BASE, FRAME_FUNC]\t// Copy function down, but keep PC.\n    |  cbz NARGS8:RC, >3\n    |2:\n    |  ldr TMP0, [RA, RB]\n    |   add TMP1, RB, #8\n    |   cmp TMP1, NARGS8:RC\n    |  str TMP0, [BASE, RB]\n    |    mov RB, TMP1\n    |   bne <2\n    |3:\n    |  cmp TMP2, #1\t\t\t// (> FF_C) Calling a fast function?\n    |  bhi >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  ldrb RAw, [PC, #-3]\n    |  sub CARG1, BASE, RA, lsl #3\n    |  ldr LFUNC:CARG1, [CARG1, #-32]\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG1, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG1, #PC2PROTO(k)]\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  eor PC, PC, #FRAME_VARG\n    |  tst PC, #FRAME_TYPEP\t\t// Vararg frame below?\n    |  csel TMP2, RB, TMP2, ne\t\t// Clear ffid if no Lua function below.\n    |  bne <1\n    |  sub BASE, BASE, PC\n    |  ldr PC, [BASE, FRAME_PC]\n    |  tst PC, #FRAME_TYPE\n    |  csel TMP2, RB, TMP2, ne\t\t// Clear ffid if no Lua function below.\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA, lsl #3\n    |  ldr CARG3, [RA, #-24]\n    |    mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |   ldp CARG1, CARG2, [RA, #-16]\n    |    add BASE, RA, #16\n    |    mov NARGS8:RC, #16\t\t// Iterators get 2 arguments.\n    |  str CARG3, [RA]\t\t\t// Copy callable.\n    |   stp CARG1, CARG2, [RA, #16]\t// Copy state and control var.\n    |  checkfunc CARG3, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  add RA, BASE, RA, lsl #3\n    |  ldr TAB:RB, [RA, #-16]\n    |    ldrh TMP3w, [PC, #2]\n    |  ldr CARG1w, [RA, #-8]\t\t// Get index from control var.\n    |    add PC, PC, #4\n    |    add TMP3, PC, TMP3, lsl #2\n    |  and TAB:RB, RB, #LJ_GCVMASK\n    |    sub TMP3, TMP3, #0x20000\n    |  ldr TMP1w, TAB:RB->asize\n    |   ldr CARG2, TAB:RB->array\n    |1:  // Traverse array part.\n    |  subs RC, CARG1, TMP1\n    |   add CARG3, CARG2, CARG1, lsl #3\n    |  bhs >5\t\t\t\t// Index points after array part?\n    |   ldr TMP0, [CARG3]\n    |   cmp TMP0, TISNIL\n    |   cinc CARG1, CARG1, eq\t\t// Skip holes in array part.\n    |   beq <1\n    |   add CARG1, CARG1, TISNUM\n    |   stp CARG1, TMP0, [RA]\n    |    add CARG1, CARG1, #1\n    |3:\n    |    str CARG1w, [RA, #-8]\t\t// Update control var.\n    |  mov PC, TMP3\n    |4:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  ldr TMP2w, TAB:RB->hmask\n    |   ldr NODE:RB, TAB:RB->node\n    |6:\n    |   add CARG1, RC, RC, lsl #1\n    |  cmp RC, TMP2\t\t\t// End of iteration? Branch to ITERN+1.\n    |   add NODE:CARG3, NODE:RB, CARG1, lsl #3  // node = tab->node + idx*3*8\n    |  bhi <4\n    |  ldp TMP0, CARG1, NODE:CARG3->val\n    |  cmp TMP0, TISNIL\n    |   add RC, RC, #1\n    |  beq <6\t\t\t\t// Skip holes in hash part.\n    |  stp CARG1, TMP0, [RA]\n    |  add CARG1, RC, TMP1\n    |  b <3\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base, RC = target (points to ITERN)\n    |  add RA, BASE, RA, lsl #3\n    |  ldr CFUNC:CARG1, [RA, #-24]\n    |     add RC, PC, RC, lsl #2\n    |   ldp TAB:CARG3, CARG4, [RA, #-16]\n    |     sub RC, RC, #0x20000\n    |  checkfunc CFUNC:CARG1, >5\n    |   asr TMP0, TAB:CARG3, #47\n    |  ldrb TMP1w, CFUNC:CARG1->ffid\n    |   cmn TMP0, #-LJ_TTAB\n    |   ccmp CARG4, TISNIL, #0, eq\n    |  ccmp TMP1w, #FF_next_N, #0, eq\n    |  bne >5\n    |  mov TMP0w, #0xfffe7fff\n    |  lsl TMP0, TMP0, #32\n    |  str TMP0, [RA, #-8]\t\t// Initialize control var.\n    |1:\n    |     mov PC, RC\n    |  ins_next\n    |\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov TMP0, #BC_JMP\n    |   mov TMP1, #BC_ITERC\n    |  strb TMP0w, [PC, #-4]\n    |   strb TMP1w, [RC]\n    |  b <1\n    break;\n\n  case BC_VARG:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = base, RB = (nresults+1), RC = numparams\n    |  ldr TMP1, [BASE, FRAME_PC]\n    |  add RC, BASE, RC, lsl #3\n    |   add RA, BASE, RA, lsl #3\n    |  add RC, RC, #FRAME_VARG\n    |   add TMP2, RA, RB, lsl #3\n    |  sub RC, RC, TMP1\t\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |   sub TMP3, BASE, #16\t\t// TMP3 = vtop\n    |  cbz RB, >5\n    |   sub TMP2, TMP2, #16\n    |1:  // Copy vararg slots to destination slots.\n    |  cmp RC, TMP3\n    |  ldr TMP0, [RC], #8\n    |  csel TMP0, TMP0, TISNIL, lo\n    |   cmp RA, TMP2\n    |  str TMP0, [RA], #8\n    |   blo <1\n    |2:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  ldr TMP0, L->maxstack\n    |   subs TMP2, TMP3, RC\n    |   csel RB, xzr, TMP2, le\t\t// MULTRES = (max(vtop-vbase,0)+1)*8\n    |   add RB, RB, #8\n    |  add TMP1, RA, TMP2\n    |   str RBw, SAVE_MULTRES\n    |   ble <2\t\t\t\t// Nothing to copy.\n    |  cmp TMP1, TMP0\n    |  bhi >7\n    |6:\n    |  ldr TMP0, [RC], #8\n    |  str TMP0, [RA], #8\n    |  cmp RC, TMP3\n    |  blo <6\n    |  b <2\n    |\n    |7:  // Grow stack for varargs.\n    |  lsr CARG2, TMP2, #3\n    |   stp BASE, RA, L->base\n    |  mov CARG1, L\n    |  sub RC, RC, BASE\t\t\t// Need delta, because BASE may change.\n    |   str PC, SAVE_PC\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  ldp BASE, RA, L->base\n    |  add RC, BASE, RC\n    |  sub TMP3, BASE, #16\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results, RC = extra results\n    |  ldr TMP0w, SAVE_MULTRES\n    |   ldr PC, [BASE, FRAME_PC]\n    |    add RA, BASE, RA, lsl #3\n    |  add RC, TMP0, RC, lsl #3\n    |  b ->BC_RETM_Z\n    break;\n\n  case BC_RET:\n    |  // RA = results, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |    add RA, BASE, RA, lsl #3\n    |->BC_RETM_Z:\n    |   str RCw, SAVE_MULTRES\n    |1:\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV2_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return\n    |  ldr INSw, [PC, #-4]\n    |  subs TMP1, RC, #8\n    |   sub CARG3, BASE, #16\n    |  beq >3\n    |2:\n    |  ldr TMP0, [RA], #8\n    |   add BASE, BASE, #8\n    |   sub TMP1, TMP1, #8\n    |  str TMP0, [BASE, #-24]\n    |   cbnz TMP1, <2\n    |3:\n    |  decode_RA RA, INS\n    |  sub CARG4, CARG3, RA, lsl #3\n    |   decode_RB RB, INS\n    |  ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]\n    |5:\n    |  cmp RC, RB, lsl #3\t\t// More results expected?\n    |  blo >6\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  mov BASE, CARG4\n    |  ldr CARG2, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next\n    |\n    |6:  // Fill up results with nil.\n    |  add BASE, BASE, #8\n    |   add RC, RC, #8\n    |  str TISNIL, [BASE, #-24]\n    |  b <5\n    |\n    |->BC_RETV1_Z:  // Non-standard return case.\n    |  add RA, BASE, RA, lsl #3\n    |->BC_RETV2_Z:\n    |  tst CARG2, #FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, CARG2\n    |  ldr PC, [BASE, FRAME_PC]\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |   str RCw, SAVE_MULTRES\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV1_Z\n    |   ldr INSw, [PC, #-4]\n    if (op == BC_RET1) {\n      |  ldr TMP0, [BASE, RA, lsl #3]\n    }\n    |  sub CARG4, BASE, #16\n    |   decode_RA RA, INS\n    |  sub BASE, CARG4, RA, lsl #3\n    if (op == BC_RET1) {\n      |  str TMP0, [CARG4], #8\n    }\n    |   decode_RB RB, INS\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |5:\n    |  cmp RC, RB, lsl #3\n    |  blo >6\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG2, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    |  add RC, RC, #8\n    |  str TISNIL, [CARG4], #8\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];      .define FOR_TIDX,  [RA, #4]\n  |.define FOR_STOP, [RA, #8];  .define FOR_TSTOP, [RA, #12]\n  |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]\n  |.define FOR_EXT,  [RA, #24]; .define FOR_TEXT,  [RA, #28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base, RC = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  add RA, BASE, RA, lsl #3\n    |  ldp CARG1, CARG2, FOR_IDX\t\t// CARG1 = IDX, CARG2 = STOP\n    |   ldr CARG3, FOR_STEP\t\t\t// CARG3 = STEP\n    if (op != BC_JFORL) {\n      |   add RC, PC, RC, lsl #2\n      |   sub RC, RC, #0x20000\n    }\n    |  checkint CARG1, >5\n    if (!vk) {\n      |  checkint CARG2, ->vmeta_for\n      |   checkint CARG3, ->vmeta_for\n      |  tbnz CARG3w, #31, >4\n      |  cmp CARG1w, CARG2w\n    } else {\n      |  adds CARG1w, CARG1w, CARG3w\n      |  bvs >2\n      |   add TMP0, CARG1, TISNUM\n      |  tbnz CARG3w, #31, >4\n      |  cmp CARG1w, CARG2w\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  csel PC, RC, PC, gt\n    } else if (op == BC_JFORI) {\n      |  ldrh RCw, [RC, #-2]\n    } else if (op == BC_IFORL) {\n      |  csel PC, RC, PC, le\n    }\n    if (vk) {\n      |   str TMP0, FOR_IDX\n      |   str TMP0, FOR_EXT\n    } else {\n      |  str CARG1, FOR_EXT\n    }\n    if (op == BC_JFORI || op == BC_JFORL) {\n      |  ble =>BC_JLOOP\n    }\n    |2:\n    |   ins_next\n    |\n    |4:  // Invert check for negative step.\n    |  cmp CARG2w, CARG1w\n    |  b <1\n    |\n    |5:  // FP loop.\n    |  ldp d0, d1, FOR_IDX\n    |  blo ->vmeta_for\n    if (!vk) {\n      |  checknum CARG2, ->vmeta_for\n      |   checknum CARG3, ->vmeta_for\n      |  str d0, FOR_EXT\n    } else {\n      |  ldr d2, FOR_STEP\n      |  fadd d0, d0, d2\n    }\n    |  tbnz CARG3, #63, >7\n    |  fcmp d0, d1\n    |6:\n    if (vk) {\n      |  str d0, FOR_IDX\n      |  str d0, FOR_EXT\n    }\n    if (op == BC_FORI) {\n      |  csel PC, RC, PC, hi\n    } else if (op == BC_JFORI) {\n      |  ldrh RCw, [RC, #-2]\n      |  bls =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  csel PC, RC, PC, ls\n    } else {\n      |  bls =>BC_JLOOP\n    }\n    |  b <2\n    |\n    |7:  // Invert check for negative step.\n    |  fcmp d1, d0\n    |  b <6\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base, RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add TMP1, BASE, RA, lsl #3\n    |  cmp CARG1, TISNIL\n    |  beq >1\t\t\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  str CARG1, [TMP1, #-8]\n      |  b =>BC_JLOOP\n    } else {\n      |  add TMP0, PC, RC, lsl #2\t// Otherwise save control var + branch.\n      |  sub PC, TMP0, #0x20000\n      |  str CARG1, [TMP1, #-8]\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base, RC = target (loop extent)\n    |  // Note: RA/RC is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base, RC = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  NYI\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base (only used by trace recorder), RC = target\n    |  add RC, PC, RC, lsl #2\n    |  sub PC, RC, #0x20000\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   ldrb TMP1w, [PC, #-4+PC2PROTO(numparams)]\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |  bhi ->vm_growstack_l\n    |2:\n    |  cmp NARGS8:RC, TMP1, lsl #3\t// Check for missing parameters.\n    |  blo >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD RC, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  str TISNIL, [BASE, NARGS8:RC]\n    |  add NARGS8:RC, NARGS8:RC, #8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   add TMP2, BASE, RC\n    |  add RA, RA, RC\n    |   add TMP0, RC, #16+FRAME_VARG\n    |   str LFUNC:CARG3, [TMP2], #8\t// Store (untagged) copy of LFUNC.\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |   str TMP0, [TMP2], #8\t\t// Store delta + FRAME_VARG.\n    |  bhs ->vm_growstack_l\n    |   sub RC, TMP2, #16\n    |  ldrb TMP1w, [PC, #-4+PC2PROTO(numparams)]\n    |   mov RA, BASE\n    |   mov BASE, TMP2\n    |  cbz TMP1, >2\n    |1:\n    |  cmp RA, RC\t\t\t// Less args than parameters?\n    |  bhs >3\n    |   ldr TMP0, [RA]\n    |  sub TMP1, TMP1, #1\n    |    str TISNIL, [RA], #8\t\t// Clear old fixarg slot (help the GC).\n    |   str TMP0, [TMP2], #8\n    |  cbnz TMP1, <1\n    |2:\n    |  ins_next\n    |\n    |3:\n    |  sub TMP1, TMP1, #1\n    |   str TISNIL, [TMP2], #8\n    |  cbz TMP1, <2\n    |  b <3\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  ldr CARG4, CFUNC:CARG3->f\n    } else {\n      |  ldr CARG4, GL->wrapf\n    }\n    |   add CARG2, RA, NARGS8:RC\n    |   ldr CARG1, L->maxstack\n    |  add RC, BASE, NARGS8:RC\n    |   cmp CARG2, CARG1\n    |  stp BASE, RC, L->base\n    if (op == BC_FUNCCW) {\n      |  ldr CARG2, CFUNC:CARG3->f\n    }\n    |    mv_vmstate TMP0w, C\n    |  mov CARG1, L\n    |   bhi ->vm_growstack_c\t\t// Need to grow stack.\n    |    st_vmstate TMP0w\n    |  blr CARG4\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  ldp BASE, TMP1, L->base\n    |    str L, GL->cur_L\n    |   sbfiz RC, CRET1, #3, #32\n    |    st_vmstate ST_INTERP\n    |  ldr PC, [BASE, FRAME_PC]\n    |   sub RA, TMP1, RC\t\t// RA = L->top - nresults*8\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i, cf = CFRAME_SIZE >> 3;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.byte 0xc\\n\\t.uleb128 31\\n\\t.uleb128 0\\n\"\t/* def_cfa sp */\n\t\"\\t.align 3\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 %d\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 %d\\n\",\t/* offset lr */\n\tfcofs, CFRAME_SIZE, cf, cf-1);\n    for (i = 19; i <= 28; i++)  /* offset x19-x28 */\n      fprintf(ctx->fp, \"\\t.byte 0x%x\\n\\t.uleb128 %d\\n\", 0x80+i, cf-i+17);\n    for (i = 8; i <= 15; i++)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 0x%x\\n\\t.uleb128 %d\\n\",\n\t      64+i, cf-i-4);\n    fprintf(ctx->fp,\n\t\"\\t.align 3\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 32\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 4\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 3\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x93\\n\\t.uleb128 2\\n\"\t\t/* offset x19 */\n\t\"\\t.align 3\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 31\\n\\t.uleb128 0\\n\"\t/* def_cfa sp */\n\t\"\\t.align 3\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 %d\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 %d\\n\",\t/* offset lr */\n\tfcofs, CFRAME_SIZE, cf, cf-1);\n    for (i = 19; i <= 28; i++)  /* offset x19-x28 */\n      fprintf(ctx->fp, \"\\t.byte 0x%x\\n\\t.uleb128 %d\\n\", 0x80+i, cf-i+17);\n    for (i = 8; i <= 15; i++)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 0x%x\\n\\t.uleb128 %d\\n\",\n\t      64+i, cf-i-4);\n    fprintf(ctx->fp,\n\t\"\\t.align 3\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 1\\n\"                        /* augmentation length */\n\t\"\\t.byte 0x1b\\n\"                        /* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 31\\n\\t.uleb128 0\\n\"\t/* def_cfa sp */\n\t\"\\t.align 3\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"                        /* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 32\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 4\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 3\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x93\\n\\t.uleb128 2\\n\"\t\t/* offset x19 */\n\t\"\\t.align 3\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_mips.dasc",
    "content": "|// Low-level VM code for MIPS CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|//\n|// MIPS soft-float support contributed by Djordje Kovacevic and\n|// Stefan Pejic from RT-RK.com, sponsored by Cisco Systems, Inc.\n|\n|.arch mips\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra\n|\n|.macro .FPU, a, b\n|.if FPU\n|  a, b\n|.endif\n|.endmacro\n|\n|// The following must be C callee-save (but BASE is often refetched).\n|.define BASE,\t\tr16\t// Base of current Lua stack frame.\n|.define KBASE,\t\tr17\t// Constants of current Lua function.\n|.define PC,\t\tr18\t// Next PC.\n|.define DISPATCH,\tr19\t// Opcode dispatch table.\n|.define LREG,\t\tr20\t// Register holding lua_State (also in SAVE_L).\n|.define MULTRES,\tr21\t// Size of multi-result: (nresults+1)*8.\n|\n|.define JGL,\t\tr30\t// On-trace: global_State + 32768.\n|\n|// Constants for type-comparisons, stores and conversions. C callee-save.\n|.define TISNUM,\tr22\n|.define TISNIL,\tr30\n|.if FPU\n|.define TOBIT,\t\tf30\t// 2^52 + 2^51.\n|.endif\n|\n|// The following temporaries are not saved across C calls, except for RA.\n|.define RA,\t\tr23\t// Callee-save.\n|.define RB,\t\tr8\n|.define RC,\t\tr9\n|.define RD,\t\tr10\n|.define INS,\t\tr11\n|\n|.define AT,\t\tr1\t// Assembler temporary.\n|.define TMP0,\t\tr12\n|.define TMP1,\t\tr13\n|.define TMP2,\t\tr14\n|.define TMP3,\t\tr15\n|\n|// Calling conventions.\n|.define CFUNCADDR,\tr25\n|.define CARG1,\t\tr4\n|.define CARG2,\t\tr5\n|.define CARG3,\t\tr6\n|.define CARG4,\t\tr7\n|\n|.define CRET1,\t\tr2\n|.define CRET2,\t\tr3\n|\n|.if ENDIAN_LE\n|.define SFRETLO,\tCRET1\n|.define SFRETHI,\tCRET2\n|.define SFARG1LO,\tCARG1\n|.define SFARG1HI,\tCARG2\n|.define SFARG2LO,\tCARG3\n|.define SFARG2HI,\tCARG4\n|.else\n|.define SFRETLO,\tCRET2\n|.define SFRETHI,\tCRET1\n|.define SFARG1LO,\tCARG2\n|.define SFARG1HI,\tCARG1\n|.define SFARG2LO,\tCARG4\n|.define SFARG2HI,\tCARG3\n|.endif\n|\n|.if FPU\n|.define FARG1,\t\tf12\n|.define FARG2,\t\tf14\n|\n|.define FRET1,\t\tf0\n|.define FRET2,\t\tf2\n|.endif\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.if FPU\t\t// MIPS32 hard-float.\n|\n|.define CFRAME_SPACE,\t112\t// Delta for sp.\n|\n|.define SAVE_ERRF,\t124(sp)\t// 32 bit C frame info.\n|.define SAVE_NRES,\t120(sp)\n|.define SAVE_CFRAME,\t116(sp)\n|.define SAVE_L,\t112(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.\n|.define SAVE_GPR_,\t72\t// .. 72+10*4: 32 bit GPR saves.\n|.define SAVE_FPR_,\t24\t// .. 24+6*8: 64 bit FPR saves.\n|\n|.else\t\t\t// MIPS32 soft-float\n|\n|.define CFRAME_SPACE,\t64\t// Delta for sp.\n|\n|.define SAVE_ERRF,\t76(sp)\t// 32 bit C frame info.\n|.define SAVE_NRES,\t72(sp)\n|.define SAVE_CFRAME,\t68(sp)\n|.define SAVE_L,\t64(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.\n|.define SAVE_GPR_,\t24\t// .. 24+10*4: 32 bit GPR saves.\n|\n|.endif\n|\n|.define SAVE_PC,\t20(sp)\n|.define ARG5,\t\t16(sp)\n|.define CSAVE_4,\t12(sp)\n|.define CSAVE_3,\t8(sp)\n|.define CSAVE_2,\t4(sp)\n|.define CSAVE_1,\t0(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee.\n|\n|.define ARG5_OFS,\t16\n|.define SAVE_MULTRES,\tARG5\n|\n|//-----------------------------------------------------------------------\n|\n|.macro saveregs\n|  addiu sp, sp, -CFRAME_SPACE\n|  sw ra, SAVE_GPR_+9*4(sp)\n|  sw r30, SAVE_GPR_+8*4(sp)\n|   .FPU sdc1 f30, SAVE_FPR_+5*8(sp)\n|  sw r23, SAVE_GPR_+7*4(sp)\n|  sw r22, SAVE_GPR_+6*4(sp)\n|   .FPU sdc1 f28, SAVE_FPR_+4*8(sp)\n|  sw r21, SAVE_GPR_+5*4(sp)\n|  sw r20, SAVE_GPR_+4*4(sp)\n|   .FPU sdc1 f26, SAVE_FPR_+3*8(sp)\n|  sw r19, SAVE_GPR_+3*4(sp)\n|  sw r18, SAVE_GPR_+2*4(sp)\n|   .FPU sdc1 f24, SAVE_FPR_+2*8(sp)\n|  sw r17, SAVE_GPR_+1*4(sp)\n|  sw r16, SAVE_GPR_+0*4(sp)\n|   .FPU sdc1 f22, SAVE_FPR_+1*8(sp)\n|   .FPU sdc1 f20, SAVE_FPR_+0*8(sp)\n|.endmacro\n|\n|.macro restoreregs_ret\n|  lw ra, SAVE_GPR_+9*4(sp)\n|  lw r30, SAVE_GPR_+8*4(sp)\n|   .FPU ldc1 f30, SAVE_FPR_+5*8(sp)\n|  lw r23, SAVE_GPR_+7*4(sp)\n|  lw r22, SAVE_GPR_+6*4(sp)\n|   .FPU ldc1 f28, SAVE_FPR_+4*8(sp)\n|  lw r21, SAVE_GPR_+5*4(sp)\n|  lw r20, SAVE_GPR_+4*4(sp)\n|   .FPU ldc1 f26, SAVE_FPR_+3*8(sp)\n|  lw r19, SAVE_GPR_+3*4(sp)\n|  lw r18, SAVE_GPR_+2*4(sp)\n|   .FPU ldc1 f24, SAVE_FPR_+2*8(sp)\n|  lw r17, SAVE_GPR_+1*4(sp)\n|  lw r16, SAVE_GPR_+0*4(sp)\n|   .FPU ldc1 f22, SAVE_FPR_+1*8(sp)\n|   .FPU ldc1 f20, SAVE_FPR_+0*8(sp)\n|  jr ra\n|  addiu sp, sp, CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; .long 0xf0f0f0f0; .endmacro\n|\n|// Macros to mark delay slots.\n|.macro ., a; a; .endmacro\n|.macro ., a,b; a,b; .endmacro\n|.macro ., a,b,c; a,b,c; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Endian-specific defines.\n|.if ENDIAN_LE\n|.define FRAME_PC,\t-4\n|.define FRAME_FUNC,\t-8\n|.define HI,\t\t4\n|.define LO,\t\t0\n|.define OFS_RD,\t2\n|.define OFS_RA,\t1\n|.define OFS_OP,\t0\n|.else\n|.define FRAME_PC,\t-8\n|.define FRAME_FUNC,\t-4\n|.define HI,\t\t0\n|.define LO,\t\t4\n|.define OFS_RD,\t0\n|.define OFS_RA,\t2\n|.define OFS_OP,\t3\n|.endif\n|\n|// Instruction decode.\n|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro\n|.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro\n|.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro\n|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro\n|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro\n|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro\n|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro\n|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro\n|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  lw INS, 0(PC)\n|   addiu PC, PC, 4\n|.endmacro\n|// Instruction decode+dispatch.\n|.macro ins_NEXT2\n|  decode_OP4a TMP1, INS\n|  decode_OP4b TMP1\n|  addu TMP0, DISPATCH, TMP1\n|   decode_RD8a RD, INS\n|  lw AT, 0(TMP0)\n|   decode_RA8a RA, INS\n|   decode_RD8b RD\n|  jr AT\n|   decode_RA8b RA\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  lw PC, LFUNC:RB->pc\n|  lw INS, 0(PC)\n|   addiu PC, PC, 4\n|  decode_OP4a TMP1, INS\n|   decode_RA8a RA, INS\n|  decode_OP4b TMP1\n|   decode_RA8b RA\n|  addu TMP0, DISPATCH, TMP1\n|  lw TMP0, 0(TMP0)\n|  jr TMP0\n|   addu RA, RA, BASE\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  sw PC, FRAME_PC(BASE)\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|.macro branch_RD\n|  srl TMP0, RD, 1\n|  lui AT, (-(BCBIAS_J*4 >> 16) & 65535)\n|  addu TMP0, TMP0, AT\n|  addu PC, PC, TMP0\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n#define GG_DISP2GOT\t\t(GG_OFS(got) - GG_OFS(dispatch))\n#define DISPATCH_GOT(name)\t(GG_DISP2GOT + 4*LJ_GOT_##name)\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro load_got, func\n|  lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)\n|.endmacro\n|// Much faster. Sadly, there's no easy way to force the required code layout.\n|// .macro call_intern, func; bal extern func; .endmacro\n|.macro call_intern, func; jalr CFUNCADDR; .endmacro\n|.macro call_extern; jalr CFUNCADDR; .endmacro\n|.macro jmp_extern; jr CFUNCADDR; .endmacro\n|\n|.macro hotcheck, delta, target\n|  srl TMP1, PC, 1\n|  andi TMP1, TMP1, 126\n|  addu TMP1, TMP1, DISPATCH\n|  lhu TMP2, GG_DISP2HOT(TMP1)\n|  addiu TMP2, TMP2, -delta\n|  bltz TMP2, target\n|.  sh TMP2, GG_DISP2HOT(TMP1)\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL, ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state. Uses TMP0.\n|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro\n|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp, target\n|  lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   andi mark, mark, ~LJ_GC_BLACK & 255\t\t// black2gray(tab)\n|  sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   sb mark, tab->marked\n|  b target\n|.  sw tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: TMP2 = previous base.\n  |  andi AT, PC, FRAME_P\n  |  beqz AT, ->cont_dispatch\n  |.  li TMP1, LJ_TTRUE\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  lw PC, FRAME_PC(TMP2)\t\t// Fetch PC of previous frame.\n  |  move BASE, TMP2\t\t\t// Restore caller base.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   sw TMP1, FRAME_PC(RA)\t\t// Prepend true to results.\n  |   addiu RA, RA, -8\n  |\n  |->vm_returnc:\n  |   addiu RD, RD, 8\t\t\t// RD = (nresults+1)*8.\n  |  andi TMP0, PC, FRAME_TYPE\n  |   beqz RD, ->vm_unwind_c_eh\n  |.   li CRET1, LUA_YIELD\n  |  beqz TMP0, ->BC_RET_Z\t\t// Handle regular return to Lua.\n  |.  move MULTRES, RD\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return\n  |  // TMP0 = PC & FRAME_TYPE\n  |   li TMP2, -8\n  |  xori AT, TMP0, FRAME_C\n  |   and TMP2, PC, TMP2\n  |  bnez AT, ->vm_returnp\n  |   subu TMP2, BASE, TMP2\t\t// TMP2 = previous base.\n  |\n  |  addiu TMP1, RD, -8\n  |   sw TMP2, L->base\n  |    li_vmstate C\n  |   lw TMP2, SAVE_NRES\n  |   addiu BASE, BASE, -8\n  |    st_vmstate\n  |  beqz TMP1, >2\n  |.   sll TMP2, TMP2, 3\n  |1:\n  |  addiu TMP1, TMP1, -8\n  |   lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |    addiu RA, RA, 8\n  |   sw SFRETHI, HI(BASE)\n  |    sw SFRETLO, LO(BASE)\n  |  bnez TMP1, <1\n  |.  addiu BASE, BASE, 8\n  |\n  |2:\n  |  bne TMP2, RD, >6\n  |3:\n  |.  sw BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  lw TMP0, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   move CRET1, r0\t\t\t// Ok return status for vm_pcall.\n  |  sw TMP0, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs_ret\n  |\n  |6:\n  |  lw TMP1, L->maxstack\n  |  slt AT, TMP2, RD\n  |  bnez AT, >7\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |.  slt AT, BASE, TMP1\n  |  beqz AT, >8\n  |.  nop\n  |  sw TISNIL, HI(BASE)\n  |  addiu RD, RD, 8\n  |  b <2\n  |.  addiu BASE, BASE, 8\n  |\n  |7:  // Less results wanted.\n  |  subu TMP0, RD, TMP2\n  |  subu TMP0, BASE, TMP0\t\t// Either keep top or shrink it.\n  |  b <3\n  |.  movn BASE, TMP0, TMP2\t\t// LUA_MULTRET+1 case?\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  load_got lj_state_growstack\n  |   move MULTRES, RD\n  |  srl CARG2, TMP2, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |    lw TMP2, SAVE_NRES\n  |  lw BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |   move RD, MULTRES\n  |  b <2\n  |.   sll TMP2, TMP2, 3\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  move sp, CARG1\n  |  move CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  lw L, SAVE_L\n  |   li TMP0, ~LJ_VMST_C\n  |  lw GL:TMP1, L->glref\n  |  b ->vm_leave_unw\n  |.  sw TMP0, GL:TMP1->vmstate\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  li AT, -4\n  |  and sp, CARG1, AT\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  lw L, SAVE_L\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |     li TISNIL, LJ_TNIL\n  |  lw BASE, L->base\n  |   lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     .FPU mtc1 TMP3, TOBIT\n  |  li TMP1, LJ_TFALSE\n  |    li_vmstate INTERP\n  |  lw PC, FRAME_PC(BASE)\t\t// Fetch PC of previous frame.\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  addiu RA, BASE, -8\t\t\t// Results start at BASE-8.\n  |   addiu DISPATCH, DISPATCH, GG_G2DISP\n  |  sw TMP1, HI(RA)\t\t\t// Prepend false to error message.\n  |    st_vmstate\n  |  b ->vm_returnc\n  |.  li RD, 16\t\t\t\t// 2 results: false + error message.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  b >2\n  |.  li CARG2, LUA_MINSTACK\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  addu RC, BASE, RC\n  |   subu RA, RA, BASE\n  |  sw BASE, L->base\n  |   addiu PC, PC, 4\t\t\t// Must point after first instruction.\n  |  sw RC, L->top\n  |   srl CARG2, RA, 3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  load_got lj_state_growstack\n  |   sw PC, SAVE_PC\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  lw BASE, L->base\n  |  lw RC, L->top\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  subu RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  move L, CARG1\n  |    lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  move BASE, CARG2\n  |    lbu TMP1, L->status\n  |   sw L, SAVE_L\n  |  li PC, FRAME_CP\n  |  addiu TMP0, sp, CFRAME_RESUME\n  |    addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw r0, SAVE_NRES\n  |   sw r0, SAVE_ERRF\n  |   sw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |   sw r0, SAVE_CFRAME\n  |    beqz TMP1, >3\n  |. sw TMP0, L->cframe\n  |\n  |  // Resume after yield (like a return).\n  |  sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  move RA, BASE\n  |   lw BASE, L->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lw TMP1, L->top\n  |  lw PC, FRAME_PC(BASE)\n  |     .FPU  lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   subu RD, TMP1, BASE\n  |     .FPU  mtc1 TMP3, TOBIT\n  |    sb r0, L->status\n  |     .FPU  cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |   addiu RD, RD, 8\n  |    st_vmstate\n  |   move MULTRES, RD\n  |  andi TMP0, PC, FRAME_TYPE\n  |  beqz TMP0, ->BC_RET_Z\n  |.    li TISNIL, LJ_TNIL\n  |  b ->vm_return\n  |.  nop\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  sw CARG4, SAVE_ERRF\n  |  b >1\n  |.  li PC, FRAME_CP\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  li PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  lw TMP1, L:CARG1->cframe\n  |    move L, CARG1\n  |   sw CARG3, SAVE_NRES\n  |    lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   sw CARG1, SAVE_L\n  |     move BASE, CARG2\n  |    addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  sw TMP1, SAVE_CFRAME\n  |  sw sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  lw TMP2, L->base\t\t\t// TMP2 = old base (used in vmeta_call).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   lw TMP1, L->top\n  |     .FPU mtc1 TMP3, TOBIT\n  |  addu PC, PC, BASE\n  |   subu NARGS8:RC, TMP1, BASE\n  |  subu PC, PC, TMP2\t\t\t// PC = frame delta + frame type\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |     li TISNIL, LJ_TNIL\n  |    st_vmstate\n  |\n  |->vm_call_dispatch:\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  lw TMP0, FRAME_PC(BASE)\n  |  li AT, LJ_TFUNC\n  |  bne TMP0, AT, ->vmeta_call\n  |.  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  move L, CARG1\n  |   lw TMP0, L:CARG1->stack\n  |  sw CARG1, SAVE_L\n  |   lw TMP1, L->top\n  |     lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  sw CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   subu TMP0, TMP0, TMP1\t\t// Compute -savestack(L, L->top).\n  |    lw TMP1, L->cframe\n  |     addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw TMP0, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  sw r0, SAVE_ERRF\t\t\t// No error function.\n  |    sw TMP1, SAVE_CFRAME\n  |    sw sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |     sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  jalr CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.  move CFUNCADDR, CARG4\n  |  move BASE, CRET1\n  |  bnez CRET1, <3\t\t\t// Else continue with the call.\n  |.  li PC, FRAME_CP\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |.  nop\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the\n  |// stack, so BASE doesn't need to be reloaded across these calls.\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8\n  |  lw TMP0, -16+LO(BASE)\t\t// Continuation.\n  |   move RB, BASE\n  |   move BASE, TMP2\t\t\t// Restore caller BASE.\n  |    lw LFUNC:TMP1, FRAME_FUNC(TMP2)\n  |.if FFI\n  |  sltiu AT, TMP0, 2\n  |.endif\n  |     lw PC, -16+HI(RB)\t\t// Restore PC from [cont|PC].\n  |   addu TMP2, RA, RD\n  |    lw TMP1, LFUNC:TMP1->pc\n  |.if FFI\n  |  bnez AT, >1\n  |.endif\n  |.  sw TISNIL, -8+HI(TMP2)\t\t// Ensure one valid arg.\n  |  // BASE = base, RA = resultptr, RB = meta base\n  |  jr TMP0\t\t\t\t// Jump to continuation.\n  |.  lw KBASE, PC2PROTO(k)(TMP1)\n  |\n  |.if FFI\n  |1:\n  |  bnez TMP0, ->cont_ffi_callback\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |.  addiu TMP1, RB, -16\n  |  b ->vm_call_tail\n  |.  subu RC, TMP1, BASE\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |   addiu CARG2, RB, -16\n  |  lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |  decode_RB8a MULTRES, INS\n  |   decode_RA8a RA, INS\n  |  decode_RB8b MULTRES\n  |   decode_RA8b RA\n  |  addu TMP1, BASE, MULTRES\n  |   sw BASE, L->base\n  |   subu CARG3, CARG2, TMP1\n  |  sw SFRETHI, HI(CARG2)\n  |  bne TMP1, CARG2, ->BC_CAT_Z\n  |.  sw SFRETLO, LO(CARG2)\n  |  addu RA, BASE, RA\n  |  sw SFRETHI, HI(RA)\n  |  b ->cont_nop\n  |.  sw SFRETLO, LO(RA)\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP0, HI(CARG3)\n  |\n  |->vmeta_tgets:\n  |  addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |  sw TAB:RB, LO(CARG2)\n  |   addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sw TMP0, HI(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP1, HI(CARG3)\n  |\n  |->vmeta_tgetb:\t\t\t// TMP0 = index\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  sw TMP0, LO(CARG3)\n  |  sw TISNUM, HI(CARG3)\n  |\n  |->vmeta_tgetv:\n  |1:\n  |  load_got lj_meta_tget\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  beqz CRET1, >3\n  |.  addiu TMP1, BASE, -FRAME_CONT\n  |  lw SFARG1HI, HI(CRET1)\n  |   lw SFARG2HI, LO(CRET1)\n  |  ins_next1\n  |  sw SFARG1HI, HI(RA)\n  |   sw SFARG2HI, LO(RA)\n  |  ins_next2\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  lw BASE, L->top\n  |  sw PC, -16+HI(BASE)\t\t// [cont|PC]\n  |   subu PC, BASE, TMP1\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(t, k).\n  |\n  |->vmeta_tgetr:\n  |  load_got lj_tab_getinth\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  nop\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->BC_TGETR_Z\n  |.  move SFARG2HI, TISNIL\n  |  lw SFARG2HI, HI(CRET1)\n  |  b ->BC_TGETR_Z\n  |.  lw SFARG2LO, LO(CRET1)\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP0, HI(CARG3)\n  |\n  |->vmeta_tsets:\n  |  addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |  sw TAB:RB, LO(CARG2)\n  |   addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sw TMP0, HI(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP1, HI(CARG3)\n  |\n  |->vmeta_tsetb:\t\t\t// TMP0 = index\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  sw TMP0, LO(CARG3)\n  |  sw TISNUM, HI(CARG3)\n  |\n  |->vmeta_tsetv:\n  |1:\n  |  load_got lj_meta_tset\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  lw SFARG1HI, HI(RA)\n  |  beqz CRET1, >3\n  |.  lw SFARG1LO, LO(RA)\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  ins_next1\n  |  sw SFARG1HI, HI(CRET1)\n  |   sw SFARG1LO, LO(CRET1)\n  |  ins_next2\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  addiu TMP1, BASE, -FRAME_CONT\n  |  lw BASE, L->top\n  |  sw PC, -16+HI(BASE)\t\t// [cont|PC]\n  |   subu PC, BASE, TMP1\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  sw SFARG1HI, 16+HI(BASE)\t\t// Copy value to third argument.\n  |   sw SFARG1LO, 16+LO(BASE)\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 24\t\t\t// 3 args for func(t, k, v)\n  |\n  |->vmeta_tsetr:\n  |  load_got lj_tab_setinth\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |.  move CARG1, L\n  |  // Returns TValue *.\n  |  b ->BC_TSETR_Z\n  |.  nop\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  // RA/RD point to o1/o2.\n  |  move CARG2, RA\n  |  move CARG3, RD\n  |  load_got lj_meta_comp\n  |  addiu PC, PC, -4\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  decode_OP1 CARG4, INS\n  |  call_intern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  sltiu AT, CRET1, 2\n  |  beqz AT, ->vmeta_binop\n  |   negu TMP2, CRET1\n  |4:\n  |  lhu RD, OFS_RD(PC)\n  |   addiu PC, PC, 4\n  |   lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)\n  |  sll RD, RD, 2\n  |  addu RD, RD, TMP1\n  |  and RD, RD, TMP2\n  |  addu PC, PC, RD\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  lbu TMP1, -4+OFS_RA(PC)\n  |   lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, BASE, TMP1\n  |   sw SFRETHI, HI(TMP1)\n  |  b ->cont_nop\n  |.   sw SFRETLO, LO(TMP1)\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  lw TMP0, HI(RA)\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  negu TMP2, AT\t\t\t// Branch if result is true.\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  lw TMP0, HI(RA)\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  addiu TMP2, AT, -1\t\t// Branch if result is false.\n  |\n  |->vmeta_equal:\n  |  // SFARG1LO/SFARG2LO point to o1/o2. TMP0 is set to 0/1.\n  |  load_got lj_meta_equal\n  |   move CARG2, SFARG1LO\n  |   move CARG3, SFARG2LO\n  |   move CARG4, TMP0\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  load_got lj_meta_equal_cd\n  |  move CARG2, INS\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_equal_cd\t// (lua_State *L, BCIns op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |->vmeta_istype:\n  |  load_got lj_meta_istype\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   srl CARG2, RA, 3\n  |   srl CARG3, RD, 3\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |.  move CARG1, L\n  |  b ->cont_nop\n  |.  nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_unm:\n  |  move RC, RB\n  |\n  |->vmeta_arith:\n  |  load_got lj_meta_arith\n  |  decode_OP1 TMP0, INS\n  |   sw BASE, L->base\n  |  move CARG2, RA\n  |   sw PC, SAVE_PC\n  |  move CARG3, RB\n  |  move CARG4, RC\n  |  sw TMP0, ARG5\n  |  call_intern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |.  move CARG1, L\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  beqz CRET1, ->cont_nop\n  |.  nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  subu TMP1, CRET1, BASE\n  |   sw PC, -16+HI(CRET1)\t\t// [cont|PC]\n  |   move TMP2, BASE\n  |  addiu PC, TMP1, FRAME_CONT\n  |   move BASE, CRET1\n  |  b ->vm_call_dispatch\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(o1, o2).\n  |\n  |->vmeta_len:\n  |  // CARG2 already set by BC_LEN.\n#if LJ_52\n  |  move MULTRES, CARG1\n#endif\n  |  load_got lj_meta_len\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |.  move CARG1, L\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  bnez CRET1, ->vmeta_binop\t\t// Binop call for compatibility.\n  |.  nop\n  |  b ->BC_LEN_Z\n  |.  move CARG1, MULTRES\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |.  nop\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sw TMP2, L->base\t\t\t// This is the callers base!\n  |  addiu CARG2, BASE, -8\n  |   sw PC, SAVE_PC\n  |  addu CARG3, BASE, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   addiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sw BASE, L->base\n  |  addiu CARG2, RA, -8\n  |   sw PC, SAVE_PC\n  |  addu CARG3, RA, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |  lw TMP1, FRAME_PC(BASE)\n  |   lw LFUNC:RB, FRAME_FUNC(RA)\t// Guaranteed to be a function here.\n  |  b ->BC_CALLT_Z\n  |.  addiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  load_got lj_meta_for\n  |   sw BASE, L->base\n  |  move CARG2, RA\n  |   sw PC, SAVE_PC\n  |  move MULTRES, INS\n  |  call_intern lj_meta_for\t// (lua_State *L, TValue *base)\n  |.  move CARG1, L\n  |.if JIT\n  |  decode_OP1 TMP0, MULTRES\n  |  li AT, BC_JFORI\n  |.endif\n  |  decode_RA8a RA, MULTRES\n  |   decode_RD8a RD, MULTRES\n  |  decode_RA8b RA\n  |.if JIT\n  |  beq TMP0, AT, =>BC_JFORI\n  |.  decode_RD8b RD\n  |  b =>BC_FORI\n  |.  nop\n  |.else\n  |  b =>BC_FORI\n  |.  decode_RD8b RD\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw SFARG1LO, LO(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.   lw SFARG2HI, 8+HI(BASE)\n  |   lw SFARG1LO, LO(BASE)\n  |    lw SFARG2LO, 8+LO(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  lw SFARG1HI, HI(BASE)\n  |.if FPU\n  |   ldc1 FARG1, 0(BASE)\n  |.else\n  |   lw SFARG1LO, LO(BASE)\n  |.endif\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  lw SFARG2HI, 8+HI(BASE)\n  |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n  |.if FPU\n  |   ldc1 FARG1, 0(BASE)\n  |.else\n  |   lw SFARG1LO, LO(BASE)\n  |.endif\n  |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n  |.if FPU\n  |   ldc1 FARG2, 8(BASE)\n  |.else\n  |   lw SFARG2LO, 8+LO(BASE)\n  |.endif\n  |  and TMP0, TMP0, TMP1\n  |  beqz TMP0, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!\n  |.macro ffgccheck\n  |  lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n  |  lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n  |  subu AT, TMP0, TMP1\n  |  bgezal AT, ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  sltiu AT, SFARG1HI, LJ_TISTRUECOND\n  |  beqz AT, ->fff_fallback\n  |.  addiu RA, BASE, -8\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RD, NARGS8:RC, 8\t\t// Compute (nresults+1)*8.\n  |  addu TMP2, RA, NARGS8:RC\n  |   sw SFARG1HI, HI(RA)\n  |  addiu TMP1, BASE, 8\n  |  beq BASE, TMP2, ->fff_res\t\t// Done if exactly 1 argument.\n  |.  sw SFARG1LO, LO(RA)\n  |1:\n  |  lw SFRETHI, HI(TMP1)\n  |   lw SFRETLO, LO(TMP1)\n  |  sw SFRETHI, -8+HI(TMP1)\n  |   sw SFRETLO, -8+LO(TMP1)\n  |  bne TMP1, TMP2, <1\n  |.  addiu TMP1, TMP1, 8\n  |  b ->fff_res\n  |.  nop\n  |\n  |.ffunc type\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  sltiu TMP0, SFARG1HI, LJ_TISNUM\n  |  movn SFARG1HI, TISNUM, TMP0\n  |  not TMP1, SFARG1HI\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, CFUNC:RB, TMP1\n  |  lw SFARG1HI, CFUNC:TMP1->upvalue[0].u32.hi\n  |  b ->fff_restv\n  |.  lw SFARG1LO, CFUNC:TMP1->upvalue[0].u32.lo\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, >6\n  |.  li AT, LJ_TUDATA\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  lw TAB:SFARG1LO, TAB:SFARG1LO->metatable\n  |2:\n  |  lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)\n  |  beqz TAB:SFARG1LO, ->fff_restv\n  |.  li SFARG1HI, LJ_TNIL\n  |  lw TMP0, TAB:SFARG1LO->hmask\n  |   li SFARG1HI, LJ_TTAB\t\t// Use metatable as default result.\n  |  lw TMP1, STR:RC->hash\n  |  lw NODE:TMP2, TAB:SFARG1LO->node\n  |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n  |  sll TMP0, TMP1, 5\n  |  sll TMP1, TMP1, 3\n  |  subu TMP1, TMP0, TMP1\n  |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n  |  li AT, LJ_TSTR\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  lw CARG4, offsetof(Node, key)+HI(NODE:TMP2)\n  |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n  |    lw NODE:TMP3, NODE:TMP2->next\n  |  bne CARG4, AT, >4\n  |.    lw CARG3, offsetof(Node, val)+HI(NODE:TMP2)\n  |  beq TMP0, STR:RC, >5\n  |.    lw TMP1, offsetof(Node, val)+LO(NODE:TMP2)\n  |4:\n  |  beqz NODE:TMP3, ->fff_restv\t// Not found, keep default result.\n  |.  move NODE:TMP2, NODE:TMP3\n  |  b <3\n  |.  nop\n  |5:\n  |  beq CARG3, TISNIL, ->fff_restv\t// Ditto for nil value.\n  |.  nop\n  |  move SFARG1HI, CARG3\t\t// Return value of mt.__metatable.\n  |  b ->fff_restv\n  |.  move SFARG1LO, TMP1\n  |\n  |6:\n  |  beq SFARG1HI, AT, <1\n  |.  sltu AT, TISNUM, SFARG1HI\n  |  movz SFARG1HI, TISNUM, AT\n  |  not TMP1, SFARG1HI\n  |  sll TMP1, TMP1, 2\n  |  addu TMP1, DISPATCH, TMP1\n  |  b <2\n  |.  lw TAB:SFARG1LO, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1)\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  addiu SFARG2HI, SFARG2HI, -LJ_TTAB\n  |  lw TAB:TMP1, TAB:SFARG1LO->metatable\n  |   lbu TMP3, TAB:SFARG1LO->marked\n  |  or AT, SFARG2HI, TAB:TMP1\n  |  bnez AT, ->fff_fallback\n  |.  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n  |  beqz AT, ->fff_restv\n  |.  sw TAB:SFARG2LO, TAB:SFARG1LO->metatable\n  |  barrierback TAB:SFARG1LO, TMP3, TMP0, ->fff_restv\n  |\n  |.ffunc rawget\n  |  lw CARG4, HI(BASE)\n  |   sltiu AT, NARGS8:RC, 16\n  |    lw TAB:CARG2, LO(BASE)\n  |  load_got lj_tab_get\n  |  addiu CARG4, CARG4, -LJ_TTAB\n  |  or AT, AT, CARG4\n  |  bnez AT, ->fff_fallback\n  |   addiu CARG3, BASE, 8\n  |  call_intern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |.  move CARG1, L\n  |  // Returns cTValue *.\n  |  lw SFARG1HI, HI(CRET1)\n  |  b ->fff_restv\n  |.  lw SFARG1LO, LO(CRET1)\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  lw CARG1, HI(BASE)\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly one number argument.\n  |  sltu TMP0, TISNUM, CARG1\n  |  or AT, AT, TMP0\n  |  bnez AT, ->fff_fallback\n  |.  lw SFARG1HI, HI(BASE)\n  |  b ->fff_restv\n  |.  lw SFARG1LO, LO(BASE)\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  li AT, LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq SFARG1HI, AT, ->fff_restv\t// String key?\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |.  lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)\n  |  sltu TMP0, TISNUM, SFARG1HI\n  |  or TMP0, TMP0, TMP1\n  |  bnez TMP0, ->fff_fallback\n  |.  sw BASE, L->base\t\t\t// Add frame since C call can throw.\n  |  ffgccheck\n  |.  sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  load_got lj_strfmt_number\n  |  move CARG1, L\n  |  call_intern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |.  move CARG2, BASE\n  |  // Returns GCstr *.\n  |  li SFARG1HI, LJ_TSTR\n  |  b ->fff_restv\n  |.  move SFARG1LO, CRET1\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc next\n  |  lw CARG1, HI(BASE)\n  |   lw TAB:CARG2, LO(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  addu TMP2, BASE, NARGS8:RC\n  |  li AT, LJ_TTAB\n  |   sw TISNIL, HI(TMP2)\t\t// Set missing 2nd arg to nil.\n  |  bne CARG1, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n  |  load_got lj_tab_next\n  |   sw BASE, L->base\t\t\t// Add frame since C call can throw.\n  |   sw BASE, L->top\t\t\t// Dummy frame length is ok.\n  |  addiu CARG3, BASE, 8\n  |   sw PC, SAVE_PC\n  |  call_intern lj_tab_next\t\t// (lua_State *L, GCtab *t, TValue *key)\n  |.  move CARG1, L\n  |  // Returns 0 at end of traversal.\n  |  beqz CRET1, ->fff_restv\t\t// End of traversal: return nil.\n  |.  li SFARG1HI, LJ_TNIL\n  |  lw TMP0, 8+HI(BASE)\n  |   lw TMP1, 8+LO(BASE)\n  |    addiu RA, BASE, -8\n  |  lw TMP2, 16+HI(BASE)\n  |   lw TMP3, 16+LO(BASE)\n  |  sw TMP0, HI(RA)\n  |   sw TMP1, LO(RA)\n  |  sw TMP2, 8+HI(RA)\n  |   sw TMP3, 8+LO(RA)\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.ffunc_1 pairs\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n#if LJ_52\n  |  lw TAB:TMP2, TAB:SFARG1LO->metatable\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n#endif\n  |.  addiu RA, BASE, -8\n  |   sw TISNIL, 8+HI(BASE)\n  |  sw TMP0, HI(RA)\n  |   sw TMP1, LO(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |.ffunc ipairs_aux\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw CARG3, HI(BASE)\n  |    lw TAB:CARG1, LO(BASE)\n  |   lw CARG4, 8+HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  addiu CARG3, CARG3, -LJ_TTAB\n  |  xor CARG4, CARG4, TISNUM\n  |  and AT, CARG3, CARG4\n  |  bnez AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n  |  lw TMP2, 8+LO(BASE)\n  |   lw TMP0, TAB:CARG1->asize\n  |   lw TMP1, TAB:CARG1->array\n  |  addiu TMP2, TMP2, 1\n  |  sw TISNUM, -8+HI(BASE)\n  |  sltu AT, TMP2, TMP0\n  |   sw TMP2, -8+LO(BASE)\n  |  beqz AT, >2\t\t\t// Not in array part?\n  |.  addiu RA, BASE, -8\n  |   sll TMP3, TMP2, 3\n  |   addu TMP3, TMP1, TMP3\n  |  lw TMP1, HI(TMP3)\n  |   lw TMP2, LO(TMP3)\n  |1:\n  |  beq TMP1, TISNIL, ->fff_res\t// End of iteration, return 0 results.\n  |.  li RD, (0+1)*8\n  |  sw TMP1, 8+HI(RA)\n  |   sw TMP2, 8+LO(RA)\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lw TMP0, TAB:CARG1->hmask\n  |  load_got lj_tab_getinth\n  |  beqz TMP0, ->fff_res\n  |.  li RD, (0+1)*8\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  move CARG2, TMP2\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->fff_res\n  |.  li RD, (0+1)*8\n  |  lw TMP1, HI(CRET1)\n  |  b <1\n  |.  lw TMP2, LO(CRET1)\n  |\n  |.ffunc_1 ipairs\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n#if LJ_52\n  |  lw TAB:TMP2, TAB:SFARG1LO->metatable\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n#endif\n  |.  addiu RA, BASE, -8\n  |   sw TISNUM, 8+HI(BASE)\n  |   sw r0, 8+LO(BASE)\n  |  sw TMP0, HI(RA)\n  |   sw TMP1, LO(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |   move TMP2, BASE\n  |   addiu BASE, BASE, 8\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |  andi TMP3, TMP3, 1\n  |  addiu PC, TMP3, 8+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |.  addiu NARGS8:RC, NARGS8:RC, -8\n  |\n  |.ffunc xpcall\n  |    sltiu AT, NARGS8:RC, 16\n  |  lw CARG4, 8+HI(BASE)\n  |    bnez AT, ->fff_fallback\n  |.  lw CARG3, 8+LO(BASE)\n  |   lw CARG1, LO(BASE)\n  |    lw CARG2, HI(BASE)\n  |    lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)\n  |  li AT, LJ_TFUNC\n  |   move TMP2, BASE\n  |  bne CARG4, AT, ->fff_fallback  // Traceback must be a function.\n  |   addiu BASE, BASE, 16\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |   sw CARG3, LO(TMP2)\t// Swap function and traceback.\n  |   sw CARG4, HI(TMP2)\n  |  andi TMP3, TMP3, 1\n  |   sw CARG1, 8+LO(TMP2)\n  |    sw CARG2, 8+HI(TMP2)\n  |  addiu PC, TMP3, 16+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |.  addiu NARGS8:RC, NARGS8:RC, -16\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc coroutine_resume\n  |  lw CARG3, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw CARG1, LO(BASE)\n  |  li AT, LJ_TTHREAD\n  |  bne CARG3, AT, ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  lw L:CARG1, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  lbu TMP0, L:CARG1->status\n  |   lw TMP1, L:CARG1->cframe\n  |    lw CARG2, L:CARG1->top\n  |    lw TMP2, L:CARG1->base\n  |  addiu TMP3, TMP0, -LUA_YIELD\n  |  bgtz TMP3, ->fff_fallback\t\t// st > LUA_YIELD?\n  |.   xor TMP2, TMP2, CARG2\n  |  bnez TMP1, ->fff_fallback\t\t// cframe != 0?\n  |.  or AT, TMP2, TMP0\n  |  lw TMP0, L:CARG1->maxstack\n  |  beqz AT, ->fff_fallback\t\t// base == top && st == 0?\n  |.  lw PC, FRAME_PC(BASE)\n  |  addu TMP2, CARG2, NARGS8:RC\n  |  sltu AT, TMP0, TMP2\n  |  bnez AT, ->fff_fallback\t\t// Stack overflow?\n  |.  sw PC, SAVE_PC\n  |   sw BASE, L->base\n  |1:\n  |.if resume\n  |  addiu BASE, BASE, 8\t\t// Keep resumed thread in stack for GC.\n  |  addiu NARGS8:RC, NARGS8:RC, -8\n  |  addiu TMP2, TMP2, -8\n  |.endif\n  |  sw TMP2, L:CARG1->top\n  |  addu TMP1, BASE, NARGS8:RC\n  |  move CARG3, CARG2\n  |  sw BASE, L->top\n  |2:  // Move args to coroutine.\n  |   lw SFRETHI, HI(BASE)\n  |    lw SFRETLO, LO(BASE)\n  |  sltu AT, BASE, TMP1\n  |  beqz AT, >3\n  |.  addiu BASE, BASE, 8\n  |   sw SFRETHI, HI(CARG3)\n  |    sw SFRETLO, LO(CARG3)\n  |  b <2\n  |.  addiu CARG3, CARG3, 8\n  |3:\n  |  bal ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |.  move L:RA, L:CARG1\n  |  // Returns thread status.\n  |4:\n  |  lw TMP2, L:RA->base\n  |   sltiu AT, CRET1, LUA_YIELD+1\n  |  lw TMP3, L:RA->top\n  |    li_vmstate INTERP\n  |  lw BASE, L->base\n  |    sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |    st_vmstate\n  |   beqz AT, >8\n  |. subu RD, TMP3, TMP2\n  |   lw TMP0, L->maxstack\n  |  beqz RD, >6\t\t\t// No results?\n  |.  addu TMP1, BASE, RD\n  |  sltu AT, TMP0, TMP1\n  |  bnez AT, >9\t\t\t// Need to grow stack?\n  |.  addu TMP3, TMP2, RD\n  |  sw TMP2, L:RA->top\t\t\t// Clear coroutine stack.\n  |  move TMP1, BASE\n  |5:  // Move results from coroutine.\n  |   lw SFRETHI, HI(TMP2)\n  |    lw SFRETLO, LO(TMP2)\n  |  addiu TMP2, TMP2, 8\n  |  sltu AT, TMP2, TMP3\n  |   sw SFRETHI, HI(TMP1)\n  |    sw SFRETLO, LO(TMP1)\n  |  bnez AT, <5\n  |.  addiu TMP1, TMP1, 8\n  |6:\n  |  andi TMP0, PC, FRAME_TYPE\n  |.if resume\n  |  li TMP1, LJ_TTRUE\n  |   addiu RA, BASE, -8\n  |  sw TMP1, -8+HI(BASE)\t\t// Prepend true to results.\n  |  addiu RD, RD, 16\n  |.else\n  |  move RA, BASE\n  |  addiu RD, RD, 8\n  |.endif\n  |7:\n  |  sw PC, SAVE_PC\n  |  beqz TMP0, ->BC_RET_Z\n  |.  move MULTRES, RD\n  |  b ->vm_return\n  |.  nop\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  addiu TMP3, TMP3, -8\n  |   li TMP1, LJ_TFALSE\n  |  lw SFRETHI, HI(TMP3)\n  |   lw SFRETLO, LO(TMP3)\n  |   sw TMP3, L:RA->top\t\t// Remove error from coroutine stack.\n  |    li RD, (2+1)*8\n  |   sw TMP1, -8+HI(BASE)\t\t// Prepend false to results.\n  |    addiu RA, BASE, -8\n  |  sw SFRETHI, HI(BASE)\t\t// Copy error message.\n  |   sw SFRETLO, LO(BASE)\n  |  b <7\n  |.  andi TMP0, PC, FRAME_TYPE\n  |.else\n  |  load_got lj_ffh_coroutine_wrap_err\n  |  move CARG2, L:RA\n  |  call_intern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |.  move CARG1, L\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  load_got lj_state_growstack\n  |  srl CARG2, RD, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  b <4\n  |.  li CRET1, 0\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  lw TMP0, L->cframe\n  |   addu TMP1, BASE, NARGS8:RC\n  |   sw BASE, L->base\n  |  andi TMP0, TMP0, CFRAME_RESUME\n  |   sw TMP1, L->top\n  |  beqz TMP0, ->fff_fallback\n  |.   li CRET1, LUA_YIELD\n  |  sw r0, L->cframe\n  |  b ->vm_leave_unw\n  |.   sb CRET1, L->status\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  bne SFARG1HI, TISNUM, >1\n  |.  sra TMP0, SFARG1LO, 31\n  |  xor TMP1, SFARG1LO, TMP0\n  |  subu SFARG1LO, TMP1, TMP0\n  |  bgez SFARG1LO, ->fff_restv\n  |.  nop\n  |  lui SFARG1HI, 0x41e0\t\t// 2^31 as a double.\n  |  b ->fff_restv\n  |.  li SFARG1LO, 0\n  |1:\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  sll SFARG1HI, SFARG1HI, 1\n  |  srl SFARG1HI, SFARG1HI, 1\n  |// fallthrough\n  |\n  |->fff_restv:\n  |  // SFARG1LO/SFARG1HI = TValue result.\n  |  lw PC, FRAME_PC(BASE)\n  |   sw SFARG1HI, -8+HI(BASE)\n  |  addiu RA, BASE, -8\n  |   sw SFARG1LO, -8+LO(BASE)\n  |->fff_res1:\n  |  // RA = results, PC = return.\n  |  li RD, (1+1)*8\n  |->fff_res:\n  |  // RA = results, RD = (nresults+1)*8, PC = return.\n  |  andi TMP0, PC, FRAME_TYPE\n  |  bnez TMP0, ->vm_return\n  |.  move MULTRES, RD\n  |  lw INS, -4(PC)\n  |  decode_RB8a RB, INS\n  |  decode_RB8b RB\n  |5:\n  |  sltu AT, RD, RB\n  |  bnez AT, >6\t\t\t// More results expected?\n  |.  decode_RA8a TMP0, INS\n  |  decode_RA8b TMP0\n  |  ins_next1\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |   subu BASE, RA, TMP0\n  |  ins_next2\n  |\n  |6:  // Fill up results with nil.\n  |  addu TMP1, RA, RD\n  |   addiu RD, RD, 8\n  |  b <5\n  |.  sw TISNIL, -8+HI(TMP1)\n  |\n  |.macro math_extern, func\n  |  .ffunc math_ .. func\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  load_got func\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |.  load_got func\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |// TODO: Return integer type if result is integer (own sf implementation).\n  |.macro math_round, func\n  |->ff_math_ .. func:\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw SFARG1LO, LO(BASE)\n  |  beq SFARG1HI, TISNUM, ->fff_restv\n  |.  sltu AT, SFARG1HI, TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  bal ->vm_ .. func\n  |.else\n  |.  load_got func\n  |  call_extern\n  |.endif\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  li AT, 8\n  |  bne NARGS8:RC, AT, ->fff_fallback\t// Exactly 1 argument.\n  |.  lw SFARG1HI, HI(BASE)\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  load_got log\n  |.if FPU\n  |  call_extern\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |  call_extern\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  b ->fff_resn\n  |.  nop\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if FPU\n  |.ffunc_n math_sqrt\n  |.  sqrt.d FRET1, FARG1\n  |// fallthrough to ->fff_resn\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |->fff_resn:\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |  b ->fff_res1\n  |.  sdc1 FRET1, -8(BASE)\n  |.else\n  |  sw SFRETHI, -8+HI(BASE)\n  |  b ->fff_res1\n  |.  sw SFRETLO, -8+LO(BASE)\n  |.endif\n  |\n  |\n  |.ffunc math_ldexp\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.   lw CARG4, 8+HI(BASE)\n  |  bne CARG4, TISNUM, ->fff_fallback\n  |  load_got ldexp\n  |.  sltu AT, SFARG1HI, TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  call_extern\n  |.  lw CARG3, 8+LO(BASE)\n  |  b ->fff_resn\n  |.  nop\n  |\n  |.ffunc_n math_frexp\n  |  load_got frexp\n  |   lw PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |   lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |   mtc1 TMP1, FARG2\n  |  sdc1 FRET1, 0(RA)\n  |   cvt.d.w FARG2, FARG2\n  |   sdc1 FARG2, 8(RA)\n  |.else\n  |  sw SFRETLO, LO(RA)\n  |  sw SFRETHI, HI(RA)\n  |  sw TMP1, 8+LO(RA)\n  |  sw TISNUM, 8+HI(RA)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.ffunc_n math_modf\n  |  load_got modf\n  |   lw PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  addiu CARG3, BASE, -8\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |  sdc1 FRET1, 0(BASE)\n  |.else\n  |  sw SFRETLO, LO(BASE)\n  |  sw SFRETHI, HI(BASE)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.macro math_minmax, name, intins, fpins\n  |  .ffunc_1 name\n  |  addu TMP3, BASE, NARGS8:RC\n  |  bne SFARG1HI, TISNUM, >5\n  |.  addiu TMP2, BASE, 8\n  |1:  // Handle integers.\n  |.  lw SFARG2HI, HI(TMP2)\n  |  beq TMP2, TMP3, ->fff_restv\n  |.  lw SFARG2LO, LO(TMP2)\n  |  bne SFARG2HI, TISNUM, >3\n  |.  slt AT, SFARG1LO, SFARG2LO\n  |  intins SFARG1LO, SFARG2LO, AT\n  |  b <1\n  |.  addiu TMP2, TMP2, 8\n  |\n  |3:  // Convert intermediate result to number and continue with number loop.\n  |  sltiu AT, SFARG2HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  mtc1 SFARG1LO, FRET1\n  |  cvt.d.w FRET1, FRET1\n  |  b >7\n  |.  ldc1 FARG1, 0(TMP2)\n  |.else\n  |.  nop\n  |  bal ->vm_sfi2d_1\n  |.  nop\n  |  b >7\n  |.  nop\n  |.endif\n  |\n  |5:\n  |.  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FRET1, 0(BASE)\n  |.endif\n  |\n  |6:  // Handle numbers.\n  |.  lw SFARG2HI, HI(TMP2)\n  |.if FPU\n  |  beq TMP2, TMP3, ->fff_resn\n  |.else\n  |  beq TMP2, TMP3, ->fff_restv\n  |.endif\n  |.  sltiu AT, SFARG2HI, LJ_TISNUM\n  |  beqz AT, >8\n  |.if FPU\n  |.  ldc1 FARG1, 0(TMP2)\n  |.else\n  |.  lw SFARG2LO, LO(TMP2)\n  |.endif\n  |7:\n  |.if FPU\n  |  c.olt.d FRET1, FARG1\n  |  fpins FRET1, FARG1\n  |.else\n  |  bal ->vm_sfcmpolt\n  |.  nop\n  |  intins SFARG1LO, SFARG2LO, CRET1\n  |  intins SFARG1HI, SFARG2HI, CRET1\n  |.endif\n  |  b <6\n  |.  addiu TMP2, TMP2, 8\n  |\n  |8:  // Convert integer to number and continue with number loop.\n  |  bne SFARG2HI, TISNUM, ->fff_fallback\n  |.if FPU\n  |.  lwc1 FARG1, LO(TMP2)\n  |  b <7\n  |.  cvt.d.w FARG1, FARG1\n  |.else\n  |.  nop\n  |  bal ->vm_sfi2d_2\n  |.  nop\n  |  b <7\n  |.  nop\n  |.endif\n  |\n  |.endmacro\n  |\n  |  math_minmax math_min, movz, movf.d\n  |  math_minmax math_max, movn, movt.d\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  lw CARG3, HI(BASE)\n  |   lw STR:CARG1, LO(BASE)\n  |  xori AT, NARGS8:RC, 8\n  |  addiu CARG3, CARG3, -LJ_TSTR\n  |  or AT, AT, CARG3\n  |  bnez AT, ->fff_fallback\t\t// Need exactly 1 string argument.\n  |.  nop\n  |  lw TMP0, STR:CARG1->len\n  |    addiu RA, BASE, -8\n  |    lw PC, FRAME_PC(BASE)\n  |  sltu RD, r0, TMP0\n  |   lbu TMP1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |  addiu RD, RD, 1\n  |  sll RD, RD, 3\t\t\t// RD = ((str->len != 0)+1)*8\n  |  sw TISNUM, HI(RA)\n  |  b ->fff_res\n  |.  sw TMP1, LO(RA)\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |.  lw CARG3, HI(BASE)\n  |   lw CARG1, LO(BASE)\n  |  li TMP1, 255\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly 1 argument.\n  |  xor TMP0, CARG3, TISNUM\t\t// Integer.\n  |   sltu TMP1, TMP1, CARG1\t\t// !(255 < n).\n  |  or AT, AT, TMP0\n  |   or AT, AT, TMP1\n  |  bnez AT, ->fff_fallback\n  |.  li CARG3, 1\n  |  addiu CARG2, sp, ARG5_OFS\n  |  sb CARG1, ARG5\n  |->fff_newstr:\n  |  load_got lj_str_new\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |.  move CARG1, L\n  |  // Returns GCstr *.\n  |  lw BASE, L->base\n  |->fff_resstr:\n  |  move SFARG1LO, CRET1\n  |  b ->fff_restv\n  |.  li SFARG1HI, LJ_TSTR\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |.  addiu AT, NARGS8:RC, -16\n  |   lw CARG3, 16+HI(BASE)\n  |   lw TMP0, HI(BASE)\n  |    lw STR:CARG1, LO(BASE)\n  |  bltz AT, ->fff_fallback\n  |.  lw CARG2, 8+HI(BASE)\n  |  beqz AT, >1\n  |.  li CARG4, -1\n  |  bne CARG3, TISNUM, ->fff_fallback\n  |.  lw CARG4, 16+LO(BASE)\n  |1:\n  |  bne CARG2, TISNUM, ->fff_fallback\n  |.  li AT, LJ_TSTR\n  |  bne TMP0, AT, ->fff_fallback\n  |.  lw CARG3, 8+LO(BASE)\n  |  lw CARG2, STR:CARG1->len\n  |  // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end\n  |  slt AT, CARG4, r0\n  |  addiu TMP0, CARG2, 1\n  |  addu TMP1, CARG4, TMP0\n  |   slt TMP3, CARG3, r0\n  |  movn CARG4, TMP1, AT\t\t// if (end < 0) end += len+1\n  |   addu TMP1, CARG3, TMP0\n  |   movn CARG3, TMP1, TMP3\t\t// if (start < 0) start += len+1\n  |   li TMP2, 1\n  |  slt AT, CARG4, r0\n  |   slt TMP3, r0, CARG3\n  |  movn CARG4, r0, AT\t\t\t// if (end < 0) end = 0\n  |   movz CARG3, TMP2, TMP3\t\t// if (start < 1) start = 1\n  |  slt AT, CARG2, CARG4\n  |  movn CARG4, CARG2, AT\t\t// if (end > len) end = len\n  |   addu CARG2, STR:CARG1, CARG3\n  |  subu CARG3, CARG4, CARG3\t\t// len = end - start\n  |   addiu CARG2, CARG2, sizeof(GCstr)-1\n  |  bgez CARG3, ->fff_newstr\n  |.  addiu CARG3, CARG3, 1\t\t// len++\n  |->fff_emptystr:  // Return empty string.\n  |  addiu STR:SFARG1LO, DISPATCH, DISPATCH_GL(strempty)\n  |  b ->fff_restv\n  |.  li SFARG1HI, LJ_TSTR\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |.  lw CARG3, HI(BASE)\n  |   lw STR:CARG2, LO(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  li AT, LJ_TSTR\n  |  bne CARG3, AT, ->fff_fallback\n  |.  addiu SBUF:CARG1, DISPATCH, DISPATCH_GL(tmpbuf)\n  |  load_got lj_buf_putstr_ .. name\n  |  lw TMP0, SBUF:CARG1->b\n  |   sw L, SBUF:CARG1->L\n  |   sw BASE, L->base\n  |  sw TMP0, SBUF:CARG1->p\n  |  call_intern extern lj_buf_putstr_ .. name\n  |.  sw PC, SAVE_PC\n  |  load_got lj_buf_tostr\n  |  call_intern lj_buf_tostr\n  |.  move SBUF:CARG1, SBUF:CRET1\n  |  b ->fff_resstr\n  |.  lw BASE, L->base\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |->vm_tobit_fb:\n  |  beqz TMP1, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  add.d FARG1, FARG1, TOBIT\n  |  jr ra\n  |.  mfc1 CRET1, FARG1\n  |.else\n  |// FP number to bit conversion for soft-float.\n  |->vm_tobit:\n  |  sll TMP0, SFARG1HI, 1\n  |  lui AT, 0x0020\n  |  addu TMP0, TMP0, AT\n  |  slt AT, TMP0, r0\n  |  movz SFARG1LO, r0, AT\n  |  beqz AT, >2\n  |.  li TMP1, 0x3e0\n  |  not TMP1, TMP1\n  |  sra TMP0, TMP0, 21\n  |  subu TMP0, TMP1, TMP0\n  |  slt AT, TMP0, r0\n  |  bnez AT, >1\n  |.  sll TMP1, SFARG1HI, 11\n  |  lui AT, 0x8000\n  |  or TMP1, TMP1, AT\n  |  srl AT, SFARG1LO, 21\n  |  or TMP1, TMP1, AT\n  |  slt AT, SFARG1HI, r0\n  |  beqz AT, >2\n  |.  srlv SFARG1LO, TMP1, TMP0\n  |  subu SFARG1LO, r0, SFARG1LO\n  |2:\n  |  jr ra\n  |.  move CRET1, SFARG1LO\n  |1:\n  |  addiu TMP0, TMP0, 21\n  |  srlv TMP1, SFARG1LO, TMP0\n  |  li AT, 20\n  |  subu TMP0, AT, TMP0\n  |  sll SFARG1LO, SFARG1HI, 12\n  |  sllv AT, SFARG1LO, TMP0\n  |  or SFARG1LO, TMP1, AT\n  |  slt AT, SFARG1HI, r0\n  |  beqz AT, <2\n  |.  nop\n  |  jr ra\n  |.  subu CRET1, r0, SFARG1LO\n  |.endif\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  beq SFARG1HI, TISNUM, >6\n  |.  move CRET1, SFARG1LO\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |6:\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  addiu TMP2, BASE, 8\n  |  addu TMP3, BASE, NARGS8:RC\n  |1:\n  |  lw SFARG1HI, HI(TMP2)\n  |  beq TMP2, TMP3, ->fff_resi\n  |.  lw SFARG1LO, LO(TMP2)\n  |.if FPU\n  |  bne SFARG1HI, TISNUM, >2\n  |.  addiu TMP2, TMP2, 8\n  |  b <1\n  |.  ins CRET1, CRET1, SFARG1LO\n  |2:\n  |   ldc1 FARG1, -8(TMP2)\n  |  sltu TMP1, SFARG1HI, TISNUM\n  |  beqz TMP1, ->fff_fallback\n  |.  add.d FARG1, FARG1, TOBIT\n  |  mfc1 SFARG1LO, FARG1\n  |  b <1\n  |.  ins CRET1, CRET1, SFARG1LO\n  |.else\n  |  beq SFARG1HI, TISNUM, >2\n  |.  move CRET2, CRET1\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |  move SFARG1LO, CRET2\n  |2:\n  |  ins CRET1, CRET1, SFARG1LO\n  |  b <1\n  |.  addiu TMP2, TMP2, 8\n  |.endif\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, or\n  |.ffunc_bit_op bxor, xor\n  |\n  |.ffunc_bit bswap\n  |  srl TMP0, CRET1, 24\n  |   srl TMP2, CRET1, 8\n  |  sll TMP1, CRET1, 24\n  |   andi TMP2, TMP2, 0xff00\n  |  or TMP0, TMP0, TMP1\n  |   andi CRET1, CRET1, 0xff00\n  |  or TMP0, TMP0, TMP2\n  |   sll CRET1, CRET1, 8\n  |  b ->fff_resi\n  |.  or CRET1, TMP0, CRET1\n  |\n  |.ffunc_bit bnot\n  |  b ->fff_resi\n  |.  not CRET1, CRET1\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc_2 bit_..name\n  |  beq SFARG1HI, TISNUM, >1\n  |.  nop\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |  move SFARG1LO, CRET1\n  |1:\n  |  bne SFARG2HI, TISNUM, ->fff_fallback\n  |.  nop\n  |.if shmod == 1\n  |  li AT, 32\n  |  subu TMP0, AT, SFARG2LO\n  |  sllv SFARG2LO, SFARG1LO, SFARG2LO\n  |  srlv SFARG1LO, SFARG1LO, TMP0\n  |.elif shmod == 2\n  |  li AT, 32\n  |  subu TMP0, AT, SFARG2LO\n  |  srlv SFARG2LO, SFARG1LO, SFARG2LO\n  |  sllv SFARG1LO, SFARG1LO, TMP0\n  |.endif\n  |  b ->fff_resi\n  |.  ins CRET1, SFARG1LO, SFARG2LO\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, sllv, 0\n  |.ffunc_bit_sh rshift, srlv, 0\n  |.ffunc_bit_sh arshift, srav, 0\n  |// Can't use rotrv, since it's only in MIPS32R2.\n  |.ffunc_bit_sh rol, or, 1\n  |.ffunc_bit_sh ror, or, 2\n  |\n  |.ffunc_bit tobit\n  |->fff_resi:\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RA, BASE, -8\n  |  sw TISNUM, -8+HI(BASE)\n  |  b ->fff_res1\n  |.  sw CRET1, -8+LO(BASE)\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RB = CFUNC, RC = nargs*8\n  |  lw TMP3, CFUNC:RB->f\n  |    addu TMP1, BASE, NARGS8:RC\n  |   lw PC, FRAME_PC(BASE)\t\t// Fallback may overwrite PC.\n  |    addiu TMP0, TMP1, 8*LUA_MINSTACK\n  |     lw TMP2, L->maxstack\n  |   sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sltu AT, TMP2, TMP0\n  |     sw BASE, L->base\n  |    sw TMP1, L->top\n  |  bnez AT, >5\t\t\t// Need to grow stack.\n  |.  move CFUNCADDR, TMP3\n  |  jalr TMP3\t\t\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  lw BASE, L->base\n  |   sll RD, CRET1, 3\n  |  bgtz CRET1, ->fff_res\t\t// Returned nresults+1?\n  |.  addiu RA, BASE, -8\n  |1:  // Returned 0 or -1: retry fast path.\n  |  lw TMP0, L->top\n  |   lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  bnez CRET1, ->vm_call_tail\t\t// Returned -1?\n  |.  subu NARGS8:RC, TMP0, BASE\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  andi TMP0, PC, FRAME_TYPE\n  |   li AT, -4\n  |  bnez TMP0, >3\n  |.  and TMP1, PC, AT\n  |  lbu TMP1, OFS_RA(PC)\n  |  sll TMP1, TMP1, 3\n  |  addiu TMP1, TMP1, 8\n  |3:\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |.  subu TMP2, BASE, TMP1\n  |\n  |5:  // Grow stack for fallback handler.\n  |  load_got lj_state_growstack\n  |  li CARG2, LUA_MINSTACK\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  lw BASE, L->base\n  |  b <1\n  |.  li CRET1, 0\t\t\t// Force retry.\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  move MULTRES, ra\n  |  load_got lj_gc_step\n  |   sw BASE, L->base\n  |  addu TMP0, BASE, NARGS8:RC\n  |   sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sw TMP0, L->top\n  |  call_intern lj_gc_step\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |   lw BASE, L->base\n  |  move ra, MULTRES\n  |    lw TMP0, L->top\n  |  lw CFUNC:RB, FRAME_FUNC(BASE)\n  |  jr ra\n  |.  subu NARGS8:RC, TMP0, BASE\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_VMEVENT\t// No recording while in vmevent.\n  |  bnez AT, >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |.  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\n  |  bnez AT, >1\n  |.  addiu TMP2, TMP2, -1\n  |  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, >1\n  |.  nop\n  |  b >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  beqz AT, >1\n  |5:  // Re-dispatch to static ins.\n  |.  lw AT, GG_DISP2STATIC(TMP0)\t// Assumes TMP0 holds DISPATCH+OP*4.\n  |  jr AT\n  |.  nop\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  bnez AT, <5\n  |.  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, <5\n  |.  addiu TMP2, TMP2, -1\n  |  beqz TMP2, >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, LUA_MASKLINE\n  |  beqz AT, <5\n  |1:\n  |.  load_got lj_dispatch_ins\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sw BASE, L->base\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call_intern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |3:\n  |  lw BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  lw INS, -4(PC)\n  |  decode_OP4a TMP1, INS\n  |  decode_OP4b TMP1\n  |  addu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  lw AT, GG_DISP2STATIC(TMP0)\n  |   decode_RA8a RA, INS\n  |   decode_RD8b RD\n  |  jr AT\n  |   decode_RA8b RA\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  addiu PC, PC, 4\n  |  b <4\n  |.  lw MULTRES, -24+LO(RB)\t\t// Restore MULTRES for *M ins.\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n  |   addiu CARG1, DISPATCH, GG_DISP2J\n  |   sw PC, SAVE_PC\n  |  lw TMP1, LFUNC:TMP1->pc\n  |   move CARG2, PC\n  |   sw L, DISPATCH_J(L)(DISPATCH)\n  |  lbu TMP1, PC2PROTO(framesize)(TMP1)\n  |  load_got lj_trace_hot\n  |   sw BASE, L->base\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, BASE, TMP1\n  |  call_intern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |.  sw TMP1, L->top\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |.if JIT\n  |  b >1\n  |.endif\n  |.  move CARG2, PC\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  ori CARG2, PC, 1\n  |1:\n  |.endif\n  |  load_got lj_dispatch_call\n  |  addu TMP0, BASE, RC\n  |   sw PC, SAVE_PC\n  |   sw BASE, L->base\n  |  subu RA, RA, BASE\n  |   sw TMP0, L->top\n  |  call_intern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // Returns ASMFunction.\n  |  lw BASE, L->base\n  |   lw TMP0, L->top\n  |   sw r0, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  subu NARGS8:RC, TMP0, BASE\n  |  addu RA, BASE, RA\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  jr CRET1\n  |.  lw INS, -4(PC)\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |    lw TMP2, -24+LO(RB)\t\t// Save previous trace.\n  |  decode_RA8a RC, INS\n  |   addiu AT, MULTRES, -8\n  |  decode_RA8b RC\n  |   beqz AT, >2\n  |. addu RC, BASE, RC\t\t\t// Call base.\n  |1:  // Move results down.\n  |  lw SFRETHI, HI(RA)\n  |   lw SFRETLO, LO(RA)\n  |   addiu AT, AT, -8\n  |    addiu RA, RA, 8\n  |  sw SFRETHI, HI(RC)\n  |   sw SFRETLO, LO(RC)\n  |   bnez AT, <1\n  |.   addiu RC, RC, 8\n  |2:\n  |   decode_RA8a RA, INS\n  |    decode_RB8a RB, INS\n  |   decode_RA8b RA\n  |    decode_RB8b RB\n  |   addu RA, RA, RB\n  |   addu RA, BASE, RA\n  |3:\n  |   sltu AT, RC, RA\n  |   bnez AT, >9\t\t\t// More results wanted?\n  |.   nop\n  |\n  |  lhu TMP3, TRACE:TMP2->traceno\n  |  lhu RD, TRACE:TMP2->link\n  |  beq RD, TMP3, ->cont_nop\t\t// Blacklisted.\n  |.  load_got lj_dispatch_stitch\n  |  bnez RD, =>BC_JLOOP\t\t// Jump to stitched trace.\n  |.  sll RD, RD, 3\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  sw TMP3, DISPATCH_J(exitno)(DISPATCH)\n  |  sw L, DISPATCH_J(L)(DISPATCH)\n  |  sw BASE, L->base\n  |  addiu CARG1, DISPATCH, GG_DISP2J\n  |  call_intern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |.  move CARG2, PC\n  |  b ->cont_nop\n  |.  lw BASE, L->base\n  |\n  |9:\n  |  sw TISNIL, HI(RC)\n  |  b <3\n  |.  addiu RC, RC, 8\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  load_got lj_dispatch_profile\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sw BASE, L->base\n  |  call_intern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  addiu PC, PC, -4\n  |  b ->cont_nop\n  |.  lw BASE, L->base\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b\n  |.if FPU\n  |  sdc1 f..a, 16+a*8(sp)\n  |  sw r..a, 16+32*8+a*4(sp)\n  |  sw r..b, 16+32*8+b*4(sp)\n  |.else\n  |  sw r..a, 16+a*4(sp)\n  |  sw r..b, 16+b*4(sp)\n  |.endif\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |.if FPU\n  |  addiu sp, sp, -(16+32*8+32*4)\n  |.else\n  |  addiu sp, sp, -(16+32*4)\n  |.endif\n  |  savex_ 0, 1\n  |  savex_ 2, 3\n  |  savex_ 4, 5\n  |  savex_ 6, 7\n  |  savex_ 8, 9\n  |  savex_ 10, 11\n  |  savex_ 12, 13\n  |  savex_ 14, 15\n  |  savex_ 16, 17\n  |  savex_ 18, 19\n  |  savex_ 20, 21\n  |  savex_ 22, 23\n  |  savex_ 24, 25\n  |  savex_ 26, 27\n  |.if FPU\n  |  sdc1 f28, 16+28*8(sp)\n  |  sdc1 f30, 16+30*8(sp)\n  |  sw r28, 16+32*8+28*4(sp)\n  |  sw r30, 16+32*8+30*4(sp)\n  |  sw r0, 16+32*8+31*4(sp)\t\t// Clear RID_TMP.\n  |  addiu TMP2, sp, 16+32*8+32*4\t// Recompute original value of sp.\n  |  sw TMP2, 16+32*8+29*4(sp)\t\t// Store sp in RID_SP\n  |.else\n  |  sw r28, 16+28*4(sp)\n  |  sw r30, 16+30*4(sp)\n  |  sw r0, 16+31*4(sp)\t\t\t// Clear RID_TMP.\n  |  addiu TMP2, sp, 16+32*4\t\t// Recompute original value of sp.\n  |  sw TMP2, 16+29*4(sp)\t\t// Store sp in RID_SP\n  |.endif\n  |  li_vmstate EXIT\n  |  addiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  lw TMP1, 0(TMP2)\t\t\t// Load exit number.\n  |  st_vmstate\n  |  lw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |   lw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n  |  load_got lj_trace_exit\n  |  sw L, DISPATCH_J(L)(DISPATCH)\n  |  sw ra, DISPATCH_J(parent)(DISPATCH)  // Store trace number.\n  |   sw BASE, L->base\n  |  sw TMP1, DISPATCH_J(exitno)(DISPATCH)  // Store exit number.\n  |  addiu CARG1, DISPATCH, GG_DISP2J\n  |   sw r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  call_intern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |.  addiu CARG2, sp, 16\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  lw TMP1, L->cframe\n  |  li AT, -4\n  |   lw BASE, L->base\n  |  and sp, TMP1, AT\n  |   lw PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  b >1\n  |.  sw L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |.endif\n  |->vm_exit_interp:\n  |.if JIT\n  |  // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.\n  |  lw L, SAVE_L\n  |   addiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  sw BASE, L->base\n  |1:\n  |  bltz CRET1, >9\t\t\t// Check for error from exit.\n  |.  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |    .FPU lui TMP3, 0x59c0\t\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  sll MULTRES, CRET1, 3\n  |    li TISNIL, LJ_TNIL\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  sw MULTRES, SAVE_MULTRES\n  |    .FPU mtc1 TMP3, TOBIT\n  |  lw TMP1, LFUNC:RB->pc\n  |   sw r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  lw KBASE, PC2PROTO(k)(TMP1)\n  |    .FPU cvt.d.s TOBIT, TOBIT\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  lw INS, 0(PC)\n  |   addiu PC, PC, 4\n  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1\n  |    sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)\n  |  decode_OP4a TMP1, INS\n  |  decode_OP4b TMP1\n  |    sltiu TMP2, TMP1, BC_FUNCF*4\n  |  addu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  lw AT, 0(TMP0)\n  |   decode_RA8a RA, INS\n  |    beqz TMP2, >2\n  |.  decode_RA8b RA\n  |  jr AT\n  |.  decode_RD8b RD\n  |2:\n  |  sltiu TMP2, TMP1, (BC_FUNCC+2)*4\t// Fast function?\n  |  bnez TMP2, >3\n  |.  lw TMP1, FRAME_PC(BASE)\n  |  // Check frame below fast function.\n  |  andi TMP0, TMP1, FRAME_TYPE\n  |  bnez TMP0, >3\t\t\t// Trace stitching continuation?\n  |.  nop\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  lw TMP2, -4(TMP1)\n  |  decode_RA8a TMP0, TMP2\n  |  decode_RA8b TMP0\n  |  subu TMP1, BASE, TMP0\n  |  lw LFUNC:TMP2, -8+FRAME_FUNC(TMP1)\n  |  lw TMP1, LFUNC:TMP2->pc\n  |  lw KBASE, PC2PROTO(k)(TMP1)\n  |3:\n  |  addiu RC, MULTRES, -8\n  |  jr AT\n  |.  addu RA, RA, BASE\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  load_got lj_err_throw\n  |  negu CARG2, CRET1\n  |  call_intern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.  move CARG1, L\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Hard-float round to integer.\n  |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.\n  |.macro vm_round_hf, func\n  |  lui TMP0, 0x4330\t\t\t// Hiword of 2^52 (double).\n  |  mtc1 r0, f4\n  |  mtc1 TMP0, f5\n  |  abs.d FRET2, FARG1\t\t\t// |x|\n  |    mfc1 AT, f13\n  |  c.olt.d 0, FRET2, f4\n  |   add.d FRET1, FRET2, f4\t\t// (|x| + 2^52) - 2^52\n  |  bc1f 0, >1\t\t\t\t// Truncate only if |x| < 2^52.\n  |.  sub.d FRET1, FRET1, f4\n  |    slt AT, AT, r0\n  |.if \"func\" == \"ceil\"\n  |   lui TMP0, 0xbff0\t\t\t// Hiword of -1 (double). Preserves -0.\n  |.else\n  |   lui TMP0, 0x3ff0\t\t\t// Hiword of +1 (double).\n  |.endif\n  |.if \"func\" == \"trunc\"\n  |   mtc1 TMP0, f5\n  |  c.olt.d 0, FRET2, FRET1\t\t// |x| < result?\n  |   sub.d FRET2, FRET1, f4\n  |  movt.d FRET1, FRET2, 0\t\t// If yes, subtract +1.\n  |  neg.d FRET2, FRET1\n  |  jr ra\n  |.  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.else\n  |  neg.d FRET2, FRET1\n  |   mtc1 TMP0, f5\n  |  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.if \"func\" == \"ceil\"\n  |  c.olt.d 0, FRET1, FARG1\t\t// x > result?\n  |.else\n  |  c.olt.d 0, FARG1, FRET1\t\t// x < result?\n  |.endif\n  |   sub.d FRET2, FRET1, f4\t\t// If yes, subtract +-1.\n  |  jr ra\n  |.  movt.d FRET1, FRET2, 0\n  |.endif\n  |1:\n  |  jr ra\n  |.  mov.d FRET1, FARG1\n  |.endmacro\n  |\n  |.macro vm_round, func\n  |.if FPU\n  |  vm_round_hf, func\n  |.endif\n  |.endmacro\n  |\n  |->vm_floor:\n  |  vm_round floor\n  |->vm_ceil:\n  |  vm_round ceil\n  |->vm_trunc:\n  |.if JIT\n  |  vm_round trunc\n  |.endif\n  |\n  |// Soft-float integer to number conversion.\n  |.macro sfi2d, AHI, ALO\n  |.if not FPU\n  |  beqz ALO, >9\t\t\t// Handle zero first.\n  |.  sra TMP0, ALO, 31\n  |  xor TMP1, ALO, TMP0\n  |  subu TMP1, TMP1, TMP0\t\t// Absolute value in TMP1.\n  |  clz AHI, TMP1\n  |    andi TMP0, TMP0, 0x800\t\t// Mask sign bit.\n  |  li AT, 0x3ff+31-1\n  |   sllv TMP1, TMP1, AHI\t\t// Align mantissa left with leading 1.\n  |  subu AHI, AT, AHI\t\t\t// Exponent - 1 in AHI.\n  |   sll ALO, TMP1, 21\n  |  or AHI, AHI, TMP0\t\t\t// Sign | Exponent.\n  |   srl TMP1, TMP1, 11\n  |  sll AHI, AHI, 20\t\t\t// Align left.\n  |  jr ra\n  |.  addu AHI, AHI, TMP1\t\t// Add mantissa, increment exponent.\n  |9:\n  |  jr ra\n  |.  li AHI, 0\n  |.endif\n  |.endmacro\n  |\n  |// Input SFARG1LO. Output: SFARG1*. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_1:\n  |  sfi2d SFARG1HI, SFARG1LO\n  |\n  |// Input SFARG2LO. Output: SFARG2*. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_2:\n  |  sfi2d SFARG2HI, SFARG2LO\n  |\n  |// Soft-float comparison. Equivalent to c.eq.d.\n  |// Input: SFARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpeq:\n  |.if not FPU\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  xor TMP0, SFARG1HI, SFARG2HI\n  |  xor TMP1, SFARG1LO, SFARG2LO\n  |  or AT, TMP0, TMP1\n  |  jr ra\n  |.  sltiu CRET1, AT, 1\t\t// Same values: return 1.\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ult.d and c.olt.d.\n  |// Input: SFARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1, CRET2.\n  |->vm_sfcmpult:\n  |.if not FPU\n  |  b >1\n  |.  li CRET2, 1\n  |.endif\n  |\n  |->vm_sfcmpolt:\n  |.if not FPU\n  |  li CRET2, 0\n  |1:\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 0.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0 or 1;\n  |.  and AT, SFARG1HI, SFARG2HI\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  beq SFARG1HI, SFARG2HI, >8\n  |.  sltu CRET1, SFARG1LO, SFARG2LO\n  |  jr ra\n  |.  slt CRET1, SFARG1HI, SFARG2HI\n  |5:  // Swap conditions if both operands are negative.\n  |  beq SFARG1HI, SFARG2HI, >8\n  |.  sltu CRET1, SFARG2LO, SFARG1LO\n  |  jr ra\n  |.  slt CRET1, SFARG2HI, SFARG1HI\n  |8:\n  |  jr ra\n  |.  nop\n  |9:\n  |  jr ra\n  |.  move CRET1, CRET2\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ole.d a, b or c.ole.d b, a.\n  |// Input: SFARG*, TMP3. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpolex:\n  |.if not FPU\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  and AT, SFARG1HI, SFARG2HI\n  |  xor AT, AT, TMP3\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  beq SFARG1HI, SFARG2HI, >6\n  |.  sltu CRET1, SFARG2LO, SFARG1LO\n  |  jr ra\n  |.  slt CRET1, SFARG2HI, SFARG1HI\n  |5:  // Swap conditions if both operands are negative.\n  |  beq SFARG1HI, SFARG2HI, >6\n  |.  sltu CRET1, SFARG1LO, SFARG2LO\n  |  slt CRET1, SFARG1HI, SFARG2HI\n  |6:\n  |  jr ra\n  |.  nop\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |.macro sfmin_max, name, intins\n  |->vm_sf .. name:\n  |.if JIT and not FPU\n  |  move TMP2, ra\n  |  bal ->vm_sfcmpolt\n  |.  nop\n  |  move TMP0, CRET1\n  |  move SFRETHI, SFARG1HI\n  |   move SFRETLO, SFARG1LO\n  |  move ra, TMP2\n  |  intins SFRETHI, SFARG2HI, TMP0\n  |  jr ra\n  |.  intins SFRETLO, SFARG2LO, TMP0\n  |.endif\n  |.endmacro\n  |\n  |  sfmin_max min, movz\n  |  sfmin_max max, movn\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in r1, g in r2.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  lw CTSTATE, GL:r2->ctype_state\n  |   addiu DISPATCH, r2, GG_G2DISP\n  |  load_got lj_ccallback_enter\n  |  sw r1, CTSTATE->cb.slot\n  |  sw CARG1, CTSTATE->cb.gpr[0]\n  |  sw CARG2, CTSTATE->cb.gpr[1]\n  |   .FPU sdc1 FARG1, CTSTATE->cb.fpr[0]\n  |  sw CARG3, CTSTATE->cb.gpr[2]\n  |  sw CARG4, CTSTATE->cb.gpr[3]\n  |   .FPU sdc1 FARG2, CTSTATE->cb.fpr[1]\n  |  addiu TMP0, sp, CFRAME_SPACE+16\n  |  sw TMP0, CTSTATE->cb.stack\n  |  sw r0, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   move CARG2, sp\n  |  call_intern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |.  move CARG1, CTSTATE\n  |  // Returns lua_State *.\n  |  lw BASE, L:CRET1->base\n  |  lw RC, L:CRET1->top\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   move L, CRET1\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |     .FPU mtc1 TMP3, TOBIT\n  |    li_vmstate INTERP\n  |     li TISNIL, LJ_TNIL\n  |  subu RC, RC, BASE\n  |    st_vmstate\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  load_got lj_ccallback_leave\n  |  lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)\n  |   sw BASE, L->base\n  |   sw RB, L->top\n  |  sw L, CTSTATE->L\n  |  move CARG2, RA\n  |  call_intern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |.  move CARG1, CTSTATE\n  |   .FPU ldc1 FRET1, CTSTATE->cb.fpr[0]\n  |  lw CRET1, CTSTATE->cb.gpr[0]\n  |   .FPU ldc1 FRET2, CTSTATE->cb.fpr[1]\n  |  b ->vm_leave_unw\n  |.  lw CRET2, CTSTATE->cb.gpr[1]\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, CARG1\n  |  lw TMP1, CCSTATE->spadj\n  |   lbu CARG2, CCSTATE->nsp\n  |  move TMP2, sp\n  |  subu sp, sp, TMP1\n  |  sw ra, -4(TMP2)\n  |   sll CARG2, CARG2, 2\n  |  sw r16, -8(TMP2)\n  |  sw CCSTATE, -12(TMP2)\n  |  move r16, TMP2\n  |  addiu TMP1, CCSTATE, offsetof(CCallState, stack)\n  |  addiu TMP2, sp, 16\n  |  beqz CARG2, >2\n  |.  addu TMP3, TMP1, CARG2\n  |1:\n  |   lw TMP0, 0(TMP1)\n  |  addiu TMP1, TMP1, 4\n  |  sltu AT, TMP1, TMP3\n  |   sw TMP0, 0(TMP2)\n  |  bnez AT, <1\n  |.  addiu TMP2, TMP2, 4\n  |2:\n  |  lw CFUNCADDR, CCSTATE->func\n  |  lw CARG2, CCSTATE->gpr[1]\n  |  lw CARG3, CCSTATE->gpr[2]\n  |  lw CARG4, CCSTATE->gpr[3]\n  |  .FPU ldc1 FARG1, CCSTATE->fpr[0]\n  |  .FPU ldc1 FARG2, CCSTATE->fpr[1]\n  |  jalr CFUNCADDR\n  |.  lw CARG1, CCSTATE->gpr[0]\t\t// Do this last, since CCSTATE is CARG1.\n  |  lw CCSTATE:TMP1, -12(r16)\n  |  lw TMP2, -8(r16)\n  |  lw ra, -4(r16)\n  |  sw CRET1, CCSTATE:TMP1->gpr[0]\n  |  sw CRET2, CCSTATE:TMP1->gpr[1]\n  |.if FPU\n  |  sdc1 FRET1, CCSTATE:TMP1->fpr[0]\n  |  sdc1 FRET2, CCSTATE:TMP1->fpr[1]\n  |.else\n  |  sw CARG1, CCSTATE:TMP1->gpr[2]\t// Soft-float: complex double .im part.\n  |  sw CARG2, CCSTATE:TMP1->gpr[3]\n  |.endif\n  |  move sp, r16\n  |  jr ra\n  |.  move r16, TMP2\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.macro bc_comp, FRA, FRD, RAHI, RALO, RDHI, RDLO, movop, fmovop, fcomp, sfcomp\n    |  addu RA, BASE, RA\n    |   addu RD, BASE, RD\n    |  lw RAHI, HI(RA)\n    |   lw RDHI, HI(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |    addiu PC, PC, 4\n    |  bne RAHI, TISNUM, >2\n    |.  lw RALO, LO(RA)\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  lw RDLO, LO(RD)\n    |  bne RDHI, TISNUM, >5\n    |.   decode_RD4b TMP2\n    |  slt AT, SFARG1LO, SFARG2LO\n    |    addu TMP2, TMP2, TMP3\n    |  movop TMP2, r0, AT\n    |1:\n    |  addu PC, PC, TMP2\n    |  ins_next\n    |\n    |2:  // RA is not an integer.\n    |  sltiu AT, RAHI, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |.   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sltiu AT, RDHI, LJ_TISNUM\n    |.if FPU\n    |  ldc1 FRA, 0(RA)\n    |   ldc1 FRD, 0(RD)\n    |.else\n    |   lw RDLO, LO(RD)\n    |.endif\n    |  beqz AT, >4\n    |.   decode_RD4b TMP2\n    |3:  // RA and RD are both numbers.\n    |.if FPU\n    |  fcomp f20, f22\n    |   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.  fmovop TMP2, r0\n    |.else\n    |  bal sfcomp\n    |.   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.  movop TMP2, r0, CRET1\n    |.endif\n    |\n    |4:  // RA is a number, RD is not a number.\n    |  bne RDHI, TISNUM, ->vmeta_comp\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 FRD, LO(RD)\n    |  b <3\n    |.  cvt.d.w FRD, FRD\n    |.else\n    |.  nop\n    |.if \"RDHI\" == \"SFARG1HI\"\n    |  bal ->vm_sfi2d_1\n    |.else\n    |  bal ->vm_sfi2d_2\n    |.endif\n    |.  nop\n    |  b <3\n    |.  nop\n    |.endif\n    |\n    |5:  // RA is an integer, RD is not an integer\n    |  sltiu AT, RDHI, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |.  mtc1 RALO, FRA\n    |   ldc1 FRD, 0(RD)\n    |  b <3\n    |   cvt.d.w FRA, FRA\n    |.else\n    |.  nop\n    |.if \"RAHI\" == \"SFARG1HI\"\n    |  bal ->vm_sfi2d_1\n    |.else\n    |  bal ->vm_sfi2d_2\n    |.endif\n    |.  nop\n    |  b <3\n    |.  nop\n    |.endif\n    |.endmacro\n    |\n    if (op == BC_ISLT) {\n      |  bc_comp f20, f22, SFARG1HI, SFARG1LO, SFARG2HI, SFARG2LO, movz, movf, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISGE) {\n      |  bc_comp f20, f22, SFARG1HI, SFARG1LO, SFARG2HI, SFARG2LO, movn, movt, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISLE) {\n      |  bc_comp f22, f20, SFARG2HI, SFARG2LO, SFARG1HI, SFARG1LO, movn, movt, c.ult.d, ->vm_sfcmpult\n    } else {\n      |  bc_comp f22, f20, SFARG2HI, SFARG2LO, SFARG1HI, SFARG1LO, movz, movf, c.ult.d, ->vm_sfcmpult\n    }\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |  addu RA, BASE, RA\n    |    addiu PC, PC, 4\n    |  addu RD, BASE, RD\n    |  lw SFARG1HI, HI(RA)\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |  lw SFARG2HI, HI(RD)\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sltu AT, TISNUM, SFARG1HI\n    |  sltu TMP0, TISNUM, SFARG2HI\n    |  or AT, AT, TMP0\n    if (vk) {\n      |  beqz AT, ->BC_ISEQN_Z\n    } else {\n      |  beqz AT, ->BC_ISNEN_Z\n    }\n    |.   decode_RD4b TMP2\n    |  // Either or both types are not numbers.\n    |  lw SFARG1LO, LO(RA)\n    |  lw SFARG2LO, LO(RD)\n    |  addu TMP2, TMP2, TMP3\n    |.if FFI\n    |  li TMP3, LJ_TCDATA\n    |  beq SFARG1HI, TMP3, ->vmeta_equal_cd\n    |.endif\n    |.  sltiu AT, SFARG1HI, LJ_TISPRI\t\t// Not a primitive?\n    |.if FFI\n    |  beq SFARG2HI, TMP3, ->vmeta_equal_cd\n    |.endif\n    |.  xor TMP3, SFARG1LO, SFARG2LO\t\t// Same tv?\n    |  xor SFARG2HI, SFARG2HI, SFARG1HI\t\t// Same type?\n    |  sltiu TMP0, SFARG1HI, LJ_TISTABUD+1\t// Table or userdata?\n    |  movz TMP3, r0, AT\t\t\t// Ignore tv if primitive.\n    |  movn TMP0, r0, SFARG2HI\t\t\t// Tab/ud and same type?\n    |  or AT, SFARG2HI, TMP3\t\t\t// Same type && (pri||same tv).\n    |  movz TMP0, r0, AT\n    |  beqz TMP0, >1\t// Done if not tab/ud or not same type or same tv.\n    if (vk) {\n      |.  movn TMP2, r0, AT\n    } else {\n      |.  movz TMP2, r0, AT\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  lw TAB:TMP1, TAB:SFARG1LO->metatable\n    |  beqz TAB:TMP1, >1\t\t// No metatable?\n    |.  nop\n    |  lbu TMP1, TAB:TMP1->nomm\n    |  andi TMP1, TMP1, 1<<MM_eq\n    |  bnez TMP1, >1\t\t\t// Or 'no __eq' flag set?\n    |.  nop\n    |  b ->vmeta_equal\t\t\t// Handle __eq metamethod.\n    |.  li TMP0, 1-vk\t\t\t// ne = 0 or 1.\n    |1:\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target\n    |  addu RA, BASE, RA\n    |   addiu PC, PC, 4\n    |  lw TMP0, HI(RA)\n    |   srl RD, RD, 1\n    |  lw STR:TMP3, LO(RA)\n    |   subu RD, KBASE, RD\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |.if FFI\n    |  li AT, LJ_TCDATA\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  lw STR:TMP1, -4(RD)\t\t// KBASE-4-str_const*4\n    |  addiu TMP0, TMP0, -LJ_TSTR\n    |   decode_RD4b TMP2\n    |  xor TMP1, STR:TMP1, STR:TMP3\n    |  or TMP0, TMP0, TMP1\n    |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |   addu TMP2, TMP2, TMP3\n    if (vk) {\n      |  movn TMP2, r0, TMP0\n    } else {\n      |  movz TMP2, r0, TMP0\n    }\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RD = num_const*8, JMP with RD = target\n    |  addu RA, BASE, RA\n    |   addu RD, KBASE, RD\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG2HI, HI(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |    addiu PC, PC, 4\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |    decode_RD4b TMP2\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  bne SFARG1HI, TISNUM, >3\n    |.  lw SFARG1LO, LO(RA)\n    |  lw SFARG2LO, LO(RD)\n    |    addu TMP2, TMP2, TMP3\n    |  bne SFARG2HI, TISNUM, >6\n    |.  xor AT, SFARG1LO, SFARG2LO\n    if (vk) {\n      |  movn TMP2, r0, AT\n      |1:\n      |  addu PC, PC, TMP2\n      |2:\n    } else {\n      |  movz TMP2, r0, AT\n      |1:\n      |2:\n      |  addu PC, PC, TMP2\n    }\n    |  ins_next\n    |\n    |3:  // RA is not an integer.\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |.if FFI\n    |  beqz AT, >8\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |.   addu TMP2, TMP2, TMP3\n    |  sltiu AT, SFARG2HI, LJ_TISNUM\n    |.if FPU\n    |  ldc1 f20, 0(RA)\n    |   ldc1 f22, 0(RD)\n    |.endif\n    |  beqz AT, >5\n    |.  lw SFARG2LO, LO(RD)\n    |4:  // RA and RD are both numbers.\n    |.if FPU\n    |  c.eq.d f20, f22\n    |  b <1\n    if (vk) {\n      |.  movf TMP2, r0\n    } else {\n      |.  movt TMP2, r0\n    }\n    |.else\n    |  bal ->vm_sfcmpeq\n    |.  nop\n    |  b <1\n    if (vk) {\n      |.  movz TMP2, r0, CRET1\n    } else {\n      |.  movn TMP2, r0, CRET1\n    }\n    |.endif\n    |\n    |5:  // RA is a number, RD is not a number.\n    |.if FFI\n    |  bne SFARG2HI, TISNUM, >9\n    |.else\n    |  bne SFARG2HI, TISNUM, <2\n    |.endif\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 f22, LO(RD)\n    |  b <4\n    |.  cvt.d.w f22, f22\n    |.else\n    |.  nop\n    |  bal ->vm_sfi2d_2\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |6:  // RA is an integer, RD is not an integer\n    |  sltiu AT, SFARG2HI, LJ_TISNUM\n    |.if FFI\n    |  beqz AT, >9\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |.  mtc1 SFARG1LO, f20\n    |   ldc1 f22, 0(RD)\n    |  b <4\n    |   cvt.d.w f20, f20\n    |.else\n    |.  nop\n    |  bal ->vm_sfi2d_1\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |.if FFI\n    |8:\n    |  li AT, LJ_TCDATA\n    |  bne SFARG1HI, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |9:\n    |  li AT, LJ_TCDATA\n    |  bne SFARG2HI, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target\n    |  addu RA, BASE, RA\n    |   srl TMP1, RD, 3\n    |  lw TMP0, HI(RA)\n    |    lhu TMP2, OFS_RD(PC)\n    |   not TMP1, TMP1\n    |    addiu PC, PC, 4\n    |.if FFI\n    |  li AT, LJ_TCDATA\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  xor TMP0, TMP0, TMP1\n    |  decode_RD4b TMP2\n    |  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  addu TMP2, TMP2, TMP3\n    if (vk) {\n      |  movn TMP2, r0, TMP0\n    } else {\n      |  movz TMP2, r0, TMP0\n    }\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target\n    |  addu RD, BASE, RD\n    |   lhu TMP2, OFS_RD(PC)\n    |  lw TMP0, HI(RD)\n    |   addiu PC, PC, 4\n    if (op == BC_IST || op == BC_ISF) {\n      |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      if (op == BC_IST) {\n\t|  movz TMP2, r0, TMP0\n      } else {\n\t|  movn TMP2, r0, TMP0\n      }\n      |  addu PC, PC, TMP2\n    } else {\n      |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n      |  lw SFRETHI, HI(RD)\n      |   lw SFRETLO, LO(RD)\n      if (op == BC_ISTC) {\n\t|  beqz TMP0, >1\n      } else {\n\t|  bnez TMP0, >1\n      }\n      |.  addu RA, BASE, RA\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      |  sw SFRETHI, HI(RA)\n      |   sw SFRETLO, LO(RA)\n      |   addu PC, PC, TMP2\n      |1:\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RD = -type*8\n    |  addu TMP2, BASE, RA\n    |  srl TMP1, RD, 3\n    |  lw TMP0, HI(TMP2)\n    |  ins_next1\n    |  addu AT, TMP0, TMP1\n    |  bnez AT, ->vmeta_istype\n    |.  ins_next2\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RD = -(TISNUM-1)*8\n    |  addu TMP2, BASE, RA\n    |  lw TMP0, HI(TMP2)\n    |  ins_next1\n    |  sltiu AT, TMP0, LJ_TISNUM\n    |  beqz AT, ->vmeta_istype\n    |.  ins_next2\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RD = src*8\n    |  addu RD, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw SFRETHI, HI(RD)\n    |   lw SFRETLO, LO(RD)\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RD = src*8\n    |  addu RD, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw TMP0, HI(RD)\n    |   li TMP1, LJ_TFALSE\n    |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n    |  addiu TMP1, TMP0, LJ_TTRUE\n    |  ins_next1\n    |  sw TMP1, HI(RA)\n    |  ins_next2\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RD = src*8\n    |  addu RB, BASE, RD\n    |  lw SFARG1HI, HI(RB)\n    |   addu RA, BASE, RA\n    |  bne SFARG1HI, TISNUM, >2\n    |.  lw SFARG1LO, LO(RB)\n    |  lui TMP1, 0x8000\n    |  beq SFARG1LO, TMP1, ->vmeta_unm\t// Meta handler deals with -2^31.\n    |.  negu SFARG1LO, SFARG1LO\n    |1:\n    |  ins_next1\n    |  sw SFARG1HI, HI(RA)\n    |   sw SFARG1LO, LO(RA)\n    |  ins_next2\n    |2:\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |  beqz AT, ->vmeta_unm\n    |.  lui TMP1, 0x8000\n    |  b <1\n    |.  xor SFARG1HI, SFARG1HI, TMP1\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RD = src*8\n    |  addu CARG2, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw TMP0, HI(CARG2)\n    |   lw CARG1, LO(CARG2)\n    |  li AT, LJ_TSTR\n    |  bne TMP0, AT, >2\n    |.  li AT, LJ_TTAB\n    |   lw CRET1, STR:CARG1->len\n    |1:\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw CRET1, LO(RA)\n    |  ins_next2\n    |2:\n    |  bne TMP0, AT, ->vmeta_len\n    |.  nop\n#if LJ_52\n    |  lw TAB:TMP2, TAB:CARG1->metatable\n    |  bnez TAB:TMP2, >9\n    |.  nop\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  load_got lj_tab_len\n    |  call_intern lj_tab_len\t\t// (GCtab *t)\n    |.  nop\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n    |.  nop\n#if LJ_52\n    |9:\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_len\n    |  bnez TMP0, <3\t\t\t// 'no __len' flag set: done.\n    |.  nop\n    |  b ->vmeta_len\n    |.  nop\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro fpmod, a, b, c\n    |  bal ->vm_floor     // floor(b/c)\n    |.  div.d FARG1, b, c\n    |  mul.d a, FRET1, c\n    |  sub.d a, b, a      // b - floor(b/c)*c\n    |.endmacro\n\n    |.macro sfpmod\n    |  addiu sp, sp, -16\n    |\n    |  load_got __divdf3\n    |  sw SFARG1HI, HI(sp)\n    |   sw SFARG1LO, LO(sp)\n    |  sw SFARG2HI, 8+HI(sp)\n    |  call_extern\n    |.  sw SFARG2LO, 8+LO(sp)\n    |\n    |  load_got floor\n    |  move SFARG1HI, SFRETHI\n    |  call_extern\n    |.  move SFARG1LO, SFRETLO\n    |\n    |  load_got __muldf3\n    |  move SFARG1HI, SFRETHI\n    |   move SFARG1LO, SFRETLO\n    |  lw SFARG2HI, 8+HI(sp)\n    |  call_extern\n    |.  lw SFARG2LO, 8+LO(sp)\n    |\n    |  load_got __subdf3\n    |  lw SFARG1HI, HI(sp)\n    |   lw SFARG1LO, LO(sp)\n    |  move SFARG2HI, SFRETHI\n    |  call_extern\n    |.  move SFARG2LO, SFRETLO\n    |\n    |  addiu sp, sp, 16\n    |.endmacro\n\n    |.macro ins_arithpre, label\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||switch (vk) {\n    ||case 0:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = num_const*8\n    |   addu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RC, KBASE, RC\n    ||  break;\n    ||case 1:\n    |   decode_RB8a RC, INS\n    |   decode_RB8b RC\n    |    decode_RDtoRC8 RB, RD\n    |   // RA = dst*8, RB = num_const*8, RC = src1*8\n    |   addu RC, BASE, RC\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RB, KBASE, RB\n    ||  break;\n    ||default:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = src2*8\n    |   addu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RC, BASE, RC\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arith, intins, fpins, fpcall, label\n    |  ins_arithpre none\n    |\n    |.if \"label\" ~= \"none\"\n    |label:\n    |.endif\n    |\n    |  lw SFARG1HI, HI(RB)\n    |   lw SFARG2HI, HI(RC)\n    |\n    |.if \"intins\" ~= \"div\"\n    |\n    |  // Check for two integers.\n    |  lw SFARG1LO, LO(RB)\n    |  bne SFARG1HI, TISNUM, >5\n    |.  lw SFARG2LO, LO(RC)\n    |  bne SFARG2HI, TISNUM, >5\n    |\n    |.if \"intins\" == \"addu\"\n    |.  intins CRET1, SFARG1LO, SFARG2LO\n    |  xor TMP1, CRET1, SFARG1LO\t// ((y^a) & (y^b)) < 0: overflow.\n    |  xor TMP2, CRET1, SFARG2LO\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.elif \"intins\" == \"subu\"\n    |.  intins CRET1, SFARG1LO, SFARG2LO\n    |  xor TMP1, CRET1, SFARG1LO\t// ((y^a) & (a^b)) < 0: overflow.\n    |  xor TMP2, SFARG1LO, SFARG2LO\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.elif \"intins\" == \"mult\"\n    |.  intins SFARG1LO, SFARG2LO\n    |  mflo CRET1\n    |  mfhi TMP2\n    |  sra TMP1, CRET1, 31\n    |  bne TMP1, TMP2, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.else\n    |.  load_got lj_vm_modi\n    |  beqz SFARG2LO, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.if ENDIAN_BE\n    |  move CARG1, SFARG1LO\n    |.endif\n    |  call_extern\n    |.  move CARG2, SFARG2LO\n    |.endif\n    |\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw CRET1, LO(RA)\n    |3:\n    |  ins_next2\n    |\n    |.elif not FPU\n    |\n    |  lw SFARG1LO, LO(RB)\n    |   lw SFARG2LO, LO(RC)\n    |\n    |.endif\n    |\n    |5:  // Check for two numbers.\n    |  .FPU ldc1 f20, 0(RB)\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |   sltiu TMP0, SFARG2HI, LJ_TISNUM\n    |  .FPU ldc1 f22, 0(RC)\n    |   and AT, AT, TMP0\n    |   beqz AT, ->vmeta_arith\n    |.   addu RA, BASE, RA\n    |\n    |.if FPU\n    |  fpins FRET1, f20, f22\n    |.elif \"fpcall\" == \"sfpmod\"\n    |  sfpmod\n    |.else\n    |  load_got fpcall\n    |  call_extern\n    |.  nop\n    |.endif\n    |\n    |  ins_next1\n    |.if not FPU\n    |  sw SFRETHI, HI(RA)\n    |.endif\n    |.if \"intins\" ~= \"div\"\n    |  b <3\n    |.endif\n    |.if FPU\n    |.  sdc1 FRET1, 0(RA)\n    |.else\n    |.  sw SFRETLO, LO(RA)\n    |.endif\n    |.if \"intins\" == \"div\"\n    |  ins_next2\n    |.endif\n    |\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith addu, add.d, __adddf3, none\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith subu, sub.d, __subdf3, none\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith mult, mul.d, __muldf3, none\n    break;\n  case BC_DIVVN:\n    |  ins_arith div, div.d, __divdf3, ->BC_DIVVN_Z\n    break;\n  case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithpre ->BC_DIVVN_Z\n    break;\n  case BC_MODVN:\n    |  ins_arith modi, fpmod, sfpmod, ->BC_MODVN_Z\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre ->BC_MODVN_Z\n    break;\n  case BC_POW:\n    |  ins_arithpre none\n    |  lw SFARG1HI, HI(RB)\n    |   lw SFARG2HI, HI(RC)\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |  sltiu TMP0, SFARG2HI, LJ_TISNUM\n    |  and AT, AT, TMP0\n    |  load_got pow\n    |  beqz AT, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.if FPU\n    |  ldc1 FARG1, 0(RB)\n    |  ldc1 FARG2, 0(RC)\n    |.else\n    |  lw SFARG1LO, LO(RB)\n    |   lw SFARG2LO, LO(RC)\n    |.endif\n    |  call_extern\n    |.  nop\n    |  ins_next1\n    |.if FPU\n    |  sdc1 FRET1, 0(RA)\n    |.else\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  case BC_CAT:\n    |  // RA = dst*8, RB = src_start*8, RC = src_end*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  subu CARG3, RC, RB\n    |   sw BASE, L->base\n    |  addu CARG2, BASE, RC\n    |  move MULTRES, RB\n    |->BC_CAT_Z:\n    |  load_got lj_meta_cat\n    |  srl CARG3, CARG3, 3\n    |   sw PC, SAVE_PC\n    |  call_intern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |.  move CARG1, L\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  bnez CRET1, ->vmeta_binop\n    |.  lw BASE, L->base\n    |  addu RB, BASE, MULTRES\n    |  lw SFRETHI, HI(RB)\n    |   lw SFRETLO, LO(RB)\n    |   addu RA, BASE, RA\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RD = str_const*8 (~)\n    |  srl TMP1, RD, 1\n    |  subu TMP1, KBASE, TMP1\n    |  ins_next1\n    |  lw TMP0, -4(TMP1)\t\t// KBASE-4-str_const*4\n    |  addu RA, BASE, RA\n    |   li TMP2, LJ_TSTR\n    |  sw TMP0, LO(RA)\n    |   sw TMP2, HI(RA)\n    |  ins_next2\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RD = cdata_const*8 (~)\n    |  srl TMP1, RD, 1\n    |  subu TMP1, KBASE, TMP1\n    |  ins_next1\n    |  lw TMP0, -4(TMP1)\t\t// KBASE-4-cdata_const*4\n    |  addu RA, BASE, RA\n    |   li TMP2, LJ_TCDATA\n    |  sw TMP0, LO(RA)\n    |   sw TMP2, HI(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, RD = int16_literal*8\n    |  sra RD, INS, 16\n    |  addu RA, BASE, RA\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw RD, LO(RA)\n    |  ins_next2\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RD = num_const*8\n    |  addu RD, KBASE, RD\n    |   addu RA, BASE, RA\n    |  lw SFRETHI, HI(RD)\n    |   lw SFRETLO, LO(RD)\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RD = primitive_type*8 (~)\n    |  srl TMP1, RD, 3\n    |   addu RA, BASE, RA\n    |  not TMP0, TMP1\n    |  ins_next1\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RD = end*8\n    |  addu RA, BASE, RA\n    |  sw TISNIL, HI(RA)\n    |   addiu RA, RA, 8\n    |  addu RD, BASE, RD\n    |1:\n    |  sw TISNIL, HI(RA)\n    |  slt AT, RA, RD\n    |  bnez AT, <1\n    |.  addiu RA, RA, 8\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RD = uvnum*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RD, RD, 1\n    |   addu RD, RD, LFUNC:RB\n    |  lw UPVAL:RB, LFUNC:RD->uvptr\n    |  ins_next1\n    |  lw TMP1, UPVAL:RB->v\n    |  lw SFRETHI, HI(TMP1)\n    |   lw SFRETLO, LO(TMP1)\n    |  addu RA, BASE, RA\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RD = src*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |    srl RA, RA, 1\n    |   addu RD, BASE, RD\n    |    addu RA, RA, LFUNC:RB\n    |  lw UPVAL:RB, LFUNC:RA->uvptr\n    |   lw SFRETHI, HI(RD)\n    |    lw SFRETLO, LO(RD)\n    |  lbu TMP3, UPVAL:RB->marked\n    |   lw CARG2, UPVAL:RB->v\n    |  andi TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |  lbu TMP0, UPVAL:RB->closed\n    |   sw SFRETHI, HI(CARG2)\n    |    sw SFRETLO, LO(CARG2)\n    |  li AT, LJ_GC_BLACK|1\n    |  or TMP3, TMP3, TMP0\n    |  beq TMP3, AT, >2\t\t\t// Upvalue is closed and black?\n    |.  addiu TMP2, SFRETHI, -(LJ_TNUMX+1)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)\n    |  beqz AT, <1\t\t\t// tvisgcv(v)\n    |.  nop\n    |  lbu TMP3, GCOBJ:SFRETLO->gch.marked\n    |  andi TMP3, TMP3, LJ_GC_WHITES\t// iswhite(v)\n    |  beqz TMP3, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  addiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RD = str_const*8 (~)\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |    srl RA, RA, 1\n    |   srl TMP1, RD, 1\n    |    addu RA, RA, LFUNC:RB\n    |   subu TMP1, KBASE, TMP1\n    |  lw UPVAL:RB, LFUNC:RA->uvptr\n    |   lw STR:TMP1, -4(TMP1)\t\t// KBASE-4-str_const*4\n    |  lbu TMP2, UPVAL:RB->marked\n    |   lw CARG2, UPVAL:RB->v\n    |   lbu TMP3, STR:TMP1->marked\n    |  andi AT, TMP2, LJ_GC_BLACK\t// isblack(uv)\n    |   lbu TMP2, UPVAL:RB->closed\n    |   li TMP0, LJ_TSTR\n    |   sw STR:TMP1, LO(CARG2)\n    |  bnez AT, >2\n    |.  sw TMP0, HI(CARG2)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  beqz TMP2, <1\n    |.  andi AT, TMP3, LJ_GC_WHITES\t// iswhite(str)\n    |  beqz AT, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  addiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RD = num_const*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RA, RA, 1\n    |    addu RD, KBASE, RD\n    |   addu RA, RA, LFUNC:RB\n    |   lw UPVAL:RB, LFUNC:RA->uvptr\n    |    lw SFRETHI, HI(RD)\n    |     lw SFRETLO, LO(RD)\n    |   lw TMP1, UPVAL:RB->v\n    |  ins_next1\n    |    sw SFRETHI, HI(TMP1)\n    |     sw SFRETLO, LO(TMP1)\n    |  ins_next2\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RD = primitive_type*8 (~)\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RA, RA, 1\n    |    srl TMP0, RD, 3\n    |   addu RA, RA, LFUNC:RB\n    |    not TMP0, TMP0\n    |   lw UPVAL:RB, LFUNC:RA->uvptr\n    |  ins_next1\n    |   lw TMP1, UPVAL:RB->v\n    |   sw TMP0, HI(TMP1)\n    |  ins_next2\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RD = target\n    |  lw TMP2, L->openupval\n    |  branch_RD\t\t\t// Do this first since RD is not saved.\n    |  load_got lj_func_closeuv\n    |   sw BASE, L->base\n    |  beqz TMP2, >1\n    |.  move CARG1, L\n    |  call_intern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |.  addu CARG2, BASE, RA\n    |  lw BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)\n    |  srl TMP1, RD, 1\n    |  load_got lj_func_newL_gc\n    |  subu TMP1, KBASE, TMP1\n    |  lw CARG3, FRAME_FUNC(BASE)\n    |  lw CARG2, -4(TMP1)\t\t// KBASE-4-tab_const*4\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call_intern lj_func_newL_gc\n    |.  move CARG1, L\n    |  // Returns GCfuncL *.\n    |  lw BASE, L->base\n    |   li TMP0, LJ_TFUNC\n    |  ins_next1\n    |  addu RA, BASE, RA\n    |  sw LFUNC:CRET1, LO(RA)\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)\n    |  lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n    |  lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, >5\n    |1:\n    if (op == BC_TNEW) {\n      |  load_got lj_tab_new\n      |  srl CARG2, RD, 3\n      |  andi CARG2, CARG2, 0x7ff\n      |  li TMP0, 0x801\n      |  addiu AT, CARG2, -0x7ff\n      |   srl CARG3, RD, 14\n      |  movz CARG2, TMP0, AT\n      |  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  call_intern lj_tab_new\n      |.  move CARG1, L\n      |  // Returns Table *.\n    } else {\n      |  load_got lj_tab_dup\n      |  srl TMP1, RD, 1\n      |  subu TMP1, KBASE, TMP1\n      |  move CARG1, L\n      |  call_intern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n      |.  lw CARG2, -4(TMP1)\t\t// KBASE-4-str_const*4\n      |  // Returns Table *.\n    }\n    |  lw BASE, L->base\n    |  ins_next1\n    |  addu RA, BASE, RA\n    |   li TMP0, LJ_TTAB\n    |  sw TAB:CRET1, LO(RA)\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    |5:\n    |  load_got lj_gc_step_fixtop\n    |  move MULTRES, RD\n    |  call_intern lj_gc_step_fixtop\t// (lua_State *L)\n    |.  move CARG1, L\n    |  b <1\n    |.  move RD, MULTRES\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RD = str_const*8 (~)\n  case BC_GSET:\n    |  // RA = src*8, RD = str_const*8 (~)\n    |  lw LFUNC:TMP2, FRAME_FUNC(BASE)\n    |   srl TMP1, RD, 1\n    |   subu TMP1, KBASE, TMP1\n    |  lw TAB:RB, LFUNC:TMP2->env\n    |  lw STR:RC, -4(TMP1)\t\t// KBASE-4-str_const*4\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    |.  addu RA, BASE, RA\n    break;\n\n  case BC_TGETV:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG2, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TMP1, HI(CARG2)\n    |   lw TMP2, HI(CARG3)\n    |    lw TAB:RB, LO(CARG2)\n    |  li AT, LJ_TTAB\n    |  bne TMP1, AT, ->vmeta_tgetv\n    |.  addu RA, BASE, RA\n    |  bne TMP2, TISNUM, >5\n    |.  lw RC, LO(CARG3)\n    |  lw TMP0, TAB:RB->asize\n    |   lw TMP1, TAB:RB->array\n    |  sltu AT, RC, TMP0\n    |   sll TMP2, RC, 3\n    |  beqz AT, ->vmeta_tgetv\t\t// Integer key and in array part?\n    |.  addu TMP2, TMP1, TMP2\n    |  lw SFRETHI, HI(TMP2)\n    |  beq SFRETHI, TISNIL, >2\n    |.  lw SFRETLO, LO(TMP2)\n    |1:\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetv\n    |.  nop\n    |\n    |5:\n    |  li AT, LJ_TSTR\n    |  bne TMP2, AT, ->vmeta_tgetv\n    |.  nop\n    |  b ->BC_TGETS_Z\t\t\t// String key?\n    |.  nop\n    break;\n  case BC_TGETS:\n    |  // RA = dst*8, RB = table*8, RC = str_const*4 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RC4a RC, INS\n    |  lw TMP0, HI(CARG2)\n    |   decode_RC4b RC\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   subu CARG3, KBASE, RC\n    |   lw STR:RC, -4(CARG3)\t\t// KBASE-4-str_const*4\n    |  bne TMP0, AT, ->vmeta_tgets1\n    |.  addu RA, BASE, RA\n    |->BC_TGETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  lw TMP0, TAB:RB->hmask\n    |  lw TMP1, STR:RC->hash\n    |  lw NODE:TMP2, TAB:RB->node\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)\n    |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n    |    lw NODE:TMP1, NODE:TMP2->next\n    |    lw SFRETHI, offsetof(Node, val)+HI(NODE:TMP2)\n    |  addiu CARG1, CARG1, -LJ_TSTR\n    |   xor TMP0, TMP0, STR:RC\n    |  or AT, CARG1, TMP0\n    |  bnez AT, >4\n    |.  lw TAB:TMP3, TAB:RB->metatable\n    |    beq SFRETHI, TISNIL, >5\t// Key found, but nil value?\n    |.    lw SFRETLO, offsetof(Node, val)+LO(NODE:TMP2)\n    |3:\n    |  ins_next1\n    |    sw SFRETHI, HI(RA)\n    |     sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |4:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  beqz TAB:TMP3, <3\t\t// No metatable: done.\n    |.  li SFRETHI, LJ_TNIL\n    |  lbu TMP0, TAB:TMP3->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <3\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgets\n    |.  nop\n    break;\n  case BC_TGETB:\n    |  // RA = dst*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  lw CARG1, HI(CARG2)\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   addu RA, BASE, RA\n    |  bne CARG1, AT, ->vmeta_tgetb\n    |.  srl TMP0, RC, 3\n    |  lw TMP1, TAB:RB->asize\n    |   lw TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tgetb\n    |.  addu RC, TMP2, RC\n    |  lw SFRETHI, HI(RC)\n    |  beq SFRETHI, TISNIL, >5\n    |.  lw SFRETLO, LO(RC)\n    |1:\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_index\n    |  bnez TMP1, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    break;\n  case BC_TGETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu RB, BASE, RB\n    |   addu RC, BASE, RC\n    |  lw TAB:CARG1, LO(RB)\n    |   lw CARG2, LO(RC)\n    |    addu RA, BASE, RA\n    |  lw TMP0, TAB:CARG1->asize\n    |   lw TMP1, TAB:CARG1->array\n    |  sltu AT, CARG2, TMP0\n    |   sll TMP2, CARG2, 3\n    |  beqz AT, ->vmeta_tgetr\t\t// In array part?\n    |.  addu CRET1, TMP1, TMP2\n    |  lw SFARG2HI, HI(CRET1)\n    |   lw SFARG2LO, LO(CRET1)\n    |->BC_TGETR_Z:\n    |  ins_next1\n    |  sw SFARG2HI, HI(RA)\n    |   sw SFARG2LO, LO(RA)\n    |  ins_next2\n    break;\n\n  case BC_TSETV:\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG2, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TMP1, HI(CARG2)\n    |   lw TMP2, HI(CARG3)\n    |    lw TAB:RB, LO(CARG2)\n    |  li AT, LJ_TTAB\n    |  bne TMP1, AT, ->vmeta_tsetv\n    |.  addu RA, BASE, RA\n    |  bne TMP2, TISNUM, >5\n    |.  lw RC, LO(CARG3)\n    |  lw TMP0, TAB:RB->asize\n    |   lw TMP1, TAB:RB->array\n    |  sltu AT, RC, TMP0\n    |   sll TMP2, RC, 3\n    |  beqz AT, ->vmeta_tsetv\t\t// Integer key and in array part?\n    |.  addu TMP1, TMP1, TMP2\n    |  lw TMP0, HI(TMP1)\n    |   lbu TMP3, TAB:RB->marked\n    |  lw SFRETHI, HI(RA)\n    |  beq TMP0, TISNIL, >3\n    |.  lw SFRETLO, LO(RA)\n    |1:\n    |   andi AT, TMP3, LJ_GC_BLACK  // isblack(table)\n    |  sw SFRETHI, HI(TMP1)\n    |  bnez AT, >7\n    |.  sw SFRETLO, LO(TMP1)\n    |2:\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP2, TAB:TMP2->nomm\n    |  andi TMP2, TMP2, 1<<MM_newindex\n    |  bnez TMP2, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetv\n    |.  nop\n    |\n    |5:\n    |  li AT, LJ_TSTR\n    |  bne TMP2, AT, ->vmeta_tsetv\n    |.  nop\n    |  b ->BC_TSETS_Z\t\t\t// String key?\n    |.  nop\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETS:\n    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RC4a RC, INS\n    |  lw TMP0, HI(CARG2)\n    |   decode_RC4b RC\n    |  li AT, LJ_TTAB\n    |   subu CARG3, KBASE, RC\n    |    lw TAB:RB, LO(CARG2)\n    |   lw STR:RC, -4(CARG3)\t\t// KBASE-4-str_const*4\n    |  bne TMP0, AT, ->vmeta_tsets1\n    |.  addu RA, BASE, RA\n    |->BC_TSETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8\n    |  lw TMP0, TAB:RB->hmask\n    |  lw TMP1, STR:RC->hash\n    |  lw NODE:TMP2, TAB:RB->node\n    |   sb r0, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |.if FPU\n    |   ldc1 f20, 0(RA)\n    |.else\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |.endif\n    |1:\n    |  lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)\n    |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n    |  li AT, LJ_TSTR\n    |    lw NODE:TMP1, NODE:TMP2->next\n    |  bne CARG1, AT, >5\n    |.   lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)\n    |   bne TMP0, STR:RC, >5\n    |.    lbu TMP3, TAB:RB->marked\n    |    beq CARG2, TISNIL, >4\t\t// Key found, but nil value?\n    |.    lw TAB:TMP0, TAB:RB->metatable\n    |2:\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |.if FPU\n    |  bnez AT, >7\n    |.  sdc1 f20, NODE:TMP2->val\n    |.else\n    |   sw SFRETHI, NODE:TMP2->val.u32.hi\n    |  bnez AT, >7\n    |.   sw SFRETLO, NODE:TMP2->val.u32.lo\n    |.endif\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  beqz TAB:TMP0, <2\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP0->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  bnez TMP0, <2\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsets\n    |.  nop\n    |\n    |5:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, add a new one\n    |\n    |  // But check for __newindex first.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, >6\t\t// No metatable: continue.\n    |.  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  beqz TMP0, ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |.  li AT, LJ_TSTR\n    |6:\n    |  load_got lj_tab_newkey\n    |  sw STR:RC, LO(CARG3)\n    |  sw AT, HI(CARG3)\n    |   sw BASE, L->base\n    |  move CARG2, TAB:RB\n    |   sw PC, SAVE_PC\n    |  call_intern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k\n    |.  move CARG1, L\n    |  // Returns TValue *.\n    |  lw BASE, L->base\n    |.if FPU\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sdc1 f20, 0(CRET1)\n    |.else\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG1LO, LO(RA)\n    |  sw SFARG1HI, HI(CRET1)\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sw SFARG1LO, LO(CRET1)\n    |.endif\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <3\n    break;\n  case BC_TSETB:\n    |  // RA = src*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  lw CARG1, HI(CARG2)\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   addu RA, BASE, RA\n    |  bne CARG1, AT, ->vmeta_tsetb\n    |.  srl TMP0, RC, 3\n    |  lw TMP1, TAB:RB->asize\n    |   lw TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tsetb\n    |.  addu RC, TMP2, RC\n    |  lw TMP1, HI(RC)\n    |   lbu TMP3, TAB:RB->marked\n    |  beq TMP1, TISNIL, >5\n    |1:\n    |.  lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |   sw SFRETHI, HI(RC)\n    |  bnez AT, >7\n    |.   sw SFRETLO, LO(RC)\n    |2:\n    |  ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_newindex\n    |  bnez TMP1, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG1, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TAB:CARG2, LO(CARG1)\n    |   lw CARG3, LO(CARG3)\n    |  lbu TMP3, TAB:CARG2->marked\n    |   lw TMP0, TAB:CARG2->asize\n    |    lw TMP1, TAB:CARG2->array\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.  addu RA, BASE, RA\n    |2:\n    |  sltu AT, CARG3, TMP0\n    |   sll TMP2, CARG3, 3\n    |  beqz AT, ->vmeta_tsetr\t\t// In array part?\n    |.  addu CRET1, TMP1, TMP2\n    |->BC_TSETR_Z:\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG1LO, LO(RA)\n    |  ins_next1\n    |  sw SFARG1HI, HI(CRET1)\n    |   sw SFARG1LO, LO(CRET1)\n    |  ins_next2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)\n    |  addu RA, BASE, RA\n    |1:\n    |   addu TMP3, KBASE, RD\n    |  lw TAB:CARG2, -8+LO(RA)\t\t// Guaranteed to be a table.\n    |    addiu TMP0, MULTRES, -8\n    |   lw TMP3, LO(TMP3)\t\t// Integer constant is in lo-word.\n    |    beqz TMP0, >4\t\t\t// Nothing to copy?\n    |.    srl CARG3, TMP0, 3\n    |  addu CARG3, CARG3, TMP3\n    |  lw TMP2, TAB:CARG2->asize\n    |   sll TMP1, TMP3, 3\n    |    lbu TMP3, TAB:CARG2->marked\n    |   lw CARG1, TAB:CARG2->array\n    |  sltu AT, TMP2, CARG3\n    |  bnez AT, >5\n    |.  addu TMP2, RA, TMP0\n    |   addu TMP1, TMP1, CARG1\n    |  andi TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |3:  // Copy result slots to table.\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  sltu AT, RA, TMP2\n    |   sw SFRETHI, HI(TMP1)\n    |    sw SFRETLO, LO(TMP1)\n    |  bnez AT, <3\n    |.   addiu TMP1, TMP1, 8\n    |  bnez TMP0, >7\n    |. nop\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  load_got lj_tab_reasize\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  move BASE, RD\n    |  call_intern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |.  move CARG1, L\n    |  // Must not reallocate the stack.\n    |  move RD, BASE\n    |  b <1\n    |.  lw BASE, L->base\t// Reload BASE for lack of a saved register.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP0, <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |  b ->BC_CALL_Z\n    |.  addu NARGS8:RC, NARGS8:RC, MULTRES\n    break;\n  case BC_CALL:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |->BC_CALL_Z:\n    |  move TMP2, BASE\n    |  addu BASE, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP0, HI(BASE)\n    |   lw LFUNC:RB, LO(BASE)\n    |   addiu BASE, BASE, 8\n    |  bne TMP0, AT, ->vmeta_call\n    |.  addiu NARGS8:RC, NARGS8:RC, -8\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8\n    |  addu NARGS8:RD, NARGS8:RD, MULTRES\t// BC_CALLT gets RC from RD.\n    |  // Fall through. Assumes BC_CALLT follows.\n    break;\n  case BC_CALLT:\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |  addu RA, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP0, HI(RA)\n    |   lw LFUNC:RB, LO(RA)\n    |   move NARGS8:RC, RD\n    |    lw TMP1, FRAME_PC(BASE)\n    |   addiu RA, RA, 8\n    |  bne TMP0, AT, ->vmeta_callt\n    |.  addiu NARGS8:RC, NARGS8:RC, -8\n    |->BC_CALLT_Z:\n    |  andi TMP0, TMP1, FRAME_TYPE\t// Caveat: preserve TMP0 until the 'or'.\n    |   lbu TMP3, LFUNC:RB->ffid\n    |  bnez TMP0, >7\n    |.  xori TMP2, TMP1, FRAME_VARG\n    |1:\n    |  sw LFUNC:RB, FRAME_FUNC(BASE)\t// Copy function down, but keep PC.\n    |  sltiu AT, TMP3, 2\t\t// (> FF_C) Calling a fast function?\n    |  move TMP2, BASE\n    |  beqz NARGS8:RC, >3\n    |.  move TMP3, NARGS8:RC\n    |2:\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  addiu TMP3, TMP3, -8\n    |   sw SFRETHI, HI(TMP2)\n    |    sw SFRETLO, LO(TMP2)\n    |  bnez TMP3, <2\n    |.   addiu TMP2, TMP2, 8\n    |3:\n    |  or TMP0, TMP0, AT\n    |  beqz TMP0, >5\n    |.  nop\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  lw INS, -4(TMP1)\n    |  decode_RA8a RA, INS\n    |  decode_RA8b RA\n    |  subu TMP1, BASE, RA\n    |  lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1)\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  b <4\n    |.  lw KBASE, PC2PROTO(k)(TMP1)\t// Need to prepare KBASE.\n    |\n    |7:  // Tailcall from a vararg function.\n    |  andi AT, TMP2, FRAME_TYPEP\n    |  bnez AT, <1\t\t\t// Vararg frame below?\n    |.  subu TMP2, BASE, TMP2\t\t// Relocate BASE down.\n    |  move BASE, TMP2\n    |  lw TMP1, FRAME_PC(TMP2)\n    |  b <1\n    |.  andi TMP0, TMP1, FRAME_TYPE\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))\n    |  move TMP2, BASE\n    |  addu BASE, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP1, -24+HI(BASE)\n    |   lw LFUNC:RB, -24+LO(BASE)\n    |    lw SFARG1HI, -16+HI(BASE)\n    |     lw SFARG1LO, -16+LO(BASE)\n    |    lw SFARG2HI, -8+HI(BASE)\n    |     lw SFARG2LO, -8+LO(BASE)\n    |  sw TMP1, HI(BASE)\t\t// Copy callable.\n    |   sw LFUNC:RB, LO(BASE)\n    |    sw SFARG1HI, 8+HI(BASE)\t// Copy state.\n    |     sw SFARG1LO, 8+LO(BASE)\n    |    sw SFARG2HI, 16+HI(BASE)\t// Copy control var.\n    |     sw SFARG2LO, 16+LO(BASE)\n    |   addiu BASE, BASE, 8\n    |  bne TMP1, AT, ->vmeta_call\n    |.  li NARGS8:RC, 16\t\t// Iterators get 2 arguments.\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  addu RA, BASE, RA\n    |  lw TAB:RB, -16+LO(RA)\n    |  lw RC, -8+LO(RA)\t\t\t// Get index from control var.\n    |  lw TMP0, TAB:RB->asize\n    |  lw TMP1, TAB:RB->array\n    |   addiu PC, PC, 4\n    |1:  // Traverse array part.\n    |  sltu AT, RC, TMP0\n    |  beqz AT, >5\t\t\t// Index points after array part?\n    |.  sll TMP3, RC, 3\n    |  addu TMP3, TMP1, TMP3\n    |  lw SFARG1HI, HI(TMP3)\n    |   lw SFARG1LO, LO(TMP3)\n    |     lhu RD, -4+OFS_RD(PC)\n    |  sw TISNUM, HI(RA)\n    |   sw RC, LO(RA)\n    |  beq SFARG1HI, TISNIL, <1\t\t// Skip holes in array part.\n    |.  addiu RC, RC, 1\n    |  sw SFARG1HI, 8+HI(RA)\n    |   sw SFARG1LO, 8+LO(RA)\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |     decode_RD4b RD\n    |     addu RD, RD, TMP3\n    |   sw RC, -8+LO(RA)\t\t// Update control var.\n    |     addu PC, PC, RD\n    |3:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  lw TMP1, TAB:RB->hmask\n    |  subu RC, RC, TMP0\n    |   lw TMP2, TAB:RB->node\n    |6:\n    |  sltu AT, TMP1, RC\t\t// End of iteration? Branch to ITERL+1.\n    |  bnez AT, <3\n    |.  sll TMP3, RC, 5\n    |   sll RB, RC, 3\n    |   subu TMP3, TMP3, RB\n    |  addu NODE:TMP3, TMP3, TMP2\n    |  lw SFARG1HI, NODE:TMP3->val.u32.hi\n    |   lw SFARG1LO, NODE:TMP3->val.u32.lo\n    |     lhu RD, -4+OFS_RD(PC)\n    |  beq SFARG1HI, TISNIL, <6\t\t// Skip holes in hash part.\n    |.  addiu RC, RC, 1\n    |  lw SFARG2HI, NODE:TMP3->key.u32.hi\n    |   lw SFARG2LO, NODE:TMP3->key.u32.lo\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sw SFARG1HI, 8+HI(RA)\n    |   sw SFARG1LO, 8+LO(RA)\n    |    addu RC, RC, TMP0\n    |     decode_RD4b RD\n    |     addu RD, RD, TMP3\n    |  sw SFARG2HI, HI(RA)\n    |   sw SFARG2LO, LO(RA)\n    |     addu PC, PC, RD\n    |  b <3\n    |.  sw RC, -8+LO(RA)\t\t// Update control var.\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RD = target (points to ITERN)\n    |  addu RA, BASE, RA\n    |  lw TMP0, -24+HI(RA)\n    |  lw CFUNC:TMP1, -24+LO(RA)\n    |   lw TMP2, -16+HI(RA)\n    |    lw TMP3, -8+HI(RA)\n    |  li AT, LJ_TFUNC\n    |  bne TMP0, AT, >5\n    |.  addiu TMP2, TMP2, -LJ_TTAB\n    |  lbu TMP1, CFUNC:TMP1->ffid\n    |  addiu TMP3, TMP3, -LJ_TNIL\n    |   srl TMP0, RD, 1\n    |  or TMP2, TMP2, TMP3\n    |  addiu TMP1, TMP1, -FF_next_N\n    |   addu TMP0, PC, TMP0\n    |  or TMP1, TMP1, TMP2\n    |  bnez TMP1, >5\n    |.  lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  addu PC, TMP0, TMP2\n    |  lui TMP1, 0xfffe\n    |  ori TMP1, TMP1, 0x7fff\n    |  sw r0, -8+LO(RA)\t\t\t// Initialize control var.\n    |  sw TMP1, -8+HI(RA)\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  li TMP3, BC_JMP\n    |   li TMP1, BC_ITERC\n    |  sb TMP3, -4+OFS_OP(PC)\n    |   addu PC, TMP0, TMP2\n    |  b <1\n    |.  sb TMP1, OFS_OP(PC)\n    break;\n\n  case BC_VARG:\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  lw TMP0, FRAME_PC(BASE)\n    |  decode_RDtoRC8 RC, RD\n    |   decode_RB8a RB, INS\n    |  addu RC, BASE, RC\n    |   decode_RB8b RB\n    |   addu RA, BASE, RA\n    |  addiu RC, RC, FRAME_VARG\n    |   addu TMP2, RA, RB\n    |  addiu TMP3, BASE, -8\t\t// TMP3 = vtop\n    |  subu RC, RC, TMP0\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  beqz RB, >5\t\t\t// Copy all varargs?\n    |.  subu TMP1, TMP3, RC\n    |  addiu TMP2, TMP2, -16\n    |1:  // Copy vararg slots to destination slots.\n    |  lw CARG1, HI(RC)\n    |  sltu AT, RC, TMP3\n    |   lw CARG2, LO(RC)\n    |    addiu RC, RC, 8\n    |  movz CARG1, TISNIL, AT\n    |  sw CARG1, HI(RA)\n    |   sw CARG2, LO(RA)\n    |  sltu AT, RA, TMP2\n    |  bnez AT, <1\n    |.   addiu RA, RA, 8\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  lw TMP0, L->maxstack\n    |  blez TMP1, <3\t\t\t// No vararg slots?\n    |.  li MULTRES, 8\t\t\t// MULTRES = (0+1)*8\n    |  addu TMP2, RA, TMP1\n    |  sltu AT, TMP0, TMP2\n    |  bnez AT, >7\n    |.  addiu MULTRES, TMP1, 8\n    |6:\n    |  lw SFRETHI, HI(RC)\n    |   lw SFRETLO, LO(RC)\n    |   addiu RC, RC, 8\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  sltu AT, RC, TMP3\n    |  bnez AT, <6\t\t\t// More vararg slots?\n    |.  addiu RA, RA, 8\n    |  b <3\n    |.  nop\n    |\n    |7:  // Grow stack for varargs.\n    |  load_got lj_state_growstack\n    |   sw RA, L->top\n    |  subu RA, RA, BASE\n    |   sw BASE, L->base\n    |  subu BASE, RC, BASE\t\t// Need delta, because BASE may change.\n    |   sw PC, SAVE_PC\n    |  srl CARG2, TMP1, 3\n    |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n    |.  move CARG1, L\n    |  move RC, BASE\n    |  lw BASE, L->base\n    |  addu RA, BASE, RA\n    |  addu RC, BASE, RC\n    |  b <6\n    |.  addiu TMP3, BASE, -8\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RD = extra_nresults*8\n    |  addu RD, RD, MULTRES\t\t// MULTRES >= 8, so RD >= 8.\n    |  // Fall through. Assumes BC_RET follows.\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lw PC, FRAME_PC(BASE)\n    |   addu RA, BASE, RA\n    |    move MULTRES, RD\n    |1:\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return\n    |   lw INS, -4(PC)\n    |    addiu TMP2, BASE, -8\n    |    addiu RC, RD, -8\n    |  decode_RA8a TMP0, INS\n    |   decode_RB8a RB, INS\n    |  decode_RA8b TMP0\n    |   decode_RB8b RB\n    |   addu TMP3, TMP2, RB\n    |  beqz RC, >3\n    |.  subu BASE, TMP2, TMP0\n    |2:\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  addiu RC, RC, -8\n    |   sw SFRETHI, HI(TMP2)\n    |    sw SFRETLO, LO(TMP2)\n    |  bnez RC, <2\n    |.   addiu TMP2, TMP2, 8\n    |3:\n    |  addiu TMP3, TMP3, -8\n    |5:\n    |  sltu AT, TMP2, TMP3\n    |  bnez AT, >6\n    |.  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  lw KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  sw TISNIL, HI(TMP2)\n    |  b <5\n    |.  addiu TMP2, TMP2, 8\n    |\n    |->BC_RETV_Z:  // Non-standard return case.\n    |  andi TMP2, TMP1, FRAME_TYPEP\n    |  bnez TMP2, ->vm_return\n    |.  nop\n    |  // Return from vararg function: relocate BASE down.\n    |  subu BASE, BASE, TMP1\n    |  b <1\n    |.  lw PC, FRAME_PC(BASE)\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lw PC, FRAME_PC(BASE)\n    |   addu RA, BASE, RA\n    |    move MULTRES, RD\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |\n    |  lw INS, -4(PC)\n    |   addiu TMP2, BASE, -8\n    if (op == BC_RET1) {\n      |  lw SFRETHI, HI(RA)\n      |   lw SFRETLO, LO(RA)\n    }\n    |  decode_RB8a RB, INS\n    |   decode_RA8a RA, INS\n    |  decode_RB8b RB\n    |   decode_RA8b RA\n    if (op == BC_RET1) {\n      |  sw SFRETHI, HI(TMP2)\n      |   sw SFRETLO, LO(TMP2)\n    }\n    |   subu BASE, TMP2, RA\n    |5:\n    |  sltu AT, RD, RB\n    |  bnez AT, >6\n    |.  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  lw KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  addiu TMP2, TMP2, 8\n    |  addiu RD, RD, 8\n    |  b <5\n    if (op == BC_RET1) {\n      |.  sw TISNIL, HI(TMP2)\n    } else {\n      |.  sw TISNIL, -8+HI(TMP2)\n    }\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RD = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  addu RA, BASE, RA\n    |  lw SFARG1HI, FORL_IDX*8+HI(RA)\n    |   lw SFARG1LO, FORL_IDX*8+LO(RA)\n    if (op != BC_JFORL) {\n      |  srl RD, RD, 1\n      |  lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n      |  addu TMP2, RD, TMP2\n    }\n    if (!vk) {\n      |  lw SFARG2HI, FORL_STOP*8+HI(RA)\n      |   lw SFARG2LO, FORL_STOP*8+LO(RA)\n      |  bne SFARG1HI, TISNUM, >5\n      |.  lw SFRETHI, FORL_STEP*8+HI(RA)\n      |  xor AT, SFARG2HI, TISNUM\n      |   lw SFRETLO, FORL_STEP*8+LO(RA)\n      |  xor TMP0, SFRETHI, TISNUM\n      |  or AT, AT, TMP0\n      |  bnez AT, ->vmeta_for\n      |.  slt AT, SFRETLO, r0\n      |  slt CRET1, SFARG2LO, SFARG1LO\n      |  slt TMP1, SFARG1LO, SFARG2LO\n      |  movn CRET1, TMP1, AT\n    } else {\n      |  bne SFARG1HI, TISNUM, >5\n      |.  lw SFARG2LO, FORL_STEP*8+LO(RA)\n      |  lw SFRETLO, FORL_STOP*8+LO(RA)\n      |  move TMP3, SFARG1LO\n      |  addu SFARG1LO, SFARG1LO, SFARG2LO\n      |  xor TMP0, SFARG1LO, TMP3\n      |  xor TMP1, SFARG1LO, SFARG2LO\n      |  and TMP0, TMP0, TMP1\n      |  slt TMP1, SFARG1LO, SFRETLO\n      |  slt CRET1, SFRETLO, SFARG1LO\n      |  slt AT, SFARG2LO, r0\n      |   slt TMP0, TMP0, r0\t\t// ((y^a) & (y^b)) < 0: overflow.\n      |  movn CRET1, TMP1, AT\n      |   or CRET1, CRET1, TMP0\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  movz TMP2, r0, CRET1\n      |  addu PC, PC, TMP2\n    } else if (op == BC_JFORI) {\n      |  addu PC, PC, TMP2\n      |  lhu RD, -4+OFS_RD(PC)\n    } else if (op == BC_IFORL) {\n      |  movn TMP2, r0, CRET1\n      |  addu PC, PC, TMP2\n    }\n    if (vk) {\n      |  sw SFARG1HI, FORL_IDX*8+HI(RA)\n      |   sw SFARG1LO, FORL_IDX*8+LO(RA)\n    }\n    |  ins_next1\n    |  sw SFARG1HI, FORL_EXT*8+HI(RA)\n    |   sw SFARG1LO, FORL_EXT*8+LO(RA)\n    |2:\n    if (op == BC_JFORI) {\n      |  beqz CRET1, =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else if (op == BC_JFORL) {\n      |  beqz CRET1, =>BC_JLOOP\n    }\n    |  ins_next2\n    |\n    |5:  // FP loop.\n    |.if FPU\n    if (!vk) {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f2, FORL_STOP*8(RA)\n      |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n      |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n      |  sltiu AT, SFRETHI, LJ_TISNUM\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  slt TMP3, SFRETHI, r0\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |  li CRET1, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  b <1\n      |.  movn CRET1, AT, TMP3\n    } else {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f4, FORL_STEP*8(RA)\n      |    ldc1 f2, FORL_STOP*8(RA)\n      |   lw SFARG2HI, FORL_STEP*8+HI(RA)\n      |  add.d f0, f0, f4\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |   slt TMP3, SFARG2HI, r0\n      |  li CRET1, 1\n      |  li AT, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  movn CRET1, AT, TMP3\n      if (op == BC_IFORL) {\n\t|  movn TMP2, r0, CRET1\n\t|  addu PC, PC, TMP2\n      }\n      |  sdc1 f0, FORL_IDX*8(RA)\n      |  ins_next1\n      |  b <2\n      |.  sdc1 f0, FORL_EXT*8(RA)\n    }\n    |.else\n    if (!vk) {\n      |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n      |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n      |  sltiu AT, SFRETHI, LJ_TISNUM\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  nop\n      |  bal ->vm_sfcmpolex\n      |.  move TMP3, SFRETHI\n      |  b <1\n      |.  nop\n    } else {\n      |   lw SFARG2HI, FORL_STEP*8+HI(RA)\n      |  load_got __adddf3\n      |  call_extern\n      |.  sw TMP2, ARG5\n      |  lw SFARG2HI, FORL_STOP*8+HI(RA)\n      |   lw SFARG2LO, FORL_STOP*8+LO(RA)\n      |  move SFARG1HI, SFRETHI\n      |   move SFARG1LO, SFRETLO\n      |  bal ->vm_sfcmpolex\n      |.  lw TMP3, FORL_STEP*8+HI(RA)\n      if ( op == BC_JFORL ) {\n\t|   lhu RD, -4+OFS_RD(PC)\n\t|  lw TMP2, ARG5\n\t|  b <1\n\t|.  decode_RD8b RD\n      } else {\n\t|  b <1\n\t|.  lw TMP2, ARG5\n      }\n    }\n    |.endif\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RD = target\n    |  addu RA, BASE, RA\n    |  lw TMP1, HI(RA)\n    |  beq TMP1, TISNIL, >1\t\t// Stop if iterator returned nil.\n    |.  lw TMP2, LO(RA)\n    if (op == BC_JITERL) {\n      |  sw TMP1, -8+HI(RA)\n      |  b =>BC_JLOOP\n      |.  sw TMP2, -8+LO(RA)\n    } else {\n      |  branch_RD\t\t\t// Otherwise save control var + branch.\n      |  sw TMP1, -8+HI(RA)\n      |   sw TMP2, -8+LO(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base*8 (ignored), RD = traceno*8\n    |  lw TMP1, DISPATCH_J(trace)(DISPATCH)\n    |  srl RD, RD, 1\n    |   li AT, 0\n    |  addu TMP1, TMP1, RD\n    |  // Traces on MIPS don't store the trace number, so use 0.\n    |   sw AT, DISPATCH_GL(vmstate)(DISPATCH)\n    |  lw TRACE:TMP2, 0(TMP1)\n    |   sw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n    |  lw TMP2, TRACE:TMP2->mcode\n    |   sw L, DISPATCH_GL(tmpbuf.L)(DISPATCH)\n    |  jr TMP2\n    |.  addiu JGL, DISPATCH, GG_DISP2G+32768\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RD = target\n    |  branch_RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lw TMP2, L->maxstack\n    |   lbu TMP1, -4+PC2PROTO(numparams)(PC)\n    |    lw KBASE, -4+PC2PROTO(k)(PC)\n    |  sltu AT, TMP2, RA\n    |  bnez AT, ->vm_growstack_l\n    |.  sll TMP1, TMP1, 3\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n    }\n    |2:\n    |  sltu AT, NARGS8:RC, TMP1\t\t// Check for missing parameters.\n    |  bnez AT, >3\n    |.  addu AT, BASE, NARGS8:RC\n    if (op == BC_JFUNCF) {\n      |  decode_RD8a RD, INS\n      |  b =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else {\n      |  ins_next2\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  sw TISNIL, HI(AT)\n    |  b <2\n    |.  addiu NARGS8:RC, NARGS8:RC, 8\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |   addu TMP1, BASE, RC\n    |  lw TMP2, L->maxstack\n    |  addu TMP0, RA, RC\n    |   sw LFUNC:RB, LO(TMP1)\t\t// Store copy of LFUNC.\n    |   addiu TMP3, RC, 8+FRAME_VARG\n    |  sltu AT, TMP0, TMP2\n    |    lw KBASE, -4+PC2PROTO(k)(PC)\n    |  beqz AT, ->vm_growstack_l\n    |.  sw TMP3, HI(TMP1)\t\t// Store delta + FRAME_VARG.\n    |  lbu TMP2, -4+PC2PROTO(numparams)(PC)\n    |   move RA, BASE\n    |   move RC, TMP1\n    |  ins_next1\n    |  beqz TMP2, >3\n    |.  addiu BASE, TMP1, 8\n    |1:\n    |  lw TMP0, HI(RA)\n    |   lw TMP3, LO(RA)\n    |  sltu AT, RA, RC\t\t\t// Less args than parameters?\n    |  move CARG1, TMP0\n    |  movz TMP0, TISNIL, AT\t\t// Clear missing parameters.\n    |  movn CARG1, TISNIL, AT\t\t// Clear old fixarg slot (help the GC).\n    |   sw TMP3, 8+LO(TMP1)\n    |    addiu TMP2, TMP2, -1\n    |  sw TMP0, 8+HI(TMP1)\n    |    addiu TMP1, TMP1, 8\n    |  sw CARG1, HI(RA)\n    |  bnez TMP2, <1\n    |.   addiu RA, RA, 8\n    |3:\n    |  ins_next2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  lw CFUNCADDR, CFUNC:RB->f\n    } else {\n      |  lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)\n    }\n    |  addu TMP1, RA, NARGS8:RC\n    |  lw TMP2, L->maxstack\n    |   addu RC, BASE, NARGS8:RC\n    |  sw BASE, L->base\n    |  sltu AT, TMP2, TMP1\n    |   sw RC, L->top\n    |    li_vmstate C\n    if (op == BC_FUNCCW) {\n      |  lw CARG2, CFUNC:RB->f\n    }\n    |  bnez AT, ->vm_growstack_c\t// Need to grow stack.\n    |.  move CARG1, L\n    |  jalr CFUNCADDR\t\t\t// (lua_State *L [, lua_CFunction f])\n    |.   st_vmstate\n    |  // Returns nresults.\n    |  lw BASE, L->base\n    |   sll RD, CRET1, 3\n    |  lw TMP1, L->top\n    |    li_vmstate INTERP\n    |  lw PC, FRAME_PC(BASE)\t\t// Fetch PC of caller.\n    |   subu RA, TMP1, RD\t\t// RA = L->top - nresults*8\n    |    sw L, DISPATCH_GL(cur_L)(DISPATCH)\n    |  b ->vm_returnc\n    |.   st_vmstate\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.4byte .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.4byte 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.4byte .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.4byte .Lbegin\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.sleb128 1\\n\"\n\t\"\\t.byte 0x9e\\n\\t.sleb128 2\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 23; i >= 16; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 26-i);\n#if !LJ_SOFTFP\n    for (i = 30; i >= 20; i -= 2)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+32+i, 42-i);\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.4byte .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.4byte lj_vm_ffi_call\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.uleb128 1\\n\"\n\t\"\\t.byte 0x90\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x10\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"aw\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\"\\t.globl lj_err_unwind_dwarf\\n\"\n\t\".Lframe1:\\n\"\n\t\"\\t.4byte .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.4byte 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0\\n\"\n\t\"\\t.4byte lj_err_unwind_dwarf\\n\"\n\t\"\\t.byte 0\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.4byte .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.4byte .LASFDE2-.Lframe1\\n\"\n\t\"\\t.4byte .Lbegin\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.sleb128 1\\n\"\n\t\"\\t.byte 0x9e\\n\\t.sleb128 2\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 23; i >= 16; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 26-i);\n#if !LJ_SOFTFP\n    for (i = 30; i >= 20; i -= 2)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+32+i, 42-i);\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.4byte .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.4byte 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.4byte .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.4byte .LASFDE3-.Lframe2\\n\"\n\t\"\\t.4byte lj_vm_ffi_call\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9f\\n\\t.uleb128 1\\n\"\n\t\"\\t.byte 0x90\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x10\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_ppc.dasc",
    "content": "|// Low-level VM code for PowerPC 32 bit or 32on64 bit mode.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch ppc\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// DynASM defines used by the PPC port:\n|//\n|// P64     64 bit pointers (only for GPR64 testing).\n|//         Note: see vm_ppc64.dasc for a full PPC64 _LP64 port.\n|// GPR64   64 bit registers (but possibly 32 bit pointers, e.g. PS3).\n|//         Affects reg saves, stack layout, carry/overflow/dot flags etc.\n|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360).\n|// TOC     Need table of contents (64 bit or 32 bit variant, e.g. PS3).\n|//         Function pointers are really a struct: code, TOC, env (optional).\n|// TOCENV  Function pointers have an environment pointer, too (not on PS3).\n|// PPE     Power Processor Element of Cell (PS3) or Xenon (Xbox 360).\n|//         Must avoid (slow) micro-coded instructions.\n|\n|.if P64\n|.define TOC, 1\n|.define TOCENV, 1\n|.macro lpx, a, b, c; ldx a, b, c; .endmacro\n|.macro lp, a, b; ld a, b; .endmacro\n|.macro stp, a, b; std a, b; .endmacro\n|.define decode_OPP, decode_OP8\n|.if FFI\n|// Missing: Calling conventions, 64 bit regs, TOC.\n|.error lib_ffi not yet implemented for PPC64\n|.endif\n|.else\n|.macro lpx, a, b, c; lwzx a, b, c; .endmacro\n|.macro lp, a, b; lwz a, b; .endmacro\n|.macro stp, a, b; stw a, b; .endmacro\n|.define decode_OPP, decode_OP4\n|.endif\n|\n|// Convenience macros for TOC handling.\n|.if TOC\n|// Linker needs a TOC patch area for every external call relocation.\n|.macro blex, target; bl extern target@plt; nop; .endmacro\n|.macro .toc, a, b; a, b; .endmacro\n|.if P64\n|.define TOC_OFS,\t 8\n|.define ENV_OFS,\t16\n|.else\n|.define TOC_OFS,\t4\n|.define ENV_OFS,\t8\n|.endif\n|.else  // No TOC.\n|.macro blex, target; bl extern target@plt; .endmacro\n|.macro .toc, a, b; .endmacro\n|.endif\n|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro\n|\n|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro\n|\n|.macro andix., y, a, i\n|.if PPE\n|  rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i)\n|  cmpwi y, 0\n|.else\n|  andi. y, a, i\n|.endif\n|.endmacro\n|\n|.macro clrso, reg\n|.if PPE\n|  li reg, 0\n|  mtxer reg\n|.else\n|  mcrxr cr0\n|.endif\n|.endmacro\n|\n|.macro checkov, reg, noov\n|.if PPE\n|  mfxer reg\n|  add reg, reg, reg\n|  cmpwi reg, 0\n|   li reg, 0\n|   mtxer reg\n|  bgey noov\n|.else\n|  mcrxr cr0\n|  bley noov\n|.endif\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA)\n|\n|// The following must be C callee-save (but BASE is often refetched).\n|.define BASE,\t\tr14\t// Base of current Lua stack frame.\n|.define KBASE,\t\tr15\t// Constants of current Lua function.\n|.define PC,\t\tr16\t// Next PC.\n|.define DISPATCH,\tr17\t// Opcode dispatch table.\n|.define LREG,\t\tr18\t// Register holding lua_State (also in SAVE_L).\n|.define MULTRES,\tr19\t// Size of multi-result: (nresults+1)*8.\n|.define JGL,\t\tr31\t// On-trace: global_State + 32768.\n|\n|// Constants for type-comparisons, stores and conversions. C callee-save.\n|.define TISNUM,\tr22\n|.define TISNIL,\tr23\n|.define ZERO,\t\tr24\n|.define TOBIT,\t\tf30\t// 2^52 + 2^51.\n|.define TONUM,\t\tf31\t// 2^52 + 2^51 + 2^31.\n|\n|// The following temporaries are not saved across C calls, except for RA.\n|.define RA,\t\tr20\t// Callee-save.\n|.define RB,\t\tr10\n|.define RC,\t\tr11\n|.define RD,\t\tr12\n|.define INS,\t\tr7\t// Overlaps CARG5.\n|\n|.define TMP0,\t\tr0\n|.define TMP1,\t\tr8\n|.define TMP2,\t\tr9\n|.define TMP3,\t\tr6\t// Overlaps CARG4.\n|\n|// Saved temporaries.\n|.define SAVE0,\t\tr21\n|\n|// Calling conventions.\n|.define CARG1,\t\tr3\n|.define CARG2,\t\tr4\n|.define CARG3,\t\tr5\n|.define CARG4,\t\tr6\t// Overlaps TMP3.\n|.define CARG5,\t\tr7\t// Overlaps INS.\n|\n|.define FARG1,\t\tf1\n|.define FARG2,\t\tf2\n|\n|.define CRET1,\t\tr3\n|.define CRET2,\t\tr4\n|\n|.define TOCREG,\tr2\t// TOC register (only used by C code).\n|.define ENVREG,\tr11\t// Environment pointer (nested C functions).\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.if GPR64\n|.if FRAME32\n|\n|//\t\t\t456(sp) // \\ 32/64 bit C frame info\n|.define TONUM_LO,\t452(sp) // |\n|.define TONUM_HI,\t448(sp) // |\n|.define TMPD_LO,\t444(sp) // |\n|.define TMPD_HI,\t440(sp) // |\n|.define SAVE_CR,\t432(sp) // | 64 bit CR save.\n|.define SAVE_ERRF,\t424(sp) //  > Parameter save area.\n|.define SAVE_NRES,\t420(sp) // |\n|.define SAVE_L,\t416(sp) // |\n|.define SAVE_PC,\t412(sp) // |\n|.define SAVE_MULTRES,\t408(sp) // |\n|.define SAVE_CFRAME,\t400(sp) // / 64 bit C frame chain.\n|//\t\t\t392(sp) // Reserved.\n|.define CFRAME_SPACE,\t384     // Delta for sp.\n|// Back chain for sp:\t384(sp) <-- sp entering interpreter\n|.define SAVE_LR,\t376(sp) // 32 bit LR stored in hi-part.\n|.define SAVE_GPR_,\t232     // .. 232+18*8: 64 bit GPR saves.\n|.define SAVE_FPR_,\t88      // .. 88+18*8: 64 bit FPR saves.\n|//\t\t\t80(sp) // Needed for 16 byte stack frame alignment.\n|//\t\t\t16(sp)  // Callee parameter save area (ABI mandated).\n|//\t\t\t8(sp)   // Reserved\n|// Back chain for sp:\t0(sp)   <-- sp while in interpreter\n|// 32 bit sp stored in hi-part of 0(sp).\n|\n|.define TMPD_BLO,\t447(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|\n|.else\n|\n|//\t\t\t508(sp) // \\ 32 bit C frame info.\n|.define SAVE_ERRF,\t472(sp) // |\n|.define SAVE_NRES,\t468(sp) // |\n|.define SAVE_L,\t464(sp) //  > Parameter save area.\n|.define SAVE_PC,\t460(sp) // |\n|.define SAVE_MULTRES,\t456(sp) // |\n|.define SAVE_CFRAME,\t448(sp) // / 64 bit C frame chain.\n|.define SAVE_LR,\t416(sp)\n|.define CFRAME_SPACE,\t400     // Delta for sp.\n|// Back chain for sp:\t400(sp) <-- sp entering interpreter\n|.define SAVE_FPR_,\t256     // .. 256+18*8: 64 bit FPR saves.\n|.define SAVE_GPR_,\t112     // .. 112+18*8: 64 bit GPR saves.\n|//\t\t\t48(sp)  // Callee parameter save area (ABI mandated).\n|.define SAVE_TOC,\t40(sp)  // TOC save area.\n|.define TMPD_LO,\t36(sp)  // \\ Link editor temp (ABI mandated).\n|.define TMPD_HI,\t32(sp)  // /\n|.define TONUM_LO,\t28(sp)  // \\ Compiler temp (ABI mandated).\n|.define TONUM_HI,\t24(sp)  // /\n|// Next frame lr:\t16(sp)\n|.define SAVE_CR,\t8(sp)  // 64 bit CR save.\n|// Back chain for sp:\t0(sp)\t<-- sp while in interpreter\n|\n|.define TMPD_BLO,\t39(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|\n|.endif\n|.else\n|\n|.define SAVE_LR,\t276(sp)\n|.define CFRAME_SPACE,\t272     // Delta for sp.\n|// Back chain for sp:\t272(sp) <-- sp entering interpreter\n|.define SAVE_FPR_,\t128     // .. 128+18*8: 64 bit FPR saves.\n|.define SAVE_GPR_,\t56      // .. 56+18*4: 32 bit GPR saves.\n|.define SAVE_CR,\t52(sp)  // 32 bit CR save.\n|.define SAVE_ERRF,\t48(sp)  // 32 bit C frame info.\n|.define SAVE_NRES,\t44(sp)\n|.define SAVE_CFRAME,\t40(sp)\n|.define SAVE_L,\t36(sp)\n|.define SAVE_PC,\t32(sp)\n|.define SAVE_MULTRES,\t28(sp)\n|.define UNUSED1,\t24(sp)\n|.define TMPD_LO,\t20(sp)\n|.define TMPD_HI,\t16(sp)\n|.define TONUM_LO,\t12(sp)\n|.define TONUM_HI,\t8(sp)\n|// Next frame lr:\t4(sp)\n|// Back chain for sp:\t0(sp)\t<-- sp while in interpreter\n|\n|.define TMPD_BLO,\t23(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|\n|.endif\n|\n|.macro save_, reg\n|.if GPR64\n|  std r..reg, SAVE_GPR_+(reg-14)*8(sp)\n|.else\n|  stw r..reg, SAVE_GPR_+(reg-14)*4(sp)\n|.endif\n|  stfd f..reg, SAVE_FPR_+(reg-14)*8(sp)\n|.endmacro\n|.macro rest_, reg\n|.if GPR64\n|  ld r..reg, SAVE_GPR_+(reg-14)*8(sp)\n|.else\n|  lwz r..reg, SAVE_GPR_+(reg-14)*4(sp)\n|.endif\n|  lfd f..reg, SAVE_FPR_+(reg-14)*8(sp)\n|.endmacro\n|\n|.macro saveregs\n|.if GPR64 and not FRAME32\n|  stdu sp, -CFRAME_SPACE(sp)\n|.else\n|  stwu sp, -CFRAME_SPACE(sp)\n|.endif\n|  save_ 14; save_ 15; save_ 16\n|  mflr r0\n|  save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22\n|.if GPR64 and not FRAME32\n|  std r0, SAVE_LR\n|.else\n|  stw r0, SAVE_LR\n|.endif\n|  save_ 23; save_ 24; save_ 25\n|  mfcr r0\n|  save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31\n|.if GPR64\n|  std r0, SAVE_CR\n|.else\n|  stw r0, SAVE_CR\n|.endif\n|  .toc std TOCREG, SAVE_TOC\n|.endmacro\n|\n|.macro restoreregs\n|.if GPR64 and not FRAME32\n|  ld r0, SAVE_LR\n|.else\n|  lwz r0, SAVE_LR\n|.endif\n|.if GPR64\n|  ld r12, SAVE_CR\n|.else\n|  lwz r12, SAVE_CR\n|.endif\n|  rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19\n|  mtlr r0;\n|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif\n|  rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25\n|.if PPE; mtocrf 0x10, r12; .endif\n|  rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31\n|.if PPE; mtocrf 0x08, r12; .endif\n|  addi sp, sp, CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; tw 4, sp, sp; .endmacro\n|\n|// int/FP conversions.\n|.macro tonum_i, freg, reg\n|  xoris reg, reg, 0x8000\n|  stw reg, TONUM_LO\n|  lfd freg, TONUM_D\n|  fsub freg, freg, TONUM\n|.endmacro\n|\n|.macro tonum_u, freg, reg\n|  stw reg, TONUM_LO\n|  lfd freg, TONUM_D\n|  fsub freg, freg, TOBIT\n|.endmacro\n|\n|.macro toint, reg, freg, tmpfreg\n|  fctiwz tmpfreg, freg\n|  stfd tmpfreg, TMPD\n|  lwz reg, TMPD_LO\n|.endmacro\n|\n|.macro toint, reg, freg\n|  toint reg, freg, freg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_PC,\t-8\n|.define FRAME_FUNC,\t-4\n|\n|// Instruction decode.\n|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro\n|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro\n|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro\n|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro\n|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro\n|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro\n|\n|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro\n|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  lwz INS, 0(PC)\n|   addi PC, PC, 4\n|.endmacro\n|// Instruction decode+dispatch. Note: optimized for e300!\n|.macro ins_NEXT2\n|  decode_OPP TMP1, INS\n|  lpx TMP0, DISPATCH, TMP1\n|  mtctr TMP0\n|   decode_RB8 RB, INS\n|   decode_RD8 RD, INS\n|   decode_RA8 RA, INS\n|   decode_RC8 RC, INS\n|  bctr\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  lwz PC, LFUNC:RB->pc\n|  lwz INS, 0(PC)\n|   addi PC, PC, 4\n|  decode_OPP TMP1, INS\n|   decode_RA8 RA, INS\n|  lpx TMP0, DISPATCH, TMP1\n|   add RA, RA, BASE\n|  mtctr TMP0\n|  bctr\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  stw PC, FRAME_PC(BASE)\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checknum, reg; cmplw reg, TISNUM; .endmacro\n|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro\n|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro\n|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro\n|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro\n|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro\n|\n|.macro branch_RD\n|  srwi TMP0, RD, 1\n|  addis PC, PC, -(BCBIAS_J*4 >> 16)\n|  add PC, PC, TMP0\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta, target\n|  rlwinm TMP1, PC, 31, 25, 30\n|  addi TMP1, TMP1, GG_DISP2HOT\n|  lhzx TMP2, DISPATCH, TMP1\n|  addic. TMP2, TMP2, -delta\n|  sthx TMP2, DISPATCH, TMP1\n|  blt target\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL, ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state. Uses TMP0.\n|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro\n|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|  // Assumes LJ_GC_BLACK is 0x04.\n|   rlwinm mark, mark, 0, 30, 28\t\t// black2gray(tab)\n|  stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   stb mark, tab->marked\n|  stw tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: TMP2 = previous base.\n  |  andix. TMP0, PC, FRAME_P\n  |   li TMP1, LJ_TTRUE\n  |  beq ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  lwz PC, FRAME_PC(TMP2)\t\t// Fetch PC of previous frame.\n  |  mr BASE, TMP2\t\t\t// Restore caller base.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   stwu TMP1, FRAME_PC(RA)\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  addi RD, RD, 8\t\t\t// RD = (nresults+1)*8.\n  |   andix. TMP0, PC, FRAME_TYPE\n  |  cmpwi cr1, RD, 0\n  |  li CRET1, LUA_YIELD\n  |  beq cr1, ->vm_unwind_c_eh\n  |  mr MULTRES, RD\n  |   beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return\n  |  // TMP0 = PC & FRAME_TYPE\n  |  cmpwi TMP0, FRAME_C\n  |   rlwinm TMP2, PC, 0, 0, 28\n  |    li_vmstate C\n  |   sub TMP2, BASE, TMP2\t\t// TMP2 = previous base.\n  |  bney ->vm_returnp\n  |\n  |  addic. TMP1, RD, -8\n  |   stp TMP2, L->base\n  |   lwz TMP2, SAVE_NRES\n  |    subi BASE, BASE, 8\n  |    st_vmstate\n  |   slwi TMP2, TMP2, 3\n  |  beq >2\n  |1:\n  |  addic. TMP1, TMP1, -8\n  |   lfd f0, 0(RA)\n  |    addi RA, RA, 8\n  |   stfd f0, 0(BASE)\n  |    addi BASE, BASE, 8\n  |  bney <1\n  |\n  |2:\n  |  cmpw TMP2, RD\t\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  stp BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  lp TMP0, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   li CRET1, 0\t\t\t// Ok return status for vm_pcall.\n  |  stp TMP0, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  blr\n  |\n  |6:\n  |  ble >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  lwz TMP1, L->maxstack\n  |  cmplw BASE, TMP1\n  |  bge >8\n  |  stw TISNIL, 0(BASE)\n  |  addi RD, RD, 8\n  |  addi BASE, BASE, 8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  subfic TMP3, TMP2, 0\t\t// LUA_MULTRET+1 case?\n  |   sub TMP0, RD, TMP2\n  |  subfe TMP1, TMP1, TMP1\t\t// TMP1 = TMP2 == 0 ? 0 : -1\n  |   and TMP0, TMP0, TMP1\n  |  sub BASE, BASE, TMP0\t\t// Either keep top or shrink it.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  stp BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |   mr SAVE0, RD\n  |  srwi CARG2, TMP2, 3\n  |  mr CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |    lwz TMP2, SAVE_NRES\n  |   mr RD, SAVE0\n  |    slwi TMP2, TMP2, 3\n  |  lp BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mr sp, CARG1\n  |  mr CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  lwz L, SAVE_L\n  |  .toc ld TOCREG, SAVE_TOC\n  |   li TMP0, ~LJ_VMST_C\n  |  lwz GL:TMP1, L->glref\n  |   stw TMP0, GL:TMP1->vmstate\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |.if GPR64\n  |  rldicr sp, CARG1, 0, 61\n  |.else\n  |  rlwinm sp, CARG1, 0, 0, 29\n  |.endif\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  lwz L, SAVE_L\n  |  .toc ld TOCREG, SAVE_TOC\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  lp BASE, L->base\n  |     lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     li ZERO, 0\n  |     stw TMP3, TMPD\n  |  li TMP1, LJ_TFALSE\n  |     ori TMP3, TMP3, 0x0004\t\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     li TISNIL, LJ_TNIL\n  |    li_vmstate INTERP\n  |     lfs TOBIT, TMPD\n  |  lwz PC, FRAME_PC(BASE)\t\t// Fetch PC of previous frame.\n  |  la RA, -8(BASE)\t\t\t// Results start at BASE-8.\n  |     stw TMP3, TMPD\n  |   addi DISPATCH, DISPATCH, GG_G2DISP\n  |  stw TMP1, 0(RA)\t\t\t// Prepend false to error message.\n  |  li RD, 16\t\t\t\t// 2 results: false + error message.\n  |    st_vmstate\n  |     lfs TONUM, TMPD\n  |  b ->vm_returnc\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  li CARG2, LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |  stp BASE, L->base\n  |   addi PC, PC, 4\t\t\t// Must point after first instruction.\n  |  stp RC, L->top\n  |   srwi CARG2, RA, 3\n  |2:\n  |  // L->base = new base, L->top = top\n  |   stw PC, SAVE_PC\n  |  mr CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lp BASE, L->base\n  |  lp RC, L->top\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  sub RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mr L, CARG1\n  |    lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  mr BASE, CARG2\n  |    lbz TMP1, L->status\n  |   stw L, SAVE_L\n  |  li PC, FRAME_CP\n  |  addi TMP0, sp, CFRAME_RESUME\n  |    addi DISPATCH, DISPATCH, GG_G2DISP\n  |   stw CARG3, SAVE_NRES\n  |    cmplwi TMP1, 0\n  |   stw CARG3, SAVE_ERRF\n  |   stp CARG3, SAVE_CFRAME\n  |   stw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  stp TMP0, L->cframe\n  |    beq >3\n  |\n  |  // Resume after yield (like a return).\n  |  stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  mr RA, BASE\n  |   lp BASE, L->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lp TMP1, L->top\n  |  lwz PC, FRAME_PC(BASE)\n  |     lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |    stb CARG3, L->status\n  |     stw TMP3, TMPD\n  |     ori TMP3, TMP3, 0x0004\t\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     lfs TOBIT, TMPD\n  |   sub RD, TMP1, BASE\n  |     stw TMP3, TMPD\n  |     lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |   addi RD, RD, 8\n  |     stw TMP0, TONUM_HI\n  |    li_vmstate INTERP\n  |     li ZERO, 0\n  |    st_vmstate\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   mr MULTRES, RD\n  |     lfs TONUM, TMPD\n  |     li TISNIL, LJ_TNIL\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  li PC, FRAME_CP\n  |  stw CARG4, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  li PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  lp TMP1, L:CARG1->cframe\n  |    mr L, CARG1\n  |   stw CARG3, SAVE_NRES\n  |    lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   stw CARG1, SAVE_L\n  |     mr BASE, CARG2\n  |    addi DISPATCH, DISPATCH, GG_G2DISP\n  |   stw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  stp TMP1, SAVE_CFRAME\n  |  stp sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  lp TMP2, L->base\t\t\t// TMP2 = old base (used in vmeta_call).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lp TMP1, L->top\n  |     lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  add PC, PC, BASE\n  |     stw TMP3, TMPD\n  |     li ZERO, 0\n  |     ori TMP3, TMP3, 0x0004\t\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     lfs TOBIT, TMPD\n  |  sub PC, PC, TMP2\t\t\t// PC = frame delta + frame type\n  |     stw TMP3, TMPD\n  |     lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |   sub NARGS8:RC, TMP1, BASE\n  |     stw TMP0, TONUM_HI\n  |    li_vmstate INTERP\n  |     lfs TONUM, TMPD\n  |     li TISNIL, LJ_TNIL\n  |    st_vmstate\n  |\n  |->vm_call_dispatch:\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  lwz TMP0, FRAME_PC(BASE)\n  |   lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  checkfunc TMP0; bne ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mr L, CARG1\n  |   lwz TMP0, L:CARG1->stack\n  |  stw CARG1, SAVE_L\n  |   lp TMP1, L->top\n  |     lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  stw CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   sub TMP0, TMP0, TMP1\t\t// Compute -savestack(L, L->top).\n  |    lp TMP1, L->cframe\n  |     addi DISPATCH, DISPATCH, GG_G2DISP\n  |  .toc lp CARG4, 0(CARG4)\n  |  li TMP2, 0\n  |   stw TMP0, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  stw TMP2, SAVE_ERRF\t\t// No error function.\n  |    stp TMP1, SAVE_CFRAME\n  |    stp sp, L->cframe\t\t// Add our C frame to cframe chain.\n  |     stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  mtctr CARG4\n  |  bctrl\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.if PPE\n  |  mr BASE, CRET1\n  |  cmpwi CRET1, 0\n  |.else\n  |  mr. BASE, CRET1\n  |.endif\n  |   li PC, FRAME_CP\n  |  bne <3\t\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the\n  |// stack, so BASE doesn't need to be reloaded across these calls.\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8\n  |  lwz TMP0, -12(BASE)\t\t// Continuation.\n  |   mr RB, BASE\n  |   mr BASE, TMP2\t\t\t// Restore caller BASE.\n  |    lwz LFUNC:TMP1, FRAME_FUNC(TMP2)\n  |.if FFI\n  |  cmplwi TMP0, 1\n  |.endif\n  |     lwz PC, -16(RB)\t\t\t// Restore PC from [cont|PC].\n  |   subi TMP2, RD, 8\n  |    lwz TMP1, LFUNC:TMP1->pc\n  |   stwx TISNIL, RA, TMP2\t\t// Ensure one valid arg.\n  |.if FFI\n  |  ble >1\n  |.endif\n  |    lwz KBASE, PC2PROTO(k)(TMP1)\n  |  // BASE = base, RA = resultptr, RB = meta base\n  |  mtctr TMP0\n  |  bctr\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |  subi TMP1, RB, 16\n  |  sub RC, TMP1, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, RB = meta base\n  |  lwz INS, -4(PC)\n  |   subi CARG2, RB, 16\n  |  decode_RB8 SAVE0, INS\n  |   lfd f0, 0(RA)\n  |  add TMP1, BASE, SAVE0\n  |   stp BASE, L->base\n  |  cmplw TMP1, CARG2\n  |   sub CARG3, CARG2, TMP1\n  |  decode_RA8 RA, INS\n  |   stfd f0, 0(CARG2)\n  |  bney ->BC_CAT_Z\n  |   stfdx f0, BASE, RA\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TSTR\n  |   decode_RB8 RB, INS\n  |  stw STR:RC, 4(CARG3)\n  |   add CARG2, BASE, RB\n  |  stw TMP0, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tgets:\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TTAB\n  |  stw TAB:RB, 4(CARG2)\n  |   la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)\n  |  stw TMP0, 0(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   stw STR:RC, 4(CARG3)\n  |   stw TMP1, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// TMP0 = index\n  |.if not DUALNUM\n  |  tonum_u f0, TMP0\n  |.endif\n  |   decode_RB8 RB, INS\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |   add CARG2, BASE, RB\n  |.if DUALNUM\n  |  stw TISNUM, 0(CARG3)\n  |  stw TMP0, 4(CARG3)\n  |.else\n  |  stfd f0, 0(CARG3)\n  |.endif\n  |  b >1\n  |\n  |->vmeta_tgetv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |  stp BASE, L->base\n  |  mr CARG1, L\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cmplwi CRET1, 0\n  |  beq >3\n  |   lfd f0, 0(CRET1)\n  |  ins_next1\n  |   stfdx f0, BASE, RA\n  |  ins_next2\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  subfic TMP1, BASE, FRAME_CONT\n  |  lp BASE, L->top\n  |  stw PC, -16(BASE)\t\t\t// [cont|PC]\n  |   add PC, TMP1, BASE\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   li NARGS8:RC, 16\t\t\t// 2 args for func(t, k).\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cmplwi CRET1, 0\n  |  beq >1\n  |  lfd f14, 0(CRET1)\n  |  b ->BC_TGETR_Z\n  |1:\n  |  stwx TISNIL, BASE, RA\n  |  b ->cont_nop\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TSTR\n  |   decode_RB8 RB, INS\n  |  stw STR:RC, 4(CARG3)\n  |   add CARG2, BASE, RB\n  |  stw TMP0, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tsets:\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TTAB\n  |  stw TAB:RB, 4(CARG2)\n  |   la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)\n  |  stw TMP0, 0(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   stw STR:RC, 4(CARG3)\n  |   stw TMP1, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// TMP0 = index\n  |.if not DUALNUM\n  |  tonum_u f0, TMP0\n  |.endif\n  |   decode_RB8 RB, INS\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |   add CARG2, BASE, RB\n  |.if DUALNUM\n  |  stw TISNUM, 0(CARG3)\n  |  stw TMP0, 4(CARG3)\n  |.else\n  |  stfd f0, 0(CARG3)\n  |.endif\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |  stp BASE, L->base\n  |  mr CARG1, L\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cmplwi CRET1, 0\n  |   lfdx f0, BASE, RA\n  |  beq >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  ins_next1\n  |   stfd f0, 0(CRET1)\n  |  ins_next2\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  subfic TMP1, BASE, FRAME_CONT\n  |  lp BASE, L->top\n  |  stw PC, -16(BASE)\t\t\t// [cont|PC]\n  |   add PC, TMP1, BASE\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   li NARGS8:RC, 24\t\t\t// 3 args for func(t, k, v)\n  |  stfd f0, 16(BASE)\t\t\t// Copy value to third argument.\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  stp BASE, L->base\n  |  stw PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |  stfd f14, 0(CRET1)\n  |  b ->cont_nop\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  mr CARG1, L\n  |   subi PC, PC, 4\n  |.if DUALNUM\n  |  mr CARG2, RA\n  |.else\n  |  add CARG2, BASE, RA\n  |.endif\n  |   stw PC, SAVE_PC\n  |.if DUALNUM\n  |  mr CARG3, RD\n  |.else\n  |  add CARG3, BASE, RD\n  |.endif\n  |   stp BASE, L->base\n  |  decode_OP1 CARG4, INS\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  cmplwi CRET1, 1\n  |  bgt ->vmeta_binop\n  |  subfic CRET1, CRET1, 0\n  |4:\n  |  lwz INS, 0(PC)\n  |   addi PC, PC, 4\n  |  decode_RD4 TMP2, INS\n  |  addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n  |  and TMP2, TMP2, CRET1\n  |  add PC, PC, TMP2\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  lwz INS, -4(PC)\n  |   lfd f0, 0(RA)\n  |  decode_RA8 TMP1, INS\n  |   stfdx f0, BASE, TMP1\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  lwz TMP0, 0(RA)\n  |  .gpr64 extsw TMP0, TMP0\n  |  subfic TMP0, TMP0, LJ_TTRUE\t// Branch if result is true.\n  |  subfe CRET1, CRET1, CRET1\n  |  not CRET1, CRET1\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  lwz TMP0, 0(RA)\n  |  .gpr64 extsw TMP0, TMP0\n  |  subfic TMP0, TMP0, LJ_TTRUE\t// Branch if result is false.\n  |  subfe CRET1, CRET1, CRET1\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  mr CARG2, INS\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |   srwi CARG2, RA, 3\n  |   mr CARG1, L\n  |   srwi CARG3, RD, 3\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_nv:\n  |  add CARG3, KBASE, RC\n  |  add CARG4, BASE, RB\n  |  b >1\n  |->vmeta_arith_nv2:\n  |.if DUALNUM\n  |  mr CARG3, RC\n  |  mr CARG4, RB\n  |  b >1\n  |.endif\n  |\n  |->vmeta_unm:\n  |  mr CARG3, RD\n  |  mr CARG4, RD\n  |  b >1\n  |\n  |->vmeta_arith_vn:\n  |  add CARG3, BASE, RB\n  |  add CARG4, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  add CARG3, BASE, RB\n  |  add CARG4, BASE, RC\n  |.if DUALNUM\n  |  b >1\n  |.endif\n  |->vmeta_arith_vn2:\n  |->vmeta_arith_vv2:\n  |.if DUALNUM\n  |  mr CARG3, RB\n  |  mr CARG4, RC\n  |.endif\n  |1:\n  |  add CARG2, BASE, RA\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  decode_OP1 CARG5, INS\t\t// Caveat: CARG5 overlaps INS.\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  cmplwi CRET1, 0\n  |  beq ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub TMP1, CRET1, BASE\n  |   stw PC, -16(CRET1)\t\t// [cont|PC]\n  |   mr TMP2, BASE\n  |  addi PC, TMP1, FRAME_CONT\n  |   mr BASE, CRET1\n  |  li NARGS8:RC, 16\t\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n#if LJ_52\n  |  mr SAVE0, CARG1\n#endif\n  |  mr CARG2, RD\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  cmplwi CRET1, 0\n  |  bne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  mr CARG1, SAVE0\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8\n  |  mr CARG1, L\n  |   stp TMP2, L->base\t\t\t// This is the callers base!\n  |  subi CARG2, BASE, 8\n  |   stw PC, SAVE_PC\n  |  add CARG3, BASE, RC\n  |   mr SAVE0, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   addi NARGS8:RC, SAVE0, 8\t\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  subi CARG2, RA, 8\n  |   stw PC, SAVE_PC\n  |  add CARG3, RA, RC\n  |   mr SAVE0, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  lwz TMP1, FRAME_PC(BASE)\n  |   addi NARGS8:RC, SAVE0, 8\t\t// Got one more argument now.\n  |   lwz LFUNC:RB, FRAME_FUNC(RA)\t// Guaranteed to be a function here.\n  |  b ->BC_CALLT_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  mr CARG2, RA\n  |   stw PC, SAVE_PC\n  |  mr SAVE0, INS\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |.if JIT\n  |   decode_OP1 TMP0, SAVE0\n  |.endif\n  |  decode_RA8 RA, SAVE0\n  |.if JIT\n  |   cmpwi TMP0, BC_JFORI\n  |.endif\n  |  decode_RD8 RD, SAVE0\n  |.if JIT\n  |   beqy =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz CARG1, 4(BASE)\n  |  blt ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lwz CARG4, 8(BASE)\n  |   lwz CARG1, 4(BASE)\n  |    lwz CARG2, 12(BASE)\n  |  blt ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lfd FARG1, 0(BASE)\n  |  blt ->fff_fallback\n  |  checknum CARG3; bge ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lfd FARG1, 0(BASE)\n  |   lwz CARG4, 8(BASE)\n  |    lfd FARG2, 8(BASE)\n  |  blt ->fff_fallback\n  |  checknum CARG3; bge ->fff_fallback\n  |  checknum CARG4; bge ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1.\n  |.macro ffgccheck\n  |  lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n  |  lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n  |  cmplw TMP0, TMP1\n  |  bgel ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  li TMP1, LJ_TFALSE\n  |   la RA, -8(BASE)\n  |  cmplw cr1, CARG3, TMP1\n  |    lwz PC, FRAME_PC(BASE)\n  |  bge cr1, ->fff_fallback\n  |   stw CARG3, 0(RA)\n  |  addi RD, NARGS8:RC, 8\t\t// Compute (nresults+1)*8.\n  |   stw CARG1, 4(RA)\n  |  beq ->fff_res\t\t\t// Done if exactly 1 argument.\n  |  li TMP1, 8\n  |  subi RC, RC, 8\n  |1:\n  |  cmplw TMP1, RC\n  |   lfdx f0, BASE, TMP1\n  |   stfdx f0, RA, TMP1\n  |    addi TMP1, TMP1, 8\n  |  bney <1\n  |  b ->fff_res\n  |\n  |.ffunc type\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |  blt ->fff_fallback\n  |  .gpr64 extsw CARG1, CARG1\n  |  subfc TMP0, TISNUM, CARG1\n  |  subfe TMP2, CARG1, CARG1\n  |  orc TMP1, TMP2, TMP0\n  |  addi TMP1, TMP1, ~LJ_TISNUM+1\n  |  slwi TMP1, TMP1, 3\n  |   la TMP2, CFUNC:RB->upvalue\n  |  lfdx FARG1, TMP2, TMP1\n  |  b ->fff_resn\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  checktab CARG3; bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  lwz TAB:CARG1, TAB:CARG1->metatable\n  |2:\n  |  li CARG3, LJ_TNIL\n  |   cmplwi TAB:CARG1, 0\n  |  lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)\n  |   beq ->fff_restv\n  |  lwz TMP0, TAB:CARG1->hmask\n  |   li CARG3, LJ_TTAB\t\t\t// Use metatable as default result.\n  |  lwz TMP1, STR:RC->hash\n  |  lwz NODE:TMP2, TAB:CARG1->node\n  |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n  |  slwi TMP0, TMP1, 5\n  |  slwi TMP1, TMP1, 3\n  |  sub TMP1, TMP0, TMP1\n  |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  lwz CARG4, NODE:TMP2->key\n  |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n  |    lwz CARG2, NODE:TMP2->val\n  |     lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)\n  |  checkstr CARG4; bne >4\n  |   cmpw TMP0, STR:RC; beq >5\n  |4:\n  |  lwz NODE:TMP2, NODE:TMP2->next\n  |  cmplwi NODE:TMP2, 0\n  |  beq ->fff_restv\t\t\t// Not found, keep default result.\n  |  b <3\n  |5:\n  |  checknil CARG2\n  |  beq ->fff_restv\t\t\t// Ditto for nil value.\n  |  mr CARG3, CARG2\t\t\t// Return value of mt.__metatable.\n  |  mr CARG1, TMP1\n  |  b ->fff_restv\n  |\n  |6:\n  |  cmpwi CARG3, LJ_TUDATA; beq <1\n  |  .gpr64 extsw CARG3, CARG3\n  |  subfc TMP0, TISNUM, CARG3\n  |  subfe TMP2, CARG3, CARG3\n  |  orc TMP1, TMP2, TMP0\n  |  addi TMP1, TMP1, ~LJ_TISNUM+1\n  |  slwi TMP1, TMP1, 2\n  |   la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH)\n  |  lwzx TAB:CARG1, TMP2, TMP1\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |   checktab CARG3; bne ->fff_fallback\n  |  lwz TAB:TMP1, TAB:CARG1->metatable\n  |   checktab CARG4; bne ->fff_fallback\n  |  cmplwi TAB:TMP1, 0\n  |   lbz TMP3, TAB:CARG1->marked\n  |  bne ->fff_fallback\n  |   andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n  |    stw TAB:CARG2, TAB:CARG1->metatable\n  |   beq ->fff_restv\n  |  barrierback TAB:CARG1, TMP3, TMP0\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG4, 0(BASE)\n  |    lwz TAB:CARG2, 4(BASE)\n  |  blt ->fff_fallback\n  |  checktab CARG4; bne ->fff_fallback\n  |   la CARG3, 8(BASE)\n  |   mr CARG1, L\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |  lfd FARG1, 0(CRET1)\n  |  b ->fff_resn\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |    lfd FARG1, 0(BASE)\n  |  bne ->fff_fallback\t\t\t// Exactly one argument.\n  |   checknum CARG1; bgt ->fff_fallback\n  |  b ->fff_resn\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  checkstr CARG3\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\t\t\t// String key?\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)\n  |  checknum CARG3\n  |  cmplwi cr1, TMP0, 0\n  |   stp BASE, L->base\t\t\t// Add frame since C call can throw.\n  |  crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  beq ->fff_fallback\n  |  ffgccheck\n  |  mr CARG1, L\n  |  mr CARG2, BASE\n  |.if DUALNUM\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |.else\n  |  bl extern lj_strfmt_num\t\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // Returns GCstr *.\n  |  li CARG3, LJ_TSTR\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc next\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |    lwz TAB:CARG2, 4(BASE)\n  |  blt ->fff_fallback\n  |   stwx TISNIL, BASE, NARGS8:RC\t// Set missing 2nd arg to nil.\n  |  checktab CARG1\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n  |   stp BASE, L->base\t\t\t// Add frame since C call can throw.\n  |  mr CARG1, L\n  |   stp BASE, L->top\t\t\t// Dummy frame length is ok.\n  |  la CARG3, 8(BASE)\n  |   stw PC, SAVE_PC\n  |  bl extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Returns 0 at end of traversal.\n  |  cmplwi CRET1, 0\n  |   li CARG3, LJ_TNIL\n  |  beq ->fff_restv\t\t\t// End of traversal: return nil.\n  |  lfd f0, 8(BASE)\t\t\t// Copy key and value to results.\n  |   la RA, -8(BASE)\n  |  lfd f1, 16(BASE)\n  |  stfd f0, 0(RA)\n  |   li RD, (2+1)*8\n  |  stfd f1, 8(RA)\n  |  b ->fff_res\n  |\n  |.ffunc_1 pairs\n  |  checktab CARG3\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n#if LJ_52\n  |   lwz TAB:TMP2, TAB:CARG1->metatable\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |   cmplwi TAB:TMP2, 0\n  |  la RA, -8(BASE)\n  |   bne ->fff_fallback\n#else\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |  la RA, -8(BASE)\n#endif\n  |   stw TISNIL, 8(BASE)\n  |  li RD, (3+1)*8\n  |  stfd f0, 0(RA)\n  |  b ->fff_res\n  |\n  |.ffunc ipairs_aux\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lwz TAB:CARG1, 4(BASE)\n  |   lwz CARG4, 8(BASE)\n  |.if DUALNUM\n  |    lwz TMP2, 12(BASE)\n  |.else\n  |    lfd FARG2, 8(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checktab CARG3\n  |  checknum cr1, CARG4\n  |   lwz PC, FRAME_PC(BASE)\n  |.if DUALNUM\n  |  bne ->fff_fallback\n  |  bne cr1, ->fff_fallback\n  |.else\n  |    lus TMP0, 0x3ff0\n  |    stw ZERO, TMPD_LO\n  |  bne ->fff_fallback\n  |    stw TMP0, TMPD_HI\n  |  bge cr1, ->fff_fallback\n  |    lfd FARG1, TMPD\n  |  toint TMP2, FARG2, f0\n  |.endif\n  |   lwz TMP0, TAB:CARG1->asize\n  |   lwz TMP1, TAB:CARG1->array\n  |.if not DUALNUM\n  |  fadd FARG2, FARG2, FARG1\n  |.endif\n  |  addi TMP2, TMP2, 1\n  |   la RA, -8(BASE)\n  |  cmplw TMP0, TMP2\n  |.if DUALNUM\n  |  stw TISNUM, 0(RA)\n  |   slwi TMP3, TMP2, 3\n  |  stw TMP2, 4(RA)\n  |.else\n  |   slwi TMP3, TMP2, 3\n  |  stfd FARG2, 0(RA)\n  |.endif\n  |  ble >2\t\t\t\t// Not in array part?\n  |  lwzx TMP2, TMP1, TMP3\n  |  lfdx f0, TMP1, TMP3\n  |1:\n  |  checknil TMP2\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\t\t\t// End of iteration, return 0 results.\n  |   li RD, (2+1)*8\n  |  stfd f0, 8(RA)\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lwz TMP0, TAB:CARG1->hmask\n  |  cmplwi TMP0, 0\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\n  |   mr CARG2, TMP2\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cmplwi CRET1, 0\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\n  |  lwz TMP2, 0(CRET1)\n  |  lfd f0, 0(CRET1)\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktab CARG3\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n#if LJ_52\n  |   lwz TAB:TMP2, TAB:CARG1->metatable\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |   cmplwi TAB:TMP2, 0\n  |  la RA, -8(BASE)\n  |   bne ->fff_fallback\n#else\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |  la RA, -8(BASE)\n#endif\n  |.if DUALNUM\n  |  stw TISNUM, 8(BASE)\n  |.else\n  |  stw ZERO, 8(BASE)\n  |.endif\n  |   stw ZERO, 12(BASE)\n  |  li RD, (3+1)*8\n  |  stfd f0, 0(RA)\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  cmplwi NARGS8:RC, 8\n  |   lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  blt ->fff_fallback\n  |   mr TMP2, BASE\n  |   la BASE, 8(BASE)\n  |  // Remember active hook before pcall.\n  |  rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31\n  |   subi NARGS8:RC, NARGS8:RC, 8\n  |  addi PC, TMP3, 8+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc xpcall\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG4, 8(BASE)\n  |    lfd FARG2, 8(BASE)\n  |    lfd FARG1, 0(BASE)\n  |  blt ->fff_fallback\n  |  lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH)\n  |   mr TMP2, BASE\n  |  checkfunc CARG4; bne ->fff_fallback  // Traceback must be a function.\n  |   la BASE, 16(BASE)\n  |  // Remember active hook before pcall.\n  |  rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31\n  |    stfd FARG2, 0(TMP2)\t\t// Swap function and traceback.\n  |  subi NARGS8:RC, NARGS8:RC, 16\n  |    stfd FARG1, 8(TMP2)\n  |  addi PC, TMP1, 16+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  lwz L:CARG1, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  lbz TMP0, L:CARG1->status\n  |   lp TMP1, L:CARG1->cframe\n  |    lp CARG2, L:CARG1->top\n  |  cmplwi cr0, TMP0, LUA_YIELD\n  |    lp TMP2, L:CARG1->base\n  |   cmplwi cr1, TMP1, 0\n  |   lwz TMP0, L:CARG1->maxstack\n  |    cmplw cr7, CARG2, TMP2\n  |   lwz PC, FRAME_PC(BASE)\n  |  crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq\t\t// st>LUA_YIELD || cframe!=0\n  |   add TMP2, CARG2, NARGS8:RC\n  |  crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq\t// base==top && st!=LUA_YIELD\n  |   cmplw cr1, TMP2, TMP0\n  |  cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt\n  |   stw PC, SAVE_PC\n  |  cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt\t\t// cond1 || cond2 || stackov\n  |   stp BASE, L->base\n  |  blt cr6, ->fff_fallback\n  |1:\n  |.if resume\n  |  addi BASE, BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |  subi NARGS8:RC, NARGS8:RC, 8\n  |  subi TMP2, TMP2, 8\n  |.endif\n  |  stp TMP2, L:CARG1->top\n  |  li TMP1, 0\n  |  stp BASE, L->top\n  |2:  // Move args to coroutine.\n  |  cmpw TMP1, NARGS8:RC\n  |   lfdx f0, BASE, TMP1\n  |  beq >3\n  |   stfdx f0, CARG2, TMP1\n  |  addi TMP1, TMP1, 8\n  |  b <2\n  |3:\n  |  li CARG3, 0\n  |   mr L:SAVE0, L:CARG1\n  |  li CARG4, 0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  lp TMP2, L:SAVE0->base\n  |   cmplwi CRET1, LUA_YIELD\n  |  lp TMP3, L:SAVE0->top\n  |    li_vmstate INTERP\n  |  lp BASE, L->base\n  |    stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |    st_vmstate\n  |   bgt >8\n  |  sub RD, TMP3, TMP2\n  |   lwz TMP0, L->maxstack\n  |  cmplwi RD, 0\n  |   add TMP1, BASE, RD\n  |  beq >6\t\t\t\t// No results?\n  |  cmplw TMP1, TMP0\n  |   li TMP1, 0\n  |  bgt >9\t\t\t\t// Need to grow stack?\n  |\n  |  subi TMP3, RD, 8\n  |   stp TMP2, L:SAVE0->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |  cmplw TMP1, TMP3\n  |   lfdx f0, TMP2, TMP1\n  |   stfdx f0, BASE, TMP1\n  |    addi TMP1, TMP1, 8\n  |  bne <5\n  |6:\n  |  andix. TMP0, PC, FRAME_TYPE\n  |.if resume\n  |  li TMP1, LJ_TTRUE\n  |   la RA, -8(BASE)\n  |  stw TMP1, -8(BASE)\t\t\t// Prepend true to results.\n  |  addi RD, RD, 16\n  |.else\n  |  mr RA, BASE\n  |  addi RD, RD, 8\n  |.endif\n  |7:\n  |    stw PC, SAVE_PC\n  |   mr MULTRES, RD\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  andix. TMP0, PC, FRAME_TYPE\n  |  la TMP3, -8(TMP3)\n  |   li TMP1, LJ_TFALSE\n  |  lfd f0, 0(TMP3)\n  |   stp TMP3, L:SAVE0->top\t\t// Remove error from coroutine stack.\n  |    li RD, (2+1)*8\n  |   stw TMP1, -8(BASE)\t\t// Prepend false to results.\n  |    la RA, -8(BASE)\n  |  stfd f0, 0(BASE)\t\t\t// Copy error message.\n  |  b <7\n  |.else\n  |  mr CARG1, L\n  |  mr CARG2, L:SAVE0\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mr CARG1, L\n  |  srwi CARG2, RD, 3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  li CRET1, 0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  lp TMP0, L->cframe\n  |   add TMP1, BASE, NARGS8:RC\n  |   stp BASE, L->base\n  |  andix. TMP0, TMP0, CFRAME_RESUME\n  |   stp TMP1, L->top\n  |    li CRET1, LUA_YIELD\n  |  beq ->fff_fallback\n  |   stp ZERO, L->cframe\n  |    stb CRET1, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  checknum CARG3\n  |.if DUALNUM\n  |  bne >2\n  |  srawi TMP1, CARG1, 31\n  |  xor TMP2, TMP1, CARG1\n  |.if GPR64\n  |  lus TMP0, 0x8000\n  |  sub CARG1, TMP2, TMP1\n  |  cmplw CARG1, TMP0\n  |  beq >1\n  |.else\n  |  sub. CARG1, TMP2, TMP1\n  |  blt >1\n  |.endif\n  |->fff_resi:\n  |  lwz PC, FRAME_PC(BASE)\n  |  la RA, -8(BASE)\n  |  stw TISNUM, -8(BASE)\n  |  stw CRET1, -4(BASE)\n  |  b ->fff_res1\n  |1:\n  |  lus CARG3, 0x41e0\t// 2^31.\n  |  li CARG1, 0\n  |  b ->fff_restv\n  |2:\n  |.endif\n  |  bge ->fff_fallback\n  |  rlwinm CARG3, CARG3, 0, 1, 31\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG3/CARG1 = TValue result.\n  |  lwz PC, FRAME_PC(BASE)\n  |   stw CARG3, -8(BASE)\n  |  la RA, -8(BASE)\n  |   stw CARG1, -4(BASE)\n  |->fff_res1:\n  |  // RA = results, PC = return.\n  |  li RD, (1+1)*8\n  |->fff_res:\n  |  // RA = results, RD = (nresults+1)*8, PC = return.\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   mr MULTRES, RD\n  |  bney ->vm_return\n  |  lwz INS, -4(PC)\n  |  decode_RB8 RB, INS\n  |5:\n  |  cmplw RB, RD\t\t\t// More results expected?\n  |   decode_RA8 TMP0, INS\n  |  bgt >6\n  |  ins_next1\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |   sub BASE, RA, TMP0\n  |  ins_next2\n  |\n  |6:  // Fill up results with nil.\n  |  subi TMP1, RD, 8\n  |   addi RD, RD, 8\n  |  stwx TISNIL, RA, TMP1\n  |  b <5\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_round, func\n  |  .ffunc_1 math_ .. func\n  |   checknum CARG3; beqy ->fff_restv\n  |  rlwinm TMP2, CARG3, 12, 21, 31\n  |   bge ->fff_fallback\n  |  addic. TMP2, TMP2, -1023\t\t// exp = exponent(x) - 1023\n  |  cmplwi cr1, TMP2, 31\t\t// 0 <= exp < 31?\n  |   subfic TMP0, TMP2, 31\n  |  blt >3\n  |  slwi TMP1, CARG3, 11\n  |   srwi TMP3, CARG1, 21\n  |  oris TMP1, TMP1, 0x8000\n  |   addi TMP2, TMP2, 1\n  |  or TMP1, TMP1, TMP3\n  |   slwi CARG2, CARG1, 11\n  |  bge cr1, >4\n  |   slw TMP3, TMP1, TMP2\n  |  srw RD, TMP1, TMP0\n  |   or TMP3, TMP3, CARG2\n  |  srawi TMP2, CARG3, 31\n  |.if \"func\" == \"floor\"\n  |  and TMP1, TMP3, TMP2\n  |  addic TMP0, TMP1, -1\n  |  subfe TMP1, TMP0, TMP1\n  |  add CARG1, RD, TMP1\n  |  xor CARG1, CARG1, TMP2\n  |  sub CARG1, CARG1, TMP2\n  |  b ->fff_resi\n  |.else\n  |  andc TMP1, TMP3, TMP2\n  |  addic TMP0, TMP1, -1\n  |  subfe TMP1, TMP0, TMP1\n  |  add CARG1, RD, TMP1\n  |  cmpw CARG1, RD\n  |  xor CARG1, CARG1, TMP2\n  |  sub CARG1, CARG1, TMP2\n  |  bge ->fff_resi\n  |  // Overflow to 2^31.\n  |  lus CARG3, 0x41e0\t\t\t// 2^31.\n  |  li CARG1, 0\n  |  b ->fff_restv\n  |.endif\n  |3:  // |x| < 1\n  |  slwi TMP2, CARG3, 1\n  |   srawi TMP1, CARG3, 31\n  |  or TMP2, CARG1, TMP2\t\t// ztest = (hi+hi) | lo\n  |.if \"func\" == \"floor\"\n  |  and TMP1, TMP2, TMP1\t\t// (ztest & sign) == 0 ? 0 : -1\n  |  subfic TMP2, TMP1, 0\n  |  subfe CARG1, CARG1, CARG1\n  |.else\n  |  andc TMP1, TMP2, TMP1\t\t// (ztest & ~sign) == 0 ? 0 : 1\n  |  addic TMP2, TMP1, -1\n  |  subfe CARG1, TMP2, TMP1\n  |.endif\n  |  b ->fff_resi\n  |4:  // exp >= 31. Check for -(2^31).\n  |  xoris TMP1, TMP1, 0x8000\n  |  srawi TMP2, CARG3, 31\n  |.if \"func\" == \"floor\"\n  |  or TMP1, TMP1, CARG2\n  |.endif\n  |.if PPE\n  |  orc TMP1, TMP1, TMP2\n  |  cmpwi TMP1, 0\n  |.else\n  |  orc. TMP1, TMP1, TMP2\n  |.endif\n  |  crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n  |  lus CARG1, 0x8000\t\t\t// -(2^31).\n  |  beqy ->fff_resi\n  |5:\n  |  lfd FARG1, 0(BASE)\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.if DUALNUM\n  |  math_round floor\n  |  math_round ceil\n  |.else\n  |  // NYI: use internal implementation.\n  |  math_extern floor\n  |  math_extern ceil\n  |.endif\n  |\n  |.if SQRT\n  |.ffunc_n math_sqrt\n  |  fsqrt FARG1, FARG1\n  |  b ->fff_resn\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |.ffunc math_log\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lfd FARG1, 0(BASE)\n  |  bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |  checknum CARG3; bge ->fff_fallback\n  |  blex log\n  |  b ->fff_resn\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if DUALNUM\n  |.ffunc math_ldexp\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lfd FARG1, 0(BASE)\n  |   lwz CARG4, 8(BASE)\n  |.if GPR64\n  |    lwz CARG2, 12(BASE)\n  |.else\n  |    lwz CARG1, 12(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checknum CARG3; bge ->fff_fallback\n  |  checknum CARG4; bne ->fff_fallback\n  |.else\n  |.ffunc_nn math_ldexp\n  |.if GPR64\n  |  toint CARG2, FARG2\n  |.else\n  |  toint CARG1, FARG2\n  |.endif\n  |.endif\n  |  blex ldexp\n  |  b ->fff_resn\n  |\n  |.ffunc_n math_frexp\n  |.if GPR64\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |.else\n  |  la CARG1, DISPATCH_GL(tmptv)(DISPATCH)\n  |.endif\n  |   lwz PC, FRAME_PC(BASE)\n  |  blex frexp\n  |   lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH)\n  |   la RA, -8(BASE)\n  |.if not DUALNUM\n  |   tonum_i FARG2, TMP1\n  |.endif\n  |  stfd FARG1, 0(RA)\n  |  li RD, (2+1)*8\n  |.if DUALNUM\n  |   stw TISNUM, 8(RA)\n  |   stw TMP1, 12(RA)\n  |.else\n  |   stfd FARG2, 8(RA)\n  |.endif\n  |  b ->fff_res\n  |\n  |.ffunc_n math_modf\n  |.if GPR64\n  |  la CARG2, -8(BASE)\n  |.else\n  |  la CARG1, -8(BASE)\n  |.endif\n  |   lwz PC, FRAME_PC(BASE)\n  |  blex modf\n  |   la RA, -8(BASE)\n  |  stfd FARG1, 0(BASE)\n  |  li RD, (2+1)*8\n  |  b ->fff_res\n  |\n  |.macro math_minmax, name, ismax\n  |.if DUALNUM\n  |  .ffunc_1 name\n  |  checknum CARG3\n  |   addi TMP1, BASE, 8\n  |   add TMP2, BASE, NARGS8:RC\n  |  bne >4\n  |1:  // Handle integers.\n  |  lwz CARG4, 0(TMP1)\n  |   cmplw cr1, TMP1, TMP2\n  |  lwz CARG2, 4(TMP1)\n  |   bge cr1, ->fff_resi\n  |  checknum CARG4\n  |   xoris TMP0, CARG1, 0x8000\n  |   xoris TMP3, CARG2, 0x8000\n  |  bne >3\n  |  subfc TMP3, TMP3, TMP0\n  |  subfe TMP0, TMP0, TMP0\n  |.if ismax\n  |  andc TMP3, TMP3, TMP0\n  |.else\n  |  and TMP3, TMP3, TMP0\n  |.endif\n  |  add CARG1, TMP3, CARG2\n  |.if GPR64\n  |  rldicl CARG1, CARG1, 0, 32\n  |.endif\n  |   addi TMP1, TMP1, 8\n  |  b <1\n  |3:\n  |  bge ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  tonum_i FARG1, CARG1\n  |  lfd FARG2, 0(TMP1)\n  |  b >6\n  |4:\n  |   lfd FARG1, 0(BASE)\n  |  bge ->fff_fallback\n  |5:  // Handle numbers.\n  |  lwz CARG4, 0(TMP1)\n  |   cmplw cr1, TMP1, TMP2\n  |  lfd FARG2, 0(TMP1)\n  |   bge cr1, ->fff_resn\n  |  checknum CARG4; bge >7\n  |6:\n  |  fsub f0, FARG1, FARG2\n  |   addi TMP1, TMP1, 8\n  |.if ismax\n  |  fsel FARG1, f0, FARG1, FARG2\n  |.else\n  |  fsel FARG1, f0, FARG2, FARG1\n  |.endif\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |   lwz CARG2, 4(TMP1)\n  |  bne ->fff_fallback\n  |  tonum_i FARG2, CARG2\n  |  b <6\n  |.else\n  |  .ffunc_n name\n  |  li TMP1, 8\n  |1:\n  |   lwzx CARG2, BASE, TMP1\n  |   lfdx FARG2, BASE, TMP1\n  |  cmplw cr1, TMP1, NARGS8:RC\n  |   checknum CARG2\n  |  bge cr1, ->fff_resn\n  |   bge ->fff_fallback\n  |  fsub f0, FARG1, FARG2\n  |   addi TMP1, TMP1, 8\n  |.if ismax\n  |  fsel FARG1, f0, FARG1, FARG2\n  |.else\n  |  fsel FARG1, f0, FARG2, FARG1\n  |.endif\n  |  b <1\n  |.endif\n  |.endmacro\n  |\n  |  math_minmax math_min, 0\n  |  math_minmax math_max, 1\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz STR:CARG1, 4(BASE)\n  |  bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |   checkstr CARG3\n  |   bne ->fff_fallback\n  |  lwz TMP0, STR:CARG1->len\n  |.if DUALNUM\n  |   lbz CARG1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   li RD, (0+1)*8\n  |   lwz PC, FRAME_PC(BASE)\n  |  cmplwi TMP0, 0\n  |   la RA, -8(BASE)\n  |  beqy ->fff_res\n  |  b ->fff_resi\n  |.else\n  |   lbz TMP1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |  addic TMP3, TMP0, -1\t\t// RD = ((str->len != 0)+1)*8\n  |  subfe RD, TMP3, TMP0\n  |   stw TMP1, TONUM_LO\t\t// Inlined tonum_u f0, TMP1.\n  |  addi RD, RD, 1\n  |   lfd f0, TONUM_D\n  |  la RA, -8(BASE)\n  |  lwz PC, FRAME_PC(BASE)\n  |   fsub f0, f0, TOBIT\n  |  slwi RD, RD, 3\n  |   stfd f0, 0(RA)\n  |  b ->fff_res\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |.if DUALNUM\n  |    lwz TMP0, 4(BASE)\n  |  bne ->fff_fallback\t\t\t// Exactly 1 argument.\n  |  checknum CARG3; bne ->fff_fallback\n  |   la CARG2, 7(BASE)\n  |.else\n  |    lfd FARG1, 0(BASE)\n  |  bne ->fff_fallback\t\t\t// Exactly 1 argument.\n  |  checknum CARG3; bge ->fff_fallback\n  |  toint TMP0, FARG1\n  |   la CARG2, TMPD_BLO\n  |.endif\n  |   li CARG3, 1\n  |  cmplwi TMP0, 255; bgt ->fff_fallback\n  |->fff_newstr:\n  |  mr CARG1, L\n  |  stp BASE, L->base\n  |  stw PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  lp BASE, L->base\n  |  li CARG3, LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 16(BASE)\n  |.if not DUALNUM\n  |    lfd f0, 16(BASE)\n  |.endif\n  |   lwz TMP0, 0(BASE)\n  |    lwz STR:CARG1, 4(BASE)\n  |  blt ->fff_fallback\n  |   lwz CARG2, 8(BASE)\n  |.if DUALNUM\n  |    lwz TMP1, 12(BASE)\n  |.else\n  |    lfd f1, 8(BASE)\n  |.endif\n  |   li TMP2, -1\n  |  beq >1\n  |.if DUALNUM\n  |  checknum CARG3\n  |   lwz TMP2, 20(BASE)\n  |  bne ->fff_fallback\n  |1:\n  |  checknum CARG2; bne ->fff_fallback\n  |.else\n  |  checknum CARG3; bge ->fff_fallback\n  |  toint TMP2, f0\n  |1:\n  |  checknum CARG2; bge ->fff_fallback\n  |.endif\n  |  checkstr TMP0; bne ->fff_fallback\n  |.if not DUALNUM\n  |   toint TMP1, f1\n  |.endif\n  |   lwz TMP0, STR:CARG1->len\n  |  cmplw TMP0, TMP2\t\t\t// len < end? (unsigned compare)\n  |   addi TMP3, TMP2, 1\n  |  blt >5\n  |2:\n  |  cmpwi TMP1, 0\t\t\t// start <= 0?\n  |   add TMP3, TMP1, TMP0\n  |  ble >7\n  |3:\n  |  sub CARG3, TMP2, TMP1\n  |    addi CARG2, STR:CARG1, #STR-1\n  |  srawi TMP0, CARG3, 31\n  |   addi CARG3, CARG3, 1\n  |    add CARG2, CARG2, TMP1\n  |  andc CARG3, CARG3, TMP0\n  |.if GPR64\n  |  rldicl CARG2, CARG2, 0, 32\n  |  rldicl CARG3, CARG3, 0, 32\n  |.endif\n  |  b ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  cmpw TMP0, TMP2\t\t\t// len >= end? (signed compare)\n  |   add TMP2, TMP0, TMP3\t\t// Negative end: end = end+len+1.\n  |  bge <2\n  |   mr TMP2, TMP0\t\t\t// Overflow: end = len.\n  |  b <2\n  |\n  |7:  // Negative start or underflow.\n  |  .gpr64 extsw TMP1, TMP1\n  |  addic CARG3, TMP1, -1\n  |  subfe CARG3, CARG3, CARG3\n  |   srawi CARG2, TMP3, 31\t\t// Note: modifies carry.\n  |  andc TMP3, TMP3, CARG3\n  |   andc TMP1, TMP3, CARG2\n  |  addi TMP1, TMP1, 1\t\t\t// start = 1 + (start ? start+len : 0)\n  |  b <3\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz STR:CARG2, 4(BASE)\n  |  blt ->fff_fallback\n  |  checkstr CARG3\n  |   la SBUF:CARG1, DISPATCH_GL(tmpbuf)(DISPATCH)\n  |  bne ->fff_fallback\n  |   lwz TMP0, SBUF:CARG1->b\n  |  stw L, SBUF:CARG1->L\n  |  stp BASE, L->base\n  |  stw PC, SAVE_PC\n  |   stw TMP0, SBUF:CARG1->p\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name\n  |.if DUALNUM\n  |  .ffunc_1 bit_..name\n  |  checknum CARG3; bnel ->fff_tobit_fb\n  |.else\n  |  .ffunc_n bit_..name\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |.endif\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  addi TMP1, BASE, 8\n  |  add TMP2, BASE, NARGS8:RC\n  |1:\n  |  lwz CARG4, 0(TMP1)\n  |   cmplw cr1, TMP1, TMP2\n  |.if DUALNUM\n  |  lwz CARG2, 4(TMP1)\n  |.else\n  |  lfd FARG1, 0(TMP1)\n  |.endif\n  |   bgey cr1, ->fff_resi\n  |  checknum CARG4\n  |.if DUALNUM\n  |  bnel ->fff_bitop_fb\n  |.else\n  |  fadd FARG1, FARG1, TOBIT\n  |  bge ->fff_fallback\n  |  stfd FARG1, TMPD\n  |  lwz CARG2, TMPD_LO\n  |.endif\n  |  ins CARG1, CARG1, CARG2\n  |   addi TMP1, TMP1, 8\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, or\n  |.ffunc_bit_op bxor, xor\n  |\n  |.ffunc_bit bswap\n  |  rotlwi TMP0, CARG1, 8\n  |  rlwimi TMP0, CARG1, 24, 0, 7\n  |  rlwimi TMP0, CARG1, 24, 16, 23\n  |  mr CRET1, TMP0\n  |  b ->fff_resi\n  |\n  |.ffunc_bit bnot\n  |  not CRET1, CARG1\n  |  b ->fff_resi\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |.if DUALNUM\n  |  .ffunc_2 bit_..name\n  |  checknum CARG3; bnel ->fff_tobit_fb\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  checknum CARG4; bne ->fff_fallback\n  |.else\n  |  .ffunc_nn bit_..name\n  |  fadd FARG1, FARG1, TOBIT\n  |  fadd FARG2, FARG2, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |  stfd FARG2, TMPD\n  |  lwz CARG2, TMPD_LO\n  |.endif\n  |.if shmod == 1\n  |  rlwinm CARG2, CARG2, 0, 27, 31\n  |.elif shmod == 2\n  |  neg CARG2, CARG2\n  |.endif\n  |  ins CRET1, CARG1, CARG2\n  |  b ->fff_resi\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, slw, 1\n  |.ffunc_bit_sh rshift, srw, 1\n  |.ffunc_bit_sh arshift, sraw, 1\n  |.ffunc_bit_sh rol, rotlw, 0\n  |.ffunc_bit_sh ror, rotlw, 2\n  |\n  |.ffunc_bit tobit\n  |.if DUALNUM\n  |  b ->fff_resi\n  |.else\n  |->fff_resi:\n  |  tonum_i FARG1, CRET1\n  |.endif\n  |->fff_resn:\n  |  lwz PC, FRAME_PC(BASE)\n  |  la RA, -8(BASE)\n  |  stfd FARG1, -8(BASE)\n  |  b ->fff_res1\n  |\n  |// Fallback FP number to bit conversion.\n  |->fff_tobit_fb:\n  |.if DUALNUM\n  |  lfd FARG1, 0(BASE)\n  |  bgt ->fff_fallback\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |  blr\n  |.endif\n  |->fff_bitop_fb:\n  |.if DUALNUM\n  |  lfd FARG1, 0(TMP1)\n  |  bgt ->fff_fallback\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG2, TMPD_LO\n  |  blr\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RB = CFUNC, RC = nargs*8\n  |  lp TMP3, CFUNC:RB->f\n  |    add TMP1, BASE, NARGS8:RC\n  |   lwz PC, FRAME_PC(BASE)\t\t// Fallback may overwrite PC.\n  |    addi TMP0, TMP1, 8*LUA_MINSTACK\n  |     lwz TMP2, L->maxstack\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  .toc lp TMP3, 0(TMP3)\n  |  cmplw TMP0, TMP2\n  |     stp BASE, L->base\n  |    stp TMP1, L->top\n  |   mr CARG1, L\n  |  bgt >5\t\t\t\t// Need to grow stack.\n  |  mtctr TMP3\n  |  bctrl\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  lp BASE, L->base\n  |  cmpwi CRET1, 0\n  |   slwi RD, CRET1, 3\n  |   la RA, -8(BASE)\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |  lp TMP0, L->top\n  |   lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  sub NARGS8:RC, TMP0, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   rlwinm TMP1, PC, 0, 0, 28\n  |  bne >3\n  |  lwz INS, -4(PC)\n  |  decode_RA8 TMP1, INS\n  |  addi TMP1, TMP1, 8\n  |3:\n  |  sub TMP2, BASE, TMP1\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  li CARG2, LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lp BASE, L->base\n  |  cmpw TMP0, TMP0\t\t\t// Set 4*cr0+eq to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  mflr SAVE0\n  |   stp BASE, L->base\n  |  add TMP0, BASE, NARGS8:RC\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  stp TMP0, L->top\n  |  mr CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |   lp BASE, L->base\n  |  mtlr SAVE0\n  |    lp TMP0, L->top\n  |   sub NARGS8:RC, TMP0, BASE\n  |   lwz CFUNC:RB, FRAME_FUNC(BASE)\n  |  blr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_VMEVENT\t// No recording while in vmevent.\n  |  bne >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |   lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\n  |  bne >1\n  |   subi TMP2, TMP2, 1\n  |  andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqy >1\n  |   stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  b >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\t// Hook already active?\n  |  beq >1\n  |5:  // Re-dispatch to static ins.\n  |  addi TMP1, TMP1, GG_DISP2STATIC\t// Assumes decode_OPP TMP1, INS.\n  |  lpx TMP0, DISPATCH, TMP1\n  |  mtctr TMP0\n  |  bctr\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\t// Hook already active?\n  |   rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0\n  |  bne <5\n  |\n  |   cmpwi cr1, TMP0, 0\n  |  addic. TMP2, TMP2, -1\n  |   beq cr1, <5\n  |  stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  beq >1\n  |   bge cr1, <5\n  |1:\n  |  mr CARG1, L\n  |   stw MULTRES, SAVE_MULTRES\n  |  mr CARG2, PC\n  |   stp BASE, L->base\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  lp BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  lwz INS, -4(PC)\n  |  decode_OPP TMP1, INS\n  |   decode_RB8 RB, INS\n  |  addi TMP1, TMP1, GG_DISP2STATIC\n  |   decode_RD8 RD, INS\n  |  lpx TMP0, DISPATCH, TMP1\n  |   decode_RA8 RA, INS\n  |   decode_RC8 RC, INS\n  |  mtctr TMP0\n  |  bctr\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  addi PC, PC, 4\n  |  lwz MULTRES, -20(RB)\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n  |   addi CARG1, DISPATCH, GG_DISP2J\n  |   stw PC, SAVE_PC\n  |  lwz TMP1, LFUNC:TMP1->pc\n  |   mr CARG2, PC\n  |   stw L, DISPATCH_J(L)(DISPATCH)\n  |  lbz TMP1, PC2PROTO(framesize)(TMP1)\n  |   stp BASE, L->base\n  |  slwi TMP1, TMP1, 3\n  |  add TMP1, BASE, TMP1\n  |  stp TMP1, L->top\n  |  bl extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  b <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mr CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  ori CARG2, PC, 1\n  |1:\n  |.endif\n  |  add TMP0, BASE, RC\n  |   stw PC, SAVE_PC\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  sub RA, RA, BASE\n  |   stp TMP0, L->top\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  lp BASE, L->base\n  |   lp TMP0, L->top\n  |   stw ZERO, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  sub NARGS8:RC, TMP0, BASE\n  |  add RA, BASE, RA\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  lwz INS, -4(PC)\n  |  mtctr CRET1\n  |  bctr\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, RB = meta base\n  |  lwz INS, -4(PC)\n  |    lwz TRACE:TMP2, -20(RB)\t\t// Save previous trace.\n  |   addic. TMP1, MULTRES, -8\n  |  decode_RA8 RC, INS\t\t\t// Call base.\n  |   beq >2\n  |1:  // Move results down.\n  |  lfd f0, 0(RA)\n  |   addic. TMP1, TMP1, -8\n  |    addi RA, RA, 8\n  |  stfdx f0, BASE, RC\n  |    addi RC, RC, 8\n  |   bne <1\n  |2:\n  |   decode_RA8 RA, INS\n  |   decode_RB8 RB, INS\n  |   add RA, RA, RB\n  |3:\n  |   cmplw RA, RC\n  |   bgt >9\t\t\t\t// More results wanted?\n  |\n  |  lhz TMP3, TRACE:TMP2->traceno\n  |  lhz RD, TRACE:TMP2->link\n  |  cmpw RD, TMP3\n  |   cmpwi cr1, RD, 0\n  |  beq ->cont_nop\t\t\t// Blacklisted.\n  |    slwi RD, RD, 3\n  |   bne cr1, =>BC_JLOOP\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  stw TMP3, DISPATCH_J(exitno)(DISPATCH)\n  |  stp L, DISPATCH_J(L)(DISPATCH)\n  |  stp BASE, L->base\n  |  addi CARG1, DISPATCH, GG_DISP2J\n  |  mr CARG2, PC\n  |  bl extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  lp BASE, L->base\n  |  b ->cont_nop\n  |\n  |9:\n  |  stwx TISNIL, BASE, RC\n  |  addi RC, RC, 8\n  |  b <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mr CARG1, L\n  |   stw MULTRES, SAVE_MULTRES\n  |  mr CARG2, PC\n  |   stp BASE, L->base\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  lp BASE, L->base\n  |  subi PC, PC, 4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b, c, d\n  |  stfd f..a, 16+a*8(sp)\n  |  stfd f..b, 16+b*8(sp)\n  |  stfd f..c, 16+c*8(sp)\n  |  stfd f..d, 16+d*8(sp)\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |  addi sp, sp, -(16+32*8+32*4)\n  |  stmw r2, 16+32*8+2*4(sp)\n  |    addi DISPATCH, JGL, -GG_DISP2G-32768\n  |    li CARG2, ~LJ_VMST_EXIT\n  |   lwz CARG1, 16+32*8+32*4(sp)\t// Get stack chain.\n  |    stw CARG2, DISPATCH_GL(vmstate)(DISPATCH)\n  |  savex_ 0,1,2,3\n  |   stw CARG1, 0(sp)\t\t\t// Store extended stack chain.\n  |   clrso TMP1\n  |  savex_ 4,5,6,7\n  |   addi CARG2, sp, 16+32*8+32*4\t// Recompute original value of sp.\n  |  savex_ 8,9,10,11\n  |   stw CARG2, 16+32*8+1*4(sp)\t// Store sp in RID_SP.\n  |  savex_ 12,13,14,15\n  |   mflr CARG3\n  |   li TMP1, 0\n  |  savex_ 16,17,18,19\n  |   stw TMP1, 16+32*8+0*4(sp)\t\t// Clear RID_TMP.\n  |  savex_ 20,21,22,23\n  |   lhz CARG4, 2(CARG3)\t\t// Load trace number.\n  |  savex_ 24,25,26,27\n  |  lwz L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  savex_ 28,29,30,31\n  |   sub CARG3, TMP0, CARG3\t\t// Compute exit number.\n  |  lp BASE, DISPATCH_GL(jit_base)(DISPATCH)\n  |   srwi CARG3, CARG3, 2\n  |  stp L, DISPATCH_J(L)(DISPATCH)\n  |   subi CARG3, CARG3, 2\n  |  stp BASE, L->base\n  |   stw CARG4, DISPATCH_J(parent)(DISPATCH)\n  |  stw TMP1, DISPATCH_GL(jit_base)(DISPATCH)\n  |  addi CARG1, DISPATCH, GG_DISP2J\n  |   stw CARG3, DISPATCH_J(exitno)(DISPATCH)\n  |  addi CARG2, sp, 16\n  |  bl extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  lp TMP1, L->cframe\n  |  lwz TMP2, 0(sp)\n  |   lp BASE, L->base\n  |.if GPR64\n  |  rldicr sp, TMP1, 0, 61\n  |.else\n  |  rlwinm sp, TMP1, 0, 0, 29\n  |.endif\n  |   lwz PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  stw TMP2, 0(sp)\n  |  stw L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |  b >1\n  |.endif\n  |->vm_exit_interp:\n  |.if JIT\n  |  // CARG1 = MULTRES or negated error code, BASE, PC and JGL set.\n  |  lwz L, SAVE_L\n  |  addi DISPATCH, JGL, -GG_DISP2G-32768\n  |  stp BASE, L->base\n  |1:\n  |  cmpwi CARG1, 0\n  |  blt >9\t\t\t\t// Check for error from exit.\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |   slwi MULTRES, CARG1, 3\n  |    li TMP2, 0\n  |   stw MULTRES, SAVE_MULTRES\n  |  lwz TMP1, LFUNC:RB->pc\n  |    stw TMP2, DISPATCH_GL(jit_base)(DISPATCH)\n  |  lwz KBASE, PC2PROTO(k)(TMP1)\n  |  // Setup type comparison constants.\n  |  li TISNUM, LJ_TISNUM\n  |  lus TMP3, 0x59c0\t\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  stw TMP3, TMPD\n  |  li ZERO, 0\n  |  ori TMP3, TMP3, 0x0004\t\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |  lfs TOBIT, TMPD\n  |  stw TMP3, TMPD\n  |  lus TMP0, 0x4338\t\t\t// Hiword of 2^52 + 2^51 (double)\n  |    li TISNIL, LJ_TNIL\n  |  stw TMP0, TONUM_HI\n  |  lfs TONUM, TMPD\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  lwz INS, 0(PC)\n  |   addi PC, PC, 4\n  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1.\n  |    stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)\n  |  decode_OPP TMP1, INS\n  |   decode_RA8 RA, INS\n  |  lpx TMP0, DISPATCH, TMP1\n  |  mtctr TMP0\n  |  cmplwi TMP1, BC_FUNCF*4\t\t// Function header?\n  |  bge >2\n  |   decode_RB8 RB, INS\n  |   decode_RD8 RD, INS\n  |   decode_RC8 RC, INS\n  |  bctr\n  |2:\n  |  cmplwi TMP1, (BC_FUNCC+2)*4\t// Fast function?\n  |  blt >3\n  |  // Check frame below fast function.\n  |  lwz TMP1, FRAME_PC(BASE)\n  |  andix. TMP0, TMP1, FRAME_TYPE\n  |  bney >3\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  lwz TMP2, -4(TMP1)\n  |  decode_RA8 TMP0, TMP2\n  |  sub TMP1, BASE, TMP0\n  |  lwz LFUNC:TMP2, -12(TMP1)\n  |  lwz TMP1, LFUNC:TMP2->pc\n  |  lwz KBASE, PC2PROTO(k)(TMP1)\n  |3:\n  |   subi RC, MULTRES, 8\n  |   add RA, RA, BASE\n  |  bctr\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  neg CARG2, CARG1\n  |  mr CARG1, L\n  |  bl extern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// NYI: Use internal implementations of floor, ceil, trunc.\n  |\n  |->vm_modi:\n  |  divwo. TMP0, CARG1, CARG2\n  |  bso >1\n  |.if GPR64\n  |   xor CARG3, CARG1, CARG2\n  |   cmpwi CARG3, 0\n  |.else\n  |   xor. CARG3, CARG1, CARG2\n  |.endif\n  |  mullw TMP0, TMP0, CARG2\n  |  sub CARG1, CARG1, TMP0\n  |   bgelr\n  |  cmpwi CARG1, 0; beqlr\n  |  add CARG1, CARG1, CARG2\n  |  blr\n  |1:\n  |  cmpwi CARG2, 0\n  |   li CARG1, 0\n  |  beqlr\n  |  clrso TMP0\t\t\t// Clear SO for -2147483648 % -1 and return 0.\n  |  blr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// void lj_vm_cachesync(void *start, void *end)\n  |// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size.\n  |// This is a good lower bound, except for very ancient PPC models.\n  |->vm_cachesync:\n  |.if JIT or FFI\n  |  // Compute start of first cache line and number of cache lines.\n  |  rlwinm CARG1, CARG1, 0, 0, 26\n  |  sub CARG2, CARG2, CARG1\n  |  addi CARG2, CARG2, 31\n  |  rlwinm. CARG2, CARG2, 27, 5, 31\n  |  beqlr\n  |  mtctr CARG2\n  |  mr CARG3, CARG1\n  |1:  // Flush D-Cache.\n  |  dcbst r0, CARG1\n  |  addi CARG1, CARG1, 32\n  |  bdnz <1\n  |  sync\n  |  mtctr CARG2\n  |1:  // Invalidate I-Cache.\n  |  icbi r0, CARG3\n  |  addi CARG3, CARG3, 32\n  |  bdnz <1\n  |  isync\n  |  blr\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in r11, g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  lwz CTSTATE, GL:r12->ctype_state\n  |   addi DISPATCH, r12, GG_G2DISP\n  |  stw r11, CTSTATE->cb.slot\n  |  stw r3, CTSTATE->cb.gpr[0]\n  |   stfd f1, CTSTATE->cb.fpr[0]\n  |  stw r4, CTSTATE->cb.gpr[1]\n  |   stfd f2, CTSTATE->cb.fpr[1]\n  |  stw r5, CTSTATE->cb.gpr[2]\n  |   stfd f3, CTSTATE->cb.fpr[2]\n  |  stw r6, CTSTATE->cb.gpr[3]\n  |   stfd f4, CTSTATE->cb.fpr[3]\n  |  stw r7, CTSTATE->cb.gpr[4]\n  |   stfd f5, CTSTATE->cb.fpr[4]\n  |  stw r8, CTSTATE->cb.gpr[5]\n  |   stfd f6, CTSTATE->cb.fpr[5]\n  |  stw r9, CTSTATE->cb.gpr[6]\n  |   stfd f7, CTSTATE->cb.fpr[6]\n  |  stw r10, CTSTATE->cb.gpr[7]\n  |   stfd f8, CTSTATE->cb.fpr[7]\n  |  addi TMP0, sp, CFRAME_SPACE+8\n  |  stw TMP0, CTSTATE->cb.stack\n  |   mr CARG1, CTSTATE\n  |  stw CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |   mr CARG2, sp\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  lp BASE, L:CRET1->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  lp RC, L:CRET1->top\n  |     lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |     li ZERO, 0\n  |   mr L, CRET1\n  |     stw TMP3, TMPD\n  |     lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |     ori TMP3, TMP3, 0x0004\t\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     stw TMP0, TONUM_HI\n  |     li TISNIL, LJ_TNIL\n  |    li_vmstate INTERP\n  |     lfs TOBIT, TMPD\n  |     stw TMP3, TMPD\n  |  sub RC, RC, BASE\n  |    st_vmstate\n  |     lfs TONUM, TMPD\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)\n  |   stp BASE, L->base\n  |   stp RB, L->top\n  |  stp L, CTSTATE->L\n  |  mr CARG1, CTSTATE\n  |  mr CARG2, RA\n  |  bl extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  lwz CRET1, CTSTATE->cb.gpr[0]\n  |  lfd FARG1, CTSTATE->cb.fpr[0]\n  |  lwz CRET2, CTSTATE->cb.gpr[1]\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, CARG1\n  |  lwz TMP1, CCSTATE->spadj\n  |    mflr TMP0\n  |   lbz CARG2, CCSTATE->nsp\n  |   lbz CARG3, CCSTATE->nfpr\n  |  neg TMP1, TMP1\n  |    stw TMP0, 4(sp)\n  |   cmpwi cr1, CARG3, 0\n  |  mr TMP2, sp\n  |   addic. CARG2, CARG2, -1\n  |  stwux sp, sp, TMP1\n  |   crnot 4*cr1+eq, 4*cr1+eq\t\t// For vararg calls.\n  |  stw r14, -4(TMP2)\n  |  stw CCSTATE, -8(TMP2)\n  |  mr r14, TMP2\n  |  la TMP1, CCSTATE->stack\n  |   slwi CARG2, CARG2, 2\n  |   blty >2\n  |  la TMP2, 8(sp)\n  |1:\n  |  lwzx TMP0, TMP1, CARG2\n  |  stwx TMP0, TMP2, CARG2\n  |   addic. CARG2, CARG2, -4\n  |  bge <1\n  |2:\n  |  bney cr1, >3\n  |  lfd f1, CCSTATE->fpr[0]\n  |  lfd f2, CCSTATE->fpr[1]\n  |  lfd f3, CCSTATE->fpr[2]\n  |  lfd f4, CCSTATE->fpr[3]\n  |  lfd f5, CCSTATE->fpr[4]\n  |  lfd f6, CCSTATE->fpr[5]\n  |  lfd f7, CCSTATE->fpr[6]\n  |  lfd f8, CCSTATE->fpr[7]\n  |3:\n  |   lp TMP0, CCSTATE->func\n  |  lwz CARG2, CCSTATE->gpr[1]\n  |  lwz CARG3, CCSTATE->gpr[2]\n  |  lwz CARG4, CCSTATE->gpr[3]\n  |  lwz CARG5, CCSTATE->gpr[4]\n  |   mtctr TMP0\n  |  lwz r8, CCSTATE->gpr[5]\n  |  lwz r9, CCSTATE->gpr[6]\n  |  lwz r10, CCSTATE->gpr[7]\n  |  lwz CARG1, CCSTATE->gpr[0]\t\t// Do this last, since CCSTATE is CARG1.\n  |   bctrl\n  |  lwz CCSTATE:TMP1, -8(r14)\n  |  lwz TMP2, -4(r14)\n  |   lwz TMP0, 4(r14)\n  |  stw CARG1, CCSTATE:TMP1->gpr[0]\n  |  stfd FARG1, CCSTATE:TMP1->fpr[0]\n  |  stw CARG2, CCSTATE:TMP1->gpr[1]\n  |   mtlr TMP0\n  |  stw CARG3, CCSTATE:TMP1->gpr[2]\n  |   mr sp, r14\n  |  stw CARG4, CCSTATE:TMP1->gpr[3]\n  |   mr r14, TMP2\n  |  blr\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux TMP0, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux TMP1, RD, BASE\n    |    lwz TMP2, -4(PC)\n    |  checknum cr0, TMP0\n    |   lwz CARG3, 4(RD)\n    |    decode_RD4 TMP2, TMP2\n    |  checknum cr1, TMP1\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bne cr0, >7\n    |  bne cr1, >8\n    |   cmpw CARG2, CARG3\n    if (op == BC_ISLT) {\n      |  bge >2\n    } else if (op == BC_ISGE) {\n      |  blt >2\n    } else if (op == BC_ISLE) {\n      |  bgt >2\n    } else {\n      |  ble >2\n    }\n    |1:\n    |  add PC, PC, TMP2\n    |2:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  bgt cr0, ->vmeta_comp\n    |  // RA is a number.\n    |   lfd f0, 0(RA)\n    |  bgt cr1, ->vmeta_comp\n    |  blt cr1, >4\n    |  // RA is a number, RD is an integer.\n    |  tonum_i f1, CARG3\n    |  b >5\n    |\n    |8: // RA is an integer, RD is not an integer.\n    |  bgt cr1, ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  tonum_i f0, CARG2\n    |4:\n    |  lfd f1, 0(RD)\n    |5:\n    |  fcmpu cr0, f0, f1\n    if (op == BC_ISLT) {\n      |  bge <2\n    } else if (op == BC_ISGE) {\n      |  blt <2\n    } else if (op == BC_ISLE) {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  bge <2\n    } else {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  blt <2\n    }\n    |  b <1\n    |.else\n    |  lwzx TMP0, BASE, RA\n    |    addi PC, PC, 4\n    |   lfdx f0, BASE, RA\n    |  lwzx TMP1, BASE, RD\n    |  checknum cr0, TMP0\n    |    lwz TMP2, -4(PC)\n    |   lfdx f1, BASE, RD\n    |  checknum cr1, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |  bge cr0, ->vmeta_comp\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bge cr1, ->vmeta_comp\n    |  fcmpu cr0, f0, f1\n    if (op == BC_ISLT) {\n      |  bge >1\n    } else if (op == BC_ISGE) {\n      |  blt >1\n    } else if (op == BC_ISLE) {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  bge >1\n    } else {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  blt >1\n    }\n    |  add PC, PC, TMP2\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux TMP0, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux TMP1, RD, BASE\n    |  checknum cr0, TMP0\n    |    lwz TMP2, -4(PC)\n    |  checknum cr1, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |   lwz CARG3, 4(RD)\n    |  cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    if (vk) {\n      |  ble cr7, ->BC_ISEQN_Z\n    } else {\n      |  ble cr7, ->BC_ISNEN_Z\n    }\n    |.else\n    |  lwzux TMP0, RA, BASE\n    |   lwz TMP2, 0(PC)\n    |    lfd f0, 0(RA)\n    |   addi PC, PC, 4\n    |  lwzux TMP1, RD, BASE\n    |  checknum cr0, TMP0\n    |   decode_RD4 TMP2, TMP2\n    |    lfd f1, 0(RD)\n    |  checknum cr1, TMP1\n    |   addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bge cr0, >5\n    |  bge cr1, >5\n    |  fcmpu cr0, f0, f1\n    if (vk) {\n      |  bne >1\n      |  add PC, PC, TMP2\n    } else {\n      |  beq >1\n      |  add PC, PC, TMP2\n    }\n    |1:\n    |  ins_next\n    |.endif\n    |5:  // Either or both types are not numbers.\n    |.if not DUALNUM\n    |    lwz CARG2, 4(RA)\n    |    lwz CARG3, 4(RD)\n    |.endif\n    |.if FFI\n    |  cmpwi cr7, TMP0, LJ_TCDATA\n    |  cmpwi cr5, TMP1, LJ_TCDATA\n    |.endif\n    |   not TMP3, TMP0\n    |  cmplw TMP0, TMP1\n    |   cmplwi cr1, TMP3, ~LJ_TISPRI\t\t// Primitive?\n    |.if FFI\n    |  cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq\n    |.endif\n    |   cmplwi cr6, TMP3, ~LJ_TISTABUD\t\t// Table or userdata?\n    |.if FFI\n    |  beq cr7, ->vmeta_equal_cd\n    |.endif\n    |    cmplw cr5, CARG2, CARG3\n    |  crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt\t// 2: Same type and primitive.\n    |  crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq\t// 1: Same tv or different type.\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq\t// 0: Same type and same tv.\n    |   mr SAVE0, PC\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt\t// 0 or 2.\n    |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt\t// 1 or 2.\n    if (vk) {\n      |  bne cr0, >6\n      |  add PC, PC, TMP2\n      |6:\n    } else {\n      |  beq cr0, >6\n      |  add PC, PC, TMP2\n      |6:\n    }\n    |.if DUALNUM\n    |  bge cr0, >2\t\t\t// Done if 1 or 2.\n    |1:\n    |  ins_next\n    |2:\n    |.else\n    |  blt cr0, <1\t\t\t// Done if 1 or 2.\n    |.endif\n    |  blt cr6, <1\t\t\t// Done if not tab/ud.\n    |\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  lwz TAB:TMP2, TAB:CARG2->metatable\n    |   li CARG4, 1-vk\t\t\t// ne = 0 or 1.\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable?\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_eq\n    |  bne <1\t\t\t\t// Or 'no __eq' flag set?\n    |  mr PC, SAVE0\t\t\t// Restore old PC.\n    |  b ->vmeta_equal\t\t\t// Handle __eq metamethod.\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target\n    |  lwzux TMP0, RA, BASE\n    |   srwi RD, RD, 1\n    |  lwz STR:TMP3, 4(RA)\n    |    lwz TMP2, 0(PC)\n    |   subfic RD, RD, -4\n    |    addi PC, PC, 4\n    |.if FFI\n    |  cmpwi TMP0, LJ_TCDATA\n    |.endif\n    |   lwzx STR:TMP1, KBASE, RD\t// KBASE-4-str_const*4\n    |  .gpr64 extsw TMP0, TMP0\n    |  subfic TMP0, TMP0, LJ_TSTR\n    |.if FFI\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  sub TMP1, STR:TMP1, STR:TMP3\n    |  or TMP0, TMP0, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |  subfic TMP0, TMP0, 0\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  subfe TMP1, TMP1, TMP1\n    if (vk) {\n      |  andc TMP2, TMP2, TMP1\n    } else {\n      |  and TMP2, TMP2, TMP1\n    }\n    |  add PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RD = num_const*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux TMP0, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux TMP1, RD, KBASE\n    |  checknum cr0, TMP0\n    |    lwz TMP2, -4(PC)\n    |  checknum cr1, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |   lwz CARG3, 4(RD)\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  bne cr0, >7\n    |  bne cr1, >8\n    |   cmpw CARG2, CARG3\n    |4:\n    |.else\n    if (vk) {\n      |->BC_ISEQN_Z:  // Dummy label.\n    } else {\n      |->BC_ISNEN_Z:  // Dummy label.\n    }\n    |  lwzx TMP0, BASE, RA\n    |    addi PC, PC, 4\n    |   lfdx f0, BASE, RA\n    |    lwz TMP2, -4(PC)\n    |  lfdx f1, KBASE, RD\n    |    decode_RD4 TMP2, TMP2\n    |  checknum TMP0\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bge >3\n    |  fcmpu cr0, f0, f1\n    |.endif\n    if (vk) {\n      |  bne >1\n      |  add PC, PC, TMP2\n      |1:\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |  beq >2\n      |1:\n      |.if not FFI\n      |3:\n      |.endif\n      |  add PC, PC, TMP2\n      |2:\n    }\n    |  ins_next\n    |.if FFI\n    |3:\n    |  cmpwi TMP0, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |  b <1\n    |.endif\n    |.if DUALNUM\n    |7:  // RA is not an integer.\n    |  bge cr0, <3\n    |  // RA is a number.\n    |   lfd f0, 0(RA)\n    |  blt cr1, >1\n    |  // RA is a number, RD is an integer.\n    |  tonum_i f1, CARG3\n    |  b >2\n    |\n    |8: // RA is an integer, RD is a number.\n    |  tonum_i f0, CARG2\n    |1:\n    |  lfd f1, 0(RD)\n    |2:\n    |  fcmpu cr0, f0, f1\n    |  b <4\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target\n    |  lwzx TMP0, BASE, RA\n    |   srwi TMP1, RD, 3\n    |    lwz TMP2, 0(PC)\n    |   not TMP1, TMP1\n    |    addi PC, PC, 4\n    |.if FFI\n    |  cmpwi TMP0, LJ_TCDATA\n    |.endif\n    |  sub TMP0, TMP0, TMP1\n    |.if FFI\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |    decode_RD4 TMP2, TMP2\n    |  .gpr64 extsw TMP0, TMP0\n    |  addic TMP0, TMP0, -1\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  subfe TMP1, TMP1, TMP1\n    if (vk) {\n      |  and TMP2, TMP2, TMP1\n    } else {\n      |  andc TMP2, TMP2, TMP1\n    }\n    |  add PC, PC, TMP2\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target\n    |  lwzx TMP0, BASE, RD\n    |   lwz INS, 0(PC)\n    |   addi PC, PC, 4\n    if (op == BC_IST || op == BC_ISF) {\n      |  .gpr64 extsw TMP0, TMP0\n      |  subfic TMP0, TMP0, LJ_TTRUE\n      |   decode_RD4 TMP2, INS\n      |  subfe TMP1, TMP1, TMP1\n      |   addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n      if (op == BC_IST) {\n\t|  andc TMP2, TMP2, TMP1\n      } else {\n\t|  and TMP2, TMP2, TMP1\n      }\n      |  add PC, PC, TMP2\n    } else {\n      |  li TMP1, LJ_TFALSE\n      |   lfdx f0, BASE, RD\n      |  cmplw TMP0, TMP1\n      if (op == BC_ISTC) {\n\t|  bge >1\n      } else {\n\t|  blt >1\n      }\n      |  addis PC, PC, -(BCBIAS_J*4 >> 16)\n      |  decode_RD4 TMP2, INS\n      |   stfdx f0, BASE, RA\n      |  add PC, PC, TMP2\n      |1:\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RD = -type*8\n    |  lwzx TMP0, BASE, RA\n    |  srwi TMP1, RD, 3\n    |  ins_next1\n    |.if not PPE and not GPR64\n    |  add. TMP0, TMP0, TMP1\n    |.else\n    |  neg TMP1, TMP1\n    |  cmpw TMP0, TMP1\n    |.endif\n    |  bne ->vmeta_istype\n    |  ins_next2\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RD = -(TISNUM-1)*8\n    |  lwzx TMP0, BASE, RA\n    |  ins_next1\n    |  checknum TMP0\n    |  bge ->vmeta_istype\n    |  ins_next2\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RD = src*8\n    |  ins_next1\n    |  lfdx f0, BASE, RD\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RD = src*8\n    |  ins_next1\n    |  lwzx TMP0, BASE, RD\n    |  .gpr64 extsw TMP0, TMP0\n    |  subfic TMP1, TMP0, LJ_TTRUE\n    |  adde TMP0, TMP0, TMP1\n    |  stwx TMP0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RD = src*8\n    |  lwzux TMP1, RD, BASE\n    |   lwz TMP0, 4(RD)\n    |  checknum TMP1\n    |.if DUALNUM\n    |  bne >5\n    |.if GPR64\n    |  lus TMP2, 0x8000\n    |  neg TMP0, TMP0\n    |  cmplw TMP0, TMP2\n    |  beq >4\n    |.else\n    |  nego. TMP0, TMP0\n    |  bso >4\n    |1:\n    |.endif\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |   stw TMP0, 4(RA)\n    |3:\n    |  ins_next2\n    |4:\n    |.if not GPR64\n    |  // Potential overflow.\n    |  checkov TMP1, <1\t\t\t// Ignore unrelated overflow.\n    |.endif\n    |  lus TMP1, 0x41e0\t\t\t// 2^31.\n    |  li TMP0, 0\n    |  b >7\n    |.endif\n    |5:\n    |  bge ->vmeta_unm\n    |  xoris TMP1, TMP1, 0x8000\n    |7:\n    |  ins_next1\n    |  stwux TMP1, RA, BASE\n    |   stw TMP0, 4(RA)\n    |.if DUALNUM\n    |  b <3\n    |.else\n    |  ins_next2\n    |.endif\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RD = src*8\n    |  lwzux TMP0, RD, BASE\n    |   lwz CARG1, 4(RD)\n    |  checkstr TMP0; bne >2\n    |  lwz CRET1, STR:CARG1->len\n    |1:\n    |.if DUALNUM\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |   stw CRET1, 4(RA)\n    |.else\n    |  tonum_u f0, CRET1\t\t// Result is a non-negative integer.\n    |  ins_next1\n    |  stfdx f0, BASE, RA\n    |.endif\n    |  ins_next2\n    |2:\n    |  checktab TMP0; bne ->vmeta_len\n#if LJ_52\n    |  lwz TAB:TMP2, TAB:CARG1->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  bne >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n#if LJ_52\n    |9:\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_len\n    |  bne <3\t\t\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   lwzx TMP1, BASE, RB\n    |   .if DUALNUM\n    |     lwzx TMP2, KBASE, RC\n    |   .endif\n    |    lfdx f14, BASE, RB\n    |    lfdx f15, KBASE, RC\n    |   .if DUALNUM\n    |     checknum cr0, TMP1\n    |     checknum cr1, TMP2\n    |     crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |     bge ->vmeta_arith_vn\n    |   .else\n    |     checknum TMP1; bge ->vmeta_arith_vn\n    |   .endif\n    ||  break;\n    ||case 1:\n    |   lwzx TMP1, BASE, RB\n    |   .if DUALNUM\n    |     lwzx TMP2, KBASE, RC\n    |   .endif\n    |    lfdx f15, BASE, RB\n    |    lfdx f14, KBASE, RC\n    |   .if DUALNUM\n    |     checknum cr0, TMP1\n    |     checknum cr1, TMP2\n    |     crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |     bge ->vmeta_arith_nv\n    |   .else\n    |     checknum TMP1; bge ->vmeta_arith_nv\n    |   .endif\n    ||  break;\n    ||default:\n    |   lwzx TMP1, BASE, RB\n    |   lwzx TMP2, BASE, RC\n    |    lfdx f14, BASE, RB\n    |    lfdx f15, BASE, RC\n    |   checknum cr0, TMP1\n    |   checknum cr1, TMP2\n    |   crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |   bge ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn2\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv2\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv2\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro intmod, a, b, c\n    |  bl ->vm_modi\n    |.endmacro\n    |\n    |.macro fpmod, a, b, c\n    |->BC_MODVN_Z:\n    |  fdiv FARG1, b, c\n    |  // NYI: Use internal implementation of floor.\n    |  blex floor\t\t\t// floor(b/c)\n    |  fmul a, FARG1, c\n    |  fsub a, b, a\t\t\t// b - floor(b/c)*c\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins\n    |  ins_arithpre\n    |.if \"fpins\" == \"fpmod_\"\n    |  b ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    |.else\n    |  fpins f0, f14, f15\n    |  ins_next1\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   lwzux TMP1, RB, BASE\n    |   lwzux TMP2, RC, KBASE\n    |    lwz CARG1, 4(RB)\n    |   checknum cr0, TMP1\n    |    lwz CARG2, 4(RC)\n    ||  break;\n    ||case 1:\n    |   lwzux TMP1, RB, BASE\n    |   lwzux TMP2, RC, KBASE\n    |    lwz CARG2, 4(RB)\n    |   checknum cr0, TMP1\n    |    lwz CARG1, 4(RC)\n    ||  break;\n    ||default:\n    |   lwzux TMP1, RB, BASE\n    |   lwzux TMP2, RC, BASE\n    |    lwz CARG1, 4(RB)\n    |   checknum cr0, TMP1\n    |    lwz CARG2, 4(RC)\n    ||  break;\n    ||}\n    |  checknum cr1, TMP2\n    |  bne >5\n    |  bne cr1, >5\n    |  intins CARG1, CARG1, CARG2\n    |  bso >4\n    |1:\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |  stw CARG1, 4(RA)\n    |2:\n    |  ins_next2\n    |4:  // Overflow.\n    |  checkov TMP0, <1\t\t\t// Ignore unrelated overflow.\n    |  ins_arithfallback b\n    |5:  // FP variant.\n    ||if (vk == 1) {\n    |  lfd f15, 0(RB)\n    |   crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |  lfd f14, 0(RC)\n    ||} else {\n    |  lfd f14, 0(RB)\n    |   crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |  lfd f15, 0(RC)\n    ||}\n    |   ins_arithfallback bge\n    |.if \"fpins\" == \"fpmod_\"\n    |  b ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    |.else\n    |  fpins f0, f14, f15\n    |  ins_next1\n    |  stfdx f0, BASE, RA\n    |  b <2\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arith, intins, fpins\n    |.if DUALNUM\n    |  ins_arithdn intins, fpins\n    |.else\n    |  ins_arithfp fpins\n    |.endif\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |.if GPR64\n    |.macro addo32., y, a, b\n    |  // Need to check overflow for (a<<32) + (b<<32).\n    |  rldicr TMP0, a, 32, 31\n    |  rldicr TMP3, b, 32, 31\n    |  addo. TMP0, TMP0, TMP3\n    |  add y, a, b\n    |.endmacro\n    |  ins_arith addo32., fadd\n    |.else\n    |  ins_arith addo., fadd\n    |.endif\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |.if GPR64\n    |.macro subo32., y, a, b\n    |  // Need to check overflow for (a<<32) - (b<<32).\n    |  rldicr TMP0, a, 32, 31\n    |  rldicr TMP3, b, 32, 31\n    |  subo. TMP0, TMP0, TMP3\n    |  sub y, a, b\n    |.endmacro\n    |  ins_arith subo32., fsub\n    |.else\n    |  ins_arith subo., fsub\n    |.endif\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith mullwo., fmul\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp fdiv\n    break;\n  case BC_MODVN:\n    |  ins_arith intmod, fpmod\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arith intmod, fpmod_\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  lwzx TMP1, BASE, RB\n    |   lfdx FARG1, BASE, RB\n    |  lwzx TMP2, BASE, RC\n    |   lfdx FARG2, BASE, RC\n    |  checknum cr0, TMP1\n    |  checknum cr1, TMP2\n    |  crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |  bge ->vmeta_arith_vv\n    |  blex pow\n    |  ins_next1\n    |  stfdx FARG1, BASE, RA\n    |  ins_next2\n    break;\n\n  case BC_CAT:\n    |  // RA = dst*8, RB = src_start*8, RC = src_end*8\n    |  sub CARG3, RC, RB\n    |   stp BASE, L->base\n    |  add CARG2, BASE, RC\n    |  mr SAVE0, RB\n    |->BC_CAT_Z:\n    |   stw PC, SAVE_PC\n    |  mr CARG1, L\n    |  srwi CARG3, CARG3, 3\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  cmplwi CRET1, 0\n    |   lp BASE, L->base\n    |  bne ->vmeta_binop\n    |  ins_next1\n    |  lfdx f0, BASE, SAVE0\t\t// Copy result from RB to RA.\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RD = str_const*8 (~)\n    |  srwi TMP1, RD, 1\n    |  subfic TMP1, TMP1, -4\n    |  ins_next1\n    |  lwzx TMP0, KBASE, TMP1\t\t// KBASE-4-str_const*4\n    |  li TMP2, LJ_TSTR\n    |  stwux TMP2, RA, BASE\n    |  stw TMP0, 4(RA)\n    |  ins_next2\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RD = cdata_const*8 (~)\n    |  srwi TMP1, RD, 1\n    |  subfic TMP1, TMP1, -4\n    |  ins_next1\n    |  lwzx TMP0, KBASE, TMP1\t\t// KBASE-4-cdata_const*4\n    |  li TMP2, LJ_TCDATA\n    |  stwux TMP2, RA, BASE\n    |  stw TMP0, 4(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, RD = int16_literal*8\n    |.if DUALNUM\n    |  slwi RD, RD, 13\n    |  srawi RD, RD, 16\n    |  ins_next1\n    |   stwux TISNUM, RA, BASE\n    |   stw RD, 4(RA)\n    |  ins_next2\n    |.else\n    |  // The soft-float approach is faster.\n    |  slwi RD, RD, 13\n    |  srawi TMP1, RD, 31\n    |  xor TMP2, TMP1, RD\n    |  sub TMP2, TMP2, TMP1\t\t// TMP2 = abs(x)\n    |  cntlzw TMP3, TMP2\n    |  subfic TMP1, TMP3, 0x40d\t\t// TMP1 = exponent-1\n    |   slw TMP2, TMP2, TMP3\t\t// TMP2 = left aligned mantissa\n    |    subfic TMP3, RD, 0\n    |  slwi TMP1, TMP1, 20\n    |   rlwimi RD, TMP2, 21, 1, 31\t// hi = sign(x) | (mantissa>>11)\n    |    subfe TMP0, TMP0, TMP0\n    |   add RD, RD, TMP1\t\t// hi = hi + exponent-1\n    |    and RD, RD, TMP0\t\t// hi = x == 0 ? 0 : hi\n    |  ins_next1\n    |    stwux RD, RA, BASE\n    |    stw ZERO, 4(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RD = num_const*8\n    |  ins_next1\n    |  lfdx f0, KBASE, RD\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RD = primitive_type*8 (~)\n    |  srwi TMP1, RD, 3\n    |  not TMP0, TMP1\n    |  ins_next1\n    |  stwx TMP0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RD = end*8\n    |  stwx TISNIL, BASE, RA\n    |   addi RA, RA, 8\n    |1:\n    |  stwx TISNIL, BASE, RA\n    |  cmpw RA, RD\n    |   addi RA, RA, 8\n    |  blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RD = uvnum*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RD, RD, 1\n    |   addi RD, RD, offsetof(GCfuncL, uvptr)\n    |  lwzx UPVAL:RB, LFUNC:RB, RD\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |  lfd f0, 0(TMP1)\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RD = src*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |    srwi RA, RA, 1\n    |    addi RA, RA, offsetof(GCfuncL, uvptr)\n    |   lfdux f0, RD, BASE\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  lbz TMP3, UPVAL:RB->marked\n    |   lwz CARG2, UPVAL:RB->v\n    |  andix. TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |    lbz TMP0, UPVAL:RB->closed\n    |   lwz TMP2, 0(RD)\n    |   stfd f0, 0(CARG2)\n    |    cmplwi cr1, TMP0, 0\n    |   lwz TMP1, 4(RD)\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n    |   subi TMP2, TMP2, (LJ_TNUMX+1)\n    |  bne >2\t\t\t\t// Upvalue is closed and black?\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1)\n    |  bge <1\t\t\t\t// tvisgcv(v)\n    |  lbz TMP3, GCOBJ:TMP1->gch.marked\n    |  andix. TMP3, TMP3, LJ_GC_WHITES\t// iswhite(v)\n    |   la CARG1, GG_DISP2G(DISPATCH)\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  beq <1\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RD = str_const*8 (~)\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi TMP1, RD, 1\n    |    srwi RA, RA, 1\n    |   subfic TMP1, TMP1, -4\n    |    addi RA, RA, offsetof(GCfuncL, uvptr)\n    |   lwzx STR:TMP1, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  lbz TMP3, UPVAL:RB->marked\n    |   lwz CARG2, UPVAL:RB->v\n    |  andix. TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |   lbz TMP3, STR:TMP1->marked\n    |   lbz TMP2, UPVAL:RB->closed\n    |   li TMP0, LJ_TSTR\n    |   stw STR:TMP1, 4(CARG2)\n    |   stw TMP0, 0(CARG2)\n    |  bne >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  andix. TMP3, TMP3, LJ_GC_WHITES\t// iswhite(str)\n    |   cmplwi cr1, TMP2, 0\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n    |   la CARG1, GG_DISP2G(DISPATCH)\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  beq <1\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RD = num_const*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RA, RA, 1\n    |   addi RA, RA, offsetof(GCfuncL, uvptr)\n    |    lfdx f0, KBASE, RD\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |  stfd f0, 0(TMP1)\n    |  ins_next2\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RD = primitive_type*8 (~)\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RA, RA, 1\n    |    srwi TMP0, RD, 3\n    |   addi RA, RA, offsetof(GCfuncL, uvptr)\n    |    not TMP0, TMP0\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |  stw TMP0, 0(TMP1)\n    |  ins_next2\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RD = target\n    |  lwz TMP1, L->openupval\n    |  branch_RD\t\t\t// Do this first since RD is not saved.\n    |   stp BASE, L->base\n    |  cmplwi TMP1, 0\n    |   mr CARG1, L\n    |  beq >1\n    |   add CARG2, BASE, RA\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  lp BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)\n    |  srwi TMP1, RD, 1\n    |   stp BASE, L->base\n    |  subfic TMP1, TMP1, -4\n    |   stw PC, SAVE_PC\n    |  lwzx CARG2, KBASE, TMP1\t\t// KBASE-4-tab_const*4\n    |   mr CARG1, L\n    |  lwz CARG3, FRAME_FUNC(BASE)\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  lp BASE, L->base\n    |   li TMP0, LJ_TFUNC\n    |  stwux TMP0, RA, BASE\n    |  stw LFUNC:CRET1, 4(RA)\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)\n    |  lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n    |   mr CARG1, L\n    |  lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n    |   stp BASE, L->base\n    |  cmplw TMP0, TMP1\n    |   stw PC, SAVE_PC\n    |  bge >5\n    |1:\n    if (op == BC_TNEW) {\n      |  rlwinm CARG2, RD, 29, 21, 31\n      |  rlwinm CARG3, RD, 18, 27, 31\n      |  cmpwi CARG2, 0x7ff; beq >3\n      |2:\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns Table *.\n    } else {\n      |  srwi TMP1, RD, 1\n      |  subfic TMP1, TMP1, -4\n      |  lwzx CARG2, KBASE, TMP1\t\t// KBASE-4-tab_const*4\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns Table *.\n    }\n    |  lp BASE, L->base\n    |   li TMP0, LJ_TTAB\n    |  stwux TMP0, RA, BASE\n    |  stw TAB:CRET1, 4(RA)\n    |  ins_next\n    if (op == BC_TNEW) {\n      |3:\n      |  li CARG2, 0x801\n      |  b <2\n    }\n    |5:\n    |  mr SAVE0, RD\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mr RD, SAVE0\n    |  mr CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RD = str_const*8 (~)\n  case BC_GSET:\n    |  // RA = src*8, RD = str_const*8 (~)\n    |  lwz LFUNC:TMP2, FRAME_FUNC(BASE)\n    |   srwi TMP1, RD, 1\n    |  lwz TAB:RB, LFUNC:TMP2->env\n    |   subfic TMP1, TMP1, -4\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  lwzux CARG1, RB, BASE\n    |  lwzux CARG2, RC, BASE\n    |   lwz TAB:RB, 4(RB)\n    |.if DUALNUM\n    |   lwz RC, 4(RC)\n    |.else\n    |   lfd f0, 0(RC)\n    |.endif\n    |  checktab CARG1\n    |   checknum cr1, CARG2\n    |  bne ->vmeta_tgetv\n    |.if DUALNUM\n    |  lwz TMP0, TAB:RB->asize\n    |   bne cr1, >5\n    |   lwz TMP1, TAB:RB->array\n    |  cmplw TMP0, RC\n    |   slwi TMP2, RC, 3\n    |.else\n    |   bge cr1, >5\n    |  // Convert number key to integer, check for integerness and range.\n    |  fctiwz f1, f0\n    |    fadd f2, f0, TOBIT\n    |  stfd f1, TMPD\n    |   lwz TMP0, TAB:RB->asize\n    |    fsub f2, f2, TOBIT\n    |  lwz TMP2, TMPD_LO\n    |   lwz TMP1, TAB:RB->array\n    |    fcmpu cr1, f0, f2\n    |  cmplw cr0, TMP0, TMP2\n    |  crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq\n    |   slwi TMP2, TMP2, 3\n    |.endif\n    |  ble ->vmeta_tgetv\t\t// Integer key and in array part?\n    |  lwzx TMP0, TMP1, TMP2\n    |   lfdx f14, TMP1, TMP2\n    |  checknil TMP0; beq >2\n    |1:\n    |  ins_next1\n    |   stfdx f14, BASE, RA\n    |  ins_next2\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetv\n    |\n    |5:\n    |  checkstr CARG2; bne ->vmeta_tgetv\n    |.if not DUALNUM\n    |  lwz STR:RC, 4(RC)\n    |.endif\n    |  b ->BC_TGETS_Z\t\t\t// String key?\n    break;\n  case BC_TGETS:\n    |  // RA = dst*8, RB = table*8, RC = str_const*8 (~)\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP1, RC, 1\n    |    lwz TAB:RB, 4(RB)\n    |   subfic TMP1, TMP1, -4\n    |  checktab CARG1\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  bne ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  lwz TMP0, TAB:RB->hmask\n    |  lwz TMP1, STR:RC->hash\n    |  lwz NODE:TMP2, TAB:RB->node\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n    |  slwi TMP0, TMP1, 5\n    |  slwi TMP1, TMP1, 3\n    |  sub TMP1, TMP0, TMP1\n    |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lwz CARG1, NODE:TMP2->key\n    |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n    |    lwz CARG2, NODE:TMP2->val\n    |     lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)\n    |  checkstr CARG1; bne >4\n    |   cmpw TMP0, STR:RC; bne >4\n    |    checknil CARG2; beq >5\t\t// Key found, but nil value?\n    |3:\n    |    stwux CARG2, RA, BASE\n    |     stw TMP1, 4(RA)\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  lwz NODE:TMP2, NODE:TMP2->next\n    |  cmplwi NODE:TMP2, 0\n    |  bne <1\n    |  // End of hash chain: key not found, nil result.\n    |   li CARG2, LJ_TNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <3\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_index\n    |  bne <3\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  // RA = dst*8, RB = table*8, RC = index*8\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP0, RC, 3\n    |   lwz TAB:RB, 4(RB)\n    |  checktab CARG1; bne ->vmeta_tgetb\n    |  lwz TMP1, TAB:RB->asize\n    |   lwz TMP2, TAB:RB->array\n    |  cmplw TMP0, TMP1; bge ->vmeta_tgetb\n    |  lwzx TMP1, TMP2, RC\n    |   lfdx f0, TMP2, RC\n    |  checknil TMP1; beq >5\n    |1:\n    |  ins_next1\n    |   stfdx f0, BASE, RA\n    |  ins_next2\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\t\t\t// Caveat: preserve TMP0!\n    break;\n  case BC_TGETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  add RB, BASE, RB\n    |  lwz TAB:CARG1, 4(RB)\n    |.if DUALNUM\n    |  add RC, BASE, RC\n    |  lwz TMP0, TAB:CARG1->asize\n    |  lwz CARG2, 4(RC)\n    |   lwz TMP1, TAB:CARG1->array\n    |.else\n    |  lfdx f0, BASE, RC\n    |  lwz TMP0, TAB:CARG1->asize\n    |  toint CARG2, f0\n    |   lwz TMP1, TAB:CARG1->array\n    |.endif\n    |  cmplw TMP0, CARG2\n    |   slwi TMP2, CARG2, 3\n    |  ble ->vmeta_tgetr\t\t// In array part?\n    |   lfdx f14, TMP1, TMP2\n    |->BC_TGETR_Z:\n    |  ins_next1\n    |   stfdx f14, BASE, RA\n    |  ins_next2\n    break;\n\n  case BC_TSETV:\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  lwzux CARG1, RB, BASE\n    |  lwzux CARG2, RC, BASE\n    |   lwz TAB:RB, 4(RB)\n    |.if DUALNUM\n    |   lwz RC, 4(RC)\n    |.else\n    |   lfd f0, 0(RC)\n    |.endif\n    |  checktab CARG1\n    |   checknum cr1, CARG2\n    |  bne ->vmeta_tsetv\n    |.if DUALNUM\n    |  lwz TMP0, TAB:RB->asize\n    |   bne cr1, >5\n    |   lwz TMP1, TAB:RB->array\n    |  cmplw TMP0, RC\n    |   slwi TMP0, RC, 3\n    |.else\n    |   bge cr1, >5\n    |  // Convert number key to integer, check for integerness and range.\n    |  fctiwz f1, f0\n    |    fadd f2, f0, TOBIT\n    |  stfd f1, TMPD\n    |   lwz TMP0, TAB:RB->asize\n    |    fsub f2, f2, TOBIT\n    |  lwz TMP2, TMPD_LO\n    |   lwz TMP1, TAB:RB->array\n    |    fcmpu cr1, f0, f2\n    |  cmplw cr0, TMP0, TMP2\n    |  crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq\n    |   slwi TMP0, TMP2, 3\n    |.endif\n    |  ble ->vmeta_tsetv\t\t// Integer key and in array part?\n    |   lwzx TMP2, TMP1, TMP0\n    |  lbz TMP3, TAB:RB->marked\n    |    lfdx f14, BASE, RA\n    |   checknil TMP2; beq >3\n    |1:\n    |  andix. TMP2, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |    stfdx f14, TMP1, TMP0\n    |  bne >7\n    |2:\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetv\n    |\n    |5:\n    |  checkstr CARG2; bne ->vmeta_tsetv\n    |.if not DUALNUM\n    |  lwz STR:RC, 4(RC)\n    |.endif\n    |  b ->BC_TSETS_Z\t\t\t// String key?\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <2\n    break;\n  case BC_TSETS:\n    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP1, RC, 1\n    |    lwz TAB:RB, 4(RB)\n    |   subfic TMP1, TMP1, -4\n    |  checktab CARG1\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  bne ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8\n    |  lwz TMP0, TAB:RB->hmask\n    |  lwz TMP1, STR:RC->hash\n    |  lwz NODE:TMP2, TAB:RB->node\n    |    stb ZERO, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->hash & tab->hmask\n    |    lfdx f14, BASE, RA\n    |  slwi TMP0, TMP1, 5\n    |  slwi TMP1, TMP1, 3\n    |  sub TMP1, TMP0, TMP1\n    |    lbz TMP3, TAB:RB->marked\n    |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lwz CARG1, NODE:TMP2->key\n    |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n    |    lwz CARG2, NODE:TMP2->val\n    |     lwz NODE:TMP1, NODE:TMP2->next\n    |  checkstr CARG1; bne >5\n    |   cmpw TMP0, STR:RC; bne >5\n    |    checknil CARG2; beq >4\t\t// Key found, but nil value?\n    |2:\n    |  andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |    stfd f14, NODE:TMP2->val\n    |  bne >7\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |  cmplwi TAB:TMP1, 0\n    |  beq <2\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP1->nomm\n    |  andix. TMP0, TMP0, 1<<MM_newindex\n    |  bne <2\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  cmplwi NODE:TMP1, 0\n    |   mr NODE:TMP2, NODE:TMP1\n    |  bne <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |   la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n    |   stw PC, SAVE_PC\n    |   mr CARG1, L\n    |  cmplwi TAB:TMP1, 0\n    |   stp BASE, L->base\n    |  beq >6\t\t\t\t// No metatable: continue.\n    |  lbz TMP0, TAB:TMP1->nomm\n    |  andix. TMP0, TMP0, 1<<MM_newindex\n    |  beq ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  li TMP0, LJ_TSTR\n    |   stw STR:RC, 4(CARG3)\n    |   mr CARG2, TAB:RB\n    |  stw TMP0, 0(CARG3)\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  lp BASE, L->base\n    |  stfd f14, 0(CRET1)\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  // RA = src*8, RB = table*8, RC = index*8\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP0, RC, 3\n    |   lwz TAB:RB, 4(RB)\n    |  checktab CARG1; bne ->vmeta_tsetb\n    |  lwz TMP1, TAB:RB->asize\n    |   lwz TMP2, TAB:RB->array\n    |    lbz TMP3, TAB:RB->marked\n    |  cmplw TMP0, TMP1\n    |   lfdx f14, BASE, RA\n    |  bge ->vmeta_tsetb\n    |  lwzx TMP1, TMP2, RC\n    |  checknil TMP1; beq >5\n    |1:\n    |  andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |   stfdx f14, TMP2, RC\n    |  bne >7\n    |2:\n    |  ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |  cmplwi TAB:TMP1, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP1, TAB:TMP1->nomm\n    |  andix. TMP1, TMP1, 1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetb\t\t\t// Caveat: preserve TMP0!\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  add RB, BASE, RB\n    |  lwz TAB:CARG2, 4(RB)\n    |.if DUALNUM\n    |  add RC, BASE, RC\n    |    lbz TMP3, TAB:CARG2->marked\n    |  lwz TMP0, TAB:CARG2->asize\n    |  lwz CARG3, 4(RC)\n    |   lwz TMP1, TAB:CARG2->array\n    |.else\n    |  lfdx f0, BASE, RC\n    |    lbz TMP3, TAB:CARG2->marked\n    |  lwz TMP0, TAB:CARG2->asize\n    |  toint CARG3, f0\n    |   lwz TMP1, TAB:CARG2->array\n    |.endif\n    |  andix. TMP2, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bne >7\n    |2:\n    |  cmplw TMP0, CARG3\n    |   slwi TMP2, CARG3, 3\n    |   lfdx f14, BASE, RA\n    |  ble ->vmeta_tsetr\t\t// In array part?\n    |  ins_next1\n    |   stfdx f14, TMP1, TMP2\n    |  ins_next2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP2\n    |  b <2\n    break;\n\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)\n    |  add RA, BASE, RA\n    |1:\n    |   add TMP3, KBASE, RD\n    |  lwz TAB:CARG2, -4(RA)\t\t// Guaranteed to be a table.\n    |    addic. TMP0, MULTRES, -8\n    |   lwz TMP3, 4(TMP3)\t\t// Integer constant is in lo-word.\n    |    srwi CARG3, TMP0, 3\n    |    beq >4\t\t\t\t// Nothing to copy?\n    |  add CARG3, CARG3, TMP3\n    |  lwz TMP2, TAB:CARG2->asize\n    |   slwi TMP1, TMP3, 3\n    |    lbz TMP3, TAB:CARG2->marked\n    |  cmplw CARG3, TMP2\n    |   add TMP2, RA, TMP0\n    |   lwz TMP0, TAB:CARG2->array\n    |  bgt >5\n    |   add TMP1, TMP1, TMP0\n    |    andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |3:  // Copy result slots to table.\n    |   lfd f0, 0(RA)\n    |  addi RA, RA, 8\n    |  cmpw cr1, RA, TMP2\n    |   stfd f0, 0(TMP1)\n    |    addi TMP1, TMP1, 8\n    |  blt cr1, <3\n    |  bne >7\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   stp BASE, L->base\n    |  mr CARG1, L\n    |   stw PC, SAVE_PC\n    |  mr SAVE0, RD\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  mr RD, SAVE0\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP0\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8\n    |  add NARGS8:RC, NARGS8:RC, MULTRES\n    |  // Fall through. Assumes BC_CALL follows.\n    break;\n  case BC_CALL:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8\n    |  mr TMP2, BASE\n    |  lwzux TMP0, BASE, RA\n    |   lwz LFUNC:RB, 4(BASE)\n    |    subi NARGS8:RC, NARGS8:RC, 8\n    |   addi BASE, BASE, 8\n    |  checkfunc TMP0; bne ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8\n    |  add NARGS8:RC, NARGS8:RC, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows.\n    break;\n  case BC_CALLT:\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |  lwzux TMP0, RA, BASE\n    |   lwz LFUNC:RB, 4(RA)\n    |    subi NARGS8:RC, NARGS8:RC, 8\n    |    lwz TMP1, FRAME_PC(BASE)\n    |  checkfunc TMP0\n    |   addi RA, RA, 8\n    |  bne ->vmeta_callt\n    |->BC_CALLT_Z:\n    |  andix. TMP0, TMP1, FRAME_TYPE\t// Caveat: preserve cr0 until the crand.\n    |   lbz TMP3, LFUNC:RB->ffid\n    |    xori TMP2, TMP1, FRAME_VARG\n    |    cmplwi cr1, NARGS8:RC, 0\n    |  bne >7\n    |1:\n    |  stw LFUNC:RB, FRAME_FUNC(BASE)\t// Copy function down, but keep PC.\n    |  li TMP2, 0\n    |   cmplwi cr7, TMP3, 1\t\t// (> FF_C) Calling a fast function?\n    |    beq cr1, >3\n    |2:\n    |  addi TMP3, TMP2, 8\n    |   lfdx f0, RA, TMP2\n    |  cmplw cr1, TMP3, NARGS8:RC\n    |   stfdx f0, BASE, TMP2\n    |  mr TMP2, TMP3\n    |  bne cr1, <2\n    |3:\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt\n    |  beq >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  lwz INS, -4(TMP1)\n    |  decode_RA8 RA, INS\n    |  sub TMP1, BASE, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1)\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\t// Need to prepare KBASE.\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  andix. TMP0, TMP2, FRAME_TYPEP\n    |  bne <1\t\t\t\t// Vararg frame below?\n    |  sub BASE, BASE, TMP2\t\t// Relocate BASE down.\n    |  lwz TMP1, FRAME_PC(BASE)\n    |  andix. TMP0, TMP1, FRAME_TYPE\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))\n    |  mr TMP2, BASE\n    |  add BASE, BASE, RA\n    |  lwz TMP1, -24(BASE)\n    |   lwz LFUNC:RB, -20(BASE)\n    |    lfd f1, -8(BASE)\n    |    lfd f0, -16(BASE)\n    |  stw TMP1, 0(BASE)\t\t// Copy callable.\n    |   stw LFUNC:RB, 4(BASE)\n    |  checkfunc TMP1\n    |    stfd f1, 16(BASE)\t\t// Copy control var.\n    |     li NARGS8:RC, 16\t\t// Iterators get 2 arguments.\n    |    stfdu f0, 8(BASE)\t\t// Copy state.\n    |  bne ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  add RA, BASE, RA\n    |  lwz TAB:RB, -12(RA)\n    |  lwz RC, -4(RA)\t\t\t// Get index from control var.\n    |  lwz TMP0, TAB:RB->asize\n    |  lwz TMP1, TAB:RB->array\n    |   addi PC, PC, 4\n    |1:  // Traverse array part.\n    |  cmplw RC, TMP0\n    |   slwi TMP3, RC, 3\n    |  bge >5\t\t\t\t// Index points after array part?\n    |  lwzx TMP2, TMP1, TMP3\n    |   lfdx f0, TMP1, TMP3\n    |  checknil TMP2\n    |     lwz INS, -4(PC)\n    |  beq >4\n    |.if DUALNUM\n    |   stw RC, 4(RA)\n    |   stw TISNUM, 0(RA)\n    |.else\n    |   tonum_u f1, RC\n    |.endif\n    |    addi RC, RC, 1\n    |     addis TMP3, PC, -(BCBIAS_J*4 >> 16)\n    |  stfd f0, 8(RA)\n    |     decode_RD4 TMP1, INS\n    |    stw RC, -4(RA)\t\t\t// Update control var.\n    |     add PC, TMP1, TMP3\n    |.if not DUALNUM\n    |   stfd f1, 0(RA)\n    |.endif\n    |3:\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  addi RC, RC, 1\n    |  b <1\n    |\n    |5:  // Traverse hash part.\n    |  lwz TMP1, TAB:RB->hmask\n    |  sub RC, RC, TMP0\n    |   lwz TMP2, TAB:RB->node\n    |6:\n    |  cmplw RC, TMP1\t\t\t// End of iteration? Branch to ITERL+1.\n    |   slwi TMP3, RC, 5\n    |  bgty <3\n    |   slwi RB, RC, 3\n    |   sub TMP3, TMP3, RB\n    |  lwzx RB, TMP2, TMP3\n    |  lfdx f0, TMP2, TMP3\n    |   add NODE:TMP3, TMP2, TMP3\n    |  checknil RB\n    |     lwz INS, -4(PC)\n    |  beq >7\n    |   lfd f1, NODE:TMP3->key\n    |     addis TMP2, PC, -(BCBIAS_J*4 >> 16)\n    |  stfd f0, 8(RA)\n    |    add RC, RC, TMP0\n    |     decode_RD4 TMP1, INS\n    |   stfd f1, 0(RA)\n    |    addi RC, RC, 1\n    |     add PC, TMP1, TMP2\n    |    stw RC, -4(RA)\t\t\t// Update control var.\n    |  b <3\n    |\n    |7:  // Skip holes in hash part.\n    |  addi RC, RC, 1\n    |  b <6\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RD = target (points to ITERN)\n    |  add RA, BASE, RA\n    |  lwz TMP0, -24(RA)\n    |  lwz CFUNC:TMP1, -20(RA)\n    |   lwz TMP2, -16(RA)\n    |    lwz TMP3, -8(RA)\n    |   cmpwi cr0, TMP2, LJ_TTAB\n    |  cmpwi cr1, TMP0, LJ_TFUNC\n    |    cmpwi cr6, TMP3, LJ_TNIL\n    |  bne cr1, >5\n    |  lbz TMP1, CFUNC:TMP1->ffid\n    |   crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq\n    |  cmpwi cr7, TMP1, FF_next_N\n    |    srwi TMP0, RD, 1\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq\n    |    add TMP3, PC, TMP0\n    |  bne cr0, >5\n    |  lus TMP1, 0xfffe\n    |  ori TMP1, TMP1, 0x7fff\n    |  stw ZERO, -4(RA)\t\t\t// Initialize control var.\n    |  stw TMP1, -8(RA)\n    |    addis PC, TMP3, -(BCBIAS_J*4 >> 16)\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  li TMP0, BC_JMP\n    |   li TMP1, BC_ITERC\n    |  stb TMP0, -1(PC)\n    |    addis PC, TMP3, -(BCBIAS_J*4 >> 16)\n    |   stb TMP1, 3(PC)\n    |  b <1\n    break;\n\n  case BC_VARG:\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  lwz TMP0, FRAME_PC(BASE)\n    |  add RC, BASE, RC\n    |   add RA, BASE, RA\n    |  addi RC, RC, FRAME_VARG\n    |   add TMP2, RA, RB\n    |  subi TMP3, BASE, 8\t\t// TMP3 = vtop\n    |  sub RC, RC, TMP0\t\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  cmplwi cr1, RB, 0\n    |.if PPE\n    |   sub TMP1, TMP3, RC\n    |   cmpwi TMP1, 0\n    |.else\n    |   sub. TMP1, TMP3, RC\n    |.endif\n    |  beq cr1, >5\t\t\t// Copy all varargs?\n    |   subi TMP2, TMP2, 16\n    |   ble >2\t\t\t\t// No vararg slots?\n    |1:  // Copy vararg slots to destination slots.\n    |  lfd f0, 0(RC)\n    |   addi RC, RC, 8\n    |  stfd f0, 0(RA)\n    |  cmplw RA, TMP2\n    |   cmplw cr1, RC, TMP3\n    |  bge >3\t\t\t\t// All destination slots filled?\n    |    addi RA, RA, 8\n    |   blt cr1, <1\t\t\t// More vararg slots?\n    |2:  // Fill up remainder with nil.\n    |  stw TISNIL, 0(RA)\n    |  cmplw RA, TMP2\n    |   addi RA, RA, 8\n    |  blt <2\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  lwz TMP0, L->maxstack\n    |   li MULTRES, 8\t\t\t// MULTRES = (0+1)*8\n    |  bley <3\t\t\t\t// No vararg slots?\n    |  add TMP2, RA, TMP1\n    |  cmplw TMP2, TMP0\n    |   addi MULTRES, TMP1, 8\n    |  bgt >7\n    |6:\n    |  lfd f0, 0(RC)\n    |   addi RC, RC, 8\n    |  stfd f0, 0(RA)\n    |  cmplw RC, TMP3\n    |   addi RA, RA, 8\n    |  blt <6\t\t\t\t// More vararg slots?\n    |  b <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mr CARG1, L\n    |   stp RA, L->top\n    |  sub SAVE0, RC, BASE\t\t// Need delta, because BASE may change.\n    |   stp BASE, L->base\n    |  sub RA, RA, BASE\n    |   stw PC, SAVE_PC\n    |  srwi CARG2, TMP1, 3\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  lp BASE, L->base\n    |  add RA, BASE, RA\n    |  add RC, BASE, SAVE0\n    |  subi TMP3, BASE, 8\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RD = extra_nresults*8\n    |  add RD, RD, MULTRES\t\t// MULTRES >= 8, so RD >= 8.\n    |  // Fall through. Assumes BC_RET follows.\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lwz PC, FRAME_PC(BASE)\n    |   add RA, BASE, RA\n    |    mr MULTRES, RD\n    |1:\n    |  andix. TMP0, PC, FRAME_TYPE\n    |   xori TMP1, PC, FRAME_VARG\n    |  bne ->BC_RETV_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return\n    |   lwz INS, -4(PC)\n    |  cmpwi RD, 8\n    |   subi TMP2, BASE, 8\n    |   subi RC, RD, 8\n    |   decode_RB8 RB, INS\n    |  beq >3\n    |   li TMP1, 0\n    |2:\n    |  addi TMP3, TMP1, 8\n    |   lfdx f0, RA, TMP1\n    |  cmpw TMP3, RC\n    |   stfdx f0, TMP2, TMP1\n    |  beq >3\n    |  addi TMP1, TMP3, 8\n    |   lfdx f1, RA, TMP3\n    |  cmpw TMP1, RC\n    |   stfdx f1, TMP2, TMP3\n    |  bne <2\n    |3:\n    |5:\n    |  cmplw RB, RD\n    |   decode_RA8 RA, INS\n    |  bgt >6\n    |   sub BASE, TMP2, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  subi TMP1, RD, 8\n    |   addi RD, RD, 8\n    |  stwx TISNIL, TMP2, TMP1\n    |  b <5\n    |\n    |->BC_RETV_Z:  // Non-standard return case.\n    |  andix. TMP2, TMP1, FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, TMP1\n    |  lwz PC, FRAME_PC(BASE)\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lwz PC, FRAME_PC(BASE)\n    |   add RA, BASE, RA\n    |    mr MULTRES, RD\n    |  andix. TMP0, PC, FRAME_TYPE\n    |   xori TMP1, PC, FRAME_VARG\n    |  bney ->BC_RETV_Z\n    |\n    |  lwz INS, -4(PC)\n    |   subi TMP2, BASE, 8\n    |  decode_RB8 RB, INS\n    if (op == BC_RET1) {\n      |  lfd f0, 0(RA)\n      |  stfd f0, 0(TMP2)\n    }\n    |5:\n    |  cmplw RB, RD\n    |   decode_RA8 RA, INS\n    |  bgt >6\n    |   sub BASE, TMP2, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  subi TMP1, RD, 8\n    |   addi RD, RD, 8\n    |  stwx TISNIL, TMP2, TMP1\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RD = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |.if DUALNUM\n    |  // Integer loop.\n    |  lwzux TMP1, RA, BASE\n    |   lwz CARG1, FORL_IDX*8+4(RA)\n    |  cmplw cr0, TMP1, TISNUM\n    if (vk) {\n      |   lwz CARG3, FORL_STEP*8+4(RA)\n      |  bne >9\n      |.if GPR64\n      |  // Need to check overflow for (a<<32) + (b<<32).\n      |  rldicr TMP0, CARG1, 32, 31\n      |  rldicr TMP2, CARG3, 32, 31\n      |  add CARG1, CARG1, CARG3\n      |  addo. TMP0, TMP0, TMP2\n      |.else\n      |  addo. CARG1, CARG1, CARG3\n      |.endif\n      |    cmpwi cr6, CARG3, 0\n      |   lwz CARG2, FORL_STOP*8+4(RA)\n      |  bso >6\n      |4:\n      |  stw CARG1, FORL_IDX*8+4(RA)\n    } else {\n      |  lwz TMP3, FORL_STEP*8(RA)\n      |   lwz CARG3, FORL_STEP*8+4(RA)\n      |  lwz TMP2, FORL_STOP*8(RA)\n      |   lwz CARG2, FORL_STOP*8+4(RA)\n      |  cmplw cr7, TMP3, TISNUM\n      |  cmplw cr1, TMP2, TISNUM\n      |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq\n      |  crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n      |    cmpwi cr6, CARG3, 0\n      |  bne >9\n    }\n    |    blt cr6, >5\n    |  cmpw CARG1, CARG2\n    |1:\n    |   stw TISNUM, FORL_EXT*8(RA)\n    if (op != BC_JFORL) {\n      |  srwi RD, RD, 1\n    }\n    |   stw CARG1, FORL_EXT*8+4(RA)\n    if (op != BC_JFORL) {\n      |  add RD, PC, RD\n    }\n    if (op == BC_FORI) {\n      |  bgt >3  // See FP loop below.\n    } else if (op == BC_JFORI) {\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n      |  bley >7\n    } else if (op == BC_IFORL) {\n      |  bgt >2\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else {\n      |  bley =>BC_JLOOP\n    }\n    |2:\n    |  ins_next\n    |5:  // Invert check for negative step.\n    |  cmpw CARG2, CARG1\n    |  b <1\n    if (vk) {\n      |6:  // Potential overflow.\n      |  checkov TMP0, <4\t\t// Ignore unrelated overflow.\n      |  b <2\n    }\n    |.endif\n    if (vk) {\n      |.if DUALNUM\n      |9:  // FP loop.\n      |  lfd f1, FORL_IDX*8(RA)\n      |.else\n      |  lfdux f1, RA, BASE\n      |.endif\n      |  lfd f3, FORL_STEP*8(RA)\n      |  lfd f2, FORL_STOP*8(RA)\n      |   lwz TMP3, FORL_STEP*8(RA)\n      |  fadd f1, f1, f3\n      |  stfd f1, FORL_IDX*8(RA)\n    } else {\n      |.if DUALNUM\n      |9:  // FP loop.\n      |.else\n      |  lwzux TMP1, RA, BASE\n      |  lwz TMP3, FORL_STEP*8(RA)\n      |  lwz TMP2, FORL_STOP*8(RA)\n      |  cmplw cr0, TMP1, TISNUM\n      |  cmplw cr7, TMP3, TISNUM\n      |  cmplw cr1, TMP2, TISNUM\n      |.endif\n      |   lfd f1, FORL_IDX*8(RA)\n      |  crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt\n      |  crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n      |   lfd f2, FORL_STOP*8(RA)\n      |  bge ->vmeta_for\n    }\n    |  cmpwi cr6, TMP3, 0\n    if (op != BC_JFORL) {\n      |  srwi RD, RD, 1\n    }\n    |   stfd f1, FORL_EXT*8(RA)\n    if (op != BC_JFORL) {\n      |  add RD, PC, RD\n    }\n    |  fcmpu cr0, f1, f2\n    if (op == BC_JFORI) {\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    }\n    |  blt cr6, >5\n    if (op == BC_FORI) {\n      |  bgt >3\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  bgty <2\n      |.else\n      |  bgt >2\n      |.endif\n      |1:\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else if (op == BC_JFORI) {\n      |  bley >7\n    } else {\n      |  bley =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  b <2\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |5:  // Negative step.\n    if (op == BC_FORI) {\n      |  bge <2\n      |3:  // Used by integer loop, too.\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else if (op == BC_IFORL) {\n      |  bgey <1\n    } else if (op == BC_JFORI) {\n      |  bgey >7\n    } else {\n      |  bgey =>BC_JLOOP\n    }\n    |  b <2\n    if (op == BC_JFORI) {\n      |7:\n      |  lwz INS, -4(PC)\n      |  decode_RD8 RD, INS\n      |  b =>BC_JLOOP\n    }\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RD = target\n    |  lwzux TMP1, RA, BASE\n    |   lwz TMP2, 4(RA)\n    |  checknil TMP1; beq >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  stw TMP1, -8(RA)\n      |   stw TMP2, -4(RA)\n      |  b =>BC_JLOOP\n    } else {\n      |  branch_RD\t\t\t// Otherwise save control var + branch.\n      |  stw TMP1, -8(RA)\n      |   stw TMP2, -4(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base*8 (ignored), RD = traceno*8\n    |  lwz TMP1, DISPATCH_J(trace)(DISPATCH)\n    |  srwi RD, RD, 1\n    |  // Traces on PPC don't store the trace number, so use 0.\n    |   stw ZERO, DISPATCH_GL(vmstate)(DISPATCH)\n    |  lwzx TRACE:TMP2, TMP1, RD\n    |  clrso TMP1\n    |  lp TMP2, TRACE:TMP2->mcode\n    |   stw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n    |  mtctr TMP2\n    |   addi JGL, DISPATCH, GG_DISP2G+32768\n    |   stw L, DISPATCH_GL(tmpbuf.L)(DISPATCH)\n    |  bctr\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RD = target\n    |  branch_RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lwz TMP2, L->maxstack\n    |   lbz TMP1, -4+PC2PROTO(numparams)(PC)\n    |    lwz KBASE, -4+PC2PROTO(k)(PC)\n    |  cmplw RA, TMP2\n    |   slwi TMP1, TMP1, 3\n    |  bgt ->vm_growstack_l\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n    }\n    |2:\n    |  cmplw NARGS8:RC, TMP1\t\t// Check for missing parameters.\n    |  blt >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD8 RD, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next2\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  stwx TISNIL, BASE, NARGS8:RC\n    |  addi NARGS8:RC, NARGS8:RC, 8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lwz TMP2, L->maxstack\n    |   add TMP1, BASE, RC\n    |  add TMP0, RA, RC\n    |   stw LFUNC:RB, 4(TMP1)\t\t// Store copy of LFUNC.\n    |   addi TMP3, RC, 8+FRAME_VARG\n    |    lwz KBASE, -4+PC2PROTO(k)(PC)\n    |  cmplw TMP0, TMP2\n    |   stw TMP3, 0(TMP1)\t\t// Store delta + FRAME_VARG.\n    |  bge ->vm_growstack_l\n    |  lbz TMP2, -4+PC2PROTO(numparams)(PC)\n    |   mr RA, BASE\n    |   mr RC, TMP1\n    |  ins_next1\n    |  cmpwi TMP2, 0\n    |   addi BASE, TMP1, 8\n    |  beq >3\n    |1:\n    |  cmplw RA, RC\t\t\t// Less args than parameters?\n    |   lwz TMP0, 0(RA)\n    |   lwz TMP3, 4(RA)\n    |  bge >4\n    |    stw TISNIL, 0(RA)\t\t// Clear old fixarg slot (help the GC).\n    |    addi RA, RA, 8\n    |2:\n    |  addic. TMP2, TMP2, -1\n    |   stw TMP0, 8(TMP1)\n    |   stw TMP3, 12(TMP1)\n    |    addi TMP1, TMP1, 8\n    |  bne <1\n    |3:\n    |  ins_next2\n    |\n    |4:  // Clear missing parameters.\n    |  li TMP0, LJ_TNIL\n    |  b <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  lp RD, CFUNC:RB->f\n    } else {\n      |  lp RD, DISPATCH_GL(wrapf)(DISPATCH)\n    }\n    |   add TMP1, RA, NARGS8:RC\n    |   lwz TMP2, L->maxstack\n    |  .toc lp TMP3, 0(RD)\n    |    add RC, BASE, NARGS8:RC\n    |   stp BASE, L->base\n    |   cmplw TMP1, TMP2\n    |    stp RC, L->top\n    |     li_vmstate C\n    |.if TOC\n    |  mtctr TMP3\n    |.else\n    |  mtctr RD\n    |.endif\n    if (op == BC_FUNCCW) {\n      |  lp CARG2, CFUNC:RB->f\n    }\n    |  mr CARG1, L\n    |   bgt ->vm_growstack_c\t\t// Need to grow stack.\n    |  .toc lp TOCREG, TOC_OFS(RD)\n    |  .tocenv lp ENVREG, ENV_OFS(RD)\n    |     st_vmstate\n    |  bctrl\t\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  lp BASE, L->base\n    |  .toc ld TOCREG, SAVE_TOC\n    |   slwi RD, CRET1, 3\n    |  lp TMP1, L->top\n    |    li_vmstate INTERP\n    |  lwz PC, FRAME_PC(BASE)\t\t// Fetch PC of caller.\n    |    stw L, DISPATCH_GL(cur_L)(DISPATCH)\n    |   sub RA, TMP1, RD\t\t// RA = L->top - nresults*8\n    |    st_vmstate\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x5\\n\\t.uleb128 70\\n\\t.uleb128 55\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 14; i <= 31; i++)\n      fprintf(ctx->fp,\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\",\n\t0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_TARGET_PS3\n\t\"\\t.long .lj_vm_ffi_call\\n\"\n#else\n\t\"\\t.long lj_vm_ffi_call\\n\"\n#endif\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x8e\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xe\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x5\\n\\t.uleb128 70\\n\\t.uleb128 55\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 14; i <= 31; i++)\n      fprintf(ctx->fp,\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\",\n\t0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x8e\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xe\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_x64.dasc",
    "content": "|// Low-level VM code for x64 CPUs in LJ_GC64 mode.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch x64\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|//-----------------------------------------------------------------------\n|\n|.if WIN\n|.define X64WIN, 1\t\t\t// Windows/x64 calling conventions.\n|.endif\n|\n|// Fixed register assignments for the interpreter.\n|// This is very fragile and has many dependencies. Caveat emptor.\n|.define BASE,\t\trdx\t\t// Not C callee-save, refetched anyway.\n|.if X64WIN\n|.define KBASE,\t\trdi\t\t// Must be C callee-save.\n|.define PC,\t\trsi\t\t// Must be C callee-save.\n|.define DISPATCH,\trbx\t\t// Must be C callee-save.\n|.define KBASEd,\tedi\n|.define PCd,\t\tesi\n|.define DISPATCHd,\tebx\n|.else\n|.define KBASE,\t\tr15\t\t// Must be C callee-save.\n|.define PC,\t\trbx\t\t// Must be C callee-save.\n|.define DISPATCH,\tr14\t\t// Must be C callee-save.\n|.define KBASEd,\tr15d\n|.define PCd,\t\tebx\n|.define DISPATCHd,\tr14d\n|.endif\n|\n|.define RA,\t\trcx\n|.define RAd,\t\tecx\n|.define RAH,\t\tch\n|.define RAL,\t\tcl\n|.define RB,\t\trbp\t\t// Must be rbp (C callee-save).\n|.define RBd,\t\tebp\n|.define RC,\t\trax\t\t// Must be rax.\n|.define RCd,\t\teax\n|.define RCW,\t\tax\n|.define RCH,\t\tah\n|.define RCL,\t\tal\n|.define OP,\t\tRBd\n|.define RD,\t\tRC\n|.define RDd,\t\tRCd\n|.define RDW,\t\tRCW\n|.define RDL,\t\tRCL\n|.define TMPR,\t\tr10\n|.define TMPRd,\t\tr10d\n|.define ITYPE,\t\tr11\n|.define ITYPEd,\tr11d\n|\n|.if X64WIN\n|.define CARG1,\t\trcx\t\t// x64/WIN64 C call arguments.\n|.define CARG2,\t\trdx\n|.define CARG3,\t\tr8\n|.define CARG4,\t\tr9\n|.define CARG1d,\tecx\n|.define CARG2d,\tedx\n|.define CARG3d,\tr8d\n|.define CARG4d,\tr9d\n|.else\n|.define CARG1,\t\trdi\t\t// x64/POSIX C call arguments.\n|.define CARG2,\t\trsi\n|.define CARG3,\t\trdx\n|.define CARG4,\t\trcx\n|.define CARG5,\t\tr8\n|.define CARG6,\t\tr9\n|.define CARG1d,\tedi\n|.define CARG2d,\tesi\n|.define CARG3d,\tedx\n|.define CARG4d,\tecx\n|.define CARG5d,\tr8d\n|.define CARG6d,\tr9d\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|//-----------------------------------------------------------------------\n|.if X64WIN\t\t// x64/Windows stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rdi; push rsi; push rbx\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|  pop rbx; pop rsi; pop rdi; pop rbp\n|.endmacro\n|\n|.define SAVE_CFRAME,\taword [rsp+aword*13]\n|.define SAVE_PC,\taword [rsp+aword*12]\n|.define SAVE_L,\taword [rsp+aword*11]\n|.define SAVE_ERRF,\tdword [rsp+dword*21]\n|.define SAVE_NRES,\tdword [rsp+dword*20]\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.define ARG5,\t\taword [rsp+aword*4]\n|.define CSAVE_4,\taword [rsp+aword*3]\n|.define CSAVE_3,\taword [rsp+aword*2]\n|.define CSAVE_2,\taword [rsp+aword*1]\n|.define CSAVE_1,\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee\n|\n|.define ARG5d,\t\tdword [rsp+dword*8]\n|.define TMP1,\t\tARG5\t\t\t// TMP1 overlaps ARG5\n|.define TMP1d,\t\tARG5d\n|.define TMP1hi,\tdword [rsp+dword*9]\n|.define MULTRES,\tTMP1d\t\t\t// MULTRES overlaps TMP1d.\n|\n|//-----------------------------------------------------------------------\n|.else\t\t\t// x64/POSIX stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rbx; push r15; push r14\n|.if NO_UNWIND\n|  push r13; push r12\n|.endif\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|.if NO_UNWIND\n|  pop r12; pop r13\n|.endif\n|  pop r14; pop r15; pop rbx; pop rbp\n|.endmacro\n|\n|//----- 16 byte aligned,\n|.if NO_UNWIND\n|.define SAVE_RET,\taword [rsp+aword*11]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*10]\n|.define SAVE_R3,\taword [rsp+aword*9]\n|.define SAVE_R2,\taword [rsp+aword*8]\n|.define SAVE_R1,\taword [rsp+aword*7]\n|.define SAVE_RU2,\taword [rsp+aword*6]\n|.define SAVE_RU1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.else\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.endif\n|.define SAVE_CFRAME,\taword [rsp+aword*4]\n|.define SAVE_PC,\taword [rsp+aword*3]\n|.define SAVE_L,\taword [rsp+aword*2]\n|.define SAVE_ERRF,\tdword [rsp+dword*3]\n|.define SAVE_NRES,\tdword [rsp+dword*2]\n|.define TMP1,\t\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned\n|\n|.define TMP1d,\t\tdword [rsp]\n|.define TMP1hi,\tdword [rsp+dword*1]\n|.define MULTRES,\tTMP1d\t\t\t// MULTRES overlaps TMP1d.\n|\n|.endif\n|\n|//-----------------------------------------------------------------------\n|\n|// Instruction headers.\n|.macro ins_A; .endmacro\n|.macro ins_AD; .endmacro\n|.macro ins_AJ; .endmacro\n|.macro ins_ABC; movzx RBd, RCH; movzx RCd, RCL; .endmacro\n|.macro ins_AB_; movzx RBd, RCH; .endmacro\n|.macro ins_A_C; movzx RCd, RCL; .endmacro\n|.macro ins_AND; not RD; .endmacro\n|\n|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).\n|.macro ins_NEXT\n|  mov RCd, [PC]\n|  movzx RAd, RCH\n|  movzx OP, RCL\n|  add PC, 4\n|  shr RCd, 16\n|  jmp aword [DISPATCH+OP*8]\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  // Around 10%-30% slower on Core2, a lot more slower on P4.\n|  .macro ins_next\n|    jmp ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-8] = PC\n|  mov PC, LFUNC:RB->pc\n|  mov RAd, [PC]\n|  movzx OP, RAL\n|  movzx RAd, RAH\n|  add PC, 4\n|  jmp aword [DISPATCH+OP*8]\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC, RD = nargs+1\n|  mov [BASE-8], PC\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to clear or set tags.\n|.macro cleartp, reg; shl reg, 17; shr reg, 17; .endmacro\n|.macro settp, reg, tp\n|  mov64 ITYPE, ((int64_t)tp<<47)\n|  or reg, ITYPE\n|.endmacro\n|.macro settp, dst, reg, tp\n|  mov64 dst, ((int64_t)tp<<47)\n|  or dst, reg\n|.endmacro\n|.macro setint, reg\n|  settp reg, LJ_TISNUM\n|.endmacro\n|.macro setint, dst, reg\n|  settp dst, reg, LJ_TISNUM\n|.endmacro\n|\n|// Macros to test operand types.\n|.macro checktp_nc, reg, tp, target\n|  mov ITYPE, reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checktp, reg, tp, target\n|  mov ITYPE, reg\n|  cleartp reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checktptp, src, tp, target\n|  mov ITYPE, src\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC, target; .endmacro\n|\n|.macro checknumx, reg, target, jump\n|  mov ITYPE, reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, LJ_TISNUM\n|  jump target\n|.endmacro\n|.macro checkint, reg, target; checknumx reg, target, jne; .endmacro\n|.macro checkinttp, src, target; checknumx src, target, jne; .endmacro\n|.macro checknum, reg, target; checknumx reg, target, jae; .endmacro\n|.macro checknumtp, src, target; checknumx src, target, jae; .endmacro\n|.macro checknumber, src, target; checknumx src, target, ja; .endmacro\n|\n|.macro mov_false, reg; mov64 reg, (int64_t)~((uint64_t)1<<47); .endmacro\n|.macro mov_true, reg; mov64 reg, (int64_t)~((uint64_t)2<<47); .endmacro\n|\n|// These operands must be used with movzx.\n|.define PC_OP, byte [PC-4]\n|.define PC_RA, byte [PC-3]\n|.define PC_RB, byte [PC-1]\n|.define PC_RC, byte [PC-2]\n|.define PC_RD, word [PC-2]\n|\n|.macro branchPC, reg\n|  lea PC, [PC+reg*4-BCBIAS_J*4]\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|// Decrement hashed hotcount and trigger trace recorder if zero.\n|.macro hotloop, reg\n|  mov reg, PCd\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP\n|  jb ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall, reg\n|  mov reg, PCd\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL\n|  jb ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro set_vmstate, st\n|  mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st\n|.endmacro\n|\n|.macro fpop1; fstp st1; .endmacro\n|\n|// Synthesize SSE FP constants.\n|.macro sseconst_abs, reg, tmp\t\t// Synthesize abs mask.\n|  mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp\n|.endmacro\n|\n|.macro sseconst_hi, reg, tmp, val\t// Synthesize hi-32 bit const.\n|  mov64 tmp, U64x(val,00000000); movd reg, tmp\n|.endmacro\n|\n|.macro sseconst_sign, reg, tmp\t\t// Synthesize sign mask.\n|  sseconst_hi reg, tmp, 80000000\n|.endmacro\n|.macro sseconst_1, reg, tmp\t\t// Synthesize 1.0.\n|  sseconst_hi reg, tmp, 3ff00000\n|.endmacro\n|.macro sseconst_m1, reg, tmp\t\t// Synthesize -1.0.\n|  sseconst_hi reg, tmp, bff00000\n|.endmacro\n|.macro sseconst_2p52, reg, tmp\t\t// Synthesize 2^52.\n|  sseconst_hi reg, tmp, 43300000\n|.endmacro\n|.macro sseconst_tobit, reg, tmp\t// Synthesize 2^52 + 2^51.\n|  sseconst_hi reg, tmp, 43380000\n|.endmacro\n|\n|// Move table write barrier back. Overwrites reg.\n|.macro barrierback, tab, reg\n|  and byte tab->marked, (uint8_t)~LJ_GC_BLACK\t// black2gray(tab)\n|  mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]\n|  mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab\n|  mov tab->gclist, reg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  test PCd, FRAME_P\n  |  jz ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  and PC, -8\n  |  sub BASE, PC\t\t\t// Restore caller base.\n  |  lea RA, [RA+PC-8]\t\t\t// Rebase RA and prepend one result.\n  |  mov PC, [BASE-8]\t\t\t// Fetch PC of previous frame.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |  mov_true ITYPE\n  |  mov aword [BASE+RA], ITYPE\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  add RDd, 1\t\t\t\t// RD = nresults+1\n  |  jz ->vm_unwind_yield\n  |  mov MULTRES, RDd\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return\n  |  xor PC, FRAME_C\n  |  test PCd, FRAME_TYPE\n  |  jnz ->vm_returnp\n  |\n  |  // Return to C.\n  |  set_vmstate C\n  |  and PC, -8\n  |  sub PC, BASE\n  |  neg PC\t\t\t\t// Previous base = BASE - delta.\n  |\n  |  sub RDd, 1\n  |  jz >2\n  |1:  // Move results down.\n  |  mov RB, [BASE+RA]\n  |  mov [BASE-16], RB\n  |  add BASE, 8\n  |  sub RDd, 1\n  |  jnz <1\n  |2:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, PC\n  |3:\n  |  mov RDd, MULTRES\n  |  mov RAd, SAVE_NRES\t\t\t// RA = wanted nresults+1\n  |4:\n  |  cmp RAd, RDd\n  |  jne >6\t\t\t\t// More/less results wanted?\n  |5:\n  |  sub BASE, 16\n  |  mov L:RB->top, BASE\n  |\n  |->vm_leave_cp:\n  |  mov RA, SAVE_CFRAME\t\t// Restore previous C frame.\n  |  mov L:RB->cframe, RA\n  |  xor eax, eax\t\t\t// Ok return status for vm_pcall.\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  jb >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  cmp BASE, L:RB->maxstack\n  |  ja >8\n  |  mov aword [BASE-16], LJ_TNIL\n  |  add BASE, 8\n  |  add RDd, 1\n  |  jmp <4\n  |\n  |7:  // Less results wanted.\n  |  test RAd, RAd\n  |  jz <5\t\t\t\t// But check for LUA_MULTRET+1.\n  |  sub RA, RD\t\t\t\t// Negative result!\n  |  lea BASE, [BASE+RA*8]\t\t// Correct top.\n  |  jmp <5\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  mov L:RB->top, BASE\t\t// Save current top held in BASE (yes).\n  |  mov MULTRES, RDd\t\t\t// Need to fill only remainder with nil.\n  |  mov CARG2d, RAd\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->top\t\t// Need the (realloced) L->top in BASE.\n  |  jmp <3\n  |\n  |->vm_unwind_yield:\n  |  mov al, LUA_YIELD\n  |  jmp ->vm_unwind_c_eh\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov eax, CARG2d\t\t\t// Error return status for vm_pcall.\n  |  mov rsp, CARG1\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov GL:RB, L:RB->glref\n  |  mov dword GL:RB->vmstate, ~LJ_VMST_C\n  |  jmp ->vm_leave_unw\n  |\n  |->vm_unwind_rethrow:\n  |.if not X64WIN\n  |  mov CARG1, SAVE_L\n  |  mov CARG2d, eax\n  |  restoreregs\n  |  jmp extern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  and CARG1, CFRAME_RAWMASK\n  |  mov rsp, CARG1\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov RDd, 1+1\t\t\t// Really 1+2 results, incr. later.\n  |  mov BASE, L:RB->base\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov PC, [BASE-8]\t\t\t// Fetch PC of previous frame.\n  |  mov_false RA\n  |  mov RB, [BASE]\n  |  mov [BASE-16], RA\t\t\t// Prepend false to error message.\n  |  mov [BASE-8], RB\n  |  mov RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  set_vmstate INTERP\n  |  jmp ->vm_returnc\t\t\t// Increments RD/MULTRES and returns.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  mov CARG2d, LUA_MINSTACK\n  |  jmp >2\n  |\n  |->vm_growstack_v:\t\t\t// Grow stack for vararg Lua function.\n  |  sub RD, 16\t\t\t\t// LJ_FR2\n  |  jmp >1\n  |\n  |->vm_growstack_f:\t\t\t// Grow stack for fixarg Lua function.\n  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |1:\n  |  movzx RAd, byte [PC-4+PC2PROTO(framesize)]\n  |  add PC, 4\t\t\t\t// Must point after first instruction.\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov SAVE_PC, PC\n  |  mov CARG2, RA\n  |2:\n  |  // RB = L, L->base = new base, L->top = top\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  mov LFUNC:RB, [BASE-16]\n  |  cleartp LFUNC:RB\n  |  sub RD, BASE\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  // BASE = new base, RB = LFUNC, RD = nargs+1\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov RA, CARG2\n  |  mov PCd, FRAME_CP\n  |  xor RDd, RDd\n  |  lea KBASE, [esp+CFRAME_RESUME]\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov SAVE_PC, RD\t\t\t// Any value outside of bytecode is ok.\n  |  mov SAVE_CFRAME, RD\n  |  mov SAVE_NRES, RDd\n  |  mov SAVE_ERRF, RDd\n  |  mov L:RB->cframe, KBASE\n  |  cmp byte L:RB->status, RDL\n  |  je >2\t\t\t\t// Initial resume (like a call).\n  |\n  |  // Resume after yield (like a return).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov byte L:RB->status, RDL\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr RDd, 3\n  |  add RDd, 1\t\t\t\t// RD = nresults+1\n  |  sub RA, BASE\t\t\t// RA = resultofs\n  |  mov PC, [BASE-8]\n  |  mov MULTRES, RDd\n  |  test PCd, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PCd, FRAME_CP\n  |  mov SAVE_ERRF, CARG4d\n  |  jmp >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PCd, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  mov SAVE_NRES, CARG3d\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov RA, CARG2\n  |\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |  add DISPATCH, GG_G2DISP\n  |  mov L:RB->cframe, rsp\n  |\n  |2:  // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov BASE, L:RB->base\t\t// BASE = old base (used in vmeta_call).\n  |  add PC, RA\n  |  sub PC, BASE\t\t\t// PC = frame delta + frame type\n  |\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr NARGS:RDd, 3\n  |  add NARGS:RDd, 1\t\t\t// RD = nargs+1\n  |\n  |->vm_call_dispatch:\n  |  mov LFUNC:RB, [RA-16]\n  |  checkfunc LFUNC:RB, ->vmeta_call\t// Ensure KBASE defined and != BASE.\n  |\n  |->vm_call_dispatch_f:\n  |  mov BASE, RA\n  |  ins_call\n  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |\n  |  mov KBASE, L:RB->stack\t\t// Compute -savestack(L, L->top).\n  |  sub KBASE, L:RB->top\n  |   mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov SAVE_ERRF, 0\t\t\t// No error function.\n  |  mov SAVE_NRES, KBASEd\t\t// Neg. delta means cframe w/o frame.\n  |   add DISPATCH, GG_G2DISP\n  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).\n  |\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov L:RB->cframe, rsp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  // TValue * (new base) or NULL returned in eax (RC).\n  |  test RC, RC\n  |  jz ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |  mov RA, RC\n  |  mov PCd, FRAME_CP\n  |  jmp <2\t\t\t\t// Else continue with the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)\n  |  add RA, BASE\n  |  and PC, -8\n  |  mov RB, BASE\n  |  sub BASE, PC\t\t\t// Restore caller BASE.\n  |  mov aword [RA+RD*8-8], LJ_TNIL\t// Ensure one valid arg.\n  |  mov RC, RA\t\t\t\t// ... in [RC]\n  |  mov PC, [RB-24]\t\t\t// Restore PC from [cont|PC].\n  |  mov RA, qword [RB-32]\t\t// May be negative on WIN64 with debug.\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |  mov LFUNC:KBASE, [BASE-16]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  // BASE = base, RC = result, RB = meta base\n  |  jmp RA\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  je ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: Tail call from C function.\n  |  sub RB, BASE\n  |  shr RBd, 3\n  |  lea RDd, [RBd-3]\n  |  jmp ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// BASE = base, RC = result, RB = mbase\n  |  movzx RAd, PC_RB\n  |  sub RB, 32\n  |  lea RA, [BASE+RA*8]\n  |  sub RA, RB\n  |  je ->cont_ra\n  |  neg RA\n  |  shr RAd, 3\n  |.if X64WIN\n  |  mov CARG3d, RAd\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\n  |  mov RC, [RC]\n  |  mov [RB], RC\n  |  mov CARG2, RB\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\n  |  mov CARG3d, RAd\n  |  mov RA, [RC]\n  |  mov [RB], RA\n  |  mov CARG2, RB\n  |.endif\n  |  jmp ->BC_CAT_Z\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets:\n  |  settp STR:RC, LJ_TSTR\t\t// STR:RC = GCstr *\n  |  mov TMP1, STR:RC\n  |  lea RC, TMP1\n  |  cmp PC_OP, BC_GGET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t// TAB:RB = GCtab *\n  |  lea RB, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RB], TAB:RA\n  |  jmp >2\n  |\n  |->vmeta_tgetb:\n  |  movzx RCd, PC_RC\n  |.if DUALNUM\n  |  setint RC\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RCd\n  |  movsd TMP1, xmm0\n  |.endif\n  |  lea RC, TMP1\n  |  jmp >1\n  |\n  |->vmeta_tgetv:\n  |  movzx RCd, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RBd, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2, RB\n  |  mov CARG3, RC\n  |  mov L:RB, L:CARG1\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |->cont_ra:\t\t\t\t// BASE = base, RC = result\n  |  movzx RAd, PC_RA\n  |  mov RB, [RC]\n  |  mov [BASE+RA*8], RB\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  mov RA, L:RB->top\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-16]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RDd, 2+1\t\t\t// 2 args for func(t, k).\n  |  cleartp LFUNC:RB\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  mov CARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, RCd\t\t\t// Caveat: CARG2 == BASE\n  |  call extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RC).\n  |  movzx RAd, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RC, RC\n  |  jnz ->BC_TGETR_Z\n  |  mov ITYPE, LJ_TNIL\n  |  jmp ->BC_TGETR2_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets:\n  |  settp STR:RC, LJ_TSTR\t\t// STR:RC = GCstr *\n  |  mov TMP1, STR:RC\n  |  lea RC, TMP1\n  |  cmp PC_OP, BC_GSET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t// TAB:RB = GCtab *\n  |  lea RB, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RB], TAB:RA\n  |  jmp >2\n  |\n  |->vmeta_tsetb:\n  |  movzx RCd, PC_RC\n  |.if DUALNUM\n  |  setint RC\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RCd\n  |  movsd TMP1, xmm0\n  |.endif\n  |  lea RC, TMP1\n  |  jmp >1\n  |\n  |->vmeta_tsetv:\n  |  movzx RCd, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RBd, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2, RB\n  |  mov CARG3, RC\n  |  mov L:RB, L:CARG1\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  movzx RAd, PC_RA\n  |  mov RB, [BASE+RA*8]\n  |  mov [RC], RB\n  |->cont_nop:\t\t\t\t// BASE = base, (RC = result)\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  mov RA, L:RB->top\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  movzx RCd, PC_RA\n  |  // Copy value to third argument.\n  |  mov RB, [BASE+RC*8]\n  |  mov [RA+16], RB\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-16]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RDd, 3+1\t\t\t// 3 args for func(t, k, v).\n  |  cleartp LFUNC:RB\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |.if X64WIN\n  |  mov L:CARG1, SAVE_L\n  |  mov CARG3d, RCd\n  |  mov L:CARG1->base, BASE\n  |  xchg CARG2, TAB:RB\t\t\t// Caveat: CARG2 == BASE.\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov CARG2, TAB:RB\n  |  mov L:CARG1->base, BASE\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG3d, RCd\t\t\t// Caveat: CARG3 == BASE.\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // TValue * returned in eax (RC).\n  |  movzx RAd, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  jmp ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  movzx RDd, PC_RD\n  |  movzx RAd, PC_RA\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 == BASE.\n  |.if X64WIN\n  |  lea CARG3, [BASE+RD*8]\n  |  lea CARG2, [BASE+RA*8]\n  |.else\n  |  lea CARG2, [BASE+RA*8]\n  |  lea CARG3, [BASE+RD*8]\n  |.endif\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1/CARG4 == RA.\n  |  movzx CARG4d, PC_OP\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |3:\n  |  mov BASE, L:RB->base\n  |  cmp RC, 1\n  |  ja ->vmeta_binop\n  |4:\n  |  lea PC, [PC+4]\n  |  jb >6\n  |5:\n  |  movzx RDd, PC_RD\n  |  branchPC RD\n  |6:\n  |  ins_next\n  |\n  |->cont_condt:\t\t\t// BASE = base, RC = result\n  |  add PC, 4\n  |  mov ITYPE, [RC]\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND\t\t// Branch if result is true.\n  |  jb <5\n  |  jmp <6\n  |\n  |->cont_condf:\t\t\t// BASE = base, RC = result\n  |  mov ITYPE, [RC]\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND\t\t// Branch if result is false.\n  |  jmp <4\n  |\n  |->vmeta_equal:\n  |  cleartp TAB:RD\n  |  sub PC, 4\n  |.if X64WIN\n  |  mov CARG3, RD\n  |  mov CARG4d, RBd\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG2, RA\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1 == RA.\n  |.else\n  |  mov CARG2, RA\n  |  mov CARG4d, RBd\t\t\t// Caveat: CARG4 == RA.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG3, RD\n  |  mov CARG1, L:RB\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, 4\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG1, L:RB\n  |  mov CARG2d, dword [PC-4]\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal_cd\t// (lua_State *L, BCIns ins)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2d, RAd\n  |  mov CARG3d, RDd\n  |  mov L:CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  mov BASE, L:RB->base\n  |  jmp <6\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vno:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_vn:\n  |  lea RC, [KBASE+RC*8]\n  |  jmp >1\n  |\n  |->vmeta_arith_nvo:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_nv:\n  |  lea TMPR, [KBASE+RC*8]\n  |  lea RC, [BASE+RB*8]\n  |  mov RB, TMPR\n  |  jmp >2\n  |\n  |->vmeta_unm:\n  |  lea RC, [BASE+RD*8]\n  |  mov RB, RC\n  |  jmp >2\n  |\n  |->vmeta_arith_vvo:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_vv:\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  lea RA, [BASE+RA*8]\n  |.if X64WIN\n  |  mov CARG3, RB\n  |  mov CARG4, RC\n  |  movzx RCd, PC_OP\n  |  mov ARG5d, RCd\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG2, RA\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1 == RA.\n  |.else\n  |  movzx CARG5d, PC_OP\n  |  mov CARG2, RA\n  |  mov CARG4, RC\t\t\t// Caveat: CARG4 == RA.\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG3, RB\n  |  mov L:RB, L:CARG1\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_arith\t// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = base, RC = new base, stack = cont/func/o1/o2\n  |  mov RA, RC\n  |  sub RC, BASE\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  lea PC, [RC+FRAME_CONT]\n  |  mov NARGS:RDd, 2+1\t\t\t// 2 args for func(o1, o2).\n  |  jmp ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  movzx RDd, PC_RD\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  lea CARG2, [BASE+RD*8]\t\t// Caveat: CARG2 == BASE\n  |  mov L:CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // NULL (retry) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n#if LJ_52\n  |  test RC, RC\n  |  jne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  movzx RDd, PC_RD\n  |  mov TAB:CARG1, [BASE+RD*8]\n  |  cleartp TAB:CARG1\n  |  jmp ->BC_LEN_Z\n#else\n  |  jmp ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call_ra:\n  |  lea RA, [BASE+RA*8+16]\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return\n  |  mov TMP1d, NARGS:RDd\t\t// Save RA, RC for us.\n  |  mov RB, RA\n  |.if X64WIN\n  |  mov L:TMPR, SAVE_L\n  |  mov L:TMPR->base, BASE\t\t// Caveat: CARG2 is BASE.\n  |  lea CARG2, [RA-16]\n  |  lea CARG3, [RA+NARGS:RD*8-8]\n  |  mov CARG1, L:TMPR\t\t\t// Caveat: CARG1 is RA.\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG3 is BASE.\n  |  lea CARG2, [RA-16]\n  |  lea CARG3, [RA+NARGS:RD*8-8]\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  mov RA, RB\n  |  mov L:RB, SAVE_L\n  |  mov BASE, L:RB->base\n  |  mov NARGS:RDd, TMP1d\n  |  mov LFUNC:RB, [RA-16]\n  |  cleartp LFUNC:RB\n  |  add NARGS:RDd, 1\n  |  // This is fragile. L->base must not move, KBASE must always be defined.\n  |  cmp KBASE, BASE\t\t\t// Continue with CALLT if flag set.\n  |  je ->BC_CALLT_Z\n  |  mov BASE, RA\n  |  ins_call\t\t\t\t// Otherwise call resolved metamethod.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, RA\t\t\t// Caveat: CARG2 == BASE\n  |  mov L:CARG1, L:RB\t\t\t// Caveat: CARG1 == RA\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  mov BASE, L:RB->base\n  |  mov RCd, [PC-4]\n  |  movzx RAd, RCH\n  |  movzx OP, RCL\n  |  shr RCd, 16\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmp NARGS:RDd, 1+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmp NARGS:RDd, 2+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name, op\n  |  .ffunc_1 name\n  |  checknumtp [BASE], ->fff_fallback\n  |  op xmm0, qword [BASE]\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc_n name, movsd\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc_2 name\n  |  checknumtp [BASE], ->fff_fallback\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  movsd xmm1, qword [BASE+8]\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses label 1.\n  |.macro ffgccheck\n  |  mov RB, [DISPATCH+DISPATCH_GL(gc.total)]\n  |  cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]\n  |  jb >1\n  |  call ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  mov ITYPE, [BASE]\n  |  mov RB, ITYPE\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND; jae ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  mov MULTRES, RDd\n  |  mov RB, [BASE]\n  |  mov [BASE-16], RB\n  |  sub RDd, 2\n  |  jz >2\n  |  mov RA, BASE\n  |1:\n  |  add RA, 8\n  |  mov RB, [RA]\n  |  mov [RA-16], RB\n  |  sub RDd, 1\n  |  jnz <1\n  |2:\n  |  mov RDd, MULTRES\n  |  jmp ->fff_res_\n  |\n  |.ffunc_1 type\n  |  mov RC, [BASE]\n  |  sar RC, 47\n  |  mov RBd, LJ_TISNUM\n  |  cmp RCd, RBd\n  |  cmovb RCd, RBd\n  |  not RCd\n  |2:\n  |  mov CFUNC:RB, [BASE-16]\n  |  cleartp CFUNC:RB\n  |  mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]\n  |  mov PC, [BASE-8]\n  |  settp STR:RC, LJ_TSTR\n  |  mov [BASE-16], STR:RC\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  mov TAB:RB, [BASE]\n  |  mov PC, [BASE-8]\n  |  checktab TAB:RB, >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  mov TAB:RB, TAB:RB->metatable\n  |2:\n  |  test TAB:RB, TAB:RB\n  |  mov aword [BASE-16], LJ_TNIL\n  |  jz ->fff_res1\n  |  settp TAB:RC, TAB:RB, LJ_TTAB\n  |  mov [BASE-16], TAB:RC\t\t// Store metatable as default result.\n  |  mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+8*(GCROOT_MMNAME+MM_metatable)]\n  |  mov RAd, TAB:RB->hmask\n  |  and RAd, STR:RC->hash\n  |  settp STR:RC, LJ_TSTR\n  |  imul RAd, #NODE\n  |  add NODE:RA, TAB:RB->node\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  cmp NODE:RA->key, STR:RC\n  |  je >5\n  |4:\n  |  mov NODE:RA, NODE:RA->next\n  |  test NODE:RA, NODE:RA\n  |  jnz <3\n  |  jmp ->fff_res1\t\t\t// Not found, keep default result.\n  |5:\n  |  mov RB, NODE:RA->val\n  |  cmp RB, LJ_TNIL; je ->fff_res1\t// Ditto for nil value.\n  |  mov [BASE-16], RB\t\t\t// Return value of mt.__metatable.\n  |  jmp ->fff_res1\n  |\n  |6:\n  |  cmp ITYPEd, LJ_TUDATA; je <1\n  |  cmp ITYPEd, LJ_TISNUM; ja >7\n  |  mov ITYPEd, LJ_TISNUM\n  |7:\n  |  not ITYPEd\n  |  mov TAB:RB, [DISPATCH+ITYPE*8+DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  jmp <2\n  |\n  |.ffunc_2 setmetatable\n  |  mov TAB:RB, [BASE]\n  |  mov TAB:TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n  |  mov TAB:RA, [BASE+8]\n  |  checktab TAB:RA, ->fff_fallback\n  |  mov TAB:RB->metatable, TAB:RA\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], TAB:TMPR\t\t\t// Return original table.\n  |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n  |  jz >1\n  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.\n  |  barrierback TAB:RB, RC\n  |1:\n  |  jmp ->fff_res1\n  |\n  |.ffunc_2 rawget\n  |.if X64WIN\n  |  mov TAB:RA, [BASE]\n  |  checktab TAB:RA, ->fff_fallback\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3, [BASE+8]\n  |  mov CARG2, TAB:RA\t\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG1, SAVE_L\n  |.else\n  |  mov TAB:CARG2, [BASE]\n  |  checktab TAB:CARG2, ->fff_fallback\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3, [BASE+8]\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG1, SAVE_L\n  |.endif\n  |  call extern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |  // cTValue * returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  // Copy table slot.\n  |  mov RB, [RD]\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\t// Exactly one argument.\n  |  mov RB, [BASE]\n  |  checknumber RB, ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  mov PC, [BASE-8]\n  |  mov STR:RB, [BASE]\n  |  checktp_nc STR:RB, LJ_TSTR, >3\n  |  // A __tostring method in the string base metatable is ignored.\n  |2:\n  |  mov [BASE-16], STR:RB\n  |  jmp ->fff_res1\n  |3:  // Handle numbers inline, unless a number base metatable is present.\n  |  cmp ITYPEd, LJ_TISNUM;  ja ->fff_fallback_1\n  |  cmp aword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0\n  |  jne ->fff_fallback\n  |  ffgccheck\t\t\t\t// Caveat: uses label 1.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |.if not X64WIN\n  |  mov CARG2, BASE\t\t\t// Otherwise: CARG2 == BASE\n  |.endif\n  |  mov L:CARG1, L:RB\n  |.if DUALNUM\n  |  call extern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |.else\n  |  call extern lj_strfmt_num\t\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // GCstr returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  settp STR:RB, RD, LJ_TSTR\n  |  jmp <2\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  je >2\t\t\t\t// Missing 2nd arg?\n  |1:\n  |.if X64WIN\n  |  mov RA, [BASE]\n  |  checktab RA, ->fff_fallback\n  |.else\n  |  mov CARG2, [BASE]\n  |  checktab CARG2, ->fff_fallback\n  |.endif\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov L:RB->top, BASE\t\t// Dummy frame length is ok.\n  |  mov PC, [BASE-8]\n  |.if X64WIN\n  |  lea CARG3, [BASE+8]\n  |  mov CARG2, RA\t\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG1, L:RB\n  |.else\n  |  lea CARG3, [BASE+8]\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG1, L:RB\n  |.endif\n  |  mov SAVE_PC, PC\t\t\t// Needed for ITERN fallback.\n  |  call extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Flag returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  test RDd, RDd;  jz >3\t\t// End of traversal?\n  |  // Copy key and value to results.\n  |  mov RB, [BASE+8]\n  |  mov RD, [BASE+16]\n  |  mov [BASE-16], RB\n  |  mov [BASE-8], RD\n  |->fff_res2:\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |2:  // Set missing 2nd arg to nil.\n  |  mov aword [BASE+8], LJ_TNIL\n  |  jmp <1\n  |3:  // End of traversal: return nil.\n  |  mov aword [BASE-16], LJ_TNIL\n  |  jmp ->fff_res1\n  |\n  |.ffunc_1 pairs\n  |  mov TAB:RB, [BASE]\n  |  mov TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  mov CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], CFUNC:RD\n  |  mov [BASE-8], TMPR\n  |  mov aword [BASE], LJ_TNIL\n  |  mov RDd, 1+3\n  |  jmp ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  mov TAB:RB, [BASE]\n  |  checktab TAB:RB, ->fff_fallback\n  |.if DUALNUM\n  |  mov RA, [BASE+8]\n  |  checkint RA, ->fff_fallback\n  |.else\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  movsd xmm0, qword [BASE+8]\n  |.endif\n  |  mov PC, [BASE-8]\n  |.if DUALNUM\n  |  add RAd, 1\n  |  setint ITYPE, RA\n  |  mov [BASE-16], ITYPE\n  |.else\n  |  sseconst_1 xmm1, TMPR\n  |  addsd xmm0, xmm1\n  |  cvttsd2si RAd, xmm0\n  |  movsd qword [BASE-16], xmm0\n  |.endif\n  |  cmp RAd, TAB:RB->asize;  jae >2\t// Not in array part?\n  |  mov RD, TAB:RB->array\n  |  lea RD, [RD+RA*8]\n  |1:\n  |  cmp aword [RD], LJ_TNIL;  je ->fff_res0\n  |  // Copy array slot.\n  |  mov RB, [RD]\n  |  mov [BASE-8], RB\n  |  jmp ->fff_res2\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cmp dword TAB:RB->hmask, 0; je ->fff_res0\n  |.if X64WIN\n  |  mov TMPR, BASE\n  |  mov CARG2d, RAd\n  |  mov CARG1, TAB:RB\n  |  mov RB, TMPR\n  |.else\n  |  mov CARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, RAd\t\t\t// Caveat: CARG2 == BASE\n  |.endif\n  |  call extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RD).\n  |  mov BASE, RB\n  |  test RD, RD\n  |  jnz <1\n  |->fff_res0:\n  |  mov RDd, 1+0\n  |  jmp ->fff_res\n  |\n  |.ffunc_1 ipairs\n  |  mov TAB:RB, [BASE]\n  |  mov TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  mov CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], CFUNC:RD\n  |  mov [BASE-8], TMPR\n  |.if DUALNUM\n  |  mov64 RD, ((int64_t)LJ_TISNUM<<47)\n  |  mov [BASE], RD\n  |.else\n  |  mov qword [BASE], 0\n  |.endif\n  |  mov RDd, 1+3\n  |  jmp ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc_1 pcall\n  |  lea RA, [BASE+16]\n  |  sub NARGS:RDd, 1\n  |  mov PCd, 16+FRAME_PCALL\n  |1:\n  |  movzx RBd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  shr RB, HOOK_ACTIVE_SHIFT\n  |  and RB, 1\n  |  add PC, RB\t\t\t\t// Remember active hook before pcall.\n  |  // Note: this does a (harmless) copy of the function to the PC slot, too.\n  |  mov KBASE, RD\n  |2:\n  |  mov RB, [RA+KBASE*8-24]\n  |  mov [RA+KBASE*8-16], RB\n  |  sub KBASE, 1\n  |  ja <2\n  |  jmp ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  mov LFUNC:RA, [BASE+8]\n  |  checktp_nc LFUNC:RA, LJ_TFUNC, ->fff_fallback\n  |  mov LFUNC:RB, [BASE]\t\t// Swap function and traceback.\n  |  mov [BASE], LFUNC:RA\n  |  mov [BASE+8], LFUNC:RB\n  |  lea RA, [BASE+24]\n  |  sub NARGS:RDd, 2\n  |  mov PCd, 24+FRAME_PCALL\n  |  jmp <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  mov L:RB, [BASE]\n  |  cleartp L:RB\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  mov CFUNC:RB, [BASE-16]\n  |  cleartp CFUNC:RB\n  |  mov L:RB, CFUNC:RB->upvalue[0].gcr\n  |  cleartp L:RB\n  |.endif\n  |  mov PC, [BASE-8]\n  |  mov SAVE_PC, PC\n  |  mov TMP1, L:RB\n  |.if resume\n  |  checktptp [BASE], LJ_TTHREAD, ->fff_fallback\n  |.endif\n  |  cmp aword L:RB->cframe, 0; jne ->fff_fallback\n  |  cmp byte L:RB->status, LUA_YIELD;  ja ->fff_fallback\n  |  mov RA, L:RB->top\n  |  je >1\t\t\t\t// Status != LUA_YIELD (i.e. 0)?\n  |  cmp RA, L:RB->base\t\t\t// Check for presence of initial func.\n  |  je ->fff_fallback\n  |  mov PC, [RA-8]\t\t\t// Move initial function up.\n  |  mov [RA], PC\n  |  add RA, 8\n  |1:\n  |.if resume\n  |  lea PC, [RA+NARGS:RD*8-16]\t\t// Check stack space (-1-thread).\n  |.else\n  |  lea PC, [RA+NARGS:RD*8-8]\t\t// Check stack space (-1).\n  |.endif\n  |  cmp PC, L:RB->maxstack; ja ->fff_fallback\n  |  mov L:RB->top, PC\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if resume\n  |  add BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |.endif\n  |  mov L:RB->top, BASE\n  |.if resume\n  |  lea RB, [BASE+NARGS:RD*8-24]\t// RB = end of source for stack move.\n  |.else\n  |  lea RB, [BASE+NARGS:RD*8-16]\t// RB = end of source for stack move.\n  |.endif\n  |  sub RB, PC\t\t\t// Relative to PC.\n  |\n  |  cmp PC, RA\n  |  je >3\n  |2:  // Move args to coroutine.\n  |  mov RC, [PC+RB]\n  |  mov [PC-8], RC\n  |  sub PC, 8\n  |  cmp PC, RA\n  |  jne <2\n  |3:\n  |  mov CARG2, RA\n  |  mov CARG1, TMP1\n  |  call ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:PC, TMP1\n  |  mov BASE, L:RB->base\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |\n  |  cmp eax, LUA_YIELD\n  |  ja >8\n  |4:\n  |  mov RA, L:PC->base\n  |  mov KBASE, L:PC->top\n  |  mov L:PC->top, RA\t\t\t// Clear coroutine stack.\n  |  mov PC, KBASE\n  |  sub PC, RA\n  |  je >6\t\t\t\t// No results?\n  |  lea RD, [BASE+PC]\n  |  shr PCd, 3\n  |  cmp RD, L:RB->maxstack\n  |  ja >9\t\t\t\t// Need to grow stack?\n  |\n  |  mov RB, BASE\n  |  sub RB, RA\n  |5:  // Move results from coroutine.\n  |  mov RD, [RA]\n  |  mov [RA+RB], RD\n  |  add RA, 8\n  |  cmp RA, KBASE\n  |  jne <5\n  |6:\n  |.if resume\n  |  lea RDd, [PCd+2]\t\t\t// nresults+1 = 1 + true + results.\n  |  mov_true ITYPE\t\t\t// Prepend true to results.\n  |  mov [BASE-8], ITYPE\n  |.else\n  |  lea RDd, [PCd+1]\t\t\t// nresults+1 = 1 + results.\n  |.endif\n  |7:\n  |  mov PC, SAVE_PC\n  |  mov MULTRES, RDd\n  |.if resume\n  |  mov RA, -8\n  |.else\n  |  xor RAd, RAd\n  |.endif\n  |  test PCd, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  mov_false ITYPE\t\t\t// Prepend false to results.\n  |  mov [BASE-8], ITYPE\n  |  mov RA, L:PC->top\n  |  sub RA, 8\n  |  mov L:PC->top, RA\t\t\t// Clear error from coroutine stack.\n  |  // Copy error message.\n  |  mov RD, [RA]\n  |  mov [BASE], RD\n  |  mov RDd, 1+2\t\t\t// nresults+1 = 1 + false + error.\n  |  jmp <7\n  |.else\n  |  mov CARG2, L:PC\n  |  mov CARG1, L:RB\n  |  call extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Error function does not return.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov L:RA, TMP1\n  |  mov L:RA->top, KBASE\t\t// Undo coroutine stack clearing.\n  |  mov CARG2, PC\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov L:PC, TMP1\n  |  mov BASE, L:RB->base\n  |  jmp <4\t\t\t\t// Retry the stack move.\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  mov L:RB, SAVE_L\n  |  test aword L:RB->cframe, CFRAME_RESUME\n  |  jz ->fff_fallback\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB->top, RD\n  |  xor RDd, RDd\n  |  mov aword L:RB->cframe, RD\n  |  mov al, LUA_YIELD\n  |  mov byte L:RB->status, al\n  |  jmp ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |  .ffunc_1 math_abs\n  |  mov RB, [BASE]\n  |.if DUALNUM\n  |  checkint RB, >3\n  |  cmp RBd, 0; jns ->fff_resi\n  |  neg RBd; js >2\n  |->fff_resbit:\n  |->fff_resi:\n  |  setint RB\n  |->fff_resRB:\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |2:\n  |  mov64 RB, U64x(41e00000,00000000)  // 2^31.\n  |  jmp ->fff_resRB\n  |3:\n  |  ja ->fff_fallback\n  |.else\n  |  checknum RB, ->fff_fallback\n  |.endif\n  |  shl RB, 1\n  |  shr RB, 1\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |.ffunc_n math_sqrt, sqrtsd\n  |->fff_resxmm0:\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-16], xmm0\n  |  // fallthrough\n  |\n  |->fff_res1:\n  |  mov RDd, 1+1\n  |->fff_res:\n  |  mov MULTRES, RDd\n  |->fff_res_:\n  |  test PCd, FRAME_TYPE\n  |  jnz >7\n  |5:\n  |  cmp PC_RB, RDL\t\t\t// More results expected?\n  |  ja >6\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  movzx RAd, PC_RA\n  |  neg RA\n  |  lea BASE, [BASE+RA*8-16]\t\t// base = base - (RA+2)*8\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  mov aword [BASE+RD*8-24], LJ_TNIL\n  |  add RD, 1\n  |  jmp <5\n  |\n  |7:  // Non-standard return case.\n  |  mov RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  jmp ->vm_return\n  |\n  |.macro math_round, func\n  |  .ffunc math_ .. func\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checknumx RB, ->fff_resRB, je\n  |  ja ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  call ->vm_ .. func .. _sse\n  |.if DUALNUM\n  |  cvttsd2si RBd, xmm0\n  |  cmp RBd, 0x80000000\n  |  jne ->fff_resi\n  |  cvtsi2sd xmm1, RBd\n  |  ucomisd xmm0, xmm1\n  |  jp ->fff_resxmm0\n  |  je ->fff_resi\n  |.endif\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  cmp NARGS:RDd, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  checknumtp [BASE], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  mov RB, BASE\n  |  call extern log\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_2 math_ldexp\n  |  checknumtp [BASE], ->fff_fallback\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  fld qword [BASE+8]\n  |  fld qword [BASE]\n  |  fscale\n  |  fpop1\n  |  mov PC, [BASE-8]\n  |  fstp qword [BASE-16]\n  |  jmp ->fff_res1\n  |\n  |.ffunc_n math_frexp\n  |.if X64WIN\n  |  lea CARG2, TMP1\n  |.else\n  |  lea CARG1, TMP1\n  |.endif\n  |  mov RB, BASE\n  |  call extern frexp\n  |  mov BASE, RB\n  |  mov RBd, TMP1d\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-16], xmm0\n  |.if DUALNUM\n  |  setint RB\n  |  mov [BASE-8], RB\n  |.else\n  |  cvtsi2sd xmm1, RBd\n  |  movsd qword [BASE-8], xmm1\n  |.endif\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |\n  |.ffunc_n math_modf\n  |.if X64WIN\n  |  lea CARG2, [BASE-16]\n  |.else\n  |  lea CARG1, [BASE-16]\n  |.endif\n  |  mov PC, [BASE-8]\n  |  mov RB, BASE\n  |  call extern modf\n  |  mov BASE, RB\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-8], xmm0\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |\n  |.macro math_minmax, name, cmovop, sseop\n  |  .ffunc name\n  |  mov RAd, 2\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, >4\n  |1:  // Handle integers.\n  |  cmp RAd, RDd; jae ->fff_resRB\n  |  mov TMPR, [BASE+RA*8-8]\n  |  checkint TMPR, >3\n  |  cmp RBd, TMPRd\n  |  cmovop RB, TMPR\n  |  add RAd, 1\n  |  jmp <1\n  |3:\n  |  ja ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  cvtsi2sd xmm0, RBd\n  |  jmp >6\n  |4:\n  |  ja ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |.endif\n  |\n  |  movsd xmm0, qword [BASE]\n  |5:  // Handle numbers or integers.\n  |  cmp RAd, RDd; jae ->fff_resxmm0\n  |.if DUALNUM\n  |  mov RB, [BASE+RA*8-8]\n  |  checknumx RB, >6, jb\n  |  ja ->fff_fallback\n  |  cvtsi2sd xmm1, RBd\n  |  jmp >7\n  |.else\n  |  checknumtp [BASE+RA*8-8], ->fff_fallback\n  |.endif\n  |6:\n  |  movsd xmm1, qword [BASE+RA*8-8]\n  |7:\n  |  sseop xmm0, xmm1\n  |  add RAd, 1\n  |  jmp <5\n  |.endmacro\n  |\n  |  math_minmax math_min, cmovg, minsd\n  |  math_minmax math_max, cmovl, maxsd\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\n  |  mov STR:RB, [BASE]\n  |  checkstr STR:RB, ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  cmp dword STR:RB->len, 1\n  |  jb ->fff_res0\t\t\t// Return no results for empty string.\n  |  movzx RBd, byte STR:RB[1]\n  |.if DUALNUM\n  |  jmp ->fff_resi\n  |.else\n  |  cvtsi2sd xmm0, RBd; jmp ->fff_resxmm0\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\t// *Exactly* 1 arg.\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |  cvttsd2si RBd, qword [BASE]\n  |.endif\n  |  cmp RBd, 255;  ja ->fff_fallback\n  |  mov TMP1d, RBd\n  |  mov TMPRd, 1\n  |  lea RD, TMP1\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG3d, TMPRd\t\t\t// Zero-extended to size_t.\n  |  mov CARG2, RD\n  |  mov CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // GCstr * returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  mov PC, [BASE-8]\n  |  settp STR:RD, LJ_TSTR\n  |  mov [BASE-16], STR:RD\n  |  jmp ->fff_res1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  mov TMPRd, -1\n  |  cmp NARGS:RDd, 1+2;  jb ->fff_fallback\n  |  jna >1\n  |.if DUALNUM\n  |  mov TMPR, [BASE+16]\n  |  checkint TMPR, ->fff_fallback\n  |.else\n  |  checknumtp [BASE+16], ->fff_fallback\n  |  cvttsd2si TMPRd, qword [BASE+16]\n  |.endif\n  |1:\n  |  mov STR:RB, [BASE]\n  |  checkstr STR:RB, ->fff_fallback\n  |.if DUALNUM\n  |  mov ITYPE, [BASE+8]\n  |  mov RAd, ITYPEd\t\t\t// Must clear hiword for lea below.\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISNUM\n  |  jne ->fff_fallback\n  |.else\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  cvttsd2si RAd, qword [BASE+8]\n  |.endif\n  |  mov RCd, STR:RB->len\n  |  cmp RCd, TMPRd\t\t\t// len < end? (unsigned compare)\n  |  jb >5\n  |2:\n  |  test RAd, RAd\t\t\t// start <= 0?\n  |  jle >7\n  |3:\n  |  sub TMPRd, RAd\t\t\t// start > end?\n  |  jl ->fff_emptystr\n  |  lea RD, [STR:RB+RAd+#STR-1]\n  |  add TMPRd, 1\n  |4:\n  |  jmp ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  jl >6\n  |  lea TMPRd, [TMPRd+RCd+1]\t\t// end = end+(len+1)\n  |  jmp <2\n  |6:  // Overflow.\n  |  mov TMPRd, RCd\t\t\t// end = len\n  |  jmp <2\n  |\n  |7:  // Negative start or underflow.\n  |  je >8\n  |  add RAd, RCd\t\t\t// start = start+(len+1)\n  |  add RAd, 1\n  |  jg <3\t\t\t\t// start > 0?\n  |8:  // Underflow.\n  |  mov RAd, 1\t\t\t\t// start = 1\n  |  jmp <3\n  |\n  |->fff_emptystr:  // Range underflow.\n  |  xor TMPRd, TMPRd\t\t\t// Zero length. Any ptr in RD is ok.\n  |  jmp <4\n  |\n  |.macro ffstring_op, name\n  |  .ffunc_1 string_ .. name\n  |  ffgccheck\n  |.if X64WIN\n  |  mov STR:TMPR, [BASE]\n  |  checkstr STR:TMPR, ->fff_fallback\n  |.else\n  |  mov STR:CARG2, [BASE]\n  |  checkstr STR:CARG2, ->fff_fallback\n  |.endif\n  |  mov L:RB, SAVE_L\n  |   lea SBUF:CARG1, [DISPATCH+DISPATCH_GL(tmpbuf)]\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  mov STR:CARG2, STR:TMPR\t\t// Caveat: CARG2 == BASE\n  |.endif\n  |   mov RC, SBUF:CARG1->b\n  |   mov SBUF:CARG1->L, L:RB\n  |   mov SBUF:CARG1->p, RC\n  |  mov SAVE_PC, PC\n  |  call extern lj_buf_putstr_ .. name\n  |  mov CARG1, rax\n  |  call extern lj_buf_tostr\n  |  jmp ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name, kind, fdef\n  |  fdef name\n  |.if kind == 2\n  |  sseconst_tobit xmm1, RB\n  |.endif\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, >1\n  |.if kind > 0\n  |  jmp >2\n  |.else\n  |  jmp ->fff_resbit\n  |.endif\n  |1:\n  |  ja ->fff_fallback\n  |  movd xmm0, RB\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |.endif\n  |.if kind < 2\n  |  sseconst_tobit xmm1, RB\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RBd, xmm0\n  |2:\n  |.endmacro\n  |\n  |.macro .ffunc_bit, name, kind\n  |  .ffunc_bit name, kind, .ffunc_1\n  |.endmacro\n  |\n  |.ffunc_bit bit_tobit, 0\n  |  jmp ->fff_resbit\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name, 2\n  |  mov TMPRd, NARGS:RDd\t\t// Save for fallback.\n  |  lea RD, [BASE+NARGS:RD*8-16]\n  |1:\n  |  cmp RD, BASE\n  |  jbe ->fff_resbit\n  |.if DUALNUM\n  |  mov RA, [RD]\n  |  checkint RA, >2\n  |  ins RBd, RAd\n  |  sub RD, 8\n  |  jmp <1\n  |2:\n  |  ja ->fff_fallback_bit_op\n  |  movd xmm0, RA\n  |.else\n  |  checknumtp [RD], ->fff_fallback_bit_op\n  |  movsd xmm0, qword [RD]\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RAd, xmm0\n  |  ins RBd, RAd\n  |  sub RD, 8\n  |  jmp <1\n  |.endmacro\n  |\n  |.ffunc_bit_op bit_band, and\n  |.ffunc_bit_op bit_bor, or\n  |.ffunc_bit_op bit_bxor, xor\n  |\n  |.ffunc_bit bit_bswap, 1\n  |  bswap RBd\n  |  jmp ->fff_resbit\n  |\n  |.ffunc_bit bit_bnot, 1\n  |  not RBd\n  |.if DUALNUM\n  |  jmp ->fff_resbit\n  |.else\n  |->fff_resbit:\n  |  cvtsi2sd xmm0, RBd\n  |  jmp ->fff_resxmm0\n  |.endif\n  |\n  |->fff_fallback_bit_op:\n  |  mov NARGS:RDd, TMPRd\t\t// Restore for fallback\n  |  jmp ->fff_fallback\n  |\n  |.macro .ffunc_bit_sh, name, ins\n  |.if DUALNUM\n  |  .ffunc_bit name, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  mov RA, [BASE+8]\n  |  checkint RA, ->fff_fallback\n  |.else\n  |  .ffunc_nn name\n  |  sseconst_tobit xmm2, RB\n  |  addsd xmm0, xmm2\n  |  addsd xmm1, xmm2\n  |  movd RBd, xmm0\n  |  movd RAd, xmm1\n  |.endif\n  |  ins RBd, cl\t\t\t// Assumes RA is ecx.\n  |  jmp ->fff_resbit\n  |.endmacro\n  |\n  |.ffunc_bit_sh bit_lshift, shl\n  |.ffunc_bit_sh bit_rshift, shr\n  |.ffunc_bit_sh bit_arshift, sar\n  |.ffunc_bit_sh bit_rol, rol\n  |.ffunc_bit_sh bit_ror, ror\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback_2:\n  |  mov NARGS:RDd, 1+2\t\t\t// Other args are ignored, anyway.\n  |  jmp ->fff_fallback\n  |->fff_fallback_1:\n  |  mov NARGS:RDd, 1+1\t\t\t// Other args are ignored, anyway.\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RD = nargs+1\n  |  mov L:RB, SAVE_L\n  |  mov PC, [BASE-8]\t\t\t// Fallback may overwrite PC.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  lea RA, [RD+8*LUA_MINSTACK]\t// Ensure enough space for handler.\n  |  mov L:RB->top, RD\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  cmp RA, L:RB->maxstack\n  |  ja >5\t\t\t\t// Need to grow stack.\n  |  mov CARG1, L:RB\n  |  call aword CFUNC:RD->f\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  test RDd, RDd; jg ->fff_res\t// Returned nresults+1?\n  |1:\n  |  mov RA, L:RB->top\n  |  sub RA, BASE\n  |  shr RAd, 3\n  |  test RDd, RDd\n  |  lea NARGS:RDd, [RAd+1]\n  |  mov LFUNC:RB, [BASE-16]\n  |  jne ->vm_call_tail\t\t\t// Returned -1?\n  |  cleartp LFUNC:RB\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  mov RA, BASE\n  |  test PCd, FRAME_TYPE\n  |  jnz >3\n  |  movzx RBd, PC_RA\n  |  neg RB\n  |  lea BASE, [BASE+RB*8-16]\t\t// base = base - (RB+2)*8\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |3:\n  |  mov RB, PC\n  |  and RB, -8\n  |  sub BASE, RB\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2d, LUA_MINSTACK\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  xor RDd, RDd\t\t\t// Simulate a return 0.\n  |  jmp <1\t\t\t\t// Dumb retry (goes through ff first).\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RD = nargs+1\n  |  pop RB\t\t\t\t// Must keep stack at same level.\n  |  mov TMP1, RB\t\t\t// Save return address\n  |  mov L:RB, SAVE_L\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov CARG1, L:RB\n  |  mov L:RB->top, RD\n  |  call extern lj_gc_step\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  mov RB, TMP1\n  |  push RB\t\t\t\t// Restore return address.\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  jnz >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |  test RDL, HOOK_ACTIVE\n  |  jnz >1\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >1\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jmp >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |  jmp >1\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >5\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jz >1\n  |  test RDL, LUA_MASKLINE\n  |  jz >5\n  |1:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\t\t\t// Caveat: CARG2 == BASE\n  |  mov CARG1, L:RB\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call extern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  mov BASE, L:RB->base\n  |4:\n  |  movzx RAd, PC_RA\n  |5:\n  |  movzx OP, PC_OP\n  |  movzx RDd, PC_RD\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  add PC, 4\n  |  mov RA, [RB-40]\n  |  mov MULTRES, RAd\t\t\t// Restore MULTRES for *M ins.\n  |  jmp <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  mov LFUNC:RB, [BASE-16]\t\t// Same as curr_topL(L).\n  |  cleartp LFUNC:RB\n  |  mov RB, LFUNC:RB->pc\n  |  movzx RDd, byte [RB+PC2PROTO(framesize)]\n  |  lea RD, [BASE+RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov CARG2, PC\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  jmp <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov SAVE_PC, PC\n  |.if JIT\n  |  jmp >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  mov SAVE_PC, PC\n  |  or PC, 1\t\t\t\t// Marker for hot call.\n  |1:\n  |.endif\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov CARG2, PC\n  |  mov CARG1, L:RB\n  |  call extern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |  // ASMFunction returned in eax/rax (RD).\n  |  mov SAVE_PC, 0\t\t\t// Invalidate for subsequent line hook.\n  |.if JIT\n  |  and PC, -2\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov RA, RD\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  mov RB, RA\n  |  movzx RAd, PC_RA\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  jmp RB\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // BASE = base, RC = result, RB = mbase\n  |  mov ITYPEd, [RB-24]\t\t// Save previous trace number.\n  |  mov TMPRd, MULTRES\n  |  movzx RAd, PC_RA\n  |  lea RA, [BASE+RA*8]\t\t// Call base.\n  |  sub TMPRd, 1\n  |  jz >2\n  |1:  // Move results down.\n  |  mov RB, [RC]\n  |  mov [RA], RB\n  |  add RC, 8\n  |  add RA, 8\n  |  sub TMPRd, 1\n  |  jnz <1\n  |2:\n  |  movzx RCd, PC_RA\n  |  movzx RBd, PC_RB\n  |  add RC, RB\n  |  lea RC, [BASE+RC*8-8]\n  |3:\n  |  cmp RC, RA\n  |  ja >9\t\t\t\t// More results wanted?\n  |\n  |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n  |  mov TRACE:RD, [RA+ITYPE*8]\n  |  test TRACE:RD, TRACE:RD\n  |  jz ->cont_nop\n  |  movzx RDd, word TRACE:RD->link\n  |  cmp RDd, RBd\n  |  je ->cont_nop\t\t\t// Blacklisted.\n  |  test RDd, RDd\n  |  jne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  call extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  jmp ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  mov aword [RA], LJ_TNIL\n  |  add RA, 8\n  |  jmp <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\t\t\t// Caveat: CARG2 == BASE\n  |  mov CARG1, L:RB\n  |  call extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  sub PC, 4\n  |  jmp ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Called from an exit stub with the exit number on the stack.\n  |// The 16 bit exit number is stored with two (sign-extended) push imm8.\n  |->vm_exit_handler:\n  |.if JIT\n  |  push r13; push r12\n  |  push r11; push r10; push r9; push r8\n  |  push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp\n  |  push rbx; push rdx; push rcx; push rax\n  |  movzx RCd, byte [rbp-8]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [rbp-16]\n  |  mov [rbp-8], r15; mov [rbp-16], r14\n  |  // Caveat: DISPATCH is rbx.\n  |  mov DISPATCH, [ebp]\n  |  mov RA, [DISPATCH+DISPATCH_GL(vmstate)]\t// Get trace number.\n  |  set_vmstate EXIT\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RC\n  |  mov [DISPATCH+DISPATCH_J(parent)], RA\n  |.if X64WIN\n  |  sub rsp, 16*8+4*8\t\t\t// Room for SSE regs + save area.\n  |.else\n  |  sub rsp, 16*8\t\t\t// Room for SSE regs.\n  |.endif\n  |  add rbp, -128\n  |  movsd qword [rbp-8],   xmm15; movsd qword [rbp-16],  xmm14\n  |  movsd qword [rbp-24],  xmm13; movsd qword [rbp-32],  xmm12\n  |  movsd qword [rbp-40],  xmm11; movsd qword [rbp-48],  xmm10\n  |  movsd qword [rbp-56],  xmm9;  movsd qword [rbp-64],  xmm8\n  |  movsd qword [rbp-72],  xmm7;  movsd qword [rbp-80],  xmm6\n  |  movsd qword [rbp-88],  xmm5;  movsd qword [rbp-96],  xmm4\n  |  movsd qword [rbp-104], xmm3;  movsd qword [rbp-112], xmm2\n  |  movsd qword [rbp-120], xmm1;  movsd qword [rbp-128], xmm0\n  |  // Caveat: RB is rbp.\n  |  mov L:RB, [DISPATCH+DISPATCH_GL(cur_L)]\n  |  mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  lea CARG2, [rsp+4*8]\n  |.else\n  |  mov CARG2, rsp\n  |.endif\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  call extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // MULTRES or negated error code returned in eax (RD).\n  |  mov RA, L:RB->cframe\n  |  and RA, CFRAME_RAWMASK\n  |  mov [RA+CFRAME_OFS_L], L:RB\t// Set SAVE_L (on-trace resume/yield).\n  |  mov BASE, L:RB->base\n  |  mov PC, [RA+CFRAME_OFS_PC]\t// Get SAVE_PC.\n  |  jmp >1\n  |.endif\n  |->vm_exit_interp:\n  |  // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |  // Restore additional callee-save registers only used in compiled code.\n  |.if X64WIN\n  |  lea RA, [rsp+10*16+4*8]\n  |1:\n  |  movdqa xmm15, [RA-10*16]\n  |  movdqa xmm14, [RA-9*16]\n  |  movdqa xmm13, [RA-8*16]\n  |  movdqa xmm12, [RA-7*16]\n  |  movdqa xmm11, [RA-6*16]\n  |  movdqa xmm10, [RA-5*16]\n  |  movdqa xmm9, [RA-4*16]\n  |  movdqa xmm8, [RA-3*16]\n  |  movdqa xmm7, [RA-2*16]\n  |  mov rsp, RA\t\t\t// Reposition stack to C frame.\n  |  movdqa xmm6, [RA-1*16]\n  |  mov r15, CSAVE_1\n  |  mov r14, CSAVE_2\n  |  mov r13, CSAVE_3\n  |  mov r12, CSAVE_4\n  |.else\n  |  lea RA, [rsp+16]\n  |1:\n  |  mov r13, [RA-8]\n  |  mov r12, [RA]\n  |  mov rsp, RA\t\t\t// Reposition stack to C frame.\n  |.endif\n  |  test RDd, RDd; js >9\t\t// Check for error from exit.\n  |  mov L:RB, SAVE_L\n  |  mov MULTRES, RDd\n  |  mov LFUNC:KBASE, [BASE-16]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  mov L:RB->base, BASE\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  set_vmstate INTERP\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  mov RCd, [PC]\n  |  movzx RAd, RCH\n  |  movzx OP, RCL\n  |  add PC, 4\n  |  shr RCd, 16\n  |  cmp OP, BC_FUNCF\t\t\t// Function header?\n  |  jb >3\n  |  cmp OP, BC_FUNCC+2\t\t\t// Fast function?\n  |  jae >4\n  |2:\n  |  mov RCd, MULTRES\t\t\t// RC/RD holds nres+1.\n  |3:\n  |  jmp aword [DISPATCH+OP*8]\n  |\n  |4:  // Check frame below fast function.\n  |  mov RC, [BASE-8]\n  |  test RCd, FRAME_TYPE\n  |  jnz <2\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  movzx RCd, byte [RC-3]\n  |  neg RC\n  |  mov LFUNC:KBASE, [BASE+RC*8-24]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  jmp <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  neg RD\n  |  mov CARG1, L:RB\n  |  mov CARG2, RD\n  |  call extern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called by math.floor/math.ceil fast functions\n  |// and from JIT code. arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.\n  |.macro vm_round, name, mode, cond\n  |->name:\n  |->name .. _sse:\n  |  sseconst_abs xmm2, RD\n  |  sseconst_2p52 xmm3, RD\n  |  movaps xmm1, xmm0\n  |  andpd xmm1, xmm2\t\t\t// |x|\n  |  ucomisd xmm3, xmm1\t\t\t// No truncation if 2^52 <= |x|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |.if mode == 2\t\t// trunc(x)?\n  |  movaps xmm0, xmm1\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  sseconst_1 xmm3, RD\n  |  cmpsd xmm0, xmm1, 1\t\t// |x| < result?\n  |  andpd xmm0, xmm3\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract -1.\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |.else\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |  .if mode == 1\t\t// ceil(x)?\n  |    sseconst_m1 xmm2, RD\t\t// Must subtract -1 to preserve -0.\n  |    cmpsd xmm0, xmm1, 6\t\t// x > result?\n  |  .else\t\t\t// floor(x)?\n  |    sseconst_1 xmm2, RD\n  |    cmpsd xmm0, xmm1, 1\t\t// x < result?\n  |  .endif\n  |  andpd xmm0, xmm2\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract +-1.\n  |.endif\n  |  movaps xmm0, xmm1\n  |1:\n  |  ret\n  |.endmacro\n  |\n  |  vm_round vm_floor, 0, 1\n  |  vm_round vm_ceil,  1, JIT\n  |  vm_round vm_trunc, 2, JIT\n  |\n  |// FP modulo x%y. Called by BC_MOD* and vm_arith.\n  |->vm_mod:\n  |// Args in xmm0/xmm1, return value in xmm0.\n  |// Caveat: xmm0-xmm5 and RC (eax) modified!\n  |  movaps xmm5, xmm0\n  |  divsd xmm0, xmm1\n  |  sseconst_abs xmm2, RD\n  |  sseconst_2p52 xmm3, RD\n  |  movaps xmm4, xmm0\n  |  andpd xmm4, xmm2\t\t\t// |x/y|\n  |  ucomisd xmm3, xmm4\t\t\t// No truncation if 2^52 <= |x/y|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |  addsd xmm4, xmm3\t\t\t// (|x/y| + 2^52) - 2^52\n  |  subsd xmm4, xmm3\n  |  orpd xmm4, xmm2\t\t\t// Merge sign bit back in.\n  |  sseconst_1 xmm2, RD\n  |  cmpsd xmm0, xmm4, 1\t\t// x/y < result?\n  |  andpd xmm0, xmm2\n  |  subsd xmm4, xmm0\t\t\t// If yes, subtract 1.0.\n  |  movaps xmm0, xmm5\n  |  mulsd xmm1, xmm4\n  |  subsd xmm0, xmm1\n  |  ret\n  |1:\n  |  mulsd xmm1, xmm0\n  |  movaps xmm0, xmm5\n  |  subsd xmm0, xmm1\n  |  ret\n  |\n  |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.\n  |->vm_powi_sse:\n  |  cmp eax, 1; jle >6\t\t\t// i<=1?\n  |  // Now 1 < (unsigned)i <= 0x80000000.\n  |1:  // Handle leading zeros.\n  |  test eax, 1; jnz >2\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1\n  |  jmp <1\n  |2:\n  |  shr eax, 1; jz >5\n  |  movaps xmm1, xmm0\n  |3:  // Handle trailing bits.\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1; jz >4\n  |  jnc <3\n  |  mulsd xmm1, xmm0\n  |  jmp <3\n  |4:\n  |  mulsd xmm0, xmm1\n  |5:\n  |  ret\n  |6:\n  |  je <5\t\t\t\t// x^1 ==> x\n  |  jb >7\t\t\t\t// x^0 ==> 1\n  |  neg eax\n  |  call <1\n  |  sseconst_1 xmm1, RD\n  |  divsd xmm1, xmm0\n  |  movaps xmm0, xmm1\n  |  ret\n  |7:\n  |  sseconst_1 xmm0, RD\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])\n  |->vm_cpuid:\n  |  mov eax, CARG1d\n  |  .if X64WIN; push rsi; mov rsi, CARG2; .endif\n  |  push rbx\n  |  cpuid\n  |  mov [rsi], eax\n  |  mov [rsi+4], ebx\n  |  mov [rsi+8], ecx\n  |  mov [rsi+12], edx\n  |  pop rbx\n  |  .if X64WIN; pop rsi; .endif\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Assertions ---------------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->assert_bad_for_arg_type:\n#ifdef LUA_USE_ASSERT\n  |  int3\n#endif\n  |  int3\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in ah/al.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs_\t// ebp/rbp already saved. ebp now holds global_State *.\n  |  lea DISPATCH, [ebp+GG_G2DISP]\n  |  mov CTSTATE, GL:ebp->ctype_state\n  |  movzx eax, ax\n  |  mov CTSTATE->cb.slot, eax\n  |  mov CTSTATE->cb.gpr[0], CARG1\n  |  mov CTSTATE->cb.gpr[1], CARG2\n  |  mov CTSTATE->cb.gpr[2], CARG3\n  |  mov CTSTATE->cb.gpr[3], CARG4\n  |  movsd qword CTSTATE->cb.fpr[0], xmm0\n  |  movsd qword CTSTATE->cb.fpr[1], xmm1\n  |  movsd qword CTSTATE->cb.fpr[2], xmm2\n  |  movsd qword CTSTATE->cb.fpr[3], xmm3\n  |.if X64WIN\n  |  lea rax, [rsp+CFRAME_SIZE+4*8]\n  |.else\n  |  lea rax, [rsp+CFRAME_SIZE]\n  |  mov CTSTATE->cb.gpr[4], CARG5\n  |  mov CTSTATE->cb.gpr[5], CARG6\n  |  movsd qword CTSTATE->cb.fpr[4], xmm4\n  |  movsd qword CTSTATE->cb.fpr[5], xmm5\n  |  movsd qword CTSTATE->cb.fpr[6], xmm6\n  |  movsd qword CTSTATE->cb.fpr[7], xmm7\n  |.endif\n  |  mov CTSTATE->cb.stack, rax\n  |  mov CARG2, rsp\n  |  mov SAVE_PC, CTSTATE\t\t// Any value outside of bytecode is ok.\n  |  mov CARG1, CTSTATE\n  |  call extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // lua_State * returned in eax (RD).\n  |  set_vmstate INTERP\n  |  mov BASE, L:RD->base\n  |  mov RD, L:RD->top\n  |  sub RD, BASE\n  |  mov LFUNC:RB, [BASE-16]\n  |  cleartp LFUNC:RB\n  |  shr RD, 3\n  |  add RD, 1\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  mov L:RA, SAVE_L\n  |  mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]\n  |  mov aword CTSTATE->L, L:RA\n  |  mov L:RA->base, BASE\n  |  mov L:RA->top, RB\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RC\n  |  call extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  mov rax, CTSTATE->cb.gpr[0]\n  |  movsd xmm0, qword CTSTATE->cb.fpr[0]\n  |  jmp ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, rbx\n  |  push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1\n  |\n  |  // Readjust stack.\n  |  mov eax, CCSTATE->spadj\n  |  sub rsp, rax\n  |\n  |  // Copy stack slots.\n  |  movzx ecx, byte CCSTATE->nsp\n  |  sub ecx, 1\n  |  js >2\n  |1:\n  |  mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]\n  |  mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax\n  |  sub ecx, 1\n  |  jns <1\n  |2:\n  |\n  |  movzx eax, byte CCSTATE->nfpr\n  |  mov CARG1, CCSTATE->gpr[0]\n  |  mov CARG2, CCSTATE->gpr[1]\n  |  mov CARG3, CCSTATE->gpr[2]\n  |  mov CARG4, CCSTATE->gpr[3]\n  |.if not X64WIN\n  |  mov CARG5, CCSTATE->gpr[4]\n  |  mov CARG6, CCSTATE->gpr[5]\n  |.endif\n  |  test eax, eax; jz >5\n  |  movaps xmm0, CCSTATE->fpr[0]\n  |  movaps xmm1, CCSTATE->fpr[1]\n  |  movaps xmm2, CCSTATE->fpr[2]\n  |  movaps xmm3, CCSTATE->fpr[3]\n  |.if not X64WIN\n  |  cmp eax, 4; jbe >5\n  |  movaps xmm4, CCSTATE->fpr[4]\n  |  movaps xmm5, CCSTATE->fpr[5]\n  |  movaps xmm6, CCSTATE->fpr[6]\n  |  movaps xmm7, CCSTATE->fpr[7]\n  |.endif\n  |5:\n  |\n  |  call aword CCSTATE->func\n  |\n  |  mov CCSTATE->gpr[0], rax\n  |  movaps CCSTATE->fpr[0], xmm0\n  |.if not X64WIN\n  |  mov CCSTATE->gpr[1], rdx\n  |  movaps CCSTATE->fpr[1], xmm1\n  |.endif\n  |\n  |  mov rbx, [rbp-8]; leave; ret\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |// Note: aligning all instructions does not pay off.\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  |.macro jmp_comp, lt, ge, le, gt, target\n  ||switch (op) {\n  ||case BC_ISLT:\n  |   lt target\n  ||break;\n  ||case BC_ISGE:\n  |   ge target\n  ||break;\n  ||case BC_ISLE:\n  |   le target\n  ||break;\n  ||case BC_ISGT:\n  |   gt target\n  ||break;\n  ||default: break;  /* Shut up GCC. */\n  ||}\n  |.endmacro\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RD = src2, JMP with RD = target\n    |  ins_AD\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov RB, [BASE+RD*8]\n    |  mov RA, ITYPE\n    |  mov RD, RB\n    |  sar ITYPE, 47\n    |  sar RB, 47\n    |.if DUALNUM\n    |  cmp ITYPEd, LJ_TISNUM; jne >7\n    |  cmp RBd, LJ_TISNUM; jne >8\n    |  add PC, 4\n    |  cmp RAd, RDd\n    |  jmp_comp jge, jl, jg, jle, >9\n    |6:\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is a number.\n    |  cmp RBd, LJ_TISNUM; jb >1; jne ->vmeta_comp\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, RDd\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm1, RAd\n    |  movd xmm0, RD\n    |  jmp >3\n    |.else\n    |  cmp ITYPEd, LJ_TISNUM; jae ->vmeta_comp\n    |  cmp RBd, LJ_TISNUM; jae ->vmeta_comp\n    |.endif\n    |1:\n    |  movd xmm0, RD\n    |2:\n    |  movd xmm1, RA\n    |3:\n    |  add PC, 4\n    |  ucomisd xmm0, xmm1\n    |  // Unordered: all of ZF CF PF set, ordered: PF clear.\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    |.if DUALNUM\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  jmp_comp jbe, ja, jb, jae, >1\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  ins_AD\t// RA = src1, RD = src2, JMP with RD = target\n    |  mov RB, [BASE+RD*8]\n    |  mov ITYPE, [BASE+RA*8]\n    |  add PC, 4\n    |  mov RD, RB\n    |  mov RA, ITYPE\n    |  sar RB, 47\n    |  sar ITYPE, 47\n    |.if DUALNUM\n    |  cmp RBd, LJ_TISNUM; jne >7\n    |  cmp ITYPEd, LJ_TISNUM; jne >8\n    |  cmp RDd, RAd\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RD is not an integer.\n    |  ja >5\n    |  // RD is a number.\n    |  movd xmm1, RD\n    |  cmp ITYPEd, LJ_TISNUM; jb >1; jne >5\n    |  // RD is a number, RA is an integer.\n    |  cvtsi2sd xmm0, RAd\n    |  jmp >2\n    |\n    |8:  // RD is an integer, RA is not an integer.\n    |  ja >5\n    |  // RD is an integer, RA is a number.\n    |  cvtsi2sd xmm1, RDd\n    |  jmp >1\n    |\n    |.else\n    |  cmp RBd, LJ_TISNUM; jae >5\n    |  cmp ITYPEd, LJ_TISNUM; jae >5\n    |  movd xmm1, RD\n    |.endif\n    |1:\n    |  movd xmm0, RA\n    |2:\n    |  ucomisd xmm0, xmm1\n    |4:\n  iseqne_fp:\n    if (vk) {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  jne >2\n    } else {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  je >1\n    }\n  iseqne_end:\n    if (vk) {\n      |1:\t\t\t\t// EQ: Branch to the target.\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\t\t\t\t// NE: Fallthrough to next instruction.\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |.if not FFI\n      |3:\n      |.endif\n      |2:\t\t\t\t// NE: Branch to the target.\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |1:\t\t\t\t// EQ: Fallthrough to next instruction.\n    }\n    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||\n\t\t       op == BC_ISEQN || op == BC_ISNEN)) {\n      |  jmp <9\n    } else {\n      |  ins_next\n    }\n    |\n    if (op == BC_ISEQV || op == BC_ISNEV) {\n      |5:  // Either or both types are not numbers.\n      |.if FFI\n      |  cmp RBd, LJ_TCDATA; je ->vmeta_equal_cd\n      |  cmp ITYPEd, LJ_TCDATA; je ->vmeta_equal_cd\n      |.endif\n      |  cmp RA, RD\n      |  je <1\t\t\t\t// Same GCobjs or pvalues?\n      |  cmp RBd, ITYPEd\n      |  jne <2\t\t\t\t// Not the same type?\n      |  cmp RBd, LJ_TISTABUD\n      |  ja <2\t\t\t\t// Different objects and not table/ud?\n      |\n      |  // Different tables or userdatas. Need to check __eq metamethod.\n      |  // Field metatable must be at same offset for GCtab and GCudata!\n      |  cleartp TAB:RA\n      |  mov TAB:RB, TAB:RA->metatable\n      |  test TAB:RB, TAB:RB\n      |  jz <2\t\t\t\t// No metatable?\n      |  test byte TAB:RB->nomm, 1<<MM_eq\n      |  jnz <2\t\t\t\t// Or 'no __eq' flag set?\n      if (vk) {\n\t|  xor RBd, RBd\t\t\t// ne = 0\n      } else {\n\t|  mov RBd, 1\t\t\t// ne = 1\n      }\n      |  jmp ->vmeta_equal\t\t// Handle __eq metamethod.\n    } else {\n      |.if FFI\n      |3:\n      |  cmp ITYPEd, LJ_TCDATA\n      if (LJ_DUALNUM && vk) {\n\t|  jne <9\n      } else {\n\t|  jne <2\n      }\n      |  jmp ->vmeta_equal_cd\n      |.endif\n    }\n    break;\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  ins_AND\t// RA = src, RD = str const, JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  add PC, 4\n    |  checkstr RB, >3\n    |  cmp RB, [KBASE+RD*8]\n  iseqne_test:\n    if (vk) {\n      |  jne >2\n    } else {\n      |  je >1\n    }\n    goto iseqne_end;\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  ins_AD\t// RA = src, RD = num const, JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  add PC, 4\n    |.if DUALNUM\n    |  checkint RB, >7\n    |  mov RD, [KBASE+RD*8]\n    |  checkint RD, >8\n    |  cmp RBd, RDd\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja >3\n    |  // RA is a number.\n    |  mov RD, [KBASE+RD*8]\n    |  checkint RD, >1\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, RDd\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm0, RBd\n    |  movd xmm1, RD\n    |  ucomisd xmm0, xmm1\n    |  jmp >4\n    |1:\n    |  movd xmm0, RD\n    |.else\n    |  checknum RB, >3\n    |1:\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |.endif\n    |2:\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |4:\n    goto iseqne_fp;\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  ins_AND\t// RA = src, RD = primitive type (~), JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  sar RB, 47\n    |  add PC, 4\n    |  cmp RBd, RDd\n    if (!LJ_HASFFI) goto iseqne_test;\n    if (vk) {\n      |  jne >3\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n      |3:\n      |  cmp RBd, LJ_TCDATA; jne <2\n      |  jmp ->vmeta_equal_cd\n    } else {\n      |  je >2\n      |  cmp RBd, LJ_TCDATA; je ->vmeta_equal_cd\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  ins_AD\t// RA = dst or unused, RD = src, JMP with RD = target\n    |  mov ITYPE, [BASE+RD*8]\n    |  add PC, 4\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov RB, ITYPE\n    }\n    |  sar ITYPE, 47\n    |  cmp ITYPEd, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISTC) {\n      |  jae >1\n    } else {\n      |  jb >1\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov [BASE+RA*8], RB\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |1:\t\t\t\t\t// Fallthrough to the next instruction.\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  ins_AD\t// RA = src, RD = -type\n    |  mov RB, [BASE+RA*8]\n    |  sar RB, 47\n    |  add RBd, RDd\n    |  jne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  ins_AD\t// RA = src, RD = -(TISNUM-1)\n    |  checknumtp [BASE+RA*8], ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |  mov [BASE+RA*8], RB\n    |  ins_next_\n    break;\n  case BC_NOT:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |  sar RB, 47\n    |  mov RCd, 2\n    |  cmp RB, LJ_TISTRUECOND\n    |  sbb RCd, 0\n    |  shl RC, 47\n    |  not RC\n    |  mov [BASE+RA*8], RC\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |.if DUALNUM\n    |  checkint RB, >5\n    |  neg RBd\n    |  jo >4\n    |  setint RB\n    |9:\n    |  mov [BASE+RA*8], RB\n    |  ins_next\n    |4:\n    |  mov64 RB, U64x(41e00000,00000000)  // 2^31.\n    |  jmp <9\n    |5:\n    |  ja ->vmeta_unm\n    |.else\n    |  checknum RB, ->vmeta_unm\n    |.endif\n    |  mov64 RD, U64x(80000000,00000000)\n    |  xor RB, RD\n    |.if DUALNUM\n    |  jmp <9\n    |.else\n    |  mov [BASE+RA*8], RB\n    |  ins_next\n    |.endif\n    break;\n  case BC_LEN:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RD, [BASE+RD*8]\n    |  checkstr RD, >2\n    |.if DUALNUM\n    |  mov RDd, dword STR:RD->len\n    |1:\n    |  setint RD\n    |  mov [BASE+RA*8], RD\n    |.else\n    |  xorps xmm0, xmm0\n    |  cvtsi2sd xmm0, dword STR:RD->len\n    |1:\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    |2:\n    |  cmp ITYPEd, LJ_TTAB; jne ->vmeta_len\n    |  mov TAB:CARG1, TAB:RD\n#if LJ_52\n    |  mov TAB:RB, TAB:RD->metatable\n    |  cmp TAB:RB, 0\n    |  jnz >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |  call extern lj_tab_len\t\t// (GCtab *t)\n    |  // Length of table returned in eax (RD).\n    |.if DUALNUM\n    |  // Nothing to do.\n    |.else\n    |  cvtsi2sd xmm0, RDd\n    |.endif\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  movzx RAd, PC_RA\n    |  jmp <1\n#if LJ_52\n    |9:  // Check for __len.\n    |  test byte TAB:RB->nomm, 1<<MM_len\n    |  jnz <3\n    |  jmp ->vmeta_len\t\t\t// 'no __len' flag NOT set: check.\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre, sseins, ssereg\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_vn\n    |   .if DUALNUM\n    |     checknumtp [KBASE+RC*8], ->vmeta_arith_vn\n    |   .endif\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [KBASE+RC*8]\n    ||  break;\n    ||case 1:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_nv\n    |   .if DUALNUM\n    |     checknumtp [KBASE+RC*8], ->vmeta_arith_nv\n    |   .endif\n    |   movsd xmm0, qword [KBASE+RC*8]\n    |   sseins ssereg, qword [BASE+RB*8]\n    ||  break;\n    ||default:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_vv\n    |   checknumtp [BASE+RC*8], ->vmeta_arith_vv\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [BASE+RC*8]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [KBASE+RC*8]\n    |   checkint RB, ->vmeta_arith_vno\n    |   checkint RC, ->vmeta_arith_vno\n    |   intins RBd, RCd; jo ->vmeta_arith_vno\n    ||  break;\n    ||case 1:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [KBASE+RC*8]\n    |   checkint RB, ->vmeta_arith_nvo\n    |   checkint RC, ->vmeta_arith_nvo\n    |   intins RCd, RBd; jo ->vmeta_arith_nvo\n    ||  break;\n    ||default:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [BASE+RC*8]\n    |   checkint RB, ->vmeta_arith_vvo\n    |   checkint RC, ->vmeta_arith_vvo\n    |   intins RBd, RCd; jo ->vmeta_arith_vvo\n    ||  break;\n    ||}\n    ||if (vk == 1) {\n    |   setint RC\n    |   mov [BASE+RA*8], RC\n    ||} else {\n    |   setint RB\n    |   mov [BASE+RA*8], RB\n    ||}\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arithpost\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endmacro\n    |\n    |.macro ins_arith, sseins\n    |  ins_arithpre sseins, xmm0\n    |  ins_arithpost\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arith, intins, sseins\n    |.if DUALNUM\n    |  ins_arithdn intins\n    |.else\n    |  ins_arith, sseins\n    |.endif\n    |.endmacro\n\n    |  // RA = dst, RB = src1 or num const, RC = src2 or num const\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith add, addsd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith sub, subsd\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith imul, mulsd\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arith divsd\n    break;\n  case BC_MODVN:\n    |  ins_arithpre movsd, xmm1\n    |->BC_MODVN_Z:\n    |  call ->vm_mod\n    |  ins_arithpost\n    |  ins_next\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre movsd, xmm1\n    |  jmp ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    break;\n  case BC_POW:\n    |  ins_arithpre movsd, xmm1\n    |  mov RB, BASE\n    |  call extern pow\n    |  movzx RAd, PC_RA\n    |  mov BASE, RB\n    |  ins_arithpost\n    |  ins_next\n    break;\n\n  case BC_CAT:\n    |  ins_ABC\t// RA = dst, RB = src_start, RC = src_end\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\n    |  lea CARG2, [BASE+RC*8]\n    |  mov CARG3d, RCd\n    |  sub CARG3d, RBd\n    |->BC_CAT_Z:\n    |  mov L:RB, L:CARG1\n    |  mov SAVE_PC, PC\n    |  call extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  test RC, RC\n    |  jnz ->vmeta_binop\n    |  movzx RBd, PC_RB\t\t\t// Copy result to Stk[RA] from Stk[RB].\n    |  movzx RAd, PC_RA\n    |  mov RC, [BASE+RB*8]\n    |  mov [BASE+RA*8], RC\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov RD, [KBASE+RD*8]\n    |  settp RD, LJ_TSTR\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  ins_AND\t// RA = dst, RD = cdata const (~)\n    |  mov RD, [KBASE+RD*8]\n    |  settp RD, LJ_TCDATA\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  ins_AD\t// RA = dst, RD = signed int16 literal\n    |.if DUALNUM\n    |  movsx RDd, RDW\n    |  setint RD\n    |  mov [BASE+RA*8], RD\n    |.else\n    |  movsx RDd, RDW\t\t\t// Sign-extend literal.\n    |  cvtsi2sd xmm0, RDd\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  ins_AD\t// RA = dst, RD = num const\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  movsd qword [BASE+RA*8], xmm0\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  ins_AD\t// RA = dst, RD = primitive type (~)\n    |  shl RD, 47\n    |  not RD\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  ins_AD\t// RA = dst_start, RD = dst_end\n    |  lea RA, [BASE+RA*8+8]\n    |  lea RD, [BASE+RD*8]\n    |  mov RB, LJ_TNIL\n    |  mov [RA-8], RB\t\t\t// Sets minimum 2 slots.\n    |1:\n    |  mov [RA], RB\n    |  add RA, 8\n    |  cmp RA, RD\n    |  jbe <1\n    |  ins_next\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  ins_AD\t// RA = dst, RD = upvalue #\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RD*8+offsetof(GCfuncL, uvptr)]\n    |  mov RB, UPVAL:RB->v\n    |  mov RD, [RB]\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_USETV:\n#define TV2MARKOFS \\\n ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))\n    |  ins_AD\t// RA = upvalue #, RD = src\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  cmp byte UPVAL:RB->closed, 0\n    |  mov RB, UPVAL:RB->v\n    |  mov RA, [BASE+RD*8]\n    |  mov [RB], RA\n    |  jz >1\n    |  // Check barrier for closed upvalue.\n    |  test byte [RB+TV2MARKOFS], LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Upvalue is black. Check if new value is collectable and white.\n    |  mov RD, RA\n    |  sar RD, 47\n    |  sub RDd, LJ_TISGCV\n    |  cmp RDd, LJ_TNUMX - LJ_TISGCV\t\t\t// tvisgcv(v)\n    |  jbe <1\n    |  cleartp GCOBJ:RA\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(v)\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if not X64WIN\n    |  mov CARG2, RB\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |.else\n    |  xchg CARG2, RB\t\t\t// Save BASE (CARG2 == BASE).\n    |.endif\n    |  lea GL:CARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n#undef TV2MARKOFS\n  case BC_USETS:\n    |  ins_AND\t// RA = upvalue #, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  mov STR:RA, [KBASE+RD*8]\n    |  mov RD, UPVAL:RB->v\n    |  settp STR:ITYPE, STR:RA, LJ_TSTR\n    |  mov [RD], STR:ITYPE\n    |  test byte UPVAL:RB->marked, LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(str)\n    |  jz <1\n    |  cmp byte UPVAL:RB->closed, 0\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov RB, BASE\t\t\t// Save BASE (CARG2 == BASE).\n    |  mov CARG2, RD\n    |  lea GL:CARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n  case BC_USETN:\n    |  ins_AD\t// RA = upvalue #, RD = num const\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  movsd qword [RA], xmm0\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  ins_AD\t// RA = upvalue #, RD = primitive type (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  shl RD, 47\n    |  not RD\n    |  mov RA, UPVAL:RB->v\n    |  mov [RA], RD\n    |  ins_next\n    break;\n  case BC_UCLO:\n    |  ins_AD\t// RA = level, RD = target\n    |  branchPC RD\t\t\t// Do this first to free RD.\n    |  mov L:RB, SAVE_L\n    |  cmp dword L:RB->openupval, 0\n    |  je >1\n    |  mov L:RB->base, BASE\n    |  lea CARG2, [BASE+RA*8]\t\t// Caveat: CARG2 == BASE\n    |  mov L:CARG1, L:RB\t\t// Caveat: CARG1 == RA\n    |  call extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  mov BASE, L:RB->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  ins_AND\t// RA = dst, RD = proto const (~) (holding function prototype)\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n    |  mov CARG3, [BASE-16]\n    |  cleartp CARG3\n    |  mov CARG2, [KBASE+RD*8]\t\t// Fetch GCproto *.\n    |  mov CARG1, L:RB\n    |  mov SAVE_PC, PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call extern lj_func_newL_gc\n    |  // GCfuncL * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp LFUNC:RC, LJ_TFUNC\n    |  mov [BASE+RA*8], LFUNC:RC\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n    |  ins_AD\t// RA = dst, RD = hbits|asize\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov SAVE_PC, PC\n    |  jae >5\n    |1:\n    |  mov CARG3d, RDd\n    |  and RDd, 0x7ff\n    |  shr CARG3d, 11\n    |  cmp RDd, 0x7ff\n    |  je >3\n    |2:\n    |  mov L:CARG1, L:RB\n    |  mov CARG2d, RDd\n    |  call extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp TAB:RC, LJ_TTAB\n    |  mov [BASE+RA*8], TAB:RC\n    |  ins_next\n    |3:  // Turn 0x7ff into 0x801.\n    |  mov RDd, 0x801\n    |  jmp <2\n    |5:\n    |  mov L:CARG1, L:RB\n    |  call extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  movzx RDd, PC_RD\n    |  jmp <1\n    break;\n  case BC_TDUP:\n    |  ins_AND\t// RA = dst, RD = table const (~) (holding template table)\n    |  mov L:RB, SAVE_L\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  mov SAVE_PC, PC\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov L:RB->base, BASE\n    |  jae >3\n    |2:\n    |  mov TAB:CARG2, [KBASE+RD*8]\t// Caveat: CARG2 == BASE\n    |  mov L:CARG1, L:RB\t\t// Caveat: CARG1 == RA\n    |  call extern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp TAB:RC, LJ_TTAB\n    |  mov [BASE+RA*8], TAB:RC\n    |  ins_next\n    |3:\n    |  mov L:CARG1, L:RB\n    |  call extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  movzx RDd, PC_RD\t\t\t// Need to reload RD.\n    |  not RD\n    |  jmp <2\n    break;\n\n  case BC_GGET:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*8]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_GSET:\n    |  ins_AND\t// RA = src, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*8]\n    |  jmp ->BC_TSETS_Z\n    break;\n\n  case BC_TGETV:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  mov RC, [BASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tgetv\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movd xmm0, RC\n    |  cvttsd2si RCd, xmm0\n    |  cvtsi2sd xmm1, RCd\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tgetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RCd, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tgetv\t\t// Not in array part? Use fallback.\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |  mov ITYPE, [RC]\n    |  cmp ITYPE, LJ_TNIL\t\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |1:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetv\t\t\t// 'no __index' flag NOT set: check.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  cmp ITYPEd, LJ_TSTR; jne ->vmeta_tgetv\n    |  cleartp STR:RC\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  ins_ABC\t// RA = dst, RB = table, RC = str const (~)\n    |  mov TAB:RB, [BASE+RB*8]\n    |  not RC\n    |  mov STR:RC, [KBASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tgets\n    |->BC_TGETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  mov TMPRd, TAB:RB->hmask\n    |  and TMPRd, STR:RC->hash\n    |  imul TMPRd, #NODE\n    |  add NODE:TMPR, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cmp NODE:TMPR->key, ITYPE\n    |  jne >4\n    |  // Get node value.\n    |  mov ITYPE, NODE:TMPR->val\n    |  cmp ITYPE, LJ_TNIL\n    |  je >5\t\t\t\t// Key found, but nil value?\n    |2:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  mov NODE:TMPR, NODE:TMPR->next\n    |  test NODE:TMPR, NODE:TMPR\n    |  jnz <1\n    |  // End of hash chain: key not found, nil result.\n    |  mov ITYPE, LJ_TNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <2\t\t\t\t// No metatable: done.\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jnz <2\t\t\t\t// 'no __index' flag set: done.\n    |  jmp ->vmeta_tgets\t\t// Caveat: preserve STR:RC.\n    break;\n  case BC_TGETB:\n    |  ins_ABC\t// RA = dst, RB = table, RC = byte literal\n    |  mov TAB:RB, [BASE+RB*8]\n    |  checktab TAB:RB, ->vmeta_tgetb\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tgetb\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |  mov ITYPE, [RC]\n    |  cmp ITYPE, LJ_TNIL\n    |  je >2\n    |1:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetb\t\t\t// 'no __index' flag NOT set: check.\n    |  jmp <1\n    break;\n  case BC_TGETR:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cleartp TAB:RB\n    |.if DUALNUM\n    |  mov RCd, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RCd, qword [BASE+RC*8]\n    |.endif\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tgetr\t\t// Not in array part? Use fallback.\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |->BC_TGETR_Z:\n    |  mov ITYPE, [RC]\n    |->BC_TGETR2_Z:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  mov RC, [BASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tsetv\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movd xmm0, RC\n    |  cvttsd2si RCd, xmm0\n    |  cvtsi2sd xmm1, RCd\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tsetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RCd, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tsetv\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  cmp aword [RC], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:  // Set array slot.\n    |  mov RB, [BASE+RA*8]\n    |  mov [RC], RB\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetv\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  cmp ITYPEd, LJ_TSTR; jne ->vmeta_tsetv\n    |  cleartp STR:RC\n    |  jmp ->BC_TSETS_Z\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n  case BC_TSETS:\n    |  ins_ABC\t// RA = src, RB = table, RC = str const (~)\n    |  mov TAB:RB, [BASE+RB*8]\n    |  not RC\n    |  mov STR:RC, [KBASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tsets\n    |->BC_TSETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  mov TMPRd, TAB:RB->hmask\n    |  and TMPRd, STR:RC->hash\n    |  imul TMPRd, #NODE\n    |  mov byte TAB:RB->nomm, 0\t\t// Clear metamethod cache.\n    |  add NODE:TMPR, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cmp NODE:TMPR->key, ITYPE\n    |  jne >5\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp aword [TMPR], LJ_TNIL\n    |  je >4\t\t\t\t// Previous value is nil?\n    |2:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |3:  // Set node value.\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [TMPR], ITYPE\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  mov TAB:ITYPE, TAB:RB->metatable\n    |  test TAB:ITYPE, TAB:ITYPE\n    |  jz <2\n    |  test byte TAB:ITYPE->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <2\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:TMPR, NODE:TMPR->next\n    |  test NODE:TMPR, NODE:TMPR\n    |  jnz <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz >6\t\t\t\t// No metatable: continue.\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mov TMP1, ITYPE\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\n    |  lea CARG3, TMP1\n    |  mov CARG2, TAB:RB\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Handles write barrier for the new key. TValue * returned in eax (RC).\n    |  mov L:CARG1, SAVE_L\n    |  mov BASE, L:CARG1->base\n    |  mov TMPR, rax\n    |  movzx RAd, PC_RA\n    |  jmp <2\t\t\t\t// Must check write barrier for value.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, ITYPE\n    |  jmp <3\n    break;\n  case BC_TSETB:\n    |  ins_ABC\t// RA = src, RB = table, RC = byte literal\n    |  mov TAB:RB, [BASE+RB*8]\n    |  checktab TAB:RB, ->vmeta_tsetb\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tsetb\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  cmp aword [RC], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\t // Set array slot.\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [RC], ITYPE\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetb\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <1\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n  case BC_TSETR:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cleartp TAB:RB\n    |.if DUALNUM\n    |  mov RC, [BASE+RC*8]\n    |.else\n    |  cvttsd2si RCd, qword [BASE+RC*8]\n    |.endif\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tsetr\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Set array slot.\n    |->BC_TSETR_Z:\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [RC], ITYPE\n    |  ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n\n  case BC_TSETM:\n    |  ins_AD\t// RA = base (table at base-1), RD = num const (start index)\n    |1:\n    |  mov TMPRd, dword [KBASE+RD*8]\t// Integer constant is in lo-word.\n    |  lea RA, [BASE+RA*8]\n    |  mov TAB:RB, [RA-8]\t\t// Guaranteed to be a table.\n    |  cleartp TAB:RB\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  mov RDd, MULTRES\n    |  sub RDd, 1\n    |  jz >4\t\t\t\t// Nothing to copy?\n    |  add RDd, TMPRd\t\t\t// Compute needed size.\n    |  cmp RDd, TAB:RB->asize\n    |  ja >5\t\t\t\t// Doesn't fit into array part?\n    |  sub RDd, TMPRd\n    |  shl TMPRd, 3\n    |  add TMPR, TAB:RB->array\n    |3:  // Copy result slots to table.\n    |  mov RB, [RA]\n    |  add RA, 8\n    |  mov [TMPR], RB\n    |  add TMPR, 8\n    |  sub RDd, 1\n    |  jnz <3\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n    |  mov CARG2, TAB:RB\n    |  mov CARG3d, RDd\n    |  mov L:RB, L:CARG1\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\t\t\t// Restore RA.\n    |  movzx RDd, PC_RD\t\t\t// Restore RD.\n    |  jmp <1\t\t\t\t// Retry.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:RB, RD\n    |  jmp <2\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALL: case BC_CALLM:\n    |  ins_A_C\t// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs\n    if (op == BC_CALLM) {\n      |  add NARGS:RDd, MULTRES\n    }\n    |  mov LFUNC:RB, [BASE+RA*8]\n    |  checkfunc LFUNC:RB, ->vmeta_call_ra\n    |  lea BASE, [BASE+RA*8+16]\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  ins_AD\t// RA = base, RD = extra_nargs\n    |  add NARGS:RDd, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.\n    break;\n  case BC_CALLT:\n    |  ins_AD\t// RA = base, RD = nargs+1\n    |  lea RA, [BASE+RA*8+16]\n    |  mov KBASE, BASE\t\t\t// Use KBASE for move + vmeta_call hint.\n    |  mov LFUNC:RB, [RA-16]\n    |  checktp_nc LFUNC:RB, LJ_TFUNC, ->vmeta_call\n    |->BC_CALLT_Z:\n    |  mov PC, [BASE-8]\n    |  test PCd, FRAME_TYPE\n    |  jnz >7\n    |1:\n    |  mov [BASE-16], LFUNC:RB\t\t// Copy func+tag down, reloaded below.\n    |  mov MULTRES, NARGS:RDd\n    |  sub NARGS:RDd, 1\n    |  jz >3\n    |2:  // Move args down.\n    |  mov RB, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RB\n    |  add KBASE, 8\n    |  sub NARGS:RDd, 1\n    |  jnz <2\n    |\n    |  mov LFUNC:RB, [BASE-16]\n    |3:\n    |  cleartp LFUNC:RB\n    |  mov NARGS:RDd, MULTRES\n    |  cmp byte LFUNC:RB->ffid, 1\t// (> FF_C) Calling a fast function?\n    |  ja >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function.\n    |  test PCd, FRAME_TYPE\t\t// Lua frame below?\n    |  jnz <4\n    |  movzx RAd, PC_RA\n    |  neg RA\n    |  mov LFUNC:KBASE, [BASE+RA*8-32]\t// Need to prepare KBASE.\n    |  cleartp LFUNC:KBASE\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  jmp <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  sub PC, FRAME_VARG\n    |  test PCd, FRAME_TYPEP\n    |  jnz >8\t\t\t\t// Vararg frame below?\n    |  sub BASE, PC\t\t\t// Need to relocate BASE/KBASE down.\n    |  mov KBASE, BASE\n    |  mov PC, [BASE-8]\n    |  jmp <1\n    |8:\n    |  add PCd, FRAME_VARG\n    |  jmp <1\n    break;\n\n  case BC_ITERC:\n    |  ins_A\t// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)\n    |  lea RA, [BASE+RA*8+16]\t\t// fb = base+2\n    |  mov RB, [RA-32]\t\t\t// Copy state. fb[0] = fb[-4].\n    |  mov RC, [RA-24]\t\t\t// Copy control var. fb[1] = fb[-3].\n    |  mov [RA], RB\n    |  mov [RA+8], RC\n    |  mov LFUNC:RB, [RA-40]\t\t// Copy callable. fb[-1] = fb[-5]\n    |  mov [RA-16], LFUNC:RB\n    |  mov NARGS:RDd, 2+1\t\t// Handle like a regular 2-arg call.\n    |  checkfunc LFUNC:RB, ->vmeta_call\n    |  mov BASE, RA\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  ins_A\t// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  mov TAB:RB, [BASE+RA*8-16]\n    |  cleartp TAB:RB\n    |  mov RCd, [BASE+RA*8-8]\t\t// Get index from control var.\n    |  mov TMPRd, TAB:RB->asize\n    |  add PC, 4\n    |  mov ITYPE, TAB:RB->array\n    |1:  // Traverse array part.\n    |  cmp RCd, TMPRd; jae >5\t\t// Index points after array part?\n    |  cmp aword [ITYPE+RC*8], LJ_TNIL; je >4\n    |.if not DUALNUM\n    |  cvtsi2sd xmm0, RCd\n    |.endif\n    |  // Copy array slot to returned value.\n    |  mov RB, [ITYPE+RC*8]\n    |  mov [BASE+RA*8+8], RB\n    |  // Return array index as a numeric key.\n    |.if DUALNUM\n    |  setint ITYPE, RC\n    |  mov [BASE+RA*8], ITYPE\n    |.else\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  add RCd, 1\n    |  mov [BASE+RA*8-8], RCd\t\t// Update control var.\n    |2:\n    |  movzx RDd, PC_RD\t\t\t// Get target from ITERL.\n    |  branchPC RD\n    |3:\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  add RCd, 1\n    |  jmp <1\n    |\n    |5:  // Traverse hash part.\n    |  sub RCd, TMPRd\n    |6:\n    |  cmp RCd, TAB:RB->hmask; ja <3\t// End of iteration? Branch to ITERL+1.\n    |  imul ITYPEd, RCd, #NODE\n    |  add NODE:ITYPE, TAB:RB->node\n    |  cmp aword NODE:ITYPE->val, LJ_TNIL; je >7\n    |  lea TMPRd, [RCd+TMPRd+1]\n    |  // Copy key and value from hash slot.\n    |  mov RB, NODE:ITYPE->key\n    |  mov RC, NODE:ITYPE->val\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+8], RC\n    |  mov [BASE+RA*8-8], TMPRd\n    |  jmp <2\n    |\n    |7:  // Skip holes in hash part.\n    |  add RCd, 1\n    |  jmp <6\n    break;\n\n  case BC_ISNEXT:\n    |  ins_AD\t// RA = base, RD = target (points to ITERN)\n    |  mov CFUNC:RB, [BASE+RA*8-24]\n    |  checkfunc CFUNC:RB, >5\n    |  checktptp [BASE+RA*8-16], LJ_TTAB, >5\n    |  cmp aword [BASE+RA*8-8], LJ_TNIL; jne >5\n    |  cmp byte CFUNC:RB->ffid, FF_next_N; jne >5\n    |  branchPC RD\n    |  mov64 TMPR, U64x(fffe7fff, 00000000)\n    |  mov [BASE+RA*8-8], TMPR\t\t// Initialize control var.\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov PC_OP, BC_JMP\n    |  branchPC RD\n    |  mov byte [PC], BC_ITERC\n    |  jmp <1\n    break;\n\n  case BC_VARG:\n    |  ins_ABC\t// RA = base, RB = nresults+1, RC = numparams\n    |  lea TMPR, [BASE+RC*8+(16+FRAME_VARG)]\n    |  lea RA, [BASE+RA*8]\n    |  sub TMPR, [BASE-8]\n    |  // Note: TMPR may now be even _above_ BASE if nargs was < numparams.\n    |  test RB, RB\n    |  jz >5\t\t\t\t// Copy all varargs?\n    |  lea RB, [RA+RB*8-8]\n    |  cmp TMPR, BASE\t\t\t// No vararg slots?\n    |  jnb >2\n    |1:  // Copy vararg slots to destination slots.\n    |  mov RC, [TMPR-16]\n    |  add TMPR, 8\n    |  mov [RA], RC\n    |  add RA, 8\n    |  cmp RA, RB\t\t\t// All destination slots filled?\n    |  jnb >3\n    |  cmp TMPR, BASE\t\t\t// No more vararg slots?\n    |  jb <1\n    |2:  // Fill up remainder with nil.\n    |  mov aword [RA], LJ_TNIL\n    |  add RA, 8\n    |  cmp RA, RB\n    |  jb <2\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  mov MULTRES, 1\t\t\t// MULTRES = 0+1\n    |  mov RC, BASE\n    |  sub RC, TMPR\n    |  jbe <3\t\t\t\t// No vararg slots?\n    |  mov RBd, RCd\n    |  shr RBd, 3\n    |  add RBd, 1\n    |  mov MULTRES, RBd\t\t\t// MULTRES = #varargs+1\n    |  mov L:RB, SAVE_L\n    |  add RC, RA\n    |  cmp RC, L:RB->maxstack\n    |  ja >7\t\t\t\t// Need to grow stack?\n    |6:  // Copy all vararg slots.\n    |  mov RC, [TMPR-16]\n    |  add TMPR, 8\n    |  mov [RA], RC\n    |  add RA, 8\n    |  cmp TMPR, BASE\t\t\t// No more vararg slots?\n    |  jb <6\n    |  jmp <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mov L:RB->base, BASE\n    |  mov L:RB->top, RA\n    |  mov SAVE_PC, PC\n    |  sub TMPR, BASE\t\t\t// Need delta, because BASE may change.\n    |  mov TMP1hi, TMPRd\n    |  mov CARG2d, MULTRES\n    |  sub CARG2d, 1\n    |  mov CARG1, L:RB\n    |  call extern lj_state_growstack\t// (lua_State *L, int n)\n    |  mov BASE, L:RB->base\n    |  movsxd TMPR, TMP1hi\n    |  mov RA, L:RB->top\n    |  add TMPR, BASE\n    |  jmp <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  ins_AD\t// RA = results, RD = extra_nresults\n    |  add RDd, MULTRES\t\t\t// MULTRES >=1, so RD >=1.\n    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.\n    break;\n\n  case BC_RET: case BC_RET0: case BC_RET1:\n    |  ins_AD\t// RA = results, RD = nresults+1\n    if (op != BC_RET0) {\n      |  shl RAd, 3\n    }\n    |1:\n    |  mov PC, [BASE-8]\n    |  mov MULTRES, RDd\t\t\t// Save nresults+1.\n    |  test PCd, FRAME_TYPE\t\t// Check frame type marker.\n    |  jnz >7\t\t\t\t// Not returning to a fixarg Lua func?\n    switch (op) {\n    case BC_RET:\n      |->BC_RET_Z:\n      |  mov KBASE, BASE\t\t// Use KBASE for result move.\n      |  sub RDd, 1\n      |  jz >3\n      |2:  // Move results down.\n      |  mov RB, [KBASE+RA]\n      |  mov [KBASE-16], RB\n      |  add KBASE, 8\n      |  sub RDd, 1\n      |  jnz <2\n      |3:\n      |  mov RDd, MULTRES\t\t// Note: MULTRES may be >255.\n      |  movzx RBd, PC_RB\t\t// So cannot compare with RDL!\n      |5:\n      |  cmp RBd, RDd\t\t\t// More results expected?\n      |  ja >6\n      break;\n    case BC_RET1:\n      |  mov RB, [BASE+RA]\n      |  mov [BASE-16], RB\n      /* fallthrough */\n    case BC_RET0:\n      |5:\n      |  cmp PC_RB, RDL\t\t\t// More results expected?\n      |  ja >6\n    default:\n      break;\n    }\n    |  movzx RAd, PC_RA\n    |  neg RA\n    |  lea BASE, [BASE+RA*8-16]\t\t// base = base - (RA+2)*8\n    |  mov LFUNC:KBASE, [BASE-16]\n    |  cleartp LFUNC:KBASE\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    if (op == BC_RET) {\n      |  mov aword [KBASE-16], LJ_TNIL\t// Note: relies on shifted base.\n      |  add KBASE, 8\n    } else {\n      |  mov aword [BASE+RD*8-24], LJ_TNIL\n    }\n    |  add RD, 1\n    |  jmp <5\n    |\n    |7:  // Non-standard return case.\n    |  lea RB, [PC-FRAME_VARG]\n    |  test RBd, FRAME_TYPEP\n    |  jnz ->vm_return\n    |  // Return from vararg function: relocate BASE down and RA up.\n    |  sub BASE, RB\n    if (op != BC_RET0) {\n      |  add RA, RB\n    }\n    |  jmp <1\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA]\n  |.define FOR_STOP, [RA+8]\n  |.define FOR_STEP, [RA+16]\n  |.define FOR_EXT,  [RA+24]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ins_AJ\t// RA = base, RD = target (after end of loop or start of loop)\n    |  lea RA, [BASE+RA*8]\n    if (LJ_DUALNUM) {\n      |  mov RB, FOR_IDX\n      |  checkint RB, >9\n      |  mov TMPR, FOR_STOP\n      if (!vk) {\n\t|  checkint TMPR, ->vmeta_for\n\t|  mov ITYPE, FOR_STEP\n\t|  test ITYPEd, ITYPEd; js >5\n\t|  sar ITYPE, 47;\n\t|  cmp ITYPEd, LJ_TISNUM; jne ->vmeta_for\n      } else {\n#ifdef LUA_USE_ASSERT\n\t|  checkinttp FOR_STOP, ->assert_bad_for_arg_type\n\t|  checkinttp FOR_STEP, ->assert_bad_for_arg_type\n#endif\n\t|  mov ITYPE, FOR_STEP\n\t|  test ITYPEd, ITYPEd; js >5\n\t|  add RBd, ITYPEd; jo >1\n\t|  setint RB\n\t|  mov FOR_IDX, RB\n      }\n      |  cmp RBd, TMPRd\n      |  mov FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jle >7\n\t|1:\n\t|6:\n\t|  branchPC RD\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RDd, PC_RD\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      } else if (op == BC_IFORL) {\n\t|  jg >7\n\t|6:\n\t|  branchPC RD\n\t|1:\n      } else {\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      }\n      |7:\n      |  ins_next\n      |\n      |5:  // Invert check for negative step.\n      if (!vk) {\n\t|  sar ITYPE, 47;\n\t|  cmp ITYPEd, LJ_TISNUM; jne ->vmeta_for\n      } else {\n\t|  add RBd, ITYPEd; jo <1\n\t|  setint RB\n\t|  mov FOR_IDX, RB\n      }\n      |  cmp RBd, TMPRd\n      |  mov FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jge <7\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RDd, PC_RD\n\t|  jge =>BC_JLOOP\n      } else if (op == BC_IFORL) {\n\t|  jl <7\n      } else {\n\t|  jge =>BC_JLOOP\n      }\n      |  jmp <6\n      |9:  // Fallback to FP variant.\n      if (!vk) {\n\t|  jae ->vmeta_for\n      }\n    } else if (!vk) {\n      |  checknumtp FOR_IDX, ->vmeta_for\n    }\n    if (!vk) {\n      |  checknumtp FOR_STOP, ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  checknumtp FOR_STOP, ->assert_bad_for_arg_type\n      |  checknumtp FOR_STEP, ->assert_bad_for_arg_type\n#endif\n    }\n    |  mov RB, FOR_STEP\n    if (!vk) {\n      |  checknum RB, ->vmeta_for\n    }\n    |  movsd xmm0, qword FOR_IDX\n    |  movsd xmm1, qword FOR_STOP\n    if (vk) {\n      |  addsd xmm0, qword FOR_STEP\n      |  movsd qword FOR_IDX, xmm0\n      |  test RB, RB; js >3\n    } else {\n      |  jl >3\n    }\n    |  ucomisd xmm1, xmm0\n    |1:\n    |  movsd qword FOR_EXT, xmm0\n    if (op == BC_FORI) {\n      |.if DUALNUM\n      |  jnb <7\n      |.else\n      |  jnb >2\n      |  branchPC RD\n      |.endif\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  movzx RDd, PC_RD\n      |  jnb =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  jb <7\n      |.else\n      |  jb >2\n      |  branchPC RD\n      |.endif\n    } else {\n      |  jnb =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  jmp <6\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |\n    |3:  // Invert comparison if step is negative.\n    |  ucomisd xmm0, xmm1\n    |  jmp <1\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  ins_AJ\t// RA = base, RD = target\n    |  lea RA, [BASE+RA*8]\n    |  mov RB, [RA]\n    |  cmp RB, LJ_TNIL; je >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  mov [RA-8], RB\n      |  jmp =>BC_JLOOP\n    } else {\n      |  branchPC RD\t\t\t// Otherwise save control var + branch.\n      |  mov [RA-8], RB\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.\n    break;\n\n  case BC_ILOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  ins_AD\t// RA = base (ignored), RD = traceno\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  mov TRACE:RD, [RA+RD*8]\n    |  mov RD, TRACE:RD->mcode\n    |  mov L:RB, SAVE_L\n    |  mov [DISPATCH+DISPATCH_GL(jit_base)], BASE\n    |  mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB\n    |  // Save additional callee-save registers only used in compiled code.\n    |.if X64WIN\n    |  mov CSAVE_4, r12\n    |  mov CSAVE_3, r13\n    |  mov CSAVE_2, r14\n    |  mov CSAVE_1, r15\n    |  mov RA, rsp\n    |  sub rsp, 10*16+4*8\n    |  movdqa [RA-1*16], xmm6\n    |  movdqa [RA-2*16], xmm7\n    |  movdqa [RA-3*16], xmm8\n    |  movdqa [RA-4*16], xmm9\n    |  movdqa [RA-5*16], xmm10\n    |  movdqa [RA-6*16], xmm11\n    |  movdqa [RA-7*16], xmm12\n    |  movdqa [RA-8*16], xmm13\n    |  movdqa [RA-9*16], xmm14\n    |  movdqa [RA-10*16], xmm15\n    |.else\n    |  sub rsp, 16\n    |  mov [rsp+16], r12\n    |  mov [rsp+8], r13\n    |.endif\n    |  jmp RD\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  ins_AJ\t// RA = unused, RD = target\n    |  branchPC RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n   /*\n   ** Reminder: A function may be called with func/args above L->maxstack,\n   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,\n   ** too. This means all FUNC* ops (including fast functions) must check\n   ** for stack overflow _before_ adding more slots!\n   */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall RBd\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  mov KBASE, [PC-4+PC2PROTO(k)]\n    |  mov L:RB, SAVE_L\n    |  lea RA, [BASE+RA*8]\t\t// Top of frame.\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_f\n    |  movzx RAd, byte [PC-4+PC2PROTO(numparams)]\n    |  cmp NARGS:RDd, RAd\t\t// Check for missing parameters.\n    |  jbe >3\n    |2:\n    if (op == BC_JFUNCF) {\n      |  movzx RDd, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov aword [BASE+NARGS:RD*8-8], LJ_TNIL\n    |  add NARGS:RDd, 1\n    |  cmp NARGS:RDd, RAd\n    |  jbe <3\n    |  jmp <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    | int3  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  lea RBd, [NARGS:RD*8+FRAME_VARG+8]\n    |  lea RD, [BASE+NARGS:RD*8+8]\n    |  mov LFUNC:KBASE, [BASE-16]\n    |  mov [RD-8], RB\t\t\t// Store delta + FRAME_VARG.\n    |  mov [RD-16], LFUNC:KBASE\t\t// Store copy of LFUNC.\n    |  mov L:RB, SAVE_L\n    |  lea RA, [RD+RA*8]\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_v\t\t// Need to grow stack.\n    |  mov RA, BASE\n    |  mov BASE, RD\n    |  movzx RBd, byte [PC-4+PC2PROTO(numparams)]\n    |  test RBd, RBd\n    |  jz >2\n    |  add RA, 8\n    |1:  // Copy fixarg slots up to new frame.\n    |  add RA, 8\n    |  cmp RA, BASE\n    |  jnb >3\t\t\t\t// Less args than parameters?\n    |  mov KBASE, [RA-16]\n    |  mov [RD], KBASE\n    |  add RD, 8\n    |  mov aword [RA-16], LJ_TNIL\t// Clear old fixarg slot (help the GC).\n    |  sub RBd, 1\n    |  jnz <1\n    |2:\n    if (op == BC_JFUNCV) {\n      |  movzx RDd, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  mov KBASE, [PC-4+PC2PROTO(k)]\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov aword [RD], LJ_TNIL\n    |  add RD, 8\n    |  sub RBd, 1\n    |  jnz <3\n    |  jmp <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  ins_AD  // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1\n    |  mov CFUNC:RB, [BASE-16]\n    |  cleartp CFUNC:RB\n    |  mov KBASE, CFUNC:RB->f\n    |  mov L:RB, SAVE_L\n    |  lea RD, [BASE+NARGS:RD*8-8]\n    |  mov L:RB->base, BASE\n    |  lea RA, [RD+8*LUA_MINSTACK]\n    |  cmp RA, L:RB->maxstack\n    |  mov L:RB->top, RD\n    if (op == BC_FUNCC) {\n      |  mov CARG1, L:RB\t\t// Caveat: CARG1 may be RA.\n    } else {\n      |  mov CARG2, KBASE\n      |  mov CARG1, L:RB\t\t// Caveat: CARG1 may be RA.\n    }\n    |  ja ->vm_growstack_c\t\t// Need to grow stack.\n    |  set_vmstate C\n    if (op == BC_FUNCC) {\n      |  call KBASE\t\t\t// (lua_State *L)\n    } else {\n      |  // (lua_State *L, lua_CFunction f)\n      |  call aword [DISPATCH+DISPATCH_GL(wrapf)]\n    }\n    |  // nresults returned in eax (RD).\n    |  mov BASE, L:RB->base\n    |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n    |  set_vmstate INTERP\n    |  lea RA, [BASE+RD*8]\n    |  neg RA\n    |  add RA, L:RB->top\t\t// RA = (L->top-(L->base+nresults))*8\n    |  mov PC, [BASE-8]\t\t\t// Fetch PC of caller.\n    |  jmp ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n  dasm_growpc(Dst, BC__MAX);\n  build_subroutines(ctx);\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#if LJ_NO_UNWIND\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x6\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x7\\n\"\t/* offset r12 */\n#endif\n\t\"\\t.align 8\\n\"\n\t\".LEFDE0:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n#if (defined(__sun__) && defined(__svr4__))\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@unwind\\n\");\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n#endif\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE2:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n#if !LJ_NO_UNWIND\n  /* Mental note: never let Apple design an assembler.\n  ** Or a linker. Or a plastic case. But I digress.\n  */\n  case BUILD_machasm: {\n#if LJ_HASFFI\n    int fcsize = 0;\n#endif\n    int i;\n    fprintf(ctx->fp, \"\\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\\n\");\n    fprintf(ctx->fp,\n\t\"EH_frame1:\\n\"\n\t\"\\t.set L$set$x,LECIEX-LSCIEX\\n\"\n\t\"\\t.long L$set$x\\n\"\n\t\"LSCIEX:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zPR\\\\0\\\"\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.byte 128-8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.byte 6\\n\"\t\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9b\\n\"\t\t\t/* indirect|pcrel|sdata4 */\n\t\"\\t.long _lj_err_unwind_dwarf+4@GOTPCREL\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte 0x7\\n\\t.byte 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.byte 0x1\\n\"\n\t\"\\t.align 3\\n\"\n\t\"LECIEX:\\n\\n\");\n    for (i = 0; i < ctx->nsym; i++) {\n      const char *name = ctx->sym[i].name;\n      int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;\n      if (size == 0) continue;\n#if LJ_HASFFI\n      if (!strcmp(name, \"_lj_vm_ffi_call\")) { fcsize = size; continue; }\n#endif\n      fprintf(ctx->fp,\n\t  \"%s.eh:\\n\"\n\t  \"LSFDE%d:\\n\"\n\t  \"\\t.set L$set$%d,LEFDE%d-LASFDE%d\\n\"\n\t  \"\\t.long L$set$%d\\n\"\n\t  \"LASFDE%d:\\n\"\n\t  \"\\t.long LASFDE%d-EH_frame1\\n\"\n\t  \"\\t.long %s-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte %d\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.byte 0x8f\\n\\t.byte 0x4\\n\"\t\t/* offset r15 */\n\t  \"\\t.byte 0x8e\\n\\t.byte 0x5\\n\"\t\t/* offset r14 */\n\t  \"\\t.align 3\\n\"\n\t  \"LEFDE%d:\\n\\n\",\n\t  name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);\n    }\n#if LJ_HASFFI\n    if (fcsize) {\n      fprintf(ctx->fp,\n\t  \"EH_frame2:\\n\"\n\t  \"\\t.set L$set$y,LECIEY-LSCIEY\\n\"\n\t  \"\\t.long L$set$y\\n\"\n\t  \"LSCIEY:\\n\"\n\t  \"\\t.long 0\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.ascii \\\"zR\\\\0\\\"\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.byte 128-8\\n\"\n\t  \"\\t.byte 0x10\\n\"\n\t  \"\\t.byte 1\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte 0x7\\n\\t.byte 8\\n\"\n\t  \"\\t.byte 0x80+0x10\\n\\t.byte 0x1\\n\"\n\t  \"\\t.align 3\\n\"\n\t  \"LECIEY:\\n\\n\");\n      fprintf(ctx->fp,\n\t  \"_lj_vm_ffi_call.eh:\\n\"\n\t  \"LSFDEY:\\n\"\n\t  \"\\t.set L$set$yy,LEFDEY-LASFDEY\\n\"\n\t  \"\\t.long L$set$yy\\n\"\n\t  \"LASFDEY:\\n\"\n\t  \"\\t.long LASFDEY-EH_frame2\\n\"\n\t  \"\\t.long _lj_vm_ffi_call-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte 16\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0xd\\n\\t.byte 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.align 3\\n\"\n\t  \"LEFDEY:\\n\\n\", fcsize);\n    }\n#endif\n    fprintf(ctx->fp, \".subsections_via_symbols\\n\");\n    }\n    break;\n#endif\n  default:  /* Difficult for other modes. */\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/vm_x86.dasc",
    "content": "|// Low-level VM code for x86 CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h\n|\n|.if P64\n|.arch x64\n|.else\n|.arch x86\n|.endif\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|//-----------------------------------------------------------------------\n|\n|.if P64\n|.define X64, 1\n|.if WIN\n|.define X64WIN, 1\n|.endif\n|.endif\n|\n|// Fixed register assignments for the interpreter.\n|// This is very fragile and has many dependencies. Caveat emptor.\n|.define BASE,\t\tedx\t\t// Not C callee-save, refetched anyway.\n|.if not X64\n|.define KBASE,\t\tedi\t\t// Must be C callee-save.\n|.define KBASEa,\tKBASE\n|.define PC,\t\tesi\t\t// Must be C callee-save.\n|.define PCa,\t\tPC\n|.define DISPATCH,\tebx\t\t// Must be C callee-save.\n|.elif X64WIN\n|.define KBASE,\t\tedi\t\t// Must be C callee-save.\n|.define KBASEa,\trdi\n|.define PC,\t\tesi\t\t// Must be C callee-save.\n|.define PCa,\t\trsi\n|.define DISPATCH,\tebx\t\t// Must be C callee-save.\n|.else\n|.define KBASE,\t\tr15d\t\t// Must be C callee-save.\n|.define KBASEa,\tr15\n|.define PC,\t\tebx\t\t// Must be C callee-save.\n|.define PCa,\t\trbx\n|.define DISPATCH,\tr14d\t\t// Must be C callee-save.\n|.endif\n|\n|.define RA,\t\tecx\n|.define RAH,\t\tch\n|.define RAL,\t\tcl\n|.define RB,\t\tebp\t\t// Must be ebp (C callee-save).\n|.define RC,\t\teax\t\t// Must be eax.\n|.define RCW,\t\tax\n|.define RCH,\t\tah\n|.define RCL,\t\tal\n|.define OP,\t\tRB\n|.define RD,\t\tRC\n|.define RDW,\t\tRCW\n|.define RDL,\t\tRCL\n|.if X64\n|.define RAa, rcx\n|.define RBa, rbp\n|.define RCa, rax\n|.define RDa, rax\n|.else\n|.define RAa, RA\n|.define RBa, RB\n|.define RCa, RC\n|.define RDa, RD\n|.endif\n|\n|.if not X64\n|.define FCARG1,\tecx\t\t// x86 fastcall arguments.\n|.define FCARG2,\tedx\n|.elif X64WIN\n|.define CARG1,\t\trcx\t\t// x64/WIN64 C call arguments.\n|.define CARG2,\t\trdx\n|.define CARG3,\t\tr8\n|.define CARG4,\t\tr9\n|.define CARG1d,\tecx\n|.define CARG2d,\tedx\n|.define CARG3d,\tr8d\n|.define CARG4d,\tr9d\n|.define FCARG1,\tCARG1d\t\t// Upwards compatible to x86 fastcall.\n|.define FCARG2,\tCARG2d\n|.else\n|.define CARG1,\t\trdi\t\t// x64/POSIX C call arguments.\n|.define CARG2,\t\trsi\n|.define CARG3,\t\trdx\n|.define CARG4,\t\trcx\n|.define CARG5,\t\tr8\n|.define CARG6,\t\tr9\n|.define CARG1d,\tedi\n|.define CARG2d,\tesi\n|.define CARG3d,\tedx\n|.define CARG4d,\tecx\n|.define CARG5d,\tr8d\n|.define CARG6d,\tr9d\n|.define FCARG1,\tCARG1d\t\t// Simulate x86 fastcall.\n|.define FCARG2,\tCARG2d\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|//-----------------------------------------------------------------------\n|.if not X64\t\t// x86 stack layout.\n|\n|.define CFRAME_SPACE,\taword*7\t\t\t// Delta for esp (see <--).\n|.macro saveregs_\n|  push edi; push esi; push ebx\n|  sub esp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push ebp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add esp, CFRAME_SPACE\n|  pop ebx; pop esi; pop edi; pop ebp\n|.endmacro\n|\n|.define SAVE_ERRF,\taword [esp+aword*15]\t// vm_pcall/vm_cpcall only.\n|.define SAVE_NRES,\taword [esp+aword*14]\n|.define SAVE_CFRAME,\taword [esp+aword*13]\n|.define SAVE_L,\taword [esp+aword*12]\n|//----- 16 byte aligned, ^^^ arguments from C caller\n|.define SAVE_RET,\taword [esp+aword*11]\t//<-- esp entering interpreter.\n|.define SAVE_R4,\taword [esp+aword*10]\n|.define SAVE_R3,\taword [esp+aword*9]\n|.define SAVE_R2,\taword [esp+aword*8]\n|//----- 16 byte aligned\n|.define SAVE_R1,\taword [esp+aword*7]\t//<-- esp after register saves.\n|.define SAVE_PC,\taword [esp+aword*6]\n|.define TMP2,\t\taword [esp+aword*5]\n|.define TMP1,\t\taword [esp+aword*4]\n|//----- 16 byte aligned\n|.define ARG4,\t\taword [esp+aword*3]\n|.define ARG3,\t\taword [esp+aword*2]\n|.define ARG2,\t\taword [esp+aword*1]\n|.define ARG1,\t\taword [esp]\t\t//<-- esp while in interpreter.\n|//----- 16 byte aligned, ^^^ arguments for C callee\n|\n|// FPARGx overlaps ARGx and ARG(x+1) on x86.\n|.define FPARG3,\tqword [esp+qword*1]\n|.define FPARG1,\tqword [esp]\n|// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [esp+aword*4]\n|.define TMP3,\t\tARG4\n|.define ARG5,\t\tTMP1\n|.define TMPa,\t\tTMP1\n|.define MULTRES,\tTMP2\n|\n|// Arguments for vm_call and vm_pcall.\n|.define INARG_BASE,\tSAVE_CFRAME\t\t// Overwritten by SAVE_CFRAME!\n|\n|// Arguments for vm_cpcall.\n|.define INARG_CP_CALL,\tSAVE_ERRF\n|.define INARG_CP_UD,\tSAVE_NRES\n|.define INARG_CP_FUNC,\tSAVE_CFRAME\n|\n|//-----------------------------------------------------------------------\n|.elif X64WIN\t\t// x64/Windows stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rdi; push rsi; push rbx\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|  pop rbx; pop rsi; pop rdi; pop rbp\n|.endmacro\n|\n|.define SAVE_CFRAME,\taword [rsp+aword*13]\n|.define SAVE_PC,\tdword [rsp+dword*25]\n|.define SAVE_L,\tdword [rsp+dword*24]\n|.define SAVE_ERRF,\tdword [rsp+dword*23]\n|.define SAVE_NRES,\tdword [rsp+dword*22]\n|.define TMP2,\t\tdword [rsp+dword*21]\n|.define TMP1,\t\tdword [rsp+dword*20]\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.define ARG5,\t\taword [rsp+aword*4]\n|.define CSAVE_4,\taword [rsp+aword*3]\n|.define CSAVE_3,\taword [rsp+aword*2]\n|.define CSAVE_2,\taword [rsp+aword*1]\n|.define CSAVE_1,\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee\n|\n|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [rsp+aword*10]\n|.define MULTRES,\tTMP2\n|.define TMPa,\t\tARG5\n|.define ARG5d,\t\tdword [rsp+aword*4]\n|.define TMP3,\t\tARG5d\n|\n|//-----------------------------------------------------------------------\n|.else\t\t\t// x64/POSIX stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rbx; push r15; push r14\n|.if NO_UNWIND\n|  push r13; push r12\n|.endif\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|.if NO_UNWIND\n|  pop r12; pop r13\n|.endif\n|  pop r14; pop r15; pop rbx; pop rbp\n|.endmacro\n|\n|//----- 16 byte aligned,\n|.if NO_UNWIND\n|.define SAVE_RET,\taword [rsp+aword*11]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*10]\n|.define SAVE_R3,\taword [rsp+aword*9]\n|.define SAVE_R2,\taword [rsp+aword*8]\n|.define SAVE_R1,\taword [rsp+aword*7]\n|.define SAVE_RU2,\taword [rsp+aword*6]\n|.define SAVE_RU1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.else\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.endif\n|.define SAVE_CFRAME,\taword [rsp+aword*4]\n|.define SAVE_PC,\tdword [rsp+dword*7]\n|.define SAVE_L,\tdword [rsp+dword*6]\n|.define SAVE_ERRF,\tdword [rsp+dword*5]\n|.define SAVE_NRES,\tdword [rsp+dword*4]\n|.define TMPa,\t\taword [rsp+aword*1]\n|.define TMP2,\t\tdword [rsp+dword*1]\n|.define TMP1,\t\tdword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned\n|\n|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [rsp]\n|.define TMP3,\t\tdword [rsp+aword*1]\n|.define MULTRES,\tTMP2\n|\n|.endif\n|\n|//-----------------------------------------------------------------------\n|\n|// Instruction headers.\n|.macro ins_A; .endmacro\n|.macro ins_AD; .endmacro\n|.macro ins_AJ; .endmacro\n|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro\n|.macro ins_AB_; movzx RB, RCH; .endmacro\n|.macro ins_A_C; movzx RC, RCL; .endmacro\n|.macro ins_AND; not RDa; .endmacro\n|\n|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).\n|.macro ins_NEXT\n|  mov RC, [PC]\n|  movzx RA, RCH\n|  movzx OP, RCL\n|  add PC, 4\n|  shr RC, 16\n|.if X64\n|  jmp aword [DISPATCH+OP*8]\n|.else\n|  jmp aword [DISPATCH+OP*4]\n|.endif\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  // Around 10%-30% slower on Core2, a lot more slower on P4.\n|  .macro ins_next\n|    jmp ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC\n|  mov PC, LFUNC:RB->pc\n|  mov RA, [PC]\n|  movzx OP, RAL\n|  movzx RA, RAH\n|  add PC, 4\n|.if X64\n|  jmp aword [DISPATCH+OP*8]\n|.else\n|  jmp aword [DISPATCH+OP*4]\n|.endif\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC, RD = nargs+1\n|  mov [BASE-4], PC\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checktp, reg, tp;  cmp dword [BASE+reg*8+4], tp; .endmacro\n|.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro\n|.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro\n|\n|// These operands must be used with movzx.\n|.define PC_OP, byte [PC-4]\n|.define PC_RA, byte [PC-3]\n|.define PC_RB, byte [PC-1]\n|.define PC_RC, byte [PC-2]\n|.define PC_RD, word [PC-2]\n|\n|.macro branchPC, reg\n|  lea PC, [PC+reg*4-BCBIAS_J*4]\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|// Decrement hashed hotcount and trigger trace recorder if zero.\n|.macro hotloop, reg\n|  mov reg, PC\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP\n|  jb ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall, reg\n|  mov reg, PC\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL\n|  jb ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro set_vmstate, st\n|  mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st\n|.endmacro\n|\n|// x87 compares.\n|.macro fcomparepp\t\t\t// Compare and pop st0 >< st1.\n|  fucomip st1\n|  fpop\n|.endmacro\n|\n|.macro fpop1; fstp st1; .endmacro\n|\n|// Synthesize SSE FP constants.\n|.macro sseconst_abs, reg, tmp\t\t// Synthesize abs mask.\n|.if X64\n|  mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp\n|.else\n|  pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1\n|.endif\n|.endmacro\n|\n|.macro sseconst_hi, reg, tmp, val\t// Synthesize hi-32 bit const.\n|.if X64\n|  mov64 tmp, U64x(val,00000000); movd reg, tmp\n|.else\n|  mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51\n|.endif\n|.endmacro\n|\n|.macro sseconst_sign, reg, tmp\t\t// Synthesize sign mask.\n|  sseconst_hi reg, tmp, 80000000\n|.endmacro\n|.macro sseconst_1, reg, tmp\t\t// Synthesize 1.0.\n|  sseconst_hi reg, tmp, 3ff00000\n|.endmacro\n|.macro sseconst_m1, reg, tmp\t\t// Synthesize -1.0.\n|  sseconst_hi reg, tmp, bff00000\n|.endmacro\n|.macro sseconst_2p52, reg, tmp\t\t// Synthesize 2^52.\n|  sseconst_hi reg, tmp, 43300000\n|.endmacro\n|.macro sseconst_tobit, reg, tmp\t// Synthesize 2^52 + 2^51.\n|  sseconst_hi reg, tmp, 43380000\n|.endmacro\n|\n|// Move table write barrier back. Overwrites reg.\n|.macro barrierback, tab, reg\n|  and byte tab->marked, (uint8_t)~LJ_GC_BLACK\t// black2gray(tab)\n|  mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]\n|  mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab\n|  mov tab->gclist, reg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  test PC, FRAME_P\n  |  jz ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  and PC, -8\n  |  sub BASE, PC\t\t\t// Restore caller base.\n  |  lea RAa, [RA+PC-8]\t\t\t// Rebase RA and prepend one result.\n  |  mov PC, [BASE-4]\t\t\t// Fetch PC of previous frame.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |  mov dword [BASE+RA+4], LJ_TTRUE\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  add RD, 1\t\t\t\t// RD = nresults+1\n  |  jz ->vm_unwind_yield\n  |  mov MULTRES, RD\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return\n  |  xor PC, FRAME_C\n  |  test PC, FRAME_TYPE\n  |  jnz ->vm_returnp\n  |\n  |  // Return to C.\n  |  set_vmstate C\n  |  and PC, -8\n  |  sub PC, BASE\n  |  neg PC\t\t\t\t// Previous base = BASE - delta.\n  |\n  |  sub RD, 1\n  |  jz >2\n  |1:  // Move results down.\n  |.if X64\n  |  mov RBa, [BASE+RA]\n  |  mov [BASE-8], RBa\n  |.else\n  |  mov RB, [BASE+RA]\n  |  mov [BASE-8], RB\n  |  mov RB, [BASE+RA+4]\n  |  mov [BASE-4], RB\n  |.endif\n  |  add BASE, 8\n  |  sub RD, 1\n  |  jnz <1\n  |2:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, PC\n  |3:\n  |  mov RD, MULTRES\n  |  mov RA, SAVE_NRES\t\t\t// RA = wanted nresults+1\n  |4:\n  |  cmp RA, RD\n  |  jne >6\t\t\t\t// More/less results wanted?\n  |5:\n  |  sub BASE, 8\n  |  mov L:RB->top, BASE\n  |\n  |->vm_leave_cp:\n  |  mov RAa, SAVE_CFRAME\t\t// Restore previous C frame.\n  |  mov L:RB->cframe, RAa\n  |  xor eax, eax\t\t\t// Ok return status for vm_pcall.\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  jb >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  cmp BASE, L:RB->maxstack\n  |  ja >8\n  |  mov dword [BASE-4], LJ_TNIL\n  |  add BASE, 8\n  |  add RD, 1\n  |  jmp <4\n  |\n  |7:  // Less results wanted.\n  |  test RA, RA\n  |  jz <5\t\t\t\t// But check for LUA_MULTRET+1.\n  |  sub RA, RD\t\t\t\t// Negative result!\n  |  lea BASE, [BASE+RA*8]\t\t// Correct top.\n  |  jmp <5\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  mov L:RB->top, BASE\t\t// Save current top held in BASE (yes).\n  |  mov MULTRES, RD\t\t\t// Need to fill only remainder with nil.\n  |  mov FCARG2, RA\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->top\t\t// Need the (realloced) L->top in BASE.\n  |  jmp <3\n  |\n  |->vm_unwind_yield:\n  |  mov al, LUA_YIELD\n  |  jmp ->vm_unwind_c_eh\n  |\n  |->vm_unwind_c@8:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |.if X64\n  |  mov eax, CARG2d\t\t\t// Error return status for vm_pcall.\n  |  mov rsp, CARG1\n  |.else\n  |  mov eax, FCARG2\t\t\t// Error return status for vm_pcall.\n  |  mov esp, FCARG1\n  |.endif\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov GL:RB, L:RB->glref\n  |  mov dword GL:RB->vmstate, ~LJ_VMST_C\n  |  jmp ->vm_leave_unw\n  |\n  |->vm_unwind_rethrow:\n  |.if X64 and not X64WIN\n  |  mov FCARG1, SAVE_L\n  |  mov FCARG2, eax\n  |  restoreregs\n  |  jmp extern lj_err_throw@8\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |->vm_unwind_ff@4:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |.if X64\n  |  and CARG1, CFRAME_RAWMASK\n  |  mov rsp, CARG1\n  |.else\n  |  and FCARG1, CFRAME_RAWMASK\n  |  mov esp, FCARG1\n  |.endif\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov RAa, -8\t\t\t// Results start at BASE+RA = BASE-8.\n  |  mov RD, 1+1\t\t\t// Really 1+2 results, incr. later.\n  |  mov BASE, L:RB->base\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov PC, [BASE-4]\t\t\t// Fetch PC of previous frame.\n  |  mov dword [BASE-4], LJ_TFALSE\t// Prepend false to error message.\n  |  set_vmstate INTERP\n  |  jmp ->vm_returnc\t\t\t// Increments RD/MULTRES and returns.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  mov FCARG2, LUA_MINSTACK\n  |  jmp >2\n  |\n  |->vm_growstack_v:\t\t\t// Grow stack for vararg Lua function.\n  |  sub RD, 8\n  |  jmp >1\n  |\n  |->vm_growstack_f:\t\t\t// Grow stack for fixarg Lua function.\n  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |1:\n  |  movzx RA, byte [PC-4+PC2PROTO(framesize)]\n  |  add PC, 4\t\t\t\t// Must point after first instruction.\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov SAVE_PC, PC\n  |  mov FCARG2, RA\n  |2:\n  |  // RB = L, L->base = new base, L->top = top\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  mov LFUNC:RB, [BASE-8]\n  |  sub RD, BASE\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  // BASE = new base, RB = LFUNC, RD = nargs+1\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |.if X64\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |  mov RA, CARG2d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov RA, INARG_BASE\t\t\t// Caveat: overlaps SAVE_CFRAME!\n  |.endif\n  |  mov PC, FRAME_CP\n  |  xor RD, RD\n  |  lea KBASEa, [esp+CFRAME_RESUME]\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov SAVE_PC, RD\t\t\t// Any value outside of bytecode is ok.\n  |  mov SAVE_CFRAME, RDa\n  |.if X64\n  |  mov SAVE_NRES, RD\n  |  mov SAVE_ERRF, RD\n  |.endif\n  |  mov L:RB->cframe, KBASEa\n  |  cmp byte L:RB->status, RDL\n  |  je >2\t\t\t\t// Initial resume (like a call).\n  |\n  |  // Resume after yield (like a return).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov byte L:RB->status, RDL\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr RD, 3\n  |  add RD, 1\t\t\t\t// RD = nresults+1\n  |  sub RA, BASE\t\t\t// RA = resultofs\n  |  mov PC, [BASE-4]\n  |  mov MULTRES, RD\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, FRAME_CP\n  |.if X64\n  |  mov SAVE_ERRF, CARG4d\n  |.endif\n  |  jmp >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |.if X64\n  |  mov SAVE_NRES, CARG3d\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |  mov RA, CARG2d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov RA, INARG_BASE\t\t\t// Caveat: overlaps SAVE_CFRAME!\n  |.endif\n  |\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov KBASEa, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASEa\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |  add DISPATCH, GG_G2DISP\n  |.if X64\n  |  mov L:RB->cframe, rsp\n  |.else\n  |  mov L:RB->cframe, esp\n  |.endif\n  |\n  |2:  // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov BASE, L:RB->base\t\t// BASE = old base (used in vmeta_call).\n  |  add PC, RA\n  |  sub PC, BASE\t\t\t// PC = frame delta + frame type\n  |\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr NARGS:RD, 3\n  |  add NARGS:RD, 1\t\t\t// RD = nargs+1\n  |\n  |->vm_call_dispatch:\n  |  mov LFUNC:RB, [RA-8]\n  |  cmp dword [RA-4], LJ_TFUNC\n  |  jne ->vmeta_call\t\t\t// Ensure KBASE defined and != BASE.\n  |\n  |->vm_call_dispatch_f:\n  |  mov BASE, RA\n  |  ins_call\n  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |.if X64\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap!\n  |  mov RC, INARG_CP_UD\t\t// Get args before they are overwritten.\n  |  mov RA, INARG_CP_FUNC\n  |  mov BASE, INARG_CP_CALL\n  |.endif\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |\n  |  mov KBASE, L:RB->stack\t\t// Compute -savestack(L, L->top).\n  |  sub KBASE, L:RB->top\n  |   mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov SAVE_ERRF, 0\t\t\t// No error function.\n  |  mov SAVE_NRES, KBASE\t\t// Neg. delta means cframe w/o frame.\n  |   add DISPATCH, GG_G2DISP\n  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).\n  |\n  |.if X64\n  |  mov KBASEa, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASEa\n  |  mov L:RB->cframe, rsp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.else\n  |  mov ARG3, RC\t\t\t// Have to copy args downwards.\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov L:RB->cframe, esp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call BASE\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.endif\n  |  // TValue * (new base) or NULL returned in eax (RC).\n  |  test RC, RC\n  |  jz ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |  mov RA, RC\n  |  mov PC, FRAME_CP\n  |  jmp <2\t\t\t\t// Else continue with the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)\n  |  add RA, BASE\n  |  and PC, -8\n  |  mov RB, BASE\n  |  sub BASE, PC\t\t\t// Restore caller BASE.\n  |  mov dword [RA+RD*8-4], LJ_TNIL\t// Ensure one valid arg.\n  |  mov RC, RA\t\t\t\t// ... in [RC]\n  |  mov PC, [RB-12]\t\t\t// Restore PC from [cont|PC].\n  |.if X64\n  |  movsxd RAa, dword [RB-16]\t\t// May be negative on WIN64 with debug.\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |  lea KBASEa, qword [=>0]\n  |  add RAa, KBASEa\n  |.else\n  |  mov RA, dword [RB-16]\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |.endif\n  |  mov LFUNC:KBASE, [BASE-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  // BASE = base, RC = result, RB = meta base\n  |  jmp RAa\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  je ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: Tail call from C function.\n  |  sub RB, BASE\n  |  shr RB, 3\n  |  lea RD, [RB-1]\n  |  jmp ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// BASE = base, RC = result, RB = mbase\n  |  movzx RA, PC_RB\n  |  sub RB, 16\n  |  lea RA, [BASE+RA*8]\n  |  sub RA, RB\n  |  je ->cont_ra\n  |  neg RA\n  |  shr RA, 3\n  |.if X64WIN\n  |  mov CARG3d, RA\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\n  |  mov RCa, [RC]\n  |  mov [RB], RCa\n  |  mov CARG2d, RB\n  |.elif X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\n  |  mov CARG3d, RA\n  |  mov RAa, [RC]\n  |  mov [RB], RAa\n  |  mov CARG2d, RB\n  |.else\n  |  mov ARG3, RA\n  |  mov RA, [RC+4]\n  |  mov RC, [RC]\n  |  mov [RB+4], RA\n  |  mov [RB], RC\n  |  mov ARG2, RB\n  |.endif\n  |  jmp ->BC_CAT_Z\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets:\n  |  mov TMP1, RC\t\t\t// RC = GCstr *\n  |  mov TMP2, LJ_TSTR\n  |  lea RCa, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n  |  cmp PC_OP, BC_GGET\n  |  jne >1\n  |  lea RA, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RA], TAB:RB\t\t\t// RB = GCtab *\n  |  mov dword [RA+4], LJ_TTAB\n  |  mov RB, RA\n  |  jmp >2\n  |\n  |->vmeta_tgetb:\n  |  movzx RC, PC_RC\n  |.if DUALNUM\n  |  mov TMP2, LJ_TISNUM\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RC\n  |  movsd TMPQ, xmm0\n  |.endif\n  |  lea RCa, TMPQ\t\t\t// Store temp. TValue in TMPQ.\n  |  jmp >1\n  |\n  |->vmeta_tgetv:\n  |  movzx RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |.if X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RB\n  |  mov CARG3, RCa\t\t\t// May be 64 bit ptr to stack.\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG2, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |->cont_ra:\t\t\t\t// BASE = base, RC = result\n  |  movzx RA, PC_RA\n  |.if X64\n  |  mov RBa, [RC]\n  |  mov [BASE+RA*8], RBa\n  |.else\n  |  mov RB, [RC+4]\n  |  mov RC, [RC]\n  |  mov [BASE+RA*8+4], RB\n  |  mov [BASE+RA*8], RC\n  |.endif\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  mov RA, L:RB->top\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-8]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RD, 2+1\t\t\t// 2 args for func(t, k).\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  mov FCARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov FCARG2, RC\t\t\t// Caveat: FCARG2 == BASE\n  |  call extern lj_tab_getinth@8\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RC).\n  |  movzx RA, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RC, RC\n  |  jnz ->BC_TGETR_Z\n  |  mov dword [BASE+RA*8+4], LJ_TNIL\n  |  jmp ->BC_TGETR2_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets:\n  |  mov TMP1, RC\t\t\t// RC = GCstr *\n  |  mov TMP2, LJ_TSTR\n  |  lea RCa, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n  |  cmp PC_OP, BC_GSET\n  |  jne >1\n  |  lea RA, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RA], TAB:RB\t\t\t// RB = GCtab *\n  |  mov dword [RA+4], LJ_TTAB\n  |  mov RB, RA\n  |  jmp >2\n  |\n  |->vmeta_tsetb:\n  |  movzx RC, PC_RC\n  |.if DUALNUM\n  |  mov TMP2, LJ_TISNUM\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RC\n  |  movsd TMPQ, xmm0\n  |.endif\n  |  lea RCa, TMPQ\t\t\t// Store temp. TValue in TMPQ.\n  |  jmp >1\n  |\n  |->vmeta_tsetv:\n  |  movzx RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |.if X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RB\n  |  mov CARG3, RCa\t\t\t// May be 64 bit ptr to stack.\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG2, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  movzx RA, PC_RA\n  |.if X64\n  |  mov RBa, [BASE+RA*8]\n  |  mov [RC], RBa\n  |.else\n  |  mov RB, [BASE+RA*8+4]\n  |  mov RA, [BASE+RA*8]\n  |  mov [RC+4], RB\n  |  mov [RC], RA\n  |.endif\n  |->cont_nop:\t\t\t\t// BASE = base, (RC = result)\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  mov RA, L:RB->top\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  movzx RC, PC_RA\n  |  // Copy value to third argument.\n  |.if X64\n  |  mov RBa, [BASE+RC*8]\n  |  mov [RA+16], RBa\n  |.else\n  |  mov RB, [BASE+RC*8+4]\n  |  mov RC, [BASE+RC*8]\n  |  mov [RA+20], RB\n  |  mov [RA+16], RC\n  |.endif\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-8]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RD, 3+1\t\t\t// 3 args for func(t, k, v).\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |.if X64WIN\n  |  mov L:CARG1d, SAVE_L\n  |  mov CARG3d, RC\n  |  mov L:CARG1d->base, BASE\n  |  xchg CARG2d, TAB:RB\t\t// Caveat: CARG2d == BASE.\n  |.elif X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov CARG2d, TAB:RB\n  |  mov L:CARG1d->base, BASE\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG3d, RC\t\t\t// Caveat: CARG3d == BASE.\n  |.else\n  |  mov L:RA, SAVE_L\n  |  mov ARG2, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov ARG3, RC\n  |  mov ARG1, L:RA\n  |  mov L:RA->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // TValue * returned in eax (RC).\n  |  movzx RA, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  jmp ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d == BASE.\n  |.if X64WIN\n  |  lea CARG3d, [BASE+RD*8]\n  |  lea CARG2d, [BASE+RA*8]\n  |.else\n  |  lea CARG2d, [BASE+RA*8]\n  |  lea CARG3d, [BASE+RD*8]\n  |.endif\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d/CARG4d == RA.\n  |  movzx CARG4d, PC_OP\n  |.else\n  |  movzx RB, PC_OP\n  |  lea RD, [BASE+RD*8]\n  |  lea RA, [BASE+RA*8]\n  |  mov ARG4, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |3:\n  |  mov BASE, L:RB->base\n  |  cmp RC, 1\n  |  ja ->vmeta_binop\n  |4:\n  |  lea PC, [PC+4]\n  |  jb >6\n  |5:\n  |  movzx RD, PC_RD\n  |  branchPC RD\n  |6:\n  |  ins_next\n  |\n  |->cont_condt:\t\t\t// BASE = base, RC = result\n  |  add PC, 4\n  |  cmp dword [RC+4], LJ_TISTRUECOND\t// Branch if result is true.\n  |  jb <5\n  |  jmp <6\n  |\n  |->cont_condf:\t\t\t// BASE = base, RC = result\n  |  cmp dword [RC+4], LJ_TISTRUECOND\t// Branch if result is false.\n  |  jmp <4\n  |\n  |->vmeta_equal:\n  |  sub PC, 4\n  |.if X64WIN\n  |  mov CARG3d, RD\n  |  mov CARG4d, RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG2d, RA\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d == RA.\n  |.elif X64\n  |  mov CARG2d, RA\n  |  mov CARG4d, RB\t\t\t// Caveat: CARG4d == RA.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG3d, RD\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG4, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, 4\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG1, L:RB\n  |  mov FCARG2, dword [PC-4]\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal_cd@8\t// (lua_State *L, BCIns ins)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RA\n  |  movzx CARG3d, PC_RD\n  |  mov L:CARG1d, L:RB\n  |.else\n  |  movzx RD, PC_RD\n  |  mov ARG2, RA\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  mov BASE, L:RB->base\n  |  jmp <6\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vno:\n  |.if DUALNUM\n  |  movzx RB, PC_RB\n  |.endif\n  |->vmeta_arith_vn:\n  |  lea RC, [KBASE+RC*8]\n  |  jmp >1\n  |\n  |->vmeta_arith_nvo:\n  |.if DUALNUM\n  |  movzx RC, PC_RC\n  |.endif\n  |->vmeta_arith_nv:\n  |  lea RC, [KBASE+RC*8]\n  |  lea RB, [BASE+RB*8]\n  |  xchg RB, RC\n  |  jmp >2\n  |\n  |->vmeta_unm:\n  |  lea RC, [BASE+RD*8]\n  |  mov RB, RC\n  |  jmp >2\n  |\n  |->vmeta_arith_vvo:\n  |.if DUALNUM\n  |  movzx RB, PC_RB\n  |.endif\n  |->vmeta_arith_vv:\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  lea RA, [BASE+RA*8]\n  |.if X64WIN\n  |  mov CARG3d, RB\n  |  mov CARG4d, RC\n  |  movzx RC, PC_OP\n  |  mov ARG5d, RC\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG2d, RA\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d == RA.\n  |.elif X64\n  |  movzx CARG5d, PC_OP\n  |  mov CARG2d, RA\n  |  mov CARG4d, RC\t\t\t// Caveat: CARG4d == RA.\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG3d, RB\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG3, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG4, RC\n  |  movzx RC, PC_OP\n  |  mov ARG2, RA\n  |  mov ARG5, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_arith\t// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = base, RC = new base, stack = cont/func/o1/o2\n  |  mov RA, RC\n  |  sub RC, BASE\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  lea PC, [RC+FRAME_CONT]\n  |  mov NARGS:RD, 2+1\t\t\t// 2 args for func(o1, o2).\n  |  jmp ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  lea FCARG2, [BASE+RD*8]\t\t// Caveat: FCARG2 == BASE\n  |  mov L:FCARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_len@8\t\t// (lua_State *L, TValue *o)\n  |  // NULL (retry) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n#if LJ_52\n  |  test RC, RC\n  |  jne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  movzx RD, PC_RD\n  |  mov TAB:FCARG1, [BASE+RD*8]\n  |  jmp ->BC_LEN_Z\n#else\n  |  jmp ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call_ra:\n  |  lea RA, [BASE+RA*8+8]\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return\n  |  mov TMP2, RA\t\t\t// Save RA, RC for us.\n  |  mov TMP1, NARGS:RD\n  |  sub RA, 8\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RA\n  |  lea CARG3d, [RA+NARGS:RD*8]\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n  |.else\n  |  lea RC, [RA+NARGS:RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov ARG2, RA\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\t\t// This is the callers base!\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  mov BASE, L:RB->base\n  |  mov RA, TMP2\n  |  mov NARGS:RD, TMP1\n  |  mov LFUNC:RB, [RA-8]\n  |  add NARGS:RD, 1\n  |  // This is fragile. L->base must not move, KBASE must always be defined.\n  |  cmp KBASE, BASE\t\t\t// Continue with CALLT if flag set.\n  |  je ->BC_CALLT_Z\n  |  mov BASE, RA\n  |  ins_call\t\t\t\t// Otherwise call resolved metamethod.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, RA\t\t\t// Caveat: FCARG2 == BASE\n  |  mov L:FCARG1, L:RB\t\t\t// Caveat: FCARG1 == RA\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_for@8\t// (lua_State *L, TValue *base)\n  |  mov BASE, L:RB->base\n  |  mov RC, [PC-4]\n  |  movzx RA, RCH\n  |  movzx OP, RCL\n  |  shr RC, 16\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |.else\n  |  jmp aword [DISPATCH+OP*4+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmp NARGS:RD, 1+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmp NARGS:RD, 2+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nsse, name, op\n  |  .ffunc_1 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  op xmm0, qword [BASE]\n  |.endmacro\n  |\n  |.macro .ffunc_nsse, name\n  |  .ffunc_nsse name, movsd\n  |.endmacro\n  |\n  |.macro .ffunc_nnsse, name\n  |  .ffunc_2 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM;  jae ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  movsd xmm1, qword [BASE+8]\n  |.endmacro\n  |\n  |.macro .ffunc_nnr, name\n  |  .ffunc_2 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM;  jae ->fff_fallback\n  |  fld qword [BASE+8]\n  |  fld qword [BASE]\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses label 1.\n  |.macro ffgccheck\n  |  mov RB, [DISPATCH+DISPATCH_GL(gc.total)]\n  |  cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]\n  |  jb >1\n  |  call ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  mov RB, [BASE+4]\n  |  cmp RB, LJ_TISTRUECOND;  jae ->fff_fallback\n  |  mov PC, [BASE-4]\n  |  mov MULTRES, RD\n  |  mov [BASE-4], RB\n  |  mov RB, [BASE]\n  |  mov [BASE-8], RB\n  |  sub RD, 2\n  |  jz >2\n  |  mov RA, BASE\n  |1:\n  |  add RA, 8\n  |.if X64\n  |  mov RBa, [RA]\n  |  mov [RA-8], RBa\n  |.else\n  |  mov RB, [RA+4]\n  |  mov [RA-4], RB\n  |  mov RB, [RA]\n  |  mov [RA-8], RB\n  |.endif\n  |  sub RD, 1\n  |  jnz <1\n  |2:\n  |  mov RD, MULTRES\n  |  jmp ->fff_res_\n  |\n  |.ffunc_1 type\n  |  mov RB, [BASE+4]\n  |.if X64\n  |  mov RA, RB\n  |  sar RA, 15\n  |  cmp RA, -2\n  |  je >3\n  |.endif\n  |  mov RC, ~LJ_TNUMX\n  |  not RB\n  |  cmp RC, RB\n  |  cmova RC, RB\n  |2:\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RC\n  |  jmp ->fff_res1\n  |.if X64\n  |3:\n  |  mov RC, ~LJ_TLIGHTUD\n  |  jmp <2\n  |.endif\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  mov RB, [BASE+4]\n  |  mov PC, [BASE-4]\n  |  cmp RB, LJ_TTAB;  jne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  mov TAB:RB, [BASE]\n  |  mov TAB:RB, TAB:RB->metatable\n  |2:\n  |  test TAB:RB, TAB:RB\n  |  mov dword [BASE-4], LJ_TNIL\n  |  jz ->fff_res1\n  |  mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)]\n  |  mov dword [BASE-4], LJ_TTAB\t// Store metatable as default result.\n  |  mov [BASE-8], TAB:RB\n  |  mov RA, TAB:RB->hmask\n  |  and RA, STR:RC->hash\n  |  imul RA, #NODE\n  |  add NODE:RA, TAB:RB->node\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  cmp dword NODE:RA->key.it, LJ_TSTR\n  |  jne >4\n  |  cmp dword NODE:RA->key.gcr, STR:RC\n  |  je >5\n  |4:\n  |  mov NODE:RA, NODE:RA->next\n  |  test NODE:RA, NODE:RA\n  |  jnz <3\n  |  jmp ->fff_res1\t\t\t// Not found, keep default result.\n  |5:\n  |  mov RB, [RA+4]\n  |  cmp RB, LJ_TNIL;  je ->fff_res1\t// Ditto for nil value.\n  |  mov RC, [RA]\n  |  mov [BASE-4], RB\t\t\t// Return value of mt.__metatable.\n  |  mov [BASE-8], RC\n  |  jmp ->fff_res1\n  |\n  |6:\n  |  cmp RB, LJ_TUDATA;  je <1\n  |.if X64\n  |  cmp RB, LJ_TNUMX;  ja >8\n  |  cmp RB, LJ_TISNUM;  jbe >7\n  |  mov RB, LJ_TLIGHTUD\n  |  jmp >8\n  |7:\n  |.else\n  |  cmp RB, LJ_TISNUM;  ja >8\n  |.endif\n  |  mov RB, LJ_TNUMX\n  |8:\n  |  not RB\n  |  mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  jmp <2\n  |\n  |.ffunc_2 setmetatable\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  mov TAB:RB, [BASE]\n  |  cmp dword TAB:RB->metatable, 0;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TTAB;  jne ->fff_fallback\n  |  mov TAB:RC, [BASE+8]\n  |  mov TAB:RB->metatable, TAB:RC\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TTAB\t\t// Return original table.\n  |  mov [BASE-8], TAB:RB\n  |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n  |  jz >1\n  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.\n  |  barrierback TAB:RB, RC\n  |1:\n  |  jmp ->fff_res1\n  |\n  |.ffunc_2 rawget\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |.if X64WIN\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3d, [BASE+8]\n  |  mov CARG2d, [BASE]\t\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG1d, SAVE_L\n  |.elif X64\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, [BASE]\n  |  lea CARG3d, [BASE+8]\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG1d, SAVE_L\n  |.else\n  |  mov TAB:RD, [BASE]\n  |  mov L:RB, SAVE_L\n  |  mov ARG2, TAB:RD\n  |  mov ARG1, L:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  add BASE, 8\n  |  mov ARG3, BASE\n  |.endif\n  |  call extern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |  // cTValue * returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  // Copy table slot.\n  |.if X64\n  |  mov RBa, [RD]\n  |  mov PC, [BASE-4]\n  |  mov [BASE-8], RBa\n  |.else\n  |  mov RB, [RD]\n  |  mov RD, [RD+4]\n  |  mov PC, [BASE-4]\n  |  mov [BASE-8], RB\n  |  mov [BASE-4], RD\n  |.endif\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\t// Exactly one argument.\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >1\n  |  mov RB, dword [BASE]; jmp ->fff_resi\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]; jmp ->fff_resxmm0\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  mov PC, [BASE-4]\n  |  cmp dword [BASE+4], LJ_TSTR;  jne >3\n  |  // A __tostring method in the string base metatable is ignored.\n  |  mov STR:RD, [BASE]\n  |2:\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RD\n  |  jmp ->fff_res1\n  |3:  // Handle numbers inline, unless a number base metatable is present.\n  |  cmp dword [BASE+4], LJ_TISNUM;  ja ->fff_fallback\n  |  cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0\n  |  jne ->fff_fallback\n  |  ffgccheck\t\t\t\t// Caveat: uses label 1.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |.if X64 and not X64WIN\n  |  mov FCARG2, BASE\t\t\t// Otherwise: FCARG2 == BASE\n  |.endif\n  |  mov L:FCARG1, L:RB\n  |.if DUALNUM\n  |  call extern lj_strfmt_number@8\t// (lua_State *L, cTValue *o)\n  |.else\n  |  call extern lj_strfmt_num@8\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // GCstr returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  jmp <2\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  je >2\t\t\t\t// Missing 2nd arg?\n  |1:\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov L:RB->top, BASE\t\t// Dummy frame length is ok.\n  |  mov PC, [BASE-4]\n  |.if X64WIN\n  |  lea CARG3d, [BASE+8]\n  |  mov CARG2d, [BASE]\t\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG1d, L:RB\n  |.elif X64\n  |  mov CARG2d, [BASE]\n  |  lea CARG3d, [BASE+8]\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov TAB:RD, [BASE]\n  |  mov ARG2, TAB:RD\n  |  mov ARG1, L:RB\n  |  add BASE, 8\n  |  mov ARG3, BASE\n  |.endif\n  |  mov SAVE_PC, PC\t\t\t// Needed for ITERN fallback.\n  |  call extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Flag returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  test RD, RD;  jz >3\t\t// End of traversal?\n  |  // Copy key and value to results.\n  |.if X64\n  |  mov RBa, [BASE+8]\n  |  mov RDa, [BASE+16]\n  |  mov [BASE-8], RBa\n  |  mov [BASE], RDa\n  |.else\n  |  mov RB, [BASE+8]\n  |  mov RD, [BASE+12]\n  |  mov [BASE-8], RB\n  |  mov [BASE-4], RD\n  |  mov RB, [BASE+16]\n  |  mov RD, [BASE+20]\n  |  mov [BASE], RB\n  |  mov [BASE+4], RD\n  |.endif\n  |->fff_res2:\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |2:  // Set missing 2nd arg to nil.\n  |  mov dword [BASE+12], LJ_TNIL\n  |  jmp <1\n  |3:  // End of traversal: return nil.\n  |  mov dword [BASE-4], LJ_TNIL\n  |  jmp ->fff_res1\n  |\n  |.ffunc_1 pairs\n  |  mov TAB:RB, [BASE]\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n#if LJ_52\n  |  cmp dword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov CFUNC:RD, CFUNC:RB->upvalue[0]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TFUNC\n  |  mov [BASE-8], CFUNC:RD\n  |  mov dword [BASE+12], LJ_TNIL\n  |  mov RD, 1+3\n  |  jmp ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  mov PC, [BASE-4]\n  |.if DUALNUM\n  |  mov RD, dword [BASE+8]\n  |  add RD, 1\n  |  mov dword [BASE-4], LJ_TISNUM\n  |  mov dword [BASE-8], RD\n  |.else\n  |  movsd xmm0, qword [BASE+8]\n  |  sseconst_1 xmm1, RBa\n  |  addsd xmm0, xmm1\n  |  cvttsd2si RD, xmm0\n  |  movsd qword [BASE-8], xmm0\n  |.endif\n  |  mov TAB:RB, [BASE]\n  |  cmp RD, TAB:RB->asize;  jae >2\t// Not in array part?\n  |  shl RD, 3\n  |  add RD, TAB:RB->array\n  |1:\n  |  cmp dword [RD+4], LJ_TNIL;  je ->fff_res0\n  |  // Copy array slot.\n  |.if X64\n  |  mov RBa, [RD]\n  |  mov [BASE], RBa\n  |.else\n  |  mov RB, [RD]\n  |  mov RD, [RD+4]\n  |  mov [BASE], RB\n  |  mov [BASE+4], RD\n  |.endif\n  |  jmp ->fff_res2\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cmp dword TAB:RB->hmask, 0; je ->fff_res0\n  |  mov FCARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov FCARG2, RD\t\t\t// Caveat: FCARG2 == BASE\n  |  call extern lj_tab_getinth@8\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RD).\n  |  mov BASE, RB\n  |  test RD, RD\n  |  jnz <1\n  |->fff_res0:\n  |  mov RD, 1+0\n  |  jmp ->fff_res\n  |\n  |.ffunc_1 ipairs\n  |  mov TAB:RB, [BASE]\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n#if LJ_52\n  |  cmp dword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov CFUNC:RD, CFUNC:RB->upvalue[0]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TFUNC\n  |  mov [BASE-8], CFUNC:RD\n  |.if DUALNUM\n  |  mov dword [BASE+12], LJ_TISNUM\n  |  mov dword [BASE+8], 0\n  |.else\n  |  xorps xmm0, xmm0\n  |  movsd qword [BASE+8], xmm0\n  |.endif\n  |  mov RD, 1+3\n  |  jmp ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc_1 pcall\n  |  lea RA, [BASE+8]\n  |  sub NARGS:RD, 1\n  |  mov PC, 8+FRAME_PCALL\n  |1:\n  |  movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  shr RB, HOOK_ACTIVE_SHIFT\n  |  and RB, 1\n  |  add PC, RB\t\t\t\t// Remember active hook before pcall.\n  |  jmp ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  cmp dword [BASE+12], LJ_TFUNC;  jne ->fff_fallback\n  |  mov RB, [BASE+4]\t\t\t// Swap function and traceback.\n  |  mov [BASE+12], RB\n  |  mov dword [BASE+4], LJ_TFUNC\n  |  mov LFUNC:RB, [BASE]\n  |  mov PC, [BASE+8]\n  |  mov [BASE+8], LFUNC:RB\n  |  mov [BASE], PC\n  |  lea RA, [BASE+16]\n  |  sub NARGS:RD, 2\n  |  mov PC, 16+FRAME_PCALL\n  |  jmp <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  mov L:RB, [BASE]\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov L:RB, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  mov PC, [BASE-4]\n  |  mov SAVE_PC, PC\n  |.if X64\n  |  mov TMP1, L:RB\n  |.else\n  |  mov ARG1, L:RB\n  |.endif\n  |.if resume\n  |  cmp dword [BASE+4], LJ_TTHREAD;  jne ->fff_fallback\n  |.endif\n  |  cmp aword L:RB->cframe, 0; jne ->fff_fallback\n  |  cmp byte L:RB->status, LUA_YIELD;  ja ->fff_fallback\n  |  mov RA, L:RB->top\n  |  je >1\t\t\t\t// Status != LUA_YIELD (i.e. 0)?\n  |  cmp RA, L:RB->base\t\t\t// Check for presence of initial func.\n  |  je ->fff_fallback\n  |1:\n  |.if resume\n  |  lea PC, [RA+NARGS:RD*8-16]\t\t// Check stack space (-1-thread).\n  |.else\n  |  lea PC, [RA+NARGS:RD*8-8]\t\t// Check stack space (-1).\n  |.endif\n  |  cmp PC, L:RB->maxstack; ja ->fff_fallback\n  |  mov L:RB->top, PC\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if resume\n  |  add BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |.endif\n  |  mov L:RB->top, BASE\n  |.if resume\n  |  lea RB, [BASE+NARGS:RD*8-24]\t// RB = end of source for stack move.\n  |.else\n  |  lea RB, [BASE+NARGS:RD*8-16]\t// RB = end of source for stack move.\n  |.endif\n  |  sub RBa, PCa\t\t\t// Relative to PC.\n  |\n  |  cmp PC, RA\n  |  je >3\n  |2:  // Move args to coroutine.\n  |.if X64\n  |  mov RCa, [PC+RB]\n  |  mov [PC-8], RCa\n  |.else\n  |  mov RC, [PC+RB+4]\n  |  mov [PC-4], RC\n  |  mov RC, [PC+RB]\n  |  mov [PC-8], RC\n  |.endif\n  |  sub PC, 8\n  |  cmp PC, RA\n  |  jne <2\n  |3:\n  |.if X64\n  |  mov CARG2d, RA\n  |  mov CARG1d, TMP1\n  |.else\n  |  mov ARG2, RA\n  |  xor RA, RA\n  |  mov ARG4, RA\n  |  mov ARG3, RA\n  |.endif\n  |  call ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |\n  |  mov L:RB, SAVE_L\n  |.if X64\n  |  mov L:PC, TMP1\n  |.else\n  |  mov L:PC, ARG1\t\t\t// The callee doesn't modify SAVE_L.\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |\n  |  cmp eax, LUA_YIELD\n  |  ja >8\n  |4:\n  |  mov RA, L:PC->base\n  |  mov KBASE, L:PC->top\n  |  mov L:PC->top, RA\t\t\t// Clear coroutine stack.\n  |  mov PC, KBASE\n  |  sub PC, RA\n  |  je >6\t\t\t\t// No results?\n  |  lea RD, [BASE+PC]\n  |  shr PC, 3\n  |  cmp RD, L:RB->maxstack\n  |  ja >9\t\t\t\t// Need to grow stack?\n  |\n  |  mov RB, BASE\n  |  sub RBa, RAa\n  |5:  // Move results from coroutine.\n  |.if X64\n  |  mov RDa, [RA]\n  |  mov [RA+RB], RDa\n  |.else\n  |  mov RD, [RA]\n  |  mov [RA+RB], RD\n  |  mov RD, [RA+4]\n  |  mov [RA+RB+4], RD\n  |.endif\n  |  add RA, 8\n  |  cmp RA, KBASE\n  |  jne <5\n  |6:\n  |.if resume\n  |  lea RD, [PC+2]\t\t\t// nresults+1 = 1 + true + results.\n  |  mov dword [BASE-4], LJ_TTRUE\t// Prepend true to results.\n  |.else\n  |  lea RD, [PC+1]\t\t\t// nresults+1 = 1 + results.\n  |.endif\n  |7:\n  |  mov PC, SAVE_PC\n  |  mov MULTRES, RD\n  |.if resume\n  |  mov RAa, -8\n  |.else\n  |  xor RA, RA\n  |.endif\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  mov dword [BASE-4], LJ_TFALSE\t// Prepend false to results.\n  |  mov RA, L:PC->top\n  |  sub RA, 8\n  |  mov L:PC->top, RA\t\t\t// Clear error from coroutine stack.\n  |  // Copy error message.\n  |.if X64\n  |  mov RDa, [RA]\n  |  mov [BASE], RDa\n  |.else\n  |  mov RD, [RA]\n  |  mov [BASE], RD\n  |  mov RD, [RA+4]\n  |  mov [BASE+4], RD\n  |.endif\n  |  mov RD, 1+2\t\t\t// nresults+1 = 1 + false + error.\n  |  jmp <7\n  |.else\n  |  mov FCARG2, L:PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_ffh_coroutine_wrap_err@8  // (lua_State *L, lua_State *co)\n  |  // Error function does not return.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |.if X64\n  |  mov L:RA, TMP1\n  |.else\n  |  mov L:RA, ARG1\t\t\t// The callee doesn't modify SAVE_L.\n  |.endif\n  |  mov L:RA->top, KBASE\t\t// Undo coroutine stack clearing.\n  |  mov FCARG2, PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |.if X64\n  |  mov L:PC, TMP1\n  |.else\n  |  mov L:PC, ARG1\n  |.endif\n  |  mov BASE, L:RB->base\n  |  jmp <4\t\t\t\t// Retry the stack move.\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  mov L:RB, SAVE_L\n  |  test aword L:RB->cframe, CFRAME_RESUME\n  |  jz ->fff_fallback\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB->top, RD\n  |  xor RD, RD\n  |  mov aword L:RB->cframe, RDa\n  |  mov al, LUA_YIELD\n  |  mov byte L:RB->status, al\n  |  jmp ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.if not DUALNUM\n  |->fff_resi:  // Dummy.\n  |.endif\n  |\n  |->fff_resn:\n  |  mov PC, [BASE-4]\n  |  fstp qword [BASE-8]\n  |  jmp ->fff_res1\n  |\n  |  .ffunc_1 math_abs\n  |.if DUALNUM\n  |  cmp dword [BASE+4], LJ_TISNUM; jne >2\n  |  mov RB, dword [BASE]\n  |  cmp RB, 0; jns ->fff_resi\n  |  neg RB; js >1\n  |->fff_resbit:\n  |->fff_resi:\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TISNUM\n  |  mov dword [BASE-8], RB\n  |  jmp ->fff_res1\n  |1:\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], 0x41e00000  // 2^31.\n  |  mov dword [BASE-8], 0\n  |  jmp ->fff_res1\n  |2:\n  |  ja ->fff_fallback\n  |.else\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  sseconst_abs xmm1, RDa\n  |  andps xmm0, xmm1\n  |->fff_resxmm0:\n  |  mov PC, [BASE-4]\n  |  movsd qword [BASE-8], xmm0\n  |  // fallthrough\n  |\n  |->fff_res1:\n  |  mov RD, 1+1\n  |->fff_res:\n  |  mov MULTRES, RD\n  |->fff_res_:\n  |  test PC, FRAME_TYPE\n  |  jnz >7\n  |5:\n  |  cmp PC_RB, RDL\t\t\t// More results expected?\n  |  ja >6\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  movzx RA, PC_RA\n  |  not RAa\t\t\t\t// Note: ~RA = -(RA+1)\n  |  lea BASE, [BASE+RA*8]\t\t// base = base - (RA+1)*8\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  mov dword [BASE+RD*8-12], LJ_TNIL\n  |  add RD, 1\n  |  jmp <5\n  |\n  |7:  // Non-standard return case.\n  |  mov RAa, -8\t\t\t// Results start at BASE+RA = BASE-8.\n  |  jmp ->vm_return\n  |\n  |.if X64\n  |.define fff_resfp, fff_resxmm0\n  |.else\n  |.define fff_resfp, fff_resn\n  |.endif\n  |\n  |.macro math_round, func\n  |  .ffunc math_ .. func\n  |.if DUALNUM\n  |  cmp dword [BASE+4], LJ_TISNUM; jne >1\n  |  mov RB, dword [BASE]; jmp ->fff_resi\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  call ->vm_ .. func .. _sse\n  |.if DUALNUM\n  |  cvttsd2si RB, xmm0\n  |  cmp RB, 0x80000000\n  |  jne ->fff_resi\n  |  cvtsi2sd xmm1, RB\n  |  ucomisd xmm0, xmm1\n  |  jp ->fff_resxmm0\n  |  je ->fff_resi\n  |.endif\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0\n  |\n  |.ffunc math_log\n  |  cmp NARGS:RD, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |.endif\n  |  mov RB, BASE\n  |  call extern log\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |\n  |.macro math_extern, func\n  |  .ffunc_nsse math_ .. func\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |.endif\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nnsse math_ .. func\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |  movsd FPARG3, xmm1\n  |.endif\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |.endmacro\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_nnr math_ldexp;\tfscale; fpop1;\tjmp ->fff_resn\n  |\n  |.ffunc_1 math_frexp\n  |  mov RB, [BASE+4]\n  |  cmp RB, LJ_TISNUM;  jae ->fff_fallback\n  |  mov PC, [BASE-4]\n  |  mov RC, [BASE]\n  |  mov [BASE-4], RB; mov [BASE-8], RC\n  |  shl RB, 1; cmp RB, 0xffe00000; jae >3\n  |  or RC, RB; jz >3\n  |  mov RC, 1022\n  |  cmp RB, 0x00200000; jb >4\n  |1:\n  |  shr RB, 21; sub RB, RC\t\t// Extract and unbias exponent.\n  |  cvtsi2sd xmm0, RB\n  |  mov RB, [BASE-4]\n  |  and RB, 0x800fffff\t\t\t// Mask off exponent.\n  |  or RB, 0x3fe00000\t\t\t// Put mantissa in range [0.5,1) or 0.\n  |  mov [BASE-4], RB\n  |2:\n  |  movsd qword [BASE], xmm0\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |3:  // Return +-0, +-Inf, NaN unmodified and an exponent of 0.\n  |  xorps xmm0, xmm0; jmp <2\n  |4:  // Handle denormals by multiplying with 2^54 and adjusting the bias.\n  |  movsd xmm0, qword [BASE]\n  |  sseconst_hi xmm1, RBa, 43500000  // 2^54.\n  |  mulsd xmm0, xmm1\n  |  movsd qword [BASE-8], xmm0\n  |  mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1\n  |\n  |.ffunc_nsse math_modf\n  |  mov RB, [BASE+4]\n  |  mov PC, [BASE-4]\n  |  shl RB, 1; cmp RB, 0xffe00000; je >4\t// +-Inf?\n  |  movaps xmm4, xmm0\n  |  call ->vm_trunc_sse\n  |  subsd xmm4, xmm0\n  |1:\n  |  movsd qword [BASE-8], xmm0\n  |  movsd qword [BASE], xmm4\n  |  mov RC, [BASE-4]; mov RB, [BASE+4]\n  |  xor RC, RB; js >3\t\t\t\t// Need to adjust sign?\n  |2:\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |3:\n  |  xor RB, 0x80000000; mov [BASE+4], RB\t// Flip sign of fraction.\n  |  jmp <2\n  |4:\n  |  xorps xmm4, xmm4; jmp <1\t\t\t// Return +-Inf and +-0.\n  |\n  |.macro math_minmax, name, cmovop, sseop\n  |  .ffunc name\n  |  mov RA, 2\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >4\n  |  mov RB, dword [BASE]\n  |1:  // Handle integers.\n  |  cmp RA, RD; jae ->fff_resi\n  |  cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3\n  |  cmp RB, dword [BASE+RA*8-8]\n  |  cmovop RB, dword [BASE+RA*8-8]\n  |  add RA, 1\n  |  jmp <1\n  |3:\n  |  ja ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  cvtsi2sd xmm0, RB\n  |  jmp >6\n  |4:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |\n  |  movsd xmm0, qword [BASE]\n  |5:  // Handle numbers or integers.\n  |  cmp RA, RD; jae ->fff_resxmm0\n  |  cmp dword [BASE+RA*8-4], LJ_TISNUM\n  |.if DUALNUM\n  |  jb >6\n  |  ja ->fff_fallback\n  |  cvtsi2sd xmm1, dword [BASE+RA*8-8]\n  |  jmp >7\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |6:\n  |  movsd xmm1, qword [BASE+RA*8-8]\n  |7:\n  |  sseop xmm0, xmm1\n  |  add RA, 1\n  |  jmp <5\n  |.endmacro\n  |\n  |  math_minmax math_min, cmovg, minsd\n  |  math_minmax math_max, cmovl, maxsd\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  mov STR:RB, [BASE]\n  |  mov PC, [BASE-4]\n  |  cmp dword STR:RB->len, 1\n  |  jb ->fff_res0\t\t\t// Return no results for empty string.\n  |  movzx RB, byte STR:RB[1]\n  |.if DUALNUM\n  |  jmp ->fff_resi\n  |.else\n  |  cvtsi2sd xmm0, RB; jmp ->fff_resxmm0\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\t// *Exactly* 1 arg.\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |  mov RB, dword [BASE]\n  |  cmp RB, 255;  ja ->fff_fallback\n  |  mov TMP2, RB\n  |.else\n  |  jae ->fff_fallback\n  |  cvttsd2si RB, qword [BASE]\n  |  cmp RB, 255;  ja ->fff_fallback\n  |  mov TMP2, RB\n  |.endif\n  |.if X64\n  |  mov TMP3, 1\n  |.else\n  |  mov ARG3, 1\n  |.endif\n  |  lea RDa, TMP2\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if X64\n  |  mov CARG3d, TMP3\t\t\t// Zero-extended to size_t.\n  |  mov CARG2, RDa\t\t\t// May be 64 bit ptr to stack.\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG2, RD\n  |  mov ARG1, L:RB\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // GCstr * returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RD\n  |  jmp ->fff_res1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  mov TMP2, -1\n  |  cmp NARGS:RD, 1+2;  jb ->fff_fallback\n  |  jna >1\n  |  cmp dword [BASE+20], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |  mov RB, dword [BASE+16]\n  |  mov TMP2, RB\n  |.else\n  |  jae ->fff_fallback\n  |  cvttsd2si RB, qword [BASE+16]\n  |  mov TMP2, RB\n  |.endif\n  |1:\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  mov STR:RB, [BASE]\n  |  mov TMP3, STR:RB\n  |  mov RB, STR:RB->len\n  |.if DUALNUM\n  |  mov RA, dword [BASE+8]\n  |.else\n  |  cvttsd2si RA, qword [BASE+8]\n  |.endif\n  |  mov RC, TMP2\n  |  cmp RB, RC\t\t\t\t// len < end? (unsigned compare)\n  |  jb >5\n  |2:\n  |  test RA, RA\t\t\t// start <= 0?\n  |  jle >7\n  |3:\n  |  mov STR:RB, TMP3\n  |  sub RC, RA\t\t\t\t// start > end?\n  |  jl ->fff_emptystr\n  |  lea RB, [STR:RB+RA+#STR-1]\n  |  add RC, 1\n  |4:\n  |.if X64\n  |  mov TMP3, RC\n  |.else\n  |  mov ARG3, RC\n  |.endif\n  |  mov RD, RB\n  |  jmp ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  jl >6\n  |  lea RC, [RC+RB+1]\t\t\t// end = end+(len+1)\n  |  jmp <2\n  |6:  // Overflow.\n  |  mov RC, RB\t\t\t\t// end = len\n  |  jmp <2\n  |\n  |7:  // Negative start or underflow.\n  |  je >8\n  |  add RA, RB\t\t\t\t// start = start+(len+1)\n  |  add RA, 1\n  |  jg <3\t\t\t\t// start > 0?\n  |8:  // Underflow.\n  |  mov RA, 1\t\t\t\t// start = 1\n  |  jmp <3\n  |\n  |->fff_emptystr:  // Range underflow.\n  |  xor RC, RC\t\t\t\t// Zero length. Any ptr in RB is ok.\n  |  jmp <4\n  |\n  |.macro ffstring_op, name\n  |  .ffunc_1 string_ .. name\n  |  ffgccheck\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  mov L:RB, SAVE_L\n  |   lea SBUF:FCARG1, [DISPATCH+DISPATCH_GL(tmpbuf)]\n  |  mov L:RB->base, BASE\n  |  mov STR:FCARG2, [BASE]\t\t// Caveat: FCARG2 == BASE\n  |   mov RC, SBUF:FCARG1->b\n  |   mov SBUF:FCARG1->L, L:RB\n  |   mov SBUF:FCARG1->p, RC\n  |  mov SAVE_PC, PC\n  |  call extern lj_buf_putstr_ .. name .. @8\n  |  mov FCARG1, eax\n  |  call extern lj_buf_tostr@4\n  |  jmp ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name, kind, fdef\n  |  fdef name\n  |.if kind == 2\n  |  sseconst_tobit xmm1, RBa\n  |.endif\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >1\n  |  mov RB, dword [BASE]\n  |.if kind > 0\n  |  jmp >2\n  |.else\n  |  jmp ->fff_resbit\n  |.endif\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |.if kind < 2\n  |  sseconst_tobit xmm1, RBa\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RB, xmm0\n  |2:\n  |.endmacro\n  |\n  |.macro .ffunc_bit, name, kind\n  |  .ffunc_bit name, kind, .ffunc_1\n  |.endmacro\n  |\n  |.ffunc_bit bit_tobit, 0\n  |  jmp ->fff_resbit\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name, 2\n  |  mov TMP2, NARGS:RD\t\t\t// Save for fallback.\n  |  lea RD, [BASE+NARGS:RD*8-16]\n  |1:\n  |  cmp RD, BASE\n  |  jbe ->fff_resbit\n  |  cmp dword [RD+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >2\n  |  ins RB, dword [RD]\n  |  sub RD, 8\n  |  jmp <1\n  |2:\n  |  ja ->fff_fallback_bit_op\n  |.else\n  |  jae ->fff_fallback_bit_op\n  |.endif\n  |  movsd xmm0, qword [RD]\n  |  addsd xmm0, xmm1\n  |  movd RA, xmm0\n  |  ins RB, RA\n  |  sub RD, 8\n  |  jmp <1\n  |.endmacro\n  |\n  |.ffunc_bit_op bit_band, and\n  |.ffunc_bit_op bit_bor, or\n  |.ffunc_bit_op bit_bxor, xor\n  |\n  |.ffunc_bit bit_bswap, 1\n  |  bswap RB\n  |  jmp ->fff_resbit\n  |\n  |.ffunc_bit bit_bnot, 1\n  |  not RB\n  |.if DUALNUM\n  |  jmp ->fff_resbit\n  |.else\n  |->fff_resbit:\n  |  cvtsi2sd xmm0, RB\n  |  jmp ->fff_resxmm0\n  |.endif\n  |\n  |->fff_fallback_bit_op:\n  |  mov NARGS:RD, TMP2\t\t\t// Restore for fallback\n  |  jmp ->fff_fallback\n  |\n  |.macro .ffunc_bit_sh, name, ins\n  |.if DUALNUM\n  |  .ffunc_bit name, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback\n  |  mov RA, dword [BASE+8]\n  |.else\n  |  .ffunc_nnsse name\n  |  sseconst_tobit xmm2, RBa\n  |  addsd xmm0, xmm2\n  |  addsd xmm1, xmm2\n  |  movd RB, xmm0\n  |  movd RA, xmm1\n  |.endif\n  |  ins RB, cl\t\t\t\t// Assumes RA is ecx.\n  |  jmp ->fff_resbit\n  |.endmacro\n  |\n  |.ffunc_bit_sh bit_lshift, shl\n  |.ffunc_bit_sh bit_rshift, shr\n  |.ffunc_bit_sh bit_arshift, sar\n  |.ffunc_bit_sh bit_rol, rol\n  |.ffunc_bit_sh bit_ror, ror\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback_2:\n  |  mov NARGS:RD, 1+2\t\t\t// Other args are ignored, anyway.\n  |  jmp ->fff_fallback\n  |->fff_fallback_1:\n  |  mov NARGS:RD, 1+1\t\t\t// Other args are ignored, anyway.\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RD = nargs+1\n  |  mov L:RB, SAVE_L\n  |  mov PC, [BASE-4]\t\t\t// Fallback may overwrite PC.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  lea RA, [RD+8*LUA_MINSTACK]\t// Ensure enough space for handler.\n  |  mov L:RB->top, RD\n  |  mov CFUNC:RD, [BASE-8]\n  |  cmp RA, L:RB->maxstack\n  |  ja >5\t\t\t\t// Need to grow stack.\n  |.if X64\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG1, L:RB\n  |.endif\n  |  call aword CFUNC:RD->f\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  test RD, RD;  jg ->fff_res\t\t// Returned nresults+1?\n  |1:\n  |  mov RA, L:RB->top\n  |  sub RA, BASE\n  |  shr RA, 3\n  |  test RD, RD\n  |  lea NARGS:RD, [RA+1]\n  |  mov LFUNC:RB, [BASE-8]\n  |  jne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  mov RA, BASE\n  |  test PC, FRAME_TYPE\n  |  jnz >3\n  |  movzx RB, PC_RA\n  |  not RBa\t\t\t\t// Note: ~RB = -(RB+1)\n  |  lea BASE, [BASE+RB*8]\t\t// base = base - (RB+1)*8\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |3:\n  |  mov RB, PC\n  |  and RB, -8\n  |  sub BASE, RB\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov FCARG2, LUA_MINSTACK\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  xor RD, RD\t\t\t\t// Simulate a return 0.\n  |  jmp <1\t\t\t\t// Dumb retry (goes through ff first).\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RD = nargs+1\n  |  pop RBa\t\t\t\t// Must keep stack at same level.\n  |  mov TMPa, RBa\t\t\t// Save return address\n  |  mov L:RB, SAVE_L\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov FCARG1, L:RB\n  |  mov L:RB->top, RD\n  |  call extern lj_gc_step@4\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  mov RBa, TMPa\n  |  push RBa\t\t\t\t// Restore return address.\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  jnz >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |  test RDL, HOOK_ACTIVE\n  |  jnz >1\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >1\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jmp >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |  jmp >1\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >5\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jz >1\n  |  test RDL, LUA_MASKLINE\n  |  jz >5\n  |1:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\t\t\t// Caveat: FCARG2 == BASE\n  |  mov FCARG1, L:RB\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call extern lj_dispatch_ins@8\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  mov BASE, L:RB->base\n  |4:\n  |  movzx RA, PC_RA\n  |5:\n  |  movzx OP, PC_OP\n  |  movzx RD, PC_RD\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |.else\n  |  jmp aword [DISPATCH+OP*4+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |.endif\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  add PC, 4\n  |  mov RA, [RB-24]\n  |  mov MULTRES, RA\t\t\t// Restore MULTRES for *M ins.\n  |  jmp <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  mov LFUNC:RB, [BASE-8]\t\t// Same as curr_topL(L).\n  |  mov RB, LFUNC:RB->pc\n  |  movzx RD, byte [RB+PC2PROTO(framesize)]\n  |  lea RD, [BASE+RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov FCARG2, PC\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  mov SAVE_PC, PC\n  |  call extern lj_trace_hot@8\t\t// (jit_State *J, const BCIns *pc)\n  |  jmp <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov SAVE_PC, PC\n  |.if JIT\n  |  jmp >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  mov SAVE_PC, PC\n  |  or PC, 1\t\t\t\t// Marker for hot call.\n  |1:\n  |.endif\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov FCARG2, PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_dispatch_call@8\t// (lua_State *L, const BCIns *pc)\n  |  // ASMFunction returned in eax/rax (RDa).\n  |  mov SAVE_PC, 0\t\t\t// Invalidate for subsequent line hook.\n  |.if JIT\n  |  and PC, -2\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov RAa, RDa\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  mov RBa, RAa\n  |  movzx RA, PC_RA\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  jmp RBa\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // BASE = base, RC = result, RB = mbase\n  |  mov TRACE:RA, [RB-24]\t\t// Save previous trace.\n  |  mov TMP1, TRACE:RA\n  |  mov TMP3, DISPATCH\t\t\t// Need one more register.\n  |  mov DISPATCH, MULTRES\n  |  movzx RA, PC_RA\n  |  lea RA, [BASE+RA*8]\t\t// Call base.\n  |  sub DISPATCH, 1\n  |  jz >2\n  |1:  // Move results down.\n  |.if X64\n  |  mov RBa, [RC]\n  |  mov [RA], RBa\n  |.else\n  |  mov RB, [RC]\n  |  mov [RA], RB\n  |  mov RB, [RC+4]\n  |  mov [RA+4], RB\n  |.endif\n  |  add RC, 8\n  |  add RA, 8\n  |  sub DISPATCH, 1\n  |  jnz <1\n  |2:\n  |  movzx RC, PC_RA\n  |  movzx RB, PC_RB\n  |  add RC, RB\n  |  lea RC, [BASE+RC*8-8]\n  |3:\n  |  cmp RC, RA\n  |  ja >9\t\t\t\t// More results wanted?\n  |\n  |  mov DISPATCH, TMP3\n  |  mov TRACE:RD, TMP1\t\t\t// Get previous trace.\n  |  movzx RB, word TRACE:RD->traceno\n  |  movzx RD, word TRACE:RD->link\n  |  cmp RD, RB\n  |  je ->cont_nop\t\t\t// Blacklisted.\n  |  test RD, RD\n  |  jne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  call extern lj_dispatch_stitch@8\t// (jit_State *J, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  jmp ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  mov dword [RA+4], LJ_TNIL\n  |  add RA, 8\n  |  jmp <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\t\t\t// Caveat: FCARG2 == BASE\n  |  mov FCARG1, L:RB\n  |  call extern lj_dispatch_profile@8\t// (lua_State *L, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  sub PC, 4\n  |  jmp ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Called from an exit stub with the exit number on the stack.\n  |// The 16 bit exit number is stored with two (sign-extended) push imm8.\n  |->vm_exit_handler:\n  |.if JIT\n  |.if X64\n  |  push r13; push r12\n  |  push r11; push r10; push r9; push r8\n  |  push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp\n  |  push rbx; push rdx; push rcx; push rax\n  |  movzx RC, byte [rbp-8]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [rbp-16]\n  |  mov [rbp-8], r15; mov [rbp-16], r14\n  |.else\n  |  push ebp; lea ebp, [esp+12]; push ebp\n  |  push ebx; push edx; push ecx; push eax\n  |  movzx RC, byte [ebp-4]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [ebp-8]\n  |  mov [ebp-4], edi; mov [ebp-8], esi\n  |.endif\n  |  // Caveat: DISPATCH is ebx.\n  |  mov DISPATCH, [ebp]\n  |  mov RA, [DISPATCH+DISPATCH_GL(vmstate)]\t// Get trace number.\n  |  set_vmstate EXIT\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RC\n  |  mov [DISPATCH+DISPATCH_J(parent)], RA\n  |.if X64\n  |.if X64WIN\n  |  sub rsp, 16*8+4*8\t\t\t// Room for SSE regs + save area.\n  |.else\n  |  sub rsp, 16*8\t\t\t// Room for SSE regs.\n  |.endif\n  |  add rbp, -128\n  |  movsd qword [rbp-8],   xmm15; movsd qword [rbp-16],  xmm14\n  |  movsd qword [rbp-24],  xmm13; movsd qword [rbp-32],  xmm12\n  |  movsd qword [rbp-40],  xmm11; movsd qword [rbp-48],  xmm10\n  |  movsd qword [rbp-56],  xmm9;  movsd qword [rbp-64],  xmm8\n  |  movsd qword [rbp-72],  xmm7;  movsd qword [rbp-80],  xmm6\n  |  movsd qword [rbp-88],  xmm5;  movsd qword [rbp-96],  xmm4\n  |  movsd qword [rbp-104], xmm3;  movsd qword [rbp-112], xmm2\n  |  movsd qword [rbp-120], xmm1;  movsd qword [rbp-128], xmm0\n  |.else\n  |  sub esp, 8*8+16\t\t\t// Room for SSE regs + args.\n  |  movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6\n  |  movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4\n  |  movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2\n  |  movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0\n  |.endif\n  |  // Caveat: RB is ebp.\n  |  mov L:RB, [DISPATCH+DISPATCH_GL(cur_L)]\n  |  mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  lea CARG2, [rsp+4*8]\n  |.elif X64\n  |  mov CARG2, rsp\n  |.else\n  |  lea FCARG2, [esp+16]\n  |.endif\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  call extern lj_trace_exit@8\t// (jit_State *J, ExitState *ex)\n  |  // MULTRES or negated error code returned in eax (RD).\n  |  mov RAa, L:RB->cframe\n  |  and RAa, CFRAME_RAWMASK\n  |.if X64WIN\n  |  // Reposition stack later.\n  |.elif X64\n  |  mov rsp, RAa\t\t\t// Reposition stack to C frame.\n  |.else\n  |  mov esp, RAa\t\t\t// Reposition stack to C frame.\n  |.endif\n  |  mov [RAa+CFRAME_OFS_L], L:RB\t// Set SAVE_L (on-trace resume/yield).\n  |  mov BASE, L:RB->base\n  |  mov PC, [RAa+CFRAME_OFS_PC]\t// Get SAVE_PC.\n  |.if X64\n  |  jmp >1\n  |.endif\n  |.endif\n  |->vm_exit_interp:\n  |  // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |.if X64\n  |  // Restore additional callee-save registers only used in compiled code.\n  |.if X64WIN\n  |  lea RAa, [rsp+9*16+4*8]\n  |1:\n  |  movdqa xmm15, [RAa-9*16]\n  |  movdqa xmm14, [RAa-8*16]\n  |  movdqa xmm13, [RAa-7*16]\n  |  movdqa xmm12, [RAa-6*16]\n  |  movdqa xmm11, [RAa-5*16]\n  |  movdqa xmm10, [RAa-4*16]\n  |  movdqa xmm9, [RAa-3*16]\n  |  movdqa xmm8, [RAa-2*16]\n  |  movdqa xmm7, [RAa-1*16]\n  |  mov rsp, RAa\t\t\t// Reposition stack to C frame.\n  |  movdqa xmm6, [RAa]\n  |  mov r15, CSAVE_3\n  |  mov r14, CSAVE_4\n  |.else\n  |  add rsp, 16\t\t\t// Reposition stack to C frame.\n  |1:\n  |.endif\n  |  mov r13, TMPa\n  |  mov r12, TMPQ\n  |.endif\n  |  test RD, RD; js >9\t\t\t// Check for error from exit.\n  |  mov L:RB, SAVE_L\n  |  mov MULTRES, RD\n  |  mov LFUNC:KBASE, [BASE-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  mov L:RB->base, BASE\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  set_vmstate INTERP\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  mov RC, [PC]\n  |  movzx RA, RCH\n  |  movzx OP, RCL\n  |  add PC, 4\n  |  shr RC, 16\n  |  cmp OP, BC_FUNCF\t\t\t// Function header?\n  |  jb >3\n  |  cmp OP, BC_FUNCC+2\t\t\t// Fast function?\n  |  jae >4\n  |2:\n  |  mov RC, MULTRES\t\t\t// RC/RD holds nres+1.\n  |3:\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8]\n  |.else\n  |  jmp aword [DISPATCH+OP*4]\n  |.endif\n  |\n  |4:  // Check frame below fast function.\n  |  mov RC, [BASE-4]\n  |  test RC, FRAME_TYPE\n  |  jnz <2\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  movzx RC, byte [RC-3]\n  |  not RCa\n  |  mov LFUNC:KBASE, [BASE+RC*8-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  jmp <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  neg RD\n  |  mov FCARG1, L:RB\n  |  mov FCARG2, RD\n  |  call extern lj_err_throw@8\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called by math.floor/math.ceil fast functions\n  |// and from JIT code. arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.\n  |.macro vm_round, name, mode, cond\n  |->name:\n  |.if not X64 and cond\n  |  movsd xmm0, qword [esp+4]\n  |  call ->name .. _sse\n  |  movsd qword [esp+4], xmm0  // Overwrite callee-owned arg.\n  |  fld qword [esp+4]\n  |  ret\n  |.endif\n  |\n  |->name .. _sse:\n  |  sseconst_abs xmm2, RDa\n  |  sseconst_2p52 xmm3, RDa\n  |  movaps xmm1, xmm0\n  |  andpd xmm1, xmm2\t\t\t// |x|\n  |  ucomisd xmm3, xmm1\t\t\t// No truncation if 2^52 <= |x|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |.if mode == 2\t\t// trunc(x)?\n  |  movaps xmm0, xmm1\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  sseconst_1 xmm3, RDa\n  |  cmpsd xmm0, xmm1, 1\t\t// |x| < result?\n  |  andpd xmm0, xmm3\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract -1.\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |.else\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |  .if mode == 1\t\t// ceil(x)?\n  |    sseconst_m1 xmm2, RDa\t\t// Must subtract -1 to preserve -0.\n  |    cmpsd xmm0, xmm1, 6\t\t// x > result?\n  |  .else\t\t\t// floor(x)?\n  |    sseconst_1 xmm2, RDa\n  |    cmpsd xmm0, xmm1, 1\t\t// x < result?\n  |  .endif\n  |  andpd xmm0, xmm2\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract +-1.\n  |.endif\n  |  movaps xmm0, xmm1\n  |1:\n  |  ret\n  |.endmacro\n  |\n  |  vm_round vm_floor, 0, 1\n  |  vm_round vm_ceil,  1, JIT\n  |  vm_round vm_trunc, 2, JIT\n  |\n  |// FP modulo x%y. Called by BC_MOD* and vm_arith.\n  |->vm_mod:\n  |// Args in xmm0/xmm1, return value in xmm0.\n  |// Caveat: xmm0-xmm5 and RC (eax) modified!\n  |  movaps xmm5, xmm0\n  |  divsd xmm0, xmm1\n  |  sseconst_abs xmm2, RDa\n  |  sseconst_2p52 xmm3, RDa\n  |  movaps xmm4, xmm0\n  |  andpd xmm4, xmm2\t\t\t// |x/y|\n  |  ucomisd xmm3, xmm4\t\t\t// No truncation if 2^52 <= |x/y|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |  addsd xmm4, xmm3\t\t\t// (|x/y| + 2^52) - 2^52\n  |  subsd xmm4, xmm3\n  |  orpd xmm4, xmm2\t\t\t// Merge sign bit back in.\n  |  sseconst_1 xmm2, RDa\n  |  cmpsd xmm0, xmm4, 1\t\t// x/y < result?\n  |  andpd xmm0, xmm2\n  |  subsd xmm4, xmm0\t\t\t// If yes, subtract 1.0.\n  |  movaps xmm0, xmm5\n  |  mulsd xmm1, xmm4\n  |  subsd xmm0, xmm1\n  |  ret\n  |1:\n  |  mulsd xmm1, xmm0\n  |  movaps xmm0, xmm5\n  |  subsd xmm0, xmm1\n  |  ret\n  |\n  |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.\n  |->vm_powi_sse:\n  |  cmp eax, 1; jle >6\t\t\t// i<=1?\n  |  // Now 1 < (unsigned)i <= 0x80000000.\n  |1:  // Handle leading zeros.\n  |  test eax, 1; jnz >2\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1\n  |  jmp <1\n  |2:\n  |  shr eax, 1; jz >5\n  |  movaps xmm1, xmm0\n  |3:  // Handle trailing bits.\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1; jz >4\n  |  jnc <3\n  |  mulsd xmm1, xmm0\n  |  jmp <3\n  |4:\n  |  mulsd xmm0, xmm1\n  |5:\n  |  ret\n  |6:\n  |  je <5\t\t\t\t// x^1 ==> x\n  |  jb >7\t\t\t\t// x^0 ==> 1\n  |  neg eax\n  |  call <1\n  |  sseconst_1 xmm1, RDa\n  |  divsd xmm1, xmm0\n  |  movaps xmm0, xmm1\n  |  ret\n  |7:\n  |  sseconst_1 xmm0, RDa\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])\n  |->vm_cpuid:\n  |.if X64\n  |  mov eax, CARG1d\n  |  .if X64WIN; push rsi; mov rsi, CARG2; .endif\n  |  push rbx\n  |  cpuid\n  |  mov [rsi], eax\n  |  mov [rsi+4], ebx\n  |  mov [rsi+8], ecx\n  |  mov [rsi+12], edx\n  |  pop rbx\n  |  .if X64WIN; pop rsi; .endif\n  |  ret\n  |.else\n  |  pushfd\n  |  pop edx\n  |  mov ecx, edx\n  |  xor edx, 0x00200000\t\t// Toggle ID bit in flags.\n  |  push edx\n  |  popfd\n  |  pushfd\n  |  pop edx\n  |  xor eax, eax\t\t\t// Zero means no features supported.\n  |  cmp ecx, edx\n  |  jz >1\t\t\t\t// No ID toggle means no CPUID support.\n  |  mov eax, [esp+4]\t\t\t// Argument 1 is function number.\n  |  push edi\n  |  push ebx\n  |  cpuid\n  |  mov edi, [esp+16]\t\t\t// Argument 2 is result area.\n  |  mov [edi], eax\n  |  mov [edi+4], ebx\n  |  mov [edi+8], ecx\n  |  mov [edi+12], edx\n  |  pop ebx\n  |  pop edi\n  |1:\n  |  ret\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Assertions ---------------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->assert_bad_for_arg_type:\n#ifdef LUA_USE_ASSERT\n  |  int3\n#endif\n  |  int3\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in ah/al.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |.if not X64\n  |  sub esp, 16\t\t\t// Leave room for SAVE_ERRF etc.\n  |.endif\n  |  saveregs_\t// ebp/rbp already saved. ebp now holds global_State *.\n  |  lea DISPATCH, [ebp+GG_G2DISP]\n  |  mov CTSTATE, GL:ebp->ctype_state\n  |  movzx eax, ax\n  |  mov CTSTATE->cb.slot, eax\n  |.if X64\n  |  mov CTSTATE->cb.gpr[0], CARG1\n  |  mov CTSTATE->cb.gpr[1], CARG2\n  |  mov CTSTATE->cb.gpr[2], CARG3\n  |  mov CTSTATE->cb.gpr[3], CARG4\n  |  movsd qword CTSTATE->cb.fpr[0], xmm0\n  |  movsd qword CTSTATE->cb.fpr[1], xmm1\n  |  movsd qword CTSTATE->cb.fpr[2], xmm2\n  |  movsd qword CTSTATE->cb.fpr[3], xmm3\n  |.if X64WIN\n  |  lea rax, [rsp+CFRAME_SIZE+4*8]\n  |.else\n  |  lea rax, [rsp+CFRAME_SIZE]\n  |  mov CTSTATE->cb.gpr[4], CARG5\n  |  mov CTSTATE->cb.gpr[5], CARG6\n  |  movsd qword CTSTATE->cb.fpr[4], xmm4\n  |  movsd qword CTSTATE->cb.fpr[5], xmm5\n  |  movsd qword CTSTATE->cb.fpr[6], xmm6\n  |  movsd qword CTSTATE->cb.fpr[7], xmm7\n  |.endif\n  |  mov CTSTATE->cb.stack, rax\n  |  mov CARG2, rsp\n  |.else\n  |  lea eax, [esp+CFRAME_SIZE+16]\n  |  mov CTSTATE->cb.gpr[0], FCARG1\n  |  mov CTSTATE->cb.gpr[1], FCARG2\n  |  mov CTSTATE->cb.stack, eax\n  |  mov FCARG1, [esp+CFRAME_SIZE+12]\t// Move around misplaced retaddr/ebp.\n  |  mov FCARG2, [esp+CFRAME_SIZE+8]\n  |  mov SAVE_RET, FCARG1\n  |  mov SAVE_R4, FCARG2\n  |  mov FCARG2, esp\n  |.endif\n  |  mov SAVE_PC, CTSTATE\t\t// Any value outside of bytecode is ok.\n  |  mov FCARG1, CTSTATE\n  |  call extern lj_ccallback_enter@8\t// (CTState *cts, void *cf)\n  |  // lua_State * returned in eax (RD).\n  |  set_vmstate INTERP\n  |  mov BASE, L:RD->base\n  |  mov RD, L:RD->top\n  |  sub RD, BASE\n  |  mov LFUNC:RB, [BASE-8]\n  |  shr RD, 3\n  |  add RD, 1\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  mov L:RA, SAVE_L\n  |  mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]\n  |  mov aword CTSTATE->L, L:RAa\n  |  mov L:RA->base, BASE\n  |  mov L:RA->top, RB\n  |  mov FCARG1, CTSTATE\n  |  mov FCARG2, RC\n  |  call extern lj_ccallback_leave@8\t// (CTState *cts, TValue *o)\n  |.if X64\n  |  mov rax, CTSTATE->cb.gpr[0]\n  |  movsd xmm0, qword CTSTATE->cb.fpr[0]\n  |  jmp ->vm_leave_unw\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov eax, CTSTATE->cb.gpr[0]\n  |  mov edx, CTSTATE->cb.gpr[1]\n  |  cmp dword CTSTATE->cb.gpr[2], 1\n  |  jb >7\n  |  je >6\n  |  fld qword CTSTATE->cb.fpr[0].d\n  |  jmp >7\n  |6:\n  |  fld dword CTSTATE->cb.fpr[0].f\n  |7:\n  |  mov ecx, L:RB->top\n  |  movzx ecx, word [ecx+6]\t\t// Get stack adjustment and copy up.\n  |  mov SAVE_L, ecx\t\t\t// Must be one slot above SAVE_RET\n  |  restoreregs\n  |  pop ecx\t\t\t\t// Move return addr from SAVE_RET.\n  |  add esp, [esp]\t\t\t// Adjust stack.\n  |  add esp, 16\n  |  push ecx\n  |  ret\n  |.endif\n  |.endif\n  |\n  |->vm_ffi_call@4:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |.if X64\n  |  .type CCSTATE, CCallState, rbx\n  |  push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1\n  |.else\n  |  .type CCSTATE, CCallState, ebx\n  |  push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1\n  |.endif\n  |\n  |  // Readjust stack.\n  |.if X64\n  |  mov eax, CCSTATE->spadj\n  |  sub rsp, rax\n  |.else\n  |  sub esp, CCSTATE->spadj\n  |.if WIN\n  |  mov CCSTATE->spadj, esp\n  |.endif\n  |.endif\n  |\n  |  // Copy stack slots.\n  |  movzx ecx, byte CCSTATE->nsp\n  |  sub ecx, 1\n  |  js >2\n  |1:\n  |.if X64\n  |  mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]\n  |  mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax\n  |.else\n  |  mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)]\n  |  mov [esp+ecx*4], eax\n  |.endif\n  |  sub ecx, 1\n  |  jns <1\n  |2:\n  |\n  |.if X64\n  |  movzx eax, byte CCSTATE->nfpr\n  |  mov CARG1, CCSTATE->gpr[0]\n  |  mov CARG2, CCSTATE->gpr[1]\n  |  mov CARG3, CCSTATE->gpr[2]\n  |  mov CARG4, CCSTATE->gpr[3]\n  |.if not X64WIN\n  |  mov CARG5, CCSTATE->gpr[4]\n  |  mov CARG6, CCSTATE->gpr[5]\n  |.endif\n  |  test eax, eax; jz >5\n  |  movaps xmm0, CCSTATE->fpr[0]\n  |  movaps xmm1, CCSTATE->fpr[1]\n  |  movaps xmm2, CCSTATE->fpr[2]\n  |  movaps xmm3, CCSTATE->fpr[3]\n  |.if not X64WIN\n  |  cmp eax, 4; jbe >5\n  |  movaps xmm4, CCSTATE->fpr[4]\n  |  movaps xmm5, CCSTATE->fpr[5]\n  |  movaps xmm6, CCSTATE->fpr[6]\n  |  movaps xmm7, CCSTATE->fpr[7]\n  |.endif\n  |5:\n  |.else\n  |  mov FCARG1, CCSTATE->gpr[0]\n  |  mov FCARG2, CCSTATE->gpr[1]\n  |.endif\n  |\n  |  call aword CCSTATE->func\n  |\n  |.if X64\n  |  mov CCSTATE->gpr[0], rax\n  |  movaps CCSTATE->fpr[0], xmm0\n  |.if not X64WIN\n  |  mov CCSTATE->gpr[1], rdx\n  |  movaps CCSTATE->fpr[1], xmm1\n  |.endif\n  |.else\n  |  mov CCSTATE->gpr[0], eax\n  |  mov CCSTATE->gpr[1], edx\n  |  cmp byte CCSTATE->resx87, 1\n  |  jb >7\n  |  je >6\n  |  fstp qword CCSTATE->fpr[0].d[0]\n  |  jmp >7\n  |6:\n  |  fstp dword CCSTATE->fpr[0].f[0]\n  |7:\n  |.if WIN\n  |  sub CCSTATE->spadj, esp\n  |.endif\n  |.endif\n  |\n  |.if X64\n  |  mov rbx, [rbp-8]; leave; ret\n  |.else\n  |  mov ebx, [ebp-4]; leave; ret\n  |.endif\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |// Note: aligning all instructions does not pay off.\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  |.macro jmp_comp, lt, ge, le, gt, target\n  ||switch (op) {\n  ||case BC_ISLT:\n  |   lt target\n  ||break;\n  ||case BC_ISGE:\n  |   ge target\n  ||break;\n  ||case BC_ISLE:\n  |   le target\n  ||break;\n  ||case BC_ISGT:\n  |   gt target\n  ||break;\n  ||default: break;  /* Shut up GCC. */\n  ||}\n  |.endmacro\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RD = src2, JMP with RD = target\n    |  ins_AD\n    |.if DUALNUM\n    |  checkint RA, >7\n    |  checkint RD, >8\n    |  mov RB, dword [BASE+RA*8]\n    |  add PC, 4\n    |  cmp RB, dword [BASE+RD*8]\n    |  jmp_comp jge, jl, jg, jle, >9\n    |6:\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is a number.\n    |  cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, dword [BASE+RD*8]\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm1, dword [BASE+RA*8]\n    |  movsd xmm0, qword [BASE+RD*8]\n    |  add PC, 4\n    |  ucomisd xmm0, xmm1\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  checknum RA, ->vmeta_comp\n    |  checknum RD, ->vmeta_comp\n    |.endif\n    |1:\n    |  movsd xmm0, qword [BASE+RD*8]\n    |2:\n    |  add PC, 4\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |3:\n    |  // Unordered: all of ZF CF PF set, ordered: PF clear.\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    |.if DUALNUM\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  jmp_comp jbe, ja, jb, jae, >1\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  ins_AD\t// RA = src1, RD = src2, JMP with RD = target\n    |  mov RB, [BASE+RD*8+4]\n    |  add PC, 4\n    |.if DUALNUM\n    |  cmp RB, LJ_TISNUM; jne >7\n    |  checkint RA, >8\n    |  mov RB, dword [BASE+RD*8]\n    |  cmp RB, dword [BASE+RA*8]\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RD is not an integer.\n    |  ja >5\n    |  // RD is a number.\n    |  cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5\n    |  // RD is a number, RA is an integer.\n    |  cvtsi2sd xmm0, dword [BASE+RA*8]\n    |  jmp >2\n    |\n    |8:  // RD is an integer, RA is not an integer.\n    |  ja >5\n    |  // RD is an integer, RA is a number.\n    |  cvtsi2sd xmm0, dword [BASE+RD*8]\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |  jmp >4\n    |\n    |.else\n    |  cmp RB, LJ_TISNUM; jae >5\n    |  checknum RA, >5\n    |.endif\n    |1:\n    |  movsd xmm0, qword [BASE+RA*8]\n    |2:\n    |  ucomisd xmm0, qword [BASE+RD*8]\n    |4:\n  iseqne_fp:\n    if (vk) {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  jne >2\n    } else {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  je >1\n    }\n  iseqne_end:\n    if (vk) {\n      |1:\t\t\t\t// EQ: Branch to the target.\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\t\t\t\t// NE: Fallthrough to next instruction.\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |.if not FFI\n      |3:\n      |.endif\n      |2:\t\t\t\t// NE: Branch to the target.\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |1:\t\t\t\t// EQ: Fallthrough to next instruction.\n    }\n    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||\n\t\t       op == BC_ISEQN || op == BC_ISNEN)) {\n      |  jmp <9\n    } else {\n      |  ins_next\n    }\n    |\n    if (op == BC_ISEQV || op == BC_ISNEV) {\n      |5:  // Either or both types are not numbers.\n      |.if FFI\n      |  cmp RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  checktp RA, LJ_TCDATA; je ->vmeta_equal_cd\n      |.endif\n      |  checktp RA, RB\t\t\t// Compare types.\n      |  jne <2\t\t\t\t// Not the same type?\n      |  cmp RB, LJ_TISPRI\n      |  jae <1\t\t\t\t// Same type and primitive type?\n      |\n      |  // Same types and not a primitive type. Compare GCobj or pvalue.\n      |  mov RA, [BASE+RA*8]\n      |  mov RD, [BASE+RD*8]\n      |  cmp RA, RD\n      |  je <1\t\t\t\t// Same GCobjs or pvalues?\n      |  cmp RB, LJ_TISTABUD\n      |  ja <2\t\t\t\t// Different objects and not table/ud?\n      |.if X64\n      |  cmp RB, LJ_TUDATA\t\t// And not 64 bit lightuserdata.\n      |  jb <2\n      |.endif\n      |\n      |  // Different tables or userdatas. Need to check __eq metamethod.\n      |  // Field metatable must be at same offset for GCtab and GCudata!\n      |  mov TAB:RB, TAB:RA->metatable\n      |  test TAB:RB, TAB:RB\n      |  jz <2\t\t\t\t// No metatable?\n      |  test byte TAB:RB->nomm, 1<<MM_eq\n      |  jnz <2\t\t\t\t// Or 'no __eq' flag set?\n      if (vk) {\n\t|  xor RB, RB\t\t\t// ne = 0\n      } else {\n\t|  mov RB, 1\t\t\t// ne = 1\n      }\n      |  jmp ->vmeta_equal\t\t// Handle __eq metamethod.\n    } else {\n      |.if FFI\n      |3:\n      |  cmp RB, LJ_TCDATA\n      if (LJ_DUALNUM && vk) {\n\t|  jne <9\n      } else {\n\t|  jne <2\n      }\n      |  jmp ->vmeta_equal_cd\n      |.endif\n    }\n    break;\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  ins_AND\t// RA = src, RD = str const, JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |  cmp RB, LJ_TSTR; jne >3\n    |  mov RA, [BASE+RA*8]\n    |  cmp RA, [KBASE+RD*4]\n  iseqne_test:\n    if (vk) {\n      |  jne >2\n    } else {\n      |  je >1\n    }\n    goto iseqne_end;\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  ins_AD\t// RA = src, RD = num const, JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |.if DUALNUM\n    |  cmp RB, LJ_TISNUM; jne >7\n    |  cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8\n    |  mov RB, dword [KBASE+RD*8]\n    |  cmp RB, dword [BASE+RA*8]\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja >3\n    |  // RA is a number.\n    |  cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, dword [KBASE+RD*8]\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm0, dword [BASE+RA*8]\n    |  ucomisd xmm0, qword [KBASE+RD*8]\n    |  jmp >4\n    |.else\n    |  cmp RB, LJ_TISNUM; jae >3\n    |.endif\n    |1:\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |2:\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |4:\n    goto iseqne_fp;\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  ins_AND\t// RA = src, RD = primitive type (~), JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |  cmp RB, RD\n    if (!LJ_HASFFI) goto iseqne_test;\n    if (vk) {\n      |  jne >3\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n      |3:\n      |  cmp RB, LJ_TCDATA; jne <2\n      |  jmp ->vmeta_equal_cd\n    } else {\n      |  je >2\n      |  cmp RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  ins_AD\t// RA = dst or unused, RD = src, JMP with RD = target\n    |  mov RB, [BASE+RD*8+4]\n    |  add PC, 4\n    |  cmp RB, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISTC) {\n      |  jae >1\n    } else {\n      |  jb >1\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov [BASE+RA*8+4], RB\n      |  mov RB, [BASE+RD*8]\n      |  mov [BASE+RA*8], RB\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |1:\t\t\t\t\t// Fallthrough to the next instruction.\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  ins_AD\t// RA = src, RD = -type\n    |  add RD, [BASE+RA*8+4]\n    |  jne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  ins_AD\t// RA = src, RD = -(TISNUM-1)\n    |  checknum RA, ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  ins_AD\t// RA = dst, RD = src\n    |.if X64\n    |  mov RBa, [BASE+RD*8]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [BASE+RD*8+4]\n    |  mov RD, [BASE+RD*8]\n    |  mov [BASE+RA*8+4], RB\n    |  mov [BASE+RA*8], RD\n    |.endif\n    |  ins_next_\n    break;\n  case BC_NOT:\n    |  ins_AD\t// RA = dst, RD = src\n    |  xor RB, RB\n    |  checktp RD, LJ_TISTRUECOND\n    |  adc RB, LJ_TTRUE\n    |  mov [BASE+RA*8+4], RB\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  ins_AD\t// RA = dst, RD = src\n    |.if DUALNUM\n    |  checkint RD, >5\n    |  mov RB, [BASE+RD*8]\n    |  neg RB\n    |  jo >4\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RB\n    |9:\n    |  ins_next\n    |4:\n    |  mov dword [BASE+RA*8+4], 0x41e00000  // 2^31.\n    |  mov dword [BASE+RA*8], 0\n    |  jmp <9\n    |5:\n    |  ja ->vmeta_unm\n    |.else\n    |  checknum RD, ->vmeta_unm\n    |.endif\n    |  movsd xmm0, qword [BASE+RD*8]\n    |  sseconst_sign xmm1, RDa\n    |  xorps xmm0, xmm1\n    |  movsd qword [BASE+RA*8], xmm0\n    |.if DUALNUM\n    |  jmp <9\n    |.else\n    |  ins_next\n    |.endif\n    break;\n  case BC_LEN:\n    |  ins_AD\t// RA = dst, RD = src\n    |  checkstr RD, >2\n    |  mov STR:RD, [BASE+RD*8]\n    |.if DUALNUM\n    |  mov RD, dword STR:RD->len\n    |1:\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RD\n    |.else\n    |  xorps xmm0, xmm0\n    |  cvtsi2sd xmm0, dword STR:RD->len\n    |1:\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    |2:\n    |  checktab RD, ->vmeta_len\n    |  mov TAB:FCARG1, [BASE+RD*8]\n#if LJ_52\n    |  mov TAB:RB, TAB:FCARG1->metatable\n    |  cmp TAB:RB, 0\n    |  jnz >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |  call extern lj_tab_len@4\t\t// (GCtab *t)\n    |  // Length of table returned in eax (RD).\n    |.if DUALNUM\n    |  // Nothing to do.\n    |.else\n    |  cvtsi2sd xmm0, RD\n    |.endif\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  movzx RA, PC_RA\n    |  jmp <1\n#if LJ_52\n    |9:  // Check for __len.\n    |  test byte TAB:RB->nomm, 1<<MM_len\n    |  jnz <3\n    |  jmp ->vmeta_len\t\t\t// 'no __len' flag NOT set: check.\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre, sseins, ssereg\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checknum RB, ->vmeta_arith_vn\n    |   .if DUALNUM\n    |     cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn\n    |   .endif\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [KBASE+RC*8]\n    ||  break;\n    ||case 1:\n    |   checknum RB, ->vmeta_arith_nv\n    |   .if DUALNUM\n    |     cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv\n    |   .endif\n    |   movsd xmm0, qword [KBASE+RC*8]\n    |   sseins ssereg, qword [BASE+RB*8]\n    ||  break;\n    ||default:\n    |   checknum RB, ->vmeta_arith_vv\n    |   checknum RC, ->vmeta_arith_vv\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [BASE+RC*8]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checkint RB, ->vmeta_arith_vn\n    |   cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn\n    |   mov RB, [BASE+RB*8]\n    |   intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno\n    ||  break;\n    ||case 1:\n    |   checkint RB, ->vmeta_arith_nv\n    |   cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv\n    |   mov RC, [KBASE+RC*8]\n    |   intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo\n    ||  break;\n    ||default:\n    |   checkint RB, ->vmeta_arith_vv\n    |   checkint RC, ->vmeta_arith_vv\n    |   mov RB, [BASE+RB*8]\n    |   intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo\n    ||  break;\n    ||}\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    ||if (vk == 1) {\n    |   mov dword [BASE+RA*8], RC\n    ||} else {\n    |   mov dword [BASE+RA*8], RB\n    ||}\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arithpost\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endmacro\n    |\n    |.macro ins_arith, sseins\n    |  ins_arithpre sseins, xmm0\n    |  ins_arithpost\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arith, intins, sseins\n    |.if DUALNUM\n    |  ins_arithdn intins\n    |.else\n    |  ins_arith, sseins\n    |.endif\n    |.endmacro\n\n    |  // RA = dst, RB = src1 or num const, RC = src2 or num const\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith add, addsd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith sub, subsd\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith imul, mulsd\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arith divsd\n    break;\n  case BC_MODVN:\n    |  ins_arithpre movsd, xmm1\n    |->BC_MODVN_Z:\n    |  call ->vm_mod\n    |  ins_arithpost\n    |  ins_next\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre movsd, xmm1\n    |  jmp ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    break;\n  case BC_POW:\n    |  ins_arithpre movsd, xmm1\n    |  mov RB, BASE\n    |.if not X64\n    |  movsd FPARG1, xmm0\n    |  movsd FPARG3, xmm1\n    |.endif\n    |  call extern pow\n    |  movzx RA, PC_RA\n    |  mov BASE, RB\n    |.if X64\n    |  ins_arithpost\n    |.else\n    |  fstp qword [BASE+RA*8]\n    |.endif\n    |  ins_next\n    break;\n\n  case BC_CAT:\n    |  ins_ABC\t// RA = dst, RB = src_start, RC = src_end\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\n    |  lea CARG2d, [BASE+RC*8]\n    |  mov CARG3d, RC\n    |  sub CARG3d, RB\n    |->BC_CAT_Z:\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  lea RA, [BASE+RC*8]\n    |  sub RC, RB\n    |  mov ARG2, RA\n    |  mov ARG3, RC\n    |->BC_CAT_Z:\n    |  mov L:RB, SAVE_L\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  test RC, RC\n    |  jnz ->vmeta_binop\n    |  movzx RB, PC_RB\t\t\t// Copy result to Stk[RA] from Stk[RB].\n    |  movzx RA, PC_RA\n    |.if X64\n    |  mov RCa, [BASE+RB*8]\n    |  mov [BASE+RA*8], RCa\n    |.else\n    |  mov RC, [BASE+RB*8+4]\n    |  mov RB, [BASE+RB*8]\n    |  mov [BASE+RA*8+4], RC\n    |  mov [BASE+RA*8], RB\n    |.endif\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov RD, [KBASE+RD*4]\n    |  mov dword [BASE+RA*8+4], LJ_TSTR\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  ins_AND\t// RA = dst, RD = cdata const (~)\n    |  mov RD, [KBASE+RD*4]\n    |  mov dword [BASE+RA*8+4], LJ_TCDATA\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  ins_AD\t// RA = dst, RD = signed int16 literal\n    |.if DUALNUM\n    |  movsx RD, RDW\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RD\n    |.else\n    |  movsx RD, RDW\t\t\t// Sign-extend literal.\n    |  cvtsi2sd xmm0, RD\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  ins_AD\t// RA = dst, RD = num const\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  movsd qword [BASE+RA*8], xmm0\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  ins_AND\t// RA = dst, RD = primitive type (~)\n    |  mov [BASE+RA*8+4], RD\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  ins_AD\t// RA = dst_start, RD = dst_end\n    |  lea RA, [BASE+RA*8+12]\n    |  lea RD, [BASE+RD*8+4]\n    |  mov RB, LJ_TNIL\n    |  mov [RA-8], RB\t\t\t// Sets minimum 2 slots.\n    |1:\n    |  mov [RA], RB\n    |  add RA, 8\n    |  cmp RA, RD\n    |  jbe <1\n    |  ins_next\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  ins_AD\t// RA = dst, RD = upvalue #\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)]\n    |  mov RB, UPVAL:RB->v\n    |.if X64\n    |  mov RDa, [RB]\n    |  mov [BASE+RA*8], RDa\n    |.else\n    |  mov RD, [RB+4]\n    |  mov RB, [RB]\n    |  mov [BASE+RA*8+4], RD\n    |  mov [BASE+RA*8], RB\n    |.endif\n    |  ins_next\n    break;\n  case BC_USETV:\n#define TV2MARKOFS \\\n ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))\n    |  ins_AD\t// RA = upvalue #, RD = src\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  cmp byte UPVAL:RB->closed, 0\n    |  mov RB, UPVAL:RB->v\n    |  mov RA, [BASE+RD*8]\n    |  mov RD, [BASE+RD*8+4]\n    |  mov [RB], RA\n    |  mov [RB+4], RD\n    |  jz >1\n    |  // Check barrier for closed upvalue.\n    |  test byte [RB+TV2MARKOFS], LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Upvalue is black. Check if new value is collectable and white.\n    |  sub RD, LJ_TISGCV\n    |  cmp RD, LJ_TNUMX - LJ_TISGCV\t\t\t// tvisgcv(v)\n    |  jbe <1\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(v)\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if X64 and not X64WIN\n    |  mov FCARG2, RB\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |.else\n    |  xchg FCARG2, RB\t\t\t// Save BASE (FCARG2 == BASE).\n    |.endif\n    |  lea GL:FCARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv@8\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n#undef TV2MARKOFS\n  case BC_USETS:\n    |  ins_AND\t// RA = upvalue #, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov GCOBJ:RA, [KBASE+RD*4]\n    |  mov RD, UPVAL:RB->v\n    |  mov [RD], GCOBJ:RA\n    |  mov dword [RD+4], LJ_TSTR\n    |  test byte UPVAL:RB->marked, LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(str)\n    |  jz <1\n    |  cmp byte UPVAL:RB->closed, 0\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov RB, BASE\t\t\t// Save BASE (FCARG2 == BASE).\n    |  mov FCARG2, RD\n    |  lea GL:FCARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv@8\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n  case BC_USETN:\n    |  ins_AD\t// RA = upvalue #, RD = num const\n    |  mov LFUNC:RB, [BASE-8]\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  movsd qword [RA], xmm0\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  ins_AND\t// RA = upvalue #, RD = primitive type (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  mov [RA+4], RD\n    |  ins_next\n    break;\n  case BC_UCLO:\n    |  ins_AD\t// RA = level, RD = target\n    |  branchPC RD\t\t\t// Do this first to free RD.\n    |  mov L:RB, SAVE_L\n    |  cmp dword L:RB->openupval, 0\n    |  je >1\n    |  mov L:RB->base, BASE\n    |  lea FCARG2, [BASE+RA*8]\t\t// Caveat: FCARG2 == BASE\n    |  mov L:FCARG1, L:RB\t\t// Caveat: FCARG1 == RA\n    |  call extern lj_func_closeuv@8\t// (lua_State *L, TValue *level)\n    |  mov BASE, L:RB->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  ins_AND\t// RA = dst, RD = proto const (~) (holding function prototype)\n    |.if X64\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n    |  mov CARG3d, [BASE-8]\n    |  mov CARG2d, [KBASE+RD*4]\t\t// Fetch GCproto *.\n    |  mov CARG1d, L:RB\n    |.else\n    |  mov LFUNC:RA, [BASE-8]\n    |  mov PROTO:RD, [KBASE+RD*4]\t// Fetch GCproto *.\n    |  mov L:RB, SAVE_L\n    |  mov ARG3, LFUNC:RA\n    |  mov ARG2, PROTO:RD\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call extern lj_func_newL_gc\n    |  // GCfuncL * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], LFUNC:RC\n    |  mov dword [BASE+RA*8+4], LJ_TFUNC\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n    |  ins_AD\t// RA = dst, RD = hbits|asize\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov SAVE_PC, PC\n    |  jae >5\n    |1:\n    |.if X64\n    |  mov CARG3d, RD\n    |  and RD, 0x7ff\n    |  shr CARG3d, 11\n    |.else\n    |  mov RA, RD\n    |  and RD, 0x7ff\n    |  shr RA, 11\n    |  mov ARG3, RA\n    |.endif\n    |  cmp RD, 0x7ff\n    |  je >3\n    |2:\n    |.if X64\n    |  mov L:CARG1d, L:RB\n    |  mov CARG2d, RD\n    |.else\n    |  mov ARG1, L:RB\n    |  mov ARG2, RD\n    |.endif\n    |  call extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], TAB:RC\n    |  mov dword [BASE+RA*8+4], LJ_TTAB\n    |  ins_next\n    |3:  // Turn 0x7ff into 0x801.\n    |  mov RD, 0x801\n    |  jmp <2\n    |5:\n    |  mov L:FCARG1, L:RB\n    |  call extern lj_gc_step_fixtop@4\t// (lua_State *L)\n    |  movzx RD, PC_RD\n    |  jmp <1\n    break;\n  case BC_TDUP:\n    |  ins_AND\t// RA = dst, RD = table const (~) (holding template table)\n    |  mov L:RB, SAVE_L\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  mov SAVE_PC, PC\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov L:RB->base, BASE\n    |  jae >3\n    |2:\n    |  mov TAB:FCARG2, [KBASE+RD*4]\t// Caveat: FCARG2 == BASE\n    |  mov L:FCARG1, L:RB\t\t// Caveat: FCARG1 == RA\n    |  call extern lj_tab_dup@8\t\t// (lua_State *L, Table *kt)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], TAB:RC\n    |  mov dword [BASE+RA*8+4], LJ_TTAB\n    |  ins_next\n    |3:\n    |  mov L:FCARG1, L:RB\n    |  call extern lj_gc_step_fixtop@4\t// (lua_State *L)\n    |  movzx RD, PC_RD\t\t\t// Need to reload RD.\n    |  not RDa\n    |  jmp <2\n    break;\n\n  case BC_GGET:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*4]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_GSET:\n    |  ins_AND\t// RA = src, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*4]\n    |  jmp ->BC_TSETS_Z\n    break;\n\n  case BC_TGETV:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  checktab RB, ->vmeta_tgetv\n    |  mov TAB:RB, [BASE+RB*8]\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movsd xmm0, qword [BASE+RC*8]\n    |  cvttsd2si RC, xmm0\n    |  cvtsi2sd xmm1, RC\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tgetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RC, TAB:RB->asize\t// Takes care of unordered, too.\n    |  jae ->vmeta_tgetv\t\t// Not in array part? Use fallback.\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |  // Get array slot.\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |1:\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz >3\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetv\t\t\t// 'no __index' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |3:\n    |  mov dword [BASE+RA*8+4], LJ_TNIL\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  checkstr RC, ->vmeta_tgetv\n    |  mov STR:RC, [BASE+RC*8]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  ins_ABC\t// RA = dst, RB = table, RC = str const (~)\n    |  not RCa\n    |  mov STR:RC, [KBASE+RC*4]\n    |  checktab RB, ->vmeta_tgets\n    |  mov TAB:RB, [BASE+RB*8]\n    |->BC_TGETS_Z:\t// RB = GCtab *, RC = GCstr *, refetches PC_RA.\n    |  mov RA, TAB:RB->hmask\n    |  and RA, STR:RC->hash\n    |  imul RA, #NODE\n    |  add NODE:RA, TAB:RB->node\n    |1:\n    |  cmp dword NODE:RA->key.it, LJ_TSTR\n    |  jne >4\n    |  cmp dword NODE:RA->key.gcr, STR:RC\n    |  jne >4\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp dword [RA+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >5\t\t\t\t// Key found, but nil value?\n    |  movzx RC, PC_RA\n    |  // Get node value.\n    |.if X64\n    |  mov RBa, [RA]\n    |  mov [BASE+RC*8], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov RA, [RA+4]\n    |  mov [BASE+RC*8], RB\n    |  mov [BASE+RC*8+4], RA\n    |.endif\n    |2:\n    |  ins_next\n    |\n    |3:\n    |  movzx RC, PC_RA\n    |  mov dword [BASE+RC*8+4], LJ_TNIL\n    |  jmp <2\n    |\n    |4:  // Follow hash chain.\n    |  mov NODE:RA, NODE:RA->next\n    |  test NODE:RA, NODE:RA\n    |  jnz <1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test TAB:RA, TAB:RA\n    |  jz <3\t\t\t\t// No metatable: done.\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jnz <3\t\t\t\t// 'no __index' flag set: done.\n    |  jmp ->vmeta_tgets\t\t// Caveat: preserve STR:RC.\n    break;\n  case BC_TGETB:\n    |  ins_ABC\t// RA = dst, RB = table, RC = byte literal\n    |  checktab RB, ->vmeta_tgetb\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tgetb\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |  // Get array slot.\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |1:\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz >3\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetb\t\t\t// 'no __index' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |3:\n    |  mov dword [BASE+RA*8+4], LJ_TNIL\n    |  jmp <1\n    break;\n  case BC_TGETR:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |.if DUALNUM\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RC, qword [BASE+RC*8]\n    |.endif\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tgetr\t\t// Not in array part? Use fallback.\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |->BC_TGETR_Z:\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |->BC_TGETR2_Z:\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  checktab RB, ->vmeta_tsetv\n    |  mov TAB:RB, [BASE+RB*8]\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movsd xmm0, qword [BASE+RC*8]\n    |  cvttsd2si RC, xmm0\n    |  cvtsi2sd xmm1, RC\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tsetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RC, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tsetv\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:  // Set array slot.\n    |.if X64\n    |  mov RBa, [BASE+RA*8]\n    |  mov [RC], RBa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <1\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetv\t\t\t// 'no __newindex' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  checkstr RC, ->vmeta_tsetv\n    |  mov STR:RC, [BASE+RC*8]\n    |  jmp ->BC_TSETS_Z\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n  case BC_TSETS:\n    |  ins_ABC\t// RA = src, RB = table, RC = str const (~)\n    |  not RCa\n    |  mov STR:RC, [KBASE+RC*4]\n    |  checktab RB, ->vmeta_tsets\n    |  mov TAB:RB, [BASE+RB*8]\n    |->BC_TSETS_Z:\t// RB = GCtab *, RC = GCstr *, refetches PC_RA.\n    |  mov RA, TAB:RB->hmask\n    |  and RA, STR:RC->hash\n    |  imul RA, #NODE\n    |  mov byte TAB:RB->nomm, 0\t\t// Clear metamethod cache.\n    |  add NODE:RA, TAB:RB->node\n    |1:\n    |  cmp dword NODE:RA->key.it, LJ_TSTR\n    |  jne >5\n    |  cmp dword NODE:RA->key.gcr, STR:RC\n    |  jne >5\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp dword [RA+4], LJ_TNIL\n    |  je >4\t\t\t\t// Previous value is nil?\n    |2:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |3:  // Set node value.\n    |  movzx RC, PC_RA\n    |.if X64\n    |  mov RBa, [BASE+RC*8]\n    |  mov [RA], RBa\n    |.else\n    |  mov RB, [BASE+RC*8+4]\n    |  mov RC, [BASE+RC*8]\n    |  mov [RA+4], RB\n    |  mov [RA], RC\n    |.endif\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <2\n    |  mov TMP1, RA\t\t\t// Save RA.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |  mov RA, TMP1\t\t\t// Restore RA.\n    |  jmp <2\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:RA, NODE:RA->next\n    |  test NODE:RA, NODE:RA\n    |  jnz <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test TAB:RA, TAB:RA\n    |  jz >6\t\t\t\t// No metatable: continue.\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mov TMP1, STR:RC\n    |  mov TMP2, LJ_TSTR\n    |  mov TMP3, TAB:RB\t\t\t// Save TAB:RB for us.\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\n    |  lea CARG3, TMP1\n    |  mov CARG2d, TAB:RB\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  lea RC, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n    |  mov ARG2, TAB:RB\n    |  mov L:RB, SAVE_L\n    |  mov ARG3, RC\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Handles write barrier for the new key. TValue * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  mov TAB:RB, TMP3\t\t\t// Need TAB:RB for barrier.\n    |  mov RA, eax\n    |  jmp <2\t\t\t\t// Must check write barrier for value.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RC\t\t// Destroys STR:RC.\n    |  jmp <3\n    break;\n  case BC_TSETB:\n    |  ins_ABC\t// RA = src, RB = table, RC = byte literal\n    |  checktab RB, ->vmeta_tsetb\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tsetb\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\t // Set array slot.\n    |.if X64\n    |  mov RAa, [BASE+RA*8]\n    |  mov [RC], RAa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <1\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetb\t\t\t// 'no __newindex' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n  case BC_TSETR:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |.if DUALNUM\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RC, qword [BASE+RC*8]\n    |.endif\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tsetr\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  // Set array slot.\n    |->BC_TSETR_Z:\n    |.if X64\n    |  mov RBa, [BASE+RA*8]\n    |  mov [RC], RBa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n\n  case BC_TSETM:\n    |  ins_AD\t// RA = base (table at base-1), RD = num const (start index)\n    |  mov TMP1, KBASE\t\t\t// Need one more free register.\n    |  mov KBASE, dword [KBASE+RD*8]\t// Integer constant is in lo-word.\n    |1:\n    |  lea RA, [BASE+RA*8]\n    |  mov TAB:RB, [RA-8]\t\t// Guaranteed to be a table.\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  mov RD, MULTRES\n    |  sub RD, 1\n    |  jz >4\t\t\t\t// Nothing to copy?\n    |  add RD, KBASE\t\t\t// Compute needed size.\n    |  cmp RD, TAB:RB->asize\n    |  ja >5\t\t\t\t// Doesn't fit into array part?\n    |  sub RD, KBASE\n    |  shl KBASE, 3\n    |  add KBASE, TAB:RB->array\n    |3:  // Copy result slots to table.\n    |.if X64\n    |  mov RBa, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov [KBASE], RB\n    |  mov RB, [RA+4]\n    |  add RA, 8\n    |  mov [KBASE+4], RB\n    |.endif\n    |  add KBASE, 8\n    |  sub RD, 1\n    |  jnz <3\n    |4:\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n    |  mov CARG2d, TAB:RB\n    |  mov CARG3d, RD\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  mov ARG2, TAB:RB\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov ARG3, RD\n    |  mov ARG1, L:RB\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\t\t\t\t// Retry.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:RB, RD\n    |  jmp <2\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALL: case BC_CALLM:\n    |  ins_A_C\t// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs\n    if (op == BC_CALLM) {\n      |  add NARGS:RD, MULTRES\n    }\n    |  cmp dword [BASE+RA*8+4], LJ_TFUNC\n    |  mov LFUNC:RB, [BASE+RA*8]\n    |  jne ->vmeta_call_ra\n    |  lea BASE, [BASE+RA*8+8]\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  ins_AD\t// RA = base, RD = extra_nargs\n    |  add NARGS:RD, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.\n    break;\n  case BC_CALLT:\n    |  ins_AD\t// RA = base, RD = nargs+1\n    |  lea RA, [BASE+RA*8+8]\n    |  mov KBASE, BASE\t\t\t// Use KBASE for move + vmeta_call hint.\n    |  mov LFUNC:RB, [RA-8]\n    |  cmp dword [RA-4], LJ_TFUNC\n    |  jne ->vmeta_call\n    |->BC_CALLT_Z:\n    |  mov PC, [BASE-4]\n    |  test PC, FRAME_TYPE\n    |  jnz >7\n    |1:\n    |  mov [BASE-8], LFUNC:RB\t\t// Copy function down, reloaded below.\n    |  mov MULTRES, NARGS:RD\n    |  sub NARGS:RD, 1\n    |  jz >3\n    |2:  // Move args down.\n    |.if X64\n    |  mov RBa, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov [KBASE], RB\n    |  mov RB, [RA+4]\n    |  add RA, 8\n    |  mov [KBASE+4], RB\n    |.endif\n    |  add KBASE, 8\n    |  sub NARGS:RD, 1\n    |  jnz <2\n    |\n    |  mov LFUNC:RB, [BASE-8]\n    |3:\n    |  mov NARGS:RD, MULTRES\n    |  cmp byte LFUNC:RB->ffid, 1\t// (> FF_C) Calling a fast function?\n    |  ja >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function.\n    |  test PC, FRAME_TYPE\t\t// Lua frame below?\n    |  jnz <4\n    |  movzx RA, PC_RA\n    |  not RAa\n    |  mov LFUNC:KBASE, [BASE+RA*8-8]\t// Need to prepare KBASE.\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  jmp <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  sub PC, FRAME_VARG\n    |  test PC, FRAME_TYPEP\n    |  jnz >8\t\t\t\t// Vararg frame below?\n    |  sub BASE, PC\t\t\t// Need to relocate BASE/KBASE down.\n    |  mov KBASE, BASE\n    |  mov PC, [BASE-4]\n    |  jmp <1\n    |8:\n    |  add PC, FRAME_VARG\n    |  jmp <1\n    break;\n\n  case BC_ITERC:\n    |  ins_A\t// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)\n    |  lea RA, [BASE+RA*8+8]\t\t// fb = base+1\n    |.if X64\n    |  mov RBa, [RA-24]\t\t\t// Copy state. fb[0] = fb[-3].\n    |  mov RCa, [RA-16]\t\t\t// Copy control var. fb[1] = fb[-2].\n    |  mov [RA], RBa\n    |  mov [RA+8], RCa\n    |.else\n    |  mov RB, [RA-24]\t\t\t// Copy state. fb[0] = fb[-3].\n    |  mov RC, [RA-20]\n    |  mov [RA], RB\n    |  mov [RA+4], RC\n    |  mov RB, [RA-16]\t\t\t// Copy control var. fb[1] = fb[-2].\n    |  mov RC, [RA-12]\n    |  mov [RA+8], RB\n    |  mov [RA+12], RC\n    |.endif\n    |  mov LFUNC:RB, [RA-32]\t\t// Copy callable. fb[-1] = fb[-4]\n    |  mov RC, [RA-28]\n    |  mov [RA-8], LFUNC:RB\n    |  mov [RA-4], RC\n    |  cmp RC, LJ_TFUNC\t\t\t// Handle like a regular 2-arg call.\n    |  mov NARGS:RD, 2+1\n    |  jne ->vmeta_call\n    |  mov BASE, RA\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  ins_A\t// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  mov TMP1, KBASE\t\t\t// Need two more free registers.\n    |  mov TMP2, DISPATCH\n    |  mov TAB:RB, [BASE+RA*8-16]\n    |  mov RC, [BASE+RA*8-8]\t\t// Get index from control var.\n    |  mov DISPATCH, TAB:RB->asize\n    |  add PC, 4\n    |  mov KBASE, TAB:RB->array\n    |1:  // Traverse array part.\n    |  cmp RC, DISPATCH; jae >5\t\t// Index points after array part?\n    |  cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4\n    |.if DUALNUM\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RC\n    |.else\n    |  cvtsi2sd xmm0, RC\n    |.endif\n    |  // Copy array slot to returned value.\n    |.if X64\n    |  mov RBa, [KBASE+RC*8]\n    |  mov [BASE+RA*8+8], RBa\n    |.else\n    |  mov RB, [KBASE+RC*8+4]\n    |  mov [BASE+RA*8+12], RB\n    |  mov RB, [KBASE+RC*8]\n    |  mov [BASE+RA*8+8], RB\n    |.endif\n    |  add RC, 1\n    |  // Return array index as a numeric key.\n    |.if DUALNUM\n    |  // See above.\n    |.else\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  mov [BASE+RA*8-8], RC\t\t// Update control var.\n    |2:\n    |  movzx RD, PC_RD\t\t\t// Get target from ITERL.\n    |  branchPC RD\n    |3:\n    |  mov DISPATCH, TMP2\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  add RC, 1\n    |  jmp <1\n    |\n    |5:  // Traverse hash part.\n    |  sub RC, DISPATCH\n    |6:\n    |  cmp RC, TAB:RB->hmask; ja <3\t// End of iteration? Branch to ITERL+1.\n    |  imul KBASE, RC, #NODE\n    |  add NODE:KBASE, TAB:RB->node\n    |  cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7\n    |  lea DISPATCH, [RC+DISPATCH+1]\n    |  // Copy key and value from hash slot.\n    |.if X64\n    |  mov RBa, NODE:KBASE->key\n    |  mov RCa, NODE:KBASE->val\n    |  mov [BASE+RA*8], RBa\n    |  mov [BASE+RA*8+8], RCa\n    |.else\n    |  mov RB, NODE:KBASE->key.gcr\n    |  mov RC, NODE:KBASE->key.it\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |  mov RB, NODE:KBASE->val.gcr\n    |  mov RC, NODE:KBASE->val.it\n    |  mov [BASE+RA*8+8], RB\n    |  mov [BASE+RA*8+12], RC\n    |.endif\n    |  mov [BASE+RA*8-8], DISPATCH\n    |  jmp <2\n    |\n    |7:  // Skip holes in hash part.\n    |  add RC, 1\n    |  jmp <6\n    break;\n\n  case BC_ISNEXT:\n    |  ins_AD\t// RA = base, RD = target (points to ITERN)\n    |  cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5\n    |  mov CFUNC:RB, [BASE+RA*8-24]\n    |  cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5\n    |  cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5\n    |  cmp byte CFUNC:RB->ffid, FF_next_N; jne >5\n    |  branchPC RD\n    |  mov dword [BASE+RA*8-8], 0\t// Initialize control var.\n    |  mov dword [BASE+RA*8-4], 0xfffe7fff\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov PC_OP, BC_JMP\n    |  branchPC RD\n    |  mov byte [PC], BC_ITERC\n    |  jmp <1\n    break;\n\n  case BC_VARG:\n    |  ins_ABC\t// RA = base, RB = nresults+1, RC = numparams\n    |  mov TMP1, KBASE\t\t\t// Need one more free register.\n    |  lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]\n    |  lea RA, [BASE+RA*8]\n    |  sub KBASE, [BASE-4]\n    |  // Note: KBASE may now be even _above_ BASE if nargs was < numparams.\n    |  test RB, RB\n    |  jz >5\t\t\t\t// Copy all varargs?\n    |  lea RB, [RA+RB*8-8]\n    |  cmp KBASE, BASE\t\t\t// No vararg slots?\n    |  jnb >2\n    |1:  // Copy vararg slots to destination slots.\n    |.if X64\n    |  mov RCa, [KBASE-8]\n    |  add KBASE, 8\n    |  mov [RA], RCa\n    |.else\n    |  mov RC, [KBASE-8]\n    |  mov [RA], RC\n    |  mov RC, [KBASE-4]\n    |  add KBASE, 8\n    |  mov [RA+4], RC\n    |.endif\n    |  add RA, 8\n    |  cmp RA, RB\t\t\t// All destination slots filled?\n    |  jnb >3\n    |  cmp KBASE, BASE\t\t\t// No more vararg slots?\n    |  jb <1\n    |2:  // Fill up remainder with nil.\n    |  mov dword [RA+4], LJ_TNIL\n    |  add RA, 8\n    |  cmp RA, RB\n    |  jb <2\n    |3:\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  mov MULTRES, 1\t\t\t// MULTRES = 0+1\n    |  mov RC, BASE\n    |  sub RC, KBASE\n    |  jbe <3\t\t\t\t// No vararg slots?\n    |  mov RB, RC\n    |  shr RB, 3\n    |  add RB, 1\n    |  mov MULTRES, RB\t\t\t// MULTRES = #varargs+1\n    |  mov L:RB, SAVE_L\n    |  add RC, RA\n    |  cmp RC, L:RB->maxstack\n    |  ja >7\t\t\t\t// Need to grow stack?\n    |6:  // Copy all vararg slots.\n    |.if X64\n    |  mov RCa, [KBASE-8]\n    |  add KBASE, 8\n    |  mov [RA], RCa\n    |.else\n    |  mov RC, [KBASE-8]\n    |  mov [RA], RC\n    |  mov RC, [KBASE-4]\n    |  add KBASE, 8\n    |  mov [RA+4], RC\n    |.endif\n    |  add RA, 8\n    |  cmp KBASE, BASE\t\t\t// No more vararg slots?\n    |  jb <6\n    |  jmp <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mov L:RB->base, BASE\n    |  mov L:RB->top, RA\n    |  mov SAVE_PC, PC\n    |  sub KBASE, BASE\t\t\t// Need delta, because BASE may change.\n    |  mov FCARG2, MULTRES\n    |  sub FCARG2, 1\n    |  mov FCARG1, L:RB\n    |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n    |  mov BASE, L:RB->base\n    |  mov RA, L:RB->top\n    |  add KBASE, BASE\n    |  jmp <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  ins_AD\t// RA = results, RD = extra_nresults\n    |  add RD, MULTRES\t\t\t// MULTRES >=1, so RD >=1.\n    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.\n    break;\n\n  case BC_RET: case BC_RET0: case BC_RET1:\n    |  ins_AD\t// RA = results, RD = nresults+1\n    if (op != BC_RET0) {\n      |  shl RA, 3\n    }\n    |1:\n    |  mov PC, [BASE-4]\n    |  mov MULTRES, RD\t\t\t// Save nresults+1.\n    |  test PC, FRAME_TYPE\t\t// Check frame type marker.\n    |  jnz >7\t\t\t\t// Not returning to a fixarg Lua func?\n    switch (op) {\n    case BC_RET:\n      |->BC_RET_Z:\n      |  mov KBASE, BASE\t\t// Use KBASE for result move.\n      |  sub RD, 1\n      |  jz >3\n      |2:  // Move results down.\n      |.if X64\n      |  mov RBa, [KBASE+RA]\n      |  mov [KBASE-8], RBa\n      |.else\n      |  mov RB, [KBASE+RA]\n      |  mov [KBASE-8], RB\n      |  mov RB, [KBASE+RA+4]\n      |  mov [KBASE-4], RB\n      |.endif\n      |  add KBASE, 8\n      |  sub RD, 1\n      |  jnz <2\n      |3:\n      |  mov RD, MULTRES\t\t// Note: MULTRES may be >255.\n      |  movzx RB, PC_RB\t\t// So cannot compare with RDL!\n      |5:\n      |  cmp RB, RD\t\t\t// More results expected?\n      |  ja >6\n      break;\n    case BC_RET1:\n      |.if X64\n      |  mov RBa, [BASE+RA]\n      |  mov [BASE-8], RBa\n      |.else\n      |  mov RB, [BASE+RA+4]\n      |  mov [BASE-4], RB\n      |  mov RB, [BASE+RA]\n      |  mov [BASE-8], RB\n      |.endif\n      /* fallthrough */\n    case BC_RET0:\n      |5:\n      |  cmp PC_RB, RDL\t\t\t// More results expected?\n      |  ja >6\n    default:\n      break;\n    }\n    |  movzx RA, PC_RA\n    |  not RAa\t\t\t\t// Note: ~RA = -(RA+1)\n    |  lea BASE, [BASE+RA*8]\t\t// base = base - (RA+1)*8\n    |  mov LFUNC:KBASE, [BASE-8]\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    if (op == BC_RET) {\n      |  mov dword [KBASE-4], LJ_TNIL\t// Note: relies on shifted base.\n      |  add KBASE, 8\n    } else {\n      |  mov dword [BASE+RD*8-12], LJ_TNIL\n    }\n    |  add RD, 1\n    |  jmp <5\n    |\n    |7:  // Non-standard return case.\n    |  lea RB, [PC-FRAME_VARG]\n    |  test RB, FRAME_TYPEP\n    |  jnz ->vm_return\n    |  // Return from vararg function: relocate BASE down and RA up.\n    |  sub BASE, RB\n    if (op != BC_RET0) {\n      |  add RA, RB\n    }\n    |  jmp <1\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];    .define FOR_TIDX,  dword [RA+4]\n  |.define FOR_STOP, [RA+8];  .define FOR_TSTOP, dword [RA+12]\n  |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20]\n  |.define FOR_EXT,  [RA+24]; .define FOR_TEXT,  dword [RA+28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ins_AJ\t// RA = base, RD = target (after end of loop or start of loop)\n    |  lea RA, [BASE+RA*8]\n    if (LJ_DUALNUM) {\n      |  cmp FOR_TIDX, LJ_TISNUM; jne >9\n      if (!vk) {\n\t|  cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for\n\t|  cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for\n\t|  mov RB, dword FOR_IDX\n\t|  cmp dword FOR_STEP, 0; jl >5\n      } else {\n#ifdef LUA_USE_ASSERT\n\t|  cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type\n\t|  cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type\n#endif\n\t|  mov RB, dword FOR_STEP\n\t|  test RB, RB; js >5\n\t|  add RB, dword FOR_IDX; jo >1\n\t|  mov dword FOR_IDX, RB\n      }\n      |  cmp RB, dword FOR_STOP\n      |  mov FOR_TEXT, LJ_TISNUM\n      |  mov dword FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jle >7\n\t|1:\n\t|6:\n\t|  branchPC RD\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RD, PC_RD\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      } else if (op == BC_IFORL) {\n\t|  jg >7\n\t|6:\n\t|  branchPC RD\n\t|1:\n      } else {\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      }\n      |7:\n      |  ins_next\n      |\n      |5:  // Invert check for negative step.\n      if (vk) {\n\t|  add RB, dword FOR_IDX; jo <1\n\t|  mov dword FOR_IDX, RB\n      }\n      |  cmp RB, dword FOR_STOP\n      |  mov FOR_TEXT, LJ_TISNUM\n      |  mov dword FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jge <7\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RD, PC_RD\n\t|  jge =>BC_JLOOP\n      } else if (op == BC_IFORL) {\n\t|  jl <7\n      } else {\n\t|  jge =>BC_JLOOP\n      }\n      |  jmp <6\n      |9:  // Fallback to FP variant.\n    } else if (!vk) {\n      |  cmp FOR_TIDX, LJ_TISNUM\n    }\n    if (!vk) {\n      |  jae ->vmeta_for\n      |  cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type\n      |  cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type\n#endif\n    }\n    |  mov RB, FOR_TSTEP\t\t// Load type/hiword of for step.\n    if (!vk) {\n      |  cmp RB, LJ_TISNUM; jae ->vmeta_for\n    }\n    |  movsd xmm0, qword FOR_IDX\n    |  movsd xmm1, qword FOR_STOP\n    if (vk) {\n      |  addsd xmm0, qword FOR_STEP\n      |  movsd qword FOR_IDX, xmm0\n      |  test RB, RB; js >3\n    } else {\n      |  jl >3\n    }\n    |  ucomisd xmm1, xmm0\n    |1:\n    |  movsd qword FOR_EXT, xmm0\n    if (op == BC_FORI) {\n      |.if DUALNUM\n      |  jnb <7\n      |.else\n      |  jnb >2\n      |  branchPC RD\n      |.endif\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  movzx RD, PC_RD\n      |  jnb =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  jb <7\n      |.else\n      |  jb >2\n      |  branchPC RD\n      |.endif\n    } else {\n      |  jnb =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  jmp <6\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |\n    |3:  // Invert comparison if step is negative.\n    |  ucomisd xmm0, xmm1\n    |  jmp <1\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  ins_AJ\t// RA = base, RD = target\n    |  lea RA, [BASE+RA*8]\n    |  mov RB, [RA+4]\n    |  cmp RB, LJ_TNIL; je >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  mov [RA-4], RB\n      |  mov RB, [RA]\n      |  mov [RA-8], RB\n      |  jmp =>BC_JLOOP\n    } else {\n      |  branchPC RD\t\t\t// Otherwise save control var + branch.\n      |  mov RD, [RA]\n      |  mov [RA-4], RB\n      |  mov [RA-8], RD\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.\n    break;\n\n  case BC_ILOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  ins_AD\t// RA = base (ignored), RD = traceno\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  mov TRACE:RD, [RA+RD*4]\n    |  mov RDa, TRACE:RD->mcode\n    |  mov L:RB, SAVE_L\n    |  mov [DISPATCH+DISPATCH_GL(jit_base)], BASE\n    |  mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB\n    |  // Save additional callee-save registers only used in compiled code.\n    |.if X64WIN\n    |  mov TMPQ, r12\n    |  mov TMPa, r13\n    |  mov CSAVE_4, r14\n    |  mov CSAVE_3, r15\n    |  mov RAa, rsp\n    |  sub rsp, 9*16+4*8\n    |  movdqa [RAa], xmm6\n    |  movdqa [RAa-1*16], xmm7\n    |  movdqa [RAa-2*16], xmm8\n    |  movdqa [RAa-3*16], xmm9\n    |  movdqa [RAa-4*16], xmm10\n    |  movdqa [RAa-5*16], xmm11\n    |  movdqa [RAa-6*16], xmm12\n    |  movdqa [RAa-7*16], xmm13\n    |  movdqa [RAa-8*16], xmm14\n    |  movdqa [RAa-9*16], xmm15\n    |.elif X64\n    |  mov TMPQ, r12\n    |  mov TMPa, r13\n    |  sub rsp, 16\n    |.endif\n    |  jmp RDa\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  ins_AJ\t// RA = unused, RD = target\n    |  branchPC RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n   /*\n   ** Reminder: A function may be called with func/args above L->maxstack,\n   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,\n   ** too. This means all FUNC* ops (including fast functions) must check\n   ** for stack overflow _before_ adding more slots!\n   */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall RB\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  mov KBASE, [PC-4+PC2PROTO(k)]\n    |  mov L:RB, SAVE_L\n    |  lea RA, [BASE+RA*8]\t\t// Top of frame.\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_f\n    |  movzx RA, byte [PC-4+PC2PROTO(numparams)]\n    |  cmp NARGS:RD, RA\t\t\t// Check for missing parameters.\n    |  jbe >3\n    |2:\n    if (op == BC_JFUNCF) {\n      |  movzx RD, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov dword [BASE+NARGS:RD*8-4], LJ_TNIL\n    |  add NARGS:RD, 1\n    |  cmp NARGS:RD, RA\n    |  jbe <3\n    |  jmp <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    | int3  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  lea RB, [NARGS:RD*8+FRAME_VARG]\n    |  lea RD, [BASE+NARGS:RD*8]\n    |  mov LFUNC:KBASE, [BASE-8]\n    |  mov [RD-4], RB\t\t\t// Store delta + FRAME_VARG.\n    |  mov [RD-8], LFUNC:KBASE\t\t// Store copy of LFUNC.\n    |  mov L:RB, SAVE_L\n    |  lea RA, [RD+RA*8]\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_v\t\t// Need to grow stack.\n    |  mov RA, BASE\n    |  mov BASE, RD\n    |  movzx RB, byte [PC-4+PC2PROTO(numparams)]\n    |  test RB, RB\n    |  jz >2\n    |1:  // Copy fixarg slots up to new frame.\n    |  add RA, 8\n    |  cmp RA, BASE\n    |  jnb >3\t\t\t\t// Less args than parameters?\n    |  mov KBASE, [RA-8]\n    |  mov [RD], KBASE\n    |  mov KBASE, [RA-4]\n    |  mov [RD+4], KBASE\n    |  add RD, 8\n    |  mov dword [RA-4], LJ_TNIL\t// Clear old fixarg slot (help the GC).\n    |  sub RB, 1\n    |  jnz <1\n    |2:\n    if (op == BC_JFUNCV) {\n      |  movzx RD, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  mov KBASE, [PC-4+PC2PROTO(k)]\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov dword [RD+4], LJ_TNIL\n    |  add RD, 8\n    |  sub RB, 1\n    |  jnz <3\n    |  jmp <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  ins_AD  // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1\n    |  mov CFUNC:RB, [BASE-8]\n    |  mov KBASEa, CFUNC:RB->f\n    |  mov L:RB, SAVE_L\n    |  lea RD, [BASE+NARGS:RD*8-8]\n    |  mov L:RB->base, BASE\n    |  lea RA, [RD+8*LUA_MINSTACK]\n    |  cmp RA, L:RB->maxstack\n    |  mov L:RB->top, RD\n    if (op == BC_FUNCC) {\n      |.if X64\n      |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n      |.else\n      |  mov ARG1, L:RB\n      |.endif\n    } else {\n      |.if X64\n      |  mov CARG2, KBASEa\n      |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n      |.else\n      |  mov ARG2, KBASEa\n      |  mov ARG1, L:RB\n      |.endif\n    }\n    |  ja ->vm_growstack_c\t\t// Need to grow stack.\n    |  set_vmstate C\n    if (op == BC_FUNCC) {\n      |  call KBASEa\t\t\t// (lua_State *L)\n    } else {\n      |  // (lua_State *L, lua_CFunction f)\n      |  call aword [DISPATCH+DISPATCH_GL(wrapf)]\n    }\n    |  // nresults returned in eax (RD).\n    |  mov BASE, L:RB->base\n    |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n    |  set_vmstate INTERP\n    |  lea RA, [BASE+RD*8]\n    |  neg RA\n    |  add RA, L:RB->top\t\t// RA = (L->top-(L->base+nresults))*8\n    |  mov PC, [BASE-4]\t\t\t// Fetch PC of caller.\n    |  jmp ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n  dasm_growpc(Dst, BC__MAX);\n  build_subroutines(ctx);\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n#if LJ_64\n#define SZPTR\t\"8\"\n#define BSZPTR\t\"3\"\n#define REG_SP\t\"0x7\"\n#define REG_RA\t\"0x10\"\n#else\n#define SZPTR\t\"4\"\n#define BSZPTR\t\"2\"\n#define REG_SP\t\"0x4\"\n#define REG_RA\t\"0x8\"\n#endif\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_64\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#if LJ_NO_UNWIND\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x6\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x7\\n\"\t/* offset r12 */\n#endif\n#else\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0x3\\n\"\t/* offset edi */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x4\\n\"\t/* offset esi */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x5\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE0:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_64\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n#else\n\t\"\\t.long lj_vm_ffi_call\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 8\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x5\\n\"\t\t/* def_cfa_register ebp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n#if (defined(__sun__) && defined(__svr4__))\n#if LJ_64\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@unwind\\n\");\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"aw\\\",@progbits\\n\");\n#endif\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n#endif\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n#if LJ_64\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#else\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0x3\\n\"\t/* offset edi */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x4\\n\"\t/* offset esi */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x5\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE2:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n#if LJ_64\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n#else\n\t\"\\t.byte 0xe\\n\\t.uleb128 8\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x5\\n\"\t\t/* def_cfa_register ebp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n#if !LJ_NO_UNWIND\n  /* Mental note: never let Apple design an assembler.\n  ** Or a linker. Or a plastic case. But I digress.\n  */\n  case BUILD_machasm: {\n#if LJ_HASFFI\n    int fcsize = 0;\n#endif\n    int i;\n    fprintf(ctx->fp, \"\\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\\n\");\n    fprintf(ctx->fp,\n\t\"EH_frame1:\\n\"\n\t\"\\t.set L$set$x,LECIEX-LSCIEX\\n\"\n\t\"\\t.long L$set$x\\n\"\n\t\"LSCIEX:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zPR\\\\0\\\"\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.byte 128-\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.byte 6\\n\"\t\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9b\\n\"\t\t\t/* indirect|pcrel|sdata4 */\n#if LJ_64\n\t\"\\t.long _lj_err_unwind_dwarf+4@GOTPCREL\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte \" REG_SP \"\\n\\t.byte \" SZPTR \"\\n\"\n#else\n\t\"\\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte 0x5\\n\\t.byte 0x4\\n\"  /* esp=5 on 32 bit MACH-O. */\n#endif\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.byte 0x1\\n\"\n\t\"\\t.align \" BSZPTR \"\\n\"\n\t\"LECIEX:\\n\\n\");\n    for (i = 0; i < ctx->nsym; i++) {\n      const char *name = ctx->sym[i].name;\n      int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;\n      if (size == 0) continue;\n#if LJ_HASFFI\n      if (!strcmp(name, \"_lj_vm_ffi_call\")) { fcsize = size; continue; }\n#endif\n      fprintf(ctx->fp,\n\t  \"%s.eh:\\n\"\n\t  \"LSFDE%d:\\n\"\n\t  \"\\t.set L$set$%d,LEFDE%d-LASFDE%d\\n\"\n\t  \"\\t.long L$set$%d\\n\"\n\t  \"LASFDE%d:\\n\"\n\t  \"\\t.long LASFDE%d-EH_frame1\\n\"\n\t  \"\\t.long %s-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte %d\\n\"\t\t/* def_cfa_offset */\n#if LJ_64\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.byte 0x8f\\n\\t.byte 0x4\\n\"\t\t/* offset r15 */\n\t  \"\\t.byte 0x8e\\n\\t.byte 0x5\\n\"\t\t/* offset r14 */\n#else\n\t  \"\\t.byte 0x84\\n\\t.byte 0x2\\n\"\t\t/* offset ebp (4 for MACH-O)*/\n\t  \"\\t.byte 0x87\\n\\t.byte 0x3\\n\"\t\t/* offset edi */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x4\\n\"\t\t/* offset esi */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x5\\n\"\t\t/* offset ebx */\n#endif\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LEFDE%d:\\n\\n\",\n\t  name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);\n    }\n#if LJ_HASFFI\n    if (fcsize) {\n      fprintf(ctx->fp,\n\t  \"EH_frame2:\\n\"\n\t  \"\\t.set L$set$y,LECIEY-LSCIEY\\n\"\n\t  \"\\t.long L$set$y\\n\"\n\t  \"LSCIEY:\\n\"\n\t  \"\\t.long 0\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.ascii \\\"zR\\\\0\\\"\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.byte 128-\" SZPTR \"\\n\"\n\t  \"\\t.byte \" REG_RA \"\\n\"\n\t  \"\\t.byte 1\\n\"\t\t\t\t/* augmentation length */\n#if LJ_64\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte \" REG_SP \"\\n\\t.byte \" SZPTR \"\\n\"\n#else\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte 0x5\\n\\t.byte 0x4\\n\"  /* esp=5 on 32 bit MACH. */\n#endif\n\t  \"\\t.byte 0x80+\" REG_RA \"\\n\\t.byte 0x1\\n\"\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LECIEY:\\n\\n\");\n      fprintf(ctx->fp,\n\t  \"_lj_vm_ffi_call.eh:\\n\"\n\t  \"LSFDEY:\\n\"\n\t  \"\\t.set L$set$yy,LEFDEY-LASFDEY\\n\"\n\t  \"\\t.long L$set$yy\\n\"\n\t  \"LASFDEY:\\n\"\n\t  \"\\t.long LASFDEY-EH_frame2\\n\"\n\t  \"\\t.long _lj_vm_ffi_call-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n#if LJ_64\n\t  \"\\t.byte 0xe\\n\\t.byte 16\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0xd\\n\\t.byte 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n#else\n\t  \"\\t.byte 0xe\\n\\t.byte 8\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x84\\n\\t.byte 0x2\\n\"\t\t/* offset ebp (4 for MACH-O)*/\n\t  \"\\t.byte 0xd\\n\\t.byte 0x4\\n\"\t\t/* def_cfa_register ebp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset ebx */\n#endif\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LEFDEY:\\n\\n\", fcsize);\n    }\n#endif\n#if !LJ_64\n    fprintf(ctx->fp,\n      \"\\t.non_lazy_symbol_pointer\\n\"\n      \"L_lj_err_unwind_dwarf$non_lazy_ptr:\\n\"\n      \".indirect_symbol _lj_err_unwind_dwarf\\n\"\n      \".long 0\\n\\n\");\n    fprintf(ctx->fp, \"\\t.section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5\\n\");\n    {\n      const char *const *xn;\n      for (xn = ctx->extnames; *xn; xn++)\n\tif (strncmp(*xn, LABEL_PREFIX, sizeof(LABEL_PREFIX)-1))\n\t  fprintf(ctx->fp, \"L_%s$stub:\\n\\t.indirect_symbol _%s\\n\\t.ascii \\\"\\\\364\\\\364\\\\364\\\\364\\\\364\\\"\\n\", *xn, *xn);\n    }\n#endif\n    fprintf(ctx->fp, \".subsections_via_symbols\\n\");\n    }\n    break;\n#endif\n  default:  /* Difficult for other modes. */\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/xb1build.bat",
    "content": "@rem Script to build LuaJIT with the Xbox One SDK.\n@rem Donated to the public domain.\n@rem\n@rem Open a \"Visual Studio .NET Command Prompt\" (64 bit host compiler)\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n@if not defined DurangoXDK goto :FAIL\n\n@setlocal\n@echo ---- Host compiler ----\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /DLUAJIT_ENABLE_GC64\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@rem Error out for 64 bit host compiler\n@minilua\n@if not errorlevel 8 goto :FAIL\n\n@set DASMFLAGS=-D WIN -D FFI -D P64\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_x64.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% /D_DURANGO host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m peobj -o lj_vm.obj\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@echo ---- Cross compiler ----\n\n@set CWD=%cd%\n@call \"%DurangoXDK%\\xdk\\DurangoVars.cmd\" XDK\n@cd /D \"%CWD%\"\n@shift\n\n@set LJCOMPILE=\"cl\" /nologo /c /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /D_LIB /D_UNICODE /D_DURANGO\n@set LJLIB=\"lib\" /nologo\n\n@if \"%1\"==\"debug\" (\n  @shift\n  @set LJCOMPILE=%LJCOMPILE% /Zi /MDd /Od\n  @set LJLINK=%LJLINK% /debug \n) else (\n  @set LJCOMPILE=%LJCOMPILE% /MD /O2 /DNDEBUG\n)\n\n@if \"%1\"==\"amalg\" goto :AMALG\n%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:luajit.lib lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :NOAMALG\n:AMALG\n%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:luajit.lib ljamalg.obj lj_vm.obj\n@if errorlevel 1 goto :BAD\n:NOAMALG\n\n@del *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for Xbox One ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\n@goto :END\n:FAIL\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\n@echo (64 bit host compiler). The Xbox One SDK must be installed, too.\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b2/src/xedkbuild.bat",
    "content": "@rem Script to build LuaJIT with the Xbox 360 SDK.\n@rem Donated to the public domain.\n@rem\n@rem Open a \"Visual Studio .NET Command Prompt\" (32 bit host compiler)\n@rem Then cd to this directory and run this script.\n\n@if not defined INCLUDE goto :FAIL\n@if not defined XEDK goto :FAIL\n\n@setlocal\n@rem ---- Host compiler ----\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\n@set LJLINK=link /nologo\n@set LJMT=mt /nologo\n@set DASMDIR=..\\dynasm\n@set DASM=%DASMDIR%\\dynasm.lua\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c\n\n%LJCOMPILE% host\\minilua.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:minilua.exe minilua.obj\n@if errorlevel 1 goto :BAD\nif exist minilua.exe.manifest^\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\n\n@rem Error out for 64 bit host compiler\n@minilua\n@if errorlevel 8 goto :FAIL\n\n@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_ppc.dasc\n@if errorlevel 1 goto :BAD\n\n%LJCOMPILE% /I \".\" /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC  host\\buildvm*.c\n@if errorlevel 1 goto :BAD\n%LJLINK% /out:buildvm.exe buildvm*.obj\n@if errorlevel 1 goto :BAD\nif exist buildvm.exe.manifest^\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\n\nbuildvm -m peobj -o lj_vm.obj\n@if errorlevel 1 goto :BAD\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\n@if errorlevel 1 goto :BAD\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\n@if errorlevel 1 goto :BAD\n\n@rem ---- Cross compiler ----\n@set LJCOMPILE=\"%XEDK%\\bin\\win32\\cl\" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC\n@set LJLIB=\"%XEDK%\\bin\\win32\\lib\" /nologo\n@set \"INCLUDE=%XEDK%\\include\\xbox\"\n\n@if \"%1\" neq \"debug\" goto :NODEBUG\n@shift\n@set \"LJCOMPILE=%LJCOMPILE% /Zi\"\n:NODEBUG\n@if \"%1\"==\"amalg\" goto :AMALG\n%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj\n@if errorlevel 1 goto :BAD\n@goto :NOAMALG\n:AMALG\n%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c\n@if errorlevel 1 goto :BAD\n%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj\n@if errorlevel 1 goto :BAD\n:NOAMALG\n\n@del *.obj *.manifest minilua.exe buildvm.exe\n@echo.\n@echo === Successfully built LuaJIT for Xbox 360 ===\n\n@goto :END\n:BAD\n@echo.\n@echo *******************************************************\n@echo *** Build FAILED -- Please check the error messages ***\n@echo *******************************************************\u0007\n@goto :END\n:FAIL\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\n@echo (32 bit host compiler). The Xbox 360 SDK must be installed, too.\n:END\n"
  },
  {
    "path": "build/luajit-2.1.0b3/.gitignore",
    "content": "*.[oa]\n*.so\n*.obj\n*.lib\n*.exp\n*.dll\n*.exe\n*.manifest\n*.dmp\n*.swp\n.tags\n"
  },
  {
    "path": "build/luajit-2.1.0b3/COPYRIGHT",
    "content": "===============================================================================\nLuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/\n\nCopyright (C) 2005-2021 Mike Pall. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n[ MIT license: https://www.opensource.org/licenses/mit-license.php ]\n\n===============================================================================\n[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]\n\nCopyright (C) 1994-2012 Lua.org, PUC-Rio.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n===============================================================================\n[ LuaJIT includes code from dlmalloc, which has this license statement: ]\n\nThis is a version (aka dlmalloc) of malloc/free/realloc written by\nDoug Lea and released to the public domain, as explained at\nhttps://creativecommons.org/licenses/publicdomain\n\n===============================================================================\n"
  },
  {
    "path": "build/luajit-2.1.0b3/Makefile",
    "content": "##############################################################################\n# LuaJIT top level Makefile for installation. Requires GNU Make.\n#\n# Please read doc/install.html before changing any variables!\n#\n# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).\n# Note: src/Makefile has many more configurable options.\n#\n# ##### This Makefile is NOT useful for Windows! #####\n# For MSVC, please follow the instructions given in src/msvcbuild.bat.\n# For MinGW and Cygwin, cd to src and run make with the Makefile there.\n#\n# Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n##############################################################################\n\nMAJVER=  2\nMINVER=  1\nRELVER=  0\nPREREL=  -beta3\nVERSION= $(MAJVER).$(MINVER).$(RELVER)$(PREREL)\nABIVER=  5.1\n\n##############################################################################\n#\n# Change the installation path as needed. This automatically adjusts\n# the paths in src/luaconf.h, too. Note: PREFIX must be an absolute path!\n#\nexport PREFIX= /usr/local\nexport MULTILIB= lib\n##############################################################################\n\nDPREFIX= $(DESTDIR)$(PREFIX)\nINSTALL_BIN=   $(DPREFIX)/bin\nINSTALL_LIB=   $(DPREFIX)/$(MULTILIB)\nINSTALL_SHARE= $(DPREFIX)/share\nINSTALL_INC=   $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)\n\nINSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION)\nINSTALL_JITLIB= $(INSTALL_LJLIBD)/jit\nINSTALL_LMODD= $(INSTALL_SHARE)/lua\nINSTALL_LMOD= $(INSTALL_LMODD)/$(ABIVER)\nINSTALL_CMODD= $(INSTALL_LIB)/lua\nINSTALL_CMOD= $(INSTALL_CMODD)/$(ABIVER)\nINSTALL_MAN= $(INSTALL_SHARE)/man/man1\nINSTALL_PKGCONFIG= $(INSTALL_LIB)/pkgconfig\n\nINSTALL_TNAME= luajit-$(VERSION)\nINSTALL_TSYMNAME= luajit\nINSTALL_ANAME= libluajit-$(ABIVER).a\nINSTALL_SOSHORT1= libluajit-$(ABIVER).so\nINSTALL_SOSHORT2= libluajit-$(ABIVER).so.$(MAJVER)\nINSTALL_SONAME= $(INSTALL_SOSHORT2).$(MINVER).$(RELVER)\nINSTALL_DYLIBSHORT1= libluajit-$(ABIVER).dylib\nINSTALL_DYLIBSHORT2= libluajit-$(ABIVER).$(MAJVER).dylib\nINSTALL_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).$(MINVER).$(RELVER).dylib\nINSTALL_PCNAME= luajit.pc\n\nINSTALL_STATIC= $(INSTALL_LIB)/$(INSTALL_ANAME)\nINSTALL_DYN= $(INSTALL_LIB)/$(INSTALL_SONAME)\nINSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_SOSHORT1)\nINSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_SOSHORT2)\nINSTALL_T= $(INSTALL_BIN)/$(INSTALL_TNAME)\nINSTALL_TSYM= $(INSTALL_BIN)/$(INSTALL_TSYMNAME)\nINSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME)\n\nINSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \\\n  $(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD)\nUNINSTALL_DIRS= $(INSTALL_JITLIB) $(INSTALL_LJLIBD) $(INSTALL_INC) \\\n  $(INSTALL_LMOD) $(INSTALL_LMODD) $(INSTALL_CMOD) $(INSTALL_CMODD)\n\nRM= rm -f\nMKDIR= mkdir -p\nRMDIR= rmdir 2>/dev/null\nSYMLINK= ln -sf\nINSTALL_X= install -m 0755\nINSTALL_F= install -m 0644\nUNINSTALL= $(RM)\nLDCONFIG= ldconfig -n 2>/dev/null\nSED_PC= sed -e \"s|^prefix=.*|prefix=$(PREFIX)|\" \\\n            -e \"s|^multilib=.*|multilib=$(MULTILIB)|\"\n\nFILE_T= luajit\nFILE_A= libluajit.a\nFILE_SO= libluajit.so\nFILE_MAN= luajit.1\nFILE_PC= luajit.pc\nFILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h\nFILES_JITLIB= bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua \\\n\t      dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua \\\n\t      dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua \\\n\t      dis_mips64.lua dis_mips64el.lua vmdef.lua\n\nifeq (,$(findstring Windows,$(OS)))\n  HOST_SYS:= $(shell uname -s)\nelse\n  HOST_SYS= Windows\nendif\nTARGET_SYS?= $(HOST_SYS)\n\nifeq (Darwin,$(TARGET_SYS))\n  INSTALL_SONAME= $(INSTALL_DYLIBNAME)\n  INSTALL_SOSHORT1= $(INSTALL_DYLIBSHORT1)\n  INSTALL_SOSHORT2= $(INSTALL_DYLIBSHORT2)\n  LDCONFIG= :\nendif\n\n##############################################################################\n\nINSTALL_DEP= src/luajit\n\ndefault all $(INSTALL_DEP):\n\t@echo \"==== Building LuaJIT $(VERSION) ====\"\n\t$(MAKE) -C src\n\t@echo \"==== Successfully built LuaJIT $(VERSION) ====\"\n\ninstall: $(INSTALL_DEP)\n\t@echo \"==== Installing LuaJIT $(VERSION) to $(PREFIX) ====\"\n\t$(MKDIR) $(INSTALL_DIRS)\n\tcd src && $(INSTALL_X) $(FILE_T) $(INSTALL_T)\n\tcd src && test -f $(FILE_A) && $(INSTALL_F) $(FILE_A) $(INSTALL_STATIC) || :\n\t$(RM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2)\n\tcd src && test -f $(FILE_SO) && \\\n\t  $(INSTALL_X) $(FILE_SO) $(INSTALL_DYN) && \\\n\t  ( $(LDCONFIG) $(INSTALL_LIB) || : ) && \\\n\t  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \\\n\t  $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :\n\tcd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)\n\tcd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \\\n\t  $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \\\n\t  $(RM) $(FILE_PC).tmp\n\tcd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)\n\tcd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)\n\t@echo \"==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ====\"\n\t@echo \"\"\n\t@echo \"Note: the development releases deliberately do NOT install a symlink for luajit\"\n\t@echo \"You can do this now by running this command (with sudo):\"\n\t@echo \"\"\n\t@echo \"  $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)\"\n\t@echo \"\"\n\n\nuninstall:\n\t@echo \"==== Uninstalling LuaJIT $(VERSION) from $(PREFIX) ====\"\n\t$(UNINSTALL) $(INSTALL_T) $(INSTALL_STATIC) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2) $(INSTALL_MAN)/$(FILE_MAN) $(INSTALL_PC)\n\tfor file in $(FILES_JITLIB); do \\\n\t  $(UNINSTALL) $(INSTALL_JITLIB)/$$file; \\\n\t  done\n\tfor file in $(FILES_INC); do \\\n\t  $(UNINSTALL) $(INSTALL_INC)/$$file; \\\n\t  done\n\t$(LDCONFIG) $(INSTALL_LIB)\n\t$(RMDIR) $(UNINSTALL_DIRS) || :\n\t@echo \"==== Successfully uninstalled LuaJIT $(VERSION) from $(PREFIX) ====\"\n\n##############################################################################\n\namalg:\n\t@echo \"Building LuaJIT $(VERSION)\"\n\t$(MAKE) -C src amalg\n\nclean:\n\t$(MAKE) -C src clean\n\n.PHONY: all install amalg clean\n\n##############################################################################\n"
  },
  {
    "path": "build/luajit-2.1.0b3/README",
    "content": "README for LuaJIT 2.1.0-beta3\n-----------------------------\n\nLuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.\n\nProject Homepage: https://luajit.org/\n\nLuaJIT is Copyright (C) 2005-2021 Mike Pall.\nLuaJIT is free software, released under the MIT license.\nSee full Copyright Notice in the COPYRIGHT file or in luajit.h.\n\nDocumentation for LuaJIT is available in HTML format.\nPlease point your favorite browser to:\n\n doc/luajit.html\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/bluequad-print.css",
    "content": "/* Copyright (C) 2004-2021 Mike Pall.\n *\n * You are welcome to use the general ideas of this design for your own sites.\n * But please do not steal the stylesheet, the layout or the color scheme.\n */\nbody {\n  font-family: serif;\n  font-size: 11pt;\n  margin: 0 3em;\n  padding: 0;\n  border: none;\n}\na:link, a:visited, a:hover, a:active {\n  text-decoration: none;\n  background: transparent;\n  color: #0000ff;\n}\nh1, h2, h3 {\n  font-family: sans-serif;\n  font-weight: bold;\n  text-align: left;\n  margin: 0.5em 0;\n  padding: 0;\n}\nh1 {\n  font-size: 200%;\n}\nh2 {\n  font-size: 150%;\n}\nh3 {\n  font-size: 125%;\n}\np {\n  margin: 0 0 0.5em 0;\n  padding: 0;\n}\nul, ol {\n  margin: 0.5em 0;\n  padding: 0 0 0 2em;\n}\nul {\n  list-style: outside square;\n}\nol {\n  list-style: outside decimal;\n}\nli {\n  margin: 0;\n  padding: 0;\n}\ndl {\n  margin: 1em 0;\n  padding: 1em;\n  border: 1px solid black;\n}\ndt {\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n}\ndt sup {\n  float: right;\n  margin-left: 1em;\n}\ndd {\n  margin: 0.5em 0 0 2em;\n  padding: 0;\n}\ntable {\n  table-layout: fixed;\n  width: 100%;\n  margin: 1em 0;\n  padding: 0;\n  border: 1px solid black;\n  border-spacing: 0;\n  border-collapse: collapse;\n}\ntr {\n  margin: 0;\n  padding: 0;\n  border: none;\n}\ntd {\n  text-align: left;\n  margin: 0;\n  padding: 0.2em 0.5em;\n  border-top: 1px solid black;\n  border-bottom: 1px solid black;\n}\ntr.separate td {\n  border-top: double;\n}\ntt, pre, code, kbd, samp {\n  font-family: monospace;\n  font-size: 75%;\n}\nkbd {\n  font-weight: bolder;\n}\nblockquote, pre {\n  margin: 1em 2em;\n  padding: 0;\n}\nimg {\n  border: none;\n  vertical-align: baseline;\n  margin: 0;\n  padding: 0;\n}\nimg.left {\n  float: left;\n  margin: 0.5em 1em 0.5em 0;\n}\nimg.right {\n  float: right;\n  margin: 0.5em 0 0.5em 1em;\n}\n.flush {\n  clear: both;\n  visibility: hidden;\n}\n.hide, .noprint, #nav {\n  display: none !important;\n}\n.pagebreak {\n  page-break-before: always;\n}\n#site {\n  text-align: right;\n  font-family: sans-serif;\n  font-weight: bold;\n  margin: 0 1em;\n  border-bottom: 1pt solid black;\n}\n#site a {\n  font-size: 1.2em;\n}\n#site a:link, #site a:visited {\n  text-decoration: none;\n  font-weight: bold;\n  background: transparent;\n  color: #ffffff;\n}\n#logo {\n  color: #ff8000;\n}\n#head {\n  clear: both;\n  margin: 0 1em;\n}\n#main {\n  line-height: 1.3;\n  text-align: justify;\n  margin: 1em;\n}\n#foot {\n  clear: both;\n  font-size: 80%;\n  text-align: center;\n  margin: 0 1.25em;\n  padding: 0.5em 0 0 0;\n  border-top: 1pt solid black;\n  page-break-before: avoid;\n  page-break-after: avoid;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/bluequad.css",
    "content": "/* Copyright (C) 2004-2021 Mike Pall.\n *\n * You are welcome to use the general ideas of this design for your own sites.\n * But please do not steal the stylesheet, the layout or the color scheme.\n */\n/* colorscheme:\n *\n * site  |  head   #4162bf/white   | #6078bf/#e6ecff\n * ------+------   ----------------+-------------------\n * nav   |  main   #bfcfff         | #e6ecff/black\n *\n * nav:  hiback   loback     #c5d5ff #b9c9f9\n *       hiborder loborder   #e6ecff #97a7d7\n *       link     hover      #2142bf #ff0000\n *\n * link: link visited hover  #2142bf #8122bf #ff0000\n *\n * main: boxback  boxborder  #f0f4ff #bfcfff\n */\nbody {\n  font-family: Verdana, Arial, Helvetica, sans-serif;\n  font-size: 10pt;\n  margin: 0;\n  padding: 0;\n  border: none;\n  background: #e0e0e0;\n  color: #000000;\n}\na:link {\n  text-decoration: none;\n  background: transparent;\n  color: #2142bf;\n}\na:visited {\n  text-decoration: none;\n  background: transparent;\n  color: #8122bf;\n}\na:hover, a:active {\n  text-decoration: underline;\n  background: transparent;\n  color: #ff0000;\n}\nh1, h2, h3 {\n  font-weight: bold;\n  text-align: left;\n  margin: 0.5em 0;\n  padding: 0;\n  background: transparent;\n}\nh1 {\n  font-size: 200%;\n  line-height: 3em; /* really 6em relative to body, match #site span */\n  margin: 0;\n}\nh2 {\n  font-size: 150%;\n  color: #606060;\n}\nh3 {\n  font-size: 125%;\n  color: #404040;\n}\np {\n  max-width: 600px;\n  margin: 0 0 0.5em 0;\n  padding: 0;\n}\nb {\n  color: #404040;\n}\nul, ol {\n  max-width: 600px;\n  margin: 0.5em 0;\n  padding: 0 0 0 2em;\n}\nul {\n  list-style: outside square;\n}\nol {\n  list-style: outside decimal;\n}\nli {\n  margin: 0;\n  padding: 0;\n}\ndl {\n  max-width: 600px;\n  margin: 1em 0;\n  padding: 1em;\n  border: 1px solid #bfcfff;\n  background: #f0f4ff;\n}\ndt {\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n}\ndt sup {\n  float: right;\n  margin-left: 1em;\n  color: #808080;\n}\ndt a:visited {\n  text-decoration: none;\n  color: #2142bf;\n}\ndt a:hover, dt a:active {\n  text-decoration: none;\n  color: #ff0000;\n}\ndd {\n  margin: 0.5em 0 0 2em;\n  padding: 0;\n}\ndiv.tablewrap { /* for IE *sigh* */\n  max-width: 600px;\n}\ntable {\n  table-layout: fixed;\n  border-spacing: 0;\n  border-collapse: collapse;\n  max-width: 600px;\n  width: 100%;\n  margin: 1em 0;\n  padding: 0;\n  border: 1px solid #bfcfff;\n}\ntr {\n  margin: 0;\n  padding: 0;\n  border: none;\n}\ntr.odd {\n  background: #f0f4ff;\n}\ntr.separate td {\n  border-top: 1px solid #bfcfff;\n}\ntd {\n  text-align: left;\n  margin: 0;\n  padding: 0.2em 0.5em;\n  border: none;\n}\ntt, code, kbd, samp {\n  font-family: Courier New, Courier, monospace;\n  line-height: 1.2;\n  font-size: 110%;\n}\nkbd {\n  font-weight: bolder;\n}\nblockquote, pre {\n  max-width: 600px;\n  margin: 1em 2em;\n  padding: 0;\n}\npre {\n  line-height: 1.1;\n}\npre.code {\n  line-height: 1.4;\n  margin: 0.5em 0 1em 0.5em;\n  padding: 0.5em 1em;\n  border: 1px solid #bfcfff;\n  background: #f0f4ff;\n}\npre.mark {\n  padding-left: 2em;\n}\nspan.codemark {\n  position:absolute;\n  left: 16em;\n  color: #4040c0;\n}\nspan.mark {\n  color: #4040c0;\n  font-family: Courier New, Courier, monospace;\n  line-height: 1.1;\n}\nimg {\n  border: none;\n  vertical-align: baseline;\n  margin: 0;\n  padding: 0;\n}\nimg.left {\n  float: left;\n  margin: 0.5em 1em 0.5em 0;\n}\nimg.right {\n  float: right;\n  margin: 0.5em 0 0.5em 1em;\n}\n.indent {\n  padding-left: 1em;\n}\n.flush {\n  clear: both;\n  visibility: hidden;\n}\n.hide, .noscreen {\n  display: none !important;\n}\n.ext {\n  color: #ff8000;\n}\n.new {\n  font-size: 6pt;\n  vertical-align: middle;\n  background: #ff8000;\n  color: #ffffff;\n}\n#site {\n  clear: both;\n  float: left;\n  width: 13em;\n  text-align: center;\n  font-weight: bold;\n  margin: 0;\n  padding: 0;\n  background: transparent;\n  color: #ffffff;\n}\n#site a {\n  font-size: 200%;\n}\n#site a:link, #site a:visited {\n  text-decoration: none;\n  font-weight: bold;\n  background: transparent;\n  color: #ffffff;\n}\n#site span {\n  line-height: 3em; /* really 6em relative to body, match h1 */\n}\n#logo {\n  color: #ffb380;\n}\n#head {\n  margin: 0;\n  padding: 0 0 0 2em;\n  border-left: solid 13em #4162bf;\n  border-right: solid 3em #6078bf;\n  background: #6078bf;\n  color: #e6ecff;\n}\n#nav {\n  clear: both;\n  float: left;\n  overflow: hidden;\n  text-align: left;\n  line-height: 1.5;\n  width: 13em;\n  padding-top: 1em;\n  background: transparent;\n}\n#nav ul {\n  list-style: none outside;\n  margin: 0;\n  padding: 0;\n}\n#nav li {\n  margin: 0;\n  padding: 0;\n}\n#nav a {\n  display: block;\n  text-decoration: none;\n  font-weight: bold;\n  margin: 0;\n  padding: 2px 1em;\n  border-top: 1px solid transparent;\n  border-bottom: 1px solid transparent;\n  background: transparent;\n  color: #2142bf;\n}\n#nav a:hover, #nav a:active {\n  text-decoration: none;\n  border-top: 1px solid #97a7d7;\n  border-bottom: 1px solid #e6ecff;\n  background: #b9c9f9;\n  color: #ff0000;\n}\n#nav a.current, #nav a.current:hover, #nav a.current:active {\n  border-top: 1px solid #e6ecff;\n  border-bottom: 1px solid #97a7d7;\n  background: #c5d5ff;\n  color: #2142bf;\n}\n#nav ul ul a {\n  padding: 0 1em 0 1.7em;\n}\n#nav ul ul ul a {\n  padding: 0 0.5em 0 2.4em;\n}\n#main {\n  line-height: 1.5;\n  text-align: left;\n  margin: 0;\n  padding: 1em 2em;\n  border-left: solid 13em #bfcfff;\n  border-right: solid 3em #e6ecff;\n  background: #e6ecff;\n}\n#foot {\n  clear: both;\n  font-size: 80%;\n  text-align: center;\n  margin: 0;\n  padding: 0.5em;\n  background: #6078bf;\n  color: #ffffff;\n}\n#foot a:link, #foot a:visited {\n  text-decoration: underline;\n  background: transparent;\n  color: #ffffff;\n}\n#foot a:hover, #foot a:active {\n  text-decoration: underline;\n  background: transparent;\n  color: #bfcfff;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/changes.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n<title>LuaJIT Change History</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<meta name=\"Author\" content=\"Mike Pall\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2017, Mike Pall\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ndiv.major { max-width: 600px; padding: 1em; margin: 1em 0 1em 0; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"http://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>LuaJIT Change History</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"http://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n<ul><li>\n<a class=\"current\" href=\"changes.html\">Changes</a>\n</li></ul>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://luajit.org/performance.html\">Performance <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"http://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis is a list of changes between the released versions of LuaJIT.<br>\nThe current <span style=\"color: #0000c0;\">stable version</span> is <strong>LuaJIT&nbsp;2.0.5</strong>.<br>\n</p>\n<p>\nPlease check the\n<a href=\"http://luajit.org/changes.html\"><span class=\"ext\">&raquo;</span>&nbsp;Online Change History</a>\nto see whether newer versions are available.\n</p>\n\n<div class=\"major\" style=\"background: #d0d0ff;\">\n<h2 id=\"LuaJIT-2.1.0-beta3\">LuaJIT 2.1.0-beta3 &mdash; 2017-05-01</h2>\n<ul>\n<li>Rewrite memory block allocator.</li>\n<li>Add various extension from Lua 5.2/5.3.</li>\n<li>Remove old Lua 5.0 compatibility defines.</li>\n<li>Set arg table before evaluating <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.</li>\n<li>Fix FOLD rules for <tt>math.abs()</tt> and FP negation.</li>\n<li>Fix soft-float <tt>math.abs()</tt> and negation.</li>\n<li>Fix formatting of some small denormals at low precision.</li>\n<li>LJ_GC64: Add JIT compiler support.</li>\n<li>x64/LJ_GC64: Add JIT compiler backend.</li>\n<li>x86/x64: Generate BMI2 shifts and rotates, if available.</li>\n<li>Windows/x86: Add full exception interoperability.</li>\n<li>ARM64: Add big-endian support.</li>\n<li>ARM64: Add JIT compiler backend.</li>\n<li>MIPS: Fix <tt>TSETR</tt> barrier.</li>\n<li>MIPS: Support MIPS16 interlinking.</li>\n<li>MIPS soft-float: Fix code generation for <tt>HREF</tt>.</li>\n<li>MIPS64: Add MIPS64 hard-float JIT compiler backend.</li>\n<li>MIPS64: Add MIPS64 hard-float/soft-float support to interpreter.</li>\n<li>FFI: Compile bitfield loads/stores.</li>\n<li>Various fixes common with the 2.0 branch.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.1.0-beta2\">LuaJIT 2.1.0-beta2 &mdash; 2016-03-03</h2>\n<ul>\n<li>Enable trace stitching.</li>\n<li>Use internal implementation for converting FP numbers to strings.</li>\n<li>Parse Unicode escape <tt>'\\u{XX...}'</tt> in string literals.</li>\n<li>Add MIPS soft-float support.</li>\n<li>Switch MIPS port to dual-number mode.</li>\n<li>x86/x64: Add support for AES-NI, AVX and AVX2 to DynASM.</li>\n<li>FFI: Add <tt>ssize_t</tt> declaration.</li>\n<li>FFI: Parse <tt>#line NN</tt> and <tt>#NN</tt>.</li>\n<li>Various minor fixes.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.1.0-beta1\">LuaJIT 2.1.0-beta1 &mdash; 2015-08-25</h2>\n<p>\nThis is a brief summary of the major changes in LuaJIT 2.1 compared to 2.0.\nPlease take a look at the commit history for more details.\n</p>\n<ul>\n<li>Changes to the VM core:\n<ul>\n<li>Add low-overhead profiler (<tt>-jp</tt>).</li>\n<li>Add <tt>LJ_GC64</tt> mode: 64 bit GC object references (really: 47 bit). Interpreter-only for now.</li>\n<li>Add <tt>LJ_FR2</tt> mode: Two-slot frame info. Required by <tt>LJ_GC64</tt> mode.</li>\n<li>Add <tt>table.new()</tt> and <tt>table.clear()</tt>.</li>\n<li>Parse binary number literals (<tt>0bxxx</tt>).</li>\n</ul></li>\n<li>Improvements to the JIT compiler:\n<ul>\n<li>Add trace stitching (disabled for now).</li>\n<li>Compile various builtins: <tt>string.char()</tt>, <tt>string.reverse()</tt>, <tt>string.lower()</tt>, <tt>string.upper()</tt>, <tt>string.rep()</tt>, <tt>string.format()</tt>, <tt>table.concat()</tt>, <tt>bit.tohex()</tt>, <tt>getfenv(0)</tt>, <tt>debug.getmetatable()</tt>.</li>\n<li>Compile <tt>string.find()</tt> for fixed string searches (no patterns).</li>\n<li>Compile <tt>BC_TSETM</tt>, e.g. <tt>{1,2,3,f()}</tt>.</li>\n<li>Compile string concatenations (<tt>BC_CAT</tt>).</li>\n<li>Compile <tt>__concat</tt> metamethod.</li>\n<li>Various minor optimizations.</li>\n</ul></li>\n<li>Internal Changes:\n<ul>\n<li>Add support for embedding LuaJIT bytecode for builtins.</li>\n<li>Replace various builtins with embedded bytecode.</li>\n<li>Refactor string buffers and string formatting.</li>\n<li>Remove obsolete non-truncating number to integer conversions.</li>\n</ul></li>\n<li>Ports:\n<ul>\n<li>Add Xbox One port (<tt>LJ_GC64</tt> mode).</li>\n<li>ARM64: Add port of the interpreter (<tt>LJ_GC64</tt> mode).</li>\n<li>x64: Add separate port of the interpreter to <tt>LJ_GC64</tt> mode.</li>\n<li>x86/x64: Drop internal x87 math functions. Use libm functions.</li>\n<li>x86: Remove x87 support from interpreter. SSE2 is mandatory now.</li>\n<li>PPC/e500: Drop support for this architecture.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>FFI: Add 64 bit bitwise operations.</li>\n<li>FFI: Compile VLA/VLS and large cdata allocations with default initialization.</li>\n<li>FFI: Compile conversions from functions to function pointers.</li>\n<li>FFI: Compile lightuserdata to <tt>void *</tt> conversion.</li>\n<li>FFI: Compile <tt>ffi.gc(cdata, nil)</tt>, too.</li>\n<li>FFI: Add <tt>ffi.typeinfo()</tt>.</li>\n</ul></li>\n</ul>\n</div>\n\n<div class=\"major\" style=\"background: #ffffd0;\">\n<h2 id=\"LuaJIT-2.0.5\">LuaJIT 2.0.5 &mdash; 2017-05-01</h2>\n<ul>\n<li>Add workaround for MSVC 2015 stdio changes.</li>\n<li>Limit mcode alloc probing, depending on the available pool size.</li>\n<li>Fix overly restrictive range calculation in mcode allocation.</li>\n<li>Fix out-of-scope goto handling in parser.</li>\n<li>Remove internal <tt>__mode = \"K\"</tt> and replace with safe check.</li>\n<li>Add \"proto\" field to <tt>jit.util.funcinfo()</tt>.</li>\n<li>Fix GC step size calculation.</li>\n<li>Initialize <tt>uv-&gt;immutable</tt> for upvalues of loaded chunks.</li>\n<li>Fix for cdata vs. non-cdata arithmetics/comparisons.</li>\n<li>Drop leftover regs in 'for' iterator assignment, too.</li>\n<li>Fix PHI remarking in SINK pass.</li>\n<li>Don't try to record outermost <tt>pcall()</tt> return to lower frame.</li>\n<li>Add guard for obscure aliasing between open upvalues and SSA slots.</li>\n<li>Remove assumption that <tt>lj_math_random_step()</tt> doesn't clobber FPRs.</li>\n<li>Fix handling of non-numeric strings in arithmetic coercions.</li>\n<li>Fix recording of <tt>select(n, ...)</tt> with off-trace varargs</li>\n<li>Fix install for cross-builds.</li>\n<li>Don't allocate unused 2nd result register in JIT compiler backend.</li>\n<li>Drop marks from replayed instructions when sinking.</li>\n<li>Fix unsinking check.</li>\n<li>Properly handle OOM in <tt>trace_save()</tt>.</li>\n<li>Limit number of arguments given to <tt>io.lines()</tt> and <tt>fp:lines()</tt>.</li>\n<li>Fix narrowing of <tt>TOBIT</tt>.</li>\n<li>OSX: Fix build with recent XCode.</li>\n<li>x86/x64: Don't spill an explicit <tt>REF_BASE</tt> in the IR.</li>\n<li>x86/x64: Fix instruction length decoder.</li>\n<li>x86/x64: Search for exit jumps with instruction length decoder.</li>\n<li>ARM: Fix <tt>BLX</tt> encoding for Thumb interworking calls.</li>\n<li>MIPS: Don't use <tt>RID_GP</tt> as a scratch register.</li>\n<li>MIPS: Fix emitted code for U32 to float conversion.</li>\n<li>MIPS: Backport workaround for compact unwind tables.</li>\n<li>MIPS: Fix cross-endian jit.bcsave.</li>\n<li>MIPS: Fix <tt>BC_ISNEXT</tt> fallback path.</li>\n<li>MIPS: Fix use of ffgccheck delay slots in interpreter.</li>\n<li>FFI: Fix FOLD rules for <tt>int64_t</tt> comparisons.</li>\n<li>FFI: Fix SPLIT pass for <tt>CONV i64.u64</tt>.</li>\n<li>FFI: Fix <tt>ipairs()</tt> recording.</li>\n<li>FFI: Don't propagate qualifiers into subtypes of complex.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.4\">LuaJIT 2.0.4 &mdash; 2015-05-14</h2>\n<ul>\n<li>Fix stack check in narrowing optimization.</li>\n<li>Fix Lua/C API typecheck error for special indexes.</li>\n<li>Fix string to number conversion.</li>\n<li>Fix lexer error for chunks without tokens.</li>\n<li>Don't compile <tt>IR_RETF</tt> after <tt>CALLT</tt> to ff with-side effects.</li>\n<li>Fix <tt>BC_UCLO</tt>/<tt>BC_JMP</tt> join optimization in Lua parser.</li>\n<li>Fix corner case in string to number conversion.</li>\n<li>Gracefully handle <tt>lua_error()</tt> for a suspended coroutine.</li>\n<li>Avoid error messages when building with Clang.</li>\n<li>Fix snapshot #0 handling for traces with a stack check on entry.</li>\n<li>Fix fused constant loads under high register pressure.</li>\n<li>Invalidate backpropagation cache after DCE.</li>\n<li>Fix ABC elimination.</li>\n<li>Fix debug info for main chunk of stripped bytecode.</li>\n<li>Fix FOLD rule for <tt>string.sub(s, ...) == k</tt>.</li>\n<li>Fix FOLD rule for <tt>STRREF</tt> of <tt>SNEW</tt>.</li>\n<li>Fix frame traversal while searching for error function.</li>\n<li>Prevent GC estimate miscalculation due to buffer growth.</li>\n<li>Prevent adding side traces for stack checks.</li>\n<li>Fix top slot calculation for snapshots with continuations.</li>\n<li>Fix check for reuse of SCEV results in <tt>FORL</tt>.</li>\n<li>Add PS Vita port.</li>\n<li>Fix compatibility issues with Illumos.</li>\n<li>Fix DragonFly build (unsupported).</li>\n<li>OpenBSD/x86: Better executable memory allocation for W^X mode.</li>\n<li>x86: Fix argument checks for <tt>ipairs()</tt> iterator.</li>\n<li>x86: <tt>lj_math_random_step()</tt> clobbers XMM regs on OSX Clang.</li>\n<li>x86: Fix code generation for unused result of <tt>math.random()</tt>.</li>\n<li>x64: Allow building with <tt>LUAJIT_USE_SYSMALLOC</tt> and <tt>LUAJIT_USE_VALGRIND</tt>.</li>\n<li>x86/x64: Fix argument check for bit shifts.</li>\n<li>x86/x64: Fix code generation for fused test/arith ops.</li>\n<li>ARM: Fix write barrier check in <tt>BC_USETS</tt>.</li>\n<li>PPC: Fix red zone overflow in machine code generation.</li>\n<li>PPC: Don't use <tt>mcrxr</tt> on PPE.</li>\n<li>Various archs: Fix excess stack growth in interpreter.</li>\n<li>FFI: Fix FOLD rule for <tt>TOBIT</tt> + <tt>CONV num.u32</tt>.</li>\n<li>FFI: Prevent DSE across <tt>ffi.string()</tt>.</li>\n<li>FFI: No meta fallback when indexing pointer to incomplete struct.</li>\n<li>FFI: Fix initialization of unions of subtypes.</li>\n<li>FFI: Fix cdata vs. non-cdata arithmetic and comparisons.</li>\n<li>FFI: Fix <tt>__index</tt>/<tt>__newindex</tt> metamethod resolution for ctypes.</li>\n<li>FFI: Fix compilation of reference field access.</li>\n<li>FFI: Fix frame traversal for backtraces with FFI callbacks.</li>\n<li>FFI: Fix recording of indexing a struct pointer ctype object itself.</li>\n<li>FFI: Allow non-scalar cdata to be compared for equality by address.</li>\n<li>FFI: Fix pseudo type conversions for type punning.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.3\">LuaJIT 2.0.3 &mdash; 2014-03-12</h2>\n<ul>\n<li>Add PS4 port.</li>\n<li>Add support for multilib distro builds.</li>\n<li>Fix OSX build.</li>\n<li>Fix MinGW build.</li>\n<li>Fix Xbox 360 build.</li>\n<li>Improve ULOAD forwarding for open upvalues.</li>\n<li>Fix GC steps threshold handling when called by JIT-compiled code.</li>\n<li>Fix argument checks for <tt>math.deg()</tt> and <tt>math.rad()</tt>.</li>\n<li>Fix <tt>jit.flush(func|true)</tt>.</li>\n<li>Respect <tt>jit.off(func)</tt> when returning to a function, too.</li>\n<li>Fix compilation of <tt>string.byte(s, nil, n)</tt>.</li>\n<li>Fix line number for relocated bytecode after closure fixup</li>\n<li>Fix frame traversal for backtraces.</li>\n<li>Fix ABC elimination.</li>\n<li>Fix handling of redundant PHIs.</li>\n<li>Fix snapshot restore for exit to function header.</li>\n<li>Fix type punning alias analysis for constified pointers</li>\n<li>Fix call unroll checks in the presence of metamethod frames.</li>\n<li>Fix initial maxslot for down-recursive traces.</li>\n<li>Prevent BASE register coalescing if parent uses <tt>IR_RETF</tt>.</li>\n<li>Don't purge modified function from stack slots in <tt>BC_RET</tt>.</li>\n<li>Fix recording of <tt>BC_VARG</tt>.</li>\n<li>Don't access dangling reference to reallocated IR.</li>\n<li>Fix frame depth display for bytecode dump in <tt>-jdump</tt>.</li>\n<li>ARM: Fix register allocation when rematerializing FPRs.</li>\n<li>x64: Fix store to upvalue for lightuserdata values.</li>\n<li>FFI: Add missing GC steps for callback argument conversions.</li>\n<li>FFI: Properly unload loaded DLLs.</li>\n<li>FFI: Fix argument checks for <tt>ffi.string()</tt>.</li>\n<li>FFI/x64: Fix passing of vector arguments to calls.</li>\n<li>FFI: Rehash finalizer table after GC cycle, if needed.</li>\n<li>FFI: Fix <tt>cts-&gt;L</tt> for cdata unsinking in snapshot restore.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.2\">LuaJIT 2.0.2 &mdash; 2013-06-03</h2>\n<ul>\n<li>Fix memory access check for fast string interning.</li>\n<li>Fix MSVC intrinsics for older versions.</li>\n<li>Add missing GC steps for <tt>io.*</tt> functions.</li>\n<li>Fix spurious red zone overflows in machine code generation.</li>\n<li>Fix jump-range constrained mcode allocation.</li>\n<li>Inhibit DSE for implicit loads via calls.</li>\n<li>Fix builtin string to number conversion for overflow digits.</li>\n<li>Fix optional argument handling while recording builtins.</li>\n<li>Fix optional argument handling in <tt>table.concat()</tt>.</li>\n<li>Add partial support for building with MingW64 GCC 4.8-SEH.</li>\n<li>Add missing PHI barrier to <tt>string.sub(str, a, b) == kstr</tt> FOLD rule.</li>\n<li>Fix compatibility issues with Illumos.</li>\n<li>ARM: Fix cache flush/sync for exit stubs of JIT-compiled code.</li>\n<li>MIPS: Fix cache flush/sync for JIT-compiled code jump area.</li>\n<li>PPC: Add <tt>plt</tt> suffix for external calls from assembler code.</li>\n<li>FFI: Fix snapshot substitution in SPLIT pass.</li>\n<li>FFI/x86: Fix register allocation for 64 bit comparisons.</li>\n<li>FFI: Fix tailcall in lowest frame to C&nbsp;function with bool result.</li>\n<li>FFI: Ignore <tt>long</tt> type specifier in <tt>ffi.istype()</tt>.</li>\n<li>FFI: Fix calling conventions for 32 bit OSX and iOS simulator (struct returns).</li>\n<li>FFI: Fix calling conventions for ARM hard-float EABI (nested structs).</li>\n<li>FFI: Improve error messages for arithmetic and comparison operators.</li>\n<li>FFI: Insert no-op type conversion for pointer to integer cast.</li>\n<li>FFI: Fix unroll limit for <tt>ffi.fill()</tt>.</li>\n<li>FFI: Must sink <tt>XBAR</tt> together with <tt>XSTORE</tt>s.</li>\n<li>FFI: Preserve intermediate string for <tt>const&nbsp;char&nbsp;*</tt> conversion.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.1\">LuaJIT 2.0.1 &mdash; 2013-02-19</h2>\n<ul>\n<li>Don't clear frame for out-of-memory error.</li>\n<li>Leave hook when resume catches error thrown from hook.</li>\n<li>Add missing GC steps for template table creation.</li>\n<li>Fix discharge order of comparisons in Lua parser.</li>\n<li>Improve buffer handling for <tt>io.read()</tt>.</li>\n<li>OSX: Add support for Mach-O object files to <tt>-b</tt> option.</li>\n<li>Fix PS3 port.</li>\n<li>Fix/enable Xbox 360 port.</li>\n<li>x86/x64: Always mark ref for shift count as non-weak.</li>\n<li>x64: Don't fuse implicitly 32-to-64 extended operands.</li>\n<li>ARM: Fix armhf call argument handling.</li>\n<li>ARM: Fix code generation for integer math.min/math.max.</li>\n<li>PPC/e500: Fix <tt>lj_vm_floor()</tt> for Inf/NaN.</li>\n<li>FFI: Change priority of table initializer variants for structs.</li>\n<li>FFI: Fix code generation for bool call result check on x86/x64.</li>\n<li>FFI: Load FFI library on-demand for bytecode with cdata literals.</li>\n<li>FFI: Fix handling of qualified transparent structs/unions.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0\">LuaJIT 2.0.0 &mdash; 2012-11-08</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n  <li>Fix Android/x86 build.</li>\n  <li>Fix recording of equality comparisons with <tt>__eq</tt> metamethods.</li>\n  <li>Fix detection of immutable upvalues.</li>\n  <li>Replace error with PANIC for callbacks from JIT-compiled code.</li>\n  <li>Fix builtin string to number conversion for <tt>INT_MIN</tt>.</li>\n  <li>Don't create unneeded array part for template tables.</li>\n  <li>Fix <tt>CONV.num.int</tt> sinking.</li>\n  <li>Don't propagate implicitly widened number to index metamethods.</li>\n  <li>ARM: Fix ordered comparisons of number vs. non-number.</li>\n  <li>FFI: Fix code generation for replay of sunk float fields.</li>\n  <li>FFI: Fix signedness of bool.</li>\n  <li>FFI: Fix recording of bool call result check on x86/x64.</li>\n  <li>FFI: Fix stack-adjustment for <tt>__thiscall</tt> callbacks.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta11\">LuaJIT 2.0.0-beta11 &mdash; 2012-10-16</h2>\n<ul>\n<li>New features:\n<ul>\n  <li>Use ARM VFP instructions, if available (build-time detection).</li>\n  <li>Add support for ARM hard-float EABI (<tt>armhf</tt>).</li>\n  <li>Add PS3 port.</li>\n  <li>Add many features from Lua&nbsp;5.2, e.g. <tt>goto</tt>/labels.\n  Refer to <a href=\"extensions.html#lua52\">this list</a>.</li>\n  <li>FFI: Add parameterized C types.</li>\n  <li>FFI: Add support for copy constructors.</li>\n  <li>FFI: Equality comparisons never raise an error (treat as unequal instead).</li>\n  <li>FFI: Box all accessed or returned enums.</li>\n  <li>FFI: Check for <tt>__new</tt> metamethod when calling a constructor.</li>\n  <li>FFI: Handle <tt>__pairs</tt>/<tt>__ipairs</tt> metamethods for cdata objects.</li>\n  <li>FFI: Convert <tt>io.*</tt> file handle to <tt>FILE *</tt> pointer (but as a <tt>void *</tt>).</li>\n  <li>FFI: Detect and support type punning through unions.</li>\n  <li>FFI: Improve various error messages.</li>\n</ul></li>\n<li>Build-system reorganization:\n<ul>\n  <li>Reorganize directory layout:<br>\n  <tt>lib/*</tt> &rarr; <tt>src/jit/*</tt><br>\n  <tt>src/buildvm_*.dasc</tt> &rarr; <tt>src/vm_*.dasc</tt><br>\n  <tt>src/buildvm_*.h</tt> &rarr; removed<br>\n  <tt>src/buildvm*</tt> &rarr; <tt>src/host/*</tt></li>\n  <li>Add minified Lua interpreter plus Lua BitOp (<tt>minilua</tt>) to run DynASM.</li>\n  <li>Change DynASM bit operations to use Lua BitOp</li>\n  <li>Translate only <tt>vm_*.dasc</tt> for detected target architecture.</li>\n  <li>Improve target detection for <tt>msvcbuild.bat</tt>.</li>\n  <li>Fix build issues on Cygwin and MinGW with optional MSys.</li>\n  <li>Handle cross-compiles with FPU/no-FPU or hard-fp/soft-fp ABI mismatch.</li>\n  <li>Remove some library functions for no-JIT/no-FFI builds.</li>\n  <li>Add uninstall target to top-level Makefile.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n  <li>Preserve snapshot #0 PC for all traces.</li>\n  <li>Fix argument checks for <tt>coroutine.create()</tt>.</li>\n  <li>Command line prints version and JIT status to <tt>stdout</tt>, not <tt>stderr</tt>.</li>\n  <li>Fix userdata <tt>__gc</tt> separations at Lua state close.</li>\n  <li>Fix <tt>TDUP</tt> to <tt>HLOAD</tt> forwarding for <tt>LJ_DUALNUM</tt> builds.</li>\n  <li>Fix buffer check in bytecode writer.</li>\n  <li>Make <tt>os.date()</tt> thread-safe.</li>\n  <li>Add missing declarations for MSVC intrinsics.</li>\n  <li>Fix dispatch table modifications for return hooks.</li>\n  <li>Workaround for MSVC conversion bug (<tt>double</tt> &rarr; <tt>uint32_t</tt> &rarr; <tt>int32_t</tt>).</li>\n  <li>Fix FOLD rule <tt>(i-j)-i => 0-j</tt>.</li>\n  <li>Never use DWARF unwinder on Windows.</li>\n  <li>Fix shrinking of direct mapped blocks in builtin allocator.</li>\n  <li>Limit recursion depth in <tt>string.match()</tt> et al.</li>\n  <li>Fix late despecialization of <tt>ITERN</tt> after loop has been entered.</li>\n  <li>Fix <tt>'f'</tt> and <tt>'L'</tt> options for <tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt>.</li>\n  <li>Fix <tt>package.searchpath()</tt>.</li>\n  <li>OSX: Change dylib names to be consistent with other platforms.</li>\n  <li>Android: Workaround for broken <tt>sprintf(\"%g\",&nbsp;-0.0)</tt>.</li>\n  <li>x86: Remove support for ancient CPUs without <tt>CMOV</tt> (before Pentium Pro).</li>\n  <li>x86: Fix register allocation for calls returning register pair.</li>\n  <li>x86/x64: Fix fusion of unsigned byte comparisons with swapped operands.</li>\n  <li>ARM: Fix <tt>tonumber()</tt> argument check.</li>\n  <li>ARM: Fix modulo operator and <tt>math.floor()</tt>/<tt>math.ceil()</tt> for <tt>inf</tt>/<tt>nan</tt>.</li>\n  <li>ARM: Invoke SPLIT pass for leftover <tt>IR_TOBIT</tt>.</li>\n  <li>ARM: Fix BASE register coalescing.</li>\n  <li>PPC: Fix interpreter state setup in callbacks.</li>\n  <li>PPC: Fix <tt>string.sub()</tt> range check.</li>\n  <li>MIPS: Support generation of MIPS/MIPSEL bytecode object files.</li>\n  <li>MIPS: Fix calls to <tt>floor()</tt>/<tt>ceil()</tt><tt>/trunc()</tt>.</li>\n  <li>ARM/PPC: Detect more target architecture variants.</li>\n  <li>ARM/PPC/e500/MIPS: Fix tailcalls from fast functions, esp. <tt>tostring()</tt>.</li>\n  <li>ARM/PPC/MIPS: Fix rematerialization of FP constants.</li>\n  <li>FFI: Don't call <tt>FreeLibrary()</tt> on our own EXE/DLL.</li>\n  <li>FFI: Resolve metamethods for constructors, too.</li>\n  <li>FFI: Properly disable callbacks on iOS (would require executable memory).</li>\n  <li>FFI: Fix cdecl string parsing during recording.</li>\n  <li>FFI: Show address pointed to for <tt>tostring(ref)</tt>, too.</li>\n  <li>FFI: Fix alignment of C call argument/return structure.</li>\n  <li>FFI: Initialize all fields of standard types.</li>\n  <li>FFI: Fix callback handling when new C&nbsp;types are declared in callback.</li>\n  <li>FFI: Fix recording of constructors for pointers.</li>\n  <li>FFI: Always resolve metamethods for pointers to structs.</li>\n  <li>FFI: Correctly propagate alignment when interning nested types.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n  <li>Add allocation sinking and store sinking optimization.</li>\n  <li>Constify immutable upvalues.</li>\n  <li>Add builtin string to integer or FP number conversion. Improves cross-platform consistency and correctness.</li>\n  <li>Create string hash slots in template tables for non-const values, too. Avoids later table resizes.</li>\n  <li>Eliminate <tt>HREFK</tt> guard for template table references.</li>\n  <li>Add various new FOLD rules.</li>\n  <li>Don't use stack unwinding for <tt>lua_yield()</tt> (slow on x64).</li>\n  <li>ARM, PPC, MIPS: Improve <tt>XLOAD</tt> operand fusion and register hinting.</li>\n  <li>PPC, MIPS: Compile <tt>math.sqrt()</tt> to sqrt instruction, if available.</li>\n  <li>FFI: Fold <tt>KPTR</tt> + constant offset in SPLIT pass.</li>\n  <li>FFI: Optimize/inline <tt>ffi.copy()</tt> and <tt>ffi.fill()</tt>.</li>\n  <li>FFI: Compile and optimize array/struct copies.</li>\n  <li>FFI: Compile <tt>ffi.typeof(cdata|ctype)</tt>, <tt>ffi.sizeof()</tt>, <tt>ffi.alignof()</tt>, <tt>ffi.offsetof()</tt> and <tt>ffi.gc()</tt>.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta10\">LuaJIT 2.0.0-beta10 &mdash; 2012-05-09</h2>\n<ul>\n<li>New features:\n<ul>\n<li>The MIPS of LuaJIT is complete. It requires a CPU conforming to the\nMIPS32&nbsp;R1 architecture with hardware FPU. O32 hard-fp ABI,\nlittle-endian or big-endian.</li>\n<li>Auto-detect target arch via cross-compiler. No need for\n<tt>TARGET=arch</tt> anymore.</li>\n<li>Make DynASM compatible with Lua 5.2.</li>\n<li>From Lua 5.2: Try <tt>__tostring</tt> metamethod on non-string error\nmessages..</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix parsing of hex literals with exponents.</li>\n<li>Fix bytecode dump for certain number constants.</li>\n<li>Fix argument type in error message for relative arguments.</li>\n<li>Fix argument error handling on Lua stacks without a frame.</li>\n<li>Add missing mcode limit check in assembler backend.</li>\n<li>Fix compilation on OpenBSD.</li>\n<li>Avoid recursive GC steps after GC-triggered trace exit.</li>\n<li>Replace <tt>&lt;unwind.h&gt;</tt> definitions with our own.</li>\n<li>Fix OSX build issues. Bump minimum required OSX version to 10.4.</li>\n<li>Fix discharge order of comparisons in Lua parser.</li>\n<li>Ensure running <tt>__gc</tt> of userdata created in <tt>__gc</tt>\nat state close.</li>\n<li>Limit number of userdata <tt>__gc</tt> separations at state close.</li>\n<li>Fix bytecode <tt>JMP</tt> slot range when optimizing\n<tt>and</tt>/<tt>or</tt> with constant LHS.</li>\n<li>Fix DSE of <tt>USTORE</tt>.</li>\n<li>Make <tt>lua_concat()</tt> work from C&nbsp;hook with partial frame.</li>\n<li>Add required PHIs for implicit conversions, e.g. via <tt>XREF</tt>\nforwarding.</li>\n<li>Add more comparison variants to Valgrind suppressions file.</li>\n<li>Disable loading bytecode with an extra header (BOM or <tt>#!</tt>).</li>\n<li>Fix PHI stack slot syncing.</li>\n<li>ARM: Reorder type/value tests to silence Valgrind.</li>\n<li>ARM: Fix register allocation for <tt>ldrd</tt>-optimized\n<tt>HREFK</tt>.</li>\n<li>ARM: Fix conditional branch fixup for <tt>OBAR</tt>.</li>\n<li>ARM: Invoke SPLIT pass for <tt>double</tt> args in FFI call.</li>\n<li>ARM: Handle all <tt>CALL*</tt> ops with <tt>double</tt> results in\nSPLIT pass.</li>\n<li>ARM: Fix rejoin of <tt>POW</tt> in SPLIT pass.</li>\n<li>ARM: Fix compilation of <tt>math.sinh</tt>, <tt>math.cosh</tt>,\n<tt>math.tanh</tt>.</li>\n<li>ARM, PPC: Avoid pointless arg clearing in <tt>BC_IFUNCF</tt>.</li>\n<li>PPC: Fix resume after yield from hook.</li>\n<li>PPC: Fix argument checking for <tt>rawget()</tt>.</li>\n<li>PPC: Fix fusion of floating-point <tt>XLOAD</tt>/<tt>XSTORE</tt>.</li>\n<li>PPC: Fix <tt>HREFK</tt> code generation for huge tables.</li>\n<li>PPC: Use builtin D-Cache/I-Cache sync code.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Ignore empty statements in <tt>ffi.cdef()</tt>.</li>\n<li>Ignore number parsing errors while skipping definitions.</li>\n<li>Don't touch frame in callbacks with tailcalls to fast functions.</li>\n<li>Fix library unloading on POSIX systems.</li>\n<li>Finalize cdata before userdata when closing the state.</li>\n<li>Change <tt>ffi.load()</tt> library name resolution for Cygwin.</li>\n<li>Fix resolving of function name redirects on Windows/x86.</li>\n<li>Fix symbol resolving error messages on Windows.</li>\n<li>Fix blacklisting of C functions calling callbacks.</li>\n<li>Fix result type of pointer difference.</li>\n<li>Use correct PC in FFI metamethod error message.</li>\n<li>Allow <tt>'typedef _Bool int BOOL;'</tt> for the Windows API.</li>\n<li>Don't record test for bool result of call, if ignored.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta9\">LuaJIT 2.0.0-beta9 &mdash; 2011-12-14</h2>\n<ul>\n<li>New features:\n<ul>\n<li>PPC port of LuaJIT is complete. Default is the dual-number port\n(usually faster). Single-number port selectable via <tt>src/Makefile</tt>\nat build time.</li>\n<li>Add FFI callback support.</li>\n<li>Extend <tt>-b</tt> to generate <tt>.c</tt>, <tt>.h</tt> or <tt>.obj/.o</tt>\nfiles with embedded bytecode.</li>\n<li>Allow loading embedded bytecode with <tt>require()</tt>.</li>\n<li>From Lua 5.2: Change to <tt>'\\z'</tt> escape. Reject undefined escape\nsequences.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix OSX 10.7 build. Fix <tt>install_name</tt> and versioning on OSX.</li>\n<li>Fix iOS build.</li>\n<li>Install <tt>dis_arm.lua</tt>, too.</li>\n<li>Mark installed shared library as executable.</li>\n<li>Add debug option to <tt>msvcbuild.bat</tt> and improve error handling.</li>\n<li>Fix data-flow analysis for iterators.</li>\n<li>Fix forced unwinding triggered by external unwinder.</li>\n<li>Record missing <tt>for</tt> loop slot loads (return to lower frame).</li>\n<li>Always use ANSI variants of Windows system functions.</li>\n<li>Fix GC barrier for multi-result table constructor (<tt>TSETM</tt>).</li>\n<li>Fix/add various FOLD rules.</li>\n<li>Add potential PHI for number conversions due to type instability.</li>\n<li>Do not eliminate PHIs only referenced from other PHIs.</li>\n<li>Correctly anchor implicit number to string conversions in Lua/C API.</li>\n<li>Fix various stack limit checks.</li>\n<li>x64: Use thread-safe exceptions for external unwinding (GCC platforms).</li>\n<li>x64: Fix result type of cdata index conversions.</li>\n<li>x64: Fix <tt>math.random()</tt> and <tt>bit.bswap()</tt> code generation.</li>\n<li>x64: Fix <tt>lightuserdata</tt> comparisons.</li>\n<li>x64: Always extend stack-passed arguments to pointer size.</li>\n<li>ARM: Many fixes to code generation backend.</li>\n<li>PPC/e500: Fix dispatch for binop metamethods.</li>\n<li>PPC/e500: Save/restore condition registers when entering/leaving the VM.</li>\n<li>PPC/e500: Fix write barrier in stores of strings to upvalues.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Fix C comment parsing.</li>\n<li>Fix snapshot optimization for cdata comparisons.</li>\n<li>Fix recording of const/enum lookups in namespaces.</li>\n<li>Fix call argument and return handling for <tt>I8/U8/I16/U16</tt> types.</li>\n<li>Fix unfused loads of float fields.</li>\n<li>Fix <tt>ffi.string()</tt> recording.</li>\n<li>Save <tt>GetLastError()</tt> around <tt>ffi.load()</tt> and symbol\nresolving, too.</li>\n<li>Improve ld script detection in <tt>ffi.load()</tt>.</li>\n<li>Record loads/stores to external variables in namespaces.</li>\n<li>Compile calls to stdcall, fastcall and vararg functions.</li>\n<li>Treat function ctypes like pointers in comparisons.</li>\n<li>Resolve <tt>__call</tt> metamethod for pointers, too.</li>\n<li>Record C function calls with bool return values.</li>\n<li>Record <tt>ffi.errno()</tt>.</li>\n<li>x86: Fix number to <tt>uint32_t</tt> conversion rounding.</li>\n<li>x86: Fix 64 bit arithmetic in assembler backend.</li>\n<li>x64: Fix struct-by-value calling conventions.</li>\n<li>ARM: Ensure invocation of SPLIT pass for float conversions.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Display trace types with <tt>-jv</tt> and <tt>-jdump</tt>.</li>\n<li>Record isolated calls. But prefer recording loops over calls.</li>\n<li>Specialize to prototype for non-monomorphic functions. Solves the\ntrace-explosion problem for closure-heavy programming styles.</li>\n<li>Always generate a portable <tt>vmdef.lua</tt>. Easier for distros.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta8\">LuaJIT 2.0.0-beta8 &mdash; 2011-06-23</h2>\n<ul>\n<li>New features:\n<ul>\n<li>Soft-float ARM port of LuaJIT is complete.</li>\n<li>Add support for bytecode loading/saving and <tt>-b</tt> command line\noption.</li>\n<li>From Lua 5.2: <tt>__len</tt> metamethod for tables\n(disabled by default).</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>ARM: Misc. fixes for interpreter.</li>\n<li>x86/x64: Fix <tt>bit.*</tt> argument checking in interpreter.</li>\n<li>Catch early out-of-memory in memory allocator initialization.</li>\n<li>Fix data-flow analysis for paths leading to an upvalue close.</li>\n<li>Fix check for missing arguments in <tt>string.format()</tt>.</li>\n<li>Fix Solaris/x86 build (note: not a supported target).</li>\n<li>Fix recording of loops with instable directions in side traces.</li>\n<li>x86/x64: Fix fusion of comparisons with <tt>u8</tt>/<tt>u16</tt>\n<tt>XLOAD</tt>.</li>\n<li>x86/x64: Fix register allocation for variable shifts.</li>\n</ul></li>\n<li>FFI library:\n<ul>\n<li>Add <tt>ffi.errno()</tt>. Save <tt>errno</tt>/<tt>GetLastError()</tt>\naround allocations etc.</li>\n<li>Fix <tt>__gc</tt> for VLA/VLS cdata objects.</li>\n<li>Fix recording of casts from 32 bit cdata pointers to integers.</li>\n<li><tt>tonumber(cdata)</tt> returns <tt>nil</tt> for non-numbers.</li>\n<li>Show address pointed to for <tt>tostring(pointer)</tt>.</li>\n<li>Print <tt>NULL</tt> pointers as <tt>\"cdata&lt;... *&gt;: NULL\"</tt>.</li>\n<li>Support <tt>__tostring</tt> metamethod for pointers to structs, too.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>More tuning for loop unrolling heuristics.</li>\n<li>Flatten and compress in-memory debug info (saves ~70%).</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta7\">LuaJIT 2.0.0-beta7 &mdash; 2011-05-05</h2>\n<ul>\n<li>New features:\n<ul>\n<li>ARM port of the LuaJIT interpreter is complete.</li>\n<li>FFI library: Add <tt>ffi.gc()</tt>, <tt>ffi.metatype()</tt>,\n<tt>ffi.istype()</tt>.</li>\n<li>FFI library: Resolve ld script redirection in <tt>ffi.load()</tt>.</li>\n<li>From Lua 5.2: <tt>package.searchpath()</tt>, <tt>fp:read(\"*L\")</tt>,\n<tt>load(string)</tt>.</li>\n<li>From Lua 5.2, disabled by default: empty statement,\n<tt>table.unpack()</tt>, modified <tt>coroutine.running()</tt>.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>FFI library: numerous fixes.</li>\n<li>Fix type mismatches in store-to-load forwarding.</li>\n<li>Fix error handling within metamethods.</li>\n<li>Fix <tt>table.maxn()</tt>.</li>\n<li>Improve accuracy of <tt>x^-k</tt> on x64.</li>\n<li>Fix code generation for Intel Atom in x64 mode.</li>\n<li>Fix narrowing of POW.</li>\n<li>Fix recording of retried fast functions.</li>\n<li>Fix code generation for <tt>bit.bnot()</tt> and multiplies.</li>\n<li>Fix error location within cpcall frames.</li>\n<li>Add workaround for old libgcc unwind bug.</li>\n<li>Fix <tt>lua_yield()</tt> and <tt>getmetatable(lightuserdata)</tt> on x64.</li>\n<li>Misc. fixes for PPC/e500 interpreter.</li>\n<li>Fix stack slot updates for down-recursion.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Add dual-number mode (int/double) for the VM. Enabled for ARM.</li>\n<li>Improve narrowing of arithmetic operators and <tt>for</tt> loops.</li>\n<li>Tune loop unrolling heuristics and increase trace recorder limits.</li>\n<li>Eliminate dead slots in snapshots using bytecode data-flow analysis.</li>\n<li>Avoid phantom stores to proxy tables.</li>\n<li>Optimize lookups in empty proxy tables.</li>\n<li>Improve bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta6\">LuaJIT 2.0.0-beta6 &mdash; 2011-02-11</h2>\n<ul>\n<li>New features:\n<ul>\n<li>PowerPC/e500v2 port of the LuaJIT interpreter is complete.</li>\n<li>Various minor features from Lua 5.2: Hex escapes in literals,\n<tt>'\\*'</tt> escape, reversible <tt>string.format(\"%q\",s)</tt>,\n<tt>\"%g\"</tt> pattern, <tt>table.sort</tt> checks callbacks,\n<tt>os.exit(status|true|false[,close])</tt>.</li>\n<li>Lua 5.2 <tt>__pairs</tt> and <tt>__ipairs</tt> metamethods\n(disabled by default).</li>\n<li>Initial release of the FFI library.</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix <tt>string.format()</tt> for non-finite numbers.</li>\n<li>Fix memory leak when compiled to use the built-in allocator.</li>\n<li>x86/x64: Fix unnecessary resize in <tt>TSETM</tt> bytecode.</li>\n<li>Fix various GC issues with traces and <tt>jit.flush()</tt>.</li>\n<li>x64: Fix fusion of indexes for array references.</li>\n<li>x86/x64: Fix stack overflow handling for coroutine results.</li>\n<li>Enable low-2GB memory allocation on FreeBSD/x64.</li>\n<li>Fix <tt>collectgarbage(\"count\")</tt> result if more than 2GB is in use.</li>\n<li>Fix parsing of hex floats.</li>\n<li>x86/x64: Fix loop branch inversion with trailing\n<tt>HREF+NE/EQ</tt>.</li>\n<li>Add <tt>jit.os</tt> string.</li>\n<li><tt>coroutine.create()</tt> permits running C functions, too.</li>\n<li>Fix OSX build to work with newer ld64 versions.</li>\n<li>Fix bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Emit specialized bytecode for <tt>pairs()</tt>/<tt>next()</tt>.</li>\n<li>Improve bytecode coalescing of <tt>nil</tt> constants.</li>\n<li>Compile calls to vararg functions.</li>\n<li>Compile <tt>select()</tt>.</li>\n<li>Improve alias analysis, esp. for loads from allocations.</li>\n<li>Tuning of various compiler heuristics.</li>\n<li>Refactor and extend IR conversion instructions.</li>\n<li>x86/x64: Various backend enhancements related to the FFI.</li>\n<li>Add SPLIT pass to split 64 bit IR instructions for 32 bit CPUs.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta5\">LuaJIT 2.0.0-beta5 &mdash; 2010-08-24</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n<li>Fix trace exit dispatch to function headers.</li>\n<li>Fix Windows and OSX builds with LUAJIT_DISABLE_JIT.</li>\n<li>Reorganize and fix placement of generated machine code on x64.</li>\n<li>Fix TNEW in x64 interpreter.</li>\n<li>Do not eliminate PHIs for values only referenced from side exits.</li>\n<li>OS-independent canonicalization of strings for non-finite numbers.</li>\n<li>Fix <tt>string.char()</tt> range check on x64.</li>\n<li>Fix <tt>tostring()</tt> resolving within <tt>print()</tt>.</li>\n<li>Fix error handling for <tt>next()</tt>.</li>\n<li>Fix passing of constant arguments to external calls on x64.</li>\n<li>Fix interpreter argument check for two-argument SSE math functions.</li>\n<li>Fix C frame chain corruption caused by <tt>lua_cpcall()</tt>.</li>\n<li>Fix return from <tt>pcall()</tt> within active hook.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Replace on-trace GC frame syncing with interpreter exit.</li>\n<li>Improve hash lookup specialization by not removing dead keys during GC.</li>\n<li>Turn traces into true GC objects.</li>\n<li>Avoid starting a GC cycle immediately after library init.</li>\n<li>Add weak guards to improve dead-code elimination.</li>\n<li>Speed up string interning.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta4\">LuaJIT 2.0.0-beta4 &mdash; 2010-03-28</h2>\n<ul>\n<li>Correctness and completeness:\n<ul>\n<li>Fix precondition for on-trace creation of table keys.</li>\n<li>Fix <tt>{f()}</tt> on x64 when table is resized.</li>\n<li>Fix folding of ordered comparisons with same references.</li>\n<li>Fix snapshot restores for multi-result bytecodes.</li>\n<li>Fix potential hang when recording bytecode with nested closures.</li>\n<li>Fix recording of <tt>getmetatable()</tt>, <tt>tonumber()</tt> and bad argument types.</li>\n<li>Fix SLOAD fusion across returns to lower frames.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Add array bounds check elimination. <tt>-Oabc</tt> is enabled by default.</li>\n<li>More tuning for x64, e.g. smaller table objects.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta3\">LuaJIT 2.0.0-beta3 &mdash; 2010-03-07</h2>\n<ul>\n<li>LuaJIT x64 port:\n<ul>\n<li>Port integrated memory allocator to Linux/x64, Windows/x64 and OSX/x64.</li>\n<li>Port interpreter and JIT compiler to x64.</li>\n<li>Port DynASM to x64.</li>\n<li>Many 32/64 bit cleanups in the VM.</li>\n<li>Allow building the interpreter with either x87 or SSE2 arithmetics.</li>\n<li>Add external unwinding and C++ exception interop (default on x64).</li>\n</ul></li>\n<li>Correctness and completeness:\n<ul>\n<li>Fix constructor bytecode generation for certain conditional values.</li>\n<li>Fix some cases of ordered string comparisons.</li>\n<li>Fix <tt>lua_tocfunction()</tt>.</li>\n<li>Fix cutoff register in JMP bytecode for some conditional expressions.</li>\n<li>Fix PHI marking algorithm for references from variant slots.</li>\n<li>Fix <tt>package.cpath</tt> for non-default PREFIX.</li>\n<li>Fix DWARF2 frame unwind information for interpreter on OSX.</li>\n<li>Drive the GC forward on string allocations in the parser.</li>\n<li>Implement call/return hooks (zero-cost if disabled).</li>\n<li>Implement yield from C hooks.</li>\n<li>Disable JIT compiler on older non-SSE2 CPUs instead of aborting.</li>\n</ul></li>\n<li>Structural and performance enhancements:\n<ul>\n<li>Compile recursive code (tail-, up- and down-recursion).</li>\n<li>Improve heuristics for bytecode penalties and blacklisting.</li>\n<li>Split CALL/FUNC recording and clean up fast function call semantics.</li>\n<li>Major redesign of internal function call handling.</li>\n<li>Improve FOR loop const specialization and integerness checks.</li>\n<li>Switch to pre-initialized stacks. Avoid frame-clearing.</li>\n<li>Colocation of prototypes and related data: bytecode, constants, debug info.</li>\n<li>Cleanup parser and streamline bytecode generation.</li>\n<li>Add support for weak IR references to register allocator.</li>\n<li>Switch to compressed, extensible snapshots.</li>\n<li>Compile returns to frames below the start frame.</li>\n<li>Improve alias analysis of upvalues using a disambiguation hash value.</li>\n<li>Compile floor/ceil/trunc to SSE2 helper calls or SSE4.1 instructions.</li>\n<li>Add generic C call handling to IR and backend.</li>\n<li>Improve KNUM fuse vs. load heuristics.</li>\n<li>Compile various <tt>io.*()</tt> functions.</li>\n<li>Compile <tt>math.sinh()</tt>, <tt>math.cosh()</tt>, <tt>math.tanh()</tt>\nand <tt>math.random()</tt>.</li>\n</ul></li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta2\">LuaJIT 2.0.0-beta2 &mdash; 2009-11-09</h2>\n<ul>\n<li>Reorganize build system. Build static+shared library on POSIX.</li>\n<li>Allow C++ exception conversion on all platforms\nusing a wrapper function.</li>\n<li>Automatically catch C++ exceptions and rethrow Lua error\n(DWARF2 only).</li>\n<li>Check for the correct x87 FPU precision at strategic points.</li>\n<li>Always use wrappers for libm functions.</li>\n<li>Resurrect metamethod name strings before copying them.</li>\n<li>Mark current trace, even if compiler is idle.</li>\n<li>Ensure FILE metatable is created only once.</li>\n<li>Fix type comparisons when different integer types are involved.</li>\n<li>Fix <tt>getmetatable()</tt> recording.</li>\n<li>Fix TDUP with dead keys in template table.</li>\n<li><tt>jit.flush(tr)</tt> returns status.\nPrevent manual flush of a trace that's still linked.</li>\n<li>Improve register allocation heuristics for invariant references.</li>\n<li>Compile the push/pop variants of <tt>table.insert()</tt> and\n<tt>table.remove()</tt>.</li>\n<li>Compatibility with MSVC <tt>link&nbsp/debug</tt>.</li>\n<li>Fix <tt>lua_iscfunction()</tt>.</li>\n<li>Fix <tt>math.random()</tt> when compiled with <tt>-fpic</tt> (OSX).</li>\n<li>Fix <tt>table.maxn()</tt>.</li>\n<li>Bump <tt>MACOSX_DEPLOYMENT_TARGET</tt> to <tt>10.4</tt></li>\n<li><tt>luaL_check*()</tt> and <tt>luaL_opt*()</tt> now support\nnegative arguments, too.<br>\nThis matches the behavior of Lua 5.1, but not the specification.</li>\n</ul>\n\n<h2 id=\"LuaJIT-2.0.0-beta1\">LuaJIT 2.0.0-beta1 &mdash; 2009-10-31</h2>\n<ul>\n<li>This is the first public release of LuaJIT 2.0.</li>\n<li>The whole VM has been rewritten from the ground up, so there's\nno point in listing differences over earlier versions.</li>\n</ul>\n</div>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2017 Mike Pall\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/contact.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Contact</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Contact</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nIf you want to report bugs, propose fixes or suggest enhancements,\nplease use the\n<a href=\"https://github.com/LuaJIT/LuaJIT/issues\"><span class=\"ext\">&raquo;</span>&nbsp;GitHub issue tracker</a>.\n</p>\n<p>\nPlease send general questions to the\n<a href=\"https://luajit.org/list.html\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT mailing list</a>.\n</p>\n<p>\nYou can also send any questions you have directly to me:\n</p>\n\n<script type=\"text/javascript\">\n<!--\nvar xS=\"@-:\\\" .0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<abc>defghijklmnopqrstuvwxyz\";function xD(s)\n{var len=s.length;var r=\"\";for(var i=0;i<len;i++)\n{var c=s.charAt(i);var n=xS.indexOf(c);if(n!=-1)c=xS.charAt(69-n);r+=c;}\ndocument.write(\"<\"+\"p>\"+r+\"<\"+\"/p>\\n\");}\n//-->\n</script>\n<script type=\"text/javascript\">\n<!--\nxD(\"fyZKB8xv\\\"FJytmz8.KAB0u52D\")\n//--></script>\n<noscript>\n<p><img src=\"img/contact.png\" alt=\"Contact info in image\" width=\"170\" height=\"13\">\n</p>\n</noscript>\n\n<h2>Copyright</h2>\n<p>\nAll documentation is\nCopyright &copy; 2005-2021 Mike Pall.\n</p>\n\n\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_buffer.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>String Buffer Library</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\n.lib {\n  vertical-align: middle;\n  margin-left: 5px;\n  padding: 0 5px;\n  font-size: 60%;\n  border-radius: 5px;\n  background: #c5d5ff;\n  color: #000;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>String Buffer Library</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThe string buffer library allows <b>high-performance manipulation of\nstring-like data</b>.\n</p>\n<p>\nUnlike Lua strings, which are constants, string buffers are\n<b>mutable</b> sequences of 8-bit (binary-transparent) characters. Data\ncan be stored, formatted and encoded into a string buffer and later\nconverted, extracted or decoded.\n</p>\n<p>\nThe convenient string buffer API simplifies common string manipulation\ntasks, that would otherwise require creating many intermediate strings.\nString buffers improve performance by eliminating redundant memory\ncopies, object creation, string interning and garbage collection\noverhead. In conjunction with the FFI library, they allow zero-copy\noperations.\n</p>\n<p>\nThe string buffer libary also includes a high-performance\n<a href=\"serialize\">serializer</a> for Lua objects.\n</p>\n\n<h2 id=\"wip\" style=\"color:#ff0000\">Work in Progress</h2>\n<p>\n<b style=\"color:#ff0000\">This library is a work in progress. More\nfunctionality will be added soon.</b>\n</p>\n\n<h2 id=\"use\">Using the String Buffer Library</h2>\n<p>\nThe string buffer library is built into LuaJIT by default, but it's not\nloaded by default. Add this to the start of every Lua file that needs\none of its functions:\n</p>\n<pre class=\"code\">\nlocal buffer = require(\"string.buffer\")\n</pre>\n<p>\nThe convention for the syntax shown on this page is that <tt>buffer</tt>\nrefers to the buffer library and <tt>buf</tt> refers to an individual\nbuffer object.\n</p>\n<p>\nPlease note the difference between a Lua function call, e.g.\n<tt>buffer.new()</tt> (with a dot) and a Lua method call, e.g.\n<tt>buf:reset()</tt> (with a colon).\n</p>\n\n<h3 id=\"buffer_object\">Buffer Objects</h3>\n<p>\nA buffer object is a garbage-collected Lua object. After creation with\n<tt>buffer.new()</tt>, it can (and should) be reused for many operations.\nWhen the last reference to a buffer object is gone, it will eventually\nbe freed by the garbage collector, along with the allocated buffer\nspace.\n</p>\n<p>\nBuffers operate like a FIFO (first-in first-out) data structure. Data\ncan be appended (written) to the end of the buffer and consumed (read)\nfrom the front of the buffer. These operations may be freely mixed.\n</p>\n<p>\nThe buffer space that holds the characters is managed automatically\n&mdash; it grows as needed and already consumed space is recycled. Use\n<tt>buffer.new(size)</tt> and <tt>buf:free()</tt>, if you need more\ncontrol.\n</p>\n<p>\nThe maximum size of a single buffer is the same as the maximum size of a\nLua string, which is slightly below two gigabytes. For huge data sizes,\nneither strings nor buffers are the right data structure &mdash; use the\nFFI library to directly map memory or files up to the virtual memory\nlimit of your OS.\n</p>\n\n<h3 id=\"buffer_overview\">Buffer Method Overview</h3>\n<ul>\n<li>\nThe <tt>buf:put*()</tt>-like methods append (write) characters to the\nend of the buffer.\n</li>\n<li>\nThe <tt>buf:get*()</tt>-like methods consume (read) characters from the\nfront of the buffer.\n</li>\n<li>\nOther methods, like <tt>buf:tostring()</tt> only read the buffer\ncontents, but don't change the buffer.\n</li>\n<li>\nThe <tt>buf:set()</tt> method allows zero-copy consumption of a string\nor an FFI cdata object as a buffer.\n</li>\n<li>\nThe FFI-specific methods allow zero-copy read/write-style operations or\nmodifying the buffer contents in-place. Please check the\n<a href=\"#ffi_caveats\">FFI caveats</a> below, too.\n</li>\n<li>\nMethods that don't need to return anything specific, return the buffer\nobject itself as a convenience. This allows method chaining, e.g.:\n<tt>buf:reset():encode(obj)</tt> or <tt>buf:skip(len):get()</tt>\n</li>\n</ul>\n\n<h2 id=\"create\">Buffer Creation and Management</h2>\n\n<h3 id=\"buffer_new\"><tt>local buf = buffer.new([size [,options]])<br>\nlocal buf = buffer.new([options])</tt></h3>\n<p>\nCreates a new buffer object.\n</p>\n<p>\nThe optional <tt>size</tt> argument ensures a minimum initial buffer\nsize. This is strictly an optimization when the required buffer size is\nknown beforehand. The buffer space will grow as needed, in any case.\n</p>\n<p>\nThe optional table <tt>options</tt> sets various\n<a href=\"#serialize_options\">serialization options</a>.\n</p>\n\n<h3 id=\"buffer_reset\"><tt>buf = buf:reset()</tt></h3>\n<p>\nReset (empty) the buffer. The allocated buffer space is not freed and\nmay be reused.\n</p>\n\n<h3 id=\"buffer_free\"><tt>buf = buf:free()</tt></h3>\n<p>\nThe buffer space of the buffer object is freed. The object itself\nremains intact, empty and may be reused.\n</p>\n<p>\nNote: you normally don't need to use this method. The garbage collector\nautomatically frees the buffer space, when the buffer object is\ncollected. Use this method, if you need to free the associated memory\nimmediately.\n</p>\n\n<h2 id=\"write\">Buffer Writers</h2>\n\n<h3 id=\"buffer_put\"><tt>buf = buf:put([str|num|obj] [,…])</tt></h3>\n<p>\nAppends a string <tt>str</tt>, a number <tt>num</tt> or any object\n<tt>obj</tt> with a <tt>__tostring</tt> metamethod to the buffer.\nMultiple arguments are appended in the given order.\n</p>\n<p>\nAppending a buffer to a buffer is possible and short-circuited\ninternally. But it still involves a copy. Better combine the buffer\nwrites to use a single buffer.\n</p>\n\n<h3 id=\"buffer_putf\"><tt>buf = buf:putf(format, …)</tt></h3>\n<p>\nAppends the formatted arguments to the buffer. The <tt>format</tt>\nstring supports the same options as <tt>string.format()</tt>.\n</p>\n\n<h3 id=\"buffer_putcdata\"><tt>buf = buf:putcdata(cdata, len)</tt><span class=\"lib\">FFI</span></h3>\n<p>\nAppends the given <tt>len</tt> number of bytes from the memory pointed\nto by the FFI <tt>cdata</tt> object to the buffer. The object needs to\nbe convertible to a (constant) pointer.\n</p>\n\n<h3 id=\"buffer_set\"><tt>buf = buf:set(str)<br>\nbuf = buf:set(cdata, len)</tt><span class=\"lib\">FFI</span></h3>\n<p>\nThis method allows zero-copy consumption of a string or an FFI cdata\nobject as a buffer. It stores a reference to the passed string\n<tt>str</tt> or the FFI <tt>cdata</tt> object in the buffer. Any buffer\nspace originally allocated is freed. This is <i>not</i> an append\noperation, unlike the <tt>buf:put*()</tt> methods.\n</p>\n<p>\nAfter calling this method, the buffer behaves as if\n<tt>buf:free():put(str)</tt> or <tt>buf:free():put(cdata,&nbsp;len)</tt>\nhad been called. However, the data is only referenced and not copied, as\nlong as the buffer is only consumed.\n</p>\n<p>\nIn case the buffer is written to later on, the referenced data is copied\nand the object reference is removed (copy-on-write semantics).\n</p>\n<p>\nThe stored reference is an anchor for the garbage collector and keeps the\noriginally passed string or FFI cdata object alive.\n</p>\n\n<h3 id=\"buffer_reserve\"><tt>ptr, len = buf:reserve(size)</tt><span class=\"lib\">FFI</span><br>\n<tt>buf = buf:commit(used)</tt><span class=\"lib\">FFI</span></h3>\n<p>\nThe <tt>reserve</tt> method reserves at least <tt>size</tt> bytes of\nwrite space in the buffer. It returns an <tt>uint8_t&nbsp;*</tt> FFI\ncdata pointer <tt>ptr</tt> that points to this space.\n</p>\n<p>\nThe available length in bytes is returned in <tt>len</tt>. This is at\nleast <tt>size</tt> bytes, but may be more to facilitate efficient\nbuffer growth. You can either make use of the additional space or ignore\n<tt>len</tt> and only use <tt>size</tt> bytes.\n</p>\n<p>\nThe <tt>commit</tt> method appends the <tt>used</tt> bytes of the\npreviously returned write space to the buffer data.\n</p>\n<p>\nThis pair of methods allows zero-copy use of C read-style APIs:\n</p>\n<pre class=\"code\">\nlocal MIN_SIZE = 65536\nrepeat\n  local ptr, len = buf:reserve(MIN_SIZE)\n  local n = C.read(fd, ptr, len)\n  if n == 0 then break end -- EOF.\n  if n &lt; 0 then error(\"read error\") end\n  buf:commit(n)\nuntil false\n</pre>\n<p>\nThe reserved write space is <i>not</i> initialized. At least the\n<tt>used</tt> bytes <b>must</b> be written to before calling the\n<tt>commit</tt> method. There's no need to call the <tt>commit</tt>\nmethod, if nothing is added to the buffer (e.g. on error).\n</p>\n\n<h2 id=\"read\">Buffer Readers</h2>\n\n<h3 id=\"buffer_length\"><tt>len = #buf</tt></h3>\n<p>\nReturns the current length of the buffer data in bytes.\n</p>\n\n<h3 id=\"buffer_concat\"><tt>res = str|num|buf .. str|num|buf […]</tt></h3>\n<p>\nThe Lua concatenation operator <tt>..</tt> also accepts buffers, just\nlike strings or numbers. It always returns a string and not a buffer.\n</p>\n<p>\nNote that although this is supported for convenience, this thwarts one\nof the main reasons to use buffers, which is to avoid string\nallocations. Rewrite it with <tt>buf:put()</tt> and <tt>buf:get()</tt>.\n</p>\n<p>\nMixing this with unrelated objects that have a <tt>__concat</tt>\nmetamethod may not work, since these probably only expect strings.\n</p>\n\n<h3 id=\"buffer_skip\"><tt>buf = buf:skip(len)</tt></h3>\n<p>\nSkips (consumes) <tt>len</tt> bytes from the buffer up to the current\nlength of the buffer data.\n</p>\n\n<h3 id=\"buffer_get\"><tt>str, … = buf:get([len|nil] [,…])</tt></h3>\n<p>\nConsumes the buffer data and returns one or more strings. If called\nwithout arguments, the whole buffer data is consumed. If called with a\nnumber, up to <tt>len</tt> bytes are consumed. A <tt>nil</tt> argument\nconsumes the remaining buffer space (this only makes sense as the last\nargument). Multiple arguments consume the buffer data in the given\norder.\n</p>\n<p>\nNote: a zero length or no remaining buffer data returns an empty string\nand not <tt>nil</tt>.\n</p>\n\n<h3 id=\"buffer_tostring\"><tt>str = buf:tostring()<br>\nstr = tostring(buf)</tt></h3>\n<p>\nCreates a string from the buffer data, but doesn't consume it. The\nbuffer remains unchanged.\n</p>\n<p>\nBuffer objects also define a <tt>__tostring</tt> metamethod. This means\nbuffers can be passed to the global <tt>tostring()</tt> function and\nmany other functions that accept this in place of strings. The important\ninternal uses in functions like <tt>io.write()</tt> are short-circuited\nto avoid the creation of an intermediate string object.\n</p>\n\n<h3 id=\"buffer_ref\"><tt>ptr, len = buf:ref()</tt><span class=\"lib\">FFI</span></h3>\n<p>\nReturns an <tt>uint8_t&nbsp;*</tt> FFI cdata pointer <tt>ptr</tt> that\npoints to the buffer data. The length of the buffer data in bytes is\nreturned in <tt>len</tt>.\n</p>\n<p>\nThe returned pointer can be directly passed to C functions that expect a\nbuffer and a length. You can also do bytewise reads\n(<tt>local&nbsp;x&nbsp;=&nbsp;ptr[i]</tt>) or writes\n(<tt>ptr[i]&nbsp;=&nbsp;0x40</tt>) of the buffer data.\n</p>\n<p>\nIn conjunction with the <tt>skip</tt> method, this allows zero-copy use\nof C write-style APIs:\n</p>\n<pre class=\"code\">\nrepeat\n  local ptr, len = buf:ref()\n  if len == 0 then break end\n  local n = C.write(fd, ptr, len)\n  if n &lt; 0 then error(\"write error\") end\n  buf:skip(n)\nuntil n >= len\n</pre>\n<p>\nUnlike Lua strings, buffer data is <i>not</i> implicitly\nzero-terminated. It's not safe to pass <tt>ptr</tt> to C functions that\nexpect zero-terminated strings. If you're not using <tt>len</tt>, then\nyou're doing something wrong.\n</p>\n\n<h2 id=\"serialize\">Serialization of Lua Objects</h2>\n<p>\nThe following functions and methods allow <b>high-speed serialization</b>\n(encoding) of a Lua object into a string and decoding it back to a Lua\nobject. This allows convenient storage and transport of <b>structured\ndata</b>.\n</p>\n<p>\nThe encoded data is in an <a href=\"#serialize_format\">internal binary\nformat</a>. The data can be stored in files, binary-transparent\ndatabases or transmitted to other LuaJIT instances across threads,\nprocesses or networks.\n</p>\n<p>\nEncoding speed can reach up to 1 Gigabyte/second on a modern desktop- or\nserver-class system, even when serializing many small objects. Decoding\nspeed is mostly constrained by object creation cost.\n</p>\n<p>\nThe serializer handles most Lua types, common FFI number types and\nnested structures. Functions, thread objects, other FFI cdata and full\nuserdata cannot be serialized (yet).\n</p>\n<p>\nThe encoder serializes nested structures as trees. Multiple references\nto a single object will be stored separately and create distinct objects\nafter decoding. Circular references cause an error.\n</p>\n\n<h3 id=\"serialize_methods\">Serialization Functions and Methods</h3>\n\n<h3 id=\"buffer_encode\"><tt>str = buffer.encode(obj)<br>\nbuf = buf:encode(obj)</tt></h3>\n<p>\nSerializes (encodes) the Lua object <tt>obj</tt>. The stand-alone\nfunction returns a string <tt>str</tt>. The buffer method appends the\nencoding to the buffer.\n</p>\n<p>\n<tt>obj</tt> can be any of the supported Lua types &mdash; it doesn't\nneed to be a Lua table.\n</p>\n<p>\nThis function may throw an error when attempting to serialize\nunsupported object types, circular references or deeply nested tables.\n</p>\n\n<h3 id=\"buffer_decode\"><tt>obj = buffer.decode(str)<br>\nobj = buf:decode()</tt></h3>\n<p>\nThe stand-alone function de-serializes (decodes) the string\n<tt>str</tt>, the buffer method de-serializes one object from the\nbuffer. Both return a Lua object <tt>obj</tt>.\n</p>\n<p>\nThe returned object may be any of the supported Lua types &mdash;\neven <tt>nil</tt>.\n</p>\n<p>\nThis function may throw an error when fed with malformed or incomplete\nencoded data. The stand-alone function throws when there's left-over\ndata after decoding a single top-level object. The buffer method leaves\nany left-over data in the buffer.\n</p>\n\n<h3 id=\"serialize_options\">Serialization Options</h3>\n<p>\nThe <tt>options</tt> table passed to <tt>buffer.new()</tt> may contain\nthe following members (all optional):\n</p>\n<ul>\n<li>\n<tt>dict</tt> is a Lua table holding a <b>dictionary of strings</b> that\ncommonly occur as table keys of objects you are serializing. These keys\nare compactly encoded as indexes during serialization. A well chosen\ndictionary saves space and improves serialization performance.\n</li>\n<li>\n<tt>metatable</tt> is a Lua table holding a <b>dictionary of metatables</b>\nfor the table objects you are serializing.\n</li>\n</ul>\n<p>\n<tt>dict</tt> needs to be an array of strings and <tt>metatable</tt> needs\nto be an array of tables. Both starting at index 1 and without holes (no\n<tt>nil</tt> inbetween). The tables are anchored in the buffer object and\ninternally modified into a two-way index (don't do this yourself, just pass\na plain array). The tables must not be modified after they have been passed\nto <tt>buffer.new()</tt>.\n</p>\n<p>\nThe <tt>dict</tt> and <tt>metatable</tt> tables used by the encoder and\ndecoder must be the same. Put the most common entries at the front. Extend\nat the end to ensure backwards-compatibility &mdash; older encodings can\nthen still be read. You may also set some indexes to <tt>false</tt> to\nexplicitly drop backwards-compatibility. Old encodings that use these\nindexes will throw an error when decoded.\n</p>\n<p>\nMetatables that are not found in the <tt>metatable</tt> dictionary are\nignored when encoding. Decoding returns a table with a <tt>nil</tt>\nmetatable.\n</p>\n<p>\nNote: parsing and preparation of the options table is somewhat\nexpensive. Create a buffer object only once and recycle it for multiple\nuses. Avoid mixing encoder and decoder buffers, since the\n<tt>buf:set()</tt> method frees the already allocated buffer space:\n</p>\n<pre class=\"code\">\nlocal options = {\n  dict = { \"commonly\", \"used\", \"string\", \"keys\" },\n}\nlocal buf_enc = buffer.new(options)\nlocal buf_dec = buffer.new(options)\n\nlocal function encode(obj)\n  return buf_enc:reset():encode(obj):get()\nend\n\nlocal function decode(str)\n  return buf_dec:set(str):decode()\nend\n</pre>\n\n<h3 id=\"serialize_stream\">Streaming Serialization</h3>\n<p>\nIn some contexts, it's desirable to do piecewise serialization of large\ndatasets, also known as <i>streaming</i>.\n</p>\n<p>\nThis serialization format can be safely concatenated and supports streaming.\nMultiple encodings can simply be appended to a buffer and later decoded\nindividually:\n</p>\n<pre class=\"code\">\nlocal buf = buffer.new()\nbuf:encode(obj1)\nbuf:encode(obj2)\nlocal copy1 = buf:decode()\nlocal copy2 = buf:decode()\n</pre>\n<p>\nHere's how to iterate over a stream:\n</p>\n<pre class=\"code\">\nwhile #buf ~= 0 do\n  local obj = buf:decode()\n  -- Do something with obj.\nend\n</pre>\n<p>\nSince the serialization format doesn't prepend a length to its encoding,\nnetwork applications may need to transmit the length, too.\n</p>\n\n<h3 id=\"serialize_format\">Serialization Format Specification</h3>\n<p>\nThis serialization format is designed for <b>internal use</b> by LuaJIT\napplications. Serialized data is upwards-compatible and portable across\nall supported LuaJIT platforms.\n</p>\n<p>\nIt's an <b>8-bit binary format</b> and not human-readable. It uses e.g.\nembedded zeroes and stores embedded Lua string objects unmodified, which\nare 8-bit-clean, too. Encoded data can be safely concatenated for\nstreaming and later decoded one top-level object at a time.\n</p>\n<p>\nThe encoding is reasonably compact, but tuned for maximum performance,\nnot for minimum space usage. It compresses well with any of the common\nbyte-oriented data compression algorithms.\n</p>\n<p>\nAlthough documented here for reference, this format is explicitly\n<b>not</b> intended to be a 'public standard' for structured data\ninterchange across computer languages (like JSON or MessagePack). Please\ndo not use it as such.\n</p>\n<p>\nThe specification is given below as a context-free grammar with a\ntop-level <tt>object</tt> as the starting point. Alternatives are\nseparated by the <tt>|</tt> symbol and <tt>*</tt> indicates repeats.\nGrouping is implicit or indicated by <tt>{…}</tt>. Terminals are\neither plain hex numbers, encoded as bytes, or have a <tt>.format</tt>\nsuffix.\n</p>\n<pre>\nobject    → nil | false | true\n          | null | lightud32 | lightud64\n          | int | num | tab | tab_mt\n          | int64 | uint64 | complex\n          | string\n\nnil       → 0x00\nfalse     → 0x01\ntrue      → 0x02\n\nnull      → 0x03                            // NULL lightuserdata\nlightud32 → 0x04 data.I                   // 32 bit lightuserdata\nlightud64 → 0x05 data.L                   // 64 bit lightuserdata\n\nint       → 0x06 int.I                                 // int32_t\nnum       → 0x07 double.L\n\ntab       → 0x08                                   // Empty table\n          | 0x09 h.U h*{object object}          // Key/value hash\n          | 0x0a a.U a*object                    // 0-based array\n          | 0x0b a.U a*object h.U h*{object object}      // Mixed\n          | 0x0c a.U (a-1)*object                // 1-based array\n          | 0x0d a.U (a-1)*object h.U h*{object object}  // Mixed\ntab_mt    → 0x0e (index-1).U tab          // Metatable dict entry\n\nint64     → 0x10 int.L                             // FFI int64_t\nuint64    → 0x11 uint.L                           // FFI uint64_t\ncomplex   → 0x12 re.L im.L                         // FFI complex\n\nstring    → (0x20+len).U len*char.B\n          | 0x0f (index-1).U                 // String dict entry\n\n.B = 8 bit\n.I = 32 bit little-endian\n.L = 64 bit little-endian\n.U = prefix-encoded 32 bit unsigned number n:\n     0x00..0xdf   → n.B\n     0xe0..0x1fdf → (0xe0|(((n-0xe0)>>8)&0x1f)).B ((n-0xe0)&0xff).B\n   0x1fe0..       → 0xff n.I\n</pre>\n\n<h2 id=\"error\">Error handling</h2>\n<p>\nMany of the buffer methods can throw an error. Out-of-memory or usage\nerrors are best caught with an outer wrapper for larger parts of code.\nThere's not much one can do after that, anyway.\n</p>\n<p>\nOTOH you may want to catch some errors individually. Buffer methods need\nto receive the buffer object as the first argument. The Lua colon-syntax\n<tt>obj:method()</tt> does that implicitly. But to wrap a method with\n<tt>pcall()</tt>, the arguments need to be passed like this:\n</p>\n<pre class=\"code\">\nlocal ok, err = pcall(buf.encode, buf, obj)\nif not ok then\n  -- Handle error in err.\nend\n</pre>\n\n<h2 id=\"ffi_caveats\">FFI caveats</h2>\n<p>\nThe string buffer library has been designed to work well together with\nthe FFI library. But due to the low-level nature of the FFI library,\nsome care needs to be taken:\n</p>\n<p>\nFirst, please remember that FFI pointers are zero-indexed. The space\nreturned by <tt>buf:reserve()</tt> and <tt>buf:ref()</tt> starts at the\nreturned pointer and ends before <tt>len</tt> bytes after that.\n</p>\n<p>\nI.e. the first valid index is <tt>ptr[0]</tt> and the last valid index\nis <tt>ptr[len-1]</tt>. If the returned length is zero, there's no valid\nindex at all. The returned pointer may even be <tt>NULL</tt>.\n</p>\n<p>\nThe space pointed to by the returned pointer is only valid as long as\nthe buffer is not modified in any way (neither append, nor consume, nor\nreset, etc.). The pointer is also not a GC anchor for the buffer object\nitself.\n</p>\n<p>\nBuffer data is only guaranteed to be byte-aligned. Casting the returned\npointer to a data type with higher alignment may cause unaligned\naccesses. It depends on the CPU architecture whether this is allowed or\nnot (it's always OK on x86/x64 and mostly OK on other modern\narchitectures).\n</p>\n<p>\nFFI pointers or references do not count as GC anchors for an underlying\nobject. E.g. an <tt>array</tt> allocated with <tt>ffi.new()</tt> is\nanchored by <tt>buf:set(array,&nbsp;len)</tt>, but not by\n<tt>buf:set(array+offset,&nbsp;len)</tt>. The addition of the offset\ncreates a new pointer, even when the offset is zero. In this case, you\nneed to make sure there's still a reference to the original array as\nlong as its contents are in use by the buffer.\n</p>\n<p>\nEven though each LuaJIT VM instance is single-threaded (but you can\ncreate multiple VMs), FFI data structures can be accessed concurrently.\nBe careful when reading/writing FFI cdata from/to buffers to avoid\nconcurrent accesses or modifications. In particular, the memory\nreferenced by <tt>buf:set(cdata,&nbsp;len)</tt> must not be modified\nwhile buffer readers are working on it. Shared, but read-only memory\nmappings of files are OK, but only if the file does not change.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_c_api.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Lua/C API Extensions</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Lua/C API Extensions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a class=\"current\" href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT adds some extensions to the standard Lua/C API. The LuaJIT include\ndirectory must be in the compiler search path (<tt>-I<i>path</i></tt>)\nto be able to include the required header for C code:\n</p>\n<pre class=\"code\">\n#include \"luajit.h\"\n</pre>\n<p>\nOr for C++ code:\n</p>\n<pre class=\"code\">\n#include \"lua.hpp\"\n</pre>\n\n<h2 id=\"luaJIT_setmode\"><tt>luaJIT_setmode(L, idx, mode)</tt>\n&mdash; Control VM</h2>\n<p>\nThis is a C API extension to allow control of the VM from C code. The\nfull prototype of <tt>LuaJIT_setmode</tt> is:\n</p>\n<pre class=\"code\">\nLUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);\n</pre>\n<p>\nThe returned status is either success (<tt>1</tt>) or failure (<tt>0</tt>).\nThe second argument is either <tt>0</tt> or a stack index (similar to the\nother Lua/C API functions).\n</p>\n<p>\nThe third argument specifies the mode, which is 'or'ed with a flag.\nThe flag can be <tt>LUAJIT_MODE_OFF</tt> to turn a feature off,\n<tt>LUAJIT_MODE_ON</tt> to turn a feature on, or\n<tt>LUAJIT_MODE_FLUSH</tt> to flush cached code.\n</p>\n<p>\nThe following modes are defined:\n</p>\n\n<h3 id=\"mode_engine\"><tt>luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|flag)</tt></h3>\n<p>\nTurn the whole JIT compiler on or off or flush the whole cache of compiled code.\n</p>\n\n<h3 id=\"mode_func\"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_FUNC|flag)</tt><br>\n<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLFUNC|flag)</tt><br>\n<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLSUBFUNC|flag)</tt></h3>\n<p>\nThis sets the mode for the function at the stack index <tt>idx</tt> or\nthe parent of the calling function (<tt>idx = 0</tt>). It either\nenables JIT compilation for a function, disables it and flushes any\nalready compiled code or only flushes already compiled code. This\napplies recursively to all sub-functions of the function with\n<tt>LUAJIT_MODE_ALLFUNC</tt> or only to the sub-functions with\n<tt>LUAJIT_MODE_ALLSUBFUNC</tt>.\n</p>\n\n<h3 id=\"mode_trace\"><tt>luaJIT_setmode(L, trace,<br>\n&nbsp;&nbsp;LUAJIT_MODE_TRACE|LUAJIT_MODE_FLUSH)</tt></h3>\n<p>\nFlushes the specified root trace and all of its side traces from the cache.\nThe code for the trace will be retained as long as there are any other\ntraces which link to it.\n</p>\n\n<h3 id=\"mode_wrapcfunc\"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</tt></h3>\n<p>\nThis mode defines a wrapper function for calls to C functions. If\ncalled with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt>\nmust be a <tt>lightuserdata</tt> object holding a pointer to the wrapper\nfunction. From now on all C functions are called through the wrapper\nfunction. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned\noff and all C functions are directly called.\n</p>\n<p>\nThe wrapper function can be used for debugging purposes or to catch\nand convert foreign exceptions. But please read the section on\n<a href=\"extensions.html#exceptions\">C++&nbsp;exception interoperability</a>\nfirst. Recommended usage can be seen in this C++ code excerpt:\n</p>\n<pre class=\"code\">\n#include &lt;exception&gt;\n#include \"lua.hpp\"\n\n// Catch C++ exceptions and convert them to Lua error messages.\n// Customize as needed for your own exception classes.\nstatic int wrap_exceptions(lua_State *L, lua_CFunction f)\n{\n  try {\n    return f(L);  // Call wrapped function and return result.\n  } catch (const char *s) {  // Catch and convert exceptions.\n    lua_pushstring(L, s);\n  } catch (std::exception& e) {\n    lua_pushstring(L, e.what());\n  } catch (...) {\n    lua_pushliteral(L, \"caught (...)\");\n  }\n  return lua_error(L);  // Rethrow as a Lua error.\n}\n\nstatic int myinit(lua_State *L)\n{\n  ...\n  // Define wrapper function and enable it.\n  lua_pushlightuserdata(L, (void *)wrap_exceptions);\n  luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);\n  lua_pop(L, 1);\n  ...\n}\n</pre>\n<p>\nNote that you can only define <b>a single global wrapper function</b>,\nso be careful when using this mechanism from multiple C++ modules.\nAlso note that this mechanism is not without overhead.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_ffi.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>FFI Library</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Library</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a class=\"current\" href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\n\nThe FFI library allows <b>calling external C&nbsp;functions</b> and\n<b>using C&nbsp;data structures</b> from pure Lua code.\n\n</p>\n<p>\n\nThe FFI library largely obviates the need to write tedious manual\nLua/C bindings in C. No need to learn a separate binding language\n&mdash; <b>it parses plain C&nbsp;declarations!</b> These can be\ncut-n-pasted from C&nbsp;header files or reference manuals. It's up to\nthe task of binding large libraries without the need for dealing with\nfragile binding generators.\n\n</p>\n<p>\nThe FFI library is tightly integrated into LuaJIT (it's not available\nas a separate module). The code generated by the JIT-compiler for\naccesses to C&nbsp;data structures from Lua code is on par with the\ncode a C&nbsp;compiler would generate. Calls to C&nbsp;functions can\nbe inlined in JIT-compiled code, unlike calls to functions bound via\nthe classic Lua/C API.\n</p>\n<p>\nThis page gives a short introduction to the usage of the FFI library.\n<em>Please use the FFI sub-topics in the navigation bar to learn more.</em>\n</p>\n\n<h2 id=\"call\">Motivating Example: Calling External C Functions</h2>\n<p>\nIt's really easy to call an external C&nbsp;library function:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&#9312;\n&#9313;\n\n\n&#9314;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">int printf(const char *fmt, ...);</span>\n]]\nffi.C.printf(\"Hello %s!\", \"world\")\n</pre>\n<p>\nSo, let's pick that apart:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> Load the FFI library.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> Add a C&nbsp;declaration\nfor the function. The part inside the double-brackets (in green) is\njust standard C&nbsp;syntax.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Call the named\nC&nbsp;function &mdash; Yes, it's that simple!\n</p>\n<p style=\"font-size: 8pt;\">\nActually, what goes on behind the scenes is far from simple: <span\nstyle=\"color:#4040c0;\">&#9314;</span> makes use of the standard\nC&nbsp;library namespace <tt>ffi.C</tt>. Indexing this namespace with\na symbol name (<tt>\"printf\"</tt>) automatically binds it to the\nstandard C&nbsp;library. The result is a special kind of object which,\nwhen called, runs the <tt>printf</tt> function. The arguments passed\nto this function are automatically converted from Lua objects to the\ncorresponding C&nbsp;types.\n</p>\n<p>\nOk, so maybe the use of <tt>printf()</tt> wasn't such a spectacular\nexample. You could have done that with <tt>io.write()</tt> and\n<tt>string.format()</tt>, too. But you get the idea ...\n</p>\n<p>\nSo here's something to pop up a message box on Windows:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">int MessageBoxA(void *w, const char *txt, const char *cap, int type);</span>\n]]\nffi.C.MessageBoxA(nil, \"Hello world!\", \"Test\", 0)\n</pre>\n<p>\nBing! Again, that was far too easy, no?\n</p>\n<p style=\"font-size: 8pt;\">\nCompare this with the effort required to bind that function using the\nclassic Lua/C API: create an extra C&nbsp;file, add a C&nbsp;function\nthat retrieves and checks the argument types passed from Lua and calls\nthe actual C&nbsp;function, add a list of module functions and their\nnames, add a <tt>luaopen_*</tt> function and register all module\nfunctions, compile and link it into a shared library (DLL), move it to\nthe proper path, add Lua code that loads the module aaaand ... finally\ncall the binding function. Phew!\n</p>\n\n<h2 id=\"cdata\">Motivating Example: Using C Data Structures</h2>\n<p>\nThe FFI library allows you to create and access C&nbsp;data\nstructures. Of course the main use for this is for interfacing with\nC&nbsp;functions. But they can be used stand-alone, too.\n</p>\n<p>\nLua is built upon high-level data types. They are flexible, extensible\nand dynamic. That's why we all love Lua so much. Alas, this can be\ninefficient for certain tasks, where you'd really want a low-level\ndata type. E.g. a large array of a fixed structure needs to be\nimplemented with a big table holding lots of tiny tables. This imposes\nboth a substantial memory overhead as well as a performance overhead.\n</p>\n<p>\nHere's a sketch of a library that operates on color images plus a\nsimple benchmark. First, the plain Lua version:\n</p>\n<pre class=\"code\">\nlocal floor = math.floor\n\nlocal function image_ramp_green(n)\n  local img = {}\n  local f = 255/(n-1)\n  for i=1,n do\n    img[i] = { red = 0, green = floor((i-1)*f), blue = 0, alpha = 255 }\n  end\n  return img\nend\n\nlocal function image_to_grey(img, n)\n  for i=1,n do\n    local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)\n    img[i].red = y; img[i].green = y; img[i].blue = y\n  end\nend\n\nlocal N = 400*400\nlocal img = image_ramp_green(N)\nfor i=1,1000 do\n  image_to_grey(img, N)\nend\n</pre>\n<p>\nThis creates a table with 160.000 pixels, each of which is a table\nholding four number values in the range of 0-255. First an image with\na green ramp is created (1D for simplicity), then the image is\nconverted to greyscale 1000 times. Yes, that's silly, but I was in\nneed of a simple example ...\n</p>\n<p>\nAnd here's the FFI version. The modified parts have been marked in\nbold:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&#9312;\n\n\n\n\n\n&#9313;\n\n&#9314;\n&#9315;\n\n\n\n\n\n\n&#9314;\n&#9316;</span><b>local ffi = require(\"ffi\")\nffi.cdef[[\n</b><span style=\"color:#00a000;\">typedef struct { uint8_t red, green, blue, alpha; } rgba_pixel;</span><b>\n]]</b>\n\nlocal function image_ramp_green(n)\n  <b>local img = ffi.new(\"rgba_pixel[?]\", n)</b>\n  local f = 255/(n-1)\n  for i=<b>0,n-1</b> do\n    <b>img[i].green = i*f</b>\n    <b>img[i].alpha = 255</b>\n  end\n  return img\nend\n\nlocal function image_to_grey(img, n)\n  for i=<b>0,n-1</b> do\n    local y = <b>0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue</b>\n    img[i].red = y; img[i].green = y; img[i].blue = y\n  end\nend\n\nlocal N = 400*400\nlocal img = image_ramp_green(N)\nfor i=1,1000 do\n  image_to_grey(img, N)\nend\n</pre>\n<p>\nOk, so that wasn't too difficult:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> First, load the FFI\nlibrary and declare the low-level data type. Here we choose a\n<tt>struct</tt> which holds four byte fields, one for each component\nof a 4x8&nbsp;bit RGBA pixel.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> Creating the data\nstructure with <tt>ffi.new()</tt> is straightforward &mdash; the\n<tt>'?'</tt> is a placeholder for the number of elements of a\nvariable-length array.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> C&nbsp;arrays are\nzero-based, so the indexes have to run from <tt>0</tt> to\n<tt>n-1</tt>. One might want to allocate one more element instead to\nsimplify converting legacy code.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> Since <tt>ffi.new()</tt>\nzero-fills the array by default, we only need to set the green and the\nalpha fields.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> The calls to\n<tt>math.floor()</tt> can be omitted here, because floating-point\nnumbers are already truncated towards zero when converting them to an\ninteger. This happens implicitly when the number is stored in the\nfields of each pixel.\n</p>\n<p>\nNow let's have a look at the impact of the changes: first, memory\nconsumption for the image is down from 22&nbsp;Megabytes to\n640&nbsp;Kilobytes (400*400*4 bytes). That's a factor of 35x less! So,\nyes, tables do have a noticeable overhead. BTW: The original program\nwould consume 40&nbsp;Megabytes in plain Lua (on x64).\n</p>\n<p>\nNext, performance: the pure Lua version runs in 9.57 seconds (52.9\nseconds with the Lua interpreter) and the FFI version runs in 0.48\nseconds on my machine (YMMV). That's a factor of 20x faster (110x\nfaster than the Lua interpreter).\n</p>\n<p style=\"font-size: 8pt;\">\nThe avid reader may notice that converting the pure Lua version over\nto use array indexes for the colors (<tt>[1]</tt> instead of\n<tt>.red</tt>, <tt>[2]</tt> instead of <tt>.green</tt> etc.) ought to\nbe more compact and faster. This is certainly true (by a factor of\n~1.7x). Switching to a struct-of-arrays would help, too.\n</p>\n<p style=\"font-size: 8pt;\">\nHowever the resulting code would be less idiomatic and rather\nerror-prone. And it still doesn't get even close to the performance of\nthe FFI version of the code. Also, high-level data structures cannot\nbe easily passed to other C&nbsp;functions, especially I/O functions,\nwithout undue conversion penalties.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_ffi_api.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>ffi.* API Functions</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.abitable { width: 30em; line-height: 1.2; }\ntr.abihead td { font-weight: bold; }\ntd.abiparam { font-weight: bold; width: 6em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1><tt>ffi.*</tt> API Functions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a class=\"current\" href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page describes the API functions provided by the FFI library in\ndetail. It's recommended to read through the\n<a href=\"ext_ffi.html\">introduction</a> and the\n<a href=\"ext_ffi_tutorial.html\">FFI tutorial</a> first.\n</p>\n\n<h2 id=\"glossary\">Glossary</h2>\n<ul>\n<li><b>cdecl</b> &mdash; An abstract C&nbsp;type declaration (a Lua\nstring).</li>\n<li><b>ctype</b> &mdash; A C&nbsp;type object. This is a special kind of\n<b>cdata</b> returned by <tt>ffi.typeof()</tt>. It serves as a\n<b>cdata</b> <a href=\"#ffi_new\">constructor</a> when called.</li>\n<li><b>cdata</b> &mdash; A C&nbsp;data object. It holds a value of the\ncorresponding <b>ctype</b>.</li>\n<li><b>ct</b> &mdash; A C&nbsp;type specification which can be used for\nmost of the API functions. Either a <b>cdecl</b>, a <b>ctype</b> or a\n<b>cdata</b> serving as a template type.</li>\n<li><b>cb</b> &mdash; A callback object. This is a C&nbsp;data object\nholding a special function pointer. Calling this function from\nC&nbsp;code runs an associated Lua function.</li>\n<li><b>VLA</b> &mdash; A variable-length array is declared with a\n<tt>?</tt> instead of the number of elements, e.g. <tt>\"int[?]\"</tt>.\nThe number of elements (<tt>nelem</tt>) must be given when it's\n<a href=\"#ffi_new\">created</a>.</li>\n<li><b>VLS</b> &mdash; A variable-length struct is a <tt>struct</tt> C\ntype where the last element is a <b>VLA</b>. The same rules for\ndeclaration and creation apply.</li>\n</ul>\n\n<h2 id=\"decl\">Declaring and Accessing External Symbols</h2>\n<p>\nExternal symbols must be declared first and can then be accessed by\nindexing a <a href=\"ext_ffi_semantics.html#clib\">C&nbsp;library\nnamespace</a>, which automatically binds the symbol to a specific\nlibrary.\n</p>\n\n<h3 id=\"ffi_cdef\"><tt>ffi.cdef(def)</tt></h3>\n<p>\nAdds multiple C&nbsp;declarations for types or external symbols (named\nvariables or functions). <tt>def</tt> must be a Lua string. It's\nrecommended to use the syntactic sugar for string arguments as\nfollows:\n</p>\n<pre class=\"code\">\nffi.cdef[[\n<span style=\"color:#00a000;\">typedef struct foo { int a, b; } foo_t;  // Declare a struct and typedef.\nint dofoo(foo_t *f, int n);  /* Declare an external C function. */</span>\n]]\n</pre>\n<p>\nThe contents of the string (the part in green above) must be a\nsequence of\n<a href=\"ext_ffi_semantics.html#clang\">C&nbsp;declarations</a>,\nseparated by semicolons. The trailing semicolon for a single\ndeclaration may be omitted.\n</p>\n<p>\nPlease note that external symbols are only <em>declared</em>, but they\nare <em>not bound</em> to any specific address, yet. Binding is\nachieved with C&nbsp;library namespaces (see below).\n</p>\n<p style=\"color: #c00000;\">\nC&nbsp;declarations are not passed through a C&nbsp;pre-processor,\nyet. No pre-processor tokens are allowed, except for\n<tt>#pragma&nbsp;pack</tt>. Replace <tt>#define</tt> in existing\nC&nbsp;header files with <tt>enum</tt>, <tt>static&nbsp;const</tt>\nor <tt>typedef</tt> and/or pass the files through an external\nC&nbsp;pre-processor (once). Be careful not to include unneeded or\nredundant declarations from unrelated header files.\n</p>\n\n<h3 id=\"ffi_C\"><tt>ffi.C</tt></h3>\n<p>\nThis is the default C&nbsp;library namespace &mdash; note the\nuppercase <tt>'C'</tt>. It binds to the default set of symbols or\nlibraries on the target system. These are more or less the same as a\nC&nbsp;compiler would offer by default, without specifying extra link\nlibraries.\n</p>\n<p>\nOn POSIX systems, this binds to symbols in the default or global\nnamespace. This includes all exported symbols from the executable and\nany libraries loaded into the global namespace. This includes at least\n<tt>libc</tt>, <tt>libm</tt>, <tt>libdl</tt> (on Linux),\n<tt>libgcc</tt> (if compiled with GCC), as well as any exported\nsymbols from the Lua/C&nbsp;API provided by LuaJIT itself.\n</p>\n<p>\nOn Windows systems, this binds to symbols exported from the\n<tt>*.exe</tt>, the <tt>lua51.dll</tt> (i.e. the Lua/C&nbsp;API\nprovided by LuaJIT itself), the C&nbsp;runtime library LuaJIT was linked\nwith (<tt>msvcrt*.dll</tt>), <tt>kernel32.dll</tt>,\n<tt>user32.dll</tt> and <tt>gdi32.dll</tt>.\n</p>\n\n<h3 id=\"ffi_load\"><tt>clib = ffi.load(name [,global])</tt></h3>\n<p>\nThis loads the dynamic library given by <tt>name</tt> and returns\na new C&nbsp;library namespace which binds to its symbols. On POSIX\nsystems, if <tt>global</tt> is <tt>true</tt>, the library symbols are\nloaded into the global namespace, too.\n</p>\n<p>\nIf <tt>name</tt> is a path, the library is loaded from this path.\nOtherwise <tt>name</tt> is canonicalized in a system-dependent way and\nsearched in the default search path for dynamic libraries:\n</p>\n<p>\nOn POSIX systems, if the name contains no dot, the extension\n<tt>.so</tt> is appended. Also, the <tt>lib</tt> prefix is prepended\nif necessary. So <tt>ffi.load(\"z\")</tt> looks for <tt>\"libz.so\"</tt>\nin the default shared library search path.\n</p>\n<p>\nOn Windows systems, if the name contains no dot, the extension\n<tt>.dll</tt> is appended. So <tt>ffi.load(\"ws2_32\")</tt> looks for\n<tt>\"ws2_32.dll\"</tt> in the default DLL search path.\n</p>\n\n<h2 id=\"create\">Creating cdata Objects</h2>\n<p>\nThe following API functions create cdata objects (<tt>type()</tt>\nreturns <tt>\"cdata\"</tt>). All created cdata objects are\n<a href=\"ext_ffi_semantics.html#gc\">garbage collected</a>.\n</p>\n\n<h3 id=\"ffi_new\"><tt>cdata = ffi.new(ct [,nelem] [,init...])<br>\ncdata = <em>ctype</em>([nelem,] [init...])</tt></h3>\n<p>\nCreates a cdata object for the given <tt>ct</tt>. VLA/VLS types\nrequire the <tt>nelem</tt> argument. The second syntax uses a ctype as\na constructor and is otherwise fully equivalent.\n</p>\n<p>\nThe cdata object is initialized according to the\n<a href=\"ext_ffi_semantics.html#init\">rules for initializers</a>,\nusing the optional <tt>init</tt> arguments. Excess initializers cause\nan error.\n</p>\n<p>\nPerformance notice: if you want to create many objects of one kind,\nparse the cdecl only once and get its ctype with\n<tt>ffi.typeof()</tt>. Then use the ctype as a constructor repeatedly.\n</p>\n<p style=\"font-size: 8pt;\">\nPlease note that an anonymous <tt>struct</tt> declaration implicitly\ncreates a new and distinguished ctype every time you use it for\n<tt>ffi.new()</tt>. This is probably <b>not</b> what you want,\nespecially if you create more than one cdata object. Different anonymous\n<tt>structs</tt> are not considered assignment-compatible by the\nC&nbsp;standard, even though they may have the same fields! Also, they\nare considered different types by the JIT-compiler, which may cause an\nexcessive number of traces. It's strongly suggested to either declare\na named <tt>struct</tt> or <tt>typedef</tt> with <tt>ffi.cdef()</tt>\nor to create a single ctype object for an anonymous <tt>struct</tt>\nwith <tt>ffi.typeof()</tt>.\n</p>\n\n<h3 id=\"ffi_typeof\"><tt>ctype = ffi.typeof(ct)</tt></h3>\n<p>\nCreates a ctype object for the given <tt>ct</tt>.\n</p>\n<p>\nThis function is especially useful to parse a cdecl only once and then\nuse the resulting ctype object as a <a href=\"#ffi_new\">constructor</a>.\n</p>\n\n<h3 id=\"ffi_cast\"><tt>cdata = ffi.cast(ct, init)</tt></h3>\n<p>\nCreates a scalar cdata object for the given <tt>ct</tt>. The cdata\nobject is initialized with <tt>init</tt> using the \"cast\" variant of\nthe <a href=\"ext_ffi_semantics.html#convert\">C&nbsp;type conversion\nrules</a>.\n</p>\n<p>\nThis functions is mainly useful to override the pointer compatibility\nchecks or to convert pointers to addresses or vice versa.\n</p>\n\n<h3 id=\"ffi_metatype\"><tt>ctype = ffi.metatype(ct, metatable)</tt></h3>\n<p>\nCreates a ctype object for the given <tt>ct</tt> and associates it with\na metatable. Only <tt>struct</tt>/<tt>union</tt> types, complex numbers\nand vectors are allowed. Other types may be wrapped in a\n<tt>struct</tt>, if needed.\n</p>\n<p>\nThe association with a metatable is permanent and cannot be changed\nafterwards. Neither the contents of the <tt>metatable</tt> nor the\ncontents of an <tt>__index</tt> table (if any) may be modified\nafterwards. The associated metatable automatically applies to all uses\nof this type, no matter how the objects are created or where they\noriginate from. Note that pre-defined operations on types have\nprecedence (e.g. declared field names cannot be overridden).\n</p>\n<p>\nAll standard Lua metamethods are implemented. These are called directly,\nwithout shortcuts and on any mix of types. For binary operations, the\nleft operand is checked first for a valid ctype metamethod. The\n<tt>__gc</tt> metamethod only applies to <tt>struct</tt>/<tt>union</tt>\ntypes and performs an implicit <a href=\"#ffi_gc\"><tt>ffi.gc()</tt></a>\ncall during creation of an instance.\n</p>\n\n<h3 id=\"ffi_gc\"><tt>cdata = ffi.gc(cdata, finalizer)</tt></h3>\n<p>\nAssociates a finalizer with a pointer or aggregate cdata object. The\ncdata object is returned unchanged.\n</p>\n<p>\nThis function allows safe integration of unmanaged resources into the\nautomatic memory management of the LuaJIT garbage collector. Typical\nusage:\n</p>\n<pre class=\"code\">\nlocal p = ffi.gc(ffi.C.malloc(n), ffi.C.free)\n...\np = nil -- Last reference to p is gone.\n-- GC will eventually run finalizer: ffi.C.free(p)\n</pre>\n<p>\nA cdata finalizer works like the <tt>__gc</tt> metamethod for userdata\nobjects: when the last reference to a cdata object is gone, the\nassociated finalizer is called with the cdata object as an argument. The\nfinalizer can be a Lua function or a cdata function or cdata function\npointer. An existing finalizer can be removed by setting a <tt>nil</tt>\nfinalizer, e.g. right before explicitly deleting a resource:\n</p>\n<pre class=\"code\">\nffi.C.free(ffi.gc(p, nil)) -- Manually free the memory.\n</pre>\n\n<h2 id=\"info\">C&nbsp;Type Information</h2>\n<p>\nThe following API functions return information about C&nbsp;types.\nThey are most useful for inspecting cdata objects.\n</p>\n\n<h3 id=\"ffi_sizeof\"><tt>size = ffi.sizeof(ct [,nelem])</tt></h3>\n<p>\nReturns the size of <tt>ct</tt> in bytes. Returns <tt>nil</tt> if\nthe size is not known (e.g. for <tt>\"void\"</tt> or function types).\nRequires <tt>nelem</tt> for VLA/VLS types, except for cdata objects.\n</p>\n\n<h3 id=\"ffi_alignof\"><tt>align = ffi.alignof(ct)</tt></h3>\n<p>\nReturns the minimum required alignment for <tt>ct</tt> in bytes.\n</p>\n\n<h3 id=\"ffi_offsetof\"><tt>ofs [,bpos,bsize] = ffi.offsetof(ct, field)</tt></h3>\n<p>\nReturns the offset (in bytes) of <tt>field</tt> relative to the start\nof <tt>ct</tt>, which must be a <tt>struct</tt>. Additionally returns\nthe position and the field size (in bits) for bit fields.\n</p>\n\n<h3 id=\"ffi_istype\"><tt>status = ffi.istype(ct, obj)</tt></h3>\n<p>\nReturns <tt>true</tt> if <tt>obj</tt> has the C&nbsp;type given by\n<tt>ct</tt>. Returns <tt>false</tt> otherwise.\n</p>\n<p>\nC&nbsp;type qualifiers (<tt>const</tt> etc.) are ignored. Pointers are\nchecked with the standard pointer compatibility rules, but without any\nspecial treatment for <tt>void&nbsp;*</tt>. If <tt>ct</tt> specifies a\n<tt>struct</tt>/<tt>union</tt>, then a pointer to this type is accepted,\ntoo. Otherwise the types must match exactly.\n</p>\n<p>\nNote: this function accepts all kinds of Lua objects for the\n<tt>obj</tt> argument, but always returns <tt>false</tt> for non-cdata\nobjects.\n</p>\n\n<h2 id=\"util\">Utility Functions</h2>\n\n<h3 id=\"ffi_errno\"><tt>err = ffi.errno([newerr])</tt></h3>\n<p>\nReturns the error number set by the last C&nbsp;function call which\nindicated an error condition. If the optional <tt>newerr</tt> argument\nis present, the error number is set to the new value and the previous\nvalue is returned.\n</p>\n<p>\nThis function offers a portable and OS-independent way to get and set the\nerror number. Note that only <em>some</em> C&nbsp;functions set the error\nnumber. And it's only significant if the function actually indicated an\nerror condition (e.g. with a return value of <tt>-1</tt> or\n<tt>NULL</tt>). Otherwise, it may or may not contain any previously set\nvalue.\n</p>\n<p>\nYou're advised to call this function only when needed and as close as\npossible after the return of the related C&nbsp;function. The\n<tt>errno</tt> value is preserved across hooks, memory allocations,\ninvocations of the JIT compiler and other internal VM activity. The same\napplies to the value returned by <tt>GetLastError()</tt> on Windows, but\nyou need to declare and call it yourself.\n</p>\n\n<h3 id=\"ffi_string\"><tt>str = ffi.string(ptr [,len])</tt></h3>\n<p>\nCreates an interned Lua string from the data pointed to by\n<tt>ptr</tt>.\n</p>\n<p>\nIf the optional argument <tt>len</tt> is missing, <tt>ptr</tt> is\nconverted to a <tt>\"char&nbsp;*\"</tt> and the data is assumed to be\nzero-terminated. The length of the string is computed with\n<tt>strlen()</tt>.\n</p>\n<p>\nOtherwise <tt>ptr</tt> is converted to a <tt>\"void&nbsp;*\"</tt> and\n<tt>len</tt> gives the length of the data. The data may contain\nembedded zeros and need not be byte-oriented (though this may cause\nendianess issues).\n</p>\n<p>\nThis function is mainly useful to convert (temporary)\n<tt>\"const&nbsp;char&nbsp;*\"</tt> pointers returned by\nC&nbsp;functions to Lua strings and store them or pass them to other\nfunctions expecting a Lua string. The Lua string is an (interned) copy\nof the data and bears no relation to the original data area anymore.\nLua strings are 8&nbsp;bit clean and may be used to hold arbitrary,\nnon-character data.\n</p>\n<p>\nPerformance notice: it's faster to pass the length of the string, if\nit's known. E.g. when the length is returned by a C&nbsp;call like\n<tt>sprintf()</tt>.\n</p>\n\n<h3 id=\"ffi_copy\"><tt>ffi.copy(dst, src, len)<br>\nffi.copy(dst, str)</tt></h3>\n<p>\nCopies the data pointed to by <tt>src</tt> to <tt>dst</tt>.\n<tt>dst</tt> is converted to a <tt>\"void&nbsp;*\"</tt> and <tt>src</tt>\nis converted to a <tt>\"const void&nbsp;*\"</tt>.\n</p>\n<p>\nIn the first syntax, <tt>len</tt> gives the number of bytes to copy.\nCaveat: if <tt>src</tt> is a Lua string, then <tt>len</tt> must not\nexceed <tt>#src+1</tt>.\n</p>\n<p>\nIn the second syntax, the source of the copy must be a Lua string. All\nbytes of the string <em>plus a zero-terminator</em> are copied to\n<tt>dst</tt> (i.e. <tt>#src+1</tt> bytes).\n</p>\n<p>\nPerformance notice: <tt>ffi.copy()</tt> may be used as a faster\n(inlinable) replacement for the C&nbsp;library functions\n<tt>memcpy()</tt>, <tt>strcpy()</tt> and <tt>strncpy()</tt>.\n</p>\n\n<h3 id=\"ffi_fill\"><tt>ffi.fill(dst, len [,c])</tt></h3>\n<p>\nFills the data pointed to by <tt>dst</tt> with <tt>len</tt> constant\nbytes, given by <tt>c</tt>. If <tt>c</tt> is omitted, the data is\nzero-filled.\n</p>\n<p>\nPerformance notice: <tt>ffi.fill()</tt> may be used as a faster\n(inlinable) replacement for the C&nbsp;library function\n<tt>memset(dst,&nbsp;c,&nbsp;len)</tt>. Please note the different\norder of arguments!\n</p>\n\n<h2 id=\"target\">Target-specific Information</h2>\n\n<h3 id=\"ffi_abi\"><tt>status = ffi.abi(param)</tt></h3>\n<p>\nReturns <tt>true</tt> if <tt>param</tt> (a Lua string) applies for the\ntarget ABI (Application Binary Interface). Returns <tt>false</tt>\notherwise. The following parameters are currently defined:\n</p>\n<table class=\"abitable\">\n<tr class=\"abihead\">\n<td class=\"abiparam\">Parameter</td>\n<td class=\"abidesc\">Description</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">32bit</td><td class=\"abidesc\">32 bit architecture</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">64bit</td><td class=\"abidesc\">64 bit architecture</td></tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">le</td><td class=\"abidesc\">Little-endian architecture</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">be</td><td class=\"abidesc\">Big-endian architecture</td></tr>\n<tr class=\"odd separate\">\n<td class=\"abiparam\">fpu</td><td class=\"abidesc\">Target has a hardware FPU</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">softfp</td><td class=\"abidesc\">softfp calling conventions</td></tr>\n<tr class=\"odd\">\n<td class=\"abiparam\">hardfp</td><td class=\"abidesc\">hardfp calling conventions</td></tr>\n<tr class=\"even separate\">\n<td class=\"abiparam\">eabi</td><td class=\"abidesc\">EABI variant of the standard ABI</td></tr>\n<tr class=\"odd\">\n<td class=\"abiparam\">win</td><td class=\"abidesc\">Windows variant of the standard ABI</td></tr>\n<tr class=\"even\">\n<td class=\"abiparam\">uwp</td><td class=\"abidesc\">Universal Windows Platform</td></tr>\n<tr class=\"odd\">\n<td class=\"abiparam\">gc64</td><td class=\"abidesc\">64 bit GC references</td></tr>\n</table>\n\n<h3 id=\"ffi_os\"><tt>ffi.os</tt></h3>\n<p>\nContains the target OS name. Same contents as\n<a href=\"ext_jit.html#jit_os\"><tt>jit.os</tt></a>.\n</p>\n\n<h3 id=\"ffi_arch\"><tt>ffi.arch</tt></h3>\n<p>\nContains the target architecture name. Same contents as\n<a href=\"ext_jit.html#jit_arch\"><tt>jit.arch</tt></a>.\n</p>\n\n<h2 id=\"callback\">Methods for Callbacks</h2>\n<p>\nThe C&nbsp;types for <a href=\"ext_ffi_semantics.html#callback\">callbacks</a>\nhave some extra methods:\n</p>\n\n<h3 id=\"callback_free\"><tt>cb:free()</tt></h3>\n<p>\nFree the resources associated with a callback. The associated Lua\nfunction is unanchored and may be garbage collected. The callback\nfunction pointer is no longer valid and must not be called anymore\n(it may be reused by a subsequently created callback).\n</p>\n\n<h3 id=\"callback_set\"><tt>cb:set(func)</tt></h3>\n<p>\nAssociate a new Lua function with a callback. The C&nbsp;type of the\ncallback and the callback function pointer are unchanged.\n</p>\n<p>\nThis method is useful to dynamically switch the receiver of callbacks\nwithout creating a new callback each time and registering it again (e.g.\nwith a GUI library).\n</p>\n\n<h2 id=\"extended\">Extended Standard Library Functions</h2>\n<p>\nThe following standard library functions have been extended to work\nwith cdata objects:\n</p>\n\n<h3 id=\"tonumber\"><tt>n = tonumber(cdata)</tt></h3>\n<p>\nConverts a number cdata object to a <tt>double</tt> and returns it as\na Lua number. This is particularly useful for boxed 64&nbsp;bit\ninteger values. Caveat: this conversion may incur a precision loss.\n</p>\n\n<h3 id=\"tostring\"><tt>s = tostring(cdata)</tt></h3>\n<p>\nReturns a string representation of the value of 64&nbsp;bit integers\n(<tt><b>\"</b>nnn<b>LL\"</b></tt> or <tt><b>\"</b>nnn<b>ULL\"</b></tt>) or\ncomplex numbers (<tt><b>\"</b>re&plusmn;im<b>i\"</b></tt>). Otherwise\nreturns a string representation of the C&nbsp;type of a ctype object\n(<tt><b>\"ctype&lt;</b>type<b>&gt;\"</b></tt>) or a cdata object\n(<tt><b>\"cdata&lt;</b>type<b>&gt;:&nbsp;</b>address\"</tt>), unless you\noverride it with a <tt>__tostring</tt> metamethod (see\n<a href=\"#ffi_metatype\"><tt>ffi.metatype()</tt></a>).\n</p>\n\n<h3 id=\"pairs\"><tt>iter, obj, start = pairs(cdata)<br>\niter, obj, start = ipairs(cdata)<br></tt></h3>\n<p>\nCalls the <tt>__pairs</tt> or <tt>__ipairs</tt> metamethod of the\ncorresponding ctype.\n</p>\n\n<h2 id=\"literals\">Extensions to the Lua Parser</h2>\n<p>\nThe parser for Lua source code treats numeric literals with the\nsuffixes <tt>LL</tt> or <tt>ULL</tt> as signed or unsigned 64&nbsp;bit\nintegers. Case doesn't matter, but uppercase is recommended for\nreadability. It handles decimal (<tt>42LL</tt>), hexadecimal\n(<tt>0x2aLL</tt>) and binary (<tt>0b101010LL</tt>) literals.\n</p>\n<p>\nThe imaginary part of complex numbers can be specified by suffixing\nnumber literals with <tt>i</tt> or <tt>I</tt>, e.g. <tt>12.5i</tt>.\nCaveat: you'll need to use <tt>1i</tt> to get an imaginary part with\nthe value one, since <tt>i</tt> itself still refers to a variable\nnamed <tt>i</tt>.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_ffi_semantics.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>FFI Semantics</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.convtable { line-height: 1.2; }\ntr.convhead td { font-weight: bold; }\ntd.convop { font-style: italic; width: 40%; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Semantics</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a class=\"current\" href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page describes the detailed semantics underlying the FFI library\nand its interaction with both Lua and C&nbsp;code.\n</p>\n<p>\nGiven that the FFI library is designed to interface with C&nbsp;code\nand that declarations can be written in plain C&nbsp;syntax, <b>it\nclosely follows the C&nbsp;language semantics</b>, wherever possible.\nSome minor concessions are needed for smoother interoperation with Lua\nlanguage semantics.\n</p>\n<p>\nPlease don't be overwhelmed by the contents of this page &mdash; this\nis a reference and you may need to consult it, if in doubt. It doesn't\nhurt to skim this page, but most of the semantics \"just work\" as you'd\nexpect them to work. It should be straightforward to write\napplications using the LuaJIT FFI for developers with a C or C++\nbackground.\n</p>\n\n<h2 id=\"clang\">C Language Support</h2>\n<p>\nThe FFI library has a built-in C&nbsp;parser with a minimal memory\nfootprint. It's used by the <a href=\"ext_ffi_api.html\">ffi.* library\nfunctions</a> to declare C&nbsp;types or external symbols.\n</p>\n<p>\nIt's only purpose is to parse C&nbsp;declarations, as found e.g. in\nC&nbsp;header files. Although it does evaluate constant expressions,\nit's <em>not</em> a C&nbsp;compiler. The body of <tt>inline</tt>\nC&nbsp;function definitions is simply ignored.\n</p>\n<p>\nAlso, this is <em>not</em> a validating C&nbsp;parser. It expects and\naccepts correctly formed C&nbsp;declarations, but it may choose to\nignore bad declarations or show rather generic error messages. If in\ndoubt, please check the input against your favorite C&nbsp;compiler.\n</p>\n<p>\nThe C&nbsp;parser complies to the <b>C99 language standard</b> plus\nthe following extensions:\n</p>\n<ul>\n\n<li>The <tt>'\\e'</tt> escape in character and string literals.</li>\n\n<li>The C99/C++ boolean type, declared with the keywords <tt>bool</tt>\nor <tt>_Bool</tt>.</li>\n\n<li>Complex numbers, declared with the keywords <tt>complex</tt> or\n<tt>_Complex</tt>.</li>\n\n<li>Two complex number types: <tt>complex</tt> (aka\n<tt>complex&nbsp;double</tt>) and <tt>complex&nbsp;float</tt>.</li>\n\n<li>Vector types, declared with the GCC <tt>mode</tt> or\n<tt>vector_size</tt> attribute.</li>\n\n<li>Unnamed ('transparent') <tt>struct</tt>/<tt>union</tt> fields\ninside a <tt>struct</tt>/<tt>union</tt>.</li>\n\n<li>Incomplete <tt>enum</tt> declarations, handled like incomplete\n<tt>struct</tt> declarations.</li>\n\n<li>Unnamed <tt>enum</tt> fields inside a\n<tt>struct</tt>/<tt>union</tt>. This is similar to a scoped C++\n<tt>enum</tt>, except that declared constants are visible in the\nglobal namespace, too.</li>\n\n<li>Scoped <tt>static&nbsp;const</tt> declarations inside a\n<tt>struct</tt>/<tt>union</tt> (from C++).</li>\n\n<li>Zero-length arrays (<tt>[0]</tt>), empty\n<tt>struct</tt>/<tt>union</tt>, variable-length arrays (VLA,\n<tt>[?]</tt>) and variable-length structs (VLS, with a trailing\nVLA).</li>\n\n<li>C++ reference types (<tt>int&nbsp;&amp;x</tt>).</li>\n\n<li>Alternate GCC keywords with '<tt>__</tt>', e.g.\n<tt>__const__</tt>.</li>\n\n<li>GCC <tt>__attribute__</tt> with the following attributes:\n<tt>aligned</tt>, <tt>packed</tt>, <tt>mode</tt>,\n<tt>vector_size</tt>, <tt>cdecl</tt>, <tt>fastcall</tt>,\n<tt>stdcall</tt>, <tt>thiscall</tt>.</li>\n\n<li>The GCC <tt>__extension__</tt> keyword and the GCC\n<tt>__alignof__</tt> operator.</li>\n\n<li>GCC <tt>__asm__(\"symname\")</tt> symbol name redirection for\nfunction declarations.</li>\n\n<li>MSVC keywords for fixed-length types: <tt>__int8</tt>,\n<tt>__int16</tt>, <tt>__int32</tt> and <tt>__int64</tt>.</li>\n\n<li>MSVC <tt>__cdecl</tt>, <tt>__fastcall</tt>, <tt>__stdcall</tt>,\n<tt>__thiscall</tt>, <tt>__ptr32</tt>, <tt>__ptr64</tt>,\n<tt>__declspec(align(n))</tt> and <tt>#pragma&nbsp;pack</tt>.</li>\n\n<li>All other GCC/MSVC-specific attributes are ignored.</li>\n\n</ul>\n<p>\nThe following C&nbsp;types are pre-defined by the C&nbsp;parser (like\na <tt>typedef</tt>, except re-declarations will be ignored):\n</p>\n<ul>\n\n<li>Vararg handling: <tt>va_list</tt>, <tt>__builtin_va_list</tt>,\n<tt>__gnuc_va_list</tt>.</li>\n\n<li>From <tt>&lt;stddef.h&gt;</tt>: <tt>ptrdiff_t</tt>,\n<tt>size_t</tt>, <tt>wchar_t</tt>.</li>\n\n<li>From <tt>&lt;stdint.h&gt;</tt>: <tt>int8_t</tt>, <tt>int16_t</tt>,\n<tt>int32_t</tt>, <tt>int64_t</tt>, <tt>uint8_t</tt>,\n<tt>uint16_t</tt>, <tt>uint32_t</tt>, <tt>uint64_t</tt>,\n<tt>intptr_t</tt>, <tt>uintptr_t</tt>.</li>\n\n<li>From <tt>&lt;unistd.h&gt;</tt> (POSIX): <tt>ssize_t</tt>.</li>\n\n</ul>\n<p>\nYou're encouraged to use these types in preference to\ncompiler-specific extensions or target-dependent standard types.\nE.g. <tt>char</tt> differs in signedness and <tt>long</tt> differs in\nsize, depending on the target architecture and platform ABI.\n</p>\n<p>\nThe following C&nbsp;features are <b>not</b> supported:\n</p>\n<ul>\n\n<li>A declaration must always have a type specifier; it doesn't\ndefault to an <tt>int</tt> type.</li>\n\n<li>Old-style empty function declarations (K&amp;R) are not allowed.\nAll C&nbsp;functions must have a proper prototype declaration. A\nfunction declared without parameters (<tt>int&nbsp;foo();</tt>) is\ntreated as a function taking zero arguments, like in C++.</li>\n\n<li>The <tt>long double</tt> C&nbsp;type is parsed correctly, but\nthere's no support for the related conversions, accesses or arithmetic\noperations.</li>\n\n<li>Wide character strings and character literals are not\nsupported.</li>\n\n<li><a href=\"#status\">See below</a> for features that are currently\nnot implemented.</li>\n\n</ul>\n\n<h2 id=\"convert\">C Type Conversion Rules</h2>\n\n<h3 id=\"convert_tolua\">Conversions from C&nbsp;types to Lua objects</h3>\n<p>\nThese conversion rules apply for <em>read accesses</em> to\nC&nbsp;types: indexing pointers, arrays or\n<tt>struct</tt>/<tt>union</tt> types; reading external variables or\nconstant values; retrieving return values from C&nbsp;calls:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>int8_t</tt>, <tt>int16_t</tt></td><td class=\"convop\">&rarr;<sup>sign-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>uint8_t</tt>, <tt>uint16_t</tt></td><td class=\"convop\">&rarr;<sup>zero-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>int32_t</tt>, <tt>uint32_t</tt></td><td class=\"convop\">&rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>int64_t</tt>, <tt>uint64_t</tt></td><td class=\"convop\">boxed value</td><td class=\"convout\">64 bit int cdata</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr; <tt>double</tt></td><td class=\"convout\">number</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\"><tt>bool</tt></td><td class=\"convop\">0 &rarr; <tt>false</tt>, otherwise <tt>true</tt></td><td class=\"convout\">boolean</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>enum</tt></td><td class=\"convop\">boxed value</td><td class=\"convout\">enum cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">boxed value</td><td class=\"convout\">complex cdata</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Vector</td><td class=\"convop\">boxed value</td><td class=\"convout\">vector cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">boxed value</td><td class=\"convout\">pointer cdata</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Array</td><td class=\"convop\">boxed reference</td><td class=\"convout\">reference cdata</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">boxed reference</td><td class=\"convout\">reference cdata</td></tr>\n</table>\n<p>\nBitfields are treated like their underlying type.\n</p>\n<p>\nReference types are dereferenced <em>before</em> a conversion can take\nplace &mdash; the conversion is applied to the C&nbsp;type pointed to\nby the reference.\n</p>\n\n<h3 id=\"convert_fromlua\">Conversions from Lua objects to C&nbsp;types</h3>\n<p>\nThese conversion rules apply for <em>write accesses</em> to\nC&nbsp;types: indexing pointers, arrays or\n<tt>struct</tt>/<tt>union</tt> types; initializing cdata objects;\ncasts to C&nbsp;types; writing to external variables; passing\narguments to C&nbsp;calls:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">number</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">boolean</td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">nil</td><td class=\"convop\"><tt>NULL</tt> &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">lightuserdata</td><td class=\"convop\">lightuserdata address &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">userdata</td><td class=\"convop\">userdata payload &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">io.* file</td><td class=\"convop\">get FILE * handle &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">string</td><td class=\"convop\">match against <tt>enum</tt> constant</td><td class=\"convout\"><tt>enum</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">string</td><td class=\"convop\">copy string data + zero-byte</td><td class=\"convout\"><tt>int8_t[]</tt>, <tt>uint8_t[]</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">string</td><td class=\"convop\">string data &rarr;</td><td class=\"convout\"><tt>const char[]</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">function</td><td class=\"convop\"><a href=\"#callback\">create callback</a> &rarr;</td><td class=\"convout\">C function type</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">table</td><td class=\"convop\"><a href=\"#init_table\">table initializer</a></td><td class=\"convout\">Array</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">table</td><td class=\"convop\"><a href=\"#init_table\">table initializer</a></td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">cdata</td><td class=\"convop\">cdata payload &rarr;</td><td class=\"convout\">C type</td></tr>\n</table>\n<p>\nIf the result type of this conversion doesn't match the\nC&nbsp;type of the destination, the\n<a href=\"#convert_between\">conversion rules between C&nbsp;types</a>\nare applied.\n</p>\n<p>\nReference types are immutable after initialization (\"no re-seating of\nreferences\"). For initialization purposes or when passing values to\nreference parameters, they are treated like pointers. Note that unlike\nin C++, there's no way to implement automatic reference generation of\nvariables under the Lua language semantics. If you want to call a\nfunction with a reference parameter, you need to explicitly pass a\none-element array.\n</p>\n\n<h3 id=\"convert_between\">Conversions between C&nbsp;types</h3>\n<p>\nThese conversion rules are more or less the same as the standard\nC&nbsp;conversion rules. Some rules only apply to casts, or require\npointer or type compatibility:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Signed integer</td><td class=\"convop\">&rarr;<sup>narrow or sign-extend</sup></td><td class=\"convout\">Integer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Unsigned integer</td><td class=\"convop\">&rarr;<sup>narrow or zero-extend</sup></td><td class=\"convout\">Integer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Integer</td><td class=\"convop\">&rarr;<sup>round</sup></td><td class=\"convout\"><tt>double</tt>, <tt>float</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>trunc</sup> <tt>int32_t</tt> &rarr;<sup>narrow</sup></td><td class=\"convout\"><tt>(u)int8_t</tt>, <tt>(u)int16_t</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>trunc</sup></td><td class=\"convout\"><tt>(u)int32_t</tt>, <tt>(u)int64_t</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>double</tt>, <tt>float</tt></td><td class=\"convop\">&rarr;<sup>round</sup></td><td class=\"convout\"><tt>float</tt>, <tt>double</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">n == 0 &rarr; 0, otherwise 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>bool</tt></td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\">Number</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">convert real part</td><td class=\"convout\">Number</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert real part, imag = 0</td><td class=\"convout\">Complex number</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Complex number</td><td class=\"convop\">convert real and imag part</td><td class=\"convout\">Complex number</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert scalar and replicate</td><td class=\"convout\">Vector</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Vector</td><td class=\"convop\">copy (same size)</td><td class=\"convout\">Vector</td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">take base address (compat)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Array</td><td class=\"convop\">take base address (compat)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Function</td><td class=\"convop\">take function address</td><td class=\"convout\">Function pointer</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Number</td><td class=\"convop\">convert via <tt>uintptr_t</tt> (cast)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">convert address (compat/cast)</td><td class=\"convout\">Pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Pointer</td><td class=\"convop\">convert address (cast)</td><td class=\"convout\">Integer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Array</td><td class=\"convop\">convert base address (cast)</td><td class=\"convout\">Integer</td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">Array</td><td class=\"convop\">copy (compat)</td><td class=\"convout\">Array</td></tr>\n<tr class=\"even\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt></td><td class=\"convop\">copy (identical type)</td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt></td></tr>\n</table>\n<p>\nBitfields or <tt>enum</tt> types are treated like their underlying\ntype.\n</p>\n<p>\nConversions not listed above will raise an error. E.g. it's not\npossible to convert a pointer to a complex number or vice versa.\n</p>\n\n<h3 id=\"convert_vararg\">Conversions for vararg C&nbsp;function arguments</h3>\n<p>\nThe following default conversion rules apply when passing Lua objects\nto the variable argument part of vararg C&nbsp;functions:\n</p>\n<table class=\"convtable\">\n<tr class=\"convhead\">\n<td class=\"convin\">Input</td>\n<td class=\"convop\">Conversion</td>\n<td class=\"convout\">Output</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">number</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">boolean</td><td class=\"convop\"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class=\"convout\"><tt>bool</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\">nil</td><td class=\"convop\"><tt>NULL</tt> &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">userdata</td><td class=\"convop\">userdata payload &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">lightuserdata</td><td class=\"convop\">lightuserdata address &rarr;</td><td class=\"convout\"><tt>(void *)</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"convin\">string</td><td class=\"convop\">string data &rarr;</td><td class=\"convout\"><tt>const char *</tt></td></tr>\n<tr class=\"odd separate\">\n<td class=\"convin\"><tt>float</tt> cdata</td><td class=\"convop\">&rarr;</td><td class=\"convout\"><tt>double</tt></td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Array cdata</td><td class=\"convop\">take base address</td><td class=\"convout\">Element pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\"><tt>struct</tt>/<tt>union</tt> cdata</td><td class=\"convop\">take base address</td><td class=\"convout\"><tt>struct</tt>/<tt>union</tt> pointer</td></tr>\n<tr class=\"even\">\n<td class=\"convin\">Function cdata</td><td class=\"convop\">take function address</td><td class=\"convout\">Function pointer</td></tr>\n<tr class=\"odd\">\n<td class=\"convin\">Any other cdata</td><td class=\"convop\">no conversion</td><td class=\"convout\">C type</td></tr>\n</table>\n<p>\nTo pass a Lua object, other than a cdata object, as a specific type,\nyou need to override the conversion rules: create a temporary cdata\nobject with a constructor or a cast and initialize it with the value\nto pass:\n</p>\n<p>\nAssuming <tt>x</tt> is a Lua number, here's how to pass it as an\ninteger to a vararg function:\n</p>\n<pre class=\"code\">\nffi.cdef[[\nint printf(const char *fmt, ...);\n]]\nffi.C.printf(\"integer value: %d\\n\", ffi.new(\"int\", x))\n</pre>\n<p>\nIf you don't do this, the default Lua number &rarr; <tt>double</tt>\nconversion rule applies. A vararg C&nbsp;function expecting an integer\nwill see a garbled or uninitialized value.\n</p>\n\n<h2 id=\"init\">Initializers</h2>\n<p>\nCreating a cdata object with\n<a href=\"ext_ffi_api.html#ffi_new\"><tt>ffi.new()</tt></a> or the\nequivalent constructor syntax always initializes its contents, too.\nDifferent rules apply, depending on the number of optional\ninitializers and the C&nbsp;types involved:\n</p>\n<ul>\n<li>If no initializers are given, the object is filled with zero bytes.</li>\n\n<li>Scalar types (numbers and pointers) accept a single initializer.\nThe Lua object is <a href=\"#convert_fromlua\">converted to the scalar\nC&nbsp;type</a>.</li>\n\n<li>Valarrays (complex numbers and vectors) are treated like scalars\nwhen a single initializer is given. Otherwise they are treated like\nregular arrays.</li>\n\n<li>Aggregate types (arrays and structs) accept either a single cdata\ninitializer of the same type (copy constructor), a single\n<a href=\"#init_table\">table initializer</a>, or a flat list of\ninitializers.</li>\n\n<li>The elements of an array are initialized, starting at index zero.\nIf a single initializer is given for an array, it's repeated for all\nremaining elements. This doesn't happen if two or more initializers\nare given: all remaining uninitialized elements are filled with zero\nbytes.</li>\n\n<li>Byte arrays may also be initialized with a Lua string. This copies\nthe whole string plus a terminating zero-byte. The copy stops early only\nif the array has a known, fixed size.</li>\n\n<li>The fields of a <tt>struct</tt> are initialized in the order of\ntheir declaration. Uninitialized fields are filled with zero\nbytes.</li>\n\n<li>Only the first field of a <tt>union</tt> can be initialized with a\nflat initializer.</li>\n\n<li>Elements or fields which are aggregates themselves are initialized\nwith a <em>single</em> initializer, but this may be a table\ninitializer or a compatible aggregate.</li>\n\n<li>Excess initializers cause an error.</li>\n\n</ul>\n\n<h2 id=\"init_table\">Table Initializers</h2>\n<p>\nThe following rules apply if a Lua table is used to initialize an\nArray or a <tt>struct</tt>/<tt>union</tt>:\n</p>\n<ul>\n\n<li>If the table index <tt>[0]</tt> is non-<tt>nil</tt>, then the\ntable is assumed to be zero-based. Otherwise it's assumed to be\none-based.</li>\n\n<li>Array elements, starting at index zero, are initialized one-by-one\nwith the consecutive table elements, starting at either index\n<tt>[0]</tt> or <tt>[1]</tt>. This process stops at the first\n<tt>nil</tt> table element.</li>\n\n<li>If exactly one array element was initialized, it's repeated for\nall the remaining elements. Otherwise all remaining uninitialized\nelements are filled with zero bytes.</li>\n\n<li>The above logic only applies to arrays with a known fixed size.\nA VLA is only initialized with the element(s) given in the table.\nDepending on the use case, you may need to explicitly add a\n<tt>NULL</tt> or <tt>0</tt> terminator to a VLA.</li>\n\n<li>A <tt>struct</tt>/<tt>union</tt> can be initialized in the\norder of the declaration of its fields. Each field is initialized with\nconsecutive table elements, starting at either index <tt>[0]</tt>\nor <tt>[1]</tt>. This process stops at the first <tt>nil</tt> table\nelement.</li>\n\n<li>Otherwise, if neither index <tt>[0]</tt> nor <tt>[1]</tt> is present,\na <tt>struct</tt>/<tt>union</tt> is initialized by looking up each field\nname (as a string key) in the table. Each non-<tt>nil</tt> value is\nused to initialize the corresponding field.</li>\n\n<li>Uninitialized fields of a <tt>struct</tt> are filled with zero\nbytes, except for the trailing VLA of a VLS.</li>\n\n<li>Initialization of a <tt>union</tt> stops after one field has been\ninitialized. If no field has been initialized, the <tt>union</tt> is\nfilled with zero bytes.</li>\n\n<li>Elements or fields which are aggregates themselves are initialized\nwith a <em>single</em> initializer, but this may be a nested table\ninitializer (or a compatible aggregate).</li>\n\n<li>Excess initializers for an array cause an error. Excess\ninitializers for a <tt>struct</tt>/<tt>union</tt> are ignored.\nUnrelated table entries are ignored, too.</li>\n\n</ul>\n<p>\nExample:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\n\nffi.cdef[[\nstruct foo { int a, b; };\nunion bar { int i; double d; };\nstruct nested { int x; struct foo y; };\n]]\n\nffi.new(\"int[3]\", {})            --> 0, 0, 0\nffi.new(\"int[3]\", {1})           --> 1, 1, 1\nffi.new(\"int[3]\", {1,2})         --> 1, 2, 0\nffi.new(\"int[3]\", {1,2,3})       --> 1, 2, 3\nffi.new(\"int[3]\", {[0]=1})       --> 1, 1, 1\nffi.new(\"int[3]\", {[0]=1,2})     --> 1, 2, 0\nffi.new(\"int[3]\", {[0]=1,2,3})   --> 1, 2, 3\nffi.new(\"int[3]\", {[0]=1,2,3,4}) --> error: too many initializers\n\nffi.new(\"struct foo\", {})            --> a = 0, b = 0\nffi.new(\"struct foo\", {1})           --> a = 1, b = 0\nffi.new(\"struct foo\", {1,2})         --> a = 1, b = 2\nffi.new(\"struct foo\", {[0]=1,2})     --> a = 1, b = 2\nffi.new(\"struct foo\", {b=2})         --> a = 0, b = 2\nffi.new(\"struct foo\", {a=1,b=2,c=3}) --> a = 1, b = 2  'c' is ignored\n\nffi.new(\"union bar\", {})        --> i = 0, d = 0.0\nffi.new(\"union bar\", {1})       --> i = 1, d = ?\nffi.new(\"union bar\", {[0]=1,2}) --> i = 1, d = ?    '2' is ignored\nffi.new(\"union bar\", {d=2})     --> i = ?, d = 2.0\n\nffi.new(\"struct nested\", {1,{2,3}})     --> x = 1, y.a = 2, y.b = 3\nffi.new(\"struct nested\", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3\n</pre>\n\n<h2 id=\"cdata_ops\">Operations on cdata Objects</h2>\n<p>\nAll of the standard Lua operators can be applied to cdata objects or a\nmix of a cdata object and another Lua object. The following list shows\nthe pre-defined operations.\n</p>\n<p>\nReference types are dereferenced <em>before</em> performing each of\nthe operations below &mdash; the operation is applied to the\nC&nbsp;type pointed to by the reference.\n</p>\n<p>\nThe pre-defined operations are always tried first before deferring to a\nmetamethod or index table (if any) for the corresponding ctype (except\nfor <tt>__new</tt>). An error is raised if the metamethod lookup or\nindex table lookup fails.\n</p>\n\n<h3 id=\"cdata_array\">Indexing a cdata object</h3>\n<ul>\n\n<li><b>Indexing a pointer/array</b>: a cdata pointer/array can be\nindexed by a cdata number or a Lua number. The element address is\ncomputed as the base address plus the number value multiplied by the\nelement size in bytes. A read access loads the element value and\n<a href=\"#convert_tolua\">converts it to a Lua object</a>. A write\naccess <a href=\"#convert_fromlua\">converts a Lua object to the element\ntype</a> and stores the converted value to the element. An error is\nraised if the element size is undefined or a write access to a\nconstant element is attempted.</li>\n\n<li><b>Dereferencing a <tt>struct</tt>/<tt>union</tt> field</b>: a\ncdata <tt>struct</tt>/<tt>union</tt> or a pointer to a\n<tt>struct</tt>/<tt>union</tt> can be dereferenced by a string key,\ngiving the field name. The field address is computed as the base\naddress plus the relative offset of the field. A read access loads the\nfield value and <a href=\"#convert_tolua\">converts it to a Lua\nobject</a>. A write access <a href=\"#convert_fromlua\">converts a Lua\nobject to the field type</a> and stores the converted value to the\nfield. An error is raised if a write access to a constant\n<tt>struct</tt>/<tt>union</tt> or a constant field is attempted.\nScoped enum constants or static constants are treated like a constant\nfield.</li>\n\n<li><b>Indexing a complex number</b>: a complex number can be indexed\neither by a cdata number or a Lua number with the values 0 or 1, or by\nthe strings <tt>\"re\"</tt> or <tt>\"im\"</tt>. A read access loads the\nreal part (<tt>[0]</tt>, <tt>.re</tt>) or the imaginary part\n(<tt>[1]</tt>, <tt>.im</tt>) part of a complex number and\n<a href=\"#convert_tolua\">converts it to a Lua number</a>. The\nsub-parts of a complex number are immutable &mdash; assigning to an\nindex of a complex number raises an error. Accessing out-of-bound\nindexes returns unspecified results, but is guaranteed not to trigger\nmemory access violations.</li>\n\n<li><b>Indexing a vector</b>: a vector is treated like an array for\nindexing purposes, except the vector elements are immutable &mdash;\nassigning to an index of a vector raises an error.</li>\n\n</ul>\n<p>\nA ctype object can be indexed with a string key, too. The only\npre-defined operation is reading scoped constants of\n<tt>struct</tt>/<tt>union</tt> types. All other accesses defer\nto the corresponding metamethods or index tables (if any).\n</p>\n<p>\nNote: since there's (deliberately) no address-of operator, a cdata\nobject holding a value type is effectively immutable after\ninitialization. The JIT compiler benefits from this fact when applying\ncertain optimizations.\n</p>\n<p>\nAs a consequence, the <em>elements</em> of complex numbers and\nvectors are immutable. But the elements of an aggregate holding these\ntypes <em>may</em> be modified of course. I.e. you cannot assign to\n<tt>foo.c.im</tt>, but you can assign a (newly created) complex number\nto <tt>foo.c</tt>.\n</p>\n<p>\nThe JIT compiler implements strict aliasing rules: accesses to different\ntypes do <b>not</b> alias, except for differences in signedness (this\napplies even to <tt>char</tt> pointers, unlike C99). Type punning\nthrough unions is explicitly detected and allowed.\n</p>\n\n<h3 id=\"cdata_call\">Calling a cdata object</h3>\n<ul>\n\n<li><b>Constructor</b>: a ctype object can be called and used as a\n<a href=\"ext_ffi_api.html#ffi_new\">constructor</a>. This is equivalent\nto <tt>ffi.new(ct, ...)</tt>, unless a <tt>__new</tt> metamethod is\ndefined. The <tt>__new</tt> metamethod is called with the ctype object\nplus any other arguments passed to the constructor. Note that you have to\nuse <tt>ffi.new</tt> inside of it, since calling <tt>ct(...)</tt> would\ncause infinite recursion.</li>\n\n<li><b>C&nbsp;function call</b>: a cdata function or cdata function\npointer can be called. The passed arguments are\n<a href=\"#convert_fromlua\">converted to the C&nbsp;types</a> of the\nparameters given by the function declaration. Arguments passed to the\nvariable argument part of vararg C&nbsp;function use\n<a href=\"#convert_vararg\">special conversion rules</a>. This\nC&nbsp;function is called and the return value (if any) is\n<a href=\"#convert_tolua\">converted to a Lua object</a>.<br>\nOn Windows/x86 systems, <tt>__stdcall</tt> functions are automatically\ndetected and a function declared as <tt>__cdecl</tt> (the default) is\nsilently fixed up after the first call.</li>\n\n</ul>\n\n<h3 id=\"cdata_arith\">Arithmetic on cdata objects</h3>\n<ul>\n\n<li><b>Pointer arithmetic</b>: a cdata pointer/array and a cdata\nnumber or a Lua number can be added or subtracted. The number must be\non the right hand side for a subtraction. The result is a pointer of\nthe same type with an address plus or minus the number value\nmultiplied by the element size in bytes. An error is raised if the\nelement size is undefined.</li>\n\n<li><b>Pointer difference</b>: two compatible cdata pointers/arrays\ncan be subtracted. The result is the difference between their\naddresses, divided by the element size in bytes. An error is raised if\nthe element size is undefined or zero.</li>\n\n<li><b>64&nbsp;bit integer arithmetic</b>: the standard arithmetic\noperators (<tt>+&nbsp;-&nbsp;*&nbsp;/&nbsp;%&nbsp;^</tt> and unary\nminus) can be applied to two cdata numbers, or a cdata number and a\nLua number. If one of them is an <tt>uint64_t</tt>, the other side is\nconverted to an <tt>uint64_t</tt> and an unsigned arithmetic operation\nis performed. Otherwise both sides are converted to an\n<tt>int64_t</tt> and a signed arithmetic operation is performed. The\nresult is a boxed 64&nbsp;bit cdata object.<br>\n\nIf one of the operands is an <tt>enum</tt> and the other operand is a\nstring, the string is converted to the value of a matching <tt>enum</tt>\nconstant before the above conversion.<br>\n\nThese rules ensure that 64&nbsp;bit integers are \"sticky\". Any\nexpression involving at least one 64&nbsp;bit integer operand results\nin another one. The undefined cases for the division, modulo and power\noperators return <tt>2LL&nbsp;^&nbsp;63</tt> or\n<tt>2ULL&nbsp;^&nbsp;63</tt>.<br>\n\nYou'll have to explicitly convert a 64&nbsp;bit integer to a Lua\nnumber (e.g. for regular floating-point calculations) with\n<tt>tonumber()</tt>. But note this may incur a precision loss.</li>\n\n<li><b>64&nbsp;bit bitwise operations</b>: the rules for 64&nbsp;bit\narithmetic operators apply analogously.<br>\n\nUnlike the other <tt>bit.*</tt> operations, <tt>bit.tobit()</tt>\nconverts a cdata number via <tt>int64_t</tt> to <tt>int32_t</tt> and\nreturns a Lua number.<br>\n\nFor <tt>bit.band()</tt>, <tt>bit.bor()</tt> and <tt>bit.bxor()</tt>, the\nconversion to <tt>int64_t</tt> or <tt>uint64_t</tt> applies to\n<em>all</em> arguments, if <em>any</em> argument is a cdata number.<br>\n\nFor all other operations, only the first argument is used to determine\nthe output type. This implies that a cdata number as a shift count for\nshifts and rotates is accepted, but that alone does <em>not</em> cause\na cdata number output.\n\n</ul>\n\n<h3 id=\"cdata_comp\">Comparisons of cdata objects</h3>\n<ul>\n\n<li><b>Pointer comparison</b>: two compatible cdata pointers/arrays\ncan be compared. The result is the same as an unsigned comparison of\ntheir addresses. <tt>nil</tt> is treated like a <tt>NULL</tt> pointer,\nwhich is compatible with any other pointer type.</li>\n\n<li><b>64&nbsp;bit integer comparison</b>: two cdata numbers, or a\ncdata number and a Lua number can be compared with each other. If one\nof them is an <tt>uint64_t</tt>, the other side is converted to an\n<tt>uint64_t</tt> and an unsigned comparison is performed. Otherwise\nboth sides are converted to an <tt>int64_t</tt> and a signed\ncomparison is performed.<br>\n\nIf one of the operands is an <tt>enum</tt> and the other operand is a\nstring, the string is converted to the value of a matching <tt>enum</tt>\nconstant before the above conversion.<br>\n\n<li><b>Comparisons for equality/inequality</b> never raise an error.\nEven incompatible pointers can be compared for equality by address. Any\nother incompatible comparison (also with non-cdata objects) treats the\ntwo sides as unequal.</li>\n\n</ul>\n\n<h3 id=\"cdata_key\">cdata objects as table keys</h3>\n<p>\nLua tables may be indexed by cdata objects, but this doesn't provide\nany useful semantics &mdash; <b>cdata objects are unsuitable as table\nkeys!</b>\n</p>\n<p>\nA cdata object is treated like any other garbage-collected object and\nis hashed and compared by its address for table indexing. Since\nthere's no interning for cdata value types, the same value may be\nboxed in different cdata objects with different addresses. Thus\n<tt>t[1LL+1LL]</tt> and <tt>t[2LL]</tt> usually <b>do not</b> point to\nthe same hash slot and they certainly <b>do not</b> point to the same\nhash slot as <tt>t[2]</tt>.\n</p>\n<p>\nIt would seriously drive up implementation complexity and slow down\nthe common case, if one were to add extra handling for by-value\nhashing and comparisons to Lua tables. Given the ubiquity of their use\ninside the VM, this is not acceptable.\n</p>\n<p>\nThere are three viable alternatives, if you really need to use cdata\nobjects as keys:\n</p>\n<ul>\n\n<li>If you can get by with the precision of Lua numbers\n(52&nbsp;bits), then use <tt>tonumber()</tt> on a cdata number or\ncombine multiple fields of a cdata aggregate to a Lua number. Then use\nthe resulting Lua number as a key when indexing tables.<br>\nOne obvious benefit: <tt>t[tonumber(2LL)]</tt> <b>does</b> point to\nthe same slot as <tt>t[2]</tt>.</li>\n\n<li>Otherwise use either <tt>tostring()</tt> on 64&nbsp;bit integers\nor complex numbers or combine multiple fields of a cdata aggregate to\na Lua string (e.g. with\n<a href=\"ext_ffi_api.html#ffi_string\"><tt>ffi.string()</tt></a>). Then\nuse the resulting Lua string as a key when indexing tables.</li>\n\n<li>Create your own specialized hash table implementation using the\nC&nbsp;types provided by the FFI library, just like you would in\nC&nbsp;code. Ultimately this may give much better performance than the\nother alternatives or what a generic by-value hash table could\npossibly provide.</li>\n\n</ul>\n\n<h2 id=\"param\">Parameterized Types</h2>\n<p>\nTo facilitate some abstractions, the two functions\n<a href=\"ext_ffi_api.html#ffi_typeof\"><tt>ffi.typeof</tt></a> and\n<a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a> support\nparameterized types in C&nbsp;declarations. Note: none of the other API\nfunctions taking a cdecl allow this.\n</p>\n<p>\nAny place you can write a <b><tt>typedef</tt> name</b>, an\n<b>identifier</b> or a <b>number</b> in a declaration, you can write\n<tt>$</tt> (the dollar sign) instead. These placeholders are replaced in\norder of appearance with the arguments following the cdecl string:\n</p>\n<pre class=\"code\">\n-- Declare a struct with a parameterized field type and name:\nffi.cdef([[\ntypedef struct { $ $; } foo_t;\n]], type1, name1)\n\n-- Anonymous struct with dynamic names:\nlocal bar_t = ffi.typeof(\"struct { int $, $; }\", name1, name2)\n-- Derived pointer type:\nlocal bar_ptr_t = ffi.typeof(\"$ *\", bar_t)\n\n-- Parameterized dimensions work even where a VLA won't work:\nlocal matrix_t = ffi.typeof(\"uint8_t[$][$]\", width, height)\n</pre>\n<p>\nCaveat: this is <em>not</em> simple text substitution! A passed ctype or\ncdata object is treated like the underlying type, a passed string is\nconsidered an identifier and a number is considered a number. You must\nnot mix this up: e.g. passing <tt>\"int\"</tt> as a string doesn't work in\nplace of a type, you'd need to use <tt>ffi.typeof(\"int\")</tt> instead.\n</p>\n<p>\nThe main use for parameterized types are libraries implementing abstract\ndata types\n(<a href=\"https://www.freelists.org/post/luajit/ffi-type-of-pointer-to,8\"><span class=\"ext\">&raquo;</span>&nbsp;example</a>),\nsimilar to what can be achieved with C++ template metaprogramming.\nAnother use case are derived types of anonymous structs, which avoids\npollution of the global struct namespace.\n</p>\n<p>\nPlease note that parameterized types are a nice tool and indispensable\nfor certain use cases. But you'll want to use them sparingly in regular\ncode, e.g. when all types are actually fixed.\n</p>\n\n<h2 id=\"gc\">Garbage Collection of cdata Objects</h2>\n<p>\nAll explicitly (<tt>ffi.new()</tt>, <tt>ffi.cast()</tt> etc.) or\nimplicitly (accessors) created cdata objects are garbage collected.\nYou need to ensure to retain valid references to cdata objects\nsomewhere on a Lua stack, an upvalue or in a Lua table while they are\nstill in use. Once the last reference to a cdata object is gone, the\ngarbage collector will automatically free the memory used by it (at\nthe end of the next GC cycle).\n</p>\n<p>\nPlease note that pointers themselves are cdata objects, however they\nare <b>not</b> followed by the garbage collector. So e.g. if you\nassign a cdata array to a pointer, you must keep the cdata object\nholding the array alive as long as the pointer is still in use:\n</p>\n<pre class=\"code\">\nffi.cdef[[\ntypedef struct { int *a; } foo_t;\n]]\n\nlocal s = ffi.new(\"foo_t\", ffi.new(\"int[10]\")) -- <span style=\"color:#c00000;\">WRONG!</span>\n\nlocal a = ffi.new(\"int[10]\") -- <span style=\"color:#00a000;\">OK</span>\nlocal s = ffi.new(\"foo_t\", a)\n-- Now do something with 's', but keep 'a' alive until you're done.\n</pre>\n<p>\nSimilar rules apply for Lua strings which are implicitly converted to\n<tt>\"const&nbsp;char&nbsp;*\"</tt>: the string object itself must be\nreferenced somewhere or it'll be garbage collected eventually. The\npointer will then point to stale data, which may have already been\noverwritten. Note that <em>string literals</em> are automatically kept\nalive as long as the function containing it (actually its prototype)\nis not garbage collected.\n</p>\n<p>\nObjects which are passed as an argument to an external C&nbsp;function\nare kept alive until the call returns. So it's generally safe to\ncreate temporary cdata objects in argument lists. This is a common\nidiom for <a href=\"#convert_vararg\">passing specific C&nbsp;types to\nvararg functions</a>.\n</p>\n<p>\nMemory areas returned by C functions (e.g. from <tt>malloc()</tt>)\nmust be manually managed, of course (or use\n<a href=\"ext_ffi_api.html#ffi_gc\"><tt>ffi.gc()</tt></a>). Pointers to\ncdata objects are indistinguishable from pointers returned by C\nfunctions (which is one of the reasons why the GC cannot follow them).\n</p>\n\n<h2 id=\"callback\">Callbacks</h2>\n<p>\nThe LuaJIT FFI automatically generates special callback functions\nwhenever a Lua function is converted to a C&nbsp;function pointer. This\nassociates the generated callback function pointer with the C&nbsp;type\nof the function pointer and the Lua function object (closure).\n</p>\n<p>\nThis can happen implicitly due to the usual conversions, e.g. when\npassing a Lua function to a function pointer argument. Or you can use\n<tt>ffi.cast()</tt> to explicitly cast a Lua function to a\nC&nbsp;function pointer.\n</p>\n<p>\nCurrently only certain C&nbsp;function types can be used as callback\nfunctions. Neither C&nbsp;vararg functions nor functions with\npass-by-value aggregate argument or result types are supported. There\nare no restrictions for the kind of Lua functions that can be called\nfrom the callback &mdash; no checks for the proper number of arguments\nare made. The return value of the Lua function will be converted to the\nresult type and an error will be thrown for invalid conversions.\n</p>\n<p>\nIt's allowed to throw errors across a callback invocation, but it's not\nadvisable in general. Do this only if you know the C&nbsp;function, that\ncalled the callback, copes with the forced stack unwinding and doesn't\nleak resources.\n</p>\n<p>\nOne thing that's not allowed, is to let an FFI call into a C&nbsp;function\nget JIT-compiled, which in turn calls a callback, calling into Lua again.\nUsually this attempt is caught by the interpreter first and the\nC&nbsp;function is blacklisted for compilation.\n</p>\n<p>\nHowever, this heuristic may fail under specific circumstances: e.g. a\nmessage polling function might not run Lua callbacks right away and the call\ngets JIT-compiled. If it later happens to call back into Lua (e.g. a rarely\ninvoked error callback), you'll get a VM PANIC with the message\n<tt>\"bad callback\"</tt>. Then you'll need to manually turn off\nJIT-compilation with\n<a href=\"ext_jit.html#jit_onoff_func\"><tt>jit.off()</tt></a> for the\nsurrounding Lua function that invokes such a message polling function (or\nsimilar).\n</p>\n\n<h3 id=\"callback_resources\">Callback resource handling</h3>\n<p>\nCallbacks take up resources &mdash; you can only have a limited number\nof them at the same time (500&nbsp;-&nbsp;1000, depending on the\narchitecture). The associated Lua functions are anchored to prevent\ngarbage collection, too.\n</p>\n<p>\n<b>Callbacks due to implicit conversions are permanent!</b> There is no\nway to guess their lifetime, since the C&nbsp;side might store the\nfunction pointer for later use (typical for GUI toolkits). The associated\nresources cannot be reclaimed until termination:\n</p>\n<pre class=\"code\">\nffi.cdef[[\ntypedef int (__stdcall *WNDENUMPROC)(void *hwnd, intptr_t l);\nint EnumWindows(WNDENUMPROC func, intptr_t l);\n]]\n\n-- Implicit conversion to a callback via function pointer argument.\nlocal count = 0\nffi.C.EnumWindows(function(hwnd, l)\n  count = count + 1\n  return true\nend, 0)\n-- The callback is permanent and its resources cannot be reclaimed!\n-- Ok, so this may not be a problem, if you do this only once.\n</pre>\n<p>\nNote: this example shows that you <em>must</em> properly declare\n<tt>__stdcall</tt> callbacks on Windows/x86 systems. The calling\nconvention cannot be automatically detected, unlike for\n<tt>__stdcall</tt> calls <em>to</em> Windows functions.\n</p>\n<p>\nFor some use cases it's necessary to free up the resources or to\ndynamically redirect callbacks. Use an explicit cast to a\nC&nbsp;function pointer and keep the resulting cdata object. Then use\nthe <a href=\"ext_ffi_api.html#callback_free\"><tt>cb:free()</tt></a>\nor <a href=\"ext_ffi_api.html#callback_set\"><tt>cb:set()</tt></a> methods\non the cdata object:\n</p>\n<pre class=\"code\">\n-- Explicitly convert to a callback via cast.\nlocal count = 0\nlocal cb = ffi.cast(\"WNDENUMPROC\", function(hwnd, l)\n  count = count + 1\n  return true\nend)\n\n-- Pass it to a C function.\nffi.C.EnumWindows(cb, 0)\n-- EnumWindows doesn't need the callback after it returns, so free it.\n\ncb:free()\n-- The callback function pointer is no longer valid and its resources\n-- will be reclaimed. The created Lua closure will be garbage collected.\n</pre>\n\n<h3 id=\"callback_performance\">Callback performance</h3>\n<p>\n<b>Callbacks are slow!</b> First, the C&nbsp;to Lua transition itself\nhas an unavoidable cost, similar to a <tt>lua_call()</tt> or\n<tt>lua_pcall()</tt>. Argument and result marshalling add to that cost.\nAnd finally, neither the C&nbsp;compiler nor LuaJIT can inline or\noptimize across the language barrier and hoist repeated computations out\nof a callback function.\n</p>\n<p>\nDo not use callbacks for performance-sensitive work: e.g. consider a\nnumerical integration routine which takes a user-defined function to\nintegrate over. It's a bad idea to call a user-defined Lua function from\nC&nbsp;code millions of times. The callback overhead will be absolutely\ndetrimental for performance.\n</p>\n<p>\nIt's considerably faster to write the numerical integration routine\nitself in Lua &mdash; the JIT compiler will be able to inline the\nuser-defined function and optimize it together with its calling context,\nwith very competitive performance.\n</p>\n<p>\nAs a general guideline: <b>use callbacks only when you must</b>, because\nof existing C&nbsp;APIs. E.g. callback performance is irrelevant for a\nGUI application, which waits for user input most of the time, anyway.\n</p>\n<p>\nFor new designs <b>avoid push-style APIs</b>: a C&nbsp;function repeatedly\ncalling a callback for each result. Instead <b>use pull-style APIs</b>:\ncall a C&nbsp;function repeatedly to get a new result. Calls from Lua\nto C via the FFI are much faster than the other way round. Most well-designed\nlibraries already use pull-style APIs (read/write, get/put).\n</p>\n\n<h2 id=\"clib\">C Library Namespaces</h2>\n<p>\nA C&nbsp;library namespace is a special kind of object which allows\naccess to the symbols contained in shared libraries or the default\nsymbol namespace. The default\n<a href=\"ext_ffi_api.html#ffi_C\"><tt>ffi.C</tt></a> namespace is\nautomatically created when the FFI library is loaded. C&nbsp;library\nnamespaces for specific shared libraries may be created with the\n<a href=\"ext_ffi_api.html#ffi_load\"><tt>ffi.load()</tt></a> API\nfunction.\n</p>\n<p>\nIndexing a C&nbsp;library namespace object with a symbol name (a Lua\nstring) automatically binds it to the library. First the symbol type\nis resolved &mdash; it must have been declared with\n<a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a>. Then the\nsymbol address is resolved by searching for the symbol name in the\nassociated shared libraries or the default symbol namespace. Finally,\nthe resulting binding between the symbol name, the symbol type and its\naddress is cached. Missing symbol declarations or nonexistent symbol\nnames cause an error.\n</p>\n<p>\nThis is what happens on a <b>read access</b> for the different kinds of\nsymbols:\n</p>\n<ul>\n\n<li>External functions: a cdata object with the type of the function\nand its address is returned.</li>\n\n<li>External variables: the symbol address is dereferenced and the\nloaded value is <a href=\"#convert_tolua\">converted to a Lua object</a>\nand returned.</li>\n\n<li>Constant values (<tt>static&nbsp;const</tt> or <tt>enum</tt>\nconstants): the constant is <a href=\"#convert_tolua\">converted to a\nLua object</a> and returned.</li>\n\n</ul>\n<p>\nThis is what happens on a <b>write access</b>:\n</p>\n<ul>\n\n<li>External variables: the value to be written is\n<a href=\"#convert_fromlua\">converted to the C&nbsp;type</a> of the\nvariable and then stored at the symbol address.</li>\n\n<li>Writing to constant variables or to any other symbol type causes\nan error, like any other attempted write to a constant location.</li>\n\n</ul>\n<p>\nC&nbsp;library namespaces themselves are garbage collected objects. If\nthe last reference to the namespace object is gone, the garbage\ncollector will eventually release the shared library reference and\nremove all memory associated with the namespace. Since this may\ntrigger the removal of the shared library from the memory of the\nrunning process, it's generally <em>not safe</em> to use function\ncdata objects obtained from a library if the namespace object may be\nunreferenced.\n</p>\n<p>\nPerformance notice: the JIT compiler specializes to the identity of\nnamespace objects and to the strings used to index it. This\neffectively turns function cdata objects into constants. It's not\nuseful and actually counter-productive to explicitly cache these\nfunction objects, e.g. <tt>local strlen = ffi.C.strlen</tt>. OTOH it\n<em>is</em> useful to cache the namespace itself, e.g. <tt>local C =\nffi.C</tt>.\n</p>\n\n<h2 id=\"policy\">No Hand-holding!</h2>\n<p>\nThe FFI library has been designed as <b>a low-level library</b>. The\ngoal is to interface with C&nbsp;code and C&nbsp;data types with a\nminimum of overhead. This means <b>you can do anything you can do\nfrom&nbsp;C</b>: access all memory, overwrite anything in memory, call\nmachine code at any memory address and so on.\n</p>\n<p>\nThe FFI library provides <b>no memory safety</b>, unlike regular Lua\ncode. It will happily allow you to dereference a <tt>NULL</tt>\npointer, to access arrays out of bounds or to misdeclare\nC&nbsp;functions. If you make a mistake, your application might crash,\njust like equivalent C&nbsp;code would.\n</p>\n<p>\nThis behavior is inevitable, since the goal is to provide full\ninteroperability with C&nbsp;code. Adding extra safety measures, like\nbounds checks, would be futile. There's no way to detect\nmisdeclarations of C&nbsp;functions, since shared libraries only\nprovide symbol names, but no type information. Likewise there's no way\nto infer the valid range of indexes for a returned pointer.\n</p>\n<p>\nAgain: the FFI library is a low-level library. This implies it needs\nto be used with care, but it's flexibility and performance often\noutweigh this concern. If you're a C or C++ developer, it'll be easy\nto apply your existing knowledge. OTOH writing code for the FFI\nlibrary is not for the faint of heart and probably shouldn't be the\nfirst exercise for someone with little experience in Lua, C or C++.\n</p>\n<p>\nAs a corollary of the above, the FFI library is <b>not safe for use by\nuntrusted Lua code</b>. If you're sandboxing untrusted Lua code, you\ndefinitely don't want to give this code access to the FFI library or\nto <em>any</em> cdata object (except 64&nbsp;bit integers or complex\nnumbers). Any properly engineered Lua sandbox needs to provide safety\nwrappers for many of the standard Lua library functions &mdash;\nsimilar wrappers need to be written for high-level operations on FFI\ndata types, too.\n</p>\n\n<h2 id=\"status\">Current Status</h2>\n<p>\nThe initial release of the FFI library has some limitations and is\nmissing some features. Most of these will be fixed in future releases.\n</p>\n<p>\n<a href=\"#clang\">C language support</a> is\ncurrently incomplete:\n</p>\n<ul>\n<li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor,\nyet.</li>\n<li>The C&nbsp;parser is able to evaluate most constant expressions\ncommonly found in C&nbsp;header files. However it doesn't handle the\nfull range of C&nbsp;expression semantics and may fail for some\nobscure constructs.</li>\n<li><tt>static const</tt> declarations only work for integer types\nup to 32&nbsp;bits. Neither declaring string constants nor\nfloating-point constants is supported.</li>\n<li>Packed <tt>struct</tt> bitfields that cross container boundaries\nare not implemented.</li>\n<li>Native vector types may be defined with the GCC <tt>mode</tt> or\n<tt>vector_size</tt> attribute. But no operations other than loading,\nstoring and initializing them are supported, yet.</li>\n<li>The <tt>volatile</tt> type qualifier is currently ignored by\ncompiled code.</li>\n<li><a href=\"ext_ffi_api.html#ffi_cdef\"><tt>ffi.cdef</tt></a> silently\nignores most re-declarations. Note: avoid re-declarations which do not\nconform to C99. The implementation will eventually be changed to\nperform strict checks.</li>\n</ul>\n<p>\nThe JIT compiler already handles a large subset of all FFI operations.\nIt automatically falls back to the interpreter for unimplemented\noperations (you can check for this with the\n<a href=\"running.html#opt_j\"><tt>-jv</tt></a> command line option).\nThe following operations are currently not compiled and may exhibit\nsuboptimal performance, especially when used in inner loops:\n</p>\n<ul>\n<li>Vector operations.</li>\n<li>Table initializers.</li>\n<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>\n<li>Non-default initialization of VLA/VLS or large C&nbsp;types\n(&gt; 128&nbsp;bytes or &gt; 16 array elements).</li>\n<li>Bitfield initializations.</li>\n<li>Pointer differences for element sizes that are not a power of\ntwo.</li>\n<li>Calls to C&nbsp;functions with aggregates passed or returned by\nvalue.</li>\n<li>Calls to ctype metamethods which are not plain functions.</li>\n<li>ctype <tt>__newindex</tt> tables and non-string lookups in ctype\n<tt>__index</tt> tables.</li>\n<li><tt>tostring()</tt> for cdata types.</li>\n<li>Calls to <tt>ffi.cdef()</tt>, <tt>ffi.load()</tt> and\n<tt>ffi.metatype()</tt>.</li>\n</ul>\n<p>\nOther missing features:\n</p>\n<ul>\n<li>Arithmetic for <tt>complex</tt> numbers.</li>\n<li>Passing structs by value to vararg C&nbsp;functions.</li>\n<li><a href=\"extensions.html#exceptions\">C++ exception interoperability</a>\ndoes not extend to C&nbsp;functions called via the FFI, if the call is\ncompiled.</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_ffi_tutorial.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>FFI Tutorial</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.idiomtable { font-size: 90%; line-height: 1.2; }\ntable.idiomtable tt { font-size: 100%; }\ntable.idiomtable td { vertical-align: top; }\ntr.idiomhead td { font-weight: bold; }\ntd.idiomlua b { font-weight: normal; color: #2142bf; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>FFI Tutorial</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a class=\"current\" href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis page is intended to give you an overview of the features of the FFI\nlibrary by presenting a few use cases and guidelines.\n</p>\n<p>\nThis page makes no attempt to explain all of the FFI library, though.\nYou'll want to have a look at the <a href=\"ext_ffi_api.html\">ffi.* API\nfunction reference</a> and the <a href=\"ext_ffi_semantics.html\">FFI\nsemantics</a> to learn more.\n</p>\n\n<h2 id=\"load\">Loading the FFI Library</h2>\n<p>\nThe FFI library is built into LuaJIT by default, but it's not loaded\nand initialized by default. The suggested way to use the FFI library\nis to add the following to the start of every Lua file that needs one\nof its functions:\n</p>\n<pre class=\"code\">\nlocal ffi = require(\"ffi\")\n</pre>\n<p>\nPlease note this doesn't define an <tt>ffi</tt> variable in the table\nof globals &mdash; you really need to use the local variable. The\n<tt>require</tt> function ensures the library is only loaded once.\n</p>\n<p style=\"font-size: 8pt;\">\nNote: If you want to experiment with the FFI from the interactive prompt\nof the command line executable, omit the <tt>local</tt>, as it doesn't\npreserve local variables across lines.\n</p>\n\n<h2 id=\"sleep\">Accessing Standard System Functions</h2>\n<p>\nThe following code explains how to access standard system functions.\nWe slowly print two lines of dots by sleeping for 10&nbsp;milliseconds\nafter each dot:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n\n\n&#9313;\n&#9314;\n&#9315;\n\n\n\n&#9316;\n\n\n\n\n\n&#9317;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">void Sleep(int ms);\nint poll(struct pollfd *fds, unsigned long nfds, int timeout);</span>\n]]\n\nlocal sleep\nif ffi.os == \"Windows\" then\n  function sleep(s)\n    ffi.C.Sleep(s*1000)\n  end\nelse\n  function sleep(s)\n    ffi.C.poll(nil, 0, s*1000)\n  end\nend\n\nfor i=1,160 do\n  io.write(\".\"); io.flush()\n  sleep(0.01)\nend\nio.write(\"\\n\")\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines the\nC&nbsp;library functions we're going to use. The part inside the\ndouble-brackets (in green) is just standard C&nbsp;syntax. You can\nusually get this info from the C&nbsp;header files or the\ndocumentation provided by each C&nbsp;library or C&nbsp;compiler.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> The difficulty we're\nfacing here, is that there are different standards to choose from.\nWindows has a simple <tt>Sleep()</tt> function. On other systems there\nare a variety of functions available to achieve sub-second sleeps, but\nwith no clear consensus. Thankfully <tt>poll()</tt> can be used for\nthis task, too, and it's present on most non-Windows systems. The\ncheck for <tt>ffi.os</tt> makes sure we use the Windows-specific\nfunction only on Windows systems.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Here we're wrapping the\ncall to the C&nbsp;function in a Lua function. This isn't strictly\nnecessary, but it's helpful to deal with system-specific issues only\nin one part of the code. The way we're wrapping it ensures the check\nfor the OS is only done during initialization and not for every call.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> A more subtle point is\nthat we defined our <tt>sleep()</tt> function (for the sake of this\nexample) as taking the number of seconds, but accepting fractional\nseconds. Multiplying this by 1000 gets us milliseconds, but that still\nleaves it a Lua number, which is a floating-point value. Alas, the\n<tt>Sleep()</tt> function only accepts an integer value. Luckily for\nus, the FFI library automatically performs the conversion when calling\nthe function (truncating the FP value towards zero, like in C).\n</p>\n<p style=\"font-size: 8pt;\">\nSome readers will notice that <tt>Sleep()</tt> is part of\n<tt>KERNEL32.DLL</tt> and is also a <tt>stdcall</tt> function. So how\ncan this possibly work? The FFI library provides the <tt>ffi.C</tt>\ndefault C&nbsp;library namespace, which allows calling functions from\nthe default set of libraries, like a C&nbsp;compiler would. Also, the\nFFI library automatically detects <tt>stdcall</tt> functions, so you\ndon't need to declare them as such.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> The <tt>poll()</tt>\nfunction takes a couple more arguments we're not going to use. You can\nsimply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt>\nfor the <tt>nfds</tt> parameter. Please note that the\nnumber&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>,\nunlike in C++. You really have to pass pointers to pointer arguments\nand numbers to number arguments.\n</p>\n<p style=\"font-size: 8pt;\">\nThe page on <a href=\"ext_ffi_semantics.html\">FFI semantics</a> has all\nof the gory details about\n<a href=\"ext_ffi_semantics.html#convert\">conversions between Lua\nobjects and C&nbsp;types</a>. For the most part you don't have to deal\nwith this, as it's performed automatically and it's carefully designed\nto bridge the semantic differences between Lua and C.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> Now that we have defined\nour own <tt>sleep()</tt> function, we can just call it from plain Lua\ncode. That wasn't so bad, huh? Turning these boring animated dots into\na fascinating best-selling game is left as an exercise for the reader.\n:-)\n</p>\n\n<h2 id=\"zlib\">Accessing the zlib Compression Library</h2>\n<p>\nThe following code shows how to access the <a\nhref=\"https://zlib.net/\"><span class=\"ext\">&raquo;</span>&nbsp;zlib</a> compression library from Lua code.\nWe'll define two convenience wrapper functions that take a string and\ncompress or uncompress it to another string:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n\n\n\n&#9313;\n\n\n&#9314;\n\n&#9315;\n\n\n&#9316;\n\n\n&#9317;\n\n\n\n\n\n\n\n&#9318;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">unsigned long compressBound(unsigned long sourceLen);\nint compress2(uint8_t *dest, unsigned long *destLen,\n\t      const uint8_t *source, unsigned long sourceLen, int level);\nint uncompress(uint8_t *dest, unsigned long *destLen,\n\t       const uint8_t *source, unsigned long sourceLen);</span>\n]]\nlocal zlib = ffi.load(ffi.os == \"Windows\" and \"zlib1\" or \"z\")\n\nlocal function compress(txt)\n  local n = zlib.compressBound(#txt)\n  local buf = ffi.new(\"uint8_t[?]\", n)\n  local buflen = ffi.new(\"unsigned long[1]\", n)\n  local res = zlib.compress2(buf, buflen, txt, #txt, 9)\n  assert(res == 0)\n  return ffi.string(buf, buflen[0])\nend\n\nlocal function uncompress(comp, n)\n  local buf = ffi.new(\"uint8_t[?]\", n)\n  local buflen = ffi.new(\"unsigned long[1]\", n)\n  local res = zlib.uncompress(buf, buflen, comp, #comp)\n  assert(res == 0)\n  return ffi.string(buf, buflen[0])\nend\n\n-- Simple test code.\nlocal txt = string.rep(\"abcd\", 1000)\nprint(\"Uncompressed size: \", #txt)\nlocal c = compress(txt)\nprint(\"Compressed size: \", #c)\nlocal txt2 = uncompress(c, #txt)\nassert(txt2 == txt)\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines some of the\nC&nbsp;functions provided by zlib. For the sake of this example, some\ntype indirections have been reduced and it uses the pre-defined\nfixed-size integer types, while still adhering to the zlib API/ABI.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> This loads the zlib shared\nlibrary. On POSIX systems it's named <tt>libz.so</tt> and usually\ncomes pre-installed. Since <tt>ffi.load()</tt> automatically adds any\nmissing standard prefixes/suffixes, we can simply load the\n<tt>\"z\"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and\nyou'll have to download it first from the\n<a href=\"https://zlib.net/\"><span class=\"ext\">&raquo;</span>&nbsp;zlib site</a>. The check for\n<tt>ffi.os</tt> makes sure we pass the right name to\n<tt>ffi.load()</tt>.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> First, the maximum size of\nthe compression buffer is obtained by calling the\n<tt>zlib.compressBound</tt> function with the length of the\nuncompressed string. The next line allocates a byte buffer of this\nsize. The <tt>[?]</tt> in the type specification indicates a\nvariable-length array (VLA). The actual number of elements of this\narray is given as the 2nd argument to <tt>ffi.new()</tt>.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> This may look strange at\nfirst, but have a look at the declaration of the <tt>compress2</tt>\nfunction from zlib: the destination length is defined as a pointer!\nThis is because you pass in the maximum buffer size and get back the\nactual length that was used.\n</p>\n<p>\nIn C you'd pass in the address of a local variable\n(<tt>&amp;buflen</tt>). But since there's no address-of operator in\nLua, we'll just pass in a one-element array. Conveniently it can be\ninitialized with the maximum buffer size in one step. Calling the\nactual <tt>zlib.compress2</tt> function is then straightforward.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> We want to return the\ncompressed data as a Lua string, so we'll use <tt>ffi.string()</tt>.\nIt needs a pointer to the start of the data and the actual length. The\nlength has been returned in the <tt>buflen</tt> array, so we'll just\nget it from there.\n</p>\n<p style=\"font-size: 8pt;\">\nNote that since the function returns now, the <tt>buf</tt> and\n<tt>buflen</tt> variables will eventually be garbage collected. This\nis fine, because <tt>ffi.string()</tt> has copied the contents to a\nnewly created (interned) Lua string. If you plan to call this function\nlots of times, consider reusing the buffers and/or handing back the\nresults in buffers instead of strings. This will reduce the overhead\nfor garbage collection and string interning.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> The <tt>uncompress</tt>\nfunctions does the exact opposite of the <tt>compress</tt> function.\nThe compressed data doesn't include the size of the original string,\nso this needs to be passed in. Otherwise no surprises here.\n</p>\n<p>\n<span class=\"mark\">&#9318;</span> The code, that makes use\nof the functions we just defined, is just plain Lua code. It doesn't\nneed to know anything about the LuaJIT FFI &mdash; the convenience\nwrapper functions completely hide it.\n</p>\n<p>\nOne major advantage of the LuaJIT FFI is that you are now able to\nwrite those wrappers <em>in Lua</em>. And at a fraction of the time it\nwould cost you to create an extra C&nbsp;module using the Lua/C API.\nMany of the simpler C&nbsp;functions can probably be used directly\nfrom your Lua code, without any wrappers.\n</p>\n<p style=\"font-size: 8pt;\">\nSide note: the zlib API uses the <tt>long</tt> type for passing\nlengths and sizes around. But all those zlib functions actually only\ndeal with 32&nbsp;bit values. This is an unfortunate choice for a\npublic API, but may be explained by zlib's history &mdash; we'll just\nhave to deal with it.\n</p>\n<p style=\"font-size: 8pt;\">\nFirst, you should know that a <tt>long</tt> is a 64&nbsp;bit type e.g.\non POSIX/x64 systems, but a 32&nbsp;bit type on Windows/x64 and on\n32&nbsp;bit systems. Thus a <tt>long</tt> result can be either a plain\nLua number or a boxed 64&nbsp;bit integer cdata object, depending on\nthe target system.\n</p>\n<p style=\"font-size: 8pt;\">\nOk, so the <tt>ffi.*</tt> functions generally accept cdata objects\nwherever you'd want to use a number. That's why we get a away with\npassing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua\nlibrary functions or modules don't know how to deal with this. So for\nmaximum portability one needs to use <tt>tonumber()</tt> on returned\n<tt>long</tt> results before passing them on. Otherwise the\napplication might work on some systems, but would fail in a POSIX/x64\nenvironment.\n</p>\n\n<h2 id=\"metatype\">Defining Metamethods for a C&nbsp;Type</h2>\n<p>\nThe following code explains how to define metamethods for a C type.\nWe define a simple point type and add some operations to it:\n</p>\n<pre class=\"code mark\">\n<span class=\"codemark\">&nbsp;\n&#9312;\n\n\n\n&#9313;\n\n&#9314;\n\n&#9315;\n\n\n\n&#9316;\n\n&#9317;</span>local ffi = require(\"ffi\")\nffi.cdef[[\n<span style=\"color:#00a000;\">typedef struct { double x, y; } point_t;</span>\n]]\n\nlocal point\nlocal mt = {\n  __add = function(a, b) return point(a.x+b.x, a.y+b.y) end,\n  __len = function(a) return math.sqrt(a.x*a.x + a.y*a.y) end,\n  __index = {\n    area = function(a) return a.x*a.x + a.y*a.y end,\n  },\n}\npoint = ffi.metatype(\"point_t\", mt)\n\nlocal a = point(3, 4)\nprint(a.x, a.y)  --> 3  4\nprint(#a)        --> 5\nprint(a:area())  --> 25\nlocal b = a + point(0.5, 8)\nprint(#b)        --> 12.5\n</pre>\n<p>\nHere's the step-by-step explanation:\n</p>\n<p>\n<span class=\"mark\">&#9312;</span> This defines the C&nbsp;type for a\ntwo-dimensional point object.\n</p>\n<p>\n<span class=\"mark\">&#9313;</span> We have to declare the variable\nholding the point constructor first, because it's used inside of a\nmetamethod.\n</p>\n<p>\n<span class=\"mark\">&#9314;</span> Let's define an <tt>__add</tt>\nmetamethod which adds the coordinates of two points and creates a new\npoint object. For simplicity, this function assumes that both arguments\nare points. But it could be any mix of objects, if at least one operand\nis of the required type (e.g. adding a point plus a number or vice\nversa). Our <tt>__len</tt> metamethod returns the distance of a point to\nthe origin.\n</p>\n<p>\n<span class=\"mark\">&#9315;</span> If we run out of operators, we can\ndefine named methods, too. Here the <tt>__index</tt> table defines an\n<tt>area</tt> function. For custom indexing needs, one might want to\ndefine <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead.\n</p>\n<p>\n<span class=\"mark\">&#9316;</span> This associates the metamethods with\nour C&nbsp;type. This only needs to be done once. For convenience, a\nconstructor is returned by\n<a href=\"ext_ffi_api.html#ffi_metatype\"><tt>ffi.metatype()</tt></a>.\nWe're not required to use it, though. The original C&nbsp;type can still\nbe used e.g. to create an array of points. The metamethods automatically\napply to any and all uses of this type.\n</p>\n<p>\nPlease note that the association with a metatable is permanent and\n<b>the metatable must not be modified afterwards!</b> Ditto for the\n<tt>__index</tt> table.\n</p>\n<p>\n<span class=\"mark\">&#9317;</span> Here are some simple usage examples\nfor the point type and their expected results. The pre-defined\noperations (such as <tt>a.x</tt>) can be freely mixed with the newly\ndefined metamethods. Note that <tt>area</tt> is a method and must be\ncalled with the Lua syntax for methods: <tt>a:area()</tt>, not\n<tt>a.area()</tt>.\n</p>\n<p>\nThe C&nbsp;type metamethod mechanism is most useful when used in\nconjunction with C&nbsp;libraries that are written in an object-oriented\nstyle. Creators return a pointer to a new instance and methods take an\ninstance pointer as the first argument. Sometimes you can just point\n<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the\ndestructor and you're done. But often enough you'll want to add\nconvenience wrappers, e.g. to return actual Lua strings or when\nreturning multiple values.\n</p>\n<p>\nSome C libraries only declare instance pointers as an opaque\n<tt>void&nbsp;*</tt> type. In this case you can use a fake type for all\ndeclarations, e.g. a pointer to a named (incomplete) struct will do:\n<tt>typedef struct foo_type *foo_handle</tt>. The C&nbsp;side doesn't\nknow what you declare with the LuaJIT FFI, but as long as the underlying\ntypes are compatible, everything still works.\n</p>\n\n<h2 id=\"idioms\">Translating C&nbsp;Idioms</h2>\n<p>\nHere's a list of common C&nbsp;idioms and their translation to the\nLuaJIT FFI:\n</p>\n<table class=\"idiomtable\">\n<tr class=\"idiomhead\">\n<td class=\"idiomdesc\">Idiom</td>\n<td class=\"idiomc\">C&nbsp;code</td>\n<td class=\"idiomlua\">Lua code</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"idiomdesc\">Pointer dereference<br><tt>int *p;</tt></td><td class=\"idiomc\"><tt>x = *p;<br>*p = y;</tt></td><td class=\"idiomlua\"><tt>x = <b>p[0]</b><br><b>p[0]</b> = y</tt></td></tr>\n<tr class=\"even\">\n<td class=\"idiomdesc\">Pointer indexing<br><tt>int i, *p;</tt></td><td class=\"idiomc\"><tt>x = p[i];<br>p[i+1] = y;</tt></td><td class=\"idiomlua\"><tt>x = p[i]<br>p[i+1] = y</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Array indexing<br><tt>int i, a[];</tt></td><td class=\"idiomc\"><tt>x = a[i];<br>a[i+1] = y;</tt></td><td class=\"idiomlua\"><tt>x = a[i]<br>a[i+1] = y</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\"><tt>struct</tt>/<tt>union</tt> dereference<br><tt>struct foo s;</tt></td><td class=\"idiomc\"><tt>x = s.field;<br>s.field = y;</tt></td><td class=\"idiomlua\"><tt>x = s.field<br>s.field = y</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\"><tt>struct</tt>/<tt>union</tt> pointer deref.<br><tt>struct foo *sp;</tt></td><td class=\"idiomc\"><tt>x = sp->field;<br>sp->field = y;</tt></td><td class=\"idiomlua\"><tt>x = <b>s.field</b><br><b>s.field</b> = y</tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\">Pointer arithmetic<br><tt>int i, *p;</tt></td><td class=\"idiomc\"><tt>x = p + i;<br>y = p - i;</tt></td><td class=\"idiomlua\"><tt>x = p + i<br>y = p - i</tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Pointer difference<br><tt>int *p1, *p2;</tt></td><td class=\"idiomc\"><tt>x = p1 - p2;</tt></td><td class=\"idiomlua\"><tt>x = p1 - p2</tt></td></tr>\n<tr class=\"even\">\n<td class=\"idiomdesc\">Array element pointer<br><tt>int i, a[];</tt></td><td class=\"idiomc\"><tt>x = &amp;a[i];</tt></td><td class=\"idiomlua\"><tt>x = <b>a+i</b></tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\">Cast pointer to address<br><tt>int *p;</tt></td><td class=\"idiomc\"><tt>x = (intptr_t)p;</tt></td><td class=\"idiomlua\"><tt>x = <b>tonumber(<br>&nbsp;ffi.cast(\"intptr_t\",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p))</b></tt></td></tr>\n<tr class=\"even separate\">\n<td class=\"idiomdesc\">Functions with outargs<br><tt>void foo(int *inoutlen);</tt></td><td class=\"idiomc\"><tt>int len = x;<br>foo(&amp;len);<br>y = len;</tt></td><td class=\"idiomlua\"><tt><b>local len =<br>&nbsp;&nbsp;ffi.new(\"int[1]\", x)<br>foo(len)<br>y = len[0]</b></tt></td></tr>\n<tr class=\"odd\">\n<td class=\"idiomdesc\"><a href=\"ext_ffi_semantics.html#convert_vararg\">Vararg conversions</a><br><tt>int printf(char *fmt, ...);</tt></td><td class=\"idiomc\"><tt>printf(\"%g\", 1.0);<br>printf(\"%d\", 1);<br>&nbsp;</tt></td><td class=\"idiomlua\"><tt>printf(\"%g\", 1);<br>printf(\"%d\",<br>&nbsp;&nbsp;<b>ffi.new(\"int\", 1)</b>)</tt></td></tr>\n</table>\n\n<h2 id=\"cache\">To Cache or Not to Cache</h2>\n<p>\nIt's a common Lua idiom to cache library functions in local variables\nor upvalues, e.g.:\n</p>\n<pre class=\"code\">\nlocal byte, char = string.byte, string.char\nlocal function foo(x)\n  return char(byte(x)+1)\nend\n</pre>\n<p>\nThis replaces several hash-table lookups with a (faster) direct use of\na local or an upvalue. This is less important with LuaJIT, since the\nJIT compiler optimizes hash-table lookups a lot and is even able to\nhoist most of them out of the inner loops. It can't eliminate\n<em>all</em> of them, though, and it saves some typing for often-used\nfunctions. So there's still a place for this, even with LuaJIT.\n</p>\n<p>\nThe situation is a bit different with C&nbsp;function calls via the\nFFI library. The JIT compiler has special logic to eliminate <em>all\nof the lookup overhead</em> for functions resolved from a\n<a href=\"ext_ffi_semantics.html#clib\">C&nbsp;library namespace</a>!\nThus it's not helpful and actually counter-productive to cache\nindividual C&nbsp;functions like this:\n</p>\n<pre class=\"code\">\nlocal <b>funca</b>, <b>funcb</b> = ffi.C.funca, ffi.C.funcb -- <span style=\"color:#c00000;\">Not helpful!</span>\nlocal function foo(x, n)\n  for i=1,n do <b>funcb</b>(<b>funca</b>(x, i), 1) end\nend\n</pre>\n<p>\nThis turns them into indirect calls and generates bigger and slower\nmachine code. Instead you'll want to cache the namespace itself and\nrely on the JIT compiler to eliminate the lookups:\n</p>\n<pre class=\"code\">\nlocal <b>C</b> = ffi.C          -- <span style=\"color:#00a000;\">Instead use this!</span>\nlocal function foo(x, n)\n  for i=1,n do <b>C.funcb</b>(<b>C.funca</b>(x, i), 1) end\nend\n</pre>\n<p>\nThis generates both shorter and faster code. So <b>don't cache\nC&nbsp;functions</b>, but <b>do</b> cache namespaces! Most often the\nnamespace is already in a local variable at an outer scope, e.g. from\n<tt>local&nbsp;lib&nbsp;=&nbsp;ffi.load(...)</tt>. Note that copying\nit to a local variable in the function scope is unnecessary.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_jit.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>jit.* Library</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1><tt>jit.*</tt> Library</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a class=\"current\" href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThe functions in this built-in module control the behavior of the JIT\ncompiler engine. Note that JIT-compilation is fully automatic &mdash;\nyou probably won't need to use any of the following functions unless\nyou have special needs.\n</p>\n\n<h3 id=\"jit_onoff\"><tt>jit.on()<br>\njit.off()</tt></h3>\n<p>\nTurns the whole JIT compiler on (default) or off.\n</p>\n<p>\nThese functions are typically used with the command line options\n<tt>-j on</tt> or <tt>-j off</tt>.\n</p>\n\n<h3 id=\"jit_flush\"><tt>jit.flush()</tt></h3>\n<p>\nFlushes the whole cache of compiled code.\n</p>\n\n<h3 id=\"jit_onoff_func\"><tt>jit.on(func|true [,true|false])<br>\njit.off(func|true [,true|false])<br>\njit.flush(func|true [,true|false])</tt></h3>\n<p>\n<tt>jit.on</tt> enables JIT compilation for a Lua function (this is\nthe default).\n</p>\n<p>\n<tt>jit.off</tt> disables JIT compilation for a Lua function and\nflushes any already compiled code from the code cache.\n</p>\n<p>\n<tt>jit.flush</tt> flushes the code, but doesn't affect the\nenable/disable status.\n</p>\n<p>\nThe current function, i.e. the Lua function calling this library\nfunction, can also be specified by passing <tt>true</tt> as the first\nargument.\n</p>\n<p>\nIf the second argument is <tt>true</tt>, JIT compilation is also\nenabled, disabled or flushed recursively for all sub-functions of a\nfunction. With <tt>false</tt> only the sub-functions are affected.\n</p>\n<p>\nThe <tt>jit.on</tt> and <tt>jit.off</tt> functions only set a flag\nwhich is checked when the function is about to be compiled. They do\nnot trigger immediate compilation.\n</p>\n<p>\nTypical usage is <tt>jit.off(true, true)</tt> in the main chunk\nof a module to turn off JIT compilation for the whole module for\ndebugging purposes.\n</p>\n\n<h3 id=\"jit_flush_tr\"><tt>jit.flush(tr)</tt></h3>\n<p>\nFlushes the root trace, specified by its number, and all of its side\ntraces from the cache. The code for the trace will be retained as long\nas there are any other traces which link to it.\n</p>\n\n<h3 id=\"jit_status\"><tt>status, ... = jit.status()</tt></h3>\n<p>\nReturns the current status of the JIT compiler. The first result is\neither <tt>true</tt> or <tt>false</tt> if the JIT compiler is turned\non or off. The remaining results are strings for CPU-specific features\nand enabled optimizations.\n</p>\n\n<h3 id=\"jit_version\"><tt>jit.version</tt></h3>\n<p>\nContains the LuaJIT version string.\n</p>\n\n<h3 id=\"jit_version_num\"><tt>jit.version_num</tt></h3>\n<p>\nContains the version number of the LuaJIT core. Version xx.yy.zz\nis represented by the decimal number xxyyzz.\n</p>\n\n<h3 id=\"jit_os\"><tt>jit.os</tt></h3>\n<p>\nContains the target OS name:\n\"Windows\", \"Linux\", \"OSX\", \"BSD\", \"POSIX\" or \"Other\".\n</p>\n\n<h3 id=\"jit_arch\"><tt>jit.arch</tt></h3>\n<p>\nContains the target architecture name:\n\"x86\", \"x64\", \"arm\", \"arm64\", \"arm64be\", \"ppc\", \"mips\", \"mipsel\", \"mips64\", \"mips64el\", \"mips64r6\", \"mips64r6el\".\n</p>\n\n<h2 id=\"jit_opt\"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>\n<p>\nThis sub-module provides the backend for the <tt>-O</tt> command line\noption.\n</p>\n<p>\nYou can also use it programmatically, e.g.:\n</p>\n<pre class=\"code\">\njit.opt.start(2) -- same as -O2\njit.opt.start(\"-dce\")\njit.opt.start(\"hotloop=10\", \"hotexit=2\")\n</pre>\n<p>\nUnlike in LuaJIT 1.x, the module is built-in and\n<b>optimization is turned on by default!</b>\nIt's no longer necessary to run <tt>require(\"jit.opt\").start()</tt>,\nwhich was one of the ways to enable optimization.\n</p>\n\n<h2 id=\"jit_util\"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>\n<p>\nThis sub-module holds functions to introspect the bytecode, generated\ntraces, the IR and the generated machine code. The functionality\nprovided by this module is still in flux and therefore undocumented.\n</p>\n<p>\nThe debug modules <tt>-jbc</tt>, <tt>-jv</tt> and <tt>-jdump</tt> make\nextensive use of these functions. Please check out their source code,\nif you want to know more.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/ext_profiler.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Profiler</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Profiler</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a class=\"current\" href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT has an integrated statistical profiler with very low overhead. It\nallows sampling the currently executing stack and other parameters in\nregular intervals.\n</p>\n<p>\nThe integrated profiler can be accessed from three levels:\n</p>\n<ul>\n<li>The <a href=\"#hl_profiler\">bundled high-level profiler</a>, invoked by the\n<a href=\"#j_p\"><tt>-jp</tt></a> command line option.</li>\n<li>A <a href=\"#ll_lua_api\">low-level Lua API</a> to control the profiler.</li>\n<li>A <a href=\"#ll_c_api\">low-level C API</a> to control the profiler.</li>\n</ul>\n\n<h2 id=\"hl_profiler\">High-Level Profiler</h2>\n<p>\nThe bundled high-level profiler offers basic profiling functionality. It\ngenerates simple textual summaries or source code annotations. It can be\naccessed with the <a href=\"#j_p\"><tt>-jp</tt></a> command line option\nor from Lua code by loading the underlying <tt>jit.p</tt> module.\n</p>\n<p>\nTo cut to the chase &mdash; run this to get a CPU usage profile by\nfunction name:\n</p>\n<pre class=\"code\">\nluajit -jp myapp.lua\n</pre>\n<p>\nIt's <em>not</em> a stated goal of the bundled profiler to add every\npossible option or to cater for special profiling needs. The low-level\nprofiler APIs are documented below. They may be used by third-party\nauthors to implement advanced functionality, e.g. IDE integration or\ngraphical profilers.\n</p>\n<p>\nNote: Sampling works for both interpreted and JIT-compiled code. The\nresults for JIT-compiled code may sometimes be surprising. LuaJIT\nheavily optimizes and inlines Lua code &mdash; there's no simple\none-to-one correspondence between source code lines and the sampled\nmachine code.\n</p>\n\n<h3 id=\"j_p\"><tt>-jp=[options[,output]]</tt></h3>\n<p>\nThe <tt>-jp</tt> command line option starts the high-level profiler.\nWhen the application run by the command line terminates, the profiler\nstops and writes the results to <tt>stdout</tt> or to the specified\n<tt>output</tt> file.\n</p>\n<p>\nThe <tt>options</tt> argument specifies how the profiling is to be\nperformed:\n</p>\n<ul>\n<li><tt>f</tt> &mdash; Stack dump: function name, otherwise module:line.\nThis is the default mode.</li>\n<li><tt>F</tt> &mdash; Stack dump: ditto, but dump module:name.</li>\n<li><tt>l</tt> &mdash; Stack dump: module:line.</li>\n<li><tt>&lt;number&gt;</tt> &mdash; stack dump depth (callee &larr;\ncaller). Default: 1.</li>\n<li><tt>-&lt;number&gt;</tt> &mdash; Inverse stack dump depth (caller\n&rarr; callee).</li>\n<li><tt>s</tt> &mdash; Split stack dump after first stack level. Implies\ndepth&nbsp;&ge;&nbsp;2 or depth&nbsp;&le;&nbsp;-2.</li>\n<li><tt>p</tt> &mdash; Show full path for module names.</li>\n<li><tt>v</tt> &mdash; Show VM states.</li>\n<li><tt>z</tt> &mdash; Show <a href=\"#jit_zone\">zones</a>.</li>\n<li><tt>r</tt> &mdash; Show raw sample counts. Default: show percentages.</li>\n<li><tt>a</tt> &mdash; Annotate excerpts from source code files.</li>\n<li><tt>A</tt> &mdash; Annotate complete source code files.</li>\n<li><tt>G</tt> &mdash; Produce raw output suitable for graphical tools.</li>\n<li><tt>m&lt;number&gt;</tt> &mdash; Minimum sample percentage to be shown.\nDefault: 3%.</li>\n<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds.\nDefault: 10ms.<br>\nNote: The actual sampling precision is OS-dependent.</li>\n</ul>\n<p>\nThe default output for <tt>-jp</tt> is a list of the most CPU consuming\nspots in the application. Increasing the stack dump depth with (say)\n<tt>-jp=2</tt> may help to point out the main callers or callees of\nhotspots. But sample aggregation is still flat per unique stack dump.\n</p>\n<p>\nTo get a two-level view (split view) of callers/callees, use\n<tt>-jp=s</tt> or <tt>-jp=-s</tt>. The percentages shown for the second\nlevel are relative to the first level.\n</p>\n<p>\nTo see how much time is spent in each line relative to a function, use\n<tt>-jp=fl</tt>.\n</p>\n<p>\nTo see how much time is spent in different VM states or\n<a href=\"#jit_zone\">zones</a>, use <tt>-jp=v</tt> or <tt>-jp=z</tt>.\n</p>\n<p>\nCombinations of <tt>v/z</tt> with <tt>f/F/l</tt> produce two-level\nviews, e.g. <tt>-jp=vf</tt> or <tt>-jp=fv</tt>. This shows the time\nspent in a VM state or zone vs. hotspots. This can be used to answer\nquestions like \"Which time consuming functions are only interpreted?\" or\n\"What's the garbage collector overhead for a specific function?\".\n</p>\n<p>\nMultiple options can be combined &mdash; but not all combinations make\nsense, see above. E.g. <tt>-jp=3si4m1</tt> samples three stack levels\ndeep in 4ms intervals and shows a split view of the CPU consuming\nfunctions and their callers with a 1% threshold.\n</p>\n<p>\nSource code annotations produced by <tt>-jp=a</tt> or <tt>-jp=A</tt> are\nalways flat and at the line level. Obviously, the source code files need\nto be readable by the profiler script.\n</p>\n<p>\nThe high-level profiler can also be started and stopped from Lua code with:\n</p>\n<pre class=\"code\">\nrequire(\"jit.p\").start(options, output)\n...\nrequire(\"jit.p\").stop()\n</pre>\n\n<h3 id=\"jit_zone\"><tt>jit.zone</tt> &mdash; Zones</h3>\n<p>\nZones can be used to provide information about different parts of an\napplication to the high-level profiler. E.g. a game could make use of an\n<tt>\"AI\"</tt> zone, a <tt>\"PHYS\"</tt> zone, etc. Zones are hierarchical,\norganized as a stack.\n</p>\n<p>\nThe <tt>jit.zone</tt> module needs to be loaded explicitly:\n</p>\n<pre class=\"code\">\nlocal zone = require(\"jit.zone\")\n</pre>\n<ul>\n<li><tt>zone(\"name\")</tt> pushes a named zone to the zone stack.</li>\n<li><tt>zone()</tt> pops the current zone from the zone stack and\nreturns its name.</li>\n<li><tt>zone:get()</tt> returns the current zone name or <tt>nil</tt>.</li>\n<li><tt>zone:flush()</tt> flushes the zone stack.</li>\n</ul>\n<p>\nTo show the time spent in each zone use <tt>-jp=z</tt>. To show the time\nspent relative to hotspots use e.g. <tt>-jp=zf</tt> or <tt>-jp=fz</tt>.\n</p>\n\n<h2 id=\"ll_lua_api\">Low-level Lua API</h2>\n<p>\nThe <tt>jit.profile</tt> module gives access to the low-level API of the\nprofiler from Lua code. This module needs to be loaded explicitly:\n<pre class=\"code\">\nlocal profile = require(\"jit.profile\")\n</pre>\n<p>\nThis module can be used to implement your own higher-level profiler.\nA typical profiling run starts the profiler, captures stack dumps in\nthe profiler callback, adds them to a hash table to aggregate the number\nof samples, stops the profiler and then analyzes all of the captured\nstack dumps. Other parameters can be sampled in the profiler callback,\ntoo. But it's important not to spend too much time in the callback,\nsince this may skew the statistics.\n</p>\n\n<h3 id=\"profile_start\"><tt>profile.start(mode, cb)</tt>\n&mdash; Start profiler</h3>\n<p>\nThis function starts the profiler. The <tt>mode</tt> argument is a\nstring holding options:\n</p>\n<ul>\n<li><tt>f</tt> &mdash; Profile with precision down to the function level.</li>\n<li><tt>l</tt> &mdash; Profile with precision down to the line level.</li>\n<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds (default\n10ms).</br>\nNote: The actual sampling precision is OS-dependent.\n</li>\n</ul>\n<p>\nThe <tt>cb</tt> argument is a callback function which is called with\nthree arguments: <tt>(thread, samples, vmstate)</tt>. The callback is\ncalled on a separate coroutine, the <tt>thread</tt> argument is the\nstate that holds the stack to sample for profiling. Note: do\n<em>not</em> modify the stack of that state or call functions on it.\n</p>\n<p>\n<tt>samples</tt> gives the number of accumulated samples since the last\ncallback (usually 1).\n</p>\n<p>\n<tt>vmstate</tt> holds the VM state at the time the profiling timer\ntriggered. This may or may not correspond to the state of the VM when\nthe profiling callback is called. The state is either <tt>'N'</tt>\nnative (compiled) code, <tt>'I'</tt> interpreted code, <tt>'C'</tt>\nC&nbsp;code, <tt>'G'</tt> the garbage collector, or <tt>'J'</tt> the JIT\ncompiler.\n</p>\n\n<h3 id=\"profile_stop\"><tt>profile.stop()</tt>\n&mdash; Stop profiler</h3>\n<p>\nThis function stops the profiler.\n</p>\n\n<h3 id=\"profile_dump\"><tt>dump = profile.dumpstack([thread,] fmt, depth)</tt>\n&mdash; Dump stack </h3>\n<p>\nThis function allows taking stack dumps in an efficient manner. It\nreturns a string with a stack dump for the <tt>thread</tt> (coroutine),\nformatted according to the <tt>fmt</tt> argument:\n</p>\n<ul>\n<li><tt>p</tt> &mdash; Preserve the full path for module names. Otherwise\nonly the file name is used.</li>\n<li><tt>f</tt> &mdash; Dump the function name if it can be derived. Otherwise\nuse module:line.</li>\n<li><tt>F</tt> &mdash; Ditto, but dump module:name.</li>\n<li><tt>l</tt> &mdash; Dump module:line.</li>\n<li><tt>Z</tt> &mdash; Zap the following characters for the last dumped\nframe.</li>\n<li>All other characters are added verbatim to the output string.</li>\n</ul>\n<p>\nThe <tt>depth</tt> argument gives the number of frames to dump, starting\nat the topmost frame of the thread. A negative number dumps the frames in\ninverse order.\n</p>\n<p>\nThe first example prints a list of the current module names and line\nnumbers of up to 10 frames in separate lines. The second example prints\nsemicolon-separated function names for all frames (up to 100) in inverse\norder:\n</p>\n<pre class=\"code\">\nprint(profile.dumpstack(thread, \"l\\n\", 10))\nprint(profile.dumpstack(thread, \"lZ;\", -100))\n</pre>\n\n<h2 id=\"ll_c_api\">Low-level C API</h2>\n<p>\nThe profiler can be controlled directly from C&nbsp;code, e.g. for\nuse by IDEs. The declarations are in <tt>\"luajit.h\"</tt> (see\n<a href=\"ext_c_api.html\">Lua/C API</a> extensions).\n</p>\n\n<h3 id=\"luaJIT_profile_start\"><tt>luaJIT_profile_start(L, mode, cb, data)</tt>\n&mdash; Start profiler</h3>\n<p>\nThis function starts the profiler. <a href=\"#profile_start\">See\nabove</a> for a description of the <tt>mode</tt> argument.\n</p>\n<p>\nThe <tt>cb</tt> argument is a callback function with the following\ndeclaration:\n</p>\n<pre class=\"code\">\ntypedef void (*luaJIT_profile_callback)(void *data, lua_State *L,\n                                        int samples, int vmstate);\n</pre>\n<p>\n<tt>data</tt> is available for use by the callback. <tt>L</tt> is the\nstate that holds the stack to sample for profiling. Note: do\n<em>not</em> modify this stack or call functions on this stack &mdash;\nuse a separate coroutine for this purpose. <a href=\"#profile_start\">See\nabove</a> for a description of <tt>samples</tt> and <tt>vmstate</tt>.\n</p>\n\n<h3 id=\"luaJIT_profile_stop\"><tt>luaJIT_profile_stop(L)</tt>\n&mdash; Stop profiler</h3>\n<p>\nThis function stops the profiler.\n</p>\n\n<h3 id=\"luaJIT_profile_dumpstack\"><tt>p = luaJIT_profile_dumpstack(L, fmt, depth, len)</tt>\n&mdash; Dump stack </h3>\n<p>\nThis function allows taking stack dumps in an efficient manner.\n<a href=\"#profile_dump\">See above</a> for a description of <tt>fmt</tt>\nand <tt>depth</tt>.\n</p>\n<p>\nThis function returns a <tt>const&nbsp;char&nbsp;*</tt> pointing to a\nprivate string buffer of the profiler. The <tt>int&nbsp;*len</tt>\nargument returns the length of the output string. The buffer is\noverwritten on the next call and deallocated when the profiler stops.\nYou either need to consume the content immediately or copy it for later\nuse.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/extensions.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Extensions</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.exc {\n  line-height: 1.2;\n}\ntr.exchead td {\n  font-weight: bold;\n}\ntd.excplatform {\n  width: 48%;\n}\ntd.exccompiler {\n  width: 29%;\n}\ntd.excinterop {\n  width: 23%;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Extensions</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is fully upwards-compatible with Lua 5.1. It supports all\n<a href=\"https://www.lua.org/manual/5.1/manual.html#5\"><span class=\"ext\">&raquo;</span>&nbsp;standard Lua\nlibrary functions</a> and the full set of\n<a href=\"https://www.lua.org/manual/5.1/manual.html#3\"><span class=\"ext\">&raquo;</span>&nbsp;Lua/C API\nfunctions</a>.\n</p>\n<p>\nLuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic\nloader level. This means you can compile a C&nbsp;module against the\nstandard Lua headers and load the same shared library from either Lua\nor LuaJIT.\n</p>\n<p>\nLuaJIT extends the standard Lua VM with new functionality and adds\nseveral extension modules. Please note this page is only about\n<em>functional</em> enhancements and not about performance enhancements,\nsuch as the optimized VM, the faster interpreter or the JIT compiler.\n</p>\n\n<h2 id=\"modules\">Extensions Modules</h2>\n<p>\nLuaJIT comes with several built-in extension modules:\n</p>\n\n<h3 id=\"bit\"><tt>bit.*</tt> &mdash; Bitwise operations</h3>\n<p>\nLuaJIT supports all bitwise operations as defined by\n<a href=\"https://bitop.luajit.org\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp</a>:\n</p>\n<pre class=\"code\">\nbit.tobit  bit.tohex  bit.bnot    bit.band bit.bor  bit.bxor\nbit.lshift bit.rshift bit.arshift bit.rol  bit.ror  bit.bswap\n</pre>\n<p>\nThis module is a LuaJIT built-in &mdash; you don't need to download or\ninstall Lua BitOp. The Lua BitOp site has full documentation for all\n<a href=\"https://bitop.luajit.org/api.html\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp API functions</a>.\nThe FFI adds support for\n<a href=\"ext_ffi_semantics.html#cdata_arith\">64&nbsp;bit bitwise operations</a>,\nusing the same API functions.\n</p>\n<p>\nPlease make sure to <tt>require</tt> the module before using any of\nits functions:\n</p>\n<pre class=\"code\">\nlocal bit = require(\"bit\")\n</pre>\n<p>\nAn already installed Lua BitOp module is ignored by LuaJIT.\nThis way you can use bit operations from both Lua and LuaJIT on a\nshared installation.\n</p>\n\n<h3 id=\"ffi\"><tt>ffi.*</tt> &mdash; FFI library</h3>\n<p>\nThe <a href=\"ext_ffi.html\">FFI library</a> allows calling external\nC&nbsp;functions and the use of C&nbsp;data structures from pure Lua\ncode.\n</p>\n\n<h3 id=\"jit\"><tt>jit.*</tt> &mdash; JIT compiler control</h3>\n<p>\nThe functions in this module\n<a href=\"ext_jit.html\">control the behavior of the JIT compiler engine</a>.\n</p>\n\n<h3 id=\"c_api\">C API extensions</h3>\n<p>\nLuaJIT adds some\n<a href=\"ext_c_api.html\">extra functions to the Lua/C API</a>.\n</p>\n\n<h3 id=\"profiler\">Profiler</h3>\n<p>\nLuaJIT has an <a href=\"ext_profiler.html\">integrated profiler</a>.\n</p>\n\n<h2 id=\"library\">Enhanced Standard Library Functions</h2>\n\n<h3 id=\"xpcall\"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>\n<p>\nUnlike the standard implementation in Lua 5.1, <tt>xpcall()</tt>\npasses any arguments after the error function to the function\nwhich is called in a protected context.\n</p>\n\n<h3 id=\"load\"><tt>loadfile()</tt> etc. handle UTF-8 source code</h3>\n<p>\nNon-ASCII characters are handled transparently by the Lua source code parser.\nThis allows the use of UTF-8 characters in identifiers and strings.\nA UTF-8 BOM is skipped at the start of the source code.\n</p>\n\n<h3 id=\"tostring\"><tt>tostring()</tt> etc. canonicalize NaN and &plusmn;Inf</h3>\n<p>\nAll number-to-string conversions consistently convert non-finite numbers\nto the same strings on all platforms. NaN results in <tt>\"nan\"</tt>,\npositive infinity results in <tt>\"inf\"</tt> and negative infinity results\nin <tt>\"-inf\"</tt>.\n</p>\n\n<h3 id=\"tonumber\"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3>\n<p>\nAll string-to-number conversions consistently convert integer and\nfloating-point inputs in decimal, hexadecimal and binary on all platforms.\n<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous\nproblems with poor C library implementations. The builtin conversion\nfunction provides full precision according to the IEEE-754 standard, it\nworks independently of the current locale and it supports hex floating-point\nnumbers (e.g. <tt>0x1.5p-3</tt>).\n</p>\n\n<h3 id=\"string_dump\"><tt>string.dump(f [,strip])</tt> generates portable bytecode</h3>\n<p>\nAn extra argument has been added to <tt>string.dump()</tt>. If set to\n<tt>true</tt>, 'stripped' bytecode without debug information is\ngenerated. This speeds up later bytecode loading and reduces memory\nusage. See also the\n<a href=\"running.html#opt_b\"><tt>-b</tt> command line option</a>.\n</p>\n<p>\nThe generated bytecode is portable and can be loaded on any architecture\nthat LuaJIT supports, independent of word size or endianess. However the\nbytecode compatibility versions must match. Bytecode stays compatible\nfor dot releases (x.y.0 &rarr; x.y.1), but may change with major or\nminor releases (2.0 &rarr; 2.1) or between any beta release. Foreign\nbytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.\n</p>\n<p>\nNote: <tt>LJ_GC64</tt> mode requires a different frame layout, which implies\na different, incompatible bytecode format for all 64 bit ports. This may be\nrectified in the future.\n</p>\n\n<h3 id=\"table_new\"><tt>table.new(narray, nhash)</tt> allocates a pre-sized table</h3>\n<p>\nAn extra library function <tt>table.new()</tt> can be made available via\n<tt>require(\"table.new\")</tt>. This creates a pre-sized table, just like\nthe C API equivalent <tt>lua_createtable()</tt>. This is useful for big\ntables if the final table size is known and automatic table resizing is\ntoo expensive.\n</p>\n\n<h3 id=\"table_clear\"><tt>table.clear(tab)</tt> clears a table</h3>\n<p>\nAn extra library function <tt>table.clear()</tt> can be made available\nvia <tt>require(\"table.clear\")</tt>. This clears all keys and values\nfrom a table, but preserves the allocated array/hash sizes. This is\nuseful when a table, which is linked from multiple places, needs to be\ncleared and/or when recycling a table for use by the same context. This\navoids managing backlinks, saves an allocation and the overhead of\nincremental array/hash part growth.\n</p>\n<p>\nPlease note this function is meant for very specific situations. In most\ncases it's better to replace the (usually single) link with a new table\nand let the GC do its work.\n</p>\n\n<h3 id=\"math_random\">Enhanced PRNG for <tt>math.random()</tt></h3>\n<p>\nLuaJIT uses a Tausworthe PRNG with period 2^223 to implement\n<tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of\nthe PRNG results is much superior compared to the standard Lua\nimplementation which uses the platform-specific ANSI rand().\n</p>\n<p>\nThe PRNG generates the same sequences from the same seeds on all\nplatforms and makes use of all bits in the seed argument.\n<tt>math.random()</tt> without arguments generates 52 pseudo-random bits\nfor every call. The result is uniformly distributed between 0.0 and 1.0.\nIt's correctly scaled up and rounded for <tt>math.random(n&nbsp;[,m])</tt> to\npreserve uniformity.\n</p>\n<p>\nImportant: Neither this nor any other PRNG based on the simplistic\n<tt>math.random()</tt> API is suitable for cryptographic use.\n</p>\n\n<h3 id=\"io\"><tt>io.*</tt> functions handle 64&nbsp;bit file offsets</h3>\n<p>\nThe file I/O functions in the standard <tt>io.*</tt> library handle\n64&nbsp;bit file offsets. In particular this means it's possible\nto open files larger than 2&nbsp;Gigabytes and to reposition or obtain\nthe current file position for offsets beyond 2&nbsp;GB\n(<tt>fp:seek()</tt> method).\n</p>\n\n<h3 id=\"debug_meta\"><tt>debug.*</tt> functions identify metamethods</h3>\n<p>\n<tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt> also return information\nabout invoked metamethods. The <tt>namewhat</tt> field is set to\n<tt>\"metamethod\"</tt> and the <tt>name</tt> field has the name of\nthe corresponding metamethod (e.g. <tt>\"__index\"</tt>).\n</p>\n\n<h2 id=\"resumable\">Fully Resumable VM</h2>\n<p>\nThe LuaJIT VM is fully resumable. This means you can yield from a\ncoroutine even across contexts, where this would not possible with\nthe standard Lua&nbsp;5.1 VM: e.g. you can yield across <tt>pcall()</tt>\nand <tt>xpcall()</tt>, across iterators and across metamethods.\n</p>\n\n<h2 id=\"lua52\">Extensions from Lua 5.2</h2>\n<p>\nLuaJIT supports some language and library extensions from Lua&nbsp;5.2.\nFeatures that are unlikely to break existing code are unconditionally\nenabled:\n</p>\n<ul>\n<li><tt>goto</tt> and <tt>::labels::</tt>.</li>\n<li>Hex escapes <tt>'\\x3F'</tt> and <tt>'\\*'</tt> escape in strings.</li>\n<li><tt>load(string|reader [, chunkname [,mode [,env]]])</tt>.</li>\n<li><tt>loadstring()</tt> is an alias for <tt>load()</tt>.</li>\n<li><tt>loadfile(filename [,mode [,env]])</tt>.</li>\n<li><tt>math.log(x [,base])</tt>.</li>\n<li><tt>string.rep(s, n [,sep])</tt>.</li>\n<li><tt>string.format()</tt>: <tt>%q</tt> reversible.\n<tt>%s</tt> checks <tt>__tostring</tt>.\n<tt>%a</tt> and <tt>\"%A</tt> added.</li>\n<li>String matching pattern <tt>%g</tt> added.</li>\n<li><tt>io.read(\"*L\")</tt>.</li>\n<li><tt>io.lines()</tt> and <tt>file:lines()</tt> process\n<tt>io.read()</tt> options.</li>\n<li><tt>os.exit(status|true|false [,close])</tt>.</li>\n<li><tt>package.searchpath(name, path [, sep [, rep]])</tt>.</li>\n<li><tt>package.loadlib(name, \"*\")</tt>.</li>\n<li><tt>debug.getinfo()</tt> returns <tt>nparams</tt> and <tt>isvararg</tt>\nfor option <tt>\"u\"</tt>.</li>\n<li><tt>debug.getlocal()</tt> accepts function instead of level.</li>\n<li><tt>debug.getlocal()</tt> and <tt>debug.setlocal()</tt> accept negative\nindexes for varargs.</li>\n<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle\nC&nbsp;functions.</li>\n<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>\n<li>Lua/C API extensions:\n<tt>lua_version()</tt>\n<tt>lua_upvalueid()</tt>\n<tt>lua_upvaluejoin()</tt>\n<tt>lua_loadx()</tt>\n<tt>lua_copy()</tt>\n<tt>lua_tonumberx()</tt>\n<tt>lua_tointegerx()</tt>\n<tt>luaL_fileresult()</tt>\n<tt>luaL_execresult()</tt>\n<tt>luaL_loadfilex()</tt>\n<tt>luaL_loadbufferx()</tt>\n<tt>luaL_traceback()</tt>\n<tt>luaL_setfuncs()</tt>\n<tt>luaL_pushmodule()</tt>\n<tt>luaL_newlibtable()</tt>\n<tt>luaL_newlib()</tt>\n<tt>luaL_testudata()</tt>\n<tt>luaL_setmetatable()</tt>\n</li>\n<li>Command line option <tt>-E</tt>.</li>\n<li>Command line checks <tt>__tostring</tt> for errors.</li>\n</ul>\n<p>\nOther features are only enabled, if LuaJIT is built with\n<tt>-DLUAJIT_ENABLE_LUA52COMPAT</tt>:\n</p>\n<ul>\n<li><tt>goto</tt> is a keyword and not a valid variable name anymore.</li>\n<li><tt>break</tt> can be placed anywhere. Empty statements (<tt>;;</tt>)\nare allowed.</li>\n<li><tt>__lt</tt>, <tt>__le</tt> are invoked for mixed types.</li>\n<li><tt>__len</tt> for tables. <tt>rawlen()</tt> library function.</li>\n<li><tt>pairs()</tt> and <tt>ipairs()</tt> check for <tt>__pairs</tt> and\n<tt>__ipairs</tt>.</li>\n<li><tt>coroutine.running()</tt> returns two results.</li>\n<li><tt>table.pack()</tt> and <tt>table.unpack()</tt>\n(same as <tt>unpack()</tt>).</li>\n<li><tt>io.write()</tt> and <tt>file:write()</tt> return file handle\ninstead of <tt>true</tt>.</li>\n<li><tt>os.execute()</tt> and <tt>pipe:close()</tt> return detailed\nexit status.</li>\n<li><tt>debug.setmetatable()</tt> returns object.</li>\n<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>\n<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li>\n<li><tt>package.searchers</tt>.</li>\n<li><tt>module()</tt> returns the module table.</li>\n</ul>\n<p>\nNote: this provides only partial compatibility with Lua 5.2 at the\nlanguage and Lua library level. LuaJIT is API+ABI-compatible with\nLua&nbsp;5.1, which prevents implementing features that would otherwise\nbreak the Lua/C API and ABI (e.g. <tt>_ENV</tt>).\n</p>\n\n<h2 id=\"lua53\">Extensions from Lua 5.3</h2>\n<p>\nLuaJIT supports some extensions from Lua&nbsp;5.3:\n<ul>\n<li>Unicode escape <tt>'\\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.</li>\n<li>The argument table <tt>arg</tt> can be read (and modified) by <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.</li>\n<li><tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.</li>\n<li><tt>assert()</tt> accepts any type of error object.</li>\n<li><tt>table.move(a1, f, e, t [,a2])</tt>.</li>\n<li><tt>coroutine.isyieldable()</tt>.</li>\n<li>Lua/C API extensions:\n<tt>lua_isyieldable()</tt>\n</li>\n</ul>\n\n<h2 id=\"exceptions\">C++ Exception Interoperability</h2>\n<p>\nLuaJIT has built-in support for interoperating with C++&nbsp;exceptions.\nThe available range of features depends on the target platform and\nthe toolchain used to compile LuaJIT:\n</p>\n<table class=\"exc\">\n<tr class=\"exchead\">\n<td class=\"excplatform\">Platform</td>\n<td class=\"exccompiler\">Compiler</td>\n<td class=\"excinterop\">Interoperability</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"excplatform\">External frame unwinding</td>\n<td class=\"exccompiler\">GCC, Clang, MSVC</td>\n<td class=\"excinterop\"><b style=\"color: #00a000;\">Full</b></td>\n</tr>\n<tr class=\"even\">\n<td class=\"excplatform\">Internal frame unwinding + DWARF2</td>\n<td class=\"exccompiler\">GCC, Clang</td>\n<td class=\"excinterop\"><b style=\"color: #c06000;\">Limited</b></td>\n</tr>\n<tr class=\"odd\">\n<td class=\"excplatform\">Windows 64 bit</td>\n<td class=\"exccompiler\">non-MSVC</td>\n<td class=\"excinterop\"><b style=\"color: #c06000;\">Limited</b></td>\n</tr>\n<tr class=\"even\">\n<td class=\"excplatform\">Other platforms</td>\n<td class=\"exccompiler\">Other compilers</td>\n<td class=\"excinterop\"><b style=\"color: #a00000;\">No</b></td>\n</tr>\n</table>\n<p>\n<b style=\"color: #00a000;\">Full interoperability</b> means:\n</p>\n<ul>\n<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,\n<tt>lua_pcall()</tt> etc.</li>\n<li>C++&nbsp;exceptions will be converted to the generic Lua error\n<tt>\"C++&nbsp;exception\"</tt>, unless you use the\n<a href=\"ext_c_api.html#mode_wrapcfunc\">C&nbsp;call wrapper</a> feature.</li>\n<li>It's safe to throw C++&nbsp;exceptions across non-protected Lua frames\non the C&nbsp;stack. The contents of the C++&nbsp;exception object\npass through unmodified.</li>\n<li>Lua errors can be caught on the C++ side with <tt>catch(...)</tt>.\nThe corresponding Lua error message can be retrieved from the Lua stack.<br>\nFor MSVC for Windows 64 bit this requires compilation of your C++ code\nwith <tt>/EHa</tt>.</li>\n<li>Throwing Lua errors across C++ frames is safe. C++ destructors\nwill be called.</li>\n</ul>\n<p>\n<b style=\"color: #c06000;\">Limited interoperability</b> means:\n</p>\n<ul>\n<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,\n<tt>lua_pcall()</tt> etc.</li>\n<li>C++&nbsp;exceptions will be converted to the generic Lua error\n<tt>\"C++&nbsp;exception\"</tt>, unless you use the\n<a href=\"ext_c_api.html#mode_wrapcfunc\">C&nbsp;call wrapper</a> feature.</li>\n<li>C++&nbsp;exceptions will be caught by non-protected Lua frames and\nare rethrown as a generic Lua error. The C++&nbsp;exception object will\nbe destroyed.</li>\n<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>\n<li>Throwing Lua errors across C++ frames will <b>not</b> call\nC++ destructors.</li>\n</ul>\n\n<p>\n<b style=\"color: #a00000;\">No interoperability</b> means:\n</p>\n<ul>\n<li>It's <b>not</b> safe to throw C++&nbsp;exceptions across Lua frames.</li>\n<li>C++&nbsp;exceptions <b>cannot</b> be caught on the Lua side.</li>\n<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>\n<li>Throwing Lua errors across C++ frames will <b>not</b> call\nC++ destructors.</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/faq.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Frequently Asked Questions (FAQ)</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ndd { margin-left: 1.5em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Frequently Asked Questions (FAQ)</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a class=\"current\" href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<dl id=\"info\">\n<dt>Q: Where can I learn more about LuaJIT and Lua?</dt>\n<dd>\n<ul style=\"padding: 0;\">\n<li>The <a href=\"https://luajit.org/list.html\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics\nrelated to LuaJIT.</li>\n<li>The <a href=\"http://wiki.luajit.org/\"><span class=\"ext\">&raquo;</span>&nbsp;LuaJIT wiki</a> gathers community\nresources about LuaJIT.</li>\n<li>News about Lua itself can be found at the\n<a href=\"https://www.lua.org/lua-l.html\"><span class=\"ext\">&raquo;</span>&nbsp;Lua mailing list</a>.\nThe mailing list archives are worth checking out for older postings\nabout LuaJIT.</li>\n<li>The <a href=\"https://lua.org\"><span class=\"ext\">&raquo;</span>&nbsp;main Lua.org site</a> has complete\n<a href=\"https://www.lua.org/docs.html\"><span class=\"ext\">&raquo;</span>&nbsp;documentation</a> of the language\nand links to books and papers about Lua.</li>\n<li>The community-managed <a href=\"http://lua-users.org/wiki/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua Wiki</a>\nhas information about diverse topics.</li>\n</ul></dd>\n</dl>\n\n<dl id=\"tech\">\n<dt>Q: Where can I learn more about the compiler technology used by LuaJIT?</dt>\n<dd>\nPlease use the following Google Scholar searches to find relevant papers:<br>\nSearch for: <a href=\"https://scholar.google.com/scholar?q=Trace+Compiler\"><span class=\"ext\">&raquo;</span>&nbsp;Trace Compiler</a><br>\nSearch for: <a href=\"https://scholar.google.com/scholar?q=JIT+Compiler\"><span class=\"ext\">&raquo;</span>&nbsp;JIT Compiler</a><br>\nSearch for: <a href=\"https://scholar.google.com/scholar?q=Dynamic+Language+Optimizations\"><span class=\"ext\">&raquo;</span>&nbsp;Dynamic Language Optimizations</a><br>\nSearch for: <a href=\"https://scholar.google.com/scholar?q=SSA+Form\"><span class=\"ext\">&raquo;</span>&nbsp;SSA Form</a><br>\nSearch for: <a href=\"https://scholar.google.com/scholar?q=Linear+Scan+Register+Allocation\"><span class=\"ext\">&raquo;</span>&nbsp;Linear Scan Register Allocation</a><br>\nHere is a list of the <a href=\"http://lua-users.org/lists/lua-l/2009-11/msg00089.html\"><span class=\"ext\">&raquo;</span>&nbsp;innovative features in LuaJIT</a>.<br>\nAnd, you know, reading the source is of course the only way to enlightenment.\n</dd>\n</dl>\n\n<dl id=\"arg\">\n<dt>Q: Why do I get this error: \"attempt to index global 'arg' (a nil value)\"?<br>\nQ: My vararg functions fail after switching to LuaJIT!</dt>\n<dd>LuaJIT is compatible to the Lua 5.1 language standard. It doesn't\nsupport the implicit <tt>arg</tt> parameter for old-style vararg\nfunctions from Lua 5.0.<br>Please convert your code to the\n<a href=\"https://www.lua.org/manual/5.1/manual.html#2.5.9\"><span class=\"ext\">&raquo;</span>&nbsp;Lua 5.1\nvararg syntax</a>.</dd>\n</dl>\n\n<dl id=\"x87\">\n<dt>Q: Why do I get this error: \"bad FPU precision\"?<br>\n<dt>Q: I get weird behavior after initializing Direct3D.<br>\n<dt>Q: Some FPU operations crash after I load a Delphi DLL.<br>\n</dt>\n<dd>\n\nDirectX/Direct3D (up to version 9) sets the x87 FPU to single-precision\nmode by default. This violates the Windows ABI and interferes with the\noperation of many programs &mdash; LuaJIT is affected, too. Please make\nsure you always use the <tt>D3DCREATE_FPU_PRESERVE</tt> flag when\ninitializing Direct3D.<br>\n\nDirect3D version 10 or higher do not show this behavior anymore.\nConsider testing your application with older versions, too.<br>\n\nSimilarly, the Borland/Delphi runtime modifies the FPU control word and\nenables FP exceptions. Of course this violates the Windows ABI, too.\nPlease check the Delphi docs for the Set8087CW method.</dd>\n</dl>\n\n<dl id=\"ctrlc\">\n<dt>Q: Sometimes Ctrl-C fails to stop my Lua program. Why?</dt>\n<dd>The interrupt signal handler sets a Lua debug hook. But this is\nignored by compiled code. If your program is running in a tight loop\nand never falls back to the interpreter, the debug hook never runs and\ncan't throw the \"interrupted!\" error.<br>\nYou have to press Ctrl-C twice to get stop your program. That's similar\nto when it's stuck running inside a C function under the Lua interpreter.</dd>\n</dl>\n\n<dl id=\"order\">\n<dt>Q: Table iteration with <tt>pairs()</tt> does not result in the same order?</dt>\n<dd>The order of table iteration is explicitly <b>undefined</b> by\nthe Lua language standard.<br>\nDifferent Lua implementations or versions may use different orders for\notherwise identical tables. Different ways of constructing a table may\nresult in different orders, too.<br>\nDue to improved VM security, LuaJIT 2.1 may even use a different order\non separate VM invocations or when string keys are newly interned.<br><br>\nIf your program relies on a deterministic order, it has a bug. Rewrite it,\nso it doesn't rely on the key order. Or sort the table keys, if you must.</dd>\n</dl>\n\n<dl id=\"sandbox\">\n<dt>Q: Can Lua code be safely sandboxed?</dt>\n<dd>\nMaybe for an extremly restricted subset of Lua and if you relentlessly\nscrutinize every single interface function you offer to the untrusted code.<br>\n\nAlthough Lua provides some sandboxing functionality (<tt>setfenv()</tt>, hooks),\nit's very hard to get this right even for the Lua core libraries. Of course,\nyou'll need to inspect any extension library, too. And there are libraries\nthat are inherently unsafe, e.g. the <a href=\"ext_ffi.html\">FFI library</a>.<br>\n\nMore reading material at the <a href=\"http://lua-users.org/wiki/SandBoxes\"><span class=\"ext\">&raquo;</span>&nbsp;Lua Wiki</a> and <a href=\"https://en.wikipedia.org/wiki/Sandbox_(computer_security)\"><span class=\"ext\">&raquo;</span>&nbsp;Wikipedia</a>.<br><br>\n\nRelatedly, <b>loading untrusted bytecode is not safe!</b><br>\n\nIt's trivial to crash the Lua or LuaJIT VM with maliciously crafted bytecode.\nThis is well known and there's no bytecode verification on purpose, so please\ndon't report a bug about it. Check the <tt>mode</tt> parameter for the\n<tt>load*()</tt> functions to disable loading of bytecode.<br><br>\n\n<b>In general, the only promising approach is to sandbox Lua code at the\nprocess level and not the VM level.</b>\n</dd>\n</dl>\n\n<dl id=\"arch\">\n<dt>Q: Lua runs everywhere. Why doesn't LuaJIT support my CPU?</dt>\n<dd>Because it's a compiler &mdash; it needs to generate native\nmachine code. This means the code generator must be ported to each\narchitecture. And the fast interpreter is written in assembler and\nmust be ported, too. This is quite an undertaking.<br>\nThe <a href=\"install.html\">install documentation</a> shows the supported\narchitectures.<br>\nOther architectures may follow based on sufficient user demand and\nmarket-relevance of the architecture. Sponsoring is required to develop\nthe port itself, to integrate it and to continuously maintain it in the\nactively developed branches.</dd>\n</dl>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/install.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Installation</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.compat {\n  line-height: 1.2;\n  font-size: 80%;\n}\ntable.compat td {\n  border: 1px solid #bfcfff;\n  height: 2.5em;\n}\ntable.compat tr.compathead td {\n  font-weight: bold;\n  border-bottom: 2px solid #bfcfff;\n}\ntr.compathead td.compatos {\n  vertical-align: top;\n}\ntable.compat td.compatcpu {\n  width: 18%;\n  border-right: 2px solid #bfcfff;\n}\ntd.compatos {\n  width: 21%;\n  vertical-align: middle;\n}\ntd.compatno {\n  background-color: #d0d0d0;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Installation</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a class=\"current\" href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is only distributed as a source package. This page explains\nhow to build and install LuaJIT with different operating systems\nand C&nbsp;compilers.\n</p>\n<p>\nFor the impatient (on POSIX systems):\n</p>\n<pre class=\"code\">\nmake &amp;&amp; sudo make install\n</pre>\n<p>\nLuaJIT currently builds out-of-the box on most systems.\nHere's the compatibility matrix for the supported combinations of\noperating systems, CPUs and compilers:\n</p>\n<table class=\"compat\">\n<tr class=\"compathead\">\n<td class=\"compatcpu\">CPU / OS</td>\n<td class=\"compatos\"><a href=\"#posix\">Linux</a> or<br><a href=\"#android\">Android</a></td>\n<td class=\"compatos\"><a href=\"#posix\">*BSD, Other</a></td>\n<td class=\"compatos\"><a href=\"#posix\">macOS 10.4+</a> or<br><a href=\"#ios\">iOS 3.0+</a></td>\n<td class=\"compatos\"><a href=\"#windows\">Windows 7<br>or later</a></td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"compatcpu\">x86 (32 bit)</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos\">MSVC<br>MinGW, Cygwin</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\">x64 (64 bit)</td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">GCC 4.2+<br>ORBIS (<a href=\"#ps4\">PS4</a>)</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos\">MSVC<br>Durango (<a href=\"#xboxone\">Xbox One</a>)</td>\n</tr>\n<tr class=\"odd\">\n<td class=\"compatcpu\"><a href=\"#cross2\">ARMv5+<br>ARM9E+</a></td>\n<td class=\"compatos\">GCC 4.2+</td>\n<td class=\"compatos\">GCC 4.2+<br>PSP2 (<a href=\"#psvita\">PS VITA</a>)</td>\n<td class=\"compatos\">XCode 5.0+<br>Clang</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\"><a href=\"#cross2\">ARM64<br>ARM64be</a></td>\n<td class=\"compatos\">GCC 4.8+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos\">XCode 6.0+<br>Clang 3.5+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n<tr class=\"odd\">\n<td class=\"compatcpu\"><a href=\"#cross2\">PPC</a></td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos\">GCC 4.3+<br>GCC 4.1 (<a href=\"#ps3\">PS3</a>)</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos\">XEDK (<a href=\"#xbox360\">Xbox 360</a>)</td>\n</tr>\n<tr class=\"even\">\n<td class=\"compatcpu\"><a href=\"#cross2\">MIPS32<br>MIPS64<br>MIPS64r6</a></td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos\">GCC 4.3+</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n<td class=\"compatos compatno\">&nbsp;</td>\n</tr>\n</table>\n\n<h2>Configuring LuaJIT</h2>\n<p>\nThe standard configuration should work fine for most installations.\nUsually there is no need to tweak the settings. The following files\nhold all user-configurable settings:\n</p>\n<ul>\n<li><tt>src/luaconf.h</tt> sets some configuration variables.</li>\n<li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX\nonly).</li>\n<li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT\nunder POSIX, MinGW or Cygwin.</li>\n<li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with\nMSVC (Visual Studio).</li>\n</ul>\n<p>\nPlease read the instructions given in these files, before changing\nany settings.\n</p>\n<p>\nAll LuaJIT 64 bit ports use 64 bit GC objects by default (<tt>LJ_GC64</tt>).\nFor x64, you can select the old 32-on-64 bit mode by adding\n<tt>XCFLAGS=-DLUAJIT_DISABLE_GC64</tt> to the make command.\nPlease check the note about the\n<a href=\"extensions.html#string_dump\">bytecode format</a> differences, too.\n</p>\n\n<h2 id=\"posix\">POSIX Systems (Linux, macOS, *BSD etc.)</h2>\n<h3>Prerequisites</h3>\n<p>\nDepending on your distribution, you may need to install a package for\nGCC, the development headers and/or a complete SDK. E.g. on a current\nDebian/Ubuntu, install <tt>libc6-dev</tt> with the package manager.\n</p>\n<p>\nThe recommended way to fetch the latest version is to do a pull from\nthe git repository.\n</p>\n<p>\nAlternatively download the latest source package of LuaJIT (pick the .tar.gz).\nMove it to a directory of your choice, open a terminal window and change\nto this directory. Now unpack the archive and change to the newly created\ndirectory (replace XX.YY.ZZ with the version you downloaded):\n</p>\n<pre class=\"code\">\ntar zxf LuaJIT-XX.YY.ZZ.tar.gz\ncd LuaJIT-XX.YY.ZZ\n</pre>\n<h3>Building LuaJIT</h3>\n<p>\nThe supplied Makefiles try to auto-detect the settings needed for your\noperating system and your compiler. They need to be run with GNU Make,\nwhich is probably the default on your system, anyway. Simply run:\n</p>\n<pre class=\"code\">\nmake\n</pre>\n<p>\nThis always builds a native binary, depending on the host OS\nyou're running this command on. Check the section on\n<a href=\"#cross\">cross-compilation</a> for more options.\n</p>\n<p>\nBy default, modules are only searched under the prefix <tt>/usr/local</tt>.\nYou can add an extra prefix to the search paths by appending the\n<tt>PREFIX</tt> option, e.g.:\n</p>\n<pre class=\"code\">\nmake PREFIX=/home/myself/lj2\n</pre>\n<p>\nNote for macOS: you <b>must</b> set the <tt>MACOSX_DEPLOYMENT_TARGET</tt>\nenvironment variable to a value supported by your toolchain:\n</p>\n<pre class=\"code\">\nMACOSX_DEPLOYMENT_TARGET=XX.YY make\n</pre>\n<h3>Installing LuaJIT</h3>\n<p>\nThe top-level Makefile installs LuaJIT by default under\n<tt>/usr/local</tt>, i.e. the executable ends up in\n<tt>/usr/local/bin</tt> and so on. You need root privileges\nto write to this path. So, assuming sudo is installed on your system,\nrun the following command and enter your sudo password:\n</p>\n<pre class=\"code\">\nsudo make install\n</pre>\n<p>\nOtherwise specify the directory prefix as an absolute path, e.g.:\n</p>\n<pre class=\"code\">\nmake install PREFIX=/home/myself/lj2\n</pre>\n<p>\nObviously the prefixes given during build and installation need to be the same.\n</p>\n\n<h2 id=\"windows\">Windows Systems</h2>\n<h3>Prerequisites</h3>\n<p>\nEither install one of the open source SDKs\n(<a href=\"http://mingw.org/\"><span class=\"ext\">&raquo;</span>&nbsp;MinGW</a> or\n<a href=\"https://www.cygwin.com/\"><span class=\"ext\">&raquo;</span>&nbsp;Cygwin</a>), which come with a modified\nGCC plus the required development headers.\nOr install Microsoft's Visual Studio (MSVC).\n</p>\n<p>\nNext, pull from the git repository or download the source package and\nunpack it using an archive manager (e.g. the Windows Explorer) to\na directory of your choice.\n</p>\n<h3>Building with MSVC</h3>\n<p>\nOpen a \"Visual Studio Command Prompt\" (either x86 or x64), <tt>cd</tt> to the\ndirectory where you've unpacked the sources and run these commands:\n</p>\n<pre class=\"code\">\ncd src\nmsvcbuild\n</pre>\n<p>\nCheck the <tt>msvcbuild.bat</tt> file for more options.\nThen follow the installation instructions below.\n</p>\n<h3>Building with MinGW or Cygwin</h3>\n<p>\nOpen a command prompt window and make sure the MinGW or Cygwin programs\nare in your path. Then <tt>cd</tt> to the directory of the git repository\nor where you've unpacked the sources. Then run this command for MinGW:\n</p>\n<pre class=\"code\">\nmingw32-make\n</pre>\n<p>\nOr this command for Cygwin:\n</p>\n<pre class=\"code\">\nmake\n</pre>\n<p>\nThen follow the installation instructions below.\n</p>\n<h3>Installing LuaJIT</h3>\n<p>\nCopy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt>\ndirectory) to a newly created directory (any location is ok).\nAdd <tt>lua</tt> and <tt>lua\\jit</tt> directories below it and copy\nall Lua files from the <tt>src\\jit</tt> directory of the distribution\nto the latter directory.\n</p>\n<p>\nThere are no hardcoded\nabsolute path names &mdash; all modules are loaded relative to the\ndirectory where <tt>luajit.exe</tt> is installed\n(see <tt>src/luaconf.h</tt>).\n</p>\n\n<h2 id=\"cross\">Cross-compiling LuaJIT</h2>\n<p>\nFirst, let's clear up some terminology:\n</p>\n<ul>\n<li>Host: This is your development system, usually based on a x64 or x86 CPU.</li>\n<li>Target: This is the target system you want LuaJIT to run on, e.g. Android/ARM.</li>\n<li>Toolchain: This comprises a C compiler, linker, assembler and a matching C library.</li>\n<li>Host (or system) toolchain: This is the toolchain used to build native binaries for your host system.</li>\n<li>Cross-compile toolchain: This is the toolchain used to build binaries for the target system. They can only be run on the target system.</li>\n</ul>\n<p>\nThe GNU Makefile-based build system allows cross-compiling on any host\nfor any supported target:\n</p>\n<ul>\n<li>Yes, you need a toolchain for both your host <em>and</em> your target!</li>\n<li>Both host and target architectures must have the same pointer size.</li>\n<li>E.g. if you want to cross-compile to a 32 bit target on a 64 bit host, you need to install the multilib development package (e.g. <tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part (<tt>HOST_CC=\"gcc -m32\"</tt>).</li>\n<li>64 bit targets always require compilation on a 64 bit host.</li>\n</ul>\n<p>\nYou need to specify <tt>TARGET_SYS</tt> whenever the host OS and the\ntarget OS differ, or you'll get assembler or linker errors:\n</p>\n<ul>\n<li>E.g. if you're compiling on a Windows or macOS host for embedded Linux or Android, you need to add <tt>TARGET_SYS=Linux</tt> to the examples below.</li>\n<li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.</li>\n<li>Don't forget to specify the same <tt>TARGET_SYS</tt> for the install step, too.</li>\n</ul>\n<p>\nHere are some examples where host and target have the same CPU:\n</p>\n<pre class=\"code\">\n# Cross-compile to a 32 bit binary on a multilib x64 OS\nmake CC=\"gcc -m32\"\n\n# Cross-compile on Debian/Ubuntu for Windows (mingw32 package)\nmake HOST_CC=\"gcc -m32\" CROSS=i586-mingw32msvc- TARGET_SYS=Windows\n</pre>\n<p id=\"cross2\">\nThe <tt>CROSS</tt> prefix allows specifying a standard GNU cross-compile\ntoolchain (Binutils, GCC and a matching libc). The prefix may vary\ndepending on the <tt>--target</tt> the toolchain was built for (note the\n<tt>CROSS</tt> prefix has a trailing <tt>\"-\"</tt>). The examples below\nuse the canonical toolchain triplets for Linux.\n</p>\n<p>\nSince there's often no easy way to detect CPU features at runtime, it's\nimportant to compile with the proper CPU or architecture settings:\n</o>\n<ul>\n<li>The best way to get consistent results is to specify the correct settings when building the toolchain yourself.</li>\n<li>For a pre-built, generic toolchain add <tt>-mcpu=...</tt> or <tt>-march=...</tt> and other necessary flags to <tt>TARGET_CFLAGS</tt>.</li>\n<li>For ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting, too. Otherwise LuaJIT may not run at the full performance of your target CPU.</li>\n<li>For MIPS it's important to select a supported ABI (o32 on MIPS32, n64 on MIPS64) and consistently compile your project either with hard-float or soft-float compiler settings.</li>\n</ul>\n<p>\nHere are some examples for targets with a different CPU than the host:\n</p>\n<pre class=\"code\">\n# ARM soft-float\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabi- \\\n     TARGET_CFLAGS=\"-mfloat-abi=soft\"\n\n# ARM soft-float ABI with VFP (example for Cortex-A9)\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabi- \\\n     TARGET_CFLAGS=\"-mcpu=cortex-a9 -mfloat-abi=softfp\"\n\n# ARM hard-float ABI with VFP (armhf, most modern toolchains)\nmake HOST_CC=\"gcc -m32\" CROSS=arm-linux-gnueabihf-\n\n# ARM64\nmake CROSS=aarch64-linux-\n\n# PPC\nmake HOST_CC=\"gcc -m32\" CROSS=powerpc-linux-gnu-\n\n# MIPS32 big-endian\nmake HOST_CC=\"gcc -m32\" CROSS=mips-linux-\n# MIPS32 little-endian\nmake HOST_CC=\"gcc -m32\" CROSS=mipsel-linux-\n\n# MIPS64 big-endian\nmake CROSS=mips-linux- TARGET_CFLAGS=\"-mips64r2 -mabi=64\"\n# MIPS64 little-endian\nmake CROSS=mipsel-linux- TARGET_CFLAGS=\"-mips64r2 -mabi=64\"\n</pre>\n<p>\nYou can cross-compile for <b id=\"android\">Android</b> using the <a href=\"https://developer.android.com/ndk/\"><span class=\"ext\">&raquo;</span>&nbsp;Android NDK</a>.\nPlease adapt the environment variables to match the install locations and the\ndesired target platform. E.g. Android&nbsp;4.1 corresponds to ABI level&nbsp;16.\n</p>\n<pre class=\"code\">\n# Android/ARM64, aarch64, Android 5.0+ (L)\nNDKDIR=/opt/android/ndk\nNDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin\nNDKCROSS=$NDKBIN/aarch64-linux-android-\nNDKCC=$NDKBIN/aarch64-linux-android21-clang\nmake CROSS=$NDKCROSS \\\n     STATIC_CC=$NDKCC DYNAMIC_CC=\"$NDKCC -fPIC\" \\\n     TARGET_LD=$NDKCC TARGET_AR=$NDKBIN/llvm-ar\n     TARGET_STRIP=$NDKBIN/llvm-strip\n\n# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB)\nNDKDIR=/opt/android/ndk\nNDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin\nNDKCROSS=$NDKBIN/arm-linux-androideabi-\nNDKCC=$NDKBIN/armv7a-linux-androideabi16-clang\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKCROSS \\\n     STATIC_CC=$NDKCC DYNAMIC_CC=\"$NDKCC -fPIC\" \\\n     TARGET_LD=$NDKCC TARGET_AR=$NDKBIN/llvm-ar\n     TARGET_STRIP=$NDKBIN/llvm-strip\n</pre>\n<p>\nYou can cross-compile for <b id=\"ios\">iOS 3.0+</b> (iPhone/iPad) using the <a href=\"https://developer.apple.com/ios/\"><span class=\"ext\">&raquo;</span>&nbsp;iOS SDK</a>:\n</p>\n<p style=\"font-size: 8pt;\">\nNote: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps\nare not allowed to generate code at runtime. You'll only get the performance\nof the LuaJIT interpreter on iOS. This is still faster than plain Lua, but\nmuch slower than the JIT compiler. Please complain to Apple, not me.\nOr use Android. :-p\n</p>\n<pre class=\"code\">\n# iOS/ARM64\nISDKP=$(xcrun --sdk iphoneos --show-sdk-path)\nICC=$(xcrun --sdk iphoneos --find clang)\nISDKF=\"-arch arm64 -isysroot $ISDKP\"\nmake DEFAULT_CC=clang CROSS=\"$(dirname $ICC)/\" \\\n     TARGET_FLAGS=\"$ISDKF\" TARGET_SYS=iOS\n</pre>\n\n<h3 id=\"consoles\">Cross-compiling for consoles</h3>\n<p>\nBuilding LuaJIT for consoles requires both a supported host compiler\n(x86 or x64) and a cross-compiler (to PPC or ARM) from the official\nconsole SDK.\n</p>\n<p>\nDue to restrictions on consoles, the JIT compiler is disabled and only\nthe fast interpreter is built. This is still faster than plain Lua,\nbut much slower than the JIT compiler. The FFI is disabled, too, since\nit's not very useful in such an environment.\n</p>\n<p>\nThe following commands build a static library <tt>libluajit.a</tt>,\nwhich can be linked against your game, just like the Lua library.\n</p>\n<p>\nTo cross-compile for <b id=\"ps3\">PS3</b> from a Linux host (requires\n32&nbsp;bit GCC, i.e. multilib Linux/x64) or a Windows host (requires\n32&nbsp;bit MinGW), run this command:\n</p>\n<pre class=\"code\">\nmake HOST_CC=\"gcc -m32\" CROSS=ppu-lv2-\n</pre>\n<p>\nTo cross-compile for <b id=\"ps4\">PS4</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (64&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and\nrun the following commands:\n</p>\n<pre class=\"code\">\ncd src\nps4build\n</pre>\n<p>\nTo cross-compile for <b id=\"psvita\">PS Vita</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (32&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and\nrun the following commands:\n</p>\n<pre class=\"code\">\ncd src\npsvitabuild\n</pre>\n<p>\nTo cross-compile for <b id=\"xbox360\">Xbox 360</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (32&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and run\nthe following commands:\n</p>\n<pre class=\"code\">\ncd src\nxedkbuild\n</pre>\n<p>\nTo cross-compile for <b id=\"xboxone\">Xbox One</b> from a Windows host,\nopen a \"Visual Studio .NET Command Prompt\" (64&nbsp;bit host compiler),\n<tt>cd</tt> to the directory where you've unpacked the sources and run\nthe following commands:\n</p>\n<pre class=\"code\">\ncd src\nxb1build\n</pre>\n\n<h2 id=\"embed\">Embedding LuaJIT</h2>\n<p>\nLuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua\ninto your application, you probably don't need to do anything to switch\nto LuaJIT, except link with a different library:\n</p>\n<ul>\n<li>It's strongly suggested to build LuaJIT separately using the supplied\nbuild system. Please do <em>not</em> attempt to integrate the individual\nsource files into your build tree. You'll most likely get the internal build\ndependencies wrong or mess up the compiler flags. Treat LuaJIT like any\nother external library and link your application with either the dynamic\nor static library, depending on your needs.</li>\n<li>If you want to load C modules compiled for plain Lua\nwith <tt>require()</tt>, you need to make sure the public symbols\n(e.g. <tt>lua_pushnumber</tt>) are exported, too:\n<ul><li>On POSIX systems you can either link to the shared library\nor link the static library into your application. In the latter case\nyou'll need to export all public symbols from your main executable\n(e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies\n(e.g. <tt>-lm -ldl</tt> on Linux).</li>\n<li>Since Windows symbols are bound to a specific DLL name, you need to\nlink to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename\nthe DLL). You may link LuaJIT statically on Windows only if you don't\nintend to load Lua/C modules at runtime.\n</li></ul>\n</li>\n</ul>\n<p>Additional hints for initializing LuaJIT using the C API functions:</p>\n<ul>\n<li>Here's a\n<a href=\"http://lua-users.org/wiki/SimpleLuaApiExample\"><span class=\"ext\">&raquo;</span>&nbsp;simple example</a>\nfor embedding Lua or LuaJIT into your application.</li>\n<li>Make sure you use <tt>luaL_newstate</tt>. Avoid using\n<tt>lua_newstate</tt>, since this uses the (slower) default memory\nallocator from your system (no support for this on 64&nbsp;bit architectures).</li>\n<li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style\nof calling <tt>luaopen_base</tt> etc. directly.</li>\n<li>To change or extend the list of standard libraries to load, copy\n<tt>src/lib_init.c</tt> to your project and modify it accordingly.\nMake sure the <tt>jit</tt> library is loaded or the JIT compiler\nwill not be activated.</li>\n<li>The <tt>bit.*</tt> module for bitwise operations\nis already built-in. There's no need to statically link\n<a href=\"https://bitop.luajit.org/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua BitOp</a> to your application.</li>\n</ul>\n\n<h2 id=\"distro\">Hints for Distribution Maintainers</h2>\n<p>\nThe LuaJIT build system has extra provisions for the needs of most\nPOSIX-based distributions. If you're a package maintainer for\na distribution, <em>please</em> make use of these features and\navoid patching, subverting, autotoolizing or messing up the build system\nin unspeakable ways.\n</p>\n<p>\nThere should be absolutely no need to patch <tt>luaconf.h</tt> or any\nof the Makefiles. And please do not hand-pick files for your packages &mdash;\nsimply use whatever <tt>make install</tt> creates. There's a reason\nfor all of the files <em>and</em> directories it creates.\n</p>\n<p>\nThe build system uses GNU make and auto-detects most settings based on\nthe host you're building it on. This should work fine for native builds,\neven when sandboxed. You may need to pass some of the following flags to\n<em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines\nfor a regular distribution build:\n</p>\n<ul>\n<li><tt>PREFIX</tt> overrides the installation path and should usually\nbe set to <tt>/usr</tt>. Setting this also changes the module paths and\nthe paths needed to locate the shared library.</li>\n<li><tt>DESTDIR</tt> is an absolute path which allows you to install\nto a shadow tree instead of the root tree of the build system.</li>\n<li><tt>MULTILIB</tt> sets the architecture-specific library path component\nfor multilib systems. The default is <tt>lib</tt>.</li>\n<li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt>\nfor additional variables to tweak. The following variables <em>may</em> be\noverridden, but it's <em>not</em> recommended, except for special needs\nlike cross-builds:\n<tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,\nTARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,\nTARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS\n</tt></li>\n</ul>\n<p>\nThe build system has a special target for an amalgamated build, i.e.\n<tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file\nand allows GCC to generate faster and shorter code. Alas, this requires\nlots of memory during the build. This may be a problem for some users,\nthat's why it's not enabled by default. But it shouldn't be a problem for\nmost build farms. It's recommended that binary distributions use this\ntarget for their LuaJIT builds.\n</p>\n<p>\nThe tl;dr version of the above:\n</p>\n<pre class=\"code\">\nmake amalg PREFIX=/usr && \\\nmake install PREFIX=/usr DESTDIR=/tmp/buildroot\n</pre>\n<p>\nFinally, if you encounter any difficulties, please\n<a href=\"contact.html\">contact me</a> first, instead of releasing a broken\npackage onto unsuspecting users. Because they'll usually gonna complain\nto me (the upstream) and not you (the package maintainer), anyway.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/luajit.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>LuaJIT</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<meta name=\"description\" content=\"LuaJIT is a Just-In-Time (JIT) compiler for the Lua language.\">\n<style type=\"text/css\">\ntable.feature {\n  width: inherit;\n  line-height: 1.2;\n  margin: 0;\n}\ntable.feature td {\n  width: 80px;\n  height: 40px;\n  vertical-align: middle;\n  text-align: center;\n  font-weight: bold;\n  border: 4px solid #e6ecff;\n  border-radius: 12px;\n}\ntable.os td {\n  background: #7080d0;\n  background-image: linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -moz-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -webkit-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -o-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n  background-image: -ms-linear-gradient(#4060c0 10%, #b0b0ff 95%);\n}\ntable.os1 td {\n  color: #ffff80;\n}\ntable.os2 td {\n  color: #ffa040;\n}\ntable.os3 td {\n  color: #40ffff;\n}\ntable.compiler td {\n  color: #2080ff;\n  background: #62bf41;\n  background-image: linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -moz-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -webkit-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -o-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n  background-image: -ms-linear-gradient(#62bf41 10%, #b0ffb0 95%);\n}\ntable.cpu td {\n  color: #ffff00;\n  background: #cf7251;\n  background-image: linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -moz-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -webkit-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -o-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n  background-image: -ms-linear-gradient(#bf6241 10%, #ffb0b0 95%);\n}\ntable.fcompat td {\n  color: #2060e0;\n  background: #61cfcf;\n  background-image: linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -moz-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -webkit-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -o-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n  background-image: -ms-linear-gradient(#41bfbf 10%, #b0ffff 95%);\n}\ntable.stats td {\n  color: #ffffff;\n  background: #a0a0a0;\n  background-image: linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -moz-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -webkit-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -o-linear-gradient(#808080 10%, #d0d0d0 95%);\n  background-image: -ms-linear-gradient(#808080 10%, #d0d0d0 95%);\n}\ntable.stats td.speed {\n  color: #ff4020;\n}\ntable.stats td.kb {\n  color: #ffff80;\n  background: #808080;\n  background-image: linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -moz-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -webkit-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -o-linear-gradient(#606060 10%, #c0c0c0 95%);\n  background-image: -ms-linear-gradient(#606060 10%, #c0c0c0 95%);\n}\ntable.feature small {\n  font-size: 50%;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>LuaJIT</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a class=\"current\" href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT is a <b>Just-In-Time Compiler</b> (JIT) for the\n<a href=\"https://www.lua.org/\"><span class=\"ext\">&raquo;</span>&nbsp;Lua</a> programming language.\nLua is a powerful, dynamic and light-weight programming language.\nIt may be embedded or used as a general-purpose, stand-alone language.\n</p>\n<p>\nLuaJIT is Copyright &copy; 2005-2021 Mike Pall, released under the\n<a href=\"https://www.opensource.org/licenses/mit-license.php\"><span class=\"ext\">&raquo;</span>&nbsp;MIT open source license</a>.\n</p>\n<p>\n</p>\n\n<h2>Compatibility</h2>\n<table class=\"feature os os1\">\n<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>macOS</td><td>POSIX</td></tr>\n</table>\n<table class=\"feature os os2\">\n<tr><td><span style=\"font-size:90%;\">Embedded</span></td><td>Android</td><td>iOS</td></tr>\n</table>\n<table class=\"feature os os3\">\n<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr>\n</table>\n<table class=\"feature compiler\">\n<tr><td>GCC</td><td>Clang<br>LLVM</td><td>MSVC</td></tr>\n</table>\n<table class=\"feature cpu\">\n<tr><td>x86<br>x64</td><td>ARM<br>ARM64</td><td>PPC</td><td>MIPS32<br>MIPS64</td></tr>\n</table>\n<table class=\"feature fcompat\">\n<tr><td>Lua&nbsp;5.1<br>API+ABI</td><td>+&nbsp;JIT</td><td>+&nbsp;BitOp</td><td>+&nbsp;FFI</td><td>Drop-in<br>DLL/.so</td></tr>\n</table>\n\n<h2>Overview</h2>\n<table class=\"feature stats\">\n<tr>\n<td class=\"speed\">3x<br>-&nbsp;&nbsp;100x</td>\n<td class=\"kb\">115&nbsp;<small>KB</small><br>VM</td>\n<td class=\"kb\">90&nbsp;<small>KB</small><br>JIT</td>\n<td class=\"kloc\">63&nbsp;<small>KLOC</small><br>C</td>\n<td class=\"kloc\">24&nbsp;<small>KLOC</small><br>ASM</td>\n<td class=\"kloc\">11&nbsp;<small>KLOC</small><br>Lua</td>\n</tr>\n</table>\n<p style=\"margin-top: 1em;\">\nLuaJIT has been successfully used as a <b>scripting middleware</b> in\ngames, appliances, network and graphics apps, numerical simulations,\ntrading platforms and many other specialty applications. It scales from\nembedded devices, smartphones, desktops up to server farms. It combines\nhigh flexibility with high performance\nand an unmatched <b>low memory footprint</b>.\n</p>\n<p>\nLuaJIT has been in continuous development since 2005. It's widely\nconsidered to be <b>one of the fastest dynamic language\nimplementations</b>. It has outperformed other dynamic languages on many\ncross-language benchmarks since its first release &mdash; often by a\nsubstantial margin.\n</p>\n<p>\nFor <b>LuaJIT 2.0</b>, the whole VM has been rewritten from the ground up\nand relentlessly optimized for performance. It combines a <b>high-speed\ninterpreter</b>, written in assembler, with a <b>state-of-the-art JIT\ncompiler</b>.\n</p>\n<p>\nAn innovative <b>trace compiler</b> is integrated with advanced,\nSSA-based optimizations and highly tuned code generation backends.\nA substantial reduction of the overhead associated with dynamic languages\nallows it to break into the performance range traditionally reserved for\noffline, static language compilers.\n</p>\n\n<h2>More ...</h2>\n<p>\nPlease select a sub-topic in the navigation bar to learn more about LuaJIT.\n</p>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/running.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Running LuaJIT</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\ntable.opt {\n  line-height: 1.2;\n}\ntr.opthead td {\n  font-weight: bold;\n}\ntd.flag_name {\n  width: 4em;\n}\ntd.flag_level {\n  width: 2em;\n  text-align: center;\n}\ntd.param_name {\n  width: 6em;\n}\ntd.param_default {\n  width: 4em;\n  text-align: right;\n}\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Running LuaJIT</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a class=\"current\" href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nLuaJIT has only a single stand-alone executable, called <tt>luajit</tt> on\nPOSIX systems or <tt>luajit.exe</tt> on Windows. It can be used to run simple\nLua statements or whole Lua applications from the command line. It has an\ninteractive mode, too.\n</p>\n\n<h2 id=\"options\">Command Line Options</h2>\n<p>\nThe <tt>luajit</tt> stand-alone executable is just a slightly modified\nversion of the regular <tt>lua</tt> stand-alone executable.\nIt supports the same basic options, too. <tt>luajit&nbsp;-h</tt>\nprints a short list of the available options. Please have a look at the\n<a href=\"https://www.lua.org/manual/5.1/manual.html#6\"><span class=\"ext\">&raquo;</span>&nbsp;Lua manual</a>\nfor details.\n</p>\n<p>\nLuaJIT has some additional options:\n</p>\n\n<h3 id=\"opt_b\"><tt>-b[options] input output</tt></h3>\n<p>\nThis option saves or lists bytecode. The following additional options\nare accepted:\n</p>\n<ul>\n<li><tt>-l</tt> &mdash; Only list bytecode.</li>\n<li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>\n<li><tt>-g</tt> &mdash; Keep debug info.</li>\n<li><tt>-n name</tt> &mdash; Set module name (default: auto-detect from input name)</li>\n<li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>\n<li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>\n<li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li>\n<li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>\n<li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>\n</ul>\n<p>\nThe output file type is auto-detected from the extension of the output\nfile name:\n</p>\n<ul>\n<li><tt>c</tt> &mdash; C source file, exported bytecode data.</li>\n<li><tt>h</tt> &mdash; C header file, static bytecode data.</li>\n<li><tt>obj</tt> or <tt>o</tt> &mdash; Object file, exported bytecode data\n(OS- and architecture-specific).</li>\n<li><tt>raw</tt> or any other extension &mdash; Raw bytecode file (portable).\n</ul>\n<p>\nNotes:\n</p>\n<ul>\n<li>See also <a href=\"extensions.html#string_dump\">string.dump()</a>\nfor information on bytecode portability and compatibility.</li>\n<li>A file in raw bytecode format is auto-detected and can be loaded like\nany Lua source file. E.g. directly from the command line or with\n<tt>loadfile()</tt>, <tt>dofile()</tt> etc.</li>\n<li>To statically embed the bytecode of a module in your application,\ngenerate an object file and just link it with your application.</li>\n<li>On most ELF-based systems (e.g. Linux) you need to explicitly export the\nglobal symbols when linking your application, e.g. with: <tt>-Wl,-E</tt></li>\n<li><tt>require()</tt> tries to load embedded bytecode data from exported\nsymbols (in <tt>*.exe</tt> or <tt>lua51.dll</tt> on Windows) and from\nshared libraries in <tt>package.cpath</tt>.</li>\n</ul>\n<p>\nTypical usage examples:\n</p>\n<pre class=\"code\">\nluajit -b test.lua test.out                 # Save bytecode to test.out\nluajit -bg test.lua test.out                # Keep debug info\nluajit -be \"print('hello world')\" test.out  # Save cmdline script\n\nluajit -bl test.lua                         # List to stdout\nluajit -bl test.lua test.txt                # List to test.txt\nluajit -ble \"print('hello world')\"          # List cmdline script\n\nluajit -b test.lua test.obj                 # Generate object file\n# Link test.obj with your application and load it with require(\"test\")\n</pre>\n\n<h3 id=\"opt_j\"><tt>-j cmd[=arg[,arg...]]</tt></h3>\n<p>\nThis option performs a LuaJIT control command or activates one of the\nloadable extension modules. The command is first looked up in the\n<tt>jit.*</tt> library. If no matching function is found, a module\nnamed <tt>jit.&lt;cmd&gt;</tt> is loaded and the <tt>start()</tt>\nfunction of the module is called with the specified arguments (if\nany). The space between <tt>-j</tt> and <tt>cmd</tt> is optional.\n</p>\n<p>\nHere are the available LuaJIT control commands:\n</p>\n<ul>\n<li id=\"j_on\"><tt>-jon</tt> &mdash; Turns the JIT compiler on (default).</li>\n<li id=\"j_off\"><tt>-joff</tt> &mdash; Turns the JIT compiler off (only use the interpreter).</li>\n<li id=\"j_flush\"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>\n<li id=\"j_v\"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>\n<li id=\"j_dump\"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>\n<li id=\"j_p\"><tt>-jp</tt> &mdash; Start the <a href=\"ext_profiler.html\">integrated profiler</a>.</li>\n</ul>\n<p>\nThe <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules\nwritten in Lua. They are mainly used for debugging the JIT compiler\nitself. For a description of their options and output format, please\nread the comment block at the start of their source.\nThey can be found in the <tt>lib</tt> directory of the source\ndistribution or installed under the <tt>jit</tt> directory. By default\nthis is <tt>/usr/local/share/luajit-XX.YY.ZZ>/jit</tt> on POSIX\nsystems (replace XX.YY.ZZ by the installed version).\n</p>\n\n<h3 id=\"opt_O\"><tt>-O[level]</tt><br>\n<tt>-O[+]flag</tt>&nbsp;&nbsp;&nbsp;<tt>-O-flag</tt><br>\n<tt>-Oparam=value</tt></h3>\n<p>\nThis options allows fine-tuned control of the optimizations used by\nthe JIT compiler. This is mainly intended for debugging LuaJIT itself.\nPlease note that the JIT compiler is extremely fast (we are talking\nabout the microsecond to millisecond range). Disabling optimizations\ndoesn't have any visible impact on its overhead, but usually generates\ncode that runs slower.\n</p>\n<p>\nThe first form sets an optimization level &mdash; this enables a\nspecific mix of optimization flags. <tt>-O0</tt> turns off all\noptimizations and higher numbers enable more optimizations. Omitting\nthe level (i.e. just <tt>-O</tt>) sets the default optimization level,\nwhich is <tt>-O3</tt> in the current version.\n</p>\n<p>\nThe second form adds or removes individual optimization flags.\nThe third form sets a parameter for the VM or the JIT compiler\nto a specific value.\n</p>\n<p>\nYou can either use this option multiple times (like <tt>-Ocse\n-O-dce -Ohotloop=10</tt>) or separate several settings with a comma\n(like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from\nleft to right and later settings override earlier ones. You can freely\nmix the three forms, but note that setting an optimization level\noverrides all earlier flags.\n</p>\n<p>\nHere are the available flags and at what optimization levels they\nare enabled:\n</p>\n<table class=\"opt\">\n<tr class=\"opthead\">\n<td class=\"flag_name\">Flag</td>\n<td class=\"flag_level\">-O1</td>\n<td class=\"flag_level\">-O2</td>\n<td class=\"flag_level\">-O3</td>\n<td class=\"flag_desc\">&nbsp;</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"flag_name\">fold</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Constant Folding, Simplifications and Reassociation</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">cse</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Common-Subexpression Elimination</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">dce</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Dead-Code Elimination</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">narrow</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Narrowing of numbers to integers</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">loop</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Loop Optimizations (code hoisting)</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">fwd</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Load Forwarding (L2L) and Store Forwarding (S2L)</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">dse</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Dead-Store Elimination</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">abc</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Array Bounds Check Elimination</td></tr>\n<tr class=\"odd\">\n<td class=\"flag_name\">sink</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Allocation/Store Sinking</td></tr>\n<tr class=\"even\">\n<td class=\"flag_name\">fuse</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&nbsp;</td><td class=\"flag_level\">&bull;</td><td class=\"flag_desc\">Fusion of operands into instructions</td></tr>\n</table>\n<p>\nHere are the parameters and their default settings:\n</p>\n<table class=\"opt\">\n<tr class=\"opthead\">\n<td class=\"param_name\">Parameter</td>\n<td class=\"param_default\">Default</td>\n<td class=\"param_desc\">&nbsp;</td>\n</tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">maxtrace</td><td class=\"param_default\">1000</td><td class=\"param_desc\">Max. number of traces in the cache</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxrecord</td><td class=\"param_default\">4000</td><td class=\"param_desc\">Max. number of recorded IR instructions</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">maxirconst</td><td class=\"param_default\">500</td><td class=\"param_desc\">Max. number of IR constants of a trace</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxside</td><td class=\"param_default\">100</td><td class=\"param_desc\">Max. number of side traces of a root trace</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">maxsnap</td><td class=\"param_default\">500</td><td class=\"param_desc\">Max. number of snapshots for a trace</td></tr>\n<tr class=\"even separate\">\n<td class=\"param_name\">hotloop</td><td class=\"param_default\">56</td><td class=\"param_desc\">Number of iterations to detect a hot loop or hot call</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">hotexit</td><td class=\"param_default\">10</td><td class=\"param_desc\">Number of taken exits to start a side trace</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">tryside</td><td class=\"param_default\">4</td><td class=\"param_desc\">Number of attempts to compile a side trace</td></tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">instunroll</td><td class=\"param_default\">4</td><td class=\"param_desc\">Max. unroll factor for instable loops</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">loopunroll</td><td class=\"param_default\">15</td><td class=\"param_desc\">Max. unroll factor for loop ops in side traces</td></tr>\n<tr class=\"odd\">\n<td class=\"param_name\">callunroll</td><td class=\"param_default\">3</td><td class=\"param_desc\">Max. unroll factor for pseudo-recursive calls</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">recunroll</td><td class=\"param_default\">2</td><td class=\"param_desc\">Min. unroll factor for true recursion</td></tr>\n<tr class=\"odd separate\">\n<td class=\"param_name\">sizemcode</td><td class=\"param_default\">32</td><td class=\"param_desc\">Size of each machine code area in KBytes (Windows: 64K)</td></tr>\n<tr class=\"even\">\n<td class=\"param_name\">maxmcode</td><td class=\"param_default\">512</td><td class=\"param_desc\">Max. total size of all machine code areas in KBytes</td></tr>\n</table>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/doc/status.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n<title>Status</title>\n<meta charset=\"utf-8\">\n<meta name=\"Copyright\" content=\"Copyright (C) 2005-2021\">\n<meta name=\"Language\" content=\"en\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad.css\" media=\"screen\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"bluequad-print.css\" media=\"print\">\n<style type=\"text/css\">\nul li { padding-bottom: 0.3em; }\n</style>\n</head>\n<body>\n<div id=\"site\">\n<a href=\"https://luajit.org\"><span>Lua<span id=\"logo\">JIT</span></span></a>\n</div>\n<div id=\"head\">\n<h1>Status</h1>\n</div>\n<div id=\"nav\">\n<ul><li>\n<a href=\"luajit.html\">LuaJIT</a>\n<ul><li>\n<a href=\"https://luajit.org/download.html\">Download <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"install.html\">Installation</a>\n</li><li>\n<a href=\"running.html\">Running</a>\n</li></ul>\n</li><li>\n<a href=\"extensions.html\">Extensions</a>\n<ul><li>\n<a href=\"ext_ffi.html\">FFI Library</a>\n<ul><li>\n<a href=\"ext_ffi_tutorial.html\">FFI Tutorial</a>\n</li><li>\n<a href=\"ext_ffi_api.html\">ffi.* API</a>\n</li><li>\n<a href=\"ext_ffi_semantics.html\">FFI Semantics</a>\n</li></ul>\n</li><li>\n<a href=\"ext_buffer.html\">String Buffers</a>\n</li><li>\n<a href=\"ext_jit.html\">jit.* Library</a>\n</li><li>\n<a href=\"ext_c_api.html\">Lua/C API</a>\n</li><li>\n<a href=\"ext_profiler.html\">Profiler</a>\n</li></ul>\n</li><li>\n<a class=\"current\" href=\"status.html\">Status</a>\n</li><li>\n<a href=\"faq.html\">FAQ</a>\n</li><li>\n<a href=\"http://wiki.luajit.org/\">Wiki <span class=\"ext\">&raquo;</span></a>\n</li><li>\n<a href=\"https://luajit.org/list.html\">Mailing List <span class=\"ext\">&raquo;</span></a>\n</li></ul>\n</div>\n<div id=\"main\">\n<p>\nThis documentation is for LuaJIT 2.1.0-beta3. Please check the <tt>doc</tt>\ndirectory in each git branch for the version-specific documentation.\n</p>\n<p>\nThe currently developed branches are LuaJIT&nbsp;2.1 and LuaJIT&nbsp;2.0.\n</p>\n<p>\nLuaJIT&nbsp;2.0 is in feature-freeze &mdash; new features will only\nbe added to LuaJIT&nbsp;2.1.\n</p>\n\n<h2>Current Status</h2>\n<p>\nLuaJIT ought to run all Lua&nbsp;5.1-compatible source code just fine.\nIt's considered a serious bug if the VM crashes or produces unexpected\nresults &mdash; please report this.\n</p>\n<p>\nKnown incompatibilities and issues in LuaJIT&nbsp;2.0:\n</p>\n<ul>\n<li>\nThere are some differences in <b>implementation-defined</b> behavior.\nThese either have a good reason, are arbitrary design choices\nor are due to quirks in the VM. The latter cases may get fixed if a\ndemonstrable need is shown.\n</li>\n<li>\nThe Lua <b>debug API</b> is missing a couple of features (return\nhooks for non-Lua functions) and shows slightly different behavior\nin LuaJIT (no per-coroutine hooks, no tail call counting).\n</li>\n</ul>\n<br class=\"flush\">\n</div>\n<div id=\"foot\">\n<hr class=\"hide\">\nCopyright &copy; 2005-2021\n<span class=\"noprint\">\n&middot;\n<a href=\"contact.html\">Contact</a>\n</span>\n</div>\n</body>\n</html>\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/Examples/run.sh",
    "content": "#!/bin/bash\n# set -x\n\n# run test\nlua ../dynasm.lua test_z_inst.c | gcc -DDASM_CHECKS -std=gnu99 -Wall -Werror -g -x c -o test_z_inst -\n./test_z_inst\nec=$?\n\n# cleanup\nrm -f ./test_z_inst\n\n# exit\nexit $ec\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/Examples/test_z_inst.c",
    "content": "#include <assert.h>\n#include <stdio.h>\n#include <sys/mman.h>\n\n#include \"../dasm_proto.h\"\n#include \"../dasm_s390x.h\"\n\n// DynASM directives.\n|.arch s390x\n|.actionlist actions\n|.globals lab_\n\nstatic void add(dasm_State *state)\n{\n  dasm_State ** Dst = &state;\n\n  | ar r2,r3\n  | br r14\n}\n\n/*\nstatic void add_rrd(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n  \n  | lgfi r4 , 0x02\n  | maer r2 , r3 , r4\n  | br r14\n}\n*/\n\nstatic void sub(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  | sr r2,r3\n  | br r14\n}\n\nstatic void mul(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  | msr r2 , r3\n  | br r14\n}\n\nstatic void rx(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  int x = 1;\n  int y = 4095;\n\n  | la r4, 4095(r2, r3)\n  | la r5, 4095(r4)\n  | la r1, x(r5)\n  | la r2, y(r1, r0)\n  | br r14\n}\n\nstatic void rxy(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  int x = -524287;\n  int y = 524286;\n\n  | lay r4, -524288(r2, r3)\n  | lay r5, 524287(r4)\n  | lay r1, x(r5)\n  | lay r2, y(r1, r0)\n  | br r14\n}\n\nstatic void lab(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  // r1 = 0; do { r2 += r2; r1 += 1; } while(r1 < r3);\n  | la r1, 0(r0)\n  |1:\n  | agr r2, r2\n  | la r1, 1(r1)\n  | cgr r1, r3\n  | jl <1\n  | br r14\n}\n\nstatic void labg(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  // r1 = 0; do { r2 += r2; r1 += 1; } while(r1 < r3);\n  | la r1, 0(r0)\n  |1:\n  | agr r2, r2\n  | la r1, 1(r1)\n  | cgr r1, r3\n  | jgl <1\n  | jgnl >1\n  | stg r0, 0(r0)\n  |1:\n  | br r14\n}\n\nstatic void jmp_fwd(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n  \n  // while(r2!=r3){r2 += 2};\n  | j >1\n  |1:\n  | cgr r2 , r3\n  | jne >2\n  | je >3\n  |2:\n  | afi r2, 0x2\n  | j <1\n  |3:\n  | br r14\n\n}\n\nstatic void add_imm16(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n  \n  | ahi r2 , 0xf\n  | br r14\n}\n\nstatic void add_imm32(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n  \n  | afi r2 , 0xe\n  | br r14\n}\n\nstatic void save(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  |.define CFRAME_SPACE,\t224\t// Delta for sp, 8 byte aligned.\n  |\n  |// Register save area.\n  |.define SAVE_GPRS,\t264(sp)\t// Save area for r6-r15 (10*8 bytes).\n  |\n  |// Argument save area, each slot is 8-bytes (32-bit types are sign/zero extended).\n  |.define RESERVED,\t232(sp)\t// Reserved for compiler use.\n  |.define BACKCHAIN,\t224(sp)\n  |\n  |// Current stack frame.\n  |.define SAVE_FPR15,\t216(sp)\n  |.define SAVE_FPR14,\t208(sp)\n  |.define SAVE_FPR13,\t200(sp)\n  |.define SAVE_FPR12,\t192(sp)\n  |.define SAVE_FPR11,\t184(sp)\n  |.define SAVE_FPR10,\t176(sp)\n  |.define SAVE_FPR9,\t168(sp)\n  |.define SAVE_FPR8,\t160(sp)\n  |\n  |// Callee save area.\n  |.define CALLEESAVE,\t000(sp)\n  |\n  |.macro saveregs\n  |  lay sp, -CFRAME_SPACE(sp)\t// Allocate stack frame.\n  |  stmg r6, r15, SAVE_GPRS\t// Technically we restore r15 regardless.\n  |  std f8, SAVE_FPR8\t\t// f8-f15 are callee-saved.\n  |  std f9, SAVE_FPR9\n  |  std f10, SAVE_FPR10\n  |  std f11, SAVE_FPR11\n  |  std f12, SAVE_FPR12\n  |  std f13, SAVE_FPR13\n  |  std f14, SAVE_FPR14\n  |  std f15, SAVE_FPR15\n  |.endmacro\n  |\n  |.macro restoreregs\n  |  ld f8, SAVE_FPR8\t\t// f8-f15 are callee-saved.\n  |  ld f9, SAVE_FPR9\n  |  ld f10, SAVE_FPR10\n  |  ld f11, SAVE_FPR11\n  |  ld f12, SAVE_FPR12\n  |  ld f13, SAVE_FPR13\n  |  ld f14, SAVE_FPR14\n  |  ld f15, SAVE_FPR15\n  |  lmg r6, r15, SAVE_GPRS\t// Restores the stack pointer.\n  |.endmacro\n  |\n  | saveregs\n  | lgfi r7, 0x10 // 16\n  | lgfi r8, 0x20 // 32\n  | agr r2, r3\n  | agr r7, r8\n  | msgr r2, r7\n  | restoreregs\n  | br r14\n}\n\nstatic void labmul(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  // Multiply using an add function.\n  // Only correct if input is positive.\n  |->mul_func:\n  | stmg r6, r14, 48(sp)\n  | lgr r6, r2\n  | lgr r7, r3\n  | cgfi r7, 0\n  | je >3\n  | cgfi r7, 1\n  | je >2\n  |1:\n  | lgr r3, r6\n  | brasl r14, ->add_func\n  | lay r7, -1(r7)\n  | cgfi r7, 1\n  | jh <1\n  |2:\n  | lmg r6, r14, 48(sp)\n  | br r14\n  |3:\n  | la r2, 0(r0)\n  | j <2\n\n  |->add_func:\n  | agr r2, r3\n  | br r14\n}\n\nstatic void pc(dasm_State *state) {\n  dasm_State **Dst = &state;\n  int MAX = 10;\n  dasm_growpc(Dst, MAX+1);\n\n  | j =>MAX\n  for (int i = 0; i <= MAX; i++) {\n    |=>i:\n    if (i == 0) {\n      | br r14\n    } else {\n      | aghi r2, i\n      | j =>i-1\n    }\n  }\n}\n\n/*\nstatic void load_test(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n  \n  | ltdr r2 , r3\n  | br r14\n}\n*/\n\n\nstatic void test_mask(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  |lay   sp , -8(sp)\n  |stg   r2,  4(sp)\n  |tm    4(sp),0x04\n  |je >2\n  |jne >1\n|1:\n  |ar r2,r3\n  |br r14\n|2:\n  |sr r2,r3\n  |br r14\n}\n\nstatic void ssa(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  | lay sp, -16(sp)\n  | lay r0, -1(r0)\n  | stg r0, 8(sp)\n  | xc 8(8, sp), 8(sp)\n  | stg r2, 0(sp)\n  | mvc 13(2, sp), 6(sp)\n  | lg r2, 8(sp)\n  | la sp, 16(sp)\n  | br r14\n}\n\nstatic void ssa_act(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  int xl = 8;\n  int d1 = 13;\n  int l1 = 2;\n  int d2 = 6;\n\n  | lay sp, -16(sp)\n  | lay r0, -1(r0)\n  | stg r0, 8(sp)\n  | xc 8(xl, sp), 8(sp)\n  | stg r2, 0(sp)\n  | mvc d1(l1, sp), d2(sp)\n  | lg r2, 8(sp)\n  | la sp, 16(sp)\n  | br r14\n}\n\ntypedef struct {\n  int a;\n  int b;\n} SimpleStruct;\n\nstatic void type(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  | .type SIMPLE, SimpleStruct\n  | lay sp, -8(sp)\n  | stg r2, 0(sp)\n  | xgr r2, r2\n  | l r2, SIMPLE:sp->b\n  | la sp, 8(sp)\n  | br r14\n}\n\nstatic void sil(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  | lay sp, -16(sp)\n  | xc 0(16, sp), 0(sp)\n  | mvghi 0(sp), 5\n  | mvhi 8(sp), 7\n  | mvhhi 12(sp), 11\n  | lghi r2, 0\n  | ag r2, 0(sp)  // r2 += 5\n  | a r2, 8(sp)   // r2 += 7\n  | ah r2, 12(sp) // r2 += 11\n  | la sp, 16(sp)\n  | br r14\n}\n\nstatic void rrfe_rrd(dasm_State *state) {\n  dasm_State ** Dst = &state;\n\n  | cefbr f0,r2\n  | cefbr f2,r3\n  | cefbr f4,r4\n  | maebr f0 ,f2 ,f4\n  | cfebr r2, 0, f0\n  | br r14\n}\n\nstatic void rre(dasm_State *state)  {\n\n  dasm_State **Dst = &state;\n\n  | lay   sp , -8(sp)\n  | cefbr f0 ,  r2\n  | cefbr f1 ,  r3\n  | fidr  f0 ,  f1\n  | cfebr r2 ,0,f0\n  | la    sp,   8(sp)\n  | br   r14\n}\n\nstatic void rsb(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  | lay sp, -4(sp)\n  | lghi r3, 0x0706\n  | lghi r4, 0\n  | iill r4, 6\n  | iilh r4, 7\n  | st r4, 0(sp)\n  | lghi r2, 0\n  | clm r3, 5, 0(sp)\n  | jne >1\n  | lghi r2, 1\n  |1:\n  | la sp, 4(sp)\n  | br r14\n}\n\nstatic void sqrt_rxe(dasm_State *state)\n{\n  dasm_State **Dst = &state;\n\n  | lay     sp , -8(sp)\n  | cefbr   f0 , r2\n  | stdy    f0 , 0(sp)\n  | sqeb    f0 ,0(r4,sp)\n  | cfebr   r2 ,0, f0\n  | la      sp, 8(sp)\n  | br      r14\n\n}\n\nstatic void rxf(dasm_State *state) {\n  dasm_State **Dst = &state;\n\n  | lay    sp , -8(sp)\n  | cegbra f1 ,0, r2,0\n  | cegbra f2 ,0,r3,0\n  | ste    f2 ,0(sp)\n  | maeb   f1, f2, 0(sp)\n  | cfebr  r2 ,0, f1\n  | la     sp, 8(sp)\n  | br     r14\n\n}\n\ntypedef struct {\n  int64_t arg1;\n  int64_t arg2;\n  int64_t arg3;\n  void (*fn)(dasm_State *);\n  int64_t want;\n  const char *testname;\n} test_table;\n\ntest_table test[] = {\n  { 1, 2, 0,       add,        3,     \"add\"},\n  {10, 5, 0,       sub,        5,     \"sub\"},\n  { 2, 3, 0,       mul,        6,     \"mul\"},\n  { 5, 7, 0,        rx,    12298,      \"rx\"},\n  { 5, 7, 0,       rxy,       10,     \"rxy\"},\n  { 2, 4, 0,       lab,       32,     \"lab\"},\n  { 2, 4, 0,      labg,       32,    \"labg\"},\n  { 2, 0, 0, add_imm16,       17,   \"imm16\"},\n  { 2, 0, 0, add_imm32,       16,   \"imm32\"},\n  { 7, 3, 0,      save,      480,    \"save\"},\n  { 7, 3, 0,    labmul,       21, \"labmul0\"},\n  { 7, 0, 0,    labmul,        0, \"labmul1\"},\n  { 0, 0, 0,        pc,       55,      \"pc\"},\n  { 2,12, 0,   jmp_fwd,       12, \"jmp_fwd\"},\n//  { 9,8, 0,    add_rrd,       25, \"add_rrd\"},\n//  { 2,4, 0,  load_test,        4,\"load_test\"},\n  {-1, 0, 0,       ssa, 65535<<8,     \"ssa\"},\n  {-1, 0, 0,   ssa_act, 65535<<8, \"ssa_act\"},\n  {27, 0, 0,      type,       27,    \"type\"},\n  { 0, 0, 0,       sil,       23,     \"sil\"},\n  {15, 3,10,   rrfe_rrd,      45, \"rrfe_rrd\"},\n  { 0, 0, 0,        rsb,       0,     \"rsb\"},\n  {12,10, 0,        rre,      10,     \"rre\"},\n  {16,10, 0,   sqrt_rxe,       4,\"sqrt_rxe\"},\n  {16,10, 0,        rxf,     116,     \"rxf\"},\n  { 4, 3, 0,  test_mask,       1,\"test_mask\"}\n};\n\nstatic void *jitcode(dasm_State **state, size_t *size)\n{\n  int dasm_status = dasm_link(state, size);\n  assert(dasm_status == DASM_S_OK);\n\n  void *ret = mmap(0, *size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n  dasm_encode(state, ret);\n  dasm_free(state);\n\n  mprotect(ret, *size, PROT_READ | PROT_EXEC);\n  return (int *)ret;\n}\n\nint main(int argc, char *argv[])\n{\n  dasm_State *state;\n  for(int i = 0; i < sizeof(test)/sizeof(test[0]); i++) {\n    dasm_init(&state, 1);\n    void* labels[lab__MAX];\n    dasm_setupglobal(&state, labels, lab__MAX);\n    dasm_setup(&state, actions);\n    test[i].fn(state);\n    size_t size;\n    int64_t (*fptr)(int64_t, int64_t, int64_t) = jitcode(&state, &size);\n    int64_t got = fptr(test[i].arg1, test[i].arg2, test[i].arg3);\n\n    if (got != test[i].want) {\n      fprintf(stderr, \"FAIL: test %s: want %ld, got %ld\\n\", test[i].testname, test[i].want, got);\n      exit(1);\n    }\n    munmap(fptr, size);\n  }\n  printf(\"all tests passed\\n\");\n  return 0;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_arm.h",
    "content": "/*\n** DynASM ARM encoding engine.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"arm\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC,\n  DASM_IMM, DASM_IMM12, DASM_IMM16, DASM_IMML8, DASM_IMML12, DASM_IMMV8,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\nstatic int dasm_imm12(unsigned int n)\n{\n  int i;\n  for (i = 0; i < 16; i++, n = (n << 2) | (n >> 30))\n    if (n <= 255) return (int)(n + (i << 8));\n  return -1;\n}\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n      case DASM_IMM16:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n\tif ((ins & 0x8000))\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMMV8:\n\tCK((n & 3) == 0, RANGE_I);\n\tn >>= 2;\n\t/* fallthrough */\n      case DASM_IMML8:\n      case DASM_IMML12:\n\tCK(n >= 0 ? ((n>>((ins>>5)&31)) == 0) :\n\t\t    (((-n)>>((ins>>5)&31)) == 0), RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM12:\n\tCK(dasm_imm12((unsigned int)n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMM12: case DASM_IMM16:\n\tcase DASM_IMML8: case DASM_IMML12: case DASM_IMMV8: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048));\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  if (n < 0) {\n\t    n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp - 4);\n\t    goto patchrel;\n\t  }\n\t  /* fallthrough */\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) - 4;\n\tpatchrel:\n\t  if ((ins & 0x800) == 0) {\n\t    CK((n & 3) == 0 && ((n+0x02000000) >> 26) == 0, RANGE_REL);\n\t    cp[-1] |= ((n >> 2) & 0x00ffffff);\n\t  } else if ((ins & 0x1000)) {\n\t    CK((n & 3) == 0 && -256 <= n && n <= 256, RANGE_REL);\n\t    goto patchimml8;\n\t  } else if ((ins & 0x2000) == 0) {\n\t    CK((n & 3) == 0 && -4096 <= n && n <= 4096, RANGE_REL);\n\t    goto patchimml;\n\t  } else {\n\t    CK((n & 3) == 0 && -1020 <= n && n <= 1020, RANGE_REL);\n\t    n >>= 2;\n\t    goto patchimml;\n\t  }\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= ((n>>((ins>>10)&31)) & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMM12:\n\t  cp[-1] |= dasm_imm12((unsigned int)n);\n\t  break;\n\tcase DASM_IMM16:\n\t  cp[-1] |= ((n & 0xf000) << 4) | (n & 0x0fff);\n\t  break;\n\tcase DASM_IMML8: patchimml8:\n\t  cp[-1] |= n >= 0 ? (0x00800000 | (n & 0x0f) | ((n & 0xf0) << 4)) :\n\t\t\t     ((-n & 0x0f) | ((-n & 0xf0) << 4));\n\t  break;\n\tcase DASM_IMML12: case DASM_IMMV8: patchimml:\n\t  cp[-1] |= n >= 0 ? (0x00800000 | n) : (-n);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_arm.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM ARM module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"arm\",\n  description =\t\"DynASM ARM module\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable, rawget = assert, setmetatable, rawget\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, insert = table.concat, table.sort, table.insert\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal ror, tohex = bit.ror, bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMM12\", \"IMM16\", \"IMML8\", \"IMML12\", \"IMMV8\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0x000fffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  if n <= 0x000fffff then\n    insert(actlist, pos+1, n)\n    n = map_action.ESC * 0x10000\n  end\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\n\n-- Ext. register name -> int. name.\nlocal map_archdef = { sp = \"r13\", lr = \"r14\", pc = \"r15\", }\n\n-- Int. register name -> ext. name.\nlocal map_reg_rev = { r13 = \"sp\", r14 = \"lr\", r15 = \"pc\", }\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return map_reg_rev[s] or s\nend\n\nlocal map_shift = { lsl = 0, lsr = 1, asr = 2, ror = 3, }\n\nlocal map_cond = {\n  eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,\n  hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,\n  hs = 2, lo = 3,\n}\n\n------------------------------------------------------------------------------\n\n-- Template strings for ARM instructions.\nlocal map_op = {\n  -- Basic data processing instructions.\n  and_3 = \"e0000000DNPs\",\n  eor_3 = \"e0200000DNPs\",\n  sub_3 = \"e0400000DNPs\",\n  rsb_3 = \"e0600000DNPs\",\n  add_3 = \"e0800000DNPs\",\n  adc_3 = \"e0a00000DNPs\",\n  sbc_3 = \"e0c00000DNPs\",\n  rsc_3 = \"e0e00000DNPs\",\n  tst_2 = \"e1100000NP\",\n  teq_2 = \"e1300000NP\",\n  cmp_2 = \"e1500000NP\",\n  cmn_2 = \"e1700000NP\",\n  orr_3 = \"e1800000DNPs\",\n  mov_2 = \"e1a00000DPs\",\n  bic_3 = \"e1c00000DNPs\",\n  mvn_2 = \"e1e00000DPs\",\n\n  and_4 = \"e0000000DNMps\",\n  eor_4 = \"e0200000DNMps\",\n  sub_4 = \"e0400000DNMps\",\n  rsb_4 = \"e0600000DNMps\",\n  add_4 = \"e0800000DNMps\",\n  adc_4 = \"e0a00000DNMps\",\n  sbc_4 = \"e0c00000DNMps\",\n  rsc_4 = \"e0e00000DNMps\",\n  tst_3 = \"e1100000NMp\",\n  teq_3 = \"e1300000NMp\",\n  cmp_3 = \"e1500000NMp\",\n  cmn_3 = \"e1700000NMp\",\n  orr_4 = \"e1800000DNMps\",\n  mov_3 = \"e1a00000DMps\",\n  bic_4 = \"e1c00000DNMps\",\n  mvn_3 = \"e1e00000DMps\",\n\n  lsl_3 = \"e1a00000DMws\",\n  lsr_3 = \"e1a00020DMws\",\n  asr_3 = \"e1a00040DMws\",\n  ror_3 = \"e1a00060DMws\",\n  rrx_2 = \"e1a00060DMs\",\n\n  -- Multiply and multiply-accumulate.\n  mul_3 = \"e0000090NMSs\",\n  mla_4 = \"e0200090NMSDs\",\n  umaal_4 = \"e0400090DNMSs\",\t-- v6\n  mls_4 = \"e0600090DNMSs\",\t-- v6T2\n  umull_4 = \"e0800090DNMSs\",\n  umlal_4 = \"e0a00090DNMSs\",\n  smull_4 = \"e0c00090DNMSs\",\n  smlal_4 = \"e0e00090DNMSs\",\n\n  -- Halfword multiply and multiply-accumulate.\n  smlabb_4 = \"e1000080NMSD\",\t-- v5TE\n  smlatb_4 = \"e10000a0NMSD\",\t-- v5TE\n  smlabt_4 = \"e10000c0NMSD\",\t-- v5TE\n  smlatt_4 = \"e10000e0NMSD\",\t-- v5TE\n  smlawb_4 = \"e1200080NMSD\",\t-- v5TE\n  smulwb_3 = \"e12000a0NMS\",\t-- v5TE\n  smlawt_4 = \"e12000c0NMSD\",\t-- v5TE\n  smulwt_3 = \"e12000e0NMS\",\t-- v5TE\n  smlalbb_4 = \"e1400080NMSD\",\t-- v5TE\n  smlaltb_4 = \"e14000a0NMSD\",\t-- v5TE\n  smlalbt_4 = \"e14000c0NMSD\",\t-- v5TE\n  smlaltt_4 = \"e14000e0NMSD\",\t-- v5TE\n  smulbb_3 = \"e1600080NMS\",\t-- v5TE\n  smultb_3 = \"e16000a0NMS\",\t-- v5TE\n  smulbt_3 = \"e16000c0NMS\",\t-- v5TE\n  smultt_3 = \"e16000e0NMS\",\t-- v5TE\n\n  -- Miscellaneous data processing instructions.\n  clz_2 = \"e16f0f10DM\", -- v5T\n  rev_2 = \"e6bf0f30DM\", -- v6\n  rev16_2 = \"e6bf0fb0DM\", -- v6\n  revsh_2 = \"e6ff0fb0DM\", -- v6\n  sel_3 = \"e6800fb0DNM\", -- v6\n  usad8_3 = \"e780f010NMS\", -- v6\n  usada8_4 = \"e7800010NMSD\", -- v6\n  rbit_2 = \"e6ff0f30DM\", -- v6T2\n  movw_2 = \"e3000000DW\", -- v6T2\n  movt_2 = \"e3400000DW\", -- v6T2\n  -- Note: the X encodes width-1, not width.\n  sbfx_4 = \"e7a00050DMvX\", -- v6T2\n  ubfx_4 = \"e7e00050DMvX\", -- v6T2\n  -- Note: the X encodes the msb field, not the width.\n  bfc_3 = \"e7c0001fDvX\", -- v6T2\n  bfi_4 = \"e7c00010DMvX\", -- v6T2\n\n  -- Packing and unpacking instructions.\n  pkhbt_3 = \"e6800010DNM\", pkhbt_4 = \"e6800010DNMv\", -- v6\n  pkhtb_3 = \"e6800050DNM\", pkhtb_4 = \"e6800050DNMv\", -- v6\n  sxtab_3 = \"e6a00070DNM\", sxtab_4 = \"e6a00070DNMv\", -- v6\n  sxtab16_3 = \"e6800070DNM\", sxtab16_4 = \"e6800070DNMv\", -- v6\n  sxtah_3 = \"e6b00070DNM\", sxtah_4 = \"e6b00070DNMv\", -- v6\n  sxtb_2 = \"e6af0070DM\", sxtb_3 = \"e6af0070DMv\", -- v6\n  sxtb16_2 = \"e68f0070DM\", sxtb16_3 = \"e68f0070DMv\", -- v6\n  sxth_2 = \"e6bf0070DM\", sxth_3 = \"e6bf0070DMv\", -- v6\n  uxtab_3 = \"e6e00070DNM\", uxtab_4 = \"e6e00070DNMv\", -- v6\n  uxtab16_3 = \"e6c00070DNM\", uxtab16_4 = \"e6c00070DNMv\", -- v6\n  uxtah_3 = \"e6f00070DNM\", uxtah_4 = \"e6f00070DNMv\", -- v6\n  uxtb_2 = \"e6ef0070DM\", uxtb_3 = \"e6ef0070DMv\", -- v6\n  uxtb16_2 = \"e6cf0070DM\", uxtb16_3 = \"e6cf0070DMv\", -- v6\n  uxth_2 = \"e6ff0070DM\", uxth_3 = \"e6ff0070DMv\", -- v6\n\n  -- Saturating instructions.\n  qadd_3 = \"e1000050DMN\",\t-- v5TE\n  qsub_3 = \"e1200050DMN\",\t-- v5TE\n  qdadd_3 = \"e1400050DMN\",\t-- v5TE\n  qdsub_3 = \"e1600050DMN\",\t-- v5TE\n  -- Note: the X for ssat* encodes sat_imm-1, not sat_imm.\n  ssat_3 = \"e6a00010DXM\", ssat_4 = \"e6a00010DXMp\", -- v6\n  usat_3 = \"e6e00010DXM\", usat_4 = \"e6e00010DXMp\", -- v6\n  ssat16_3 = \"e6a00f30DXM\", -- v6\n  usat16_3 = \"e6e00f30DXM\", -- v6\n\n  -- Parallel addition and subtraction.\n  sadd16_3 = \"e6100f10DNM\", -- v6\n  sasx_3 = \"e6100f30DNM\", -- v6\n  ssax_3 = \"e6100f50DNM\", -- v6\n  ssub16_3 = \"e6100f70DNM\", -- v6\n  sadd8_3 = \"e6100f90DNM\", -- v6\n  ssub8_3 = \"e6100ff0DNM\", -- v6\n  qadd16_3 = \"e6200f10DNM\", -- v6\n  qasx_3 = \"e6200f30DNM\", -- v6\n  qsax_3 = \"e6200f50DNM\", -- v6\n  qsub16_3 = \"e6200f70DNM\", -- v6\n  qadd8_3 = \"e6200f90DNM\", -- v6\n  qsub8_3 = \"e6200ff0DNM\", -- v6\n  shadd16_3 = \"e6300f10DNM\", -- v6\n  shasx_3 = \"e6300f30DNM\", -- v6\n  shsax_3 = \"e6300f50DNM\", -- v6\n  shsub16_3 = \"e6300f70DNM\", -- v6\n  shadd8_3 = \"e6300f90DNM\", -- v6\n  shsub8_3 = \"e6300ff0DNM\", -- v6\n  uadd16_3 = \"e6500f10DNM\", -- v6\n  uasx_3 = \"e6500f30DNM\", -- v6\n  usax_3 = \"e6500f50DNM\", -- v6\n  usub16_3 = \"e6500f70DNM\", -- v6\n  uadd8_3 = \"e6500f90DNM\", -- v6\n  usub8_3 = \"e6500ff0DNM\", -- v6\n  uqadd16_3 = \"e6600f10DNM\", -- v6\n  uqasx_3 = \"e6600f30DNM\", -- v6\n  uqsax_3 = \"e6600f50DNM\", -- v6\n  uqsub16_3 = \"e6600f70DNM\", -- v6\n  uqadd8_3 = \"e6600f90DNM\", -- v6\n  uqsub8_3 = \"e6600ff0DNM\", -- v6\n  uhadd16_3 = \"e6700f10DNM\", -- v6\n  uhasx_3 = \"e6700f30DNM\", -- v6\n  uhsax_3 = \"e6700f50DNM\", -- v6\n  uhsub16_3 = \"e6700f70DNM\", -- v6\n  uhadd8_3 = \"e6700f90DNM\", -- v6\n  uhsub8_3 = \"e6700ff0DNM\", -- v6\n\n  -- Load/store instructions.\n  str_2 = \"e4000000DL\", str_3 = \"e4000000DL\", str_4 = \"e4000000DL\",\n  strb_2 = \"e4400000DL\", strb_3 = \"e4400000DL\", strb_4 = \"e4400000DL\",\n  ldr_2 = \"e4100000DL\", ldr_3 = \"e4100000DL\", ldr_4 = \"e4100000DL\",\n  ldrb_2 = \"e4500000DL\", ldrb_3 = \"e4500000DL\", ldrb_4 = \"e4500000DL\",\n  strh_2 = \"e00000b0DL\", strh_3 = \"e00000b0DL\",\n  ldrh_2 = \"e01000b0DL\", ldrh_3 = \"e01000b0DL\",\n  ldrd_2 = \"e00000d0DL\", ldrd_3 = \"e00000d0DL\", -- v5TE\n  ldrsb_2 = \"e01000d0DL\", ldrsb_3 = \"e01000d0DL\",\n  strd_2 = \"e00000f0DL\", strd_3 = \"e00000f0DL\", -- v5TE\n  ldrsh_2 = \"e01000f0DL\", ldrsh_3 = \"e01000f0DL\",\n\n  ldm_2 = \"e8900000oR\", ldmia_2 = \"e8900000oR\", ldmfd_2 = \"e8900000oR\",\n  ldmda_2 = \"e8100000oR\", ldmfa_2 = \"e8100000oR\",\n  ldmdb_2 = \"e9100000oR\", ldmea_2 = \"e9100000oR\",\n  ldmib_2 = \"e9900000oR\", ldmed_2 = \"e9900000oR\",\n  stm_2 = \"e8800000oR\", stmia_2 = \"e8800000oR\", stmfd_2 = \"e8800000oR\",\n  stmda_2 = \"e8000000oR\", stmfa_2 = \"e8000000oR\",\n  stmdb_2 = \"e9000000oR\", stmea_2 = \"e9000000oR\",\n  stmib_2 = \"e9800000oR\", stmed_2 = \"e9800000oR\",\n  pop_1 = \"e8bd0000R\", push_1 = \"e92d0000R\",\n\n  -- Branch instructions.\n  b_1 = \"ea000000B\",\n  bl_1 = \"eb000000B\",\n  blx_1 = \"e12fff30C\",\n  bx_1 = \"e12fff10M\",\n\n  -- Miscellaneous instructions.\n  nop_0 = \"e1a00000\",\n  mrs_1 = \"e10f0000D\",\n  bkpt_1 = \"e1200070K\", -- v5T\n  svc_1 = \"ef000000T\", swi_1 = \"ef000000T\",\n  ud_0 = \"e7f001f0\",\n\n  -- VFP instructions.\n  [\"vadd.f32_3\"] = \"ee300a00dnm\",\n  [\"vadd.f64_3\"] = \"ee300b00Gdnm\",\n  [\"vsub.f32_3\"] = \"ee300a40dnm\",\n  [\"vsub.f64_3\"] = \"ee300b40Gdnm\",\n  [\"vmul.f32_3\"] = \"ee200a00dnm\",\n  [\"vmul.f64_3\"] = \"ee200b00Gdnm\",\n  [\"vnmul.f32_3\"] = \"ee200a40dnm\",\n  [\"vnmul.f64_3\"] = \"ee200b40Gdnm\",\n  [\"vmla.f32_3\"] = \"ee000a00dnm\",\n  [\"vmla.f64_3\"] = \"ee000b00Gdnm\",\n  [\"vmls.f32_3\"] = \"ee000a40dnm\",\n  [\"vmls.f64_3\"] = \"ee000b40Gdnm\",\n  [\"vnmla.f32_3\"] = \"ee100a40dnm\",\n  [\"vnmla.f64_3\"] = \"ee100b40Gdnm\",\n  [\"vnmls.f32_3\"] = \"ee100a00dnm\",\n  [\"vnmls.f64_3\"] = \"ee100b00Gdnm\",\n  [\"vdiv.f32_3\"] = \"ee800a00dnm\",\n  [\"vdiv.f64_3\"] = \"ee800b00Gdnm\",\n\n  [\"vabs.f32_2\"] = \"eeb00ac0dm\",\n  [\"vabs.f64_2\"] = \"eeb00bc0Gdm\",\n  [\"vneg.f32_2\"] = \"eeb10a40dm\",\n  [\"vneg.f64_2\"] = \"eeb10b40Gdm\",\n  [\"vsqrt.f32_2\"] = \"eeb10ac0dm\",\n  [\"vsqrt.f64_2\"] = \"eeb10bc0Gdm\",\n  [\"vcmp.f32_2\"] = \"eeb40a40dm\",\n  [\"vcmp.f64_2\"] = \"eeb40b40Gdm\",\n  [\"vcmpe.f32_2\"] = \"eeb40ac0dm\",\n  [\"vcmpe.f64_2\"] = \"eeb40bc0Gdm\",\n  [\"vcmpz.f32_1\"] = \"eeb50a40d\",\n  [\"vcmpz.f64_1\"] = \"eeb50b40Gd\",\n  [\"vcmpze.f32_1\"] = \"eeb50ac0d\",\n  [\"vcmpze.f64_1\"] = \"eeb50bc0Gd\",\n\n  vldr_2 = \"ed100a00dl|ed100b00Gdl\",\n  vstr_2 = \"ed000a00dl|ed000b00Gdl\",\n  vldm_2 = \"ec900a00or\",\n  vldmia_2 = \"ec900a00or\",\n  vldmdb_2 = \"ed100a00or\",\n  vpop_1 = \"ecbd0a00r\",\n  vstm_2 = \"ec800a00or\",\n  vstmia_2 = \"ec800a00or\",\n  vstmdb_2 = \"ed000a00or\",\n  vpush_1 = \"ed2d0a00r\",\n\n  [\"vmov.f32_2\"] = \"eeb00a40dm|eeb00a00dY\",\t-- #imm is VFPv3 only\n  [\"vmov.f64_2\"] = \"eeb00b40Gdm|eeb00b00GdY\",\t-- #imm is VFPv3 only\n  vmov_2 = \"ee100a10Dn|ee000a10nD\",\n  vmov_3 = \"ec500a10DNm|ec400a10mDN|ec500b10GDNm|ec400b10GmDN\",\n\n  vmrs_0 = \"eef1fa10\",\n  vmrs_1 = \"eef10a10D\",\n  vmsr_1 = \"eee10a10D\",\n\n  [\"vcvt.s32.f32_2\"] = \"eebd0ac0dm\",\n  [\"vcvt.s32.f64_2\"] = \"eebd0bc0dGm\",\n  [\"vcvt.u32.f32_2\"] = \"eebc0ac0dm\",\n  [\"vcvt.u32.f64_2\"] = \"eebc0bc0dGm\",\n  [\"vcvtr.s32.f32_2\"] = \"eebd0a40dm\",\n  [\"vcvtr.s32.f64_2\"] = \"eebd0b40dGm\",\n  [\"vcvtr.u32.f32_2\"] = \"eebc0a40dm\",\n  [\"vcvtr.u32.f64_2\"] = \"eebc0b40dGm\",\n  [\"vcvt.f32.s32_2\"] = \"eeb80ac0dm\",\n  [\"vcvt.f64.s32_2\"] = \"eeb80bc0GdFm\",\n  [\"vcvt.f32.u32_2\"] = \"eeb80a40dm\",\n  [\"vcvt.f64.u32_2\"] = \"eeb80b40GdFm\",\n  [\"vcvt.f32.f64_2\"] = \"eeb70bc0dGm\",\n  [\"vcvt.f64.f32_2\"] = \"eeb70ac0GdFm\",\n\n  -- VFPv4 only:\n  [\"vfma.f32_3\"] = \"eea00a00dnm\",\n  [\"vfma.f64_3\"] = \"eea00b00Gdnm\",\n  [\"vfms.f32_3\"] = \"eea00a40dnm\",\n  [\"vfms.f64_3\"] = \"eea00b40Gdnm\",\n  [\"vfnma.f32_3\"] = \"ee900a40dnm\",\n  [\"vfnma.f64_3\"] = \"ee900b40Gdnm\",\n  [\"vfnms.f32_3\"] = \"ee900a00dnm\",\n  [\"vfnms.f64_3\"] = \"ee900b00Gdnm\",\n\n  -- NYI: Advanced SIMD instructions.\n\n  -- NYI: I have no need for these instructions right now:\n  -- swp, swpb, strex, ldrex, strexd, ldrexd, strexb, ldrexb, strexh, ldrexh\n  -- msr, nopv6, yield, wfe, wfi, sev, dbg, bxj, smc, srs, rfe\n  -- cps, setend, pli, pld, pldw, clrex, dsb, dmb, isb\n  -- stc, ldc, mcr, mcr2, mrc, mrc2, mcrr, mcrr2, mrrc, mrrc2, cdp, cdp2\n}\n\n-- Add mnemonics for \"s\" variants.\ndo\n  local t = {}\n  for k,v in pairs(map_op) do\n    if sub(v, -1) == \"s\" then\n      local v2 = sub(v, 1, 2)..char(byte(v, 3)+1)..sub(v, 4, -2)\n      t[sub(k, 1, -3)..\"s\"..sub(k, -2)] = v2\n    end\n  end\n  for k,v in pairs(t) do\n    map_op[k] = v\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r1?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r(1?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 15 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_gpr_pm(expr)\n  local pm, expr2 = match(expr, \"^([+-]?)(.*)$\")\n  return parse_gpr(expr2), (pm == \"-\")\nend\n\nlocal function parse_vr(expr, tp)\n  local t, r = match(expr, \"^([sd])([0-9]+)$\")\n  if t == tp then\n    r = tonumber(r)\n    if r <= 31 then\n      if t == \"s\" then return shr(r, 1), band(r, 1) end\n      return band(r, 15), shr(r, 4)\n    end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_reglist(reglist)\n  reglist = match(reglist, \"^{%s*([^}]*)}$\")\n  if not reglist then werror(\"register list expected\") end\n  local rr = 0\n  for p in gmatch(reglist..\",\", \"%s*([^,]*),\") do\n    local rbit = shl(1, parse_gpr(gsub(p, \"%s+$\", \"\")))\n    if band(rr, rbit) ~= 0 then\n      werror(\"duplicate register `\"..p..\"'\")\n    end\n    rr = rr + rbit\n  end\n  return rr\nend\n\nlocal function parse_vrlist(reglist)\n  local ta, ra, tb, rb = match(reglist,\n\t\t\t   \"^{%s*([sd])([0-9]+)%s*%-%s*([sd])([0-9]+)%s*}$\")\n  ra, rb = tonumber(ra), tonumber(rb)\n  if ta and ta == tb and ra and rb and ra <= 31 and rb <= 31 and ra <= rb then\n    local nr = rb+1 - ra\n    if ta == \"s\" then\n      return shl(shr(ra,1),12)+shl(band(ra,1),22) + nr\n    else\n      return shl(band(ra,15),12)+shl(shr(ra,4),22) + nr*2 + 0x100\n    end\n  end\n  werror(\"register list expected\")\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = tonumber(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm12(imm)\n  local n = tonumber(imm)\n  if n then\n    local m = band(n)\n    for i=0,-15,-1 do\n      if shr(m, 8) == 0 then return m + shl(band(i, 15), 8) end\n      m = ror(m, 2)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM12\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm16(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = tonumber(imm)\n  if n then\n    if shr(n, 16) == 0 then return band(n, 0x0fff) + shl(band(n, 0xf000), 4) end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM16\", 32*16, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm_load(imm, ext)\n  local n = tonumber(imm)\n  if n then\n    if ext then\n      if n >= -255 and n <= 255 then\n\tlocal up = 0x00800000\n\tif n < 0 then n = -n; up = 0 end\n\treturn shl(band(n, 0xf0), 4) + band(n, 0x0f) + up\n      end\n    else\n      if n >= -4095 and n <= 4095 then\n\tif n >= 0 then return n+0x00800000 end\n\treturn -n\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(ext and \"IMML8\" or \"IMML12\", 32768 + shl(ext and 8 or 12, 5), imm)\n    return 0\n  end\nend\n\nlocal function parse_shift(shift, gprok)\n  if shift == \"rrx\" then\n    return 3 * 32\n  else\n    local s, s2 = match(shift, \"^(%S+)%s*(.*)$\")\n    s = map_shift[s]\n    if not s then werror(\"expected shift operand\") end\n    if sub(s2, 1, 1) == \"#\" then\n      return parse_imm(s2, 5, 7, 0, false) + shl(s, 5)\n    else\n      if not gprok then werror(\"expected immediate shift operand\") end\n      return shl(parse_gpr(s2), 8) + shl(s, 5) + 16\n    end\n  end\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\nlocal function parse_load(params, nparams, n, op)\n  local oplo = band(op, 255)\n  local ext, ldrd = (oplo ~= 0), (oplo == 208)\n  local d\n  if (ldrd or oplo == 240) then\n    d = band(shr(op, 12), 15)\n    if band(d, 1) ~= 0 then werror(\"odd destination register\") end\n  end\n  local pn = params[n]\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  local p2 = params[n+1]\n  if not p1 then\n    if not p2 then\n      if match(pn, \"^[<>=%-]\") or match(pn, \"^extern%s+\") then\n\tlocal mode, n, s = parse_label(pn, false)\n\twaction(\"REL_\"..mode, n + (ext and 0x1800 or 0x0800), s, 1)\n\treturn op + 15 * 65536 + 0x01000000 + (ext and 0x00400000 or 0)\n      end\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal d, tp = parse_gpr(reg)\n\tif tp then\n\t  waction(ext and \"IMML8\" or \"IMML12\", 32768 + 32*(ext and 8 or 12),\n\t\t  format(tp.ctypefmt, tailr))\n\t  return op + shl(d, 16) + 0x01000000 + (ext and 0x00400000 or 0)\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  if wb == \"!\" then op = op + 0x00200000 end\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    local p3 = params[n+2]\n    op = op + shl(parse_gpr(p1), 16)\n    local imm = match(p2, \"^#(.*)$\")\n    if imm then\n      local m = parse_imm_load(imm, ext)\n      if p3 then werror(\"too many parameters\") end\n      op = op + m + (ext and 0x00400000 or 0)\n    else\n      local m, neg = parse_gpr_pm(p2)\n      if ldrd and (m == d or m-1 == d) then werror(\"register conflict\") end\n      op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)\n      if p3 then op = op + parse_shift(p3) end\n    end\n  else\n    local p1a, p2 = match(p1, \"^([^,%s]*)%s*(.*)$\")\n    op = op + shl(parse_gpr(p1a), 16) + 0x01000000\n    if p2 ~= \"\" then\n      local imm = match(p2, \"^,%s*#(.*)$\")\n      if imm then\n\tlocal m = parse_imm_load(imm, ext)\n\top = op + m + (ext and 0x00400000 or 0)\n      else\n\tlocal p2a, p3 = match(p2, \"^,%s*([^,%s]*)%s*,?%s*(.*)$\")\n\tlocal m, neg = parse_gpr_pm(p2a)\n\tif ldrd and (m == d or m-1 == d) then werror(\"register conflict\") end\n\top = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)\n\tif p3 ~= \"\" then\n\t  if ext then werror(\"too many parameters\") end\n\t  op = op + parse_shift(p3)\n\tend\n      end\n    else\n      if wb == \"!\" then werror(\"bad use of '!'\") end\n      op = op + (ext and 0x00c00000 or 0x00800000)\n    end\n  end\n  return op\nend\n\nlocal function parse_vload(q)\n  local reg, imm = match(q, \"^%[%s*([^,%s]*)%s*(.*)%]$\")\n  if reg then\n    local d = shl(parse_gpr(reg), 16)\n    if imm == \"\" then return d end\n    imm = match(imm, \"^,%s*#(.*)$\")\n    if imm then\n      local n = tonumber(imm)\n      if n then\n\tif n >= -1020 and n <= 1020 and n%4 == 0 then\n\t  return d + (n >= 0 and n/4+0x00800000 or -n/4)\n\tend\n\twerror(\"out of range immediate `\"..imm..\"'\")\n      else\n\twaction(\"IMMV8\", 32768 + 32*8, imm)\n\treturn d\n      end\n    end\n  else\n    if match(q, \"^[<>=%-]\") or match(q, \"^extern%s+\") then\n      local mode, n, s = parse_label(q, false)\n      waction(\"REL_\"..mode, n + 0x2800, s, 1)\n      return 15 * 65536\n    end\n    local reg, tailr = match(q, \"^([%w_:]+)%s*(.*)$\")\n    if reg and tailr ~= \"\" then\n      local d, tp = parse_gpr(reg)\n      if tp then\n\twaction(\"IMMV8\", 32768 + 32*8, format(tp.ctypefmt, tailr))\n\treturn shl(d, 16)\n      end\n    end\n  end\n  werror(\"expected address operand\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nlocal function parse_template(params, template, nparams, pos)\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n = 1\n  local vr = \"s\"\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    local q = params[n]\n    if p == \"D\" then\n      op = op + shl(parse_gpr(q), 12); n = n + 1\n    elseif p == \"N\" then\n      op = op + shl(parse_gpr(q), 16); n = n + 1\n    elseif p == \"S\" then\n      op = op + shl(parse_gpr(q), 8); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_gpr(q); n = n + 1\n    elseif p == \"d\" then\n      local r,h = parse_vr(q, vr); op = op+shl(r,12)+shl(h,22); n = n + 1\n    elseif p == \"n\" then\n      local r,h = parse_vr(q, vr); op = op+shl(r,16)+shl(h,7); n = n + 1\n    elseif p == \"m\" then\n      local r,h = parse_vr(q, vr); op = op+r+shl(h,5); n = n + 1\n    elseif p == \"P\" then\n      local imm = match(q, \"^#(.*)$\")\n      if imm then\n\top = op + parse_imm12(imm) + 0x02000000\n      else\n\top = op + parse_gpr(q)\n      end\n      n = n + 1\n    elseif p == \"p\" then\n      op = op + parse_shift(q, true); n = n + 1\n    elseif p == \"L\" then\n      op = parse_load(params, nparams, n, op)\n    elseif p == \"l\" then\n      op = op + parse_vload(q)\n    elseif p == \"B\" then\n      local mode, n, s = parse_label(q, false)\n      waction(\"REL_\"..mode, n, s, 1)\n    elseif p == \"C\" then -- blx gpr vs. blx label.\n      if match(q, \"^([%w_]+):(r1?[0-9])$\") or match(q, \"^r(1?[0-9])$\") then\n\top = op + parse_gpr(q)\n      else\n\tif op < 0xe0000000 then werror(\"unconditional instruction\") end\n\tlocal mode, n, s = parse_label(q, false)\n\twaction(\"REL_\"..mode, n, s, 1)\n\top = 0xfa000000\n      end\n    elseif p == \"F\" then\n      vr = \"s\"\n    elseif p == \"G\" then\n      vr = \"d\"\n    elseif p == \"o\" then\n      local r, wb = match(q, \"^([^!]*)(!?)$\")\n      op = op + shl(parse_gpr(r), 16) + (wb == \"!\" and 0x00200000 or 0)\n      n = n + 1\n    elseif p == \"R\" then\n      op = op + parse_reglist(q); n = n + 1\n    elseif p == \"r\" then\n      op = op + parse_vrlist(q); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm16(q); n = n + 1\n    elseif p == \"v\" then\n      op = op + parse_imm(q, 5, 7, 0, false); n = n + 1\n    elseif p == \"w\" then\n      local imm = match(q, \"^#(.*)$\")\n      if imm then\n\top = op + parse_imm(q, 5, 7, 0, false); n = n + 1\n      else\n\top = op + shl(parse_gpr(q), 8) + 16\n      end\n    elseif p == \"X\" then\n      op = op + parse_imm(q, 5, 16, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      local imm = tonumber(match(q, \"^#(.*)$\")); n = n + 1\n      if not imm or shr(imm, 8) ~= 0 then\n\twerror(\"bad immediate operand\")\n      end\n      op = op + shl(band(imm, 0xf0), 12) + band(imm, 0x0f)\n    elseif p == \"K\" then\n      local imm = tonumber(match(q, \"^#(.*)$\")); n = n + 1\n      if not imm or shr(imm, 16) ~= 0 then\n\twerror(\"bad immediate operand\")\n      end\n      op = op + shl(band(imm, 0xfff0), 4) + band(imm, 0x000f)\n    elseif p == \"T\" then\n      op = op + parse_imm(q, 24, 0, 0, false); n = n + 1\n    elseif p == \"s\" then\n      -- Ignored.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return template:gsub(\"%x%x%x%x%x%x%x%x\", \"\") end\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 3 positions.\n  if secpos+3 > maxsecpos then wflush() end\n  local pos = wpos()\n  local lpos, apos, spos = #actlist, #actargs, secpos\n\n  local ok, err\n  for t in gmatch(template, \"[^|]+\") do\n    ok, err = pcall(parse_template, params, t, nparams, pos)\n    if ok then return end\n    secpos = spos\n    actlist[lpos+1] = nil\n    actlist[lpos+2] = nil\n    actlist[lpos+3] = nil\n    actargs[apos+1] = nil\n    actargs[apos+2] = nil\n    actargs[apos+3] = nil\n  end\n  error(err, 0)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = function(t, k)\n    local v = map_coreop[k]\n    if v then return v end\n    local k1, cc, k2 = match(k, \"^(.-)(..)([._].*)$\")\n    local cv = map_cond[cc]\n    if cv then\n      local v = rawget(t, k1..k2)\n      if type(v) == \"string\" then\n\tlocal scv = format(\"%x\", cv)\n\treturn gsub(scv..sub(v, 2), \"|e\", \"|\"..scv)\n      end\n    end\n  end })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_arm64.h",
    "content": "/*\n** DynASM ARM64 encoding engine.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"arm64\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC, DASM_REL_A,\n  DASM_IMM, DASM_IMM6, DASM_IMM12, DASM_IMM13W, DASM_IMM13X, DASM_IMML,\n  DASM_IMMV, DASM_VREG,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_RANGE_VREG\t0x16000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\nstatic int dasm_imm12(unsigned int n)\n{\n  if ((n >> 12) == 0)\n    return n;\n  else if ((n & 0xff000fff) == 0)\n    return (n >> 12) | 0x1000;\n  else\n    return -1;\n}\n\nstatic int dasm_ffs(unsigned long long x)\n{\n  int n = -1;\n  while (x) { x >>= 1; n++; }\n  return n;\n}\n\nstatic int dasm_imm13(int lo, int hi)\n{\n  int inv = 0, w = 64, s = 0xfff, xa, xb;\n  unsigned long long n = (((unsigned long long)hi) << 32) | (unsigned int)lo;\n  unsigned long long m = 1ULL, a, b, c;\n  if (n & 1) { n = ~n; inv = 1; }\n  a = n & -n; b = (n+a)&-(n+a); c = (n+a-b)&-(n+a-b);\n  xa = dasm_ffs(a); xb = dasm_ffs(b);\n  if (c) {\n    w = dasm_ffs(c) - xa;\n    if (w == 32) m = 0x0000000100000001UL;\n    else if (w == 16) m = 0x0001000100010001UL;\n    else if (w == 8) m = 0x0101010101010101UL;\n    else if (w == 4) m = 0x1111111111111111UL;\n    else if (w == 2) m = 0x5555555555555555UL;\n    else return -1;\n    s = (-2*w & 0x3f) - 1;\n  } else if (!a) {\n    return -1;\n  } else if (xb == -1) {\n    xb = 64;\n  }\n  if ((b-a) * m != n) return -1;\n  if (inv) {\n    return ((w - xb) << 6) | (s+w+xa-xb);\n  } else {\n    return ((w - xa) << 6) | (s+xb-xa);\n  }\n  return -1;\n}\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: if ((ins & 0x8000)) ofs += 8; break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tif ((ins & 0x8000)) ofs += 8;\n\tbreak;\n      case DASM_REL_A:\n\tb[pos++] = n;\n\tb[pos++] = va_arg(ap, int);\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif ((ins & 0x8000))\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM6:\n\tCK((n >> 6) == 0, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM12:\n\tCK(dasm_imm12((unsigned int)n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM13W:\n\tCK(dasm_imm13(n, n) != -1, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMM13X: {\n\tint m = va_arg(ap, int);\n\tCK(dasm_imm13(n, m) != -1, RANGE_I);\n\tb[pos++] = n;\n\tb[pos++] = m;\n\tbreak;\n\t}\n      case DASM_IMML: {\n#ifdef DASM_CHECKS\n\tint scale = (ins & 3);\n\tCK((!(n & ((1<<scale)-1)) && (unsigned int)(n>>scale) < 4096) ||\n\t   (unsigned int)(n+256) < 512, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n\t}\n      case DASM_IMMV:\n\tofs += 4;\n\tb[pos++] = n;\n\tbreak;\n      case DASM_VREG:\n\tCK(n < 32, RANGE_VREG);\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMM6: case DASM_IMM12: case DASM_IMM13W:\n\tcase DASM_IMML: case DASM_IMMV: case DASM_VREG: pos++; break;\n\tcase DASM_IMM13X: case DASM_REL_A: pos += 2; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048));\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  if (n < 0) {\n\t    ptrdiff_t na = (ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4;\n\t    n = (int)na;\n\t    CK((ptrdiff_t)n == na, RANGE_REL);\n\t    goto patchrel;\n\t  }\n\t  /* fallthrough */\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) + 4;\n\tpatchrel:\n\t  if (!(ins & 0xf800)) {  /* B, BL */\n\t    CK((n & 3) == 0 && ((n+0x08000000) >> 28) == 0, RANGE_REL);\n\t    cp[-1] |= ((n >> 2) & 0x03ffffff);\n\t  } else if ((ins & 0x800)) {  /* B.cond, CBZ, CBNZ, LDR* literal */\n\t    CK((n & 3) == 0 && ((n+0x00100000) >> 21) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x00ffffe0);\n\t  } else if ((ins & 0x3000) == 0x2000) {  /* ADR */\n\t    CK(((n+0x00100000) >> 21) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x00ffffe0) | ((n & 3) << 29);\n\t  } else if ((ins & 0x3000) == 0x3000) {  /* ADRP */\n\t    cp[-1] |= ((n >> 9) & 0x00ffffe0) | (((n >> 12) & 3) << 29);\n\t  } else if ((ins & 0x1000)) {  /* TBZ, TBNZ */\n\t    CK((n & 3) == 0 && ((n+0x00008000) >> 16) == 0, RANGE_REL);\n\t    cp[-1] |= ((n << 3) & 0x0007ffe0);\n\t  } else if ((ins & 0x8000)) {  /* absolute */\n\t    cp[0] = (unsigned int)((ptrdiff_t)cp - 4 + n);\n\t    cp[1] = (unsigned int)(((ptrdiff_t)cp - 4 + n) >> 32);\n\t    cp += 2;\n\t  }\n\t  break;\n\tcase DASM_REL_A: {\n\t  ptrdiff_t na = (((ptrdiff_t)(*b++) << 32) | (unsigned int)n);\n\t  if ((ins & 0x3000) == 0x3000) {  /* ADRP */\n\t    ins &= ~0x1000;\n\t    na = (na >> 12) - (((ptrdiff_t)cp - 4) >> 12);\n\t  } else {\n\t    na = na - (ptrdiff_t)cp + 4;\n\t  }\n\t  n = (int)na;\n\t  CK((ptrdiff_t)n == na, RANGE_REL);\n\t  goto patchrel;\n\t}\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMM6:\n\t  cp[-1] |= ((n&31) << 19) | ((n&32) << 26);\n\t  break;\n\tcase DASM_IMM12:\n\t  cp[-1] |= (dasm_imm12((unsigned int)n) << 10);\n\t  break;\n\tcase DASM_IMM13W:\n\t  cp[-1] |= (dasm_imm13(n, n) << 10);\n\t  break;\n\tcase DASM_IMM13X:\n\t  cp[-1] |= (dasm_imm13(n, *b++) << 10);\n\t  break;\n\tcase DASM_IMML: {\n\t  int scale = (ins & 3);\n\t  cp[-1] |= (!(n & ((1<<scale)-1)) && (unsigned int)(n>>scale) < 4096) ?\n\t    ((n << (10-scale)) | 0x01000000) : ((n & 511) << 12);\n\t  break;\n\t  }\n\tcase DASM_IMMV:\n\t  *cp++ = n;\n\t  break;\n\tcase DASM_VREG:\n\t  cp[-1] |= (n & 0x1f) << (ins & 0x1f);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_arm64.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM ARM64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"arm\",\n  description =\t\"DynASM ARM64 module\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable, rawget = assert, setmetatable, rawget\nlocal _s = string\nlocal format, byte, char = _s.format, _s.byte, _s.char\nlocal match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, insert = table.concat, table.sort, table.insert\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal ror, tohex, tobit = bit.ror, bit.tohex, bit.tobit\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"REL_A\",\n  \"IMM\", \"IMM6\", \"IMM12\", \"IMM13W\", \"IMM13X\", \"IMML\", \"IMMV\",\n  \"VREG\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0x000fffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  if n <= 0x000fffff then\n    insert(actlist, pos+1, n)\n    n = map_action.ESC * 0x10000\n  end\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\n\n-- Ext. register name -> int. name.\nlocal map_archdef = { xzr = \"@x31\", wzr = \"@w31\", lr = \"x30\", }\n\n-- Int. register name -> ext. name.\nlocal map_reg_rev = { [\"@x31\"] = \"xzr\", [\"@w31\"] = \"wzr\", x30 = \"lr\", }\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return map_reg_rev[s] or s\nend\n\nlocal map_shift = { lsl = 0, lsr = 1, asr = 2, }\n\nlocal map_extend = {\n  uxtb = 0, uxth = 1, uxtw = 2, uxtx = 3,\n  sxtb = 4, sxth = 5, sxtw = 6, sxtx = 7,\n}\n\nlocal map_cond = {\n  eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,\n  hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,\n  hs = 2, lo = 3,\n}\n\n------------------------------------------------------------------------------\n\nlocal parse_reg_type\n\nlocal function parse_reg(expr, shift)\n  if not expr then werror(\"expected register name\") end\n  local tname, ovreg = match(expr, \"^([%w_]+):(@?%l%d+)$\")\n  if not tname then\n    tname, ovreg = match(expr, \"^([%w_]+):(R[xwqdshb]%b())$\")\n  end\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local ok31, rt, r = match(expr, \"^(@?)([xwqdshb])([123]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 30 or (r == 31 and ok31 ~= \"\" or (rt ~= \"w\" and rt ~= \"x\")) then\n      if not parse_reg_type then\n\tparse_reg_type = rt\n      elseif parse_reg_type ~= rt then\n\twerror(\"register size mismatch\")\n      end\n      return shl(r, shift), tp\n    end\n  end\n  local vrt, vreg = match(expr, \"^R([xwqdshb])(%b())$\")\n  if vreg then\n    if not parse_reg_type then\n      parse_reg_type = vrt\n    elseif parse_reg_type ~= vrt then\n      werror(\"register size mismatch\")\n    end\n    if shift then waction(\"VREG\", shift, vreg) end\n    return 0\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_reg_base(expr)\n  if expr == \"sp\" then return 0x3e0 end\n  local base, tp = parse_reg(expr, 5)\n  if parse_reg_type ~= \"x\" then werror(\"bad register type\") end\n  parse_reg_type = false\n  return base, tp\nend\n\nlocal parse_ctx = {}\n\nlocal loadenv = setfenv and function(s)\n  local code = loadstring(s, \"\")\n  if code then setfenv(code, parse_ctx) end\n  return code\nend or function(s)\n  return load(s, \"\", nil, parse_ctx)\nend\n\n-- Try to parse simple arithmetic, too, since some basic ops are aliases.\nlocal function parse_number(n)\n  local x = tonumber(n)\n  if x then return x end\n  local code = loadenv(\"return \"..n)\n  if code then\n    local ok, y = pcall(code)\n    if ok and type(y) == \"number\" then return y end\n  end\n  return nil\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm12(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    if shr(n, 12) == 0 then\n      return shl(n, 10)\n    elseif band(n, 0xff000fff) == 0 then\n      return shr(n, 2) + 0x00400000\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM12\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm13(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  local r64 = parse_reg_type == \"x\"\n  if n and n % 1 == 0 and n >= 0 and n <= 0xffffffff then\n    local inv = false\n    if band(n, 1) == 1 then n = bit.bnot(n); inv = true end\n    local t = {}\n    for i=1,32 do t[i] = band(n, 1); n = shr(n, 1) end\n    local b = table.concat(t)\n    b = b..(r64 and (inv and \"1\" or \"0\"):rep(32) or b)\n    local p0, p1, p0a, p1a = b:match(\"^(0+)(1+)(0*)(1*)\")\n    if p0 then\n      local w = p1a == \"\" and (r64 and 64 or 32) or #p1+#p0a\n      if band(w, w-1) == 0 and b == b:sub(1, w):rep(64/w) then\n\tlocal s = band(-2*w, 0x3f) - 1\n\tif w == 64 then s = s + 0x1000 end\n\tif inv then\n\t  return shl(w-#p1-#p0, 16) + shl(s+w-#p1, 10)\n\telse\n\t  return shl(w-#p0, 16) + shl(s+#p1, 10)\n\tend\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif r64 then\n    waction(\"IMM13X\", 0, format(\"(unsigned int)(%s)\", imm))\n    actargs[#actargs+1] = format(\"(unsigned int)((unsigned long long)(%s)>>32)\", imm)\n    return 0\n  else\n    waction(\"IMM13W\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm6(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    if n >= 0 and n <= 63 then\n      return shl(band(n, 0x1f), 19) + (n >= 32 and 0x80000000 or 0)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMM6\", 0, imm)\n    return 0\n  end\nend\n\nlocal function parse_imm_load(imm, scale)\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n and m >= 0 and m < 0x1000 then\n      return shl(m, 10) + 0x01000000 -- Scaled, unsigned 12 bit offset.\n    elseif n >= -256 and n < 256 then\n      return shl(band(n, 511), 12) -- Unscaled, signed 9 bit offset.\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    waction(\"IMML\", scale, imm)\n    return 0\n  end\nend\n\nlocal function parse_fpimm(imm)\n  imm = match(imm, \"^#(.*)$\")\n  if not imm then werror(\"expected immediate operand\") end\n  local n = parse_number(imm)\n  if n then\n    local m, e = math.frexp(n)\n    local s, e2 = 0, band(e-2, 7)\n    if m < 0 then m = -m; s = 0x00100000 end\n    m = m*32-16\n    if m % 1 == 0 and m >= 0 and m <= 15 and sar(shl(e2, 29), 29)+2 == e then\n      return s + shl(e2, 17) + shl(m, 13)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  else\n    werror(\"NYI fpimm action\")\n  end\nend\n\nlocal function parse_shift(expr)\n  local s, s2 = match(expr, \"^(%S+)%s*(.*)$\")\n  s = map_shift[s]\n  if not s then werror(\"expected shift operand\") end\n  return parse_imm(s2, 6, 10, 0, false) + shl(s, 22)\nend\n\nlocal function parse_lslx16(expr)\n  local n = match(expr, \"^lsl%s*#(%d+)$\")\n  n = tonumber(n)\n  if not n then werror(\"expected shift operand\") end\n  if band(n, parse_reg_type == \"x\" and 0xffffffcf or 0xffffffef) ~= 0 then\n    werror(\"bad shift amount\")\n  end\n  return shl(n, 17)\nend\n\nlocal function parse_extend(expr)\n  local s, s2 = match(expr, \"^(%S+)%s*(.*)$\")\n  if s == \"lsl\" then\n    s = parse_reg_type == \"x\" and 3 or 2\n  else\n    s = map_extend[s]\n  end\n  if not s then werror(\"expected extend operand\") end\n  return (s2 == \"\" and 0 or parse_imm(s2, 3, 10, 0, false)) + shl(s, 13)\nend\n\nlocal function parse_cond(expr, inv)\n  local c = map_cond[expr]\n  if not c then werror(\"expected condition operand\") end\n  return shl(bit.bxor(c, inv), 12)\nend\n\nlocal function parse_load(params, nparams, n, op)\n  if params[n+2] then werror(\"too many operands\") end\n  local scale = shr(op, 30)\n  local pn, p2 = params[n], params[n+1]\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  if not p1 then\n    if not p2 then\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal base, tp = parse_reg_base(reg)\n\tif tp then\n\t  waction(\"IMML\", scale, format(tp.ctypefmt, tailr))\n\t  return op + base\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    op = op + parse_reg_base(p1) + parse_imm(p2, 9, 12, 0, true) + 0x400\n  elseif wb == \"!\" then\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*,%s*(.*)$\")\n    if not p1a then werror(\"bad use of '!'\") end\n    op = op + parse_reg_base(p1a) + parse_imm(p2a, 9, 12, 0, true) + 0xc00\n  else\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*(.*)$\")\n    op = op + parse_reg_base(p1a)\n    if p2a ~= \"\" then\n      local imm = match(p2a, \"^,%s*#(.*)$\")\n      if imm then\n\top = op + parse_imm_load(imm, scale)\n      else\n\tlocal p2b, p3b, p3s = match(p2a, \"^,%s*([^,%s]*)%s*,?%s*(%S*)%s*(.*)$\")\n\top = op + parse_reg(p2b, 16) + 0x00200800\n\tif parse_reg_type ~= \"x\" and parse_reg_type ~= \"w\" then\n\t  werror(\"bad index register type\")\n\tend\n\tif p3b == \"\" then\n\t  if parse_reg_type ~= \"x\" then werror(\"bad index register type\") end\n\t  op = op + 0x6000\n\telse\n\t  if p3s == \"\" or p3s == \"#0\" then\n\t  elseif p3s == \"#\"..scale then\n\t    op = op + 0x1000\n\t  else\n\t    werror(\"bad scale\")\n\t  end\n\t  if parse_reg_type == \"x\" then\n\t    if p3b == \"lsl\" and p3s ~= \"\" then op = op + 0x6000\n\t    elseif p3b == \"sxtx\" then op = op + 0xe000\n\t    else\n\t      werror(\"bad extend/shift specifier\")\n\t    end\n\t  else\n\t    if p3b == \"uxtw\" then op = op + 0x4000\n\t    elseif p3b == \"sxtw\" then op = op + 0xc000\n\t    else\n\t      werror(\"bad extend/shift specifier\")\n\t    end\n\t  end\n\tend\n      end\n    else\n      if wb == \"!\" then werror(\"bad use of '!'\") end\n      op = op + 0x01000000\n    end\n  end\n  return op\nend\n\nlocal function parse_load_pair(params, nparams, n, op)\n  if params[n+2] then werror(\"too many operands\") end\n  local pn, p2 = params[n], params[n+1]\n  local scale = shr(op, 30) == 0 and 2 or 3\n  local p1, wb = match(pn, \"^%[%s*(.-)%s*%](!?)$\")\n  if not p1 then\n    if not p2 then\n      local reg, tailr = match(pn, \"^([%w_:]+)%s*(.*)$\")\n      if reg and tailr ~= \"\" then\n\tlocal base, tp = parse_reg_base(reg)\n\tif tp then\n\t  waction(\"IMM\", 32768+7*32+15+scale*1024, format(tp.ctypefmt, tailr))\n\t  return op + base + 0x01000000\n\tend\n      end\n    end\n    werror(\"expected address operand\")\n  end\n  if p2 then\n    if wb == \"!\" then werror(\"bad use of '!'\") end\n    op = op + 0x00800000\n  else\n    local p1a, p2a = match(p1, \"^([^,%s]*)%s*,%s*(.*)$\")\n    if p1a then p1, p2 = p1a, p2a else p2 = \"#0\" end\n    op = op + (wb == \"!\" and 0x01800000 or 0x01000000)\n  end\n  return op + parse_reg_base(p1) + parse_imm(p2, 7, 15, scale, true)\nend\n\nlocal function parse_label(label, def)\n  local prefix = label:sub(1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, label:sub(3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[label:sub(3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n    -- &expr (pointer)\n    if label:sub(1, 1) == \"&\" then\n      return \"A\", 0, format(\"(ptrdiff_t)(%s)\", label:sub(2))\n    end\n  end\nend\n\nlocal function branch_type(op)\n  if band(op, 0x7c000000) == 0x14000000 then return 0 -- B, BL\n  elseif shr(op, 24) == 0x54 or band(op, 0x7e000000) == 0x34000000 or\n\t band(op, 0x3b000000) == 0x18000000 then\n    return 0x800 -- B.cond, CBZ, CBNZ, LDR* literal\n  elseif band(op, 0x7e000000) == 0x36000000 then return 0x1000 -- TBZ, TBNZ\n  elseif band(op, 0x9f000000) == 0x10000000 then return 0x2000 -- ADR\n  elseif band(op, 0x9f000000) == band(0x90000000) then return 0x3000 -- ADRP\n  else\n    assert(false, \"unknown branch type\")\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal map_op, op_template\n\nlocal function op_alias(opname, f)\n  return function(params, nparams)\n    if not params then return \"-> \"..opname:sub(1, -3) end\n    f(params, nparams)\n    op_template(params, map_op[opname], nparams)\n  end\nend\n\nlocal function alias_bfx(p)\n  p[4] = \"#(\"..p[3]:sub(2)..\")+(\"..p[4]:sub(2)..\")-1\"\nend\n\nlocal function alias_bfiz(p)\n  parse_reg(p[1], 0)\n  if parse_reg_type == \"w\" then\n    p[3] = \"#(32-(\"..p[3]:sub(2)..\"))%32\"\n    p[4] = \"#(\"..p[4]:sub(2)..\")-1\"\n  else\n    p[3] = \"#(64-(\"..p[3]:sub(2)..\"))%64\"\n    p[4] = \"#(\"..p[4]:sub(2)..\")-1\"\n  end\nend\n\nlocal alias_lslimm = op_alias(\"ubfm_4\", function(p)\n  parse_reg(p[1], 0)\n  local sh = p[3]:sub(2)\n  if parse_reg_type == \"w\" then\n    p[3] = \"#(32-(\"..sh..\"))%32\"\n    p[4] = \"#31-(\"..sh..\")\"\n  else\n    p[3] = \"#(64-(\"..sh..\"))%64\"\n    p[4] = \"#63-(\"..sh..\")\"\n  end\nend)\n\n-- Template strings for ARM instructions.\nmap_op = {\n  -- Basic data processing instructions.\n  add_3  = \"0b000000DNMg|11000000pDpNIg|8b206000pDpNMx\",\n  add_4  = \"0b000000DNMSg|0b200000DNMXg|8b200000pDpNMXx|8b200000pDpNxMwX\",\n  adds_3 = \"2b000000DNMg|31000000DpNIg|ab206000DpNMx\",\n  adds_4 = \"2b000000DNMSg|2b200000DNMXg|ab200000DpNMXx|ab200000DpNxMwX\",\n  cmn_2  = \"2b00001fNMg|3100001fpNIg|ab20601fpNMx\",\n  cmn_3  = \"2b00001fNMSg|2b20001fNMXg|ab20001fpNMXx|ab20001fpNxMwX\",\n\n  sub_3  = \"4b000000DNMg|51000000pDpNIg|cb206000pDpNMx\",\n  sub_4  = \"4b000000DNMSg|4b200000DNMXg|cb200000pDpNMXx|cb200000pDpNxMwX\",\n  subs_3 = \"6b000000DNMg|71000000DpNIg|eb206000DpNMx\",\n  subs_4 = \"6b000000DNMSg|6b200000DNMXg|eb200000DpNMXx|eb200000DpNxMwX\",\n  cmp_2  = \"6b00001fNMg|7100001fpNIg|eb20601fpNMx\",\n  cmp_3  = \"6b00001fNMSg|6b20001fNMXg|eb20001fpNMXx|eb20001fpNxMwX\",\n\n  neg_2  = \"4b0003e0DMg\",\n  neg_3  = \"4b0003e0DMSg\",\n  negs_2 = \"6b0003e0DMg\",\n  negs_3 = \"6b0003e0DMSg\",\n\n  adc_3  = \"1a000000DNMg\",\n  adcs_3 = \"3a000000DNMg\",\n  sbc_3  = \"5a000000DNMg\",\n  sbcs_3 = \"7a000000DNMg\",\n  ngc_2  = \"5a0003e0DMg\",\n  ngcs_2 = \"7a0003e0DMg\",\n\n  and_3  = \"0a000000DNMg|12000000pDNig\",\n  and_4  = \"0a000000DNMSg\",\n  orr_3  = \"2a000000DNMg|32000000pDNig\",\n  orr_4  = \"2a000000DNMSg\",\n  eor_3  = \"4a000000DNMg|52000000pDNig\",\n  eor_4  = \"4a000000DNMSg\",\n  ands_3 = \"6a000000DNMg|72000000DNig\",\n  ands_4 = \"6a000000DNMSg\",\n  tst_2  = \"6a00001fNMg|7200001fNig\",\n  tst_3  = \"6a00001fNMSg\",\n\n  bic_3  = \"0a200000DNMg\",\n  bic_4  = \"0a200000DNMSg\",\n  orn_3  = \"2a200000DNMg\",\n  orn_4  = \"2a200000DNMSg\",\n  eon_3  = \"4a200000DNMg\",\n  eon_4  = \"4a200000DNMSg\",\n  bics_3 = \"6a200000DNMg\",\n  bics_4 = \"6a200000DNMSg\",\n\n  movn_2 = \"12800000DWg\",\n  movn_3 = \"12800000DWRg\",\n  movz_2 = \"52800000DWg\",\n  movz_3 = \"52800000DWRg\",\n  movk_2 = \"72800000DWg\",\n  movk_3 = \"72800000DWRg\",\n\n  -- TODO: this doesn't cover all valid immediates for mov reg, #imm.\n  mov_2  = \"2a0003e0DMg|52800000DW|320003e0pDig|11000000pDpNg\",\n  mov_3  = \"2a0003e0DMSg\",\n  mvn_2  = \"2a2003e0DMg\",\n  mvn_3  = \"2a2003e0DMSg\",\n\n  adr_2  = \"10000000DBx\",\n  adrp_2 = \"90000000DBx\",\n\n  csel_4  = \"1a800000DNMCg\",\n  csinc_4 = \"1a800400DNMCg\",\n  csinv_4 = \"5a800000DNMCg\",\n  csneg_4 = \"5a800400DNMCg\",\n  cset_2  = \"1a9f07e0Dcg\",\n  csetm_2 = \"5a9f03e0Dcg\",\n  cinc_3  = \"1a800400DNmcg\",\n  cinv_3  = \"5a800000DNmcg\",\n  cneg_3  = \"5a800400DNmcg\",\n\n  ccmn_4 = \"3a400000NMVCg|3a400800N5VCg\",\n  ccmp_4 = \"7a400000NMVCg|7a400800N5VCg\",\n\n  madd_4 = \"1b000000DNMAg\",\n  msub_4 = \"1b008000DNMAg\",\n  mul_3  = \"1b007c00DNMg\",\n  mneg_3 = \"1b00fc00DNMg\",\n\n  smaddl_4 = \"9b200000DxNMwAx\",\n  smsubl_4 = \"9b208000DxNMwAx\",\n  smull_3  = \"9b207c00DxNMw\",\n  smnegl_3 = \"9b20fc00DxNMw\",\n  smulh_3  = \"9b407c00DNMx\",\n  umaddl_4 = \"9ba00000DxNMwAx\",\n  umsubl_4 = \"9ba08000DxNMwAx\",\n  umull_3  = \"9ba07c00DxNMw\",\n  umnegl_3 = \"9ba0fc00DxNMw\",\n  umulh_3  = \"9bc07c00DNMx\",\n\n  udiv_3 = \"1ac00800DNMg\",\n  sdiv_3 = \"1ac00c00DNMg\",\n\n  -- Bit operations.\n  sbfm_4 = \"13000000DN12w|93400000DN12x\",\n  bfm_4  = \"33000000DN12w|b3400000DN12x\",\n  ubfm_4 = \"53000000DN12w|d3400000DN12x\",\n  extr_4 = \"13800000DNM2w|93c00000DNM2x\",\n\n  sxtb_2 = \"13001c00DNw|93401c00DNx\",\n  sxth_2 = \"13003c00DNw|93403c00DNx\",\n  sxtw_2 = \"93407c00DxNw\",\n  uxtb_2 = \"53001c00DNw\",\n  uxth_2 = \"53003c00DNw\",\n\n  sbfx_4  = op_alias(\"sbfm_4\", alias_bfx),\n  bfxil_4 = op_alias(\"bfm_4\", alias_bfx),\n  ubfx_4  = op_alias(\"ubfm_4\", alias_bfx),\n  sbfiz_4 = op_alias(\"sbfm_4\", alias_bfiz),\n  bfi_4   = op_alias(\"bfm_4\", alias_bfiz),\n  ubfiz_4 = op_alias(\"ubfm_4\", alias_bfiz),\n\n  lsl_3  = function(params, nparams)\n    if params and params[3]:byte() == 35 then\n      return alias_lslimm(params, nparams)\n    else\n      return op_template(params, \"1ac02000DNMg\", nparams)\n    end\n  end,\n  lsr_3  = \"1ac02400DNMg|53007c00DN1w|d340fc00DN1x\",\n  asr_3  = \"1ac02800DNMg|13007c00DN1w|9340fc00DN1x\",\n  ror_3  = \"1ac02c00DNMg|13800000DNm2w|93c00000DNm2x\",\n\n  clz_2   = \"5ac01000DNg\",\n  cls_2   = \"5ac01400DNg\",\n  rbit_2  = \"5ac00000DNg\",\n  rev_2   = \"5ac00800DNw|dac00c00DNx\",\n  rev16_2 = \"5ac00400DNg\",\n  rev32_2 = \"dac00800DNx\",\n\n  -- Loads and stores.\n  [\"strb_*\"]  = \"38000000DwL\",\n  [\"ldrb_*\"]  = \"38400000DwL\",\n  [\"ldrsb_*\"] = \"38c00000DwL|38800000DxL\",\n  [\"strh_*\"]  = \"78000000DwL\",\n  [\"ldrh_*\"]  = \"78400000DwL\",\n  [\"ldrsh_*\"] = \"78c00000DwL|78800000DxL\",\n  [\"str_*\"]   = \"b8000000DwL|f8000000DxL|bc000000DsL|fc000000DdL\",\n  [\"ldr_*\"]   = \"18000000DwB|58000000DxB|1c000000DsB|5c000000DdB|b8400000DwL|f8400000DxL|bc400000DsL|fc400000DdL\",\n  [\"ldrsw_*\"] = \"98000000DxB|b8800000DxL\",\n  -- NOTE: ldur etc. are handled by ldr et al.\n\n  [\"stp_*\"]   = \"28000000DAwP|a8000000DAxP|2c000000DAsP|6c000000DAdP\",\n  [\"ldp_*\"]   = \"28400000DAwP|a8400000DAxP|2c400000DAsP|6c400000DAdP\",\n  [\"ldpsw_*\"] = \"68400000DAxP\",\n\n  -- Branches.\n  b_1    = \"14000000B\",\n  bl_1   = \"94000000B\",\n  blr_1  = \"d63f0000Nx\",\n  br_1   = \"d61f0000Nx\",\n  ret_0  = \"d65f03c0\",\n  ret_1  = \"d65f0000Nx\",\n  -- b.cond is added below.\n  cbz_2  = \"34000000DBg\",\n  cbnz_2 = \"35000000DBg\",\n  tbz_3  = \"36000000DTBw|36000000DTBx\",\n  tbnz_3 = \"37000000DTBw|37000000DTBx\",\n\n  -- Miscellaneous instructions.\n  -- TODO: hlt, hvc, smc, svc, eret, dcps[123], drps, mrs, msr\n  -- TODO: sys, sysl, ic, dc, at, tlbi\n  -- TODO: hint, yield, wfe, wfi, sev, sevl\n  -- TODO: clrex, dsb, dmb, isb\n  nop_0  = \"d503201f\",\n  brk_0  = \"d4200000\",\n  brk_1  = \"d4200000W\",\n\n  -- Floating point instructions.\n  fmov_2  = \"1e204000DNf|1e260000DwNs|1e270000DsNw|9e660000DxNd|9e670000DdNx|1e201000DFf\",\n  fabs_2  = \"1e20c000DNf\",\n  fneg_2  = \"1e214000DNf\",\n  fsqrt_2 = \"1e21c000DNf\",\n\n  fcvt_2  = \"1e22c000DdNs|1e624000DsNd\",\n\n  -- TODO: half-precision and fixed-point conversions.\n  fcvtas_2 = \"1e240000DwNs|9e240000DxNs|1e640000DwNd|9e640000DxNd\",\n  fcvtau_2 = \"1e250000DwNs|9e250000DxNs|1e650000DwNd|9e650000DxNd\",\n  fcvtms_2 = \"1e300000DwNs|9e300000DxNs|1e700000DwNd|9e700000DxNd\",\n  fcvtmu_2 = \"1e310000DwNs|9e310000DxNs|1e710000DwNd|9e710000DxNd\",\n  fcvtns_2 = \"1e200000DwNs|9e200000DxNs|1e600000DwNd|9e600000DxNd\",\n  fcvtnu_2 = \"1e210000DwNs|9e210000DxNs|1e610000DwNd|9e610000DxNd\",\n  fcvtps_2 = \"1e280000DwNs|9e280000DxNs|1e680000DwNd|9e680000DxNd\",\n  fcvtpu_2 = \"1e290000DwNs|9e290000DxNs|1e690000DwNd|9e690000DxNd\",\n  fcvtzs_2 = \"1e380000DwNs|9e380000DxNs|1e780000DwNd|9e780000DxNd\",\n  fcvtzu_2 = \"1e390000DwNs|9e390000DxNs|1e790000DwNd|9e790000DxNd\",\n\n  scvtf_2  = \"1e220000DsNw|9e220000DsNx|1e620000DdNw|9e620000DdNx\",\n  ucvtf_2  = \"1e230000DsNw|9e230000DsNx|1e630000DdNw|9e630000DdNx\",\n\n  frintn_2 = \"1e244000DNf\",\n  frintp_2 = \"1e24c000DNf\",\n  frintm_2 = \"1e254000DNf\",\n  frintz_2 = \"1e25c000DNf\",\n  frinta_2 = \"1e264000DNf\",\n  frintx_2 = \"1e274000DNf\",\n  frinti_2 = \"1e27c000DNf\",\n\n  fadd_3   = \"1e202800DNMf\",\n  fsub_3   = \"1e203800DNMf\",\n  fmul_3   = \"1e200800DNMf\",\n  fnmul_3  = \"1e208800DNMf\",\n  fdiv_3   = \"1e201800DNMf\",\n\n  fmadd_4  = \"1f000000DNMAf\",\n  fmsub_4  = \"1f008000DNMAf\",\n  fnmadd_4 = \"1f200000DNMAf\",\n  fnmsub_4 = \"1f208000DNMAf\",\n\n  fmax_3   = \"1e204800DNMf\",\n  fmaxnm_3 = \"1e206800DNMf\",\n  fmin_3   = \"1e205800DNMf\",\n  fminnm_3 = \"1e207800DNMf\",\n\n  fcmp_2   = \"1e202000NMf|1e202008NZf\",\n  fcmpe_2  = \"1e202010NMf|1e202018NZf\",\n\n  fccmp_4  = \"1e200400NMVCf\",\n  fccmpe_4 = \"1e200410NMVCf\",\n\n  fcsel_4  = \"1e200c00DNMCf\",\n\n  -- TODO: crc32*, aes*, sha*, pmull\n  -- TODO: SIMD instructions.\n}\n\nfor cond,c in pairs(map_cond) do\n  map_op[\"b\"..cond..\"_1\"] = tohex(0x54000000+c)..\"B\"\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nlocal function parse_template(params, template, nparams, pos)\n  local op = tonumber(template:sub(1, 8), 16)\n  local n = 1\n  local rtt = {}\n\n  parse_reg_type = false\n\n  -- Process each character.\n  for p in gmatch(template:sub(9), \".\") do\n    local q = params[n]\n    if p == \"D\" then\n      op = op + parse_reg(q, 0); n = n + 1\n    elseif p == \"N\" then\n      op = op + parse_reg(q, 5); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_reg(q, 16); n = n + 1\n    elseif p == \"A\" then\n      op = op + parse_reg(q, 10); n = n + 1\n    elseif p == \"m\" then\n      op = op + parse_reg(params[n-1], 16)\n\n    elseif p == \"p\" then\n      if q == \"sp\" then params[n] = \"@x31\" end\n    elseif p == \"g\" then\n      if parse_reg_type == \"x\" then\n\top = op + 0x80000000\n      elseif parse_reg_type ~= \"w\" then\n\twerror(\"bad register type\")\n      end\n      parse_reg_type = false\n    elseif p == \"f\" then\n      if parse_reg_type == \"d\" then\n\top = op + 0x00400000\n      elseif parse_reg_type ~= \"s\" then\n\twerror(\"bad register type\")\n      end\n      parse_reg_type = false\n    elseif p == \"x\" or p == \"w\" or p == \"d\" or p == \"s\" then\n      if parse_reg_type ~= p then\n\twerror(\"register size mismatch\")\n      end\n      parse_reg_type = false\n\n    elseif p == \"L\" then\n      op = parse_load(params, nparams, n, op)\n    elseif p == \"P\" then\n      op = parse_load_pair(params, nparams, n, op)\n\n    elseif p == \"B\" then\n      local mode, v, s = parse_label(q, false); n = n + 1\n      if not mode then werror(\"bad label `\"..q..\"'\") end\n      local m = branch_type(op)\n      if mode == \"A\" then\n\twaction(\"REL_\"..mode, v+m, format(\"(unsigned int)(%s)\", s))\n\tactargs[#actargs+1] = format(\"(unsigned int)((%s)>>32)\", s)\n      else\n\twaction(\"REL_\"..mode, v+m, s, 1)\n      end\n\n    elseif p == \"I\" then\n      op = op + parse_imm12(q); n = n + 1\n    elseif p == \"i\" then\n      op = op + parse_imm13(q); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm(q, 16, 5, 0, false); n = n + 1\n    elseif p == \"T\" then\n      op = op + parse_imm6(q); n = n + 1\n    elseif p == \"1\" then\n      op = op + parse_imm(q, 6, 16, 0, false); n = n + 1\n    elseif p == \"2\" then\n      op = op + parse_imm(q, 6, 10, 0, false); n = n + 1\n    elseif p == \"5\" then\n      op = op + parse_imm(q, 5, 16, 0, false); n = n + 1\n    elseif p == \"V\" then\n      op = op + parse_imm(q, 4, 0, 0, false); n = n + 1\n    elseif p == \"F\" then\n      op = op + parse_fpimm(q); n = n + 1\n    elseif p == \"Z\" then\n      if q ~= \"#0\" and q ~= \"#0.0\" then werror(\"expected zero immediate\") end\n      n = n + 1\n\n    elseif p == \"S\" then\n      op = op + parse_shift(q); n = n + 1\n    elseif p == \"X\" then\n      op = op + parse_extend(q); n = n + 1\n    elseif p == \"R\" then\n      op = op + parse_lslx16(q); n = n + 1\n    elseif p == \"C\" then\n      op = op + parse_cond(q, 0); n = n + 1\n    elseif p == \"c\" then\n      op = op + parse_cond(q, 1); n = n + 1\n\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nfunction op_template(params, template, nparams)\n  if not params then return template:gsub(\"%x%x%x%x%x%x%x%x\", \"\") end\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 4 positions.\n  if secpos+4 > maxsecpos then wflush() end\n  local pos = wpos()\n  local lpos, apos, spos = #actlist, #actargs, secpos\n\n  local ok, err\n  for t in gmatch(template, \"[^|]+\") do\n    ok, err = pcall(parse_template, params, t, nparams, pos)\n    if ok then return end\n    secpos = spos\n    actlist[lpos+1] = nil\n    actlist[lpos+2] = nil\n    actlist[lpos+3] = nil\n    actlist[lpos+4] = nil\n    actargs[apos+1] = nil\n    actargs[apos+2] = nil\n    actargs[apos+3] = nil\n    actargs[apos+4] = nil\n  end\n  error(err, 0)\nend\n\nmap_op[\".template__\"] = op_template\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if not mode or mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nlocal function op_data(params)\n  if not params then return \"imm...\" end\n  local sz = params.op == \".long\" and 4 or 8\n  for _,p in ipairs(params) do\n    local imm = parse_number(p)\n    if imm then\n      local n = tobit(imm)\n      if n == imm or (n < 0 and n + 2^32 == imm) then\n\twputw(n < 0 and n + 2^32 or n)\n\tif sz == 8 then\n\t  wputw(imm < 0 and 0xffffffff or 0)\n\tend\n      elseif sz == 4 then\n\twerror(\"bad immediate `\"..p..\"'\")\n      else\n\timm = nil\n      end\n    end\n    if not imm then\n      local mode, v, s = parse_label(p, false)\n      if sz == 4 then\n\tif mode then werror(\"label does not fit into .long\") end\n\twaction(\"IMMV\", 0, p)\n      elseif mode and mode ~= \"A\" then\n\twaction(\"REL_\"..mode, v+0x8000, s, 1)\n      else\n\tif mode == \"A\" then p = s end\n\twaction(\"IMMV\", 0, format(\"(unsigned int)(%s)\", p))\n\twaction(\"IMMV\", 0, format(\"(unsigned int)((unsigned long long)(%s)>>32)\", p))\n      end\n    end\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\nmap_op[\".long_*\"] = op_data\nmap_op[\".quad_*\"] = op_data\nmap_op[\".addr_*\"] = op_data\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_mips.h",
    "content": "/*\n** DynASM MIPS encoding engine.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"mips\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC, DASM_IMM, DASM_IMMS,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16) - 0xff00;\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM: case DASM_IMMS:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n#endif\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif (ins & 0x8000)\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16) - 0xff00;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMMS: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16) - 0xff00;\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1);\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  if (n < 0) {\n\t    n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);\n\t    goto patchrel;\n\t  }\n\t  /* fallthrough */\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n);\n\t  if (ins & 2048)\n\t    n = (n + (int)(size_t)base) & 0x0fffffff;\n\t  else\n\t    n = n - (int)((char *)cp - base);\n\tpatchrel: {\n\t  unsigned int e = 16 + ((ins >> 12) & 15);\n\t  CK((n & 3) == 0 &&\n\t     ((n + ((ins & 2048) ? 0 : (1<<(e+1)))) >> (e+2)) == 0, RANGE_REL);\n\t  cp[-1] |= ((n>>2) & ((1<<e)-1));\n\t  }\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMMS:\n\t  cp[-1] |= ((n>>3) & 4); n &= 0x1f;\n\t  /* fallthrough */\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_mips.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM MIPS32/MIPS64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\nlocal mips64 = mips64\nlocal mipsr6 = _map_def.MIPSR6\n\n-- Module information:\nlocal _info = {\n  arch =\tmips64 and \"mips64\" or \"mips\",\n  description =\t\"DynASM MIPS32/MIPS64 module\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable = assert, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch = _s.match, _s.gmatch\nlocal concat, sort = table.concat, table.sort\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal tohex = bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMMS\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(0xff000000 + w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n >= 0xff000000 then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = { sp=\"r29\", ra=\"r31\" } -- Ext. register name -> int. name.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  if s == \"r29\" then return \"sp\"\n  elseif s == \"r31\" then return \"ra\" end\n  return s\nend\n\n------------------------------------------------------------------------------\n\n-- Template strings for MIPS instructions.\nlocal map_op = {\n  -- First-level opcodes.\n  j_1 =\t\t\"08000000J\",\n  jal_1 =\t\"0c000000J\",\n  b_1 =\t\t\"10000000B\",\n  beqz_2 =\t\"10000000SB\",\n  beq_3 =\t\"10000000STB\",\n  bnez_2 =\t\"14000000SB\",\n  bne_3 =\t\"14000000STB\",\n  blez_2 =\t\"18000000SB\",\n  bgtz_2 =\t\"1c000000SB\",\n  li_2 =\t\"24000000TI\",\n  addiu_3 =\t\"24000000TSI\",\n  slti_3 =\t\"28000000TSI\",\n  sltiu_3 =\t\"2c000000TSI\",\n  andi_3 =\t\"30000000TSU\",\n  lu_2 =\t\"34000000TU\",\n  ori_3 =\t\"34000000TSU\",\n  xori_3 =\t\"38000000TSU\",\n  lui_2 =\t\"3c000000TU\",\n  daddiu_3 =\tmips64 and \"64000000TSI\",\n  ldl_2 =\tmips64 and \"68000000TO\",\n  ldr_2 =\tmips64 and \"6c000000TO\",\n  lb_2 =\t\"80000000TO\",\n  lh_2 =\t\"84000000TO\",\n  lw_2 =\t\"8c000000TO\",\n  lbu_2 =\t\"90000000TO\",\n  lhu_2 =\t\"94000000TO\",\n  lwu_2 =\tmips64 and \"9c000000TO\",\n  sb_2 =\t\"a0000000TO\",\n  sh_2 =\t\"a4000000TO\",\n  sw_2 =\t\"ac000000TO\",\n  lwc1_2 =\t\"c4000000HO\",\n  ldc1_2 =\t\"d4000000HO\",\n  ld_2 =\tmips64 and \"dc000000TO\",\n  swc1_2 =\t\"e4000000HO\",\n  sdc1_2 =\t\"f4000000HO\",\n  sd_2 =\tmips64 and \"fc000000TO\",\n\n  -- Opcode SPECIAL.\n  nop_0 =\t\"00000000\",\n  sll_3 =\t\"00000000DTA\",\n  sextw_2 =\t\"00000000DT\",\n  srl_3 =\t\"00000002DTA\",\n  rotr_3 =\t\"00200002DTA\",\n  sra_3 =\t\"00000003DTA\",\n  sllv_3 =\t\"00000004DTS\",\n  srlv_3 =\t\"00000006DTS\",\n  rotrv_3 =\t\"00000046DTS\",\n  drotrv_3 =\tmips64 and \"00000056DTS\",\n  srav_3 =\t\"00000007DTS\",\n  jalr_1 =\t\"0000f809S\",\n  jalr_2 =\t\"00000009DS\",\n  syscall_0 =\t\"0000000c\",\n  syscall_1 =\t\"0000000cY\",\n  break_0 =\t\"0000000d\",\n  break_1 =\t\"0000000dY\",\n  sync_0 =\t\"0000000f\",\n  dsllv_3 =\tmips64 and \"00000014DTS\",\n  dsrlv_3 =\tmips64 and \"00000016DTS\",\n  dsrav_3 =\tmips64 and \"00000017DTS\",\n  add_3 =\t\"00000020DST\",\n  move_2 =\tmips64 and \"00000025DS\" or \"00000021DS\",\n  addu_3 =\t\"00000021DST\",\n  sub_3 =\t\"00000022DST\",\n  negu_2 =\tmips64 and \"0000002fDT\" or \"00000023DT\",\n  subu_3 =\t\"00000023DST\",\n  and_3 =\t\"00000024DST\",\n  or_3 =\t\"00000025DST\",\n  xor_3 =\t\"00000026DST\",\n  not_2 =\t\"00000027DS\",\n  nor_3 =\t\"00000027DST\",\n  slt_3 =\t\"0000002aDST\",\n  sltu_3 =\t\"0000002bDST\",\n  dadd_3 =\tmips64 and \"0000002cDST\",\n  daddu_3 =\tmips64 and \"0000002dDST\",\n  dsub_3 =\tmips64 and \"0000002eDST\",\n  dsubu_3 =\tmips64 and \"0000002fDST\",\n  tge_2 =\t\"00000030ST\",\n  tge_3 =\t\"00000030STZ\",\n  tgeu_2 =\t\"00000031ST\",\n  tgeu_3 =\t\"00000031STZ\",\n  tlt_2 =\t\"00000032ST\",\n  tlt_3 =\t\"00000032STZ\",\n  tltu_2 =\t\"00000033ST\",\n  tltu_3 =\t\"00000033STZ\",\n  teq_2 =\t\"00000034ST\",\n  teq_3 =\t\"00000034STZ\",\n  tne_2 =\t\"00000036ST\",\n  tne_3 =\t\"00000036STZ\",\n  dsll_3 =\tmips64 and \"00000038DTa\",\n  dsrl_3 =\tmips64 and \"0000003aDTa\",\n  drotr_3 =\tmips64 and \"0020003aDTa\",\n  dsra_3 =\tmips64 and \"0000003bDTa\",\n  dsll32_3 =\tmips64 and \"0000003cDTA\",\n  dsrl32_3 =\tmips64 and \"0000003eDTA\",\n  drotr32_3 =\tmips64 and \"0020003eDTA\",\n  dsra32_3 =\tmips64 and \"0000003fDTA\",\n\n  -- Opcode REGIMM.\n  bltz_2 =\t\"04000000SB\",\n  bgez_2 =\t\"04010000SB\",\n  bltzl_2 =\t\"04020000SB\",\n  bgezl_2 =\t\"04030000SB\",\n  bal_1 =\t\"04110000B\",\n  synci_1 =\t\"041f0000O\",\n\n  -- Opcode SPECIAL3.\n  ext_4 =\t\"7c000000TSAM\", -- Note: last arg is msbd = size-1\n  dextm_4 =\tmips64 and \"7c000001TSAM\", -- Args: pos    | size-1-32\n  dextu_4 =\tmips64 and \"7c000002TSAM\", -- Args: pos-32 | size-1\n  dext_4 =\tmips64 and \"7c000003TSAM\", -- Args: pos    | size-1\n  zextw_2 =\tmips64 and \"7c00f803TS\",\n  ins_4 =\t\"7c000004TSAM\", -- Note: last arg is msb = pos+size-1\n  dinsm_4 =\tmips64 and \"7c000005TSAM\", -- Args: pos    | pos+size-33\n  dinsu_4 =\tmips64 and \"7c000006TSAM\", -- Args: pos-32 | pos+size-33\n  dins_4 =\tmips64 and \"7c000007TSAM\", -- Args: pos    | pos+size-1\n  wsbh_2 =\t\"7c0000a0DT\",\n  dsbh_2 =\tmips64 and \"7c0000a4DT\",\n  dshd_2 =\tmips64 and \"7c000164DT\",\n  seb_2 =\t\"7c000420DT\",\n  seh_2 =\t\"7c000620DT\",\n  rdhwr_2 =\t\"7c00003bTD\",\n\n  -- Opcode COP0.\n  mfc0_2 =\t\"40000000TD\",\n  mfc0_3 =\t\"40000000TDW\",\n  dmfc0_2 =\tmips64 and \"40200000TD\",\n  dmfc0_3 =\tmips64 and \"40200000TDW\",\n  mtc0_2 =\t\"40800000TD\",\n  mtc0_3 =\t\"40800000TDW\",\n  dmtc0_2 =\tmips64 and \"40a00000TD\",\n  dmtc0_3 =\tmips64 and \"40a00000TDW\",\n  rdpgpr_2 =\t\"41400000DT\",\n  di_0 =\t\"41606000\",\n  di_1 =\t\"41606000T\",\n  ei_0 =\t\"41606020\",\n  ei_1 =\t\"41606020T\",\n  wrpgpr_2 =\t\"41c00000DT\",\n  tlbr_0 =\t\"42000001\",\n  tlbwi_0 =\t\"42000002\",\n  tlbwr_0 =\t\"42000006\",\n  tlbp_0 =\t\"42000008\",\n  eret_0 =\t\"42000018\",\n  deret_0 =\t\"4200001f\",\n  wait_0 =\t\"42000020\",\n\n  -- Opcode COP1.\n  mfc1_2 =\t\"44000000TG\",\n  dmfc1_2 =\tmips64 and \"44200000TG\",\n  cfc1_2 =\t\"44400000TG\",\n  mfhc1_2 =\t\"44600000TG\",\n  mtc1_2 =\t\"44800000TG\",\n  dmtc1_2 =\tmips64 and \"44a00000TG\",\n  ctc1_2 =\t\"44c00000TG\",\n  mthc1_2 =\t\"44e00000TG\",\n\n  [\"add.s_3\"] =\t\t\"46000000FGH\",\n  [\"sub.s_3\"] =\t\t\"46000001FGH\",\n  [\"mul.s_3\"] =\t\t\"46000002FGH\",\n  [\"div.s_3\"] =\t\t\"46000003FGH\",\n  [\"sqrt.s_2\"] =\t\"46000004FG\",\n  [\"abs.s_2\"] =\t\t\"46000005FG\",\n  [\"mov.s_2\"] =\t\t\"46000006FG\",\n  [\"neg.s_2\"] =\t\t\"46000007FG\",\n  [\"round.l.s_2\"] =\t\"46000008FG\",\n  [\"trunc.l.s_2\"] =\t\"46000009FG\",\n  [\"ceil.l.s_2\"] =\t\"4600000aFG\",\n  [\"floor.l.s_2\"] =\t\"4600000bFG\",\n  [\"round.w.s_2\"] =\t\"4600000cFG\",\n  [\"trunc.w.s_2\"] =\t\"4600000dFG\",\n  [\"ceil.w.s_2\"] =\t\"4600000eFG\",\n  [\"floor.w.s_2\"] =\t\"4600000fFG\",\n  [\"recip.s_2\"] =\t\"46000015FG\",\n  [\"rsqrt.s_2\"] =\t\"46000016FG\",\n  [\"cvt.d.s_2\"] =\t\"46000021FG\",\n  [\"cvt.w.s_2\"] =\t\"46000024FG\",\n  [\"cvt.l.s_2\"] =\t\"46000025FG\",\n  [\"add.d_3\"] =\t\t\"46200000FGH\",\n  [\"sub.d_3\"] =\t\t\"46200001FGH\",\n  [\"mul.d_3\"] =\t\t\"46200002FGH\",\n  [\"div.d_3\"] =\t\t\"46200003FGH\",\n  [\"sqrt.d_2\"] =\t\"46200004FG\",\n  [\"abs.d_2\"] =\t\t\"46200005FG\",\n  [\"mov.d_2\"] =\t\t\"46200006FG\",\n  [\"neg.d_2\"] =\t\t\"46200007FG\",\n  [\"round.l.d_2\"] =\t\"46200008FG\",\n  [\"trunc.l.d_2\"] =\t\"46200009FG\",\n  [\"ceil.l.d_2\"] =\t\"4620000aFG\",\n  [\"floor.l.d_2\"] =\t\"4620000bFG\",\n  [\"round.w.d_2\"] =\t\"4620000cFG\",\n  [\"trunc.w.d_2\"] =\t\"4620000dFG\",\n  [\"ceil.w.d_2\"] =\t\"4620000eFG\",\n  [\"floor.w.d_2\"] =\t\"4620000fFG\",\n  [\"recip.d_2\"] =\t\"46200015FG\",\n  [\"rsqrt.d_2\"] =\t\"46200016FG\",\n  [\"cvt.s.d_2\"] =\t\"46200020FG\",\n  [\"cvt.w.d_2\"] =\t\"46200024FG\",\n  [\"cvt.l.d_2\"] =\t\"46200025FG\",\n  [\"cvt.s.w_2\"] =\t\"46800020FG\",\n  [\"cvt.d.w_2\"] =\t\"46800021FG\",\n  [\"cvt.s.l_2\"] =\t\"46a00020FG\",\n  [\"cvt.d.l_2\"] =\t\"46a00021FG\",\n}\n\nif mipsr6 then -- Instructions added with MIPSR6.\n\n  for k,v in pairs({\n\n    -- Add immediate to upper bits.\n    aui_3 =\t\"3c000000TSI\",\n    daui_3 =\tmips64 and \"74000000TSI\",\n    dahi_2 =\tmips64 and \"04060000SI\",\n    dati_2 =\tmips64 and \"041e0000SI\",\n\n    -- TODO: addiupc, auipc, aluipc, lwpc, lwupc, ldpc.\n\n    -- Compact branches.\n    blezalc_2 =\t\"18000000TB\",\t-- rt != 0.\n    bgezalc_2 =\t\"18000000T=SB\",\t-- rt != 0.\n    bgtzalc_2 =\t\"1c000000TB\",\t-- rt != 0.\n    bltzalc_2 =\t\"1c000000T=SB\",\t-- rt != 0.\n\n    blezc_2 =\t\"58000000TB\",\t-- rt != 0.\n    bgezc_2 =\t\"58000000T=SB\",\t-- rt != 0.\n    bgec_3 =\t\"58000000STB\",\t-- rs != rt.\n    blec_3 =\t\"58000000TSB\",\t-- rt != rs.\n\n    bgtzc_2 =\t\"5c000000TB\",\t-- rt != 0.\n    bltzc_2 =\t\"5c000000T=SB\",\t-- rt != 0.\n    bltc_3 =\t\"5c000000STB\",\t-- rs != rt.\n    bgtc_3 =\t\"5c000000TSB\",\t-- rt != rs.\n\n    bgeuc_3 =\t\"18000000STB\",\t-- rs != rt.\n    bleuc_3 =\t\"18000000TSB\",\t-- rt != rs.\n    bltuc_3 =\t\"1c000000STB\",\t-- rs != rt.\n    bgtuc_3 =\t\"1c000000TSB\",\t-- rt != rs.\n\n    beqzalc_2 =\t\"20000000TB\",\t-- rt != 0.\n    bnezalc_2 =\t\"60000000TB\",\t-- rt != 0.\n    beqc_3 =\t\"20000000STB\",\t-- rs < rt.\n    bnec_3 =\t\"60000000STB\",\t-- rs < rt.\n    bovc_3 =\t\"20000000STB\",\t-- rs >= rt.\n    bnvc_3 =\t\"60000000STB\",\t-- rs >= rt.\n\n    beqzc_2 =\t\"d8000000SK\",\t-- rs != 0.\n    bnezc_2 =\t\"f8000000SK\",\t-- rs != 0.\n    jic_2 =\t\"d8000000TI\",\n    jialc_2 =\t\"f8000000TI\",\n    bc_1 =\t\"c8000000L\",\n    balc_1 =\t\"e8000000L\",\n\n    -- Opcode SPECIAL.\n    jr_1 =\t\"00000009S\",\n    sdbbp_0 =\t\"0000000e\",\n    sdbbp_1 =\t\"0000000eY\",\n    lsa_4 =\t\"00000005DSTA\",\n    dlsa_4 =\tmips64 and \"00000015DSTA\",\n    seleqz_3 =\t\"00000035DST\",\n    selnez_3 =\t\"00000037DST\",\n    clz_2 =\t\"00000050DS\",\n    clo_2 =\t\"00000051DS\",\n    dclz_2 =\tmips64 and \"00000052DS\",\n    dclo_2 =\tmips64 and \"00000053DS\",\n    mul_3 =\t\"00000098DST\",\n    muh_3 =\t\"000000d8DST\",\n    mulu_3 =\t\"00000099DST\",\n    muhu_3 =\t\"000000d9DST\",\n    div_3 =\t\"0000009aDST\",\n    mod_3 =\t\"000000daDST\",\n    divu_3 =\t\"0000009bDST\",\n    modu_3 =\t\"000000dbDST\",\n    dmul_3 =\tmips64 and \"0000009cDST\",\n    dmuh_3 =\tmips64 and \"000000dcDST\",\n    dmulu_3 =\tmips64 and \"0000009dDST\",\n    dmuhu_3 =\tmips64 and \"000000ddDST\",\n    ddiv_3 =\tmips64 and \"0000009eDST\",\n    dmod_3 =\tmips64 and \"000000deDST\",\n    ddivu_3 =\tmips64 and \"0000009fDST\",\n    dmodu_3 =\tmips64 and \"000000dfDST\",\n\n    -- Opcode SPECIAL3.\n    align_4 =\t\t\"7c000220DSTA\",\n    dalign_4 =\t\tmips64 and \"7c000224DSTA\",\n    bitswap_2 =\t\t\"7c000020DT\",\n    dbitswap_2 =\tmips64 and \"7c000024DT\",\n\n    -- Opcode COP1.\n    bc1eqz_2 =\t\"45200000HB\",\n    bc1nez_2 =\t\"45a00000HB\",\n\n    [\"sel.s_3\"] =\t\"46000010FGH\",\n    [\"seleqz.s_3\"] =\t\"46000014FGH\",\n    [\"selnez.s_3\"] =\t\"46000017FGH\",\n    [\"maddf.s_3\"] =\t\"46000018FGH\",\n    [\"msubf.s_3\"] =\t\"46000019FGH\",\n    [\"rint.s_2\"] =\t\"4600001aFG\",\n    [\"class.s_2\"] =\t\"4600001bFG\",\n    [\"min.s_3\"] =\t\"4600001cFGH\",\n    [\"mina.s_3\"] =\t\"4600001dFGH\",\n    [\"max.s_3\"] =\t\"4600001eFGH\",\n    [\"maxa.s_3\"] =\t\"4600001fFGH\",\n    [\"cmp.af.s_3\"] =\t\"46800000FGH\",\n    [\"cmp.un.s_3\"] =\t\"46800001FGH\",\n    [\"cmp.or.s_3\"] =\t\"46800011FGH\",\n    [\"cmp.eq.s_3\"] =\t\"46800002FGH\",\n    [\"cmp.une.s_3\"] =\t\"46800012FGH\",\n    [\"cmp.ueq.s_3\"] =\t\"46800003FGH\",\n    [\"cmp.ne.s_3\"] =\t\"46800013FGH\",\n    [\"cmp.lt.s_3\"] =\t\"46800004FGH\",\n    [\"cmp.ult.s_3\"] =\t\"46800005FGH\",\n    [\"cmp.le.s_3\"] =\t\"46800006FGH\",\n    [\"cmp.ule.s_3\"] =\t\"46800007FGH\",\n    [\"cmp.saf.s_3\"] =\t\"46800008FGH\",\n    [\"cmp.sun.s_3\"] =\t\"46800009FGH\",\n    [\"cmp.sor.s_3\"] =\t\"46800019FGH\",\n    [\"cmp.seq.s_3\"] =\t\"4680000aFGH\",\n    [\"cmp.sune.s_3\"] =\t\"4680001aFGH\",\n    [\"cmp.sueq.s_3\"] =\t\"4680000bFGH\",\n    [\"cmp.sne.s_3\"] =\t\"4680001bFGH\",\n    [\"cmp.slt.s_3\"] =\t\"4680000cFGH\",\n    [\"cmp.sult.s_3\"] =\t\"4680000dFGH\",\n    [\"cmp.sle.s_3\"] =\t\"4680000eFGH\",\n    [\"cmp.sule.s_3\"] =\t\"4680000fFGH\",\n\n    [\"sel.d_3\"] =\t\"46200010FGH\",\n    [\"seleqz.d_3\"] =\t\"46200014FGH\",\n    [\"selnez.d_3\"] =\t\"46200017FGH\",\n    [\"maddf.d_3\"] =\t\"46200018FGH\",\n    [\"msubf.d_3\"] =\t\"46200019FGH\",\n    [\"rint.d_2\"] =\t\"4620001aFG\",\n    [\"class.d_2\"] =\t\"4620001bFG\",\n    [\"min.d_3\"] =\t\"4620001cFGH\",\n    [\"mina.d_3\"] =\t\"4620001dFGH\",\n    [\"max.d_3\"] =\t\"4620001eFGH\",\n    [\"maxa.d_3\"] =\t\"4620001fFGH\",\n    [\"cmp.af.d_3\"] =\t\"46a00000FGH\",\n    [\"cmp.un.d_3\"] =\t\"46a00001FGH\",\n    [\"cmp.or.d_3\"] =\t\"46a00011FGH\",\n    [\"cmp.eq.d_3\"] =\t\"46a00002FGH\",\n    [\"cmp.une.d_3\"] =\t\"46a00012FGH\",\n    [\"cmp.ueq.d_3\"] =\t\"46a00003FGH\",\n    [\"cmp.ne.d_3\"] =\t\"46a00013FGH\",\n    [\"cmp.lt.d_3\"] =\t\"46a00004FGH\",\n    [\"cmp.ult.d_3\"] =\t\"46a00005FGH\",\n    [\"cmp.le.d_3\"] =\t\"46a00006FGH\",\n    [\"cmp.ule.d_3\"] =\t\"46a00007FGH\",\n    [\"cmp.saf.d_3\"] =\t\"46a00008FGH\",\n    [\"cmp.sun.d_3\"] =\t\"46a00009FGH\",\n    [\"cmp.sor.d_3\"] =\t\"46a00019FGH\",\n    [\"cmp.seq.d_3\"] =\t\"46a0000aFGH\",\n    [\"cmp.sune.d_3\"] =\t\"46a0001aFGH\",\n    [\"cmp.sueq.d_3\"] =\t\"46a0000bFGH\",\n    [\"cmp.sne.d_3\"] =\t\"46a0001bFGH\",\n    [\"cmp.slt.d_3\"] =\t\"46a0000cFGH\",\n    [\"cmp.sult.d_3\"] =\t\"46a0000dFGH\",\n    [\"cmp.sle.d_3\"] =\t\"46a0000eFGH\",\n    [\"cmp.sule.d_3\"] =\t\"46a0000fFGH\",\n\n  }) do map_op[k] = v end\n\nelse -- Instructions removed by MIPSR6.\n\n  for k,v in pairs({\n    -- Traps, don't use.\n    addi_3 =\t\"20000000TSI\",\n    daddi_3 =\tmips64 and \"60000000TSI\",\n\n    -- Branch on likely, don't use.\n    beqzl_2 =\t\"50000000SB\",\n    beql_3 =\t\"50000000STB\",\n    bnezl_2 =\t\"54000000SB\",\n    bnel_3 =\t\"54000000STB\",\n    blezl_2 =\t\"58000000SB\",\n    bgtzl_2 =\t\"5c000000SB\",\n\n    lwl_2 =\t\"88000000TO\",\n    lwr_2 =\t\"98000000TO\",\n    swl_2 =\t\"a8000000TO\",\n    sdl_2 =\tmips64 and \"b0000000TO\",\n    sdr_2 =\tmips64 and \"b1000000TO\",\n    swr_2 =\t\"b8000000TO\",\n    cache_2 =\t\"bc000000NO\",\n    ll_2 =\t\"c0000000TO\",\n    pref_2 =\t\"cc000000NO\",\n    sc_2 =\t\"e0000000TO\",\n    scd_2 =\tmips64 and \"f0000000TO\",\n\n    -- Opcode SPECIAL.\n    movf_2 =\t\"00000001DS\",\n    movf_3 =\t\"00000001DSC\",\n    movt_2 =\t\"00010001DS\",\n    movt_3 =\t\"00010001DSC\",\n    jr_1 =\t\"00000008S\",\n    movz_3 =\t\"0000000aDST\",\n    movn_3 =\t\"0000000bDST\",\n    mfhi_1 =\t\"00000010D\",\n    mthi_1 =\t\"00000011S\",\n    mflo_1 =\t\"00000012D\",\n    mtlo_1 =\t\"00000013S\",\n    mult_2 =\t\"00000018ST\",\n    multu_2 =\t\"00000019ST\",\n    div_3 =\t\"0000001aST\",\n    divu_3 =\t\"0000001bST\",\n    ddiv_3 =\tmips64 and \"0000001eST\",\n    ddivu_3 =\tmips64 and \"0000001fST\",\n    dmult_2 =\tmips64 and \"0000001cST\",\n    dmultu_2 =\tmips64 and \"0000001dST\",\n\n    -- Opcode REGIMM.\n    tgei_2 =\t\"04080000SI\",\n    tgeiu_2 =\t\"04090000SI\",\n    tlti_2 =\t\"040a0000SI\",\n    tltiu_2 =\t\"040b0000SI\",\n    teqi_2 =\t\"040c0000SI\",\n    tnei_2 =\t\"040e0000SI\",\n    bltzal_2 =\t\"04100000SB\",\n    bgezal_2 =\t\"04110000SB\",\n    bltzall_2 =\t\"04120000SB\",\n    bgezall_2 =\t\"04130000SB\",\n\n    -- Opcode SPECIAL2.\n    madd_2 =\t\"70000000ST\",\n    maddu_2 =\t\"70000001ST\",\n    mul_3 =\t\"70000002DST\",\n    msub_2 =\t\"70000004ST\",\n    msubu_2 =\t\"70000005ST\",\n    clz_2 =\t\"70000020D=TS\",\n    clo_2 =\t\"70000021D=TS\",\n    dclz_2 =\tmips64 and \"70000024D=TS\",\n    dclo_2 =\tmips64 and \"70000025D=TS\",\n    sdbbp_0 =\t\"7000003f\",\n    sdbbp_1 =\t\"7000003fY\",\n\n    -- Opcode COP1.\n    bc1f_1 =\t\"45000000B\",\n    bc1f_2 =\t\"45000000CB\",\n    bc1t_1 =\t\"45010000B\",\n    bc1t_2 =\t\"45010000CB\",\n    bc1fl_1 =\t\"45020000B\",\n    bc1fl_2 =\t\"45020000CB\",\n    bc1tl_1 =\t\"45030000B\",\n    bc1tl_2 =\t\"45030000CB\",\n\n    [\"movf.s_2\"] =\t\"46000011FG\",\n    [\"movf.s_3\"] =\t\"46000011FGC\",\n    [\"movt.s_2\"] =\t\"46010011FG\",\n    [\"movt.s_3\"] =\t\"46010011FGC\",\n    [\"movz.s_3\"] =\t\"46000012FGT\",\n    [\"movn.s_3\"] =\t\"46000013FGT\",\n    [\"cvt.ps.s_3\"] =\t\"46000026FGH\",\n    [\"c.f.s_2\"] =\t\"46000030GH\",\n    [\"c.f.s_3\"] =\t\"46000030VGH\",\n    [\"c.un.s_2\"] =\t\"46000031GH\",\n    [\"c.un.s_3\"] =\t\"46000031VGH\",\n    [\"c.eq.s_2\"] =\t\"46000032GH\",\n    [\"c.eq.s_3\"] =\t\"46000032VGH\",\n    [\"c.ueq.s_2\"] =\t\"46000033GH\",\n    [\"c.ueq.s_3\"] =\t\"46000033VGH\",\n    [\"c.olt.s_2\"] =\t\"46000034GH\",\n    [\"c.olt.s_3\"] =\t\"46000034VGH\",\n    [\"c.ult.s_2\"] =\t\"46000035GH\",\n    [\"c.ult.s_3\"] =\t\"46000035VGH\",\n    [\"c.ole.s_2\"] =\t\"46000036GH\",\n    [\"c.ole.s_3\"] =\t\"46000036VGH\",\n    [\"c.ule.s_2\"] =\t\"46000037GH\",\n    [\"c.ule.s_3\"] =\t\"46000037VGH\",\n    [\"c.sf.s_2\"] =\t\"46000038GH\",\n    [\"c.sf.s_3\"] =\t\"46000038VGH\",\n    [\"c.ngle.s_2\"] =\t\"46000039GH\",\n    [\"c.ngle.s_3\"] =\t\"46000039VGH\",\n    [\"c.seq.s_2\"] =\t\"4600003aGH\",\n    [\"c.seq.s_3\"] =\t\"4600003aVGH\",\n    [\"c.ngl.s_2\"] =\t\"4600003bGH\",\n    [\"c.ngl.s_3\"] =\t\"4600003bVGH\",\n    [\"c.lt.s_2\"] =\t\"4600003cGH\",\n    [\"c.lt.s_3\"] =\t\"4600003cVGH\",\n    [\"c.nge.s_2\"] =\t\"4600003dGH\",\n    [\"c.nge.s_3\"] =\t\"4600003dVGH\",\n    [\"c.le.s_2\"] =\t\"4600003eGH\",\n    [\"c.le.s_3\"] =\t\"4600003eVGH\",\n    [\"c.ngt.s_2\"] =\t\"4600003fGH\",\n    [\"c.ngt.s_3\"] =\t\"4600003fVGH\",\n    [\"movf.d_2\"] =\t\"46200011FG\",\n    [\"movf.d_3\"] =\t\"46200011FGC\",\n    [\"movt.d_2\"] =\t\"46210011FG\",\n    [\"movt.d_3\"] =\t\"46210011FGC\",\n    [\"movz.d_3\"] =\t\"46200012FGT\",\n    [\"movn.d_3\"] =\t\"46200013FGT\",\n    [\"c.f.d_2\"] =\t\"46200030GH\",\n    [\"c.f.d_3\"] =\t\"46200030VGH\",\n    [\"c.un.d_2\"] =\t\"46200031GH\",\n    [\"c.un.d_3\"] =\t\"46200031VGH\",\n    [\"c.eq.d_2\"] =\t\"46200032GH\",\n    [\"c.eq.d_3\"] =\t\"46200032VGH\",\n    [\"c.ueq.d_2\"] =\t\"46200033GH\",\n    [\"c.ueq.d_3\"] =\t\"46200033VGH\",\n    [\"c.olt.d_2\"] =\t\"46200034GH\",\n    [\"c.olt.d_3\"] =\t\"46200034VGH\",\n    [\"c.ult.d_2\"] =\t\"46200035GH\",\n    [\"c.ult.d_3\"] =\t\"46200035VGH\",\n    [\"c.ole.d_2\"] =\t\"46200036GH\",\n    [\"c.ole.d_3\"] =\t\"46200036VGH\",\n    [\"c.ule.d_2\"] =\t\"46200037GH\",\n    [\"c.ule.d_3\"] =\t\"46200037VGH\",\n    [\"c.sf.d_2\"] =\t\"46200038GH\",\n    [\"c.sf.d_3\"] =\t\"46200038VGH\",\n    [\"c.ngle.d_2\"] =\t\"46200039GH\",\n    [\"c.ngle.d_3\"] =\t\"46200039VGH\",\n    [\"c.seq.d_2\"] =\t\"4620003aGH\",\n    [\"c.seq.d_3\"] =\t\"4620003aVGH\",\n    [\"c.ngl.d_2\"] =\t\"4620003bGH\",\n    [\"c.ngl.d_3\"] =\t\"4620003bVGH\",\n    [\"c.lt.d_2\"] =\t\"4620003cGH\",\n    [\"c.lt.d_3\"] =\t\"4620003cVGH\",\n    [\"c.nge.d_2\"] =\t\"4620003dGH\",\n    [\"c.nge.d_3\"] =\t\"4620003dVGH\",\n    [\"c.le.d_2\"] =\t\"4620003eGH\",\n    [\"c.le.d_3\"] =\t\"4620003eVGH\",\n    [\"c.ngt.d_2\"] =\t\"4620003fGH\",\n    [\"c.ngt.d_3\"] =\t\"4620003fVGH\",\n    [\"add.ps_3\"] =\t\"46c00000FGH\",\n    [\"sub.ps_3\"] =\t\"46c00001FGH\",\n    [\"mul.ps_3\"] =\t\"46c00002FGH\",\n    [\"abs.ps_2\"] =\t\"46c00005FG\",\n    [\"mov.ps_2\"] =\t\"46c00006FG\",\n    [\"neg.ps_2\"] =\t\"46c00007FG\",\n    [\"movf.ps_2\"] =\t\"46c00011FG\",\n    [\"movf.ps_3\"] =\t\"46c00011FGC\",\n    [\"movt.ps_2\"] =\t\"46c10011FG\",\n    [\"movt.ps_3\"] =\t\"46c10011FGC\",\n    [\"movz.ps_3\"] =\t\"46c00012FGT\",\n    [\"movn.ps_3\"] =\t\"46c00013FGT\",\n    [\"cvt.s.pu_2\"] =\t\"46c00020FG\",\n    [\"cvt.s.pl_2\"] =\t\"46c00028FG\",\n    [\"pll.ps_3\"] =\t\"46c0002cFGH\",\n    [\"plu.ps_3\"] =\t\"46c0002dFGH\",\n    [\"pul.ps_3\"] =\t\"46c0002eFGH\",\n    [\"puu.ps_3\"] =\t\"46c0002fFGH\",\n    [\"c.f.ps_2\"] =\t\"46c00030GH\",\n    [\"c.f.ps_3\"] =\t\"46c00030VGH\",\n    [\"c.un.ps_2\"] =\t\"46c00031GH\",\n    [\"c.un.ps_3\"] =\t\"46c00031VGH\",\n    [\"c.eq.ps_2\"] =\t\"46c00032GH\",\n    [\"c.eq.ps_3\"] =\t\"46c00032VGH\",\n    [\"c.ueq.ps_2\"] =\t\"46c00033GH\",\n    [\"c.ueq.ps_3\"] =\t\"46c00033VGH\",\n    [\"c.olt.ps_2\"] =\t\"46c00034GH\",\n    [\"c.olt.ps_3\"] =\t\"46c00034VGH\",\n    [\"c.ult.ps_2\"] =\t\"46c00035GH\",\n    [\"c.ult.ps_3\"] =\t\"46c00035VGH\",\n    [\"c.ole.ps_2\"] =\t\"46c00036GH\",\n    [\"c.ole.ps_3\"] =\t\"46c00036VGH\",\n    [\"c.ule.ps_2\"] =\t\"46c00037GH\",\n    [\"c.ule.ps_3\"] =\t\"46c00037VGH\",\n    [\"c.sf.ps_2\"] =\t\"46c00038GH\",\n    [\"c.sf.ps_3\"] =\t\"46c00038VGH\",\n    [\"c.ngle.ps_2\"] =\t\"46c00039GH\",\n    [\"c.ngle.ps_3\"] =\t\"46c00039VGH\",\n    [\"c.seq.ps_2\"] =\t\"46c0003aGH\",\n    [\"c.seq.ps_3\"] =\t\"46c0003aVGH\",\n    [\"c.ngl.ps_2\"] =\t\"46c0003bGH\",\n    [\"c.ngl.ps_3\"] =\t\"46c0003bVGH\",\n    [\"c.lt.ps_2\"] =\t\"46c0003cGH\",\n    [\"c.lt.ps_3\"] =\t\"46c0003cVGH\",\n    [\"c.nge.ps_2\"] =\t\"46c0003dGH\",\n    [\"c.nge.ps_3\"] =\t\"46c0003dVGH\",\n    [\"c.le.ps_2\"] =\t\"46c0003eGH\",\n    [\"c.le.ps_3\"] =\t\"46c0003eVGH\",\n    [\"c.ngt.ps_2\"] =\t\"46c0003fGH\",\n    [\"c.ngt.ps_3\"] =\t\"46c0003fVGH\",\n\n    -- Opcode COP1X.\n    lwxc1_2 =\t\"4c000000FX\",\n    ldxc1_2 =\t\"4c000001FX\",\n    luxc1_2 =\t\"4c000005FX\",\n    swxc1_2 =\t\"4c000008FX\",\n    sdxc1_2 =\t\"4c000009FX\",\n    suxc1_2 =\t\"4c00000dFX\",\n    prefx_2 =\t\"4c00000fMX\",\n    [\"alnv.ps_4\"] =\t\"4c00001eFGHS\",\n    [\"madd.s_4\"] =\t\"4c000020FRGH\",\n    [\"madd.d_4\"] =\t\"4c000021FRGH\",\n    [\"madd.ps_4\"] =\t\"4c000026FRGH\",\n    [\"msub.s_4\"] =\t\"4c000028FRGH\",\n    [\"msub.d_4\"] =\t\"4c000029FRGH\",\n    [\"msub.ps_4\"] =\t\"4c00002eFRGH\",\n    [\"nmadd.s_4\"] =\t\"4c000030FRGH\",\n    [\"nmadd.d_4\"] =\t\"4c000031FRGH\",\n    [\"nmadd.ps_4\"] =\t\"4c000036FRGH\",\n    [\"nmsub.s_4\"] =\t\"4c000038FRGH\",\n    [\"nmsub.d_4\"] =\t\"4c000039FRGH\",\n    [\"nmsub.ps_4\"] =\t\"4c00003eFRGH\",\n\n  }) do map_op[k] = v end\n\nend\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r[1-3]?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_fpr(expr)\n  local r = match(expr, \"^f([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed, action)\n  local n = tonumber(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^[rf]([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):([rf][1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(action or \"IMM\",\n\t    (signed and 32768 or 0)+shl(scale, 10)+shl(bits, 5)+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_disp(disp)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = shl(parse_gpr(reg), 21)\n    local extname = match(imm, \"^extern%s+(%S+)$\")\n    if extname then\n      waction(\"REL_EXT\", map_extern[extname], nil, 1)\n      return r\n    else\n      return r + parse_imm(imm, 16, 0, 0, true)\n    end\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if tp then\n      waction(\"IMM\", 32768+16*32, format(tp.ctypefmt, tailr))\n      return shl(r, 21)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_index(idx)\n  local rt, rs = match(idx, \"^(.*)%(([%w_:]+)%)$\")\n  if rt then\n    rt = parse_gpr(rt)\n    rs = parse_gpr(rs)\n    return shl(rt, 16) + shl(rs, 21)\n  end\n  werror(\"bad index `\"..idx..\"'\")\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return sub(template, 9) end\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n = 1\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 2 positions (ins/ext).\n  if secpos+2 > maxsecpos then wflush() end\n  local pos = wpos()\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    if p == \"D\" then\n      op = op + shl(parse_gpr(params[n]), 11); n = n + 1\n    elseif p == \"T\" then\n      op = op + shl(parse_gpr(params[n]), 16); n = n + 1\n    elseif p == \"S\" then\n      op = op + shl(parse_gpr(params[n]), 21); n = n + 1\n    elseif p == \"F\" then\n      op = op + shl(parse_fpr(params[n]), 6); n = n + 1\n    elseif p == \"G\" then\n      op = op + shl(parse_fpr(params[n]), 11); n = n + 1\n    elseif p == \"H\" then\n      op = op + shl(parse_fpr(params[n]), 16); n = n + 1\n    elseif p == \"R\" then\n      op = op + shl(parse_fpr(params[n]), 21); n = n + 1\n    elseif p == \"I\" then\n      op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1\n    elseif p == \"U\" then\n      op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1\n    elseif p == \"O\" then\n      op = op + parse_disp(params[n]); n = n + 1\n    elseif p == \"X\" then\n      op = op + parse_index(params[n]); n = n + 1\n    elseif p == \"B\" or p == \"J\" or p == \"K\" or p == \"L\" then\n      local mode, m, s = parse_label(params[n], false)\n      if p == \"J\" then m = m + 0xa800\n      elseif p == \"K\" then m = m + 0x5000\n      elseif p == \"L\" then m = m + 0xa000 end\n      waction(\"REL_\"..mode, m, s, 1)\n      n = n + 1\n    elseif p == \"A\" then\n      op = op + parse_imm(params[n], 5, 6, 0, false); n = n + 1\n    elseif p == \"a\" then\n      local m = parse_imm(params[n], 6, 6, 0, false, \"IMMS\"); n = n + 1\n      op = op + band(m, 0x7c0) + band(shr(m, 9), 4)\n    elseif p == \"M\" then\n      op = op + parse_imm(params[n], 5, 11, 0, false); n = n + 1\n    elseif p == \"N\" then\n      op = op + parse_imm(params[n], 5, 16, 0, false); n = n + 1\n    elseif p == \"C\" then\n      op = op + parse_imm(params[n], 3, 18, 0, false); n = n + 1\n    elseif p == \"V\" then\n      op = op + parse_imm(params[n], 3, 8, 0, false); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_imm(params[n], 3, 0, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      op = op + parse_imm(params[n], 20, 6, 0, false); n = n + 1\n    elseif p == \"Z\" then\n      op = op + parse_imm(params[n], 10, 6, 0, false); n = n + 1\n    elseif p == \"=\" then\n      n = n - 1 -- Re-use previous parameter for next template char.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_mips64.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM MIPS64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n-- This module just sets 64 bit mode for the combined MIPS/MIPS64 module.\n-- All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nmips64 = true -- Using a global is an ugly, but effective solution.\nreturn require(\"dasm_mips\")\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_ppc.h",
    "content": "/*\n** DynASM PPC/PPC64 encoding engine.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"ppc\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC, DASM_IMM, DASM_IMMSH,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned int *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned int ins = *p++;\n    unsigned int action = (ins >> 16);\n    if (action >= DASM__MAX) {\n      ofs += 4;\n    } else {\n      int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n      switch (action) {\n      case DASM_STOP: goto stop;\n      case DASM_SECTION:\n\tn = (ins & 255); CK(n < D->maxsection, RANGE_SEC);\n\tD->section = &D->sections[n]; goto stop;\n      case DASM_ESC: p++; ofs += 4; break;\n      case DASM_REL_EXT: break;\n      case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;\n      case DASM_REL_LG:\n\tn = (ins & 2047) - 10; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl += 10; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tbreak;\n      case DASM_LABEL_LG:\n\tpl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC:\n\tpl = D->pclabels + n; CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;\n\t}\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_IMM:\n#ifdef DASM_CHECKS\n\tCK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);\n#endif\n\tn >>= ((ins>>10)&31);\n#ifdef DASM_CHECKS\n\tif (ins & 0x8000)\n\t  CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);\n\telse\n\t  CK((n>>((ins>>5)&31)) == 0, RANGE_I);\n#endif\n\tb[pos++] = n;\n\tbreak;\n      case DASM_IMMSH:\n\tCK((n >> 6) == 0, RANGE_I);\n\tb[pos++] = n;\n\tbreak;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: p++; break;\n\tcase DASM_REL_EXT: break;\n\tcase DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;\n\tcase DASM_REL_LG: case DASM_REL_PC: pos++; break;\n\tcase DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;\n\tcase DASM_IMM: case DASM_IMMSH: pos++; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned int *cp = (unsigned int *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n\tunsigned int ins = *p++;\n\tunsigned int action = (ins >> 16);\n\tint n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_STOP: case DASM_SECTION: goto stop;\n\tcase DASM_ESC: *cp++ = *p++; break;\n\tcase DASM_REL_EXT:\n\t  n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;\n\t  goto patchrel;\n\tcase DASM_ALIGN:\n\t  ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;\n\t  break;\n\tcase DASM_REL_LG:\n\t  if (n < 0) {\n\t    n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp);\n\t    goto patchrel;\n\t  }\n\t  /* fallthrough */\n\tcase DASM_REL_PC:\n\t  CK(n >= 0, UNDEF_PC);\n\t  n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);\n\tpatchrel:\n\t  CK((n & 3) == 0 &&\n\t      (((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>\n\t       ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);\n\t  cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));\n\t  break;\n\tcase DASM_LABEL_LG:\n\t  ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);\n\t  break;\n\tcase DASM_LABEL_PC: break;\n\tcase DASM_IMM:\n\t  cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);\n\t  break;\n\tcase DASM_IMMSH:\n\t  cp[-1] |= (ins & 1) ? ((n&31)<<11)|((n&32)>>4) : ((n&31)<<6)|(n&32);\n\t  break;\n\tdefault: *cp++ = ins; break;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_ppc.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM PPC/PPC64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n--\n-- Support for various extensions contributed by Caio Souza Oliveira.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"ppc\",\n  description =\t\"DynASM PPC module\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable = assert, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch = _s.match, _s.gmatch\nlocal concat, sort = table.concat, table.sort\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal tohex = bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"IMM\", \"IMMSH\"\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nfor n,name in ipairs(action_names) do\n  map_action[name] = n-1\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned int \", name, \"[\", nn, \"] = {\\n\")\n  for i = 1,nn-1 do\n    assert(out:write(\"0x\", tohex(actlist[i]), \",\\n\"))\n  end\n  assert(out:write(\"0x\", tohex(actlist[nn]), \"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add word to action list.\nlocal function wputxw(n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxw(w * 0x10000 + (val or 0))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped word.\nlocal function wputw(n)\n  if n <= 0xffffff then waction(\"ESC\") end\n  wputxw(n)\nend\n\n-- Reserve position for word.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n-- Store word to reserved position.\nlocal function wputpos(pos, n)\n  assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, \"word out of range\")\n  actlist[pos] = n\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0,next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0,next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = { sp = \"r1\" } -- Ext. register name -> int. name.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  if s == \"r1\" then return \"sp\" end\n  return s\nend\n\nlocal map_cond = {\n  lt = 0, gt = 1, eq = 2, so = 3,\n  ge = 4, le = 5, ne = 6, ns = 7,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_op, op_template\n\nlocal function op_alias(opname, f)\n  return function(params, nparams)\n    if not params then return \"-> \"..opname:sub(1, -3) end\n    f(params, nparams)\n    op_template(params, map_op[opname], nparams)\n  end\nend\n\n-- Template strings for PPC instructions.\nmap_op = {\n  tdi_3 =\t\"08000000ARI\",\n  twi_3 =\t\"0c000000ARI\",\n  mulli_3 =\t\"1c000000RRI\",\n  subfic_3 =\t\"20000000RRI\",\n  cmplwi_3 =\t\"28000000XRU\",\n  cmplwi_2 =\t\"28000000-RU\",\n  cmpldi_3 =\t\"28200000XRU\",\n  cmpldi_2 =\t\"28200000-RU\",\n  cmpwi_3 =\t\"2c000000XRI\",\n  cmpwi_2 =\t\"2c000000-RI\",\n  cmpdi_3 =\t\"2c200000XRI\",\n  cmpdi_2 =\t\"2c200000-RI\",\n  addic_3 =\t\"30000000RRI\",\n  [\"addic._3\"] = \"34000000RRI\",\n  addi_3 =\t\"38000000RR0I\",\n  li_2 =\t\"38000000RI\",\n  la_2 =\t\"38000000RD\",\n  addis_3 =\t\"3c000000RR0I\",\n  lis_2 =\t\"3c000000RI\",\n  lus_2 =\t\"3c000000RU\",\n  bc_3 =\t\"40000000AAK\",\n  bcl_3 =\t\"40000001AAK\",\n  bdnz_1 =\t\"42000000K\",\n  bdz_1 =\t\"42400000K\",\n  sc_0 =\t\"44000000\",\n  b_1 =\t\t\"48000000J\",\n  bl_1 =\t\"48000001J\",\n  rlwimi_5 =\t\"50000000RR~AAA.\",\n  rlwinm_5 =\t\"54000000RR~AAA.\",\n  rlwnm_5 =\t\"5c000000RR~RAA.\",\n  ori_3 =\t\"60000000RR~U\",\n  nop_0 =\t\"60000000\",\n  oris_3 =\t\"64000000RR~U\",\n  xori_3 =\t\"68000000RR~U\",\n  xoris_3 =\t\"6c000000RR~U\",\n  [\"andi._3\"] =\t\"70000000RR~U\",\n  [\"andis._3\"] = \"74000000RR~U\",\n  lwz_2 =\t\"80000000RD\",\n  lwzu_2 =\t\"84000000RD\",\n  lbz_2 =\t\"88000000RD\",\n  lbzu_2 =\t\"8c000000RD\",\n  stw_2 =\t\"90000000RD\",\n  stwu_2 =\t\"94000000RD\",\n  stb_2 =\t\"98000000RD\",\n  stbu_2 =\t\"9c000000RD\",\n  lhz_2 =\t\"a0000000RD\",\n  lhzu_2 =\t\"a4000000RD\",\n  lha_2 =\t\"a8000000RD\",\n  lhau_2 =\t\"ac000000RD\",\n  sth_2 =\t\"b0000000RD\",\n  sthu_2 =\t\"b4000000RD\",\n  lmw_2 =\t\"b8000000RD\",\n  stmw_2 =\t\"bc000000RD\",\n  lfs_2 =\t\"c0000000FD\",\n  lfsu_2 =\t\"c4000000FD\",\n  lfd_2 =\t\"c8000000FD\",\n  lfdu_2 =\t\"cc000000FD\",\n  stfs_2 =\t\"d0000000FD\",\n  stfsu_2 =\t\"d4000000FD\",\n  stfd_2 =\t\"d8000000FD\",\n  stfdu_2 =\t\"dc000000FD\",\n  ld_2 =\t\"e8000000RD\", -- NYI: displacement must be divisible by 4.\n  ldu_2 =\t\"e8000001RD\",\n  lwa_2 =\t\"e8000002RD\",\n  std_2 =\t\"f8000000RD\",\n  stdu_2 =\t\"f8000001RD\",\n\n  subi_3 =\top_alias(\"addi_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  subis_3 =\top_alias(\"addis_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  subic_3 =\top_alias(\"addic_3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n  [\"subic._3\"] = op_alias(\"addic._3\", function(p) p[3] = \"-(\"..p[3]..\")\" end),\n\n  rotlwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = \"0\"; p[5] = \"31\"\n  end),\n  rotrwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[3] = \"32-(\"..p[3]..\")\"; p[4] = \"0\"; p[5] = \"31\"\n  end),\n  rotlw_3 =\top_alias(\"rlwnm_5\", function(p)\n    p[4] = \"0\"; p[5] = \"31\"\n  end),\n  slwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[5] = \"31-(\"..p[3]..\")\"; p[4] = \"0\"\n  end),\n  srwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = p[3]; p[3] = \"32-(\"..p[3]..\")\"; p[5] = \"31\"\n  end),\n  clrlwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[4] = p[3]; p[3] = \"0\"; p[5] = \"31\"\n  end),\n  clrrwi_3 =\top_alias(\"rlwinm_5\", function(p)\n    p[5] = \"31-(\"..p[3]..\")\"; p[3] = \"0\"; p[4] = \"0\"\n  end),\n\n  -- Primary opcode 4:\n  mulhhwu_3 =\t\t\"10000010RRR.\",\n  machhwu_3 =\t\t\"10000018RRR.\",\n  mulhhw_3 =\t\t\"10000050RRR.\",\n  nmachhw_3 =\t\t\"1000005cRRR.\",\n  machhwsu_3 =\t\t\"10000098RRR.\",\n  machhws_3 =\t\t\"100000d8RRR.\",\n  nmachhws_3 =\t\t\"100000dcRRR.\",\n  mulchwu_3 =\t\t\"10000110RRR.\",\n  macchwu_3 =\t\t\"10000118RRR.\",\n  mulchw_3 =\t\t\"10000150RRR.\",\n  macchw_3 =\t\t\"10000158RRR.\",\n  nmacchw_3 =\t\t\"1000015cRRR.\",\n  macchwsu_3 =\t\t\"10000198RRR.\",\n  macchws_3 =\t\t\"100001d8RRR.\",\n  nmacchws_3 =\t\t\"100001dcRRR.\",\n  mullhw_3 =\t\t\"10000350RRR.\",\n  maclhw_3 =\t\t\"10000358RRR.\",\n  nmaclhw_3 =\t\t\"1000035cRRR.\",\n  maclhwsu_3 =\t\t\"10000398RRR.\",\n  maclhws_3 =\t\t\"100003d8RRR.\",\n  nmaclhws_3 =\t\t\"100003dcRRR.\",\n  machhwuo_3 =\t\t\"10000418RRR.\",\n  nmachhwo_3 =\t\t\"1000045cRRR.\",\n  machhwsuo_3 =\t\t\"10000498RRR.\",\n  machhwso_3 =\t\t\"100004d8RRR.\",\n  nmachhwso_3 =\t\t\"100004dcRRR.\",\n  macchwuo_3 =\t\t\"10000518RRR.\",\n  macchwo_3 =\t\t\"10000558RRR.\",\n  nmacchwo_3 =\t\t\"1000055cRRR.\",\n  macchwsuo_3 =\t\t\"10000598RRR.\",\n  macchwso_3 =\t\t\"100005d8RRR.\",\n  nmacchwso_3 =\t\t\"100005dcRRR.\",\n  maclhwo_3 =\t\t\"10000758RRR.\",\n  nmaclhwo_3 =\t\t\"1000075cRRR.\",\n  maclhwsuo_3 =\t\t\"10000798RRR.\",\n  maclhwso_3 =\t\t\"100007d8RRR.\",\n  nmaclhwso_3 =\t\t\"100007dcRRR.\",\n\n  vaddubm_3 =\t\t\"10000000VVV\",\n  vmaxub_3 =\t\t\"10000002VVV\",\n  vrlb_3 =\t\t\"10000004VVV\",\n  vcmpequb_3 =\t\t\"10000006VVV\",\n  vmuloub_3 =\t\t\"10000008VVV\",\n  vaddfp_3 =\t\t\"1000000aVVV\",\n  vmrghb_3 =\t\t\"1000000cVVV\",\n  vpkuhum_3 =\t\t\"1000000eVVV\",\n  vmhaddshs_4 =\t\t\"10000020VVVV\",\n  vmhraddshs_4 =\t\"10000021VVVV\",\n  vmladduhm_4 =\t\t\"10000022VVVV\",\n  vmsumubm_4 =\t\t\"10000024VVVV\",\n  vmsummbm_4 =\t\t\"10000025VVVV\",\n  vmsumuhm_4 =\t\t\"10000026VVVV\",\n  vmsumuhs_4 =\t\t\"10000027VVVV\",\n  vmsumshm_4 =\t\t\"10000028VVVV\",\n  vmsumshs_4 =\t\t\"10000029VVVV\",\n  vsel_4 =\t\t\"1000002aVVVV\",\n  vperm_4 =\t\t\"1000002bVVVV\",\n  vsldoi_4 =\t\t\"1000002cVVVP\",\n  vpermxor_4 =\t\t\"1000002dVVVV\",\n  vmaddfp_4 =\t\t\"1000002eVVVV~\",\n  vnmsubfp_4 =\t\t\"1000002fVVVV~\",\n  vaddeuqm_4 =\t\t\"1000003cVVVV\",\n  vaddecuq_4 =\t\t\"1000003dVVVV\",\n  vsubeuqm_4 =\t\t\"1000003eVVVV\",\n  vsubecuq_4 =\t\t\"1000003fVVVV\",\n  vadduhm_3 =\t\t\"10000040VVV\",\n  vmaxuh_3 =\t\t\"10000042VVV\",\n  vrlh_3 =\t\t\"10000044VVV\",\n  vcmpequh_3 =\t\t\"10000046VVV\",\n  vmulouh_3 =\t\t\"10000048VVV\",\n  vsubfp_3 =\t\t\"1000004aVVV\",\n  vmrghh_3 =\t\t\"1000004cVVV\",\n  vpkuwum_3 =\t\t\"1000004eVVV\",\n  vadduwm_3 =\t\t\"10000080VVV\",\n  vmaxuw_3 =\t\t\"10000082VVV\",\n  vrlw_3 =\t\t\"10000084VVV\",\n  vcmpequw_3 =\t\t\"10000086VVV\",\n  vmulouw_3 =\t\t\"10000088VVV\",\n  vmuluwm_3 =\t\t\"10000089VVV\",\n  vmrghw_3 =\t\t\"1000008cVVV\",\n  vpkuhus_3 =\t\t\"1000008eVVV\",\n  vaddudm_3 =\t\t\"100000c0VVV\",\n  vmaxud_3 =\t\t\"100000c2VVV\",\n  vrld_3 =\t\t\"100000c4VVV\",\n  vcmpeqfp_3 =\t\t\"100000c6VVV\",\n  vcmpequd_3 =\t\t\"100000c7VVV\",\n  vpkuwus_3 =\t\t\"100000ceVVV\",\n  vadduqm_3 =\t\t\"10000100VVV\",\n  vmaxsb_3 =\t\t\"10000102VVV\",\n  vslb_3 =\t\t\"10000104VVV\",\n  vmulosb_3 =\t\t\"10000108VVV\",\n  vrefp_2 =\t\t\"1000010aV-V\",\n  vmrglb_3 =\t\t\"1000010cVVV\",\n  vpkshus_3 =\t\t\"1000010eVVV\",\n  vaddcuq_3 =\t\t\"10000140VVV\",\n  vmaxsh_3 =\t\t\"10000142VVV\",\n  vslh_3 =\t\t\"10000144VVV\",\n  vmulosh_3 =\t\t\"10000148VVV\",\n  vrsqrtefp_2 =\t\t\"1000014aV-V\",\n  vmrglh_3 =\t\t\"1000014cVVV\",\n  vpkswus_3 =\t\t\"1000014eVVV\",\n  vaddcuw_3 =\t\t\"10000180VVV\",\n  vmaxsw_3 =\t\t\"10000182VVV\",\n  vslw_3 =\t\t\"10000184VVV\",\n  vmulosw_3 =\t\t\"10000188VVV\",\n  vexptefp_2 =\t\t\"1000018aV-V\",\n  vmrglw_3 =\t\t\"1000018cVVV\",\n  vpkshss_3 =\t\t\"1000018eVVV\",\n  vmaxsd_3 =\t\t\"100001c2VVV\",\n  vsl_3 =\t\t\"100001c4VVV\",\n  vcmpgefp_3 =\t\t\"100001c6VVV\",\n  vlogefp_2 =\t\t\"100001caV-V\",\n  vpkswss_3 =\t\t\"100001ceVVV\",\n  vadduhs_3 =\t\t\"10000240VVV\",\n  vminuh_3 =\t\t\"10000242VVV\",\n  vsrh_3 =\t\t\"10000244VVV\",\n  vcmpgtuh_3 =\t\t\"10000246VVV\",\n  vmuleuh_3 =\t\t\"10000248VVV\",\n  vrfiz_2 =\t\t\"1000024aV-V\",\n  vsplth_3 =\t\t\"1000024cVV3\",\n  vupkhsh_2 =\t\t\"1000024eV-V\",\n  vminuw_3 =\t\t\"10000282VVV\",\n  vminud_3 =\t\t\"100002c2VVV\",\n  vcmpgtud_3 =\t\t\"100002c7VVV\",\n  vrfim_2 =\t\t\"100002caV-V\",\n  vcmpgtsb_3 =\t\t\"10000306VVV\",\n  vcfux_3 =\t\t\"1000030aVVA~\",\n  vaddshs_3 =\t\t\"10000340VVV\",\n  vminsh_3 =\t\t\"10000342VVV\",\n  vsrah_3 =\t\t\"10000344VVV\",\n  vcmpgtsh_3 =\t\t\"10000346VVV\",\n  vmulesh_3 =\t\t\"10000348VVV\",\n  vcfsx_3 =\t\t\"1000034aVVA~\",\n  vspltish_2 =\t\t\"1000034cVS\",\n  vupkhpx_2 =\t\t\"1000034eV-V\",\n  vaddsws_3 =\t\t\"10000380VVV\",\n  vminsw_3 =\t\t\"10000382VVV\",\n  vsraw_3 =\t\t\"10000384VVV\",\n  vcmpgtsw_3 =\t\t\"10000386VVV\",\n  vmulesw_3 =\t\t\"10000388VVV\",\n  vctuxs_3 =\t\t\"1000038aVVA~\",\n  vspltisw_2 =\t\t\"1000038cVS\",\n  vminsd_3 =\t\t\"100003c2VVV\",\n  vsrad_3 =\t\t\"100003c4VVV\",\n  vcmpbfp_3 =\t\t\"100003c6VVV\",\n  vcmpgtsd_3 =\t\t\"100003c7VVV\",\n  vctsxs_3 =\t\t\"100003caVVA~\",\n  vupklpx_2 =\t\t\"100003ceV-V\",\n  vsububm_3 =\t\t\"10000400VVV\",\n  [\"bcdadd._4\"] =\t\"10000401VVVy.\",\n  vavgub_3 =\t\t\"10000402VVV\",\n  vand_3 =\t\t\"10000404VVV\",\n  [\"vcmpequb._3\"] =\t\"10000406VVV\",\n  vmaxfp_3 =\t\t\"1000040aVVV\",\n  vsubuhm_3 =\t\t\"10000440VVV\",\n  [\"bcdsub._4\"] =\t\"10000441VVVy.\",\n  vavguh_3 =\t\t\"10000442VVV\",\n  vandc_3 =\t\t\"10000444VVV\",\n  [\"vcmpequh._3\"] =\t\"10000446VVV\",\n  vminfp_3 =\t\t\"1000044aVVV\",\n  vpkudum_3 =\t\t\"1000044eVVV\",\n  vsubuwm_3 =\t\t\"10000480VVV\",\n  vavguw_3 =\t\t\"10000482VVV\",\n  vor_3 =\t\t\"10000484VVV\",\n  [\"vcmpequw._3\"] =\t\"10000486VVV\",\n  vpmsumw_3 =\t\t\"10000488VVV\",\n  [\"vcmpeqfp._3\"] =\t\"100004c6VVV\",\n  [\"vcmpequd._3\"] =\t\"100004c7VVV\",\n  vpkudus_3 =\t\t\"100004ceVVV\",\n  vavgsb_3 =\t\t\"10000502VVV\",\n  vavgsh_3 =\t\t\"10000542VVV\",\n  vorc_3 =\t\t\"10000544VVV\",\n  vbpermq_3 =\t\t\"1000054cVVV\",\n  vpksdus_3 =\t\t\"1000054eVVV\",\n  vavgsw_3 =\t\t\"10000582VVV\",\n  vsld_3 =\t\t\"100005c4VVV\",\n  [\"vcmpgefp._3\"] =\t\"100005c6VVV\",\n  vpksdss_3 =\t\t\"100005ceVVV\",\n  vsububs_3 =\t\t\"10000600VVV\",\n  mfvscr_1 =\t\t\"10000604V--\",\n  vsum4ubs_3 =\t\t\"10000608VVV\",\n  vsubuhs_3 =\t\t\"10000640VVV\",\n  mtvscr_1 =\t\t\"10000644--V\",\n  [\"vcmpgtuh._3\"] =\t\"10000646VVV\",\n  vsum4shs_3 =\t\t\"10000648VVV\",\n  vupkhsw_2 =\t\t\"1000064eV-V\",\n  vsubuws_3 =\t\t\"10000680VVV\",\n  vshasigmaw_4 =\t\"10000682VVYp\",\n  veqv_3 =\t\t\"10000684VVV\",\n  vsum2sws_3 =\t\t\"10000688VVV\",\n  vmrgow_3 =\t\t\"1000068cVVV\",\n  vshasigmad_4 =\t\"100006c2VVYp\",\n  vsrd_3 =\t\t\"100006c4VVV\",\n  [\"vcmpgtud._3\"] =\t\"100006c7VVV\",\n  vupklsw_2 =\t\t\"100006ceV-V\",\n  vupkslw_2 =\t\t\"100006ceV-V\",\n  vsubsbs_3 =\t\t\"10000700VVV\",\n  vclzb_2 =\t\t\"10000702V-V\",\n  vpopcntb_2 =\t\t\"10000703V-V\",\n  [\"vcmpgtsb._3\"] =\t\"10000706VVV\",\n  vsum4sbs_3 =\t\t\"10000708VVV\",\n  vsubshs_3 =\t\t\"10000740VVV\",\n  vclzh_2 =\t\t\"10000742V-V\",\n  vpopcnth_2 =\t\t\"10000743V-V\",\n  [\"vcmpgtsh._3\"] =\t\"10000746VVV\",\n  vsubsws_3 =\t\t\"10000780VVV\",\n  vclzw_2 =\t\t\"10000782V-V\",\n  vpopcntw_2 =\t\t\"10000783V-V\",\n  [\"vcmpgtsw._3\"] =\t\"10000786VVV\",\n  vsumsws_3 =\t\t\"10000788VVV\",\n  vmrgew_3 =\t\t\"1000078cVVV\",\n  vclzd_2 =\t\t\"100007c2V-V\",\n  vpopcntd_2 =\t\t\"100007c3V-V\",\n  [\"vcmpbfp._3\"] =\t\"100007c6VVV\",\n  [\"vcmpgtsd._3\"] =\t\"100007c7VVV\",\n\n  -- Primary opcode 19:\n  mcrf_2 =\t\"4c000000XX\",\n  isync_0 =\t\"4c00012c\",\n  crnor_3 =\t\"4c000042CCC\",\n  crnot_2 =\t\"4c000042CC=\",\n  crandc_3 =\t\"4c000102CCC\",\n  crxor_3 =\t\"4c000182CCC\",\n  crclr_1 =\t\"4c000182C==\",\n  crnand_3 =\t\"4c0001c2CCC\",\n  crand_3 =\t\"4c000202CCC\",\n  creqv_3 =\t\"4c000242CCC\",\n  crset_1 =\t\"4c000242C==\",\n  crorc_3 =\t\"4c000342CCC\",\n  cror_3 =\t\"4c000382CCC\",\n  crmove_2 =\t\"4c000382CC=\",\n  bclr_2 =\t\"4c000020AA\",\n  bclrl_2 =\t\"4c000021AA\",\n  bcctr_2 =\t\"4c000420AA\",\n  bcctrl_2 =\t\"4c000421AA\",\n  bctar_2 =\t\"4c000460AA\",\n  bctarl_2 =\t\"4c000461AA\",\n  blr_0 =\t\"4e800020\",\n  blrl_0 =\t\"4e800021\",\n  bctr_0 =\t\"4e800420\",\n  bctrl_0 =\t\"4e800421\",\n\n  -- Primary opcode 31:\n  cmpw_3 =\t\"7c000000XRR\",\n  cmpw_2 =\t\"7c000000-RR\",\n  cmpd_3 =\t\"7c200000XRR\",\n  cmpd_2 =\t\"7c200000-RR\",\n  tw_3 =\t\"7c000008ARR\",\n  lvsl_3 =\t\"7c00000cVRR\",\n  subfc_3 =\t\"7c000010RRR.\",\n  subc_3 =\t\"7c000010RRR~.\",\n  mulhdu_3 =\t\"7c000012RRR.\",\n  addc_3 =\t\"7c000014RRR.\",\n  mulhwu_3 =\t\"7c000016RRR.\",\n  isel_4 =\t\"7c00001eRRRC\",\n  isellt_3 =\t\"7c00001eRRR\",\n  iselgt_3 =\t\"7c00005eRRR\",\n  iseleq_3 =\t\"7c00009eRRR\",\n  mfcr_1 =\t\"7c000026R\",\n  mfocrf_2 =\t\"7c100026RG\",\n  mtcrf_2 =\t\"7c000120GR\",\n  mtocrf_2 =\t\"7c100120GR\",\n  lwarx_3 =\t\"7c000028RR0R\",\n  ldx_3 =\t\"7c00002aRR0R\",\n  lwzx_3 =\t\"7c00002eRR0R\",\n  slw_3 =\t\"7c000030RR~R.\",\n  cntlzw_2 =\t\"7c000034RR~\",\n  sld_3 =\t\"7c000036RR~R.\",\n  and_3 =\t\"7c000038RR~R.\",\n  cmplw_3 =\t\"7c000040XRR\",\n  cmplw_2 =\t\"7c000040-RR\",\n  cmpld_3 =\t\"7c200040XRR\",\n  cmpld_2 =\t\"7c200040-RR\",\n  lvsr_3 =\t\"7c00004cVRR\",\n  subf_3 =\t\"7c000050RRR.\",\n  sub_3 =\t\"7c000050RRR~.\",\n  lbarx_3 =\t\"7c000068RR0R\",\n  ldux_3 =\t\"7c00006aRR0R\",\n  dcbst_2 =\t\"7c00006c-RR\",\n  lwzux_3 =\t\"7c00006eRR0R\",\n  cntlzd_2 =\t\"7c000074RR~\",\n  andc_3 =\t\"7c000078RR~R.\",\n  td_3 =\t\"7c000088ARR\",\n  lvewx_3 =\t\"7c00008eVRR\",\n  mulhd_3 =\t\"7c000092RRR.\",\n  addg6s_3 =\t\"7c000094RRR\",\n  mulhw_3 =\t\"7c000096RRR.\",\n  dlmzb_3 =\t\"7c00009cRR~R.\",\n  ldarx_3 =\t\"7c0000a8RR0R\",\n  dcbf_2 =\t\"7c0000ac-RR\",\n  lbzx_3 =\t\"7c0000aeRR0R\",\n  lvx_3 =\t\"7c0000ceVRR\",\n  neg_2 =\t\"7c0000d0RR.\",\n  lharx_3 =\t\"7c0000e8RR0R\",\n  lbzux_3 =\t\"7c0000eeRR0R\",\n  popcntb_2 =\t\"7c0000f4RR~\",\n  not_2 =\t\"7c0000f8RR~%.\",\n  nor_3 =\t\"7c0000f8RR~R.\",\n  stvebx_3 =\t\"7c00010eVRR\",\n  subfe_3 =\t\"7c000110RRR.\",\n  sube_3 =\t\"7c000110RRR~.\",\n  adde_3 =\t\"7c000114RRR.\",\n  stdx_3 =\t\"7c00012aRR0R\",\n  [\"stwcx._3\"] =\t\"7c00012dRR0R.\",\n  stwx_3 =\t\"7c00012eRR0R\",\n  prtyw_2 =\t\"7c000134RR~\",\n  stvehx_3 =\t\"7c00014eVRR\",\n  stdux_3 =\t\"7c00016aRR0R\",\n  [\"stqcx._3\"] =\t\"7c00016dR:R0R.\",\n  stwux_3 =\t\"7c00016eRR0R\",\n  prtyd_2 =\t\"7c000174RR~\",\n  stvewx_3 =\t\"7c00018eVRR\",\n  subfze_2 =\t\"7c000190RR.\",\n  addze_2 =\t\"7c000194RR.\",\n  [\"stdcx._3\"] =\t\"7c0001adRR0R.\",\n  stbx_3 =\t\"7c0001aeRR0R\",\n  stvx_3 =\t\"7c0001ceVRR\",\n  subfme_2 =\t\"7c0001d0RR.\",\n  mulld_3 =\t\"7c0001d2RRR.\",\n  addme_2 =\t\"7c0001d4RR.\",\n  mullw_3 =\t\"7c0001d6RRR.\",\n  dcbtst_2 =\t\"7c0001ec-RR\",\n  stbux_3 =\t\"7c0001eeRR0R\",\n  bpermd_3 =\t\"7c0001f8RR~R\",\n  lvepxl_3 =\t\"7c00020eVRR\",\n  add_3 =\t\"7c000214RRR.\",\n  lqarx_3 =\t\"7c000228R:R0R\",\n  dcbt_2 =\t\"7c00022c-RR\",\n  lhzx_3 =\t\"7c00022eRR0R\",\n  cdtbcd_2 =\t\"7c000234RR~\",\n  eqv_3 =\t\"7c000238RR~R.\",\n  lvepx_3 =\t\"7c00024eVRR\",\n  eciwx_3 =\t\"7c00026cRR0R\",\n  lhzux_3 =\t\"7c00026eRR0R\",\n  cbcdtd_2 =\t\"7c000274RR~\",\n  xor_3 =\t\"7c000278RR~R.\",\n  mfspefscr_1 =\t\"7c0082a6R\",\n  mfxer_1 =\t\"7c0102a6R\",\n  mflr_1 =\t\"7c0802a6R\",\n  mfctr_1 =\t\"7c0902a6R\",\n  lwax_3 =\t\"7c0002aaRR0R\",\n  lhax_3 =\t\"7c0002aeRR0R\",\n  mftb_1 =\t\"7c0c42e6R\",\n  mftbu_1 =\t\"7c0d42e6R\",\n  lvxl_3 =\t\"7c0002ceVRR\",\n  lwaux_3 =\t\"7c0002eaRR0R\",\n  lhaux_3 =\t\"7c0002eeRR0R\",\n  popcntw_2 =\t\"7c0002f4RR~\",\n  divdeu_3 =\t\"7c000312RRR.\",\n  divweu_3 =\t\"7c000316RRR.\",\n  sthx_3 =\t\"7c00032eRR0R\",\n  orc_3 =\t\"7c000338RR~R.\",\n  ecowx_3 =\t\"7c00036cRR0R\",\n  sthux_3 =\t\"7c00036eRR0R\",\n  or_3 =\t\"7c000378RR~R.\",\n  mr_2 =\t\"7c000378RR~%.\",\n  divdu_3 =\t\"7c000392RRR.\",\n  divwu_3 =\t\"7c000396RRR.\",\n  mtspefscr_1 =\t\"7c0083a6R\",\n  mtxer_1 =\t\"7c0103a6R\",\n  mtlr_1 =\t\"7c0803a6R\",\n  mtctr_1 =\t\"7c0903a6R\",\n  dcbi_2 =\t\"7c0003ac-RR\",\n  nand_3 =\t\"7c0003b8RR~R.\",\n  dsn_2 =\t\"7c0003c6-RR\",\n  stvxl_3 =\t\"7c0003ceVRR\",\n  divd_3 =\t\"7c0003d2RRR.\",\n  divw_3 =\t\"7c0003d6RRR.\",\n  popcntd_2 =\t\"7c0003f4RR~\",\n  cmpb_3 =\t\"7c0003f8RR~R.\",\n  mcrxr_1 =\t\"7c000400X\",\n  lbdx_3 =\t\"7c000406RRR\",\n  subfco_3 =\t\"7c000410RRR.\",\n  subco_3 =\t\"7c000410RRR~.\",\n  addco_3 =\t\"7c000414RRR.\",\n  ldbrx_3 =\t\"7c000428RR0R\",\n  lswx_3 =\t\"7c00042aRR0R\",\n  lwbrx_3 =\t\"7c00042cRR0R\",\n  lfsx_3 =\t\"7c00042eFR0R\",\n  srw_3 =\t\"7c000430RR~R.\",\n  srd_3 =\t\"7c000436RR~R.\",\n  lhdx_3 =\t\"7c000446RRR\",\n  subfo_3 =\t\"7c000450RRR.\",\n  subo_3 =\t\"7c000450RRR~.\",\n  lfsux_3 =\t\"7c00046eFR0R\",\n  lwdx_3 =\t\"7c000486RRR\",\n  lswi_3 =\t\"7c0004aaRR0A\",\n  sync_0 =\t\"7c0004ac\",\n  lwsync_0 =\t\"7c2004ac\",\n  ptesync_0 =\t\"7c4004ac\",\n  lfdx_3 =\t\"7c0004aeFR0R\",\n  lddx_3 =\t\"7c0004c6RRR\",\n  nego_2 =\t\"7c0004d0RR.\",\n  lfdux_3 =\t\"7c0004eeFR0R\",\n  stbdx_3 =\t\"7c000506RRR\",\n  subfeo_3 =\t\"7c000510RRR.\",\n  subeo_3 =\t\"7c000510RRR~.\",\n  addeo_3 =\t\"7c000514RRR.\",\n  stdbrx_3 =\t\"7c000528RR0R\",\n  stswx_3 =\t\"7c00052aRR0R\",\n  stwbrx_3 =\t\"7c00052cRR0R\",\n  stfsx_3 =\t\"7c00052eFR0R\",\n  sthdx_3 =\t\"7c000546RRR\",\n  [\"stbcx._3\"] =\t\"7c00056dRRR\",\n  stfsux_3 =\t\"7c00056eFR0R\",\n  stwdx_3 =\t\"7c000586RRR\",\n  subfzeo_2 =\t\"7c000590RR.\",\n  addzeo_2 =\t\"7c000594RR.\",\n  stswi_3 =\t\"7c0005aaRR0A\",\n  [\"sthcx._3\"] =\t\"7c0005adRRR\",\n  stfdx_3 =\t\"7c0005aeFR0R\",\n  stddx_3 =\t\"7c0005c6RRR\",\n  subfmeo_2 =\t\"7c0005d0RR.\",\n  mulldo_3 =\t\"7c0005d2RRR.\",\n  addmeo_2 =\t\"7c0005d4RR.\",\n  mullwo_3 =\t\"7c0005d6RRR.\",\n  dcba_2 =\t\"7c0005ec-RR\",\n  stfdux_3 =\t\"7c0005eeFR0R\",\n  stvepxl_3 =\t\"7c00060eVRR\",\n  addo_3 =\t\"7c000614RRR.\",\n  lhbrx_3 =\t\"7c00062cRR0R\",\n  lfdpx_3 =\t\"7c00062eF:RR\",\n  sraw_3 =\t\"7c000630RR~R.\",\n  srad_3 =\t\"7c000634RR~R.\",\n  lfddx_3 =\t\"7c000646FRR\",\n  stvepx_3 =\t\"7c00064eVRR\",\n  srawi_3 =\t\"7c000670RR~A.\",\n  sradi_3 =\t\"7c000674RR~H.\",\n  eieio_0 =\t\"7c0006ac\",\n  lfiwax_3 =\t\"7c0006aeFR0R\",\n  divdeuo_3 =\t\"7c000712RRR.\",\n  divweuo_3 =\t\"7c000716RRR.\",\n  sthbrx_3 =\t\"7c00072cRR0R\",\n  stfdpx_3 =\t\"7c00072eF:RR\",\n  extsh_2 =\t\"7c000734RR~.\",\n  stfddx_3 =\t\"7c000746FRR\",\n  divdeo_3 =\t\"7c000752RRR.\",\n  divweo_3 =\t\"7c000756RRR.\",\n  extsb_2 =\t\"7c000774RR~.\",\n  divduo_3 =\t\"7c000792RRR.\",\n  divwou_3 =\t\"7c000796RRR.\",\n  icbi_2 =\t\"7c0007ac-RR\",\n  stfiwx_3 =\t\"7c0007aeFR0R\",\n  extsw_2 =\t\"7c0007b4RR~.\",\n  divdo_3 =\t\"7c0007d2RRR.\",\n  divwo_3 =\t\"7c0007d6RRR.\",\n  dcbz_2 =\t\"7c0007ec-RR\",\n\n  [\"tbegin._1\"] =\t\"7c00051d1\",\n  [\"tbegin._0\"] =\t\"7c00051d\",\n  [\"tend._1\"] =\t\t\"7c00055dY\",\n  [\"tend._0\"] =\t\t\"7c00055d\",\n  [\"tendall._0\"] =\t\"7e00055d\",\n  tcheck_1 =\t\t\"7c00059cX\",\n  [\"tsr._1\"] =\t\t\"7c0005dd1\",\n  [\"tsuspend._0\"] =\t\"7c0005dd\",\n  [\"tresume._0\"] =\t\"7c2005dd\",\n  [\"tabortwc._3\"] =\t\"7c00061dARR\",\n  [\"tabortdc._3\"] =\t\"7c00065dARR\",\n  [\"tabortwci._3\"] =\t\"7c00069dARS\",\n  [\"tabortdci._3\"] =\t\"7c0006ddARS\",\n  [\"tabort._1\"] =\t\"7c00071d-R-\",\n  [\"treclaim._1\"] =\t\"7c00075d-R\",\n  [\"trechkpt._0\"] =\t\"7c0007dd\",\n\n  lxsiwzx_3 =\t\"7c000018QRR\",\n  lxsiwax_3 =\t\"7c000098QRR\",\n  mfvsrd_2 =\t\"7c000066-Rq\",\n  mfvsrwz_2 =\t\"7c0000e6-Rq\",\n  stxsiwx_3 =\t\"7c000118QRR\",\n  mtvsrd_2 =\t\"7c000166QR\",\n  mtvsrwa_2 =\t\"7c0001a6QR\",\n  lxvdsx_3 =\t\"7c000298QRR\",\n  lxsspx_3 =\t\"7c000418QRR\",\n  lxsdx_3 =\t\"7c000498QRR\",\n  stxsspx_3 =\t\"7c000518QRR\",\n  stxsdx_3 =\t\"7c000598QRR\",\n  lxvw4x_3 =\t\"7c000618QRR\",\n  lxvd2x_3 =\t\"7c000698QRR\",\n  stxvw4x_3 =\t\"7c000718QRR\",\n  stxvd2x_3 =\t\"7c000798QRR\",\n\n  -- Primary opcode 30:\n  rldicl_4 =\t\"78000000RR~HM.\",\n  rldicr_4 =\t\"78000004RR~HM.\",\n  rldic_4 =\t\"78000008RR~HM.\",\n  rldimi_4 =\t\"7800000cRR~HM.\",\n  rldcl_4 =\t\"78000010RR~RM.\",\n  rldcr_4 =\t\"78000012RR~RM.\",\n\n  rotldi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = \"0\"\n  end),\n  rotrdi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[3] = \"64-(\"..p[3]..\")\"; p[4] = \"0\"\n  end),\n  rotld_3 =\top_alias(\"rldcl_4\", function(p)\n    p[4] = \"0\"\n  end),\n  sldi_3 =\top_alias(\"rldicr_4\", function(p)\n    p[4] = \"63-(\"..p[3]..\")\"\n  end),\n  srdi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = p[3]; p[3] = \"64-(\"..p[3]..\")\"\n  end),\n  clrldi_3 =\top_alias(\"rldicl_4\", function(p)\n    p[4] = p[3]; p[3] = \"0\"\n  end),\n  clrrdi_3 =\top_alias(\"rldicr_4\", function(p)\n    p[4] = \"63-(\"..p[3]..\")\"; p[3] = \"0\"\n  end),\n\n  -- Primary opcode 56:\n  lq_2 =\t\"e0000000R:D\", -- NYI: displacement must be divisible by 8.\n\n  -- Primary opcode 57:\n  lfdp_2 =\t\"e4000000F:D\", -- NYI: displacement must be divisible by 4.\n\n  -- Primary opcode 59:\n  fdivs_3 =\t\"ec000024FFF.\",\n  fsubs_3 =\t\"ec000028FFF.\",\n  fadds_3 =\t\"ec00002aFFF.\",\n  fsqrts_2 =\t\"ec00002cF-F.\",\n  fres_2 =\t\"ec000030F-F.\",\n  fmuls_3 =\t\"ec000032FF-F.\",\n  frsqrtes_2 =\t\"ec000034F-F.\",\n  fmsubs_4 =\t\"ec000038FFFF~.\",\n  fmadds_4 =\t\"ec00003aFFFF~.\",\n  fnmsubs_4 =\t\"ec00003cFFFF~.\",\n  fnmadds_4 =\t\"ec00003eFFFF~.\",\n  fcfids_2 =\t\"ec00069cF-F.\",\n  fcfidus_2 =\t\"ec00079cF-F.\",\n\n  dadd_3 =\t\"ec000004FFF.\",\n  dqua_4 =\t\"ec000006FFFZ.\",\n  dmul_3 =\t\"ec000044FFF.\",\n  drrnd_4 =\t\"ec000046FFFZ.\",\n  dscli_3 =\t\"ec000084FF6.\",\n  dquai_4 =\t\"ec000086SF~FZ.\",\n  dscri_3 =\t\"ec0000c4FF6.\",\n  drintx_4 =\t\"ec0000c61F~FZ.\",\n  dcmpo_3 =\t\"ec000104XFF\",\n  dtstex_3 =\t\"ec000144XFF\",\n  dtstdc_3 =\t\"ec000184XF6\",\n  dtstdg_3 =\t\"ec0001c4XF6\",\n  drintn_4 =\t\"ec0001c61F~FZ.\",\n  dctdp_2 =\t\"ec000204F-F.\",\n  dctfix_2 =\t\"ec000244F-F.\",\n  ddedpd_3 =\t\"ec000284ZF~F.\",\n  dxex_2 =\t\"ec0002c4F-F.\",\n  dsub_3 =\t\"ec000404FFF.\",\n  ddiv_3 =\t\"ec000444FFF.\",\n  dcmpu_3 =\t\"ec000504XFF\",\n  dtstsf_3 =\t\"ec000544XFF\",\n  drsp_2 =\t\"ec000604F-F.\",\n  dcffix_2 =\t\"ec000644F-F.\",\n  denbcd_3 =\t\"ec000684YF~F.\",\n  diex_3 =\t\"ec0006c4FFF.\",\n\n  -- Primary opcode 60:\n  xsaddsp_3 =\t\t\"f0000000QQQ\",\n  xsmaddasp_3 =\t\t\"f0000008QQQ\",\n  xxsldwi_4 =\t\t\"f0000010QQQz\",\n  xsrsqrtesp_2 =\t\"f0000028Q-Q\",\n  xssqrtsp_2 =\t\t\"f000002cQ-Q\",\n  xxsel_4 =\t\t\"f0000030QQQQ\",\n  xssubsp_3 =\t\t\"f0000040QQQ\",\n  xsmaddmsp_3 =\t\t\"f0000048QQQ\",\n  xxpermdi_4 =\t\t\"f0000050QQQz\",\n  xsresp_2 =\t\t\"f0000068Q-Q\",\n  xsmulsp_3 =\t\t\"f0000080QQQ\",\n  xsmsubasp_3 =\t\t\"f0000088QQQ\",\n  xxmrghw_3 =\t\t\"f0000090QQQ\",\n  xsdivsp_3 =\t\t\"f00000c0QQQ\",\n  xsmsubmsp_3 =\t\t\"f00000c8QQQ\",\n  xsadddp_3 =\t\t\"f0000100QQQ\",\n  xsmaddadp_3 =\t\t\"f0000108QQQ\",\n  xscmpudp_3 =\t\t\"f0000118XQQ\",\n  xscvdpuxws_2 =\t\"f0000120Q-Q\",\n  xsrdpi_2 =\t\t\"f0000124Q-Q\",\n  xsrsqrtedp_2 =\t\"f0000128Q-Q\",\n  xssqrtdp_2 =\t\t\"f000012cQ-Q\",\n  xssubdp_3 =\t\t\"f0000140QQQ\",\n  xsmaddmdp_3 =\t\t\"f0000148QQQ\",\n  xscmpodp_3 =\t\t\"f0000158XQQ\",\n  xscvdpsxws_2 =\t\"f0000160Q-Q\",\n  xsrdpiz_2 =\t\t\"f0000164Q-Q\",\n  xsredp_2 =\t\t\"f0000168Q-Q\",\n  xsmuldp_3 =\t\t\"f0000180QQQ\",\n  xsmsubadp_3 =\t\t\"f0000188QQQ\",\n  xxmrglw_3 =\t\t\"f0000190QQQ\",\n  xsrdpip_2 =\t\t\"f00001a4Q-Q\",\n  xstsqrtdp_2 =\t\t\"f00001a8X-Q\",\n  xsrdpic_2 =\t\t\"f00001acQ-Q\",\n  xsdivdp_3 =\t\t\"f00001c0QQQ\",\n  xsmsubmdp_3 =\t\t\"f00001c8QQQ\",\n  xsrdpim_2 =\t\t\"f00001e4Q-Q\",\n  xstdivdp_3 =\t\t\"f00001e8XQQ\",\n  xvaddsp_3 =\t\t\"f0000200QQQ\",\n  xvmaddasp_3 =\t\t\"f0000208QQQ\",\n  xvcmpeqsp_3 =\t\t\"f0000218QQQ\",\n  xvcvspuxws_2 =\t\"f0000220Q-Q\",\n  xvrspi_2 =\t\t\"f0000224Q-Q\",\n  xvrsqrtesp_2 =\t\"f0000228Q-Q\",\n  xvsqrtsp_2 =\t\t\"f000022cQ-Q\",\n  xvsubsp_3 =\t\t\"f0000240QQQ\",\n  xvmaddmsp_3 =\t\t\"f0000248QQQ\",\n  xvcmpgtsp_3 =\t\t\"f0000258QQQ\",\n  xvcvspsxws_2 =\t\"f0000260Q-Q\",\n  xvrspiz_2 =\t\t\"f0000264Q-Q\",\n  xvresp_2 =\t\t\"f0000268Q-Q\",\n  xvmulsp_3 =\t\t\"f0000280QQQ\",\n  xvmsubasp_3 =\t\t\"f0000288QQQ\",\n  xxspltw_3 =\t\t\"f0000290QQg~\",\n  xvcmpgesp_3 =\t\t\"f0000298QQQ\",\n  xvcvuxwsp_2 =\t\t\"f00002a0Q-Q\",\n  xvrspip_2 =\t\t\"f00002a4Q-Q\",\n  xvtsqrtsp_2 =\t\t\"f00002a8X-Q\",\n  xvrspic_2 =\t\t\"f00002acQ-Q\",\n  xvdivsp_3 =\t\t\"f00002c0QQQ\",\n  xvmsubmsp_3 =\t\t\"f00002c8QQQ\",\n  xvcvsxwsp_2 =\t\t\"f00002e0Q-Q\",\n  xvrspim_2 =\t\t\"f00002e4Q-Q\",\n  xvtdivsp_3 =\t\t\"f00002e8XQQ\",\n  xvadddp_3 =\t\t\"f0000300QQQ\",\n  xvmaddadp_3 =\t\t\"f0000308QQQ\",\n  xvcmpeqdp_3 =\t\t\"f0000318QQQ\",\n  xvcvdpuxws_2 =\t\"f0000320Q-Q\",\n  xvrdpi_2 =\t\t\"f0000324Q-Q\",\n  xvrsqrtedp_2 =\t\"f0000328Q-Q\",\n  xvsqrtdp_2 =\t\t\"f000032cQ-Q\",\n  xvsubdp_3 =\t\t\"f0000340QQQ\",\n  xvmaddmdp_3 =\t\t\"f0000348QQQ\",\n  xvcmpgtdp_3 =\t\t\"f0000358QQQ\",\n  xvcvdpsxws_2 =\t\"f0000360Q-Q\",\n  xvrdpiz_2 =\t\t\"f0000364Q-Q\",\n  xvredp_2 =\t\t\"f0000368Q-Q\",\n  xvmuldp_3 =\t\t\"f0000380QQQ\",\n  xvmsubadp_3 =\t\t\"f0000388QQQ\",\n  xvcmpgedp_3 =\t\t\"f0000398QQQ\",\n  xvcvuxwdp_2 =\t\t\"f00003a0Q-Q\",\n  xvrdpip_2 =\t\t\"f00003a4Q-Q\",\n  xvtsqrtdp_2 =\t\t\"f00003a8X-Q\",\n  xvrdpic_2 =\t\t\"f00003acQ-Q\",\n  xvdivdp_3 =\t\t\"f00003c0QQQ\",\n  xvmsubmdp_3 =\t\t\"f00003c8QQQ\",\n  xvcvsxwdp_2 =\t\t\"f00003e0Q-Q\",\n  xvrdpim_2 =\t\t\"f00003e4Q-Q\",\n  xvtdivdp_3 =\t\t\"f00003e8XQQ\",\n  xsnmaddasp_3 =\t\"f0000408QQQ\",\n  xxland_3 =\t\t\"f0000410QQQ\",\n  xscvdpsp_2 =\t\t\"f0000424Q-Q\",\n  xscvdpspn_2 =\t\t\"f000042cQ-Q\",\n  xsnmaddmsp_3 =\t\"f0000448QQQ\",\n  xxlandc_3 =\t\t\"f0000450QQQ\",\n  xsrsp_2 =\t\t\"f0000464Q-Q\",\n  xsnmsubasp_3 =\t\"f0000488QQQ\",\n  xxlor_3 =\t\t\"f0000490QQQ\",\n  xscvuxdsp_2 =\t\t\"f00004a0Q-Q\",\n  xsnmsubmsp_3 =\t\"f00004c8QQQ\",\n  xxlxor_3 =\t\t\"f00004d0QQQ\",\n  xscvsxdsp_2 =\t\t\"f00004e0Q-Q\",\n  xsmaxdp_3 =\t\t\"f0000500QQQ\",\n  xsnmaddadp_3 =\t\"f0000508QQQ\",\n  xxlnor_3 =\t\t\"f0000510QQQ\",\n  xscvdpuxds_2 =\t\"f0000520Q-Q\",\n  xscvspdp_2 =\t\t\"f0000524Q-Q\",\n  xscvspdpn_2 =\t\t\"f000052cQ-Q\",\n  xsmindp_3 =\t\t\"f0000540QQQ\",\n  xsnmaddmdp_3 =\t\"f0000548QQQ\",\n  xxlorc_3 =\t\t\"f0000550QQQ\",\n  xscvdpsxds_2 =\t\"f0000560Q-Q\",\n  xsabsdp_2 =\t\t\"f0000564Q-Q\",\n  xscpsgndp_3 =\t\t\"f0000580QQQ\",\n  xsnmsubadp_3 =\t\"f0000588QQQ\",\n  xxlnand_3 =\t\t\"f0000590QQQ\",\n  xscvuxddp_2 =\t\t\"f00005a0Q-Q\",\n  xsnabsdp_2 =\t\t\"f00005a4Q-Q\",\n  xsnmsubmdp_3 =\t\"f00005c8QQQ\",\n  xxleqv_3 =\t\t\"f00005d0QQQ\",\n  xscvsxddp_2 =\t\t\"f00005e0Q-Q\",\n  xsnegdp_2 =\t\t\"f00005e4Q-Q\",\n  xvmaxsp_3 =\t\t\"f0000600QQQ\",\n  xvnmaddasp_3 =\t\"f0000608QQQ\",\n  [\"xvcmpeqsp._3\"] =\t\"f0000618QQQ\",\n  xvcvspuxds_2 =\t\"f0000620Q-Q\",\n  xvcvdpsp_2 =\t\t\"f0000624Q-Q\",\n  xvminsp_3 =\t\t\"f0000640QQQ\",\n  xvnmaddmsp_3 =\t\"f0000648QQQ\",\n  [\"xvcmpgtsp._3\"] =\t\"f0000658QQQ\",\n  xvcvspsxds_2 =\t\"f0000660Q-Q\",\n  xvabssp_2 =\t\t\"f0000664Q-Q\",\n  xvcpsgnsp_3 =\t\t\"f0000680QQQ\",\n  xvnmsubasp_3 =\t\"f0000688QQQ\",\n  [\"xvcmpgesp._3\"] =\t\"f0000698QQQ\",\n  xvcvuxdsp_2 =\t\t\"f00006a0Q-Q\",\n  xvnabssp_2 =\t\t\"f00006a4Q-Q\",\n  xvnmsubmsp_3 =\t\"f00006c8QQQ\",\n  xvcvsxdsp_2 =\t\t\"f00006e0Q-Q\",\n  xvnegsp_2 =\t\t\"f00006e4Q-Q\",\n  xvmaxdp_3 =\t\t\"f0000700QQQ\",\n  xvnmaddadp_3 =\t\"f0000708QQQ\",\n  [\"xvcmpeqdp._3\"] =\t\"f0000718QQQ\",\n  xvcvdpuxds_2 =\t\"f0000720Q-Q\",\n  xvcvspdp_2 =\t\t\"f0000724Q-Q\",\n  xvmindp_3 =\t\t\"f0000740QQQ\",\n  xvnmaddmdp_3 =\t\"f0000748QQQ\",\n  [\"xvcmpgtdp._3\"] =\t\"f0000758QQQ\",\n  xvcvdpsxds_2 =\t\"f0000760Q-Q\",\n  xvabsdp_2 =\t\t\"f0000764Q-Q\",\n  xvcpsgndp_3 =\t\t\"f0000780QQQ\",\n  xvnmsubadp_3 =\t\"f0000788QQQ\",\n  [\"xvcmpgedp._3\"] =\t\"f0000798QQQ\",\n  xvcvuxddp_2 =\t\t\"f00007a0Q-Q\",\n  xvnabsdp_2 =\t\t\"f00007a4Q-Q\",\n  xvnmsubmdp_3 =\t\"f00007c8QQQ\",\n  xvcvsxddp_2 =\t\t\"f00007e0Q-Q\",\n  xvnegdp_2 =\t\t\"f00007e4Q-Q\",\n\n  -- Primary opcode 61:\n  stfdp_2 =\t\"f4000000F:D\", -- NYI: displacement must be divisible by 4.\n\n  -- Primary opcode 62:\n  stq_2 =\t\"f8000002R:D\", -- NYI: displacement must be divisible by 8.\n\n  -- Primary opcode 63:\n  fdiv_3 =\t\"fc000024FFF.\",\n  fsub_3 =\t\"fc000028FFF.\",\n  fadd_3 =\t\"fc00002aFFF.\",\n  fsqrt_2 =\t\"fc00002cF-F.\",\n  fsel_4 =\t\"fc00002eFFFF~.\",\n  fre_2 =\t\"fc000030F-F.\",\n  fmul_3 =\t\"fc000032FF-F.\",\n  frsqrte_2 =\t\"fc000034F-F.\",\n  fmsub_4 =\t\"fc000038FFFF~.\",\n  fmadd_4 =\t\"fc00003aFFFF~.\",\n  fnmsub_4 =\t\"fc00003cFFFF~.\",\n  fnmadd_4 =\t\"fc00003eFFFF~.\",\n  fcmpu_3 =\t\"fc000000XFF\",\n  fcpsgn_3 =\t\"fc000010FFF.\",\n  fcmpo_3 =\t\"fc000040XFF\",\n  mtfsb1_1 =\t\"fc00004cA\",\n  fneg_2 =\t\"fc000050F-F.\",\n  mcrfs_2 =\t\"fc000080XX\",\n  mtfsb0_1 =\t\"fc00008cA\",\n  fmr_2 =\t\"fc000090F-F.\",\n  frsp_2 =\t\"fc000018F-F.\",\n  fctiw_2 =\t\"fc00001cF-F.\",\n  fctiwz_2 =\t\"fc00001eF-F.\",\n  ftdiv_2 =\t\"fc000100X-F.\",\n  fctiwu_2 =\t\"fc00011cF-F.\",\n  fctiwuz_2 =\t\"fc00011eF-F.\",\n  mtfsfi_2 =\t\"fc00010cAA\", -- NYI: upshift.\n  fnabs_2 =\t\"fc000110F-F.\",\n  ftsqrt_2 =\t\"fc000140X-F.\",\n  fabs_2 =\t\"fc000210F-F.\",\n  frin_2 =\t\"fc000310F-F.\",\n  friz_2 =\t\"fc000350F-F.\",\n  frip_2 =\t\"fc000390F-F.\",\n  frim_2 =\t\"fc0003d0F-F.\",\n  mffs_1 =\t\"fc00048eF.\",\n  -- NYI: mtfsf, mtfsb0, mtfsb1.\n  fctid_2 =\t\"fc00065cF-F.\",\n  fctidz_2 =\t\"fc00065eF-F.\",\n  fmrgow_3 =\t\"fc00068cFFF\",\n  fcfid_2 =\t\"fc00069cF-F.\",\n  fctidu_2 =\t\"fc00075cF-F.\",\n  fctiduz_2 =\t\"fc00075eF-F.\",\n  fmrgew_3 =\t\"fc00078cFFF\",\n  fcfidu_2 =\t\"fc00079cF-F.\",\n\n  daddq_3 =\t\"fc000004F:F:F:.\",\n  dquaq_4 =\t\"fc000006F:F:F:Z.\",\n  dmulq_3 =\t\"fc000044F:F:F:.\",\n  drrndq_4 =\t\"fc000046F:F:F:Z.\",\n  dscliq_3 =\t\"fc000084F:F:6.\",\n  dquaiq_4 =\t\"fc000086SF:~F:Z.\",\n  dscriq_3 =\t\"fc0000c4F:F:6.\",\n  drintxq_4 =\t\"fc0000c61F:~F:Z.\",\n  dcmpoq_3 =\t\"fc000104XF:F:\",\n  dtstexq_3 =\t\"fc000144XF:F:\",\n  dtstdcq_3 =\t\"fc000184XF:6\",\n  dtstdgq_3 =\t\"fc0001c4XF:6\",\n  drintnq_4 =\t\"fc0001c61F:~F:Z.\",\n  dctqpq_2 =\t\"fc000204F:-F:.\",\n  dctfixq_2 =\t\"fc000244F:-F:.\",\n  ddedpdq_3 =\t\"fc000284ZF:~F:.\",\n  dxexq_2 =\t\"fc0002c4F:-F:.\",\n  dsubq_3 =\t\"fc000404F:F:F:.\",\n  ddivq_3 =\t\"fc000444F:F:F:.\",\n  dcmpuq_3 =\t\"fc000504XF:F:\",\n  dtstsfq_3 =\t\"fc000544XF:F:\",\n  drdpq_2 =\t\"fc000604F:-F:.\",\n  dcffixq_2 =\t\"fc000644F:-F:.\",\n  denbcdq_3 =\t\"fc000684YF:~F:.\",\n  diexq_3 =\t\"fc0006c4F:FF:.\",\n\n  -- Primary opcode 4, SPE APU extension:\n  evaddw_3 =\t\t\"10000200RRR\",\n  evaddiw_3 =\t\t\"10000202RAR~\",\n  evsubw_3 =\t\t\"10000204RRR~\",\n  evsubiw_3 =\t\t\"10000206RAR~\",\n  evabs_2 =\t\t\"10000208RR\",\n  evneg_2 =\t\t\"10000209RR\",\n  evextsb_2 =\t\t\"1000020aRR\",\n  evextsh_2 =\t\t\"1000020bRR\",\n  evrndw_2 =\t\t\"1000020cRR\",\n  evcntlzw_2 =\t\t\"1000020dRR\",\n  evcntlsw_2 =\t\t\"1000020eRR\",\n  brinc_3 =\t\t\"1000020fRRR\",\n  evand_3 =\t\t\"10000211RRR\",\n  evandc_3 =\t\t\"10000212RRR\",\n  evxor_3 =\t\t\"10000216RRR\",\n  evor_3 =\t\t\"10000217RRR\",\n  evmr_2 =\t\t\"10000217RR=\",\n  evnor_3 =\t\t\"10000218RRR\",\n  evnot_2 =\t\t\"10000218RR=\",\n  eveqv_3 =\t\t\"10000219RRR\",\n  evorc_3 =\t\t\"1000021bRRR\",\n  evnand_3 =\t\t\"1000021eRRR\",\n  evsrwu_3 =\t\t\"10000220RRR\",\n  evsrws_3 =\t\t\"10000221RRR\",\n  evsrwiu_3 =\t\t\"10000222RRA\",\n  evsrwis_3 =\t\t\"10000223RRA\",\n  evslw_3 =\t\t\"10000224RRR\",\n  evslwi_3 =\t\t\"10000226RRA\",\n  evrlw_3 =\t\t\"10000228RRR\",\n  evsplati_2 =\t\t\"10000229RS\",\n  evrlwi_3 =\t\t\"1000022aRRA\",\n  evsplatfi_2 =\t\t\"1000022bRS\",\n  evmergehi_3 =\t\t\"1000022cRRR\",\n  evmergelo_3 =\t\t\"1000022dRRR\",\n  evcmpgtu_3 =\t\t\"10000230XRR\",\n  evcmpgtu_2 =\t\t\"10000230-RR\",\n  evcmpgts_3 =\t\t\"10000231XRR\",\n  evcmpgts_2 =\t\t\"10000231-RR\",\n  evcmpltu_3 =\t\t\"10000232XRR\",\n  evcmpltu_2 =\t\t\"10000232-RR\",\n  evcmplts_3 =\t\t\"10000233XRR\",\n  evcmplts_2 =\t\t\"10000233-RR\",\n  evcmpeq_3 =\t\t\"10000234XRR\",\n  evcmpeq_2 =\t\t\"10000234-RR\",\n  evsel_4 =\t\t\"10000278RRRW\",\n  evsel_3 =\t\t\"10000278RRR\",\n  evfsadd_3 =\t\t\"10000280RRR\",\n  evfssub_3 =\t\t\"10000281RRR\",\n  evfsabs_2 =\t\t\"10000284RR\",\n  evfsnabs_2 =\t\t\"10000285RR\",\n  evfsneg_2 =\t\t\"10000286RR\",\n  evfsmul_3 =\t\t\"10000288RRR\",\n  evfsdiv_3 =\t\t\"10000289RRR\",\n  evfscmpgt_3 =\t\t\"1000028cXRR\",\n  evfscmpgt_2 =\t\t\"1000028c-RR\",\n  evfscmplt_3 =\t\t\"1000028dXRR\",\n  evfscmplt_2 =\t\t\"1000028d-RR\",\n  evfscmpeq_3 =\t\t\"1000028eXRR\",\n  evfscmpeq_2 =\t\t\"1000028e-RR\",\n  evfscfui_2 =\t\t\"10000290R-R\",\n  evfscfsi_2 =\t\t\"10000291R-R\",\n  evfscfuf_2 =\t\t\"10000292R-R\",\n  evfscfsf_2 =\t\t\"10000293R-R\",\n  evfsctui_2 =\t\t\"10000294R-R\",\n  evfsctsi_2 =\t\t\"10000295R-R\",\n  evfsctuf_2 =\t\t\"10000296R-R\",\n  evfsctsf_2 =\t\t\"10000297R-R\",\n  evfsctuiz_2 =\t\t\"10000298R-R\",\n  evfsctsiz_2 =\t\t\"1000029aR-R\",\n  evfststgt_3 =\t\t\"1000029cXRR\",\n  evfststgt_2 =\t\t\"1000029c-RR\",\n  evfststlt_3 =\t\t\"1000029dXRR\",\n  evfststlt_2 =\t\t\"1000029d-RR\",\n  evfststeq_3 =\t\t\"1000029eXRR\",\n  evfststeq_2 =\t\t\"1000029e-RR\",\n  efsadd_3 =\t\t\"100002c0RRR\",\n  efssub_3 =\t\t\"100002c1RRR\",\n  efsabs_2 =\t\t\"100002c4RR\",\n  efsnabs_2 =\t\t\"100002c5RR\",\n  efsneg_2 =\t\t\"100002c6RR\",\n  efsmul_3 =\t\t\"100002c8RRR\",\n  efsdiv_3 =\t\t\"100002c9RRR\",\n  efscmpgt_3 =\t\t\"100002ccXRR\",\n  efscmpgt_2 =\t\t\"100002cc-RR\",\n  efscmplt_3 =\t\t\"100002cdXRR\",\n  efscmplt_2 =\t\t\"100002cd-RR\",\n  efscmpeq_3 =\t\t\"100002ceXRR\",\n  efscmpeq_2 =\t\t\"100002ce-RR\",\n  efscfd_2 =\t\t\"100002cfR-R\",\n  efscfui_2 =\t\t\"100002d0R-R\",\n  efscfsi_2 =\t\t\"100002d1R-R\",\n  efscfuf_2 =\t\t\"100002d2R-R\",\n  efscfsf_2 =\t\t\"100002d3R-R\",\n  efsctui_2 =\t\t\"100002d4R-R\",\n  efsctsi_2 =\t\t\"100002d5R-R\",\n  efsctuf_2 =\t\t\"100002d6R-R\",\n  efsctsf_2 =\t\t\"100002d7R-R\",\n  efsctuiz_2 =\t\t\"100002d8R-R\",\n  efsctsiz_2 =\t\t\"100002daR-R\",\n  efststgt_3 =\t\t\"100002dcXRR\",\n  efststgt_2 =\t\t\"100002dc-RR\",\n  efststlt_3 =\t\t\"100002ddXRR\",\n  efststlt_2 =\t\t\"100002dd-RR\",\n  efststeq_3 =\t\t\"100002deXRR\",\n  efststeq_2 =\t\t\"100002de-RR\",\n  efdadd_3 =\t\t\"100002e0RRR\",\n  efdsub_3 =\t\t\"100002e1RRR\",\n  efdcfuid_2 =\t\t\"100002e2R-R\",\n  efdcfsid_2 =\t\t\"100002e3R-R\",\n  efdabs_2 =\t\t\"100002e4RR\",\n  efdnabs_2 =\t\t\"100002e5RR\",\n  efdneg_2 =\t\t\"100002e6RR\",\n  efdmul_3 =\t\t\"100002e8RRR\",\n  efddiv_3 =\t\t\"100002e9RRR\",\n  efdctuidz_2 =\t\t\"100002eaR-R\",\n  efdctsidz_2 =\t\t\"100002ebR-R\",\n  efdcmpgt_3 =\t\t\"100002ecXRR\",\n  efdcmpgt_2 =\t\t\"100002ec-RR\",\n  efdcmplt_3 =\t\t\"100002edXRR\",\n  efdcmplt_2 =\t\t\"100002ed-RR\",\n  efdcmpeq_3 =\t\t\"100002eeXRR\",\n  efdcmpeq_2 =\t\t\"100002ee-RR\",\n  efdcfs_2 =\t\t\"100002efR-R\",\n  efdcfui_2 =\t\t\"100002f0R-R\",\n  efdcfsi_2 =\t\t\"100002f1R-R\",\n  efdcfuf_2 =\t\t\"100002f2R-R\",\n  efdcfsf_2 =\t\t\"100002f3R-R\",\n  efdctui_2 =\t\t\"100002f4R-R\",\n  efdctsi_2 =\t\t\"100002f5R-R\",\n  efdctuf_2 =\t\t\"100002f6R-R\",\n  efdctsf_2 =\t\t\"100002f7R-R\",\n  efdctuiz_2 =\t\t\"100002f8R-R\",\n  efdctsiz_2 =\t\t\"100002faR-R\",\n  efdtstgt_3 =\t\t\"100002fcXRR\",\n  efdtstgt_2 =\t\t\"100002fc-RR\",\n  efdtstlt_3 =\t\t\"100002fdXRR\",\n  efdtstlt_2 =\t\t\"100002fd-RR\",\n  efdtsteq_3 =\t\t\"100002feXRR\",\n  efdtsteq_2 =\t\t\"100002fe-RR\",\n  evlddx_3 =\t\t\"10000300RR0R\",\n  evldd_2 =\t\t\"10000301R8\",\n  evldwx_3 =\t\t\"10000302RR0R\",\n  evldw_2 =\t\t\"10000303R8\",\n  evldhx_3 =\t\t\"10000304RR0R\",\n  evldh_2 =\t\t\"10000305R8\",\n  evlwhex_3 =\t\t\"10000310RR0R\",\n  evlwhe_2 =\t\t\"10000311R4\",\n  evlwhoux_3 =\t\t\"10000314RR0R\",\n  evlwhou_2 =\t\t\"10000315R4\",\n  evlwhosx_3 =\t\t\"10000316RR0R\",\n  evlwhos_2 =\t\t\"10000317R4\",\n  evstddx_3 =\t\t\"10000320RR0R\",\n  evstdd_2 =\t\t\"10000321R8\",\n  evstdwx_3 =\t\t\"10000322RR0R\",\n  evstdw_2 =\t\t\"10000323R8\",\n  evstdhx_3 =\t\t\"10000324RR0R\",\n  evstdh_2 =\t\t\"10000325R8\",\n  evstwhex_3 =\t\t\"10000330RR0R\",\n  evstwhe_2 =\t\t\"10000331R4\",\n  evstwhox_3 =\t\t\"10000334RR0R\",\n  evstwho_2 =\t\t\"10000335R4\",\n  evstwwex_3 =\t\t\"10000338RR0R\",\n  evstwwe_2 =\t\t\"10000339R4\",\n  evstwwox_3 =\t\t\"1000033cRR0R\",\n  evstwwo_2 =\t\t\"1000033dR4\",\n  evmhessf_3 =\t\t\"10000403RRR\",\n  evmhossf_3 =\t\t\"10000407RRR\",\n  evmheumi_3 =\t\t\"10000408RRR\",\n  evmhesmi_3 =\t\t\"10000409RRR\",\n  evmhesmf_3 =\t\t\"1000040bRRR\",\n  evmhoumi_3 =\t\t\"1000040cRRR\",\n  evmhosmi_3 =\t\t\"1000040dRRR\",\n  evmhosmf_3 =\t\t\"1000040fRRR\",\n  evmhessfa_3 =\t\t\"10000423RRR\",\n  evmhossfa_3 =\t\t\"10000427RRR\",\n  evmheumia_3 =\t\t\"10000428RRR\",\n  evmhesmia_3 =\t\t\"10000429RRR\",\n  evmhesmfa_3 =\t\t\"1000042bRRR\",\n  evmhoumia_3 =\t\t\"1000042cRRR\",\n  evmhosmia_3 =\t\t\"1000042dRRR\",\n  evmhosmfa_3 =\t\t\"1000042fRRR\",\n  evmwhssf_3 =\t\t\"10000447RRR\",\n  evmwlumi_3 =\t\t\"10000448RRR\",\n  evmwhumi_3 =\t\t\"1000044cRRR\",\n  evmwhsmi_3 =\t\t\"1000044dRRR\",\n  evmwhsmf_3 =\t\t\"1000044fRRR\",\n  evmwssf_3 =\t\t\"10000453RRR\",\n  evmwumi_3 =\t\t\"10000458RRR\",\n  evmwsmi_3 =\t\t\"10000459RRR\",\n  evmwsmf_3 =\t\t\"1000045bRRR\",\n  evmwhssfa_3 =\t\t\"10000467RRR\",\n  evmwlumia_3 =\t\t\"10000468RRR\",\n  evmwhumia_3 =\t\t\"1000046cRRR\",\n  evmwhsmia_3 =\t\t\"1000046dRRR\",\n  evmwhsmfa_3 =\t\t\"1000046fRRR\",\n  evmwssfa_3 =\t\t\"10000473RRR\",\n  evmwumia_3 =\t\t\"10000478RRR\",\n  evmwsmia_3 =\t\t\"10000479RRR\",\n  evmwsmfa_3 =\t\t\"1000047bRRR\",\n  evmra_2 =\t\t\"100004c4RR\",\n  evdivws_3 =\t\t\"100004c6RRR\",\n  evdivwu_3 =\t\t\"100004c7RRR\",\n  evmwssfaa_3 =\t\t\"10000553RRR\",\n  evmwumiaa_3 =\t\t\"10000558RRR\",\n  evmwsmiaa_3 =\t\t\"10000559RRR\",\n  evmwsmfaa_3 =\t\t\"1000055bRRR\",\n  evmwssfan_3 =\t\t\"100005d3RRR\",\n  evmwumian_3 =\t\t\"100005d8RRR\",\n  evmwsmian_3 =\t\t\"100005d9RRR\",\n  evmwsmfan_3 =\t\t\"100005dbRRR\",\n  evmergehilo_3 =\t\"1000022eRRR\",\n  evmergelohi_3 =\t\"1000022fRRR\",\n  evlhhesplatx_3 =\t\"10000308RR0R\",\n  evlhhesplat_2 =\t\"10000309R2\",\n  evlhhousplatx_3 =\t\"1000030cRR0R\",\n  evlhhousplat_2 =\t\"1000030dR2\",\n  evlhhossplatx_3 =\t\"1000030eRR0R\",\n  evlhhossplat_2 =\t\"1000030fR2\",\n  evlwwsplatx_3 =\t\"10000318RR0R\",\n  evlwwsplat_2 =\t\"10000319R4\",\n  evlwhsplatx_3 =\t\"1000031cRR0R\",\n  evlwhsplat_2 =\t\"1000031dR4\",\n  evaddusiaaw_2 =\t\"100004c0RR\",\n  evaddssiaaw_2 =\t\"100004c1RR\",\n  evsubfusiaaw_2 =\t\"100004c2RR\",\n  evsubfssiaaw_2 =\t\"100004c3RR\",\n  evaddumiaaw_2 =\t\"100004c8RR\",\n  evaddsmiaaw_2 =\t\"100004c9RR\",\n  evsubfumiaaw_2 =\t\"100004caRR\",\n  evsubfsmiaaw_2 =\t\"100004cbRR\",\n  evmheusiaaw_3 =\t\"10000500RRR\",\n  evmhessiaaw_3 =\t\"10000501RRR\",\n  evmhessfaaw_3 =\t\"10000503RRR\",\n  evmhousiaaw_3 =\t\"10000504RRR\",\n  evmhossiaaw_3 =\t\"10000505RRR\",\n  evmhossfaaw_3 =\t\"10000507RRR\",\n  evmheumiaaw_3 =\t\"10000508RRR\",\n  evmhesmiaaw_3 =\t\"10000509RRR\",\n  evmhesmfaaw_3 =\t\"1000050bRRR\",\n  evmhoumiaaw_3 =\t\"1000050cRRR\",\n  evmhosmiaaw_3 =\t\"1000050dRRR\",\n  evmhosmfaaw_3 =\t\"1000050fRRR\",\n  evmhegumiaa_3 =\t\"10000528RRR\",\n  evmhegsmiaa_3 =\t\"10000529RRR\",\n  evmhegsmfaa_3 =\t\"1000052bRRR\",\n  evmhogumiaa_3 =\t\"1000052cRRR\",\n  evmhogsmiaa_3 =\t\"1000052dRRR\",\n  evmhogsmfaa_3 =\t\"1000052fRRR\",\n  evmwlusiaaw_3 =\t\"10000540RRR\",\n  evmwlssiaaw_3 =\t\"10000541RRR\",\n  evmwlumiaaw_3 =\t\"10000548RRR\",\n  evmwlsmiaaw_3 =\t\"10000549RRR\",\n  evmheusianw_3 =\t\"10000580RRR\",\n  evmhessianw_3 =\t\"10000581RRR\",\n  evmhessfanw_3 =\t\"10000583RRR\",\n  evmhousianw_3 =\t\"10000584RRR\",\n  evmhossianw_3 =\t\"10000585RRR\",\n  evmhossfanw_3 =\t\"10000587RRR\",\n  evmheumianw_3 =\t\"10000588RRR\",\n  evmhesmianw_3 =\t\"10000589RRR\",\n  evmhesmfanw_3 =\t\"1000058bRRR\",\n  evmhoumianw_3 =\t\"1000058cRRR\",\n  evmhosmianw_3 =\t\"1000058dRRR\",\n  evmhosmfanw_3 =\t\"1000058fRRR\",\n  evmhegumian_3 =\t\"100005a8RRR\",\n  evmhegsmian_3 =\t\"100005a9RRR\",\n  evmhegsmfan_3 =\t\"100005abRRR\",\n  evmhogumian_3 =\t\"100005acRRR\",\n  evmhogsmian_3 =\t\"100005adRRR\",\n  evmhogsmfan_3 =\t\"100005afRRR\",\n  evmwlusianw_3 =\t\"100005c0RRR\",\n  evmwlssianw_3 =\t\"100005c1RRR\",\n  evmwlumianw_3 =\t\"100005c8RRR\",\n  evmwlsmianw_3 =\t\"100005c9RRR\",\n\n  -- NYI: Book E instructions.\n}\n\n-- Add mnemonics for \".\" variants.\ndo\n  local t = {}\n  for k,v in pairs(map_op) do\n    if type(v) == \"string\" and sub(v, -1) == \".\" then\n      local v2 = sub(v, 1, 7)..char(byte(v, 8)+1)..sub(v, 9, -2)\n      t[sub(k, 1, -3)..\".\"..sub(k, -2)] = v2\n    end\n  end\n  for k,v in pairs(t) do\n    map_op[k] = v\n  end\nend\n\n-- Add more branch mnemonics.\nfor cond,c in pairs(map_cond) do\n  local b1 = \"b\"..cond\n  local c1 = shl(band(c, 3), 16) + (c < 4 and 0x01000000 or 0)\n  -- bX[l]\n  map_op[b1..\"_1\"] = tohex(0x40800000 + c1)..\"K\"\n  map_op[b1..\"y_1\"] = tohex(0x40a00000 + c1)..\"K\"\n  map_op[b1..\"l_1\"] = tohex(0x40800001 + c1)..\"K\"\n  map_op[b1..\"_2\"] = tohex(0x40800000 + c1)..\"-XK\"\n  map_op[b1..\"y_2\"] = tohex(0x40a00000 + c1)..\"-XK\"\n  map_op[b1..\"l_2\"] = tohex(0x40800001 + c1)..\"-XK\"\n  -- bXlr[l]\n  map_op[b1..\"lr_0\"] = tohex(0x4c800020 + c1)\n  map_op[b1..\"lrl_0\"] = tohex(0x4c800021 + c1)\n  map_op[b1..\"ctr_0\"] = tohex(0x4c800420 + c1)\n  map_op[b1..\"ctrl_0\"] = tohex(0x4c800421 + c1)\n  -- bXctr[l]\n  map_op[b1..\"lr_1\"] = tohex(0x4c800020 + c1)..\"-X\"\n  map_op[b1..\"lrl_1\"] = tohex(0x4c800021 + c1)..\"-X\"\n  map_op[b1..\"ctr_1\"] = tohex(0x4c800420 + c1)..\"-X\"\n  map_op[b1..\"ctrl_1\"] = tohex(0x4c800421 + c1)..\"-X\"\nend\n\n------------------------------------------------------------------------------\n\nlocal function parse_gpr(expr)\n  local tname, ovreg = match(expr, \"^([%w_]+):(r[1-3]?[0-9])$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^r([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_fpr(expr)\n  local r = match(expr, \"^f([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_vr(expr)\n  local r = match(expr, \"^v([1-3]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 31 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_vs(expr)\n  local r = match(expr, \"^vs([1-6]?[0-9])$\")\n  if r then\n    r = tonumber(r)\n    if r <= 63 then return r end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal function parse_cr(expr)\n  local r = match(expr, \"^cr([0-7])$\")\n  if r then return tonumber(r) end\n  werror(\"bad condition register name `\"..expr..\"'\")\nend\n\nlocal function parse_cond(expr)\n  local r, cond = match(expr, \"^4%*cr([0-7])%+(%w%w)$\")\n  if r then\n    r = tonumber(r)\n    local c = map_cond[cond]\n    if c and c < 4 then return r*4+c end\n  end\n  werror(\"bad condition bit name `\"..expr..\"'\")\nend\n\nlocal parse_ctx = {}\n\nlocal loadenv = setfenv and function(s)\n  local code = loadstring(s, \"\")\n  if code then setfenv(code, parse_ctx) end\n  return code\nend or function(s)\n  return load(s, \"\", nil, parse_ctx)\nend\n\n-- Try to parse simple arithmetic, too, since some basic ops are aliases.\nlocal function parse_number(n)\n  local x = tonumber(n)\n  if x then return x end\n  local code = loadenv(\"return \"..n)\n  if code then\n    local ok, y = pcall(code)\n    if ok then return y end\n  end\n  return nil\nend\n\nlocal function parse_imm(imm, bits, shift, scale, signed)\n  local n = parse_number(imm)\n  if n then\n    local m = sar(n, scale)\n    if shl(m, scale) == n then\n      if signed then\n\tlocal s = sar(m, bits-1)\n\tif s == 0 then return shl(m, shift)\n\telseif s == -1 then return shl(m + shl(1, bits), shift) end\n      else\n\tif sar(m, bits) == 0 then return shl(m, shift) end\n      end\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^[rfv]([1-3]?[0-9])$\") or\n\t match(imm, \"^vs([1-6]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r[1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMM\", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)\n    return 0\n  end\nend\n\nlocal function parse_shiftmask(imm, isshift)\n  local n = parse_number(imm)\n  if n then\n    if shr(n, 6) == 0 then\n      local lsb = band(n, 31)\n      local msb = n - lsb\n      return isshift and (shl(lsb, 11)+shr(msb, 4)) or (shl(lsb, 6)+msb)\n    end\n    werror(\"out of range immediate `\"..imm..\"'\")\n  elseif match(imm, \"^r([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r[1-3]?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMMSH\", isshift and 1 or 0, imm)\n    return 0;\n  end\nend\n\nlocal function parse_disp(disp)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    return shl(r, 16) + parse_imm(imm, 16, 0, 0, true)\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    if tp then\n      waction(\"IMM\", 32768+16*32, format(tp.ctypefmt, tailr))\n      return shl(r, 16)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_u5disp(disp, scale)\n  local imm, reg = match(disp, \"^(.*)%(([%w_:]+)%)$\")\n  if imm then\n    local r = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    return shl(r, 16) + parse_imm(imm, 5, 11, scale, false)\n  end\n  local reg, tailr = match(disp, \"^([%w_:]+)%s*(.*)$\")\n  if reg and tailr ~= \"\" then\n    local r, tp = parse_gpr(reg)\n    if r == 0 then werror(\"cannot use r0 in displacement\") end\n    if tp then\n      waction(\"IMM\", scale*1024+5*32+11, format(tp.ctypefmt, tailr))\n      return shl(r, 16)\n    end\n  end\n  werror(\"bad displacement `\"..disp..\"'\")\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- Handle opcodes defined with template strings.\nop_template = function(params, template, nparams)\n  if not params then return sub(template, 9) end\n  local op = tonumber(sub(template, 1, 8), 16)\n  local n, rs = 1, 26\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 3 positions (rlwinm).\n  if secpos+3 > maxsecpos then wflush() end\n  local pos = wpos()\n\n  -- Process each character.\n  for p in gmatch(sub(template, 9), \".\") do\n    if p == \"R\" then\n      rs = rs - 5; op = op + shl(parse_gpr(params[n]), rs); n = n + 1\n    elseif p == \"F\" then\n      rs = rs - 5; op = op + shl(parse_fpr(params[n]), rs); n = n + 1\n    elseif p == \"V\" then\n      rs = rs - 5; op = op + shl(parse_vr(params[n]), rs); n = n + 1\n    elseif p == \"Q\" then\n      local vs = parse_vs(params[n]); n = n + 1; rs = rs - 5\n      local sh = rs == 6 and 2 or 3 + band(shr(rs, 1), 3)\n      op = op + shl(band(vs, 31), rs) + shr(band(vs, 32), sh)\n    elseif p == \"q\" then\n      local vs = parse_vs(params[n]); n = n + 1\n      op = op + shl(band(vs, 31), 21) + shr(band(vs, 32), 5)\n    elseif p == \"A\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, false); n = n + 1\n    elseif p == \"S\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, true); n = n + 1\n    elseif p == \"I\" then\n      op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1\n    elseif p == \"U\" then\n      op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1\n    elseif p == \"D\" then\n      op = op + parse_disp(params[n]); n = n + 1\n    elseif p == \"2\" then\n      op = op + parse_u5disp(params[n], 1); n = n + 1\n    elseif p == \"4\" then\n      op = op + parse_u5disp(params[n], 2); n = n + 1\n    elseif p == \"8\" then\n      op = op + parse_u5disp(params[n], 3); n = n + 1\n    elseif p == \"C\" then\n      rs = rs - 5; op = op + shl(parse_cond(params[n]), rs); n = n + 1\n    elseif p == \"X\" then\n      rs = rs - 5; op = op + shl(parse_cr(params[n]), rs+2); n = n + 1\n    elseif p == \"1\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs, 0, false); n = n + 1\n    elseif p == \"g\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs, 0, false); n = n + 1\n    elseif p == \"3\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 3, rs, 0, false); n = n + 1\n    elseif p == \"P\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 4, rs, 0, false); n = n + 1\n    elseif p == \"p\" then\n      op = op + parse_imm(params[n], 4, rs, 0, false); n = n + 1\n    elseif p == \"6\" then\n      rs = rs - 6; op = op + parse_imm(params[n], 6, rs, 0, false); n = n + 1\n    elseif p == \"Y\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs+4, 0, false); n = n + 1\n    elseif p == \"y\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 1, rs+3, 0, false); n = n + 1\n    elseif p == \"Z\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs+3, 0, false); n = n + 1\n    elseif p == \"z\" then\n      rs = rs - 5; op = op + parse_imm(params[n], 2, rs+2, 0, false); n = n + 1\n    elseif p == \"W\" then\n      op = op + parse_cr(params[n]); n = n + 1\n    elseif p == \"G\" then\n      op = op + parse_imm(params[n], 8, 12, 0, false); n = n + 1\n    elseif p == \"H\" then\n      op = op + parse_shiftmask(params[n], true); n = n + 1\n    elseif p == \"M\" then\n      op = op + parse_shiftmask(params[n], false); n = n + 1\n    elseif p == \"J\" or p == \"K\" then\n      local mode, m, s = parse_label(params[n], false)\n      if p == \"K\" then m = m + 2048 end\n      waction(\"REL_\"..mode, m, s, 1)\n      n = n + 1\n    elseif p == \"0\" then\n      if band(shr(op, rs), 31) == 0 then werror(\"cannot use r0\") end\n    elseif p == \"=\" or p == \"%\" then\n      local t = band(shr(op, p == \"%\" and rs+5 or rs), 31)\n      rs = rs - 5\n      op = op + shl(t, rs)\n    elseif p == \"~\" then\n      local mm = shl(31, rs)\n      local lo = band(op, mm)\n      local hi = band(op, shl(mm, 5))\n      op = op - lo - hi + shl(lo, 5) + shr(hi, 5)\n    elseif p == \":\" then\n      if band(shr(op, rs), 1) ~= 0 then werror(\"register pair expected\") end\n    elseif p == \"-\" then\n      rs = rs - 5\n    elseif p == \".\" then\n      -- Ignored.\n    else\n      assert(false)\n    end\n  end\n  wputpos(pos, op)\nend\n\nmap_op[\".template__\"] = op_template\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _,p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_proto.h",
    "content": "/*\n** DynASM encoding engine prototypes.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#ifndef _DASM_PROTO_H\n#define _DASM_PROTO_H\n\n#include <stddef.h>\n#include <stdarg.h>\n\n#define DASM_IDENT\t\"DynASM 1.5.0\"\n#define DASM_VERSION\t10500\t/* 1.5.0 */\n\n#ifndef Dst_DECL\n#define Dst_DECL\tdasm_State **Dst\n#endif\n\n#ifndef Dst_REF\n#define Dst_REF\t\t(*Dst)\n#endif\n\n#ifndef DASM_FDEF\n#define DASM_FDEF\textern\n#endif\n\n#ifndef DASM_M_GROW\n#define DASM_M_GROW(ctx, t, p, sz, need) \\\n  do { \\\n    size_t _sz = (sz), _need = (need); \\\n    if (_sz < _need) { \\\n      if (_sz < 16) _sz = 16; \\\n      while (_sz < _need) _sz += _sz; \\\n      (p) = (t *)realloc((p), _sz); \\\n      if ((p) == NULL) exit(1); \\\n      (sz) = _sz; \\\n    } \\\n  } while(0)\n#endif\n\n#ifndef DASM_M_FREE\n#define DASM_M_FREE(ctx, p, sz)\tfree(p)\n#endif\n\n/* Internal DynASM encoder state. */\ntypedef struct dasm_State dasm_State;\n\n\n/* Initialize and free DynASM state. */\nDASM_FDEF void dasm_init(Dst_DECL, int maxsection);\nDASM_FDEF void dasm_free(Dst_DECL);\n\n/* Setup global array. Must be called before dasm_setup(). */\nDASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nDASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);\n\n/* Setup encoder. */\nDASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);\n\n/* Feed encoder with actions. Calls are generated by pre-processor. */\nDASM_FDEF void dasm_put(Dst_DECL, int start, ...);\n\n/* Link sections and return the resulting size. */\nDASM_FDEF int dasm_link(Dst_DECL, size_t *szp);\n\n/* Encode sections into buffer. */\nDASM_FDEF int dasm_encode(Dst_DECL, void *buffer);\n\n/* Get PC label offset. */\nDASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nDASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);\n#else\n#define dasm_checkstep(a, b)\t0\n#endif\n\n\n#endif /* _DASM_PROTO_H */\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_s390x.h",
    "content": "/*\n** DynASM s390x encoding engine.\n** Copyright (C) 2005-2017 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"s390x\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. */\nenum {\n  DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,\n  /* The following actions need a buffer position. */\n  DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,\n  /* The following actions also have an argument. */\n  DASM_REL_PC, DASM_LABEL_PC,\n  DASM_DISP12, DASM_DISP20,\n  DASM_IMM8, DASM_IMM16, DASM_IMM32,\n  DASM_LEN8R,DASM_LEN4HR,DASM_LEN4LR,\n  DASM__MAX\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_REL\t0x15000000\n#define DASM_S_UNDEF_LG\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned short *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;                    /* Biased buffer pointer (negative section bias). */\n  int *buf;                     /* True buffer pointer. */\n  size_t bsize;                 /* Buffer size in bytes. */\n  int pos;                      /* Biased buffer position. */\n  int epos;                     /* End of biased buffer position - max single put. */\n  int ofs;                      /* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;                 /* Allocated size of this structure. */\n  dasm_ActList actionlist;      /* Current actionlist pointer. */\n  int *lglabels;                /* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;                /* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;               /* Array of globals (bias -10). */\n  dasm_Section *section;        /* Pointer to active section. */\n  size_t codesize;              /* Total size of all code sections. */\n  int maxsection;               /* 0 <= sectionidx < maxsection. */\n  int status;                   /* Status code. */\n  dasm_Section sections[1];     /* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;    /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels)\n    DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels)\n    DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;         /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10 + maxgl) * sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc * sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels) + osz), 0, D->pcsize - osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList) actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels)\n    memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n                sec->bsize + 2 * DASM_MAXSECPOS * sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos =\n      (int)sec->bsize / sizeof(int) - DASM_MAXSECPOS + DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    unsigned short ins = *p++;\n    unsigned short action = ins;\n    if (action >= DASM__MAX) {\n      ofs += 2;\n      continue;\n    }\n\n    int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;\n    switch (action) {\n    case DASM_STOP:\n      goto stop;\n    case DASM_SECTION:\n      n = *p++ & 255;\n      CK(n < D->maxsection, RANGE_SEC);\n      D->section = &D->sections[n];\n      goto stop;\n    case DASM_ESC:\n      p++;\n      ofs += 2;\n      break;\n    case DASM_REL_EXT:\n      p++;\n      ofs += 4;\n      break;\n    case DASM_ALIGN:\n      ofs += *p++;\n      b[pos++] = ofs;\n      break;\n    case DASM_REL_LG:\n      if (p[-2] >> 12 == 0xc) { /* RIL instruction needs 32-bit immediate. */\n        ofs += 2;\n      }\n      n = *p++ - 10;\n      pl = D->lglabels + n;\n      /* Bkwd rel or global. */\n      if (n >= 0) {\n        CK(n >= 10 || *pl < 0, RANGE_LG);\n        CKPL(lg, LG);\n        goto putrel;\n      }\n      pl += 10;\n      n = *pl;\n      if (n < 0)\n        n = 0;                  /* Start new chain for fwd rel if label exists. */\n      goto linkrel;\n    case DASM_REL_PC:\n      if (p[-2] >> 12 == 0xc) { /* RIL instruction needs 32-bit immediate. */\n        ofs += 2;\n      }\n      pl = D->pclabels + n;\n      CKPL(pc, PC);\n    putrel:\n      n = *pl;\n      if (n < 0) {              /* Label exists. Get label pos and store it. */\n        b[pos] = -n;\n      } else {\n      linkrel:\n        b[pos] = n;             /* Else link to rel chain, anchored at label. */\n        *pl = pos;\n      }\n      ofs += 2;\n      pos++;\n      break;\n    case DASM_LABEL_LG:\n      pl = D->lglabels + *p++ - 10;\n      CKPL(lg, LG);\n      goto putlabel;\n    case DASM_LABEL_PC:\n      pl = D->pclabels + n;\n      CKPL(pc, PC);\n    putlabel:\n      n = *pl;                  /* n > 0: Collapse rel chain and replace with label pos. */\n      while (n > 0) {\n        int *pb = DASM_POS2PTR(D, n);\n        n = *pb;\n        *pb = pos;\n      }\n      *pl = -pos;               /* Label exists now. */\n      b[pos++] = ofs;           /* Store pass1 offset estimate. */\n      break;\n    case DASM_IMM8:\n      b[pos++] = n;\n      break;\n    case DASM_IMM16:\n      CK(((short)n) == n || ((unsigned short)n) == n, RANGE_I);     /* TODO: is this the right way to handle unsigned immediates? */\n      ofs += 2;\n      b[pos++] = n;\n      break;\n    case DASM_IMM32:\n      ofs += 4;\n      b[pos++] = n;\n      break;\n    case DASM_DISP20:\n      CK(-(1 << 19) <= n && n < (1 << 19), RANGE_I);\n      b[pos++] = n;\n      break;\n    case DASM_DISP12:\n      CK((n >> 12) == 0, RANGE_I);\n      b[pos++] = n;\n      break;\n    case DASM_LEN8R:\n      CK(n >= 1 && n <= 256, RANGE_I);\n      b[pos++] = n;\n      break;\n    case DASM_LEN4HR:\n    case DASM_LEN4LR:\n      CK(n >= 1 && n <= 128, RANGE_I);\n      b[pos++] = n;\n      break;\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n\n#undef CK\n\n/* Pass 2: Link sections, shrink aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t * szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK)\n    return D->status;\n  {\n    int pc;\n    for (pc = 0; pc * sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0)\n        return DASM_S_UNDEF_PC | pc;\n  }\n#endif\n\n  {                             /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 20; idx * sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) {\n        int *pb = DASM_POS2PTR(D, n);\n        n = *pb;\n        *pb = -idx;\n      }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      while (1) {\n        unsigned short ins = *p++;\n        unsigned short action = ins;\n        switch (action) {\n        case DASM_STOP:\n        case DASM_SECTION:\n          goto stop;\n        case DASM_ESC:\n          p++;\n          break;\n        case DASM_REL_EXT:\n          p++;\n          break;\n        case DASM_ALIGN:\n          ofs -= (b[pos++] + ofs) & *p++;\n          break;\n        case DASM_REL_LG:\n        case DASM_REL_PC:\n          p++;\n          pos++;\n          break;\n        case DASM_LABEL_LG:\n        case DASM_LABEL_PC:\n          p++;\n          b[pos++] += ofs;\n          break;\n        case DASM_IMM8:\n        case DASM_IMM16:\n        case DASM_IMM32:\n        case DASM_DISP20:\n        case DASM_DISP12:\n        case DASM_LEN8R:\n        case DASM_LEN4HR:\n        case DASM_LEN4LR:\n          pos++;\n          break;\n        }\n      }\n    stop:(void)0;\n    }\n    ofs += sec->ofs;            /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;            /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#endif\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  char *base = (char *)buffer;\n  unsigned short *cp = (unsigned short *)buffer;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      while (1) {\n        unsigned short ins = *p++;\n        unsigned short action = ins;\n        int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;\n        switch (action) {\n        case DASM_STOP:\n        case DASM_SECTION:\n          goto stop;\n        case DASM_ESC:\n          *cp++ = *p++;\n          break;\n        case DASM_REL_EXT:\n          n = DASM_EXTERN(Dst, (unsigned char *)cp, *p++, 1) - 4;\n          goto patchrel;\n        case DASM_ALIGN:\n          ins = *p++;\n          /* TODO: emit 4-byte noprs instead of 2-byte nops where possible. */\n          while ((((char *)cp - base) & ins))\n            *cp++ = 0x0700;     /* nop */\n          break;\n        case DASM_REL_LG:\n          CK(n >= 0, UNDEF_LG);\n        case DASM_REL_PC:\n          CK(n >= 0, UNDEF_PC);\n          n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);\n          p++;                  /* skip argument */\n        patchrel:\n          /* Offsets are halfword aligned (so need to be halved). */\n          n += 2;               /* Offset is relative to start of instruction. */\n          if (cp[-1] >> 12 == 0xc) {\n            *cp++ = n >> 17;\n          } else {\n            CK(-(1 << 16) <= n && n < (1 << 16) && (n & 1) == 0, RANGE_LG);\n          }\n          *cp++ = n >> 1;\n          break;\n        case DASM_LABEL_LG:\n          ins = *p++;\n          if (ins >= 20)\n            D->globals[ins - 10] = (void *)(base + n);\n          break;\n        case DASM_LABEL_PC:\n          break;\n        case DASM_IMM8:\n          cp[-1] |= n & 0xff;  \n          break;\n        case DASM_IMM16:\n          *cp++ = n;\n          break;\n        case DASM_IMM32:\n          *cp++ = n >> 16;\n          *cp++ = n;\n          break;\n        case DASM_DISP20:\n          cp[-2] |= n & 0xfff;\n          cp[-1] |= (n >> 4) & 0xff00;\n          break;\n        case DASM_DISP12:\n          cp[-1] |= n & 0xfff;\n          break;\n        case DASM_LEN8R:\n          cp[-1] |= (n - 1) & 0xff;\n          break;\n        case DASM_LEN4HR:\n          cp[-1] |= ((n - 1) << 4) & 0xf0;\n          break;\n        case DASM_LEN4LR:\n          cp[-1] |= (n - 1) & 0x0f;\n          break;\n        default:\n          *cp++ = ins;\n          break;\n        }\n      }\n    stop:(void)0;\n    }\n  }\n\n  if (base + D->codesize != (char *)cp) /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n\n#undef CK\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc * sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0)\n      return *DASM_POS2PTR(D, -pos);\n    if (pos > 0)\n      return -1;                /* Undefined. */\n  }\n  return -2;                    /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) {\n        D->status = DASM_S_UNDEF_LG | i;\n        break;\n      }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC | (D->section - D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_s390x.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM s390x module.\n--\n-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Module information:\nlocal _info = {\n  arch =\t\"s390x\",\n  description =\t\"DynASM s390x module\",\n  version =\t\"1.4.0\",\n  vernum =\t 10400,\n  release =\t\"2015-10-18\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, setmetatable, rawget = assert, setmetatable, rawget\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, insert = table.concat, table.sort, table.insert\nlocal bit = bit or require(\"bit\")\nlocal band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift\nlocal ror, tohex = bit.ror, bit.tohex\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  \"STOP\", \"SECTION\", \"ESC\", \"REL_EXT\",\n  \"ALIGN\", \"REL_LG\", \"LABEL_LG\",\n  \"REL_PC\", \"LABEL_PC\", \"DISP12\", \"DISP20\", \"IMM8\", \"IMM16\", \"IMM32\", \"LEN8R\",\"LEN4HR\",\"LEN4LR\",\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number.\nlocal map_action = {}\nlocal max_action = 0\nfor n, name in ipairs(action_names) do\n  map_action[name] = n-1\n  max_action = n\nend\n\n-- Action list buffer.\nlocal actlist = {}\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n------------------------------------------------------------------------------\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n, name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\nlocal function havearg(a)\n  return a == \"ESC\" or\n         a == \"SECTION\" or\n         a == \"REL_LG\" or\n         a == \"LABEL_LG\" or\n         a == \"REL_EXT\"\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  if nn == 0 then nn = 1; actlist[0] = map_action.STOP end\n  out:write(\"static const unsigned short \", name, \"[\", nn, \"] = {\")\n  local esc = false -- also need to escape for action arguments\n  for i = 1, nn do\n    assert(out:write(\"\\n  0x\", sub(tohex(actlist[i]), 5, 8)))\n    if i ~= nn then assert(out:write(\",\")) end\n    local name = action_names[actlist[i]+1]\n    if not esc and name then\n      assert(out:write(\" /* \", name, \" */\"))\n      esc = havearg(name)\n    else\n      esc = false\n    end\n  end\n  assert(out:write(\"\\n};\\n\\n\"))\nend\n\n------------------------------------------------------------------------------\n\n-- Add halfword to action list.\nlocal function wputxhw(n)\n  assert(n >= 0 and n <= 0xffff, \"halfword out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, val, a, num)\n  local w = assert(map_action[action], \"bad action name `\"..action..\"'\")\n  wputxhw(w)\n  if val then wputxhw(val) end -- Not sure about this, do we always have one arg?\n  if a then actargs[#actargs+1] = a end\n  if val or a or num then secpos = secpos + (num or 1) end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  if #actlist == actargs[1] then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  wline(format(\"dasm_put(Dst, %s);\", concat(actargs, \", \")), true)\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped halfword.\nlocal function wputhw(n)\n  if n <= max_action then waction(\"ESC\") end\n  wputxhw(n)\nend\n\n-- Reserve position for halfword.\nlocal function wpos()\n  local pos = #actlist+1\n  actlist[pos] = \"\"\n  return pos\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 20\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 2047 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=20, next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=20, next_global-1 do\n    out:write(\"  \", prefix, t[i], \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=20, next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = 0\nlocal map_extern_ = {}\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n > 2047 then werror(\"too many extern labels\") end\n  next_extern = n + 1\n  t[name] = n\n  map_extern_[n] = name\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  out:write(\"Extern labels:\\n\")\n  for i=0, next_extern-1 do\n    out:write(format(\"  %s\\n\", map_extern_[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=0, next_extern-1 do\n    out:write(\"  \\\"\", map_extern_[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\n-- Ext. register name -> int. name.\nlocal map_archdef = { sp = \"r15\" }\n\n-- Int. register name -> ext. name.\nlocal map_reg_rev = { r15 = \"sp\" }\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for Dt... macros).\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return map_reg_rev[s] or s\nend\n\nlocal map_cond = {\n  o = 1, h = 2, nle = 3, l = 4,\n  nhe = 5, lh = 6, ne = 7, e = 8,\n  nlh = 9, he = 10, nl = 11, le = 12,\n  nh = 13, no = 14, [\"\"] = 15,\n}\n\n------------------------------------------------------------------------------\n\nlocal function parse_reg(expr)\n  if not expr then werror(\"expected register name\") end\n  local tname, ovreg = match(expr, \"^([%w_]+):(r1?%d)$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    if not reg then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    expr = reg\n  end\n  local r = match(expr, \"^[rf](1?%d)$\")\n  if r then\n    r = tonumber(r)\n    if r <= 15 then return r, tp end\n  end\n  werror(\"bad register name `\"..expr..\"'\")\nend\n\nlocal parse_ctx = {}\n\nlocal loadenv = setfenv and function(s)\n  local code = loadstring(s, \"\")\n  if code then setfenv(code, parse_ctx) end\n  return code\nend or function(s)\n  return load(s, \"\", nil, parse_ctx)\nend\n\n-- Try to parse simple arithmetic, too, since some basic ops are aliases.\nlocal function parse_number(n)\n  local x = tonumber(n)\n  if x then return x end\n  local code = loadenv(\"return \"..n)\n  if code then\n    local ok, y = pcall(code)\n    if ok then return y end\n  end\n  return nil\nend\n\nlocal function is_uint12(num)\n  return 0 <= num and num < 4096\nend\n\nlocal function is_int20(num)\n  return -shl(1, 19) <= num and num < shl(1, 19)\nend\n\nlocal function is_int32(num)\n  return -2147483648 <= num and num < 2147483648\nend\n\nlocal function is_uint16(num)\n  return 0 <= num and num < 0xffff\nend\n\nlocal function is_int16(num)\n  return -32768 <= num and num < 32768\nend\n\nlocal function is_int8(num)\n  return -128 <= num and num < 128\nend\n\nlocal function is_uint8(num)\n  return 0 <= num and num < 256\nend\n\n-- Split a memory operand of the form d(b) or d(x,b) into d, x and b.\n-- If x is not specified then it is 0.\nlocal function split_memop(arg)\n  local reg = \"[%w_:]+\"\n  local d, x, b = match(arg, \"^(.*)%(%s*(\"..reg..\")%s*,%s*(\"..reg..\")%s*%)$\")\n  if d then\n    return d, parse_reg(x), parse_reg(b)\n  end\n  local d, b = match(arg, \"^(.*)%(%s*(\"..reg..\")%s*%)$\")\n  if d then\n    return d, 0, parse_reg(b)\n  end\n  -- Assume the two registers are passed as \"(r1,r2)\", and displacement(d) is not specified. TODO: not sure if we want to do this, GAS doesn't.\n  local x, b = match(arg,\"%(%s*(\"..reg..\")%s*,%s*(\"..reg..\")%s*%)$\")\n  if b then\n    return 0, parse_reg(x), parse_reg(b)\n  end\n  -- Accept a lone integer as a displacement. TODO: allow expressions/variables here? Interacts badly with the other rules currently.\n  local d = match(arg,\"^(-?[%d]+)$\")\n  if d then\n    return d, 0, 0\n  end\n  local reg, tailr = match(arg, \"^([%w_:]+)%s*(.*)$\")\n  if reg then\n    local r, tp = parse_reg(reg)\n    if tp then\n      return format(tp.ctypefmt, tailr), 0, r\n    end\n  end\n  werror(\"bad memory operand: \"..arg)\n  return nil\nend\n\n-- Parse memory operand of the form d(x, b) where 0 <= d < 4096 and b and x\n-- are GPRs.\n-- If the fourth return value is not-nil then it needs to be called to\n-- insert an action.\n-- Encoded as: xbddd\nlocal function parse_mem_bx(arg)\n  local d, x, b = split_memop(arg)\n  local dval = tonumber(d)\n  if dval then\n    if not is_uint12(dval) then\n      werror(\"displacement out of range: \", dval)\n    end\n    return dval, x, b, nil\n  end\n  if match(d, \"^[rf]1?[0-9]?\") then\n    werror(\"expected immediate operand, got register\")\n  end\n  return 0, x, b, function() waction(\"DISP12\", nil, d) end\nend\n\n-- Parse memory operand of the form d(b) where 0 <= d < 4096 and b is a GPR.\n-- Encoded as: bddd\nlocal function parse_mem_b(arg)\n  local d, x, b, a = parse_mem_bx(arg)\n  if x ~= 0 then\n    werror(\"unexpected index register\")\n  end\n  return d, b, a\nend\n\n-- Parse memory operand of the form d(x, b) where -(2^20)/2 <= d < (2^20)/2\n-- and b and x are GPRs.\n-- Encoded as: xblllhh (ls are the low-bits of d, and hs are the high bits).\nlocal function parse_mem_bxy(arg)\n  local d, x, b = split_memop(arg)\n  local dval = tonumber(d)\n  if dval then\n    if not is_int20(dval) then\n      werror(\"displacement out of range: \", dval)\n    end\n    return dval, x, b, nil\n  end\n  if match(d, \"^[rf]1?[0-9]?\") then\n    werror(\"expected immediate operand, got register\")\n  end\n  return 0, x, b, function() waction(\"DISP20\", nil, d) end\nend\n\n-- Parse memory operand of the form d(b) where -(2^20)/2 <= d < (2^20)/2 and\n-- b is a GPR.\n-- Encoded as: blllhh (ls are the low-bits of d, and hs are the high bits).\nlocal function parse_mem_by(arg)\n  local d, x, b, a = parse_mem_bxy(arg)\n  if x ~= 0 then\n    werror(\"unexpected index register\")\n  end\n  return d, b, a\nend\n\n-- Parse memory operand of the form d(l, b) where 0 <= d < 4096, 1 <= l <= 256,\n-- and b is a GPR.\nlocal function parse_mem_lb(arg)\n  local reg = \"r1?[0-9]\"\n  local d, l, b = match(arg, \"^(.*)%s*%(%s*(.*)%s*,%s*(\"..reg..\")%s*%)$\")\n  if not d then\n    -- TODO: handle values without registers?\n    -- TODO: handle registers without a displacement?\n    werror(\"bad memory operand: \"..arg)\n    return nil\n  end\n  local dval = tonumber(d)\n  local dact = nil\n  if dval then\n    if not is_uint12(dval) then\n      werror(\"displacement out of range: \", dval)\n    end\n  else\n    dval = 0\n    dact = function() waction(\"DISP12\", nil, d) end\n  end\n  local lval = tonumber(l)\n  local lact = nil\n  if lval then\n    if lval < 1 or lval > 256 then\n      werror(\"length out of range: \", dval)\n    end\n    lval = lval - 1\n  else\n    lval = 0\n    lact = function() waction(\"LEN8R\", nil, l) end\n  end\n  return dval, lval, parse_reg(b), dact, lact\nend\n\nlocal function parse_mem_l2b(arg, high_l)\n  local reg = \"r1?[0-9]\"\n  local d, l, b = match(arg, \"^(.*)%s*%(%s*(.*)%s*,%s*(\"..reg..\")%s*%)$\")\n  if not d then\n    -- TODO: handle values without registers?\n    -- TODO: handle registers without a displacement?\n    werror(\"bad memory operand: \"..arg)\n    return nil\n  end\n  local dval = tonumber(d)\n  local dact = nil\n  if dval then\n    if not is_uint12(dval) then\n      werror(\"displacement out of range: \", dval)\n    end\n  else\n    dval = 0\n    dact = function() waction(\"DISP12\", nil, d) end\n  end\n  local lval = tonumber(l)\n  local lact = nil\n  if lval then\n    if lval < 1 or lval > 128 then\n      werror(\"length out of range: \", dval)\n    end\n    lval = lval - 1\n  else\n    lval = 0\n    if high_l then\n    lact = function() waction(\"LEN4HR\", nil, l) end\n    else\n    lact = function() waction(\"LEN4LR\", nil, l) end\n    end\n  end\n  return dval, lval, parse_reg(b), dact, lact\nend\n\nlocal function parse_imm32(imm)\n  local imm_val = tonumber(imm)\n  if imm_val then\n    if not is_int32(imm_val) then\n      werror(\"immediate value out of range: \", imm_val)\n    end\n    wputhw(band(shr(imm_val, 16), 0xffff))\n    wputhw(band(imm_val, 0xffff))\n  elseif match(imm, \"^[rfv]([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r1?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMM32\", nil, imm) -- if we get label\n  end\nend\n\nlocal function parse_imm16(imm)\n  local imm_val = tonumber(imm)\n  if imm_val then\n    if not is_int16(imm_val) and not is_uint16(imm_val) then\n      werror(\"immediate value out of range: \", imm_val)\n    end\n    wputhw(band(imm_val, 0xffff))\n  elseif match(imm, \"^[rfv]([1-3]?[0-9])$\") or\n\t match(imm, \"^([%w_]+):(r1?[0-9])$\") then\n    werror(\"expected immediate operand, got register\")\n  else\n    waction(\"IMM16\", nil, imm)\n  end\nend\n\nlocal function parse_imm8(imm)\n  local imm_val = tonumber(imm)\n  if imm_val then\n    if not is_int8(imm_val) and not is_uint8(imm_val) then\n      werror(\"Immediate value out of range: \", imm_val)\n    end\n    return imm_val, nil\n  end\n  return 0, function() waction(\"IMM8\", nil, imm) end\nend\n\nlocal function parse_mask(mask)\n  local m3 = parse_number(mask)\n  if m3 then\n    if ((m3 == 1) or (m3 == 0) or ( m3 >=3 and m3 <=7)) then\n      return m3\n    else\n      werror(\"Mask value should be 0,1 or 3-7: \", m3)\n    end\n  end\nend\n\nlocal function parse_mask2(mask)\n  local m4 = parse_number(mask)\n  if ( m4 >=0 and m4 <=1) then\n    return m4\n  else\n    werror(\"Mask value should be 0 or 1: \", m4)\n  end\nend\n\nlocal function parse_label(label, def)\n  local prefix = sub(label, 1, 2)\n  -- =>label (pc label reference)\n  if prefix == \"=>\" then\n    return \"PC\", 0, sub(label, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"LG\", map_global[sub(label, 3)]\n  end\n  if def then\n    -- [1-9] (local label definition)\n    if match(label, \"^[1-9]$\") then\n      return \"LG\", 10+tonumber(label)\n    end\n  else\n    -- [<>][1-9] (local label reference)\n    local dir, lnum = match(label, \"^([<>])([1-9])$\")\n    if dir then -- Fwd: 1-9, Bkwd: 11-19.\n      return \"LG\", lnum + (dir == \">\" and 0 or 10)\n    end\n    -- extern label (extern label reference)\n    local extname = match(label, \"^extern%s+(%S+)$\")\n    if extname then\n      return \"EXT\", map_extern[extname]\n    end\n  end\n  werror(\"bad label `\"..label..\"'\")\nend\n\n------------------------------------------------------------------------------\n\nlocal map_op, op_template\n\nlocal function op_alias(opname, f)\n  return function(params, nparams)\n    if not params then return \"-> \"..opname:sub(1, -3) end\n    f(params, nparams)\n    op_template(params, map_op[opname], nparams)\n  end\nend\n\n-- Template strings for s390x instructions.\nmap_op = {\n  a_2 =\t\t\"00005a000000RX-a\",\n  ad_2 =\t\"00006a000000RX-a\",\n  adb_2 =\t\"ed000000001aRXE\",\n  adbr_2 =\t\"0000b31a0000RRE\",\n  adr_2 =\t\"000000002a00RR\",\n  ae_2 =\t\"00007a000000RX-a\",\n  aeb_2 =\t\"ed000000000aRXE\",\n  aebr_2 =\t\"0000b30a0000RRE\",\n  aer_2 =\t\"000000003a00RR\",\n  afi_2 =\t\"c20900000000RIL-a\",\n  ag_2 =\t\"e30000000008RXY-a\",\n  agf_2 =\t\"e30000000018RXY-a\",\n  agfi_2 =\t\"c20800000000RIL-a\",\n  agfr_2 =\t\"0000b9180000RRE\",\n  aghi_2 =\t\"0000a70b0000RI-a\",\n  agr_2 =\t\"0000b9080000RRE\",\n  ah_2 =\t\"00004a000000RX-a\",\n  ahi_2 =\t\"0000a70a0000RI-a\",\n  ahy_2 =\t\"e3000000007aRXY-a\",\n  aih_2 =\t\"cc0800000000RIL-a\",\n  al_2 =\t\"00005e000000RX-a\",\n  alc_2 =\t\"e30000000098RXY-a\",\n  alcg_2 =\t\"e30000000088RXY-a\",\n  alcgr_2 =\t\"0000b9880000RRE\",\n  alcr_2 =\t\"0000b9980000RRE\",\n  alfi_2 =\t\"c20b00000000RIL-a\",\n  alg_2 =\t\"e3000000000aRXY-a\",\n  algf_2 =\t\"e3000000001aRXY-a\",\n  algfi_2 =\t\"c20a00000000RIL-a\",\n  algfr_2 =\t\"0000b91a0000RRE\",\n  algr_2 =\t\"0000b90a0000RRE\",\n  alr_2 =\t\"000000001e00RR\",\n  alsih_2 =\t\"cc0a00000000RIL-a\",\n  alsihn_2 =\t\"cc0b00000000RIL-a\",\n  aly_2 =\t\"e3000000005eRXY-a\",\n  ap_2 =\t\"fa0000000000SS-b\",\n  ar_2 =\t\"000000001a00RR\",\n  au_2 =\t\"00007e000000RX-a\",\n  aur_2 =\t\"000000003e00RR\",\n  aw_2 =\t\"00006e000000RX-a\",\n  awr_2 =\t\"000000002e00RR\",\n  axbr_2 =\t\"0000b34a0000RRE\",\n  axr_2 =\t\"000000003600RR\",\n  ay_2 =\t\"e3000000005aRXY-a\",\n  bakr_2 =\t\"0000b2400000RRE\",\n  bal_2 =\t\"000045000000RX-a\",\n  balr_2 =\t\"000000000500RR\",\n  bas_2 =\t\"00004d000000RX-a\",\n  basr_2 =\t\"000000000d00RR\",\n  bassm_2 =\t\"000000000c00RR\",\n  bc_2 =\t\"000047000000RX-b\",\n  bc_2 =\t\"000047000000RX-b\",\n  bcr_2 =\t\"000000000700RR\",\n  bct_2 =\t\"000046000000RX-a\",\n  bctg_2 =\t\"e30000000046RXY-a\",\n  bctgr_2 =\t\"0000b9460000RRE\",\n  bctr_2 =\t\"000000000600RR\",\n  bras_2 =\t\"0000a7050000RI-b\",\n  brasl_2 =\t\"c00500000000RIL-b\",\n  brc_2 =\t\"0000a7040000RI-c\",\n  brcl_2 =\t\"c00400000000RIL-c\",\n  brcl_2 =\t\"c00400000000RIL-c\",\n  brct_2 =\t\"0000a7060000RI-b\",\n  brctg_2 =\t\"0000a7070000RI-b\",\n  brcth_2 =\t\"cc0600000000RIL-b\",\n  brxh_3 =\t\"000084000000RSI\",\n  brxhg_3 =\t\"ec0000000044RIE-e\",\n  bsa_2 =\t\"0000b25a0000RRE\",\n  bsg_2 =\t\"0000b2580000RRE\",\n  bsm_2 =\t\"000000000b00RR\",\n  bxh_3 =\t\"000086000000RS-a\",\n  bxhg_3 =\t\"eb0000000044RSY-a\",\n  bxle_3 =\t\"000087000000RS-a\",\n  bxleg_3 =\t\"eb0000000045RSY-a\",\n  c_2 =\t\t\"000059000000RX-a\",\n  cd_2 =\t\"000069000000RX-a\",\n  cdb_2 =\t\"ed0000000019RXE\",\n  cdbr_2 =\t\"0000b3190000RRE\",\n  cdfbr_2 =\t\"0000b3950000RRE\",\n  cdfbra_4 =\t\"0000b3950000RRF-e\",\n  cdfr_2 =\t\"0000b3b50000RRE\",\n  cdftr_2 =\t\"0000b9510000RRE\",\n  cdgbr_2 =\t\"0000b3a50000RRE\",\n  cdgbra_4 =\t\"0000b3a50000RRF-e\",\n  cdgr_2 =\t\"0000b3c50000RRE\",\n  cdgtr_2 =\t\"0000b3f10000RRE\",\n  cdr_2 =\t\"000000002900RR\",\n  cds_3 =\t\"0000bb000000RS-a\",\n  cdsg_3 =\t\"eb000000003eRSY-a\",\n  cdstr_2 =\t\"0000b3f30000RRE\",\n  cdsy_3 =\t\"eb0000000031RSY-a\",\n  cdtr_2 =\t\"0000b3e40000RRE\",\n  cdutr_2 =\t\"0000b3f20000RRE\",\n  ce_2 =\t\"000079000000RX-a\",\n  ceb_2 =\t\"ed0000000009RXE\",\n  cebr_2 =\t\"0000b3090000RRE\",\n  cedtr_2 =\t\"0000b3f40000RRE\",\n  cefbr_2 =\t\"0000b3940000RRE\",\n  cefbra_4 =\t\"0000b3940000RRF-e\",\n  cefr_2 =\t\"0000b3b40000RRE\",\n  cegbr_2 =\t\"0000b3a40000RRE\",\n  cegbra_4 =\t\"0000b3a40000RRF-e\",\n  cegr_2 =\t\"0000b3c40000RRE\",\n  cer_2 =\t\"000000003900RR\",\n  cextr_2 =\t\"0000b3fc0000RRE\",\n  cfdbr_3 =\t\"0000b3990000RRF-e\",\n  cfdbra_4 =\t\"0000b3990000RRF-e\",\n  cfebr_3 =\t\"0000b3980000RRF-e\",\n  cfebra_4 =\t\"0000b3980000RRF-e\",\n  cfi_2 =\t\"c20d00000000RIL-a\",\n  cfxbr_3 =\t\"0000b39a0000RRF-e\",\n  cfxbra_4 =\t\"0000b39a0000RRF-e\",\n  cg_2 =\t\"e30000000020RXY-a\",\n  cgdbr_3 =\t\"0000b3a90000RRF-e\",\n  cgdbra_4 =\t\"0000b3a90000RRF-e\",\n  cgebr_3 =\t\"0000b3a80000RRF-e\",\n  cgebra_4 =\t\"0000b3a80000RRF-e\",\n  cgf_2 =\t\"e30000000030RXY-a\",\n  cgfi_2 =\t\"c20c00000000RIL-a\",\n  cgfr_2 =\t\"0000b9300000RRE\",\n  cgfrl_2 =\t\"c60c00000000RIL-b\",\n  cgh_2 =\t\"e30000000034RXY-a\",\n  cghi_2 =\t\"0000a70f0000RI-a\",\n  cghrl_2 =\t\"c60400000000RIL-b\",\n  cgr_2 =\t\"0000b9200000RRE\",\n  cgrl_2 =\t\"c60800000000RIL-b\",\n  cgxbr_3 =\t\"0000b3aa0000RRF-e\",\n  cgxbra_4 =\t\"0000b3aa0000RRF-e\",\n  ch_2 =\t\"000049000000RX-a\",\n  chf_2 =\t\"e300000000cdRXY-a\",\n  chhr_2 =\t\"0000b9cd0000RRE\",\n  chi_2 =\t\"0000a70e0000RI-a\",\n  chlr_2 =\t\"0000b9dd0000RRE\",\n  chrl_2 =\t\"c60500000000RIL-b\",\n  chy_2 =\t\"e30000000079RXY-a\",\n  cih_2 =\t\"cc0d00000000RIL-a\",\n  cksm_2 =\t\"0000b2410000RRE\",\n  cl_2 =\t\"000055000000RX-a\",\n  clc_2 =\t\"d50000000000SS-a\",\n  clcl_2 =\t\"000000000f00RR\",\n  clcle_3 =\t\"0000a9000000RS-a\",\n  clclu_3 =\t\"eb000000008fRSY-a\",\n  clfi_2 =\t\"c20f00000000RIL-a\",\n  clg_2 =\t\"e30000000021RXY-a\",\n  clgf_2 =\t\"e30000000031RXY-a\",\n  clgfi_2 =\t\"c20e00000000RIL-a\",\n  clgfr_2 =\t\"0000b9310000RRE\",\n  clgfrl_2 =\t\"c60e00000000RIL-b\",\n  clghrl_2 =\t\"c60600000000RIL-b\",\n  clgr_2 =\t\"0000b9210000RRE\",\n  clgrl_2 =\t\"c60a00000000RIL-b\",\n  clhf_2 =\t\"e300000000cfRXY-a\",\n  clhhr_2 =\t\"0000b9cf0000RRE\",\n  clhlr_2 =\t\"0000b9df0000RRE\",\n  clhrl_2 =\t\"c60700000000RIL-b\",\n  cli_2 =\t\"000095000000SI\",\n  clih_2 =\t\"cc0f00000000RIL-a\",\n  clm_3 =\t\"0000bd000000RS-b\",\n  clmh_3 =\t\"eb0000000020RSY-b\",\n  clmy_3 =\t\"eb0000000021RSY-b\",\n  clr_2 =\t\"000000001500RR\",\n  clrl_2 =\t\"c60f00000000RIL-b\",\n  clst_2 =\t\"0000b25d0000RRE\",\n  cly_2 =\t\"e30000000055RXY-a\",\n  cmpsc_2 =\t\"0000b2630000RRE\",\n  cpya_2 =\t\"0000b24d0000RRE\",\n  cr_2 =\t\"000000001900RR\",\n  crl_2 =\t\"c60d00000000RIL-b\",\n  cs_3 =\t\"0000ba000000RS-a\",\n  csg_3 =\t\"eb0000000030RSY-a\",\n  csp_2 =\t\"0000b2500000RRE\",\n  cspg_2 =\t\"0000b98a0000RRE\",\n  csy_3 =\t\"eb0000000014RSY-a\",\n  cu41_2 =\t\"0000b9b20000RRE\",\n  cu42_2 =\t\"0000b9b30000RRE\",\n  cudtr_2 =\t\"0000b3e20000RRE\",\n  cuse_2 =\t\"0000b2570000RRE\",\n  cuxtr_2 =\t\"0000b3ea0000RRE\",\n  cvb_2 =\t\"00004f000000RX-a\",\n  cvbg_2 =\t\"e3000000000eRXY-a\",\n  cvby_2 =\t\"e30000000006RXY-a\",\n  cvd_2 =\t\"00004e000000RX-a\",\n  cvdg_2 =\t\"e3000000002eRXY-a\",\n  cvdy_2 =\t\"e30000000026RXY-a\",\n  cxbr_2 =\t\"0000b3490000RRE\",\n  cxfbr_2 =\t\"0000b3960000RRE\",\n  cxfbra_4 =\t\"0000b3960000RRF-e\",\n  cxfr_2 =\t\"0000b3b60000RRE\",\n  cxftr_2 =\t\"0000b9590000RRE\",\n  cxgbr_2 =\t\"0000b3a60000RRE\",\n  cxgbra_4 =\t\"0000b3a60000RRF-e\",\n  cxgr_2 =\t\"0000b3c60000RRE\",\n  cxgtr_2 =\t\"0000b3f90000RRE\",\n  cxr_2 =\t\"0000b3690000RRE\",\n  cxstr_2 =\t\"0000b3fb0000RRE\",\n  cxtr_2 =\t\"0000b3ec0000RRE\",\n  cxutr_2 =\t\"0000b3fa0000RRE\",\n  cy_2 =\t\"e30000000059RXY-a\",\n  d_2 =\t\t\"00005d000000RX-a\",\n  dd_2 =\t\"00006d000000RX-a\",\n  ddb_2 =\t\"ed000000001dRXE\",\n  ddbr_2 =\t\"0000b31d0000RRE\",\n  ddr_2 =\t\"000000002d00RR\",\n  de_2 =\t\"00007d000000RX-a\",\n  deb_2 =\t\"ed000000000dRXE\",\n  debr_2 =\t\"0000b30d0000RRE\",\n  der_2 =\t\"000000003d00RR\",\n  didbr_4 =\t\"0000b35b0000RRF-b\",\n  dl_2 =\t\"e30000000097RXY-a\",\n  dlg_2 =\t\"e30000000087RXY-a\",\n  dlgr_2 =\t\"0000b9870000RRE\",\n  dlr_2 =\t\"0000b9970000RRE\",\n  dr_2 =\t\"000000001d00RR\",\n  dsg_2 =\t\"e3000000000dRXY-a\",\n  dsgf_2 =\t\"e3000000001dRXY-a\",\n  dsgfr_2 =\t\"0000b91d0000RRE\",\n  dsgr_2 =\t\"0000b90d0000RRE\",\n  dxbr_2 =\t\"0000b34d0000RRE\",\n  dxr_2 =\t\"0000b22d0000RRE\",\n  ear_2 =\t\"0000b24f0000RRE\",\n  ecag_3 =\t\"eb000000004cRSY-a\",\n  ed_2 =\t\"de0000000000SS-a\",\n  edmk_2 =\t\"df0000000000SS-a\",\n  eedtr_2 =\t\"0000b3e50000RRE\",\n  eextr_2 =\t\"0000b3ed0000RRE\",\n  efpc_2 =\t\"0000b38c0000RRE\",\n  epair_2 =\t\"0000b99a0000RRE\",\n  epar_2 =\t\"0000b2260000RRE\",\n  epsw_2 =\t\"0000b98d0000RRE\",\n  ereg_2 =\t\"0000b2490000RRE\",\n  eregg_2 =\t\"0000b90e0000RRE\",\n  esair_2 =\t\"0000b99b0000RRE\",\n  esar_2 =\t\"0000b2270000RRE\",\n  esdtr_2 =\t\"0000b3e70000RRE\",\n  esea_2 =\t\"0000b99d0000RRE\",\n  esta_2 =\t\"0000b24a0000RRE\",\n  esxtr_2 =\t\"0000b3ef0000RRE\",\n  ex_2 =\t\"000044000000RX-a\",\n  exrl_2 =\t\"c60000000000RIL-b\",\n  fidr_2 =\t\"0000b37f0000RRE\",\n  fier_2 =\t\"0000b3770000RRE\",\n  fixr_2 =\t\"0000b3670000RRE\",\n  flogr_2 =\t\"0000b9830000RRE\",\n  hdr_2 =\t\"000000002400RR\",\n  her_2 =\t\"000000003400RR\",\n  iac_2 =\t\"0000b2240000RRE\",\n  ic_2 =\t\"000043000000RX-a\",\n  icm_3 =\t\"0000bf000000RS-b\",\n  icmh_3 =\t\"eb0000000080RSY-b\",\n  icmy_3 =\t\"eb0000000081RSY-b\",\n  icy_2 =\t\"e30000000073RXY-a\",\n  iihf_2 =\t\"c00800000000RIL-a\",\n  iihh_2 =\t\"0000a5000000RI-a\",\n  iihl_2 =\t\"0000a5010000RI-a\",\n  iilf_2 =\t\"c00900000000RIL-a\",\n  iilh_2 =\t\"0000a5020000RI-a\",\n  iill_2 =\t\"0000a5030000RI-a\",\n  ipm_2 =\t\"0000b2220000RRE\",\n  iske_2 =\t\"0000b2290000RRE\",\n  ivsk_2 =\t\"0000b2230000RRE\",\n  kdbr_2 =\t\"0000b3180000RRE\",\n  kdtr_2 =\t\"0000b3e00000RRE\",\n  kebr_2 =\t\"0000b3080000RRE\",\n  kimd_2 =\t\"0000b93e0000RRE\",\n  klmd_2 =\t\"0000b93f0000RRE\",\n  km_2 =\t\"0000b92e0000RRE\",\n  kmac_2 =\t\"0000b91e0000RRE\",\n  kmc_2 =\t\"0000b92f0000RRE\",\n  kmf_2 =\t\"0000b92a0000RRE\",\n  kmo_2 =\t\"0000b92b0000RRE\",\n  kxbr_2 =\t\"0000b3480000RRE\",\n  kxtr_2 =\t\"0000b3e80000RRE\",\n  l_2 =\t\t\"000058000000RX-a\",\n  la_2 =\t\"000041000000RX-a\",\n  laa_3 =\t\"eb00000000f8RSY-a\",\n  laag_3 =\t\"eb00000000e8RSY-a\",\n  laal_3 =\t\"eb00000000faRSY-a\",\n  laalg_3 =\t\"eb00000000eaRSY-a\",\n  lae_2 =\t\"000051000000RX-a\",\n  laey_2 =\t\"e30000000075RXY-a\",\n  lam_3 =\t\"00009a000000RS-a\",\n  lamy_3 =\t\"eb000000009aRSY-a\",\n  lan_3 =\t\"eb00000000f4RSY-a\",\n  lang_3 =\t\"eb00000000e4RSY-a\",\n  lao_3 =\t\"eb00000000f6RSY-a\",\n  laog_3 =\t\"eb00000000e6RSY-a\",\n  larl_2 =\t\"c00000000000RIL-b\",\n  lax_3 =\t\"eb00000000f7RSY-a\",\n  laxg_3 =\t\"eb00000000e7RSY-a\",\n  lay_2 =\t\"e30000000071RXY-a\",\n  lb_2 =\t\"e30000000076RXY-a\",\n  lbh_2 =\t\"e300000000c0RXY-a\",\n  lbr_2 =\t\"0000b9260000RRE\",\n  lcdbr_2 =\t\"0000b3130000RRE\",\n  lcdfr_2 =\t\"0000b3730000RRE\",\n  lcdr_2 =\t\"000000002300RR\",\n  lcebr_2 =\t\"0000b3030000RRE\",\n  lcer_2 =\t\"000000003300RR\",\n  lcgfr_2 =\t\"0000b9130000RRE\",\n  lcgr_2 =\t\"0000b9030000RRE\",\n  lcr_2 =\t\"000000001300RR\",\n  lctl_3 =\t\"0000b7000000RS-a\",\n  lctlg_3 =\t\"eb000000002fRSY-a\",\n  lcxbr_2 =\t\"0000b3430000RRE\",\n  lcxr_2 =\t\"0000b3630000RRE\",\n  ld_2 =\t\"000068000000RX-a\",\n  ldebr_2 =\t\"0000b3040000RRE\",\n  lder_2 =\t\"0000b3240000RRE\",\n  ldgr_2 =\t\"0000b3c10000RRE\",\n  ldr_2 =\t\"000000002800RR\",\n  ldxbr_2 =\t\"0000b3450000RRE\",\n  ldxr_2 =\t\"000000002500RR\",\n  ldy_2 =\t\"ed0000000065RXY-a\",\n  le_2 =\t\"000078000000RX-a\",\n  ledbr_2 =\t\"0000b3440000RRE\",\n  ledr_2 =\t\"000000003500RR\",\n  ler_2 =\t\"000000003800RR\",\n  lexbr_2 =\t\"0000b3460000RRE\",\n  lexr_2 =\t\"0000b3660000RRE\",\n  ley_2 =\t\"ed0000000064RXY-a\",\n  lfh_2 =\t\"e300000000caRXY-a\",\n  lg_2 =\t\"e30000000004RXY-a\",\n  lgb_2 =\t\"e30000000077RXY-a\",\n  lgbr_2 =\t\"0000b9060000RRE\",\n  lgdr_2 =\t\"0000b3cd0000RRE\",\n  lgf_2 =\t\"e30000000014RXY-a\",\n  lgfi_2 =\t\"c00100000000RIL-a\",\n  lgfr_2 =\t\"0000b9140000RRE\",\n  lgfrl_2 =\t\"c40c00000000RIL-b\",\n  lgh_2 =\t\"e30000000015RXY-a\",\n  lghi_2 =\t\"0000a7090000RI-a\",\n  lghr_2 =\t\"0000b9070000RRE\",\n  lghrl_2 =\t\"c40400000000RIL-b\",\n  lgr_2 =\t\"0000b9040000RRE\",\n  lgrl_2 =\t\"c40800000000RIL-b\",\n  lh_2 =\t\"000048000000RX-a\",\n  lhh_2 =\t\"e300000000c4RXY-a\",\n  lhi_2 =\t\"0000a7080000RI-a\",\n  lhr_2 =\t\"0000b9270000RRE\",\n  lhrl_2 =\t\"c40500000000RIL-b\",\n  lhy_2 =\t\"e30000000078RXY-a\",\n  llc_2 =\t\"e30000000094RXY-a\",\n  llch_2 =\t\"e300000000c2RXY-a\",\n  llcr_2 =\t\"0000b9940000RRE\",\n  llgc_2 =\t\"e30000000090RXY-a\",\n  llgcr_2 =\t\"0000b9840000RRE\",\n  llgf_2 =\t\"e30000000016RXY-a\",\n  llgfr_2 =\t\"0000b9160000RRE\",\n  llgfrl_2 =\t\"c40e00000000RIL-b\",\n  llgh_2 =\t\"e30000000091RXY-a\",\n  llghr_2 =\t\"0000b9850000RRE\",\n  llghrl_2 =\t\"c40600000000RIL-b\",\n  llgt_2 =\t\"e30000000017RXY-a\",\n  llgtr_2 =\t\"0000b9170000RRE\",\n  llh_2 =\t\"e30000000095RXY-a\",\n  llhh_2 =\t\"e300000000c6RXY-a\",\n  llhr_2 =\t\"0000b9950000RRE\",\n  llhrl_2 =\t\"c40200000000RIL-b\",\n  llihf_2 =\t\"c00e00000000RIL-a\",\n  llihh_2 =\t\"0000a50c0000RI-a\",\n  llihl_2 =\t\"0000a50d0000RI-a\",\n  llilf_2 =\t\"c00f00000000RIL-a\",\n  llilh_2 =\t\"0000a50e0000RI-a\",\n  llill_2 =\t\"0000a50f0000RI-a\",\n  lm_3 =\t\"000098000000RS-a\",\n  lmg_3 =\t\"eb0000000004RSY-a\",\n  lmh_3 =\t\"eb0000000096RSY-a\",\n  lmy_3 =\t\"eb0000000098RSY-a\",\n  lndbr_2 =\t\"0000b3110000RRE\",\n  lndfr_2 =\t\"0000b3710000RRE\",\n  lndr_2 =\t\"000000002100RR\",\n  lnebr_2 =\t\"0000b3010000RRE\",\n  lner_2 =\t\"000000003100RR\",\n  lngfr_2 =\t\"0000b9110000RRE\",\n  lngr_2 =\t\"0000b9010000RRE\",\n  lnr_2 =\t\"000000001100RR\",\n  lnxbr_2 =\t\"0000b3410000RRE\",\n  lnxr_2 =\t\"0000b3610000RRE\",\n  loc_3 =\t\"eb00000000f2RSY-b\",\n  locg_3 =\t\"eb00000000e2RSY-b\",\n  lpdbr_2 =\t\"0000b3100000RRE\",\n  lpdfr_2 =\t\"0000b3700000RRE\",\n  lpdr_2 =\t\"000000002000RR\",\n  lpebr_2 =\t\"0000b3000000RRE\",\n  lper_2 =\t\"000000003000RR\",\n  lpgfr_2 =\t\"0000b9100000RRE\",\n  lpgr_2 =\t\"0000b9000000RRE\",\n  lpq_2 =\t\"e3000000008fRXY-a\",\n  lpr_2 =\t\"000000001000RR\",\n  lpxbr_2 =\t\"0000b3400000RRE\",\n  lpxr_2 =\t\"0000b3600000RRE\",\n  lr_2 =\t\"000000001800RR\",\n  lra_2 =\t\"0000b1000000RX-a\",\n  lrag_2 =\t\"e30000000003RXY-a\",\n  lray_2 =\t\"e30000000013RXY-a\",\n  lrdr_2 =\t\"000000002500RR\",\n  lrer_2 =\t\"000000003500RR\",\n  lrl_2 =\t\"c40d00000000RIL-b\",\n  lrv_2 =\t\"e3000000001eRXY-a\",\n  lrvg_2 =\t\"e3000000000fRXY-a\",\n  lrvgr_2 =\t\"0000b90f0000RRE\",\n  lrvh_2 =\t\"e3000000001fRXY-a\",\n  lrvr_2 =\t\"0000b91f0000RRE\",\n  lt_2 =\t\"e30000000012RXY-a\",\n  ltdbr_2 =\t\"0000b3120000RRE\",\n  ltdr_2 =\t\"000000002200RR\",\n  ltdtr_2 =\t\"0000b3d60000RRE\",\n  ltebr_2 =\t\"0000b3020000RRE\",\n  lter_2 =\t\"000000003200RR\",\n  ltg_2 =\t\"e30000000002RXY-a\",\n  ltgf_2 =\t\"e30000000032RXY-a\",\n  ltgfr_2 =\t\"0000b9120000RRE\",\n  ltgr_2 =\t\"0000b9020000RRE\",\n  ltr_2 =\t\"000000001200RR\",\n  ltxbr_2 =\t\"0000b3420000RRE\",\n  ltxr_2 =\t\"0000b3620000RRE\",\n  ltxtr_2 =\t\"0000b3de0000RRE\",\n  lura_2 =\t\"0000b24b0000RRE\",\n  lurag_2 =\t\"0000b9050000RRE\",\n  lxdbr_2 =\t\"0000b3050000RRE\",\n  lxdr_2 =\t\"0000b3250000RRE\",\n  lxebr_2 =\t\"0000b3060000RRE\",\n  lxer_2 =\t\"0000b3260000RRE\",\n  lxr_2 =\t\"0000b3650000RRE\",\n  ly_2 =\t\"e30000000058RXY-a\",\n  lzdr_2 =\t\"0000b3750000RRE\",\n  lzer_2 =\t\"0000b3740000RRE\",\n  lzxr_2 =\t\"0000b3760000RRE\",\n  m_2 =\t\t\"00005c000000RX-a\",\n  madb_3 =\t\"ed000000001eRXF\",\n  maeb_3 =\t\"ed000000000eRXF\",\n  maebr_3 =\t\"0000b30e0000RRD\",\n  maer_3 =\t\"0000b32e0000RRD\",\n  md_2 =\t\"00006c000000RX-a\",\n  mdb_2 =\t\"ed000000001cRXE\",\n  mdbr_2 =\t\"0000b31c0000RRE\",\n  mde_2 =\t\"00007c000000RX-a\",\n  mdeb_2 =\t\"ed000000000cRXE\",\n  mdebr_2 =\t\"0000b30c0000RRE\",\n  mder_2 =\t\"000000003c00RR\",\n  mdr_2 =\t\"000000002c00RR\",\n  me_2 =\t\"00007c000000RX-a\",\n  meeb_2 =\t\"ed0000000017RXE\",\n  meebr_2 =\t\"0000b3170000RRE\",\n  meer_2 =\t\"0000b3370000RRE\",\n  mer_2 =\t\"000000003c00RR\",\n  mfy_2 =\t\"e3000000005cRXY-a\",\n  mghi_2 =\t\"0000a70d0000RI-a\",\n  mh_2 =\t\"00004c000000RX-a\",\n  mhi_2 =\t\"0000a70c0000RI-a\",\n  mhy_2 =\t\"e3000000007cRXY-a\",\n  ml_2 =\t\"e30000000096RXY-a\",\n  mlg_2 =\t\"e30000000086RXY-a\",\n  mlgr_2 =\t\"0000b9860000RRE\",\n  mlr_2 =\t\"0000b9960000RRE\",\n  mr_2 =\t\"000000001c00RR\",\n  ms_2 =\t\"000071000000RX-a\",\n  msfi_2 =\t\"c20100000000RIL-a\",\n  msg_2 =\t\"e3000000000cRXY-a\",\n  msgf_2 =\t\"e3000000001cRXY-a\",\n  msgfi_2 =\t\"c20000000000RIL-a\",\n  msgfr_2 =\t\"0000b91c0000RRE\",\n  msgr_2 =\t\"0000b90c0000RRE\",\n  msr_2 =\t\"0000b2520000RRE\",\n  msta_2 =\t\"0000b2470000RRE\",\n  msy_2 =\t\"e30000000051RXY-a\",\n  mvc_2 =\t\"d20000000000SS-a\",\n  mvcin_2 =\t\"e80000000000SS-a\",\n  mvcl_2 =\t\"000000000e00RR\",\n  mvcle_3 =\t\"0000a8000000RS-a\",\n  mvclu_3 =\t\"eb000000008eRSY-a\",\n  mvghi_2 =\t\"e54800000000SIL\",\n  mvhhi_2 =\t\"e54400000000SIL\",\n  mvhi_2 =\t\"e54c00000000SIL\",\n  mvi_2 =\t\"000092000000SI\",\n  mvn_2 =\t\"d10000000000SS-a\",\n  mvpg_2 =\t\"0000b2540000RRE\",\n  mvst_2 =\t\"0000b2550000RRE\",\n  mvz_2 =\t\"d30000000000SS-a\",\n  mxbr_2 =\t\"0000b34c0000RRE\",\n  mxd_2 =\t\"000067000000RX-a\",\n  mxdb_2 =\t\"ed0000000007RXE\",\n  mxdbr_2 =\t\"0000b3070000RRE\",\n  mxdr_2 =\t\"000000002700RR\",\n  mxr_2 =\t\"000000002600RR\",\n  n_2 =\t\t\"000054000000RX-a\",\n  nc_2 =\t\"d40000000000SS-a\",\n  ng_2 =\t\"e30000000080RXY-a\",\n  ngr_2 =\t\"0000b9800000RRE\",\n  ni_2 =\t\"000094000000SI\",\n  nihf_2 =\t\"c00a00000000RIL-a\",\n  nihh_2 =\t\"0000a5040000RI-a\",\n  nihl_2 =\t\"0000a5050000RI-a\",\n  nilf_2 =\t\"c00b00000000RIL-a\",\n  nilh_2 =\t\"0000a5060000RI-a\",\n  nill_2 =\t\"0000a5070000RI-a\",\n  nr_2 =\t\"000000001400RR\",\n  ny_2 =\t\"e30000000054RXY-a\",\n  o_2 =\t\t\"000056000000RX-a\",\n  oc_2 =\t\"d60000000000SS-a\",\n  og_2 =\t\"e30000000081RXY-a\",\n  ogr_2 =\t\"0000b9810000RRE\",\n  oi_2 =\t\"000096000000SI\",\n  oihf_2 =\t\"c00c00000000RIL-a\",\n  oihh_2 =\t\"0000a5080000RI-a\",\n  oihl_2 =\t\"0000a5090000RI-a\",\n  oilf_2 =\t\"c00d00000000RIL-a\",\n  oilh_2 =\t\"0000a50a0000RI-a\",\n  oill_2 =\t\"0000a50b0000RI-a\",\n  or_2 =\t\"000000001600RR\",\n  oy_2 =\t\"e30000000056RXY-a\",\n  palb_2 =\t\"0000b2480000RRE\",\n  pcc_2 =\t\"0000b92c0000RRE\",\n  pckmo_2 =\t\"0000b9280000RRE\",\n  pfd_2 =\t\"e30000000036m\",\n  pfdrl_2 =\t\"c60200000000RIL-c\",\n  pfmf_2 =\t\"0000b9af0000RRE\",\n  pgin_2 =\t\"0000b22e0000RRE\",\n  pgout_2 =\t\"0000b22f0000RRE\",\n  popcnt_2 =\t\"0000b9e10000RRE\",\n  pt_2 =\t\"0000b2280000RRE\",\n  ptf_2 =\t\"0000b9a20000RRE\",\n  pti_2 =\t\"0000b99e0000RRE\",\n  rll_3 =\t\"eb000000001dRSY-a\",\n  rllg_3 =\t\"eb000000001cRSY-a\",\n  rrbe_2 =\t\"0000b22a0000RRE\",\n  rrbm_2 =\t\"0000b9ae0000RRE\",\n  s_2 =\t\t\"00005b000000RX-a\",\n  sar_2 =\t\"0000b24e0000RRE\",\n  sd_2 =\t\"00006b000000RX-a\",\n  sdb_2 =\t\"ed000000001bRXE\",\n  sdbr_2 =\t\"0000b31b0000RRE\",\n  sdr_2 =\t\"000000002b00RR\",\n  se_2 =\t\"00007b000000RX-a\",\n  seb_2 =\t\"ed000000000bRXE\",\n  sebr_2 =\t\"0000b30b0000RRE\",\n  ser_2 =\t\"000000003b00RR\",\n  sfasr_2 =\t\"0000b3850000RRE\",\n  sfpc_2 =\t\"0000b3840000RRE\",\n  sg_2 =\t\"e30000000009RXY-a\",\n  sgf_2 =\t\"e30000000019RXY-a\",\n  sgfr_2 =\t\"0000b9190000RRE\",\n  sgr_2 =\t\"0000b9090000RRE\",\n  sh_2 =\t\"00004b000000RX-a\",\n  shy_2 =\t\"e3000000007bRXY-a\",\n  sl_2 =\t\"00005f000000RX-a\",\n  sla_2 =\t\"00008b000000RS-a\",\n  slag_3 =\t\"eb000000000bRSY-a\",\n  slak_3 =\t\"eb00000000ddRSY-a\",\n  slb_2 =\t\"e30000000099RXY-a\",\n  slbg_2 =\t\"e30000000089RXY-a\",\n  slbgr_2 =\t\"0000b9890000RRE\",\n  slbr_2 =\t\"0000b9990000RRE\",\n  slda_2 =\t\"00008f000000RS-a\",\n  sldl_2 =\t\"00008d000000RS-a\",\n  slfi_2 =\t\"c20500000000RIL-a\",\n  slg_2 =\t\"e3000000000bRXY-a\",\n  slgf_2 =\t\"e3000000001bRXY-a\",\n  slgfi_2 =\t\"c20400000000RIL-a\",\n  slgfr_2 =\t\"0000b91b0000RRE\",\n  slgr_2 =\t\"0000b90b0000RRE\",\n  sll_2 =\t\"000089000000RS-a\",\n  sllg_3 =\t\"eb000000000dRSY-a\",\n  sllk_3 =\t\"eb00000000dfRSY-a\",\n  slr_2 =\t\"000000001f00RR\",\n  sly_2 =\t\"e3000000005fRXY-a\",\n  spm_2 =\t\"000000000400RR\",\n  sqdb_2 =\t\"ed0000000015RXE\",\n  sqdbr_2 =\t\"0000b3150000RRE\",\n  sqdr_2 =\t\"0000b2440000RRE\",\n  sqeb_2 =\t\"ed0000000014RXE\",\n  sqebr_2 =\t\"0000b3140000RRE\",\n  sqer_2 =\t\"0000b2450000RRE\",\n  sqxbr_2 =\t\"0000b3160000RRE\",\n  sqxr_2 =\t\"0000b3360000RRE\",\n  sr_2 =\t\"000000001b00RR\",\n  sra_2 =\t\"00008a000000RS-a\",\n  srag_3 =\t\"eb000000000aRSY-a\",\n  srak_3 =\t\"eb00000000dcRSY-a\",\n  srda_2 =\t\"00008e000000RS-a\",\n  srdl_2 =\t\"00008c000000RS-a\",\n  srl_2 =\t\"000088000000RS-a\",\n  srlg_3 =\t\"eb000000000cRSY-a\",\n  srlk_3 =\t\"eb00000000deRSY-a\",\n  srst_2 =\t\"0000b25e0000RRE\",\n  srstu_2 =\t\"0000b9be0000RRE\",\n  ssair_2 =\t\"0000b99f0000RRE\",\n  ssar_2 =\t\"0000b2250000RRE\",\n  st_2 =\t\"000050000000RX-a\",\n  stam_3 =\t\"00009b000000RS-a\",\n  stamy_3 =\t\"eb000000009bRSY-a\",\n  stc_2 =\t\"000042000000RX-a\",\n  stch_2 =\t\"e300000000c3RXY-a\",\n  stcm_3 =\t\"0000be000000RS-b\",\n  stcmh_3 =\t\"eb000000002cRSY-b\",\n  stcmy_3 =\t\"eb000000002dRSY-b\",\n  stctg_3 =\t\"eb0000000025RSY-a\",\n  stctl_3 =\t\"0000b6000000RS-a\",\n  stcy_2 =\t\"e30000000072RXY-a\",\n  std_2 =\t\"000060000000RX-a\",\n  stdy_2 =\t\"ed0000000067RXY-a\",\n  ste_2 =\t\"000070000000RX-a\",\n  stey_2 =\t\"ed0000000066RXY-a\",\n  stfh_2 =\t\"e300000000cbRXY-a\",\n  stfl_1 =\t\"0000b2b10000S\",\n  stg_2 =\t\"e30000000024RXY-a\",\n  stgrl_2 =\t\"c40b00000000RIL-b\",\n  sth_2 =\t\"000040000000RX-a\",\n  sthh_2 =\t\"e300000000c7RXY-a\",\n  sthrl_2 =\t\"c40700000000RIL-b\",\n  sthy_2 =\t\"e30000000070RXY-a\",\n  stm_3 =\t\"000090000000RS-a\",\n  stmg_3 =\t\"eb0000000024RSY-a\",\n  stmh_3 =\t\"eb0000000026RSY-a\",\n  stmy_3 =\t\"eb0000000090RSY-a\",\n  stoc_3 =\t\"eb00000000f3RSY-b\",\n  stocg_3 =\t\"eb00000000e3RSY-b\",\n  stpq_2 =\t\"e3000000008eRXY-a\",\n  strl_2 =\t\"c40f00000000RIL-b\",\n  strv_2 =\t\"e3000000003eRXY-a\",\n  strvg_2 =\t\"e3000000002fRXY-a\",\n  strvh_2 =\t\"e3000000003fRXY-a\",\n  stura_2 =\t\"0000b2460000RRE\",\n  sturg_2 =\t\"0000b9250000RRE\",\n  sty_2 =\t\"e30000000050RXY-a\",\n  su_2 =\t\"00007f000000RX-a\",\n  sur_2 =\t\"000000003f00RR\",\n  svc_1 =\t\"000000000a00I\",\n  sw_2 =\t\"00006f000000RX-a\",\n  swr_2 =\t\"000000002f00RR\",\n  sxbr_2 =\t\"0000b34b0000RRE\",\n  sxr_2 =\t\"000000003700RR\",\n  sy_2 =\t\"e3000000005bRXY-a\",\n  tar_2 =\t\"0000b24c0000RRE\",\n  tb_2 =\t\"0000b22c0000RRE\",\n  thder_2 =\t\"0000b3580000RRE\",\n  thdr_2 =\t\"0000b3590000RRE\",\n  tm_2 =\t\"000091000000SI\",\n  tmhh_2 =\t\"0000a7020000RI-a\",\n  tmhl_2 =\t\"0000a7030000RI-a\",\n  tmlh_2 =\t\"0000a7000000RI-a\",\n  tmll_2 =\t\"0000a7010000RI-a\",\n  tmy_2 =\t\"eb0000000051SIY\",\n  tr_2 =\t\"dc0000000000SS-a\",\n  trace_3 =\t\"000099000000RS-a\",\n  tracg_3 =\t\"eb000000000fRSY-a\",\n  tre_2 =\t\"0000b2a50000RRE\",\n  trt_2 =\t\"dd0000000000SS-a\",\n  trtr_2 =\t\"d00000000000SS-a\",\n  unpka_2 =\t\"ea0000000000SS-a\",\n  unpku_2 =\t\"e20000000000SS-a\",\n  x_2 =\t\t\"000057000000RX-a\",\n  xc_2 =\t\"d70000000000SS-a\",\n  xg_2 =\t\"e30000000082RXY-a\",\n  xgr_2 =\t\"0000b9820000RRE\",\n  xi_2 =\t\"000097000000SI\",\n  xihf_2 =\t\"c00600000000RIL-a\",\n  xilf_2 =\t\"c00700000000RIL-a\",\n  xr_2 =\t\"000000001700RR\",\n  xy_2 =\t\"e30000000057RXY-a\",\n}\nfor cond, c in pairs(map_cond) do\n  -- Extended mnemonics for branches.\n  -- TODO: replace 'B' with correct encoding.\n  -- brc\n  map_op[\"j\"..cond..\"_1\"] = \"0000\"..tohex(0xa7040000+shl(c, 20))..\"RI-c\"\n  -- brcl\n  map_op[\"jg\"..cond..\"_1\"] = tohex(0xc0040000+shl(c, 20))..\"0000\"..\"RIL-c\"\n  -- bc\n  map_op[\"b\"..cond..\"_1\"] = \"0000\"..tohex(0x47000000+shl(c, 20))..\"RX-b\"\n  -- bcr\n  map_op[\"b\"..cond..\"r_1\"] = \"0000\"..tohex(0x0700+shl(c, 4))..\"RR\"\nend\n------------------------------------------------------------------------------\n-- Handle opcodes defined with template strings.\nlocal function parse_template(params, template, nparams, pos)\n  -- Read the template in 16-bit chunks.\n  -- Leading halfword zeroes should not be written out.\n  local op0 = tonumber(sub(template, 1, 4), 16)\n  local op1 = tonumber(sub(template, 5, 8), 16)\n  local op2 = tonumber(sub(template, 9, 12), 16)\n\n  -- Process each character.\n  local p = sub(template, 13)\n  if p == \"I\" then\n    local imm_val, a = parse_imm8(params[1])\n    op2 = op2 + imm_val\n    wputhw(op2)\n    if a then a() end\n  elseif p == \"RI-a\" then\n    op1 = op1 + shl(parse_reg(params[1]), 4)\n    wputhw(op1)\n    parse_imm16(params[2])\n  elseif p == \"RI-b\" then\n    op1 = op1 + shl(parse_reg(params[1]), 4)\n    wputhw(op1)\n    local mode, n, s = parse_label(params[2])\n    waction(\"REL_\"..mode, n, s)\n  elseif p == \"RI-c\" then\n    if #params > 1 then\n      op1 = op1 + shl(parse_num(params[1]), 4)\n    end\n    wputhw(op1)\n    local mode, n, s = parse_label(params[#params])\n    waction(\"REL_\"..mode, n, s)\n  elseif p == \"RIE-e\" then\n    op0 = op0 + shl(parse_reg(params[1]), 4) + parse_reg(params[2])\n    wputhw1(op0)\n    local mode, n, s = parse_label(params[3])\n    waction(\"REL_\"..mode, n, s)\n    wputhw(op2)\n  elseif p == \"RIL-a\" then\n    op0 = op0 + shl(parse_reg(params[1]), 4)\n    wputhw(op0);\n    parse_imm32(params[2])\n  elseif p == \"RIL-b\" then\n    op0 = op0 + shl(parse_reg(params[1]), 4)\n    wputhw(op0)\n    local mode, n, s = parse_label(params[2])\n    waction(\"REL_\"..mode, n, s)\n  elseif p == \"RIL-c\" then\n    if #params > 1 then\n      op0 = op0 + shl(parse_num(params[1]), 4)\n    end\n    wputhw(op0)\n    local mode, n, s = parse_label(params[#params])\n    waction(\"REL_\"..mode, n, s)\n  elseif p == \"RR\" then\n    if #params > 1 then\n      op2 = op2 + shl(parse_reg(params[1]), 4)\n    end\n    op2 = op2 + parse_reg(params[#params])\n    wputhw(op2)\n  elseif p == \"RRD\" then\n    wputhw(op1)\n    op2 = op2 + shl(parse_reg(params[1]), 12) + shl(parse_reg(params[2]), 4) + parse_reg(params[3])\n    wputhw(op2)\n  elseif p == \"RRE\" then\n    op2 = op2 + shl(parse_reg(params[1]), 4) + parse_reg(params[2])\n    wputhw(op1); wputhw(op2)\n  elseif p == \"RRF-b\" then\n    wputhw(op1)\n    op2 = op2 + shl(parse_reg(params[1]), 4) + shl(parse_reg(params[2]), 12) + parse_reg(params[3]) + shl(parse_mask(params[4]), 8)\n    wputhw(op2)\n  elseif p == \"RRF-e\" then\n    wputhw(op1)\n    op2 = op2 + shl(parse_reg(params[1]), 4) + shl(parse_mask(params[2]), 12) + parse_reg(params[3])\n    if params[4] then\n      op2 = op2 + shl(parse_mask2(params[4]), 8)\n    end\n    wputhw(op2)\n  elseif p == \"RS-a\" then\n    if (params[3]) then\n      local d, b, a = parse_mem_b(params[3])\n      op1 = op1 + shl(parse_reg(params[1]), 4) + parse_reg(params[2])\n      op2 = op2 + shl(b, 12) + d\n    else\n      local d, b, a = parse_mem_b(params[2])\n      op1 = op1 + shl(parse_reg(params[1]), 4)\n      op2 = op2 + shl(b, 12) + d\n    end\n    wputhw(op1); wputhw(op2)\n    if a then a() end \n  elseif p == \"RS-b\" then\n    local m = parse_mask(params[2])\n    local d, b, a = parse_mem_b(params[3])\n    op1 = op1 + shl(parse_reg(params[1]), 4) + m\n    op2 = op2 + shl(b, 12) + d\n    wputhw(op1); wputhw(op2)\n    if a then a() end\n  elseif p == \"RSI\" then\n    op1 = op1 + shl(parse_reg(params[1]), 4) + parse_reg(params[2])\n    wputhw(op1)\n    local mode, n, s = parse_label(params[3])\n    waction(\"REL_\"..mode, n, s)\n  elseif p == \"RSY-a\" then\n    local d, b, a = parse_mem_by(params[3])\n    op0 = op0 + shl(parse_reg(params[1]), 4) + parse_reg(params[2])\n    op1 = op1 + shl(b, 12) + band(d, 0xfff)\n    op2 = op2 + band(shr(d, 4), 0xff00)\n    wputhw(op0); wputhw(op1); wputhw(op2)\n    if a then a() end -- a() emits action.\n  elseif p == \"RX-a\" then\n    local d, x, b, a = parse_mem_bx(params[2])\n    op1 = op1 + shl(parse_reg(params[1]), 4) + x\n    op2 = op2 + shl(b, 12) + d\n    wputhw(op1); wputhw(op2)\n    if a then a() end\n  elseif p == \"RX-b\" then\n    local d, x, b, a = parse_mem_bx(params[#params])\n    if #params > 1 then\n      op1 = op1 + shl(parse_num(params[1]), 4)\n    end\n    op1 = op1 + x\n    op2 = op2 + shl(b, 12) + d\n    wputhw(op1); wputhw(op2)\n    if a then a() end\n  elseif p == \"RXE\" then\n    local d, x, b, a = parse_mem_bx(params[2])\n    op0 = op0 + shl(parse_reg(params[1]), 4) + x\n    op1 = op1 + shl(b, 12) + d\n    wputhw(op0); wputhw(op1)\n    if a then a() end\n    wputhw(op2);\n  elseif p == \"RXF\" then\n    local d, x, b, a = parse_mem_bx(params[3])\n    op0 = op0 + shl(parse_reg(params[2]), 4) + x\n    op1 = op1 + shl(b, 12) + d\n    wputhw(op0); wputhw(op1)\n    if a then a() end\n    op2 = op2 + shl(parse_reg(params[1]), 12)\n    wputhw(op2)\n  elseif p == \"RXY-a\" then\n    local d, x, b, a = parse_mem_bxy(params[2])\n    op0 = op0 + shl(parse_reg(params[1]), 4) + x\n    op1 = op1 + shl(b, 12) + band(d, 0xfff)\n    op2 = op2 + band(shr(d, 4), 0xff00)\n    wputhw(op0); wputhw(op1); wputhw(op2)\n    if a then a() end\n  elseif p == \"S\" then\n    wputhw(op1);\n    local d, b, a = parse_mem_b(params[1])\n    op2 = op2 + shl(b, 12) + d\n    wputhw(op2)\n    if a then a() end\n  elseif p == \"SI\" then\n    local imm_val, a = parse_imm8(params[2])\n    op1 = op1 + imm_val\n    wputhw(op1)\n    if a then a() end\n    local d, b, a = parse_mem_b(params[1])\n    op2 = op2 + shl(b, 12) + d\n    wputhw(op2)\n    if a then a() end\n  elseif p == \"SIL\" then\n    wputhw(op0)\n    local d, b, a = parse_mem_b(params[1])\n    op1 = op1 + shl(b, 12) + d\n    wputhw(op1)\n    if a then a() end\n    parse_imm16(params[2])\n  elseif p == \"SIY\" then\n    local imm8, iact = parse_imm8(params[2])\n    op0 = op0 + shl(imm8, 8)\n    wputhw(op0)\n    if iact then iact() end\n    local d, b, a = parse_mem_by(params[1])\n    op1 = op1 + shl(b, 12) + band(d, 0xfff)\n    op2 = op2 + band(shr(d, 4), 0xff00)\n    wputhw(op1); wputhw(op2)\n    if a then a() end \n  elseif p == \"SS-a\" then\n    local d1, l1, b1, d1a, l1a = parse_mem_lb(params[1])\n    local d2, b2, d2a = parse_mem_b(params[2])\n    op0 = op0 + l1\n    op1 = op1 + shl(b1, 12) + d1\n    op2 = op2 + shl(b2, 12) + d2\n    wputhw(op0)\n    if l1a then l1a() end\n    wputhw(op1)\n    if d1a then d1a() end\n    wputhw(op2)\n    if d2a then d2a() end\n  elseif p == \"SS-b\" then\n    local high_l = true\n    local d1, l1, b1, d1a, l1a = parse_mem_l2b(params[1], high_l)\n    high_l = false\n    local d2, l2, b2, d2a, l2a = parse_mem_l2b(params[2], high_l)\n    op0 = op0 + shl(l1, 4) + l2\n    op1 = op1 + shl(b1, 12) + d1\n    op2 = op2 + shl(b2, 12) + d2\n    wputhw(op0)\n    if l1a then l1a() end\n    if l2a then l2a() end\n    wputhw(op1)\n    if d1a then d1a() end\n    wputhw(op2)\n    if d2a then d2a() end\n  else\n    werror(\"unrecognized encoding\")\n  end\nend\n\nfunction op_template(params, template, nparams)\n  if not params then return template:gsub(\"%x%x%x%x%x%x%x%x%x%x%x%x\", \"\") end\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 5 positions.\n  if secpos+5 > maxsecpos then wflush() end\n  local lpos, apos, spos = #actlist, #actargs, secpos\n  local ok, err\n  for t in gmatch(template, \"[^|]+\") do\n    ok, err = pcall(parse_template, params, t, nparams)\n    if ok then return end\n    secpos = spos\n    actlist[lpos+1] = nil\n    actlist[lpos+2] = nil\n    actlist[lpos+3] = nil\n    actargs[apos+1] = nil\n    actargs[apos+2] = nil\n    actargs[apos+3] = nil\n  end\n  error(err, 0)\nend\nmap_op[\".template__\"] = op_template\n------------------------------------------------------------------------------\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n------------------------------------------------------------------------------\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_1\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local mode, n, s = parse_label(params[1], true)\n  if mode == \"EXT\" then werror(\"bad label definition\") end\n  waction(\"LABEL_\"..mode, n, s, 1)\nend\n------------------------------------------------------------------------------\n-- Pseudo-opcodes for data storage.\nmap_op[\".long_*\"] = function(params)\n  if not params then return \"imm...\" end\n  for _, p in ipairs(params) do\n    local n = tonumber(p)\n    if not n then werror(\"bad immediate `\"..p..\"'\") end\n    if n < 0 then n = n + 2^32 end\n    wputw(n)\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1])\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1, 8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", align-1, nil, 1) -- Action halfword is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n------------------------------------------------------------------------------\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _, name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n------------------------------------------------------------------------------\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\", num)\n  wflush(true) -- SECTION is a terminal action.\nend\n------------------------------------------------------------------------------\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpactions(out)\nend\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n------------------------------------------------------------------------------\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\nreturn _M\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_x64.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM x64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n-- This module just sets 64 bit mode for the combined x86/x64 module.\n-- All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nx64 = true -- Using a global is an ugly, but effective solution.\nreturn require(\"dasm_x86\")\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_x86.h",
    "content": "/*\n** DynASM x86 encoding engine.\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n** Released under the MIT license. See dynasm.lua for full copyright notice.\n*/\n\n#include <stddef.h>\n#include <stdarg.h>\n#include <string.h>\n#include <stdlib.h>\n\n#define DASM_ARCH\t\t\"x86\"\n\n#ifndef DASM_EXTERN\n#define DASM_EXTERN(a,b,c,d)\t0\n#endif\n\n/* Action definitions. DASM_STOP must be 255. */\nenum {\n  DASM_DISP = 233,\n  DASM_IMM_S, DASM_IMM_B, DASM_IMM_W, DASM_IMM_D, DASM_IMM_WB, DASM_IMM_DB,\n  DASM_VREG, DASM_SPACE, DASM_SETLABEL, DASM_REL_A, DASM_REL_LG, DASM_REL_PC,\n  DASM_IMM_LG, DASM_IMM_PC, DASM_LABEL_LG, DASM_LABEL_PC, DASM_ALIGN,\n  DASM_EXTERN, DASM_ESC, DASM_MARK, DASM_SECTION, DASM_STOP\n};\n\n/* Maximum number of section buffer positions for a single dasm_put() call. */\n#define DASM_MAXSECPOS\t\t25\n\n/* DynASM encoder status codes. Action list offset or number are or'ed in. */\n#define DASM_S_OK\t\t0x00000000\n#define DASM_S_NOMEM\t\t0x01000000\n#define DASM_S_PHASE\t\t0x02000000\n#define DASM_S_MATCH_SEC\t0x03000000\n#define DASM_S_RANGE_I\t\t0x11000000\n#define DASM_S_RANGE_SEC\t0x12000000\n#define DASM_S_RANGE_LG\t\t0x13000000\n#define DASM_S_RANGE_PC\t\t0x14000000\n#define DASM_S_RANGE_VREG\t0x15000000\n#define DASM_S_UNDEF_L\t\t0x21000000\n#define DASM_S_UNDEF_PC\t\t0x22000000\n\n/* Macros to convert positions (8 bit section + 24 bit index). */\n#define DASM_POS2IDX(pos)\t((pos)&0x00ffffff)\n#define DASM_POS2BIAS(pos)\t((pos)&0xff000000)\n#define DASM_SEC2POS(sec)\t((sec)<<24)\n#define DASM_POS2SEC(pos)\t((pos)>>24)\n#define DASM_POS2PTR(D, pos)\t(D->sections[DASM_POS2SEC(pos)].rbuf + (pos))\n\n/* Action list type. */\ntypedef const unsigned char *dasm_ActList;\n\n/* Per-section structure. */\ntypedef struct dasm_Section {\n  int *rbuf;\t\t/* Biased buffer pointer (negative section bias). */\n  int *buf;\t\t/* True buffer pointer. */\n  size_t bsize;\t\t/* Buffer size in bytes. */\n  int pos;\t\t/* Biased buffer position. */\n  int epos;\t\t/* End of biased buffer position - max single put. */\n  int ofs;\t\t/* Byte offset into section. */\n} dasm_Section;\n\n/* Core structure holding the DynASM encoding state. */\nstruct dasm_State {\n  size_t psize;\t\t\t/* Allocated size of this structure. */\n  dasm_ActList actionlist;\t/* Current actionlist pointer. */\n  int *lglabels;\t\t/* Local/global chain/pos ptrs. */\n  size_t lgsize;\n  int *pclabels;\t\t/* PC label chains/pos ptrs. */\n  size_t pcsize;\n  void **globals;\t\t/* Array of globals (bias -10). */\n  dasm_Section *section;\t/* Pointer to active section. */\n  size_t codesize;\t\t/* Total size of all code sections. */\n  int maxsection;\t\t/* 0 <= sectionidx < maxsection. */\n  int status;\t\t\t/* Status code. */\n  dasm_Section sections[1];\t/* All sections. Alloc-extended. */\n};\n\n/* The size of the core structure depends on the max. number of sections. */\n#define DASM_PSZ(ms)\t(sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))\n\n\n/* Initialize DynASM state. */\nvoid dasm_init(Dst_DECL, int maxsection)\n{\n  dasm_State *D;\n  size_t psz = 0;\n  int i;\n  Dst_REF = NULL;\n  DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));\n  D = Dst_REF;\n  D->psize = psz;\n  D->lglabels = NULL;\n  D->lgsize = 0;\n  D->pclabels = NULL;\n  D->pcsize = 0;\n  D->globals = NULL;\n  D->maxsection = maxsection;\n  for (i = 0; i < maxsection; i++) {\n    D->sections[i].buf = NULL;  /* Need this for pass3. */\n    D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);\n    D->sections[i].bsize = 0;\n    D->sections[i].epos = 0;  /* Wrong, but is recalculated after resize. */\n  }\n}\n\n/* Free DynASM state. */\nvoid dasm_free(Dst_DECL)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  for (i = 0; i < D->maxsection; i++)\n    if (D->sections[i].buf)\n      DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);\n  if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);\n  if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);\n  DASM_M_FREE(Dst, D, D->psize);\n}\n\n/* Setup global label array. Must be called before dasm_setup(). */\nvoid dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)\n{\n  dasm_State *D = Dst_REF;\n  D->globals = gl - 10;  /* Negative bias to compensate for locals. */\n  DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));\n}\n\n/* Grow PC label array. Can be called after dasm_setup(), too. */\nvoid dasm_growpc(Dst_DECL, unsigned int maxpc)\n{\n  dasm_State *D = Dst_REF;\n  size_t osz = D->pcsize;\n  DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));\n  memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);\n}\n\n/* Setup encoder. */\nvoid dasm_setup(Dst_DECL, const void *actionlist)\n{\n  dasm_State *D = Dst_REF;\n  int i;\n  D->actionlist = (dasm_ActList)actionlist;\n  D->status = DASM_S_OK;\n  D->section = &D->sections[0];\n  memset((void *)D->lglabels, 0, D->lgsize);\n  if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);\n  for (i = 0; i < D->maxsection; i++) {\n    D->sections[i].pos = DASM_SEC2POS(i);\n    D->sections[i].ofs = 0;\n  }\n}\n\n\n#ifdef DASM_CHECKS\n#define CK(x, st) \\\n  do { if (!(x)) { \\\n    D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)\n#define CKPL(kind, st) \\\n  do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \\\n    D->status=DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)\n#else\n#define CK(x, st)\t((void)0)\n#define CKPL(kind, st)\t((void)0)\n#endif\n\n/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */\nvoid dasm_put(Dst_DECL, int start, ...)\n{\n  va_list ap;\n  dasm_State *D = Dst_REF;\n  dasm_ActList p = D->actionlist + start;\n  dasm_Section *sec = D->section;\n  int pos = sec->pos, ofs = sec->ofs, mrm = -1;\n  int *b;\n\n  if (pos >= sec->epos) {\n    DASM_M_GROW(Dst, int, sec->buf, sec->bsize,\n      sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));\n    sec->rbuf = sec->buf - DASM_POS2BIAS(pos);\n    sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);\n  }\n\n  b = sec->rbuf;\n  b[pos++] = start;\n\n  va_start(ap, start);\n  while (1) {\n    int action = *p++;\n    if (action < DASM_DISP) {\n      ofs++;\n    } else if (action <= DASM_REL_A) {\n      int n = va_arg(ap, int);\n      b[pos++] = n;\n      switch (action) {\n      case DASM_DISP:\n\tif (n == 0) { if (mrm < 0) mrm = p[-2]; if ((mrm&7) != 5) break; }\n\t/* fallthrough */\n      case DASM_IMM_DB: if (((n+128)&-256) == 0) goto ob; /* fallthrough */\n      case DASM_REL_A: /* Assumes ptrdiff_t is int. !x64 */\n      case DASM_IMM_D: ofs += 4; break;\n      case DASM_IMM_S: CK(((n+128)&-256) == 0, RANGE_I); goto ob;\n      case DASM_IMM_B: CK((n&-256) == 0, RANGE_I); ob: ofs++; break;\n      case DASM_IMM_WB: if (((n+128)&-256) == 0) goto ob; /* fallthrough */\n      case DASM_IMM_W: CK((n&-65536) == 0, RANGE_I); ofs += 2; break;\n      case DASM_SPACE: p++; ofs += n; break;\n      case DASM_SETLABEL: b[pos-2] = -0x40000000; break;  /* Neg. label ofs. */\n      case DASM_VREG: CK((n&-16) == 0 && (n != 4 || (*p>>5) != 2), RANGE_VREG);\n\tif (*p < 0x40 && p[1] == DASM_DISP) mrm = n;\n\tif (*p < 0x20 && (n&7) == 4) ofs++;\n\tswitch ((*p++ >> 3) & 3) {\n\tcase 3: n |= b[pos-3]; /* fallthrough */\n\tcase 2: n |= b[pos-2]; /* fallthrough */\n\tcase 1: if (n <= 7) { b[pos-1] |= 0x10; ofs--; }\n\t}\n\tcontinue;\n      }\n      mrm = -1;\n    } else {\n      int *pl, n;\n      switch (action) {\n      case DASM_REL_LG:\n      case DASM_IMM_LG:\n\tn = *p++; pl = D->lglabels + n;\n\t/* Bkwd rel or global. */\n\tif (n <= 246) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }\n\tpl -= 246; n = *pl;\n\tif (n < 0) n = 0;  /* Start new chain for fwd rel if label exists. */\n\tgoto linkrel;\n      case DASM_REL_PC:\n      case DASM_IMM_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);\n      putrel:\n\tn = *pl;\n\tif (n < 0) {  /* Label exists. Get label pos and store it. */\n\t  b[pos] = -n;\n\t} else {\n      linkrel:\n\t  b[pos] = n;  /* Else link to rel chain, anchored at label. */\n\t  *pl = pos;\n\t}\n\tpos++;\n\tofs += 4;  /* Maximum offset needed. */\n\tif (action == DASM_REL_LG || action == DASM_REL_PC) {\n\t  b[pos++] = ofs;  /* Store pass1 offset estimate. */\n\t} else if (sizeof(ptrdiff_t) == 8) {\n\t  ofs += 4;\n\t}\n\tbreak;\n      case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel;\n      case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);\n      putlabel:\n\tn = *pl;  /* n > 0: Collapse rel chain and replace with label pos. */\n\twhile (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; }\n\t*pl = -pos;  /* Label exists now. */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_ALIGN:\n\tofs += *p++;  /* Maximum alignment needed (arg is 2**n-1). */\n\tb[pos++] = ofs;  /* Store pass1 offset estimate. */\n\tbreak;\n      case DASM_EXTERN: p += 2; ofs += 4; break;\n      case DASM_ESC: p++; ofs++; break;\n      case DASM_MARK: mrm = p[-2]; break;\n      case DASM_SECTION:\n\tn = *p; CK(n < D->maxsection, RANGE_SEC); D->section = &D->sections[n];\n      case DASM_STOP: goto stop;\n      }\n    }\n  }\nstop:\n  va_end(ap);\n  sec->pos = pos;\n  sec->ofs = ofs;\n}\n#undef CK\n\n/* Pass 2: Link sections, shrink branches/aligns, fix label offsets. */\nint dasm_link(Dst_DECL, size_t *szp)\n{\n  dasm_State *D = Dst_REF;\n  int secnum;\n  int ofs = 0;\n\n#ifdef DASM_CHECKS\n  *szp = 0;\n  if (D->status != DASM_S_OK) return D->status;\n  {\n    int pc;\n    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)\n      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;\n  }\n#endif\n\n  { /* Handle globals not defined in this translation unit. */\n    int idx;\n    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {\n      int n = D->lglabels[idx];\n      /* Undefined label: Collapse rel chain and replace with marker (< 0). */\n      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }\n    }\n  }\n\n  /* Combine all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->rbuf;\n    int pos = DASM_SEC2POS(secnum);\n    int lastpos = sec->pos;\n\n    while (pos != lastpos) {\n      dasm_ActList p = D->actionlist + b[pos++];\n      int op = 0;\n      while (1) {\n\tint action = *p++;\n\tswitch (action) {\n\tcase DASM_REL_LG: p++;\n\t  /* fallthrough */\n\tcase DASM_REL_PC: {\n\t  int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0);\n\t  if (shrink) {  /* Shrinkable branch opcode? */\n\t    int lofs, lpos = b[pos];\n\t    if (lpos < 0) goto noshrink;  /* Ext global? */\n\t    lofs = *DASM_POS2PTR(D, lpos);\n\t    if (lpos > pos) {  /* Fwd label: add cumulative section offsets. */\n\t      int i;\n\t      for (i = secnum; i < DASM_POS2SEC(lpos); i++)\n\t\tlofs += D->sections[i].ofs;\n\t    } else {\n\t      lofs -= ofs;  /* Bkwd label: unfix offset. */\n\t    }\n\t    lofs -= b[pos+1];  /* Short branch ok? */\n\t    if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink;  /* Yes. */\n\t    else { noshrink: shrink = 0; }  /* No, cannot shrink op. */\n\t  }\n\t  b[pos+1] = shrink;\n\t  pos += 2;\n\t  break;\n\t}\n\t  /* fallthrough */\n\tcase DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++;\n\t  /* fallthrough */\n\tcase DASM_DISP: case DASM_IMM_S: case DASM_IMM_B: case DASM_IMM_W:\n\tcase DASM_IMM_D: case DASM_IMM_WB: case DASM_IMM_DB:\n\tcase DASM_SETLABEL: case DASM_REL_A: case DASM_IMM_PC: pos++; break;\n\tcase DASM_LABEL_LG: p++;\n\t  /* fallthrough */\n\tcase DASM_LABEL_PC: b[pos++] += ofs; break; /* Fix label offset. */\n\tcase DASM_ALIGN: ofs -= (b[pos++]+ofs)&*p++; break; /* Adjust ofs. */\n\tcase DASM_EXTERN: p += 2; break;\n\tcase DASM_ESC: op = *p++; break;\n\tcase DASM_MARK: break;\n\tcase DASM_SECTION: case DASM_STOP: goto stop;\n\tdefault: op = action; break;\n\t}\n      }\n      stop: (void)0;\n    }\n    ofs += sec->ofs;  /* Next section starts right after current section. */\n  }\n\n  D->codesize = ofs;  /* Total size of all code sections */\n  *szp = ofs;\n  return DASM_S_OK;\n}\n\n#define dasmb(x)\t*cp++ = (unsigned char)(x)\n#ifndef DASM_ALIGNED_WRITES\n#define dasmw(x) \\\n  do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0)\n#define dasmd(x) \\\n  do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0)\n#define dasmq(x) \\\n  do { *((unsigned long long *)cp) = (unsigned long long)(x); cp+=8; } while (0)\n#else\n#define dasmw(x)\tdo { dasmb(x); dasmb((x)>>8); } while (0)\n#define dasmd(x)\tdo { dasmw(x); dasmw((x)>>16); } while (0)\n#define dasmq(x)\tdo { dasmd(x); dasmd((x)>>32); } while (0)\n#endif\nstatic unsigned char *dasma_(unsigned char *cp, ptrdiff_t x)\n{\n  if (sizeof(ptrdiff_t) == 8)\n    dasmq((unsigned long long)x);\n  else\n    dasmd((unsigned int)x);\n  return cp;\n}\n#define dasma(x)\t(cp = dasma_(cp, (x)))\n\n/* Pass 3: Encode sections. */\nint dasm_encode(Dst_DECL, void *buffer)\n{\n  dasm_State *D = Dst_REF;\n  unsigned char *base = (unsigned char *)buffer;\n  unsigned char *cp = base;\n  int secnum;\n\n  /* Encode all code sections. No support for data sections (yet). */\n  for (secnum = 0; secnum < D->maxsection; secnum++) {\n    dasm_Section *sec = D->sections + secnum;\n    int *b = sec->buf;\n    int *endb = sec->rbuf + sec->pos;\n\n    while (b != endb) {\n      dasm_ActList p = D->actionlist + *b++;\n      unsigned char *mark = NULL;\n      while (1) {\n\tint action = *p++;\n\tint n = (action >= DASM_DISP && action <= DASM_ALIGN) ? *b++ : 0;\n\tswitch (action) {\n\tcase DASM_DISP: if (!mark) mark = cp; {\n\t  unsigned char *mm = mark;\n\t  if (*p != DASM_IMM_DB && *p != DASM_IMM_WB) mark = NULL;\n\t  if (n == 0) { int mrm = mm[-1]&7; if (mrm == 4) mrm = mm[0]&7;\n\t    if (mrm != 5) { mm[-1] -= 0x80; break; } }\n\t  if (((n+128) & -256) != 0) goto wd; else mm[-1] -= 0x40;\n\t}\n\t  /* fallthrough */\n\tcase DASM_IMM_S: case DASM_IMM_B: wb: dasmb(n); break;\n\tcase DASM_IMM_DB: if (((n+128)&-256) == 0) {\n\t    db: if (!mark) mark = cp; mark[-2] += 2; mark = NULL; goto wb;\n\t  } else mark = NULL;\n\t  /* fallthrough */\n\tcase DASM_IMM_D: wd: dasmd(n); break;\n\tcase DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL;\n\t  /* fallthrough */\n\tcase DASM_IMM_W: dasmw(n); break;\n\tcase DASM_VREG: {\n\t  int t = *p++;\n\t  unsigned char *ex = cp - (t&7);\n\t  if ((n & 8) && t < 0xa0) {\n\t    if (*ex & 0x80) ex[1] ^= 0x20 << (t>>6); else *ex ^= 1 << (t>>6);\n\t    n &= 7;\n\t  } else if (n & 0x10) {\n\t    if (*ex & 0x80) {\n\t      *ex = 0xc5; ex[1] = (ex[1] & 0x80) | ex[2]; ex += 2;\n\t    }\n\t    while (++ex < cp) ex[-1] = *ex;\n\t    if (mark) mark--;\n\t    cp--;\n\t    n &= 7;\n\t  }\n\t  if (t >= 0xc0) n <<= 4;\n\t  else if (t >= 0x40) n <<= 3;\n\t  else if (n == 4 && t < 0x20) { cp[-1] ^= n; *cp++ = 0x20; }\n\t  cp[-1] ^= n;\n\t  break;\n\t}\n\tcase DASM_REL_LG: p++; if (n >= 0) goto rel_pc;\n\t  b++; n = (int)(ptrdiff_t)D->globals[-n];\n\t  /* fallthrough */\n\tcase DASM_REL_A: rel_a:\n\t  n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */\n\tcase DASM_REL_PC: rel_pc: {\n\t  int shrink = *b++;\n\t  int *pb = DASM_POS2PTR(D, n); if (*pb < 0) { n = pb[1]; goto rel_a; }\n\t  n = *pb - ((int)(cp-base) + 4-shrink);\n\t  if (shrink == 0) goto wd;\n\t  if (shrink == 4) { cp--; cp[-1] = *cp-0x10; } else cp[-1] = 0xeb;\n\t  goto wb;\n\t}\n\tcase DASM_IMM_LG:\n\t  p++;\n\t  if (n < 0) { dasma((ptrdiff_t)D->globals[-n]); break; }\n\t  /* fallthrough */\n\tcase DASM_IMM_PC: {\n\t  int *pb = DASM_POS2PTR(D, n);\n\t  dasma(*pb < 0 ? (ptrdiff_t)pb[1] : (*pb + (ptrdiff_t)base));\n\t  break;\n\t}\n\tcase DASM_LABEL_LG: {\n\t  int idx = *p++;\n\t  if (idx >= 10)\n\t    D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));\n\t  break;\n\t}\n\tcase DASM_LABEL_PC: case DASM_SETLABEL: break;\n\tcase DASM_SPACE: { int fill = *p++; while (n--) *cp++ = fill; break; }\n\tcase DASM_ALIGN:\n\t  n = *p++;\n\t  while (((cp-base) & n)) *cp++ = 0x90; /* nop */\n\t  break;\n\tcase DASM_EXTERN: n = DASM_EXTERN(Dst, cp, p[1], *p); p += 2; goto wd;\n\tcase DASM_MARK: mark = cp; break;\n\tcase DASM_ESC: action = *p++;\n\t  /* fallthrough */\n\tdefault: *cp++ = action; break;\n\tcase DASM_SECTION: case DASM_STOP: goto stop;\n\t}\n      }\n      stop: (void)0;\n    }\n  }\n\n  if (base + D->codesize != cp)  /* Check for phase errors. */\n    return DASM_S_PHASE;\n  return DASM_S_OK;\n}\n\n/* Get PC label offset. */\nint dasm_getpclabel(Dst_DECL, unsigned int pc)\n{\n  dasm_State *D = Dst_REF;\n  if (pc*sizeof(int) < D->pcsize) {\n    int pos = D->pclabels[pc];\n    if (pos < 0) return *DASM_POS2PTR(D, -pos);\n    if (pos > 0) return -1;  /* Undefined. */\n  }\n  return -2;  /* Unused or out of range. */\n}\n\n#ifdef DASM_CHECKS\n/* Optional sanity checker to call between isolated encoding steps. */\nint dasm_checkstep(Dst_DECL, int secmatch)\n{\n  dasm_State *D = Dst_REF;\n  if (D->status == DASM_S_OK) {\n    int i;\n    for (i = 1; i <= 9; i++) {\n      if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_L|i; break; }\n      D->lglabels[i] = 0;\n    }\n  }\n  if (D->status == DASM_S_OK && secmatch >= 0 &&\n      D->section != &D->sections[secmatch])\n    D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections);\n  return D->status;\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dasm_x86.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM x86/x64 module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See dynasm.lua for full copyright notice.\n------------------------------------------------------------------------------\n\nlocal x64 = x64\n\n-- Module information:\nlocal _info = {\n  arch =\tx64 and \"x64\" or \"x86\",\n  description =\t\"DynASM x86/x64 module\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  license =\t\"MIT\",\n}\n\n-- Exported glue functions for the arch-specific module.\nlocal _M = { _info = _info }\n\n-- Cache library functions.\nlocal type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs\nlocal assert, unpack, setmetatable = assert, unpack or table.unpack, setmetatable\nlocal _s = string\nlocal sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char\nlocal find, match, gmatch, gsub = _s.find, _s.match, _s.gmatch, _s.gsub\nlocal concat, sort, remove = table.concat, table.sort, table.remove\nlocal bit = bit or require(\"bit\")\nlocal band, bxor, shl, shr = bit.band, bit.bxor, bit.lshift, bit.rshift\n\n-- Inherited tables and callbacks.\nlocal g_opt, g_arch\nlocal wline, werror, wfatal, wwarn\n\n-- Action name list.\n-- CHECK: Keep this in sync with the C code!\nlocal action_names = {\n  -- int arg, 1 buffer pos:\n  \"DISP\",  \"IMM_S\", \"IMM_B\", \"IMM_W\", \"IMM_D\",  \"IMM_WB\", \"IMM_DB\",\n  -- action arg (1 byte), int arg, 1 buffer pos (reg/num):\n  \"VREG\", \"SPACE\",\n  -- ptrdiff_t arg, 1 buffer pos (address): !x64\n  \"SETLABEL\", \"REL_A\",\n  -- action arg (1 byte) or int arg, 2 buffer pos (link, offset):\n  \"REL_LG\", \"REL_PC\",\n  -- action arg (1 byte) or int arg, 1 buffer pos (link):\n  \"IMM_LG\", \"IMM_PC\",\n  -- action arg (1 byte) or int arg, 1 buffer pos (offset):\n  \"LABEL_LG\", \"LABEL_PC\",\n  -- action arg (1 byte), 1 buffer pos (offset):\n  \"ALIGN\",\n  -- action args (2 bytes), no buffer pos.\n  \"EXTERN\",\n  -- action arg (1 byte), no buffer pos.\n  \"ESC\",\n  -- no action arg, no buffer pos.\n  \"MARK\",\n  -- action arg (1 byte), no buffer pos, terminal action:\n  \"SECTION\",\n  -- no args, no buffer pos, terminal action:\n  \"STOP\"\n}\n\n-- Maximum number of section buffer positions for dasm_put().\n-- CHECK: Keep this in sync with the C code!\nlocal maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.\n\n-- Action name -> action number (dynamically generated below).\nlocal map_action = {}\n-- First action number. Everything below does not need to be escaped.\nlocal actfirst = 256-#action_names\n\n-- Action list buffer and string (only used to remove dupes).\nlocal actlist = {}\nlocal actstr = \"\"\n\n-- Argument list for next dasm_put(). Start with offset 0 into action list.\nlocal actargs = { 0 }\n\n-- Current number of section buffer positions for dasm_put().\nlocal secpos = 1\n\n-- VREG kind encodings, pre-shifted by 5 bits.\nlocal map_vreg = {\n  [\"modrm.rm.m\"] = 0x00,\n  [\"modrm.rm.r\"] = 0x20,\n  [\"opcode\"] =     0x20,\n  [\"sib.base\"] =   0x20,\n  [\"sib.index\"] =  0x40,\n  [\"modrm.reg\"] =  0x80,\n  [\"vex.v\"] =      0xa0,\n  [\"imm.hi\"] =     0xc0,\n}\n\n-- Current number of VREG actions contributing to REX/VEX shrinkage.\nlocal vreg_shrink_count = 0\n\n------------------------------------------------------------------------------\n\n-- Compute action numbers for action names.\nfor n,name in ipairs(action_names) do\n  local num = actfirst + n - 1\n  map_action[name] = num\nend\n\n-- Dump action names and numbers.\nlocal function dumpactions(out)\n  out:write(\"DynASM encoding engine action codes:\\n\")\n  for n,name in ipairs(action_names) do\n    local num = map_action[name]\n    out:write(format(\"  %-10s %02X  %d\\n\", name, num, num))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write action list buffer as a huge static C array.\nlocal function writeactions(out, name)\n  local nn = #actlist\n  local last = actlist[nn] or 255\n  actlist[nn] = nil -- Remove last byte.\n  if nn == 0 then nn = 1 end\n  out:write(\"static const unsigned char \", name, \"[\", nn, \"] = {\\n\")\n  local s = \"  \"\n  for n,b in ipairs(actlist) do\n    s = s..b..\",\"\n    if #s >= 75 then\n      assert(out:write(s, \"\\n\"))\n      s = \"  \"\n    end\n  end\n  out:write(s, last, \"\\n};\\n\\n\") -- Add last byte back.\nend\n\n------------------------------------------------------------------------------\n\n-- Add byte to action list.\nlocal function wputxb(n)\n  assert(n >= 0 and n <= 255 and n % 1 == 0, \"byte out of range\")\n  actlist[#actlist+1] = n\nend\n\n-- Add action to list with optional arg. Advance buffer pos, too.\nlocal function waction(action, a, num)\n  wputxb(assert(map_action[action], \"bad action name `\"..action..\"'\"))\n  if a then actargs[#actargs+1] = a end\n  if a or num then secpos = secpos + (num or 1) end\nend\n\n-- Optionally add a VREG action.\nlocal function wvreg(kind, vreg, psz, sk, defer)\n  if not vreg then return end\n  waction(\"VREG\", vreg)\n  local b = assert(map_vreg[kind], \"bad vreg kind `\"..vreg..\"'\")\n  if b < (sk or 0) then\n    vreg_shrink_count = vreg_shrink_count + 1\n  end\n  if not defer then\n    b = b + vreg_shrink_count * 8\n    vreg_shrink_count = 0\n  end\n  wputxb(b + (psz or 0))\nend\n\n-- Add call to embedded DynASM C code.\nlocal function wcall(func, args)\n  wline(format(\"dasm_%s(Dst, %s);\", func, concat(args, \", \")), true)\nend\n\n-- Delete duplicate action list chunks. A tad slow, but so what.\nlocal function dedupechunk(offset)\n  local al, as = actlist, actstr\n  local chunk = char(unpack(al, offset+1, #al))\n  local orig = find(as, chunk, 1, true)\n  if orig then\n    actargs[1] = orig-1 -- Replace with original offset.\n    for i=offset+1,#al do al[i] = nil end -- Kill dupe.\n  else\n    actstr = as..chunk\n  end\nend\n\n-- Flush action list (intervening C code or buffer pos overflow).\nlocal function wflush(term)\n  local offset = actargs[1]\n  if #actlist == offset then return end -- Nothing to flush.\n  if not term then waction(\"STOP\") end -- Terminate action list.\n  dedupechunk(offset)\n  wcall(\"put\", actargs) -- Add call to dasm_put().\n  actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().\n  secpos = 1 -- The actionlist offset occupies a buffer position, too.\nend\n\n-- Put escaped byte.\nlocal function wputb(n)\n  if n >= actfirst then waction(\"ESC\") end -- Need to escape byte.\n  wputxb(n)\nend\n\n------------------------------------------------------------------------------\n\n-- Global label name -> global label number. With auto assignment on 1st use.\nlocal next_global = 10\nlocal map_global = setmetatable({}, { __index = function(t, name)\n  if not match(name, \"^[%a_][%w_@]*$\") then werror(\"bad global label\") end\n  local n = next_global\n  if n > 246 then werror(\"too many global labels\") end\n  next_global = n + 1\n  t[name] = n\n  return n\nend})\n\n-- Dump global labels.\nlocal function dumpglobals(out, lvl)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"Global labels:\\n\")\n  for i=10,next_global-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write global label enum.\nlocal function writeglobals(out, prefix)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"enum {\\n\")\n  for i=10,next_global-1 do\n    out:write(\"  \", prefix, gsub(t[i], \"@.*\", \"\"), \",\\n\")\n  end\n  out:write(\"  \", prefix, \"_MAX\\n};\\n\")\nend\n\n-- Write global label names.\nlocal function writeglobalnames(out, name)\n  local t = {}\n  for name, n in pairs(map_global) do t[n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=10,next_global-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Extern label name -> extern label number. With auto assignment on 1st use.\nlocal next_extern = -1\nlocal map_extern = setmetatable({}, { __index = function(t, name)\n  -- No restrictions on the name for now.\n  local n = next_extern\n  if n < -256 then werror(\"too many extern labels\") end\n  next_extern = n - 1\n  t[name] = n\n  return n\nend})\n\n-- Dump extern labels.\nlocal function dumpexterns(out, lvl)\n  local t = {}\n  for name, n in pairs(map_extern) do t[-n] = name end\n  out:write(\"Extern labels:\\n\")\n  for i=1,-next_extern-1 do\n    out:write(format(\"  %s\\n\", t[i]))\n  end\n  out:write(\"\\n\")\nend\n\n-- Write extern label names.\nlocal function writeexternnames(out, name)\n  local t = {}\n  for name, n in pairs(map_extern) do t[-n] = name end\n  out:write(\"static const char *const \", name, \"[] = {\\n\")\n  for i=1,-next_extern-1 do\n    out:write(\"  \\\"\", t[i], \"\\\",\\n\")\n  end\n  out:write(\"  (const char *)0\\n};\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Arch-specific maps.\nlocal map_archdef = {}\t\t-- Ext. register name -> int. name.\nlocal map_reg_rev = {}\t\t-- Int. register name -> ext. name.\nlocal map_reg_num = {}\t\t-- Int. register name -> register number.\nlocal map_reg_opsize = {}\t-- Int. register name -> operand size.\nlocal map_reg_valid_base = {}\t-- Int. register name -> valid base register?\nlocal map_reg_valid_index = {}\t-- Int. register name -> valid index register?\nlocal map_reg_needrex = {}\t-- Int. register name -> need rex vs. no rex.\nlocal reg_list = {}\t\t-- Canonical list of int. register names.\n\nlocal map_type = {}\t\t-- Type name -> { ctype, reg }\nlocal ctypenum = 0\t\t-- Type number (for _PTx macros).\n\nlocal addrsize = x64 and \"q\" or \"d\"\t-- Size for address operands.\n\n-- Helper functions to fill register maps.\nlocal function mkrmap(sz, cl, names)\n  local cname = format(\"@%s\", sz)\n  reg_list[#reg_list+1] = cname\n  map_archdef[cl] = cname\n  map_reg_rev[cname] = cl\n  map_reg_num[cname] = -1\n  map_reg_opsize[cname] = sz\n  if sz == addrsize or sz == \"d\" then\n    map_reg_valid_base[cname] = true\n    map_reg_valid_index[cname] = true\n  end\n  if names then\n    for n,name in ipairs(names) do\n      local iname = format(\"@%s%x\", sz, n-1)\n      reg_list[#reg_list+1] = iname\n      map_archdef[name] = iname\n      map_reg_rev[iname] = name\n      map_reg_num[iname] = n-1\n      map_reg_opsize[iname] = sz\n      if sz == \"b\" and n > 4 then map_reg_needrex[iname] = false end\n      if sz == addrsize or sz == \"d\" then\n\tmap_reg_valid_base[iname] = true\n\tmap_reg_valid_index[iname] = true\n      end\n    end\n  end\n  for i=0,(x64 and sz ~= \"f\") and 15 or 7 do\n    local needrex = sz == \"b\" and i > 3\n    local iname = format(\"@%s%x%s\", sz, i, needrex and \"R\" or \"\")\n    if needrex then map_reg_needrex[iname] = true end\n    local name\n    if sz == \"o\" or sz == \"y\" then name = format(\"%s%d\", cl, i)\n    elseif sz == \"f\" then name = format(\"st%d\", i)\n    else name = format(\"r%d%s\", i, sz == addrsize and \"\" or sz) end\n    map_archdef[name] = iname\n    if not map_reg_rev[iname] then\n      reg_list[#reg_list+1] = iname\n      map_reg_rev[iname] = name\n      map_reg_num[iname] = i\n      map_reg_opsize[iname] = sz\n      if sz == addrsize or sz == \"d\" then\n\tmap_reg_valid_base[iname] = true\n\tmap_reg_valid_index[iname] = true\n      end\n    end\n  end\n  reg_list[#reg_list+1] = \"\"\nend\n\n-- Integer registers (qword, dword, word and byte sized).\nif x64 then\n  mkrmap(\"q\", \"Rq\", {\"rax\", \"rcx\", \"rdx\", \"rbx\", \"rsp\", \"rbp\", \"rsi\", \"rdi\"})\nend\nmkrmap(\"d\", \"Rd\", {\"eax\", \"ecx\", \"edx\", \"ebx\", \"esp\", \"ebp\", \"esi\", \"edi\"})\nmkrmap(\"w\", \"Rw\", {\"ax\", \"cx\", \"dx\", \"bx\", \"sp\", \"bp\", \"si\", \"di\"})\nmkrmap(\"b\", \"Rb\", {\"al\", \"cl\", \"dl\", \"bl\", \"ah\", \"ch\", \"dh\", \"bh\"})\nmap_reg_valid_index[map_archdef.esp] = false\nif x64 then map_reg_valid_index[map_archdef.rsp] = false end\nif x64 then map_reg_needrex[map_archdef.Rb] = true end\nmap_archdef[\"Ra\"] = \"@\"..addrsize\n\n-- FP registers (internally tword sized, but use \"f\" as operand size).\nmkrmap(\"f\", \"Rf\")\n\n-- SSE registers (oword sized, but qword and dword accessible).\nmkrmap(\"o\", \"xmm\")\n\n-- AVX registers (yword sized, but oword, qword and dword accessible).\nmkrmap(\"y\", \"ymm\")\n\n-- Operand size prefixes to codes.\nlocal map_opsize = {\n  byte = \"b\", word = \"w\", dword = \"d\", qword = \"q\", oword = \"o\", yword = \"y\",\n  tword = \"t\", aword = addrsize,\n}\n\n-- Operand size code to number.\nlocal map_opsizenum = {\n  b = 1, w = 2, d = 4, q = 8, o = 16, y = 32, t = 10,\n}\n\n-- Operand size code to name.\nlocal map_opsizename = {\n  b = \"byte\", w = \"word\", d = \"dword\", q = \"qword\", o = \"oword\", y = \"yword\",\n  t = \"tword\", f = \"fpword\",\n}\n\n-- Valid index register scale factors.\nlocal map_xsc = {\n  [\"1\"] = 0, [\"2\"] = 1, [\"4\"] = 2, [\"8\"] = 3,\n}\n\n-- Condition codes.\nlocal map_cc = {\n  o = 0, no = 1, b = 2, nb = 3, e = 4, ne = 5, be = 6, nbe = 7,\n  s = 8, ns = 9, p = 10, np = 11, l = 12, nl = 13, le = 14, nle = 15,\n  c = 2, nae = 2, nc = 3, ae = 3, z = 4, nz = 5, na = 6, a = 7,\n  pe = 10, po = 11, nge = 12, ge = 13, ng = 14, g = 15,\n}\n\n\n-- Reverse defines for registers.\nfunction _M.revdef(s)\n  return gsub(s, \"@%w+\", map_reg_rev)\nend\n\n-- Dump register names and numbers\nlocal function dumpregs(out)\n  out:write(\"Register names, sizes and internal numbers:\\n\")\n  for _,reg in ipairs(reg_list) do\n    if reg == \"\" then\n      out:write(\"\\n\")\n    else\n      local name = map_reg_rev[reg]\n      local num = map_reg_num[reg]\n      local opsize = map_opsizename[map_reg_opsize[reg]]\n      out:write(format(\"  %-5s %-8s %s\\n\", name, opsize,\n\t\t       num < 0 and \"(variable)\" or num))\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Put action for label arg (IMM_LG, IMM_PC, REL_LG, REL_PC).\nlocal function wputlabel(aprefix, imm, num)\n  if type(imm) == \"number\" then\n    if imm < 0 then\n      waction(\"EXTERN\")\n      wputxb(aprefix == \"IMM_\" and 0 or 1)\n      imm = -imm-1\n    else\n      waction(aprefix..\"LG\", nil, num);\n    end\n    wputxb(imm)\n  else\n    waction(aprefix..\"PC\", imm, num)\n  end\nend\n\n-- Put signed byte or arg.\nlocal function wputsbarg(n)\n  if type(n) == \"number\" then\n    if n < -128 or n > 127 then\n      werror(\"signed immediate byte out of range\")\n    end\n    if n < 0 then n = n + 256 end\n    wputb(n)\n  else waction(\"IMM_S\", n) end\nend\n\n-- Put unsigned byte or arg.\nlocal function wputbarg(n)\n  if type(n) == \"number\" then\n    if n < 0 or n > 255 then\n      werror(\"unsigned immediate byte out of range\")\n    end\n    wputb(n)\n  else waction(\"IMM_B\", n) end\nend\n\n-- Put unsigned word or arg.\nlocal function wputwarg(n)\n  if type(n) == \"number\" then\n    if shr(n, 16) ~= 0 then\n      werror(\"unsigned immediate word out of range\")\n    end\n    wputb(band(n, 255)); wputb(shr(n, 8));\n  else waction(\"IMM_W\", n) end\nend\n\n-- Put signed or unsigned dword or arg.\nlocal function wputdarg(n)\n  local tn = type(n)\n  if tn == \"number\" then\n    wputb(band(n, 255))\n    wputb(band(shr(n, 8), 255))\n    wputb(band(shr(n, 16), 255))\n    wputb(shr(n, 24))\n  elseif tn == \"table\" then\n    wputlabel(\"IMM_\", n[1], 1)\n  else\n    waction(\"IMM_D\", n)\n  end\nend\n\n-- Put signed or unsigned qword or arg.\nlocal function wputqarg(n)\n  local tn = type(n)\n  if tn == \"number\" then -- This is only used for numbers from -2^31..2^32-1.\n    wputb(band(n, 255))\n    wputb(band(shr(n, 8), 255))\n    wputb(band(shr(n, 16), 255))\n    wputb(shr(n, 24))\n    local sign = n < 0 and 255 or 0\n    wputb(sign); wputb(sign); wputb(sign); wputb(sign)\n  else\n    waction(\"IMM_D\", format(\"(unsigned int)(%s)\", n))\n    waction(\"IMM_D\", format(\"(unsigned int)((unsigned long long)(%s)>>32)\", n))\n  end\nend\n\n-- Put operand-size dependent number or arg (defaults to dword).\nlocal function wputszarg(sz, n)\n  if not sz or sz == \"d\" or sz == \"q\" then wputdarg(n)\n  elseif sz == \"w\" then wputwarg(n)\n  elseif sz == \"b\" then wputbarg(n)\n  elseif sz == \"s\" then wputsbarg(n)\n  else werror(\"bad operand size\") end\nend\n\n-- Put multi-byte opcode with operand-size dependent modifications.\nlocal function wputop(sz, op, rex, vex, vregr, vregxb)\n  local psz, sk = 0, nil\n  if vex then\n    local tail\n    if vex.m == 1 and band(rex, 11) == 0 then\n      if x64 and vregxb then\n\tsk = map_vreg[\"modrm.reg\"]\n      else\n\twputb(0xc5)\n      tail = shl(bxor(band(rex, 4), 4), 5)\n      psz = 3\n      end\n    end\n    if not tail then\n      wputb(0xc4)\n      wputb(shl(bxor(band(rex, 7), 7), 5) + vex.m)\n      tail = shl(band(rex, 8), 4)\n      psz = 4\n    end\n    local reg, vreg = 0, nil\n    if vex.v then\n      reg = vex.v.reg\n      if not reg then werror(\"bad vex operand\") end\n      if reg < 0 then reg = 0; vreg = vex.v.vreg end\n    end\n    if sz == \"y\" or vex.l then tail = tail + 4 end\n    wputb(tail + shl(bxor(reg, 15), 3) + vex.p)\n    wvreg(\"vex.v\", vreg)\n    rex = 0\n    if op >= 256 then werror(\"bad vex opcode\") end\n  else\n    if rex ~= 0 then\n      if not x64 then werror(\"bad operand size\") end\n    elseif (vregr or vregxb) and x64 then\n      rex = 0x10\n      sk = map_vreg[\"vex.v\"]\n    end\n  end\n  local r\n  if sz == \"w\" then wputb(102) end\n  -- Needs >32 bit numbers, but only for crc32 eax, word [ebx]\n  if op >= 4294967296 then r = op%4294967296 wputb((op-r)/4294967296) op = r end\n  if op >= 16777216 then wputb(shr(op, 24)); op = band(op, 0xffffff) end\n  if op >= 65536 then\n    if rex ~= 0 then\n      local opc3 = band(op, 0xffff00)\n      if opc3 == 0x0f3a00 or opc3 == 0x0f3800 then\n\twputb(64 + band(rex, 15)); rex = 0; psz = 2\n      end\n    end\n    wputb(shr(op, 16)); op = band(op, 0xffff); psz = psz + 1\n  end\n  if op >= 256 then\n    local b = shr(op, 8)\n    if b == 15 and rex ~= 0 then wputb(64 + band(rex, 15)); rex = 0; psz = 2 end\n    wputb(b); op = band(op, 255); psz = psz + 1\n  end\n  if rex ~= 0 then wputb(64 + band(rex, 15)); psz = 2 end\n  if sz == \"b\" then op = op - 1 end\n  wputb(op)\n  return psz, sk\nend\n\n-- Put ModRM or SIB formatted byte.\nlocal function wputmodrm(m, s, rm, vs, vrm)\n  assert(m < 4 and s < 16 and rm < 16, \"bad modrm operands\")\n  wputb(shl(m, 6) + shl(band(s, 7), 3) + band(rm, 7))\nend\n\n-- Put ModRM/SIB plus optional displacement.\nlocal function wputmrmsib(t, imark, s, vsreg, psz, sk)\n  local vreg, vxreg\n  local reg, xreg = t.reg, t.xreg\n  if reg and reg < 0 then reg = 0; vreg = t.vreg end\n  if xreg and xreg < 0 then xreg = 0; vxreg = t.vxreg end\n  if s < 0 then s = 0 end\n\n  -- Register mode.\n  if sub(t.mode, 1, 1) == \"r\" then\n    wputmodrm(3, s, reg)\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vreg)\n    wvreg(\"modrm.rm.r\", vreg, psz+1, sk)\n    return\n  end\n\n  local disp = t.disp\n  local tdisp = type(disp)\n  -- No base register?\n  if not reg then\n    local riprel = false\n    if xreg then\n      -- Indexed mode with index register only.\n      -- [xreg*xsc+disp] -> (0, s, esp) (xsc, xreg, ebp)\n      wputmodrm(0, s, 4)\n      if imark == \"I\" then waction(\"MARK\") end\n      wvreg(\"modrm.reg\", vsreg, psz+1, sk, vxreg)\n      wputmodrm(t.xsc, xreg, 5)\n      wvreg(\"sib.index\", vxreg, psz+2, sk)\n    else\n      -- Pure 32 bit displacement.\n      if x64 and tdisp ~= \"table\" then\n\twputmodrm(0, s, 4) -- [disp] -> (0, s, esp) (0, esp, ebp)\n\twvreg(\"modrm.reg\", vsreg, psz+1, sk)\n\tif imark == \"I\" then waction(\"MARK\") end\n\twputmodrm(0, 4, 5)\n      else\n\triprel = x64\n\twputmodrm(0, s, 5) -- [disp|rip-label] -> (0, s, ebp)\n\twvreg(\"modrm.reg\", vsreg, psz+1, sk)\n\tif imark == \"I\" then waction(\"MARK\") end\n      end\n    end\n    if riprel then -- Emit rip-relative displacement.\n      if match(\"UWSiI\", imark) then\n\twerror(\"NYI: rip-relative displacement followed by immediate\")\n      end\n      -- The previous byte in the action buffer cannot be 0xe9 or 0x80-0x8f.\n      wputlabel(\"REL_\", disp[1], 2)\n    else\n      wputdarg(disp)\n    end\n    return\n  end\n\n  local m\n  if tdisp == \"number\" then -- Check displacement size at assembly time.\n    if disp == 0 and band(reg, 7) ~= 5 then -- [ebp] -> [ebp+0] (in SIB, too)\n      if not vreg then m = 0 end -- Force DISP to allow [Rd(5)] -> [ebp+0]\n    elseif disp >= -128 and disp <= 127 then m = 1\n    else m = 2 end\n  elseif tdisp == \"table\" then\n    m = 2\n  end\n\n  -- Index register present or esp as base register: need SIB encoding.\n  if xreg or band(reg, 7) == 4 then\n    wputmodrm(m or 2, s, 4) -- ModRM.\n    if m == nil or imark == \"I\" then waction(\"MARK\") end\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vxreg or vreg)\n    wputmodrm(t.xsc or 0, xreg or 4, reg) -- SIB.\n    wvreg(\"sib.index\", vxreg, psz+2, sk, vreg)\n    wvreg(\"sib.base\", vreg, psz+2, sk)\n  else\n    wputmodrm(m or 2, s, reg) -- ModRM.\n    if (imark == \"I\" and (m == 1 or m == 2)) or\n       (m == nil and (vsreg or vreg)) then waction(\"MARK\") end\n    wvreg(\"modrm.reg\", vsreg, psz+1, sk, vreg)\n    wvreg(\"modrm.rm.m\", vreg, psz+1, sk)\n  end\n\n  -- Put displacement.\n  if m == 1 then wputsbarg(disp)\n  elseif m == 2 then wputdarg(disp)\n  elseif m == nil then waction(\"DISP\", disp) end\nend\n\n------------------------------------------------------------------------------\n\n-- Return human-readable operand mode string.\nlocal function opmodestr(op, args)\n  local m = {}\n  for i=1,#args do\n    local a = args[i]\n    m[#m+1] = sub(a.mode, 1, 1)..(a.opsize or \"?\")\n  end\n  return op..\" \"..concat(m, \",\")\nend\n\n-- Convert number to valid integer or nil.\nlocal function toint(expr, isqword)\n  local n = tonumber(expr)\n  if n then\n    if n % 1 ~= 0 then\n      werror(\"not an integer number `\"..expr..\"'\")\n    elseif isqword then\n      if n < -2147483648 or n > 2147483647 then\n\tn = nil -- Handle it as an expression to avoid precision loss.\n      end\n    elseif n < -2147483648 or n > 4294967295 then\n      werror(\"bad integer number `\"..expr..\"'\")\n    end\n    return n\n  end\nend\n\n-- Parse immediate expression.\nlocal function immexpr(expr)\n  -- &expr (pointer)\n  if sub(expr, 1, 1) == \"&\" then\n    return \"iPJ\", format(\"(ptrdiff_t)(%s)\", sub(expr,2))\n  end\n\n  local prefix = sub(expr, 1, 2)\n  -- =>expr (pc label reference)\n  if prefix == \"=>\" then\n    return \"iJ\", sub(expr, 3)\n  end\n  -- ->name (global label reference)\n  if prefix == \"->\" then\n    return \"iJ\", map_global[sub(expr, 3)]\n  end\n\n  -- [<>][1-9] (local label reference)\n  local dir, lnum = match(expr, \"^([<>])([1-9])$\")\n  if dir then -- Fwd: 247-255, Bkwd: 1-9.\n    return \"iJ\", lnum + (dir == \">\" and 246 or 0)\n  end\n\n  local extname = match(expr, \"^extern%s+(%S+)$\")\n  if extname then\n    return \"iJ\", map_extern[extname]\n  end\n\n  -- expr (interpreted as immediate)\n  return \"iI\", expr\nend\n\n-- Parse displacement expression: +-num, +-expr, +-opsize*num\nlocal function dispexpr(expr)\n  local disp = expr == \"\" and 0 or toint(expr)\n  if disp then return disp end\n  local c, dispt = match(expr, \"^([+-])%s*(.+)$\")\n  if c == \"+\" then\n    expr = dispt\n  elseif not c then\n    werror(\"bad displacement expression `\"..expr..\"'\")\n  end\n  local opsize, tailops = match(dispt, \"^(%w+)%s*%*%s*(.+)$\")\n  local ops, imm = map_opsize[opsize], toint(tailops)\n  if ops and imm then\n    if c == \"-\" then imm = -imm end\n    return imm*map_opsizenum[ops]\n  end\n  local mode, iexpr = immexpr(dispt)\n  if mode == \"iJ\" then\n    if c == \"-\" then werror(\"cannot invert label reference\") end\n    return { iexpr }\n  end\n  return expr -- Need to return original signed expression.\nend\n\n-- Parse register or type expression.\nlocal function rtexpr(expr)\n  if not expr then return end\n  local tname, ovreg = match(expr, \"^([%w_]+):(@[%w_]+)$\")\n  local tp = map_type[tname or expr]\n  if tp then\n    local reg = ovreg or tp.reg\n    local rnum = map_reg_num[reg]\n    if not rnum then\n      werror(\"type `\"..(tname or expr)..\"' needs a register override\")\n    end\n    if not map_reg_valid_base[reg] then\n      werror(\"bad base register override `\"..(map_reg_rev[reg] or reg)..\"'\")\n    end\n    return reg, rnum, tp\n  end\n  return expr, map_reg_num[expr]\nend\n\n-- Parse operand and return { mode, opsize, reg, xreg, xsc, disp, imm }.\nlocal function parseoperand(param, isqword)\n  local t = {}\n\n  local expr = param\n  local opsize, tailops = match(param, \"^(%w+)%s*(.+)$\")\n  if opsize then\n    t.opsize = map_opsize[opsize]\n    if t.opsize then expr = tailops end\n  end\n\n  local br = match(expr, \"^%[%s*(.-)%s*%]$\")\n  repeat\n    if br then\n      t.mode = \"xm\"\n\n      -- [disp]\n      t.disp = toint(br)\n      if t.disp then\n\tt.mode = x64 and \"xm\" or \"xmO\"\n\tbreak\n      end\n\n      -- [reg...]\n      local tp\n      local reg, tailr = match(br, \"^([@%w_:]+)%s*(.*)$\")\n      reg, t.reg, tp = rtexpr(reg)\n      if not t.reg then\n\t-- [expr]\n\tt.mode = x64 and \"xm\" or \"xmO\"\n\tt.disp = dispexpr(\"+\"..br)\n\tbreak\n      end\n\n      if t.reg == -1 then\n\tt.vreg, tailr = match(tailr, \"^(%b())(.*)$\")\n\tif not t.vreg then werror(\"bad variable register expression\") end\n      end\n\n      -- [xreg*xsc] or [xreg*xsc+-disp] or [xreg*xsc+-expr]\n      local xsc, tailsc = match(tailr, \"^%*%s*([1248])%s*(.*)$\")\n      if xsc then\n\tif not map_reg_valid_index[reg] then\n\t  werror(\"bad index register `\"..map_reg_rev[reg]..\"'\")\n\tend\n\tt.xsc = map_xsc[xsc]\n\tt.xreg = t.reg\n\tt.vxreg = t.vreg\n\tt.reg = nil\n\tt.vreg = nil\n\tt.disp = dispexpr(tailsc)\n\tbreak\n      end\n      if not map_reg_valid_base[reg] then\n\twerror(\"bad base register `\"..map_reg_rev[reg]..\"'\")\n      end\n\n      -- [reg] or [reg+-disp]\n      t.disp = toint(tailr) or (tailr == \"\" and 0)\n      if t.disp then break end\n\n      -- [reg+xreg...]\n      local xreg, tailx = match(tailr, \"^%+%s*([@%w_:]+)%s*(.*)$\")\n      xreg, t.xreg, tp = rtexpr(xreg)\n      if not t.xreg then\n\t-- [reg+-expr]\n\tt.disp = dispexpr(tailr)\n\tbreak\n      end\n      if not map_reg_valid_index[xreg] then\n\twerror(\"bad index register `\"..map_reg_rev[xreg]..\"'\")\n      end\n\n      if t.xreg == -1 then\n\tt.vxreg, tailx = match(tailx, \"^(%b())(.*)$\")\n\tif not t.vxreg then werror(\"bad variable register expression\") end\n      end\n\n      -- [reg+xreg*xsc...]\n      local xsc, tailsc = match(tailx, \"^%*%s*([1248])%s*(.*)$\")\n      if xsc then\n\tt.xsc = map_xsc[xsc]\n\ttailx = tailsc\n      end\n\n      -- [...] or [...+-disp] or [...+-expr]\n      t.disp = dispexpr(tailx)\n    else\n      -- imm or opsize*imm\n      local imm = toint(expr, isqword)\n      if not imm and sub(expr, 1, 1) == \"*\" and t.opsize then\n\timm = toint(sub(expr, 2))\n\tif imm then\n\t  imm = imm * map_opsizenum[t.opsize]\n\t  t.opsize = nil\n\tend\n      end\n      if imm then\n\tif t.opsize then werror(\"bad operand size override\") end\n\tlocal m = \"i\"\n\tif imm == 1 then m = m..\"1\" end\n\tif imm >= 4294967168 and imm <= 4294967295 then imm = imm-4294967296 end\n\tif imm >= -128 and imm <= 127 then m = m..\"S\" end\n\tt.imm = imm\n\tt.mode = m\n\tbreak\n      end\n\n      local tp\n      local reg, tailr = match(expr, \"^([@%w_:]+)%s*(.*)$\")\n      reg, t.reg, tp = rtexpr(reg)\n      if t.reg then\n\tif t.reg == -1 then\n\t  t.vreg, tailr = match(tailr, \"^(%b())(.*)$\")\n\t  if not t.vreg then werror(\"bad variable register expression\") end\n\tend\n\t-- reg\n\tif tailr == \"\" then\n\t  if t.opsize then werror(\"bad operand size override\") end\n\t  t.opsize = map_reg_opsize[reg]\n\t  if t.opsize == \"f\" then\n\t    t.mode = t.reg == 0 and \"fF\" or \"f\"\n\t  else\n\t    if reg == \"@w4\" or (x64 and reg == \"@d4\") then\n\t      wwarn(\"bad idea, try again with `\"..(x64 and \"rsp'\" or \"esp'\"))\n\t    end\n\t    t.mode = t.reg == 0 and \"rmR\" or (reg == \"@b1\" and \"rmC\" or \"rm\")\n\t  end\n\t  t.needrex = map_reg_needrex[reg]\n\t  break\n\tend\n\n\t-- type[idx], type[idx].field, type->field -> [reg+offset_expr]\n\tif not tp then werror(\"bad operand `\"..param..\"'\") end\n\tt.mode = \"xm\"\n\tt.disp = format(tp.ctypefmt, tailr)\n      else\n\tt.mode, t.imm = immexpr(expr)\n\tif sub(t.mode, -1) == \"J\" then\n\t  if t.opsize and t.opsize ~= addrsize then\n\t    werror(\"bad operand size override\")\n\t  end\n\t  t.opsize = addrsize\n\tend\n      end\n    end\n  until true\n  return t\nend\n\n------------------------------------------------------------------------------\n-- x86 Template String Description\n-- ===============================\n--\n-- Each template string is a list of [match:]pattern pairs,\n-- separated by \"|\". The first match wins. No match means a\n-- bad or unsupported combination of operand modes or sizes.\n--\n-- The match part and the \":\" is omitted if the operation has\n-- no operands. Otherwise the first N characters are matched\n-- against the mode strings of each of the N operands.\n--\n-- The mode string for each operand type is (see parseoperand()):\n--   Integer register: \"rm\", +\"R\" for eax, ax, al, +\"C\" for cl\n--   FP register:      \"f\",  +\"F\" for st0\n--   Index operand:    \"xm\", +\"O\" for [disp] (pure offset)\n--   Immediate:        \"i\",  +\"S\" for signed 8 bit, +\"1\" for 1,\n--                     +\"I\" for arg, +\"P\" for pointer\n--   Any:              +\"J\" for valid jump targets\n--\n-- So a match character \"m\" (mixed) matches both an integer register\n-- and an index operand (to be encoded with the ModRM/SIB scheme).\n-- But \"r\" matches only a register and \"x\" only an index operand\n-- (e.g. for FP memory access operations).\n--\n-- The operand size match string starts right after the mode match\n-- characters and ends before the \":\". \"dwb\" or \"qdwb\" is assumed, if empty.\n-- The effective data size of the operation is matched against this list.\n--\n-- If only the regular \"b\", \"w\", \"d\", \"q\", \"t\" operand sizes are\n-- present, then all operands must be the same size. Unspecified sizes\n-- are ignored, but at least one operand must have a size or the pattern\n-- won't match (use the \"byte\", \"word\", \"dword\", \"qword\", \"tword\"\n-- operand size overrides. E.g.: mov dword [eax], 1).\n--\n-- If the list has a \"1\" or \"2\" prefix, the operand size is taken\n-- from the respective operand and any other operand sizes are ignored.\n-- If the list contains only \".\", all operand sizes are ignored.\n-- If the list has a \"/\" prefix, the concatenated (mixed) operand sizes\n-- are compared to the match.\n--\n-- E.g. \"rrdw\" matches for either two dword registers or two word\n-- registers. \"Fx2dq\" matches an st0 operand plus an index operand\n-- pointing to a dword (float) or qword (double).\n--\n-- Every character after the \":\" is part of the pattern string:\n--   Hex chars are accumulated to form the opcode (left to right).\n--   \"n\"       disables the standard opcode mods\n--             (otherwise: -1 for \"b\", o16 prefix for \"w\", rex.w for \"q\")\n--   \"X\"       Force REX.W.\n--   \"r\"/\"R\"   adds the reg. number from the 1st/2nd operand to the opcode.\n--   \"m\"/\"M\"   generates ModRM/SIB from the 1st/2nd operand.\n--             The spare 3 bits are either filled with the last hex digit or\n--             the result from a previous \"r\"/\"R\". The opcode is restored.\n--   \"u\"       Use VEX encoding, vvvv unused.\n--   \"v\"/\"V\"   Use VEX encoding, vvvv from 1st/2nd operand (the operand is\n--             removed from the list used by future characters).\n--   \"w\"       Use VEX encoding, vvvv from 3rd operand.\n--   \"L\"       Force VEX.L\n--\n-- All of the following characters force a flush of the opcode:\n--   \"o\"/\"O\"   stores a pure 32 bit disp (offset) from the 1st/2nd operand.\n--   \"s\"       stores a 4 bit immediate from the last register operand,\n--             followed by 4 zero bits.\n--   \"S\"       stores a signed 8 bit immediate from the last operand.\n--   \"U\"       stores an unsigned 8 bit immediate from the last operand.\n--   \"W\"       stores an unsigned 16 bit immediate from the last operand.\n--   \"i\"       stores an operand sized immediate from the last operand.\n--   \"I\"       dito, but generates an action code to optionally modify\n--             the opcode (+2) for a signed 8 bit immediate.\n--   \"J\"       generates one of the REL action codes from the last operand.\n--\n------------------------------------------------------------------------------\n\n-- Template strings for x86 instructions. Ordered by first opcode byte.\n-- Unimplemented opcodes (deliberate omissions) are marked with *.\nlocal map_op = {\n  -- 00-05: add...\n  -- 06: *push es\n  -- 07: *pop es\n  -- 08-0D: or...\n  -- 0E: *push cs\n  -- 0F: two byte opcode prefix\n  -- 10-15: adc...\n  -- 16: *push ss\n  -- 17: *pop ss\n  -- 18-1D: sbb...\n  -- 1E: *push ds\n  -- 1F: *pop ds\n  -- 20-25: and...\n  es_0 =\t\"26\",\n  -- 27: *daa\n  -- 28-2D: sub...\n  cs_0 =\t\"2E\",\n  -- 2F: *das\n  -- 30-35: xor...\n  ss_0 =\t\"36\",\n  -- 37: *aaa\n  -- 38-3D: cmp...\n  ds_0 =\t\"3E\",\n  -- 3F: *aas\n  inc_1 =\tx64 and \"m:FF0m\" or \"rdw:40r|m:FF0m\",\n  dec_1 =\tx64 and \"m:FF1m\" or \"rdw:48r|m:FF1m\",\n  push_1 =\t(x64 and \"rq:n50r|rw:50r|mq:nFF6m|mw:FF6m\" or\n\t\t\t \"rdw:50r|mdw:FF6m\")..\"|S.:6AS|ib:n6Ai|i.:68i\",\n  pop_1 =\tx64 and \"rq:n58r|rw:58r|mq:n8F0m|mw:8F0m\" or \"rdw:58r|mdw:8F0m\",\n  -- 60: *pusha, *pushad, *pushaw\n  -- 61: *popa, *popad, *popaw\n  -- 62: *bound rdw,x\n  -- 63: x86: *arpl mw,rw\n  movsxd_2 =\tx64 and \"rm/qd:63rM\",\n  fs_0 =\t\"64\",\n  gs_0 =\t\"65\",\n  o16_0 =\t\"66\",\n  a16_0 =\tnot x64 and \"67\" or nil,\n  a32_0 =\tx64 and \"67\",\n  -- 68: push idw\n  -- 69: imul rdw,mdw,idw\n  -- 6A: push ib\n  -- 6B: imul rdw,mdw,S\n  -- 6C: *insb\n  -- 6D: *insd, *insw\n  -- 6E: *outsb\n  -- 6F: *outsd, *outsw\n  -- 70-7F: jcc lb\n  -- 80: add... mb,i\n  -- 81: add... mdw,i\n  -- 82: *undefined\n  -- 83: add... mdw,S\n  test_2 =\t\"mr:85Rm|rm:85rM|Ri:A9ri|mi:F70mi\",\n  -- 86: xchg rb,mb\n  -- 87: xchg rdw,mdw\n  -- 88: mov mb,r\n  -- 89: mov mdw,r\n  -- 8A: mov r,mb\n  -- 8B: mov r,mdw\n  -- 8C: *mov mdw,seg\n  lea_2 =\t\"rx1dq:8DrM\",\n  -- 8E: *mov seg,mdw\n  -- 8F: pop mdw\n  nop_0 =\t\"90\",\n  xchg_2 =\t\"Rrqdw:90R|rRqdw:90r|rm:87rM|mr:87Rm\",\n  cbw_0 =\t\"6698\",\n  cwde_0 =\t\"98\",\n  cdqe_0 =\t\"4898\",\n  cwd_0 =\t\"6699\",\n  cdq_0 =\t\"99\",\n  cqo_0 =\t\"4899\",\n  -- 9A: *call iw:idw\n  wait_0 =\t\"9B\",\n  fwait_0 =\t\"9B\",\n  pushf_0 =\t\"9C\",\n  pushfd_0 =\tnot x64 and \"9C\",\n  pushfq_0 =\tx64 and \"9C\",\n  popf_0 =\t\"9D\",\n  popfd_0 =\tnot x64 and \"9D\",\n  popfq_0 =\tx64 and \"9D\",\n  sahf_0 =\t\"9E\",\n  lahf_0 =\t\"9F\",\n  mov_2 =\t\"OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi\",\n  movsb_0 =\t\"A4\",\n  movsw_0 =\t\"66A5\",\n  movsd_0 =\t\"A5\",\n  cmpsb_0 =\t\"A6\",\n  cmpsw_0 =\t\"66A7\",\n  cmpsd_0 =\t\"A7\",\n  -- A8: test Rb,i\n  -- A9: test Rdw,i\n  stosb_0 =\t\"AA\",\n  stosw_0 =\t\"66AB\",\n  stosd_0 =\t\"AB\",\n  lodsb_0 =\t\"AC\",\n  lodsw_0 =\t\"66AD\",\n  lodsd_0 =\t\"AD\",\n  scasb_0 =\t\"AE\",\n  scasw_0 =\t\"66AF\",\n  scasd_0 =\t\"AF\",\n  -- B0-B7: mov rb,i\n  -- B8-BF: mov rdw,i\n  -- C0: rol... mb,i\n  -- C1: rol... mdw,i\n  ret_1 =\t\"i.:nC2W\",\n  ret_0 =\t\"C3\",\n  -- C4: *les rdw,mq\n  -- C5: *lds rdw,mq\n  -- C6: mov mb,i\n  -- C7: mov mdw,i\n  -- C8: *enter iw,ib\n  leave_0 =\t\"C9\",\n  -- CA: *retf iw\n  -- CB: *retf\n  int3_0 =\t\"CC\",\n  int_1 =\t\"i.:nCDU\",\n  into_0 =\t\"CE\",\n  -- CF: *iret\n  -- D0: rol... mb,1\n  -- D1: rol... mdw,1\n  -- D2: rol... mb,cl\n  -- D3: rol... mb,cl\n  -- D4: *aam ib\n  -- D5: *aad ib\n  -- D6: *salc\n  -- D7: *xlat\n  -- D8-DF: floating point ops\n  -- E0: *loopne\n  -- E1: *loope\n  -- E2: *loop\n  -- E3: *jcxz, *jecxz\n  -- E4: *in Rb,ib\n  -- E5: *in Rdw,ib\n  -- E6: *out ib,Rb\n  -- E7: *out ib,Rdw\n  call_1 =\tx64 and \"mq:nFF2m|J.:E8nJ\" or \"md:FF2m|J.:E8J\",\n  jmp_1 =\tx64 and \"mq:nFF4m|J.:E9nJ\" or \"md:FF4m|J.:E9J\", -- short: EB\n  -- EA: *jmp iw:idw\n  -- EB: jmp ib\n  -- EC: *in Rb,dx\n  -- ED: *in Rdw,dx\n  -- EE: *out dx,Rb\n  -- EF: *out dx,Rdw\n  lock_0 =\t\"F0\",\n  int1_0 =\t\"F1\",\n  repne_0 =\t\"F2\",\n  repnz_0 =\t\"F2\",\n  rep_0 =\t\"F3\",\n  repe_0 =\t\"F3\",\n  repz_0 =\t\"F3\",\n  -- F4: *hlt\n  cmc_0 =\t\"F5\",\n  -- F6: test... mb,i; div... mb\n  -- F7: test... mdw,i; div... mdw\n  clc_0 =\t\"F8\",\n  stc_0 =\t\"F9\",\n  -- FA: *cli\n  cld_0 =\t\"FC\",\n  std_0 =\t\"FD\",\n  -- FE: inc... mb\n  -- FF: inc... mdw\n\n  -- misc ops\n  not_1 =\t\"m:F72m\",\n  neg_1 =\t\"m:F73m\",\n  mul_1 =\t\"m:F74m\",\n  imul_1 =\t\"m:F75m\",\n  div_1 =\t\"m:F76m\",\n  idiv_1 =\t\"m:F77m\",\n\n  imul_2 =\t\"rmqdw:0FAFrM|rIqdw:69rmI|rSqdw:6BrmS|riqdw:69rmi\",\n  imul_3 =\t\"rmIqdw:69rMI|rmSqdw:6BrMS|rmiqdw:69rMi\",\n\n  movzx_2 =\t\"rm/db:0FB6rM|rm/qb:|rm/wb:0FB6rM|rm/dw:0FB7rM|rm/qw:\",\n  movsx_2 =\t\"rm/db:0FBErM|rm/qb:|rm/wb:0FBErM|rm/dw:0FBFrM|rm/qw:\",\n\n  bswap_1 =\t\"rqd:0FC8r\",\n  bsf_2 =\t\"rmqdw:0FBCrM\",\n  bsr_2 =\t\"rmqdw:0FBDrM\",\n  bt_2 =\t\"mrqdw:0FA3Rm|miqdw:0FBA4mU\",\n  btc_2 =\t\"mrqdw:0FBBRm|miqdw:0FBA7mU\",\n  btr_2 =\t\"mrqdw:0FB3Rm|miqdw:0FBA6mU\",\n  bts_2 =\t\"mrqdw:0FABRm|miqdw:0FBA5mU\",\n\n  shld_3 =\t\"mriqdw:0FA4RmU|mrC/qq:0FA5Rm|mrC/dd:|mrC/ww:\",\n  shrd_3 =\t\"mriqdw:0FACRmU|mrC/qq:0FADRm|mrC/dd:|mrC/ww:\",\n\n  rdtsc_0 =\t\"0F31\", -- P1+\n  rdpmc_0 =\t\"0F33\", -- P6+\n  cpuid_0 =\t\"0FA2\", -- P1+\n\n  -- floating point ops\n  fst_1 =\t\"ff:DDD0r|xd:D92m|xq:nDD2m\",\n  fstp_1 =\t\"ff:DDD8r|xd:D93m|xq:nDD3m|xt:DB7m\",\n  fld_1 =\t\"ff:D9C0r|xd:D90m|xq:nDD0m|xt:DB5m\",\n\n  fpop_0 =\t\"DDD8\", -- Alias for fstp st0.\n\n  fist_1 =\t\"xw:nDF2m|xd:DB2m\",\n  fistp_1 =\t\"xw:nDF3m|xd:DB3m|xq:nDF7m\",\n  fild_1 =\t\"xw:nDF0m|xd:DB0m|xq:nDF5m\",\n\n  fxch_0 =\t\"D9C9\",\n  fxch_1 =\t\"ff:D9C8r\",\n  fxch_2 =\t\"fFf:D9C8r|Fff:D9C8R\",\n\n  fucom_1 =\t\"ff:DDE0r\",\n  fucom_2 =\t\"Fff:DDE0R\",\n  fucomp_1 =\t\"ff:DDE8r\",\n  fucomp_2 =\t\"Fff:DDE8R\",\n  fucomi_1 =\t\"ff:DBE8r\", -- P6+\n  fucomi_2 =\t\"Fff:DBE8R\", -- P6+\n  fucomip_1 =\t\"ff:DFE8r\", -- P6+\n  fucomip_2 =\t\"Fff:DFE8R\", -- P6+\n  fcomi_1 =\t\"ff:DBF0r\", -- P6+\n  fcomi_2 =\t\"Fff:DBF0R\", -- P6+\n  fcomip_1 =\t\"ff:DFF0r\", -- P6+\n  fcomip_2 =\t\"Fff:DFF0R\", -- P6+\n  fucompp_0 =\t\"DAE9\",\n  fcompp_0 =\t\"DED9\",\n\n  fldenv_1 =\t\"x.:D94m\",\n  fnstenv_1 =\t\"x.:D96m\",\n  fstenv_1 =\t\"x.:9BD96m\",\n  fldcw_1 =\t\"xw:nD95m\",\n  fstcw_1 =\t\"xw:n9BD97m\",\n  fnstcw_1 =\t\"xw:nD97m\",\n  fstsw_1 =\t\"Rw:n9BDFE0|xw:n9BDD7m\",\n  fnstsw_1 =\t\"Rw:nDFE0|xw:nDD7m\",\n  fclex_0 =\t\"9BDBE2\",\n  fnclex_0 =\t\"DBE2\",\n\n  fnop_0 =\t\"D9D0\",\n  -- D9D1-D9DF: unassigned\n\n  fchs_0 =\t\"D9E0\",\n  fabs_0 =\t\"D9E1\",\n  -- D9E2: unassigned\n  -- D9E3: unassigned\n  ftst_0 =\t\"D9E4\",\n  fxam_0 =\t\"D9E5\",\n  -- D9E6: unassigned\n  -- D9E7: unassigned\n  fld1_0 =\t\"D9E8\",\n  fldl2t_0 =\t\"D9E9\",\n  fldl2e_0 =\t\"D9EA\",\n  fldpi_0 =\t\"D9EB\",\n  fldlg2_0 =\t\"D9EC\",\n  fldln2_0 =\t\"D9ED\",\n  fldz_0 =\t\"D9EE\",\n  -- D9EF: unassigned\n\n  f2xm1_0 =\t\"D9F0\",\n  fyl2x_0 =\t\"D9F1\",\n  fptan_0 =\t\"D9F2\",\n  fpatan_0 =\t\"D9F3\",\n  fxtract_0 =\t\"D9F4\",\n  fprem1_0 =\t\"D9F5\",\n  fdecstp_0 =\t\"D9F6\",\n  fincstp_0 =\t\"D9F7\",\n  fprem_0 =\t\"D9F8\",\n  fyl2xp1_0 =\t\"D9F9\",\n  fsqrt_0 =\t\"D9FA\",\n  fsincos_0 =\t\"D9FB\",\n  frndint_0 =\t\"D9FC\",\n  fscale_0 =\t\"D9FD\",\n  fsin_0 =\t\"D9FE\",\n  fcos_0 =\t\"D9FF\",\n\n  -- SSE, SSE2\n  andnpd_2 =\t\"rmo:660F55rM\",\n  andnps_2 =\t\"rmo:0F55rM\",\n  andpd_2 =\t\"rmo:660F54rM\",\n  andps_2 =\t\"rmo:0F54rM\",\n  clflush_1 =\t\"x.:0FAE7m\",\n  cmppd_3 =\t\"rmio:660FC2rMU\",\n  cmpps_3 =\t\"rmio:0FC2rMU\",\n  cmpsd_3 =\t\"rrio:F20FC2rMU|rxi/oq:\",\n  cmpss_3 =\t\"rrio:F30FC2rMU|rxi/od:\",\n  comisd_2 =\t\"rro:660F2FrM|rx/oq:\",\n  comiss_2 =\t\"rro:0F2FrM|rx/od:\",\n  cvtdq2pd_2 =\t\"rro:F30FE6rM|rx/oq:\",\n  cvtdq2ps_2 =\t\"rmo:0F5BrM\",\n  cvtpd2dq_2 =\t\"rmo:F20FE6rM\",\n  cvtpd2ps_2 =\t\"rmo:660F5ArM\",\n  cvtpi2pd_2 =\t\"rx/oq:660F2ArM\",\n  cvtpi2ps_2 =\t\"rx/oq:0F2ArM\",\n  cvtps2dq_2 =\t\"rmo:660F5BrM\",\n  cvtps2pd_2 =\t\"rro:0F5ArM|rx/oq:\",\n  cvtsd2si_2 =\t\"rr/do:F20F2DrM|rr/qo:|rx/dq:|rxq:\",\n  cvtsd2ss_2 =\t\"rro:F20F5ArM|rx/oq:\",\n  cvtsi2sd_2 =\t\"rm/od:F20F2ArM|rm/oq:F20F2ArXM\",\n  cvtsi2ss_2 =\t\"rm/od:F30F2ArM|rm/oq:F30F2ArXM\",\n  cvtss2sd_2 =\t\"rro:F30F5ArM|rx/od:\",\n  cvtss2si_2 =\t\"rr/do:F30F2DrM|rr/qo:|rxd:|rx/qd:\",\n  cvttpd2dq_2 =\t\"rmo:660FE6rM\",\n  cvttps2dq_2 =\t\"rmo:F30F5BrM\",\n  cvttsd2si_2 =\t\"rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:\",\n  cvttss2si_2 =\t\"rr/do:F30F2CrM|rr/qo:|rxd:|rx/qd:\",\n  fxsave_1 =\t\"x.:0FAE0m\",\n  fxrstor_1 =\t\"x.:0FAE1m\",\n  ldmxcsr_1 =\t\"xd:0FAE2m\",\n  lfence_0 =\t\"0FAEE8\",\n  maskmovdqu_2 = \"rro:660FF7rM\",\n  mfence_0 =\t\"0FAEF0\",\n  movapd_2 =\t\"rmo:660F28rM|mro:660F29Rm\",\n  movaps_2 =\t\"rmo:0F28rM|mro:0F29Rm\",\n  movd_2 =\t\"rm/od:660F6ErM|rm/oq:660F6ErXM|mr/do:660F7ERm|mr/qo:\",\n  movdqa_2 =\t\"rmo:660F6FrM|mro:660F7FRm\",\n  movdqu_2 =\t\"rmo:F30F6FrM|mro:F30F7FRm\",\n  movhlps_2 =\t\"rro:0F12rM\",\n  movhpd_2 =\t\"rx/oq:660F16rM|xr/qo:n660F17Rm\",\n  movhps_2 =\t\"rx/oq:0F16rM|xr/qo:n0F17Rm\",\n  movlhps_2 =\t\"rro:0F16rM\",\n  movlpd_2 =\t\"rx/oq:660F12rM|xr/qo:n660F13Rm\",\n  movlps_2 =\t\"rx/oq:0F12rM|xr/qo:n0F13Rm\",\n  movmskpd_2 =\t\"rr/do:660F50rM\",\n  movmskps_2 =\t\"rr/do:0F50rM\",\n  movntdq_2 =\t\"xro:660FE7Rm\",\n  movnti_2 =\t\"xrqd:0FC3Rm\",\n  movntpd_2 =\t\"xro:660F2BRm\",\n  movntps_2 =\t\"xro:0F2BRm\",\n  movq_2 =\t\"rro:F30F7ErM|rx/oq:|xr/qo:n660FD6Rm\",\n  movsd_2 =\t\"rro:F20F10rM|rx/oq:|xr/qo:nF20F11Rm\",\n  movss_2 =\t\"rro:F30F10rM|rx/od:|xr/do:F30F11Rm\",\n  movupd_2 =\t\"rmo:660F10rM|mro:660F11Rm\",\n  movups_2 =\t\"rmo:0F10rM|mro:0F11Rm\",\n  orpd_2 =\t\"rmo:660F56rM\",\n  orps_2 =\t\"rmo:0F56rM\",\n  pause_0 =\t\"F390\",\n  pextrw_3 =\t\"rri/do:660FC5rMU|xri/wo:660F3A15nRmU\", -- Mem op: SSE4.1 only.\n  pinsrw_3 =\t\"rri/od:660FC4rMU|rxi/ow:\",\n  pmovmskb_2 =\t\"rr/do:660FD7rM\",\n  prefetchnta_1 = \"xb:n0F180m\",\n  prefetcht0_1 = \"xb:n0F181m\",\n  prefetcht1_1 = \"xb:n0F182m\",\n  prefetcht2_1 = \"xb:n0F183m\",\n  pshufd_3 =\t\"rmio:660F70rMU\",\n  pshufhw_3 =\t\"rmio:F30F70rMU\",\n  pshuflw_3 =\t\"rmio:F20F70rMU\",\n  pslld_2 =\t\"rmo:660FF2rM|rio:660F726mU\",\n  pslldq_2 =\t\"rio:660F737mU\",\n  psllq_2 =\t\"rmo:660FF3rM|rio:660F736mU\",\n  psllw_2 =\t\"rmo:660FF1rM|rio:660F716mU\",\n  psrad_2 =\t\"rmo:660FE2rM|rio:660F724mU\",\n  psraw_2 =\t\"rmo:660FE1rM|rio:660F714mU\",\n  psrld_2 =\t\"rmo:660FD2rM|rio:660F722mU\",\n  psrldq_2 =\t\"rio:660F733mU\",\n  psrlq_2 =\t\"rmo:660FD3rM|rio:660F732mU\",\n  psrlw_2 =\t\"rmo:660FD1rM|rio:660F712mU\",\n  rcpps_2 =\t\"rmo:0F53rM\",\n  rcpss_2 =\t\"rro:F30F53rM|rx/od:\",\n  rsqrtps_2 =\t\"rmo:0F52rM\",\n  rsqrtss_2 =\t\"rmo:F30F52rM\",\n  sfence_0 =\t\"0FAEF8\",\n  shufpd_3 =\t\"rmio:660FC6rMU\",\n  shufps_3 =\t\"rmio:0FC6rMU\",\n  stmxcsr_1 =   \"xd:0FAE3m\",\n  ucomisd_2 =\t\"rro:660F2ErM|rx/oq:\",\n  ucomiss_2 =\t\"rro:0F2ErM|rx/od:\",\n  unpckhpd_2 =\t\"rmo:660F15rM\",\n  unpckhps_2 =\t\"rmo:0F15rM\",\n  unpcklpd_2 =\t\"rmo:660F14rM\",\n  unpcklps_2 =\t\"rmo:0F14rM\",\n  xorpd_2 =\t\"rmo:660F57rM\",\n  xorps_2 =\t\"rmo:0F57rM\",\n\n  -- SSE3 ops\n  fisttp_1 =\t\"xw:nDF1m|xd:DB1m|xq:nDD1m\",\n  addsubpd_2 =\t\"rmo:660FD0rM\",\n  addsubps_2 =\t\"rmo:F20FD0rM\",\n  haddpd_2 =\t\"rmo:660F7CrM\",\n  haddps_2 =\t\"rmo:F20F7CrM\",\n  hsubpd_2 =\t\"rmo:660F7DrM\",\n  hsubps_2 =\t\"rmo:F20F7DrM\",\n  lddqu_2 =\t\"rxo:F20FF0rM\",\n  movddup_2 =\t\"rmo:F20F12rM\",\n  movshdup_2 =\t\"rmo:F30F16rM\",\n  movsldup_2 =\t\"rmo:F30F12rM\",\n\n  -- SSSE3 ops\n  pabsb_2 =\t\"rmo:660F381CrM\",\n  pabsd_2 =\t\"rmo:660F381ErM\",\n  pabsw_2 =\t\"rmo:660F381DrM\",\n  palignr_3 =\t\"rmio:660F3A0FrMU\",\n  phaddd_2 =\t\"rmo:660F3802rM\",\n  phaddsw_2 =\t\"rmo:660F3803rM\",\n  phaddw_2 =\t\"rmo:660F3801rM\",\n  phsubd_2 =\t\"rmo:660F3806rM\",\n  phsubsw_2 =\t\"rmo:660F3807rM\",\n  phsubw_2 =\t\"rmo:660F3805rM\",\n  pmaddubsw_2 =\t\"rmo:660F3804rM\",\n  pmulhrsw_2 =\t\"rmo:660F380BrM\",\n  pshufb_2 =\t\"rmo:660F3800rM\",\n  psignb_2 =\t\"rmo:660F3808rM\",\n  psignd_2 =\t\"rmo:660F380ArM\",\n  psignw_2 =\t\"rmo:660F3809rM\",\n\n  -- SSE4.1 ops\n  blendpd_3 =\t\"rmio:660F3A0DrMU\",\n  blendps_3 =\t\"rmio:660F3A0CrMU\",\n  blendvpd_3 =\t\"rmRo:660F3815rM\",\n  blendvps_3 =\t\"rmRo:660F3814rM\",\n  dppd_3 =\t\"rmio:660F3A41rMU\",\n  dpps_3 =\t\"rmio:660F3A40rMU\",\n  extractps_3 =\t\"mri/do:660F3A17RmU|rri/qo:660F3A17RXmU\",\n  insertps_3 =\t\"rrio:660F3A41rMU|rxi/od:\",\n  movntdqa_2 =\t\"rxo:660F382ArM\",\n  mpsadbw_3 =\t\"rmio:660F3A42rMU\",\n  packusdw_2 =\t\"rmo:660F382BrM\",\n  pblendvb_3 =\t\"rmRo:660F3810rM\",\n  pblendw_3 =\t\"rmio:660F3A0ErMU\",\n  pcmpeqq_2 =\t\"rmo:660F3829rM\",\n  pextrb_3 =\t\"rri/do:660F3A14nRmU|rri/qo:|xri/bo:\",\n  pextrd_3 =\t\"mri/do:660F3A16RmU\",\n  pextrq_3 =\t\"mri/qo:660F3A16RmU\",\n  -- pextrw is SSE2, mem operand is SSE4.1 only\n  phminposuw_2 = \"rmo:660F3841rM\",\n  pinsrb_3 =\t\"rri/od:660F3A20nrMU|rxi/ob:\",\n  pinsrd_3 =\t\"rmi/od:660F3A22rMU\",\n  pinsrq_3 =\t\"rmi/oq:660F3A22rXMU\",\n  pmaxsb_2 =\t\"rmo:660F383CrM\",\n  pmaxsd_2 =\t\"rmo:660F383DrM\",\n  pmaxud_2 =\t\"rmo:660F383FrM\",\n  pmaxuw_2 =\t\"rmo:660F383ErM\",\n  pminsb_2 =\t\"rmo:660F3838rM\",\n  pminsd_2 =\t\"rmo:660F3839rM\",\n  pminud_2 =\t\"rmo:660F383BrM\",\n  pminuw_2 =\t\"rmo:660F383ArM\",\n  pmovsxbd_2 =\t\"rro:660F3821rM|rx/od:\",\n  pmovsxbq_2 =\t\"rro:660F3822rM|rx/ow:\",\n  pmovsxbw_2 =\t\"rro:660F3820rM|rx/oq:\",\n  pmovsxdq_2 =\t\"rro:660F3825rM|rx/oq:\",\n  pmovsxwd_2 =\t\"rro:660F3823rM|rx/oq:\",\n  pmovsxwq_2 =\t\"rro:660F3824rM|rx/od:\",\n  pmovzxbd_2 =\t\"rro:660F3831rM|rx/od:\",\n  pmovzxbq_2 =\t\"rro:660F3832rM|rx/ow:\",\n  pmovzxbw_2 =\t\"rro:660F3830rM|rx/oq:\",\n  pmovzxdq_2 =\t\"rro:660F3835rM|rx/oq:\",\n  pmovzxwd_2 =\t\"rro:660F3833rM|rx/oq:\",\n  pmovzxwq_2 =\t\"rro:660F3834rM|rx/od:\",\n  pmuldq_2 =\t\"rmo:660F3828rM\",\n  pmulld_2 =\t\"rmo:660F3840rM\",\n  ptest_2 =\t\"rmo:660F3817rM\",\n  roundpd_3 =\t\"rmio:660F3A09rMU\",\n  roundps_3 =\t\"rmio:660F3A08rMU\",\n  roundsd_3 =\t\"rrio:660F3A0BrMU|rxi/oq:\",\n  roundss_3 =\t\"rrio:660F3A0ArMU|rxi/od:\",\n\n  -- SSE4.2 ops\n  crc32_2 =\t\"rmqd:F20F38F1rM|rm/dw:66F20F38F1rM|rm/db:F20F38F0rM|rm/qb:\",\n  pcmpestri_3 =\t\"rmio:660F3A61rMU\",\n  pcmpestrm_3 =\t\"rmio:660F3A60rMU\",\n  pcmpgtq_2 =\t\"rmo:660F3837rM\",\n  pcmpistri_3 =\t\"rmio:660F3A63rMU\",\n  pcmpistrm_3 =\t\"rmio:660F3A62rMU\",\n  popcnt_2 =\t\"rmqdw:F30FB8rM\",\n\n  -- SSE4a\n  extrq_2 =\t\"rro:660F79rM\",\n  extrq_3 =\t\"riio:660F780mUU\",\n  insertq_2 =\t\"rro:F20F79rM\",\n  insertq_4 =\t\"rriio:F20F78rMUU\",\n  lzcnt_2 =\t\"rmqdw:F30FBDrM\",\n  movntsd_2 =\t\"xr/qo:nF20F2BRm\",\n  movntss_2 =\t\"xr/do:F30F2BRm\",\n  -- popcnt is also in SSE4.2\n\n  -- AES-NI\n  aesdec_2 =\t\"rmo:660F38DErM\",\n  aesdeclast_2 = \"rmo:660F38DFrM\",\n  aesenc_2 =\t\"rmo:660F38DCrM\",\n  aesenclast_2 = \"rmo:660F38DDrM\",\n  aesimc_2 =\t\"rmo:660F38DBrM\",\n  aeskeygenassist_3 = \"rmio:660F3ADFrMU\",\n  pclmulqdq_3 =\t\"rmio:660F3A44rMU\",\n\n   -- AVX FP ops\n  vaddsubpd_3 =\t\"rrmoy:660FVD0rM\",\n  vaddsubps_3 =\t\"rrmoy:F20FVD0rM\",\n  vandpd_3 =\t\"rrmoy:660FV54rM\",\n  vandps_3 =\t\"rrmoy:0FV54rM\",\n  vandnpd_3 =\t\"rrmoy:660FV55rM\",\n  vandnps_3 =\t\"rrmoy:0FV55rM\",\n  vblendpd_4 =\t\"rrmioy:660F3AV0DrMU\",\n  vblendps_4 =\t\"rrmioy:660F3AV0CrMU\",\n  vblendvpd_4 =\t\"rrmroy:660F3AV4BrMs\",\n  vblendvps_4 =\t\"rrmroy:660F3AV4ArMs\",\n  vbroadcastf128_2 = \"rx/yo:660F38u1ArM\",\n  vcmppd_4 =\t\"rrmioy:660FVC2rMU\",\n  vcmpps_4 =\t\"rrmioy:0FVC2rMU\",\n  vcmpsd_4 =\t\"rrrio:F20FVC2rMU|rrxi/ooq:\",\n  vcmpss_4 =\t\"rrrio:F30FVC2rMU|rrxi/ood:\",\n  vcomisd_2 =\t\"rro:660Fu2FrM|rx/oq:\",\n  vcomiss_2 =\t\"rro:0Fu2FrM|rx/od:\",\n  vcvtdq2pd_2 =\t\"rro:F30FuE6rM|rx/oq:|rm/yo:\",\n  vcvtdq2ps_2 =\t\"rmoy:0Fu5BrM\",\n  vcvtpd2dq_2 =\t\"rmoy:F20FuE6rM\",\n  vcvtpd2ps_2 =\t\"rmoy:660Fu5ArM\",\n  vcvtps2dq_2 =\t\"rmoy:660Fu5BrM\",\n  vcvtps2pd_2 =\t\"rro:0Fu5ArM|rx/oq:|rm/yo:\",\n  vcvtsd2si_2 =\t\"rr/do:F20Fu2DrM|rx/dq:|rr/qo:|rxq:\",\n  vcvtsd2ss_3 =\t\"rrro:F20FV5ArM|rrx/ooq:\",\n  vcvtsi2sd_3 =\t\"rrm/ood:F20FV2ArM|rrm/ooq:F20FVX2ArM\",\n  vcvtsi2ss_3 =\t\"rrm/ood:F30FV2ArM|rrm/ooq:F30FVX2ArM\",\n  vcvtss2sd_3 =\t\"rrro:F30FV5ArM|rrx/ood:\",\n  vcvtss2si_2 =\t\"rr/do:F30Fu2DrM|rxd:|rr/qo:|rx/qd:\",\n  vcvttpd2dq_2 = \"rmo:660FuE6rM|rm/oy:660FuLE6rM\",\n  vcvttps2dq_2 = \"rmoy:F30Fu5BrM\",\n  vcvttsd2si_2 = \"rr/do:F20Fu2CrM|rx/dq:|rr/qo:|rxq:\",\n  vcvttss2si_2 = \"rr/do:F30Fu2CrM|rxd:|rr/qo:|rx/qd:\",\n  vdppd_4 =\t\"rrmio:660F3AV41rMU\",\n  vdpps_4 =\t\"rrmioy:660F3AV40rMU\",\n  vextractf128_3 = \"mri/oy:660F3AuL19RmU\",\n  vextractps_3 = \"mri/do:660F3Au17RmU\",\n  vhaddpd_3 =\t\"rrmoy:660FV7CrM\",\n  vhaddps_3 =\t\"rrmoy:F20FV7CrM\",\n  vhsubpd_3 =\t\"rrmoy:660FV7DrM\",\n  vhsubps_3 =\t\"rrmoy:F20FV7DrM\",\n  vinsertf128_4 = \"rrmi/yyo:660F3AV18rMU\",\n  vinsertps_4 =\t\"rrrio:660F3AV21rMU|rrxi/ood:\",\n  vldmxcsr_1 =\t\"xd:0FuAE2m\",\n  vmaskmovps_3 = \"rrxoy:660F38V2CrM|xrroy:660F38V2ERm\",\n  vmaskmovpd_3 = \"rrxoy:660F38V2DrM|xrroy:660F38V2FRm\",\n  vmovapd_2 =\t\"rmoy:660Fu28rM|mroy:660Fu29Rm\",\n  vmovaps_2 =\t\"rmoy:0Fu28rM|mroy:0Fu29Rm\",\n  vmovd_2 =\t\"rm/od:660Fu6ErM|rm/oq:660FuX6ErM|mr/do:660Fu7ERm|mr/qo:\",\n  vmovq_2 =\t\"rro:F30Fu7ErM|rx/oq:|xr/qo:660FuD6Rm\",\n  vmovddup_2 =\t\"rmy:F20Fu12rM|rro:|rx/oq:\",\n  vmovhlps_3 =\t\"rrro:0FV12rM\",\n  vmovhpd_2 =\t\"xr/qo:660Fu17Rm\",\n  vmovhpd_3 =\t\"rrx/ooq:660FV16rM\",\n  vmovhps_2 =\t\"xr/qo:0Fu17Rm\",\n  vmovhps_3 =\t\"rrx/ooq:0FV16rM\",\n  vmovlhps_3 =\t\"rrro:0FV16rM\",\n  vmovlpd_2 =\t\"xr/qo:660Fu13Rm\",\n  vmovlpd_3 =\t\"rrx/ooq:660FV12rM\",\n  vmovlps_2 =\t\"xr/qo:0Fu13Rm\",\n  vmovlps_3 =\t\"rrx/ooq:0FV12rM\",\n  vmovmskpd_2 =\t\"rr/do:660Fu50rM|rr/dy:660FuL50rM\",\n  vmovmskps_2 =\t\"rr/do:0Fu50rM|rr/dy:0FuL50rM\",\n  vmovntpd_2 =\t\"xroy:660Fu2BRm\",\n  vmovntps_2 =\t\"xroy:0Fu2BRm\",\n  vmovsd_2 =\t\"rx/oq:F20Fu10rM|xr/qo:F20Fu11Rm\",\n  vmovsd_3 =\t\"rrro:F20FV10rM\",\n  vmovshdup_2 =\t\"rmoy:F30Fu16rM\",\n  vmovsldup_2 =\t\"rmoy:F30Fu12rM\",\n  vmovss_2 =\t\"rx/od:F30Fu10rM|xr/do:F30Fu11Rm\",\n  vmovss_3 =\t\"rrro:F30FV10rM\",\n  vmovupd_2 =\t\"rmoy:660Fu10rM|mroy:660Fu11Rm\",\n  vmovups_2 =\t\"rmoy:0Fu10rM|mroy:0Fu11Rm\",\n  vorpd_3 =\t\"rrmoy:660FV56rM\",\n  vorps_3 =\t\"rrmoy:0FV56rM\",\n  vpermilpd_3 =\t\"rrmoy:660F38V0DrM|rmioy:660F3Au05rMU\",\n  vpermilps_3 =\t\"rrmoy:660F38V0CrM|rmioy:660F3Au04rMU\",\n  vperm2f128_4 = \"rrmiy:660F3AV06rMU\",\n  vptestpd_2 =\t\"rmoy:660F38u0FrM\",\n  vptestps_2 =\t\"rmoy:660F38u0ErM\",\n  vrcpps_2 =\t\"rmoy:0Fu53rM\",\n  vrcpss_3 =\t\"rrro:F30FV53rM|rrx/ood:\",\n  vrsqrtps_2 =\t\"rmoy:0Fu52rM\",\n  vrsqrtss_3 =\t\"rrro:F30FV52rM|rrx/ood:\",\n  vroundpd_3 =\t\"rmioy:660F3Au09rMU\",\n  vroundps_3 =\t\"rmioy:660F3Au08rMU\",\n  vroundsd_4 =\t\"rrrio:660F3AV0BrMU|rrxi/ooq:\",\n  vroundss_4 =\t\"rrrio:660F3AV0ArMU|rrxi/ood:\",\n  vshufpd_4 =\t\"rrmioy:660FVC6rMU\",\n  vshufps_4 =\t\"rrmioy:0FVC6rMU\",\n  vsqrtps_2 =\t\"rmoy:0Fu51rM\",\n  vsqrtss_2 =\t\"rro:F30Fu51rM|rx/od:\",\n  vsqrtpd_2 =\t\"rmoy:660Fu51rM\",\n  vsqrtsd_2 =\t\"rro:F20Fu51rM|rx/oq:\",\n  vstmxcsr_1 =\t\"xd:0FuAE3m\",\n  vucomisd_2 =\t\"rro:660Fu2ErM|rx/oq:\",\n  vucomiss_2 =\t\"rro:0Fu2ErM|rx/od:\",\n  vunpckhpd_3 =\t\"rrmoy:660FV15rM\",\n  vunpckhps_3 =\t\"rrmoy:0FV15rM\",\n  vunpcklpd_3 =\t\"rrmoy:660FV14rM\",\n  vunpcklps_3 =\t\"rrmoy:0FV14rM\",\n  vxorpd_3 =\t\"rrmoy:660FV57rM\",\n  vxorps_3 =\t\"rrmoy:0FV57rM\",\n  vzeroall_0 =\t\"0FuL77\",\n  vzeroupper_0 = \"0Fu77\",\n\n  -- AVX2 FP ops\n  vbroadcastss_2 = \"rx/od:660F38u18rM|rx/yd:|rro:|rr/yo:\",\n  vbroadcastsd_2 = \"rx/yq:660F38u19rM|rr/yo:\",\n  -- *vgather* (!vsib)\n  vpermpd_3 =\t\"rmiy:660F3AuX01rMU\",\n  vpermps_3 =\t\"rrmy:660F38V16rM\",\n\n  -- AVX, AVX2 integer ops\n  -- In general, xmm requires AVX, ymm requires AVX2.\n  vaesdec_3 =  \"rrmo:660F38VDErM\",\n  vaesdeclast_3 = \"rrmo:660F38VDFrM\",\n  vaesenc_3 =  \"rrmo:660F38VDCrM\",\n  vaesenclast_3 = \"rrmo:660F38VDDrM\",\n  vaesimc_2 =  \"rmo:660F38uDBrM\",\n  vaeskeygenassist_3 = \"rmio:660F3AuDFrMU\",\n  vlddqu_2 =\t\"rxoy:F20FuF0rM\",\n  vmaskmovdqu_2 = \"rro:660FuF7rM\",\n  vmovdqa_2 =\t\"rmoy:660Fu6FrM|mroy:660Fu7FRm\",\n  vmovdqu_2 =\t\"rmoy:F30Fu6FrM|mroy:F30Fu7FRm\",\n  vmovntdq_2 =\t\"xroy:660FuE7Rm\",\n  vmovntdqa_2 =\t\"rxoy:660F38u2ArM\",\n  vmpsadbw_4 =\t\"rrmioy:660F3AV42rMU\",\n  vpabsb_2 =\t\"rmoy:660F38u1CrM\",\n  vpabsd_2 =\t\"rmoy:660F38u1ErM\",\n  vpabsw_2 =\t\"rmoy:660F38u1DrM\",\n  vpackusdw_3 =\t\"rrmoy:660F38V2BrM\",\n  vpalignr_4 =\t\"rrmioy:660F3AV0FrMU\",\n  vpblendvb_4 =\t\"rrmroy:660F3AV4CrMs\",\n  vpblendw_4 =\t\"rrmioy:660F3AV0ErMU\",\n  vpclmulqdq_4 = \"rrmio:660F3AV44rMU\",\n  vpcmpeqq_3 =\t\"rrmoy:660F38V29rM\",\n  vpcmpestri_3 = \"rmio:660F3Au61rMU\",\n  vpcmpestrm_3 = \"rmio:660F3Au60rMU\",\n  vpcmpgtq_3 =\t\"rrmoy:660F38V37rM\",\n  vpcmpistri_3 = \"rmio:660F3Au63rMU\",\n  vpcmpistrm_3 = \"rmio:660F3Au62rMU\",\n  vpextrb_3 =\t\"rri/do:660F3Au14nRmU|rri/qo:|xri/bo:\",\n  vpextrw_3 =\t\"rri/do:660FuC5rMU|xri/wo:660F3Au15nRmU\",\n  vpextrd_3 =\t\"mri/do:660F3Au16RmU\",\n  vpextrq_3 =\t\"mri/qo:660F3Au16RmU\",\n  vphaddw_3 =\t\"rrmoy:660F38V01rM\",\n  vphaddd_3 =\t\"rrmoy:660F38V02rM\",\n  vphaddsw_3 =\t\"rrmoy:660F38V03rM\",\n  vphminposuw_2 = \"rmo:660F38u41rM\",\n  vphsubw_3 =\t\"rrmoy:660F38V05rM\",\n  vphsubd_3 =\t\"rrmoy:660F38V06rM\",\n  vphsubsw_3 =\t\"rrmoy:660F38V07rM\",\n  vpinsrb_4 =\t\"rrri/ood:660F3AV20rMU|rrxi/oob:\",\n  vpinsrw_4 =\t\"rrri/ood:660FVC4rMU|rrxi/oow:\",\n  vpinsrd_4 =\t\"rrmi/ood:660F3AV22rMU\",\n  vpinsrq_4 =\t\"rrmi/ooq:660F3AVX22rMU\",\n  vpmaddubsw_3 = \"rrmoy:660F38V04rM\",\n  vpmaxsb_3 =\t\"rrmoy:660F38V3CrM\",\n  vpmaxsd_3 =\t\"rrmoy:660F38V3DrM\",\n  vpmaxuw_3 =\t\"rrmoy:660F38V3ErM\",\n  vpmaxud_3 =\t\"rrmoy:660F38V3FrM\",\n  vpminsb_3 =\t\"rrmoy:660F38V38rM\",\n  vpminsd_3 =\t\"rrmoy:660F38V39rM\",\n  vpminuw_3 =\t\"rrmoy:660F38V3ArM\",\n  vpminud_3 =\t\"rrmoy:660F38V3BrM\",\n  vpmovmskb_2 =\t\"rr/do:660FuD7rM|rr/dy:660FuLD7rM\",\n  vpmovsxbw_2 =\t\"rroy:660F38u20rM|rx/oq:|rx/yo:\",\n  vpmovsxbd_2 =\t\"rroy:660F38u21rM|rx/od:|rx/yq:\",\n  vpmovsxbq_2 =\t\"rroy:660F38u22rM|rx/ow:|rx/yd:\",\n  vpmovsxwd_2 =\t\"rroy:660F38u23rM|rx/oq:|rx/yo:\",\n  vpmovsxwq_2 =\t\"rroy:660F38u24rM|rx/od:|rx/yq:\",\n  vpmovsxdq_2 =\t\"rroy:660F38u25rM|rx/oq:|rx/yo:\",\n  vpmovzxbw_2 =\t\"rroy:660F38u30rM|rx/oq:|rx/yo:\",\n  vpmovzxbd_2 =\t\"rroy:660F38u31rM|rx/od:|rx/yq:\",\n  vpmovzxbq_2 =\t\"rroy:660F38u32rM|rx/ow:|rx/yd:\",\n  vpmovzxwd_2 =\t\"rroy:660F38u33rM|rx/oq:|rx/yo:\",\n  vpmovzxwq_2 =\t\"rroy:660F38u34rM|rx/od:|rx/yq:\",\n  vpmovzxdq_2 =\t\"rroy:660F38u35rM|rx/oq:|rx/yo:\",\n  vpmuldq_3 =\t\"rrmoy:660F38V28rM\",\n  vpmulhrsw_3 =\t\"rrmoy:660F38V0BrM\",\n  vpmulld_3 =\t\"rrmoy:660F38V40rM\",\n  vpshufb_3 =\t\"rrmoy:660F38V00rM\",\n  vpshufd_3 =\t\"rmioy:660Fu70rMU\",\n  vpshufhw_3 =\t\"rmioy:F30Fu70rMU\",\n  vpshuflw_3 =\t\"rmioy:F20Fu70rMU\",\n  vpsignb_3 =\t\"rrmoy:660F38V08rM\",\n  vpsignw_3 =\t\"rrmoy:660F38V09rM\",\n  vpsignd_3 =\t\"rrmoy:660F38V0ArM\",\n  vpslldq_3 =\t\"rrioy:660Fv737mU\",\n  vpsllw_3 =\t\"rrmoy:660FVF1rM|rrioy:660Fv716mU\",\n  vpslld_3 =\t\"rrmoy:660FVF2rM|rrioy:660Fv726mU\",\n  vpsllq_3 =\t\"rrmoy:660FVF3rM|rrioy:660Fv736mU\",\n  vpsraw_3 =\t\"rrmoy:660FVE1rM|rrioy:660Fv714mU\",\n  vpsrad_3 =\t\"rrmoy:660FVE2rM|rrioy:660Fv724mU\",\n  vpsrldq_3 =\t\"rrioy:660Fv733mU\",\n  vpsrlw_3 =\t\"rrmoy:660FVD1rM|rrioy:660Fv712mU\",\n  vpsrld_3 =\t\"rrmoy:660FVD2rM|rrioy:660Fv722mU\",\n  vpsrlq_3 =\t\"rrmoy:660FVD3rM|rrioy:660Fv732mU\",\n  vptest_2 =\t\"rmoy:660F38u17rM\",\n\n  -- AVX2 integer ops\n  vbroadcasti128_2 = \"rx/yo:660F38u5ArM\",\n  vinserti128_4 = \"rrmi/yyo:660F3AV38rMU\",\n  vextracti128_3 = \"mri/oy:660F3AuL39RmU\",\n  vpblendd_4 =\t\"rrmioy:660F3AV02rMU\",\n  vpbroadcastb_2 = \"rro:660F38u78rM|rx/ob:|rr/yo:|rx/yb:\",\n  vpbroadcastw_2 = \"rro:660F38u79rM|rx/ow:|rr/yo:|rx/yw:\",\n  vpbroadcastd_2 = \"rro:660F38u58rM|rx/od:|rr/yo:|rx/yd:\",\n  vpbroadcastq_2 = \"rro:660F38u59rM|rx/oq:|rr/yo:|rx/yq:\",\n  vpermd_3 =\t\"rrmy:660F38V36rM\",\n  vpermq_3 =\t\"rmiy:660F3AuX00rMU\",\n  -- *vpgather* (!vsib)\n  vperm2i128_4 = \"rrmiy:660F3AV46rMU\",\n  vpmaskmovd_3 = \"rrxoy:660F38V8CrM|xrroy:660F38V8ERm\",\n  vpmaskmovq_3 = \"rrxoy:660F38VX8CrM|xrroy:660F38VX8ERm\",\n  vpsllvd_3 =\t\"rrmoy:660F38V47rM\",\n  vpsllvq_3 =\t\"rrmoy:660F38VX47rM\",\n  vpsravd_3 =\t\"rrmoy:660F38V46rM\",\n  vpsrlvd_3 =\t\"rrmoy:660F38V45rM\",\n  vpsrlvq_3 =\t\"rrmoy:660F38VX45rM\",\n\n  -- Intel ADX\n  adcx_2 =\t\"rmqd:660F38F6rM\",\n  adox_2 =\t\"rmqd:F30F38F6rM\",\n\n  -- BMI1\n  andn_3 =\t\"rrmqd:0F38VF2rM\",\n  bextr_3 =\t\"rmrqd:0F38wF7rM\",\n  blsi_2 =\t\"rmqd:0F38vF33m\",\n  blsmsk_2 =\t\"rmqd:0F38vF32m\",\n  blsr_2 =\t\"rmqd:0F38vF31m\",\n  tzcnt_2 =\t\"rmqdw:F30FBCrM\",\n\n  -- BMI2\n  bzhi_3 =\t\"rmrqd:0F38wF5rM\",\n  mulx_3 =\t\"rrmqd:F20F38VF6rM\",\n  pdep_3 =\t\"rrmqd:F20F38VF5rM\",\n  pext_3 =\t\"rrmqd:F30F38VF5rM\",\n  rorx_3 =\t\"rmSqd:F20F3AuF0rMS\",\n  sarx_3 =\t\"rmrqd:F30F38wF7rM\",\n  shrx_3 =\t\"rmrqd:F20F38wF7rM\",\n  shlx_3 =\t\"rmrqd:660F38wF7rM\",\n\n  -- FMA3\n  vfmaddsub132pd_3 = \"rrmoy:660F38VX96rM\",\n  vfmaddsub132ps_3 = \"rrmoy:660F38V96rM\",\n  vfmaddsub213pd_3 = \"rrmoy:660F38VXA6rM\",\n  vfmaddsub213ps_3 = \"rrmoy:660F38VA6rM\",\n  vfmaddsub231pd_3 = \"rrmoy:660F38VXB6rM\",\n  vfmaddsub231ps_3 = \"rrmoy:660F38VB6rM\",\n\n  vfmsubadd132pd_3 = \"rrmoy:660F38VX97rM\",\n  vfmsubadd132ps_3 = \"rrmoy:660F38V97rM\",\n  vfmsubadd213pd_3 = \"rrmoy:660F38VXA7rM\",\n  vfmsubadd213ps_3 = \"rrmoy:660F38VA7rM\",\n  vfmsubadd231pd_3 = \"rrmoy:660F38VXB7rM\",\n  vfmsubadd231ps_3 = \"rrmoy:660F38VB7rM\",\n\n  vfmadd132pd_3 = \"rrmoy:660F38VX98rM\",\n  vfmadd132ps_3 = \"rrmoy:660F38V98rM\",\n  vfmadd132sd_3 = \"rrro:660F38VX99rM|rrx/ooq:\",\n  vfmadd132ss_3 = \"rrro:660F38V99rM|rrx/ood:\",\n  vfmadd213pd_3 = \"rrmoy:660F38VXA8rM\",\n  vfmadd213ps_3 = \"rrmoy:660F38VA8rM\",\n  vfmadd213sd_3 = \"rrro:660F38VXA9rM|rrx/ooq:\",\n  vfmadd213ss_3 = \"rrro:660F38VA9rM|rrx/ood:\",\n  vfmadd231pd_3 = \"rrmoy:660F38VXB8rM\",\n  vfmadd231ps_3 = \"rrmoy:660F38VB8rM\",\n  vfmadd231sd_3 = \"rrro:660F38VXB9rM|rrx/ooq:\",\n  vfmadd231ss_3 = \"rrro:660F38VB9rM|rrx/ood:\",\n\n  vfmsub132pd_3 = \"rrmoy:660F38VX9ArM\",\n  vfmsub132ps_3 = \"rrmoy:660F38V9ArM\",\n  vfmsub132sd_3 = \"rrro:660F38VX9BrM|rrx/ooq:\",\n  vfmsub132ss_3 = \"rrro:660F38V9BrM|rrx/ood:\",\n  vfmsub213pd_3 = \"rrmoy:660F38VXAArM\",\n  vfmsub213ps_3 = \"rrmoy:660F38VAArM\",\n  vfmsub213sd_3 = \"rrro:660F38VXABrM|rrx/ooq:\",\n  vfmsub213ss_3 = \"rrro:660F38VABrM|rrx/ood:\",\n  vfmsub231pd_3 = \"rrmoy:660F38VXBArM\",\n  vfmsub231ps_3 = \"rrmoy:660F38VBArM\",\n  vfmsub231sd_3 = \"rrro:660F38VXBBrM|rrx/ooq:\",\n  vfmsub231ss_3 = \"rrro:660F38VBBrM|rrx/ood:\",\n\n  vfnmadd132pd_3 = \"rrmoy:660F38VX9CrM\",\n  vfnmadd132ps_3 = \"rrmoy:660F38V9CrM\",\n  vfnmadd132sd_3 = \"rrro:660F38VX9DrM|rrx/ooq:\",\n  vfnmadd132ss_3 = \"rrro:660F38V9DrM|rrx/ood:\",\n  vfnmadd213pd_3 = \"rrmoy:660F38VXACrM\",\n  vfnmadd213ps_3 = \"rrmoy:660F38VACrM\",\n  vfnmadd213sd_3 = \"rrro:660F38VXADrM|rrx/ooq:\",\n  vfnmadd213ss_3 = \"rrro:660F38VADrM|rrx/ood:\",\n  vfnmadd231pd_3 = \"rrmoy:660F38VXBCrM\",\n  vfnmadd231ps_3 = \"rrmoy:660F38VBCrM\",\n  vfnmadd231sd_3 = \"rrro:660F38VXBDrM|rrx/ooq:\",\n  vfnmadd231ss_3 = \"rrro:660F38VBDrM|rrx/ood:\",\n\n  vfnmsub132pd_3 = \"rrmoy:660F38VX9ErM\",\n  vfnmsub132ps_3 = \"rrmoy:660F38V9ErM\",\n  vfnmsub132sd_3 = \"rrro:660F38VX9FrM|rrx/ooq:\",\n  vfnmsub132ss_3 = \"rrro:660F38V9FrM|rrx/ood:\",\n  vfnmsub213pd_3 = \"rrmoy:660F38VXAErM\",\n  vfnmsub213ps_3 = \"rrmoy:660F38VAErM\",\n  vfnmsub213sd_3 = \"rrro:660F38VXAFrM|rrx/ooq:\",\n  vfnmsub213ss_3 = \"rrro:660F38VAFrM|rrx/ood:\",\n  vfnmsub231pd_3 = \"rrmoy:660F38VXBErM\",\n  vfnmsub231ps_3 = \"rrmoy:660F38VBErM\",\n  vfnmsub231sd_3 = \"rrro:660F38VXBFrM|rrx/ooq:\",\n  vfnmsub231ss_3 = \"rrro:660F38VBFrM|rrx/ood:\",\n}\n\n------------------------------------------------------------------------------\n\n-- Arithmetic ops.\nfor name,n in pairs{ add = 0, [\"or\"] = 1, adc = 2, sbb = 3,\n\t\t     [\"and\"] = 4, sub = 5, xor = 6, cmp = 7 } do\n  local n8 = shl(n, 3)\n  map_op[name..\"_2\"] = format(\n    \"mr:%02XRm|rm:%02XrM|mI1qdw:81%XmI|mS1qdw:83%XmS|Ri1qdwb:%02Xri|mi1qdwb:81%Xmi\",\n    1+n8, 3+n8, n, n, 5+n8, n)\nend\n\n-- Shift ops.\nfor name,n in pairs{ rol = 0, ror = 1, rcl = 2, rcr = 3,\n\t\t     shl = 4, shr = 5,          sar = 7, sal = 4 } do\n  map_op[name..\"_2\"] = format(\"m1:D1%Xm|mC1qdwb:D3%Xm|mi:C1%XmU\", n, n, n)\nend\n\n-- Conditional ops.\nfor cc,n in pairs(map_cc) do\n  map_op[\"j\"..cc..\"_1\"] = format(\"J.:n0F8%XJ\", n) -- short: 7%X\n  map_op[\"set\"..cc..\"_1\"] = format(\"mb:n0F9%X2m\", n)\n  map_op[\"cmov\"..cc..\"_2\"] = format(\"rmqdw:0F4%XrM\", n) -- P6+\nend\n\n-- FP arithmetic ops.\nfor name,n in pairs{ add = 0, mul = 1, com = 2, comp = 3,\n\t\t     sub = 4, subr = 5, div = 6, divr = 7 } do\n  local nc = 0xc0 + shl(n, 3)\n  local nr = nc + (n < 4 and 0 or (n % 2 == 0 and 8 or -8))\n  local fn = \"f\"..name\n  map_op[fn..\"_1\"] = format(\"ff:D8%02Xr|xd:D8%Xm|xq:nDC%Xm\", nc, n, n)\n  if n == 2 or n == 3 then\n    map_op[fn..\"_2\"] = format(\"Fff:D8%02XR|Fx2d:D8%XM|Fx2q:nDC%XM\", nc, n, n)\n  else\n    map_op[fn..\"_2\"] = format(\"Fff:D8%02XR|fFf:DC%02Xr|Fx2d:D8%XM|Fx2q:nDC%XM\", nc, nr, n, n)\n    map_op[fn..\"p_1\"] = format(\"ff:DE%02Xr\", nr)\n    map_op[fn..\"p_2\"] = format(\"fFf:DE%02Xr\", nr)\n  end\n  map_op[\"fi\"..name..\"_1\"] = format(\"xd:DA%Xm|xw:nDE%Xm\", n, n)\nend\n\n-- FP conditional moves.\nfor cc,n in pairs{ b=0, e=1, be=2, u=3, nb=4, ne=5, nbe=6, nu=7 } do\n  local nc = 0xdac0 + shl(band(n, 3), 3) + shl(band(n, 4), 6)\n  map_op[\"fcmov\"..cc..\"_1\"] = format(\"ff:%04Xr\", nc) -- P6+\n  map_op[\"fcmov\"..cc..\"_2\"] = format(\"Fff:%04XR\", nc) -- P6+\nend\n\n-- SSE / AVX FP arithmetic ops.\nfor name,n in pairs{ sqrt = 1, add = 8, mul = 9,\n\t\t     sub = 12, min = 13, div = 14, max = 15 } do\n  map_op[name..\"ps_2\"] = format(\"rmo:0F5%XrM\", n)\n  map_op[name..\"ss_2\"] = format(\"rro:F30F5%XrM|rx/od:\", n)\n  map_op[name..\"pd_2\"] = format(\"rmo:660F5%XrM\", n)\n  map_op[name..\"sd_2\"] = format(\"rro:F20F5%XrM|rx/oq:\", n)\n  if n ~= 1 then\n    map_op[\"v\"..name..\"ps_3\"] = format(\"rrmoy:0FV5%XrM\", n)\n    map_op[\"v\"..name..\"ss_3\"] = format(\"rrro:F30FV5%XrM|rrx/ood:\", n)\n    map_op[\"v\"..name..\"pd_3\"] = format(\"rrmoy:660FV5%XrM\", n)\n    map_op[\"v\"..name..\"sd_3\"] = format(\"rrro:F20FV5%XrM|rrx/ooq:\", n)\n  end\nend\n\n-- SSE2 / AVX / AVX2 integer arithmetic ops (66 0F leaf).\nfor name,n in pairs{\n  paddb = 0xFC, paddw = 0xFD, paddd = 0xFE, paddq = 0xD4,\n  paddsb = 0xEC, paddsw = 0xED, packssdw = 0x6B,\n  packsswb = 0x63, packuswb = 0x67, paddusb = 0xDC,\n  paddusw = 0xDD, pand = 0xDB, pandn = 0xDF, pavgb = 0xE0,\n  pavgw = 0xE3, pcmpeqb = 0x74, pcmpeqd = 0x76,\n  pcmpeqw = 0x75, pcmpgtb = 0x64, pcmpgtd = 0x66,\n  pcmpgtw = 0x65, pmaddwd = 0xF5, pmaxsw = 0xEE,\n  pmaxub = 0xDE, pminsw = 0xEA, pminub = 0xDA,\n  pmulhuw = 0xE4, pmulhw = 0xE5, pmullw = 0xD5,\n  pmuludq = 0xF4, por = 0xEB, psadbw = 0xF6, psubb = 0xF8,\n  psubw = 0xF9, psubd = 0xFA, psubq = 0xFB, psubsb = 0xE8,\n  psubsw = 0xE9, psubusb = 0xD8, psubusw = 0xD9,\n  punpckhbw = 0x68, punpckhwd = 0x69, punpckhdq = 0x6A,\n  punpckhqdq = 0x6D, punpcklbw = 0x60, punpcklwd = 0x61,\n  punpckldq = 0x62, punpcklqdq = 0x6C, pxor = 0xEF\n} do\n  map_op[name..\"_2\"] = format(\"rmo:660F%02XrM\", n)\n  map_op[\"v\"..name..\"_3\"] = format(\"rrmoy:660FV%02XrM\", n)\nend\n\n------------------------------------------------------------------------------\n\nlocal map_vexarg = { u = false, v = 1, V = 2, w = 3 }\n\n-- Process pattern string.\nlocal function dopattern(pat, args, sz, op, needrex)\n  local digit, addin, vex\n  local opcode = 0\n  local szov = sz\n  local narg = 1\n  local rex = 0\n\n  -- Limit number of section buffer positions used by a single dasm_put().\n  -- A single opcode needs a maximum of 6 positions.\n  if secpos+6 > maxsecpos then wflush() end\n\n  -- Process each character.\n  for c in gmatch(pat..\"|\", \".\") do\n    if match(c, \"%x\") then\t-- Hex digit.\n      digit = byte(c) - 48\n      if digit > 48 then digit = digit - 39\n      elseif digit > 16 then digit = digit - 7 end\n      opcode = opcode*16 + digit\n      addin = nil\n    elseif c == \"n\" then\t-- Disable operand size mods for opcode.\n      szov = nil\n    elseif c == \"X\" then\t-- Force REX.W.\n      rex = 8\n    elseif c == \"L\" then\t-- Force VEX.L.\n      vex.l = true\n    elseif c == \"r\" then\t-- Merge 1st operand regno. into opcode.\n      addin = args[1]; opcode = opcode + (addin.reg % 8)\n      if narg < 2 then narg = 2 end\n    elseif c == \"R\" then\t-- Merge 2nd operand regno. into opcode.\n      addin = args[2]; opcode = opcode + (addin.reg % 8)\n      narg = 3\n    elseif c == \"m\" or c == \"M\" then\t-- Encode ModRM/SIB.\n      local s\n      if addin then\n\ts = addin.reg\n\topcode = opcode - band(s, 7)\t-- Undo regno opcode merge.\n      else\n\ts = band(opcode, 15)\t-- Undo last digit.\n\topcode = shr(opcode, 4)\n      end\n      local nn = c == \"m\" and 1 or 2\n      local t = args[nn]\n      if narg <= nn then narg = nn + 1 end\n      if szov == \"q\" and rex == 0 then rex = rex + 8 end\n      if t.reg and t.reg > 7 then rex = rex + 1 end\n      if t.xreg and t.xreg > 7 then rex = rex + 2 end\n      if s > 7 then rex = rex + 4 end\n      if needrex then rex = rex + 16 end\n      local psz, sk = wputop(szov, opcode, rex, vex, s < 0, t.vreg or t.vxreg)\n      opcode = nil\n      local imark = sub(pat, -1) -- Force a mark (ugly).\n      -- Put ModRM/SIB with regno/last digit as spare.\n      wputmrmsib(t, imark, s, addin and addin.vreg, psz, sk)\n      addin = nil\n    elseif map_vexarg[c] ~= nil then -- Encode using VEX prefix\n      local b = band(opcode, 255); opcode = shr(opcode, 8)\n      local m = 1\n      if b == 0x38 then m = 2\n      elseif b == 0x3a then m = 3 end\n      if m ~= 1 then b = band(opcode, 255); opcode = shr(opcode, 8) end\n      if b ~= 0x0f then\n\twerror(\"expected `0F', `0F38', or `0F3A' to precede `\"..c..\n\t  \"' in pattern `\"..pat..\"' for `\"..op..\"'\")\n      end\n      local v = map_vexarg[c]\n      if v then v = remove(args, v) end\n      b = band(opcode, 255)\n      local p = 0\n      if b == 0x66 then p = 1\n      elseif b == 0xf3 then p = 2\n      elseif b == 0xf2 then p = 3 end\n      if p ~= 0 then opcode = shr(opcode, 8) end\n      if opcode ~= 0 then wputop(nil, opcode, 0); opcode = 0 end\n      vex = { m = m, p = p, v = v }\n    else\n      if opcode then -- Flush opcode.\n\tif szov == \"q\" and rex == 0 then rex = rex + 8 end\n\tif needrex then rex = rex + 16 end\n\tif addin and addin.reg == -1 then\n\t  local psz, sk = wputop(szov, opcode - 7, rex, vex, true)\n\t  wvreg(\"opcode\", addin.vreg, psz, sk)\n\telse\n\t  if addin and addin.reg > 7 then rex = rex + 1 end\n\t  wputop(szov, opcode, rex, vex)\n\tend\n\topcode = nil\n      end\n      if c == \"|\" then break end\n      if c == \"o\" then -- Offset (pure 32 bit displacement).\n\twputdarg(args[1].disp); if narg < 2 then narg = 2 end\n      elseif c == \"O\" then\n\twputdarg(args[2].disp); narg = 3\n      else\n\t-- Anything else is an immediate operand.\n\tlocal a = args[narg]\n\tnarg = narg + 1\n\tlocal mode, imm = a.mode, a.imm\n\tif mode == \"iJ\" and not match(x64 and \"J\" or \"iIJ\", c) then\n\t  werror(\"bad operand size for label\")\n\tend\n\tif c == \"S\" then\n\t  wputsbarg(imm)\n\telseif c == \"U\" then\n\t  wputbarg(imm)\n\telseif c == \"W\" then\n\t  wputwarg(imm)\n\telseif c == \"i\" or c == \"I\" then\n\t  if mode == \"iJ\" then\n\t    wputlabel(\"IMM_\", imm, 1)\n\t  elseif mode == \"iI\" and c == \"I\" then\n\t    waction(sz == \"w\" and \"IMM_WB\" or \"IMM_DB\", imm)\n\t  else\n\t    wputszarg(sz, imm)\n\t  end\n\telseif c == \"J\" then\n\t  if mode == \"iPJ\" then\n\t    waction(\"REL_A\", imm) -- !x64 (secpos)\n\t  else\n\t    wputlabel(\"REL_\", imm, 2)\n\t  end\n\telseif c == \"s\" then\n\t  local reg = a.reg\n\t  if reg < 0 then\n\t    wputb(0)\n\t    wvreg(\"imm.hi\", a.vreg)\n\t  else\n\t    wputb(shl(reg, 4))\n\t  end\n\telse\n\t  werror(\"bad char `\"..c..\"' in pattern `\"..pat..\"' for `\"..op..\"'\")\n\tend\n      end\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Mapping of operand modes to short names. Suppress output with '#'.\nlocal map_modename = {\n  r = \"reg\", R = \"eax\", C = \"cl\", x = \"mem\", m = \"mrm\", i = \"imm\",\n  f = \"stx\", F = \"st0\", J = \"lbl\", [\"1\"] = \"1\",\n  I = \"#\", S = \"#\", O = \"#\",\n}\n\n-- Return a table/string showing all possible operand modes.\nlocal function templatehelp(template, nparams)\n  if nparams == 0 then return \"\" end\n  local t = {}\n  for tm in gmatch(template, \"[^%|]+\") do\n    local s = map_modename[sub(tm, 1, 1)]\n    s = s..gsub(sub(tm, 2, nparams), \".\", function(c)\n      return \", \"..map_modename[c]\n    end)\n    if not match(s, \"#\") then t[#t+1] = s end\n  end\n  return t\nend\n\n-- Match operand modes against mode match part of template.\nlocal function matchtm(tm, args)\n  for i=1,#args do\n    if not match(args[i].mode, sub(tm, i, i)) then return end\n  end\n  return true\nend\n\n-- Handle opcodes defined with template strings.\nmap_op[\".template__\"] = function(params, template, nparams)\n  if not params then return templatehelp(template, nparams) end\n  local args = {}\n\n  -- Zero-operand opcodes have no match part.\n  if #params == 0 then\n    dopattern(template, args, \"d\", params.op, nil)\n    return\n  end\n\n  -- Determine common operand size (coerce undefined size) or flag as mixed.\n  local sz, szmix, needrex\n  for i,p in ipairs(params) do\n    args[i] = parseoperand(p)\n    local nsz = args[i].opsize\n    if nsz then\n      if sz and sz ~= nsz then szmix = true else sz = nsz end\n    end\n    local nrex = args[i].needrex\n    if nrex ~= nil then\n      if needrex == nil then\n\tneedrex = nrex\n      elseif needrex ~= nrex then\n\twerror(\"bad mix of byte-addressable registers\")\n      end\n    end\n  end\n\n  -- Try all match:pattern pairs (separated by '|').\n  local gotmatch, lastpat\n  for tm in gmatch(template, \"[^%|]+\") do\n    -- Split off size match (starts after mode match) and pattern string.\n    local szm, pat = match(tm, \"^(.-):(.*)$\", #args+1)\n    if pat == \"\" then pat = lastpat else lastpat = pat end\n    if matchtm(tm, args) then\n      local prefix = sub(szm, 1, 1)\n      if prefix == \"/\" then -- Exactly match leading operand sizes.\n\tfor i = #szm,1,-1 do\n\t  if i == 1 then\n\t    dopattern(pat, args, sz, params.op, needrex) -- Process pattern.\n\t    return\n\t  elseif args[i-1].opsize ~= sub(szm, i, i) then\n\t    break\n\t  end\n\tend\n      else -- Match common operand size.\n\tlocal szp = sz\n\tif szm == \"\" then szm = x64 and \"qdwb\" or \"dwb\" end -- Default sizes.\n\tif prefix == \"1\" then szp = args[1].opsize; szmix = nil\n\telseif prefix == \"2\" then szp = args[2].opsize; szmix = nil end\n\tif not szmix and (prefix == \".\" or match(szm, szp or \"#\")) then\n\t  dopattern(pat, args, szp, params.op, needrex) -- Process pattern.\n\t  return\n\tend\n      end\n      gotmatch = true\n    end\n  end\n\n  local msg = \"bad operand mode\"\n  if gotmatch then\n    if szmix then\n      msg = \"mixed operand size\"\n    else\n      msg = sz and \"bad operand size\" or \"missing operand size\"\n    end\n  end\n\n  werror(msg..\" in `\"..opmodestr(params.op, args)..\"'\")\nend\n\n------------------------------------------------------------------------------\n\n-- x64-specific opcode for 64 bit immediates and displacements.\nif x64 then\n  function map_op.mov64_2(params)\n    if not params then return { \"reg, imm\", \"reg, [disp]\", \"[disp], reg\" } end\n    if secpos+2 > maxsecpos then wflush() end\n    local opcode, op64, sz, rex, vreg\n    local op64 = match(params[1], \"^%[%s*(.-)%s*%]$\")\n    if op64 then\n      local a = parseoperand(params[2])\n      if a.mode ~= \"rmR\" then werror(\"bad operand mode\") end\n      sz = a.opsize\n      rex = sz == \"q\" and 8 or 0\n      opcode = 0xa3\n    else\n      op64 = match(params[2], \"^%[%s*(.-)%s*%]$\")\n      local a = parseoperand(params[1])\n      if op64 then\n\tif a.mode ~= \"rmR\" then werror(\"bad operand mode\") end\n\tsz = a.opsize\n\trex = sz == \"q\" and 8 or 0\n\topcode = 0xa1\n      else\n\tif sub(a.mode, 1, 1) ~= \"r\" or a.opsize ~= \"q\" then\n\t  werror(\"bad operand mode\")\n\tend\n\top64 = params[2]\n\tif a.reg == -1 then\n\t  vreg = a.vreg\n\t  opcode = 0xb8\n\telse\n\t  opcode = 0xb8 + band(a.reg, 7)\n\tend\n\trex = a.reg > 7 and 9 or 8\n      end\n    end\n    local psz, sk = wputop(sz, opcode, rex, nil, vreg)\n    wvreg(\"opcode\", vreg, psz, sk)\n    waction(\"IMM_D\", format(\"(unsigned int)(%s)\", op64))\n    waction(\"IMM_D\", format(\"(unsigned int)((%s)>>32)\", op64))\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcodes for data storage.\nlocal function op_data(params)\n  if not params then return \"imm...\" end\n  local sz = sub(params.op, 2, 2)\n  if sz == \"l\" then sz = \"d\" elseif sz == \"a\" then sz = addrsize end\n  for _,p in ipairs(params) do\n    local a = parseoperand(p, sz == \"q\")\n    if sub(a.mode, 1, 1) ~= \"i\" or (a.opsize and a.opsize ~= sz) then\n      werror(\"bad mode or size in `\"..p..\"'\")\n    end\n    if a.mode == \"iJ\" then\n      wputlabel(\"IMM_\", a.imm, 1)\n    elseif sz == \"q\" then\n      wputqarg(a.imm)\n    else\n      wputszarg(sz, a.imm)\n    end\n    if secpos+2 > maxsecpos then wflush() end\n  end\nend\n\nmap_op[\".byte_*\"] = op_data\nmap_op[\".sbyte_*\"] = op_data\nmap_op[\".word_*\"] = op_data\nmap_op[\".dword_*\"] = op_data\nmap_op[\".qword_*\"] = op_data\nmap_op[\".aword_*\"] = op_data\nmap_op[\".long_*\"] = op_data\nmap_op[\".quad_*\"] = op_data\nmap_op[\".addr_*\"] = op_data\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode to mark the position where the action list is to be emitted.\nmap_op[\".actionlist_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeactions(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the global enum is to be emitted.\nmap_op[\".globals_1\"] = function(params)\n  if not params then return \"prefix\" end\n  local prefix = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobals(out, prefix) end)\nend\n\n-- Pseudo-opcode to mark the position where the global names are to be emitted.\nmap_op[\".globalnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeglobalnames(out, name) end)\nend\n\n-- Pseudo-opcode to mark the position where the extern names are to be emitted.\nmap_op[\".externnames_1\"] = function(params)\n  if not params then return \"cvar\" end\n  local name = params[1] -- No syntax check. You get to keep the pieces.\n  wline(function(out) writeexternnames(out, name) end)\nend\n\n------------------------------------------------------------------------------\n\n-- Label pseudo-opcode (converted from trailing colon form).\nmap_op[\".label_2\"] = function(params)\n  if not params then return \"[1-9] | ->global | =>pcexpr  [, addr]\" end\n  if secpos+2 > maxsecpos then wflush() end\n  local a = parseoperand(params[1])\n  local mode, imm = a.mode, a.imm\n  if type(imm) == \"number\" and (mode == \"iJ\" or (imm >= 1 and imm <= 9)) then\n    -- Local label (1: ... 9:) or global label (->global:).\n    waction(\"LABEL_LG\", nil, 1)\n    wputxb(imm)\n  elseif mode == \"iJ\" then\n    -- PC label (=>pcexpr:).\n    waction(\"LABEL_PC\", imm)\n  else\n    werror(\"bad label definition\")\n  end\n  -- SETLABEL must immediately follow LABEL_LG/LABEL_PC.\n  local addr = params[2]\n  if addr then\n    local a = parseoperand(addr)\n    if a.mode == \"iPJ\" then\n      waction(\"SETLABEL\", a.imm)\n    else\n      werror(\"bad label assignment\")\n    end\n  end\nend\nmap_op[\".label_1\"] = map_op[\".label_2\"]\n\n------------------------------------------------------------------------------\n\n-- Alignment pseudo-opcode.\nmap_op[\".align_1\"] = function(params)\n  if not params then return \"numpow2\" end\n  if secpos+1 > maxsecpos then wflush() end\n  local align = tonumber(params[1]) or map_opsizenum[map_opsize[params[1]]]\n  if align then\n    local x = align\n    -- Must be a power of 2 in the range (2 ... 256).\n    for i=1,8 do\n      x = x / 2\n      if x == 1 then\n\twaction(\"ALIGN\", nil, 1)\n\twputxb(align-1) -- Action byte is 2**n-1.\n\treturn\n      end\n    end\n  end\n  werror(\"bad alignment\")\nend\n\n-- Spacing pseudo-opcode.\nmap_op[\".space_2\"] = function(params)\n  if not params then return \"num [, filler]\" end\n  if secpos+1 > maxsecpos then wflush() end\n  waction(\"SPACE\", params[1])\n  local fill = params[2]\n  if fill then\n    fill = tonumber(fill)\n    if not fill or fill < 0 or fill > 255 then werror(\"bad filler\") end\n  end\n  wputxb(fill or 0)\nend\nmap_op[\".space_1\"] = map_op[\".space_2\"]\n\n------------------------------------------------------------------------------\n\n-- Pseudo-opcode for (primitive) type definitions (map to C types).\nmap_op[\".type_3\"] = function(params, nparams)\n  if not params then\n    return nparams == 2 and \"name, ctype\" or \"name, ctype, reg\"\n  end\n  local name, ctype, reg = params[1], params[2], params[3]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    werror(\"bad type name `\"..name..\"'\")\n  end\n  local tp = map_type[name]\n  if tp then\n    werror(\"duplicate type `\"..name..\"'\")\n  end\n  if reg and not map_reg_valid_base[reg] then\n    werror(\"bad base register `\"..(map_reg_rev[reg] or reg)..\"'\")\n  end\n  -- Add #type to defines. A bit unclean to put it in map_archdef.\n  map_archdef[\"#\"..name] = \"sizeof(\"..ctype..\")\"\n  -- Add new type and emit shortcut define.\n  local num = ctypenum + 1\n  map_type[name] = {\n    ctype = ctype,\n    ctypefmt = format(\"Dt%X(%%s)\", num),\n    reg = reg,\n  }\n  wline(format(\"#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)\", num, ctype))\n  ctypenum = num\nend\nmap_op[\".type_2\"] = map_op[\".type_3\"]\n\n-- Dump type definitions.\nlocal function dumptypes(out, lvl)\n  local t = {}\n  for name in pairs(map_type) do t[#t+1] = name end\n  sort(t)\n  out:write(\"Type definitions:\\n\")\n  for _,name in ipairs(t) do\n    local tp = map_type[name]\n    local reg = tp.reg and map_reg_rev[tp.reg] or \"\"\n    out:write(format(\"  %-20s %-20s %s\\n\", name, tp.ctype, reg))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Set the current section.\nfunction _M.section(num)\n  waction(\"SECTION\")\n  wputxb(num)\n  wflush(true) -- SECTION is a terminal action.\nend\n\n------------------------------------------------------------------------------\n\n-- Dump architecture description.\nfunction _M.dumparch(out)\n  out:write(format(\"DynASM %s version %s, released %s\\n\\n\",\n    _info.arch, _info.version, _info.release))\n  dumpregs(out)\n  dumpactions(out)\nend\n\n-- Dump all user defined elements.\nfunction _M.dumpdef(out, lvl)\n  dumptypes(out, lvl)\n  dumpglobals(out, lvl)\n  dumpexterns(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Pass callbacks from/to the DynASM core.\nfunction _M.passcb(wl, we, wf, ww)\n  wline, werror, wfatal, wwarn = wl, we, wf, ww\n  return wflush\nend\n\n-- Setup the arch-specific module.\nfunction _M.setup(arch, opt)\n  g_arch, g_opt = arch, opt\nend\n\n-- Merge the core maps and the arch-specific maps.\nfunction _M.mergemaps(map_coreop, map_def)\n  setmetatable(map_op, { __index = map_coreop })\n  setmetatable(map_def, { __index = map_archdef })\n  return map_op, map_def\nend\n\nreturn _M\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/dynasm/dynasm.lua",
    "content": "------------------------------------------------------------------------------\n-- DynASM. A dynamic assembler for code generation engines.\n-- Originally designed and implemented for LuaJIT.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- See below for full copyright notice.\n------------------------------------------------------------------------------\n\n-- Application information.\nlocal _info = {\n  name =\t\"DynASM\",\n  description =\t\"A dynamic assembler for code generation engines\",\n  version =\t\"1.5.0\",\n  vernum =\t 10500,\n  release =\t\"2021-05-02\",\n  author =\t\"Mike Pall\",\n  url =\t\t\"https://luajit.org/dynasm.html\",\n  license =\t\"MIT\",\n  copyright =\t[[\nCopyright (C) 2005-2021 Mike Pall. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[ MIT license: https://www.opensource.org/licenses/mit-license.php ]\n]],\n}\n\n-- Cache library functions.\nlocal type, pairs, ipairs = type, pairs, ipairs\nlocal pcall, error, assert = pcall, error, assert\nlocal _s = string\nlocal sub, match, gmatch, gsub = _s.sub, _s.match, _s.gmatch, _s.gsub\nlocal format, rep, upper = _s.format, _s.rep, _s.upper\nlocal _t = table\nlocal insert, remove, concat, sort = _t.insert, _t.remove, _t.concat, _t.sort\nlocal exit = os.exit\nlocal io = io\nlocal stdin, stdout, stderr = io.stdin, io.stdout, io.stderr\n\n------------------------------------------------------------------------------\n\n-- Program options.\nlocal g_opt = {}\n\n-- Global state for current file.\nlocal g_fname, g_curline, g_indent, g_lineno, g_synclineno, g_arch\nlocal g_errcount = 0\n\n-- Write buffer for output file.\nlocal g_wbuffer, g_capbuffer\n\n------------------------------------------------------------------------------\n\n-- Write an output line (or callback function) to the buffer.\nlocal function wline(line, needindent)\n  local buf = g_capbuffer or g_wbuffer\n  buf[#buf+1] = needindent and g_indent..line or line\n  g_synclineno = g_synclineno + 1\nend\n\n-- Write assembler line as a comment, if requestd.\nlocal function wcomment(aline)\n  if g_opt.comment then\n    wline(g_opt.comment..aline..g_opt.endcomment, true)\n  end\nend\n\n-- Resync CPP line numbers.\nlocal function wsync()\n  if g_synclineno ~= g_lineno and g_opt.cpp then\n    wline(\"#line \"..g_lineno..' \"'..g_fname..'\"')\n    g_synclineno = g_lineno\n  end\nend\n\n-- Dummy action flush function. Replaced with arch-specific function later.\nlocal function wflush(term)\nend\n\n-- Dump all buffered output lines.\nlocal function wdumplines(out, buf)\n  for _,line in ipairs(buf) do\n    if type(line) == \"string\" then\n      assert(out:write(line, \"\\n\"))\n    else\n      -- Special callback to dynamically insert lines after end of processing.\n      line(out)\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Emit an error. Processing continues with next statement.\nlocal function werror(msg)\n  error(format(\"%s:%s: error: %s:\\n%s\", g_fname, g_lineno, msg, g_curline), 0)\nend\n\n-- Emit a fatal error. Processing stops.\nlocal function wfatal(msg)\n  g_errcount = \"fatal\"\n  werror(msg)\nend\n\n-- Print a warning. Processing continues.\nlocal function wwarn(msg)\n  stderr:write(format(\"%s:%s: warning: %s:\\n%s\\n\",\n    g_fname, g_lineno, msg, g_curline))\nend\n\n-- Print caught error message. But suppress excessive errors.\nlocal function wprinterr(...)\n  if type(g_errcount) == \"number\" then\n    -- Regular error.\n    g_errcount = g_errcount + 1\n    if g_errcount < 21 then -- Seems to be a reasonable limit.\n      stderr:write(...)\n    elseif g_errcount == 21 then\n      stderr:write(g_fname,\n\t\":*: warning: too many errors (suppressed further messages).\\n\")\n    end\n  else\n    -- Fatal error.\n    stderr:write(...)\n    return true -- Stop processing.\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Map holding all option handlers.\nlocal opt_map = {}\nlocal opt_current\n\n-- Print error and exit with error status.\nlocal function opterror(...)\n  stderr:write(\"dynasm.lua: ERROR: \", ...)\n  stderr:write(\"\\n\")\n  exit(1)\nend\n\n-- Get option parameter.\nlocal function optparam(args)\n  local argn = args.argn\n  local p = args[argn]\n  if not p then\n    opterror(\"missing parameter for option `\", opt_current, \"'.\")\n  end\n  args.argn = argn + 1\n  return p\nend\n\n------------------------------------------------------------------------------\n\n-- Core pseudo-opcodes.\nlocal map_coreop = {}\n-- Dummy opcode map. Replaced by arch-specific map.\nlocal map_op = {}\n\n-- Forward declarations.\nlocal dostmt\nlocal readfile\n\n------------------------------------------------------------------------------\n\n-- Map for defines (initially empty, chains to arch-specific map).\nlocal map_def = {}\n\n-- Pseudo-opcode to define a substitution.\nmap_coreop[\".define_2\"] = function(params, nparams)\n  if not params then return nparams == 1 and \"name\" or \"name, subst\" end\n  local name, def = params[1], params[2] or \"1\"\n  if not match(name, \"^[%a_][%w_]*$\") then werror(\"bad or duplicate define\") end\n  map_def[name] = def\nend\nmap_coreop[\".define_1\"] = map_coreop[\".define_2\"]\n\n-- Define a substitution on the command line.\nfunction opt_map.D(args)\n  local namesubst = optparam(args)\n  local name, subst = match(namesubst, \"^([%a_][%w_]*)=(.*)$\")\n  if name then\n    map_def[name] = subst\n  elseif match(namesubst, \"^[%a_][%w_]*$\") then\n    map_def[namesubst] = \"1\"\n  else\n    opterror(\"bad define\")\n  end\nend\n\n-- Undefine a substitution on the command line.\nfunction opt_map.U(args)\n  local name = optparam(args)\n  if match(name, \"^[%a_][%w_]*$\") then\n    map_def[name] = nil\n  else\n    opterror(\"bad define\")\n  end\nend\n\n-- Helper for definesubst.\nlocal gotsubst\n\nlocal function definesubst_one(word)\n  local subst = map_def[word]\n  if subst then gotsubst = word; return subst else return word end\nend\n\n-- Iteratively substitute defines.\nlocal function definesubst(stmt)\n  -- Limit number of iterations.\n  for i=1,100 do\n    gotsubst = false\n    stmt = gsub(stmt, \"#?[%w_]+\", definesubst_one)\n    if not gotsubst then break end\n  end\n  if gotsubst then wfatal(\"recursive define involving `\"..gotsubst..\"'\") end\n  return stmt\nend\n\n-- Dump all defines.\nlocal function dumpdefines(out, lvl)\n  local t = {}\n  for name in pairs(map_def) do\n    t[#t+1] = name\n  end\n  sort(t)\n  out:write(\"Defines:\\n\")\n  for _,name in ipairs(t) do\n    local subst = map_def[name]\n    if g_arch then subst = g_arch.revdef(subst) end\n    out:write(format(\"  %-20s %s\\n\", name, subst))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Support variables for conditional assembly.\nlocal condlevel = 0\nlocal condstack = {}\n\n-- Evaluate condition with a Lua expression. Substitutions already performed.\nlocal function cond_eval(cond)\n  local func, err\n  if setfenv then\n    func, err = loadstring(\"return \"..cond, \"=expr\")\n  else\n    -- No globals. All unknown identifiers evaluate to nil.\n    func, err = load(\"return \"..cond, \"=expr\", \"t\", {})\n  end\n  if func then\n    if setfenv then\n      setfenv(func, {}) -- No globals. All unknown identifiers evaluate to nil.\n    end\n    local ok, res = pcall(func)\n    if ok then\n      if res == 0 then return false end -- Oh well.\n      return not not res\n    end\n    err = res\n  end\n  wfatal(\"bad condition: \"..err)\nend\n\n-- Skip statements until next conditional pseudo-opcode at the same level.\nlocal function stmtskip()\n  local dostmt_save = dostmt\n  local lvl = 0\n  dostmt = function(stmt)\n    local op = match(stmt, \"^%s*(%S+)\")\n    if op == \".if\" then\n      lvl = lvl + 1\n    elseif lvl ~= 0 then\n      if op == \".endif\" then lvl = lvl - 1 end\n    elseif op == \".elif\" or op == \".else\" or op == \".endif\" then\n      dostmt = dostmt_save\n      dostmt(stmt)\n    end\n  end\nend\n\n-- Pseudo-opcodes for conditional assembly.\nmap_coreop[\".if_1\"] = function(params)\n  if not params then return \"condition\" end\n  local lvl = condlevel + 1\n  local res = cond_eval(params[1])\n  condlevel = lvl\n  condstack[lvl] = res\n  if not res then stmtskip() end\nend\n\nmap_coreop[\".elif_1\"] = function(params)\n  if not params then return \"condition\" end\n  if condlevel == 0 then wfatal(\".elif without .if\") end\n  local lvl = condlevel\n  local res = condstack[lvl]\n  if res then\n    if res == \"else\" then wfatal(\".elif after .else\") end\n  else\n    res = cond_eval(params[1])\n    if res then\n      condstack[lvl] = res\n      return\n    end\n  end\n  stmtskip()\nend\n\nmap_coreop[\".else_0\"] = function(params)\n  if condlevel == 0 then wfatal(\".else without .if\") end\n  local lvl = condlevel\n  local res = condstack[lvl]\n  condstack[lvl] = \"else\"\n  if res then\n    if res == \"else\" then wfatal(\".else after .else\") end\n    stmtskip()\n  end\nend\n\nmap_coreop[\".endif_0\"] = function(params)\n  local lvl = condlevel\n  if lvl == 0 then wfatal(\".endif without .if\") end\n  condlevel = lvl - 1\nend\n\n-- Check for unfinished conditionals.\nlocal function checkconds()\n  if g_errcount ~= \"fatal\" and condlevel ~= 0 then\n    wprinterr(g_fname, \":*: error: unbalanced conditional\\n\")\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Search for a file in the given path and open it for reading.\nlocal function pathopen(path, name)\n  local dirsep = package and match(package.path, \"\\\\\") and \"\\\\\" or \"/\"\n  for _,p in ipairs(path) do\n    local fullname = p == \"\" and name or p..dirsep..name\n    local fin = io.open(fullname, \"r\")\n    if fin then\n      g_fname = fullname\n      return fin\n    end\n  end\nend\n\n-- Include a file.\nmap_coreop[\".include_1\"] = function(params)\n  if not params then return \"filename\" end\n  local name = params[1]\n  -- Save state. Ugly, I know. but upvalues are fast.\n  local gf, gl, gcl, gi = g_fname, g_lineno, g_curline, g_indent\n  -- Read the included file.\n  local fatal = readfile(pathopen(g_opt.include, name) or\n\t\t\t wfatal(\"include file `\"..name..\"' not found\"))\n  -- Restore state.\n  g_synclineno = -1\n  g_fname, g_lineno, g_curline, g_indent = gf, gl, gcl, gi\n  if fatal then wfatal(\"in include file\") end\nend\n\n-- Make .include and conditionals initially available, too.\nmap_op[\".include_1\"] = map_coreop[\".include_1\"]\nmap_op[\".if_1\"] = map_coreop[\".if_1\"]\nmap_op[\".elif_1\"] = map_coreop[\".elif_1\"]\nmap_op[\".else_0\"] = map_coreop[\".else_0\"]\nmap_op[\".endif_0\"] = map_coreop[\".endif_0\"]\n\n------------------------------------------------------------------------------\n\n-- Support variables for macros.\nlocal mac_capture, mac_lineno, mac_name\nlocal mac_active = {}\nlocal mac_list = {}\n\n-- Pseudo-opcode to define a macro.\nmap_coreop[\".macro_*\"] = function(mparams)\n  if not mparams then return \"name [, params...]\" end\n  -- Split off and validate macro name.\n  local name = remove(mparams, 1)\n  if not name then werror(\"missing macro name\") end\n  if not (match(name, \"^[%a_][%w_%.]*$\") or match(name, \"^%.[%w_%.]*$\")) then\n    wfatal(\"bad macro name `\"..name..\"'\")\n  end\n  -- Validate macro parameter names.\n  local mdup = {}\n  for _,mp in ipairs(mparams) do\n    if not match(mp, \"^[%a_][%w_]*$\") then\n      wfatal(\"bad macro parameter name `\"..mp..\"'\")\n    end\n    if mdup[mp] then wfatal(\"duplicate macro parameter name `\"..mp..\"'\") end\n    mdup[mp] = true\n  end\n  -- Check for duplicate or recursive macro definitions.\n  local opname = name..\"_\"..#mparams\n  if map_op[opname] or map_op[name..\"_*\"] then\n    wfatal(\"duplicate macro `\"..name..\"' (\"..#mparams..\" parameters)\")\n  end\n  if mac_capture then wfatal(\"recursive macro definition\") end\n\n  -- Enable statement capture.\n  local lines = {}\n  mac_lineno = g_lineno\n  mac_name = name\n  mac_capture = function(stmt) -- Statement capture function.\n    -- Stop macro definition with .endmacro pseudo-opcode.\n    if not match(stmt, \"^%s*.endmacro%s*$\") then\n      lines[#lines+1] = stmt\n      return\n    end\n    mac_capture = nil\n    mac_lineno = nil\n    mac_name = nil\n    mac_list[#mac_list+1] = opname\n    -- Add macro-op definition.\n    map_op[opname] = function(params)\n      if not params then return mparams, lines end\n      -- Protect against recursive macro invocation.\n      if mac_active[opname] then wfatal(\"recursive macro invocation\") end\n      mac_active[opname] = true\n      -- Setup substitution map.\n      local subst = {}\n      for i,mp in ipairs(mparams) do subst[mp] = params[i] end\n      local mcom\n      if g_opt.maccomment and g_opt.comment then\n\tmcom = \" MACRO \"..name..\" (\"..#mparams..\")\"\n\twcomment(\"{\"..mcom)\n      end\n      -- Loop through all captured statements\n      for _,stmt in ipairs(lines) do\n\t-- Substitute macro parameters.\n\tlocal st = gsub(stmt, \"[%w_]+\", subst)\n\tst = definesubst(st)\n\tst = gsub(st, \"%s*%.%.%s*\", \"\") -- Token paste a..b.\n\tif mcom and sub(st, 1, 1) ~= \"|\" then wcomment(st) end\n\t-- Emit statement. Use a protected call for better diagnostics.\n\tlocal ok, err = pcall(dostmt, st)\n\tif not ok then\n\t  -- Add the captured statement to the error.\n\t  wprinterr(err, \"\\n\", g_indent, \"|  \", stmt,\n\t\t    \"\\t[MACRO \", name, \" (\", #mparams, \")]\\n\")\n\tend\n      end\n      if mcom then wcomment(\"}\"..mcom) end\n      mac_active[opname] = nil\n    end\n  end\nend\n\n-- An .endmacro pseudo-opcode outside of a macro definition is an error.\nmap_coreop[\".endmacro_0\"] = function(params)\n  wfatal(\".endmacro without .macro\")\nend\n\n-- Dump all macros and their contents (with -PP only).\nlocal function dumpmacros(out, lvl)\n  sort(mac_list)\n  out:write(\"Macros:\\n\")\n  for _,opname in ipairs(mac_list) do\n    local name = sub(opname, 1, -3)\n    local params, lines = map_op[opname]()\n    out:write(format(\"  %-20s %s\\n\", name, concat(params, \", \")))\n    if lvl > 1 then\n      for _,line in ipairs(lines) do\n\tout:write(\"  |\", line, \"\\n\")\n      end\n      out:write(\"\\n\")\n    end\n  end\n  out:write(\"\\n\")\nend\n\n-- Check for unfinished macro definitions.\nlocal function checkmacros()\n  if mac_capture then\n    wprinterr(g_fname, \":\", mac_lineno,\n\t      \": error: unfinished .macro `\", mac_name ,\"'\\n\")\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Support variables for captures.\nlocal cap_lineno, cap_name\nlocal cap_buffers = {}\nlocal cap_used = {}\n\n-- Start a capture.\nmap_coreop[\".capture_1\"] = function(params)\n  if not params then return \"name\" end\n  wflush()\n  local name = params[1]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    wfatal(\"bad capture name `\"..name..\"'\")\n  end\n  if cap_name then\n    wfatal(\"already capturing to `\"..cap_name..\"' since line \"..cap_lineno)\n  end\n  cap_name = name\n  cap_lineno = g_lineno\n  -- Create or continue a capture buffer and start the output line capture.\n  local buf = cap_buffers[name]\n  if not buf then buf = {}; cap_buffers[name] = buf end\n  g_capbuffer = buf\n  g_synclineno = 0\nend\n\n-- Stop a capture.\nmap_coreop[\".endcapture_0\"] = function(params)\n  wflush()\n  if not cap_name then wfatal(\".endcapture without a valid .capture\") end\n  cap_name = nil\n  cap_lineno = nil\n  g_capbuffer = nil\n  g_synclineno = 0\nend\n\n-- Dump a capture buffer.\nmap_coreop[\".dumpcapture_1\"] = function(params)\n  if not params then return \"name\" end\n  wflush()\n  local name = params[1]\n  if not match(name, \"^[%a_][%w_]*$\") then\n    wfatal(\"bad capture name `\"..name..\"'\")\n  end\n  cap_used[name] = true\n  wline(function(out)\n    local buf = cap_buffers[name]\n    if buf then wdumplines(out, buf) end\n  end)\n  g_synclineno = 0\nend\n\n-- Dump all captures and their buffers (with -PP only).\nlocal function dumpcaptures(out, lvl)\n  out:write(\"Captures:\\n\")\n  for name,buf in pairs(cap_buffers) do\n    out:write(format(\"  %-20s %4s)\\n\", name, \"(\"..#buf))\n    if lvl > 1 then\n      local bar = rep(\"=\", 76)\n      out:write(\"  \", bar, \"\\n\")\n      for _,line in ipairs(buf) do\n\tout:write(\"  \", line, \"\\n\")\n      end\n      out:write(\"  \", bar, \"\\n\\n\")\n    end\n  end\n  out:write(\"\\n\")\nend\n\n-- Check for unfinished or unused captures.\nlocal function checkcaptures()\n  if cap_name then\n    wprinterr(g_fname, \":\", cap_lineno,\n\t      \": error: unfinished .capture `\", cap_name,\"'\\n\")\n    return\n  end\n  for name in pairs(cap_buffers) do\n    if not cap_used[name] then\n      wprinterr(g_fname, \":*: error: missing .dumpcapture \", name ,\"\\n\")\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Sections names.\nlocal map_sections = {}\n\n-- Pseudo-opcode to define code sections.\n-- TODO: Data sections, BSS sections. Needs extra C code and API.\nmap_coreop[\".section_*\"] = function(params)\n  if not params then return \"name...\" end\n  if #map_sections > 0 then werror(\"duplicate section definition\") end\n  wflush()\n  for sn,name in ipairs(params) do\n    local opname = \".\"..name..\"_0\"\n    if not match(name, \"^[%a][%w_]*$\") or\n       map_op[opname] or map_op[\".\"..name..\"_*\"] then\n      werror(\"bad section name `\"..name..\"'\")\n    end\n    map_sections[#map_sections+1] = name\n    wline(format(\"#define DASM_SECTION_%s\\t%d\", upper(name), sn-1))\n    map_op[opname] = function(params) g_arch.section(sn-1) end\n  end\n  wline(format(\"#define DASM_MAXSECTION\\t\\t%d\", #map_sections))\nend\n\n-- Dump all sections.\nlocal function dumpsections(out, lvl)\n  out:write(\"Sections:\\n\")\n  for _,name in ipairs(map_sections) do\n    out:write(format(\"  %s\\n\", name))\n  end\n  out:write(\"\\n\")\nend\n\n------------------------------------------------------------------------------\n\n-- Replacement for customized Lua, which lacks the package library.\nlocal prefix = \"\"\nif not require then\n  function require(name)\n    local fp = assert(io.open(prefix..name..\".lua\"))\n    local s = fp:read(\"*a\")\n    assert(fp:close())\n    return assert(loadstring(s, \"@\"..name..\".lua\"))()\n  end\nend\n\n-- Load architecture-specific module.\nlocal function loadarch(arch)\n  if not match(arch, \"^[%w_]+$\") then return \"bad arch name\" end\n  _G._map_def = map_def\n  local ok, m_arch = pcall(require, \"dasm_\"..arch)\n  if not ok then return \"cannot load module: \"..m_arch end\n  g_arch = m_arch\n  wflush = m_arch.passcb(wline, werror, wfatal, wwarn)\n  m_arch.setup(arch, g_opt)\n  map_op, map_def = m_arch.mergemaps(map_coreop, map_def)\nend\n\n-- Dump architecture description.\nfunction opt_map.dumparch(args)\n  local name = optparam(args)\n  if not g_arch then\n    local err = loadarch(name)\n    if err then opterror(err) end\n  end\n\n  local t = {}\n  for name in pairs(map_coreop) do t[#t+1] = name end\n  for name in pairs(map_op) do t[#t+1] = name end\n  sort(t)\n\n  local out = stdout\n  local _arch = g_arch._info\n  out:write(format(\"%s version %s, released %s, %s\\n\",\n    _info.name, _info.version, _info.release, _info.url))\n  g_arch.dumparch(out)\n\n  local pseudo = true\n  out:write(\"Pseudo-Opcodes:\\n\")\n  for _,sname in ipairs(t) do\n    local name, nparam = match(sname, \"^(.+)_([0-9%*])$\")\n    if name then\n      if pseudo and sub(name, 1, 1) ~= \".\" then\n\tout:write(\"\\nOpcodes:\\n\")\n\tpseudo = false\n      end\n      local f = map_op[sname]\n      local s\n      if nparam ~= \"*\" then nparam = nparam + 0 end\n      if nparam == 0 then\n\ts = \"\"\n      elseif type(f) == \"string\" then\n\ts = map_op[\".template__\"](nil, f, nparam)\n      else\n\ts = f(nil, nparam)\n      end\n      if type(s) == \"table\" then\n\tfor _,s2 in ipairs(s) do\n\t  out:write(format(\"  %-12s %s\\n\", name, s2))\n\tend\n      else\n\tout:write(format(\"  %-12s %s\\n\", name, s))\n      end\n    end\n  end\n  out:write(\"\\n\")\n  exit(0)\nend\n\n-- Pseudo-opcode to set the architecture.\n-- Only initially available (map_op is replaced when called).\nmap_op[\".arch_1\"] = function(params)\n  if not params then return \"name\" end\n  local err = loadarch(params[1])\n  if err then wfatal(err) end\n  wline(format(\"#if DASM_VERSION != %d\", _info.vernum))\n  wline('#error \"Version mismatch between DynASM and included encoding engine\"')\n  wline(\"#endif\")\nend\n\n-- Dummy .arch pseudo-opcode to improve the error report.\nmap_coreop[\".arch_1\"] = function(params)\n  if not params then return \"name\" end\n  wfatal(\"duplicate .arch statement\")\nend\n\n------------------------------------------------------------------------------\n\n-- Dummy pseudo-opcode. Don't confuse '.nop' with 'nop'.\nmap_coreop[\".nop_*\"] = function(params)\n  if not params then return \"[ignored...]\" end\nend\n\n-- Pseudo-opcodes to raise errors.\nmap_coreop[\".error_1\"] = function(params)\n  if not params then return \"message\" end\n  werror(params[1])\nend\n\nmap_coreop[\".fatal_1\"] = function(params)\n  if not params then return \"message\" end\n  wfatal(params[1])\nend\n\n-- Dump all user defined elements.\nlocal function dumpdef(out)\n  local lvl = g_opt.dumpdef\n  if lvl == 0 then return end\n  dumpsections(out, lvl)\n  dumpdefines(out, lvl)\n  if g_arch then g_arch.dumpdef(out, lvl) end\n  dumpmacros(out, lvl)\n  dumpcaptures(out, lvl)\nend\n\n------------------------------------------------------------------------------\n\n-- Helper for splitstmt.\nlocal splitlvl\n\nlocal function splitstmt_one(c)\n  if c == \"(\" then\n    splitlvl = \")\"..splitlvl\n  elseif c == \"[\" then\n    splitlvl = \"]\"..splitlvl\n  elseif c == \"{\" then\n    splitlvl = \"}\"..splitlvl\n  elseif c == \")\" or c == \"]\" or c == \"}\" then\n    if sub(splitlvl, 1, 1) ~= c then werror(\"unbalanced (), [] or {}\") end\n    splitlvl = sub(splitlvl, 2)\n  elseif splitlvl == \"\" then\n    return \" \\0 \"\n  end\n  return c\nend\n\n-- Split statement into (pseudo-)opcode and params.\nlocal function splitstmt(stmt)\n  -- Convert label with trailing-colon into .label statement.\n  local label = match(stmt, \"^%s*(.+):%s*$\")\n  if label then return \".label\", {label} end\n\n  -- Split at commas and equal signs, but obey parentheses and brackets.\n  splitlvl = \"\"\n  stmt = gsub(stmt, \"[,%(%)%[%]{}]\", splitstmt_one)\n  if splitlvl ~= \"\" then werror(\"unbalanced () or []\") end\n\n  -- Split off opcode.\n  local op, other = match(stmt, \"^%s*([^%s%z]+)%s*(.*)$\")\n  if not op then werror(\"bad statement syntax\") end\n\n  -- Split parameters.\n  local params = {}\n  for p in gmatch(other, \"%s*(%Z+)%z?\") do\n    params[#params+1] = gsub(p, \"%s+$\", \"\")\n  end\n  if #params > 16 then werror(\"too many parameters\") end\n\n  params.op = op\n  return op, params\nend\n\n-- Process a single statement.\ndostmt = function(stmt)\n  -- Ignore empty statements.\n  if match(stmt, \"^%s*$\") then return end\n\n  -- Capture macro defs before substitution.\n  if mac_capture then return mac_capture(stmt) end\n  stmt = definesubst(stmt)\n\n  -- Emit C code without parsing the line.\n  if sub(stmt, 1, 1) == \"|\" then\n    local tail = sub(stmt, 2)\n    wflush()\n    if sub(tail, 1, 2) == \"//\" then wcomment(tail) else wline(tail, true) end\n    return\n  end\n\n  -- Split into (pseudo-)opcode and params.\n  local op, params = splitstmt(stmt)\n\n  -- Get opcode handler (matching # of parameters or generic handler).\n  local f = map_op[op..\"_\"..#params] or map_op[op..\"_*\"]\n  if not f then\n    if not g_arch then wfatal(\"first statement must be .arch\") end\n    -- Improve error report.\n    for i=0,9 do\n      if map_op[op..\"_\"..i] then\n\twerror(\"wrong number of parameters for `\"..op..\"'\")\n      end\n    end\n    werror(\"unknown statement `\"..op..\"'\")\n  end\n\n  -- Call opcode handler or special handler for template strings.\n  if type(f) == \"string\" then\n    map_op[\".template__\"](params, f)\n  else\n    f(params)\n  end\nend\n\n-- Process a single line.\nlocal function doline(line)\n  if g_opt.flushline then wflush() end\n\n  -- Assembler line?\n  local indent, aline = match(line, \"^(%s*)%|(.*)$\")\n  if not aline then\n    -- No, plain C code line, need to flush first.\n    wflush()\n    wsync()\n    wline(line, false)\n    return\n  end\n\n  g_indent = indent -- Remember current line indentation.\n\n  -- Emit C code (even from macros). Avoids echo and line parsing.\n  if sub(aline, 1, 1) == \"|\" then\n    if not mac_capture then\n      wsync()\n    elseif g_opt.comment then\n      wsync()\n      wcomment(aline)\n    end\n    dostmt(aline)\n    return\n  end\n\n  -- Echo assembler line as a comment.\n  if g_opt.comment then\n    wsync()\n    wcomment(aline)\n  end\n\n  -- Strip assembler comments.\n  aline = gsub(aline, \"//.*$\", \"\")\n\n  -- Split line into statements at semicolons.\n  if match(aline, \";\") then\n    for stmt in gmatch(aline, \"[^;]+\") do dostmt(stmt) end\n  else\n    dostmt(aline)\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Write DynASM header.\nlocal function dasmhead(out)\n  out:write(format([[\n/*\n** This file has been pre-processed with DynASM.\n** %s\n** DynASM version %s, DynASM %s version %s\n** DO NOT EDIT! The original file is in \"%s\".\n*/\n\n]], _info.url,\n    _info.version, g_arch._info.arch, g_arch._info.version,\n    g_fname))\nend\n\n-- Read input file.\nreadfile = function(fin)\n  g_indent = \"\"\n  g_lineno = 0\n  g_synclineno = -1\n\n  -- Process all lines.\n  for line in fin:lines() do\n    g_lineno = g_lineno + 1\n    g_curline = line\n    local ok, err = pcall(doline, line)\n    if not ok and wprinterr(err, \"\\n\") then return true end\n  end\n  wflush()\n\n  -- Close input file.\n  assert(fin == stdin or fin:close())\nend\n\n-- Write output file.\nlocal function writefile(outfile)\n  local fout\n\n  -- Open output file.\n  if outfile == nil or outfile == \"-\" then\n    fout = stdout\n  else\n    fout = assert(io.open(outfile, \"w\"))\n  end\n\n  -- Write all buffered lines\n  wdumplines(fout, g_wbuffer)\n\n  -- Close output file.\n  assert(fout == stdout or fout:close())\n\n  -- Optionally dump definitions.\n  dumpdef(fout == stdout and stderr or stdout)\nend\n\n-- Translate an input file to an output file.\nlocal function translate(infile, outfile)\n  g_wbuffer = {}\n  g_indent = \"\"\n  g_lineno = 0\n  g_synclineno = -1\n\n  -- Put header.\n  wline(dasmhead)\n\n  -- Read input file.\n  local fin\n  if infile == \"-\" then\n    g_fname = \"(stdin)\"\n    fin = stdin\n  else\n    g_fname = infile\n    fin = assert(io.open(infile, \"r\"))\n  end\n  readfile(fin)\n\n  -- Check for errors.\n  if not g_arch then\n    wprinterr(g_fname, \":*: error: missing .arch directive\\n\")\n  end\n  checkconds()\n  checkmacros()\n  checkcaptures()\n\n  if g_errcount ~= 0 then\n    stderr:write(g_fname, \":*: info: \", g_errcount, \" error\",\n      (type(g_errcount) == \"number\" and g_errcount > 1) and \"s\" or \"\",\n      \" in input file -- no output file generated.\\n\")\n    dumpdef(stderr)\n    exit(1)\n  end\n\n  -- Write output file.\n  writefile(outfile)\nend\n\n------------------------------------------------------------------------------\n\n-- Print help text.\nfunction opt_map.help()\n  stdout:write(\"DynASM -- \", _info.description, \".\\n\")\n  stdout:write(\"DynASM \", _info.version, \" \", _info.release, \"  \", _info.url, \"\\n\")\n  stdout:write[[\n\nUsage: dynasm [OPTION]... INFILE.dasc|-\n\n  -h, --help           Display this help text.\n  -V, --version        Display version and copyright information.\n\n  -o, --outfile FILE   Output file name (default is stdout).\n  -I, --include DIR    Add directory to the include search path.\n\n  -c, --ccomment       Use /* */ comments for assembler lines.\n  -C, --cppcomment     Use // comments for assembler lines (default).\n  -N, --nocomment      Suppress assembler lines in output.\n  -M, --maccomment     Show macro expansions as comments (default off).\n\n  -L, --nolineno       Suppress CPP line number information in output.\n  -F, --flushline      Flush action list for every line.\n\n  -D NAME[=SUBST]      Define a substitution.\n  -U NAME              Undefine a substitution.\n\n  -P, --dumpdef        Dump defines, macros, etc. Repeat for more output.\n  -A, --dumparch ARCH  Load architecture ARCH and dump description.\n]]\n  exit(0)\nend\n\n-- Print version information.\nfunction opt_map.version()\n  stdout:write(format(\"%s version %s, released %s\\n%s\\n\\n%s\",\n    _info.name, _info.version, _info.release, _info.url, _info.copyright))\n  exit(0)\nend\n\n-- Misc. options.\nfunction opt_map.outfile(args) g_opt.outfile = optparam(args) end\nfunction opt_map.include(args) insert(g_opt.include, 1, optparam(args)) end\nfunction opt_map.ccomment() g_opt.comment = \"/*|\"; g_opt.endcomment = \" */\" end\nfunction opt_map.cppcomment() g_opt.comment = \"//|\"; g_opt.endcomment = \"\" end\nfunction opt_map.nocomment() g_opt.comment = false end\nfunction opt_map.maccomment() g_opt.maccomment = true end\nfunction opt_map.nolineno() g_opt.cpp = false end\nfunction opt_map.flushline() g_opt.flushline = true end\nfunction opt_map.dumpdef() g_opt.dumpdef = g_opt.dumpdef + 1 end\n\n------------------------------------------------------------------------------\n\n-- Short aliases for long options.\nlocal opt_alias = {\n  h = \"help\", [\"?\"] = \"help\", V = \"version\",\n  o = \"outfile\", I = \"include\",\n  c = \"ccomment\", C = \"cppcomment\", N = \"nocomment\", M = \"maccomment\",\n  L = \"nolineno\", F = \"flushline\",\n  P = \"dumpdef\", A = \"dumparch\",\n}\n\n-- Parse single option.\nlocal function parseopt(opt, args)\n  opt_current = #opt == 1 and \"-\"..opt or \"--\"..opt\n  local f = opt_map[opt] or opt_map[opt_alias[opt]]\n  if not f then\n    opterror(\"unrecognized option `\", opt_current, \"'. Try `--help'.\\n\")\n  end\n  f(args)\nend\n\n-- Parse arguments.\nlocal function parseargs(args)\n  -- Default options.\n  g_opt.comment = \"//|\"\n  g_opt.endcomment = \"\"\n  g_opt.cpp = true\n  g_opt.dumpdef = 0\n  g_opt.include = { \"\" }\n\n  -- Process all option arguments.\n  args.argn = 1\n  repeat\n    local a = args[args.argn]\n    if not a then break end\n    local lopt, opt = match(a, \"^%-(%-?)(.+)\")\n    if not opt then break end\n    args.argn = args.argn + 1\n    if lopt == \"\" then\n      -- Loop through short options.\n      for o in gmatch(opt, \".\") do parseopt(o, args) end\n    else\n      -- Long option.\n      parseopt(opt, args)\n    end\n  until false\n\n  -- Check for proper number of arguments.\n  local nargs = #args - args.argn + 1\n  if nargs ~= 1 then\n    if nargs == 0 then\n      if g_opt.dumpdef > 0 then return dumpdef(stdout) end\n    end\n    opt_map.help()\n  end\n\n  -- Translate a single input file to a single output file\n  -- TODO: Handle multiple files?\n  translate(args[args.argn], g_opt.outfile)\nend\n\n------------------------------------------------------------------------------\n\n-- Add the directory dynasm.lua resides in to the Lua module search path.\nlocal arg = arg\nif arg and arg[0] then\n  prefix = match(arg[0], \"^(.*[/\\\\])\")\n  if package and prefix then package.path = prefix..\"?.lua;\"..package.path end\nend\n\n-- Start DynASM.\nparseargs{...}\n\n------------------------------------------------------------------------------\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/etc/luajit.1",
    "content": ".TH luajit 1 \"\" \"\" \"LuaJIT documentation\"\n.SH NAME\nluajit \\- Just-In-Time Compiler for the Lua Language\n\\fB\n.SH SYNOPSIS\n.B luajit\n[\\fIoptions\\fR]... [\\fIscript\\fR [\\fIargs\\fR]...]\n.SH \"WEB SITE\"\n.IR https://luajit.org\n.SH DESCRIPTION\n.PP\nThis is the command-line program to run Lua programs with \\fBLuaJIT\\fR.\n.PP\n\\fBLuaJIT\\fR is a just-in-time (JIT) compiler for the Lua language.\nThe virtual machine (VM) is based on a fast interpreter combined with\na trace compiler. It can significantly improve the performance of Lua programs.\n.PP\n\\fBLuaJIT\\fR is API\\- and ABI-compatible with the VM of the standard\nLua\\ 5.1 interpreter. When embedding the VM into an application,\nthe built library can be used as a drop-in replacement.\n.SH OPTIONS\n.TP\n.BI \"\\-e \" chunk\nRun the given chunk of Lua code.\n.TP\n.BI \"\\-l \" library\nLoad the named library, just like \\fBrequire(\"\\fR\\fIlibrary\\fR\\fB\")\\fR.\n.TP\n.BI \"\\-b \" ...\nSave or list bytecode. Run without arguments to get help on options.\n.TP\n.BI \"\\-j \" command\nPerform LuaJIT control command (optional space after \\fB\\-j\\fR).\n.TP\n.BI \"\\-O\" [opt]\nControl LuaJIT optimizations.\n.TP\n.B \"\\-i\"\nRun in interactive mode.\n.TP\n.B \"\\-v\"\nShow \\fBLuaJIT\\fR version.\n.TP\n.B \"\\-E\"\nIgnore environment variables.\n.TP\n.B \"\\-\\-\"\nStop processing options.\n.TP\n.B \"\\-\"\nRead script from stdin instead.\n.PP\nAfter all options are processed, the given \\fIscript\\fR is run.\nThe arguments are passed in the global \\fIarg\\fR table.\n.PP\nInteractive mode is only entered, if no \\fIscript\\fR and no \\fB\\-e\\fR\noption is given. Interactive mode can be left with EOF (\\fICtrl\\-Z\\fB).\n.SH EXAMPLES\n.TP\nluajit hello.lua world\n\nPrints \"Hello world\", assuming \\fIhello.lua\\fR contains:\n.br\n  print(\"Hello\", arg[1])\n.TP\nluajit \\-e \"local x=0; for i=1,1e9 do x=x+i end; print(x)\"\n\nCalculates the sum of the numbers from 1 to 1000000000.\n.br\nAnd finishes in a reasonable amount of time, too.\n.TP\nluajit \\-jv \\-e \"for i=1,10 do for j=1,10 do for k=1,100 do end end end\"\n\nRuns some nested loops and shows the resulting traces.\n.SH COPYRIGHT\n.PP\n\\fBLuaJIT\\fR is Copyright \\(co 2005-2021 Mike Pall.\n.br\n\\fBLuaJIT\\fR is open source software, released under the MIT license.\n.SH SEE ALSO\n.PP\nMore details in the provided HTML docs or at:\n.IR https://luajit.org\n.br\nMore about the Lua language can be found at:\n.IR https://lua.org/docs.html\n.PP\nlua(1)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/etc/luajit.pc",
    "content": "# Package information for LuaJIT to be used by pkg-config.\nmajver=2\nminver=1\nrelver=0\nversion=${majver}.${minver}.${relver}-beta3\nabiver=5.1\n\nprefix=/usr/local\nmultilib=lib\nexec_prefix=${prefix}\nlibdir=${exec_prefix}/${multilib}\nlibname=luajit-${abiver}\nincludedir=${prefix}/include/luajit-${majver}.${minver}\n\nINSTALL_LMOD=${prefix}/share/lua/${abiver}\nINSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}\n\nName: LuaJIT\nDescription: Just-in-time compiler for Lua\nURL: https://luajit.org\nVersion: ${version}\nRequires:\nLibs: -L${libdir} -l${libname}\nLibs.private: -Wl,-E -lm -ldl\nCflags: -I${includedir}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/.gitignore",
    "content": "luajit\nlj_bcdef.h\nlj_ffdef.h\nlj_libdef.h\nlj_recdef.h\nlj_folddef.h\nlj_vm.[sS]\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/Makefile",
    "content": "##############################################################################\n# LuaJIT Makefile. Requires GNU Make.\n#\n# Please read doc/install.html before changing any variables!\n#\n# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).\n# Also works with MinGW and Cygwin on Windows.\n# Please check msvcbuild.bat for building with MSVC on Windows.\n#\n# Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n##############################################################################\n\nMAJVER=  2\nMINVER=  1\nRELVER=  0\nABIVER=  5.1\nNODOTABIVER= 51\n\n##############################################################################\n#############################  COMPILER OPTIONS  #############################\n##############################################################################\n# These options mainly affect the speed of the JIT compiler itself, not the\n# speed of the JIT-compiled code. Turn any of the optional settings on by\n# removing the '#' in front of them. Make sure you force a full recompile\n# with \"make clean\", followed by \"make\" if you change any options.\n#\nDEFAULT_CC = gcc\n#\n# LuaJIT builds as a native 32 or 64 bit binary by default.\nCC= $(DEFAULT_CC)\n#\n# Use this if you want to force a 32 bit build on a 64 bit multilib OS.\n#CC= $(DEFAULT_CC) -m32\n#\n# Since the assembler part does NOT maintain a frame pointer, it's pointless\n# to slow down the C part by not omitting it. Debugging, tracebacks and\n# unwinding are not affected -- the assembler part has frame unwind\n# information and GCC emits it where needed (x64) or with -g (see CCDEBUG).\nCCOPT= -O2 -fomit-frame-pointer\n# Use this if you want to generate a smaller binary (but it's slower):\n#CCOPT= -Os -fomit-frame-pointer\n# Note: it's no longer recommended to use -O3 with GCC 4.x.\n# The I-Cache bloat usually outweighs the benefits from aggressive inlining.\n#\n# Target-specific compiler options:\n#\n# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute\n# the binaries to a different machine you could also use: -march=native\n#\nCCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse\nCCOPT_x64=\nCCOPT_arm=\nCCOPT_arm64=\nCCOPT_ppc=\nCCOPT_mips=\n#\nCCDEBUG=\n# Uncomment the next line to generate debug information:\n#CCDEBUG= -g\n#\nCCWARN= -Wall\n# Uncomment the next line to enable more warnings:\n#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith\n#\n##############################################################################\n\n##############################################################################\n################################  BUILD MODE  ################################\n##############################################################################\n# The default build mode is mixed mode on POSIX. On Windows this is the same\n# as dynamic mode.\n#\n# Mixed mode creates a static + dynamic library and a statically linked luajit.\nBUILDMODE= mixed\n#\n# Static mode creates a static library and a statically linked luajit.\n#BUILDMODE= static\n#\n# Dynamic mode creates a dynamic library and a dynamically linked luajit.\n# Note: this executable will only run when the library is installed!\n#BUILDMODE= dynamic\n#\n##############################################################################\n\n##############################################################################\n#################################  FEATURES  #################################\n##############################################################################\n# Enable/disable these features as needed, but make sure you force a full\n# recompile with \"make clean\", followed by \"make\".\nXCFLAGS=\n#\n# Permanently disable the FFI extension to reduce the size of the LuaJIT\n# executable. But please consider that the FFI library is compiled-in,\n# but NOT loaded by default. It only allocates any memory, if you actually\n# make use of it.\n#XCFLAGS+= -DLUAJIT_DISABLE_FFI\n#\n# Features from Lua 5.2 that are unlikely to break existing code are\n# enabled by default. Some other features that *might* break some existing\n# code (e.g. __pairs or os.execute() return values) can be enabled here.\n# Note: this does not provide full compatibility with Lua 5.2 at this time.\n#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT\n#\n# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.\n#XCFLAGS+= -DLUAJIT_DISABLE_JIT\n#\n# Some architectures (e.g. PPC) can use either single-number (1) or\n# dual-number (2) mode. Uncomment one of these lines to override the\n# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.\n#XCFLAGS+= -DLUAJIT_NUMMODE=1\n#XCFLAGS+= -DLUAJIT_NUMMODE=2\n#\n# Disable LJ_GC64 mode for x64.\n#XCFLAGS+= -DLUAJIT_DISABLE_GC64\n#\n##############################################################################\n\n##############################################################################\n############################  DEBUGGING SUPPORT  #############################\n##############################################################################\n# Enable these options as needed, but make sure you force a full recompile\n# with \"make clean\", followed by \"make\".\n# Note that most of these are NOT suitable for benchmarking or release mode!\n#\n# Use the system provided memory allocator (realloc) instead of the\n# bundled memory allocator. This is slower, but sometimes helpful for\n# debugging. This option cannot be enabled on x64 without GC64, since\n# realloc usually doesn't return addresses in the right address range.\n# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and\n# the only way to get useful results from it for all other architectures.\n#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC\n#\n# This define is required to run LuaJIT under Valgrind. The Valgrind\n# header files must be installed. You should enable debug information, too.\n#XCFLAGS+= -DLUAJIT_USE_VALGRIND\n#\n# This is the client for the GDB JIT API. GDB 7.0 or higher is required\n# to make use of it. See lj_gdbjit.c for details. Enabling this causes\n# a non-negligible overhead, even when not running under GDB.\n#XCFLAGS+= -DLUAJIT_USE_GDBJIT\n#\n# Turn on assertions for the Lua/C API to debug problems with lua_* calls.\n# This is rather slow -- use only while developing C libraries/embeddings.\n#XCFLAGS+= -DLUA_USE_APICHECK\n#\n# Turn on assertions for the whole LuaJIT VM. This significantly slows down\n# everything. Use only if you suspect a problem with LuaJIT itself.\n#XCFLAGS+= -DLUA_USE_ASSERT\n#\n##############################################################################\n# You probably don't need to change anything below this line!\n##############################################################################\n\n##############################################################################\n# Host system detection.\n##############################################################################\n\nifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))\n  HOST_SYS= Windows\nelse\n  HOST_SYS:= $(shell uname -s)\n  ifneq (,$(findstring MINGW,$(HOST_SYS)))\n    HOST_SYS= Windows\n    HOST_MSYS= mingw\n  endif\n  ifneq (,$(findstring MSYS,$(HOST_SYS)))\n    HOST_SYS= Windows\n    HOST_MSYS= mingw\n  endif\n  ifneq (,$(findstring CYGWIN,$(HOST_SYS)))\n    HOST_SYS= Windows\n    HOST_MSYS= cygwin\n  endif\nendif\n\n##############################################################################\n# Flags and options for host and target.\n##############################################################################\n\n# You can override the following variables at the make command line:\n#   CC       HOST_CC       STATIC_CC       DYNAMIC_CC\n#   CFLAGS   HOST_CFLAGS   TARGET_CFLAGS\n#   LDFLAGS  HOST_LDFLAGS  TARGET_LDFLAGS  TARGET_SHLDFLAGS\n#   LIBS     HOST_LIBS     TARGET_LIBS\n#   CROSS    HOST_SYS      TARGET_SYS      TARGET_FLAGS\n#\n# Cross-compilation examples:\n#   make HOST_CC=\"gcc -m32\" CROSS=i586-mingw32msvc- TARGET_SYS=Windows\n#   make HOST_CC=\"gcc -m32\" CROSS=powerpc-linux-gnu-\n\nASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)\nCCOPTIONS= $(CCDEBUG) $(ASOPTIONS)\nLDOPTIONS= $(CCDEBUG) $(LDFLAGS)\n\nHOST_CC= $(CC)\nHOST_RM?= rm -f\n# If left blank, minilua is built and used. You can supply an installed\n# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua\nHOST_LUA=\n\nHOST_XCFLAGS= -I.\nHOST_XLDFLAGS=\nHOST_XLIBS=\nHOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)\nHOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)\nHOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)\n\nSTATIC_CC = $(CROSS)$(CC)\nDYNAMIC_CC = $(CROSS)$(CC) -fPIC\nTARGET_CC= $(STATIC_CC)\nTARGET_STCC= $(STATIC_CC)\nTARGET_DYNCC= $(DYNAMIC_CC)\nTARGET_LD= $(CROSS)$(CC)\nTARGET_AR= $(CROSS)ar rcus\nTARGET_STRIP= $(CROSS)strip\n\nTARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)\nTARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)\nTARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib\nTARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)\nTARGET_DLLNAME= lua$(NODOTABIVER).dll\nTARGET_DLLDOTANAME= libluajit-$(ABIVER).dll.a\nTARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)\nTARGET_DYNXLDOPTS=\n\nTARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE\nTARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE\nTARGET_XLDFLAGS=\nTARGET_XLIBS= -lm\nTARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ASFLAGS= $(ASOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)\nTARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)\nTARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)\nTARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)\n\nTARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)\nifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= x64\nelse\nifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= x86\nelse\nifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))\n  TARGET_LJARCH= arm\nelse\nifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH)))\n  ifneq (,$(findstring __AARCH64EB__ ,$(TARGET_TESTARCH)))\n    TARGET_ARCH= -D__AARCH64EB__=1\n  endif\n  TARGET_LJARCH= arm64\nelse\nifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))\n  ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))\n    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_LE\n  else\n    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_BE\n  endif\n  TARGET_LJARCH= ppc\nelse\nifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))\n  ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))\n    TARGET_ARCH= -D__MIPSEL__=1\n  endif\n  ifneq (,$(findstring LJ_TARGET_MIPS64 ,$(TARGET_TESTARCH)))\n    TARGET_LJARCH= mips64\n  else\n    TARGET_LJARCH= mips\n  endif\nelse\n  $(error Unsupported target architecture)\nendif\nendif\nendif\nendif\nendif\nendif\n\nifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))\n  TARGET_SYS= PS3\n  TARGET_ARCH+= -D__CELLOS_LV2__\n  TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC\n  TARGET_XLIBS+= -lpthread\nendif\n\nTARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))\nTARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))\n\nifneq (,$(PREFIX))\nifneq (/usr/local,$(PREFIX))\n  TARGET_XCFLAGS+= -DLUA_ROOT=\\\"$(PREFIX)\\\"\n  ifneq (/usr,$(PREFIX))\n    TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)\n  endif\nendif\nendif\nifneq (,$(MULTILIB))\n  TARGET_XCFLAGS+= -DLUA_MULTILIB=\\\"$(MULTILIB)\\\"\nendif\nifneq (,$(LMULTILIB))\n  TARGET_XCFLAGS+= -DLUA_LMULTILIB=\\\"$(LMULTILIB)\\\"\nendif\n\n##############################################################################\n# Target system detection.\n##############################################################################\n\nTARGET_SYS?= $(HOST_SYS)\nifeq (Windows,$(TARGET_SYS))\n  TARGET_STRIP+= --strip-unneeded\n  TARGET_XSHLDFLAGS= -shared -Wl,--out-implib,$(TARGET_DLLDOTANAME)\n  TARGET_DYNXLDOPTS=\nelse\n  TARGET_AR+= 2>/dev/null\nifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))\n  TARGET_XCFLAGS+= -fno-stack-protector\nendif\nifeq (Darwin,$(TARGET_SYS))\n  ifeq (,$(MACOSX_DEPLOYMENT_TARGET))\n    $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)\n  endif\n  TARGET_STRIP+= -x\n  TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL\n  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC\n  TARGET_DYNXLDOPTS=\n  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)\nelse\nifeq (iOS,$(TARGET_SYS))\n  TARGET_STRIP+= -x\n  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC\n  TARGET_DYNXLDOPTS=\n  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)\n  ifeq (arm64,$(TARGET_LJARCH))\n    TARGET_XCFLAGS+= -fno-omit-frame-pointer\n  endif\nelse\n  ifeq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))\n    # Find out whether the target toolchain always generates unwind tables.\n    TARGET_TESTUNWIND=$(shell exec 2>/dev/null; echo 'extern void b(void);int a(void){b();return 0;}' | $(TARGET_CC) -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o)\n    ifneq (,$(findstring E,$(TARGET_TESTUNWIND)))\n      TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL\n    endif\n  endif\n  ifneq (SunOS,$(TARGET_SYS))\n    ifneq (PS3,$(TARGET_SYS))\n      TARGET_XLDFLAGS+= -Wl,-E\n    endif\n  endif\n  ifeq (Linux,$(TARGET_SYS))\n    TARGET_XLIBS+= -ldl\n  endif\n  ifeq (GNU/kFreeBSD,$(TARGET_SYS))\n    TARGET_XLIBS+= -ldl\n  endif\nendif\nendif\nendif\n\nifneq ($(HOST_SYS),$(TARGET_SYS))\n  ifeq (Windows,$(TARGET_SYS))\n    HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS\n  else\n  ifeq (Linux,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX\n  else\n  ifeq (Darwin,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX\n  else\n  ifeq (iOS,$(TARGET_SYS))\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX -DTARGET_OS_IPHONE=1\n  else\n    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER\n  endif\n  endif\n  endif\n  endif\nendif\n\nifneq (,$(CCDEBUG))\n  TARGET_STRIP= @:\nendif\n\n##############################################################################\n# Files and pathnames.\n##############################################################################\n\nMINILUA_O= host/minilua.o\nMINILUA_LIBS= -lm\nMINILUA_T= host/minilua\nMINILUA_X= $(MINILUA_T)\n\nifeq (,$(HOST_LUA))\n  HOST_LUA= $(MINILUA_X)\n  DASM_DEP= $(MINILUA_T)\nendif\n\nDASM_DIR= ../dynasm\nDASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua\nDASM_XFLAGS=\nDASM_AFLAGS=\nDASM_ARCH= $(TARGET_LJARCH)\n\nifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D ENDIAN_LE\nelse\n  DASM_AFLAGS+= -D ENDIAN_BE\nendif\nifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D P64\nendif\nifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D JIT\nendif\nifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D FFI\nendif\nifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D DUALNUM\nendif\nifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D FPU\n  TARGET_ARCH+= -DLJ_ARCH_HASFPU=1\nelse\n  TARGET_ARCH+= -DLJ_ARCH_HASFPU=0\nendif\nifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D HFABI\n  TARGET_ARCH+= -DLJ_ABI_SOFTFP=0\nelse\n  TARGET_ARCH+= -DLJ_ABI_SOFTFP=1\nendif\nifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D NO_UNWIND\n  TARGET_ARCH+= -DLUAJIT_NO_UNWIND\nendif\nDASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))\nifeq (Windows,$(TARGET_SYS))\n  DASM_AFLAGS+= -D WIN\nendif\nifeq (x64,$(TARGET_LJARCH))\n  ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))\n    DASM_ARCH= x86\n  endif\nelse\nifeq (arm,$(TARGET_LJARCH))\n  ifeq (iOS,$(TARGET_SYS))\n    DASM_AFLAGS+= -D IOS\n  endif\nelse\nifneq (,$(findstring LJ_TARGET_MIPSR6 ,$(TARGET_TESTARCH)))\n  DASM_AFLAGS+= -D MIPSR6\nendif\nifeq (ppc,$(TARGET_LJARCH))\n  ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D SQRT\n  endif\n  ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D ROUND\n  endif\n  ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))\n    DASM_AFLAGS+= -D GPR64\n  endif\n  ifeq (PS3,$(TARGET_SYS))\n    DASM_AFLAGS+= -D PPE -D TOC\n  endif\nendif\nendif\nendif\n\nDASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)\nDASM_DASC= vm_$(DASM_ARCH).dasc\n\nBUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \\\n\t   host/buildvm_lib.o host/buildvm_fold.o\nBUILDVM_T= host/buildvm\nBUILDVM_X= $(BUILDVM_T)\n\nHOST_O= $(MINILUA_O) $(BUILDVM_O)\nHOST_T= $(MINILUA_T) $(BUILDVM_T)\n\nLJVM_S= lj_vm.S\nLJVM_O= lj_vm.o\nLJVM_BOUT= $(LJVM_S)\nLJVM_MODE= elfasm\n\nLJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \\\n\t lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o \\\n\t lib_buffer.o\nLJLIB_C= $(LJLIB_O:.o=.c)\n\nLJCORE_O= lj_assert.o lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \\\n\t  lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \\\n\t  lj_prng.o lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o \\\n\t  lj_strscan.o lj_strfmt.o lj_strfmt_num.o lj_serialize.o \\\n\t  lj_api.o lj_profile.o \\\n\t  lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \\\n\t  lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \\\n\t  lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \\\n\t  lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \\\n\t  lj_asm.o lj_trace.o lj_gdbjit.o \\\n\t  lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \\\n\t  lj_carith.o lj_clib.o lj_cparse.o \\\n\t  lj_lib.o lj_alloc.o lib_aux.o \\\n\t  $(LJLIB_O) lib_init.o\n\nLJVMCORE_O= $(LJVM_O) $(LJCORE_O)\nLJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)\n\nLIB_VMDEF= jit/vmdef.lua\nLIB_VMDEFP= $(LIB_VMDEF)\n\nLUAJIT_O= luajit.o\nLUAJIT_A= libluajit.a\nLUAJIT_SO= libluajit.so\nLUAJIT_T= luajit\n\nALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)\nALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \\\n\t    host/buildvm_arch.h\nALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)\nWIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk\nALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)\n\n##############################################################################\n# Build mode handling.\n##############################################################################\n\n# Mixed mode defaults.\nTARGET_O= $(LUAJIT_A)\nTARGET_T= $(LUAJIT_T) $(LUAJIT_SO)\nTARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)\n\nifeq (Windows,$(TARGET_SYS))\n  TARGET_DYNCC= $(STATIC_CC)\n  LJVM_MODE= peobj\n  LJVM_BOUT= $(LJVM_O)\n  LUAJIT_T= luajit.exe\n  ifeq (cygwin,$(HOST_MSYS))\n    LUAJIT_SO= cyg$(TARGET_DLLNAME)\n  else\n    LUAJIT_SO= $(TARGET_DLLNAME)\n  endif\n  # Mixed mode is not supported on Windows. And static mode doesn't work well.\n  # C modules cannot be loaded, because they bind to lua51.dll.\n  ifneq (static,$(BUILDMODE))\n    BUILDMODE= dynamic\n    TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL\n  endif\nendif\nifeq (Darwin,$(TARGET_SYS))\n  LJVM_MODE= machasm\nendif\nifeq (iOS,$(TARGET_SYS))\n  LJVM_MODE= machasm\nendif\nifeq (SunOS,$(TARGET_SYS))\n  BUILDMODE= static\nendif\nifeq (PS3,$(TARGET_SYS))\n  BUILDMODE= static\nendif\n\nifeq (Windows,$(HOST_SYS))\n  MINILUA_T= host/minilua.exe\n  BUILDVM_T= host/buildvm.exe\n  ifeq (,$(HOST_MSYS))\n    MINILUA_X= host\\minilua\n    BUILDVM_X= host\\buildvm\n    ALL_RM:= $(subst /,\\,$(ALL_RM))\n    HOST_RM= del\n  endif\nendif\n\nifeq (static,$(BUILDMODE))\n  TARGET_DYNCC= @:\n  TARGET_T= $(LUAJIT_T)\n  TARGET_DEP= $(LIB_VMDEF)\nelse\nifeq (dynamic,$(BUILDMODE))\n  ifneq (Windows,$(TARGET_SYS))\n    TARGET_CC= $(DYNAMIC_CC)\n  endif\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\n  TARGET_O= $(LUAJIT_SO)\n  TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)\nelse\nifeq (Darwin,$(TARGET_SYS))\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\nendif\nifeq (iOS,$(TARGET_SYS))\n  TARGET_DYNCC= @:\n  LJVMCORE_DYNO= $(LJVMCORE_O)\nendif\nendif\nendif\n\nQ= @\nE= @echo\n#Q=\n#E= @:\n\n##############################################################################\n# Make targets.\n##############################################################################\n\ndefault all:\t$(TARGET_T)\n\namalg:\n\t$(MAKE) all \"LJCORE_O=ljamalg.o\"\n\nclean:\n\t$(HOST_RM) $(ALL_RM)\n\nlibbc:\n\t./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)\n\t$(MAKE) all\n\ndepend:\n\t@for file in $(ALL_HDRGEN); do \\\n\t  test -f $$file || touch $$file; \\\n\t  done\n\t@$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \\\n\t  sed -e \"s| [^ ]*/dasm_\\S*\\.h||g\" \\\n\t      -e \"s|^\\([^l ]\\)|host/\\1|\" \\\n\t      -e \"s| lj_target_\\S*\\.h| lj_target_*.h|g\" \\\n\t      -e \"s| lj_emit_\\S*\\.h| lj_emit_*.h|g\" \\\n\t      -e \"s| lj_asm_\\S*\\.h| lj_asm_*.h|g\" >Makefile.dep\n\t@for file in $(ALL_HDRGEN); do \\\n\t  test -s $$file || $(HOST_RM) $$file; \\\n\t  done\n\n.PHONY: default all amalg clean libbc depend\n\n##############################################################################\n# Rules for generated files.\n##############################################################################\n\n$(MINILUA_T): $(MINILUA_O)\n\t$(E) \"HOSTLINK  $@\"\n\t$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)\n\nhost/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua lj_arch.h lua.h luaconf.h\n\t$(E) \"DYNASM    $@\"\n\t$(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)\n\nhost/buildvm.o: $(DASM_DIR)/dasm_*.h\n\n$(BUILDVM_T): $(BUILDVM_O)\n\t$(E) \"HOSTLINK  $@\"\n\t$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)\n\n$(LJVM_BOUT): $(BUILDVM_T)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@\n\nlj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)\n\nlj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)\n\nlj_libdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)\n\nlj_recdef.h: $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)\n\n$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)\n\nlj_folddef.h: $(BUILDVM_T) lj_opt_fold.c\n\t$(E) \"BUILDVM   $@\"\n\t$(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c\n\n##############################################################################\n# Object file rules.\n##############################################################################\n\n%.o: %.c\n\t$(E) \"CC        $@\"\n\t$(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<\n\t$(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<\n\n%.o: %.S\n\t$(E) \"ASM       $@\"\n\t$(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<\n\t$(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<\n\n$(LUAJIT_O):\n\t$(E) \"CC        $@\"\n\t$(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<\n\n$(HOST_O): %.o: %.c\n\t$(E) \"HOSTCC    $@\"\n\t$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<\n\ninclude Makefile.dep\n\n##############################################################################\n# Target file rules.\n##############################################################################\n\n$(LUAJIT_A): $(LJVMCORE_O)\n\t$(E) \"AR        $@\"\n\t$(Q)$(TARGET_AR) $@ $(LJVMCORE_O)\n\n# The dependency on _O, but linking with _DYNO is intentional.\n$(LUAJIT_SO): $(LJVMCORE_O)\n\t$(E) \"DYNLINK   $@\"\n\t$(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)\n\t$(Q)$(TARGET_STRIP) $@\n\n$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)\n\t$(E) \"LINK      $@\"\n\t$(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)\n\t$(Q)$(TARGET_STRIP) $@\n\t$(E) \"OK        Successfully built LuaJIT\"\n\n##############################################################################\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/Makefile.dep",
    "content": "lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_state.h lj_trace.h lj_jit.h lj_ir.h \\\n lj_dispatch.h lj_bc.h lj_traceerr.h lj_lib.h\nlib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h \\\n lj_str.h lj_tab.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h \\\n lj_cconv.h lj_ff.h lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h \\\n lj_strscan.h lj_strfmt.h lj_lib.h lj_libdef.h\nlib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_strscan.h \\\n lj_strfmt.h lj_ctype.h lj_cdata.h lj_cconv.h lj_carith.h lj_ff.h \\\n lj_ffdef.h lj_lib.h lj_libdef.h\nlib_buffer.o: lib_buffer.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \\\n lj_tab.h lj_udata.h lj_meta.h lj_ctype.h lj_cdata.h lj_cconv.h \\\n lj_strfmt.h lj_serialize.h lj_lib.h lj_libdef.h\nlib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \\\n lj_libdef.h\nlib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \\\n lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \\\n lj_ccallback.h lj_clib.h lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h \\\n lj_libdef.h\nlib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h\nlib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_state.h \\\n lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h\nlib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \\\n lj_state.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \\\n lj_target.h lj_target_*.h lj_trace.h lj_dispatch.h lj_traceerr.h \\\n lj_vm.h lj_vmevent.h lj_lib.h luajit.h lj_libdef.h\nlib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_prng.h lj_libdef.h\nlib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_lib.h \\\n lj_libdef.h\nlib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h\nlib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \\\n lj_tab.h lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h \\\n lj_char.h lj_strfmt.h lj_lib.h lj_libdef.h\nlib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h \\\n lj_tab.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h\nlj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h \\\n lj_prng.h\nlj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \\\n lj_meta.h lj_state.h lj_bc.h lj_frame.h lj_trace.h lj_jit.h lj_ir.h \\\n lj_dispatch.h lj_traceerr.h lj_vm.h lj_strscan.h lj_strfmt.h\nlj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_buf.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_ir.h \\\n lj_jit.h lj_ircall.h lj_iropt.h lj_mcode.h lj_trace.h lj_dispatch.h \\\n lj_traceerr.h lj_snap.h lj_asm.h lj_vm.h lj_target.h lj_target_*.h \\\n lj_emit_*.h lj_asm_*.h\nlj_assert.o: lj_assert.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h\nlj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \\\n lj_bcdef.h\nlj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_bc.h \\\n lj_ctype.h lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h \\\n lj_strfmt.h\nlj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_buf.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h \\\n lj_ir.h lj_strfmt.h lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h\nlj_buf.o: lj_buf.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_strfmt.h\nlj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ir.h lj_ctype.h \\\n lj_cconv.h lj_cdata.h lj_carith.h lj_strscan.h\nlj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h \\\n lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \\\n lj_traceerr.h\nlj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \\\n lj_bc.h lj_ctype.h lj_cconv.h lj_ccall.h lj_ccallback.h lj_target.h \\\n lj_target_*.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h\nlj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ctype.h \\\n lj_cdata.h lj_cconv.h lj_ccallback.h\nlj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_cconv.h lj_cdata.h\nlj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h\nlj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \\\n lj_cdata.h lj_clib.h lj_strfmt.h\nlj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_ctype.h lj_cparse.h \\\n lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h\nlj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_gc.h \\\n lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \\\n lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \\\n lj_crecord.h lj_strfmt.h\nlj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \\\n lj_ccallback.h lj_buf.h\nlj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \\\n lj_state.h lj_frame.h lj_bc.h lj_strfmt.h lj_jit.h lj_ir.h\nlj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_func.h lj_tab.h \\\n lj_meta.h lj_debug.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \\\n lj_strfmt.h lj_jit.h lj_ir.h lj_ccallback.h lj_ctype.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_profile.h lj_vm.h luajit.h\nlj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \\\n lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \\\n lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h lj_strfmt.h\nlj_ffrecord.o: lj_ffrecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_frame.h \\\n lj_bc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \\\n lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h \\\n lj_crecord.h lj_vm.h lj_strscan.h lj_strfmt.h lj_serialize.h lj_recdef.h\nlj_func.o: lj_func.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_func.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \\\n lj_traceerr.h lj_vm.h\nlj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_func.h lj_udata.h \\\n lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h \\\n lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h\nlj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_buf.h \\\n lj_str.h lj_strfmt.h lj_jit.h lj_ir.h lj_dispatch.h\nlj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_buf.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \\\n lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h \\\n lj_carith.h lj_vm.h lj_strscan.h lj_serialize.h lj_strfmt.h lj_prng.h\nlj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h \\\n lualib.h lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h \\\n lj_strfmt.h\nlj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \\\n lj_dispatch.h lj_jit.h lj_ir.h lj_ctype.h lj_vm.h lj_strscan.h \\\n lj_strfmt.h lj_lex.h lj_bcdump.h lj_lib.h\nlj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \\\n lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_func.h \\\n lj_frame.h lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h\nlj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_jit.h lj_ir.h lj_mcode.h lj_trace.h \\\n lj_dispatch.h lj_bc.h lj_traceerr.h lj_prng.h lj_vm.h\nlj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_meta.h lj_frame.h \\\n lj_bc.h lj_vm.h lj_strscan.h lj_strfmt.h lj_lib.h\nlj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h\nlj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_jit.h lj_iropt.h\nlj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \\\n lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \\\n lj_carith.h lj_vm.h lj_strscan.h lj_strfmt.h lj_folddef.h\nlj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \\\n lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \\\n lj_vm.h\nlj_opt_mem.o: lj_opt_mem.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_ircall.h lj_dispatch.h lj_bc.h\nlj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h lj_strscan.h\nlj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h\nlj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h \\\n lj_jit.h lj_ircall.h lj_iropt.h lj_dispatch.h lj_bc.h lj_vm.h\nlj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \\\n lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_strfmt.h lj_lex.h lj_parse.h \\\n lj_vm.h lj_vmevent.h\nlj_prng.o: lj_prng.c lj_def.h lua.h luaconf.h lj_arch.h lj_prng.h\nlj_profile.o: lj_profile.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_buf.h lj_gc.h lj_str.h lj_frame.h lj_bc.h lj_debug.h lj_dispatch.h \\\n lj_jit.h lj_ir.h lj_trace.h lj_traceerr.h lj_profile.h luajit.h\nlj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \\\n lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_debug.h lj_ir.h lj_jit.h \\\n lj_ircall.h lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h \\\n lj_record.h lj_ffrecord.h lj_snap.h lj_vm.h lj_prng.h\nlj_serialize.o: lj_serialize.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_tab.h \\\n lj_udata.h lj_ctype.h lj_cdata.h lj_ir.h lj_serialize.h\nlj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \\\n lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \\\n lj_target_*.h lj_ctype.h lj_cdata.h\nlj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_tab.h lj_func.h \\\n lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h \\\n lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_prng.h lj_lex.h \\\n lj_alloc.h luajit.h\nlj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_str.h lj_char.h lj_prng.h\nlj_strfmt.o: lj_strfmt.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_meta.h lj_state.h \\\n lj_char.h lj_strfmt.h lj_ctype.h lj_lib.h\nlj_strfmt_num.o: lj_strfmt_num.c lj_obj.h lua.h luaconf.h lj_def.h \\\n lj_arch.h lj_buf.h lj_gc.h lj_str.h lj_strfmt.h\nlj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_char.h lj_strscan.h\nlj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \\\n lj_err.h lj_errmsg.h lj_tab.h\nlj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_frame.h lj_bc.h \\\n lj_state.h lj_ir.h lj_jit.h lj_iropt.h lj_mcode.h lj_trace.h \\\n lj_dispatch.h lj_traceerr.h lj_snap.h lj_gdbjit.h lj_record.h lj_asm.h \\\n lj_vm.h lj_vmevent.h lj_target.h lj_target_*.h lj_prng.h\nlj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_gc.h lj_err.h lj_errmsg.h lj_udata.h\nlj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \\\n lj_vm.h lj_vmevent.h\nlj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \\\n lj_ir.h lj_vm.h\nljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_assert.c lj_obj.h \\\n lj_def.h lj_arch.h lj_gc.c lj_gc.h lj_err.h lj_errmsg.h lj_buf.h \\\n lj_str.h lj_tab.h lj_func.h lj_udata.h lj_meta.h lj_state.h lj_frame.h \\\n lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \\\n lj_traceerr.h lj_vm.h lj_err.c lj_debug.h lj_ff.h lj_ffdef.h lj_strfmt.h \\\n lj_char.c lj_char.h lj_bc.c lj_bcdef.h lj_obj.c lj_buf.c lj_str.c \\\n lj_prng.h lj_tab.c lj_func.c lj_udata.c lj_meta.c lj_strscan.h lj_lib.h \\\n lj_debug.c lj_prng.c lj_state.c lj_lex.h lj_alloc.h luajit.h \\\n lj_dispatch.c lj_ccallback.h lj_profile.h lj_vmevent.c lj_vmevent.h \\\n lj_vmmath.c lj_strscan.c lj_strfmt.c lj_strfmt_num.c lj_serialize.c \\\n lj_serialize.h lj_api.c lj_profile.c lj_lex.c lualib.h lj_parse.h \\\n lj_parse.c lj_bcread.c lj_bcdump.h lj_bcwrite.c lj_load.c lj_ctype.c \\\n lj_cdata.c lj_cconv.h lj_cconv.c lj_ccall.c lj_ccall.h lj_ccallback.c \\\n lj_target.h lj_target_*.h lj_mcode.h lj_carith.c lj_carith.h lj_clib.c \\\n lj_clib.h lj_cparse.c lj_cparse.h lj_lib.c lj_ir.c lj_ircall.h \\\n lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \\\n lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_opt_split.c lj_opt_sink.c \\\n lj_mcode.c lj_snap.c lj_record.c lj_record.h lj_ffrecord.h lj_crecord.c \\\n lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h lj_emit_*.h \\\n lj_asm_*.h lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c \\\n lib_base.c lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \\\n lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c \\\n lib_buffer.c lib_init.c\nluajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h\nhost/buildvm.o: host/buildvm.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_gc.h lj_obj.h lj_bc.h lj_ir.h \\\n lj_ircall.h lj_ir.h lj_jit.h lj_frame.h lj_bc.h lj_dispatch.h lj_ctype.h \\\n lj_gc.h lj_ccall.h lj_ctype.h luajit.h \\\n host/buildvm_arch.h lj_traceerr.h\nhost/buildvm_asm.o: host/buildvm_asm.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_bc.h lj_def.h lj_arch.h\nhost/buildvm_fold.o: host/buildvm_fold.c host/buildvm.h lj_def.h lua.h \\\n luaconf.h lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_ir.h lj_obj.h\nhost/buildvm_lib.o: host/buildvm_lib.c host/buildvm.h lj_def.h lua.h luaconf.h \\\n lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_bc.h lj_lib.h lj_obj.h \\\n host/buildvm_libbc.h\nhost/buildvm_peobj.o: host/buildvm_peobj.c host/buildvm.h lj_def.h lua.h \\\n luaconf.h lj_arch.h lj_bc.h lj_def.h lj_arch.h\nhost/minilua.o: host/minilua.c\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/.gitignore",
    "content": "minilua\nbuildvm\nbuildvm_arch.h\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/README",
    "content": "The files in this directory are only used during the build process of LuaJIT.\nFor cross-compilation, they must be executed on the host, not on the target.\n\nThese files should NOT be installed!\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm.c",
    "content": "/*\n** LuaJIT VM builder.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** This is a tool to build the hand-tuned assembler code required for\n** LuaJIT's bytecode interpreter. It supports a variety of output formats\n** to feed different toolchains (see usage() below).\n**\n** This tool is not particularly optimized because it's only used while\n** _building_ LuaJIT. There's no point in distributing or installing it.\n** Only the object code generated by this tool is linked into LuaJIT.\n**\n** Caveat: some memory is not free'd, error handling is lazy.\n** It's a one-shot tool -- any effort fixing this would be wasted.\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_ircall.h\"\n#include \"lj_frame.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_ccall.h\"\n#endif\n#include \"luajit.h\"\n\n#if defined(_WIN32)\n#include <fcntl.h>\n#include <io.h>\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n/* DynASM glue definitions. */\n#define Dst\t\tctx\n#define Dst_DECL\tBuildCtx *ctx\n#define Dst_REF\t\t(ctx->D)\n#define DASM_CHECKS\t1\n\n#include \"../dynasm/dasm_proto.h\"\n\n/* Glue macros for DynASM. */\nstatic int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);\n\n#define DASM_EXTERN(ctx, addr, idx, type) \\\n  collect_reloc(ctx, addr, idx, type)\n\n/* ------------------------------------------------------------------------ */\n\n/* Avoid trouble if cross-compiling for an x86 target. Speed doesn't matter. */\n#define DASM_ALIGNED_WRITES\t1\n\n/* Embed architecture-specific DynASM encoder. */\n#if LJ_TARGET_X86ORX64\n#include \"../dynasm/dasm_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"../dynasm/dasm_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"../dynasm/dasm_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"../dynasm/dasm_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"../dynasm/dasm_mips.h\"\n#else\n#error \"No support for this architecture (yet)\"\n#endif\n\n/* Embed generated architecture-specific backend. */\n#include \"buildvm_arch.h\"\n\n/* ------------------------------------------------------------------------ */\n\nvoid owrite(BuildCtx *ctx, const void *ptr, size_t sz)\n{\n  if (fwrite(ptr, 1, sz, ctx->fp) != sz) {\n    fprintf(stderr, \"Error: cannot write to output file: %s\\n\",\n\t    strerror(errno));\n    exit(1);\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Emit code as raw bytes. Only used for DynASM debugging. */\nstatic void emit_raw(BuildCtx *ctx)\n{\n  owrite(ctx, ctx->code, ctx->codesz);\n}\n\n/* -- Build machine code -------------------------------------------------- */\n\nstatic const char *sym_decorate(BuildCtx *ctx,\n\t\t\t\tconst char *prefix, const char *suffix)\n{\n  char name[256];\n  char *p;\n#if LJ_64\n  const char *symprefix = ctx->mode == BUILD_machasm ? \"_\" : \"\";\n#elif LJ_TARGET_XBOX360\n  const char *symprefix = \"\";\n#else\n  const char *symprefix = ctx->mode != BUILD_elfasm ? \"_\" : \"\";\n#endif\n  sprintf(name, \"%s%s%s\", symprefix, prefix, suffix);\n  p = strchr(name, '@');\n  if (p) {\n#if LJ_TARGET_X86ORX64\n    if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj))\n      name[0] = name[1] == 'R' ? '_' : '@';  /* Just for _RtlUnwind@16. */\n    else\n      *p = '\\0';\n#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE\n    /* Keep @plt etc. */\n#else\n    *p = '\\0';\n#endif\n  }\n  p = (char *)malloc(strlen(name)+1);  /* MSVC doesn't like strdup. */\n  strcpy(p, name);\n  return p;\n}\n\n#define NRELOCSYM\t(sizeof(extnames)/sizeof(extnames[0])-1)\n\nstatic int relocmap[NRELOCSYM];\n\n/* Collect external relocations. */\nstatic int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)\n{\n  if (ctx->nreloc >= BUILD_MAX_RELOC) {\n    fprintf(stderr, \"Error: too many relocations, increase BUILD_MAX_RELOC.\\n\");\n    exit(1);\n  }\n  if (relocmap[idx] < 0) {\n    relocmap[idx] = ctx->nrelocsym;\n    ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, \"\", extnames[idx]);\n    ctx->nrelocsym++;\n  }\n  ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code);\n  ctx->reloc[ctx->nreloc].sym = relocmap[idx];\n  ctx->reloc[ctx->nreloc].type = type;\n  ctx->nreloc++;\n#if LJ_TARGET_XBOX360\n  return (int)(ctx->code - addr) + 4;  /* Encode symbol offset of .text. */\n#else\n  return 0;  /* Encode symbol offset of 0. */\n#endif\n}\n\n/* Naive insertion sort. Performance doesn't matter here. */\nstatic void sym_insert(BuildCtx *ctx, int32_t ofs,\n\t\t       const char *prefix, const char *suffix)\n{\n  ptrdiff_t i = ctx->nsym++;\n  while (i > 0) {\n    if (ctx->sym[i-1].ofs <= ofs)\n      break;\n    ctx->sym[i] = ctx->sym[i-1];\n    i--;\n  }\n  ctx->sym[i].ofs = ofs;\n  ctx->sym[i].name = sym_decorate(ctx, prefix, suffix);\n}\n\n/* Build the machine code. */\nstatic int build_code(BuildCtx *ctx)\n{\n  int status;\n  int i;\n\n  /* Initialize DynASM structures. */\n  ctx->nglob = GLOB__MAX;\n  ctx->glob = (void **)malloc(ctx->nglob*sizeof(void *));\n  memset(ctx->glob, 0, ctx->nglob*sizeof(void *));\n  ctx->nreloc = 0;\n\n  ctx->globnames = globnames;\n  ctx->extnames = extnames;\n  ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *));\n  ctx->nrelocsym = 0;\n  for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1;\n\n  ctx->dasm_ident = DASM_IDENT;\n  ctx->dasm_arch = DASM_ARCH;\n\n  dasm_init(Dst, DASM_MAXSECTION);\n  dasm_setupglobal(Dst, ctx->glob, ctx->nglob);\n  dasm_setup(Dst, build_actionlist);\n\n  /* Call arch-specific backend to emit the code. */\n  ctx->npc = build_backend(ctx);\n\n  /* Finalize the code. */\n  (void)dasm_checkstep(Dst, -1);\n  if ((status = dasm_link(Dst, &ctx->codesz))) return status;\n  ctx->code = (uint8_t *)malloc(ctx->codesz);\n  if ((status = dasm_encode(Dst, (void *)ctx->code))) return status;\n\n  /* Allocate symbol table and bytecode offsets. */\n  ctx->beginsym = sym_decorate(ctx, \"\", LABEL_PREFIX \"vm_asm_begin\");\n  ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym));\n  ctx->nsym = 0;\n  ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t));\n\n  /* Collect the opcodes (PC labels). */\n  for (i = 0; i < ctx->npc; i++) {\n    int32_t ofs = dasm_getpclabel(Dst, i);\n    if (ofs < 0) return 0x22000000|i;\n    ctx->bc_ofs[i] = ofs;\n    if ((LJ_HASJIT ||\n\t !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP ||\n\t   i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) &&\n\t(LJ_HASFFI || i != BC_KCDATA))\n      sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]);\n  }\n\n  /* Collect the globals (named labels). */\n  for (i = 0; i < ctx->nglob; i++) {\n    const char *gl = globnames[i];\n    int len = (int)strlen(gl);\n    if (!ctx->glob[i]) {\n      fprintf(stderr, \"Error: undefined global %s\\n\", gl);\n      exit(2);\n    }\n    /* Skip the _Z symbols. */\n    if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z'))\n      sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code),\n\t\t LABEL_PREFIX, globnames[i]);\n  }\n\n  /* Close the address range. */\n  sym_insert(ctx, (int32_t)ctx->codesz, \"\", \"\");\n  ctx->nsym--;\n\n  dasm_free(Dst);\n\n  return 0;\n}\n\n/* -- Generate VM enums --------------------------------------------------- */\n\nconst char *const bc_names[] = {\n#define BCNAME(name, ma, mb, mc, mt)       #name,\nBCDEF(BCNAME)\n#undef BCNAME\n  NULL\n};\n\nconst char *const ir_names[] = {\n#define IRNAME(name, m, m1, m2)\t#name,\nIRDEF(IRNAME)\n#undef IRNAME\n  NULL\n};\n\nconst char *const irt_names[] = {\n#define IRTNAME(name, size)\t#name,\nIRTDEF(IRTNAME)\n#undef IRTNAME\n  NULL\n};\n\nconst char *const irfpm_names[] = {\n#define FPMNAME(name)\t\t#name,\nIRFPMDEF(FPMNAME)\n#undef FPMNAME\n  NULL\n};\n\nconst char *const irfield_names[] = {\n#define FLNAME(name, ofs)\t#name,\nIRFLDEF(FLNAME)\n#undef FLNAME\n  NULL\n};\n\nconst char *const ircall_names[] = {\n#define IRCALLNAME(cond, name, nargs, kind, type, flags)\t#name,\nIRCALLDEF(IRCALLNAME)\n#undef IRCALLNAME\n  NULL\n};\n\nstatic const char *const trace_errors[] = {\n#define TREDEF(name, msg)\tmsg,\n#include \"lj_traceerr.h\"\n  NULL\n};\n\nstatic const char *lower(char *buf, const char *s)\n{\n  char *p = buf;\n  while (*s) {\n    *p++ = (*s >= 'A' && *s <= 'Z') ? *s+0x20 : *s;\n    s++;\n  }\n  *p = '\\0';\n  return buf;\n}\n\n/* Emit C source code for bytecode-related definitions. */\nstatic void emit_bcdef(BuildCtx *ctx)\n{\n  int i;\n  fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  fprintf(ctx->fp, \"LJ_DATADEF const uint16_t lj_bc_ofs[] = {\\n\");\n  for (i = 0; i < ctx->npc; i++) {\n    if (i != 0)\n      fprintf(ctx->fp, \",\\n\");\n    fprintf(ctx->fp, \"%d\", ctx->bc_ofs[i]);\n  }\n}\n\n/* Emit VM definitions as Lua code for debug modules. */\nstatic void emit_vmdef(BuildCtx *ctx)\n{\n  char buf[80];\n  int i;\n  fprintf(ctx->fp, \"-- This is a generated file. DO NOT EDIT!\\n\\n\");\n  fprintf(ctx->fp, \"return {\\n\\n\");\n\n  fprintf(ctx->fp, \"bcnames = \\\"\");\n  for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, \"%-6s\", bc_names[i]);\n  fprintf(ctx->fp, \"\\\",\\n\\n\");\n\n  fprintf(ctx->fp, \"irnames = \\\"\");\n  for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, \"%-6s\", ir_names[i]);\n  fprintf(ctx->fp, \"\\\",\\n\\n\");\n\n  fprintf(ctx->fp, \"irfpm = { [0]=\");\n  for (i = 0; irfpm_names[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\", \", lower(buf, irfpm_names[i]));\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"irfield = { [0]=\");\n  for (i = 0; irfield_names[i]; i++) {\n    char *p;\n    lower(buf, irfield_names[i]);\n    p = strchr(buf, '_');\n    if (p) *p = '.';\n    fprintf(ctx->fp, \"\\\"%s\\\", \", buf);\n  }\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"ircall = {\\n[0]=\");\n  for (i = 0; ircall_names[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", ircall_names[i]);\n  fprintf(ctx->fp, \"},\\n\\n\");\n\n  fprintf(ctx->fp, \"traceerr = {\\n[0]=\");\n  for (i = 0; trace_errors[i]; i++)\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", trace_errors[i]);\n  fprintf(ctx->fp, \"},\\n\\n\");\n}\n\n/* -- Argument parsing ---------------------------------------------------- */\n\n/* Build mode names. */\nstatic const char *const modenames[] = {\n#define BUILDNAME(name)\t\t#name,\nBUILDDEF(BUILDNAME)\n#undef BUILDNAME\n  NULL\n};\n\n/* Print usage information and exit. */\nstatic void usage(void)\n{\n  int i;\n  fprintf(stderr, LUAJIT_VERSION \" VM builder.\\n\");\n  fprintf(stderr, LUAJIT_COPYRIGHT \", \" LUAJIT_URL \"\\n\");\n  fprintf(stderr, \"Target architecture: \" LJ_ARCH_NAME \"\\n\\n\");\n  fprintf(stderr, \"Usage: buildvm -m mode [-o outfile] [infiles...]\\n\\n\");\n  fprintf(stderr, \"Available modes:\\n\");\n  for (i = 0; i < BUILD__MAX; i++)\n    fprintf(stderr, \"  %s\\n\", modenames[i]);\n  exit(1);\n}\n\n/* Parse the output mode name. */\nstatic BuildMode parsemode(const char *mode)\n{\n  int i;\n  for (i = 0; modenames[i]; i++)\n    if (!strcmp(mode, modenames[i]))\n      return (BuildMode)i;\n  usage();\n  return (BuildMode)-1;\n}\n\n/* Parse arguments. */\nstatic void parseargs(BuildCtx *ctx, char **argv)\n{\n  const char *a;\n  int i;\n  ctx->mode = (BuildMode)-1;\n  ctx->outname = \"-\";\n  for (i = 1; (a = argv[i]) != NULL; i++) {\n    if (a[0] != '-')\n      break;\n    switch (a[1]) {\n    case '-':\n      if (a[2]) goto err;\n      i++;\n      goto ok;\n    case '\\0':\n      goto ok;\n    case 'm':\n      i++;\n      if (a[2] || argv[i] == NULL) goto err;\n      ctx->mode = parsemode(argv[i]);\n      break;\n    case 'o':\n      i++;\n      if (a[2] || argv[i] == NULL) goto err;\n      ctx->outname = argv[i];\n      break;\n    default: err:\n      usage();\n      break;\n    }\n  }\nok:\n  ctx->args = argv+i;\n  if (ctx->mode == (BuildMode)-1) goto err;\n}\n\nint main(int argc, char **argv)\n{\n  BuildCtx ctx_;\n  BuildCtx *ctx = &ctx_;\n  int status, binmode;\n\n  if (sizeof(void *) != 4*LJ_32+8*LJ_64) {\n    fprintf(stderr,\"Error: pointer size mismatch in cross-build.\\n\");\n    fprintf(stderr,\"Try: make HOST_CC=\\\"gcc -m32\\\" CROSS=...\\n\\n\");\n    return 1;\n  }\n\n  UNUSED(argc);\n  parseargs(ctx, argv);\n\n  if ((status = build_code(ctx))) {\n    fprintf(stderr,\"Error: DASM error %08x\\n\", status);\n    return 1;\n  }\n\n  switch (ctx->mode) {\n  case BUILD_peobj:\n  case BUILD_raw:\n    binmode = 1;\n    break;\n  default:\n    binmode = 0;\n    break;\n  }\n\n  if (ctx->outname[0] == '-' && ctx->outname[1] == '\\0') {\n    ctx->fp = stdout;\n#if defined(_WIN32)\n    if (binmode)\n      _setmode(_fileno(stdout), _O_BINARY);  /* Yuck. */\n#endif\n  } else if (!(ctx->fp = fopen(ctx->outname, binmode ? \"wb\" : \"w\"))) {\n    fprintf(stderr, \"Error: cannot open output file '%s': %s\\n\",\n\t    ctx->outname, strerror(errno));\n    exit(1);\n  }\n\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n  case BUILD_coffasm:\n  case BUILD_machasm:\n    emit_asm(ctx);\n    emit_asm_debug(ctx);\n    break;\n  case BUILD_peobj:\n    emit_peobj(ctx);\n    break;\n  case BUILD_raw:\n    emit_raw(ctx);\n    break;\n  case BUILD_bcdef:\n    emit_bcdef(ctx);\n    emit_lib(ctx);\n    break;\n  case BUILD_vmdef:\n    emit_vmdef(ctx);\n    emit_lib(ctx);\n    fprintf(ctx->fp, \"}\\n\\n\");\n    break;\n  case BUILD_ffdef:\n  case BUILD_libdef:\n  case BUILD_recdef:\n    emit_lib(ctx);\n    break;\n  case BUILD_folddef:\n    emit_fold(ctx);\n    break;\n  default:\n    break;\n  }\n\n  fflush(ctx->fp);\n  if (ferror(ctx->fp)) {\n    fprintf(stderr, \"Error: cannot write to output file: %s\\n\",\n\t    strerror(errno));\n    exit(1);\n  }\n  fclose(ctx->fp);\n\n  return 0;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm.h",
    "content": "/*\n** LuaJIT VM builder.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _BUILDVM_H\n#define _BUILDVM_H\n\n#include <sys/types.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* Hardcoded limits. Increase as needed. */\n#define BUILD_MAX_RELOC\t\t200\t/* Max. number of relocations. */\n#define BUILD_MAX_FOLD\t\t4096\t/* Max. number of fold rules. */\n\n/* Prefix for scanned library definitions. */\n#define LIBDEF_PREFIX\t\t\"LJLIB_\"\n\n/* Prefix for scanned fold definitions. */\n#define FOLDDEF_PREFIX\t\t\"LJFOLD\"\n\n/* Prefixes for generated labels. */\n#define LABEL_PREFIX\t\t\"lj_\"\n#define LABEL_PREFIX_BC\t\tLABEL_PREFIX \"BC_\"\n#define LABEL_PREFIX_FF\t\tLABEL_PREFIX \"ff_\"\n#define LABEL_PREFIX_CF\t\tLABEL_PREFIX \"cf_\"\n#define LABEL_PREFIX_FFH\tLABEL_PREFIX \"ffh_\"\n#define LABEL_PREFIX_LIBCF\tLABEL_PREFIX \"lib_cf_\"\n#define LABEL_PREFIX_LIBINIT\tLABEL_PREFIX \"lib_init_\"\n\n/* Forward declaration. */\nstruct dasm_State;\n\n/* Build modes. */\n#define BUILDDEF(_) \\\n  _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \\\n  _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \\\n  _(folddef)\n\ntypedef enum {\n#define BUILDENUM(name)\t\tBUILD_##name,\nBUILDDEF(BUILDENUM)\n#undef BUILDENUM\n  BUILD__MAX\n} BuildMode;\n\n/* Code relocation. */\ntypedef struct BuildReloc {\n  int32_t ofs;\n  int sym;\n  int type;\n} BuildReloc;\n\ntypedef struct BuildSym {\n  const char *name;\n  int32_t ofs;\n} BuildSym;\n\n/* Build context structure. */\ntypedef struct BuildCtx {\n  /* DynASM state pointer. Should be first member. */\n  struct dasm_State *D;\n  /* Parsed command line. */\n  BuildMode mode;\n  FILE *fp;\n  const char *outname;\n  char **args;\n  /* Code and symbols generated by DynASM. */\n  uint8_t *code;\n  size_t codesz;\n  int npc, nglob, nsym, nreloc, nrelocsym;\n  void **glob;\n  BuildSym *sym;\n  const char **relocsym;\n  int32_t *bc_ofs;\n  const char *beginsym;\n  /* Strings generated by DynASM. */\n  const char *const *globnames;\n  const char *const *extnames;\n  const char *dasm_ident;\n  const char *dasm_arch;\n  /* Relocations. */\n  BuildReloc reloc[BUILD_MAX_RELOC];\n} BuildCtx;\n\nextern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);\nextern void emit_asm(BuildCtx *ctx);\nextern void emit_peobj(BuildCtx *ctx);\nextern void emit_lib(BuildCtx *ctx);\nextern void emit_fold(BuildCtx *ctx);\n\nextern const char *const bc_names[];\nextern const char *const ir_names[];\nextern const char *const irt_names[];\nextern const char *const irfpm_names[];\nextern const char *const irfield_names[];\nextern const char *const ircall_names[];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm_asm.c",
    "content": "/*\n** LuaJIT VM builder: Assembler source code emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_bc.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#if LJ_TARGET_X86ORX64\n/* Emit bytes piecewise as assembler text. */\nstatic void emit_asm_bytes(BuildCtx *ctx, uint8_t *p, int n)\n{\n  int i;\n  for (i = 0; i < n; i++) {\n    if ((i & 15) == 0)\n      fprintf(ctx->fp, \"\\t.byte %d\", p[i]);\n    else\n      fprintf(ctx->fp, \",%d\", p[i]);\n    if ((i & 15) == 15) putc('\\n', ctx->fp);\n  }\n  if ((n & 15) != 0) putc('\\n', ctx->fp);\n}\n\n/* Emit relocation */\nstatic void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    if (type)\n      fprintf(ctx->fp, \"\\t.long %s-.-4\\n\", sym);\n    else\n      fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.def %s; .scl 3; .type 32; .endef\\n\", sym);\n    if (type)\n      fprintf(ctx->fp, \"\\t.long %s-.-4\\n\", sym);\n    else\n      fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  default:  /* BUILD_machasm for relative relocations handled below. */\n    fprintf(ctx->fp, \"\\t.long %s\\n\", sym);\n    break;\n  }\n}\n\nstatic const char *const jccnames[] = {\n  \"jo\", \"jno\", \"jb\", \"jnb\", \"jz\", \"jnz\", \"jbe\", \"ja\",\n  \"js\", \"jns\", \"jpe\", \"jpo\", \"jl\", \"jge\", \"jle\", \"jg\"\n};\n\n/* Emit x86/x64 text relocations. */\nstatic void emit_asm_reloc_text(BuildCtx *ctx, uint8_t *cp, int n,\n\t\t\t\tconst char *sym)\n{\n  const char *opname = NULL;\n  if (--n < 0) goto err;\n  if (cp[n] == 0xe8) {\n    opname = \"call\";\n  } else if (cp[n] == 0xe9) {\n    opname = \"jmp\";\n  } else if (cp[n] >= 0x80 && cp[n] <= 0x8f && n > 0 && cp[n-1] == 0x0f) {\n    opname = jccnames[cp[n]-0x80];\n    n--;\n  } else {\nerr:\n    fprintf(stderr, \"Error: unsupported opcode for %s symbol relocation.\\n\",\n\t    sym);\n    exit(1);\n  }\n  emit_asm_bytes(ctx, cp, n);\n  if (strncmp(sym+(*sym == '_'), LABEL_PREFIX, sizeof(LABEL_PREFIX)-1)) {\n    /* Various fixups for external symbols outside of our binary. */\n    if (ctx->mode == BUILD_elfasm) {\n      if (LJ_32)\n\tfprintf(ctx->fp, \"#if __PIC__\\n\\t%s lj_wrap_%s\\n#else\\n\", opname, sym);\n      fprintf(ctx->fp, \"\\t%s %s@PLT\\n\", opname, sym);\n      if (LJ_32)\n\tfprintf(ctx->fp, \"#endif\\n\");\n      return;\n    } else if (LJ_32 && ctx->mode == BUILD_machasm) {\n      fprintf(ctx->fp, \"\\t%s L%s$stub\\n\", opname, sym);\n      return;\n    }\n  }\n  fprintf(ctx->fp, \"\\t%s %s\\n\", opname, sym);\n}\n#else\n/* Emit words piecewise as assembler text. */\nstatic void emit_asm_words(BuildCtx *ctx, uint8_t *p, int n)\n{\n  int i;\n  for (i = 0; i < n; i += 4) {\n    uint32_t ins = *(uint32_t *)(p+i);\n#if LJ_TARGET_ARM64 && LJ_BE\n    ins = lj_bswap(ins);  /* ARM64 instructions are always little-endian. */\n#endif\n    if ((i & 15) == 0)\n      fprintf(ctx->fp, \"\\t.long 0x%08x\", ins);\n    else\n      fprintf(ctx->fp, \",0x%08x\", ins);\n    if ((i & 15) == 12) putc('\\n', ctx->fp);\n  }\n  if ((n & 15) != 0) putc('\\n', ctx->fp);\n}\n\n/* Emit relocation as part of an instruction. */\nstatic void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n,\n\t\t\t       const char *sym)\n{\n  uint32_t ins;\n  emit_asm_words(ctx, p, n-4);\n  ins = *(uint32_t *)(p+n-4);\n#if LJ_TARGET_ARM\n  if ((ins & 0xff000000u) == 0xfa000000u) {\n    fprintf(ctx->fp, \"\\tblx %s\\n\", sym);\n  } else if ((ins & 0x0e000000u) == 0x0a000000u) {\n    fprintf(ctx->fp, \"\\t%s%.2s %s\\n\", (ins & 0x01000000u) ? \"bl\" : \"b\",\n\t    &\"eqnecsccmiplvsvchilsgeltgtle\"[2*(ins >> 28)], sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_ARM64\n  if ((ins >> 26) == 0x25u) {\n    fprintf(ctx->fp, \"\\tbl %s\\n\", sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_PPC\n#if LJ_TARGET_PS3\n#define TOCPREFIX \".\"\n#else\n#define TOCPREFIX \"\"\n#endif\n  if ((ins >> 26) == 16) {\n    fprintf(ctx->fp, \"\\t%s %d, %d, \" TOCPREFIX \"%s\\n\",\n\t    (ins & 1) ? \"bcl\" : \"bc\", (ins >> 21) & 31, (ins >> 16) & 31, sym);\n  } else if ((ins >> 26) == 18) {\n    fprintf(ctx->fp, \"\\t%s \" TOCPREFIX \"%s\\n\", (ins & 1) ? \"bl\" : \"b\", sym);\n  } else {\n    fprintf(stderr,\n\t    \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t    ins, sym);\n    exit(1);\n  }\n#elif LJ_TARGET_MIPS\n  fprintf(stderr,\n\t  \"Error: unsupported opcode %08x for %s symbol relocation.\\n\",\n\t  ins, sym);\n  exit(1);\n#else\n#error \"missing relocation support for this architecture\"\n#endif\n}\n#endif\n\n#if LJ_TARGET_ARM\n#define ELFASM_PX\t\"%%\"\n#else\n#define ELFASM_PX\t\"@\"\n#endif\n\n/* Emit an assembler label. */\nstatic void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n#if LJ_TARGET_PS3\n    if (!strncmp(name, \"lj_vm_\", 6) &&\n\tstrcmp(name, ctx->beginsym) &&\n\t!strstr(name, \"hook\")) {\n      fprintf(ctx->fp,\n\t\"\\n\\t.globl %s\\n\"\n\t\"\\t.section \\\".opd\\\",\\\"aw\\\"\\n\"\n\t\"%s:\\n\"\n\t\"\\t.long .%s,.TOC.@tocbase32\\n\"\n\t\"\\t.size %s,8\\n\"\n\t\"\\t.previous\\n\"\n\t\"\\t.globl .%s\\n\"\n\t\"\\t.hidden .%s\\n\"\n\t\"\\t.type .%s, \" ELFASM_PX \"function\\n\"\n\t\"\\t.size .%s, %d\\n\"\n\t\".%s:\\n\",\n\tname, name, name, name, name, name, name, name, size, name);\n      break;\n    }\n#endif\n    fprintf(ctx->fp,\n      \"\\n\\t.globl %s\\n\"\n      \"\\t.hidden %s\\n\"\n      \"\\t.type %s, \" ELFASM_PX \"%s\\n\"\n      \"\\t.size %s, %d\\n\"\n      \"%s:\\n\",\n      name, name, name, isfunc ? \"function\" : \"object\", name, size, name);\n    break;\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\n\\t.globl %s\\n\", name);\n    if (isfunc)\n      fprintf(ctx->fp, \"\\t.def %s; .scl 3; .type 32; .endef\\n\", name);\n    fprintf(ctx->fp, \"%s:\\n\", name);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp,\n      \"\\n\\t.private_extern %s\\n\"\n      \"\\t.no_dead_strip %s\\n\"\n      \"%s:\\n\", name, name, name);\n    break;\n  default:\n    break;\n  }\n}\n\n/* Emit alignment. */\nstatic void emit_asm_align(BuildCtx *ctx, int bits)\n{\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.p2align %d\\n\", bits);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp, \"\\t.align %d\\n\", bits);\n    break;\n  default:\n    break;\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Emit assembler source code. */\nvoid emit_asm(BuildCtx *ctx)\n{\n  int i, rel;\n\n  fprintf(ctx->fp, \"\\t.file \\\"buildvm_%s.dasc\\\"\\n\", ctx->dasm_arch);\n  fprintf(ctx->fp, \"\\t.text\\n\");\n  emit_asm_align(ctx, 4);\n\n#if LJ_TARGET_PS3\n  emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0);\n#else\n  emit_asm_label(ctx, ctx->beginsym, 0, 0);\n#endif\n  if (ctx->mode != BUILD_machasm)\n    fprintf(ctx->fp, \".Lbegin:\\n\");\n\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND\n  /* This should really be moved into buildvm_arm.dasc. */\n#if LJ_ARCH_HASFPU\n  fprintf(ctx->fp,\n\t  \".fnstart\\n\"\n\t  \".save {r5, r6, r7, r8, r9, r10, r11, lr}\\n\"\n\t  \".vsave {d8-d15}\\n\"\n\t  \".save {r4}\\n\"\n\t  \".pad #28\\n\");\n#else\n  fprintf(ctx->fp,\n\t  \".fnstart\\n\"\n\t  \".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\\n\"\n\t  \".pad #28\\n\");\n#endif\n#endif\n#if LJ_TARGET_MIPS\n  fprintf(ctx->fp, \".set nomips16\\n.abicalls\\n.set noreorder\\n.set nomacro\\n\");\n#endif\n\n  for (i = rel = 0; i < ctx->nsym; i++) {\n    int32_t ofs = ctx->sym[i].ofs;\n    int32_t next = ctx->sym[i+1].ofs;\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI\n    if (!strcmp(ctx->sym[i].name, \"lj_vm_ffi_call\"))\n      fprintf(ctx->fp,\n\t      \".globl lj_err_unwind_arm\\n\"\n\t      \".personality lj_err_unwind_arm\\n\"\n\t      \".fnend\\n\"\n\t      \".fnstart\\n\"\n\t      \".save {r4, r5, r11, lr}\\n\"\n\t      \".setfp r11, sp\\n\");\n#endif\n    emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);\n    while (rel < ctx->nreloc && ctx->reloc[rel].ofs <= next) {\n      BuildReloc *r = &ctx->reloc[rel];\n      int n = r->ofs - ofs;\n#if LJ_TARGET_X86ORX64\n      if (r->type != 0 &&\n\t  (ctx->mode == BUILD_elfasm || ctx->mode == BUILD_machasm)) {\n\temit_asm_reloc_text(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);\n      } else {\n\temit_asm_bytes(ctx, ctx->code+ofs, n);\n\temit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);\n      }\n      ofs += n+4;\n#else\n      emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);\n      ofs += n;\n#endif\n      rel++;\n    }\n#if LJ_TARGET_X86ORX64\n    emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);\n#else\n    emit_asm_words(ctx, ctx->code+ofs, next-ofs);\n#endif\n  }\n\n#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND\n  fprintf(ctx->fp,\n#if !LJ_HASFFI\n\t  \".globl lj_err_unwind_arm\\n\"\n\t  \".personality lj_err_unwind_arm\\n\"\n#endif\n\t  \".fnend\\n\");\n#endif\n\n  fprintf(ctx->fp, \"\\n\");\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA)\n    fprintf(ctx->fp, \"\\t.section .note.GNU-stack,\\\"\\\",\" ELFASM_PX \"progbits\\n\");\n#endif\n#if LJ_TARGET_PPC && !LJ_TARGET_PS3 && !LJ_ABI_SOFTFP\n    /* Hard-float ABI. */\n    fprintf(ctx->fp, \"\\t.gnu_attribute 4, 1\\n\");\n#endif\n    /* fallthrough */\n  case BUILD_coffasm:\n    fprintf(ctx->fp, \"\\t.ident \\\"%s\\\"\\n\", ctx->dasm_ident);\n    break;\n  case BUILD_machasm:\n    fprintf(ctx->fp,\n      \"\\t.cstring\\n\"\n      \"\\t.ascii \\\"%s\\\\0\\\"\\n\", ctx->dasm_ident);\n    break;\n  default:\n    break;\n  }\n  fprintf(ctx->fp, \"\\n\");\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm_fold.c",
    "content": "/*\n** LuaJIT VM builder: IR folding hash table generator.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n\n/* Context for the folding hash table generator. */\nstatic int lineno;\nstatic uint32_t funcidx;\nstatic uint32_t foldkeys[BUILD_MAX_FOLD];\nstatic uint32_t nkeys;\n\n/* Try to fill the hash table with keys using the hash parameters. */\nstatic int tryhash(uint32_t *htab, uint32_t sz, uint32_t r, int dorol)\n{\n  uint32_t i;\n  if (dorol && ((r & 31) == 0 || (r>>5) == 0))\n    return 0;  /* Avoid zero rotates. */\n  memset(htab, 0xff, (sz+1)*sizeof(uint32_t));\n  for (i = 0; i < nkeys; i++) {\n    uint32_t key = foldkeys[i];\n    uint32_t k = key & 0xffffff;\n    uint32_t h = (dorol ? lj_rol(lj_rol(k, r>>5) - k, r&31) :\n\t\t\t  (((k << (r>>5)) - k) << (r&31))) % sz;\n    if (htab[h] != 0xffffffff) {  /* Collision on primary slot. */\n      if (htab[h+1] != 0xffffffff) {  /* Collision on secondary slot. */\n\t/* Try to move the colliding key, if possible. */\n\tif (h < sz-1 && htab[h+2] == 0xffffffff) {\n\t  uint32_t k2 = htab[h+1] & 0xffffff;\n\t  uint32_t h2 = (dorol ? lj_rol(lj_rol(k2, r>>5) - k2, r&31) :\n\t\t\t\t (((k2 << (r>>5)) - k2) << (r&31))) % sz;\n\t  if (h2 != h+1) return 0;  /* Cannot resolve collision. */\n\t  htab[h+2] = htab[h+1];  /* Move colliding key to secondary slot. */\n\t} else {\n\t  return 0;  /* Collision. */\n\t}\n      }\n      htab[h+1] = key;\n    } else {\n      htab[h] = key;\n    }\n  }\n  return 1;  /* Success, all keys could be stored. */\n}\n\n/* Print the generated hash table. */\nstatic void printhash(BuildCtx *ctx, uint32_t *htab, uint32_t sz)\n{\n  uint32_t i;\n  fprintf(ctx->fp, \"static const uint32_t fold_hash[%d] = {\\n0x%08x\",\n\t  sz+1, htab[0]);\n  for (i = 1; i < sz+1; i++)\n    fprintf(ctx->fp, \",\\n0x%08x\", htab[i]);\n  fprintf(ctx->fp, \"\\n};\\n\\n\");\n}\n\n/* Exhaustive search for the shortest semi-perfect hash table. */\nstatic void makehash(BuildCtx *ctx)\n{\n  uint32_t htab[BUILD_MAX_FOLD*2+1];\n  uint32_t sz, r;\n  /* Search for the smallest hash table with an odd size. */\n  for (sz = (nkeys|1); sz < BUILD_MAX_FOLD*2; sz += 2) {\n    /* First try all shift hash combinations. */\n    for (r = 0; r < 32*32; r++) {\n      if (tryhash(htab, sz, r, 0)) {\n\tprinthash(ctx, htab, sz);\n\tfprintf(ctx->fp,\n\t\t\"#define fold_hashkey(k)\\t(((((k)<<%u)-(k))<<%u)%%%u)\\n\\n\",\n\t\tr>>5, r&31, sz);\n\treturn;\n      }\n    }\n    /* Then try all rotate hash combinations. */\n    for (r = 0; r < 32*32; r++) {\n      if (tryhash(htab, sz, r, 1)) {\n\tprinthash(ctx, htab, sz);\n\tfprintf(ctx->fp,\n\t  \"#define fold_hashkey(k)\\t(lj_rol(lj_rol((k),%u)-(k),%u)%%%u)\\n\\n\",\n\t\tr>>5, r&31, sz);\n\treturn;\n      }\n    }\n  }\n  fprintf(stderr, \"Error: search for perfect hash failed\\n\");\n  exit(1);\n}\n\n/* Parse one token of a fold rule. */\nstatic uint32_t nexttoken(char **pp, int allowlit, int allowany)\n{\n  char *p = *pp;\n  if (p) {\n    uint32_t i;\n    char *q = strchr(p, ' ');\n    if (q) *q++ = '\\0';\n    *pp = q;\n    if (allowlit && !strncmp(p, \"IRFPM_\", 6)) {\n      for (i = 0; irfpm_names[i]; i++)\n\tif (!strcmp(irfpm_names[i], p+6))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRFL_\", 5)) {\n      for (i = 0; irfield_names[i]; i++)\n\tif (!strcmp(irfield_names[i], p+5))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRCALL_\", 7)) {\n      for (i = 0; ircall_names[i]; i++)\n\tif (!strcmp(ircall_names[i], p+7))\n\t  return i;\n    } else if (allowlit && !strncmp(p, \"IRCONV_\", 7)) {\n      for (i = 0; irt_names[i]; i++) {\n\tconst char *r = strchr(p+7, '_');\n\tif (r && !strncmp(irt_names[i], p+7, r-(p+7))) {\n\t  uint32_t j;\n\t  for (j = 0; irt_names[j]; j++)\n\t    if (!strcmp(irt_names[j], r+1))\n\t      return (i << 5) + j;\n\t}\n      }\n    } else if (allowlit && *p >= '0' && *p <= '9') {\n      for (i = 0; *p >= '0' && *p <= '9'; p++)\n\ti = i*10 + (*p - '0');\n      if (*p == '\\0')\n\treturn i;\n    } else if (allowany && !strcmp(\"any\", p)) {\n      return allowany;\n    } else {\n      for (i = 0; ir_names[i]; i++)\n\tif (!strcmp(ir_names[i], p))\n\t  return i;\n    }\n    fprintf(stderr, \"Error: bad fold definition token \\\"%s\\\" at line %d\\n\", p, lineno);\n    exit(1);\n  }\n  return 0;\n}\n\n/* Parse a fold rule. */\nstatic void foldrule(char *p)\n{\n  uint32_t op = nexttoken(&p, 0, 0);\n  uint32_t left = nexttoken(&p, 0, 0x7f);\n  uint32_t right = nexttoken(&p, 1, 0x3ff);\n  uint32_t key = (funcidx << 24) | (op << 17) | (left << 10) | right;\n  uint32_t i;\n  if (nkeys >= BUILD_MAX_FOLD) {\n    fprintf(stderr, \"Error: too many fold rules, increase BUILD_MAX_FOLD.\\n\");\n    exit(1);\n  }\n  /* Simple insertion sort to detect duplicates. */\n  for (i = nkeys; i > 0; i--) {\n    if ((foldkeys[i-1]&0xffffff) < (key & 0xffffff))\n      break;\n    if ((foldkeys[i-1]&0xffffff) == (key & 0xffffff)) {\n      fprintf(stderr, \"Error: duplicate fold definition at line %d\\n\", lineno);\n      exit(1);\n    }\n    foldkeys[i] = foldkeys[i-1];\n  }\n  foldkeys[i] = key;\n  nkeys++;\n}\n\n/* Emit C source code for IR folding hash table. */\nvoid emit_fold(BuildCtx *ctx)\n{\n  char buf[256];  /* We don't care about analyzing lines longer than that. */\n  const char *fname = ctx->args[0];\n  FILE *fp;\n\n  if (fname == NULL) {\n    fprintf(stderr, \"Error: missing input filename\\n\");\n    exit(1);\n  }\n\n  if (fname[0] == '-' && fname[1] == '\\0') {\n    fp = stdin;\n  } else {\n    fp = fopen(fname, \"r\");\n    if (!fp) {\n      fprintf(stderr, \"Error: cannot open input file '%s': %s\\n\",\n\t      fname, strerror(errno));\n      exit(1);\n    }\n  }\n\n  fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  fprintf(ctx->fp, \"static const FoldFunc fold_func[] = {\\n\");\n\n  lineno = 0;\n  funcidx = 0;\n  nkeys = 0;\n  while (fgets(buf, sizeof(buf), fp) != NULL) {\n    lineno++;\n    /* The prefix must be at the start of a line, otherwise it's ignored. */\n    if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) {\n      char *p = buf+sizeof(FOLDDEF_PREFIX)-1;\n      char *q = strchr(p, ')');\n      if (p[0] == '(' && q) {\n\tp++;\n\t*q = '\\0';\n\tfoldrule(p);\n      } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) {\n\tp += 2;\n\t*q = '\\0';\n\tif (funcidx)\n\t  fprintf(ctx->fp, \",\\n\");\n\tif (p[-2] == 'X')\n\t  fprintf(ctx->fp, \"  %s\", p);\n\telse\n\t  fprintf(ctx->fp, \"  fold_%s\", p);\n\tfuncidx++;\n      } else {\n\tbuf[strlen(buf)-1] = '\\0';\n\tfprintf(stderr, \"Error: unknown fold definition tag %s%s at line %d\\n\",\n\t\tFOLDDEF_PREFIX, p, lineno);\n\texit(1);\n      }\n    }\n  }\n  fclose(fp);\n  fprintf(ctx->fp, \"\\n};\\n\\n\");\n\n  makehash(ctx);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm_lib.c",
    "content": "/*\n** LuaJIT VM builder: library definition compiler.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"buildvm.h\"\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n#include \"lj_lib.h\"\n#include \"buildvm_libbc.h\"\n\n/* Context for library definitions. */\nstatic uint8_t obuf[8192];\nstatic uint8_t *optr;\nstatic char modname[80];\nstatic size_t modnamelen;\nstatic char funcname[80];\nstatic int modstate, regfunc;\nstatic int ffid, recffid, ffasmfunc;\n\nenum {\n  REGFUNC_OK,\n  REGFUNC_NOREG,\n  REGFUNC_NOREGUV\n};\n\nstatic void libdef_name(const char *p, int kind)\n{\n  size_t n = strlen(p);\n  if (kind != LIBINIT_STRING) {\n    if (n > modnamelen && p[modnamelen] == '_' &&\n\t!strncmp(p, modname, modnamelen)) {\n      p += modnamelen+1;\n      n -= modnamelen+1;\n    }\n  }\n  if (n > LIBINIT_MAXSTR) {\n    fprintf(stderr, \"Error: string too long: '%s'\\n\",  p);\n    exit(1);\n  }\n  if (optr+1+n+2 > obuf+sizeof(obuf)) {  /* +2 for caller. */\n    fprintf(stderr, \"Error: output buffer overflow\\n\");\n    exit(1);\n  }\n  *optr++ = (uint8_t)(n | kind);\n  memcpy(optr, p, n);\n  optr += n;\n}\n\nstatic void libdef_endmodule(BuildCtx *ctx)\n{\n  if (modstate != 0) {\n    char line[80];\n    const uint8_t *p;\n    int n;\n    if (modstate == 1)\n      fprintf(ctx->fp, \"  (lua_CFunction)0\");\n    fprintf(ctx->fp, \"\\n};\\n\");\n    fprintf(ctx->fp, \"static const uint8_t %s%s[] = {\\n\",\n\t    LABEL_PREFIX_LIBINIT, modname);\n    line[0] = '\\0';\n    for (n = 0, p = obuf; p < optr; p++) {\n      n += sprintf(line+n, \"%d,\", *p);\n      if (n >= 75) {\n\tfprintf(ctx->fp, \"%s\\n\", line);\n\tn = 0;\n\tline[0] = '\\0';\n      }\n    }\n    fprintf(ctx->fp, \"%s%d\\n};\\n#endif\\n\\n\", line, LIBINIT_END);\n  }\n}\n\nstatic void libdef_module(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    libdef_endmodule(ctx);\n    optr = obuf;\n    *optr++ = (uint8_t)ffid;\n    *optr++ = (uint8_t)ffasmfunc;\n    *optr++ = 0;  /* Hash table size. */\n    modstate = 1;\n    fprintf(ctx->fp, \"#ifdef %sMODULE_%s\\n\", LIBDEF_PREFIX, p);\n    fprintf(ctx->fp, \"#undef %sMODULE_%s\\n\", LIBDEF_PREFIX, p);\n    fprintf(ctx->fp, \"static const lua_CFunction %s%s[] = {\\n\",\n\t    LABEL_PREFIX_LIBCF, p);\n  }\n  modnamelen = strlen(p);\n  if (modnamelen > sizeof(modname)-1) {\n    fprintf(stderr, \"Error: module name too long: '%s'\\n\", p);\n    exit(1);\n  }\n  strcpy(modname, p);\n}\n\nstatic int find_ffofs(BuildCtx *ctx, const char *name)\n{\n  int i;\n  for (i = 0; i < ctx->nglob; i++) {\n    const char *gl = ctx->globnames[i];\n    if (gl[0] == 'f' && gl[1] == 'f' && gl[2] == '_' && !strcmp(gl+3, name)) {\n      return (int)((uint8_t *)ctx->glob[i] - ctx->code);\n    }\n  }\n  fprintf(stderr, \"Error: undefined fast function %s%s\\n\",\n\t  LABEL_PREFIX_FF, name);\n  exit(1);\n}\n\nstatic void libdef_func(BuildCtx *ctx, char *p, int arg)\n{\n  if (arg != LIBINIT_CF)\n    ffasmfunc++;\n  if (ctx->mode == BUILD_libdef) {\n    if (modstate == 0) {\n      fprintf(stderr, \"Error: no module for function definition %s\\n\", p);\n      exit(1);\n    }\n    if (regfunc == REGFUNC_NOREG) {\n      if (optr+1 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_FFID;\n    } else {\n      if (arg != LIBINIT_ASM_) {\n\tif (modstate != 1) fprintf(ctx->fp, \",\\n\");\n\tmodstate = 2;\n\tfprintf(ctx->fp, \"  %s%s\", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p);\n      }\n      if (regfunc != REGFUNC_NOREGUV) obuf[2]++;  /* Bump hash table size. */\n      libdef_name(regfunc == REGFUNC_NOREGUV ? \"\" : p, arg);\n    }\n  } else if (ctx->mode == BUILD_ffdef) {\n    fprintf(ctx->fp, \"FFDEF(%s)\\n\", p);\n  } else if (ctx->mode == BUILD_recdef) {\n    if (strlen(p) > sizeof(funcname)-1) {\n      fprintf(stderr, \"Error: function name too long: '%s'\\n\", p);\n      exit(1);\n    }\n    strcpy(funcname, p);\n  } else if (ctx->mode == BUILD_vmdef) {\n    int i;\n    for (i = 1; p[i] && modname[i-1]; i++)\n      if (p[i] == '_') p[i] = '.';\n    fprintf(ctx->fp, \"\\\"%s\\\",\\n\", p);\n  } else if (ctx->mode == BUILD_bcdef) {\n    if (arg != LIBINIT_CF)\n      fprintf(ctx->fp, \",\\n%d\", find_ffofs(ctx, p));\n  }\n  ffid++;\n  regfunc = REGFUNC_OK;\n}\n\nstatic uint8_t *libdef_uleb128(uint8_t *p, uint32_t *vv)\n{\n  uint32_t v = *p++;\n  if (v >= 0x80) {\n    int sh = 0; v &= 0x7f;\n    do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80);\n  }\n  *vv = v;\n  return p;\n}\n\nstatic void libdef_fixupbc(uint8_t *p)\n{\n  uint32_t i, sizebc;\n  p += 4;\n  p = libdef_uleb128(p, &sizebc);\n  p = libdef_uleb128(p, &sizebc);\n  p = libdef_uleb128(p, &sizebc);\n  for (i = 0; i < sizebc; i++, p += 4) {\n    uint8_t op = p[libbc_endian ? 3 : 0];\n    uint8_t ra = p[libbc_endian ? 2 : 1];\n    uint8_t rc = p[libbc_endian ? 1 : 2];\n    uint8_t rb = p[libbc_endian ? 0 : 3];\n    if (!LJ_DUALNUM && op == BC_ISTYPE && rc == ~LJ_TNUMX+1) {\n      op = BC_ISNUM; rc++;\n    }\n    p[LJ_ENDIAN_SELECT(0, 3)] = op;\n    p[LJ_ENDIAN_SELECT(1, 2)] = ra;\n    p[LJ_ENDIAN_SELECT(2, 1)] = rc;\n    p[LJ_ENDIAN_SELECT(3, 0)] = rb;\n  }\n}\n\nstatic void libdef_lua(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    int i;\n    for (i = 0; libbc_map[i].name != NULL; i++) {\n      if (!strcmp(libbc_map[i].name, p)) {\n\tint ofs = libbc_map[i].ofs;\n\tint len = libbc_map[i+1].ofs - ofs;\n\tobuf[2]++;  /* Bump hash table size. */\n\t*optr++ = LIBINIT_LUA;\n\tlibdef_name(p, 0);\n\tmemcpy(optr, libbc_code + ofs, len);\n\tlibdef_fixupbc(optr);\n\toptr += len;\n\treturn;\n      }\n    }\n    fprintf(stderr, \"Error: missing libbc definition for %s\\n\", p);\n    exit(1);\n  }\n}\n\nstatic uint32_t find_rec(char *name)\n{\n  char *p = (char *)obuf;\n  uint32_t n;\n  for (n = 2; *p; n++) {\n    if (strcmp(p, name) == 0)\n      return n;\n    p += strlen(p)+1;\n  }\n  if (p+strlen(name)+1 >= (char *)obuf+sizeof(obuf)) {\n    fprintf(stderr, \"Error: output buffer overflow\\n\");\n    exit(1);\n  }\n  strcpy(p, name);\n  return n;\n}\n\nstatic void libdef_rec(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_recdef) {\n    char *q;\n    uint32_t n;\n    for (; recffid+1 < ffid; recffid++)\n      fprintf(ctx->fp, \",\\n0\");\n    recffid = ffid;\n    if (*p == '.') p = funcname;\n    q = strchr(p, ' ');\n    if (q) *q++ = '\\0';\n    n = find_rec(p);\n    if (q)\n      fprintf(ctx->fp, \",\\n0x%02x00+(%s)\", n, q);\n    else\n      fprintf(ctx->fp, \",\\n0x%02x00\", n);\n  }\n}\n\nstatic void memcpy_endian(void *dst, void *src, size_t n)\n{\n  union { uint8_t b; uint32_t u; } host_endian;\n  host_endian.u = 1;\n  if (host_endian.b == LJ_ENDIAN_SELECT(1, 0)) {\n    memcpy(dst, src, n);\n  } else {\n    size_t i;\n    for (i = 0; i < n; i++)\n      ((uint8_t *)dst)[i] = ((uint8_t *)src)[n-i-1];\n  }\n}\n\nstatic void libdef_push(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    int len = (int)strlen(p);\n    if (*p == '\"') {\n      if (len > 1 && p[len-1] == '\"') {\n\tp[len-1] = '\\0';\n\tlibdef_name(p+1, LIBINIT_STRING);\n\treturn;\n      }\n    } else if (*p >= '0' && *p <= '9') {\n      char *ep;\n      double d = strtod(p, &ep);\n      if (*ep == '\\0') {\n\tif (optr+1+sizeof(double) > obuf+sizeof(obuf)) {\n\t  fprintf(stderr, \"Error: output buffer overflow\\n\");\n\t  exit(1);\n\t}\n\t*optr++ = LIBINIT_NUMBER;\n\tmemcpy_endian(optr, &d, sizeof(double));\n\toptr += sizeof(double);\n\treturn;\n      }\n    } else if (!strcmp(p, \"lastcl\")) {\n      if (optr+1 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_LASTCL;\n      return;\n    } else if (len > 4 && !strncmp(p, \"top-\", 4)) {\n      if (optr+2 > obuf+sizeof(obuf)) {\n\tfprintf(stderr, \"Error: output buffer overflow\\n\");\n\texit(1);\n      }\n      *optr++ = LIBINIT_COPY;\n      *optr++ = (uint8_t)atoi(p+4);\n      return;\n    }\n    fprintf(stderr, \"Error: bad value for %sPUSH(%s)\\n\", LIBDEF_PREFIX, p);\n    exit(1);\n  }\n}\n\nstatic void libdef_set(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(arg);\n  if (ctx->mode == BUILD_libdef) {\n    if (p[0] == '!' && p[1] == '\\0') p[0] = '\\0';  /* Set env. */\n    libdef_name(p, LIBINIT_STRING);\n    *optr++ = LIBINIT_SET;\n    obuf[2]++;  /* Bump hash table size. */\n  }\n}\n\nstatic void libdef_regfunc(BuildCtx *ctx, char *p, int arg)\n{\n  UNUSED(ctx); UNUSED(p);\n  regfunc = arg;\n}\n\ntypedef void (*LibDefFunc)(BuildCtx *ctx, char *p, int arg);\n\ntypedef struct LibDefHandler {\n  const char *suffix;\n  const char *stop;\n  const LibDefFunc func;\n  const int arg;\n} LibDefHandler;\n\nstatic const LibDefHandler libdef_handlers[] = {\n  { \"MODULE_\",\t\" \\t\\r\\n\",\tlibdef_module,\t\t0 },\n  { \"CF(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_CF },\n  { \"ASM(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_ASM },\n  { \"ASM_(\",\t\")\",\t\tlibdef_func,\t\tLIBINIT_ASM_ },\n  { \"LUA(\",\t\")\",\t\tlibdef_lua,\t\t0 },\n  { \"REC(\",\t\")\",\t\tlibdef_rec,\t\t0 },\n  { \"PUSH(\",\t\")\",\t\tlibdef_push,\t\t0 },\n  { \"SET(\",\t\")\",\t\tlibdef_set,\t\t0 },\n  { \"NOREGUV\",\tNULL,\t\tlibdef_regfunc,\t\tREGFUNC_NOREGUV },\n  { \"NOREG\",\tNULL,\t\tlibdef_regfunc,\t\tREGFUNC_NOREG },\n  { NULL,\tNULL,\t\t(LibDefFunc)0,\t\t0 }\n};\n\n/* Emit C source code for library function definitions. */\nvoid emit_lib(BuildCtx *ctx)\n{\n  const char *fname;\n\n  if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef ||\n      ctx->mode == BUILD_recdef)\n    fprintf(ctx->fp, \"/* This is a generated file. DO NOT EDIT! */\\n\\n\");\n  else if (ctx->mode == BUILD_vmdef)\n    fprintf(ctx->fp, \"ffnames = {\\n[0]=\\\"Lua\\\",\\n\\\"C\\\",\\n\");\n  if (ctx->mode == BUILD_recdef)\n    fprintf(ctx->fp, \"static const uint16_t recff_idmap[] = {\\n0,\\n0x0100\");\n  recffid = ffid = FF_C+1;\n  ffasmfunc = 0;\n\n  while ((fname = *ctx->args++)) {\n    char buf[256];  /* We don't care about analyzing lines longer than that. */\n    FILE *fp;\n    if (fname[0] == '-' && fname[1] == '\\0') {\n      fp = stdin;\n    } else {\n      fp = fopen(fname, \"r\");\n      if (!fp) {\n\tfprintf(stderr, \"Error: cannot open input file '%s': %s\\n\",\n\t\tfname, strerror(errno));\n\texit(1);\n      }\n    }\n    modstate = 0;\n    regfunc = REGFUNC_OK;\n    while (fgets(buf, sizeof(buf), fp) != NULL) {\n      char *p;\n      /* Simplistic pre-processor. Only handles top-level #if/#endif. */\n      if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {\n\tint ok = 1;\n\tif (!strcmp(buf, \"#if LJ_52\\n\"))\n\t  ok = LJ_52;\n\telse if (!strcmp(buf, \"#if LJ_HASJIT\\n\"))\n\t  ok = LJ_HASJIT;\n\telse if (!strcmp(buf, \"#if LJ_HASFFI\\n\"))\n\t  ok = LJ_HASFFI;\n\telse if (!strcmp(buf, \"#if LJ_HASBUFFER\\n\"))\n\t  ok = LJ_HASBUFFER;\n\tif (!ok) {\n\t  int lvl = 1;\n\t  while (fgets(buf, sizeof(buf), fp) != NULL) {\n\t    if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') {\n\t      if (--lvl == 0) break;\n\t    } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {\n\t      lvl++;\n\t    }\n\t  }\n\t  continue;\n\t}\n      }\n      for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) {\n\tconst LibDefHandler *ldh;\n\tp += sizeof(LIBDEF_PREFIX)-1;\n\tfor (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) {\n\t  size_t n, len = strlen(ldh->suffix);\n\t  if (!strncmp(p, ldh->suffix, len)) {\n\t    p += len;\n\t    n = ldh->stop ? strcspn(p, ldh->stop) : 0;\n\t    if (!p[n]) break;\n\t    p[n] = '\\0';\n\t    ldh->func(ctx, p, ldh->arg);\n\t    p += n+1;\n\t    break;\n\t  }\n\t}\n\tif (ldh->suffix == NULL) {\n\t  buf[strlen(buf)-1] = '\\0';\n\t  fprintf(stderr, \"Error: unknown library definition tag %s%s\\n\",\n\t\t  LIBDEF_PREFIX, p);\n\t  exit(1);\n\t}\n      }\n    }\n    fclose(fp);\n    if (ctx->mode == BUILD_libdef) {\n      libdef_endmodule(ctx);\n    }\n  }\n\n  if (ctx->mode == BUILD_ffdef) {\n    fprintf(ctx->fp, \"\\n#undef FFDEF\\n\\n\");\n    fprintf(ctx->fp,\n      \"#ifndef FF_NUM_ASMFUNC\\n#define FF_NUM_ASMFUNC %d\\n#endif\\n\\n\",\n      ffasmfunc);\n  } else if (ctx->mode == BUILD_vmdef) {\n    fprintf(ctx->fp, \"},\\n\\n\");\n  } else if (ctx->mode == BUILD_bcdef) {\n    int i;\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n    fprintf(ctx->fp, \"LJ_DATADEF const uint16_t lj_bc_mode[] = {\\n\");\n    fprintf(ctx->fp, \"BCDEF(BCMODE)\\n\");\n    for (i = ffasmfunc-1; i > 0; i--)\n      fprintf(ctx->fp, \"BCMODE_FF,\\n\");\n    fprintf(ctx->fp, \"BCMODE_FF\\n};\\n\\n\");\n  } else if (ctx->mode == BUILD_recdef) {\n    char *p = (char *)obuf;\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n    fprintf(ctx->fp, \"static const RecordFunc recff_func[] = {\\n\"\n\t    \"recff_nyi,\\n\"\n\t    \"recff_c\");\n    while (*p) {\n      fprintf(ctx->fp, \",\\nrecff_%s\", p);\n      p += strlen(p)+1;\n    }\n    fprintf(ctx->fp, \"\\n};\\n\\n\");\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm_libbc.h",
    "content": "/* This is a generated file. DO NOT EDIT! */\n\nstatic const int libbc_endian = 0;\n\nstatic const uint8_t libbc_code[] = {\n#if LJ_FR2\n0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0,\n0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0,1,2,0,0,0,3,\n16,0,5,0,21,1,0,0,76,1,2,0,0,2,10,0,0,0,15,16,0,12,0,16,1,9,0,41,2,1,0,21,3,\n0,0,41,4,1,0,77,2,8,128,18,6,1,0,18,8,5,0,59,9,5,0,66,6,3,2,10,6,0,0,88,7,1,\n128,76,6,2,0,79,2,248,127,75,0,1,0,0,2,11,0,0,0,16,16,0,12,0,16,1,9,0,43,2,\n0,0,18,3,0,0,41,4,0,0,88,5,7,128,18,7,1,0,18,9,5,0,18,10,6,0,66,7,3,2,10,7,\n0,0,88,8,1,128,76,7,2,0,70,5,3,3,82,5,247,127,75,0,1,0,0,1,2,0,0,0,3,16,0,12,\n0,21,1,0,0,76,1,2,0,0,2,10,0,0,2,30,16,0,12,0,21,2,0,0,11,1,0,0,88,3,7,128,\n8,2,0,0,88,3,23,128,59,3,2,0,43,4,0,0,64,4,2,0,76,3,2,0,88,3,18,128,16,1,14,\n0,41,3,1,0,3,3,1,0,88,3,14,128,3,1,2,0,88,3,12,128,59,3,1,0,22,4,1,1,18,5,2,\n0,41,6,1,0,77,4,4,128,23,8,1,7,59,9,7,0,64,9,8,0,79,4,252,127,43,4,0,0,64,4,\n2,0,76,3,2,0,75,0,1,0,0,2,0,5,12,0,0,0,35,16,0,12,0,16,1,14,0,16,2,14,0,16,\n3,14,0,11,4,0,0,88,5,1,128,18,4,0,0,16,4,12,0,3,1,2,0,88,5,24,128,33,5,1,3,\n0,2,3,0,88,6,4,128,2,3,1,0,88,6,2,128,4,4,0,0,88,6,9,128,18,6,1,0,18,7,2,0,\n41,8,1,0,77,6,4,128,32,10,5,9,59,11,9,0,64,11,10,4,79,6,252,127,88,6,8,128,\n18,6,2,0,18,7,1,0,41,8,255,255,77,6,4,128,32,10,5,9,59,11,9,0,64,11,10,4,79,\n6,252,127,76,4,2,0,0\n#else\n0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0,\n0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0,1,2,0,0,0,3,\n16,0,5,0,21,1,0,0,76,1,2,0,0,2,9,0,0,0,15,16,0,12,0,16,1,9,0,41,2,1,0,21,3,\n0,0,41,4,1,0,77,2,8,128,18,6,1,0,18,7,5,0,59,8,5,0,66,6,3,2,10,6,0,0,88,7,1,\n128,76,6,2,0,79,2,248,127,75,0,1,0,0,2,10,0,0,0,16,16,0,12,0,16,1,9,0,43,2,\n0,0,18,3,0,0,41,4,0,0,88,5,7,128,18,7,1,0,18,8,5,0,18,9,6,0,66,7,3,2,10,7,0,\n0,88,8,1,128,76,7,2,0,70,5,3,3,82,5,247,127,75,0,1,0,0,1,2,0,0,0,3,16,0,12,\n0,21,1,0,0,76,1,2,0,0,2,10,0,0,2,30,16,0,12,0,21,2,0,0,11,1,0,0,88,3,7,128,\n8,2,0,0,88,3,23,128,59,3,2,0,43,4,0,0,64,4,2,0,76,3,2,0,88,3,18,128,16,1,14,\n0,41,3,1,0,3,3,1,0,88,3,14,128,3,1,2,0,88,3,12,128,59,3,1,0,22,4,1,1,18,5,2,\n0,41,6,1,0,77,4,4,128,23,8,1,7,59,9,7,0,64,9,8,0,79,4,252,127,43,4,0,0,64,4,\n2,0,76,3,2,0,75,0,1,0,0,2,0,5,12,0,0,0,35,16,0,12,0,16,1,14,0,16,2,14,0,16,\n3,14,0,11,4,0,0,88,5,1,128,18,4,0,0,16,4,12,0,3,1,2,0,88,5,24,128,33,5,1,3,\n0,2,3,0,88,6,4,128,2,3,1,0,88,6,2,128,4,4,0,0,88,6,9,128,18,6,1,0,18,7,2,0,\n41,8,1,0,77,6,4,128,32,10,5,9,59,11,9,0,64,11,10,4,79,6,252,127,88,6,8,128,\n18,6,2,0,18,7,1,0,41,8,255,255,77,6,4,128,32,10,5,9,59,11,9,0,64,11,10,4,79,\n6,252,127,76,4,2,0,0\n#endif\n};\n\nstatic const struct { const char *name; int ofs; } libbc_map[] = {\n{\"math_deg\",0},\n{\"math_rad\",25},\n{\"string_len\",50},\n{\"table_foreachi\",69},\n{\"table_foreach\",136},\n{\"table_getn\",207},\n{\"table_remove\",226},\n{\"table_move\",355},\n{NULL,502}\n};\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/buildvm_peobj.c",
    "content": "/*\n** LuaJIT VM builder: PE object emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Only used for building on Windows, since we cannot assume the presence\n** of a suitable assembler. The host and target byte order must match.\n*/\n\n#include \"buildvm.h\"\n#include \"lj_bc.h\"\n\n#if LJ_TARGET_X86ORX64\n\n/* Context for PE object emitter. */\nstatic char *strtab;\nstatic size_t strtabofs;\n\n/* -- PE object definitions ----------------------------------------------- */\n\n/* PE header. */\ntypedef struct PEheader {\n  uint16_t arch;\n  uint16_t nsects;\n  uint32_t time;\n  uint32_t symtabofs;\n  uint32_t nsyms;\n  uint16_t opthdrsz;\n  uint16_t flags;\n} PEheader;\n\n/* PE section. */\ntypedef struct PEsection {\n  char name[8];\n  uint32_t vsize;\n  uint32_t vaddr;\n  uint32_t size;\n  uint32_t ofs;\n  uint32_t relocofs;\n  uint32_t lineofs;\n  uint16_t nreloc;\n  uint16_t nline;\n  uint32_t flags;\n} PEsection;\n\n/* PE relocation. */\ntypedef struct PEreloc {\n  uint32_t vaddr;\n  uint32_t symidx;\n  uint16_t type;\n} PEreloc;\n\n/* Cannot use sizeof, because it pads up to the max. alignment. */\n#define PEOBJ_RELOC_SIZE\t(4+4+2)\n\n/* PE symbol table entry. */\ntypedef struct PEsym {\n  union {\n    char name[8];\n    uint32_t nameref[2];\n  } n;\n  uint32_t value;\n  int16_t sect;\n  uint16_t type;\n  uint8_t scl;\n  uint8_t naux;\n} PEsym;\n\n/* PE symbol table auxiliary entry for a section. */\ntypedef struct PEsymaux {\n  uint32_t size;\n  uint16_t nreloc;\n  uint16_t nline;\n  uint32_t cksum;\n  uint16_t assoc;\n  uint8_t comdatsel;\n  uint8_t unused[3];\n} PEsymaux;\n\n/* Cannot use sizeof, because it pads up to the max. alignment. */\n#define PEOBJ_SYM_SIZE\t(8+4+2+2+1+1)\n\n/* PE object CPU specific defines. */\n#if LJ_TARGET_X86\n#define PEOBJ_ARCH_TARGET\t0x014c\n#define PEOBJ_RELOC_REL32\t0x14  /* MS: REL32, GNU: DISP32. */\n#define PEOBJ_RELOC_DIR32\t0x06\n#define PEOBJ_RELOC_OFS\t\t0\n#define PEOBJ_TEXT_FLAGS\t0x60500020  /* 60=r+x, 50=align16, 20=code. */\n#elif LJ_TARGET_X64\n#define PEOBJ_ARCH_TARGET\t0x8664\n#define PEOBJ_RELOC_REL32\t0x04  /* MS: REL32, GNU: DISP32. */\n#define PEOBJ_RELOC_DIR32\t0x02\n#define PEOBJ_RELOC_ADDR32NB\t0x03\n#define PEOBJ_RELOC_OFS\t\t0\n#define PEOBJ_TEXT_FLAGS\t0x60500020  /* 60=r+x, 50=align16, 20=code. */\n#endif\n\n/* Section numbers (0-based). */\nenum {\n  PEOBJ_SECT_ABS = -2,\n  PEOBJ_SECT_UNDEF = -1,\n  PEOBJ_SECT_TEXT,\n#if LJ_TARGET_X64\n  PEOBJ_SECT_PDATA,\n  PEOBJ_SECT_XDATA,\n#elif LJ_TARGET_X86\n  PEOBJ_SECT_SXDATA,\n#endif\n  PEOBJ_SECT_RDATA_Z,\n  PEOBJ_NSECTIONS\n};\n\n/* Symbol types. */\n#define PEOBJ_TYPE_NULL\t\t0\n#define PEOBJ_TYPE_FUNC\t\t0x20\n\n/* Symbol storage class. */\n#define PEOBJ_SCL_EXTERN\t2\n#define PEOBJ_SCL_STATIC\t3\n\n/* -- PE object emitter --------------------------------------------------- */\n\n/* Emit PE object symbol. */\nstatic void emit_peobj_sym(BuildCtx *ctx, const char *name, uint32_t value,\n\t\t\t   int sect, int type, int scl)\n{\n  PEsym sym;\n  size_t len = strlen(name);\n  if (!strtab) {  /* Pass 1: only calculate string table length. */\n    if (len > 8) strtabofs += len+1;\n    return;\n  }\n  if (len <= 8) {\n    memcpy(sym.n.name, name, len);\n    memset(sym.n.name+len, 0, 8-len);\n  } else {\n    sym.n.nameref[0] = 0;\n    sym.n.nameref[1] = (uint32_t)strtabofs;\n    memcpy(strtab + strtabofs, name, len);\n    strtab[strtabofs+len] = 0;\n    strtabofs += len+1;\n  }\n  sym.value = value;\n  sym.sect = (int16_t)(sect+1);  /* 1-based section number. */\n  sym.type = (uint16_t)type;\n  sym.scl = (uint8_t)scl;\n  sym.naux = 0;\n  owrite(ctx, &sym, PEOBJ_SYM_SIZE);\n}\n\n/* Emit PE object section symbol. */\nstatic void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect)\n{\n  PEsym sym;\n  PEsymaux aux;\n  if (!strtab) return;  /* Pass 1: no output. */\n  memcpy(sym.n.name, pesect[sect].name, 8);\n  sym.value = 0;\n  sym.sect = (int16_t)(sect+1);  /* 1-based section number. */\n  sym.type = PEOBJ_TYPE_NULL;\n  sym.scl = PEOBJ_SCL_STATIC;\n  sym.naux = 1;\n  owrite(ctx, &sym, PEOBJ_SYM_SIZE);\n  memset(&aux, 0, sizeof(PEsymaux));\n  aux.size = pesect[sect].size;\n  aux.nreloc = pesect[sect].nreloc;\n  owrite(ctx, &aux, PEOBJ_SYM_SIZE);\n}\n\n/* Emit Windows PE object file. */\nvoid emit_peobj(BuildCtx *ctx)\n{\n  PEheader pehdr;\n  PEsection pesect[PEOBJ_NSECTIONS];\n  uint32_t sofs;\n  int i, nrsym;\n  union { uint8_t b; uint32_t u; } host_endian;\n\n  sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection);\n\n  /* Fill in PE sections. */\n  memset(&pesect, 0, PEOBJ_NSECTIONS*sizeof(PEsection));\n  memcpy(pesect[PEOBJ_SECT_TEXT].name, \".text\", sizeof(\".text\")-1);\n  pesect[PEOBJ_SECT_TEXT].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_TEXT].size = (uint32_t)ctx->codesz);\n  pesect[PEOBJ_SECT_TEXT].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE;\n  /* Flags: 60 = read+execute, 50 = align16, 20 = code. */\n  pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS;\n\n#if LJ_TARGET_X64\n  memcpy(pesect[PEOBJ_SECT_PDATA].name, \".pdata\", sizeof(\".pdata\")-1);\n  pesect[PEOBJ_SECT_PDATA].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_PDATA].size = 6*4);\n  pesect[PEOBJ_SECT_PDATA].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_PDATA].nreloc = 6) * PEOBJ_RELOC_SIZE;\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_PDATA].flags = 0x40300040;\n\n  memcpy(pesect[PEOBJ_SECT_XDATA].name, \".xdata\", sizeof(\".xdata\")-1);\n  pesect[PEOBJ_SECT_XDATA].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_XDATA].size = 8*2+4+6*2);  /* See below. */\n  pesect[PEOBJ_SECT_XDATA].relocofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_XDATA].nreloc = 1) * PEOBJ_RELOC_SIZE;\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_XDATA].flags = 0x40300040;\n#elif LJ_TARGET_X86\n  memcpy(pesect[PEOBJ_SECT_SXDATA].name, \".sxdata\", sizeof(\".sxdata\")-1);\n  pesect[PEOBJ_SECT_SXDATA].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_SXDATA].size = 4);\n  pesect[PEOBJ_SECT_SXDATA].relocofs = sofs;\n  /* Flags: 40 = read, 30 = align4, 02 = lnk_info, 40 = initialized data. */\n  pesect[PEOBJ_SECT_SXDATA].flags = 0x40300240;\n#endif\n\n  memcpy(pesect[PEOBJ_SECT_RDATA_Z].name, \".rdata$Z\", sizeof(\".rdata$Z\")-1);\n  pesect[PEOBJ_SECT_RDATA_Z].ofs = sofs;\n  sofs += (pesect[PEOBJ_SECT_RDATA_Z].size = (uint32_t)strlen(ctx->dasm_ident)+1);\n  /* Flags: 40 = read, 30 = align4, 40 = initialized data. */\n  pesect[PEOBJ_SECT_RDATA_Z].flags = 0x40300040;\n\n  /* Fill in PE header. */\n  pehdr.arch = PEOBJ_ARCH_TARGET;\n  pehdr.nsects = PEOBJ_NSECTIONS;\n  pehdr.time = 0;  /* Timestamp is optional. */\n  pehdr.symtabofs = sofs;\n  pehdr.opthdrsz = 0;\n  pehdr.flags = 0;\n\n  /* Compute the size of the symbol table:\n  ** @feat.00 + nsections*2\n  ** + asm_start + nsym\n  ** + nrsym\n  */\n  nrsym = ctx->nrelocsym;\n  pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym;\n#if LJ_TARGET_X64\n  pehdr.nsyms += 1;  /* Symbol for lj_err_unwind_win. */\n#endif\n\n  /* Write PE object header and all sections. */\n  owrite(ctx, &pehdr, sizeof(PEheader));\n  owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS);\n\n  /* Write .text section. */\n  host_endian.u = 1;\n  if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) {\n    fprintf(stderr, \"Error: different byte order for host and target\\n\");\n    exit(1);\n  }\n  owrite(ctx, ctx->code, ctx->codesz);\n  for (i = 0; i < ctx->nreloc; i++) {\n    PEreloc reloc;\n    reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS;\n    reloc.symidx = 1+2+ctx->reloc[i].sym;  /* Reloc syms are after .text sym. */\n    reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n\n#if LJ_TARGET_X64\n  { /* Write .pdata section. */\n    uint32_t fcofs = (uint32_t)ctx->sym[ctx->nsym-1].ofs;\n    uint32_t pdata[3];  /* Start of .text, end of .text and .xdata. */\n    PEreloc reloc;\n    pdata[0] = 0; pdata[1] = fcofs; pdata[2] = 0;\n    owrite(ctx, &pdata, sizeof(pdata));\n    pdata[0] = fcofs; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 20;\n    owrite(ctx, &pdata, sizeof(pdata));\n    reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 12; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 16; reloc.symidx = 1+2+nrsym+2+2+1;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n    reloc.vaddr = 20; reloc.symidx = 1+2+nrsym+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n  { /* Write .xdata section. */\n    uint16_t xdata[8+2+6];\n    PEreloc reloc;\n    xdata[0] = 0x01|0x08|0x10;  /* Ver. 1, uhandler/ehandler, prolog size 0. */\n    xdata[1] = 0x0005;  /* Number of unwind codes, no frame pointer. */\n    xdata[2] = 0x4200;  /* Stack offset 4*8+8 = aword*5. */\n    xdata[3] = 0x3000;  /* Push rbx. */\n    xdata[4] = 0x6000;  /* Push rsi. */\n    xdata[5] = 0x7000;  /* Push rdi. */\n    xdata[6] = 0x5000;  /* Push rbp. */\n    xdata[7] = 0;  /* Alignment. */\n    xdata[8] = xdata[9] = 0;  /* Relocated address of exception handler. */\n    xdata[10] = 0x01;  /* Ver. 1, no handler, prolog size 0. */\n    xdata[11] = 0x1504;  /* Number of unwind codes, fp = rbp, fpofs = 16. */\n    xdata[12] = 0x0300;  /* set_fpreg. */\n    xdata[13] = 0x0200;  /* stack offset 0*8+8 = aword*1. */\n    xdata[14] = 0x3000;  /* Push rbx. */\n    xdata[15] = 0x5000;  /* Push rbp. */\n    owrite(ctx, &xdata, sizeof(xdata));\n    reloc.vaddr = 2*8; reloc.symidx = 1+2+nrsym+2+2;\n    reloc.type = PEOBJ_RELOC_ADDR32NB;\n    owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);\n  }\n#elif LJ_TARGET_X86\n  /* Write .sxdata section. */\n  for (i = 0; i < nrsym; i++) {\n    if (!strcmp(ctx->relocsym[i], \"_lj_err_unwind_win\")) {\n      uint32_t symidx = 1+2+i;\n      owrite(ctx, &symidx, 4);\n      break;\n    }\n  }\n  if (i == nrsym) {\n    fprintf(stderr, \"Error: extern lj_err_unwind_win not used\\n\");\n    exit(1);\n  }\n#endif\n\n  /* Write .rdata$Z section. */\n  owrite(ctx, ctx->dasm_ident, strlen(ctx->dasm_ident)+1);\n\n  /* Write symbol table. */\n  strtab = NULL;  /* 1st pass: collect string sizes. */\n  for (;;) {\n    strtabofs = 4;\n    /* Mark as SafeSEH compliant. */\n    emit_peobj_sym(ctx, \"@feat.00\", 1,\n\t\t   PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC);\n\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT);\n    for (i = 0; i < nrsym; i++)\n      emit_peobj_sym(ctx, ctx->relocsym[i], 0,\n\t\t     PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n\n#if LJ_TARGET_X64\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA);\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA);\n    emit_peobj_sym(ctx, \"lj_err_unwind_win\", 0,\n\t\t   PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n#elif LJ_TARGET_X86\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_SXDATA);\n#endif\n\n    emit_peobj_sym(ctx, ctx->beginsym, 0,\n\t\t   PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN);\n    for (i = 0; i < ctx->nsym; i++)\n      emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs,\n\t\t     PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);\n\n    emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z);\n\n    if (strtab)\n      break;\n    /* 2nd pass: alloc strtab, write syms and copy strings. */\n    strtab = (char *)malloc(strtabofs);\n    *(uint32_t *)strtab = (uint32_t)strtabofs;\n  }\n\n  /* Write string table. */\n  owrite(ctx, strtab, strtabofs);\n}\n\n#else\n\nvoid emit_peobj(BuildCtx *ctx)\n{\n  UNUSED(ctx);\n  fprintf(stderr, \"Error: no PE object support for this target\\n\");\n  exit(1);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/genlibbc.lua",
    "content": "----------------------------------------------------------------------------\n-- Lua script to dump the bytecode of the library functions written in Lua.\n-- The resulting 'buildvm_libbc.h' is used for the build process of LuaJIT.\n----------------------------------------------------------------------------\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n\nlocal ffi = require(\"ffi\")\nlocal bit = require(\"bit\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal bcnames = vmdef.bcnames\n\nlocal format = string.format\n\nlocal isbe = (string.byte(string.dump(function() end), 5) % 2 == 1)\n\nlocal function usage(arg)\n  io.stderr:write(\"Usage: \", arg and arg[0] or \"genlibbc\",\n\t\t  \" [-o buildvm_libbc.h] lib_*.c\\n\")\n  os.exit(1)\nend\n\nlocal function parse_arg(arg)\n  local outfile = \"-\"\n  if not (arg and arg[1]) then\n    usage(arg)\n  end\n  if arg[1] == \"-o\" then\n    outfile = arg[2]\n    if not outfile then usage(arg) end\n    table.remove(arg, 1)\n    table.remove(arg, 1)\n  end\n  return outfile\nend\n\nlocal function read_files(names)\n  local src = \"\"\n  for _,name in ipairs(names) do\n    local fp = assert(io.open(name))\n    src = src .. fp:read(\"*a\")\n    fp:close()\n  end\n  return src\nend\n\nlocal function transform_lua(code)\n  local fixup = {}\n  local n = -30000\n  code = string.gsub(code, \"CHECK_(%w*)%((.-)%)\", function(tp, var)\n    n = n + 1\n    fixup[n] = { \"CHECK\", tp }\n    return format(\"%s=%d\", var, n)\n  end)\n  code = string.gsub(code, \"PAIRS%((.-)%)\", function(var)\n    fixup.PAIRS = true\n    return format(\"nil, %s, 0\", var)\n  end)\n  return \"return \"..code, fixup\nend\n\nlocal function read_uleb128(p)\n  local v = p[0]; p = p + 1\n  if v >= 128 then\n    local sh = 7; v = v - 128\n    repeat\n      local r = p[0]\n      v = v + bit.lshift(bit.band(r, 127), sh)\n      sh = sh + 7\n      p = p + 1\n    until r < 128\n  end\n  return p, v\nend\n\n-- ORDER LJ_T\nlocal name2itype = {\n  str = 5, func = 9, tab = 12, int = 14, num = 15\n}\n\nlocal BC = {}\nfor i=0,#bcnames/6-1 do\n  BC[string.gsub(string.sub(bcnames, i*6+1, i*6+6), \" \", \"\")] = i\nend\nlocal xop, xra = isbe and 3 or 0, isbe and 2 or 1\nlocal xrc, xrb = isbe and 1 or 2, isbe and 0 or 3\n\nlocal function fixup_dump(dump, fixup)\n  local buf = ffi.new(\"uint8_t[?]\", #dump+1, dump)\n  local p = buf+5\n  local n, sizebc\n  p, n = read_uleb128(p)\n  local start = p\n  p = p + 4\n  p = read_uleb128(p)\n  p = read_uleb128(p)\n  p, sizebc = read_uleb128(p)\n  local rawtab = {}\n  for i=0,sizebc-1 do\n    local op = p[xop]\n    if op == BC.KSHORT then\n      local rd = p[xrc] + 256*p[xrb]\n      rd = bit.arshift(bit.lshift(rd, 16), 16)\n      local f = fixup[rd]\n      if f then\n\tif f[1] == \"CHECK\" then\n\t  local tp = f[2]\n\t  if tp == \"tab\" then rawtab[p[xra]] = true end\n\t  p[xop] = tp == \"num\" and BC.ISNUM or BC.ISTYPE\n\t  p[xrb] = 0\n\t  p[xrc] = name2itype[tp]\n\telse\n\t  error(\"unhandled fixup type: \"..f[1])\n\tend\n      end\n    elseif op == BC.TGETV then\n      if rawtab[p[xrb]] then\n\tp[xop] = BC.TGETR\n      end\n    elseif op == BC.TSETV then\n      if rawtab[p[xrb]] then\n\tp[xop] = BC.TSETR\n      end\n    elseif op == BC.ITERC then\n      if fixup.PAIRS then\n\tp[xop] = BC.ITERN\n      end\n    end\n    p = p + 4\n  end\n  return ffi.string(start, n)\nend\n\nlocal function find_defs(src)\n  local defs = {}\n  for name, code in string.gmatch(src, \"LJLIB_LUA%(([^)]*)%)%s*/%*(.-)%*/\") do\n    local env = {}\n    local tcode, fixup = transform_lua(code)\n    local func = assert(load(tcode, \"\", nil, env))()\n    defs[name] = fixup_dump(string.dump(func, true), fixup)\n    defs[#defs+1] = name\n  end\n  return defs\nend\n\nlocal function gen_header(defs)\n  local t = {}\n  local function w(x) t[#t+1] = x end\n  w(\"/* This is a generated file. DO NOT EDIT! */\\n\\n\")\n  w(\"static const int libbc_endian = \") w(isbe and 1 or 0) w(\";\\n\\n\")\n  local s = \"\"\n  for _,name in ipairs(defs) do\n    s = s .. defs[name]\n  end\n  w(\"static const uint8_t libbc_code[] = {\\n\")\n  local n = 0\n  for i=1,#s do\n    local x = string.byte(s, i)\n    w(x); w(\",\")\n    n = n + (x < 10 and 2 or (x < 100 and 3 or 4))\n    if n >= 75 then n = 0; w(\"\\n\") end\n  end\n  w(\"0\\n};\\n\\n\")\n  w(\"static const struct { const char *name; int ofs; } libbc_map[] = {\\n\")\n  local m = 0\n  for _,name in ipairs(defs) do\n    w('{\"'); w(name); w('\",'); w(m) w('},\\n')\n    m = m + #defs[name]\n  end\n  w(\"{NULL,\"); w(m); w(\"}\\n};\\n\\n\")\n  return table.concat(t)\nend\n\nlocal function write_file(name, data)\n  if name == \"-\" then\n    assert(io.write(data))\n    assert(io.flush())\n  else\n    local fp = io.open(name)\n    if fp then\n      local old = fp:read(\"*a\")\n      fp:close()\n      if data == old then return end\n    end\n    fp = assert(io.open(name, \"w\"))\n    assert(fp:write(data))\n    assert(fp:close())\n  end\nend\n\nlocal outfile = parse_arg(arg)\nlocal src = read_files(arg)\nlocal defs = find_defs(src)\nlocal hdr = gen_header(defs)\nwrite_file(outfile, hdr)\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/genminilua.lua",
    "content": "----------------------------------------------------------------------------\n-- Lua script to generate a customized, minified version of Lua.\n-- The resulting 'minilua' is used for the build process of LuaJIT.\n----------------------------------------------------------------------------\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n\nlocal sub, match, gsub = string.sub, string.match, string.gsub\n\nlocal LUA_VERSION = \"5.1.5\"\nlocal LUA_SOURCE\n\nlocal function usage()\n  io.stderr:write(\"Usage: \", arg and arg[0] or \"genminilua\",\n\t\t  \" lua-\", LUA_VERSION, \"-source-dir\\n\")\n  os.exit(1)\nend\n\nlocal function find_sources()\n  LUA_SOURCE = arg and arg[1]\n  if not LUA_SOURCE then usage() end\n  if sub(LUA_SOURCE, -1) ~= \"/\" then LUA_SOURCE = LUA_SOURCE..\"/\" end\n  local fp = io.open(LUA_SOURCE .. \"lua.h\")\n  if not fp then\n    LUA_SOURCE = LUA_SOURCE..\"src/\"\n    fp = io.open(LUA_SOURCE .. \"lua.h\")\n    if not fp then usage() end\n  end\n  local all = fp:read(\"*a\")\n  fp:close()\n  if not match(all, 'LUA_RELEASE%s*\"Lua '..LUA_VERSION..'\"') then\n    io.stderr:write(\"Error: version mismatch\\n\")\n    usage()\n  end\nend\n\nlocal LUA_FILES = {\n\"lmem.c\", \"lobject.c\", \"ltm.c\", \"lfunc.c\", \"ldo.c\", \"lstring.c\", \"ltable.c\",\n\"lgc.c\", \"lstate.c\", \"ldebug.c\", \"lzio.c\", \"lopcodes.c\",\n\"llex.c\", \"lcode.c\", \"lparser.c\", \"lvm.c\", \"lapi.c\", \"lauxlib.c\",\n\"lbaselib.c\", \"ltablib.c\", \"liolib.c\", \"loslib.c\", \"lstrlib.c\", \"linit.c\",\n}\n\nlocal REMOVE_LIB = {}\ngsub([[\ncollectgarbage dofile gcinfo getfenv getmetatable load print rawequal rawset\nselect tostring xpcall\nforeach foreachi getn maxn setn\npopen tmpfile seek setvbuf __tostring\nclock date difftime execute getenv rename setlocale time tmpname\ndump gfind len reverse\nLUA_LOADLIBNAME LUA_MATHLIBNAME LUA_DBLIBNAME\n]], \"%S+\", function(name)\n  REMOVE_LIB[name] = true\nend)\n\nlocal REMOVE_EXTINC = { [\"<assert.h>\"] = true, [\"<locale.h>\"] = true, }\n\nlocal CUSTOM_MAIN = [[\ntypedef unsigned int UB;\nstatic UB barg(lua_State *L,int idx){\nunion{lua_Number n;U64 b;}bn;\nbn.n=lua_tonumber(L,idx)+6755399441055744.0;\nif (bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,\"number\");\nreturn(UB)bn.b;\n}\n#define BRET(b) lua_pushnumber(L,(lua_Number)(int)(b));return 1;\nstatic int tobit(lua_State *L){\nBRET(barg(L,1))}\nstatic int bnot(lua_State *L){\nBRET(~barg(L,1))}\nstatic int band(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}\nstatic int bor(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}\nstatic int bxor(lua_State *L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}\nstatic int lshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}\nstatic int rshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}\nstatic int arshift(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}\nstatic int rol(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}\nstatic int ror(lua_State *L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}\nstatic int bswap(lua_State *L){\nUB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}\nstatic int tohex(lua_State *L){\nUB b=barg(L,1);\nint n=lua_isnone(L,2)?8:(int)barg(L,2);\nconst char *hexdigits=\"0123456789abcdef\";\nchar buf[8];\nint i;\nif(n<0){n=-n;hexdigits=\"0123456789ABCDEF\";}\nif(n>8)n=8;\nfor(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}\nlua_pushlstring(L,buf,(size_t)n);\nreturn 1;\n}\nstatic const struct luaL_Reg bitlib[] = {\n{\"tobit\",tobit},\n{\"bnot\",bnot},\n{\"band\",band},\n{\"bor\",bor},\n{\"bxor\",bxor},\n{\"lshift\",lshift},\n{\"rshift\",rshift},\n{\"arshift\",arshift},\n{\"rol\",rol},\n{\"ror\",ror},\n{\"bswap\",bswap},\n{\"tohex\",tohex},\n{NULL,NULL}\n};\nint main(int argc, char **argv){\n  lua_State *L = luaL_newstate();\n  int i;\n  luaL_openlibs(L);\n  luaL_register(L, \"bit\", bitlib);\n  if (argc < 2) return sizeof(void *);\n  lua_createtable(L, 0, 1);\n  lua_pushstring(L, argv[1]);\n  lua_rawseti(L, -2, 0);\n  lua_setglobal(L, \"arg\");\n  if (luaL_loadfile(L, argv[1]))\n    goto err;\n  for (i = 2; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  if (lua_pcall(L, argc - 2, 0, 0)) {\n  err:\n    fprintf(stderr, \"Error: %s\\n\", lua_tostring(L, -1));\n    return 1;\n  }\n  lua_close(L);\n  return 0;\n}\n]]\n\nlocal function read_sources()\n  local t = {}\n  for i, name in ipairs(LUA_FILES) do\n    local fp = assert(io.open(LUA_SOURCE..name, \"r\"))\n    t[i] = fp:read(\"*a\")\n    assert(fp:close())\n  end\n  t[#t+1] = CUSTOM_MAIN\n  return table.concat(t)\nend\n\nlocal includes = {}\n\nlocal function merge_includes(src)\n  return gsub(src, '#include%s*\"([^\"]*)\"%s*\\n', function(name)\n    if includes[name] then return \"\" end\n    includes[name] = true\n    local fp = assert(io.open(LUA_SOURCE..name, \"r\"))\n    local inc = fp:read(\"*a\")\n    assert(fp:close())\n    inc = gsub(inc, \"#ifndef%s+%w+_h\\n#define%s+%w+_h\\n\", \"\")\n    inc = gsub(inc, \"#endif%s*$\", \"\")\n    return merge_includes(inc)\n  end)\nend\n\nlocal function get_license(src)\n  return match(src, \"/%*+\\n%* Copyright %(.-%*/\\n\")\nend\n\nlocal function fold_lines(src)\n  return gsub(src, \"\\\\\\n\", \" \")\nend\n\nlocal strings = {}\n\nlocal function save_str(str)\n  local n = #strings+1\n  strings[n] = str\n  return \"\\1\"..n..\"\\2\"\nend\n\nlocal function save_strings(src)\n  src = gsub(src, '\"[^\"\\n]*\"', save_str)\n  return gsub(src, \"'[^'\\n]*'\", save_str)\nend\n\nlocal function restore_strings(src)\n  return gsub(src, \"\\1(%d+)\\2\", function(numstr)\n    return strings[tonumber(numstr)]\n  end)\nend\n\nlocal function def_istrue(def)\n  return def == \"INT_MAX > 2147483640L\" or\n\t def == \"LUAI_BITSINT >= 32\" or\n\t def == \"SIZE_Bx < LUAI_BITSINT-1\" or\n\t def == \"cast\" or\n\t def == \"defined(LUA_CORE)\" or\n\t def == \"MINSTRTABSIZE\" or\n\t def == \"LUA_MINBUFFER\" or\n\t def == \"HARDSTACKTESTS\" or\n\t def == \"UNUSED\"\nend\n\nlocal head, defs = {[[\n#ifdef _MSC_VER\ntypedef unsigned __int64 U64;\n#else\ntypedef unsigned long long U64;\n#endif\nint _CRT_glob = 0;\n]]}, {}\n\nlocal function preprocess(src)\n  local t = { match(src, \"^(.-)#\") }\n  local lvl, on, oldon = 0, true, {}\n  for pp, def, txt in string.gmatch(src, \"#(%w+) *([^\\n]*)\\n([^#]*)\") do\n    if pp == \"if\" or pp == \"ifdef\" or pp == \"ifndef\" then\n      lvl = lvl + 1\n      oldon[lvl] = on\n      on = def_istrue(def)\n    elseif pp == \"else\" then\n      if oldon[lvl] then\n\tif on == false then on = true else on = false end\n      end\n    elseif pp == \"elif\" then\n      if oldon[lvl] then\n\ton = def_istrue(def)\n      end\n    elseif pp == \"endif\" then\n      on = oldon[lvl]\n      lvl = lvl - 1\n    elseif on then\n      if pp == \"include\" then\n\tif not head[def] and not REMOVE_EXTINC[def] then\n\t  head[def] = true\n\t  head[#head+1] = \"#include \"..def..\"\\n\"\n\tend\n      elseif pp == \"define\" then\n\tlocal k, sp, v = match(def, \"([%w_]+)(%s*)(.*)\")\n\tif k and not (sp == \"\" and sub(v, 1, 1) == \"(\") then\n\t  defs[k] = gsub(v, \"%a[%w_]*\", function(tok)\n\t    return defs[tok] or tok\n\t  end)\n\telse\n\t  t[#t+1] = \"#define \"..def..\"\\n\"\n\tend\n      elseif pp ~= \"undef\" then\n\terror(\"unexpected directive: \"..pp..\" \"..def)\n      end\n    end\n    if on then t[#t+1] = txt end\n  end\n  return gsub(table.concat(t), \"%a[%w_]*\", function(tok)\n    return defs[tok] or tok\n  end)\nend\n\nlocal function merge_header(src, license)\n  local hdr = string.format([[\n/* This is a heavily customized and minimized copy of Lua %s. */\n/* It's only used to build LuaJIT. It does NOT have all standard functions! */\n]], LUA_VERSION)\n  return hdr..license..table.concat(head)..src\nend\n\nlocal function strip_unused1(src)\n  return gsub(src, '(  {\"?([%w_]+)\"?,%s+%a[%w_]*},\\n)', function(line, func)\n    return REMOVE_LIB[func] and \"\" or line\n  end)\nend\n\nlocal function strip_unused2(src)\n  return gsub(src, \"Symbolic Execution.-}=\", \"\")\nend\n\nlocal function strip_unused3(src)\n  src = gsub(src, \"extern\", \"static\")\n  src = gsub(src, \"\\nstatic([^\\n]-)%(([^)]*)%)%(\", \"\\nstatic%1 %2(\")\n  src = gsub(src, \"#define lua_assert[^\\n]*\\n\", \"\")\n  src = gsub(src, \"lua_assert%b();?\", \"\")\n  src = gsub(src, \"default:\\n}\", \"default:;\\n}\")\n  src = gsub(src, \"lua_lock%b();\", \"\")\n  src = gsub(src, \"lua_unlock%b();\", \"\")\n  src = gsub(src, \"luai_threadyield%b();\", \"\")\n  src = gsub(src, \"luai_userstateopen%b();\", \"{}\")\n  src = gsub(src, \"luai_userstate%w+%b();\", \"\")\n  src = gsub(src, \"%(%(c==.*luaY_parser%)\", \"luaY_parser\")\n  src = gsub(src, \"trydecpoint%(ls,seminfo%)\",\n\t\t  \"luaX_lexerror(ls,\\\"malformed number\\\",TK_NUMBER)\")\n  src = gsub(src, \"int c=luaZ_lookahead%b();\", \"\")\n  src = gsub(src, \"luaL_register%(L,[^,]*,co_funcs%);\\nreturn 2;\",\n\t\t  \"return 1;\")\n  src = gsub(src, \"getfuncname%b():\", \"NULL:\")\n  src = gsub(src, \"getobjname%b():\", \"NULL:\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*%)\\n[^\\n]*\\n\", \"\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*%)%b{}\\n\", \"\")\n  src = gsub(src, \"if%([^\\n]*hookmask[^\\n]*&&\\n[^\\n]*%b{}\\n\", \"\")\n  src = gsub(src, \"(twoto%b()%()\", \"%1(size_t)\")\n  src = gsub(src, \"i<sizenode\", \"i<(int)sizenode\")\n  src = gsub(src, \"cast%(unsigned int,key%-1%)\", \"cast(unsigned int,key)-1\")\n  return gsub(src, \"\\n\\n+\", \"\\n\")\nend\n\nlocal function strip_comments(src)\n  return gsub(src, \"/%*.-%*/\", \" \")\nend\n\nlocal function strip_whitespace(src)\n  src = gsub(src, \"^%s+\", \"\")\n  src = gsub(src, \"%s*\\n%s*\", \"\\n\")\n  src = gsub(src, \"[ \\t]+\", \" \")\n  src = gsub(src, \"(%W) \", \"%1\")\n  return gsub(src, \" (%W)\", \"%1\")\nend\n\nlocal function rename_tokens1(src)\n  src = gsub(src, \"getline\", \"getline_\")\n  src = gsub(src, \"struct ([%w_]+)\", \"ZX%1\")\n  return gsub(src, \"union ([%w_]+)\", \"ZY%1\")\nend\n\nlocal function rename_tokens2(src)\n  src = gsub(src, \"ZX([%w_]+)\", \"struct %1\")\n  return gsub(src, \"ZY([%w_]+)\", \"union %1\")\nend\n\nlocal function func_gather(src)\n  local nodes, list = {}, {}\n  local pos, len = 1, #src\n  while pos < len do\n    local d, w = match(src, \"^(#define ([%w_]+)[^\\n]*\\n)\", pos)\n    if d then\n      local n = #list+1\n      list[n] = d\n      nodes[w] = n\n    else\n      local s\n      d, w, s = match(src, \"^(([%w_]+)[^\\n]*([{;])\\n)\", pos)\n      if not d then\n\td, w, s = match(src, \"^(([%w_]+)[^(]*%b()([{;])\\n)\", pos)\n\tif not d then d = match(src, \"^[^\\n]*\\n\", pos) end\n      end\n      if s == \"{\" then\n\td = d..sub(match(src, \"^%b{}[^;\\n]*;?\\n\", pos+#d-2), 3)\n\tif sub(d, -2) == \"{\\n\" then\n\t  d = d..sub(match(src, \"^%b{}[^;\\n]*;?\\n\", pos+#d-2), 3)\n\tend\n      end\n      local k, v = nil, d\n      if w == \"typedef\" then\n\tif match(d, \"^typedef enum\") then\n\t  head[#head+1] = d\n\telse\n\t  k = match(d, \"([%w_]+);\\n$\")\n\t  if not k then k = match(d, \"^.-%(.-([%w_]+)%)%(\") end\n\tend\n      elseif w == \"enum\" then\n\thead[#head+1] = v\n      elseif w ~= nil then\n\tk = match(d, \"^[^\\n]-([%w_]+)[(%[=]\")\n\tif k then\n\t  if w ~= \"static\" and k ~= \"main\" then v = \"static \"..d end\n\telse\n\t  k = w\n\tend\n      end\n      if w and k then\n\tlocal o = nodes[k]\n\tif o then nodes[\"*\"..k] = o end\n\tlocal n = #list+1\n\tlist[n] = v\n\tnodes[k] = n\n      end\n    end\n    pos = pos + #d\n  end\n  return nodes, list\nend\n\nlocal function func_visit(nodes, list, used, n)\n  local i = nodes[n]\n  for m in string.gmatch(list[i], \"[%w_]+\") do\n    if nodes[m] then\n      local j = used[m]\n      if not j then\n\tused[m] = i\n\tfunc_visit(nodes, list, used, m)\n      elseif i < j then\n\tused[m] = i\n      end\n    end\n  end\nend\n\nlocal function func_collect(src)\n  local nodes, list = func_gather(src)\n  local used = {}\n  func_visit(nodes, list, used, \"main\")\n  for n,i in pairs(nodes) do\n    local j = used[n]\n    if j and j < i then used[\"*\"..n] = j end\n  end\n  for n,i in pairs(nodes) do\n    if not used[n] then list[i] = \"\" end\n  end\n  return table.concat(list)\nend\n\nfind_sources()\nlocal src = read_sources()\nsrc = merge_includes(src)\nlocal license = get_license(src)\nsrc = fold_lines(src)\nsrc = strip_unused1(src)\nsrc = save_strings(src)\nsrc = strip_unused2(src)\nsrc = strip_comments(src)\nsrc = preprocess(src)\nsrc = strip_whitespace(src)\nsrc = strip_unused3(src)\nsrc = rename_tokens1(src)\nsrc = func_collect(src)\nsrc = rename_tokens2(src)\nsrc = restore_strings(src)\nsrc = merge_header(src, license)\nio.write(src)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/host/minilua.c",
    "content": "/* This is a heavily customized and minimized copy of Lua 5.1.5. */\n/* It's only used to build LuaJIT. It does NOT have all standard functions! */\n/******************************************************************************\n* Copyright (C) 1994-2012 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n#ifdef _MSC_VER\ntypedef unsigned __int64 U64;\n#else\ntypedef unsigned long long U64;\n#endif\nint _CRT_glob = 0;\n#include <stddef.h>\n#include <stdarg.h>\n#include <limits.h>\n#include <math.h>\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <setjmp.h>\n#include <errno.h>\n#include <time.h>\ntypedef enum{\nTM_INDEX,\nTM_NEWINDEX,\nTM_GC,\nTM_MODE,\nTM_EQ,\nTM_ADD,\nTM_SUB,\nTM_MUL,\nTM_DIV,\nTM_MOD,\nTM_POW,\nTM_UNM,\nTM_LEN,\nTM_LT,\nTM_LE,\nTM_CONCAT,\nTM_CALL,\nTM_N\n}TMS;\nenum OpMode{iABC,iABx,iAsBx};\ntypedef enum{\nOP_MOVE,\nOP_LOADK,\nOP_LOADBOOL,\nOP_LOADNIL,\nOP_GETUPVAL,\nOP_GETGLOBAL,\nOP_GETTABLE,\nOP_SETGLOBAL,\nOP_SETUPVAL,\nOP_SETTABLE,\nOP_NEWTABLE,\nOP_SELF,\nOP_ADD,\nOP_SUB,\nOP_MUL,\nOP_DIV,\nOP_MOD,\nOP_POW,\nOP_UNM,\nOP_NOT,\nOP_LEN,\nOP_CONCAT,\nOP_JMP,\nOP_EQ,\nOP_LT,\nOP_LE,\nOP_TEST,\nOP_TESTSET,\nOP_CALL,\nOP_TAILCALL,\nOP_RETURN,\nOP_FORLOOP,\nOP_FORPREP,\nOP_TFORLOOP,\nOP_SETLIST,\nOP_CLOSE,\nOP_CLOSURE,\nOP_VARARG\n}OpCode;\nenum OpArgMask{\nOpArgN,\nOpArgU,\nOpArgR,\nOpArgK\n};\ntypedef enum{\nVVOID,\nVNIL,\nVTRUE,\nVFALSE,\nVK,\nVKNUM,\nVLOCAL,\nVUPVAL,\nVGLOBAL,\nVINDEXED,\nVJMP,\nVRELOCABLE,\nVNONRELOC,\nVCALL,\nVVARARG\n}expkind;\nenum RESERVED{\nTK_AND=257,TK_BREAK,\nTK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION,\nTK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT,\nTK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE,\nTK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER,\nTK_NAME,TK_STRING,TK_EOS\n};\ntypedef enum BinOpr{\nOPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW,\nOPR_CONCAT,\nOPR_NE,OPR_EQ,\nOPR_LT,OPR_LE,OPR_GT,OPR_GE,\nOPR_AND,OPR_OR,\nOPR_NOBINOPR\n}BinOpr;\ntypedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr;\n#define LUA_QL(x)\"'\"x\"'\"\n#define luai_apicheck(L,o){(void)L;}\n#define lua_number2str(s,n)sprintf((s),\"%.14g\",(n))\n#define lua_str2number(s,p)strtod((s),(p))\n#define luai_numadd(a,b)((a)+(b))\n#define luai_numsub(a,b)((a)-(b))\n#define luai_nummul(a,b)((a)*(b))\n#define luai_numdiv(a,b)((a)/(b))\n#define luai_nummod(a,b)((a)-floor((a)/(b))*(b))\n#define luai_numpow(a,b)(pow(a,b))\n#define luai_numunm(a)(-(a))\n#define luai_numeq(a,b)((a)==(b))\n#define luai_numlt(a,b)((a)<(b))\n#define luai_numle(a,b)((a)<=(b))\n#define luai_numisnan(a)(!luai_numeq((a),(a)))\n#define lua_number2int(i,d)((i)=(int)(d))\n#define lua_number2integer(i,d)((i)=(lua_Integer)(d))\n#define LUAI_THROW(L,c)longjmp((c)->b,1)\n#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a}\n#define lua_pclose(L,file)((void)((void)L,file),0)\n#define lua_upvalueindex(i)((-10002)-(i))\ntypedef struct lua_State lua_State;\ntypedef int(*lua_CFunction)(lua_State*L);\ntypedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz);\ntypedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize);\ntypedef double lua_Number;\ntypedef ptrdiff_t lua_Integer;\nstatic void lua_settop(lua_State*L,int idx);\nstatic int lua_type(lua_State*L,int idx);\nstatic const char* lua_tolstring(lua_State*L,int idx,size_t*len);\nstatic size_t lua_objlen(lua_State*L,int idx);\nstatic void lua_pushlstring(lua_State*L,const char*s,size_t l);\nstatic void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n);\nstatic void lua_createtable(lua_State*L,int narr,int nrec);\nstatic void lua_setfield(lua_State*L,int idx,const char*k);\n#define lua_pop(L,n)lua_settop(L,-(n)-1)\n#define lua_newtable(L)lua_createtable(L,0,0)\n#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0)\n#define lua_strlen(L,i)lua_objlen(L,(i))\n#define lua_isfunction(L,n)(lua_type(L,(n))==6)\n#define lua_istable(L,n)(lua_type(L,(n))==5)\n#define lua_isnil(L,n)(lua_type(L,(n))==0)\n#define lua_isboolean(L,n)(lua_type(L,(n))==1)\n#define lua_isnone(L,n)(lua_type(L,(n))==(-1))\n#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0)\n#define lua_pushliteral(L,s)lua_pushlstring(L,\"\"s,(sizeof(s)/sizeof(char))-1)\n#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s))\n#define lua_tostring(L,i)lua_tolstring(L,(i),NULL)\ntypedef struct lua_Debug lua_Debug;\ntypedef void(*lua_Hook)(lua_State*L,lua_Debug*ar);\nstruct lua_Debug{\nint event;\nconst char*name;\nconst char*namewhat;\nconst char*what;\nconst char*source;\nint currentline;\nint nups;\nint linedefined;\nint lastlinedefined;\nchar short_src[60];\nint i_ci;\n};\ntypedef unsigned int lu_int32;\ntypedef size_t lu_mem;\ntypedef ptrdiff_t l_mem;\ntypedef unsigned char lu_byte;\n#define IntPoint(p)((unsigned int)(lu_mem)(p))\ntypedef union{double u;void*s;long l;}L_Umaxalign;\ntypedef double l_uacNumber;\n#define check_exp(c,e)(e)\n#define UNUSED(x)((void)(x))\n#define cast(t,exp)((t)(exp))\n#define cast_byte(i)cast(lu_byte,(i))\n#define cast_num(i)cast(lua_Number,(i))\n#define cast_int(i)cast(int,(i))\ntypedef lu_int32 Instruction;\n#define condhardstacktests(x)((void)0)\ntypedef union GCObject GCObject;\ntypedef struct GCheader{\nGCObject*next;lu_byte tt;lu_byte marked;\n}GCheader;\ntypedef union{\nGCObject*gc;\nvoid*p;\nlua_Number n;\nint b;\n}Value;\ntypedef struct lua_TValue{\nValue value;int tt;\n}TValue;\n#define ttisnil(o)(ttype(o)==0)\n#define ttisnumber(o)(ttype(o)==3)\n#define ttisstring(o)(ttype(o)==4)\n#define ttistable(o)(ttype(o)==5)\n#define ttisfunction(o)(ttype(o)==6)\n#define ttisboolean(o)(ttype(o)==1)\n#define ttisuserdata(o)(ttype(o)==7)\n#define ttisthread(o)(ttype(o)==8)\n#define ttislightuserdata(o)(ttype(o)==2)\n#define ttype(o)((o)->tt)\n#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc)\n#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p)\n#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n)\n#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts)\n#define tsvalue(o)(&rawtsvalue(o)->tsv)\n#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u)\n#define uvalue(o)(&rawuvalue(o)->uv)\n#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl)\n#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h)\n#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b)\n#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th)\n#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0))\n#define checkconsistency(obj)\n#define checkliveness(g,obj)\n#define setnilvalue(obj)((obj)->tt=0)\n#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;}\n#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;}\n#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);}\n#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);}\n#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);}\n#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);}\n#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);}\n#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);}\n#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);}\n#define setttype(obj,tt)(ttype(obj)=(tt))\n#define iscollectable(o)(ttype(o)>=4)\ntypedef TValue*StkId;\ntypedef union TString{\nL_Umaxalign dummy;\nstruct{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte reserved;\nunsigned int hash;\nsize_t len;\n}tsv;\n}TString;\n#define getstr(ts)cast(const char*,(ts)+1)\n#define svalue(o)getstr(rawtsvalue(o))\ntypedef union Udata{\nL_Umaxalign dummy;\nstruct{\nGCObject*next;lu_byte tt;lu_byte marked;\nstruct Table*metatable;\nstruct Table*env;\nsize_t len;\n}uv;\n}Udata;\ntypedef struct Proto{\nGCObject*next;lu_byte tt;lu_byte marked;\nTValue*k;\nInstruction*code;\nstruct Proto**p;\nint*lineinfo;\nstruct LocVar*locvars;\nTString**upvalues;\nTString*source;\nint sizeupvalues;\nint sizek;\nint sizecode;\nint sizelineinfo;\nint sizep;\nint sizelocvars;\nint linedefined;\nint lastlinedefined;\nGCObject*gclist;\nlu_byte nups;\nlu_byte numparams;\nlu_byte is_vararg;\nlu_byte maxstacksize;\n}Proto;\ntypedef struct LocVar{\nTString*varname;\nint startpc;\nint endpc;\n}LocVar;\ntypedef struct UpVal{\nGCObject*next;lu_byte tt;lu_byte marked;\nTValue*v;\nunion{\nTValue value;\nstruct{\nstruct UpVal*prev;\nstruct UpVal*next;\n}l;\n}u;\n}UpVal;\ntypedef struct CClosure{\nGCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;\nlua_CFunction f;\nTValue upvalue[1];\n}CClosure;\ntypedef struct LClosure{\nGCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;\nstruct Proto*p;\nUpVal*upvals[1];\n}LClosure;\ntypedef union Closure{\nCClosure c;\nLClosure l;\n}Closure;\n#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC)\ntypedef union TKey{\nstruct{\nValue value;int tt;\nstruct Node*next;\n}nk;\nTValue tvk;\n}TKey;\ntypedef struct Node{\nTValue i_val;\nTKey i_key;\n}Node;\ntypedef struct Table{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte flags;\nlu_byte lsizenode;\nstruct Table*metatable;\nTValue*array;\nNode*node;\nNode*lastfree;\nGCObject*gclist;\nint sizearray;\n}Table;\n#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1)))))\n#define twoto(x)((size_t)1<<(x))\n#define sizenode(t)(twoto((t)->lsizenode))\nstatic const TValue luaO_nilobject_;\n#define ceillog2(x)(luaO_log2((x)-1)+1)\nstatic int luaO_log2(unsigned int x);\n#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e]))\n#define fasttm(l,et,e)gfasttm(G(l),et,e)\nstatic const TValue*luaT_gettm(Table*events,TMS event,TString*ename);\n#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L))\n#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0)\n#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0)\n#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t))\n#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t))\n#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t)))\n#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t)))\n#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t))))\nstatic void*luaM_realloc_(lua_State*L,void*block,size_t oldsize,\nsize_t size);\nstatic void*luaM_toobig(lua_State*L);\nstatic void*luaM_growaux_(lua_State*L,void*block,int*size,\nsize_t size_elem,int limit,\nconst char*errormsg);\ntypedef struct Zio ZIO;\n#define char2int(c)cast(int,cast(unsigned char,(c)))\n#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z))\ntypedef struct Mbuffer{\nchar*buffer;\nsize_t n;\nsize_t buffsize;\n}Mbuffer;\n#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0)\n#define luaZ_buffer(buff)((buff)->buffer)\n#define luaZ_sizebuffer(buff)((buff)->buffsize)\n#define luaZ_bufflen(buff)((buff)->n)\n#define luaZ_resetbuffer(buff)((buff)->n=0)\n#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size)\n#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0)\nstruct Zio{\nsize_t n;\nconst char*p;\nlua_Reader reader;\nvoid*data;\nlua_State*L;\n};\nstatic int luaZ_fill(ZIO*z);\nstruct lua_longjmp;\n#define gt(L)(&L->l_gt)\n#define registry(L)(&G(L)->l_registry)\ntypedef struct stringtable{\nGCObject**hash;\nlu_int32 nuse;\nint size;\n}stringtable;\ntypedef struct CallInfo{\nStkId base;\nStkId func;\nStkId top;\nconst Instruction*savedpc;\nint nresults;\nint tailcalls;\n}CallInfo;\n#define curr_func(L)(clvalue(L->ci->func))\n#define ci_func(ci)(clvalue((ci)->func))\n#define f_isLua(ci)(!ci_func(ci)->c.isC)\n#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci))\ntypedef struct global_State{\nstringtable strt;\nlua_Alloc frealloc;\nvoid*ud;\nlu_byte currentwhite;\nlu_byte gcstate;\nint sweepstrgc;\nGCObject*rootgc;\nGCObject**sweepgc;\nGCObject*gray;\nGCObject*grayagain;\nGCObject*weak;\nGCObject*tmudata;\nMbuffer buff;\nlu_mem GCthreshold;\nlu_mem totalbytes;\nlu_mem estimate;\nlu_mem gcdept;\nint gcpause;\nint gcstepmul;\nlua_CFunction panic;\nTValue l_registry;\nstruct lua_State*mainthread;\nUpVal uvhead;\nstruct Table*mt[(8+1)];\nTString*tmname[TM_N];\n}global_State;\nstruct lua_State{\nGCObject*next;lu_byte tt;lu_byte marked;\nlu_byte status;\nStkId top;\nStkId base;\nglobal_State*l_G;\nCallInfo*ci;\nconst Instruction*savedpc;\nStkId stack_last;\nStkId stack;\nCallInfo*end_ci;\nCallInfo*base_ci;\nint stacksize;\nint size_ci;\nunsigned short nCcalls;\nunsigned short baseCcalls;\nlu_byte hookmask;\nlu_byte allowhook;\nint basehookcount;\nint hookcount;\nlua_Hook hook;\nTValue l_gt;\nTValue env;\nGCObject*openupval;\nGCObject*gclist;\nstruct lua_longjmp*errorJmp;\nptrdiff_t errfunc;\n};\n#define G(L)(L->l_G)\nunion GCObject{\nGCheader gch;\nunion TString ts;\nunion Udata u;\nunion Closure cl;\nstruct Table h;\nstruct Proto p;\nstruct UpVal uv;\nstruct lua_State th;\n};\n#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts))\n#define gco2ts(o)(&rawgco2ts(o)->tsv)\n#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u))\n#define gco2u(o)(&rawgco2u(o)->uv)\n#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl))\n#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h))\n#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p))\n#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv))\n#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv))\n#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th))\n#define obj2gco(v)(cast(GCObject*,(v)))\nstatic void luaE_freethread(lua_State*L,lua_State*L1);\n#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1)\n#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0)\n#define resethookcount(L)(L->hookcount=L->basehookcount)\nstatic void luaG_typeerror(lua_State*L,const TValue*o,\nconst char*opname);\nstatic void luaG_runerror(lua_State*L,const char*fmt,...);\n#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));\n#define incr_top(L){luaD_checkstack(L,1);L->top++;}\n#define savestack(L,p)((char*)(p)-(char*)L->stack)\n#define restorestack(L,n)((TValue*)((char*)L->stack+(n)))\n#define saveci(L,p)((char*)(p)-(char*)L->base_ci)\n#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n)))\ntypedef void(*Pfunc)(lua_State*L,void*ud);\nstatic int luaD_poscall(lua_State*L,StkId firstResult);\nstatic void luaD_reallocCI(lua_State*L,int newsize);\nstatic void luaD_reallocstack(lua_State*L,int newsize);\nstatic void luaD_growstack(lua_State*L,int n);\nstatic void luaD_throw(lua_State*L,int errcode);\nstatic void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems,\nint limit,const char*errormsg){\nvoid*newblock;\nint newsize;\nif(*size>=limit/2){\nif(*size>=limit)\nluaG_runerror(L,errormsg);\nnewsize=limit;\n}\nelse{\nnewsize=(*size)*2;\nif(newsize<4)\nnewsize=4;\n}\nnewblock=luaM_reallocv(L,block,*size,newsize,size_elems);\n*size=newsize;\nreturn newblock;\n}\nstatic void*luaM_toobig(lua_State*L){\nluaG_runerror(L,\"memory allocation error: block too big\");\nreturn NULL;\n}\nstatic void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){\nglobal_State*g=G(L);\nblock=(*g->frealloc)(g->ud,block,osize,nsize);\nif(block==NULL&&nsize>0)\nluaD_throw(L,4);\ng->totalbytes=(g->totalbytes-osize)+nsize;\nreturn block;\n}\n#define resetbits(x,m)((x)&=cast(lu_byte,~(m)))\n#define setbits(x,m)((x)|=(m))\n#define testbits(x,m)((x)&(m))\n#define bitmask(b)(1<<(b))\n#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2))\n#define l_setbit(x,b)setbits(x,bitmask(b))\n#define resetbit(x,b)resetbits(x,bitmask(b))\n#define testbit(x,b)testbits(x,bitmask(b))\n#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2)))\n#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2)))\n#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2)))\n#define iswhite(x)test2bits((x)->gch.marked,0,1)\n#define isblack(x)testbit((x)->gch.marked,2)\n#define isgray(x)(!isblack(x)&&!iswhite(x))\n#define otherwhite(g)(g->currentwhite^bit2mask(0,1))\n#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1))\n#define changewhite(x)((x)->gch.marked^=bit2mask(0,1))\n#define gray2black(x)l_setbit((x)->gch.marked,2)\n#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x)))\n#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1))\n#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);}\n#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));}\n#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);}\n#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));}\n#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);}\nstatic void luaC_step(lua_State*L);\nstatic void luaC_link(lua_State*L,GCObject*o,lu_byte tt);\nstatic void luaC_linkupval(lua_State*L,UpVal*uv);\nstatic void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v);\nstatic void luaC_barrierback(lua_State*L,Table*t);\n#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char))\n#define sizeudata(u)(sizeof(union Udata)+(u)->len)\n#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s)))\n#define luaS_newliteral(L,s)(luaS_newlstr(L,\"\"s,(sizeof(s)/sizeof(char))-1))\n#define luaS_fix(s)l_setbit((s)->tsv.marked,5)\nstatic TString*luaS_newlstr(lua_State*L,const char*str,size_t l);\n#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o)))\n#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL))\n#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2))\nstatic int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2);\nstatic const TValue*luaV_tonumber(const TValue*obj,TValue*n);\nstatic int luaV_tostring(lua_State*L,StkId obj);\nstatic void luaV_execute(lua_State*L,int nexeccalls);\nstatic void luaV_concat(lua_State*L,int total,int last);\nstatic const TValue luaO_nilobject_={{NULL},0};\nstatic int luaO_int2fb(unsigned int x){\nint e=0;\nwhile(x>=16){\nx=(x+1)>>1;\ne++;\n}\nif(x<8)return x;\nelse return((e+1)<<3)|(cast_int(x)-8);\n}\nstatic int luaO_fb2int(int x){\nint e=(x>>3)&31;\nif(e==0)return x;\nelse return((x&7)+8)<<(e-1);\n}\nstatic int luaO_log2(unsigned int x){\nstatic const lu_byte log_2[256]={\n0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n};\nint l=-1;\nwhile(x>=256){l+=8;x>>=8;}\nreturn l+log_2[x];\n}\nstatic int luaO_rawequalObj(const TValue*t1,const TValue*t2){\nif(ttype(t1)!=ttype(t2))return 0;\nelse switch(ttype(t1)){\ncase 0:\nreturn 1;\ncase 3:\nreturn luai_numeq(nvalue(t1),nvalue(t2));\ncase 1:\nreturn bvalue(t1)==bvalue(t2);\ncase 2:\nreturn pvalue(t1)==pvalue(t2);\ndefault:\nreturn gcvalue(t1)==gcvalue(t2);\n}\n}\nstatic int luaO_str2d(const char*s,lua_Number*result){\nchar*endptr;\n*result=lua_str2number(s,&endptr);\nif(endptr==s)return 0;\nif(*endptr=='x'||*endptr=='X')\n*result=cast_num(strtoul(s,&endptr,16));\nif(*endptr=='\\0')return 1;\nwhile(isspace(cast(unsigned char,*endptr)))endptr++;\nif(*endptr!='\\0')return 0;\nreturn 1;\n}\nstatic void pushstr(lua_State*L,const char*str){\nsetsvalue(L,L->top,luaS_new(L,str));\nincr_top(L);\n}\nstatic const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){\nint n=1;\npushstr(L,\"\");\nfor(;;){\nconst char*e=strchr(fmt,'%');\nif(e==NULL)break;\nsetsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt));\nincr_top(L);\nswitch(*(e+1)){\ncase's':{\nconst char*s=va_arg(argp,char*);\nif(s==NULL)s=\"(null)\";\npushstr(L,s);\nbreak;\n}\ncase'c':{\nchar buff[2];\nbuff[0]=cast(char,va_arg(argp,int));\nbuff[1]='\\0';\npushstr(L,buff);\nbreak;\n}\ncase'd':{\nsetnvalue(L->top,cast_num(va_arg(argp,int)));\nincr_top(L);\nbreak;\n}\ncase'f':{\nsetnvalue(L->top,cast_num(va_arg(argp,l_uacNumber)));\nincr_top(L);\nbreak;\n}\ncase'p':{\nchar buff[4*sizeof(void*)+8];\nsprintf(buff,\"%p\",va_arg(argp,void*));\npushstr(L,buff);\nbreak;\n}\ncase'%':{\npushstr(L,\"%\");\nbreak;\n}\ndefault:{\nchar buff[3];\nbuff[0]='%';\nbuff[1]=*(e+1);\nbuff[2]='\\0';\npushstr(L,buff);\nbreak;\n}\n}\nn+=2;\nfmt=e+2;\n}\npushstr(L,fmt);\nluaV_concat(L,n+1,cast_int(L->top-L->base)-1);\nL->top-=n;\nreturn svalue(L->top-1);\n}\nstatic const char*luaO_pushfstring(lua_State*L,const char*fmt,...){\nconst char*msg;\nva_list argp;\nva_start(argp,fmt);\nmsg=luaO_pushvfstring(L,fmt,argp);\nva_end(argp);\nreturn msg;\n}\nstatic void luaO_chunkid(char*out,const char*source,size_t bufflen){\nif(*source=='='){\nstrncpy(out,source+1,bufflen);\nout[bufflen-1]='\\0';\n}\nelse{\nif(*source=='@'){\nsize_t l;\nsource++;\nbufflen-=sizeof(\" '...' \");\nl=strlen(source);\nstrcpy(out,\"\");\nif(l>bufflen){\nsource+=(l-bufflen);\nstrcat(out,\"...\");\n}\nstrcat(out,source);\n}\nelse{\nsize_t len=strcspn(source,\"\\n\\r\");\nbufflen-=sizeof(\" [string \\\"...\\\"] \");\nif(len>bufflen)len=bufflen;\nstrcpy(out,\"[string \\\"\");\nif(source[len]!='\\0'){\nstrncat(out,source,len);\nstrcat(out,\"...\");\n}\nelse\nstrcat(out,source);\nstrcat(out,\"\\\"]\");\n}\n}\n}\n#define gnode(t,i)(&(t)->node[i])\n#define gkey(n)(&(n)->i_key.nk)\n#define gval(n)(&(n)->i_val)\n#define gnext(n)((n)->i_key.nk.next)\n#define key2tval(n)(&(n)->i_key.tvk)\nstatic TValue*luaH_setnum(lua_State*L,Table*t,int key);\nstatic const TValue*luaH_getstr(Table*t,TString*key);\nstatic TValue*luaH_set(lua_State*L,Table*t,const TValue*key);\nstatic const char*const luaT_typenames[]={\n\"nil\",\"boolean\",\"userdata\",\"number\",\n\"string\",\"table\",\"function\",\"userdata\",\"thread\",\n\"proto\",\"upval\"\n};\nstatic void luaT_init(lua_State*L){\nstatic const char*const luaT_eventname[]={\n\"__index\",\"__newindex\",\n\"__gc\",\"__mode\",\"__eq\",\n\"__add\",\"__sub\",\"__mul\",\"__div\",\"__mod\",\n\"__pow\",\"__unm\",\"__len\",\"__lt\",\"__le\",\n\"__concat\",\"__call\"\n};\nint i;\nfor(i=0;i<TM_N;i++){\nG(L)->tmname[i]=luaS_new(L,luaT_eventname[i]);\nluaS_fix(G(L)->tmname[i]);\n}\n}\nstatic const TValue*luaT_gettm(Table*events,TMS event,TString*ename){\nconst TValue*tm=luaH_getstr(events,ename);\nif(ttisnil(tm)){\nevents->flags|=cast_byte(1u<<event);\nreturn NULL;\n}\nelse return tm;\n}\nstatic const TValue*luaT_gettmbyobj(lua_State*L,const TValue*o,TMS event){\nTable*mt;\nswitch(ttype(o)){\ncase 5:\nmt=hvalue(o)->metatable;\nbreak;\ncase 7:\nmt=uvalue(o)->metatable;\nbreak;\ndefault:\nmt=G(L)->mt[ttype(o)];\n}\nreturn(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_));\n}\n#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1)))\n#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1)))\nstatic Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){\nClosure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems)));\nluaC_link(L,obj2gco(c),6);\nc->c.isC=1;\nc->c.env=e;\nc->c.nupvalues=cast_byte(nelems);\nreturn c;\n}\nstatic Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){\nClosure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems)));\nluaC_link(L,obj2gco(c),6);\nc->l.isC=0;\nc->l.env=e;\nc->l.nupvalues=cast_byte(nelems);\nwhile(nelems--)c->l.upvals[nelems]=NULL;\nreturn c;\n}\nstatic UpVal*luaF_newupval(lua_State*L){\nUpVal*uv=luaM_new(L,UpVal);\nluaC_link(L,obj2gco(uv),(8+2));\nuv->v=&uv->u.value;\nsetnilvalue(uv->v);\nreturn uv;\n}\nstatic UpVal*luaF_findupval(lua_State*L,StkId level){\nglobal_State*g=G(L);\nGCObject**pp=&L->openupval;\nUpVal*p;\nUpVal*uv;\nwhile(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){\nif(p->v==level){\nif(isdead(g,obj2gco(p)))\nchangewhite(obj2gco(p));\nreturn p;\n}\npp=&p->next;\n}\nuv=luaM_new(L,UpVal);\nuv->tt=(8+2);\nuv->marked=luaC_white(g);\nuv->v=level;\nuv->next=*pp;\n*pp=obj2gco(uv);\nuv->u.l.prev=&g->uvhead;\nuv->u.l.next=g->uvhead.u.l.next;\nuv->u.l.next->u.l.prev=uv;\ng->uvhead.u.l.next=uv;\nreturn uv;\n}\nstatic void unlinkupval(UpVal*uv){\nuv->u.l.next->u.l.prev=uv->u.l.prev;\nuv->u.l.prev->u.l.next=uv->u.l.next;\n}\nstatic void luaF_freeupval(lua_State*L,UpVal*uv){\nif(uv->v!=&uv->u.value)\nunlinkupval(uv);\nluaM_free(L,uv);\n}\nstatic void luaF_close(lua_State*L,StkId level){\nUpVal*uv;\nglobal_State*g=G(L);\nwhile(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){\nGCObject*o=obj2gco(uv);\nL->openupval=uv->next;\nif(isdead(g,o))\nluaF_freeupval(L,uv);\nelse{\nunlinkupval(uv);\nsetobj(L,&uv->u.value,uv->v);\nuv->v=&uv->u.value;\nluaC_linkupval(L,uv);\n}\n}\n}\nstatic Proto*luaF_newproto(lua_State*L){\nProto*f=luaM_new(L,Proto);\nluaC_link(L,obj2gco(f),(8+1));\nf->k=NULL;\nf->sizek=0;\nf->p=NULL;\nf->sizep=0;\nf->code=NULL;\nf->sizecode=0;\nf->sizelineinfo=0;\nf->sizeupvalues=0;\nf->nups=0;\nf->upvalues=NULL;\nf->numparams=0;\nf->is_vararg=0;\nf->maxstacksize=0;\nf->lineinfo=NULL;\nf->sizelocvars=0;\nf->locvars=NULL;\nf->linedefined=0;\nf->lastlinedefined=0;\nf->source=NULL;\nreturn f;\n}\nstatic void luaF_freeproto(lua_State*L,Proto*f){\nluaM_freearray(L,f->code,f->sizecode,Instruction);\nluaM_freearray(L,f->p,f->sizep,Proto*);\nluaM_freearray(L,f->k,f->sizek,TValue);\nluaM_freearray(L,f->lineinfo,f->sizelineinfo,int);\nluaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar);\nluaM_freearray(L,f->upvalues,f->sizeupvalues,TString*);\nluaM_free(L,f);\n}\nstatic void luaF_freeclosure(lua_State*L,Closure*c){\nint size=(c->c.isC)?sizeCclosure(c->c.nupvalues):\nsizeLclosure(c->l.nupvalues);\nluaM_freemem(L,c,size);\n}\n#define MASK1(n,p)((~((~(Instruction)0)<<n))<<p)\n#define MASK0(n,p)(~MASK1(n,p))\n#define GET_OPCODE(i)(cast(OpCode,((i)>>0)&MASK1(6,0)))\n#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0))))\n#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0)))\n#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6)))))\n#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0)))\n#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9)))))\n#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0)))\n#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8)))))\n#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0)))\n#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8)))))\n#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1))\n#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1)))\n#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8)))\n#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8)))\n#define ISK(x)((x)&(1<<(9-1)))\n#define INDEXK(r)((int)(r)&~(1<<(9-1)))\n#define RKASK(x)((x)|(1<<(9-1)))\nstatic const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)];\n#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3))\n#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3))\n#define testTMode(m)(luaP_opmodes[m]&(1<<7))\ntypedef struct expdesc{\nexpkind k;\nunion{\nstruct{int info,aux;}s;\nlua_Number nval;\n}u;\nint t;\nint f;\n}expdesc;\ntypedef struct upvaldesc{\nlu_byte k;\nlu_byte info;\n}upvaldesc;\nstruct BlockCnt;\ntypedef struct FuncState{\nProto*f;\nTable*h;\nstruct FuncState*prev;\nstruct LexState*ls;\nstruct lua_State*L;\nstruct BlockCnt*bl;\nint pc;\nint lasttarget;\nint jpc;\nint freereg;\nint nk;\nint np;\nshort nlocvars;\nlu_byte nactvar;\nupvaldesc upvalues[60];\nunsigned short actvar[200];\n}FuncState;\nstatic Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,\nconst char*name);\nstruct lua_longjmp{\nstruct lua_longjmp*previous;\njmp_buf b;\nvolatile int status;\n};\nstatic void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){\nswitch(errcode){\ncase 4:{\nsetsvalue(L,oldtop,luaS_newliteral(L,\"not enough memory\"));\nbreak;\n}\ncase 5:{\nsetsvalue(L,oldtop,luaS_newliteral(L,\"error in error handling\"));\nbreak;\n}\ncase 3:\ncase 2:{\nsetobj(L,oldtop,L->top-1);\nbreak;\n}\n}\nL->top=oldtop+1;\n}\nstatic void restore_stack_limit(lua_State*L){\nif(L->size_ci>20000){\nint inuse=cast_int(L->ci-L->base_ci);\nif(inuse+1<20000)\nluaD_reallocCI(L,20000);\n}\n}\nstatic void resetstack(lua_State*L,int status){\nL->ci=L->base_ci;\nL->base=L->ci->base;\nluaF_close(L,L->base);\nluaD_seterrorobj(L,status,L->base);\nL->nCcalls=L->baseCcalls;\nL->allowhook=1;\nrestore_stack_limit(L);\nL->errfunc=0;\nL->errorJmp=NULL;\n}\nstatic void luaD_throw(lua_State*L,int errcode){\nif(L->errorJmp){\nL->errorJmp->status=errcode;\nLUAI_THROW(L,L->errorJmp);\n}\nelse{\nL->status=cast_byte(errcode);\nif(G(L)->panic){\nresetstack(L,errcode);\nG(L)->panic(L);\n}\nexit(EXIT_FAILURE);\n}\n}\nstatic int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){\nstruct lua_longjmp lj;\nlj.status=0;\nlj.previous=L->errorJmp;\nL->errorJmp=&lj;\nLUAI_TRY(L,&lj,\n(*f)(L,ud);\n);\nL->errorJmp=lj.previous;\nreturn lj.status;\n}\nstatic void correctstack(lua_State*L,TValue*oldstack){\nCallInfo*ci;\nGCObject*up;\nL->top=(L->top-oldstack)+L->stack;\nfor(up=L->openupval;up!=NULL;up=up->gch.next)\ngco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack;\nfor(ci=L->base_ci;ci<=L->ci;ci++){\nci->top=(ci->top-oldstack)+L->stack;\nci->base=(ci->base-oldstack)+L->stack;\nci->func=(ci->func-oldstack)+L->stack;\n}\nL->base=(L->base-oldstack)+L->stack;\n}\nstatic void luaD_reallocstack(lua_State*L,int newsize){\nTValue*oldstack=L->stack;\nint realsize=newsize+1+5;\nluaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue);\nL->stacksize=realsize;\nL->stack_last=L->stack+newsize;\ncorrectstack(L,oldstack);\n}\nstatic void luaD_reallocCI(lua_State*L,int newsize){\nCallInfo*oldci=L->base_ci;\nluaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo);\nL->size_ci=newsize;\nL->ci=(L->ci-oldci)+L->base_ci;\nL->end_ci=L->base_ci+L->size_ci-1;\n}\nstatic void luaD_growstack(lua_State*L,int n){\nif(n<=L->stacksize)\nluaD_reallocstack(L,2*L->stacksize);\nelse\nluaD_reallocstack(L,L->stacksize+n);\n}\nstatic CallInfo*growCI(lua_State*L){\nif(L->size_ci>20000)\nluaD_throw(L,5);\nelse{\nluaD_reallocCI(L,2*L->size_ci);\nif(L->size_ci>20000)\nluaG_runerror(L,\"stack overflow\");\n}\nreturn++L->ci;\n}\nstatic StkId adjust_varargs(lua_State*L,Proto*p,int actual){\nint i;\nint nfixargs=p->numparams;\nTable*htab=NULL;\nStkId base,fixed;\nfor(;actual<nfixargs;++actual)\nsetnilvalue(L->top++);\nfixed=L->top-actual;\nbase=L->top;\nfor(i=0;i<nfixargs;i++){\nsetobj(L,L->top++,fixed+i);\nsetnilvalue(fixed+i);\n}\nif(htab){\nsethvalue(L,L->top++,htab);\n}\nreturn base;\n}\nstatic StkId tryfuncTM(lua_State*L,StkId func){\nconst TValue*tm=luaT_gettmbyobj(L,func,TM_CALL);\nStkId p;\nptrdiff_t funcr=savestack(L,func);\nif(!ttisfunction(tm))\nluaG_typeerror(L,func,\"call\");\nfor(p=L->top;p>func;p--)setobj(L,p,p-1);\nincr_top(L);\nfunc=restorestack(L,funcr);\nsetobj(L,func,tm);\nreturn func;\n}\n#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci))\nstatic int luaD_precall(lua_State*L,StkId func,int nresults){\nLClosure*cl;\nptrdiff_t funcr;\nif(!ttisfunction(func))\nfunc=tryfuncTM(L,func);\nfuncr=savestack(L,func);\ncl=&clvalue(func)->l;\nL->ci->savedpc=L->savedpc;\nif(!cl->isC){\nCallInfo*ci;\nStkId st,base;\nProto*p=cl->p;\nluaD_checkstack(L,p->maxstacksize+p->numparams);\nfunc=restorestack(L,funcr);\nif(!p->is_vararg){\nbase=func+1;\nif(L->top>base+p->numparams)\nL->top=base+p->numparams;\n}\nelse{\nint nargs=cast_int(L->top-func)-1;\nbase=adjust_varargs(L,p,nargs);\nfunc=restorestack(L,funcr);\n}\nci=inc_ci(L);\nci->func=func;\nL->base=ci->base=base;\nci->top=L->base+p->maxstacksize;\nL->savedpc=p->code;\nci->tailcalls=0;\nci->nresults=nresults;\nfor(st=L->top;st<ci->top;st++)\nsetnilvalue(st);\nL->top=ci->top;\nreturn 0;\n}\nelse{\nCallInfo*ci;\nint n;\nluaD_checkstack(L,20);\nci=inc_ci(L);\nci->func=restorestack(L,funcr);\nL->base=ci->base=ci->func+1;\nci->top=L->top+20;\nci->nresults=nresults;\nn=(*curr_func(L)->c.f)(L);\nif(n<0)\nreturn 2;\nelse{\nluaD_poscall(L,L->top-n);\nreturn 1;\n}\n}\n}\nstatic int luaD_poscall(lua_State*L,StkId firstResult){\nStkId res;\nint wanted,i;\nCallInfo*ci;\nci=L->ci--;\nres=ci->func;\nwanted=ci->nresults;\nL->base=(ci-1)->base;\nL->savedpc=(ci-1)->savedpc;\nfor(i=wanted;i!=0&&firstResult<L->top;i--)\nsetobj(L,res++,firstResult++);\nwhile(i-->0)\nsetnilvalue(res++);\nL->top=res;\nreturn(wanted-(-1));\n}\nstatic void luaD_call(lua_State*L,StkId func,int nResults){\nif(++L->nCcalls>=200){\nif(L->nCcalls==200)\nluaG_runerror(L,\"C stack overflow\");\nelse if(L->nCcalls>=(200+(200>>3)))\nluaD_throw(L,5);\n}\nif(luaD_precall(L,func,nResults)==0)\nluaV_execute(L,1);\nL->nCcalls--;\nluaC_checkGC(L);\n}\nstatic int luaD_pcall(lua_State*L,Pfunc func,void*u,\nptrdiff_t old_top,ptrdiff_t ef){\nint status;\nunsigned short oldnCcalls=L->nCcalls;\nptrdiff_t old_ci=saveci(L,L->ci);\nlu_byte old_allowhooks=L->allowhook;\nptrdiff_t old_errfunc=L->errfunc;\nL->errfunc=ef;\nstatus=luaD_rawrunprotected(L,func,u);\nif(status!=0){\nStkId oldtop=restorestack(L,old_top);\nluaF_close(L,oldtop);\nluaD_seterrorobj(L,status,oldtop);\nL->nCcalls=oldnCcalls;\nL->ci=restoreci(L,old_ci);\nL->base=L->ci->base;\nL->savedpc=L->ci->savedpc;\nL->allowhook=old_allowhooks;\nrestore_stack_limit(L);\n}\nL->errfunc=old_errfunc;\nreturn status;\n}\nstruct SParser{\nZIO*z;\nMbuffer buff;\nconst char*name;\n};\nstatic void f_parser(lua_State*L,void*ud){\nint i;\nProto*tf;\nClosure*cl;\nstruct SParser*p=cast(struct SParser*,ud);\nluaC_checkGC(L);\ntf=luaY_parser(L,p->z,\n&p->buff,p->name);\ncl=luaF_newLclosure(L,tf->nups,hvalue(gt(L)));\ncl->l.p=tf;\nfor(i=0;i<tf->nups;i++)\ncl->l.upvals[i]=luaF_newupval(L);\nsetclvalue(L,L->top,cl);\nincr_top(L);\n}\nstatic int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){\nstruct SParser p;\nint status;\np.z=z;p.name=name;\nluaZ_initbuffer(L,&p.buff);\nstatus=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc);\nluaZ_freebuffer(L,&p.buff);\nreturn status;\n}\nstatic void luaS_resize(lua_State*L,int newsize){\nGCObject**newhash;\nstringtable*tb;\nint i;\nif(G(L)->gcstate==2)\nreturn;\nnewhash=luaM_newvector(L,newsize,GCObject*);\ntb=&G(L)->strt;\nfor(i=0;i<newsize;i++)newhash[i]=NULL;\nfor(i=0;i<tb->size;i++){\nGCObject*p=tb->hash[i];\nwhile(p){\nGCObject*next=p->gch.next;\nunsigned int h=gco2ts(p)->hash;\nint h1=lmod(h,newsize);\np->gch.next=newhash[h1];\nnewhash[h1]=p;\np=next;\n}\n}\nluaM_freearray(L,tb->hash,tb->size,TString*);\ntb->size=newsize;\ntb->hash=newhash;\n}\nstatic TString*newlstr(lua_State*L,const char*str,size_t l,\nunsigned int h){\nTString*ts;\nstringtable*tb;\nif(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char))\nluaM_toobig(L);\nts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString)));\nts->tsv.len=l;\nts->tsv.hash=h;\nts->tsv.marked=luaC_white(G(L));\nts->tsv.tt=4;\nts->tsv.reserved=0;\nmemcpy(ts+1,str,l*sizeof(char));\n((char*)(ts+1))[l]='\\0';\ntb=&G(L)->strt;\nh=lmod(h,tb->size);\nts->tsv.next=tb->hash[h];\ntb->hash[h]=obj2gco(ts);\ntb->nuse++;\nif(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2)\nluaS_resize(L,tb->size*2);\nreturn ts;\n}\nstatic TString*luaS_newlstr(lua_State*L,const char*str,size_t l){\nGCObject*o;\nunsigned int h=cast(unsigned int,l);\nsize_t step=(l>>5)+1;\nsize_t l1;\nfor(l1=l;l1>=step;l1-=step)\nh=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1]));\nfor(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)];\no!=NULL;\no=o->gch.next){\nTString*ts=rawgco2ts(o);\nif(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){\nif(isdead(G(L),o))changewhite(o);\nreturn ts;\n}\n}\nreturn newlstr(L,str,l,h);\n}\nstatic Udata*luaS_newudata(lua_State*L,size_t s,Table*e){\nUdata*u;\nif(s>((size_t)(~(size_t)0)-2)-sizeof(Udata))\nluaM_toobig(L);\nu=cast(Udata*,luaM_malloc(L,s+sizeof(Udata)));\nu->uv.marked=luaC_white(G(L));\nu->uv.tt=7;\nu->uv.len=s;\nu->uv.metatable=NULL;\nu->uv.env=e;\nu->uv.next=G(L)->mainthread->next;\nG(L)->mainthread->next=obj2gco(u);\nreturn u;\n}\n#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t))))\n#define hashstr(t,str)hashpow2(t,(str)->tsv.hash)\n#define hashboolean(t,p)hashpow2(t,p)\n#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1))))\n#define hashpointer(t,p)hashmod(t,IntPoint(p))\nstatic const Node dummynode_={\n{{NULL},0},\n{{{NULL},0,NULL}}\n};\nstatic Node*hashnum(const Table*t,lua_Number n){\nunsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))];\nint i;\nif(luai_numeq(n,0))\nreturn gnode(t,0);\nmemcpy(a,&n,sizeof(a));\nfor(i=1;i<cast_int(sizeof(lua_Number)/sizeof(int));i++)a[0]+=a[i];\nreturn hashmod(t,a[0]);\n}\nstatic Node*mainposition(const Table*t,const TValue*key){\nswitch(ttype(key)){\ncase 3:\nreturn hashnum(t,nvalue(key));\ncase 4:\nreturn hashstr(t,rawtsvalue(key));\ncase 1:\nreturn hashboolean(t,bvalue(key));\ncase 2:\nreturn hashpointer(t,pvalue(key));\ndefault:\nreturn hashpointer(t,gcvalue(key));\n}\n}\nstatic int arrayindex(const TValue*key){\nif(ttisnumber(key)){\nlua_Number n=nvalue(key);\nint k;\nlua_number2int(k,n);\nif(luai_numeq(cast_num(k),n))\nreturn k;\n}\nreturn-1;\n}\nstatic int findindex(lua_State*L,Table*t,StkId key){\nint i;\nif(ttisnil(key))return-1;\ni=arrayindex(key);\nif(0<i&&i<=t->sizearray)\nreturn i-1;\nelse{\nNode*n=mainposition(t,key);\ndo{\nif(luaO_rawequalObj(key2tval(n),key)||\n(ttype(gkey(n))==(8+3)&&iscollectable(key)&&\ngcvalue(gkey(n))==gcvalue(key))){\ni=cast_int(n-gnode(t,0));\nreturn i+t->sizearray;\n}\nelse n=gnext(n);\n}while(n);\nluaG_runerror(L,\"invalid key to \"LUA_QL(\"next\"));\nreturn 0;\n}\n}\nstatic int luaH_next(lua_State*L,Table*t,StkId key){\nint i=findindex(L,t,key);\nfor(i++;i<t->sizearray;i++){\nif(!ttisnil(&t->array[i])){\nsetnvalue(key,cast_num(i+1));\nsetobj(L,key+1,&t->array[i]);\nreturn 1;\n}\n}\nfor(i-=t->sizearray;i<(int)sizenode(t);i++){\nif(!ttisnil(gval(gnode(t,i)))){\nsetobj(L,key,key2tval(gnode(t,i)));\nsetobj(L,key+1,gval(gnode(t,i)));\nreturn 1;\n}\n}\nreturn 0;\n}\nstatic int computesizes(int nums[],int*narray){\nint i;\nint twotoi;\nint a=0;\nint na=0;\nint n=0;\nfor(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){\nif(nums[i]>0){\na+=nums[i];\nif(a>twotoi/2){\nn=twotoi;\nna=a;\n}\n}\nif(a==*narray)break;\n}\n*narray=n;\nreturn na;\n}\nstatic int countint(const TValue*key,int*nums){\nint k=arrayindex(key);\nif(0<k&&k<=(1<<(32-2))){\nnums[ceillog2(k)]++;\nreturn 1;\n}\nelse\nreturn 0;\n}\nstatic int numusearray(const Table*t,int*nums){\nint lg;\nint ttlg;\nint ause=0;\nint i=1;\nfor(lg=0,ttlg=1;lg<=(32-2);lg++,ttlg*=2){\nint lc=0;\nint lim=ttlg;\nif(lim>t->sizearray){\nlim=t->sizearray;\nif(i>lim)\nbreak;\n}\nfor(;i<=lim;i++){\nif(!ttisnil(&t->array[i-1]))\nlc++;\n}\nnums[lg]+=lc;\nause+=lc;\n}\nreturn ause;\n}\nstatic int numusehash(const Table*t,int*nums,int*pnasize){\nint totaluse=0;\nint ause=0;\nint i=sizenode(t);\nwhile(i--){\nNode*n=&t->node[i];\nif(!ttisnil(gval(n))){\nause+=countint(key2tval(n),nums);\ntotaluse++;\n}\n}\n*pnasize+=ause;\nreturn totaluse;\n}\nstatic void setarrayvector(lua_State*L,Table*t,int size){\nint i;\nluaM_reallocvector(L,t->array,t->sizearray,size,TValue);\nfor(i=t->sizearray;i<size;i++)\nsetnilvalue(&t->array[i]);\nt->sizearray=size;\n}\nstatic void setnodevector(lua_State*L,Table*t,int size){\nint lsize;\nif(size==0){\nt->node=cast(Node*,(&dummynode_));\nlsize=0;\n}\nelse{\nint i;\nlsize=ceillog2(size);\nif(lsize>(32-2))\nluaG_runerror(L,\"table overflow\");\nsize=twoto(lsize);\nt->node=luaM_newvector(L,size,Node);\nfor(i=0;i<size;i++){\nNode*n=gnode(t,i);\ngnext(n)=NULL;\nsetnilvalue(gkey(n));\nsetnilvalue(gval(n));\n}\n}\nt->lsizenode=cast_byte(lsize);\nt->lastfree=gnode(t,size);\n}\nstatic void resize(lua_State*L,Table*t,int nasize,int nhsize){\nint i;\nint oldasize=t->sizearray;\nint oldhsize=t->lsizenode;\nNode*nold=t->node;\nif(nasize>oldasize)\nsetarrayvector(L,t,nasize);\nsetnodevector(L,t,nhsize);\nif(nasize<oldasize){\nt->sizearray=nasize;\nfor(i=nasize;i<oldasize;i++){\nif(!ttisnil(&t->array[i]))\nsetobj(L,luaH_setnum(L,t,i+1),&t->array[i]);\n}\nluaM_reallocvector(L,t->array,oldasize,nasize,TValue);\n}\nfor(i=twoto(oldhsize)-1;i>=0;i--){\nNode*old=nold+i;\nif(!ttisnil(gval(old)))\nsetobj(L,luaH_set(L,t,key2tval(old)),gval(old));\n}\nif(nold!=(&dummynode_))\nluaM_freearray(L,nold,twoto(oldhsize),Node);\n}\nstatic void luaH_resizearray(lua_State*L,Table*t,int nasize){\nint nsize=(t->node==(&dummynode_))?0:sizenode(t);\nresize(L,t,nasize,nsize);\n}\nstatic void rehash(lua_State*L,Table*t,const TValue*ek){\nint nasize,na;\nint nums[(32-2)+1];\nint i;\nint totaluse;\nfor(i=0;i<=(32-2);i++)nums[i]=0;\nnasize=numusearray(t,nums);\ntotaluse=nasize;\ntotaluse+=numusehash(t,nums,&nasize);\nnasize+=countint(ek,nums);\ntotaluse++;\nna=computesizes(nums,&nasize);\nresize(L,t,nasize,totaluse-na);\n}\nstatic Table*luaH_new(lua_State*L,int narray,int nhash){\nTable*t=luaM_new(L,Table);\nluaC_link(L,obj2gco(t),5);\nt->metatable=NULL;\nt->flags=cast_byte(~0);\nt->array=NULL;\nt->sizearray=0;\nt->lsizenode=0;\nt->node=cast(Node*,(&dummynode_));\nsetarrayvector(L,t,narray);\nsetnodevector(L,t,nhash);\nreturn t;\n}\nstatic void luaH_free(lua_State*L,Table*t){\nif(t->node!=(&dummynode_))\nluaM_freearray(L,t->node,sizenode(t),Node);\nluaM_freearray(L,t->array,t->sizearray,TValue);\nluaM_free(L,t);\n}\nstatic Node*getfreepos(Table*t){\nwhile(t->lastfree-->t->node){\nif(ttisnil(gkey(t->lastfree)))\nreturn t->lastfree;\n}\nreturn NULL;\n}\nstatic TValue*newkey(lua_State*L,Table*t,const TValue*key){\nNode*mp=mainposition(t,key);\nif(!ttisnil(gval(mp))||mp==(&dummynode_)){\nNode*othern;\nNode*n=getfreepos(t);\nif(n==NULL){\nrehash(L,t,key);\nreturn luaH_set(L,t,key);\n}\nothern=mainposition(t,key2tval(mp));\nif(othern!=mp){\nwhile(gnext(othern)!=mp)othern=gnext(othern);\ngnext(othern)=n;\n*n=*mp;\ngnext(mp)=NULL;\nsetnilvalue(gval(mp));\n}\nelse{\ngnext(n)=gnext(mp);\ngnext(mp)=n;\nmp=n;\n}\n}\ngkey(mp)->value=key->value;gkey(mp)->tt=key->tt;\nluaC_barriert(L,t,key);\nreturn gval(mp);\n}\nstatic const TValue*luaH_getnum(Table*t,int key){\nif(cast(unsigned int,key)-1<cast(unsigned int,t->sizearray))\nreturn&t->array[key-1];\nelse{\nlua_Number nk=cast_num(key);\nNode*n=hashnum(t,nk);\ndo{\nif(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk))\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\n}\nstatic const TValue*luaH_getstr(Table*t,TString*key){\nNode*n=hashstr(t,key);\ndo{\nif(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key)\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\nstatic const TValue*luaH_get(Table*t,const TValue*key){\nswitch(ttype(key)){\ncase 0:return(&luaO_nilobject_);\ncase 4:return luaH_getstr(t,rawtsvalue(key));\ncase 3:{\nint k;\nlua_Number n=nvalue(key);\nlua_number2int(k,n);\nif(luai_numeq(cast_num(k),nvalue(key)))\nreturn luaH_getnum(t,k);\n}\ndefault:{\nNode*n=mainposition(t,key);\ndo{\nif(luaO_rawequalObj(key2tval(n),key))\nreturn gval(n);\nelse n=gnext(n);\n}while(n);\nreturn(&luaO_nilobject_);\n}\n}\n}\nstatic TValue*luaH_set(lua_State*L,Table*t,const TValue*key){\nconst TValue*p=luaH_get(t,key);\nt->flags=0;\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nif(ttisnil(key))luaG_runerror(L,\"table index is nil\");\nelse if(ttisnumber(key)&&luai_numisnan(nvalue(key)))\nluaG_runerror(L,\"table index is NaN\");\nreturn newkey(L,t,key);\n}\n}\nstatic TValue*luaH_setnum(lua_State*L,Table*t,int key){\nconst TValue*p=luaH_getnum(t,key);\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nTValue k;\nsetnvalue(&k,cast_num(key));\nreturn newkey(L,t,&k);\n}\n}\nstatic TValue*luaH_setstr(lua_State*L,Table*t,TString*key){\nconst TValue*p=luaH_getstr(t,key);\nif(p!=(&luaO_nilobject_))\nreturn cast(TValue*,p);\nelse{\nTValue k;\nsetsvalue(L,&k,key);\nreturn newkey(L,t,&k);\n}\n}\nstatic int unbound_search(Table*t,unsigned int j){\nunsigned int i=j;\nj++;\nwhile(!ttisnil(luaH_getnum(t,j))){\ni=j;\nj*=2;\nif(j>cast(unsigned int,(INT_MAX-2))){\ni=1;\nwhile(!ttisnil(luaH_getnum(t,i)))i++;\nreturn i-1;\n}\n}\nwhile(j-i>1){\nunsigned int m=(i+j)/2;\nif(ttisnil(luaH_getnum(t,m)))j=m;\nelse i=m;\n}\nreturn i;\n}\nstatic int luaH_getn(Table*t){\nunsigned int j=t->sizearray;\nif(j>0&&ttisnil(&t->array[j-1])){\nunsigned int i=0;\nwhile(j-i>1){\nunsigned int m=(i+j)/2;\nif(ttisnil(&t->array[m-1]))j=m;\nelse i=m;\n}\nreturn i;\n}\nelse if(t->node==(&dummynode_))\nreturn j;\nelse return unbound_search(t,j);\n}\n#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g)))\n#define white2gray(x)reset2bits((x)->gch.marked,0,1)\n#define black2gray(x)resetbit((x)->gch.marked,2)\n#define stringmark(s)reset2bits((s)->tsv.marked,0,1)\n#define isfinalized(u)testbit((u)->marked,3)\n#define markfinalized(u)l_setbit((u)->marked,3)\n#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));}\n#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));}\n#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause)\nstatic void removeentry(Node*n){\nif(iscollectable(gkey(n)))\nsetttype(gkey(n),(8+3));\n}\nstatic void reallymarkobject(global_State*g,GCObject*o){\nwhite2gray(o);\nswitch(o->gch.tt){\ncase 4:{\nreturn;\n}\ncase 7:{\nTable*mt=gco2u(o)->metatable;\ngray2black(o);\nif(mt)markobject(g,mt);\nmarkobject(g,gco2u(o)->env);\nreturn;\n}\ncase(8+2):{\nUpVal*uv=gco2uv(o);\nmarkvalue(g,uv->v);\nif(uv->v==&uv->u.value)\ngray2black(o);\nreturn;\n}\ncase 6:{\ngco2cl(o)->c.gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase 5:{\ngco2h(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase 8:{\ngco2th(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ncase(8+1):{\ngco2p(o)->gclist=g->gray;\ng->gray=o;\nbreak;\n}\ndefault:;\n}\n}\nstatic void marktmu(global_State*g){\nGCObject*u=g->tmudata;\nif(u){\ndo{\nu=u->gch.next;\nmakewhite(g,u);\nreallymarkobject(g,u);\n}while(u!=g->tmudata);\n}\n}\nstatic size_t luaC_separateudata(lua_State*L,int all){\nglobal_State*g=G(L);\nsize_t deadmem=0;\nGCObject**p=&g->mainthread->next;\nGCObject*curr;\nwhile((curr=*p)!=NULL){\nif(!(iswhite(curr)||all)||isfinalized(gco2u(curr)))\np=&curr->gch.next;\nelse if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){\nmarkfinalized(gco2u(curr));\np=&curr->gch.next;\n}\nelse{\ndeadmem+=sizeudata(gco2u(curr));\nmarkfinalized(gco2u(curr));\n*p=curr->gch.next;\nif(g->tmudata==NULL)\ng->tmudata=curr->gch.next=curr;\nelse{\ncurr->gch.next=g->tmudata->gch.next;\ng->tmudata->gch.next=curr;\ng->tmudata=curr;\n}\n}\n}\nreturn deadmem;\n}\nstatic int traversetable(global_State*g,Table*h){\nint i;\nint weakkey=0;\nint weakvalue=0;\nconst TValue*mode;\nif(h->metatable)\nmarkobject(g,h->metatable);\nmode=gfasttm(g,h->metatable,TM_MODE);\nif(mode&&ttisstring(mode)){\nweakkey=(strchr(svalue(mode),'k')!=NULL);\nweakvalue=(strchr(svalue(mode),'v')!=NULL);\nif(weakkey||weakvalue){\nh->marked&=~(bitmask(3)|bitmask(4));\nh->marked|=cast_byte((weakkey<<3)|\n(weakvalue<<4));\nh->gclist=g->weak;\ng->weak=obj2gco(h);\n}\n}\nif(weakkey&&weakvalue)return 1;\nif(!weakvalue){\ni=h->sizearray;\nwhile(i--)\nmarkvalue(g,&h->array[i]);\n}\ni=sizenode(h);\nwhile(i--){\nNode*n=gnode(h,i);\nif(ttisnil(gval(n)))\nremoveentry(n);\nelse{\nif(!weakkey)markvalue(g,gkey(n));\nif(!weakvalue)markvalue(g,gval(n));\n}\n}\nreturn weakkey||weakvalue;\n}\nstatic void traverseproto(global_State*g,Proto*f){\nint i;\nif(f->source)stringmark(f->source);\nfor(i=0;i<f->sizek;i++)\nmarkvalue(g,&f->k[i]);\nfor(i=0;i<f->sizeupvalues;i++){\nif(f->upvalues[i])\nstringmark(f->upvalues[i]);\n}\nfor(i=0;i<f->sizep;i++){\nif(f->p[i])\nmarkobject(g,f->p[i]);\n}\nfor(i=0;i<f->sizelocvars;i++){\nif(f->locvars[i].varname)\nstringmark(f->locvars[i].varname);\n}\n}\nstatic void traverseclosure(global_State*g,Closure*cl){\nmarkobject(g,cl->c.env);\nif(cl->c.isC){\nint i;\nfor(i=0;i<cl->c.nupvalues;i++)\nmarkvalue(g,&cl->c.upvalue[i]);\n}\nelse{\nint i;\nmarkobject(g,cl->l.p);\nfor(i=0;i<cl->l.nupvalues;i++)\nmarkobject(g,cl->l.upvals[i]);\n}\n}\nstatic void checkstacksizes(lua_State*L,StkId max){\nint ci_used=cast_int(L->ci-L->base_ci);\nint s_used=cast_int(max-L->stack);\nif(L->size_ci>20000)\nreturn;\nif(4*ci_used<L->size_ci&&2*8<L->size_ci)\nluaD_reallocCI(L,L->size_ci/2);\ncondhardstacktests(luaD_reallocCI(L,ci_used+1));\nif(4*s_used<L->stacksize&&\n2*((2*20)+5)<L->stacksize)\nluaD_reallocstack(L,L->stacksize/2);\ncondhardstacktests(luaD_reallocstack(L,s_used));\n}\nstatic void traversestack(global_State*g,lua_State*l){\nStkId o,lim;\nCallInfo*ci;\nmarkvalue(g,gt(l));\nlim=l->top;\nfor(ci=l->base_ci;ci<=l->ci;ci++){\nif(lim<ci->top)lim=ci->top;\n}\nfor(o=l->stack;o<l->top;o++)\nmarkvalue(g,o);\nfor(;o<=lim;o++)\nsetnilvalue(o);\ncheckstacksizes(l,lim);\n}\nstatic l_mem propagatemark(global_State*g){\nGCObject*o=g->gray;\ngray2black(o);\nswitch(o->gch.tt){\ncase 5:{\nTable*h=gco2h(o);\ng->gray=h->gclist;\nif(traversetable(g,h))\nblack2gray(o);\nreturn sizeof(Table)+sizeof(TValue)*h->sizearray+\nsizeof(Node)*sizenode(h);\n}\ncase 6:{\nClosure*cl=gco2cl(o);\ng->gray=cl->c.gclist;\ntraverseclosure(g,cl);\nreturn(cl->c.isC)?sizeCclosure(cl->c.nupvalues):\nsizeLclosure(cl->l.nupvalues);\n}\ncase 8:{\nlua_State*th=gco2th(o);\ng->gray=th->gclist;\nth->gclist=g->grayagain;\ng->grayagain=o;\nblack2gray(o);\ntraversestack(g,th);\nreturn sizeof(lua_State)+sizeof(TValue)*th->stacksize+\nsizeof(CallInfo)*th->size_ci;\n}\ncase(8+1):{\nProto*p=gco2p(o);\ng->gray=p->gclist;\ntraverseproto(g,p);\nreturn sizeof(Proto)+sizeof(Instruction)*p->sizecode+\nsizeof(Proto*)*p->sizep+\nsizeof(TValue)*p->sizek+\nsizeof(int)*p->sizelineinfo+\nsizeof(LocVar)*p->sizelocvars+\nsizeof(TString*)*p->sizeupvalues;\n}\ndefault:return 0;\n}\n}\nstatic size_t propagateall(global_State*g){\nsize_t m=0;\nwhile(g->gray)m+=propagatemark(g);\nreturn m;\n}\nstatic int iscleared(const TValue*o,int iskey){\nif(!iscollectable(o))return 0;\nif(ttisstring(o)){\nstringmark(rawtsvalue(o));\nreturn 0;\n}\nreturn iswhite(gcvalue(o))||\n(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o))));\n}\nstatic void cleartable(GCObject*l){\nwhile(l){\nTable*h=gco2h(l);\nint i=h->sizearray;\nif(testbit(h->marked,4)){\nwhile(i--){\nTValue*o=&h->array[i];\nif(iscleared(o,0))\nsetnilvalue(o);\n}\n}\ni=sizenode(h);\nwhile(i--){\nNode*n=gnode(h,i);\nif(!ttisnil(gval(n))&&\n(iscleared(key2tval(n),1)||iscleared(gval(n),0))){\nsetnilvalue(gval(n));\nremoveentry(n);\n}\n}\nl=h->gclist;\n}\n}\nstatic void freeobj(lua_State*L,GCObject*o){\nswitch(o->gch.tt){\ncase(8+1):luaF_freeproto(L,gco2p(o));break;\ncase 6:luaF_freeclosure(L,gco2cl(o));break;\ncase(8+2):luaF_freeupval(L,gco2uv(o));break;\ncase 5:luaH_free(L,gco2h(o));break;\ncase 8:{\nluaE_freethread(L,gco2th(o));\nbreak;\n}\ncase 4:{\nG(L)->strt.nuse--;\nluaM_freemem(L,o,sizestring(gco2ts(o)));\nbreak;\n}\ncase 7:{\nluaM_freemem(L,o,sizeudata(gco2u(o)));\nbreak;\n}\ndefault:;\n}\n}\n#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2))\nstatic GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){\nGCObject*curr;\nglobal_State*g=G(L);\nint deadmask=otherwhite(g);\nwhile((curr=*p)!=NULL&&count-->0){\nif(curr->gch.tt==8)\nsweepwholelist(L,&gco2th(curr)->openupval);\nif((curr->gch.marked^bit2mask(0,1))&deadmask){\nmakewhite(g,curr);\np=&curr->gch.next;\n}\nelse{\n*p=curr->gch.next;\nif(curr==g->rootgc)\ng->rootgc=curr->gch.next;\nfreeobj(L,curr);\n}\n}\nreturn p;\n}\nstatic void checkSizes(lua_State*L){\nglobal_State*g=G(L);\nif(g->strt.nuse<cast(lu_int32,g->strt.size/4)&&\ng->strt.size>32*2)\nluaS_resize(L,g->strt.size/2);\nif(luaZ_sizebuffer(&g->buff)>32*2){\nsize_t newsize=luaZ_sizebuffer(&g->buff)/2;\nluaZ_resizebuffer(L,&g->buff,newsize);\n}\n}\nstatic void GCTM(lua_State*L){\nglobal_State*g=G(L);\nGCObject*o=g->tmudata->gch.next;\nUdata*udata=rawgco2u(o);\nconst TValue*tm;\nif(o==g->tmudata)\ng->tmudata=NULL;\nelse\ng->tmudata->gch.next=udata->uv.next;\nudata->uv.next=g->mainthread->next;\ng->mainthread->next=o;\nmakewhite(g,o);\ntm=fasttm(L,udata->uv.metatable,TM_GC);\nif(tm!=NULL){\nlu_byte oldah=L->allowhook;\nlu_mem oldt=g->GCthreshold;\nL->allowhook=0;\ng->GCthreshold=2*g->totalbytes;\nsetobj(L,L->top,tm);\nsetuvalue(L,L->top+1,udata);\nL->top+=2;\nluaD_call(L,L->top-2,0);\nL->allowhook=oldah;\ng->GCthreshold=oldt;\n}\n}\nstatic void luaC_callGCTM(lua_State*L){\nwhile(G(L)->tmudata)\nGCTM(L);\n}\nstatic void luaC_freeall(lua_State*L){\nglobal_State*g=G(L);\nint i;\ng->currentwhite=bit2mask(0,1)|bitmask(6);\nsweepwholelist(L,&g->rootgc);\nfor(i=0;i<g->strt.size;i++)\nsweepwholelist(L,&g->strt.hash[i]);\n}\nstatic void markmt(global_State*g){\nint i;\nfor(i=0;i<(8+1);i++)\nif(g->mt[i])markobject(g,g->mt[i]);\n}\nstatic void markroot(lua_State*L){\nglobal_State*g=G(L);\ng->gray=NULL;\ng->grayagain=NULL;\ng->weak=NULL;\nmarkobject(g,g->mainthread);\nmarkvalue(g,gt(g->mainthread));\nmarkvalue(g,registry(L));\nmarkmt(g);\ng->gcstate=1;\n}\nstatic void remarkupvals(global_State*g){\nUpVal*uv;\nfor(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){\nif(isgray(obj2gco(uv)))\nmarkvalue(g,uv->v);\n}\n}\nstatic void atomic(lua_State*L){\nglobal_State*g=G(L);\nsize_t udsize;\nremarkupvals(g);\npropagateall(g);\ng->gray=g->weak;\ng->weak=NULL;\nmarkobject(g,L);\nmarkmt(g);\npropagateall(g);\ng->gray=g->grayagain;\ng->grayagain=NULL;\npropagateall(g);\nudsize=luaC_separateudata(L,0);\nmarktmu(g);\nudsize+=propagateall(g);\ncleartable(g->weak);\ng->currentwhite=cast_byte(otherwhite(g));\ng->sweepstrgc=0;\ng->sweepgc=&g->rootgc;\ng->gcstate=2;\ng->estimate=g->totalbytes-udsize;\n}\nstatic l_mem singlestep(lua_State*L){\nglobal_State*g=G(L);\nswitch(g->gcstate){\ncase 0:{\nmarkroot(L);\nreturn 0;\n}\ncase 1:{\nif(g->gray)\nreturn propagatemark(g);\nelse{\natomic(L);\nreturn 0;\n}\n}\ncase 2:{\nlu_mem old=g->totalbytes;\nsweepwholelist(L,&g->strt.hash[g->sweepstrgc++]);\nif(g->sweepstrgc>=g->strt.size)\ng->gcstate=3;\ng->estimate-=old-g->totalbytes;\nreturn 10;\n}\ncase 3:{\nlu_mem old=g->totalbytes;\ng->sweepgc=sweeplist(L,g->sweepgc,40);\nif(*g->sweepgc==NULL){\ncheckSizes(L);\ng->gcstate=4;\n}\ng->estimate-=old-g->totalbytes;\nreturn 40*10;\n}\ncase 4:{\nif(g->tmudata){\nGCTM(L);\nif(g->estimate>100)\ng->estimate-=100;\nreturn 100;\n}\nelse{\ng->gcstate=0;\ng->gcdept=0;\nreturn 0;\n}\n}\ndefault:return 0;\n}\n}\nstatic void luaC_step(lua_State*L){\nglobal_State*g=G(L);\nl_mem lim=(1024u/100)*g->gcstepmul;\nif(lim==0)\nlim=(((lu_mem)(~(lu_mem)0)-2)-1)/2;\ng->gcdept+=g->totalbytes-g->GCthreshold;\ndo{\nlim-=singlestep(L);\nif(g->gcstate==0)\nbreak;\n}while(lim>0);\nif(g->gcstate!=0){\nif(g->gcdept<1024u)\ng->GCthreshold=g->totalbytes+1024u;\nelse{\ng->gcdept-=1024u;\ng->GCthreshold=g->totalbytes;\n}\n}\nelse{\nsetthreshold(g);\n}\n}\nstatic void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){\nglobal_State*g=G(L);\nif(g->gcstate==1)\nreallymarkobject(g,v);\nelse\nmakewhite(g,o);\n}\nstatic void luaC_barrierback(lua_State*L,Table*t){\nglobal_State*g=G(L);\nGCObject*o=obj2gco(t);\nblack2gray(o);\nt->gclist=g->grayagain;\ng->grayagain=o;\n}\nstatic void luaC_link(lua_State*L,GCObject*o,lu_byte tt){\nglobal_State*g=G(L);\no->gch.next=g->rootgc;\ng->rootgc=o;\no->gch.marked=luaC_white(g);\no->gch.tt=tt;\n}\nstatic void luaC_linkupval(lua_State*L,UpVal*uv){\nglobal_State*g=G(L);\nGCObject*o=obj2gco(uv);\no->gch.next=g->rootgc;\ng->rootgc=o;\nif(isgray(o)){\nif(g->gcstate==1){\ngray2black(o);\nluaC_barrier(L,uv,uv->v);\n}\nelse{\nmakewhite(g,o);\n}\n}\n}\ntypedef union{\nlua_Number r;\nTString*ts;\n}SemInfo;\ntypedef struct Token{\nint token;\nSemInfo seminfo;\n}Token;\ntypedef struct LexState{\nint current;\nint linenumber;\nint lastline;\nToken t;\nToken lookahead;\nstruct FuncState*fs;\nstruct lua_State*L;\nZIO*z;\nMbuffer*buff;\nTString*source;\nchar decpoint;\n}LexState;\nstatic void luaX_init(lua_State*L);\nstatic void luaX_lexerror(LexState*ls,const char*msg,int token);\n#define state_size(x)(sizeof(x)+0)\n#define fromstate(l)(cast(lu_byte*,(l))-0)\n#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0))\ntypedef struct LG{\nlua_State l;\nglobal_State g;\n}LG;\nstatic void stack_init(lua_State*L1,lua_State*L){\nL1->base_ci=luaM_newvector(L,8,CallInfo);\nL1->ci=L1->base_ci;\nL1->size_ci=8;\nL1->end_ci=L1->base_ci+L1->size_ci-1;\nL1->stack=luaM_newvector(L,(2*20)+5,TValue);\nL1->stacksize=(2*20)+5;\nL1->top=L1->stack;\nL1->stack_last=L1->stack+(L1->stacksize-5)-1;\nL1->ci->func=L1->top;\nsetnilvalue(L1->top++);\nL1->base=L1->ci->base=L1->top;\nL1->ci->top=L1->top+20;\n}\nstatic void freestack(lua_State*L,lua_State*L1){\nluaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo);\nluaM_freearray(L,L1->stack,L1->stacksize,TValue);\n}\nstatic void f_luaopen(lua_State*L,void*ud){\nglobal_State*g=G(L);\nUNUSED(ud);\nstack_init(L,L);\nsethvalue(L,gt(L),luaH_new(L,0,2));\nsethvalue(L,registry(L),luaH_new(L,0,2));\nluaS_resize(L,32);\nluaT_init(L);\nluaX_init(L);\nluaS_fix(luaS_newliteral(L,\"not enough memory\"));\ng->GCthreshold=4*g->totalbytes;\n}\nstatic void preinit_state(lua_State*L,global_State*g){\nG(L)=g;\nL->stack=NULL;\nL->stacksize=0;\nL->errorJmp=NULL;\nL->hook=NULL;\nL->hookmask=0;\nL->basehookcount=0;\nL->allowhook=1;\nresethookcount(L);\nL->openupval=NULL;\nL->size_ci=0;\nL->nCcalls=L->baseCcalls=0;\nL->status=0;\nL->base_ci=L->ci=NULL;\nL->savedpc=NULL;\nL->errfunc=0;\nsetnilvalue(gt(L));\n}\nstatic void close_state(lua_State*L){\nglobal_State*g=G(L);\nluaF_close(L,L->stack);\nluaC_freeall(L);\nluaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*);\nluaZ_freebuffer(L,&g->buff);\nfreestack(L,L);\n(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0);\n}\nstatic void luaE_freethread(lua_State*L,lua_State*L1){\nluaF_close(L1,L1->stack);\nfreestack(L,L1);\nluaM_freemem(L,fromstate(L1),state_size(lua_State));\n}\nstatic lua_State*lua_newstate(lua_Alloc f,void*ud){\nint i;\nlua_State*L;\nglobal_State*g;\nvoid*l=(*f)(ud,NULL,0,state_size(LG));\nif(l==NULL)return NULL;\nL=tostate(l);\ng=&((LG*)L)->g;\nL->next=NULL;\nL->tt=8;\ng->currentwhite=bit2mask(0,5);\nL->marked=luaC_white(g);\nset2bits(L->marked,5,6);\npreinit_state(L,g);\ng->frealloc=f;\ng->ud=ud;\ng->mainthread=L;\ng->uvhead.u.l.prev=&g->uvhead;\ng->uvhead.u.l.next=&g->uvhead;\ng->GCthreshold=0;\ng->strt.size=0;\ng->strt.nuse=0;\ng->strt.hash=NULL;\nsetnilvalue(registry(L));\nluaZ_initbuffer(L,&g->buff);\ng->panic=NULL;\ng->gcstate=0;\ng->rootgc=obj2gco(L);\ng->sweepstrgc=0;\ng->sweepgc=&g->rootgc;\ng->gray=NULL;\ng->grayagain=NULL;\ng->weak=NULL;\ng->tmudata=NULL;\ng->totalbytes=sizeof(LG);\ng->gcpause=200;\ng->gcstepmul=200;\ng->gcdept=0;\nfor(i=0;i<(8+1);i++)g->mt[i]=NULL;\nif(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){\nclose_state(L);\nL=NULL;\n}\nelse\n{}\nreturn L;\n}\nstatic void callallgcTM(lua_State*L,void*ud){\nUNUSED(ud);\nluaC_callGCTM(L);\n}\nstatic void lua_close(lua_State*L){\nL=G(L)->mainthread;\nluaF_close(L,L->stack);\nluaC_separateudata(L,1);\nL->errfunc=0;\ndo{\nL->ci=L->base_ci;\nL->base=L->top=L->ci->base;\nL->nCcalls=L->baseCcalls=0;\n}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0);\nclose_state(L);\n}\n#define getcode(fs,e)((fs)->f->code[(e)->u.s.info])\n#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1))\n#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1))\nstatic int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx);\nstatic int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C);\nstatic void luaK_setreturns(FuncState*fs,expdesc*e,int nresults);\nstatic void luaK_patchtohere(FuncState*fs,int list);\nstatic void luaK_concat(FuncState*fs,int*l1,int l2);\nstatic int currentpc(lua_State*L,CallInfo*ci){\nif(!isLua(ci))return-1;\nif(ci==L->ci)\nci->savedpc=L->savedpc;\nreturn pcRel(ci->savedpc,ci_func(ci)->l.p);\n}\nstatic int currentline(lua_State*L,CallInfo*ci){\nint pc=currentpc(L,ci);\nif(pc<0)\nreturn-1;\nelse\nreturn getline_(ci_func(ci)->l.p,pc);\n}\nstatic int lua_getstack(lua_State*L,int level,lua_Debug*ar){\nint status;\nCallInfo*ci;\nfor(ci=L->ci;level>0&&ci>L->base_ci;ci--){\nlevel--;\nif(f_isLua(ci))\nlevel-=ci->tailcalls;\n}\nif(level==0&&ci>L->base_ci){\nstatus=1;\nar->i_ci=cast_int(ci-L->base_ci);\n}\nelse if(level<0){\nstatus=1;\nar->i_ci=0;\n}\nelse status=0;\nreturn status;\n}\nstatic Proto*getluaproto(CallInfo*ci){\nreturn(isLua(ci)?ci_func(ci)->l.p:NULL);\n}\nstatic void funcinfo(lua_Debug*ar,Closure*cl){\nif(cl->c.isC){\nar->source=\"=[C]\";\nar->linedefined=-1;\nar->lastlinedefined=-1;\nar->what=\"C\";\n}\nelse{\nar->source=getstr(cl->l.p->source);\nar->linedefined=cl->l.p->linedefined;\nar->lastlinedefined=cl->l.p->lastlinedefined;\nar->what=(ar->linedefined==0)?\"main\":\"Lua\";\n}\nluaO_chunkid(ar->short_src,ar->source,60);\n}\nstatic void info_tailcall(lua_Debug*ar){\nar->name=ar->namewhat=\"\";\nar->what=\"tail\";\nar->lastlinedefined=ar->linedefined=ar->currentline=-1;\nar->source=\"=(tail call)\";\nluaO_chunkid(ar->short_src,ar->source,60);\nar->nups=0;\n}\nstatic void collectvalidlines(lua_State*L,Closure*f){\nif(f==NULL||f->c.isC){\nsetnilvalue(L->top);\n}\nelse{\nTable*t=luaH_new(L,0,0);\nint*lineinfo=f->l.p->lineinfo;\nint i;\nfor(i=0;i<f->l.p->sizelineinfo;i++)\nsetbvalue(luaH_setnum(L,t,lineinfo[i]),1);\nsethvalue(L,L->top,t);\n}\nincr_top(L);\n}\nstatic int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar,\nClosure*f,CallInfo*ci){\nint status=1;\nif(f==NULL){\ninfo_tailcall(ar);\nreturn status;\n}\nfor(;*what;what++){\nswitch(*what){\ncase'S':{\nfuncinfo(ar,f);\nbreak;\n}\ncase'l':{\nar->currentline=(ci)?currentline(L,ci):-1;\nbreak;\n}\ncase'u':{\nar->nups=f->c.nupvalues;\nbreak;\n}\ncase'n':{\nar->namewhat=(ci)?NULL:NULL;\nif(ar->namewhat==NULL){\nar->namewhat=\"\";\nar->name=NULL;\n}\nbreak;\n}\ncase'L':\ncase'f':\nbreak;\ndefault:status=0;\n}\n}\nreturn status;\n}\nstatic int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){\nint status;\nClosure*f=NULL;\nCallInfo*ci=NULL;\nif(*what=='>'){\nStkId func=L->top-1;\nluai_apicheck(L,ttisfunction(func));\nwhat++;\nf=clvalue(func);\nL->top--;\n}\nelse if(ar->i_ci!=0){\nci=L->base_ci+ar->i_ci;\nf=clvalue(ci->func);\n}\nstatus=auxgetinfo(L,what,ar,f,ci);\nif(strchr(what,'f')){\nif(f==NULL)setnilvalue(L->top);\nelse setclvalue(L,L->top,f);\nincr_top(L);\n}\nif(strchr(what,'L'))\ncollectvalidlines(L,f);\nreturn status;\n}\nstatic int isinstack(CallInfo*ci,const TValue*o){\nStkId p;\nfor(p=ci->base;p<ci->top;p++)\nif(o==p)return 1;\nreturn 0;\n}\nstatic void luaG_typeerror(lua_State*L,const TValue*o,const char*op){\nconst char*name=NULL;\nconst char*t=luaT_typenames[ttype(o)];\nconst char*kind=(isinstack(L->ci,o))?\nNULL:\nNULL;\nif(kind)\nluaG_runerror(L,\"attempt to %s %s \"LUA_QL(\"%s\")\" (a %s value)\",\nop,kind,name,t);\nelse\nluaG_runerror(L,\"attempt to %s a %s value\",op,t);\n}\nstatic void luaG_concaterror(lua_State*L,StkId p1,StkId p2){\nif(ttisstring(p1)||ttisnumber(p1))p1=p2;\nluaG_typeerror(L,p1,\"concatenate\");\n}\nstatic void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){\nTValue temp;\nif(luaV_tonumber(p1,&temp)==NULL)\np2=p1;\nluaG_typeerror(L,p2,\"perform arithmetic on\");\n}\nstatic int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){\nconst char*t1=luaT_typenames[ttype(p1)];\nconst char*t2=luaT_typenames[ttype(p2)];\nif(t1[2]==t2[2])\nluaG_runerror(L,\"attempt to compare two %s values\",t1);\nelse\nluaG_runerror(L,\"attempt to compare %s with %s\",t1,t2);\nreturn 0;\n}\nstatic void addinfo(lua_State*L,const char*msg){\nCallInfo*ci=L->ci;\nif(isLua(ci)){\nchar buff[60];\nint line=currentline(L,ci);\nluaO_chunkid(buff,getstr(getluaproto(ci)->source),60);\nluaO_pushfstring(L,\"%s:%d: %s\",buff,line,msg);\n}\n}\nstatic void luaG_errormsg(lua_State*L){\nif(L->errfunc!=0){\nStkId errfunc=restorestack(L,L->errfunc);\nif(!ttisfunction(errfunc))luaD_throw(L,5);\nsetobj(L,L->top,L->top-1);\nsetobj(L,L->top-1,errfunc);\nincr_top(L);\nluaD_call(L,L->top-2,1);\n}\nluaD_throw(L,2);\n}\nstatic void luaG_runerror(lua_State*L,const char*fmt,...){\nva_list argp;\nva_start(argp,fmt);\naddinfo(L,luaO_pushvfstring(L,fmt,argp));\nva_end(argp);\nluaG_errormsg(L);\n}\nstatic int luaZ_fill(ZIO*z){\nsize_t size;\nlua_State*L=z->L;\nconst char*buff;\nbuff=z->reader(L,z->data,&size);\nif(buff==NULL||size==0)return(-1);\nz->n=size-1;\nz->p=buff;\nreturn char2int(*(z->p++));\n}\nstatic void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){\nz->L=L;\nz->reader=reader;\nz->data=data;\nz->n=0;\nz->p=NULL;\n}\nstatic char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){\nif(n>buff->buffsize){\nif(n<32)n=32;\nluaZ_resizebuffer(L,buff,n);\n}\nreturn buff->buffer;\n}\n#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m))\nstatic const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={\nopmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgK,OpArgN,iABx)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgU,OpArgN,iABC)\n,opmode(0,1,OpArgK,OpArgN,iABx)\n,opmode(0,1,OpArgR,OpArgK,iABC)\n,opmode(0,0,OpArgK,OpArgN,iABx)\n,opmode(0,0,OpArgU,OpArgN,iABC)\n,opmode(0,0,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgR,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgK,OpArgK,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgR,iABC)\n,opmode(0,0,OpArgR,OpArgN,iAsBx)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,0,OpArgK,OpArgK,iABC)\n,opmode(1,1,OpArgR,OpArgU,iABC)\n,opmode(1,1,OpArgR,OpArgU,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,1,OpArgU,OpArgU,iABC)\n,opmode(0,0,OpArgU,OpArgN,iABC)\n,opmode(0,1,OpArgR,OpArgN,iAsBx)\n,opmode(0,1,OpArgR,OpArgN,iAsBx)\n,opmode(1,0,OpArgN,OpArgU,iABC)\n,opmode(0,0,OpArgU,OpArgU,iABC)\n,opmode(0,0,OpArgN,OpArgN,iABC)\n,opmode(0,1,OpArgU,OpArgN,iABx)\n,opmode(0,1,OpArgU,OpArgN,iABC)\n};\n#define next(ls)(ls->current=zgetc(ls->z))\n#define currIsNewline(ls)(ls->current=='\\n'||ls->current=='\\r')\nstatic const char*const luaX_tokens[]={\n\"and\",\"break\",\"do\",\"else\",\"elseif\",\n\"end\",\"false\",\"for\",\"function\",\"if\",\n\"in\",\"local\",\"nil\",\"not\",\"or\",\"repeat\",\n\"return\",\"then\",\"true\",\"until\",\"while\",\n\"..\",\"...\",\"==\",\">=\",\"<=\",\"~=\",\n\"<number>\",\"<name>\",\"<string>\",\"<eof>\",\nNULL\n};\n#define save_and_next(ls)(save(ls,ls->current),next(ls))\nstatic void save(LexState*ls,int c){\nMbuffer*b=ls->buff;\nif(b->n+1>b->buffsize){\nsize_t newsize;\nif(b->buffsize>=((size_t)(~(size_t)0)-2)/2)\nluaX_lexerror(ls,\"lexical element too long\",0);\nnewsize=b->buffsize*2;\nluaZ_resizebuffer(ls->L,b,newsize);\n}\nb->buffer[b->n++]=cast(char,c);\n}\nstatic void luaX_init(lua_State*L){\nint i;\nfor(i=0;i<(cast(int,TK_WHILE-257+1));i++){\nTString*ts=luaS_new(L,luaX_tokens[i]);\nluaS_fix(ts);\nts->tsv.reserved=cast_byte(i+1);\n}\n}\nstatic const char*luaX_token2str(LexState*ls,int token){\nif(token<257){\nreturn(iscntrl(token))?luaO_pushfstring(ls->L,\"char(%d)\",token):\nluaO_pushfstring(ls->L,\"%c\",token);\n}\nelse\nreturn luaX_tokens[token-257];\n}\nstatic const char*txtToken(LexState*ls,int token){\nswitch(token){\ncase TK_NAME:\ncase TK_STRING:\ncase TK_NUMBER:\nsave(ls,'\\0');\nreturn luaZ_buffer(ls->buff);\ndefault:\nreturn luaX_token2str(ls,token);\n}\n}\nstatic void luaX_lexerror(LexState*ls,const char*msg,int token){\nchar buff[80];\nluaO_chunkid(buff,getstr(ls->source),80);\nmsg=luaO_pushfstring(ls->L,\"%s:%d: %s\",buff,ls->linenumber,msg);\nif(token)\nluaO_pushfstring(ls->L,\"%s near \"LUA_QL(\"%s\"),msg,txtToken(ls,token));\nluaD_throw(ls->L,3);\n}\nstatic void luaX_syntaxerror(LexState*ls,const char*msg){\nluaX_lexerror(ls,msg,ls->t.token);\n}\nstatic TString*luaX_newstring(LexState*ls,const char*str,size_t l){\nlua_State*L=ls->L;\nTString*ts=luaS_newlstr(L,str,l);\nTValue*o=luaH_setstr(L,ls->fs->h,ts);\nif(ttisnil(o)){\nsetbvalue(o,1);\nluaC_checkGC(L);\n}\nreturn ts;\n}\nstatic void inclinenumber(LexState*ls){\nint old=ls->current;\nnext(ls);\nif(currIsNewline(ls)&&ls->current!=old)\nnext(ls);\nif(++ls->linenumber>=(INT_MAX-2))\nluaX_syntaxerror(ls,\"chunk has too many lines\");\n}\nstatic void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){\nls->decpoint='.';\nls->L=L;\nls->lookahead.token=TK_EOS;\nls->z=z;\nls->fs=NULL;\nls->linenumber=1;\nls->lastline=1;\nls->source=source;\nluaZ_resizebuffer(ls->L,ls->buff,32);\nnext(ls);\n}\nstatic int check_next(LexState*ls,const char*set){\nif(!strchr(set,ls->current))\nreturn 0;\nsave_and_next(ls);\nreturn 1;\n}\nstatic void buffreplace(LexState*ls,char from,char to){\nsize_t n=luaZ_bufflen(ls->buff);\nchar*p=luaZ_buffer(ls->buff);\nwhile(n--)\nif(p[n]==from)p[n]=to;\n}\nstatic void read_numeral(LexState*ls,SemInfo*seminfo){\ndo{\nsave_and_next(ls);\n}while(isdigit(ls->current)||ls->current=='.');\nif(check_next(ls,\"Ee\"))\ncheck_next(ls,\"+-\");\nwhile(isalnum(ls->current)||ls->current=='_')\nsave_and_next(ls);\nsave(ls,'\\0');\nbuffreplace(ls,'.',ls->decpoint);\nif(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r))\nluaX_lexerror(ls,\"malformed number\",TK_NUMBER);\n}\nstatic int skip_sep(LexState*ls){\nint count=0;\nint s=ls->current;\nsave_and_next(ls);\nwhile(ls->current=='='){\nsave_and_next(ls);\ncount++;\n}\nreturn(ls->current==s)?count:(-count)-1;\n}\nstatic void read_long_string(LexState*ls,SemInfo*seminfo,int sep){\nint cont=0;\n(void)(cont);\nsave_and_next(ls);\nif(currIsNewline(ls))\ninclinenumber(ls);\nfor(;;){\nswitch(ls->current){\ncase(-1):\nluaX_lexerror(ls,(seminfo)?\"unfinished long string\":\n\"unfinished long comment\",TK_EOS);\nbreak;\ncase']':{\nif(skip_sep(ls)==sep){\nsave_and_next(ls);\ngoto endloop;\n}\nbreak;\n}\ncase'\\n':\ncase'\\r':{\nsave(ls,'\\n');\ninclinenumber(ls);\nif(!seminfo)luaZ_resetbuffer(ls->buff);\nbreak;\n}\ndefault:{\nif(seminfo)save_and_next(ls);\nelse next(ls);\n}\n}\n}endloop:\nif(seminfo)\nseminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep),\nluaZ_bufflen(ls->buff)-2*(2+sep));\n}\nstatic void read_string(LexState*ls,int del,SemInfo*seminfo){\nsave_and_next(ls);\nwhile(ls->current!=del){\nswitch(ls->current){\ncase(-1):\nluaX_lexerror(ls,\"unfinished string\",TK_EOS);\ncontinue;\ncase'\\n':\ncase'\\r':\nluaX_lexerror(ls,\"unfinished string\",TK_STRING);\ncontinue;\ncase'\\\\':{\nint c;\nnext(ls);\nswitch(ls->current){\ncase'a':c='\\a';break;\ncase'b':c='\\b';break;\ncase'f':c='\\f';break;\ncase'n':c='\\n';break;\ncase'r':c='\\r';break;\ncase't':c='\\t';break;\ncase'v':c='\\v';break;\ncase'\\n':\ncase'\\r':save(ls,'\\n');inclinenumber(ls);continue;\ncase(-1):continue;\ndefault:{\nif(!isdigit(ls->current))\nsave_and_next(ls);\nelse{\nint i=0;\nc=0;\ndo{\nc=10*c+(ls->current-'0');\nnext(ls);\n}while(++i<3&&isdigit(ls->current));\nif(c>UCHAR_MAX)\nluaX_lexerror(ls,\"escape sequence too large\",TK_STRING);\nsave(ls,c);\n}\ncontinue;\n}\n}\nsave(ls,c);\nnext(ls);\ncontinue;\n}\ndefault:\nsave_and_next(ls);\n}\n}\nsave_and_next(ls);\nseminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1,\nluaZ_bufflen(ls->buff)-2);\n}\nstatic int llex(LexState*ls,SemInfo*seminfo){\nluaZ_resetbuffer(ls->buff);\nfor(;;){\nswitch(ls->current){\ncase'\\n':\ncase'\\r':{\ninclinenumber(ls);\ncontinue;\n}\ncase'-':{\nnext(ls);\nif(ls->current!='-')return'-';\nnext(ls);\nif(ls->current=='['){\nint sep=skip_sep(ls);\nluaZ_resetbuffer(ls->buff);\nif(sep>=0){\nread_long_string(ls,NULL,sep);\nluaZ_resetbuffer(ls->buff);\ncontinue;\n}\n}\nwhile(!currIsNewline(ls)&&ls->current!=(-1))\nnext(ls);\ncontinue;\n}\ncase'[':{\nint sep=skip_sep(ls);\nif(sep>=0){\nread_long_string(ls,seminfo,sep);\nreturn TK_STRING;\n}\nelse if(sep==-1)return'[';\nelse luaX_lexerror(ls,\"invalid long string delimiter\",TK_STRING);\n}\ncase'=':{\nnext(ls);\nif(ls->current!='=')return'=';\nelse{next(ls);return TK_EQ;}\n}\ncase'<':{\nnext(ls);\nif(ls->current!='=')return'<';\nelse{next(ls);return TK_LE;}\n}\ncase'>':{\nnext(ls);\nif(ls->current!='=')return'>';\nelse{next(ls);return TK_GE;}\n}\ncase'~':{\nnext(ls);\nif(ls->current!='=')return'~';\nelse{next(ls);return TK_NE;}\n}\ncase'\"':\ncase'\\'':{\nread_string(ls,ls->current,seminfo);\nreturn TK_STRING;\n}\ncase'.':{\nsave_and_next(ls);\nif(check_next(ls,\".\")){\nif(check_next(ls,\".\"))\nreturn TK_DOTS;\nelse return TK_CONCAT;\n}\nelse if(!isdigit(ls->current))return'.';\nelse{\nread_numeral(ls,seminfo);\nreturn TK_NUMBER;\n}\n}\ncase(-1):{\nreturn TK_EOS;\n}\ndefault:{\nif(isspace(ls->current)){\nnext(ls);\ncontinue;\n}\nelse if(isdigit(ls->current)){\nread_numeral(ls,seminfo);\nreturn TK_NUMBER;\n}\nelse if(isalpha(ls->current)||ls->current=='_'){\nTString*ts;\ndo{\nsave_and_next(ls);\n}while(isalnum(ls->current)||ls->current=='_');\nts=luaX_newstring(ls,luaZ_buffer(ls->buff),\nluaZ_bufflen(ls->buff));\nif(ts->tsv.reserved>0)\nreturn ts->tsv.reserved-1+257;\nelse{\nseminfo->ts=ts;\nreturn TK_NAME;\n}\n}\nelse{\nint c=ls->current;\nnext(ls);\nreturn c;\n}\n}\n}\n}\n}\nstatic void luaX_next(LexState*ls){\nls->lastline=ls->linenumber;\nif(ls->lookahead.token!=TK_EOS){\nls->t=ls->lookahead;\nls->lookahead.token=TK_EOS;\n}\nelse\nls->t.token=llex(ls,&ls->t.seminfo);\n}\nstatic void luaX_lookahead(LexState*ls){\nls->lookahead.token=llex(ls,&ls->lookahead.seminfo);\n}\n#define hasjumps(e)((e)->t!=(e)->f)\nstatic int isnumeral(expdesc*e){\nreturn(e->k==VKNUM&&e->t==(-1)&&e->f==(-1));\n}\nstatic void luaK_nil(FuncState*fs,int from,int n){\nInstruction*previous;\nif(fs->pc>fs->lasttarget){\nif(fs->pc==0){\nif(from>=fs->nactvar)\nreturn;\n}\nelse{\nprevious=&fs->f->code[fs->pc-1];\nif(GET_OPCODE(*previous)==OP_LOADNIL){\nint pfrom=GETARG_A(*previous);\nint pto=GETARG_B(*previous);\nif(pfrom<=from&&from<=pto+1){\nif(from+n-1>pto)\nSETARG_B(*previous,from+n-1);\nreturn;\n}\n}\n}\n}\nluaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0);\n}\nstatic int luaK_jump(FuncState*fs){\nint jpc=fs->jpc;\nint j;\nfs->jpc=(-1);\nj=luaK_codeAsBx(fs,OP_JMP,0,(-1));\nluaK_concat(fs,&j,jpc);\nreturn j;\n}\nstatic void luaK_ret(FuncState*fs,int first,int nret){\nluaK_codeABC(fs,OP_RETURN,first,nret+1,0);\n}\nstatic int condjump(FuncState*fs,OpCode op,int A,int B,int C){\nluaK_codeABC(fs,op,A,B,C);\nreturn luaK_jump(fs);\n}\nstatic void fixjump(FuncState*fs,int pc,int dest){\nInstruction*jmp=&fs->f->code[pc];\nint offset=dest-(pc+1);\nif(abs(offset)>(((1<<(9+9))-1)>>1))\nluaX_syntaxerror(fs->ls,\"control structure too long\");\nSETARG_sBx(*jmp,offset);\n}\nstatic int luaK_getlabel(FuncState*fs){\nfs->lasttarget=fs->pc;\nreturn fs->pc;\n}\nstatic int getjump(FuncState*fs,int pc){\nint offset=GETARG_sBx(fs->f->code[pc]);\nif(offset==(-1))\nreturn(-1);\nelse\nreturn(pc+1)+offset;\n}\nstatic Instruction*getjumpcontrol(FuncState*fs,int pc){\nInstruction*pi=&fs->f->code[pc];\nif(pc>=1&&testTMode(GET_OPCODE(*(pi-1))))\nreturn pi-1;\nelse\nreturn pi;\n}\nstatic int need_value(FuncState*fs,int list){\nfor(;list!=(-1);list=getjump(fs,list)){\nInstruction i=*getjumpcontrol(fs,list);\nif(GET_OPCODE(i)!=OP_TESTSET)return 1;\n}\nreturn 0;\n}\nstatic int patchtestreg(FuncState*fs,int node,int reg){\nInstruction*i=getjumpcontrol(fs,node);\nif(GET_OPCODE(*i)!=OP_TESTSET)\nreturn 0;\nif(reg!=((1<<8)-1)&&reg!=GETARG_B(*i))\nSETARG_A(*i,reg);\nelse\n*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i));\nreturn 1;\n}\nstatic void removevalues(FuncState*fs,int list){\nfor(;list!=(-1);list=getjump(fs,list))\npatchtestreg(fs,list,((1<<8)-1));\n}\nstatic void patchlistaux(FuncState*fs,int list,int vtarget,int reg,\nint dtarget){\nwhile(list!=(-1)){\nint next=getjump(fs,list);\nif(patchtestreg(fs,list,reg))\nfixjump(fs,list,vtarget);\nelse\nfixjump(fs,list,dtarget);\nlist=next;\n}\n}\nstatic void dischargejpc(FuncState*fs){\npatchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc);\nfs->jpc=(-1);\n}\nstatic void luaK_patchlist(FuncState*fs,int list,int target){\nif(target==fs->pc)\nluaK_patchtohere(fs,list);\nelse{\npatchlistaux(fs,list,target,((1<<8)-1),target);\n}\n}\nstatic void luaK_patchtohere(FuncState*fs,int list){\nluaK_getlabel(fs);\nluaK_concat(fs,&fs->jpc,list);\n}\nstatic void luaK_concat(FuncState*fs,int*l1,int l2){\nif(l2==(-1))return;\nelse if(*l1==(-1))\n*l1=l2;\nelse{\nint list=*l1;\nint next;\nwhile((next=getjump(fs,list))!=(-1))\nlist=next;\nfixjump(fs,list,l2);\n}\n}\nstatic void luaK_checkstack(FuncState*fs,int n){\nint newstack=fs->freereg+n;\nif(newstack>fs->f->maxstacksize){\nif(newstack>=250)\nluaX_syntaxerror(fs->ls,\"function or expression too complex\");\nfs->f->maxstacksize=cast_byte(newstack);\n}\n}\nstatic void luaK_reserveregs(FuncState*fs,int n){\nluaK_checkstack(fs,n);\nfs->freereg+=n;\n}\nstatic void freereg(FuncState*fs,int reg){\nif(!ISK(reg)&&reg>=fs->nactvar){\nfs->freereg--;\n}\n}\nstatic void freeexp(FuncState*fs,expdesc*e){\nif(e->k==VNONRELOC)\nfreereg(fs,e->u.s.info);\n}\nstatic int addk(FuncState*fs,TValue*k,TValue*v){\nlua_State*L=fs->L;\nTValue*idx=luaH_set(L,fs->h,k);\nProto*f=fs->f;\nint oldsize=f->sizek;\nif(ttisnumber(idx)){\nreturn cast_int(nvalue(idx));\n}\nelse{\nsetnvalue(idx,cast_num(fs->nk));\nluaM_growvector(L,f->k,fs->nk,f->sizek,TValue,\n((1<<(9+9))-1),\"constant table overflow\");\nwhile(oldsize<f->sizek)setnilvalue(&f->k[oldsize++]);\nsetobj(L,&f->k[fs->nk],v);\nluaC_barrier(L,f,v);\nreturn fs->nk++;\n}\n}\nstatic int luaK_stringK(FuncState*fs,TString*s){\nTValue o;\nsetsvalue(fs->L,&o,s);\nreturn addk(fs,&o,&o);\n}\nstatic int luaK_numberK(FuncState*fs,lua_Number r){\nTValue o;\nsetnvalue(&o,r);\nreturn addk(fs,&o,&o);\n}\nstatic int boolK(FuncState*fs,int b){\nTValue o;\nsetbvalue(&o,b);\nreturn addk(fs,&o,&o);\n}\nstatic int nilK(FuncState*fs){\nTValue k,v;\nsetnilvalue(&v);\nsethvalue(fs->L,&k,fs->h);\nreturn addk(fs,&k,&v);\n}\nstatic void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){\nif(e->k==VCALL){\nSETARG_C(getcode(fs,e),nresults+1);\n}\nelse if(e->k==VVARARG){\nSETARG_B(getcode(fs,e),nresults+1);\nSETARG_A(getcode(fs,e),fs->freereg);\nluaK_reserveregs(fs,1);\n}\n}\nstatic void luaK_setoneret(FuncState*fs,expdesc*e){\nif(e->k==VCALL){\ne->k=VNONRELOC;\ne->u.s.info=GETARG_A(getcode(fs,e));\n}\nelse if(e->k==VVARARG){\nSETARG_B(getcode(fs,e),2);\ne->k=VRELOCABLE;\n}\n}\nstatic void luaK_dischargevars(FuncState*fs,expdesc*e){\nswitch(e->k){\ncase VLOCAL:{\ne->k=VNONRELOC;\nbreak;\n}\ncase VUPVAL:{\ne->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VGLOBAL:{\ne->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VINDEXED:{\nfreereg(fs,e->u.s.aux);\nfreereg(fs,e->u.s.info);\ne->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux);\ne->k=VRELOCABLE;\nbreak;\n}\ncase VVARARG:\ncase VCALL:{\nluaK_setoneret(fs,e);\nbreak;\n}\ndefault:break;\n}\n}\nstatic int code_label(FuncState*fs,int A,int b,int jump){\nluaK_getlabel(fs);\nreturn luaK_codeABC(fs,OP_LOADBOOL,A,b,jump);\n}\nstatic void discharge2reg(FuncState*fs,expdesc*e,int reg){\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:{\nluaK_nil(fs,reg,1);\nbreak;\n}\ncase VFALSE:case VTRUE:{\nluaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0);\nbreak;\n}\ncase VK:{\nluaK_codeABx(fs,OP_LOADK,reg,e->u.s.info);\nbreak;\n}\ncase VKNUM:{\nluaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval));\nbreak;\n}\ncase VRELOCABLE:{\nInstruction*pc=&getcode(fs,e);\nSETARG_A(*pc,reg);\nbreak;\n}\ncase VNONRELOC:{\nif(reg!=e->u.s.info)\nluaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0);\nbreak;\n}\ndefault:{\nreturn;\n}\n}\ne->u.s.info=reg;\ne->k=VNONRELOC;\n}\nstatic void discharge2anyreg(FuncState*fs,expdesc*e){\nif(e->k!=VNONRELOC){\nluaK_reserveregs(fs,1);\ndischarge2reg(fs,e,fs->freereg-1);\n}\n}\nstatic void exp2reg(FuncState*fs,expdesc*e,int reg){\ndischarge2reg(fs,e,reg);\nif(e->k==VJMP)\nluaK_concat(fs,&e->t,e->u.s.info);\nif(hasjumps(e)){\nint final;\nint p_f=(-1);\nint p_t=(-1);\nif(need_value(fs,e->t)||need_value(fs,e->f)){\nint fj=(e->k==VJMP)?(-1):luaK_jump(fs);\np_f=code_label(fs,reg,0,1);\np_t=code_label(fs,reg,1,0);\nluaK_patchtohere(fs,fj);\n}\nfinal=luaK_getlabel(fs);\npatchlistaux(fs,e->f,final,reg,p_f);\npatchlistaux(fs,e->t,final,reg,p_t);\n}\ne->f=e->t=(-1);\ne->u.s.info=reg;\ne->k=VNONRELOC;\n}\nstatic void luaK_exp2nextreg(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nfreeexp(fs,e);\nluaK_reserveregs(fs,1);\nexp2reg(fs,e,fs->freereg-1);\n}\nstatic int luaK_exp2anyreg(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nif(e->k==VNONRELOC){\nif(!hasjumps(e))return e->u.s.info;\nif(e->u.s.info>=fs->nactvar){\nexp2reg(fs,e,e->u.s.info);\nreturn e->u.s.info;\n}\n}\nluaK_exp2nextreg(fs,e);\nreturn e->u.s.info;\n}\nstatic void luaK_exp2val(FuncState*fs,expdesc*e){\nif(hasjumps(e))\nluaK_exp2anyreg(fs,e);\nelse\nluaK_dischargevars(fs,e);\n}\nstatic int luaK_exp2RK(FuncState*fs,expdesc*e){\nluaK_exp2val(fs,e);\nswitch(e->k){\ncase VKNUM:\ncase VTRUE:\ncase VFALSE:\ncase VNIL:{\nif(fs->nk<=((1<<(9-1))-1)){\ne->u.s.info=(e->k==VNIL)?nilK(fs):\n(e->k==VKNUM)?luaK_numberK(fs,e->u.nval):\nboolK(fs,(e->k==VTRUE));\ne->k=VK;\nreturn RKASK(e->u.s.info);\n}\nelse break;\n}\ncase VK:{\nif(e->u.s.info<=((1<<(9-1))-1))\nreturn RKASK(e->u.s.info);\nelse break;\n}\ndefault:break;\n}\nreturn luaK_exp2anyreg(fs,e);\n}\nstatic void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){\nswitch(var->k){\ncase VLOCAL:{\nfreeexp(fs,ex);\nexp2reg(fs,ex,var->u.s.info);\nreturn;\n}\ncase VUPVAL:{\nint e=luaK_exp2anyreg(fs,ex);\nluaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0);\nbreak;\n}\ncase VGLOBAL:{\nint e=luaK_exp2anyreg(fs,ex);\nluaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info);\nbreak;\n}\ncase VINDEXED:{\nint e=luaK_exp2RK(fs,ex);\nluaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e);\nbreak;\n}\ndefault:{\nbreak;\n}\n}\nfreeexp(fs,ex);\n}\nstatic void luaK_self(FuncState*fs,expdesc*e,expdesc*key){\nint func;\nluaK_exp2anyreg(fs,e);\nfreeexp(fs,e);\nfunc=fs->freereg;\nluaK_reserveregs(fs,2);\nluaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key));\nfreeexp(fs,key);\ne->u.s.info=func;\ne->k=VNONRELOC;\n}\nstatic void invertjump(FuncState*fs,expdesc*e){\nInstruction*pc=getjumpcontrol(fs,e->u.s.info);\nSETARG_A(*pc,!(GETARG_A(*pc)));\n}\nstatic int jumponcond(FuncState*fs,expdesc*e,int cond){\nif(e->k==VRELOCABLE){\nInstruction ie=getcode(fs,e);\nif(GET_OPCODE(ie)==OP_NOT){\nfs->pc--;\nreturn condjump(fs,OP_TEST,GETARG_B(ie),0,!cond);\n}\n}\ndischarge2anyreg(fs,e);\nfreeexp(fs,e);\nreturn condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond);\n}\nstatic void luaK_goiftrue(FuncState*fs,expdesc*e){\nint pc;\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VK:case VKNUM:case VTRUE:{\npc=(-1);\nbreak;\n}\ncase VJMP:{\ninvertjump(fs,e);\npc=e->u.s.info;\nbreak;\n}\ndefault:{\npc=jumponcond(fs,e,0);\nbreak;\n}\n}\nluaK_concat(fs,&e->f,pc);\nluaK_patchtohere(fs,e->t);\ne->t=(-1);\n}\nstatic void luaK_goiffalse(FuncState*fs,expdesc*e){\nint pc;\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:case VFALSE:{\npc=(-1);\nbreak;\n}\ncase VJMP:{\npc=e->u.s.info;\nbreak;\n}\ndefault:{\npc=jumponcond(fs,e,1);\nbreak;\n}\n}\nluaK_concat(fs,&e->t,pc);\nluaK_patchtohere(fs,e->f);\ne->f=(-1);\n}\nstatic void codenot(FuncState*fs,expdesc*e){\nluaK_dischargevars(fs,e);\nswitch(e->k){\ncase VNIL:case VFALSE:{\ne->k=VTRUE;\nbreak;\n}\ncase VK:case VKNUM:case VTRUE:{\ne->k=VFALSE;\nbreak;\n}\ncase VJMP:{\ninvertjump(fs,e);\nbreak;\n}\ncase VRELOCABLE:\ncase VNONRELOC:{\ndischarge2anyreg(fs,e);\nfreeexp(fs,e);\ne->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0);\ne->k=VRELOCABLE;\nbreak;\n}\ndefault:{\nbreak;\n}\n}\n{int temp=e->f;e->f=e->t;e->t=temp;}\nremovevalues(fs,e->f);\nremovevalues(fs,e->t);\n}\nstatic void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){\nt->u.s.aux=luaK_exp2RK(fs,k);\nt->k=VINDEXED;\n}\nstatic int constfolding(OpCode op,expdesc*e1,expdesc*e2){\nlua_Number v1,v2,r;\nif(!isnumeral(e1)||!isnumeral(e2))return 0;\nv1=e1->u.nval;\nv2=e2->u.nval;\nswitch(op){\ncase OP_ADD:r=luai_numadd(v1,v2);break;\ncase OP_SUB:r=luai_numsub(v1,v2);break;\ncase OP_MUL:r=luai_nummul(v1,v2);break;\ncase OP_DIV:\nif(v2==0)return 0;\nr=luai_numdiv(v1,v2);break;\ncase OP_MOD:\nif(v2==0)return 0;\nr=luai_nummod(v1,v2);break;\ncase OP_POW:r=luai_numpow(v1,v2);break;\ncase OP_UNM:r=luai_numunm(v1);break;\ncase OP_LEN:return 0;\ndefault:r=0;break;\n}\nif(luai_numisnan(r))return 0;\ne1->u.nval=r;\nreturn 1;\n}\nstatic void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){\nif(constfolding(op,e1,e2))\nreturn;\nelse{\nint o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0;\nint o1=luaK_exp2RK(fs,e1);\nif(o1>o2){\nfreeexp(fs,e1);\nfreeexp(fs,e2);\n}\nelse{\nfreeexp(fs,e2);\nfreeexp(fs,e1);\n}\ne1->u.s.info=luaK_codeABC(fs,op,0,o1,o2);\ne1->k=VRELOCABLE;\n}\n}\nstatic void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1,\nexpdesc*e2){\nint o1=luaK_exp2RK(fs,e1);\nint o2=luaK_exp2RK(fs,e2);\nfreeexp(fs,e2);\nfreeexp(fs,e1);\nif(cond==0&&op!=OP_EQ){\nint temp;\ntemp=o1;o1=o2;o2=temp;\ncond=1;\n}\ne1->u.s.info=condjump(fs,op,cond,o1,o2);\ne1->k=VJMP;\n}\nstatic void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){\nexpdesc e2;\ne2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0;\nswitch(op){\ncase OPR_MINUS:{\nif(!isnumeral(e))\nluaK_exp2anyreg(fs,e);\ncodearith(fs,OP_UNM,e,&e2);\nbreak;\n}\ncase OPR_NOT:codenot(fs,e);break;\ncase OPR_LEN:{\nluaK_exp2anyreg(fs,e);\ncodearith(fs,OP_LEN,e,&e2);\nbreak;\n}\ndefault:;\n}\n}\nstatic void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){\nswitch(op){\ncase OPR_AND:{\nluaK_goiftrue(fs,v);\nbreak;\n}\ncase OPR_OR:{\nluaK_goiffalse(fs,v);\nbreak;\n}\ncase OPR_CONCAT:{\nluaK_exp2nextreg(fs,v);\nbreak;\n}\ncase OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV:\ncase OPR_MOD:case OPR_POW:{\nif(!isnumeral(v))luaK_exp2RK(fs,v);\nbreak;\n}\ndefault:{\nluaK_exp2RK(fs,v);\nbreak;\n}\n}\n}\nstatic void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){\nswitch(op){\ncase OPR_AND:{\nluaK_dischargevars(fs,e2);\nluaK_concat(fs,&e2->f,e1->f);\n*e1=*e2;\nbreak;\n}\ncase OPR_OR:{\nluaK_dischargevars(fs,e2);\nluaK_concat(fs,&e2->t,e1->t);\n*e1=*e2;\nbreak;\n}\ncase OPR_CONCAT:{\nluaK_exp2val(fs,e2);\nif(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){\nfreeexp(fs,e1);\nSETARG_B(getcode(fs,e2),e1->u.s.info);\ne1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info;\n}\nelse{\nluaK_exp2nextreg(fs,e2);\ncodearith(fs,OP_CONCAT,e1,e2);\n}\nbreak;\n}\ncase OPR_ADD:codearith(fs,OP_ADD,e1,e2);break;\ncase OPR_SUB:codearith(fs,OP_SUB,e1,e2);break;\ncase OPR_MUL:codearith(fs,OP_MUL,e1,e2);break;\ncase OPR_DIV:codearith(fs,OP_DIV,e1,e2);break;\ncase OPR_MOD:codearith(fs,OP_MOD,e1,e2);break;\ncase OPR_POW:codearith(fs,OP_POW,e1,e2);break;\ncase OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break;\ncase OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break;\ncase OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break;\ncase OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break;\ncase OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break;\ncase OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break;\ndefault:;\n}\n}\nstatic void luaK_fixline(FuncState*fs,int line){\nfs->f->lineinfo[fs->pc-1]=line;\n}\nstatic int luaK_code(FuncState*fs,Instruction i,int line){\nProto*f=fs->f;\ndischargejpc(fs);\nluaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction,\n(INT_MAX-2),\"code size overflow\");\nf->code[fs->pc]=i;\nluaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int,\n(INT_MAX-2),\"code size overflow\");\nf->lineinfo[fs->pc]=line;\nreturn fs->pc++;\n}\nstatic int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){\nreturn luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline);\n}\nstatic int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){\nreturn luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline);\n}\nstatic void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){\nint c=(nelems-1)/50+1;\nint b=(tostore==(-1))?0:tostore;\nif(c<=((1<<9)-1))\nluaK_codeABC(fs,OP_SETLIST,base,b,c);\nelse{\nluaK_codeABC(fs,OP_SETLIST,base,b,0);\nluaK_code(fs,cast(Instruction,c),fs->ls->lastline);\n}\nfs->freereg=base+1;\n}\n#define hasmultret(k)((k)==VCALL||(k)==VVARARG)\n#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]])\n#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m)\ntypedef struct BlockCnt{\nstruct BlockCnt*previous;\nint breaklist;\nlu_byte nactvar;\nlu_byte upval;\nlu_byte isbreakable;\n}BlockCnt;\nstatic void chunk(LexState*ls);\nstatic void expr(LexState*ls,expdesc*v);\nstatic void anchor_token(LexState*ls){\nif(ls->t.token==TK_NAME||ls->t.token==TK_STRING){\nTString*ts=ls->t.seminfo.ts;\nluaX_newstring(ls,getstr(ts),ts->tsv.len);\n}\n}\nstatic void error_expected(LexState*ls,int token){\nluaX_syntaxerror(ls,\nluaO_pushfstring(ls->L,LUA_QL(\"%s\")\" expected\",luaX_token2str(ls,token)));\n}\nstatic void errorlimit(FuncState*fs,int limit,const char*what){\nconst char*msg=(fs->f->linedefined==0)?\nluaO_pushfstring(fs->L,\"main function has more than %d %s\",limit,what):\nluaO_pushfstring(fs->L,\"function at line %d has more than %d %s\",\nfs->f->linedefined,limit,what);\nluaX_lexerror(fs->ls,msg,0);\n}\nstatic int testnext(LexState*ls,int c){\nif(ls->t.token==c){\nluaX_next(ls);\nreturn 1;\n}\nelse return 0;\n}\nstatic void check(LexState*ls,int c){\nif(ls->t.token!=c)\nerror_expected(ls,c);\n}\nstatic void checknext(LexState*ls,int c){\ncheck(ls,c);\nluaX_next(ls);\n}\n#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);}\nstatic void check_match(LexState*ls,int what,int who,int where){\nif(!testnext(ls,what)){\nif(where==ls->linenumber)\nerror_expected(ls,what);\nelse{\nluaX_syntaxerror(ls,luaO_pushfstring(ls->L,\nLUA_QL(\"%s\")\" expected (to close \"LUA_QL(\"%s\")\" at line %d)\",\nluaX_token2str(ls,what),luaX_token2str(ls,who),where));\n}\n}\n}\nstatic TString*str_checkname(LexState*ls){\nTString*ts;\ncheck(ls,TK_NAME);\nts=ls->t.seminfo.ts;\nluaX_next(ls);\nreturn ts;\n}\nstatic void init_exp(expdesc*e,expkind k,int i){\ne->f=e->t=(-1);\ne->k=k;\ne->u.s.info=i;\n}\nstatic void codestring(LexState*ls,expdesc*e,TString*s){\ninit_exp(e,VK,luaK_stringK(ls->fs,s));\n}\nstatic void checkname(LexState*ls,expdesc*e){\ncodestring(ls,e,str_checkname(ls));\n}\nstatic int registerlocalvar(LexState*ls,TString*varname){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint oldsize=f->sizelocvars;\nluaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars,\nLocVar,SHRT_MAX,\"too many local variables\");\nwhile(oldsize<f->sizelocvars)f->locvars[oldsize++].varname=NULL;\nf->locvars[fs->nlocvars].varname=varname;\nluaC_objbarrier(ls->L,f,varname);\nreturn fs->nlocvars++;\n}\n#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,\"\"v,(sizeof(v)/sizeof(char))-1),n)\nstatic void new_localvar(LexState*ls,TString*name,int n){\nFuncState*fs=ls->fs;\nluaY_checklimit(fs,fs->nactvar+n+1,200,\"local variables\");\nfs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name));\n}\nstatic void adjustlocalvars(LexState*ls,int nvars){\nFuncState*fs=ls->fs;\nfs->nactvar=cast_byte(fs->nactvar+nvars);\nfor(;nvars;nvars--){\ngetlocvar(fs,fs->nactvar-nvars).startpc=fs->pc;\n}\n}\nstatic void removevars(LexState*ls,int tolevel){\nFuncState*fs=ls->fs;\nwhile(fs->nactvar>tolevel)\ngetlocvar(fs,--fs->nactvar).endpc=fs->pc;\n}\nstatic int indexupvalue(FuncState*fs,TString*name,expdesc*v){\nint i;\nProto*f=fs->f;\nint oldsize=f->sizeupvalues;\nfor(i=0;i<f->nups;i++){\nif(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){\nreturn i;\n}\n}\nluaY_checklimit(fs,f->nups+1,60,\"upvalues\");\nluaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues,\nTString*,(INT_MAX-2),\"\");\nwhile(oldsize<f->sizeupvalues)f->upvalues[oldsize++]=NULL;\nf->upvalues[f->nups]=name;\nluaC_objbarrier(fs->L,f,name);\nfs->upvalues[f->nups].k=cast_byte(v->k);\nfs->upvalues[f->nups].info=cast_byte(v->u.s.info);\nreturn f->nups++;\n}\nstatic int searchvar(FuncState*fs,TString*n){\nint i;\nfor(i=fs->nactvar-1;i>=0;i--){\nif(n==getlocvar(fs,i).varname)\nreturn i;\n}\nreturn-1;\n}\nstatic void markupval(FuncState*fs,int level){\nBlockCnt*bl=fs->bl;\nwhile(bl&&bl->nactvar>level)bl=bl->previous;\nif(bl)bl->upval=1;\n}\nstatic int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){\nif(fs==NULL){\ninit_exp(var,VGLOBAL,((1<<8)-1));\nreturn VGLOBAL;\n}\nelse{\nint v=searchvar(fs,n);\nif(v>=0){\ninit_exp(var,VLOCAL,v);\nif(!base)\nmarkupval(fs,v);\nreturn VLOCAL;\n}\nelse{\nif(singlevaraux(fs->prev,n,var,0)==VGLOBAL)\nreturn VGLOBAL;\nvar->u.s.info=indexupvalue(fs,n,var);\nvar->k=VUPVAL;\nreturn VUPVAL;\n}\n}\n}\nstatic void singlevar(LexState*ls,expdesc*var){\nTString*varname=str_checkname(ls);\nFuncState*fs=ls->fs;\nif(singlevaraux(fs,varname,var,1)==VGLOBAL)\nvar->u.s.info=luaK_stringK(fs,varname);\n}\nstatic void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){\nFuncState*fs=ls->fs;\nint extra=nvars-nexps;\nif(hasmultret(e->k)){\nextra++;\nif(extra<0)extra=0;\nluaK_setreturns(fs,e,extra);\nif(extra>1)luaK_reserveregs(fs,extra-1);\n}\nelse{\nif(e->k!=VVOID)luaK_exp2nextreg(fs,e);\nif(extra>0){\nint reg=fs->freereg;\nluaK_reserveregs(fs,extra);\nluaK_nil(fs,reg,extra);\n}\n}\n}\nstatic void enterlevel(LexState*ls){\nif(++ls->L->nCcalls>200)\nluaX_lexerror(ls,\"chunk has too many syntax levels\",0);\n}\n#define leavelevel(ls)((ls)->L->nCcalls--)\nstatic void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){\nbl->breaklist=(-1);\nbl->isbreakable=isbreakable;\nbl->nactvar=fs->nactvar;\nbl->upval=0;\nbl->previous=fs->bl;\nfs->bl=bl;\n}\nstatic void leaveblock(FuncState*fs){\nBlockCnt*bl=fs->bl;\nfs->bl=bl->previous;\nremovevars(fs->ls,bl->nactvar);\nif(bl->upval)\nluaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);\nfs->freereg=fs->nactvar;\nluaK_patchtohere(fs,bl->breaklist);\n}\nstatic void pushclosure(LexState*ls,FuncState*func,expdesc*v){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint oldsize=f->sizep;\nint i;\nluaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*,\n((1<<(9+9))-1),\"constant table overflow\");\nwhile(oldsize<f->sizep)f->p[oldsize++]=NULL;\nf->p[fs->np++]=func->f;\nluaC_objbarrier(ls->L,f,func->f);\ninit_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1));\nfor(i=0;i<func->f->nups;i++){\nOpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL;\nluaK_codeABC(fs,o,0,func->upvalues[i].info,0);\n}\n}\nstatic void open_func(LexState*ls,FuncState*fs){\nlua_State*L=ls->L;\nProto*f=luaF_newproto(L);\nfs->f=f;\nfs->prev=ls->fs;\nfs->ls=ls;\nfs->L=L;\nls->fs=fs;\nfs->pc=0;\nfs->lasttarget=-1;\nfs->jpc=(-1);\nfs->freereg=0;\nfs->nk=0;\nfs->np=0;\nfs->nlocvars=0;\nfs->nactvar=0;\nfs->bl=NULL;\nf->source=ls->source;\nf->maxstacksize=2;\nfs->h=luaH_new(L,0,0);\nsethvalue(L,L->top,fs->h);\nincr_top(L);\nsetptvalue(L,L->top,f);\nincr_top(L);\n}\nstatic void close_func(LexState*ls){\nlua_State*L=ls->L;\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nremovevars(ls,0);\nluaK_ret(fs,0,0);\nluaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction);\nf->sizecode=fs->pc;\nluaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int);\nf->sizelineinfo=fs->pc;\nluaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue);\nf->sizek=fs->nk;\nluaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*);\nf->sizep=fs->np;\nluaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar);\nf->sizelocvars=fs->nlocvars;\nluaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*);\nf->sizeupvalues=f->nups;\nls->fs=fs->prev;\nif(fs)anchor_token(ls);\nL->top-=2;\n}\nstatic Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){\nstruct LexState lexstate;\nstruct FuncState funcstate;\nlexstate.buff=buff;\nluaX_setinput(L,&lexstate,z,luaS_new(L,name));\nopen_func(&lexstate,&funcstate);\nfuncstate.f->is_vararg=2;\nluaX_next(&lexstate);\nchunk(&lexstate);\ncheck(&lexstate,TK_EOS);\nclose_func(&lexstate);\nreturn funcstate.f;\n}\nstatic void field(LexState*ls,expdesc*v){\nFuncState*fs=ls->fs;\nexpdesc key;\nluaK_exp2anyreg(fs,v);\nluaX_next(ls);\ncheckname(ls,&key);\nluaK_indexed(fs,v,&key);\n}\nstatic void yindex(LexState*ls,expdesc*v){\nluaX_next(ls);\nexpr(ls,v);\nluaK_exp2val(ls->fs,v);\nchecknext(ls,']');\n}\nstruct ConsControl{\nexpdesc v;\nexpdesc*t;\nint nh;\nint na;\nint tostore;\n};\nstatic void recfield(LexState*ls,struct ConsControl*cc){\nFuncState*fs=ls->fs;\nint reg=ls->fs->freereg;\nexpdesc key,val;\nint rkkey;\nif(ls->t.token==TK_NAME){\nluaY_checklimit(fs,cc->nh,(INT_MAX-2),\"items in a constructor\");\ncheckname(ls,&key);\n}\nelse\nyindex(ls,&key);\ncc->nh++;\nchecknext(ls,'=');\nrkkey=luaK_exp2RK(fs,&key);\nexpr(ls,&val);\nluaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val));\nfs->freereg=reg;\n}\nstatic void closelistfield(FuncState*fs,struct ConsControl*cc){\nif(cc->v.k==VVOID)return;\nluaK_exp2nextreg(fs,&cc->v);\ncc->v.k=VVOID;\nif(cc->tostore==50){\nluaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);\ncc->tostore=0;\n}\n}\nstatic void lastlistfield(FuncState*fs,struct ConsControl*cc){\nif(cc->tostore==0)return;\nif(hasmultret(cc->v.k)){\nluaK_setmultret(fs,&cc->v);\nluaK_setlist(fs,cc->t->u.s.info,cc->na,(-1));\ncc->na--;\n}\nelse{\nif(cc->v.k!=VVOID)\nluaK_exp2nextreg(fs,&cc->v);\nluaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);\n}\n}\nstatic void listfield(LexState*ls,struct ConsControl*cc){\nexpr(ls,&cc->v);\nluaY_checklimit(ls->fs,cc->na,(INT_MAX-2),\"items in a constructor\");\ncc->na++;\ncc->tostore++;\n}\nstatic void constructor(LexState*ls,expdesc*t){\nFuncState*fs=ls->fs;\nint line=ls->linenumber;\nint pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0);\nstruct ConsControl cc;\ncc.na=cc.nh=cc.tostore=0;\ncc.t=t;\ninit_exp(t,VRELOCABLE,pc);\ninit_exp(&cc.v,VVOID,0);\nluaK_exp2nextreg(ls->fs,t);\nchecknext(ls,'{');\ndo{\nif(ls->t.token=='}')break;\ncloselistfield(fs,&cc);\nswitch(ls->t.token){\ncase TK_NAME:{\nluaX_lookahead(ls);\nif(ls->lookahead.token!='=')\nlistfield(ls,&cc);\nelse\nrecfield(ls,&cc);\nbreak;\n}\ncase'[':{\nrecfield(ls,&cc);\nbreak;\n}\ndefault:{\nlistfield(ls,&cc);\nbreak;\n}\n}\n}while(testnext(ls,',')||testnext(ls,';'));\ncheck_match(ls,'}','{',line);\nlastlistfield(fs,&cc);\nSETARG_B(fs->f->code[pc],luaO_int2fb(cc.na));\nSETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh));\n}\nstatic void parlist(LexState*ls){\nFuncState*fs=ls->fs;\nProto*f=fs->f;\nint nparams=0;\nf->is_vararg=0;\nif(ls->t.token!=')'){\ndo{\nswitch(ls->t.token){\ncase TK_NAME:{\nnew_localvar(ls,str_checkname(ls),nparams++);\nbreak;\n}\ncase TK_DOTS:{\nluaX_next(ls);\nf->is_vararg|=2;\nbreak;\n}\ndefault:luaX_syntaxerror(ls,\"<name> or \"LUA_QL(\"...\")\" expected\");\n}\n}while(!f->is_vararg&&testnext(ls,','));\n}\nadjustlocalvars(ls,nparams);\nf->numparams=cast_byte(fs->nactvar-(f->is_vararg&1));\nluaK_reserveregs(fs,fs->nactvar);\n}\nstatic void body(LexState*ls,expdesc*e,int needself,int line){\nFuncState new_fs;\nopen_func(ls,&new_fs);\nnew_fs.f->linedefined=line;\nchecknext(ls,'(');\nif(needself){\nnew_localvarliteral(ls,\"self\",0);\nadjustlocalvars(ls,1);\n}\nparlist(ls);\nchecknext(ls,')');\nchunk(ls);\nnew_fs.f->lastlinedefined=ls->linenumber;\ncheck_match(ls,TK_END,TK_FUNCTION,line);\nclose_func(ls);\npushclosure(ls,&new_fs,e);\n}\nstatic int explist1(LexState*ls,expdesc*v){\nint n=1;\nexpr(ls,v);\nwhile(testnext(ls,',')){\nluaK_exp2nextreg(ls->fs,v);\nexpr(ls,v);\nn++;\n}\nreturn n;\n}\nstatic void funcargs(LexState*ls,expdesc*f){\nFuncState*fs=ls->fs;\nexpdesc args;\nint base,nparams;\nint line=ls->linenumber;\nswitch(ls->t.token){\ncase'(':{\nif(line!=ls->lastline)\nluaX_syntaxerror(ls,\"ambiguous syntax (function call x new statement)\");\nluaX_next(ls);\nif(ls->t.token==')')\nargs.k=VVOID;\nelse{\nexplist1(ls,&args);\nluaK_setmultret(fs,&args);\n}\ncheck_match(ls,')','(',line);\nbreak;\n}\ncase'{':{\nconstructor(ls,&args);\nbreak;\n}\ncase TK_STRING:{\ncodestring(ls,&args,ls->t.seminfo.ts);\nluaX_next(ls);\nbreak;\n}\ndefault:{\nluaX_syntaxerror(ls,\"function arguments expected\");\nreturn;\n}\n}\nbase=f->u.s.info;\nif(hasmultret(args.k))\nnparams=(-1);\nelse{\nif(args.k!=VVOID)\nluaK_exp2nextreg(fs,&args);\nnparams=fs->freereg-(base+1);\n}\ninit_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2));\nluaK_fixline(fs,line);\nfs->freereg=base+1;\n}\nstatic void prefixexp(LexState*ls,expdesc*v){\nswitch(ls->t.token){\ncase'(':{\nint line=ls->linenumber;\nluaX_next(ls);\nexpr(ls,v);\ncheck_match(ls,')','(',line);\nluaK_dischargevars(ls->fs,v);\nreturn;\n}\ncase TK_NAME:{\nsinglevar(ls,v);\nreturn;\n}\ndefault:{\nluaX_syntaxerror(ls,\"unexpected symbol\");\nreturn;\n}\n}\n}\nstatic void primaryexp(LexState*ls,expdesc*v){\nFuncState*fs=ls->fs;\nprefixexp(ls,v);\nfor(;;){\nswitch(ls->t.token){\ncase'.':{\nfield(ls,v);\nbreak;\n}\ncase'[':{\nexpdesc key;\nluaK_exp2anyreg(fs,v);\nyindex(ls,&key);\nluaK_indexed(fs,v,&key);\nbreak;\n}\ncase':':{\nexpdesc key;\nluaX_next(ls);\ncheckname(ls,&key);\nluaK_self(fs,v,&key);\nfuncargs(ls,v);\nbreak;\n}\ncase'(':case TK_STRING:case'{':{\nluaK_exp2nextreg(fs,v);\nfuncargs(ls,v);\nbreak;\n}\ndefault:return;\n}\n}\n}\nstatic void simpleexp(LexState*ls,expdesc*v){\nswitch(ls->t.token){\ncase TK_NUMBER:{\ninit_exp(v,VKNUM,0);\nv->u.nval=ls->t.seminfo.r;\nbreak;\n}\ncase TK_STRING:{\ncodestring(ls,v,ls->t.seminfo.ts);\nbreak;\n}\ncase TK_NIL:{\ninit_exp(v,VNIL,0);\nbreak;\n}\ncase TK_TRUE:{\ninit_exp(v,VTRUE,0);\nbreak;\n}\ncase TK_FALSE:{\ninit_exp(v,VFALSE,0);\nbreak;\n}\ncase TK_DOTS:{\nFuncState*fs=ls->fs;\ncheck_condition(ls,fs->f->is_vararg,\n\"cannot use \"LUA_QL(\"...\")\" outside a vararg function\");\nfs->f->is_vararg&=~4;\ninit_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0));\nbreak;\n}\ncase'{':{\nconstructor(ls,v);\nreturn;\n}\ncase TK_FUNCTION:{\nluaX_next(ls);\nbody(ls,v,0,ls->linenumber);\nreturn;\n}\ndefault:{\nprimaryexp(ls,v);\nreturn;\n}\n}\nluaX_next(ls);\n}\nstatic UnOpr getunopr(int op){\nswitch(op){\ncase TK_NOT:return OPR_NOT;\ncase'-':return OPR_MINUS;\ncase'#':return OPR_LEN;\ndefault:return OPR_NOUNOPR;\n}\n}\nstatic BinOpr getbinopr(int op){\nswitch(op){\ncase'+':return OPR_ADD;\ncase'-':return OPR_SUB;\ncase'*':return OPR_MUL;\ncase'/':return OPR_DIV;\ncase'%':return OPR_MOD;\ncase'^':return OPR_POW;\ncase TK_CONCAT:return OPR_CONCAT;\ncase TK_NE:return OPR_NE;\ncase TK_EQ:return OPR_EQ;\ncase'<':return OPR_LT;\ncase TK_LE:return OPR_LE;\ncase'>':return OPR_GT;\ncase TK_GE:return OPR_GE;\ncase TK_AND:return OPR_AND;\ncase TK_OR:return OPR_OR;\ndefault:return OPR_NOBINOPR;\n}\n}\nstatic const struct{\nlu_byte left;\nlu_byte right;\n}priority[]={\n{6,6},{6,6},{7,7},{7,7},{7,7},\n{10,9},{5,4},\n{3,3},{3,3},\n{3,3},{3,3},{3,3},{3,3},\n{2,2},{1,1}\n};\nstatic BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){\nBinOpr op;\nUnOpr uop;\nenterlevel(ls);\nuop=getunopr(ls->t.token);\nif(uop!=OPR_NOUNOPR){\nluaX_next(ls);\nsubexpr(ls,v,8);\nluaK_prefix(ls->fs,uop,v);\n}\nelse simpleexp(ls,v);\nop=getbinopr(ls->t.token);\nwhile(op!=OPR_NOBINOPR&&priority[op].left>limit){\nexpdesc v2;\nBinOpr nextop;\nluaX_next(ls);\nluaK_infix(ls->fs,op,v);\nnextop=subexpr(ls,&v2,priority[op].right);\nluaK_posfix(ls->fs,op,v,&v2);\nop=nextop;\n}\nleavelevel(ls);\nreturn op;\n}\nstatic void expr(LexState*ls,expdesc*v){\nsubexpr(ls,v,0);\n}\nstatic int block_follow(int token){\nswitch(token){\ncase TK_ELSE:case TK_ELSEIF:case TK_END:\ncase TK_UNTIL:case TK_EOS:\nreturn 1;\ndefault:return 0;\n}\n}\nstatic void block(LexState*ls){\nFuncState*fs=ls->fs;\nBlockCnt bl;\nenterblock(fs,&bl,0);\nchunk(ls);\nleaveblock(fs);\n}\nstruct LHS_assign{\nstruct LHS_assign*prev;\nexpdesc v;\n};\nstatic void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){\nFuncState*fs=ls->fs;\nint extra=fs->freereg;\nint conflict=0;\nfor(;lh;lh=lh->prev){\nif(lh->v.k==VINDEXED){\nif(lh->v.u.s.info==v->u.s.info){\nconflict=1;\nlh->v.u.s.info=extra;\n}\nif(lh->v.u.s.aux==v->u.s.info){\nconflict=1;\nlh->v.u.s.aux=extra;\n}\n}\n}\nif(conflict){\nluaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0);\nluaK_reserveregs(fs,1);\n}\n}\nstatic void assignment(LexState*ls,struct LHS_assign*lh,int nvars){\nexpdesc e;\ncheck_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED,\n\"syntax error\");\nif(testnext(ls,',')){\nstruct LHS_assign nv;\nnv.prev=lh;\nprimaryexp(ls,&nv.v);\nif(nv.v.k==VLOCAL)\ncheck_conflict(ls,lh,&nv.v);\nluaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls,\n\"variables in assignment\");\nassignment(ls,&nv,nvars+1);\n}\nelse{\nint nexps;\nchecknext(ls,'=');\nnexps=explist1(ls,&e);\nif(nexps!=nvars){\nadjust_assign(ls,nvars,nexps,&e);\nif(nexps>nvars)\nls->fs->freereg-=nexps-nvars;\n}\nelse{\nluaK_setoneret(ls->fs,&e);\nluaK_storevar(ls->fs,&lh->v,&e);\nreturn;\n}\n}\ninit_exp(&e,VNONRELOC,ls->fs->freereg-1);\nluaK_storevar(ls->fs,&lh->v,&e);\n}\nstatic int cond(LexState*ls){\nexpdesc v;\nexpr(ls,&v);\nif(v.k==VNIL)v.k=VFALSE;\nluaK_goiftrue(ls->fs,&v);\nreturn v.f;\n}\nstatic void breakstat(LexState*ls){\nFuncState*fs=ls->fs;\nBlockCnt*bl=fs->bl;\nint upval=0;\nwhile(bl&&!bl->isbreakable){\nupval|=bl->upval;\nbl=bl->previous;\n}\nif(!bl)\nluaX_syntaxerror(ls,\"no loop to break\");\nif(upval)\nluaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);\nluaK_concat(fs,&bl->breaklist,luaK_jump(fs));\n}\nstatic void whilestat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nint whileinit;\nint condexit;\nBlockCnt bl;\nluaX_next(ls);\nwhileinit=luaK_getlabel(fs);\ncondexit=cond(ls);\nenterblock(fs,&bl,1);\nchecknext(ls,TK_DO);\nblock(ls);\nluaK_patchlist(fs,luaK_jump(fs),whileinit);\ncheck_match(ls,TK_END,TK_WHILE,line);\nleaveblock(fs);\nluaK_patchtohere(fs,condexit);\n}\nstatic void repeatstat(LexState*ls,int line){\nint condexit;\nFuncState*fs=ls->fs;\nint repeat_init=luaK_getlabel(fs);\nBlockCnt bl1,bl2;\nenterblock(fs,&bl1,1);\nenterblock(fs,&bl2,0);\nluaX_next(ls);\nchunk(ls);\ncheck_match(ls,TK_UNTIL,TK_REPEAT,line);\ncondexit=cond(ls);\nif(!bl2.upval){\nleaveblock(fs);\nluaK_patchlist(ls->fs,condexit,repeat_init);\n}\nelse{\nbreakstat(ls);\nluaK_patchtohere(ls->fs,condexit);\nleaveblock(fs);\nluaK_patchlist(ls->fs,luaK_jump(fs),repeat_init);\n}\nleaveblock(fs);\n}\nstatic int exp1(LexState*ls){\nexpdesc e;\nint k;\nexpr(ls,&e);\nk=e.k;\nluaK_exp2nextreg(ls->fs,&e);\nreturn k;\n}\nstatic void forbody(LexState*ls,int base,int line,int nvars,int isnum){\nBlockCnt bl;\nFuncState*fs=ls->fs;\nint prep,endfor;\nadjustlocalvars(ls,3);\nchecknext(ls,TK_DO);\nprep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs);\nenterblock(fs,&bl,0);\nadjustlocalvars(ls,nvars);\nluaK_reserveregs(fs,nvars);\nblock(ls);\nleaveblock(fs);\nluaK_patchtohere(fs,prep);\nendfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)):\nluaK_codeABC(fs,OP_TFORLOOP,base,0,nvars);\nluaK_fixline(fs,line);\nluaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1);\n}\nstatic void fornum(LexState*ls,TString*varname,int line){\nFuncState*fs=ls->fs;\nint base=fs->freereg;\nnew_localvarliteral(ls,\"(for index)\",0);\nnew_localvarliteral(ls,\"(for limit)\",1);\nnew_localvarliteral(ls,\"(for step)\",2);\nnew_localvar(ls,varname,3);\nchecknext(ls,'=');\nexp1(ls);\nchecknext(ls,',');\nexp1(ls);\nif(testnext(ls,','))\nexp1(ls);\nelse{\nluaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1));\nluaK_reserveregs(fs,1);\n}\nforbody(ls,base,line,1,1);\n}\nstatic void forlist(LexState*ls,TString*indexname){\nFuncState*fs=ls->fs;\nexpdesc e;\nint nvars=0;\nint line;\nint base=fs->freereg;\nnew_localvarliteral(ls,\"(for generator)\",nvars++);\nnew_localvarliteral(ls,\"(for state)\",nvars++);\nnew_localvarliteral(ls,\"(for control)\",nvars++);\nnew_localvar(ls,indexname,nvars++);\nwhile(testnext(ls,','))\nnew_localvar(ls,str_checkname(ls),nvars++);\nchecknext(ls,TK_IN);\nline=ls->linenumber;\nadjust_assign(ls,3,explist1(ls,&e),&e);\nluaK_checkstack(fs,3);\nforbody(ls,base,line,nvars-3,0);\n}\nstatic void forstat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nTString*varname;\nBlockCnt bl;\nenterblock(fs,&bl,1);\nluaX_next(ls);\nvarname=str_checkname(ls);\nswitch(ls->t.token){\ncase'=':fornum(ls,varname,line);break;\ncase',':case TK_IN:forlist(ls,varname);break;\ndefault:luaX_syntaxerror(ls,LUA_QL(\"=\")\" or \"LUA_QL(\"in\")\" expected\");\n}\ncheck_match(ls,TK_END,TK_FOR,line);\nleaveblock(fs);\n}\nstatic int test_then_block(LexState*ls){\nint condexit;\nluaX_next(ls);\ncondexit=cond(ls);\nchecknext(ls,TK_THEN);\nblock(ls);\nreturn condexit;\n}\nstatic void ifstat(LexState*ls,int line){\nFuncState*fs=ls->fs;\nint flist;\nint escapelist=(-1);\nflist=test_then_block(ls);\nwhile(ls->t.token==TK_ELSEIF){\nluaK_concat(fs,&escapelist,luaK_jump(fs));\nluaK_patchtohere(fs,flist);\nflist=test_then_block(ls);\n}\nif(ls->t.token==TK_ELSE){\nluaK_concat(fs,&escapelist,luaK_jump(fs));\nluaK_patchtohere(fs,flist);\nluaX_next(ls);\nblock(ls);\n}\nelse\nluaK_concat(fs,&escapelist,flist);\nluaK_patchtohere(fs,escapelist);\ncheck_match(ls,TK_END,TK_IF,line);\n}\nstatic void localfunc(LexState*ls){\nexpdesc v,b;\nFuncState*fs=ls->fs;\nnew_localvar(ls,str_checkname(ls),0);\ninit_exp(&v,VLOCAL,fs->freereg);\nluaK_reserveregs(fs,1);\nadjustlocalvars(ls,1);\nbody(ls,&b,0,ls->linenumber);\nluaK_storevar(fs,&v,&b);\ngetlocvar(fs,fs->nactvar-1).startpc=fs->pc;\n}\nstatic void localstat(LexState*ls){\nint nvars=0;\nint nexps;\nexpdesc e;\ndo{\nnew_localvar(ls,str_checkname(ls),nvars++);\n}while(testnext(ls,','));\nif(testnext(ls,'='))\nnexps=explist1(ls,&e);\nelse{\ne.k=VVOID;\nnexps=0;\n}\nadjust_assign(ls,nvars,nexps,&e);\nadjustlocalvars(ls,nvars);\n}\nstatic int funcname(LexState*ls,expdesc*v){\nint needself=0;\nsinglevar(ls,v);\nwhile(ls->t.token=='.')\nfield(ls,v);\nif(ls->t.token==':'){\nneedself=1;\nfield(ls,v);\n}\nreturn needself;\n}\nstatic void funcstat(LexState*ls,int line){\nint needself;\nexpdesc v,b;\nluaX_next(ls);\nneedself=funcname(ls,&v);\nbody(ls,&b,needself,line);\nluaK_storevar(ls->fs,&v,&b);\nluaK_fixline(ls->fs,line);\n}\nstatic void exprstat(LexState*ls){\nFuncState*fs=ls->fs;\nstruct LHS_assign v;\nprimaryexp(ls,&v.v);\nif(v.v.k==VCALL)\nSETARG_C(getcode(fs,&v.v),1);\nelse{\nv.prev=NULL;\nassignment(ls,&v,1);\n}\n}\nstatic void retstat(LexState*ls){\nFuncState*fs=ls->fs;\nexpdesc e;\nint first,nret;\nluaX_next(ls);\nif(block_follow(ls->t.token)||ls->t.token==';')\nfirst=nret=0;\nelse{\nnret=explist1(ls,&e);\nif(hasmultret(e.k)){\nluaK_setmultret(fs,&e);\nif(e.k==VCALL&&nret==1){\nSET_OPCODE(getcode(fs,&e),OP_TAILCALL);\n}\nfirst=fs->nactvar;\nnret=(-1);\n}\nelse{\nif(nret==1)\nfirst=luaK_exp2anyreg(fs,&e);\nelse{\nluaK_exp2nextreg(fs,&e);\nfirst=fs->nactvar;\n}\n}\n}\nluaK_ret(fs,first,nret);\n}\nstatic int statement(LexState*ls){\nint line=ls->linenumber;\nswitch(ls->t.token){\ncase TK_IF:{\nifstat(ls,line);\nreturn 0;\n}\ncase TK_WHILE:{\nwhilestat(ls,line);\nreturn 0;\n}\ncase TK_DO:{\nluaX_next(ls);\nblock(ls);\ncheck_match(ls,TK_END,TK_DO,line);\nreturn 0;\n}\ncase TK_FOR:{\nforstat(ls,line);\nreturn 0;\n}\ncase TK_REPEAT:{\nrepeatstat(ls,line);\nreturn 0;\n}\ncase TK_FUNCTION:{\nfuncstat(ls,line);\nreturn 0;\n}\ncase TK_LOCAL:{\nluaX_next(ls);\nif(testnext(ls,TK_FUNCTION))\nlocalfunc(ls);\nelse\nlocalstat(ls);\nreturn 0;\n}\ncase TK_RETURN:{\nretstat(ls);\nreturn 1;\n}\ncase TK_BREAK:{\nluaX_next(ls);\nbreakstat(ls);\nreturn 1;\n}\ndefault:{\nexprstat(ls);\nreturn 0;\n}\n}\n}\nstatic void chunk(LexState*ls){\nint islast=0;\nenterlevel(ls);\nwhile(!islast&&!block_follow(ls->t.token)){\nislast=statement(ls);\ntestnext(ls,';');\nls->fs->freereg=ls->fs->nactvar;\n}\nleavelevel(ls);\n}\nstatic const TValue*luaV_tonumber(const TValue*obj,TValue*n){\nlua_Number num;\nif(ttisnumber(obj))return obj;\nif(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){\nsetnvalue(n,num);\nreturn n;\n}\nelse\nreturn NULL;\n}\nstatic int luaV_tostring(lua_State*L,StkId obj){\nif(!ttisnumber(obj))\nreturn 0;\nelse{\nchar s[32];\nlua_Number n=nvalue(obj);\nlua_number2str(s,n);\nsetsvalue(L,obj,luaS_new(L,s));\nreturn 1;\n}\n}\nstatic void callTMres(lua_State*L,StkId res,const TValue*f,\nconst TValue*p1,const TValue*p2){\nptrdiff_t result=savestack(L,res);\nsetobj(L,L->top,f);\nsetobj(L,L->top+1,p1);\nsetobj(L,L->top+2,p2);\nluaD_checkstack(L,3);\nL->top+=3;\nluaD_call(L,L->top-3,1);\nres=restorestack(L,result);\nL->top--;\nsetobj(L,res,L->top);\n}\nstatic void callTM(lua_State*L,const TValue*f,const TValue*p1,\nconst TValue*p2,const TValue*p3){\nsetobj(L,L->top,f);\nsetobj(L,L->top+1,p1);\nsetobj(L,L->top+2,p2);\nsetobj(L,L->top+3,p3);\nluaD_checkstack(L,4);\nL->top+=4;\nluaD_call(L,L->top-4,0);\n}\nstatic void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){\nint loop;\nfor(loop=0;loop<100;loop++){\nconst TValue*tm;\nif(ttistable(t)){\nTable*h=hvalue(t);\nconst TValue*res=luaH_get(h,key);\nif(!ttisnil(res)||\n(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){\nsetobj(L,val,res);\nreturn;\n}\n}\nelse if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX)))\nluaG_typeerror(L,t,\"index\");\nif(ttisfunction(tm)){\ncallTMres(L,val,tm,t,key);\nreturn;\n}\nt=tm;\n}\nluaG_runerror(L,\"loop in gettable\");\n}\nstatic void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){\nint loop;\nTValue temp;\nfor(loop=0;loop<100;loop++){\nconst TValue*tm;\nif(ttistable(t)){\nTable*h=hvalue(t);\nTValue*oldval=luaH_set(L,h,key);\nif(!ttisnil(oldval)||\n(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){\nsetobj(L,oldval,val);\nh->flags=0;\nluaC_barriert(L,h,val);\nreturn;\n}\n}\nelse if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX)))\nluaG_typeerror(L,t,\"index\");\nif(ttisfunction(tm)){\ncallTM(L,tm,t,key,val);\nreturn;\n}\nsetobj(L,&temp,tm);\nt=&temp;\n}\nluaG_runerror(L,\"loop in settable\");\n}\nstatic int call_binTM(lua_State*L,const TValue*p1,const TValue*p2,\nStkId res,TMS event){\nconst TValue*tm=luaT_gettmbyobj(L,p1,event);\nif(ttisnil(tm))\ntm=luaT_gettmbyobj(L,p2,event);\nif(ttisnil(tm))return 0;\ncallTMres(L,res,tm,p1,p2);\nreturn 1;\n}\nstatic const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2,\nTMS event){\nconst TValue*tm1=fasttm(L,mt1,event);\nconst TValue*tm2;\nif(tm1==NULL)return NULL;\nif(mt1==mt2)return tm1;\ntm2=fasttm(L,mt2,event);\nif(tm2==NULL)return NULL;\nif(luaO_rawequalObj(tm1,tm2))\nreturn tm1;\nreturn NULL;\n}\nstatic int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2,\nTMS event){\nconst TValue*tm1=luaT_gettmbyobj(L,p1,event);\nconst TValue*tm2;\nif(ttisnil(tm1))return-1;\ntm2=luaT_gettmbyobj(L,p2,event);\nif(!luaO_rawequalObj(tm1,tm2))\nreturn-1;\ncallTMres(L,L->top,tm1,p1,p2);\nreturn!l_isfalse(L->top);\n}\nstatic int l_strcmp(const TString*ls,const TString*rs){\nconst char*l=getstr(ls);\nsize_t ll=ls->tsv.len;\nconst char*r=getstr(rs);\nsize_t lr=rs->tsv.len;\nfor(;;){\nint temp=strcoll(l,r);\nif(temp!=0)return temp;\nelse{\nsize_t len=strlen(l);\nif(len==lr)\nreturn(len==ll)?0:1;\nelse if(len==ll)\nreturn-1;\nlen++;\nl+=len;ll-=len;r+=len;lr-=len;\n}\n}\n}\nstatic int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){\nint res;\nif(ttype(l)!=ttype(r))\nreturn luaG_ordererror(L,l,r);\nelse if(ttisnumber(l))\nreturn luai_numlt(nvalue(l),nvalue(r));\nelse if(ttisstring(l))\nreturn l_strcmp(rawtsvalue(l),rawtsvalue(r))<0;\nelse if((res=call_orderTM(L,l,r,TM_LT))!=-1)\nreturn res;\nreturn luaG_ordererror(L,l,r);\n}\nstatic int lessequal(lua_State*L,const TValue*l,const TValue*r){\nint res;\nif(ttype(l)!=ttype(r))\nreturn luaG_ordererror(L,l,r);\nelse if(ttisnumber(l))\nreturn luai_numle(nvalue(l),nvalue(r));\nelse if(ttisstring(l))\nreturn l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0;\nelse if((res=call_orderTM(L,l,r,TM_LE))!=-1)\nreturn res;\nelse if((res=call_orderTM(L,r,l,TM_LT))!=-1)\nreturn!res;\nreturn luaG_ordererror(L,l,r);\n}\nstatic int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){\nconst TValue*tm;\nswitch(ttype(t1)){\ncase 0:return 1;\ncase 3:return luai_numeq(nvalue(t1),nvalue(t2));\ncase 1:return bvalue(t1)==bvalue(t2);\ncase 2:return pvalue(t1)==pvalue(t2);\ncase 7:{\nif(uvalue(t1)==uvalue(t2))return 1;\ntm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable,\nTM_EQ);\nbreak;\n}\ncase 5:{\nif(hvalue(t1)==hvalue(t2))return 1;\ntm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ);\nbreak;\n}\ndefault:return gcvalue(t1)==gcvalue(t2);\n}\nif(tm==NULL)return 0;\ncallTMres(L,L->top,tm,t1,t2);\nreturn!l_isfalse(L->top);\n}\nstatic void luaV_concat(lua_State*L,int total,int last){\ndo{\nStkId top=L->base+last+1;\nint n=2;\nif(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){\nif(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT))\nluaG_concaterror(L,top-2,top-1);\n}else if(tsvalue(top-1)->len==0)\n(void)tostring(L,top-2);\nelse{\nsize_t tl=tsvalue(top-1)->len;\nchar*buffer;\nint i;\nfor(n=1;n<total&&tostring(L,top-n-1);n++){\nsize_t l=tsvalue(top-n-1)->len;\nif(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,\"string length overflow\");\ntl+=l;\n}\nbuffer=luaZ_openspace(L,&G(L)->buff,tl);\ntl=0;\nfor(i=n;i>0;i--){\nsize_t l=tsvalue(top-i)->len;\nmemcpy(buffer+tl,svalue(top-i),l);\ntl+=l;\n}\nsetsvalue(L,top-n,luaS_newlstr(L,buffer,tl));\n}\ntotal-=n-1;\nlast-=n-1;\n}while(total>1);\n}\nstatic void Arith(lua_State*L,StkId ra,const TValue*rb,\nconst TValue*rc,TMS op){\nTValue tempb,tempc;\nconst TValue*b,*c;\nif((b=luaV_tonumber(rb,&tempb))!=NULL&&\n(c=luaV_tonumber(rc,&tempc))!=NULL){\nlua_Number nb=nvalue(b),nc=nvalue(c);\nswitch(op){\ncase TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break;\ncase TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break;\ncase TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break;\ncase TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break;\ncase TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break;\ncase TM_POW:setnvalue(ra,luai_numpow(nb,nc));break;\ncase TM_UNM:setnvalue(ra,luai_numunm(nb));break;\ndefault:break;\n}\n}\nelse if(!call_binTM(L,rb,rc,ra,op))\nluaG_aritherror(L,rb,rc);\n}\n#define runtime_check(L,c){if(!(c))break;}\n#define RA(i)(base+GETARG_A(i))\n#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i))\n#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i))\n#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i))\n#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i))\n#define dojump(L,pc,i){(pc)+=(i);}\n#define Protect(x){L->savedpc=pc;{x;};base=L->base;}\n#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));}\nstatic void luaV_execute(lua_State*L,int nexeccalls){\nLClosure*cl;\nStkId base;\nTValue*k;\nconst Instruction*pc;\nreentry:\npc=L->savedpc;\ncl=&clvalue(L->ci->func)->l;\nbase=L->base;\nk=cl->p->k;\nfor(;;){\nconst Instruction i=*pc++;\nStkId ra;\nra=RA(i);\nswitch(GET_OPCODE(i)){\ncase OP_MOVE:{\nsetobj(L,ra,RB(i));\ncontinue;\n}\ncase OP_LOADK:{\nsetobj(L,ra,KBx(i));\ncontinue;\n}\ncase OP_LOADBOOL:{\nsetbvalue(ra,GETARG_B(i));\nif(GETARG_C(i))pc++;\ncontinue;\n}\ncase OP_LOADNIL:{\nTValue*rb=RB(i);\ndo{\nsetnilvalue(rb--);\n}while(rb>=ra);\ncontinue;\n}\ncase OP_GETUPVAL:{\nint b=GETARG_B(i);\nsetobj(L,ra,cl->upvals[b]->v);\ncontinue;\n}\ncase OP_GETGLOBAL:{\nTValue g;\nTValue*rb=KBx(i);\nsethvalue(L,&g,cl->env);\nProtect(luaV_gettable(L,&g,rb,ra));\ncontinue;\n}\ncase OP_GETTABLE:{\nProtect(luaV_gettable(L,RB(i),RKC(i),ra));\ncontinue;\n}\ncase OP_SETGLOBAL:{\nTValue g;\nsethvalue(L,&g,cl->env);\nProtect(luaV_settable(L,&g,KBx(i),ra));\ncontinue;\n}\ncase OP_SETUPVAL:{\nUpVal*uv=cl->upvals[GETARG_B(i)];\nsetobj(L,uv->v,ra);\nluaC_barrier(L,uv,ra);\ncontinue;\n}\ncase OP_SETTABLE:{\nProtect(luaV_settable(L,ra,RKB(i),RKC(i)));\ncontinue;\n}\ncase OP_NEWTABLE:{\nint b=GETARG_B(i);\nint c=GETARG_C(i);\nsethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c)));\nProtect(luaC_checkGC(L));\ncontinue;\n}\ncase OP_SELF:{\nStkId rb=RB(i);\nsetobj(L,ra+1,rb);\nProtect(luaV_gettable(L,rb,RKC(i),ra));\ncontinue;\n}\ncase OP_ADD:{\narith_op(luai_numadd,TM_ADD);\ncontinue;\n}\ncase OP_SUB:{\narith_op(luai_numsub,TM_SUB);\ncontinue;\n}\ncase OP_MUL:{\narith_op(luai_nummul,TM_MUL);\ncontinue;\n}\ncase OP_DIV:{\narith_op(luai_numdiv,TM_DIV);\ncontinue;\n}\ncase OP_MOD:{\narith_op(luai_nummod,TM_MOD);\ncontinue;\n}\ncase OP_POW:{\narith_op(luai_numpow,TM_POW);\ncontinue;\n}\ncase OP_UNM:{\nTValue*rb=RB(i);\nif(ttisnumber(rb)){\nlua_Number nb=nvalue(rb);\nsetnvalue(ra,luai_numunm(nb));\n}\nelse{\nProtect(Arith(L,ra,rb,rb,TM_UNM));\n}\ncontinue;\n}\ncase OP_NOT:{\nint res=l_isfalse(RB(i));\nsetbvalue(ra,res);\ncontinue;\n}\ncase OP_LEN:{\nconst TValue*rb=RB(i);\nswitch(ttype(rb)){\ncase 5:{\nsetnvalue(ra,cast_num(luaH_getn(hvalue(rb))));\nbreak;\n}\ncase 4:{\nsetnvalue(ra,cast_num(tsvalue(rb)->len));\nbreak;\n}\ndefault:{\nProtect(\nif(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN))\nluaG_typeerror(L,rb,\"get length of\");\n)\n}\n}\ncontinue;\n}\ncase OP_CONCAT:{\nint b=GETARG_B(i);\nint c=GETARG_C(i);\nProtect(luaV_concat(L,c-b+1,c);luaC_checkGC(L));\nsetobj(L,RA(i),base+b);\ncontinue;\n}\ncase OP_JMP:{\ndojump(L,pc,GETARG_sBx(i));\ncontinue;\n}\ncase OP_EQ:{\nTValue*rb=RKB(i);\nTValue*rc=RKC(i);\nProtect(\nif(equalobj(L,rb,rc)==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_LT:{\nProtect(\nif(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_LE:{\nProtect(\nif(lessequal(L,RKB(i),RKC(i))==GETARG_A(i))\ndojump(L,pc,GETARG_sBx(*pc));\n)\npc++;\ncontinue;\n}\ncase OP_TEST:{\nif(l_isfalse(ra)!=GETARG_C(i))\ndojump(L,pc,GETARG_sBx(*pc));\npc++;\ncontinue;\n}\ncase OP_TESTSET:{\nTValue*rb=RB(i);\nif(l_isfalse(rb)!=GETARG_C(i)){\nsetobj(L,ra,rb);\ndojump(L,pc,GETARG_sBx(*pc));\n}\npc++;\ncontinue;\n}\ncase OP_CALL:{\nint b=GETARG_B(i);\nint nresults=GETARG_C(i)-1;\nif(b!=0)L->top=ra+b;\nL->savedpc=pc;\nswitch(luaD_precall(L,ra,nresults)){\ncase 0:{\nnexeccalls++;\ngoto reentry;\n}\ncase 1:{\nif(nresults>=0)L->top=L->ci->top;\nbase=L->base;\ncontinue;\n}\ndefault:{\nreturn;\n}\n}\n}\ncase OP_TAILCALL:{\nint b=GETARG_B(i);\nif(b!=0)L->top=ra+b;\nL->savedpc=pc;\nswitch(luaD_precall(L,ra,(-1))){\ncase 0:{\nCallInfo*ci=L->ci-1;\nint aux;\nStkId func=ci->func;\nStkId pfunc=(ci+1)->func;\nif(L->openupval)luaF_close(L,ci->base);\nL->base=ci->base=ci->func+((ci+1)->base-pfunc);\nfor(aux=0;pfunc+aux<L->top;aux++)\nsetobj(L,func+aux,pfunc+aux);\nci->top=L->top=func+aux;\nci->savedpc=L->savedpc;\nci->tailcalls++;\nL->ci--;\ngoto reentry;\n}\ncase 1:{\nbase=L->base;\ncontinue;\n}\ndefault:{\nreturn;\n}\n}\n}\ncase OP_RETURN:{\nint b=GETARG_B(i);\nif(b!=0)L->top=ra+b-1;\nif(L->openupval)luaF_close(L,base);\nL->savedpc=pc;\nb=luaD_poscall(L,ra);\nif(--nexeccalls==0)\nreturn;\nelse{\nif(b)L->top=L->ci->top;\ngoto reentry;\n}\n}\ncase OP_FORLOOP:{\nlua_Number step=nvalue(ra+2);\nlua_Number idx=luai_numadd(nvalue(ra),step);\nlua_Number limit=nvalue(ra+1);\nif(luai_numlt(0,step)?luai_numle(idx,limit)\n:luai_numle(limit,idx)){\ndojump(L,pc,GETARG_sBx(i));\nsetnvalue(ra,idx);\nsetnvalue(ra+3,idx);\n}\ncontinue;\n}\ncase OP_FORPREP:{\nconst TValue*init=ra;\nconst TValue*plimit=ra+1;\nconst TValue*pstep=ra+2;\nL->savedpc=pc;\nif(!tonumber(init,ra))\nluaG_runerror(L,LUA_QL(\"for\")\" initial value must be a number\");\nelse if(!tonumber(plimit,ra+1))\nluaG_runerror(L,LUA_QL(\"for\")\" limit must be a number\");\nelse if(!tonumber(pstep,ra+2))\nluaG_runerror(L,LUA_QL(\"for\")\" step must be a number\");\nsetnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep)));\ndojump(L,pc,GETARG_sBx(i));\ncontinue;\n}\ncase OP_TFORLOOP:{\nStkId cb=ra+3;\nsetobj(L,cb+2,ra+2);\nsetobj(L,cb+1,ra+1);\nsetobj(L,cb,ra);\nL->top=cb+3;\nProtect(luaD_call(L,cb,GETARG_C(i)));\nL->top=L->ci->top;\ncb=RA(i)+3;\nif(!ttisnil(cb)){\nsetobj(L,cb-1,cb);\ndojump(L,pc,GETARG_sBx(*pc));\n}\npc++;\ncontinue;\n}\ncase OP_SETLIST:{\nint n=GETARG_B(i);\nint c=GETARG_C(i);\nint last;\nTable*h;\nif(n==0){\nn=cast_int(L->top-ra)-1;\nL->top=L->ci->top;\n}\nif(c==0)c=cast_int(*pc++);\nruntime_check(L,ttistable(ra));\nh=hvalue(ra);\nlast=((c-1)*50)+n;\nif(last>h->sizearray)\nluaH_resizearray(L,h,last);\nfor(;n>0;n--){\nTValue*val=ra+n;\nsetobj(L,luaH_setnum(L,h,last--),val);\nluaC_barriert(L,h,val);\n}\ncontinue;\n}\ncase OP_CLOSE:{\nluaF_close(L,ra);\ncontinue;\n}\ncase OP_CLOSURE:{\nProto*p;\nClosure*ncl;\nint nup,j;\np=cl->p->p[GETARG_Bx(i)];\nnup=p->nups;\nncl=luaF_newLclosure(L,nup,cl->env);\nncl->l.p=p;\nfor(j=0;j<nup;j++,pc++){\nif(GET_OPCODE(*pc)==OP_GETUPVAL)\nncl->l.upvals[j]=cl->upvals[GETARG_B(*pc)];\nelse{\nncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc));\n}\n}\nsetclvalue(L,ra,ncl);\nProtect(luaC_checkGC(L));\ncontinue;\n}\ncase OP_VARARG:{\nint b=GETARG_B(i)-1;\nint j;\nCallInfo*ci=L->ci;\nint n=cast_int(ci->base-ci->func)-cl->p->numparams-1;\nif(b==(-1)){\nProtect(luaD_checkstack(L,n));\nra=RA(i);\nb=n;\nL->top=ra+n;\n}\nfor(j=0;j<b;j++){\nif(j<n){\nsetobj(L,ra+j,ci->base-n+j);\n}\nelse{\nsetnilvalue(ra+j);\n}\n}\ncontinue;\n}\n}\n}\n}\n#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base))\n#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_))\n#define api_incr_top(L){luai_apicheck(L,L->top<L->ci->top);L->top++;}\nstatic TValue*index2adr(lua_State*L,int idx){\nif(idx>0){\nTValue*o=L->base+(idx-1);\nluai_apicheck(L,idx<=L->ci->top-L->base);\nif(o>=L->top)return cast(TValue*,(&luaO_nilobject_));\nelse return o;\n}\nelse if(idx>(-10000)){\nluai_apicheck(L,idx!=0&&-idx<=L->top-L->base);\nreturn L->top+idx;\n}\nelse switch(idx){\ncase(-10000):return registry(L);\ncase(-10001):{\nClosure*func=curr_func(L);\nsethvalue(L,&L->env,func->c.env);\nreturn&L->env;\n}\ncase(-10002):return gt(L);\ndefault:{\nClosure*func=curr_func(L);\nidx=(-10002)-idx;\nreturn(idx<=func->c.nupvalues)\n?&func->c.upvalue[idx-1]\n:cast(TValue*,(&luaO_nilobject_));\n}\n}\n}\nstatic Table*getcurrenv(lua_State*L){\nif(L->ci==L->base_ci)\nreturn hvalue(gt(L));\nelse{\nClosure*func=curr_func(L);\nreturn func->c.env;\n}\n}\nstatic int lua_checkstack(lua_State*L,int size){\nint res=1;\nif(size>8000||(L->top-L->base+size)>8000)\nres=0;\nelse if(size>0){\nluaD_checkstack(L,size);\nif(L->ci->top<L->top+size)\nL->ci->top=L->top+size;\n}\nreturn res;\n}\nstatic lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){\nlua_CFunction old;\nold=G(L)->panic;\nG(L)->panic=panicf;\nreturn old;\n}\nstatic int lua_gettop(lua_State*L){\nreturn cast_int(L->top-L->base);\n}\nstatic void lua_settop(lua_State*L,int idx){\nif(idx>=0){\nluai_apicheck(L,idx<=L->stack_last-L->base);\nwhile(L->top<L->base+idx)\nsetnilvalue(L->top++);\nL->top=L->base+idx;\n}\nelse{\nluai_apicheck(L,-(idx+1)<=(L->top-L->base));\nL->top+=idx+1;\n}\n}\nstatic void lua_remove(lua_State*L,int idx){\nStkId p;\np=index2adr(L,idx);\napi_checkvalidindex(L,p);\nwhile(++p<L->top)setobj(L,p-1,p);\nL->top--;\n}\nstatic void lua_insert(lua_State*L,int idx){\nStkId p;\nStkId q;\np=index2adr(L,idx);\napi_checkvalidindex(L,p);\nfor(q=L->top;q>p;q--)setobj(L,q,q-1);\nsetobj(L,p,L->top);\n}\nstatic void lua_replace(lua_State*L,int idx){\nStkId o;\nif(idx==(-10001)&&L->ci==L->base_ci)\nluaG_runerror(L,\"no calling environment\");\napi_checknelems(L,1);\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nif(idx==(-10001)){\nClosure*func=curr_func(L);\nluai_apicheck(L,ttistable(L->top-1));\nfunc->c.env=hvalue(L->top-1);\nluaC_barrier(L,func,L->top-1);\n}\nelse{\nsetobj(L,o,L->top-1);\nif(idx<(-10002))\nluaC_barrier(L,curr_func(L),L->top-1);\n}\nL->top--;\n}\nstatic void lua_pushvalue(lua_State*L,int idx){\nsetobj(L,L->top,index2adr(L,idx));\napi_incr_top(L);\n}\nstatic int lua_type(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn(o==(&luaO_nilobject_))?(-1):ttype(o);\n}\nstatic const char*lua_typename(lua_State*L,int t){\nUNUSED(L);\nreturn(t==(-1))?\"no value\":luaT_typenames[t];\n}\nstatic int lua_iscfunction(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn iscfunction(o);\n}\nstatic int lua_isnumber(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nreturn tonumber(o,&n);\n}\nstatic int lua_isstring(lua_State*L,int idx){\nint t=lua_type(L,idx);\nreturn(t==4||t==3);\n}\nstatic int lua_rawequal(lua_State*L,int index1,int index2){\nStkId o1=index2adr(L,index1);\nStkId o2=index2adr(L,index2);\nreturn(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0\n:luaO_rawequalObj(o1,o2);\n}\nstatic int lua_lessthan(lua_State*L,int index1,int index2){\nStkId o1,o2;\nint i;\no1=index2adr(L,index1);\no2=index2adr(L,index2);\ni=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0\n:luaV_lessthan(L,o1,o2);\nreturn i;\n}\nstatic lua_Number lua_tonumber(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nif(tonumber(o,&n))\nreturn nvalue(o);\nelse\nreturn 0;\n}\nstatic lua_Integer lua_tointeger(lua_State*L,int idx){\nTValue n;\nconst TValue*o=index2adr(L,idx);\nif(tonumber(o,&n)){\nlua_Integer res;\nlua_Number num=nvalue(o);\nlua_number2integer(res,num);\nreturn res;\n}\nelse\nreturn 0;\n}\nstatic int lua_toboolean(lua_State*L,int idx){\nconst TValue*o=index2adr(L,idx);\nreturn!l_isfalse(o);\n}\nstatic const char*lua_tolstring(lua_State*L,int idx,size_t*len){\nStkId o=index2adr(L,idx);\nif(!ttisstring(o)){\nif(!luaV_tostring(L,o)){\nif(len!=NULL)*len=0;\nreturn NULL;\n}\nluaC_checkGC(L);\no=index2adr(L,idx);\n}\nif(len!=NULL)*len=tsvalue(o)->len;\nreturn svalue(o);\n}\nstatic size_t lua_objlen(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nswitch(ttype(o)){\ncase 4:return tsvalue(o)->len;\ncase 7:return uvalue(o)->len;\ncase 5:return luaH_getn(hvalue(o));\ncase 3:{\nsize_t l;\nl=(luaV_tostring(L,o)?tsvalue(o)->len:0);\nreturn l;\n}\ndefault:return 0;\n}\n}\nstatic lua_CFunction lua_tocfunction(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nreturn(!iscfunction(o))?NULL:clvalue(o)->c.f;\n}\nstatic void*lua_touserdata(lua_State*L,int idx){\nStkId o=index2adr(L,idx);\nswitch(ttype(o)){\ncase 7:return(rawuvalue(o)+1);\ncase 2:return pvalue(o);\ndefault:return NULL;\n}\n}\nstatic void lua_pushnil(lua_State*L){\nsetnilvalue(L->top);\napi_incr_top(L);\n}\nstatic void lua_pushnumber(lua_State*L,lua_Number n){\nsetnvalue(L->top,n);\napi_incr_top(L);\n}\nstatic void lua_pushinteger(lua_State*L,lua_Integer n){\nsetnvalue(L->top,cast_num(n));\napi_incr_top(L);\n}\nstatic void lua_pushlstring(lua_State*L,const char*s,size_t len){\nluaC_checkGC(L);\nsetsvalue(L,L->top,luaS_newlstr(L,s,len));\napi_incr_top(L);\n}\nstatic void lua_pushstring(lua_State*L,const char*s){\nif(s==NULL)\nlua_pushnil(L);\nelse\nlua_pushlstring(L,s,strlen(s));\n}\nstatic const char*lua_pushvfstring(lua_State*L,const char*fmt,\nva_list argp){\nconst char*ret;\nluaC_checkGC(L);\nret=luaO_pushvfstring(L,fmt,argp);\nreturn ret;\n}\nstatic const char*lua_pushfstring(lua_State*L,const char*fmt,...){\nconst char*ret;\nva_list argp;\nluaC_checkGC(L);\nva_start(argp,fmt);\nret=luaO_pushvfstring(L,fmt,argp);\nva_end(argp);\nreturn ret;\n}\nstatic void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){\nClosure*cl;\nluaC_checkGC(L);\napi_checknelems(L,n);\ncl=luaF_newCclosure(L,n,getcurrenv(L));\ncl->c.f=fn;\nL->top-=n;\nwhile(n--)\nsetobj(L,&cl->c.upvalue[n],L->top+n);\nsetclvalue(L,L->top,cl);\napi_incr_top(L);\n}\nstatic void lua_pushboolean(lua_State*L,int b){\nsetbvalue(L->top,(b!=0));\napi_incr_top(L);\n}\nstatic int lua_pushthread(lua_State*L){\nsetthvalue(L,L->top,L);\napi_incr_top(L);\nreturn(G(L)->mainthread==L);\n}\nstatic void lua_gettable(lua_State*L,int idx){\nStkId t;\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nluaV_gettable(L,t,L->top-1,L->top-1);\n}\nstatic void lua_getfield(lua_State*L,int idx,const char*k){\nStkId t;\nTValue key;\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nsetsvalue(L,&key,luaS_new(L,k));\nluaV_gettable(L,t,&key,L->top);\napi_incr_top(L);\n}\nstatic void lua_rawget(lua_State*L,int idx){\nStkId t;\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nsetobj(L,L->top-1,luaH_get(hvalue(t),L->top-1));\n}\nstatic void lua_rawgeti(lua_State*L,int idx,int n){\nStkId o;\no=index2adr(L,idx);\nluai_apicheck(L,ttistable(o));\nsetobj(L,L->top,luaH_getnum(hvalue(o),n));\napi_incr_top(L);\n}\nstatic void lua_createtable(lua_State*L,int narray,int nrec){\nluaC_checkGC(L);\nsethvalue(L,L->top,luaH_new(L,narray,nrec));\napi_incr_top(L);\n}\nstatic int lua_getmetatable(lua_State*L,int objindex){\nconst TValue*obj;\nTable*mt=NULL;\nint res;\nobj=index2adr(L,objindex);\nswitch(ttype(obj)){\ncase 5:\nmt=hvalue(obj)->metatable;\nbreak;\ncase 7:\nmt=uvalue(obj)->metatable;\nbreak;\ndefault:\nmt=G(L)->mt[ttype(obj)];\nbreak;\n}\nif(mt==NULL)\nres=0;\nelse{\nsethvalue(L,L->top,mt);\napi_incr_top(L);\nres=1;\n}\nreturn res;\n}\nstatic void lua_getfenv(lua_State*L,int idx){\nStkId o;\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nswitch(ttype(o)){\ncase 6:\nsethvalue(L,L->top,clvalue(o)->c.env);\nbreak;\ncase 7:\nsethvalue(L,L->top,uvalue(o)->env);\nbreak;\ncase 8:\nsetobj(L,L->top,gt(thvalue(o)));\nbreak;\ndefault:\nsetnilvalue(L->top);\nbreak;\n}\napi_incr_top(L);\n}\nstatic void lua_settable(lua_State*L,int idx){\nStkId t;\napi_checknelems(L,2);\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nluaV_settable(L,t,L->top-2,L->top-1);\nL->top-=2;\n}\nstatic void lua_setfield(lua_State*L,int idx,const char*k){\nStkId t;\nTValue key;\napi_checknelems(L,1);\nt=index2adr(L,idx);\napi_checkvalidindex(L,t);\nsetsvalue(L,&key,luaS_new(L,k));\nluaV_settable(L,t,&key,L->top-1);\nL->top--;\n}\nstatic void lua_rawset(lua_State*L,int idx){\nStkId t;\napi_checknelems(L,2);\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nsetobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1);\nluaC_barriert(L,hvalue(t),L->top-1);\nL->top-=2;\n}\nstatic void lua_rawseti(lua_State*L,int idx,int n){\nStkId o;\napi_checknelems(L,1);\no=index2adr(L,idx);\nluai_apicheck(L,ttistable(o));\nsetobj(L,luaH_setnum(L,hvalue(o),n),L->top-1);\nluaC_barriert(L,hvalue(o),L->top-1);\nL->top--;\n}\nstatic int lua_setmetatable(lua_State*L,int objindex){\nTValue*obj;\nTable*mt;\napi_checknelems(L,1);\nobj=index2adr(L,objindex);\napi_checkvalidindex(L,obj);\nif(ttisnil(L->top-1))\nmt=NULL;\nelse{\nluai_apicheck(L,ttistable(L->top-1));\nmt=hvalue(L->top-1);\n}\nswitch(ttype(obj)){\ncase 5:{\nhvalue(obj)->metatable=mt;\nif(mt)\nluaC_objbarriert(L,hvalue(obj),mt);\nbreak;\n}\ncase 7:{\nuvalue(obj)->metatable=mt;\nif(mt)\nluaC_objbarrier(L,rawuvalue(obj),mt);\nbreak;\n}\ndefault:{\nG(L)->mt[ttype(obj)]=mt;\nbreak;\n}\n}\nL->top--;\nreturn 1;\n}\nstatic int lua_setfenv(lua_State*L,int idx){\nStkId o;\nint res=1;\napi_checknelems(L,1);\no=index2adr(L,idx);\napi_checkvalidindex(L,o);\nluai_apicheck(L,ttistable(L->top-1));\nswitch(ttype(o)){\ncase 6:\nclvalue(o)->c.env=hvalue(L->top-1);\nbreak;\ncase 7:\nuvalue(o)->env=hvalue(L->top-1);\nbreak;\ncase 8:\nsethvalue(L,gt(thvalue(o)),hvalue(L->top-1));\nbreak;\ndefault:\nres=0;\nbreak;\n}\nif(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1));\nL->top--;\nreturn res;\n}\n#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;}\n#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na)))\nstatic void lua_call(lua_State*L,int nargs,int nresults){\nStkId func;\napi_checknelems(L,nargs+1);\ncheckresults(L,nargs,nresults);\nfunc=L->top-(nargs+1);\nluaD_call(L,func,nresults);\nadjustresults(L,nresults);\n}\nstruct CallS{\nStkId func;\nint nresults;\n};\nstatic void f_call(lua_State*L,void*ud){\nstruct CallS*c=cast(struct CallS*,ud);\nluaD_call(L,c->func,c->nresults);\n}\nstatic int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){\nstruct CallS c;\nint status;\nptrdiff_t func;\napi_checknelems(L,nargs+1);\ncheckresults(L,nargs,nresults);\nif(errfunc==0)\nfunc=0;\nelse{\nStkId o=index2adr(L,errfunc);\napi_checkvalidindex(L,o);\nfunc=savestack(L,o);\n}\nc.func=L->top-(nargs+1);\nc.nresults=nresults;\nstatus=luaD_pcall(L,f_call,&c,savestack(L,c.func),func);\nadjustresults(L,nresults);\nreturn status;\n}\nstatic int lua_load(lua_State*L,lua_Reader reader,void*data,\nconst char*chunkname){\nZIO z;\nint status;\nif(!chunkname)chunkname=\"?\";\nluaZ_init(L,&z,reader,data);\nstatus=luaD_protectedparser(L,&z,chunkname);\nreturn status;\n}\nstatic int lua_error(lua_State*L){\napi_checknelems(L,1);\nluaG_errormsg(L);\nreturn 0;\n}\nstatic int lua_next(lua_State*L,int idx){\nStkId t;\nint more;\nt=index2adr(L,idx);\nluai_apicheck(L,ttistable(t));\nmore=luaH_next(L,hvalue(t),L->top-1);\nif(more){\napi_incr_top(L);\n}\nelse\nL->top-=1;\nreturn more;\n}\nstatic void lua_concat(lua_State*L,int n){\napi_checknelems(L,n);\nif(n>=2){\nluaC_checkGC(L);\nluaV_concat(L,n,cast_int(L->top-L->base)-1);\nL->top-=(n-1);\n}\nelse if(n==0){\nsetsvalue(L,L->top,luaS_newlstr(L,\"\",0));\napi_incr_top(L);\n}\n}\nstatic void*lua_newuserdata(lua_State*L,size_t size){\nUdata*u;\nluaC_checkGC(L);\nu=luaS_newudata(L,size,getcurrenv(L));\nsetuvalue(L,L->top,u);\napi_incr_top(L);\nreturn u+1;\n}\n#define luaL_getn(L,i)((int)lua_objlen(L,i))\n#define luaL_setn(L,i,j)((void)0)\ntypedef struct luaL_Reg{\nconst char*name;\nlua_CFunction func;\n}luaL_Reg;\nstatic void luaI_openlib(lua_State*L,const char*libname,\nconst luaL_Reg*l,int nup);\nstatic int luaL_argerror(lua_State*L,int numarg,const char*extramsg);\nstatic const char* luaL_checklstring(lua_State*L,int numArg,\nsize_t*l);\nstatic const char* luaL_optlstring(lua_State*L,int numArg,\nconst char*def,size_t*l);\nstatic lua_Integer luaL_checkinteger(lua_State*L,int numArg);\nstatic lua_Integer luaL_optinteger(lua_State*L,int nArg,\nlua_Integer def);\nstatic int luaL_error(lua_State*L,const char*fmt,...);\nstatic const char* luaL_findtable(lua_State*L,int idx,\nconst char*fname,int szhint);\n#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg))))\n#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL))\n#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL))\n#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n)))\n#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d)))\n#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i)))\n#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n)))\n#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n)))\ntypedef struct luaL_Buffer{\nchar*p;\nint lvl;\nlua_State*L;\nchar buffer[BUFSIZ];\n}luaL_Buffer;\n#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c)))\n#define luaL_addsize(B,n)((B)->p+=(n))\nstatic char* luaL_prepbuffer(luaL_Buffer*B);\nstatic int luaL_argerror(lua_State*L,int narg,const char*extramsg){\nlua_Debug ar;\nif(!lua_getstack(L,0,&ar))\nreturn luaL_error(L,\"bad argument #%d (%s)\",narg,extramsg);\nlua_getinfo(L,\"n\",&ar);\nif(strcmp(ar.namewhat,\"method\")==0){\nnarg--;\nif(narg==0)\nreturn luaL_error(L,\"calling \"LUA_QL(\"%s\")\" on bad self (%s)\",\nar.name,extramsg);\n}\nif(ar.name==NULL)\nar.name=\"?\";\nreturn luaL_error(L,\"bad argument #%d to \"LUA_QL(\"%s\")\" (%s)\",\nnarg,ar.name,extramsg);\n}\nstatic int luaL_typerror(lua_State*L,int narg,const char*tname){\nconst char*msg=lua_pushfstring(L,\"%s expected, got %s\",\ntname,luaL_typename(L,narg));\nreturn luaL_argerror(L,narg,msg);\n}\nstatic void tag_error(lua_State*L,int narg,int tag){\nluaL_typerror(L,narg,lua_typename(L,tag));\n}\nstatic void luaL_where(lua_State*L,int level){\nlua_Debug ar;\nif(lua_getstack(L,level,&ar)){\nlua_getinfo(L,\"Sl\",&ar);\nif(ar.currentline>0){\nlua_pushfstring(L,\"%s:%d: \",ar.short_src,ar.currentline);\nreturn;\n}\n}\nlua_pushliteral(L,\"\");\n}\nstatic int luaL_error(lua_State*L,const char*fmt,...){\nva_list argp;\nva_start(argp,fmt);\nluaL_where(L,1);\nlua_pushvfstring(L,fmt,argp);\nva_end(argp);\nlua_concat(L,2);\nreturn lua_error(L);\n}\nstatic int luaL_newmetatable(lua_State*L,const char*tname){\nlua_getfield(L,(-10000),tname);\nif(!lua_isnil(L,-1))\nreturn 0;\nlua_pop(L,1);\nlua_newtable(L);\nlua_pushvalue(L,-1);\nlua_setfield(L,(-10000),tname);\nreturn 1;\n}\nstatic void*luaL_checkudata(lua_State*L,int ud,const char*tname){\nvoid*p=lua_touserdata(L,ud);\nif(p!=NULL){\nif(lua_getmetatable(L,ud)){\nlua_getfield(L,(-10000),tname);\nif(lua_rawequal(L,-1,-2)){\nlua_pop(L,2);\nreturn p;\n}\n}\n}\nluaL_typerror(L,ud,tname);\nreturn NULL;\n}\nstatic void luaL_checkstack(lua_State*L,int space,const char*mes){\nif(!lua_checkstack(L,space))\nluaL_error(L,\"stack overflow (%s)\",mes);\n}\nstatic void luaL_checktype(lua_State*L,int narg,int t){\nif(lua_type(L,narg)!=t)\ntag_error(L,narg,t);\n}\nstatic void luaL_checkany(lua_State*L,int narg){\nif(lua_type(L,narg)==(-1))\nluaL_argerror(L,narg,\"value expected\");\n}\nstatic const char*luaL_checklstring(lua_State*L,int narg,size_t*len){\nconst char*s=lua_tolstring(L,narg,len);\nif(!s)tag_error(L,narg,4);\nreturn s;\n}\nstatic const char*luaL_optlstring(lua_State*L,int narg,\nconst char*def,size_t*len){\nif(lua_isnoneornil(L,narg)){\nif(len)\n*len=(def?strlen(def):0);\nreturn def;\n}\nelse return luaL_checklstring(L,narg,len);\n}\nstatic lua_Number luaL_checknumber(lua_State*L,int narg){\nlua_Number d=lua_tonumber(L,narg);\nif(d==0&&!lua_isnumber(L,narg))\ntag_error(L,narg,3);\nreturn d;\n}\nstatic lua_Integer luaL_checkinteger(lua_State*L,int narg){\nlua_Integer d=lua_tointeger(L,narg);\nif(d==0&&!lua_isnumber(L,narg))\ntag_error(L,narg,3);\nreturn d;\n}\nstatic lua_Integer luaL_optinteger(lua_State*L,int narg,\nlua_Integer def){\nreturn luaL_opt(L,luaL_checkinteger,narg,def);\n}\nstatic int luaL_getmetafield(lua_State*L,int obj,const char*event){\nif(!lua_getmetatable(L,obj))\nreturn 0;\nlua_pushstring(L,event);\nlua_rawget(L,-2);\nif(lua_isnil(L,-1)){\nlua_pop(L,2);\nreturn 0;\n}\nelse{\nlua_remove(L,-2);\nreturn 1;\n}\n}\nstatic void luaL_register(lua_State*L,const char*libname,\nconst luaL_Reg*l){\nluaI_openlib(L,libname,l,0);\n}\nstatic int libsize(const luaL_Reg*l){\nint size=0;\nfor(;l->name;l++)size++;\nreturn size;\n}\nstatic void luaI_openlib(lua_State*L,const char*libname,\nconst luaL_Reg*l,int nup){\nif(libname){\nint size=libsize(l);\nluaL_findtable(L,(-10000),\"_LOADED\",1);\nlua_getfield(L,-1,libname);\nif(!lua_istable(L,-1)){\nlua_pop(L,1);\nif(luaL_findtable(L,(-10002),libname,size)!=NULL)\nluaL_error(L,\"name conflict for module \"LUA_QL(\"%s\"),libname);\nlua_pushvalue(L,-1);\nlua_setfield(L,-3,libname);\n}\nlua_remove(L,-2);\nlua_insert(L,-(nup+1));\n}\nfor(;l->name;l++){\nint i;\nfor(i=0;i<nup;i++)\nlua_pushvalue(L,-nup);\nlua_pushcclosure(L,l->func,nup);\nlua_setfield(L,-(nup+2),l->name);\n}\nlua_pop(L,nup);\n}\nstatic const char*luaL_findtable(lua_State*L,int idx,\nconst char*fname,int szhint){\nconst char*e;\nlua_pushvalue(L,idx);\ndo{\ne=strchr(fname,'.');\nif(e==NULL)e=fname+strlen(fname);\nlua_pushlstring(L,fname,e-fname);\nlua_rawget(L,-2);\nif(lua_isnil(L,-1)){\nlua_pop(L,1);\nlua_createtable(L,0,(*e=='.'?1:szhint));\nlua_pushlstring(L,fname,e-fname);\nlua_pushvalue(L,-2);\nlua_settable(L,-4);\n}\nelse if(!lua_istable(L,-1)){\nlua_pop(L,2);\nreturn fname;\n}\nlua_remove(L,-2);\nfname=e+1;\n}while(*e=='.');\nreturn NULL;\n}\n#define bufflen(B)((B)->p-(B)->buffer)\n#define bufffree(B)((size_t)(BUFSIZ-bufflen(B)))\nstatic int emptybuffer(luaL_Buffer*B){\nsize_t l=bufflen(B);\nif(l==0)return 0;\nelse{\nlua_pushlstring(B->L,B->buffer,l);\nB->p=B->buffer;\nB->lvl++;\nreturn 1;\n}\n}\nstatic void adjuststack(luaL_Buffer*B){\nif(B->lvl>1){\nlua_State*L=B->L;\nint toget=1;\nsize_t toplen=lua_strlen(L,-1);\ndo{\nsize_t l=lua_strlen(L,-(toget+1));\nif(B->lvl-toget+1>=(20/2)||toplen>l){\ntoplen+=l;\ntoget++;\n}\nelse break;\n}while(toget<B->lvl);\nlua_concat(L,toget);\nB->lvl=B->lvl-toget+1;\n}\n}\nstatic char*luaL_prepbuffer(luaL_Buffer*B){\nif(emptybuffer(B))\nadjuststack(B);\nreturn B->buffer;\n}\nstatic void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){\nwhile(l--)\nluaL_addchar(B,*s++);\n}\nstatic void luaL_pushresult(luaL_Buffer*B){\nemptybuffer(B);\nlua_concat(B->L,B->lvl);\nB->lvl=1;\n}\nstatic void luaL_addvalue(luaL_Buffer*B){\nlua_State*L=B->L;\nsize_t vl;\nconst char*s=lua_tolstring(L,-1,&vl);\nif(vl<=bufffree(B)){\nmemcpy(B->p,s,vl);\nB->p+=vl;\nlua_pop(L,1);\n}\nelse{\nif(emptybuffer(B))\nlua_insert(L,-2);\nB->lvl++;\nadjuststack(B);\n}\n}\nstatic void luaL_buffinit(lua_State*L,luaL_Buffer*B){\nB->L=L;\nB->p=B->buffer;\nB->lvl=0;\n}\ntypedef struct LoadF{\nint extraline;\nFILE*f;\nchar buff[BUFSIZ];\n}LoadF;\nstatic const char*getF(lua_State*L,void*ud,size_t*size){\nLoadF*lf=(LoadF*)ud;\n(void)L;\nif(lf->extraline){\nlf->extraline=0;\n*size=1;\nreturn\"\\n\";\n}\nif(feof(lf->f))return NULL;\n*size=fread(lf->buff,1,sizeof(lf->buff),lf->f);\nreturn(*size>0)?lf->buff:NULL;\n}\nstatic int errfile(lua_State*L,const char*what,int fnameindex){\nconst char*serr=strerror(errno);\nconst char*filename=lua_tostring(L,fnameindex)+1;\nlua_pushfstring(L,\"cannot %s %s: %s\",what,filename,serr);\nlua_remove(L,fnameindex);\nreturn(5+1);\n}\nstatic int luaL_loadfile(lua_State*L,const char*filename){\nLoadF lf;\nint status,readstatus;\nint c;\nint fnameindex=lua_gettop(L)+1;\nlf.extraline=0;\nif(filename==NULL){\nlua_pushliteral(L,\"=stdin\");\nlf.f=stdin;\n}\nelse{\nlua_pushfstring(L,\"@%s\",filename);\nlf.f=fopen(filename,\"r\");\nif(lf.f==NULL)return errfile(L,\"open\",fnameindex);\n}\nc=getc(lf.f);\nif(c=='#'){\nlf.extraline=1;\nwhile((c=getc(lf.f))!=EOF&&c!='\\n');\nif(c=='\\n')c=getc(lf.f);\n}\nif(c==\"\\033Lua\"[0]&&filename){\nlf.f=freopen(filename,\"rb\",lf.f);\nif(lf.f==NULL)return errfile(L,\"reopen\",fnameindex);\nwhile((c=getc(lf.f))!=EOF&&c!=\"\\033Lua\"[0]);\nlf.extraline=0;\n}\nungetc(c,lf.f);\nstatus=lua_load(L,getF,&lf,lua_tostring(L,-1));\nreadstatus=ferror(lf.f);\nif(filename)fclose(lf.f);\nif(readstatus){\nlua_settop(L,fnameindex);\nreturn errfile(L,\"read\",fnameindex);\n}\nlua_remove(L,fnameindex);\nreturn status;\n}\ntypedef struct LoadS{\nconst char*s;\nsize_t size;\n}LoadS;\nstatic const char*getS(lua_State*L,void*ud,size_t*size){\nLoadS*ls=(LoadS*)ud;\n(void)L;\nif(ls->size==0)return NULL;\n*size=ls->size;\nls->size=0;\nreturn ls->s;\n}\nstatic int luaL_loadbuffer(lua_State*L,const char*buff,size_t size,\nconst char*name){\nLoadS ls;\nls.s=buff;\nls.size=size;\nreturn lua_load(L,getS,&ls,name);\n}\nstatic void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){\n(void)ud;\n(void)osize;\nif(nsize==0){\nfree(ptr);\nreturn NULL;\n}\nelse\nreturn realloc(ptr,nsize);\n}\nstatic int panic(lua_State*L){\n(void)L;\nfprintf(stderr,\"PANIC: unprotected error in call to Lua API (%s)\\n\",\nlua_tostring(L,-1));\nreturn 0;\n}\nstatic lua_State*luaL_newstate(void){\nlua_State*L=lua_newstate(l_alloc,NULL);\nif(L)lua_atpanic(L,&panic);\nreturn L;\n}\nstatic int luaB_tonumber(lua_State*L){\nint base=luaL_optint(L,2,10);\nif(base==10){\nluaL_checkany(L,1);\nif(lua_isnumber(L,1)){\nlua_pushnumber(L,lua_tonumber(L,1));\nreturn 1;\n}\n}\nelse{\nconst char*s1=luaL_checkstring(L,1);\nchar*s2;\nunsigned long n;\nluaL_argcheck(L,2<=base&&base<=36,2,\"base out of range\");\nn=strtoul(s1,&s2,base);\nif(s1!=s2){\nwhile(isspace((unsigned char)(*s2)))s2++;\nif(*s2=='\\0'){\nlua_pushnumber(L,(lua_Number)n);\nreturn 1;\n}\n}\n}\nlua_pushnil(L);\nreturn 1;\n}\nstatic int luaB_error(lua_State*L){\nint level=luaL_optint(L,2,1);\nlua_settop(L,1);\nif(lua_isstring(L,1)&&level>0){\nluaL_where(L,level);\nlua_pushvalue(L,1);\nlua_concat(L,2);\n}\nreturn lua_error(L);\n}\nstatic int luaB_setmetatable(lua_State*L){\nint t=lua_type(L,2);\nluaL_checktype(L,1,5);\nluaL_argcheck(L,t==0||t==5,2,\n\"nil or table expected\");\nif(luaL_getmetafield(L,1,\"__metatable\"))\nluaL_error(L,\"cannot change a protected metatable\");\nlua_settop(L,2);\nlua_setmetatable(L,1);\nreturn 1;\n}\nstatic void getfunc(lua_State*L,int opt){\nif(lua_isfunction(L,1))lua_pushvalue(L,1);\nelse{\nlua_Debug ar;\nint level=opt?luaL_optint(L,1,1):luaL_checkint(L,1);\nluaL_argcheck(L,level>=0,1,\"level must be non-negative\");\nif(lua_getstack(L,level,&ar)==0)\nluaL_argerror(L,1,\"invalid level\");\nlua_getinfo(L,\"f\",&ar);\nif(lua_isnil(L,-1))\nluaL_error(L,\"no function environment for tail call at level %d\",\nlevel);\n}\n}\nstatic int luaB_setfenv(lua_State*L){\nluaL_checktype(L,2,5);\ngetfunc(L,0);\nlua_pushvalue(L,2);\nif(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){\nlua_pushthread(L);\nlua_insert(L,-2);\nlua_setfenv(L,-2);\nreturn 0;\n}\nelse if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0)\nluaL_error(L,\nLUA_QL(\"setfenv\")\" cannot change environment of given object\");\nreturn 1;\n}\nstatic int luaB_rawget(lua_State*L){\nluaL_checktype(L,1,5);\nluaL_checkany(L,2);\nlua_settop(L,2);\nlua_rawget(L,1);\nreturn 1;\n}\nstatic int luaB_type(lua_State*L){\nluaL_checkany(L,1);\nlua_pushstring(L,luaL_typename(L,1));\nreturn 1;\n}\nstatic int luaB_next(lua_State*L){\nluaL_checktype(L,1,5);\nlua_settop(L,2);\nif(lua_next(L,1))\nreturn 2;\nelse{\nlua_pushnil(L);\nreturn 1;\n}\n}\nstatic int luaB_pairs(lua_State*L){\nluaL_checktype(L,1,5);\nlua_pushvalue(L,lua_upvalueindex(1));\nlua_pushvalue(L,1);\nlua_pushnil(L);\nreturn 3;\n}\nstatic int ipairsaux(lua_State*L){\nint i=luaL_checkint(L,2);\nluaL_checktype(L,1,5);\ni++;\nlua_pushinteger(L,i);\nlua_rawgeti(L,1,i);\nreturn(lua_isnil(L,-1))?0:2;\n}\nstatic int luaB_ipairs(lua_State*L){\nluaL_checktype(L,1,5);\nlua_pushvalue(L,lua_upvalueindex(1));\nlua_pushvalue(L,1);\nlua_pushinteger(L,0);\nreturn 3;\n}\nstatic int load_aux(lua_State*L,int status){\nif(status==0)\nreturn 1;\nelse{\nlua_pushnil(L);\nlua_insert(L,-2);\nreturn 2;\n}\n}\nstatic int luaB_loadstring(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nconst char*chunkname=luaL_optstring(L,2,s);\nreturn load_aux(L,luaL_loadbuffer(L,s,l,chunkname));\n}\nstatic int luaB_loadfile(lua_State*L){\nconst char*fname=luaL_optstring(L,1,NULL);\nreturn load_aux(L,luaL_loadfile(L,fname));\n}\nstatic int luaB_assert(lua_State*L){\nluaL_checkany(L,1);\nif(!lua_toboolean(L,1))\nreturn luaL_error(L,\"%s\",luaL_optstring(L,2,\"assertion failed!\"));\nreturn lua_gettop(L);\n}\nstatic int luaB_unpack(lua_State*L){\nint i,e,n;\nluaL_checktype(L,1,5);\ni=luaL_optint(L,2,1);\ne=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1));\nif(i>e)return 0;\nn=e-i+1;\nif(n<=0||!lua_checkstack(L,n))\nreturn luaL_error(L,\"too many results to unpack\");\nlua_rawgeti(L,1,i);\nwhile(i++<e)\nlua_rawgeti(L,1,i);\nreturn n;\n}\nstatic int luaB_pcall(lua_State*L){\nint status;\nluaL_checkany(L,1);\nstatus=lua_pcall(L,lua_gettop(L)-1,(-1),0);\nlua_pushboolean(L,(status==0));\nlua_insert(L,1);\nreturn lua_gettop(L);\n}\nstatic int luaB_newproxy(lua_State*L){\nlua_settop(L,1);\nlua_newuserdata(L,0);\nif(lua_toboolean(L,1)==0)\nreturn 1;\nelse if(lua_isboolean(L,1)){\nlua_newtable(L);\nlua_pushvalue(L,-1);\nlua_pushboolean(L,1);\nlua_rawset(L,lua_upvalueindex(1));\n}\nelse{\nint validproxy=0;\nif(lua_getmetatable(L,1)){\nlua_rawget(L,lua_upvalueindex(1));\nvalidproxy=lua_toboolean(L,-1);\nlua_pop(L,1);\n}\nluaL_argcheck(L,validproxy,1,\"boolean or proxy expected\");\nlua_getmetatable(L,1);\n}\nlua_setmetatable(L,2);\nreturn 1;\n}\nstatic const luaL_Reg base_funcs[]={\n{\"assert\",luaB_assert},\n{\"error\",luaB_error},\n{\"loadfile\",luaB_loadfile},\n{\"loadstring\",luaB_loadstring},\n{\"next\",luaB_next},\n{\"pcall\",luaB_pcall},\n{\"rawget\",luaB_rawget},\n{\"setfenv\",luaB_setfenv},\n{\"setmetatable\",luaB_setmetatable},\n{\"tonumber\",luaB_tonumber},\n{\"type\",luaB_type},\n{\"unpack\",luaB_unpack},\n{NULL,NULL}\n};\nstatic void auxopen(lua_State*L,const char*name,\nlua_CFunction f,lua_CFunction u){\nlua_pushcfunction(L,u);\nlua_pushcclosure(L,f,1);\nlua_setfield(L,-2,name);\n}\nstatic void base_open(lua_State*L){\nlua_pushvalue(L,(-10002));\nlua_setglobal(L,\"_G\");\nluaL_register(L,\"_G\",base_funcs);\nlua_pushliteral(L,\"Lua 5.1\");\nlua_setglobal(L,\"_VERSION\");\nauxopen(L,\"ipairs\",luaB_ipairs,ipairsaux);\nauxopen(L,\"pairs\",luaB_pairs,luaB_next);\nlua_createtable(L,0,1);\nlua_pushvalue(L,-1);\nlua_setmetatable(L,-2);\nlua_pushliteral(L,\"kv\");\nlua_setfield(L,-2,\"__mode\");\nlua_pushcclosure(L,luaB_newproxy,1);\nlua_setglobal(L,\"newproxy\");\n}\nstatic int luaopen_base(lua_State*L){\nbase_open(L);\nreturn 1;\n}\n#define aux_getn(L,n)(luaL_checktype(L,n,5),luaL_getn(L,n))\nstatic int tinsert(lua_State*L){\nint e=aux_getn(L,1)+1;\nint pos;\nswitch(lua_gettop(L)){\ncase 2:{\npos=e;\nbreak;\n}\ncase 3:{\nint i;\npos=luaL_checkint(L,2);\nif(pos>e)e=pos;\nfor(i=e;i>pos;i--){\nlua_rawgeti(L,1,i-1);\nlua_rawseti(L,1,i);\n}\nbreak;\n}\ndefault:{\nreturn luaL_error(L,\"wrong number of arguments to \"LUA_QL(\"insert\"));\n}\n}\nluaL_setn(L,1,e);\nlua_rawseti(L,1,pos);\nreturn 0;\n}\nstatic int tremove(lua_State*L){\nint e=aux_getn(L,1);\nint pos=luaL_optint(L,2,e);\nif(!(1<=pos&&pos<=e))\nreturn 0;\nluaL_setn(L,1,e-1);\nlua_rawgeti(L,1,pos);\nfor(;pos<e;pos++){\nlua_rawgeti(L,1,pos+1);\nlua_rawseti(L,1,pos);\n}\nlua_pushnil(L);\nlua_rawseti(L,1,e);\nreturn 1;\n}\nstatic void addfield(lua_State*L,luaL_Buffer*b,int i){\nlua_rawgeti(L,1,i);\nif(!lua_isstring(L,-1))\nluaL_error(L,\"invalid value (%s) at index %d in table for \"\nLUA_QL(\"concat\"),luaL_typename(L,-1),i);\nluaL_addvalue(b);\n}\nstatic int tconcat(lua_State*L){\nluaL_Buffer b;\nsize_t lsep;\nint i,last;\nconst char*sep=luaL_optlstring(L,2,\"\",&lsep);\nluaL_checktype(L,1,5);\ni=luaL_optint(L,3,1);\nlast=luaL_opt(L,luaL_checkint,4,luaL_getn(L,1));\nluaL_buffinit(L,&b);\nfor(;i<last;i++){\naddfield(L,&b,i);\nluaL_addlstring(&b,sep,lsep);\n}\nif(i==last)\naddfield(L,&b,i);\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic void set2(lua_State*L,int i,int j){\nlua_rawseti(L,1,i);\nlua_rawseti(L,1,j);\n}\nstatic int sort_comp(lua_State*L,int a,int b){\nif(!lua_isnil(L,2)){\nint res;\nlua_pushvalue(L,2);\nlua_pushvalue(L,a-1);\nlua_pushvalue(L,b-2);\nlua_call(L,2,1);\nres=lua_toboolean(L,-1);\nlua_pop(L,1);\nreturn res;\n}\nelse\nreturn lua_lessthan(L,a,b);\n}\nstatic void auxsort(lua_State*L,int l,int u){\nwhile(l<u){\nint i,j;\nlua_rawgeti(L,1,l);\nlua_rawgeti(L,1,u);\nif(sort_comp(L,-1,-2))\nset2(L,l,u);\nelse\nlua_pop(L,2);\nif(u-l==1)break;\ni=(l+u)/2;\nlua_rawgeti(L,1,i);\nlua_rawgeti(L,1,l);\nif(sort_comp(L,-2,-1))\nset2(L,i,l);\nelse{\nlua_pop(L,1);\nlua_rawgeti(L,1,u);\nif(sort_comp(L,-1,-2))\nset2(L,i,u);\nelse\nlua_pop(L,2);\n}\nif(u-l==2)break;\nlua_rawgeti(L,1,i);\nlua_pushvalue(L,-1);\nlua_rawgeti(L,1,u-1);\nset2(L,i,u-1);\ni=l;j=u-1;\nfor(;;){\nwhile(lua_rawgeti(L,1,++i),sort_comp(L,-1,-2)){\nif(i>u)luaL_error(L,\"invalid order function for sorting\");\nlua_pop(L,1);\n}\nwhile(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){\nif(j<l)luaL_error(L,\"invalid order function for sorting\");\nlua_pop(L,1);\n}\nif(j<i){\nlua_pop(L,3);\nbreak;\n}\nset2(L,i,j);\n}\nlua_rawgeti(L,1,u-1);\nlua_rawgeti(L,1,i);\nset2(L,u-1,i);\nif(i-l<u-i){\nj=l;i=i-1;l=i+2;\n}\nelse{\nj=i+1;i=u;u=j-2;\n}\nauxsort(L,j,i);\n}\n}\nstatic int sort(lua_State*L){\nint n=aux_getn(L,1);\nluaL_checkstack(L,40,\"\");\nif(!lua_isnoneornil(L,2))\nluaL_checktype(L,2,6);\nlua_settop(L,2);\nauxsort(L,1,n);\nreturn 0;\n}\nstatic const luaL_Reg tab_funcs[]={\n{\"concat\",tconcat},\n{\"insert\",tinsert},\n{\"remove\",tremove},\n{\"sort\",sort},\n{NULL,NULL}\n};\nstatic int luaopen_table(lua_State*L){\nluaL_register(L,\"table\",tab_funcs);\nreturn 1;\n}\nstatic const char*const fnames[]={\"input\",\"output\"};\nstatic int pushresult(lua_State*L,int i,const char*filename){\nint en=errno;\nif(i){\nlua_pushboolean(L,1);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nif(filename)\nlua_pushfstring(L,\"%s: %s\",filename,strerror(en));\nelse\nlua_pushfstring(L,\"%s\",strerror(en));\nlua_pushinteger(L,en);\nreturn 3;\n}\n}\nstatic void fileerror(lua_State*L,int arg,const char*filename){\nlua_pushfstring(L,\"%s: %s\",filename,strerror(errno));\nluaL_argerror(L,arg,lua_tostring(L,-1));\n}\n#define tofilep(L)((FILE**)luaL_checkudata(L,1,\"FILE*\"))\nstatic int io_type(lua_State*L){\nvoid*ud;\nluaL_checkany(L,1);\nud=lua_touserdata(L,1);\nlua_getfield(L,(-10000),\"FILE*\");\nif(ud==NULL||!lua_getmetatable(L,1)||!lua_rawequal(L,-2,-1))\nlua_pushnil(L);\nelse if(*((FILE**)ud)==NULL)\nlua_pushliteral(L,\"closed file\");\nelse\nlua_pushliteral(L,\"file\");\nreturn 1;\n}\nstatic FILE*tofile(lua_State*L){\nFILE**f=tofilep(L);\nif(*f==NULL)\nluaL_error(L,\"attempt to use a closed file\");\nreturn*f;\n}\nstatic FILE**newfile(lua_State*L){\nFILE**pf=(FILE**)lua_newuserdata(L,sizeof(FILE*));\n*pf=NULL;\nluaL_getmetatable(L,\"FILE*\");\nlua_setmetatable(L,-2);\nreturn pf;\n}\nstatic int io_noclose(lua_State*L){\nlua_pushnil(L);\nlua_pushliteral(L,\"cannot close standard file\");\nreturn 2;\n}\nstatic int io_pclose(lua_State*L){\nFILE**p=tofilep(L);\nint ok=lua_pclose(L,*p);\n*p=NULL;\nreturn pushresult(L,ok,NULL);\n}\nstatic int io_fclose(lua_State*L){\nFILE**p=tofilep(L);\nint ok=(fclose(*p)==0);\n*p=NULL;\nreturn pushresult(L,ok,NULL);\n}\nstatic int aux_close(lua_State*L){\nlua_getfenv(L,1);\nlua_getfield(L,-1,\"__close\");\nreturn(lua_tocfunction(L,-1))(L);\n}\nstatic int io_close(lua_State*L){\nif(lua_isnone(L,1))\nlua_rawgeti(L,(-10001),2);\ntofile(L);\nreturn aux_close(L);\n}\nstatic int io_gc(lua_State*L){\nFILE*f=*tofilep(L);\nif(f!=NULL)\naux_close(L);\nreturn 0;\n}\nstatic int io_open(lua_State*L){\nconst char*filename=luaL_checkstring(L,1);\nconst char*mode=luaL_optstring(L,2,\"r\");\nFILE**pf=newfile(L);\n*pf=fopen(filename,mode);\nreturn(*pf==NULL)?pushresult(L,0,filename):1;\n}\nstatic FILE*getiofile(lua_State*L,int findex){\nFILE*f;\nlua_rawgeti(L,(-10001),findex);\nf=*(FILE**)lua_touserdata(L,-1);\nif(f==NULL)\nluaL_error(L,\"standard %s file is closed\",fnames[findex-1]);\nreturn f;\n}\nstatic int g_iofile(lua_State*L,int f,const char*mode){\nif(!lua_isnoneornil(L,1)){\nconst char*filename=lua_tostring(L,1);\nif(filename){\nFILE**pf=newfile(L);\n*pf=fopen(filename,mode);\nif(*pf==NULL)\nfileerror(L,1,filename);\n}\nelse{\ntofile(L);\nlua_pushvalue(L,1);\n}\nlua_rawseti(L,(-10001),f);\n}\nlua_rawgeti(L,(-10001),f);\nreturn 1;\n}\nstatic int io_input(lua_State*L){\nreturn g_iofile(L,1,\"r\");\n}\nstatic int io_output(lua_State*L){\nreturn g_iofile(L,2,\"w\");\n}\nstatic int io_readline(lua_State*L);\nstatic void aux_lines(lua_State*L,int idx,int toclose){\nlua_pushvalue(L,idx);\nlua_pushboolean(L,toclose);\nlua_pushcclosure(L,io_readline,2);\n}\nstatic int f_lines(lua_State*L){\ntofile(L);\naux_lines(L,1,0);\nreturn 1;\n}\nstatic int io_lines(lua_State*L){\nif(lua_isnoneornil(L,1)){\nlua_rawgeti(L,(-10001),1);\nreturn f_lines(L);\n}\nelse{\nconst char*filename=luaL_checkstring(L,1);\nFILE**pf=newfile(L);\n*pf=fopen(filename,\"r\");\nif(*pf==NULL)\nfileerror(L,1,filename);\naux_lines(L,lua_gettop(L),1);\nreturn 1;\n}\n}\nstatic int read_number(lua_State*L,FILE*f){\nlua_Number d;\nif(fscanf(f,\"%lf\",&d)==1){\nlua_pushnumber(L,d);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nreturn 0;\n}\n}\nstatic int test_eof(lua_State*L,FILE*f){\nint c=getc(f);\nungetc(c,f);\nlua_pushlstring(L,NULL,0);\nreturn(c!=EOF);\n}\nstatic int read_line(lua_State*L,FILE*f){\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nfor(;;){\nsize_t l;\nchar*p=luaL_prepbuffer(&b);\nif(fgets(p,BUFSIZ,f)==NULL){\nluaL_pushresult(&b);\nreturn(lua_objlen(L,-1)>0);\n}\nl=strlen(p);\nif(l==0||p[l-1]!='\\n')\nluaL_addsize(&b,l);\nelse{\nluaL_addsize(&b,l-1);\nluaL_pushresult(&b);\nreturn 1;\n}\n}\n}\nstatic int read_chars(lua_State*L,FILE*f,size_t n){\nsize_t rlen;\nsize_t nr;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nrlen=BUFSIZ;\ndo{\nchar*p=luaL_prepbuffer(&b);\nif(rlen>n)rlen=n;\nnr=fread(p,sizeof(char),rlen,f);\nluaL_addsize(&b,nr);\nn-=nr;\n}while(n>0&&nr==rlen);\nluaL_pushresult(&b);\nreturn(n==0||lua_objlen(L,-1)>0);\n}\nstatic int g_read(lua_State*L,FILE*f,int first){\nint nargs=lua_gettop(L)-1;\nint success;\nint n;\nclearerr(f);\nif(nargs==0){\nsuccess=read_line(L,f);\nn=first+1;\n}\nelse{\nluaL_checkstack(L,nargs+20,\"too many arguments\");\nsuccess=1;\nfor(n=first;nargs--&&success;n++){\nif(lua_type(L,n)==3){\nsize_t l=(size_t)lua_tointeger(L,n);\nsuccess=(l==0)?test_eof(L,f):read_chars(L,f,l);\n}\nelse{\nconst char*p=lua_tostring(L,n);\nluaL_argcheck(L,p&&p[0]=='*',n,\"invalid option\");\nswitch(p[1]){\ncase'n':\nsuccess=read_number(L,f);\nbreak;\ncase'l':\nsuccess=read_line(L,f);\nbreak;\ncase'a':\nread_chars(L,f,~((size_t)0));\nsuccess=1;\nbreak;\ndefault:\nreturn luaL_argerror(L,n,\"invalid format\");\n}\n}\n}\n}\nif(ferror(f))\nreturn pushresult(L,0,NULL);\nif(!success){\nlua_pop(L,1);\nlua_pushnil(L);\n}\nreturn n-first;\n}\nstatic int io_read(lua_State*L){\nreturn g_read(L,getiofile(L,1),1);\n}\nstatic int f_read(lua_State*L){\nreturn g_read(L,tofile(L),2);\n}\nstatic int io_readline(lua_State*L){\nFILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1));\nint sucess;\nif(f==NULL)\nluaL_error(L,\"file is already closed\");\nsucess=read_line(L,f);\nif(ferror(f))\nreturn luaL_error(L,\"%s\",strerror(errno));\nif(sucess)return 1;\nelse{\nif(lua_toboolean(L,lua_upvalueindex(2))){\nlua_settop(L,0);\nlua_pushvalue(L,lua_upvalueindex(1));\naux_close(L);\n}\nreturn 0;\n}\n}\nstatic int g_write(lua_State*L,FILE*f,int arg){\nint nargs=lua_gettop(L)-1;\nint status=1;\nfor(;nargs--;arg++){\nif(lua_type(L,arg)==3){\nstatus=status&&\nfprintf(f,\"%.14g\",lua_tonumber(L,arg))>0;\n}\nelse{\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nstatus=status&&(fwrite(s,sizeof(char),l,f)==l);\n}\n}\nreturn pushresult(L,status,NULL);\n}\nstatic int io_write(lua_State*L){\nreturn g_write(L,getiofile(L,2),1);\n}\nstatic int f_write(lua_State*L){\nreturn g_write(L,tofile(L),2);\n}\nstatic int io_flush(lua_State*L){\nreturn pushresult(L,fflush(getiofile(L,2))==0,NULL);\n}\nstatic int f_flush(lua_State*L){\nreturn pushresult(L,fflush(tofile(L))==0,NULL);\n}\nstatic const luaL_Reg iolib[]={\n{\"close\",io_close},\n{\"flush\",io_flush},\n{\"input\",io_input},\n{\"lines\",io_lines},\n{\"open\",io_open},\n{\"output\",io_output},\n{\"read\",io_read},\n{\"type\",io_type},\n{\"write\",io_write},\n{NULL,NULL}\n};\nstatic const luaL_Reg flib[]={\n{\"close\",io_close},\n{\"flush\",f_flush},\n{\"lines\",f_lines},\n{\"read\",f_read},\n{\"write\",f_write},\n{\"__gc\",io_gc},\n{NULL,NULL}\n};\nstatic void createmeta(lua_State*L){\nluaL_newmetatable(L,\"FILE*\");\nlua_pushvalue(L,-1);\nlua_setfield(L,-2,\"__index\");\nluaL_register(L,NULL,flib);\n}\nstatic void createstdfile(lua_State*L,FILE*f,int k,const char*fname){\n*newfile(L)=f;\nif(k>0){\nlua_pushvalue(L,-1);\nlua_rawseti(L,(-10001),k);\n}\nlua_pushvalue(L,-2);\nlua_setfenv(L,-2);\nlua_setfield(L,-3,fname);\n}\nstatic void newfenv(lua_State*L,lua_CFunction cls){\nlua_createtable(L,0,1);\nlua_pushcfunction(L,cls);\nlua_setfield(L,-2,\"__close\");\n}\nstatic int luaopen_io(lua_State*L){\ncreatemeta(L);\nnewfenv(L,io_fclose);\nlua_replace(L,(-10001));\nluaL_register(L,\"io\",iolib);\nnewfenv(L,io_noclose);\ncreatestdfile(L,stdin,1,\"stdin\");\ncreatestdfile(L,stdout,2,\"stdout\");\ncreatestdfile(L,stderr,0,\"stderr\");\nlua_pop(L,1);\nlua_getfield(L,-1,\"popen\");\nnewfenv(L,io_pclose);\nlua_setfenv(L,-2);\nlua_pop(L,1);\nreturn 1;\n}\nstatic int os_pushresult(lua_State*L,int i,const char*filename){\nint en=errno;\nif(i){\nlua_pushboolean(L,1);\nreturn 1;\n}\nelse{\nlua_pushnil(L);\nlua_pushfstring(L,\"%s: %s\",filename,strerror(en));\nlua_pushinteger(L,en);\nreturn 3;\n}\n}\nstatic int os_remove(lua_State*L){\nconst char*filename=luaL_checkstring(L,1);\nreturn os_pushresult(L,remove(filename)==0,filename);\n}\nstatic int os_exit(lua_State*L){\nexit(luaL_optint(L,1,EXIT_SUCCESS));\n}\nstatic const luaL_Reg syslib[]={\n{\"exit\",os_exit},\n{\"remove\",os_remove},\n{NULL,NULL}\n};\nstatic int luaopen_os(lua_State*L){\nluaL_register(L,\"os\",syslib);\nreturn 1;\n}\n#define uchar(c)((unsigned char)(c))\nstatic ptrdiff_t posrelat(ptrdiff_t pos,size_t len){\nif(pos<0)pos+=(ptrdiff_t)len+1;\nreturn(pos>=0)?pos:0;\n}\nstatic int str_sub(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nptrdiff_t start=posrelat(luaL_checkinteger(L,2),l);\nptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l);\nif(start<1)start=1;\nif(end>(ptrdiff_t)l)end=(ptrdiff_t)l;\nif(start<=end)\nlua_pushlstring(L,s+start-1,end-start+1);\nelse lua_pushliteral(L,\"\");\nreturn 1;\n}\nstatic int str_lower(lua_State*L){\nsize_t l;\nsize_t i;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nluaL_buffinit(L,&b);\nfor(i=0;i<l;i++)\nluaL_addchar(&b,tolower(uchar(s[i])));\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_upper(lua_State*L){\nsize_t l;\nsize_t i;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nluaL_buffinit(L,&b);\nfor(i=0;i<l;i++)\nluaL_addchar(&b,toupper(uchar(s[i])));\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_rep(lua_State*L){\nsize_t l;\nluaL_Buffer b;\nconst char*s=luaL_checklstring(L,1,&l);\nint n=luaL_checkint(L,2);\nluaL_buffinit(L,&b);\nwhile(n-->0)\nluaL_addlstring(&b,s,l);\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic int str_byte(lua_State*L){\nsize_t l;\nconst char*s=luaL_checklstring(L,1,&l);\nptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l);\nptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l);\nint n,i;\nif(posi<=0)posi=1;\nif((size_t)pose>l)pose=l;\nif(posi>pose)return 0;\nn=(int)(pose-posi+1);\nif(posi+n<=pose)\nluaL_error(L,\"string slice too long\");\nluaL_checkstack(L,n,\"string slice too long\");\nfor(i=0;i<n;i++)\nlua_pushinteger(L,uchar(s[posi+i-1]));\nreturn n;\n}\nstatic int str_char(lua_State*L){\nint n=lua_gettop(L);\nint i;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nfor(i=1;i<=n;i++){\nint c=luaL_checkint(L,i);\nluaL_argcheck(L,uchar(c)==c,i,\"invalid value\");\nluaL_addchar(&b,uchar(c));\n}\nluaL_pushresult(&b);\nreturn 1;\n}\ntypedef struct MatchState{\nconst char*src_init;\nconst char*src_end;\nlua_State*L;\nint level;\nstruct{\nconst char*init;\nptrdiff_t len;\n}capture[32];\n}MatchState;\nstatic int check_capture(MatchState*ms,int l){\nl-='1';\nif(l<0||l>=ms->level||ms->capture[l].len==(-1))\nreturn luaL_error(ms->L,\"invalid capture index\");\nreturn l;\n}\nstatic int capture_to_close(MatchState*ms){\nint level=ms->level;\nfor(level--;level>=0;level--)\nif(ms->capture[level].len==(-1))return level;\nreturn luaL_error(ms->L,\"invalid pattern capture\");\n}\nstatic const char*classend(MatchState*ms,const char*p){\nswitch(*p++){\ncase'%':{\nif(*p=='\\0')\nluaL_error(ms->L,\"malformed pattern (ends with \"LUA_QL(\"%%\")\")\");\nreturn p+1;\n}\ncase'[':{\nif(*p=='^')p++;\ndo{\nif(*p=='\\0')\nluaL_error(ms->L,\"malformed pattern (missing \"LUA_QL(\"]\")\")\");\nif(*(p++)=='%'&&*p!='\\0')\np++;\n}while(*p!=']');\nreturn p+1;\n}\ndefault:{\nreturn p;\n}\n}\n}\nstatic int match_class(int c,int cl){\nint res;\nswitch(tolower(cl)){\ncase'a':res=isalpha(c);break;\ncase'c':res=iscntrl(c);break;\ncase'd':res=isdigit(c);break;\ncase'l':res=islower(c);break;\ncase'p':res=ispunct(c);break;\ncase's':res=isspace(c);break;\ncase'u':res=isupper(c);break;\ncase'w':res=isalnum(c);break;\ncase'x':res=isxdigit(c);break;\ncase'z':res=(c==0);break;\ndefault:return(cl==c);\n}\nreturn(islower(cl)?res:!res);\n}\nstatic int matchbracketclass(int c,const char*p,const char*ec){\nint sig=1;\nif(*(p+1)=='^'){\nsig=0;\np++;\n}\nwhile(++p<ec){\nif(*p=='%'){\np++;\nif(match_class(c,uchar(*p)))\nreturn sig;\n}\nelse if((*(p+1)=='-')&&(p+2<ec)){\np+=2;\nif(uchar(*(p-2))<=c&&c<=uchar(*p))\nreturn sig;\n}\nelse if(uchar(*p)==c)return sig;\n}\nreturn!sig;\n}\nstatic int singlematch(int c,const char*p,const char*ep){\nswitch(*p){\ncase'.':return 1;\ncase'%':return match_class(c,uchar(*(p+1)));\ncase'[':return matchbracketclass(c,p,ep-1);\ndefault:return(uchar(*p)==c);\n}\n}\nstatic const char*match(MatchState*ms,const char*s,const char*p);\nstatic const char*matchbalance(MatchState*ms,const char*s,\nconst char*p){\nif(*p==0||*(p+1)==0)\nluaL_error(ms->L,\"unbalanced pattern\");\nif(*s!=*p)return NULL;\nelse{\nint b=*p;\nint e=*(p+1);\nint cont=1;\nwhile(++s<ms->src_end){\nif(*s==e){\nif(--cont==0)return s+1;\n}\nelse if(*s==b)cont++;\n}\n}\nreturn NULL;\n}\nstatic const char*max_expand(MatchState*ms,const char*s,\nconst char*p,const char*ep){\nptrdiff_t i=0;\nwhile((s+i)<ms->src_end&&singlematch(uchar(*(s+i)),p,ep))\ni++;\nwhile(i>=0){\nconst char*res=match(ms,(s+i),ep+1);\nif(res)return res;\ni--;\n}\nreturn NULL;\n}\nstatic const char*min_expand(MatchState*ms,const char*s,\nconst char*p,const char*ep){\nfor(;;){\nconst char*res=match(ms,s,ep+1);\nif(res!=NULL)\nreturn res;\nelse if(s<ms->src_end&&singlematch(uchar(*s),p,ep))\ns++;\nelse return NULL;\n}\n}\nstatic const char*start_capture(MatchState*ms,const char*s,\nconst char*p,int what){\nconst char*res;\nint level=ms->level;\nif(level>=32)luaL_error(ms->L,\"too many captures\");\nms->capture[level].init=s;\nms->capture[level].len=what;\nms->level=level+1;\nif((res=match(ms,s,p))==NULL)\nms->level--;\nreturn res;\n}\nstatic const char*end_capture(MatchState*ms,const char*s,\nconst char*p){\nint l=capture_to_close(ms);\nconst char*res;\nms->capture[l].len=s-ms->capture[l].init;\nif((res=match(ms,s,p))==NULL)\nms->capture[l].len=(-1);\nreturn res;\n}\nstatic const char*match_capture(MatchState*ms,const char*s,int l){\nsize_t len;\nl=check_capture(ms,l);\nlen=ms->capture[l].len;\nif((size_t)(ms->src_end-s)>=len&&\nmemcmp(ms->capture[l].init,s,len)==0)\nreturn s+len;\nelse return NULL;\n}\nstatic const char*match(MatchState*ms,const char*s,const char*p){\ninit:\nswitch(*p){\ncase'(':{\nif(*(p+1)==')')\nreturn start_capture(ms,s,p+2,(-2));\nelse\nreturn start_capture(ms,s,p+1,(-1));\n}\ncase')':{\nreturn end_capture(ms,s,p+1);\n}\ncase'%':{\nswitch(*(p+1)){\ncase'b':{\ns=matchbalance(ms,s,p+2);\nif(s==NULL)return NULL;\np+=4;goto init;\n}\ncase'f':{\nconst char*ep;char previous;\np+=2;\nif(*p!='[')\nluaL_error(ms->L,\"missing \"LUA_QL(\"[\")\" after \"\nLUA_QL(\"%%f\")\" in pattern\");\nep=classend(ms,p);\nprevious=(s==ms->src_init)?'\\0':*(s-1);\nif(matchbracketclass(uchar(previous),p,ep-1)||\n!matchbracketclass(uchar(*s),p,ep-1))return NULL;\np=ep;goto init;\n}\ndefault:{\nif(isdigit(uchar(*(p+1)))){\ns=match_capture(ms,s,uchar(*(p+1)));\nif(s==NULL)return NULL;\np+=2;goto init;\n}\ngoto dflt;\n}\n}\n}\ncase'\\0':{\nreturn s;\n}\ncase'$':{\nif(*(p+1)=='\\0')\nreturn(s==ms->src_end)?s:NULL;\nelse goto dflt;\n}\ndefault:dflt:{\nconst char*ep=classend(ms,p);\nint m=s<ms->src_end&&singlematch(uchar(*s),p,ep);\nswitch(*ep){\ncase'?':{\nconst char*res;\nif(m&&((res=match(ms,s+1,ep+1))!=NULL))\nreturn res;\np=ep+1;goto init;\n}\ncase'*':{\nreturn max_expand(ms,s,p,ep);\n}\ncase'+':{\nreturn(m?max_expand(ms,s+1,p,ep):NULL);\n}\ncase'-':{\nreturn min_expand(ms,s,p,ep);\n}\ndefault:{\nif(!m)return NULL;\ns++;p=ep;goto init;\n}\n}\n}\n}\n}\nstatic const char*lmemfind(const char*s1,size_t l1,\nconst char*s2,size_t l2){\nif(l2==0)return s1;\nelse if(l2>l1)return NULL;\nelse{\nconst char*init;\nl2--;\nl1=l1-l2;\nwhile(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){\ninit++;\nif(memcmp(init,s2+1,l2)==0)\nreturn init-1;\nelse{\nl1-=init-s1;\ns1=init;\n}\n}\nreturn NULL;\n}\n}\nstatic void push_onecapture(MatchState*ms,int i,const char*s,\nconst char*e){\nif(i>=ms->level){\nif(i==0)\nlua_pushlstring(ms->L,s,e-s);\nelse\nluaL_error(ms->L,\"invalid capture index\");\n}\nelse{\nptrdiff_t l=ms->capture[i].len;\nif(l==(-1))luaL_error(ms->L,\"unfinished capture\");\nif(l==(-2))\nlua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1);\nelse\nlua_pushlstring(ms->L,ms->capture[i].init,l);\n}\n}\nstatic int push_captures(MatchState*ms,const char*s,const char*e){\nint i;\nint nlevels=(ms->level==0&&s)?1:ms->level;\nluaL_checkstack(ms->L,nlevels,\"too many captures\");\nfor(i=0;i<nlevels;i++)\npush_onecapture(ms,i,s,e);\nreturn nlevels;\n}\nstatic int str_find_aux(lua_State*L,int find){\nsize_t l1,l2;\nconst char*s=luaL_checklstring(L,1,&l1);\nconst char*p=luaL_checklstring(L,2,&l2);\nptrdiff_t init=posrelat(luaL_optinteger(L,3,1),l1)-1;\nif(init<0)init=0;\nelse if((size_t)(init)>l1)init=(ptrdiff_t)l1;\nif(find&&(lua_toboolean(L,4)||\nstrpbrk(p,\"^$*+?.([%-\")==NULL)){\nconst char*s2=lmemfind(s+init,l1-init,p,l2);\nif(s2){\nlua_pushinteger(L,s2-s+1);\nlua_pushinteger(L,s2-s+l2);\nreturn 2;\n}\n}\nelse{\nMatchState ms;\nint anchor=(*p=='^')?(p++,1):0;\nconst char*s1=s+init;\nms.L=L;\nms.src_init=s;\nms.src_end=s+l1;\ndo{\nconst char*res;\nms.level=0;\nif((res=match(&ms,s1,p))!=NULL){\nif(find){\nlua_pushinteger(L,s1-s+1);\nlua_pushinteger(L,res-s);\nreturn push_captures(&ms,NULL,0)+2;\n}\nelse\nreturn push_captures(&ms,s1,res);\n}\n}while(s1++<ms.src_end&&!anchor);\n}\nlua_pushnil(L);\nreturn 1;\n}\nstatic int str_find(lua_State*L){\nreturn str_find_aux(L,1);\n}\nstatic int str_match(lua_State*L){\nreturn str_find_aux(L,0);\n}\nstatic int gmatch_aux(lua_State*L){\nMatchState ms;\nsize_t ls;\nconst char*s=lua_tolstring(L,lua_upvalueindex(1),&ls);\nconst char*p=lua_tostring(L,lua_upvalueindex(2));\nconst char*src;\nms.L=L;\nms.src_init=s;\nms.src_end=s+ls;\nfor(src=s+(size_t)lua_tointeger(L,lua_upvalueindex(3));\nsrc<=ms.src_end;\nsrc++){\nconst char*e;\nms.level=0;\nif((e=match(&ms,src,p))!=NULL){\nlua_Integer newstart=e-s;\nif(e==src)newstart++;\nlua_pushinteger(L,newstart);\nlua_replace(L,lua_upvalueindex(3));\nreturn push_captures(&ms,src,e);\n}\n}\nreturn 0;\n}\nstatic int gmatch(lua_State*L){\nluaL_checkstring(L,1);\nluaL_checkstring(L,2);\nlua_settop(L,2);\nlua_pushinteger(L,0);\nlua_pushcclosure(L,gmatch_aux,3);\nreturn 1;\n}\nstatic void add_s(MatchState*ms,luaL_Buffer*b,const char*s,\nconst char*e){\nsize_t l,i;\nconst char*news=lua_tolstring(ms->L,3,&l);\nfor(i=0;i<l;i++){\nif(news[i]!='%')\nluaL_addchar(b,news[i]);\nelse{\ni++;\nif(!isdigit(uchar(news[i])))\nluaL_addchar(b,news[i]);\nelse if(news[i]=='0')\nluaL_addlstring(b,s,e-s);\nelse{\npush_onecapture(ms,news[i]-'1',s,e);\nluaL_addvalue(b);\n}\n}\n}\n}\nstatic void add_value(MatchState*ms,luaL_Buffer*b,const char*s,\nconst char*e){\nlua_State*L=ms->L;\nswitch(lua_type(L,3)){\ncase 3:\ncase 4:{\nadd_s(ms,b,s,e);\nreturn;\n}\ncase 6:{\nint n;\nlua_pushvalue(L,3);\nn=push_captures(ms,s,e);\nlua_call(L,n,1);\nbreak;\n}\ncase 5:{\npush_onecapture(ms,0,s,e);\nlua_gettable(L,3);\nbreak;\n}\n}\nif(!lua_toboolean(L,-1)){\nlua_pop(L,1);\nlua_pushlstring(L,s,e-s);\n}\nelse if(!lua_isstring(L,-1))\nluaL_error(L,\"invalid replacement value (a %s)\",luaL_typename(L,-1));\nluaL_addvalue(b);\n}\nstatic int str_gsub(lua_State*L){\nsize_t srcl;\nconst char*src=luaL_checklstring(L,1,&srcl);\nconst char*p=luaL_checkstring(L,2);\nint tr=lua_type(L,3);\nint max_s=luaL_optint(L,4,srcl+1);\nint anchor=(*p=='^')?(p++,1):0;\nint n=0;\nMatchState ms;\nluaL_Buffer b;\nluaL_argcheck(L,tr==3||tr==4||\ntr==6||tr==5,3,\n\"string/function/table expected\");\nluaL_buffinit(L,&b);\nms.L=L;\nms.src_init=src;\nms.src_end=src+srcl;\nwhile(n<max_s){\nconst char*e;\nms.level=0;\ne=match(&ms,src,p);\nif(e){\nn++;\nadd_value(&ms,&b,src,e);\n}\nif(e&&e>src)\nsrc=e;\nelse if(src<ms.src_end)\nluaL_addchar(&b,*src++);\nelse break;\nif(anchor)break;\n}\nluaL_addlstring(&b,src,ms.src_end-src);\nluaL_pushresult(&b);\nlua_pushinteger(L,n);\nreturn 2;\n}\nstatic void addquoted(lua_State*L,luaL_Buffer*b,int arg){\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nluaL_addchar(b,'\"');\nwhile(l--){\nswitch(*s){\ncase'\"':case'\\\\':case'\\n':{\nluaL_addchar(b,'\\\\');\nluaL_addchar(b,*s);\nbreak;\n}\ncase'\\r':{\nluaL_addlstring(b,\"\\\\r\",2);\nbreak;\n}\ncase'\\0':{\nluaL_addlstring(b,\"\\\\000\",4);\nbreak;\n}\ndefault:{\nluaL_addchar(b,*s);\nbreak;\n}\n}\ns++;\n}\nluaL_addchar(b,'\"');\n}\nstatic const char*scanformat(lua_State*L,const char*strfrmt,char*form){\nconst char*p=strfrmt;\nwhile(*p!='\\0'&&strchr(\"-+ #0\",*p)!=NULL)p++;\nif((size_t)(p-strfrmt)>=sizeof(\"-+ #0\"))\nluaL_error(L,\"invalid format (repeated flags)\");\nif(isdigit(uchar(*p)))p++;\nif(isdigit(uchar(*p)))p++;\nif(*p=='.'){\np++;\nif(isdigit(uchar(*p)))p++;\nif(isdigit(uchar(*p)))p++;\n}\nif(isdigit(uchar(*p)))\nluaL_error(L,\"invalid format (width or precision too long)\");\n*(form++)='%';\nstrncpy(form,strfrmt,p-strfrmt+1);\nform+=p-strfrmt+1;\n*form='\\0';\nreturn p;\n}\nstatic void addintlen(char*form){\nsize_t l=strlen(form);\nchar spec=form[l-1];\nstrcpy(form+l-1,\"l\");\nform[l+sizeof(\"l\")-2]=spec;\nform[l+sizeof(\"l\")-1]='\\0';\n}\nstatic int str_format(lua_State*L){\nint top=lua_gettop(L);\nint arg=1;\nsize_t sfl;\nconst char*strfrmt=luaL_checklstring(L,arg,&sfl);\nconst char*strfrmt_end=strfrmt+sfl;\nluaL_Buffer b;\nluaL_buffinit(L,&b);\nwhile(strfrmt<strfrmt_end){\nif(*strfrmt!='%')\nluaL_addchar(&b,*strfrmt++);\nelse if(*++strfrmt=='%')\nluaL_addchar(&b,*strfrmt++);\nelse{\nchar form[(sizeof(\"-+ #0\")+sizeof(\"l\")+10)];\nchar buff[512];\nif(++arg>top)\nluaL_argerror(L,arg,\"no value\");\nstrfrmt=scanformat(L,strfrmt,form);\nswitch(*strfrmt++){\ncase'c':{\nsprintf(buff,form,(int)luaL_checknumber(L,arg));\nbreak;\n}\ncase'd':case'i':{\naddintlen(form);\nsprintf(buff,form,(long)luaL_checknumber(L,arg));\nbreak;\n}\ncase'o':case'u':case'x':case'X':{\naddintlen(form);\nsprintf(buff,form,(unsigned long)luaL_checknumber(L,arg));\nbreak;\n}\ncase'e':case'E':case'f':\ncase'g':case'G':{\nsprintf(buff,form,(double)luaL_checknumber(L,arg));\nbreak;\n}\ncase'q':{\naddquoted(L,&b,arg);\ncontinue;\n}\ncase's':{\nsize_t l;\nconst char*s=luaL_checklstring(L,arg,&l);\nif(!strchr(form,'.')&&l>=100){\nlua_pushvalue(L,arg);\nluaL_addvalue(&b);\ncontinue;\n}\nelse{\nsprintf(buff,form,s);\nbreak;\n}\n}\ndefault:{\nreturn luaL_error(L,\"invalid option \"LUA_QL(\"%%%c\")\" to \"\nLUA_QL(\"format\"),*(strfrmt-1));\n}\n}\nluaL_addlstring(&b,buff,strlen(buff));\n}\n}\nluaL_pushresult(&b);\nreturn 1;\n}\nstatic const luaL_Reg strlib[]={\n{\"byte\",str_byte},\n{\"char\",str_char},\n{\"find\",str_find},\n{\"format\",str_format},\n{\"gmatch\",gmatch},\n{\"gsub\",str_gsub},\n{\"lower\",str_lower},\n{\"match\",str_match},\n{\"rep\",str_rep},\n{\"sub\",str_sub},\n{\"upper\",str_upper},\n{NULL,NULL}\n};\nstatic void createmetatable(lua_State*L){\nlua_createtable(L,0,1);\nlua_pushliteral(L,\"\");\nlua_pushvalue(L,-2);\nlua_setmetatable(L,-2);\nlua_pop(L,1);\nlua_pushvalue(L,-2);\nlua_setfield(L,-2,\"__index\");\nlua_pop(L,1);\n}\nstatic int luaopen_string(lua_State*L){\nluaL_register(L,\"string\",strlib);\ncreatemetatable(L);\nreturn 1;\n}\nstatic const luaL_Reg lualibs[]={\n{\"\",luaopen_base},\n{\"table\",luaopen_table},\n{\"io\",luaopen_io},\n{\"os\",luaopen_os},\n{\"string\",luaopen_string},\n{NULL,NULL}\n};\nstatic void luaL_openlibs(lua_State*L){\nconst luaL_Reg*lib=lualibs;\nfor(;lib->func;lib++){\nlua_pushcfunction(L,lib->func);\nlua_pushstring(L,lib->name);\nlua_call(L,1,0);\n}\n}\ntypedef unsigned int UB;\nstatic UB barg(lua_State*L,int idx){\nunion{lua_Number n;U64 b;}bn;\nbn.n=lua_tonumber(L,idx)+6755399441055744.0;\nif(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,\"number\");\nreturn(UB)bn.b;\n}\n#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1;\nstatic int tobit(lua_State*L){\nBRET(barg(L,1))}\nstatic int bnot(lua_State*L){\nBRET(~barg(L,1))}\nstatic int band(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}\nstatic int bor(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}\nstatic int bxor(lua_State*L){\nint i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}\nstatic int lshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}\nstatic int rshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}\nstatic int arshift(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}\nstatic int rol(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}\nstatic int ror(lua_State*L){\nUB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}\nstatic int bswap(lua_State*L){\nUB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}\nstatic int tohex(lua_State*L){\nUB b=barg(L,1);\nint n=lua_isnone(L,2)?8:(int)barg(L,2);\nconst char*hexdigits=\"0123456789abcdef\";\nchar buf[8];\nint i;\nif(n<0){n=-n;hexdigits=\"0123456789ABCDEF\";}\nif(n>8)n=8;\nfor(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}\nlua_pushlstring(L,buf,(size_t)n);\nreturn 1;\n}\nstatic const struct luaL_Reg bitlib[]={\n{\"tobit\",tobit},\n{\"bnot\",bnot},\n{\"band\",band},\n{\"bor\",bor},\n{\"bxor\",bxor},\n{\"lshift\",lshift},\n{\"rshift\",rshift},\n{\"arshift\",arshift},\n{\"rol\",rol},\n{\"ror\",ror},\n{\"bswap\",bswap},\n{\"tohex\",tohex},\n{NULL,NULL}\n};\nint main(int argc,char**argv){\nlua_State*L=luaL_newstate();\nint i;\nluaL_openlibs(L);\nluaL_register(L,\"bit\",bitlib);\nif(argc<2)return sizeof(void*);\nlua_createtable(L,0,1);\nlua_pushstring(L,argv[1]);\nlua_rawseti(L,-2,0);\nlua_setglobal(L,\"arg\");\nif(luaL_loadfile(L,argv[1]))\ngoto err;\nfor(i=2;i<argc;i++)\nlua_pushstring(L,argv[i]);\nif(lua_pcall(L,argc-2,0,0)){\nerr:\nfprintf(stderr,\"Error: %s\\n\",lua_tostring(L,-1));\nreturn 1;\n}\nlua_close(L);\nreturn 0;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/.gitignore",
    "content": "vmdef.lua\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/bc.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT bytecode listing module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module lists the bytecode of a Lua function. If it's loaded by -jbc\n-- it hooks into the parser and lists all functions of a chunk as they\n-- are parsed.\n--\n-- Example usage:\n--\n--   luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; print(x)'\n--   luajit -jbc=- foo.lua\n--   luajit -jbc=foo.list foo.lua\n--\n-- Default output is to stderr. To redirect the output to a file, pass a\n-- filename as an argument (use '-' for stdout) or set the environment\n-- variable LUAJIT_LISTFILE. The file is overwritten every time the module\n-- is started.\n--\n-- This module can also be used programmatically:\n--\n--   local bc = require(\"jit.bc\")\n--\n--   local function foo() print(\"hello\") end\n--\n--   bc.dump(foo)           --> -- BYTECODE -- [...]\n--   print(bc.line(foo, 2)) --> 0002    KSTR     1   1      ; \"hello\"\n--\n--   local out = {\n--     -- Do something with each line:\n--     write = function(t, ...) io.write(...) end,\n--     close = function(t) end,\n--     flush = function(t) end,\n--   }\n--   bc.dump(foo, out)\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal bit = require(\"bit\")\nlocal sub, gsub, format = string.sub, string.gsub, string.format\nlocal byte, band, shr = string.byte, bit.band, bit.rshift\nlocal funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck\nlocal funcuvname = jutil.funcuvname\nlocal bcnames = vmdef.bcnames\nlocal stdout, stderr = io.stdout, io.stderr\n\n------------------------------------------------------------------------------\n\nlocal function ctlsub(c)\n  if c == \"\\n\" then return \"\\\\n\"\n  elseif c == \"\\r\" then return \"\\\\r\"\n  elseif c == \"\\t\" then return \"\\\\t\"\n  else return format(\"\\\\%03d\", byte(c))\n  end\nend\n\n-- Return one bytecode line.\nlocal function bcline(func, pc, prefix)\n  local ins, m = funcbc(func, pc)\n  if not ins then return end\n  local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128)\n  local a = band(shr(ins, 8), 0xff)\n  local oidx = 6*band(ins, 0xff)\n  local op = sub(bcnames, oidx+1, oidx+6)\n  local s = format(\"%04d %s %-6s %3s \",\n    pc, prefix or \"  \", op, ma == 0 and \"\" or a)\n  local d = shr(ins, 16)\n  if mc == 13*128 then -- BCMjump\n    return format(\"%s=> %04d\\n\", s, pc+d-0x7fff)\n  end\n  if mb ~= 0 then\n    d = band(d, 0xff)\n  elseif mc == 0 then\n    return s..\"\\n\"\n  end\n  local kc\n  if mc == 10*128 then -- BCMstr\n    kc = funck(func, -d-1)\n    kc = format(#kc > 40 and '\"%.40s\"~' or '\"%s\"', gsub(kc, \"%c\", ctlsub))\n  elseif mc == 9*128 then -- BCMnum\n    kc = funck(func, d)\n    if op == \"TSETM \" then kc = kc - 2^52 end\n  elseif mc == 12*128 then -- BCMfunc\n    local fi = funcinfo(funck(func, -d-1))\n    if fi.ffid then\n      kc = vmdef.ffnames[fi.ffid]\n    else\n      kc = fi.loc\n    end\n  elseif mc == 5*128 then -- BCMuv\n    kc = funcuvname(func, d)\n  end\n  if ma == 5 then -- BCMuv\n    local ka = funcuvname(func, a)\n    if kc then kc = ka..\" ; \"..kc else kc = ka end\n  end\n  if mb ~= 0 then\n    local b = shr(ins, 24)\n    if kc then return format(\"%s%3d %3d  ; %s\\n\", s, b, d, kc) end\n    return format(\"%s%3d %3d\\n\", s, b, d)\n  end\n  if kc then return format(\"%s%3d      ; %s\\n\", s, d, kc) end\n  if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits\n  return format(\"%s%3d\\n\", s, d)\nend\n\n-- Collect branch targets of a function.\nlocal function bctargets(func)\n  local target = {}\n  for pc=1,1000000000 do\n    local ins, m = funcbc(func, pc)\n    if not ins then break end\n    if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end\n  end\n  return target\nend\n\n-- Dump bytecode instructions of a function.\nlocal function bcdump(func, out, all)\n  if not out then out = stdout end\n  local fi = funcinfo(func)\n  if all and fi.children then\n    for n=-1,-1000000000,-1 do\n      local k = funck(func, n)\n      if not k then break end\n      if type(k) == \"proto\" then bcdump(k, out, true) end\n    end\n  end\n  out:write(format(\"-- BYTECODE -- %s-%d\\n\", fi.loc, fi.lastlinedefined))\n  local target = bctargets(func)\n  for pc=1,1000000000 do\n    local s = bcline(func, pc, target[pc] and \"=>\")\n    if not s then break end\n    out:write(s)\n  end\n  out:write(\"\\n\")\n  out:flush()\nend\n\n------------------------------------------------------------------------------\n\n-- Active flag and output file handle.\nlocal active, out\n\n-- List handler.\nlocal function h_list(func)\n  return bcdump(func, out)\nend\n\n-- Detach list handler.\nlocal function bclistoff()\n  if active then\n    active = false\n    jit.attach(h_list)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach list handler.\nlocal function bcliston(outfile)\n  if active then bclistoff() end\n  if not outfile then outfile = os.getenv(\"LUAJIT_LISTFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stderr\n  end\n  jit.attach(h_list, \"bc\")\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  line = bcline,\n  dump = bcdump,\n  targets = bctargets,\n  on = bcliston,\n  off = bclistoff,\n  start = bcliston -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/bcsave.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT module to save/list bytecode.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module saves or lists the bytecode for an input file.\n-- It's run by the -b command line option.\n--\n------------------------------------------------------------------------------\n\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal bit = require(\"bit\")\n\n-- Symbol name prefix for LuaJIT bytecode.\nlocal LJBC_PREFIX = \"luaJIT_BC_\"\n\nlocal type, assert = type, assert\nlocal format = string.format\nlocal tremove, tconcat = table.remove, table.concat\n\n------------------------------------------------------------------------------\n\nlocal function usage()\n  io.stderr:write[[\nSave LuaJIT bytecode: luajit -b[options] input output\n  -l        Only list bytecode.\n  -s        Strip debug info (default).\n  -g        Keep debug info.\n  -n name   Set module name (default: auto-detect from input name).\n  -t type   Set output file type (default: auto-detect from output name).\n  -a arch   Override architecture for object files (default: native).\n  -o os     Override OS for object files (default: native).\n  -e chunk  Use chunk string as input.\n  --        Stop handling options.\n  -         Use stdin as input and/or stdout as output.\n\nFile types: c h obj o raw (default)\n]]\n  os.exit(1)\nend\n\nlocal function check(ok, ...)\n  if ok then return ok, ... end\n  io.stderr:write(\"luajit: \", ...)\n  io.stderr:write(\"\\n\")\n  os.exit(1)\nend\n\nlocal function readfile(input)\n  if type(input) == \"function\" then return input end\n  if input == \"-\" then input = nil end\n  return check(loadfile(input))\nend\n\nlocal function savefile(name, mode)\n  if name == \"-\" then return io.stdout end\n  return check(io.open(name, mode))\nend\n\nlocal function set_stdout_binary(ffi)\n  ffi.cdef[[int _setmode(int fd, int mode);]]\n  ffi.C._setmode(1, 0x8000)\nend\n\n------------------------------------------------------------------------------\n\nlocal map_type = {\n  raw = \"raw\", c = \"c\", h = \"h\", o = \"obj\", obj = \"obj\",\n}\n\nlocal map_arch = {\n  x86 =\t\t{ e = \"le\", b = 32, m = 3, p = 0x14c, },\n  x64 =\t\t{ e = \"le\", b = 64, m = 62, p = 0x8664, },\n  arm =\t\t{ e = \"le\", b = 32, m = 40, p = 0x1c0, },\n  arm64 =\t{ e = \"le\", b = 64, m = 183, p = 0xaa64, },\n  arm64be =\t{ e = \"be\", b = 64, m = 183, },\n  ppc =\t\t{ e = \"be\", b = 32, m = 20, },\n  mips =\t{ e = \"be\", b = 32, m = 8, f = 0x50001006, },\n  mipsel =\t{ e = \"le\", b = 32, m = 8, f = 0x50001006, },\n  mips64 =\t{ e = \"be\", b = 64, m = 8, f = 0x80000007, },\n  mips64el =\t{ e = \"le\", b = 64, m = 8, f = 0x80000007, },\n  mips64r6 =\t{ e = \"be\", b = 64, m = 8, f = 0xa0000407, },\n  mips64r6el =\t{ e = \"le\", b = 64, m = 8, f = 0xa0000407, },\n}\n\nlocal map_os = {\n  linux = true, windows = true, osx = true, freebsd = true, netbsd = true,\n  openbsd = true, dragonfly = true, solaris = true,\n}\n\nlocal function checkarg(str, map, err)\n  str = str:lower()\n  local s = check(map[str], \"unknown \", err)\n  return type(s) == \"string\" and s or str\nend\n\nlocal function detecttype(str)\n  local ext = str:lower():match(\"%.(%a+)$\")\n  return map_type[ext] or \"raw\"\nend\n\nlocal function checkmodname(str)\n  check(str:match(\"^[%w_.%-]+$\"), \"bad module name\")\n  return str:gsub(\"[%.%-]\", \"_\")\nend\n\nlocal function detectmodname(str)\n  if type(str) == \"string\" then\n    local tail = str:match(\"[^/\\\\]+$\")\n    if tail then str = tail end\n    local head = str:match(\"^(.*)%.[^.]*$\")\n    if head then str = head end\n    str = str:match(\"^[%w_.%-]+\")\n  else\n    str = nil\n  end\n  check(str, \"cannot derive module name, use -n name\")\n  return str:gsub(\"[%.%-]\", \"_\")\nend\n\n------------------------------------------------------------------------------\n\nlocal function bcsave_tail(fp, output, s)\n  local ok, err = fp:write(s)\n  if ok and output ~= \"-\" then ok, err = fp:close() end\n  check(ok, \"cannot write \", output, \": \", err)\nend\n\nlocal function bcsave_raw(output, s)\n  if output == \"-\" and jit.os == \"Windows\" then\n    local ok, ffi = pcall(require, \"ffi\")\n    check(ok, \"FFI library required to write binary file to stdout\")\n    set_stdout_binary(ffi)\n  end\n  local fp = savefile(output, \"wb\")\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_c(ctx, output, s)\n  local fp = savefile(output, \"w\")\n  if ctx.type == \"c\" then\n    fp:write(format([[\n#ifdef __cplusplus\nextern \"C\"\n#endif\n#ifdef _WIN32\n__declspec(dllexport)\n#endif\nconst unsigned char %s%s[] = {\n]], LJBC_PREFIX, ctx.modname))\n  else\n    fp:write(format([[\n#define %s%s_SIZE %d\nstatic const unsigned char %s%s[] = {\n]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname))\n  end\n  local t, n, m = {}, 0, 0\n  for i=1,#s do\n    local b = tostring(string.byte(s, i))\n    m = m + #b + 1\n    if m > 78 then\n      fp:write(tconcat(t, \",\", 1, n), \",\\n\")\n      n, m = 0, #b + 1\n    end\n    n = n + 1\n    t[n] = b\n  end\n  bcsave_tail(fp, output, tconcat(t, \",\", 1, n)..\"\\n};\\n\")\nend\n\nlocal function bcsave_elfobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct {\n  uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];\n  uint16_t type, machine;\n  uint32_t version;\n  uint32_t entry, phofs, shofs;\n  uint32_t flags;\n  uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;\n} ELF32header;\ntypedef struct {\n  uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];\n  uint16_t type, machine;\n  uint32_t version;\n  uint64_t entry, phofs, shofs;\n  uint32_t flags;\n  uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;\n} ELF64header;\ntypedef struct {\n  uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize;\n} ELF32sectheader;\ntypedef struct {\n  uint32_t name, type;\n  uint64_t flags, addr, ofs, size;\n  uint32_t link, info;\n  uint64_t align, entsize;\n} ELF64sectheader;\ntypedef struct {\n  uint32_t name, value, size;\n  uint8_t info, other;\n  uint16_t sectidx;\n} ELF32symbol;\ntypedef struct {\n  uint32_t name;\n  uint8_t info, other;\n  uint16_t sectidx;\n  uint64_t value, size;\n} ELF64symbol;\ntypedef struct {\n  ELF32header hdr;\n  ELF32sectheader sect[6];\n  ELF32symbol sym[2];\n  uint8_t space[4096];\n} ELF32obj;\ntypedef struct {\n  ELF64header hdr;\n  ELF64sectheader sect[6];\n  ELF64symbol sym[2];\n  uint8_t space[4096];\n} ELF64obj;\n]]\n  local symname = LJBC_PREFIX..ctx.modname\n  local ai = assert(map_arch[ctx.arch])\n  local is64, isbe = ai.b == 64, ai.e == \"be\"\n\n  -- Handle different host/target endianess.\n  local function f32(x) return x end\n  local f16, fofs = f32, f32\n  if ffi.abi(\"be\") ~= isbe then\n    f32 = bit.bswap\n    function f16(x) return bit.rshift(bit.bswap(x), 16) end\n    if is64 then\n      local two32 = ffi.cast(\"int64_t\", 2^32)\n      function fofs(x) return bit.bswap(x)*two32 end\n    else\n      fofs = f32\n    end\n  end\n\n  -- Create ELF object and fill in header.\n  local o = ffi.new(is64 and \"ELF64obj\" or \"ELF32obj\")\n  local hdr = o.hdr\n  if ctx.os == \"bsd\" or ctx.os == \"other\" then -- Determine native hdr.eosabi.\n    local bf = assert(io.open(\"/bin/ls\", \"rb\"))\n    local bs = bf:read(9)\n    bf:close()\n    ffi.copy(o, bs, 9)\n    check(hdr.emagic[0] == 127, \"no support for writing native object files\")\n  else\n    hdr.emagic = \"\\127ELF\"\n    hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0\n  end\n  hdr.eclass = is64 and 2 or 1\n  hdr.eendian = isbe and 2 or 1\n  hdr.eversion = 1\n  hdr.type = f16(1)\n  hdr.machine = f16(ai.m)\n  hdr.flags = f32(ai.f or 0)\n  hdr.version = f32(1)\n  hdr.shofs = fofs(ffi.offsetof(o, \"sect\"))\n  hdr.ehsize = f16(ffi.sizeof(hdr))\n  hdr.shentsize = f16(ffi.sizeof(o.sect[0]))\n  hdr.shnum = f16(6)\n  hdr.shstridx = f16(2)\n\n  -- Fill in sections and symbols.\n  local sofs, ofs = ffi.offsetof(o, \"space\"), 1\n  for i,name in ipairs{\n      \".symtab\", \".shstrtab\", \".strtab\", \".rodata\", \".note.GNU-stack\",\n    } do\n    local sect = o.sect[i]\n    sect.align = fofs(1)\n    sect.name = f32(ofs)\n    ffi.copy(o.space+ofs, name)\n    ofs = ofs + #name+1\n  end\n  o.sect[1].type = f32(2) -- .symtab\n  o.sect[1].link = f32(3)\n  o.sect[1].info = f32(1)\n  o.sect[1].align = fofs(8)\n  o.sect[1].ofs = fofs(ffi.offsetof(o, \"sym\"))\n  o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0]))\n  o.sect[1].size = fofs(ffi.sizeof(o.sym))\n  o.sym[1].name = f32(1)\n  o.sym[1].sectidx = f16(4)\n  o.sym[1].size = fofs(#s)\n  o.sym[1].info = 17\n  o.sect[2].type = f32(3) -- .shstrtab\n  o.sect[2].ofs = fofs(sofs)\n  o.sect[2].size = fofs(ofs)\n  o.sect[3].type = f32(3) -- .strtab\n  o.sect[3].ofs = fofs(sofs + ofs)\n  o.sect[3].size = fofs(#symname+2)\n  ffi.copy(o.space+ofs+1, symname)\n  ofs = ofs + #symname + 2\n  o.sect[4].type = f32(1) -- .rodata\n  o.sect[4].flags = fofs(2)\n  o.sect[4].ofs = fofs(sofs + ofs)\n  o.sect[4].size = fofs(#s)\n  o.sect[5].type = f32(1) -- .note.GNU-stack\n  o.sect[5].ofs = fofs(sofs + ofs + #s)\n\n  -- Write ELF object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_peobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct {\n  uint16_t arch, nsects;\n  uint32_t time, symtabofs, nsyms;\n  uint16_t opthdrsz, flags;\n} PEheader;\ntypedef struct {\n  char name[8];\n  uint32_t vsize, vaddr, size, ofs, relocofs, lineofs;\n  uint16_t nreloc, nline;\n  uint32_t flags;\n} PEsection;\ntypedef struct __attribute((packed)) {\n  union {\n    char name[8];\n    uint32_t nameref[2];\n  };\n  uint32_t value;\n  int16_t sect;\n  uint16_t type;\n  uint8_t scl, naux;\n} PEsym;\ntypedef struct __attribute((packed)) {\n  uint32_t size;\n  uint16_t nreloc, nline;\n  uint32_t cksum;\n  uint16_t assoc;\n  uint8_t comdatsel, unused[3];\n} PEsymaux;\ntypedef struct {\n  PEheader hdr;\n  PEsection sect[2];\n  // Must be an even number of symbol structs.\n  PEsym sym0;\n  PEsymaux sym0aux;\n  PEsym sym1;\n  PEsymaux sym1aux;\n  PEsym sym2;\n  PEsym sym3;\n  uint32_t strtabsize;\n  uint8_t space[4096];\n} PEobj;\n]]\n  local symname = LJBC_PREFIX..ctx.modname\n  local ai = assert(map_arch[ctx.arch])\n  local is64 = ai.b == 64\n  local symexport = \"   /EXPORT:\"..symname..\",DATA \"\n\n  -- The file format is always little-endian. Swap if the host is big-endian.\n  local function f32(x) return x end\n  local f16 = f32\n  if ffi.abi(\"be\") then\n    f32 = bit.bswap\n    function f16(x) return bit.rshift(bit.bswap(x), 16) end\n  end\n\n  -- Create PE object and fill in header.\n  local o = ffi.new(\"PEobj\")\n  local hdr = o.hdr\n  hdr.arch = f16(assert(ai.p))\n  hdr.nsects = f16(2)\n  hdr.symtabofs = f32(ffi.offsetof(o, \"sym0\"))\n  hdr.nsyms = f32(6)\n\n  -- Fill in sections and symbols.\n  o.sect[0].name = \".drectve\"\n  o.sect[0].size = f32(#symexport)\n  o.sect[0].flags = f32(0x00100a00)\n  o.sym0.sect = f16(1)\n  o.sym0.scl = 3\n  o.sym0.name = \".drectve\"\n  o.sym0.naux = 1\n  o.sym0aux.size = f32(#symexport)\n  o.sect[1].name = \".rdata\"\n  o.sect[1].size = f32(#s)\n  o.sect[1].flags = f32(0x40300040)\n  o.sym1.sect = f16(2)\n  o.sym1.scl = 3\n  o.sym1.name = \".rdata\"\n  o.sym1.naux = 1\n  o.sym1aux.size = f32(#s)\n  o.sym2.sect = f16(2)\n  o.sym2.scl = 2\n  o.sym2.nameref[1] = f32(4)\n  o.sym3.sect = f16(-1)\n  o.sym3.scl = 2\n  o.sym3.value = f32(1)\n  o.sym3.name = \"@feat.00\" -- Mark as SafeSEH compliant.\n  ffi.copy(o.space, symname)\n  local ofs = #symname + 1\n  o.strtabsize = f32(ofs + 4)\n  o.sect[0].ofs = f32(ffi.offsetof(o, \"space\") + ofs)\n  ffi.copy(o.space + ofs, symexport)\n  ofs = ofs + #symexport\n  o.sect[1].ofs = f32(ffi.offsetof(o, \"space\") + ofs)\n\n  -- Write PE object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_machobj(ctx, output, s, ffi)\n  ffi.cdef[[\ntypedef struct\n{\n  uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags;\n} mach_header;\ntypedef struct\n{\n  mach_header; uint32_t reserved;\n} mach_header_64;\ntypedef struct {\n  uint32_t cmd, cmdsize;\n  char segname[16];\n  uint32_t vmaddr, vmsize, fileoff, filesize;\n  uint32_t maxprot, initprot, nsects, flags;\n} mach_segment_command;\ntypedef struct {\n  uint32_t cmd, cmdsize;\n  char segname[16];\n  uint64_t vmaddr, vmsize, fileoff, filesize;\n  uint32_t maxprot, initprot, nsects, flags;\n} mach_segment_command_64;\ntypedef struct {\n  char sectname[16], segname[16];\n  uint32_t addr, size;\n  uint32_t offset, align, reloff, nreloc, flags;\n  uint32_t reserved1, reserved2;\n} mach_section;\ntypedef struct {\n  char sectname[16], segname[16];\n  uint64_t addr, size;\n  uint32_t offset, align, reloff, nreloc, flags;\n  uint32_t reserved1, reserved2, reserved3;\n} mach_section_64;\ntypedef struct {\n  uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize;\n} mach_symtab_command;\ntypedef struct {\n  int32_t strx;\n  uint8_t type, sect;\n  int16_t desc;\n  uint32_t value;\n} mach_nlist;\ntypedef struct {\n  uint32_t strx;\n  uint8_t type, sect;\n  uint16_t desc;\n  uint64_t value;\n} mach_nlist_64;\ntypedef struct\n{\n  uint32_t magic, nfat_arch;\n} mach_fat_header;\ntypedef struct\n{\n  uint32_t cputype, cpusubtype, offset, size, align;\n} mach_fat_arch;\ntypedef struct {\n  struct {\n    mach_header hdr;\n    mach_segment_command seg;\n    mach_section sec;\n    mach_symtab_command sym;\n  } arch[1];\n  mach_nlist sym_entry;\n  uint8_t space[4096];\n} mach_obj;\ntypedef struct {\n  struct {\n    mach_header_64 hdr;\n    mach_segment_command_64 seg;\n    mach_section_64 sec;\n    mach_symtab_command sym;\n  } arch[1];\n  mach_nlist_64 sym_entry;\n  uint8_t space[4096];\n} mach_obj_64;\ntypedef struct {\n  mach_fat_header fat;\n  mach_fat_arch fat_arch[2];\n  struct {\n    mach_header hdr;\n    mach_segment_command seg;\n    mach_section sec;\n    mach_symtab_command sym;\n  } arch[2];\n  mach_nlist sym_entry;\n  uint8_t space[4096];\n} mach_fat_obj;\n]]\n  local symname = '_'..LJBC_PREFIX..ctx.modname\n  local isfat, is64, align, mobj = false, false, 4, \"mach_obj\"\n  if ctx.arch == \"x64\" then\n    is64, align, mobj = true, 8, \"mach_obj_64\"\n  elseif ctx.arch == \"arm\" then\n    isfat, mobj = true, \"mach_fat_obj\"\n  elseif ctx.arch == \"arm64\" then\n    is64, align, isfat, mobj = true, 8, true, \"mach_fat_obj\"\n  else\n    check(ctx.arch == \"x86\", \"unsupported architecture for OSX\")\n  end\n  local function aligned(v, a) return bit.band(v+a-1, -a) end\n  local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE.\n\n  -- Create Mach-O object and fill in header.\n  local o = ffi.new(mobj)\n  local mach_size = aligned(ffi.offsetof(o, \"space\")+#symname+2, align)\n  local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12}, arm64={0x01000007,0x0100000c} })[ctx.arch]\n  local cpusubtype = ({ x86={3}, x64={3}, arm={3,9}, arm64={3,0} })[ctx.arch]\n  if isfat then\n    o.fat.magic = be32(0xcafebabe)\n    o.fat.nfat_arch = be32(#cpusubtype)\n  end\n\n  -- Fill in sections and symbols.\n  for i=0,#cpusubtype-1 do\n    local ofs = 0\n    if isfat then\n      local a = o.fat_arch[i]\n      a.cputype = be32(cputype[i+1])\n      a.cpusubtype = be32(cpusubtype[i+1])\n      -- Subsequent slices overlap each other to share data.\n      ofs = ffi.offsetof(o, \"arch\") + i*ffi.sizeof(o.arch[0])\n      a.offset = be32(ofs)\n      a.size = be32(mach_size-ofs+#s)\n    end\n    local a = o.arch[i]\n    a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface\n    a.hdr.cputype = cputype[i+1]\n    a.hdr.cpusubtype = cpusubtype[i+1]\n    a.hdr.filetype = 1\n    a.hdr.ncmds = 2\n    a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym)\n    a.seg.cmd = is64 and 0x19 or 0x1\n    a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)\n    a.seg.vmsize = #s\n    a.seg.fileoff = mach_size-ofs\n    a.seg.filesize = #s\n    a.seg.maxprot = 1\n    a.seg.initprot = 1\n    a.seg.nsects = 1\n    ffi.copy(a.sec.sectname, \"__data\")\n    ffi.copy(a.sec.segname, \"__DATA\")\n    a.sec.size = #s\n    a.sec.offset = mach_size-ofs\n    a.sym.cmd = 2\n    a.sym.cmdsize = ffi.sizeof(a.sym)\n    a.sym.symoff = ffi.offsetof(o, \"sym_entry\")-ofs\n    a.sym.nsyms = 1\n    a.sym.stroff = ffi.offsetof(o, \"sym_entry\")+ffi.sizeof(o.sym_entry)-ofs\n    a.sym.strsize = aligned(#symname+2, align)\n  end\n  o.sym_entry.type = 0xf\n  o.sym_entry.sect = 1\n  o.sym_entry.strx = 1\n  ffi.copy(o.space+1, symname)\n\n  -- Write Macho-O object file.\n  local fp = savefile(output, \"wb\")\n  fp:write(ffi.string(o, mach_size))\n  bcsave_tail(fp, output, s)\nend\n\nlocal function bcsave_obj(ctx, output, s)\n  local ok, ffi = pcall(require, \"ffi\")\n  check(ok, \"FFI library required to write this file type\")\n  if output == \"-\" and jit.os == \"Windows\" then\n    set_stdout_binary(ffi)\n  end\n  if ctx.os == \"windows\" then\n    return bcsave_peobj(ctx, output, s, ffi)\n  elseif ctx.os == \"osx\" then\n    return bcsave_machobj(ctx, output, s, ffi)\n  else\n    return bcsave_elfobj(ctx, output, s, ffi)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal function bclist(input, output)\n  local f = readfile(input)\n  require(\"jit.bc\").dump(f, savefile(output, \"w\"), true)\nend\n\nlocal function bcsave(ctx, input, output)\n  local f = readfile(input)\n  local s = string.dump(f, ctx.strip)\n  local t = ctx.type\n  if not t then\n    t = detecttype(output)\n    ctx.type = t\n  end\n  if t == \"raw\" then\n    bcsave_raw(output, s)\n  else\n    if not ctx.modname then ctx.modname = detectmodname(input) end\n    if t == \"obj\" then\n      bcsave_obj(ctx, output, s)\n    else\n      bcsave_c(ctx, output, s)\n    end\n  end\nend\n\nlocal function docmd(...)\n  local arg = {...}\n  local n = 1\n  local list = false\n  local ctx = {\n    strip = true, arch = jit.arch, os = jit.os:lower(),\n    type = false, modname = false,\n  }\n  while n <= #arg do\n    local a = arg[n]\n    if type(a) == \"string\" and a:sub(1, 1) == \"-\" and a ~= \"-\" then\n      tremove(arg, n)\n      if a == \"--\" then break end\n      for m=2,#a do\n\tlocal opt = a:sub(m, m)\n\tif opt == \"l\" then\n\t  list = true\n\telseif opt == \"s\" then\n\t  ctx.strip = true\n\telseif opt == \"g\" then\n\t  ctx.strip = false\n\telse\n\t  if arg[n] == nil or m ~= #a then usage() end\n\t  if opt == \"e\" then\n\t    if n ~= 1 then usage() end\n\t    arg[1] = check(loadstring(arg[1]))\n\t  elseif opt == \"n\" then\n\t    ctx.modname = checkmodname(tremove(arg, n))\n\t  elseif opt == \"t\" then\n\t    ctx.type = checkarg(tremove(arg, n), map_type, \"file type\")\n\t  elseif opt == \"a\" then\n\t    ctx.arch = checkarg(tremove(arg, n), map_arch, \"architecture\")\n\t  elseif opt == \"o\" then\n\t    ctx.os = checkarg(tremove(arg, n), map_os, \"OS name\")\n\t  else\n\t    usage()\n\t  end\n\tend\n      end\n    else\n      n = n + 1\n    end\n  end\n  if list then\n    if #arg == 0 or #arg > 2 then usage() end\n    bclist(arg[1], arg[2] or \"-\")\n  else\n    if #arg ~= 2 then usage() end\n    bcsave(ctx, arg[1], arg[2])\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Public module functions.\nreturn {\n  start = docmd -- Process -b command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_arm.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT ARM disassembler module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles most user-mode ARMv7 instructions\n-- NYI: Advanced SIMD and VFP instructions.\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch = string.match, string.gmatch\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, ror, tohex = bit.band, bit.bor, bit.ror, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Opcode maps\n------------------------------------------------------------------------------\n\nlocal map_loadc = {\n  shift = 8, mask = 15,\n  [10] = {\n    shift = 20, mask = 1,\n    [0] = {\n      shift = 23, mask = 3,\n      [0] = \"vmovFmDN\", \"vstmFNdr\",\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vstrFdl\",\n\t{ shift = 16, mask = 15, [13] = \"vpushFdr\", _ = \"vstmdbFNdr\", }\n      },\n    },\n    {\n      shift = 23, mask = 3,\n      [0] = \"vmovFDNm\",\n      { shift = 16, mask = 15, [13] = \"vpopFdr\", _ = \"vldmFNdr\", },\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vldrFdl\", \"vldmdbFNdr\",\n      },\n    },\n  },\n  [11] = {\n    shift = 20, mask = 1,\n    [0] = {\n      shift = 23, mask = 3,\n      [0] = \"vmovGmDN\", \"vstmGNdr\",\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vstrGdl\",\n\t{ shift = 16, mask = 15, [13] = \"vpushGdr\", _ = \"vstmdbGNdr\", }\n      },\n    },\n    {\n      shift = 23, mask = 3,\n      [0] = \"vmovGDNm\",\n      { shift = 16, mask = 15, [13] = \"vpopGdr\", _ = \"vldmGNdr\", },\n      _ = {\n\tshift = 21, mask = 1,\n\t[0] = \"vldrGdl\", \"vldmdbGNdr\",\n      },\n    },\n  },\n  _ = {\n    shift = 0, mask = 0 -- NYI ldc, mcrr, mrrc.\n  },\n}\n\nlocal map_vfps = {\n  shift = 6, mask = 0x2c001,\n  [0] = \"vmlaF.dnm\", \"vmlsF.dnm\",\n  [0x04000] = \"vnmlsF.dnm\", [0x04001] = \"vnmlaF.dnm\",\n  [0x08000] = \"vmulF.dnm\", [0x08001] = \"vnmulF.dnm\",\n  [0x0c000] = \"vaddF.dnm\", [0x0c001] = \"vsubF.dnm\",\n  [0x20000] = \"vdivF.dnm\",\n  [0x24000] = \"vfnmsF.dnm\", [0x24001] = \"vfnmaF.dnm\",\n  [0x28000] = \"vfmaF.dnm\", [0x28001] = \"vfmsF.dnm\",\n  [0x2c000] = \"vmovF.dY\",\n  [0x2c001] = {\n    shift = 7, mask = 0x1e01,\n    [0] = \"vmovF.dm\", \"vabsF.dm\",\n    [0x0200] = \"vnegF.dm\", [0x0201] = \"vsqrtF.dm\",\n    [0x0800] = \"vcmpF.dm\", [0x0801] = \"vcmpeF.dm\",\n    [0x0a00] = \"vcmpzF.d\", [0x0a01] = \"vcmpzeF.d\",\n    [0x0e01] = \"vcvtG.dF.m\",\n    [0x1000] = \"vcvt.f32.u32Fdm\", [0x1001] = \"vcvt.f32.s32Fdm\",\n    [0x1800] = \"vcvtr.u32F.dm\", [0x1801] = \"vcvt.u32F.dm\",\n    [0x1a00] = \"vcvtr.s32F.dm\", [0x1a01] = \"vcvt.s32F.dm\",\n  },\n}\n\nlocal map_vfpd = {\n  shift = 6, mask = 0x2c001,\n  [0] = \"vmlaG.dnm\", \"vmlsG.dnm\",\n  [0x04000] = \"vnmlsG.dnm\", [0x04001] = \"vnmlaG.dnm\",\n  [0x08000] = \"vmulG.dnm\", [0x08001] = \"vnmulG.dnm\",\n  [0x0c000] = \"vaddG.dnm\", [0x0c001] = \"vsubG.dnm\",\n  [0x20000] = \"vdivG.dnm\",\n  [0x24000] = \"vfnmsG.dnm\", [0x24001] = \"vfnmaG.dnm\",\n  [0x28000] = \"vfmaG.dnm\", [0x28001] = \"vfmsG.dnm\",\n  [0x2c000] = \"vmovG.dY\",\n  [0x2c001] = {\n    shift = 7, mask = 0x1e01,\n    [0] = \"vmovG.dm\", \"vabsG.dm\",\n    [0x0200] = \"vnegG.dm\", [0x0201] = \"vsqrtG.dm\",\n    [0x0800] = \"vcmpG.dm\", [0x0801] = \"vcmpeG.dm\",\n    [0x0a00] = \"vcmpzG.d\", [0x0a01] = \"vcmpzeG.d\",\n    [0x0e01] = \"vcvtF.dG.m\",\n    [0x1000] = \"vcvt.f64.u32GdFm\", [0x1001] = \"vcvt.f64.s32GdFm\",\n    [0x1800] = \"vcvtr.u32FdG.m\", [0x1801] = \"vcvt.u32FdG.m\",\n    [0x1a00] = \"vcvtr.s32FdG.m\", [0x1a01] = \"vcvt.s32FdG.m\",\n  },\n}\n\nlocal map_datac = {\n  shift = 24, mask = 1,\n  [0] = {\n    shift = 4, mask = 1,\n    [0] = {\n      shift = 8, mask = 15,\n      [10] = map_vfps,\n      [11] = map_vfpd,\n      -- NYI cdp, mcr, mrc.\n    },\n    {\n      shift = 8, mask = 15,\n      [10] = {\n\tshift = 20, mask = 15,\n\t[0] = \"vmovFnD\", \"vmovFDn\",\n\t[14] = \"vmsrD\",\n\t[15] = { shift = 12, mask = 15, [15] = \"vmrs\", _ = \"vmrsD\", },\n      },\n    },\n  },\n  \"svcT\",\n}\n\nlocal map_loadcu = {\n  shift = 0, mask = 0, -- NYI unconditional CP load/store.\n}\n\nlocal map_datacu = {\n  shift = 0, mask = 0, -- NYI unconditional CP data.\n}\n\nlocal map_simddata = {\n  shift = 0, mask = 0, -- NYI SIMD data.\n}\n\nlocal map_simdload = {\n  shift = 0, mask = 0, -- NYI SIMD load/store, preload.\n}\n\nlocal map_preload = {\n  shift = 0, mask = 0, -- NYI preload.\n}\n\nlocal map_media = {\n  shift = 20, mask = 31,\n  [0] = false,\n  { --01\n    shift = 5, mask = 7,\n    [0] = \"sadd16DNM\", \"sasxDNM\", \"ssaxDNM\", \"ssub16DNM\",\n    \"sadd8DNM\", false, false, \"ssub8DNM\",\n  },\n  { --02\n    shift = 5, mask = 7,\n    [0] = \"qadd16DNM\", \"qasxDNM\", \"qsaxDNM\", \"qsub16DNM\",\n    \"qadd8DNM\", false, false, \"qsub8DNM\",\n  },\n  { --03\n    shift = 5, mask = 7,\n    [0] = \"shadd16DNM\", \"shasxDNM\", \"shsaxDNM\", \"shsub16DNM\",\n    \"shadd8DNM\", false, false, \"shsub8DNM\",\n  },\n  false,\n  { --05\n    shift = 5, mask = 7,\n    [0] = \"uadd16DNM\", \"uasxDNM\", \"usaxDNM\", \"usub16DNM\",\n    \"uadd8DNM\", false, false, \"usub8DNM\",\n  },\n  { --06\n    shift = 5, mask = 7,\n    [0] = \"uqadd16DNM\", \"uqasxDNM\", \"uqsaxDNM\", \"uqsub16DNM\",\n    \"uqadd8DNM\", false, false, \"uqsub8DNM\",\n  },\n  { --07\n    shift = 5, mask = 7,\n    [0] = \"uhadd16DNM\", \"uhasxDNM\", \"uhsaxDNM\", \"uhsub16DNM\",\n    \"uhadd8DNM\", false, false, \"uhsub8DNM\",\n  },\n  { --08\n    shift = 5, mask = 7,\n    [0] = \"pkhbtDNMU\", false, \"pkhtbDNMU\",\n    { shift = 16, mask = 15, [15] = \"sxtb16DMU\", _ = \"sxtab16DNMU\", },\n    \"pkhbtDNMU\", \"selDNM\", \"pkhtbDNMU\",\n  },\n  false,\n  { --0a\n    shift = 5, mask = 7,\n    [0] = \"ssatDxMu\", \"ssat16DxM\", \"ssatDxMu\",\n    { shift = 16, mask = 15, [15] = \"sxtbDMU\", _ = \"sxtabDNMU\", },\n    \"ssatDxMu\", false, \"ssatDxMu\",\n  },\n  { --0b\n    shift = 5, mask = 7,\n    [0] = \"ssatDxMu\", \"revDM\", \"ssatDxMu\",\n    { shift = 16, mask = 15, [15] = \"sxthDMU\", _ = \"sxtahDNMU\", },\n    \"ssatDxMu\", \"rev16DM\", \"ssatDxMu\",\n  },\n  { --0c\n    shift = 5, mask = 7,\n    [3] = { shift = 16, mask = 15, [15] = \"uxtb16DMU\", _ = \"uxtab16DNMU\", },\n  },\n  false,\n  { --0e\n    shift = 5, mask = 7,\n    [0] = \"usatDwMu\", \"usat16DwM\", \"usatDwMu\",\n    { shift = 16, mask = 15, [15] = \"uxtbDMU\", _ = \"uxtabDNMU\", },\n    \"usatDwMu\", false, \"usatDwMu\",\n  },\n  { --0f\n    shift = 5, mask = 7,\n    [0] = \"usatDwMu\", \"rbitDM\", \"usatDwMu\",\n    { shift = 16, mask = 15, [15] = \"uxthDMU\", _ = \"uxtahDNMU\", },\n    \"usatDwMu\", \"revshDM\", \"usatDwMu\",\n  },\n  { --10\n    shift = 12, mask = 15,\n    [15] = {\n      shift = 5, mask = 7,\n      \"smuadNMS\", \"smuadxNMS\", \"smusdNMS\", \"smusdxNMS\",\n    },\n    _ = {\n      shift = 5, mask = 7,\n      [0] = \"smladNMSD\", \"smladxNMSD\", \"smlsdNMSD\", \"smlsdxNMSD\",\n    },\n  },\n  false, false, false,\n  { --14\n    shift = 5, mask = 7,\n    [0] = \"smlaldDNMS\", \"smlaldxDNMS\", \"smlsldDNMS\", \"smlsldxDNMS\",\n  },\n  { --15\n    shift = 5, mask = 7,\n    [0] = { shift = 12, mask = 15, [15] = \"smmulNMS\", _ = \"smmlaNMSD\", },\n    { shift = 12, mask = 15, [15] = \"smmulrNMS\", _ = \"smmlarNMSD\", },\n    false, false, false, false,\n    \"smmlsNMSD\", \"smmlsrNMSD\",\n  },\n  false, false,\n  { --18\n    shift = 5, mask = 7,\n    [0] = { shift = 12, mask = 15, [15] = \"usad8NMS\", _ = \"usada8NMSD\", },\n  },\n  false,\n  { --1a\n    shift = 5, mask = 3, [2] = \"sbfxDMvw\",\n  },\n  { --1b\n    shift = 5, mask = 3, [2] = \"sbfxDMvw\",\n  },\n  { --1c\n    shift = 5, mask = 3,\n    [0] = { shift = 0, mask = 15, [15] = \"bfcDvX\", _ = \"bfiDMvX\", },\n  },\n  { --1d\n    shift = 5, mask = 3,\n    [0] = { shift = 0, mask = 15, [15] = \"bfcDvX\", _ = \"bfiDMvX\", },\n  },\n  { --1e\n    shift = 5, mask = 3, [2] = \"ubfxDMvw\",\n  },\n  { --1f\n    shift = 5, mask = 3, [2] = \"ubfxDMvw\",\n  },\n}\n\nlocal map_load = {\n  shift = 21, mask = 9,\n  {\n    shift = 20, mask = 5,\n    [0] = \"strtDL\", \"ldrtDL\", [4] = \"strbtDL\", [5] = \"ldrbtDL\",\n  },\n  _ = {\n    shift = 20, mask = 5,\n    [0] = \"strDL\", \"ldrDL\", [4] = \"strbDL\", [5] = \"ldrbDL\",\n  }\n}\n\nlocal map_load1 = {\n  shift = 4, mask = 1,\n  [0] = map_load, map_media,\n}\n\nlocal map_loadm = {\n  shift = 20, mask = 1,\n  [0] = {\n    shift = 23, mask = 3,\n    [0] = \"stmdaNR\", \"stmNR\",\n    { shift = 16, mask = 63, [45] = \"pushR\", _ = \"stmdbNR\", }, \"stmibNR\",\n  },\n  {\n    shift = 23, mask = 3,\n    [0] = \"ldmdaNR\", { shift = 16, mask = 63, [61] = \"popR\", _ = \"ldmNR\", },\n    \"ldmdbNR\", \"ldmibNR\",\n  },\n}\n\nlocal map_data = {\n  shift = 21, mask = 15,\n  [0] = \"andDNPs\", \"eorDNPs\", \"subDNPs\", \"rsbDNPs\",\n  \"addDNPs\", \"adcDNPs\", \"sbcDNPs\", \"rscDNPs\",\n  \"tstNP\", \"teqNP\", \"cmpNP\", \"cmnNP\",\n  \"orrDNPs\", \"movDPs\", \"bicDNPs\", \"mvnDPs\",\n}\n\nlocal map_mul = {\n  shift = 21, mask = 7,\n  [0] = \"mulNMSs\", \"mlaNMSDs\", \"umaalDNMS\", \"mlsDNMS\",\n  \"umullDNMSs\", \"umlalDNMSs\", \"smullDNMSs\", \"smlalDNMSs\",\n}\n\nlocal map_sync = {\n  shift = 20, mask = 15, -- NYI: brackets around N. R(D+1) for ldrexd/strexd.\n  [0] = \"swpDMN\", false, false, false,\n  \"swpbDMN\", false, false, false,\n  \"strexDMN\", \"ldrexDN\", \"strexdDN\", \"ldrexdDN\",\n  \"strexbDMN\", \"ldrexbDN\", \"strexhDN\", \"ldrexhDN\",\n}\n\nlocal map_mulh = {\n  shift = 21, mask = 3,\n  [0] = { shift = 5, mask = 3,\n    [0] = \"smlabbNMSD\", \"smlatbNMSD\", \"smlabtNMSD\", \"smlattNMSD\", },\n  { shift = 5, mask = 3,\n    [0] = \"smlawbNMSD\", \"smulwbNMS\", \"smlawtNMSD\", \"smulwtNMS\", },\n  { shift = 5, mask = 3,\n    [0] = \"smlalbbDNMS\", \"smlaltbDNMS\", \"smlalbtDNMS\", \"smlalttDNMS\", },\n  { shift = 5, mask = 3,\n    [0] = \"smulbbNMS\", \"smultbNMS\", \"smulbtNMS\", \"smulttNMS\", },\n}\n\nlocal map_misc = {\n  shift = 4, mask = 7,\n  -- NYI: decode PSR bits of msr.\n  [0] = { shift = 21, mask = 1, [0] = \"mrsD\", \"msrM\", },\n  { shift = 21, mask = 3, \"bxM\", false, \"clzDM\", },\n  { shift = 21, mask = 3, \"bxjM\", },\n  { shift = 21, mask = 3, \"blxM\", },\n  false,\n  { shift = 21, mask = 3, [0] = \"qaddDMN\", \"qsubDMN\", \"qdaddDMN\", \"qdsubDMN\", },\n  false,\n  { shift = 21, mask = 3, \"bkptK\", },\n}\n\nlocal map_datar = {\n  shift = 4, mask = 9,\n  [9] = {\n    shift = 5, mask = 3,\n    [0] = { shift = 24, mask = 1, [0] = map_mul, map_sync, },\n    { shift = 20, mask = 1, [0] = \"strhDL\", \"ldrhDL\", },\n    { shift = 20, mask = 1, [0] = \"ldrdDL\", \"ldrsbDL\", },\n    { shift = 20, mask = 1, [0] = \"strdDL\", \"ldrshDL\", },\n  },\n  _ = {\n    shift = 20, mask = 25,\n    [16] = { shift = 7, mask = 1, [0] = map_misc, map_mulh, },\n    _ = {\n      shift = 0, mask = 0xffffffff,\n      [bor(0xe1a00000)] = \"nop\",\n      _ = map_data,\n    }\n  },\n}\n\nlocal map_datai = {\n  shift = 20, mask = 31, -- NYI: decode PSR bits of msr. Decode imm12.\n  [16] = \"movwDW\", [20] = \"movtDW\",\n  [18] = { shift = 0, mask = 0xf00ff, [0] = \"nopv6\", _ = \"msrNW\", },\n  [22] = \"msrNW\",\n  _ = map_data,\n}\n\nlocal map_branch = {\n  shift = 24, mask = 1,\n  [0] = \"bB\", \"blB\"\n}\n\nlocal map_condins = {\n  [0] = map_datar, map_datai, map_load, map_load1,\n  map_loadm, map_branch, map_loadc, map_datac\n}\n\n-- NYI: setend.\nlocal map_uncondins = {\n  [0] = false, map_simddata, map_simdload, map_preload,\n  false, \"blxB\", map_loadcu, map_datacu,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"r1\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"sp\", \"lr\", \"pc\",\n}\n\nlocal map_cond = {\n  [0] = \"eq\", \"ne\", \"hs\", \"lo\", \"mi\", \"pl\", \"vs\", \"vc\",\n  \"hi\", \"ls\", \"ge\", \"lt\", \"gt\", \"le\", \"al\",\n}\n\nlocal map_shift = { [0] = \"lsl\", \"lsr\", \"asr\", \"ror\", }\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then\n      extra = \"\\t->\"..sym\n    elseif band(ctx.op, 0x0e000000) ~= 0x0a000000 then\n      extra = \"\\t; 0x\"..tohex(ctx.rel)\n    end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-5s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-5s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\n-- Format operand 2 of load/store opcodes.\nlocal function fmtload(ctx, op, pos)\n  local base = map_gpr[band(rshift(op, 16), 15)]\n  local x, ofs\n  local ext = (band(op, 0x04000000) == 0)\n  if not ext and band(op, 0x02000000) == 0 then\n    ofs = band(op, 4095)\n    if band(op, 0x00800000) == 0 then ofs = -ofs end\n    if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n    ofs = \"#\"..ofs\n  elseif ext and band(op, 0x00400000) ~= 0 then\n    ofs = band(op, 15) + band(rshift(op, 4), 0xf0)\n    if band(op, 0x00800000) == 0 then ofs = -ofs end\n    if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n    ofs = \"#\"..ofs\n  else\n    ofs = map_gpr[band(op, 15)]\n    if ext or band(op, 0xfe0) == 0 then\n    elseif band(op, 0xfe0) == 0x60 then\n      ofs = format(\"%s, rrx\", ofs)\n    else\n      local sh = band(rshift(op, 7), 31)\n      if sh == 0 then sh = 32 end\n      ofs = format(\"%s, %s #%d\", ofs, map_shift[band(rshift(op, 5), 3)], sh)\n    end\n    if band(op, 0x00800000) == 0 then ofs = \"-\"..ofs end\n  end\n  if ofs == \"#0\" then\n    x = format(\"[%s]\", base)\n  elseif band(op, 0x01000000) == 0 then\n    x = format(\"[%s], %s\", base, ofs)\n  else\n    x = format(\"[%s, %s]\", base, ofs)\n  end\n  if band(op, 0x01200000) == 0x01200000 then x = x..\"!\" end\n  return x\nend\n\n-- Format operand 2 of vector load/store opcodes.\nlocal function fmtvload(ctx, op, pos)\n  local base = map_gpr[band(rshift(op, 16), 15)]\n  local ofs = band(op, 255)*4\n  if band(op, 0x00800000) == 0 then ofs = -ofs end\n  if base == \"pc\" then ctx.rel = ctx.addr + pos + 8 + ofs end\n  if ofs == 0 then\n    return format(\"[%s]\", base)\n  else\n    return format(\"[%s, #%d]\", base, ofs)\n  end\nend\n\nlocal function fmtvr(op, vr, sh0, sh1)\n  if vr == \"s\" then\n    return format(\"s%d\", 2*band(rshift(op, sh0), 15)+band(rshift(op, sh1), 1))\n  else\n    return format(\"d%d\", band(rshift(op, sh0), 15)+band(rshift(op, sh1-4), 16))\n  end\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)\n  local operands = {}\n  local suffix = \"\"\n  local last, name, pat\n  local vr\n  ctx.op = op\n  ctx.rel = nil\n\n  local cond = rshift(op, 28)\n  local opat\n  if cond == 15 then\n    opat = map_uncondins[band(rshift(op, 25), 7)]\n  else\n    if cond ~= 14 then suffix = map_cond[cond] end\n    opat = map_condins[band(rshift(op, 25), 7)]\n  end\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._\n  end\n  name, pat = match(opat, \"^([a-z0-9]*)(.*)\")\n  if sub(pat, 1, 1) == \".\" then\n    local s2, p2 = match(pat, \"^([a-z0-9.]*)(.*)\")\n    suffix = suffix..s2\n    pat = p2\n  end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"D\" then\n      x = map_gpr[band(rshift(op, 12), 15)]\n    elseif p == \"N\" then\n      x = map_gpr[band(rshift(op, 16), 15)]\n    elseif p == \"S\" then\n      x = map_gpr[band(rshift(op, 8), 15)]\n    elseif p == \"M\" then\n      x = map_gpr[band(op, 15)]\n    elseif p == \"d\" then\n      x = fmtvr(op, vr, 12, 22)\n    elseif p == \"n\" then\n      x = fmtvr(op, vr, 16, 7)\n    elseif p == \"m\" then\n      x = fmtvr(op, vr, 0, 5)\n    elseif p == \"P\" then\n      if band(op, 0x02000000) ~= 0 then\n\tx = ror(band(op, 255), 2*band(rshift(op, 8), 15))\n      else\n\tx = map_gpr[band(op, 15)]\n\tif band(op, 0xff0) ~= 0 then\n\t  operands[#operands+1] = x\n\t  local s = map_shift[band(rshift(op, 5), 3)]\n\t  local r = nil\n\t  if band(op, 0xf90) == 0 then\n\t    if s == \"ror\" then s = \"rrx\" else r = \"#32\" end\n\t  elseif band(op, 0x10) == 0 then\n\t    r = \"#\"..band(rshift(op, 7), 31)\n\t  else\n\t    r = map_gpr[band(rshift(op, 8), 15)]\n\t  end\n\t  if name == \"mov\" then name = s; x = r\n\t  elseif r then x = format(\"%s %s\", s, r)\n\t  else x = s end\n\tend\n      end\n    elseif p == \"L\" then\n      x = fmtload(ctx, op, pos)\n    elseif p == \"l\" then\n      x = fmtvload(ctx, op, pos)\n    elseif p == \"B\" then\n      local addr = ctx.addr + pos + 8 + arshift(lshift(op, 8), 6)\n      if cond == 15 then addr = addr + band(rshift(op, 23), 2) end\n      ctx.rel = addr\n      x = \"0x\"..tohex(addr)\n    elseif p == \"F\" then\n      vr = \"s\"\n    elseif p == \"G\" then\n      vr = \"d\"\n    elseif p == \".\" then\n      suffix = suffix..(vr == \"s\" and \".f32\" or \".f64\")\n    elseif p == \"R\" then\n      if band(op, 0x00200000) ~= 0 and #operands == 1 then\n\toperands[1] = operands[1]..\"!\"\n      end\n      local t = {}\n      for i=0,15 do\n\tif band(rshift(op, i), 1) == 1 then t[#t+1] = map_gpr[i] end\n      end\n      x = \"{\"..concat(t, \", \")..\"}\"\n    elseif p == \"r\" then\n      if band(op, 0x00200000) ~= 0 and #operands == 2 then\n\toperands[1] = operands[1]..\"!\"\n      end\n      local s = tonumber(sub(last, 2))\n      local n = band(op, 255)\n      if vr == \"d\" then n = rshift(n, 1) end\n      operands[#operands] = format(\"{%s-%s%d}\", last, vr, s+n-1)\n    elseif p == \"W\" then\n      x = band(op, 0x0fff) + band(rshift(op, 4), 0xf000)\n    elseif p == \"T\" then\n      x = \"#0x\"..tohex(band(op, 0x00ffffff), 6)\n    elseif p == \"U\" then\n      x = band(rshift(op, 7), 31)\n      if x == 0 then x = nil end\n    elseif p == \"u\" then\n      x = band(rshift(op, 7), 31)\n      if band(op, 0x40) == 0 then\n\tif x == 0 then x = nil else x = \"lsl #\"..x end\n      else\n\tif x == 0 then x = \"asr #32\" else x = \"asr #\"..x end\n      end\n    elseif p == \"v\" then\n      x = band(rshift(op, 7), 31)\n    elseif p == \"w\" then\n      x = band(rshift(op, 16), 31)\n    elseif p == \"x\" then\n      x = band(rshift(op, 16), 31) + 1\n    elseif p == \"X\" then\n      x = band(rshift(op, 16), 31) - last + 1\n    elseif p == \"Y\" then\n      x = band(rshift(op, 12), 0xf0) + band(op, 0x0f)\n    elseif p == \"K\" then\n      x = \"#0x\"..tohex(band(rshift(op, 4), 0x0000fff0) + band(op, 15), 4)\n    elseif p == \"s\" then\n      if band(op, 0x00100000) ~= 0 then suffix = \"s\"..suffix end\n    else\n      assert(false)\n    end\n    if x then\n      last = x\n      if type(x) == \"number\" then x = \"#\"..x end\n      operands[#operands+1] = x\n    end\n  end\n\n  return putop(ctx, name..suffix, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  ctx.pos = ofs\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 16 then return map_gpr[r] end\n  return \"d\"..(r-16)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  disass = disass,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_arm64.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT ARM64 disassembler module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n--\n-- Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.\n-- Sponsored by Cisco Systems, Inc.\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles most user-mode AArch64 instructions.\n-- NYI: Advanced SIMD and VFP instructions.\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, bxor, tohex = bit.band, bit.bor, bit.bxor, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\nlocal ror = bit.ror\n\n------------------------------------------------------------------------------\n-- Opcode maps\n------------------------------------------------------------------------------\n\nlocal map_adr = { -- PC-relative addressing.\n  shift = 31, mask = 1,\n  [0] = \"adrDBx\", \"adrpDBx\"\n}\n\nlocal map_addsubi = { -- Add/subtract immediate.\n  shift = 29, mask = 3,\n  [0] = \"add|movDNIg\", \"adds|cmnD0NIg\", \"subDNIg\", \"subs|cmpD0NIg\",\n}\n\nlocal map_logi = { -- Logical immediate.\n  shift = 31, mask = 1,\n  [0] = {\n    shift = 22, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = \"andDNig\", \"orr|movDN0ig\", \"eorDNig\", \"ands|tstD0Nig\"\n    },\n    false -- unallocated\n  },\n  {\n    shift = 29, mask = 3,\n    [0] = \"andDNig\", \"orr|movDN0ig\", \"eorDNig\", \"ands|tstD0Nig\"\n  }\n}\n\nlocal map_movwi = { -- Move wide immediate.\n  shift = 31, mask = 1,\n  [0] = {\n    shift = 22, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = \"movnDWRg\", false, \"movz|movDYRg\", \"movkDWRg\"\n    }, false -- unallocated\n  },\n  {\n    shift = 29, mask = 3,\n    [0] = \"movnDWRg\", false, \"movz|movDYRg\", \"movkDWRg\"\n  },\n}\n\nlocal map_bitf = { -- Bitfield.\n  shift = 31, mask = 1,\n  [0] = {\n    shift = 22, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = \"sbfm|sbfiz|sbfx|asr|sxtw|sxth|sxtbDN12w\",\n      \"bfm|bfi|bfxilDN13w\",\n      \"ubfm|ubfiz|ubfx|lsr|lsl|uxth|uxtbDN12w\"\n    }\n  },\n  {\n    shift = 22, mask = 1,\n    {\n      shift = 29, mask = 3,\n      [0] = \"sbfm|sbfiz|sbfx|asr|sxtw|sxth|sxtbDN12x\",\n      \"bfm|bfi|bfxilDN13x\",\n      \"ubfm|ubfiz|ubfx|lsr|lsl|uxth|uxtbDN12x\"\n    }\n  }\n}\n\nlocal map_datai = { -- Data processing - immediate.\n  shift = 23, mask = 7,\n  [0] = map_adr, map_adr, map_addsubi, false,\n  map_logi, map_movwi, map_bitf,\n  {\n    shift = 15, mask = 0x1c0c1,\n    [0] = \"extr|rorDNM4w\", [0x10080] = \"extr|rorDNM4x\",\n    [0x10081] = \"extr|rorDNM4x\"\n  }\n}\n\nlocal map_logsr = { -- Logical, shifted register.\n  shift = 31, mask = 1,\n  [0] = {\n    shift = 15, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = {\n\tshift = 21, mask = 7,\n\t[0] = \"andDNMSg\", \"bicDNMSg\", \"andDNMSg\", \"bicDNMSg\",\n\t\"andDNMSg\", \"bicDNMSg\", \"andDNMg\", \"bicDNMg\"\n      },\n      {\n\tshift = 21, mask = 7,\n\t[0] =\"orr|movDN0MSg\", \"orn|mvnDN0MSg\", \"orr|movDN0MSg\", \"orn|mvnDN0MSg\",\n\t     \"orr|movDN0MSg\", \"orn|mvnDN0MSg\", \"orr|movDN0Mg\", \"orn|mvnDN0Mg\"\n      },\n      {\n\tshift = 21, mask = 7,\n\t[0] = \"eorDNMSg\", \"eonDNMSg\", \"eorDNMSg\", \"eonDNMSg\",\n\t\"eorDNMSg\", \"eonDNMSg\", \"eorDNMg\", \"eonDNMg\"\n      },\n      {\n\tshift = 21, mask = 7,\n\t[0] = \"ands|tstD0NMSg\", \"bicsDNMSg\", \"ands|tstD0NMSg\", \"bicsDNMSg\",\n\t\"ands|tstD0NMSg\", \"bicsDNMSg\", \"ands|tstD0NMg\", \"bicsDNMg\"\n      }\n    },\n    false -- unallocated\n  },\n  {\n    shift = 29, mask = 3,\n    [0] = {\n      shift = 21, mask = 7,\n      [0] = \"andDNMSg\", \"bicDNMSg\", \"andDNMSg\", \"bicDNMSg\",\n      \"andDNMSg\", \"bicDNMSg\", \"andDNMg\", \"bicDNMg\"\n    },\n    {\n      shift = 21, mask = 7,\n      [0] = \"orr|movDN0MSg\", \"orn|mvnDN0MSg\", \"orr|movDN0MSg\", \"orn|mvnDN0MSg\",\n      \"orr|movDN0MSg\", \"orn|mvnDN0MSg\", \"orr|movDN0Mg\", \"orn|mvnDN0Mg\"\n    },\n    {\n      shift = 21, mask = 7,\n      [0] = \"eorDNMSg\", \"eonDNMSg\", \"eorDNMSg\", \"eonDNMSg\",\n      \"eorDNMSg\", \"eonDNMSg\", \"eorDNMg\", \"eonDNMg\"\n    },\n    {\n      shift = 21, mask = 7,\n      [0] = \"ands|tstD0NMSg\", \"bicsDNMSg\", \"ands|tstD0NMSg\", \"bicsDNMSg\",\n      \"ands|tstD0NMSg\", \"bicsDNMSg\", \"ands|tstD0NMg\", \"bicsDNMg\"\n    }\n  }\n}\n\nlocal map_assh = {\n  shift = 31, mask = 1,\n  [0] = {\n    shift = 15, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = {\n\tshift = 22, mask = 3,\n\t[0] = \"addDNMSg\", \"addDNMSg\", \"addDNMSg\", \"addDNMg\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"adds|cmnD0NMSg\", \"adds|cmnD0NMSg\",\n\t      \"adds|cmnD0NMSg\", \"adds|cmnD0NMg\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"sub|negDN0MSg\", \"sub|negDN0MSg\", \"sub|negDN0MSg\", \"sub|negDN0Mg\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"subs|cmp|negsD0N0MzSg\", \"subs|cmp|negsD0N0MzSg\",\n\t      \"subs|cmp|negsD0N0MzSg\", \"subs|cmp|negsD0N0Mzg\"\n      },\n    },\n    false -- unallocated\n  },\n  {\n    shift = 29, mask = 3,\n    [0] = {\n      shift = 22, mask = 3,\n      [0] = \"addDNMSg\", \"addDNMSg\", \"addDNMSg\", \"addDNMg\"\n    },\n    {\n      shift = 22, mask = 3,\n      [0] = \"adds|cmnD0NMSg\", \"adds|cmnD0NMSg\", \"adds|cmnD0NMSg\",\n\t    \"adds|cmnD0NMg\"\n    },\n    {\n      shift = 22, mask = 3,\n      [0] = \"sub|negDN0MSg\", \"sub|negDN0MSg\", \"sub|negDN0MSg\", \"sub|negDN0Mg\"\n    },\n    {\n      shift = 22, mask = 3,\n      [0] = \"subs|cmp|negsD0N0MzSg\", \"subs|cmp|negsD0N0MzSg\",\n\t    \"subs|cmp|negsD0N0MzSg\", \"subs|cmp|negsD0N0Mzg\"\n    }\n  }\n}\n\nlocal map_addsubsh = { -- Add/subtract, shifted register.\n  shift = 22, mask = 3,\n  [0] = map_assh, map_assh, map_assh\n}\n\nlocal map_addsubex = { -- Add/subtract, extended register.\n  shift = 22, mask = 3,\n  [0] = {\n    shift = 29, mask = 3,\n    [0] = \"addDNMXg\", \"adds|cmnD0NMXg\", \"subDNMXg\", \"subs|cmpD0NMzXg\",\n  }\n}\n\nlocal map_addsubc = { -- Add/subtract, with carry.\n  shift = 10, mask = 63,\n  [0] = {\n    shift = 29, mask = 3,\n    [0] = \"adcDNMg\", \"adcsDNMg\", \"sbc|ngcDN0Mg\", \"sbcs|ngcsDN0Mg\",\n  }\n}\n\nlocal map_ccomp = {\n  shift = 4, mask = 1,\n  [0] = {\n    shift = 10, mask = 3,\n    [0] = { -- Conditional compare register.\n      shift = 29, mask = 3,\n      \"ccmnNMVCg\", false, \"ccmpNMVCg\",\n    },\n    [2] = {  -- Conditional compare immediate.\n      shift = 29, mask = 3,\n      \"ccmnN5VCg\", false, \"ccmpN5VCg\",\n    }\n  }\n}\n\nlocal map_csel = { -- Conditional select.\n  shift = 11, mask = 1,\n  [0] = {\n    shift = 10, mask = 1,\n    [0] = {\n      shift = 29, mask = 3,\n      [0] = \"cselDNMzCg\", false, \"csinv|cinv|csetmDNMcg\", false,\n    },\n    {\n      shift = 29, mask = 3,\n      [0] = \"csinc|cinc|csetDNMcg\", false, \"csneg|cnegDNMcg\", false,\n    }\n  }\n}\n\nlocal map_data1s = { -- Data processing, 1 source.\n  shift = 29, mask = 1,\n  [0] = {\n    shift = 31, mask = 1,\n    [0] = {\n      shift = 10, mask = 0x7ff,\n      [0] = \"rbitDNg\", \"rev16DNg\", \"revDNw\", false, \"clzDNg\", \"clsDNg\"\n    },\n    {\n      shift = 10, mask = 0x7ff,\n      [0] = \"rbitDNg\", \"rev16DNg\", \"rev32DNx\", \"revDNx\", \"clzDNg\", \"clsDNg\"\n    }\n  }\n}\n\nlocal map_data2s = { -- Data processing, 2 sources.\n  shift = 29, mask = 1,\n  [0] = {\n    shift = 10, mask = 63,\n    false, \"udivDNMg\", \"sdivDNMg\", false, false, false, false, \"lslDNMg\",\n    \"lsrDNMg\", \"asrDNMg\", \"rorDNMg\"\n  }\n}\n\nlocal map_data3s = { -- Data processing, 3 sources.\n  shift = 29, mask = 7,\n  [0] = {\n    shift = 21, mask = 7,\n    [0] = {\n      shift = 15, mask = 1,\n      [0] = \"madd|mulDNMA0g\", \"msub|mnegDNMA0g\"\n    }\n  }, false, false, false,\n  {\n    shift = 15, mask = 1,\n    [0] = {\n      shift = 21, mask = 7,\n      [0] = \"madd|mulDNMA0g\", \"smaddl|smullDxNMwA0x\", \"smulhDNMx\", false,\n      false, \"umaddl|umullDxNMwA0x\", \"umulhDNMx\"\n    },\n    {\n      shift = 21, mask = 7,\n      [0] = \"msub|mnegDNMA0g\", \"smsubl|smneglDxNMwA0x\", false, false,\n      false, \"umsubl|umneglDxNMwA0x\"\n    }\n  }\n}\n\nlocal map_datar = { -- Data processing, register.\n  shift = 28, mask = 1,\n  [0] = {\n    shift = 24, mask = 1,\n    [0] = map_logsr,\n    {\n      shift = 21, mask = 1,\n      [0] = map_addsubsh, map_addsubex\n    }\n  },\n  {\n    shift = 21, mask = 15,\n    [0] = map_addsubc, false, map_ccomp, false, map_csel, false,\n    {\n      shift = 30, mask = 1,\n      [0] = map_data2s, map_data1s\n    },\n    false, map_data3s, map_data3s, map_data3s, map_data3s, map_data3s,\n    map_data3s, map_data3s, map_data3s\n  }\n}\n\nlocal map_lrl = { -- Load register, literal.\n  shift = 26, mask = 1,\n  [0] = {\n    shift = 30, mask = 3,\n    [0] = \"ldrDwB\", \"ldrDxB\", \"ldrswDxB\"\n  },\n  {\n    shift = 30, mask = 3,\n    [0] = \"ldrDsB\", \"ldrDdB\"\n  }\n}\n\nlocal map_lsriind = { -- Load/store register, immediate pre/post-indexed.\n  shift = 30, mask = 3,\n  [0] = {\n    shift = 26, mask = 1,\n    [0] = {\n      shift = 22, mask = 3,\n      [0] = \"strbDwzL\", \"ldrbDwzL\", \"ldrsbDxzL\", \"ldrsbDwzL\"\n    }\n  },\n  {\n    shift = 26, mask = 1,\n    [0] = {\n      shift = 22, mask = 3,\n      [0] = \"strhDwzL\", \"ldrhDwzL\", \"ldrshDxzL\", \"ldrshDwzL\"\n    }\n  },\n  {\n    shift = 26, mask = 1,\n    [0] = {\n      shift = 22, mask = 3,\n      [0] = \"strDwzL\", \"ldrDwzL\", \"ldrswDxzL\"\n    },\n    {\n      shift = 22, mask = 3,\n      [0] = \"strDszL\", \"ldrDszL\"\n    }\n  },\n  {\n    shift = 26, mask = 1,\n    [0] = {\n      shift = 22, mask = 3,\n      [0] = \"strDxzL\", \"ldrDxzL\"\n    },\n    {\n      shift = 22, mask = 3,\n      [0] = \"strDdzL\", \"ldrDdzL\"\n    }\n  }\n}\n\nlocal map_lsriro = {\n  shift = 21, mask = 1,\n  [0] = {  -- Load/store register immediate.\n    shift = 10, mask = 3,\n    [0] = { -- Unscaled immediate.\n      shift = 26, mask = 1,\n      [0] = {\n\tshift = 30, mask = 3,\n\t[0] = {\n\t  shift = 22, mask = 3,\n\t  [0] = \"sturbDwK\", \"ldurbDwK\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"sturhDwK\", \"ldurhDwK\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"sturDwK\", \"ldurDwK\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"sturDxK\", \"ldurDxK\"\n\t}\n      }\n    }, map_lsriind, false, map_lsriind\n  },\n  {  -- Load/store register, register offset.\n    shift = 10, mask = 3,\n    [2] = {\n      shift = 26, mask = 1,\n      [0] = {\n\tshift = 30, mask = 3,\n\t[0] = {\n\t  shift = 22, mask = 3,\n\t  [0] = \"strbDwO\", \"ldrbDwO\", \"ldrsbDxO\", \"ldrsbDwO\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"strhDwO\", \"ldrhDwO\", \"ldrshDxO\", \"ldrshDwO\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"strDwO\", \"ldrDwO\", \"ldrswDxO\"\n\t},\n\t{\n\t  shift = 22, mask = 3,\n\t  [0] = \"strDxO\", \"ldrDxO\"\n\t}\n      },\n      {\n\tshift = 30, mask = 3,\n\t[2] = {\n\t  shift = 22, mask = 3,\n\t  [0] = \"strDsO\", \"ldrDsO\"\n\t},\n\t[3] = {\n\t  shift = 22, mask = 3,\n\t  [0] = \"strDdO\", \"ldrDdO\"\n\t}\n      }\n    }\n  }\n}\n\nlocal map_lsp = { -- Load/store register pair, offset.\n  shift = 22, mask = 1,\n  [0] = {\n    shift = 30, mask = 3,\n    [0] = {\n      shift = 26, mask = 1,\n      [0] = \"stpDzAzwP\", \"stpDzAzsP\",\n    },\n    {\n      shift = 26, mask = 1,\n      \"stpDzAzdP\"\n    },\n    {\n      shift = 26, mask = 1,\n      [0] = \"stpDzAzxP\"\n    }\n  },\n  {\n    shift = 30, mask = 3,\n    [0] = {\n      shift = 26, mask = 1,\n      [0] = \"ldpDzAzwP\", \"ldpDzAzsP\",\n    },\n    {\n      shift = 26, mask = 1,\n      [0] = \"ldpswDAxP\", \"ldpDzAzdP\"\n    },\n    {\n      shift = 26, mask = 1,\n      [0] = \"ldpDzAzxP\"\n    }\n  }\n}\n\nlocal map_ls = { -- Loads and stores.\n  shift = 24, mask = 0x31,\n  [0x10] = map_lrl, [0x30] = map_lsriro,\n  [0x20] = {\n    shift = 23, mask = 3,\n    map_lsp, map_lsp, map_lsp\n  },\n  [0x21] = {\n    shift = 23, mask = 3,\n    map_lsp, map_lsp, map_lsp\n  },\n  [0x31] = {\n    shift = 26, mask = 1,\n    [0] = {\n      shift = 30, mask = 3,\n      [0] = {\n\tshift = 22, mask = 3,\n\t[0] = \"strbDwzU\", \"ldrbDwzU\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"strhDwzU\", \"ldrhDwzU\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"strDwzU\", \"ldrDwzU\"\n      },\n      {\n\tshift = 22, mask = 3,\n\t[0] = \"strDxzU\", \"ldrDxzU\"\n      }\n    },\n    {\n      shift = 30, mask = 3,\n      [2] = {\n\tshift = 22, mask = 3,\n\t[0] = \"strDszU\", \"ldrDszU\"\n      },\n      [3] = {\n\tshift = 22, mask = 3,\n\t[0] = \"strDdzU\", \"ldrDdzU\"\n      }\n    }\n  },\n}\n\nlocal map_datafp = { -- Data processing, SIMD and FP.\n  shift = 28, mask = 7,\n  { -- 001\n    shift = 24, mask = 1,\n    [0] = {\n      shift = 21, mask = 1,\n      {\n\tshift = 10, mask = 3,\n\t[0] = {\n\t  shift = 12, mask = 1,\n\t  [0] = {\n\t    shift = 13, mask = 1,\n\t    [0] = {\n\t      shift = 14, mask = 1,\n\t      [0] = {\n\t\tshift = 15, mask = 1,\n\t\t[0] = { -- FP/int conversion.\n\t\t  shift = 31, mask = 1,\n\t\t  [0] = {\n\t\t    shift = 16, mask = 0xff,\n\t\t    [0x20] = \"fcvtnsDwNs\", [0x21] = \"fcvtnuDwNs\",\n\t\t    [0x22] = \"scvtfDsNw\", [0x23] = \"ucvtfDsNw\",\n\t\t    [0x24] = \"fcvtasDwNs\", [0x25] = \"fcvtauDwNs\",\n\t\t    [0x26] = \"fmovDwNs\", [0x27] = \"fmovDsNw\",\n\t\t    [0x28] = \"fcvtpsDwNs\", [0x29] = \"fcvtpuDwNs\",\n\t\t    [0x30] = \"fcvtmsDwNs\", [0x31] = \"fcvtmuDwNs\",\n\t\t    [0x38] = \"fcvtzsDwNs\", [0x39] = \"fcvtzuDwNs\",\n\t\t    [0x60] = \"fcvtnsDwNd\", [0x61] = \"fcvtnuDwNd\",\n\t\t    [0x62] = \"scvtfDdNw\", [0x63] = \"ucvtfDdNw\",\n\t\t    [0x64] = \"fcvtasDwNd\", [0x65] = \"fcvtauDwNd\",\n\t\t    [0x68] = \"fcvtpsDwNd\", [0x69] = \"fcvtpuDwNd\",\n\t\t    [0x70] = \"fcvtmsDwNd\", [0x71] = \"fcvtmuDwNd\",\n\t\t    [0x78] = \"fcvtzsDwNd\", [0x79] = \"fcvtzuDwNd\"\n\t\t  },\n\t\t  {\n\t\t    shift = 16, mask = 0xff,\n\t\t    [0x20] = \"fcvtnsDxNs\", [0x21] = \"fcvtnuDxNs\",\n\t\t    [0x22] = \"scvtfDsNx\", [0x23] = \"ucvtfDsNx\",\n\t\t    [0x24] = \"fcvtasDxNs\", [0x25] = \"fcvtauDxNs\",\n\t\t    [0x28] = \"fcvtpsDxNs\", [0x29] = \"fcvtpuDxNs\",\n\t\t    [0x30] = \"fcvtmsDxNs\", [0x31] = \"fcvtmuDxNs\",\n\t\t    [0x38] = \"fcvtzsDxNs\", [0x39] = \"fcvtzuDxNs\",\n\t\t    [0x60] = \"fcvtnsDxNd\", [0x61] = \"fcvtnuDxNd\",\n\t\t    [0x62] = \"scvtfDdNx\", [0x63] = \"ucvtfDdNx\",\n\t\t    [0x64] = \"fcvtasDxNd\", [0x65] = \"fcvtauDxNd\",\n\t\t    [0x66] = \"fmovDxNd\", [0x67] = \"fmovDdNx\",\n\t\t    [0x68] = \"fcvtpsDxNd\", [0x69] = \"fcvtpuDxNd\",\n\t\t    [0x70] = \"fcvtmsDxNd\", [0x71] = \"fcvtmuDxNd\",\n\t\t    [0x78] = \"fcvtzsDxNd\", [0x79] = \"fcvtzuDxNd\"\n\t\t  }\n\t\t}\n\t      },\n\t      { -- FP data-processing, 1 source.\n\t\tshift = 31, mask = 1,\n\t\t[0] = {\n\t\t  shift = 22, mask = 3,\n\t\t  [0] = {\n\t\t    shift = 15, mask = 63,\n\t\t    [0] = \"fmovDNf\", \"fabsDNf\", \"fnegDNf\",\n\t\t    \"fsqrtDNf\", false, \"fcvtDdNs\", false, false,\n\t\t    \"frintnDNf\", \"frintpDNf\", \"frintmDNf\", \"frintzDNf\",\n\t\t    \"frintaDNf\", false, \"frintxDNf\", \"frintiDNf\",\n\t\t  },\n\t\t  {\n\t\t    shift = 15, mask = 63,\n\t\t    [0] = \"fmovDNf\", \"fabsDNf\", \"fnegDNf\",\n\t\t    \"fsqrtDNf\", \"fcvtDsNd\", false, false, false,\n\t\t    \"frintnDNf\", \"frintpDNf\", \"frintmDNf\", \"frintzDNf\",\n\t\t    \"frintaDNf\", false, \"frintxDNf\", \"frintiDNf\",\n\t\t  }\n\t\t}\n\t      }\n\t    },\n\t    { -- FP compare.\n\t      shift = 31, mask = 1,\n\t      [0] = {\n\t\tshift = 14, mask = 3,\n\t\t[0] = {\n\t\t  shift = 23, mask = 1,\n\t\t  [0] = {\n\t\t    shift = 0, mask = 31,\n\t\t    [0] = \"fcmpNMf\", [8] = \"fcmpNZf\",\n\t\t    [16] = \"fcmpeNMf\", [24] = \"fcmpeNZf\",\n\t\t  }\n\t\t}\n\t      }\n\t    }\n\t  },\n\t  { -- FP immediate.\n\t    shift = 31, mask = 1,\n\t    [0] = {\n\t      shift = 5, mask = 31,\n\t      [0] = {\n\t\tshift = 23, mask = 1,\n\t\t[0] = \"fmovDFf\"\n\t      }\n\t    }\n\t  }\n\t},\n\t{ -- FP conditional compare.\n\t  shift = 31, mask = 1,\n\t  [0] = {\n\t    shift = 23, mask = 1,\n\t    [0] = {\n\t      shift = 4, mask = 1,\n\t      [0] = \"fccmpNMVCf\", \"fccmpeNMVCf\"\n\t    }\n\t  }\n\t},\n\t{ -- FP data-processing, 2 sources.\n\t  shift = 31, mask = 1,\n\t  [0] = {\n\t    shift = 23, mask = 1,\n\t    [0] = {\n\t      shift = 12, mask = 15,\n\t      [0] = \"fmulDNMf\", \"fdivDNMf\", \"faddDNMf\", \"fsubDNMf\",\n\t      \"fmaxDNMf\", \"fminDNMf\", \"fmaxnmDNMf\", \"fminnmDNMf\",\n\t      \"fnmulDNMf\"\n\t    }\n\t  }\n\t},\n\t{ -- FP conditional select.\n\t  shift = 31, mask = 1,\n\t  [0] = {\n\t    shift = 23, mask = 1,\n\t    [0] = \"fcselDNMCf\"\n\t  }\n\t}\n      }\n    },\n    { -- FP data-processing, 3 sources.\n      shift = 31, mask = 1,\n      [0] = {\n\tshift = 15, mask = 1,\n\t[0] = {\n\t  shift = 21, mask = 5,\n\t  [0] = \"fmaddDNMAf\", \"fnmaddDNMAf\"\n\t},\n\t{\n\t  shift = 21, mask = 5,\n\t  [0] = \"fmsubDNMAf\", \"fnmsubDNMAf\"\n\t}\n      }\n    }\n  }\n}\n\nlocal map_br = { -- Branches, exception generating and system instructions.\n  shift = 29, mask = 7,\n  [0] = \"bB\",\n  { -- Compare & branch, immediate.\n    shift = 24, mask = 3,\n    [0] = \"cbzDBg\", \"cbnzDBg\", \"tbzDTBw\", \"tbnzDTBw\"\n  },\n  { -- Conditional branch, immediate.\n    shift = 24, mask = 3,\n    [0] = {\n      shift = 4, mask = 1,\n      [0] = {\n\tshift = 0, mask = 15,\n\t[0] = \"beqB\", \"bneB\", \"bhsB\", \"bloB\", \"bmiB\", \"bplB\", \"bvsB\", \"bvcB\",\n\t\"bhiB\", \"blsB\", \"bgeB\", \"bltB\", \"bgtB\", \"bleB\", \"balB\"\n      }\n    }\n  }, false, \"blB\",\n  { -- Compare & branch, immediate.\n    shift = 24, mask = 3,\n    [0] = \"cbzDBg\", \"cbnzDBg\", \"tbzDTBx\", \"tbnzDTBx\"\n  },\n  {\n    shift = 24, mask = 3,\n    [0] = { -- Exception generation.\n      shift = 0, mask = 0xe0001f,\n      [0x200000] = \"brkW\"\n    },\n    { -- System instructions.\n      shift = 0, mask = 0x3fffff,\n      [0x03201f] = \"nop\"\n    },\n    { -- Unconditional branch, register.\n      shift = 0, mask = 0xfffc1f,\n      [0x1f0000] = \"brNx\", [0x3f0000] = \"blrNx\",\n      [0x5f0000] = \"retNx\"\n    },\n  }\n}\n\nlocal map_init = {\n  shift = 25, mask = 15,\n  [0] = false, false, false, false, map_ls, map_datar, map_ls, map_datafp,\n  map_datai, map_datai, map_br, map_br, map_ls, map_datar, map_ls, map_datafp\n}\n\n------------------------------------------------------------------------------\n\nlocal map_regs = { x = {}, w = {}, d = {}, s = {} }\n\nfor i=0,30 do\n  map_regs.x[i] = \"x\"..i\n  map_regs.w[i] = \"w\"..i\n  map_regs.d[i] = \"d\"..i\n  map_regs.s[i] = \"s\"..i\nend\nmap_regs.x[31] = \"sp\"\nmap_regs.w[31] = \"wsp\"\nmap_regs.d[31] = \"d31\"\nmap_regs.s[31] = \"s31\"\n\nlocal map_cond = {\n  [0] = \"eq\", \"ne\", \"cs\", \"cc\", \"mi\", \"pl\", \"vs\", \"vc\",\n  \"hi\", \"ls\", \"ge\", \"lt\", \"gt\", \"le\", \"al\",\n}\n\nlocal map_shift = { [0] = \"lsl\", \"lsr\", \"asr\", }\n\nlocal map_extend = {\n  [0] = \"uxtb\", \"uxth\", \"uxtw\", \"uxtx\", \"sxtb\", \"sxth\", \"sxtw\", \"sxtx\",\n}\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then\n      extra = \"\\t->\"..sym\n    end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-5s %s%s\\n\",\n      ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-5s %s%s\\n\",\n      ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\nlocal function match_reg(p, pat, regnum)\n  return map_regs[match(pat, p..\"%w-([xwds])\")][regnum]\nend\n\nlocal function fmt_hex32(x)\n  if x < 0 then\n    return tohex(x)\n  else\n    return format(\"%x\", x)\n  end\nend\n\nlocal imm13_rep = { 0x55555555, 0x11111111, 0x01010101, 0x00010001, 0x00000001 }\n\nlocal function decode_imm13(op)\n  local imms = band(rshift(op, 10), 63)\n  local immr = band(rshift(op, 16), 63)\n  if band(op, 0x00400000) == 0 then\n    local len = 5\n    if imms >= 56 then\n      if imms >= 60 then len = 1 else len = 2 end\n    elseif imms >= 48 then len = 3 elseif imms >= 32 then len = 4 end\n    local l = lshift(1, len)-1\n    local s = band(imms, l)\n    local r = band(immr, l)\n    local imm = ror(rshift(-1, 31-s), r)\n    if len ~= 5 then imm = band(imm, lshift(1, l)-1) + rshift(imm, 31-l) end\n    imm = imm * imm13_rep[len]\n    local ix = fmt_hex32(imm)\n    if rshift(op, 31) ~= 0 then\n      return ix..tohex(imm)\n    else\n      return ix\n    end\n  else\n    local lo, hi = -1, 0\n    if imms < 32 then lo = rshift(-1, 31-imms) else hi = rshift(-1, 63-imms) end\n    if immr ~= 0 then\n      lo, hi = ror(lo, immr), ror(hi, immr)\n      local x = immr == 32 and 0 or band(bxor(lo, hi), lshift(-1, 32-immr))\n      lo, hi = bxor(lo, x), bxor(hi, x)\n      if immr >= 32 then lo, hi = hi, lo end\n    end\n    if hi ~= 0 then\n      return fmt_hex32(hi)..tohex(lo)\n    else\n      return fmt_hex32(lo)\n    end\n  end\nend\n\nlocal function parse_immpc(op, name)\n  if name == \"b\" or name == \"bl\" then\n    return arshift(lshift(op, 6), 4)\n  elseif name == \"adr\" or name == \"adrp\" then\n    local immlo = band(rshift(op, 29), 3)\n    local immhi = lshift(arshift(lshift(op, 8), 13), 2)\n    return bor(immhi, immlo)\n  elseif name == \"tbz\" or name == \"tbnz\" then\n    return lshift(arshift(lshift(op, 13), 18), 2)\n  else\n    return lshift(arshift(lshift(op, 8), 13), 2)\n  end\nend\n\nlocal function parse_fpimm8(op)\n  local sign = band(op, 0x100000) == 0 and 1 or -1\n  local exp = bxor(rshift(arshift(lshift(op, 12), 5), 24), 0x80) - 131\n  local frac = 16+band(rshift(op, 13), 15)\n  return sign * frac * 2^exp\nend\n\nlocal function prefer_bfx(sf, uns, imms, immr)\n  if imms < immr or imms == 31 or imms == 63 then\n    return false\n  end\n  if immr == 0 then\n    if sf == 0 and (imms == 7 or imms == 15) then\n      return false\n    end\n    if sf ~= 0 and uns == 0 and (imms == 7 or imms == 15 or imms == 31) then\n      return false\n    end\n  end\n  return true\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)\n  local operands = {}\n  local suffix = \"\"\n  local last, name, pat\n  local map_reg\n  ctx.op = op\n  ctx.rel = nil\n  last = nil\n  local opat\n  opat = map_init[band(rshift(op, 25), 15)]\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._\n  end\n  name, pat = match(opat, \"^([a-z0-9]*)(.*)\")\n  local altname, pat2 = match(pat, \"|([a-z0-9_.|]*)(.*)\")\n  if altname then pat = pat2 end\n  if sub(pat, 1, 1) == \".\" then\n    local s2, p2 = match(pat, \"^([a-z0-9.]*)(.*)\")\n    suffix = suffix..s2\n    pat = p2\n  end\n\n  local rt = match(pat, \"[gf]\")\n  if rt then\n    if rt == \"g\" then\n      map_reg = band(op, 0x80000000) ~= 0 and map_regs.x or map_regs.w\n    else\n      map_reg = band(op, 0x400000) ~= 0 and map_regs.d or map_regs.s\n    end\n  end\n\n  local second0, immr\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"D\" then\n      local regnum = band(op, 31)\n      x = rt and map_reg[regnum] or match_reg(p, pat, regnum)\n    elseif p == \"N\" then\n      local regnum = band(rshift(op, 5), 31)\n      x = rt and map_reg[regnum] or match_reg(p, pat, regnum)\n    elseif p == \"M\" then\n      local regnum = band(rshift(op, 16), 31)\n      x = rt and map_reg[regnum] or match_reg(p, pat, regnum)\n    elseif p == \"A\" then\n      local regnum = band(rshift(op, 10), 31)\n      x = rt and map_reg[regnum] or match_reg(p, pat, regnum)\n    elseif p == \"B\" then\n      local addr = ctx.addr + pos + parse_immpc(op, name)\n      ctx.rel = addr\n      x = \"0x\"..tohex(addr)\n    elseif p == \"T\" then\n      x = bor(band(rshift(op, 26), 32), band(rshift(op, 19), 31))\n    elseif p == \"V\" then\n      x = band(op, 15)\n    elseif p == \"C\" then\n      x = map_cond[band(rshift(op, 12), 15)]\n    elseif p == \"c\" then\n      local rn = band(rshift(op, 5), 31)\n      local rm = band(rshift(op, 16), 31)\n      local cond = band(rshift(op, 12), 15)\n      local invc = bxor(cond, 1)\n      x = map_cond[cond]\n      if altname and cond ~= 14 and cond ~= 15 then\n\tlocal a1, a2 = match(altname, \"([^|]*)|(.*)\")\n\tif rn == rm then\n\t  local n = #operands\n\t  operands[n] = nil\n\t  x = map_cond[invc]\n\t  if rn ~= 31 then\n\t    if a1 then name = a1 else name = altname end\n\t  else\n\t    operands[n-1] = nil\n\t    name = a2\n\t  end\n\tend\n      end\n    elseif p == \"W\" then\n      x = band(rshift(op, 5), 0xffff)\n    elseif p == \"Y\" then\n      x = band(rshift(op, 5), 0xffff)\n      local hw = band(rshift(op, 21), 3)\n      if altname and (hw == 0 or x ~= 0) then\n\tname = altname\n      end\n    elseif p == \"L\" then\n      local rn = map_regs.x[band(rshift(op, 5), 31)]\n      local imm9 = arshift(lshift(op, 11), 23)\n      if band(op, 0x800) ~= 0 then\n\tx = \"[\"..rn..\", #\"..imm9..\"]!\"\n      else\n\tx = \"[\"..rn..\"], #\"..imm9\n      end\n    elseif p == \"U\" then\n      local rn = map_regs.x[band(rshift(op, 5), 31)]\n      local sz = band(rshift(op, 30), 3)\n      local imm12 = lshift(arshift(lshift(op, 10), 20), sz)\n      if imm12 ~= 0 then\n\tx = \"[\"..rn..\", #\"..imm12..\"]\"\n      else\n\tx = \"[\"..rn..\"]\"\n      end\n    elseif p == \"K\" then\n      local rn = map_regs.x[band(rshift(op, 5), 31)]\n      local imm9 = arshift(lshift(op, 11), 23)\n      if imm9 ~= 0 then\n\tx = \"[\"..rn..\", #\"..imm9..\"]\"\n      else\n\tx = \"[\"..rn..\"]\"\n      end\n    elseif p == \"O\" then\n      local rn, rm = map_regs.x[band(rshift(op, 5), 31)]\n      local m = band(rshift(op, 13), 1)\n      if m == 0 then\n\trm = map_regs.w[band(rshift(op, 16), 31)]\n      else\n\trm = map_regs.x[band(rshift(op, 16), 31)]\n      end\n      x = \"[\"..rn..\", \"..rm\n      local opt = band(rshift(op, 13), 7)\n      local s = band(rshift(op, 12), 1)\n      local sz = band(rshift(op, 30), 3)\n      -- extension to be applied\n      if opt == 3 then\n       if s == 0 then x = x..\"]\"\n       else x = x..\", lsl #\"..sz..\"]\" end\n      elseif opt == 2 or opt == 6 or opt == 7 then\n\tif s == 0 then x = x..\", \"..map_extend[opt]..\"]\"\n\telse x = x..\", \"..map_extend[opt]..\" #\"..sz..\"]\" end\n      else\n\tx = x..\"]\"\n      end\n    elseif p == \"P\" then\n      local opcv, sh = rshift(op, 26), 2\n      if opcv >= 0x2a then sh = 4 elseif opcv >= 0x1b then sh = 3 end\n      local imm7 = lshift(arshift(lshift(op, 10), 25), sh)\n      local rn = map_regs.x[band(rshift(op, 5), 31)]\n      local ind = band(rshift(op, 23), 3)\n      if ind == 1 then\n\tx = \"[\"..rn..\"], #\"..imm7\n      elseif ind == 2 then\n\tif imm7 == 0 then\n\t  x = \"[\"..rn..\"]\"\n\telse\n\t  x = \"[\"..rn..\", #\"..imm7..\"]\"\n\tend\n      elseif ind == 3 then\n\tx = \"[\"..rn..\", #\"..imm7..\"]!\"\n      end\n    elseif p == \"I\" then\n      local shf = band(rshift(op, 22), 3)\n      local imm12 = band(rshift(op, 10), 0x0fff)\n      local rn, rd = band(rshift(op, 5), 31), band(op, 31)\n      if altname == \"mov\" and shf == 0 and imm12 == 0 and (rn == 31 or rd == 31) then\n\tname = altname\n\tx = nil\n      elseif shf == 0 then\n\tx = imm12\n      elseif shf == 1 then\n\tx = imm12..\", lsl #12\"\n      end\n    elseif p == \"i\" then\n      x = \"#0x\"..decode_imm13(op)\n    elseif p == \"1\" then\n      immr = band(rshift(op, 16), 63)\n      x = immr\n    elseif p == \"2\" then\n      x = band(rshift(op, 10), 63)\n      if altname then\n\tlocal a1, a2, a3, a4, a5, a6 =\n\t  match(altname, \"([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|(.*)\")\n\tlocal sf = band(rshift(op, 26), 32)\n\tlocal uns = band(rshift(op, 30), 1)\n\tif prefer_bfx(sf, uns, x, immr) then\n\t  name = a2\n\t  x = x - immr + 1\n\telseif immr == 0 and x == 7 then\n\t  local n = #operands\n\t  operands[n] = nil\n\t  if sf ~= 0 then\n\t    operands[n-1] = gsub(operands[n-1], \"x\", \"w\")\n\t  end\n\t  last = operands[n-1]\n\t  name = a6\n\t  x = nil\n\telseif immr == 0 and x == 15 then\n\t  local n = #operands\n\t  operands[n] = nil\n\t  if sf ~= 0 then\n\t    operands[n-1] = gsub(operands[n-1], \"x\", \"w\")\n\t  end\n\t  last = operands[n-1]\n\t  name = a5\n\t  x = nil\n\telseif x == 31 or x == 63 then\n\t  if x == 31 and immr == 0 and name == \"sbfm\" then\n\t    name = a4\n\t    local n = #operands\n\t    operands[n] = nil\n\t    if sf ~= 0 then\n\t      operands[n-1] = gsub(operands[n-1], \"x\", \"w\")\n\t    end\n\t    last = operands[n-1]\n\t  else\n\t    name = a3\n\t  end\n\t  x = nil\n\telseif band(x, 31) ~= 31 and immr == x+1 and name == \"ubfm\" then\n\t  name = a4\n\t  last = \"#\"..(sf+32 - immr)\n\t  operands[#operands] = last\n\t  x = nil\n\telseif x < immr then\n\t  name = a1\n\t  last = \"#\"..(sf+32 - immr)\n\t  operands[#operands] = last\n\t  x = x + 1\n\tend\n      end\n    elseif p == \"3\" then\n      x = band(rshift(op, 10), 63)\n      if altname then\n\tlocal a1, a2 = match(altname, \"([^|]*)|(.*)\")\n\tif x < immr then\n\t  name = a1\n\t  local sf = band(rshift(op, 26), 32)\n\t  last = \"#\"..(sf+32 - immr)\n\t  operands[#operands] = last\n\t  x = x + 1\n\telse\n\t  name = a2\n\t  x = x - immr + 1\n\tend\n      end\n    elseif p == \"4\" then\n      x = band(rshift(op, 10), 63)\n      local rn = band(rshift(op, 5), 31)\n      local rm = band(rshift(op, 16), 31)\n      if altname and rn == rm then\n\tlocal n = #operands\n\toperands[n] = nil\n\tlast = operands[n-1]\n\tname = altname\n      end\n    elseif p == \"5\" then\n      x = band(rshift(op, 16), 31)\n    elseif p == \"S\" then\n      x = band(rshift(op, 10), 63)\n      if x == 0 then x = nil\n      else x = map_shift[band(rshift(op, 22), 3)]..\" #\"..x end\n    elseif p == \"X\" then\n      local opt = band(rshift(op, 13), 7)\n      -- Width specifier <R>.\n      if opt ~= 3 and opt ~= 7 then\n\tlast = map_regs.w[band(rshift(op, 16), 31)]\n\toperands[#operands] = last\n      end\n      x = band(rshift(op, 10), 7)\n      -- Extension.\n      if opt == 2 + band(rshift(op, 31), 1) and\n\t band(rshift(op, second0 and 5 or 0), 31) == 31 then\n\tif x == 0 then x = nil\n\telse x = \"lsl #\"..x end\n      else\n\tif x == 0 then x = map_extend[band(rshift(op, 13), 7)]\n\telse x = map_extend[band(rshift(op, 13), 7)]..\" #\"..x end\n      end\n    elseif p == \"R\" then\n      x = band(rshift(op,21), 3)\n      if x == 0 then x = nil\n      else x = \"lsl #\"..x*16 end\n    elseif p == \"z\" then\n      local n = #operands\n      if operands[n] == \"sp\" then operands[n] = \"xzr\"\n      elseif operands[n] == \"wsp\" then operands[n] = \"wzr\"\n      end\n    elseif p == \"Z\" then\n      x = 0\n    elseif p == \"F\" then\n      x = parse_fpimm8(op)\n    elseif p == \"g\" or p == \"f\" or p == \"x\" or p == \"w\" or\n\t   p == \"d\" or p == \"s\" then\n      -- These are handled in D/N/M/A.\n    elseif p == \"0\" then\n      if last == \"sp\" or last == \"wsp\" then\n\tlocal n = #operands\n\toperands[n] = nil\n\tlast = operands[n-1]\n\tif altname then\n\t  local a1, a2 = match(altname, \"([^|]*)|(.*)\")\n\t  if not a1 then\n\t    name = altname\n\t  elseif second0 then\n\t    name, altname = a2, a1\n\t  else\n\t    name, altname = a1, a2\n\t  end\n\tend\n      end\n      second0 = true\n    else\n      assert(false)\n    end\n    if x then\n      last = x\n      if type(x) == \"number\" then x = \"#\"..x end\n      operands[#operands+1] = x\n    end\n  end\n\n  return putop(ctx, name..suffix, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  ctx.pos = ofs\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 32 then return map_regs.x[r] end\n  return map_regs.d[r-32]\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  disass = disass,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_arm64be.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT ARM64BE disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- ARM64 instructions are always little-endian. So just forward to the\n-- common ARM64 disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nreturn require((string.match(..., \".*%.\") or \"\")..\"dis_arm64\")\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mips.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS disassembler module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT/X license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles all standard MIPS32R1/R2 instructions.\n-- Default mode is big-endian, but see: dis_mipsel.lua\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal byte, format = string.byte, string.format\nlocal match, gmatch = string.match, string.gmatch\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, tohex = bit.band, bit.bor, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Extended opcode maps common to all MIPS releases\n------------------------------------------------------------------------------\n\nlocal map_srl = { shift = 21, mask = 1, [0] = \"srlDTA\", \"rotrDTA\", }\nlocal map_srlv = { shift = 6, mask = 1, [0] = \"srlvDTS\", \"rotrvDTS\", }\n\nlocal map_cop0 = {\n  shift = 25, mask = 1,\n  [0] = {\n    shift = 21, mask = 15,\n    [0] = \"mfc0TDW\", [4] = \"mtc0TDW\",\n    [10] = \"rdpgprDT\",\n    [11] = { shift = 5, mask = 1, [0] = \"diT0\", \"eiT0\", },\n    [14] = \"wrpgprDT\",\n  }, {\n    shift = 0, mask = 63,\n    [1] = \"tlbr\", [2] = \"tlbwi\", [6] = \"tlbwr\", [8] = \"tlbp\",\n    [24] = \"eret\", [31] = \"deret\",\n    [32] = \"wait\",\n  },\n}\n\n------------------------------------------------------------------------------\n-- Primary and extended opcode maps for MIPS R1-R5\n------------------------------------------------------------------------------\n\nlocal map_movci = { shift = 16, mask = 1, [0] = \"movfDSC\", \"movtDSC\", }\n\nlocal map_special = {\n  shift = 0, mask = 63,\n  [0] = { shift = 0, mask = -1, [0] = \"nop\", _ = \"sllDTA\" },\n  map_movci,\tmap_srl,\t\"sraDTA\",\n  \"sllvDTS\",\tfalse,\t\tmap_srlv,\t\"sravDTS\",\n  \"jrS\",\t\"jalrD1S\",\t\"movzDST\",\t\"movnDST\",\n  \"syscallY\",\t\"breakY\",\tfalse,\t\t\"sync\",\n  \"mfhiD\",\t\"mthiS\",\t\"mfloD\",\t\"mtloS\",\n  \"dsllvDST\",\tfalse,\t\t\"dsrlvDST\",\t\"dsravDST\",\n  \"multST\",\t\"multuST\",\t\"divST\",\t\"divuST\",\n  \"dmultST\",\t\"dmultuST\",\t\"ddivST\",\t\"ddivuST\",\n  \"addDST\",\t\"addu|moveDST0\", \"subDST\",\t\"subu|neguDS0T\",\n  \"andDST\",\t\"or|moveDST0\",\t\"xorDST\",\t\"nor|notDST0\",\n  false,\tfalse,\t\t\"sltDST\",\t\"sltuDST\",\n  \"daddDST\",\t\"dadduDST\",\t\"dsubDST\",\t\"dsubuDST\",\n  \"tgeSTZ\",\t\"tgeuSTZ\",\t\"tltSTZ\",\t\"tltuSTZ\",\n  \"teqSTZ\",\tfalse,\t\t\"tneSTZ\",\tfalse,\n  \"dsllDTA\",\tfalse,\t\t\"dsrlDTA\",\t\"dsraDTA\",\n  \"dsll32DTA\",\tfalse,\t\t\"dsrl32DTA\",\t\"dsra32DTA\",\n}\n\nlocal map_special2 = {\n  shift = 0, mask = 63,\n  [0] = \"maddST\", \"madduST\",\t\"mulDST\",\tfalse,\n  \"msubST\",\t\"msubuST\",\n  [32] = \"clzDS\", [33] = \"cloDS\",\n  [63] = \"sdbbpY\",\n}\n\nlocal map_bshfl = {\n  shift = 6, mask = 31,\n  [2] = \"wsbhDT\",\n  [16] = \"sebDT\",\n  [24] = \"sehDT\",\n}\n\nlocal map_dbshfl = {\n  shift = 6, mask = 31,\n  [2] = \"dsbhDT\",\n  [5] = \"dshdDT\",\n}\n\nlocal map_special3 = {\n  shift = 0, mask = 63,\n  [0]  = \"extTSAK\", [1]  = \"dextmTSAP\", [3]  = \"dextTSAK\",\n  [4]  = \"insTSAL\", [6]  = \"dinsuTSEQ\", [7]  = \"dinsTSAL\",\n  [32] = map_bshfl, [36] = map_dbshfl,  [59] = \"rdhwrTD\",\n}\n\nlocal map_regimm = {\n  shift = 16, mask = 31,\n  [0] = \"bltzSB\",\t\"bgezSB\",\t\"bltzlSB\",\t\"bgezlSB\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"tgeiSI\",\t\"tgeiuSI\",\t\"tltiSI\",\t\"tltiuSI\",\n  \"teqiSI\",\tfalse,\t\t\"tneiSI\",\tfalse,\n  \"bltzalSB\",\t\"bgezalSB\",\t\"bltzallSB\",\t\"bgezallSB\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\t\"synciSO\",\n}\n\nlocal map_cop1s = {\n  shift = 0, mask = 63,\n  [0] = \"add.sFGH\",\t\"sub.sFGH\",\t\"mul.sFGH\",\t\"div.sFGH\",\n  \"sqrt.sFG\",\t\t\"abs.sFG\",\t\"mov.sFG\",\t\"neg.sFG\",\n  \"round.l.sFG\",\t\"trunc.l.sFG\",\t\"ceil.l.sFG\",\t\"floor.l.sFG\",\n  \"round.w.sFG\",\t\"trunc.w.sFG\",\t\"ceil.w.sFG\",\t\"floor.w.sFG\",\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.sFGC\", \"movt.sFGC\" },\n  \"movz.sFGT\",\t\"movn.sFGT\",\n  false,\t\"recip.sFG\",\t\"rsqrt.sFG\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\"cvt.d.sFG\",\tfalse,\t\tfalse,\n  \"cvt.w.sFG\",\t\"cvt.l.sFG\",\t\"cvt.ps.sFGH\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"c.f.sVGH\",\t\"c.un.sVGH\",\t\"c.eq.sVGH\",\t\"c.ueq.sVGH\",\n  \"c.olt.sVGH\",\t\"c.ult.sVGH\",\t\"c.ole.sVGH\",\t\"c.ule.sVGH\",\n  \"c.sf.sVGH\",\t\"c.ngle.sVGH\",\t\"c.seq.sVGH\",\t\"c.ngl.sVGH\",\n  \"c.lt.sVGH\",\t\"c.nge.sVGH\",\t\"c.le.sVGH\",\t\"c.ngt.sVGH\",\n}\n\nlocal map_cop1d = {\n  shift = 0, mask = 63,\n  [0] = \"add.dFGH\",\t\"sub.dFGH\",\t\"mul.dFGH\",\t\"div.dFGH\",\n  \"sqrt.dFG\",\t\t\"abs.dFG\",\t\"mov.dFG\",\t\"neg.dFG\",\n  \"round.l.dFG\",\t\"trunc.l.dFG\",\t\"ceil.l.dFG\",\t\"floor.l.dFG\",\n  \"round.w.dFG\",\t\"trunc.w.dFG\",\t\"ceil.w.dFG\",\t\"floor.w.dFG\",\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.dFGC\", \"movt.dFGC\" },\n  \"movz.dFGT\",\t\"movn.dFGT\",\n  false,\t\"recip.dFG\",\t\"rsqrt.dFG\",\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.dFG\",\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.w.dFG\",\t\"cvt.l.dFG\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"c.f.dVGH\",\t\"c.un.dVGH\",\t\"c.eq.dVGH\",\t\"c.ueq.dVGH\",\n  \"c.olt.dVGH\",\t\"c.ult.dVGH\",\t\"c.ole.dVGH\",\t\"c.ule.dVGH\",\n  \"c.df.dVGH\",\t\"c.ngle.dVGH\",\t\"c.deq.dVGH\",\t\"c.ngl.dVGH\",\n  \"c.lt.dVGH\",\t\"c.nge.dVGH\",\t\"c.le.dVGH\",\t\"c.ngt.dVGH\",\n}\n\nlocal map_cop1ps = {\n  shift = 0, mask = 63,\n  [0] = \"add.psFGH\",\t\"sub.psFGH\",\t\"mul.psFGH\",\tfalse,\n  false,\t\t\"abs.psFG\",\t\"mov.psFG\",\t\"neg.psFG\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\n  { shift = 16, mask = 1, [0] = \"movf.psFGC\", \"movt.psFGC\" },\n  \"movz.psFGT\",\t\"movn.psFGT\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.puFG\",\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.plFG\",\tfalse,\t\tfalse,\t\tfalse,\n  \"pll.psFGH\",\t\"plu.psFGH\",\t\"pul.psFGH\",\t\"puu.psFGH\",\n  \"c.f.psVGH\",\t\"c.un.psVGH\",\t\"c.eq.psVGH\",\t\"c.ueq.psVGH\",\n  \"c.olt.psVGH\", \"c.ult.psVGH\",\t\"c.ole.psVGH\",\t\"c.ule.psVGH\",\n  \"c.psf.psVGH\", \"c.ngle.psVGH\", \"c.pseq.psVGH\", \"c.ngl.psVGH\",\n  \"c.lt.psVGH\",\t\"c.nge.psVGH\",\t\"c.le.psVGH\",\t\"c.ngt.psVGH\",\n}\n\nlocal map_cop1w = {\n  shift = 0, mask = 63,\n  [32] = \"cvt.s.wFG\", [33] = \"cvt.d.wFG\",\n}\n\nlocal map_cop1l = {\n  shift = 0, mask = 63,\n  [32] = \"cvt.s.lFG\", [33] = \"cvt.d.lFG\",\n}\n\nlocal map_cop1bc = {\n  shift = 16, mask = 3,\n  [0] = \"bc1fCB\", \"bc1tCB\",\t\"bc1flCB\",\t\"bc1tlCB\",\n}\n\nlocal map_cop1 = {\n  shift = 21, mask = 31,\n  [0] = \"mfc1TG\", \"dmfc1TG\",\t\"cfc1TG\",\t\"mfhc1TG\",\n  \"mtc1TG\",\t\"dmtc1TG\",\t\"ctc1TG\",\t\"mthc1TG\",\n  map_cop1bc,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  map_cop1s,\tmap_cop1d,\tfalse,\t\tfalse,\n  map_cop1w,\tmap_cop1l,\tmap_cop1ps,\n}\n\nlocal map_cop1x = {\n  shift = 0, mask = 63,\n  [0] = \"lwxc1FSX\",\t\"ldxc1FSX\",\tfalse,\t\tfalse,\n  false,\t\"luxc1FSX\",\tfalse,\t\tfalse,\n  \"swxc1FSX\",\t\"sdxc1FSX\",\tfalse,\t\tfalse,\n  false,\t\"suxc1FSX\",\tfalse,\t\t\"prefxMSX\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"alnv.psFGHS\",\tfalse,\n  \"madd.sFRGH\",\t\"madd.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"madd.psFRGH\",\tfalse,\n  \"msub.sFRGH\",\t\"msub.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"msub.psFRGH\",\tfalse,\n  \"nmadd.sFRGH\", \"nmadd.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"nmadd.psFRGH\",\tfalse,\n  \"nmsub.sFRGH\", \"nmsub.dFRGH\",\tfalse,\t\tfalse,\n  false,\tfalse,\t\t\"nmsub.psFRGH\",\tfalse,\n}\n\nlocal map_pri = {\n  [0] = map_special,\tmap_regimm,\t\"jJ\",\t\"jalJ\",\n  \"beq|beqz|bST00B\",\t\"bne|bnezST0B\",\t\t\"blezSB\",\t\"bgtzSB\",\n  \"addiTSI\",\t\"addiu|liTS0I\",\t\"sltiTSI\",\t\"sltiuTSI\",\n  \"andiTSU\",\t\"ori|liTS0U\",\t\"xoriTSU\",\t\"luiTU\",\n  map_cop0,\tmap_cop1,\tfalse,\t\tmap_cop1x,\n  \"beql|beqzlST0B\",\t\"bnel|bnezlST0B\",\t\"blezlSB\",\t\"bgtzlSB\",\n  \"daddiTSI\",\t\"daddiuTSI\",\tfalse,\t\tfalse,\n  map_special2,\t\"jalxJ\",\tfalse,\t\tmap_special3,\n  \"lbTSO\",\t\"lhTSO\",\t\"lwlTSO\",\t\"lwTSO\",\n  \"lbuTSO\",\t\"lhuTSO\",\t\"lwrTSO\",\tfalse,\n  \"sbTSO\",\t\"shTSO\",\t\"swlTSO\",\t\"swTSO\",\n  false,\tfalse,\t\t\"swrTSO\",\t\"cacheNSO\",\n  \"llTSO\",\t\"lwc1HSO\",\t\"lwc2TSO\",\t\"prefNSO\",\n  false,\t\"ldc1HSO\",\t\"ldc2TSO\",\t\"ldTSO\",\n  \"scTSO\",\t\"swc1HSO\",\t\"swc2TSO\",\tfalse,\n  false,\t\"sdc1HSO\",\t\"sdc2TSO\",\t\"sdTSO\",\n}\n\n------------------------------------------------------------------------------\n-- Primary and extended opcode maps for MIPS R6\n------------------------------------------------------------------------------\n\nlocal map_mul_r6 =   { shift = 6, mask = 3, [2] = \"mulDST\",   [3] = \"muhDST\" }\nlocal map_mulu_r6 =  { shift = 6, mask = 3, [2] = \"muluDST\",  [3] = \"muhuDST\" }\nlocal map_div_r6 =   { shift = 6, mask = 3, [2] = \"divDST\",   [3] = \"modDST\" }\nlocal map_divu_r6 =  { shift = 6, mask = 3, [2] = \"divuDST\",  [3] = \"moduDST\" }\nlocal map_dmul_r6 =  { shift = 6, mask = 3, [2] = \"dmulDST\",  [3] = \"dmuhDST\" }\nlocal map_dmulu_r6 = { shift = 6, mask = 3, [2] = \"dmuluDST\", [3] = \"dmuhuDST\" }\nlocal map_ddiv_r6 =  { shift = 6, mask = 3, [2] = \"ddivDST\",  [3] = \"dmodDST\" }\nlocal map_ddivu_r6 = { shift = 6, mask = 3, [2] = \"ddivuDST\", [3] = \"dmoduDST\" }\n\nlocal map_special_r6 = {\n  shift = 0, mask = 63,\n  [0] = { shift = 0, mask = -1, [0] = \"nop\", _ = \"sllDTA\" },\n  false,\tmap_srl,\t\"sraDTA\",\n  \"sllvDTS\",\tfalse,\t\tmap_srlv,\t\"sravDTS\",\n  \"jrS\",\t\"jalrD1S\",\tfalse,\t\tfalse,\n  \"syscallY\",\t\"breakY\",\tfalse,\t\t\"sync\",\n  \"clzDS\",\t\"cloDS\",\t\"dclzDS\",\t\"dcloDS\",\n  \"dsllvDST\",\t\"dlsaDSTA\",\t\"dsrlvDST\",\t\"dsravDST\",\n  map_mul_r6,\tmap_mulu_r6,\tmap_div_r6,\tmap_divu_r6,\n  map_dmul_r6,\tmap_dmulu_r6,\tmap_ddiv_r6,\tmap_ddivu_r6,\n  \"addDST\",\t\"addu|moveDST0\", \"subDST\",\t\"subu|neguDS0T\",\n  \"andDST\",\t\"or|moveDST0\",\t\"xorDST\",\t\"nor|notDST0\",\n  false,\tfalse,\t\t\"sltDST\",\t\"sltuDST\",\n  \"daddDST\",\t\"dadduDST\",\t\"dsubDST\",\t\"dsubuDST\",\n  \"tgeSTZ\",\t\"tgeuSTZ\",\t\"tltSTZ\",\t\"tltuSTZ\",\n  \"teqSTZ\",\t\"seleqzDST\",\t\"tneSTZ\",\t\"selnezDST\",\n  \"dsllDTA\",\tfalse,\t\t\"dsrlDTA\",\t\"dsraDTA\",\n  \"dsll32DTA\",\tfalse,\t\t\"dsrl32DTA\",\t\"dsra32DTA\",\n}\n\nlocal map_bshfl_r6 = {\n  shift = 9, mask = 3,\n  [1] = \"alignDSTa\",\n  _ = {\n    shift = 6, mask = 31,\n    [0] = \"bitswapDT\",\n    [2] = \"wsbhDT\",\n    [16] = \"sebDT\",\n    [24] = \"sehDT\",\n  }\n}\n\nlocal map_dbshfl_r6 = {\n  shift = 9, mask = 3,\n  [1] = \"dalignDSTa\",\n  _ = {\n    shift = 6, mask = 31,\n    [0] = \"dbitswapDT\",\n    [2] = \"dsbhDT\",\n    [5] = \"dshdDT\",\n  }\n}\n\nlocal map_special3_r6 = {\n  shift = 0, mask = 63,\n  [0]  = \"extTSAK\", [1]  = \"dextmTSAP\", [3]  = \"dextTSAK\",\n  [4]  = \"insTSAL\", [6]  = \"dinsuTSEQ\", [7]  = \"dinsTSAL\",\n  [32] = map_bshfl_r6, [36] = map_dbshfl_r6,  [59] = \"rdhwrTD\",\n}\n\nlocal map_regimm_r6 = {\n  shift = 16, mask = 31,\n  [0] = \"bltzSB\", [1] = \"bgezSB\",\n  [6] = \"dahiSI\", [30] = \"datiSI\",\n  [23] = \"sigrieI\", [31] = \"synciSO\",\n}\n\nlocal map_pcrel_r6 = {\n  shift = 19, mask = 3,\n  [0] = \"addiupcS2\", \"lwpcS2\", \"lwupcS2\", {\n    shift = 18, mask = 1,\n    [0] = \"ldpcS3\", { shift = 16, mask = 3, [2] = \"auipcSI\", [3] = \"aluipcSI\" }\n  }\n}\n\nlocal map_cop1s_r6 = {\n  shift = 0, mask = 63,\n  [0] = \"add.sFGH\",\t\"sub.sFGH\",\t\"mul.sFGH\",\t\"div.sFGH\",\n  \"sqrt.sFG\",\t\t\"abs.sFG\",\t\"mov.sFG\",\t\"neg.sFG\",\n  \"round.l.sFG\",\t\"trunc.l.sFG\",\t\"ceil.l.sFG\",\t\"floor.l.sFG\",\n  \"round.w.sFG\",\t\"trunc.w.sFG\",\t\"ceil.w.sFG\",\t\"floor.w.sFG\",\n  \"sel.sFGH\",\t\tfalse,\t\tfalse,\t\tfalse,\n  \"seleqz.sFGH\",\t\"recip.sFG\",\t\"rsqrt.sFG\",\t\"selnez.sFGH\",\n  \"maddf.sFGH\",\t\t\"msubf.sFGH\",\t\"rint.sFG\",\t\"class.sFG\",\n  \"min.sFGH\",\t\t\"mina.sFGH\",\t\"max.sFGH\",\t\"maxa.sFGH\",\n  false,\t\t\"cvt.d.sFG\",\tfalse,\t\tfalse,\n  \"cvt.w.sFG\",\t\t\"cvt.l.sFG\",\n}\n\nlocal map_cop1d_r6 = {\n  shift = 0, mask = 63,\n  [0] = \"add.dFGH\",\t\"sub.dFGH\",\t\"mul.dFGH\",\t\"div.dFGH\",\n  \"sqrt.dFG\",\t\t\"abs.dFG\",\t\"mov.dFG\",\t\"neg.dFG\",\n  \"round.l.dFG\",\t\"trunc.l.dFG\",\t\"ceil.l.dFG\",\t\"floor.l.dFG\",\n  \"round.w.dFG\",\t\"trunc.w.dFG\",\t\"ceil.w.dFG\",\t\"floor.w.dFG\",\n  \"sel.dFGH\",\t\tfalse,\t\tfalse,\t\tfalse,\n  \"seleqz.dFGH\",\t\"recip.dFG\",\t\"rsqrt.dFG\",\t\"selnez.dFGH\",\n  \"maddf.dFGH\",\t\t\"msubf.dFGH\",\t\"rint.dFG\",\t\"class.dFG\",\n  \"min.dFGH\",\t\t\"mina.dFGH\",\t\"max.dFGH\",\t\"maxa.dFGH\",\n  \"cvt.s.dFG\",\t\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.w.dFG\",\t\t\"cvt.l.dFG\",\n}\n\nlocal map_cop1w_r6 = {\n  shift = 0, mask = 63,\n  [0] = \"cmp.af.sFGH\",\t\"cmp.un.sFGH\",\t\"cmp.eq.sFGH\",\t\"cmp.ueq.sFGH\",\n  \"cmp.lt.sFGH\",\t\"cmp.ult.sFGH\",\t\"cmp.le.sFGH\",\t\"cmp.ule.sFGH\",\n  \"cmp.saf.sFGH\",\t\"cmp.sun.sFGH\",\t\"cmp.seq.sFGH\",\t\"cmp.sueq.sFGH\",\n  \"cmp.slt.sFGH\",\t\"cmp.sult.sFGH\",\t\"cmp.sle.sFGH\",\t\"cmp.sule.sFGH\",\n  false,\t\t\"cmp.or.sFGH\",\t\"cmp.une.sFGH\",\t\"cmp.ne.sFGH\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\t\"cmp.sor.sFGH\",\t\"cmp.sune.sFGH\",\t\"cmp.sne.sFGH\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.wFG\", \"cvt.d.wFG\",\n}\n\nlocal map_cop1l_r6 = {\n  shift = 0, mask = 63,\n  [0] = \"cmp.af.dFGH\",\t\"cmp.un.dFGH\",\t\"cmp.eq.dFGH\",\t\"cmp.ueq.dFGH\",\n  \"cmp.lt.dFGH\",\t\"cmp.ult.dFGH\",\t\"cmp.le.dFGH\",\t\"cmp.ule.dFGH\",\n  \"cmp.saf.dFGH\",\t\"cmp.sun.dFGH\",\t\"cmp.seq.dFGH\",\t\"cmp.sueq.dFGH\",\n  \"cmp.slt.dFGH\",\t\"cmp.sult.dFGH\",\t\"cmp.sle.dFGH\",\t\"cmp.sule.dFGH\",\n  false,\t\t\"cmp.or.dFGH\",\t\"cmp.une.dFGH\",\t\"cmp.ne.dFGH\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\t\"cmp.sor.dFGH\",\t\"cmp.sune.dFGH\",\t\"cmp.sne.dFGH\",\n  false,\t\tfalse,\t\tfalse,\t\tfalse,\n  \"cvt.s.lFG\", \"cvt.d.lFG\",\n}\n\nlocal map_cop1_r6 = {\n  shift = 21, mask = 31,\n  [0] = \"mfc1TG\", \"dmfc1TG\",\t\"cfc1TG\",\t\"mfhc1TG\",\n  \"mtc1TG\",\t\"dmtc1TG\",\t\"ctc1TG\",\t\"mthc1TG\",\n  false,\t\"bc1eqzHB\",\tfalse,\t\tfalse,\n  false,\t\"bc1nezHB\",\tfalse,\t\tfalse,\n  map_cop1s_r6,\tmap_cop1d_r6,\tfalse,\t\tfalse,\n  map_cop1w_r6,\tmap_cop1l_r6,\n}\n\nlocal function maprs_popTS(rs, rt)\n  if rt == 0 then return 0 elseif rs == 0 then return 1\n  elseif rs == rt then return 2 else return 3 end\nend\n\nlocal map_pop06_r6 = {\n  maprs = maprs_popTS, [0] = \"blezSB\", \"blezalcTB\", \"bgezalcTB\", \"bgeucSTB\"\n}\nlocal map_pop07_r6 = {\n  maprs = maprs_popTS, [0] = \"bgtzSB\", \"bgtzalcTB\", \"bltzalcTB\", \"bltucSTB\"\n}\nlocal map_pop26_r6 = {\n  maprs = maprs_popTS, \"blezcTB\", \"bgezcTB\", \"bgecSTB\"\n}\nlocal map_pop27_r6 = {\n  maprs = maprs_popTS, \"bgtzcTB\", \"bltzcTB\", \"bltcSTB\"\n}\n\nlocal function maprs_popS(rs, rt)\n  if rs == 0 then return 0 else return 1 end\nend\n\nlocal map_pop66_r6 = {\n  maprs = maprs_popS, [0] = \"jicTI\", \"beqzcSb\"\n}\nlocal map_pop76_r6 = {\n  maprs = maprs_popS, [0] = \"jialcTI\", \"bnezcSb\"\n}\n\nlocal function maprs_popST(rs, rt)\n  if rs >= rt then return 0 elseif rs == 0 then return 1 else return 2 end\nend\n\nlocal map_pop10_r6 = {\n  maprs = maprs_popST, [0] = \"bovcSTB\", \"beqzalcTB\", \"beqcSTB\"\n}\nlocal map_pop30_r6 = {\n  maprs = maprs_popST, [0] = \"bnvcSTB\", \"bnezalcTB\", \"bnecSTB\"\n}\n\nlocal map_pri_r6 = {\n  [0] = map_special_r6,\tmap_regimm_r6,\t\"jJ\",\t\"jalJ\",\n  \"beq|beqz|bST00B\",\t\"bne|bnezST0B\",\t\tmap_pop06_r6,\tmap_pop07_r6,\n  map_pop10_r6,\t\"addiu|liTS0I\",\t\"sltiTSI\",\t\"sltiuTSI\",\n  \"andiTSU\",\t\"ori|liTS0U\",\t\"xoriTSU\",\t\"aui|luiTS0U\",\n  map_cop0,\tmap_cop1_r6,\tfalse,\t\tfalse,\n  false,\tfalse,\t\tmap_pop26_r6,\tmap_pop27_r6,\n  map_pop30_r6,\t\"daddiuTSI\",\tfalse,\t\tfalse,\n  false,\t\"dauiTSI\",\tfalse,\t\tmap_special3_r6,\n  \"lbTSO\",\t\"lhTSO\",\tfalse,\t\t\"lwTSO\",\n  \"lbuTSO\",\t\"lhuTSO\",\tfalse,\t\tfalse,\n  \"sbTSO\",\t\"shTSO\",\tfalse,\t\t\"swTSO\",\n  false,\tfalse,\t\tfalse,\t\tfalse,\n  false,\t\"lwc1HSO\",\t\"bc#\",\t\tfalse,\n  false,\t\"ldc1HSO\",\tmap_pop66_r6,\t\"ldTSO\",\n  false,\t\"swc1HSO\",\t\"balc#\",\tmap_pcrel_r6,\n  false,\t\"sdc1HSO\",\tmap_pop76_r6,\t\"sdTSO\",\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"r1\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\",\n  \"r16\", \"r17\", \"r18\", \"r19\", \"r20\", \"r21\", \"r22\", \"r23\",\n  \"r24\", \"r25\", \"r26\", \"r27\", \"r28\", \"sp\", \"r30\", \"ra\",\n}\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then extra = \"\\t->\"..sym end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-7s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-7s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\nlocal function get_be(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)\nend\n\nlocal function get_le(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local op = ctx:get()\n  local operands = {}\n  local last = nil\n  ctx.op = op\n  ctx.rel = nil\n\n  local opat = ctx.map_pri[rshift(op, 26)]\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    if opat.maprs then\n      opat = opat[opat.maprs(band(rshift(op,21),31), band(rshift(op,16),31))]\n    else\n      opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._\n    end\n  end\n  local name, pat = match(opat, \"^([a-z0-9_.]*)(.*)\")\n  local altname, pat2 = match(pat, \"|([a-z0-9_.|]*)(.*)\")\n  if altname then pat = pat2 end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"S\" then\n      x = map_gpr[band(rshift(op, 21), 31)]\n    elseif p == \"T\" then\n      x = map_gpr[band(rshift(op, 16), 31)]\n    elseif p == \"D\" then\n      x = map_gpr[band(rshift(op, 11), 31)]\n    elseif p == \"F\" then\n      x = \"f\"..band(rshift(op, 6), 31)\n    elseif p == \"G\" then\n      x = \"f\"..band(rshift(op, 11), 31)\n    elseif p == \"H\" then\n      x = \"f\"..band(rshift(op, 16), 31)\n    elseif p == \"R\" then\n      x = \"f\"..band(rshift(op, 21), 31)\n    elseif p == \"A\" then\n      x = band(rshift(op, 6), 31)\n    elseif p == \"a\" then\n      x = band(rshift(op, 6), 7)\n    elseif p == \"E\" then\n      x = band(rshift(op, 6), 31) + 32\n    elseif p == \"M\" then\n      x = band(rshift(op, 11), 31)\n    elseif p == \"N\" then\n      x = band(rshift(op, 16), 31)\n    elseif p == \"C\" then\n      x = band(rshift(op, 18), 7)\n      if x == 0 then x = nil end\n    elseif p == \"K\" then\n      x = band(rshift(op, 11), 31) + 1\n    elseif p == \"P\" then\n      x = band(rshift(op, 11), 31) + 33\n    elseif p == \"L\" then\n      x = band(rshift(op, 11), 31) - last + 1\n    elseif p == \"Q\" then\n      x = band(rshift(op, 11), 31) - last + 33\n    elseif p == \"I\" then\n      x = arshift(lshift(op, 16), 16)\n    elseif p == \"2\" then\n      x = arshift(lshift(op, 13), 11)\n    elseif p == \"3\" then\n      x = arshift(lshift(op, 14), 11)\n    elseif p == \"U\" then\n      x = band(op, 0xffff)\n    elseif p == \"O\" then\n      local disp = arshift(lshift(op, 16), 16)\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p == \"X\" then\n      local index = map_gpr[band(rshift(op, 16), 31)]\n      operands[#operands] = format(\"%s(%s)\", index, last)\n    elseif p == \"B\" then\n      x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 14) + 4\n      ctx.rel = x\n      x = format(\"0x%08x\", x)\n    elseif p == \"b\" then\n      x = ctx.addr + ctx.pos + arshift(lshift(op, 11), 9) + 4\n      ctx.rel = x\n      x = format(\"0x%08x\", x)\n    elseif p == \"#\" then\n      x = ctx.addr + ctx.pos + arshift(lshift(op, 6), 4) + 4\n      ctx.rel = x\n      x = format(\"0x%08x\", x)\n    elseif p == \"J\" then\n      local a = ctx.addr + ctx.pos\n      x = a - band(a, 0x0fffffff) + band(op, 0x03ffffff)*4\n      ctx.rel = x\n      x = format(\"0x%08x\", x)\n    elseif p == \"V\" then\n      x = band(rshift(op, 8), 7)\n      if x == 0 then x = nil end\n    elseif p == \"W\" then\n      x = band(op, 7)\n      if x == 0 then x = nil end\n    elseif p == \"Y\" then\n      x = band(rshift(op, 6), 0x000fffff)\n      if x == 0 then x = nil end\n    elseif p == \"Z\" then\n      x = band(rshift(op, 6), 1023)\n      if x == 0 then x = nil end\n    elseif p == \"0\" then\n      if last == \"r0\" or last == 0 then\n\tlocal n = #operands\n\toperands[n] = nil\n\tlast = operands[n-1]\n\tif altname then\n\t  local a1, a2 = match(altname, \"([^|]*)|(.*)\")\n\t  if a1 then name, altname = a1, a2\n\t  else name = altname end\n\tend\n      end\n    elseif p == \"1\" then\n      if last == \"ra\" then\n\toperands[#operands] = nil\n      end\n    else\n      assert(false)\n    end\n    if x then operands[#operands+1] = x; last = x end\n  end\n\n  return putop(ctx, name, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  stop = stop - stop % 4\n  ctx.pos = ofs - ofs % 4\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  ctx.get = get_be\n  ctx.map_pri = map_pri\n  return ctx\nend\n\nlocal function create_el(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.get = get_le\n  return ctx\nend\n\nlocal function create_r6(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.map_pri = map_pri_r6\n  return ctx\nend\n\nlocal function create_r6_el(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.get = get_le\n  ctx.map_pri = map_pri_r6\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\nlocal function disass_el(code, addr, out)\n  create_el(code, addr, out):disass()\nend\n\nlocal function disass_r6(code, addr, out)\n  create_r6(code, addr, out):disass()\nend\n\nlocal function disass_r6_el(code, addr, out)\n  create_r6_el(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 32 then return map_gpr[r] end\n  return \"f\"..(r-32)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  create_el = create_el,\n  create_r6 = create_r6,\n  create_r6_el = create_r6_el,\n  disass = disass,\n  disass_el = disass_el,\n  disass_r6 = disass_r6,\n  disass_r6_el = disass_r6_el,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mips64.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS64 disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the big-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create,\n  disass = dis_mips.disass,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mips64el.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS64EL disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the little-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create_el,\n  disass = dis_mips.disass_el,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mips64r6.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS64R6 disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the r6 big-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create_r6,\n  disass = dis_mips.disass_r6,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mips64r6el.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPS64R6EL disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the r6 little-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create_r6_el,\n  disass = dis_mips.disass_r6_el,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_mipsel.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT MIPSEL disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the little-endian functions from the\n-- MIPS disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_mips = require((string.match(..., \".*%.\") or \"\")..\"dis_mips\")\nreturn {\n  create = dis_mips.create_el,\n  disass = dis_mips.disass_el,\n  regname = dis_mips.regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_ppc.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT PPC disassembler module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT/X license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- It disassembles all common, non-privileged 32/64 bit PowerPC instructions\n-- plus the e500 SPE instructions and some Cell/Xenon extensions.\n--\n-- NYI: VMX, VMX128\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal byte, format = string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal concat = table.concat\nlocal bit = require(\"bit\")\nlocal band, bor, tohex = bit.band, bit.bor, bit.tohex\nlocal lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift\n\n------------------------------------------------------------------------------\n-- Primary and extended opcode maps\n------------------------------------------------------------------------------\n\nlocal map_crops = {\n  shift = 1, mask = 1023,\n  [0] = \"mcrfXX\",\n  [33] = \"crnor|crnotCCC=\", [129] = \"crandcCCC\",\n  [193] = \"crxor|crclrCCC%\", [225] = \"crnandCCC\",\n  [257] = \"crandCCC\", [289] = \"creqv|crsetCCC%\",\n  [417] = \"crorcCCC\", [449] = \"cror|crmoveCCC=\",\n  [16] = \"b_lrKB\", [528] = \"b_ctrKB\",\n  [150] = \"isync\",\n}\n\nlocal map_rlwinm = setmetatable({\n  shift = 0, mask = -1,\n},\n{ __index = function(t, x)\n    local rot = band(rshift(x, 11), 31)\n    local mb = band(rshift(x, 6), 31)\n    local me = band(rshift(x, 1), 31)\n    if mb == 0 and me == 31-rot then\n      return \"slwiRR~A.\"\n    elseif me == 31 and mb == 32-rot then\n      return \"srwiRR~-A.\"\n    else\n      return \"rlwinmRR~AAA.\"\n    end\n  end\n})\n\nlocal map_rld = {\n  shift = 2, mask = 7,\n  [0] = \"rldiclRR~HM.\", \"rldicrRR~HM.\", \"rldicRR~HM.\", \"rldimiRR~HM.\",\n  {\n    shift = 1, mask = 1,\n    [0] = \"rldclRR~RM.\", \"rldcrRR~RM.\",\n  },\n}\n\nlocal map_ext = setmetatable({\n  shift = 1, mask = 1023,\n\n  [0] = \"cmp_YLRR\", [32] = \"cmpl_YLRR\",\n  [4] = \"twARR\", [68] = \"tdARR\",\n\n  [8] = \"subfcRRR.\", [40] = \"subfRRR.\",\n  [104] = \"negRR.\", [136] = \"subfeRRR.\",\n  [200] = \"subfzeRR.\", [232] = \"subfmeRR.\",\n  [520] = \"subfcoRRR.\", [552] = \"subfoRRR.\",\n  [616] = \"negoRR.\", [648] = \"subfeoRRR.\",\n  [712] = \"subfzeoRR.\", [744] = \"subfmeoRR.\",\n\n  [9] = \"mulhduRRR.\", [73] = \"mulhdRRR.\", [233] = \"mulldRRR.\",\n  [457] = \"divduRRR.\", [489] = \"divdRRR.\",\n  [745] = \"mulldoRRR.\",\n  [969] = \"divduoRRR.\", [1001] = \"divdoRRR.\",\n\n  [10] = \"addcRRR.\", [138] = \"addeRRR.\",\n  [202] = \"addzeRR.\", [234] = \"addmeRR.\", [266] = \"addRRR.\",\n  [522] = \"addcoRRR.\", [650] = \"addeoRRR.\",\n  [714] = \"addzeoRR.\", [746] = \"addmeoRR.\", [778] = \"addoRRR.\",\n\n  [11] = \"mulhwuRRR.\", [75] = \"mulhwRRR.\", [235] = \"mullwRRR.\",\n  [459] = \"divwuRRR.\", [491] = \"divwRRR.\",\n  [747] = \"mullwoRRR.\",\n  [971] = \"divwouRRR.\", [1003] = \"divwoRRR.\",\n\n  [15] = \"iselltRRR\", [47] = \"iselgtRRR\", [79] = \"iseleqRRR\",\n\n  [144] = { shift = 20, mask = 1, [0] = \"mtcrfRZ~\", \"mtocrfRZ~\", },\n  [19] = { shift = 20, mask = 1, [0] = \"mfcrR\", \"mfocrfRZ\", },\n  [371] = { shift = 11, mask = 1023, [392] = \"mftbR\", [424] = \"mftbuR\", },\n  [339] = {\n    shift = 11, mask = 1023,\n    [32] = \"mferR\", [256] = \"mflrR\", [288] = \"mfctrR\", [16] = \"mfspefscrR\",\n  },\n  [467] = {\n    shift = 11, mask = 1023,\n    [32] = \"mtxerR\", [256] = \"mtlrR\", [288] = \"mtctrR\", [16] = \"mtspefscrR\",\n  },\n\n  [20] = \"lwarxRR0R\", [84] = \"ldarxRR0R\",\n\n  [21] = \"ldxRR0R\", [53] = \"lduxRRR\",\n  [149] = \"stdxRR0R\", [181] = \"stduxRRR\",\n  [341] = \"lwaxRR0R\", [373] = \"lwauxRRR\",\n\n  [23] = \"lwzxRR0R\", [55] = \"lwzuxRRR\",\n  [87] = \"lbzxRR0R\", [119] = \"lbzuxRRR\",\n  [151] = \"stwxRR0R\", [183] = \"stwuxRRR\",\n  [215] = \"stbxRR0R\", [247] = \"stbuxRRR\",\n  [279] = \"lhzxRR0R\", [311] = \"lhzuxRRR\",\n  [343] = \"lhaxRR0R\", [375] = \"lhauxRRR\",\n  [407] = \"sthxRR0R\", [439] = \"sthuxRRR\",\n\n  [54] = \"dcbst-R0R\", [86] = \"dcbf-R0R\",\n  [150] = \"stwcxRR0R.\", [214] = \"stdcxRR0R.\",\n  [246] = \"dcbtst-R0R\", [278] = \"dcbt-R0R\",\n  [310] = \"eciwxRR0R\", [438] = \"ecowxRR0R\",\n  [470] = \"dcbi-RR\",\n\n  [598] = {\n    shift = 21, mask = 3,\n    [0] = \"sync\", \"lwsync\", \"ptesync\",\n  },\n  [758] = \"dcba-RR\",\n  [854] = \"eieio\", [982] = \"icbi-R0R\", [1014] = \"dcbz-R0R\",\n\n  [26] = \"cntlzwRR~\", [58] = \"cntlzdRR~\",\n  [122] = \"popcntbRR~\",\n  [154] = \"prtywRR~\", [186] = \"prtydRR~\",\n\n  [28] = \"andRR~R.\", [60] = \"andcRR~R.\", [124] = \"nor|notRR~R=.\",\n  [284] = \"eqvRR~R.\", [316] = \"xorRR~R.\",\n  [412] = \"orcRR~R.\", [444] = \"or|mrRR~R=.\", [476] = \"nandRR~R.\",\n  [508] = \"cmpbRR~R\",\n\n  [512] = \"mcrxrX\",\n\n  [532] = \"ldbrxRR0R\", [660] = \"stdbrxRR0R\",\n\n  [533] = \"lswxRR0R\", [597] = \"lswiRR0A\",\n  [661] = \"stswxRR0R\", [725] = \"stswiRR0A\",\n\n  [534] = \"lwbrxRR0R\", [662] = \"stwbrxRR0R\",\n  [790] = \"lhbrxRR0R\", [918] = \"sthbrxRR0R\",\n\n  [535] = \"lfsxFR0R\", [567] = \"lfsuxFRR\",\n  [599] = \"lfdxFR0R\", [631] = \"lfduxFRR\",\n  [663] = \"stfsxFR0R\", [695] = \"stfsuxFRR\",\n  [727] = \"stfdxFR0R\", [759] = \"stfduxFR0R\",\n  [855] = \"lfiwaxFR0R\",\n  [983] = \"stfiwxFR0R\",\n\n  [24] = \"slwRR~R.\",\n\n  [27] = \"sldRR~R.\", [536] = \"srwRR~R.\",\n  [792] = \"srawRR~R.\", [824] = \"srawiRR~A.\",\n\n  [794] = \"sradRR~R.\", [826] = \"sradiRR~H.\", [827] = \"sradiRR~H.\",\n  [922] = \"extshRR~.\", [954] = \"extsbRR~.\", [986] = \"extswRR~.\",\n\n  [539] = \"srdRR~R.\",\n},\n{ __index = function(t, x)\n    if band(x, 31) == 15 then return \"iselRRRC\" end\n  end\n})\n\nlocal map_ld = {\n  shift = 0, mask = 3,\n  [0] = \"ldRRE\", \"lduRRE\", \"lwaRRE\",\n}\n\nlocal map_std = {\n  shift = 0, mask = 3,\n  [0] = \"stdRRE\", \"stduRRE\",\n}\n\nlocal map_fps = {\n  shift = 5, mask = 1,\n  {\n    shift = 1, mask = 15,\n    [0] = false, false, \"fdivsFFF.\", false,\n    \"fsubsFFF.\", \"faddsFFF.\", \"fsqrtsF-F.\", false,\n    \"fresF-F.\", \"fmulsFF-F.\", \"frsqrtesF-F.\", false,\n    \"fmsubsFFFF~.\", \"fmaddsFFFF~.\", \"fnmsubsFFFF~.\", \"fnmaddsFFFF~.\",\n  }\n}\n\nlocal map_fpd = {\n  shift = 5, mask = 1,\n  [0] = {\n    shift = 1, mask = 1023,\n    [0] = \"fcmpuXFF\", [32] = \"fcmpoXFF\", [64] = \"mcrfsXX\",\n    [38] = \"mtfsb1A.\", [70] = \"mtfsb0A.\", [134] = \"mtfsfiA>>-A>\",\n    [8] = \"fcpsgnFFF.\", [40] = \"fnegF-F.\", [72] = \"fmrF-F.\",\n    [136] = \"fnabsF-F.\", [264] = \"fabsF-F.\",\n    [12] = \"frspF-F.\",\n    [14] = \"fctiwF-F.\", [15] = \"fctiwzF-F.\",\n    [583] = \"mffsF.\", [711] = \"mtfsfZF.\",\n    [392] = \"frinF-F.\", [424] = \"frizF-F.\",\n    [456] = \"fripF-F.\", [488] = \"frimF-F.\",\n    [814] = \"fctidF-F.\", [815] = \"fctidzF-F.\", [846] = \"fcfidF-F.\",\n  },\n  {\n    shift = 1, mask = 15,\n    [0] = false, false, \"fdivFFF.\", false,\n    \"fsubFFF.\", \"faddFFF.\", \"fsqrtF-F.\", \"fselFFFF~.\",\n    \"freF-F.\", \"fmulFF-F.\", \"frsqrteF-F.\", false,\n    \"fmsubFFFF~.\", \"fmaddFFFF~.\", \"fnmsubFFFF~.\", \"fnmaddFFFF~.\",\n  }\n}\n\nlocal map_spe = {\n  shift = 0, mask = 2047,\n\n  [512] = \"evaddwRRR\", [514] = \"evaddiwRAR~\",\n  [516] = \"evsubwRRR~\", [518] = \"evsubiwRAR~\",\n  [520] = \"evabsRR\", [521] = \"evnegRR\",\n  [522] = \"evextsbRR\", [523] = \"evextshRR\", [524] = \"evrndwRR\",\n  [525] = \"evcntlzwRR\", [526] = \"evcntlswRR\",\n\n  [527] = \"brincRRR\",\n\n  [529] = \"evandRRR\", [530] = \"evandcRRR\", [534] = \"evxorRRR\",\n  [535] = \"evor|evmrRRR=\", [536] = \"evnor|evnotRRR=\",\n  [537] = \"eveqvRRR\", [539] = \"evorcRRR\", [542] = \"evnandRRR\",\n\n  [544] = \"evsrwuRRR\", [545] = \"evsrwsRRR\",\n  [546] = \"evsrwiuRRA\", [547] = \"evsrwisRRA\",\n  [548] = \"evslwRRR\", [550] = \"evslwiRRA\",\n  [552] = \"evrlwRRR\", [553] = \"evsplatiRS\",\n  [554] = \"evrlwiRRA\", [555] = \"evsplatfiRS\",\n  [556] = \"evmergehiRRR\", [557] = \"evmergeloRRR\",\n  [558] = \"evmergehiloRRR\", [559] = \"evmergelohiRRR\",\n\n  [560] = \"evcmpgtuYRR\", [561] = \"evcmpgtsYRR\",\n  [562] = \"evcmpltuYRR\", [563] = \"evcmpltsYRR\",\n  [564] = \"evcmpeqYRR\",\n\n  [632] = \"evselRRR\", [633] = \"evselRRRW\",\n  [634] = \"evselRRRW\", [635] = \"evselRRRW\",\n  [636] = \"evselRRRW\", [637] = \"evselRRRW\",\n  [638] = \"evselRRRW\", [639] = \"evselRRRW\",\n\n  [640] = \"evfsaddRRR\", [641] = \"evfssubRRR\",\n  [644] = \"evfsabsRR\", [645] = \"evfsnabsRR\", [646] = \"evfsnegRR\",\n  [648] = \"evfsmulRRR\", [649] = \"evfsdivRRR\",\n  [652] = \"evfscmpgtYRR\", [653] = \"evfscmpltYRR\", [654] = \"evfscmpeqYRR\",\n  [656] = \"evfscfuiR-R\", [657] = \"evfscfsiR-R\",\n  [658] = \"evfscfufR-R\", [659] = \"evfscfsfR-R\",\n  [660] = \"evfsctuiR-R\", [661] = \"evfsctsiR-R\",\n  [662] = \"evfsctufR-R\", [663] = \"evfsctsfR-R\",\n  [664] = \"evfsctuizR-R\", [666] = \"evfsctsizR-R\",\n  [668] = \"evfststgtYRR\", [669] = \"evfststltYRR\", [670] = \"evfststeqYRR\",\n\n  [704] = \"efsaddRRR\", [705] = \"efssubRRR\",\n  [708] = \"efsabsRR\", [709] = \"efsnabsRR\", [710] = \"efsnegRR\",\n  [712] = \"efsmulRRR\", [713] = \"efsdivRRR\",\n  [716] = \"efscmpgtYRR\", [717] = \"efscmpltYRR\", [718] = \"efscmpeqYRR\",\n  [719] = \"efscfdR-R\",\n  [720] = \"efscfuiR-R\", [721] = \"efscfsiR-R\",\n  [722] = \"efscfufR-R\", [723] = \"efscfsfR-R\",\n  [724] = \"efsctuiR-R\", [725] = \"efsctsiR-R\",\n  [726] = \"efsctufR-R\", [727] = \"efsctsfR-R\",\n  [728] = \"efsctuizR-R\", [730] = \"efsctsizR-R\",\n  [732] = \"efststgtYRR\", [733] = \"efststltYRR\", [734] = \"efststeqYRR\",\n\n  [736] = \"efdaddRRR\", [737] = \"efdsubRRR\",\n  [738] = \"efdcfuidR-R\", [739] = \"efdcfsidR-R\",\n  [740] = \"efdabsRR\", [741] = \"efdnabsRR\", [742] = \"efdnegRR\",\n  [744] = \"efdmulRRR\", [745] = \"efddivRRR\",\n  [746] = \"efdctuidzR-R\", [747] = \"efdctsidzR-R\",\n  [748] = \"efdcmpgtYRR\", [749] = \"efdcmpltYRR\", [750] = \"efdcmpeqYRR\",\n  [751] = \"efdcfsR-R\",\n  [752] = \"efdcfuiR-R\", [753] = \"efdcfsiR-R\",\n  [754] = \"efdcfufR-R\", [755] = \"efdcfsfR-R\",\n  [756] = \"efdctuiR-R\", [757] = \"efdctsiR-R\",\n  [758] = \"efdctufR-R\", [759] = \"efdctsfR-R\",\n  [760] = \"efdctuizR-R\", [762] = \"efdctsizR-R\",\n  [764] = \"efdtstgtYRR\", [765] = \"efdtstltYRR\", [766] = \"efdtsteqYRR\",\n\n  [768] = \"evlddxRR0R\", [769] = \"evlddRR8\",\n  [770] = \"evldwxRR0R\", [771] = \"evldwRR8\",\n  [772] = \"evldhxRR0R\", [773] = \"evldhRR8\",\n  [776] = \"evlhhesplatxRR0R\", [777] = \"evlhhesplatRR2\",\n  [780] = \"evlhhousplatxRR0R\", [781] = \"evlhhousplatRR2\",\n  [782] = \"evlhhossplatxRR0R\", [783] = \"evlhhossplatRR2\",\n  [784] = \"evlwhexRR0R\", [785] = \"evlwheRR4\",\n  [788] = \"evlwhouxRR0R\", [789] = \"evlwhouRR4\",\n  [790] = \"evlwhosxRR0R\", [791] = \"evlwhosRR4\",\n  [792] = \"evlwwsplatxRR0R\", [793] = \"evlwwsplatRR4\",\n  [796] = \"evlwhsplatxRR0R\", [797] = \"evlwhsplatRR4\",\n\n  [800] = \"evstddxRR0R\", [801] = \"evstddRR8\",\n  [802] = \"evstdwxRR0R\", [803] = \"evstdwRR8\",\n  [804] = \"evstdhxRR0R\", [805] = \"evstdhRR8\",\n  [816] = \"evstwhexRR0R\", [817] = \"evstwheRR4\",\n  [820] = \"evstwhoxRR0R\", [821] = \"evstwhoRR4\",\n  [824] = \"evstwwexRR0R\", [825] = \"evstwweRR4\",\n  [828] = \"evstwwoxRR0R\", [829] = \"evstwwoRR4\",\n\n  [1027] = \"evmhessfRRR\", [1031] = \"evmhossfRRR\", [1032] = \"evmheumiRRR\",\n  [1033] = \"evmhesmiRRR\", [1035] = \"evmhesmfRRR\", [1036] = \"evmhoumiRRR\",\n  [1037] = \"evmhosmiRRR\", [1039] = \"evmhosmfRRR\", [1059] = \"evmhessfaRRR\",\n  [1063] = \"evmhossfaRRR\", [1064] = \"evmheumiaRRR\", [1065] = \"evmhesmiaRRR\",\n  [1067] = \"evmhesmfaRRR\", [1068] = \"evmhoumiaRRR\", [1069] = \"evmhosmiaRRR\",\n  [1071] = \"evmhosmfaRRR\", [1095] = \"evmwhssfRRR\", [1096] = \"evmwlumiRRR\",\n  [1100] = \"evmwhumiRRR\", [1101] = \"evmwhsmiRRR\", [1103] = \"evmwhsmfRRR\",\n  [1107] = \"evmwssfRRR\", [1112] = \"evmwumiRRR\", [1113] = \"evmwsmiRRR\",\n  [1115] = \"evmwsmfRRR\", [1127] = \"evmwhssfaRRR\", [1128] = \"evmwlumiaRRR\",\n  [1132] = \"evmwhumiaRRR\", [1133] = \"evmwhsmiaRRR\", [1135] = \"evmwhsmfaRRR\",\n  [1139] = \"evmwssfaRRR\", [1144] = \"evmwumiaRRR\", [1145] = \"evmwsmiaRRR\",\n  [1147] = \"evmwsmfaRRR\",\n\n  [1216] = \"evaddusiaawRR\", [1217] = \"evaddssiaawRR\",\n  [1218] = \"evsubfusiaawRR\", [1219] = \"evsubfssiaawRR\",\n  [1220] = \"evmraRR\",\n  [1222] = \"evdivwsRRR\", [1223] = \"evdivwuRRR\",\n  [1224] = \"evaddumiaawRR\", [1225] = \"evaddsmiaawRR\",\n  [1226] = \"evsubfumiaawRR\", [1227] = \"evsubfsmiaawRR\",\n\n  [1280] = \"evmheusiaawRRR\", [1281] = \"evmhessiaawRRR\",\n  [1283] = \"evmhessfaawRRR\", [1284] = \"evmhousiaawRRR\",\n  [1285] = \"evmhossiaawRRR\", [1287] = \"evmhossfaawRRR\",\n  [1288] = \"evmheumiaawRRR\", [1289] = \"evmhesmiaawRRR\",\n  [1291] = \"evmhesmfaawRRR\", [1292] = \"evmhoumiaawRRR\",\n  [1293] = \"evmhosmiaawRRR\", [1295] = \"evmhosmfaawRRR\",\n  [1320] = \"evmhegumiaaRRR\", [1321] = \"evmhegsmiaaRRR\",\n  [1323] = \"evmhegsmfaaRRR\", [1324] = \"evmhogumiaaRRR\",\n  [1325] = \"evmhogsmiaaRRR\", [1327] = \"evmhogsmfaaRRR\",\n  [1344] = \"evmwlusiaawRRR\", [1345] = \"evmwlssiaawRRR\",\n  [1352] = \"evmwlumiaawRRR\", [1353] = \"evmwlsmiaawRRR\",\n  [1363] = \"evmwssfaaRRR\", [1368] = \"evmwumiaaRRR\",\n  [1369] = \"evmwsmiaaRRR\", [1371] = \"evmwsmfaaRRR\",\n  [1408] = \"evmheusianwRRR\", [1409] = \"evmhessianwRRR\",\n  [1411] = \"evmhessfanwRRR\", [1412] = \"evmhousianwRRR\",\n  [1413] = \"evmhossianwRRR\", [1415] = \"evmhossfanwRRR\",\n  [1416] = \"evmheumianwRRR\", [1417] = \"evmhesmianwRRR\",\n  [1419] = \"evmhesmfanwRRR\", [1420] = \"evmhoumianwRRR\",\n  [1421] = \"evmhosmianwRRR\", [1423] = \"evmhosmfanwRRR\",\n  [1448] = \"evmhegumianRRR\", [1449] = \"evmhegsmianRRR\",\n  [1451] = \"evmhegsmfanRRR\", [1452] = \"evmhogumianRRR\",\n  [1453] = \"evmhogsmianRRR\", [1455] = \"evmhogsmfanRRR\",\n  [1472] = \"evmwlusianwRRR\", [1473] = \"evmwlssianwRRR\",\n  [1480] = \"evmwlumianwRRR\", [1481] = \"evmwlsmianwRRR\",\n  [1491] = \"evmwssfanRRR\", [1496] = \"evmwumianRRR\",\n  [1497] = \"evmwsmianRRR\", [1499] = \"evmwsmfanRRR\",\n}\n\nlocal map_pri = {\n  [0] = false,\tfalse,\t\t\"tdiARI\",\t\"twiARI\",\n  map_spe,\tfalse,\t\tfalse,\t\t\"mulliRRI\",\n  \"subficRRI\",\tfalse,\t\t\"cmpl_iYLRU\",\t\"cmp_iYLRI\",\n  \"addicRRI\",\t\"addic.RRI\",\t\"addi|liRR0I\",\t\"addis|lisRR0I\",\n  \"b_KBJ\",\t\"sc\",\t\t \"bKJ\",\t\tmap_crops,\n  \"rlwimiRR~AAA.\", map_rlwinm,\tfalse,\t\t\"rlwnmRR~RAA.\",\n  \"oriNRR~U\",\t\"orisRR~U\",\t\"xoriRR~U\",\t\"xorisRR~U\",\n  \"andi.RR~U\",\t\"andis.RR~U\",\tmap_rld,\tmap_ext,\n  \"lwzRRD\",\t\"lwzuRRD\",\t\"lbzRRD\",\t\"lbzuRRD\",\n  \"stwRRD\",\t\"stwuRRD\",\t\"stbRRD\",\t\"stbuRRD\",\n  \"lhzRRD\",\t\"lhzuRRD\",\t\"lhaRRD\",\t\"lhauRRD\",\n  \"sthRRD\",\t\"sthuRRD\",\t\"lmwRRD\",\t\"stmwRRD\",\n  \"lfsFRD\",\t\"lfsuFRD\",\t\"lfdFRD\",\t\"lfduFRD\",\n  \"stfsFRD\",\t\"stfsuFRD\",\t\"stfdFRD\",\t\"stfduFRD\",\n  false,\tfalse,\t\tmap_ld,\t\tmap_fps,\n  false,\tfalse,\t\tmap_std,\tmap_fpd,\n}\n\n------------------------------------------------------------------------------\n\nlocal map_gpr = {\n  [0] = \"r0\", \"sp\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\",\n  \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\",\n  \"r16\", \"r17\", \"r18\", \"r19\", \"r20\", \"r21\", \"r22\", \"r23\",\n  \"r24\", \"r25\", \"r26\", \"r27\", \"r28\", \"r29\", \"r30\", \"r31\",\n}\n\nlocal map_cond = { [0] = \"lt\", \"gt\", \"eq\", \"so\", \"ge\", \"le\", \"ne\", \"ns\", }\n\n-- Format a condition bit.\nlocal function condfmt(cond)\n  if cond <= 3 then\n    return map_cond[band(cond, 3)]\n  else\n    return format(\"4*cr%d+%s\", rshift(cond, 2), map_cond[band(cond, 3)])\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local pos = ctx.pos\n  local extra = \"\"\n  if ctx.rel then\n    local sym = ctx.symtab[ctx.rel]\n    if sym then extra = \"\\t->\"..sym end\n  end\n  if ctx.hexdump > 0 then\n    ctx.out(format(\"%08x  %s  %-7s %s%s\\n\",\n\t    ctx.addr+pos, tohex(ctx.op), text, concat(operands, \", \"), extra))\n  else\n    ctx.out(format(\"%08x  %-7s %s%s\\n\",\n\t    ctx.addr+pos, text, concat(operands, \", \"), extra))\n  end\n  ctx.pos = pos + 4\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  return putop(ctx, \".long\", { \"0x\"..tohex(ctx.op) })\nend\n\n-- Disassemble a single instruction.\nlocal function disass_ins(ctx)\n  local pos = ctx.pos\n  local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)\n  local op = bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)\n  local operands = {}\n  local last = nil\n  local rs = 21\n  ctx.op = op\n  ctx.rel = nil\n\n  local opat = map_pri[rshift(b0, 2)]\n  while type(opat) ~= \"string\" do\n    if not opat then return unknown(ctx) end\n    opat = opat[band(rshift(op, opat.shift), opat.mask)]\n  end\n  local name, pat = match(opat, \"^([a-z0-9_.]*)(.*)\")\n  local altname, pat2 = match(pat, \"|([a-z0-9_.]*)(.*)\")\n  if altname then pat = pat2 end\n\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"R\" then\n      x = map_gpr[band(rshift(op, rs), 31)]\n      rs = rs - 5\n    elseif p == \"F\" then\n      x = \"f\"..band(rshift(op, rs), 31)\n      rs = rs - 5\n    elseif p == \"A\" then\n      x = band(rshift(op, rs), 31)\n      rs = rs - 5\n    elseif p == \"S\" then\n      x = arshift(lshift(op, 27-rs), 27)\n      rs = rs - 5\n    elseif p == \"I\" then\n      x = arshift(lshift(op, 16), 16)\n    elseif p == \"U\" then\n      x = band(op, 0xffff)\n    elseif p == \"D\" or p == \"E\" then\n      local disp = arshift(lshift(op, 16), 16)\n      if p == \"E\" then disp = band(disp, -4) end\n      if last == \"r0\" then last = \"0\" end\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p >= \"2\" and p <= \"8\" then\n      local disp = band(rshift(op, rs), 31) * p\n      if last == \"r0\" then last = \"0\" end\n      operands[#operands] = format(\"%d(%s)\", disp, last)\n    elseif p == \"H\" then\n      x = band(rshift(op, rs), 31) + lshift(band(op, 2), 4)\n      rs = rs - 5\n    elseif p == \"M\" then\n      x = band(rshift(op, rs), 31) + band(op, 0x20)\n    elseif p == \"C\" then\n      x = condfmt(band(rshift(op, rs), 31))\n      rs = rs - 5\n    elseif p == \"B\" then\n      local bo = rshift(op, 21)\n      local cond = band(rshift(op, 16), 31)\n      local cn = \"\"\n      rs = rs - 10\n      if band(bo, 4) == 0 then\n\tcn = band(bo, 2) == 0 and \"dnz\" or \"dz\"\n\tif band(bo, 0x10) == 0 then\n\t  cn = cn..(band(bo, 8) == 0 and \"f\" or \"t\")\n\tend\n\tif band(bo, 0x10) == 0 then x = condfmt(cond) end\n\tname = name..(band(bo, 1) == band(rshift(op, 15), 1) and \"-\" or \"+\")\n      elseif band(bo, 0x10) == 0 then\n\tcn = map_cond[band(cond, 3) + (band(bo, 8) == 0 and 4 or 0)]\n\tif cond > 3 then x = \"cr\"..rshift(cond, 2) end\n\tname = name..(band(bo, 1) == band(rshift(op, 15), 1) and \"-\" or \"+\")\n      end\n      name = gsub(name, \"_\", cn)\n    elseif p == \"J\" then\n      x = arshift(lshift(op, 27-rs), 29-rs)*4\n      if band(op, 2) == 0 then x = ctx.addr + pos + x end\n      ctx.rel = x\n      x = \"0x\"..tohex(x)\n    elseif p == \"K\" then\n      if band(op, 1) ~= 0 then name = name..\"l\" end\n      if band(op, 2) ~= 0 then name = name..\"a\" end\n    elseif p == \"X\" or p == \"Y\" then\n      x = band(rshift(op, rs+2), 7)\n      if x == 0 and p == \"Y\" then x = nil else x = \"cr\"..x end\n      rs = rs - 5\n    elseif p == \"W\" then\n      x = \"cr\"..band(op, 7)\n    elseif p == \"Z\" then\n      x = band(rshift(op, rs-4), 255)\n      rs = rs - 10\n    elseif p == \">\" then\n      operands[#operands] = rshift(operands[#operands], 1)\n    elseif p == \"0\" then\n      if last == \"r0\" then\n\toperands[#operands] = nil\n\tif altname then name = altname end\n      end\n    elseif p == \"L\" then\n      name = gsub(name, \"_\", band(op, 0x00200000) ~= 0 and \"d\" or \"w\")\n    elseif p == \".\" then\n      if band(op, 1) == 1 then name = name..\".\" end\n    elseif p == \"N\" then\n      if op == 0x60000000 then name = \"nop\"; break end\n    elseif p == \"~\" then\n      local n = #operands\n      operands[n-1],  operands[n] = operands[n], operands[n-1]\n    elseif p == \"=\" then\n      local n = #operands\n      if last == operands[n-1] then\n\toperands[n] = nil\n\tname = altname\n      end\n    elseif p == \"%\" then\n      local n = #operands\n      if last == operands[n-1] and last == operands[n-2] then\n\toperands[n] = nil\n\toperands[n-1] = nil\n\tname = altname\n      end\n    elseif p == \"-\" then\n      rs = rs - 5\n    else\n      assert(false)\n    end\n    if x then operands[#operands+1] = x; last = x end\n  end\n\n  return putop(ctx, name, operands)\nend\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  stop = stop - stop % 4\n  ctx.pos = ofs - ofs % 4\n  ctx.rel = nil\n  while ctx.pos < stop do disass_ins(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = addr or 0\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 8\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 32 then return map_gpr[r] end\n  return \"f\"..(r-32)\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  disass = disass,\n  regname = regname\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_x64.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT x64 disassembler wrapper module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This module just exports the 64 bit functions from the combined\n-- x86/x64 disassembler module. All the interesting stuff is there.\n------------------------------------------------------------------------------\n\nlocal dis_x86 = require((string.match(..., \".*%.\") or \"\")..\"dis_x86\")\nreturn {\n  create = dis_x86.create64,\n  disass = dis_x86.disass64,\n  regname = dis_x86.regname64\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dis_x86.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT x86/x64 disassembler module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n-- This is a helper module used by the LuaJIT machine code dumper module.\n--\n-- Sending small code snippets to an external disassembler and mixing the\n-- output with our own stuff was too fragile. So I had to bite the bullet\n-- and write yet another x86 disassembler. Oh well ...\n--\n-- The output format is very similar to what ndisasm generates. But it has\n-- been developed independently by looking at the opcode tables from the\n-- Intel and AMD manuals. The supported instruction set is quite extensive\n-- and reflects what a current generation Intel or AMD CPU implements in\n-- 32 bit and 64 bit mode. Yes, this includes MMX, SSE, SSE2, SSE3, SSSE3,\n-- SSE4.1, SSE4.2, SSE4a, AVX, AVX2 and even privileged and hypervisor\n-- (VMX/SVM) instructions.\n--\n-- Notes:\n-- * The (useless) a16 prefix, 3DNow and pre-586 opcodes are unsupported.\n-- * No attempt at optimization has been made -- it's fast enough for my needs.\n------------------------------------------------------------------------------\n\nlocal type = type\nlocal sub, byte, format = string.sub, string.byte, string.format\nlocal match, gmatch, gsub = string.match, string.gmatch, string.gsub\nlocal lower, rep = string.lower, string.rep\nlocal bit = require(\"bit\")\nlocal tohex = bit.tohex\n\n-- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on.\nlocal map_opc1_32 = {\n--0x\n[0]=\"addBmr\",\"addVmr\",\"addBrm\",\"addVrm\",\"addBai\",\"addVai\",\"push es\",\"pop es\",\n\"orBmr\",\"orVmr\",\"orBrm\",\"orVrm\",\"orBai\",\"orVai\",\"push cs\",\"opc2*\",\n--1x\n\"adcBmr\",\"adcVmr\",\"adcBrm\",\"adcVrm\",\"adcBai\",\"adcVai\",\"push ss\",\"pop ss\",\n\"sbbBmr\",\"sbbVmr\",\"sbbBrm\",\"sbbVrm\",\"sbbBai\",\"sbbVai\",\"push ds\",\"pop ds\",\n--2x\n\"andBmr\",\"andVmr\",\"andBrm\",\"andVrm\",\"andBai\",\"andVai\",\"es:seg\",\"daa\",\n\"subBmr\",\"subVmr\",\"subBrm\",\"subVrm\",\"subBai\",\"subVai\",\"cs:seg\",\"das\",\n--3x\n\"xorBmr\",\"xorVmr\",\"xorBrm\",\"xorVrm\",\"xorBai\",\"xorVai\",\"ss:seg\",\"aaa\",\n\"cmpBmr\",\"cmpVmr\",\"cmpBrm\",\"cmpVrm\",\"cmpBai\",\"cmpVai\",\"ds:seg\",\"aas\",\n--4x\n\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\"incVR\",\n\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\"decVR\",\n--5x\n\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\"pushUR\",\n\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\"popUR\",\n--6x\n\"sz*pushaw,pusha\",\"sz*popaw,popa\",\"boundVrm\",\"arplWmr\",\n\"fs:seg\",\"gs:seg\",\"o16:\",\"a16\",\n\"pushUi\",\"imulVrmi\",\"pushBs\",\"imulVrms\",\n\"insb\",\"insVS\",\"outsb\",\"outsVS\",\n--7x\n\"joBj\",\"jnoBj\",\"jbBj\",\"jnbBj\",\"jzBj\",\"jnzBj\",\"jbeBj\",\"jaBj\",\n\"jsBj\",\"jnsBj\",\"jpeBj\",\"jpoBj\",\"jlBj\",\"jgeBj\",\"jleBj\",\"jgBj\",\n--8x\n\"arith!Bmi\",\"arith!Vmi\",\"arith!Bmi\",\"arith!Vms\",\n\"testBmr\",\"testVmr\",\"xchgBrm\",\"xchgVrm\",\n\"movBmr\",\"movVmr\",\"movBrm\",\"movVrm\",\n\"movVmg\",\"leaVrm\",\"movWgm\",\"popUm\",\n--9x\n\"nop*xchgVaR|pause|xchgWaR|repne nop\",\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\n\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\"xchgVaR\",\n\"sz*cbw,cwde,cdqe\",\"sz*cwd,cdq,cqo\",\"call farViw\",\"wait\",\n\"sz*pushfw,pushf\",\"sz*popfw,popf\",\"sahf\",\"lahf\",\n--Ax\n\"movBao\",\"movVao\",\"movBoa\",\"movVoa\",\n\"movsb\",\"movsVS\",\"cmpsb\",\"cmpsVS\",\n\"testBai\",\"testVai\",\"stosb\",\"stosVS\",\n\"lodsb\",\"lodsVS\",\"scasb\",\"scasVS\",\n--Bx\n\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\"movBRi\",\n\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\"movVRI\",\n--Cx\n\"shift!Bmu\",\"shift!Vmu\",\"retBw\",\"ret\",\"vex*3$lesVrm\",\"vex*2$ldsVrm\",\"movBmi\",\"movVmi\",\n\"enterBwu\",\"leave\",\"retfBw\",\"retf\",\"int3\",\"intBu\",\"into\",\"iretVS\",\n--Dx\n\"shift!Bm1\",\"shift!Vm1\",\"shift!Bmc\",\"shift!Vmc\",\"aamBu\",\"aadBu\",\"salc\",\"xlatb\",\n\"fp*0\",\"fp*1\",\"fp*2\",\"fp*3\",\"fp*4\",\"fp*5\",\"fp*6\",\"fp*7\",\n--Ex\n\"loopneBj\",\"loopeBj\",\"loopBj\",\"sz*jcxzBj,jecxzBj,jrcxzBj\",\n\"inBau\",\"inVau\",\"outBua\",\"outVua\",\n\"callVj\",\"jmpVj\",\"jmp farViw\",\"jmpBj\",\"inBad\",\"inVad\",\"outBda\",\"outVda\",\n--Fx\n\"lock:\",\"int1\",\"repne:rep\",\"rep:\",\"hlt\",\"cmc\",\"testb!Bm\",\"testv!Vm\",\n\"clc\",\"stc\",\"cli\",\"sti\",\"cld\",\"std\",\"incb!Bm\",\"incd!Vm\",\n}\nassert(#map_opc1_32 == 255)\n\n-- Map for 1st opcode byte in 64 bit mode (overrides only).\nlocal map_opc1_64 = setmetatable({\n  [0x06]=false, [0x07]=false, [0x0e]=false,\n  [0x16]=false, [0x17]=false, [0x1e]=false, [0x1f]=false,\n  [0x27]=false, [0x2f]=false, [0x37]=false, [0x3f]=false,\n  [0x60]=false, [0x61]=false, [0x62]=false, [0x63]=\"movsxdVrDmt\", [0x67]=\"a32:\",\n  [0x40]=\"rex*\",   [0x41]=\"rex*b\",   [0x42]=\"rex*x\",   [0x43]=\"rex*xb\",\n  [0x44]=\"rex*r\",  [0x45]=\"rex*rb\",  [0x46]=\"rex*rx\",  [0x47]=\"rex*rxb\",\n  [0x48]=\"rex*w\",  [0x49]=\"rex*wb\",  [0x4a]=\"rex*wx\",  [0x4b]=\"rex*wxb\",\n  [0x4c]=\"rex*wr\", [0x4d]=\"rex*wrb\", [0x4e]=\"rex*wrx\", [0x4f]=\"rex*wrxb\",\n  [0x82]=false, [0x9a]=false, [0xc4]=\"vex*3\", [0xc5]=\"vex*2\", [0xce]=false,\n  [0xd4]=false, [0xd5]=false, [0xd6]=false, [0xea]=false,\n}, { __index = map_opc1_32 })\n\n-- Map for 2nd opcode byte (0F xx). True CISC hell. Hey, I told you.\n-- Prefix dependent MMX/SSE opcodes: (none)|rep|o16|repne, -|F3|66|F2\nlocal map_opc2 = {\n--0x\n[0]=\"sldt!Dmp\",\"sgdt!Ump\",\"larVrm\",\"lslVrm\",nil,\"syscall\",\"clts\",\"sysret\",\n\"invd\",\"wbinvd\",nil,\"ud1\",nil,\"$prefetch!Bm\",\"femms\",\"3dnowMrmu\",\n--1x\n\"movupsXrm|movssXrvm|movupdXrm|movsdXrvm\",\n\"movupsXmr|movssXmvr|movupdXmr|movsdXmvr\",\n\"movhlpsXrm$movlpsXrm|movsldupXrm|movlpdXrm|movddupXrm\",\n\"movlpsXmr||movlpdXmr\",\n\"unpcklpsXrvm||unpcklpdXrvm\",\n\"unpckhpsXrvm||unpckhpdXrvm\",\n\"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm\",\n\"movhpsXmr||movhpdXmr\",\n\"$prefetcht!Bm\",\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\n\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\"hintnopVm\",\n--2x\n\"movUmx$\",\"movUmy$\",\"movUxm$\",\"movUym$\",\"movUmz$\",nil,\"movUzm$\",nil,\n\"movapsXrm||movapdXrm\",\n\"movapsXmr||movapdXmr\",\n\"cvtpi2psXrMm|cvtsi2ssXrvVmt|cvtpi2pdXrMm|cvtsi2sdXrvVmt\",\n\"movntpsXmr|movntssXmr|movntpdXmr|movntsdXmr\",\n\"cvttps2piMrXm|cvttss2siVrXm|cvttpd2piMrXm|cvttsd2siVrXm\",\n\"cvtps2piMrXm|cvtss2siVrXm|cvtpd2piMrXm|cvtsd2siVrXm\",\n\"ucomissXrm||ucomisdXrm\",\n\"comissXrm||comisdXrm\",\n--3x\n\"wrmsr\",\"rdtsc\",\"rdmsr\",\"rdpmc\",\"sysenter\",\"sysexit\",nil,\"getsec\",\n\"opc3*38\",nil,\"opc3*3a\",nil,nil,nil,nil,nil,\n--4x\n\"cmovoVrm\",\"cmovnoVrm\",\"cmovbVrm\",\"cmovnbVrm\",\n\"cmovzVrm\",\"cmovnzVrm\",\"cmovbeVrm\",\"cmovaVrm\",\n\"cmovsVrm\",\"cmovnsVrm\",\"cmovpeVrm\",\"cmovpoVrm\",\n\"cmovlVrm\",\"cmovgeVrm\",\"cmovleVrm\",\"cmovgVrm\",\n--5x\n\"movmskpsVrXm$||movmskpdVrXm$\",\"sqrtpsXrm|sqrtssXrm|sqrtpdXrm|sqrtsdXrm\",\n\"rsqrtpsXrm|rsqrtssXrvm\",\"rcppsXrm|rcpssXrvm\",\n\"andpsXrvm||andpdXrvm\",\"andnpsXrvm||andnpdXrvm\",\n\"orpsXrvm||orpdXrvm\",\"xorpsXrvm||xorpdXrvm\",\n\"addpsXrvm|addssXrvm|addpdXrvm|addsdXrvm\",\"mulpsXrvm|mulssXrvm|mulpdXrvm|mulsdXrvm\",\n\"cvtps2pdXrm|cvtss2sdXrvm|cvtpd2psXrm|cvtsd2ssXrvm\",\n\"cvtdq2psXrm|cvttps2dqXrm|cvtps2dqXrm\",\n\"subpsXrvm|subssXrvm|subpdXrvm|subsdXrvm\",\"minpsXrvm|minssXrvm|minpdXrvm|minsdXrvm\",\n\"divpsXrvm|divssXrvm|divpdXrvm|divsdXrvm\",\"maxpsXrvm|maxssXrvm|maxpdXrvm|maxsdXrvm\",\n--6x\n\"punpcklbwPrvm\",\"punpcklwdPrvm\",\"punpckldqPrvm\",\"packsswbPrvm\",\n\"pcmpgtbPrvm\",\"pcmpgtwPrvm\",\"pcmpgtdPrvm\",\"packuswbPrvm\",\n\"punpckhbwPrvm\",\"punpckhwdPrvm\",\"punpckhdqPrvm\",\"packssdwPrvm\",\n\"||punpcklqdqXrvm\",\"||punpckhqdqXrvm\",\n\"movPrVSm\",\"movqMrm|movdquXrm|movdqaXrm\",\n--7x\n\"pshufwMrmu|pshufhwXrmu|pshufdXrmu|pshuflwXrmu\",\"pshiftw!Pvmu\",\n\"pshiftd!Pvmu\",\"pshiftq!Mvmu||pshiftdq!Xvmu\",\n\"pcmpeqbPrvm\",\"pcmpeqwPrvm\",\"pcmpeqdPrvm\",\"emms*|\",\n\"vmreadUmr||extrqXmuu$|insertqXrmuu$\",\"vmwriteUrm||extrqXrm$|insertqXrm$\",\nnil,nil,\n\"||haddpdXrvm|haddpsXrvm\",\"||hsubpdXrvm|hsubpsXrvm\",\n\"movVSmMr|movqXrm|movVSmXr\",\"movqMmr|movdquXmr|movdqaXmr\",\n--8x\n\"joVj\",\"jnoVj\",\"jbVj\",\"jnbVj\",\"jzVj\",\"jnzVj\",\"jbeVj\",\"jaVj\",\n\"jsVj\",\"jnsVj\",\"jpeVj\",\"jpoVj\",\"jlVj\",\"jgeVj\",\"jleVj\",\"jgVj\",\n--9x\n\"setoBm\",\"setnoBm\",\"setbBm\",\"setnbBm\",\"setzBm\",\"setnzBm\",\"setbeBm\",\"setaBm\",\n\"setsBm\",\"setnsBm\",\"setpeBm\",\"setpoBm\",\"setlBm\",\"setgeBm\",\"setleBm\",\"setgBm\",\n--Ax\n\"push fs\",\"pop fs\",\"cpuid\",\"btVmr\",\"shldVmru\",\"shldVmrc\",nil,nil,\n\"push gs\",\"pop gs\",\"rsm\",\"btsVmr\",\"shrdVmru\",\"shrdVmrc\",\"fxsave!Dmp\",\"imulVrm\",\n--Bx\n\"cmpxchgBmr\",\"cmpxchgVmr\",\"$lssVrm\",\"btrVmr\",\n\"$lfsVrm\",\"$lgsVrm\",\"movzxVrBmt\",\"movzxVrWmt\",\n\"|popcntVrm\",\"ud2Dp\",\"bt!Vmu\",\"btcVmr\",\n\"bsfVrm\",\"bsrVrm|lzcntVrm|bsrWrm\",\"movsxVrBmt\",\"movsxVrWmt\",\n--Cx\n\"xaddBmr\",\"xaddVmr\",\n\"cmppsXrvmu|cmpssXrvmu|cmppdXrvmu|cmpsdXrvmu\",\"$movntiVmr|\",\n\"pinsrwPrvWmu\",\"pextrwDrPmu\",\n\"shufpsXrvmu||shufpdXrvmu\",\"$cmpxchg!Qmp\",\n\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\"bswapVR\",\n--Dx\n\"||addsubpdXrvm|addsubpsXrvm\",\"psrlwPrvm\",\"psrldPrvm\",\"psrlqPrvm\",\n\"paddqPrvm\",\"pmullwPrvm\",\n\"|movq2dqXrMm|movqXmr|movdq2qMrXm$\",\"pmovmskbVrMm||pmovmskbVrXm\",\n\"psubusbPrvm\",\"psubuswPrvm\",\"pminubPrvm\",\"pandPrvm\",\n\"paddusbPrvm\",\"padduswPrvm\",\"pmaxubPrvm\",\"pandnPrvm\",\n--Ex\n\"pavgbPrvm\",\"psrawPrvm\",\"psradPrvm\",\"pavgwPrvm\",\n\"pmulhuwPrvm\",\"pmulhwPrvm\",\n\"|cvtdq2pdXrm|cvttpd2dqXrm|cvtpd2dqXrm\",\"$movntqMmr||$movntdqXmr\",\n\"psubsbPrvm\",\"psubswPrvm\",\"pminswPrvm\",\"porPrvm\",\n\"paddsbPrvm\",\"paddswPrvm\",\"pmaxswPrvm\",\"pxorPrvm\",\n--Fx\n\"|||lddquXrm\",\"psllwPrvm\",\"pslldPrvm\",\"psllqPrvm\",\n\"pmuludqPrvm\",\"pmaddwdPrvm\",\"psadbwPrvm\",\"maskmovqMrm||maskmovdquXrm$\",\n\"psubbPrvm\",\"psubwPrvm\",\"psubdPrvm\",\"psubqPrvm\",\n\"paddbPrvm\",\"paddwPrvm\",\"padddPrvm\",\"ud\",\n}\nassert(map_opc2[255] == \"ud\")\n\n-- Map for three-byte opcodes. Can't wait for their next invention.\nlocal map_opc3 = {\n[\"38\"] = { -- [66] 0f 38 xx\n--0x\n[0]=\"pshufbPrvm\",\"phaddwPrvm\",\"phadddPrvm\",\"phaddswPrvm\",\n\"pmaddubswPrvm\",\"phsubwPrvm\",\"phsubdPrvm\",\"phsubswPrvm\",\n\"psignbPrvm\",\"psignwPrvm\",\"psigndPrvm\",\"pmulhrswPrvm\",\n\"||permilpsXrvm\",\"||permilpdXrvm\",nil,nil,\n--1x\n\"||pblendvbXrma\",nil,nil,nil,\n\"||blendvpsXrma\",\"||blendvpdXrma\",\"||permpsXrvm\",\"||ptestXrm\",\n\"||broadcastssXrm\",\"||broadcastsdXrm\",\"||broadcastf128XrlXm\",nil,\n\"pabsbPrm\",\"pabswPrm\",\"pabsdPrm\",nil,\n--2x\n\"||pmovsxbwXrm\",\"||pmovsxbdXrm\",\"||pmovsxbqXrm\",\"||pmovsxwdXrm\",\n\"||pmovsxwqXrm\",\"||pmovsxdqXrm\",nil,nil,\n\"||pmuldqXrvm\",\"||pcmpeqqXrvm\",\"||$movntdqaXrm\",\"||packusdwXrvm\",\n\"||maskmovpsXrvm\",\"||maskmovpdXrvm\",\"||maskmovpsXmvr\",\"||maskmovpdXmvr\",\n--3x\n\"||pmovzxbwXrm\",\"||pmovzxbdXrm\",\"||pmovzxbqXrm\",\"||pmovzxwdXrm\",\n\"||pmovzxwqXrm\",\"||pmovzxdqXrm\",\"||permdXrvm\",\"||pcmpgtqXrvm\",\n\"||pminsbXrvm\",\"||pminsdXrvm\",\"||pminuwXrvm\",\"||pminudXrvm\",\n\"||pmaxsbXrvm\",\"||pmaxsdXrvm\",\"||pmaxuwXrvm\",\"||pmaxudXrvm\",\n--4x\n\"||pmulddXrvm\",\"||phminposuwXrm\",nil,nil,\nnil,\"||psrlvVSXrvm\",\"||psravdXrvm\",\"||psllvVSXrvm\",\n--5x\n[0x58] = \"||pbroadcastdXrlXm\",[0x59] = \"||pbroadcastqXrlXm\",\n[0x5a] = \"||broadcasti128XrlXm\",\n--7x\n[0x78] = \"||pbroadcastbXrlXm\",[0x79] = \"||pbroadcastwXrlXm\",\n--8x\n[0x8c] = \"||pmaskmovXrvVSm\",\n[0x8e] = \"||pmaskmovVSmXvr\",\n--9x\n[0x96] = \"||fmaddsub132pHXrvm\",[0x97] = \"||fmsubadd132pHXrvm\",\n[0x98] = \"||fmadd132pHXrvm\",[0x99] = \"||fmadd132sHXrvm\",\n[0x9a] = \"||fmsub132pHXrvm\",[0x9b] = \"||fmsub132sHXrvm\",\n[0x9c] = \"||fnmadd132pHXrvm\",[0x9d] = \"||fnmadd132sHXrvm\",\n[0x9e] = \"||fnmsub132pHXrvm\",[0x9f] = \"||fnmsub132sHXrvm\",\n--Ax\n[0xa6] = \"||fmaddsub213pHXrvm\",[0xa7] = \"||fmsubadd213pHXrvm\",\n[0xa8] = \"||fmadd213pHXrvm\",[0xa9] = \"||fmadd213sHXrvm\",\n[0xaa] = \"||fmsub213pHXrvm\",[0xab] = \"||fmsub213sHXrvm\",\n[0xac] = \"||fnmadd213pHXrvm\",[0xad] = \"||fnmadd213sHXrvm\",\n[0xae] = \"||fnmsub213pHXrvm\",[0xaf] = \"||fnmsub213sHXrvm\",\n--Bx\n[0xb6] = \"||fmaddsub231pHXrvm\",[0xb7] = \"||fmsubadd231pHXrvm\",\n[0xb8] = \"||fmadd231pHXrvm\",[0xb9] = \"||fmadd231sHXrvm\",\n[0xba] = \"||fmsub231pHXrvm\",[0xbb] = \"||fmsub231sHXrvm\",\n[0xbc] = \"||fnmadd231pHXrvm\",[0xbd] = \"||fnmadd231sHXrvm\",\n[0xbe] = \"||fnmsub231pHXrvm\",[0xbf] = \"||fnmsub231sHXrvm\",\n--Dx\n[0xdc] = \"||aesencXrvm\", [0xdd] = \"||aesenclastXrvm\",\n[0xde] = \"||aesdecXrvm\", [0xdf] = \"||aesdeclastXrvm\",\n--Fx\n[0xf0] = \"|||crc32TrBmt\",[0xf1] = \"|||crc32TrVmt\",\n[0xf7] = \"| sarxVrmv| shlxVrmv| shrxVrmv\",\n},\n\n[\"3a\"] = { -- [66] 0f 3a xx\n--0x\n[0x00]=\"||permqXrmu\",\"||permpdXrmu\",\"||pblenddXrvmu\",nil,\n\"||permilpsXrmu\",\"||permilpdXrmu\",\"||perm2f128Xrvmu\",nil,\n\"||roundpsXrmu\",\"||roundpdXrmu\",\"||roundssXrvmu\",\"||roundsdXrvmu\",\n\"||blendpsXrvmu\",\"||blendpdXrvmu\",\"||pblendwXrvmu\",\"palignrPrvmu\",\n--1x\nnil,nil,nil,nil,\n\"||pextrbVmXru\",\"||pextrwVmXru\",\"||pextrVmSXru\",\"||extractpsVmXru\",\n\"||insertf128XrvlXmu\",\"||extractf128XlXmYru\",nil,nil,\nnil,nil,nil,nil,\n--2x\n\"||pinsrbXrvVmu\",\"||insertpsXrvmu\",\"||pinsrXrvVmuS\",nil,\n--3x\n[0x38] = \"||inserti128Xrvmu\",[0x39] = \"||extracti128XlXmYru\",\n--4x\n[0x40] = \"||dppsXrvmu\",\n[0x41] = \"||dppdXrvmu\",\n[0x42] = \"||mpsadbwXrvmu\",\n[0x44] = \"||pclmulqdqXrvmu\",\n[0x46] = \"||perm2i128Xrvmu\",\n[0x4a] = \"||blendvpsXrvmb\",[0x4b] = \"||blendvpdXrvmb\",\n[0x4c] = \"||pblendvbXrvmb\",\n--6x\n[0x60] = \"||pcmpestrmXrmu\",[0x61] = \"||pcmpestriXrmu\",\n[0x62] = \"||pcmpistrmXrmu\",[0x63] = \"||pcmpistriXrmu\",\n[0xdf] = \"||aeskeygenassistXrmu\",\n--Fx\n[0xf0] = \"||| rorxVrmu\",\n},\n}\n\n-- Map for VMX/SVM opcodes 0F 01 C0-FF (sgdt group with register operands).\nlocal map_opcvm = {\n[0xc1]=\"vmcall\",[0xc2]=\"vmlaunch\",[0xc3]=\"vmresume\",[0xc4]=\"vmxoff\",\n[0xc8]=\"monitor\",[0xc9]=\"mwait\",\n[0xd8]=\"vmrun\",[0xd9]=\"vmmcall\",[0xda]=\"vmload\",[0xdb]=\"vmsave\",\n[0xdc]=\"stgi\",[0xdd]=\"clgi\",[0xde]=\"skinit\",[0xdf]=\"invlpga\",\n[0xf8]=\"swapgs\",[0xf9]=\"rdtscp\",\n}\n\n-- Map for FP opcodes. And you thought stack machines are simple?\nlocal map_opcfp = {\n-- D8-DF 00-BF: opcodes with a memory operand.\n-- D8\n[0]=\"faddFm\",\"fmulFm\",\"fcomFm\",\"fcompFm\",\"fsubFm\",\"fsubrFm\",\"fdivFm\",\"fdivrFm\",\n\"fldFm\",nil,\"fstFm\",\"fstpFm\",\"fldenvVm\",\"fldcwWm\",\"fnstenvVm\",\"fnstcwWm\",\n-- DA\n\"fiaddDm\",\"fimulDm\",\"ficomDm\",\"ficompDm\",\n\"fisubDm\",\"fisubrDm\",\"fidivDm\",\"fidivrDm\",\n-- DB\n\"fildDm\",\"fisttpDm\",\"fistDm\",\"fistpDm\",nil,\"fld twordFmp\",nil,\"fstp twordFmp\",\n-- DC\n\"faddGm\",\"fmulGm\",\"fcomGm\",\"fcompGm\",\"fsubGm\",\"fsubrGm\",\"fdivGm\",\"fdivrGm\",\n-- DD\n\"fldGm\",\"fisttpQm\",\"fstGm\",\"fstpGm\",\"frstorDmp\",nil,\"fnsaveDmp\",\"fnstswWm\",\n-- DE\n\"fiaddWm\",\"fimulWm\",\"ficomWm\",\"ficompWm\",\n\"fisubWm\",\"fisubrWm\",\"fidivWm\",\"fidivrWm\",\n-- DF\n\"fildWm\",\"fisttpWm\",\"fistWm\",\"fistpWm\",\n\"fbld twordFmp\",\"fildQm\",\"fbstp twordFmp\",\"fistpQm\",\n-- xx C0-FF: opcodes with a pseudo-register operand.\n-- D8\n\"faddFf\",\"fmulFf\",\"fcomFf\",\"fcompFf\",\"fsubFf\",\"fsubrFf\",\"fdivFf\",\"fdivrFf\",\n-- D9\n\"fldFf\",\"fxchFf\",{\"fnop\"},nil,\n{\"fchs\",\"fabs\",nil,nil,\"ftst\",\"fxam\"},\n{\"fld1\",\"fldl2t\",\"fldl2e\",\"fldpi\",\"fldlg2\",\"fldln2\",\"fldz\"},\n{\"f2xm1\",\"fyl2x\",\"fptan\",\"fpatan\",\"fxtract\",\"fprem1\",\"fdecstp\",\"fincstp\"},\n{\"fprem\",\"fyl2xp1\",\"fsqrt\",\"fsincos\",\"frndint\",\"fscale\",\"fsin\",\"fcos\"},\n-- DA\n\"fcmovbFf\",\"fcmoveFf\",\"fcmovbeFf\",\"fcmovuFf\",nil,{nil,\"fucompp\"},nil,nil,\n-- DB\n\"fcmovnbFf\",\"fcmovneFf\",\"fcmovnbeFf\",\"fcmovnuFf\",\n{nil,nil,\"fnclex\",\"fninit\"},\"fucomiFf\",\"fcomiFf\",nil,\n-- DC\n\"fadd toFf\",\"fmul toFf\",nil,nil,\n\"fsub toFf\",\"fsubr toFf\",\"fdivr toFf\",\"fdiv toFf\",\n-- DD\n\"ffreeFf\",nil,\"fstFf\",\"fstpFf\",\"fucomFf\",\"fucompFf\",nil,nil,\n-- DE\n\"faddpFf\",\"fmulpFf\",nil,{nil,\"fcompp\"},\n\"fsubrpFf\",\"fsubpFf\",\"fdivrpFf\",\"fdivpFf\",\n-- DF\nnil,nil,nil,nil,{\"fnstsw ax\"},\"fucomipFf\",\"fcomipFf\",nil,\n}\nassert(map_opcfp[126] == \"fcomipFf\")\n\n-- Map for opcode groups. The subkey is sp from the ModRM byte.\nlocal map_opcgroup = {\n  arith = { \"add\", \"or\", \"adc\", \"sbb\", \"and\", \"sub\", \"xor\", \"cmp\" },\n  shift = { \"rol\", \"ror\", \"rcl\", \"rcr\", \"shl\", \"shr\", \"sal\", \"sar\" },\n  testb = { \"testBmi\", \"testBmi\", \"not\", \"neg\", \"mul\", \"imul\", \"div\", \"idiv\" },\n  testv = { \"testVmi\", \"testVmi\", \"not\", \"neg\", \"mul\", \"imul\", \"div\", \"idiv\" },\n  incb = { \"inc\", \"dec\" },\n  incd = { \"inc\", \"dec\", \"callUmp\", \"$call farDmp\",\n\t   \"jmpUmp\", \"$jmp farDmp\", \"pushUm\" },\n  sldt = { \"sldt\", \"str\", \"lldt\", \"ltr\", \"verr\", \"verw\" },\n  sgdt = { \"vm*$sgdt\", \"vm*$sidt\", \"$lgdt\", \"vm*$lidt\",\n\t   \"smsw\", nil, \"lmsw\", \"vm*$invlpg\" },\n  bt = { nil, nil, nil, nil, \"bt\", \"bts\", \"btr\", \"btc\" },\n  cmpxchg = { nil, \"sz*,cmpxchg8bQmp,cmpxchg16bXmp\", nil, nil,\n\t      nil, nil, \"vmptrld|vmxon|vmclear\", \"vmptrst\" },\n  pshiftw = { nil, nil, \"psrlw\", nil, \"psraw\", nil, \"psllw\" },\n  pshiftd = { nil, nil, \"psrld\", nil, \"psrad\", nil, \"pslld\" },\n  pshiftq = { nil, nil, \"psrlq\", nil, nil, nil, \"psllq\" },\n  pshiftdq = { nil, nil, \"psrlq\", \"psrldq\", nil, nil, \"psllq\", \"pslldq\" },\n  fxsave = { \"$fxsave\", \"$fxrstor\", \"$ldmxcsr\", \"$stmxcsr\",\n\t     nil, \"lfenceDp$\", \"mfenceDp$\", \"sfenceDp$clflush\" },\n  prefetch = { \"prefetch\", \"prefetchw\" },\n  prefetcht = { \"prefetchnta\", \"prefetcht0\", \"prefetcht1\", \"prefetcht2\" },\n}\n\n------------------------------------------------------------------------------\n\n-- Maps for register names.\nlocal map_regs = {\n  B = { \"al\", \"cl\", \"dl\", \"bl\", \"ah\", \"ch\", \"dh\", \"bh\",\n\t\"r8b\", \"r9b\", \"r10b\", \"r11b\", \"r12b\", \"r13b\", \"r14b\", \"r15b\" },\n  B64 = { \"al\", \"cl\", \"dl\", \"bl\", \"spl\", \"bpl\", \"sil\", \"dil\",\n\t  \"r8b\", \"r9b\", \"r10b\", \"r11b\", \"r12b\", \"r13b\", \"r14b\", \"r15b\" },\n  W = { \"ax\", \"cx\", \"dx\", \"bx\", \"sp\", \"bp\", \"si\", \"di\",\n\t\"r8w\", \"r9w\", \"r10w\", \"r11w\", \"r12w\", \"r13w\", \"r14w\", \"r15w\" },\n  D = { \"eax\", \"ecx\", \"edx\", \"ebx\", \"esp\", \"ebp\", \"esi\", \"edi\",\n\t\"r8d\", \"r9d\", \"r10d\", \"r11d\", \"r12d\", \"r13d\", \"r14d\", \"r15d\" },\n  Q = { \"rax\", \"rcx\", \"rdx\", \"rbx\", \"rsp\", \"rbp\", \"rsi\", \"rdi\",\n\t\"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r13\", \"r14\", \"r15\" },\n  M = { \"mm0\", \"mm1\", \"mm2\", \"mm3\", \"mm4\", \"mm5\", \"mm6\", \"mm7\",\n\t\"mm0\", \"mm1\", \"mm2\", \"mm3\", \"mm4\", \"mm5\", \"mm6\", \"mm7\" }, -- No x64 ext!\n  X = { \"xmm0\", \"xmm1\", \"xmm2\", \"xmm3\", \"xmm4\", \"xmm5\", \"xmm6\", \"xmm7\",\n\t\"xmm8\", \"xmm9\", \"xmm10\", \"xmm11\", \"xmm12\", \"xmm13\", \"xmm14\", \"xmm15\" },\n  Y = { \"ymm0\", \"ymm1\", \"ymm2\", \"ymm3\", \"ymm4\", \"ymm5\", \"ymm6\", \"ymm7\",\n\t\"ymm8\", \"ymm9\", \"ymm10\", \"ymm11\", \"ymm12\", \"ymm13\", \"ymm14\", \"ymm15\" },\n}\nlocal map_segregs = { \"es\", \"cs\", \"ss\", \"ds\", \"fs\", \"gs\", \"segr6\", \"segr7\" }\n\n-- Maps for size names.\nlocal map_sz2n = {\n  B = 1, W = 2, D = 4, Q = 8, M = 8, X = 16, Y = 32,\n}\nlocal map_sz2prefix = {\n  B = \"byte\", W = \"word\", D = \"dword\",\n  Q = \"qword\",\n  M = \"qword\", X = \"xword\", Y = \"yword\",\n  F = \"dword\", G = \"qword\", -- No need for sizes/register names for these two.\n}\n\n------------------------------------------------------------------------------\n\n-- Output a nicely formatted line with an opcode and operands.\nlocal function putop(ctx, text, operands)\n  local code, pos, hex = ctx.code, ctx.pos, \"\"\n  local hmax = ctx.hexdump\n  if hmax > 0 then\n    for i=ctx.start,pos-1 do\n      hex = hex..format(\"%02X\", byte(code, i, i))\n    end\n    if #hex > hmax then hex = sub(hex, 1, hmax)..\". \"\n    else hex = hex..rep(\" \", hmax-#hex+2) end\n  end\n  if operands then text = text..\" \"..operands end\n  if ctx.o16 then text = \"o16 \"..text; ctx.o16 = false end\n  if ctx.a32 then text = \"a32 \"..text; ctx.a32 = false end\n  if ctx.rep then text = ctx.rep..\" \"..text; ctx.rep = false end\n  if ctx.rex then\n    local t = (ctx.rexw and \"w\" or \"\")..(ctx.rexr and \"r\" or \"\")..\n\t      (ctx.rexx and \"x\" or \"\")..(ctx.rexb and \"b\" or \"\")..\n\t      (ctx.vexl and \"l\" or \"\")\n    if ctx.vexv and ctx.vexv ~= 0 then t = t..\"v\"..ctx.vexv end\n    if t ~= \"\" then text = ctx.rex..\".\"..t..\" \"..gsub(text, \"^ \", \"\")\n    elseif ctx.rex == \"vex\" then text = gsub(\"v\"..text, \"^v \", \"\") end\n    ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false\n    ctx.rex = false; ctx.vexl = false; ctx.vexv = false\n  end\n  if ctx.seg then\n    local text2, n = gsub(text, \"%[\", \"[\"..ctx.seg..\":\")\n    if n == 0 then text = ctx.seg..\" \"..text else text = text2 end\n    ctx.seg = false\n  end\n  if ctx.lock then text = \"lock \"..text; ctx.lock = false end\n  local imm = ctx.imm\n  if imm then\n    local sym = ctx.symtab[imm]\n    if sym then text = text..\"\\t->\"..sym end\n  end\n  ctx.out(format(\"%08x  %s%s\\n\", ctx.addr+ctx.start, hex, text))\n  ctx.mrm = false\n  ctx.vexv = false\n  ctx.start = pos\n  ctx.imm = nil\nend\n\n-- Clear all prefix flags.\nlocal function clearprefixes(ctx)\n  ctx.o16 = false; ctx.seg = false; ctx.lock = false; ctx.rep = false\n  ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false\n  ctx.rex = false; ctx.a32 = false; ctx.vexl = false\nend\n\n-- Fallback for incomplete opcodes at the end.\nlocal function incomplete(ctx)\n  ctx.pos = ctx.stop+1\n  clearprefixes(ctx)\n  return putop(ctx, \"(incomplete)\")\nend\n\n-- Fallback for unknown opcodes.\nlocal function unknown(ctx)\n  clearprefixes(ctx)\n  return putop(ctx, \"(unknown)\")\nend\n\n-- Return an immediate of the specified size.\nlocal function getimm(ctx, pos, n)\n  if pos+n-1 > ctx.stop then return incomplete(ctx) end\n  local code = ctx.code\n  if n == 1 then\n    local b1 = byte(code, pos, pos)\n    return b1\n  elseif n == 2 then\n    local b1, b2 = byte(code, pos, pos+1)\n    return b1+b2*256\n  else\n    local b1, b2, b3, b4 = byte(code, pos, pos+3)\n    local imm = b1+b2*256+b3*65536+b4*16777216\n    ctx.imm = imm\n    return imm\n  end\nend\n\n-- Process pattern string and generate the operands.\nlocal function putpat(ctx, name, pat)\n  local operands, regs, sz, mode, sp, rm, sc, rx, sdisp\n  local code, pos, stop, vexl = ctx.code, ctx.pos, ctx.stop, ctx.vexl\n\n  -- Chars used: 1DFGHIMPQRSTUVWXYabcdfgijlmoprstuvwxyz\n  for p in gmatch(pat, \".\") do\n    local x = nil\n    if p == \"V\" or p == \"U\" then\n      if ctx.rexw then sz = \"Q\"; ctx.rexw = false\n      elseif ctx.o16 then sz = \"W\"; ctx.o16 = false\n      elseif p == \"U\" and ctx.x64 then sz = \"Q\"\n      else sz = \"D\" end\n      regs = map_regs[sz]\n    elseif p == \"T\" then\n      if ctx.rexw then sz = \"Q\"; ctx.rexw = false else sz = \"D\" end\n      regs = map_regs[sz]\n    elseif p == \"B\" then\n      sz = \"B\"\n      regs = ctx.rex and map_regs.B64 or map_regs.B\n    elseif match(p, \"[WDQMXYFG]\") then\n      sz = p\n      if sz == \"X\" and vexl then sz = \"Y\"; ctx.vexl = false end\n      regs = map_regs[sz]\n    elseif p == \"P\" then\n      sz = ctx.o16 and \"X\" or \"M\"; ctx.o16 = false\n      if sz == \"X\" and vexl then sz = \"Y\"; ctx.vexl = false end\n      regs = map_regs[sz]\n    elseif p == \"H\" then\n      name = name..(ctx.rexw and \"d\" or \"s\")\n      ctx.rexw = false\n    elseif p == \"S\" then\n      name = name..lower(sz)\n    elseif p == \"s\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = imm <= 127 and format(\"+0x%02x\", imm)\n\t\t     or format(\"-0x%02x\", 256-imm)\n      pos = pos+1\n    elseif p == \"u\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = format(\"0x%02x\", imm)\n      pos = pos+1\n    elseif p == \"b\" then\n      local imm = getimm(ctx, pos, 1); if not imm then return end\n      x = regs[imm/16+1]\n      pos = pos+1\n    elseif p == \"w\" then\n      local imm = getimm(ctx, pos, 2); if not imm then return end\n      x = format(\"0x%x\", imm)\n      pos = pos+2\n    elseif p == \"o\" then -- [offset]\n      if ctx.x64 then\n\tlocal imm1 = getimm(ctx, pos, 4); if not imm1 then return end\n\tlocal imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end\n\tx = format(\"[0x%08x%08x]\", imm2, imm1)\n\tpos = pos+8\n      else\n\tlocal imm = getimm(ctx, pos, 4); if not imm then return end\n\tx = format(\"[0x%08x]\", imm)\n\tpos = pos+4\n      end\n    elseif p == \"i\" or p == \"I\" then\n      local n = map_sz2n[sz]\n      if n == 8 and ctx.x64 and p == \"I\" then\n\tlocal imm1 = getimm(ctx, pos, 4); if not imm1 then return end\n\tlocal imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end\n\tx = format(\"0x%08x%08x\", imm2, imm1)\n      else\n\tif n == 8 then n = 4 end\n\tlocal imm = getimm(ctx, pos, n); if not imm then return end\n\tif sz == \"Q\" and (imm < 0 or imm > 0x7fffffff) then\n\t  imm = (0xffffffff+1)-imm\n\t  x = format(imm > 65535 and \"-0x%08x\" or \"-0x%x\", imm)\n\telse\n\t  x = format(imm > 65535 and \"0x%08x\" or \"0x%x\", imm)\n\tend\n      end\n      pos = pos+n\n    elseif p == \"j\" then\n      local n = map_sz2n[sz]\n      if n == 8 then n = 4 end\n      local imm = getimm(ctx, pos, n); if not imm then return end\n      if sz == \"B\" and imm > 127 then imm = imm-256\n      elseif imm > 2147483647 then imm = imm-4294967296 end\n      pos = pos+n\n      imm = imm + pos + ctx.addr\n      if imm > 4294967295 and not ctx.x64 then imm = imm-4294967296 end\n      ctx.imm = imm\n      if sz == \"W\" then\n\tx = format(\"word 0x%04x\", imm%65536)\n      elseif ctx.x64 then\n\tlocal lo = imm % 0x1000000\n\tx = format(\"0x%02x%06x\", (imm-lo) / 0x1000000, lo)\n      else\n\tx = \"0x\"..tohex(imm)\n      end\n    elseif p == \"R\" then\n      local r = byte(code, pos-1, pos-1)%8\n      if ctx.rexb then r = r + 8; ctx.rexb = false end\n      x = regs[r+1]\n    elseif p == \"a\" then x = regs[1]\n    elseif p == \"c\" then x = \"cl\"\n    elseif p == \"d\" then x = \"dx\"\n    elseif p == \"1\" then x = \"1\"\n    else\n      if not mode then\n\tmode = ctx.mrm\n\tif not mode then\n\t  if pos > stop then return incomplete(ctx) end\n\t  mode = byte(code, pos, pos)\n\t  pos = pos+1\n\tend\n\trm = mode%8; mode = (mode-rm)/8\n\tsp = mode%8; mode = (mode-sp)/8\n\tsdisp = \"\"\n\tif mode < 3 then\n\t  if rm == 4 then\n\t    if pos > stop then return incomplete(ctx) end\n\t    sc = byte(code, pos, pos)\n\t    pos = pos+1\n\t    rm = sc%8; sc = (sc-rm)/8\n\t    rx = sc%8; sc = (sc-rx)/8\n\t    if ctx.rexx then rx = rx + 8; ctx.rexx = false end\n\t    if rx == 4 then rx = nil end\n\t  end\n\t  if mode > 0 or rm == 5 then\n\t    local dsz = mode\n\t    if dsz ~= 1 then dsz = 4 end\n\t    local disp = getimm(ctx, pos, dsz); if not disp then return end\n\t    if mode == 0 then rm = nil end\n\t    if rm or rx or (not sc and ctx.x64 and not ctx.a32) then\n\t      if dsz == 1 and disp > 127 then\n\t\tsdisp = format(\"-0x%x\", 256-disp)\n\t      elseif disp >= 0 and disp <= 0x7fffffff then\n\t\tsdisp = format(\"+0x%x\", disp)\n\t      else\n\t\tsdisp = format(\"-0x%x\", (0xffffffff+1)-disp)\n\t      end\n\t    else\n\t      sdisp = format(ctx.x64 and not ctx.a32 and\n\t\tnot (disp >= 0 and disp <= 0x7fffffff)\n\t\tand \"0xffffffff%08x\" or \"0x%08x\", disp)\n\t    end\n\t    pos = pos+dsz\n\t  end\n\tend\n\tif rm and ctx.rexb then rm = rm + 8; ctx.rexb = false end\n\tif ctx.rexr then sp = sp + 8; ctx.rexr = false end\n      end\n      if p == \"m\" then\n\tif mode == 3 then x = regs[rm+1]\n\telse\n\t  local aregs = ctx.a32 and map_regs.D or ctx.aregs\n\t  local srm, srx = \"\", \"\"\n\t  if rm then srm = aregs[rm+1]\n\t  elseif not sc and ctx.x64 and not ctx.a32 then srm = \"rip\" end\n\t  ctx.a32 = false\n\t  if rx then\n\t    if rm then srm = srm..\"+\" end\n\t    srx = aregs[rx+1]\n\t    if sc > 0 then srx = srx..\"*\"..(2^sc) end\n\t  end\n\t  x = format(\"[%s%s%s]\", srm, srx, sdisp)\n\tend\n\tif mode < 3 and\n\t   (not match(pat, \"[aRrgp]\") or match(pat, \"t\")) then -- Yuck.\n\t  x = map_sz2prefix[sz]..\" \"..x\n\tend\n      elseif p == \"r\" then x = regs[sp+1]\n      elseif p == \"g\" then x = map_segregs[sp+1]\n      elseif p == \"p\" then -- Suppress prefix.\n      elseif p == \"f\" then x = \"st\"..rm\n      elseif p == \"x\" then\n\tif sp == 0 and ctx.lock and not ctx.x64 then\n\t  x = \"CR8\"; ctx.lock = false\n\telse\n\t  x = \"CR\"..sp\n\tend\n      elseif p == \"v\" then\n\tif ctx.vexv then\n\t  x = regs[ctx.vexv+1]; ctx.vexv = false\n\tend\n      elseif p == \"y\" then x = \"DR\"..sp\n      elseif p == \"z\" then x = \"TR\"..sp\n      elseif p == \"l\" then vexl = false\n      elseif p == \"t\" then\n      else\n\terror(\"bad pattern `\"..pat..\"'\")\n      end\n    end\n    if x then operands = operands and operands..\", \"..x or x end\n  end\n  ctx.pos = pos\n  return putop(ctx, name, operands)\nend\n\n-- Forward declaration.\nlocal map_act\n\n-- Fetch and cache MRM byte.\nlocal function getmrm(ctx)\n  local mrm = ctx.mrm\n  if not mrm then\n    local pos = ctx.pos\n    if pos > ctx.stop then return nil end\n    mrm = byte(ctx.code, pos, pos)\n    ctx.pos = pos+1\n    ctx.mrm = mrm\n  end\n  return mrm\nend\n\n-- Dispatch to handler depending on pattern.\nlocal function dispatch(ctx, opat, patgrp)\n  if not opat then return unknown(ctx) end\n  if match(opat, \"%|\") then -- MMX/SSE variants depending on prefix.\n    local p\n    if ctx.rep then\n      p = ctx.rep==\"rep\" and \"%|([^%|]*)\" or \"%|[^%|]*%|[^%|]*%|([^%|]*)\"\n      ctx.rep = false\n    elseif ctx.o16 then p = \"%|[^%|]*%|([^%|]*)\"; ctx.o16 = false\n    else p = \"^[^%|]*\" end\n    opat = match(opat, p)\n    if not opat then return unknown(ctx) end\n--    ctx.rep = false; ctx.o16 = false\n    --XXX fails for 66 f2 0f 38 f1 06  crc32 eax,WORD PTR [esi]\n    --XXX remove in branches?\n  end\n  if match(opat, \"%$\") then -- reg$mem variants.\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    opat = match(opat, mrm >= 192 and \"^[^%$]*\" or \"%$(.*)\")\n    if opat == \"\" then return unknown(ctx) end\n  end\n  if opat == \"\" then return unknown(ctx) end\n  local name, pat = match(opat, \"^([a-z0-9 ]*)(.*)\")\n  if pat == \"\" and patgrp then pat = patgrp end\n  return map_act[sub(pat, 1, 1)](ctx, name, pat)\nend\n\n-- Get a pattern from an opcode map and dispatch to handler.\nlocal function dispatchmap(ctx, opcmap)\n  local pos = ctx.pos\n  local opat = opcmap[byte(ctx.code, pos, pos)]\n  pos = pos + 1\n  ctx.pos = pos\n  return dispatch(ctx, opat)\nend\n\n-- Map for action codes. The key is the first char after the name.\nmap_act = {\n  -- Simple opcodes without operands.\n  [\"\"] = function(ctx, name, pat)\n    return putop(ctx, name)\n  end,\n\n  -- Operand size chars fall right through.\n  B = putpat, W = putpat, D = putpat, Q = putpat,\n  V = putpat, U = putpat, T = putpat,\n  M = putpat, X = putpat, P = putpat,\n  F = putpat, G = putpat, Y = putpat,\n  H = putpat,\n\n  -- Collect prefixes.\n  [\":\"] = function(ctx, name, pat)\n    ctx[pat == \":\" and name or sub(pat, 2)] = name\n    if ctx.pos - ctx.start > 5 then return unknown(ctx) end -- Limit #prefixes.\n  end,\n\n  -- Chain to special handler specified by name.\n  [\"*\"] = function(ctx, name, pat)\n    return map_act[name](ctx, name, sub(pat, 2))\n  end,\n\n  -- Use named subtable for opcode group.\n  [\"!\"] = function(ctx, name, pat)\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    return dispatch(ctx, map_opcgroup[name][((mrm-(mrm%8))/8)%8+1], sub(pat, 2))\n  end,\n\n  -- o16,o32[,o64] variants.\n  sz = function(ctx, name, pat)\n    if ctx.o16 then ctx.o16 = false\n    else\n      pat = match(pat, \",(.*)\")\n      if ctx.rexw then\n\tlocal p = match(pat, \",(.*)\")\n\tif p then pat = p; ctx.rexw = false end\n      end\n    end\n    pat = match(pat, \"^[^,]*\")\n    return dispatch(ctx, pat)\n  end,\n\n  -- Two-byte opcode dispatch.\n  opc2 = function(ctx, name, pat)\n    return dispatchmap(ctx, map_opc2)\n  end,\n\n  -- Three-byte opcode dispatch.\n  opc3 = function(ctx, name, pat)\n    return dispatchmap(ctx, map_opc3[pat])\n  end,\n\n  -- VMX/SVM dispatch.\n  vm = function(ctx, name, pat)\n    return dispatch(ctx, map_opcvm[ctx.mrm])\n  end,\n\n  -- Floating point opcode dispatch.\n  fp = function(ctx, name, pat)\n    local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end\n    local rm = mrm%8\n    local idx = pat*8 + ((mrm-rm)/8)%8\n    if mrm >= 192 then idx = idx + 64 end\n    local opat = map_opcfp[idx]\n    if type(opat) == \"table\" then opat = opat[rm+1] end\n    return dispatch(ctx, opat)\n  end,\n\n  -- REX prefix.\n  rex = function(ctx, name, pat)\n    if ctx.rex then return unknown(ctx) end -- Only 1 REX or VEX prefix allowed.\n    for p in gmatch(pat, \".\") do ctx[\"rex\"..p] = true end\n    ctx.rex = \"rex\"\n  end,\n\n  -- VEX prefix.\n  vex = function(ctx, name, pat)\n    if ctx.rex then return unknown(ctx) end -- Only 1 REX or VEX prefix allowed.\n    ctx.rex = \"vex\"\n    local pos = ctx.pos\n    if ctx.mrm then\n      ctx.mrm = nil\n      pos = pos-1\n    end\n    local b = byte(ctx.code, pos, pos)\n    if not b then return incomplete(ctx) end\n    pos = pos+1\n    if b < 128 then ctx.rexr = true end\n    local m = 1\n    if pat == \"3\" then\n      m = b%32; b = (b-m)/32\n      local nb = b%2; b = (b-nb)/2\n      if nb == 0 then ctx.rexb = true end\n      local nx = b%2\n      if nx == 0 then ctx.rexx = true end\n      b = byte(ctx.code, pos, pos)\n      if not b then return incomplete(ctx) end\n      pos = pos+1\n      if b >= 128 then ctx.rexw = true end\n    end\n    ctx.pos = pos\n    local map\n    if m == 1 then map = map_opc2\n    elseif m == 2 then map = map_opc3[\"38\"]\n    elseif m == 3 then map = map_opc3[\"3a\"]\n    else return unknown(ctx) end\n    local p = b%4; b = (b-p)/4\n    if p == 1 then ctx.o16 = \"o16\"\n    elseif p == 2 then ctx.rep = \"rep\"\n    elseif p == 3 then ctx.rep = \"repne\" end\n    local l = b%2; b = (b-l)/2\n    if l ~= 0 then ctx.vexl = true end\n    ctx.vexv = (-1-b)%16\n    return dispatchmap(ctx, map)\n  end,\n\n  -- Special case for nop with REX prefix.\n  nop = function(ctx, name, pat)\n    return dispatch(ctx, ctx.rex and pat or \"nop\")\n  end,\n\n  -- Special case for 0F 77.\n  emms = function(ctx, name, pat)\n    if ctx.rex ~= \"vex\" then\n      return putop(ctx, \"emms\")\n    elseif ctx.vexl then\n      ctx.vexl = false\n      return putop(ctx, \"zeroall\")\n    else\n      return putop(ctx, \"zeroupper\")\n    end\n  end,\n}\n\n------------------------------------------------------------------------------\n\n-- Disassemble a block of code.\nlocal function disass_block(ctx, ofs, len)\n  if not ofs then ofs = 0 end\n  local stop = len and ofs+len or #ctx.code\n  ofs = ofs + 1\n  ctx.start = ofs\n  ctx.pos = ofs\n  ctx.stop = stop\n  ctx.imm = nil\n  ctx.mrm = false\n  clearprefixes(ctx)\n  while ctx.pos <= stop do dispatchmap(ctx, ctx.map1) end\n  if ctx.pos ~= ctx.start then incomplete(ctx) end\nend\n\n-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).\nlocal function create(code, addr, out)\n  local ctx = {}\n  ctx.code = code\n  ctx.addr = (addr or 0) - 1\n  ctx.out = out or io.write\n  ctx.symtab = {}\n  ctx.disass = disass_block\n  ctx.hexdump = 16\n  ctx.x64 = false\n  ctx.map1 = map_opc1_32\n  ctx.aregs = map_regs.D\n  return ctx\nend\n\nlocal function create64(code, addr, out)\n  local ctx = create(code, addr, out)\n  ctx.x64 = true\n  ctx.map1 = map_opc1_64\n  ctx.aregs = map_regs.Q\n  return ctx\nend\n\n-- Simple API: disassemble code (a string) at address and output via out.\nlocal function disass(code, addr, out)\n  create(code, addr, out):disass()\nend\n\nlocal function disass64(code, addr, out)\n  create64(code, addr, out):disass()\nend\n\n-- Return register name for RID.\nlocal function regname(r)\n  if r < 8 then return map_regs.D[r+1] end\n  return map_regs.X[r-7]\nend\n\nlocal function regname64(r)\n  if r < 16 then return map_regs.Q[r+1] end\n  return map_regs.X[r-15]\nend\n\n-- Public module functions.\nreturn {\n  create = create,\n  create64 = create64,\n  disass = disass,\n  disass64 = disass64,\n  regname = regname,\n  regname64 = regname64\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/dump.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT compiler dump module.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module can be used to debug the JIT compiler itself. It dumps the\n-- code representations and structures used in various compiler stages.\n--\n-- Example usage:\n--\n--   luajit -jdump -e \"local x=0; for i=1,1e6 do x=x+i end; print(x)\"\n--   luajit -jdump=im -e \"for i=1,1000 do for j=1,1000 do end end\" | less -R\n--   luajit -jdump=is myapp.lua | less -R\n--   luajit -jdump=-b myapp.lua\n--   luajit -jdump=+aH,myapp.html myapp.lua\n--   luajit -jdump=ixT,myapp.dump myapp.lua\n--\n-- The first argument specifies the dump mode. The second argument gives\n-- the output file name. Default output is to stdout, unless the environment\n-- variable LUAJIT_DUMPFILE is set. The file is overwritten every time the\n-- module is started.\n--\n-- Different features can be turned on or off with the dump mode. If the\n-- mode starts with a '+', the following features are added to the default\n-- set of features; a '-' removes them. Otherwise the features are replaced.\n--\n-- The following dump features are available (* marks the default):\n--\n--  * t  Print a line for each started, ended or aborted trace (see also -jv).\n--  * b  Dump the traced bytecode.\n--  * i  Dump the IR (intermediate representation).\n--    r  Augment the IR with register/stack slots.\n--    s  Dump the snapshot map.\n--  * m  Dump the generated machine code.\n--    x  Print each taken trace exit.\n--    X  Print each taken trace exit and the contents of all registers.\n--    a  Print the IR of aborted traces, too.\n--\n-- The output format can be set with the following characters:\n--\n--    T  Plain text output.\n--    A  ANSI-colored text output\n--    H  Colorized HTML + CSS output.\n--\n-- The default output format is plain text. It's set to ANSI-colored text\n-- if the COLORTERM variable is set. Note: this is independent of any output\n-- redirection, which is actually considered a feature.\n--\n-- You probably want to use less -R to enjoy viewing ANSI-colored text from\n-- a pipe or a file. Add this to your ~/.bashrc: export LESS=\"-R\"\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal funcinfo, funcbc = jutil.funcinfo, jutil.funcbc\nlocal traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek\nlocal tracemc, tracesnap = jutil.tracemc, jutil.tracesnap\nlocal traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr\nlocal bit = require(\"bit\")\nlocal band, shr, tohex = bit.band, bit.rshift, bit.tohex\nlocal sub, gsub, format = string.sub, string.gsub, string.format\nlocal byte, rep = string.byte, string.rep\nlocal type, tostring = type, tostring\nlocal stdout, stderr = io.stdout, io.stderr\n\n-- Load other modules on-demand.\nlocal bcline, disass\n\n-- Active flag, output file handle and dump mode.\nlocal active, out, dumpmode\n\n------------------------------------------------------------------------------\n\nlocal symtabmt = { __index = false }\nlocal symtab = {}\nlocal nexitsym = 0\n\n-- Fill nested symbol table with per-trace exit stub addresses.\nlocal function fillsymtab_tr(tr, nexit)\n  local t = {}\n  symtabmt.__index = t\n  if jit.arch:sub(1, 4) == \"mips\" then\n    t[traceexitstub(tr, 0)] = \"exit\"\n    return\n  end\n  for i=0,nexit-1 do\n    local addr = traceexitstub(tr, i)\n    if addr < 0 then addr = addr + 2^32 end\n    t[addr] = tostring(i)\n  end\n  local addr = traceexitstub(tr, nexit)\n  if addr then t[addr] = \"stack_check\" end\nend\n\n-- Fill symbol table with trace exit stub addresses.\nlocal function fillsymtab(tr, nexit)\n  local t = symtab\n  if nexitsym == 0 then\n    local maskaddr = jit.arch == \"arm\" and -2\n    local ircall = vmdef.ircall\n    for i=0,#ircall do\n      local addr = ircalladdr(i)\n      if addr ~= 0 then\n\tif maskaddr then addr = band(addr, maskaddr) end\n\tif addr < 0 then addr = addr + 2^32 end\n\tt[addr] = ircall[i]\n      end\n    end\n  end\n  if nexitsym == 1000000 then -- Per-trace exit stubs.\n    fillsymtab_tr(tr, nexit)\n  elseif nexit > nexitsym then -- Shared exit stubs.\n    for i=nexitsym,nexit-1 do\n      local addr = traceexitstub(i)\n      if addr == nil then -- Fall back to per-trace exit stubs.\n\tfillsymtab_tr(tr, nexit)\n\tsetmetatable(symtab, symtabmt)\n\tnexit = 1000000\n\tbreak\n      end\n      if addr < 0 then addr = addr + 2^32 end\n      t[addr] = tostring(i)\n    end\n    nexitsym = nexit\n  end\n  return t\nend\n\nlocal function dumpwrite(s)\n  out:write(s)\nend\n\n-- Disassemble machine code.\nlocal function dump_mcode(tr)\n  local info = traceinfo(tr)\n  if not info then return end\n  local mcode, addr, loop = tracemc(tr)\n  if not mcode then return end\n  if not disass then disass = require(\"jit.dis_\"..jit.arch) end\n  if addr < 0 then addr = addr + 2^32 end\n  out:write(\"---- TRACE \", tr, \" mcode \", #mcode, \"\\n\")\n  local ctx = disass.create(mcode, addr, dumpwrite)\n  ctx.hexdump = 0\n  ctx.symtab = fillsymtab(tr, info.nexit)\n  if loop ~= 0 then\n    symtab[addr+loop] = \"LOOP\"\n    ctx:disass(0, loop)\n    out:write(\"->LOOP:\\n\")\n    ctx:disass(loop, #mcode-loop)\n    symtab[addr+loop] = nil\n  else\n    ctx:disass(0, #mcode)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal irtype_text = {\n  [0] = \"nil\",\n  \"fal\",\n  \"tru\",\n  \"lud\",\n  \"str\",\n  \"p32\",\n  \"thr\",\n  \"pro\",\n  \"fun\",\n  \"p64\",\n  \"cdt\",\n  \"tab\",\n  \"udt\",\n  \"flt\",\n  \"num\",\n  \"i8 \",\n  \"u8 \",\n  \"i16\",\n  \"u16\",\n  \"int\",\n  \"u32\",\n  \"i64\",\n  \"u64\",\n  \"sfp\",\n}\n\nlocal colortype_ansi = {\n  [0] = \"%s\",\n  \"%s\",\n  \"%s\",\n  \"\\027[36m%s\\027[m\",\n  \"\\027[32m%s\\027[m\",\n  \"%s\",\n  \"\\027[1m%s\\027[m\",\n  \"%s\",\n  \"\\027[1m%s\\027[m\",\n  \"%s\",\n  \"\\027[33m%s\\027[m\",\n  \"\\027[31m%s\\027[m\",\n  \"\\027[36m%s\\027[m\",\n  \"\\027[34m%s\\027[m\",\n  \"\\027[34m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n  \"\\027[35m%s\\027[m\",\n}\n\nlocal function colorize_text(s)\n  return s\nend\n\nlocal function colorize_ansi(s, t, extra)\n  local out = format(colortype_ansi[t], s)\n  if extra then out = \"\\027[3m\"..out end\n  return out\nend\n\nlocal irtype_ansi = setmetatable({},\n  { __index = function(tab, t)\n      local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end })\n\nlocal html_escape = { [\"<\"] = \"&lt;\", [\">\"] = \"&gt;\", [\"&\"] = \"&amp;\", }\n\nlocal function colorize_html(s, t, extra)\n  s = gsub(s, \"[<>&]\", html_escape)\n  return format('<span class=\"irt_%s%s\">%s</span>',\n\t\tirtype_text[t], extra and \" irt_extra\" or \"\", s)\nend\n\nlocal irtype_html = setmetatable({},\n  { __index = function(tab, t)\n      local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end })\n\nlocal header_html = [[\n<style type=\"text/css\">\nbackground { background: #ffffff; color: #000000; }\npre.ljdump {\nfont-size: 10pt;\nbackground: #f0f4ff;\ncolor: #000000;\nborder: 1px solid #bfcfff;\npadding: 0.5em;\nmargin-left: 2em;\nmargin-right: 2em;\n}\nspan.irt_str { color: #00a000; }\nspan.irt_thr, span.irt_fun { color: #404040; font-weight: bold; }\nspan.irt_tab { color: #c00000; }\nspan.irt_udt, span.irt_lud { color: #00c0c0; }\nspan.irt_num { color: #4040c0; }\nspan.irt_int, span.irt_i8, span.irt_u8, span.irt_i16, span.irt_u16 { color: #b040b0; }\nspan.irt_extra { font-style: italic; }\n</style>\n]]\n\nlocal colorize, irtype\n\n-- Lookup tables to convert some literals into names.\nlocal litname = {\n  [\"SLOAD \"] = setmetatable({}, { __index = function(t, mode)\n    local s = \"\"\n    if band(mode, 1) ~= 0 then s = s..\"P\" end\n    if band(mode, 2) ~= 0 then s = s..\"F\" end\n    if band(mode, 4) ~= 0 then s = s..\"T\" end\n    if band(mode, 8) ~= 0 then s = s..\"C\" end\n    if band(mode, 16) ~= 0 then s = s..\"R\" end\n    if band(mode, 32) ~= 0 then s = s..\"I\" end\n    if band(mode, 64) ~= 0 then s = s..\"K\" end\n    t[mode] = s\n    return s\n  end}),\n  [\"XLOAD \"] = { [0] = \"\", \"R\", \"V\", \"RV\", \"U\", \"RU\", \"VU\", \"RVU\", },\n  [\"CONV  \"] = setmetatable({}, { __index = function(t, mode)\n    local s = irtype[band(mode, 31)]\n    s = irtype[band(shr(mode, 5), 31)]..\".\"..s\n    if band(mode, 0x800) ~= 0 then s = s..\" sext\" end\n    local c = shr(mode, 12)\n    if c == 1 then s = s..\" none\"\n    elseif c == 2 then s = s..\" index\"\n    elseif c == 3 then s = s..\" check\" end\n    t[mode] = s\n    return s\n  end}),\n  [\"FLOAD \"] = vmdef.irfield,\n  [\"FREF  \"] = vmdef.irfield,\n  [\"FPMATH\"] = vmdef.irfpm,\n  [\"TMPREF\"] = { [0] = \"\", \"IN\", \"OUT\", \"INOUT\", \"\", \"\", \"OUT2\", \"INOUT2\" },\n  [\"BUFHDR\"] = { [0] = \"RESET\", \"APPEND\", \"WRITE\" },\n  [\"TOSTR \"] = { [0] = \"INT\", \"NUM\", \"CHAR\" },\n}\n\nlocal function ctlsub(c)\n  if c == \"\\n\" then return \"\\\\n\"\n  elseif c == \"\\r\" then return \"\\\\r\"\n  elseif c == \"\\t\" then return \"\\\\t\"\n  else return format(\"\\\\%03d\", byte(c))\n  end\nend\n\nlocal function fmtfunc(func, pc)\n  local fi = funcinfo(func, pc)\n  if fi.loc then\n    return fi.loc\n  elseif fi.ffid then\n    return vmdef.ffnames[fi.ffid]\n  elseif fi.addr then\n    return format(\"C:%x\", fi.addr)\n  else\n    return \"(?)\"\n  end\nend\n\nlocal function formatk(tr, idx, sn)\n  local k, t, slot = tracek(tr, idx)\n  local tn = type(k)\n  local s\n  if tn == \"number\" then\n    if t < 12 then\n      s = k == 0 and \"NULL\" or format(\"[0x%08x]\", k)\n    elseif band(sn or 0, 0x30000) ~= 0 then\n      s = band(sn, 0x20000) ~= 0 and \"contpc\" or \"ftsz\"\n    elseif k == 2^52+2^51 then\n      s = \"bias\"\n    else\n      s = format(0 < k and k < 0x1p-1026 and \"%+a\" or \"%+.14g\", k)\n    end\n  elseif tn == \"string\" then\n    s = format(#k > 20 and '\"%.20s\"~' or '\"%s\"', gsub(k, \"%c\", ctlsub))\n  elseif tn == \"function\" then\n    s = fmtfunc(k)\n  elseif tn == \"table\" then\n    s = format(\"{%p}\", k)\n  elseif tn == \"userdata\" then\n    if t == 12 then\n      s = format(\"userdata:%p\", k)\n    else\n      s = format(\"[%p]\", k)\n      if s == \"[NULL]\" then s = \"NULL\" end\n    end\n  elseif t == 21 then -- int64_t\n    s = sub(tostring(k), 1, -3)\n    if sub(s, 1, 1) ~= \"-\" then s = \"+\"..s end\n  elseif sn == 0x1057fff then -- SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL)\n    return \"----\" -- Special case for LJ_FR2 slot 1.\n  else\n    s = tostring(k) -- For primitives.\n  end\n  s = colorize(format(\"%-4s\", s), t, band(sn or 0, 0x100000) ~= 0)\n  if slot then\n    s = format(\"%s @%d\", s, slot)\n  end\n  return s\nend\n\nlocal function printsnap(tr, snap)\n  local n = 2\n  for s=0,snap[1]-1 do\n    local sn = snap[n]\n    if shr(sn, 24) == s then\n      n = n + 1\n      local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS\n      if ref < 0 then\n\tout:write(formatk(tr, ref, sn))\n      elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM\n\tout:write(colorize(format(\"%04d/%04d\", ref, ref+1), 14))\n      else\n\tlocal m, ot, op1, op2 = traceir(tr, ref)\n\tout:write(colorize(format(\"%04d\", ref), band(ot, 31), band(sn, 0x100000) ~= 0))\n      end\n      out:write(band(sn, 0x10000) == 0 and \" \" or \"|\") -- SNAP_FRAME\n    else\n      out:write(\"---- \")\n    end\n  end\n  out:write(\"]\\n\")\nend\n\n-- Dump snapshots (not interleaved with IR).\nlocal function dump_snap(tr)\n  out:write(\"---- TRACE \", tr, \" snapshots\\n\")\n  for i=0,1000000000 do\n    local snap = tracesnap(tr, i)\n    if not snap then break end\n    out:write(format(\"#%-3d %04d [ \", i, snap[0]))\n    printsnap(tr, snap)\n  end\nend\n\n-- Return a register name or stack slot for a rid/sp location.\nlocal function ridsp_name(ridsp, ins)\n  if not disass then disass = require(\"jit.dis_\"..jit.arch) end\n  local rid, slot = band(ridsp, 0xff), shr(ridsp, 8)\n  if rid == 253 or rid == 254 then\n    return (slot == 0 or slot == 255) and \" {sink\" or format(\" {%04d\", ins-slot)\n  end\n  if ridsp > 255 then return format(\"[%x]\", slot*4) end\n  if rid < 128 then return disass.regname(rid) end\n  return \"\"\nend\n\n-- Dump CALL* function ref and return optional ctype.\nlocal function dumpcallfunc(tr, ins)\n  local ctype\n  if ins > 0 then\n    local m, ot, op1, op2 = traceir(tr, ins)\n    if band(ot, 31) == 0 then -- nil type means CARG(func, ctype).\n      ins = op1\n      ctype = formatk(tr, op2)\n    end\n  end\n  if ins < 0 then\n    out:write(format(\"[0x%x](\", tonumber((tracek(tr, ins)))))\n  else\n    out:write(format(\"%04d (\", ins))\n  end\n  return ctype\nend\n\n-- Recursively gather CALL* args and dump them.\nlocal function dumpcallargs(tr, ins)\n  if ins < 0 then\n    out:write(formatk(tr, ins))\n  else\n    local m, ot, op1, op2 = traceir(tr, ins)\n    local oidx = 6*shr(ot, 8)\n    local op = sub(vmdef.irnames, oidx+1, oidx+6)\n    if op == \"CARG  \" then\n      dumpcallargs(tr, op1)\n      if op2 < 0 then\n\tout:write(\" \", formatk(tr, op2))\n      else\n\tout:write(\" \", format(\"%04d\", op2))\n      end\n    else\n      out:write(format(\"%04d\", ins))\n    end\n  end\nend\n\n-- Dump IR and interleaved snapshots.\nlocal function dump_ir(tr, dumpsnap, dumpreg)\n  local info = traceinfo(tr)\n  if not info then return end\n  local nins = info.nins\n  out:write(\"---- TRACE \", tr, \" IR\\n\")\n  local irnames = vmdef.irnames\n  local snapref = 65536\n  local snap, snapno\n  if dumpsnap then\n    snap = tracesnap(tr, 0)\n    snapref = snap[0]\n    snapno = 0\n  end\n  for ins=1,nins do\n    if ins >= snapref then\n      if dumpreg then\n\tout:write(format(\"....              SNAP   #%-3d [ \", snapno))\n      else\n\tout:write(format(\"....        SNAP   #%-3d [ \", snapno))\n      end\n      printsnap(tr, snap)\n      snapno = snapno + 1\n      snap = tracesnap(tr, snapno)\n      snapref = snap and snap[0] or 65536\n    end\n    local m, ot, op1, op2, ridsp = traceir(tr, ins)\n    local oidx, t = 6*shr(ot, 8), band(ot, 31)\n    local op = sub(irnames, oidx+1, oidx+6)\n    if op == \"LOOP  \" then\n      if dumpreg then\n\tout:write(format(\"%04d ------------ LOOP ------------\\n\", ins))\n      else\n\tout:write(format(\"%04d ------ LOOP ------------\\n\", ins))\n      end\n    elseif op ~= \"NOP   \" and op ~= \"CARG  \" and\n\t   (dumpreg or op ~= \"RENAME\") then\n      local rid = band(ridsp, 255)\n      if dumpreg then\n\tout:write(format(\"%04d %-6s\", ins, ridsp_name(ridsp, ins)))\n      else\n\tout:write(format(\"%04d \", ins))\n      end\n      out:write(format(\"%s%s %s %s \",\n\t\t       (rid == 254 or rid == 253) and \"}\" or\n\t\t       (band(ot, 128) == 0 and \" \" or \">\"),\n\t\t       band(ot, 64) == 0 and \" \" or \"+\",\n\t\t       irtype[t], op))\n      local m1, m2 = band(m, 3), band(m, 3*4)\n      if sub(op, 1, 4) == \"CALL\" then\n\tlocal ctype\n\tif m2 == 1*4 then -- op2 == IRMlit\n\t  out:write(format(\"%-10s  (\", vmdef.ircall[op2]))\n\telse\n\t  ctype = dumpcallfunc(tr, op2)\n\tend\n\tif op1 ~= -1 then dumpcallargs(tr, op1) end\n\tout:write(\")\")\n\tif ctype then out:write(\" ctype \", ctype) end\n      elseif op == \"CNEW  \" and op2 == -1 then\n\tout:write(formatk(tr, op1))\n      elseif m1 ~= 3 then -- op1 != IRMnone\n\tif op1 < 0 then\n\t  out:write(formatk(tr, op1))\n\telse\n\t  out:write(format(m1 == 0 and \"%04d\" or \"#%-3d\", op1))\n\tend\n\tif m2 ~= 3*4 then -- op2 != IRMnone\n\t  if m2 == 1*4 then -- op2 == IRMlit\n\t    local litn = litname[op]\n\t    if litn and litn[op2] then\n\t      out:write(\"  \", litn[op2])\n\t    elseif op == \"UREFO \" or op == \"UREFC \" then\n\t      out:write(format(\"  #%-3d\", shr(op2, 8)))\n\t    else\n\t      out:write(format(\"  #%-3d\", op2))\n\t    end\n\t  elseif op2 < 0 then\n\t    out:write(\"  \", formatk(tr, op2))\n\t  else\n\t    out:write(format(\"  %04d\", op2))\n\t  end\n\tend\n      end\n      out:write(\"\\n\")\n    end\n  end\n  if snap then\n    if dumpreg then\n      out:write(format(\"....              SNAP   #%-3d [ \", snapno))\n    else\n      out:write(format(\"....        SNAP   #%-3d [ \", snapno))\n    end\n    printsnap(tr, snap)\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal recprefix = \"\"\nlocal recdepth = 0\n\n-- Format trace error message.\nlocal function fmterr(err, info)\n  if type(err) == \"number\" then\n    if type(info) == \"function\" then info = fmtfunc(info) end\n    err = format(vmdef.traceerr[err], info)\n  end\n  return err\nend\n\n-- Dump trace states.\nlocal function dump_trace(what, tr, func, pc, otr, oex)\n  if what == \"stop\" or (what == \"abort\" and dumpmode.a) then\n    if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == \"stop\")\n    elseif dumpmode.s then dump_snap(tr) end\n    if dumpmode.m then dump_mcode(tr) end\n  end\n  if what == \"start\" then\n    if dumpmode.H then out:write('<pre class=\"ljdump\">\\n') end\n    out:write(\"---- TRACE \", tr, \" \", what)\n    if otr then out:write(\" \", otr, \"/\", oex == -1 and \"stitch\" or oex) end\n    out:write(\" \", fmtfunc(func, pc), \"\\n\")\n  elseif what == \"stop\" or what == \"abort\" then\n    out:write(\"---- TRACE \", tr, \" \", what)\n    if what == \"abort\" then\n      out:write(\" \", fmtfunc(func, pc), \" -- \", fmterr(otr, oex), \"\\n\")\n    else\n      local info = traceinfo(tr)\n      local link, ltype = info.link, info.linktype\n      if link == tr or link == 0 then\n\tout:write(\" -> \", ltype, \"\\n\")\n      elseif ltype == \"root\" then\n\tout:write(\" -> \", link, \"\\n\")\n      else\n\tout:write(\" -> \", link, \" \", ltype, \"\\n\")\n      end\n    end\n    if dumpmode.H then out:write(\"</pre>\\n\\n\") else out:write(\"\\n\") end\n  else\n    if what == \"flush\" then symtab, nexitsym = {}, 0 end\n    out:write(\"---- TRACE \", what, \"\\n\\n\")\n  end\n  out:flush()\nend\n\n-- Dump recorded bytecode.\nlocal function dump_record(tr, func, pc, depth)\n  if depth ~= recdepth then\n    recdepth = depth\n    recprefix = rep(\" .\", depth)\n  end\n  local line\n  if pc >= 0 then\n    line = bcline(func, pc, recprefix)\n    if dumpmode.H then line = gsub(line, \"[<>&]\", html_escape) end\n  else\n    line = \"0000 \"..recprefix..\" FUNCC      \\n\"\n  end\n  if pc <= 0 then\n    out:write(sub(line, 1, -2), \"         ; \", fmtfunc(func), \"\\n\")\n  else\n    out:write(line)\n  end\n  if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC\n    out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond.\n  end\nend\n\n------------------------------------------------------------------------------\n\nlocal gpr64 = jit.arch:match(\"64\")\nlocal fprmips32 = jit.arch == \"mips\" or jit.arch == \"mipsel\"\n\n-- Dump taken trace exits.\nlocal function dump_texit(tr, ex, ngpr, nfpr, ...)\n  out:write(\"---- TRACE \", tr, \" exit \", ex, \"\\n\")\n  if dumpmode.X then\n    local regs = {...}\n    if gpr64 then\n      for i=1,ngpr do\n\tout:write(format(\" %016x\", regs[i]))\n\tif i % 4 == 0 then out:write(\"\\n\") end\n      end\n    else\n      for i=1,ngpr do\n\tout:write(\" \", tohex(regs[i]))\n\tif i % 8 == 0 then out:write(\"\\n\") end\n      end\n    end\n    if fprmips32 then\n      for i=1,nfpr,2 do\n\tout:write(format(\" %+17.14g\", regs[ngpr+i]))\n\tif i % 8 == 7 then out:write(\"\\n\") end\n      end\n    else\n      for i=1,nfpr do\n\tout:write(format(\" %+17.14g\", regs[ngpr+i]))\n\tif i % 4 == 0 then out:write(\"\\n\") end\n      end\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Detach dump handlers.\nlocal function dumpoff()\n  if active then\n    active = false\n    jit.attach(dump_texit)\n    jit.attach(dump_record)\n    jit.attach(dump_trace)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach dump handlers.\nlocal function dumpon(opt, outfile)\n  if active then dumpoff() end\n\n  local term = os.getenv(\"TERM\")\n  local colormode = (term and term:match(\"color\") or os.getenv(\"COLORTERM\")) and \"A\" or \"T\"\n  if opt then\n    opt = gsub(opt, \"[TAH]\", function(mode) colormode = mode; return \"\"; end)\n  end\n\n  local m = { t=true, b=true, i=true, m=true, }\n  if opt and opt ~= \"\" then\n    local o = sub(opt, 1, 1)\n    if o ~= \"+\" and o ~= \"-\" then m = {} end\n    for i=1,#opt do m[sub(opt, i, i)] = (o ~= \"-\") end\n  end\n  dumpmode = m\n\n  if m.t or m.b or m.i or m.s or m.m then\n    jit.attach(dump_trace, \"trace\")\n  end\n  if m.b then\n    jit.attach(dump_record, \"record\")\n    if not bcline then bcline = require(\"jit.bc\").line end\n  end\n  if m.x or m.X then\n    jit.attach(dump_texit, \"texit\")\n  end\n\n  if not outfile then outfile = os.getenv(\"LUAJIT_DUMPFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stdout\n  end\n\n  m[colormode] = true\n  if colormode == \"A\" then\n    colorize = colorize_ansi\n    irtype = irtype_ansi\n  elseif colormode == \"H\" then\n    colorize = colorize_html\n    irtype = irtype_html\n    out:write(header_html)\n  else\n    colorize = colorize_text\n    irtype = irtype_text\n  end\n\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  on = dumpon,\n  off = dumpoff,\n  start = dumpon -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/p.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT profiler.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module is a simple command line interface to the built-in\n-- low-overhead profiler of LuaJIT.\n--\n-- The lower-level API of the profiler is accessible via the \"jit.profile\"\n-- module or the luaJIT_profile_* C API.\n--\n-- Example usage:\n--\n--   luajit -jp myapp.lua\n--   luajit -jp=s myapp.lua\n--   luajit -jp=-s myapp.lua\n--   luajit -jp=vl myapp.lua\n--   luajit -jp=G,profile.txt myapp.lua\n--\n-- The following dump features are available:\n--\n--   f  Stack dump: function name, otherwise module:line. Default mode.\n--   F  Stack dump: ditto, but always prepend module.\n--   l  Stack dump: module:line.\n--   <number> stack dump depth (callee < caller). Default: 1.\n--   -<number> Inverse stack dump depth (caller > callee).\n--   s  Split stack dump after first stack level. Implies abs(depth) >= 2.\n--   p  Show full path for module names.\n--   v  Show VM states. Can be combined with stack dumps, e.g. vf or fv.\n--   z  Show zones. Can be combined with stack dumps, e.g. zf or fz.\n--   r  Show raw sample counts. Default: show percentages.\n--   a  Annotate excerpts from source code files.\n--   A  Annotate complete source code files.\n--   G  Produce raw output suitable for graphical tools (e.g. flame graphs).\n--   m<number> Minimum sample percentage to be shown. Default: 3.\n--   i<number> Sampling interval in milliseconds. Default: 10.\n--\n----------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal profile = require(\"jit.profile\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal math = math\nlocal pairs, ipairs, tonumber, floor = pairs, ipairs, tonumber, math.floor\nlocal sort, format = table.sort, string.format\nlocal stdout = io.stdout\nlocal zone -- Load jit.zone module on demand.\n\n-- Output file handle.\nlocal out\n\n------------------------------------------------------------------------------\n\nlocal prof_ud\nlocal prof_states, prof_split, prof_min, prof_raw, prof_fmt, prof_depth\nlocal prof_ann, prof_count1, prof_count2, prof_samples\n\nlocal map_vmmode = {\n  N = \"Compiled\",\n  I = \"Interpreted\",\n  C = \"C code\",\n  G = \"Garbage Collector\",\n  J = \"JIT Compiler\",\n}\n\n-- Profiler callback.\nlocal function prof_cb(th, samples, vmmode)\n  prof_samples = prof_samples + samples\n  local key_stack, key_stack2, key_state\n  -- Collect keys for sample.\n  if prof_states then\n    if prof_states == \"v\" then\n      key_state = map_vmmode[vmmode] or vmmode\n    else\n      key_state = zone:get() or \"(none)\"\n    end\n  end\n  if prof_fmt then\n    key_stack = profile.dumpstack(th, prof_fmt, prof_depth)\n    key_stack = key_stack:gsub(\"%[builtin#(%d+)%]\", function(x)\n      return vmdef.ffnames[tonumber(x)]\n    end)\n    if prof_split == 2 then\n      local k1, k2 = key_stack:match(\"(.-) [<>] (.*)\")\n      if k2 then key_stack, key_stack2 = k1, k2 end\n    elseif prof_split == 3 then\n      key_stack2 = profile.dumpstack(th, \"l\", 1)\n    end\n  end\n  -- Order keys.\n  local k1, k2\n  if prof_split == 1 then\n    if key_state then\n      k1 = key_state\n      if key_stack then k2 = key_stack end\n    end\n  elseif key_stack then\n    k1 = key_stack\n    if key_stack2 then k2 = key_stack2 elseif key_state then k2 = key_state end\n  end\n  -- Coalesce samples in one or two levels.\n  if k1 then\n    local t1 = prof_count1\n    t1[k1] = (t1[k1] or 0) + samples\n    if k2 then\n      local t2 = prof_count2\n      local t3 = t2[k1]\n      if not t3 then t3 = {}; t2[k1] = t3 end\n      t3[k2] = (t3[k2] or 0) + samples\n    end\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Show top N list.\nlocal function prof_top(count1, count2, samples, indent)\n  local t, n = {}, 0\n  for k in pairs(count1) do\n    n = n + 1\n    t[n] = k\n  end\n  sort(t, function(a, b) return count1[a] > count1[b] end)\n  for i=1,n do\n    local k = t[i]\n    local v = count1[k]\n    local pct = floor(v*100/samples + 0.5)\n    if pct < prof_min then break end\n    if not prof_raw then\n      out:write(format(\"%s%2d%%  %s\\n\", indent, pct, k))\n    elseif prof_raw == \"r\" then\n      out:write(format(\"%s%5d  %s\\n\", indent, v, k))\n    else\n      out:write(format(\"%s %d\\n\", k, v))\n    end\n    if count2 then\n      local r = count2[k]\n      if r then\n\tprof_top(r, nil, v, (prof_split == 3 or prof_split == 1) and \"  -- \" or\n\t\t\t    (prof_depth < 0 and \"  -> \" or \"  <- \"))\n      end\n    end\n  end\nend\n\n-- Annotate source code\nlocal function prof_annotate(count1, samples)\n  local files = {}\n  local ms = 0\n  for k, v in pairs(count1) do\n    local pct = floor(v*100/samples + 0.5)\n    ms = math.max(ms, v)\n    if pct >= prof_min then\n      local file, line = k:match(\"^(.*):(%d+)$\")\n      if not file then file = k; line = 0 end\n      local fl = files[file]\n      if not fl then fl = {}; files[file] = fl; files[#files+1] = file end\n      line = tonumber(line)\n      fl[line] = prof_raw and v or pct\n    end\n  end\n  sort(files)\n  local fmtv, fmtn = \" %3d%% | %s\\n\", \"      | %s\\n\"\n  if prof_raw then\n    local n = math.max(5, math.ceil(math.log10(ms)))\n    fmtv = \"%\"..n..\"d | %s\\n\"\n    fmtn = (\" \"):rep(n)..\" | %s\\n\"\n  end\n  local ann = prof_ann\n  for _, file in ipairs(files) do\n    local f0 = file:byte()\n    if f0 == 40 or f0 == 91 then\n      out:write(format(\"\\n====== %s ======\\n[Cannot annotate non-file]\\n\", file))\n      break\n    end\n    local fp, err = io.open(file)\n    if not fp then\n      out:write(format(\"====== ERROR: %s: %s\\n\", file, err))\n      break\n    end\n    out:write(format(\"\\n====== %s ======\\n\", file))\n    local fl = files[file]\n    local n, show = 1, false\n    if ann ~= 0 then\n      for i=1,ann do\n\tif fl[i] then show = true; out:write(\"@@ 1 @@\\n\"); break end\n      end\n    end\n    for line in fp:lines() do\n      if line:byte() == 27 then\n\tout:write(\"[Cannot annotate bytecode file]\\n\")\n\tbreak\n      end\n      local v = fl[n]\n      if ann ~= 0 then\n\tlocal v2 = fl[n+ann]\n\tif show then\n\t  if v2 then show = n+ann elseif v then show = n\n\t  elseif show+ann < n then show = false end\n\telseif v2 then\n\t  show = n+ann\n\t  out:write(format(\"@@ %d @@\\n\", n))\n\tend\n\tif not show then goto next end\n      end\n      if v then\n\tout:write(format(fmtv, v, line))\n      else\n\tout:write(format(fmtn, line))\n      end\n    ::next::\n      n = n + 1\n    end\n    fp:close()\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Finish profiling and dump result.\nlocal function prof_finish()\n  if prof_ud then\n    profile.stop()\n    local samples = prof_samples\n    if samples == 0 then\n      if prof_raw ~= true then out:write(\"[No samples collected]\\n\") end\n      return\n    end\n    if prof_ann then\n      prof_annotate(prof_count1, samples)\n    else\n      prof_top(prof_count1, prof_count2, samples, \"\")\n    end\n    prof_count1 = nil\n    prof_count2 = nil\n    prof_ud = nil\n    if out ~= stdout then out:close() end\n  end\nend\n\n-- Start profiling.\nlocal function prof_start(mode)\n  local interval = \"\"\n  mode = mode:gsub(\"i%d*\", function(s) interval = s; return \"\" end)\n  prof_min = 3\n  mode = mode:gsub(\"m(%d+)\", function(s) prof_min = tonumber(s); return \"\" end)\n  prof_depth = 1\n  mode = mode:gsub(\"%-?%d+\", function(s) prof_depth = tonumber(s); return \"\" end)\n  local m = {}\n  for c in mode:gmatch(\".\") do m[c] = c end\n  prof_states = m.z or m.v\n  if prof_states == \"z\" then zone = require(\"jit.zone\") end\n  local scope = m.l or m.f or m.F or (prof_states and \"\" or \"f\")\n  local flags = (m.p or \"\")\n  prof_raw = m.r\n  if m.s then\n    prof_split = 2\n    if prof_depth == -1 or m[\"-\"] then prof_depth = -2\n    elseif prof_depth == 1 then prof_depth = 2 end\n  elseif mode:find(\"[fF].*l\") then\n    scope = \"l\"\n    prof_split = 3\n  else\n    prof_split = (scope == \"\" or mode:find(\"[zv].*[lfF]\")) and 1 or 0\n  end\n  prof_ann = m.A and 0 or (m.a and 3)\n  if prof_ann then\n    scope = \"l\"\n    prof_fmt = \"pl\"\n    prof_split = 0\n    prof_depth = 1\n  elseif m.G and scope ~= \"\" then\n    prof_fmt = flags..scope..\"Z;\"\n    prof_depth = -100\n    prof_raw = true\n    prof_min = 0\n  elseif scope == \"\" then\n    prof_fmt = false\n  else\n    local sc = prof_split == 3 and m.f or m.F or scope\n    prof_fmt = flags..sc..(prof_depth >= 0 and \"Z < \" or \"Z > \")\n  end\n  prof_count1 = {}\n  prof_count2 = {}\n  prof_samples = 0\n  profile.start(scope:lower()..interval, prof_cb)\n  prof_ud = newproxy(true)\n  getmetatable(prof_ud).__gc = prof_finish\nend\n\n------------------------------------------------------------------------------\n\nlocal function start(mode, outfile)\n  if not outfile then outfile = os.getenv(\"LUAJIT_PROFILEFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stdout\n  end\n  prof_start(mode or \"f\")\nend\n\n-- Public module functions.\nreturn {\n  start = start, -- For -j command line option.\n  stop = prof_finish\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/v.lua",
    "content": "----------------------------------------------------------------------------\n-- Verbose mode of the LuaJIT compiler.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module shows verbose information about the progress of the\n-- JIT compiler. It prints one line for each generated trace. This module\n-- is useful to see which code has been compiled or where the compiler\n-- punts and falls back to the interpreter.\n--\n-- Example usage:\n--\n--   luajit -jv -e \"for i=1,1000 do for j=1,1000 do end end\"\n--   luajit -jv=myapp.out myapp.lua\n--\n-- Default output is to stderr. To redirect the output to a file, pass a\n-- filename as an argument (use '-' for stdout) or set the environment\n-- variable LUAJIT_VERBOSEFILE. The file is overwritten every time the\n-- module is started.\n--\n-- The output from the first example should look like this:\n--\n-- [TRACE   1 (command line):1 loop]\n-- [TRACE   2 (1/3) (command line):1 -> 1]\n--\n-- The first number in each line is the internal trace number. Next are\n-- the file name ('(command line)') and the line number (':1') where the\n-- trace has started. Side traces also show the parent trace number and\n-- the exit number where they are attached to in parentheses ('(1/3)').\n-- An arrow at the end shows where the trace links to ('-> 1'), unless\n-- it loops to itself.\n--\n-- In this case the inner loop gets hot and is traced first, generating\n-- a root trace. Then the last exit from the 1st trace gets hot, too,\n-- and triggers generation of the 2nd trace. The side trace follows the\n-- path along the outer loop and *around* the inner loop, back to its\n-- start, and then links to the 1st trace. Yes, this may seem unusual,\n-- if you know how traditional compilers work. Trace compilers are full\n-- of surprises like this -- have fun! :-)\n--\n-- Aborted traces are shown like this:\n--\n-- [TRACE --- foo.lua:44 -- leaving loop in root trace at foo:lua:50]\n--\n-- Don't worry -- trace aborts are quite common, even in programs which\n-- can be fully compiled. The compiler may retry several times until it\n-- finds a suitable trace.\n--\n-- Of course this doesn't work with features that are not-yet-implemented\n-- (NYI error messages). The VM simply falls back to the interpreter. This\n-- may not matter at all if the particular trace is not very high up in\n-- the CPU usage profile. Oh, and the interpreter is quite fast, too.\n--\n-- Also check out the -jdump module, which prints all the gory details.\n--\n------------------------------------------------------------------------------\n\n-- Cache some library functions and objects.\nlocal jit = require(\"jit\")\nassert(jit.version_num == 20100, \"LuaJIT core/library version mismatch\")\nlocal jutil = require(\"jit.util\")\nlocal vmdef = require(\"jit.vmdef\")\nlocal funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo\nlocal type, format = type, string.format\nlocal stdout, stderr = io.stdout, io.stderr\n\n-- Active flag and output file handle.\nlocal active, out\n\n------------------------------------------------------------------------------\n\nlocal startloc, startex\n\nlocal function fmtfunc(func, pc)\n  local fi = funcinfo(func, pc)\n  if fi.loc then\n    return fi.loc\n  elseif fi.ffid then\n    return vmdef.ffnames[fi.ffid]\n  elseif fi.addr then\n    return format(\"C:%x\", fi.addr)\n  else\n    return \"(?)\"\n  end\nend\n\n-- Format trace error message.\nlocal function fmterr(err, info)\n  if type(err) == \"number\" then\n    if type(info) == \"function\" then info = fmtfunc(info) end\n    err = format(vmdef.traceerr[err], info)\n  end\n  return err\nend\n\n-- Dump trace states.\nlocal function dump_trace(what, tr, func, pc, otr, oex)\n  if what == \"start\" then\n    startloc = fmtfunc(func, pc)\n    startex = otr and \"(\"..otr..\"/\"..(oex == -1 and \"stitch\" or oex)..\") \" or \"\"\n  else\n    if what == \"abort\" then\n      local loc = fmtfunc(func, pc)\n      if loc ~= startloc then\n\tout:write(format(\"[TRACE --- %s%s -- %s at %s]\\n\",\n\t  startex, startloc, fmterr(otr, oex), loc))\n      else\n\tout:write(format(\"[TRACE --- %s%s -- %s]\\n\",\n\t  startex, startloc, fmterr(otr, oex)))\n      end\n    elseif what == \"stop\" then\n      local info = traceinfo(tr)\n      local link, ltype = info.link, info.linktype\n      if ltype == \"interpreter\" then\n\tout:write(format(\"[TRACE %3s %s%s -- fallback to interpreter]\\n\",\n\t  tr, startex, startloc))\n      elseif ltype == \"stitch\" then\n\tout:write(format(\"[TRACE %3s %s%s %s %s]\\n\",\n\t  tr, startex, startloc, ltype, fmtfunc(func, pc)))\n      elseif link == tr or link == 0 then\n\tout:write(format(\"[TRACE %3s %s%s %s]\\n\",\n\t  tr, startex, startloc, ltype))\n      elseif ltype == \"root\" then\n\tout:write(format(\"[TRACE %3s %s%s -> %d]\\n\",\n\t  tr, startex, startloc, link))\n      else\n\tout:write(format(\"[TRACE %3s %s%s -> %d %s]\\n\",\n\t  tr, startex, startloc, link, ltype))\n      end\n    else\n      out:write(format(\"[TRACE %s]\\n\", what))\n    end\n    out:flush()\n  end\nend\n\n------------------------------------------------------------------------------\n\n-- Detach dump handlers.\nlocal function dumpoff()\n  if active then\n    active = false\n    jit.attach(dump_trace)\n    if out and out ~= stdout and out ~= stderr then out:close() end\n    out = nil\n  end\nend\n\n-- Open the output file and attach dump handlers.\nlocal function dumpon(outfile)\n  if active then dumpoff() end\n  if not outfile then outfile = os.getenv(\"LUAJIT_VERBOSEFILE\") end\n  if outfile then\n    out = outfile == \"-\" and stdout or assert(io.open(outfile, \"w\"))\n  else\n    out = stderr\n  end\n  jit.attach(dump_trace, \"trace\")\n  active = true\nend\n\n-- Public module functions.\nreturn {\n  on = dumpon,\n  off = dumpoff,\n  start = dumpon -- For -j command line option.\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/jit/zone.lua",
    "content": "----------------------------------------------------------------------------\n-- LuaJIT profiler zones.\n--\n-- Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n-- Released under the MIT license. See Copyright Notice in luajit.h\n----------------------------------------------------------------------------\n--\n-- This module implements a simple hierarchical zone model.\n--\n-- Example usage:\n--\n--   local zone = require(\"jit.zone\")\n--   zone(\"AI\")\n--   ...\n--     zone(\"A*\")\n--     ...\n--     print(zone:get()) --> \"A*\"\n--     ...\n--     zone()\n--   ...\n--   print(zone:get()) --> \"AI\"\n--   ...\n--   zone()\n--\n----------------------------------------------------------------------------\n\nlocal remove = table.remove\n\nreturn setmetatable({\n  flush = function(t)\n    for i=#t,1,-1 do t[i] = nil end\n  end,\n  get = function(t)\n    return t[#t]\n  end\n}, {\n  __call = function(t, zone)\n    if zone then\n      t[#t+1] = zone\n    else\n      return (assert(remove(t), \"empty zone stack\"))\n    end\n  end\n})\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n/* extra error code for `luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\nLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l);\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);\nLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int narg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\n                                   const char *const lst[]);\n\n/* pre-defined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);\nLUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,\n                                  const char *name);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,\n                                         const char *fname, int szhint);\n\n/* From Lua 5.2. */\nLUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);\nLUALIB_API int luaL_execresult(lua_State *L, int stat);\nLUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\n\t\t\t\t const char *mode);\nLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\n\t\t\t\t   const char *name, const char *mode);\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n\t\t\t\tint level);\nLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\n\t\t\t\t   int sizehint);\nLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\nLUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define luaL_argcheck(L, cond,numarg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n/* From Lua 5.2. */\n#define luaL_newlibtable(L, l) \\\n\tlua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\n#define luaL_newlib(L, l)\t(luaL_newlibtable(L, l), luaL_setfuncs(L, l, 0))\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n\ntypedef struct luaL_Buffer {\n  char *p;\t\t\t/* current position in buffer */\n  int lvl;  /* number of strings in the stack (level) */\n  lua_State *L;\n  char buffer[LUAL_BUFFERSIZE];\n} luaL_Buffer;\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \\\n   (*(B)->p++ = (char)(c)))\n\n/* compatibility only */\n#define luaL_putchar(B,c)\tluaL_addchar(B,c)\n\n#define luaL_addsize(B,n)\t((B)->p += (n))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\n\n\n/* }====================================================== */\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_aux.c",
    "content": "/*\n** Auxiliary library for the Lua/C API.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major parts taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n\n#define lib_aux_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_state.h\"\n#include \"lj_trace.h\"\n#include \"lj_lib.h\"\n\n#if LJ_TARGET_POSIX\n#include <sys/wait.h>\n#endif\n\n/* -- I/O error handling -------------------------------------------------- */\n\nLUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)\n{\n  if (stat) {\n    setboolV(L->top++, 1);\n    return 1;\n  } else {\n    int en = errno;  /* Lua API calls may change this value. */\n    setnilV(L->top++);\n    if (fname)\n      lua_pushfstring(L, \"%s: %s\", fname, strerror(en));\n    else\n      lua_pushfstring(L, \"%s\", strerror(en));\n    setintV(L->top++, en);\n    lj_trace_abort(G(L));\n    return 3;\n  }\n}\n\nLUALIB_API int luaL_execresult(lua_State *L, int stat)\n{\n  if (stat != -1) {\n#if LJ_TARGET_POSIX\n    if (WIFSIGNALED(stat)) {\n      stat = WTERMSIG(stat);\n      setnilV(L->top++);\n      lua_pushliteral(L, \"signal\");\n    } else {\n      if (WIFEXITED(stat))\n\tstat = WEXITSTATUS(stat);\n      if (stat == 0)\n\tsetboolV(L->top++, 1);\n      else\n\tsetnilV(L->top++);\n      lua_pushliteral(L, \"exit\");\n    }\n#else\n    if (stat == 0)\n      setboolV(L->top++, 1);\n    else\n      setnilV(L->top++);\n    lua_pushliteral(L, \"exit\");\n#endif\n    setintV(L->top++, stat);\n    return 3;\n  }\n  return luaL_fileresult(L, 0, NULL);\n}\n\n/* -- Module registration ------------------------------------------------- */\n\nLUALIB_API const char *luaL_findtable(lua_State *L, int idx,\n\t\t\t\t      const char *fname, int szhint)\n{\n  const char *e;\n  lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, (size_t)(e - fname));\n    lua_rawget(L, -2);\n    if (lua_isnil(L, -1)) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, (size_t)(e - fname));\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    } else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\nstatic int libsize(const luaL_Reg *l)\n{\n  int size = 0;\n  for (; l && l->name; l++) size++;\n  return size;\n}\n\nLUALIB_API void luaL_pushmodule(lua_State *L, const char *modname, int sizehint)\n{\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n  lua_getfield(L, -1, modname);\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, sizehint) != NULL)\n      lj_err_callerv(L, LJ_ERR_BADMODN, modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, -3, modname);  /* _LOADED[modname] = new table. */\n  }\n  lua_remove(L, -2);  /* Remove _LOADED table. */\n}\n\nLUALIB_API void luaL_openlib(lua_State *L, const char *libname,\n\t\t\t     const luaL_Reg *l, int nup)\n{\n  lj_lib_checkfpu(L);\n  if (libname) {\n    luaL_pushmodule(L, libname, libsize(l));\n    lua_insert(L, -(nup + 1));  /* Move module table below upvalues. */\n  }\n  if (l)\n    luaL_setfuncs(L, l, nup);\n  else\n    lua_pop(L, nup);  /* Remove upvalues. */\n}\n\nLUALIB_API void luaL_register(lua_State *L, const char *libname,\n\t\t\t      const luaL_Reg *l)\n{\n  luaL_openlib(L, libname, l, 0);\n}\n\nLUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)\n{\n  luaL_checkstack(L, nup, \"too many upvalues\");\n  for (; l->name; l++) {\n    int i;\n    for (i = 0; i < nup; i++)  /* Copy upvalues to the top. */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);\n    lua_setfield(L, -(nup + 2), l->name);\n  }\n  lua_pop(L, nup);  /* Remove upvalues. */\n}\n\nLUALIB_API const char *luaL_gsub(lua_State *L, const char *s,\n\t\t\t\t const char *p, const char *r)\n{\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, (size_t)(wild - s));  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after `p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n/* -- Buffer handling ----------------------------------------------------- */\n\n#define bufflen(B)\t((size_t)((B)->p - (B)->buffer))\n#define bufffree(B)\t((size_t)(LUAL_BUFFERSIZE - bufflen(B)))\n\nstatic int emptybuffer(luaL_Buffer *B)\n{\n  size_t l = bufflen(B);\n  if (l == 0)\n    return 0;  /* put nothing on stack */\n  lua_pushlstring(B->L, B->buffer, l);\n  B->p = B->buffer;\n  B->lvl++;\n  return 1;\n}\n\nstatic void adjuststack(luaL_Buffer *B)\n{\n  if (B->lvl > 1) {\n    lua_State *L = B->L;\n    int toget = 1;  /* number of levels to concat */\n    size_t toplen = lua_strlen(L, -1);\n    do {\n      size_t l = lua_strlen(L, -(toget+1));\n      if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l))\n\tbreak;\n      toplen += l;\n      toget++;\n    } while (toget < B->lvl);\n    lua_concat(L, toget);\n    B->lvl = B->lvl - toget + 1;\n  }\n}\n\nLUALIB_API char *luaL_prepbuffer(luaL_Buffer *B)\n{\n  if (emptybuffer(B))\n    adjuststack(B);\n  return B->buffer;\n}\n\nLUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)\n{\n  if (l <= bufffree(B)) {\n    memcpy(B->p, s, l);\n    B->p += l;\n  } else {\n    emptybuffer(B);\n    lua_pushlstring(B->L, s, l);\n    B->lvl++;\n    adjuststack(B);\n  }\n}\n\nLUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)\n{\n  luaL_addlstring(B, s, strlen(s));\n}\n\nLUALIB_API void luaL_pushresult(luaL_Buffer *B)\n{\n  emptybuffer(B);\n  lua_concat(B->L, B->lvl);\n  B->lvl = 1;\n}\n\nLUALIB_API void luaL_addvalue(luaL_Buffer *B)\n{\n  lua_State *L = B->L;\n  size_t vl;\n  const char *s = lua_tolstring(L, -1, &vl);\n  if (vl <= bufffree(B)) {  /* fit into buffer? */\n    memcpy(B->p, s, vl);  /* put it there */\n    B->p += vl;\n    lua_pop(L, 1);  /* remove from stack */\n  } else {\n    if (emptybuffer(B))\n      lua_insert(L, -2);  /* put buffer before new value */\n    B->lvl++;  /* add new value into B stack */\n    adjuststack(B);\n  }\n}\n\nLUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)\n{\n  B->L = L;\n  B->p = B->buffer;\n  B->lvl = 0;\n}\n\n/* -- Reference management ------------------------------------------------ */\n\n#define FREELIST_REF\t0\n\n/* Convert a stack index to an absolute index. */\n#define abs_index(L, i) \\\n  ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)\n\nLUALIB_API int luaL_ref(lua_State *L, int t)\n{\n  int ref;\n  t = abs_index(L, t);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* `nil' has a unique fixed reference */\n  }\n  lua_rawgeti(L, t, FREELIST_REF);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[FREELIST_REF] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, FREELIST_REF);  /* (t[FREELIST_REF] = t[ref]) */\n  } else {  /* no free elements */\n    ref = (int)lua_objlen(L, t);\n    ref++;  /* create new reference */\n  }\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\nLUALIB_API void luaL_unref(lua_State *L, int t, int ref)\n{\n  if (ref >= 0) {\n    t = abs_index(L, t);\n    lua_rawgeti(L, t, FREELIST_REF);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */\n  }\n}\n\n/* -- Default allocator and panic function -------------------------------- */\n\nstatic int panic(lua_State *L)\n{\n  const char *s = lua_tostring(L, -1);\n  fputs(\"PANIC: unprotected error in call to Lua API (\", stderr);\n  fputs(s ? s : \"?\", stderr);\n  fputc(')', stderr); fputc('\\n', stderr);\n  fflush(stderr);\n  return 0;\n}\n\n#ifdef LUAJIT_USE_SYSMALLOC\n\n#if LJ_64 && !LJ_GC64 && !defined(LUAJIT_USE_VALGRIND)\n#error \"Must use builtin allocator for 64 bit target\"\n#endif\n\nstatic void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)\n{\n  (void)ud;\n  (void)osize;\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  } else {\n    return realloc(ptr, nsize);\n  }\n}\n\nLUALIB_API lua_State *luaL_newstate(void)\n{\n  lua_State *L = lua_newstate(mem_alloc, NULL);\n  if (L) G(L)->panic = panic;\n  return L;\n}\n\n#else\n\nLUALIB_API lua_State *luaL_newstate(void)\n{\n  lua_State *L;\n#if LJ_64 && !LJ_GC64\n  L = lj_state_newstate(LJ_ALLOCF_INTERNAL, NULL);\n#else\n  L = lua_newstate(LJ_ALLOCF_INTERNAL, NULL);\n#endif\n  if (L) G(L)->panic = panic;\n  return L;\n}\n\n#if LJ_64 && !LJ_GC64\nLUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)\n{\n  UNUSED(f); UNUSED(ud);\n  fputs(\"Must use luaL_newstate() for 64 bit target\\n\", stderr);\n  return NULL;\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_base.c",
    "content": "/*\n** Base and coroutine library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <stdio.h>\n\n#define lib_base_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#endif\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* -- Base library: checks ------------------------------------------------ */\n\n#define LJLIB_MODULE_base\n\nLJLIB_ASM(assert)\t\tLJLIB_REC(.)\n{\n  lj_lib_checkany(L, 1);\n  if (L->top == L->base+1)\n    lj_err_caller(L, LJ_ERR_ASSERT);\n  else if (tvisstr(L->base+1) || tvisnumber(L->base+1))\n    lj_err_callermsg(L, strdata(lj_lib_checkstr(L, 2)));\n  else\n    lj_err_run(L);\n  return FFH_UNREACHABLE;\n}\n\n/* ORDER LJ_T */\nLJLIB_PUSH(\"nil\")\nLJLIB_PUSH(\"boolean\")\nLJLIB_PUSH(top-1)  /* boolean */\nLJLIB_PUSH(\"userdata\")\nLJLIB_PUSH(\"string\")\nLJLIB_PUSH(\"upval\")\nLJLIB_PUSH(\"thread\")\nLJLIB_PUSH(\"proto\")\nLJLIB_PUSH(\"function\")\nLJLIB_PUSH(\"trace\")\nLJLIB_PUSH(\"cdata\")\nLJLIB_PUSH(\"table\")\nLJLIB_PUSH(top-9)  /* userdata */\nLJLIB_PUSH(\"number\")\nLJLIB_ASM_(type)\t\tLJLIB_REC(.)\n/* Recycle the lj_lib_checkany(L, 1) from assert. */\n\n/* -- Base library: iterators --------------------------------------------- */\n\n/* This solves a circular dependency problem -- change FF_next_N as needed. */\nLJ_STATIC_ASSERT((int)FF_next == FF_next_N);\n\nLJLIB_ASM(next)\t\t\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_err_msg(L, LJ_ERR_NEXTIDX);\n  return FFH_UNREACHABLE;\n}\n\n#if LJ_52 || LJ_HASFFI\nstatic int ffh_pairs(lua_State *L, MMS mm)\n{\n  TValue *o = lj_lib_checkany(L, 1);\n  cTValue *mo = lj_meta_lookup(L, o, mm);\n  if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {\n    L->top = o+1;  /* Only keep one argument. */\n    copyTV(L, L->base-1-LJ_FR2, mo);  /* Replace callable. */\n    return FFH_TAILCALL;\n  } else {\n    if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);\n    if (LJ_FR2) { copyTV(L, o-1, o); o--; }\n    setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));\n    if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);\n    return FFH_RES(3);\n  }\n}\n#else\n#define ffh_pairs(L, mm)\t(lj_lib_checktab(L, 1), FFH_UNREACHABLE)\n#endif\n\nLJLIB_PUSH(lastcl)\nLJLIB_ASM(pairs)\t\tLJLIB_REC(xpairs 0)\n{\n  return ffh_pairs(L, MM_pairs);\n}\n\nLJLIB_NOREGUV LJLIB_ASM(ipairs_aux)\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkint(L, 2);\n  return FFH_UNREACHABLE;\n}\n\nLJLIB_PUSH(lastcl)\nLJLIB_ASM(ipairs)\t\tLJLIB_REC(xpairs 1)\n{\n  return ffh_pairs(L, MM_ipairs);\n}\n\n/* -- Base library: getters and setters ----------------------------------- */\n\nLJLIB_ASM_(getmetatable)\tLJLIB_REC(.)\n/* Recycle the lj_lib_checkany(L, 1) from assert. */\n\nLJLIB_ASM(setmetatable)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  GCtab *mt = lj_lib_checktabornil(L, 2);\n  if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable)))\n    lj_err_caller(L, LJ_ERR_PROTMT);\n  setgcref(t->metatable, obj2gco(mt));\n  if (mt) { lj_gc_objbarriert(L, t, mt); }\n  settabV(L, L->base-1-LJ_FR2, t);\n  return FFH_RES(1);\n}\n\nLJLIB_CF(getfenv)\t\tLJLIB_REC(.)\n{\n  GCfunc *fn;\n  cTValue *o = L->base;\n  if (!(o < L->top && tvisfunc(o))) {\n    int level = lj_lib_optint(L, 1, 1);\n    o = lj_debug_frame(L, level, &level);\n    if (o == NULL)\n      lj_err_arg(L, 1, LJ_ERR_INVLVL);\n    if (LJ_FR2) o--;\n  }\n  fn = &gcval(o)->fn;\n  settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env));\n  return 1;\n}\n\nLJLIB_CF(setfenv)\n{\n  GCfunc *fn;\n  GCtab *t = lj_lib_checktab(L, 2);\n  cTValue *o = L->base;\n  if (!(o < L->top && tvisfunc(o))) {\n    int level = lj_lib_checkint(L, 1);\n    if (level == 0) {\n      /* NOBARRIER: A thread (i.e. L) is never black. */\n      setgcref(L->env, obj2gco(t));\n      return 0;\n    }\n    o = lj_debug_frame(L, level, &level);\n    if (o == NULL)\n      lj_err_arg(L, 1, LJ_ERR_INVLVL);\n    if (LJ_FR2) o--;\n  }\n  fn = &gcval(o)->fn;\n  if (!isluafunc(fn))\n    lj_err_caller(L, LJ_ERR_SETFENV);\n  setgcref(fn->l.env, obj2gco(t));\n  lj_gc_objbarrier(L, obj2gco(fn), t);\n  setfuncV(L, L->top++, fn);\n  return 1;\n}\n\nLJLIB_ASM(rawget)\t\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkany(L, 2);\n  return FFH_UNREACHABLE;\n}\n\nLJLIB_CF(rawset)\t\tLJLIB_REC(.)\n{\n  lj_lib_checktab(L, 1);\n  lj_lib_checkany(L, 2);\n  L->top = 1+lj_lib_checkany(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\nLJLIB_CF(rawequal)\t\tLJLIB_REC(.)\n{\n  cTValue *o1 = lj_lib_checkany(L, 1);\n  cTValue *o2 = lj_lib_checkany(L, 2);\n  setboolV(L->top-1, lj_obj_equal(o1, o2));\n  return 1;\n}\n\n#if LJ_52\nLJLIB_CF(rawlen)\t\tLJLIB_REC(.)\n{\n  cTValue *o = L->base;\n  int32_t len;\n  if (L->top > o && tvisstr(o))\n    len = (int32_t)strV(o)->len;\n  else\n    len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1));\n  setintV(L->top-1, len);\n  return 1;\n}\n#endif\n\nLJLIB_CF(unpack)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n, i = lj_lib_optint(L, 2, 1);\n  int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?\n\t      lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t);\n  uint32_t nu;\n  if (i > e) return 0;\n  nu = (uint32_t)e - (uint32_t)i;\n  n = (int32_t)(nu+1);\n  if (nu >= LUAI_MAXCSTACK || !lua_checkstack(L, n))\n    lj_err_caller(L, LJ_ERR_UNPACK);\n  do {\n    cTValue *tv = lj_tab_getint(t, i);\n    if (tv) {\n      copyTV(L, L->top++, tv);\n    } else {\n      setnilV(L->top++);\n    }\n  } while (i++ < e);\n  return n;\n}\n\nLJLIB_CF(select)\t\tLJLIB_REC(.)\n{\n  int32_t n = (int32_t)(L->top - L->base);\n  if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') {\n    setintV(L->top-1, n-1);\n    return 1;\n  } else {\n    int32_t i = lj_lib_checkint(L, 1);\n    if (i < 0) i = n + i; else if (i > n) i = n;\n    if (i < 1)\n      lj_err_arg(L, 1, LJ_ERR_IDXRNG);\n    return n - i;\n  }\n}\n\n/* -- Base library: conversions ------------------------------------------- */\n\nLJLIB_ASM(tonumber)\t\tLJLIB_REC(.)\n{\n  int32_t base = lj_lib_optint(L, 2, 10);\n  if (base == 10) {\n    TValue *o = lj_lib_checkany(L, 1);\n    if (lj_strscan_numberobj(o)) {\n      copyTV(L, L->base-1-LJ_FR2, o);\n      return FFH_RES(1);\n    }\n#if LJ_HASFFI\n    if (tviscdata(o)) {\n      CTState *cts = ctype_cts(L);\n      CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid);\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {\n\tif (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) &&\n\t    ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) {\n\t  int32_t i;\n\t  lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0);\n\t  setintV(L->base-1-LJ_FR2, i);\n\t  return FFH_RES(1);\n\t}\n\tlj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE),\n\t\t       (uint8_t *)&(L->base-1-LJ_FR2)->n, o, 0);\n\treturn FFH_RES(1);\n      }\n    }\n#endif\n  } else {\n    const char *p = strdata(lj_lib_checkstr(L, 1));\n    char *ep;\n    unsigned int neg = 0;\n    unsigned long ul;\n    if (base < 2 || base > 36)\n      lj_err_arg(L, 2, LJ_ERR_BASERNG);\n    while (lj_char_isspace((unsigned char)(*p))) p++;\n    if (*p == '-') { p++; neg = 1; } else if (*p == '+') { p++; }\n    if (lj_char_isalnum((unsigned char)(*p))) {\n      ul = strtoul(p, &ep, base);\n      if (p != ep) {\n\twhile (lj_char_isspace((unsigned char)(*ep))) ep++;\n\tif (*ep == '\\0') {\n\t  if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u+neg)) {\n\t    if (neg) ul = (unsigned long)-(long)ul;\n\t    setintV(L->base-1-LJ_FR2, (int32_t)ul);\n\t  } else {\n\t    lua_Number n = (lua_Number)ul;\n\t    if (neg) n = -n;\n\t    setnumV(L->base-1-LJ_FR2, n);\n\t  }\n\t  return FFH_RES(1);\n\t}\n      }\n    }\n  }\n  setnilV(L->base-1-LJ_FR2);\n  return FFH_RES(1);\n}\n\nLJLIB_ASM(tostring)\t\tLJLIB_REC(.)\n{\n  TValue *o = lj_lib_checkany(L, 1);\n  cTValue *mo;\n  L->top = o+1;  /* Only keep one argument. */\n  if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {\n    copyTV(L, L->base-1-LJ_FR2, mo);  /* Replace callable. */\n    return FFH_TAILCALL;\n  }\n  lj_gc_check(L);\n  setstrV(L, L->base-1-LJ_FR2, lj_strfmt_obj(L, L->base));\n  return FFH_RES(1);\n}\n\n/* -- Base library: throw and catch errors -------------------------------- */\n\nLJLIB_CF(error)\n{\n  int32_t level = lj_lib_optint(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_isstring(L, 1) && level > 0) {\n    luaL_where(L, level);\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\nLJLIB_ASM(pcall)\t\tLJLIB_REC(.)\n{\n  lj_lib_checkany(L, 1);\n  lj_lib_checkfunc(L, 2);  /* For xpcall only. */\n  return FFH_UNREACHABLE;\n}\nLJLIB_ASM_(xpcall)\t\tLJLIB_REC(.)\n\n/* -- Base library: load Lua code ----------------------------------------- */\n\nstatic int load_aux(lua_State *L, int status, int envarg)\n{\n  if (status == LUA_OK) {\n    if (tvistab(L->base+envarg-1)) {\n      GCfunc *fn = funcV(L->top-1);\n      GCtab *t = tabV(L->base+envarg-1);\n      setgcref(fn->c.env, obj2gco(t));\n      lj_gc_objbarrier(L, fn, t);\n    }\n    return 1;\n  } else {\n    setnilV(L->top-2);\n    return 2;\n  }\n}\n\nLJLIB_CF(loadfile)\n{\n  GCstr *fname = lj_lib_optstr(L, 1);\n  GCstr *mode = lj_lib_optstr(L, 2);\n  int status;\n  lua_settop(L, 3);  /* Ensure env arg exists. */\n  status = luaL_loadfilex(L, fname ? strdata(fname) : NULL,\n\t\t\t  mode ? strdata(mode) : NULL);\n  return load_aux(L, status, 3);\n}\n\nstatic const char *reader_func(lua_State *L, void *ud, size_t *size)\n{\n  UNUSED(ud);\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  copyTV(L, L->top++, L->base);\n  lua_call(L, 0, 1);  /* Call user-supplied function. */\n  L->top--;\n  if (tvisnil(L->top)) {\n    *size = 0;\n    return NULL;\n  } else if (tvisstr(L->top) || tvisnumber(L->top)) {\n    copyTV(L, L->base+4, L->top);  /* Anchor string in reserved stack slot. */\n    return lua_tolstring(L, 5, size);\n  } else {\n    lj_err_caller(L, LJ_ERR_RDRSTR);\n    return NULL;\n  }\n}\n\nLJLIB_CF(load)\n{\n  GCstr *name = lj_lib_optstr(L, 2);\n  GCstr *mode = lj_lib_optstr(L, 3);\n  int status;\n  if (L->base < L->top &&\n      (tvisstr(L->base) || tvisnumber(L->base) || tvisbuf(L->base))) {\n    const char *s;\n    MSize len;\n    if (tvisbuf(L->base)) {\n      SBufExt *sbx = bufV(L->base);\n      s = sbx->r;\n      len = sbufxlen(sbx);\n      if (!name) name = &G(L)->strempty;  /* Buffers are not NUL-terminated. */\n    } else {\n      GCstr *str = lj_lib_checkstr(L, 1);\n      s = strdata(str);\n      len = str->len;\n    }\n    lua_settop(L, 4);  /* Ensure env arg exists. */\n    status = luaL_loadbufferx(L, s, len, name ? strdata(name) : s,\n\t\t\t      mode ? strdata(mode) : NULL);\n  } else {\n    lj_lib_checkfunc(L, 1);\n    lua_settop(L, 5);  /* Reserve a slot for the string from the reader. */\n    status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : \"=(load)\",\n\t\t       mode ? strdata(mode) : NULL);\n  }\n  return load_aux(L, status, 4);\n}\n\nLJLIB_CF(loadstring)\n{\n  return lj_cf_load(L);\n}\n\nLJLIB_CF(dofile)\n{\n  GCstr *fname = lj_lib_optstr(L, 1);\n  setnilV(L->top);\n  L->top = L->base+1;\n  if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != LUA_OK)\n    lua_error(L);\n  lua_call(L, 0, LUA_MULTRET);\n  return (int)(L->top - L->base) - 1;\n}\n\n/* -- Base library: GC control -------------------------------------------- */\n\nLJLIB_CF(gcinfo)\n{\n  setintV(L->top++, (int32_t)(G(L)->gc.total >> 10));\n  return 1;\n}\n\nLJLIB_CF(collectgarbage)\n{\n  int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT,  /* ORDER LUA_GC* */\n    \"\\4stop\\7restart\\7collect\\5count\\1\\377\\4step\\10setpause\\12setstepmul\\1\\377\\11isrunning\");\n  int32_t data = lj_lib_optint(L, 2, 0);\n  if (opt == LUA_GCCOUNT) {\n    setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);\n  } else {\n    int res = lua_gc(L, opt, data);\n    if (opt == LUA_GCSTEP || opt == LUA_GCISRUNNING)\n      setboolV(L->top, res);\n    else\n      setintV(L->top, res);\n  }\n  L->top++;\n  return 1;\n}\n\n/* -- Base library: miscellaneous functions ------------------------------- */\n\nLJLIB_PUSH(top-2)  /* Upvalue holds weak table. */\nLJLIB_CF(newproxy)\n{\n  lua_settop(L, 1);\n  lua_newuserdata(L, 0);\n  if (lua_toboolean(L, 1) == 0) {  /* newproxy(): without metatable. */\n    return 1;\n  } else if (lua_isboolean(L, 1)) {  /* newproxy(true): with metatable. */\n    lua_newtable(L);\n    lua_pushvalue(L, -1);\n    lua_pushboolean(L, 1);\n    lua_rawset(L, lua_upvalueindex(1));  /* Remember mt in weak table. */\n  } else {  /* newproxy(proxy): inherit metatable. */\n    int validproxy = 0;\n    if (lua_getmetatable(L, 1)) {\n      lua_rawget(L, lua_upvalueindex(1));\n      validproxy = lua_toboolean(L, -1);\n      lua_pop(L, 1);\n    }\n    if (!validproxy)\n      lj_err_arg(L, 1, LJ_ERR_NOPROXY);\n    lua_getmetatable(L, 1);\n  }\n  lua_setmetatable(L, 2);\n  return 1;\n}\n\nLJLIB_PUSH(\"tostring\")\nLJLIB_CF(print)\n{\n  ptrdiff_t i, nargs = L->top - L->base;\n  cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1)));\n  int shortcut;\n  if (tv && !tvisnil(tv)) {\n    copyTV(L, L->top++, tv);\n  } else {\n    setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1)));\n    lua_gettable(L, LUA_GLOBALSINDEX);\n    tv = L->top-1;\n  }\n  shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring) &&\n\t     !gcrefu(basemt_it(G(L), LJ_TNUMX));\n  for (i = 0; i < nargs; i++) {\n    cTValue *o = &L->base[i];\n    const char *str;\n    size_t size;\n    MSize len;\n    if (shortcut && (str = lj_strfmt_wstrnum(L, o, &len)) != NULL) {\n      size = len;\n    } else {\n      copyTV(L, L->top+1, o);\n      copyTV(L, L->top, L->top-1);\n      L->top += 2;\n      lua_call(L, 1, 1);\n      str = lua_tolstring(L, -1, &size);\n      if (!str)\n\tlj_err_caller(L, LJ_ERR_PRTOSTR);\n      L->top--;\n    }\n    if (i)\n      putchar('\\t');\n    fwrite(str, 1, size, stdout);\n  }\n  putchar('\\n');\n  return 0;\n}\n\nLJLIB_PUSH(top-3)\nLJLIB_SET(_VERSION)\n\n#include \"lj_libdef.h\"\n\n/* -- Coroutine library --------------------------------------------------- */\n\n#define LJLIB_MODULE_coroutine\n\nLJLIB_CF(coroutine_status)\n{\n  const char *s;\n  lua_State *co;\n  if (!(L->top > L->base && tvisthread(L->base)))\n    lj_err_arg(L, 1, LJ_ERR_NOCORO);\n  co = threadV(L->base);\n  if (co == L) s = \"running\";\n  else if (co->status == LUA_YIELD) s = \"suspended\";\n  else if (co->status != LUA_OK) s = \"dead\";\n  else if (co->base > tvref(co->stack)+1+LJ_FR2) s = \"normal\";\n  else if (co->top == co->base) s = \"dead\";\n  else s = \"suspended\";\n  lua_pushstring(L, s);\n  return 1;\n}\n\nLJLIB_CF(coroutine_running)\n{\n#if LJ_52\n  int ismain = lua_pushthread(L);\n  setboolV(L->top++, ismain);\n  return 2;\n#else\n  if (lua_pushthread(L))\n    setnilV(L->top++);\n  return 1;\n#endif\n}\n\nLJLIB_CF(coroutine_isyieldable)\n{\n  setboolV(L->top++, cframe_canyield(L->cframe));\n  return 1;\n}\n\nLJLIB_CF(coroutine_create)\n{\n  lua_State *L1;\n  if (!(L->base < L->top && tvisfunc(L->base)))\n    lj_err_argt(L, 1, LUA_TFUNCTION);\n  L1 = lua_newthread(L);\n  setfuncV(L, L1->top++, funcV(L->base));\n  return 1;\n}\n\nLJLIB_ASM(coroutine_yield)\n{\n  lj_err_caller(L, LJ_ERR_CYIELD);\n  return FFH_UNREACHABLE;\n}\n\nstatic int ffh_resume(lua_State *L, lua_State *co, int wrap)\n{\n  if (co->cframe != NULL || co->status > LUA_YIELD ||\n      (co->status == LUA_OK && co->top == co->base)) {\n    ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD;\n    if (wrap) lj_err_caller(L, em);\n    setboolV(L->base-1-LJ_FR2, 0);\n    setstrV(L, L->base-LJ_FR2, lj_err_str(L, em));\n    return FFH_RES(2);\n  }\n  lj_state_growstack(co, (MSize)(L->top - L->base));\n  return FFH_RETRY;\n}\n\nLJLIB_ASM(coroutine_resume)\n{\n  if (!(L->top > L->base && tvisthread(L->base)))\n    lj_err_arg(L, 1, LJ_ERR_NOCORO);\n  return ffh_resume(L, threadV(L->base), 0);\n}\n\nLJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)\n{\n  return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1);\n}\n\n/* Inline declarations. */\nLJ_ASMF void lj_ff_coroutine_wrap_aux(void);\n#if !(LJ_TARGET_MIPS && defined(ljamalg_c))\nLJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,\n\t\t\t\t\t\t\t  lua_State *co);\n#endif\n\n/* Error handler, called from assembler VM. */\nvoid LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)\n{\n  co->top--; copyTV(L, L->top, co->top); L->top++;\n  if (tvisstr(L->top-1))\n    lj_err_callermsg(L, strVdata(L->top-1));\n  else\n    lj_err_run(L);\n}\n\n/* Forward declaration. */\nstatic void setpc_wrap_aux(lua_State *L, GCfunc *fn);\n\nLJLIB_CF(coroutine_wrap)\n{\n  GCfunc *fn;\n  lj_cf_coroutine_create(L);\n  fn = lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1);\n  setpc_wrap_aux(L, fn);\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\n/* Fix the PC of wrap_aux. Really ugly workaround. */\nstatic void setpc_wrap_aux(lua_State *L, GCfunc *fn)\n{\n  setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]);\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void newproxy_weaktable(lua_State *L)\n{\n  /* NOBARRIER: The table is new (marked white). */\n  GCtab *t = lj_tab_new(L, 0, 1);\n  settabV(L, L->top++, t);\n  setgcref(t->metatable, obj2gco(t));\n  setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"__mode\")),\n\t    lj_str_newlit(L, \"kv\"));\n  t->nomm = (uint8_t)(~(1u<<MM_mode));\n}\n\nLUALIB_API int luaopen_base(lua_State *L)\n{\n  /* NOBARRIER: Table and value are the same. */\n  GCtab *env = tabref(L->env);\n  settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, \"_G\")), env);\n  lua_pushliteral(L, LUA_VERSION);  /* top-3. */\n  newproxy_weaktable(L);  /* top-2. */\n  LJ_LIB_REG(L, \"_G\", base);\n  LJ_LIB_REG(L, LUA_COLIBNAME, coroutine);\n  return 2;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_bit.c",
    "content": "/*\n** Bit manipulation library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_bit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_bit\n\n#if LJ_HASFFI\nstatic int bit_result64(lua_State *L, CTypeID id, uint64_t x)\n{\n  GCcdata *cd = lj_cdata_new_(L, id, 8);\n  *(uint64_t *)cdataptr(cd) = x;\n  setcdataV(L, L->base-1-LJ_FR2, cd);\n  return FFH_RES(1);\n}\n#else\nstatic int32_t bit_checkbit(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else {\n    int32_t i = lj_num2bit(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return i;\n  }\n}\n#endif\n\nLJLIB_ASM(bit_tobit)\t\tLJLIB_REC(bit_tobit)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  setintV(L->base-1-LJ_FR2, (int32_t)lj_carith_check64(L, 1, &id));\n  return FFH_RES(1);\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_bnot)\t\tLJLIB_REC(bit_unary IR_BNOT)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  return id ? bit_result64(L, id, ~x) : FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_bswap)\t\tLJLIB_REC(bit_unary IR_BSWAP)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  return id ? bit_result64(L, id, lj_bswap64(x)) : FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n#endif\n}\n\nLJLIB_ASM(bit_lshift)\t\tLJLIB_REC(bit_shift IR_BSHL)\n{\n#if LJ_HASFFI\n  CTypeID id = 0, id2 = 0;\n  uint64_t x = lj_carith_check64(L, 1, &id);\n  int32_t sh = (int32_t)lj_carith_check64(L, 2, &id2);\n  if (id) {\n    x = lj_carith_shift64(x, sh, curr_func(L)->c.ffid - (int)FF_bit_lshift);\n    return bit_result64(L, id, x);\n  }\n  if (id2) setintV(L->base+1, sh);\n  return FFH_RETRY;\n#else\n  lj_lib_checknumber(L, 1);\n  bit_checkbit(L, 2);\n  return FFH_RETRY;\n#endif\n}\nLJLIB_ASM_(bit_rshift)\t\tLJLIB_REC(bit_shift IR_BSHR)\nLJLIB_ASM_(bit_arshift)\t\tLJLIB_REC(bit_shift IR_BSAR)\nLJLIB_ASM_(bit_rol)\t\tLJLIB_REC(bit_shift IR_BROL)\nLJLIB_ASM_(bit_ror)\t\tLJLIB_REC(bit_shift IR_BROR)\n\nLJLIB_ASM(bit_band)\t\tLJLIB_REC(bit_nary IR_BAND)\n{\n#if LJ_HASFFI\n  CTypeID id = 0;\n  TValue *o = L->base, *top = L->top;\n  int i = 0;\n  do { lj_carith_check64(L, ++i, &id); } while (++o < top);\n  if (id) {\n    CTState *cts = ctype_cts(L);\n    CType *ct = ctype_get(cts, id);\n    int op = curr_func(L)->c.ffid - (int)FF_bit_bor;\n    uint64_t x, y = op >= 0 ? 0 : ~(uint64_t)0;\n    o = L->base;\n    do {\n      lj_cconv_ct_tv(cts, ct, (uint8_t *)&x, o, 0);\n      if (op < 0) y &= x; else if (op == 0) y |= x; else y ^= x;\n    } while (++o < top);\n    return bit_result64(L, id, y);\n  }\n  return FFH_RETRY;\n#else\n  int i = 0;\n  do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);\n  return FFH_RETRY;\n#endif\n}\nLJLIB_ASM_(bit_bor)\t\tLJLIB_REC(bit_nary IR_BOR)\nLJLIB_ASM_(bit_bxor)\t\tLJLIB_REC(bit_nary IR_BXOR)\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(bit_tohex)\t\tLJLIB_REC(.)\n{\n#if LJ_HASFFI\n  CTypeID id = 0, id2 = 0;\n  uint64_t b = lj_carith_check64(L, 1, &id);\n  int32_t n = L->base+1>=L->top ? (id ? 16 : 8) :\n\t\t\t\t  (int32_t)lj_carith_check64(L, 2, &id2);\n#else\n  uint32_t b = (uint32_t)bit_checkbit(L, 1);\n  int32_t n = L->base+1>=L->top ? 8 : bit_checkbit(L, 2);\n#endif\n  SBuf *sb = lj_buf_tmp_(L);\n  SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);\n  if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }\n  sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);\n#if LJ_HASFFI\n  if (n < 16) b &= ((uint64_t)1 << 4*n)-1;\n#else\n  if (n < 8) b &= (1u << 4*n)-1;\n#endif\n  sb = lj_strfmt_putfxint(sb, sf, b);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_bit(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_BITLIBNAME, bit);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_buffer.c",
    "content": "/*\n** Buffer library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_buffer_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n\n#if LJ_HASBUFFER\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_udata.h\"\n#include \"lj_meta.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#endif\n#include \"lj_strfmt.h\"\n#include \"lj_serialize.h\"\n#include \"lj_lib.h\"\n\n/* -- Helper functions ---------------------------------------------------- */\n\n/* Check that the first argument is a string buffer. */\nstatic SBufExt *buffer_tobuf(lua_State *L)\n{\n  if (!(L->base < L->top && tvisbuf(L->base)))\n    lj_err_argtype(L, 1, \"buffer\");\n  return bufV(L->base);\n}\n\n/* Ditto, but for writers. */\nstatic LJ_AINLINE SBufExt *buffer_tobufw(lua_State *L)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  setsbufXL_(sbx, L);\n  return sbx;\n}\n\n#define buffer_toudata(sbx)\t((GCudata *)(sbx)-1)\n\n/* -- Buffer methods ------------------------------------------------------ */\n\n#define LJLIB_MODULE_buffer_method\n\nLJLIB_CF(buffer_method_free)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  lj_bufx_free(L, sbx);\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_reset)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  lj_bufx_reset(sbx);\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_skip)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  MSize n = (MSize)lj_lib_checkintrange(L, 2, 0, LJ_MAX_BUF);\n  MSize len = sbufxlen(sbx);\n  if (n < len) {\n    sbx->r += n;\n  } else {\n    sbx->r = sbx->w = sbx->b;\n  }\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_set)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  GCobj *ref;\n  const char *p;\n  MSize len;\n#if LJ_HASFFI\n  if (tviscdata(L->base+1)) {\n    CTState *cts = ctype_cts(L);\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p,\n\t\t   L->base+1, CCF_ARG(2));\n    len = (MSize)lj_lib_checkintrange(L, 3, 0, LJ_MAX_BUF);\n  } else\n#endif\n  {\n    GCstr *str = lj_lib_checkstrx(L, 2);\n    p = strdata(str);\n    len = str->len;\n  }\n  lj_bufx_free(L, sbx);\n  lj_bufx_set_cow(L, sbx, p, len);\n  ref = gcV(L->base+1);\n  setgcref(sbx->cowref, ref);\n  lj_gc_objbarrier(L, buffer_toudata(sbx), ref);\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_put)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  ptrdiff_t arg, narg = L->top - L->base;\n  for (arg = 1; arg < narg; arg++) {\n    cTValue *o = &L->base[arg], *mo = NULL;\n  retry:\n    if (tvisstr(o)) {\n      lj_buf_putstr((SBuf *)sbx, strV(o));\n    } else if (tvisint(o)) {\n      lj_strfmt_putint((SBuf *)sbx, intV(o));\n    } else if (tvisnum(o)) {\n      lj_strfmt_putfnum((SBuf *)sbx, STRFMT_G14, numV(o));\n    } else if (tvisbuf(o)) {\n      SBufExt *sbx2 = bufV(o);\n      if (sbx2 == sbx) lj_err_arg(L, arg+1, LJ_ERR_BUFFER_SELF);\n      lj_buf_putmem((SBuf *)sbx, sbx2->r, sbufxlen(sbx2));\n    } else if (!mo && !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {\n      /* Call __tostring metamethod inline. */\n      copyTV(L, L->top++, mo);\n      copyTV(L, L->top++, o);\n      lua_call(L, 1, 1);\n      o = &L->base[arg];  /* The stack may have been reallocated. */\n      copyTV(L, &L->base[arg], L->top-1);\n      L->top = L->base + narg;\n      goto retry;  /* Retry with the result. */\n    } else {\n      lj_err_argtype(L, arg+1, \"string/number/__tostring\");\n    }\n    /* Probably not useful to inline other __tostring MMs, e.g. FFI numbers. */\n  }\n  L->top = L->base+1;  /* Chain buffer object. */\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(buffer_method_putf)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  lj_strfmt_putarg(L, (SBuf *)sbx, 2, 2);\n  L->top = L->base+1;  /* Chain buffer object. */\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(buffer_method_get)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  ptrdiff_t arg, narg = L->top - L->base;\n  if (narg == 1) {\n    narg++;\n    setnilV(L->top++);  /* get() is the same as get(nil). */\n  }\n  for (arg = 1; arg < narg; arg++) {\n    TValue *o = &L->base[arg];\n    MSize n = tvisnil(o) ? LJ_MAX_BUF :\n\t      (MSize) lj_lib_checkintrange(L, arg+1, 0, LJ_MAX_BUF);\n    MSize len = sbufxlen(sbx);\n    if (n > len) n = len;\n    setstrV(L, o, lj_str_new(L, sbx->r, n));\n    sbx->r += n;\n  }\n  if (sbx->r == sbx->w) sbx->r = sbx->w = sbx->b;\n  lj_gc_check(L);\n  return narg-1;\n}\n\n#if LJ_HASFFI\nLJLIB_CF(buffer_method_putcdata)\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  const char *p;\n  MSize len;\n  if (tviscdata(L->base+1)) {\n    CTState *cts = ctype_cts(L);\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p,\n\t\t   L->base+1, CCF_ARG(2));\n  } else {\n    lj_err_argtype(L, 2, \"cdata\");\n  }\n  len = (MSize)lj_lib_checkintrange(L, 3, 0, LJ_MAX_BUF);\n  lj_buf_putmem((SBuf *)sbx, p, len);\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_reserve)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  MSize sz = (MSize)lj_lib_checkintrange(L, 2, 0, LJ_MAX_BUF);\n  GCcdata *cd;\n  lj_buf_more((SBuf *)sbx, sz);\n  ctype_loadffi(L);\n  cd = lj_cdata_new_(L, CTID_P_UINT8, CTSIZE_PTR);\n  *(void **)cdataptr(cd) = sbx->w;\n  setcdataV(L, L->top++, cd);\n  setintV(L->top++, sbufleft(sbx));\n  return 2;\n}\n\nLJLIB_CF(buffer_method_commit)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  MSize len = (MSize)lj_lib_checkintrange(L, 2, 0, LJ_MAX_BUF);\n  if (len > sbufleft(sbx)) lj_err_arg(L, 2, LJ_ERR_NUMRNG);\n  sbx->w += len;\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_ref)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  GCcdata *cd;\n  ctype_loadffi(L);\n  cd = lj_cdata_new_(L, CTID_P_UINT8, CTSIZE_PTR);\n  *(void **)cdataptr(cd) = sbx->r;\n  setcdataV(L, L->top++, cd);\n  setintV(L->top++, sbufxlen(sbx));\n  return 2;\n}\n#endif\n\nLJLIB_CF(buffer_method_encode)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  cTValue *o = lj_lib_checkany(L, 2);\n  lj_serialize_put(sbx, o);\n  lj_gc_check(L);\n  L->top = L->base+1;  /* Chain buffer object. */\n  return 1;\n}\n\nLJLIB_CF(buffer_method_decode)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobufw(L);\n  setnilV(L->top++);\n  sbx->r = lj_serialize_get(sbx, L->top-1);\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(buffer_method___gc)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  lj_bufx_free(L, sbx);\n  return 0;\n}\n\nLJLIB_CF(buffer_method___tostring)\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  setstrV(L, L->top-1, lj_str_new(L, sbx->r, sbufxlen(sbx)));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(buffer_method___len)\t\tLJLIB_REC(.)\n{\n  SBufExt *sbx = buffer_tobuf(L);\n  setintV(L->top-1, (int32_t)sbufxlen(sbx));\n  return 1;\n}\n\nLJLIB_PUSH(\"buffer\") LJLIB_SET(__metatable)\nLJLIB_PUSH(top-1) LJLIB_SET(__index)\n\n/* -- Buffer library functions -------------------------------------------- */\n\n#define LJLIB_MODULE_buffer\n\nLJLIB_PUSH(top-2) LJLIB_SET(!)  /* Set environment. */\n\nLJLIB_CF(buffer_new)\n{\n  MSize sz = 0;\n  int targ = 1;\n  GCtab *env, *dict_str = NULL, *dict_mt = NULL;\n  GCudata *ud;\n  SBufExt *sbx;\n  if (L->base < L->top && !tvistab(L->base)) {\n    targ = 2;\n    if (!tvisnil(L->base))\n      sz = (MSize)lj_lib_checkintrange(L, 1, 0, LJ_MAX_BUF);\n  }\n  if (L->base+targ-1 < L->top) {\n    GCtab *options = lj_lib_checktab(L, targ);\n    cTValue *opt_dict, *opt_mt;\n    opt_dict = lj_tab_getstr(options, lj_str_newlit(L, \"dict\"));\n    if (opt_dict && tvistab(opt_dict)) {\n      dict_str = tabV(opt_dict);\n      lj_serialize_dict_prep_str(L, dict_str);\n    }\n    opt_mt = lj_tab_getstr(options, lj_str_newlit(L, \"metatable\"));\n    if (opt_mt && tvistab(opt_mt)) {\n      dict_mt = tabV(opt_mt);\n      lj_serialize_dict_prep_mt(L, dict_mt);\n    }\n  }\n  env = tabref(curr_func(L)->c.env);\n  ud = lj_udata_new(L, sizeof(SBufExt), env);\n  ud->udtype = UDTYPE_BUFFER;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcref(ud->metatable, obj2gco(env));\n  setudataV(L, L->top++, ud);\n  sbx = (SBufExt *)uddata(ud);\n  lj_bufx_init(L, sbx);\n  setgcref(sbx->dict_str, obj2gco(dict_str));\n  setgcref(sbx->dict_mt, obj2gco(dict_mt));\n  if (sz > 0) lj_buf_need2((SBuf *)sbx, sz);\n  return 1;\n}\n\nLJLIB_CF(buffer_encode)\t\t\tLJLIB_REC(.)\n{\n  cTValue *o = lj_lib_checkany(L, 1);\n  setstrV(L, L->top++, lj_serialize_encode(L, o));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(buffer_decode)\t\t\tLJLIB_REC(.)\n{\n  GCstr *str = lj_lib_checkstrx(L, 1);\n  setnilV(L->top++);\n  lj_serialize_decode(L, L->top-1, str);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nint luaopen_string_buffer(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, buffer_method);\n  lua_getfield(L, -1, \"__tostring\");\n  lua_setfield(L, -2, \"tostring\");\n  LJ_LIB_REG(L, NULL, buffer);\n  return 1;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_debug.c",
    "content": "/*\n** Debug library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_debug_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_debug\n\nLJLIB_CF(debug_getregistry)\n{\n  copyTV(L, L->top++, registry(L));\n  return 1;\n}\n\nLJLIB_CF(debug_getmetatable)\tLJLIB_REC(.)\n{\n  lj_lib_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    setnilV(L->top-1);\n  }\n  return 1;\n}\n\nLJLIB_CF(debug_setmetatable)\n{\n  lj_lib_checktabornil(L, 2);\n  L->top = L->base+2;\n  lua_setmetatable(L, 1);\n#if !LJ_52\n  setboolV(L->top-1, 1);\n#endif\n  return 1;\n}\n\nLJLIB_CF(debug_getfenv)\n{\n  lj_lib_checkany(L, 1);\n  lua_getfenv(L, 1);\n  return 1;\n}\n\nLJLIB_CF(debug_setfenv)\n{\n  lj_lib_checktab(L, 2);\n  L->top = L->base+2;\n  if (!lua_setfenv(L, 1))\n    lj_err_caller(L, LJ_ERR_SETFENV);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void settabss(lua_State *L, const char *i, const char *v)\n{\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic void settabsi(lua_State *L, const char *i, int v)\n{\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic void settabsb(lua_State *L, const char *i, int v)\n{\n  lua_pushboolean(L, v);\n  lua_setfield(L, -2, i);\n}\n\nstatic lua_State *getthread(lua_State *L, int *arg)\n{\n  if (L->base < L->top && tvisthread(L->base)) {\n    *arg = 1;\n    return threadV(L->base);\n  } else {\n    *arg = 0;\n    return L;\n  }\n}\n\nstatic void treatstackoption(lua_State *L, lua_State *L1, const char *fname)\n{\n  if (L == L1) {\n    lua_pushvalue(L, -2);\n    lua_remove(L, -3);\n  }\n  else\n    lua_xmove(L1, L, 1);\n  lua_setfield(L, -2, fname);\n}\n\nLJLIB_CF(debug_getinfo)\n{\n  lj_Debug ar;\n  int arg, opt_f = 0, opt_L = 0;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnSu\");\n  if (lua_isnumber(L, arg+1)) {\n    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) {\n      setnilV(L->top-1);\n      return 1;\n    }\n  } else if (L->base+arg < L->top && tvisfunc(L->base+arg)) {\n    options = lua_pushfstring(L, \">%s\", options);\n    setfuncV(L1, L1->top++, funcV(L->base+arg));\n  } else {\n    lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL);\n  }\n  if (!lj_debug_getinfo(L1, options, &ar, 1))\n    lj_err_arg(L, arg+2, LJ_ERR_INVOPT);\n  lua_createtable(L, 0, 16);  /* Create result table. */\n  for (; *options; options++) {\n    switch (*options) {\n    case 'S':\n      settabss(L, \"source\", ar.source);\n      settabss(L, \"short_src\", ar.short_src);\n      settabsi(L, \"linedefined\", ar.linedefined);\n      settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n      settabss(L, \"what\", ar.what);\n      break;\n    case 'l':\n      settabsi(L, \"currentline\", ar.currentline);\n      break;\n    case 'u':\n      settabsi(L, \"nups\", ar.nups);\n      settabsi(L, \"nparams\", ar.nparams);\n      settabsb(L, \"isvararg\", ar.isvararg);\n      break;\n    case 'n':\n      settabss(L, \"name\", ar.name);\n      settabss(L, \"namewhat\", ar.namewhat);\n      break;\n    case 'f': opt_f = 1; break;\n    case 'L': opt_L = 1; break;\n    default: break;\n    }\n  }\n  if (opt_L) treatstackoption(L, L1, \"activelines\");\n  if (opt_f) treatstackoption(L, L1, \"func\");\n  return 1;  /* Return result table. */\n}\n\nLJLIB_CF(debug_getlocal)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  int slot = lj_lib_checkint(L, arg+2);\n  if (tvisfunc(L->base+arg)) {\n    L->top = L->base+arg+1;\n    lua_pushstring(L, lua_getlocal(L, NULL, slot));\n    return 1;\n  }\n  if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))\n    lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);\n  name = lua_getlocal(L1, &ar, slot);\n  if (name) {\n    lua_xmove(L1, L, 1);\n    lua_pushstring(L, name);\n    lua_pushvalue(L, -2);\n    return 2;\n  } else {\n    setnilV(L->top-1);\n    return 1;\n  }\n}\n\nLJLIB_CF(debug_setlocal)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  TValue *tv;\n  if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))\n    lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);\n  tv = lj_lib_checkany(L, arg+3);\n  copyTV(L1, L1->top++, tv);\n  lua_pushstring(L, lua_setlocal(L1, &ar, lj_lib_checkint(L, arg+2)));\n  return 1;\n}\n\nstatic int debug_getupvalue(lua_State *L, int get)\n{\n  int32_t n = lj_lib_checkint(L, 2);\n  const char *name;\n  lj_lib_checkfunc(L, 1);\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name) {\n    lua_pushstring(L, name);\n    if (!get) return 1;\n    copyTV(L, L->top, L->top-2);\n    L->top++;\n    return 2;\n  }\n  return 0;\n}\n\nLJLIB_CF(debug_getupvalue)\n{\n  return debug_getupvalue(L, 1);\n}\n\nLJLIB_CF(debug_setupvalue)\n{\n  lj_lib_checkany(L, 3);\n  return debug_getupvalue(L, 0);\n}\n\nLJLIB_CF(debug_upvalueid)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  int32_t n = lj_lib_checkint(L, 2) - 1;\n  if ((uint32_t)n >= fn->l.nupvalues)\n    lj_err_arg(L, 2, LJ_ERR_IDXRNG);\n  lua_pushlightuserdata(L, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :\n\t\t\t\t\t   (void *)&fn->c.upvalue[n]);\n  return 1;\n}\n\nLJLIB_CF(debug_upvaluejoin)\n{\n  GCfunc *fn[2];\n  GCRef *p[2];\n  int i;\n  for (i = 0; i < 2; i++) {\n    int32_t n;\n    fn[i] = lj_lib_checkfunc(L, 2*i+1);\n    if (!isluafunc(fn[i]))\n      lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC);\n    n = lj_lib_checkint(L, 2*i+2) - 1;\n    if ((uint32_t)n >= fn[i]->l.nupvalues)\n      lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG);\n    p[i] = &fn[i]->l.uvptr[n];\n  }\n  setgcrefr(*p[0], *p[1]);\n  lj_gc_objbarrier(L, fn[0], gcref(*p[1]));\n  return 0;\n}\n\n#if LJ_52\nLJLIB_CF(debug_getuservalue)\n{\n  TValue *o = L->base;\n  if (o < L->top && tvisudata(o))\n    settabV(L, o, tabref(udataV(o)->env));\n  else\n    setnilV(o);\n  L->top = o+1;\n  return 1;\n}\n\nLJLIB_CF(debug_setuservalue)\n{\n  TValue *o = L->base;\n  if (!(o < L->top && tvisudata(o)))\n    lj_err_argt(L, 1, LUA_TUSERDATA);\n  if (!(o+1 < L->top && tvistab(o+1)))\n    lj_err_argt(L, 2, LUA_TTABLE);\n  L->top = o+2;\n  lua_setfenv(L, 1);\n  return 1;\n}\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n#define KEY_HOOK\t(U64x(80000000,00000000)|'h')\n\nstatic void hookf(lua_State *L, lua_Debug *ar)\n{\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\n  (L->top++)->u64 = KEY_HOOK;\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  if (lua_isfunction(L, -1)) {\n    lua_pushstring(L, hooknames[(int)ar->event]);\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);\n    else lua_pushnil(L);\n    lua_call(L, 2, 0);\n  }\n}\n\nstatic int makemask(const char *smask, int count)\n{\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\nstatic char *unmakemask(int mask, char *smask)\n{\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\nLJLIB_CF(debug_sethook)\n{\n  int arg, mask, count;\n  lua_Hook func;\n  (void)getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  } else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = luaL_optint(L, arg+3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  (L->top++)->u64 = KEY_HOOK;\n  lua_pushvalue(L, arg+1);\n  lua_rawset(L, LUA_REGISTRYINDEX);\n  lua_sethook(L, func, mask, count);\n  return 0;\n}\n\nLJLIB_CF(debug_gethook)\n{\n  char buff[5];\n  int mask = lua_gethookmask(L);\n  lua_Hook hook = lua_gethook(L);\n  if (hook != NULL && hook != hookf) {  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  } else {\n    (L->top++)->u64 = KEY_HOOK;\n    lua_rawget(L, LUA_REGISTRYINDEX);   /* get hook */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));\n  lua_pushinteger(L, lua_gethookcount(L));\n  return 3;\n}\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(debug_debug)\n{\n  for (;;) {\n    char buffer[250];\n    fputs(\"lua_debug> \", stderr);\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n\tstrcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n\tlua_pcall(L, 0, 0, 0)) {\n      const char *s = lua_tostring(L, -1);\n      fputs(s ? s : \"(error object is not a string)\", stderr);\n      fputs(\"\\n\", stderr);\n    }\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n/* ------------------------------------------------------------------------ */\n\n#define LEVELS1\t12\t/* size of the first part of the stack */\n#define LEVELS2\t10\t/* size of the second part of the stack */\n\nLJLIB_CF(debug_traceback)\n{\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *msg = lua_tostring(L, arg+1);\n  if (msg == NULL && L->top > L->base+arg)\n    L->top = L->base+arg+1;\n  else\n    luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1)));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_debug(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_DBLIBNAME, debug);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_ffi.c",
    "content": "/*\n** FFI library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_ffi_c\n#define LUA_LIB\n\n#include <errno.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cparse.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_clib.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* -- C type checks ------------------------------------------------------- */\n\n/* Check first argument for a C type and returns its ID. */\nstatic CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param)\n{\n  TValue *o = L->base;\n  if (!(o < L->top)) {\n  err_argtype:\n    lj_err_argtype(L, 1, \"C type\");\n  }\n  if (tvisstr(o)) {  /* Parse an abstract C type declaration. */\n    GCstr *s = strV(o);\n    CPState cp;\n    int errcode;\n    cp.L = L;\n    cp.cts = cts;\n    cp.srcname = strdata(s);\n    cp.p = strdata(s);\n    cp.param = param;\n    cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;\n    errcode = lj_cparse(&cp);\n    if (errcode) lj_err_throw(L, errcode);  /* Propagate errors. */\n    return cp.val.id;\n  } else {\n    GCcdata *cd;\n    if (!tviscdata(o)) goto err_argtype;\n    if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM);\n    cd = cdataV(o);\n    return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid;\n  }\n}\n\n/* Check argument for C data and return it. */\nstatic GCcdata *ffi_checkcdata(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tviscdata(o)))\n    lj_err_argt(L, narg, LUA_TCDATA);\n  return cdataV(o);\n}\n\n/* Convert argument to C pointer. */\nstatic void *ffi_checkptr(lua_State *L, int narg, CTypeID id)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = L->base + narg-1;\n  void *p;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg));\n  return p;\n}\n\n/* Convert argument to int32_t. */\nstatic int32_t ffi_checkint(lua_State *L, int narg)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = L->base + narg-1;\n  int32_t i;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o,\n\t\t CCF_ARG(narg));\n  return i;\n}\n\n/* -- C type metamethods -------------------------------------------------- */\n\n#define LJLIB_MODULE_ffi_meta\n\n/* Handle ctype __index/__newindex metamethods. */\nstatic int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  cTValue *tv = lj_ctype_meta(cts, id, mm);\n  TValue *base = L->base;\n  if (!tv) {\n    const char *s;\n  err_index:\n    s = strdata(lj_ctype_repr(L, id, NULL));\n    if (tvisstr(L->base+1)) {\n      lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1));\n    } else {\n      const char *key = tviscdata(L->base+1) ?\n\tstrdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) :\n\tlj_typename(L->base+1);\n      lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key);\n    }\n  }\n  if (!tvisfunc(tv)) {\n    if (mm == MM_index) {\n      cTValue *o = lj_meta_tget(L, tv, base+1);\n      if (o) {\n\tif (tvisnil(o)) goto err_index;\n\tcopyTV(L, L->top-1, o);\n\treturn 1;\n      }\n    } else {\n      TValue *o = lj_meta_tset(L, tv, base+1);\n      if (o) {\n\tcopyTV(L, o, base+2);\n\treturn 0;\n      }\n    }\n    copyTV(L, base, L->top);\n    tv = L->top-1-LJ_FR2;\n  }\n  return lj_meta_tailcall(L, tv);\n}\n\nLJLIB_CF(ffi_meta___index)\tLJLIB_REC(cdata_index 0)\n{\n  CTState *cts = ctype_cts(L);\n  CTInfo qual = 0;\n  CType *ct;\n  uint8_t *p;\n  TValue *o = L->base;\n  if (!(o+1 < L->top && tviscdata(o)))  /* Also checks for presence of key. */\n    lj_err_argt(L, 1, LUA_TCDATA);\n  ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);\n  if ((qual & 1))\n    return ffi_index_meta(L, cts, ct, MM_index);\n  if (lj_cdata_get(cts, ct, L->top-1, p))\n    lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_meta___newindex)\tLJLIB_REC(cdata_index 1)\n{\n  CTState *cts = ctype_cts(L);\n  CTInfo qual = 0;\n  CType *ct;\n  uint8_t *p;\n  TValue *o = L->base;\n  if (!(o+2 < L->top && tviscdata(o)))  /* Also checks for key and value. */\n    lj_err_argt(L, 1, LUA_TCDATA);\n  ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);\n  if ((qual & 1)) {\n    if ((qual & CTF_CONST))\n      lj_err_caller(L, LJ_ERR_FFI_WRCONST);\n    return ffi_index_meta(L, cts, ct, MM_newindex);\n  }\n  lj_cdata_set(cts, ct, p, o+2, qual);\n  return 0;\n}\n\n/* Common handler for cdata arithmetic. */\nstatic int ffi_arith(lua_State *L)\n{\n  MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq);\n  return lj_carith_op(L, mm);\n}\n\n/* The following functions must be in contiguous ORDER MM. */\nLJLIB_CF(ffi_meta___eq)\t\tLJLIB_REC(cdata_arith MM_eq)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___len)\tLJLIB_REC(cdata_arith MM_len)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___lt)\t\tLJLIB_REC(cdata_arith MM_lt)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___le)\t\tLJLIB_REC(cdata_arith MM_le)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___concat)\tLJLIB_REC(cdata_arith MM_concat)\n{\n  return ffi_arith(L);\n}\n\n/* Forward declaration. */\nstatic int lj_cf_ffi_new(lua_State *L);\n\nLJLIB_CF(ffi_meta___call)\tLJLIB_REC(cdata_call)\n{\n  CTState *cts = ctype_cts(L);\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  CTypeID id = cd->ctypeid;\n  CType *ct;\n  cTValue *tv;\n  MMS mm = MM_call;\n  if (cd->ctypeid == CTID_CTYPEID) {\n    id = *(CTypeID *)cdataptr(cd);\n    mm = MM_new;\n  } else {\n    int ret = lj_ccall_func(L, cd);\n    if (ret >= 0)\n      return ret;\n  }\n  /* Handle ctype __call/__new metamethod. */\n  ct = ctype_raw(cts, id);\n  if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n  tv = lj_ctype_meta(cts, id, mm);\n  if (tv)\n    return lj_meta_tailcall(L, tv);\n  else if (mm == MM_call)\n    lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL)));\n  return lj_cf_ffi_new(L);\n}\n\nLJLIB_CF(ffi_meta___add)\tLJLIB_REC(cdata_arith MM_add)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___sub)\tLJLIB_REC(cdata_arith MM_sub)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___mul)\tLJLIB_REC(cdata_arith MM_mul)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___div)\tLJLIB_REC(cdata_arith MM_div)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___mod)\tLJLIB_REC(cdata_arith MM_mod)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___pow)\tLJLIB_REC(cdata_arith MM_pow)\n{\n  return ffi_arith(L);\n}\n\nLJLIB_CF(ffi_meta___unm)\tLJLIB_REC(cdata_arith MM_unm)\n{\n  return ffi_arith(L);\n}\n/* End of contiguous ORDER MM. */\n\nLJLIB_CF(ffi_meta___tostring)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  const char *msg = \"cdata<%s>: %p\";\n  CTypeID id = cd->ctypeid;\n  void *p = cdataptr(cd);\n  if (id == CTID_CTYPEID) {\n    msg = \"ctype<%s>\";\n    id = *(CTypeID *)p;\n  } else {\n    CTState *cts = ctype_cts(L);\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isref(ct->info)) {\n      p = *(void **)p;\n      ct = ctype_rawchild(cts, ct);\n    }\n    if (ctype_iscomplex(ct->info)) {\n      setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size));\n      goto checkgc;\n    } else if (ct->size == 8 && ctype_isinteger(ct->info)) {\n      setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd),\n\t\t\t\t\t       (ct->info & CTF_UNSIGNED)));\n      goto checkgc;\n    } else if (ctype_isfunc(ct->info)) {\n      p = *(void **)p;\n    } else if (ctype_isenum(ct->info)) {\n      msg = \"cdata<%s>: %d\";\n      p = (void *)(uintptr_t)*(uint32_t **)p;\n    } else {\n      if (ctype_isptr(ct->info)) {\n\tp = cdata_getptr(p, ct->size);\n\tct = ctype_rawchild(cts, ct);\n      }\n      if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) {\n\t/* Handle ctype __tostring metamethod. */\n\tcTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring);\n\tif (tv)\n\t  return lj_meta_tailcall(L, tv);\n      }\n    }\n  }\n  lj_strfmt_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);\ncheckgc:\n  lj_gc_check(L);\n  return 1;\n}\n\nstatic int ffi_pairs(lua_State *L, MMS mm)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkcdata(L, 1)->ctypeid;\n  CType *ct = ctype_raw(cts, id);\n  cTValue *tv;\n  if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n  tv = lj_ctype_meta(cts, id, mm);\n  if (!tv)\n    lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)),\n\t\t   strdata(mmname_str(G(L), mm)));\n  return lj_meta_tailcall(L, tv);\n}\n\nLJLIB_CF(ffi_meta___pairs)\n{\n  return ffi_pairs(L, MM_pairs);\n}\n\nLJLIB_CF(ffi_meta___ipairs)\n{\n  return ffi_pairs(L, MM_ipairs);\n}\n\nLJLIB_PUSH(\"ffi\") LJLIB_SET(__metatable)\n\n#include \"lj_libdef.h\"\n\n/* -- C library metamethods ----------------------------------------------- */\n\n#define LJLIB_MODULE_ffi_clib\n\n/* Index C library by a name. */\nstatic TValue *ffi_clib_index(lua_State *L)\n{\n  TValue *o = L->base;\n  CLibrary *cl;\n  if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB))\n    lj_err_argt(L, 1, LUA_TUSERDATA);\n  cl = (CLibrary *)uddata(udataV(o));\n  if (!(o+1 < L->top && tvisstr(o+1)))\n    lj_err_argt(L, 2, LUA_TSTRING);\n  return lj_clib_index(L, cl, strV(o+1));\n}\n\nLJLIB_CF(ffi_clib___index)\tLJLIB_REC(clib_index 1)\n{\n  TValue *tv = ffi_clib_index(L);\n  if (tviscdata(tv)) {\n    CTState *cts = ctype_cts(L);\n    GCcdata *cd = cdataV(tv);\n    CType *s = ctype_get(cts, cd->ctypeid);\n    if (ctype_isextern(s->info)) {\n      CTypeID sid = ctype_cid(s->info);\n      void *sp = *(void **)cdataptr(cd);\n      CType *ct = ctype_raw(cts, sid);\n      if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp))\n\tlj_gc_check(L);\n      return 1;\n    }\n  }\n  copyTV(L, L->top-1, tv);\n  return 1;\n}\n\nLJLIB_CF(ffi_clib___newindex)\tLJLIB_REC(clib_index 0)\n{\n  TValue *tv = ffi_clib_index(L);\n  TValue *o = L->base+2;\n  if (o < L->top && tviscdata(tv)) {\n    CTState *cts = ctype_cts(L);\n    GCcdata *cd = cdataV(tv);\n    CType *d = ctype_get(cts, cd->ctypeid);\n    if (ctype_isextern(d->info)) {\n      CTInfo qual = 0;\n      for (;;) {  /* Skip attributes and collect qualifiers. */\n\td = ctype_child(cts, d);\n\tif (!ctype_isattrib(d->info)) break;\n\tif (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;\n      }\n      if (!((d->info|qual) & CTF_CONST)) {\n\tlj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0);\n\treturn 0;\n      }\n    }\n  }\n  lj_err_caller(L, LJ_ERR_FFI_WRCONST);\n  return 0;  /* unreachable */\n}\n\nLJLIB_CF(ffi_clib___gc)\n{\n  TValue *o = L->base;\n  if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)\n    lj_clib_unload((CLibrary *)uddata(udataV(o)));\n  return 0;\n}\n\n#include \"lj_libdef.h\"\n\n/* -- Callback function metamethods --------------------------------------- */\n\n#define LJLIB_MODULE_ffi_callback\n\nstatic int ffi_callback_set(lua_State *L, GCfunc *fn)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) {\n    MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd));\n    if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) {\n      GCtab *t = cts->miscmap;\n      TValue *tv = lj_tab_setint(L, t, (int32_t)slot);\n      if (fn) {\n\tsetfuncV(L, tv, fn);\n\tlj_gc_anybarriert(L, t);\n      } else {\n\tsetnilV(tv);\n\tcts->cb.cbid[slot] = 0;\n\tcts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid;\n      }\n      return 0;\n    }\n  }\n  lj_err_caller(L, LJ_ERR_FFI_BADCBACK);\n  return 0;\n}\n\nLJLIB_CF(ffi_callback_free)\n{\n  return ffi_callback_set(L, NULL);\n}\n\nLJLIB_CF(ffi_callback_set)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 2);\n  return ffi_callback_set(L, fn);\n}\n\nLJLIB_PUSH(top-1) LJLIB_SET(__index)\n\n#include \"lj_libdef.h\"\n\n/* -- FFI library functions ----------------------------------------------- */\n\n#define LJLIB_MODULE_ffi\n\nLJLIB_CF(ffi_cdef)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  CPState cp;\n  int errcode;\n  cp.L = L;\n  cp.cts = ctype_cts(L);\n  cp.srcname = strdata(s);\n  cp.p = strdata(s);\n  cp.param = L->base+1;\n  cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT;\n  errcode = lj_cparse(&cp);\n  if (errcode) lj_err_throw(L, errcode);  /* Propagate errors. */\n  lj_gc_check(L);\n  return 0;\n}\n\nLJLIB_CF(ffi_new)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CType *ct = ctype_raw(cts, id);\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  TValue *o = L->base+1;\n  GCcdata *cd;\n  if ((info & CTF_VLA)) {\n    o++;\n    sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));\n  }\n  if (sz == CTSIZE_INVALID)\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE);\n  cd = lj_cdata_newx(cts, id, sz, info);\n  setcdataV(L, o-1, cd);  /* Anchor the uninitialized cdata. */\n  lj_cconv_ct_init(cts, ct, sz, cdataptr(cd),\n\t\t   o, (MSize)(L->top - o));  /* Initialize cdata. */\n  if (ctype_isstruct(ct->info)) {\n    /* Handle ctype __gc metamethod. Use the fast lookup here. */\n    cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);\n    if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) {\n      GCtab *t = cts->finalizer;\n      if (gcref(t->metatable)) {\n\t/* Add to finalizer table, if still enabled. */\n\tcopyTV(L, lj_tab_set(L, t, o-1), tv);\n\tlj_gc_anybarriert(L, t);\n\tcd->marked |= LJ_GC_CDATA_FIN;\n      }\n    }\n  }\n  L->top = o;  /* Only return the cdata itself. */\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_cast)\tLJLIB_REC(ffi_new)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CType *d = ctype_raw(cts, id);\n  TValue *o = lj_lib_checkany(L, 2);\n  L->top = o+1;  /* Make sure this is the last item on the stack. */\n  if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) {\n    GCcdata *cd = lj_cdata_new(cts, id, d->size);\n    lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST);\n    setcdataV(L, o, cd);\n    lj_gc_check(L);\n  }\n  return 1;\n}\n\nLJLIB_CF(ffi_typeof)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, L->base+1);\n  GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4);\n  *(CTypeID *)cdataptr(cd) = id;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\n/* Internal and unsupported API. */\nLJLIB_CF(ffi_typeinfo)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = (CTypeID)ffi_checkint(L, 1);\n  if (id > 0 && id < cts->top) {\n    CType *ct = ctype_get(cts, id);\n    GCtab *t;\n    lua_createtable(L, 0, 4);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"info\")), (int32_t)ct->info);\n    if (ct->size != CTSIZE_INVALID)\n      setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"size\")), (int32_t)ct->size);\n    if (ct->sib)\n      setintV(lj_tab_setstr(L, t, lj_str_newlit(L, \"sib\")), (int32_t)ct->sib);\n    if (gcref(ct->name)) {\n      GCstr *s = gco2str(gcref(ct->name));\n      if (isdead(G(L), obj2gco(s))) flipwhite(obj2gco(s));\n      setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"name\")), s);\n    }\n    lj_gc_check(L);\n    return 1;\n  }\n  return 0;\n}\n\nLJLIB_CF(ffi_istype)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id1 = ffi_checkctype(L, cts, NULL);\n  TValue *o = lj_lib_checkany(L, 2);\n  int b = 0;\n  if (tviscdata(o)) {\n    GCcdata *cd = cdataV(o);\n    CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) :\n\t\t\t\t\t\tcd->ctypeid;\n    CType *ct1 = lj_ctype_rawref(cts, id1);\n    CType *ct2 = lj_ctype_rawref(cts, id2);\n    if (ct1 == ct2) {\n      b = 1;\n    } else if (ctype_type(ct1->info) == ctype_type(ct2->info) &&\n\t       ct1->size == ct2->size) {\n      if (ctype_ispointer(ct1->info))\n\tb = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL);\n      else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info))\n\tb = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0);\n    } else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) &&\n\t       ct1 == ctype_rawchild(cts, ct2)) {\n      b = 1;\n    }\n  }\n  setboolV(L->top-1, b);\n  setboolV(&G(L)->tmptv2, b);  /* Remember for trace recorder. */\n  return 1;\n}\n\nLJLIB_CF(ffi_sizeof)\tLJLIB_REC(ffi_xof FF_ffi_sizeof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CTSize sz;\n  if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) {\n    sz = cdatavlen(cdataV(L->base));\n  } else {\n    CType *ct = lj_ctype_rawref(cts, id);\n    if (ctype_isvltype(ct->info))\n      sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));\n    else\n      sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;\n    if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) {\n      setnilV(L->top-1);\n      return 1;\n    }\n  }\n  setintV(L->top-1, (int32_t)sz);\n  return 1;\n}\n\nLJLIB_CF(ffi_alignof)\tLJLIB_REC(ffi_xof FF_ffi_alignof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  CTSize sz = 0;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  setintV(L->top-1, 1 << ctype_align(info));\n  return 1;\n}\n\nLJLIB_CF(ffi_offsetof)\tLJLIB_REC(ffi_xof FF_ffi_offsetof)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  GCstr *name = lj_lib_checkstr(L, 2);\n  CType *ct = lj_ctype_rawref(cts, id);\n  CTSize ofs;\n  if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) {\n    CType *fct = lj_ctype_getfield(cts, ct, name, &ofs);\n    if (fct) {\n      setintV(L->top-1, ofs);\n      if (ctype_isfield(fct->info)) {\n\treturn 1;\n      } else if (ctype_isbitfield(fct->info)) {\n\tsetintV(L->top++, ctype_bitpos(fct->info));\n\tsetintV(L->top++, ctype_bitbsz(fct->info));\n\treturn 3;\n      }\n    }\n  }\n  return 0;\n}\n\nLJLIB_CF(ffi_errno)\tLJLIB_REC(.)\n{\n  int err = errno;\n  if (L->top > L->base)\n    errno = ffi_checkint(L, 1);\n  setintV(L->top++, err);\n  return 1;\n}\n\nLJLIB_CF(ffi_string)\tLJLIB_REC(.)\n{\n  CTState *cts = ctype_cts(L);\n  TValue *o = lj_lib_checkany(L, 1);\n  const char *p;\n  size_t len;\n  if (o+1 < L->top && !tvisnil(o+1)) {\n    len = (size_t)ffi_checkint(L, 2);\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o,\n\t\t   CCF_ARG(1));\n  } else {\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o,\n\t\t   CCF_ARG(1));\n    len = strlen(p);\n  }\n  L->top = o+1;  /* Make sure this is the last item on the stack. */\n  setstrV(L, o, lj_str_new(L, p, len));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_CF(ffi_copy)\tLJLIB_REC(.)\n{\n  void *dp = ffi_checkptr(L, 1, CTID_P_VOID);\n  void *sp = ffi_checkptr(L, 2, CTID_P_CVOID);\n  TValue *o = L->base+1;\n  CTSize len;\n  if (tvisstr(o) && o+1 >= L->top)\n    len = strV(o)->len+1;  /* Copy Lua string including trailing '\\0'. */\n  else\n    len = (CTSize)ffi_checkint(L, 3);\n  memcpy(dp, sp, len);\n  return 0;\n}\n\nLJLIB_CF(ffi_fill)\tLJLIB_REC(.)\n{\n  void *dp = ffi_checkptr(L, 1, CTID_P_VOID);\n  CTSize len = (CTSize)ffi_checkint(L, 2);\n  int32_t fill = 0;\n  if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3);\n  memset(dp, fill, len);\n  return 0;\n}\n\n/* Test ABI string. */\nLJLIB_CF(ffi_abi)\tLJLIB_REC(.)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int b = lj_cparse_case(s,\n#if LJ_64\n    \"\\00564bit\"\n#else\n    \"\\00532bit\"\n#endif\n#if LJ_ARCH_HASFPU\n    \"\\003fpu\"\n#endif\n#if LJ_ABI_SOFTFP\n    \"\\006softfp\"\n#else\n    \"\\006hardfp\"\n#endif\n#if LJ_ABI_EABI\n    \"\\004eabi\"\n#endif\n#if LJ_ABI_WIN\n    \"\\003win\"\n#endif\n#if LJ_TARGET_UWP\n    \"\\003uwp\"\n#endif\n#if LJ_LE\n    \"\\002le\"\n#else\n    \"\\002be\"\n#endif\n#if LJ_GC64\n    \"\\004gc64\"\n#endif\n  ) >= 0;\n  setboolV(L->top-1, b);\n  setboolV(&G(L)->tmptv2, b);  /* Remember for trace recorder. */\n  return 1;\n}\n\nLJLIB_PUSH(top-8) LJLIB_SET(!)  /* Store reference to miscmap table. */\n\nLJLIB_CF(ffi_metatype)\n{\n  CTState *cts = ctype_cts(L);\n  CTypeID id = ffi_checkctype(L, cts, NULL);\n  GCtab *mt = lj_lib_checktab(L, 2);\n  GCtab *t = cts->miscmap;\n  CType *ct = ctype_get(cts, id);  /* Only allow raw types. */\n  TValue *tv;\n  GCcdata *cd;\n  if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||\n\tctype_isvector(ct->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  tv = lj_tab_setinth(L, t, -(int32_t)id);\n  if (!tvisnil(tv))\n    lj_err_caller(L, LJ_ERR_PROTMT);\n  settabV(L, tv, mt);\n  lj_gc_anybarriert(L, t);\n  cd = lj_cdata_new(cts, CTID_CTYPEID, 4);\n  *(CTypeID *)cdataptr(cd) = id;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_PUSH(top-7) LJLIB_SET(!)  /* Store reference to finalizer table. */\n\nLJLIB_CF(ffi_gc)\tLJLIB_REC(.)\n{\n  GCcdata *cd = ffi_checkcdata(L, 1);\n  TValue *fin = lj_lib_checkany(L, 2);\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||\n\tctype_isrefarray(ct->info)))\n    lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);\n  lj_cdata_setfin(L, cd, gcval(fin), itype(fin));\n  L->top = L->base+1;  /* Pass through the cdata object. */\n  return 1;\n}\n\nLJLIB_PUSH(top-5) LJLIB_SET(!)  /* Store clib metatable in func environment. */\n\nLJLIB_CF(ffi_load)\n{\n  GCstr *name = lj_lib_checkstr(L, 1);\n  int global = (L->base+1 < L->top && tvistruecond(L->base+1));\n  lj_clib_load(L, tabref(curr_func(L)->c.env), name, global);\n  return 1;\n}\n\nLJLIB_PUSH(top-4) LJLIB_SET(C)\nLJLIB_PUSH(top-3) LJLIB_SET(os)\nLJLIB_PUSH(top-2) LJLIB_SET(arch)\n\n#include \"lj_libdef.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Create special weak-keyed finalizer table. */\nstatic GCtab *ffi_finalizer(lua_State *L)\n{\n  /* NOBARRIER: The table is new (marked white). */\n  GCtab *t = lj_tab_new(L, 0, 1);\n  settabV(L, L->top++, t);\n  setgcref(t->metatable, obj2gco(t));\n  setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"__mode\")),\n\t  lj_str_newlit(L, \"k\"));\n  t->nomm = (uint8_t)(~(1u<<MM_mode));\n  return t;\n}\n\n/* Register FFI module as loaded. */\nstatic void ffi_register_module(lua_State *L)\n{\n  cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, \"_LOADED\"));\n  if (tmp && tvistab(tmp)) {\n    GCtab *t = tabV(tmp);\n    copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1);\n    lj_gc_anybarriert(L, t);\n  }\n}\n\nLUALIB_API int luaopen_ffi(lua_State *L)\n{\n  CTState *cts = lj_ctype_init(L);\n  settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1)));\n  cts->finalizer = ffi_finalizer(L);\n  LJ_LIB_REG(L, NULL, ffi_meta);\n  /* NOBARRIER: basemt is a GC root. */\n  setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1)));\n  LJ_LIB_REG(L, NULL, ffi_clib);\n  LJ_LIB_REG(L, NULL, ffi_callback);\n  /* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */\n  settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1));\n  L->top--;\n  lj_clib_default(L, tabV(L->top-1));  /* Create ffi.C default namespace. */\n  lua_pushliteral(L, LJ_OS_NAME);\n  lua_pushliteral(L, LJ_ARCH_NAME);\n  LJ_LIB_REG(L, NULL, ffi);  /* Note: no global \"ffi\" created! */\n  ffi_register_module(L);\n  return 1;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_init.c",
    "content": "/*\n** Library initialization.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major parts taken verbatim from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_init_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_arch.h\"\n\nstatic const luaL_Reg lj_lib_load[] = {\n  { \"\",\t\t\tluaopen_base },\n  { LUA_LOADLIBNAME,\tluaopen_package },\n  { LUA_TABLIBNAME,\tluaopen_table },\n  { LUA_IOLIBNAME,\tluaopen_io },\n  { LUA_OSLIBNAME,\tluaopen_os },\n  { LUA_STRLIBNAME,\tluaopen_string },\n  { LUA_MATHLIBNAME,\tluaopen_math },\n  { LUA_DBLIBNAME,\tluaopen_debug },\n  { LUA_BITLIBNAME,\tluaopen_bit },\n  { LUA_JITLIBNAME,\tluaopen_jit },\n  { NULL,\t\tNULL }\n};\n\nstatic const luaL_Reg lj_lib_preload[] = {\n#if LJ_HASFFI\n  { LUA_FFILIBNAME,\tluaopen_ffi },\n#endif\n  { NULL,\t\tNULL }\n};\n\nLUALIB_API void luaL_openlibs(lua_State *L)\n{\n  const luaL_Reg *lib;\n  for (lib = lj_lib_load; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_pushstring(L, lib->name);\n    lua_call(L, 1, 0);\n  }\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\",\n\t\t sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);\n  for (lib = lj_lib_preload; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_setfield(L, -2, lib->name);\n  }\n  lua_pop(L, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_io.c",
    "content": "/*\n** I/O library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n\n#define lib_io_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_state.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* Userdata payload for I/O file. */\ntypedef struct IOFileUD {\n  FILE *fp;\t\t/* File handle. */\n  uint32_t type;\t/* File type. */\n} IOFileUD;\n\n#define IOFILE_TYPE_FILE\t0\t/* Regular file. */\n#define IOFILE_TYPE_PIPE\t1\t/* Pipe. */\n#define IOFILE_TYPE_STDF\t2\t/* Standard file handle. */\n#define IOFILE_TYPE_MASK\t3\n\n#define IOFILE_FLAG_CLOSE\t4\t/* Close after io.lines() iterator. */\n\n#define IOSTDF_UD(L, id)\t(&gcref(G(L)->gcroot[(id)])->ud)\n#define IOSTDF_IOF(L, id)\t((IOFileUD *)uddata(IOSTDF_UD(L, (id))))\n\n/* -- Open/close helpers -------------------------------------------------- */\n\nstatic IOFileUD *io_tofilep(lua_State *L)\n{\n  if (!(L->base < L->top && tvisudata(L->base) &&\n\tudataV(L->base)->udtype == UDTYPE_IO_FILE))\n    lj_err_argtype(L, 1, \"FILE*\");\n  return (IOFileUD *)uddata(udataV(L->base));\n}\n\nstatic IOFileUD *io_tofile(lua_State *L)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOCLFL);\n  return iof;\n}\n\nstatic IOFileUD *io_stdfile(lua_State *L, ptrdiff_t id)\n{\n  IOFileUD *iof = IOSTDF_IOF(L, id);\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOSTDCL);\n  return iof;\n}\n\nstatic IOFileUD *io_file_new(lua_State *L)\n{\n  IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));\n  GCudata *ud = udataV(L->top-1);\n  ud->udtype = UDTYPE_IO_FILE;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcrefr(ud->metatable, curr_func(L)->c.env);\n  iof->fp = NULL;\n  iof->type = IOFILE_TYPE_FILE;\n  return iof;\n}\n\nstatic IOFileUD *io_file_open(lua_State *L, const char *mode)\n{\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  IOFileUD *iof = io_file_new(L);\n  iof->fp = fopen(fname, mode);\n  if (iof->fp == NULL)\n    luaL_argerror(L, 1, lj_strfmt_pushf(L, \"%s: %s\", fname, strerror(errno)));\n  return iof;\n}\n\nstatic int io_file_close(lua_State *L, IOFileUD *iof)\n{\n  int ok;\n  if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) {\n    ok = (fclose(iof->fp) == 0);\n  } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {\n    int stat = -1;\n#if LJ_TARGET_POSIX\n    stat = pclose(iof->fp);\n#elif LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE && !LJ_TARGET_UWP\n    stat = _pclose(iof->fp);\n#endif\n#if LJ_52\n    iof->fp = NULL;\n    return luaL_execresult(L, stat);\n#else\n    ok = (stat != -1);\n#endif\n  } else {\n    lj_assertL((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_STDF,\n\t       \"close of unknown FILE* type\");\n    setnilV(L->top++);\n    lua_pushliteral(L, \"cannot close standard file\");\n    return 2;\n  }\n  iof->fp = NULL;\n  return luaL_fileresult(L, ok, NULL);\n}\n\n/* -- Read/write helpers -------------------------------------------------- */\n\nstatic int io_file_readnum(lua_State *L, FILE *fp)\n{\n  lua_Number d;\n  if (fscanf(fp, LUA_NUMBER_SCAN, &d) == 1) {\n    if (LJ_DUALNUM) {\n      int32_t i = lj_num2int(d);\n      if (d == (lua_Number)i && !tvismzero((cTValue *)&d)) {\n\tsetintV(L->top++, i);\n\treturn 1;\n      }\n    }\n    setnumV(L->top++, d);\n    return 1;\n  } else {\n    setnilV(L->top++);\n    return 0;\n  }\n}\n\nstatic int io_file_readline(lua_State *L, FILE *fp, MSize chop)\n{\n  MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0;\n  char *buf;\n  for (;;) {\n    buf = lj_buf_tmp(L, m);\n    if (fgets(buf+n, m-n, fp) == NULL) break;\n    n += (MSize)strlen(buf+n);\n    ok |= n;\n    if (n && buf[n-1] == '\\n') { n -= chop; break; }\n    if (n >= m - 64) m += m;\n  }\n  setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n  lj_gc_check(L);\n  return (int)ok;\n}\n\nstatic void io_file_readall(lua_State *L, FILE *fp)\n{\n  MSize m, n;\n  for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {\n    char *buf = lj_buf_tmp(L, m);\n    n += (MSize)fread(buf+n, 1, m-n, fp);\n    if (n != m) {\n      setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n      lj_gc_check(L);\n      return;\n    }\n  }\n}\n\nstatic int io_file_readlen(lua_State *L, FILE *fp, MSize m)\n{\n  if (m) {\n    char *buf = lj_buf_tmp(L, m);\n    MSize n = (MSize)fread(buf, 1, m, fp);\n    setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));\n    lj_gc_check(L);\n    return n > 0;\n  } else {\n    int c = getc(fp);\n    ungetc(c, fp);\n    setstrV(L, L->top++, &G(L)->strempty);\n    return (c != EOF);\n  }\n}\n\nstatic int io_file_read(lua_State *L, IOFileUD *iof, int start)\n{\n  FILE *fp = iof->fp;\n  int ok, n, nargs = (int)(L->top - L->base) - start;\n  clearerr(fp);\n  if (nargs == 0) {\n    ok = io_file_readline(L, fp, 1);\n    n = start+1;  /* Return 1 result. */\n  } else {\n    /* The results plus the buffers go on top of the args. */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    ok = 1;\n    for (n = start; nargs-- && ok; n++) {\n      if (tvisstr(L->base+n)) {\n\tconst char *p = strVdata(L->base+n);\n\tif (p[0] == '*') p++;\n\tif (p[0] == 'n')\n\t  ok = io_file_readnum(L, fp);\n\telse if ((p[0] & ~0x20) == 'L')\n\t  ok = io_file_readline(L, fp, (p[0] == 'l'));\n\telse if (p[0] == 'a')\n\t  io_file_readall(L, fp);\n\telse\n\t  lj_err_arg(L, n+1, LJ_ERR_INVFMT);\n      } else if (tvisnumber(L->base+n)) {\n\tok = io_file_readlen(L, fp, (MSize)lj_lib_checkint(L, n+1));\n      } else {\n\tlj_err_arg(L, n+1, LJ_ERR_INVOPT);\n      }\n    }\n  }\n  if (ferror(fp))\n    return luaL_fileresult(L, 0, NULL);\n  if (!ok)\n    setnilV(L->top-1);  /* Replace last result with nil. */\n  return n - start;\n}\n\nstatic int io_file_write(lua_State *L, IOFileUD *iof, int start)\n{\n  FILE *fp = iof->fp;\n  cTValue *tv;\n  int status = 1;\n  for (tv = L->base+start; tv < L->top; tv++) {\n    MSize len;\n    const char *p = lj_strfmt_wstrnum(L, tv, &len);\n    if (!p)\n      lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING);\n    status = status && (fwrite(p, 1, len, fp) == len);\n  }\n  if (LJ_52 && status) {\n    L->top = L->base+1;\n    if (start == 0)\n      setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT));\n    return 1;\n  }\n  return luaL_fileresult(L, status, NULL);\n}\n\nstatic int io_file_iter(lua_State *L)\n{\n  GCfunc *fn = curr_func(L);\n  IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0]));\n  int n = fn->c.nupvalues - 1;\n  if (iof->fp == NULL)\n    lj_err_caller(L, LJ_ERR_IOCLFL);\n  L->top = L->base;\n  if (n) {  /* Copy upvalues with options to stack. */\n    lj_state_checkstack(L, (MSize)n);\n    memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue));\n    L->top += n;\n  }\n  n = io_file_read(L, iof, 0);\n  if (ferror(iof->fp))\n    lj_err_callermsg(L, strVdata(L->top-2));\n  if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) {\n    io_file_close(L, iof);  /* Return values are ignored. */\n    return 0;\n  }\n  return n;\n}\n\nstatic int io_file_lines(lua_State *L)\n{\n  int n = (int)(L->top - L->base);\n  if (n > LJ_MAX_UPVAL)\n    lj_err_caller(L, LJ_ERR_UNPACK);\n  lua_pushcclosure(L, io_file_iter, n);\n  return 1;\n}\n\n/* -- I/O file methods ---------------------------------------------------- */\n\n#define LJLIB_MODULE_io_method\n\nLJLIB_CF(io_method_close)\n{\n  IOFileUD *iof;\n  if (L->base < L->top) {\n    iof = io_tofile(L);\n  } else {\n    iof = IOSTDF_IOF(L, GCROOT_IO_OUTPUT);\n    if (iof->fp == NULL)\n      lj_err_caller(L, LJ_ERR_IOCLFL);\n  }\n  return io_file_close(L, iof);\n}\n\nLJLIB_CF(io_method_read)\n{\n  return io_file_read(L, io_tofile(L), 1);\n}\n\nLJLIB_CF(io_method_write)\t\tLJLIB_REC(io_write 0)\n{\n  return io_file_write(L, io_tofile(L), 1);\n}\n\nLJLIB_CF(io_method_flush)\t\tLJLIB_REC(io_flush 0)\n{\n  return luaL_fileresult(L, fflush(io_tofile(L)->fp) == 0, NULL);\n}\n\n#if LJ_32 && defined(__ANDROID__) && __ANDROID_API__ < 24\n/* The Android NDK is such an unmatched marvel of engineering. */\nextern int fseeko32(FILE *, long int, int) __asm__(\"fseeko\");\nextern long int ftello32(FILE *) __asm__(\"ftello\");\n#define fseeko(fp, pos, whence)\t(fseeko32((fp), (pos), (whence)))\n#define ftello(fp)\t\t(ftello32((fp)))\n#endif\n\nLJLIB_CF(io_method_seek)\n{\n  FILE *fp = io_tofile(L)->fp;\n  int opt = lj_lib_checkopt(L, 2, 1, \"\\3set\\3cur\\3end\");\n  int64_t ofs = 0;\n  cTValue *o;\n  int res;\n  if (opt == 0) opt = SEEK_SET;\n  else if (opt == 1) opt = SEEK_CUR;\n  else if (opt == 2) opt = SEEK_END;\n  o = L->base+2;\n  if (o < L->top) {\n    if (tvisint(o))\n      ofs = (int64_t)intV(o);\n    else if (tvisnum(o))\n      ofs = (int64_t)numV(o);\n    else if (!tvisnil(o))\n      lj_err_argt(L, 3, LUA_TNUMBER);\n  }\n#if LJ_TARGET_POSIX\n  res = fseeko(fp, ofs, opt);\n#elif _MSC_VER >= 1400\n  res = _fseeki64(fp, ofs, opt);\n#elif defined(__MINGW32__)\n  res = fseeko64(fp, ofs, opt);\n#else\n  res = fseek(fp, (long)ofs, opt);\n#endif\n  if (res)\n    return luaL_fileresult(L, 0, NULL);\n#if LJ_TARGET_POSIX\n  ofs = ftello(fp);\n#elif _MSC_VER >= 1400\n  ofs = _ftelli64(fp);\n#elif defined(__MINGW32__)\n  ofs = ftello64(fp);\n#else\n  ofs = (int64_t)ftell(fp);\n#endif\n  setint64V(L->top-1, ofs);\n  return 1;\n}\n\nLJLIB_CF(io_method_setvbuf)\n{\n  FILE *fp = io_tofile(L)->fp;\n  int opt = lj_lib_checkopt(L, 2, -1, \"\\4full\\4line\\2no\");\n  size_t sz = (size_t)lj_lib_optint(L, 3, LUAL_BUFFERSIZE);\n  if (opt == 0) opt = _IOFBF;\n  else if (opt == 1) opt = _IOLBF;\n  else if (opt == 2) opt = _IONBF;\n  return luaL_fileresult(L, setvbuf(fp, NULL, opt, sz) == 0, NULL);\n}\n\nLJLIB_CF(io_method_lines)\n{\n  io_tofile(L);\n  return io_file_lines(L);\n}\n\nLJLIB_CF(io_method___gc)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp != NULL && (iof->type & IOFILE_TYPE_MASK) != IOFILE_TYPE_STDF)\n    io_file_close(L, iof);\n  return 0;\n}\n\nLJLIB_CF(io_method___tostring)\n{\n  IOFileUD *iof = io_tofilep(L);\n  if (iof->fp != NULL)\n    lua_pushfstring(L, \"file (%p)\", iof->fp);\n  else\n    lua_pushliteral(L, \"file (closed)\");\n  return 1;\n}\n\nLJLIB_PUSH(top-1) LJLIB_SET(__index)\n\n#include \"lj_libdef.h\"\n\n/* -- I/O library functions ----------------------------------------------- */\n\n#define LJLIB_MODULE_io\n\nLJLIB_PUSH(top-2) LJLIB_SET(!)  /* Set environment. */\n\nLJLIB_CF(io_open)\n{\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  GCstr *s = lj_lib_optstr(L, 2);\n  const char *mode = s ? strdata(s) : \"r\";\n  IOFileUD *iof = io_file_new(L);\n  iof->fp = fopen(fname, mode);\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);\n}\n\nLJLIB_CF(io_popen)\n{\n#if LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE && !LJ_TARGET_UWP)\n  const char *fname = strdata(lj_lib_checkstr(L, 1));\n  GCstr *s = lj_lib_optstr(L, 2);\n  const char *mode = s ? strdata(s) : \"r\";\n  IOFileUD *iof = io_file_new(L);\n  iof->type = IOFILE_TYPE_PIPE;\n#if LJ_TARGET_POSIX\n  fflush(NULL);\n  iof->fp = popen(fname, mode);\n#else\n  iof->fp = _popen(fname, mode);\n#endif\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);\n#else\n  return luaL_error(L, LUA_QL(\"popen\") \" not supported\");\n#endif\n}\n\nLJLIB_CF(io_tmpfile)\n{\n  IOFileUD *iof = io_file_new(L);\n#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n  iof->fp = NULL; errno = ENOSYS;\n#else\n  iof->fp = tmpfile();\n#endif\n  return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL);\n}\n\nLJLIB_CF(io_close)\n{\n  return lj_cf_io_method_close(L);\n}\n\nLJLIB_CF(io_read)\n{\n  return io_file_read(L, io_stdfile(L, GCROOT_IO_INPUT), 0);\n}\n\nLJLIB_CF(io_write)\t\tLJLIB_REC(io_write GCROOT_IO_OUTPUT)\n{\n  return io_file_write(L, io_stdfile(L, GCROOT_IO_OUTPUT), 0);\n}\n\nLJLIB_CF(io_flush)\t\tLJLIB_REC(io_flush GCROOT_IO_OUTPUT)\n{\n  return luaL_fileresult(L, fflush(io_stdfile(L, GCROOT_IO_OUTPUT)->fp) == 0, NULL);\n}\n\nstatic int io_std_getset(lua_State *L, ptrdiff_t id, const char *mode)\n{\n  if (L->base < L->top && !tvisnil(L->base)) {\n    if (tvisudata(L->base)) {\n      io_tofile(L);\n      L->top = L->base+1;\n    } else {\n      io_file_open(L, mode);\n    }\n    /* NOBARRIER: The standard I/O handles are GC roots. */\n    setgcref(G(L)->gcroot[id], gcV(L->top-1));\n  } else {\n    setudataV(L, L->top++, IOSTDF_UD(L, id));\n  }\n  return 1;\n}\n\nLJLIB_CF(io_input)\n{\n  return io_std_getset(L, GCROOT_IO_INPUT, \"r\");\n}\n\nLJLIB_CF(io_output)\n{\n  return io_std_getset(L, GCROOT_IO_OUTPUT, \"w\");\n}\n\nLJLIB_CF(io_lines)\n{\n  if (L->base == L->top) setnilV(L->top++);\n  if (!tvisnil(L->base)) {  /* io.lines(fname) */\n    IOFileUD *iof = io_file_open(L, \"r\");\n    iof->type = IOFILE_TYPE_FILE|IOFILE_FLAG_CLOSE;\n    L->top--;\n    setudataV(L, L->base, udataV(L->top));\n  } else {  /* io.lines() iterates over stdin. */\n    setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT));\n  }\n  return io_file_lines(L);\n}\n\nLJLIB_CF(io_type)\n{\n  cTValue *o = lj_lib_checkany(L, 1);\n  if (!(tvisudata(o) && udataV(o)->udtype == UDTYPE_IO_FILE))\n    setnilV(L->top++);\n  else if (((IOFileUD *)uddata(udataV(o)))->fp != NULL)\n    lua_pushliteral(L, \"file\");\n  else\n    lua_pushliteral(L, \"closed file\");\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\n/* ------------------------------------------------------------------------ */\n\nstatic GCobj *io_std_new(lua_State *L, FILE *fp, const char *name)\n{\n  IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));\n  GCudata *ud = udataV(L->top-1);\n  ud->udtype = UDTYPE_IO_FILE;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcref(ud->metatable, gcV(L->top-3));\n  iof->fp = fp;\n  iof->type = IOFILE_TYPE_STDF;\n  lua_setfield(L, -2, name);\n  return obj2gco(ud);\n}\n\nLUALIB_API int luaopen_io(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, io_method);\n  copyTV(L, L->top, L->top-1); L->top++;\n  lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);\n  LJ_LIB_REG(L, LUA_IOLIBNAME, io);\n  setgcref(G(L)->gcroot[GCROOT_IO_INPUT], io_std_new(L, stdin, \"stdin\"));\n  setgcref(G(L)->gcroot[GCROOT_IO_OUTPUT], io_std_new(L, stdout, \"stdout\"));\n  io_std_new(L, stderr, \"stderr\");\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_jit.c",
    "content": "/*\n** JIT library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lib_jit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#if LJ_HASJIT\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_target.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n#include \"lj_lib.h\"\n\n#include \"luajit.h\"\n\n/* -- jit.* functions ----------------------------------------------------- */\n\n#define LJLIB_MODULE_jit\n\nstatic int setjitmode(lua_State *L, int mode)\n{\n  int idx = 0;\n  if (L->base == L->top || tvisnil(L->base)) {  /* jit.on/off/flush([nil]) */\n    mode |= LUAJIT_MODE_ENGINE;\n  } else {\n    /* jit.on/off/flush(func|proto, nil|true|false) */\n    if (tvisfunc(L->base) || tvisproto(L->base))\n      idx = 1;\n    else if (!tvistrue(L->base))  /* jit.on/off/flush(true, nil|true|false) */\n      goto err;\n    if (L->base+1 < L->top && tvisbool(L->base+1))\n      mode |= boolV(L->base+1) ? LUAJIT_MODE_ALLFUNC : LUAJIT_MODE_ALLSUBFUNC;\n    else\n      mode |= LUAJIT_MODE_FUNC;\n  }\n  if (luaJIT_setmode(L, idx, mode) != 1) {\n    if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE)\n      lj_err_caller(L, LJ_ERR_NOJIT);\n  err:\n    lj_err_argt(L, 1, LUA_TFUNCTION);\n  }\n  return 0;\n}\n\nLJLIB_CF(jit_on)\n{\n  return setjitmode(L, LUAJIT_MODE_ON);\n}\n\nLJLIB_CF(jit_off)\n{\n  return setjitmode(L, LUAJIT_MODE_OFF);\n}\n\nLJLIB_CF(jit_flush)\n{\n#if LJ_HASJIT\n  if (L->base < L->top && tvisnumber(L->base)) {\n    int traceno = lj_lib_checkint(L, 1);\n    luaJIT_setmode(L, traceno, LUAJIT_MODE_FLUSH|LUAJIT_MODE_TRACE);\n    return 0;\n  }\n#endif\n  return setjitmode(L, LUAJIT_MODE_FLUSH);\n}\n\n#if LJ_HASJIT\n/* Push a string for every flag bit that is set. */\nstatic void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base,\n\t\t\t\tconst char *str)\n{\n  for (; *str; base <<= 1, str += 1+*str)\n    if (flags & base)\n      setstrV(L, L->top++, lj_str_new(L, str+1, *(uint8_t *)str));\n}\n#endif\n\nLJLIB_CF(jit_status)\n{\n#if LJ_HASJIT\n  jit_State *J = L2J(L);\n  L->top = L->base;\n  setboolV(L->top++, (J->flags & JIT_F_ON) ? 1 : 0);\n  flagbits_to_strings(L, J->flags, JIT_F_CPU, JIT_F_CPUSTRING);\n  flagbits_to_strings(L, J->flags, JIT_F_OPT, JIT_F_OPTSTRING);\n  return (int)(L->top - L->base);\n#else\n  setboolV(L->top++, 0);\n  return 1;\n#endif\n}\n\nLJLIB_CF(jit_security)\n{\n  int idx = lj_lib_checkopt(L, 1, -1, LJ_SECURITY_MODESTRING);\n  setintV(L->top++, ((LJ_SECURITY_MODE >> (2*idx)) & 3));\n  return 1;\n}\n\nLJLIB_CF(jit_attach)\n{\n#ifdef LUAJIT_DISABLE_VMEVENT\n  luaL_error(L, \"vmevent API disabled\");\n#else\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  GCstr *s = lj_lib_optstr(L, 2);\n  luaL_findtable(L, LUA_REGISTRYINDEX, LJ_VMEVENTS_REGKEY, LJ_VMEVENTS_HSIZE);\n  if (s) {  /* Attach to given event. */\n    const uint8_t *p = (const uint8_t *)strdata(s);\n    uint32_t h = s->len;\n    while (*p) h = h ^ (lj_rol(h, 6) + *p++);\n    lua_pushvalue(L, 1);\n    lua_rawseti(L, -2, VMEVENT_HASHIDX(h));\n    G(L)->vmevmask = VMEVENT_NOCACHE;  /* Invalidate cache. */\n  } else {  /* Detach if no event given. */\n    setnilV(L->top++);\n    while (lua_next(L, -2)) {\n      L->top--;\n      if (tvisfunc(L->top) && funcV(L->top) == fn) {\n\tsetnilV(lj_tab_set(L, tabV(L->top-2), L->top-1));\n      }\n    }\n  }\n#endif\n  return 0;\n}\n\nLJLIB_PUSH(top-5) LJLIB_SET(os)\nLJLIB_PUSH(top-4) LJLIB_SET(arch)\nLJLIB_PUSH(top-3) LJLIB_SET(version_num)\nLJLIB_PUSH(top-2) LJLIB_SET(version)\n\n#include \"lj_libdef.h\"\n\n/* -- jit.util.* functions ------------------------------------------------ */\n\n#define LJLIB_MODULE_jit_util\n\n/* -- Reflection API for Lua functions ------------------------------------ */\n\n/* Return prototype of first argument (Lua function or prototype object) */\nstatic GCproto *check_Lproto(lua_State *L, int nolua)\n{\n  TValue *o = L->base;\n  if (L->top > o) {\n    if (tvisproto(o)) {\n      return protoV(o);\n    } else if (tvisfunc(o)) {\n      if (isluafunc(funcV(o)))\n\treturn funcproto(funcV(o));\n      else if (nolua)\n\treturn NULL;\n    }\n  }\n  lj_err_argt(L, 1, LUA_TFUNCTION);\n  return NULL;  /* unreachable */\n}\n\nstatic void setintfield(lua_State *L, GCtab *t, const char *name, int32_t val)\n{\n  setintV(lj_tab_setstr(L, t, lj_str_newz(L, name)), val);\n}\n\n/* local info = jit.util.funcinfo(func [,pc]) */\nLJLIB_CF(jit_util_funcinfo)\n{\n  GCproto *pt = check_Lproto(L, 1);\n  if (pt) {\n    BCPos pc = (BCPos)lj_lib_optint(L, 2, 0);\n    GCtab *t;\n    lua_createtable(L, 0, 16);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintfield(L, t, \"linedefined\", pt->firstline);\n    setintfield(L, t, \"lastlinedefined\", pt->firstline + pt->numline);\n    setintfield(L, t, \"stackslots\", pt->framesize);\n    setintfield(L, t, \"params\", pt->numparams);\n    setintfield(L, t, \"bytecodes\", (int32_t)pt->sizebc);\n    setintfield(L, t, \"gcconsts\", (int32_t)pt->sizekgc);\n    setintfield(L, t, \"nconsts\", (int32_t)pt->sizekn);\n    setintfield(L, t, \"upvalues\", (int32_t)pt->sizeuv);\n    if (pc < pt->sizebc)\n      setintfield(L, t, \"currentline\", lj_debug_line(pt, pc));\n    lua_pushboolean(L, (pt->flags & PROTO_VARARG));\n    lua_setfield(L, -2, \"isvararg\");\n    lua_pushboolean(L, (pt->flags & PROTO_CHILD));\n    lua_setfield(L, -2, \"children\");\n    setstrV(L, L->top++, proto_chunkname(pt));\n    lua_setfield(L, -2, \"source\");\n    lj_debug_pushloc(L, pt, pc);\n    lua_setfield(L, -2, \"loc\");\n    setprotoV(L, lj_tab_setstr(L, t, lj_str_newlit(L, \"proto\")), pt);\n  } else {\n    GCfunc *fn = funcV(L->base);\n    GCtab *t;\n    lua_createtable(L, 0, 4);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    if (!iscfunc(fn))\n      setintfield(L, t, \"ffid\", fn->c.ffid);\n    setintptrV(lj_tab_setstr(L, t, lj_str_newlit(L, \"addr\")),\n\t       (intptr_t)(void *)fn->c.f);\n    setintfield(L, t, \"upvalues\", fn->c.nupvalues);\n  }\n  return 1;\n}\n\n/* local ins, m = jit.util.funcbc(func, pc) */\nLJLIB_CF(jit_util_funcbc)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  BCPos pc = (BCPos)lj_lib_checkint(L, 2);\n  if (pc < pt->sizebc) {\n    BCIns ins = proto_bc(pt)[pc];\n    BCOp op = bc_op(ins);\n    lj_assertL(op < BC__MAX, \"bad bytecode op %d\", op);\n    setintV(L->top, ins);\n    setintV(L->top+1, lj_bc_mode[op]);\n    L->top += 2;\n    return 2;\n  }\n  return 0;\n}\n\n/* local k = jit.util.funck(func, idx) */\nLJLIB_CF(jit_util_funck)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2);\n  if (idx >= 0) {\n    if (idx < (ptrdiff_t)pt->sizekn) {\n      copyTV(L, L->top-1, proto_knumtv(pt, idx));\n      return 1;\n    }\n  } else {\n    if (~idx < (ptrdiff_t)pt->sizekgc) {\n      GCobj *gc = proto_kgc(pt, idx);\n      setgcV(L, L->top-1, gc, ~gc->gch.gct);\n      return 1;\n    }\n  }\n  return 0;\n}\n\n/* local name = jit.util.funcuvname(func, idx) */\nLJLIB_CF(jit_util_funcuvname)\n{\n  GCproto *pt = check_Lproto(L, 0);\n  uint32_t idx = (uint32_t)lj_lib_checkint(L, 2);\n  if (idx < pt->sizeuv) {\n    setstrV(L, L->top-1, lj_str_newz(L, lj_debug_uvname(pt, idx)));\n    return 1;\n  }\n  return 0;\n}\n\n/* -- Reflection API for traces ------------------------------------------- */\n\n#if LJ_HASJIT\n\n/* Check trace argument. Must not throw for non-existent trace numbers. */\nstatic GCtrace *jit_checktrace(lua_State *L)\n{\n  TraceNo tr = (TraceNo)lj_lib_checkint(L, 1);\n  jit_State *J = L2J(L);\n  if (tr > 0 && tr < J->sizetrace)\n    return traceref(J, tr);\n  return NULL;\n}\n\n/* Names of link types. ORDER LJ_TRLINK */\nstatic const char *const jit_trlinkname[] = {\n  \"none\", \"root\", \"loop\", \"tail-recursion\", \"up-recursion\", \"down-recursion\",\n  \"interpreter\", \"return\", \"stitch\"\n};\n\n/* local info = jit.util.traceinfo(tr) */\nLJLIB_CF(jit_util_traceinfo)\n{\n  GCtrace *T = jit_checktrace(L);\n  if (T) {\n    GCtab *t;\n    lua_createtable(L, 0, 8);  /* Increment hash size if fields are added. */\n    t = tabV(L->top-1);\n    setintfield(L, t, \"nins\", (int32_t)T->nins - REF_BIAS - 1);\n    setintfield(L, t, \"nk\", REF_BIAS - (int32_t)T->nk);\n    setintfield(L, t, \"link\", T->link);\n    setintfield(L, t, \"nexit\", T->nsnap);\n    setstrV(L, L->top++, lj_str_newz(L, jit_trlinkname[T->linktype]));\n    lua_setfield(L, -2, \"linktype\");\n    /* There are many more fields. Add them only when needed. */\n    return 1;\n  }\n  return 0;\n}\n\n/* local m, ot, op1, op2, prev = jit.util.traceir(tr, idx) */\nLJLIB_CF(jit_util_traceir)\n{\n  GCtrace *T = jit_checktrace(L);\n  IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;\n  if (T && ref >= REF_BIAS && ref < T->nins) {\n    IRIns *ir = &T->ir[ref];\n    int32_t m = lj_ir_mode[ir->o];\n    setintV(L->top-2, m);\n    setintV(L->top-1, ir->ot);\n    setintV(L->top++, (int32_t)ir->op1 - (irm_op1(m)==IRMref ? REF_BIAS : 0));\n    setintV(L->top++, (int32_t)ir->op2 - (irm_op2(m)==IRMref ? REF_BIAS : 0));\n    setintV(L->top++, ir->prev);\n    return 5;\n  }\n  return 0;\n}\n\n/* local k, t [, slot] = jit.util.tracek(tr, idx) */\nLJLIB_CF(jit_util_tracek)\n{\n  GCtrace *T = jit_checktrace(L);\n  IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;\n  if (T && ref >= T->nk && ref < REF_BIAS) {\n    IRIns *ir = &T->ir[ref];\n    int32_t slot = -1;\n    if (ir->o == IR_KSLOT) {\n      slot = ir->op2;\n      ir = &T->ir[ir->op1];\n    }\n#if LJ_HASFFI\n    if (ir->o == IR_KINT64) ctype_loadffi(L);\n#endif\n    lj_ir_kvalue(L, L->top-2, ir);\n    setintV(L->top-1, (int32_t)irt_type(ir->t));\n    if (slot == -1)\n      return 2;\n    setintV(L->top++, slot);\n    return 3;\n  }\n  return 0;\n}\n\n/* local snap = jit.util.tracesnap(tr, sn) */\nLJLIB_CF(jit_util_tracesnap)\n{\n  GCtrace *T = jit_checktrace(L);\n  SnapNo sn = (SnapNo)lj_lib_checkint(L, 2);\n  if (T && sn < T->nsnap) {\n    SnapShot *snap = &T->snap[sn];\n    SnapEntry *map = &T->snapmap[snap->mapofs];\n    MSize n, nent = snap->nent;\n    GCtab *t;\n    lua_createtable(L, nent+2, 0);\n    t = tabV(L->top-1);\n    setintV(lj_tab_setint(L, t, 0), (int32_t)snap->ref - REF_BIAS);\n    setintV(lj_tab_setint(L, t, 1), (int32_t)snap->nslots);\n    for (n = 0; n < nent; n++)\n      setintV(lj_tab_setint(L, t, (int32_t)(n+2)), (int32_t)map[n]);\n    setintV(lj_tab_setint(L, t, (int32_t)(nent+2)), (int32_t)SNAP(255, 0, 0));\n    return 1;\n  }\n  return 0;\n}\n\n/* local mcode, addr, loop = jit.util.tracemc(tr) */\nLJLIB_CF(jit_util_tracemc)\n{\n  GCtrace *T = jit_checktrace(L);\n  if (T && T->mcode != NULL) {\n    setstrV(L, L->top-1, lj_str_new(L, (const char *)T->mcode, T->szmcode));\n    setintptrV(L->top++, (intptr_t)(void *)T->mcode);\n    setintV(L->top++, T->mcloop);\n    return 3;\n  }\n  return 0;\n}\n\n/* local addr = jit.util.traceexitstub([tr,] exitno) */\nLJLIB_CF(jit_util_traceexitstub)\n{\n#ifdef EXITSTUBS_PER_GROUP\n  ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1);\n  jit_State *J = L2J(L);\n  if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) {\n    setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno));\n    return 1;\n  }\n#else\n  if (L->top > L->base+1) {  /* Don't throw for one-argument variant. */\n    GCtrace *T = jit_checktrace(L);\n    ExitNo exitno = (ExitNo)lj_lib_checkint(L, 2);\n    ExitNo maxexit = T->root ? T->nsnap+1 : T->nsnap;\n    if (T && T->mcode != NULL && exitno < maxexit) {\n      setintptrV(L->top-1, (intptr_t)(void *)exitstub_trace_addr(T, exitno));\n      return 1;\n    }\n  }\n#endif\n  return 0;\n}\n\n/* local addr = jit.util.ircalladdr(idx) */\nLJLIB_CF(jit_util_ircalladdr)\n{\n  uint32_t idx = (uint32_t)lj_lib_checkint(L, 1);\n  if (idx < IRCALL__MAX) {\n    setintptrV(L->top-1, (intptr_t)(void *)lj_ir_callinfo[idx].func);\n    return 1;\n  }\n  return 0;\n}\n\n#endif\n\n#include \"lj_libdef.h\"\n\nstatic int luaopen_jit_util(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, jit_util);\n  return 1;\n}\n\n/* -- jit.opt module ------------------------------------------------------ */\n\n#if LJ_HASJIT\n\n#define LJLIB_MODULE_jit_opt\n\n/* Parse optimization level. */\nstatic int jitopt_level(jit_State *J, const char *str)\n{\n  if (str[0] >= '0' && str[0] <= '9' && str[1] == '\\0') {\n    uint32_t flags;\n    if (str[0] == '0') flags = JIT_F_OPT_0;\n    else if (str[0] == '1') flags = JIT_F_OPT_1;\n    else if (str[0] == '2') flags = JIT_F_OPT_2;\n    else flags = JIT_F_OPT_3;\n    J->flags = (J->flags & ~JIT_F_OPT_MASK) | flags;\n    return 1;  /* Ok. */\n  }\n  return 0;  /* No match. */\n}\n\n/* Parse optimization flag. */\nstatic int jitopt_flag(jit_State *J, const char *str)\n{\n  const char *lst = JIT_F_OPTSTRING;\n  uint32_t opt;\n  int set = 1;\n  if (str[0] == '+') {\n    str++;\n  } else if (str[0] == '-') {\n    str++;\n    set = 0;\n  } else if (str[0] == 'n' && str[1] == 'o') {\n    str += str[2] == '-' ? 3 : 2;\n    set = 0;\n  }\n  for (opt = JIT_F_OPT; ; opt <<= 1) {\n    size_t len = *(const uint8_t *)lst;\n    if (len == 0)\n      break;\n    if (strncmp(str, lst+1, len) == 0 && str[len] == '\\0') {\n      if (set) J->flags |= opt; else J->flags &= ~opt;\n      return 1;  /* Ok. */\n    }\n    lst += 1+len;\n  }\n  return 0;  /* No match. */\n}\n\n/* Parse optimization parameter. */\nstatic int jitopt_param(jit_State *J, const char *str)\n{\n  const char *lst = JIT_P_STRING;\n  int i;\n  for (i = 0; i < JIT_P__MAX; i++) {\n    size_t len = *(const uint8_t *)lst;\n    lj_assertJ(len != 0, \"bad JIT_P_STRING\");\n    if (strncmp(str, lst+1, len) == 0 && str[len] == '=') {\n      int32_t n = 0;\n      const char *p = &str[len+1];\n      while (*p >= '0' && *p <= '9')\n\tn = n*10 + (*p++ - '0');\n      if (*p) return 0;  /* Malformed number. */\n      J->param[i] = n;\n      if (i == JIT_P_hotloop)\n\tlj_dispatch_init_hotcount(J2G(J));\n      return 1;  /* Ok. */\n    }\n    lst += 1+len;\n  }\n  return 0;  /* No match. */\n}\n\n/* jit.opt.start(flags...) */\nLJLIB_CF(jit_opt_start)\n{\n  jit_State *J = L2J(L);\n  int nargs = (int)(L->top - L->base);\n  if (nargs == 0) {\n    J->flags = (J->flags & ~JIT_F_OPT_MASK) | JIT_F_OPT_DEFAULT;\n  } else {\n    int i;\n    for (i = 1; i <= nargs; i++) {\n      const char *str = strdata(lj_lib_checkstr(L, i));\n      if (!jitopt_level(J, str) &&\n\t  !jitopt_flag(J, str) &&\n\t  !jitopt_param(J, str))\n\tlj_err_callerv(L, LJ_ERR_JITOPT, str);\n    }\n  }\n  return 0;\n}\n\n#include \"lj_libdef.h\"\n\n#endif\n\n/* -- jit.profile module -------------------------------------------------- */\n\n#if LJ_HASPROFILE\n\n#define LJLIB_MODULE_jit_profile\n\n/* Not loaded by default, use: local profile = require(\"jit.profile\") */\n\n#define KEY_PROFILE_THREAD\t(U64x(80000000,00000000)|'t')\n#define KEY_PROFILE_FUNC\t(U64x(80000000,00000000)|'f')\n\nstatic void jit_profile_callback(lua_State *L2, lua_State *L, int samples,\n\t\t\t\t int vmstate)\n{\n  TValue key;\n  cTValue *tv;\n  key.u64 = KEY_PROFILE_FUNC;\n  tv = lj_tab_get(L, tabV(registry(L)), &key);\n  if (tvisfunc(tv)) {\n    char vmst = (char)vmstate;\n    int status;\n    setfuncV(L2, L2->top++, funcV(tv));\n    setthreadV(L2, L2->top++, L);\n    setintV(L2->top++, samples);\n    setstrV(L2, L2->top++, lj_str_new(L2, &vmst, 1));\n    status = lua_pcall(L2, 3, 0, 0);  /* callback(thread, samples, vmstate) */\n    if (status) {\n      if (G(L2)->panic) G(L2)->panic(L2);\n      exit(EXIT_FAILURE);\n    }\n    lj_trace_abort(G(L2));\n  }\n}\n\n/* profile.start(mode, cb) */\nLJLIB_CF(jit_profile_start)\n{\n  GCtab *registry = tabV(registry(L));\n  GCstr *mode = lj_lib_optstr(L, 1);\n  GCfunc *func = lj_lib_checkfunc(L, 2);\n  lua_State *L2 = lua_newthread(L);  /* Thread that runs profiler callback. */\n  TValue key;\n  /* Anchor thread and function in registry. */\n  key.u64 = KEY_PROFILE_THREAD;\n  setthreadV(L, lj_tab_set(L, registry, &key), L2);\n  key.u64 = KEY_PROFILE_FUNC;\n  setfuncV(L, lj_tab_set(L, registry, &key), func);\n  lj_gc_anybarriert(L, registry);\n  luaJIT_profile_start(L, mode ? strdata(mode) : \"\",\n\t\t       (luaJIT_profile_callback)jit_profile_callback, L2);\n  return 0;\n}\n\n/* profile.stop() */\nLJLIB_CF(jit_profile_stop)\n{\n  GCtab *registry;\n  TValue key;\n  luaJIT_profile_stop(L);\n  registry = tabV(registry(L));\n  key.u64 = KEY_PROFILE_THREAD;\n  setnilV(lj_tab_set(L, registry, &key));\n  key.u64 = KEY_PROFILE_FUNC;\n  setnilV(lj_tab_set(L, registry, &key));\n  lj_gc_anybarriert(L, registry);\n  return 0;\n}\n\n/* dump = profile.dumpstack([thread,] fmt, depth) */\nLJLIB_CF(jit_profile_dumpstack)\n{\n  lua_State *L2 = L;\n  int arg = 0;\n  size_t len;\n  int depth;\n  GCstr *fmt;\n  const char *p;\n  if (L->top > L->base && tvisthread(L->base)) {\n    L2 = threadV(L->base);\n    arg = 1;\n  }\n  fmt = lj_lib_checkstr(L, arg+1);\n  depth = lj_lib_checkint(L, arg+2);\n  p = luaJIT_profile_dumpstack(L2, strdata(fmt), depth, &len);\n  lua_pushlstring(L, p, len);\n  return 1;\n}\n\n#include \"lj_libdef.h\"\n\nstatic int luaopen_jit_profile(lua_State *L)\n{\n  LJ_LIB_REG(L, NULL, jit_profile);\n  return 1;\n}\n\n#endif\n\n/* -- JIT compiler initialization ----------------------------------------- */\n\n#if LJ_HASJIT\n/* Default values for JIT parameters. */\nstatic const int32_t jit_param_default[JIT_P__MAX+1] = {\n#define JIT_PARAMINIT(len, name, value)\t(value),\nJIT_PARAMDEF(JIT_PARAMINIT)\n#undef JIT_PARAMINIT\n  0\n};\n\n#if LJ_TARGET_ARM && LJ_TARGET_LINUX\n#include <sys/utsname.h>\n#endif\n\n/* Arch-dependent CPU feature detection. */\nstatic uint32_t jit_cpudetect(void)\n{\n  uint32_t flags = 0;\n#if LJ_TARGET_X86ORX64\n\n  uint32_t vendor[4];\n  uint32_t features[4];\n  if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) {\n    flags |= ((features[2] >> 0)&1) * JIT_F_SSE3;\n    flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1;\n    if (vendor[0] >= 7) {\n      uint32_t xfeatures[4];\n      lj_vm_cpuid(7, xfeatures);\n      flags |= ((xfeatures[1] >> 8)&1) * JIT_F_BMI2;\n    }\n  }\n  /* Don't bother checking for SSE2 -- the VM will crash before getting here. */\n\n#elif LJ_TARGET_ARM\n\n  int ver = LJ_ARCH_VERSION;  /* Compile-time ARM CPU detection. */\n#if LJ_TARGET_LINUX\n  if (ver < 70) {  /* Runtime ARM CPU detection. */\n    struct utsname ut;\n    uname(&ut);\n    if (strncmp(ut.machine, \"armv\", 4) == 0) {\n      if (ut.machine[4] >= '8') ver = 80;\n      else if (ut.machine[4] == '7') ver = 70;\n      else if (ut.machine[4] == '6') ver = 60;\n    }\n  }\n#endif\n  flags |= ver >= 70 ? JIT_F_ARMV7 :\n\t   ver >= 61 ? JIT_F_ARMV6T2_ :\n\t   ver >= 60 ? JIT_F_ARMV6_ : 0;\n  flags |= LJ_ARCH_HASFPU == 0 ? 0 : ver >= 70 ? JIT_F_VFPV3 : JIT_F_VFPV2;\n\n#elif LJ_TARGET_ARM64\n\n  /* No optional CPU features to detect (for now). */\n\n#elif LJ_TARGET_PPC\n\n#if LJ_ARCH_SQRT\n  flags |= JIT_F_SQRT;\n#endif\n#if LJ_ARCH_ROUND\n  flags |= JIT_F_ROUND;\n#endif\n\n#elif LJ_TARGET_MIPS\n\n  /* Compile-time MIPS CPU detection. */\n#if LJ_ARCH_VERSION >= 20\n  flags |= JIT_F_MIPSXXR2;\n#endif\n  /* Runtime MIPS CPU detection. */\n#if defined(__GNUC__)\n  if (!(flags & JIT_F_MIPSXXR2)) {\n    int x;\n#ifdef __mips16\n    x = 0;  /* Runtime detection is difficult. Ensure optimal -march flags. */\n#else\n    /* On MIPS32R1 rotr is treated as srl. rotr r2,r2,1 -> srl r2,r2,1. */\n    __asm__(\"li $2, 1\\n\\t.long 0x00221042\\n\\tmove %0, $2\" : \"=r\"(x) : : \"$2\");\n#endif\n    if (x) flags |= JIT_F_MIPSXXR2;  /* Either 0x80000000 (R2) or 0 (R1). */\n  }\n#endif\n\n#else\n#error \"Missing CPU detection for this architecture\"\n#endif\n  return flags;\n}\n\n/* Initialize JIT compiler. */\nstatic void jit_init(lua_State *L)\n{\n  jit_State *J = L2J(L);\n  J->flags = jit_cpudetect() | JIT_F_ON | JIT_F_OPT_DEFAULT;\n  memcpy(J->param, jit_param_default, sizeof(J->param));\n  lj_dispatch_update(G(L));\n}\n#endif\n\nLUALIB_API int luaopen_jit(lua_State *L)\n{\n#if LJ_HASJIT\n  jit_init(L);\n#endif\n  lua_pushliteral(L, LJ_OS_NAME);\n  lua_pushliteral(L, LJ_ARCH_NAME);\n  lua_pushinteger(L, LUAJIT_VERSION_NUM);\n  lua_pushliteral(L, LUAJIT_VERSION);\n  LJ_LIB_REG(L, LUA_JITLIBNAME, jit);\n#if LJ_HASPROFILE\n  lj_lib_prereg(L, LUA_JITLIBNAME \".profile\", luaopen_jit_profile,\n\t\ttabref(L->env));\n#endif\n#ifndef LUAJIT_DISABLE_JITUTIL\n  lj_lib_prereg(L, LUA_JITLIBNAME \".util\", luaopen_jit_util, tabref(L->env));\n#endif\n#if LJ_HASJIT\n  LJ_LIB_REG(L, \"jit.opt\", jit_opt);\n#endif\n  L->top -= 2;\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_math.c",
    "content": "/*\n** Math library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <math.h>\n\n#define lib_math_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_lib.h\"\n#include \"lj_vm.h\"\n#include \"lj_prng.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_math\n\nLJLIB_ASM(math_abs)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknumber(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_floor)\t\tLJLIB_REC(math_round IRFPM_FLOOR)\nLJLIB_ASM_(math_ceil)\t\tLJLIB_REC(math_round IRFPM_CEIL)\n\nLJLIB_ASM(math_sqrt)\t\tLJLIB_REC(math_unary IRFPM_SQRT)\n{\n  lj_lib_checknum(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_log10)\t\tLJLIB_REC(math_call IRCALL_log10)\nLJLIB_ASM_(math_exp)\t\tLJLIB_REC(math_call IRCALL_exp)\nLJLIB_ASM_(math_sin)\t\tLJLIB_REC(math_call IRCALL_sin)\nLJLIB_ASM_(math_cos)\t\tLJLIB_REC(math_call IRCALL_cos)\nLJLIB_ASM_(math_tan)\t\tLJLIB_REC(math_call IRCALL_tan)\nLJLIB_ASM_(math_asin)\t\tLJLIB_REC(math_call IRCALL_asin)\nLJLIB_ASM_(math_acos)\t\tLJLIB_REC(math_call IRCALL_acos)\nLJLIB_ASM_(math_atan)\t\tLJLIB_REC(math_call IRCALL_atan)\nLJLIB_ASM_(math_sinh)\t\tLJLIB_REC(math_call IRCALL_sinh)\nLJLIB_ASM_(math_cosh)\t\tLJLIB_REC(math_call IRCALL_cosh)\nLJLIB_ASM_(math_tanh)\t\tLJLIB_REC(math_call IRCALL_tanh)\nLJLIB_ASM_(math_frexp)\nLJLIB_ASM_(math_modf)\n\nLJLIB_ASM(math_log)\t\tLJLIB_REC(math_log)\n{\n  double x = lj_lib_checknum(L, 1);\n  if (L->base+1 < L->top) {\n    double y = lj_lib_checknum(L, 2);\n#ifdef LUAJIT_NO_LOG2\n    x = log(x); y = 1.0 / log(y);\n#else\n    x = lj_vm_log2(x); y = 1.0 / lj_vm_log2(y);\n#endif\n    setnumV(L->base-1-LJ_FR2, x*y);  /* Do NOT join the expression to x / y. */\n    return FFH_RES(1);\n  }\n  return FFH_RETRY;\n}\n\nLJLIB_LUA(math_deg) /* function(x) return x * 57.29577951308232 end */\nLJLIB_LUA(math_rad) /* function(x) return x * 0.017453292519943295 end */\n\nLJLIB_ASM(math_atan2)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknum(L, 1);\n  lj_lib_checknum(L, 2);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_pow)\t\tLJLIB_REC(.)\nLJLIB_ASM_(math_fmod)\n\nLJLIB_ASM(math_ldexp)\t\tLJLIB_REC(.)\n{\n  lj_lib_checknum(L, 1);\n#if LJ_DUALNUM && !LJ_TARGET_X86ORX64\n  lj_lib_checkint(L, 2);\n#else\n  lj_lib_checknum(L, 2);\n#endif\n  return FFH_RETRY;\n}\n\nLJLIB_ASM(math_min)\t\tLJLIB_REC(math_minmax IR_MIN)\n{\n  int i = 0;\n  do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(math_max)\t\tLJLIB_REC(math_minmax IR_MAX)\n\nLJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi)\nLJLIB_PUSH(1e310) LJLIB_SET(huge)\n\n/* ------------------------------------------------------------------------ */\n\n/* This implements a Tausworthe PRNG with period 2^223. Based on:\n**   Tables of maximally-equidistributed combined LFSR generators,\n**   Pierre L'Ecuyer, 1991, table 3, 1st entry.\n** Full-period ME-CF generator with L=64, J=4, k=223, N1=49.\n*/\n\n/* Union needed for bit-pattern conversion between uint64_t and double. */\ntypedef union { uint64_t u64; double d; } U64double;\n\n/* PRNG seeding function. */\nstatic void random_seed(PRNGState *rs, double d)\n{\n  uint32_t r = 0x11090601;  /* 64-k[i] as four 8 bit constants. */\n  int i;\n  for (i = 0; i < 4; i++) {\n    U64double u;\n    uint32_t m = 1u << (r&255);\n    r >>= 8;\n    u.d = d = d * 3.14159265358979323846 + 2.7182818284590452354;\n    if (u.u64 < m) u.u64 += m;  /* Ensure k[i] MSB of u[i] are non-zero. */\n    rs->u[i] = u.u64;\n  }\n  for (i = 0; i < 10; i++)\n    (void)lj_prng_u64(rs);\n}\n\n/* PRNG extract function. */\nLJLIB_PUSH(top-2)  /* Upvalue holds userdata with PRNGState. */\nLJLIB_CF(math_random)\t\tLJLIB_REC(.)\n{\n  int n = (int)(L->top - L->base);\n  PRNGState *rs = (PRNGState *)(uddata(udataV(lj_lib_upvalue(L, 1))));\n  U64double u;\n  double d;\n  u.u64 = lj_prng_u64d(rs);\n  d = u.d - 1.0;\n  if (n > 0) {\n#if LJ_DUALNUM\n    int isint = 1;\n    double r1;\n    lj_lib_checknumber(L, 1);\n    if (tvisint(L->base)) {\n      r1 = (lua_Number)intV(L->base);\n    } else {\n      isint = 0;\n      r1 = numV(L->base);\n    }\n#else\n    double r1 = lj_lib_checknum(L, 1);\n#endif\n    if (n == 1) {\n      d = lj_vm_floor(d*r1) + 1.0;  /* d is an int in range [1, r1] */\n    } else {\n#if LJ_DUALNUM\n      double r2;\n      lj_lib_checknumber(L, 2);\n      if (tvisint(L->base+1)) {\n\tr2 = (lua_Number)intV(L->base+1);\n      } else {\n\tisint = 0;\n\tr2 = numV(L->base+1);\n      }\n#else\n      double r2 = lj_lib_checknum(L, 2);\n#endif\n      d = lj_vm_floor(d*(r2-r1+1.0)) + r1;  /* d is an int in range [r1, r2] */\n    }\n#if LJ_DUALNUM\n    if (isint) {\n      setintV(L->top-1, lj_num2int(d));\n      return 1;\n    }\n#endif\n  }  /* else: d is a double in range [0, 1] */\n  setnumV(L->top++, d);\n  return 1;\n}\n\n/* PRNG seed function. */\nLJLIB_PUSH(top-2)  /* Upvalue holds userdata with PRNGState. */\nLJLIB_CF(math_randomseed)\n{\n  PRNGState *rs = (PRNGState *)(uddata(udataV(lj_lib_upvalue(L, 1))));\n  random_seed(rs, lj_lib_checknum(L, 1));\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_math(lua_State *L)\n{\n  PRNGState *rs = (PRNGState *)lua_newuserdata(L, sizeof(PRNGState));\n  lj_prng_seed_fixed(rs);\n  LJ_LIB_REG(L, LUA_MATHLIBNAME, math);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_os.c",
    "content": "/*\n** OS library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <time.h>\n\n#define lib_os_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_lib.h\"\n\n#if LJ_TARGET_POSIX\n#include <unistd.h>\n#else\n#include <stdio.h>\n#endif\n\n#if !LJ_TARGET_PSVITA\n#include <locale.h>\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_os\n\nLJLIB_CF(os_execute)\n{\n#if LJ_NO_SYSTEM\n#if LJ_52\n  errno = ENOSYS;\n  return luaL_fileresult(L, 0, NULL);\n#else\n  lua_pushinteger(L, -1);\n  return 1;\n#endif\n#else\n  const char *cmd = luaL_optstring(L, 1, NULL);\n  int stat = system(cmd);\n#if LJ_52\n  if (cmd)\n    return luaL_execresult(L, stat);\n  setboolV(L->top++, 1);\n#else\n  setintV(L->top++, stat);\n#endif\n  return 1;\n#endif\n}\n\nLJLIB_CF(os_remove)\n{\n  const char *filename = luaL_checkstring(L, 1);\n  return luaL_fileresult(L, remove(filename) == 0, filename);\n}\n\nLJLIB_CF(os_rename)\n{\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);\n}\n\nLJLIB_CF(os_tmpname)\n{\n#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n  lj_err_caller(L, LJ_ERR_OSUNIQF);\n  return 0;\n#else\n#if LJ_TARGET_POSIX\n  char buf[15+1];\n  int fp;\n  strcpy(buf, \"/tmp/lua_XXXXXX\");\n  fp = mkstemp(buf);\n  if (fp != -1)\n    close(fp);\n  else\n    lj_err_caller(L, LJ_ERR_OSUNIQF);\n#else\n  char buf[L_tmpnam];\n  if (tmpnam(buf) == NULL)\n    lj_err_caller(L, LJ_ERR_OSUNIQF);\n#endif\n  lua_pushstring(L, buf);\n  return 1;\n#endif\n}\n\nLJLIB_CF(os_getenv)\n{\n#if LJ_TARGET_CONSOLE\n  lua_pushnil(L);\n#else\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n#endif\n  return 1;\n}\n\nLJLIB_CF(os_exit)\n{\n  int status;\n  if (L->base < L->top && tvisbool(L->base))\n    status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE;\n  else\n    status = lj_lib_optint(L, 1, EXIT_SUCCESS);\n  if (L->base+1 < L->top && tvistruecond(L->base+1))\n    lua_close(L);\n  exit(status);\n  return 0;  /* Unreachable. */\n}\n\nLJLIB_CF(os_clock)\n{\n  setnumV(L->top++, ((lua_Number)clock())*(1.0/(lua_Number)CLOCKS_PER_SEC));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void setfield(lua_State *L, const char *key, int value)\n{\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield(lua_State *L, const char *key, int value)\n{\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic int getboolfield(lua_State *L, const char *key)\n{\n  int res;\n  lua_getfield(L, -1, key);\n  res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\nstatic int getfield(lua_State *L, const char *key, int d)\n{\n  int res;\n  lua_getfield(L, -1, key);\n  if (lua_isnumber(L, -1)) {\n    res = (int)lua_tointeger(L, -1);\n  } else {\n    if (d < 0)\n      lj_err_callerv(L, LJ_ERR_OSDATEF, key);\n    res = d;\n  }\n  lua_pop(L, 1);\n  return res;\n}\n\nLJLIB_CF(os_date)\n{\n  const char *s = luaL_optstring(L, 1, \"%c\");\n  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));\n  struct tm *stm;\n#if LJ_TARGET_POSIX\n  struct tm rtm;\n#endif\n  if (*s == '!') {  /* UTC? */\n    s++;  /* Skip '!' */\n#if LJ_TARGET_POSIX\n    stm = gmtime_r(&t, &rtm);\n#else\n    stm = gmtime(&t);\n#endif\n  } else {\n#if LJ_TARGET_POSIX\n    stm = localtime_r(&t, &rtm);\n#else\n    stm = localtime(&t);\n#endif\n  }\n  if (stm == NULL) {  /* Invalid date? */\n    setnilV(L->top++);\n  } else if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setfield(L, \"sec\", stm->tm_sec);\n    setfield(L, \"min\", stm->tm_min);\n    setfield(L, \"hour\", stm->tm_hour);\n    setfield(L, \"day\", stm->tm_mday);\n    setfield(L, \"month\", stm->tm_mon+1);\n    setfield(L, \"year\", stm->tm_year+1900);\n    setfield(L, \"wday\", stm->tm_wday+1);\n    setfield(L, \"yday\", stm->tm_yday+1);\n    setboolfield(L, \"isdst\", stm->tm_isdst);\n  } else if (*s) {\n    SBuf *sb = &G(L)->tmpbuf;\n    MSize sz = 0, retry = 4;\n    const char *q;\n    for (q = s; *q; q++)\n      sz += (*q == '%') ? 30 : 1;  /* Overflow doesn't matter. */\n    setsbufL(sb, L);\n    while (retry--) {  /* Limit growth for invalid format or empty result. */\n      char *buf = lj_buf_need(sb, sz);\n      size_t len = strftime(buf, sbufsz(sb), s, stm);\n      if (len) {\n\tsetstrV(L, L->top++, lj_str_new(L, buf, len));\n\tlj_gc_check(L);\n\tbreak;\n      }\n      sz += (sz|1);\n    }\n  } else {\n    setstrV(L, L->top++, &G(L)->strempty);\n  }\n  return 1;\n}\n\nLJLIB_CF(os_time)\n{\n  time_t t;\n  if (lua_isnoneornil(L, 1)) {  /* called without args? */\n    t = time(NULL);  /* get current time */\n  } else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0);\n    ts.tm_min = getfield(L, \"min\", 0);\n    ts.tm_hour = getfield(L, \"hour\", 12);\n    ts.tm_mday = getfield(L, \"day\", -1);\n    ts.tm_mon = getfield(L, \"month\", -1) - 1;\n    ts.tm_year = getfield(L, \"year\", -1) - 1900;\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n  }\n  if (t == (time_t)(-1))\n    lua_pushnil(L);\n  else\n    lua_pushnumber(L, (lua_Number)t);\n  return 1;\n}\n\nLJLIB_CF(os_difftime)\n{\n  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),\n\t\t\t     (time_t)(luaL_optnumber(L, 2, (lua_Number)0))));\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(os_setlocale)\n{\n#if LJ_TARGET_PSVITA\n  lua_pushliteral(L, \"C\");\n#else\n  GCstr *s = lj_lib_optstr(L, 1);\n  const char *str = s ? strdata(s) : NULL;\n  int opt = lj_lib_checkopt(L, 2, 6,\n    \"\\5ctype\\7numeric\\4time\\7collate\\10monetary\\1\\377\\3all\");\n  if (opt == 0) opt = LC_CTYPE;\n  else if (opt == 1) opt = LC_NUMERIC;\n  else if (opt == 2) opt = LC_TIME;\n  else if (opt == 3) opt = LC_COLLATE;\n  else if (opt == 4) opt = LC_MONETARY;\n  else if (opt == 6) opt = LC_ALL;\n  lua_pushstring(L, setlocale(opt, str));\n#endif\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_os(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_OSLIBNAME, os);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_package.c",
    "content": "/*\n** Package library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_package_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Error codes for ll_loadfunc. */\n#define PACKAGE_ERR_LIB\t\t1\n#define PACKAGE_ERR_FUNC\t2\n#define PACKAGE_ERR_LOAD\t3\n\n/* Redefined in platform specific part. */\n#define PACKAGE_LIB_FAIL\t\"open\"\n#define setprogdir(L)\t\t((void)0)\n\n/* Symbol name prefixes. */\n#define SYMPREFIX_CF\t\t\"luaopen_%s\"\n#define SYMPREFIX_BC\t\t\"luaJIT_BC_%s\"\n\n#if LJ_TARGET_DLOPEN\n\n#include <dlfcn.h>\n\nstatic void ll_unloadlib(void *lib)\n{\n  dlclose(lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL));\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  lua_CFunction f = (lua_CFunction)dlsym(lib, sym);\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n#if defined(RTLD_DEFAULT)\n  if (lib == NULL) lib = RTLD_DEFAULT;\n#elif LJ_TARGET_OSX || LJ_TARGET_BSD\n  if (lib == NULL) lib = (void *)(intptr_t)-2;\n#endif\n  return (const char *)dlsym(lib, sym);\n}\n\n#elif LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\n#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS  4\n#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT  2\nBOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);\n#endif\n\n#if LJ_TARGET_UWP\nvoid *LJ_WIN_LOADLIBA(const char *path)\n{\n  DWORD err = GetLastError();\n  wchar_t wpath[256];\n  HANDLE lib = NULL;\n  if (MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, 256) > 0) {\n    lib = LoadPackagedLibrary(wpath, 0);\n  }\n  SetLastError(err);\n  return lib;\n}\n#endif\n\n#undef setprogdir\n\nstatic void setprogdir(lua_State *L)\n{\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL) {\n    luaL_error(L, \"unable to get ModuleFileName\");\n  } else {\n    *lb = '\\0';\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\nstatic void pusherror(lua_State *L)\n{\n  DWORD error = GetLastError();\n#if LJ_TARGET_XBOXONE\n  wchar_t wbuffer[128];\n  char buffer[128*2];\n  if (FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, wbuffer, sizeof(wbuffer)/sizeof(wchar_t), NULL) &&\n      WideCharToMultiByte(CP_ACP, 0, wbuffer, 128, buffer, 128*2, NULL, NULL))\n#else\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer), NULL))\n#endif\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void ll_unloadlib(void *lib)\n{\n  FreeLibrary((HINSTANCE)lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  HINSTANCE lib = LJ_WIN_LOADLIBA(path);\n  if (lib == NULL) pusherror(L);\n  UNUSED(gl);\n  return lib;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n#if LJ_TARGET_UWP\nEXTERN_C IMAGE_DOS_HEADER __ImageBase;\n#endif\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n  if (lib) {\n    return (const char *)GetProcAddress((HINSTANCE)lib, sym);\n  } else {\n#if LJ_TARGET_UWP\n    return (const char *)GetProcAddress((HINSTANCE)&__ImageBase, sym);\n#else\n    HINSTANCE h = GetModuleHandleA(NULL);\n    const char *p = (const char *)GetProcAddress(h, sym);\n    if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t\t\t(const char *)ll_bcsym, &h))\n      p = (const char *)GetProcAddress(h, sym);\n    return p;\n#endif\n  }\n}\n\n#else\n\n#undef PACKAGE_LIB_FAIL\n#define PACKAGE_LIB_FAIL\t\"absent\"\n\n#define DLMSG\t\"dynamic libraries not enabled; no support for target OS\"\n\nstatic void ll_unloadlib(void *lib)\n{\n  UNUSED(lib);\n}\n\nstatic void *ll_load(lua_State *L, const char *path, int gl)\n{\n  UNUSED(path); UNUSED(gl);\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\nstatic lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)\n{\n  UNUSED(lib); UNUSED(sym);\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\nstatic const char *ll_bcsym(void *lib, const char *sym)\n{\n  UNUSED(lib); UNUSED(sym);\n  return NULL;\n}\n\n#endif\n\n/* ------------------------------------------------------------------------ */\n\nstatic void **ll_register(lua_State *L, const char *path)\n{\n  void **plib;\n  lua_pushfstring(L, \"LOADLIB: %s\", path);\n  lua_gettable(L, LUA_REGISTRYINDEX);  /* check library in registry? */\n  if (!lua_isnil(L, -1)) {  /* is there an entry? */\n    plib = (void **)lua_touserdata(L, -1);\n  } else {  /* no entry yet; create one */\n    lua_pop(L, 1);\n    plib = (void **)lua_newuserdata(L, sizeof(void *));\n    *plib = NULL;\n    luaL_setmetatable(L, \"_LOADLIB\");\n    lua_pushfstring(L, \"LOADLIB: %s\", path);\n    lua_pushvalue(L, -2);\n    lua_settable(L, LUA_REGISTRYINDEX);\n  }\n  return plib;\n}\n\nstatic const char *mksymname(lua_State *L, const char *modname,\n\t\t\t     const char *prefix)\n{\n  const char *funcname;\n  const char *mark = strchr(modname, *LUA_IGMARK);\n  if (mark) modname = mark + 1;\n  funcname = luaL_gsub(L, modname, \".\", \"_\");\n  funcname = lua_pushfstring(L, prefix, funcname);\n  lua_remove(L, -2);  /* remove 'gsub' result */\n  return funcname;\n}\n\nstatic int ll_loadfunc(lua_State *L, const char *path, const char *name, int r)\n{\n  void **reg;\n  if (strlen(path) >= 4096) {\n    lua_pushliteral(L, \"path too long\");\n    return PACKAGE_ERR_LIB;\n  }\n  reg = ll_register(L, path);\n  if (*reg == NULL) *reg = ll_load(L, path, (*name == '*'));\n  if (*reg == NULL) {\n    return PACKAGE_ERR_LIB;  /* Unable to load library. */\n  } else if (*name == '*') {  /* Only load library into global namespace. */\n    lua_pushboolean(L, 1);\n    return 0;\n  } else {\n    const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF);\n    lua_CFunction f = ll_sym(L, *reg, sym);\n    if (f) {\n      lua_pushcfunction(L, f);\n      return 0;\n    }\n    if (!r) {\n      const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC));\n      lua_pop(L, 1);\n      if (bcdata) {\n\tif (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0)\n\t  return PACKAGE_ERR_LOAD;\n\treturn 0;\n      }\n    }\n    return PACKAGE_ERR_FUNC;  /* Unable to find function. */\n  }\n}\n\nstatic int lj_cf_package_loadlib(lua_State *L)\n{\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int st = ll_loadfunc(L, path, init, 1);\n  if (st == 0) {  /* no errors? */\n    return 1;  /* return the loaded function */\n  } else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (st == PACKAGE_ERR_LIB) ?  PACKAGE_LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\nstatic int lj_cf_package_unloadlib(lua_State *L)\n{\n  void **lib = (void **)luaL_checkudata(L, 1, \"_LOADLIB\");\n  if (*lib) ll_unloadlib(*lib);\n  *lib = NULL;  /* mark library as closed */\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic int readable(const char *filename)\n{\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\nstatic const char *pushnexttemplate(lua_State *L, const char *path)\n{\n  const char *l;\n  while (*path == *LUA_PATHSEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATHSEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, (size_t)(l - path));  /* template */\n  return l;\n}\n\nstatic const char *searchpath (lua_State *L, const char *name,\n\t\t\t       const char *path, const char *sep,\n\t\t\t       const char *dirsep)\n{\n  luaL_Buffer msg;  /* to build error message */\n  luaL_buffinit(L, &msg);\n  if (*sep != '\\0')  /* non-empty separator? */\n    name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename = luaL_gsub(L, lua_tostring(L, -1),\n\t\t\t\t     LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file \" LUA_QS, filename);\n    lua_remove(L, -2);  /* remove file name */\n    luaL_addvalue(&msg);  /* concatenate error msg. entry */\n  }\n  luaL_pushresult(&msg);  /* create error message */\n  return NULL;  /* not found */\n}\n\nstatic int lj_cf_package_searchpath(lua_State *L)\n{\n  const char *f = searchpath(L, luaL_checkstring(L, 1),\n\t\t\t\tluaL_checkstring(L, 2),\n\t\t\t\tluaL_optstring(L, 3, \".\"),\n\t\t\t\tluaL_optstring(L, 4, LUA_DIRSEP));\n  if (f != NULL) {\n    return 1;\n  } else {  /* error message is on top of the stack */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    return 2;  /* return nil + error message */\n  }\n}\n\nstatic const char *findfile(lua_State *L, const char *name,\n\t\t\t    const char *pname)\n{\n  const char *path;\n  lua_getfield(L, LUA_ENVIRONINDEX, pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, LUA_QL(\"package.%s\") \" must be a string\", pname);\n  return searchpath(L, name, path, \".\", LUA_DIRSEP);\n}\n\nstatic void loaderror(lua_State *L, const char *filename)\n{\n  luaL_error(L, \"error loading module \" LUA_QS \" from file \" LUA_QS \":\\n\\t%s\",\n\t     lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\nstatic int lj_cf_package_loader_lua(lua_State *L)\n{\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (luaL_loadfile(L, filename) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\nstatic int lj_cf_package_loader_c(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (ll_loadfunc(L, filename, name, 0) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\nstatic int lj_cf_package_loader_croot(lua_State *L)\n{\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int st;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, (size_t)(p - name));\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\");\n  if (filename == NULL) return 1;  /* root not found */\n  if ((st = ll_loadfunc(L, filename, name, 0)) != 0) {\n    if (st != PACKAGE_ERR_FUNC) loaderror(L, filename);  /* real error */\n    lua_pushfstring(L, \"\\n\\tno module \" LUA_QS \" in file \" LUA_QS,\n\t\t    name, filename);\n    return 1;  /* function not found */\n  }\n  return 1;\n}\n\nstatic int lj_cf_package_loader_preload(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_ENVIRONINDEX, \"preload\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.preload\") \" must be a table\");\n  lua_getfield(L, -1, name);\n  if (lua_isnil(L, -1)) {  /* Not found? */\n    const char *bcname = mksymname(L, name, SYMPREFIX_BC);\n    const char *bcdata = ll_bcsym(NULL, bcname);\n    if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0)\n      lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  }\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#define KEY_SENTINEL\t(U64x(80000000,00000000)|'s')\n\nstatic int lj_cf_package_require(lua_State *L)\n{\n  const char *name = luaL_checkstring(L, 1);\n  int i;\n  lua_settop(L, 1);  /* _LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, 2, name);\n  if (lua_toboolean(L, -1)) {  /* is it there? */\n    if ((L->top-1)->u64 == KEY_SENTINEL)  /* check loops */\n      luaL_error(L, \"loop or previous error loading module \" LUA_QS, name);\n    return 1;  /* package is already loaded */\n  }\n  /* else must load it; iterate over available loaders */\n  lua_getfield(L, LUA_ENVIRONINDEX, \"loaders\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.loaders\") \" must be a table\");\n  lua_pushliteral(L, \"\");  /* error message accumulator */\n  for (i = 1; ; i++) {\n    lua_rawgeti(L, -2, i);  /* get a loader */\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"module \" LUA_QS \" not found:%s\",\n\t\t name, lua_tostring(L, -2));\n    lua_pushstring(L, name);\n    lua_call(L, 1, 1);  /* call it */\n    if (lua_isfunction(L, -1))  /* did it find module? */\n      break;  /* module loaded successfully */\n    else if (lua_isstring(L, -1))  /* loader returned error message? */\n      lua_concat(L, 2);  /* accumulate it */\n    else\n      lua_pop(L, 1);\n  }\n  (L->top++)->u64 = KEY_SENTINEL;\n  lua_setfield(L, 2, name);  /* _LOADED[name] = sentinel */\n  lua_pushstring(L, name);  /* pass name as argument to module */\n  lua_call(L, 1, 1);  /* run loaded module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  lua_getfield(L, 2, name);\n  if ((L->top-1)->u64 == KEY_SENTINEL) {   /* module did not set a value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  lj_lib_checkfpu(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void setfenv(lua_State *L)\n{\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, LUA_QL(\"module\") \" not called from a Lua function\");\n  lua_pushvalue(L, -2);\n  lua_setfenv(L, -2);\n  lua_pop(L, 1);\n}\n\nstatic void dooptions(lua_State *L, int n)\n{\n  int i;\n  for (i = 2; i <= n; i++) {\n    lua_pushvalue(L, i);  /* get option (a function) */\n    lua_pushvalue(L, -2);  /* module */\n    lua_call(L, 1, 0);\n  }\n}\n\nstatic void modinit(lua_State *L, const char *modname)\n{\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname; else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, (size_t)(dot - modname));\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\nstatic int lj_cf_package_module(lua_State *L)\n{\n  const char *modname = luaL_checkstring(L, 1);\n  int lastarg = (int)(L->top - L->base);\n  luaL_pushmodule(L, modname, 1);\n  lua_getfield(L, -1, \"_NAME\");\n  if (!lua_isnil(L, -1)) {  /* Module already initialized? */\n    lua_pop(L, 1);\n  } else {\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  setfenv(L);\n  dooptions(L, lastarg);\n  return LJ_52;\n}\n\nstatic int lj_cf_package_seeall(lua_State *L)\n{\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#define AUXMARK\t\t\"\\1\"\n\nstatic void setpath(lua_State *L, const char *fieldname, const char *envname,\n\t\t    const char *def, int noenv)\n{\n#if LJ_TARGET_CONSOLE\n  const char *path = NULL;\n  UNUSED(envname);\n#else\n  const char *path = getenv(envname);\n#endif\n  if (path == NULL || noenv) {\n    lua_pushstring(L, def);\n  } else {\n    path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,\n\t\t\t      LUA_PATHSEP AUXMARK LUA_PATHSEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\nstatic const luaL_Reg package_lib[] = {\n  { \"loadlib\",\tlj_cf_package_loadlib },\n  { \"searchpath\",  lj_cf_package_searchpath },\n  { \"seeall\",\tlj_cf_package_seeall },\n  { NULL, NULL }\n};\n\nstatic const luaL_Reg package_global[] = {\n  { \"module\",\tlj_cf_package_module },\n  { \"require\",\tlj_cf_package_require },\n  { NULL, NULL }\n};\n\nstatic const lua_CFunction package_loaders[] =\n{\n  lj_cf_package_loader_preload,\n  lj_cf_package_loader_lua,\n  lj_cf_package_loader_c,\n  lj_cf_package_loader_croot,\n  NULL\n};\n\nLUALIB_API int luaopen_package(lua_State *L)\n{\n  int i;\n  int noenv;\n  luaL_newmetatable(L, \"_LOADLIB\");\n  lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);\n  lua_setfield(L, -2, \"__gc\");\n  luaL_register(L, LUA_LOADLIBNAME, package_lib);\n  lua_copy(L, -1, LUA_ENVIRONINDEX);\n  lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0);\n  for (i = 0; package_loaders[i] != NULL; i++) {\n    lj_lib_pushcf(L, package_loaders[i], 1);\n    lua_rawseti(L, -2, i+1);\n  }\n#if LJ_52\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -3, \"searchers\");\n#endif\n  lua_setfield(L, -2, \"loaders\");\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  noenv = lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  setpath(L, \"path\", LUA_PATH, LUA_PATH_DEFAULT, noenv);\n  setpath(L, \"cpath\", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);\n  lua_pushliteral(L, LUA_PATH_CONFIG);\n  lua_setfield(L, -2, \"config\");\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n  lua_setfield(L, -2, \"loaded\");\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\", 4);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  luaL_register(L, NULL, package_global);\n  lua_pop(L, 1);\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_string.c",
    "content": "/*\n** String library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_string_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_ff.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_char.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_string\n\nLJLIB_LUA(string_len) /*\n  function(s)\n    CHECK_str(s)\n    return #s\n  end\n*/\n\nLJLIB_ASM(string_byte)\t\tLJLIB_REC(string_range 0)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int32_t len = (int32_t)s->len;\n  int32_t start = lj_lib_optint(L, 2, 1);\n  int32_t stop = lj_lib_optint(L, 3, start);\n  int32_t n, i;\n  const unsigned char *p;\n  if (stop < 0) stop += len+1;\n  if (start < 0) start += len+1;\n  if (start <= 0) start = 1;\n  if (stop > len) stop = len;\n  if (start > stop) return FFH_RES(0);  /* Empty interval: return no results. */\n  start--;\n  n = stop - start;\n  if ((uint32_t)n > LUAI_MAXCSTACK)\n    lj_err_caller(L, LJ_ERR_STRSLC);\n  lj_state_checkstack(L, (MSize)n);\n  p = (const unsigned char *)strdata(s) + start;\n  for (i = 0; i < n; i++)\n    setintV(L->base + i-1-LJ_FR2, p[i]);\n  return FFH_RES(n);\n}\n\nLJLIB_ASM(string_char)\t\tLJLIB_REC(.)\n{\n  int i, nargs = (int)(L->top - L->base);\n  char *buf = lj_buf_tmp(L, (MSize)nargs);\n  for (i = 1; i <= nargs; i++) {\n    int32_t k = lj_lib_checkint(L, i);\n    if (!checku8(k))\n      lj_err_arg(L, i, LJ_ERR_BADVAL);\n    buf[i-1] = (char)k;\n  }\n  setstrV(L, L->base-1-LJ_FR2, lj_str_new(L, buf, (size_t)nargs));\n  return FFH_RES(1);\n}\n\nLJLIB_ASM(string_sub)\t\tLJLIB_REC(string_range 1)\n{\n  lj_lib_checkstr(L, 1);\n  lj_lib_checkint(L, 2);\n  setintV(L->base+2, lj_lib_optint(L, 3, -1));\n  return FFH_RETRY;\n}\n\nLJLIB_CF(string_rep)\t\tLJLIB_REC(.)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  int32_t rep = lj_lib_checkint(L, 2);\n  GCstr *sep = lj_lib_optstr(L, 3);\n  SBuf *sb = lj_buf_tmp_(L);\n  if (sep && rep > 1) {\n    GCstr *s2 = lj_buf_cat2str(L, sep, s);\n    lj_buf_reset(sb);\n    lj_buf_putstr(sb, s);\n    s = s2;\n    rep--;\n  }\n  sb = lj_buf_putstr_rep(sb, s, rep);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\nLJLIB_ASM(string_reverse)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_reverse)\n{\n  lj_lib_checkstr(L, 1);\n  return FFH_RETRY;\n}\nLJLIB_ASM_(string_lower)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_lower)\nLJLIB_ASM_(string_upper)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_upper)\n\n/* ------------------------------------------------------------------------ */\n\nstatic int writer_buf(lua_State *L, const void *p, size_t size, void *sb)\n{\n  lj_buf_putmem((SBuf *)sb, p, (MSize)size);\n  UNUSED(L);\n  return 0;\n}\n\nLJLIB_CF(string_dump)\n{\n  GCfunc *fn = lj_lib_checkfunc(L, 1);\n  int strip = L->base+1 < L->top && tvistruecond(L->base+1);\n  SBuf *sb = lj_buf_tmp_(L);  /* Assumes lj_bcwrite() doesn't use tmpbuf. */\n  L->top = L->base+1;\n  if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, sb, strip))\n    lj_err_caller(L, LJ_ERR_STRDUMP);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* macro to `unsign' a character */\n#define uchar(c)\t((unsigned char)(c))\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end (`\\0') of source string */\n  lua_State *L;\n  int level;  /* total number of captures (finished or unfinished) */\n  int depth;\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n#define L_ESC\t\t'%'\n\nstatic int check_capture(MatchState *ms, int l)\n{\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    lj_err_caller(ms->L, LJ_ERR_STRCAPI);\n  return l;\n}\n\nstatic int capture_to_close(MatchState *ms)\n{\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  lj_err_caller(ms->L, LJ_ERR_STRPATC);\n  return 0;  /* unreachable */\n}\n\nstatic const char *classend(MatchState *ms, const char *p)\n{\n  switch (*p++) {\n  case L_ESC:\n    if (*p == '\\0')\n      lj_err_caller(ms->L, LJ_ERR_STRPATE);\n    return p+1;\n  case '[':\n    if (*p == '^') p++;\n    do {  /* look for a `]' */\n      if (*p == '\\0')\n\tlj_err_caller(ms->L, LJ_ERR_STRPATM);\n      if (*(p++) == L_ESC && *p != '\\0')\n\tp++;  /* skip escapes (e.g. `%]') */\n    } while (*p != ']');\n    return p+1;\n  default:\n    return p;\n  }\n}\n\nstatic const unsigned char match_class_map[32] = {\n  0,LJ_CHAR_ALPHA,0,LJ_CHAR_CNTRL,LJ_CHAR_DIGIT,0,0,LJ_CHAR_GRAPH,0,0,0,0,\n  LJ_CHAR_LOWER,0,0,0,LJ_CHAR_PUNCT,0,0,LJ_CHAR_SPACE,0,\n  LJ_CHAR_UPPER,0,LJ_CHAR_ALNUM,LJ_CHAR_XDIGIT,0,0,0,0,0,0,0\n};\n\nstatic int match_class(int c, int cl)\n{\n  if ((cl & 0xc0) == 0x40) {\n    int t = match_class_map[(cl&0x1f)];\n    if (t) {\n      t = lj_char_isa(c, t);\n      return (cl & 0x20) ? t : !t;\n    }\n    if (cl == 'z') return c == 0;\n    if (cl == 'Z') return c != 0;\n  }\n  return (cl == c);\n}\n\nstatic int matchbracketclass(int c, const char *p, const char *ec)\n{\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the `^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n\treturn sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n\treturn sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\nstatic int singlematch(int c, const char *p, const char *ep)\n{\n  switch (*p) {\n  case '.': return 1;  /* matches any char */\n  case L_ESC: return match_class(c, uchar(*(p+1)));\n  case '[': return matchbracketclass(c, p, ep-1);\n  default:  return (uchar(*p) == c);\n  }\n}\n\nstatic const char *match(MatchState *ms, const char *s, const char *p);\n\nstatic const char *matchbalance(MatchState *ms, const char *s, const char *p)\n{\n  if (*p == 0 || *(p+1) == 0)\n    lj_err_caller(ms->L, LJ_ERR_STRPATU);\n  if (*s != *p) {\n    return NULL;\n  } else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n\tif (--cont == 0) return s+1;\n      } else if (*s == b) {\n\tcont++;\n      }\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\nstatic const char *max_expand(MatchState *ms, const char *s,\n\t\t\t      const char *p, const char *ep)\n{\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\nstatic const char *min_expand(MatchState *ms, const char *s,\n\t\t\t      const char *p, const char *ep)\n{\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (s<ms->src_end && singlematch(uchar(*s), p, ep))\n      s++;  /* try with one more repetition */\n    else\n      return NULL;\n  }\n}\n\nstatic const char *start_capture(MatchState *ms, const char *s,\n\t\t\t\t const char *p, int what)\n{\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) lj_err_caller(ms->L, LJ_ERR_STRCAPN);\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\nstatic const char *end_capture(MatchState *ms, const char *s,\n\t\t\t       const char *p)\n{\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\nstatic const char *match_capture(MatchState *ms, const char *s, int l)\n{\n  size_t len;\n  l = check_capture(ms, l);\n  len = (size_t)ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else\n    return NULL;\n}\n\nstatic const char *match(MatchState *ms, const char *s, const char *p)\n{\n  if (++ms->depth > LJ_MAX_XLEVEL)\n    lj_err_caller(ms->L, LJ_ERR_STRPATX);\n  init: /* using goto's to optimize tail recursion */\n  switch (*p) {\n  case '(':  /* start capture */\n    if (*(p+1) == ')')  /* position capture? */\n      s = start_capture(ms, s, p+2, CAP_POSITION);\n    else\n      s = start_capture(ms, s, p+1, CAP_UNFINISHED);\n    break;\n  case ')':  /* end capture */\n    s = end_capture(ms, s, p+1);\n    break;\n  case L_ESC:\n    switch (*(p+1)) {\n    case 'b':  /* balanced string? */\n      s = matchbalance(ms, s, p+2);\n      if (s == NULL) break;\n      p+=4;\n      goto init;  /* else s = match(ms, s, p+4); */\n    case 'f': {  /* frontier? */\n      const char *ep; char previous;\n      p += 2;\n      if (*p != '[')\n\tlj_err_caller(ms->L, LJ_ERR_STRPATB);\n      ep = classend(ms, p);  /* points to what is next */\n      previous = (s == ms->src_init) ? '\\0' : *(s-1);\n      if (matchbracketclass(uchar(previous), p, ep-1) ||\n\t !matchbracketclass(uchar(*s), p, ep-1)) { s = NULL; break; }\n      p=ep;\n      goto init;  /* else s = match(ms, s, ep); */\n      }\n    default:\n      if (lj_char_isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */\n\ts = match_capture(ms, s, uchar(*(p+1)));\n\tif (s == NULL) break;\n\tp+=2;\n\tgoto init;  /* else s = match(ms, s, p+2) */\n      }\n      goto dflt;  /* case default */\n    }\n    break;\n  case '\\0':  /* end of pattern */\n    break;  /* match succeeded */\n  case '$':\n    /* is the `$' the last char in pattern? */\n    if (*(p+1) != '\\0') goto dflt;\n    if (s != ms->src_end) s = NULL;  /* check end of string */\n    break;\n  default: dflt: {  /* it is a pattern item */\n    const char *ep = classend(ms, p);  /* points to what is next */\n    int m = s<ms->src_end && singlematch(uchar(*s), p, ep);\n    switch (*ep) {\n    case '?': {  /* optional */\n      const char *res;\n      if (m && ((res=match(ms, s+1, ep+1)) != NULL)) {\n\ts = res;\n\tbreak;\n      }\n      p=ep+1;\n      goto init;  /* else s = match(ms, s, ep+1); */\n      }\n    case '*':  /* 0 or more repetitions */\n      s = max_expand(ms, s, p, ep);\n      break;\n    case '+':  /* 1 or more repetitions */\n      s = (m ? max_expand(ms, s+1, p, ep) : NULL);\n      break;\n    case '-':  /* 0 or more repetitions (minimum) */\n      s = min_expand(ms, s, p, ep);\n      break;\n    default:\n      if (m) { s++; p=ep; goto init; }  /* else s = match(ms, s+1, ep); */\n      s = NULL;\n      break;\n    }\n    break;\n    }\n  }\n  ms->depth--;\n  return s;\n}\n\nstatic void push_onecapture(MatchState *ms, int i, const char *s, const char *e)\n{\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, (size_t)(e - s));  /* add whole match */\n    else\n      lj_err_caller(ms->L, LJ_ERR_STRCAPI);\n  } else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) lj_err_caller(ms->L, LJ_ERR_STRCAPU);\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, (size_t)l);\n  }\n}\n\nstatic int push_captures(MatchState *ms, const char *s, const char *e)\n{\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\nstatic int str_find_aux(lua_State *L, int find)\n{\n  GCstr *s = lj_lib_checkstr(L, 1);\n  GCstr *p = lj_lib_checkstr(L, 2);\n  int32_t start = lj_lib_optint(L, 3, 1);\n  MSize st;\n  if (start < 0) start += (int32_t)s->len; else start--;\n  if (start < 0) start = 0;\n  st = (MSize)start;\n  if (st > s->len) {\n#if LJ_52\n    setnilV(L->top-1);\n    return 1;\n#else\n    st = s->len;\n#endif\n  }\n  if (find && ((L->base+3 < L->top && tvistruecond(L->base+3)) ||\n\t       !lj_str_haspattern(p))) {  /* Search for fixed string. */\n    const char *q = lj_str_find(strdata(s)+st, strdata(p), s->len-st, p->len);\n    if (q) {\n      setintV(L->top-2, (int32_t)(q-strdata(s)) + 1);\n      setintV(L->top-1, (int32_t)(q-strdata(s)) + (int32_t)p->len);\n      return 2;\n    }\n  } else {  /* Search for pattern. */\n    MatchState ms;\n    const char *pstr = strdata(p);\n    const char *sstr = strdata(s) + st;\n    int anchor = 0;\n    if (*pstr == '^') { pstr++; anchor = 1; }\n    ms.L = L;\n    ms.src_init = strdata(s);\n    ms.src_end = strdata(s) + s->len;\n    do {  /* Loop through string and try to match the pattern. */\n      const char *q;\n      ms.level = ms.depth = 0;\n      q = match(&ms, sstr, pstr);\n      if (q) {\n\tif (find) {\n\t  setintV(L->top++, (int32_t)(sstr-(strdata(s)-1)));\n\t  setintV(L->top++, (int32_t)(q-strdata(s)));\n\t  return push_captures(&ms, NULL, NULL) + 2;\n\t} else {\n\t  return push_captures(&ms, sstr, q);\n\t}\n      }\n    } while (sstr++ < ms.src_end && !anchor);\n  }\n  setnilV(L->top-1);  /* Not found. */\n  return 1;\n}\n\nLJLIB_CF(string_find)\t\tLJLIB_REC(.)\n{\n  return str_find_aux(L, 1);\n}\n\nLJLIB_CF(string_match)\n{\n  return str_find_aux(L, 0);\n}\n\nLJLIB_NOREG LJLIB_CF(string_gmatch_aux)\n{\n  const char *p = strVdata(lj_lib_upvalue(L, 2));\n  GCstr *str = strV(lj_lib_upvalue(L, 1));\n  const char *s = strdata(str);\n  TValue *tvpos = lj_lib_upvalue(L, 3);\n  const char *src = s + tvpos->u32.lo;\n  MatchState ms;\n  ms.L = L;\n  ms.src_init = s;\n  ms.src_end = s + str->len;\n  for (; src <= ms.src_end; src++) {\n    const char *e;\n    ms.level = ms.depth = 0;\n    if ((e = match(&ms, src, p)) != NULL) {\n      int32_t pos = (int32_t)(e - s);\n      if (e == src) pos++;  /* Ensure progress for empty match. */\n      tvpos->u32.lo = (uint32_t)pos;\n      return push_captures(&ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\nLJLIB_CF(string_gmatch)\n{\n  lj_lib_checkstr(L, 1);\n  lj_lib_checkstr(L, 2);\n  L->top = L->base+3;\n  (L->top-1)->u64 = 0;\n  lj_lib_pushcc(L, lj_cf_string_gmatch_aux, FF_string_gmatch_aux, 3);\n  return 1;\n}\n\nstatic void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)\n{\n  size_t l, i;\n  const char *news = lua_tolstring(ms->L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC) {\n      luaL_addchar(b, news[i]);\n    } else {\n      i++;  /* skip ESC */\n      if (!lj_char_isdigit(uchar(news[i]))) {\n\tluaL_addchar(b, news[i]);\n      } else if (news[i] == '0') {\n\tluaL_addlstring(b, s, (size_t)(e - s));\n      } else {\n\tpush_onecapture(ms, news[i] - '1', s, e);\n\tluaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\nstatic void add_value(MatchState *ms, luaL_Buffer *b,\n\t\t      const char *s, const char *e)\n{\n  lua_State *L = ms->L;\n  switch (lua_type(L, 3)) {\n    case LUA_TNUMBER:\n    case LUA_TSTRING: {\n      add_s(ms, b, s, e);\n      return;\n    }\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, (size_t)(e - s));  /* keep original text */\n  } else if (!lua_isstring(L, -1)) {\n    lj_err_callerv(L, LJ_ERR_STRGSRV, luaL_typename(L, -1));\n  }\n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\nLJLIB_CF(string_gsub)\n{\n  size_t srcl;\n  const char *src = luaL_checklstring(L, 1, &srcl);\n  const char *p = luaL_checkstring(L, 2);\n  int  tr = lua_type(L, 3);\n  int max_s = luaL_optint(L, 4, (int)(srcl+1));\n  int anchor = (*p == '^') ? (p++, 1) : 0;\n  int n = 0;\n  MatchState ms;\n  luaL_Buffer b;\n  if (!(tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n\ttr == LUA_TFUNCTION || tr == LUA_TTABLE))\n    lj_err_arg(L, 3, LJ_ERR_NOSFT);\n  luaL_buffinit(L, &b);\n  ms.L = L;\n  ms.src_init = src;\n  ms.src_end = src+srcl;\n  while (n < max_s) {\n    const char *e;\n    ms.level = ms.depth = 0;\n    e = match(&ms, src, p);\n    if (e) {\n      n++;\n      add_value(&ms, &b, src, e);\n    }\n    if (e && e>src) /* non empty match? */\n      src = e;  /* skip it */\n    else if (src < ms.src_end)\n      luaL_addchar(&b, *src++);\n    else\n      break;\n    if (anchor)\n      break;\n  }\n  luaL_addlstring(&b, src, (size_t)(ms.src_end-src));\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* ------------------------------------------------------------------------ */\n\nLJLIB_CF(string_format)\t\tLJLIB_REC(.)\n{\n  int retry = 0;\n  SBuf *sb;\n  do {\n    sb = lj_buf_tmp_(L);\n    retry = lj_strfmt_putarg(L, sb, 1, -retry);\n  } while (retry > 0);\n  setstrV(L, L->top-1, lj_buf_str(L, sb));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_string(lua_State *L)\n{\n  GCtab *mt;\n  global_State *g;\n  LJ_LIB_REG(L, LUA_STRLIBNAME, string);\n  mt = lj_tab_new(L, 0, 1);\n  /* NOBARRIER: basemt is a GC root. */\n  g = G(L);\n  setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt));\n  settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1));\n  mt->nomm = (uint8_t)(~(1u<<MM_index));\n#if LJ_HASBUFFER\n  lj_lib_prereg(L, LUA_STRLIBNAME \".buffer\", luaopen_string_buffer, tabV(L->top-1));\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lib_table.c",
    "content": "/*\n** Table library.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lib_table_c\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_tab.h\"\n#include \"lj_ff.h\"\n#include \"lj_lib.h\"\n\n/* ------------------------------------------------------------------------ */\n\n#define LJLIB_MODULE_table\n\nLJLIB_LUA(table_foreachi) /*\n  function(t, f)\n    CHECK_tab(t)\n    CHECK_func(f)\n    for i=1,#t do\n      local r = f(i, t[i])\n      if r ~= nil then return r end\n    end\n  end\n*/\n\nLJLIB_LUA(table_foreach) /*\n  function(t, f)\n    CHECK_tab(t)\n    CHECK_func(f)\n    for k, v in PAIRS(t) do\n      local r = f(k, v)\n      if r ~= nil then return r end\n    end\n  end\n*/\n\nLJLIB_LUA(table_getn) /*\n  function(t)\n    CHECK_tab(t)\n    return #t\n  end\n*/\n\nLJLIB_CF(table_maxn)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  TValue *array = tvref(t->array);\n  Node *node;\n  lua_Number m = 0;\n  ptrdiff_t i;\n  for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--)\n    if (!tvisnil(&array[i])) {\n      m = (lua_Number)(int32_t)i;\n      break;\n    }\n  node = noderef(t->node);\n  for (i = (ptrdiff_t)t->hmask; i >= 0; i--)\n    if (!tvisnil(&node[i].val) && tvisnumber(&node[i].key)) {\n      lua_Number n = numberVnum(&node[i].key);\n      if (n > m) m = n;\n    }\n  setnumV(L->top-1, m);\n  return 1;\n}\n\nLJLIB_CF(table_insert)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n, i = (int32_t)lj_tab_len(t) + 1;\n  int nargs = (int)((char *)L->top - (char *)L->base);\n  if (nargs != 2*sizeof(TValue)) {\n    if (nargs != 3*sizeof(TValue))\n      lj_err_caller(L, LJ_ERR_TABINS);\n    /* NOBARRIER: This just moves existing elements around. */\n    for (n = lj_lib_checkint(L, 2); i > n; i--) {\n      /* The set may invalidate the get pointer, so need to do it first! */\n      TValue *dst = lj_tab_setint(L, t, i);\n      cTValue *src = lj_tab_getint(t, i-1);\n      if (src) {\n\tcopyTV(L, dst, src);\n      } else {\n\tsetnilV(dst);\n      }\n    }\n    i = n;\n  }\n  {\n    TValue *dst = lj_tab_setint(L, t, i);\n    copyTV(L, dst, L->top-1);  /* Set new value. */\n    lj_gc_barriert(L, t, dst);\n  }\n  return 0;\n}\n\nLJLIB_LUA(table_remove) /*\n  function(t, pos)\n    CHECK_tab(t)\n    local len = #t\n    if pos == nil then\n      if len ~= 0 then\n\tlocal old = t[len]\n\tt[len] = nil\n\treturn old\n      end\n    else\n      CHECK_int(pos)\n      if pos >= 1 and pos <= len then\n\tlocal old = t[pos]\n\tfor i=pos+1,len do\n\t  t[i-1] = t[i]\n\tend\n\tt[len] = nil\n\treturn old\n      end\n    end\n  end\n*/\n\nLJLIB_LUA(table_move) /*\n  function(a1, f, e, t, a2)\n    CHECK_tab(a1)\n    CHECK_int(f)\n    CHECK_int(e)\n    CHECK_int(t)\n    if a2 == nil then a2 = a1 end\n    CHECK_tab(a2)\n    if e >= f then\n      local d = t - f\n      if t > e or t <= f or a2 ~= a1 then\n\tfor i=f,e do a2[i+d] = a1[i] end\n      else\n\tfor i=e,f,-1 do a2[i+d] = a1[i] end\n      end\n    end\n    return a2\n  end\n*/\n\nLJLIB_CF(table_concat)\t\tLJLIB_REC(.)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  GCstr *sep = lj_lib_optstr(L, 2);\n  int32_t i = lj_lib_optint(L, 3, 1);\n  int32_t e = (L->base+3 < L->top && !tvisnil(L->base+3)) ?\n\t      lj_lib_checkint(L, 4) : (int32_t)lj_tab_len(t);\n  SBuf *sb = lj_buf_tmp_(L);\n  SBuf *sbx = lj_buf_puttab(sb, t, sep, i, e);\n  if (LJ_UNLIKELY(!sbx)) {  /* Error: bad element type. */\n    int32_t idx = (int32_t)(intptr_t)sb->w;\n    cTValue *o = lj_tab_getint(t, idx);\n    lj_err_callerv(L, LJ_ERR_TABCAT,\n\t\t   lj_obj_itypename[o ? itypemap(o) : ~LJ_TNIL], idx);\n  }\n  setstrV(L, L->top-1, lj_buf_str(L, sbx));\n  lj_gc_check(L);\n  return 1;\n}\n\n/* ------------------------------------------------------------------------ */\n\nstatic void set2(lua_State *L, int i, int j)\n{\n  lua_rawseti(L, 1, i);\n  lua_rawseti(L, 1, j);\n}\n\nstatic int sort_comp(lua_State *L, int a, int b)\n{\n  if (!lua_isnil(L, 2)) {  /* function? */\n    int res;\n    lua_pushvalue(L, 2);\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */\n    lua_call(L, 2, 1);\n    res = lua_toboolean(L, -1);\n    lua_pop(L, 1);\n    return res;\n  } else {  /* a < b? */\n    return lua_lessthan(L, a, b);\n  }\n}\n\nstatic void auxsort(lua_State *L, int l, int u)\n{\n  while (l < u) {  /* for tail recursion */\n    int i, j;\n    /* sort elements a[l], a[(l+u)/2] and a[u] */\n    lua_rawgeti(L, 1, l);\n    lua_rawgeti(L, 1, u);\n    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */\n      set2(L, l, u);  /* swap a[l] - a[u] */\n    else\n      lua_pop(L, 2);\n    if (u-l == 1) break;  /* only 2 elements */\n    i = (l+u)/2;\n    lua_rawgeti(L, 1, i);\n    lua_rawgeti(L, 1, l);\n    if (sort_comp(L, -2, -1)) {  /* a[i]<a[l]? */\n      set2(L, i, l);\n    } else {\n      lua_pop(L, 1);  /* remove a[l] */\n      lua_rawgeti(L, 1, u);\n      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */\n\tset2(L, i, u);\n      else\n\tlua_pop(L, 2);\n    }\n    if (u-l == 2) break;  /* only 3 elements */\n    lua_rawgeti(L, 1, i);  /* Pivot */\n    lua_pushvalue(L, -1);\n    lua_rawgeti(L, 1, u-1);\n    set2(L, i, u-1);\n    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */\n    i = l; j = u-1;\n    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */\n      /* repeat ++i until a[i] >= P */\n      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {\n\tif (i>=u) lj_err_caller(L, LJ_ERR_TABSORT);\n\tlua_pop(L, 1);  /* remove a[i] */\n      }\n      /* repeat --j until a[j] <= P */\n      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {\n\tif (j<=l) lj_err_caller(L, LJ_ERR_TABSORT);\n\tlua_pop(L, 1);  /* remove a[j] */\n      }\n      if (j<i) {\n\tlua_pop(L, 3);  /* pop pivot, a[i], a[j] */\n\tbreak;\n      }\n      set2(L, i, j);\n    }\n    lua_rawgeti(L, 1, u-1);\n    lua_rawgeti(L, 1, i);\n    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */\n    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */\n    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */\n    if (i-l < u-i) {\n      j=l; i=i-1; l=i+2;\n    } else {\n      j=i+1; i=u; u=j-2;\n    }\n    auxsort(L, j, i);  /* call recursively the smaller one */\n  }  /* repeat the routine for the larger one */\n}\n\nLJLIB_CF(table_sort)\n{\n  GCtab *t = lj_lib_checktab(L, 1);\n  int32_t n = (int32_t)lj_tab_len(t);\n  lua_settop(L, 2);\n  if (!tvisnil(L->base+1))\n    lj_lib_checkfunc(L, 2);\n  auxsort(L, 1, n);\n  return 0;\n}\n\n#if LJ_52\nLJLIB_PUSH(\"n\")\nLJLIB_CF(table_pack)\n{\n  TValue *array, *base = L->base;\n  MSize i, n = (uint32_t)(L->top - base);\n  GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1);\n  /* NOBARRIER: The table is new (marked white). */\n  setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n);\n  for (array = tvref(t->array) + 1, i = 0; i < n; i++)\n    copyTV(L, &array[i], &base[i]);\n  settabV(L, base, t);\n  L->top = base+1;\n  lj_gc_check(L);\n  return 1;\n}\n#endif\n\nLJLIB_NOREG LJLIB_CF(table_new)\t\tLJLIB_REC(.)\n{\n  int32_t a = lj_lib_checkint(L, 1);\n  int32_t h = lj_lib_checkint(L, 2);\n  lua_createtable(L, a, h);\n  return 1;\n}\n\nLJLIB_NOREG LJLIB_CF(table_clear)\tLJLIB_REC(.)\n{\n  lj_tab_clear(lj_lib_checktab(L, 1));\n  return 0;\n}\n\nstatic int luaopen_table_new(lua_State *L)\n{\n  return lj_lib_postreg(L, lj_cf_table_new, FF_table_new, \"new\");\n}\n\nstatic int luaopen_table_clear(lua_State *L)\n{\n  return lj_lib_postreg(L, lj_cf_table_clear, FF_table_clear, \"clear\");\n}\n\n/* ------------------------------------------------------------------------ */\n\n#include \"lj_libdef.h\"\n\nLUALIB_API int luaopen_table(lua_State *L)\n{\n  LJ_LIB_REG(L, LUA_TABLIBNAME, table);\n#if LJ_52\n  lua_getglobal(L, \"unpack\");\n  lua_setfield(L, -2, \"unpack\");\n#endif\n  lj_lib_prereg(L, LUA_TABLIBNAME \".new\", luaopen_table_new, tabV(L->top-1));\n  lj_lib_prereg(L, LUA_TABLIBNAME \".clear\", luaopen_table_clear, tabV(L->top-1));\n  return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj.supp",
    "content": "# Valgrind suppression file for LuaJIT 2.0.\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:lj_str_cmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:lj_str_cmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Cond\n   fun:lj_str_new\n}\n{\n   Optimized string compare\n   Memcheck:Addr4\n   fun:str_fastcmp\n}\n{\n   Optimized string compare\n   Memcheck:Addr1\n   fun:str_fastcmp\n}\n{\n   Optimized string compare\n   Memcheck:Cond\n   fun:str_fastcmp\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_alloc.c",
    "content": "/*\n** Bundled memory allocator.\n**\n** Beware: this is a HEAVILY CUSTOMIZED version of dlmalloc.\n** The original bears the following remark:\n**\n**   This is a version (aka dlmalloc) of malloc/free/realloc written by\n**   Doug Lea and released to the public domain, as explained at\n**   https://creativecommons.org/licenses/publicdomain.\n**\n**   * Version pre-2.8.4 Wed Mar 29 19:46:29 2006    (dl at gee)\n**\n** No additional copyright is claimed over the customizations.\n** Please do NOT bother the original author about this version here!\n**\n** If you want to use dlmalloc in another project, you should get\n** the original from: ftp://gee.cs.oswego.edu/pub/misc/\n** For thread-safe derivatives, take a look at:\n** - ptmalloc: https://www.malloc.de/\n** - nedmalloc: https://www.nedprod.com/programs/portable/nedmalloc/\n*/\n\n#define lj_alloc_c\n#define LUA_CORE\n\n/* To get the mremap prototype. Must be defined before any system includes. */\n#if defined(__linux__) && !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n#include \"lj_alloc.h\"\n#include \"lj_prng.h\"\n\n#ifndef LUAJIT_USE_SYSMALLOC\n\n#define MAX_SIZE_T\t\t(~(size_t)0)\n#define MALLOC_ALIGNMENT\t((size_t)8U)\n\n#define DEFAULT_GRANULARITY\t((size_t)128U * (size_t)1024U)\n#define DEFAULT_TRIM_THRESHOLD\t((size_t)2U * (size_t)1024U * (size_t)1024U)\n#define DEFAULT_MMAP_THRESHOLD\t((size_t)128U * (size_t)1024U)\n#define MAX_RELEASE_CHECK_RATE\t255\n\n/* ------------------- size_t and alignment properties -------------------- */\n\n/* The byte and bit size of a size_t */\n#define SIZE_T_SIZE\t\t(sizeof(size_t))\n#define SIZE_T_BITSIZE\t\t(sizeof(size_t) << 3)\n\n/* Some constants coerced to size_t */\n/* Annoying but necessary to avoid errors on some platforms */\n#define SIZE_T_ZERO\t\t((size_t)0)\n#define SIZE_T_ONE\t\t((size_t)1)\n#define SIZE_T_TWO\t\t((size_t)2)\n#define TWO_SIZE_T_SIZES\t(SIZE_T_SIZE<<1)\n#define FOUR_SIZE_T_SIZES\t(SIZE_T_SIZE<<2)\n#define SIX_SIZE_T_SIZES\t(FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)\n\n/* The bit mask value corresponding to MALLOC_ALIGNMENT */\n#define CHUNK_ALIGN_MASK\t(MALLOC_ALIGNMENT - SIZE_T_ONE)\n\n/* the number of bytes to offset an address to align it */\n#define align_offset(A)\\\n ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\\\n  ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))\n\n/* -------------------------- MMAP support ------------------------------- */\n\n#define MFAIL\t\t\t((void *)(MAX_SIZE_T))\n#define CMFAIL\t\t\t((char *)(MFAIL)) /* defined for convenience */\n\n#define IS_DIRECT_BIT\t\t(SIZE_T_ONE)\n\n\n/* Determine system-specific block allocation method. */\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#define LJ_ALLOC_VIRTUALALLOC\t1\n\n#if LJ_64 && !LJ_GC64\n#define LJ_ALLOC_NTAVM\t\t1\n#endif\n\n#else\n\n#include <errno.h>\n/* If this include fails, then rebuild with: -DLUAJIT_USE_SYSMALLOC */\n#include <sys/mman.h>\n\n#define LJ_ALLOC_MMAP\t\t1\n\n#if LJ_64\n\n#define LJ_ALLOC_MMAP_PROBE\t1\n\n#if LJ_GC64\n#define LJ_ALLOC_MBITS\t\t47\t/* 128 TB in LJ_GC64 mode. */\n#elif LJ_TARGET_X64 && LJ_HASJIT\n/* Due to limitations in the x64 compiler backend. */\n#define LJ_ALLOC_MBITS\t\t31\t/* 2 GB on x64 with !LJ_GC64. */\n#else\n#define LJ_ALLOC_MBITS\t\t32\t/* 4 GB on other archs with !LJ_GC64. */\n#endif\n\n#endif\n\n#if LJ_64 && !LJ_GC64 && defined(MAP_32BIT)\n#define LJ_ALLOC_MMAP32\t\t1\n#endif\n\n#if LJ_TARGET_LINUX\n#define LJ_ALLOC_MREMAP\t\t1\n#endif\n\n#endif\n\n\n#if LJ_ALLOC_VIRTUALALLOC\n\n#if LJ_ALLOC_NTAVM\n/* Undocumented, but hey, that's what we all love so much about Windows. */\ntypedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG_PTR zbits,\n\t\t       size_t *size, ULONG alloctype, ULONG prot);\nstatic PNTAVM ntavm;\n\n/* Number of top bits of the lower 32 bits of an address that must be zero.\n** Apparently 0 gives us full 64 bit addresses and 1 gives us the lower 2GB.\n*/\n#define NTAVM_ZEROBITS\t\t1\n\nstatic void init_mmap(void)\n{\n  ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA(\"ntdll.dll\"),\n\t\t\t\t \"NtAllocateVirtualMemory\");\n}\n#define INIT_MMAP()\tinit_mmap()\n\n/* Win64 32 bit MMAP via NtAllocateVirtualMemory. */\nstatic void *mmap_plain(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = NULL;\n  long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,\n\t\t  MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  SetLastError(olderr);\n  return st == 0 ? ptr : MFAIL;\n}\n\n/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */\nstatic void *direct_mmap(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = NULL;\n  long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,\n\t\t  MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE);\n  SetLastError(olderr);\n  return st == 0 ? ptr : MFAIL;\n}\n\n#else\n\n/* Win32 MMAP via VirtualAlloc */\nstatic void *mmap_plain(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = LJ_WIN_VALLOC(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  SetLastError(olderr);\n  return ptr ? ptr : MFAIL;\n}\n\n/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */\nstatic void *direct_mmap(size_t size)\n{\n  DWORD olderr = GetLastError();\n  void *ptr = LJ_WIN_VALLOC(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,\n\t\t\t    PAGE_READWRITE);\n  SetLastError(olderr);\n  return ptr ? ptr : MFAIL;\n}\n\n#endif\n\n#define CALL_MMAP(prng, size)\tmmap_plain(size)\n#define DIRECT_MMAP(prng, size)\tdirect_mmap(size)\n\n/* This function supports releasing coalesed segments */\nstatic int CALL_MUNMAP(void *ptr, size_t size)\n{\n  DWORD olderr = GetLastError();\n  MEMORY_BASIC_INFORMATION minfo;\n  char *cptr = (char *)ptr;\n  while (size) {\n    if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)\n      return -1;\n    if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||\n\tminfo.State != MEM_COMMIT || minfo.RegionSize > size)\n      return -1;\n    if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)\n      return -1;\n    cptr += minfo.RegionSize;\n    size -= minfo.RegionSize;\n  }\n  SetLastError(olderr);\n  return 0;\n}\n\n#elif LJ_ALLOC_MMAP\n\n#define MMAP_PROT\t\t(PROT_READ|PROT_WRITE)\n#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)\n#define MAP_ANONYMOUS\t\tMAP_ANON\n#endif\n#define MMAP_FLAGS\t\t(MAP_PRIVATE|MAP_ANONYMOUS)\n\n#if LJ_ALLOC_MMAP_PROBE\n\n#ifdef MAP_TRYFIXED\n#define MMAP_FLAGS_PROBE\t(MMAP_FLAGS|MAP_TRYFIXED)\n#else\n#define MMAP_FLAGS_PROBE\tMMAP_FLAGS\n#endif\n\n#define LJ_ALLOC_MMAP_PROBE_MAX\t\t30\n#define LJ_ALLOC_MMAP_PROBE_LINEAR\t5\n\n#define LJ_ALLOC_MMAP_PROBE_LOWER\t((uintptr_t)0x4000)\n\nstatic void *mmap_probe(PRNGState *rs, size_t size)\n{\n  /* Hint for next allocation. Doesn't need to be thread-safe. */\n  static uintptr_t hint_addr = 0;\n  int olderr = errno;\n  int retry;\n  for (retry = 0; retry < LJ_ALLOC_MMAP_PROBE_MAX; retry++) {\n    void *p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);\n    uintptr_t addr = (uintptr_t)p;\n    if ((addr >> LJ_ALLOC_MBITS) == 0 && addr >= LJ_ALLOC_MMAP_PROBE_LOWER &&\n\t((addr + size) >> LJ_ALLOC_MBITS) == 0) {\n      /* We got a suitable address. Bump the hint address. */\n      hint_addr = addr + size;\n      errno = olderr;\n      return p;\n    }\n    if (p != MFAIL) {\n      munmap(p, size);\n    } else if (errno == ENOMEM) {\n      return MFAIL;\n    }\n    if (hint_addr) {\n      /* First, try linear probing. */\n      if (retry < LJ_ALLOC_MMAP_PROBE_LINEAR) {\n\thint_addr += 0x1000000;\n\tif (((hint_addr + size) >> LJ_ALLOC_MBITS) != 0)\n\t  hint_addr = 0;\n\tcontinue;\n      } else if (retry == LJ_ALLOC_MMAP_PROBE_LINEAR) {\n\t/* Next, try a no-hint probe to get back an ASLR address. */\n\thint_addr = 0;\n\tcontinue;\n      }\n    }\n    /* Finally, try pseudo-random probing. */\n    do {\n      hint_addr = lj_prng_u64(rs) & (((uintptr_t)1<<LJ_ALLOC_MBITS)-LJ_PAGESIZE);\n    } while (hint_addr < LJ_ALLOC_MMAP_PROBE_LOWER);\n  }\n  errno = olderr;\n  return MFAIL;\n}\n\n#endif\n\n#if LJ_ALLOC_MMAP32\n\n#if LJ_TARGET_SOLARIS\n#define LJ_ALLOC_MMAP32_START\t((uintptr_t)0x1000)\n#else\n#define LJ_ALLOC_MMAP32_START\t((uintptr_t)0)\n#endif\n\n#if LJ_ALLOC_MMAP_PROBE\nstatic void *mmap_map32(PRNGState *rs, size_t size)\n#else\nstatic void *mmap_map32(size_t size)\n#endif\n{\n#if LJ_ALLOC_MMAP_PROBE\n  static int fallback = 0;\n  if (fallback)\n    return mmap_probe(rs, size);\n#endif\n  {\n    int olderr = errno;\n    void *ptr = mmap((void *)LJ_ALLOC_MMAP32_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);\n    errno = olderr;\n    /* This only allows 1GB on Linux. So fallback to probing to get 2GB. */\n#if LJ_ALLOC_MMAP_PROBE\n    if (ptr == MFAIL) {\n      fallback = 1;\n      return mmap_probe(rs, size);\n    }\n#endif\n    return ptr;\n  }\n}\n\n#endif\n\n#if LJ_ALLOC_MMAP32\n#if LJ_ALLOC_MMAP_PROBE\n#define CALL_MMAP(prng, size)\tmmap_map32(prng, size)\n#else\n#define CALL_MMAP(prng, size)\tmmap_map32(size)\n#endif\n#elif LJ_ALLOC_MMAP_PROBE\n#define CALL_MMAP(prng, size)\tmmap_probe(prng, size)\n#else\nstatic void *mmap_plain(size_t size)\n{\n  int olderr = errno;\n  void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0);\n  errno = olderr;\n  return ptr;\n}\n#define CALL_MMAP(prng, size)\tmmap_plain(size)\n#endif\n\n#if LJ_64 && !LJ_GC64 && ((defined(__FreeBSD__) && __FreeBSD__ < 10) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4\n\n#include <sys/resource.h>\n\nstatic void init_mmap(void)\n{\n  struct rlimit rlim;\n  rlim.rlim_cur = rlim.rlim_max = 0x10000;\n  setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail later. */\n}\n#define INIT_MMAP()\tinit_mmap()\n\n#endif\n\nstatic int CALL_MUNMAP(void *ptr, size_t size)\n{\n  int olderr = errno;\n  int ret = munmap(ptr, size);\n  errno = olderr;\n  return ret;\n}\n\n#if LJ_ALLOC_MREMAP\n/* Need to define _GNU_SOURCE to get the mremap prototype. */\nstatic void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz, int flags)\n{\n  int olderr = errno;\n  ptr = mremap(ptr, osz, nsz, flags);\n  errno = olderr;\n  return ptr;\n}\n\n#define CALL_MREMAP(addr, osz, nsz, mv) CALL_MREMAP_((addr), (osz), (nsz), (mv))\n#define CALL_MREMAP_NOMOVE\t0\n#define CALL_MREMAP_MAYMOVE\t1\n#if LJ_64 && (!LJ_GC64 || LJ_TARGET_ARM64)\n#define CALL_MREMAP_MV\t\tCALL_MREMAP_NOMOVE\n#else\n#define CALL_MREMAP_MV\t\tCALL_MREMAP_MAYMOVE\n#endif\n#endif\n\n#endif\n\n\n#ifndef INIT_MMAP\n#define INIT_MMAP()\t\t((void)0)\n#endif\n\n#ifndef DIRECT_MMAP\n#define DIRECT_MMAP(prng, s)\tCALL_MMAP(prng, s)\n#endif\n\n#ifndef CALL_MREMAP\n#define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL)\n#endif\n\n/* -----------------------  Chunk representations ------------------------ */\n\nstruct malloc_chunk {\n  size_t               prev_foot;  /* Size of previous chunk (if free).  */\n  size_t               head;       /* Size and inuse bits. */\n  struct malloc_chunk *fd;         /* double links -- used only if free. */\n  struct malloc_chunk *bk;\n};\n\ntypedef struct malloc_chunk  mchunk;\ntypedef struct malloc_chunk *mchunkptr;\ntypedef struct malloc_chunk *sbinptr;  /* The type of bins of chunks */\ntypedef size_t bindex_t;               /* Described below */\ntypedef unsigned int binmap_t;         /* Described below */\ntypedef unsigned int flag_t;           /* The type of various bit flag sets */\n\n/* ------------------- Chunks sizes and alignments ----------------------- */\n\n#define MCHUNK_SIZE\t\t(sizeof(mchunk))\n\n#define CHUNK_OVERHEAD\t\t(SIZE_T_SIZE)\n\n/* Direct chunks need a second word of overhead ... */\n#define DIRECT_CHUNK_OVERHEAD\t(TWO_SIZE_T_SIZES)\n/* ... and additional padding for fake next-chunk at foot */\n#define DIRECT_FOOT_PAD\t\t(FOUR_SIZE_T_SIZES)\n\n/* The smallest size we can malloc is an aligned minimal chunk */\n#define MIN_CHUNK_SIZE\\\n  ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)\n\n/* conversion from malloc headers to user pointers, and back */\n#define chunk2mem(p)\t\t((void *)((char *)(p) + TWO_SIZE_T_SIZES))\n#define mem2chunk(mem)\t\t((mchunkptr)((char *)(mem) - TWO_SIZE_T_SIZES))\n/* chunk associated with aligned address A */\n#define align_as_chunk(A)\t(mchunkptr)((A) + align_offset(chunk2mem(A)))\n\n/* Bounds on request (not chunk) sizes. */\n#define MAX_REQUEST\t\t((~MIN_CHUNK_SIZE+1) << 2)\n#define MIN_REQUEST\t\t(MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)\n\n/* pad request bytes into a usable size */\n#define pad_request(req) \\\n   (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)\n\n/* pad request, checking for minimum (but not maximum) */\n#define request2size(req) \\\n  (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))\n\n/* ------------------ Operations on head and foot fields ----------------- */\n\n#define PINUSE_BIT\t\t(SIZE_T_ONE)\n#define CINUSE_BIT\t\t(SIZE_T_TWO)\n#define INUSE_BITS\t\t(PINUSE_BIT|CINUSE_BIT)\n\n/* Head value for fenceposts */\n#define FENCEPOST_HEAD\t\t(INUSE_BITS|SIZE_T_SIZE)\n\n/* extraction of fields from head words */\n#define cinuse(p)\t\t((p)->head & CINUSE_BIT)\n#define pinuse(p)\t\t((p)->head & PINUSE_BIT)\n#define chunksize(p)\t\t((p)->head & ~(INUSE_BITS))\n\n#define clear_pinuse(p)\t\t((p)->head &= ~PINUSE_BIT)\n#define clear_cinuse(p)\t\t((p)->head &= ~CINUSE_BIT)\n\n/* Treat space at ptr +/- offset as a chunk */\n#define chunk_plus_offset(p, s)\t\t((mchunkptr)(((char *)(p)) + (s)))\n#define chunk_minus_offset(p, s)\t((mchunkptr)(((char *)(p)) - (s)))\n\n/* Ptr to next or previous physical malloc_chunk. */\n#define next_chunk(p)\t((mchunkptr)(((char *)(p)) + ((p)->head & ~INUSE_BITS)))\n#define prev_chunk(p)\t((mchunkptr)(((char *)(p)) - ((p)->prev_foot) ))\n\n/* extract next chunk's pinuse bit */\n#define next_pinuse(p)\t((next_chunk(p)->head) & PINUSE_BIT)\n\n/* Get/set size at footer */\n#define get_foot(p, s)\t(((mchunkptr)((char *)(p) + (s)))->prev_foot)\n#define set_foot(p, s)\t(((mchunkptr)((char *)(p) + (s)))->prev_foot = (s))\n\n/* Set size, pinuse bit, and foot */\n#define set_size_and_pinuse_of_free_chunk(p, s)\\\n  ((p)->head = (s|PINUSE_BIT), set_foot(p, s))\n\n/* Set size, pinuse bit, foot, and clear next pinuse */\n#define set_free_with_pinuse(p, s, n)\\\n  (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))\n\n#define is_direct(p)\\\n  (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_DIRECT_BIT))\n\n/* Get the internal overhead associated with chunk p */\n#define overhead_for(p)\\\n (is_direct(p)? DIRECT_CHUNK_OVERHEAD : CHUNK_OVERHEAD)\n\n/* ---------------------- Overlaid data structures ----------------------- */\n\nstruct malloc_tree_chunk {\n  /* The first four fields must be compatible with malloc_chunk */\n  size_t                    prev_foot;\n  size_t                    head;\n  struct malloc_tree_chunk *fd;\n  struct malloc_tree_chunk *bk;\n\n  struct malloc_tree_chunk *child[2];\n  struct malloc_tree_chunk *parent;\n  bindex_t                  index;\n};\n\ntypedef struct malloc_tree_chunk  tchunk;\ntypedef struct malloc_tree_chunk *tchunkptr;\ntypedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */\n\n/* A little helper macro for trees */\n#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])\n\n/* ----------------------------- Segments -------------------------------- */\n\nstruct malloc_segment {\n  char        *base;             /* base address */\n  size_t       size;             /* allocated size */\n  struct malloc_segment *next;   /* ptr to next segment */\n};\n\ntypedef struct malloc_segment  msegment;\ntypedef struct malloc_segment *msegmentptr;\n\n/* ---------------------------- malloc_state ----------------------------- */\n\n/* Bin types, widths and sizes */\n#define NSMALLBINS\t\t(32U)\n#define NTREEBINS\t\t(32U)\n#define SMALLBIN_SHIFT\t\t(3U)\n#define SMALLBIN_WIDTH\t\t(SIZE_T_ONE << SMALLBIN_SHIFT)\n#define TREEBIN_SHIFT\t\t(8U)\n#define MIN_LARGE_SIZE\t\t(SIZE_T_ONE << TREEBIN_SHIFT)\n#define MAX_SMALL_SIZE\t\t(MIN_LARGE_SIZE - SIZE_T_ONE)\n#define MAX_SMALL_REQUEST  (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)\n\nstruct malloc_state {\n  binmap_t   smallmap;\n  binmap_t   treemap;\n  size_t     dvsize;\n  size_t     topsize;\n  mchunkptr  dv;\n  mchunkptr  top;\n  size_t     trim_check;\n  size_t     release_checks;\n  mchunkptr  smallbins[(NSMALLBINS+1)*2];\n  tbinptr    treebins[NTREEBINS];\n  msegment   seg;\n  PRNGState  *prng;\n};\n\ntypedef struct malloc_state *mstate;\n\n#define is_initialized(M)\t((M)->top != 0)\n\n/* -------------------------- system alloc setup ------------------------- */\n\n/* page-align a size */\n#define page_align(S)\\\n (((S) + (LJ_PAGESIZE - SIZE_T_ONE)) & ~(LJ_PAGESIZE - SIZE_T_ONE))\n\n/* granularity-align a size */\n#define granularity_align(S)\\\n  (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\\\n   & ~(DEFAULT_GRANULARITY - SIZE_T_ONE))\n\n#if LJ_TARGET_WINDOWS\n#define mmap_align(S)\tgranularity_align(S)\n#else\n#define mmap_align(S)\tpage_align(S)\n#endif\n\n/*  True if segment S holds address A */\n#define segment_holds(S, A)\\\n  ((char *)(A) >= S->base && (char *)(A) < S->base + S->size)\n\n/* Return segment holding given address */\nstatic msegmentptr segment_holding(mstate m, char *addr)\n{\n  msegmentptr sp = &m->seg;\n  for (;;) {\n    if (addr >= sp->base && addr < sp->base + sp->size)\n      return sp;\n    if ((sp = sp->next) == 0)\n      return 0;\n  }\n}\n\n/* Return true if segment contains a segment link */\nstatic int has_segment_link(mstate m, msegmentptr ss)\n{\n  msegmentptr sp = &m->seg;\n  for (;;) {\n    if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size)\n      return 1;\n    if ((sp = sp->next) == 0)\n      return 0;\n  }\n}\n\n/*\n  TOP_FOOT_SIZE is padding at the end of a segment, including space\n  that may be needed to place segment records and fenceposts when new\n  noncontiguous segments are added.\n*/\n#define TOP_FOOT_SIZE\\\n  (align_offset(TWO_SIZE_T_SIZES)+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)\n\n/* ---------------------------- Indexing Bins ---------------------------- */\n\n#define is_small(s)\t\t(((s) >> SMALLBIN_SHIFT) < NSMALLBINS)\n#define small_index(s)\t\t((s)  >> SMALLBIN_SHIFT)\n#define small_index2size(i)\t((i)  << SMALLBIN_SHIFT)\n#define MIN_SMALL_INDEX\t\t(small_index(MIN_CHUNK_SIZE))\n\n/* addressing by index. See above about smallbin repositioning */\n#define smallbin_at(M, i)\t((sbinptr)((char *)&((M)->smallbins[(i)<<1])))\n#define treebin_at(M,i)\t\t(&((M)->treebins[i]))\n\n/* assign tree index for size S to variable I */\n#define compute_tree_index(S, I)\\\n{\\\n  unsigned int X = (unsigned int)(S >> TREEBIN_SHIFT);\\\n  if (X == 0) {\\\n    I = 0;\\\n  } else if (X > 0xFFFF) {\\\n    I = NTREEBINS-1;\\\n  } else {\\\n    unsigned int K = lj_fls(X);\\\n    I =  (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\\\n  }\\\n}\n\n/* Bit representing maximum resolved size in a treebin at i */\n#define bit_for_tree_index(i) \\\n   (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)\n\n/* Shift placing maximum resolved bit in a treebin at i as sign bit */\n#define leftshift_for_tree_index(i) \\\n   ((i == NTREEBINS-1)? 0 : \\\n    ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))\n\n/* The size of the smallest chunk held in bin with index i */\n#define minsize_for_tree_index(i) \\\n   ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) |  \\\n   (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))\n\n/* ------------------------ Operations on bin maps ----------------------- */\n\n/* bit corresponding to given index */\n#define idx2bit(i)\t\t((binmap_t)(1) << (i))\n\n/* Mark/Clear bits with given index */\n#define mark_smallmap(M,i)\t((M)->smallmap |=  idx2bit(i))\n#define clear_smallmap(M,i)\t((M)->smallmap &= ~idx2bit(i))\n#define smallmap_is_marked(M,i)\t((M)->smallmap &   idx2bit(i))\n\n#define mark_treemap(M,i)\t((M)->treemap  |=  idx2bit(i))\n#define clear_treemap(M,i)\t((M)->treemap  &= ~idx2bit(i))\n#define treemap_is_marked(M,i)\t((M)->treemap  &   idx2bit(i))\n\n/* mask with all bits to left of least bit of x on */\n#define left_bits(x)\t\t((x<<1) | (~(x<<1)+1))\n\n/* Set cinuse bit and pinuse bit of next chunk */\n#define set_inuse(M,p,s)\\\n  ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\\\n  ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)\n\n/* Set cinuse and pinuse of this chunk and pinuse of next chunk */\n#define set_inuse_and_pinuse(M,p,s)\\\n  ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\\\n  ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)\n\n/* Set size, cinuse and pinuse bit of this chunk */\n#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\\\n  ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))\n\n/* ----------------------- Operations on smallbins ----------------------- */\n\n/* Link a free chunk into a smallbin  */\n#define insert_small_chunk(M, P, S) {\\\n  bindex_t I = small_index(S);\\\n  mchunkptr B = smallbin_at(M, I);\\\n  mchunkptr F = B;\\\n  if (!smallmap_is_marked(M, I))\\\n    mark_smallmap(M, I);\\\n  else\\\n    F = B->fd;\\\n  B->fd = P;\\\n  F->bk = P;\\\n  P->fd = F;\\\n  P->bk = B;\\\n}\n\n/* Unlink a chunk from a smallbin  */\n#define unlink_small_chunk(M, P, S) {\\\n  mchunkptr F = P->fd;\\\n  mchunkptr B = P->bk;\\\n  bindex_t I = small_index(S);\\\n  if (F == B) {\\\n    clear_smallmap(M, I);\\\n  } else {\\\n    F->bk = B;\\\n    B->fd = F;\\\n  }\\\n}\n\n/* Unlink the first chunk from a smallbin */\n#define unlink_first_small_chunk(M, B, P, I) {\\\n  mchunkptr F = P->fd;\\\n  if (B == F) {\\\n    clear_smallmap(M, I);\\\n  } else {\\\n    B->fd = F;\\\n    F->bk = B;\\\n  }\\\n}\n\n/* Replace dv node, binning the old one */\n/* Used only when dvsize known to be small */\n#define replace_dv(M, P, S) {\\\n  size_t DVS = M->dvsize;\\\n  if (DVS != 0) {\\\n    mchunkptr DV = M->dv;\\\n    insert_small_chunk(M, DV, DVS);\\\n  }\\\n  M->dvsize = S;\\\n  M->dv = P;\\\n}\n\n/* ------------------------- Operations on trees ------------------------- */\n\n/* Insert chunk into tree */\n#define insert_large_chunk(M, X, S) {\\\n  tbinptr *H;\\\n  bindex_t I;\\\n  compute_tree_index(S, I);\\\n  H = treebin_at(M, I);\\\n  X->index = I;\\\n  X->child[0] = X->child[1] = 0;\\\n  if (!treemap_is_marked(M, I)) {\\\n    mark_treemap(M, I);\\\n    *H = X;\\\n    X->parent = (tchunkptr)H;\\\n    X->fd = X->bk = X;\\\n  } else {\\\n    tchunkptr T = *H;\\\n    size_t K = S << leftshift_for_tree_index(I);\\\n    for (;;) {\\\n      if (chunksize(T) != S) {\\\n\ttchunkptr *C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\\\n\tK <<= 1;\\\n\tif (*C != 0) {\\\n\t  T = *C;\\\n\t} else {\\\n\t  *C = X;\\\n\t  X->parent = T;\\\n\t  X->fd = X->bk = X;\\\n\t  break;\\\n\t}\\\n      } else {\\\n\ttchunkptr F = T->fd;\\\n\tT->fd = F->bk = X;\\\n\tX->fd = F;\\\n\tX->bk = T;\\\n\tX->parent = 0;\\\n\tbreak;\\\n      }\\\n    }\\\n  }\\\n}\n\n#define unlink_large_chunk(M, X) {\\\n  tchunkptr XP = X->parent;\\\n  tchunkptr R;\\\n  if (X->bk != X) {\\\n    tchunkptr F = X->fd;\\\n    R = X->bk;\\\n    F->bk = R;\\\n    R->fd = F;\\\n  } else {\\\n    tchunkptr *RP;\\\n    if (((R = *(RP = &(X->child[1]))) != 0) ||\\\n\t((R = *(RP = &(X->child[0]))) != 0)) {\\\n      tchunkptr *CP;\\\n      while ((*(CP = &(R->child[1])) != 0) ||\\\n\t     (*(CP = &(R->child[0])) != 0)) {\\\n\tR = *(RP = CP);\\\n      }\\\n      *RP = 0;\\\n    }\\\n  }\\\n  if (XP != 0) {\\\n    tbinptr *H = treebin_at(M, X->index);\\\n    if (X == *H) {\\\n      if ((*H = R) == 0) \\\n\tclear_treemap(M, X->index);\\\n    } else {\\\n      if (XP->child[0] == X) \\\n\tXP->child[0] = R;\\\n      else \\\n\tXP->child[1] = R;\\\n    }\\\n    if (R != 0) {\\\n      tchunkptr C0, C1;\\\n      R->parent = XP;\\\n      if ((C0 = X->child[0]) != 0) {\\\n\tR->child[0] = C0;\\\n\tC0->parent = R;\\\n      }\\\n      if ((C1 = X->child[1]) != 0) {\\\n\tR->child[1] = C1;\\\n\tC1->parent = R;\\\n      }\\\n    }\\\n  }\\\n}\n\n/* Relays to large vs small bin operations */\n\n#define insert_chunk(M, P, S)\\\n  if (is_small(S)) { insert_small_chunk(M, P, S)\\\n  } else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }\n\n#define unlink_chunk(M, P, S)\\\n  if (is_small(S)) { unlink_small_chunk(M, P, S)\\\n  } else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }\n\n/* -----------------------  Direct-mmapping chunks ----------------------- */\n\nstatic void *direct_alloc(mstate m, size_t nb)\n{\n  size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n  if (LJ_LIKELY(mmsize > nb)) {     /* Check for wrap around 0 */\n    char *mm = (char *)(DIRECT_MMAP(m->prng, mmsize));\n    if (mm != CMFAIL) {\n      size_t offset = align_offset(chunk2mem(mm));\n      size_t psize = mmsize - offset - DIRECT_FOOT_PAD;\n      mchunkptr p = (mchunkptr)(mm + offset);\n      p->prev_foot = offset | IS_DIRECT_BIT;\n      p->head = psize|CINUSE_BIT;\n      chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;\n      chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;\n      return chunk2mem(p);\n    }\n  }\n  UNUSED(m);\n  return NULL;\n}\n\nstatic mchunkptr direct_resize(mchunkptr oldp, size_t nb)\n{\n  size_t oldsize = chunksize(oldp);\n  if (is_small(nb)) /* Can't shrink direct regions below small size */\n    return NULL;\n  /* Keep old chunk if big enough but not too big */\n  if (oldsize >= nb + SIZE_T_SIZE &&\n      (oldsize - nb) <= (DEFAULT_GRANULARITY >> 1)) {\n    return oldp;\n  } else {\n    size_t offset = oldp->prev_foot & ~IS_DIRECT_BIT;\n    size_t oldmmsize = oldsize + offset + DIRECT_FOOT_PAD;\n    size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n    char *cp = (char *)CALL_MREMAP((char *)oldp - offset,\n\t\t\t\t   oldmmsize, newmmsize, CALL_MREMAP_MV);\n    if (cp != CMFAIL) {\n      mchunkptr newp = (mchunkptr)(cp + offset);\n      size_t psize = newmmsize - offset - DIRECT_FOOT_PAD;\n      newp->head = psize|CINUSE_BIT;\n      chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;\n      chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0;\n      return newp;\n    }\n  }\n  return NULL;\n}\n\n/* -------------------------- mspace management -------------------------- */\n\n/* Initialize top chunk and its size */\nstatic void init_top(mstate m, mchunkptr p, size_t psize)\n{\n  /* Ensure alignment */\n  size_t offset = align_offset(chunk2mem(p));\n  p = (mchunkptr)((char *)p + offset);\n  psize -= offset;\n\n  m->top = p;\n  m->topsize = psize;\n  p->head = psize | PINUSE_BIT;\n  /* set size of fake trailing chunk holding overhead space only once */\n  chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;\n  m->trim_check = DEFAULT_TRIM_THRESHOLD; /* reset on each update */\n}\n\n/* Initialize bins for a new mstate that is otherwise zeroed out */\nstatic void init_bins(mstate m)\n{\n  /* Establish circular links for smallbins */\n  bindex_t i;\n  for (i = 0; i < NSMALLBINS; i++) {\n    sbinptr bin = smallbin_at(m,i);\n    bin->fd = bin->bk = bin;\n  }\n}\n\n/* Allocate chunk and prepend remainder with chunk in successor base. */\nstatic void *prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)\n{\n  mchunkptr p = align_as_chunk(newbase);\n  mchunkptr oldfirst = align_as_chunk(oldbase);\n  size_t psize = (size_t)((char *)oldfirst - (char *)p);\n  mchunkptr q = chunk_plus_offset(p, nb);\n  size_t qsize = psize - nb;\n  set_size_and_pinuse_of_inuse_chunk(m, p, nb);\n\n  /* consolidate remainder with first chunk of old base */\n  if (oldfirst == m->top) {\n    size_t tsize = m->topsize += qsize;\n    m->top = q;\n    q->head = tsize | PINUSE_BIT;\n  } else if (oldfirst == m->dv) {\n    size_t dsize = m->dvsize += qsize;\n    m->dv = q;\n    set_size_and_pinuse_of_free_chunk(q, dsize);\n  } else {\n    if (!cinuse(oldfirst)) {\n      size_t nsize = chunksize(oldfirst);\n      unlink_chunk(m, oldfirst, nsize);\n      oldfirst = chunk_plus_offset(oldfirst, nsize);\n      qsize += nsize;\n    }\n    set_free_with_pinuse(q, qsize, oldfirst);\n    insert_chunk(m, q, qsize);\n  }\n\n  return chunk2mem(p);\n}\n\n/* Add a segment to hold a new noncontiguous region */\nstatic void add_segment(mstate m, char *tbase, size_t tsize)\n{\n  /* Determine locations and sizes of segment, fenceposts, old top */\n  char *old_top = (char *)m->top;\n  msegmentptr oldsp = segment_holding(m, old_top);\n  char *old_end = oldsp->base + oldsp->size;\n  size_t ssize = pad_request(sizeof(struct malloc_segment));\n  char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);\n  size_t offset = align_offset(chunk2mem(rawsp));\n  char *asp = rawsp + offset;\n  char *csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp;\n  mchunkptr sp = (mchunkptr)csp;\n  msegmentptr ss = (msegmentptr)(chunk2mem(sp));\n  mchunkptr tnext = chunk_plus_offset(sp, ssize);\n  mchunkptr p = tnext;\n\n  /* reset top to new space */\n  init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);\n\n  /* Set up segment record */\n  set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);\n  *ss = m->seg; /* Push current record */\n  m->seg.base = tbase;\n  m->seg.size = tsize;\n  m->seg.next = ss;\n\n  /* Insert trailing fenceposts */\n  for (;;) {\n    mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);\n    p->head = FENCEPOST_HEAD;\n    if ((char *)(&(nextp->head)) < old_end)\n      p = nextp;\n    else\n      break;\n  }\n\n  /* Insert the rest of old top into a bin as an ordinary free chunk */\n  if (csp != old_top) {\n    mchunkptr q = (mchunkptr)old_top;\n    size_t psize = (size_t)(csp - old_top);\n    mchunkptr tn = chunk_plus_offset(q, psize);\n    set_free_with_pinuse(q, psize, tn);\n    insert_chunk(m, q, psize);\n  }\n}\n\n/* -------------------------- System allocation -------------------------- */\n\nstatic void *alloc_sys(mstate m, size_t nb)\n{\n  char *tbase = CMFAIL;\n  size_t tsize = 0;\n\n  /* Directly map large chunks */\n  if (LJ_UNLIKELY(nb >= DEFAULT_MMAP_THRESHOLD)) {\n    void *mem = direct_alloc(m, nb);\n    if (mem != 0)\n      return mem;\n  }\n\n  {\n    size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;\n    size_t rsize = granularity_align(req);\n    if (LJ_LIKELY(rsize > nb)) { /* Fail if wraps around zero */\n      char *mp = (char *)(CALL_MMAP(m->prng, rsize));\n      if (mp != CMFAIL) {\n\ttbase = mp;\n\ttsize = rsize;\n      }\n    }\n  }\n\n  if (tbase != CMFAIL) {\n    msegmentptr sp = &m->seg;\n    /* Try to merge with an existing segment */\n    while (sp != 0 && tbase != sp->base + sp->size)\n      sp = sp->next;\n    if (sp != 0 && segment_holds(sp, m->top)) { /* append */\n      sp->size += tsize;\n      init_top(m, m->top, m->topsize + tsize);\n    } else {\n      sp = &m->seg;\n      while (sp != 0 && sp->base != tbase + tsize)\n\tsp = sp->next;\n      if (sp != 0) {\n\tchar *oldbase = sp->base;\n\tsp->base = tbase;\n\tsp->size += tsize;\n\treturn prepend_alloc(m, tbase, oldbase, nb);\n      } else {\n\tadd_segment(m, tbase, tsize);\n      }\n    }\n\n    if (nb < m->topsize) { /* Allocate from new or extended top space */\n      size_t rsize = m->topsize -= nb;\n      mchunkptr p = m->top;\n      mchunkptr r = m->top = chunk_plus_offset(p, nb);\n      r->head = rsize | PINUSE_BIT;\n      set_size_and_pinuse_of_inuse_chunk(m, p, nb);\n      return chunk2mem(p);\n    }\n  }\n\n  return NULL;\n}\n\n/* -----------------------  system deallocation -------------------------- */\n\n/* Unmap and unlink any mmapped segments that don't contain used chunks */\nstatic size_t release_unused_segments(mstate m)\n{\n  size_t released = 0;\n  size_t nsegs = 0;\n  msegmentptr pred = &m->seg;\n  msegmentptr sp = pred->next;\n  while (sp != 0) {\n    char *base = sp->base;\n    size_t size = sp->size;\n    msegmentptr next = sp->next;\n    nsegs++;\n    {\n      mchunkptr p = align_as_chunk(base);\n      size_t psize = chunksize(p);\n      /* Can unmap if first chunk holds entire segment and not pinned */\n      if (!cinuse(p) && (char *)p + psize >= base + size - TOP_FOOT_SIZE) {\n\ttchunkptr tp = (tchunkptr)p;\n\tif (p == m->dv) {\n\t  m->dv = 0;\n\t  m->dvsize = 0;\n\t} else {\n\t  unlink_large_chunk(m, tp);\n\t}\n\tif (CALL_MUNMAP(base, size) == 0) {\n\t  released += size;\n\t  /* unlink obsoleted record */\n\t  sp = pred;\n\t  sp->next = next;\n\t} else { /* back out if cannot unmap */\n\t  insert_large_chunk(m, tp, psize);\n\t}\n      }\n    }\n    pred = sp;\n    sp = next;\n  }\n  /* Reset check counter */\n  m->release_checks = nsegs > MAX_RELEASE_CHECK_RATE ?\n\t\t      nsegs : MAX_RELEASE_CHECK_RATE;\n  return released;\n}\n\nstatic int alloc_trim(mstate m, size_t pad)\n{\n  size_t released = 0;\n  if (pad < MAX_REQUEST && is_initialized(m)) {\n    pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */\n\n    if (m->topsize > pad) {\n      /* Shrink top space in granularity-size units, keeping at least one */\n      size_t unit = DEFAULT_GRANULARITY;\n      size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -\n\t\t      SIZE_T_ONE) * unit;\n      msegmentptr sp = segment_holding(m, (char *)m->top);\n\n      if (sp->size >= extra &&\n\t  !has_segment_link(m, sp)) { /* can't shrink if pinned */\n\tsize_t newsize = sp->size - extra;\n\t/* Prefer mremap, fall back to munmap */\n\tif ((CALL_MREMAP(sp->base, sp->size, newsize, CALL_MREMAP_NOMOVE) != MFAIL) ||\n\t    (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {\n\t  released = extra;\n\t}\n      }\n\n      if (released != 0) {\n\tsp->size -= released;\n\tinit_top(m, m->top, m->topsize - released);\n      }\n    }\n\n    /* Unmap any unused mmapped segments */\n    released += release_unused_segments(m);\n\n    /* On failure, disable autotrim to avoid repeated failed future calls */\n    if (released == 0 && m->topsize > m->trim_check)\n      m->trim_check = MAX_SIZE_T;\n  }\n\n  return (released != 0)? 1 : 0;\n}\n\n/* ---------------------------- malloc support --------------------------- */\n\n/* allocate a large request from the best fitting chunk in a treebin */\nstatic void *tmalloc_large(mstate m, size_t nb)\n{\n  tchunkptr v = 0;\n  size_t rsize = ~nb+1; /* Unsigned negation */\n  tchunkptr t;\n  bindex_t idx;\n  compute_tree_index(nb, idx);\n\n  if ((t = *treebin_at(m, idx)) != 0) {\n    /* Traverse tree for this bin looking for node with size == nb */\n    size_t sizebits = nb << leftshift_for_tree_index(idx);\n    tchunkptr rst = 0;  /* The deepest untaken right subtree */\n    for (;;) {\n      tchunkptr rt;\n      size_t trem = chunksize(t) - nb;\n      if (trem < rsize) {\n\tv = t;\n\tif ((rsize = trem) == 0)\n\t  break;\n      }\n      rt = t->child[1];\n      t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];\n      if (rt != 0 && rt != t)\n\trst = rt;\n      if (t == 0) {\n\tt = rst; /* set t to least subtree holding sizes > nb */\n\tbreak;\n      }\n      sizebits <<= 1;\n    }\n  }\n\n  if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */\n    binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;\n    if (leftbits != 0)\n      t = *treebin_at(m, lj_ffs(leftbits));\n  }\n\n  while (t != 0) { /* find smallest of tree or subtree */\n    size_t trem = chunksize(t) - nb;\n    if (trem < rsize) {\n      rsize = trem;\n      v = t;\n    }\n    t = leftmost_child(t);\n  }\n\n  /*  If dv is a better fit, return NULL so malloc will use it */\n  if (v != 0 && rsize < (size_t)(m->dvsize - nb)) {\n    mchunkptr r = chunk_plus_offset(v, nb);\n    unlink_large_chunk(m, v);\n    if (rsize < MIN_CHUNK_SIZE) {\n      set_inuse_and_pinuse(m, v, (rsize + nb));\n    } else {\n      set_size_and_pinuse_of_inuse_chunk(m, v, nb);\n      set_size_and_pinuse_of_free_chunk(r, rsize);\n      insert_chunk(m, r, rsize);\n    }\n    return chunk2mem(v);\n  }\n  return NULL;\n}\n\n/* allocate a small request from the best fitting chunk in a treebin */\nstatic void *tmalloc_small(mstate m, size_t nb)\n{\n  tchunkptr t, v;\n  mchunkptr r;\n  size_t rsize;\n  bindex_t i = lj_ffs(m->treemap);\n\n  v = t = *treebin_at(m, i);\n  rsize = chunksize(t) - nb;\n\n  while ((t = leftmost_child(t)) != 0) {\n    size_t trem = chunksize(t) - nb;\n    if (trem < rsize) {\n      rsize = trem;\n      v = t;\n    }\n  }\n\n  r = chunk_plus_offset(v, nb);\n  unlink_large_chunk(m, v);\n  if (rsize < MIN_CHUNK_SIZE) {\n    set_inuse_and_pinuse(m, v, (rsize + nb));\n  } else {\n    set_size_and_pinuse_of_inuse_chunk(m, v, nb);\n    set_size_and_pinuse_of_free_chunk(r, rsize);\n    replace_dv(m, r, rsize);\n  }\n  return chunk2mem(v);\n}\n\n/* ----------------------------------------------------------------------- */\n\nvoid *lj_alloc_create(PRNGState *rs)\n{\n  size_t tsize = DEFAULT_GRANULARITY;\n  char *tbase;\n  INIT_MMAP();\n  UNUSED(rs);\n  tbase = (char *)(CALL_MMAP(rs, tsize));\n  if (tbase != CMFAIL) {\n    size_t msize = pad_request(sizeof(struct malloc_state));\n    mchunkptr mn;\n    mchunkptr msp = align_as_chunk(tbase);\n    mstate m = (mstate)(chunk2mem(msp));\n    memset(m, 0, msize);\n    msp->head = (msize|PINUSE_BIT|CINUSE_BIT);\n    m->seg.base = tbase;\n    m->seg.size = tsize;\n    m->release_checks = MAX_RELEASE_CHECK_RATE;\n    init_bins(m);\n    mn = next_chunk(mem2chunk(m));\n    init_top(m, mn, (size_t)((tbase + tsize) - (char *)mn) - TOP_FOOT_SIZE);\n    return m;\n  }\n  return NULL;\n}\n\nvoid lj_alloc_setprng(void *msp, PRNGState *rs)\n{\n  mstate ms = (mstate)msp;\n  ms->prng = rs;\n}\n\nvoid lj_alloc_destroy(void *msp)\n{\n  mstate ms = (mstate)msp;\n  msegmentptr sp = &ms->seg;\n  while (sp != 0) {\n    char *base = sp->base;\n    size_t size = sp->size;\n    sp = sp->next;\n    CALL_MUNMAP(base, size);\n  }\n}\n\nstatic LJ_NOINLINE void *lj_alloc_malloc(void *msp, size_t nsize)\n{\n  mstate ms = (mstate)msp;\n  void *mem;\n  size_t nb;\n  if (nsize <= MAX_SMALL_REQUEST) {\n    bindex_t idx;\n    binmap_t smallbits;\n    nb = (nsize < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(nsize);\n    idx = small_index(nb);\n    smallbits = ms->smallmap >> idx;\n\n    if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */\n      mchunkptr b, p;\n      idx += ~smallbits & 1;       /* Uses next bin if idx empty */\n      b = smallbin_at(ms, idx);\n      p = b->fd;\n      unlink_first_small_chunk(ms, b, p, idx);\n      set_inuse_and_pinuse(ms, p, small_index2size(idx));\n      mem = chunk2mem(p);\n      return mem;\n    } else if (nb > ms->dvsize) {\n      if (smallbits != 0) { /* Use chunk in next nonempty smallbin */\n\tmchunkptr b, p, r;\n\tsize_t rsize;\n\tbinmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx));\n\tbindex_t i = lj_ffs(leftbits);\n\tb = smallbin_at(ms, i);\n\tp = b->fd;\n\tunlink_first_small_chunk(ms, b, p, i);\n\trsize = small_index2size(i) - nb;\n\t/* Fit here cannot be remainderless if 4byte sizes */\n\tif (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) {\n\t  set_inuse_and_pinuse(ms, p, small_index2size(i));\n\t} else {\n\t  set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n\t  r = chunk_plus_offset(p, nb);\n\t  set_size_and_pinuse_of_free_chunk(r, rsize);\n\t  replace_dv(ms, r, rsize);\n\t}\n\tmem = chunk2mem(p);\n\treturn mem;\n      } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) {\n\treturn mem;\n      }\n    }\n  } else if (nsize >= MAX_REQUEST) {\n    nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */\n  } else {\n    nb = pad_request(nsize);\n    if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) {\n      return mem;\n    }\n  }\n\n  if (nb <= ms->dvsize) {\n    size_t rsize = ms->dvsize - nb;\n    mchunkptr p = ms->dv;\n    if (rsize >= MIN_CHUNK_SIZE) { /* split dv */\n      mchunkptr r = ms->dv = chunk_plus_offset(p, nb);\n      ms->dvsize = rsize;\n      set_size_and_pinuse_of_free_chunk(r, rsize);\n      set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n    } else { /* exhaust dv */\n      size_t dvs = ms->dvsize;\n      ms->dvsize = 0;\n      ms->dv = 0;\n      set_inuse_and_pinuse(ms, p, dvs);\n    }\n    mem = chunk2mem(p);\n    return mem;\n  } else if (nb < ms->topsize) { /* Split top */\n    size_t rsize = ms->topsize -= nb;\n    mchunkptr p = ms->top;\n    mchunkptr r = ms->top = chunk_plus_offset(p, nb);\n    r->head = rsize | PINUSE_BIT;\n    set_size_and_pinuse_of_inuse_chunk(ms, p, nb);\n    mem = chunk2mem(p);\n    return mem;\n  }\n  return alloc_sys(ms, nb);\n}\n\nstatic LJ_NOINLINE void *lj_alloc_free(void *msp, void *ptr)\n{\n  if (ptr != 0) {\n    mchunkptr p = mem2chunk(ptr);\n    mstate fm = (mstate)msp;\n    size_t psize = chunksize(p);\n    mchunkptr next = chunk_plus_offset(p, psize);\n    if (!pinuse(p)) {\n      size_t prevsize = p->prev_foot;\n      if ((prevsize & IS_DIRECT_BIT) != 0) {\n\tprevsize &= ~IS_DIRECT_BIT;\n\tpsize += prevsize + DIRECT_FOOT_PAD;\n\tCALL_MUNMAP((char *)p - prevsize, psize);\n\treturn NULL;\n      } else {\n\tmchunkptr prev = chunk_minus_offset(p, prevsize);\n\tpsize += prevsize;\n\tp = prev;\n\t/* consolidate backward */\n\tif (p != fm->dv) {\n\t  unlink_chunk(fm, p, prevsize);\n\t} else if ((next->head & INUSE_BITS) == INUSE_BITS) {\n\t  fm->dvsize = psize;\n\t  set_free_with_pinuse(p, psize, next);\n\t  return NULL;\n\t}\n      }\n    }\n    if (!cinuse(next)) {  /* consolidate forward */\n      if (next == fm->top) {\n\tsize_t tsize = fm->topsize += psize;\n\tfm->top = p;\n\tp->head = tsize | PINUSE_BIT;\n\tif (p == fm->dv) {\n\t  fm->dv = 0;\n\t  fm->dvsize = 0;\n\t}\n\tif (tsize > fm->trim_check)\n\t  alloc_trim(fm, 0);\n\treturn NULL;\n      } else if (next == fm->dv) {\n\tsize_t dsize = fm->dvsize += psize;\n\tfm->dv = p;\n\tset_size_and_pinuse_of_free_chunk(p, dsize);\n\treturn NULL;\n      } else {\n\tsize_t nsize = chunksize(next);\n\tpsize += nsize;\n\tunlink_chunk(fm, next, nsize);\n\tset_size_and_pinuse_of_free_chunk(p, psize);\n\tif (p == fm->dv) {\n\t  fm->dvsize = psize;\n\t  return NULL;\n\t}\n      }\n    } else {\n      set_free_with_pinuse(p, psize, next);\n    }\n\n    if (is_small(psize)) {\n      insert_small_chunk(fm, p, psize);\n    } else {\n      tchunkptr tp = (tchunkptr)p;\n      insert_large_chunk(fm, tp, psize);\n      if (--fm->release_checks == 0)\n\trelease_unused_segments(fm);\n    }\n  }\n  return NULL;\n}\n\nstatic LJ_NOINLINE void *lj_alloc_realloc(void *msp, void *ptr, size_t nsize)\n{\n  if (nsize >= MAX_REQUEST) {\n    return NULL;\n  } else {\n    mstate m = (mstate)msp;\n    mchunkptr oldp = mem2chunk(ptr);\n    size_t oldsize = chunksize(oldp);\n    mchunkptr next = chunk_plus_offset(oldp, oldsize);\n    mchunkptr newp = 0;\n    size_t nb = request2size(nsize);\n\n    /* Try to either shrink or extend into top. Else malloc-copy-free */\n    if (is_direct(oldp)) {\n      newp = direct_resize(oldp, nb);  /* this may return NULL. */\n    } else if (oldsize >= nb) { /* already big enough */\n      size_t rsize = oldsize - nb;\n      newp = oldp;\n      if (rsize >= MIN_CHUNK_SIZE) {\n\tmchunkptr rem = chunk_plus_offset(newp, nb);\n\tset_inuse(m, newp, nb);\n\tset_inuse(m, rem, rsize);\n\tlj_alloc_free(m, chunk2mem(rem));\n      }\n    } else if (next == m->top && oldsize + m->topsize > nb) {\n      /* Expand into top */\n      size_t newsize = oldsize + m->topsize;\n      size_t newtopsize = newsize - nb;\n      mchunkptr newtop = chunk_plus_offset(oldp, nb);\n      set_inuse(m, oldp, nb);\n      newtop->head = newtopsize |PINUSE_BIT;\n      m->top = newtop;\n      m->topsize = newtopsize;\n      newp = oldp;\n    }\n\n    if (newp != 0) {\n      return chunk2mem(newp);\n    } else {\n      void *newmem = lj_alloc_malloc(m, nsize);\n      if (newmem != 0) {\n\tsize_t oc = oldsize - overhead_for(oldp);\n\tmemcpy(newmem, ptr, oc < nsize ? oc : nsize);\n\tlj_alloc_free(m, ptr);\n      }\n      return newmem;\n    }\n  }\n}\n\nvoid *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize)\n{\n  (void)osize;\n  if (nsize == 0) {\n    return lj_alloc_free(msp, ptr);\n  } else if (ptr == NULL) {\n    return lj_alloc_malloc(msp, nsize);\n  } else {\n    return lj_alloc_realloc(msp, ptr, nsize);\n  }\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_alloc.h",
    "content": "/*\n** Bundled memory allocator.\n** Donated to the public domain.\n*/\n\n#ifndef _LJ_ALLOC_H\n#define _LJ_ALLOC_H\n\n#include \"lj_def.h\"\n\n#ifndef LUAJIT_USE_SYSMALLOC\nLJ_FUNC void *lj_alloc_create(PRNGState *rs);\nLJ_FUNC void lj_alloc_setprng(void *msp, PRNGState *rs);\nLJ_FUNC void lj_alloc_destroy(void *msp);\nLJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_api.c",
    "content": "/*\n** Public Lua/C API.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_api_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_udata.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#include \"lj_frame.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Common helper functions --------------------------------------------- */\n\n#define lj_checkapi_slot(idx) \\\n  lj_checkapi((idx) <= (L->top - L->base), \"stack slot %d out of range\", (idx))\n\nstatic TValue *index2adr(lua_State *L, int idx)\n{\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    return o < L->top ? o : niltv(L);\n  } else if (idx > LUA_REGISTRYINDEX) {\n    lj_checkapi(idx != 0 && -idx <= L->top - L->base,\n\t\t\"bad stack slot %d\", idx);\n    return L->top + idx;\n  } else if (idx == LUA_GLOBALSINDEX) {\n    TValue *o = &G(L)->tmptv;\n    settabV(L, o, tabref(L->env));\n    return o;\n  } else if (idx == LUA_REGISTRYINDEX) {\n    return registry(L);\n  } else {\n    GCfunc *fn = curr_func(L);\n    lj_checkapi(fn->c.gct == ~LJ_TFUNC && !isluafunc(fn),\n\t\t\"calling frame is not a C function\");\n    if (idx == LUA_ENVIRONINDEX) {\n      TValue *o = &G(L)->tmptv;\n      settabV(L, o, tabref(fn->c.env));\n      return o;\n    } else {\n      idx = LUA_GLOBALSINDEX - idx;\n      return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L);\n    }\n  }\n}\n\nstatic LJ_AINLINE TValue *index2adr_check(lua_State *L, int idx)\n{\n  TValue *o = index2adr(L, idx);\n  lj_checkapi(o != niltv(L), \"invalid stack slot %d\", idx);\n  return o;\n}\n\nstatic TValue *index2adr_stack(lua_State *L, int idx)\n{\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    if (o < L->top) {\n      return o;\n    } else {\n      lj_checkapi(0, \"invalid stack slot %d\", idx);\n      return niltv(L);\n    }\n    return o < L->top ? o : niltv(L);\n  } else {\n    lj_checkapi(idx != 0 && -idx <= L->top - L->base,\n\t\t\"invalid stack slot %d\", idx);\n    return L->top + idx;\n  }\n}\n\nstatic GCtab *getcurrenv(lua_State *L)\n{\n  GCfunc *fn = curr_func(L);\n  return fn->c.gct == ~LJ_TFUNC ? tabref(fn->c.env) : tabref(L->env);\n}\n\n/* -- Miscellaneous API functions ----------------------------------------- */\n\nLUA_API int lua_status(lua_State *L)\n{\n  return L->status;\n}\n\nLUA_API int lua_checkstack(lua_State *L, int size)\n{\n  if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) {\n    return 0;  /* Stack overflow. */\n  } else if (size > 0) {\n    lj_state_checkstack(L, (MSize)size);\n  }\n  return 1;\n}\n\nLUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg)\n{\n  if (!lua_checkstack(L, size))\n    lj_err_callerv(L, LJ_ERR_STKOVM, msg);\n}\n\nLUA_API void lua_xmove(lua_State *L, lua_State *to, int n)\n{\n  TValue *f, *t;\n  if (L == to) return;\n  lj_checkapi_slot(n);\n  lj_checkapi(G(L) == G(to), \"move across global states\");\n  lj_state_checkstack(to, (MSize)n);\n  f = L->top;\n  t = to->top = to->top + n;\n  while (--n >= 0) copyTV(to, --t, --f);\n  L->top = f;\n}\n\nLUA_API const lua_Number *lua_version(lua_State *L)\n{\n  static const lua_Number version = LUA_VERSION_NUM;\n  UNUSED(L);\n  return &version;\n}\n\n/* -- Stack manipulation -------------------------------------------------- */\n\nLUA_API int lua_gettop(lua_State *L)\n{\n  return (int)(L->top - L->base);\n}\n\nLUA_API void lua_settop(lua_State *L, int idx)\n{\n  if (idx >= 0) {\n    lj_checkapi(idx <= tvref(L->maxstack) - L->base, \"bad stack slot %d\", idx);\n    if (L->base + idx > L->top) {\n      if (L->base + idx >= tvref(L->maxstack))\n\tlj_state_growstack(L, (MSize)idx - (MSize)(L->top - L->base));\n      do { setnilV(L->top++); } while (L->top < L->base + idx);\n    } else {\n      L->top = L->base + idx;\n    }\n  } else {\n    lj_checkapi(-(idx+1) <= (L->top - L->base), \"bad stack slot %d\", idx);\n    L->top += idx+1;  /* Shrinks top (idx < 0). */\n  }\n}\n\nLUA_API void lua_remove(lua_State *L, int idx)\n{\n  TValue *p = index2adr_stack(L, idx);\n  while (++p < L->top) copyTV(L, p-1, p);\n  L->top--;\n}\n\nLUA_API void lua_insert(lua_State *L, int idx)\n{\n  TValue *q, *p = index2adr_stack(L, idx);\n  for (q = L->top; q > p; q--) copyTV(L, q, q-1);\n  copyTV(L, p, L->top);\n}\n\nstatic void copy_slot(lua_State *L, TValue *f, int idx)\n{\n  if (idx == LUA_GLOBALSINDEX) {\n    lj_checkapi(tvistab(f), \"stack slot %d is not a table\", idx);\n    /* NOBARRIER: A thread (i.e. L) is never black. */\n    setgcref(L->env, obj2gco(tabV(f)));\n  } else if (idx == LUA_ENVIRONINDEX) {\n    GCfunc *fn = curr_func(L);\n    if (fn->c.gct != ~LJ_TFUNC)\n      lj_err_msg(L, LJ_ERR_NOENV);\n    lj_checkapi(tvistab(f), \"stack slot %d is not a table\", idx);\n    setgcref(fn->c.env, obj2gco(tabV(f)));\n    lj_gc_barrier(L, fn, f);\n  } else {\n    TValue *o = index2adr_check(L, idx);\n    copyTV(L, o, f);\n    if (idx < LUA_GLOBALSINDEX)  /* Need a barrier for upvalues. */\n      lj_gc_barrier(L, curr_func(L), f);\n  }\n}\n\nLUA_API void lua_replace(lua_State *L, int idx)\n{\n  lj_checkapi_slot(1);\n  copy_slot(L, L->top - 1, idx);\n  L->top--;\n}\n\nLUA_API void lua_copy(lua_State *L, int fromidx, int toidx)\n{\n  copy_slot(L, index2adr(L, fromidx), toidx);\n}\n\nLUA_API void lua_pushvalue(lua_State *L, int idx)\n{\n  copyTV(L, L->top, index2adr(L, idx));\n  incr_top(L);\n}\n\n/* -- Stack getters ------------------------------------------------------- */\n\nLUA_API int lua_type(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisnumber(o)) {\n    return LUA_TNUMBER;\n#if LJ_64 && !LJ_GC64\n  } else if (tvislightud(o)) {\n    return LUA_TLIGHTUSERDATA;\n#endif\n  } else if (o == niltv(L)) {\n    return LUA_TNONE;\n  } else {  /* Magic internal/external tag conversion. ORDER LJ_T */\n    uint32_t t = ~itype(o);\n#if LJ_64\n    int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u);\n#else\n    int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u);\n#endif\n    lj_assertL(tt != LUA_TNIL || tvisnil(o), \"bad tag conversion\");\n    return tt;\n  }\n}\n\nLUALIB_API void luaL_checktype(lua_State *L, int idx, int tt)\n{\n  if (lua_type(L, idx) != tt)\n    lj_err_argt(L, idx, tt);\n}\n\nLUALIB_API void luaL_checkany(lua_State *L, int idx)\n{\n  if (index2adr(L, idx) == niltv(L))\n    lj_err_arg(L, idx, LJ_ERR_NOVAL);\n}\n\nLUA_API const char *lua_typename(lua_State *L, int t)\n{\n  UNUSED(L);\n  return lj_obj_typename[t+1];\n}\n\nLUA_API int lua_iscfunction(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return tvisfunc(o) && !isluafunc(funcV(o));\n}\n\nLUA_API int lua_isnumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  return (tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), &tmp)));\n}\n\nLUA_API int lua_isstring(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (tvisstr(o) || tvisnumber(o));\n}\n\nLUA_API int lua_isuserdata(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (tvisudata(o) || tvislightud(o));\n}\n\nLUA_API int lua_rawequal(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  return (o1 == niltv(L) || o2 == niltv(L)) ? 0 : lj_obj_equal(o1, o2);\n}\n\nLUA_API int lua_equal(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  if (tvisint(o1) && tvisint(o2)) {\n    return intV(o1) == intV(o2);\n  } else if (tvisnumber(o1) && tvisnumber(o2)) {\n    return numberVnum(o1) == numberVnum(o2);\n  } else if (itype(o1) != itype(o2)) {\n    return 0;\n  } else if (tvispri(o1)) {\n    return o1 != niltv(L) && o2 != niltv(L);\n#if LJ_64 && !LJ_GC64\n  } else if (tvislightud(o1)) {\n    return o1->u64 == o2->u64;\n#endif\n  } else if (gcrefeq(o1->gcr, o2->gcr)) {\n    return 1;\n  } else if (!tvistabud(o1)) {\n    return 0;\n  } else {\n    TValue *base = lj_meta_equal(L, gcV(o1), gcV(o2), 0);\n    if ((uintptr_t)base <= 1) {\n      return (int)(uintptr_t)base;\n    } else {\n      L->top = base+2;\n      lj_vm_call(L, base, 1+1);\n      L->top -= 2+LJ_FR2;\n      return tvistruecond(L->top+1+LJ_FR2);\n    }\n  }\n}\n\nLUA_API int lua_lessthan(lua_State *L, int idx1, int idx2)\n{\n  cTValue *o1 = index2adr(L, idx1);\n  cTValue *o2 = index2adr(L, idx2);\n  if (o1 == niltv(L) || o2 == niltv(L)) {\n    return 0;\n  } else if (tvisint(o1) && tvisint(o2)) {\n    return intV(o1) < intV(o2);\n  } else if (tvisnumber(o1) && tvisnumber(o2)) {\n    return numberVnum(o1) < numberVnum(o2);\n  } else {\n    TValue *base = lj_meta_comp(L, o1, o2, 0);\n    if ((uintptr_t)base <= 1) {\n      return (int)(uintptr_t)base;\n    } else {\n      L->top = base+2;\n      lj_vm_call(L, base, 1+1);\n      L->top -= 2+LJ_FR2;\n      return tvistruecond(L->top+1+LJ_FR2);\n    }\n  }\n}\n\nLUA_API lua_Number lua_tonumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp))\n    return numV(&tmp);\n  else\n    return 0;\n}\n\nLUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *ok)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o))) {\n    if (ok) *ok = 1;\n    return numberVnum(o);\n  } else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp)) {\n    if (ok) *ok = 1;\n    return numV(&tmp);\n  } else {\n    if (ok) *ok = 0;\n    return 0;\n  }\n}\n\nLUALIB_API lua_Number luaL_checknumber(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))\n    lj_err_argt(L, idx, LUA_TNUMBER);\n  return numV(&tmp);\n}\n\nLUALIB_API lua_Number luaL_optnumber(lua_State *L, int idx, lua_Number def)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  if (LJ_LIKELY(tvisnumber(o)))\n    return numberVnum(o);\n  else if (tvisnil(o))\n    return def;\n  else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))\n    lj_err_argt(L, idx, LUA_TNUMBER);\n  return numV(&tmp);\n}\n\nLUA_API lua_Integer lua_tointeger(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      return 0;\n    if (tvisint(&tmp))\n      return intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *ok)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    if (ok) *ok = 1;\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp))) {\n      if (ok) *ok = 0;\n      return 0;\n    }\n    if (tvisint(&tmp)) {\n      if (ok) *ok = 1;\n      return intV(&tmp);\n    }\n    n = numV(&tmp);\n  }\n  if (ok) *ok = 1;\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      lj_err_argt(L, idx, LUA_TNUMBER);\n    if (tvisint(&tmp))\n      return (lua_Integer)intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def)\n{\n  cTValue *o = index2adr(L, idx);\n  TValue tmp;\n  lua_Number n;\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    n = numV(o);\n  } else if (tvisnil(o)) {\n    return def;\n  } else {\n    if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))\n      lj_err_argt(L, idx, LUA_TNUMBER);\n    if (tvisint(&tmp))\n      return (lua_Integer)intV(&tmp);\n    n = numV(&tmp);\n  }\n#if LJ_64\n  return (lua_Integer)n;\n#else\n  return lj_num2int(n);\n#endif\n}\n\nLUA_API int lua_toboolean(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return tvistruecond(o);\n}\n\nLUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    if (len != NULL) *len = 0;\n    return NULL;\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    lj_err_argt(L, idx, LUA_TSTRING);\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API const char *luaL_optlstring(lua_State *L, int idx,\n\t\t\t\t       const char *def, size_t *len)\n{\n  TValue *o = index2adr(L, idx);\n  GCstr *s;\n  if (LJ_LIKELY(tvisstr(o))) {\n    s = strV(o);\n  } else if (tvisnil(o)) {\n    if (len != NULL) *len = def ? strlen(def) : 0;\n    return def;\n  } else if (tvisnumber(o)) {\n    lj_gc_check(L);\n    o = index2adr(L, idx);  /* GC may move the stack. */\n    s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n  } else {\n    lj_err_argt(L, idx, LUA_TSTRING);\n  }\n  if (len != NULL) *len = s->len;\n  return strdata(s);\n}\n\nLUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def,\n\t\t\t\tconst char *const lst[])\n{\n  ptrdiff_t i;\n  const char *s = lua_tolstring(L, idx, NULL);\n  if (s == NULL && (s = def) == NULL)\n    lj_err_argt(L, idx, LUA_TSTRING);\n  for (i = 0; lst[i]; i++)\n    if (strcmp(lst[i], s) == 0)\n      return (int)i;\n  lj_err_argv(L, idx, LJ_ERR_INVOPTM, s);\n}\n\nLUA_API size_t lua_objlen(lua_State *L, int idx)\n{\n  TValue *o = index2adr(L, idx);\n  if (tvisstr(o)) {\n    return strV(o)->len;\n  } else if (tvistab(o)) {\n    return (size_t)lj_tab_len(tabV(o));\n  } else if (tvisudata(o)) {\n    return udataV(o)->len;\n  } else if (tvisnumber(o)) {\n    GCstr *s = lj_strfmt_number(L, o);\n    setstrV(L, o, s);\n    return s->len;\n  } else {\n    return 0;\n  }\n}\n\nLUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisfunc(o)) {\n    BCOp op = bc_op(*mref(funcV(o)->c.pc, BCIns));\n    if (op == BC_FUNCC || op == BC_FUNCCW)\n      return funcV(o)->c.f;\n  }\n  return NULL;\n}\n\nLUA_API void *lua_touserdata(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisudata(o))\n    return uddata(udataV(o));\n  else if (tvislightud(o))\n    return lightudV(G(L), o);\n  else\n    return NULL;\n}\n\nLUA_API lua_State *lua_tothread(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  return (!tvisthread(o)) ? NULL : threadV(o);\n}\n\nLUA_API const void *lua_topointer(lua_State *L, int idx)\n{\n  return lj_obj_ptr(G(L), index2adr(L, idx));\n}\n\n/* -- Stack setters (object creation) ------------------------------------- */\n\nLUA_API void lua_pushnil(lua_State *L)\n{\n  setnilV(L->top);\n  incr_top(L);\n}\n\nLUA_API void lua_pushnumber(lua_State *L, lua_Number n)\n{\n  setnumV(L->top, n);\n  if (LJ_UNLIKELY(tvisnan(L->top)))\n    setnanV(L->top);  /* Canonicalize injected NaNs. */\n  incr_top(L);\n}\n\nLUA_API void lua_pushinteger(lua_State *L, lua_Integer n)\n{\n  setintptrV(L->top, n);\n  incr_top(L);\n}\n\nLUA_API void lua_pushlstring(lua_State *L, const char *str, size_t len)\n{\n  GCstr *s;\n  lj_gc_check(L);\n  s = lj_str_new(L, str, len);\n  setstrV(L, L->top, s);\n  incr_top(L);\n}\n\nLUA_API void lua_pushstring(lua_State *L, const char *str)\n{\n  if (str == NULL) {\n    setnilV(L->top);\n  } else {\n    GCstr *s;\n    lj_gc_check(L);\n    s = lj_str_newz(L, str);\n    setstrV(L, L->top, s);\n  }\n  incr_top(L);\n}\n\nLUA_API const char *lua_pushvfstring(lua_State *L, const char *fmt,\n\t\t\t\t     va_list argp)\n{\n  lj_gc_check(L);\n  return lj_strfmt_pushvf(L, fmt, argp);\n}\n\nLUA_API const char *lua_pushfstring(lua_State *L, const char *fmt, ...)\n{\n  const char *ret;\n  va_list argp;\n  lj_gc_check(L);\n  va_start(argp, fmt);\n  ret = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  return ret;\n}\n\nLUA_API void lua_pushcclosure(lua_State *L, lua_CFunction f, int n)\n{\n  GCfunc *fn;\n  lj_gc_check(L);\n  lj_checkapi_slot(n);\n  fn = lj_func_newC(L, (MSize)n, getcurrenv(L));\n  fn->c.f = f;\n  L->top -= n;\n  while (n--)\n    copyTV(L, &fn->c.upvalue[n], L->top+n);\n  setfuncV(L, L->top, fn);\n  lj_assertL(iswhite(obj2gco(fn)), \"new GC object is not white\");\n  incr_top(L);\n}\n\nLUA_API void lua_pushboolean(lua_State *L, int b)\n{\n  setboolV(L->top, (b != 0));\n  incr_top(L);\n}\n\nLUA_API void lua_pushlightuserdata(lua_State *L, void *p)\n{\n#if LJ_64\n  p = lj_lightud_intern(L, p);\n#endif\n  setrawlightudV(L->top, p);\n  incr_top(L);\n}\n\nLUA_API void lua_createtable(lua_State *L, int narray, int nrec)\n{\n  lj_gc_check(L);\n  settabV(L, L->top, lj_tab_new_ah(L, narray, nrec));\n  incr_top(L);\n}\n\nLUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)\n{\n  GCtab *regt = tabV(registry(L));\n  TValue *tv = lj_tab_setstr(L, regt, lj_str_newz(L, tname));\n  if (tvisnil(tv)) {\n    GCtab *mt = lj_tab_new(L, 0, 1);\n    settabV(L, tv, mt);\n    settabV(L, L->top++, mt);\n    lj_gc_anybarriert(L, regt);\n    return 1;\n  } else {\n    copyTV(L, L->top++, tv);\n    return 0;\n  }\n}\n\nLUA_API int lua_pushthread(lua_State *L)\n{\n  setthreadV(L, L->top, L);\n  incr_top(L);\n  return (mainthread(G(L)) == L);\n}\n\nLUA_API lua_State *lua_newthread(lua_State *L)\n{\n  lua_State *L1;\n  lj_gc_check(L);\n  L1 = lj_state_new(L);\n  setthreadV(L, L->top, L1);\n  incr_top(L);\n  return L1;\n}\n\nLUA_API void *lua_newuserdata(lua_State *L, size_t size)\n{\n  GCudata *ud;\n  lj_gc_check(L);\n  if (size > LJ_MAX_UDATA)\n    lj_err_msg(L, LJ_ERR_UDATAOV);\n  ud = lj_udata_new(L, (MSize)size, getcurrenv(L));\n  setudataV(L, L->top, ud);\n  incr_top(L);\n  return uddata(ud);\n}\n\nLUA_API void lua_concat(lua_State *L, int n)\n{\n  lj_checkapi_slot(n);\n  if (n >= 2) {\n    n--;\n    do {\n      TValue *top = lj_meta_cat(L, L->top-1, -n);\n      if (top == NULL) {\n\tL->top -= n;\n\tbreak;\n      }\n      n -= (int)(L->top - top);\n      L->top = top+2;\n      lj_vm_call(L, top, 1+1);\n      L->top -= 1+LJ_FR2;\n      copyTV(L, L->top-1, L->top+LJ_FR2);\n    } while (--n > 0);\n  } else if (n == 0) {  /* Push empty string. */\n    setstrV(L, L->top, &G(L)->strempty);\n    incr_top(L);\n  }\n  /* else n == 1: nothing to do. */\n}\n\n/* -- Object getters ------------------------------------------------------ */\n\nLUA_API void lua_gettable(lua_State *L, int idx)\n{\n  cTValue *t = index2adr_check(L, idx);\n  cTValue *v = lj_meta_tget(L, t, L->top-1);\n  if (v == NULL) {\n    L->top += 2;\n    lj_vm_call(L, L->top-2, 1+1);\n    L->top -= 2+LJ_FR2;\n    v = L->top+1+LJ_FR2;\n  }\n  copyTV(L, L->top-1, v);\n}\n\nLUA_API void lua_getfield(lua_State *L, int idx, const char *k)\n{\n  cTValue *v, *t = index2adr_check(L, idx);\n  TValue key;\n  setstrV(L, &key, lj_str_newz(L, k));\n  v = lj_meta_tget(L, t, &key);\n  if (v == NULL) {\n    L->top += 2;\n    lj_vm_call(L, L->top-2, 1+1);\n    L->top -= 2+LJ_FR2;\n    v = L->top+1+LJ_FR2;\n  }\n  copyTV(L, L->top, v);\n  incr_top(L);\n}\n\nLUA_API void lua_rawget(lua_State *L, int idx)\n{\n  cTValue *t = index2adr(L, idx);\n  lj_checkapi(tvistab(t), \"stack slot %d is not a table\", idx);\n  copyTV(L, L->top-1, lj_tab_get(L, tabV(t), L->top-1));\n}\n\nLUA_API void lua_rawgeti(lua_State *L, int idx, int n)\n{\n  cTValue *v, *t = index2adr(L, idx);\n  lj_checkapi(tvistab(t), \"stack slot %d is not a table\", idx);\n  v = lj_tab_getint(tabV(t), n);\n  if (v) {\n    copyTV(L, L->top, v);\n  } else {\n    setnilV(L->top);\n  }\n  incr_top(L);\n}\n\nLUA_API int lua_getmetatable(lua_State *L, int idx)\n{\n  cTValue *o = index2adr(L, idx);\n  GCtab *mt = NULL;\n  if (tvistab(o))\n    mt = tabref(tabV(o)->metatable);\n  else if (tvisudata(o))\n    mt = tabref(udataV(o)->metatable);\n  else\n    mt = tabref(basemt_obj(G(L), o));\n  if (mt == NULL)\n    return 0;\n  settabV(L, L->top, mt);\n  incr_top(L);\n  return 1;\n}\n\nLUALIB_API int luaL_getmetafield(lua_State *L, int idx, const char *field)\n{\n  if (lua_getmetatable(L, idx)) {\n    cTValue *tv = lj_tab_getstr(tabV(L->top-1), lj_str_newz(L, field));\n    if (tv && !tvisnil(tv)) {\n      copyTV(L, L->top-1, tv);\n      return 1;\n    }\n    L->top--;\n  }\n  return 0;\n}\n\nLUA_API void lua_getfenv(lua_State *L, int idx)\n{\n  cTValue *o = index2adr_check(L, idx);\n  if (tvisfunc(o)) {\n    settabV(L, L->top, tabref(funcV(o)->c.env));\n  } else if (tvisudata(o)) {\n    settabV(L, L->top, tabref(udataV(o)->env));\n  } else if (tvisthread(o)) {\n    settabV(L, L->top, tabref(threadV(o)->env));\n  } else {\n    setnilV(L->top);\n  }\n  incr_top(L);\n}\n\nLUA_API int lua_next(lua_State *L, int idx)\n{\n  cTValue *t = index2adr(L, idx);\n  int more;\n  lj_checkapi(tvistab(t), \"stack slot %d is not a table\", idx);\n  more = lj_tab_next(tabV(t), L->top-1, L->top-1);\n  if (more > 0) {\n    incr_top(L);  /* Return new key and value slot. */\n  } else if (!more) {  /* End of traversal. */\n    L->top--;  /* Remove key slot. */\n  } else {\n    lj_err_msg(L, LJ_ERR_NEXTIDX);\n  }\n  return more;\n}\n\nLUA_API const char *lua_getupvalue(lua_State *L, int idx, int n)\n{\n  TValue *val;\n  GCobj *o;\n  const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val, &o);\n  if (name) {\n    copyTV(L, L->top, val);\n    incr_top(L);\n  }\n  return name;\n}\n\nLUA_API void *lua_upvalueid(lua_State *L, int idx, int n)\n{\n  GCfunc *fn = funcV(index2adr(L, idx));\n  n--;\n  lj_checkapi((uint32_t)n < fn->l.nupvalues, \"bad upvalue %d\", n);\n  return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :\n\t\t\t (void *)&fn->c.upvalue[n];\n}\n\nLUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2)\n{\n  GCfunc *fn1 = funcV(index2adr(L, idx1));\n  GCfunc *fn2 = funcV(index2adr(L, idx2));\n  n1--; n2--;\n  lj_checkapi(isluafunc(fn1), \"stack slot %d is not a Lua function\", idx1);\n  lj_checkapi(isluafunc(fn2), \"stack slot %d is not a Lua function\", idx2);\n  lj_checkapi((uint32_t)n1 < fn1->l.nupvalues, \"bad upvalue %d\", n1+1);\n  lj_checkapi((uint32_t)n2 < fn2->l.nupvalues, \"bad upvalue %d\", n2+1);\n  setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]);\n  lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1]));\n}\n\nLUALIB_API void *luaL_testudata(lua_State *L, int idx, const char *tname)\n{\n  cTValue *o = index2adr(L, idx);\n  if (tvisudata(o)) {\n    GCudata *ud = udataV(o);\n    cTValue *tv = lj_tab_getstr(tabV(registry(L)), lj_str_newz(L, tname));\n    if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable))\n      return uddata(ud);\n  }\n  return NULL;  /* value is not a userdata with a metatable */\n}\n\nLUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)\n{\n  void *p = luaL_testudata(L, idx, tname);\n  if (!p) lj_err_argtype(L, idx, tname);\n  return p;\n}\n\n/* -- Object setters ------------------------------------------------------ */\n\nLUA_API void lua_settable(lua_State *L, int idx)\n{\n  TValue *o;\n  cTValue *t = index2adr_check(L, idx);\n  lj_checkapi_slot(2);\n  o = lj_meta_tset(L, t, L->top-2);\n  if (o) {\n    /* NOBARRIER: lj_meta_tset ensures the table is not black. */\n    L->top -= 2;\n    copyTV(L, o, L->top+1);\n  } else {\n    TValue *base = L->top;\n    copyTV(L, base+2, base-3-2*LJ_FR2);\n    L->top = base+3;\n    lj_vm_call(L, base, 0+1);\n    L->top -= 3+LJ_FR2;\n  }\n}\n\nLUA_API void lua_setfield(lua_State *L, int idx, const char *k)\n{\n  TValue *o;\n  TValue key;\n  cTValue *t = index2adr_check(L, idx);\n  lj_checkapi_slot(1);\n  setstrV(L, &key, lj_str_newz(L, k));\n  o = lj_meta_tset(L, t, &key);\n  if (o) {\n    /* NOBARRIER: lj_meta_tset ensures the table is not black. */\n    copyTV(L, o, --L->top);\n  } else {\n    TValue *base = L->top;\n    copyTV(L, base+2, base-3-2*LJ_FR2);\n    L->top = base+3;\n    lj_vm_call(L, base, 0+1);\n    L->top -= 2+LJ_FR2;\n  }\n}\n\nLUA_API void lua_rawset(lua_State *L, int idx)\n{\n  GCtab *t = tabV(index2adr(L, idx));\n  TValue *dst, *key;\n  lj_checkapi_slot(2);\n  key = L->top-2;\n  dst = lj_tab_set(L, t, key);\n  copyTV(L, dst, key+1);\n  lj_gc_anybarriert(L, t);\n  L->top = key;\n}\n\nLUA_API void lua_rawseti(lua_State *L, int idx, int n)\n{\n  GCtab *t = tabV(index2adr(L, idx));\n  TValue *dst, *src;\n  lj_checkapi_slot(1);\n  dst = lj_tab_setint(L, t, n);\n  src = L->top-1;\n  copyTV(L, dst, src);\n  lj_gc_barriert(L, t, dst);\n  L->top = src;\n}\n\nLUA_API int lua_setmetatable(lua_State *L, int idx)\n{\n  global_State *g;\n  GCtab *mt;\n  cTValue *o = index2adr_check(L, idx);\n  lj_checkapi_slot(1);\n  if (tvisnil(L->top-1)) {\n    mt = NULL;\n  } else {\n    lj_checkapi(tvistab(L->top-1), \"top stack slot is not a table\");\n    mt = tabV(L->top-1);\n  }\n  g = G(L);\n  if (tvistab(o)) {\n    setgcref(tabV(o)->metatable, obj2gco(mt));\n    if (mt)\n      lj_gc_objbarriert(L, tabV(o), mt);\n  } else if (tvisudata(o)) {\n    setgcref(udataV(o)->metatable, obj2gco(mt));\n    if (mt)\n      lj_gc_objbarrier(L, udataV(o), mt);\n  } else {\n    /* Flush cache, since traces specialize to basemt. But not during __gc. */\n    if (lj_trace_flushall(L))\n      lj_err_caller(L, LJ_ERR_NOGCMM);\n    if (tvisbool(o)) {\n      /* NOBARRIER: basemt is a GC root. */\n      setgcref(basemt_it(g, LJ_TTRUE), obj2gco(mt));\n      setgcref(basemt_it(g, LJ_TFALSE), obj2gco(mt));\n    } else {\n      /* NOBARRIER: basemt is a GC root. */\n      setgcref(basemt_obj(g, o), obj2gco(mt));\n    }\n  }\n  L->top--;\n  return 1;\n}\n\nLUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)\n{\n  lua_getfield(L, LUA_REGISTRYINDEX, tname);\n  lua_setmetatable(L, -2);\n}\n\nLUA_API int lua_setfenv(lua_State *L, int idx)\n{\n  cTValue *o = index2adr_check(L, idx);\n  GCtab *t;\n  lj_checkapi_slot(1);\n  lj_checkapi(tvistab(L->top-1), \"top stack slot is not a table\");\n  t = tabV(L->top-1);\n  if (tvisfunc(o)) {\n    setgcref(funcV(o)->c.env, obj2gco(t));\n  } else if (tvisudata(o)) {\n    setgcref(udataV(o)->env, obj2gco(t));\n  } else if (tvisthread(o)) {\n    setgcref(threadV(o)->env, obj2gco(t));\n  } else {\n    L->top--;\n    return 0;\n  }\n  lj_gc_objbarrier(L, gcV(o), t);\n  L->top--;\n  return 1;\n}\n\nLUA_API const char *lua_setupvalue(lua_State *L, int idx, int n)\n{\n  cTValue *f = index2adr(L, idx);\n  TValue *val;\n  GCobj *o;\n  const char *name;\n  lj_checkapi_slot(1);\n  name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val, &o);\n  if (name) {\n    L->top--;\n    copyTV(L, val, L->top);\n    lj_gc_barrier(L, o, L->top);\n  }\n  return name;\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n#if LJ_FR2\nstatic TValue *api_call_base(lua_State *L, int nargs)\n{\n  TValue *o = L->top, *base = o - nargs;\n  L->top = o+1;\n  for (; o > base; o--) copyTV(L, o, o-1);\n  setnilV(o);\n  return o+1;\n}\n#else\n#define api_call_base(L, nargs)\t(L->top - (nargs))\n#endif\n\nLUA_API void lua_call(lua_State *L, int nargs, int nresults)\n{\n  lj_checkapi(L->status == LUA_OK || L->status == LUA_ERRERR,\n\t      \"thread called in wrong state %d\", L->status);\n  lj_checkapi_slot(nargs+1);\n  lj_vm_call(L, api_call_base(L, nargs), nresults+1);\n}\n\nLUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)\n{\n  global_State *g = G(L);\n  uint8_t oldh = hook_save(g);\n  ptrdiff_t ef;\n  int status;\n  lj_checkapi(L->status == LUA_OK || L->status == LUA_ERRERR,\n\t      \"thread called in wrong state %d\", L->status);\n  lj_checkapi_slot(nargs+1);\n  if (errfunc == 0) {\n    ef = 0;\n  } else {\n    cTValue *o = index2adr_stack(L, errfunc);\n    ef = savestack(L, o);\n  }\n  status = lj_vm_pcall(L, api_call_base(L, nargs), nresults+1, ef);\n  if (status) hook_restore(g, oldh);\n  return status;\n}\n\nstatic TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)\n{\n  GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L));\n  TValue *top = L->top;\n  fn->c.f = func;\n  setfuncV(L, top++, fn);\n  if (LJ_FR2) setnilV(top++);\n#if LJ_64\n  ud = lj_lightud_intern(L, ud);\n#endif\n  setrawlightudV(top++, ud);\n  cframe_nres(L->cframe) = 1+0;  /* Zero results. */\n  L->top = top;\n  return top-1;  /* Now call the newly allocated C function. */\n}\n\nLUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud)\n{\n  global_State *g = G(L);\n  uint8_t oldh = hook_save(g);\n  int status;\n  lj_checkapi(L->status == LUA_OK || L->status == LUA_ERRERR,\n\t      \"thread called in wrong state %d\", L->status);\n  status = lj_vm_cpcall(L, func, ud, cpcall);\n  if (status) hook_restore(g, oldh);\n  return status;\n}\n\nLUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field)\n{\n  if (luaL_getmetafield(L, idx, field)) {\n    TValue *top = L->top--;\n    if (LJ_FR2) setnilV(top++);\n    copyTV(L, top++, index2adr(L, idx));\n    L->top = top;\n    lj_vm_call(L, top-1, 1+1);\n    return 1;\n  }\n  return 0;\n}\n\n/* -- Coroutine yield and resume ------------------------------------------ */\n\nLUA_API int lua_isyieldable(lua_State *L)\n{\n  return cframe_canyield(L->cframe);\n}\n\nLUA_API int lua_yield(lua_State *L, int nresults)\n{\n  void *cf = L->cframe;\n  global_State *g = G(L);\n  if (cframe_canyield(cf)) {\n    cf = cframe_raw(cf);\n    if (!hook_active(g)) {  /* Regular yield: move results down if needed. */\n      cTValue *f = L->top - nresults;\n      if (f > L->base) {\n\tTValue *t = L->base;\n\twhile (--nresults >= 0) copyTV(L, t++, f++);\n\tL->top = t;\n      }\n      L->cframe = NULL;\n      L->status = LUA_YIELD;\n      return -1;\n    } else {  /* Yield from hook: add a pseudo-frame. */\n      TValue *top = L->top;\n      hook_leave(g);\n      (top++)->u64 = cframe_multres(cf);\n      setcont(top, lj_cont_hook);\n      if (LJ_FR2) top++;\n      setframe_pc(top, cframe_pc(cf)-1);\n      top++;\n      setframe_gc(top, obj2gco(L), LJ_TTHREAD);\n      if (LJ_FR2) top++;\n      setframe_ftsz(top, ((char *)(top+1)-(char *)L->base)+FRAME_CONT);\n      L->top = L->base = top+1;\n#if ((defined(__GNUC__) || defined(__clang__)) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND) || LJ_TARGET_WINDOWS\n      lj_err_throw(L, LUA_YIELD);\n#else\n      L->cframe = NULL;\n      L->status = LUA_YIELD;\n      lj_vm_unwind_c(cf, LUA_YIELD);\n#endif\n    }\n  }\n  lj_err_msg(L, LJ_ERR_CYIELD);\n  return 0;  /* unreachable */\n}\n\nLUA_API int lua_resume(lua_State *L, int nargs)\n{\n  if (L->cframe == NULL && L->status <= LUA_YIELD)\n    return lj_vm_resume(L,\n      L->status == LUA_OK ? api_call_base(L, nargs) : L->top - nargs,\n      0, 0);\n  L->top = L->base;\n  setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP));\n  incr_top(L);\n  return LUA_ERRRUN;\n}\n\n/* -- GC and memory management -------------------------------------------- */\n\nLUA_API int lua_gc(lua_State *L, int what, int data)\n{\n  global_State *g = G(L);\n  int res = 0;\n  switch (what) {\n  case LUA_GCSTOP:\n    g->gc.threshold = LJ_MAX_MEM;\n    break;\n  case LUA_GCRESTART:\n    g->gc.threshold = data == -1 ? (g->gc.total/100)*g->gc.pause : g->gc.total;\n    break;\n  case LUA_GCCOLLECT:\n    lj_gc_fullgc(L);\n    break;\n  case LUA_GCCOUNT:\n    res = (int)(g->gc.total >> 10);\n    break;\n  case LUA_GCCOUNTB:\n    res = (int)(g->gc.total & 0x3ff);\n    break;\n  case LUA_GCSTEP: {\n    GCSize a = (GCSize)data << 10;\n    g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0;\n    while (g->gc.total >= g->gc.threshold)\n      if (lj_gc_step(L) > 0) {\n\tres = 1;\n\tbreak;\n      }\n    break;\n  }\n  case LUA_GCSETPAUSE:\n    res = (int)(g->gc.pause);\n    g->gc.pause = (MSize)data;\n    break;\n  case LUA_GCSETSTEPMUL:\n    res = (int)(g->gc.stepmul);\n    g->gc.stepmul = (MSize)data;\n    break;\n  case LUA_GCISRUNNING:\n    res = (g->gc.threshold != LJ_MAX_MEM);\n    break;\n  default:\n    res = -1;  /* Invalid option. */\n  }\n  return res;\n}\n\nLUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)\n{\n  global_State *g = G(L);\n  if (ud) *ud = g->allocd;\n  return g->allocf;\n}\n\nLUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud)\n{\n  global_State *g = G(L);\n  g->allocd = ud;\n  g->allocf = f;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_arch.h",
    "content": "/*\n** Target architecture selection.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ARCH_H\n#define _LJ_ARCH_H\n\n#include \"lua.h\"\n\n/* -- Target definitions -------------------------------------------------- */\n\n/* Target endianess. */\n#define LUAJIT_LE\t0\n#define LUAJIT_BE\t1\n\n/* Target architectures. */\n#define LUAJIT_ARCH_X86\t\t1\n#define LUAJIT_ARCH_x86\t\t1\n#define LUAJIT_ARCH_X64\t\t2\n#define LUAJIT_ARCH_x64\t\t2\n#define LUAJIT_ARCH_ARM\t\t3\n#define LUAJIT_ARCH_arm\t\t3\n#define LUAJIT_ARCH_ARM64\t4\n#define LUAJIT_ARCH_arm64\t4\n#define LUAJIT_ARCH_PPC\t\t5\n#define LUAJIT_ARCH_ppc\t\t5\n#define LUAJIT_ARCH_MIPS\t6\n#define LUAJIT_ARCH_mips\t6\n#define LUAJIT_ARCH_MIPS32\t6\n#define LUAJIT_ARCH_mips32\t6\n#define LUAJIT_ARCH_MIPS64\t7\n#define LUAJIT_ARCH_mips64\t7\n\n/* Target OS. */\n#define LUAJIT_OS_OTHER\t\t0\n#define LUAJIT_OS_WINDOWS\t1\n#define LUAJIT_OS_LINUX\t\t2\n#define LUAJIT_OS_OSX\t\t3\n#define LUAJIT_OS_BSD\t\t4\n#define LUAJIT_OS_POSIX\t\t5\n\n/* Number mode. */\n#define LJ_NUMMODE_SINGLE\t0\t/* Single-number mode only. */\n#define LJ_NUMMODE_SINGLE_DUAL\t1\t/* Default to single-number mode. */\n#define LJ_NUMMODE_DUAL\t\t2\t/* Dual-number mode only. */\n#define LJ_NUMMODE_DUAL_SINGLE\t3\t/* Default to dual-number mode. */\n\n/* -- Target detection ---------------------------------------------------- */\n\n/* Select native target if no target defined. */\n#ifndef LUAJIT_TARGET\n\n#if defined(__i386) || defined(__i386__) || defined(_M_IX86)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_X86\n#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_X64\n#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_ARM\n#elif defined(__aarch64__)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_ARM64\n#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_PPC\n#elif defined(__mips64__) || defined(__mips64) || defined(__MIPS64__) || defined(__MIPS64)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_MIPS64\n#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)\n#define LUAJIT_TARGET\tLUAJIT_ARCH_MIPS32\n#else\n#error \"No support for this architecture (yet)\"\n#endif\n\n#endif\n\n/* Select native OS if no target OS defined. */\n#ifndef LUAJIT_OS\n\n#if defined(_WIN32) && !defined(_XBOX_VER)\n#define LUAJIT_OS\tLUAJIT_OS_WINDOWS\n#elif defined(__linux__)\n#define LUAJIT_OS\tLUAJIT_OS_LINUX\n#elif defined(__MACH__) && defined(__APPLE__)\n#include \"TargetConditionals.h\"\n#define LUAJIT_OS\tLUAJIT_OS_OSX\n#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \\\n       defined(__NetBSD__) || defined(__OpenBSD__) || \\\n       defined(__DragonFly__)) && !defined(__ORBIS__)\n#define LUAJIT_OS\tLUAJIT_OS_BSD\n#elif (defined(__sun__) && defined(__svr4__))\n#define LJ_TARGET_SOLARIS\t1\n#define LUAJIT_OS\tLUAJIT_OS_POSIX\n#elif defined(__HAIKU__)\n#define LUAJIT_OS\tLUAJIT_OS_POSIX\n#elif defined(__CYGWIN__)\n#define LJ_TARGET_CYGWIN\t1\n#define LUAJIT_OS\tLUAJIT_OS_POSIX\n#else\n#define LUAJIT_OS\tLUAJIT_OS_OTHER\n#endif\n\n#endif\n\n/* Set target OS properties. */\n#if LUAJIT_OS == LUAJIT_OS_WINDOWS\n#define LJ_OS_NAME\t\"Windows\"\n#elif LUAJIT_OS == LUAJIT_OS_LINUX\n#define LJ_OS_NAME\t\"Linux\"\n#elif LUAJIT_OS == LUAJIT_OS_OSX\n#define LJ_OS_NAME\t\"OSX\"\n#elif LUAJIT_OS == LUAJIT_OS_BSD\n#define LJ_OS_NAME\t\"BSD\"\n#elif LUAJIT_OS == LUAJIT_OS_POSIX\n#define LJ_OS_NAME\t\"POSIX\"\n#else\n#define LJ_OS_NAME\t\"Other\"\n#endif\n\n#define LJ_TARGET_WINDOWS\t(LUAJIT_OS == LUAJIT_OS_WINDOWS)\n#define LJ_TARGET_LINUX\t\t(LUAJIT_OS == LUAJIT_OS_LINUX)\n#define LJ_TARGET_OSX\t\t(LUAJIT_OS == LUAJIT_OS_OSX)\n#define LJ_TARGET_BSD\t\t(LUAJIT_OS == LUAJIT_OS_BSD)\n#define LJ_TARGET_POSIX\t\t(LUAJIT_OS > LUAJIT_OS_WINDOWS)\n#if LJ_TARGET_IOS\n#define LJ_TARGET_DLOPEN\t0\n#else\n#define LJ_TARGET_DLOPEN\tLJ_TARGET_POSIX\n#endif\n\n#if TARGET_OS_IPHONE\n#define LJ_TARGET_IOS\t\t1\n#else\n#define LJ_TARGET_IOS\t\t0\n#endif\n\n#ifdef __CELLOS_LV2__\n#define LJ_TARGET_PS3\t\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#ifdef __ORBIS__\n#define LJ_TARGET_PS4\t\t1\n#define LJ_TARGET_CONSOLE\t1\n#undef NULL\n#define NULL ((void*)0)\n#endif\n\n#ifdef __psp2__\n#define LJ_TARGET_PSVITA\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#if _XBOX_VER >= 200\n#define LJ_TARGET_XBOX360\t1\n#define LJ_TARGET_CONSOLE\t1\n#endif\n\n#ifdef _DURANGO\n#define LJ_TARGET_XBOXONE\t1\n#define LJ_TARGET_CONSOLE\t1\n#define LJ_TARGET_GC64\t\t1\n#endif\n\n#ifdef _UWP\n#define LJ_TARGET_UWP\t\t1\n#if LUAJIT_TARGET == LUAJIT_ARCH_X64\n#define LJ_TARGET_GC64\t\t1\n#endif\n#endif\n\n/* -- Arch-specific settings ---------------------------------------------- */\n\n/* Set target architecture properties. */\n#if LUAJIT_TARGET == LUAJIT_ARCH_X86\n\n#define LJ_ARCH_NAME\t\t\"x86\"\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#define LJ_TARGET_X86\t\t1\n#define LJ_TARGET_X86ORX64\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_EHRAREG\t8\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNALIGNED\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_SINGLE_DUAL\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_X64\n\n#define LJ_ARCH_NAME\t\t\"x64\"\n#define LJ_ARCH_BITS\t\t64\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#define LJ_TARGET_X64\t\t1\n#define LJ_TARGET_X86ORX64\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_EHRAREG\t16\n#define LJ_TARGET_JUMPRANGE\t31\t/* +-2^31 = +-2GB */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNALIGNED\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_SINGLE_DUAL\n#ifndef LUAJIT_DISABLE_GC64\n#define LJ_TARGET_GC64\t\t1\n#elif LJ_TARGET_OSX\n#error \"macOS requires GC64 -- don't disable it\"\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM\n\n#define LJ_ARCH_NAME\t\t\"arm\"\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__\n#define LJ_ARCH_HASFPU\t\t0\n#endif\n#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP\n#define LJ_ABI_SOFTFP\t\t1\n#endif\n#define LJ_ABI_EABI\t\t1\n#define LJ_TARGET_ARM\t\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_EHRAREG\t14\n#define LJ_TARGET_JUMPRANGE\t25\t/* +-2^25 = +-32MB */\n#define LJ_TARGET_MASKSHIFT\t0\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n\n#if __ARM_ARCH == 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__\n#define LJ_ARCH_VERSION\t\t80\n#elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__\n#define LJ_ARCH_VERSION\t\t70\n#elif __ARM_ARCH_6T2__\n#define LJ_ARCH_VERSION\t\t61\n#elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__\n#define LJ_ARCH_VERSION\t\t60\n#else\n#define LJ_ARCH_VERSION\t\t50\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64\n\n#define LJ_ARCH_BITS\t\t64\n#if defined(__AARCH64EB__)\n#define LJ_ARCH_NAME\t\t\"arm64be\"\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_BE\n#else\n#define LJ_ARCH_NAME\t\t\"arm64\"\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#endif\n#define LJ_TARGET_ARM64\t\t1\n#define LJ_TARGET_EHRETREG\t0\n#define LJ_TARGET_EHRAREG\t30\n#define LJ_TARGET_JUMPRANGE\t27\t/* +-2^27 = +-128MB */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_TARGET_GC64\t\t1\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n\n#define LJ_ARCH_VERSION\t\t80\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC\n\n#ifndef LJ_ARCH_ENDIAN\n#if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#else\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_BE\n#endif\n#endif\n\n#if _LP64\n#define LJ_ARCH_BITS\t\t64\n#if LJ_ARCH_ENDIAN == LUAJIT_LE\n#define LJ_ARCH_NAME\t\t\"ppc64le\"\n#else\n#define LJ_ARCH_NAME\t\t\"ppc64\"\n#endif\n#else\n#define LJ_ARCH_BITS\t\t32\n#define LJ_ARCH_NAME\t\t\"ppc\"\n\n#if !defined(LJ_ARCH_HASFPU)\n#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)\n#define LJ_ARCH_HASFPU\t\t0\n#else\n#define LJ_ARCH_HASFPU\t\t1\n#endif\n#endif\n\n#if !defined(LJ_ABI_SOFTFP)\n#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)\n#define LJ_ABI_SOFTFP\t\t1\n#else\n#define LJ_ABI_SOFTFP\t\t0\n#endif\n#endif\n#endif\n\n#if LJ_ABI_SOFTFP\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n#else\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL_SINGLE\n#endif\n\n#define LJ_TARGET_PPC\t\t1\n#define LJ_TARGET_EHRETREG\t3\n#define LJ_TARGET_EHRAREG\t65\n#define LJ_TARGET_JUMPRANGE\t25\t/* +-2^25 = +-32MB */\n#define LJ_TARGET_MASKSHIFT\t0\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t1\t/* Want only IR_BROL. */\n\n#if LJ_TARGET_CONSOLE\n#define LJ_ARCH_PPC32ON64\t1\n#define LJ_ARCH_NOFFI\t\t1\n#elif LJ_ARCH_BITS == 64\n#error \"No support for PPC64\"\n#endif\n\n#if _ARCH_PWR7\n#define LJ_ARCH_VERSION\t\t70\n#elif _ARCH_PWR6\n#define LJ_ARCH_VERSION\t\t60\n#elif _ARCH_PWR5X\n#define LJ_ARCH_VERSION\t\t51\n#elif _ARCH_PWR5\n#define LJ_ARCH_VERSION\t\t50\n#elif _ARCH_PWR4\n#define LJ_ARCH_VERSION\t\t40\n#else\n#define LJ_ARCH_VERSION\t\t0\n#endif\n#if _ARCH_PPCSQ\n#define LJ_ARCH_SQRT\t\t1\n#endif\n#if _ARCH_PWR5X\n#define LJ_ARCH_ROUND\t\t1\n#endif\n#if __PPU__\n#define LJ_ARCH_CELL\t\t1\n#endif\n#if LJ_TARGET_XBOX360\n#define LJ_ARCH_XENON\t\t1\n#endif\n\n#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS32 || LUAJIT_TARGET == LUAJIT_ARCH_MIPS64\n\n#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)\n#if __mips_isa_rev >= 6\n#define LJ_TARGET_MIPSR6\t1\n#define LJ_TARGET_UNALIGNED\t1\n#endif\n#if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32\n#if LJ_TARGET_MIPSR6\n#define LJ_ARCH_NAME\t\t\"mips32r6el\"\n#else\n#define LJ_ARCH_NAME\t\t\"mipsel\"\n#endif\n#else\n#if LJ_TARGET_MIPSR6\n#define LJ_ARCH_NAME\t\t\"mips64r6el\"\n#else\n#define LJ_ARCH_NAME\t\t\"mips64el\"\n#endif\n#endif\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_LE\n#else\n#if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32\n#if LJ_TARGET_MIPSR6\n#define LJ_ARCH_NAME\t\t\"mips32r6\"\n#else\n#define LJ_ARCH_NAME\t\t\"mips\"\n#endif\n#else\n#if LJ_TARGET_MIPSR6\n#define LJ_ARCH_NAME\t\t\"mips64r6\"\n#else\n#define LJ_ARCH_NAME\t\t\"mips64\"\n#endif\n#endif\n#define LJ_ARCH_ENDIAN\t\tLUAJIT_BE\n#endif\n\n#if !defined(LJ_ARCH_HASFPU)\n#ifdef __mips_soft_float\n#define LJ_ARCH_HASFPU\t\t0\n#else\n#define LJ_ARCH_HASFPU\t\t1\n#endif\n#endif\n\n#if !defined(LJ_ABI_SOFTFP)\n#ifdef __mips_soft_float\n#define LJ_ABI_SOFTFP\t\t1\n#else\n#define LJ_ABI_SOFTFP\t\t0\n#endif\n#endif\n\n#if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32\n#define LJ_ARCH_BITS\t\t32\n#define LJ_TARGET_MIPS32\t1\n#else\n#define LJ_ARCH_BITS\t\t64\n#define LJ_TARGET_MIPS64\t1\n#define LJ_TARGET_GC64\t\t1\n#endif\n#define LJ_TARGET_MIPS\t\t1\n#define LJ_TARGET_EHRETREG\t4\n#define LJ_TARGET_EHRAREG\t31\n#define LJ_TARGET_JUMPRANGE\t27\t/* 2*2^27 = 256MB-aligned region */\n#define LJ_TARGET_MASKSHIFT\t1\n#define LJ_TARGET_MASKROT\t1\n#define LJ_TARGET_UNIFYROT\t2\t/* Want only IR_BROR. */\n#define LJ_ARCH_NUMMODE\t\tLJ_NUMMODE_DUAL\n\n#if LJ_TARGET_MIPSR6\n#define LJ_ARCH_VERSION\t\t60\n#elif _MIPS_ARCH_MIPS32R2 || _MIPS_ARCH_MIPS64R2\n#define LJ_ARCH_VERSION\t\t20\n#else\n#define LJ_ARCH_VERSION\t\t10\n#endif\n\n#else\n#error \"No target architecture defined\"\n#endif\n\n/* -- Checks for requirements --------------------------------------------- */\n\n/* Check for minimum required compiler versions. */\n#if defined(__GNUC__)\n#if LJ_TARGET_X86\n#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)\n#error \"Need at least GCC 3.4 or newer\"\n#endif\n#elif LJ_TARGET_X64\n#if __GNUC__ < 4\n#error \"Need at least GCC 4.0 or newer\"\n#endif\n#elif LJ_TARGET_ARM\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)\n#error \"Need at least GCC 4.2 or newer\"\n#endif\n#elif LJ_TARGET_ARM64\n#if __clang__\n#if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)) && !defined(__NX_TOOLCHAIN_MAJOR__)\n#error \"Need at least Clang 3.5 or newer\"\n#endif\n#else\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)\n#error \"Need at least GCC 4.8 or newer\"\n#endif\n#endif\n#elif !LJ_TARGET_PS3\n#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)\n#error \"Need at least GCC 4.3 or newer\"\n#endif\n#endif\n#endif\n\n/* Check target-specific constraints. */\n#ifndef _BUILDVM_H\n#if LJ_TARGET_X64\n#if __USING_SJLJ_EXCEPTIONS__\n#error \"Need a C compiler with native exception handling on x64\"\n#endif\n#elif LJ_TARGET_ARM\n#if defined(__ARMEB__)\n#error \"No support for big-endian ARM\"\n#endif\n#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__\n#error \"No support for Cortex-M CPUs\"\n#endif\n#if !(__ARM_EABI__ || LJ_TARGET_IOS)\n#error \"Only ARM EABI or iOS 3.0+ ABI is supported\"\n#endif\n#elif LJ_TARGET_ARM64\n#if defined(_ILP32)\n#error \"No support for ILP32 model on ARM64\"\n#endif\n#elif LJ_TARGET_PPC\n#if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN))\n#error \"No support for little-endian PPC32\"\n#endif\n#if defined(__NO_FPRS__) && !defined(_SOFT_FLOAT)\n#error \"No support for PPC/e500 anymore (use LuaJIT 2.0)\"\n#endif\n#elif LJ_TARGET_MIPS32\n#if !((defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32) || (defined(_ABIO32) && _MIPS_SIM == _ABIO32))\n#error \"Only o32 ABI supported for MIPS32\"\n#endif\n#if LJ_TARGET_MIPSR6\n/* Not that useful, since most available r6 CPUs are 64 bit. */\n#error \"No support for MIPS32R6\"\n#endif\n#elif LJ_TARGET_MIPS64\n#if !((defined(_MIPS_SIM_ABI64) && _MIPS_SIM == _MIPS_SIM_ABI64) || (defined(_ABI64) && _MIPS_SIM == _ABI64))\n/* MIPS32ON64 aka n32 ABI support might be desirable, but difficult. */\n#error \"Only n64 ABI supported for MIPS64\"\n#endif\n#endif\n#endif\n\n/* -- Derived defines ----------------------------------------------------- */\n\n/* Enable or disable the dual-number mode for the VM. */\n#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)\n#error \"No support for this number mode on this architecture\"\n#endif\n#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \\\n    (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)\n#define LJ_DUALNUM\t\t1\n#else\n#define LJ_DUALNUM\t\t0\n#endif\n\n#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE\n/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */\n/* Ditto for the consoles. Complain to Sony or MS, not me. */\n#ifndef LUAJIT_ENABLE_JIT\n#define LJ_OS_NOJIT\t\t1\n#endif\n#endif\n\n/* 64 bit GC references. */\n#if LJ_TARGET_GC64\n#define LJ_GC64\t\t\t1\n#else\n#define LJ_GC64\t\t\t0\n#endif\n\n/* 2-slot frame info. */\n#if LJ_GC64\n#define LJ_FR2\t\t\t1\n#else\n#define LJ_FR2\t\t\t0\n#endif\n\n/* Disable or enable the JIT compiler. */\n#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)\n#define LJ_HASJIT\t\t0\n#else\n#define LJ_HASJIT\t\t1\n#endif\n\n/* Disable or enable the FFI extension. */\n#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)\n#define LJ_HASFFI\t\t0\n#else\n#define LJ_HASFFI\t\t1\n#endif\n\n/* Disable or enable the string buffer extension. */\n#if defined(LUAJIT_DISABLE_BUFFER)\n#define LJ_HASBUFFER\t\t0\n#else\n#define LJ_HASBUFFER\t\t1\n#endif\n\n#if defined(LUAJIT_DISABLE_PROFILE)\n#define LJ_HASPROFILE\t\t0\n#elif LJ_TARGET_POSIX\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_SIGPROF\t1\n#elif LJ_TARGET_PS3\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_PTHREAD\t1\n#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360\n#define LJ_HASPROFILE\t\t1\n#define LJ_PROFILE_WTHREAD\t1\n#else\n#define LJ_HASPROFILE\t\t0\n#endif\n\n#ifndef LJ_ARCH_HASFPU\n#define LJ_ARCH_HASFPU\t\t1\n#endif\n#ifndef LJ_ABI_SOFTFP\n#define LJ_ABI_SOFTFP\t\t0\n#endif\n#define LJ_SOFTFP\t\t(!LJ_ARCH_HASFPU)\n#define LJ_SOFTFP32\t\t(LJ_SOFTFP && LJ_32)\n\n#if LJ_ARCH_ENDIAN == LUAJIT_BE\n#define LJ_LE\t\t\t0\n#define LJ_BE\t\t\t1\n#define LJ_ENDIAN_SELECT(le, be)\tbe\n#define LJ_ENDIAN_LOHI(lo, hi)\t\thi lo\n#else\n#define LJ_LE\t\t\t1\n#define LJ_BE\t\t\t0\n#define LJ_ENDIAN_SELECT(le, be)\tle\n#define LJ_ENDIAN_LOHI(lo, hi)\t\tlo hi\n#endif\n\n#if LJ_ARCH_BITS == 32\n#define LJ_32\t\t\t1\n#define LJ_64\t\t\t0\n#else\n#define LJ_32\t\t\t0\n#define LJ_64\t\t\t1\n#endif\n\n#ifndef LJ_TARGET_UNALIGNED\n#define LJ_TARGET_UNALIGNED\t0\n#endif\n\n#ifndef LJ_PAGESIZE\n#define LJ_PAGESIZE\t\t4096\n#endif\n\n/* Various workarounds for embedded operating systems or weak C runtimes. */\n#if defined(__ANDROID__) || defined(__symbian__) || LJ_TARGET_XBOX360 || LJ_TARGET_WINDOWS\n#define LUAJIT_NO_LOG2\n#endif\n#if LJ_TARGET_CONSOLE || LJ_TARGET_IOS\n#define LJ_NO_SYSTEM\t\t1\n#endif\n\n#if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN\n#define LJ_ABI_WIN\t\t1\n#else\n#define LJ_ABI_WIN\t\t0\n#endif\n\n#if LJ_TARGET_WINDOWS\n#if LJ_TARGET_UWP\n#define LJ_WIN_VALLOC\tVirtualAllocFromApp\n#define LJ_WIN_VPROTECT\tVirtualProtectFromApp\nextern void *LJ_WIN_LOADLIBA(const char *path);\n#else\n#define LJ_WIN_VALLOC\tVirtualAlloc\n#define LJ_WIN_VPROTECT\tVirtualProtect\n#define LJ_WIN_LOADLIBA(path)\tLoadLibraryExA((path), NULL, 0)\n#endif\n#endif\n\n#if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4\n#define LJ_NO_UNWIND\t\t1\n#endif\n\n#if !LJ_NO_UNWIND && !defined(LUAJIT_UNWIND_INTERNAL) && (LJ_ABI_WIN || (defined(LUAJIT_UNWIND_EXTERNAL) && (defined(__GNUC__) || defined(__clang__))))\n#define LJ_UNWIND_EXT\t\t1\n#else\n#define LJ_UNWIND_EXT\t\t0\n#endif\n\n#if LJ_UNWIND_EXT && LJ_HASJIT && !LJ_TARGET_ARM && !(LJ_ABI_WIN && LJ_TARGET_X86)\n#define LJ_UNWIND_JIT\t\t1\n#else\n#define LJ_UNWIND_JIT\t\t0\n#endif\n\n/* Compatibility with Lua 5.1 vs. 5.2. */\n#ifdef LUAJIT_ENABLE_LUA52COMPAT\n#define LJ_52\t\t\t1\n#else\n#define LJ_52\t\t\t0\n#endif\n\n/* -- VM security --------------------------------------------------------- */\n\n/* Don't make any changes here. Instead build with:\n**   make \"XCFLAGS=-DLUAJIT_SECURITY_flag=value\"\n**\n** Important note to distro maintainers: DO NOT change the defaults for a\n** regular distro build -- neither upwards, nor downwards!\n** These build-time configurable security flags are intended for embedders\n** who may have specific needs wrt. security vs. performance.\n*/\n\n/* Security defaults. */\n#ifndef LUAJIT_SECURITY_PRNG\n/* PRNG init: 0 = fixed/insecure, 1 = secure from OS. */\n#define LUAJIT_SECURITY_PRNG\t1\n#endif\n\n#ifndef LUAJIT_SECURITY_STRHASH\n/* String hash: 0 = sparse only, 1 = sparse + dense. */\n#define LUAJIT_SECURITY_STRHASH\t1\n#endif\n\n#ifndef LUAJIT_SECURITY_STRID\n/* String IDs: 0 = linear, 1 = reseed < 255, 2 = reseed < 15, 3 = random. */\n#define LUAJIT_SECURITY_STRID\t1\n#endif\n\n#ifndef LUAJIT_SECURITY_MCODE\n/* Machine code page protection: 0 = insecure RWX, 1 = secure RW^X. */\n#define LUAJIT_SECURITY_MCODE\t1\n#endif\n\n#define LJ_SECURITY_MODE \\\n  ( 0u \\\n  | ((LUAJIT_SECURITY_PRNG & 3) << 0) \\\n  | ((LUAJIT_SECURITY_STRHASH & 3) << 2) \\\n  | ((LUAJIT_SECURITY_STRID & 3) << 4) \\\n  | ((LUAJIT_SECURITY_MCODE & 3) << 6) \\\n  )\n#define LJ_SECURITY_MODESTRING \\\n  \"\\004prng\\007strhash\\005strid\\005mcode\"\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm.c",
    "content": "/*\n** IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_asm_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_asm.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_target.h\"\n\n#ifdef LUA_USE_ASSERT\n#include <stdio.h>\n#endif\n\n/* -- Assembler state and common macros ----------------------------------- */\n\n/* Assembler state. */\ntypedef struct ASMState {\n  RegCost cost[RID_MAX];  /* Reference and blended allocation cost for regs. */\n\n  MCode *mcp;\t\t/* Current MCode pointer (grows down). */\n  MCode *mclim;\t\t/* Lower limit for MCode memory + red zone. */\n#ifdef LUA_USE_ASSERT\n  MCode *mcp_prev;\t/* Red zone overflow check. */\n#endif\n\n  IRIns *ir;\t\t/* Copy of pointer to IR instructions/constants. */\n  jit_State *J;\t\t/* JIT compiler state. */\n\n#if LJ_TARGET_X86ORX64\n  x86ModRM mrm;\t\t/* Fused x86 address operand. */\n#endif\n\n  RegSet freeset;\t/* Set of free registers. */\n  RegSet modset;\t/* Set of registers modified inside the loop. */\n  RegSet weakset;\t/* Set of weakly referenced registers. */\n  RegSet phiset;\t/* Set of PHI registers. */\n\n  uint32_t flags;\t/* Copy of JIT compiler flags. */\n  int loopinv;\t\t/* Loop branch inversion (0:no, 1:yes, 2:yes+CC_P). */\n\n  int32_t evenspill;\t/* Next even spill slot. */\n  int32_t oddspill;\t/* Next odd spill slot (or 0). */\n\n  IRRef curins;\t\t/* Reference of current instruction. */\n  IRRef stopins;\t/* Stop assembly before hitting this instruction. */\n  IRRef orignins;\t/* Original T->nins. */\n\n  IRRef snapref;\t/* Current snapshot is active after this reference. */\n  IRRef snaprename;\t/* Rename highwater mark for snapshot check. */\n  SnapNo snapno;\t/* Current snapshot number. */\n  SnapNo loopsnapno;\t/* Loop snapshot number. */\n  int snapalloc;\t/* Current snapshot needs allocation. */\n  BloomFilter snapfilt1, snapfilt2;\t/* Filled with snapshot refs. */\n\n  IRRef fuseref;\t/* Fusion limit (loopref, 0 or FUSE_DISABLED). */\n  IRRef sectref;\t/* Section base reference (loopref or 0). */\n  IRRef loopref;\t/* Reference of LOOP instruction (or 0). */\n\n  BCReg topslot;\t/* Number of slots for stack check (unless 0). */\n  int32_t gcsteps;\t/* Accumulated number of GC steps (per section). */\n\n  GCtrace *T;\t\t/* Trace to assemble. */\n  GCtrace *parent;\t/* Parent trace (or NULL). */\n\n  MCode *mcbot;\t\t/* Bottom of reserved MCode. */\n  MCode *mctop;\t\t/* Top of generated MCode. */\n  MCode *mctoporig;\t/* Original top of generated MCode. */\n  MCode *mcloop;\t/* Pointer to loop MCode (or NULL). */\n  MCode *invmcp;\t/* Points to invertible loop branch (or NULL). */\n  MCode *flagmcp;\t/* Pending opportunity to merge flag setting ins. */\n  MCode *realign;\t/* Realign loop if not NULL. */\n\n#ifdef RID_NUM_KREF\n  intptr_t krefk[RID_NUM_KREF];\n#endif\n  IRRef1 phireg[RID_MAX];  /* PHI register references. */\n  uint16_t parentmap[LJ_MAX_JSLOTS];  /* Parent instruction to RegSP map. */\n} ASMState;\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertA(c, ...)\tlj_assertG_(J2G(as->J), (c), __VA_ARGS__)\n#else\n#define lj_assertA(c, ...)\t((void)as)\n#endif\n\n#define IR(ref)\t\t\t(&as->ir[(ref)])\n\n#define ASMREF_TMP1\t\tREF_TRUE\t/* Temp. register. */\n#define ASMREF_TMP2\t\tREF_FALSE\t/* Temp. register. */\n#define ASMREF_L\t\tREF_NIL\t\t/* Stores register for L. */\n\n/* Check for variant to invariant references. */\n#define iscrossref(as, ref)\t((ref) < as->sectref)\n\n/* Inhibit memory op fusion from variant to invariant references. */\n#define FUSE_DISABLED\t\t(~(IRRef)0)\n#define mayfuse(as, ref)\t((ref) > as->fuseref)\n#define neverfuse(as)\t\t(as->fuseref == FUSE_DISABLED)\n#define canfuse(as, ir)\t\t(!neverfuse(as) && !irt_isphi((ir)->t))\n#define opisfusableload(o) \\\n  ((o) == IR_ALOAD || (o) == IR_HLOAD || (o) == IR_ULOAD || \\\n   (o) == IR_FLOAD || (o) == IR_XLOAD || (o) == IR_SLOAD || (o) == IR_VLOAD)\n\n/* Sparse limit checks using a red zone before the actual limit. */\n#define MCLIM_REDZONE\t64\n\nstatic LJ_NORET LJ_NOINLINE void asm_mclimit(ASMState *as)\n{\n  lj_mcode_limiterr(as->J, (size_t)(as->mctop - as->mcp + 4*MCLIM_REDZONE));\n}\n\nstatic LJ_AINLINE void checkmclim(ASMState *as)\n{\n#ifdef LUA_USE_ASSERT\n  if (as->mcp + MCLIM_REDZONE < as->mcp_prev) {\n    IRIns *ir = IR(as->curins+1);\n    lj_assertA(0, \"red zone overflow: %p IR %04d  %02d %04d %04d\\n\", as->mcp,\n      as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS);\n  }\n#endif\n  if (LJ_UNLIKELY(as->mcp < as->mclim)) asm_mclimit(as);\n#ifdef LUA_USE_ASSERT\n  as->mcp_prev = as->mcp;\n#endif\n}\n\n#ifdef RID_NUM_KREF\n#define ra_iskref(ref)\t\t((ref) < RID_NUM_KREF)\n#define ra_krefreg(ref)\t\t((Reg)(RID_MIN_KREF + (Reg)(ref)))\n#define ra_krefk(as, ref)\t(as->krefk[(ref)])\n\nstatic LJ_AINLINE void ra_setkref(ASMState *as, Reg r, intptr_t k)\n{\n  IRRef ref = (IRRef)(r - RID_MIN_KREF);\n  as->krefk[ref] = k;\n  as->cost[r] = REGCOST(ref, ref);\n}\n\n#else\n#define ra_iskref(ref)\t\t0\n#define ra_krefreg(ref)\t\tRID_MIN_GPR\n#define ra_krefk(as, ref)\t0\n#endif\n\n/* Arch-specific field offsets. */\nstatic const uint8_t field_ofs[IRFL__MAX+1] = {\n#define FLOFS(name, ofs)\t(uint8_t)(ofs),\nIRFLDEF(FLOFS)\n#undef FLOFS\n  0\n};\n\n/* -- Target-specific instruction emitter --------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_emit_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_emit_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"lj_emit_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_emit_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_emit_mips.h\"\n#else\n#error \"Missing instruction emitter for target CPU\"\n#endif\n\n/* Generic load/store of register from/to stack slot. */\n#define emit_spload(as, ir, r, ofs) \\\n  emit_loadofs(as, ir, (r), RID_SP, (ofs))\n#define emit_spstore(as, ir, r, ofs) \\\n  emit_storeofs(as, ir, (r), RID_SP, (ofs))\n\n/* -- Register allocator debugging ---------------------------------------- */\n\n/* #define LUAJIT_DEBUG_RA */\n\n#ifdef LUAJIT_DEBUG_RA\n\n#include <stdio.h>\n#include <stdarg.h>\n\n#define RIDNAME(name)\t#name,\nstatic const char *const ra_regname[] = {\n  GPRDEF(RIDNAME)\n  FPRDEF(RIDNAME)\n  VRIDDEF(RIDNAME)\n  NULL\n};\n#undef RIDNAME\n\nstatic char ra_dbg_buf[65536];\nstatic char *ra_dbg_p;\nstatic char *ra_dbg_merge;\nstatic MCode *ra_dbg_mcp;\n\nstatic void ra_dstart(void)\n{\n  ra_dbg_p = ra_dbg_buf;\n  ra_dbg_merge = NULL;\n  ra_dbg_mcp = NULL;\n}\n\nstatic void ra_dflush(void)\n{\n  fwrite(ra_dbg_buf, 1, (size_t)(ra_dbg_p-ra_dbg_buf), stdout);\n  ra_dstart();\n}\n\nstatic void ra_dprintf(ASMState *as, const char *fmt, ...)\n{\n  char *p;\n  va_list argp;\n  va_start(argp, fmt);\n  p = ra_dbg_mcp == as->mcp ? ra_dbg_merge : ra_dbg_p;\n  ra_dbg_mcp = NULL;\n  p += sprintf(p, \"%08x  \\e[36m%04d \", (uintptr_t)as->mcp, as->curins-REF_BIAS);\n  for (;;) {\n    const char *e = strchr(fmt, '$');\n    if (e == NULL) break;\n    memcpy(p, fmt, (size_t)(e-fmt));\n    p += e-fmt;\n    if (e[1] == 'r') {\n      Reg r = va_arg(argp, Reg) & RID_MASK;\n      if (r <= RID_MAX) {\n\tconst char *q;\n\tfor (q = ra_regname[r]; *q; q++)\n\t  *p++ = *q >= 'A' && *q <= 'Z' ? *q + 0x20 : *q;\n      } else {\n\t*p++ = '?';\n\tlj_assertA(0, \"bad register %d for debug format \\\"%s\\\"\", r, fmt);\n      }\n    } else if (e[1] == 'f' || e[1] == 'i') {\n      IRRef ref;\n      if (e[1] == 'f')\n\tref = va_arg(argp, IRRef);\n      else\n\tref = va_arg(argp, IRIns *) - as->ir;\n      if (ref >= REF_BIAS)\n\tp += sprintf(p, \"%04d\", ref - REF_BIAS);\n      else\n\tp += sprintf(p, \"K%03d\", REF_BIAS - ref);\n    } else if (e[1] == 's') {\n      uint32_t slot = va_arg(argp, uint32_t);\n      p += sprintf(p, \"[sp+0x%x]\", sps_scale(slot));\n    } else if (e[1] == 'x') {\n      p += sprintf(p, \"%08x\", va_arg(argp, int32_t));\n    } else {\n      lj_assertA(0, \"bad debug format code\");\n    }\n    fmt = e+2;\n  }\n  va_end(argp);\n  while (*fmt)\n    *p++ = *fmt++;\n  *p++ = '\\e'; *p++ = '['; *p++ = 'm'; *p++ = '\\n';\n  if (p > ra_dbg_buf+sizeof(ra_dbg_buf)-256) {\n    fwrite(ra_dbg_buf, 1, (size_t)(p-ra_dbg_buf), stdout);\n    p = ra_dbg_buf;\n  }\n  ra_dbg_p = p;\n}\n\n#define RA_DBG_START()\tra_dstart()\n#define RA_DBG_FLUSH()\tra_dflush()\n#define RA_DBG_REF() \\\n  do { char *_p = ra_dbg_p; ra_dprintf(as, \"\"); \\\n       ra_dbg_merge = _p; ra_dbg_mcp = as->mcp; } while (0)\n#define RA_DBGX(x)\tra_dprintf x\n\n#else\n#define RA_DBG_START()\t((void)0)\n#define RA_DBG_FLUSH()\t((void)0)\n#define RA_DBG_REF()\t((void)0)\n#define RA_DBGX(x)\t((void)0)\n#endif\n\n/* -- Register allocator -------------------------------------------------- */\n\n#define ra_free(as, r)\t\trset_set(as->freeset, (r))\n#define ra_modified(as, r)\trset_set(as->modset, (r))\n#define ra_weak(as, r)\t\trset_set(as->weakset, (r))\n#define ra_noweak(as, r)\trset_clear(as->weakset, (r))\n\n#define ra_used(ir)\t\t(ra_hasreg((ir)->r) || ra_hasspill((ir)->s))\n\n/* Setup register allocator. */\nstatic void ra_setup(ASMState *as)\n{\n  Reg r;\n  /* Initially all regs (except the stack pointer) are free for use. */\n  as->freeset = RSET_INIT;\n  as->modset = RSET_EMPTY;\n  as->weakset = RSET_EMPTY;\n  as->phiset = RSET_EMPTY;\n  memset(as->phireg, 0, sizeof(as->phireg));\n  for (r = RID_MIN_GPR; r < RID_MAX; r++)\n    as->cost[r] = REGCOST(~0u, 0u);\n}\n\n/* Rematerialize constants. */\nstatic Reg ra_rematk(ASMState *as, IRRef ref)\n{\n  IRIns *ir;\n  Reg r;\n  if (ra_iskref(ref)) {\n    r = ra_krefreg(ref);\n    lj_assertA(!rset_test(as->freeset, r), \"rematk of free reg %d\", r);\n    ra_free(as, r);\n    ra_modified(as, r);\n#if LJ_64\n    emit_loadu64(as, r, ra_krefk(as, ref));\n#else\n    emit_loadi(as, r, ra_krefk(as, ref));\n#endif\n    return r;\n  }\n  ir = IR(ref);\n  r = ir->r;\n  lj_assertA(ra_hasreg(r), \"rematk of K%03d has no reg\", REF_BIAS - ref);\n  lj_assertA(!ra_hasspill(ir->s),\n\t     \"rematk of K%03d has spill slot [%x]\", REF_BIAS - ref, ir->s);\n  ra_free(as, r);\n  ra_modified(as, r);\n  ir->r = RID_INIT;  /* Do not keep any hint. */\n  RA_DBGX((as, \"remat     $i $r\", ir, r));\n#if !LJ_SOFTFP32\n  if (ir->o == IR_KNUM) {\n    emit_loadk64(as, r, ir);\n  } else\n#endif\n  if (emit_canremat(REF_BASE) && ir->o == IR_BASE) {\n    ra_sethint(ir->r, RID_BASE);  /* Restore BASE register hint. */\n    emit_getgl(as, r, jit_base);\n  } else if (emit_canremat(ASMREF_L) && ir->o == IR_KPRI) {\n    /* REF_NIL stores ASMREF_L register. */\n    lj_assertA(irt_isnil(ir->t), \"rematk of bad ASMREF_L\");\n    emit_getgl(as, r, cur_L);\n#if LJ_64\n  } else if (ir->o == IR_KINT64) {\n    emit_loadu64(as, r, ir_kint64(ir)->u64);\n#if LJ_GC64\n  } else if (ir->o == IR_KGC) {\n    emit_loadu64(as, r, (uintptr_t)ir_kgc(ir));\n  } else if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n    emit_loadu64(as, r, (uintptr_t)ir_kptr(ir));\n#endif\n#endif\n  } else {\n    lj_assertA(ir->o == IR_KINT || ir->o == IR_KGC ||\n\t       ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL,\n\t       \"rematk of bad IR op %d\", ir->o);\n    emit_loadi(as, r, ir->i);\n  }\n  return r;\n}\n\n/* Force a spill. Allocate a new spill slot if needed. */\nstatic int32_t ra_spill(ASMState *as, IRIns *ir)\n{\n  int32_t slot = ir->s;\n  lj_assertA(ir >= as->ir + REF_TRUE,\n\t     \"spill of K%03d\", REF_BIAS - (int)(ir - as->ir));\n  if (!ra_hasspill(slot)) {\n    if (irt_is64(ir->t)) {\n      slot = as->evenspill;\n      as->evenspill += 2;\n    } else if (as->oddspill) {\n      slot = as->oddspill;\n      as->oddspill = 0;\n    } else {\n      slot = as->evenspill;\n      as->oddspill = slot+1;\n      as->evenspill += 2;\n    }\n    if (as->evenspill > 256)\n      lj_trace_err(as->J, LJ_TRERR_SPILLOV);\n    ir->s = (uint8_t)slot;\n  }\n  return sps_scale(slot);\n}\n\n/* Release the temporarily allocated register in ASMREF_TMP1/ASMREF_TMP2. */\nstatic Reg ra_releasetmp(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  Reg r = ir->r;\n  lj_assertA(ra_hasreg(r), \"release of TMP%d has no reg\", ref-ASMREF_TMP1+1);\n  lj_assertA(!ra_hasspill(ir->s),\n\t     \"release of TMP%d has spill slot [%x]\", ref-ASMREF_TMP1+1, ir->s);\n  ra_free(as, r);\n  ra_modified(as, r);\n  ir->r = RID_INIT;\n  return r;\n}\n\n/* Restore a register (marked as free). Rematerialize or force a spill. */\nstatic Reg ra_restore(ASMState *as, IRRef ref)\n{\n  if (emit_canremat(ref)) {\n    return ra_rematk(as, ref);\n  } else {\n    IRIns *ir = IR(ref);\n    int32_t ofs = ra_spill(as, ir);  /* Force a spill slot. */\n    Reg r = ir->r;\n    lj_assertA(ra_hasreg(r), \"restore of IR %04d has no reg\", ref - REF_BIAS);\n    ra_sethint(ir->r, r);  /* Keep hint. */\n    ra_free(as, r);\n    if (!rset_test(as->weakset, r)) {  /* Only restore non-weak references. */\n      ra_modified(as, r);\n      RA_DBGX((as, \"restore   $i $r\", ir, r));\n      emit_spload(as, ir, r, ofs);\n    }\n    return r;\n  }\n}\n\n/* Save a register to a spill slot. */\nstatic void ra_save(ASMState *as, IRIns *ir, Reg r)\n{\n  RA_DBGX((as, \"save      $i $r\", ir, r));\n  emit_spstore(as, ir, r, sps_scale(ir->s));\n}\n\n#define MINCOST(name) \\\n  if (rset_test(RSET_ALL, RID_##name) && \\\n      LJ_LIKELY(allow&RID2RSET(RID_##name)) && as->cost[RID_##name] < cost) \\\n    cost = as->cost[RID_##name];\n\n/* Evict the register with the lowest cost, forcing a restore. */\nstatic Reg ra_evict(ASMState *as, RegSet allow)\n{\n  IRRef ref;\n  RegCost cost = ~(RegCost)0;\n  lj_assertA(allow != RSET_EMPTY, \"evict from empty set\");\n  if (RID_NUM_FPR == 0 || allow < RID2RSET(RID_MAX_GPR)) {\n    GPRDEF(MINCOST)\n  } else {\n    FPRDEF(MINCOST)\n  }\n  ref = regcost_ref(cost);\n  lj_assertA(ra_iskref(ref) || (ref >= as->T->nk && ref < as->T->nins),\n\t     \"evict of out-of-range IR %04d\", ref - REF_BIAS);\n  /* Preferably pick any weak ref instead of a non-weak, non-const ref. */\n  if (!irref_isk(ref) && (as->weakset & allow)) {\n    IRIns *ir = IR(ref);\n    if (!rset_test(as->weakset, ir->r))\n      ref = regcost_ref(as->cost[rset_pickbot((as->weakset & allow))]);\n  }\n  return ra_restore(as, ref);\n}\n\n/* Pick any register (marked as free). Evict on-demand. */\nstatic Reg ra_pick(ASMState *as, RegSet allow)\n{\n  RegSet pick = as->freeset & allow;\n  if (!pick)\n    return ra_evict(as, allow);\n  else\n    return rset_picktop(pick);\n}\n\n/* Get a scratch register (marked as free). */\nstatic Reg ra_scratch(ASMState *as, RegSet allow)\n{\n  Reg r = ra_pick(as, allow);\n  ra_modified(as, r);\n  RA_DBGX((as, \"scratch        $r\", r));\n  return r;\n}\n\n/* Evict all registers from a set (if not free). */\nstatic void ra_evictset(ASMState *as, RegSet drop)\n{\n  RegSet work;\n  as->modset |= drop;\n#if !LJ_SOFTFP\n  work = (drop & ~as->freeset) & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n#endif\n  work = (drop & ~as->freeset);\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n}\n\n/* Evict (rematerialize) all registers allocated to constants. */\nstatic void ra_evictk(ASMState *as)\n{\n  RegSet work;\n#if !LJ_SOFTFP\n  work = ~as->freeset & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    if (emit_canremat(ref) && irref_isk(ref)) {\n      ra_rematk(as, ref);\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n#endif\n  work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    if (emit_canremat(ref) && irref_isk(ref)) {\n      ra_rematk(as, ref);\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n}\n\n#ifdef RID_NUM_KREF\n/* Allocate a register for a constant. */\nstatic Reg ra_allock(ASMState *as, intptr_t k, RegSet allow)\n{\n  /* First try to find a register which already holds the same constant. */\n  RegSet pick, work = ~as->freeset & RSET_GPR;\n  Reg r;\n  while (work) {\n    IRRef ref;\n    r = rset_pickbot(work);\n    ref = regcost_ref(as->cost[r]);\n#if LJ_64\n    if (ref < ASMREF_L) {\n      if (ra_iskref(ref)) {\n\tif (k == ra_krefk(as, ref))\n\t  return r;\n      } else {\n\tIRIns *ir = IR(ref);\n\tif ((ir->o == IR_KINT64 && k == (int64_t)ir_kint64(ir)->u64) ||\n#if LJ_GC64\n\t    (ir->o == IR_KINT && k == ir->i) ||\n\t    (ir->o == IR_KGC && k == (intptr_t)ir_kgc(ir)) ||\n\t    ((ir->o == IR_KPTR || ir->o == IR_KKPTR) &&\n\t     k == (intptr_t)ir_kptr(ir))\n#else\n\t    (ir->o != IR_KINT64 && k == ir->i)\n#endif\n\t   )\n\t  return r;\n      }\n    }\n#else\n    if (ref < ASMREF_L &&\n\tk == (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i))\n      return r;\n#endif\n    rset_clear(work, r);\n  }\n  pick = as->freeset & allow;\n  if (pick) {\n    /* Constants should preferably get unmodified registers. */\n    if ((pick & ~as->modset))\n      pick &= ~as->modset;\n    r = rset_pickbot(pick);  /* Reduce conflicts with inverse allocation. */\n  } else {\n    r = ra_evict(as, allow);\n  }\n  RA_DBGX((as, \"allock    $x $r\", k, r));\n  ra_setkref(as, r, k);\n  rset_clear(as->freeset, r);\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a specific register for a constant. */\nstatic void ra_allockreg(ASMState *as, intptr_t k, Reg r)\n{\n  Reg kr = ra_allock(as, k, RID2RSET(r));\n  if (kr != r) {\n    IRIns irdummy;\n    irdummy.t.irt = IRT_INT;\n    ra_scratch(as, RID2RSET(r));\n    emit_movrr(as, &irdummy, r, kr);\n  }\n}\n#else\n#define ra_allockreg(as, k, r)\t\temit_loadi(as, (r), (k))\n#endif\n\n/* Allocate a register for ref from the allowed set of registers.\n** Note: this function assumes the ref does NOT have a register yet!\n** Picks an optimal register, sets the cost and marks the register as non-free.\n*/\nstatic Reg ra_allocref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  RegSet pick = as->freeset & allow;\n  Reg r;\n  lj_assertA(ra_noreg(ir->r),\n\t     \"IR %04d already has reg %d\", ref - REF_BIAS, ir->r);\n  if (pick) {\n    /* First check register hint from propagation or PHI. */\n    if (ra_hashint(ir->r)) {\n      r = ra_gethint(ir->r);\n      if (rset_test(pick, r))  /* Use hint register if possible. */\n\tgoto found;\n      /* Rematerialization is cheaper than missing a hint. */\n      if (rset_test(allow, r) && emit_canremat(regcost_ref(as->cost[r]))) {\n\tra_rematk(as, regcost_ref(as->cost[r]));\n\tgoto found;\n      }\n      RA_DBGX((as, \"hintmiss  $f $r\", ref, r));\n    }\n    /* Invariants should preferably get unmodified registers. */\n    if (ref < as->loopref && !irt_isphi(ir->t)) {\n      if ((pick & ~as->modset))\n\tpick &= ~as->modset;\n      r = rset_pickbot(pick);  /* Reduce conflicts with inverse allocation. */\n    } else {\n      /* We've got plenty of regs, so get callee-save regs if possible. */\n      if (RID_NUM_GPR > 8 && (pick & ~RSET_SCRATCH))\n\tpick &= ~RSET_SCRATCH;\n      r = rset_picktop(pick);\n    }\n  } else {\n    r = ra_evict(as, allow);\n  }\nfound:\n  RA_DBGX((as, \"alloc     $f $r\", ref, r));\n  ir->r = (uint8_t)r;\n  rset_clear(as->freeset, r);\n  ra_noweak(as, r);\n  as->cost[r] = REGCOST_REF_T(ref, irt_t(ir->t));\n  return r;\n}\n\n/* Allocate a register on-demand. */\nstatic Reg ra_alloc1(ASMState *as, IRRef ref, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  /* Note: allow is ignored if the register is already allocated. */\n  if (ra_noreg(r)) r = ra_allocref(as, ref, allow);\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Add a register rename to the IR. */\nstatic void ra_addrename(ASMState *as, Reg down, IRRef ref, SnapNo snapno)\n{\n  IRRef ren;\n  lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), ref, snapno);\n  ren = tref_ref(lj_ir_emit(as->J));\n  as->J->cur.ir[ren].r = (uint8_t)down;\n  as->J->cur.ir[ren].s = SPS_NONE;\n}\n\n/* Rename register allocation and emit move. */\nstatic void ra_rename(ASMState *as, Reg down, Reg up)\n{\n  IRRef ref = regcost_ref(as->cost[up] = as->cost[down]);\n  IRIns *ir = IR(ref);\n  ir->r = (uint8_t)up;\n  as->cost[down] = 0;\n  lj_assertA((down < RID_MAX_GPR) == (up < RID_MAX_GPR),\n\t     \"rename between GPR/FPR %d and %d\", down, up);\n  lj_assertA(!rset_test(as->freeset, down), \"rename from free reg %d\", down);\n  lj_assertA(rset_test(as->freeset, up), \"rename to non-free reg %d\", up);\n  ra_free(as, down);  /* 'down' is free ... */\n  ra_modified(as, down);\n  rset_clear(as->freeset, up);  /* ... and 'up' is now allocated. */\n  ra_noweak(as, up);\n  RA_DBGX((as, \"rename    $f $r $r\", regcost_ref(as->cost[up]), down, up));\n  emit_movrr(as, ir, down, up);  /* Backwards codegen needs inverse move. */\n  if (!ra_hasspill(IR(ref)->s)) {  /* Add the rename to the IR. */\n    /*\n    ** The rename is effective at the subsequent (already emitted) exit\n    ** branch. This is for the current snapshot (as->snapno). Except if we\n    ** haven't yet allocated any refs for the snapshot (as->snapalloc == 1),\n    ** then it belongs to the next snapshot.\n    ** See also the discussion at asm_snap_checkrename().\n    */\n    ra_addrename(as, down, ref, as->snapno + as->snapalloc);\n  }\n}\n\n/* Pick a destination register (marked as free).\n** Caveat: allow is ignored if there's already a destination register.\n** Use ra_destreg() to get a specific register.\n*/\nstatic Reg ra_dest(ASMState *as, IRIns *ir, RegSet allow)\n{\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n  } else {\n    if (ra_hashint(dest) && rset_test((as->freeset&allow), ra_gethint(dest))) {\n      dest = ra_gethint(dest);\n      ra_modified(as, dest);\n      RA_DBGX((as, \"dest           $r\", dest));\n    } else {\n      dest = ra_scratch(as, allow);\n    }\n    ir->r = dest;\n  }\n  if (LJ_UNLIKELY(ra_hasspill(ir->s))) ra_save(as, ir, dest);\n  return dest;\n}\n\n/* Force a specific destination register (marked as free). */\nstatic void ra_destreg(ASMState *as, IRIns *ir, Reg r)\n{\n  Reg dest = ra_dest(as, ir, RID2RSET(r));\n  if (dest != r) {\n    lj_assertA(rset_test(as->freeset, r), \"dest reg %d is not free\", r);\n    ra_modified(as, r);\n    emit_movrr(as, ir, dest, r);\n  }\n}\n\n#if LJ_TARGET_X86ORX64\n/* Propagate dest register to left reference. Emit moves as needed.\n** This is a required fixup step for all 2-operand machine instructions.\n*/\nstatic void ra_left(ASMState *as, Reg dest, IRRef lref)\n{\n  IRIns *ir = IR(lref);\n  Reg left = ir->r;\n  if (ra_noreg(left)) {\n    if (irref_isk(lref)) {\n      if (ir->o == IR_KNUM) {\n\t/* FP remat needs a load except for +0. Still better than eviction. */\n\tif (tvispzero(ir_knum(ir)) || !(as->freeset & RSET_FPR)) {\n\t  emit_loadk64(as, dest, ir);\n\t  return;\n\t}\n#if LJ_64\n      } else if (ir->o == IR_KINT64) {\n\temit_loadk64(as, dest, ir);\n\treturn;\n#if LJ_GC64\n      } else if (ir->o == IR_KGC || ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n\temit_loadk64(as, dest, ir);\n\treturn;\n#endif\n#endif\n      } else if (ir->o != IR_KPRI) {\n\tlj_assertA(ir->o == IR_KINT || ir->o == IR_KGC ||\n\t\t   ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL,\n\t\t   \"K%03d has bad IR op %d\", REF_BIAS - lref, ir->o);\n\temit_loadi(as, dest, ir->i);\n\treturn;\n      }\n    }\n    if (!ra_hashint(left) && !iscrossref(as, lref))\n      ra_sethint(ir->r, dest);  /* Propagate register hint. */\n    left = ra_allocref(as, lref, dest < RID_MAX_GPR ? RSET_GPR : RSET_FPR);\n  }\n  ra_noweak(as, left);\n  /* Move needed for true 3-operand instruction: y=a+b ==> y=a; y+=b. */\n  if (dest != left) {\n    /* Use register renaming if dest is the PHI reg. */\n    if (irt_isphi(ir->t) && as->phireg[dest] == lref) {\n      ra_modified(as, left);\n      ra_rename(as, left, dest);\n    } else {\n      emit_movrr(as, ir, dest, left);\n    }\n  }\n}\n#else\n/* Similar to ra_left, except we override any hints. */\nstatic void ra_leftov(ASMState *as, Reg dest, IRRef lref)\n{\n  IRIns *ir = IR(lref);\n  Reg left = ir->r;\n  if (ra_noreg(left)) {\n    ra_sethint(ir->r, dest);  /* Propagate register hint. */\n    left = ra_allocref(as, lref,\n\t\t       (LJ_SOFTFP || dest < RID_MAX_GPR) ? RSET_GPR : RSET_FPR);\n  }\n  ra_noweak(as, left);\n  if (dest != left) {\n    /* Use register renaming if dest is the PHI reg. */\n    if (irt_isphi(ir->t) && as->phireg[dest] == lref) {\n      ra_modified(as, left);\n      ra_rename(as, left, dest);\n    } else {\n      emit_movrr(as, ir, dest, left);\n    }\n  }\n}\n#endif\n\n/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */\nstatic void ra_destpair(ASMState *as, IRIns *ir)\n{\n  Reg destlo = ir->r, desthi = (ir+1)->r;\n  IRIns *irx = (LJ_64 && !irt_is64(ir->t)) ? ir+1 : ir;\n  /* First spill unrelated refs blocking the destination registers. */\n  if (!rset_test(as->freeset, RID_RETLO) &&\n      destlo != RID_RETLO && desthi != RID_RETLO)\n    ra_restore(as, regcost_ref(as->cost[RID_RETLO]));\n  if (!rset_test(as->freeset, RID_RETHI) &&\n      destlo != RID_RETHI && desthi != RID_RETHI)\n    ra_restore(as, regcost_ref(as->cost[RID_RETHI]));\n  /* Next free the destination registers (if any). */\n  if (ra_hasreg(destlo)) {\n    ra_free(as, destlo);\n    ra_modified(as, destlo);\n  } else {\n    destlo = RID_RETLO;\n  }\n  if (ra_hasreg(desthi)) {\n    ra_free(as, desthi);\n    ra_modified(as, desthi);\n  } else {\n    desthi = RID_RETHI;\n  }\n  /* Check for conflicts and shuffle the registers as needed. */\n  if (destlo == RID_RETHI) {\n    if (desthi == RID_RETLO) {\n#if LJ_TARGET_X86ORX64\n      *--as->mcp = REX_64IR(irx, XI_XCHGa + RID_RETHI);\n#else\n      emit_movrr(as, irx, RID_RETHI, RID_TMP);\n      emit_movrr(as, irx, RID_RETLO, RID_RETHI);\n      emit_movrr(as, irx, RID_TMP, RID_RETLO);\n#endif\n    } else {\n      emit_movrr(as, irx, RID_RETHI, RID_RETLO);\n      if (desthi != RID_RETHI) emit_movrr(as, irx, desthi, RID_RETHI);\n    }\n  } else if (desthi == RID_RETLO) {\n    emit_movrr(as, irx, RID_RETLO, RID_RETHI);\n    if (destlo != RID_RETLO) emit_movrr(as, irx, destlo, RID_RETLO);\n  } else {\n    if (desthi != RID_RETHI) emit_movrr(as, irx, desthi, RID_RETHI);\n    if (destlo != RID_RETLO) emit_movrr(as, irx, destlo, RID_RETLO);\n  }\n  /* Restore spill slots (if any). */\n  if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI);\n  if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO);\n}\n\n/* -- Snapshot handling --------- ----------------------------------------- */\n\n/* Can we rematerialize a KNUM instead of forcing a spill? */\nstatic int asm_snap_canremat(ASMState *as)\n{\n  Reg r;\n  for (r = RID_MIN_FPR; r < RID_MAX_FPR; r++)\n    if (irref_isk(regcost_ref(as->cost[r])))\n      return 1;\n  return 0;\n}\n\n/* Check whether a sunk store corresponds to an allocation. */\nstatic int asm_sunk_store(ASMState *as, IRIns *ira, IRIns *irs)\n{\n  if (irs->s == 255) {\n    if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\tirs->o == IR_FSTORE || irs->o == IR_XSTORE) {\n      IRIns *irk = IR(irs->op1);\n      if (irk->o == IR_AREF || irk->o == IR_HREFK)\n\tirk = IR(irk->op1);\n      return (IR(irk->op1) == ira);\n    }\n    return 0;\n  } else {\n    return (ira + irs->s == irs);  /* Quick check. */\n  }\n}\n\n/* Allocate register or spill slot for a ref that escapes to a snapshot. */\nstatic void asm_snap_alloc1(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (!irref_isk(ref) && ir->r != RID_SUNK) {\n    bloomset(as->snapfilt1, ref);\n    bloomset(as->snapfilt2, hashrot(ref, ref + HASH_BIAS));\n    if (ra_used(ir)) return;\n    if (ir->r == RID_SINK) {\n      ir->r = RID_SUNK;\n#if LJ_HASFFI\n      if (ir->o == IR_CNEWI) {  /* Allocate CNEWI value. */\n\tasm_snap_alloc1(as, ir->op2);\n\tif (LJ_32 && (ir+1)->o == IR_HIOP)\n\t  asm_snap_alloc1(as, (ir+1)->op2);\n      } else\n#endif\n      {  /* Allocate stored values for TNEW, TDUP and CNEW. */\n\tIRIns *irs;\n\tlj_assertA(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW,\n\t\t   \"sink of IR %04d has bad op %d\", ref - REF_BIAS, ir->o);\n\tfor (irs = IR(as->snapref-1); irs > ir; irs--)\n\t  if (irs->r == RID_SINK && asm_sunk_store(as, ir, irs)) {\n\t    lj_assertA(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\t\t       irs->o == IR_FSTORE || irs->o == IR_XSTORE,\n\t\t       \"sunk store IR %04d has bad op %d\",\n\t\t       (int)(irs - as->ir) - REF_BIAS, irs->o);\n\t    asm_snap_alloc1(as, irs->op2);\n\t    if (LJ_32 && (irs+1)->o == IR_HIOP)\n\t      asm_snap_alloc1(as, (irs+1)->op2);\n\t  }\n      }\n    } else {\n      RegSet allow;\n      if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) {\n\tIRIns *irc;\n\tfor (irc = IR(as->curins); irc > ir; irc--)\n\t  if ((irc->op1 == ref || irc->op2 == ref) &&\n\t      !(irc->r == RID_SINK || irc->r == RID_SUNK))\n\t    goto nosink;  /* Don't sink conversion if result is used. */\n\tasm_snap_alloc1(as, ir->op1);\n\treturn;\n      }\n    nosink:\n      allow = (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR;\n      if ((as->freeset & allow) ||\n\t       (allow == RSET_FPR && asm_snap_canremat(as))) {\n\t/* Get a weak register if we have a free one or can rematerialize. */\n\tReg r = ra_allocref(as, ref, allow);  /* Allocate a register. */\n\tif (!irt_isphi(ir->t))\n\t  ra_weak(as, r);  /* But mark it as weakly referenced. */\n\tcheckmclim(as);\n\tRA_DBGX((as, \"snapreg   $f $r\", ref, ir->r));\n      } else {\n\tra_spill(as, ir);  /* Otherwise force a spill slot. */\n\tRA_DBGX((as, \"snapspill $f $s\", ref, ir->s));\n      }\n    }\n  }\n}\n\n/* Allocate refs escaping to a snapshot. */\nstatic void asm_snap_alloc(ASMState *as, int snapno)\n{\n  SnapShot *snap = &as->T->snap[snapno];\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  as->snapfilt1 = as->snapfilt2 = 0;\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    IRRef ref = snap_ref(sn);\n    if (!irref_isk(ref)) {\n      asm_snap_alloc1(as, ref);\n      if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) {\n\tlj_assertA(irt_type(IR(ref+1)->t) == IRT_SOFTFP,\n\t\t   \"snap %d[%d] points to bad SOFTFP IR %04d\",\n\t\t   snapno, n, ref - REF_BIAS);\n\tasm_snap_alloc1(as, ref+1);\n      }\n    }\n  }\n}\n\n/* All guards for a snapshot use the same exitno. This is currently the\n** same as the snapshot number. Since the exact origin of the exit cannot\n** be determined, all guards for the same snapshot must exit with the same\n** RegSP mapping.\n** A renamed ref which has been used in a prior guard for the same snapshot\n** would cause an inconsistency. The easy way out is to force a spill slot.\n*/\nstatic int asm_snap_checkrename(ASMState *as, IRRef ren)\n{\n  if (bloomtest(as->snapfilt1, ren) &&\n      bloomtest(as->snapfilt2, hashrot(ren, ren + HASH_BIAS))) {\n    IRIns *ir = IR(ren);\n    ra_spill(as, ir);  /* Register renamed, so force a spill slot. */\n    RA_DBGX((as, \"snaprensp $f $s\", ren, ir->s));\n    return 1;  /* Found. */\n  }\n  return 0;  /* Not found. */\n}\n\n/* Prepare snapshot for next guard or throwing instruction. */\nstatic void asm_snap_prep(ASMState *as)\n{\n  if (as->snapalloc) {\n    /* Alloc on first invocation for each snapshot. */\n    as->snapalloc = 0;\n    asm_snap_alloc(as, as->snapno);\n    as->snaprename = as->T->nins;\n  } else {\n    /* Check any renames above the highwater mark. */\n    for (; as->snaprename < as->T->nins; as->snaprename++) {\n      IRIns *ir = &as->T->ir[as->snaprename];\n      if (asm_snap_checkrename(as, ir->op1))\n\tir->op2 = REF_BIAS-1;  /* Kill rename. */\n    }\n  }\n}\n\n/* Move to previous snapshot when we cross the current snapshot ref. */\nstatic void asm_snap_prev(ASMState *as)\n{\n  if (as->curins < as->snapref) {\n    uintptr_t ofs = (uintptr_t)(as->mctoporig - as->mcp);\n    if (ofs >= 0x10000) lj_trace_err(as->J, LJ_TRERR_MCODEOV);\n    do {\n      if (as->snapno == 0) return;\n      as->snapno--;\n      as->snapref = as->T->snap[as->snapno].ref;\n      as->T->snap[as->snapno].mcofs = (uint16_t)ofs;  /* Remember mcode ofs. */\n    } while (as->curins < as->snapref);  /* May have no ins inbetween. */\n    as->snapalloc = 1;\n  }\n}\n\n/* Fixup snapshot mcode offsetst. */\nstatic void asm_snap_fixup_mcofs(ASMState *as)\n{\n  uint32_t sz = (uint32_t)(as->mctoporig - as->mcp);\n  SnapShot *snap = as->T->snap;\n  SnapNo i;\n  for (i = as->T->nsnap-1; i > 0; i--) {\n    /* Compute offset from mcode start and store in correct snapshot. */\n    snap[i].mcofs = (uint16_t)(sz - snap[i-1].mcofs);\n  }\n  snap[0].mcofs = 0;\n}\n\n/* -- Miscellaneous helpers ----------------------------------------------- */\n\n/* Calculate stack adjustment. */\nstatic int32_t asm_stack_adjust(ASMState *as)\n{\n  if (as->evenspill <= SPS_FIXED)\n    return 0;\n  return sps_scale(sps_align(as->evenspill));\n}\n\n/* Must match with hash*() in lj_tab.c. */\nstatic uint32_t ir_khash(ASMState *as, IRIns *ir)\n{\n  uint32_t lo, hi;\n  UNUSED(as);\n  if (irt_isstr(ir->t)) {\n    return ir_kstr(ir)->sid;\n  } else if (irt_isnum(ir->t)) {\n    lo = ir_knum(ir)->u32.lo;\n    hi = ir_knum(ir)->u32.hi << 1;\n  } else if (irt_ispri(ir->t)) {\n    lj_assertA(!irt_isnil(ir->t), \"hash of nil key\");\n    return irt_type(ir->t)-IRT_FALSE;\n  } else {\n    lj_assertA(irt_isgcv(ir->t), \"hash of bad IR type %d\", irt_type(ir->t));\n    lo = u32ptr(ir_kgc(ir));\n#if LJ_GC64\n    hi = (uint32_t)(u64ptr(ir_kgc(ir)) >> 32) | (irt_toitype(ir->t) << 15);\n#else\n    hi = lo + HASH_BIAS;\n#endif\n  }\n  return hashrot(lo, hi);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args);\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci);\n\nstatic void asm_snew(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_new];\n  IRRef args[3];\n  asm_snap_prep(as);\n  args[0] = ASMREF_L;  /* lua_State *L    */\n  args[1] = ir->op1;   /* const char *str */\n  args[2] = ir->op2;   /* size_t len      */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_tnew(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_new1];\n  IRRef args[2];\n  asm_snap_prep(as);\n  args[0] = ASMREF_L;     /* lua_State *L    */\n  args[1] = ASMREF_TMP1;  /* uint32_t ahsize */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCtab * */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, ir->op1 | (ir->op2 << 24), ra_releasetmp(as, ASMREF_TMP1));\n}\n\nstatic void asm_tdup(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_dup];\n  IRRef args[2];\n  asm_snap_prep(as);\n  args[0] = ASMREF_L;  /* lua_State *L    */\n  args[1] = ir->op1;   /* const GCtab *kt */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCtab * */\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_gc_check(ASMState *as);\n\n/* Explicit GC step. */\nstatic void asm_gcstep(ASMState *as, IRIns *ir)\n{\n  IRIns *ira;\n  for (ira = IR(as->stopins+1); ira < ir; ira++)\n    if ((ira->o == IR_TNEW || ira->o == IR_TDUP ||\n\t (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI))) &&\n\tra_used(ira))\n      as->gcsteps++;\n  if (as->gcsteps)\n    asm_gc_check(as);\n  as->gcsteps = 0x80000000;  /* Prevent implicit GC check further up. */\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode);\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb);\n#endif\n\nstatic void asm_bufhdr(ASMState *as, IRIns *ir)\n{\n  Reg sb = ra_dest(as, ir, RSET_GPR);\n  switch (ir->op2) {\n  case IRBUFHDR_RESET: {\n    Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n    IRIns irbp;\n    irbp.ot = IRT(0, IRT_PTR);  /* Buffer data pointer type. */\n    emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w));\n    emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b));\n    break;\n    }\n  case IRBUFHDR_APPEND: {\n    /* Rematerialize const buffer pointer instead of likely spill. */\n    IRIns *irp = IR(ir->op1);\n    if (!(ra_hasreg(irp->r) || irp == ir-1 ||\n\t  (irp == ir-2 && !ra_used(ir-1)))) {\n      while (!(irp->o == IR_BUFHDR && irp->op2 == IRBUFHDR_RESET))\n\tirp = IR(irp->op1);\n      if (irref_isk(irp->op1)) {\n\tra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));\n\tir = irp;\n      }\n    }\n    break;\n    }\n#if LJ_HASBUFFER\n  case IRBUFHDR_WRITE:\n    asm_bufhdr_write(as, sb);\n    break;\n#endif\n  default: lj_assertA(0, \"bad BUFHDR op2 %d\", ir->op2); break;\n  }\n#if LJ_TARGET_X86ORX64\n  ra_left(as, sb, ir->op1);\n#else\n  ra_leftov(as, sb, ir->op1);\n#endif\n}\n\nstatic void asm_bufput(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_buf_putstr];\n  IRRef args[3];\n  IRIns *irs;\n  int kchar = -129;\n  args[0] = ir->op1;  /* SBuf * */\n  args[1] = ir->op2;  /* GCstr * */\n  irs = IR(ir->op2);\n  lj_assertA(irt_isstr(irs->t),\n\t     \"BUFPUT of non-string IR %04d\", ir->op2 - REF_BIAS);\n  if (irs->o == IR_KGC) {\n    GCstr *s = ir_kstr(irs);\n    if (s->len == 1) {  /* Optimize put of single-char string constant. */\n      kchar = (int8_t)strdata(s)[0];  /* Signed! */\n      args[1] = ASMREF_TMP1;  /* int, truncated to char */\n      ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar];\n    }\n  } else if (mayfuse(as, ir->op2) && ra_noreg(irs->r)) {\n    if (irs->o == IR_TOSTR) {  /* Fuse number to string conversions. */\n      if (irs->op2 == IRTOSTR_NUM) {\n\targs[1] = ASMREF_TMP1;  /* TValue * */\n\tci = &lj_ir_callinfo[IRCALL_lj_strfmt_putnum];\n      } else {\n\tlj_assertA(irt_isinteger(IR(irs->op1)->t),\n\t\t   \"TOSTR of non-numeric IR %04d\", irs->op1);\n\targs[1] = irs->op1;  /* int */\n\tif (irs->op2 == IRTOSTR_INT)\n\t  ci = &lj_ir_callinfo[IRCALL_lj_strfmt_putint];\n\telse\n\t  ci = &lj_ir_callinfo[IRCALL_lj_buf_putchar];\n      }\n    } else if (irs->o == IR_SNEW) {  /* Fuse string allocation. */\n      args[1] = irs->op1;  /* const void * */\n      args[2] = irs->op2;  /* MSize */\n      ci = &lj_ir_callinfo[IRCALL_lj_buf_putmem];\n    }\n  }\n  asm_setupresult(as, ir, ci);  /* SBuf * */\n  asm_gencall(as, ci, args);\n  if (args[1] == ASMREF_TMP1) {\n    Reg tmp = ra_releasetmp(as, ASMREF_TMP1);\n    if (kchar == -129)\n      asm_tvptr(as, tmp, irs->op1, IRTMPREF_IN1);\n    else\n      ra_allockreg(as, kchar, tmp);\n  }\n}\n\nstatic void asm_bufstr(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_buf_tostr];\n  IRRef args[1];\n  args[0] = ir->op1;  /* SBuf *sb */\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n}\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tostr(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci;\n  IRRef args[2];\n  asm_snap_prep(as);\n  args[0] = ASMREF_L;\n  as->gcsteps++;\n  if (ir->op2 == IRTOSTR_NUM) {\n    args[1] = ASMREF_TMP1;  /* cTValue * */\n    ci = &lj_ir_callinfo[IRCALL_lj_strfmt_num];\n  } else {\n    args[1] = ir->op1;  /* int32_t k */\n    if (ir->op2 == IRTOSTR_INT)\n      ci = &lj_ir_callinfo[IRCALL_lj_strfmt_int];\n    else\n      ci = &lj_ir_callinfo[IRCALL_lj_strfmt_char];\n  }\n  asm_setupresult(as, ir, ci);  /* GCstr * */\n  asm_gencall(as, ci, args);\n  if (ir->op2 == IRTOSTR_NUM)\n    asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1, IRTMPREF_IN1);\n}\n\n#if LJ_32 && LJ_HASFFI && !LJ_SOFTFP && !LJ_TARGET_X86\nstatic void asm_conv64(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);\n  IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);\n  IRCallID id;\n  IRRef args[2];\n  lj_assertA((ir-1)->o == IR_CONV && ir->o == IR_HIOP,\n\t     \"not a CONV/HIOP pair at IR %04d\", (int)(ir - as->ir) - REF_BIAS);\n  args[LJ_BE] = (ir-1)->op1;\n  args[LJ_LE] = ir->op1;\n  if (st == IRT_NUM || st == IRT_FLOAT) {\n    id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);\n    ir--;\n  } else {\n    id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);\n  }\n  {\n#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP\n    CCallInfo cim = lj_ir_callinfo[id], *ci = &cim;\n    cim.flags |= CCI_VARARG;  /* These calls don't use the hard-float ABI! */\n#else\n    const CCallInfo *ci = &lj_ir_callinfo[id];\n#endif\n    asm_setupresult(as, ir, ci);\n    asm_gencall(as, ci, args);\n  }\n}\n#endif\n\n/* -- Memory references --------------------------------------------------- */\n\nstatic void asm_newref(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];\n  IRRef args[3];\n  if (ir->r == RID_SINK)\n    return;\n  asm_snap_prep(as);\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ir->op1;      /* GCtab *t     */\n  args[2] = ASMREF_TMP1;  /* cTValue *key */\n  asm_setupresult(as, ir, ci);  /* TValue * */\n  asm_gencall(as, ci, args);\n  asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2, IRTMPREF_IN1);\n}\n\nstatic void asm_tmpref(ASMState *as, IRIns *ir)\n{\n  Reg r = ra_dest(as, ir, RSET_GPR);\n  asm_tvptr(as, r, ir->op1, ir->op2);\n}\n\nstatic void asm_lref(ASMState *as, IRIns *ir)\n{\n  Reg r = ra_dest(as, ir, RSET_GPR);\n#if LJ_TARGET_X86ORX64\n  ra_left(as, r, ASMREF_L);\n#else\n  ra_leftov(as, r, ASMREF_L);\n#endif\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Collect arguments from CALL* and CARG instructions. */\nstatic void asm_collectargs(ASMState *as, IRIns *ir,\n\t\t\t    const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n = CCI_XNARGS(ci);\n  /* Account for split args. */\n  lj_assertA(n <= CCI_NARGS_MAX*2, \"too many args %d to collect\", n);\n  if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; }\n  while (n-- > 1) {\n    ir = IR(ir->op1);\n    lj_assertA(ir->o == IR_CARG, \"malformed CALL arg tree\");\n    args[n] = ir->op2 == REF_NIL ? 0 : ir->op2;\n  }\n  args[0] = ir->op1 == REF_NIL ? 0 : ir->op1;\n  lj_assertA(IR(ir->op1)->o != IR_CARG, \"malformed CALL arg tree\");\n}\n\n/* Reconstruct CCallInfo flags for CALLX*. */\nstatic uint32_t asm_callx_flags(ASMState *as, IRIns *ir)\n{\n  uint32_t nargs = 0;\n  if (ir->op1 != REF_NIL) {  /* Count number of arguments first. */\n    IRIns *ira = IR(ir->op1);\n    nargs++;\n    while (ira->o == IR_CARG) { nargs++; ira = IR(ira->op1); }\n  }\n#if LJ_HASFFI\n  if (IR(ir->op2)->o == IR_CARG) {  /* Copy calling convention info. */\n    CTypeID id = (CTypeID)IR(IR(ir->op2)->op2)->i;\n    CType *ct = ctype_get(ctype_ctsG(J2G(as->J)), id);\n    nargs |= ((ct->info & CTF_VARARG) ? CCI_VARARG : 0);\n#if LJ_TARGET_X86\n    nargs |= (ctype_cconv(ct->info) << CCI_CC_SHIFT);\n#endif\n  }\n#endif\n  return (nargs | (ir->t.irt << CCI_OTSHIFT));\n}\n\nstatic void asm_callid(ASMState *as, IRIns *ir, IRCallID id)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[id];\n  IRRef args[2];\n  args[0] = ir->op1;\n  args[1] = ir->op2;\n  asm_setupresult(as, ir, ci);\n  asm_gencall(as, ci, args);\n}\n\nstatic void asm_call(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX];\n  const CCallInfo *ci = &lj_ir_callinfo[ir->op2];\n  asm_collectargs(as, ir, ci, args);\n  asm_setupresult(as, ir, ci);\n  asm_gencall(as, ci, args);\n}\n\n/* -- PHI and loop handling ----------------------------------------------- */\n\n/* Break a PHI cycle by renaming to a free register (evict if needed). */\nstatic void asm_phi_break(ASMState *as, RegSet blocked, RegSet blockedby,\n\t\t\t  RegSet allow)\n{\n  RegSet candidates = blocked & allow;\n  if (candidates) {  /* If this register file has candidates. */\n    /* Note: the set for ra_pick cannot be empty, since each register file\n    ** has some registers never allocated to PHIs.\n    */\n    Reg down, up = ra_pick(as, ~blocked & allow);  /* Get a free register. */\n    if (candidates & ~blockedby)  /* Optimize shifts, else it's a cycle. */\n      candidates = candidates & ~blockedby;\n    down = rset_picktop(candidates);  /* Pick candidate PHI register. */\n    ra_rename(as, down, up);  /* And rename it to the free register. */\n  }\n}\n\n/* PHI register shuffling.\n**\n** The allocator tries hard to preserve PHI register assignments across\n** the loop body. Most of the time this loop does nothing, since there\n** are no register mismatches.\n**\n** If a register mismatch is detected and ...\n** - the register is currently free: rename it.\n** - the register is blocked by an invariant: restore/remat and rename it.\n** - Otherwise the register is used by another PHI, so mark it as blocked.\n**\n** The renames are order-sensitive, so just retry the loop if a register\n** is marked as blocked, but has been freed in the meantime. A cycle is\n** detected if all of the blocked registers are allocated. To break the\n** cycle rename one of them to a free register and retry.\n**\n** Note that PHI spill slots are kept in sync and don't need to be shuffled.\n*/\nstatic void asm_phi_shuffle(ASMState *as)\n{\n  RegSet work;\n\n  /* Find and resolve PHI register mismatches. */\n  for (;;) {\n    RegSet blocked = RSET_EMPTY;\n    RegSet blockedby = RSET_EMPTY;\n    RegSet phiset = as->phiset;\n    while (phiset) {  /* Check all left PHI operand registers. */\n      Reg r = rset_pickbot(phiset);\n      IRIns *irl = IR(as->phireg[r]);\n      Reg left = irl->r;\n      if (r != left) {  /* Mismatch? */\n\tif (!rset_test(as->freeset, r)) {  /* PHI register blocked? */\n\t  IRRef ref = regcost_ref(as->cost[r]);\n\t  /* Blocked by other PHI (w/reg)? */\n\t  if (!ra_iskref(ref) && irt_ismarked(IR(ref)->t)) {\n\t    rset_set(blocked, r);\n\t    if (ra_hasreg(left))\n\t      rset_set(blockedby, left);\n\t    left = RID_NONE;\n\t  } else {  /* Otherwise grab register from invariant. */\n\t    ra_restore(as, ref);\n\t    checkmclim(as);\n\t  }\n\t}\n\tif (ra_hasreg(left)) {\n\t  ra_rename(as, left, r);\n\t  checkmclim(as);\n\t}\n      }\n      rset_clear(phiset, r);\n    }\n    if (!blocked) break;  /* Finished. */\n    if (!(as->freeset & blocked)) {  /* Break cycles if none are free. */\n      asm_phi_break(as, blocked, blockedby, RSET_GPR);\n      if (!LJ_SOFTFP) asm_phi_break(as, blocked, blockedby, RSET_FPR);\n      checkmclim(as);\n    }  /* Else retry some more renames. */\n  }\n\n  /* Restore/remat invariants whose registers are modified inside the loop. */\n#if !LJ_SOFTFP\n  work = as->modset & ~(as->freeset | as->phiset) & RSET_FPR;\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n#endif\n  work = as->modset & ~(as->freeset | as->phiset);\n  while (work) {\n    Reg r = rset_pickbot(work);\n    ra_restore(as, regcost_ref(as->cost[r]));\n    rset_clear(work, r);\n    checkmclim(as);\n  }\n\n  /* Allocate and save all unsaved PHI regs and clear marks. */\n  work = as->phiset;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef lref = as->phireg[r];\n    IRIns *ir = IR(lref);\n    if (ra_hasspill(ir->s)) {  /* Left PHI gained a spill slot? */\n      irt_clearmark(ir->t);  /* Handled here, so clear marker now. */\n      ra_alloc1(as, lref, RID2RSET(r));\n      ra_save(as, ir, r);  /* Save to spill slot inside the loop. */\n      checkmclim(as);\n    }\n    rset_clear(work, r);\n  }\n}\n\n/* Copy unsynced left/right PHI spill slots. Rarely needed. */\nstatic void asm_phi_copyspill(ASMState *as)\n{\n  int need = 0;\n  IRIns *ir;\n  for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--)\n    if (ra_hasspill(ir->s) && ra_hasspill(IR(ir->op1)->s))\n      need |= irt_isfp(ir->t) ? 2 : 1;  /* Unsynced spill slot? */\n  if ((need & 1)) {  /* Copy integer spill slots. */\n#if !LJ_TARGET_X86ORX64\n    Reg r = RID_TMP;\n#else\n    Reg r = RID_RET;\n    if ((as->freeset & RSET_GPR))\n      r = rset_pickbot((as->freeset & RSET_GPR));\n    else\n      emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n#endif\n    for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {\n      if (ra_hasspill(ir->s)) {\n\tIRIns *irl = IR(ir->op1);\n\tif (ra_hasspill(irl->s) && !irt_isfp(ir->t)) {\n\t  emit_spstore(as, irl, r, sps_scale(irl->s));\n\t  emit_spload(as, ir, r, sps_scale(ir->s));\n\t  checkmclim(as);\n\t}\n      }\n    }\n#if LJ_TARGET_X86ORX64\n    if (!rset_test(as->freeset, r))\n      emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n#endif\n  }\n#if !LJ_SOFTFP\n  if ((need & 2)) {  /* Copy FP spill slots. */\n#if LJ_TARGET_X86\n    Reg r = RID_XMM0;\n#else\n    Reg r = RID_FPRET;\n#endif\n    if ((as->freeset & RSET_FPR))\n      r = rset_pickbot((as->freeset & RSET_FPR));\n    if (!rset_test(as->freeset, r))\n      emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n    for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {\n      if (ra_hasspill(ir->s)) {\n\tIRIns *irl = IR(ir->op1);\n\tif (ra_hasspill(irl->s) && irt_isfp(ir->t)) {\n\t  emit_spstore(as, irl, r, sps_scale(irl->s));\n\t  emit_spload(as, ir, r, sps_scale(ir->s));\n\t  checkmclim(as);\n\t}\n      }\n    }\n    if (!rset_test(as->freeset, r))\n      emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);\n  }\n#endif\n}\n\n/* Emit renames for left PHIs which are only spilled outside the loop. */\nstatic void asm_phi_fixup(ASMState *as)\n{\n  RegSet work = as->phiset;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef lref = as->phireg[r];\n    IRIns *ir = IR(lref);\n    if (irt_ismarked(ir->t)) {\n      irt_clearmark(ir->t);\n      /* Left PHI gained a spill slot before the loop? */\n      if (ra_hasspill(ir->s)) {\n\tra_addrename(as, r, lref, as->loopsnapno);\n      }\n    }\n    rset_clear(work, r);\n  }\n}\n\n/* Setup right PHI reference. */\nstatic void asm_phi(ASMState *as, IRIns *ir)\n{\n  RegSet allow = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) &\n\t\t ~as->phiset;\n  RegSet afree = (as->freeset & allow);\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  if (ir->r == RID_SINK)  /* Sink PHI. */\n    return;\n  /* Spill slot shuffling is not implemented yet (but rarely needed). */\n  if (ra_hasspill(irl->s) || ra_hasspill(irr->s))\n    lj_trace_err(as->J, LJ_TRERR_NYIPHI);\n  /* Leave at least one register free for non-PHIs (and PHI cycle breaking). */\n  if ((afree & (afree-1))) {  /* Two or more free registers? */\n    Reg r;\n    if (ra_noreg(irr->r)) {  /* Get a register for the right PHI. */\n      r = ra_allocref(as, ir->op2, allow);\n    } else {  /* Duplicate right PHI, need a copy (rare). */\n      r = ra_scratch(as, allow);\n      emit_movrr(as, irr, r, irr->r);\n    }\n    ir->r = (uint8_t)r;\n    rset_set(as->phiset, r);\n    as->phireg[r] = (IRRef1)ir->op1;\n    irt_setmark(irl->t);  /* Marks left PHIs _with_ register. */\n    if (ra_noreg(irl->r))\n      ra_sethint(irl->r, r); /* Set register hint for left PHI. */\n  } else {  /* Otherwise allocate a spill slot. */\n    /* This is overly restrictive, but it triggers only on synthetic code. */\n    if (ra_hasreg(irl->r) || ra_hasreg(irr->r))\n      lj_trace_err(as->J, LJ_TRERR_NYIPHI);\n    ra_spill(as, ir);\n    irr->s = ir->s;  /* Set right PHI spill slot. Sync left slot later. */\n  }\n}\n\nstatic void asm_loop_fixup(ASMState *as);\n\n/* Middle part of a loop. */\nstatic void asm_loop(ASMState *as)\n{\n  MCode *mcspill;\n  /* LOOP is a guard, so the snapno is up to date. */\n  as->loopsnapno = as->snapno;\n  if (as->gcsteps)\n    asm_gc_check(as);\n  /* LOOP marks the transition from the variant to the invariant part. */\n  as->flagmcp = as->invmcp = NULL;\n  as->sectref = 0;\n  if (!neverfuse(as)) as->fuseref = 0;\n  asm_phi_shuffle(as);\n  mcspill = as->mcp;\n  asm_phi_copyspill(as);\n  asm_loop_fixup(as);\n  as->mcloop = as->mcp;\n  RA_DBGX((as, \"===== LOOP =====\"));\n  if (!as->realign) RA_DBG_FLUSH();\n  if (as->mcp != mcspill)\n    emit_jmp(as, mcspill);\n}\n\n/* -- Target-specific assembler ------------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_asm_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_asm_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"lj_asm_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_asm_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_asm_mips.h\"\n#else\n#error \"Missing assembler for target CPU\"\n#endif\n\n/* -- Common instruction helpers ------------------------------------------ */\n\n#if !LJ_SOFTFP32\n#if !LJ_TARGET_X86ORX64\n#define asm_ldexp(as, ir)\tasm_callid(as, ir, IRCALL_ldexp)\n#define asm_fppowi(as, ir)\tasm_callid(as, ir, IRCALL_lj_vm_powi)\n#endif\n\nstatic void asm_pow(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isnum(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :\n\t\t\t\t\t  IRCALL_lj_carith_powu64);\n  else\n#endif\n  if (irt_isnum(IR(ir->op2)->t))\n    asm_callid(as, ir, IRCALL_pow);\n  else\n    asm_fppowi(as, ir);\n}\n\nstatic void asm_div(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isnum(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :\n\t\t\t\t\t  IRCALL_lj_carith_divu64);\n  else\n#endif\n    asm_fpdiv(as, ir);\n}\n#endif\n\nstatic void asm_mod(ASMState *as, IRIns *ir)\n{\n#if LJ_64 && LJ_HASFFI\n  if (!irt_isint(ir->t))\n    asm_callid(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :\n\t\t\t\t\t  IRCALL_lj_carith_modu64);\n  else\n#endif\n    asm_callid(as, ir, IRCALL_lj_vm_modi);\n}\n\nstatic void asm_fuseequal(ASMState *as, IRIns *ir)\n{\n  /* Fuse HREF + EQ/NE. */\n  if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {\n    as->curins--;\n    asm_href(as, ir-1, (IROp)ir->o);\n  } else {\n    asm_equal(as, ir);\n  }\n}\n\nstatic void asm_alen(ASMState *as, IRIns *ir)\n{\n  asm_callid(as, ir, ir->op2 == REF_NIL ? IRCALL_lj_tab_len :\n\t\t\t\t\t  IRCALL_lj_tab_len_hint);\n}\n\n/* -- Instruction dispatch ------------------------------------------------ */\n\n/* Assemble a single instruction. */\nstatic void asm_ir(ASMState *as, IRIns *ir)\n{\n  switch ((IROp)ir->o) {\n  /* Miscellaneous ops. */\n  case IR_LOOP: asm_loop(as); break;\n  case IR_NOP: case IR_XBAR:\n    lj_assertA(!ra_used(ir),\n\t       \"IR %04d not unused\", (int)(ir - as->ir) - REF_BIAS);\n    break;\n  case IR_USE:\n    ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;\n  case IR_PHI: asm_phi(as, ir); break;\n  case IR_HIOP: asm_hiop(as, ir); break;\n  case IR_GCSTEP: asm_gcstep(as, ir); break;\n  case IR_PROF: asm_prof(as, ir); break;\n\n  /* Guarded assertions. */\n  case IR_LT: case IR_GE: case IR_LE: case IR_GT:\n  case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:\n  case IR_ABC:\n    asm_comp(as, ir);\n    break;\n  case IR_EQ: case IR_NE: asm_fuseequal(as, ir); break;\n\n  case IR_RETF: asm_retf(as, ir); break;\n\n  /* Bit ops. */\n  case IR_BNOT: asm_bnot(as, ir); break;\n  case IR_BSWAP: asm_bswap(as, ir); break;\n  case IR_BAND: asm_band(as, ir); break;\n  case IR_BOR: asm_bor(as, ir); break;\n  case IR_BXOR: asm_bxor(as, ir); break;\n  case IR_BSHL: asm_bshl(as, ir); break;\n  case IR_BSHR: asm_bshr(as, ir); break;\n  case IR_BSAR: asm_bsar(as, ir); break;\n  case IR_BROL: asm_brol(as, ir); break;\n  case IR_BROR: asm_bror(as, ir); break;\n\n  /* Arithmetic ops. */\n  case IR_ADD: asm_add(as, ir); break;\n  case IR_SUB: asm_sub(as, ir); break;\n  case IR_MUL: asm_mul(as, ir); break;\n  case IR_MOD: asm_mod(as, ir); break;\n  case IR_NEG: asm_neg(as, ir); break;\n#if LJ_SOFTFP32\n  case IR_DIV: case IR_POW: case IR_ABS:\n  case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:\n    /* Unused for LJ_SOFTFP32. */\n    lj_assertA(0, \"IR %04d with unused op %d\",\n\t\t  (int)(ir - as->ir) - REF_BIAS, ir->o);\n    break;\n#else\n  case IR_DIV: asm_div(as, ir); break;\n  case IR_POW: asm_pow(as, ir); break;\n  case IR_ABS: asm_abs(as, ir); break;\n  case IR_LDEXP: asm_ldexp(as, ir); break;\n  case IR_FPMATH: asm_fpmath(as, ir); break;\n  case IR_TOBIT: asm_tobit(as, ir); break;\n#endif\n  case IR_MIN: asm_min(as, ir); break;\n  case IR_MAX: asm_max(as, ir); break;\n\n  /* Overflow-checking arithmetic ops. */\n  case IR_ADDOV: asm_addov(as, ir); break;\n  case IR_SUBOV: asm_subov(as, ir); break;\n  case IR_MULOV: asm_mulov(as, ir); break;\n\n  /* Memory references. */\n  case IR_AREF: asm_aref(as, ir); break;\n  case IR_HREF: asm_href(as, ir, 0); break;\n  case IR_HREFK: asm_hrefk(as, ir); break;\n  case IR_NEWREF: asm_newref(as, ir); break;\n  case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;\n  case IR_FREF: asm_fref(as, ir); break;\n  case IR_TMPREF: asm_tmpref(as, ir); break;\n  case IR_STRREF: asm_strref(as, ir); break;\n  case IR_LREF: asm_lref(as, ir); break;\n\n  /* Loads and stores. */\n  case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n    asm_ahuvload(as, ir);\n    break;\n  case IR_FLOAD: asm_fload(as, ir); break;\n  case IR_XLOAD: asm_xload(as, ir); break;\n  case IR_SLOAD: asm_sload(as, ir); break;\n  case IR_ALEN: asm_alen(as, ir); break;\n\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;\n  case IR_FSTORE: asm_fstore(as, ir); break;\n  case IR_XSTORE: asm_xstore(as, ir); break;\n\n  /* Allocations. */\n  case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;\n  case IR_TNEW: asm_tnew(as, ir); break;\n  case IR_TDUP: asm_tdup(as, ir); break;\n  case IR_CNEW: case IR_CNEWI:\n#if LJ_HASFFI\n    asm_cnew(as, ir);\n#else\n    lj_assertA(0, \"IR %04d with unused op %d\",\n\t\t  (int)(ir - as->ir) - REF_BIAS, ir->o);\n#endif\n    break;\n\n  /* Buffer operations. */\n  case IR_BUFHDR: asm_bufhdr(as, ir); break;\n  case IR_BUFPUT: asm_bufput(as, ir); break;\n  case IR_BUFSTR: asm_bufstr(as, ir); break;\n\n  /* Write barriers. */\n  case IR_TBAR: asm_tbar(as, ir); break;\n  case IR_OBAR: asm_obar(as, ir); break;\n\n  /* Type conversions. */\n  case IR_CONV: asm_conv(as, ir); break;\n  case IR_TOSTR: asm_tostr(as, ir); break;\n  case IR_STRTO: asm_strto(as, ir); break;\n\n  /* Calls. */\n  case IR_CALLA:\n    as->gcsteps++;\n    /* fallthrough */\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;\n  case IR_CALLXS: asm_callx(as, ir); break;\n  case IR_CARG: break;\n\n  default:\n    setintV(&as->J->errinfo, ir->o);\n    lj_trace_err_info(as->J, LJ_TRERR_NYIIR);\n    break;\n  }\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Head of a root trace. */\nstatic void asm_head_root(ASMState *as)\n{\n  int32_t spadj;\n  asm_head_root_base(as);\n  emit_setvmstate(as, (int32_t)as->T->traceno);\n  spadj = asm_stack_adjust(as);\n  as->T->spadjust = (uint16_t)spadj;\n  emit_spsub(as, spadj);\n  /* Root traces assume a checked stack for the starting proto. */\n  as->T->topslot = gcref(as->T->startpt)->pt.framesize;\n}\n\n/* Head of a side trace.\n**\n** The current simplistic algorithm requires that all slots inherited\n** from the parent are live in a register between pass 2 and pass 3. This\n** avoids the complexity of stack slot shuffling. But of course this may\n** overflow the register set in some cases and cause the dreaded error:\n** \"NYI: register coalescing too complex\". A refined algorithm is needed.\n*/\nstatic void asm_head_side(ASMState *as)\n{\n  IRRef1 sloadins[RID_MAX];\n  RegSet allow = RSET_ALL;  /* Inverse of all coalesced registers. */\n  RegSet live = RSET_EMPTY;  /* Live parent registers. */\n  IRIns *irp = &as->parent->ir[REF_BASE];  /* Parent base. */\n  int32_t spadj, spdelta;\n  int pass2 = 0;\n  int pass3 = 0;\n  IRRef i;\n\n  if (as->snapno && as->topslot > as->parent->topslot) {\n    /* Force snap #0 alloc to prevent register overwrite in stack check. */\n    asm_snap_alloc(as, 0);\n  }\n  allow = asm_head_side_base(as, irp, allow);\n\n  /* Scan all parent SLOADs and collect register dependencies. */\n  for (i = as->stopins; i > REF_BASE; i--) {\n    IRIns *ir = IR(i);\n    RegSP rs;\n    lj_assertA((ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_PARENT)) ||\n\t       (LJ_SOFTFP && ir->o == IR_HIOP) || ir->o == IR_PVAL,\n\t       \"IR %04d has bad parent op %d\",\n\t       (int)(ir - as->ir) - REF_BIAS, ir->o);\n    rs = as->parentmap[i - REF_FIRST];\n    if (ra_hasreg(ir->r)) {\n      rset_clear(allow, ir->r);\n      if (ra_hasspill(ir->s)) {\n\tra_save(as, ir, ir->r);\n\tcheckmclim(as);\n      }\n    } else if (ra_hasspill(ir->s)) {\n      irt_setmark(ir->t);\n      pass2 = 1;\n    }\n    if (ir->r == rs) {  /* Coalesce matching registers right now. */\n      ra_free(as, ir->r);\n    } else if (ra_hasspill(regsp_spill(rs))) {\n      if (ra_hasreg(ir->r))\n\tpass3 = 1;\n    } else if (ra_used(ir)) {\n      sloadins[rs] = (IRRef1)i;\n      rset_set(live, rs);  /* Block live parent register. */\n    }\n  }\n\n  /* Calculate stack frame adjustment. */\n  spadj = asm_stack_adjust(as);\n  spdelta = spadj - (int32_t)as->parent->spadjust;\n  if (spdelta < 0) {  /* Don't shrink the stack frame. */\n    spadj = (int32_t)as->parent->spadjust;\n    spdelta = 0;\n  }\n  as->T->spadjust = (uint16_t)spadj;\n\n  /* Reload spilled target registers. */\n  if (pass2) {\n    for (i = as->stopins; i > REF_BASE; i--) {\n      IRIns *ir = IR(i);\n      if (irt_ismarked(ir->t)) {\n\tRegSet mask;\n\tReg r;\n\tRegSP rs;\n\tirt_clearmark(ir->t);\n\trs = as->parentmap[i - REF_FIRST];\n\tif (!ra_hasspill(regsp_spill(rs)))\n\t  ra_sethint(ir->r, rs);  /* Hint may be gone, set it again. */\n\telse if (sps_scale(regsp_spill(rs))+spdelta == sps_scale(ir->s))\n\t  continue;  /* Same spill slot, do nothing. */\n\tmask = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & allow;\n\tif (mask == RSET_EMPTY)\n\t  lj_trace_err(as->J, LJ_TRERR_NYICOAL);\n\tr = ra_allocref(as, i, mask);\n\tra_save(as, ir, r);\n\trset_clear(allow, r);\n\tif (r == rs) {  /* Coalesce matching registers right now. */\n\t  ra_free(as, r);\n\t  rset_clear(live, r);\n\t} else if (ra_hasspill(regsp_spill(rs))) {\n\t  pass3 = 1;\n\t}\n\tcheckmclim(as);\n      }\n    }\n  }\n\n  /* Store trace number and adjust stack frame relative to the parent. */\n  emit_setvmstate(as, (int32_t)as->T->traceno);\n  emit_spsub(as, spdelta);\n\n#if !LJ_TARGET_X86ORX64\n  /* Restore BASE register from parent spill slot. */\n  if (ra_hasspill(irp->s))\n    emit_spload(as, IR(REF_BASE), IR(REF_BASE)->r, sps_scale(irp->s));\n#endif\n\n  /* Restore target registers from parent spill slots. */\n  if (pass3) {\n    RegSet work = ~as->freeset & RSET_ALL;\n    while (work) {\n      Reg r = rset_pickbot(work);\n      IRRef ref = regcost_ref(as->cost[r]);\n      RegSP rs = as->parentmap[ref - REF_FIRST];\n      rset_clear(work, r);\n      if (ra_hasspill(regsp_spill(rs))) {\n\tint32_t ofs = sps_scale(regsp_spill(rs));\n\tra_free(as, r);\n\temit_spload(as, IR(ref), r, ofs);\n\tcheckmclim(as);\n      }\n    }\n  }\n\n  /* Shuffle registers to match up target regs with parent regs. */\n  for (;;) {\n    RegSet work;\n\n    /* Repeatedly coalesce free live registers by moving to their target. */\n    while ((work = as->freeset & live) != RSET_EMPTY) {\n      Reg rp = rset_pickbot(work);\n      IRIns *ir = IR(sloadins[rp]);\n      rset_clear(live, rp);\n      rset_clear(allow, rp);\n      ra_free(as, ir->r);\n      emit_movrr(as, ir, ir->r, rp);\n      checkmclim(as);\n    }\n\n    /* We're done if no live registers remain. */\n    if (live == RSET_EMPTY)\n      break;\n\n    /* Break cycles by renaming one target to a temp. register. */\n    if (live & RSET_GPR) {\n      RegSet tmpset = as->freeset & ~live & allow & RSET_GPR;\n      if (tmpset == RSET_EMPTY)\n\tlj_trace_err(as->J, LJ_TRERR_NYICOAL);\n      ra_rename(as, rset_pickbot(live & RSET_GPR), rset_pickbot(tmpset));\n    }\n    if (!LJ_SOFTFP && (live & RSET_FPR)) {\n      RegSet tmpset = as->freeset & ~live & allow & RSET_FPR;\n      if (tmpset == RSET_EMPTY)\n\tlj_trace_err(as->J, LJ_TRERR_NYICOAL);\n      ra_rename(as, rset_pickbot(live & RSET_FPR), rset_pickbot(tmpset));\n    }\n    checkmclim(as);\n    /* Continue with coalescing to fix up the broken cycle(s). */\n  }\n\n  /* Inherit top stack slot already checked by parent trace. */\n  as->T->topslot = as->parent->topslot;\n  if (as->topslot > as->T->topslot) {  /* Need to check for higher slot? */\n#ifdef EXITSTATE_CHECKEXIT\n    /* Highest exit + 1 indicates stack check. */\n    ExitNo exitno = as->T->nsnap;\n#else\n    /* Reuse the parent exit in the context of the parent trace. */\n    ExitNo exitno = as->J->exitno;\n#endif\n    as->T->topslot = (uint8_t)as->topslot;  /* Remember for child traces. */\n    asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno);\n  }\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Get base slot for a snapshot. */\nstatic BCReg asm_baseslot(ASMState *as, SnapShot *snap, int *gotframe)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  MSize n;\n  for (n = snap->nent; n > 0; n--) {\n    SnapEntry sn = map[n-1];\n    if ((sn & SNAP_FRAME)) {\n      *gotframe = 1;\n      return snap_slot(sn) - LJ_FR2;\n    }\n  }\n  return 0;\n}\n\n/* Link to another trace. */\nstatic void asm_tail_link(ASMState *as)\n{\n  SnapNo snapno = as->T->nsnap-1;  /* Last snapshot. */\n  SnapShot *snap = &as->T->snap[snapno];\n  int gotframe = 0;\n  BCReg baseslot = asm_baseslot(as, snap, &gotframe);\n\n  as->topslot = snap->topslot;\n  checkmclim(as);\n  ra_allocref(as, REF_BASE, RID2RSET(RID_BASE));\n\n  if (as->T->link == 0) {\n    /* Setup fixed registers for exit to interpreter. */\n    const BCIns *pc = snap_pc(&as->T->snapmap[snap->mapofs + snap->nent]);\n    int32_t mres;\n    if (bc_op(*pc) == BC_JLOOP) {  /* NYI: find a better way to do this. */\n      BCIns *retpc = &traceref(as->J, bc_d(*pc))->startins;\n      if (bc_isret(bc_op(*retpc)))\n\tpc = retpc;\n    }\n#if LJ_GC64\n    emit_loadu64(as, RID_LPC, u64ptr(pc));\n#else\n    ra_allockreg(as, i32ptr(J2GG(as->J)->dispatch), RID_DISPATCH);\n    ra_allockreg(as, i32ptr(pc), RID_LPC);\n#endif\n    mres = (int32_t)(snap->nslots - baseslot - LJ_FR2);\n    switch (bc_op(*pc)) {\n    case BC_CALLM: case BC_CALLMT:\n      mres -= (int32_t)(1 + LJ_FR2 + bc_a(*pc) + bc_c(*pc)); break;\n    case BC_RETM: mres -= (int32_t)(bc_a(*pc) + bc_d(*pc)); break;\n    case BC_TSETM: mres -= (int32_t)bc_a(*pc); break;\n    default: if (bc_op(*pc) < BC_FUNCF) mres = 0; break;\n    }\n    ra_allockreg(as, mres, RID_RET);  /* Return MULTRES or 0. */\n  } else if (baseslot) {\n    /* Save modified BASE for linking to trace with higher start frame. */\n    emit_setgl(as, RID_BASE, jit_base);\n  }\n  emit_addptr(as, RID_BASE, 8*(int32_t)baseslot);\n\n  if (as->J->ktrace) {  /* Patch ktrace slot with the final GCtrace pointer. */\n    setgcref(IR(as->J->ktrace)[LJ_GC64].gcr, obj2gco(as->J->curfinal));\n    IR(as->J->ktrace)->o = IR_KGC;\n  }\n\n  /* Sync the interpreter state with the on-trace state. */\n  asm_stack_restore(as, snap);\n\n  /* Root traces that add frames need to check the stack at the end. */\n  if (!as->parent && gotframe)\n    asm_stack_check(as, as->topslot, NULL, as->freeset & RSET_GPR, snapno);\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Clear reg/sp for all instructions and add register hints. */\nstatic void asm_setup_regsp(ASMState *as)\n{\n  GCtrace *T = as->T;\n  int sink = T->sinktags;\n  IRRef nins = T->nins;\n  IRIns *ir, *lastir;\n  int inloop;\n#if LJ_TARGET_ARM\n  uint32_t rload = 0xa6402a64;\n#endif\n\n  ra_setup(as);\n#if LJ_TARGET_ARM64\n  ra_setkref(as, RID_GL, (intptr_t)J2G(as->J));\n#endif\n\n  /* Clear reg/sp for constants. */\n  for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++) {\n    ir->prev = REGSP_INIT;\n    if (irt_is64(ir->t) && ir->o != IR_KNULL) {\n#if LJ_GC64\n      /* The false-positive of irt_is64() for ASMREF_L (REF_NIL) is OK here. */\n      ir->i = 0;  /* Will become non-zero only for RIP-relative addresses. */\n#else\n      /* Make life easier for backends by putting address of constant in i. */\n      ir->i = (int32_t)(intptr_t)(ir+1);\n#endif\n      ir++;\n    }\n  }\n\n  /* REF_BASE is used for implicit references to the BASE register. */\n  lastir->prev = REGSP_HINT(RID_BASE);\n\n  as->snaprename = nins;\n  as->snapref = nins;\n  as->snapno = T->nsnap;\n  as->snapalloc = 0;\n\n  as->stopins = REF_BASE;\n  as->orignins = nins;\n  as->curins = nins;\n\n  /* Setup register hints for parent link instructions. */\n  ir = IR(REF_FIRST);\n  if (as->parent) {\n    uint16_t *p;\n    lastir = lj_snap_regspmap(as->J, as->parent, as->J->exitno, ir);\n    if (lastir - ir > LJ_MAX_JSLOTS)\n      lj_trace_err(as->J, LJ_TRERR_NYICOAL);\n    as->stopins = (IRRef)((lastir-1) - as->ir);\n    for (p = as->parentmap; ir < lastir; ir++) {\n      RegSP rs = ir->prev;\n      *p++ = (uint16_t)rs;  /* Copy original parent RegSP to parentmap. */\n      if (!ra_hasspill(regsp_spill(rs)))\n\tir->prev = (uint16_t)REGSP_HINT(regsp_reg(rs));\n      else\n\tir->prev = REGSP_INIT;\n    }\n  }\n\n  inloop = 0;\n  as->evenspill = SPS_FIRST;\n  for (lastir = IR(nins); ir < lastir; ir++) {\n    if (sink) {\n      if (ir->r == RID_SINK)\n\tcontinue;\n      if (ir->r == RID_SUNK) {  /* Revert after ASM restart. */\n\tir->r = RID_SINK;\n\tcontinue;\n      }\n    }\n    switch (ir->o) {\n    case IR_LOOP:\n      inloop = 1;\n      break;\n#if LJ_TARGET_ARM\n    case IR_SLOAD:\n      if (!((ir->op2 & IRSLOAD_TYPECHECK) || (ir+1)->o == IR_HIOP))\n\tbreak;\n      /* fallthrough */\n    case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n      if (!LJ_SOFTFP && irt_isnum(ir->t)) break;\n      ir->prev = (uint16_t)REGSP_HINT((rload & 15));\n      rload = lj_ror(rload, 4);\n      continue;\n    case IR_TMPREF:\n      if ((ir->op2 & IRTMPREF_OUT2) && as->evenspill < 4)\n\tas->evenspill = 4;  /* TMPREF OUT2 needs two TValues on the stack. */\n      break;\n#endif\n    case IR_CALLXS: {\n      CCallInfo ci;\n      ci.flags = asm_callx_flags(as, ir);\n      ir->prev = asm_setup_call_slots(as, ir, &ci);\n      if (inloop)\n\tas->modset |= RSET_SCRATCH;\n      continue;\n      }\n    case IR_CALLL:\n      /* lj_vm_next needs two TValues on the stack. */\n#if LJ_TARGET_X64 && LJ_ABI_WIN\n      if (ir->op2 == IRCALL_lj_vm_next && as->evenspill < SPS_FIRST + 4)\n\tas->evenspill = SPS_FIRST + 4;\n#else\n      if (SPS_FIRST < 4 && ir->op2 == IRCALL_lj_vm_next && as->evenspill < 4)\n\tas->evenspill = 4;\n#endif\n      /* fallthrough */\n    case IR_CALLN: case IR_CALLA: case IR_CALLS: {\n      const CCallInfo *ci = &lj_ir_callinfo[ir->op2];\n      ir->prev = asm_setup_call_slots(as, ir, ci);\n      if (inloop)\n\tas->modset |= (ci->flags & CCI_NOFPRCLOBBER) ?\n\t\t      (RSET_SCRATCH & ~RSET_FPR) : RSET_SCRATCH;\n      continue;\n      }\n    case IR_HIOP:\n      switch ((ir-1)->o) {\n#if LJ_SOFTFP && LJ_TARGET_ARM\n      case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n\tif (ra_hashint((ir-1)->r)) {\n\t  ir->prev = (ir-1)->prev + 1;\n\t  continue;\n\t}\n\tbreak;\n#endif\n#if !LJ_SOFTFP && LJ_NEED_FP64 && LJ_32 && LJ_HASFFI\n      case IR_CONV:\n\tif (irt_isfp((ir-1)->t)) {\n\t  ir->prev = REGSP_HINT(RID_FPRET);\n\t  continue;\n\t}\n#endif\n      /* fallthrough */\n      case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS:\n#if LJ_SOFTFP\n      case IR_MIN: case IR_MAX:\n#endif\n\t(ir-1)->prev = REGSP_HINT(RID_RETLO);\n\tir->prev = REGSP_HINT(RID_RETHI);\n\tcontinue;\n      default:\n\tbreak;\n      }\n      break;\n#if LJ_SOFTFP\n    case IR_MIN: case IR_MAX:\n      if ((ir+1)->o != IR_HIOP) break;\n#endif\n    /* fallthrough */\n    /* C calls evict all scratch regs and return results in RID_RET. */\n    case IR_SNEW: case IR_XSNEW: case IR_NEWREF: case IR_BUFPUT:\n      if (REGARG_NUMGPR < 3 && as->evenspill < 3)\n\tas->evenspill = 3;  /* lj_str_new and lj_tab_newkey need 3 args. */\n#if LJ_TARGET_X86 && LJ_HASFFI\n      if (0) {\n    case IR_CNEW:\n\tif (ir->op2 != REF_NIL && as->evenspill < 4)\n\t  as->evenspill = 4;  /* lj_cdata_newv needs 4 args. */\n      }\n      /* fallthrough */\n#else\n      /* fallthrough */\n    case IR_CNEW:\n#endif\n      /* fallthrough */\n    case IR_TNEW: case IR_TDUP: case IR_CNEWI: case IR_TOSTR:\n    case IR_BUFSTR:\n      ir->prev = REGSP_HINT(RID_RET);\n      if (inloop)\n\tas->modset = RSET_SCRATCH;\n      continue;\n    case IR_STRTO: case IR_OBAR:\n      if (inloop)\n\tas->modset = RSET_SCRATCH;\n      break;\n#if !LJ_SOFTFP\n#if !LJ_TARGET_X86ORX64\n    case IR_LDEXP:\n#endif\n#endif\n      /* fallthrough */\n    case IR_POW:\n      if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n\tif (inloop)\n\t  as->modset |= RSET_SCRATCH;\n#if LJ_TARGET_X86\n\tif (irt_isnum(IR(ir->op2)->t)) {\n\t  if (as->evenspill < 4)  /* Leave room to call pow(). */\n\t    as->evenspill = 4;\n\t}\n\tbreak;\n#else\n\tir->prev = REGSP_HINT(RID_FPRET);\n\tcontinue;\n#endif\n      }\n      /* fallthrough */ /* for integer POW */\n    case IR_DIV: case IR_MOD:\n      if ((LJ_64 && LJ_SOFTFP) || !irt_isnum(ir->t)) {\n\tir->prev = REGSP_HINT(RID_RET);\n\tif (inloop)\n\t  as->modset |= (RSET_SCRATCH & RSET_GPR);\n\tcontinue;\n      }\n      break;\n#if LJ_64 && LJ_SOFTFP\n    case IR_ADD: case IR_SUB: case IR_MUL:\n      if (irt_isnum(ir->t)) {\n\tir->prev = REGSP_HINT(RID_RET);\n\tif (inloop)\n\t  as->modset |= (RSET_SCRATCH & RSET_GPR);\n\tcontinue;\n      }\n      break;\n#endif\n    case IR_FPMATH:\n#if LJ_TARGET_X86ORX64\n      if (ir->op2 <= IRFPM_TRUNC) {\n\tif (!(as->flags & JIT_F_SSE4_1)) {\n\t  ir->prev = REGSP_HINT(RID_XMM0);\n\t  if (inloop)\n\t    as->modset |= RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);\n\t  continue;\n\t}\n\tbreak;\n      }\n#endif\n      if (inloop)\n\tas->modset |= RSET_SCRATCH;\n#if LJ_TARGET_X86\n      break;\n#else\n      ir->prev = REGSP_HINT(RID_FPRET);\n      continue;\n#endif\n#if LJ_TARGET_X86ORX64\n    /* Non-constant shift counts need to be in RID_ECX on x86/x64. */\n    case IR_BSHL: case IR_BSHR: case IR_BSAR:\n      if ((as->flags & JIT_F_BMI2))  /* Except if BMI2 is available. */\n\tbreak;\n      /* fallthrough */\n    case IR_BROL: case IR_BROR:\n      if (!irref_isk(ir->op2) && !ra_hashint(IR(ir->op2)->r)) {\n\tIR(ir->op2)->r = REGSP_HINT(RID_ECX);\n\tif (inloop)\n\t  rset_set(as->modset, RID_ECX);\n      }\n      break;\n#endif\n    /* Do not propagate hints across type conversions or loads. */\n    case IR_TOBIT:\n    case IR_XLOAD:\n#if !LJ_TARGET_ARM\n    case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n#endif\n      break;\n    case IR_CONV:\n      if (irt_isfp(ir->t) || (ir->op2 & IRCONV_SRCMASK) == IRT_NUM ||\n\t  (ir->op2 & IRCONV_SRCMASK) == IRT_FLOAT)\n\tbreak;\n      /* fallthrough */\n    default:\n      /* Propagate hints across likely 'op reg, imm' or 'op reg'. */\n      if (irref_isk(ir->op2) && !irref_isk(ir->op1) &&\n\t  ra_hashint(regsp_reg(IR(ir->op1)->prev))) {\n\tir->prev = IR(ir->op1)->prev;\n\tcontinue;\n      }\n      break;\n    }\n    ir->prev = REGSP_INIT;\n  }\n  if ((as->evenspill & 1))\n    as->oddspill = as->evenspill++;\n  else\n    as->oddspill = 0;\n}\n\n/* -- Assembler core ------------------------------------------------------ */\n\n/* Assemble a trace. */\nvoid lj_asm_trace(jit_State *J, GCtrace *T)\n{\n  ASMState as_;\n  ASMState *as = &as_;\n\n  /* Remove nops/renames left over from ASM restart due to LJ_TRERR_MCODELM. */\n  {\n    IRRef nins = T->nins;\n    IRIns *ir = &T->ir[nins-1];\n    if (ir->o == IR_NOP || ir->o == IR_RENAME) {\n      do { ir--; nins--; } while (ir->o == IR_NOP || ir->o == IR_RENAME);\n      T->nins = nins;\n    }\n  }\n\n  /* Ensure an initialized instruction beyond the last one for HIOP checks. */\n  /* This also allows one RENAME to be added without reallocating curfinal. */\n  as->orignins = lj_ir_nextins(J);\n  lj_ir_nop(&J->cur.ir[as->orignins]);\n\n  /* Setup initial state. Copy some fields to reduce indirections. */\n  as->J = J;\n  as->T = T;\n  J->curfinal = lj_trace_alloc(J->L, T);  /* This copies the IR, too. */\n  as->flags = J->flags;\n  as->loopref = J->loopref;\n  as->realign = NULL;\n  as->loopinv = 0;\n  as->parent = J->parent ? traceref(J, J->parent) : NULL;\n\n  /* Reserve MCode memory. */\n  as->mctop = as->mctoporig = lj_mcode_reserve(J, &as->mcbot);\n  as->mcp = as->mctop;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  asm_setup_target(as);\n\n  /*\n  ** This is a loop, because the MCode may have to be (re-)assembled\n  ** multiple times:\n  **\n  ** 1. as->realign is set (and the assembly aborted), if the arch-specific\n  **    backend wants the MCode to be aligned differently.\n  **\n  **    This is currently only the case on x86/x64, where small loops get\n  **    an aligned loop body plus a short branch. Not much effort is wasted,\n  **    because the abort happens very quickly and only once.\n  **\n  ** 2. The IR is immovable, since the MCode embeds pointers to various\n  **    constants inside the IR. But RENAMEs may need to be added to the IR\n  **    during assembly, which might grow and reallocate the IR. We check\n  **    at the end if the IR (in J->cur.ir) has actually grown, resize the\n  **    copy (in J->curfinal.ir) and try again.\n  **\n  **    95% of all traces have zero RENAMEs, 3% have one RENAME, 1.5% have\n  **    2 RENAMEs and only 0.5% have more than that. That's why we opt to\n  **    always have one spare slot in the IR (see above), which means we\n  **    have to redo the assembly for only ~2% of all traces.\n  **\n  **    Very, very rarely, this needs to be done repeatedly, since the\n  **    location of constants inside the IR (actually, reachability from\n  **    a global pointer) may affect register allocation and thus the\n  **    number of RENAMEs.\n  */\n  for (;;) {\n    as->mcp = as->mctop;\n#ifdef LUA_USE_ASSERT\n    as->mcp_prev = as->mcp;\n#endif\n    as->ir = J->curfinal->ir;  /* Use the copied IR. */\n    as->curins = J->cur.nins = as->orignins;\n\n    RA_DBG_START();\n    RA_DBGX((as, \"===== STOP =====\"));\n\n    /* General trace setup. Emit tail of trace. */\n    asm_tail_prep(as);\n    as->mcloop = NULL;\n    as->flagmcp = NULL;\n    as->topslot = 0;\n    as->gcsteps = 0;\n    as->sectref = as->loopref;\n    as->fuseref = (as->flags & JIT_F_OPT_FUSE) ? as->loopref : FUSE_DISABLED;\n    asm_setup_regsp(as);\n    if (!as->loopref)\n      asm_tail_link(as);\n\n    /* Assemble a trace in linear backwards order. */\n    for (as->curins--; as->curins > as->stopins; as->curins--) {\n      IRIns *ir = IR(as->curins);\n      /* 64 bit types handled by SPLIT for 32 bit archs. */\n      lj_assertA(!(LJ_32 && irt_isint64(ir->t)),\n\t\t \"IR %04d has unsplit 64 bit type\",\n\t\t (int)(ir - as->ir) - REF_BIAS);\n      asm_snap_prev(as);\n      if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE))\n\tcontinue;  /* Dead-code elimination can be soooo easy. */\n      if (irt_isguard(ir->t))\n\tasm_snap_prep(as);\n      RA_DBG_REF();\n      checkmclim(as);\n      asm_ir(as, ir);\n    }\n\n    if (as->realign && J->curfinal->nins >= T->nins)\n      continue;  /* Retry in case only the MCode needs to be realigned. */\n\n    /* Emit head of trace. */\n    RA_DBG_REF();\n    checkmclim(as);\n    if (as->gcsteps > 0) {\n      as->curins = as->T->snap[0].ref;\n      asm_snap_prep(as);  /* The GC check is a guard. */\n      asm_gc_check(as);\n      as->curins = as->stopins;\n    }\n    ra_evictk(as);\n    if (as->parent)\n      asm_head_side(as);\n    else\n      asm_head_root(as);\n    asm_phi_fixup(as);\n\n    if (J->curfinal->nins >= T->nins) {  /* IR didn't grow? */\n      lj_assertA(J->curfinal->nk == T->nk, \"unexpected IR constant growth\");\n      memcpy(J->curfinal->ir + as->orignins, T->ir + as->orignins,\n\t     (T->nins - as->orignins) * sizeof(IRIns));  /* Copy RENAMEs. */\n      T->nins = J->curfinal->nins;\n      /* Fill mcofs of any unprocessed snapshots. */\n      as->curins = REF_FIRST;\n      asm_snap_prev(as);\n      break;  /* Done. */\n    }\n\n    /* Otherwise try again with a bigger IR. */\n    lj_trace_free(J2G(J), J->curfinal);\n    J->curfinal = NULL;  /* In case lj_trace_alloc() OOMs. */\n    J->curfinal = lj_trace_alloc(J->L, T);\n    as->realign = NULL;\n  }\n\n  RA_DBGX((as, \"===== START ====\"));\n  RA_DBG_FLUSH();\n  if (as->freeset != RSET_ALL)\n    lj_trace_err(as->J, LJ_TRERR_BADRA);  /* Ouch! Should never happen. */\n\n  /* Set trace entry point before fixing up tail to allow link to self. */\n  T->mcode = as->mcp;\n  T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0;\n  if (as->loopref)\n    asm_loop_tail_fixup(as);\n  else\n    asm_tail_fixup(as, T->link);  /* Note: this may change as->mctop! */\n  T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp);\n  asm_snap_fixup_mcofs(as);\n#if LJ_TARGET_MCODE_FIXUP\n  asm_mcode_fixup(T->mcode, T->szmcode);\n#endif\n  lj_mcode_sync(T->mcode, as->mctoporig);\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm.h",
    "content": "/*\n** IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ASM_H\n#define _LJ_ASM_H\n\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\nLJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T);\nLJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno,\n\t\t\t      MCode *target);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm_arm.h",
    "content": "/*\n** ARM IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a scratch register pair. */\nstatic Reg ra_scratchpair(ASMState *as, RegSet allow)\n{\n  RegSet pick1 = as->freeset & allow;\n  RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN;\n  Reg r;\n  if (pick2) {\n    r = rset_picktop(pick2);\n  } else {\n    RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN;\n    if (pick) {\n      r = rset_picktop(pick);\n      ra_restore(as, regcost_ref(as->cost[r+1]));\n    } else {\n      pick = pick1 & (allow << 1) & RSET_GPRODD;\n      if (pick) {\n\tr = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1]));\n      } else {\n\tr = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN);\n\tra_restore(as, regcost_ref(as->cost[r+1]));\n      }\n    }\n  }\n  lj_assertA(rset_test(RSET_GPREVEN, r), \"odd reg %d\", r);\n  ra_modified(as, r);\n  ra_modified(as, r+1);\n  RA_DBGX((as, \"scratchpair    $r $r\", r, r+1));\n  return r;\n}\n\n#if !LJ_SOFTFP\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_allocref(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_allocref(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_allocref(as, ir->op2, allow);\n    left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_allocref(as, ir->op1, allow);\n    right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n#endif\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Generate an exit stub group at the bottom of the reserved MCode memory. */\nstatic MCode *asm_exitstub_gen(ASMState *as, ExitNo group)\n{\n  MCode *mxp = as->mcbot;\n  int i;\n  if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop)\n    asm_mclimit(as);\n  /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */\n  *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP);\n  *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu);\n  mxp++;\n  *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch);  /* DISPATCH address */\n  *mxp++ = group*EXITSTUBS_PER_GROUP;\n  for (i = 0; i < EXITSTUBS_PER_GROUP; i++)\n    *mxp++ = ARMI_B|((-6-i)&0x00ffffffu);\n  lj_mcode_sync(as->mcbot, mxp);\n  lj_mcode_commitbot(as->J, mxp);\n  as->mcbot = mxp;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  return mxp - EXITSTUBS_PER_GROUP;\n}\n\n/* Setup all needed exit stubs. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)\n    lj_trace_err(as->J, LJ_TRERR_SNAPOV);\n  for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)\n    if (as->J->exitstubgroup[i] == NULL)\n      as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);\n}\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guardcc(ASMState *as, ARMCC cc)\n{\n  MCode *target = exitstub_addr(as->J, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = ARMI_BL | ((target-p-2) & 0x00ffffffu);\n    emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1);\n    return;\n  }\n  emit_branch(as, ARMF_CC(ARMI_BL, cc), target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow,\n\t\t\t  int lim)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (ofs > -lim && ofs < lim) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (ofs < lim) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tint32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);\n\t*ofsp = (ofs & 255);  /* Mask out less bits to allow LDRD. */\n\treturn ra_allock(as, (ofs & ~255), allow);\n      }\n    } else if (ir->o == IR_TMPREF) {\n      *ofsp = 0;\n      return RID_SP;\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse m operand into arithmetic/logic instructions. */\nstatic uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_hasreg(ir->r)) {\n    ra_noweak(as, ir->r);\n    return ARMF_M(ir->r);\n  } else if (irref_isk(ref)) {\n    uint32_t k = emit_isk12(ai, ir->i);\n    if (k)\n      return k;\n  } else if (mayfuse(as, ref)) {\n    if (ir->o >= IR_BSHL && ir->o <= IR_BROR) {\n      Reg m = ra_alloc1(as, ir->op1, allow);\n      ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL :\n\t\t    ir->o == IR_BSHR ? ARMSH_LSR :\n\t\t    ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR;\n      if (irref_isk(ir->op2)) {\n\treturn m | ARMF_SH(sh, (IR(ir->op2)->i & 31));\n      } else {\n\tReg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m));\n\treturn m | ARMF_RSH(sh, s);\n      }\n    } else if (ir->o == IR_ADD && ir->op1 == ir->op2) {\n      Reg m = ra_alloc1(as, ir->op1, allow);\n      return m | ARMF_SH(ARMSH_LSL, 1);\n    }\n  }\n  return ra_allocref(as, ref, allow);\n}\n\n/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */\nstatic IRRef asm_fuselsl2(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL &&\n      irref_isk(ir->op2) && IR(ir->op2)->i == 2)\n    return ir->op1;\n  return 0;  /* No fusion. */\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 :\n\t\t   (ai & 0x04000000) ? 4096 : 256;\n    if (ir->o == IR_ADD) {\n      int32_t ofs2;\n      if (irref_isk(ir->op2) &&\n\t  (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim &&\n\t  (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) {\n\tofs = ofs2;\n\tref = ir->op1;\n      } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) {\n\tIRRef lref = ir->op1, rref = ir->op2;\n\tReg rn, rm;\n\tif ((ai & 0x04000000)) {\n\t  IRRef sref = asm_fuselsl2(as, rref);\n\t  if (sref) {\n\t    rref = sref;\n\t    ai |= ARMF_SH(ARMSH_LSL, 2);\n\t  } else if ((sref = asm_fuselsl2(as, lref)) != 0) {\n\t    lref = rref;\n\t    rref = sref;\n\t    ai |= ARMF_SH(ARMSH_LSL, 2);\n\t  }\n\t}\n\trn = ra_alloc1(as, lref, allow);\n\trm = ra_alloc1(as, rref, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000)) ai |= ARMI_LS_R;\n\temit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);\n\treturn;\n      }\n    } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) {\n      lj_assertA(ofs == 0, \"bad usage\");\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs += IR(ir->op2)->i;\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs += IR(ir->op1)->i;\n\tref = ir->op2;\n      } else {\n\t/* NYI: Fuse ADD with constant. */\n\tReg rn = ra_alloc1(as, ir->op1, allow);\n\tuint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000))\n\t  emit_lso(as, ai, rd, rd, ofs);\n\telse\n\t  emit_lsox(as, ai, rd, rd, ofs);\n\temit_dn(as, ARMI_ADD^m, rd, rn);\n\treturn;\n      }\n      if (ofs <= -lim || ofs >= lim) {\n\tReg rn = ra_alloc1(as, ref, allow);\n\tReg rm = ra_allock(as, ofs, rset_exclude(allow, rn));\n\tif ((ai & 0x04000000)) ai |= ARMI_LS_R;\n\temit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);\n\treturn;\n      }\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n#if !LJ_SOFTFP\n  if ((ai & 0x08000000))\n    emit_vlso(as, ai, rd, base, ofs);\n  else\n#endif\n  if ((ai & 0x04000000))\n    emit_lso(as, ai, rd, base, ofs);\n  else\n    emit_lsox(as, ai, rd, base, ofs);\n}\n\n#if !LJ_SOFTFP\n/* Fuse to multiply-add/sub instruction. */\nstatic int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irm;\n  if (lref != rref &&\n      ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&\n\tra_noreg(irm->r)) ||\n       (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&\n\t(rref = lref, ai = air, ra_noreg(irm->r))))) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg add = ra_hintalloc(as, rref, dest, RSET_FPR);\n    Reg right, left = ra_alloc2(as, irm,\n\t\t\trset_exclude(rset_exclude(RSET_FPR, dest), add));\n    right = (left >> 8); left &= 255;\n    emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));\n    if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15));\n    return 1;\n  }\n  return 0;\n}\n#endif\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 0;\n#if LJ_SOFTFP\n  Reg gpr = REGARG_FIRSTGPR;\n#else\n  Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0;\n#endif\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func);\n#if !LJ_SOFTFP\n  for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)\n    as->cost[gpr] = REGCOST(~0u, ASMREF_L);\n  gpr = REGARG_FIRSTGPR;\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    IRIns *ir = IR(ref);\n#if !LJ_SOFTFP\n    if (ref && irt_isfp(ir->t)) {\n      RegSet of = as->freeset;\n      Reg src;\n      if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {\n\tif (irt_isnum(ir->t)) {\n\t  if (fpr <= REGARG_LASTFPR) {\n\t    ra_leftov(as, fpr, ref);\n\t    fpr++;\n\t    continue;\n\t  }\n\t} else if (fprodd) {  /* Ick. */\n\t  src = ra_alloc1(as, ref, RSET_FPR);\n\t  emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000);\n\t  fprodd = 0;\n\t  continue;\n\t} else if (fpr <= REGARG_LASTFPR) {\n\t  ra_leftov(as, fpr, ref);\n\t  fprodd = fpr++;\n\t  continue;\n\t}\n\t/* Workaround to protect argument GPRs from being used for remat. */\n\tas->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n\tsrc = ra_alloc1(as, ref, RSET_FPR);  /* May alloc GPR to remat FPR. */\n\tas->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n\tfprodd = 0;\n\tgoto stackfp;\n      }\n      /* Workaround to protect argument GPRs from being used for remat. */\n      as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n      src = ra_alloc1(as, ref, RSET_FPR);  /* May alloc GPR to remat FPR. */\n      as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n      if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u;\n      if (gpr <= REGARG_LASTGPR) {\n\tlj_assertA(rset_test(as->freeset, gpr),\n\t\t   \"reg %d not free\", gpr);  /* Must have been evicted. */\n\tif (irt_isnum(ir->t)) {\n\t  lj_assertA(rset_test(as->freeset, gpr+1),\n\t\t     \"reg %d not free\", gpr+1);  /* Ditto. */\n\t  emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15));\n\t  gpr += 2;\n\t} else {\n\t  emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15));\n\t  gpr++;\n\t}\n      } else {\n      stackfp:\n\tif (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\temit_spstore(as, ir, src, ofs);\n\tofs += irt_isnum(ir->t) ? 8 : 4;\n      }\n    } else\n#endif\n    {\n      if (gpr <= REGARG_LASTGPR) {\n\tlj_assertA(rset_test(as->freeset, gpr),\n\t\t   \"reg %d not free\", gpr);  /* Must have been evicted. */\n\tif (ref) ra_leftov(as, gpr, ref);\n\tgpr++;\n      } else {\n\tif (ref) {\n\t  Reg r = ra_alloc1(as, ref, RSET_GPR);\n\t  emit_spstore(as, ir, r, ofs);\n\t}\n\tofs += 4;\n      }\n    }\n  }\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lj_assertA(!irt_ispri(ir->t), \"PRI dest\");\n    if (!LJ_SOFTFP && irt_isfp(ir->t)) {\n      if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) {\n\tReg dest = (ra_dest(as, ir, RSET_FPR) & 15);\n\tif (irt_isnum(ir->t))\n\t  emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest);\n\telse\n\t  emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n  UNUSED(ci);\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)(irf->i);\n  } else {  /* Need a non-argument register for indirect calls. */\n    Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1));\n    emit_m(as, ARMI_BLXr, freg);\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  /* Need to force a spill on REF_BASE now to update the stack slot. */\n  emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE)));\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_nm(as, ARMI_CMP, RID_TMP,\n\t  ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_lso(as, ARMI_LDR, RID_TMP, base, -4);\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n  IRIns irgc;\n  int32_t addr = i32ptr((void *)&J2G(as->J)->cur_L);\n  irgc.ot = IRT(0, IRT_PGC);  /* GC type. */\n  emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L));\n  if ((as->flags & JIT_F_ARMV6T2)) {\n    emit_dnm(as, ARMI_BFI, RID_TMP, lj_fls(SBUF_MASK_FLAG), tmp);\n  } else {\n    emit_dnm(as, ARMI_ORR, RID_TMP, RID_TMP, tmp);\n    emit_dn(as, ARMI_AND|ARMI_K12|SBUF_MASK_FLAG, tmp, tmp);\n  }\n  emit_lso(as, ARMI_LDR, RID_TMP,\n\t   ra_allock(as, (addr & ~4095),\n\t\t     rset_exclude(rset_exclude(RSET_GPR, sb), tmp)),\n\t   (addr & 4095));\n  emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n}\n#endif\n\n/* -- Type conversions ---------------------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guardcc(as, CC_NE);\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15));\n  emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15));\n  emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n  emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15));\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n  emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15));\n}\n#endif\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if !LJ_SOFTFP\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n#endif\n  IRRef lref = ir->op1;\n  /* 64 bit integer conversions are handled by SPLIT. */\n  lj_assertA(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64),\n\t     \"IR %04d has unsplit 64 bit type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n#if LJ_SOFTFP\n  /* FP conversions are handled by SPLIT. */\n  lj_assertA(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT),\n\t     \"IR %04d has FP type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n  /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */\n#else\n  lj_assertA(irt_type(ir->t) != st, \"inconsistent types for CONV\");\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32,\n\t      (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15));\n    } else {  /* Integer to FP conversion. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      ARMIns ai = irt_isfloat(ir->t) ?\n\t(st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) :\n\t(st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32);\n      emit_dm(as, ai, (dest & 15), (dest & 15));\n      emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15));\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      ARMIns ai;\n      emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n      ai = irt_isint(ir->t) ?\n\t(st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) :\n\t(st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32);\n      emit_dm(as, ai, (tmp & 15), (left & 15));\n    }\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), \"bad type for CONV EXT\");\n      if ((as->flags & JIT_F_ARMV6)) {\n\tARMIns ai = st == IRT_I8 ? ARMI_SXTB :\n\t\t    st == IRT_U8 ? ARMI_UXTB :\n\t\t    st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH;\n\temit_dm(as, ai, dest, left);\n      } else if (st == IRT_U8) {\n\temit_dn(as, ARMI_AND|ARMI_K12|255, dest, left);\n      } else {\n\tuint32_t shift = st == IRT_I8 ? 24 : 16;\n\tARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR;\n\temit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP);\n\temit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left);\n      }\n    } else {  /* Handle 32/32 bit no-op (cast). */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  Reg rlo = 0, rhi = 0, tmp;\n  int destused = ra_used(ir);\n  int32_t ofs = 0;\n  ra_evictset(as, RSET_SCRATCH);\n#if LJ_SOFTFP\n  if (destused) {\n    if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&\n\t(ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) {\n      int i;\n      for (i = 0; i < 2; i++) {\n\tReg r = (ir+i)->r;\n\tif (ra_hasreg(r)) {\n\t  ra_free(as, r);\n\t  ra_modified(as, r);\n\t  emit_spload(as, ir+i, r, sps_scale((ir+i)->s));\n\t}\n      }\n      ofs = sps_scale(ir->s);\n      destused = 0;\n    } else {\n      rhi = ra_dest(as, ir+1, RSET_GPR);\n      rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));\n    }\n  }\n  asm_guardcc(as, CC_EQ);\n  if (destused) {\n    emit_lso(as, ARMI_LDR, rhi, RID_SP, 4);\n    emit_lso(as, ARMI_LDR, rlo, RID_SP, 0);\n  }\n#else\n  UNUSED(rhi);\n  if (destused) {\n    if (ra_hasspill(ir->s)) {\n      ofs = sps_scale(ir->s);\n      destused = 0;\n      if (ra_hasreg(ir->r)) {\n\tra_free(as, ir->r);\n\tra_modified(as, ir->r);\n\temit_spload(as, ir, ir->r, ofs);\n      }\n    } else {\n      rlo = ra_dest(as, ir, RSET_FPR);\n    }\n  }\n  asm_guardcc(as, CC_EQ);\n  if (destused)\n    emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0);\n#endif\n  emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  tmp = ra_releasetmp(as, ASMREF_TMP1);\n  if (ofs == 0)\n    emit_dm(as, ARMI_MOV, tmp, RID_SP);\n  else\n    emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode)\n{\n  if ((mode & IRTMPREF_IN1)) {\n    IRIns *ir = IR(ref);\n    if (irt_isnum(ir->t)) {\n      if ((mode & IRTMPREF_OUT1)) {\n#if LJ_SOFTFP\n\tlj_assertA(irref_isk(ref), \"unsplit FP op\");\n\temit_dm(as, ARMI_MOV, dest, RID_SP);\n\temit_lso(as, ARMI_STR,\n\t\t ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, RSET_GPR),\n\t\t RID_SP, 0);\n\temit_lso(as, ARMI_STR,\n\t\t ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, RSET_GPR),\n\t\t RID_SP, 4);\n#else\n\tReg src = ra_alloc1(as, ref, RSET_FPR);\n\temit_dm(as, ARMI_MOV, dest, RID_SP);\n\temit_vlso(as, ARMI_VSTR_D, src, RID_SP, 0);\n#endif\n      } else if (irref_isk(ref)) {\n\t/* Use the number constant itself as a TValue. */\n\tra_allockreg(as, i32ptr(ir_knum(ir)), dest);\n      } else {\n#if LJ_SOFTFP\n\tlj_assertA(0, \"unsplit FP op\");\n#else\n\t/* Otherwise force a spill and use the spill slot. */\n\temit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR);\n#endif\n      }\n    } else {\n      /* Otherwise use [sp] and [sp+4] to hold the TValue.\n      ** This assumes the following call has max. 4 args.\n      */\n      Reg type;\n      emit_dm(as, ARMI_MOV, dest, RID_SP);\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, RSET_GPR);\n\temit_lso(as, ARMI_STR, src, RID_SP, 0);\n      }\n      if (LJ_SOFTFP && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t))\n\ttype = ra_alloc1(as, ref+1, RSET_GPR);\n      else\n\ttype = ra_allock(as, irt_toitype(ir->t), RSET_GPR);\n      emit_lso(as, ARMI_STR, type, RID_SP, 4);\n    }\n  } else {\n    emit_dm(as, ARMI_MOV, dest, RID_SP);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i);\n    if (k) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_dn(as, ARMI_ADD^k, dest, base);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  IRType1 kt = irkey->t;\n  int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt));\n  uint32_t khash;\n  MCLabel l_end, l_loop;\n  rset_clear(allow, tab);\n  if (!irref_isk(refkey) || irt_isstr(kt)) {\n#if LJ_SOFTFP\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n    if (irkey[1].o == IR_HIOP) {\n      if (ra_hasreg((irkey+1)->r)) {\n\tkeynumhi = (irkey+1)->r;\n\tkeyhi = RID_TMP;\n\tra_noweak(as, keynumhi);\n      } else {\n\tkeyhi = keynumhi = ra_allocref(as, refkey+1, allow);\n      }\n      rset_clear(allow, keynumhi);\n      khi = 0;\n    }\n#else\n    if (irt_isnum(kt)) {\n      key = ra_scratch(as, allow);\n      rset_clear(allow, key);\n      keyhi = keynumhi = ra_scratch(as, allow);\n      rset_clear(allow, keyhi);\n      khi = 0;\n    } else {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n#endif\n  } else if (irt_isnum(kt)) {\n    int32_t val = (int32_t)ir_knum(irkey)->u32.lo;\n    k = emit_isk12(ARMI_CMP, val);\n    if (!k) {\n      key = ra_allock(as, val, allow);\n      rset_clear(allow, key);\n    }\n    val = (int32_t)ir_knum(irkey)->u32.hi;\n    khi = emit_isk12(ARMI_CMP, val);\n    if (!khi) {\n      keyhi = ra_allock(as, val, allow);\n      rset_clear(allow, keyhi);\n    }\n  } else if (!irt_ispri(kt)) {\n    k = emit_isk12(ARMI_CMP, irkey->i);\n    if (!k) {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n  }\n  if (!irt_ispri(kt))\n    tmp = ra_scratchpair(as, allow);\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_AL);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = --as->mcp;\n  emit_n(as, ARMI_CMP|ARMI_K12|0, dest);\n  emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next));\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_EQ);\n  else\n    emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  if (!irt_ispri(kt)) {\n    emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key);\n    emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi);\n    emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key));\n  } else {\n    emit_n(as, ARMI_CMP^khi, tmp);\n    emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it));\n  }\n  *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = irref_isk(refkey) ? ir_khash(as, irkey) : 1;\n  if (khash == 0) {\n    emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp);\n    emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp);\n    if (irt_isstr(kt)) {  /* Fetch of str->sid is cheaper than ra_allock. */\n      emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP);\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, sid));\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n    } else if (irref_isk(refkey)) {\n      emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash,\n\t       rset_exclude(rset_exclude(RSET_GPR, tab), dest));\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      if (ra_hasreg(keynumhi)) {  /* Canonicalize +-0.0 to 0.0. */\n\tif (keyhi == RID_TMP)\n\t  emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi);\n\temit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi);\n      }\n      emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP);\n      emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1);\n      emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));\n      emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)),\n\t       tmp, tmp+1, tmp);\n      emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));\n      emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp);\n      if (ra_hasreg(keynumhi)) {\n\temit_dnm(as, ARMI_EOR, tmp+1, tmp, key);\n\temit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key);  /* Test for +-0.0. */\n\temit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi);\n#if !LJ_SOFTFP\n\temit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi,\n\t\t (ra_alloc1(as, refkey, RSET_FPR) & 15));\n#endif\n      } else {\n\temit_dnm(as, ARMI_EOR, tmp+1, tmp, key);\n\temit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS,\n\t\t rset_exclude(rset_exclude(RSET_GPR, tab), key));\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key = RID_NONE, type = RID_TMP, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  lj_assertA(ofs % sizeof(Node) == 0, \"unaligned HREFK slot\");\n  if (ofs > 4095) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_opk(as, ARMI_ADD, dest, node, ofs, allow);\n  }\n  asm_guardcc(as, CC_NE);\n  if (!irt_ispri(irkey->t)) {\n    RegSet even = (as->freeset & allow);\n    even = even & (even >> 1) & RSET_GPREVEN;\n    if (even) {\n      key = ra_scratch(as, even);\n      if (rset_test(as->freeset, key+1)) {\n\ttype = key+1;\n\tra_modified(as, type);\n      }\n    } else {\n      key = ra_scratch(as, allow);\n    }\n    rset_clear(allow, key);\n  }\n  rset_clear(allow, type);\n  if (irt_isnum(irkey->t)) {\n    emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type,\n\t     (int32_t)ir_knum(irkey)->u32.hi, allow);\n    emit_opk(as, ARMI_CMP, 0, key,\n\t     (int32_t)ir_knum(irkey)->u32.lo, allow);\n  } else {\n    if (ra_hasreg(key))\n      emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow);\n    emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type);\n  }\n  emit_lso(as, ARMI_LDR, type, idx, kofs+4);\n  if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs);\n  if (ofs > 4095)\n    emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR);\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, ARMI_LDR, dest, v);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guardcc(as, CC_NE);\n      emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP);\n      emit_opk(as, ARMI_ADD, dest, uv,\n\t       (int32_t)offsetof(GCupval, tv), RSET_GPR);\n      emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_lso(as, ARMI_LDR, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lj_assertA(!ra_used(ir), \"unfused FREF\");\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    uint32_t k, m = ARMI_K12|sizeof(GCstr);\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       (k = emit_isk12(ARMI_ADD,\n\t\t\t       (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) {\n      m = k;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_dn(as, ARMI_ADD^m, dest, dest);\n    emit_dnm(as, ARMI_ADD, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  emit_opk(as, ARMI_ADD, dest, r,\n\t   sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r));\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic ARMIns asm_fxloadins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return ARMI_LDRSB;\n  case IRT_U8: return ARMI_LDRB;\n  case IRT_I16: return ARMI_LDRSH;\n  case IRT_U16: return ARMI_LDRH;\n  case IRT_NUM: lj_assertA(!LJ_SOFTFP, \"unsplit FP op\"); return ARMI_VLDR_D;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S;  /* fallthrough */\n  default: return ARMI_LDR;\n  }\n}\n\nstatic ARMIns asm_fxstoreins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return ARMI_STRB;\n  case IRT_I16: case IRT_U16: return ARMI_STRH;\n  case IRT_NUM: lj_assertA(!LJ_SOFTFP, \"unsplit FP op\"); return ARMI_VSTR_D;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S;  /* fallthrough */\n  default: return ARMI_STR;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  ARMIns ai = asm_fxloadins(as, ir);\n  Reg idx;\n  int32_t ofs;\n  if (ir->op1 == REF_NIL) {  /* FLOAD from GG_State with offset. */\n    idx = ra_allock(as, (int32_t)(ir->op2<<2) + (int32_t)J2GG(as->J), RSET_GPR);\n    ofs = 0;\n  } else {\n    idx = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->op2 == IRFL_TAB_ARRAY) {\n      ofs = asm_fuseabase(as, ir->op1);\n      if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n\temit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx);\n\treturn;\n      }\n    }\n    ofs = field_ofs[ir->op2];\n  }\n  if ((ai & 0x04000000))\n    emit_lso(as, ai, dest, idx, ofs);\n  else\n    emit_lsox(as, ai, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    ARMIns ai = asm_fxstoreins(as, ir);\n    if ((ai & 0x04000000))\n      emit_lso(as, ai, src, idx, ofs);\n    else\n      emit_lsox(as, ai, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir,\n\t\t     (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n  lj_assertA(!(ir->op2 & IRXLOAD_UNALIGNED), \"unaligned XLOAD\");\n  asm_fusexref(as, asm_fxloadins(as, ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2,\n\t\t\t(!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(as, ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_NONE, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = 0;\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n  if (ra_used(ir)) {\n    lj_assertA((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t),\n\t       \"bad load type %d\", irt_type(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow,\n\t\t       (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096);\n  if (ir->o == IR_VLOAD) ofs += 8 * ir->op2;\n  if (!hiop || type == RID_NONE) {\n    rset_clear(allow, idx);\n    if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&\n\trset_test((as->freeset & allow), dest+1)) {\n      type = dest+1;\n      ra_modified(as, type);\n    } else {\n      type = RID_TMP;\n    }\n  }\n  asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);\n  emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);\n  if (ra_hasreg(dest)) {\n#if !LJ_SOFTFP\n    if (t == IRT_NUM)\n      emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs);\n    else\n#endif\n      emit_lso(as, ARMI_LDR, dest, idx, ofs);\n  }\n  emit_lso(as, ARMI_LDR, type, idx, ofs+4);\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    RegSet allow = RSET_GPR;\n    Reg idx, src = RID_NONE, type = RID_NONE;\n    int32_t ofs = 0;\n#if !LJ_SOFTFP\n    if (irt_isnum(ir->t)) {\n      src = ra_alloc1(as, ir->op2, RSET_FPR);\n      idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024);\n      emit_vlso(as, ARMI_VSTR_D, src, idx, ofs);\n    } else\n#endif\n    {\n      int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n      if (!irt_ispri(ir->t)) {\n\tsrc = ra_alloc1(as, ir->op2, allow);\n\trset_clear(allow, src);\n      }\n      if (hiop)\n\ttype = ra_alloc1(as, (ir+1)->op2, allow);\n      else\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096);\n      if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs);\n      emit_lso(as, ARMI_STR, type, idx, ofs+4);\n    }\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  IRType t = hiop ? IRT_NUM : irt_type(ir->t);\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  lj_assertA(!(ir->op2 & IRSLOAD_PARENT),\n\t     \"bad parent SLOAD\");  /* Handled by asm_head_side(). */\n  lj_assertA(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK),\n\t     \"inconsistent SLOAD variant\");\n#if LJ_SOFTFP\n  lj_assertA(!(ir->op2 & IRSLOAD_CONVERT),\n\t     \"unsplit SLOAD convert\");  /* Handled by LJ_SOFTFP SPLIT. */\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n#else\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t = IRT_NUM;  /* Continue with a regular number type check. */\n  } else\n#endif\n  if (ra_used(ir)) {\n    Reg tmp = RID_NONE;\n    if ((ir->op2 & IRSLOAD_CONVERT))\n      tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR);\n    lj_assertA((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t),\n\t       \"bad SLOAD type %d\", irt_type(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    if ((ir->op2 & IRSLOAD_CONVERT)) {\n      if (t == IRT_INT) {\n\temit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));\n\temit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15));\n\tt = IRT_NUM;  /* Check for original type. */\n      } else {\n\temit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15));\n\temit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15));\n\tt = IRT_INT;  /* Check for original type. */\n      }\n      dest = tmp;\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\ndotypecheck:\n  rset_clear(allow, base);\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    if (ra_noreg(type)) {\n      if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&\n\t  rset_test((as->freeset & allow), dest+1)) {\n\ttype = dest+1;\n\tra_modified(as, type);\n      } else {\n\ttype = RID_TMP;\n      }\n    }\n    asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);\n    emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);\n  }\n  if (ra_hasreg(dest)) {\n#if !LJ_SOFTFP\n    if (t == IRT_NUM) {\n      if (ofs < 1024) {\n\temit_vlso(as, ARMI_VLDR_D, dest, base, ofs);\n      } else {\n\tif (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);\n\temit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0);\n\temit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow);\n\treturn;\n      }\n    } else\n#endif\n      emit_lso(as, ARMI_LDR, dest, base, ofs);\n  }\n  if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n  RegSet drop = RSET_SCRATCH;\n  lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),\n\t     \"bad CNEW/CNEWI operands\");\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    int32_t ofs = sizeof(GCcdata);\n    lj_assertA(sz == 4 || sz == 8, \"bad CNEWI size %d\", sz);\n    if (sz == 8) {\n      ofs += 4; ir++;\n      lj_assertA(ir->o == IR_HIOP, \"expected HIOP for CNEWI\");\n    }\n    for (;;) {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_lso(as, ARMI_STR, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir--;\n    }\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  {\n    uint32_t k = emit_isk12(ARMI_MOV, id);\n    Reg r = k ? RID_R1 : ra_allock(as, id, allow);\n    emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct));\n    emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid));\n    emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP);\n    if (k) emit_d(as, ARMI_MOV^k, RID_R1);\n  }\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg gr = ra_allock(as, i32ptr(J2G(as->J)),\n\t\t     rset_exclude(rset_exclude(RSET_GPR, tab), link));\n  Reg mark = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_lso(as, ARMI_STR, tab, gr,\n\t   (int32_t)offsetof(global_State, gc.grayagain));\n  emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark);\n  emit_lso(as, ARMI_LDR, link, gr,\n\t   (int32_t)offsetof(global_State, gc.grayagain));\n  emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark);\n  emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lj_assertA(IR(ir->op1)->o == IR_UREFC, \"bad OBAR type\");\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  if ((l_end[-1] >> 28) == CC_AL)\n    l_end[-1] = ARMF_CC(l_end[-1], CC_NE);\n  else\n    emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);\n  ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1));\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp);\n  emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_lso(as, ARMI_LDRB, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_dm(as, ai, (dest & 15), (left & 15));\n}\n\nstatic void asm_callround(ASMState *as, IRIns *ir, int id)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)|\n\t\tRID2RSET(RID_R3)|RID2RSET(RID_R12);\n  RegSet of;\n  Reg dest, src;\n  ra_evictset(as, drop);\n  dest = ra_dest(as, ir, RSET_FPR);\n  emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15));\n  emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf :\n\t\tid == IRFPM_CEIL ? (void *)lj_vm_ceil_sf :\n\t\t\t\t   (void *)lj_vm_trunc_sf);\n  /* Workaround to protect argument GPRs from being used for remat. */\n  of = as->freeset;\n  as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1);\n  as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L);\n  src = ra_alloc1(as, ir->op1, RSET_FPR);  /* May alloc GPR to remat FPR. */\n  as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1));\n  emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15));\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  if (ir->op2 <= IRFPM_TRUNC)\n    asm_callround(as, ir, ir->op2);\n  else if (ir->op2 == IRFPM_SQRT)\n    asm_fpunary(as, ir, ARMI_VSQRT_D);\n  else\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n#endif\n\nstatic int asm_swapops(ASMState *as, IRRef lref, IRRef rref)\n{\n  IRIns *ir;\n  if (irref_isk(rref))\n    return 0;  /* Don't swap constants to the left. */\n  if (irref_isk(lref))\n    return 1;  /* But swap constants to the right. */\n  ir = IR(rref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2))\n    return 0;  /* Don't swap fusable operands to the left. */\n  ir = IR(lref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2))\n    return 1;  /* But swap fusable operands to the right. */\n  return 0;  /* Otherwise don't swap. */\n}\n\nstatic void asm_intop(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left, dest = ra_dest(as, ir, RSET_GPR);\n  uint32_t m;\n  if (asm_swapops(as, lref, rref)) {\n    IRRef tmp = lref; lref = rref; rref = tmp;\n    if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC)\n      ai ^= (ARMI_SUB^ARMI_RSB);\n  }\n  left = ra_hintalloc(as, lref, dest, RSET_GPR);\n  m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));\n  if (irt_isguard(ir->t)) {  /* For IR_ADDOV etc. */\n    asm_guardcc(as, CC_VS);\n    ai |= ARMI_S;\n  }\n  emit_dn(as, ai^m, dest, left);\n}\n\n/* Try to drop cmp r, #0. */\nstatic ARMIns asm_drop_cmp0(ASMState *as, ARMIns ai)\n{\n  if (as->flagmcp == as->mcp) {\n    uint32_t cc = (as->mcp[1] >> 28);\n    as->flagmcp = NULL;\n    if (cc <= CC_NE) {\n      as->mcp++;\n      ai |= ARMI_S;\n    } else if (cc == CC_GE) {\n      *++as->mcp ^= ((CC_GE^CC_PL) << 28);\n      ai |= ARMI_S;\n    } else if (cc == CC_LT) {\n      *++as->mcp ^= ((CC_LT^CC_MI) << 28);\n      ai |= ARMI_S;\n    }  /* else: other conds don't work in general. */\n  }\n  return ai;\n}\n\nstatic void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  asm_intop(as, ir, asm_drop_cmp0(as, ai));\n}\n\nstatic void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  emit_dn(as, ai|ARMI_K12|0, dest, left);\n}\n\n/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */\nstatic void asm_intmul(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest));\n  Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  Reg tmp = RID_NONE;\n  /* ARMv5 restriction: dest != left and dest_hi != left. */\n  if (dest == left && left != right) { left = right; right = dest; }\n  if (irt_isguard(ir->t)) {  /* IR_MULOV */\n    if (!(as->flags & JIT_F_ARMV6) && dest == left)\n      tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left));\n    asm_guardcc(as, CC_NE);\n    emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest);\n    emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left);\n  } else {\n    if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP;\n    emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left);\n  }\n  /* Only need this for the dest == left == right case. */\n  if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right);\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D))\n      asm_fparith(as, ir, ARMI_VADD_D);\n    return;\n  }\n#endif\n  asm_intop_s(as, ir, ARMI_ADD);\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D))\n      asm_fparith(as, ir, ARMI_VSUB_D);\n    return;\n  }\n#endif\n  asm_intop_s(as, ir, ARMI_SUB);\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, ARMI_VMUL_D);\n    return;\n  }\n#endif\n  asm_intmul(as, ir);\n}\n\n#define asm_addov(as, ir)\tasm_add(as, ir)\n#define asm_subov(as, ir)\tasm_sub(as, ir)\n#define asm_mulov(as, ir)\tasm_mul(as, ir)\n\n#if !LJ_SOFTFP\n#define asm_fpdiv(as, ir)\tasm_fparith(as, ir, ARMI_VDIV_D)\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, ARMI_VABS_D)\n#endif\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, ARMI_VNEG_D);\n    return;\n  }\n#endif\n  asm_intneg(as, ir, ARMI_RSB);\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)\n{\n  ai = asm_drop_cmp0(as, ai);\n  if (ir->op2 == 0) {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);\n    emit_d(as, ai^m, dest);\n  } else {\n    /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */\n    asm_intop(as, ir, ai);\n  }\n}\n\n#define asm_bnot(as, ir)\tasm_bitop(as, ir, ARMI_MVN)\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if ((as->flags & JIT_F_ARMV6)) {\n    emit_dm(as, ARMI_REV, dest, left);\n  } else {\n    Reg tmp2 = dest;\n    if (tmp2 == left)\n      tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left));\n    emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP);\n    emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left);\n    emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP);\n    emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left);\n  }\n}\n\n#define asm_band(as, ir)\tasm_bitop(as, ir, ARMI_AND)\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, ARMI_ORR)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, ARMI_EOR)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh)\n{\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */\n    /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    int32_t shift = (IR(ir->op2)->i & 31);\n    emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left);\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, ARMSH_LSL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, ARMSH_LSR)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, ARMSH_ASR)\n#define asm_bror(as, ir)\tasm_bitshift(as, ir, ARMSH_ROR)\n#define asm_brol(as, ir)\tlj_assertA(0, \"unexpected BROL\")\n\nstatic void asm_intmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  uint32_t kcmp = 0, kmov = 0;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  Reg right = 0;\n  if (irref_isk(ir->op2)) {\n    kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i);\n    if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i);\n  }\n  if (!kmov) {\n    kcmp = 0;\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  }\n  if (kmov || dest != right) {\n    emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right);\n    cc ^= 1;  /* Must use opposite conditions for paired moves. */\n  } else {\n    cc ^= (CC_LT^CC_GT);  /* Otherwise may swap CC_LT <-> CC_GT. */\n  }\n  if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left);\n  emit_nm(as, ARMI_CMP^kcmp, left, right);\n}\n\n#if LJ_SOFTFP\nstatic void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  args[0] = ir->op1; args[1] = (ir+1)->op1;\n  args[2] = ir->op2; args[3] = (ir+1)->op2;\n  /* __aeabi_cdcmple preserves r0-r3. */\n  if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);\n  if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r);\n  if (!rset_test(as->freeset, RID_R2) &&\n      regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2);\n  if (!rset_test(as->freeset, RID_R3) &&\n      regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3);\n  ra_evictset(as, drop);\n  ra_destpair(as, ir);\n  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3);\n  emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2);\n  emit_call(as, (void *)ci->func);\n  for (r = RID_R0; r <= RID_R3; r++)\n    ra_leftov(as, r, args[r-RID_R0]);\n}\n#else\nstatic void asm_fpmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = ((left >> 8) & 15); left &= 15;\n  if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left);\n  if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right);\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ARMI_VCMP_D, left, right);\n}\n#endif\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc)\n{\n#if LJ_SOFTFP\n  UNUSED(fcc);\n#else\n  if (irt_isnum(ir->t))\n    asm_fpmin_max(as, ir, fcc);\n  else\n#endif\n    asm_intmin_max(as, ir, cc);\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, CC_GT, CC_PL)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, CC_LT, CC_LE)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n/* Map of comparisons to flags. ORDER IR. */\nstatic const uint8_t asm_compmap[IR_ABC+1] = {\n  /* op  FP swp  int cc   FP cc */\n  /* LT       */ CC_GE + (CC_HS << 4),\n  /* GE    x  */ CC_LT + (CC_HI << 4),\n  /* LE       */ CC_GT + (CC_HI << 4),\n  /* GT    x  */ CC_LE + (CC_HS << 4),\n  /* ULT   x  */ CC_HS + (CC_LS << 4),\n  /* UGE      */ CC_LO + (CC_LO << 4),\n  /* ULE   x  */ CC_HI + (CC_LO << 4),\n  /* UGT      */ CC_LS + (CC_LS << 4),\n  /* EQ       */ CC_NE + (CC_NE << 4),\n  /* NE       */ CC_EQ + (CC_EQ << 4),\n  /* ABC      */ CC_LS + (CC_LS << 4)  /* Same as UGT. */\n};\n\n#if LJ_SOFTFP\n/* FP comparisons. */\nstatic void asm_sfpcomp(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1);\n  args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1;\n  args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2;\n  /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */\n  for (r = RID_R0; r <= RID_R3; r++)\n    if (!rset_test(as->freeset, r) &&\n\tregcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r);\n  ra_evictset(as, drop);\n  asm_guardcc(as, (asm_compmap[ir->o] >> 4));\n  emit_call(as, (void *)ci->func);\n  for (r = RID_R0; r <= RID_R3; r++)\n    ra_leftov(as, r, args[r-RID_R0]);\n}\n#else\n/* FP comparisons. */\nstatic void asm_fpcomp(ASMState *as, IRIns *ir)\n{\n  Reg left, right;\n  ARMIns ai;\n  int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1);\n  if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) {\n    left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15);\n    right = 0;\n    ai = ARMI_VCMPZ_D;\n  } else {\n    left = ra_alloc2(as, ir, RSET_FPR);\n    if (swp) {\n      right = (left & 15); left = ((left >> 8) & 15);\n    } else {\n      right = ((left >> 8) & 15); left &= 15;\n    }\n    ai = ARMI_VCMP_D;\n  }\n  asm_guardcc(as, (asm_compmap[ir->o] >> 4));\n  emit_d(as, ARMI_VMRS, 0);\n  emit_dm(as, ai, left, right);\n}\n#endif\n\n/* Integer comparisons. */\nstatic void asm_intcomp(ASMState *as, IRIns *ir)\n{\n  ARMCC cc = (asm_compmap[ir->o] & 15);\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left;\n  uint32_t m;\n  int cmpprev0 = 0;\n  lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t),\n\t     \"bad comparison data type %d\", irt_type(ir->t));\n  if (asm_swapops(as, lref, rref)) {\n    Reg tmp = lref; lref = rref; rref = tmp;\n    if (cc >= CC_GE) cc ^= 7;  /* LT <-> GT, LE <-> GE */\n    else if (cc > CC_NE) cc ^= 11;  /* LO <-> HI, LS <-> HS */\n  }\n  if (irref_isk(rref) && IR(rref)->i == 0) {\n    IRIns *irl = IR(lref);\n    cmpprev0 = (irl+1 == ir);\n    /* Combine comp(BAND(left, right), 0) into tst left, right. */\n    if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) {\n      IRRef blref = irl->op1, brref = irl->op2;\n      uint32_t m2 = 0;\n      Reg bleft;\n      if (asm_swapops(as, blref, brref)) {\n\tReg tmp = blref; blref = brref; brref = tmp;\n      }\n      if (irref_isk(brref)) {\n\tm2 = emit_isk12(ARMI_AND, IR(brref)->i);\n\tif ((m2 & (ARMI_AND^ARMI_BIC)))\n\t  goto notst;  /* Not beneficial if we miss a constant operand. */\n      }\n      if (cc == CC_GE) cc = CC_PL;\n      else if (cc == CC_LT) cc = CC_MI;\n      else if (cc > CC_NE) goto notst;  /* Other conds don't work with tst. */\n      bleft = ra_alloc1(as, blref, RSET_GPR);\n      if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft));\n      asm_guardcc(as, cc);\n      emit_n(as, ARMI_TST^m2, bleft);\n      return;\n    }\n  }\nnotst:\n  left = ra_alloc1(as, lref, RSET_GPR);\n  m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left));\n  asm_guardcc(as, cc);\n  emit_n(as, ARMI_CMP^m, left);\n  /* Signed comparison with zero and referencing previous ins? */\n  if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE))\n    as->flagmcp = as->mcp;  /* Allow elimination of the compare. */\n}\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t))\n    asm_fpcomp(as, ir);\n  else\n#endif\n    asm_intcomp(as, ir);\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_int64comp(ASMState *as, IRIns *ir)\n{\n  int signedcomp = (ir->o <= IR_GT);\n  ARMCC cclo, cchi;\n  Reg leftlo, lefthi;\n  uint32_t mlo, mhi;\n  RegSet allow = RSET_GPR, oldfree;\n\n  /* Always use unsigned comparison for loword. */\n  cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15;\n  leftlo = ra_alloc1(as, ir->op1, allow);\n  oldfree = as->freeset;\n  mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo));\n  allow &= ~(oldfree & ~as->freeset);  /* Update for allocs of asm_fuseopm. */\n\n  /* Use signed or unsigned comparison for hiword. */\n  cchi = asm_compmap[ir->o] & 15;\n  lefthi = ra_alloc1(as, (ir+1)->op1, allow);\n  mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi));\n\n  /* All register allocations must be performed _before_ this point. */\n  if (signedcomp) {\n    MCLabel l_around = emit_label(as);\n    asm_guardcc(as, cclo);\n    emit_n(as, ARMI_CMP^mlo, leftlo);\n    emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around);\n    if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6;  /* GE -> GT, LE -> LT */\n    asm_guardcc(as, cchi);\n  } else {\n    asm_guardcc(as, cclo);\n    emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo);\n  }\n  emit_n(as, ARMI_CMP^mhi, lefthi);\n}\n#endif\n\n/* -- Split register ops -------------------------------------------------- */\n\n/* Hiword op of a split 32/32 bit op. Previous op is the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n#if LJ_HASFFI || LJ_SOFTFP\n  if ((ir-1)->o <= IR_NE) {  /* 64 bit integer or FP comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_int64comp(as, ir-1);\n#endif\n    return;\n#if LJ_SOFTFP\n  } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {\n    as->curins--;  /* Always skip the loword min/max. */\n    if (uselo || usehi)\n      asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_PL : CC_LE);\n    return;\n#elif LJ_HASFFI\n  } else if ((ir-1)->o == IR_CONV) {\n    as->curins--;  /* Always skip the CONV. */\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n#endif\n  } else if ((ir-1)->o == IR_XSTORE) {\n    if ((ir-1)->r != RID_SINK)\n      asm_xstore_(as, ir, 4);\n    return;\n  }\n#endif\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_HASFFI\n  case IR_ADD:\n    as->curins--;\n    asm_intop(as, ir, ARMI_ADC);\n    asm_intop(as, ir-1, ARMI_ADD|ARMI_S);\n    break;\n  case IR_SUB:\n    as->curins--;\n    asm_intop(as, ir, ARMI_SBC);\n    asm_intop(as, ir-1, ARMI_SUB|ARMI_S);\n    break;\n  case IR_NEG:\n    as->curins--;\n    asm_intneg(as, ir, ARMI_RSC);\n    asm_intneg(as, ir-1, ARMI_RSB|ARMI_S);\n    break;\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n#if LJ_SOFTFP\n  case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n  case IR_STRTO:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RSET_GPR);  /* Mark lo op as used. */\n    break;\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: case IR_TMPREF:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  default: lj_assertA(0, \"bad HIOP for op %d\", (ir-1)->o); break;\n  }\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_n(as, ARMI_TST|ARMI_K12|HOOK_PROFILE, RID_TMP);\n  emit_lsptr(as, ARMI_LDRB, RID_TMP, (void *)&J2G(as->J)->hookmask);\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  Reg pbase;\n  uint32_t k;\n  if (irp) {\n    if (!ra_hasspill(irp->s)) {\n      pbase = irp->r;\n      lj_assertA(ra_hasreg(pbase), \"base reg lost\");\n    } else if (allow) {\n      pbase = rset_pickbot(allow);\n    } else {\n      pbase = RID_RET;\n      emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0);  /* Restore temp. register. */\n    }\n  } else {\n    pbase = RID_BASE;\n  }\n  emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno));\n  k = emit_isk12(0, (int32_t)(8*topslot));\n  lj_assertA(k, \"slot offset %d does not fit in K12\", 8*topslot);\n  emit_n(as, ARMI_CMP^k, RID_TMP);\n  emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase);\n  emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP,\n\t   (int32_t)offsetof(lua_State, maxstack));\n  if (irp) {  /* Must not spill arbitrary registers in head of side trace. */\n    int32_t i = i32ptr(&J2G(as->J)->cur_L);\n    if (ra_hasspill(irp->s))\n      emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s));\n    emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095));\n    if (ra_hasspill(irp->s) && !allow)\n      emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0);  /* Save temp. register. */\n    emit_loadi(as, RID_TMP, (i & ~4095));\n  } else {\n    emit_getgl(as, RID_TMP, cur_L);\n  }\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n      RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);\n      Reg tmp;\n      /* LJ_SOFTFP: must be a number constant. */\n      lj_assertA(irref_isk(ref), \"unsplit FP op\");\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo,\n\t\t      rset_exclude(RSET_GPREVEN, RID_BASE));\n      emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs);\n      if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1);\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd);\n      emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4);\n#else\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs);\n#endif\n    } else {\n      RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);\n      Reg type;\n      lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t),\n\t\t \"restore of IR type %d\", irt_type(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE));\n\temit_lso(as, ARMI_STR, src, RID_BASE, ofs);\n\tif (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1);\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), odd);\n#if LJ_SOFTFP\n      } else if ((sn & SNAP_SOFTFPNUM)) {\n\ttype = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE));\n#endif\n      } else if ((sn & SNAP_KEYINDEX)) {\n\ttype = ra_allock(as, (int32_t)LJ_KEYINDEX, odd);\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), odd);\n      }\n      emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4);\n    }\n    checkmclim(as);\n  }\n  lj_assertA(map + nent == flinks, \"inconsistent frames in snapshot\");\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Marker to prevent patching the GC check exit. */\n#define ARM_NOPATCH_GC_CHECK\t(ARMI_BIC|ARMI_K12)\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp1, tmp2;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  *--as->mcp = ARM_NOPATCH_GC_CHECK;\n  emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  tmp1 = ra_releasetmp(as, ASMREF_TMP1);\n  tmp2 = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp2, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end);\n  emit_nm(as, ARMI_CMP, RID_TMP, tmp2);\n  emit_lso(as, ARMI_LDR, tmp2, tmp1,\n\t   (int32_t)offsetof(global_State, gc.threshold));\n  emit_lso(as, ARMI_LDR, RID_TMP, tmp1,\n\t   (int32_t)offsetof(global_State, gc.total));\n  ra_allockreg(as, i32ptr(J2G(as->J)), tmp1);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guardcc already inverted the bcc and patched the final bl. */\n    p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu);\n  } else {\n    p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu);\n  }\n}\n\n/* Fixup the tail of the loop. */\nstatic void asm_loop_tail_fixup(ASMState *as)\n{\n  UNUSED(as);  /* Nothing to do. */\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Reload L register from g->cur_L. */\nstatic void asm_head_lreg(ASMState *as)\n{\n  IRIns *ir = IR(ASMREF_L);\n  if (ra_used(ir)) {\n    Reg r = ra_dest(as, ir, RSET_GPR);\n    emit_getgl(as, r, cur_L);\n    ra_evictk(as);\n  }\n}\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  ra_destreg(as, ir, RID_BASE);\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  if (ra_hasspill(irp->s)) {\n    rset_clear(allow, ra_dest(as, ir, allow));\n  } else {\n    Reg r = irp->r;\n    lj_assertA(ra_hasreg(r), \"base reg lost\");\n    rset_clear(allow, r);\n    if (r != ir->r && !rset_test(as->freeset, r))\n      ra_restore(as, regcost_ref(as->cost[r]));\n    ra_destreg(as, ir, r);\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *p = as->mctop;\n  MCode *target;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    as->mctop = --p;\n  } else {\n    /* Patch stack adjustment. */\n    uint32_t k = emit_isk12(ARMI_ADD, spadj);\n    lj_assertA(k, \"stack adjustment %d does not fit in K12\", spadj);\n    p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP);\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop - 1;  /* Leave room for exit branch. */\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    as->mcp = p-1;  /* Leave room for stack pointer adjustment. */\n    as->invmcp = NULL;\n  }\n  *p = 0;  /* Prevent load/store merging. */\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++) {\n    if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) {\n      if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {\n\tif (irt_isnum(IR(args[i])->t)) {\n\t  if (nfpr > 0) nfpr--;\n\t  else fprodd = 0, nslots = (nslots + 3) & ~1;\n\t} else {\n\t  if (fprodd) fprodd--;\n\t  else if (nfpr > 0) fprodd = 1, nfpr--;\n\t  else nslots++;\n\t}\n      } else if (irt_isnum(IR(args[i])->t)) {\n\tngpr &= ~1;\n\tif (ngpr > 0) ngpr -= 2; else nslots += 2;\n      } else {\n\tif (ngpr > 0) ngpr--; else nslots++;\n      }\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n  }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  /* May need extra exit for asm_stack_check on side traces. */\n  asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *cstart = NULL, *cend = p;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MCode *px = exitstub_addr(J, exitno) - 2;\n  for (; p < pe; p++) {\n    /* Look for bl_cc exitstub, replace with b_cc target. */\n    uint32_t ins = *p;\n    if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u &&\n\t((ins ^ (px-p)) & 0x00ffffffu) == 0 &&\n\tp[-1] != ARM_NOPATCH_GC_CHECK) {\n      *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu);\n      cend = p+1;\n      if (!cstart) cstart = p;\n    }\n  }\n  lj_assertJ(cstart != NULL, \"exit stub %d not found\", exitno);\n  lj_mcode_sync(cstart, cend);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm_arm64.h",
    "content": "/*\n** ARM64 IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.\n** Sponsored by Cisco Systems, Inc.\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_allocref(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_allocref(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_allocref(as, ir->op2, allow);\n    left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_allocref(as, ir->op1, allow);\n    right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Setup all needed exit stubs. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  MCode *mxp = as->mctop;\n  if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim)\n    asm_mclimit(as);\n  /* 1: str lr,[sp]; bl ->vm_exit_handler; movz w0,traceno; bl <1; bl <1; ... */\n  for (i = nexits-1; (int32_t)i >= 0; i--)\n    *--mxp = A64I_LE(A64I_BL | A64F_S26(-3-i));\n  *--mxp = A64I_LE(A64I_MOVZw | A64F_U16(as->T->traceno));\n  mxp--;\n  *mxp = A64I_LE(A64I_BL | A64F_S26(((MCode *)(void *)lj_vm_exit_handler-mxp)));\n  *--mxp = A64I_LE(A64I_STRx | A64F_D(RID_LR) | A64F_N(RID_SP));\n  as->mctop = mxp;\n}\n\nstatic MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno)\n{\n  /* Keep this in-sync with exitstub_trace_addr(). */\n  return as->mctop + exitno + 3;\n}\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guardcc(ASMState *as, A64CC cc)\n{\n  MCode *target = asm_exitstub_addr(as, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = A64I_B | A64F_S26(target-p);\n    emit_cond_branch(as, cc^1, p-1);\n    return;\n  }\n  emit_cond_branch(as, cc, target);\n}\n\n/* Emit test and branch instruction to exit for guard. */\nstatic void asm_guardtnb(ASMState *as, A64Ins ai, Reg r, uint32_t bit)\n{\n  MCode *target = asm_exitstub_addr(as, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = A64I_B | A64F_S26(target-p);\n    emit_tnb(as, ai^0x01000000u, r, bit, p-1);\n    return;\n  }\n  emit_tnb(as, ai, r, bit, target);\n}\n\n/* Emit compare and branch instruction to exit for guard. */\nstatic void asm_guardcnb(ASMState *as, A64Ins ai, Reg r)\n{\n  MCode *target = asm_exitstub_addr(as, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = A64I_B | A64F_S26(target-p);\n    emit_cnb(as, ai^0x01000000u, r, p-1);\n    return;\n  }\n  emit_cnb(as, ai, r, target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\nstatic int asm_isk32(ASMState *as, IRRef ref, int32_t *k)\n{\n  if (irref_isk(ref)) {\n    IRIns *ir = IR(ref);\n    if (ir->o == IR_KNULL || !irt_is64(ir->t)) {\n      *k = ir->i;\n      return 1;\n    } else if (checki32((int64_t)ir_k64(ir)->u64)) {\n      *k = (int32_t)ir_k64(ir)->u64;\n      return 1;\n    }\n  }\n  return 0;\n}\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n#define FUSE_REG\t0x40000000\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow,\n\t\t\t  A64Ins ins)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (emit_checkofs(ins, ofs)) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t} else {\n\t  Reg base = ra_alloc1(as, ir->op1, allow);\n\t  *ofsp = FUSE_REG|ra_alloc1(as, ir->op2, rset_exclude(allow, base));\n\t  return base;\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (emit_checkofs(ins, ofs)) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tGCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv;\n\tint64_t ofs = glofs(as, &uv->tv);\n\tif (emit_checkofs(ins, ofs)) {\n\t  *ofsp = (int32_t)ofs;\n\t  return RID_GL;\n\t}\n      }\n    } else if (ir->o == IR_TMPREF) {\n      *ofsp = (int32_t)glofs(as, &J2G(as->J)->tmptv);\n      return RID_GL;\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse m operand into arithmetic/logic instructions. */\nstatic uint32_t asm_fuseopm(ASMState *as, A64Ins ai, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_hasreg(ir->r)) {\n    ra_noweak(as, ir->r);\n    return A64F_M(ir->r);\n  } else if (irref_isk(ref)) {\n    uint32_t m;\n    int64_t k = get_k64val(as, ref);\n    if ((ai & 0x1f000000) == 0x0a000000)\n      m = emit_isk13(k, irt_is64(ir->t));\n    else\n      m = emit_isk12(k);\n    if (m)\n      return m;\n  } else if (mayfuse(as, ref)) {\n    if ((ir->o >= IR_BSHL && ir->o <= IR_BSAR && irref_isk(ir->op2)) ||\n\t(ir->o == IR_ADD && ir->op1 == ir->op2)) {\n      A64Shift sh = ir->o == IR_BSHR ? A64SH_LSR :\n\t\t    ir->o == IR_BSAR ? A64SH_ASR : A64SH_LSL;\n      int shift = ir->o == IR_ADD ? 1 :\n\t\t    (IR(ir->op2)->i & (irt_is64(ir->t) ? 63 : 31));\n      IRIns *irl = IR(ir->op1);\n      if (sh == A64SH_LSL &&\n\t  irl->o == IR_CONV &&\n\t  irl->op2 == ((IRT_I64<<IRCONV_DSH)|IRT_INT|IRCONV_SEXT) &&\n\t  shift <= 4 &&\n\t  canfuse(as, irl)) {\n\tReg m = ra_alloc1(as, irl->op1, allow);\n\treturn A64F_M(m) | A64F_EXSH(A64EX_SXTW, shift);\n      } else {\n\tReg m = ra_alloc1(as, ir->op1, allow);\n\treturn A64F_M(m) | A64F_SH(sh, shift);\n      }\n    } else if (ir->o == IR_CONV &&\n\t       ir->op2 == ((IRT_I64<<IRCONV_DSH)|IRT_INT|IRCONV_SEXT)) {\n      Reg m = ra_alloc1(as, ir->op1, allow);\n      return A64F_M(m) | A64F_EX(A64EX_SXTW);\n    }\n  }\n  return A64F_M(ra_allocref(as, ref, allow));\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, A64Ins ai, Reg rd, IRRef ref,\n\t\t\t RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  int32_t ofs = 0;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    if (ir->o == IR_ADD) {\n      if (asm_isk32(as, ir->op2, &ofs) && emit_checkofs(ai, ofs)) {\n\tref = ir->op1;\n      } else {\n\tReg rn, rm;\n\tIRRef lref = ir->op1, rref = ir->op2;\n\tIRIns *irl = IR(lref);\n\tif (mayfuse(as, irl->op1)) {\n\t  unsigned int shift = 4;\n\t  if (irl->o == IR_BSHL && irref_isk(irl->op2)) {\n\t    shift = (IR(irl->op2)->i & 63);\n\t  } else if (irl->o == IR_ADD && irl->op1 == irl->op2) {\n\t    shift = 1;\n\t  }\n\t  if ((ai >> 30) == shift) {\n\t    lref = irl->op1;\n\t    irl = IR(lref);\n\t    ai |= A64I_LS_SH;\n\t  }\n\t}\n\tif (irl->o == IR_CONV &&\n\t    irl->op2 == ((IRT_I64<<IRCONV_DSH)|IRT_INT|IRCONV_SEXT) &&\n\t    canfuse(as, irl)) {\n\t  lref = irl->op1;\n\t  ai |= A64I_LS_SXTWx;\n\t} else {\n\t  ai |= A64I_LS_LSLx;\n\t}\n\trm = ra_alloc1(as, lref, allow);\n\trn = ra_alloc1(as, rref, rset_exclude(allow, rm));\n\temit_dnm(as, (ai^A64I_LS_R), (rd & 31), rn, rm);\n\treturn;\n      }\n    } else if (ir->o == IR_STRREF) {\n      if (asm_isk32(as, ir->op2, &ofs)) {\n\tref = ir->op1;\n      } else if (asm_isk32(as, ir->op1, &ofs)) {\n\tref = ir->op2;\n      } else {\n\tReg refk = irref_isk(ir->op1) ? ir->op1 : ir->op2;\n\tReg refv = irref_isk(ir->op1) ? ir->op2 : ir->op1;\n\tReg rn = ra_alloc1(as, refv, allow);\n\tIRIns *irr = IR(refk);\n\tuint32_t m;\n\tif (irr+1 == ir && !ra_used(irr) &&\n\t    irr->o == IR_ADD && irref_isk(irr->op2)) {\n\t  ofs = sizeof(GCstr) + IR(irr->op2)->i;\n\t  if (emit_checkofs(ai, ofs)) {\n\t    Reg rm = ra_alloc1(as, irr->op1, rset_exclude(allow, rn));\n\t    m = A64F_M(rm) | A64F_EX(A64EX_SXTW);\n\t    goto skipopm;\n\t  }\n\t}\n\tm = asm_fuseopm(as, 0, refk, rset_exclude(allow, rn));\n\tofs = sizeof(GCstr);\n      skipopm:\n\temit_lso(as, ai, rd, rd, ofs);\n\temit_dn(as, A64I_ADDx^m, rd, rn);\n\treturn;\n      }\n      ofs += sizeof(GCstr);\n      if (!emit_checkofs(ai, ofs)) {\n\tReg rn = ra_alloc1(as, ref, allow);\n\tReg rm = ra_allock(as, ofs, rset_exclude(allow, rn));\n\temit_dnm(as, (ai^A64I_LS_R)|A64I_LS_UXTWx, rd, rn, rm);\n\treturn;\n      }\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n  emit_lso(as, ai, (rd & 31), base, ofs);\n}\n\n/* Fuse FP multiply-add/sub. */\nstatic int asm_fusemadd(ASMState *as, IRIns *ir, A64Ins ai, A64Ins air)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irm;\n  if (lref != rref &&\n      ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&\n       ra_noreg(irm->r)) ||\n       (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&\n       (rref = lref, ai = air, ra_noreg(irm->r))))) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg add = ra_hintalloc(as, rref, dest, RSET_FPR);\n    Reg left = ra_alloc2(as, irm,\n\t\t\t rset_exclude(rset_exclude(RSET_FPR, dest), add));\n    Reg right = (left >> 8); left &= 255;\n    emit_dnma(as, ai, (dest & 31), (left & 31), (right & 31), (add & 31));\n    return 1;\n  }\n  return 0;\n}\n\n/* Fuse BAND + BSHL/BSHR into UBFM. */\nstatic int asm_fuseandshift(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1);\n  lj_assertA(ir->o == IR_BAND, \"bad usage\");\n  if (canfuse(as, irl) && irref_isk(ir->op2)) {\n    uint64_t mask = get_k64val(as, ir->op2);\n    if (irref_isk(irl->op2) && (irl->o == IR_BSHR || irl->o == IR_BSHL)) {\n      int32_t shmask = irt_is64(irl->t) ? 63 : 31;\n      int32_t shift = (IR(irl->op2)->i & shmask);\n      int32_t imms = shift;\n      if (irl->o == IR_BSHL) {\n\tmask >>= shift;\n\tshift = (shmask-shift+1) & shmask;\n\timms = 0;\n      }\n      if (mask && !((mask+1) & mask)) {  /* Contiguous 1-bits at the bottom. */\n\tReg dest = ra_dest(as, ir, RSET_GPR);\n\tReg left = ra_alloc1(as, irl->op1, RSET_GPR);\n\tA64Ins ai = shmask == 63 ? A64I_UBFMx : A64I_UBFMw;\n\timms += 63 - emit_clz64(mask);\n\tif (imms > shmask) imms = shmask;\n\temit_dn(as, ai | A64F_IMMS(imms) | A64F_IMMR(shift), dest, left);\n\treturn 1;\n      }\n    }\n  }\n  return 0;\n}\n\n/* Fuse BOR(BSHL, BSHR) into EXTR/ROR. */\nstatic int asm_fuseorshift(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  lj_assertA(ir->o == IR_BOR, \"bad usage\");\n  if (canfuse(as, irl) && canfuse(as, irr) &&\n      ((irl->o == IR_BSHR && irr->o == IR_BSHL) ||\n       (irl->o == IR_BSHL && irr->o == IR_BSHR))) {\n    if (irref_isk(irl->op2) && irref_isk(irr->op2)) {\n      IRRef lref = irl->op1, rref = irr->op1;\n      uint32_t lshift = IR(irl->op2)->i, rshift = IR(irr->op2)->i;\n      if (irl->o == IR_BSHR) {  /* BSHR needs to be the right operand. */\n\tuint32_t tmp2;\n\tIRRef tmp1 = lref; lref = rref; rref = tmp1;\n\ttmp2 = lshift; lshift = rshift; rshift = tmp2;\n      }\n      if (rshift + lshift == (irt_is64(ir->t) ? 64 : 32)) {\n\tA64Ins ai = irt_is64(ir->t) ? A64I_EXTRx : A64I_EXTRw;\n\tReg dest = ra_dest(as, ir, RSET_GPR);\n\tReg left = ra_alloc1(as, lref, RSET_GPR);\n\tReg right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left));\n\temit_dnm(as, ai | A64F_IMMS(rshift), dest, left, right);\n\treturn 1;\n      }\n    }\n  }\n  return 0;\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 0;\n  Reg gpr, fpr = REGARG_FIRSTFPR;\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func);\n  for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)\n    as->cost[gpr] = REGCOST(~0u, ASMREF_L);\n  gpr = REGARG_FIRSTGPR;\n  for (n = 0; n < nargs; n++) { /* Setup args. */\n    IRRef ref = args[n];\n    IRIns *ir = IR(ref);\n    if (ref) {\n      if (irt_isfp(ir->t)) {\n\tif (fpr <= REGARG_LASTFPR) {\n\t  lj_assertA(rset_test(as->freeset, fpr),\n\t\t     \"reg %d not free\", fpr);  /* Must have been evicted. */\n\t  ra_leftov(as, fpr, ref);\n\t  fpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_FPR);\n\t  emit_spstore(as, ir, r, ofs + ((LJ_BE && !irt_isnum(ir->t)) ? 4 : 0));\n\t  ofs += 8;\n\t}\n      } else {\n\tif (gpr <= REGARG_LASTGPR) {\n\t  lj_assertA(rset_test(as->freeset, gpr),\n\t\t     \"reg %d not free\", gpr);  /* Must have been evicted. */\n\t  ra_leftov(as, gpr, ref);\n\t  gpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_GPR);\n\t  emit_spstore(as, ir, r, ofs + ((LJ_BE && !irt_is64(ir->t)) ? 4 : 0));\n\t  ofs += 8;\n\t}\n      }\n    }\n  }\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r); /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop); /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lj_assertA(!irt_ispri(ir->t), \"PRI dest\");\n    if (irt_isfp(ir->t)) {\n      if (ci->flags & CCI_CASTU64) {\n\tReg dest = ra_dest(as, ir, RSET_FPR) & 31;\n\temit_dn(as, irt_isnum(ir->t) ? A64I_FMOV_D_R : A64I_FMOV_S_R,\n\t\tdest, RID_RET);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n  UNUSED(ci);\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(ir_k64(irf)->u64);\n  } else {  /* Need a non-argument register for indirect calls. */\n    Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_X8, RID_MAX_GPR)-RSET_FIXED);\n    emit_n(as, A64I_BLR, freg);\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  /* Need to force a spill on REF_BASE now to update the stack slot. */\n  emit_lso(as, A64I_STRx, base, RID_SP, ra_spill(as, IR(REF_BASE)));\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_nm(as, A64I_CMPx, RID_TMP,\n\t  ra_allock(as, i64ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_lso(as, A64I_LDRx, RID_TMP, base, -8);\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n  IRIns irgc;\n  irgc.ot = IRT(0, IRT_PGC);  /* GC type. */\n  emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L));\n  emit_dn(as, A64I_BFMx | A64F_IMMS(lj_fls(SBUF_MASK_FLAG)) | A64F_IMMR(0), RID_TMP, tmp);\n  emit_getgl(as, RID_TMP, cur_L);\n  emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n}\n#endif\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guardcc(as, CC_NE);\n  emit_nm(as, A64I_FCMPd, (tmp & 31), (left & 31));\n  emit_dn(as, A64I_FCVT_F64_S32, (tmp & 31), dest);\n  emit_dn(as, A64I_FCVT_S32_F64, dest, (left & 31));\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_dn(as, A64I_FMOV_R_S, dest, (tmp & 31));\n  emit_dnm(as, A64I_FADDd, (tmp & 31), (left & 31), (right & 31));\n}\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n  int st64 = (st == IRT_I64 || st == IRT_U64 || st == IRT_P64);\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n  IRRef lref = ir->op1;\n  lj_assertA(irt_type(ir->t) != st, \"inconsistent types for CONV\");\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      emit_dn(as, st == IRT_NUM ? A64I_FCVT_F32_F64 : A64I_FCVT_F64_F32,\n\t      (dest & 31), (ra_alloc1(as, lref, RSET_FPR) & 31));\n    } else {  /* Integer to FP conversion. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      A64Ins ai = irt_isfloat(ir->t) ?\n\t(((IRT_IS64 >> st) & 1) ?\n\t (st == IRT_I64 ? A64I_FCVT_F32_S64 : A64I_FCVT_F32_U64) :\n\t (st == IRT_INT ? A64I_FCVT_F32_S32 : A64I_FCVT_F32_U32)) :\n\t(((IRT_IS64 >> st) & 1) ?\n\t (st == IRT_I64 ? A64I_FCVT_F64_S64 : A64I_FCVT_F64_U64) :\n\t (st == IRT_INT ? A64I_FCVT_F64_S32 : A64I_FCVT_F64_U32));\n      emit_dn(as, ai, (dest & 31), left);\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      A64Ins ai = irt_is64(ir->t) ?\n\t(st == IRT_NUM ?\n\t (irt_isi64(ir->t) ? A64I_FCVT_S64_F64 : A64I_FCVT_U64_F64) :\n\t (irt_isi64(ir->t) ? A64I_FCVT_S64_F32 : A64I_FCVT_U64_F32)) :\n\t(st == IRT_NUM ?\n\t (irt_isint(ir->t) ? A64I_FCVT_S32_F64 : A64I_FCVT_U32_F64) :\n\t (irt_isint(ir->t) ? A64I_FCVT_S32_F32 : A64I_FCVT_U32_F32));\n      emit_dn(as, ai, dest, (left & 31));\n    }\n  } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, lref, RSET_GPR);\n    A64Ins ai = st == IRT_I8 ? A64I_SXTBw :\n\t\tst == IRT_U8 ? A64I_UXTBw :\n\t\tst == IRT_I16 ? A64I_SXTHw : A64I_UXTHw;\n    lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), \"bad type for CONV EXT\");\n    emit_dn(as, ai, dest, left);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (irt_is64(ir->t)) {\n      if (st64 || !(ir->op2 & IRCONV_SEXT)) {\n\t/* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */\n\tra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      } else {  /* 32 to 64 bit sign extension. */\n\tReg left = ra_alloc1(as, lref, RSET_GPR);\n\temit_dn(as, A64I_SXTW, dest, left);\n      }\n    } else {\n      if (st64 && !(ir->op2 & IRCONV_NONE)) {\n\t/* This is either a 32 bit reg/reg mov which zeroes the hiword\n\t** or a load of the loword from a 64 bit address.\n\t*/\n\tReg left = ra_alloc1(as, lref, RSET_GPR);\n\temit_dm(as, A64I_MOVw, dest, left);\n      } else {  /* 32/32 bit no-op (cast). */\n\tra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      }\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  Reg dest = 0, tmp;\n  int destused = ra_used(ir);\n  int32_t ofs = 0;\n  ra_evictset(as, RSET_SCRATCH);\n  if (destused) {\n    if (ra_hasspill(ir->s)) {\n      ofs = sps_scale(ir->s);\n      destused = 0;\n      if (ra_hasreg(ir->r)) {\n\tra_free(as, ir->r);\n\tra_modified(as, ir->r);\n\temit_spload(as, ir, ir->r, ofs);\n      }\n    } else {\n      dest = ra_dest(as, ir, RSET_FPR);\n    }\n  }\n  if (destused)\n    emit_lso(as, A64I_LDRd, (dest & 31), RID_SP, 0);\n  asm_guardcnb(as, A64I_CBZ, RID_RET);\n  args[0] = ir->op1; /* GCstr *str */\n  args[1] = ASMREF_TMP1; /* TValue *n  */\n  asm_gencall(as, ci, args);\n  tmp = ra_releasetmp(as, ASMREF_TMP1);\n  emit_opk(as, A64I_ADDx, tmp, RID_SP, ofs, RSET_GPR);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Store tagged value for ref at base+ofs. */\nstatic void asm_tvstore64(ASMState *as, Reg base, int32_t ofs, IRRef ref)\n{\n  RegSet allow = rset_exclude(RSET_GPR, base);\n  IRIns *ir = IR(ref);\n  lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t),\n\t     \"store of IR type %d\", irt_type(ir->t));\n  if (irref_isk(ref)) {\n    TValue k;\n    lj_ir_kvalue(as->J->L, &k, ir);\n    emit_lso(as, A64I_STRx, ra_allock(as, k.u64, allow), base, ofs);\n  } else {\n    Reg src = ra_alloc1(as, ref, allow);\n    rset_clear(allow, src);\n    if (irt_isinteger(ir->t)) {\n      Reg type = ra_allock(as, (int64_t)irt_toitype(ir->t) << 47, allow);\n      emit_lso(as, A64I_STRx, RID_TMP, base, ofs);\n      emit_dnm(as, A64I_ADDx | A64F_EX(A64EX_UXTW), RID_TMP, type, src);\n    } else {\n      Reg type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      emit_lso(as, A64I_STRx, RID_TMP, base, ofs);\n      emit_dnm(as, A64I_ADDx | A64F_SH(A64SH_LSL, 47), RID_TMP, src, type);\n    }\n  }\n}\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode)\n{\n  if ((mode & IRTMPREF_IN1)) {\n    IRIns *ir = IR(ref);\n    if (irt_isnum(ir->t)) {\n      if (irref_isk(ref) && !(mode & IRTMPREF_OUT1)) {\n\t/* Use the number constant itself as a TValue. */\n\tra_allockreg(as, i64ptr(ir_knum(ir)), dest);\n\treturn;\n      }\n      emit_lso(as, A64I_STRd, (ra_alloc1(as, ref, RSET_FPR) & 31), dest, 0);\n    } else {\n      asm_tvstore64(as, dest, 0, ref);\n    }\n  }\n  /* g->tmptv holds the TValue(s). */\n  emit_dn(as, A64I_ADDx^emit_isk12(glofs(as, &J2G(as->J)->tmptv)), dest, RID_GL);\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    uint32_t k = emit_isk12(ofs + 8*IR(ir->op2)->i);\n    if (k) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_dn(as, A64I_ADDx^k, dest, base);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_dnm(as, A64I_ADDx | A64F_EXSH(A64EX_UXTW, 3), dest, base, idx);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = 0, tmp = RID_TMP;\n  Reg ftmp = RID_NONE, type = RID_NONE, scr = RID_NONE, tisnum = RID_NONE;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  int isk = irref_isk(ir->op2);\n  IRType1 kt = irkey->t;\n  uint32_t k = 0;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n  rset_clear(allow, tab);\n\n  if (!isk) {\n    key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow);\n    rset_clear(allow, key);\n    if (!irt_isstr(kt)) {\n      tmp = ra_scratch(as, allow);\n      rset_clear(allow, tmp);\n    }\n  } else if (irt_isnum(kt)) {\n    int64_t val = (int64_t)ir_knum(irkey)->u64;\n    if (!(k = emit_isk12(val))) {\n      key = ra_allock(as, val, allow);\n      rset_clear(allow, key);\n    }\n  } else if (!irt_ispri(kt)) {\n    if (!(k = emit_isk12(irkey->i))) {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n  }\n\n  /* Allocate constants early. */\n  if (irt_isnum(kt)) {\n    if (!isk) {\n      tisnum = ra_allock(as, LJ_TISNUM << 15, allow);\n      ftmp = ra_scratch(as, rset_exclude(RSET_FPR, key));\n      rset_clear(allow, tisnum);\n    }\n  } else if (irt_isaddr(kt)) {\n    if (isk) {\n      int64_t kk = ((int64_t)irt_toitype(kt) << 47) | irkey[1].tv.u64;\n      scr = ra_allock(as, kk, allow);\n    } else {\n      scr = ra_scratch(as, allow);\n    }\n    rset_clear(allow, scr);\n  } else {\n    lj_assertA(irt_ispri(kt) && !irt_isnil(kt), \"bad HREF key type\");\n    type = ra_allock(as, ~((int64_t)~irt_toitype(kt) << 47), allow);\n    scr = ra_scratch(as, rset_clear(allow, type));\n    rset_clear(allow, scr);\n  }\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_AL);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = --as->mcp;\n  emit_n(as, A64I_CMPx^A64I_K12^0, dest);\n  emit_lso(as, A64I_LDRx, dest, dest, offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_EQ);\n  else\n    emit_cond_branch(as, CC_EQ, l_end);\n\n  if (irt_isnum(kt)) {\n    if (isk) {\n      /* Assumes -0.0 is already canonicalized to +0.0. */\n      if (k)\n\temit_n(as, A64I_CMPx^k, tmp);\n      else\n\temit_nm(as, A64I_CMPx, key, tmp);\n      emit_lso(as, A64I_LDRx, tmp, dest, offsetof(Node, key.u64));\n    } else {\n      emit_nm(as, A64I_FCMPd, key, ftmp);\n      emit_dn(as, A64I_FMOV_D_R, (ftmp & 31), (tmp & 31));\n      emit_cond_branch(as, CC_LO, l_next);\n      emit_nm(as, A64I_CMPx | A64F_SH(A64SH_LSR, 32), tisnum, tmp);\n      emit_lso(as, A64I_LDRx, tmp, dest, offsetof(Node, key.n));\n    }\n  } else if (irt_isaddr(kt)) {\n    if (isk) {\n      emit_nm(as, A64I_CMPx, scr, tmp);\n      emit_lso(as, A64I_LDRx, tmp, dest, offsetof(Node, key.u64));\n    } else {\n      emit_nm(as, A64I_CMPx, tmp, scr);\n      emit_lso(as, A64I_LDRx, scr, dest, offsetof(Node, key.u64));\n    }\n  } else {\n    emit_nm(as, A64I_CMPx, scr, type);\n    emit_lso(as, A64I_LDRx, scr, dest, offsetof(Node, key));\n  }\n\n  *l_loop = A64I_BCC | A64F_S19(as->mcp - l_loop) | CC_NE;\n  if (!isk && irt_isaddr(kt)) {\n    type = ra_allock(as, (int32_t)irt_toitype(kt), allow);\n    emit_dnm(as, A64I_ADDx | A64F_SH(A64SH_LSL, 47), tmp, key, type);\n    rset_clear(allow, type);\n  }\n  /* Load main position relative to tab->node into dest. */\n  khash = isk ? ir_khash(as, irkey) : 1;\n  if (khash == 0) {\n    emit_lso(as, A64I_LDRx, dest, tab, offsetof(GCtab, node));\n  } else {\n    emit_dnm(as, A64I_ADDx | A64F_SH(A64SH_LSL, 3), dest, tmp, dest);\n    emit_dnm(as, A64I_ADDx | A64F_SH(A64SH_LSL, 1), dest, dest, dest);\n    emit_lso(as, A64I_LDRx, tmp, tab, offsetof(GCtab, node));\n    if (isk) {\n      Reg tmphash = ra_allock(as, khash, allow);\n      emit_dnm(as, A64I_ANDw, dest, dest, tmphash);\n      emit_lso(as, A64I_LDRw, dest, tab, offsetof(GCtab, hmask));\n    } else if (irt_isstr(kt)) {\n      /* Fetch of str->sid is cheaper than ra_allock. */\n      emit_dnm(as, A64I_ANDw, dest, dest, tmp);\n      emit_lso(as, A64I_LDRw, tmp, key, offsetof(GCstr, sid));\n      emit_lso(as, A64I_LDRw, dest, tab, offsetof(GCtab, hmask));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      emit_dnm(as, A64I_ANDw, dest, dest, tmp);\n      emit_lso(as, A64I_LDRw, tmp, tab, offsetof(GCtab, hmask));\n      emit_dnm(as, A64I_SUBw, dest, dest, tmp);\n      emit_dnm(as, A64I_EXTRw | (A64F_IMMS(32-HASH_ROT3)), tmp, tmp, tmp);\n      emit_dnm(as, A64I_EORw, dest, dest, tmp);\n      emit_dnm(as, A64I_EXTRw | (A64F_IMMS(32-HASH_ROT2)), dest, dest, dest);\n      emit_dnm(as, A64I_SUBw, tmp, tmp, dest);\n      emit_dnm(as, A64I_EXTRw | (A64F_IMMS(32-HASH_ROT1)), dest, dest, dest);\n      emit_dnm(as, A64I_EORw, tmp, tmp, dest);\n      if (irt_isnum(kt)) {\n\temit_dnm(as, A64I_ADDw, dest, dest, dest);\n\temit_dn(as, A64I_LSRx | A64F_IMMR(32)|A64F_IMMS(32), dest, dest);\n\temit_dm(as, A64I_MOVw, tmp, dest);\n\temit_dn(as, A64I_FMOV_R_D, dest, (key & 31));\n      } else {\n\tcheckmclim(as);\n\temit_dm(as, A64I_MOVw, tmp, key);\n\temit_dnm(as, A64I_EORw, dest, dest,\n\t\t ra_allock(as, irt_toitype(kt) << 15, allow));\n\temit_dn(as, A64I_LSRx | A64F_IMMR(32)|A64F_IMMS(32), dest, dest);\n\temit_dm(as, A64I_MOVx, dest, key);\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  int bigofs = !emit_checkofs(A64I_LDRx, ofs);\n  Reg dest = (ra_used(ir) || bigofs) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  uint64_t k;\n  lj_assertA(ofs % sizeof(Node) == 0, \"unaligned HREFK slot\");\n  if (bigofs) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_opk(as, A64I_ADDx, dest, node, ofs, allow);\n  }\n  asm_guardcc(as, CC_NE);\n  if (irt_ispri(irkey->t)) {\n    k = ~((int64_t)~irt_toitype(irkey->t) << 47);\n  } else if (irt_isnum(irkey->t)) {\n    k = ir_knum(irkey)->u64;\n  } else {\n    k = ((uint64_t)irt_toitype(irkey->t) << 47) | (uint64_t)ir_kgc(irkey);\n  }\n  key = ra_scratch(as, allow);\n  emit_nm(as, A64I_CMPx, key, ra_allock(as, k, rset_exclude(allow, key)));\n  emit_lso(as, A64I_LDRx, key, idx, kofs);\n  if (bigofs)\n    emit_opk(as, A64I_ADDx, dest, node, ofs, RSET_GPR);\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, A64I_LDRx, dest, v);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guardcc(as, CC_NE);\n      emit_n(as, (A64I_CMPx^A64I_K12) | A64F_U12(1), RID_TMP);\n      emit_opk(as, A64I_ADDx, dest, uv,\n\t       (int32_t)offsetof(GCupval, tv), RSET_GPR);\n      emit_lso(as, A64I_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_lso(as, A64I_LDRx, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_lso(as, A64I_LDRx, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 8*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lj_assertA(!ra_used(ir), \"unfused FREF\");\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg dest = ra_dest(as, ir, allow);\n  Reg base = ra_alloc1(as, ir->op1, allow);\n  IRIns *irr = IR(ir->op2);\n  int32_t ofs = sizeof(GCstr);\n  uint32_t m;\n  rset_clear(allow, base);\n  if (irref_isk(ir->op2) && (m = emit_isk12(ofs + irr->i))) {\n    emit_dn(as, A64I_ADDx^m, dest, base);\n  } else {\n    emit_dn(as, (A64I_ADDx^A64I_K12) | A64F_U12(ofs), dest, dest);\n    emit_dnm(as, A64I_ADDx, dest, base, ra_alloc1(as, ir->op2, allow));\n  }\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic A64Ins asm_fxloadins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return A64I_LDRB ^ A64I_LS_S;\n  case IRT_U8: return A64I_LDRB;\n  case IRT_I16: return A64I_LDRH ^ A64I_LS_S;\n  case IRT_U16: return A64I_LDRH;\n  case IRT_NUM: return A64I_LDRd;\n  case IRT_FLOAT: return A64I_LDRs;\n  default: return irt_is64(ir->t) ? A64I_LDRx : A64I_LDRw;\n  }\n}\n\nstatic A64Ins asm_fxstoreins(IRIns *ir)\n{\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return A64I_STRB;\n  case IRT_I16: case IRT_U16: return A64I_STRH;\n  case IRT_NUM: return A64I_STRd;\n  case IRT_FLOAT: return A64I_STRs;\n  default: return irt_is64(ir->t) ? A64I_STRx : A64I_STRw;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx;\n  A64Ins ai = asm_fxloadins(ir);\n  int32_t ofs;\n  if (ir->op1 == REF_NIL) {  /* FLOAD from GG_State with offset. */\n    idx = RID_GL;\n    ofs = (ir->op2 << 2) - GG_OFS(g);\n  } else {\n    idx = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->op2 == IRFL_TAB_ARRAY) {\n      ofs = asm_fuseabase(as, ir->op1);\n      if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n\temit_dn(as, (A64I_ADDx^A64I_K12) | A64F_U12(ofs), dest, idx);\n\treturn;\n      }\n    }\n    ofs = field_ofs[ir->op2];\n  }\n  emit_lso(as, ai, (dest & 31), idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    emit_lso(as, asm_fxstoreins(ir), (src & 31), idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n  lj_assertA(!(ir->op2 & IRXLOAD_UNALIGNED), \"unaligned XLOAD\");\n  asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR);\n}\n\nstatic void asm_xstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src));\n  }\n}\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  Reg idx, tmp, type;\n  int32_t ofs = 0;\n  RegSet gpr = RSET_GPR, allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR;\n  lj_assertA(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) ||\n\t     irt_isint(ir->t),\n\t     \"bad load type %d\", irt_type(ir->t));\n  if (ra_used(ir)) {\n    Reg dest = ra_dest(as, ir, allow);\n    tmp = irt_isnum(ir->t) ? ra_scratch(as, rset_clear(gpr, dest)) : dest;\n    if (irt_isaddr(ir->t)) {\n      emit_dn(as, A64I_ANDx^emit_isk13(LJ_GCVMASK, 1), dest, dest);\n    } else if (irt_isnum(ir->t)) {\n      emit_dn(as, A64I_FMOV_D_R, (dest & 31), tmp);\n    } else if (irt_isint(ir->t)) {\n      emit_dm(as, A64I_MOVw, dest, dest);\n    }\n  } else {\n    tmp = ra_scratch(as, gpr);\n  }\n  type = ra_scratch(as, rset_clear(gpr, tmp));\n  idx = asm_fuseahuref(as, ir->op1, &ofs, rset_clear(gpr, type), A64I_LDRx);\n  if (ir->o == IR_VLOAD) ofs += 8 * ir->op2;\n  /* Always do the type check, even if the load result is unused. */\n  asm_guardcc(as, irt_isnum(ir->t) ? CC_LS : CC_NE);\n  if (irt_type(ir->t) >= IRT_NUM) {\n    lj_assertA(irt_isinteger(ir->t) || irt_isnum(ir->t),\n\t       \"bad load type %d\", irt_type(ir->t));\n    emit_nm(as, A64I_CMPx | A64F_SH(A64SH_LSR, 32),\n\t    ra_allock(as, LJ_TISNUM << 15, rset_exclude(gpr, idx)), tmp);\n  } else if (irt_isaddr(ir->t)) {\n    emit_n(as, (A64I_CMNx^A64I_K12) | A64F_U12(-irt_toitype(ir->t)), type);\n    emit_dn(as, A64I_ASRx | A64F_IMMR(47), type, tmp);\n  } else if (irt_isnil(ir->t)) {\n    emit_n(as, (A64I_CMNx^A64I_K12) | A64F_U12(1), tmp);\n  } else {\n    emit_nm(as, A64I_CMPx | A64F_SH(A64SH_LSR, 32),\n\t    ra_allock(as, (irt_toitype(ir->t) << 15) | 0x7fff, gpr), tmp);\n  }\n  if (ofs & FUSE_REG)\n    emit_dnm(as, (A64I_LDRx^A64I_LS_R)|A64I_LS_UXTWx|A64I_LS_SH, tmp, idx, (ofs & 31));\n  else\n    emit_lso(as, A64I_LDRx, tmp, idx, ofs);\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    RegSet allow = RSET_GPR;\n    Reg idx, src = RID_NONE, tmp = RID_TMP, type = RID_NONE;\n    int32_t ofs = 0;\n    if (irt_isnum(ir->t)) {\n      src = ra_alloc1(as, ir->op2, RSET_FPR);\n      idx = asm_fuseahuref(as, ir->op1, &ofs, allow, A64I_STRd);\n      if (ofs & FUSE_REG)\n\temit_dnm(as, (A64I_STRd^A64I_LS_R)|A64I_LS_UXTWx|A64I_LS_SH, (src & 31), idx, (ofs &31));\n      else\n\temit_lso(as, A64I_STRd, (src & 31), idx, ofs);\n    } else {\n      if (!irt_ispri(ir->t)) {\n\tsrc = ra_alloc1(as, ir->op2, allow);\n\trset_clear(allow, src);\n\tif (irt_isinteger(ir->t))\n\t  type = ra_allock(as, (uint64_t)(int32_t)LJ_TISNUM << 47, allow);\n\telse\n\t  type = ra_allock(as, irt_toitype(ir->t), allow);\n      } else {\n\ttmp = type = ra_allock(as, ~((int64_t)~irt_toitype(ir->t)<<47), allow);\n      }\n      idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type),\n\t\t\t   A64I_STRx);\n      if (ofs & FUSE_REG)\n\temit_dnm(as, (A64I_STRx^A64I_LS_R)|A64I_LS_UXTWx|A64I_LS_SH, tmp, idx, (ofs & 31));\n      else\n\temit_lso(as, A64I_STRx, tmp, idx, ofs);\n      if (ra_hasreg(src)) {\n\tif (irt_isinteger(ir->t)) {\n\t  emit_dnm(as, A64I_ADDx | A64F_EX(A64EX_UXTW), tmp, type, src);\n\t} else {\n\t  emit_dnm(as, A64I_ADDx | A64F_SH(A64SH_LSL, 47), tmp, src, type);\n\t}\n      }\n    }\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-2);\n  IRType1 t = ir->t;\n  Reg dest = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  lj_assertA(!(ir->op2 & IRSLOAD_PARENT),\n\t     \"bad parent SLOAD\");  /* Handled by asm_head_side(). */\n  lj_assertA(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK),\n\t     \"inconsistent SLOAD variant\");\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n  } else if (ra_used(ir)) {\n    Reg tmp = RID_NONE;\n    if ((ir->op2 & IRSLOAD_CONVERT))\n      tmp = ra_scratch(as, irt_isint(t) ? RSET_FPR : RSET_GPR);\n    lj_assertA((irt_isnum(t)) || irt_isint(t) || irt_isaddr(t),\n\t       \"bad SLOAD type %d\", irt_type(t));\n    dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : allow);\n    base = ra_alloc1(as, REF_BASE, rset_clear(allow, dest));\n    if (irt_isaddr(t)) {\n      emit_dn(as, A64I_ANDx^emit_isk13(LJ_GCVMASK, 1), dest, dest);\n    } else if ((ir->op2 & IRSLOAD_CONVERT)) {\n      if (irt_isint(t)) {\n\temit_dn(as, A64I_FCVT_S32_F64, dest, (tmp & 31));\n\t/* If value is already loaded for type check, move it to FPR. */\n\tif ((ir->op2 & IRSLOAD_TYPECHECK))\n\t  emit_dn(as, A64I_FMOV_D_R, (tmp & 31), dest);\n\telse\n\t  dest = tmp;\n\tt.irt = IRT_NUM;  /* Check for original type. */\n      } else {\n\temit_dn(as, A64I_FCVT_F64_S32, (dest & 31), tmp);\n\tdest = tmp;\n\tt.irt = IRT_INT;  /* Check for original type. */\n      }\n    } else if (irt_isint(t) && (ir->op2 & IRSLOAD_TYPECHECK)) {\n      emit_dm(as, A64I_MOVw, dest, dest);\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\ndotypecheck:\n  rset_clear(allow, base);\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    Reg tmp;\n    if (ra_hasreg(dest) && rset_test(RSET_GPR, dest)) {\n      tmp = dest;\n    } else {\n      tmp = ra_scratch(as, allow);\n      rset_clear(allow, tmp);\n    }\n    if (irt_isnum(t) && !(ir->op2 & IRSLOAD_CONVERT))\n      emit_dn(as, A64I_FMOV_D_R, (dest & 31), tmp);\n    /* Need type check, even if the load result is unused. */\n    asm_guardcc(as, irt_isnum(t) ? CC_LS : CC_NE);\n    if (irt_type(t) >= IRT_NUM) {\n      lj_assertA(irt_isinteger(t) || irt_isnum(t),\n\t\t \"bad SLOAD type %d\", irt_type(t));\n      emit_nm(as, A64I_CMPx | A64F_SH(A64SH_LSR, 32),\n\t      ra_allock(as, LJ_TISNUM << 15, allow), tmp);\n    } else if (irt_isnil(t)) {\n      emit_n(as, (A64I_CMNx^A64I_K12) | A64F_U12(1), tmp);\n    } else if (irt_ispri(t)) {\n      emit_nm(as, A64I_CMPx,\n\t      ra_allock(as, ~((int64_t)~irt_toitype(t) << 47) , allow), tmp);\n    } else {\n      Reg type = ra_scratch(as, allow);\n      emit_n(as, (A64I_CMNx^A64I_K12) | A64F_U12(-irt_toitype(t)), type);\n      emit_dn(as, A64I_ASRx | A64F_IMMR(47), type, tmp);\n    }\n    emit_lso(as, A64I_LDRx, tmp, base, ofs);\n    return;\n  }\n  if (ra_hasreg(dest)) {\n    emit_lso(as, irt_isnum(t) ? A64I_LDRd :\n\t     (irt_isint(t) ? A64I_LDRw : A64I_LDRx), (dest & 31), base,\n\t     ofs ^ ((LJ_BE && irt_isint(t) ? 4 : 0)));\n  }\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n  lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),\n\t     \"bad CNEW/CNEWI operands\");\n\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCcdata * */\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    int32_t ofs = sizeof(GCcdata);\n    Reg r = ra_alloc1(as, ir->op2, allow);\n    lj_assertA(sz == 4 || sz == 8, \"bad CNEWI size %d\", sz);\n    emit_lso(as, sz == 8 ? A64I_STRx : A64I_STRw, r, RID_RET, ofs);\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  {\n    Reg r = (id < 65536) ? RID_X1 : ra_allock(as, id, allow);\n    emit_lso(as, A64I_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct));\n    emit_lso(as, A64I_STRH, r, RID_RET, offsetof(GCcdata, ctypeid));\n    emit_d(as, A64I_MOVZw | A64F_U16(~LJ_TCDATA), RID_TMP);\n    if (id < 65536) emit_d(as, A64I_MOVZw | A64F_U16(id), RID_X1);\n  }\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg mark = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_lso(as, A64I_STRx, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_lso(as, A64I_STRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_setgl(as, tab, gc.grayagain);\n  emit_dn(as, A64I_ANDw^emit_isk13(~LJ_GC_BLACK, 0), mark, mark);\n  emit_getgl(as, link, gc.grayagain);\n  emit_cond_branch(as, CC_EQ, l_end);\n  emit_n(as, A64I_TSTw^emit_isk13(LJ_GC_BLACK, 0), mark);\n  emit_lso(as, A64I_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  RegSet allow = RSET_GPR;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lj_assertA(IR(ir->op1)->o == IR_UREFC, \"bad OBAR type\");\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_dm(as, A64I_MOVx, ra_releasetmp(as, ASMREF_TMP1), RID_GL);\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(allow, obj));\n  emit_cond_branch(as, CC_EQ, l_end);\n  emit_n(as, A64I_TSTw^emit_isk13(LJ_GC_BLACK, 0), tmp);\n  emit_cond_branch(as, CC_EQ, l_end);\n  emit_n(as, A64I_TSTw^emit_isk13(LJ_GC_WHITES, 0), RID_TMP);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_lso(as, A64I_LDRB, tmp, obj,\n     (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_lso(as, A64I_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\nstatic void asm_fparith(ASMState *as, IRIns *ir, A64Ins ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  emit_dnm(as, ai, (dest & 31), (left & 31), (right & 31));\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, A64Ins ai)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_dn(as, ai, (dest & 31), (left & 31));\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  IRFPMathOp fpm = (IRFPMathOp)ir->op2;\n  if (fpm == IRFPM_SQRT) {\n    asm_fpunary(as, ir, A64I_FSQRTd);\n  } else if (fpm <= IRFPM_TRUNC) {\n    asm_fpunary(as, ir, fpm == IRFPM_FLOOR ? A64I_FRINTMd :\n\t\t\tfpm == IRFPM_CEIL ? A64I_FRINTPd : A64I_FRINTZd);\n  } else {\n    asm_callid(as, ir, IRCALL_lj_vm_floor + fpm);\n  }\n}\n\nstatic int asm_swapops(ASMState *as, IRRef lref, IRRef rref)\n{\n  IRIns *ir;\n  if (irref_isk(rref))\n    return 0;  /* Don't swap constants to the left. */\n  if (irref_isk(lref))\n    return 1;  /* But swap constants to the right. */\n  ir = IR(rref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BSAR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2) ||\n      (ir->o == IR_CONV && ir->op2 == ((IRT_I64<<IRCONV_DSH)|IRT_INT|IRCONV_SEXT)))\n    return 0;  /* Don't swap fusable operands to the left. */\n  ir = IR(lref);\n  if ((ir->o >= IR_BSHL && ir->o <= IR_BSAR) ||\n      (ir->o == IR_ADD && ir->op1 == ir->op2) ||\n      (ir->o == IR_CONV && ir->op2 == ((IRT_I64<<IRCONV_DSH)|IRT_INT|IRCONV_SEXT)))\n    return 1;  /* But swap fusable operands to the right. */\n  return 0;  /* Otherwise don't swap. */\n}\n\nstatic void asm_intop(ASMState *as, IRIns *ir, A64Ins ai)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left, dest = ra_dest(as, ir, RSET_GPR);\n  uint32_t m;\n  if ((ai & ~A64I_S) != A64I_SUBw && asm_swapops(as, lref, rref)) {\n    IRRef tmp = lref; lref = rref; rref = tmp;\n  }\n  left = ra_hintalloc(as, lref, dest, RSET_GPR);\n  if (irt_is64(ir->t)) ai |= A64I_X;\n  m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));\n  if (irt_isguard(ir->t)) {  /* For IR_ADDOV etc. */\n    asm_guardcc(as, CC_VS);\n    ai |= A64I_S;\n  }\n  emit_dn(as, ai^m, dest, left);\n}\n\nstatic void asm_intop_s(ASMState *as, IRIns *ir, A64Ins ai)\n{\n  if (as->flagmcp == as->mcp) {  /* Drop cmp r, #0. */\n    as->flagmcp = NULL;\n    as->mcp++;\n    ai |= A64I_S;\n  }\n  asm_intop(as, ir, ai);\n}\n\nstatic void asm_intneg(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  emit_dm(as, irt_is64(ir->t) ? A64I_NEGx : A64I_NEGw, dest, left);\n}\n\n/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */\nstatic void asm_intmul(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest));\n  Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  if (irt_isguard(ir->t)) {  /* IR_MULOV */\n    asm_guardcc(as, CC_NE);\n    emit_dm(as, A64I_MOVw, dest, dest);  /* Zero-extend. */\n    emit_nm(as, A64I_CMPw | A64F_SH(A64SH_ASR, 31), RID_TMP, dest);\n    emit_dn(as, A64I_ASRx | A64F_IMMR(32), RID_TMP, dest);\n    emit_dnm(as, A64I_SMULL, dest, right, left);\n  } else {\n    emit_dnm(as, irt_is64(ir->t) ? A64I_MULx : A64I_MULw, dest, left, right);\n  }\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, A64I_FMADDd, A64I_FMADDd))\n      asm_fparith(as, ir, A64I_FADDd);\n    return;\n  }\n  asm_intop_s(as, ir, A64I_ADDw);\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, A64I_FNMSUBd, A64I_FMSUBd))\n      asm_fparith(as, ir, A64I_FSUBd);\n    return;\n  }\n  asm_intop_s(as, ir, A64I_SUBw);\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, A64I_FMULd);\n    return;\n  }\n  asm_intmul(as, ir);\n}\n\n#define asm_addov(as, ir)\tasm_add(as, ir)\n#define asm_subov(as, ir)\tasm_sub(as, ir)\n#define asm_mulov(as, ir)\tasm_mul(as, ir)\n\n#define asm_fpdiv(as, ir)\tasm_fparith(as, ir, A64I_FDIVd)\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, A64I_FABS)\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, A64I_FNEGd);\n    return;\n  }\n  asm_intneg(as, ir);\n}\n\nstatic void asm_band(ASMState *as, IRIns *ir)\n{\n  A64Ins ai = A64I_ANDw;\n  if (asm_fuseandshift(as, ir))\n    return;\n  if (as->flagmcp == as->mcp) {\n    /* Try to drop cmp r, #0. */\n    as->flagmcp = NULL;\n    as->mcp++;\n    ai = A64I_ANDSw;\n  }\n  asm_intop(as, ir, ai);\n}\n\nstatic void asm_borbxor(ASMState *as, IRIns *ir, A64Ins ai)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irl = IR(lref), *irr = IR(rref);\n  if ((canfuse(as, irl) && irl->o == IR_BNOT && !irref_isk(rref)) ||\n      (canfuse(as, irr) && irr->o == IR_BNOT && !irref_isk(lref))) {\n    Reg left, dest = ra_dest(as, ir, RSET_GPR);\n    uint32_t m;\n    if (irl->o == IR_BNOT) {\n      IRRef tmp = lref; lref = rref; rref = tmp;\n    }\n    left = ra_alloc1(as, lref, RSET_GPR);\n    ai |= A64I_ON;\n    if (irt_is64(ir->t)) ai |= A64I_X;\n    m = asm_fuseopm(as, ai, IR(rref)->op1, rset_exclude(RSET_GPR, left));\n    emit_dn(as, ai^m, dest, left);\n  } else {\n    asm_intop(as, ir, ai);\n  }\n}\n\nstatic void asm_bor(ASMState *as, IRIns *ir)\n{\n  if (asm_fuseorshift(as, ir))\n    return;\n  asm_borbxor(as, ir, A64I_ORRw);\n}\n\n#define asm_bxor(as, ir)\tasm_borbxor(as, ir, A64I_EORw)\n\nstatic void asm_bnot(ASMState *as, IRIns *ir)\n{\n  A64Ins ai = A64I_MVNw;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);\n  if (irt_is64(ir->t)) ai |= A64I_X;\n  emit_d(as, ai^m, dest);\n}\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_dn(as, irt_is64(ir->t) ? A64I_REVx : A64I_REVw, dest, left);\n}\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, A64Ins ai, A64Shift sh)\n{\n  int32_t shmask = irt_is64(ir->t) ? 63 : 31;\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    Reg left, dest = ra_dest(as, ir, RSET_GPR);\n    int32_t shift = (IR(ir->op2)->i & shmask);\n    IRIns *irl = IR(ir->op1);\n    if (shmask == 63) ai += A64I_UBFMx - A64I_UBFMw;\n\n    /* Fuse BSHL + BSHR/BSAR into UBFM/SBFM aka UBFX/SBFX/UBFIZ/SBFIZ. */\n    if ((sh == A64SH_LSR || sh == A64SH_ASR) && canfuse(as, irl)) {\n      if (irl->o == IR_BSHL && irref_isk(irl->op2)) {\n\tint32_t shift2 = (IR(irl->op2)->i & shmask);\n\tshift = ((shift - shift2) & shmask);\n\tshmask -= shift2;\n\tir = irl;\n      }\n    }\n\n    left = ra_alloc1(as, ir->op1, RSET_GPR);\n    switch (sh) {\n    case A64SH_LSL:\n      emit_dn(as, ai | A64F_IMMS(shmask-shift) |\n\t\t  A64F_IMMR((shmask-shift+1)&shmask), dest, left);\n      break;\n    case A64SH_LSR: case A64SH_ASR:\n      emit_dn(as, ai | A64F_IMMS(shmask) | A64F_IMMR(shift), dest, left);\n      break;\n    case A64SH_ROR:\n      emit_dnm(as, ai | A64F_IMMS(shift), dest, left, left);\n      break;\n    }\n  } else {  /* Variable-length shifts. */\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_dnm(as, (shmask == 63 ? A64I_SHRx : A64I_SHRw) | A64F_BSH(sh), dest, left, right);\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, A64I_UBFMw, A64SH_LSL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, A64I_UBFMw, A64SH_LSR)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, A64I_SBFMw, A64SH_ASR)\n#define asm_bror(as, ir)\tasm_bitshift(as, ir, A64I_EXTRw, A64SH_ROR)\n#define asm_brol(as, ir)\tlj_assertA(0, \"unexpected BROL\")\n\nstatic void asm_intmin_max(ASMState *as, IRIns *ir, A64CC cc)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_dnm(as, A64I_CSELw|A64F_CC(cc), dest, left, right);\n  emit_nm(as, A64I_CMPw, left, right);\n}\n\nstatic void asm_fpmin_max(ASMState *as, IRIns *ir, A64CC fcc)\n{\n  Reg dest = (ra_dest(as, ir, RSET_FPR) & 31);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = ((left >> 8) & 31); left &= 31;\n  emit_dnm(as, A64I_FCSELd | A64F_CC(fcc), dest, right, left);\n  emit_nm(as, A64I_FCMPd, left, right);\n}\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, A64CC cc, A64CC fcc)\n{\n  if (irt_isnum(ir->t))\n    asm_fpmin_max(as, ir, fcc);\n  else\n    asm_intmin_max(as, ir, cc);\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, CC_LT, CC_PL)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, CC_GT, CC_LE)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n/* Map of comparisons to flags. ORDER IR. */\nstatic const uint8_t asm_compmap[IR_ABC+1] = {\n  /* op  FP swp  int cc   FP cc */\n  /* LT       */ CC_GE + (CC_HS << 4),\n  /* GE    x  */ CC_LT + (CC_HI << 4),\n  /* LE       */ CC_GT + (CC_HI << 4),\n  /* GT    x  */ CC_LE + (CC_HS << 4),\n  /* ULT   x  */ CC_HS + (CC_LS << 4),\n  /* UGE      */ CC_LO + (CC_LO << 4),\n  /* ULE   x  */ CC_HI + (CC_LO << 4),\n  /* UGT      */ CC_LS + (CC_LS << 4),\n  /* EQ       */ CC_NE + (CC_NE << 4),\n  /* NE       */ CC_EQ + (CC_EQ << 4),\n  /* ABC      */ CC_LS + (CC_LS << 4)  /* Same as UGT. */\n};\n\n/* FP comparisons. */\nstatic void asm_fpcomp(ASMState *as, IRIns *ir)\n{\n  Reg left, right;\n  A64Ins ai;\n  int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1);\n  if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) {\n    left = (ra_alloc1(as, ir->op1, RSET_FPR) & 31);\n    right = 0;\n    ai = A64I_FCMPZd;\n  } else {\n    left = ra_alloc2(as, ir, RSET_FPR);\n    if (swp) {\n      right = (left & 31); left = ((left >> 8) & 31);\n    } else {\n      right = ((left >> 8) & 31); left &= 31;\n    }\n    ai = A64I_FCMPd;\n  }\n  asm_guardcc(as, (asm_compmap[ir->o] >> 4));\n  emit_nm(as, ai, left, right);\n}\n\n/* Integer comparisons. */\nstatic void asm_intcomp(ASMState *as, IRIns *ir)\n{\n  A64CC oldcc, cc = (asm_compmap[ir->o] & 15);\n  A64Ins ai = irt_is64(ir->t) ? A64I_CMPx : A64I_CMPw;\n  IRRef lref = ir->op1, rref = ir->op2;\n  Reg left;\n  uint32_t m;\n  int cmpprev0 = 0;\n  lj_assertA(irt_is64(ir->t) || irt_isint(ir->t) ||\n\t     irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t),\n\t     \"bad comparison data type %d\", irt_type(ir->t));\n  if (asm_swapops(as, lref, rref)) {\n    IRRef tmp = lref; lref = rref; rref = tmp;\n    if (cc >= CC_GE) cc ^= 7;  /* LT <-> GT, LE <-> GE */\n    else if (cc > CC_NE) cc ^= 11;  /* LO <-> HI, LS <-> HS */\n  }\n  oldcc = cc;\n  if (irref_isk(rref) && get_k64val(as, rref) == 0) {\n    IRIns *irl = IR(lref);\n    if (cc == CC_GE) cc = CC_PL;\n    else if (cc == CC_LT) cc = CC_MI;\n    else if (cc > CC_NE) goto nocombine;  /* Other conds don't work with tst. */\n    cmpprev0 = (irl+1 == ir);\n    /* Combine and-cmp-bcc into tbz/tbnz or and-cmp into tst. */\n    if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) {\n      IRRef blref = irl->op1, brref = irl->op2;\n      uint32_t m2 = 0;\n      Reg bleft;\n      if (asm_swapops(as, blref, brref)) {\n\tReg tmp = blref; blref = brref; brref = tmp;\n      }\n      if (irref_isk(brref)) {\n\tuint64_t k = get_k64val(as, brref);\n\tif (k && !(k & (k-1)) && (cc == CC_EQ || cc == CC_NE)) {\n\t  asm_guardtnb(as, cc == CC_EQ ? A64I_TBZ : A64I_TBNZ,\n\t\t       ra_alloc1(as, blref, RSET_GPR), emit_ctz64(k));\n\t  return;\n\t}\n\tm2 = emit_isk13(k, irt_is64(irl->t));\n      }\n      bleft = ra_alloc1(as, blref, RSET_GPR);\n      ai = (irt_is64(irl->t) ? A64I_TSTx : A64I_TSTw);\n      if (!m2)\n\tm2 = asm_fuseopm(as, ai, brref, rset_exclude(RSET_GPR, bleft));\n      asm_guardcc(as, cc);\n      emit_n(as, ai^m2, bleft);\n      return;\n    }\n    if (cc == CC_EQ || cc == CC_NE) {\n      /* Combine cmp-bcc into cbz/cbnz. */\n      ai = cc == CC_EQ ? A64I_CBZ : A64I_CBNZ;\n      if (irt_is64(ir->t)) ai |= A64I_X;\n      asm_guardcnb(as, ai, ra_alloc1(as, lref, RSET_GPR));\n      return;\n    }\n  }\nnocombine:\n  left = ra_alloc1(as, lref, RSET_GPR);\n  m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));\n  asm_guardcc(as, cc);\n  emit_n(as, ai^m, left);\n  /* Signed comparison with zero and referencing previous ins? */\n  if (cmpprev0 && (oldcc <= CC_NE || oldcc >= CC_GE))\n    as->flagmcp = as->mcp;  /* Allow elimination of the compare. */\n}\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fpcomp(as, ir);\n  else\n    asm_intcomp(as, ir);\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n/* -- Split register ops -------------------------------------------------- */\n\n/* Hiword op of a split 64/64 bit op. Previous op is the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n  case IR_CALLN:\n  case IR_CALLL:\n  case IR_CALLS:\n  case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  default: lj_assertA(0, \"bad HIOP for op %d\", (ir-1)->o); break;\n  }\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  uint32_t k = emit_isk13(HOOK_PROFILE, 0);\n  lj_assertA(k != 0, \"HOOK_PROFILE does not fit in K13\");\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_n(as, A64I_TSTw^k, RID_TMP);\n  emit_lsptr(as, A64I_LDRB, RID_TMP, (void *)&J2G(as->J)->hookmask);\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  Reg pbase;\n  uint32_t k;\n  if (irp) {\n    if (!ra_hasspill(irp->s)) {\n      pbase = irp->r;\n      lj_assertA(ra_hasreg(pbase), \"base reg lost\");\n    } else if (allow) {\n      pbase = rset_pickbot(allow);\n    } else {\n      pbase = RID_RET;\n      emit_lso(as, A64I_LDRx, RID_RET, RID_SP, 0);  /* Restore temp register. */\n    }\n  } else {\n    pbase = RID_BASE;\n  }\n  emit_cond_branch(as, CC_LS, asm_exitstub_addr(as, exitno));\n  k = emit_isk12((8*topslot));\n  lj_assertA(k, \"slot offset %d does not fit in K12\", 8*topslot);\n  emit_n(as, A64I_CMPx^k, RID_TMP);\n  emit_dnm(as, A64I_SUBx, RID_TMP, RID_TMP, pbase);\n  emit_lso(as, A64I_LDRx, RID_TMP, RID_TMP,\n\t   (int32_t)offsetof(lua_State, maxstack));\n  if (irp) {  /* Must not spill arbitrary registers in head of side trace. */\n    if (ra_hasspill(irp->s))\n      emit_lso(as, A64I_LDRx, pbase, RID_SP, sps_scale(irp->s));\n    emit_lso(as, A64I_LDRx, RID_TMP, RID_GL, glofs(as, &J2G(as->J)->cur_L));\n    if (ra_hasspill(irp->s) && !allow)\n      emit_lso(as, A64I_STRx, RID_RET, RID_SP, 0);  /* Save temp register. */\n  } else {\n    emit_getgl(as, RID_TMP, cur_L);\n  }\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n#ifdef LUA_USE_ASSERT\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1-LJ_FR2];\n#endif\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1-LJ_FR2);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if ((sn & SNAP_KEYINDEX)) {\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      Reg r = irref_isk(ref) ? ra_allock(as, ir->i, allow) :\n\t\t\t       ra_alloc1(as, ref, allow);\n      rset_clear(allow, r);\n      emit_lso(as, A64I_STRw, r, RID_BASE, ofs);\n      emit_lso(as, A64I_STRw, ra_allock(as, LJ_KEYINDEX, allow), RID_BASE, ofs+4);\n    } else if (irt_isnum(ir->t)) {\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_lso(as, A64I_STRd, (src & 31), RID_BASE, ofs);\n    } else {\n      asm_tvstore64(as, RID_BASE, ofs, ref);\n    }\n    checkmclim(as);\n  }\n  lj_assertA(map + nent == flinks, \"inconsistent frames in snapshot\");\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Marker to prevent patching the GC check exit. */\n#define ARM64_NOPATCH_GC_CHECK \\\n  (A64I_ORRx|A64F_D(RID_TMP)|A64F_M(RID_TMP)|A64F_N(RID_TMP))\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp2;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcnb(as, A64I_CBNZ, RID_RET); /* Assumes asm_snap_prep() is done. */\n  *--as->mcp = ARM64_NOPATCH_GC_CHECK;\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  emit_dm(as, A64I_MOVx, ra_releasetmp(as, ASMREF_TMP1), RID_GL);\n  tmp2 = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp2, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_cond_branch(as, CC_LS, l_end);\n  emit_nm(as, A64I_CMPx, RID_TMP, tmp2);\n  emit_getgl(as, tmp2, gc.threshold);\n  emit_getgl(as, RID_TMP, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    uint32_t mask = (p[-2] & 0x7e000000) == 0x36000000 ? 0x3fffu : 0x7ffffu;\n    ptrdiff_t delta = target - (p - 2);\n    /* asm_guard* already inverted the bcc/tnb/cnb and patched the final b. */\n    p[-2] |= ((uint32_t)delta & mask) << 5;\n  } else {\n    ptrdiff_t delta = target - (p - 1);\n    p[-1] = A64I_B | A64F_S26(delta);\n  }\n}\n\n/* Fixup the tail of the loop. */\nstatic void asm_loop_tail_fixup(ASMState *as)\n{\n  UNUSED(as);  /* Nothing to do. */\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Reload L register from g->cur_L. */\nstatic void asm_head_lreg(ASMState *as)\n{\n  IRIns *ir = IR(ASMREF_L);\n  if (ra_used(ir)) {\n    Reg r = ra_dest(as, ir, RSET_GPR);\n    emit_getgl(as, r, cur_L);\n    ra_evictk(as);\n  }\n}\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  ra_destreg(as, ir, RID_BASE);\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir;\n  asm_head_lreg(as);\n  ir = IR(REF_BASE);\n  if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))\n    ra_spill(as, ir);\n  if (ra_hasspill(irp->s)) {\n    rset_clear(allow, ra_dest(as, ir, allow));\n  } else {\n    Reg r = irp->r;\n    lj_assertA(ra_hasreg(r), \"base reg lost\");\n    rset_clear(allow, r);\n    if (r != ir->r && !rset_test(as->freeset, r))\n      ra_restore(as, regcost_ref(as->cost[r]));\n    ra_destreg(as, ir, r);\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *p = as->mctop;\n  MCode *target;\n  /* Undo the sp adjustment in BC_JLOOP when exiting to the interpreter. */\n  int32_t spadj = as->T->spadjust + (lnk ? 0 : sps_scale(SPS_FIXED));\n  if (spadj == 0) {\n    *--p = A64I_LE(A64I_NOP);\n    as->mctop = p;\n  } else {\n    /* Patch stack adjustment. */\n    uint32_t k = emit_isk12(spadj);\n    lj_assertA(k, \"stack adjustment %d does not fit in K12\", spadj);\n    p[-2] = (A64I_ADDx^k) | A64F_D(RID_SP) | A64F_N(RID_SP);\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  p[-1] = A64I_B | A64F_S26((target-p)+1);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop - 1;  /* Leave room for exit branch. */\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    as->mcp = p-1;  /* Leave room for stack pointer adjustment. */\n    as->invmcp = NULL;\n  }\n  *p = 0;  /* Prevent load/store merging. */\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++) {\n    if (args[i] && irt_isfp(IR(args[i])->t)) {\n      if (nfpr > 0) nfpr--; else nslots += 2;\n    } else {\n      if (ngpr > 0) ngpr--; else nslots += 2;\n    }\n  }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  /* May need extra exit for asm_stack_check on side traces. */\n  asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));\n}\n\n#if LJ_BE\n/* ARM64 instructions are always little-endian. Swap for ARM64BE. */\nstatic void asm_mcode_fixup(MCode *mcode, MSize size)\n{\n  MCode *pe = (MCode *)((char *)mcode + size);\n  while (mcode < pe) {\n    MCode ins = *mcode;\n    *mcode++ = lj_bswap(ins);\n  }\n}\n#define LJ_TARGET_MCODE_FIXUP\t1\n#endif\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *cstart = NULL;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MCode *px = exitstub_trace_addr(T, exitno);\n  int patchlong = 1;\n  /* Note: this assumes a trace exit is only ever patched once. */\n  for (; p < pe; p++) {\n    /* Look for exitstub branch, replace with branch to target. */\n    ptrdiff_t delta = target - p;\n    MCode ins = A64I_LE(*p);\n    if ((ins & 0xff000000u) == 0x54000000u &&\n\t((ins ^ ((px-p)<<5)) & 0x00ffffe0u) == 0) {\n      /* Patch bcc, if within range. */\n      if (A64F_S_OK(delta, 19)) {\n\t*p = A64I_LE((ins & 0xff00001fu) | A64F_S19(delta));\n\tif (!cstart) cstart = p;\n      }\n    } else if ((ins & 0xfc000000u) == 0x14000000u &&\n\t       ((ins ^ (px-p)) & 0x03ffffffu) == 0) {\n      /* Patch b. */\n      lj_assertJ(A64F_S_OK(delta, 26), \"branch target out of range\");\n      *p = A64I_LE((ins & 0xfc000000u) | A64F_S26(delta));\n      if (!cstart) cstart = p;\n    } else if ((ins & 0x7e000000u) == 0x34000000u &&\n\t       ((ins ^ ((px-p)<<5)) & 0x00ffffe0u) == 0) {\n      /* Patch cbz/cbnz, if within range. */\n      if (p[-1] == ARM64_NOPATCH_GC_CHECK) {\n\tpatchlong = 0;\n      } else if (A64F_S_OK(delta, 19)) {\n\t*p = A64I_LE((ins & 0xff00001fu) | A64F_S19(delta));\n\tif (!cstart) cstart = p;\n      }\n    } else if ((ins & 0x7e000000u) == 0x36000000u &&\n\t       ((ins ^ ((px-p)<<5)) & 0x0007ffe0u) == 0) {\n      /* Patch tbz/tbnz, if within range. */\n      if (A64F_S_OK(delta, 14)) {\n\t*p = A64I_LE((ins & 0xfff8001fu) | A64F_S14(delta));\n\tif (!cstart) cstart = p;\n      }\n    }\n  }\n  /* Always patch long-range branch in exit stub itself. Except, if we can't. */\n  if (patchlong) {\n    ptrdiff_t delta = target - px;\n    lj_assertJ(A64F_S_OK(delta, 26), \"branch target out of range\");\n    *px = A64I_B | A64F_S26(delta);\n    if (!cstart) cstart = px;\n  }\n  if (cstart) lj_mcode_sync(cstart, px+1);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm_mips.h",
    "content": "/*\n** MIPS IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate a register or RID_ZERO. */\nstatic Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!(allow & RSET_FPR) && irref_isk(ref) && get_kval(as, ref) == 0)\n      return RID_ZERO;\n    r = ra_allocref(as, ref, allow);\n  } else {\n    ra_noweak(as, r);\n  }\n  return r;\n}\n\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_alloc1z(as, ir->op2, allow);\n    left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_alloc1z(as, ir->op1, allow);\n    right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Need some spare long-range jump slots, for out-of-range branches. */\n#define MIPS_SPAREJUMP\t\t4\n\n/* Setup spare long-range jump slots per mcarea. */\nstatic void asm_sparejump_setup(ASMState *as)\n{\n  MCode *mxp = as->mctop;\n  if ((char *)mxp == (char *)as->J->mcarea + as->J->szmcarea) {\n    mxp -= MIPS_SPAREJUMP*2;\n    lj_assertA(MIPSI_NOP == 0, \"bad NOP\");\n    memset(mxp, 0, MIPS_SPAREJUMP*2*sizeof(MCode));\n    as->mctop = mxp;\n  }\n}\n\nstatic MCode *asm_sparejump_use(MCode *mcarea, MCode tjump)\n{\n  MCode *mxp = (MCode *)((char *)mcarea + ((MCLink *)mcarea)->size);\n  int slot = MIPS_SPAREJUMP;\n  while (slot--) {\n    mxp -= 2;\n    if (*mxp == tjump) {\n      return mxp;\n    } else if (*mxp == MIPSI_NOP) {\n      *mxp = tjump;\n      return mxp;\n    }\n  }\n  return NULL;\n}\n\n/* Setup exit stub after the end of each trace. */\nstatic void asm_exitstub_setup(ASMState *as)\n{\n  MCode *mxp = as->mctop;\n  /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */\n  *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno;\n  *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu);\n  lj_assertA(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0,\n\t     \"branch target out of range\");\n  *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0;\n  as->mctop = mxp;\n}\n\n/* Keep this in-sync with exitstub_trace_addr(). */\n#define asm_exitstub_addr(as)\t((as)->mctop)\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt)\n{\n  MCode *target = asm_exitstub_addr(as);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->invmcp = NULL;\n    as->loopinv = 1;\n    as->mcp = p+1;\n#if !LJ_TARGET_MIPSR6\n    mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u);  /* Invert cond. */\n#else\n    mi = mi ^ ((mi>>28) == 1 ? 0x04000000u :\n\t       (mi>>28) == 4 ? 0x00800000u : 0x00010000u);  /* Invert cond. */\n#endif\n    target = p;  /* Patch target later in asm_loop_fixup. */\n  }\n  emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);\n  emit_branch(as, mi, rs, rt, target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (checki16(ofs)) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (checki16(ofs)) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tintptr_t ofs = (intptr_t)&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv;\n\tintptr_t jgl = (intptr_t)J2G(as->J);\n\tif ((uintptr_t)(ofs-jgl) < 65536) {\n\t  *ofsp = ofs-jgl-32768;\n\t  return RID_JGL;\n\t} else {\n\t  *ofsp = (int16_t)ofs;\n\t  return ra_allock(as, ofs-(int16_t)ofs, allow);\n\t}\n      }\n    } else if (ir->o == IR_TMPREF) {\n      *ofsp = (int32_t)(offsetof(global_State, tmptv)-32768);\n      return RID_JGL;\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    if (ir->o == IR_ADD) {\n      intptr_t ofs2;\n      if (irref_isk(ir->op2) && (ofs2 = ofs + get_kval(as, ir->op2),\n\t\t\t\t checki16(ofs2))) {\n\tref = ir->op1;\n\tofs = (int32_t)ofs2;\n      }\n    } else if (ir->o == IR_STRREF) {\n      intptr_t ofs2 = 65536;\n      lj_assertA(ofs == 0, \"bad usage\");\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs2 = ofs + get_kval(as, ir->op2);\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs2 = ofs + get_kval(as, ir->op1);\n\tref = ir->op2;\n      }\n      if (!checki16(ofs2)) {\n\t/* NYI: Fuse ADD with constant. */\n\tReg right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\temit_hsi(as, mi, rt, RID_TMP, ofs);\n\temit_dst(as, MIPSI_AADDU, RID_TMP, left, right);\n\treturn;\n      }\n      ofs = ofs2;\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n  emit_hsi(as, mi, rt, base, ofs);\n}\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = LJ_32 ? 16 : 0;\n#if LJ_SOFTFP\n  Reg gpr = REGARG_FIRSTGPR;\n#else\n  Reg gpr, fpr = REGARG_FIRSTFPR;\n#endif\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func, 1);\n#if !LJ_SOFTFP\n  for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)\n    as->cost[gpr] = REGCOST(~0u, ASMREF_L);\n  gpr = REGARG_FIRSTGPR;\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    if (ref) {\n      IRIns *ir = IR(ref);\n#if !LJ_SOFTFP\n      if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR &&\n\t  !(ci->flags & CCI_VARARG)) {\n\tlj_assertA(rset_test(as->freeset, fpr),\n\t\t   \"reg %d not free\", fpr);  /* Already evicted. */\n\tra_leftov(as, fpr, ref);\n\tfpr += LJ_32 ? 2 : 1;\n\tgpr += (LJ_32 && irt_isnum(ir->t)) ? 2 : 1;\n      } else\n#endif\n      {\n#if LJ_32 && !LJ_SOFTFP\n\tfpr = REGARG_LASTFPR+1;\n#endif\n\tif (LJ_32 && irt_isnum(ir->t)) gpr = (gpr+1) & ~1;\n\tif (gpr <= REGARG_LASTGPR) {\n\t  lj_assertA(rset_test(as->freeset, gpr),\n\t\t     \"reg %d not free\", gpr);  /* Already evicted. */\n#if !LJ_SOFTFP\n\t  if (irt_isfp(ir->t)) {\n\t    RegSet of = as->freeset;\n\t    Reg r;\n\t    /* Workaround to protect argument GPRs from being used for remat. */\n\t    as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);\n\t    r = ra_alloc1(as, ref, RSET_FPR);\n\t    as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));\n\t    if (irt_isnum(ir->t)) {\n#if LJ_32\n\t      emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1);\n\t      emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r);\n\t      lj_assertA(rset_test(as->freeset, gpr+1),\n\t\t\t \"reg %d not free\", gpr+1);  /* Already evicted. */\n\t      gpr += 2;\n#else\n\t      emit_tg(as, MIPSI_DMFC1, gpr, r);\n\t      gpr++; fpr++;\n#endif\n\t    } else if (irt_isfloat(ir->t)) {\n\t      emit_tg(as, MIPSI_MFC1, gpr, r);\n\t      gpr++;\n#if LJ_64\n\t      fpr++;\n#endif\n\t    }\n\t  } else\n#endif\n\t  {\n\t    ra_leftov(as, gpr, ref);\n\t    gpr++;\n#if LJ_64 && !LJ_SOFTFP\n\t    fpr++;\n#endif\n\t  }\n\t} else {\n\t  Reg r = ra_alloc1z(as, ref, !LJ_SOFTFP && irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n#if LJ_32\n\t  if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += irt_isnum(ir->t) ? 8 : 4;\n#else\n\t  emit_spstore(as, ir, r, ofs + ((LJ_BE && !irt_isfp(ir->t) && !irt_is64(ir->t)) ? 4 : 0));\n\t  ofs += 8;\n#endif\n\t}\n      }\n    } else {\n#if !LJ_SOFTFP\n      fpr = REGARG_LASTFPR+1;\n#endif\n      if (gpr <= REGARG_LASTGPR) {\n\tgpr++;\n#if LJ_64 && !LJ_SOFTFP\n\tfpr++;\n#endif\n      } else {\n\tofs += LJ_32 ? 4 : 8;\n      }\n    }\n    checkmclim(as);\n  }\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n#if !LJ_SOFTFP\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n#endif\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lj_assertA(!irt_ispri(ir->t), \"PRI dest\");\n    if (!LJ_SOFTFP && irt_isfp(ir->t)) {\n      if ((ci->flags & CCI_CASTU64)) {\n\tint32_t ofs = sps_scale(ir->s);\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n#if LJ_32\n\t  emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1);\n\t  emit_tg(as, MIPSI_MTC1, RID_RETLO, dest);\n#else\n\t  emit_tg(as, MIPSI_DMTC1, RID_RET, dest);\n#endif\n\t}\n\tif (ofs) {\n#if LJ_32\n\t  emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0));\n\t  emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4));\n#else\n\t  emit_tsi(as, MIPSI_SD, RID_RET, RID_SP, ofs);\n#endif\n\t}\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)get_kval(as, func);\n  } else {  /* Need specific register for indirect calls. */\n    Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR));\n    MCode *p = as->mcp;\n    if (r == RID_CFUNCADDR)\n      *--p = MIPSI_NOP;\n    else\n      *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r);\n    *--p = MIPSI_JALR | MIPSF_S(r);\n    as->mcp = p;\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n#if !LJ_SOFTFP\nstatic void asm_callround(ASMState *as, IRIns *ir, IRCallID id)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)|\n\t\tRID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR)\n#if LJ_TARGET_MIPSR6\n\t\t|RID2RSET(RID_F21)\n#endif\n\t\t;\n  if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);\n  ra_evictset(as, drop);\n  ra_destreg(as, ir, RID_FPRET);\n  emit_call(as, (void *)lj_ir_callinfo[id].func, 0);\n  ra_leftov(as, REGARG_FIRSTFPR, ir->op1);\n}\n#endif\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guard(as, MIPSI_BNE, RID_TMP,\n\t    ra_allock(as, igcptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_tsi(as, MIPSI_AL, RID_TMP, base, -8);\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n  IRIns irgc;\n  irgc.ot = IRT(0, IRT_PGC);  /* GC type. */\n  emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L));\n  if ((as->flags & JIT_F_MIPSXXR2)) {\n    emit_tsml(as, LJ_64 ? MIPSI_DINS : MIPSI_INS, RID_TMP, tmp,\n\t      lj_fls(SBUF_MASK_FLAG), 0);\n  } else {\n    emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp);\n    emit_tsi(as, MIPSI_ANDI, tmp, tmp, SBUF_MASK_FLAG);\n  }\n  emit_getgl(as, RID_TMP, cur_L);\n  emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n}\n#endif\n\n/* -- Type conversions ---------------------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n#if !LJ_TARGET_MIPSR6\n  asm_guard(as, MIPSI_BC1F, 0, 0);\n  emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left);\n#else\n  asm_guard(as, MIPSI_BC1EQZ, 0, (tmp&31));\n  emit_fgh(as, MIPSI_CMP_EQ_D, tmp, tmp, left);\n#endif\n  emit_fg(as, MIPSI_CVT_D_W, tmp, tmp);\n  emit_tg(as, MIPSI_MFC1, dest, tmp);\n  emit_fg(as, MIPSI_CVT_W_D, tmp, left);\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  emit_tg(as, MIPSI_MFC1, dest, tmp);\n  emit_fgh(as, MIPSI_ADD_D, tmp, left, right);\n}\n#elif LJ_64  /* && LJ_SOFTFP */\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg r)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RID2RSET(REGARG_FIRSTGPR)|RID2RSET(RID_RET)|RID2RSET(RID_RET+1)|\n\t\tRID2RSET(RID_R1)|RID2RSET(RID_R12);\n  if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);\n  ra_evictset(as, drop);\n  /* Return values are in RID_RET (converted value) and RID_RET+1 (status). */\n  ra_destreg(as, ir, RID_RET);\n  asm_guard(as, MIPSI_BNE, RID_RET+1, RID_ZERO);\n  emit_call(as, (void *)lj_ir_callinfo[IRCALL_lj_vm_tointg].func, 0);\n  if (r == RID_NONE)\n    ra_leftov(as, REGARG_FIRSTGPR, ir->op1);\n  else if (r != REGARG_FIRSTGPR)\n    emit_move(as, REGARG_FIRSTGPR, r);\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_dta(as, MIPSI_SLL, dest, dest, 0);\n  asm_callid(as, ir, IRCALL_lj_vm_tobit);\n}\n#endif\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if !LJ_SOFTFP32\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n#endif\n#if LJ_64\n  int st64 = (st == IRT_I64 || st == IRT_U64 || st == IRT_P64);\n#endif\n  IRRef lref = ir->op1;\n#if LJ_32\n  /* 64 bit integer conversions are handled by SPLIT. */\n  lj_assertA(!(irt_isint64(ir->t) || (st == IRT_I64 || st == IRT_U64)),\n\t     \"IR %04d has unsplit 64 bit type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n#endif\n#if LJ_SOFTFP32\n  /* FP conversions are handled by SPLIT. */\n  lj_assertA(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT),\n\t     \"IR %04d has FP type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n  /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */\n#else\n  lj_assertA(irt_type(ir->t) != st, \"inconsistent types for CONV\");\n#if !LJ_SOFTFP\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S,\n\t      dest, ra_alloc1(as, lref, RSET_FPR));\n    } else if (st == IRT_U32) {  /* U32 to FP conversion. */\n      /* y = (x ^ 0x8000000) + 2147483648.0 */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      if (irt_isfloat(ir->t))\n\temit_fg(as, MIPSI_CVT_S_D, dest, dest);\n      /* Must perform arithmetic with doubles to keep the precision. */\n      emit_fgh(as, MIPSI_ADD_D, dest, dest, tmp);\n      emit_fg(as, MIPSI_CVT_D_W, dest, dest);\n      emit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t (void *)&as->J->k64[LJ_K64_2P31], RSET_GPR);\n      emit_tg(as, MIPSI_MTC1, RID_TMP, dest);\n      emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left);\n      emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);\n#if LJ_64\n    } else if(st == IRT_U64) {  /* U64 to FP conversion. */\n      /* if (x >= 1u<<63) y = (double)(int64_t)(x&(1u<<63)-1) + pow(2.0, 63) */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      MCLabel l_end = emit_label(as);\n      if (irt_isfloat(ir->t)) {\n\temit_fgh(as, MIPSI_ADD_S, dest, dest, tmp);\n\temit_lsptr(as, MIPSI_LWC1, (tmp & 31), (void *)&as->J->k32[LJ_K32_2P63],\n\t\t   rset_exclude(RSET_GPR, left));\n\temit_fg(as, MIPSI_CVT_S_L, dest, dest);\n      } else {\n\temit_fgh(as, MIPSI_ADD_D, dest, dest, tmp);\n\temit_lsptr(as, MIPSI_LDC1, (tmp & 31), (void *)&as->J->k64[LJ_K64_2P63],\n\t\t   rset_exclude(RSET_GPR, left));\n\temit_fg(as, MIPSI_CVT_D_L, dest, dest);\n      }\n      emit_branch(as, MIPSI_BGEZ, left, RID_ZERO, l_end);\n      emit_tg(as, MIPSI_DMTC1, RID_TMP, dest);\n      emit_tsml(as, MIPSI_DEXTM, RID_TMP, left, 30, 0);\n#endif\n    } else {  /* Integer to FP conversion. */\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n#if LJ_32\n      emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,\n\t      dest, dest);\n      emit_tg(as, MIPSI_MTC1, left, dest);\n#else\n      MIPSIns mi = irt_isfloat(ir->t) ?\n\t(st64 ? MIPSI_CVT_S_L : MIPSI_CVT_S_W) :\n\t(st64 ? MIPSI_CVT_D_L : MIPSI_CVT_D_W);\n      emit_fg(as, mi, dest, dest);\n      emit_tg(as, st64 ? MIPSI_DMTC1 : MIPSI_MTC1, left, dest);\n#endif\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      if (irt_isu32(ir->t)) {  /* FP to U32 conversion. */\n\t/* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */\n\temit_dst(as, MIPSI_XOR, dest, dest, RID_TMP);\n\temit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D,\n\t\ttmp, tmp);\n\temit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D,\n\t\t tmp, left, tmp);\n\tif (st == IRT_FLOAT)\n\t  emit_lsptr(as, MIPSI_LWC1, (tmp & 31),\n\t\t     (void *)&as->J->k32[LJ_K32_2P31], RSET_GPR);\n\telse\n\t  emit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t     (void *)&as->J->k64[LJ_K64_2P31], RSET_GPR);\n#if LJ_64\n      } else if (irt_isu64(ir->t)) {  /* FP to U64 conversion. */\n\tMCLabel l_end;\n\temit_tg(as, MIPSI_DMFC1, dest, tmp);\n\tl_end = emit_label(as);\n\t/* For inputs >= 2^63 add -2^64 and convert again. */\n\tif (st == IRT_NUM) {\n\t  emit_fg(as, MIPSI_TRUNC_L_D, tmp, tmp);\n\t  emit_fgh(as, MIPSI_ADD_D, tmp, left, tmp);\n\t  emit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t     (void *)&as->J->k64[LJ_K64_M2P64],\n\t\t     rset_exclude(RSET_GPR, dest));\n\t  emit_fg(as, MIPSI_TRUNC_L_D, tmp, left);  /* Delay slot. */\n#if !LJ_TARGET_MIPSR6\n\t emit_branch(as, MIPSI_BC1T, 0, 0, l_end);\n\t emit_fgh(as, MIPSI_C_OLT_D, 0, left, tmp);\n#else\n\t emit_branch(as, MIPSI_BC1NEZ, 0, (left&31), l_end);\n\t emit_fgh(as, MIPSI_CMP_LT_D, left, left, tmp);\n#endif\n\t  emit_lsptr(as, MIPSI_LDC1, (tmp & 31),\n\t\t     (void *)&as->J->k64[LJ_K64_2P63],\n\t\t     rset_exclude(RSET_GPR, dest));\n\t} else {\n\t  emit_fg(as, MIPSI_TRUNC_L_S, tmp, tmp);\n\t  emit_fgh(as, MIPSI_ADD_S, tmp, left, tmp);\n\t  emit_lsptr(as, MIPSI_LWC1, (tmp & 31),\n\t\t     (void *)&as->J->k32[LJ_K32_M2P64],\n\t\t     rset_exclude(RSET_GPR, dest));\n\t  emit_fg(as, MIPSI_TRUNC_L_S, tmp, left);  /* Delay slot. */\n#if !LJ_TARGET_MIPSR6\n\t emit_branch(as, MIPSI_BC1T, 0, 0, l_end);\n\t emit_fgh(as, MIPSI_C_OLT_S, 0, left, tmp);\n#else\n\t emit_branch(as, MIPSI_BC1NEZ, 0, (left&31), l_end);\n\t emit_fgh(as, MIPSI_CMP_LT_S, left, left, tmp);\n#endif\n\t  emit_lsptr(as, MIPSI_LWC1, (tmp & 31),\n\t\t     (void *)&as->J->k32[LJ_K32_2P63],\n\t\t     rset_exclude(RSET_GPR, dest));\n\t}\n#endif\n      } else {\n#if LJ_32\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D,\n\t\ttmp, left);\n#else\n\tMIPSIns mi = irt_is64(ir->t) ?\n\t  (st == IRT_NUM ? MIPSI_TRUNC_L_D : MIPSI_TRUNC_L_S) :\n\t  (st == IRT_NUM ? MIPSI_TRUNC_W_D : MIPSI_TRUNC_W_S);\n\temit_tg(as, irt_is64(ir->t) ? MIPSI_DMFC1 : MIPSI_MFC1, dest, left);\n\temit_fg(as, mi, left, left);\n#endif\n      }\n    }\n  } else\n#else\n  if (irt_isfp(ir->t)) {\n#if LJ_64 && LJ_HASFFI\n    if (stfp) {  /* FP to FP conversion. */\n      asm_callid(as, ir, irt_isnum(ir->t) ? IRCALL_softfp_f2d :\n\t\t\t\t\t    IRCALL_softfp_d2f);\n    } else {  /* Integer to FP conversion. */\n      IRCallID cid = ((IRT_IS64 >> st) & 1) ?\n\t(irt_isnum(ir->t) ?\n\t (st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d) :\n\t (st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f)) :\n\t(irt_isnum(ir->t) ?\n\t (st == IRT_INT ? IRCALL_softfp_i2d : IRCALL_softfp_ui2d) :\n\t (st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f));\n      asm_callid(as, ir, cid);\n    }\n#else\n    asm_callid(as, ir, IRCALL_softfp_i2d);\n#endif\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, RID_NONE);\n    } else {\n      IRCallID cid = irt_is64(ir->t) ?\n\t((st == IRT_NUM) ?\n\t (irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul) :\n\t (irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul)) :\n\t((st == IRT_NUM) ?\n\t (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) :\n\t (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui));\n      asm_callid(as, ir, cid);\n    }\n  } else\n#endif\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n      lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), \"bad type for CONV EXT\");\n      if ((ir->op2 & IRCONV_SEXT)) {\n\tif (LJ_64 || (as->flags & JIT_F_MIPSXXR2)) {\n\t  emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left);\n\t} else {\n\t  uint32_t shift = st == IRT_I8 ? 24 : 16;\n\t  emit_dta(as, MIPSI_SRA, dest, dest, shift);\n\t  emit_dta(as, MIPSI_SLL, dest, left, shift);\n\t}\n      } else {\n\temit_tsi(as, MIPSI_ANDI, dest, left,\n\t\t (int32_t)(st == IRT_U8 ? 0xff : 0xffff));\n      }\n    } else {  /* 32/64 bit integer conversions. */\n#if LJ_32\n      /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n#else\n      if (irt_is64(ir->t)) {\n\tif (st64) {\n\t  /* 64/64 bit no-op (cast)*/\n\t  ra_leftov(as, dest, lref);\n\t} else {\n\t  Reg left = ra_alloc1(as, lref, RSET_GPR);\n\t  if ((ir->op2 & IRCONV_SEXT)) {  /* 32 to 64 bit sign extension. */\n\t    emit_dta(as, MIPSI_SLL, dest, left, 0);\n\t  } else {  /* 32 to 64 bit zero extension. */\n\t    emit_tsml(as, MIPSI_DEXT, dest, left, 31, 0);\n\t  }\n\t}\n      } else {\n\tif (st64 && !(ir->op2 & IRCONV_NONE)) {\n\t  /* This is either a 32 bit reg/reg mov which zeroes the hiword\n\t  ** or a load of the loword from a 64 bit address.\n\t  */\n\t  Reg left = ra_alloc1(as, lref, RSET_GPR);\n\t  emit_tsml(as, MIPSI_DEXT, dest, left, 31, 0);\n\t} else {  /* 32/32 bit no-op (cast). */\n\t  /* Do nothing, but may need to move regs. */\n\t  ra_leftov(as, dest, lref);\n\t}\n      }\n#endif\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  int32_t ofs = 0;\n#if LJ_SOFTFP32\n  ra_evictset(as, RSET_SCRATCH);\n  if (ra_used(ir)) {\n    if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&\n\t(ir->s & 1) == LJ_BE && (ir->s ^ 1) == (ir+1)->s) {\n      int i;\n      for (i = 0; i < 2; i++) {\n\tReg r = (ir+i)->r;\n\tif (ra_hasreg(r)) {\n\t  ra_free(as, r);\n\t  ra_modified(as, r);\n\t  emit_spload(as, ir+i, r, sps_scale((ir+i)->s));\n\t}\n      }\n      ofs = sps_scale(ir->s & ~1);\n    } else {\n      Reg rhi = ra_dest(as, ir+1, RSET_GPR);\n      Reg rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));\n      emit_tsi(as, MIPSI_LW, rhi, RID_SP, ofs+(LJ_BE?0:4));\n      emit_tsi(as, MIPSI_LW, rlo, RID_SP, ofs+(LJ_BE?4:0));\n    }\n  }\n#else\n  RegSet drop = RSET_SCRATCH;\n  if (ra_hasreg(ir->r)) rset_set(drop, ir->r);  /* Spill dest reg (if any). */\n  ra_evictset(as, drop);\n  ofs = sps_scale(ir->s);\n#endif\n  asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  emit_tsi(as, MIPSI_AADDIU, ra_releasetmp(as, ASMREF_TMP1),\n\t   RID_SP, ofs);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n#if LJ_64\n/* Store tagged value for ref at base+ofs. */\nstatic void asm_tvstore64(ASMState *as, Reg base, int32_t ofs, IRRef ref)\n{\n  RegSet allow = rset_exclude(RSET_GPR, base);\n  IRIns *ir = IR(ref);\n  lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t),\n\t     \"store of IR type %d\", irt_type(ir->t));\n  if (irref_isk(ref)) {\n    TValue k;\n    lj_ir_kvalue(as->J->L, &k, ir);\n    emit_tsi(as, MIPSI_SD, ra_allock(as, (int64_t)k.u64, allow), base, ofs);\n  } else {\n    Reg src = ra_alloc1(as, ref, allow);\n    Reg type = ra_allock(as, (int64_t)irt_toitype(ir->t) << 47,\n\t\t\t rset_exclude(allow, src));\n    emit_tsi(as, MIPSI_SD, RID_TMP, base, ofs);\n    if (irt_isinteger(ir->t)) {\n      emit_dst(as, MIPSI_DADDU, RID_TMP, RID_TMP, type);\n      emit_tsml(as, MIPSI_DEXT, RID_TMP, src, 31, 0);\n    } else {\n      emit_dst(as, MIPSI_DADDU, RID_TMP, src, type);\n    }\n  }\n}\n#endif\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode)\n{\n  int32_t tmpofs = (int32_t)(offsetof(global_State, tmptv)-32768);\n  if ((mode & IRTMPREF_IN1)) {\n    IRIns *ir = IR(ref);\n    if (irt_isnum(ir->t)) {\n      if ((mode & IRTMPREF_OUT1)) {\n#if LJ_SOFTFP\n\temit_tsi(as, MIPSI_AADDIU, dest, RID_JGL, tmpofs);\n#if LJ_64\n\temit_setgl(as, ra_alloc1(as, ref, RSET_GPR), tmptv.u64);\n#else\n\tlj_assertA(irref_isk(ref), \"unsplit FP op\");\n\temit_setgl(as,\n\t\t   ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, RSET_GPR),\n\t\t   tmptv.u32.lo);\n\temit_setgl(as,\n\t\t   ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, RSET_GPR),\n\t\t   tmptv.u32.hi);\n#endif\n#else\n\tReg src = ra_alloc1(as, ref, RSET_FPR);\n\temit_tsi(as, MIPSI_AADDIU, dest, RID_JGL, tmpofs);\n\temit_tsi(as, MIPSI_SDC1, (src & 31),  RID_JGL, tmpofs);\n#endif\n      } else if (irref_isk(ref)) {\n\t/* Use the number constant itself as a TValue. */\n\tra_allockreg(as, igcptr(ir_knum(ir)), dest);\n      } else {\n#if LJ_SOFTFP32\n\tlj_assertA(0, \"unsplit FP op\");\n#else\n\t/* Otherwise force a spill and use the spill slot. */\n\temit_tsi(as, MIPSI_AADDIU, dest, RID_SP, ra_spill(as, ir));\n#endif\n      }\n    } else {\n      /* Otherwise use g->tmptv to hold the TValue. */\n#if LJ_32\n      Reg type;\n      emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, tmpofs);\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, RSET_GPR);\n\temit_setgl(as, src, tmptv.gcr);\n      }\n      if (LJ_SOFTFP && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t))\n\ttype = ra_alloc1(as, ref+1, RSET_GPR);\n      else\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), RSET_GPR);\n      emit_setgl(as, type, tmptv.it);\n#else\n      asm_tvstore64(as, dest, 0, ref);\n      emit_tsi(as, MIPSI_DADDIU, dest, RID_JGL, tmpofs);\n#endif\n    }\n  } else {\n    emit_tsi(as, MIPSI_AADDIU, dest, RID_JGL, tmpofs);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    ofs += 8*IR(ir->op2)->i;\n    if (checki16(ofs)) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_tsi(as, MIPSI_AADDIU, dest, base, ofs);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n#if !LJ_TARGET_MIPSR6\n  emit_dst(as, MIPSI_AADDU, dest, RID_TMP, base);\n  emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3);\n#else\n  emit_dst(as, MIPSI_ALSA | MIPSF_A(3-1), dest, idx, base);\n#endif\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2;\n#if LJ_64\n  Reg cmp64 = RID_NONE;\n#endif\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  int isk = irref_isk(refkey);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  rset_clear(allow, tab);\n  if (!LJ_SOFTFP && irt_isnum(kt)) {\n    key = ra_alloc1(as, refkey, RSET_FPR);\n    tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));\n  } else {\n    if (!irt_ispri(kt)) {\n      key = ra_alloc1(as, refkey, allow);\n      rset_clear(allow, key);\n    }\n#if LJ_32\n    if (LJ_SOFTFP && irkey[1].o == IR_HIOP) {\n      if (ra_hasreg((irkey+1)->r)) {\n\ttype = tmpnum = (irkey+1)->r;\n\ttmp1 = ra_scratch(as, allow);\n\trset_clear(allow, tmp1);\n\tra_noweak(as, tmpnum);\n      } else {\n\ttype = tmpnum = ra_allocref(as, refkey+1, allow);\n      }\n      rset_clear(allow, tmpnum);\n    } else {\n      type = ra_allock(as, (int32_t)irt_toitype(kt), allow);\n      rset_clear(allow, type);\n    }\n#endif\n  }\n  tmp2 = ra_scratch(as, allow);\n  rset_clear(allow, tmp2);\n#if LJ_64\n  if (LJ_SOFTFP || !irt_isnum(kt)) {\n    /* Allocate cmp64 register used for 64-bit comparisons */\n    if (LJ_SOFTFP && irt_isnum(kt)) {\n      cmp64 = key;\n    } else if (!isk && irt_isaddr(kt)) {\n      cmp64 = tmp2;\n    } else {\n      int64_t k;\n      if (isk && irt_isaddr(kt)) {\n\tk = ((int64_t)irt_toitype(kt) << 47) | irkey[1].tv.u64;\n      } else {\n\tlj_assertA(irt_ispri(kt) && !irt_isnil(kt), \"bad HREF key type\");\n\tk = ~((int64_t)~irt_toitype(kt) << 47);\n      }\n      cmp64 = ra_allock(as, k, allow);\n      rset_clear(allow, cmp64);\n    }\n  }\n#endif\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guard(as, MIPSI_B, RID_ZERO, RID_ZERO);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n  /* Follow hash chain until the end. */\n  emit_move(as, dest, tmp1);\n  l_loop = --as->mcp;\n  emit_tsi(as, MIPSI_AL, tmp1, dest, (int32_t)offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ) {  /* Must match asm_guard(). */\n    emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);\n    l_end = asm_exitstub_addr(as);\n  }\n  if (!LJ_SOFTFP && irt_isnum(kt)) {\n#if !LJ_TARGET_MIPSR6\n    emit_branch(as, MIPSI_BC1T, 0, 0, l_end);\n    emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key);\n#else\n    emit_branch(as, MIPSI_BC1NEZ, 0, (tmpnum&31), l_end);\n    emit_fgh(as, MIPSI_CMP_EQ_D, tmpnum, tmpnum, key);\n#endif\n    *--as->mcp = MIPSI_NOP;  /* Avoid NaN comparison overhead. */\n    emit_branch(as, MIPSI_BEQ, tmp1, RID_ZERO, l_next);\n    emit_tsi(as, MIPSI_SLTIU, tmp1, tmp1, (int32_t)LJ_TISNUM);\n#if LJ_32\n    emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n));\n  } else {\n    if (irt_ispri(kt)) {\n      emit_branch(as, MIPSI_BEQ, tmp1, type, l_end);\n    } else {\n      emit_branch(as, MIPSI_BEQ, tmp2, key, l_end);\n      emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.gcr));\n      emit_branch(as, MIPSI_BNE, tmp1, type, l_next);\n    }\n  }\n  emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.it));\n  *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu);\n#else\n    emit_dta(as, MIPSI_DSRA32, tmp1, tmp1, 15);\n    emit_tg(as, MIPSI_DMTC1, tmp1, tmpnum);\n    emit_tsi(as, MIPSI_LD, tmp1, dest, (int32_t)offsetof(Node, key.u64));\n  } else {\n    emit_branch(as, MIPSI_BEQ, tmp1, cmp64, l_end);\n    emit_tsi(as, MIPSI_LD, tmp1, dest, (int32_t)offsetof(Node, key.u64));\n  }\n  *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu);\n  if (!isk && irt_isaddr(kt)) {\n    type = ra_allock(as, (int64_t)irt_toitype(kt) << 47, allow);\n    emit_dst(as, MIPSI_DADDU, tmp2, key, type);\n    rset_clear(allow, type);\n  }\n#endif\n\n  /* Load main position relative to tab->node into dest. */\n  khash = isk ? ir_khash(as, irkey) : 1;\n  if (khash == 0) {\n    emit_tsi(as, MIPSI_AL, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    Reg tmphash = tmp1;\n    if (isk)\n      tmphash = ra_allock(as, khash, allow);\n    emit_dst(as, MIPSI_AADDU, dest, dest, tmp1);\n    lj_assertA(sizeof(Node) == 24, \"bad Node size\");\n    emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1);\n    emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3);\n    emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5);\n    emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash);\n    emit_tsi(as, MIPSI_AL, dest, tab, (int32_t)offsetof(GCtab, node));\n    emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask));\n    if (isk) {\n      /* Nothing to do. */\n    } else if (irt_isstr(kt)) {\n      emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, sid));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2);\n      emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31);\n      emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2);\n      emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31);\n      emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest);\n#if LJ_32\n      if (LJ_SOFTFP ? (irkey[1].o == IR_HIOP) : irt_isnum(kt)) {\n\temit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1);\n\tif ((as->flags & JIT_F_MIPSXXR2)) {\n\t  emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31);\n\t} else {\n\t  emit_dst(as, MIPSI_OR, dest, dest, tmp1);\n\t  emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1);\n\t  emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31);\n\t}\n\temit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1);\n#if LJ_SOFTFP\n\temit_ds(as, MIPSI_MOVE, tmp1, type);\n\temit_ds(as, MIPSI_MOVE, tmp2, key);\n#else\n\temit_tg(as, MIPSI_MFC1, tmp2, key);\n\temit_tg(as, MIPSI_MFC1, tmp1, key+1);\n#endif\n      } else {\n\temit_dst(as, MIPSI_XOR, tmp2, key, tmp1);\n\temit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31);\n\temit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow));\n      }\n#else\n      emit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1);\n      emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31);\n      if (irt_isnum(kt)) {\n\temit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1);\n\temit_dta(as, MIPSI_DSRA32, tmp1, LJ_SOFTFP ? key : tmp1, 0);\n\temit_dta(as, MIPSI_SLL, tmp2, LJ_SOFTFP ? key : tmp1, 0);\n#if !LJ_SOFTFP\n\temit_tg(as, MIPSI_DMFC1, tmp1, key);\n#endif\n      } else {\n\tcheckmclim(as);\n\temit_dta(as, MIPSI_DSRA32, tmp1, tmp1, 0);\n\temit_dta(as, MIPSI_SLL, tmp2, key, 0);\n\temit_dst(as, MIPSI_DADDU, tmp1, key, type);\n      }\n#endif\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  Reg idx = node;\n#if LJ_32\n  Reg key = RID_NONE, type = RID_TMP;\n  int32_t lo, hi;\n#else\n  Reg key = ra_scratch(as, allow);\n  int64_t k;\n#endif\n  lj_assertA(ofs % sizeof(Node) == 0, \"unaligned HREFK slot\");\n  if (ofs > 32736) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_tsi(as, MIPSI_AADDIU, dest, node, ofs);\n  }\n#if LJ_32\n  if (!irt_ispri(irkey->t)) {\n    key = ra_scratch(as, allow);\n    rset_clear(allow, key);\n  }\n  if (irt_isnum(irkey->t)) {\n    lo = (int32_t)ir_knum(irkey)->u32.lo;\n    hi = (int32_t)ir_knum(irkey)->u32.hi;\n  } else {\n    lo = irkey->i;\n    hi = irt_toitype(irkey->t);\n    if (!ra_hasreg(key))\n      goto nolo;\n  }\n  asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO);\nnolo:\n  asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO);\n  if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0));\n  emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4));\n#else\n  if (irt_ispri(irkey->t)) {\n    lj_assertA(!irt_isnil(irkey->t), \"bad HREFK key type\");\n    k = ~((int64_t)~irt_toitype(irkey->t) << 47);\n  } else if (irt_isnum(irkey->t)) {\n    k = (int64_t)ir_knum(irkey)->u64;\n  } else {\n    k = ((int64_t)irt_toitype(irkey->t) << 47) | (int64_t)ir_kgc(irkey);\n  }\n  asm_guard(as, MIPSI_BNE, key, ra_allock(as, k, allow));\n  emit_tsi(as, MIPSI_LD, key, idx, kofs);\n#endif\n  if (ofs > 32736)\n    emit_tsi(as, MIPSI_AADDU, dest, node, ra_allock(as, ofs, allow));\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, MIPSI_AL, dest, v, RSET_GPR);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_tsi(as, MIPSI_AADDIU, dest, uv, (int32_t)offsetof(GCupval, tv));\n      emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_tsi(as, MIPSI_AL, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_tsi(as, MIPSI_AL, uv, func, (int32_t)offsetof(GCfuncL, uvptr) +\n\t     (int32_t)sizeof(MRef) * (int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lj_assertA(!ra_used(ir), \"unfused FREF\");\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n#if LJ_32\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  int32_t ofs = (int32_t)sizeof(GCstr);\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       checki16(ofs + IR(irr->op2)->i)) {\n      ofs += IR(irr->op2)->i;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs);\n    emit_dst(as, MIPSI_ADDU, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  ofs += IR(refk)->i;\n  if (checki16(ofs))\n    emit_tsi(as, MIPSI_ADDIU, dest, r, ofs);\n  else\n    emit_dst(as, MIPSI_ADDU, dest, r,\n\t     ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));\n#else\n  RegSet allow = RSET_GPR;\n  Reg dest = ra_dest(as, ir, allow);\n  Reg base = ra_alloc1(as, ir->op1, allow);\n  IRIns *irr = IR(ir->op2);\n  int32_t ofs = sizeof(GCstr);\n  rset_clear(allow, base);\n  if (irref_isk(ir->op2) && checki16(ofs + irr->i)) {\n    emit_tsi(as, MIPSI_DADDIU, dest, base, ofs + irr->i);\n  } else {\n    emit_tsi(as, MIPSI_DADDIU, dest, dest, ofs);\n    emit_dst(as, MIPSI_DADDU, dest, base, ra_alloc1(as, ir->op2, allow));\n  }\n#endif\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic MIPSIns asm_fxloadins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return MIPSI_LB;\n  case IRT_U8: return MIPSI_LBU;\n  case IRT_I16: return MIPSI_LH;\n  case IRT_U16: return MIPSI_LHU;\n  case IRT_NUM:\n    lj_assertA(!LJ_SOFTFP32, \"unsplit FP op\");\n    if (!LJ_SOFTFP) return MIPSI_LDC1;\n  /* fallthrough */\n  case IRT_FLOAT: if (!LJ_SOFTFP) return MIPSI_LWC1;\n  /* fallthrough */\n  default: return (LJ_64 && irt_is64(ir->t)) ? MIPSI_LD : MIPSI_LW;\n  }\n}\n\nstatic MIPSIns asm_fxstoreins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return MIPSI_SB;\n  case IRT_I16: case IRT_U16: return MIPSI_SH;\n  case IRT_NUM:\n    lj_assertA(!LJ_SOFTFP32, \"unsplit FP op\");\n    if (!LJ_SOFTFP) return MIPSI_SDC1;\n  /* fallthrough */\n  case IRT_FLOAT: if (!LJ_SOFTFP) return MIPSI_SWC1;\n  /* fallthrough */\n  default: return (LJ_64 && irt_is64(ir->t)) ? MIPSI_SD : MIPSI_SW;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  MIPSIns mi = asm_fxloadins(as, ir);\n  Reg idx;\n  int32_t ofs;\n  if (ir->op1 == REF_NIL) {  /* FLOAD from GG_State with offset. */\n    idx = RID_JGL;\n    ofs = (ir->op2 << 2) - 32768 - GG_OFS(g);\n  } else {\n    idx = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->op2 == IRFL_TAB_ARRAY) {\n      ofs = asm_fuseabase(as, ir->op1);\n      if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n\temit_tsi(as, MIPSI_AADDIU, dest, idx, ofs);\n\treturn;\n      }\n    }\n    ofs = field_ofs[ir->op2];\n  }\n  lj_assertA(!irt_isfp(ir->t), \"bad FP FLOAD\");\n  emit_tsi(as, mi, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1z(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    MIPSIns mi = asm_fxstoreins(as, ir);\n    lj_assertA(!irt_isfp(ir->t), \"bad FP FSTORE\");\n    emit_tsi(as, mi, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir,\n    (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n  lj_assertA(LJ_TARGET_UNALIGNED || !(ir->op2 & IRXLOAD_UNALIGNED),\n\t     \"unaligned XLOAD\");\n  asm_fusexref(as, asm_fxloadins(as, ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1z(as, ir->op2,\n      (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(as, ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  int hiop = (LJ_SOFTFP32 && (ir+1)->o == IR_HIOP);\n  Reg dest = RID_NONE, type = RID_TMP, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = 0;\n  IRType1 t = ir->t;\n  if (hiop) {\n    t.irt = IRT_NUM;\n    if (ra_used(ir+1)) {\n      type = ra_dest(as, ir+1, allow);\n      rset_clear(allow, type);\n    }\n  }\n  if (ra_used(ir)) {\n    lj_assertA((LJ_SOFTFP32 ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t),\n\t       \"bad load type %d\", irt_type(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && irt_isnum(t)) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n#if LJ_64\n    if (irt_isaddr(t))\n      emit_tsml(as, MIPSI_DEXTM, dest, dest, 14, 0);\n    else if (irt_isint(t))\n      emit_dta(as, MIPSI_SLL, dest, dest, 0);\n#endif\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (ir->o == IR_VLOAD) ofs += 8 * ir->op2;\n  rset_clear(allow, idx);\n  if (irt_isnum(t)) {\n    asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n    emit_tsi(as, MIPSI_SLTIU, RID_TMP, type, (int32_t)LJ_TISNUM);\n  } else {\n    asm_guard(as, MIPSI_BNE, type,\n\t      ra_allock(as, (int32_t)irt_toitype(t), allow));\n  }\n#if LJ_32\n  if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && irt_isnum(t))\n      emit_hsi(as, MIPSI_LDC1, dest, idx, ofs);\n    else\n      emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0));\n  }\n  emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4));\n#else\n  if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && irt_isnum(t)) {\n      emit_hsi(as, MIPSI_LDC1, dest, idx, ofs);\n      dest = type;\n    }\n  } else {\n    dest = type;\n  }\n  emit_dta(as, MIPSI_DSRA32, type, dest, 15);\n  emit_tsi(as, MIPSI_LD, dest, idx, ofs);\n#endif\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg idx, src = RID_NONE, type = RID_NONE;\n  int32_t ofs = 0;\n  if (ir->r == RID_SINK)\n    return;\n  if (!LJ_SOFTFP32 && irt_isnum(ir->t)) {\n    src = ra_alloc1(as, ir->op2, LJ_SOFTFP ? RSET_GPR : RSET_FPR);\n    idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n    emit_hsi(as, LJ_SOFTFP ? MIPSI_SD : MIPSI_SDC1, src, idx, ofs);\n  } else {\n#if LJ_32\n    if (!irt_ispri(ir->t)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n    }\n    if (LJ_SOFTFP && (ir+1)->o == IR_HIOP)\n      type = ra_alloc1(as, (ir+1)->op2, allow);\n    else\n      type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n    rset_clear(allow, type);\n    idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n    if (ra_hasreg(src))\n      emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0));\n    emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4));\n#else\n    Reg tmp = RID_TMP;\n    if (irt_ispri(ir->t)) {\n      tmp = ra_allock(as, ~((int64_t)~irt_toitype(ir->t) << 47), allow);\n      rset_clear(allow, tmp);\n    } else {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n      type = ra_allock(as, (int64_t)irt_toitype(ir->t) << 47, allow);\n      rset_clear(allow, type);\n    }\n    idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n    emit_tsi(as, MIPSI_SD, tmp, idx, ofs);\n    if (ra_hasreg(src)) {\n      if (irt_isinteger(ir->t)) {\n\temit_dst(as, MIPSI_DADDU, tmp, tmp, type);\n\temit_tsml(as, MIPSI_DEXT, tmp, src, 31, 0);\n      } else {\n\temit_dst(as, MIPSI_DADDU, tmp, src, type);\n      }\n    }\n#endif\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  IRType1 t = ir->t;\n#if LJ_32\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  int hiop = (LJ_SOFTFP32 && (ir+1)->o == IR_HIOP);\n  if (hiop)\n    t.irt = IRT_NUM;\n#else\n  int32_t ofs = 8*((int32_t)ir->op1-2);\n#endif\n  lj_assertA(!(ir->op2 & IRSLOAD_PARENT),\n\t     \"bad parent SLOAD\");  /* Handled by asm_head_side(). */\n  lj_assertA(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK),\n\t     \"inconsistent SLOAD variant\");\n#if LJ_SOFTFP32\n  lj_assertA(!(ir->op2 & IRSLOAD_CONVERT),\n\t     \"unsplit SLOAD convert\");  /* Handled by LJ_SOFTFP SPLIT. */\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n#else\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    dest = ra_scratch(as, LJ_SOFTFP ? allow : RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n  } else\n#endif\n  if (ra_used(ir)) {\n    lj_assertA((LJ_SOFTFP32 ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t),\n\t       \"bad SLOAD type %d\", irt_type(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && irt_isnum(t)) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    rset_clear(allow, base);\n    if (!LJ_SOFTFP32 && (ir->op2 & IRSLOAD_CONVERT)) {\n      if (irt_isint(t)) {\n\tReg tmp = ra_scratch(as, LJ_SOFTFP ? RSET_GPR : RSET_FPR);\n#if LJ_SOFTFP\n\tra_evictset(as, rset_exclude(RSET_SCRATCH, dest));\n\tra_destreg(as, ir, RID_RET);\n\temit_call(as, (void *)lj_ir_callinfo[IRCALL_softfp_d2i].func, 0);\n\tif (tmp != REGARG_FIRSTGPR)\n\t  emit_move(as, REGARG_FIRSTGPR, tmp);\n#else\n\temit_tg(as, MIPSI_MFC1, dest, tmp);\n\temit_fg(as, MIPSI_TRUNC_W_D, tmp, tmp);\n#endif\n\tdest = tmp;\n\tt.irt = IRT_NUM;  /* Check for original type. */\n      } else {\n\tReg tmp = ra_scratch(as, RSET_GPR);\n#if LJ_SOFTFP\n\tra_evictset(as, rset_exclude(RSET_SCRATCH, dest));\n\tra_destreg(as, ir, RID_RET);\n\temit_call(as, (void *)lj_ir_callinfo[IRCALL_softfp_i2d].func, 0);\n\temit_dta(as, MIPSI_SLL, REGARG_FIRSTGPR, tmp, 0);\n#else\n\temit_fg(as, MIPSI_CVT_D_W, dest, dest);\n\temit_tg(as, MIPSI_MTC1, tmp, dest);\n#endif\n\tdest = tmp;\n\tt.irt = IRT_INT;  /* Check for original type. */\n      }\n    }\n#if LJ_64\n    else if (irt_isaddr(t)) {\n      /* Clear type from pointers. */\n      emit_tsml(as, MIPSI_DEXTM, dest, dest, 14, 0);\n    } else if (irt_isint(t) && (ir->op2 & IRSLOAD_TYPECHECK)) {\n      /* Sign-extend integers. */\n      emit_dta(as, MIPSI_SLL, dest, dest, 0);\n    }\n#endif\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\n  rset_clear(allow, base);\ndotypecheck:\n#if LJ_32\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    if (ra_noreg(type))\n      type = RID_TMP;\n    if (irt_isnum(t)) {\n      asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_tsi(as, MIPSI_SLTIU, RID_TMP, type, (int32_t)LJ_TISNUM);\n    } else {\n      Reg ktype = ra_allock(as, irt_toitype(t), allow);\n      asm_guard(as, MIPSI_BNE, type, ktype);\n    }\n  }\n  if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && irt_isnum(t))\n      emit_hsi(as, MIPSI_LDC1, dest, base, ofs);\n    else\n      emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0));\n  }\n  if (ra_hasreg(type))\n    emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4));\n#else\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    type = dest < RID_MAX_GPR ? dest : RID_TMP;\n    if (irt_ispri(t)) {\n      asm_guard(as, MIPSI_BNE, type,\n\t\tra_allock(as, ~((int64_t)~irt_toitype(t) << 47) , allow));\n    } else {\n      if (irt_isnum(t)) {\n\tasm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);\n\temit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)LJ_TISNUM);\n\tif (!LJ_SOFTFP && ra_hasreg(dest))\n\t  emit_hsi(as, MIPSI_LDC1, dest, base, ofs);\n      } else {\n\tasm_guard(as, MIPSI_BNE, RID_TMP,\n\t\t  ra_allock(as, (int32_t)irt_toitype(t), allow));\n      }\n      emit_dta(as, MIPSI_DSRA32, RID_TMP, type, 15);\n    }\n    emit_tsi(as, MIPSI_LD, type, base, ofs);\n  } else if (ra_hasreg(dest)) {\n    if (!LJ_SOFTFP && irt_isnum(t))\n      emit_hsi(as, MIPSI_LDC1, dest, base, ofs);\n    else\n      emit_tsi(as, irt_isint(t) ? MIPSI_LW : MIPSI_LD, dest, base,\n\t       ofs ^ ((LJ_BE && irt_isint(t)) ? 4 : 0));\n  }\n#endif\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet drop = RSET_SCRATCH;\n  lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),\n\t     \"bad CNEW/CNEWI operands\");\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n#if LJ_32\n    int32_t ofs = sizeof(GCcdata);\n    if (sz == 8) {\n      ofs += 4;\n      lj_assertA((ir+1)->o == IR_HIOP, \"expected HIOP for CNEWI\");\n      if (LJ_LE) ir++;\n    }\n    for (;;) {\n      Reg r = ra_alloc1z(as, ir->op2, allow);\n      emit_tsi(as, MIPSI_SW, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; if (LJ_BE) ir++; else ir--;\n    }\n#else\n    emit_tsi(as, sz == 8 ? MIPSI_SD : MIPSI_SW, ra_alloc1(as, ir->op2, allow),\n\t     RID_RET, sizeof(GCcdata));\n#endif\n    lj_assertA(sz == 4 || sz == 8, \"bad CNEWI size %d\", sz);\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));\n  emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));\n  emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA);\n  emit_ti(as, MIPSI_LI, RID_TMP, id); /* Lower 16 bit used. Sign-ext ok. */\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg link = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_tsi(as, MIPSI_AS, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_setgl(as, tab, gc.grayagain);\n  emit_getgl(as, link, gc.grayagain);\n  emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP);  /* Clear black bit. */\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK);\n  emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lj_assertA(IR(ir->op1)->o == IR_UREFC, \"bad OBAR type\");\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_tsi(as, MIPSI_AADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK);\n  emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_tsi(as, MIPSI_LBU, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  emit_fgh(as, mi, dest, left, right);\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_fg(as, mi, dest, left);\n}\n#endif\n\n#if !LJ_SOFTFP32\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (ir->op2 <= IRFPM_TRUNC)\n    asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);\n  else if (ir->op2 == IRFPM_SQRT)\n    asm_fpunary(as, ir, MIPSI_SQRT_D);\n  else\n#endif\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n#endif\n\n#if !LJ_SOFTFP\n#define asm_fpadd(as, ir)\tasm_fparith(as, ir, MIPSI_ADD_D)\n#define asm_fpsub(as, ir)\tasm_fparith(as, ir, MIPSI_SUB_D)\n#define asm_fpmul(as, ir)\tasm_fparith(as, ir, MIPSI_MUL_D)\n#elif LJ_64  /* && LJ_SOFTFP */\n#define asm_fpadd(as, ir)\tasm_callid(as, ir, IRCALL_softfp_add)\n#define asm_fpsub(as, ir)\tasm_callid(as, ir, IRCALL_softfp_sub)\n#define asm_fpmul(as, ir)\tasm_callid(as, ir, IRCALL_softfp_mul)\n#endif\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n  IRType1 t = ir->t;\n#if !LJ_SOFTFP32\n  if (irt_isnum(t)) {\n    asm_fpadd(as, ir);\n  } else\n#endif\n  {\n    /* TODO MIPSR6: Fuse ADD(BSHL(a,1-4),b) or ADD(ADD(a,a),b) to MIPSI_ALSA. */\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    if (irref_isk(ir->op2)) {\n      intptr_t k = get_kval(as, ir->op2);\n      if (checki16(k)) {\n\temit_tsi(as, (LJ_64 && irt_is64(t)) ? MIPSI_DADDIU : MIPSI_ADDIU, dest,\n\t\t left, k);\n\treturn;\n      }\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_dst(as, (LJ_64 && irt_is64(t)) ? MIPSI_DADDU : MIPSI_ADDU, dest,\n\t     left, right);\n  }\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP32\n  if (irt_isnum(ir->t)) {\n    asm_fpsub(as, ir);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    emit_dst(as, (LJ_64 && irt_is64(ir->t)) ? MIPSI_DSUBU : MIPSI_SUBU, dest,\n\t     left, right);\n  }\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP32\n  if (irt_isnum(ir->t)) {\n    asm_fpmul(as, ir);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (LJ_64 && irt_is64(ir->t)) {\n#if !LJ_TARGET_MIPSR6\n      emit_dst(as, MIPSI_MFLO, dest, 0, 0);\n      emit_dst(as, MIPSI_DMULT, 0, left, right);\n#else\n      emit_dst(as, MIPSI_DMUL, dest, left, right);\n#endif\n    } else {\n      emit_dst(as, MIPSI_MUL, dest, left, right);\n    }\n  }\n}\n\n#if !LJ_SOFTFP32\nstatic void asm_fpdiv(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n    asm_fparith(as, ir, MIPSI_DIV_D);\n#else\n    asm_callid(as, ir, IRCALL_softfp_div);\n#endif\n}\n#endif\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, MIPSI_NEG_D);\n  } else\n#elif LJ_64  /* && LJ_SOFTFP */\n  if (irt_isnum(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    emit_dst(as, MIPSI_XOR, dest, left,\n\t    ra_allock(as, 0x8000000000000000ll, rset_exclude(RSET_GPR, dest)));\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    emit_dst(as, (LJ_64 && irt_is64(ir->t)) ? MIPSI_DSUBU : MIPSI_SUBU, dest,\n\t     RID_ZERO, left);\n  }\n}\n\n#if !LJ_SOFTFP\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, MIPSI_ABS_D)\n#elif LJ_64   /* && LJ_SOFTFP */\nstatic void asm_abs(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_tsml(as, MIPSI_DEXTM, dest, left, 30, 0);\n}\n#endif\n\nstatic void asm_arithov(ASMState *as, IRIns *ir)\n{\n  /* TODO MIPSR6: bovc/bnvc. Caveat: no delay slot to load RID_TMP. */\n  Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);\n  lj_assertA(!irt_is64(ir->t), \"bad usage\");\n  if (irref_isk(ir->op2)) {\n    int k = IR(ir->op2)->i;\n    if (ir->o == IR_SUBOV) k = -k;\n    if (checki16(k)) {  /* (dest < left) == (k >= 0 ? 1 : 0) */\n      left = ra_alloc1(as, ir->op1, RSET_GPR);\n      asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      if (dest == left) emit_move(as, RID_TMP, left);\n      return;\n    }\n  }\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),\n\t\t\t\t\t\t right), dest));\n  asm_guard(as, MIPSI_BLTZ, RID_TMP, 0);\n  emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp);\n  if (ir->o == IR_ADDOV) {  /* ((dest^left) & (dest^right)) < 0 */\n    emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right);\n  } else {  /* ((dest^left) & (dest^~right)) < 0 */\n    emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest);\n    emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO);\n  }\n  emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left);\n  emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right);\n  if (dest == left || dest == right)\n    emit_move(as, RID_TMP, dest == left ? left : right);\n}\n\n#define asm_addov(as, ir)\tasm_arithov(as, ir)\n#define asm_subov(as, ir)\tasm_arithov(as, ir)\n\nstatic void asm_mulov(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),\n\t\t\t\t\t\t right), dest));\n  asm_guard(as, MIPSI_BNE, RID_TMP, tmp);\n  emit_dta(as, MIPSI_SRA, RID_TMP, dest, 31);\n#if !LJ_TARGET_MIPSR6\n  emit_dst(as, MIPSI_MFHI, tmp, 0, 0);\n  emit_dst(as, MIPSI_MFLO, dest, 0, 0);\n  emit_dst(as, MIPSI_MULT, 0, left, right);\n#else\n  emit_dst(as, MIPSI_MUL, dest, left, right);\n  emit_dst(as, MIPSI_MUH, tmp, left, right);\n#endif\n}\n\n#if LJ_32 && LJ_HASFFI\nstatic void asm_add64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0) {\n      emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP);\n      goto loarith;\n    } else if (checki16(k)) {\n      emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      goto loarith;\n    }\n  }\n  emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_dst(as, MIPSI_ADDU, dest, left, right);\nloarith:\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0) {\n      if (dest != left)\n\temit_move(as, dest, left);\n      return;\n    } else if (checki16(k)) {\n      if (dest == left) {\n\tReg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left));\n\temit_move(as, dest, tmp);\n\tdest = tmp;\n      }\n      emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left);\n      emit_tsi(as, MIPSI_ADDIU, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  if (dest == left && dest == right) {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n    emit_move(as, dest, tmp);\n    dest = tmp;\n  }\n  emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left);\n  emit_dst(as, MIPSI_ADDU, dest, left, right);\n}\n\nstatic void asm_sub64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);\n  emit_dst(as, MIPSI_SUBU, dest, left, right);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (dest == left) {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n    emit_move(as, dest, tmp);\n    dest = tmp;\n  }\n  emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest);\n  emit_dst(as, MIPSI_SUBU, dest, left, right);\n}\n\nstatic void asm_neg64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);\n  emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest);\n  emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);\n}\n#endif\n\nstatic void asm_bnot(ASMState *as, IRIns *ir)\n{\n  Reg left, right, dest = ra_dest(as, ir, RSET_GPR);\n  IRIns *irl = IR(ir->op1);\n  if (mayfuse(as, ir->op1) && irl->o == IR_BOR) {\n    left = ra_alloc2(as, irl, RSET_GPR);\n    right = (left >> 8); left &= 255;\n  } else {\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    right = RID_ZERO;\n  }\n  emit_dst(as, MIPSI_NOR, dest, left, right);\n}\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n#if LJ_32\n  if ((as->flags & JIT_F_MIPSXXR2)) {\n    emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16);\n    emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left);\n  } else {\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest));\n    emit_dst(as, MIPSI_OR, dest, dest, tmp);\n    emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);\n    emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00);\n    emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8);\n    emit_dta(as, MIPSI_SRL, dest, left, 8);\n    emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00);\n    emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP);\n    emit_dta(as, MIPSI_SRL, tmp, left, 24);\n    emit_dta(as, MIPSI_SLL, RID_TMP, left, 24);\n  }\n#else\n  if (irt_is64(ir->t)) {\n    emit_dst(as, MIPSI_DSHD, dest, 0, RID_TMP);\n    emit_dst(as, MIPSI_DSBH, RID_TMP, 0, left);\n  } else {\n    emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16);\n    emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left);\n  }\n#endif\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    intptr_t k = get_kval(as, ir->op2);\n    if (checku16(k)) {\n      emit_tsi(as, mik, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_dst(as, mi, dest, left, right);\n}\n\n#define asm_band(as, ir)\tasm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI)\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, MIPSI_OR, MIPSI_ORI)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    uint32_t shift = (uint32_t)IR(ir->op2)->i;\n    if (LJ_64 && irt_is64(ir->t)) mik |= (shift & 32) ? MIPSI_D32 : MIPSI_D;\n    emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR),\n\t     (shift & 31));\n  } else {\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (LJ_64 && irt_is64(ir->t)) mi |= MIPSI_DV;\n    emit_dst(as, mi, dest, right, left);  /* Shift amount is in rs. */\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA)\n#define asm_brol(as, ir)\tlj_assertA(0, \"unexpected BROL\")\n\nstatic void asm_bror(ASMState *as, IRIns *ir)\n{\n  if (LJ_64 || (as->flags & JIT_F_MIPSXXR2)) {\n    asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (irref_isk(ir->op2)) {  /* Constant shifts. */\n      uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);\n      Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n      emit_rotr(as, dest, left, RID_TMP, shift);\n    } else {\n      Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n      right = (left >> 8); left &= 255;\n      emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);\n      emit_dst(as, MIPSI_SRLV, dest, right, left);\n      emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left);\n      emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right);\n    }\n  }\n}\n\n#if LJ_SOFTFP\nstatic void asm_sfpmin_max(ASMState *as, IRIns *ir)\n{\n  CCallInfo ci = lj_ir_callinfo[(IROp)ir->o == IR_MIN ? IRCALL_lj_vm_sfmin : IRCALL_lj_vm_sfmax];\n#if LJ_64\n  IRRef args[2];\n  args[0] = ir->op1;\n  args[1] = ir->op2;\n#else\n  IRRef args[4];\n  args[0^LJ_BE] = ir->op1;\n  args[1^LJ_BE] = (ir+1)->op1;\n  args[2^LJ_BE] = ir->op2;\n  args[3^LJ_BE] = (ir+1)->op2;\n#endif\n  asm_setupresult(as, ir, &ci);\n  emit_call(as, (void *)ci.func, 0);\n  ci.func = NULL;\n  asm_gencall(as, &ci, args);\n}\n#endif\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int ismax)\n{\n  if (!LJ_SOFTFP32 && irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n    asm_sfpmin_max(as, ir);\n#else\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n#if !LJ_TARGET_MIPSR6\n    if (dest == left) {\n      emit_fg(as, MIPSI_MOVF_D, dest, right);\n    } else {\n      emit_fg(as, MIPSI_MOVT_D, dest, left);\n      if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right);\n    }\n    emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? right : left, ismax ? left : right);\n#else\n    emit_fgh(as, ismax ? MIPSI_MAX_D : MIPSI_MIN_D, dest, left, right);\n#endif\n#endif\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (left == right) {\n      if (dest != left) emit_move(as, dest, left);\n    } else {\n#if !LJ_TARGET_MIPSR6\n      if (dest == left) {\n\temit_dst(as, MIPSI_MOVN, dest, right, RID_TMP);\n      } else {\n\temit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP);\n\tif (dest != right) emit_move(as, dest, right);\n      }\n#else\n      emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);\n      if (dest != right) {\n\temit_dst(as, MIPSI_SELNEZ, RID_TMP, right, RID_TMP);\n\temit_dst(as, MIPSI_SELEQZ, dest, left, RID_TMP);\n      } else {\n\temit_dst(as, MIPSI_SELEQZ, RID_TMP, left, RID_TMP);\n\temit_dst(as, MIPSI_SELNEZ, dest, right, RID_TMP);\n      }\n#endif\n      emit_dst(as, MIPSI_SLT, RID_TMP,\n\t       ismax ? left : right, ismax ? right : left);\n    }\n  }\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, 0)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, 1)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n#if LJ_SOFTFP\n/* SFP comparisons. */\nstatic void asm_sfpcomp(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n#if LJ_64\n  IRRef args[2];\n  args[0] = ir->op1;\n  args[1] = ir->op2;\n#else\n  IRRef args[4];\n  args[LJ_LE ? 0 : 1] = ir->op1; args[LJ_LE ? 1 : 0] = (ir+1)->op1;\n  args[LJ_LE ? 2 : 3] = ir->op2; args[LJ_LE ? 3 : 2] = (ir+1)->op2;\n#endif\n\n  for (r = REGARG_FIRSTGPR; r <= REGARG_FIRSTGPR+(LJ_64?1:3); r++) {\n    if (!rset_test(as->freeset, r) &&\n\tregcost_ref(as->cost[r]) == args[r-REGARG_FIRSTGPR])\n      rset_clear(drop, r);\n  }\n  ra_evictset(as, drop);\n\n  asm_setupresult(as, ir, ci);\n\n  switch ((IROp)ir->o) {\n  case IR_LT:\n    asm_guard(as, MIPSI_BGEZ, RID_RET, 0);\n    break;\n  case IR_ULT:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 1);\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO);\n    break;\n  case IR_GE:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 2);\n    asm_guard(as, MIPSI_BLTZ, RID_RET, 0);\n    break;\n  case IR_LE:\n    asm_guard(as, MIPSI_BGTZ, RID_RET, 0);\n    break;\n  case IR_GT:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 2);\n    asm_guard(as, MIPSI_BLEZ, RID_RET, 0);\n    break;\n  case IR_UGE:\n    asm_guard(as, MIPSI_BLTZ, RID_RET, 0);\n    break;\n  case IR_ULE:\n    asm_guard(as, MIPSI_BEQ, RID_RET, RID_TMP);\n    emit_loadi(as, RID_TMP, 1);\n    break;\n  case IR_UGT: case IR_ABC:\n    asm_guard(as, MIPSI_BLEZ, RID_RET, 0);\n    break;\n  case IR_EQ: case IR_NE:\n    asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_RET, RID_ZERO);\n  default:\n    break;\n  }\n  asm_gencall(as, ci, args);\n}\n#endif\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  /* ORDER IR: LT GE LE GT  ULT UGE ULE UGT. */\n  IROp op = ir->o;\n  if (!LJ_SOFTFP32 && irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n    asm_sfpcomp(as, ir);\n#else\n#if !LJ_TARGET_MIPSR6\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);\n    emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right);\n#else\n    Reg tmp, right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_FPR, left), right));\n    asm_guard(as, (op&1) ? MIPSI_BC1NEZ : MIPSI_BC1EQZ, 0, (tmp&31));\n    emit_fgh(as, MIPSI_CMP_LT_D + ((op&3) ^ ((op>>2)&1)), tmp, left, right);\n#endif\n#endif\n  } else {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (op == IR_ABC) op = IR_UGT;\n    if ((op&4) == 0 && irref_isk(ir->op2) && get_kval(as, ir->op2) == 0) {\n      MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) :\n\t\t\t    ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ);\n      asm_guard(as, mi, left, 0);\n    } else {\n      if (irref_isk(ir->op2)) {\n\tintptr_t k = get_kval(as, ir->op2);\n\tif ((op&2)) k++;\n\tif (checki16(k)) {\n\t  asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n\t  emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI,\n\t\t   RID_TMP, left, k);\n\t  return;\n\t}\n      }\n      right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n      asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n      emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT,\n\t       RID_TMP, (op&2) ? right : left, (op&2) ? left : right);\n    }\n  }\n}\n\nstatic void asm_equal(ASMState *as, IRIns *ir)\n{\n  Reg right, left = ra_alloc2(as, ir, (!LJ_SOFTFP && irt_isnum(ir->t)) ?\n\t\t\t\t       RSET_FPR : RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (!LJ_SOFTFP32 && irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n    asm_sfpcomp(as, ir);\n#elif !LJ_TARGET_MIPSR6\n    asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);\n    emit_fgh(as, MIPSI_C_EQ_D, 0, left, right);\n#else\n    Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_FPR, left), right));\n    asm_guard(as, (ir->o & 1) ? MIPSI_BC1NEZ : MIPSI_BC1EQZ, 0, (tmp&31));\n    emit_fgh(as, MIPSI_CMP_EQ_D, tmp, left, right);\n#endif\n  } else {\n    asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right);\n  }\n}\n\n#if LJ_32 && LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_comp64(ASMState *as, IRIns *ir)\n{\n  /* ORDER IR: LT GE LE GT  ULT UGE ULE UGT. */\n  IROp op = (ir-1)->o;\n  MCLabel l_end;\n  Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR);\n  righthi = (lefthi >> 8); lefthi &= 255;\n  leftlo = ra_alloc2(as, ir-1,\n\t\t     rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi));\n  rightlo = (leftlo >> 8); leftlo &= 255;\n  asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);\n  l_end = emit_label(as);\n  if (lefthi != righthi)\n    emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP,\n\t     (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi);\n  emit_dst(as, MIPSI_SLTU, RID_TMP,\n\t   (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo);\n  if (lefthi != righthi)\n    emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end);\n}\n\nstatic void asm_comp64eq(ASMState *as, IRIns *ir)\n{\n  Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO);\n  tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));\n  emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp);\n  emit_dst(as, MIPSI_XOR, tmp, left, right);\n  left = ra_alloc2(as, ir-1, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  emit_dst(as, MIPSI_XOR, RID_TMP, left, right);\n}\n#endif\n\n/* -- Split register ops -------------------------------------------------- */\n\n/* Hiword op of a split 32/32 or 64/64 bit op. Previous op is the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n#if LJ_32 && (LJ_HASFFI || LJ_SOFTFP)\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n#if LJ_HASFFI && !LJ_SOFTFP\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n#endif\n  } else if ((ir-1)->o < IR_EQ) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_comp64(as, ir);\n#endif\n    return;\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_comp64eq(as, ir);\n#endif\n    return;\n#if LJ_SOFTFP\n  } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {\n      as->curins--;  /* Always skip the loword min/max. */\n    if (uselo || usehi)\n      asm_sfpmin_max(as, ir-1);\n    return;\n#endif\n  } else if ((ir-1)->o == IR_XSTORE) {\n    as->curins--;  /* Handle both stores here. */\n    if ((ir-1)->r != RID_SINK) {\n      asm_xstore_(as, ir, LJ_LE ? 4 : 0);\n      asm_xstore_(as, ir-1, LJ_LE ? 0 : 4);\n    }\n    return;\n  }\n#endif\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_32 && LJ_HASFFI\n  case IR_ADD: as->curins--; asm_add64(as, ir); break;\n  case IR_SUB: as->curins--; asm_sub64(as, ir); break;\n  case IR_NEG: as->curins--; asm_neg64(as, ir); break;\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n#if LJ_32 && LJ_SOFTFP\n  case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n  case IR_STRTO:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RSET_GPR);  /* Mark lo op as used. */\n    break;\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: case IR_TMPREF:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  default: lj_assertA(0, \"bad HIOP for op %d\", (ir-1)->o); break;\n  }\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);\n  emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, HOOK_PROFILE);\n  emit_lsglptr(as, MIPSI_LBU, RID_TMP,\n\t       (int32_t)offsetof(global_State, hookmask));\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */\n  Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;\n  ExitNo oldsnap = as->snapno;\n  rset_clear(allow, pbase);\n#if LJ_32\n  tmp = allow ? rset_pickbot(allow) :\n\t\t(pbase == RID_RETHI ? RID_RETLO : RID_RETHI);\n#else\n  tmp = allow ? rset_pickbot(allow) : RID_RET;\n#endif\n  as->snapno = exitno;\n  asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);\n  as->snapno = oldsnap;\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_tsi(as, MIPSI_AL, tmp, RID_SP, 0);\n  else\n    ra_modified(as, tmp);\n  emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot));\n  emit_dst(as, MIPSI_ASUBU, RID_TMP, tmp, pbase);\n  emit_tsi(as, MIPSI_AL, tmp, tmp, offsetof(lua_State, maxstack));\n  if (pbase == RID_TMP)\n    emit_getgl(as, RID_TMP, jit_base);\n  emit_getgl(as, tmp, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_tsi(as, MIPSI_AS, tmp, RID_SP, 0);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n#if LJ_32 || defined(LUA_USE_ASSERT)\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1-LJ_FR2];\n#endif\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1-LJ_FR2);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n#if LJ_SOFTFP32\n      Reg tmp;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      /* LJ_SOFTFP: must be a number constant. */\n      lj_assertA(irref_isk(ref), \"unsplit FP op\");\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, allow);\n      emit_tsi(as, MIPSI_SW, tmp, RID_BASE, ofs+(LJ_BE?4:0));\n      if (rset_test(as->freeset, tmp+1)) allow = RID2RSET(tmp+1);\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, allow);\n      emit_tsi(as, MIPSI_SW, tmp, RID_BASE, ofs+(LJ_BE?0:4));\n#elif LJ_SOFTFP  /* && LJ_64 */\n      Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));\n      emit_tsi(as, MIPSI_SD, src, RID_BASE, ofs);\n#else\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs);\n#endif\n    } else {\n#if LJ_32\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      Reg type;\n      lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t),\n\t\t \"restore of IR type %d\", irt_type(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, allow);\n\trset_clear(allow, src);\n\temit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0));\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), allow);\n#if LJ_SOFTFP\n      } else if ((sn & SNAP_SOFTFPNUM)) {\n\ttype = ra_alloc1(as, ref+1, rset_exclude(RSET_GPR, RID_BASE));\n#endif\n      } else if ((sn & SNAP_KEYINDEX)) {\n\ttype = ra_allock(as, (int32_t)LJ_KEYINDEX, allow);\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      }\n      emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4));\n#else\n      asm_tvstore64(as, RID_BASE, ofs, ref);\n#endif\n    }\n    checkmclim(as);\n  }\n  lj_assertA(map + nent == flinks, \"inconsistent frames in snapshot\");\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Marker to prevent patching the GC check exit. */\n#define MIPS_NOPATCH_GC_CHECK\tMIPSI_OR\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  /* Assumes asm_snap_prep() already done. */\n  asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  l_end[-3] = MIPS_NOPATCH_GC_CHECK;  /* Replace the nop after the call. */\n  emit_tsi(as, MIPSI_AADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  tmp = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end);\n  emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp);\n  emit_getgl(as, tmp, gc.threshold);\n  emit_getgl(as, RID_TMP, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  p[-1] = MIPSI_NOP;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guard already inverted the cond branch. Only patch the target. */\n    p[-3] |= ((target-p+2) & 0x0000ffffu);\n  } else {\n    p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n  }\n}\n\n/* Fixup the tail of the loop. */\nstatic void asm_loop_tail_fixup(ASMState *as)\n{\n  if (as->loopinv) as->mctop--;\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_move(as, r, RID_BASE);\n  }\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      rset_clear(allow, irp->r);\n      emit_move(as, r, irp->r);  /* Move from coalesced parent reg. */\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  int32_t spadj = as->T->spadjust;\n  MCode *p = as->mctop-1;\n  *p = spadj ? (MIPSI_AADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP;\n  p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  as->mcp = as->mctop-2;  /* Leave room for branch plus nop or stack adj. */\n  as->invmcp = as->loopref ? as->mcp : NULL;\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n#if LJ_32\n  int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n#else\n  int nslots = 0, ngpr = REGARG_NUMGPR;\n#endif\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++) {\n#if LJ_32\n    if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t) &&\n\tnfpr > 0 && !(ci->flags & CCI_VARARG)) {\n      nfpr--;\n      ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1;\n    } else if (!LJ_SOFTFP && args[i] && irt_isnum(IR(args[i])->t)) {\n      nfpr = 0;\n      ngpr = ngpr & ~1;\n      if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1;\n    } else {\n      nfpr = 0;\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n#else\n    if (ngpr > 0) ngpr--; else nslots += 2;\n#endif\n  }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_sparejump_setup(as);\n  asm_exitstub_setup(as);\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *px = exitstub_trace_addr(T, exitno);\n  MCode *cstart = NULL, *cstop = NULL;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno;\n  MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);\n  for (p++; p < pe; p++) {\n    if (*p == exitload) {  /* Look for load of exit number. */\n      /* Look for exitstub branch. Yes, this covers all used branch variants. */\n      if (((p[-1] ^ (px-p)) & 0xffffu) == 0 &&\n\t  ((p[-1] & 0xf0000000u) == MIPSI_BEQ ||\n\t   (p[-1] & 0xfc1e0000u) == MIPSI_BLTZ ||\n#if !LJ_TARGET_MIPSR6\n\t   (p[-1] & 0xffe00000u) == MIPSI_BC1F\n#else\n\t   (p[-1] & 0xff600000u) == MIPSI_BC1EQZ\n#endif\n\t  ) && p[-2] != MIPS_NOPATCH_GC_CHECK) {\n\tptrdiff_t delta = target - p;\n\tif (((delta + 0x8000) >> 16) == 0) {  /* Patch in-range branch. */\n\tpatchbranch:\n\t  p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu);\n\t  *p = MIPSI_NOP;  /* Replace the load of the exit number. */\n\t  cstop = p+1;\n\t  if (!cstart) cstart = p-1;\n\t} else {  /* Branch out of range. Use spare jump slot in mcarea. */\n\t  MCode *mcjump = asm_sparejump_use(mcarea, tjump);\n\t  if (mcjump) {\n\t    lj_mcode_sync(mcjump, mcjump+1);\n\t    delta = mcjump - p;\n\t    if (((delta + 0x8000) >> 16) == 0) {\n\t      goto patchbranch;\n\t    } else {\n\t      lj_assertJ(0, \"spare jump out of range: -Osizemcode too big\");\n\t    }\n\t  }\n\t  /* Ignore jump slot overflow. Child trace is simply not attached. */\n\t}\n      } else if (p+1 == pe) {\n\t/* Patch NOP after code for inverted loop branch. Use of J is ok. */\n\tlj_assertJ(p[1] == MIPSI_NOP, \"expected NOP\");\n\tp[1] = tjump;\n\t*p = MIPSI_NOP;  /* Replace the load of the exit number. */\n\tcstop = p+2;\n\tif (!cstart) cstart = p+1;\n      }\n    }\n  }\n  if (cstart) lj_mcode_sync(cstart, cstop);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm_ppc.h",
    "content": "/*\n** PPC IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Register allocator extensions --------------------------------------- */\n\n/* Allocate a register with a hint. */\nstatic Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)\n{\n  Reg r = IR(ref)->r;\n  if (ra_noreg(r)) {\n    if (!ra_hashint(r) && !iscrossref(as, ref))\n      ra_sethint(IR(ref)->r, hint);  /* Propagate register hint. */\n    r = ra_allocref(as, ref, allow);\n  }\n  ra_noweak(as, r);\n  return r;\n}\n\n/* Allocate two source registers for three-operand instructions. */\nstatic Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n  Reg left = irl->r, right = irr->r;\n  if (ra_hasreg(left)) {\n    ra_noweak(as, left);\n    if (ra_noreg(right))\n      right = ra_allocref(as, ir->op2, rset_exclude(allow, left));\n    else\n      ra_noweak(as, right);\n  } else if (ra_hasreg(right)) {\n    ra_noweak(as, right);\n    left = ra_allocref(as, ir->op1, rset_exclude(allow, right));\n  } else if (ra_hashint(right)) {\n    right = ra_allocref(as, ir->op2, allow);\n    left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));\n  } else {\n    left = ra_allocref(as, ir->op1, allow);\n    right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));\n  }\n  return left | (right << 8);\n}\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Setup exit stubs after the end of each trace. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  MCode *mxp = as->mctop;\n  if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim)\n    asm_mclimit(as);\n  /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */\n  for (i = nexits-1; (int32_t)i >= 0; i--)\n    *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2);\n  *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno;  /* Read by exit handler. */\n  mxp--;\n  *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2);\n  *--mxp = PPCI_MFLR|PPCF_T(RID_TMP);\n  as->mctop = mxp;\n}\n\nstatic MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno)\n{\n  /* Keep this in-sync with exitstub_trace_addr(). */\n  return as->mctop + exitno + 3;\n}\n\n/* Emit conditional branch to exit for guard. */\nstatic void asm_guardcc(ASMState *as, PPCCC cc)\n{\n  MCode *target = asm_exitstub_addr(as, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2);\n    emit_condbranch(as, PPCI_BC, cc^4, p);\n    return;\n  }\n  emit_condbranch(as, PPCI_BC, cc, target);\n}\n\n/* -- Operand fusion ------------------------------------------------------ */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if there's no conflicting instruction between curins and ref. */\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref)\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse the array base of colocated arrays. */\nstatic int32_t asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&\n      !neverfuse(as) && noconflict(as, ref, IR_NEWREF))\n    return (int32_t)sizeof(GCtab);\n  return 0;\n}\n\n/* Indicates load/store indexed is ok. */\n#define AHUREF_LSX\t((int32_t)0x80000000)\n\n/* Fuse array/hash/upvalue reference into register+offset operand. */\nstatic Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    if (ir->o == IR_AREF) {\n      if (mayfuse(as, ref)) {\n\tif (irref_isk(ir->op2)) {\n\t  IRRef tab = IR(ir->op1)->op1;\n\t  int32_t ofs = asm_fuseabase(as, tab);\n\t  IRRef refa = ofs ? tab : ir->op1;\n\t  ofs += 8*IR(ir->op2)->i;\n\t  if (checki16(ofs)) {\n\t    *ofsp = ofs;\n\t    return ra_alloc1(as, refa, allow);\n\t  }\n\t}\n\tif (*ofsp == AHUREF_LSX) {\n\t  Reg base = ra_alloc1(as, ir->op1, allow);\n\t  Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n\t  return base | (idx << 8);\n\t}\n      }\n    } else if (ir->o == IR_HREFK) {\n      if (mayfuse(as, ref)) {\n\tint32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tif (checki16(ofs)) {\n\t  *ofsp = ofs;\n\t  return ra_alloc1(as, ir->op1, allow);\n\t}\n      }\n    } else if (ir->o == IR_UREFC) {\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tint32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);\n\tint32_t jgl = (intptr_t)J2G(as->J);\n\tif ((uint32_t)(ofs-jgl) < 65536) {\n\t  *ofsp = ofs-jgl-32768;\n\t  return RID_JGL;\n\t} else {\n\t  *ofsp = (int16_t)ofs;\n\t  return ra_allock(as, ofs-(int16_t)ofs, allow);\n\t}\n      }\n    } else if (ir->o == IR_TMPREF) {\n      *ofsp = (int32_t)(offsetof(global_State, tmptv)-32768);\n      return RID_JGL;\n    }\n  }\n  *ofsp = 0;\n  return ra_alloc1(as, ref, allow);\n}\n\n/* Fuse XLOAD/XSTORE reference into load/store operand. */\nstatic void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref,\n\t\t\t RegSet allow, int32_t ofs)\n{\n  IRIns *ir = IR(ref);\n  Reg base;\n  if (ra_noreg(ir->r) && canfuse(as, ir)) {\n    if (ir->o == IR_ADD) {\n      int32_t ofs2;\n      if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {\n\tofs = ofs2;\n\tref = ir->op1;\n      } else if (ofs == 0) {\n\tReg right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\temit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);\n\treturn;\n      }\n    } else if (ir->o == IR_STRREF) {\n      lj_assertA(ofs == 0, \"bad usage\");\n      ofs = (int32_t)sizeof(GCstr);\n      if (irref_isk(ir->op2)) {\n\tofs += IR(ir->op2)->i;\n\tref = ir->op1;\n      } else if (irref_isk(ir->op1)) {\n\tofs += IR(ir->op1)->i;\n\tref = ir->op2;\n      } else {\n\t/* NYI: Fuse ADD with constant. */\n\tReg tmp, right, left = ra_alloc2(as, ir, allow);\n\tright = (left >> 8); left &= 255;\n\ttmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right));\n\temit_fai(as, pi, rt, tmp, ofs);\n\temit_tab(as, PPCI_ADD, tmp, left, right);\n\treturn;\n      }\n      if (!checki16(ofs)) {\n\tReg left = ra_alloc1(as, ref, allow);\n\tReg right = ra_allock(as, ofs, rset_exclude(allow, left));\n\temit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);\n\treturn;\n      }\n    }\n  }\n  base = ra_alloc1(as, ref, allow);\n  emit_fai(as, pi, rt, base, ofs);\n}\n\n/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */\nstatic void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref,\n\t\t\t  RegSet allow)\n{\n  IRIns *ira = IR(ref);\n  Reg right, left;\n  if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) {\n    left = ra_alloc2(as, ira, allow);\n    right = (left >> 8); left &= 255;\n  } else {\n    right = ra_alloc1(as, ref, allow);\n    left = RID_R0;\n  }\n  emit_tab(as, pi, rt, left, right);\n}\n\n#if !LJ_SOFTFP\n/* Fuse to multiply-add/sub instruction. */\nstatic int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir)\n{\n  IRRef lref = ir->op1, rref = ir->op2;\n  IRIns *irm;\n  if (lref != rref &&\n      ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&\n\tra_noreg(irm->r)) ||\n       (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&\n\t(rref = lref, pi = pir, ra_noreg(irm->r))))) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg add = ra_alloc1(as, rref, RSET_FPR);\n    Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add));\n    right = (left >> 8); left &= 255;\n    emit_facb(as, pi, dest, left, right, add);\n    return 1;\n  }\n  return 0;\n}\n#endif\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = 8;\n  Reg gpr = REGARG_FIRSTGPR;\n#if !LJ_SOFTFP\n  Reg fpr = REGARG_FIRSTFPR;\n#endif\n  if ((void *)ci->func)\n    emit_call(as, (void *)ci->func);\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    if (ref) {\n      IRIns *ir = IR(ref);\n#if !LJ_SOFTFP\n      if (irt_isfp(ir->t)) {\n\tif (fpr <= REGARG_LASTFPR) {\n\t  lj_assertA(rset_test(as->freeset, fpr),\n\t\t     \"reg %d not free\", fpr);  /* Already evicted. */\n\t  ra_leftov(as, fpr, ref);\n\t  fpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_FPR);\n\t  if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += irt_isnum(ir->t) ? 8 : 4;\n\t}\n      } else\n#endif\n      {\n\tif (gpr <= REGARG_LASTGPR) {\n\t  lj_assertA(rset_test(as->freeset, gpr),\n\t\t     \"reg %d not free\", gpr);  /* Already evicted. */\n\t  ra_leftov(as, gpr, ref);\n\t  gpr++;\n\t} else {\n\t  Reg r = ra_alloc1(as, ref, RSET_GPR);\n\t  emit_spstore(as, ir, r, ofs);\n\t  ofs += 4;\n\t}\n      }\n    } else {\n      if (gpr <= REGARG_LASTGPR)\n\tgpr++;\n      else\n\tofs += 4;\n    }\n    checkmclim(as);\n  }\n#if !LJ_SOFTFP\n  if ((ci->flags & CCI_VARARG))  /* Vararg calls need to know about FPR use. */\n    emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6);\n#endif\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n#if !LJ_SOFTFP\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n#endif\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    lj_assertA(!irt_ispri(ir->t), \"PRI dest\");\n    if (!LJ_SOFTFP && irt_isfp(ir->t)) {\n      if ((ci->flags & CCI_CASTU64)) {\n\t/* Use spill slot or temp slots. */\n\tint32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n\t  emit_fai(as, PPCI_LFD, dest, RID_SP, ofs);\n\t}\n\temit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs);\n\temit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      ra_destreg(as, ir, RID_RET);\n    }\n  }\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  if (irref_isk(func)) {  /* Call to constant address. */\n    ci.func = (ASMFunction)(void *)(intptr_t)(irf->i);\n  } else {  /* Need a non-argument register for indirect calls. */\n    RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);\n    Reg freg = ra_alloc1(as, func, allow);\n    *--as->mcp = PPCI_BCTRL;\n    *--as->mcp = PPCI_MTCTR | PPCF_T(freg);\n    ci.func = (ASMFunction)(void *)0;\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n  emit_ab(as, PPCI_CMPW, RID_TMP,\n\t  ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));\n  emit_tai(as, PPCI_LWZ, RID_TMP, base, -8);\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n  IRIns irgc;\n  irgc.ot = IRT(0, IRT_PGC);  /* GC type. */\n  emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L));\n  emit_rot(as, PPCI_RLWIMI, RID_TMP, tmp, 0, 31-lj_fls(SBUF_MASK_FLAG), 31);\n  emit_getgl(as, RID_TMP, cur_L);\n  emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n}\n#endif\n\n/* -- Type conversions ---------------------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  RegSet allow = RSET_FPR;\n  Reg tmp = ra_scratch(as, rset_clear(allow, left));\n  Reg fbias = ra_scratch(as, rset_clear(allow, tmp));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest));\n  asm_guardcc(as, CC_NE);\n  emit_fab(as, PPCI_FCMPU, 0, tmp, left);\n  emit_fab(as, PPCI_FSUB, tmp, tmp, fbias);\n  emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP);\n  emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO);\n  emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n  emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000);\n  emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n  emit_lsptr(as, PPCI_LFS, (fbias & 31),\n\t     (void *)&as->J->k32[LJ_K32_2P52_2P31], RSET_GPR);\n  emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n  emit_fb(as, PPCI_FCTIWZ, tmp, left);\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_FPR;\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, allow);\n  Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));\n  Reg tmp = ra_scratch(as, rset_clear(allow, right));\n  emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n  emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n  emit_fab(as, PPCI_FADD, tmp, left, right);\n}\n#endif\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if !LJ_SOFTFP\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n#endif\n  IRRef lref = ir->op1;\n  /* 64 bit integer conversions are handled by SPLIT. */\n  lj_assertA(!(irt_isint64(ir->t) || (st == IRT_I64 || st == IRT_U64)),\n\t     \"IR %04d has unsplit 64 bit type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n#if LJ_SOFTFP\n  /* FP conversions are handled by SPLIT. */\n  lj_assertA(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT),\n\t     \"IR %04d has FP type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n  /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */\n#else\n  lj_assertA(irt_type(ir->t) != st, \"inconsistent types for CONV\");\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      if (st == IRT_NUM)  /* double -> float conversion. */\n\temit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR));\n      else  /* float -> double conversion is a no-op on PPC. */\n\tra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    } else {  /* Integer to FP conversion. */\n      /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */\n      /* IRT_U32: Bias with 2^52, subtract 2^52. */\n      RegSet allow = RSET_GPR;\n      Reg left = ra_alloc1(as, lref, allow);\n      Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left));\n      Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest);\n      emit_fab(as, PPCI_FSUB, dest, dest, fbias);\n      emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);\n      emit_lsptr(as, PPCI_LFS, (fbias & 31),\n\t\t &as->J->k32[st == IRT_U32 ? LJ_K32_2P52 : LJ_K32_2P52_2P31],\n\t\t rset_clear(allow, hibias));\n      emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP,\n\t       RID_SP, SPOFS_TMPLO);\n      emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n      if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000);\n    }\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      Reg left = ra_alloc1(as, lref, RSET_FPR);\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n      if (irt_isu32(ir->t)) {\n\t/* Convert both x and x-2^31 to int and merge results. */\n\tReg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest));\n\temit_asb(as, PPCI_OR, dest, dest, tmpi);  /* Select with mask idiom. */\n\temit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP);\n\temit_asb(as, PPCI_ANDC, dest, dest, RID_TMP);\n\temit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO);  /* tmp = (int)(x) */\n\temit_tai(as, PPCI_ADDIS, dest, dest, 0x8000);  /* dest += 2^31 */\n\temit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31);  /* mask = -(dest < 0) */\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_tai(as, PPCI_LWZ, dest,\n\t\t RID_SP, SPOFS_TMPLO);  /* dest = (int)(x-2^31) */\n\temit_fb(as, PPCI_FCTIWZ, tmp, left);\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, tmp, tmp);\n\temit_fab(as, PPCI_FSUB, tmp, left, tmp);\n\temit_lsptr(as, PPCI_LFS, (tmp & 31),\n\t\t   (void *)&as->J->k32[LJ_K32_2P31], RSET_GPR);\n      } else {\n\temit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n\temit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, tmp, left);\n      }\n    }\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n      Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n      lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), \"bad type for CONV EXT\");\n      if ((ir->op2 & IRCONV_SEXT))\n\temit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left);\n      else\n\temit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31);\n    } else {  /* 32/64 bit integer conversions. */\n      /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */\n      ra_leftov(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    }\n  }\n}\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  int32_t ofs = SPOFS_TMP;\n#if LJ_SOFTFP\n  ra_evictset(as, RSET_SCRATCH);\n  if (ra_used(ir)) {\n    if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&\n\t(ir->s & 1) == LJ_BE && (ir->s ^ 1) == (ir+1)->s) {\n      int i;\n      for (i = 0; i < 2; i++) {\n\tReg r = (ir+i)->r;\n\tif (ra_hasreg(r)) {\n\t  ra_free(as, r);\n\t  ra_modified(as, r);\n\t  emit_spload(as, ir+i, r, sps_scale((ir+i)->s));\n\t}\n      }\n      ofs = sps_scale(ir->s & ~1);\n    } else {\n      Reg rhi = ra_dest(as, ir+1, RSET_GPR);\n      Reg rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));\n      emit_tai(as, PPCI_LWZ, rhi, RID_SP, ofs);\n      emit_tai(as, PPCI_LWZ, rlo, RID_SP, ofs+4);\n    }\n  }\n#else\n  RegSet drop = RSET_SCRATCH;\n  if (ra_hasreg(ir->r)) rset_set(drop, ir->r);  /* Spill dest reg (if any). */\n  ra_evictset(as, drop);\n  if (ir->s) ofs = sps_scale(ir->s);\n#endif\n  asm_guardcc(as, CC_EQ);\n  emit_ai(as, PPCI_CMPWI, RID_RET, 0);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs);\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode)\n{\n  int32_t tmpofs = (int32_t)(offsetof(global_State, tmptv)-32768);\n  if ((mode & IRTMPREF_IN1)) {\n    IRIns *ir = IR(ref);\n    if (irt_isnum(ir->t)) {\n      if ((mode & IRTMPREF_OUT1)) {\n#if LJ_SOFTFP\n\tlj_assertA(irref_isk(ref), \"unsplit FP op\");\n\temit_tai(as, PPCI_ADDI, dest, RID_JGL, tmpofs);\n\temit_setgl(as,\n\t\t   ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, RSET_GPR),\n\t\t   tmptv.u32.lo);\n\temit_setgl(as,\n\t\t   ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, RSET_GPR),\n\t\t   tmptv.u32.hi);\n#else\n\tReg src = ra_alloc1(as, ref, RSET_FPR);\n\temit_tai(as, PPCI_ADDI, dest, RID_JGL, tmpofs);\n\temit_fai(as, PPCI_STFD, src, RID_JGL, tmpofs);\n#endif\n      } else if (irref_isk(ref)) {\n\t/* Use the number constant itself as a TValue. */\n\tra_allockreg(as, i32ptr(ir_knum(ir)), dest);\n      } else {\n#if LJ_SOFTFP\n\tlj_assertA(0, \"unsplit FP op\");\n#else\n\t/* Otherwise force a spill and use the spill slot. */\n\temit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir));\n#endif\n      }\n    } else {\n      /* Otherwise use g->tmptv to hold the TValue. */\n      Reg type;\n      emit_tai(as, PPCI_ADDI, dest, RID_JGL, tmpofs);\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, RSET_GPR);\n\temit_setgl(as, src, tmptv.gcr);\n      }\n      if (LJ_SOFTFP && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t))\n\ttype = ra_alloc1(as, ref+1, RSET_GPR);\n      else\n\ttype = ra_allock(as, irt_toitype(ir->t), RSET_GPR);\n      emit_setgl(as, type, tmptv.it);\n    }\n  } else {\n    emit_tai(as, PPCI_ADDI, dest, RID_JGL, tmpofs);\n  }\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg idx, base;\n  if (irref_isk(ir->op2)) {\n    IRRef tab = IR(ir->op1)->op1;\n    int32_t ofs = asm_fuseabase(as, tab);\n    IRRef refa = ofs ? tab : ir->op1;\n    ofs += 8*IR(ir->op2)->i;\n    if (checki16(ofs)) {\n      base = ra_alloc1(as, refa, RSET_GPR);\n      emit_tai(as, PPCI_ADDI, dest, base, ofs);\n      return;\n    }\n  }\n  base = ra_alloc1(as, ir->op1, RSET_GPR);\n  idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));\n  emit_tab(as, PPCI_ADD, dest, RID_TMP, base);\n  emit_slwi(as, RID_TMP, idx, 3);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, tmp1 = RID_TMP, tmp2;\n  Reg tisnum = RID_NONE, tmpnum = RID_NONE;\n  IRRef refkey = ir->op2;\n  IRIns *irkey = IR(refkey);\n  int isk = irref_isk(refkey);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  rset_clear(allow, tab);\n#if LJ_SOFTFP\n  if (!isk) {\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n    if (irkey[1].o == IR_HIOP) {\n      if (ra_hasreg((irkey+1)->r)) {\n\ttmpnum = (irkey+1)->r;\n\tra_noweak(as, tmpnum);\n      } else {\n\ttmpnum = ra_allocref(as, refkey+1, allow);\n      }\n      rset_clear(allow, tmpnum);\n    }\n  }\n#else\n  if (irt_isnum(kt)) {\n    key = ra_alloc1(as, refkey, RSET_FPR);\n    tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));\n    tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);\n    rset_clear(allow, tisnum);\n  } else if (!irt_ispri(kt)) {\n    key = ra_alloc1(as, refkey, allow);\n    rset_clear(allow, key);\n  }\n#endif\n  tmp2 = ra_scratch(as, allow);\n  rset_clear(allow, tmp2);\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  as->invmcp = NULL;\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_EQ);\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = --as->mcp;\n  emit_ai(as, PPCI_CMPWI, dest, 0);\n  emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_EQ);\n  else\n    emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  if (!LJ_SOFTFP && irt_isnum(kt)) {\n    emit_fab(as, PPCI_FCMPU, 0, tmpnum, key);\n    emit_condbranch(as, PPCI_BC, CC_GE, l_next);\n    emit_ab(as, PPCI_CMPLW, tmp1, tisnum);\n    emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n));\n  } else {\n    if (!irt_ispri(kt)) {\n      emit_ab(as, PPCI_CMPW, tmp2, key);\n      emit_condbranch(as, PPCI_BC, CC_NE, l_next);\n    }\n    if (LJ_SOFTFP && ra_hasreg(tmpnum))\n      emit_ab(as, PPCI_CMPW, tmp1, tmpnum);\n    else\n      emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t));\n    if (!irt_ispri(kt))\n      emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr));\n  }\n  emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it));\n  *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) |\n\t    (((char *)as->mcp-(char *)l_loop) & 0xffffu);\n\n  /* Load main position relative to tab->node into dest. */\n  khash = isk ? ir_khash(as, irkey) : 1;\n  if (khash == 0) {\n    emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));\n  } else {\n    Reg tmphash = tmp1;\n    if (isk)\n      tmphash = ra_allock(as, khash, allow);\n    emit_tab(as, PPCI_ADD, dest, dest, tmp1);\n    emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node));\n    emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash);\n    emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));\n    emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask));\n    if (isk) {\n      /* Nothing to do. */\n    } else if (irt_isstr(kt)) {\n      emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, sid));\n    } else {  /* Must match with hash*() in lj_tab.c. */\n      emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1);\n      emit_rotlwi(as, tmp2, tmp2, HASH_ROT3);\n      emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2);\n      emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31);\n      emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2);\n      if (LJ_SOFTFP ? (irkey[1].o == IR_HIOP) : irt_isnum(kt)) {\n#if LJ_SOFTFP\n\temit_asb(as, PPCI_XOR, tmp2, key, tmp1);\n\temit_rotlwi(as, dest, tmp1, HASH_ROT1);\n\temit_tab(as, PPCI_ADD, tmp1, tmpnum, tmpnum);\n#else\n\tint32_t ofs = ra_spill(as, irkey);\n\temit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1);\n\temit_rotlwi(as, dest, tmp1, HASH_ROT1);\n\temit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1);\n\temit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4);\n\temit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs);\n#endif\n      } else {\n\temit_asb(as, PPCI_XOR, tmp2, key, tmp1);\n\temit_rotlwi(as, dest, tmp1, HASH_ROT1);\n\temit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS);\n\temit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16);\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  int32_t kofs = ofs + (int32_t)offsetof(Node, key);\n  Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg key = RID_NONE, type = RID_TMP, idx = node;\n  RegSet allow = rset_exclude(RSET_GPR, node);\n  lj_assertA(ofs % sizeof(Node) == 0, \"unaligned HREFK slot\");\n  if (ofs > 32736) {\n    idx = dest;\n    rset_clear(allow, dest);\n    kofs = (int32_t)offsetof(Node, key);\n  } else if (ra_hasreg(dest)) {\n    emit_tai(as, PPCI_ADDI, dest, node, ofs);\n  }\n  asm_guardcc(as, CC_NE);\n  if (!irt_ispri(irkey->t)) {\n    key = ra_scratch(as, allow);\n    rset_clear(allow, key);\n  }\n  rset_clear(allow, type);\n  if (irt_isnum(irkey->t)) {\n    emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo);\n    asm_guardcc(as, CC_NE);\n    emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi);\n  } else {\n    if (ra_hasreg(key)) {\n      emit_cmpi(as, key, irkey->i);  /* May use RID_TMP, i.e. type. */\n      asm_guardcc(as, CC_NE);\n    }\n    emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t));\n  }\n  if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4);\n  emit_tai(as, PPCI_LWZ, type, idx, kofs);\n  if (ofs > 32736) {\n    emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16);\n    emit_tai(as, PPCI_ADDI, dest, node, ofs);\n  }\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      asm_guardcc(as, CC_NE);\n      emit_ai(as, PPCI_CMPWI, RID_TMP, 1);\n      emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv));\n      emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));\n    } else {\n      emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v));\n    }\n    emit_tai(as, PPCI_LWZ, uv, func,\n\t     (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  UNUSED(as); UNUSED(ir);\n  lj_assertA(!ra_used(ir), \"unfused FREF\");\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRRef ref = ir->op2, refk = ir->op1;\n  int32_t ofs = (int32_t)sizeof(GCstr);\n  Reg r;\n  if (irref_isk(ref)) {\n    IRRef tmp = refk; refk = ref; ref = tmp;\n  } else if (!irref_isk(refk)) {\n    Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n    IRIns *irr = IR(ir->op2);\n    if (ra_hasreg(irr->r)) {\n      ra_noweak(as, irr->r);\n      right = irr->r;\n    } else if (mayfuse(as, irr->op2) &&\n\t       irr->o == IR_ADD && irref_isk(irr->op2) &&\n\t       checki16(ofs + IR(irr->op2)->i)) {\n      ofs += IR(irr->op2)->i;\n      right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));\n    } else {\n      right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));\n    }\n    emit_tai(as, PPCI_ADDI, dest, dest, ofs);\n    emit_tab(as, PPCI_ADD, dest, left, right);\n    return;\n  }\n  r = ra_alloc1(as, ref, RSET_GPR);\n  ofs += IR(refk)->i;\n  if (checki16(ofs))\n    emit_tai(as, PPCI_ADDI, dest, r, ofs);\n  else\n    emit_tab(as, PPCI_ADD, dest, r,\n\t     ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic PPCIns asm_fxloadins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: return PPCI_LBZ;  /* Needs sign-extension. */\n  case IRT_U8: return PPCI_LBZ;\n  case IRT_I16: return PPCI_LHA;\n  case IRT_U16: return PPCI_LHZ;\n  case IRT_NUM: lj_assertA(!LJ_SOFTFP, \"unsplit FP op\"); return PPCI_LFD;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return PPCI_LFS;\n  default: return PPCI_LWZ;\n  }\n}\n\nstatic PPCIns asm_fxstoreins(ASMState *as, IRIns *ir)\n{\n  UNUSED(as);\n  switch (irt_type(ir->t)) {\n  case IRT_I8: case IRT_U8: return PPCI_STB;\n  case IRT_I16: case IRT_U16: return PPCI_STH;\n  case IRT_NUM: lj_assertA(!LJ_SOFTFP, \"unsplit FP op\"); return PPCI_STFD;\n  case IRT_FLOAT: if (!LJ_SOFTFP) return PPCI_STFS;\n  default: return PPCI_STW;\n  }\n}\n\nstatic void asm_fload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  PPCIns pi = asm_fxloadins(as, ir);\n  Reg idx;\n  int32_t ofs;\n  if (ir->op1 == REF_NIL) {  /* FLOAD from GG_State with offset. */\n    idx = RID_JGL;\n    ofs = (ir->op2 << 2) - 32768 - GG_OFS(g);\n  } else {\n    idx = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->op2 == IRFL_TAB_ARRAY) {\n      ofs = asm_fuseabase(as, ir->op1);\n      if (ofs) {  /* Turn the t->array load into an add for colocated arrays. */\n\temit_tai(as, PPCI_ADDI, dest, idx, ofs);\n\treturn;\n      }\n    }\n    ofs = field_ofs[ir->op2];\n  }\n  lj_assertA(!irt_isi8(ir->t), \"unsupported FLOAD I8\");\n  emit_tai(as, pi, dest, idx, ofs);\n}\n\nstatic void asm_fstore(ASMState *as, IRIns *ir)\n{\n  if (ir->r != RID_SINK) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    IRIns *irf = IR(ir->op1);\n    Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));\n    int32_t ofs = field_ofs[irf->op2];\n    PPCIns pi = asm_fxstoreins(as, ir);\n    emit_tai(as, pi, src, idx, ofs);\n  }\n}\n\nstatic void asm_xload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir,\n    (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n  lj_assertA(!(ir->op2 & IRXLOAD_UNALIGNED), \"unaligned XLOAD\");\n  if (irt_isi8(ir->t))\n    emit_as(as, PPCI_EXTSB, dest, dest);\n  asm_fusexref(as, asm_fxloadins(as, ir), dest, ir->op1, RSET_GPR, 0);\n}\n\nstatic void asm_xstore_(ASMState *as, IRIns *ir, int32_t ofs)\n{\n  IRIns *irb;\n  if (ir->r == RID_SINK)\n    return;\n  if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP &&\n      ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) {\n    /* Fuse BSWAP with XSTORE to stwbrx. */\n    Reg src = ra_alloc1(as, irb->op1, RSET_GPR);\n    asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src));\n  } else {\n    Reg src = ra_alloc1(as, ir->op2,\n      (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);\n    asm_fusexref(as, asm_fxstoreins(as, ir), src, ir->op1,\n\t\t rset_exclude(RSET_GPR, src), ofs);\n  }\n}\n\n#define asm_xstore(as, ir)\tasm_xstore_(as, ir, 0)\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n  IRType1 t = ir->t;\n  Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx;\n  RegSet allow = RSET_GPR;\n  int32_t ofs = AHUREF_LSX;\n  if (LJ_SOFTFP && (ir+1)->o == IR_HIOP) {\n    t.irt = IRT_NUM;\n    if (ra_used(ir+1)) {\n      type = ra_dest(as, ir+1, allow);\n      rset_clear(allow, type);\n    }\n    ofs = 0;\n  }\n  if (ra_used(ir)) {\n    lj_assertA((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||\n\t       irt_isint(ir->t) || irt_isaddr(ir->t),\n\t       \"bad load type %d\", irt_type(ir->t));\n    if (LJ_SOFTFP || !irt_isnum(t)) ofs = 0;\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && irt_isnum(t)) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (ir->o == IR_VLOAD) {\n    ofs = ofs != AHUREF_LSX ? ofs + 8 * ir->op2 :\n\t  ir->op2 ? 8 * ir->op2 : AHUREF_LSX;\n  }\n  if (irt_isnum(t)) {\n    Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx));\n    asm_guardcc(as, CC_GE);\n    emit_ab(as, PPCI_CMPLW, type, tisnum);\n    if (ra_hasreg(dest)) {\n      if (!LJ_SOFTFP && ofs == AHUREF_LSX) {\n\ttmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR,\n\t\t\t\t\t\t       (idx&255)), (idx>>8)));\n\temit_fab(as, PPCI_LFDX, dest, (idx&255), tmp);\n      } else {\n\temit_fai(as, LJ_SOFTFP ? PPCI_LWZ : PPCI_LFD, dest, idx,\n\t\t ofs+4*LJ_SOFTFP);\n      }\n    }\n  } else {\n    asm_guardcc(as, CC_NE);\n    emit_ai(as, PPCI_CMPWI, type, irt_toitype(t));\n    if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4);\n  }\n  if (ofs == AHUREF_LSX) {\n    emit_tab(as, PPCI_LWZX, type, (idx&255), tmp);\n    emit_slwi(as, tmp, (idx>>8), 3);\n  } else {\n    emit_tai(as, PPCI_LWZ, type, idx, ofs);\n  }\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg idx, src = RID_NONE, type = RID_NONE;\n  int32_t ofs = AHUREF_LSX;\n  if (ir->r == RID_SINK)\n    return;\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    src = ra_alloc1(as, ir->op2, RSET_FPR);\n  } else {\n    if (!irt_ispri(ir->t)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n      ofs = 0;\n    }\n    if (LJ_SOFTFP && (ir+1)->o == IR_HIOP)\n      type = ra_alloc1(as, (ir+1)->op2, allow);\n    else\n      type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n    rset_clear(allow, type);\n  }\n  idx = asm_fuseahuref(as, ir->op1, &ofs, allow);\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    if (ofs == AHUREF_LSX) {\n      emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP);\n      emit_slwi(as, RID_TMP, (idx>>8), 3);\n    } else {\n      emit_fai(as, PPCI_STFD, src, idx, ofs);\n    }\n  } else {\n    if (ra_hasreg(src))\n      emit_tai(as, PPCI_STW, src, idx, ofs+4);\n    if (ofs == AHUREF_LSX) {\n      emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP);\n      emit_slwi(as, RID_TMP, (idx>>8), 3);\n    } else {\n      emit_tai(as, PPCI_STW, type, idx, ofs);\n    }\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4);\n  IRType1 t = ir->t;\n  Reg dest = RID_NONE, type = RID_NONE, base;\n  RegSet allow = RSET_GPR;\n  int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);\n  if (hiop)\n    t.irt = IRT_NUM;\n  lj_assertA(!(ir->op2 & IRSLOAD_PARENT),\n\t     \"bad parent SLOAD\");  /* Handled by asm_head_side(). */\n  lj_assertA(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK),\n\t     \"inconsistent SLOAD variant\");\n  lj_assertA(LJ_DUALNUM ||\n\t     !irt_isint(t) ||\n\t     (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME|IRSLOAD_KEYINDEX)),\n\t     \"bad SLOAD type\");\n#if LJ_SOFTFP\n  lj_assertA(!(ir->op2 & IRSLOAD_CONVERT),\n\t     \"unsplit SLOAD convert\");  /* Handled by LJ_SOFTFP SPLIT. */\n  if (hiop && ra_used(ir+1)) {\n    type = ra_dest(as, ir+1, allow);\n    rset_clear(allow, type);\n  }\n#else\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    dest = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, dest);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n  } else\n#endif\n  if (ra_used(ir)) {\n    lj_assertA(irt_isnum(t) || irt_isint(t) || irt_isaddr(t),\n\t       \"bad SLOAD type %d\", irt_type(ir->t));\n    dest = ra_dest(as, ir, (!LJ_SOFTFP && irt_isnum(t)) ? RSET_FPR : allow);\n    rset_clear(allow, dest);\n    base = ra_alloc1(as, REF_BASE, allow);\n    rset_clear(allow, base);\n    if (!LJ_SOFTFP && (ir->op2 & IRSLOAD_CONVERT)) {\n      if (irt_isint(t)) {\n\temit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);\n\tdest = ra_scratch(as, RSET_FPR);\n\temit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP);\n\temit_fb(as, PPCI_FCTIWZ, dest, dest);\n\tt.irt = IRT_NUM;  /* Check for original type. */\n      } else {\n\tReg tmp = ra_scratch(as, allow);\n\tReg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp));\n\tReg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n\temit_fab(as, PPCI_FSUB, dest, dest, fbias);\n\temit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);\n\temit_lsptr(as, PPCI_LFS, (fbias & 31),\n\t\t   (void *)&as->J->k32[LJ_K32_2P52_2P31],\n\t\t   rset_clear(allow, hibias));\n\temit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO);\n\temit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);\n\temit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000);\n\tdest = tmp;\n\tt.irt = IRT_INT;  /* Check for original type. */\n      }\n    }\n    goto dotypecheck;\n  }\n  base = ra_alloc1(as, REF_BASE, allow);\n  rset_clear(allow, base);\ndotypecheck:\n  if (irt_isnum(t)) {\n    if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n      Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);\n      asm_guardcc(as, CC_GE);\n#if !LJ_SOFTFP\n      type = RID_TMP;\n#endif\n      emit_ab(as, PPCI_CMPLW, type, tisnum);\n    }\n    if (ra_hasreg(dest)) emit_fai(as, LJ_SOFTFP ? PPCI_LWZ : PPCI_LFD, dest,\n\t\t\t\t  base, ofs-(LJ_SOFTFP?0:4));\n  } else {\n    if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n      asm_guardcc(as, CC_NE);\n      emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t));\n      type = RID_TMP;\n    }\n    if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs);\n  }\n  if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4);\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  RegSet drop = RSET_SCRATCH;\n  lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),\n\t     \"bad CNEW/CNEWI operands\");\n\n  as->gcsteps++;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  if (ra_used(ir))\n    ra_destreg(as, ir, RID_RET);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n    int32_t ofs = sizeof(GCcdata);\n    lj_assertA(sz == 4 || sz == 8, \"bad CNEWI size %d\", sz);\n    if (sz == 8) {\n      ofs += 4;\n      lj_assertA((ir+1)->o == IR_HIOP, \"expected HIOP for CNEWI\");\n    }\n    for (;;) {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_tai(as, PPCI_STW, r, RID_RET, ofs);\n      rset_clear(allow, r);\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir++;\n    }\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */\n  emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));\n  emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));\n  emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA);\n  emit_ti(as, PPCI_LI, RID_TMP, id);  /* Lower 16 bit used. Sign-ext ok. */\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),\n\t       ra_releasetmp(as, ASMREF_TMP1));\n}\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  Reg link = RID_TMP;\n  MCLabel l_end = emit_label(as);\n  emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist));\n  emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked));\n  emit_setgl(as, tab, gc.grayagain);\n  lj_assertA(LJ_GC_BLACK == 0x04, \"bad LJ_GC_BLACK\");\n  emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28);  /* Clear black bit. */\n  emit_getgl(as, link, gc.grayagain);\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK);\n  emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj, val, tmp;\n  /* No need for other object barriers (yet). */\n  lj_assertA(IR(ir->op1)->o == IR_UREFC, \"bad OBAR type\");\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  obj = IR(ir->op1)->r;\n  tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK);\n  emit_condbranch(as, PPCI_BC, CC_EQ, l_end);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES);\n  val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));\n  emit_tai(as, PPCI_LBZ, tmp, obj,\n\t   (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n  emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked));\n}\n\n/* -- Arithmetic and logic operations ------------------------------------- */\n\n#if !LJ_SOFTFP\nstatic void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n  right = (left >> 8); left &= 255;\n  if (pi == PPCI_FMUL)\n    emit_fac(as, pi, dest, left, right);\n  else\n    emit_fab(as, pi, dest, left, right);\n}\n\nstatic void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest = ra_dest(as, ir, RSET_FPR);\n  Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);\n  emit_fb(as, pi, dest, left);\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT))\n    asm_fpunary(as, ir, PPCI_FSQRT);\n  else\n    asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);\n}\n#endif\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD))\n      asm_fparith(as, ir, PPCI_FADD);\n  } else\n#endif\n  {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    PPCIns pi;\n    if (irref_isk(ir->op2)) {\n      int32_t k = IR(ir->op2)->i;\n      if (checki16(k)) {\n\tpi = PPCI_ADDI;\n\t/* May fail due to spills/restores above, but simplifies the logic. */\n\tif (as->flagmcp == as->mcp) {\n\t  as->flagmcp = NULL;\n\t  as->mcp++;\n\t  pi = PPCI_ADDICDOT;\n\t}\n\temit_tai(as, pi, dest, left, k);\n\treturn;\n      } else if ((k & 0xffff) == 0) {\n\temit_tai(as, PPCI_ADDIS, dest, left, (k >> 16));\n\treturn;\n      } else if (!as->sectref) {\n\temit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16);\n\temit_tai(as, PPCI_ADDI, dest, left, k);\n\treturn;\n      }\n    }\n    pi = PPCI_ADD;\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, left, right);\n  }\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB))\n      asm_fparith(as, ir, PPCI_FSUB);\n  } else\n#endif\n  {\n    PPCIns pi = PPCI_SUBF;\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg left, right;\n    if (irref_isk(ir->op1)) {\n      int32_t k = IR(ir->op1)->i;\n      if (checki16(k)) {\n\tright = ra_alloc1(as, ir->op2, RSET_GPR);\n\temit_tai(as, PPCI_SUBFIC, dest, right, k);\n\treturn;\n      }\n    }\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, right, left);  /* Subtract right _from_ left. */\n  }\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fparith(as, ir, PPCI_FMUL);\n  } else\n#endif\n  {\n    PPCIns pi = PPCI_MULLW;\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    if (irref_isk(ir->op2)) {\n      int32_t k = IR(ir->op2)->i;\n      if (checki16(k)) {\n\temit_tai(as, PPCI_MULLI, dest, left, k);\n\treturn;\n      }\n    }\n    /* May fail due to spills/restores above, but simplifies the logic. */\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_tab(as, pi, dest, left, right);\n  }\n}\n\n#define asm_fpdiv(as, ir)\tasm_fparith(as, ir, PPCI_FDIV)\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n#if !LJ_SOFTFP\n  if (irt_isnum(ir->t)) {\n    asm_fpunary(as, ir, PPCI_FNEG);\n  } else\n#endif\n  {\n    Reg dest, left;\n    PPCIns pi = PPCI_NEG;\n    if (as->flagmcp == as->mcp) {\n      as->flagmcp = NULL;\n      as->mcp++;\n      pi |= PPCF_DOT;\n    }\n    dest = ra_dest(as, ir, RSET_GPR);\n    left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n    emit_tab(as, pi, dest, left, 0);\n  }\n}\n\n#define asm_abs(as, ir)\t\tasm_fpunary(as, ir, PPCI_FABS)\n\nstatic void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi)\n{\n  Reg dest, left, right;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n  }\n  asm_guardcc(as, CC_SO);\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc2(as, ir, RSET_GPR);\n  right = (left >> 8); left &= 255;\n  if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; }\n  emit_tab(as, pi|PPCF_DOT, dest, left, right);\n}\n\n#define asm_addov(as, ir)\tasm_arithov(as, ir, PPCI_ADDO)\n#define asm_subov(as, ir)\tasm_arithov(as, ir, PPCI_SUBFO)\n#define asm_mulov(as, ir)\tasm_arithov(as, ir, PPCI_MULLWO)\n\n#if LJ_HASFFI\nstatic void asm_add64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);\n  PPCIns pi = PPCI_ADDE;\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k == 0)\n      pi = PPCI_ADDZE;\n    else if (k == -1)\n      pi = PPCI_ADDME;\n    else\n      goto needright;\n    right = 0;\n  } else {\n  needright:\n    right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  }\n  emit_tab(as, pi, dest, left, right);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (checki16(k)) {\n      emit_tai(as, PPCI_ADDIC, dest, left, k);\n      return;\n    }\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_tab(as, PPCI_ADDC, dest, left, right);\n}\n\nstatic void asm_sub64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR);\n  PPCIns pi = PPCI_SUBFE;\n  if (irref_isk(ir->op1)) {\n    int32_t k = IR(ir->op1)->i;\n    if (k == 0)\n      pi = PPCI_SUBFZE;\n    else if (k == -1)\n      pi = PPCI_SUBFME;\n    else\n      goto needleft;\n    left = 0;\n  } else {\n  needleft:\n    left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));\n  }\n  emit_tab(as, pi, dest, right, left);  /* Subtract right _from_ left. */\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  right = ra_alloc1(as, ir->op2, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    int32_t k = IR(ir->op1)->i;\n    if (checki16(k)) {\n      emit_tai(as, PPCI_SUBFIC, dest, right, k);\n      return;\n    }\n  }\n  left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));\n  emit_tab(as, PPCI_SUBFC, dest, right, left);\n}\n\nstatic void asm_neg64(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_tab(as, PPCI_SUBFZE, dest, left, 0);\n  ir--;\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  emit_tai(as, PPCI_SUBFIC, dest, left, 0);\n}\n#endif\n\nstatic void asm_bnot(ASMState *as, IRIns *ir)\n{\n  Reg dest, left, right;\n  PPCIns pi = PPCI_NOR;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    pi |= PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  if (mayfuse(as, ir->op1)) {\n    IRIns *irl = IR(ir->op1);\n    if (irl->o == IR_BAND)\n      pi ^= (PPCI_NOR ^ PPCI_NAND);\n    else if (irl->o == IR_BXOR)\n      pi ^= (PPCI_NOR ^ PPCI_EQV);\n    else if (irl->o != IR_BOR)\n      goto nofuse;\n    left = ra_hintalloc(as, irl->op1, dest, RSET_GPR);\n    right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left));\n  } else {\nnofuse:\n    left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  }\n  emit_asb(as, pi, dest, left, right);\n}\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  IRIns *irx;\n  if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD &&\n      ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) {\n    /* Fuse BSWAP with XLOAD to lwbrx. */\n    asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR);\n  } else {\n    Reg left = ra_alloc1(as, ir->op1, RSET_GPR);\n    Reg tmp = dest;\n    if (tmp == left) {\n      tmp = RID_TMP;\n      emit_mr(as, dest, RID_TMP);\n    }\n    emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23);\n    emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7);\n    emit_rotlwi(as, tmp, left, 8);\n  }\n}\n\n/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */\nstatic void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref)\n{\n  IRIns *ir;\n  Reg left;\n  if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) &&\n      irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) {\n    int32_t sh = (IR(ir->op2)->i & 31);\n    switch (ir->o) {\n    case IR_BSHL:\n      if ((mask & ((1u<<sh)-1))) goto nofuse;\n      break;\n    case IR_BSHR:\n      if ((mask & ~((~0u)>>sh))) goto nofuse;\n      sh = ((32-sh)&31);\n      break;\n    case IR_BROL:\n      break;\n    default:\n      goto nofuse;\n    }\n    left = ra_alloc1(as, ir->op1, RSET_GPR);\n    *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh);\n    return;\n  }\nnofuse:\n  left = ra_alloc1(as, ref, RSET_GPR);\n  *--as->mcp = pi | PPCF_T(left);\n}\n\nstatic void asm_band(ASMState *as, IRIns *ir)\n{\n  Reg dest, left, right;\n  IRRef lref = ir->op1;\n  PPCIns dot = 0;\n  IRRef op2;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    dot = PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    if (k) {\n      /* First check for a contiguous bitmask as used by rlwinm. */\n      uint32_t s1 = lj_ffs((uint32_t)k);\n      uint32_t k1 = ((uint32_t)k >> s1);\n      if ((k1 & (k1+1)) == 0) {\n\tasm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |\n\t\t\t  PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1),\n\t\t\t  k, lref);\n\treturn;\n      }\n      if (~(uint32_t)k) {\n\tuint32_t s2 = lj_ffs(~(uint32_t)k);\n\tuint32_t k2 = (~(uint32_t)k >> s2);\n\tif ((k2 & (k2+1)) == 0) {\n\t  asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |\n\t\t\t    PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)),\n\t\t\t    k, lref);\n\t  return;\n\t}\n      }\n    }\n    if (checku16(k)) {\n      left = ra_alloc1(as, lref, RSET_GPR);\n      emit_asi(as, PPCI_ANDIDOT, dest, left, k);\n      return;\n    } else if ((k & 0xffff) == 0) {\n      left = ra_alloc1(as, lref, RSET_GPR);\n      emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16));\n      return;\n    }\n  }\n  op2 = ir->op2;\n  if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) {\n    dot ^= (PPCI_AND ^ PPCI_ANDC);\n    op2 = IR(op2)->op1;\n  }\n  left = ra_hintalloc(as, lref, dest, RSET_GPR);\n  right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left));\n  emit_asb(as, PPCI_AND ^ dot, dest, left, right);\n}\n\nstatic void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);\n  if (irref_isk(ir->op2)) {\n    int32_t k = IR(ir->op2)->i;\n    Reg tmp = left;\n    if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) {\n      if (!checku16(k)) {\n\temit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16));\n\tif ((k & 0xffff) == 0) return;\n      }\n      emit_asi(as, pik, dest, left, k);\n      return;\n    }\n  }\n  /* May fail due to spills/restores above, but simplifies the logic. */\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    pi |= PPCF_DOT;\n  }\n  right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n  emit_asb(as, pi, dest, left, right);\n}\n\n#define asm_bor(as, ir)\t\tasm_bitop(as, ir, PPCI_OR, PPCI_ORI)\n#define asm_bxor(as, ir)\tasm_bitop(as, ir, PPCI_XOR, PPCI_XORI)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)\n{\n  Reg dest, left;\n  Reg dot = 0;\n  if (as->flagmcp == as->mcp) {\n    as->flagmcp = NULL;\n    as->mcp++;\n    dot = PPCF_DOT;\n  }\n  dest = ra_dest(as, ir, RSET_GPR);\n  left = ra_alloc1(as, ir->op1, RSET_GPR);\n  if (irref_isk(ir->op2)) {  /* Constant shifts. */\n    int32_t shift = (IR(ir->op2)->i & 31);\n    if (pik == 0)  /* SLWI */\n      emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift);\n    else if (pik == 1)  /* SRWI */\n      emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31);\n    else\n      emit_asb(as, pik|dot, dest, left, shift);\n  } else {\n    Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));\n    emit_asb(as, pi|dot, dest, left, right);\n  }\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, PPCI_SLW, 0)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, PPCI_SRW, 1)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI)\n#define asm_brol(as, ir) \\\n  asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31), \\\n\t\t       PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31))\n#define asm_bror(as, ir)\tlj_assertA(0, \"unexpected BROR\")\n\n#if LJ_SOFTFP\nstatic void asm_sfpmin_max(ASMState *as, IRIns *ir)\n{\n  CCallInfo ci = lj_ir_callinfo[IRCALL_softfp_cmp];\n  IRRef args[4];\n  MCLabel l_right, l_end;\n  Reg desthi = ra_dest(as, ir, RSET_GPR), destlo = ra_dest(as, ir+1, RSET_GPR);\n  Reg righthi, lefthi = ra_alloc2(as, ir, RSET_GPR);\n  Reg rightlo, leftlo = ra_alloc2(as, ir+1, RSET_GPR);\n  PPCCC cond = (IROp)ir->o == IR_MIN ? CC_EQ : CC_NE;\n  righthi = (lefthi >> 8); lefthi &= 255;\n  rightlo = (leftlo >> 8); leftlo &= 255;\n  args[0^LJ_BE] = ir->op1; args[1^LJ_BE] = (ir+1)->op1;\n  args[2^LJ_BE] = ir->op2; args[3^LJ_BE] = (ir+1)->op2;\n  l_end = emit_label(as);\n  if (desthi != righthi) emit_mr(as, desthi, righthi);\n  if (destlo != rightlo) emit_mr(as, destlo, rightlo);\n  l_right = emit_label(as);\n  if (l_end != l_right) emit_jmp(as, l_end);\n  if (desthi != lefthi) emit_mr(as, desthi, lefthi);\n  if (destlo != leftlo) emit_mr(as, destlo, leftlo);\n  if (l_right == as->mcp+1) {\n    cond ^= 4; l_right = l_end; ++as->mcp;\n  }\n  emit_condbranch(as, PPCI_BC, cond, l_right);\n  ra_evictset(as, RSET_SCRATCH);\n  emit_cmpi(as, RID_RET, 1);\n  asm_gencall(as, &ci, args);\n}\n#endif\n\nstatic void asm_min_max(ASMState *as, IRIns *ir, int ismax)\n{\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg tmp = dest;\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    if (tmp == left || tmp == right)\n      tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR,\n\t\t\t\t\tdest), left), right));\n    emit_facb(as, PPCI_FSEL, dest, tmp, left, right);\n    emit_fab(as, PPCI_FSUB, tmp, ismax ? left : right, ismax ? right : left);\n  } else {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    Reg tmp1 = RID_TMP, tmp2 = dest;\n    Reg right, left = ra_alloc2(as, ir, RSET_GPR);\n    right = (left >> 8); left &= 255;\n    if (tmp2 == left || tmp2 == right)\n      tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR,\n\t\t\t\t\t dest), left), right));\n    emit_tab(as, PPCI_ADD, dest, tmp2, right);\n    emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1);\n    emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1);\n    emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1);\n    emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000);\n    emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000);\n  }\n}\n\n#define asm_min(as, ir)\t\tasm_min_max(as, ir, 0)\n#define asm_max(as, ir)\t\tasm_min_max(as, ir, 1)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n#define CC_UNSIGNED\t0x08\t/* Unsigned integer comparison. */\n#define CC_TWO\t\t0x80\t/* Check two flags for FP comparison. */\n\n/* Map of comparisons to flags. ORDER IR. */\nstatic const uint8_t asm_compmap[IR_ABC+1] = {\n  /* op     int cc                 FP cc */\n  /* LT  */ CC_GE               + (CC_GE<<4),\n  /* GE  */ CC_LT               + (CC_LE<<4) + CC_TWO,\n  /* LE  */ CC_GT               + (CC_GE<<4) + CC_TWO,\n  /* GT  */ CC_LE               + (CC_LE<<4),\n  /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO,\n  /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4),\n  /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4),\n  /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO,\n  /* EQ  */ CC_NE               + (CC_NE<<4),\n  /* NE  */ CC_EQ               + (CC_EQ<<4),\n  /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO  /* Same as UGT. */\n};\n\nstatic void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc)\n{\n  Reg right, left = ra_alloc1(as, lref, RSET_GPR);\n  if (irref_isk(rref)) {\n    int32_t k = IR(rref)->i;\n    if ((cc & CC_UNSIGNED) == 0) {  /* Signed comparison with constant. */\n      if (checki16(k)) {\n\temit_tai(as, PPCI_CMPWI, cr, left, k);\n\t/* Signed comparison with zero and referencing previous ins? */\n\tif (k == 0 && lref == as->curins-1)\n\t  as->flagmcp = as->mcp;  /* Allow elimination of the compare. */\n\treturn;\n      } else if ((cc & 3) == (CC_EQ & 3)) {  /* Use CMPLWI for EQ or NE. */\n\tif (checku16(k)) {\n\t  emit_tai(as, PPCI_CMPLWI, cr, left, k);\n\t  return;\n\t} else if (!as->sectref && ra_noreg(IR(rref)->r)) {\n\t  emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k);\n\t  emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16));\n\t  return;\n\t}\n      }\n    } else {  /* Unsigned comparison with constant. */\n      if (checku16(k)) {\n\temit_tai(as, PPCI_CMPLWI, cr, left, k);\n\treturn;\n      }\n    }\n  }\n  right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left));\n  emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right);\n}\n\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  PPCCC cc = asm_compmap[ir->o];\n  if (!LJ_SOFTFP && irt_isnum(ir->t)) {\n    Reg right, left = ra_alloc2(as, ir, RSET_FPR);\n    right = (left >> 8); left &= 255;\n    asm_guardcc(as, (cc >> 4));\n    if ((cc & CC_TWO))\n      emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3));\n    emit_fab(as, PPCI_FCMPU, 0, left, right);\n  } else {\n    IRRef lref = ir->op1, rref = ir->op2;\n    if (irref_isk(lref) && !irref_isk(rref)) {\n      /* Swap constants to the right (only for ABC). */\n      IRRef tmp = lref; lref = rref; rref = tmp;\n      if ((cc & 2) == 0) cc ^= 1;  /* LT <-> GT, LE <-> GE */\n    }\n    asm_guardcc(as, cc);\n    asm_intcomp_(as, lref, rref, 0, cc);\n  }\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_SOFTFP\n/* SFP comparisons. */\nstatic void asm_sfpcomp(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];\n  RegSet drop = RSET_SCRATCH;\n  Reg r;\n  IRRef args[4];\n  args[0^LJ_BE] = ir->op1; args[1^LJ_BE] = (ir+1)->op1;\n  args[2^LJ_BE] = ir->op2; args[3^LJ_BE] = (ir+1)->op2;\n\n  for (r = REGARG_FIRSTGPR; r <= REGARG_FIRSTGPR+3; r++) {\n    if (!rset_test(as->freeset, r) &&\n\tregcost_ref(as->cost[r]) == args[r-REGARG_FIRSTGPR])\n      rset_clear(drop, r);\n  }\n  ra_evictset(as, drop);\n  asm_setupresult(as, ir, ci);\n  switch ((IROp)ir->o) {\n  case IR_ULT:\n    asm_guardcc(as, CC_EQ);\n    emit_ai(as, PPCI_CMPWI, RID_RET, 0);\n  case IR_ULE:\n    asm_guardcc(as, CC_EQ);\n    emit_ai(as, PPCI_CMPWI, RID_RET, 1);\n    break;\n  case IR_GE: case IR_GT:\n    asm_guardcc(as, CC_EQ);\n    emit_ai(as, PPCI_CMPWI, RID_RET, 2);\n  default:\n    asm_guardcc(as, (asm_compmap[ir->o] & 0xf));\n    emit_ai(as, PPCI_CMPWI, RID_RET, 0);\n    break;\n  }\n  asm_gencall(as, ci, args);\n}\n#endif\n\n#if LJ_HASFFI\n/* 64 bit integer comparisons. */\nstatic void asm_comp64(ASMState *as, IRIns *ir)\n{\n  PPCCC cc = asm_compmap[(ir-1)->o];\n  if ((cc&3) == (CC_EQ&3)) {\n    asm_guardcc(as, cc);\n    emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR,\n\t     (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3));\n  } else {\n    asm_guardcc(as, CC_EQ);\n    emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1));\n    emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC,\n\t     (CC_EQ&3), (CC_EQ&3), 4+(cc&3));\n  }\n  /* Loword comparison sets cr1 and is unsigned, except for equality. */\n  asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4,\n\t       cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED));\n  /* Hiword comparison sets cr0. */\n  asm_intcomp_(as, ir->op1, ir->op2, 0, cc);\n  as->flagmcp = NULL;  /* Doesn't work here. */\n}\n#endif\n\n/* -- Split register ops -------------------------------------------------- */\n\n/* Hiword op of a split 32/32 bit op. Previous op is be the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n#if LJ_HASFFI || LJ_SOFTFP\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n#if LJ_HASFFI && !LJ_SOFTFP\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n#endif\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    as->curins--;  /* Always skip the loword comparison. */\n#if LJ_SOFTFP\n    if (!irt_isint(ir->t)) {\n      asm_sfpcomp(as, ir-1);\n      return;\n    }\n#endif\n#if LJ_HASFFI\n    asm_comp64(as, ir);\n#endif\n    return;\n#if LJ_SOFTFP\n  } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {\n      as->curins--;  /* Always skip the loword min/max. */\n    if (uselo || usehi)\n      asm_sfpmin_max(as, ir-1);\n    return;\n#endif\n  } else if ((ir-1)->o == IR_XSTORE) {\n    as->curins--;  /* Handle both stores here. */\n    if ((ir-1)->r != RID_SINK) {\n      asm_xstore_(as, ir, 0);\n      asm_xstore_(as, ir-1, 4);\n    }\n    return;\n  }\n#endif\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_HASFFI\n  case IR_ADD: as->curins--; asm_add64(as, ir); break;\n  case IR_SUB: as->curins--; asm_sub64(as, ir); break;\n  case IR_NEG: as->curins--; asm_neg64(as, ir); break;\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n#if LJ_SOFTFP\n  case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n  case IR_STRTO:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RSET_GPR);  /* Mark lo op as used. */\n    break;\n  case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR: case IR_TMPREF:\n    /* Nothing to do here. Handled by lo op itself. */\n    break;\n#endif\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  default: lj_assertA(0, \"bad HIOP for op %d\", (ir-1)->o); break;\n  }\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, HOOK_PROFILE);\n  emit_lsglptr(as, PPCI_LBZ, RID_TMP,\n\t       (int32_t)offsetof(global_State, hookmask));\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */\n  Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;\n  rset_clear(allow, pbase);\n  tmp = allow ? rset_pickbot(allow) :\n\t\t(pbase == RID_RETHI ? RID_RETLO : RID_RETHI);\n  emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno));\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW);\n  else\n    ra_modified(as, tmp);\n  emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot));\n  emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp);\n  emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack));\n  if (pbase == RID_TMP)\n    emit_getgl(as, RID_TMP, jit_base);\n  emit_getgl(as, tmp, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if (irt_isnum(ir->t)) {\n#if LJ_SOFTFP\n      Reg tmp;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      /* LJ_SOFTFP: must be a number constant. */\n      lj_assertA(irref_isk(ref), \"unsplit FP op\");\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo, allow);\n      emit_tai(as, PPCI_STW, tmp, RID_BASE, ofs+(LJ_BE?4:0));\n      if (rset_test(as->freeset, tmp+1)) allow = RID2RSET(tmp+1);\n      tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, allow);\n      emit_tai(as, PPCI_STW, tmp, RID_BASE, ofs+(LJ_BE?0:4));\n#else\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_fai(as, PPCI_STFD, src, RID_BASE, ofs);\n#endif\n    } else {\n      Reg type;\n      RegSet allow = rset_exclude(RSET_GPR, RID_BASE);\n      lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t),\n\t\t \"restore of IR type %d\", irt_type(ir->t));\n      if (!irt_ispri(ir->t)) {\n\tReg src = ra_alloc1(as, ref, allow);\n\trset_clear(allow, src);\n\temit_tai(as, PPCI_STW, src, RID_BASE, ofs+4);\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\tif (s == 0) continue;  /* Do not overwrite link to previous frame. */\n\ttype = ra_allock(as, (int32_t)(*flinks--), allow);\n#if LJ_SOFTFP\n      } else if ((sn & SNAP_SOFTFPNUM)) {\n\ttype = ra_alloc1(as, ref+1, rset_exclude(RSET_GPR, RID_BASE));\n#endif\n      } else if ((sn & SNAP_KEYINDEX)) {\n\ttype = ra_allock(as, (int32_t)LJ_KEYINDEX, allow);\n      } else {\n\ttype = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);\n      }\n      emit_tai(as, PPCI_STW, type, RID_BASE, ofs);\n    }\n    checkmclim(as);\n  }\n  lj_assertA(map + nent == flinks, \"inconsistent frames in snapshot\");\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Marker to prevent patching the GC check exit. */\n#define PPC_NOPATCH_GC_CHECK\tPPCI_ORIS\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  *--as->mcp = PPC_NOPATCH_GC_CHECK;\n  emit_ai(as, PPCI_CMPWI, RID_RET, 0);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);\n  tmp = ra_releasetmp(as, ASMREF_TMP2);\n  emit_loadi(as, tmp, as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end);\n  emit_ab(as, PPCI_CMPLW, RID_TMP, tmp);\n  emit_getgl(as, tmp, gc.threshold);\n  emit_getgl(as, RID_TMP, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->loopinv) {  /* Inverted loop branch? */\n    /* asm_guardcc already inverted the cond branch and patched the final b. */\n    p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2);\n  } else {\n    p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);\n  }\n}\n\n/* Fixup the tail of the loop. */\nstatic void asm_loop_tail_fixup(ASMState *as)\n{\n  UNUSED(as);  /* Nothing to do. */\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_mr(as, r, RID_BASE);\n  }\n}\n\n/* Coalesce BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      rset_clear(allow, irp->r);\n      emit_mr(as, r, irp->r);  /* Move from coalesced parent reg. */\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  MCode *p = as->mctop;\n  MCode *target;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    *--p = PPCI_NOP;\n    *--p = PPCI_NOP;\n    as->mctop = p;\n  } else {\n    /* Patch stack adjustment. */\n    lj_assertA(checki16(CFRAME_SIZE+spadj), \"stack adjustment out of range\");\n    p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj);\n    p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj;\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop - 1;  /* Leave room for exit branch. */\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    as->mcp = p-2;  /* Leave room for stack pointer adjustment. */\n    as->invmcp = NULL;\n  }\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n  asm_collectargs(as, ir, ci, args);\n  for (i = 0; i < nargs; i++)\n    if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) {\n      if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1;\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n  return (!LJ_SOFTFP && irt_isfp(ir->t)) ? REGSP_HINT(RID_FPRET) :\n\t\t\t\t\t   REGSP_HINT(RID_RET);\n}\n\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *pe = (MCode *)((char *)p + T->szmcode);\n  MCode *px = exitstub_trace_addr(T, exitno);\n  MCode *cstart = NULL;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  int clearso = 0, patchlong = 1;\n  for (; p < pe; p++) {\n    /* Look for exitstub branch, try to replace with branch to target. */\n    uint32_t ins = *p;\n    if ((ins & 0xfc000000u) == 0x40000000u &&\n\t((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) {\n      ptrdiff_t delta = (char *)target - (char *)p;\n      if (((ins >> 16) & 3) == (CC_SO&3)) {\n\tclearso = sizeof(MCode);\n\tdelta -= sizeof(MCode);\n      }\n      /* Many, but not all short-range branches can be patched directly. */\n      if (p[-1] == PPC_NOPATCH_GC_CHECK) {\n\tpatchlong = 0;\n      } else if (((delta + 0x8000) >> 16) == 0) {\n\t*p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) |\n\t     ((delta & 0x8000) * (PPCF_Y/0x8000));\n\tif (!cstart) cstart = p;\n      }\n    } else if ((ins & 0xfc000000u) == PPCI_B &&\n\t       ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) {\n      ptrdiff_t delta = (char *)target - (char *)p;\n      lj_assertJ(((delta + 0x02000000) >> 26) == 0,\n\t\t \"branch target out of range\");\n      *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu);\n      if (!cstart) cstart = p;\n    }\n  }\n  /* Always patch long-range branch in exit stub itself. Except, if we can't. */\n  if (patchlong) {\n    ptrdiff_t delta = (char *)target - (char *)px - clearso;\n    lj_assertJ(((delta + 0x02000000) >> 26) == 0,\n\t       \"branch target out of range\");\n    *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu);\n  }\n  if (!cstart) cstart = px;\n  lj_mcode_sync(cstart, px+1);\n  if (clearso) {  /* Extend the current trace. Ugly workaround. */\n    MCode *pp = J->cur.mcode;\n    J->cur.szmcode += sizeof(MCode);\n    *--pp = PPCI_MCRXR;  /* Clear SO flag. */\n    J->cur.mcode = pp;\n    lj_mcode_sync(pp, pp+1);\n  }\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_asm_x86.h",
    "content": "/*\n** x86/x64 IR assembler (SSA IR -> machine code).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Guard handling ------------------------------------------------------ */\n\n/* Generate an exit stub group at the bottom of the reserved MCode memory. */\nstatic MCode *asm_exitstub_gen(ASMState *as, ExitNo group)\n{\n  ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff;\n  MCode *mxp = as->mcbot;\n  MCode *mxpstart = mxp;\n  if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop)\n    asm_mclimit(as);\n  /* Push low byte of exitno for each exit stub. */\n  *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs;\n  for (i = 1; i < EXITSTUBS_PER_GROUP; i++) {\n    *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2);\n    *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i);\n  }\n  /* Push the high byte of the exitno for each exit stub group. */\n  *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8);\n#if !LJ_GC64\n  /* Store DISPATCH at original stack slot 0. Account for the two push ops. */\n  *mxp++ = XI_MOVmi;\n  *mxp++ = MODRM(XM_OFS8, 0, RID_ESP);\n  *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n  *mxp++ = 2*sizeof(void *);\n  *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4;\n#endif\n  /* Jump to exit handler which fills in the ExitState. */\n  *mxp++ = XI_JMP; mxp += 4;\n  *((int32_t *)(mxp-4)) = jmprel(as->J, mxp, (MCode *)(void *)lj_vm_exit_handler);\n  /* Commit the code for this group (even if assembly fails later on). */\n  lj_mcode_commitbot(as->J, mxp);\n  as->mcbot = mxp;\n  as->mclim = as->mcbot + MCLIM_REDZONE;\n  return mxpstart;\n}\n\n/* Setup all needed exit stubs. */\nstatic void asm_exitstub_setup(ASMState *as, ExitNo nexits)\n{\n  ExitNo i;\n  if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)\n    lj_trace_err(as->J, LJ_TRERR_SNAPOV);\n  for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)\n    if (as->J->exitstubgroup[i] == NULL)\n      as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);\n}\n\n/* Emit conditional branch to exit for guard.\n** It's important to emit this *after* all registers have been allocated,\n** because rematerializations may invalidate the flags.\n*/\nstatic void asm_guardcc(ASMState *as, int cc)\n{\n  MCode *target = exitstub_addr(as->J, as->snapno);\n  MCode *p = as->mcp;\n  if (LJ_UNLIKELY(p == as->invmcp)) {\n    as->loopinv = 1;\n    *(int32_t *)(p+1) = jmprel(as->J, p+5, target);\n    target = p;\n    cc ^= 1;\n    if (as->realign) {\n      if (LJ_GC64 && LJ_UNLIKELY(as->mrm.base == RID_RIP))\n\tas->mrm.ofs += 2;  /* Fixup RIP offset for pending fused load. */\n      emit_sjcc(as, cc, target);\n      return;\n    }\n  }\n  if (LJ_GC64 && LJ_UNLIKELY(as->mrm.base == RID_RIP))\n    as->mrm.ofs += 6;  /* Fixup RIP offset for pending fused load. */\n  emit_jcc(as, cc, target);\n}\n\n/* -- Memory operand fusion ----------------------------------------------- */\n\n/* Limit linear search to this distance. Avoids O(n^2) behavior. */\n#define CONFLICT_SEARCH_LIM\t31\n\n/* Check if a reference is a signed 32 bit constant. */\nstatic int asm_isk32(ASMState *as, IRRef ref, int32_t *k)\n{\n  if (irref_isk(ref)) {\n    IRIns *ir = IR(ref);\n#if LJ_GC64\n    if (ir->o == IR_KNULL || !irt_is64(ir->t)) {\n      *k = ir->i;\n      return 1;\n    } else if (checki32((int64_t)ir_k64(ir)->u64)) {\n      *k = (int32_t)ir_k64(ir)->u64;\n      return 1;\n    }\n#else\n    if (ir->o != IR_KINT64) {\n      *k = ir->i;\n      return 1;\n    } else if (checki32((int64_t)ir_kint64(ir)->u64)) {\n      *k = (int32_t)ir_kint64(ir)->u64;\n      return 1;\n    }\n#endif\n  }\n  return 0;\n}\n\n/* Check if there's no conflicting instruction between curins and ref.\n** Also avoid fusing loads if there are multiple references.\n*/\nstatic int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload)\n{\n  IRIns *ir = as->ir;\n  IRRef i = as->curins;\n  if (i > ref + CONFLICT_SEARCH_LIM)\n    return 0;  /* Give up, ref is too far away. */\n  while (--i > ref) {\n    if (ir[i].o == conflict)\n      return 0;  /* Conflict found. */\n    else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref))\n      return 0;\n  }\n  return 1;  /* Ok, no conflict. */\n}\n\n/* Fuse array base into memory operand. */\nstatic IRRef asm_fuseabase(ASMState *as, IRRef ref)\n{\n  IRIns *irb = IR(ref);\n  as->mrm.ofs = 0;\n  if (irb->o == IR_FLOAD) {\n    IRIns *ira = IR(irb->op1);\n    lj_assertA(irb->op2 == IRFL_TAB_ARRAY, \"expected FLOAD TAB_ARRAY\");\n    /* We can avoid the FLOAD of t->array for colocated arrays. */\n    if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE &&\n\t!neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) {\n      as->mrm.ofs = (int32_t)sizeof(GCtab);  /* Ofs to colocated array. */\n      return irb->op1;  /* Table obj. */\n    }\n  } else if (irb->o == IR_ADD && irref_isk(irb->op2)) {\n    /* Fuse base offset (vararg load). */\n    as->mrm.ofs = IR(irb->op2)->i;\n    return irb->op1;\n  }\n  return ref;  /* Otherwise use the given array base. */\n}\n\n/* Fuse array reference into memory operand. */\nstatic void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irx;\n  lj_assertA(ir->o == IR_AREF, \"expected AREF\");\n  as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow);\n  irx = IR(ir->op2);\n  if (irref_isk(ir->op2)) {\n    as->mrm.ofs += 8*irx->i;\n    as->mrm.idx = RID_NONE;\n  } else {\n    rset_clear(allow, as->mrm.base);\n    as->mrm.scale = XM_SCALE8;\n    /* Fuse a constant ADD (e.g. t[i+1]) into the offset.\n    ** Doesn't help much without ABCelim, but reduces register pressure.\n    */\n    if (!LJ_64 &&  /* Has bad effects with negative index on x64. */\n\tmayfuse(as, ir->op2) && ra_noreg(irx->r) &&\n\tirx->o == IR_ADD && irref_isk(irx->op2)) {\n      as->mrm.ofs += 8*IR(irx->op2)->i;\n      as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow);\n    } else {\n      as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow);\n    }\n  }\n}\n\n/* Fuse array/hash/upvalue reference into memory operand.\n** Caveat: this may allocate GPRs for the base/idx registers. Be sure to\n** pass the final allow mask, excluding any GPRs used for other inputs.\n** In particular: 2-operand GPR instructions need to call ra_dest() first!\n*/\nstatic void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_noreg(ir->r)) {\n    switch ((IROp)ir->o) {\n    case IR_AREF:\n      if (mayfuse(as, ref)) {\n\tasm_fusearef(as, ir, allow);\n\treturn;\n      }\n      break;\n    case IR_HREFK:\n      if (mayfuse(as, ref)) {\n\tas->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);\n\tas->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));\n\tas->mrm.idx = RID_NONE;\n\treturn;\n      }\n      break;\n    case IR_UREFC:\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn = ir_kfunc(IR(ir->op1));\n\tGCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv;\n#if LJ_GC64\n\tint64_t ofs = dispofs(as, &uv->tv);\n\tif (checki32(ofs) && checki32(ofs+4)) {\n\t  as->mrm.ofs = (int32_t)ofs;\n\t  as->mrm.base = RID_DISPATCH;\n\t  as->mrm.idx = RID_NONE;\n\t  return;\n\t}\n#else\n\tas->mrm.ofs = ptr2addr(&uv->tv);\n\tas->mrm.base = as->mrm.idx = RID_NONE;\n\treturn;\n#endif\n      }\n      break;\n    case IR_TMPREF:\n#if LJ_GC64\n      as->mrm.ofs = (int32_t)dispofs(as, &J2G(as->J)->tmptv);\n      as->mrm.base = RID_DISPATCH;\n      as->mrm.idx = RID_NONE;\n#else\n      as->mrm.ofs = igcptr(&J2G(as->J)->tmptv);\n      as->mrm.base = as->mrm.idx = RID_NONE;\n#endif\n      return;\n    default:\n      break;\n    }\n  }\n  as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);\n  as->mrm.ofs = 0;\n  as->mrm.idx = RID_NONE;\n}\n\n/* Fuse FLOAD/FREF reference into memory operand. */\nstatic void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow)\n{\n  lj_assertA(ir->o == IR_FLOAD || ir->o == IR_FREF,\n\t     \"bad IR op %d\", ir->o);\n  as->mrm.idx = RID_NONE;\n  if (ir->op1 == REF_NIL) {  /* FLOAD from GG_State with offset. */\n#if LJ_GC64\n    as->mrm.ofs = (int32_t)(ir->op2 << 2) - GG_OFS(dispatch);\n    as->mrm.base = RID_DISPATCH;\n#else\n    as->mrm.ofs = (int32_t)(ir->op2 << 2) + ptr2addr(J2GG(as->J));\n    as->mrm.base = RID_NONE;\n#endif\n    return;\n  }\n  as->mrm.ofs = field_ofs[ir->op2];\n  if (irref_isk(ir->op1)) {\n    IRIns *op1 = IR(ir->op1);\n#if LJ_GC64\n    if (ir->op1 == REF_NIL) {\n      as->mrm.ofs -= GG_OFS(dispatch);\n      as->mrm.base = RID_DISPATCH;\n      return;\n    } else if (op1->o == IR_KPTR || op1->o == IR_KKPTR) {\n      intptr_t ofs = dispofs(as, ir_kptr(op1));\n      if (checki32(as->mrm.ofs + ofs)) {\n\tas->mrm.ofs += (int32_t)ofs;\n\tas->mrm.base = RID_DISPATCH;\n\treturn;\n      }\n    }\n#else\n    as->mrm.ofs += op1->i;\n    as->mrm.base = RID_NONE;\n    return;\n#endif\n  }\n  as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);\n}\n\n/* Fuse string reference into memory operand. */\nstatic void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow)\n{\n  IRIns *irr;\n  lj_assertA(ir->o == IR_STRREF, \"bad IR op %d\", ir->o);\n  as->mrm.base = as->mrm.idx = RID_NONE;\n  as->mrm.scale = XM_SCALE1;\n  as->mrm.ofs = sizeof(GCstr);\n  if (!LJ_GC64 && irref_isk(ir->op1)) {\n    as->mrm.ofs += IR(ir->op1)->i;\n  } else {\n    Reg r = ra_alloc1(as, ir->op1, allow);\n    rset_clear(allow, r);\n    as->mrm.base = (uint8_t)r;\n  }\n  irr = IR(ir->op2);\n  if (irref_isk(ir->op2)) {\n    as->mrm.ofs += irr->i;\n  } else {\n    Reg r;\n    /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */\n    if (!LJ_64 &&  /* Has bad effects with negative index on x64. */\n\tmayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) {\n      as->mrm.ofs += IR(irr->op2)->i;\n      r = ra_alloc1(as, irr->op1, allow);\n    } else {\n      r = ra_alloc1(as, ir->op2, allow);\n    }\n    if (as->mrm.base == RID_NONE)\n      as->mrm.base = (uint8_t)r;\n    else\n      as->mrm.idx = (uint8_t)r;\n  }\n}\n\nstatic void asm_fusexref(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  as->mrm.idx = RID_NONE;\n  if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n#if LJ_GC64\n    intptr_t ofs = dispofs(as, ir_kptr(ir));\n    if (checki32(ofs)) {\n      as->mrm.ofs = (int32_t)ofs;\n      as->mrm.base = RID_DISPATCH;\n      return;\n    }\n  } if (0) {\n#else\n    as->mrm.ofs = ir->i;\n    as->mrm.base = RID_NONE;\n  } else if (ir->o == IR_STRREF) {\n    asm_fusestrref(as, ir, allow);\n#endif\n  } else {\n    as->mrm.ofs = 0;\n    if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) {\n      /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */\n      IRIns *irx;\n      IRRef idx;\n      Reg r;\n      if (asm_isk32(as, ir->op2, &as->mrm.ofs)) {  /* Recognize x+ofs. */\n\tref = ir->op1;\n\tir = IR(ref);\n\tif (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r)))\n\t  goto noadd;\n      }\n      as->mrm.scale = XM_SCALE1;\n      idx = ir->op1;\n      ref = ir->op2;\n      irx = IR(idx);\n      if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) {  /* Try other operand. */\n\tidx = ir->op2;\n\tref = ir->op1;\n\tirx = IR(idx);\n      }\n      if (canfuse(as, irx) && ra_noreg(irx->r)) {\n\tif (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) {\n\t  /* Recognize idx<<b with b = 0-3, corresponding to sz = (1),2,4,8. */\n\t  idx = irx->op1;\n\t  as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6);\n\t} else if (irx->o == IR_ADD && irx->op1 == irx->op2) {\n\t  /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */\n\t  idx = irx->op1;\n\t  as->mrm.scale = XM_SCALE2;\n\t}\n      }\n      r = ra_alloc1(as, idx, allow);\n      rset_clear(allow, r);\n      as->mrm.idx = (uint8_t)r;\n    }\n  noadd:\n    as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);\n  }\n}\n\n/* Fuse load of 64 bit IR constant into memory operand. */\nstatic Reg asm_fuseloadk64(ASMState *as, IRIns *ir)\n{\n  const uint64_t *k = &ir_k64(ir)->u64;\n  if (!LJ_GC64 || checki32((intptr_t)k)) {\n    as->mrm.ofs = ptr2addr(k);\n    as->mrm.base = RID_NONE;\n#if LJ_GC64\n  } else if (checki32(dispofs(as, k))) {\n    as->mrm.ofs = (int32_t)dispofs(as, k);\n    as->mrm.base = RID_DISPATCH;\n  } else if (checki32(mcpofs(as, k)) && checki32(mcpofs(as, k+1)) &&\n\t     checki32(mctopofs(as, k)) && checki32(mctopofs(as, k+1))) {\n    as->mrm.ofs = (int32_t)mcpofs(as, k);\n    as->mrm.base = RID_RIP;\n  } else {  /* Intern 64 bit constant at bottom of mcode. */\n    if (ir->i) {\n      lj_assertA(*k == *(uint64_t*)(as->mctop - ir->i),\n\t\t \"bad interned 64 bit constant\");\n    } else {\n      while ((uintptr_t)as->mcbot & 7) *as->mcbot++ = XI_INT3;\n      *(uint64_t*)as->mcbot = *k;\n      ir->i = (int32_t)(as->mctop - as->mcbot);\n      as->mcbot += 8;\n      as->mclim = as->mcbot + MCLIM_REDZONE;\n      lj_mcode_commitbot(as->J, as->mcbot);\n    }\n    as->mrm.ofs = (int32_t)mcpofs(as, as->mctop - ir->i);\n    as->mrm.base = RID_RIP;\n#endif\n  }\n  as->mrm.idx = RID_NONE;\n  return RID_MRM;\n}\n\n/* Fuse load into memory operand.\n**\n** Important caveat: this may emit RIP-relative loads! So don't place any\n** code emitters between this function and the use of its result.\n** The only permitted exception is asm_guardcc().\n*/\nstatic Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)\n{\n  IRIns *ir = IR(ref);\n  if (ra_hasreg(ir->r)) {\n    if (allow != RSET_EMPTY) {  /* Fast path. */\n      ra_noweak(as, ir->r);\n      return ir->r;\n    }\n  fusespill:\n    /* Force a spill if only memory operands are allowed (asm_x87load). */\n    as->mrm.base = RID_ESP;\n    as->mrm.ofs = ra_spill(as, ir);\n    as->mrm.idx = RID_NONE;\n    return RID_MRM;\n  }\n  if (ir->o == IR_KNUM) {\n    RegSet avail = as->freeset & ~as->modset & RSET_FPR;\n    lj_assertA(allow != RSET_EMPTY, \"no register allowed\");\n    if (!(avail & (avail-1)))  /* Fuse if less than two regs available. */\n      return asm_fuseloadk64(as, ir);\n  } else if (ref == REF_BASE || ir->o == IR_KINT64) {\n    RegSet avail = as->freeset & ~as->modset & RSET_GPR;\n    lj_assertA(allow != RSET_EMPTY, \"no register allowed\");\n    if (!(avail & (avail-1))) {  /* Fuse if less than two regs available. */\n      if (ref == REF_BASE) {\n#if LJ_GC64\n\tas->mrm.ofs = (int32_t)dispofs(as, &J2G(as->J)->jit_base);\n\tas->mrm.base = RID_DISPATCH;\n#else\n\tas->mrm.ofs = ptr2addr(&J2G(as->J)->jit_base);\n\tas->mrm.base = RID_NONE;\n#endif\n\tas->mrm.idx = RID_NONE;\n\treturn RID_MRM;\n      } else {\n\treturn asm_fuseloadk64(as, ir);\n      }\n    }\n  } else if (mayfuse(as, ref)) {\n    RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR;\n    if (ir->o == IR_SLOAD) {\n      if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) &&\n\t  noconflict(as, ref, IR_RETF, 0) &&\n\t  !(LJ_GC64 && irt_isaddr(ir->t))) {\n\tas->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow);\n\tas->mrm.ofs = 8*((int32_t)ir->op1-1-LJ_FR2) +\n\t\t      (!LJ_FR2 && (ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n\tas->mrm.idx = RID_NONE;\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_FLOAD) {\n      /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */\n      if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) &&\n\t  noconflict(as, ref, IR_FSTORE, 0)) {\n\tasm_fusefref(as, ir, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) {\n      if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0) &&\n\t  !(LJ_GC64 && irt_isaddr(ir->t))) {\n\tasm_fuseahuref(as, ir->op1, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_XLOAD) {\n      /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp).\n      ** Fusing unaligned memory operands is ok on x86 (except for SIMD types).\n      */\n      if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) &&\n\t  noconflict(as, ref, IR_XSTORE, 0)) {\n\tasm_fusexref(as, ir->op1, xallow);\n\treturn RID_MRM;\n      }\n    } else if (ir->o == IR_VLOAD && !(LJ_GC64 && irt_isaddr(ir->t))) {\n      asm_fuseahuref(as, ir->op1, xallow);\n      as->mrm.ofs += 8 * ir->op2;\n      return RID_MRM;\n    }\n  }\n  if (ir->o == IR_FLOAD && ir->op1 == REF_NIL) {\n    asm_fusefref(as, ir, RSET_EMPTY);\n    return RID_MRM;\n  }\n  if (!(as->freeset & allow) && !emit_canremat(ref) &&\n      (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref)))\n    goto fusespill;\n  return ra_allocref(as, ref, allow);\n}\n\n#if LJ_64\n/* Don't fuse a 32 bit load into a 64 bit operation. */\nstatic Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64)\n{\n  if (is64 && !irt_is64(IR(ref)->t))\n    return ra_alloc1(as, ref, allow);\n  return asm_fuseload(as, ref, allow);\n}\n#else\n#define asm_fuseloadm(as, ref, allow, is64)  asm_fuseload(as, (ref), (allow))\n#endif\n\n/* -- Calls --------------------------------------------------------------- */\n\n/* Count the required number of stack slots for a call. */\nstatic int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t i, nargs = CCI_XNARGS(ci);\n  int nslots = 0;\n#if LJ_64\n  if (LJ_ABI_WIN) {\n    nslots = (int)(nargs*2);  /* Only matters for more than four args. */\n  } else {\n    int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;\n    for (i = 0; i < nargs; i++)\n      if (args[i] && irt_isfp(IR(args[i])->t)) {\n\tif (nfpr > 0) nfpr--; else nslots += 2;\n      } else {\n\tif (ngpr > 0) ngpr--; else nslots += 2;\n      }\n  }\n#else\n  int ngpr = 0;\n  if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)\n    ngpr = 2;\n  else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)\n    ngpr = 1;\n  for (i = 0; i < nargs; i++)\n    if (args[i] && irt_isfp(IR(args[i])->t)) {\n      nslots += irt_isnum(IR(args[i])->t) ? 2 : 1;\n    } else {\n      if (ngpr > 0) ngpr--; else nslots++;\n    }\n#endif\n  return nslots;\n}\n\n/* Generate a call to a C function. */\nstatic void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)\n{\n  uint32_t n, nargs = CCI_XNARGS(ci);\n  int32_t ofs = STACKARG_OFS;\n#if LJ_64\n  uint32_t gprs = REGARG_GPRS;\n  Reg fpr = REGARG_FIRSTFPR;\n#if !LJ_ABI_WIN\n  MCode *patchnfpr = NULL;\n#endif\n#else\n  uint32_t gprs = 0;\n  if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) {\n    if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)\n      gprs = (REGARG_GPRS & 31);\n    else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)\n      gprs = REGARG_GPRS;\n  }\n#endif\n  if ((void *)ci->func)\n    emit_call(as, ci->func);\n#if LJ_64\n  if ((ci->flags & CCI_VARARG)) {  /* Special handling for vararg calls. */\n#if LJ_ABI_WIN\n    for (n = 0; n < 4 && n < nargs; n++) {\n      IRIns *ir = IR(args[n]);\n      if (irt_isfp(ir->t))  /* Duplicate FPRs in GPRs. */\n\temit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n),\n\t\t((gprs >> (n*5)) & 31));  /* Either MOVD or MOVQ. */\n    }\n#else\n    patchnfpr = --as->mcp;  /* Indicate number of used FPRs in register al. */\n    *--as->mcp = XI_MOVrib | RID_EAX;\n#endif\n  }\n#endif\n  for (n = 0; n < nargs; n++) {  /* Setup args. */\n    IRRef ref = args[n];\n    IRIns *ir = IR(ref);\n    Reg r;\n#if LJ_64 && LJ_ABI_WIN\n    /* Windows/x64 argument registers are strictly positional. */\n    r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);\n    fpr++; gprs >>= 5;\n#elif LJ_64\n    /* POSIX/x64 argument registers are used in order of appearance. */\n    if (irt_isfp(ir->t)) {\n      r = fpr <= REGARG_LASTFPR ? fpr++ : 0;\n    } else {\n      r = gprs & 31; gprs >>= 5;\n    }\n#else\n    if (ref && irt_isfp(ir->t)) {\n      r = 0;\n    } else {\n      r = gprs & 31; gprs >>= 5;\n      if (!ref) continue;\n    }\n#endif\n    if (r) {  /* Argument is in a register. */\n      if (r < RID_MAX_GPR && ref < ASMREF_TMP1) {\n#if LJ_64\n\tif (LJ_GC64 ? !(ir->o == IR_KINT || ir->o == IR_KNULL) : ir->o == IR_KINT64)\n\t  emit_loadu64(as, r, ir_k64(ir)->u64);\n\telse\n#endif\n\t  emit_loadi(as, r, ir->i);\n      } else {\n\t/* Must have been evicted. */\n\tlj_assertA(rset_test(as->freeset, r), \"reg %d not free\", r);\n\tif (ra_hasreg(ir->r)) {\n\t  ra_noweak(as, ir->r);\n\t  emit_movrr(as, ir, r, ir->r);\n\t} else {\n\t  ra_allocref(as, ref, RID2RSET(r));\n\t}\n      }\n    } else if (irt_isfp(ir->t)) {  /* FP argument is on stack. */\n      lj_assertA(!(irt_isfloat(ir->t) && irref_isk(ref)),\n\t\t \"unexpected float constant\");\n      if (LJ_32 && (ofs & 4) && irref_isk(ref)) {\n\t/* Split stores for unaligned FP consts. */\n\temit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo);\n\temit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi);\n      } else {\n\tr = ra_alloc1(as, ref, RSET_FPR);\n\temit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto,\n\t\t  r, RID_ESP, ofs);\n      }\n      ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8;\n    } else {  /* Non-FP argument is on stack. */\n      if (LJ_32 && ref < ASMREF_TMP1) {\n\temit_movmroi(as, RID_ESP, ofs, ir->i);\n      } else {\n\tr = ra_alloc1(as, ref, RSET_GPR);\n\temit_movtomro(as, REX_64 + r, RID_ESP, ofs);\n      }\n      ofs += sizeof(intptr_t);\n    }\n    checkmclim(as);\n  }\n#if LJ_64 && !LJ_ABI_WIN\n  if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR;\n#endif\n}\n\n/* Setup result reg/sp for call. Evict scratch regs. */\nstatic void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  RegSet drop = RSET_SCRATCH;\n  int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));\n  if ((ci->flags & CCI_NOFPRCLOBBER))\n    drop &= ~RSET_FPR;\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  if (hiop && ra_hasreg((ir+1)->r))\n    rset_clear(drop, (ir+1)->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);  /* Evictions must be performed first. */\n  if (ra_used(ir)) {\n    if (irt_isfp(ir->t)) {\n      int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n#if LJ_64\n      if ((ci->flags & CCI_CASTU64)) {\n\tReg dest = ir->r;\n\tif (ra_hasreg(dest)) {\n\t  ra_free(as, dest);\n\t  ra_modified(as, dest);\n\t  emit_rr(as, XO_MOVD, dest|REX_64, RID_RET);  /* Really MOVQ. */\n\t}\n\tif (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs);\n      } else {\n\tra_destreg(as, ir, RID_FPRET);\n      }\n#else\n      /* Number result is in x87 st0 for x86 calling convention. */\n      Reg dest = ir->r;\n      if (ra_hasreg(dest)) {\n\tra_free(as, dest);\n\tra_modified(as, dest);\n\temit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS,\n\t\t  dest, RID_ESP, ofs);\n      }\n      if ((ci->flags & CCI_CASTU64)) {\n\temit_movtomro(as, RID_RETLO, RID_ESP, ofs);\n\temit_movtomro(as, RID_RETHI, RID_ESP, ofs+4);\n      } else {\n\temit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,\n\t\t  irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);\n      }\n#endif\n    } else if (hiop) {\n      ra_destpair(as, ir);\n    } else {\n      lj_assertA(!irt_ispri(ir->t), \"PRI dest\");\n      ra_destreg(as, ir, RID_RET);\n    }\n  } else if (LJ_32 && irt_isfp(ir->t) && !(ci->flags & CCI_CASTU64)) {\n    emit_x87op(as, XI_FPOP);  /* Pop unused result from x87 st0. */\n  }\n}\n\n/* Return a constant function pointer or NULL for indirect calls. */\nstatic void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func)\n{\n#if LJ_32\n  UNUSED(as);\n  if (irref_isk(func))\n    return (void *)irf->i;\n#else\n  if (irref_isk(func)) {\n    MCode *p;\n    if (irf->o == IR_KINT64)\n      p = (MCode *)(void *)ir_k64(irf)->u64;\n    else\n      p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i;\n    if (p - as->mcp == (int32_t)(p - as->mcp))\n      return p;  /* Call target is still in +-2GB range. */\n    /* Avoid the indirect case of emit_call(). Try to hoist func addr. */\n  }\n#endif\n  return NULL;\n}\n\nstatic void asm_callx(ASMState *as, IRIns *ir)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  CCallInfo ci;\n  IRRef func;\n  IRIns *irf;\n  int32_t spadj = 0;\n  ci.flags = asm_callx_flags(as, ir);\n  asm_collectargs(as, ir, &ci, args);\n  asm_setupresult(as, ir, &ci);\n#if LJ_32\n  /* Have to readjust stack after non-cdecl calls due to callee cleanup. */\n  if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)\n    spadj = 4 * asm_count_call_slots(as, &ci, args);\n#endif\n  func = ir->op2; irf = IR(func);\n  if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }\n  ci.func = (ASMFunction)asm_callx_func(as, irf, func);\n  if (!(void *)ci.func) {\n    /* Use a (hoistable) non-scratch register for indirect calls. */\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n    Reg r = ra_alloc1(as, func, allow);\n    if (LJ_32) emit_spsub(as, spadj);  /* Above code may cause restores! */\n    emit_rr(as, XO_GROUP5, XOg_CALL, r);\n  } else if (LJ_32) {\n    emit_spsub(as, spadj);\n  }\n  asm_gencall(as, &ci, args);\n}\n\n/* -- Returns ------------------------------------------------------------- */\n\n/* Return to lower frame. Guard that it goes to the right spot. */\nstatic void asm_retf(ASMState *as, IRIns *ir)\n{\n  Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);\n#if LJ_FR2\n  Reg rpc = ra_scratch(as, rset_exclude(RSET_GPR, base));\n#endif\n  void *pc = ir_kptr(IR(ir->op2));\n  int32_t delta = 1+LJ_FR2+bc_a(*((const BCIns *)pc - 1));\n  as->topslot -= (BCReg)delta;\n  if ((int32_t)as->topslot < 0) as->topslot = 0;\n  irt_setmark(IR(REF_BASE)->t);  /* Children must not coalesce with BASE reg. */\n  emit_setgl(as, base, jit_base);\n  emit_addptr(as, base, -8*delta);\n  asm_guardcc(as, CC_NE);\n#if LJ_FR2\n  emit_rmro(as, XO_CMP, rpc|REX_GC64, base, -8);\n  emit_loadu64(as, rpc, u64ptr(pc));\n#else\n  emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc));\n#endif\n}\n\n/* -- Buffer operations --------------------------------------------------- */\n\n#if LJ_HASBUFFER\nstatic void asm_bufhdr_write(ASMState *as, Reg sb)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));\n  IRIns irgc;\n  irgc.ot = IRT(0, IRT_PGC);  /* GC type. */\n  emit_storeofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n  emit_opgl(as, XO_ARITH(XOg_OR), tmp|REX_GC64, cur_L);\n  emit_gri(as, XG_ARITHi(XOg_AND), tmp, SBUF_MASK_FLAG);\n  emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L));\n}\n#endif\n\n/* -- Type conversions ---------------------------------------------------- */\n\nstatic void asm_tointg(ASMState *as, IRIns *ir, Reg left)\n{\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_guardcc(as, CC_P);\n  asm_guardcc(as, CC_NE);\n  emit_rr(as, XO_UCOMISD, left, tmp);\n  emit_rr(as, XO_CVTSI2SD, tmp, dest);\n  emit_rr(as, XO_XORPS, tmp, tmp);  /* Avoid partial register stall. */\n  emit_rr(as, XO_CVTTSD2SI, dest, left);\n  /* Can't fuse since left is needed twice. */\n}\n\nstatic void asm_tobit(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  Reg tmp = ra_noreg(IR(ir->op1)->r) ?\n\t      ra_alloc1(as, ir->op1, RSET_FPR) :\n\t      ra_scratch(as, RSET_FPR);\n  Reg right;\n  emit_rr(as, XO_MOVDto, tmp, dest);\n  right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp));\n  emit_mrm(as, XO_ADDSD, tmp, right);\n  ra_left(as, tmp, ir->op1);\n}\n\nstatic void asm_conv(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n  int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64));\n  int stfp = (st == IRT_NUM || st == IRT_FLOAT);\n  IRRef lref = ir->op1;\n  lj_assertA(irt_type(ir->t) != st, \"inconsistent types for CONV\");\n  lj_assertA(!(LJ_32 && (irt_isint64(ir->t) || st64)),\n\t     \"IR %04d has unsplit 64 bit type\",\n\t     (int)(ir - as->ir) - REF_BIAS);\n  if (irt_isfp(ir->t)) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    if (stfp) {  /* FP to FP conversion. */\n      Reg left = asm_fuseload(as, lref, RSET_FPR);\n      emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left);\n      if (left == dest) return;  /* Avoid the XO_XORPS. */\n    } else if (LJ_32 && st == IRT_U32) {  /* U32 to FP conversion on x86. */\n      /* number = (2^52+2^51 .. u32) - (2^52+2^51) */\n      cTValue *k = &as->J->k64[LJ_K64_TOBIT];\n      Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest));\n      if (irt_isfloat(ir->t))\n\temit_rr(as, XO_CVTSD2SS, dest, dest);\n      emit_rr(as, XO_SUBSD, dest, bias);  /* Subtract 2^52+2^51 bias. */\n      emit_rr(as, XO_XORPS, dest, bias);  /* Merge bias and integer. */\n      emit_rma(as, XO_MOVSD, bias, k);\n      emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR));\n      return;\n    } else {  /* Integer to FP conversion. */\n      Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ?\n\t\t ra_alloc1(as, lref, RSET_GPR) :\n\t\t asm_fuseloadm(as, lref, RSET_GPR, st64);\n      if (LJ_64 && st == IRT_U64) {\n\tMCLabel l_end = emit_label(as);\n\tcTValue *k = &as->J->k64[LJ_K64_2P64];\n\temit_rma(as, XO_ADDSD, dest, k);  /* Add 2^64 to compensate. */\n\temit_sjcc(as, CC_NS, l_end);\n\temit_rr(as, XO_TEST, left|REX_64, left);  /* Check if u64 >= 2^63. */\n      }\n      emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS,\n\t       dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left);\n    }\n    emit_rr(as, XO_XORPS, dest, dest);  /* Avoid partial register stall. */\n  } else if (stfp) {  /* FP to integer conversion. */\n    if (irt_isguard(ir->t)) {\n      /* Checked conversions are only supported from number to int. */\n      lj_assertA(irt_isint(ir->t) && st == IRT_NUM,\n\t\t \"bad type for checked CONV\");\n      asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      x86Op op = st == IRT_NUM ? XO_CVTTSD2SI : XO_CVTTSS2SI;\n      if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) {\n\t/* LJ_64: For inputs >= 2^63 add -2^64, convert again. */\n\t/* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */\n\tReg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) :\n\t\t\t\t\t  ra_scratch(as, RSET_FPR);\n\tMCLabel l_end = emit_label(as);\n\tif (LJ_32)\n\t  emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000);\n\temit_rr(as, op, dest|REX_64, tmp);\n\tif (st == IRT_NUM)\n\t  emit_rma(as, XO_ADDSD, tmp, &as->J->k64[LJ_K64_M2P64_31]);\n\telse\n\t  emit_rma(as, XO_ADDSS, tmp, &as->J->k32[LJ_K32_M2P64_31]);\n\temit_sjcc(as, CC_NS, l_end);\n\temit_rr(as, XO_TEST, dest|REX_64, dest);  /* Check if dest negative. */\n\temit_rr(as, op, dest|REX_64, tmp);\n\tra_left(as, tmp, lref);\n      } else {\n\tif (LJ_64 && irt_isu32(ir->t))\n\t  emit_rr(as, XO_MOV, dest, dest);  /* Zero hiword. */\n\temit_mrm(as, op,\n\t\t dest|((LJ_64 &&\n\t\t\t(irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0),\n\t\t asm_fuseload(as, lref, RSET_FPR));\n      }\n    }\n  } else if (st >= IRT_I8 && st <= IRT_U16) {  /* Extend to 32 bit integer. */\n    Reg left, dest = ra_dest(as, ir, RSET_GPR);\n    RegSet allow = RSET_GPR;\n    x86Op op;\n    lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t), \"bad type for CONV EXT\");\n    if (st == IRT_I8) {\n      op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX;\n    } else if (st == IRT_U8) {\n      op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX;\n    } else if (st == IRT_I16) {\n      op = XO_MOVSXw;\n    } else {\n      op = XO_MOVZXw;\n    }\n    left = asm_fuseload(as, lref, allow);\n    /* Add extra MOV if source is already in wrong register. */\n    if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) {\n      Reg tmp = ra_scratch(as, allow);\n      emit_rr(as, op, dest, tmp);\n      emit_rr(as, XO_MOV, tmp, left);\n    } else {\n      emit_mrm(as, op, dest, left);\n    }\n  } else {  /* 32/64 bit integer conversions. */\n    if (LJ_32) {  /* Only need to handle 32/32 bit no-op (cast) on x86. */\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      ra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n    } else if (irt_is64(ir->t)) {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      if (st64 || !(ir->op2 & IRCONV_SEXT)) {\n\t/* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */\n\tra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      } else {  /* 32 to 64 bit sign extension. */\n\tReg left = asm_fuseload(as, lref, RSET_GPR);\n\temit_mrm(as, XO_MOVSXd, dest|REX_64, left);\n      }\n    } else {\n      Reg dest = ra_dest(as, ir, RSET_GPR);\n      if (st64 && !(ir->op2 & IRCONV_NONE)) {\n\tReg left = asm_fuseload(as, lref, RSET_GPR);\n\t/* This is either a 32 bit reg/reg mov which zeroes the hiword\n\t** or a load of the loword from a 64 bit address.\n\t*/\n\temit_mrm(as, XO_MOV, dest, left);\n      } else {  /* 32/32 bit no-op (cast). */\n\tra_left(as, dest, lref);  /* Do nothing, but may need to move regs. */\n      }\n    }\n  }\n}\n\n#if LJ_32 && LJ_HASFFI\n/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */\n\n/* 64 bit integer to FP conversion in 32 bit mode. */\nstatic void asm_conv_fp_int64(ASMState *as, IRIns *ir)\n{\n  Reg hi = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi));\n  int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS, dest, RID_ESP, ofs);\n  }\n  emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,\n\t    irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);\n  if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) {\n    /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */\n    MCLabel l_end = emit_label(as);\n    emit_rma(as, XO_FADDq, XOg_FADDq, &as->J->k64[LJ_K64_2P64]);\n    emit_sjcc(as, CC_NS, l_end);\n    emit_rr(as, XO_TEST, hi, hi);  /* Check if u64 >= 2^63. */\n  } else {\n    lj_assertA(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64, \"bad type for CONV\");\n  }\n  emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0);\n  /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */\n  emit_rmro(as, XO_MOVto, hi, RID_ESP, 4);\n  emit_rmro(as, XO_MOVto, lo, RID_ESP, 0);\n}\n\n/* FP to 64 bit integer conversion in 32 bit mode. */\nstatic void asm_conv_int64_fp(ASMState *as, IRIns *ir)\n{\n  IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);\n  IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);\n  Reg lo, hi;\n  lj_assertA(st == IRT_NUM || st == IRT_FLOAT, \"bad type for CONV\");\n  lj_assertA(dt == IRT_I64 || dt == IRT_U64, \"bad type for CONV\");\n  hi = ra_dest(as, ir, RSET_GPR);\n  lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi));\n  if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0);\n  /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */\n  if (!(as->flags & JIT_F_SSE3)) {  /* Set FPU rounding mode to default. */\n    emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4);\n    emit_rmro(as, XO_MOVto, lo, RID_ESP, 4);\n    emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff);\n  }\n  if (dt == IRT_U64) {\n    /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */\n    MCLabel l_pop, l_end = emit_label(as);\n    emit_x87op(as, XI_FPOP);\n    l_pop = emit_label(as);\n    emit_sjmp(as, l_end);\n    emit_rmro(as, XO_MOV, hi, RID_ESP, 4);\n    if ((as->flags & JIT_F_SSE3))\n      emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);\n    else\n      emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);\n    emit_rma(as, XO_FADDq, XOg_FADDq, &as->J->k64[LJ_K64_M2P64]);\n    emit_sjcc(as, CC_NS, l_pop);\n    emit_rr(as, XO_TEST, hi, hi);  /* Check if out-of-range (2^63). */\n  }\n  emit_rmro(as, XO_MOV, hi, RID_ESP, 4);\n  if ((as->flags & JIT_F_SSE3)) {  /* Truncation is easy with SSE3. */\n    emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);\n  } else {  /* Otherwise set FPU rounding mode to truncate before the store. */\n    emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);\n    emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0);\n    emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0);\n    emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0);\n    emit_loadi(as, lo, 0xc00);\n    emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0);\n  }\n  if (dt == IRT_U64)\n    emit_x87op(as, XI_FDUP);\n  emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd,\n\t   st == IRT_NUM ? XOg_FLDq: XOg_FLDd,\n\t   asm_fuseload(as, ir->op1, RSET_EMPTY));\n}\n\nstatic void asm_conv64(ASMState *as, IRIns *ir)\n{\n  if (irt_isfp(ir->t))\n    asm_conv_fp_int64(as, ir);\n  else\n    asm_conv_int64_fp(as, ir);\n}\n#endif\n\nstatic void asm_strto(ASMState *as, IRIns *ir)\n{\n  /* Force a spill slot for the destination register (if any). */\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];\n  IRRef args[2];\n  RegSet drop = RSET_SCRATCH;\n  if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r))\n    rset_set(drop, ir->r);  /* WIN64 doesn't spill all FPRs. */\n  ra_evictset(as, drop);\n  asm_guardcc(as, CC_E);\n  emit_rr(as, XO_TEST, RID_RET, RID_RET);  /* Test return status. */\n  args[0] = ir->op1;      /* GCstr *str */\n  args[1] = ASMREF_TMP1;  /* TValue *n  */\n  asm_gencall(as, ci, args);\n  /* Store the result to the spill slot or temp slots. */\n  emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,\n\t    RID_ESP, sps_scale(ir->s));\n}\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Get pointer to TValue. */\nstatic void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode)\n{\n  if ((mode & IRTMPREF_IN1)) {\n    IRIns *ir = IR(ref);\n    if (irt_isnum(ir->t)) {\n      if (irref_isk(ref) && !(mode & IRTMPREF_OUT1)) {\n\t/* Use the number constant itself as a TValue. */\n\temit_loada(as, dest, ir_knum(ir));\n\treturn;\n      }\n      emit_rmro(as, XO_MOVSDto, ra_alloc1(as, ref, RSET_FPR), dest, 0);\n    } else {\n#if LJ_GC64\n      if (irref_isk(ref)) {\n\tTValue k;\n\tlj_ir_kvalue(as->J->L, &k, ir);\n\temit_movmroi(as, dest, 4, k.u32.hi);\n\temit_movmroi(as, dest, 0, k.u32.lo);\n      } else {\n\t/* TODO: 64 bit store + 32 bit load-modify-store is suboptimal. */\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, dest));\n\tif (irt_is64(ir->t)) {\n\t  emit_u32(as, irt_toitype(ir->t) << 15);\n\t  emit_rmro(as, XO_ARITHi, XOg_OR, dest, 4);\n\t} else {\n\t  emit_movmroi(as, dest, 4, (irt_toitype(ir->t) << 15));\n\t}\n\temit_movtomro(as, REX_64IR(ir, src), dest, 0);\n      }\n#else\n      if (!irref_isk(ref)) {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, dest));\n\temit_movtomro(as, REX_64IR(ir, src), dest, 0);\n      } else if (!irt_ispri(ir->t)) {\n\temit_movmroi(as, dest, 0, ir->i);\n      }\n      if (!(LJ_64 && irt_islightud(ir->t)))\n\temit_movmroi(as, dest, 4, irt_toitype(ir->t));\n#endif\n    }\n  }\n  emit_loada(as, dest, &J2G(as->J)->tmptv); /* g->tmptv holds the TValue(s). */\n}\n\nstatic void asm_aref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusearef(as, ir, RSET_GPR);\n  if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0))\n    emit_mrm(as, XO_LEA, dest|REX_GC64, RID_MRM);\n  else if (as->mrm.base != dest)\n    emit_rr(as, XO_MOV, dest|REX_GC64, as->mrm.base);\n}\n\n/* Inlined hash lookup. Specialized for key type and for const keys.\n** The equivalent C code is:\n**   Node *n = hashkey(t, key);\n**   do {\n**     if (lj_obj_equal(&n->key, key)) return &n->val;\n**   } while ((n = nextnode(n)));\n**   return niltv(L);\n*/\nstatic void asm_href(ASMState *as, IRIns *ir, IROp merge)\n{\n  RegSet allow = RSET_GPR;\n  int destused = ra_used(ir);\n  Reg dest = ra_dest(as, ir, allow);\n  Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));\n  Reg key = RID_NONE, tmp = RID_NONE;\n  IRIns *irkey = IR(ir->op2);\n  int isk = irref_isk(ir->op2);\n  IRType1 kt = irkey->t;\n  uint32_t khash;\n  MCLabel l_end, l_loop, l_next;\n\n  if (!isk) {\n    rset_clear(allow, tab);\n    key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow);\n    if (LJ_GC64 || !irt_isstr(kt))\n      tmp = ra_scratch(as, rset_exclude(allow, key));\n  }\n\n  /* Key not found in chain: jump to exit (if merged) or load niltv. */\n  l_end = emit_label(as);\n  if (merge == IR_NE)\n    asm_guardcc(as, CC_E);  /* XI_JMP is not found by lj_asm_patchexit. */\n  else if (destused)\n    emit_loada(as, dest, niltvg(J2G(as->J)));\n\n  /* Follow hash chain until the end. */\n  l_loop = emit_sjcc_label(as, CC_NZ);\n  emit_rr(as, XO_TEST, dest|REX_GC64, dest);\n  emit_rmro(as, XO_MOV, dest|REX_GC64, dest, offsetof(Node, next));\n  l_next = emit_label(as);\n\n  /* Type and value comparison. */\n  if (merge == IR_EQ)\n    asm_guardcc(as, CC_E);\n  else\n    emit_sjcc(as, CC_E, l_end);\n  if (irt_isnum(kt)) {\n    if (isk) {\n      /* Assumes -0.0 is already canonicalized to +0.0. */\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo),\n\t\t (int32_t)ir_knum(irkey)->u32.lo);\n      emit_sjcc(as, CC_NE, l_next);\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi),\n\t\t (int32_t)ir_knum(irkey)->u32.hi);\n    } else {\n      emit_sjcc(as, CC_P, l_next);\n      emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n));\n      emit_sjcc(as, CC_AE, l_next);\n      /* The type check avoids NaN penalties and complaints from Valgrind. */\n#if LJ_64 && !LJ_GC64\n      emit_u32(as, LJ_TISNUM);\n      emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it));\n#else\n      emit_i8(as, LJ_TISNUM);\n      emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));\n#endif\n    }\n#if LJ_64 && !LJ_GC64\n  } else if (irt_islightud(kt)) {\n    emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64));\n#endif\n#if LJ_GC64\n  } else if (irt_isaddr(kt)) {\n    if (isk) {\n      TValue k;\n      k.u64 = ((uint64_t)irt_toitype(irkey->t) << 47) | irkey[1].tv.u64;\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo),\n\t\t k.u32.lo);\n      emit_sjcc(as, CC_NE, l_next);\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi),\n\t\t k.u32.hi);\n    } else {\n      emit_rmro(as, XO_CMP, tmp|REX_64, dest, offsetof(Node, key.u64));\n    }\n  } else {\n    lj_assertA(irt_ispri(kt) && !irt_isnil(kt), \"bad HREF key type\");\n    emit_u32(as, (irt_toitype(kt)<<15)|0x7fff);\n    emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it));\n#else\n  } else {\n    if (!irt_ispri(kt)) {\n      lj_assertA(irt_isaddr(kt), \"bad HREF key type\");\n      if (isk)\n\temit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr),\n\t\t   ptr2addr(ir_kgc(irkey)));\n      else\n\temit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr));\n      emit_sjcc(as, CC_NE, l_next);\n    }\n    lj_assertA(!irt_isnil(kt), \"bad HREF key type\");\n    emit_i8(as, irt_toitype(kt));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));\n#endif\n  }\n  emit_sfixup(as, l_loop);\n  checkmclim(as);\n#if LJ_GC64\n  if (!isk && irt_isaddr(kt)) {\n    emit_rr(as, XO_OR, tmp|REX_64, key);\n    emit_loadu64(as, tmp, (uint64_t)irt_toitype(kt) << 47);\n  }\n#endif\n\n  /* Load main position relative to tab->node into dest. */\n  khash = isk ? ir_khash(as, irkey) : 1;\n  if (khash == 0) {\n    emit_rmro(as, XO_MOV, dest|REX_GC64, tab, offsetof(GCtab, node));\n  } else {\n    emit_rmro(as, XO_ARITH(XOg_ADD), dest|REX_GC64, tab, offsetof(GCtab,node));\n    emit_shifti(as, XOg_SHL, dest, 3);\n    emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0);\n    if (isk) {\n      emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash);\n      emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));\n    } else if (irt_isstr(kt)) {\n      emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, sid));\n      emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));\n    } else {  /* Must match with hashrot() in lj_tab.c. */\n      emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask));\n      emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp);\n      emit_shifti(as, XOg_ROL, tmp, HASH_ROT3);\n      emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp);\n      emit_shifti(as, XOg_ROL, dest, HASH_ROT2);\n      emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest);\n      emit_shifti(as, XOg_ROL, dest, HASH_ROT1);\n      emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest);\n      if (irt_isnum(kt)) {\n\temit_rr(as, XO_ARITH(XOg_ADD), dest, dest);\n#if LJ_64\n\temit_shifti(as, XOg_SHR|REX_64, dest, 32);\n\temit_rr(as, XO_MOV, tmp, dest);\n\temit_rr(as, XO_MOVDto, key|REX_64, dest);\n#else\n\temit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4);\n\temit_rr(as, XO_MOVDto, key, tmp);\n#endif\n      } else {\n\temit_rr(as, XO_MOV, tmp, key);\n#if LJ_GC64\n\tcheckmclim(as);\n\temit_gri(as, XG_ARITHi(XOg_XOR), dest, irt_toitype(kt) << 15);\n\tif ((as->flags & JIT_F_BMI2)) {\n\t  emit_i8(as, 32);\n\t  emit_mrm(as, XV_RORX|VEX_64, dest, key);\n\t} else {\n\t  emit_shifti(as, XOg_SHR|REX_64, dest, 32);\n\t  emit_rr(as, XO_MOV, dest|REX_64, key|REX_64);\n\t}\n#else\n\temit_rmro(as, XO_LEA, dest, key, HASH_BIAS);\n#endif\n      }\n    }\n  }\n}\n\nstatic void asm_hrefk(ASMState *as, IRIns *ir)\n{\n  IRIns *kslot = IR(ir->op2);\n  IRIns *irkey = IR(kslot->op1);\n  int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));\n  Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;\n  Reg node = ra_alloc1(as, ir->op1, RSET_GPR);\n#if !LJ_64\n  MCLabel l_exit;\n#endif\n  lj_assertA(ofs % sizeof(Node) == 0, \"unaligned HREFK slot\");\n  if (ra_hasreg(dest)) {\n    if (ofs != 0) {\n      if (dest == node)\n\temit_gri(as, XG_ARITHi(XOg_ADD), dest|REX_GC64, ofs);\n      else\n\temit_rmro(as, XO_LEA, dest|REX_GC64, node, ofs);\n    } else if (dest != node) {\n      emit_rr(as, XO_MOV, dest|REX_GC64, node);\n    }\n  }\n  asm_guardcc(as, CC_NE);\n#if LJ_64\n  if (!irt_ispri(irkey->t)) {\n    Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node));\n    emit_rmro(as, XO_CMP, key|REX_64, node,\n\t       ofs + (int32_t)offsetof(Node, key.u64));\n    lj_assertA(irt_isnum(irkey->t) || irt_isgcv(irkey->t),\n\t       \"bad HREFK key type\");\n    /* Assumes -0.0 is already canonicalized to +0.0. */\n    emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 :\n#if LJ_GC64\n\t\t\t  ((uint64_t)irt_toitype(irkey->t) << 47) |\n\t\t\t  (uint64_t)ir_kgc(irkey));\n#else\n\t\t\t  ((uint64_t)irt_toitype(irkey->t) << 32) |\n\t\t\t  (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey)));\n#endif\n  } else {\n    lj_assertA(!irt_isnil(irkey->t), \"bad HREFK key type\");\n#if LJ_GC64\n    emit_i32(as, (irt_toitype(irkey->t)<<15)|0x7fff);\n    emit_rmro(as, XO_ARITHi, XOg_CMP, node,\n\t      ofs + (int32_t)offsetof(Node, key.it));\n#else\n    emit_i8(as, irt_toitype(irkey->t));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, node,\n\t      ofs + (int32_t)offsetof(Node, key.it));\n#endif\n  }\n#else\n  l_exit = emit_label(as);\n  if (irt_isnum(irkey->t)) {\n    /* Assumes -0.0 is already canonicalized to +0.0. */\n    emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t       ofs + (int32_t)offsetof(Node, key.u32.lo),\n\t       (int32_t)ir_knum(irkey)->u32.lo);\n    emit_sjcc(as, CC_NE, l_exit);\n    emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t       ofs + (int32_t)offsetof(Node, key.u32.hi),\n\t       (int32_t)ir_knum(irkey)->u32.hi);\n  } else {\n    if (!irt_ispri(irkey->t)) {\n      lj_assertA(irt_isgcv(irkey->t), \"bad HREFK key type\");\n      emit_gmroi(as, XG_ARITHi(XOg_CMP), node,\n\t\t ofs + (int32_t)offsetof(Node, key.gcr),\n\t\t ptr2addr(ir_kgc(irkey)));\n      emit_sjcc(as, CC_NE, l_exit);\n    }\n    lj_assertA(!irt_isnil(irkey->t), \"bad HREFK key type\");\n    emit_i8(as, irt_toitype(irkey->t));\n    emit_rmro(as, XO_ARITHi8, XOg_CMP, node,\n\t      ofs + (int32_t)offsetof(Node, key.it));\n  }\n#endif\n}\n\nstatic void asm_uref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  if (irref_isk(ir->op1)) {\n    GCfunc *fn = ir_kfunc(IR(ir->op1));\n    MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;\n    emit_rma(as, XO_MOV, dest|REX_GC64, v);\n  } else {\n    Reg uv = ra_scratch(as, RSET_GPR);\n    Reg func = ra_alloc1(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_UREFC) {\n      emit_rmro(as, XO_LEA, dest|REX_GC64, uv, offsetof(GCupval, tv));\n      asm_guardcc(as, CC_NE);\n      emit_i8(as, 1);\n      emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed));\n    } else {\n      emit_rmro(as, XO_MOV, dest|REX_GC64, uv, offsetof(GCupval, v));\n    }\n    emit_rmro(as, XO_MOV, uv|REX_GC64, func,\n\t      (int32_t)offsetof(GCfuncL, uvptr) +\n\t      (int32_t)sizeof(MRef) * (int32_t)(ir->op2 >> 8));\n  }\n}\n\nstatic void asm_fref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusefref(as, ir, RSET_GPR);\n  emit_mrm(as, XO_LEA, dest, RID_MRM);\n}\n\nstatic void asm_strref(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  asm_fusestrref(as, ir, RSET_GPR);\n  if (as->mrm.base == RID_NONE)\n    emit_loadi(as, dest, as->mrm.ofs);\n  else if (as->mrm.base == dest && as->mrm.idx == RID_NONE)\n    emit_gri(as, XG_ARITHi(XOg_ADD), dest|REX_GC64, as->mrm.ofs);\n  else\n    emit_mrm(as, XO_LEA, dest|REX_GC64, RID_MRM);\n}\n\n/* -- Loads and stores ---------------------------------------------------- */\n\nstatic void asm_fxload(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);\n  x86Op xo;\n  if (ir->o == IR_FLOAD)\n    asm_fusefref(as, ir, RSET_GPR);\n  else\n    asm_fusexref(as, ir->op1, RSET_GPR);\n  /* ir->op2 is ignored -- unaligned loads are ok on x86. */\n  switch (irt_type(ir->t)) {\n  case IRT_I8: xo = XO_MOVSXb; break;\n  case IRT_U8: xo = XO_MOVZXb; break;\n  case IRT_I16: xo = XO_MOVSXw; break;\n  case IRT_U16: xo = XO_MOVZXw; break;\n  case IRT_NUM: xo = XO_MOVSD; break;\n  case IRT_FLOAT: xo = XO_MOVSS; break;\n  default:\n    if (LJ_64 && irt_is64(ir->t))\n      dest |= REX_64;\n    else\n      lj_assertA(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t),\n\t\t \"unsplit 64 bit load\");\n    xo = XO_MOV;\n    break;\n  }\n  emit_mrm(as, xo, dest, RID_MRM);\n}\n\n#define asm_fload(as, ir)\tasm_fxload(as, ir)\n#define asm_xload(as, ir)\tasm_fxload(as, ir)\n\nstatic void asm_fxstore(ASMState *as, IRIns *ir)\n{\n  RegSet allow = RSET_GPR;\n  Reg src = RID_NONE, osrc = RID_NONE;\n  int32_t k = 0;\n  if (ir->r == RID_SINK)\n    return;\n  /* The IRT_I16/IRT_U16 stores should never be simplified for constant\n  ** values since mov word [mem], imm16 has a length-changing prefix.\n  */\n  if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) ||\n      !asm_isk32(as, ir->op2, &k)) {\n    RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR :\n\t\t    (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR;\n    src = osrc = ra_alloc1(as, ir->op2, allow8);\n    if (!LJ_64 && !rset_test(allow8, src)) {  /* Already in wrong register. */\n      rset_clear(allow, osrc);\n      src = ra_scratch(as, allow8);\n    }\n    rset_clear(allow, src);\n  }\n  if (ir->o == IR_FSTORE) {\n    asm_fusefref(as, IR(ir->op1), allow);\n  } else {\n    asm_fusexref(as, ir->op1, allow);\n    if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4;\n  }\n  if (ra_hasreg(src)) {\n    x86Op xo;\n    switch (irt_type(ir->t)) {\n    case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break;\n    case IRT_I16: case IRT_U16: xo = XO_MOVtow; break;\n    case IRT_NUM: xo = XO_MOVSDto; break;\n    case IRT_FLOAT: xo = XO_MOVSSto; break;\n#if LJ_64 && !LJ_GC64\n    case IRT_LIGHTUD:\n      /* NYI: mask 64 bit lightuserdata. */\n      lj_assertA(0, \"store of lightuserdata\");\n#endif\n    default:\n      if (LJ_64 && irt_is64(ir->t))\n\tsrc |= REX_64;\n      else\n\tlj_assertA(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t),\n\t\t   \"unsplit 64 bit store\");\n      xo = XO_MOVto;\n      break;\n    }\n    emit_mrm(as, xo, src, RID_MRM);\n    if (!LJ_64 && src != osrc) {\n      ra_noweak(as, osrc);\n      emit_rr(as, XO_MOV, src, osrc);\n    }\n  } else {\n    if (irt_isi8(ir->t) || irt_isu8(ir->t)) {\n      emit_i8(as, k);\n      emit_mrm(as, XO_MOVmib, 0, RID_MRM);\n    } else {\n      lj_assertA(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) ||\n\t\t irt_isaddr(ir->t), \"bad store type\");\n      emit_i32(as, k);\n      emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM);\n    }\n  }\n}\n\n#define asm_fstore(as, ir)\tasm_fxstore(as, ir)\n#define asm_xstore(as, ir)\tasm_fxstore(as, ir)\n\n#if LJ_64 && !LJ_GC64\nstatic Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck)\n{\n  if (ra_used(ir) || typecheck) {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    if (typecheck) {\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest));\n      asm_guardcc(as, CC_NE);\n      emit_i8(as, -2);\n      emit_rr(as, XO_ARITHi8, XOg_CMP, tmp);\n      emit_shifti(as, XOg_SAR|REX_64, tmp, 47);\n      emit_rr(as, XO_MOV, tmp|REX_64, dest);\n    }\n    return dest;\n  } else {\n    return RID_NONE;\n  }\n}\n#endif\n\nstatic void asm_ahuvload(ASMState *as, IRIns *ir)\n{\n#if LJ_GC64\n  Reg tmp = RID_NONE;\n#endif\n  lj_assertA(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) ||\n\t     (LJ_DUALNUM && irt_isint(ir->t)),\n\t     \"bad load type %d\", irt_type(ir->t));\n#if LJ_64 && !LJ_GC64\n  if (irt_islightud(ir->t)) {\n    Reg dest = asm_load_lightud64(as, ir, 1);\n    if (ra_hasreg(dest)) {\n      asm_fuseahuref(as, ir->op1, RSET_GPR);\n      if (ir->o == IR_VLOAD) as->mrm.ofs += 8 * ir->op2;\n      emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM);\n    }\n    return;\n  } else\n#endif\n  if (ra_used(ir)) {\n    RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR;\n    Reg dest = ra_dest(as, ir, allow);\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n    if (ir->o == IR_VLOAD) as->mrm.ofs += 8 * ir->op2;\n#if LJ_GC64\n    if (irt_isaddr(ir->t)) {\n      emit_shifti(as, XOg_SHR|REX_64, dest, 17);\n      asm_guardcc(as, CC_NE);\n      emit_i8(as, irt_toitype(ir->t));\n      emit_rr(as, XO_ARITHi8, XOg_CMP, dest);\n      emit_i8(as, XI_O16);\n      if ((as->flags & JIT_F_BMI2)) {\n\temit_i8(as, 47);\n\temit_mrm(as, XV_RORX|VEX_64, dest, RID_MRM);\n      } else {\n\temit_shifti(as, XOg_ROR|REX_64, dest, 47);\n\temit_mrm(as, XO_MOV, dest|REX_64, RID_MRM);\n      }\n      return;\n    } else\n#endif\n    emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XO_MOVSD, dest, RID_MRM);\n  } else {\n    RegSet gpr = RSET_GPR;\n#if LJ_GC64\n    if (irt_isaddr(ir->t)) {\n      tmp = ra_scratch(as, RSET_GPR);\n      gpr = rset_exclude(gpr, tmp);\n    }\n#endif\n    asm_fuseahuref(as, ir->op1, gpr);\n    if (ir->o == IR_VLOAD) as->mrm.ofs += 8 * ir->op2;\n  }\n  /* Always do the type check, even if the load result is unused. */\n  as->mrm.ofs += 4;\n  asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE);\n  if (LJ_64 && irt_type(ir->t) >= IRT_NUM) {\n    lj_assertA(irt_isinteger(ir->t) || irt_isnum(ir->t),\n\t       \"bad load type %d\", irt_type(ir->t));\n#if LJ_GC64\n    emit_u32(as, LJ_TISNUM << 15);\n#else\n    emit_u32(as, LJ_TISNUM);\n#endif\n    emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM);\n#if LJ_GC64\n  } else if (irt_isaddr(ir->t)) {\n    as->mrm.ofs -= 4;\n    emit_i8(as, irt_toitype(ir->t));\n    emit_mrm(as, XO_ARITHi8, XOg_CMP, tmp);\n    emit_shifti(as, XOg_SAR|REX_64, tmp, 47);\n    emit_mrm(as, XO_MOV, tmp|REX_64, RID_MRM);\n  } else if (irt_isnil(ir->t)) {\n    as->mrm.ofs -= 4;\n    emit_i8(as, -1);\n    emit_mrm(as, XO_ARITHi8, XOg_CMP|REX_64, RID_MRM);\n  } else {\n    emit_u32(as, (irt_toitype(ir->t) << 15) | 0x7fff);\n    emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM);\n#else\n  } else {\n    emit_i8(as, irt_toitype(ir->t));\n    emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM);\n#endif\n  }\n}\n\nstatic void asm_ahustore(ASMState *as, IRIns *ir)\n{\n  if (ir->r == RID_SINK)\n    return;\n  if (irt_isnum(ir->t)) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_FPR);\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n    emit_mrm(as, XO_MOVSDto, src, RID_MRM);\n#if LJ_64 && !LJ_GC64\n  } else if (irt_islightud(ir->t)) {\n    Reg src = ra_alloc1(as, ir->op2, RSET_GPR);\n    asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src));\n    emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM);\n#endif\n#if LJ_GC64\n  } else if (irref_isk(ir->op2)) {\n    TValue k;\n    lj_ir_kvalue(as->J->L, &k, IR(ir->op2));\n    asm_fuseahuref(as, ir->op1, RSET_GPR);\n    if (tvisnil(&k)) {\n      emit_i32(as, -1);\n      emit_mrm(as, XO_MOVmi, REX_64, RID_MRM);\n    } else {\n      emit_u32(as, k.u32.lo);\n      emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n      as->mrm.ofs += 4;\n      emit_u32(as, k.u32.hi);\n      emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n    }\n#endif\n  } else {\n    IRIns *irr = IR(ir->op2);\n    RegSet allow = RSET_GPR;\n    Reg src = RID_NONE;\n    if (!irref_isk(ir->op2)) {\n      src = ra_alloc1(as, ir->op2, allow);\n      rset_clear(allow, src);\n    }\n    asm_fuseahuref(as, ir->op1, allow);\n    if (ra_hasreg(src)) {\n#if LJ_GC64\n      if (!(LJ_DUALNUM && irt_isinteger(ir->t))) {\n\t/* TODO: 64 bit store + 32 bit load-modify-store is suboptimal. */\n\tas->mrm.ofs += 4;\n\temit_u32(as, irt_toitype(ir->t) << 15);\n\temit_mrm(as, XO_ARITHi, XOg_OR, RID_MRM);\n\tas->mrm.ofs -= 4;\n\temit_mrm(as, XO_MOVto, src|REX_64, RID_MRM);\n\treturn;\n      }\n#endif\n      emit_mrm(as, XO_MOVto, src, RID_MRM);\n    } else if (!irt_ispri(irr->t)) {\n      lj_assertA(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t)),\n\t\t \"bad store type\");\n      emit_i32(as, irr->i);\n      emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n    }\n    as->mrm.ofs += 4;\n#if LJ_GC64\n    lj_assertA(LJ_DUALNUM && irt_isinteger(ir->t), \"bad store type\");\n    emit_i32(as, LJ_TNUMX << 15);\n#else\n    emit_i32(as, (int32_t)irt_toitype(ir->t));\n#endif\n    emit_mrm(as, XO_MOVmi, 0, RID_MRM);\n  }\n}\n\nstatic void asm_sload(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = 8*((int32_t)ir->op1-1-LJ_FR2) +\n\t\t(!LJ_FR2 && (ir->op2 & IRSLOAD_FRAME) ? 4 : 0);\n  IRType1 t = ir->t;\n  Reg base;\n  lj_assertA(!(ir->op2 & IRSLOAD_PARENT),\n\t     \"bad parent SLOAD\"); /* Handled by asm_head_side(). */\n  lj_assertA(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK),\n\t     \"inconsistent SLOAD variant\");\n  lj_assertA(LJ_DUALNUM ||\n\t     !irt_isint(t) ||\n\t     (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME|IRSLOAD_KEYINDEX)),\n\t     \"bad SLOAD type\");\n  if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {\n    Reg left = ra_scratch(as, RSET_FPR);\n    asm_tointg(as, ir, left);  /* Frees dest reg. Do this before base alloc. */\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n    emit_rmro(as, XO_MOVSD, left, base, ofs);\n    t.irt = IRT_NUM;  /* Continue with a regular number type check. */\n#if LJ_64 && !LJ_GC64\n  } else if (irt_islightud(t)) {\n    Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK));\n    if (ra_hasreg(dest)) {\n      base = ra_alloc1(as, REF_BASE, RSET_GPR);\n      emit_rmro(as, XO_MOV, dest|REX_64, base, ofs);\n    }\n    return;\n#endif\n  } else if (ra_used(ir)) {\n    RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR;\n    Reg dest = ra_dest(as, ir, allow);\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n    lj_assertA(irt_isnum(t) || irt_isint(t) || irt_isaddr(t),\n\t       \"bad SLOAD type %d\", irt_type(t));\n    if ((ir->op2 & IRSLOAD_CONVERT)) {\n      t.irt = irt_isint(t) ? IRT_NUM : IRT_INT;  /* Check for original type. */\n      emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTTSD2SI, dest, base, ofs);\n    } else {\n#if LJ_GC64\n      if (irt_isaddr(t)) {\n\t/* LJ_GC64 type check + tag removal without BMI2 and with BMI2:\n\t**\n\t**  mov r64, [addr]    rorx r64, [addr], 47\n\t**  ror r64, 47\n\t**  cmp r16, itype     cmp r16, itype\n\t**  jne ->exit         jne ->exit\n\t**  shr r64, 16        shr r64, 16\n\t*/\n\temit_shifti(as, XOg_SHR|REX_64, dest, 17);\n\tif ((ir->op2 & IRSLOAD_TYPECHECK)) {\n\t  asm_guardcc(as, CC_NE);\n\t  emit_i8(as, irt_toitype(t));\n\t  emit_rr(as, XO_ARITHi8, XOg_CMP, dest);\n\t  emit_i8(as, XI_O16);\n\t}\n\tif ((as->flags & JIT_F_BMI2)) {\n\t  emit_i8(as, 47);\n\t  emit_rmro(as, XV_RORX|VEX_64, dest, base, ofs);\n\t} else {\n\t  if ((ir->op2 & IRSLOAD_TYPECHECK))\n\t    emit_shifti(as, XOg_ROR|REX_64, dest, 47);\n\t  else\n\t    emit_shifti(as, XOg_SHL|REX_64, dest, 17);\n\t  emit_rmro(as, XO_MOV, dest|REX_64, base, ofs);\n\t}\n\treturn;\n      } else\n#endif\n      emit_rmro(as, irt_isnum(t) ? XO_MOVSD : XO_MOV, dest, base, ofs);\n    }\n  } else {\n    if (!(ir->op2 & IRSLOAD_TYPECHECK))\n      return;  /* No type check: avoid base alloc. */\n    base = ra_alloc1(as, REF_BASE, RSET_GPR);\n  }\n  if ((ir->op2 & IRSLOAD_TYPECHECK)) {\n    /* Need type check, even if the load result is unused. */\n    asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE);\n    if (LJ_64 && irt_type(t) >= IRT_NUM) {\n      lj_assertA(irt_isinteger(t) || irt_isnum(t),\n\t\t \"bad SLOAD type %d\", irt_type(t));\n#if LJ_GC64\n      emit_u32(as, LJ_TISNUM << 15);\n#else\n      emit_u32(as, LJ_TISNUM);\n#endif\n      emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4);\n#if LJ_GC64\n    } else if (irt_isnil(t)) {\n      /* LJ_GC64 type check for nil:\n      **\n      **   cmp qword [addr], -1\n      **   jne ->exit\n      */\n      emit_i8(as, -1);\n      emit_rmro(as, XO_ARITHi8, XOg_CMP|REX_64, base, ofs);\n    } else if (irt_ispri(t)) {\n      emit_u32(as, (irt_toitype(t) << 15) | 0x7fff);\n      emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4);\n    } else {\n      /* LJ_GC64 type check only:\n      **\n      **   mov r64, [addr]\n      **   sar r64, 47\n      **   cmp r32, itype\n      **   jne ->exit\n      */\n      Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, base));\n      emit_i8(as, irt_toitype(t));\n      emit_rr(as, XO_ARITHi8, XOg_CMP, tmp);\n      emit_shifti(as, XOg_SAR|REX_64, tmp, 47);\n      emit_rmro(as, XO_MOV, tmp|REX_64, base, ofs);\n#else\n    } else {\n      emit_i8(as, irt_toitype(t));\n      emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4);\n#endif\n    }\n  }\n}\n\n/* -- Allocations --------------------------------------------------------- */\n\n#if LJ_HASFFI\nstatic void asm_cnew(ASMState *as, IRIns *ir)\n{\n  CTState *cts = ctype_ctsG(J2G(as->J));\n  CTypeID id = (CTypeID)IR(ir->op1)->i;\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];\n  IRRef args[4];\n  lj_assertA(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL),\n\t     \"bad CNEW/CNEWI operands\");\n\n  as->gcsteps++;\n  asm_setupresult(as, ir, ci);  /* GCcdata * */\n\n  /* Initialize immutable cdata object. */\n  if (ir->o == IR_CNEWI) {\n    RegSet allow = (RSET_GPR & ~RSET_SCRATCH);\n#if LJ_64\n    Reg r64 = sz == 8 ? REX_64 : 0;\n    if (irref_isk(ir->op2)) {\n      IRIns *irk = IR(ir->op2);\n      uint64_t k = (irk->o == IR_KINT64 ||\n\t\t    (LJ_GC64 && (irk->o == IR_KPTR || irk->o == IR_KKPTR))) ?\n\t\t   ir_k64(irk)->u64 : (uint64_t)(uint32_t)irk->i;\n      if (sz == 4 || checki32((int64_t)k)) {\n\temit_i32(as, (int32_t)k);\n\temit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata));\n      } else {\n\temit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata));\n\temit_loadu64(as, RID_ECX, k);\n      }\n    } else {\n      Reg r = ra_alloc1(as, ir->op2, allow);\n      emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata));\n    }\n#else\n    int32_t ofs = sizeof(GCcdata);\n    if (sz == 8) {\n      ofs += 4; ir++;\n      lj_assertA(ir->o == IR_HIOP, \"missing CNEWI HIOP\");\n    }\n    do {\n      if (irref_isk(ir->op2)) {\n\temit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i);\n      } else {\n\tReg r = ra_alloc1(as, ir->op2, allow);\n\temit_movtomro(as, r, RID_RET, ofs);\n\trset_clear(allow, r);\n      }\n      if (ofs == sizeof(GCcdata)) break;\n      ofs -= 4; ir--;\n    } while (1);\n#endif\n    lj_assertA(sz == 4 || sz == 8, \"bad CNEWI size %d\", sz);\n  } else if (ir->op2 != REF_NIL) {  /* Create VLA/VLS/aligned cdata. */\n    ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];\n    args[0] = ASMREF_L;     /* lua_State *L */\n    args[1] = ir->op1;      /* CTypeID id   */\n    args[2] = ir->op2;      /* CTSize sz    */\n    args[3] = ASMREF_TMP1;  /* CTSize align */\n    asm_gencall(as, ci, args);\n    emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));\n    return;\n  }\n\n  /* Combine initialization of marked, gct and ctypeid. */\n  emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));\n  emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,\n\t   (int32_t)((~LJ_TCDATA<<8)+(id<<16)));\n  emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES);\n  emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite);\n\n  args[0] = ASMREF_L;     /* lua_State *L */\n  args[1] = ASMREF_TMP1;  /* MSize size   */\n  asm_gencall(as, ci, args);\n  emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata)));\n}\n#endif\n\n/* -- Write barriers ------------------------------------------------------ */\n\nstatic void asm_tbar(ASMState *as, IRIns *ir)\n{\n  Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);\n  Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab));\n  MCLabel l_end = emit_label(as);\n  emit_movtomro(as, tmp|REX_GC64, tab, offsetof(GCtab, gclist));\n  emit_setgl(as, tab, gc.grayagain);\n  emit_getgl(as, tmp, gc.grayagain);\n  emit_i8(as, ~LJ_GC_BLACK);\n  emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked));\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_BLACK);\n  emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked));\n}\n\nstatic void asm_obar(ASMState *as, IRIns *ir)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg obj;\n  /* No need for other object barriers (yet). */\n  lj_assertA(IR(ir->op1)->o == IR_UREFC, \"bad OBAR type\");\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ir->op1;      /* TValue *tv      */\n  asm_gencall(as, ci, args);\n  emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J));\n  obj = IR(ir->op1)->r;\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_WHITES);\n  if (irref_isk(ir->op2)) {\n    GCobj *vp = ir_kgc(IR(ir->op2));\n    emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked);\n  } else {\n    Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj));\n    emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked));\n  }\n  emit_sjcc(as, CC_Z, l_end);\n  emit_i8(as, LJ_GC_BLACK);\n  emit_rmro(as, XO_GROUP3b, XOg_TEST, obj,\n\t    (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));\n}\n\n/* -- FP/int arithmetic and logic operations ------------------------------ */\n\n/* Load reference onto x87 stack. Force a spill to memory if needed. */\nstatic void asm_x87load(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_KNUM) {\n    cTValue *tv = ir_knum(ir);\n    if (tvispzero(tv))  /* Use fldz only for +0. */\n      emit_x87op(as, XI_FLDZ);\n    else if (tvispone(tv))\n      emit_x87op(as, XI_FLD1);\n    else\n      emit_rma(as, XO_FLDq, XOg_FLDq, tv);\n  } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) &&\n\t     !irref_isk(ir->op1) && mayfuse(as, ir->op1)) {\n    IRIns *iri = IR(ir->op1);\n    emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri));\n  } else {\n    emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY));\n  }\n}\n\nstatic void asm_fpmath(ASMState *as, IRIns *ir)\n{\n  IRFPMathOp fpm = (IRFPMathOp)ir->op2;\n  if (fpm == IRFPM_SQRT) {\n    Reg dest = ra_dest(as, ir, RSET_FPR);\n    Reg left = asm_fuseload(as, ir->op1, RSET_FPR);\n    emit_mrm(as, XO_SQRTSD, dest, left);\n  } else if (fpm <= IRFPM_TRUNC) {\n    if (as->flags & JIT_F_SSE4_1) {  /* SSE4.1 has a rounding instruction. */\n      Reg dest = ra_dest(as, ir, RSET_FPR);\n      Reg left = asm_fuseload(as, ir->op1, RSET_FPR);\n      /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op.\n      ** Let's pretend it's a 3-byte opcode, and compensate afterwards.\n      ** This is atrocious, but the alternatives are much worse.\n      */\n      /* Round down/up/trunc == 1001/1010/1011. */\n      emit_i8(as, 0x09 + fpm);\n      emit_mrm(as, XO_ROUNDSD, dest, left);\n      if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) {\n\tas->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f;  /* Swap 0F and REX. */\n      }\n      *--as->mcp = 0x66;  /* 1st byte of ROUNDSD opcode. */\n    } else {  /* Call helper functions for SSE2 variant. */\n      /* The modified regs must match with the *.dasc implementation. */\n      RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);\n      if (ra_hasreg(ir->r))\n\trset_clear(drop, ir->r);  /* Dest reg handled below. */\n      ra_evictset(as, drop);\n      ra_destreg(as, ir, RID_XMM0);\n      emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse :\n\t\t    fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse);\n      ra_left(as, RID_XMM0, ir->op1);\n    }\n  } else {\n    asm_callid(as, ir, IRCALL_lj_vm_floor + fpm);\n  }\n}\n\nstatic void asm_ldexp(ASMState *as, IRIns *ir)\n{\n  int32_t ofs = sps_scale(ir->s);  /* Use spill slot or temp slots. */\n  Reg dest = ir->r;\n  if (ra_hasreg(dest)) {\n    ra_free(as, dest);\n    ra_modified(as, dest);\n    emit_rmro(as, XO_MOVSD, dest, RID_ESP, ofs);\n  }\n  emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs);\n  emit_x87op(as, XI_FPOP1);\n  emit_x87op(as, XI_FSCALE);\n  asm_x87load(as, ir->op1);\n  asm_x87load(as, ir->op2);\n}\n\nstatic void asm_fppowi(ASMState *as, IRIns *ir)\n{\n  /* The modified regs must match with the *.dasc implementation. */\n  RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX);\n  if (ra_hasreg(ir->r))\n    rset_clear(drop, ir->r);  /* Dest reg handled below. */\n  ra_evictset(as, drop);\n  ra_destreg(as, ir, RID_XMM0);\n  emit_call(as, lj_vm_powi_sse);\n  ra_left(as, RID_XMM0, ir->op1);\n  ra_left(as, RID_EAX, ir->op2);\n}\n\nstatic int asm_swapops(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  lj_assertA(ra_noreg(irr->r), \"bad usage\");\n  if (!irm_iscomm(lj_ir_mode[ir->o]))\n    return 0;  /* Can't swap non-commutative operations. */\n  if (irref_isk(ir->op2))\n    return 0;  /* Don't swap constants to the left. */\n  if (ra_hasreg(irl->r))\n    return 1;  /* Swap if left already has a register. */\n  if (ra_samehint(ir->r, irr->r))\n    return 1;  /* Swap if dest and right have matching hints. */\n  if (as->curins > as->loopref) {  /* In variant part? */\n    if (ir->op2 < as->loopref && !irt_isphi(irr->t))\n      return 0;  /* Keep invariants on the right. */\n    if (ir->op1 < as->loopref && !irt_isphi(irl->t))\n      return 1;  /* Swap invariants to the right. */\n  }\n  if (opisfusableload(irl->o))\n    return 1;  /* Swap fusable loads to the right. */\n  return 0;  /* Otherwise don't swap. */\n}\n\nstatic void asm_fparith(ASMState *as, IRIns *ir, x86Op xo)\n{\n  IRRef lref = ir->op1;\n  IRRef rref = ir->op2;\n  RegSet allow = RSET_FPR;\n  Reg dest;\n  Reg right = IR(rref)->r;\n  if (ra_hasreg(right)) {\n    rset_clear(allow, right);\n    ra_noweak(as, right);\n  }\n  dest = ra_dest(as, ir, allow);\n  if (lref == rref) {\n    right = dest;\n  } else if (ra_noreg(right)) {\n    if (asm_swapops(as, ir)) {\n      IRRef tmp = lref; lref = rref; rref = tmp;\n    }\n    right = asm_fuseload(as, rref, rset_clear(allow, dest));\n  }\n  emit_mrm(as, xo, dest, right);\n  ra_left(as, dest, lref);\n}\n\nstatic void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa)\n{\n  IRRef lref = ir->op1;\n  IRRef rref = ir->op2;\n  RegSet allow = RSET_GPR;\n  Reg dest, right;\n  int32_t k = 0;\n  if (as->flagmcp == as->mcp) {  /* Drop test r,r instruction. */\n    MCode *p = as->mcp + ((LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2);\n    MCode *q = p[0] == 0x0f ? p+1 : p;\n    if ((*q & 15) < 14) {\n      if ((*q & 15) >= 12) *q -= 4;  /* L <->S, NL <-> NS */\n      as->flagmcp = NULL;\n      as->mcp = p;\n    }  /* else: cannot transform LE/NLE to cc without use of OF. */\n  }\n  right = IR(rref)->r;\n  if (ra_hasreg(right)) {\n    rset_clear(allow, right);\n    ra_noweak(as, right);\n  }\n  dest = ra_dest(as, ir, allow);\n  if (lref == rref) {\n    right = dest;\n  } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) {\n    if (asm_swapops(as, ir)) {\n      IRRef tmp = lref; lref = rref; rref = tmp;\n    }\n    right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t));\n  }\n  if (irt_isguard(ir->t))  /* For IR_ADDOV etc. */\n    asm_guardcc(as, CC_O);\n  if (xa != XOg_X_IMUL) {\n    if (ra_hasreg(right))\n      emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right);\n    else\n      emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k);\n  } else if (ra_hasreg(right)) {  /* IMUL r, mrm. */\n    emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right);\n  } else {  /* IMUL r, r, k. */\n    /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */\n    Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t));\n    x86Op xo;\n    if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8;\n    } else { emit_i32(as, k); xo = XO_IMULi; }\n    emit_mrm(as, xo, REX_64IR(ir, dest), left);\n    return;\n  }\n  ra_left(as, dest, lref);\n}\n\n/* LEA is really a 4-operand ADD with an independent destination register,\n** up to two source registers and an immediate. One register can be scaled\n** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several\n** instructions.\n**\n** Currently only a few common cases are supported:\n** - 3-operand ADD:    y = a+b; y = a+k   with a and b already allocated\n** - Left ADD fusion:  y = (a+b)+k; y = (a+k)+b\n** - Right ADD fusion: y = a+(b+k)\n** The ommited variants have already been reduced by FOLD.\n**\n** There are more fusion opportunities, like gathering shifts or joining\n** common references. But these are probably not worth the trouble, since\n** array indexing is not decomposed and already makes use of all fields\n** of the ModRM operand.\n*/\nstatic int asm_lea(ASMState *as, IRIns *ir)\n{\n  IRIns *irl = IR(ir->op1);\n  IRIns *irr = IR(ir->op2);\n  RegSet allow = RSET_GPR;\n  Reg dest;\n  as->mrm.base = as->mrm.idx = RID_NONE;\n  as->mrm.scale = XM_SCALE1;\n  as->mrm.ofs = 0;\n  if (ra_hasreg(irl->r)) {\n    rset_clear(allow, irl->r);\n    ra_noweak(as, irl->r);\n    as->mrm.base = irl->r;\n    if (irref_isk(ir->op2) || ra_hasreg(irr->r)) {\n      /* The PHI renaming logic does a better job in some cases. */\n      if (ra_hasreg(ir->r) &&\n\t  ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) ||\n\t   (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2)))\n\treturn 0;\n      if (irref_isk(ir->op2)) {\n\tas->mrm.ofs = irr->i;\n      } else {\n\trset_clear(allow, irr->r);\n\tra_noweak(as, irr->r);\n\tas->mrm.idx = irr->r;\n      }\n    } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) &&\n\t       irref_isk(irr->op2)) {\n      Reg idx = ra_alloc1(as, irr->op1, allow);\n      rset_clear(allow, idx);\n      as->mrm.idx = (uint8_t)idx;\n      as->mrm.ofs = IR(irr->op2)->i;\n    } else {\n      return 0;\n    }\n  } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) &&\n\t     (irref_isk(ir->op2) || irref_isk(irl->op2))) {\n    Reg idx, base = ra_alloc1(as, irl->op1, allow);\n    rset_clear(allow, base);\n    as->mrm.base = (uint8_t)base;\n    if (irref_isk(ir->op2)) {\n      as->mrm.ofs = irr->i;\n      idx = ra_alloc1(as, irl->op2, allow);\n    } else {\n      as->mrm.ofs = IR(irl->op2)->i;\n      idx = ra_alloc1(as, ir->op2, allow);\n    }\n    rset_clear(allow, idx);\n    as->mrm.idx = (uint8_t)idx;\n  } else {\n    return 0;\n  }\n  dest = ra_dest(as, ir, allow);\n  emit_mrm(as, XO_LEA, dest, RID_MRM);\n  return 1;  /* Success. */\n}\n\nstatic void asm_add(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_ADDSD);\n  else if (as->flagmcp == as->mcp || irt_is64(ir->t) || !asm_lea(as, ir))\n    asm_intarith(as, ir, XOg_ADD);\n}\n\nstatic void asm_sub(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_SUBSD);\n  else  /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */\n    asm_intarith(as, ir, XOg_SUB);\n}\n\nstatic void asm_mul(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MULSD);\n  else\n    asm_intarith(as, ir, XOg_X_IMUL);\n}\n\n#define asm_fpdiv(as, ir)\tasm_fparith(as, ir, XO_DIVSD)\n\nstatic void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest);\n  ra_left(as, dest, ir->op1);\n}\n\nstatic void asm_neg(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_XORPS);\n  else\n    asm_neg_not(as, ir, XOg_NEG);\n}\n\n#define asm_abs(as, ir)\t\tasm_fparith(as, ir, XO_ANDPS)\n\nstatic void asm_intmin_max(ASMState *as, IRIns *ir, int cc)\n{\n  Reg right, dest = ra_dest(as, ir, RSET_GPR);\n  IRRef lref = ir->op1, rref = ir->op2;\n  if (irref_isk(rref)) { lref = rref; rref = ir->op1; }\n  right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest));\n  emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right);\n  emit_rr(as, XO_CMP, REX_64IR(ir, dest), right);\n  ra_left(as, dest, lref);\n}\n\nstatic void asm_min(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MINSD);\n  else\n    asm_intmin_max(as, ir, CC_G);\n}\n\nstatic void asm_max(ASMState *as, IRIns *ir)\n{\n  if (irt_isnum(ir->t))\n    asm_fparith(as, ir, XO_MAXSD);\n  else\n    asm_intmin_max(as, ir, CC_L);\n}\n\n/* Note: don't use LEA for overflow-checking arithmetic! */\n#define asm_addov(as, ir)\tasm_intarith(as, ir, XOg_ADD)\n#define asm_subov(as, ir)\tasm_intarith(as, ir, XOg_SUB)\n#define asm_mulov(as, ir)\tasm_intarith(as, ir, XOg_X_IMUL)\n\n#define asm_bnot(as, ir)\tasm_neg_not(as, ir, XOg_NOT)\n\nstatic void asm_bswap(ASMState *as, IRIns *ir)\n{\n  Reg dest = ra_dest(as, ir, RSET_GPR);\n  as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24),\n\t\t    REX_64IR(ir, 0), dest, 0, as->mcp, 1);\n  ra_left(as, dest, ir->op1);\n}\n\n#define asm_band(as, ir)\tasm_intarith(as, ir, XOg_AND)\n#define asm_bor(as, ir)\t\tasm_intarith(as, ir, XOg_OR)\n#define asm_bxor(as, ir)\tasm_intarith(as, ir, XOg_XOR)\n\nstatic void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs, x86Op xv)\n{\n  IRRef rref = ir->op2;\n  IRIns *irr = IR(rref);\n  Reg dest;\n  if (irref_isk(rref)) {  /* Constant shifts. */\n    int shift;\n    dest = ra_dest(as, ir, RSET_GPR);\n    shift = irr->i & (irt_is64(ir->t) ? 63 : 31);\n    if (!xv && shift && (as->flags & JIT_F_BMI2)) {\n      Reg left = asm_fuseloadm(as, ir->op1, RSET_GPR, irt_is64(ir->t));\n      if (left != dest) {  /* BMI2 rotate right by constant. */\n\temit_i8(as, xs == XOg_ROL ? -shift : shift);\n\temit_mrm(as, VEX_64IR(ir, XV_RORX), dest, left);\n\treturn;\n      }\n    }\n    switch (shift) {\n    case 0: break;\n    case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break;\n    default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break;\n    }\n  } else if ((as->flags & JIT_F_BMI2) && xv) {\t/* BMI2 variable shifts. */\n    Reg left, right;\n    dest = ra_dest(as, ir, RSET_GPR);\n    right = ra_alloc1(as, rref, RSET_GPR);\n    left = asm_fuseloadm(as, ir->op1, rset_exclude(RSET_GPR, right),\n\t\t\t irt_is64(ir->t));\n    emit_mrm(as, VEX_64IR(ir, xv) ^ (right << 19), dest, left);\n    return;\n  } else {  /* Variable shifts implicitly use register cl (i.e. ecx). */\n    Reg right;\n    dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX));\n    if (dest == RID_ECX) {\n      dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX));\n      emit_rr(as, XO_MOV, REX_64IR(ir, RID_ECX), dest);\n    }\n    right = irr->r;\n    if (ra_noreg(right))\n      right = ra_allocref(as, rref, RID2RSET(RID_ECX));\n    else if (right != RID_ECX)\n      ra_scratch(as, RID2RSET(RID_ECX));\n    emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest);\n    ra_noweak(as, right);\n    if (right != RID_ECX)\n      emit_rr(as, XO_MOV, RID_ECX, right);\n  }\n  ra_left(as, dest, ir->op1);\n  /*\n  ** Note: avoid using the flags resulting from a shift or rotate!\n  ** All of them cause a partial flag stall, except for r,1 shifts\n  ** (but not rotates). And a shift count of 0 leaves the flags unmodified.\n  */\n}\n\n#define asm_bshl(as, ir)\tasm_bitshift(as, ir, XOg_SHL, XV_SHLX)\n#define asm_bshr(as, ir)\tasm_bitshift(as, ir, XOg_SHR, XV_SHRX)\n#define asm_bsar(as, ir)\tasm_bitshift(as, ir, XOg_SAR, XV_SARX)\n#define asm_brol(as, ir)\tasm_bitshift(as, ir, XOg_ROL, 0)\n#define asm_bror(as, ir)\tasm_bitshift(as, ir, XOg_ROR, 0)\n\n/* -- Comparisons --------------------------------------------------------- */\n\n/* Virtual flags for unordered FP comparisons. */\n#define VCC_U\t0x1000\t\t/* Unordered. */\n#define VCC_P\t0x2000\t\t/* Needs extra CC_P branch. */\n#define VCC_S\t0x4000\t\t/* Swap avoids CC_P branch. */\n#define VCC_PS\t(VCC_P|VCC_S)\n\n/* Map of comparisons to flags. ORDER IR. */\n#define COMPFLAGS(ci, cin, cu, cf)\t((ci)+((cu)<<4)+((cin)<<8)+(cf))\nstatic const uint16_t asm_compmap[IR_ABC+1] = {\n  /*                 signed non-eq unsigned flags */\n  /* LT  */ COMPFLAGS(CC_GE, CC_G,  CC_AE, VCC_PS),\n  /* GE  */ COMPFLAGS(CC_L,  CC_L,  CC_B,  0),\n  /* LE  */ COMPFLAGS(CC_G,  CC_G,  CC_A,  VCC_PS),\n  /* GT  */ COMPFLAGS(CC_LE, CC_L,  CC_BE, 0),\n  /* ULT */ COMPFLAGS(CC_AE, CC_A,  CC_AE, VCC_U),\n  /* UGE */ COMPFLAGS(CC_B,  CC_B,  CC_B,  VCC_U|VCC_PS),\n  /* ULE */ COMPFLAGS(CC_A,  CC_A,  CC_A,  VCC_U),\n  /* UGT */ COMPFLAGS(CC_BE, CC_B,  CC_BE, VCC_U|VCC_PS),\n  /* EQ  */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P),\n  /* NE  */ COMPFLAGS(CC_E,  CC_E,  CC_E,  VCC_U|VCC_P),\n  /* ABC */ COMPFLAGS(CC_BE, CC_B,  CC_BE, VCC_U|VCC_PS)  /* Same as UGT. */\n};\n\n/* FP and integer comparisons. */\nstatic void asm_comp(ASMState *as, IRIns *ir)\n{\n  uint32_t cc = asm_compmap[ir->o];\n  if (irt_isnum(ir->t)) {\n    IRRef lref = ir->op1;\n    IRRef rref = ir->op2;\n    Reg left, right;\n    MCLabel l_around;\n    /*\n    ** An extra CC_P branch is required to preserve ordered/unordered\n    ** semantics for FP comparisons. This can be avoided by swapping\n    ** the operands and inverting the condition (except for EQ and UNE).\n    ** So always try to swap if possible.\n    **\n    ** Another option would be to swap operands to achieve better memory\n    ** operand fusion. But it's unlikely that this outweighs the cost\n    ** of the extra branches.\n    */\n    if (cc & VCC_S) {  /* Swap? */\n      IRRef tmp = lref; lref = rref; rref = tmp;\n      cc ^= (VCC_PS|(5<<4));  /* A <-> B, AE <-> BE, PS <-> none */\n    }\n    left = ra_alloc1(as, lref, RSET_FPR);\n    l_around = emit_label(as);\n    asm_guardcc(as, cc >> 4);\n    if (cc & VCC_P) {  /* Extra CC_P branch required? */\n      if (!(cc & VCC_U)) {\n\tasm_guardcc(as, CC_P);  /* Branch to exit for ordered comparisons. */\n      } else if (l_around != as->invmcp) {\n\temit_sjcc(as, CC_P, l_around);  /* Branch around for unordered. */\n      } else {\n\t/* Patched to mcloop by asm_loop_fixup. */\n\tas->loopinv = 2;\n\tif (as->realign)\n\t  emit_sjcc(as, CC_P, as->mcp);\n\telse\n\t  emit_jcc(as, CC_P, as->mcp);\n      }\n    }\n    right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left));\n    emit_mrm(as, XO_UCOMISD, left, right);\n  } else {\n    IRRef lref = ir->op1, rref = ir->op2;\n    IROp leftop = (IROp)(IR(lref)->o);\n    Reg r64 = REX_64IR(ir, 0);\n    int32_t imm = 0;\n    lj_assertA(irt_is64(ir->t) || irt_isint(ir->t) ||\n\t       irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t),\n\t       \"bad comparison data type %d\", irt_type(ir->t));\n    /* Swap constants (only for ABC) and fusable loads to the right. */\n    if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) {\n      if ((cc & 0xc) == 0xc) cc ^= 0x53;  /* L <-> G, LE <-> GE */\n      else if ((cc & 0xa) == 0x2) cc ^= 0x55;  /* A <-> B, AE <-> BE */\n      lref = ir->op2; rref = ir->op1;\n    }\n    if (asm_isk32(as, rref, &imm)) {\n      IRIns *irl = IR(lref);\n      /* Check wether we can use test ins. Not for unsigned, since CF=0. */\n      int usetest = (imm == 0 && (cc & 0xa) != 0x2);\n      if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) {\n\t/* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */\n\tReg right, left = RID_NONE;\n\tRegSet allow = RSET_GPR;\n\tif (!asm_isk32(as, irl->op2, &imm)) {\n\t  left = ra_alloc1(as, irl->op2, allow);\n\t  rset_clear(allow, left);\n\t} else {  /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */\n\t  IRIns *irll = IR(irl->op1);\n\t  if (opisfusableload((IROp)irll->o) &&\n\t      (irt_isi8(irll->t) || irt_isu8(irll->t))) {\n\t    IRType1 origt = irll->t;  /* Temporarily flip types. */\n\t    irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT;\n\t    as->curins--;  /* Skip to BAND to avoid failing in noconflict(). */\n\t    right = asm_fuseload(as, irl->op1, RSET_GPR);\n\t    as->curins++;\n\t    irll->t = origt;\n\t    if (right != RID_MRM) goto test_nofuse;\n\t    /* Fusion succeeded, emit test byte mrm, imm8. */\n\t    asm_guardcc(as, cc);\n\t    emit_i8(as, (imm & 0xff));\n\t    emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM);\n\t    return;\n\t  }\n\t}\n\tas->curins--;  /* Skip to BAND to avoid failing in noconflict(). */\n\tright = asm_fuseloadm(as, irl->op1, allow, r64);\n\tas->curins++;  /* Undo the above. */\n      test_nofuse:\n\tasm_guardcc(as, cc);\n\tif (ra_noreg(left)) {\n\t  emit_i32(as, imm);\n\t  emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right);\n\t} else {\n\t  emit_mrm(as, XO_TEST, r64 + left, right);\n\t}\n      } else {\n\tReg left;\n\tif (opisfusableload((IROp)irl->o) &&\n\t    ((irt_isu8(irl->t) && checku8(imm)) ||\n\t     ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) ||\n\t     (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) {\n\t  /* Only the IRT_INT case is fused by asm_fuseload.\n\t  ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads\n\t  ** are handled here.\n\t  ** Note that cmp word [mem], imm16 should not be generated,\n\t  ** since it has a length-changing prefix. Compares of a word\n\t  ** against a sign-extended imm8 are ok, however.\n\t  */\n\t  IRType1 origt = irl->t;  /* Temporarily flip types. */\n\t  irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT;\n\t  left = asm_fuseload(as, lref, RSET_GPR);\n\t  irl->t = origt;\n\t  if (left == RID_MRM) {  /* Fusion succeeded? */\n\t    if (irt_isu8(irl->t) || irt_isu16(irl->t))\n\t      cc >>= 4;  /* Need unsigned compare. */\n\t    asm_guardcc(as, cc);\n\t    emit_i8(as, imm);\n\t    emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ?\n\t\t\t XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM);\n\t    return;\n\t  }  /* Otherwise handle register case as usual. */\n\t} else {\n\t  left = asm_fuseloadm(as, lref,\n\t\t\t       irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64);\n\t}\n\tasm_guardcc(as, cc);\n\tif (usetest && left != RID_MRM) {\n\t  /* Use test r,r instead of cmp r,0. */\n\t  x86Op xo = XO_TEST;\n\t  if (irt_isu8(ir->t)) {\n\t    lj_assertA(ir->o == IR_EQ || ir->o == IR_NE, \"bad usage\");\n\t    xo = XO_TESTb;\n\t    if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) {\n\t      if (LJ_64) {\n\t\tleft |= FORCE_REX;\n\t      } else {\n\t\temit_i32(as, 0xff);\n\t\temit_mrm(as, XO_GROUP3, XOg_TEST, left);\n\t\treturn;\n\t      }\n\t    }\n\t  }\n\t  emit_rr(as, xo, r64 + left, left);\n\t  if (irl+1 == ir)  /* Referencing previous ins? */\n\t    as->flagmcp = as->mcp;  /* Set flag to drop test r,r if possible. */\n\t} else {\n\t  emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm);\n\t}\n      }\n    } else {\n      Reg left = ra_alloc1(as, lref, RSET_GPR);\n      Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64);\n      asm_guardcc(as, cc);\n      emit_mrm(as, XO_CMP, r64 + left, right);\n    }\n  }\n}\n\n#define asm_equal(as, ir)\tasm_comp(as, ir)\n\n#if LJ_32 && LJ_HASFFI\n/* 64 bit integer comparisons in 32 bit mode. */\nstatic void asm_comp_int64(ASMState *as, IRIns *ir)\n{\n  uint32_t cc = asm_compmap[(ir-1)->o];\n  RegSet allow = RSET_GPR;\n  Reg lefthi = RID_NONE, leftlo = RID_NONE;\n  Reg righthi = RID_NONE, rightlo = RID_NONE;\n  MCLabel l_around;\n  x86ModRM mrm;\n\n  as->curins--;  /* Skip loword ins. Avoids failing in noconflict(), too. */\n\n  /* Allocate/fuse hiword operands. */\n  if (irref_isk(ir->op2)) {\n    lefthi = asm_fuseload(as, ir->op1, allow);\n  } else {\n    lefthi = ra_alloc1(as, ir->op1, allow);\n    rset_clear(allow, lefthi);\n    righthi = asm_fuseload(as, ir->op2, allow);\n    if (righthi == RID_MRM) {\n      if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base);\n      if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx);\n    } else {\n      rset_clear(allow, righthi);\n    }\n  }\n  mrm = as->mrm;  /* Save state for hiword instruction. */\n\n  /* Allocate/fuse loword operands. */\n  if (irref_isk((ir-1)->op2)) {\n    leftlo = asm_fuseload(as, (ir-1)->op1, allow);\n  } else {\n    leftlo = ra_alloc1(as, (ir-1)->op1, allow);\n    rset_clear(allow, leftlo);\n    rightlo = asm_fuseload(as, (ir-1)->op2, allow);\n  }\n\n  /* All register allocations must be performed _before_ this point. */\n  l_around = emit_label(as);\n  as->invmcp = as->flagmcp = NULL;  /* Cannot use these optimizations. */\n\n  /* Loword comparison and branch. */\n  asm_guardcc(as, cc >> 4);  /* Always use unsigned compare for loword. */\n  if (ra_noreg(rightlo)) {\n    int32_t imm = IR((ir-1)->op2)->i;\n    if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM)\n      emit_rr(as, XO_TEST, leftlo, leftlo);\n    else\n      emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm);\n  } else {\n    emit_mrm(as, XO_CMP, leftlo, rightlo);\n  }\n\n  /* Hiword comparison and branches. */\n  if ((cc & 15) != CC_NE)\n    emit_sjcc(as, CC_NE, l_around);  /* Hiword unequal: skip loword compare. */\n  if ((cc & 15) != CC_E)\n    asm_guardcc(as, cc >> 8);  /* Hiword compare without equality check. */\n  as->mrm = mrm;  /* Restore state. */\n  if (ra_noreg(righthi)) {\n    int32_t imm = IR(ir->op2)->i;\n    if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM)\n      emit_rr(as, XO_TEST, lefthi, lefthi);\n    else\n      emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm);\n  } else {\n    emit_mrm(as, XO_CMP, lefthi, righthi);\n  }\n}\n#endif\n\n/* -- Split register ops -------------------------------------------------- */\n\n/* Hiword op of a split 32/32 or 64/64 bit op. Previous op is the loword op. */\nstatic void asm_hiop(ASMState *as, IRIns *ir)\n{\n  /* HIOP is marked as a store because it needs its own DCE logic. */\n  int uselo = ra_used(ir-1), usehi = ra_used(ir);  /* Loword/hiword used? */\n  if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;\n#if LJ_32 && LJ_HASFFI\n  if ((ir-1)->o == IR_CONV) {  /* Conversions to/from 64 bit. */\n    as->curins--;  /* Always skip the CONV. */\n    if (usehi || uselo)\n      asm_conv64(as, ir);\n    return;\n  } else if ((ir-1)->o <= IR_NE) {  /* 64 bit integer comparisons. ORDER IR. */\n    asm_comp_int64(as, ir);\n    return;\n  } else if ((ir-1)->o == IR_XSTORE) {\n    if ((ir-1)->r != RID_SINK)\n      asm_fxstore(as, ir);\n    return;\n  }\n#endif\n  if (!usehi) return;  /* Skip unused hiword op for all remaining ops. */\n  switch ((ir-1)->o) {\n#if LJ_32 && LJ_HASFFI\n  case IR_ADD:\n    as->flagmcp = NULL;\n    as->curins--;\n    asm_intarith(as, ir, XOg_ADC);\n    asm_intarith(as, ir-1, XOg_ADD);\n    break;\n  case IR_SUB:\n    as->flagmcp = NULL;\n    as->curins--;\n    asm_intarith(as, ir, XOg_SBB);\n    asm_intarith(as, ir-1, XOg_SUB);\n    break;\n  case IR_NEG: {\n    Reg dest = ra_dest(as, ir, RSET_GPR);\n    emit_rr(as, XO_GROUP3, XOg_NEG, dest);\n    emit_i8(as, 0);\n    emit_rr(as, XO_ARITHi8, XOg_ADC, dest);\n    ra_left(as, dest, ir->op1);\n    as->curins--;\n    asm_neg_not(as, ir-1, XOg_NEG);\n    break;\n    }\n  case IR_CNEWI:\n    /* Nothing to do here. Handled by CNEWI itself. */\n    break;\n#endif\n  case IR_CALLN: case IR_CALLL: case IR_CALLS: case IR_CALLXS:\n    if (!uselo)\n      ra_allocref(as, ir->op1, RID2RSET(RID_RETLO));  /* Mark lo op as used. */\n    break;\n  default: lj_assertA(0, \"bad HIOP for op %d\", (ir-1)->o); break;\n  }\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nstatic void asm_prof(ASMState *as, IRIns *ir)\n{\n  UNUSED(ir);\n  asm_guardcc(as, CC_NE);\n  emit_i8(as, HOOK_PROFILE);\n  emit_rma(as, XO_GROUP3b, XOg_TEST, &J2G(as->J)->hookmask);\n}\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Check Lua stack size for overflow. Use exit handler as fallback. */\nstatic void asm_stack_check(ASMState *as, BCReg topslot,\n\t\t\t    IRIns *irp, RegSet allow, ExitNo exitno)\n{\n  /* Try to get an unused temp. register, otherwise spill/restore eax. */\n  Reg pbase = irp ? irp->r : RID_BASE;\n  Reg r = allow ? rset_pickbot(allow) : RID_EAX;\n  emit_jcc(as, CC_B, exitstub_addr(as->J, exitno));\n  if (allow == RSET_EMPTY)  /* Restore temp. register. */\n    emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0);\n  else\n    ra_modified(as, r);\n  emit_gri(as, XG_ARITHi(XOg_CMP), r|REX_GC64, (int32_t)(8*topslot));\n  if (ra_hasreg(pbase) && pbase != r)\n    emit_rr(as, XO_ARITH(XOg_SUB), r|REX_GC64, pbase);\n  else\n#if LJ_GC64\n    emit_rmro(as, XO_ARITH(XOg_SUB), r|REX_64, RID_DISPATCH,\n\t      (int32_t)dispofs(as, &J2G(as->J)->jit_base));\n#else\n    emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE,\n\t      ptr2addr(&J2G(as->J)->jit_base));\n#endif\n  emit_rmro(as, XO_MOV, r|REX_GC64, r, offsetof(lua_State, maxstack));\n  emit_getgl(as, r, cur_L);\n  if (allow == RSET_EMPTY)  /* Spill temp. register. */\n    emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0);\n}\n\n/* Restore Lua stack from on-trace state. */\nstatic void asm_stack_restore(ASMState *as, SnapShot *snap)\n{\n  SnapEntry *map = &as->T->snapmap[snap->mapofs];\n#if !LJ_FR2 || defined(LUA_USE_ASSERT)\n  SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1-LJ_FR2];\n#endif\n  MSize n, nent = snap->nent;\n  /* Store the value of all modified slots to the Lua stack. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    int32_t ofs = 8*((int32_t)s-1-LJ_FR2);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = IR(ref);\n    if ((sn & SNAP_NORESTORE))\n      continue;\n    if ((sn & SNAP_KEYINDEX)) {\n      emit_movmroi(as, RID_BASE, ofs+4, LJ_KEYINDEX);\n      if (irref_isk(ref)) {\n\temit_movmroi(as, RID_BASE, ofs, ir->i);\n      } else {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));\n\temit_movtomro(as, src, RID_BASE, ofs);\n      }\n    } else if (irt_isnum(ir->t)) {\n      Reg src = ra_alloc1(as, ref, RSET_FPR);\n      emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs);\n    } else {\n      lj_assertA(irt_ispri(ir->t) || irt_isaddr(ir->t) ||\n\t\t (LJ_DUALNUM && irt_isinteger(ir->t)),\n\t\t \"restore of IR type %d\", irt_type(ir->t));\n      if (!irref_isk(ref)) {\n\tReg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));\n#if LJ_GC64\n\tif (irt_is64(ir->t)) {\n\t  /* TODO: 64 bit store + 32 bit load-modify-store is suboptimal. */\n\t  emit_u32(as, irt_toitype(ir->t) << 15);\n\t  emit_rmro(as, XO_ARITHi, XOg_OR, RID_BASE, ofs+4);\n\t} else if (LJ_DUALNUM && irt_isinteger(ir->t)) {\n\t  emit_movmroi(as, RID_BASE, ofs+4, LJ_TISNUM << 15);\n\t} else {\n\t  emit_movmroi(as, RID_BASE, ofs+4, (irt_toitype(ir->t)<<15)|0x7fff);\n\t}\n#endif\n\temit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs);\n#if LJ_GC64\n      } else {\n\tTValue k;\n\tlj_ir_kvalue(as->J->L, &k, ir);\n\tif (tvisnil(&k)) {\n\t  emit_i32(as, -1);\n\t  emit_rmro(as, XO_MOVmi, REX_64, RID_BASE, ofs);\n\t} else {\n\t  emit_movmroi(as, RID_BASE, ofs+4, k.u32.hi);\n\t  emit_movmroi(as, RID_BASE, ofs, k.u32.lo);\n\t}\n#else\n      } else if (!irt_ispri(ir->t)) {\n\temit_movmroi(as, RID_BASE, ofs, ir->i);\n#endif\n      }\n      if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n#if !LJ_FR2\n\tif (s != 0)  /* Do not overwrite link to previous frame. */\n\t  emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--));\n#endif\n#if !LJ_GC64\n      } else {\n\tif (!(LJ_64 && irt_islightud(ir->t)))\n\t  emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t));\n#endif\n      }\n    }\n    checkmclim(as);\n  }\n  lj_assertA(map + nent == flinks, \"inconsistent frames in snapshot\");\n}\n\n/* -- GC handling --------------------------------------------------------- */\n\n/* Check GC threshold and do one or more GC steps. */\nstatic void asm_gc_check(ASMState *as)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];\n  IRRef args[2];\n  MCLabel l_end;\n  Reg tmp;\n  ra_evictset(as, RSET_SCRATCH);\n  l_end = emit_label(as);\n  /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */\n  asm_guardcc(as, CC_NE);  /* Assumes asm_snap_prep() already done. */\n  emit_rr(as, XO_TEST, RID_RET, RID_RET);\n  args[0] = ASMREF_TMP1;  /* global_State *g */\n  args[1] = ASMREF_TMP2;  /* MSize steps     */\n  asm_gencall(as, ci, args);\n  tmp = ra_releasetmp(as, ASMREF_TMP1);\n#if LJ_GC64\n  emit_rmro(as, XO_LEA, tmp|REX_64, RID_DISPATCH, GG_DISP2G);\n#else\n  emit_loada(as, tmp, J2G(as->J));\n#endif\n  emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps);\n  /* Jump around GC step if GC total < GC threshold. */\n  emit_sjcc(as, CC_B, l_end);\n  emit_opgl(as, XO_ARITH(XOg_CMP), tmp|REX_GC64, gc.threshold);\n  emit_getgl(as, tmp, gc.total);\n  as->gcsteps = 0;\n  checkmclim(as);\n}\n\n/* -- Loop handling ------------------------------------------------------- */\n\n/* Fixup the loop branch. */\nstatic void asm_loop_fixup(ASMState *as)\n{\n  MCode *p = as->mctop;\n  MCode *target = as->mcp;\n  if (as->realign) {  /* Realigned loops use short jumps. */\n    as->realign = NULL;  /* Stop another retry. */\n    lj_assertA(((intptr_t)target & 15) == 0, \"loop realign failed\");\n    if (as->loopinv) {  /* Inverted loop branch? */\n      p -= 5;\n      p[0] = XI_JMP;\n      lj_assertA(target - p >= -128, \"loop realign failed\");\n      p[-1] = (MCode)(target - p);  /* Patch sjcc. */\n      if (as->loopinv == 2)\n\tp[-3] = (MCode)(target - p + 2);  /* Patch opt. short jp. */\n    } else {\n      lj_assertA(target - p >= -128, \"loop realign failed\");\n      p[-1] = (MCode)(int8_t)(target - p);  /* Patch short jmp. */\n      p[-2] = XI_JMPs;\n    }\n  } else {\n    MCode *newloop;\n    p[-5] = XI_JMP;\n    if (as->loopinv) {  /* Inverted loop branch? */\n      /* asm_guardcc already inverted the jcc and patched the jmp. */\n      p -= 5;\n      newloop = target+4;\n      *(int32_t *)(p-4) = (int32_t)(target - p);  /* Patch jcc. */\n      if (as->loopinv == 2) {\n\t*(int32_t *)(p-10) = (int32_t)(target - p + 6);  /* Patch opt. jp. */\n\tnewloop = target+8;\n      }\n    } else {  /* Otherwise just patch jmp. */\n      *(int32_t *)(p-4) = (int32_t)(target - p);\n      newloop = target+3;\n    }\n    /* Realign small loops and shorten the loop branch. */\n    if (newloop >= p - 128) {\n      as->realign = newloop;  /* Force a retry and remember alignment. */\n      as->curins = as->stopins;  /* Abort asm_trace now. */\n      as->T->nins = as->orignins;  /* Remove any added renames. */\n    }\n  }\n}\n\n/* Fixup the tail of the loop. */\nstatic void asm_loop_tail_fixup(ASMState *as)\n{\n  UNUSED(as);  /* Nothing to do. */\n}\n\n/* -- Head of trace ------------------------------------------------------- */\n\n/* Coalesce BASE register for a root trace. */\nstatic void asm_head_root_base(ASMState *as)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (r != RID_BASE)\n      emit_rr(as, XO_MOV, r|REX_GC64, RID_BASE);\n  }\n}\n\n/* Coalesce or reload BASE register for a side trace. */\nstatic RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)\n{\n  IRIns *ir = IR(REF_BASE);\n  Reg r = ir->r;\n  if (ra_hasreg(r)) {\n    ra_free(as, r);\n    if (rset_test(as->modset, r) || irt_ismarked(ir->t))\n      ir->r = RID_INIT;  /* No inheritance for modified BASE register. */\n    if (irp->r == r) {\n      rset_clear(allow, r);  /* Mark same BASE register as coalesced. */\n    } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {\n      /* Move from coalesced parent reg. */\n      rset_clear(allow, irp->r);\n      emit_rr(as, XO_MOV, r|REX_GC64, irp->r);\n    } else {\n      emit_getgl(as, r, jit_base);  /* Otherwise reload BASE. */\n    }\n  }\n  return allow;\n}\n\n/* -- Tail of trace ------------------------------------------------------- */\n\n/* Fixup the tail code. */\nstatic void asm_tail_fixup(ASMState *as, TraceNo lnk)\n{\n  /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */\n  MCode *p = as->mctop;\n  MCode *target, *q;\n  int32_t spadj = as->T->spadjust;\n  if (spadj == 0) {\n    p -= LJ_64 ? 7 : 6;\n  } else {\n    MCode *p1;\n    /* Patch stack adjustment. */\n    if (checki8(spadj)) {\n      p -= 3;\n      p1 = p-6;\n      *p1 = (MCode)spadj;\n    } else {\n      p1 = p-9;\n      *(int32_t *)p1 = spadj;\n    }\n#if LJ_64\n    p1[-3] = 0x48;\n#endif\n    p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi);\n    p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP);\n  }\n  /* Patch exit branch. */\n  target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;\n  *(int32_t *)(p-4) = jmprel(as->J, p, target);\n  p[-5] = XI_JMP;\n  /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */\n  for (q = as->mctop-1; q >= p; q--)\n    *q = XI_NOP;\n  as->mctop = p;\n}\n\n/* Prepare tail of code. */\nstatic void asm_tail_prep(ASMState *as)\n{\n  MCode *p = as->mctop;\n  /* Realign and leave room for backwards loop branch or exit branch. */\n  if (as->realign) {\n    int i = ((int)(intptr_t)as->realign) & 15;\n    /* Fill unused mcode tail with NOPs to make the prefetcher happy. */\n    while (i-- > 0)\n      *--p = XI_NOP;\n    as->mctop = p;\n    p -= (as->loopinv ? 5 : 2);  /* Space for short/near jmp. */\n  } else {\n    p -= 5;  /* Space for exit branch (near jmp). */\n  }\n  if (as->loopref) {\n    as->invmcp = as->mcp = p;\n  } else {\n    /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */\n    as->mcp = p - (LJ_64 ? 7 : 6);\n    as->invmcp = NULL;\n  }\n}\n\n/* -- Trace setup --------------------------------------------------------- */\n\n/* Ensure there are enough stack slots for call arguments. */\nstatic Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)\n{\n  IRRef args[CCI_NARGS_MAX*2];\n  int nslots;\n  asm_collectargs(as, ir, ci, args);\n  nslots = asm_count_call_slots(as, ci, args);\n  if (nslots > as->evenspill)  /* Leave room for args in stack slots. */\n    as->evenspill = nslots;\n#if LJ_64\n  return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);\n#else\n  return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET);\n#endif\n}\n\n/* Target-specific setup. */\nstatic void asm_setup_target(ASMState *as)\n{\n  asm_exitstub_setup(as, as->T->nsnap);\n  as->mrm.base = 0;\n}\n\n/* -- Trace patching ------------------------------------------------------ */\n\nstatic const uint8_t map_op1[256] = {\n0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x20,\n0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,\n0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,\n0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,\n#if LJ_64\n0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,\n#else\n0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,\n#endif\n0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,\n0x51,0x51,0x92,0x92,0x10,0x10,0x12,0x11,0x45,0x86,0x52,0x93,0x51,0x51,0x51,0x51,\n0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,\n0x93,0x86,0x93,0x93,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,\n0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x47,0x51,0x51,0x51,0x51,0x51,\n#if LJ_64\n0x59,0x59,0x59,0x59,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,\n#else\n0x55,0x55,0x55,0x55,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,\n#endif\n0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,\n0x93,0x93,0x53,0x51,0x70,0x71,0x93,0x86,0x54,0x51,0x53,0x51,0x51,0x52,0x51,0x51,\n0x92,0x92,0x92,0x92,0x52,0x52,0x51,0x51,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,\n0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x45,0x45,0x47,0x52,0x51,0x51,0x51,0x51,\n0x10,0x51,0x10,0x10,0x51,0x51,0x63,0x66,0x51,0x51,0x51,0x51,0x51,0x51,0x92,0x92\n};\n\nstatic const uint8_t map_op2[256] = {\n0x93,0x93,0x93,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x93,0x52,0x94,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x34,0x51,0x35,0x51,0x51,0x51,0x51,0x51,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x94,0x54,0x54,0x54,0x93,0x93,0x93,0x52,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x52,0x52,0x52,0x93,0x94,0x93,0x51,0x51,0x52,0x52,0x52,0x93,0x94,0x93,0x93,0x93,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x94,0x93,0x93,0x93,0x93,0x93,\n0x93,0x93,0x94,0x93,0x94,0x94,0x94,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,\n0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x52\n};\n\nstatic uint32_t asm_x86_inslen(const uint8_t* p)\n{\n  uint32_t result = 0;\n  uint32_t prefixes = 0;\n  uint32_t x = map_op1[*p];\n  for (;;) {\n    switch (x >> 4) {\n    case 0: return result + x + (prefixes & 4);\n    case 1: prefixes |= x; x = map_op1[*++p]; result++; break;\n    case 2: x = map_op2[*++p]; break;\n    case 3: p++; goto mrm;\n    case 4: result -= (prefixes & 2);  /* fallthrough */\n    case 5: return result + (x & 15);\n    case 6:  /* Group 3. */\n      if (p[1] & 0x38) x = 2;\n      else if ((prefixes & 2) && (x == 0x66)) x = 4;\n      goto mrm;\n    case 7: /* VEX c4/c5. */\n      if (LJ_32 && p[1] < 0xc0) {\n\tx = 2;\n\tgoto mrm;\n      }\n      if (x == 0x70) {\n\tx = *++p & 0x1f;\n\tresult++;\n\tif (x >= 2) {\n\t  p += 2;\n\t  result += 2;\n\t  goto mrm;\n\t}\n      }\n      p++;\n      result++;\n      x = map_op2[*++p];\n      break;\n    case 8: result -= (prefixes & 2);  /* fallthrough */\n    case 9: mrm:  /* ModR/M and possibly SIB. */\n      result += (x & 15);\n      x = *++p;\n      switch (x >> 6) {\n      case 0: if ((x & 7) == 5) return result + 4; break;\n      case 1: result++; break;\n      case 2: result += 4; break;\n      case 3: return result;\n      }\n      if ((x & 7) == 4) {\n\tresult++;\n\tif (x < 0x40 && (p[1] & 7) == 5) result += 4;\n      }\n      return result;\n    }\n  }\n}\n\n/* Patch exit jumps of existing machine code to a new target. */\nvoid lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)\n{\n  MCode *p = T->mcode;\n  MCode *mcarea = lj_mcode_patch(J, p, 0);\n  MSize len = T->szmcode;\n  MCode *px = exitstub_addr(J, exitno) - 6;\n  MCode *pe = p+len-6;\n  MCode *pgc = NULL;\n#if LJ_GC64\n  uint32_t statei = (uint32_t)(GG_OFS(g.vmstate) - GG_OFS(dispatch));\n#else\n  uint32_t statei = u32ptr(&J2G(J)->vmstate);\n#endif\n  if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px)\n    *(int32_t *)(p+len-4) = jmprel(J, p+len, target);\n  /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */\n  for (; p < pe; p += asm_x86_inslen(p)) {\n    intptr_t ofs = LJ_GC64 ? (p[0] & 0xf0) == 0x40 : LJ_64;\n    if (*(uint32_t *)(p+2+ofs) == statei && p[ofs+LJ_GC64-LJ_64] == XI_MOVmi)\n      break;\n  }\n  lj_assertJ(p < pe, \"instruction length decoder failed\");\n  for (; p < pe; p += asm_x86_inslen(p)) {\n    if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px &&\n\tp != pgc) {\n      *(int32_t *)(p+2) = jmprel(J, p+6, target);\n    } else if (*p == XI_CALL &&\n\t      (void *)(p+5+*(int32_t *)(p+1)) == (void *)lj_gc_step_jit) {\n      pgc = p+7;  /* Do not patch GC check exit. */\n    }\n  }\n  lj_mcode_sync(T->mcode, T->mcode + T->szmcode);\n  lj_mcode_patch(J, mcarea, 1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_assert.c",
    "content": "/*\n** Internal assertions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_assert_c\n#define LUA_CORE\n\n#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)\n\n#include <stdio.h>\n\n#include \"lj_obj.h\"\n\nvoid lj_assert_fail(global_State *g, const char *file, int line,\n\t\t    const char *func, const char *fmt, ...)\n{\n  va_list argp;\n  va_start(argp, fmt);\n  fprintf(stderr, \"LuaJIT ASSERT %s:%d: %s: \", file, line, func);\n  vfprintf(stderr, fmt, argp);\n  fputc('\\n', stderr);\n  va_end(argp);\n  UNUSED(g);  /* May be NULL. TODO: optionally dump state. */\n  abort();\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_bc.c",
    "content": "/*\n** Bytecode instruction modes.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bc_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n\n/* Bytecode offsets and bytecode instruction modes. */\n#include \"lj_bcdef.h\"\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_bc.h",
    "content": "/*\n** Bytecode instruction format.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BC_H\n#define _LJ_BC_H\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit:\n**\n** +----+----+----+----+\n** | B  | C  | A  | OP | Format ABC\n** +----+----+----+----+\n** |    D    | A  | OP | Format AD\n** +--------------------\n** MSB               LSB\n**\n** In-memory instructions are always stored in host byte order.\n*/\n\n/* Operand ranges and related constants. */\n#define BCMAX_A\t\t0xff\n#define BCMAX_B\t\t0xff\n#define BCMAX_C\t\t0xff\n#define BCMAX_D\t\t0xffff\n#define BCBIAS_J\t0x8000\n#define NO_REG\t\tBCMAX_A\n#define NO_JMP\t\t(~(BCPos)0)\n\n/* Macros to get instruction fields. */\n#define bc_op(i)\t((BCOp)((i)&0xff))\n#define bc_a(i)\t\t((BCReg)(((i)>>8)&0xff))\n#define bc_b(i)\t\t((BCReg)((i)>>24))\n#define bc_c(i)\t\t((BCReg)(((i)>>16)&0xff))\n#define bc_d(i)\t\t((BCReg)((i)>>16))\n#define bc_j(i)\t\t((ptrdiff_t)bc_d(i)-BCBIAS_J)\n\n/* Macros to set instruction fields. */\n#define setbc_byte(p, x, ofs) \\\n  ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x)\n#define setbc_op(p, x)\tsetbc_byte(p, (x), 0)\n#define setbc_a(p, x)\tsetbc_byte(p, (x), 1)\n#define setbc_b(p, x)\tsetbc_byte(p, (x), 3)\n#define setbc_c(p, x)\tsetbc_byte(p, (x), 2)\n#define setbc_d(p, x) \\\n  ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x)\n#define setbc_j(p, x)\tsetbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J))\n\n/* Macros to compose instructions. */\n#define BCINS_ABC(o, a, b, c) \\\n  (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16))\n#define BCINS_AD(o, a, d) \\\n  (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16))\n#define BCINS_AJ(o, a, j)\tBCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J))\n\n/* Bytecode instruction definition. Order matters, see below.\n**\n** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod)\n**\n** The opcode name suffixes specify the type for RB/RC or RD:\n** V = variable slot\n** S = string const\n** N = number const\n** P = primitive type (~itype)\n** B = unsigned byte literal\n** M = multiple args/results\n*/\n#define BCDEF(_) \\\n  /* Comparison ops. ORDER OPR. */ \\\n  _(ISLT,\tvar,\t___,\tvar,\tlt) \\\n  _(ISGE,\tvar,\t___,\tvar,\tlt) \\\n  _(ISLE,\tvar,\t___,\tvar,\tle) \\\n  _(ISGT,\tvar,\t___,\tvar,\tle) \\\n  \\\n  _(ISEQV,\tvar,\t___,\tvar,\teq) \\\n  _(ISNEV,\tvar,\t___,\tvar,\teq) \\\n  _(ISEQS,\tvar,\t___,\tstr,\teq) \\\n  _(ISNES,\tvar,\t___,\tstr,\teq) \\\n  _(ISEQN,\tvar,\t___,\tnum,\teq) \\\n  _(ISNEN,\tvar,\t___,\tnum,\teq) \\\n  _(ISEQP,\tvar,\t___,\tpri,\teq) \\\n  _(ISNEP,\tvar,\t___,\tpri,\teq) \\\n  \\\n  /* Unary test and copy ops. */ \\\n  _(ISTC,\tdst,\t___,\tvar,\t___) \\\n  _(ISFC,\tdst,\t___,\tvar,\t___) \\\n  _(IST,\t___,\t___,\tvar,\t___) \\\n  _(ISF,\t___,\t___,\tvar,\t___) \\\n  _(ISTYPE,\tvar,\t___,\tlit,\t___) \\\n  _(ISNUM,\tvar,\t___,\tlit,\t___) \\\n  \\\n  /* Unary ops. */ \\\n  _(MOV,\tdst,\t___,\tvar,\t___) \\\n  _(NOT,\tdst,\t___,\tvar,\t___) \\\n  _(UNM,\tdst,\t___,\tvar,\tunm) \\\n  _(LEN,\tdst,\t___,\tvar,\tlen) \\\n  \\\n  /* Binary ops. ORDER OPR. VV last, POW must be next. */ \\\n  _(ADDVN,\tdst,\tvar,\tnum,\tadd) \\\n  _(SUBVN,\tdst,\tvar,\tnum,\tsub) \\\n  _(MULVN,\tdst,\tvar,\tnum,\tmul) \\\n  _(DIVVN,\tdst,\tvar,\tnum,\tdiv) \\\n  _(MODVN,\tdst,\tvar,\tnum,\tmod) \\\n  \\\n  _(ADDNV,\tdst,\tvar,\tnum,\tadd) \\\n  _(SUBNV,\tdst,\tvar,\tnum,\tsub) \\\n  _(MULNV,\tdst,\tvar,\tnum,\tmul) \\\n  _(DIVNV,\tdst,\tvar,\tnum,\tdiv) \\\n  _(MODNV,\tdst,\tvar,\tnum,\tmod) \\\n  \\\n  _(ADDVV,\tdst,\tvar,\tvar,\tadd) \\\n  _(SUBVV,\tdst,\tvar,\tvar,\tsub) \\\n  _(MULVV,\tdst,\tvar,\tvar,\tmul) \\\n  _(DIVVV,\tdst,\tvar,\tvar,\tdiv) \\\n  _(MODVV,\tdst,\tvar,\tvar,\tmod) \\\n  \\\n  _(POW,\tdst,\tvar,\tvar,\tpow) \\\n  _(CAT,\tdst,\trbase,\trbase,\tconcat) \\\n  \\\n  /* Constant ops. */ \\\n  _(KSTR,\tdst,\t___,\tstr,\t___) \\\n  _(KCDATA,\tdst,\t___,\tcdata,\t___) \\\n  _(KSHORT,\tdst,\t___,\tlits,\t___) \\\n  _(KNUM,\tdst,\t___,\tnum,\t___) \\\n  _(KPRI,\tdst,\t___,\tpri,\t___) \\\n  _(KNIL,\tbase,\t___,\tbase,\t___) \\\n  \\\n  /* Upvalue and function ops. */ \\\n  _(UGET,\tdst,\t___,\tuv,\t___) \\\n  _(USETV,\tuv,\t___,\tvar,\t___) \\\n  _(USETS,\tuv,\t___,\tstr,\t___) \\\n  _(USETN,\tuv,\t___,\tnum,\t___) \\\n  _(USETP,\tuv,\t___,\tpri,\t___) \\\n  _(UCLO,\trbase,\t___,\tjump,\t___) \\\n  _(FNEW,\tdst,\t___,\tfunc,\tgc) \\\n  \\\n  /* Table ops. */ \\\n  _(TNEW,\tdst,\t___,\tlit,\tgc) \\\n  _(TDUP,\tdst,\t___,\ttab,\tgc) \\\n  _(GGET,\tdst,\t___,\tstr,\tindex) \\\n  _(GSET,\tvar,\t___,\tstr,\tnewindex) \\\n  _(TGETV,\tdst,\tvar,\tvar,\tindex) \\\n  _(TGETS,\tdst,\tvar,\tstr,\tindex) \\\n  _(TGETB,\tdst,\tvar,\tlit,\tindex) \\\n  _(TGETR,\tdst,\tvar,\tvar,\tindex) \\\n  _(TSETV,\tvar,\tvar,\tvar,\tnewindex) \\\n  _(TSETS,\tvar,\tvar,\tstr,\tnewindex) \\\n  _(TSETB,\tvar,\tvar,\tlit,\tnewindex) \\\n  _(TSETM,\tbase,\t___,\tnum,\tnewindex) \\\n  _(TSETR,\tvar,\tvar,\tvar,\tnewindex) \\\n  \\\n  /* Calls and vararg handling. T = tail call. */ \\\n  _(CALLM,\tbase,\tlit,\tlit,\tcall) \\\n  _(CALL,\tbase,\tlit,\tlit,\tcall) \\\n  _(CALLMT,\tbase,\t___,\tlit,\tcall) \\\n  _(CALLT,\tbase,\t___,\tlit,\tcall) \\\n  _(ITERC,\tbase,\tlit,\tlit,\tcall) \\\n  _(ITERN,\tbase,\tlit,\tlit,\tcall) \\\n  _(VARG,\tbase,\tlit,\tlit,\t___) \\\n  _(ISNEXT,\tbase,\t___,\tjump,\t___) \\\n  \\\n  /* Returns. */ \\\n  _(RETM,\tbase,\t___,\tlit,\t___) \\\n  _(RET,\trbase,\t___,\tlit,\t___) \\\n  _(RET0,\trbase,\t___,\tlit,\t___) \\\n  _(RET1,\trbase,\t___,\tlit,\t___) \\\n  \\\n  /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \\\n  _(FORI,\tbase,\t___,\tjump,\t___) \\\n  _(JFORI,\tbase,\t___,\tjump,\t___) \\\n  \\\n  _(FORL,\tbase,\t___,\tjump,\t___) \\\n  _(IFORL,\tbase,\t___,\tjump,\t___) \\\n  _(JFORL,\tbase,\t___,\tlit,\t___) \\\n  \\\n  _(ITERL,\tbase,\t___,\tjump,\t___) \\\n  _(IITERL,\tbase,\t___,\tjump,\t___) \\\n  _(JITERL,\tbase,\t___,\tlit,\t___) \\\n  \\\n  _(LOOP,\trbase,\t___,\tjump,\t___) \\\n  _(ILOOP,\trbase,\t___,\tjump,\t___) \\\n  _(JLOOP,\trbase,\t___,\tlit,\t___) \\\n  \\\n  _(JMP,\trbase,\t___,\tjump,\t___) \\\n  \\\n  /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \\\n  _(FUNCF,\trbase,\t___,\t___,\t___) \\\n  _(IFUNCF,\trbase,\t___,\t___,\t___) \\\n  _(JFUNCF,\trbase,\t___,\tlit,\t___) \\\n  _(FUNCV,\trbase,\t___,\t___,\t___) \\\n  _(IFUNCV,\trbase,\t___,\t___,\t___) \\\n  _(JFUNCV,\trbase,\t___,\tlit,\t___) \\\n  _(FUNCC,\trbase,\t___,\t___,\t___) \\\n  _(FUNCCW,\trbase,\t___,\t___,\t___)\n\n/* Bytecode opcode numbers. */\ntypedef enum {\n#define BCENUM(name, ma, mb, mc, mt)\tBC_##name,\nBCDEF(BCENUM)\n#undef BCENUM\n  BC__MAX\n} BCOp;\n\nLJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV);\nLJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV);\nLJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES);\nLJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN);\nLJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP);\nLJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE);\nLJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT);\nLJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT);\nLJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC);\nLJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM);\nLJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT);\nLJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET);\nLJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL);\nLJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL);\nLJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL);\nLJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL);\nLJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP);\nLJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP);\nLJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF);\nLJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF);\nLJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);\nLJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);\n\n/* This solves a circular dependency problem, change as needed. */\n#define FF_next_N\t4\n\n/* Stack slots used by FORI/FORL, relative to operand A. */\nenum {\n  FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT\n};\n\n/* Bytecode operand modes. ORDER BCMode */\ntypedef enum {\n  BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv,  /* Mode A must be <= 7 */\n  BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata,\n  BCM_max\n} BCMode;\n#define BCM___\t\tBCMnone\n\n#define bcmode_a(op)\t((BCMode)(lj_bc_mode[op] & 7))\n#define bcmode_b(op)\t((BCMode)((lj_bc_mode[op]>>3) & 15))\n#define bcmode_c(op)\t((BCMode)((lj_bc_mode[op]>>7) & 15))\n#define bcmode_d(op)\tbcmode_c(op)\n#define bcmode_hasd(op)\t((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3))\n#define bcmode_mm(op)\t((MMS)(lj_bc_mode[op]>>11))\n\n#define BCMODE(name, ma, mb, mc, mm) \\\n  (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)),\n#define BCMODE_FF\t0\n\nstatic LJ_AINLINE int bc_isret(BCOp op)\n{\n  return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1);\n}\n\nLJ_DATA const uint16_t lj_bc_mode[];\nLJ_DATA const uint16_t lj_bc_ofs[];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_bcdump.h",
    "content": "/*\n** Bytecode dump definitions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BCDUMP_H\n#define _LJ_BCDUMP_H\n\n#include \"lj_obj.h\"\n#include \"lj_lex.h\"\n\n/* -- Bytecode dump format ------------------------------------------------ */\n\n/*\n** dump   = header proto+ 0U\n** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]\n** proto  = lengthU pdata\n** pdata  = phead bcinsW* uvdataH* kgc* knum* [debugB*]\n** phead  = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU\n**          [debuglenU [firstlineU numlineU]]\n** kgc    = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }\n** knum   = intU0 | (loU1 hiU)\n** ktab   = narrayU nhashU karray* khash*\n** karray = ktabk\n** khash  = ktabk ktabk\n** ktabk  = ktabtypeU { intU | (loU hiU) | strB* }\n**\n** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1\n*/\n\n/* Bytecode dump header. */\n#define BCDUMP_HEAD1\t\t0x1b\n#define BCDUMP_HEAD2\t\t0x4c\n#define BCDUMP_HEAD3\t\t0x4a\n\n/* If you perform *any* kind of private modifications to the bytecode itself\n** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.\n*/\n#define BCDUMP_VERSION\t\t2\n\n/* Compatibility flags. */\n#define BCDUMP_F_BE\t\t0x01\n#define BCDUMP_F_STRIP\t\t0x02\n#define BCDUMP_F_FFI\t\t0x04\n#define BCDUMP_F_FR2\t\t0x08\n\n#define BCDUMP_F_KNOWN\t\t(BCDUMP_F_FR2*2-1)\n\n/* Type codes for the GC constants of a prototype. Plus length for strings. */\nenum {\n  BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,\n  BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR\n};\n\n/* Type codes for the keys/values of a constant table. */\nenum {\n  BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,\n  BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR\n};\n\n/* -- Bytecode reader/writer ---------------------------------------------- */\n\nLJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,\n\t\t       void *data, int strip);\nLJ_FUNC GCproto *lj_bcread_proto(LexState *ls);\nLJ_FUNC GCproto *lj_bcread(LexState *ls);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_bcread.c",
    "content": "/*\n** Bytecode reader.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bcread_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lualib.h\"\n#endif\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_state.h\"\n#include \"lj_strfmt.h\"\n\n/* Reuse some lexer fields for our own purposes. */\n#define bcread_flags(ls)\tls->level\n#define bcread_swap(ls) \\\n  ((bcread_flags(ls) & BCDUMP_F_BE) != LJ_BE*BCDUMP_F_BE)\n#define bcread_oldtop(L, ls)\trestorestack(L, ls->lastline)\n#define bcread_savetop(L, ls, top) \\\n  ls->lastline = (BCLine)savestack(L, (top))\n\n/* -- Input buffer handling ----------------------------------------------- */\n\n/* Throw reader error. */\nstatic LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em)\n{\n  lua_State *L = ls->L;\n  const char *name = ls->chunkarg;\n  if (*name == BCDUMP_HEAD1) name = \"(binary)\";\n  else if (*name == '@' || *name == '=') name++;\n  lj_strfmt_pushf(L, \"%s: %s\", name, err2msg(em));\n  lj_err_throw(L, LUA_ERRSYNTAX);\n}\n\n/* Refill buffer. */\nstatic LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need)\n{\n  lj_assertLS(len != 0, \"empty refill\");\n  if (len > LJ_MAX_BUF || ls->c < 0)\n    bcread_error(ls, LJ_ERR_BCBAD);\n  do {\n    const char *buf;\n    size_t sz;\n    char *p = ls->sb.b;\n    MSize n = (MSize)(ls->pe - ls->p);\n    if (n) {  /* Copy remainder to buffer. */\n      if (sbuflen(&ls->sb)) {  /* Move down in buffer. */\n\tlj_assertLS(ls->pe == ls->sb.w, \"bad buffer pointer\");\n\tif (ls->p != p) memmove(p, ls->p, n);\n      } else {  /* Copy from buffer provided by reader. */\n\tp = lj_buf_need(&ls->sb, len);\n\tmemcpy(p, ls->p, n);\n      }\n      ls->p = p;\n      ls->pe = p + n;\n    }\n    ls->sb.w = p + n;\n    buf = ls->rfunc(ls->L, ls->rdata, &sz);  /* Get more data from reader. */\n    if (buf == NULL || sz == 0) {  /* EOF? */\n      if (need) bcread_error(ls, LJ_ERR_BCBAD);\n      ls->c = -1;  /* Only bad if we get called again. */\n      break;\n    }\n    if (sz >= LJ_MAX_BUF - n) lj_err_mem(ls->L);\n    if (n) {  /* Append to buffer. */\n      n += (MSize)sz;\n      p = lj_buf_need(&ls->sb, n < len ? len : n);\n      memcpy(ls->sb.w, buf, sz);\n      ls->sb.w = p + n;\n      ls->p = p;\n      ls->pe = p + n;\n    } else {  /* Return buffer provided by reader. */\n      ls->p = buf;\n      ls->pe = buf + sz;\n    }\n  } while ((MSize)(ls->pe - ls->p) < len);\n}\n\n/* Need a certain number of bytes. */\nstatic LJ_AINLINE void bcread_need(LexState *ls, MSize len)\n{\n  if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len))\n    bcread_fill(ls, len, 1);\n}\n\n/* Want to read up to a certain number of bytes, but may need less. */\nstatic LJ_AINLINE void bcread_want(LexState *ls, MSize len)\n{\n  if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len))\n    bcread_fill(ls, len, 0);\n}\n\n/* Return memory block from buffer. */\nstatic LJ_AINLINE uint8_t *bcread_mem(LexState *ls, MSize len)\n{\n  uint8_t *p = (uint8_t *)ls->p;\n  ls->p += len;\n  lj_assertLS(ls->p <= ls->pe, \"buffer read overflow\");\n  return p;\n}\n\n/* Copy memory block from buffer. */\nstatic void bcread_block(LexState *ls, void *q, MSize len)\n{\n  memcpy(q, bcread_mem(ls, len), len);\n}\n\n/* Read byte from buffer. */\nstatic LJ_AINLINE uint32_t bcread_byte(LexState *ls)\n{\n  lj_assertLS(ls->p < ls->pe, \"buffer read overflow\");\n  return (uint32_t)(uint8_t)*ls->p++;\n}\n\n/* Read ULEB128 value from buffer. */\nstatic LJ_AINLINE uint32_t bcread_uleb128(LexState *ls)\n{\n  uint32_t v = lj_buf_ruleb128(&ls->p);\n  lj_assertLS(ls->p <= ls->pe, \"buffer read overflow\");\n  return v;\n}\n\n/* Read top 32 bits of 33 bit ULEB128 value from buffer. */\nstatic uint32_t bcread_uleb128_33(LexState *ls)\n{\n  const uint8_t *p = (const uint8_t *)ls->p;\n  uint32_t v = (*p++ >> 1);\n  if (LJ_UNLIKELY(v >= 0x40)) {\n    int sh = -1;\n    v &= 0x3f;\n    do {\n     v |= ((*p & 0x7f) << (sh += 7));\n   } while (*p++ >= 0x80);\n  }\n  ls->p = (char *)p;\n  lj_assertLS(ls->p <= ls->pe, \"buffer read overflow\");\n  return v;\n}\n\n/* -- Bytecode reader ----------------------------------------------------- */\n\n/* Read debug info of a prototype. */\nstatic void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)\n{\n  void *lineinfo = (void *)proto_lineinfo(pt);\n  bcread_block(ls, lineinfo, sizedbg);\n  /* Swap lineinfo if the endianess differs. */\n  if (bcread_swap(ls) && pt->numline >= 256) {\n    MSize i, n = pt->sizebc-1;\n    if (pt->numline < 65536) {\n      uint16_t *p = (uint16_t *)lineinfo;\n      for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8));\n    } else {\n      uint32_t *p = (uint32_t *)lineinfo;\n      for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]);\n    }\n  }\n}\n\n/* Find pointer to varinfo. */\nstatic const void *bcread_varinfo(GCproto *pt)\n{\n  const uint8_t *p = proto_uvinfo(pt);\n  MSize n = pt->sizeuv;\n  if (n) while (*p++ || --n) ;\n  return p;\n}\n\n/* Read a single constant key/value of a template table. */\nstatic void bcread_ktabk(LexState *ls, TValue *o)\n{\n  MSize tp = bcread_uleb128(ls);\n  if (tp >= BCDUMP_KTAB_STR) {\n    MSize len = tp - BCDUMP_KTAB_STR;\n    const char *p = (const char *)bcread_mem(ls, len);\n    setstrV(ls->L, o, lj_str_new(ls->L, p, len));\n  } else if (tp == BCDUMP_KTAB_INT) {\n    setintV(o, (int32_t)bcread_uleb128(ls));\n  } else if (tp == BCDUMP_KTAB_NUM) {\n    o->u32.lo = bcread_uleb128(ls);\n    o->u32.hi = bcread_uleb128(ls);\n  } else {\n    lj_assertLS(tp <= BCDUMP_KTAB_TRUE, \"bad constant type %d\", tp);\n    setpriV(o, ~tp);\n  }\n}\n\n/* Read a template table. */\nstatic GCtab *bcread_ktab(LexState *ls)\n{\n  MSize narray = bcread_uleb128(ls);\n  MSize nhash = bcread_uleb128(ls);\n  GCtab *t = lj_tab_new(ls->L, narray, hsize2hbits(nhash));\n  if (narray) {  /* Read array entries. */\n    MSize i;\n    TValue *o = tvref(t->array);\n    for (i = 0; i < narray; i++, o++)\n      bcread_ktabk(ls, o);\n  }\n  if (nhash) {  /* Read hash entries. */\n    MSize i;\n    for (i = 0; i < nhash; i++) {\n      TValue key;\n      bcread_ktabk(ls, &key);\n      lj_assertLS(!tvisnil(&key), \"nil key\");\n      bcread_ktabk(ls, lj_tab_set(ls->L, t, &key));\n    }\n  }\n  return t;\n}\n\n/* Read GC constants of a prototype. */\nstatic void bcread_kgc(LexState *ls, GCproto *pt, MSize sizekgc)\n{\n  MSize i;\n  GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;\n  for (i = 0; i < sizekgc; i++, kr++) {\n    MSize tp = bcread_uleb128(ls);\n    if (tp >= BCDUMP_KGC_STR) {\n      MSize len = tp - BCDUMP_KGC_STR;\n      const char *p = (const char *)bcread_mem(ls, len);\n      setgcref(*kr, obj2gco(lj_str_new(ls->L, p, len)));\n    } else if (tp == BCDUMP_KGC_TAB) {\n      setgcref(*kr, obj2gco(bcread_ktab(ls)));\n#if LJ_HASFFI\n    } else if (tp != BCDUMP_KGC_CHILD) {\n      CTypeID id = tp == BCDUMP_KGC_COMPLEX ? CTID_COMPLEX_DOUBLE :\n\t\t   tp == BCDUMP_KGC_I64 ? CTID_INT64 : CTID_UINT64;\n      CTSize sz = tp == BCDUMP_KGC_COMPLEX ? 16 : 8;\n      GCcdata *cd = lj_cdata_new_(ls->L, id, sz);\n      TValue *p = (TValue *)cdataptr(cd);\n      setgcref(*kr, obj2gco(cd));\n      p[0].u32.lo = bcread_uleb128(ls);\n      p[0].u32.hi = bcread_uleb128(ls);\n      if (tp == BCDUMP_KGC_COMPLEX) {\n\tp[1].u32.lo = bcread_uleb128(ls);\n\tp[1].u32.hi = bcread_uleb128(ls);\n      }\n#endif\n    } else {\n      lua_State *L = ls->L;\n      lj_assertLS(tp == BCDUMP_KGC_CHILD, \"bad constant type %d\", tp);\n      if (L->top <= bcread_oldtop(L, ls))  /* Stack underflow? */\n\tbcread_error(ls, LJ_ERR_BCBAD);\n      L->top--;\n      setgcref(*kr, obj2gco(protoV(L->top)));\n    }\n  }\n}\n\n/* Read number constants of a prototype. */\nstatic void bcread_knum(LexState *ls, GCproto *pt, MSize sizekn)\n{\n  MSize i;\n  TValue *o = mref(pt->k, TValue);\n  for (i = 0; i < sizekn; i++, o++) {\n    int isnum = (ls->p[0] & 1);\n    uint32_t lo = bcread_uleb128_33(ls);\n    if (isnum) {\n      o->u32.lo = lo;\n      o->u32.hi = bcread_uleb128(ls);\n    } else {\n      setintV(o, lo);\n    }\n  }\n}\n\n/* Read bytecode instructions. */\nstatic void bcread_bytecode(LexState *ls, GCproto *pt, MSize sizebc)\n{\n  BCIns *bc = proto_bc(pt);\n  bc[0] = BCINS_AD((pt->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,\n\t\t   pt->framesize, 0);\n  bcread_block(ls, bc+1, (sizebc-1)*(MSize)sizeof(BCIns));\n  /* Swap bytecode instructions if the endianess differs. */\n  if (bcread_swap(ls)) {\n    MSize i;\n    for (i = 1; i < sizebc; i++) bc[i] = lj_bswap(bc[i]);\n  }\n}\n\n/* Read upvalue refs. */\nstatic void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv)\n{\n  if (sizeuv) {\n    uint16_t *uv = proto_uv(pt);\n    bcread_block(ls, uv, sizeuv*2);\n    /* Swap upvalue refs if the endianess differs. */\n    if (bcread_swap(ls)) {\n      MSize i;\n      for (i = 0; i < sizeuv; i++)\n\tuv[i] = (uint16_t)((uv[i] >> 8)|(uv[i] << 8));\n    }\n  }\n}\n\n/* Read a prototype. */\nGCproto *lj_bcread_proto(LexState *ls)\n{\n  GCproto *pt;\n  MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept;\n  MSize ofsk, ofsuv, ofsdbg;\n  MSize sizedbg = 0;\n  BCLine firstline = 0, numline = 0;\n\n  /* Read prototype header. */\n  flags = bcread_byte(ls);\n  numparams = bcread_byte(ls);\n  framesize = bcread_byte(ls);\n  sizeuv = bcread_byte(ls);\n  sizekgc = bcread_uleb128(ls);\n  sizekn = bcread_uleb128(ls);\n  sizebc = bcread_uleb128(ls) + 1;\n  if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) {\n    sizedbg = bcread_uleb128(ls);\n    if (sizedbg) {\n      firstline = bcread_uleb128(ls);\n      numline = bcread_uleb128(ls);\n    }\n  }\n\n  /* Calculate total size of prototype including all colocated arrays. */\n  sizept = (MSize)sizeof(GCproto) +\n\t   sizebc*(MSize)sizeof(BCIns) +\n\t   sizekgc*(MSize)sizeof(GCRef);\n  sizept = (sizept + (MSize)sizeof(TValue)-1) & ~((MSize)sizeof(TValue)-1);\n  ofsk = sizept; sizept += sizekn*(MSize)sizeof(TValue);\n  ofsuv = sizept; sizept += ((sizeuv+1)&~1)*2;\n  ofsdbg = sizept; sizept += sizedbg;\n\n  /* Allocate prototype object and initialize its fields. */\n  pt = (GCproto *)lj_mem_newgco(ls->L, (MSize)sizept);\n  pt->gct = ~LJ_TPROTO;\n  pt->numparams = (uint8_t)numparams;\n  pt->framesize = (uint8_t)framesize;\n  pt->sizebc = sizebc;\n  setmref(pt->k, (char *)pt + ofsk);\n  setmref(pt->uv, (char *)pt + ofsuv);\n  pt->sizekgc = 0;  /* Set to zero until fully initialized. */\n  pt->sizekn = sizekn;\n  pt->sizept = sizept;\n  pt->sizeuv = (uint8_t)sizeuv;\n  pt->flags = (uint8_t)flags;\n  pt->trace = 0;\n  setgcref(pt->chunkname, obj2gco(ls->chunkname));\n\n  /* Close potentially uninitialized gap between bc and kgc. */\n  *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(sizekgc+1)) = 0;\n\n  /* Read bytecode instructions and upvalue refs. */\n  bcread_bytecode(ls, pt, sizebc);\n  bcread_uv(ls, pt, sizeuv);\n\n  /* Read constants. */\n  bcread_kgc(ls, pt, sizekgc);\n  pt->sizekgc = sizekgc;\n  bcread_knum(ls, pt, sizekn);\n\n  /* Read and initialize debug info. */\n  pt->firstline = firstline;\n  pt->numline = numline;\n  if (sizedbg) {\n    MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);\n    setmref(pt->lineinfo, (char *)pt + ofsdbg);\n    setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);\n    bcread_dbg(ls, pt, sizedbg);\n    setmref(pt->varinfo, bcread_varinfo(pt));\n  } else {\n    setmref(pt->lineinfo, NULL);\n    setmref(pt->uvinfo, NULL);\n    setmref(pt->varinfo, NULL);\n  }\n  return pt;\n}\n\n/* Read and check header of bytecode dump. */\nstatic int bcread_header(LexState *ls)\n{\n  uint32_t flags;\n  bcread_want(ls, 3+5+5);\n  if (bcread_byte(ls) != BCDUMP_HEAD2 ||\n      bcread_byte(ls) != BCDUMP_HEAD3 ||\n      bcread_byte(ls) != BCDUMP_VERSION) return 0;\n  bcread_flags(ls) = flags = bcread_uleb128(ls);\n  if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0;\n  if ((flags & BCDUMP_F_FR2) != LJ_FR2*BCDUMP_F_FR2) return 0;\n  if ((flags & BCDUMP_F_FFI)) {\n#if LJ_HASFFI\n    lua_State *L = ls->L;\n    ctype_loadffi(L);\n#else\n    return 0;\n#endif\n  }\n  if ((flags & BCDUMP_F_STRIP)) {\n    ls->chunkname = lj_str_newz(ls->L, ls->chunkarg);\n  } else {\n    MSize len = bcread_uleb128(ls);\n    bcread_need(ls, len);\n    ls->chunkname = lj_str_new(ls->L, (const char *)bcread_mem(ls, len), len);\n  }\n  return 1;  /* Ok. */\n}\n\n/* Read a bytecode dump. */\nGCproto *lj_bcread(LexState *ls)\n{\n  lua_State *L = ls->L;\n  lj_assertLS(ls->c == BCDUMP_HEAD1, \"bad bytecode header\");\n  bcread_savetop(L, ls, L->top);\n  lj_buf_reset(&ls->sb);\n  /* Check for a valid bytecode dump header. */\n  if (!bcread_header(ls))\n    bcread_error(ls, LJ_ERR_BCFMT);\n  for (;;) {  /* Process all prototypes in the bytecode dump. */\n    GCproto *pt;\n    MSize len;\n    const char *startp;\n    /* Read length. */\n    if (ls->p < ls->pe && ls->p[0] == 0) {  /* Shortcut EOF. */\n      ls->p++;\n      break;\n    }\n    bcread_want(ls, 5);\n    len = bcread_uleb128(ls);\n    if (!len) break;  /* EOF */\n    bcread_need(ls, len);\n    startp = ls->p;\n    pt = lj_bcread_proto(ls);\n    if (ls->p != startp + len)\n      bcread_error(ls, LJ_ERR_BCBAD);\n    setprotoV(L, L->top, pt);\n    incr_top(L);\n  }\n  if ((ls->pe != ls->p && !ls->endmark) || L->top-1 != bcread_oldtop(L, ls))\n    bcread_error(ls, LJ_ERR_BCBAD);\n  /* Pop off last prototype. */\n  L->top--;\n  return protoV(L->top);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_bcwrite.c",
    "content": "/*\n** Bytecode writer.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_bcwrite_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_buf.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#if LJ_HASJIT\n#include \"lj_dispatch.h\"\n#include \"lj_jit.h\"\n#endif\n#include \"lj_strfmt.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_vm.h\"\n\n/* Context for bytecode writer. */\ntypedef struct BCWriteCtx {\n  SBuf sb;\t\t\t/* Output buffer. */\n  GCproto *pt;\t\t\t/* Root prototype. */\n  lua_Writer wfunc;\t\t/* Writer callback. */\n  void *wdata;\t\t\t/* Writer callback data. */\n  int strip;\t\t\t/* Strip debug info. */\n  int status;\t\t\t/* Status from writer callback. */\n#ifdef LUA_USE_ASSERT\n  global_State *g;\n#endif\n} BCWriteCtx;\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertBCW(c, ...)\tlj_assertG_(ctx->g, (c), __VA_ARGS__)\n#else\n#define lj_assertBCW(c, ...)\t((void)ctx)\n#endif\n\n/* -- Bytecode writer ----------------------------------------------------- */\n\n/* Write a single constant key/value of a template table. */\nstatic void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow)\n{\n  char *p = lj_buf_more(&ctx->sb, 1+10);\n  if (tvisstr(o)) {\n    const GCstr *str = strV(o);\n    MSize len = str->len;\n    p = lj_buf_more(&ctx->sb, 5+len);\n    p = lj_strfmt_wuleb128(p, BCDUMP_KTAB_STR+len);\n    p = lj_buf_wmem(p, strdata(str), len);\n  } else if (tvisint(o)) {\n    *p++ = BCDUMP_KTAB_INT;\n    p = lj_strfmt_wuleb128(p, intV(o));\n  } else if (tvisnum(o)) {\n    if (!LJ_DUALNUM && narrow) {  /* Narrow number constants to integers. */\n      lua_Number num = numV(o);\n      int32_t k = lj_num2int(num);\n      if (num == (lua_Number)k) {  /* -0 is never a constant. */\n\t*p++ = BCDUMP_KTAB_INT;\n\tp = lj_strfmt_wuleb128(p, k);\n\tctx->sb.w = p;\n\treturn;\n      }\n    }\n    *p++ = BCDUMP_KTAB_NUM;\n    p = lj_strfmt_wuleb128(p, o->u32.lo);\n    p = lj_strfmt_wuleb128(p, o->u32.hi);\n  } else {\n    lj_assertBCW(tvispri(o), \"unhandled type %d\", itype(o));\n    *p++ = BCDUMP_KTAB_NIL+~itype(o);\n  }\n  ctx->sb.w = p;\n}\n\n/* Write a template table. */\nstatic void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t)\n{\n  MSize narray = 0, nhash = 0;\n  if (t->asize > 0) {  /* Determine max. length of array part. */\n    ptrdiff_t i;\n    TValue *array = tvref(t->array);\n    for (i = (ptrdiff_t)t->asize-1; i >= 0; i--)\n      if (!tvisnil(&array[i]))\n\tbreak;\n    narray = (MSize)(i+1);\n  }\n  if (t->hmask > 0) {  /* Count number of used hash slots. */\n    MSize i, hmask = t->hmask;\n    Node *node = noderef(t->node);\n    for (i = 0; i <= hmask; i++)\n      nhash += !tvisnil(&node[i].val);\n  }\n  /* Write number of array slots and hash slots. */\n  p = lj_strfmt_wuleb128(p, narray);\n  p = lj_strfmt_wuleb128(p, nhash);\n  ctx->sb.w = p;\n  if (narray) {  /* Write array entries (may contain nil). */\n    MSize i;\n    TValue *o = tvref(t->array);\n    for (i = 0; i < narray; i++, o++)\n      bcwrite_ktabk(ctx, o, 1);\n  }\n  if (nhash) {  /* Write hash entries. */\n    MSize i = nhash;\n    Node *node = noderef(t->node) + t->hmask;\n    for (;; node--)\n      if (!tvisnil(&node->val)) {\n\tbcwrite_ktabk(ctx, &node->key, 0);\n\tbcwrite_ktabk(ctx, &node->val, 1);\n\tif (--i == 0) break;\n      }\n  }\n}\n\n/* Write GC constants of a prototype. */\nstatic void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize i, sizekgc = pt->sizekgc;\n  GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;\n  for (i = 0; i < sizekgc; i++, kr++) {\n    GCobj *o = gcref(*kr);\n    MSize tp, need = 1;\n    char *p;\n    /* Determine constant type and needed size. */\n    if (o->gch.gct == ~LJ_TSTR) {\n      tp = BCDUMP_KGC_STR + gco2str(o)->len;\n      need = 5+gco2str(o)->len;\n    } else if (o->gch.gct == ~LJ_TPROTO) {\n      lj_assertBCW((pt->flags & PROTO_CHILD), \"prototype has unexpected child\");\n      tp = BCDUMP_KGC_CHILD;\n#if LJ_HASFFI\n    } else if (o->gch.gct == ~LJ_TCDATA) {\n      CTypeID id = gco2cd(o)->ctypeid;\n      need = 1+4*5;\n      if (id == CTID_INT64) {\n\ttp = BCDUMP_KGC_I64;\n      } else if (id == CTID_UINT64) {\n\ttp = BCDUMP_KGC_U64;\n      } else {\n\tlj_assertBCW(id == CTID_COMPLEX_DOUBLE,\n\t\t     \"bad cdata constant CTID %d\", id);\n\ttp = BCDUMP_KGC_COMPLEX;\n      }\n#endif\n    } else {\n      lj_assertBCW(o->gch.gct == ~LJ_TTAB,\n\t\t   \"bad constant GC type %d\", o->gch.gct);\n      tp = BCDUMP_KGC_TAB;\n      need = 1+2*5;\n    }\n    /* Write constant type. */\n    p = lj_buf_more(&ctx->sb, need);\n    p = lj_strfmt_wuleb128(p, tp);\n    /* Write constant data (if any). */\n    if (tp >= BCDUMP_KGC_STR) {\n      p = lj_buf_wmem(p, strdata(gco2str(o)), gco2str(o)->len);\n    } else if (tp == BCDUMP_KGC_TAB) {\n      bcwrite_ktab(ctx, p, gco2tab(o));\n      continue;\n#if LJ_HASFFI\n    } else if (tp != BCDUMP_KGC_CHILD) {\n      cTValue *q = (TValue *)cdataptr(gco2cd(o));\n      p = lj_strfmt_wuleb128(p, q[0].u32.lo);\n      p = lj_strfmt_wuleb128(p, q[0].u32.hi);\n      if (tp == BCDUMP_KGC_COMPLEX) {\n\tp = lj_strfmt_wuleb128(p, q[1].u32.lo);\n\tp = lj_strfmt_wuleb128(p, q[1].u32.hi);\n      }\n#endif\n    }\n    ctx->sb.w = p;\n  }\n}\n\n/* Write number constants of a prototype. */\nstatic void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize i, sizekn = pt->sizekn;\n  cTValue *o = mref(pt->k, TValue);\n  char *p = lj_buf_more(&ctx->sb, 10*sizekn);\n  for (i = 0; i < sizekn; i++, o++) {\n    int32_t k;\n    if (tvisint(o)) {\n      k = intV(o);\n      goto save_int;\n    } else {\n      /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */\n      if (!LJ_DUALNUM) {  /* Narrow number constants to integers. */\n\tlua_Number num = numV(o);\n\tk = lj_num2int(num);\n\tif (num == (lua_Number)k) {  /* -0 is never a constant. */\n\tsave_int:\n\t  p = lj_strfmt_wuleb128(p, 2*(uint32_t)k | ((uint32_t)k&0x80000000u));\n\t  if (k < 0)\n\t    p[-1] = (p[-1] & 7) | ((k>>27) & 0x18);\n\t  continue;\n\t}\n      }\n      p = lj_strfmt_wuleb128(p, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u)));\n      if (o->u32.lo >= 0x80000000u)\n\tp[-1] = (p[-1] & 7) | ((o->u32.lo>>27) & 0x18);\n      p = lj_strfmt_wuleb128(p, o->u32.hi);\n    }\n  }\n  ctx->sb.w = p;\n}\n\n/* Write bytecode instructions. */\nstatic char *bcwrite_bytecode(BCWriteCtx *ctx, char *p, GCproto *pt)\n{\n  MSize nbc = pt->sizebc-1;  /* Omit the [JI]FUNC* header. */\n#if LJ_HASJIT\n  uint8_t *q = (uint8_t *)p;\n#endif\n  p = lj_buf_wmem(p, proto_bc(pt)+1, nbc*(MSize)sizeof(BCIns));\n  UNUSED(ctx);\n#if LJ_HASJIT\n  /* Unpatch modified bytecode containing ILOOP/JLOOP etc. */\n  if ((pt->flags & PROTO_ILOOP) || pt->trace) {\n    jit_State *J = L2J(sbufL(&ctx->sb));\n    MSize i;\n    for (i = 0; i < nbc; i++, q += sizeof(BCIns)) {\n      BCOp op = (BCOp)q[LJ_ENDIAN_SELECT(0, 3)];\n      if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP ||\n\t  op == BC_JFORI) {\n\tq[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_IFORL+BC_FORL);\n      } else if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {\n\tBCReg rd = q[LJ_ENDIAN_SELECT(2, 1)] + (q[LJ_ENDIAN_SELECT(3, 0)] << 8);\n\tmemcpy(q, &traceref(J, rd)->startins, 4);\n      }\n    }\n  }\n#endif\n  return p;\n}\n\n/* Write prototype. */\nstatic void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)\n{\n  MSize sizedbg = 0;\n  char *p;\n\n  /* Recursively write children of prototype. */\n  if ((pt->flags & PROTO_CHILD)) {\n    ptrdiff_t i, n = pt->sizekgc;\n    GCRef *kr = mref(pt->k, GCRef) - 1;\n    for (i = 0; i < n; i++, kr--) {\n      GCobj *o = gcref(*kr);\n      if (o->gch.gct == ~LJ_TPROTO)\n\tbcwrite_proto(ctx, gco2pt(o));\n    }\n  }\n\n  /* Start writing the prototype info to a buffer. */\n  p = lj_buf_need(&ctx->sb,\n\t\t  5+4+6*5+(pt->sizebc-1)*(MSize)sizeof(BCIns)+pt->sizeuv*2);\n  p += 5;  /* Leave room for final size. */\n\n  /* Write prototype header. */\n  *p++ = (pt->flags & (PROTO_CHILD|PROTO_VARARG|PROTO_FFI));\n  *p++ = pt->numparams;\n  *p++ = pt->framesize;\n  *p++ = pt->sizeuv;\n  p = lj_strfmt_wuleb128(p, pt->sizekgc);\n  p = lj_strfmt_wuleb128(p, pt->sizekn);\n  p = lj_strfmt_wuleb128(p, pt->sizebc-1);\n  if (!ctx->strip) {\n    if (proto_lineinfo(pt))\n      sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt);\n    p = lj_strfmt_wuleb128(p, sizedbg);\n    if (sizedbg) {\n      p = lj_strfmt_wuleb128(p, pt->firstline);\n      p = lj_strfmt_wuleb128(p, pt->numline);\n    }\n  }\n\n  /* Write bytecode instructions and upvalue refs. */\n  p = bcwrite_bytecode(ctx, p, pt);\n  p = lj_buf_wmem(p, proto_uv(pt), pt->sizeuv*2);\n  ctx->sb.w = p;\n\n  /* Write constants. */\n  bcwrite_kgc(ctx, pt);\n  bcwrite_knum(ctx, pt);\n\n  /* Write debug info, if not stripped. */\n  if (sizedbg) {\n    p = lj_buf_more(&ctx->sb, sizedbg);\n    p = lj_buf_wmem(p, proto_lineinfo(pt), sizedbg);\n    ctx->sb.w = p;\n  }\n\n  /* Pass buffer to writer function. */\n  if (ctx->status == 0) {\n    MSize n = sbuflen(&ctx->sb) - 5;\n    MSize nn = (lj_fls(n)+8)*9 >> 6;\n    char *q = ctx->sb.b + (5 - nn);\n    p = lj_strfmt_wuleb128(q, n);  /* Fill in final size. */\n    lj_assertBCW(p == ctx->sb.b + 5, \"bad ULEB128 write\");\n    ctx->status = ctx->wfunc(sbufL(&ctx->sb), q, nn+n, ctx->wdata);\n  }\n}\n\n/* Write header of bytecode dump. */\nstatic void bcwrite_header(BCWriteCtx *ctx)\n{\n  GCstr *chunkname = proto_chunkname(ctx->pt);\n  const char *name = strdata(chunkname);\n  MSize len = chunkname->len;\n  char *p = lj_buf_need(&ctx->sb, 5+5+len);\n  *p++ = BCDUMP_HEAD1;\n  *p++ = BCDUMP_HEAD2;\n  *p++ = BCDUMP_HEAD3;\n  *p++ = BCDUMP_VERSION;\n  *p++ = (ctx->strip ? BCDUMP_F_STRIP : 0) +\n\t LJ_BE*BCDUMP_F_BE +\n\t ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0) +\n\t LJ_FR2*BCDUMP_F_FR2;\n  if (!ctx->strip) {\n    p = lj_strfmt_wuleb128(p, len);\n    p = lj_buf_wmem(p, name, len);\n  }\n  ctx->status = ctx->wfunc(sbufL(&ctx->sb), ctx->sb.b,\n\t\t\t   (MSize)(p - ctx->sb.b), ctx->wdata);\n}\n\n/* Write footer of bytecode dump. */\nstatic void bcwrite_footer(BCWriteCtx *ctx)\n{\n  if (ctx->status == 0) {\n    uint8_t zero = 0;\n    ctx->status = ctx->wfunc(sbufL(&ctx->sb), &zero, 1, ctx->wdata);\n  }\n}\n\n/* Protected callback for bytecode writer. */\nstatic TValue *cpwriter(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  BCWriteCtx *ctx = (BCWriteCtx *)ud;\n  UNUSED(L); UNUSED(dummy);\n  lj_buf_need(&ctx->sb, 1024);  /* Avoids resize for most prototypes. */\n  bcwrite_header(ctx);\n  bcwrite_proto(ctx, ctx->pt);\n  bcwrite_footer(ctx);\n  return NULL;\n}\n\n/* Write bytecode for a prototype. */\nint lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, void *data,\n\t      int strip)\n{\n  BCWriteCtx ctx;\n  int status;\n  ctx.pt = pt;\n  ctx.wfunc = writer;\n  ctx.wdata = data;\n  ctx.strip = strip;\n  ctx.status = 0;\n#ifdef LUA_USE_ASSERT\n  ctx.g = G(L);\n#endif\n  lj_buf_init(L, &ctx.sb);\n  status = lj_vm_cpcall(L, NULL, &ctx, cpwriter);\n  if (status == 0) status = ctx.status;\n  lj_buf_free(G(sbufL(&ctx.sb)), &ctx.sb);\n  return status;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_buf.c",
    "content": "/*\n** Buffer handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_buf_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Buffer management --------------------------------------------------- */\n\nstatic void buf_grow(SBuf *sb, MSize sz)\n{\n  MSize osz = sbufsz(sb), len = sbuflen(sb), nsz = osz;\n  char *b;\n  GCSize flag;\n  if (nsz < LJ_MIN_SBUF) nsz = LJ_MIN_SBUF;\n  while (nsz < sz) nsz += nsz;\n  flag = sbufflag(sb);\n  if ((flag & SBUF_FLAG_COW)) {  /* Copy-on-write semantics. */\n    lj_assertG_(G(sbufL(sb)), sb->w == sb->e, \"bad SBuf COW\");\n    b = (char *)lj_mem_new(sbufL(sb), nsz);\n    setsbufflag(sb, flag & ~(GCSize)SBUF_FLAG_COW);\n    setgcrefnull(sbufX(sb)->cowref);\n    memcpy(b, sb->b, osz);\n  } else {\n    b = (char *)lj_mem_realloc(sbufL(sb), sb->b, osz, nsz);\n  }\n  if ((flag & SBUF_FLAG_EXT)) {\n    sbufX(sb)->r = sbufX(sb)->r - sb->b + b;  /* Adjust read pointer, too. */\n  }\n  /* Adjust buffer pointers. */\n  sb->b = b;\n  sb->w = b + len;\n  sb->e = b + nsz;\n  if ((flag & SBUF_FLAG_BORROW)) {  /* Adjust borrowed buffer pointers. */\n    SBuf *bsb = mref(sbufX(sb)->bsb, SBuf);\n    bsb->b = b;\n    bsb->w = b + len;\n    bsb->e = b + nsz;\n  }\n}\n\nLJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz)\n{\n  lj_assertG_(G(sbufL(sb)), sz > sbufsz(sb), \"SBuf overflow\");\n  if (LJ_UNLIKELY(sz > LJ_MAX_BUF))\n    lj_err_mem(sbufL(sb));\n  buf_grow(sb, sz);\n  return sb->b;\n}\n\nLJ_NOINLINE char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz)\n{\n  if (sbufisext(sb)) {\n    SBufExt *sbx = (SBufExt *)sb;\n    MSize len = sbufxlen(sbx);\n    if (LJ_UNLIKELY(sz > LJ_MAX_BUF || len + sz > LJ_MAX_BUF))\n      lj_err_mem(sbufL(sbx));\n    if (len + sz > sbufsz(sbx)) {  /* Must grow. */\n      buf_grow((SBuf *)sbx, len + sz);\n    } else if (sbufxslack(sbx) < (sbufsz(sbx) >> 3)) {\n      /* Also grow to avoid excessive compactions, if slack < size/8. */\n      buf_grow((SBuf *)sbx, sbuflen(sbx) + sz);  /* Not sbufxlen! */\n      return sbx->w;\n    }\n    if (sbx->r != sbx->b) {  /* Compact by moving down. */\n      memmove(sbx->b, sbx->r, len);\n      sbx->r = sbx->b;\n      sbx->w = sbx->b + len;\n      lj_assertG_(G(sbufL(sbx)), len + sz <= sbufsz(sbx), \"bad SBuf compact\");\n    }\n  } else {\n    MSize len = sbuflen(sb);\n    lj_assertG_(G(sbufL(sb)), sz > sbufleft(sb), \"SBuf overflow\");\n    if (LJ_UNLIKELY(sz > LJ_MAX_BUF || len + sz > LJ_MAX_BUF))\n      lj_err_mem(sbufL(sb));\n    buf_grow(sb, len + sz);\n  }\n  return sb->w;\n}\n\nvoid LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb)\n{\n  char *b = sb->b;\n  MSize osz = (MSize)(sb->e - b);\n  if (osz > 2*LJ_MIN_SBUF) {\n    MSize n = (MSize)(sb->w - b);\n    b = lj_mem_realloc(L, b, osz, (osz >> 1));\n    sb->b = b;\n    sb->w = b + n;\n    sb->e = b + (osz >> 1);\n  }\n  lj_assertG_(G(sbufL(sb)), !sbufisext(sb), \"YAGNI shrink SBufExt\");\n}\n\nchar * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz)\n{\n  SBuf *sb = &G(L)->tmpbuf;\n  setsbufL(sb, L);\n  return lj_buf_need(sb, sz);\n}\n\n#if LJ_HASBUFFER && LJ_HASJIT\nvoid lj_bufx_set(SBufExt *sbx, const char *p, MSize len, GCobj *ref)\n{\n  lua_State *L = sbufL(sbx);\n  lj_bufx_free(L, sbx);\n  lj_bufx_set_cow(L, sbx, p, len);\n  setgcref(sbx->cowref, ref);\n  lj_gc_objbarrier(L, (GCudata *)sbx - 1, ref);\n}\n\n#if LJ_HASFFI\nMSize LJ_FASTCALL lj_bufx_more(SBufExt *sbx, MSize sz)\n{\n  lj_buf_more((SBuf *)sbx, sz);\n  return sbufleft(sbx);\n}\n#endif\n#endif\n\n/* -- Low-level buffer put operations ------------------------------------- */\n\nSBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len)\n{\n  char *w = lj_buf_more(sb, len);\n  w = lj_buf_wmem(w, q, len);\n  sb->w = w;\n  return sb;\n}\n\n#if LJ_HASJIT || LJ_HASFFI\nstatic LJ_NOINLINE SBuf * LJ_FASTCALL lj_buf_putchar2(SBuf *sb, int c)\n{\n  char *w = lj_buf_more2(sb, 1);\n  *w++ = (char)c;\n  sb->w = w;\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c)\n{\n  char *w = sb->w;\n  if (LJ_LIKELY(w < sb->e)) {\n    *w++ = (char)c;\n    sb->w = w;\n    return sb;\n  }\n  return lj_buf_putchar2(sb, c);\n}\n#endif\n\nSBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *w = lj_buf_more(sb, len);\n  w = lj_buf_wmem(w, strdata(s), len);\n  sb->w = w;\n  return sb;\n}\n\n/* -- High-level buffer put operations ------------------------------------ */\n\nSBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *w = lj_buf_more(sb, len), *e = w+len;\n  const char *q = strdata(s)+len-1;\n  while (w < e)\n    *w++ = *q--;\n  sb->w = w;\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *w = lj_buf_more(sb, len), *e = w+len;\n  const char *q = strdata(s);\n  for (; w < e; w++, q++) {\n    uint32_t c = *(unsigned char *)q;\n#if LJ_TARGET_PPC\n    *w = c + ((c >= 'A' && c <= 'Z') << 5);\n#else\n    if (c >= 'A' && c <= 'Z') c += 0x20;\n    *w = c;\n#endif\n  }\n  sb->w = w;\n  return sb;\n}\n\nSBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s)\n{\n  MSize len = s->len;\n  char *w = lj_buf_more(sb, len), *e = w+len;\n  const char *q = strdata(s);\n  for (; w < e; w++, q++) {\n    uint32_t c = *(unsigned char *)q;\n#if LJ_TARGET_PPC\n    *w = c - ((c >= 'a' && c <= 'z') << 5);\n#else\n    if (c >= 'a' && c <= 'z') c -= 0x20;\n    *w = c;\n#endif\n  }\n  sb->w = w;\n  return sb;\n}\n\nSBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep)\n{\n  MSize len = s->len;\n  if (rep > 0 && len) {\n    uint64_t tlen = (uint64_t)rep * len;\n    char *w;\n    if (LJ_UNLIKELY(tlen > LJ_MAX_STR))\n      lj_err_mem(sbufL(sb));\n    w = lj_buf_more(sb, (MSize)tlen);\n    if (len == 1) {  /* Optimize a common case. */\n      uint32_t c = strdata(s)[0];\n      do { *w++ = c; } while (--rep > 0);\n    } else {\n      const char *e = strdata(s) + len;\n      do {\n\tconst char *q = strdata(s);\n\tdo { *w++ = *q++; } while (q < e);\n      } while (--rep > 0);\n    }\n    sb->w = w;\n  }\n  return sb;\n}\n\nSBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e)\n{\n  MSize seplen = sep ? sep->len : 0;\n  if (i <= e) {\n    for (;;) {\n      cTValue *o = lj_tab_getint(t, i);\n      char *w;\n      if (!o) {\n      badtype:  /* Error: bad element type. */\n\tsb->w = (char *)(intptr_t)i;  /* Store failing index. */\n\treturn NULL;\n      } else if (tvisstr(o)) {\n\tMSize len = strV(o)->len;\n\tw = lj_buf_wmem(lj_buf_more(sb, len + seplen), strVdata(o), len);\n      } else if (tvisint(o)) {\n\tw = lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT+seplen), intV(o));\n      } else if (tvisnum(o)) {\n\tw = lj_buf_more(lj_strfmt_putfnum(sb, STRFMT_G14, numV(o)), seplen);\n      } else {\n\tgoto badtype;\n      }\n      if (i++ == e) {\n\tsb->w = w;\n\tbreak;\n      }\n      if (seplen) w = lj_buf_wmem(w, strdata(sep), seplen);\n      sb->w = w;\n    }\n  }\n  return sb;\n}\n\n/* -- Miscellaneous buffer operations ------------------------------------- */\n\nGCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb)\n{\n  return lj_str_new(sbufL(sb), sb->b, sbuflen(sb));\n}\n\n/* Concatenate two strings. */\nGCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2)\n{\n  MSize len1 = s1->len, len2 = s2->len;\n  char *buf = lj_buf_tmp(L, len1 + len2);\n  memcpy(buf, strdata(s1), len1);\n  memcpy(buf+len1, strdata(s2), len2);\n  return lj_str_new(L, buf, len1 + len2);\n}\n\n/* Read ULEB128 from buffer. */\nuint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp)\n{\n  const uint8_t *w = (const uint8_t *)*pp;\n  uint32_t v = *w++;\n  if (LJ_UNLIKELY(v >= 0x80)) {\n    int sh = 0;\n    v &= 0x7f;\n    do { v |= ((*w & 0x7f) << (sh += 7)); } while (*w++ >= 0x80);\n  }\n  *pp = (const char *)w;\n  return v;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_buf.h",
    "content": "/*\n** Buffer handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_BUF_H\n#define _LJ_BUF_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_str.h\"\n\n/* Resizable string buffers. */\n\n/* The SBuf struct definition is in lj_obj.h:\n**   char *w;\tWrite pointer.\n**   char *e;\tEnd pointer.\n**   char *b;\tBase pointer.\n**   MRef L;\tlua_State, used for buffer resizing. Extension bits in 3 LSB.\n*/\n\n/* Extended string buffer. */\ntypedef struct SBufExt {\n  SBufHeader;\n  union {\n    GCRef cowref;\t/* Copy-on-write object reference. */\n    MRef bsb;\t\t/* Borrowed string buffer. */\n  };\n  char *r;\t\t/* Read pointer. */\n  GCRef dict_str;\t/* Serialization string dictionary table. */\n  GCRef dict_mt;\t/* Serialization metatable dictionary table. */\n  int depth;\t\t/* Remaining recursion depth. */\n} SBufExt;\n\n#define sbufsz(sb)\t\t((MSize)((sb)->e - (sb)->b))\n#define sbuflen(sb)\t\t((MSize)((sb)->w - (sb)->b))\n#define sbufleft(sb)\t\t((MSize)((sb)->e - (sb)->w))\n#define sbufxlen(sbx)\t\t((MSize)((sbx)->w - (sbx)->r))\n#define sbufxslack(sbx)\t\t((MSize)((sbx)->r - (sbx)->b))\n\n#define SBUF_MASK_FLAG\t\t(7)\n#define SBUF_MASK_L\t\t(~(GCSize)SBUF_MASK_FLAG)\n#define SBUF_FLAG_EXT\t\t1\t/* Extended string buffer. */\n#define SBUF_FLAG_COW\t\t2\t/* Copy-on-write buffer. */\n#define SBUF_FLAG_BORROW\t4\t/* Borrowed string buffer. */\n\n#define sbufL(sb) \\\n  ((lua_State *)(void *)(uintptr_t)(mrefu((sb)->L) & SBUF_MASK_L))\n#define setsbufL(sb, l)\t\t(setmref((sb)->L, (l)))\n#define setsbufXL(sb, l, flag) \\\n  (setmrefu((sb)->L, (GCSize)(uintptr_t)(void *)(l) + (flag)))\n#define setsbufXL_(sb, l) \\\n  (setmrefu((sb)->L, (GCSize)(uintptr_t)(void *)(l) | (mrefu((sb)->L) & SBUF_MASK_FLAG)))\n\n#define sbufflag(sb)\t\t(mrefu((sb)->L))\n#define sbufisext(sb)\t\t(sbufflag((sb)) & SBUF_FLAG_EXT)\n#define sbufiscow(sb)\t\t(sbufflag((sb)) & SBUF_FLAG_COW)\n#define sbufisborrow(sb)\t(sbufflag((sb)) & SBUF_FLAG_BORROW)\n#define sbufiscoworborrow(sb)\t(sbufflag((sb)) & (SBUF_FLAG_COW|SBUF_FLAG_BORROW))\n#define sbufX(sb) \\\n  (lj_assertG_(G(sbufL(sb)), sbufisext(sb), \"not an SBufExt\"), (SBufExt *)(sb))\n#define setsbufflag(sb, flag)\t(setmrefu((sb)->L, (flag)))\n\n#define tvisbuf(o) \\\n  (LJ_HASBUFFER && tvisudata(o) && udataV(o)->udtype == UDTYPE_BUFFER)\n#define bufV(o)\t\tcheck_exp(tvisbuf(o), ((SBufExt *)uddata(udataV(o))))\n\n/* Buffer management */\nLJ_FUNC char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz);\nLJ_FUNC char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz);\nLJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb);\nLJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz);\n\nstatic LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb)\n{\n  setsbufL(sb, L);\n  sb->w = sb->e = sb->b = NULL;\n}\n\nstatic LJ_AINLINE void lj_buf_reset(SBuf *sb)\n{\n  sb->w = sb->b;\n}\n\nstatic LJ_AINLINE SBuf *lj_buf_tmp_(lua_State *L)\n{\n  SBuf *sb = &G(L)->tmpbuf;\n  setsbufL(sb, L);\n  lj_buf_reset(sb);\n  return sb;\n}\n\nstatic LJ_AINLINE void lj_buf_free(global_State *g, SBuf *sb)\n{\n  lj_assertG(!sbufisext(sb), \"bad free of SBufExt\");\n  lj_mem_free(g, sb->b, sbufsz(sb));\n}\n\nstatic LJ_AINLINE char *lj_buf_need(SBuf *sb, MSize sz)\n{\n  if (LJ_UNLIKELY(sz > sbufsz(sb)))\n    return lj_buf_need2(sb, sz);\n  return sb->b;\n}\n\nstatic LJ_AINLINE char *lj_buf_more(SBuf *sb, MSize sz)\n{\n  if (LJ_UNLIKELY(sz > sbufleft(sb)))\n    return lj_buf_more2(sb, sz);\n  return sb->w;\n}\n\n/* Extended buffer management */\nstatic LJ_AINLINE void lj_bufx_init(lua_State *L, SBufExt *sbx)\n{\n  memset(sbx, 0, sizeof(SBufExt));\n  setsbufXL(sbx, L, SBUF_FLAG_EXT);\n}\n\nstatic LJ_AINLINE void lj_bufx_set_borrow(lua_State *L, SBufExt *sbx, SBuf *sb)\n{\n  setsbufXL(sbx, L, SBUF_FLAG_EXT | SBUF_FLAG_BORROW);\n  setmref(sbx->bsb, sb);\n  sbx->r = sbx->w = sbx->b = sb->b;\n  sbx->e = sb->e;\n}\n\nstatic LJ_AINLINE void lj_bufx_set_cow(lua_State *L, SBufExt *sbx,\n\t\t\t\t       const char *p, MSize len)\n{\n  setsbufXL(sbx, L, SBUF_FLAG_EXT | SBUF_FLAG_COW);\n  sbx->r = sbx->b = (char *)p;\n  sbx->w = sbx->e = (char *)p + len;\n}\n\nstatic LJ_AINLINE void lj_bufx_reset(SBufExt *sbx)\n{\n  if (sbufiscow(sbx)) {\n    setmrefu(sbx->L, (mrefu(sbx->L) & ~(GCSize)SBUF_FLAG_COW));\n    setgcrefnull(sbx->cowref);\n    sbx->b = sbx->e = NULL;\n  }\n  sbx->r = sbx->w = sbx->b;\n}\n\nstatic LJ_AINLINE void lj_bufx_free(lua_State *L, SBufExt *sbx)\n{\n  if (!sbufiscoworborrow(sbx)) lj_mem_free(G(L), sbx->b, sbufsz(sbx));\n  setsbufXL(sbx, L, SBUF_FLAG_EXT);\n  setgcrefnull(sbx->cowref);\n  sbx->r = sbx->w = sbx->b = sbx->e = NULL;\n}\n\n#if LJ_HASBUFFER && LJ_HASJIT\nLJ_FUNC void lj_bufx_set(SBufExt *sbx, const char *p, MSize len, GCobj *o);\n#if LJ_HASFFI\nLJ_FUNC MSize LJ_FASTCALL lj_bufx_more(SBufExt *sbx, MSize sz);\n#endif\n#endif\n\n/* Low-level buffer put operations */\nLJ_FUNC SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len);\n#if LJ_HASJIT || LJ_HASFFI\nLJ_FUNC SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c);\n#endif\nLJ_FUNC SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s);\n\nstatic LJ_AINLINE char *lj_buf_wmem(char *p, const void *q, MSize len)\n{\n  return (char *)memcpy(p, q, len) + len;\n}\n\nstatic LJ_AINLINE void lj_buf_putb(SBuf *sb, int c)\n{\n  char *w = lj_buf_more(sb, 1);\n  *w++ = (char)c;\n  sb->w = w;\n}\n\n/* High-level buffer put operations */\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s);\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s);\nLJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s);\nLJ_FUNC SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep);\nLJ_FUNC SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep,\n\t\t\t    int32_t i, int32_t e);\n\n/* Miscellaneous buffer operations */\nLJ_FUNCA GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb);\nLJ_FUNC GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2);\nLJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp);\n\nstatic LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb)\n{\n  return lj_str_new(L, sb->b, sbuflen(sb));\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_carith.c",
    "content": "/*\n** C data arithmetic.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_ir.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_carith.h\"\n#include \"lj_strscan.h\"\n\n/* -- C data arithmetic --------------------------------------------------- */\n\n/* Binary operands of an operator converted to ctypes. */\ntypedef struct CDArith {\n  uint8_t *p[2];\n  CType *ct[2];\n} CDArith;\n\n/* Check arguments for arithmetic metamethods. */\nstatic int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca)\n{\n  TValue *o = L->base;\n  int ok = 1;\n  MSize i;\n  if (o+1 >= L->top)\n    lj_err_argt(L, 1, LUA_TCDATA);\n  for (i = 0; i < 2; i++, o++) {\n    if (tviscdata(o)) {\n      GCcdata *cd = cdataV(o);\n      CTypeID id = (CTypeID)cd->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      uint8_t *p = (uint8_t *)cdataptr(cd);\n      if (ctype_isptr(ct->info)) {\n\tp = (uint8_t *)cdata_getptr(p, ct->size);\n\tif (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);\n      } else if (ctype_isfunc(ct->info)) {\n\tp = (uint8_t *)*(void **)p;\n\tct = ctype_get(cts,\n\t  lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));\n      }\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      ca->ct[i] = ct;\n      ca->p[i] = p;\n    } else if (tvisint(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_INT32);\n      ca->p[i] = (uint8_t *)&o->i;\n    } else if (tvisnum(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_DOUBLE);\n      ca->p[i] = (uint8_t *)&o->n;\n    } else if (tvisnil(o)) {\n      ca->ct[i] = ctype_get(cts, CTID_P_VOID);\n      ca->p[i] = (uint8_t *)0;\n    } else if (tvisstr(o)) {\n      TValue *o2 = i == 0 ? o+1 : o-1;\n      CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid);\n      ca->ct[i] = NULL;\n      ca->p[i] = (uint8_t *)strVdata(o);\n      ok = 0;\n      if (ctype_isenum(ct->info)) {\n\tCTSize ofs;\n\tCType *cct = lj_ctype_getfield(cts, ct, strV(o), &ofs);\n\tif (cct && ctype_isconstval(cct->info)) {\n\t  ca->ct[i] = ctype_child(cts, cct);\n\t  ca->p[i] = (uint8_t *)&cct->size;  /* Assumes ct does not grow. */\n\t  ok = 1;\n\t} else {\n\t  ca->ct[1-i] = ct;  /* Use enum to improve error message. */\n\t  ca->p[1-i] = NULL;\n\t  break;\n\t}\n      }\n    } else {\n      ca->ct[i] = NULL;\n      ca->p[i] = (void *)(intptr_t)1;  /* To make it unequal. */\n      ok = 0;\n    }\n  }\n  return ok;\n}\n\n/* Pointer arithmetic. */\nstatic int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  CType *ctp = ca->ct[0];\n  uint8_t *pp = ca->p[0];\n  ptrdiff_t idx;\n  CTSize sz;\n  CTypeID id;\n  GCcdata *cd;\n  if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {\n    if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&\n\t(ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {\n      uint8_t *pp2 = ca->p[1];\n      if (mm == MM_eq) {  /* Pointer equality. Incompatible pointers are ok. */\n\tsetboolV(L->top-1, (pp == pp2));\n\treturn 1;\n      }\n      if (!lj_cconv_compatptr(cts, ctp, ca->ct[1], CCF_IGNQUAL))\n\treturn 0;\n      if (mm == MM_sub) {  /* Pointer difference. */\n\tintptr_t diff;\n\tsz = lj_ctype_size(cts, ctype_cid(ctp->info));  /* Element size. */\n\tif (sz == 0 || sz == CTSIZE_INVALID)\n\t  return 0;\n\tdiff = ((intptr_t)pp - (intptr_t)pp2) / (int32_t)sz;\n\t/* All valid pointer differences on x64 are in (-2^47, +2^47),\n\t** which fits into a double without loss of precision.\n\t*/\n\tsetintptrV(L->top-1, (int32_t)diff);\n\treturn 1;\n      } else if (mm == MM_lt) {  /* Pointer comparison (unsigned). */\n\tsetboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2));\n\treturn 1;\n      } else {\n\tlj_assertL(mm == MM_le, \"bad metamethod %d\", mm);\n\tsetboolV(L->top-1, ((uintptr_t)pp <= (uintptr_t)pp2));\n\treturn 1;\n      }\n    }\n    if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(ca->ct[1]->info)))\n      return 0;\n    lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[1],\n\t\t   (uint8_t *)&idx, ca->p[1], 0);\n    if (mm == MM_sub) idx = -idx;\n  } else if (mm == MM_add && ctype_isnum(ctp->info) &&\n      (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {\n    /* Swap pointer and index. */\n    ctp = ca->ct[1]; pp = ca->p[1];\n    lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[0],\n\t\t   (uint8_t *)&idx, ca->p[0], 0);\n  } else {\n    return 0;\n  }\n  sz = lj_ctype_size(cts, ctype_cid(ctp->info));  /* Element size. */\n  if (sz == CTSIZE_INVALID)\n    return 0;\n  pp += idx*(int32_t)sz;  /* Compute pointer + index. */\n  id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),\n\t\t       CTSIZE_PTR);\n  cd = lj_cdata_new(cts, id, CTSIZE_PTR);\n  *(uint8_t **)cdataptr(cd) = pp;\n  setcdataV(L, L->top-1, cd);\n  lj_gc_check(L);\n  return 1;\n}\n\n/* 64 bit integer arithmetic. */\nstatic int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  if (ctype_isnum(ca->ct[0]->info) && ca->ct[0]->size <= 8 &&\n      ctype_isnum(ca->ct[1]->info) && ca->ct[1]->size <= 8) {\n    CTypeID id = (((ca->ct[0]->info & CTF_UNSIGNED) && ca->ct[0]->size == 8) ||\n\t\t  ((ca->ct[1]->info & CTF_UNSIGNED) && ca->ct[1]->size == 8)) ?\n\t\t CTID_UINT64 : CTID_INT64;\n    CType *ct = ctype_get(cts, id);\n    GCcdata *cd;\n    uint64_t u0, u1, *up;\n    lj_cconv_ct_ct(cts, ct, ca->ct[0], (uint8_t *)&u0, ca->p[0], 0);\n    if (mm != MM_unm)\n      lj_cconv_ct_ct(cts, ct, ca->ct[1], (uint8_t *)&u1, ca->p[1], 0);\n    switch (mm) {\n    case MM_eq:\n      setboolV(L->top-1, (u0 == u1));\n      return 1;\n    case MM_lt:\n      setboolV(L->top-1,\n\t       id == CTID_INT64 ? ((int64_t)u0 < (int64_t)u1) : (u0 < u1));\n      return 1;\n    case MM_le:\n      setboolV(L->top-1,\n\t       id == CTID_INT64 ? ((int64_t)u0 <= (int64_t)u1) : (u0 <= u1));\n      return 1;\n    default: break;\n    }\n    cd = lj_cdata_new(cts, id, 8);\n    up = (uint64_t *)cdataptr(cd);\n    setcdataV(L, L->top-1, cd);\n    switch (mm) {\n    case MM_add: *up = u0 + u1; break;\n    case MM_sub: *up = u0 - u1; break;\n    case MM_mul: *up = u0 * u1; break;\n    case MM_div:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_divi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_divu64(u0, u1);\n      break;\n    case MM_mod:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_modi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_modu64(u0, u1);\n      break;\n    case MM_pow:\n      if (id == CTID_INT64)\n\t*up = (uint64_t)lj_carith_powi64((int64_t)u0, (int64_t)u1);\n      else\n\t*up = lj_carith_powu64(u0, u1);\n      break;\n    case MM_unm: *up = (uint64_t)-(int64_t)u0; break;\n    default:\n      lj_assertL(0, \"bad metamethod %d\", mm);\n      break;\n    }\n    lj_gc_check(L);\n    return 1;\n  }\n  return 0;\n}\n\n/* Handle ctype arithmetic metamethods. */\nstatic int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm)\n{\n  cTValue *tv = NULL;\n  if (tviscdata(L->base)) {\n    CTypeID id = cdataV(L->base)->ctypeid;\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n    tv = lj_ctype_meta(cts, id, mm);\n  }\n  if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) {\n    CTypeID id = cdataV(L->base+1)->ctypeid;\n    CType *ct = ctype_raw(cts, id);\n    if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n    tv = lj_ctype_meta(cts, id, mm);\n  }\n  if (!tv) {\n    const char *repr[2];\n    int i, isenum = -1, isstr = -1;\n    if (mm == MM_eq) {  /* Equality checks never raise an error. */\n      int eq = ca->p[0] == ca->p[1];\n      setboolV(L->top-1, eq);\n      setboolV(&G(L)->tmptv2, eq);  /* Remember for trace recorder. */\n      return 1;\n    }\n    for (i = 0; i < 2; i++) {\n      if (ca->ct[i] && tviscdata(L->base+i)) {\n\tif (ctype_isenum(ca->ct[i]->info)) isenum = i;\n\trepr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL));\n      } else {\n\tif (tvisstr(&L->base[i])) isstr = i;\n\trepr[i] = lj_typename(&L->base[i]);\n      }\n    }\n    if ((isenum ^ isstr) == 1)\n      lj_err_callerv(L, LJ_ERR_FFI_BADCONV, repr[isstr], repr[isenum]);\n    lj_err_callerv(L, mm == MM_len ? LJ_ERR_FFI_BADLEN :\n\t\t      mm == MM_concat ? LJ_ERR_FFI_BADCONCAT :\n\t\t      mm < MM_add ? LJ_ERR_FFI_BADCOMP : LJ_ERR_FFI_BADARITH,\n\t\t   repr[0], repr[1]);\n  }\n  return lj_meta_tailcall(L, tv);\n}\n\n/* Arithmetic operators for cdata. */\nint lj_carith_op(lua_State *L, MMS mm)\n{\n  CTState *cts = ctype_cts(L);\n  CDArith ca;\n  if (carith_checkarg(L, cts, &ca) && mm != MM_len && mm != MM_concat) {\n    if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) {\n      copyTV(L, &G(L)->tmptv2, L->top-1);  /* Remember for trace recorder. */\n      return 1;\n    }\n  }\n  return lj_carith_meta(L, cts, &ca, mm);\n}\n\n/* -- 64 bit bit operations helpers --------------------------------------- */\n\n#if LJ_64\n#define B64DEF(name) \\\n  static LJ_AINLINE uint64_t lj_carith_##name(uint64_t x, int32_t sh)\n#else\n/* Not inlined on 32 bit archs, since some of these are quite lengthy. */\n#define B64DEF(name) \\\n  uint64_t LJ_NOINLINE lj_carith_##name(uint64_t x, int32_t sh)\n#endif\n\nB64DEF(shl64) { return x << (sh&63); }\nB64DEF(shr64) { return x >> (sh&63); }\nB64DEF(sar64) { return (uint64_t)((int64_t)x >> (sh&63)); }\nB64DEF(rol64) { return lj_rol(x, (sh&63)); }\nB64DEF(ror64) { return lj_ror(x, (sh&63)); }\n\n#undef B64DEF\n\nuint64_t lj_carith_shift64(uint64_t x, int32_t sh, int op)\n{\n  switch (op) {\n  case IR_BSHL-IR_BSHL: x = lj_carith_shl64(x, sh); break;\n  case IR_BSHR-IR_BSHL: x = lj_carith_shr64(x, sh); break;\n  case IR_BSAR-IR_BSHL: x = lj_carith_sar64(x, sh); break;\n  case IR_BROL-IR_BSHL: x = lj_carith_rol64(x, sh); break;\n  case IR_BROR-IR_BSHL: x = lj_carith_ror64(x, sh); break;\n  default:\n    lj_assertX(0, \"bad shift op %d\", op);\n    break;\n  }\n  return x;\n}\n\n/* Equivalent to lj_lib_checkbit(), but handles cdata. */\nuint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id)\n{\n  TValue *o = L->base + narg-1;\n  if (o >= L->top) {\n  err:\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  } else if (LJ_LIKELY(tvisnumber(o))) {\n    /* Handled below. */\n  } else if (tviscdata(o)) {\n    CTState *cts = ctype_cts(L);\n    uint8_t *sp = (uint8_t *)cdataptr(cdataV(o));\n    CTypeID sid = cdataV(o)->ctypeid;\n    CType *s = ctype_get(cts, sid);\n    uint64_t x;\n    if (ctype_isref(s->info)) {\n      sp = *(void **)sp;\n      sid = ctype_cid(s->info);\n    }\n    s = ctype_raw(cts, sid);\n    if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n    if ((s->info & (CTMASK_NUM|CTF_BOOL|CTF_FP|CTF_UNSIGNED)) ==\n\tCTINFO(CT_NUM, CTF_UNSIGNED) && s->size == 8)\n      *id = CTID_UINT64;  /* Use uint64_t, since it has the highest rank. */\n    else if (!*id)\n      *id = CTID_INT64;  /* Use int64_t, unless already set. */\n    lj_cconv_ct_ct(cts, ctype_get(cts, *id), s,\n\t\t   (uint8_t *)&x, sp, CCF_ARG(narg));\n    return x;\n  } else if (!(tvisstr(o) && lj_strscan_number(strV(o), o))) {\n    goto err;\n  }\n  if (LJ_LIKELY(tvisint(o))) {\n    return (uint32_t)intV(o);\n  } else {\n    int32_t i = lj_num2bit(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return (uint32_t)i;\n  }\n}\n\n/* -- 64 bit integer arithmetic helpers ----------------------------------- */\n\n#if LJ_32 && LJ_HASJIT\n/* Signed/unsigned 64 bit multiplication. */\nint64_t lj_carith_mul64(int64_t a, int64_t b)\n{\n  return a * b;\n}\n#endif\n\n/* Unsigned 64 bit division. */\nuint64_t lj_carith_divu64(uint64_t a, uint64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  return a / b;\n}\n\n/* Signed 64 bit division. */\nint64_t lj_carith_divi64(int64_t a, int64_t b)\n{\n  if (b == 0 || (a == (int64_t)U64x(80000000,00000000) && b == -1))\n    return U64x(80000000,00000000);\n  return a / b;\n}\n\n/* Unsigned 64 bit modulo. */\nuint64_t lj_carith_modu64(uint64_t a, uint64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  return a % b;\n}\n\n/* Signed 64 bit modulo. */\nint64_t lj_carith_modi64(int64_t a, int64_t b)\n{\n  if (b == 0) return U64x(80000000,00000000);\n  if (a == (int64_t)U64x(80000000,00000000) && b == -1) return 0;\n  return a % b;\n}\n\n/* Unsigned 64 bit x^k. */\nuint64_t lj_carith_powu64(uint64_t x, uint64_t k)\n{\n  uint64_t y;\n  if (k == 0)\n    return 1;\n  for (; (k & 1) == 0; k >>= 1) x *= x;\n  y = x;\n  if ((k >>= 1) != 0) {\n    for (;;) {\n      x *= x;\n      if (k == 1) break;\n      if (k & 1) y *= x;\n      k >>= 1;\n    }\n    y *= x;\n  }\n  return y;\n}\n\n/* Signed 64 bit x^k. */\nint64_t lj_carith_powi64(int64_t x, int64_t k)\n{\n  if (k == 0)\n    return 1;\n  if (k < 0) {\n    if (x == 0)\n      return U64x(7fffffff,ffffffff);\n    else if (x == 1)\n      return 1;\n    else if (x == -1)\n      return (k & 1) ? -1 : 1;\n    else\n      return 0;\n  }\n  return (int64_t)lj_carith_powu64((uint64_t)x, (uint64_t)k);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_carith.h",
    "content": "/*\n** C data arithmetic.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CARITH_H\n#define _LJ_CARITH_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\nLJ_FUNC int lj_carith_op(lua_State *L, MMS mm);\n\n#if LJ_32\nLJ_FUNC uint64_t lj_carith_shl64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_shr64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_sar64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_rol64(uint64_t x, int32_t sh);\nLJ_FUNC uint64_t lj_carith_ror64(uint64_t x, int32_t sh);\n#endif\nLJ_FUNC uint64_t lj_carith_shift64(uint64_t x, int32_t sh, int op);\nLJ_FUNC uint64_t lj_carith_check64(lua_State *L, int narg, CTypeID *id);\n\n#if LJ_32 && LJ_HASJIT\nLJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);\n#endif\nLJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);\nLJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);\nLJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);\nLJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);\nLJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);\nLJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ccall.c",
    "content": "/*\n** FFI C call handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_ccall.h\"\n#include \"lj_trace.h\"\n\n/* Target-specific handling of register arguments. */\n#if LJ_TARGET_X86\n/* -- x86 calling conventions --------------------------------------------- */\n\n#if LJ_ABI_WIN\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs bigger than 8 by reference (on stack only). */ \\\n  cc->retref = (sz > 8); \\\n  if (cc->retref) cc->stack[nsp++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET\n\n#else\n\n#if LJ_TARGET_OSX\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size 1, 2, 4 or 8 in registers. */ \\\n  cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \\\n  if (cc->retref) { \\\n    if (ngpr < maxgpr) \\\n      cc->gpr[ngpr++] = (GPRArg)dp; \\\n    else \\\n      cc->stack[nsp++] = (GPRArg)dp; \\\n  } else {  /* Struct with single FP field ends up in FPR. */ \\\n    cc->resx87 = ccall_classify_struct(cts, ctr); \\\n  }\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \\\n  memcpy(dp, sp, ctr->size);\n\n#else\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference (in reg or on stack). */ \\\n  if (ngpr < maxgpr) \\\n    cc->gpr[ngpr++] = (GPRArg)dp; \\\n  else \\\n    cc->stack[nsp++] = (GPRArg)dp;\n\n#endif\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Return complex float in GPRs and complex double by reference. */ \\\n  cc->retref = (sz > 8); \\\n  if (cc->retref) { \\\n    if (ngpr < maxgpr) \\\n      cc->gpr[ngpr++] = (GPRArg)dp; \\\n    else \\\n      cc->stack[nsp++] = (GPRArg)dp; \\\n  }\n\n#endif\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!cc->retref) \\\n    *(int64_t *)dp = *(int64_t *)sp;  /* Copy complex float from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  ngpr = maxgpr;  /* Pass all structs by value on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 1;  /* Pass complex by value on stack. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (!isfp) {  /* Only non-FP values may be passed in registers. */ \\\n    if (n > 1) {  /* Anything > 32 bit is passed on the stack. */ \\\n      if (!LJ_ABI_WIN) ngpr = maxgpr;  /* Prevent reordering. */ \\\n    } else if (ngpr + 1 <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_X64 && LJ_ABI_WIN\n/* -- Windows/x64 calling conventions ------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \\\n  cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!cc->retref) \\\n    *(int64_t *)dp = *(int64_t *)sp;  /* Copy complex float from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \\\n  if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR;  /* Pass all other structs by reference. */ \\\n  }\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex float in a GPR and complex double by reference. */ \\\n  if (sz != 2*sizeof(float)) { \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR; \\\n  }\n\n/* Windows/x64 argument registers are strictly positional (use ngpr). */\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \\\n  } else { \\\n    if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \\\n  }\n\n#elif LJ_TARGET_X64\n/* -- POSIX/x64 calling conventions --------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  if (ccall_classify_struct(cts, ctr, rcl, 0)) { \\\n    cc->retref = 1;  /* Return struct by reference. */ \\\n    cc->gpr[ngpr++] = (GPRArg)dp; \\\n  } else { \\\n    cc->retref = 0;  /* Return small structs in registers. */ \\\n  }\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  ccall_classify_struct(cts, ctr, rcl, 0); \\\n  ccall_struct_ret(cc, rcl, dp, ctr->size);\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in one or two FPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPR. */ \\\n    *(int64_t *)dp = cc->fpr[0].l[0]; \\\n  } else {  /* Copy non-contiguous complex double from FPRs. */ \\\n    ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \\\n    ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \\\n  }\n\n#define CCALL_HANDLE_STRUCTARG \\\n  int rcl[2]; rcl[0] = rcl[1] = 0; \\\n  if (!ccall_classify_struct(cts, d, rcl, 0)) { \\\n    cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \\\n    if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \\\n    nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \\\n    continue; \\\n  }  /* Pass all other structs by value on stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 2;  /* Pass complex in FPRs or on stack. Needs postprocessing. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    int n2 = ctype_isvector(d->info) ? 1 : n; \\\n    if (nfpr + n2 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += n2; \\\n      goto done; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    /* Note that reordering is explicitly allowed in the x64 ABI. */ \\\n    if (n <= 2 && ngpr + n <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_ARM\n/* -- ARM calling conventions --------------------------------------------- */\n\n#if LJ_ABI_SOFTFP\n\n#define CCALL_HANDLE_STRUCTRET \\\n  /* Return structs of size <= 4 in a GPR. */ \\\n  cc->retref = !(sz <= 4); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  cc->retref = 1;  /* Return all complex values by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  UNUSED(dp); /* Nothing to do. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_REGARG_FP1\n#define CCALL_HANDLE_REGARG_FP2\n\n#else\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = !ccall_classify_struct(cts, ctr, ct); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \\\n  memcpy(dp, sp, ctr->size);\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  if (!(ct->info & CTF_VARARG)) cc->retref = 0;  /* Return complex in FPRs. */\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size);\n\n#define CCALL_HANDLE_STRUCTARG \\\n  isfp = (ccall_classify_struct(cts, d, ct) > 1);\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  isfp = 1;  /* Pass complex by value in FPRs or on stack. */\n\n#define CCALL_HANDLE_REGARG_FP1 \\\n  if (isfp && !(ct->info & CTF_VARARG)) { \\\n    if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \\\n      if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \\\n\tdp = &cc->fpr[nfpr]; \\\n\tnfpr += (n >> 1); \\\n\tgoto done; \\\n      } \\\n    } else { \\\n      if (sz > 1 && fprodd != nfpr) fprodd = 0; \\\n      if (fprodd) { \\\n\tif (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \\\n\t  dp = (void *)&cc->fpr[fprodd-1].f[1]; \\\n\t  nfpr += (n >> 1); \\\n\t  if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \\\n\t  goto done; \\\n\t} \\\n      } else { \\\n\tif (2*nfpr+n <= 2*CCALL_NARG_FPR) { \\\n\t  dp = (void *)&cc->fpr[nfpr]; \\\n\t  nfpr += (n >> 1); \\\n\t  if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \\\n\t  goto done; \\\n\t} \\\n      } \\\n    } \\\n    fprodd = 0;  /* No reordering after the first FP value is on stack. */ \\\n  } else {\n\n#define CCALL_HANDLE_REGARG_FP2\t}\n\n#endif\n\n#define CCALL_HANDLE_REGARG \\\n  CCALL_HANDLE_REGARG_FP1 \\\n  if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \\\n    if (ngpr < maxgpr) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  } \\\n  if (ngpr < maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    if (ngpr + n > maxgpr) { \\\n      nsp += ngpr + n - maxgpr;  /* Assumes contiguous gpr/stack fields. */ \\\n      if (nsp > CCALL_MAXSTACK) goto err_nyi;  /* Too many arguments. */ \\\n      ngpr = maxgpr; \\\n    } else { \\\n      ngpr += n; \\\n    } \\\n    goto done; \\\n  } CCALL_HANDLE_REGARG_FP2\n\n#define CCALL_HANDLE_RET \\\n  if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0];\n\n#elif LJ_TARGET_ARM64\n/* -- ARM64 calling conventions ------------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = !ccall_classify_struct(cts, ctr); \\\n  if (cc->retref) cc->retp = dp;\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  unsigned int cl = ccall_classify_struct(cts, ctr); \\\n  if ((cl & 4)) { /* Combine float HFA from separate registers. */ \\\n    CTSize i = (cl >> 8) - 1; \\\n    do { ((uint32_t *)dp)[i] = cc->fpr[i].lo; } while (i--); \\\n  } else { \\\n    if (cl > 1) sp = (uint8_t *)&cc->fpr[0]; \\\n    memcpy(dp, sp, ctr->size); \\\n  }\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in one or two FPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPRs. */ \\\n    ((float *)dp)[0] = cc->fpr[0].f; \\\n    ((float *)dp)[1] = cc->fpr[1].f; \\\n  } else {  /* Copy complex double from FPRs. */ \\\n    ((double *)dp)[0] = cc->fpr[0].d; \\\n    ((double *)dp)[1] = cc->fpr[1].d; \\\n  }\n\n#define CCALL_HANDLE_STRUCTARG \\\n  unsigned int cl = ccall_classify_struct(cts, d); \\\n  if (cl == 0) {  /* Pass struct by reference. */ \\\n    rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n    sz = CTSIZE_PTR; \\\n  } else if (cl > 1) {  /* Pass struct in FPRs or on stack. */ \\\n    isfp = (cl & 4) ? 2 : 1; \\\n  }  /* else: Pass struct in GPRs or on stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in separate (!) FPRs or on stack. */ \\\n  isfp = sz == 2*sizeof(float) ? 2 : 1;\n\n#define CCALL_HANDLE_REGARG \\\n  if (LJ_TARGET_OSX && isva) { \\\n    /* IOS: All variadic arguments are on the stack. */ \\\n  } else if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    int n2 = ctype_isvector(d->info) ? 1 : \\\n\t     isfp == 1 ? n : (d->size >> (4-isfp)); \\\n    if (nfpr + n2 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += n2; \\\n      goto done; \\\n    } else { \\\n      nfpr = CCALL_NARG_FPR;  /* Prevent reordering. */ \\\n      if (LJ_TARGET_OSX && d->size < 8) goto err_nyi; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    if (!LJ_TARGET_OSX && (d->info & CTF_ALIGN) > CTALIGN_PTR) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n    if (ngpr + n <= maxgpr) { \\\n      dp = &cc->gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } else { \\\n      ngpr = maxgpr;  /* Prevent reordering. */ \\\n      if (LJ_TARGET_OSX && d->size < 8) goto err_nyi; \\\n    } \\\n  }\n\n#if LJ_BE\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    sp = (uint8_t *)&cc->fpr[0].f;\n#endif\n\n\n#elif LJ_TARGET_PPC\n/* -- PPC calling conventions --------------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in 2 or 4 GPRs. */ \\\n  cc->retref = 0;\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  memcpy(dp, sp, ctr->size);  /* Copy complex from GPRs. */\n\n#define CCALL_HANDLE_STRUCTARG \\\n  rp = cdataptr(lj_cdata_new(cts, did, sz)); \\\n  sz = CTSIZE_PTR;  /* Pass all structs by reference. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_GPR \\\n  /* Try to pass argument in GPRs. */ \\\n  if (n > 1) { \\\n    /* int64_t or complex (float). */ \\\n    lj_assertL(n == 2 || n == 4, \"bad GPR size %d\", n); \\\n    if (ctype_isinteger(d->info) || ctype_isfp(d->info)) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align int64_t to regpair. */ \\\n    else if (ngpr + n > maxgpr) \\\n      ngpr = maxgpr;  /* Prevent reordering. */ \\\n  } \\\n  if (ngpr + n <= maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  } \\\n\n#if LJ_ABI_SOFTFP\n#define CCALL_HANDLE_REGARG  CCALL_HANDLE_GPR\n#else\n#define CCALL_HANDLE_REGARG \\\n  if (isfp) {  /* Try to pass argument in FPRs. */ \\\n    if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n      dp = &cc->fpr[nfpr]; \\\n      nfpr += 1; \\\n      d = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */ \\\n      goto done; \\\n    } \\\n  } else { \\\n    CCALL_HANDLE_GPR \\\n  }\n#endif\n\n#if !LJ_ABI_SOFTFP\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    ctr = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */\n#endif\n\n#elif LJ_TARGET_MIPS32\n/* -- MIPS o32 calling conventions ---------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = 1;  /* Return all structs by reference. */ \\\n  cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in 1 or 2 FPRs. */ \\\n  cc->retref = 0;\n\n#if LJ_ABI_SOFTFP\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n    ((intptr_t *)dp)[1] = cc->gpr[1]; \\\n  } else {  /* Copy complex double from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n    ((intptr_t *)dp)[1] = cc->gpr[1]; \\\n    ((intptr_t *)dp)[2] = cc->gpr[2]; \\\n    ((intptr_t *)dp)[3] = cc->gpr[3]; \\\n  }\n#else\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPRs. */ \\\n    ((float *)dp)[0] = cc->fpr[0].f; \\\n    ((float *)dp)[1] = cc->fpr[1].f; \\\n  } else {  /* Copy complex double from FPRs. */ \\\n    ((double *)dp)[0] = cc->fpr[0].d; \\\n    ((double *)dp)[1] = cc->fpr[1].d; \\\n  }\n#endif\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n#define CCALL_HANDLE_GPR \\\n  if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \\\n    ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr < maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    if (ngpr + n > maxgpr) { \\\n     nsp += ngpr + n - maxgpr;  /* Assumes contiguous gpr/stack fields. */ \\\n     if (nsp > CCALL_MAXSTACK) goto err_nyi;  /* Too many arguments. */ \\\n     ngpr = maxgpr; \\\n    } else { \\\n     ngpr += n; \\\n    } \\\n    goto done; \\\n  }\n\n#if !LJ_ABI_SOFTFP\t/* MIPS32 hard-float */\n#define CCALL_HANDLE_REGARG \\\n  if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \\\n    /* Try to pass argument in FPRs. */ \\\n    dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \\\n    nfpr++; ngpr += n; \\\n    goto done; \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    nfpr = CCALL_NARG_FPR; \\\n    CCALL_HANDLE_GPR \\\n  }\n#else\t\t\t/* MIPS32 soft-float */\n#define CCALL_HANDLE_REGARG CCALL_HANDLE_GPR\n#endif\n\n#if !LJ_ABI_SOFTFP\n/* On MIPS64 soft-float, position of float return values is endian-dependant. */\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    sp = (uint8_t *)&cc->fpr[0].f;\n#endif\n\n#elif LJ_TARGET_MIPS64\n/* -- MIPS n64 calling conventions ---------------------------------------- */\n\n#define CCALL_HANDLE_STRUCTRET \\\n  cc->retref = !(sz <= 16); \\\n  if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;\n\n#define CCALL_HANDLE_STRUCTRET2 \\\n  ccall_copy_struct(cc, ctr, dp, sp, ccall_classify_struct(cts, ctr, ct));\n\n#define CCALL_HANDLE_COMPLEXRET \\\n  /* Complex values are returned in 1 or 2 FPRs. */ \\\n  cc->retref = 0;\n\n#if LJ_ABI_SOFTFP\t/* MIPS64 soft-float */\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n  } else {  /* Copy complex double from GPRs. */ \\\n    ((intptr_t *)dp)[0] = cc->gpr[0]; \\\n    ((intptr_t *)dp)[1] = cc->gpr[1]; \\\n  }\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  /* Pass complex by value in 2 or 4 GPRs. */\n\n/* Position of soft-float 'float' return value depends on endianess.  */\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    sp = (uint8_t *)cc->gpr + LJ_ENDIAN_SELECT(0, 4);\n\n#else\t\t\t/* MIPS64 hard-float */\n\n#define CCALL_HANDLE_COMPLEXRET2 \\\n  if (ctr->size == 2*sizeof(float)) {  /* Copy complex float from FPRs. */ \\\n    ((float *)dp)[0] = cc->fpr[0].f; \\\n    ((float *)dp)[1] = cc->fpr[1].f; \\\n  } else {  /* Copy complex double from FPRs. */ \\\n    ((double *)dp)[0] = cc->fpr[0].d; \\\n    ((double *)dp)[1] = cc->fpr[1].d; \\\n  }\n\n#define CCALL_HANDLE_COMPLEXARG \\\n  if (sz == 2*sizeof(float)) { \\\n    isfp = 2; \\\n    if (ngpr < maxgpr) \\\n      sz *= 2; \\\n  }\n\n#define CCALL_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    sp = (uint8_t *)&cc->fpr[0].f;\n\n#endif\n\n#define CCALL_HANDLE_STRUCTARG \\\n  /* Pass all structs by value in registers and/or on the stack. */\n\n#define CCALL_HANDLE_REGARG \\\n  if (ngpr < maxgpr) { \\\n    dp = &cc->gpr[ngpr]; \\\n    if (ngpr + n > maxgpr) { \\\n      nsp += ngpr + n - maxgpr;  /* Assumes contiguous gpr/stack fields. */ \\\n      if (nsp > CCALL_MAXSTACK) goto err_nyi;  /* Too many arguments. */ \\\n      ngpr = maxgpr; \\\n    } else { \\\n      ngpr += n; \\\n    } \\\n    goto done; \\\n  }\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n#ifndef CCALL_HANDLE_STRUCTRET2\n#define CCALL_HANDLE_STRUCTRET2 \\\n  memcpy(dp, sp, ctr->size);  /* Copy struct return value from GPRs. */\n#endif\n\n/* -- x86 OSX ABI struct classification ----------------------------------- */\n\n#if LJ_TARGET_X86 && LJ_TARGET_OSX\n\n/* Check for struct with single FP field. */\nstatic int ccall_classify_struct(CTState *cts, CType *ct)\n{\n  CTSize sz = ct->size;\n  if (!(sz == sizeof(float) || sz == sizeof(double))) return 0;\n  if ((ct->info & CTF_UNION)) return 0;\n  while (ct->sib) {\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      CType *sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tif (sct->size == sz)\n\t  return (sz >> 2);  /* Return 1 for float or 2 for double. */\n      } else if (ctype_isstruct(sct->info)) {\n\tif (sct->size)\n\t  return ccall_classify_struct(cts, sct);\n      } else {\n\tbreak;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      break;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      CType *sct = ctype_rawchild(cts, ct);\n      if (sct->size)\n\treturn ccall_classify_struct(cts, sct);\n    }\n  }\n  return 0;\n}\n\n#endif\n\n/* -- x64 struct classification ------------------------------------------- */\n\n#if LJ_TARGET_X64 && !LJ_ABI_WIN\n\n/* Register classes for x64 struct classification. */\n#define CCALL_RCL_INT\t1\n#define CCALL_RCL_SSE\t2\n#define CCALL_RCL_MEM\t4\n/* NYI: classify vectors. */\n\nstatic int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs);\n\n/* Classify a C type. */\nstatic void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs)\n{\n  if (ctype_isarray(ct->info)) {\n    CType *cct = ctype_rawchild(cts, ct);\n    CTSize eofs, esz = cct->size, asz = ct->size;\n    for (eofs = 0; eofs < asz; eofs += esz)\n      ccall_classify_ct(cts, cct, rcl, ofs+eofs);\n  } else if (ctype_isstruct(ct->info)) {\n    ccall_classify_struct(cts, ct, rcl, ofs);\n  } else {\n    int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT;\n    lj_assertCTS(ctype_hassize(ct->info),\n\t\t \"classify ctype %08x without size\", ct->info);\n    if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM;  /* Unaligned. */\n    rcl[(ofs >= 8)] |= cl;\n  }\n}\n\n/* Recursively classify a struct based on its fields. */\nstatic int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs)\n{\n  if (ct->size > 16) return CCALL_RCL_MEM;  /* Too big, gets memory class. */\n  while (ct->sib) {\n    CTSize fofs;\n    ct = ctype_get(cts, ct->sib);\n    fofs = ofs+ct->size;\n    if (ctype_isfield(ct->info))\n      ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs);\n    else if (ctype_isbitfield(ct->info))\n      rcl[(fofs >= 8)] |= CCALL_RCL_INT;  /* NYI: unaligned bitfields? */\n    else if (ctype_isxattrib(ct->info, CTA_SUBTYPE))\n      ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs);\n  }\n  return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM);  /* Memory class? */\n}\n\n/* Try to split up a small struct into registers. */\nstatic int ccall_struct_reg(CCallState *cc, CTState *cts, GPRArg *dp, int *rcl)\n{\n  MSize ngpr = cc->ngpr, nfpr = cc->nfpr;\n  uint32_t i;\n  UNUSED(cts);\n  for (i = 0; i < 2; i++) {\n    lj_assertCTS(!(rcl[i] & CCALL_RCL_MEM), \"pass mem struct in reg\");\n    if ((rcl[i] & CCALL_RCL_INT)) {  /* Integer class takes precedence. */\n      if (ngpr >= CCALL_NARG_GPR) return 1;  /* Register overflow. */\n      cc->gpr[ngpr++] = dp[i];\n    } else if ((rcl[i] & CCALL_RCL_SSE)) {\n      if (nfpr >= CCALL_NARG_FPR) return 1;  /* Register overflow. */\n      cc->fpr[nfpr++].l[0] = dp[i];\n    }\n  }\n  cc->ngpr = ngpr; cc->nfpr = nfpr;\n  return 0;  /* Ok. */\n}\n\n/* Pass a small struct argument. */\nstatic int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl,\n\t\t\t    TValue *o, int narg)\n{\n  GPRArg dp[2];\n  dp[0] = dp[1] = 0;\n  /* Convert to temp. struct. */\n  lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));\n  if (ccall_struct_reg(cc, cts, dp, rcl)) {\n    /* Register overflow? Pass on stack. */\n    MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1;\n    if (nsp + n > CCALL_MAXSTACK) return 1;  /* Too many arguments. */\n    cc->nsp = nsp + n;\n    memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR);\n  }\n  return 0;  /* Ok. */\n}\n\n/* Combine returned small struct. */\nstatic void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz)\n{\n  GPRArg sp[2];\n  MSize ngpr = 0, nfpr = 0;\n  uint32_t i;\n  for (i = 0; i < 2; i++) {\n    if ((rcl[i] & CCALL_RCL_INT)) {  /* Integer class takes precedence. */\n      sp[i] = cc->gpr[ngpr++];\n    } else if ((rcl[i] & CCALL_RCL_SSE)) {\n      sp[i] = cc->fpr[nfpr++].l[0];\n    }\n  }\n  memcpy(dp, sp, sz);\n}\n#endif\n\n/* -- ARM hard-float ABI struct classification ---------------------------- */\n\n#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP\n\n/* Classify a struct based on its fields. */\nstatic unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf)\n{\n  CTSize sz = ct->size;\n  unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);\n  if ((ctf->info & CTF_VARARG)) goto noth;\n  while (ct->sib) {\n    CType *sct;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tr |= sct->size;\n\tif (!isu) n++; else if (n == 0) n = 1;\n      } else if (ctype_iscomplex(sct->info)) {\n\tr |= (sct->size >> 1);\n\tif (!isu) n += 2; else if (n < 2) n = 2;\n      } else if (ctype_isstruct(sct->info)) {\n\tgoto substruct;\n      } else {\n\tgoto noth;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      goto noth;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      sct = ctype_rawchild(cts, ct);\n    substruct:\n      if (sct->size > 0) {\n\tunsigned int s = ccall_classify_struct(cts, sct, ctf);\n\tif (s <= 1) goto noth;\n\tr |= (s & 255);\n\tif (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);\n      }\n    }\n  }\n  if ((r == 4 || r == 8) && n <= 4)\n    return r + (n << 8);\nnoth:  /* Not a homogeneous float/double aggregate. */\n  return (sz <= 4);  /* Return structs of size <= 4 in a GPR. */\n}\n\n#endif\n\n/* -- ARM64 ABI struct classification ------------------------------------- */\n\n#if LJ_TARGET_ARM64\n\n/* Classify a struct based on its fields. */\nstatic unsigned int ccall_classify_struct(CTState *cts, CType *ct)\n{\n  CTSize sz = ct->size;\n  unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);\n  while (ct->sib) {\n    CType *sct;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tr |= sct->size;\n\tif (!isu) n++; else if (n == 0) n = 1;\n      } else if (ctype_iscomplex(sct->info)) {\n\tr |= (sct->size >> 1);\n\tif (!isu) n += 2; else if (n < 2) n = 2;\n      } else if (ctype_isstruct(sct->info)) {\n\tgoto substruct;\n      } else {\n\tgoto noth;\n      }\n    } else if (ctype_isbitfield(ct->info)) {\n      goto noth;\n    } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      sct = ctype_rawchild(cts, ct);\n    substruct:\n      if (sct->size > 0) {\n\tunsigned int s = ccall_classify_struct(cts, sct);\n\tif (s <= 1) goto noth;\n\tr |= (s & 255);\n\tif (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);\n      }\n    }\n  }\n  if ((r == 4 || r == 8) && n <= 4)\n    return r + (n << 8);\nnoth:  /* Not a homogeneous float/double aggregate. */\n  return (sz <= 16);  /* Return structs of size <= 16 in GPRs. */\n}\n\n#endif\n\n/* -- MIPS64 ABI struct classification ---------------------------- */\n\n#if LJ_TARGET_MIPS64\n\n#define FTYPE_FLOAT\t1\n#define FTYPE_DOUBLE\t2\n\n/* Classify FP fields (max. 2) and their types. */\nstatic unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf)\n{\n  int n = 0, ft = 0;\n  if ((ctf->info & CTF_VARARG) || (ct->info & CTF_UNION))\n    goto noth;\n  while (ct->sib) {\n    CType *sct;\n    ct = ctype_get(cts, ct->sib);\n    if (n == 2) {\n      goto noth;\n    } else if (ctype_isfield(ct->info)) {\n      sct = ctype_rawchild(cts, ct);\n      if (ctype_isfp(sct->info)) {\n\tft |= (sct->size == 4 ? FTYPE_FLOAT : FTYPE_DOUBLE) << 2*n;\n\tn++;\n      } else {\n\tgoto noth;\n      }\n    } else if (ctype_isbitfield(ct->info) ||\n\t       ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      goto noth;\n    }\n  }\n  if (n <= 2)\n    return ft;\nnoth:  /* Not a homogeneous float/double aggregate. */\n  return 0;  /* Struct is in GPRs. */\n}\n\nstatic void ccall_copy_struct(CCallState *cc, CType *ctr, void *dp, void *sp,\n\t\t\t      int ft)\n{\n  if (LJ_ABI_SOFTFP ? ft :\n      ((ft & 3) == FTYPE_FLOAT || (ft >> 2) == FTYPE_FLOAT)) {\n    int i, ofs = 0;\n    for (i = 0; ft != 0; i++, ft >>= 2) {\n      if ((ft & 3) == FTYPE_FLOAT) {\n#if LJ_ABI_SOFTFP\n\t/* The 2nd FP struct result is in CARG1 (gpr[2]) and not CRET2. */\n\tmemcpy((uint8_t *)dp + ofs,\n\t       (uint8_t *)&cc->gpr[2*i] + LJ_ENDIAN_SELECT(0, 4), 4);\n#else\n\t*(float *)((uint8_t *)dp + ofs) = cc->fpr[i].f;\n#endif\n\tofs += 4;\n      } else {\n\tofs = (ofs + 7) & ~7;  /* 64 bit alignment. */\n#if LJ_ABI_SOFTFP\n\t*(intptr_t *)((uint8_t *)dp + ofs) = cc->gpr[2*i];\n#else\n\t*(double *)((uint8_t *)dp + ofs) = cc->fpr[i].d;\n#endif\n\tofs += 8;\n      }\n    }\n  } else {\n#if !LJ_ABI_SOFTFP\n    if (ft) sp = (uint8_t *)&cc->fpr[0];\n#endif\n    memcpy(dp, sp, ctr->size);\n  }\n}\n\n#endif\n\n/* -- Common C call handling ---------------------------------------------- */\n\n/* Infer the destination CTypeID for a vararg argument. */\nCTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o)\n{\n  if (tvisnumber(o)) {\n    return CTID_DOUBLE;\n  } else if (tviscdata(o)) {\n    CTypeID id = cdataV(o)->ctypeid;\n    CType *s = ctype_get(cts, id);\n    if (ctype_isrefarray(s->info)) {\n      return lj_ctype_intern(cts,\n\t       CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR);\n    } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) {\n      /* NYI: how to pass a struct by value in a vararg argument? */\n      return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR);\n    } else if (ctype_isfp(s->info) && s->size == sizeof(float)) {\n      return CTID_DOUBLE;\n    } else {\n      return id;\n    }\n  } else if (tvisstr(o)) {\n    return CTID_P_CCHAR;\n  } else if (tvisbool(o)) {\n    return CTID_BOOL;\n  } else {\n    return CTID_P_VOID;\n  }\n}\n\n/* Setup arguments for C call. */\nstatic int ccall_set_args(lua_State *L, CTState *cts, CType *ct,\n\t\t\t  CCallState *cc)\n{\n  int gcsteps = 0;\n  TValue *o, *top = L->top;\n  CTypeID fid;\n  CType *ctr;\n  MSize maxgpr, ngpr = 0, nsp = 0, narg;\n#if CCALL_NARG_FPR\n  MSize nfpr = 0;\n#if LJ_TARGET_ARM\n  MSize fprodd = 0;\n#endif\n#endif\n\n  /* Clear unused regs to get some determinism in case of misdeclaration. */\n  memset(cc->gpr, 0, sizeof(cc->gpr));\n#if CCALL_NUM_FPR\n  memset(cc->fpr, 0, sizeof(cc->fpr));\n#endif\n\n#if LJ_TARGET_X86\n  /* x86 has several different calling conventions. */\n  cc->resx87 = 0;\n  switch (ctype_cconv(ct->info)) {\n  case CTCC_FASTCALL: maxgpr = 2; break;\n  case CTCC_THISCALL: maxgpr = 1; break;\n  default: maxgpr = 0; break;\n  }\n#else\n  maxgpr = CCALL_NARG_GPR;\n#endif\n\n  /* Perform required setup for some result types. */\n  ctr = ctype_rawchild(cts, ct);\n  if (ctype_isvector(ctr->info)) {\n    if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16)))\n      goto err_nyi;\n  } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) {\n    /* Preallocate cdata object and anchor it after arguments. */\n    CTSize sz = ctr->size;\n    GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz);\n    void *dp = cdataptr(cd);\n    setcdataV(L, L->top++, cd);\n    if (ctype_isstruct(ctr->info)) {\n      CCALL_HANDLE_STRUCTRET\n    } else {\n      CCALL_HANDLE_COMPLEXRET\n    }\n#if LJ_TARGET_X86\n  } else if (ctype_isfp(ctr->info)) {\n    cc->resx87 = ctr->size == sizeof(float) ? 1 : 2;\n#endif\n  }\n\n  /* Skip initial attributes. */\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) break;\n    fid = ctf->sib;\n  }\n\n  /* Walk through all passed arguments. */\n  for (o = L->base+1, narg = 1; o < top; o++, narg++) {\n    CTypeID did;\n    CType *d;\n    CTSize sz;\n    MSize n, isfp = 0, isva = 0;\n    void *dp, *rp = NULL;\n\n    if (fid) {  /* Get argument type from field. */\n      CType *ctf = ctype_get(cts, fid);\n      fid = ctf->sib;\n      lj_assertL(ctype_isfield(ctf->info), \"field expected\");\n      did = ctype_cid(ctf->info);\n    } else {\n      if (!(ct->info & CTF_VARARG))\n\tlj_err_caller(L, LJ_ERR_FFI_NUMARG);  /* Too many arguments. */\n      did = lj_ccall_ctid_vararg(cts, o);  /* Infer vararg type. */\n      isva = 1;\n    }\n    d = ctype_raw(cts, did);\n    sz = d->size;\n\n    /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */\n    if (ctype_isnum(d->info)) {\n      if (sz > 8) goto err_nyi;\n      if ((d->info & CTF_FP))\n\tisfp = 1;\n    } else if (ctype_isvector(d->info)) {\n      if (CCALL_VECTOR_REG && (sz == 8 || sz == 16))\n\tisfp = 1;\n      else\n\tgoto err_nyi;\n    } else if (ctype_isstruct(d->info)) {\n      CCALL_HANDLE_STRUCTARG\n    } else if (ctype_iscomplex(d->info)) {\n      CCALL_HANDLE_COMPLEXARG\n    } else {\n      sz = CTSIZE_PTR;\n    }\n    sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);\n    n = sz / CTSIZE_PTR;  /* Number of GPRs or stack slots needed. */\n\n    CCALL_HANDLE_REGARG  /* Handle register arguments. */\n\n    /* Otherwise pass argument on stack. */\n    if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) {\n      MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1;\n      nsp = (nsp + align) & ~align;  /* Align argument on stack. */\n    }\n    if (nsp + n > CCALL_MAXSTACK) {  /* Too many arguments. */\n    err_nyi:\n      lj_err_caller(L, LJ_ERR_FFI_NYICALL);\n    }\n    dp = &cc->stack[nsp];\n    nsp += n;\n    isva = 0;\n\n  done:\n    if (rp) {  /* Pass by reference. */\n      gcsteps++;\n      *(void **)dp = rp;\n      dp = rp;\n    }\n    lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));\n    /* Extend passed integers to 32 bits at least. */\n    if (ctype_isinteger_or_bool(d->info) && d->size < 4) {\n      if (d->info & CTF_UNSIGNED)\n\t*(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp :\n\t\t\t\t\t (uint32_t)*(uint16_t *)dp;\n      else\n\t*(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp :\n\t\t\t\t\t(int32_t)*(int16_t *)dp;\n    }\n#if LJ_TARGET_ARM64 && LJ_BE\n    if (isfp && d->size == sizeof(float))\n      ((float *)dp)[1] = ((float *)dp)[0];  /* Floats occupy high slot. */\n#endif\n#if LJ_TARGET_MIPS64 || (LJ_TARGET_ARM64 && LJ_BE)\n    if ((ctype_isinteger_or_bool(d->info) || ctype_isenum(d->info)\n#if LJ_TARGET_MIPS64\n\t || (isfp && nsp == 0)\n#endif\n\t ) && d->size <= 4) {\n      *(int64_t *)dp = (int64_t)*(int32_t *)dp;  /* Sign-extend to 64 bit. */\n    }\n#endif\n#if LJ_TARGET_X64 && LJ_ABI_WIN\n    if (isva) {  /* Windows/x64 mirrors varargs in both register sets. */\n      if (nfpr == ngpr)\n\tcc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0];\n      else\n\tcc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1];\n    }\n#else\n    UNUSED(isva);\n#endif\n#if LJ_TARGET_X64 && !LJ_ABI_WIN\n    if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) {\n      cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1];  /* Split complex double. */\n      cc->fpr[nfpr-2].d[1] = 0;\n    }\n#elif LJ_TARGET_ARM64 || (LJ_TARGET_MIPS64 && !LJ_ABI_SOFTFP)\n    if (isfp == 2 && (uint8_t *)dp < (uint8_t *)cc->stack) {\n      /* Split float HFA or complex float into separate registers. */\n      CTSize i = (sz >> 2) - 1;\n      do { ((uint64_t *)dp)[i] = ((uint32_t *)dp)[i]; } while (i--);\n    }\n#else\n    UNUSED(isfp);\n#endif\n  }\n  if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG);  /* Too few arguments. */\n\n#if LJ_TARGET_X64 || (LJ_TARGET_PPC && !LJ_ABI_SOFTFP)\n  cc->nfpr = nfpr;  /* Required for vararg functions. */\n#endif\n  cc->nsp = nsp;\n  cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR;\n  if (nsp > CCALL_SPS_FREE)\n    cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u);\n  return gcsteps;\n}\n\n/* Get results from C call. */\nstatic int ccall_get_results(lua_State *L, CTState *cts, CType *ct,\n\t\t\t     CCallState *cc, int *ret)\n{\n  CType *ctr = ctype_rawchild(cts, ct);\n  uint8_t *sp = (uint8_t *)&cc->gpr[0];\n  if (ctype_isvoid(ctr->info)) {\n    *ret = 0;  /* Zero results. */\n    return 0;  /* No additional GC step. */\n  }\n  *ret = 1;  /* One result. */\n  if (ctype_isstruct(ctr->info)) {\n    /* Return cdata object which is already on top of stack. */\n    if (!cc->retref) {\n      void *dp = cdataptr(cdataV(L->top-1));  /* Use preallocated object. */\n      CCALL_HANDLE_STRUCTRET2\n    }\n    return 1;  /* One GC step. */\n  }\n  if (ctype_iscomplex(ctr->info)) {\n    /* Return cdata object which is already on top of stack. */\n    void *dp = cdataptr(cdataV(L->top-1));  /* Use preallocated object. */\n    CCALL_HANDLE_COMPLEXRET2\n    return 1;  /* One GC step. */\n  }\n  if (LJ_BE && ctr->size < CTSIZE_PTR &&\n      (ctype_isinteger_or_bool(ctr->info) || ctype_isenum(ctr->info)))\n    sp += (CTSIZE_PTR - ctr->size);\n#if CCALL_NUM_FPR\n  if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info))\n    sp = (uint8_t *)&cc->fpr[0];\n#endif\n#ifdef CCALL_HANDLE_RET\n  CCALL_HANDLE_RET\n#endif\n  /* No reference types end up here, so there's no need for the CTypeID. */\n  lj_assertL(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info)),\n\t     \"unexpected reference ctype\");\n  return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp);\n}\n\n/* Call C function. */\nint lj_ccall_func(lua_State *L, GCcdata *cd)\n{\n  CTState *cts = ctype_cts(L);\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  CTSize sz = CTSIZE_PTR;\n  if (ctype_isptr(ct->info)) {\n    sz = ct->size;\n    ct = ctype_rawchild(cts, ct);\n  }\n  if (ctype_isfunc(ct->info)) {\n    CCallState cc;\n    int gcsteps, ret;\n    cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz);\n    gcsteps = ccall_set_args(L, cts, ct, &cc);\n    ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab);\n    cts->cb.slot = ~0u;\n    lj_vm_ffi_call(&cc);\n    if (cts->cb.slot != ~0u) {  /* Blacklist function that called a callback. */\n      TValue tv;\n      tv.u64 = ((uintptr_t)(void *)cc.func >> 2) | U64x(800000000, 00000000);\n      setboolV(lj_tab_set(L, cts->miscmap, &tv), 1);\n    }\n    ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab);  /* May be reallocated. */\n    gcsteps += ccall_get_results(L, cts, ct, &cc, &ret);\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n    /* Automatically detect __stdcall and fix up C function declaration. */\n    if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) {\n      CTF_INSERT(ct->info, CCONV, CTCC_STDCALL);\n      lj_trace_abort(G(L));\n    }\n#endif\n    while (gcsteps-- > 0)\n      lj_gc_check(L);\n    return ret;\n  }\n  return -1;  /* Not a function. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ccall.h",
    "content": "/*\n** FFI C call handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCALL_H\n#define _LJ_CCALL_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* -- C calling conventions ----------------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n\n#if LJ_TARGET_X86\n#define CCALL_NARG_GPR\t\t2\t/* For fastcall arguments. */\n#define CCALL_NARG_FPR\t\t0\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t1\t/* For FP results on x87 stack. */\n#define CCALL_ALIGN_STACKARG\t0\t/* Don't align argument on stack. */\n#elif LJ_ABI_WIN\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NARG_FPR\t\t4\n#define CCALL_NRET_GPR\t\t1\n#define CCALL_NRET_FPR\t\t1\n#define CCALL_SPS_EXTRA\t\t4\n#else\n#define CCALL_NARG_GPR\t\t6\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t2\n#define CCALL_VECTOR_REG\t1\t/* Pass vectors in registers. */\n#endif\n\n#define CCALL_SPS_FREE\t\t1\n#define CCALL_ALIGN_CALLSTATE\t16\n\ntypedef LJ_ALIGN(16) union FPRArg {\n  double d[2];\n  float f[4];\n  uint8_t b[16];\n  uint16_t s[8];\n  int i[4];\n  int64_t l[2];\n} FPRArg;\n\ntypedef intptr_t GPRArg;\n\n#elif LJ_TARGET_ARM\n\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NRET_GPR\t\t2\t/* For softfp double. */\n#if LJ_ABI_SOFTFP\n#define CCALL_NARG_FPR\t\t0\n#define CCALL_NRET_FPR\t\t0\n#else\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_FPR\t\t4\n#endif\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  float f[2];\n} FPRArg;\n\n#elif LJ_TARGET_ARM64\n\n#define CCALL_NARG_GPR\t\t8\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NARG_FPR\t\t8\n#define CCALL_NRET_FPR\t\t4\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  struct { LJ_ENDIAN_LOHI(float f; , float g;) };\n  struct { LJ_ENDIAN_LOHI(uint32_t lo; , uint32_t hi;) };\n} FPRArg;\n\n#elif LJ_TARGET_PPC\n\n#define CCALL_NARG_GPR\t\t8\n#define CCALL_NARG_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 8)\n#define CCALL_NRET_GPR\t\t4\t/* For complex double. */\n#define CCALL_NRET_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 1)\n#define CCALL_SPS_EXTRA\t\t4\n#define CCALL_SPS_FREE\t\t0\n\ntypedef intptr_t GPRArg;\ntypedef double FPRArg;\n\n#elif LJ_TARGET_MIPS32\n\n#define CCALL_NARG_GPR\t\t4\n#define CCALL_NARG_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 2)\n#define CCALL_NRET_GPR\t\t(LJ_ABI_SOFTFP ? 4 : 2)\n#define CCALL_NRET_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 2)\n#define CCALL_SPS_EXTRA\t\t7\n#define CCALL_SPS_FREE\t\t1\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  struct { LJ_ENDIAN_LOHI(float f; , float g;) };\n} FPRArg;\n\n#elif LJ_TARGET_MIPS64\n\n/* FP args are positional and overlay the GPR array. */\n#define CCALL_NARG_GPR\t\t8\n#define CCALL_NARG_FPR\t\t0\n#define CCALL_NRET_GPR\t\t2\n#define CCALL_NRET_FPR\t\t(LJ_ABI_SOFTFP ? 0 : 2)\n#define CCALL_SPS_EXTRA\t\t3\n#define CCALL_SPS_FREE\t\t1\n\ntypedef intptr_t GPRArg;\ntypedef union FPRArg {\n  double d;\n  struct { LJ_ENDIAN_LOHI(float f; , float g;) };\n} FPRArg;\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n#ifndef CCALL_SPS_EXTRA\n#define CCALL_SPS_EXTRA\t\t0\n#endif\n#ifndef CCALL_VECTOR_REG\n#define CCALL_VECTOR_REG\t0\n#endif\n#ifndef CCALL_ALIGN_STACKARG\n#define CCALL_ALIGN_STACKARG\t1\n#endif\n#ifndef CCALL_ALIGN_CALLSTATE\n#define CCALL_ALIGN_CALLSTATE\t8\n#endif\n\n#define CCALL_NUM_GPR \\\n  (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR)\n#define CCALL_NUM_FPR \\\n  (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR)\n\n/* Check against constants in lj_ctype.h. */\nLJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR);\nLJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR);\n\n#define CCALL_MAXSTACK\t\t32\n\n/* -- C call state -------------------------------------------------------- */\n\ntypedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState {\n  void (*func)(void);\t\t/* Pointer to called function. */\n  uint32_t spadj;\t\t/* Stack pointer adjustment. */\n  uint8_t nsp;\t\t\t/* Number of stack slots. */\n  uint8_t retref;\t\t/* Return value by reference. */\n#if LJ_TARGET_X64\n  uint8_t ngpr;\t\t\t/* Number of arguments in GPRs. */\n  uint8_t nfpr;\t\t\t/* Number of arguments in FPRs. */\n#elif LJ_TARGET_X86\n  uint8_t resx87;\t\t/* Result on x87 stack: 1:float, 2:double. */\n#elif LJ_TARGET_ARM64\n  void *retp;\t\t\t/* Aggregate return pointer in x8. */\n#elif LJ_TARGET_PPC\n  uint8_t nfpr;\t\t\t/* Number of arguments in FPRs. */\n#endif\n#if LJ_32\n  int32_t align1;\n#endif\n#if CCALL_NUM_FPR\n  FPRArg fpr[CCALL_NUM_FPR];\t/* Arguments/results in FPRs. */\n#endif\n  GPRArg gpr[CCALL_NUM_GPR];\t/* Arguments/results in GPRs. */\n  GPRArg stack[CCALL_MAXSTACK];\t/* Stack slots. */\n} CCallState;\n\n/* -- C call handling ----------------------------------------------------- */\n\n/* Really belongs to lj_vm.h. */\nLJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);\n\nLJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);\nLJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ccallback.c",
    "content": "/*\n** FFI C callback handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_target.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n\n/* -- Target-specific handling of callback slots -------------------------- */\n\n#define CALLBACK_MCODE_SIZE\t(LJ_PAGESIZE * LJ_NUM_CBPAGE)\n\n#if LJ_OS_NOJIT\n\n/* Callbacks disabled. */\n#define CALLBACK_SLOT2OFS(slot)\t(0*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t(0*(ofs))\n#define CALLBACK_MAX_SLOT\t0\n\n#elif LJ_TARGET_X86ORX64\n\n#define CALLBACK_MCODE_HEAD\t(LJ_64 ? 8 : 0)\n#define CALLBACK_MCODE_GROUP\t(-2+1+2+(LJ_GC64 ? 10 : 5)+(LJ_64 ? 6 : 5))\n\n#define CALLBACK_SLOT2OFS(slot) \\\n  (CALLBACK_MCODE_HEAD + CALLBACK_MCODE_GROUP*((slot)/32) + 4*(slot))\n\nstatic MSize CALLBACK_OFS2SLOT(MSize ofs)\n{\n  MSize group;\n  ofs -= CALLBACK_MCODE_HEAD;\n  group = ofs / (32*4 + CALLBACK_MCODE_GROUP);\n  return (ofs % (32*4 + CALLBACK_MCODE_GROUP))/4 + group*32;\n}\n\n#define CALLBACK_MAX_SLOT \\\n  (((CALLBACK_MCODE_SIZE-CALLBACK_MCODE_HEAD)/(CALLBACK_MCODE_GROUP+4*32))*32)\n\n#elif LJ_TARGET_ARM\n\n#define CALLBACK_MCODE_HEAD\t\t32\n\n#elif LJ_TARGET_ARM64\n\n#define CALLBACK_MCODE_HEAD\t\t32\n\n#elif LJ_TARGET_PPC\n\n#define CALLBACK_MCODE_HEAD\t\t24\n\n#elif LJ_TARGET_MIPS32\n\n#define CALLBACK_MCODE_HEAD\t\t20\n\n#elif LJ_TARGET_MIPS64\n\n#define CALLBACK_MCODE_HEAD\t\t52\n\n#else\n\n/* Missing support for this architecture. */\n#define CALLBACK_SLOT2OFS(slot)\t(0*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t(0*(ofs))\n#define CALLBACK_MAX_SLOT\t0\n\n#endif\n\n#ifndef CALLBACK_SLOT2OFS\n#define CALLBACK_SLOT2OFS(slot)\t\t(CALLBACK_MCODE_HEAD + 8*(slot))\n#define CALLBACK_OFS2SLOT(ofs)\t\t(((ofs)-CALLBACK_MCODE_HEAD)/8)\n#define CALLBACK_MAX_SLOT\t\t(CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))\n#endif\n\n/* Convert callback slot number to callback function pointer. */\nstatic void *callback_slot2ptr(CTState *cts, MSize slot)\n{\n  return (uint8_t *)cts->cb.mcode + CALLBACK_SLOT2OFS(slot);\n}\n\n/* Convert callback function pointer to slot number. */\nMSize lj_ccallback_ptr2slot(CTState *cts, void *p)\n{\n  uintptr_t ofs = (uintptr_t)((uint8_t *)p -(uint8_t *)cts->cb.mcode);\n  if (ofs < CALLBACK_MCODE_SIZE) {\n    MSize slot = CALLBACK_OFS2SLOT((MSize)ofs);\n    if (CALLBACK_SLOT2OFS(slot) == (MSize)ofs)\n      return slot;\n  }\n  return ~0u;  /* Not a known callback function pointer. */\n}\n\n/* Initialize machine code for callback function pointers. */\n#if LJ_OS_NOJIT\n/* Disabled callback support. */\n#define callback_mcode_init(g, p)\t(p)\n#elif LJ_TARGET_X86ORX64\nstatic void *callback_mcode_init(global_State *g, uint8_t *page)\n{\n  uint8_t *p = page;\n  uint8_t *target = (uint8_t *)(void *)lj_vm_ffi_callback;\n  MSize slot;\n#if LJ_64\n  *(void **)p = target; p += 8;\n#endif\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    /* mov al, slot; jmp group */\n    *p++ = XI_MOVrib | RID_EAX; *p++ = (uint8_t)slot;\n    if ((slot & 31) == 31 || slot == CALLBACK_MAX_SLOT-1) {\n      /* push ebp/rbp; mov ah, slot>>8; mov ebp, &g. */\n      *p++ = XI_PUSH + RID_EBP;\n      *p++ = XI_MOVrib | (RID_EAX+4); *p++ = (uint8_t)(slot >> 8);\n#if LJ_GC64\n      *p++ = 0x48; *p++ = XI_MOVri | RID_EBP;\n      *(uint64_t *)p = (uint64_t)(g); p += 8;\n#else\n      *p++ = XI_MOVri | RID_EBP;\n      *(int32_t *)p = i32ptr(g); p += 4;\n#endif\n#if LJ_64\n      /* jmp [rip-pageofs] where lj_vm_ffi_callback is stored. */\n      *p++ = XI_GROUP5; *p++ = XM_OFS0 + (XOg_JMP<<3) + RID_EBP;\n      *(int32_t *)p = (int32_t)(page-(p+4)); p += 4;\n#else\n      /* jmp lj_vm_ffi_callback. */\n      *p++ = XI_JMP; *(int32_t *)p = target-(p+4); p += 4;\n#endif\n    } else {\n      *p++ = XI_JMPs; *p++ = (uint8_t)((2+2)*(31-(slot&31)) - 2);\n    }\n  }\n  return p;\n}\n#elif LJ_TARGET_ARM\nstatic void *callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  /* This must match with the saveregs macro in buildvm_arm.dasc. */\n  *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC);\n  *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR);\n  *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD;\n  *p++ = ARMI_STR|ARMI_LS_P|ARMI_LS_W|ARMF_D(RID_R12)|ARMF_N(RID_SP)|(CFRAME_SIZE-4*9);\n  *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_R12)|ARMF_N(RID_PC);\n  *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_PC)|ARMF_N(RID_PC);\n  *p++ = u32ptr(g);\n  *p++ = u32ptr(target);\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = ARMI_MOV|ARMF_D(RID_R12)|ARMF_M(RID_PC);\n    *p = ARMI_B | ((page-p-2) & 0x00ffffffu);\n    p++;\n  }\n  return p;\n}\n#elif LJ_TARGET_ARM64\nstatic void *callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  *p++ = A64I_LE(A64I_LDRLx | A64F_D(RID_X11) | A64F_S19(4));\n  *p++ = A64I_LE(A64I_LDRLx | A64F_D(RID_X10) | A64F_S19(5));\n  *p++ = A64I_LE(A64I_BR | A64F_N(RID_X11));\n  *p++ = A64I_LE(A64I_NOP);\n  ((void **)p)[0] = target;\n  ((void **)p)[1] = g;\n  p += 4;\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = A64I_LE(A64I_MOVZw | A64F_D(RID_X9) | A64F_U16(slot));\n    *p = A64I_LE(A64I_B | A64F_S26((page-p) & 0x03ffffffu));\n    p++;\n  }\n  return p;\n}\n#elif LJ_TARGET_PPC\nstatic void *callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  void *target = (void *)lj_vm_ffi_callback;\n  MSize slot;\n  *p++ = PPCI_LIS | PPCF_T(RID_TMP) | (u32ptr(target) >> 16);\n  *p++ = PPCI_LIS | PPCF_T(RID_R12) | (u32ptr(g) >> 16);\n  *p++ = PPCI_ORI | PPCF_A(RID_TMP)|PPCF_T(RID_TMP) | (u32ptr(target) & 0xffff);\n  *p++ = PPCI_ORI | PPCF_A(RID_R12)|PPCF_T(RID_R12) | (u32ptr(g) & 0xffff);\n  *p++ = PPCI_MTCTR | PPCF_T(RID_TMP);\n  *p++ = PPCI_BCTR;\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p++ = PPCI_LI | PPCF_T(RID_R11) | slot;\n    *p = PPCI_B | (((page-p) & 0x00ffffffu) << 2);\n    p++;\n  }\n  return p;\n}\n#elif LJ_TARGET_MIPS\nstatic void *callback_mcode_init(global_State *g, uint32_t *page)\n{\n  uint32_t *p = page;\n  uintptr_t target = (uintptr_t)(void *)lj_vm_ffi_callback;\n  uintptr_t ug = (uintptr_t)(void *)g;\n  MSize slot;\n#if LJ_TARGET_MIPS32\n  *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (target >> 16);\n  *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (ug >> 16);\n#else\n  *p++ = MIPSI_LUI  | MIPSF_T(RID_R3) | (target >> 48);\n  *p++ = MIPSI_LUI  | MIPSF_T(RID_R2) | (ug >> 48);\n  *p++ = MIPSI_ORI  | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) | ((target >> 32) & 0xffff);\n  *p++ = MIPSI_ORI  | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | ((ug >> 32) & 0xffff);\n  *p++ = MIPSI_DSLL | MIPSF_D(RID_R3)|MIPSF_T(RID_R3) | MIPSF_A(16);\n  *p++ = MIPSI_DSLL | MIPSF_D(RID_R2)|MIPSF_T(RID_R2) | MIPSF_A(16);\n  *p++ = MIPSI_ORI  | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) | ((target >> 16) & 0xffff);\n  *p++ = MIPSI_ORI  | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | ((ug >> 16) & 0xffff);\n  *p++ = MIPSI_DSLL | MIPSF_D(RID_R3)|MIPSF_T(RID_R3) | MIPSF_A(16);\n  *p++ = MIPSI_DSLL | MIPSF_D(RID_R2)|MIPSF_T(RID_R2) | MIPSF_A(16);\n#endif\n  *p++ = MIPSI_ORI  | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) | (target & 0xffff);\n  *p++ = MIPSI_JR | MIPSF_S(RID_R3);\n  *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (ug & 0xffff);\n  for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {\n    *p = MIPSI_B | ((page-p-1) & 0x0000ffffu);\n    p++;\n    *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot;\n  }\n  return p;\n}\n#else\n/* Missing support for this architecture. */\n#define callback_mcode_init(g, p)\t(p)\n#endif\n\n/* -- Machine code management --------------------------------------------- */\n\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#elif LJ_TARGET_POSIX\n\n#include <sys/mman.h>\n#ifndef MAP_ANONYMOUS\n#define MAP_ANONYMOUS   MAP_ANON\n#endif\n#ifdef PROT_MPROTECT\n#define CCPROT_CREATE\t(PROT_MPROTECT(PROT_EXEC))\n#else\n#define CCPROT_CREATE\t0\n#endif\n\n#endif\n\n/* Allocate and initialize area for callback function pointers. */\nstatic void callback_mcode_new(CTState *cts)\n{\n  size_t sz = (size_t)CALLBACK_MCODE_SIZE;\n  void *p, *pe;\n  if (CALLBACK_MAX_SLOT == 0)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#if LJ_TARGET_WINDOWS\n  p = LJ_WIN_VALLOC(NULL, sz, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);\n  if (!p)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#elif LJ_TARGET_POSIX\n  p = mmap(NULL, sz, (PROT_READ|PROT_WRITE|CCPROT_CREATE), MAP_PRIVATE|MAP_ANONYMOUS,\n\t   -1, 0);\n  if (p == MAP_FAILED)\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n#else\n  /* Fallback allocator. Fails if memory is not executable by default. */\n  p = lj_mem_new(cts->L, sz);\n#endif\n  cts->cb.mcode = p;\n  pe = callback_mcode_init(cts->g, p);\n  UNUSED(pe);\n  lj_assertCTS((size_t)((char *)pe - (char *)p) <= sz,\n\t       \"miscalculated CALLBACK_MAX_SLOT\");\n  lj_mcode_sync(p, (char *)p + sz);\n#if LJ_TARGET_WINDOWS\n  {\n    DWORD oprot;\n    LJ_WIN_VPROTECT(p, sz, PAGE_EXECUTE_READ, &oprot);\n  }\n#elif LJ_TARGET_POSIX\n  mprotect(p, sz, (PROT_READ|PROT_EXEC));\n#endif\n}\n\n/* Free area for callback function pointers. */\nvoid lj_ccallback_mcode_free(CTState *cts)\n{\n  size_t sz = (size_t)CALLBACK_MCODE_SIZE;\n  void *p = cts->cb.mcode;\n  if (p == NULL) return;\n#if LJ_TARGET_WINDOWS\n  VirtualFree(p, 0, MEM_RELEASE);\n  UNUSED(sz);\n#elif LJ_TARGET_POSIX\n  munmap(p, sz);\n#else\n  lj_mem_free(cts->g, p, sz);\n#endif\n}\n\n/* -- C callback entry ---------------------------------------------------- */\n\n/* Target-specific handling of register arguments. Similar to lj_ccall.c. */\n#if LJ_TARGET_X86\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (!isfp) {  /* Only non-FP values may be passed in registers. */ \\\n    if (n > 1) {  /* Anything > 32 bit is passed on the stack. */ \\\n      if (!LJ_ABI_WIN) ngpr = maxgpr;  /* Prevent reordering. */ \\\n    } else if (ngpr + 1 <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_X64 && LJ_ABI_WIN\n\n/* Windows/x64 argument registers are strictly positional (use ngpr). */\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (ngpr < maxgpr) { sp = &cts->cb.fpr[ngpr++]; UNUSED(nfpr); goto done; } \\\n  } else { \\\n    if (ngpr < maxgpr) { sp = &cts->cb.gpr[ngpr++]; goto done; } \\\n  }\n\n#elif LJ_TARGET_X64\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + n <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr]; \\\n      nfpr += n; \\\n      goto done; \\\n    } \\\n  } else { \\\n    if (ngpr + n <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } \\\n  }\n\n#elif LJ_TARGET_ARM\n\n#if LJ_ABI_SOFTFP\n\n#define CALLBACK_HANDLE_REGARG_FP1\tUNUSED(isfp);\n#define CALLBACK_HANDLE_REGARG_FP2\n\n#else\n\n#define CALLBACK_HANDLE_REGARG_FP1 \\\n  if (isfp) { \\\n    if (n == 1) { \\\n      if (fprodd) { \\\n\tsp = &cts->cb.fpr[fprodd-1]; \\\n\tfprodd = 0; \\\n\tgoto done; \\\n      } else if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n\tsp = &cts->cb.fpr[nfpr++]; \\\n\tfprodd = nfpr; \\\n\tgoto done; \\\n      } \\\n    } else { \\\n      if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n\tsp = &cts->cb.fpr[nfpr++]; \\\n\tgoto done; \\\n      } \\\n    } \\\n    fprodd = 0;  /* No reordering after the first FP value is on stack. */ \\\n  } else {\n\n#define CALLBACK_HANDLE_REGARG_FP2\t}\n\n#endif\n\n#define CALLBACK_HANDLE_REGARG \\\n  CALLBACK_HANDLE_REGARG_FP1 \\\n  if (n > 1) ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  } CALLBACK_HANDLE_REGARG_FP2\n\n#elif LJ_TARGET_ARM64\n\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + n <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr]; \\\n      nfpr += n; \\\n      goto done; \\\n    } else { \\\n      nfpr = CCALL_NARG_FPR;  /* Prevent reordering. */ \\\n    } \\\n  } else { \\\n    if (!LJ_TARGET_OSX && n > 1) \\\n      ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n    if (ngpr + n <= maxgpr) { \\\n      sp = &cts->cb.gpr[ngpr]; \\\n      ngpr += n; \\\n      goto done; \\\n    } else { \\\n      ngpr = CCALL_NARG_GPR;  /* Prevent reordering. */ \\\n    } \\\n  }\n\n#elif LJ_TARGET_PPC\n\n#define CALLBACK_HANDLE_GPR \\\n  if (n > 1) { \\\n    lj_assertCTS(((LJ_ABI_SOFTFP && ctype_isnum(cta->info)) ||  /* double. */ \\\n\t\t ctype_isinteger(cta->info)) && n == 2,  /* int64_t. */ \\\n\t\t \"bad GPR type\"); \\\n    ngpr = (ngpr + 1u) & ~1u;  /* Align int64_t to regpair. */ \\\n  } \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  }\n\n#if LJ_ABI_SOFTFP\n#define CALLBACK_HANDLE_REGARG \\\n  CALLBACK_HANDLE_GPR \\\n  UNUSED(isfp);\n#else\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp) { \\\n    if (nfpr + 1 <= CCALL_NARG_FPR) { \\\n      sp = &cts->cb.fpr[nfpr++]; \\\n      cta = ctype_get(cts, CTID_DOUBLE);  /* FPRs always hold doubles. */ \\\n      goto done; \\\n    } \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    CALLBACK_HANDLE_GPR \\\n  }\n#endif\n\n#if !LJ_ABI_SOFTFP\n#define CALLBACK_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    *(double *)dp = *(float *)dp;  /* FPRs always hold doubles. */\n#endif\n\n#elif LJ_TARGET_MIPS32\n\n#define CALLBACK_HANDLE_GPR \\\n  if (n > 1) ngpr = (ngpr + 1u) & ~1u;  /* Align to regpair. */ \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  }\n\n#if !LJ_ABI_SOFTFP\t/* MIPS32 hard-float */\n#define CALLBACK_HANDLE_REGARG \\\n  if (isfp && nfpr < CCALL_NARG_FPR) {  /* Try to pass argument in FPRs. */ \\\n    sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \\\n    nfpr++; ngpr += n; \\\n    goto done; \\\n  } else {  /* Try to pass argument in GPRs. */ \\\n    nfpr = CCALL_NARG_FPR; \\\n    CALLBACK_HANDLE_GPR \\\n  }\n#else\t\t\t/* MIPS32 soft-float */\n#define CALLBACK_HANDLE_REGARG \\\n  CALLBACK_HANDLE_GPR \\\n  UNUSED(isfp);\n#endif\n\n#define CALLBACK_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    ((float *)dp)[1] = *(float *)dp;\n\n#elif LJ_TARGET_MIPS64\n\n#if !LJ_ABI_SOFTFP\t/* MIPS64 hard-float */\n#define CALLBACK_HANDLE_REGARG \\\n  if (ngpr + n <= maxgpr) { \\\n    sp = isfp ? (void*) &cts->cb.fpr[ngpr] : (void*) &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  }\n#else\t\t\t/* MIPS64 soft-float */\n#define CALLBACK_HANDLE_REGARG \\\n  if (ngpr + n <= maxgpr) { \\\n    UNUSED(isfp); \\\n    sp = (void*) &cts->cb.gpr[ngpr]; \\\n    ngpr += n; \\\n    goto done; \\\n  }\n#endif\n\n#define CALLBACK_HANDLE_RET \\\n  if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \\\n    ((float *)dp)[1] = *(float *)dp;\n\n#else\n#error \"Missing calling convention definitions for this architecture\"\n#endif\n\n/* Convert and push callback arguments to Lua stack. */\nstatic void callback_conv_args(CTState *cts, lua_State *L)\n{\n  TValue *o = L->top;\n  intptr_t *stack = cts->cb.stack;\n  MSize slot = cts->cb.slot;\n  CTypeID id = 0, rid, fid;\n  int gcsteps = 0;\n  CType *ct;\n  GCfunc *fn;\n  int fntp;\n  MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR;\n#if CCALL_NARG_FPR\n  MSize nfpr = 0;\n#if LJ_TARGET_ARM\n  MSize fprodd = 0;\n#endif\n#endif\n\n  if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) {\n    ct = ctype_get(cts, id);\n    rid = ctype_cid(ct->info);  /* Return type. x86: +(spadj<<16). */\n    fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot));\n    fntp = LJ_TFUNC;\n  } else {  /* Must set up frame first, before throwing the error. */\n    ct = NULL;\n    rid = 0;\n    fn = (GCfunc *)L;\n    fntp = LJ_TTHREAD;\n  }\n  /* Continuation returns from callback. */\n  if (LJ_FR2) {\n    (o++)->u64 = LJ_CONT_FFI_CALLBACK;\n    (o++)->u64 = rid;\n  } else {\n    o->u32.lo = LJ_CONT_FFI_CALLBACK;\n    o->u32.hi = rid;\n    o++;\n  }\n  setframe_gc(o, obj2gco(fn), fntp);\n  if (LJ_FR2) o++;\n  setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT);\n  L->top = L->base = ++o;\n  if (!ct)\n    lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK);\n  if (isluafunc(fn))\n    setcframe_pc(L->cframe, proto_bc(funcproto(fn))+1);\n  lj_state_checkstack(L, LUA_MINSTACK);  /* May throw. */\n  o = L->base;  /* Might have been reallocated. */\n\n#if LJ_TARGET_X86\n  /* x86 has several different calling conventions. */\n  switch (ctype_cconv(ct->info)) {\n  case CTCC_FASTCALL: maxgpr = 2; break;\n  case CTCC_THISCALL: maxgpr = 1; break;\n  default: maxgpr = 0; break;\n  }\n#endif\n\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) {\n      CType *cta;\n      void *sp;\n      CTSize sz;\n      int isfp;\n      MSize n;\n      lj_assertCTS(ctype_isfield(ctf->info), \"field expected\");\n      cta = ctype_rawchild(cts, ctf);\n      isfp = ctype_isfp(cta->info);\n      sz = (cta->size + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);\n      n = sz / CTSIZE_PTR;  /* Number of GPRs or stack slots needed. */\n\n      CALLBACK_HANDLE_REGARG  /* Handle register arguments. */\n\n      /* Otherwise pass argument on stack. */\n      if (CCALL_ALIGN_STACKARG && LJ_32 && sz == 8)\n\tnsp = (nsp + 1) & ~1u;  /* Align 64 bit argument on stack. */\n      sp = &stack[nsp];\n      nsp += n;\n\n    done:\n      if (LJ_BE && cta->size < CTSIZE_PTR\n#if LJ_TARGET_MIPS64\n\t  && !(isfp && nsp)\n#endif\n\t )\n\tsp = (void *)((uint8_t *)sp + CTSIZE_PTR-cta->size);\n      gcsteps += lj_cconv_tv_ct(cts, cta, 0, o++, sp);\n    }\n    fid = ctf->sib;\n  }\n  L->top = o;\n#if LJ_TARGET_X86\n  /* Store stack adjustment for returns from non-cdecl callbacks. */\n  if (ctype_cconv(ct->info) != CTCC_CDECL) {\n#if LJ_FR2\n    (L->base-3)->u64 |= (nsp << (16+2));\n#else\n    (L->base-2)->u32.hi |= (nsp << (16+2));\n#endif\n  }\n#endif\n  while (gcsteps-- > 0)\n    lj_gc_check(L);\n}\n\n/* Convert Lua object to callback result. */\nstatic void callback_conv_result(CTState *cts, lua_State *L, TValue *o)\n{\n#if LJ_FR2\n  CType *ctr = ctype_raw(cts, (uint16_t)(L->base-3)->u64);\n#else\n  CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi);\n#endif\n#if LJ_TARGET_X86\n  cts->cb.gpr[2] = 0;\n#endif\n  if (!ctype_isvoid(ctr->info)) {\n    uint8_t *dp = (uint8_t *)&cts->cb.gpr[0];\n#if CCALL_NUM_FPR\n    if (ctype_isfp(ctr->info))\n      dp = (uint8_t *)&cts->cb.fpr[0];\n#endif\n#if LJ_TARGET_ARM64 && LJ_BE\n    if (ctype_isfp(ctr->info) && ctr->size == sizeof(float))\n      dp = (uint8_t *)&cts->cb.fpr[0].f[1];\n#endif\n    lj_cconv_ct_tv(cts, ctr, dp, o, 0);\n#ifdef CALLBACK_HANDLE_RET\n    CALLBACK_HANDLE_RET\n#endif\n    /* Extend returned integers to (at least) 32 bits. */\n    if (ctype_isinteger_or_bool(ctr->info) && ctr->size < 4) {\n      if (ctr->info & CTF_UNSIGNED)\n\t*(uint32_t *)dp = ctr->size == 1 ? (uint32_t)*(uint8_t *)dp :\n\t\t\t\t\t   (uint32_t)*(uint16_t *)dp;\n      else\n\t*(int32_t *)dp = ctr->size == 1 ? (int32_t)*(int8_t *)dp :\n\t\t\t\t\t  (int32_t)*(int16_t *)dp;\n    }\n#if LJ_TARGET_MIPS64 || (LJ_TARGET_ARM64 && LJ_BE)\n    /* Always sign-extend results to 64 bits. Even a soft-fp 'float'. */\n    if (ctr->size <= 4 &&\n\t(LJ_ABI_SOFTFP || ctype_isinteger_or_bool(ctr->info)))\n      *(int64_t *)dp = (int64_t)*(int32_t *)dp;\n#endif\n#if LJ_TARGET_X86\n    if (ctype_isfp(ctr->info))\n      cts->cb.gpr[2] = ctr->size == sizeof(float) ? 1 : 2;\n#endif\n  }\n}\n\n/* Enter callback. */\nlua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf)\n{\n  lua_State *L = cts->L;\n  global_State *g = cts->g;\n  lj_assertG(L != NULL, \"uninitialized cts->L in callback\");\n  if (tvref(g->jit_base)) {\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_FFI_BADCBACK));\n    if (g->panic) g->panic(L);\n    exit(EXIT_FAILURE);\n  }\n  lj_trace_abort(g);  /* Never record across callback. */\n  /* Setup C frame. */\n  cframe_prev(cf) = L->cframe;\n  setcframe_L(cf, L);\n  cframe_errfunc(cf) = -1;\n  cframe_nres(cf) = 0;\n  L->cframe = cf;\n  callback_conv_args(cts, L);\n  return L;  /* Now call the function on this stack. */\n}\n\n/* Leave callback. */\nvoid LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o)\n{\n  lua_State *L = cts->L;\n  GCfunc *fn;\n  TValue *obase = L->base;\n  L->base = L->top;  /* Keep continuation frame for throwing errors. */\n  if (o >= L->base) {\n    /* PC of RET* is lost. Point to last line for result conv. errors. */\n    fn = curr_func(L);\n    if (isluafunc(fn)) {\n      GCproto *pt = funcproto(fn);\n      setcframe_pc(L->cframe, proto_bc(pt)+pt->sizebc+1);\n    }\n  }\n  callback_conv_result(cts, L, o);\n  /* Finally drop C frame and continuation frame. */\n  L->top -= 2+2*LJ_FR2;\n  L->base = obase;\n  L->cframe = cframe_prev(L->cframe);\n  cts->cb.slot = 0;  /* Blacklist C function that called the callback. */\n}\n\n/* -- C callback management ----------------------------------------------- */\n\n/* Get an unused slot in the callback slot table. */\nstatic MSize callback_slot_new(CTState *cts, CType *ct)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  CTypeID1 *cbid = cts->cb.cbid;\n  MSize top;\n  for (top = cts->cb.topid; top < cts->cb.sizeid; top++)\n    if (LJ_LIKELY(cbid[top] == 0))\n      goto found;\n#if CALLBACK_MAX_SLOT\n  if (top >= CALLBACK_MAX_SLOT)\n#endif\n    lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);\n  if (!cts->cb.mcode)\n    callback_mcode_new(cts);\n  lj_mem_growvec(cts->L, cbid, cts->cb.sizeid, CALLBACK_MAX_SLOT, CTypeID1);\n  cts->cb.cbid = cbid;\n  memset(cbid+top, 0, (cts->cb.sizeid-top)*sizeof(CTypeID1));\nfound:\n  cbid[top] = id;\n  cts->cb.topid = top+1;\n  return top;\n}\n\n/* Check for function pointer and supported argument/result types. */\nstatic CType *callback_checkfunc(CTState *cts, CType *ct)\n{\n  int narg = 0;\n  if (!ctype_isptr(ct->info) || (LJ_64 && ct->size != CTSIZE_PTR))\n    return NULL;\n  ct = ctype_rawchild(cts, ct);\n  if (ctype_isfunc(ct->info)) {\n    CType *ctr = ctype_rawchild(cts, ct);\n    CTypeID fid = ct->sib;\n    if (!(ctype_isvoid(ctr->info) || ctype_isenum(ctr->info) ||\n\t  ctype_isptr(ctr->info) || (ctype_isnum(ctr->info) && ctr->size <= 8)))\n      return NULL;\n    if ((ct->info & CTF_VARARG))\n      return NULL;\n    while (fid) {\n      CType *ctf = ctype_get(cts, fid);\n      if (!ctype_isattrib(ctf->info)) {\n\tCType *cta;\n\tlj_assertCTS(ctype_isfield(ctf->info), \"field expected\");\n\tcta = ctype_rawchild(cts, ctf);\n\tif (!(ctype_isenum(cta->info) || ctype_isptr(cta->info) ||\n\t      (ctype_isnum(cta->info) && cta->size <= 8)) ||\n\t    ++narg >= LUA_MINSTACK-3)\n\t  return NULL;\n      }\n      fid = ctf->sib;\n    }\n    return ct;\n  }\n  return NULL;\n}\n\n/* Create a new callback and return the callback function pointer. */\nvoid *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn)\n{\n  ct = callback_checkfunc(cts, ct);\n  if (ct) {\n    MSize slot = callback_slot_new(cts, ct);\n    GCtab *t = cts->miscmap;\n    setfuncV(cts->L, lj_tab_setint(cts->L, t, (int32_t)slot), fn);\n    lj_gc_anybarriert(cts->L, t);\n    return callback_slot2ptr(cts, slot);\n  }\n  return NULL;  /* Bad conversion. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ccallback.h",
    "content": "/*\n** FFI C callback handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCALLBACK_H\n#define _LJ_CCALLBACK_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Really belongs to lj_vm.h. */\nLJ_ASMF void lj_vm_ffi_callback(void);\n\nLJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);\nLJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);\nLJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);\nLJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);\nLJ_FUNC void lj_ccallback_mcode_free(CTState *cts);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cconv.c",
    "content": "/*\n** C type conversions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cconv.h\"\n#include \"lj_ccallback.h\"\n\n/* -- Conversion errors --------------------------------------------------- */\n\n/* Bad conversion. */\nLJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s,\n\t\t\t\t    CTInfo flags)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  const char *src;\n  if ((flags & CCF_FROMTV))\n    src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER :\n\t\t\t     ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)];\n  else\n    src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL));\n  if (CCF_GETARG(flags))\n    lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);\n  else\n    lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);\n}\n\n/* Bad conversion from TValue. */\nLJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o,\n\t\t\t\t      CTInfo flags)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  const char *src = lj_typename(o);\n  if (CCF_GETARG(flags))\n    lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);\n  else\n    lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);\n}\n\n/* Initializer overflow. */\nLJ_NORET static void cconv_err_initov(CTState *cts, CType *d)\n{\n  const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));\n  lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst);\n}\n\n/* -- C type compatibility checks ----------------------------------------- */\n\n/* Get raw type and qualifiers for a child type. Resolves enums, too. */\nstatic CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual)\n{\n  ct = ctype_child(cts, ct);\n  for (;;) {\n    if (ctype_isattrib(ct->info)) {\n      if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;\n    } else if (!ctype_isenum(ct->info)) {\n      break;\n    }\n    ct = ctype_child(cts, ct);\n  }\n  *qual |= (ct->info & CTF_QUAL);\n  return ct;\n}\n\n/* Check for compatible types when converting to a pointer.\n** Note: these checks are more relaxed than what C99 mandates.\n*/\nint lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags)\n{\n  if (!((flags & CCF_CAST) || d == s)) {\n    CTInfo dqual = 0, squal = 0;\n    d = cconv_childqual(cts, d, &dqual);\n    if (!ctype_isstruct(s->info))\n      s = cconv_childqual(cts, s, &squal);\n    if ((flags & CCF_SAME)) {\n      if (dqual != squal)\n\treturn 0;  /* Different qualifiers. */\n    } else if (!(flags & CCF_IGNQUAL)) {\n      if ((dqual & squal) != squal)\n\treturn 0;  /* Discarded qualifiers. */\n      if (ctype_isvoid(d->info) || ctype_isvoid(s->info))\n\treturn 1;  /* Converting to/from void * is always ok. */\n    }\n    if (ctype_type(d->info) != ctype_type(s->info) ||\n\td->size != s->size)\n      return 0;  /* Different type or different size. */\n    if (ctype_isnum(d->info)) {\n      if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP)))\n\treturn 0;  /* Different numeric types. */\n    } else if (ctype_ispointer(d->info)) {\n      /* Check child types for compatibility. */\n      return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME);\n    } else if (ctype_isstruct(d->info)) {\n      if (d != s)\n\treturn 0;  /* Must be exact same type for struct/union. */\n    } else if (ctype_isfunc(d->info)) {\n      /* NYI: structural equality of functions. */\n    }\n  }\n  return 1;  /* Types are compatible. */\n}\n\n/* -- C type to C type conversion ----------------------------------------- */\n\n/* Convert C type to C type. Caveat: expects to get the raw CType!\n**\n** Note: This is only used by the interpreter and not optimized at all.\n** The JIT compiler will do a much better job specializing for each case.\n*/\nvoid lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,\n\t\t    uint8_t *dp, uint8_t *sp, CTInfo flags)\n{\n  CTSize dsize = d->size, ssize = s->size;\n  CTInfo dinfo = d->info, sinfo = s->info;\n  void *tmpptr;\n\n  lj_assertCTS(!ctype_isenum(dinfo) && !ctype_isenum(sinfo),\n\t       \"unresolved enum\");\n  lj_assertCTS(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo),\n\t       \"unstripped attribute\");\n\n  if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)\n    goto err_conv;\n\n  /* Some basic sanity checks. */\n  lj_assertCTS(!ctype_isnum(dinfo) || dsize > 0, \"bad size for number type\");\n  lj_assertCTS(!ctype_isnum(sinfo) || ssize > 0, \"bad size for number type\");\n  lj_assertCTS(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4,\n\t       \"bad size for bool type\");\n  lj_assertCTS(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4,\n\t       \"bad size for bool type\");\n  lj_assertCTS(!ctype_isinteger(dinfo) || (1u<<lj_fls(dsize)) == dsize,\n\t       \"bad size for integer type\");\n  lj_assertCTS(!ctype_isinteger(sinfo) || (1u<<lj_fls(ssize)) == ssize,\n\t       \"bad size for integer type\");\n\n  switch (cconv_idx2(dinfo, sinfo)) {\n  /* Destination is a bool. */\n  case CCX(B, B):\n    /* Source operand is already normalized. */\n    if (dsize == 1) *dp = *sp; else *(int *)dp = *sp;\n    break;\n  case CCX(B, I): {\n    MSize i;\n    uint8_t b = 0;\n    for (i = 0; i < ssize; i++) b |= sp[i];\n    b = (b != 0);\n    if (dsize == 1) *dp = b; else *(int *)dp = b;\n    break;\n    }\n  case CCX(B, F): {\n    uint8_t b;\n    if (ssize == sizeof(double)) b = (*(double *)sp != 0);\n    else if (ssize == sizeof(float)) b = (*(float *)sp != 0);\n    else goto err_conv;  /* NYI: long double. */\n    if (dsize == 1) *dp = b; else *(int *)dp = b;\n    break;\n    }\n\n  /* Destination is an integer. */\n  case CCX(I, B):\n  case CCX(I, I):\n  conv_I_I:\n    if (dsize > ssize) {  /* Zero-extend or sign-extend LSB. */\n#if LJ_LE\n      uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0;\n      memcpy(dp, sp, ssize);\n      memset(dp + ssize, fill, dsize-ssize);\n#else\n      uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0;\n      memset(dp, fill, dsize-ssize);\n      memcpy(dp + (dsize-ssize), sp, ssize);\n#endif\n    } else {  /* Copy LSB. */\n#if LJ_LE\n      memcpy(dp, sp, dsize);\n#else\n      memcpy(dp, sp + (ssize-dsize), dsize);\n#endif\n    }\n    break;\n  case CCX(I, F): {\n    double n;  /* Always convert via double. */\n  conv_I_F:\n    /* Convert source to double. */\n    if (ssize == sizeof(double)) n = *(double *)sp;\n    else if (ssize == sizeof(float)) n = (double)*(float *)sp;\n    else goto err_conv;  /* NYI: long double. */\n    /* Then convert double to integer. */\n    /* The conversion must exactly match the semantics of JIT-compiled code! */\n    if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) {\n      int32_t i = (int32_t)n;\n      if (dsize == 4) *(int32_t *)dp = i;\n      else if (dsize == 2) *(int16_t *)dp = (int16_t)i;\n      else *(int8_t *)dp = (int8_t)i;\n    } else if (dsize == 4) {\n      *(uint32_t *)dp = (uint32_t)n;\n    } else if (dsize == 8) {\n      if (!(dinfo & CTF_UNSIGNED))\n\t*(int64_t *)dp = (int64_t)n;\n      else\n\t*(uint64_t *)dp = lj_num2u64(n);\n    } else {\n      goto err_conv;  /* NYI: conversion to >64 bit integers. */\n    }\n    break;\n    }\n  case CCX(I, C):\n    s = ctype_child(cts, s);\n    sinfo = s->info;\n    ssize = s->size;\n    goto conv_I_F;  /* Just convert re. */\n  case CCX(I, P):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    goto conv_I_I;\n  case CCX(I, A):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    ssize = CTSIZE_PTR;\n    tmpptr = sp;\n    sp = (uint8_t *)&tmpptr;\n    goto conv_I_I;\n\n  /* Destination is a floating-point number. */\n  case CCX(F, B):\n  case CCX(F, I): {\n    double n;  /* Always convert via double. */\n  conv_F_I:\n    /* First convert source to double. */\n    /* The conversion must exactly match the semantics of JIT-compiled code! */\n    if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) {\n      int32_t i;\n      if (ssize == 4) {\n\ti = *(int32_t *)sp;\n      } else if (!(sinfo & CTF_UNSIGNED)) {\n\tif (ssize == 2) i = *(int16_t *)sp;\n\telse i = *(int8_t *)sp;\n      } else {\n\tif (ssize == 2) i = *(uint16_t *)sp;\n\telse i = *(uint8_t *)sp;\n      }\n      n = (double)i;\n    } else if (ssize == 4) {\n      n = (double)*(uint32_t *)sp;\n    } else if (ssize == 8) {\n      if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp;\n      else n = (double)*(uint64_t *)sp;\n    } else {\n      goto err_conv;  /* NYI: conversion from >64 bit integers. */\n    }\n    /* Convert double to destination. */\n    if (dsize == sizeof(double)) *(double *)dp = n;\n    else if (dsize == sizeof(float)) *(float *)dp = (float)n;\n    else goto err_conv;  /* NYI: long double. */\n    break;\n    }\n  case CCX(F, F): {\n    double n;  /* Always convert via double. */\n  conv_F_F:\n    if (ssize == dsize) goto copyval;\n    /* Convert source to double. */\n    if (ssize == sizeof(double)) n = *(double *)sp;\n    else if (ssize == sizeof(float)) n = (double)*(float *)sp;\n    else goto err_conv;  /* NYI: long double. */\n    /* Convert double to destination. */\n    if (dsize == sizeof(double)) *(double *)dp = n;\n    else if (dsize == sizeof(float)) *(float *)dp = (float)n;\n    else goto err_conv;  /* NYI: long double. */\n    break;\n    }\n  case CCX(F, C):\n    s = ctype_child(cts, s);\n    sinfo = s->info;\n    ssize = s->size;\n    goto conv_F_F;  /* Ignore im, and convert from re. */\n\n  /* Destination is a complex number. */\n  case CCX(C, I):\n    d = ctype_child(cts, d);\n    dinfo = d->info;\n    dsize = d->size;\n    memset(dp + dsize, 0, dsize);  /* Clear im. */\n    goto conv_F_I;  /* Convert to re. */\n  case CCX(C, F):\n    d = ctype_child(cts, d);\n    dinfo = d->info;\n    dsize = d->size;\n    memset(dp + dsize, 0, dsize);  /* Clear im. */\n    goto conv_F_F;  /* Convert to re. */\n\n  case CCX(C, C):\n    if (dsize != ssize) {  /* Different types: convert re/im separately. */\n      CType *dc = ctype_child(cts, d);\n      CType *sc = ctype_child(cts, s);\n      lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags);\n      lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags);\n      return;\n    }\n    goto copyval;  /* Otherwise this is easy. */\n\n  /* Destination is a vector. */\n  case CCX(V, I):\n  case CCX(V, F):\n  case CCX(V, C): {\n    CType *dc = ctype_child(cts, d);\n    CTSize esize;\n    /* First convert the scalar to the first element. */\n    lj_cconv_ct_ct(cts, dc, s, dp, sp, flags);\n    /* Then replicate it to the other elements (splat). */\n    for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) {\n      dp += esize;\n      memcpy(dp, sp, esize);\n    }\n    break;\n    }\n\n  case CCX(V, V):\n    /* Copy same-sized vectors, even for different lengths/element-types. */\n    if (dsize != ssize) goto err_conv;\n    goto copyval;\n\n  /* Destination is a pointer. */\n  case CCX(P, I):\n    if (!(flags & CCF_CAST)) goto err_conv;\n    dinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    goto conv_I_I;\n\n  case CCX(P, F):\n    if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv;\n    /* The signed conversion is cheaper. x64 really has 47 bit pointers. */\n    dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED);\n    goto conv_I_F;\n\n  case CCX(P, P):\n    if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;\n    cdata_setptr(dp, dsize, cdata_getptr(sp, ssize));\n    break;\n\n  case CCX(P, A):\n  case CCX(P, S):\n    if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;\n    cdata_setptr(dp, dsize, sp);\n    break;\n\n  /* Destination is an array. */\n  case CCX(A, A):\n    if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize ||\n\td->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))\n      goto err_conv;\n    goto copyval;\n\n  /* Destination is a struct/union. */\n  case CCX(S, S):\n    if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s)\n      goto err_conv;  /* Must be exact same type. */\ncopyval:  /* Copy value. */\n    lj_assertCTS(dsize == ssize, \"value copy with different sizes\");\n    memcpy(dp, sp, dsize);\n    break;\n\n  default:\n  err_conv:\n    cconv_err_conv(cts, d, s, flags);\n  }\n}\n\n/* -- C type to TValue conversion ----------------------------------------- */\n\n/* Convert C type to TValue. Caveat: expects to get the raw CType! */\nint lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,\n\t\t   TValue *o, uint8_t *sp)\n{\n  CTInfo sinfo = s->info;\n  if (ctype_isnum(sinfo)) {\n    if (!ctype_isbool(sinfo)) {\n      if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;\n      if (LJ_DUALNUM && ctype_isinteger(sinfo)) {\n\tint32_t i;\n\tlj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s,\n\t\t       (uint8_t *)&i, sp, 0);\n\tif ((sinfo & CTF_UNSIGNED) && i < 0)\n\t  setnumV(o, (lua_Number)(uint32_t)i);\n\telse\n\t  setintV(o, i);\n      } else {\n\tlj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s,\n\t\t       (uint8_t *)&o->n, sp, 0);\n\t/* Numbers are NOT canonicalized here! Beware of uninitialized data. */\n\tlj_assertCTS(tvisnum(o), \"non-canonical NaN passed\");\n      }\n    } else {\n      uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0);\n      setboolV(o, b);\n      setboolV(&cts->g->tmptv2, b);  /* Remember for trace recorder. */\n    }\n    return 0;\n  } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {\n    /* Create reference. */\n    setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid));\n    return 1;  /* Need GC step. */\n  } else {\n    GCcdata *cd;\n    CTSize sz;\n  copyval:  /* Copy value. */\n    sz = s->size;\n    lj_assertCTS(sz != CTSIZE_INVALID, \"value copy with invalid size\");\n    /* Attributes are stripped, qualifiers are kept (but mostly ignored). */\n    cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz);\n    setcdataV(cts->L, o, cd);\n    memcpy(cdataptr(cd), sp, sz);\n    return 1;  /* Need GC step. */\n  }\n}\n\n/* Convert bitfield to TValue. */\nint lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp)\n{\n  CTInfo info = s->info;\n  CTSize pos, bsz;\n  uint32_t val;\n  lj_assertCTS(ctype_isbitfield(info), \"bitfield expected\");\n  /* NYI: packed bitfields may cause misaligned reads. */\n  switch (ctype_bitcsz(info)) {\n  case 4: val = *(uint32_t *)sp; break;\n  case 2: val = *(uint16_t *)sp; break;\n  case 1: val = *(uint8_t *)sp; break;\n  default:\n    lj_assertCTS(0, \"bad bitfield container size %d\", ctype_bitcsz(info));\n    val = 0;\n    break;\n  }\n  /* Check if a packed bitfield crosses a container boundary. */\n  pos = ctype_bitpos(info);\n  bsz = ctype_bitbsz(info);\n  lj_assertCTS(pos < 8*ctype_bitcsz(info), \"bad bitfield position\");\n  lj_assertCTS(bsz > 0 && bsz <= 8*ctype_bitcsz(info), \"bad bitfield size\");\n  if (pos + bsz > 8*ctype_bitcsz(info))\n    lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);\n  if (!(info & CTF_BOOL)) {\n    CTSize shift = 32 - bsz;\n    if (!(info & CTF_UNSIGNED)) {\n      setintV(o, (int32_t)(val << (shift-pos)) >> shift);\n    } else {\n      val = (val << (shift-pos)) >> shift;\n      if (!LJ_DUALNUM || (int32_t)val < 0)\n\tsetnumV(o, (lua_Number)(uint32_t)val);\n      else\n\tsetintV(o, (int32_t)val);\n    }\n  } else {\n    uint32_t b = (val >> pos) & 1;\n    lj_assertCTS(bsz == 1, \"bad bool bitfield size\");\n    setboolV(o, b);\n    setboolV(&cts->g->tmptv2, b);  /* Remember for trace recorder. */\n  }\n  return 0;  /* No GC step needed. */\n}\n\n/* -- TValue to C type conversion ----------------------------------------- */\n\n/* Convert table to array. */\nstatic void cconv_array_tab(CTState *cts, CType *d,\n\t\t\t    uint8_t *dp, GCtab *t, CTInfo flags)\n{\n  int32_t i;\n  CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n  CTSize size = d->size, esize = dc->size, ofs = 0;\n  for (i = 0; ; i++) {\n    TValue *tv = (TValue *)lj_tab_getint(t, i);\n    if (!tv || tvisnil(tv)) {\n      if (i == 0) continue;  /* Try again for 1-based tables. */\n      break;  /* Stop at first nil. */\n    }\n    if (ofs >= size)\n      cconv_err_initov(cts, d);\n    lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags);\n    ofs += esize;\n  }\n  if (size != CTSIZE_INVALID) {  /* Only fill up arrays with known size. */\n    if (ofs == esize) {  /* Replicate a single element. */\n      for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize);\n    } else {  /* Otherwise fill the remainder with zero. */\n      memset(dp + ofs, 0, size - ofs);\n    }\n  }\n}\n\n/* Convert table to sub-struct/union. */\nstatic void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp,\n\t\t\t\tGCtab *t, int32_t *ip, CTInfo flags)\n{\n  CTypeID id = d->sib;\n  while (id) {\n    CType *df = ctype_get(cts, id);\n    id = df->sib;\n    if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {\n      TValue *tv;\n      int32_t i = *ip, iz = i;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      if (i >= 0) {\n      retry:\n\ttv = (TValue *)lj_tab_getint(t, i);\n\tif (!tv || tvisnil(tv)) {\n\t  if (i == 0) { i = 1; goto retry; }  /* 1-based tables. */\n\t  if (iz == 0) { *ip = i = -1; goto tryname; }  /* Init named fields. */\n\t  break;  /* Stop at first nil. */\n\t}\n\t*ip = i + 1;\n      } else {\n      tryname:\n\ttv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name)));\n\tif (!tv || tvisnil(tv)) continue;\n      }\n      if (ctype_isfield(df->info))\n\tlj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags);\n      else\n\tlj_cconv_bf_tv(cts, df, dp+df->size, tv);\n      if ((d->info & CTF_UNION)) break;\n    } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {\n      cconv_substruct_tab(cts, ctype_rawchild(cts, df),\n\t\t\t  dp+df->size, t, ip, flags);\n    }  /* Ignore all other entries in the chain. */\n  }\n}\n\n/* Convert table to struct/union. */\nstatic void cconv_struct_tab(CTState *cts, CType *d,\n\t\t\t     uint8_t *dp, GCtab *t, CTInfo flags)\n{\n  int32_t i = 0;\n  memset(dp, 0, d->size);  /* Much simpler to clear the struct first. */\n  cconv_substruct_tab(cts, d, dp, t, &i, flags);\n}\n\n/* Convert TValue to C type. Caveat: expects to get the raw CType! */\nvoid lj_cconv_ct_tv(CTState *cts, CType *d,\n\t\t    uint8_t *dp, TValue *o, CTInfo flags)\n{\n  CTypeID sid = CTID_P_VOID;\n  CType *s;\n  void *tmpptr;\n  uint8_t tmpbool, *sp = (uint8_t *)&tmpptr;\n  if (LJ_LIKELY(tvisint(o))) {\n    sp = (uint8_t *)&o->i;\n    sid = CTID_INT32;\n    flags |= CCF_FROMTV;\n  } else if (LJ_LIKELY(tvisnum(o))) {\n    sp = (uint8_t *)&o->n;\n    sid = CTID_DOUBLE;\n    flags |= CCF_FROMTV;\n  } else if (tviscdata(o)) {\n    sp = cdataptr(cdataV(o));\n    sid = cdataV(o)->ctypeid;\n    s = ctype_get(cts, sid);\n    if (ctype_isref(s->info)) {  /* Resolve reference for value. */\n      lj_assertCTS(s->size == CTSIZE_PTR, \"ref is not pointer-sized\");\n      sp = *(void **)sp;\n      sid = ctype_cid(s->info);\n    }\n    s = ctype_raw(cts, sid);\n    if (ctype_isfunc(s->info)) {\n      CTypeID did = ctype_typeid(cts, d);\n      sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);\n      d = ctype_get(cts, did);  /* cts->tab may have been reallocated. */\n    } else {\n      if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n      goto doconv;\n    }\n  } else if (tvisstr(o)) {\n    GCstr *str = strV(o);\n    if (ctype_isenum(d->info)) {  /* Match string against enum constant. */\n      CTSize ofs;\n      CType *cct = lj_ctype_getfield(cts, d, str, &ofs);\n      if (!cct || !ctype_isconstval(cct->info))\n\tgoto err_conv;\n      lj_assertCTS(d->size == 4, \"only 32 bit enum supported\");  /* NYI */\n      sp = (uint8_t *)&cct->size;\n      sid = ctype_cid(cct->info);\n    } else if (ctype_isrefarray(d->info)) {  /* Copy string to array. */\n      CType *dc = ctype_rawchild(cts, d);\n      CTSize sz = str->len+1;\n      if (!ctype_isinteger(dc->info) || dc->size != 1)\n\tgoto err_conv;\n      if (d->size != 0 && d->size < sz)\n\tsz = d->size;\n      memcpy(dp, strdata(str), sz);\n      return;\n    } else {  /* Otherwise pass it as a const char[]. */\n      sp = (uint8_t *)strdata(str);\n      sid = CTID_A_CCHAR;\n      flags |= CCF_FROMTV;\n    }\n  } else if (tvistab(o)) {\n    if (ctype_isarray(d->info)) {\n      cconv_array_tab(cts, d, dp, tabV(o), flags);\n      return;\n    } else if (ctype_isstruct(d->info)) {\n      cconv_struct_tab(cts, d, dp, tabV(o), flags);\n      return;\n    } else {\n      goto err_conv;\n    }\n  } else if (tvisbool(o)) {\n    tmpbool = boolV(o);\n    sp = &tmpbool;\n    sid = CTID_BOOL;\n  } else if (tvisnil(o)) {\n    tmpptr = (void *)0;\n    flags |= CCF_FROMTV;\n  } else if (tvisudata(o)) {\n    GCudata *ud = udataV(o);\n    tmpptr = uddata(ud);\n    if (ud->udtype == UDTYPE_IO_FILE)\n      tmpptr = *(void **)tmpptr;\n    else if (ud->udtype == UDTYPE_BUFFER)\n      tmpptr = ((SBufExt *)tmpptr)->r;\n  } else if (tvislightud(o)) {\n    tmpptr = lightudV(cts->g, o);\n  } else if (tvisfunc(o)) {\n    void *p = lj_ccallback_new(cts, d, funcV(o));\n    if (p) {\n      *(void **)dp = p;\n      return;\n    }\n    goto err_conv;\n  } else {\n  err_conv:\n    cconv_err_convtv(cts, d, o, flags);\n  }\n  s = ctype_get(cts, sid);\ndoconv:\n  if (ctype_isenum(d->info)) d = ctype_child(cts, d);\n  lj_cconv_ct_ct(cts, d, s, dp, sp, flags);\n}\n\n/* Convert TValue to bitfield. */\nvoid lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o)\n{\n  CTInfo info = d->info;\n  CTSize pos, bsz;\n  uint32_t val, mask;\n  lj_assertCTS(ctype_isbitfield(info), \"bitfield expected\");\n  if ((info & CTF_BOOL)) {\n    uint8_t tmpbool;\n    lj_assertCTS(ctype_bitbsz(info) == 1, \"bad bool bitfield size\");\n    lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0);\n    val = tmpbool;\n  } else {\n    CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32;\n    lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0);\n  }\n  pos = ctype_bitpos(info);\n  bsz = ctype_bitbsz(info);\n  lj_assertCTS(pos < 8*ctype_bitcsz(info), \"bad bitfield position\");\n  lj_assertCTS(bsz > 0 && bsz <= 8*ctype_bitcsz(info), \"bad bitfield size\");\n  /* Check if a packed bitfield crosses a container boundary. */\n  if (pos + bsz > 8*ctype_bitcsz(info))\n    lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);\n  mask = ((1u << bsz) - 1u) << pos;\n  val = (val << pos) & mask;\n  /* NYI: packed bitfields may cause misaligned reads/writes. */\n  switch (ctype_bitcsz(info)) {\n  case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break;\n  case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break;\n  case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break;\n  default:\n    lj_assertCTS(0, \"bad bitfield container size %d\", ctype_bitcsz(info));\n    break;\n  }\n}\n\n/* -- Initialize C type with TValues -------------------------------------- */\n\n/* Initialize an array with TValues. */\nstatic void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,\n\t\t\t     TValue *o, MSize len)\n{\n  CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n  CTSize ofs, esize = dc->size;\n  MSize i;\n  if (len*esize > sz)\n    cconv_err_initov(cts, d);\n  for (i = 0, ofs = 0; i < len; i++, ofs += esize)\n    lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0);\n  if (ofs == esize) {  /* Replicate a single element. */\n    for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize);\n  } else {  /* Otherwise fill the remainder with zero. */\n    memset(dp + ofs, 0, sz - ofs);\n  }\n}\n\n/* Initialize a sub-struct/union with TValues. */\nstatic void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp,\n\t\t\t\t TValue *o, MSize len, MSize *ip)\n{\n  CTypeID id = d->sib;\n  while (id) {\n    CType *df = ctype_get(cts, id);\n    id = df->sib;\n    if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {\n      MSize i = *ip;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      if (i >= len) break;\n      *ip = i + 1;\n      if (ctype_isfield(df->info))\n\tlj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0);\n      else\n\tlj_cconv_bf_tv(cts, df, dp+df->size, o + i);\n      if ((d->info & CTF_UNION)) break;\n    } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {\n      cconv_substruct_init(cts, ctype_rawchild(cts, df),\n\t\t\t   dp+df->size, o, len, ip);\n      if ((d->info & CTF_UNION)) break;\n    }  /* Ignore all other entries in the chain. */\n  }\n}\n\n/* Initialize a struct/union with TValues. */\nstatic void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,\n\t\t\t      TValue *o, MSize len)\n{\n  MSize i = 0;\n  memset(dp, 0, sz);  /* Much simpler to clear the struct first. */\n  cconv_substruct_init(cts, d, dp, o, len, &i);\n  if (i < len)\n    cconv_err_initov(cts, d);\n}\n\n/* Check whether to use a multi-value initializer.\n** This is true if an aggregate is to be initialized with a value.\n** Valarrays are treated as values here so ct_tv handles (V|C, I|F).\n*/\nint lj_cconv_multi_init(CTState *cts, CType *d, TValue *o)\n{\n  if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))\n    return 0;  /* Destination is not an aggregate. */\n  if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))\n    return 0;  /* Initializer is not a value. */\n  if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d)\n    return 0;  /* Source and destination are identical aggregates. */\n  return 1;  /* Otherwise the initializer is a value. */\n}\n\n/* Initialize C type with TValues. Caveat: expects to get the raw CType! */\nvoid lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,\n\t\t      uint8_t *dp, TValue *o, MSize len)\n{\n  if (len == 0)\n    memset(dp, 0, sz);\n  else if (len == 1 && !lj_cconv_multi_init(cts, d, o))\n    lj_cconv_ct_tv(cts, d, dp, o, 0);\n  else if (ctype_isarray(d->info))  /* Also handles valarray init with len>1. */\n    cconv_array_init(cts, d, sz, dp, o, len);\n  else if (ctype_isstruct(d->info))\n    cconv_struct_init(cts, d, sz, dp, o, len);\n  else\n    cconv_err_initov(cts, d);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cconv.h",
    "content": "/*\n** C type conversions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CCONV_H\n#define _LJ_CCONV_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Compressed C type index. ORDER CCX. */\nenum {\n  CCX_B,\t/* Bool. */\n  CCX_I,\t/* Integer. */\n  CCX_F,\t/* Floating-point number. */\n  CCX_C,\t/* Complex. */\n  CCX_V,\t/* Vector. */\n  CCX_P,\t/* Pointer. */\n  CCX_A,\t/* Refarray. */\n  CCX_S\t\t/* Struct/union. */\n};\n\n/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */\nstatic LJ_AINLINE uint32_t cconv_idx(CTInfo info)\n{\n  uint32_t idx = ((info >> 26) & 15u);  /* Dispatch bits. */\n  lj_assertX(ctype_type(info) <= CT_MAYCONVERT,\n\t     \"cannot convert ctype %08x\", info);\n#if LJ_64\n  idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);\n#else\n  idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);\n#endif\n  lj_assertX(idx < 8, \"cannot convert ctype %08x\", info);\n  return idx;\n}\n\n#define cconv_idx2(dinfo, sinfo) \\\n  ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))\n\n#define CCX(dst, src)\t\t((CCX_##dst << 3) + CCX_##src)\n\n/* Conversion flags. */\n#define CCF_CAST\t0x00000001u\n#define CCF_FROMTV\t0x00000002u\n#define CCF_SAME\t0x00000004u\n#define CCF_IGNQUAL\t0x00000008u\n\n#define CCF_ARG_SHIFT\t8\n#define CCF_ARG(n)\t((n) << CCF_ARG_SHIFT)\n#define CCF_GETARG(f)\t((f) >> CCF_ARG_SHIFT)\n\nLJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);\nLJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,\n\t\t\t    uint8_t *dp, uint8_t *sp, CTInfo flags);\nLJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,\n\t\t\t   TValue *o, uint8_t *sp);\nLJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);\nLJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,\n\t\t\t    uint8_t *dp, TValue *o, CTInfo flags);\nLJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);\nLJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);\nLJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,\n\t\t\t      uint8_t *dp, TValue *o, MSize len);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cdata.c",
    "content": "/*\n** C data management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n\n/* -- C data allocation --------------------------------------------------- */\n\n/* Allocate a new C data object holding a reference to another object. */\nGCcdata *lj_cdata_newref(CTState *cts, const void *p, CTypeID id)\n{\n  CTypeID refid = lj_ctype_intern(cts, CTINFO_REF(id), CTSIZE_PTR);\n  GCcdata *cd = lj_cdata_new(cts, refid, CTSIZE_PTR);\n  *(const void **)cdataptr(cd) = p;\n  return cd;\n}\n\n/* Allocate variable-sized or specially aligned C data object. */\nGCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz, CTSize align)\n{\n  global_State *g;\n  MSize extra = sizeof(GCcdataVar) + sizeof(GCcdata) +\n\t\t(align > CT_MEMALIGN ? (1u<<align) - (1u<<CT_MEMALIGN) : 0);\n  char *p = lj_mem_newt(L, extra + sz, char);\n  uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata);\n  uintptr_t almask = (1u << align) - 1u;\n  GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata));\n  lj_assertL((char *)cd - p < 65536, \"excessive cdata alignment\");\n  cdatav(cd)->offset = (uint16_t)((char *)cd - p);\n  cdatav(cd)->extra = extra;\n  cdatav(cd)->len = sz;\n  g = G(L);\n  setgcrefr(cd->nextgc, g->gc.root);\n  setgcref(g->gc.root, obj2gco(cd));\n  newwhite(g, obj2gco(cd));\n  cd->marked |= 0x80;\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = id;\n  return cd;\n}\n\n/* Allocate arbitrary C data object. */\nGCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz, CTInfo info)\n{\n  if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN)\n    return lj_cdata_new(cts, id, sz);\n  else\n    return lj_cdata_newv(cts->L, id, sz, ctype_align(info));\n}\n\n/* Free a C data object. */\nvoid LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)\n{\n  if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) {\n    GCobj *root;\n    makewhite(g, obj2gco(cd));\n    markfinalized(obj2gco(cd));\n    if ((root = gcref(g->gc.mmudata)) != NULL) {\n      setgcrefr(cd->nextgc, root->gch.nextgc);\n      setgcref(root->gch.nextgc, obj2gco(cd));\n      setgcref(g->gc.mmudata, obj2gco(cd));\n    } else {\n      setgcref(cd->nextgc, obj2gco(cd));\n      setgcref(g->gc.mmudata, obj2gco(cd));\n    }\n  } else if (LJ_LIKELY(!cdataisv(cd))) {\n    CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid);\n    CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR;\n    lj_assertG(ctype_hassize(ct->info) || ctype_isfunc(ct->info) ||\n\t       ctype_isextern(ct->info), \"free of ctype without a size\");\n    lj_mem_free(g, cd, sizeof(GCcdata) + sz);\n  } else {\n    lj_mem_free(g, memcdatav(cd), sizecdatav(cd));\n  }\n}\n\nvoid lj_cdata_setfin(lua_State *L, GCcdata *cd, GCobj *obj, uint32_t it)\n{\n  GCtab *t = ctype_ctsG(G(L))->finalizer;\n  if (gcref(t->metatable)) {\n    /* Add cdata to finalizer table, if still enabled. */\n    TValue *tv, tmp;\n    setcdataV(L, &tmp, cd);\n    lj_gc_anybarriert(L, t);\n    tv = lj_tab_set(L, t, &tmp);\n    if (it == LJ_TNIL) {\n      setnilV(tv);\n      cd->marked &= ~LJ_GC_CDATA_FIN;\n    } else {\n      setgcV(L, tv, obj, it);\n      cd->marked |= LJ_GC_CDATA_FIN;\n    }\n  }\n}\n\n/* -- C data indexing ----------------------------------------------------- */\n\n/* Index C data by a TValue. Return CType and pointer. */\nCType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,\n\t\t      CTInfo *qual)\n{\n  uint8_t *p = (uint8_t *)cdataptr(cd);\n  CType *ct = ctype_get(cts, cd->ctypeid);\n  ptrdiff_t idx;\n\n  /* Resolve reference for cdata object. */\n  if (ctype_isref(ct->info)) {\n    lj_assertCTS(ct->size == CTSIZE_PTR, \"ref is not pointer-sized\");\n    p = *(uint8_t **)p;\n    ct = ctype_child(cts, ct);\n  }\n\ncollect_attrib:\n  /* Skip attributes and collect qualifiers. */\n  while (ctype_isattrib(ct->info)) {\n    if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;\n    ct = ctype_child(cts, ct);\n  }\n  /* Interning rejects refs to refs. */\n  lj_assertCTS(!ctype_isref(ct->info), \"bad ref of ref\");\n\n  if (tvisint(key)) {\n    idx = (ptrdiff_t)intV(key);\n    goto integer_key;\n  } else if (tvisnum(key)) {  /* Numeric key. */\n#ifdef _MSC_VER\n    /* Workaround for MSVC bug. */\n    volatile\n#endif\n    lua_Number n = numV(key);\n    idx = LJ_64 ? (ptrdiff_t)n : (ptrdiff_t)lj_num2int(n);\n  integer_key:\n    if (ctype_ispointer(ct->info)) {\n      CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info));  /* Element size. */\n      if (sz == CTSIZE_INVALID)\n\tlj_err_caller(cts->L, LJ_ERR_FFI_INVSIZE);\n      if (ctype_isptr(ct->info)) {\n\tp = (uint8_t *)cdata_getptr(p, ct->size);\n      } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {\n\tif ((ct->info & CTF_COMPLEX)) idx &= 1;\n\t*qual |= CTF_CONST;  /* Valarray elements are constant. */\n      }\n      *pp = p + idx*(int32_t)sz;\n      return ct;\n    }\n  } else if (tviscdata(key)) {  /* Integer cdata key. */\n    GCcdata *cdk = cdataV(key);\n    CType *ctk = ctype_raw(cts, cdk->ctypeid);\n    if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk);\n    if (ctype_isinteger(ctk->info)) {\n      lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk,\n\t\t     (uint8_t *)&idx, cdataptr(cdk), 0);\n      goto integer_key;\n    }\n  } else if (tvisstr(key)) {  /* String key. */\n    GCstr *name = strV(key);\n    if (ctype_isstruct(ct->info)) {\n      CTSize ofs;\n      CType *fct = lj_ctype_getfieldq(cts, ct, name, &ofs, qual);\n      if (fct) {\n\t*pp = p + ofs;\n\treturn fct;\n      }\n    } else if (ctype_iscomplex(ct->info)) {\n      if (name->len == 2) {\n\t*qual |= CTF_CONST;  /* Complex fields are constant. */\n\tif (strdata(name)[0] == 'r' && strdata(name)[1] == 'e') {\n\t  *pp = p;\n\t  return ct;\n\t} else if (strdata(name)[0] == 'i' && strdata(name)[1] == 'm') {\n\t  *pp = p + (ct->size >> 1);\n\t  return ct;\n\t}\n      }\n    } else if (cd->ctypeid == CTID_CTYPEID) {\n      /* Allow indexing a (pointer to) struct constructor to get constants. */\n      CType *sct = ctype_raw(cts, *(CTypeID *)p);\n      if (ctype_isptr(sct->info))\n\tsct = ctype_rawchild(cts, sct);\n      if (ctype_isstruct(sct->info)) {\n\tCTSize ofs;\n\tCType *fct = lj_ctype_getfield(cts, sct, name, &ofs);\n\tif (fct && ctype_isconstval(fct->info))\n\t  return fct;\n      }\n      ct = sct;  /* Allow resolving metamethods for constructors, too. */\n    }\n  }\n  if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */\n    if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) {\n      p = (uint8_t *)cdata_getptr(p, ct->size);\n      ct = ctype_child(cts, ct);\n      goto collect_attrib;\n    }\n  }\n  *qual |= 1;  /* Lookup failed. */\n  return ct;  /* But return the resolved raw type. */\n}\n\n/* -- C data getters ------------------------------------------------------ */\n\n/* Get constant value and convert to TValue. */\nstatic void cdata_getconst(CTState *cts, TValue *o, CType *ct)\n{\n  CType *ctt = ctype_child(cts, ct);\n  lj_assertCTS(ctype_isinteger(ctt->info) && ctt->size <= 4,\n\t       \"only 32 bit const supported\");  /* NYI */\n  /* Constants are already zero-extended/sign-extended to 32 bits. */\n  if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)\n    setnumV(o, (lua_Number)(uint32_t)ct->size);\n  else\n    setintV(o, (int32_t)ct->size);\n}\n\n/* Get C data value and convert to TValue. */\nint lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp)\n{\n  CTypeID sid;\n\n  if (ctype_isconstval(s->info)) {\n    cdata_getconst(cts, o, s);\n    return 0;  /* No GC step needed. */\n  } else if (ctype_isbitfield(s->info)) {\n    return lj_cconv_tv_bf(cts, s, o, sp);\n  }\n\n  /* Get child type of pointer/array/field. */\n  lj_assertCTS(ctype_ispointer(s->info) || ctype_isfield(s->info),\n\t       \"pointer or field expected\");\n  sid = ctype_cid(s->info);\n  s = ctype_get(cts, sid);\n\n  /* Resolve reference for field. */\n  if (ctype_isref(s->info)) {\n    lj_assertCTS(s->size == CTSIZE_PTR, \"ref is not pointer-sized\");\n    sp = *(uint8_t **)sp;\n    sid = ctype_cid(s->info);\n    s = ctype_get(cts, sid);\n  }\n\n  /* Skip attributes. */\n  while (ctype_isattrib(s->info))\n    s = ctype_child(cts, s);\n\n  return lj_cconv_tv_ct(cts, s, sid, o, sp);\n}\n\n/* -- C data setters ------------------------------------------------------ */\n\n/* Convert TValue and set C data value. */\nvoid lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual)\n{\n  if (ctype_isconstval(d->info)) {\n    goto err_const;\n  } else if (ctype_isbitfield(d->info)) {\n    if (((d->info|qual) & CTF_CONST)) goto err_const;\n    lj_cconv_bf_tv(cts, d, dp, o);\n    return;\n  }\n\n  /* Get child type of pointer/array/field. */\n  lj_assertCTS(ctype_ispointer(d->info) || ctype_isfield(d->info),\n\t       \"pointer or field expected\");\n  d = ctype_child(cts, d);\n\n  /* Resolve reference for field. */\n  if (ctype_isref(d->info)) {\n    lj_assertCTS(d->size == CTSIZE_PTR, \"ref is not pointer-sized\");\n    dp = *(uint8_t **)dp;\n    d = ctype_child(cts, d);\n  }\n\n  /* Skip attributes and collect qualifiers. */\n  for (;;) {\n    if (ctype_isattrib(d->info)) {\n      if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;\n    } else {\n      break;\n    }\n    d = ctype_child(cts, d);\n  }\n\n  lj_assertCTS(ctype_hassize(d->info), \"store to ctype without size\");\n  lj_assertCTS(!ctype_isvoid(d->info), \"store to void type\");\n\n  if (((d->info|qual) & CTF_CONST)) {\n  err_const:\n    lj_err_caller(cts->L, LJ_ERR_FFI_WRCONST);\n  }\n\n  lj_cconv_ct_tv(cts, d, dp, o, 0);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cdata.h",
    "content": "/*\n** C data management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CDATA_H\n#define _LJ_CDATA_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* Get C data pointer. */\nstatic LJ_AINLINE void *cdata_getptr(void *p, CTSize sz)\n{\n  if (LJ_64 && sz == 4) {  /* Support 32 bit pointers on 64 bit targets. */\n    return ((void *)(uintptr_t)*(uint32_t *)p);\n  } else {\n    lj_assertX(sz == CTSIZE_PTR, \"bad pointer size %d\", sz);\n    return *(void **)p;\n  }\n}\n\n/* Set C data pointer. */\nstatic LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v)\n{\n  if (LJ_64 && sz == 4) {  /* Support 32 bit pointers on 64 bit targets. */\n    *(uint32_t *)p = (uint32_t)(uintptr_t)v;\n  } else {\n    lj_assertX(sz == CTSIZE_PTR, \"bad pointer size %d\", sz);\n    *(void **)p = (void *)v;\n  }\n}\n\n/* Allocate fixed-size C data object. */\nstatic LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz)\n{\n  GCcdata *cd;\n#ifdef LUA_USE_ASSERT\n  CType *ct = ctype_raw(cts, id);\n  lj_assertCTS((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz,\n\t       \"inconsistent size of fixed-size cdata alloc\");\n#endif\n  cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz);\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = ctype_check(cts, id);\n  return cd;\n}\n\n/* Variant which works without a valid CTState. */\nstatic LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz)\n{\n  GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz);\n  cd->gct = ~LJ_TCDATA;\n  cd->ctypeid = id;\n  return cd;\n}\n\nLJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id);\nLJ_FUNC GCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz,\n\t\t\t       CTSize align);\nLJ_FUNC GCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz,\n\t\t\t       CTInfo info);\n\nLJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);\nLJ_FUNC void lj_cdata_setfin(lua_State *L, GCcdata *cd, GCobj *obj,\n\t\t\t     uint32_t it);\n\nLJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key,\n\t\t\t      uint8_t **pp, CTInfo *qual);\nLJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp);\nLJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o,\n\t\t\t  CTInfo qual);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_char.c",
    "content": "/*\n** Character types.\n** Donated to the public domain.\n**\n** This is intended to replace the problematic libc single-byte NLS functions.\n** These just don't make sense anymore with UTF-8 locales becoming the norm\n** on POSIX systems. It never worked too well on Windows systems since hardly\n** anyone bothered to call setlocale().\n**\n** This table is hardcoded for ASCII. Identifiers include the characters\n** 128-255, too. This allows for the use of all non-ASCII chars as identifiers\n** in the lexer. This is a broad definition, but works well in practice\n** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*).\n**\n** If you really need proper character types for UTF-8 strings, please use\n** an add-on library such as slnunicode: http://luaforge.net/projects/sln/\n*/\n\n#define lj_char_c\n#define LUA_CORE\n\n#include \"lj_char.h\"\n\nLJ_DATADEF const uint8_t lj_char_bits[257] = {\n    0,\n    1,  1,  1,  1,  1,  1,  1,  1,  1,  3,  3,  3,  3,  3,  1,  1,\n    1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,\n    2,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,\n  152,152,152,152,152,152,152,152,152,152,  4,  4,  4,  4,  4,  4,\n    4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160,\n  160,160,160,160,160,160,160,160,160,160,160,  4,  4,  4,  4,132,\n    4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,\n  192,192,192,192,192,192,192,192,192,192,192,  4,  4,  4,  4,  1,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,\n  128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128\n};\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_char.h",
    "content": "/*\n** Character types.\n** Donated to the public domain.\n*/\n\n#ifndef _LJ_CHAR_H\n#define _LJ_CHAR_H\n\n#include \"lj_def.h\"\n\n#define LJ_CHAR_CNTRL\t0x01\n#define LJ_CHAR_SPACE\t0x02\n#define LJ_CHAR_PUNCT\t0x04\n#define LJ_CHAR_DIGIT\t0x08\n#define LJ_CHAR_XDIGIT\t0x10\n#define LJ_CHAR_UPPER\t0x20\n#define LJ_CHAR_LOWER\t0x40\n#define LJ_CHAR_IDENT\t0x80\n#define LJ_CHAR_ALPHA\t(LJ_CHAR_LOWER|LJ_CHAR_UPPER)\n#define LJ_CHAR_ALNUM\t(LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)\n#define LJ_CHAR_GRAPH\t(LJ_CHAR_ALNUM|LJ_CHAR_PUNCT)\n\n/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */\n#define lj_char_isa(c, t)\t((lj_char_bits+1)[(c)] & t)\n#define lj_char_iscntrl(c)\tlj_char_isa((c), LJ_CHAR_CNTRL)\n#define lj_char_isspace(c)\tlj_char_isa((c), LJ_CHAR_SPACE)\n#define lj_char_ispunct(c)\tlj_char_isa((c), LJ_CHAR_PUNCT)\n#define lj_char_isdigit(c)\tlj_char_isa((c), LJ_CHAR_DIGIT)\n#define lj_char_isxdigit(c)\tlj_char_isa((c), LJ_CHAR_XDIGIT)\n#define lj_char_isupper(c)\tlj_char_isa((c), LJ_CHAR_UPPER)\n#define lj_char_islower(c)\tlj_char_isa((c), LJ_CHAR_LOWER)\n#define lj_char_isident(c)\tlj_char_isa((c), LJ_CHAR_IDENT)\n#define lj_char_isalpha(c)\tlj_char_isa((c), LJ_CHAR_ALPHA)\n#define lj_char_isalnum(c)\tlj_char_isa((c), LJ_CHAR_ALNUM)\n#define lj_char_isgraph(c)\tlj_char_isa((c), LJ_CHAR_GRAPH)\n\n#define lj_char_toupper(c)\t((c) - (lj_char_islower(c) >> 1))\n#define lj_char_tolower(c)\t((c) + lj_char_isupper(c))\n\nLJ_DATA const uint8_t lj_char_bits[257];\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_clib.c",
    "content": "/*\n** FFI C library loader.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_str.h\"\n#include \"lj_udata.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cconv.h\"\n#include \"lj_cdata.h\"\n#include \"lj_clib.h\"\n#include \"lj_strfmt.h\"\n\n/* -- OS-specific functions ----------------------------------------------- */\n\n#if LJ_TARGET_DLOPEN\n\n#include <dlfcn.h>\n#include <stdio.h>\n\n#if defined(RTLD_DEFAULT)\n#define CLIB_DEFHANDLE\tRTLD_DEFAULT\n#elif LJ_TARGET_OSX || LJ_TARGET_BSD\n#define CLIB_DEFHANDLE\t((void *)(intptr_t)-2)\n#else\n#define CLIB_DEFHANDLE\tNULL\n#endif\n\nLJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L)\n{\n  lj_err_callermsg(L, dlerror());\n}\n\n#define clib_error(L, fmt, name)\tclib_error_(L)\n\n#if LJ_TARGET_CYGWIN\n#define CLIB_SOPREFIX\t\"cyg\"\n#else\n#define CLIB_SOPREFIX\t\"lib\"\n#endif\n\n#if LJ_TARGET_OSX\n#define CLIB_SOEXT\t\"%s.dylib\"\n#elif LJ_TARGET_CYGWIN\n#define CLIB_SOEXT\t\"%s.dll\"\n#else\n#define CLIB_SOEXT\t\"%s.so\"\n#endif\n\nstatic const char *clib_extname(lua_State *L, const char *name)\n{\n  if (!strchr(name, '/')\n#if LJ_TARGET_CYGWIN\n      && !strchr(name, '\\\\')\n#endif\n     ) {\n    if (!strchr(name, '.')) {\n      name = lj_strfmt_pushf(L, CLIB_SOEXT, name);\n      L->top--;\n#if LJ_TARGET_CYGWIN\n    } else {\n      return name;\n#endif\n    }\n    if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] &&\n\t  name[2] == CLIB_SOPREFIX[2])) {\n      name = lj_strfmt_pushf(L, CLIB_SOPREFIX \"%s\", name);\n      L->top--;\n    }\n  }\n  return name;\n}\n\n/* Check for a recognized ld script line. */\nstatic const char *clib_check_lds(lua_State *L, const char *buf)\n{\n  char *p, *e;\n  if ((!strncmp(buf, \"GROUP\", 5) || !strncmp(buf, \"INPUT\", 5)) &&\n      (p = strchr(buf, '('))) {\n    while (*++p == ' ') ;\n    for (e = p; *e && *e != ' ' && *e != ')'; e++) ;\n    return strdata(lj_str_new(L, p, e-p));\n  }\n  return NULL;\n}\n\n/* Quick and dirty solution to resolve shared library name from ld script. */\nstatic const char *clib_resolve_lds(lua_State *L, const char *name)\n{\n  FILE *fp = fopen(name, \"r\");\n  const char *p = NULL;\n  if (fp) {\n    char buf[256];\n    if (fgets(buf, sizeof(buf), fp)) {\n      if (!strncmp(buf, \"/* GNU ld script\", 16)) {  /* ld script magic? */\n\twhile (fgets(buf, sizeof(buf), fp)) {  /* Check all lines. */\n\t  p = clib_check_lds(L, buf);\n\t  if (p) break;\n\t}\n      } else {  /* Otherwise check only the first line. */\n\tp = clib_check_lds(L, buf);\n      }\n    }\n    fclose(fp);\n  }\n  return p;\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  void *h = dlopen(clib_extname(L, name),\n\t\t   RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));\n  if (!h) {\n    const char *e, *err = dlerror();\n    if (err && *err == '/' && (e = strchr(err, ':')) &&\n\t(name = clib_resolve_lds(L, strdata(lj_str_new(L, err, e-err))))) {\n      h = dlopen(name, RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));\n      if (h) return h;\n      err = dlerror();\n    }\n    if (!err) err = \"dlopen failed\";\n    lj_err_callermsg(L, err);\n  }\n  return h;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  if (cl->handle && cl->handle != CLIB_DEFHANDLE)\n    dlclose(cl->handle);\n}\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  void *p = dlsym(cl->handle, name);\n  return p;\n}\n\n#elif LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\n#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS\t4\n#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT\t2\nBOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);\n#endif\n\n#define CLIB_DEFHANDLE\t((void *)-1)\n\n/* Default libraries. */\nenum {\n  CLIB_HANDLE_EXE,\n#if !LJ_TARGET_UWP\n  CLIB_HANDLE_DLL,\n  CLIB_HANDLE_CRT,\n  CLIB_HANDLE_KERNEL32,\n  CLIB_HANDLE_USER32,\n  CLIB_HANDLE_GDI32,\n#endif\n  CLIB_HANDLE_MAX\n};\n\nstatic void *clib_def_handle[CLIB_HANDLE_MAX];\n\nLJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,\n\t\t\t\t\t    const char *name)\n{\n  DWORD err = GetLastError();\n#if LJ_TARGET_XBOXONE\n  wchar_t wbuf[128];\n  char buf[128*2];\n  if (!FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,\n\t\t      NULL, err, 0, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL) ||\n      !WideCharToMultiByte(CP_ACP, 0, wbuf, 128, buf, 128*2, NULL, NULL))\n#else\n  char buf[128];\n  if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,\n\t\t      NULL, err, 0, buf, sizeof(buf), NULL))\n#endif\n    buf[0] = '\\0';\n  lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, buf));\n}\n\nstatic int clib_needext(const char *s)\n{\n  while (*s) {\n    if (*s == '/' || *s == '\\\\' || *s == '.') return 0;\n    s++;\n  }\n  return 1;\n}\n\nstatic const char *clib_extname(lua_State *L, const char *name)\n{\n  if (clib_needext(name)) {\n    name = lj_strfmt_pushf(L, \"%s.dll\", name);\n    L->top--;\n  }\n  return name;\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  DWORD oldwerr = GetLastError();\n  void *h = LJ_WIN_LOADLIBA(clib_extname(L, name));\n  if (!h) clib_error(L, \"cannot load module \" LUA_QS \": %s\", name);\n  SetLastError(oldwerr);\n  UNUSED(global);\n  return h;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  if (cl->handle == CLIB_DEFHANDLE) {\n#if !LJ_TARGET_UWP\n    MSize i;\n    for (i = CLIB_HANDLE_KERNEL32; i < CLIB_HANDLE_MAX; i++) {\n      void *h = clib_def_handle[i];\n      if (h) {\n\tclib_def_handle[i] = NULL;\n\tFreeLibrary((HINSTANCE)h);\n      }\n    }\n#endif\n  } else if (cl->handle) {\n    FreeLibrary((HINSTANCE)cl->handle);\n  }\n}\n\n#if LJ_TARGET_UWP\nEXTERN_C IMAGE_DOS_HEADER __ImageBase;\n#endif\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  void *p = NULL;\n  if (cl->handle == CLIB_DEFHANDLE) {  /* Search default libraries. */\n    MSize i;\n    for (i = 0; i < CLIB_HANDLE_MAX; i++) {\n      HINSTANCE h = (HINSTANCE)clib_def_handle[i];\n      if (!(void *)h) {  /* Resolve default library handles (once). */\n#if LJ_TARGET_UWP\n\th = (HINSTANCE)&__ImageBase;\n#else\n\tswitch (i) {\n\tcase CLIB_HANDLE_EXE: GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, &h); break;\n\tcase CLIB_HANDLE_DLL:\n\t  GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t     (const char *)clib_def_handle, &h);\n\t  break;\n\tcase CLIB_HANDLE_CRT:\n\t  GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,\n\t\t\t     (const char *)&_fmode, &h);\n\t  break;\n\tcase CLIB_HANDLE_KERNEL32: h = LJ_WIN_LOADLIBA(\"kernel32.dll\"); break;\n\tcase CLIB_HANDLE_USER32: h = LJ_WIN_LOADLIBA(\"user32.dll\"); break;\n\tcase CLIB_HANDLE_GDI32: h = LJ_WIN_LOADLIBA(\"gdi32.dll\"); break;\n\t}\n\tif (!h) continue;\n#endif\n\tclib_def_handle[i] = (void *)h;\n      }\n      p = (void *)GetProcAddress(h, name);\n      if (p) break;\n    }\n  } else {\n    p = (void *)GetProcAddress((HINSTANCE)cl->handle, name);\n  }\n  return p;\n}\n\n#else\n\n#define CLIB_DEFHANDLE\tNULL\n\nLJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,\n\t\t\t\t\t    const char *name)\n{\n  lj_err_callermsg(L, lj_strfmt_pushf(L, fmt, name, \"no support for this OS\"));\n}\n\nstatic void *clib_loadlib(lua_State *L, const char *name, int global)\n{\n  lj_err_callermsg(L, \"no support for loading dynamic libraries for this OS\");\n  UNUSED(name); UNUSED(global);\n  return NULL;\n}\n\nstatic void clib_unloadlib(CLibrary *cl)\n{\n  UNUSED(cl);\n}\n\nstatic void *clib_getsym(CLibrary *cl, const char *name)\n{\n  UNUSED(cl); UNUSED(name);\n  return NULL;\n}\n\n#endif\n\n/* -- C library indexing -------------------------------------------------- */\n\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n/* Compute argument size for fastcall/stdcall functions. */\nstatic CTSize clib_func_argsize(CTState *cts, CType *ct)\n{\n  CTSize n = 0;\n  while (ct->sib) {\n    CType *d;\n    ct = ctype_get(cts, ct->sib);\n    if (ctype_isfield(ct->info)) {\n      d = ctype_rawchild(cts, ct);\n      n += ((d->size + 3) & ~3);\n    }\n  }\n  return n;\n}\n#endif\n\n/* Get redirected or mangled external symbol. */\nstatic const char *clib_extsym(CTState *cts, CType *ct, GCstr *name)\n{\n  if (ct->sib) {\n    CType *ctf = ctype_get(cts, ct->sib);\n    if (ctype_isxattrib(ctf->info, CTA_REDIR))\n      return strdata(gco2str(gcref(ctf->name)));\n  }\n  return strdata(name);\n}\n\n/* Index a C library by name. */\nTValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name)\n{\n  TValue *tv = lj_tab_setstr(L, cl->cache, name);\n  if (LJ_UNLIKELY(tvisnil(tv))) {\n    CTState *cts = ctype_cts(L);\n    CType *ct;\n    CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);\n    if (!id)\n      lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name));\n    if (ctype_isconstval(ct->info)) {\n      CType *ctt = ctype_child(cts, ct);\n      lj_assertCTS(ctype_isinteger(ctt->info) && ctt->size <= 4,\n\t\t   \"only 32 bit const supported\");  /* NYI */\n      if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)\n\tsetnumV(tv, (lua_Number)(uint32_t)ct->size);\n      else\n\tsetintV(tv, (int32_t)ct->size);\n    } else {\n      const char *sym = clib_extsym(cts, ct, name);\n#if LJ_TARGET_WINDOWS\n      DWORD oldwerr = GetLastError();\n#endif\n      void *p = clib_getsym(cl, sym);\n      GCcdata *cd;\n      lj_assertCTS(ctype_isfunc(ct->info) || ctype_isextern(ct->info),\n\t\t   \"unexpected ctype %08x in clib\", ct->info);\n#if LJ_TARGET_X86 && LJ_ABI_WIN\n      /* Retry with decorated name for fastcall/stdcall functions. */\n      if (!p && ctype_isfunc(ct->info)) {\n\tCTInfo cconv = ctype_cconv(ct->info);\n\tif (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) {\n\t  CTSize sz = clib_func_argsize(cts, ct);\n\t  const char *symd = lj_strfmt_pushf(L,\n\t\t\t       cconv == CTCC_FASTCALL ? \"@%s@%d\" : \"_%s@%d\",\n\t\t\t       sym, sz);\n\t  L->top--;\n\t  p = clib_getsym(cl, symd);\n\t}\n      }\n#endif\n      if (!p)\n\tclib_error(L, \"cannot resolve symbol \" LUA_QS \": %s\", sym);\n#if LJ_TARGET_WINDOWS\n      SetLastError(oldwerr);\n#endif\n      cd = lj_cdata_new(cts, id, CTSIZE_PTR);\n      *(void **)cdataptr(cd) = p;\n      setcdataV(L, tv, cd);\n      lj_gc_anybarriert(L, cl->cache);\n    }\n  }\n  return tv;\n}\n\n/* -- C library management ------------------------------------------------ */\n\n/* Create a new CLibrary object and push it on the stack. */\nstatic CLibrary *clib_new(lua_State *L, GCtab *mt)\n{\n  GCtab *t = lj_tab_new(L, 0, 0);\n  GCudata *ud = lj_udata_new(L, sizeof(CLibrary), t);\n  CLibrary *cl = (CLibrary *)uddata(ud);\n  cl->cache = t;\n  ud->udtype = UDTYPE_FFI_CLIB;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcref(ud->metatable, obj2gco(mt));\n  setudataV(L, L->top++, ud);\n  return cl;\n}\n\n/* Load a C library. */\nvoid lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global)\n{\n  void *handle = clib_loadlib(L, strdata(name), global);\n  CLibrary *cl = clib_new(L, mt);\n  cl->handle = handle;\n}\n\n/* Unload a C library. */\nvoid lj_clib_unload(CLibrary *cl)\n{\n  clib_unloadlib(cl);\n  cl->handle = NULL;\n}\n\n/* Create the default C library object. */\nvoid lj_clib_default(lua_State *L, GCtab *mt)\n{\n  CLibrary *cl = clib_new(L, mt);\n  cl->handle = CLIB_DEFHANDLE;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_clib.h",
    "content": "/*\n** FFI C library loader.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CLIB_H\n#define _LJ_CLIB_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n/* Namespace for C library indexing. */\n#define CLNS_INDEX\t((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))\n\n/* C library namespace. */\ntypedef struct CLibrary {\n  void *handle;\t\t/* Opaque handle for dynamic library loader. */\n  GCtab *cache;\t\t/* Cache for resolved symbols. Anchored in ud->env. */\n} CLibrary;\n\nLJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name);\nLJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global);\nLJ_FUNC void lj_clib_unload(CLibrary *cl);\nLJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cparse.c",
    "content": "/*\n** C declaration parser.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cparse.h\"\n#include \"lj_frame.h\"\n#include \"lj_vm.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/*\n** Important note: this is NOT a validating C parser! This is a minimal\n** C declaration parser, solely for use by the LuaJIT FFI.\n**\n** It ought to return correct results for properly formed C declarations,\n** but it may accept some invalid declarations, too (and return nonsense).\n** Also, it shows rather generic error messages to avoid unnecessary bloat.\n** If in doubt, please check the input against your favorite C compiler.\n*/\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertCP(c, ...)\t(lj_assertG_(G(cp->L), (c), __VA_ARGS__))\n#else\n#define lj_assertCP(c, ...)\t((void)cp)\n#endif\n\n/* -- Miscellaneous ------------------------------------------------------- */\n\n/* Match string against a C literal. */\n#define cp_str_is(str, k) \\\n  ((str)->len == sizeof(k)-1 && !memcmp(strdata(str), k, sizeof(k)-1))\n\n/* Check string against a linear list of matches. */\nint lj_cparse_case(GCstr *str, const char *match)\n{\n  MSize len;\n  int n;\n  for  (n = 0; (len = (MSize)*match++); n++, match += len) {\n    if (str->len == len && !memcmp(match, strdata(str), len))\n      return n;\n  }\n  return -1;\n}\n\n/* -- C lexer ------------------------------------------------------------- */\n\n/* C lexer token names. */\nstatic const char *const ctoknames[] = {\n#define CTOKSTR(name, str)\tstr,\nCTOKDEF(CTOKSTR)\n#undef CTOKSTR\n  NULL\n};\n\n/* Forward declaration. */\nLJ_NORET static void cp_err(CPState *cp, ErrMsg em);\n\nstatic const char *cp_tok2str(CPState *cp, CPToken tok)\n{\n  lj_assertCP(tok < CTOK_FIRSTDECL, \"bad CPToken %d\", tok);\n  if (tok > CTOK_OFS)\n    return ctoknames[tok-CTOK_OFS-1];\n  else if (!lj_char_iscntrl(tok))\n    return lj_strfmt_pushf(cp->L, \"%c\", tok);\n  else\n    return lj_strfmt_pushf(cp->L, \"char(%d)\", tok);\n}\n\n/* End-of-line? */\nstatic LJ_AINLINE int cp_iseol(CPChar c)\n{\n  return (c == '\\n' || c == '\\r');\n}\n\n/* Peek next raw character. */\nstatic LJ_AINLINE CPChar cp_rawpeek(CPState *cp)\n{\n  return (CPChar)(uint8_t)(*cp->p);\n}\n\nstatic LJ_NOINLINE CPChar cp_get_bs(CPState *cp);\n\n/* Get next character. */\nstatic LJ_AINLINE CPChar cp_get(CPState *cp)\n{\n  cp->c = (CPChar)(uint8_t)(*cp->p++);\n  if (LJ_LIKELY(cp->c != '\\\\')) return cp->c;\n  return cp_get_bs(cp);\n}\n\n/* Transparently skip backslash-escaped line breaks. */\nstatic LJ_NOINLINE CPChar cp_get_bs(CPState *cp)\n{\n  CPChar c2, c = cp_rawpeek(cp);\n  if (!cp_iseol(c)) return cp->c;\n  cp->p++;\n  c2 = cp_rawpeek(cp);\n  if (cp_iseol(c2) && c2 != c) cp->p++;\n  cp->linenumber++;\n  return cp_get(cp);\n}\n\n/* Save character in buffer. */\nstatic LJ_AINLINE void cp_save(CPState *cp, CPChar c)\n{\n  lj_buf_putb(&cp->sb, c);\n}\n\n/* Skip line break. Handles \"\\n\", \"\\r\", \"\\r\\n\" or \"\\n\\r\". */\nstatic void cp_newline(CPState *cp)\n{\n  CPChar c = cp_rawpeek(cp);\n  if (cp_iseol(c) && c != cp->c) cp->p++;\n  cp->linenumber++;\n}\n\nLJ_NORET static void cp_errmsg(CPState *cp, CPToken tok, ErrMsg em, ...)\n{\n  const char *msg, *tokstr;\n  lua_State *L;\n  va_list argp;\n  if (tok == 0) {\n    tokstr = NULL;\n  } else if (tok == CTOK_IDENT || tok == CTOK_INTEGER || tok == CTOK_STRING ||\n\t     tok >= CTOK_FIRSTDECL) {\n    if (cp->sb.w == cp->sb.b) cp_save(cp, '$');\n    cp_save(cp, '\\0');\n    tokstr = cp->sb.b;\n  } else {\n    tokstr = cp_tok2str(cp, tok);\n  }\n  L = cp->L;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  if (tokstr)\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tokstr);\n  if (cp->linenumber > 1)\n    msg = lj_strfmt_pushf(L, \"%s at line %d\", msg, cp->linenumber);\n  lj_err_callermsg(L, msg);\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err_token(CPState *cp, CPToken tok)\n{\n  cp_errmsg(cp, cp->tok, LJ_ERR_XTOKEN, cp_tok2str(cp, tok));\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err_badidx(CPState *cp, CType *ct)\n{\n  GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);\n  cp_errmsg(cp, 0, LJ_ERR_FFI_BADIDX, strdata(s));\n}\n\nLJ_NORET LJ_NOINLINE static void cp_err(CPState *cp, ErrMsg em)\n{\n  cp_errmsg(cp, 0, em);\n}\n\n/* -- Main lexical scanner ------------------------------------------------ */\n\n/* Parse number literal. Only handles int32_t/uint32_t right now. */\nstatic CPToken cp_number(CPState *cp)\n{\n  StrScanFmt fmt;\n  TValue o;\n  do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));\n  cp_save(cp, '\\0');\n  fmt = lj_strscan_scan((const uint8_t *)(cp->sb.b), sbuflen(&cp->sb)-1,\n\t\t\t&o, STRSCAN_OPT_C);\n  if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32;\n  else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32;\n  else if (!(cp->mode & CPARSE_MODE_SKIP))\n    cp_errmsg(cp, CTOK_INTEGER, LJ_ERR_XNUMBER);\n  cp->val.u32 = (uint32_t)o.i;\n  return CTOK_INTEGER;\n}\n\n/* Parse identifier or keyword. */\nstatic CPToken cp_ident(CPState *cp)\n{\n  do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));\n  cp->str = lj_buf_str(cp->L, &cp->sb);\n  cp->val.id = lj_ctype_getname(cp->cts, &cp->ct, cp->str, cp->tmask);\n  if (ctype_type(cp->ct->info) == CT_KW)\n    return ctype_cid(cp->ct->info);\n  return CTOK_IDENT;\n}\n\n/* Parse parameter. */\nstatic CPToken cp_param(CPState *cp)\n{\n  CPChar c = cp_get(cp);\n  TValue *o = cp->param;\n  if (lj_char_isident(c) || c == '$')  /* Reserve $xyz for future extensions. */\n    cp_errmsg(cp, c, LJ_ERR_XSYNTAX);\n  if (!o || o >= cp->L->top)\n    cp_err(cp, LJ_ERR_FFI_NUMPARAM);\n  cp->param = o+1;\n  if (tvisstr(o)) {\n    cp->str = strV(o);\n    cp->val.id = 0;\n    cp->ct = &cp->cts->tab[0];\n    return CTOK_IDENT;\n  } else if (tvisnumber(o)) {\n    cp->val.i32 = numberVint(o);\n    cp->val.id = CTID_INT32;\n    return CTOK_INTEGER;\n  } else {\n    GCcdata *cd;\n    if (!tviscdata(o))\n      lj_err_argtype(cp->L, (int)(o-cp->L->base)+1, \"type parameter\");\n    cd = cdataV(o);\n    if (cd->ctypeid == CTID_CTYPEID)\n      cp->val.id = *(CTypeID *)cdataptr(cd);\n    else\n      cp->val.id = cd->ctypeid;\n    return '$';\n  }\n}\n\n/* Parse string or character constant. */\nstatic CPToken cp_string(CPState *cp)\n{\n  CPChar delim = cp->c;\n  cp_get(cp);\n  while (cp->c != delim) {\n    CPChar c = cp->c;\n    if (c == '\\0') cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR);\n    if (c == '\\\\') {\n      c = cp_get(cp);\n      switch (c) {\n      case '\\0': cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); break;\n      case 'a': c = '\\a'; break;\n      case 'b': c = '\\b'; break;\n      case 'f': c = '\\f'; break;\n      case 'n': c = '\\n'; break;\n      case 'r': c = '\\r'; break;\n      case 't': c = '\\t'; break;\n      case 'v': c = '\\v'; break;\n      case 'e': c = 27; break;\n      case 'x':\n\tc = 0;\n\twhile (lj_char_isxdigit(cp_get(cp)))\n\t  c = (c<<4) + (lj_char_isdigit(cp->c) ? cp->c-'0' : (cp->c&15)+9);\n\tcp_save(cp, (c & 0xff));\n\tcontinue;\n      default:\n\tif (lj_char_isdigit(c)) {\n\t  c -= '0';\n\t  if (lj_char_isdigit(cp_get(cp))) {\n\t    c = c*8 + (cp->c - '0');\n\t    if (lj_char_isdigit(cp_get(cp))) {\n\t      c = c*8 + (cp->c - '0');\n\t      cp_get(cp);\n\t    }\n\t  }\n\t  cp_save(cp, (c & 0xff));\n\t  continue;\n\t}\n\tbreak;\n      }\n    }\n    cp_save(cp, c);\n    cp_get(cp);\n  }\n  cp_get(cp);\n  if (delim == '\"') {\n    cp->str = lj_buf_str(cp->L, &cp->sb);\n    return CTOK_STRING;\n  } else {\n    if (sbuflen(&cp->sb) != 1) cp_err_token(cp, '\\'');\n    cp->val.i32 = (int32_t)(char)*cp->sb.b;\n    cp->val.id = CTID_INT32;\n    return CTOK_INTEGER;\n  }\n}\n\n/* Skip C comment. */\nstatic void cp_comment_c(CPState *cp)\n{\n  do {\n    if (cp_get(cp) == '*') {\n      do {\n\tif (cp_get(cp) == '/') { cp_get(cp); return; }\n      } while (cp->c == '*');\n    }\n    if (cp_iseol(cp->c)) cp_newline(cp);\n  } while (cp->c != '\\0');\n}\n\n/* Skip C++ comment. */\nstatic void cp_comment_cpp(CPState *cp)\n{\n  while (!cp_iseol(cp_get(cp)) && cp->c != '\\0')\n    ;\n}\n\n/* Lexical scanner for C. Only a minimal subset is implemented. */\nstatic CPToken cp_next_(CPState *cp)\n{\n  lj_buf_reset(&cp->sb);\n  for (;;) {\n    if (lj_char_isident(cp->c))\n      return lj_char_isdigit(cp->c) ? cp_number(cp) : cp_ident(cp);\n    switch (cp->c) {\n    case '\\n': case '\\r': cp_newline(cp);  /* fallthrough. */\n    case ' ': case '\\t': case '\\v': case '\\f': cp_get(cp); break;\n    case '\"': case '\\'': return cp_string(cp);\n    case '/':\n      if (cp_get(cp) == '*') cp_comment_c(cp);\n      else if (cp->c == '/') cp_comment_cpp(cp);\n      else return '/';\n      break;\n    case '|':\n      if (cp_get(cp) != '|') return '|';\n      cp_get(cp); return CTOK_OROR;\n    case '&':\n      if (cp_get(cp) != '&') return '&';\n      cp_get(cp); return CTOK_ANDAND;\n    case '=':\n      if (cp_get(cp) != '=') return '=';\n      cp_get(cp); return CTOK_EQ;\n    case '!':\n      if (cp_get(cp) != '=') return '!';\n      cp_get(cp); return CTOK_NE;\n    case '<':\n      if (cp_get(cp) == '=') { cp_get(cp); return CTOK_LE; }\n      else if (cp->c == '<') { cp_get(cp); return CTOK_SHL; }\n      return '<';\n    case '>':\n      if (cp_get(cp) == '=') { cp_get(cp); return CTOK_GE; }\n      else if (cp->c == '>') { cp_get(cp); return CTOK_SHR; }\n      return '>';\n    case '-':\n      if (cp_get(cp) != '>') return '-';\n      cp_get(cp); return CTOK_DEREF;\n    case '$':\n      return cp_param(cp);\n    case '\\0': return CTOK_EOF;\n    default: { CPToken c = cp->c; cp_get(cp); return c; }\n    }\n  }\n}\n\nstatic LJ_NOINLINE CPToken cp_next(CPState *cp)\n{\n  return (cp->tok = cp_next_(cp));\n}\n\n/* -- C parser ------------------------------------------------------------ */\n\n/* Namespaces for resolving identifiers. */\n#define CPNS_DEFAULT \\\n  ((1u<<CT_KW)|(1u<<CT_TYPEDEF)|(1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))\n#define CPNS_STRUCT\t((1u<<CT_KW)|(1u<<CT_STRUCT)|(1u<<CT_ENUM))\n\ntypedef CTypeID CPDeclIdx;\t/* Index into declaration stack. */\ntypedef uint32_t CPscl;\t\t/* Storage class flags. */\n\n/* Type declaration context. */\ntypedef struct CPDecl {\n  CPDeclIdx top;\t/* Top of declaration stack. */\n  CPDeclIdx pos;\t/* Insertion position in declaration chain. */\n  CPDeclIdx specpos;\t/* Saved position for declaration specifier. */\n  uint32_t mode;\t/* Declarator mode. */\n  CPState *cp;\t\t/* C parser state. */\n  GCstr *name;\t\t/* Name of declared identifier (if direct). */\n  GCstr *redir;\t\t/* Redirected symbol name. */\n  CTypeID nameid;\t/* Existing typedef for declared identifier. */\n  CTInfo attr;\t\t/* Attributes. */\n  CTInfo fattr;\t\t/* Function attributes. */\n  CTInfo specattr;\t/* Saved attributes. */\n  CTInfo specfattr;\t/* Saved function attributes. */\n  CTSize bits;\t\t/* Field size in bits (if any). */\n  CType stack[CPARSE_MAX_DECLSTACK];  /* Type declaration stack. */\n} CPDecl;\n\n/* Forward declarations. */\nstatic CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl);\nstatic void cp_declarator(CPState *cp, CPDecl *decl);\nstatic CTypeID cp_decl_abstract(CPState *cp);\n\n/* Initialize C parser state. Caller must set up: L, p, srcname, mode. */\nstatic void cp_init(CPState *cp)\n{\n  cp->linenumber = 1;\n  cp->depth = 0;\n  cp->curpack = 0;\n  cp->packstack[0] = 255;\n  lj_buf_init(cp->L, &cp->sb);\n  lj_assertCP(cp->p != NULL, \"uninitialized cp->p\");\n  cp_get(cp);  /* Read-ahead first char. */\n  cp->tok = 0;\n  cp->tmask = CPNS_DEFAULT;\n  cp_next(cp);  /* Read-ahead first token. */\n}\n\n/* Cleanup C parser state. */\nstatic void cp_cleanup(CPState *cp)\n{\n  global_State *g = G(cp->L);\n  lj_buf_free(g, &cp->sb);\n}\n\n/* Check and consume optional token. */\nstatic int cp_opt(CPState *cp, CPToken tok)\n{\n  if (cp->tok == tok) { cp_next(cp); return 1; }\n  return 0;\n}\n\n/* Check and consume token. */\nstatic void cp_check(CPState *cp, CPToken tok)\n{\n  if (cp->tok != tok) cp_err_token(cp, tok);\n  cp_next(cp);\n}\n\n/* Check if the next token may start a type declaration. */\nstatic int cp_istypedecl(CPState *cp)\n{\n  if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECL) return 1;\n  if (cp->tok == CTOK_IDENT && ctype_istypedef(cp->ct->info)) return 1;\n  if (cp->tok == '$') return 1;\n  return 0;\n}\n\n/* -- Constant expression evaluator --------------------------------------- */\n\n/* Forward declarations. */\nstatic void cp_expr_unary(CPState *cp, CPValue *k);\nstatic void cp_expr_sub(CPState *cp, CPValue *k, int pri);\n\n/* Please note that type handling is very weak here. Most ops simply\n** assume integer operands. Accessors are only needed to compute types and\n** return synthetic values. The only purpose of the expression evaluator\n** is to compute the values of constant expressions one would typically\n** find in C header files. And again: this is NOT a validating C parser!\n*/\n\n/* Parse comma separated expression and return last result. */\nstatic void cp_expr_comma(CPState *cp, CPValue *k)\n{\n  do { cp_expr_sub(cp, k, 0); } while (cp_opt(cp, ','));\n}\n\n/* Parse sizeof/alignof operator. */\nstatic void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz)\n{\n  CTSize sz;\n  CTInfo info;\n  if (cp_opt(cp, '(')) {\n    if (cp_istypedecl(cp))\n      k->id = cp_decl_abstract(cp);\n    else\n      cp_expr_comma(cp, k);\n    cp_check(cp, ')');\n  } else {\n    cp_expr_unary(cp, k);\n  }\n  info = lj_ctype_info(cp->cts, k->id, &sz);\n  if (wantsz) {\n    if (sz != CTSIZE_INVALID)\n      k->u32 = sz;\n    else if (k->id != CTID_A_CCHAR)  /* Special case for sizeof(\"string\"). */\n      cp_err(cp, LJ_ERR_FFI_INVSIZE);\n  } else {\n    k->u32 = 1u << ctype_align(info);\n  }\n  k->id = CTID_UINT32;  /* Really size_t. */\n}\n\n/* Parse prefix operators. */\nstatic void cp_expr_prefix(CPState *cp, CPValue *k)\n{\n  if (cp->tok == CTOK_INTEGER) {\n    *k = cp->val; cp_next(cp);\n  } else if (cp_opt(cp, '+')) {\n    cp_expr_unary(cp, k);  /* Nothing to do (well, integer promotion). */\n  } else if (cp_opt(cp, '-')) {\n    cp_expr_unary(cp, k); k->i32 = -k->i32;\n  } else if (cp_opt(cp, '~')) {\n    cp_expr_unary(cp, k); k->i32 = ~k->i32;\n  } else if (cp_opt(cp, '!')) {\n    cp_expr_unary(cp, k); k->i32 = !k->i32; k->id = CTID_INT32;\n  } else if (cp_opt(cp, '(')) {\n    if (cp_istypedecl(cp)) {  /* Cast operator. */\n      CTypeID id = cp_decl_abstract(cp);\n      cp_check(cp, ')');\n      cp_expr_unary(cp, k);\n      k->id = id;  /* No conversion performed. */\n    } else {  /* Sub-expression. */\n      cp_expr_comma(cp, k);\n      cp_check(cp, ')');\n    }\n  } else if (cp_opt(cp, '*')) {  /* Indirection. */\n    CType *ct;\n    cp_expr_unary(cp, k);\n    ct = lj_ctype_rawref(cp->cts, k->id);\n    if (!ctype_ispointer(ct->info))\n      cp_err_badidx(cp, ct);\n    k->u32 = 0; k->id = ctype_cid(ct->info);\n  } else if (cp_opt(cp, '&')) {  /* Address operator. */\n    cp_expr_unary(cp, k);\n    k->id = lj_ctype_intern(cp->cts, CTINFO(CT_PTR, CTALIGN_PTR+k->id),\n\t\t\t    CTSIZE_PTR);\n  } else if (cp_opt(cp, CTOK_SIZEOF)) {\n    cp_expr_sizeof(cp, k, 1);\n  } else if (cp_opt(cp, CTOK_ALIGNOF)) {\n    cp_expr_sizeof(cp, k, 0);\n  } else if (cp->tok == CTOK_IDENT) {\n    if (ctype_type(cp->ct->info) == CT_CONSTVAL) {\n      k->u32 = cp->ct->size; k->id = ctype_cid(cp->ct->info);\n    } else if (ctype_type(cp->ct->info) == CT_EXTERN) {\n      k->u32 = cp->val.id; k->id = ctype_cid(cp->ct->info);\n    } else if (ctype_type(cp->ct->info) == CT_FUNC) {\n      k->u32 = cp->val.id; k->id = cp->val.id;\n    } else {\n      goto err_expr;\n    }\n    cp_next(cp);\n  } else if (cp->tok == CTOK_STRING) {\n    CTSize sz = cp->str->len;\n    while (cp_next(cp) == CTOK_STRING)\n      sz += cp->str->len;\n    k->u32 = sz + 1;\n    k->id = CTID_A_CCHAR;\n  } else {\n  err_expr:\n    cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n  }\n}\n\n/* Parse postfix operators. */\nstatic void cp_expr_postfix(CPState *cp, CPValue *k)\n{\n  for (;;) {\n    CType *ct;\n    if (cp_opt(cp, '[')) {  /* Array/pointer index. */\n      CPValue k2;\n      cp_expr_comma(cp, &k2);\n      ct = lj_ctype_rawref(cp->cts, k->id);\n      if (!ctype_ispointer(ct->info)) {\n\tct = lj_ctype_rawref(cp->cts, k2.id);\n\tif (!ctype_ispointer(ct->info))\n\t  cp_err_badidx(cp, ct);\n      }\n      cp_check(cp, ']');\n      k->u32 = 0;\n    } else if (cp->tok == '.' || cp->tok == CTOK_DEREF) {  /* Struct deref. */\n      CTSize ofs;\n      CType *fct;\n      ct = lj_ctype_rawref(cp->cts, k->id);\n      if (cp->tok == CTOK_DEREF) {\n\tif (!ctype_ispointer(ct->info))\n\t  cp_err_badidx(cp, ct);\n\tct = lj_ctype_rawref(cp->cts, ctype_cid(ct->info));\n      }\n      cp_next(cp);\n      if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n      if (!ctype_isstruct(ct->info) || ct->size == CTSIZE_INVALID ||\n\t  !(fct = lj_ctype_getfield(cp->cts, ct, cp->str, &ofs)) ||\n\t  ctype_isbitfield(fct->info)) {\n\tGCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_BADMEMBER, strdata(s), strdata(cp->str));\n      }\n      ct = fct;\n      k->u32 = ctype_isconstval(ct->info) ? ct->size : 0;\n      cp_next(cp);\n    } else {\n      return;\n    }\n    k->id = ctype_cid(ct->info);\n  }\n}\n\n/* Parse infix operators. */\nstatic void cp_expr_infix(CPState *cp, CPValue *k, int pri)\n{\n  CPValue k2;\n  k2.u32 = 0; k2.id = 0;  /* Silence the compiler. */\n  for (;;) {\n    switch (pri) {\n    case 0:\n      if (cp_opt(cp, '?')) {\n\tCPValue k3;\n\tcp_expr_comma(cp, &k2);  /* Right-associative. */\n\tcp_check(cp, ':');\n\tcp_expr_sub(cp, &k3, 0);\n\tk->u32 = k->u32 ? k2.u32 : k3.u32;\n\tk->id = k2.id > k3.id ? k2.id : k3.id;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 1:\n      if (cp_opt(cp, CTOK_OROR)) {\n\tcp_expr_sub(cp, &k2, 2); k->i32 = k->u32 || k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 2:\n      if (cp_opt(cp, CTOK_ANDAND)) {\n\tcp_expr_sub(cp, &k2, 3); k->i32 = k->u32 && k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 3:\n      if (cp_opt(cp, '|')) {\n\tcp_expr_sub(cp, &k2, 4); k->u32 = k->u32 | k2.u32; goto arith_result;\n      }\n      /* fallthrough */\n    case 4:\n      if (cp_opt(cp, '^')) {\n\tcp_expr_sub(cp, &k2, 5); k->u32 = k->u32 ^ k2.u32; goto arith_result;\n      }\n      /* fallthrough */\n    case 5:\n      if (cp_opt(cp, '&')) {\n\tcp_expr_sub(cp, &k2, 6); k->u32 = k->u32 & k2.u32; goto arith_result;\n      }\n      /* fallthrough */\n    case 6:\n      if (cp_opt(cp, CTOK_EQ)) {\n\tcp_expr_sub(cp, &k2, 7); k->i32 = k->u32 == k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_NE)) {\n\tcp_expr_sub(cp, &k2, 7); k->i32 = k->u32 != k2.u32; k->id = CTID_INT32;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 7:\n      if (cp_opt(cp, '<')) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 < k2.i32;\n\telse\n\t  k->i32 = k->u32 < k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, '>')) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 > k2.i32;\n\telse\n\t  k->i32 = k->u32 > k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_LE)) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 <= k2.i32;\n\telse\n\t  k->i32 = k->u32 <= k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_GE)) {\n\tcp_expr_sub(cp, &k2, 8);\n\tif (k->id == CTID_INT32 && k2.id == CTID_INT32)\n\t  k->i32 = k->i32 >= k2.i32;\n\telse\n\t  k->i32 = k->u32 >= k2.u32;\n\tk->id = CTID_INT32;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 8:\n      if (cp_opt(cp, CTOK_SHL)) {\n\tcp_expr_sub(cp, &k2, 9); k->u32 = k->u32 << k2.u32;\n\tcontinue;\n      } else if (cp_opt(cp, CTOK_SHR)) {\n\tcp_expr_sub(cp, &k2, 9);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 >> k2.i32;\n\telse\n\t  k->u32 = k->u32 >> k2.u32;\n\tcontinue;\n      }\n      /* fallthrough */\n    case 9:\n      if (cp_opt(cp, '+')) {\n\tcp_expr_sub(cp, &k2, 10); k->u32 = k->u32 + k2.u32;\n      arith_result:\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tcontinue;\n      } else if (cp_opt(cp, '-')) {\n\tcp_expr_sub(cp, &k2, 10); k->u32 = k->u32 - k2.u32; goto arith_result;\n      }\n      /* fallthrough */\n    case 10:\n      if (cp_opt(cp, '*')) {\n\tcp_expr_unary(cp, &k2); k->u32 = k->u32 * k2.u32; goto arith_result;\n      } else if (cp_opt(cp, '/')) {\n\tcp_expr_unary(cp, &k2);\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tif (k2.u32 == 0 ||\n\t    (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))\n\t  cp_err(cp, LJ_ERR_BADVAL);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 / k2.i32;\n\telse\n\t  k->u32 = k->u32 / k2.u32;\n\tcontinue;\n      } else if (cp_opt(cp, '%')) {\n\tcp_expr_unary(cp, &k2);\n\tif (k2.id > k->id) k->id = k2.id;  /* Trivial promotion to unsigned. */\n\tif (k2.u32 == 0 ||\n\t    (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))\n\t  cp_err(cp, LJ_ERR_BADVAL);\n\tif (k->id == CTID_INT32)\n\t  k->i32 = k->i32 % k2.i32;\n\telse\n\t  k->u32 = k->u32 % k2.u32;\n\tcontinue;\n      }\n    default:\n      return;\n    }\n  }\n}\n\n/* Parse and evaluate unary expression. */\nstatic void cp_expr_unary(CPState *cp, CPValue *k)\n{\n  if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);\n  cp_expr_prefix(cp, k);\n  cp_expr_postfix(cp, k);\n  cp->depth--;\n}\n\n/* Parse and evaluate sub-expression. */\nstatic void cp_expr_sub(CPState *cp, CPValue *k, int pri)\n{\n  cp_expr_unary(cp, k);\n  cp_expr_infix(cp, k, pri);\n}\n\n/* Parse constant integer expression. */\nstatic void cp_expr_kint(CPState *cp, CPValue *k)\n{\n  CType *ct;\n  cp_expr_sub(cp, k, 0);\n  ct = ctype_raw(cp->cts, k->id);\n  if (!ctype_isinteger(ct->info)) cp_err(cp, LJ_ERR_BADVAL);\n}\n\n/* Parse (non-negative) size expression. */\nstatic CTSize cp_expr_ksize(CPState *cp)\n{\n  CPValue k;\n  cp_expr_kint(cp, &k);\n  if (k.u32 >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);\n  return k.u32;\n}\n\n/* -- Type declaration stack management ----------------------------------- */\n\n/* Add declaration element behind the insertion position. */\nstatic CPDeclIdx cp_add(CPDecl *decl, CTInfo info, CTSize size)\n{\n  CPDeclIdx top = decl->top;\n  if (top >= CPARSE_MAX_DECLSTACK) cp_err(decl->cp, LJ_ERR_XLEVELS);\n  decl->stack[top].info = info;\n  decl->stack[top].size = size;\n  decl->stack[top].sib = 0;\n  setgcrefnull(decl->stack[top].name);\n  decl->stack[top].next = decl->stack[decl->pos].next;\n  decl->stack[decl->pos].next = (CTypeID1)top;\n  decl->top = top+1;\n  return top;\n}\n\n/* Push declaration element before the insertion position. */\nstatic CPDeclIdx cp_push(CPDecl *decl, CTInfo info, CTSize size)\n{\n  return (decl->pos = cp_add(decl, info, size));\n}\n\n/* Push or merge attributes. */\nstatic void cp_push_attributes(CPDecl *decl)\n{\n  CType *ct = &decl->stack[decl->pos];\n  if (ctype_isfunc(ct->info)) {  /* Ok to modify in-place. */\n#if LJ_TARGET_X86\n    if ((decl->fattr & CTFP_CCONV))\n      ct->info = (ct->info & (CTMASK_NUM|CTF_VARARG|CTMASK_CID)) +\n\t\t (decl->fattr & ~CTMASK_CID);\n#endif\n  } else {\n    if ((decl->attr & CTFP_ALIGNED) && !(decl->mode & CPARSE_MODE_FIELD))\n      cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_ALIGN)),\n\t      ctype_align(decl->attr));\n  }\n}\n\n/* Push unrolled type to declaration stack and merge qualifiers. */\nstatic void cp_push_type(CPDecl *decl, CTypeID id)\n{\n  CType *ct = ctype_get(decl->cp->cts, id);\n  CTInfo info = ct->info;\n  CTSize size = ct->size;\n  switch (ctype_type(info)) {\n  case CT_STRUCT: case CT_ENUM:\n    cp_push(decl, CTINFO(CT_TYPEDEF, id), 0);  /* Don't copy unique types. */\n    if ((decl->attr & CTF_QUAL)) {  /* Push unmerged qualifiers. */\n      cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_QUAL)),\n\t      (decl->attr & CTF_QUAL));\n      decl->attr &= ~CTF_QUAL;\n    }\n    break;\n  case CT_ATTRIB:\n    if (ctype_isxattrib(info, CTA_QUAL))\n      decl->attr &= ~size;  /* Remove redundant qualifiers. */\n    cp_push_type(decl, ctype_cid(info));  /* Unroll. */\n    cp_push(decl, info & ~CTMASK_CID, size);  /* Copy type. */\n    break;\n  case CT_ARRAY:\n    if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {\n      info |= (decl->attr & CTF_QUAL);\n      decl->attr &= ~CTF_QUAL;\n    }\n    cp_push_type(decl, ctype_cid(info));  /* Unroll. */\n    cp_push(decl, info & ~CTMASK_CID, size);  /* Copy type. */\n    decl->stack[decl->pos].sib = 1;  /* Mark as already checked and sized. */\n    /* Note: this is not copied to the ct->sib in the C type table. */\n    break;\n  case CT_FUNC:\n    /* Copy type, link parameters (shared). */\n    decl->stack[cp_push(decl, info, size)].sib = ct->sib;\n    break;\n  default:\n    /* Copy type, merge common qualifiers. */\n    cp_push(decl, info|(decl->attr & CTF_QUAL), size);\n    decl->attr &= ~CTF_QUAL;\n    break;\n  }\n}\n\n/* Consume the declaration element chain and intern the C type. */\nstatic CTypeID cp_decl_intern(CPState *cp, CPDecl *decl)\n{\n  CTypeID id = 0;\n  CPDeclIdx idx = 0;\n  CTSize csize = CTSIZE_INVALID;\n  CTSize cinfo = 0;\n  do {\n    CType *ct = &decl->stack[idx];\n    CTInfo info = ct->info;\n    CTInfo size = ct->size;\n    /* The cid is already part of info for copies of pointers/functions. */\n    idx = ct->next;\n    if (ctype_istypedef(info)) {\n      lj_assertCP(id == 0, \"typedef not at toplevel\");\n      id = ctype_cid(info);\n      /* Always refetch info/size, since struct/enum may have been completed. */\n      cinfo = ctype_get(cp->cts, id)->info;\n      csize = ctype_get(cp->cts, id)->size;\n      lj_assertCP(ctype_isstruct(cinfo) || ctype_isenum(cinfo),\n\t\t  \"typedef of bad type\");\n    } else if (ctype_isfunc(info)) {  /* Intern function. */\n      CType *fct;\n      CTypeID fid;\n      CTypeID sib;\n      if (id) {\n\tCType *refct = ctype_raw(cp->cts, id);\n\t/* Reject function or refarray return types. */\n\tif (ctype_isfunc(refct->info) || ctype_isrefarray(refct->info))\n\t  cp_err(cp, LJ_ERR_FFI_INVTYPE);\n      }\n      /* No intervening attributes allowed, skip forward. */\n      while (idx) {\n\tCType *ctn = &decl->stack[idx];\n\tif (!ctype_isattrib(ctn->info)) break;\n\tidx = ctn->next;  /* Skip attribute. */\n      }\n      sib = ct->sib;  /* Next line may reallocate the C type table. */\n      fid = lj_ctype_new(cp->cts, &fct);\n      csize = CTSIZE_INVALID;\n      fct->info = cinfo = info + id;\n      fct->size = size;\n      fct->sib = sib;\n      id = fid;\n    } else if (ctype_isattrib(info)) {\n      if (ctype_isxattrib(info, CTA_QUAL))\n\tcinfo |= size;\n      else if (ctype_isxattrib(info, CTA_ALIGN))\n\tCTF_INSERT(cinfo, ALIGN, size);\n      id = lj_ctype_intern(cp->cts, info+id, size);\n      /* Inherit csize/cinfo from original type. */\n    } else {\n      if (ctype_isnum(info)) {  /* Handle mode/vector-size attributes. */\n\tlj_assertCP(id == 0, \"number not at toplevel\");\n\tif (!(info & CTF_BOOL)) {\n\t  CTSize msize = ctype_msizeP(decl->attr);\n\t  CTSize vsize = ctype_vsizeP(decl->attr);\n\t  if (msize && (!(info & CTF_FP) || (msize == 4 || msize == 8))) {\n\t    CTSize malign = lj_fls(msize);\n\t    if (malign > 4) malign = 4;  /* Limit alignment. */\n\t    CTF_INSERT(info, ALIGN, malign);\n\t    size = msize;  /* Override size via mode. */\n\t  }\n\t  if (vsize) {  /* Vector size set? */\n\t    CTSize esize = lj_fls(size);\n\t    if (vsize >= esize) {\n\t      /* Intern the element type first. */\n\t      id = lj_ctype_intern(cp->cts, info, size);\n\t      /* Then create a vector (array) with vsize alignment. */\n\t      size = (1u << vsize);\n\t      if (vsize > 4) vsize = 4;  /* Limit alignment. */\n\t      if (ctype_align(info) > vsize) vsize = ctype_align(info);\n\t      info = CTINFO(CT_ARRAY, (info & CTF_QUAL) + CTF_VECTOR +\n\t\t\t\t      CTALIGN(vsize));\n\t    }\n\t  }\n\t}\n      } else if (ctype_isptr(info)) {\n\t/* Reject pointer/ref to ref. */\n\tif (id && ctype_isref(ctype_raw(cp->cts, id)->info))\n\t  cp_err(cp, LJ_ERR_FFI_INVTYPE);\n\tif (ctype_isref(info)) {\n\t  info &= ~CTF_VOLATILE;  /* Refs are always const, never volatile. */\n\t  /* No intervening attributes allowed, skip forward. */\n\t  while (idx) {\n\t    CType *ctn = &decl->stack[idx];\n\t    if (!ctype_isattrib(ctn->info)) break;\n\t    idx = ctn->next;  /* Skip attribute. */\n\t  }\n\t}\n      } else if (ctype_isarray(info)) {  /* Check for valid array size etc. */\n\tif (ct->sib == 0) {  /* Only check/size arrays not copied by unroll. */\n\t  if (ctype_isref(cinfo))  /* Reject arrays of refs. */\n\t    cp_err(cp, LJ_ERR_FFI_INVTYPE);\n\t  /* Reject VLS or unknown-sized types. */\n\t  if (ctype_isvltype(cinfo) || csize == CTSIZE_INVALID)\n\t    cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\t  /* a[] and a[?] keep their invalid size. */\n\t  if (size != CTSIZE_INVALID) {\n\t    uint64_t xsz = (uint64_t)size * csize;\n\t    if (xsz >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\t    size = (CTSize)xsz;\n\t  }\n\t}\n\tif ((cinfo & CTF_ALIGN) > (info & CTF_ALIGN))  /* Find max. align. */\n\t  info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN);\n\tinfo |= (cinfo & CTF_QUAL);  /* Inherit qual. */\n      } else {\n\tlj_assertCP(ctype_isvoid(info), \"bad ctype %08x\", info);\n      }\n      csize = size;\n      cinfo = info+id;\n      id = lj_ctype_intern(cp->cts, info+id, size);\n    }\n  } while (idx);\n  return id;\n}\n\n/* -- C declaration parser ------------------------------------------------ */\n\n/* Reset declaration state to declaration specifier. */\nstatic void cp_decl_reset(CPDecl *decl)\n{\n  decl->pos = decl->specpos;\n  decl->top = decl->specpos+1;\n  decl->stack[decl->specpos].next = 0;\n  decl->attr = decl->specattr;\n  decl->fattr = decl->specfattr;\n  decl->name = NULL;\n  decl->redir = NULL;\n}\n\n/* Parse constant initializer. */\n/* NYI: FP constants and strings as initializers. */\nstatic CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID ctypeid)\n{\n  CType *ctt = ctype_get(cp->cts, ctypeid);\n  CTInfo info;\n  CTSize size;\n  CPValue k;\n  CTypeID constid;\n  while (ctype_isattrib(ctt->info)) {  /* Skip attributes. */\n    ctypeid = ctype_cid(ctt->info);  /* Update ID, too. */\n    ctt = ctype_get(cp->cts, ctypeid);\n  }\n  info = ctt->info;\n  size = ctt->size;\n  if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4)\n    cp_err(cp, LJ_ERR_FFI_INVTYPE);\n  cp_check(cp, '=');\n  cp_expr_sub(cp, &k, 0);\n  constid = lj_ctype_new(cp->cts, ctp);\n  (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|ctypeid);\n  k.u32 <<= 8*(4-size);\n  if ((info & CTF_UNSIGNED))\n    k.u32 >>= 8*(4-size);\n  else\n    k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size));\n  (*ctp)->size = k.u32;\n  return constid;\n}\n\n/* Parse size in parentheses as part of attribute. */\nstatic CTSize cp_decl_sizeattr(CPState *cp)\n{\n  CTSize sz;\n  uint32_t oldtmask = cp->tmask;\n  cp->tmask = CPNS_DEFAULT;  /* Required for expression evaluator. */\n  cp_check(cp, '(');\n  sz = cp_expr_ksize(cp);\n  cp->tmask = oldtmask;\n  cp_check(cp, ')');\n  return sz;\n}\n\n/* Parse alignment attribute. */\nstatic void cp_decl_align(CPState *cp, CPDecl *decl)\n{\n  CTSize al = 4;  /* Unspecified alignment is 16 bytes. */\n  if (cp->tok == '(') {\n    al = cp_decl_sizeattr(cp);\n    al = al ? lj_fls(al) : 0;\n  }\n  CTF_INSERT(decl->attr, ALIGN, al);\n  decl->attr |= CTFP_ALIGNED;\n}\n\n/* Parse GCC asm(\"name\") redirect. */\nstatic void cp_decl_asm(CPState *cp, CPDecl *decl)\n{\n  UNUSED(decl);\n  cp_next(cp);\n  cp_check(cp, '(');\n  if (cp->tok == CTOK_STRING) {\n    GCstr *str = cp->str;\n    while (cp_next(cp) == CTOK_STRING) {\n      lj_strfmt_pushf(cp->L, \"%s%s\", strdata(str), strdata(cp->str));\n      cp->L->top--;\n      str = strV(cp->L->top);\n    }\n    decl->redir = str;\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse GCC __attribute__((mode(...))). */\nstatic void cp_decl_mode(CPState *cp, CPDecl *decl)\n{\n  cp_check(cp, '(');\n  if (cp->tok == CTOK_IDENT) {\n    const char *s = strdata(cp->str);\n    CTSize sz = 0, vlen = 0;\n    if (s[0] == '_' && s[1] == '_') s += 2;\n    if (*s == 'V') {\n      s++;\n      vlen = *s++ - '0';\n      if (*s >= '0' && *s <= '9')\n\tvlen = vlen*10 + (*s++ - '0');\n    }\n    switch (*s++) {\n    case 'Q': sz = 1; break;\n    case 'H': sz = 2; break;\n    case 'S': sz = 4; break;\n    case 'D': sz = 8; break;\n    case 'T': sz = 16; break;\n    case 'O': sz = 32; break;\n    default: goto bad_size;\n    }\n    if (*s == 'I' || *s == 'F') {\n      CTF_INSERT(decl->attr, MSIZEP, sz);\n      if (vlen) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vlen*sz));\n    }\n  bad_size:\n    cp_next(cp);\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse GCC __attribute__((...)). */\nstatic void cp_decl_gccattribute(CPState *cp, CPDecl *decl)\n{\n  cp_next(cp);\n  cp_check(cp, '(');\n  cp_check(cp, '(');\n  while (cp->tok != ')') {\n    if (cp->tok == CTOK_IDENT) {\n      GCstr *attrstr = cp->str;\n      cp_next(cp);\n      switch (lj_cparse_case(attrstr,\n\t\t\"\\007aligned\" \"\\013__aligned__\"\n\t\t\"\\006packed\" \"\\012__packed__\"\n\t\t\"\\004mode\" \"\\010__mode__\"\n\t\t\"\\013vector_size\" \"\\017__vector_size__\"\n#if LJ_TARGET_X86\n\t\t\"\\007regparm\" \"\\013__regparm__\"\n\t\t\"\\005cdecl\"  \"\\011__cdecl__\"\n\t\t\"\\010thiscall\" \"\\014__thiscall__\"\n\t\t\"\\010fastcall\" \"\\014__fastcall__\"\n\t\t\"\\007stdcall\" \"\\013__stdcall__\"\n\t\t\"\\012sseregparm\" \"\\016__sseregparm__\"\n#endif\n\t      )) {\n      case 0: case 1: /* aligned */\n\tcp_decl_align(cp, decl);\n\tbreak;\n      case 2: case 3: /* packed */\n\tdecl->attr |= CTFP_PACKED;\n\tbreak;\n      case 4: case 5: /* mode */\n\tcp_decl_mode(cp, decl);\n\tbreak;\n      case 6: case 7: /* vector_size */\n\t{\n\t  CTSize vsize = cp_decl_sizeattr(cp);\n\t  if (vsize) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vsize));\n\t}\n\tbreak;\n#if LJ_TARGET_X86\n      case 8: case 9: /* regparm */\n\tCTF_INSERT(decl->fattr, REGPARM, cp_decl_sizeattr(cp));\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case 10: case 11: /* cdecl */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_CDECL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case 12: case 13: /* thiscall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_THISCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case 14: case 15: /* fastcall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_FASTCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case 16: case 17: /* stdcall */\n\tCTF_INSERT(decl->fattr, CCONV, CTCC_STDCALL);\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n      case 18: case 19: /* sseregparm */\n\tdecl->fattr |= CTF_SSEREGPARM;\n\tdecl->fattr |= CTFP_CCONV;\n\tbreak;\n#endif\n      default:  /* Skip all other attributes. */\n\tgoto skip_attr;\n      }\n    } else if (cp->tok >= CTOK_FIRSTDECL) {  /* For __attribute((const)) etc. */\n      cp_next(cp);\n    skip_attr:\n      if (cp_opt(cp, '(')) {\n\twhile (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);\n\tcp_check(cp, ')');\n      }\n    } else {\n      break;\n    }\n    if (!cp_opt(cp, ',')) break;\n  }\n  cp_check(cp, ')');\n  cp_check(cp, ')');\n}\n\n/* Parse MSVC __declspec(...). */\nstatic void cp_decl_msvcattribute(CPState *cp, CPDecl *decl)\n{\n  cp_next(cp);\n  cp_check(cp, '(');\n  while (cp->tok == CTOK_IDENT) {\n    GCstr *attrstr = cp->str;\n    cp_next(cp);\n    if (cp_str_is(attrstr, \"align\")) {\n      cp_decl_align(cp, decl);\n    } else {  /* Ignore all other attributes. */\n      if (cp_opt(cp, '(')) {\n\twhile (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);\n\tcp_check(cp, ')');\n      }\n    }\n  }\n  cp_check(cp, ')');\n}\n\n/* Parse declaration attributes (and common qualifiers). */\nstatic void cp_decl_attributes(CPState *cp, CPDecl *decl)\n{\n  for (;;) {\n    switch (cp->tok) {\n    case CTOK_CONST: decl->attr |= CTF_CONST; break;\n    case CTOK_VOLATILE: decl->attr |= CTF_VOLATILE; break;\n    case CTOK_RESTRICT: break;  /* Ignore. */\n    case CTOK_EXTENSION: break;  /* Ignore. */\n    case CTOK_ATTRIBUTE: cp_decl_gccattribute(cp, decl); continue;\n    case CTOK_ASM: cp_decl_asm(cp, decl); continue;\n    case CTOK_DECLSPEC: cp_decl_msvcattribute(cp, decl); continue;\n    case CTOK_CCDECL:\n#if LJ_TARGET_X86\n      CTF_INSERT(decl->fattr, CCONV, cp->ct->size);\n      decl->fattr |= CTFP_CCONV;\n#endif\n      break;\n    case CTOK_PTRSZ:\n#if LJ_64\n      CTF_INSERT(decl->attr, MSIZEP, cp->ct->size);\n#endif\n      break;\n    default: return;\n    }\n    cp_next(cp);\n  }\n}\n\n/* Parse struct/union/enum name. */\nstatic CTypeID cp_struct_name(CPState *cp, CPDecl *sdecl, CTInfo info)\n{\n  CTypeID sid;\n  CType *ct;\n  cp->tmask = CPNS_STRUCT;\n  cp_next(cp);\n  cp_decl_attributes(cp, sdecl);\n  cp->tmask = CPNS_DEFAULT;\n  if (cp->tok != '{') {\n    if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n    if (cp->val.id) {  /* Name of existing struct/union/enum. */\n      sid = cp->val.id;\n      ct = cp->ct;\n      if ((ct->info ^ info) & (CTMASK_NUM|CTF_UNION))  /* Wrong type. */\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));\n    } else {  /* Create named, incomplete struct/union/enum. */\n      if ((cp->mode & CPARSE_MODE_NOIMPLICIT))\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_BADTAG, strdata(cp->str));\n      sid = lj_ctype_new(cp->cts, &ct);\n      ct->info = info;\n      ct->size = CTSIZE_INVALID;\n      ctype_setname(ct, cp->str);\n      lj_ctype_addname(cp->cts, ct, sid);\n    }\n    cp_next(cp);\n  } else {  /* Create anonymous, incomplete struct/union/enum. */\n    sid = lj_ctype_new(cp->cts, &ct);\n    ct->info = info;\n    ct->size = CTSIZE_INVALID;\n  }\n  if (cp->tok == '{') {\n    if (ct->size != CTSIZE_INVALID || ct->sib)\n      cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));\n    ct->sib = 1;  /* Indicate the type is currently being defined. */\n  }\n  return sid;\n}\n\n/* Determine field alignment. */\nstatic CTSize cp_field_align(CPState *cp, CType *ct, CTInfo info)\n{\n  CTSize align = ctype_align(info);\n  UNUSED(cp); UNUSED(ct);\n#if (LJ_TARGET_X86 && !LJ_ABI_WIN) || (LJ_TARGET_ARM && __APPLE__)\n  /* The SYSV i386 and iOS ABIs limit alignment of non-vector fields to 2^2. */\n  if (align > 2 && !(info & CTFP_ALIGNED)) {\n    if (ctype_isarray(info) && !(info & CTF_VECTOR)) {\n      do {\n\tct = ctype_rawchild(cp->cts, ct);\n\tinfo = ct->info;\n      } while (ctype_isarray(info) && !(info & CTF_VECTOR));\n    }\n    if (ctype_isnum(info) || ctype_isenum(info))\n      align = 2;\n  }\n#endif\n  return align;\n}\n\n/* Layout struct/union fields. */\nstatic void cp_struct_layout(CPState *cp, CTypeID sid, CTInfo sattr)\n{\n  CTSize bofs = 0, bmaxofs = 0;  /* Bit offset and max. bit offset. */\n  CTSize maxalign = ctype_align(sattr);\n  CType *sct = ctype_get(cp->cts, sid);\n  CTInfo sinfo = sct->info;\n  CTypeID fieldid = sct->sib;\n  while (fieldid) {\n    CType *ct = ctype_get(cp->cts, fieldid);\n    CTInfo attr = ct->size;  /* Field declaration attributes (temp.). */\n\n    if (ctype_isfield(ct->info) ||\n\t(ctype_isxattrib(ct->info, CTA_SUBTYPE) && attr)) {\n      CTSize align, amask;  /* Alignment (pow2) and alignment mask (bits). */\n      CTSize sz;\n      CTInfo info = lj_ctype_info(cp->cts, ctype_cid(ct->info), &sz);\n      CTSize bsz, csz = 8*sz;  /* Field size and container size (in bits). */\n      sinfo |= (info & (CTF_QUAL|CTF_VLA));  /* Merge pseudo-qualifiers. */\n\n      /* Check for size overflow and determine alignment. */\n      if (sz >= 0x20000000u || bofs + csz < bofs || (info & CTF_VLA)) {\n\tif (!(sz == CTSIZE_INVALID && ctype_isarray(info) &&\n\t      !(sinfo & CTF_UNION)))\n\t  cp_err(cp, LJ_ERR_FFI_INVSIZE);\n\tcsz = sz = 0;  /* Treat a[] and a[?] as zero-sized. */\n      }\n      align = cp_field_align(cp, ct, info);\n      if (((attr|sattr) & CTFP_PACKED) ||\n\t  ((attr & CTFP_ALIGNED) && ctype_align(attr) > align))\n\talign = ctype_align(attr);\n      if (cp->packstack[cp->curpack] < align)\n\talign = cp->packstack[cp->curpack];\n      if (align > maxalign) maxalign = align;\n      amask = (8u << align) - 1;\n\n      bsz = ctype_bitcsz(ct->info);  /* Bitfield size (temp.). */\n      if (bsz == CTBSZ_FIELD || !ctype_isfield(ct->info)) {\n\tbsz = csz;  /* Regular fields or subtypes always fill the container. */\n\tbofs = (bofs + amask) & ~amask;  /* Start new aligned field. */\n\tct->size = (bofs >> 3);  /* Store field offset. */\n      } else {  /* Bitfield. */\n\tif (bsz == 0 || (attr & CTFP_ALIGNED) ||\n\t    (!((attr|sattr) & CTFP_PACKED) && (bofs & amask) + bsz > csz))\n\t  bofs = (bofs + amask) & ~amask;  /* Start new aligned field. */\n\n\t/* Prefer regular field over bitfield. */\n\tif (bsz == csz && (bofs & amask) == 0) {\n\t  ct->info = CTINFO(CT_FIELD, ctype_cid(ct->info));\n\t  ct->size = (bofs >> 3);  /* Store field offset. */\n\t} else {\n\t  ct->info = CTINFO(CT_BITFIELD,\n\t    (info & (CTF_QUAL|CTF_UNSIGNED|CTF_BOOL)) +\n\t    (csz << (CTSHIFT_BITCSZ-3)) + (bsz << CTSHIFT_BITBSZ));\n#if LJ_BE\n\t  ct->info += ((csz - (bofs & (csz-1)) - bsz) << CTSHIFT_BITPOS);\n#else\n\t  ct->info += ((bofs & (csz-1)) << CTSHIFT_BITPOS);\n#endif\n\t  ct->size = ((bofs & ~(csz-1)) >> 3);  /* Store container offset. */\n\t}\n      }\n\n      /* Determine next offset or max. offset. */\n      if ((sinfo & CTF_UNION)) {\n\tif (bsz > bmaxofs) bmaxofs = bsz;\n      } else {\n\tbofs += bsz;\n      }\n    }  /* All other fields in the chain are already set up. */\n\n    fieldid = ct->sib;\n  }\n\n  /* Complete struct/union. */\n  sct->info = sinfo + CTALIGN(maxalign);\n  bofs = (sinfo & CTF_UNION) ? bmaxofs : bofs;\n  maxalign = (8u << maxalign) - 1;\n  sct->size = (((bofs + maxalign) & ~maxalign) >> 3);\n}\n\n/* Parse struct/union declaration. */\nstatic CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo)\n{\n  CTypeID sid = cp_struct_name(cp, sdecl, sinfo);\n  if (cp_opt(cp, '{')) {  /* Struct/union definition. */\n    CTypeID lastid = sid;\n    int lastdecl = 0;\n    while (cp->tok != '}') {\n      CPDecl decl;\n      CPscl scl = cp_decl_spec(cp, &decl, CDF_STATIC);\n      decl.mode = scl ? CPARSE_MODE_DIRECT :\n\tCPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD;\n\n      for (;;) {\n\tCTypeID ctypeid;\n\n\tif (lastdecl) cp_err_token(cp, '}');\n\n\t/* Parse field declarator. */\n\tdecl.bits = CTSIZE_INVALID;\n\tcp_declarator(cp, &decl);\n\tctypeid = cp_decl_intern(cp, &decl);\n\n\tif ((scl & CDF_STATIC)) {  /* Static constant in struct namespace. */\n\t  CType *ct;\n\t  CTypeID fieldid = cp_decl_constinit(cp, &ct, ctypeid);\n\t  ctype_get(cp->cts, lastid)->sib = fieldid;\n\t  lastid = fieldid;\n\t  ctype_setname(ct, decl.name);\n\t} else {\n\t  CTSize bsz = CTBSZ_FIELD;  /* Temp. for layout phase. */\n\t  CType *ct;\n\t  CTypeID fieldid = lj_ctype_new(cp->cts, &ct);  /* Do this first. */\n\t  CType *tct = ctype_raw(cp->cts, ctypeid);\n\n\t  if (decl.bits == CTSIZE_INVALID) {  /* Regular field. */\n\t    if (ctype_isarray(tct->info) && tct->size == CTSIZE_INVALID)\n\t      lastdecl = 1;  /* a[] or a[?] must be the last declared field. */\n\n\t    /* Accept transparent struct/union/enum. */\n\t    if (!decl.name) {\n\t      if (!((ctype_isstruct(tct->info) && !(tct->info & CTF_VLA)) ||\n\t\t    ctype_isenum(tct->info)))\n\t\tcp_err_token(cp, CTOK_IDENT);\n\t      ct->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_SUBTYPE) + ctypeid);\n\t      ct->size = ctype_isstruct(tct->info) ?\n\t\t\t (decl.attr|0x80000000u) : 0;  /* For layout phase. */\n\t      goto add_field;\n\t    }\n\t  } else {  /* Bitfield. */\n\t    bsz = decl.bits;\n\t    if (!ctype_isinteger_or_bool(tct->info) ||\n\t\t(bsz == 0 && decl.name) || 8*tct->size > CTBSZ_MAX ||\n\t\tbsz > ((tct->info & CTF_BOOL) ? 1 : 8*tct->size))\n\t      cp_errmsg(cp, ':', LJ_ERR_BADVAL);\n\t  }\n\n\t  /* Create temporary field for layout phase. */\n\t  ct->info = CTINFO(CT_FIELD, ctypeid + (bsz << CTSHIFT_BITCSZ));\n\t  ct->size = decl.attr;\n\t  if (decl.name) ctype_setname(ct, decl.name);\n\n\tadd_field:\n\t  ctype_get(cp->cts, lastid)->sib = fieldid;\n\t  lastid = fieldid;\n\t}\n\tif (!cp_opt(cp, ',')) break;\n\tcp_decl_reset(&decl);\n      }\n      cp_check(cp, ';');\n    }\n    cp_check(cp, '}');\n    ctype_get(cp->cts, lastid)->sib = 0;  /* Drop sib = 1 for empty structs. */\n    cp_decl_attributes(cp, sdecl);  /* Layout phase needs postfix attributes. */\n    cp_struct_layout(cp, sid, sdecl->attr);\n  }\n  return sid;\n}\n\n/* Parse enum declaration. */\nstatic CTypeID cp_decl_enum(CPState *cp, CPDecl *sdecl)\n{\n  CTypeID eid = cp_struct_name(cp, sdecl, CTINFO(CT_ENUM, CTID_VOID));\n  CTInfo einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_UINT32);\n  CTSize esize = 4;  /* Only 32 bit enums are supported. */\n  if (cp_opt(cp, '{')) {  /* Enum definition. */\n    CPValue k;\n    CTypeID lastid = eid;\n    k.u32 = 0;\n    k.id = CTID_INT32;\n    do {\n      GCstr *name = cp->str;\n      if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);\n      if (cp->val.id) cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(name));\n      cp_next(cp);\n      if (cp_opt(cp, '=')) {\n\tcp_expr_kint(cp, &k);\n\tif (k.id == CTID_UINT32) {\n\t  /* C99 says that enum constants are always (signed) integers.\n\t  ** But since unsigned constants like 0x80000000 are quite common,\n\t  ** those are left as uint32_t.\n\t  */\n\t  if (k.i32 >= 0) k.id = CTID_INT32;\n\t} else {\n\t  /* OTOH it's common practice and even mandated by some ABIs\n\t  ** that the enum type itself is unsigned, unless there are any\n\t  ** negative constants.\n\t  */\n\t  k.id = CTID_INT32;\n\t  if (k.i32 < 0) einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_INT32);\n\t}\n      }\n      /* Add named enum constant. */\n      {\n\tCType *ct;\n\tCTypeID constid = lj_ctype_new(cp->cts, &ct);\n\tctype_get(cp->cts, lastid)->sib = constid;\n\tlastid = constid;\n\tctype_setname(ct, name);\n\tct->info = CTINFO(CT_CONSTVAL, CTF_CONST|k.id);\n\tct->size = k.u32++;\n\tif (k.u32 == 0x80000000u) k.id = CTID_UINT32;\n\tlj_ctype_addname(cp->cts, ct, constid);\n      }\n      if (!cp_opt(cp, ',')) break;\n    } while (cp->tok != '}');  /* Trailing ',' is ok. */\n    cp_check(cp, '}');\n    /* Complete enum. */\n    ctype_get(cp->cts, eid)->info = einfo;\n    ctype_get(cp->cts, eid)->size = esize;\n  }\n  return eid;\n}\n\n/* Parse declaration specifiers. */\nstatic CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl)\n{\n  uint32_t cds = 0, sz = 0;\n  CTypeID tdef = 0;\n\n  decl->cp = cp;\n  decl->mode = cp->mode;\n  decl->name = NULL;\n  decl->redir = NULL;\n  decl->attr = 0;\n  decl->fattr = 0;\n  decl->pos = decl->top = 0;\n  decl->stack[0].next = 0;\n\n  for (;;) {  /* Parse basic types. */\n    cp_decl_attributes(cp, decl);\n    if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) {\n      uint32_t cbit;\n      if (cp->ct->size) {\n\tif (sz) goto end_decl;\n\tsz = cp->ct->size;\n      }\n      cbit = (1u << (cp->tok - CTOK_FIRSTDECL));\n      cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1);\n      if (cp->tok >= CTOK_FIRSTSCL) {\n\tif (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL);\n      } else if (tdef) {\n\tgoto end_decl;\n      }\n      cp_next(cp);\n      continue;\n    }\n    if (sz || tdef ||\n\t(cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX)))\n      break;\n    switch (cp->tok) {\n    case CTOK_STRUCT:\n      tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0));\n      continue;\n    case CTOK_UNION:\n      tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION));\n      continue;\n    case CTOK_ENUM:\n      tdef = cp_decl_enum(cp, decl);\n      continue;\n    case CTOK_IDENT:\n      if (ctype_istypedef(cp->ct->info)) {\n\ttdef = ctype_cid(cp->ct->info);  /* Get typedef. */\n\tcp_next(cp);\n\tcontinue;\n      }\n      break;\n    case '$':\n      tdef = cp->val.id;\n      cp_next(cp);\n      continue;\n    default:\n      break;\n    }\n    break;\n  }\nend_decl:\n\n  if ((cds & CDF_COMPLEX))  /* Use predefined complex types. */\n    tdef = sz == 4 ? CTID_COMPLEX_FLOAT : CTID_COMPLEX_DOUBLE;\n\n  if (tdef) {\n    cp_push_type(decl, tdef);\n  } else if ((cds & CDF_VOID)) {\n    cp_push(decl, CTINFO(CT_VOID, (decl->attr & CTF_QUAL)), CTSIZE_INVALID);\n    decl->attr &= ~CTF_QUAL;\n  } else {\n    /* Determine type info and size. */\n    CTInfo info = CTINFO(CT_NUM, (cds & CDF_UNSIGNED) ? CTF_UNSIGNED : 0);\n    if ((cds & CDF_BOOL)) {\n      if ((cds & ~(CDF_SCL|CDF_BOOL|CDF_INT|CDF_SIGNED|CDF_UNSIGNED)))\n\tcp_errmsg(cp, 0, LJ_ERR_FFI_INVTYPE);\n      info |= CTF_BOOL;\n      if (!(cds & CDF_SIGNED)) info |= CTF_UNSIGNED;\n      if (!sz) {\n\tsz = 1;\n      }\n    } else if ((cds & CDF_FP)) {\n      info = CTINFO(CT_NUM, CTF_FP);\n      if ((cds & CDF_LONG)) sz = sizeof(long double);\n    } else if ((cds & CDF_CHAR)) {\n      if ((cds & (CDF_CHAR|CDF_SIGNED|CDF_UNSIGNED)) == CDF_CHAR)\n\tinfo |= CTF_UCHAR;  /* Handle platforms where char is unsigned. */\n    } else if ((cds & CDF_SHORT)) {\n      sz = sizeof(short);\n    } else if ((cds & CDF_LONGLONG)) {\n      sz = 8;\n    } else if ((cds & CDF_LONG)) {\n      info |= CTF_LONG;\n      sz = sizeof(long);\n    } else if (!sz) {\n      if (!(cds & (CDF_SIGNED|CDF_UNSIGNED)))\n\tcp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC);\n      sz = sizeof(int);\n    }\n    lj_assertCP(sz != 0, \"basic ctype with zero size\");\n    info += CTALIGN(lj_fls(sz));  /* Use natural alignment. */\n    info += (decl->attr & CTF_QUAL);  /* Merge qualifiers. */\n    cp_push(decl, info, sz);\n    decl->attr &= ~CTF_QUAL;\n  }\n  decl->specpos = decl->pos;\n  decl->specattr = decl->attr;\n  decl->specfattr = decl->fattr;\n  return (cds & CDF_SCL);  /* Return storage class. */\n}\n\n/* Parse array declaration. */\nstatic void cp_decl_array(CPState *cp, CPDecl *decl)\n{\n  CTInfo info = CTINFO(CT_ARRAY, 0);\n  CTSize nelem = CTSIZE_INVALID;  /* Default size for a[] or a[?]. */\n  cp_decl_attributes(cp, decl);\n  if (cp_opt(cp, '?'))\n    info |= CTF_VLA;  /* Create variable-length array a[?]. */\n  else if (cp->tok != ']')\n    nelem = cp_expr_ksize(cp);\n  cp_check(cp, ']');\n  cp_add(decl, info, nelem);\n}\n\n/* Parse function declaration. */\nstatic void cp_decl_func(CPState *cp, CPDecl *fdecl)\n{\n  CTSize nargs = 0;\n  CTInfo info = CTINFO(CT_FUNC, 0);\n  CTypeID lastid = 0, anchor = 0;\n  if (cp->tok != ')') {\n    do {\n      CPDecl decl;\n      CTypeID ctypeid, fieldid;\n      CType *ct;\n      if (cp_opt(cp, '.')) {  /* Vararg function. */\n\tcp_check(cp, '.');  /* Workaround for the minimalistic lexer. */\n\tcp_check(cp, '.');\n\tinfo |= CTF_VARARG;\n\tbreak;\n      }\n      cp_decl_spec(cp, &decl, CDF_REGISTER);\n      decl.mode = CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT;\n      cp_declarator(cp, &decl);\n      ctypeid = cp_decl_intern(cp, &decl);\n      ct = ctype_raw(cp->cts, ctypeid);\n      if (ctype_isvoid(ct->info))\n\tbreak;\n      else if (ctype_isrefarray(ct->info))\n\tctypeid = lj_ctype_intern(cp->cts,\n\t  CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ct->info)), CTSIZE_PTR);\n      else if (ctype_isfunc(ct->info))\n\tctypeid = lj_ctype_intern(cp->cts,\n\t  CTINFO(CT_PTR, CTALIGN_PTR|ctypeid), CTSIZE_PTR);\n      /* Add new parameter. */\n      fieldid = lj_ctype_new(cp->cts, &ct);\n      if (anchor)\n\tctype_get(cp->cts, lastid)->sib = fieldid;\n      else\n\tanchor = fieldid;\n      lastid = fieldid;\n      if (decl.name) ctype_setname(ct, decl.name);\n      ct->info = CTINFO(CT_FIELD, ctypeid);\n      ct->size = nargs++;\n    } while (cp_opt(cp, ','));\n  }\n  cp_check(cp, ')');\n  if (cp_opt(cp, '{')) {  /* Skip function definition. */\n    int level = 1;\n    cp->mode |= CPARSE_MODE_SKIP;\n    for (;;) {\n      if (cp->tok == '{') level++;\n      else if (cp->tok == '}' && --level == 0) break;\n      else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}');\n      cp_next(cp);\n    }\n    cp->mode &= ~CPARSE_MODE_SKIP;\n    cp->tok = ';';  /* Ok for cp_decl_multi(), error in cp_decl_single(). */\n  }\n  info |= (fdecl->fattr & ~CTMASK_CID);\n  fdecl->fattr = 0;\n  fdecl->stack[cp_add(fdecl, info, nargs)].sib = anchor;\n}\n\n/* Parse declarator. */\nstatic void cp_declarator(CPState *cp, CPDecl *decl)\n{\n  if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);\n\n  for (;;) {  /* Head of declarator. */\n    if (cp_opt(cp, '*')) {  /* Pointer. */\n      CTSize sz;\n      CTInfo info;\n      cp_decl_attributes(cp, decl);\n      sz = CTSIZE_PTR;\n      info = CTINFO(CT_PTR, CTALIGN_PTR);\n#if LJ_64\n      if (ctype_msizeP(decl->attr) == 4) {\n\tsz = 4;\n\tinfo = CTINFO(CT_PTR, CTALIGN(2));\n      }\n#endif\n      info += (decl->attr & (CTF_QUAL|CTF_REF));\n      decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));\n      cp_push(decl, info, sz);\n    } else if (cp_opt(cp, '&') || cp_opt(cp, CTOK_ANDAND)) {  /* Reference. */\n      decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));\n      cp_push(decl, CTINFO_REF(0), CTSIZE_PTR);\n    } else {\n      break;\n    }\n  }\n\n  if (cp_opt(cp, '(')) {  /* Inner declarator. */\n    CPDeclIdx pos;\n    cp_decl_attributes(cp, decl);\n    /* Resolve ambiguity between inner declarator and 1st function parameter. */\n    if ((decl->mode & CPARSE_MODE_ABSTRACT) &&\n\t(cp->tok == ')' || cp_istypedecl(cp))) goto func_decl;\n    pos = decl->pos;\n    cp_declarator(cp, decl);\n    cp_check(cp, ')');\n    decl->pos = pos;\n  } else if (cp->tok == CTOK_IDENT) {  /* Direct declarator. */\n    if (!(decl->mode & CPARSE_MODE_DIRECT)) cp_err_token(cp, CTOK_EOF);\n    decl->name = cp->str;\n    decl->nameid = cp->val.id;\n    cp_next(cp);\n  } else {  /* Abstract declarator. */\n    if (!(decl->mode & CPARSE_MODE_ABSTRACT)) cp_err_token(cp, CTOK_IDENT);\n  }\n\n  for (;;) {  /* Tail of declarator. */\n    if (cp_opt(cp, '[')) {  /* Array. */\n      cp_decl_array(cp, decl);\n    } else if (cp_opt(cp, '(')) {  /* Function. */\n    func_decl:\n      cp_decl_func(cp, decl);\n    } else {\n      break;\n    }\n  }\n\n  if ((decl->mode & CPARSE_MODE_FIELD) && cp_opt(cp, ':'))  /* Field width. */\n    decl->bits = cp_expr_ksize(cp);\n\n  /* Process postfix attributes. */\n  cp_decl_attributes(cp, decl);\n  cp_push_attributes(decl);\n\n  cp->depth--;\n}\n\n/* Parse an abstract type declaration and return it's C type ID. */\nstatic CTypeID cp_decl_abstract(CPState *cp)\n{\n  CPDecl decl;\n  cp_decl_spec(cp, &decl, 0);\n  decl.mode = CPARSE_MODE_ABSTRACT;\n  cp_declarator(cp, &decl);\n  return cp_decl_intern(cp, &decl);\n}\n\n/* Handle pragmas. */\nstatic void cp_pragma(CPState *cp, BCLine pragmaline)\n{\n  cp_next(cp);\n  if (cp->tok == CTOK_IDENT && cp_str_is(cp->str, \"pack\"))  {\n    cp_next(cp);\n    cp_check(cp, '(');\n    if (cp->tok == CTOK_IDENT) {\n      if (cp_str_is(cp->str, \"push\")) {\n\tif (cp->curpack < CPARSE_MAX_PACKSTACK) {\n\t  cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack];\n\t  cp->curpack++;\n\t}\n      } else if (cp_str_is(cp->str, \"pop\")) {\n\tif (cp->curpack > 0) cp->curpack--;\n      } else {\n\tcp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n      }\n      cp_next(cp);\n      if (!cp_opt(cp, ',')) goto end_pack;\n    }\n    if (cp->tok == CTOK_INTEGER) {\n      cp->packstack[cp->curpack] = cp->val.u32 ? lj_fls(cp->val.u32) : 0;\n      cp_next(cp);\n    } else {\n      cp->packstack[cp->curpack] = 255;\n    }\n  end_pack:\n    cp_check(cp, ')');\n  } else {  /* Ignore all other pragmas. */\n    while (cp->tok != CTOK_EOF && cp->linenumber == pragmaline)\n      cp_next(cp);\n  }\n}\n\n/* Handle line number. */\nstatic void cp_line(CPState *cp, BCLine hashline)\n{\n  BCLine newline = cp->val.u32;\n  /* TODO: Handle file name and include it in error messages. */\n  while (cp->tok != CTOK_EOF && cp->linenumber == hashline)\n    cp_next(cp);\n  cp->linenumber = newline;\n}\n\n/* Parse multiple C declarations of types or extern identifiers. */\nstatic void cp_decl_multi(CPState *cp)\n{\n  int first = 1;\n  while (cp->tok != CTOK_EOF) {\n    CPDecl decl;\n    CPscl scl;\n    if (cp_opt(cp, ';')) {  /* Skip empty statements. */\n      first = 0;\n      continue;\n    }\n    if (cp->tok == '#') {  /* Workaround, since we have no preprocessor, yet. */\n      BCLine hashline = cp->linenumber;\n      CPToken tok = cp_next(cp);\n      if (tok == CTOK_INTEGER) {\n\tcp_line(cp, hashline);\n\tcontinue;\n      } else if (tok == CTOK_IDENT && cp_str_is(cp->str, \"line\")) {\n\tif (cp_next(cp) != CTOK_INTEGER) cp_err_token(cp, tok);\n\tcp_line(cp, hashline);\n\tcontinue;\n      } else if (tok == CTOK_IDENT && cp_str_is(cp->str, \"pragma\")) {\n\tcp_pragma(cp, hashline);\n\tcontinue;\n      } else {\n\tcp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);\n      }\n    }\n    scl = cp_decl_spec(cp, &decl, CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC);\n    if ((cp->tok == ';' || cp->tok == CTOK_EOF) &&\n\tctype_istypedef(decl.stack[0].info)) {\n      CTInfo info = ctype_rawchild(cp->cts, &decl.stack[0])->info;\n      if (ctype_isstruct(info) || ctype_isenum(info))\n\tgoto decl_end;  /* Accept empty declaration of struct/union/enum. */\n    }\n    for (;;) {\n      CTypeID ctypeid;\n      cp_declarator(cp, &decl);\n      ctypeid = cp_decl_intern(cp, &decl);\n      if (decl.name && !decl.nameid) {  /* NYI: redeclarations are ignored. */\n\tCType *ct;\n\tCTypeID id;\n\tif ((scl & CDF_TYPEDEF)) {  /* Create new typedef. */\n\t  id = lj_ctype_new(cp->cts, &ct);\n\t  ct->info = CTINFO(CT_TYPEDEF, ctypeid);\n\t  goto noredir;\n\t} else if (ctype_isfunc(ctype_get(cp->cts, ctypeid)->info)) {\n\t  /* Treat both static and extern function declarations as extern. */\n\t  ct = ctype_get(cp->cts, ctypeid);\n\t  /* We always get new anonymous functions (typedefs are copied). */\n\t  lj_assertCP(gcref(ct->name) == NULL, \"unexpected named function\");\n\t  id = ctypeid;  /* Just name it. */\n\t} else if ((scl & CDF_STATIC)) {  /* Accept static constants. */\n\t  id = cp_decl_constinit(cp, &ct, ctypeid);\n\t  goto noredir;\n\t} else {  /* External references have extern or no storage class. */\n\t  id = lj_ctype_new(cp->cts, &ct);\n\t  ct->info = CTINFO(CT_EXTERN, ctypeid);\n\t}\n\tif (decl.redir) {  /* Add attribute for redirected symbol name. */\n\t  CType *cta;\n\t  CTypeID aid = lj_ctype_new(cp->cts, &cta);\n\t  ct = ctype_get(cp->cts, id);  /* Table may have been reallocated. */\n\t  cta->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_REDIR));\n\t  cta->sib = ct->sib;\n\t  ct->sib = aid;\n\t  ctype_setname(cta, decl.redir);\n\t}\n      noredir:\n\tctype_setname(ct, decl.name);\n\tlj_ctype_addname(cp->cts, ct, id);\n      }\n      if (!cp_opt(cp, ',')) break;\n      cp_decl_reset(&decl);\n    }\n  decl_end:\n    if (cp->tok == CTOK_EOF && first) break;  /* May omit ';' for 1 decl. */\n    first = 0;\n    cp_check(cp, ';');\n  }\n}\n\n/* Parse a single C type declaration. */\nstatic void cp_decl_single(CPState *cp)\n{\n  CPDecl decl;\n  cp_decl_spec(cp, &decl, 0);\n  cp_declarator(cp, &decl);\n  cp->val.id = cp_decl_intern(cp, &decl);\n  if (cp->tok != CTOK_EOF) cp_err_token(cp, CTOK_EOF);\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Protected callback for C parser. */\nstatic TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  CPState *cp = (CPState *)ud;\n  UNUSED(dummy);\n  cframe_errfunc(L->cframe) = -1;  /* Inherit error function. */\n  cp_init(cp);\n  if ((cp->mode & CPARSE_MODE_MULTI))\n    cp_decl_multi(cp);\n  else\n    cp_decl_single(cp);\n  if (cp->param && cp->param != cp->L->top)\n    cp_err(cp, LJ_ERR_FFI_NUMPARAM);\n  lj_assertCP(cp->depth == 0, \"unbalanced cparser declaration depth\");\n  return NULL;\n}\n\n/* C parser. */\nint lj_cparse(CPState *cp)\n{\n  LJ_CTYPE_SAVE(cp->cts);\n  int errcode = lj_vm_cpcall(cp->L, NULL, cp, cpcparser);\n  if (errcode)\n    LJ_CTYPE_RESTORE(cp->cts);\n  cp_cleanup(cp);\n  return errcode;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_cparse.h",
    "content": "/*\n** C declaration parser.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CPARSE_H\n#define _LJ_CPARSE_H\n\n#include \"lj_obj.h\"\n#include \"lj_ctype.h\"\n\n#if LJ_HASFFI\n\n/* C parser limits. */\n#define CPARSE_MAX_BUF\t\t32768\t/* Max. token buffer size. */\n#define CPARSE_MAX_DECLSTACK\t100\t/* Max. declaration stack depth. */\n#define CPARSE_MAX_DECLDEPTH\t20\t/* Max. recursive declaration depth. */\n#define CPARSE_MAX_PACKSTACK\t7\t/* Max. pack pragma stack depth. */\n\n/* Flags for C parser mode. */\n#define CPARSE_MODE_MULTI\t1\t/* Process multiple declarations. */\n#define CPARSE_MODE_ABSTRACT\t2\t/* Accept abstract declarators. */\n#define CPARSE_MODE_DIRECT\t4\t/* Accept direct declarators. */\n#define CPARSE_MODE_FIELD\t8\t/* Accept field width in bits, too. */\n#define CPARSE_MODE_NOIMPLICIT\t16\t/* Reject implicit declarations. */\n#define CPARSE_MODE_SKIP\t32\t/* Skip definitions, ignore errors. */\n\ntypedef int CPChar;\t/* C parser character. Unsigned ext. from char. */\ntypedef int CPToken;\t/* C parser token. */\n\n/* C parser internal value representation. */\ntypedef struct CPValue {\n  union {\n    int32_t i32;\t/* Value for CTID_INT32. */\n    uint32_t u32;\t/* Value for CTID_UINT32. */\n  };\n  CTypeID id;\t\t/* C Type ID of the value. */\n} CPValue;\n\n/* C parser state. */\ntypedef struct CPState {\n  CPChar c;\t\t/* Current character. */\n  CPToken tok;\t\t/* Current token. */\n  CPValue val;\t\t/* Token value. */\n  GCstr *str;\t\t/* Interned string of identifier/keyword. */\n  CType *ct;\t\t/* C type table entry. */\n  const char *p;\t/* Current position in input buffer. */\n  SBuf sb;\t\t/* String buffer for tokens. */\n  lua_State *L;\t\t/* Lua state. */\n  CTState *cts;\t\t/* C type state. */\n  TValue *param;\t/* C type parameters. */\n  const char *srcname;\t/* Current source name. */\n  BCLine linenumber;\t/* Input line counter. */\n  int depth;\t\t/* Recursive declaration depth. */\n  uint32_t tmask;\t/* Type mask for next identifier. */\n  uint32_t mode;\t/* C parser mode. */\n  uint8_t packstack[CPARSE_MAX_PACKSTACK];  /* Stack for pack pragmas. */\n  uint8_t curpack;\t/* Current position in pack pragma stack. */\n} CPState;\n\nLJ_FUNC int lj_cparse(CPState *cp);\n\nLJ_FUNC int lj_cparse_case(GCstr *str, const char *match);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_crecord.c",
    "content": "/*\n** Trace recorder for C data operations.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ffrecord_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT && LJ_HASFFI\n\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_cparse.h\"\n#include \"lj_cconv.h\"\n#include \"lj_carith.h\"\n#include \"lj_clib.h\"\n#include \"lj_ccall.h\"\n#include \"lj_ff.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_snap.h\"\n#include \"lj_crecord.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_strfmt.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n#define emitconv(a, dt, st, flags) \\\n  emitir(IRT(IR_CONV, (dt)), (a), (st)|((dt) << 5)|(flags))\n\n/* -- C type checks ------------------------------------------------------- */\n\nstatic GCcdata *argv2cdata(jit_State *J, TRef tr, cTValue *o)\n{\n  GCcdata *cd;\n  TRef trtypeid;\n  if (!tref_iscdata(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  cd = cdataV(o);\n  /* Specialize to the CTypeID. */\n  trtypeid = emitir(IRT(IR_FLOAD, IRT_U16), tr, IRFL_CDATA_CTYPEID);\n  emitir(IRTG(IR_EQ, IRT_INT), trtypeid, lj_ir_kint(J, (int32_t)cd->ctypeid));\n  return cd;\n}\n\n/* Specialize to the CTypeID held by a cdata constructor. */\nstatic CTypeID crec_constructor(jit_State *J, GCcdata *cd, TRef tr)\n{\n  CTypeID id;\n  lj_assertJ(tref_iscdata(tr) && cd->ctypeid == CTID_CTYPEID,\n\t     \"expected CTypeID cdata\");\n  id = *(CTypeID *)cdataptr(cd);\n  tr = emitir(IRT(IR_FLOAD, IRT_INT), tr, IRFL_CDATA_INT);\n  emitir(IRTG(IR_EQ, IRT_INT), tr, lj_ir_kint(J, (int32_t)id));\n  return id;\n}\n\nstatic CTypeID argv2ctype(jit_State *J, TRef tr, cTValue *o)\n{\n  if (tref_isstr(tr)) {\n    GCstr *s = strV(o);\n    CPState cp;\n    CTypeID oldtop;\n    /* Specialize to the string containing the C type declaration. */\n    emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, s));\n    cp.L = J->L;\n    cp.cts = ctype_cts(J->L);\n    oldtop = cp.cts->top;\n    cp.srcname = strdata(s);\n    cp.p = strdata(s);\n    cp.param = NULL;\n    cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;\n    if (lj_cparse(&cp) || cp.cts->top > oldtop)  /* Avoid new struct defs. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    return cp.val.id;\n  } else {\n    GCcdata *cd = argv2cdata(J, tr, o);\n    return cd->ctypeid == CTID_CTYPEID ? crec_constructor(J, cd, tr) :\n\t\t\t\t\tcd->ctypeid;\n  }\n}\n\n/* Convert CType to IRType (if possible). */\nstatic IRType crec_ct2irt(CTState *cts, CType *ct)\n{\n  if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n  if (LJ_LIKELY(ctype_isnum(ct->info))) {\n    if ((ct->info & CTF_FP)) {\n      if (ct->size == sizeof(double))\n\treturn IRT_NUM;\n      else if (ct->size == sizeof(float))\n\treturn IRT_FLOAT;\n    } else {\n      uint32_t b = lj_fls(ct->size);\n      if (b <= 3)\n\treturn IRT_I8 + 2*b + ((ct->info & CTF_UNSIGNED) ? 1 : 0);\n    }\n  } else if (ctype_isptr(ct->info)) {\n    return (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n  } else if (ctype_iscomplex(ct->info)) {\n    if (ct->size == 2*sizeof(double))\n      return IRT_NUM;\n    else if (ct->size == 2*sizeof(float))\n      return IRT_FLOAT;\n  }\n  return IRT_CDATA;\n}\n\n/* -- Optimized memory fill and copy -------------------------------------- */\n\n/* Maximum length and unroll of inlined copy/fill. */\n#define CREC_COPY_MAXUNROLL\t\t16\n#define CREC_COPY_MAXLEN\t\t128\n\n#define CREC_FILL_MAXUNROLL\t\t16\n\n/* Number of windowed registers used for optimized memory copy. */\n#if LJ_TARGET_X86\n#define CREC_COPY_REGWIN\t\t2\n#elif LJ_TARGET_PPC || LJ_TARGET_MIPS\n#define CREC_COPY_REGWIN\t\t8\n#else\n#define CREC_COPY_REGWIN\t\t4\n#endif\n\n/* List of memory offsets for copy/fill. */\ntypedef struct CRecMemList {\n  CTSize ofs;\t\t/* Offset in bytes. */\n  IRType tp;\t\t/* Type of load/store. */\n  TRef trofs;\t\t/* TRef of interned offset. */\n  TRef trval;\t\t/* TRef of load value. */\n} CRecMemList;\n\n/* Generate copy list for element-wise struct copy. */\nstatic MSize crec_copy_struct(CRecMemList *ml, CTState *cts, CType *ct)\n{\n  CTypeID fid = ct->sib;\n  MSize mlp = 0;\n  while (fid) {\n    CType *df = ctype_get(cts, fid);\n    fid = df->sib;\n    if (ctype_isfield(df->info)) {\n      CType *cct;\n      IRType tp;\n      if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n      cct = ctype_rawchild(cts, df);  /* Field type. */\n      tp = crec_ct2irt(cts, cct);\n      if (tp == IRT_CDATA) return 0;  /* NYI: aggregates. */\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = df->size;\n      ml[mlp].tp = tp;\n      mlp++;\n      if (ctype_iscomplex(cct->info)) {\n\tif (mlp >= CREC_COPY_MAXUNROLL) return 0;\n\tml[mlp].ofs = df->size + (cct->size >> 1);\n\tml[mlp].tp = tp;\n\tmlp++;\n      }\n    } else if (!ctype_isconstval(df->info)) {\n      /* NYI: bitfields and sub-structures. */\n      return 0;\n    }\n  }\n  return mlp;\n}\n\n/* Generate unrolled copy list, from highest to lowest step size/alignment. */\nstatic MSize crec_copy_unroll(CRecMemList *ml, CTSize len, CTSize step,\n\t\t\t      IRType tp)\n{\n  CTSize ofs = 0;\n  MSize mlp = 0;\n  if (tp == IRT_CDATA) tp = IRT_U8 + 2*lj_fls(step);\n  do {\n    while (ofs + step <= len) {\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = ofs;\n      ml[mlp].tp = tp;\n      mlp++;\n      ofs += step;\n    }\n    step >>= 1;\n    tp -= 2;\n  } while (ofs < len);\n  return mlp;\n}\n\n/*\n** Emit copy list with windowed loads/stores.\n** LJ_TARGET_UNALIGNED: may emit unaligned loads/stores (not marked as such).\n*/\nstatic void crec_copy_emit(jit_State *J, CRecMemList *ml, MSize mlp,\n\t\t\t   TRef trdst, TRef trsrc)\n{\n  MSize i, j, rwin = 0;\n  for (i = 0, j = 0; i < mlp; ) {\n    TRef trofs = lj_ir_kintp(J, ml[i].ofs);\n    TRef trsptr = emitir(IRT(IR_ADD, IRT_PTR), trsrc, trofs);\n    ml[i].trval = emitir(IRT(IR_XLOAD, ml[i].tp), trsptr, 0);\n    ml[i].trofs = trofs;\n    i++;\n    rwin += (LJ_SOFTFP32 && ml[i].tp == IRT_NUM) ? 2 : 1;\n    if (rwin >= CREC_COPY_REGWIN || i >= mlp) {  /* Flush buffered stores. */\n      rwin = 0;\n      for ( ; j < i; j++) {\n\tTRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, ml[j].trofs);\n\temitir(IRT(IR_XSTORE, ml[j].tp), trdptr, ml[j].trval);\n      }\n    }\n  }\n}\n\n/* Optimized memory copy. */\nstatic void crec_copy(jit_State *J, TRef trdst, TRef trsrc, TRef trlen,\n\t\t      CType *ct)\n{\n  if (tref_isk(trlen)) {  /* Length must be constant. */\n    CRecMemList ml[CREC_COPY_MAXUNROLL];\n    MSize mlp = 0;\n    CTSize step = 1, len = (CTSize)IR(tref_ref(trlen))->i;\n    IRType tp = IRT_CDATA;\n    int needxbar = 0;\n    if (len == 0) return;  /* Shortcut. */\n    if (len > CREC_COPY_MAXLEN) goto fallback;\n    if (ct) {\n      CTState *cts = ctype_ctsG(J2G(J));\n      lj_assertJ(ctype_isarray(ct->info) || ctype_isstruct(ct->info),\n\t\t \"copy of non-aggregate\");\n      if (ctype_isarray(ct->info)) {\n\tCType *cct = ctype_rawchild(cts, ct);\n\ttp = crec_ct2irt(cts, cct);\n\tif (tp == IRT_CDATA) goto rawcopy;\n\tstep = lj_ir_type_size[tp];\n\tlj_assertJ((len & (step-1)) == 0, \"copy of fractional size\");\n      } else if ((ct->info & CTF_UNION)) {\n\tstep = (1u << ctype_align(ct->info));\n\tgoto rawcopy;\n      } else {\n\tmlp = crec_copy_struct(ml, cts, ct);\n\tgoto emitcopy;\n      }\n    } else {\n    rawcopy:\n      needxbar = 1;\n      if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)\n\tstep = CTSIZE_PTR;\n    }\n    mlp = crec_copy_unroll(ml, len, step, tp);\n  emitcopy:\n    if (mlp) {\n      crec_copy_emit(J, ml, mlp, trdst, trsrc);\n      if (needxbar)\n\temitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n      return;\n    }\n  }\nfallback:\n  /* Call memcpy. Always needs a barrier to disable alias analysis. */\n  lj_ir_call(J, IRCALL_memcpy, trdst, trsrc, trlen);\n  emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n}\n\n/* Generate unrolled fill list, from highest to lowest step size/alignment. */\nstatic MSize crec_fill_unroll(CRecMemList *ml, CTSize len, CTSize step)\n{\n  CTSize ofs = 0;\n  MSize mlp = 0;\n  IRType tp = IRT_U8 + 2*lj_fls(step);\n  do {\n    while (ofs + step <= len) {\n      if (mlp >= CREC_COPY_MAXUNROLL) return 0;\n      ml[mlp].ofs = ofs;\n      ml[mlp].tp = tp;\n      mlp++;\n      ofs += step;\n    }\n    step >>= 1;\n    tp -= 2;\n  } while (ofs < len);\n  return mlp;\n}\n\n/*\n** Emit stores for fill list.\n** LJ_TARGET_UNALIGNED: may emit unaligned stores (not marked as such).\n*/\nstatic void crec_fill_emit(jit_State *J, CRecMemList *ml, MSize mlp,\n\t\t\t   TRef trdst, TRef trfill)\n{\n  MSize i;\n  for (i = 0; i < mlp; i++) {\n    TRef trofs = lj_ir_kintp(J, ml[i].ofs);\n    TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, trofs);\n    emitir(IRT(IR_XSTORE, ml[i].tp), trdptr, trfill);\n  }\n}\n\n/* Optimized memory fill. */\nstatic void crec_fill(jit_State *J, TRef trdst, TRef trlen, TRef trfill,\n\t\t      CTSize step)\n{\n  if (tref_isk(trlen)) {  /* Length must be constant. */\n    CRecMemList ml[CREC_FILL_MAXUNROLL];\n    MSize mlp;\n    CTSize len = (CTSize)IR(tref_ref(trlen))->i;\n    if (len == 0) return;  /* Shortcut. */\n    if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)\n      step = CTSIZE_PTR;\n    if (step * CREC_FILL_MAXUNROLL < len) goto fallback;\n    mlp = crec_fill_unroll(ml, len, step);\n    if (!mlp) goto fallback;\n    if (tref_isk(trfill) || ml[0].tp != IRT_U8)\n      trfill = emitconv(trfill, IRT_INT, IRT_U8, 0);\n    if (ml[0].tp != IRT_U8) {  /* Scatter U8 to U16/U32/U64. */\n      if (CTSIZE_PTR == 8 && ml[0].tp == IRT_U64) {\n\tif (tref_isk(trfill))  /* Pointless on x64 with zero-extended regs. */\n\t  trfill = emitconv(trfill, IRT_U64, IRT_U32, 0);\n\ttrfill = emitir(IRT(IR_MUL, IRT_U64), trfill,\n\t\t\tlj_ir_kint64(J, U64x(01010101,01010101)));\n      } else {\n\ttrfill = emitir(IRTI(IR_MUL), trfill,\n\t\t   lj_ir_kint(J, ml[0].tp == IRT_U16 ? 0x0101 : 0x01010101));\n      }\n    }\n    crec_fill_emit(J, ml, mlp, trdst, trfill);\n  } else {\nfallback:\n    /* Call memset. Always needs a barrier to disable alias analysis. */\n    lj_ir_call(J, IRCALL_memset, trdst, trfill, trlen);  /* Note: arg order! */\n  }\n  emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n}\n\n/* -- Convert C type to C type -------------------------------------------- */\n\n/*\n** This code mirrors the code in lj_cconv.c. It performs the same steps\n** for the trace recorder that lj_cconv.c does for the interpreter.\n**\n** One major difference is that we can get away with much fewer checks\n** here. E.g. checks for casts, constness or correct types can often be\n** omitted, even if they might fail. The interpreter subsequently throws\n** an error, which aborts the trace.\n**\n** All operations are specialized to their C types, so the on-trace\n** outcome must be the same as the outcome in the interpreter. If the\n** interpreter doesn't throw an error, then the trace is correct, too.\n** Care must be taken not to generate invalid (temporary) IR or to\n** trigger asserts.\n*/\n\n/* Determine whether a passed number or cdata number is non-zero. */\nstatic int crec_isnonzero(CType *s, void *p)\n{\n  if (p == (void *)0)\n    return 0;\n  if (p == (void *)1)\n    return 1;\n  if ((s->info & CTF_FP)) {\n    if (s->size == sizeof(float))\n      return (*(float *)p != 0);\n    else\n      return (*(double *)p != 0);\n  } else {\n    if (s->size == 1)\n      return (*(uint8_t *)p != 0);\n    else if (s->size == 2)\n      return (*(uint16_t *)p != 0);\n    else if (s->size == 4)\n      return (*(uint32_t *)p != 0);\n    else\n      return (*(uint64_t *)p != 0);\n  }\n}\n\nstatic TRef crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp,\n\t\t       void *svisnz)\n{\n  IRType dt = crec_ct2irt(ctype_ctsG(J2G(J)), d);\n  IRType st = crec_ct2irt(ctype_ctsG(J2G(J)), s);\n  CTSize dsize = d->size, ssize = s->size;\n  CTInfo dinfo = d->info, sinfo = s->info;\n\n  if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)\n    goto err_conv;\n\n  /*\n  ** Note: Unlike lj_cconv_ct_ct(), sp holds the _value_ of pointers and\n  ** numbers up to 8 bytes. Otherwise sp holds a pointer.\n  */\n\n  switch (cconv_idx2(dinfo, sinfo)) {\n  /* Destination is a bool. */\n  case CCX(B, B):\n    goto xstore;  /* Source operand is already normalized. */\n  case CCX(B, I):\n  case CCX(B, F):\n    if (st != IRT_CDATA) {\n      /* Specialize to the result of a comparison against 0. */\n      TRef zero = (st == IRT_NUM  || st == IRT_FLOAT) ? lj_ir_knum(J, 0) :\n\t\t  (st == IRT_I64 || st == IRT_U64) ? lj_ir_kint64(J, 0) :\n\t\t  lj_ir_kint(J, 0);\n      int isnz = crec_isnonzero(s, svisnz);\n      emitir(IRTG(isnz ? IR_NE : IR_EQ, st), sp, zero);\n      sp = lj_ir_kint(J, isnz);\n      goto xstore;\n    }\n    goto err_nyi;\n\n  /* Destination is an integer. */\n  case CCX(I, B):\n  case CCX(I, I):\n  conv_I_I:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    /* Extend 32 to 64 bit integer. */\n    if (dsize == 8 && ssize < 8 && !(LJ_64 && (sinfo & CTF_UNSIGNED)))\n      sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st,\n\t\t    (sinfo & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);\n    else if (dsize < 8 && ssize == 8)  /* Truncate from 64 bit integer. */\n      sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, 0);\n    else if (st == IRT_INT)\n      sp = lj_opt_narrow_toint(J, sp);\n  xstore:\n    if (dt == IRT_I64 || dt == IRT_U64) lj_needsplit(J);\n    if (dp == 0) return sp;\n    emitir(IRT(IR_XSTORE, dt), dp, sp);\n    break;\n  case CCX(I, C):\n    sp = emitir(IRT(IR_XLOAD, st), sp, 0);  /* Load re. */\n    /* fallthrough */\n  case CCX(I, F):\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, IRCONV_ANY);\n    goto xstore;\n  case CCX(I, P):\n  case CCX(I, A):\n    sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);\n    ssize = CTSIZE_PTR;\n    st = IRT_UINTP;\n    if (((dsize ^ ssize) & 8) == 0) {  /* Must insert no-op type conversion. */\n      sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, IRT_PTR, 0);\n      goto xstore;\n    }\n    goto conv_I_I;\n\n  /* Destination is a floating-point number. */\n  case CCX(F, B):\n  case CCX(F, I):\n  conv_F_I:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, 0);\n    goto xstore;\n  case CCX(F, C):\n    sp = emitir(IRT(IR_XLOAD, st), sp, 0);  /* Load re. */\n    /* fallthrough */\n  case CCX(F, F):\n  conv_F_F:\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    if (dt != st) sp = emitconv(sp, dt, st, 0);\n    goto xstore;\n\n  /* Destination is a complex number. */\n  case CCX(C, I):\n  case CCX(C, F):\n    {  /* Clear im. */\n      TRef ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));\n      emitir(IRT(IR_XSTORE, dt), ptr, lj_ir_knum(J, 0));\n    }\n    /* Convert to re. */\n    if ((sinfo & CTF_FP)) goto conv_F_F; else goto conv_F_I;\n\n  case CCX(C, C):\n    if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;\n    {\n      TRef re, im, ptr;\n      re = emitir(IRT(IR_XLOAD, st), sp, 0);\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, (ssize >> 1)));\n      im = emitir(IRT(IR_XLOAD, st), ptr, 0);\n      if (dt != st) {\n\tre = emitconv(re, dt, st, 0);\n\tim = emitconv(im, dt, st, 0);\n      }\n      emitir(IRT(IR_XSTORE, dt), dp, re);\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));\n      emitir(IRT(IR_XSTORE, dt), ptr, im);\n    }\n    break;\n\n  /* Destination is a vector. */\n  case CCX(V, I):\n  case CCX(V, F):\n  case CCX(V, C):\n  case CCX(V, V):\n    goto err_nyi;\n\n  /* Destination is a pointer. */\n  case CCX(P, P):\n  case CCX(P, A):\n  case CCX(P, S):\n    /* There are only 32 bit pointers/addresses on 32 bit machines.\n    ** Also ok on x64, since all 32 bit ops clear the upper part of the reg.\n    */\n    goto xstore;\n  case CCX(P, I):\n    if (st == IRT_CDATA) goto err_nyi;\n    if (!LJ_64 && ssize == 8)  /* Truncate from 64 bit integer. */\n      sp = emitconv(sp, IRT_U32, st, 0);\n    goto xstore;\n  case CCX(P, F):\n    if (st == IRT_CDATA) goto err_nyi;\n    /* The signed conversion is cheaper. x64 really has 47 bit pointers. */\n    sp = emitconv(sp, (LJ_64 && dsize == 8) ? IRT_I64 : IRT_U32,\n\t\t  st, IRCONV_ANY);\n    goto xstore;\n\n  /* Destination is an array. */\n  case CCX(A, A):\n  /* Destination is a struct/union. */\n  case CCX(S, S):\n    if (dp == 0) goto err_conv;\n    crec_copy(J, dp, sp, lj_ir_kint(J, dsize), d);\n    break;\n\n  default:\n  err_conv:\n  err_nyi:\n    lj_trace_err(J, LJ_TRERR_NYICONV);\n    break;\n  }\n  return 0;\n}\n\n/* -- Convert C type to TValue (load) ------------------------------------- */\n\nstatic TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  IRType t = crec_ct2irt(cts, s);\n  CTInfo sinfo = s->info;\n  if (ctype_isnum(sinfo)) {\n    TRef tr;\n    if (t == IRT_CDATA)\n      goto err_nyi;  /* NYI: copyval of >64 bit integers. */\n    tr = emitir(IRT(IR_XLOAD, t), sp, 0);\n    if (t == IRT_FLOAT || t == IRT_U32) {  /* Keep uint32_t/float as numbers. */\n      return emitconv(tr, IRT_NUM, t, 0);\n    } else if (t == IRT_I64 || t == IRT_U64) {  /* Box 64 bit integer. */\n      sp = tr;\n      lj_needsplit(J);\n    } else if ((sinfo & CTF_BOOL)) {\n      /* Assume not equal to zero. Fixup and emit pending guard later. */\n      lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      return tr;\n    }\n  } else if (ctype_isptr(sinfo) || ctype_isenum(sinfo)) {\n    sp = emitir(IRT(IR_XLOAD, t), sp, 0);  /* Box pointers and enums. */\n  } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {\n    cts->L = J->L;\n    sid = lj_ctype_intern(cts, CTINFO_REF(sid), CTSIZE_PTR);  /* Create ref. */\n  } else if (ctype_iscomplex(sinfo)) {  /* Unbox/box complex. */\n    ptrdiff_t esz = (ptrdiff_t)(s->size >> 1);\n    TRef ptr, tr1, tr2, dp;\n    dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL);\n    tr1 = emitir(IRT(IR_XLOAD, t), sp, 0);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz));\n    tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)));\n    emitir(IRT(IR_XSTORE, t), ptr, tr1);\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)+esz));\n    emitir(IRT(IR_XSTORE, t), ptr, tr2);\n    return dp;\n  } else {\n    /* NYI: copyval of vectors. */\n  err_nyi:\n    lj_trace_err(J, LJ_TRERR_NYICONV);\n  }\n  /* Box pointer, ref, enum or 64 bit integer. */\n  return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, sid), sp);\n}\n\n/* -- Convert TValue to C type (store) ------------------------------------ */\n\nstatic TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID sid = CTID_P_VOID;\n  void *svisnz = 0;\n  CType *s;\n  if (LJ_LIKELY(tref_isinteger(sp))) {\n    sid = CTID_INT32;\n    svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));\n  } else if (tref_isnum(sp)) {\n    sid = CTID_DOUBLE;\n    svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));\n  } else if (tref_isbool(sp)) {\n    sp = lj_ir_kint(J, tref_istrue(sp) ? 1 : 0);\n    sid = CTID_BOOL;\n  } else if (tref_isnil(sp)) {\n    sp = lj_ir_kptr(J, NULL);\n  } else if (tref_isudata(sp)) {\n    GCudata *ud = udataV(sval);\n    if (ud->udtype == UDTYPE_IO_FILE || ud->udtype == UDTYPE_BUFFER) {\n      TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE);\n      emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, ud->udtype));\n      sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp,\n\t\t  ud->udtype == UDTYPE_IO_FILE ? IRFL_UDATA_FILE :\n\t\t\t\t\t\t IRFL_SBUF_R);\n    } else {\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCudata)));\n    }\n  } else if (tref_isstr(sp)) {\n    if (ctype_isenum(d->info)) {  /* Match string against enum constant. */\n      GCstr *str = strV(sval);\n      CTSize ofs;\n      CType *cct = lj_ctype_getfield(cts, d, str, &ofs);\n      /* Specialize to the name of the enum constant. */\n      emitir(IRTG(IR_EQ, IRT_STR), sp, lj_ir_kstr(J, str));\n      if (cct && ctype_isconstval(cct->info)) {\n\tlj_assertJ(ctype_child(cts, cct)->size == 4,\n\t\t   \"only 32 bit const supported\");  /* NYI */\n\tsvisnz = (void *)(intptr_t)(ofs != 0);\n\tsp = lj_ir_kint(J, (int32_t)ofs);\n\tsid = ctype_cid(cct->info);\n      }  /* else: interpreter will throw. */\n    } else if (ctype_isrefarray(d->info)) {  /* Copy string to array. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);  /* NYI */\n    } else {  /* Otherwise pass the string data as a const char[]. */\n      /* Don't use STRREF. It folds with SNEW, which loses the trailing NUL. */\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCstr)));\n      sid = CTID_A_CCHAR;\n    }\n  } else if (tref_islightud(sp)) {\n#if LJ_64\n    lj_trace_err(J, LJ_TRERR_NYICONV);\n#endif\n  } else {  /* NYI: tref_istab(sp). */\n    IRType t;\n    sid = argv2cdata(J, sp, sval)->ctypeid;\n    s = ctype_raw(cts, sid);\n    svisnz = cdataptr(cdataV(sval));\n    if (ctype_isfunc(s->info)) {\n      sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);\n      s = ctype_get(cts, sid);\n      t = IRT_PTR;\n    } else {\n      t = crec_ct2irt(cts, s);\n    }\n    if (ctype_isptr(s->info)) {\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR);\n      if (ctype_isref(s->info)) {\n\tsvisnz = *(void **)svisnz;\n\ts = ctype_rawchild(cts, s);\n\tif (ctype_isenum(s->info)) s = ctype_child(cts, s);\n\tt = crec_ct2irt(cts, s);\n      } else {\n\tgoto doconv;\n      }\n    } else if (t == IRT_I64 || t == IRT_U64) {\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64);\n      lj_needsplit(J);\n      goto doconv;\n    } else if (t == IRT_INT || t == IRT_U32) {\n      if (ctype_isenum(s->info)) s = ctype_child(cts, s);\n      sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT);\n      goto doconv;\n    } else {\n      sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata)));\n    }\n    if (ctype_isnum(s->info) && t != IRT_CDATA)\n      sp = emitir(IRT(IR_XLOAD, t), sp, 0);  /* Load number value. */\n    goto doconv;\n  }\n  s = ctype_get(cts, sid);\ndoconv:\n  if (ctype_isenum(d->info)) d = ctype_child(cts, d);\n  return crec_ct_ct(J, d, s, dp, sp, svisnz);\n}\n\n/* -- C data metamethods -------------------------------------------------- */\n\n/* This would be rather difficult in FOLD, so do it here:\n** (base+k)+(idx*sz)+ofs ==> (base+idx*sz)+(ofs+k)\n** (base+(idx+k)*sz)+ofs ==> (base+idx*sz)+(ofs+k*sz)\n*/\nstatic TRef crec_reassoc_ofs(jit_State *J, TRef tr, ptrdiff_t *ofsp, MSize sz)\n{\n  IRIns *ir = IR(tref_ref(tr));\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && irref_isk(ir->op2) &&\n      (ir->o == IR_ADD || ir->o == IR_ADDOV || ir->o == IR_SUBOV)) {\n    IRIns *irk = IR(ir->op2);\n    ptrdiff_t k;\n    if (LJ_64 && irk->o == IR_KINT64)\n      k = (ptrdiff_t)ir_kint64(irk)->u64 * sz;\n    else\n      k = (ptrdiff_t)irk->i * sz;\n    if (ir->o == IR_SUBOV) *ofsp -= k; else *ofsp += k;\n    tr = ir->op1;  /* Not a TRef, but the caller doesn't care. */\n  }\n  return tr;\n}\n\n/* Tailcall to function. */\nstatic void crec_tailcall(jit_State *J, RecordFFData *rd, cTValue *tv)\n{\n  TRef kfunc = lj_ir_kfunc(J, funcV(tv));\n#if LJ_FR2\n  J->base[-2] = kfunc;\n  J->base[-1] = TREF_FRAME;\n#else\n  J->base[-1] = kfunc | TREF_FRAME;\n#endif\n  rd->nres = -1;  /* Pending tailcall. */\n}\n\n/* Record ctype __index/__newindex metamethods. */\nstatic void crec_index_meta(jit_State *J, CTState *cts, CType *ct,\n\t\t\t    RecordFFData *rd)\n{\n  CTypeID id = ctype_typeid(cts, ct);\n  cTValue *tv = lj_ctype_meta(cts, id, rd->data ? MM_newindex : MM_index);\n  if (!tv)\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  if (tvisfunc(tv)) {\n    crec_tailcall(J, rd, tv);\n  } else if (rd->data == 0 && tvistab(tv) && tref_isstr(J->base[1])) {\n    /* Specialize to result of __index lookup. */\n    cTValue *o = lj_tab_get(J->L, tabV(tv), &rd->argv[1]);\n    J->base[0] = lj_record_constify(J, o);\n    if (!J->base[0])\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    /* Always specialize to the key. */\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));\n  } else {\n    /* NYI: resolving of non-function metamethods. */\n    /* NYI: non-string keys for __index table. */\n    /* NYI: stores to __newindex table. */\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n}\n\n/* Record bitfield load/store. */\nstatic void crec_index_bf(jit_State *J, RecordFFData *rd, TRef ptr, CTInfo info)\n{\n  IRType t = IRT_I8 + 2*lj_fls(ctype_bitcsz(info)) + ((info&CTF_UNSIGNED)?1:0);\n  TRef tr = emitir(IRT(IR_XLOAD, t), ptr, 0);\n  CTSize pos = ctype_bitpos(info), bsz = ctype_bitbsz(info), shift = 32 - bsz;\n  lj_assertJ(t <= IRT_U32, \"only 32 bit bitfields supported\");  /* NYI */\n  if (rd->data == 0) {  /* __index metamethod. */\n    if ((info & CTF_BOOL)) {\n      tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << pos))));\n      /* Assume not equal to zero. Fixup and emit pending guard later. */\n      lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));\n      J->postproc = LJ_POST_FIXGUARD;\n      tr = TREF_TRUE;\n    } else if (!(info & CTF_UNSIGNED)) {\n      tr = emitir(IRTI(IR_BSHL), tr, lj_ir_kint(J, shift - pos));\n      tr = emitir(IRTI(IR_BSAR), tr, lj_ir_kint(J, shift));\n    } else {\n      lj_assertJ(bsz < 32, \"unexpected full bitfield index\");\n      tr = emitir(IRTI(IR_BSHR), tr, lj_ir_kint(J, pos));\n      tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << bsz)-1)));\n      /* We can omit the U32 to NUM conversion, since bsz < 32. */\n    }\n    J->base[0] = tr;\n  } else {  /* __newindex metamethod. */\n    CTState *cts = ctype_ctsG(J2G(J));\n    CType *ct = ctype_get(cts,\n\t\t\t  (info & CTF_BOOL) ? CTID_BOOL :\n\t\t\t  (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32);\n    int32_t mask = (int32_t)(((1u << bsz)-1) << pos);\n    TRef sp = crec_ct_tv(J, ct, 0, J->base[2], &rd->argv[2]);\n    sp = emitir(IRTI(IR_BSHL), sp, lj_ir_kint(J, pos));\n    /* Use of the target type avoids forwarding conversions. */\n    sp = emitir(IRT(IR_BAND, t), sp, lj_ir_kint(J, mask));\n    tr = emitir(IRT(IR_BAND, t), tr, lj_ir_kint(J, (int32_t)~mask));\n    tr = emitir(IRT(IR_BOR, t), tr, sp);\n    emitir(IRT(IR_XSTORE, t), ptr, tr);\n    rd->nres = 0;\n    J->needsnap = 1;\n  }\n}\n\nvoid LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)\n{\n  TRef idx, ptr = J->base[0];\n  ptrdiff_t ofs = sizeof(GCcdata);\n  GCcdata *cd = argv2cdata(J, ptr, &rd->argv[0]);\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  CTypeID sid = 0;\n\n  /* Resolve pointer or reference for cdata object. */\n  if (ctype_isptr(ct->info)) {\n    IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n    if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);\n    ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR);\n    ofs = 0;\n    ptr = crec_reassoc_ofs(J, ptr, &ofs, 1);\n  }\n\nagain:\n  idx = J->base[1];\n  if (tref_isnumber(idx)) {\n    idx = lj_opt_narrow_cindex(J, idx);\n    if (ctype_ispointer(ct->info)) {\n      CTSize sz;\n  integer_key:\n      if ((ct->info & CTF_COMPLEX))\n\tidx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1));\n      sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));\n      idx = crec_reassoc_ofs(J, idx, &ofs, sz);\n#if LJ_TARGET_ARM || LJ_TARGET_PPC\n      /* Hoist base add to allow fusion of index/shift into operands. */\n      if (LJ_LIKELY(J->flags & JIT_F_OPT_LOOP) && ofs\n#if LJ_TARGET_ARM\n\t  && (sz == 1 || sz == 4)\n#endif\n\t  ) {\n\tptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));\n\tofs = 0;\n      }\n#endif\n      idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz));\n      ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);\n    }\n  } else if (tref_iscdata(idx)) {\n    GCcdata *cdk = cdataV(&rd->argv[1]);\n    CType *ctk = ctype_raw(cts, cdk->ctypeid);\n    IRType t = crec_ct2irt(cts, ctk);\n    if (ctype_ispointer(ct->info) && t >= IRT_I8 && t <= IRT_U64) {\n      if (ctk->size == 8) {\n\tidx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT64);\n      } else if (ctk->size == 4) {\n\tidx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT);\n      } else {\n\tidx = emitir(IRT(IR_ADD, IRT_PTR), idx,\n\t\t     lj_ir_kintp(J, sizeof(GCcdata)));\n\tidx = emitir(IRT(IR_XLOAD, t), idx, 0);\n      }\n      if (LJ_64 && ctk->size < sizeof(intptr_t) && !(ctk->info & CTF_UNSIGNED))\n\tidx = emitconv(idx, IRT_INTP, IRT_INT, IRCONV_SEXT);\n      if (!LJ_64 && ctk->size > sizeof(intptr_t)) {\n\tidx = emitconv(idx, IRT_INTP, t, 0);\n\tlj_needsplit(J);\n      }\n      goto integer_key;\n    }\n  } else if (tref_isstr(idx)) {\n    GCstr *name = strV(&rd->argv[1]);\n    if (cd && cd->ctypeid == CTID_CTYPEID)\n      ct = ctype_raw(cts, crec_constructor(J, cd, ptr));\n    if (ctype_isstruct(ct->info)) {\n      CTSize fofs;\n      CType *fct;\n      fct = lj_ctype_getfield(cts, ct, name, &fofs);\n      if (fct) {\n\tofs += (ptrdiff_t)fofs;\n\t/* Always specialize to the field name. */\n\temitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));\n\tif (ctype_isconstval(fct->info)) {\n\t  if (fct->size >= 0x80000000u &&\n\t      (ctype_child(cts, fct)->info & CTF_UNSIGNED)) {\n\t    J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)fct->size);\n\t    return;\n\t  }\n\t  J->base[0] = lj_ir_kint(J, (int32_t)fct->size);\n\t  return;  /* Interpreter will throw for newindex. */\n\t} else if (ctype_isbitfield(fct->info)) {\n\t  if (ofs)\n\t    ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));\n\t  crec_index_bf(J, rd, ptr, fct->info);\n\t  return;\n\t} else {\n\t  lj_assertJ(ctype_isfield(fct->info), \"field expected\");\n\t  sid = ctype_cid(fct->info);\n\t}\n      }\n    } else if (ctype_iscomplex(ct->info)) {\n      if (name->len == 2 &&\n\t  ((strdata(name)[0] == 'r' && strdata(name)[1] == 'e') ||\n\t   (strdata(name)[0] == 'i' && strdata(name)[1] == 'm'))) {\n\t/* Always specialize to the field name. */\n\temitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));\n\tif (strdata(name)[0] == 'i') ofs += (ct->size >> 1);\n\tsid = ctype_cid(ct->info);\n      }\n    }\n  }\n  if (!sid) {\n    if (ctype_isptr(ct->info)) {  /* Automatically perform '->'. */\n      CType *cct = ctype_rawchild(cts, ct);\n      if (ctype_isstruct(cct->info)) {\n\tct = cct;\n\tcd = NULL;\n\tif (tref_isstr(idx)) goto again;\n      }\n    }\n    crec_index_meta(J, cts, ct, rd);\n    return;\n  }\n\n  if (ofs)\n    ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));\n\n  /* Resolve reference for field. */\n  ct = ctype_get(cts, sid);\n  if (ctype_isref(ct->info)) {\n    ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0);\n    sid = ctype_cid(ct->info);\n    ct = ctype_get(cts, sid);\n  }\n\n  while (ctype_isattrib(ct->info))\n    ct = ctype_child(cts, ct);  /* Skip attributes. */\n\n  if (rd->data == 0) {  /* __index metamethod. */\n    J->base[0] = crec_tv_ct(J, ct, sid, ptr);\n  } else {  /* __newindex metamethod. */\n    rd->nres = 0;\n    J->needsnap = 1;\n    crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);\n  }\n}\n\n/* Record setting a finalizer. */\nstatic void crec_finalizer(jit_State *J, TRef trcd, TRef trfin, cTValue *fin)\n{\n  if (tvisgcv(fin)) {\n    if (!trfin) trfin = lj_ir_kptr(J, gcval(fin));\n  } else if (tvisnil(fin)) {\n    trfin = lj_ir_kptr(J, NULL);\n  } else {\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd,\n\t     trfin, lj_ir_kint(J, (int32_t)itype(fin)));\n  J->needsnap = 1;\n}\n\n/* Record cdata allocation. */\nstatic void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTSize sz;\n  CTInfo info = lj_ctype_info(cts, id, &sz);\n  CType *d = ctype_raw(cts, id);\n  TRef trcd, trid = lj_ir_kint(J, id);\n  cTValue *fin;\n  /* Use special instruction to box pointer or 32/64 bit integer. */\n  if (ctype_isptr(info) || (ctype_isinteger(info) && (sz == 4 || sz == 8))) {\n    TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) :\n\t      ctype_isptr(info) ? lj_ir_kptr(J, NULL) :\n\t      sz == 4 ? lj_ir_kint(J, 0) :\n\t      (lj_needsplit(J), lj_ir_kint64(J, 0));\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, sp);\n    return;\n  } else {\n    TRef trsz = TREF_NIL;\n    if ((info & CTF_VLA)) {  /* Calculate VLA/VLS size at runtime. */\n      CTSize sz0, sz1;\n      if (!J->base[1] || J->base[2])\n\tlj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init VLA/VLS. */\n      trsz = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0,\n\t\t\tJ->base[1], &rd->argv[1]);\n      sz0 = lj_ctype_vlsize(cts, d, 0);\n      sz1 = lj_ctype_vlsize(cts, d, 1);\n      trsz = emitir(IRTGI(IR_MULOV), trsz, lj_ir_kint(J, (int32_t)(sz1-sz0)));\n      trsz = emitir(IRTGI(IR_ADDOV), trsz, lj_ir_kint(J, (int32_t)sz0));\n      J->base[1] = 0;  /* Simplify logic below. */\n    } else if (ctype_align(info) > CT_MEMALIGN) {\n      trsz = lj_ir_kint(J, sz);\n    }\n    trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, trsz);\n    if (sz > 128 || (info & CTF_VLA)) {\n      TRef dp;\n      CTSize align;\n    special:  /* Only handle bulk zero-fill for large/VLA/VLS types. */\n      if (J->base[1])\n\tlj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init large/VLA/VLS types. */\n      dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata)));\n      if (trsz == TREF_NIL) trsz = lj_ir_kint(J, sz);\n      align = ctype_align(info);\n      if (align < CT_MEMALIGN) align = CT_MEMALIGN;\n      crec_fill(J, dp, trsz, lj_ir_kint(J, 0), (1u << align));\n    } else if (J->base[1] && !J->base[2] &&\n\t!lj_cconv_multi_init(cts, d, &rd->argv[1])) {\n      goto single_init;\n    } else if (ctype_isarray(d->info)) {\n      CType *dc = ctype_rawchild(cts, d);  /* Array element type. */\n      CTSize ofs, esize = dc->size;\n      TRef sp = 0;\n      TValue tv;\n      TValue *sval = &tv;\n      MSize i;\n      tv.u64 = 0;\n      if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info)) ||\n\t  esize * CREC_FILL_MAXUNROLL < sz)\n\tgoto special;\n      for (i = 1, ofs = 0; ofs < sz; ofs += esize) {\n\tTRef dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,\n\t\t\t lj_ir_kintp(J, ofs + sizeof(GCcdata)));\n\tif (J->base[i]) {\n\t  sp = J->base[i];\n\t  sval = &rd->argv[i];\n\t  i++;\n\t} else if (i != 2) {\n\t  sp = ctype_isnum(dc->info) ? lj_ir_kint(J, 0) : TREF_NIL;\n\t}\n\tcrec_ct_tv(J, dc, dp, sp, sval);\n      }\n    } else if (ctype_isstruct(d->info)) {\n      CTypeID fid;\n      MSize i = 1;\n      if (!J->base[1]) {  /* Handle zero-fill of struct-of-NYI. */\n\tfid = d->sib;\n\twhile (fid) {\n\t  CType *df = ctype_get(cts, fid);\n\t  fid = df->sib;\n\t  if (ctype_isfield(df->info)) {\n\t    CType *dc;\n\t    if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n\t    dc = ctype_rawchild(cts, df);  /* Field type. */\n\t    if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) ||\n\t\t  ctype_isenum(dc->info)))\n\t      goto special;\n\t  } else if (!ctype_isconstval(df->info)) {\n\t    goto special;\n\t  }\n\t}\n      }\n      fid = d->sib;\n      while (fid) {\n\tCType *df = ctype_get(cts, fid);\n\tfid = df->sib;\n\tif (ctype_isfield(df->info)) {\n\t  CType *dc;\n\t  TRef sp, dp;\n\t  TValue tv;\n\t  TValue *sval = &tv;\n\t  setintV(&tv, 0);\n\t  if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */\n\t  dc = ctype_rawchild(cts, df);  /* Field type. */\n\t  if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) ||\n\t\tctype_isenum(dc->info)))\n\t    lj_trace_err(J, LJ_TRERR_NYICONV);  /* NYI: init aggregates. */\n\t  if (J->base[i]) {\n\t    sp = J->base[i];\n\t    sval = &rd->argv[i];\n\t    i++;\n\t  } else {\n\t    sp = ctype_isptr(dc->info) ? TREF_NIL : lj_ir_kint(J, 0);\n\t  }\n\t  dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,\n\t\t      lj_ir_kintp(J, df->size + sizeof(GCcdata)));\n\t  crec_ct_tv(J, dc, dp, sp, sval);\n\t  if ((d->info & CTF_UNION)) {\n\t    if (d->size != dc->size)  /* NYI: partial init of union. */\n\t      lj_trace_err(J, LJ_TRERR_NYICONV);\n\t    break;\n\t  }\n\t} else if (!ctype_isconstval(df->info)) {\n\t  /* NYI: init bitfields and sub-structures. */\n\t  lj_trace_err(J, LJ_TRERR_NYICONV);\n\t}\n      }\n    } else {\n      TRef dp;\n    single_init:\n      dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata)));\n      if (J->base[1]) {\n\tcrec_ct_tv(J, d, dp, J->base[1], &rd->argv[1]);\n      } else {\n\tTValue tv;\n\ttv.u64 = 0;\n\tcrec_ct_tv(J, d, dp, lj_ir_kint(J, 0), &tv);\n      }\n    }\n  }\n  J->base[0] = trcd;\n  /* Handle __gc metamethod. */\n  fin = lj_ctype_meta(cts, id, MM_gc);\n  if (fin)\n    crec_finalizer(J, trcd, 0, fin);\n}\n\n/* Record argument conversions. */\nstatic TRef crec_call_args(jit_State *J, RecordFFData *rd,\n\t\t\t   CTState *cts, CType *ct)\n{\n  TRef args[CCI_NARGS_MAX];\n  CTypeID fid;\n  MSize i, n;\n  TRef tr, *base;\n  cTValue *o;\n#if LJ_TARGET_X86\n#if LJ_ABI_WIN\n  TRef *arg0 = NULL, *arg1 = NULL;\n#endif\n  int ngpr = 0;\n  if (ctype_cconv(ct->info) == CTCC_THISCALL)\n    ngpr = 1;\n  else if (ctype_cconv(ct->info) == CTCC_FASTCALL)\n    ngpr = 2;\n#endif\n\n  /* Skip initial attributes. */\n  fid = ct->sib;\n  while (fid) {\n    CType *ctf = ctype_get(cts, fid);\n    if (!ctype_isattrib(ctf->info)) break;\n    fid = ctf->sib;\n  }\n  args[0] = TREF_NIL;\n  for (n = 0, base = J->base+1, o = rd->argv+1; *base; n++, base++, o++) {\n    CTypeID did;\n    CType *d;\n\n    if (n >= CCI_NARGS_MAX)\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n\n    if (fid) {  /* Get argument type from field. */\n      CType *ctf = ctype_get(cts, fid);\n      fid = ctf->sib;\n      lj_assertJ(ctype_isfield(ctf->info), \"field expected\");\n      did = ctype_cid(ctf->info);\n    } else {\n      if (!(ct->info & CTF_VARARG))\n\tlj_trace_err(J, LJ_TRERR_NYICALL);  /* Too many arguments. */\n      did = lj_ccall_ctid_vararg(cts, o);  /* Infer vararg type. */\n    }\n    d = ctype_raw(cts, did);\n    if (!(ctype_isnum(d->info) || ctype_isptr(d->info) ||\n\t  ctype_isenum(d->info)))\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n    tr = crec_ct_tv(J, d, 0, *base, o);\n    if (ctype_isinteger_or_bool(d->info)) {\n      if (d->size < 4) {\n\tif ((d->info & CTF_UNSIGNED))\n\t  tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_U8 : IRT_U16, 0);\n\telse\n\t  tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_I8 : IRT_I16,IRCONV_SEXT);\n      }\n    } else if (LJ_SOFTFP32 && ctype_isfp(d->info) && d->size > 4) {\n      lj_needsplit(J);\n    }\n#if LJ_TARGET_X86\n    /* 64 bit args must not end up in registers for fastcall/thiscall. */\n#if LJ_ABI_WIN\n    if (!ctype_isfp(d->info)) {\n      /* Sigh, the Windows/x86 ABI allows reordering across 64 bit args. */\n      if (tref_typerange(tr, IRT_I64, IRT_U64)) {\n\tif (ngpr) {\n\t  arg0 = &args[n]; args[n++] = TREF_NIL; ngpr--;\n\t  if (ngpr) {\n\t    arg1 = &args[n]; args[n++] = TREF_NIL; ngpr--;\n\t  }\n\t}\n      } else {\n\tif (arg0) { *arg0 = tr; arg0 = NULL; n--; continue; }\n\tif (arg1) { *arg1 = tr; arg1 = NULL; n--; continue; }\n\tif (ngpr) ngpr--;\n      }\n    }\n#else\n    if (!ctype_isfp(d->info) && ngpr) {\n      if (tref_typerange(tr, IRT_I64, IRT_U64)) {\n\t/* No reordering for other x86 ABIs. Simply add alignment args. */\n\tdo { args[n++] = TREF_NIL; } while (--ngpr);\n      } else {\n\tngpr--;\n      }\n    }\n#endif\n#endif\n    args[n] = tr;\n  }\n  tr = args[0];\n  for (i = 1; i < n; i++)\n    tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]);\n  return tr;\n}\n\n/* Create a snapshot for the caller, simulating a 'false' return value. */\nstatic void crec_snap_caller(jit_State *J)\n{\n  lua_State *L = J->L;\n  TValue *base = L->base, *top = L->top;\n  const BCIns *pc = J->pc;\n  TRef ftr = J->base[-1-LJ_FR2];\n  ptrdiff_t delta;\n  if (!frame_islua(base-1) || J->framedepth <= 0)\n    lj_trace_err(J, LJ_TRERR_NYICALL);\n  J->pc = frame_pc(base-1); delta = 1+LJ_FR2+bc_a(J->pc[-1]);\n  L->top = base; L->base = base - delta;\n  J->base[-1-LJ_FR2] = TREF_FALSE;\n  J->base -= delta; J->baseslot -= (BCReg)delta;\n  J->maxslot = (BCReg)delta-LJ_FR2; J->framedepth--;\n  lj_snap_add(J);\n  L->base = base; L->top = top;\n  J->framedepth++; J->maxslot = 1;\n  J->base += delta; J->baseslot += (BCReg)delta;\n  J->base[-1-LJ_FR2] = ftr; J->pc = pc;\n}\n\n/* Record function call. */\nstatic int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ct = ctype_raw(cts, cd->ctypeid);\n  IRType tp = IRT_PTR;\n  if (ctype_isptr(ct->info)) {\n    tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;\n    ct = ctype_rawchild(cts, ct);\n  }\n  if (ctype_isfunc(ct->info)) {\n    TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR);\n    CType *ctr = ctype_rawchild(cts, ct);\n    IRType t = crec_ct2irt(cts, ctr);\n    TRef tr;\n    TValue tv;\n    /* Check for blacklisted C functions that might call a callback. */\n    tv.u64 = ((uintptr_t)cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4) >> 2) | U64x(800000000, 00000000);\n    if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv)))\n      lj_trace_err(J, LJ_TRERR_BLACKL);\n    if (ctype_isvoid(ctr->info)) {\n      t = IRT_NIL;\n      rd->nres = 0;\n    } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) ||\n\t\t ctype_isenum(ctr->info)) || t == IRT_CDATA) {\n      lj_trace_err(J, LJ_TRERR_NYICALL);\n    }\n    if ((ct->info & CTF_VARARG)\n#if LJ_TARGET_X86\n\t|| ctype_cconv(ct->info) != CTCC_CDECL\n#endif\n\t)\n      func = emitir(IRT(IR_CARG, IRT_NIL), func,\n\t\t    lj_ir_kint(J, ctype_typeid(cts, ct)));\n    tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func);\n    if (ctype_isbool(ctr->info)) {\n      if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) {\n\t/* Don't check result if ignored. */\n\ttr = TREF_NIL;\n      } else {\n\tcrec_snap_caller(J);\n#if LJ_TARGET_X86ORX64\n\t/* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */\n\tlj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0));\n#else\n\tlj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));\n#endif\n\tJ->postproc = LJ_POST_FIXGUARDSNAP;\n\ttr = TREF_TRUE;\n      }\n    } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) ||\n\t       t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) {\n      TRef trid = lj_ir_kint(J, ctype_cid(ct->info));\n      tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr);\n      if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);\n    } else if (t == IRT_FLOAT || t == IRT_U32) {\n      tr = emitconv(tr, IRT_NUM, t, 0);\n    } else if (t == IRT_I8 || t == IRT_I16) {\n      tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT);\n    } else if (t == IRT_U8 || t == IRT_U16) {\n      tr = emitconv(tr, IRT_INT, t, 0);\n    }\n    J->base[0] = tr;\n    J->needsnap = 1;\n    return 1;\n  }\n  return 0;\n}\n\nvoid LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]);\n  CTypeID id = cd->ctypeid;\n  CType *ct;\n  cTValue *tv;\n  MMS mm = MM_call;\n  if (id == CTID_CTYPEID) {\n    id = crec_constructor(J, cd, J->base[0]);\n    mm = MM_new;\n  } else if (crec_call(J, rd, cd)) {\n    return;\n  }\n  /* Record ctype __call/__new metamethod. */\n  ct = ctype_raw(cts, id);\n  tv = lj_ctype_meta(cts, ctype_isptr(ct->info) ? ctype_cid(ct->info) : id, mm);\n  if (tv) {\n    if (tvisfunc(tv)) {\n      crec_tailcall(J, rd, tv);\n      return;\n    }\n  } else if (mm == MM_new) {\n    crec_alloc(J, rd, id);\n    return;\n  }\n  /* No metamethod or NYI: non-function metamethods. */\n  lj_trace_err(J, LJ_TRERR_BADTYPE);\n}\n\nstatic TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm)\n{\n  if (sp[0] && sp[1] && ctype_isnum(s[0]->info) && ctype_isnum(s[1]->info)) {\n    IRType dt;\n    CTypeID id;\n    TRef tr;\n    MSize i;\n    IROp op;\n    lj_needsplit(J);\n    if (((s[0]->info & CTF_UNSIGNED) && s[0]->size == 8) ||\n\t((s[1]->info & CTF_UNSIGNED) && s[1]->size == 8)) {\n      dt = IRT_U64; id = CTID_UINT64;\n    } else {\n      dt = IRT_I64; id = CTID_INT64;\n      if (mm < MM_add &&\n\t  !((s[0]->info | s[1]->info) & CTF_FP) &&\n\t  s[0]->size == 4 && s[1]->size == 4) {  /* Try to narrow comparison. */\n\tif (!((s[0]->info ^ s[1]->info) & CTF_UNSIGNED) ||\n\t    (tref_isk(sp[1]) && IR(tref_ref(sp[1]))->i >= 0)) {\n\t  dt = (s[0]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;\n\t  goto comp;\n\t} else if (tref_isk(sp[0]) && IR(tref_ref(sp[0]))->i >= 0) {\n\t  dt = (s[1]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;\n\t  goto comp;\n\t}\n      }\n    }\n    for (i = 0; i < 2; i++) {\n      IRType st = tref_type(sp[i]);\n      if (st == IRT_NUM || st == IRT_FLOAT)\n\tsp[i] = emitconv(sp[i], dt, st, IRCONV_ANY);\n      else if (!(st == IRT_I64 || st == IRT_U64))\n\tsp[i] = emitconv(sp[i], dt, IRT_INT,\n\t\t\t (s[i]->info & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);\n    }\n    if (mm < MM_add) {\n    comp:\n      /* Assume true comparison. Fixup and emit pending guard later. */\n      if (mm == MM_eq) {\n\top = IR_EQ;\n      } else {\n\top = mm == MM_lt ? IR_LT : IR_LE;\n\tif (dt == IRT_U32 || dt == IRT_U64)\n\t  op += (IR_ULT-IR_LT);\n      }\n      lj_ir_set(J, IRTG(op, dt), sp[0], sp[1]);\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, dt), sp[0], sp[1]);\n    }\n    return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n  }\n  return 0;\n}\n\nstatic TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *ctp = s[0];\n  if (!(sp[0] && sp[1])) return 0;\n  if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {\n    if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&\n\t(ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {\n      if (mm == MM_sub) {  /* Pointer difference. */\n\tTRef tr;\n\tCTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));\n\tif (sz == 0 || (sz & (sz-1)) != 0)\n\t  return 0;  /* NYI: integer division. */\n\ttr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]);\n\ttr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz)));\n#if LJ_64\n\ttr = emitconv(tr, IRT_NUM, IRT_INTP, 0);\n#endif\n\treturn tr;\n      } else {  /* Pointer comparison (unsigned). */\n\t/* Assume true comparison. Fixup and emit pending guard later. */\n\tIROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE;\n\tlj_ir_set(J, IRTG(op, IRT_PTR), sp[0], sp[1]);\n\tJ->postproc = LJ_POST_FIXGUARD;\n\treturn TREF_TRUE;\n      }\n    }\n    if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(s[1]->info)))\n      return 0;\n  } else if (mm == MM_add && ctype_isnum(ctp->info) &&\n\t     (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {\n    TRef tr = sp[0]; sp[0] = sp[1]; sp[1] = tr;  /* Swap pointer and index. */\n    ctp = s[1];\n  } else {\n    return 0;\n  }\n  {\n    TRef tr = sp[1];\n    IRType t = tref_type(tr);\n    CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));\n    CTypeID id;\n#if LJ_64\n    if (t == IRT_NUM || t == IRT_FLOAT)\n      tr = emitconv(tr, IRT_INTP, t, IRCONV_ANY);\n    else if (!(t == IRT_I64 || t == IRT_U64))\n      tr = emitconv(tr, IRT_INTP, IRT_INT,\n\t\t    ((t - IRT_I8) & 1) ? 0 : IRCONV_SEXT);\n#else\n    if (!tref_typerange(sp[1], IRT_I8, IRT_U32)) {\n      tr = emitconv(tr, IRT_INTP, t,\n\t\t    (t == IRT_NUM || t == IRT_FLOAT) ? IRCONV_ANY : 0);\n    }\n#endif\n    tr = emitir(IRT(IR_MUL, IRT_INTP), tr, lj_ir_kintp(J, sz));\n    tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, IRT_PTR), sp[0], tr);\n    id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),\n\t\t\t CTSIZE_PTR);\n    return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n  }\n}\n\n/* Record ctype arithmetic metamethods. */\nstatic TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts,\n\t\t\t    RecordFFData *rd)\n{\n  cTValue *tv = NULL;\n  if (J->base[0]) {\n    if (tviscdata(&rd->argv[0])) {\n      CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n      tv = lj_ctype_meta(cts, id, (MMS)rd->data);\n    }\n    if (!tv && J->base[1] && tviscdata(&rd->argv[1])) {\n      CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid;\n      CType *ct = ctype_raw(cts, id);\n      if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);\n      tv = lj_ctype_meta(cts, id, (MMS)rd->data);\n    }\n  }\n  if (tv) {\n    if (tvisfunc(tv)) {\n      crec_tailcall(J, rd, tv);\n      return 0;\n    }  /* NYI: non-function metamethods. */\n  } else if ((MMS)rd->data == MM_eq) {  /* Fallback cdata pointer comparison. */\n    if (sp[0] && sp[1] && ctype_isnum(s[0]->info) == ctype_isnum(s[1]->info)) {\n      /* Assume true comparison. Fixup and emit pending guard later. */\n      lj_ir_set(J, IRTG(IR_EQ, IRT_PTR), sp[0], sp[1]);\n      J->postproc = LJ_POST_FIXGUARD;\n      return TREF_TRUE;\n    } else {\n      return TREF_FALSE;\n    }\n  }\n  lj_trace_err(J, LJ_TRERR_BADTYPE);\n  return 0;\n}\n\nvoid LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef sp[2];\n  CType *s[2];\n  MSize i;\n  for (i = 0; i < 2; i++) {\n    TRef tr = J->base[i];\n    CType *ct = ctype_get(cts, CTID_DOUBLE);\n    if (!tr) {\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    } else if (tref_iscdata(tr)) {\n      CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid;\n      IRType t;\n      ct = ctype_raw(cts, id);\n      t = crec_ct2irt(cts, ct);\n      if (ctype_isptr(ct->info)) {  /* Resolve pointer or reference. */\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR);\n\tif (ctype_isref(ct->info)) {\n\t  ct = ctype_rawchild(cts, ct);\n\t  t = crec_ct2irt(cts, ct);\n\t}\n      } else if (t == IRT_I64 || t == IRT_U64) {\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64);\n\tlj_needsplit(J);\n\tgoto ok;\n      } else if (t == IRT_INT || t == IRT_U32) {\n\ttr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT);\n\tif (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n\tgoto ok;\n      } else if (ctype_isfunc(ct->info)) {\n\ttr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR);\n\tct = ctype_get(cts,\n\t  lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));\n\tgoto ok;\n      } else {\n\ttr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata)));\n      }\n      if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n      if (ctype_isnum(ct->info)) {\n\tif (t == IRT_CDATA) {\n\t  tr = 0;\n\t} else {\n\t  if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);\n\t  tr = emitir(IRT(IR_XLOAD, t), tr, 0);\n\t}\n      }\n    } else if (tref_isnil(tr)) {\n      tr = lj_ir_kptr(J, NULL);\n      ct = ctype_get(cts, CTID_P_VOID);\n    } else if (tref_isinteger(tr)) {\n      ct = ctype_get(cts, CTID_INT32);\n    } else if (tref_isstr(tr)) {\n      TRef tr2 = J->base[1-i];\n      CTypeID id = argv2cdata(J, tr2, &rd->argv[1-i])->ctypeid;\n      ct = ctype_raw(cts, id);\n      if (ctype_isenum(ct->info)) {  /* Match string against enum constant. */\n\tGCstr *str = strV(&rd->argv[i]);\n\tCTSize ofs;\n\tCType *cct = lj_ctype_getfield(cts, ct, str, &ofs);\n\tif (cct && ctype_isconstval(cct->info)) {\n\t  /* Specialize to the name of the enum constant. */\n\t  emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str));\n\t  ct = ctype_child(cts, cct);\n\t  tr = lj_ir_kint(J, (int32_t)ofs);\n\t} else {  /* Interpreter will throw or return false. */\n\t  ct = ctype_get(cts, CTID_P_VOID);\n\t}\n      } else if (ctype_isptr(ct->info)) {\n\ttr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr)));\n      } else {\n\tct = ctype_get(cts, CTID_P_VOID);\n      }\n    } else if (!tref_isnum(tr)) {\n      tr = 0;\n      ct = ctype_get(cts, CTID_P_VOID);\n    }\n  ok:\n    s[i] = ct;\n    sp[i] = tr;\n  }\n  {\n    TRef tr;\n    MMS mm = (MMS)rd->data;\n    if ((mm == MM_len || mm == MM_concat ||\n\t (!(tr = crec_arith_int64(J, sp, s, mm)) &&\n\t  !(tr = crec_arith_ptr(J, sp, s, mm)))) &&\n\t!(tr = crec_arith_meta(J, sp, s, cts, rd)))\n      return;\n    J->base[0] = tr;\n    /* Fixup cdata comparisons, too. Avoids some cdata escapes. */\n    if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) &&\n\t!irt_isguard(J->guardemit)) {\n      const BCIns *pc = frame_contpc(J->L->base-1) - 1;\n      if (bc_op(*pc) <= BC_ISNEP) {\n\tJ2G(J)->tmptv.u64 = (uint64_t)(uintptr_t)pc;\n\tJ->postproc = LJ_POST_FIXCOMP;\n      }\n    }\n  }\n}\n\n/* -- C library namespace metamethods ------------------------------------- */\n\nvoid LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) &&\n      udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) {\n    CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0]));\n    GCstr *name = strV(&rd->argv[1]);\n    CType *ct;\n    CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);\n    cTValue *tv = lj_tab_getstr(cl->cache, name);\n    rd->nres = rd->data;\n    if (id && tv && !tvisnil(tv)) {\n      /* Specialize to the symbol name and make the result a constant. */\n      emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name));\n      if (ctype_isconstval(ct->info)) {\n\tif (ct->size >= 0x80000000u &&\n\t    (ctype_child(cts, ct)->info & CTF_UNSIGNED))\n\t  J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size);\n\telse\n\t  J->base[0] = lj_ir_kint(J, (int32_t)ct->size);\n      } else if (ctype_isextern(ct->info)) {\n\tCTypeID sid = ctype_cid(ct->info);\n\tvoid *sp = *(void **)cdataptr(cdataV(tv));\n\tTRef ptr;\n\tct = ctype_raw(cts, sid);\n\tif (LJ_64 && !checkptr32(sp))\n\t  ptr = lj_ir_kintp(J, (uintptr_t)sp);\n\telse\n\t  ptr = lj_ir_kptr(J, sp);\n\tif (rd->data) {\n\t  J->base[0] = crec_tv_ct(J, ct, sid, ptr);\n\t} else {\n\t  J->needsnap = 1;\n\t  crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);\n\t}\n      } else {\n\tJ->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA);\n      }\n    } else {\n      lj_trace_err(J, LJ_TRERR_NOCACHE);\n    }\n  }  /* else: interpreter will throw. */\n}\n\n/* -- FFI library functions ----------------------------------------------- */\n\nstatic TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval)\n{\n  return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval);\n}\n\nvoid LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd)\n{\n  crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0]));\n}\n\nvoid LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd)\n{\n  UNUSED(rd);\n  if (J->base[0])\n    lj_trace_err(J, LJ_TRERR_NYICALL);\n  J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno);\n}\n\nvoid LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef tr = J->base[0];\n  if (tr) {\n    TRef trlen = J->base[1];\n    if (!tref_isnil(trlen)) {\n      trlen = crec_toint(J, cts, trlen, &rd->argv[1]);\n      tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]);\n    } else {\n      tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]);\n      trlen = lj_ir_call(J, IRCALL_strlen, tr);\n    }\n    J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), tr, trlen);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2];\n  if (trdst && trsrc && (trlen || tref_isstr(trsrc))) {\n    trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);\n    trsrc = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, trsrc, &rd->argv[1]);\n    if (trlen) {\n      trlen = crec_toint(J, cts, trlen, &rd->argv[2]);\n    } else {\n      trlen = emitir(IRTI(IR_FLOAD), J->base[1], IRFL_STR_LEN);\n      trlen = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));\n    }\n    rd->nres = 0;\n    crec_copy(J, trdst, trsrc, trlen, NULL);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2];\n  if (trdst && trlen) {\n    CTSize step = 1;\n    if (tviscdata(&rd->argv[0])) {  /* Get alignment of original destination. */\n      CTSize sz;\n      CType *ct = ctype_raw(cts, cdataV(&rd->argv[0])->ctypeid);\n      if (ctype_isptr(ct->info))\n\tct = ctype_rawchild(cts, ct);\n      step = (1u<<ctype_align(lj_ctype_info(cts, ctype_typeid(cts, ct), &sz)));\n    }\n    trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);\n    trlen = crec_toint(J, cts, trlen, &rd->argv[1]);\n    if (trfill)\n      trfill = crec_toint(J, cts, trfill, &rd->argv[2]);\n    else\n      trfill = lj_ir_kint(J, 0);\n    rd->nres = 0;\n    crec_fill(J, trdst, trlen, trfill, step);\n  }  /* else: interpreter will throw. */\n}\n\nvoid LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd)\n{\n  if (tref_iscdata(J->base[0])) {\n    TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0]));\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA),\n\t\t\tlj_ir_kint(J, CTID_CTYPEID), trid);\n  } else {\n    setfuncV(J->L, &J->errinfo, J->fn);\n    lj_trace_err_info(J, LJ_TRERR_NYIFFU);\n  }\n}\n\nvoid LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd)\n{\n  argv2ctype(J, J->base[0], &rd->argv[0]);\n  if (tref_iscdata(J->base[1])) {\n    argv2ctype(J, J->base[1], &rd->argv[1]);\n    J->postproc = LJ_POST_FIXBOOL;\n    J->base[0] = TREF_TRUE;\n  } else {\n    J->base[0] = TREF_FALSE;\n  }\n}\n\nvoid LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)\n{\n  if (tref_isstr(J->base[0])) {\n    /* Specialize to the ABI string to make the boolean result a constant. */\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0])));\n    J->postproc = LJ_POST_FIXBOOL;\n    J->base[0] = TREF_TRUE;\n  } else {\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n}\n\n/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */\nvoid LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)\n{\n  CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]);\n  if (rd->data == FF_ffi_sizeof) {\n    CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id);\n    if (ctype_isvltype(ct->info))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  } else if (rd->data == FF_ffi_offsetof) {  /* Specialize to the field name. */\n    if (!tref_isstr(J->base[1]))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));\n    rd->nres = 3;  /* Just in case. */\n  }\n  J->postproc = LJ_POST_FIXCONST;\n  J->base[0] = J->base[1] = J->base[2] = TREF_NIL;\n}\n\nvoid LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)\n{\n  argv2cdata(J, J->base[0], &rd->argv[0]);\n  if (!J->base[1])\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  crec_finalizer(J, J->base[0], J->base[1], &rd->argv[1]);\n}\n\n/* -- 64 bit bit.* library functions -------------------------------------- */\n\n/* Determine bit operation type from argument type. */\nstatic CTypeID crec_bit64_type(CTState *cts, cTValue *tv)\n{\n  if (tviscdata(tv)) {\n    CType *ct = lj_ctype_rawref(cts, cdataV(tv)->ctypeid);\n    if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n    if ((ct->info & (CTMASK_NUM|CTF_BOOL|CTF_FP|CTF_UNSIGNED)) ==\n\tCTINFO(CT_NUM, CTF_UNSIGNED) && ct->size == 8)\n      return CTID_UINT64;  /* Use uint64_t, since it has the highest rank. */\n    return CTID_INT64;  /* Otherwise use int64_t. */\n  }\n  return 0;  /* Use regular 32 bit ops. */\n}\n\nvoid LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  TRef tr = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,\n\t\t       J->base[0], &rd->argv[0]);\n  if (!tref_isinteger(tr))\n    tr = emitconv(tr, IRT_INT, tref_type(tr), 0);\n  J->base[0] = tr;\n}\n\nint LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = crec_bit64_type(cts, &rd->argv[0]);\n  if (id) {\n    TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    tr = emitir(IRT(rd->data, id-CTID_INT64+IRT_I64), tr, 0);\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nint LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = 0;\n  MSize i;\n  for (i = 0; J->base[i] != 0; i++) {\n    CTypeID aid = crec_bit64_type(cts, &rd->argv[i]);\n    if (id < aid) id = aid;  /* Determine highest type rank of all arguments. */\n  }\n  if (id) {\n    CType *ct = ctype_get(cts, id);\n    uint32_t ot = IRT(rd->data, id-CTID_INT64+IRT_I64);\n    TRef tr = crec_ct_tv(J, ct, 0, J->base[0], &rd->argv[0]);\n    for (i = 1; J->base[i] != 0; i++) {\n      TRef tr2 = crec_ct_tv(J, ct, 0, J->base[i], &rd->argv[i]);\n      tr = emitir(ot, tr, tr2);\n    }\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nint LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id;\n  TRef tsh = 0;\n  if (J->base[0] && tref_iscdata(J->base[1])) {\n    tsh = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,\n\t\t     J->base[1], &rd->argv[1]);\n    if (!tref_isinteger(tsh))\n      tsh = emitconv(tsh, IRT_INT, tref_type(tsh), 0);\n    J->base[1] = tsh;\n  }\n  id = crec_bit64_type(cts, &rd->argv[0]);\n  if (id) {\n    TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    uint32_t op = rd->data;\n    if (!tsh) tsh = lj_opt_narrow_tobit(J, J->base[1]);\n    if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n\t!tref_isk(tsh))\n      tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 63));\n#ifdef LJ_TARGET_UNIFYROT\n      if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) {\n\top = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR;\n\ttsh = emitir(IRTI(IR_NEG), tsh, tsh);\n      }\n#endif\n    tr = emitir(IRT(op, id-CTID_INT64+IRT_I64), tr, tsh);\n    J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);\n    return 1;\n  }\n  return 0;\n}\n\nTRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CTypeID id = crec_bit64_type(cts, &rd->argv[0]);\n  TRef tr, trsf = J->base[1];\n  SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);\n  int32_t n;\n  if (trsf) {\n    CTypeID id2 = 0;\n    n = (int32_t)lj_carith_check64(J->L, 2, &id2);\n    if (id2)\n      trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]);\n    else\n      trsf = lj_opt_narrow_tobit(J, trsf);\n    emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n));  /* Specialize to n. */\n  } else {\n    n = id ? 16 : 8;\n  }\n  if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }\n  sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);\n  if (id) {\n    tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);\n    if (n < 16)\n      tr = emitir(IRT(IR_BAND, IRT_U64), tr,\n\t\t  lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));\n  } else {\n    tr = lj_opt_narrow_tobit(J, J->base[0]);\n    if (n < 8)\n      tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << 4*n)-1)));\n    tr = emitconv(tr, IRT_U64, IRT_INT, 0);  /* No sign-extension. */\n    lj_needsplit(J);\n  }\n  return lj_ir_call(J, IRCALL_lj_strfmt_putfxint, hdr, lj_ir_kint(J, sf), tr);\n}\n\n/* -- Miscellaneous library functions ------------------------------------- */\n\nvoid LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid);\n  if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);\n  if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {\n    if (ctype_isinteger_or_bool(ct->info) && ct->size <= 4 &&\n\t!(ct->size == 4 && (ct->info & CTF_UNSIGNED)))\n      d = ctype_get(cts, CTID_INT32);\n    else\n      d = ctype_get(cts, CTID_DOUBLE);\n    J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]);\n  } else {\n    /* Specialize to the ctype that couldn't be converted. */\n    argv2cdata(J, J->base[0], &rd->argv[0]);\n    J->base[0] = TREF_NIL;\n  }\n}\n\nTRef lj_crecord_loadiu64(jit_State *J, TRef tr, cTValue *o)\n{\n  CTypeID id = argv2cdata(J, tr, o)->ctypeid;\n  if (!(id == CTID_INT64 || id == CTID_UINT64))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  lj_needsplit(J);\n  return emitir(IRT(IR_FLOAD, id == CTID_INT64 ? IRT_I64 : IRT_U64), tr,\n\t\tIRFL_CDATA_INT64);\n}\n\n#if LJ_HASBUFFER\nTRef lj_crecord_topcvoid(jit_State *J, TRef tr, cTValue *o)\n{\n  CTState *cts = ctype_ctsG(J2G(J));\n  if (!tref_iscdata(tr)) lj_trace_err(J, LJ_TRERR_BADTYPE);\n  return crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, o);\n}\n\nTRef lj_crecord_topuint8(jit_State *J, TRef tr)\n{\n  return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, CTID_P_UINT8), tr);\n}\n#endif\n\n#undef IR\n#undef emitir\n#undef emitconv\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_crecord.h",
    "content": "/*\n** Trace recorder for C data operations.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CRECORD_H\n#define _LJ_CRECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n#include \"lj_ffrecord.h\"\n\n#if LJ_HASJIT && LJ_HASFFI\nLJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);\nLJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);\n\nLJ_FUNC void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd);\nLJ_FUNC int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd);\nLJ_FUNC TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr);\n\nLJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);\nLJ_FUNC TRef lj_crecord_loadiu64(jit_State *J, TRef tr, cTValue *o);\n#if LJ_HASBUFFER\nLJ_FUNC TRef lj_crecord_topcvoid(jit_State *J, TRef tr, cTValue *o);\nLJ_FUNC TRef lj_crecord_topuint8(jit_State *J, TRef tr);\n#endif\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ctype.c",
    "content": "/*\n** C type management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include \"lj_obj.h\"\n\n#if LJ_HASFFI\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_ctype.h\"\n#include \"lj_ccallback.h\"\n#include \"lj_buf.h\"\n\n/* -- C type definitions -------------------------------------------------- */\n\n/* Predefined typedefs. */\n#define CTTDDEF(_) \\\n  /* Vararg handling. */ \\\n  _(\"va_list\",\t\t\tP_VOID) \\\n  _(\"__builtin_va_list\",\tP_VOID) \\\n  _(\"__gnuc_va_list\",\t\tP_VOID) \\\n  /* From stddef.h. */ \\\n  _(\"ptrdiff_t\",\t\tINT_PSZ) \\\n  _(\"size_t\",\t\t\tUINT_PSZ) \\\n  _(\"wchar_t\",\t\t\tWCHAR) \\\n  /* Subset of stdint.h. */ \\\n  _(\"int8_t\",\t\t\tINT8) \\\n  _(\"int16_t\",\t\t\tINT16) \\\n  _(\"int32_t\",\t\t\tINT32) \\\n  _(\"int64_t\",\t\t\tINT64) \\\n  _(\"uint8_t\",\t\t\tUINT8) \\\n  _(\"uint16_t\",\t\t\tUINT16) \\\n  _(\"uint32_t\",\t\t\tUINT32) \\\n  _(\"uint64_t\",\t\t\tUINT64) \\\n  _(\"intptr_t\",\t\t\tINT_PSZ) \\\n  _(\"uintptr_t\",\t\tUINT_PSZ) \\\n  /* From POSIX. */ \\\n  _(\"ssize_t\",\t\t\tINT_PSZ) \\\n  /* End of typedef list. */\n\n/* Keywords (only the ones we actually care for). */\n#define CTKWDEF(_) \\\n  /* Type specifiers. */ \\\n  _(\"void\",\t\t-1,\tCTOK_VOID) \\\n  _(\"_Bool\",\t\t0,\tCTOK_BOOL) \\\n  _(\"bool\",\t\t1,\tCTOK_BOOL) \\\n  _(\"char\",\t\t1,\tCTOK_CHAR) \\\n  _(\"int\",\t\t4,\tCTOK_INT) \\\n  _(\"__int8\",\t\t1,\tCTOK_INT) \\\n  _(\"__int16\",\t\t2,\tCTOK_INT) \\\n  _(\"__int32\",\t\t4,\tCTOK_INT) \\\n  _(\"__int64\",\t\t8,\tCTOK_INT) \\\n  _(\"float\",\t\t4,\tCTOK_FP) \\\n  _(\"double\",\t\t8,\tCTOK_FP) \\\n  _(\"long\",\t\t0,\tCTOK_LONG) \\\n  _(\"short\",\t\t0,\tCTOK_SHORT) \\\n  _(\"_Complex\",\t\t0,\tCTOK_COMPLEX) \\\n  _(\"complex\",\t\t0,\tCTOK_COMPLEX) \\\n  _(\"__complex\",\t0,\tCTOK_COMPLEX) \\\n  _(\"__complex__\",\t0,\tCTOK_COMPLEX) \\\n  _(\"signed\",\t\t0,\tCTOK_SIGNED) \\\n  _(\"__signed\",\t\t0,\tCTOK_SIGNED) \\\n  _(\"__signed__\",\t0,\tCTOK_SIGNED) \\\n  _(\"unsigned\",\t\t0,\tCTOK_UNSIGNED) \\\n  /* Type qualifiers. */ \\\n  _(\"const\",\t\t0,\tCTOK_CONST) \\\n  _(\"__const\",\t\t0,\tCTOK_CONST) \\\n  _(\"__const__\",\t0,\tCTOK_CONST) \\\n  _(\"volatile\",\t\t0,\tCTOK_VOLATILE) \\\n  _(\"__volatile\",\t0,\tCTOK_VOLATILE) \\\n  _(\"__volatile__\",\t0,\tCTOK_VOLATILE) \\\n  _(\"restrict\",\t\t0,\tCTOK_RESTRICT) \\\n  _(\"__restrict\",\t0,\tCTOK_RESTRICT) \\\n  _(\"__restrict__\",\t0,\tCTOK_RESTRICT) \\\n  _(\"inline\",\t\t0,\tCTOK_INLINE) \\\n  _(\"__inline\",\t\t0,\tCTOK_INLINE) \\\n  _(\"__inline__\",\t0,\tCTOK_INLINE) \\\n  /* Storage class specifiers. */ \\\n  _(\"typedef\",\t\t0,\tCTOK_TYPEDEF) \\\n  _(\"extern\",\t\t0,\tCTOK_EXTERN) \\\n  _(\"static\",\t\t0,\tCTOK_STATIC) \\\n  _(\"auto\",\t\t0,\tCTOK_AUTO) \\\n  _(\"register\",\t\t0,\tCTOK_REGISTER) \\\n  /* GCC Attributes. */ \\\n  _(\"__extension__\",\t0,\tCTOK_EXTENSION) \\\n  _(\"__attribute\",\t0,\tCTOK_ATTRIBUTE) \\\n  _(\"__attribute__\",\t0,\tCTOK_ATTRIBUTE) \\\n  _(\"asm\",\t\t0,\tCTOK_ASM) \\\n  _(\"__asm\",\t\t0,\tCTOK_ASM) \\\n  _(\"__asm__\",\t\t0,\tCTOK_ASM) \\\n  /* MSVC Attributes. */ \\\n  _(\"__declspec\",\t0,\tCTOK_DECLSPEC) \\\n  _(\"__cdecl\",\t\tCTCC_CDECL,\tCTOK_CCDECL) \\\n  _(\"__thiscall\",\tCTCC_THISCALL,\tCTOK_CCDECL) \\\n  _(\"__fastcall\",\tCTCC_FASTCALL,\tCTOK_CCDECL) \\\n  _(\"__stdcall\",\tCTCC_STDCALL,\tCTOK_CCDECL) \\\n  _(\"__ptr32\",\t\t4,\tCTOK_PTRSZ) \\\n  _(\"__ptr64\",\t\t8,\tCTOK_PTRSZ) \\\n  /* Other type specifiers. */ \\\n  _(\"struct\",\t\t0,\tCTOK_STRUCT) \\\n  _(\"union\",\t\t0,\tCTOK_UNION) \\\n  _(\"enum\",\t\t0,\tCTOK_ENUM) \\\n  /* Operators. */ \\\n  _(\"sizeof\",\t\t0,\tCTOK_SIZEOF) \\\n  _(\"__alignof\",\t0,\tCTOK_ALIGNOF) \\\n  _(\"__alignof__\",\t0,\tCTOK_ALIGNOF) \\\n  /* End of keyword list. */\n\n/* Type info for predefined types. Size merged in. */\nstatic CTInfo lj_ctype_typeinfo[] = {\n#define CTTYINFODEF(id, sz, ct, info)\tCTINFO((ct),(((sz)&0x3fu)<<10)+(info)),\n#define CTTDINFODEF(name, id)\t\tCTINFO(CT_TYPEDEF, CTID_##id),\n#define CTKWINFODEF(name, sz, kw)\tCTINFO(CT_KW,(((sz)&0x3fu)<<10)+(kw)),\nCTTYDEF(CTTYINFODEF)\nCTTDDEF(CTTDINFODEF)\nCTKWDEF(CTKWINFODEF)\n#undef CTTYINFODEF\n#undef CTTDINFODEF\n#undef CTKWINFODEF\n  0\n};\n\n/* Predefined type names collected in a single string. */\nstatic const char * const lj_ctype_typenames =\n#define CTTDNAMEDEF(name, id)\t\tname \"\\0\"\n#define CTKWNAMEDEF(name, sz, cds)\tname \"\\0\"\nCTTDDEF(CTTDNAMEDEF)\nCTKWDEF(CTKWNAMEDEF)\n#undef CTTDNAMEDEF\n#undef CTKWNAMEDEF\n;\n\n#define CTTYPEINFO_NUM\t\t(sizeof(lj_ctype_typeinfo)/sizeof(CTInfo)-1)\n#ifdef LUAJIT_CTYPE_CHECK_ANCHOR\n#define CTTYPETAB_MIN\t\tCTTYPEINFO_NUM\n#else\n#define CTTYPETAB_MIN\t\t128\n#endif\n\n/* -- C type interning ---------------------------------------------------- */\n\n#define ct_hashtype(info, size)\t(hashrot(info, size) & CTHASH_MASK)\n#define ct_hashname(name) \\\n  (hashrot(u32ptr(name), u32ptr(name) + HASH_BIAS) & CTHASH_MASK)\n\n/* Create new type element. */\nCTypeID lj_ctype_new(CTState *cts, CType **ctp)\n{\n  CTypeID id = cts->top;\n  CType *ct;\n  lj_assertCTS(cts->L, \"uninitialized cts->L\");\n  if (LJ_UNLIKELY(id >= cts->sizetab)) {\n    if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);\n#ifdef LUAJIT_CTYPE_CHECK_ANCHOR\n    ct = lj_mem_newvec(cts->L, id+1, CType);\n    memcpy(ct, cts->tab, id*sizeof(CType));\n    memset(cts->tab, 0, id*sizeof(CType));\n    lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType);\n    cts->tab = ct;\n    cts->sizetab = id+1;\n#else\n    lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);\n#endif\n  }\n  cts->top = id+1;\n  *ctp = ct = &cts->tab[id];\n  ct->info = 0;\n  ct->size = 0;\n  ct->sib = 0;\n  ct->next = 0;\n  setgcrefnull(ct->name);\n  return id;\n}\n\n/* Intern a type element. */\nCTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size)\n{\n  uint32_t h = ct_hashtype(info, size);\n  CTypeID id = cts->hash[h];\n  lj_assertCTS(cts->L, \"uninitialized cts->L\");\n  while (id) {\n    CType *ct = ctype_get(cts, id);\n    if (ct->info == info && ct->size == size)\n      return id;\n    id = ct->next;\n  }\n  id = cts->top;\n  if (LJ_UNLIKELY(id >= cts->sizetab)) {\n    if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);\n    lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);\n  }\n  cts->top = id+1;\n  cts->tab[id].info = info;\n  cts->tab[id].size = size;\n  cts->tab[id].sib = 0;\n  cts->tab[id].next = cts->hash[h];\n  setgcrefnull(cts->tab[id].name);\n  cts->hash[h] = (CTypeID1)id;\n  return id;\n}\n\n/* Add type element to hash table. */\nstatic void ctype_addtype(CTState *cts, CType *ct, CTypeID id)\n{\n  uint32_t h = ct_hashtype(ct->info, ct->size);\n  ct->next = cts->hash[h];\n  cts->hash[h] = (CTypeID1)id;\n}\n\n/* Add named element to hash table. */\nvoid lj_ctype_addname(CTState *cts, CType *ct, CTypeID id)\n{\n  uint32_t h = ct_hashname(gcref(ct->name));\n  ct->next = cts->hash[h];\n  cts->hash[h] = (CTypeID1)id;\n}\n\n/* Get a C type by name, matching the type mask. */\nCTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, uint32_t tmask)\n{\n  CTypeID id = cts->hash[ct_hashname(name)];\n  while (id) {\n    CType *ct = ctype_get(cts, id);\n    if (gcref(ct->name) == obj2gco(name) &&\n\t((tmask >> ctype_type(ct->info)) & 1)) {\n      *ctp = ct;\n      return id;\n    }\n    id = ct->next;\n  }\n  *ctp = &cts->tab[0];  /* Simplify caller logic. ctype_get() would assert. */\n  return 0;\n}\n\n/* Get a struct/union/enum/function field by name. */\nCType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, CTSize *ofs,\n\t\t\t  CTInfo *qual)\n{\n  while (ct->sib) {\n    ct = ctype_get(cts, ct->sib);\n    if (gcref(ct->name) == obj2gco(name)) {\n      *ofs = ct->size;\n      return ct;\n    }\n    if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {\n      CType *fct, *cct = ctype_child(cts, ct);\n      CTInfo q = 0;\n      while (ctype_isattrib(cct->info)) {\n\tif (ctype_attrib(cct->info) == CTA_QUAL) q |= cct->size;\n\tcct = ctype_child(cts, cct);\n      }\n      fct = lj_ctype_getfieldq(cts, cct, name, ofs, qual);\n      if (fct) {\n\tif (qual) *qual |= q;\n\t*ofs += ct->size;\n\treturn fct;\n      }\n    }\n  }\n  return NULL;  /* Not found. */\n}\n\n/* -- C type information -------------------------------------------------- */\n\n/* Follow references and get raw type for a C type ID. */\nCType *lj_ctype_rawref(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_get(cts, id);\n  while (ctype_isattrib(ct->info) || ctype_isref(ct->info))\n    ct = ctype_child(cts, ct);\n  return ct;\n}\n\n/* Get size for a C type ID. Does NOT support VLA/VLS. */\nCTSize lj_ctype_size(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_raw(cts, id);\n  return ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;\n}\n\n/* Get size for a variable-length C type. Does NOT support other C types. */\nCTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem)\n{\n  uint64_t xsz = 0;\n  if (ctype_isstruct(ct->info)) {\n    CTypeID arrid = 0, fid = ct->sib;\n    xsz = ct->size;  /* Add the struct size. */\n    while (fid) {\n      CType *ctf = ctype_get(cts, fid);\n      if (ctype_type(ctf->info) == CT_FIELD)\n\tarrid = ctype_cid(ctf->info);  /* Remember last field of VLS. */\n      fid = ctf->sib;\n    }\n    ct = ctype_raw(cts, arrid);\n  }\n  lj_assertCTS(ctype_isvlarray(ct->info), \"VLA expected\");\n  ct = ctype_rawchild(cts, ct);  /* Get array element. */\n  lj_assertCTS(ctype_hassize(ct->info), \"bad VLA without size\");\n  /* Calculate actual size of VLA and check for overflow. */\n  xsz += (uint64_t)ct->size * nelem;\n  return xsz < 0x80000000u ? (CTSize)xsz : CTSIZE_INVALID;\n}\n\n/* Get type, qualifiers, size and alignment for a C type ID. */\nCTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp)\n{\n  CTInfo qual = 0;\n  CType *ct = ctype_get(cts, id);\n  for (;;) {\n    CTInfo info = ct->info;\n    if (ctype_isenum(info)) {\n      /* Follow child. Need to look at its attributes, too. */\n    } else if (ctype_isattrib(info)) {\n      if (ctype_isxattrib(info, CTA_QUAL))\n\tqual |= ct->size;\n      else if (ctype_isxattrib(info, CTA_ALIGN) && !(qual & CTFP_ALIGNED))\n\tqual |= CTFP_ALIGNED + CTALIGN(ct->size);\n    } else {\n      if (!(qual & CTFP_ALIGNED)) qual |= (info & CTF_ALIGN);\n      qual |= (info & ~(CTF_ALIGN|CTMASK_CID));\n      lj_assertCTS(ctype_hassize(info) || ctype_isfunc(info),\n\t\t   \"ctype without size\");\n      *szp = ctype_isfunc(info) ? CTSIZE_INVALID : ct->size;\n      break;\n    }\n    ct = ctype_get(cts, ctype_cid(info));\n  }\n  return qual;\n}\n\n/* Get ctype metamethod. */\ncTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)\n{\n  CType *ct = ctype_get(cts, id);\n  cTValue *tv;\n  while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) {\n    id = ctype_cid(ct->info);\n    ct = ctype_get(cts, id);\n  }\n  if (ctype_isptr(ct->info) &&\n      ctype_isfunc(ctype_get(cts, ctype_cid(ct->info))->info))\n    tv = lj_tab_getstr(cts->miscmap, &cts->g->strempty);\n  else\n    tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);\n  if (tv && tvistab(tv) &&\n      (tv = lj_tab_getstr(tabV(tv), mmname_str(cts->g, mm))) && !tvisnil(tv))\n    return tv;\n  return NULL;\n}\n\n/* -- C type representation ----------------------------------------------- */\n\n/* Fixed max. length of a C type representation. */\n#define CTREPR_MAX\t\t512\n\ntypedef struct CTRepr {\n  char *pb, *pe;\n  CTState *cts;\n  lua_State *L;\n  int needsp;\n  int ok;\n  char buf[CTREPR_MAX];\n} CTRepr;\n\n/* Prepend string. */\nstatic void ctype_prepstr(CTRepr *ctr, const char *str, MSize len)\n{\n  char *p = ctr->pb;\n  if (ctr->buf + len+1 > p) { ctr->ok = 0; return; }\n  if (ctr->needsp) *--p = ' ';\n  ctr->needsp = 1;\n  p -= len;\n  while (len-- > 0) p[len] = str[len];\n  ctr->pb = p;\n}\n\n#define ctype_preplit(ctr, str)\tctype_prepstr((ctr), \"\" str, sizeof(str)-1)\n\n/* Prepend char. */\nstatic void ctype_prepc(CTRepr *ctr, int c)\n{\n  if (ctr->buf >= ctr->pb) { ctr->ok = 0; return; }\n  *--ctr->pb = c;\n}\n\n/* Prepend number. */\nstatic void ctype_prepnum(CTRepr *ctr, uint32_t n)\n{\n  char *p = ctr->pb;\n  if (ctr->buf + 10+1 > p) { ctr->ok = 0; return; }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  ctr->pb = p;\n  ctr->needsp = 0;\n}\n\n/* Append char. */\nstatic void ctype_appc(CTRepr *ctr, int c)\n{\n  if (ctr->pe >= ctr->buf + CTREPR_MAX) { ctr->ok = 0; return; }\n  *ctr->pe++ = c;\n}\n\n/* Append number. */\nstatic void ctype_appnum(CTRepr *ctr, uint32_t n)\n{\n  char buf[10];\n  char *p = buf+sizeof(buf);\n  char *q = ctr->pe;\n  if (q > ctr->buf + CTREPR_MAX - 10) { ctr->ok = 0; return; }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  do { *q++ = *p++; } while (p < buf+sizeof(buf));\n  ctr->pe = q;\n}\n\n/* Prepend qualifiers. */\nstatic void ctype_prepqual(CTRepr *ctr, CTInfo info)\n{\n  if ((info & CTF_VOLATILE)) ctype_preplit(ctr, \"volatile\");\n  if ((info & CTF_CONST)) ctype_preplit(ctr, \"const\");\n}\n\n/* Prepend named type. */\nstatic void ctype_preptype(CTRepr *ctr, CType *ct, CTInfo qual, const char *t)\n{\n  if (gcref(ct->name)) {\n    GCstr *str = gco2str(gcref(ct->name));\n    ctype_prepstr(ctr, strdata(str), str->len);\n  } else {\n    if (ctr->needsp) ctype_prepc(ctr, ' ');\n    ctype_prepnum(ctr, ctype_typeid(ctr->cts, ct));\n    ctr->needsp = 1;\n  }\n  ctype_prepstr(ctr, t, (MSize)strlen(t));\n  ctype_prepqual(ctr, qual);\n}\n\nstatic void ctype_repr(CTRepr *ctr, CTypeID id)\n{\n  CType *ct = ctype_get(ctr->cts, id);\n  CTInfo qual = 0;\n  int ptrto = 0;\n  for (;;) {\n    CTInfo info = ct->info;\n    CTSize size = ct->size;\n    switch (ctype_type(info)) {\n    case CT_NUM:\n      if ((info & CTF_BOOL)) {\n\tctype_preplit(ctr, \"bool\");\n      } else if ((info & CTF_FP)) {\n\tif (size == sizeof(double)) ctype_preplit(ctr, \"double\");\n\telse if (size == sizeof(float)) ctype_preplit(ctr, \"float\");\n\telse ctype_preplit(ctr, \"long double\");\n      } else if (size == 1) {\n\tif (!((info ^ CTF_UCHAR) & CTF_UNSIGNED)) ctype_preplit(ctr, \"char\");\n\telse if (CTF_UCHAR) ctype_preplit(ctr, \"signed char\");\n\telse ctype_preplit(ctr, \"unsigned char\");\n      } else if (size < 8) {\n\tif (size == 4) ctype_preplit(ctr, \"int\");\n\telse ctype_preplit(ctr, \"short\");\n\tif ((info & CTF_UNSIGNED)) ctype_preplit(ctr, \"unsigned\");\n      } else {\n\tctype_preplit(ctr, \"_t\");\n\tctype_prepnum(ctr, size*8);\n\tctype_preplit(ctr, \"int\");\n\tif ((info & CTF_UNSIGNED)) ctype_prepc(ctr, 'u');\n      }\n      ctype_prepqual(ctr, (qual|info));\n      return;\n    case CT_VOID:\n      ctype_preplit(ctr, \"void\");\n      ctype_prepqual(ctr, (qual|info));\n      return;\n    case CT_STRUCT:\n      ctype_preptype(ctr, ct, qual, (info & CTF_UNION) ? \"union\" : \"struct\");\n      return;\n    case CT_ENUM:\n      if (id == CTID_CTYPEID) {\n\tctype_preplit(ctr, \"ctype\");\n\treturn;\n      }\n      ctype_preptype(ctr, ct, qual, \"enum\");\n      return;\n    case CT_ATTRIB:\n      if (ctype_attrib(info) == CTA_QUAL) qual |= size;\n      break;\n    case CT_PTR:\n      if ((info & CTF_REF)) {\n\tctype_prepc(ctr, '&');\n      } else {\n\tctype_prepqual(ctr, (qual|info));\n\tif (LJ_64 && size == 4) ctype_preplit(ctr, \"__ptr32\");\n\tctype_prepc(ctr, '*');\n      }\n      qual = 0;\n      ptrto = 1;\n      ctr->needsp = 1;\n      break;\n    case CT_ARRAY:\n      if (ctype_isrefarray(info)) {\n\tctr->needsp = 1;\n\tif (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }\n\tctype_appc(ctr, '[');\n\tif (size != CTSIZE_INVALID) {\n\t  CTSize csize = ctype_child(ctr->cts, ct)->size;\n\t  ctype_appnum(ctr, csize ? size/csize : 0);\n\t} else if ((info & CTF_VLA)) {\n\t  ctype_appc(ctr, '?');\n\t}\n\tctype_appc(ctr, ']');\n      } else if ((info & CTF_COMPLEX)) {\n\tif (size == 2*sizeof(float)) ctype_preplit(ctr, \"float\");\n\tctype_preplit(ctr, \"complex\");\n\treturn;\n      } else {\n\tctype_preplit(ctr, \")))\");\n\tctype_prepnum(ctr, size);\n\tctype_preplit(ctr, \"__attribute__((vector_size(\");\n      }\n      break;\n    case CT_FUNC:\n      ctr->needsp = 1;\n      if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }\n      ctype_appc(ctr, '(');\n      ctype_appc(ctr, ')');\n      break;\n    default:\n      lj_assertG_(ctr->cts->g, 0, \"bad ctype %08x\", info);\n      break;\n    }\n    ct = ctype_get(ctr->cts, ctype_cid(info));\n  }\n}\n\n/* Return a printable representation of a C type. */\nGCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name)\n{\n  global_State *g = G(L);\n  CTRepr ctr;\n  ctr.pb = ctr.pe = &ctr.buf[CTREPR_MAX/2];\n  ctr.cts = ctype_ctsG(g);\n  ctr.L = L;\n  ctr.ok = 1;\n  ctr.needsp = 0;\n  if (name) ctype_prepstr(&ctr, strdata(name), name->len);\n  ctype_repr(&ctr, id);\n  if (LJ_UNLIKELY(!ctr.ok)) return lj_str_newlit(L, \"?\");\n  return lj_str_new(L, ctr.pb, ctr.pe - ctr.pb);\n}\n\n/* Convert int64_t/uint64_t to string with 'LL' or 'ULL' suffix. */\nGCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned)\n{\n  char buf[1+20+3];\n  char *p = buf+sizeof(buf);\n  int sign = 0;\n  *--p = 'L'; *--p = 'L';\n  if (isunsigned) {\n    *--p = 'U';\n  } else if ((int64_t)n < 0) {\n    n = (uint64_t)-(int64_t)n;\n    sign = 1;\n  }\n  do { *--p = (char)('0' + n % 10); } while (n /= 10);\n  if (sign) *--p = '-';\n  return lj_str_new(L, p, (size_t)(buf+sizeof(buf)-p));\n}\n\n/* Convert complex to string with 'i' or 'I' suffix. */\nGCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size)\n{\n  SBuf *sb = lj_buf_tmp_(L);\n  TValue re, im;\n  if (size == 2*sizeof(double)) {\n    re.n = *(double *)sp; im.n = ((double *)sp)[1];\n  } else {\n    re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1];\n  }\n  lj_strfmt_putfnum(sb, STRFMT_G14, re.n);\n  if (!(im.u32.hi & 0x80000000u) || im.n != im.n) lj_buf_putchar(sb, '+');\n  lj_strfmt_putfnum(sb, STRFMT_G14, im.n);\n  lj_buf_putchar(sb, sb->w[-1] >= 'a' ? 'I' : 'i');\n  return lj_buf_str(L, sb);\n}\n\n/* -- C type state -------------------------------------------------------- */\n\n/* Initialize C type table and state. */\nCTState *lj_ctype_init(lua_State *L)\n{\n  CTState *cts = lj_mem_newt(L, sizeof(CTState), CTState);\n  CType *ct = lj_mem_newvec(L, CTTYPETAB_MIN, CType);\n  const char *name = lj_ctype_typenames;\n  CTypeID id;\n  memset(cts, 0, sizeof(CTState));\n  cts->tab = ct;\n  cts->sizetab = CTTYPETAB_MIN;\n  cts->top = CTTYPEINFO_NUM;\n  cts->L = NULL;\n  cts->g = G(L);\n  for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) {\n    CTInfo info = lj_ctype_typeinfo[id];\n    ct->size = (CTSize)((int32_t)(info << 16) >> 26);\n    ct->info = info & 0xffff03ffu;\n    ct->sib = 0;\n    if (ctype_type(info) == CT_KW || ctype_istypedef(info)) {\n      size_t len = strlen(name);\n      GCstr *str = lj_str_new(L, name, len);\n      ctype_setname(ct, str);\n      name += len+1;\n      lj_ctype_addname(cts, ct, id);\n    } else {\n      setgcrefnull(ct->name);\n      ct->next = 0;\n      if (!ctype_isenum(info)) ctype_addtype(cts, ct, id);\n    }\n  }\n  setmref(G(L)->ctype_state, cts);\n  return cts;\n}\n\n/* Free C type table and state. */\nvoid lj_ctype_freestate(global_State *g)\n{\n  CTState *cts = ctype_ctsG(g);\n  if (cts) {\n    lj_ccallback_mcode_free(cts);\n    lj_mem_freevec(g, cts->tab, cts->sizetab, CType);\n    lj_mem_freevec(g, cts->cb.cbid, cts->cb.sizeid, CTypeID1);\n    lj_mem_freet(g, cts);\n  }\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ctype.h",
    "content": "/*\n** C type management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_CTYPE_H\n#define _LJ_CTYPE_H\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n\n#if LJ_HASFFI\n\n/* -- C type definitions -------------------------------------------------- */\n\n/* C type numbers. Highest 4 bits of C type info. ORDER CT. */\nenum {\n  /* Externally visible types. */\n  CT_NUM,\t\t/* Integer or floating-point numbers. */\n  CT_STRUCT,\t\t/* Struct or union. */\n  CT_PTR,\t\t/* Pointer or reference. */\n  CT_ARRAY,\t\t/* Array or complex type. */\n  CT_MAYCONVERT = CT_ARRAY,\n  CT_VOID,\t\t/* Void type. */\n  CT_ENUM,\t\t/* Enumeration. */\n  CT_HASSIZE = CT_ENUM,  /* Last type where ct->size holds the actual size. */\n  CT_FUNC,\t\t/* Function. */\n  CT_TYPEDEF,\t\t/* Typedef. */\n  CT_ATTRIB,\t\t/* Miscellaneous attributes. */\n  /* Internal element types. */\n  CT_FIELD,\t\t/* Struct/union field or function parameter. */\n  CT_BITFIELD,\t\t/* Struct/union bitfield. */\n  CT_CONSTVAL,\t\t/* Constant value. */\n  CT_EXTERN,\t\t/* External reference. */\n  CT_KW\t\t\t/* Keyword. */\n};\n\nLJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR);\nLJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT);\n\n/*\n**  ---------- info ------------\n** |type      flags...  A   cid | size   |  sib  | next  | name  |\n** +----------------------------+--------+-------+-------+-------+--\n** |NUM       BFcvUL..  A       | size   |       | type  |       |\n** |STRUCT    ..cvU..V  A       | size   | field | name? | name? |\n** |PTR       ..cvR...  A   cid | size   |       | type  |       |\n** |ARRAY     VCcv...V  A   cid | size   |       | type  |       |\n** |VOID      ..cv....  A       | size   |       | type  |       |\n** |ENUM                A   cid | size   | const | name? | name? |\n** |FUNC      ....VS.. cc   cid | nargs  | field | name? | name? |\n** |TYPEDEF                 cid |        |       | name  | name  |\n** |ATTRIB        attrnum   cid | attr   | sib?  | type? |       |\n** |FIELD                   cid | offset | field |       | name? |\n** |BITFIELD  B.cvU csz bsz pos | offset | field |       | name? |\n** |CONSTVAL    c           cid | value  | const | name  | name  |\n** |EXTERN                  cid |        | sib?  | name  | name  |\n** |KW                      tok | size   |       | name  | name  |\n** +----------------------------+--------+-------+-------+-------+--\n**        ^^  ^^--- bits used for C type conversion dispatch\n*/\n\n/* C type info flags.     TFFArrrr  */\n#define CTF_BOOL\t0x08000000u\t/* Boolean: NUM, BITFIELD. */\n#define CTF_FP\t\t0x04000000u\t/* Floating-point: NUM. */\n#define CTF_CONST\t0x02000000u\t/* Const qualifier. */\n#define CTF_VOLATILE\t0x01000000u\t/* Volatile qualifier. */\n#define CTF_UNSIGNED\t0x00800000u\t/* Unsigned: NUM, BITFIELD. */\n#define CTF_LONG\t0x00400000u\t/* Long: NUM. */\n#define CTF_VLA\t\t0x00100000u\t/* Variable-length: ARRAY, STRUCT. */\n#define CTF_REF\t\t0x00800000u\t/* Reference: PTR. */\n#define CTF_VECTOR\t0x08000000u\t/* Vector: ARRAY. */\n#define CTF_COMPLEX\t0x04000000u\t/* Complex: ARRAY. */\n#define CTF_UNION\t0x00800000u\t/* Union: STRUCT. */\n#define CTF_VARARG\t0x00800000u\t/* Vararg: FUNC. */\n#define CTF_SSEREGPARM\t0x00400000u\t/* SSE register parameters: FUNC. */\n\n#define CTF_QUAL\t(CTF_CONST|CTF_VOLATILE)\n#define CTF_ALIGN\t(CTMASK_ALIGN<<CTSHIFT_ALIGN)\n#define CTF_UCHAR\t((char)-1 > 0 ? CTF_UNSIGNED : 0)\n\n/* Flags used in parser.  .F.Ammvf   cp->attr  */\n#define CTFP_ALIGNED\t0x00000001u\t/* cp->attr + ALIGN */\n#define CTFP_PACKED\t0x00000002u\t/* cp->attr */\n/*                        ...C...f   cp->fattr */\n#define CTFP_CCONV\t0x00000001u\t/* cp->fattr + CCONV/[SSE]REGPARM */\n\n/* C type info bitfields. */\n#define CTMASK_CID\t0x0000ffffu\t/* Max. 65536 type IDs. */\n#define CTMASK_NUM\t0xf0000000u\t/* Max. 16 type numbers. */\n#define CTSHIFT_NUM\t28\n#define CTMASK_ALIGN\t15\t\t/* Max. alignment is 2^15. */\n#define CTSHIFT_ALIGN\t16\n#define CTMASK_ATTRIB\t255\t\t/* Max. 256 attributes. */\n#define CTSHIFT_ATTRIB\t16\n#define CTMASK_CCONV\t3\t\t/* Max. 4 calling conventions. */\n#define CTSHIFT_CCONV\t16\n#define CTMASK_REGPARM\t3\t\t/* Max. 0-3 regparms. */\n#define CTSHIFT_REGPARM\t18\n/* Bitfields only used in parser. */\n#define CTMASK_VSIZEP\t15\t\t/* Max. vector size is 2^15. */\n#define CTSHIFT_VSIZEP\t4\n#define CTMASK_MSIZEP\t255\t\t/* Max. type size (via mode) is 128. */\n#define CTSHIFT_MSIZEP\t8\n\n/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */\n#define CTBSZ_MAX\t32\t\t/* Max. size of bitfield is 32 bit. */\n#define CTBSZ_FIELD\t127\t\t/* Temp. marker for regular field. */\n#define CTMASK_BITPOS\t127\n#define CTMASK_BITBSZ\t127\n#define CTMASK_BITCSZ\t127\n#define CTSHIFT_BITPOS\t0\n#define CTSHIFT_BITBSZ\t8\n#define CTSHIFT_BITCSZ\t16\n\n#define CTF_INSERT(info, field, val) \\\n  info = (info & ~(CTMASK_##field<<CTSHIFT_##field)) | \\\n\t  (((CTSize)(val) & CTMASK_##field) << CTSHIFT_##field)\n\n/* Calling conventions. ORDER CC */\nenum { CTCC_CDECL, CTCC_THISCALL, CTCC_FASTCALL, CTCC_STDCALL };\n\n/* Attribute numbers. */\nenum {\n  CTA_NONE,\t\t/* Ignored attribute. Must be zero. */\n  CTA_QUAL,\t\t/* Unmerged qualifiers. */\n  CTA_ALIGN,\t\t/* Alignment override. */\n  CTA_SUBTYPE,\t\t/* Transparent sub-type. */\n  CTA_REDIR,\t\t/* Redirected symbol name. */\n  CTA_BAD,\t\t/* To catch bad IDs. */\n  CTA__MAX\n};\n\n/* Special sizes. */\n#define CTSIZE_INVALID\t0xffffffffu\n\ntypedef uint32_t CTInfo;\t/* Type info. */\ntypedef uint32_t CTSize;\t/* Type size. */\ntypedef uint32_t CTypeID;\t/* Type ID. */\ntypedef uint16_t CTypeID1;\t/* Minimum-sized type ID. */\n\n/* C type table element. */\ntypedef struct CType {\n  CTInfo info;\t\t/* Type info. */\n  CTSize size;\t\t/* Type size or other info. */\n  CTypeID1 sib;\t\t/* Sibling element. */\n  CTypeID1 next;\t/* Next element in hash chain. */\n  GCRef name;\t\t/* Element name (GCstr). */\n} CType;\n\n#define CTHASH_SIZE\t128\t/* Number of hash anchors. */\n#define CTHASH_MASK\t(CTHASH_SIZE-1)\n\n/* Simplify target-specific configuration. Checked in lj_ccall.h. */\n#define CCALL_MAX_GPR\t\t8\n#define CCALL_MAX_FPR\t\t8\n\ntypedef LJ_ALIGN(8) union FPRCBArg { double d; float f[2]; } FPRCBArg;\n\n/* C callback state. Defined here, to avoid dragging in lj_ccall.h. */\n\ntypedef LJ_ALIGN(8) struct CCallback {\n  FPRCBArg fpr[CCALL_MAX_FPR];\t/* Arguments/results in FPRs. */\n  intptr_t gpr[CCALL_MAX_GPR];\t/* Arguments/results in GPRs. */\n  intptr_t *stack;\t\t/* Pointer to arguments on stack. */\n  void *mcode;\t\t\t/* Machine code for callback func. pointers. */\n  CTypeID1 *cbid;\t\t/* Callback type table. */\n  MSize sizeid;\t\t\t/* Size of callback type table. */\n  MSize topid;\t\t\t/* Highest unused callback type table slot. */\n  MSize slot;\t\t\t/* Current callback slot. */\n} CCallback;\n\n/* C type state. */\ntypedef struct CTState {\n  CType *tab;\t\t/* C type table. */\n  CTypeID top;\t\t/* Current top of C type table. */\n  MSize sizetab;\t/* Size of C type table. */\n  lua_State *L;\t\t/* Lua state (needed for errors and allocations). */\n  global_State *g;\t/* Global state. */\n  GCtab *finalizer;\t/* Map of cdata to finalizer. */\n  GCtab *miscmap;\t/* Map of -CTypeID to metatable and cb slot to func. */\n  CCallback cb;\t\t/* Temporary callback state. */\n  CTypeID1 hash[CTHASH_SIZE];  /* Hash anchors for C type table. */\n} CTState;\n\n#define CTINFO(ct, flags)\t(((CTInfo)(ct) << CTSHIFT_NUM) + (flags))\n#define CTALIGN(al)\t\t((CTSize)(al) << CTSHIFT_ALIGN)\n#define CTATTRIB(at)\t\t((CTInfo)(at) << CTSHIFT_ATTRIB)\n\n#define ctype_type(info)\t((info) >> CTSHIFT_NUM)\n#define ctype_cid(info)\t\t((CTypeID)((info) & CTMASK_CID))\n#define ctype_align(info)\t(((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN)\n#define ctype_attrib(info)\t(((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB)\n#define ctype_bitpos(info)\t(((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS)\n#define ctype_bitbsz(info)\t(((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ)\n#define ctype_bitcsz(info)\t(((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ)\n#define ctype_vsizeP(info)\t(((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP)\n#define ctype_msizeP(info)\t(((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP)\n#define ctype_cconv(info)\t(((info) >> CTSHIFT_CCONV) & CTMASK_CCONV)\n\n/* Simple type checks. */\n#define ctype_isnum(info)\t(ctype_type((info)) == CT_NUM)\n#define ctype_isvoid(info)\t(ctype_type((info)) == CT_VOID)\n#define ctype_isptr(info)\t(ctype_type((info)) == CT_PTR)\n#define ctype_isarray(info)\t(ctype_type((info)) == CT_ARRAY)\n#define ctype_isstruct(info)\t(ctype_type((info)) == CT_STRUCT)\n#define ctype_isfunc(info)\t(ctype_type((info)) == CT_FUNC)\n#define ctype_isenum(info)\t(ctype_type((info)) == CT_ENUM)\n#define ctype_istypedef(info)\t(ctype_type((info)) == CT_TYPEDEF)\n#define ctype_isattrib(info)\t(ctype_type((info)) == CT_ATTRIB)\n#define ctype_isfield(info)\t(ctype_type((info)) == CT_FIELD)\n#define ctype_isbitfield(info)\t(ctype_type((info)) == CT_BITFIELD)\n#define ctype_isconstval(info)\t(ctype_type((info)) == CT_CONSTVAL)\n#define ctype_isextern(info)\t(ctype_type((info)) == CT_EXTERN)\n#define ctype_hassize(info)\t(ctype_type((info)) <= CT_HASSIZE)\n\n/* Combined type and flag checks. */\n#define ctype_isinteger(info) \\\n  (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0))\n#define ctype_isinteger_or_bool(info) \\\n  (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0))\n#define ctype_isbool(info) \\\n  (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL))\n#define ctype_isfp(info) \\\n  (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP))\n\n#define ctype_ispointer(info) \\\n  ((ctype_type(info) >> 1) == (CT_PTR >> 1))  /* Pointer or array. */\n#define ctype_isref(info) \\\n  (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF))\n\n#define ctype_isrefarray(info) \\\n  (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0))\n#define ctype_isvector(info) \\\n  (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR))\n#define ctype_iscomplex(info) \\\n  (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX))\n\n#define ctype_isvltype(info) \\\n  (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<<CTSHIFT_NUM))) == \\\n   CTINFO(CT_STRUCT, CTF_VLA))  /* VL array or VL struct. */\n#define ctype_isvlarray(info) \\\n  (((info) & (CTMASK_NUM|CTF_VLA)) == CTINFO(CT_ARRAY, CTF_VLA))\n\n#define ctype_isxattrib(info, at) \\\n  (((info) & (CTMASK_NUM|CTATTRIB(CTMASK_ATTRIB))) == \\\n   CTINFO(CT_ATTRIB, CTATTRIB(at)))\n\n/* Target-dependent sizes and alignments. */\n#if LJ_64\n#define CTSIZE_PTR\t8\n#define CTALIGN_PTR\tCTALIGN(3)\n#else\n#define CTSIZE_PTR\t4\n#define CTALIGN_PTR\tCTALIGN(2)\n#endif\n\n#define CTINFO_REF(ref) \\\n  CTINFO(CT_PTR, (CTF_CONST|CTF_REF|CTALIGN_PTR) + (ref))\n\n#define CT_MEMALIGN\t3\t/* Alignment guaranteed by memory allocator. */\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertCTS(c, ...)\t(lj_assertG_(cts->g, (c), __VA_ARGS__))\n#else\n#define lj_assertCTS(c, ...)\t((void)cts)\n#endif\n\n/* -- Predefined types ---------------------------------------------------- */\n\n/* Target-dependent types. */\n#if LJ_TARGET_PPC\n#define CTTYDEFP(_) \\\n  _(LINT32,\t\t4,\tCT_NUM, CTF_LONG|CTALIGN(2))\n#else\n#define CTTYDEFP(_)\n#endif\n\n/* Common types. */\n#define CTTYDEF(_) \\\n  _(NONE,\t\t0,\tCT_ATTRIB, CTATTRIB(CTA_BAD)) \\\n  _(VOID,\t\t-1,\tCT_VOID, CTALIGN(0)) \\\n  _(CVOID,\t\t-1,\tCT_VOID, CTF_CONST|CTALIGN(0)) \\\n  _(BOOL,\t\t1,\tCT_NUM, CTF_BOOL|CTF_UNSIGNED|CTALIGN(0)) \\\n  _(CCHAR,\t\t1,\tCT_NUM, CTF_CONST|CTF_UCHAR|CTALIGN(0)) \\\n  _(INT8,\t\t1,\tCT_NUM, CTALIGN(0)) \\\n  _(UINT8,\t\t1,\tCT_NUM, CTF_UNSIGNED|CTALIGN(0)) \\\n  _(INT16,\t\t2,\tCT_NUM, CTALIGN(1)) \\\n  _(UINT16,\t\t2,\tCT_NUM, CTF_UNSIGNED|CTALIGN(1)) \\\n  _(INT32,\t\t4,\tCT_NUM, CTALIGN(2)) \\\n  _(UINT32,\t\t4,\tCT_NUM, CTF_UNSIGNED|CTALIGN(2)) \\\n  _(INT64,\t\t8,\tCT_NUM, CTF_LONG|CTALIGN(3)) \\\n  _(UINT64,\t\t8,\tCT_NUM, CTF_UNSIGNED|CTF_LONG|CTALIGN(3)) \\\n  _(FLOAT,\t\t4,\tCT_NUM, CTF_FP|CTALIGN(2)) \\\n  _(DOUBLE,\t\t8,\tCT_NUM, CTF_FP|CTALIGN(3)) \\\n  _(COMPLEX_FLOAT,\t8,\tCT_ARRAY, CTF_COMPLEX|CTALIGN(2)|CTID_FLOAT) \\\n  _(COMPLEX_DOUBLE,\t16,\tCT_ARRAY, CTF_COMPLEX|CTALIGN(3)|CTID_DOUBLE) \\\n  _(P_VOID,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_VOID) \\\n  _(P_CVOID,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_CVOID) \\\n  _(P_CCHAR,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_CCHAR) \\\n  _(P_UINT8,\tCTSIZE_PTR,\tCT_PTR, CTALIGN_PTR|CTID_UINT8) \\\n  _(A_CCHAR,\t\t-1,\tCT_ARRAY, CTF_CONST|CTALIGN(0)|CTID_CCHAR) \\\n  _(CTYPEID,\t\t4,\tCT_ENUM, CTALIGN(2)|CTID_INT32) \\\n  CTTYDEFP(_) \\\n  /* End of type list. */\n\n/* Public predefined type IDs. */\nenum {\n#define CTTYIDDEF(id, sz, ct, info)\tCTID_##id,\nCTTYDEF(CTTYIDDEF)\n#undef CTTYIDDEF\n  /* Predefined typedefs and keywords follow. */\n  CTID_MAX = 65536\n};\n\n/* Target-dependent type IDs. */\n#if LJ_64\n#define CTID_INT_PSZ\tCTID_INT64\n#define CTID_UINT_PSZ\tCTID_UINT64\n#else\n#define CTID_INT_PSZ\tCTID_INT32\n#define CTID_UINT_PSZ\tCTID_UINT32\n#endif\n\n#if LJ_ABI_WIN\n#define CTID_WCHAR\tCTID_UINT16\n#elif LJ_TARGET_PPC\n#define CTID_WCHAR\tCTID_LINT32\n#else\n#define CTID_WCHAR\tCTID_INT32\n#endif\n\n/* -- C tokens and keywords ----------------------------------------------- */\n\n/* C lexer keywords. */\n#define CTOKDEF(_) \\\n  _(IDENT, \"<identifier>\") _(STRING, \"<string>\") \\\n  _(INTEGER, \"<integer>\") _(EOF, \"<eof>\") \\\n  _(OROR, \"||\") _(ANDAND, \"&&\") _(EQ, \"==\") _(NE, \"!=\") \\\n  _(LE, \"<=\") _(GE, \">=\") _(SHL, \"<<\") _(SHR, \">>\") _(DEREF, \"->\")\n\n/* Simple declaration specifiers. */\n#define CDSDEF(_) \\\n  _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \\\n  _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \\\n  _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \\\n  _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER)\n\n/* C keywords. */\n#define CKWDEF(_) \\\n  CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \\\n  _(DECLSPEC) _(CCDECL) _(PTRSZ) \\\n  _(STRUCT) _(UNION) _(ENUM) \\\n  _(SIZEOF) _(ALIGNOF)\n\n/* C token numbers. */\nenum {\n  CTOK_OFS = 255,\n#define CTOKNUM(name, sym)\tCTOK_##name,\n#define CKWNUM(name)\t\tCTOK_##name,\nCTOKDEF(CTOKNUM)\nCKWDEF(CKWNUM)\n#undef CTOKNUM\n#undef CKWNUM\n  CTOK_FIRSTDECL = CTOK_VOID,\n  CTOK_FIRSTSCL = CTOK_TYPEDEF,\n  CTOK_LASTDECLFLAG = CTOK_REGISTER,\n  CTOK_LASTDECL = CTOK_ENUM\n};\n\n/* Declaration specifier flags. */\nenum {\n#define CDSFLAG(name)\tCDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)),\nCDSDEF(CDSFLAG)\n#undef CDSFLAG\n  CDF__END\n};\n\n#define CDF_SCL  (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER)\n\n/* -- C type management --------------------------------------------------- */\n\n#define ctype_ctsG(g)\t\t(mref((g)->ctype_state, CTState))\n\n/* Get C type state. */\nstatic LJ_AINLINE CTState *ctype_cts(lua_State *L)\n{\n  CTState *cts = ctype_ctsG(G(L));\n  cts->L = L;  /* Save L for errors and allocations. */\n  return cts;\n}\n\n/* Load FFI library on-demand. */\n#define ctype_loadffi(L) \\\n  do { \\\n    if (!ctype_ctsG(G(L))) { \\\n      ptrdiff_t oldtop = (char *)L->top - mref(L->stack, char); \\\n      luaopen_ffi(L); \\\n      L->top = (TValue *)(mref(L->stack, char) + oldtop); \\\n    } \\\n  } while (0)\n\n/* Save and restore state of C type table. */\n#define LJ_CTYPE_SAVE(cts)\tCTState savects_ = *(cts)\n#define LJ_CTYPE_RESTORE(cts) \\\n  ((cts)->top = savects_.top, \\\n   memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash)))\n\n/* Check C type ID for validity when assertions are enabled. */\nstatic LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id)\n{\n  UNUSED(cts);\n  lj_assertCTS(id > 0 && id < cts->top, \"bad CTID %d\", id);\n  return id;\n}\n\n/* Get C type for C type ID. */\nstatic LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id)\n{\n  return &cts->tab[ctype_check(cts, id)];\n}\n\n/* Get C type ID for a C type. */\n#define ctype_typeid(cts, ct)\t((CTypeID)((ct) - (cts)->tab))\n\n/* Get child C type. */\nstatic LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct)\n{\n  lj_assertCTS(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) ||\n\t       ctype_isbitfield(ct->info)),\n\t       \"ctype %08x has no children\", ct->info);\n  return ctype_get(cts, ctype_cid(ct->info));\n}\n\n/* Get raw type for a C type ID. */\nstatic LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id)\n{\n  CType *ct = ctype_get(cts, id);\n  while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct);\n  return ct;\n}\n\n/* Get raw type of the child of a C type. */\nstatic LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct)\n{\n  do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info));\n  return ct;\n}\n\n/* Set the name of a C type table element. */\nstatic LJ_AINLINE void ctype_setname(CType *ct, GCstr *s)\n{\n  /* NOBARRIER: mark string as fixed -- the C type table is never collected. */\n  fixstring(s);\n  setgcref(ct->name, obj2gco(s));\n}\n\nLJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp);\nLJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size);\nLJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id);\nLJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name,\n\t\t\t\t uint32_t tmask);\nLJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name,\n\t\t\t\t  CTSize *ofs, CTInfo *qual);\n#define lj_ctype_getfield(cts, ct, name, ofs) \\\n  lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL)\nLJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);\nLJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);\nLJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);\nLJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);\nLJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);\nLJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);\nLJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);\nLJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size);\nLJ_FUNC CTState *lj_ctype_init(lua_State *L);\nLJ_FUNC void lj_ctype_freestate(global_State *g);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_debug.c",
    "content": "/*\n** Debugging and introspection.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_debug_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_buf.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n\n/* -- Frames -------------------------------------------------------------- */\n\n/* Get frame corresponding to a level. */\ncTValue *lj_debug_frame(lua_State *L, int level, int *size)\n{\n  cTValue *frame, *nextframe, *bot = tvref(L->stack)+LJ_FR2;\n  /* Traverse frames backwards. */\n  for (nextframe = frame = L->base-1; frame > bot; ) {\n    if (frame_gc(frame) == obj2gco(L))\n      level++;  /* Skip dummy frames. See lj_err_optype_call(). */\n    if (level-- == 0) {\n      *size = (int)(nextframe - frame);\n      return frame;  /* Level found. */\n    }\n    nextframe = frame;\n    if (frame_islua(frame)) {\n      frame = frame_prevl(frame);\n    } else {\n      if (frame_isvarg(frame))\n\tlevel++;  /* Skip vararg pseudo-frame. */\n      frame = frame_prevd(frame);\n    }\n  }\n  *size = level;\n  return NULL;  /* Level not found. */\n}\n\n/* Invalid bytecode position. */\n#define NO_BCPOS\t(~(BCPos)0)\n\n/* Return bytecode position for function/frame or NO_BCPOS. */\nstatic BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)\n{\n  const BCIns *ins;\n  GCproto *pt;\n  BCPos pos;\n  lj_assertL(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD,\n\t     \"function or frame expected\");\n  if (!isluafunc(fn)) {  /* Cannot derive a PC for non-Lua functions. */\n    return NO_BCPOS;\n  } else if (nextframe == NULL) {  /* Lua function on top. */\n    void *cf = cframe_raw(L->cframe);\n    if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf))\n      return NO_BCPOS;\n    ins = cframe_pc(cf);  /* Only happens during error/hook handling. */\n  } else {\n    if (frame_islua(nextframe)) {\n      ins = frame_pc(nextframe);\n    } else if (frame_iscont(nextframe)) {\n      ins = frame_contpc(nextframe);\n    } else {\n      /* Lua function below errfunc/gc/hook: find cframe to get the PC. */\n      void *cf = cframe_raw(L->cframe);\n      TValue *f = L->base-1;\n      for (;;) {\n\tif (cf == NULL)\n\t  return NO_BCPOS;\n\twhile (cframe_nres(cf) < 0) {\n\t  if (f >= restorestack(L, -cframe_nres(cf)))\n\t    break;\n\t  cf = cframe_raw(cframe_prev(cf));\n\t  if (cf == NULL)\n\t    return NO_BCPOS;\n\t}\n\tif (f < nextframe)\n\t  break;\n\tif (frame_islua(f)) {\n\t  f = frame_prevl(f);\n\t} else {\n\t  if (frame_isc(f) || (frame_iscont(f) && frame_iscont_fficb(f)))\n\t    cf = cframe_raw(cframe_prev(cf));\n\t  f = frame_prevd(f);\n\t}\n      }\n      ins = cframe_pc(cf);\n      if (!ins) return NO_BCPOS;\n    }\n  }\n  pt = funcproto(fn);\n  pos = proto_bcpos(pt, ins) - 1;\n#if LJ_HASJIT\n  if (pos > pt->sizebc) {  /* Undo the effects of lj_trace_exit for JLOOP. */\n    GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins));\n    lj_assertL(bc_isret(bc_op(ins[-1])), \"return bytecode expected\");\n    pos = proto_bcpos(pt, mref(T->startpc, const BCIns));\n  }\n#endif\n  return pos;\n}\n\n/* -- Line numbers -------------------------------------------------------- */\n\n/* Get line number for a bytecode position. */\nBCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc)\n{\n  const void *lineinfo = proto_lineinfo(pt);\n  if (pc <= pt->sizebc && lineinfo) {\n    BCLine first = pt->firstline;\n    if (pc == pt->sizebc) return first + pt->numline;\n    if (pc-- == 0) return first;\n    if (pt->numline < 256)\n      return first + (BCLine)((const uint8_t *)lineinfo)[pc];\n    else if (pt->numline < 65536)\n      return first + (BCLine)((const uint16_t *)lineinfo)[pc];\n    else\n      return first + (BCLine)((const uint32_t *)lineinfo)[pc];\n  }\n  return 0;\n}\n\n/* Get line number for function/frame. */\nstatic BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe)\n{\n  BCPos pc = debug_framepc(L, fn, nextframe);\n  if (pc != NO_BCPOS) {\n    GCproto *pt = funcproto(fn);\n    lj_assertL(pc <= pt->sizebc, \"PC out of range\");\n    return lj_debug_line(pt, pc);\n  }\n  return -1;\n}\n\n/* -- Variable names ------------------------------------------------------ */\n\n/* Get name of a local variable from slot number and PC. */\nstatic const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot)\n{\n  const char *p = (const char *)proto_varinfo(pt);\n  if (p) {\n    BCPos lastpc = 0;\n    for (;;) {\n      const char *name = p;\n      uint32_t vn = *(const uint8_t *)p;\n      BCPos startpc, endpc;\n      if (vn < VARNAME__MAX) {\n\tif (vn == VARNAME_END) break;  /* End of varinfo. */\n      } else {\n\tdo { p++; } while (*(const uint8_t *)p);  /* Skip over variable name. */\n      }\n      p++;\n      lastpc = startpc = lastpc + lj_buf_ruleb128(&p);\n      if (startpc > pc) break;\n      endpc = startpc + lj_buf_ruleb128(&p);\n      if (pc < endpc && slot-- == 0) {\n\tif (vn < VARNAME__MAX) {\n#define VARNAMESTR(name, str)\tstr \"\\0\"\n\t  name = VARNAMEDEF(VARNAMESTR);\n#undef VARNAMESTR\n\t  if (--vn) while (*name++ || --vn) ;\n\t}\n\treturn name;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Get name of local variable from 1-based slot number and function/frame. */\nstatic TValue *debug_localname(lua_State *L, const lua_Debug *ar,\n\t\t\t       const char **name, BCReg slot1)\n{\n  uint32_t offset = (uint32_t)ar->i_ci & 0xffff;\n  uint32_t size = (uint32_t)ar->i_ci >> 16;\n  TValue *frame = tvref(L->stack) + offset;\n  TValue *nextframe = size ? frame + size : NULL;\n  GCfunc *fn = frame_func(frame);\n  BCPos pc = debug_framepc(L, fn, nextframe);\n  if (!nextframe) nextframe = L->top+LJ_FR2;\n  if ((int)slot1 < 0) {  /* Negative slot number is for varargs. */\n    if (pc != NO_BCPOS) {\n      GCproto *pt = funcproto(fn);\n      if ((pt->flags & PROTO_VARARG)) {\n\tslot1 = pt->numparams + (BCReg)(-(int)slot1);\n\tif (frame_isvarg(frame)) {  /* Vararg frame has been set up? (pc!=0) */\n\t  nextframe = frame;\n\t  frame = frame_prevd(frame);\n\t}\n\tif (frame + slot1+LJ_FR2 < nextframe) {\n\t  *name = \"(*vararg)\";\n\t  return frame+slot1;\n\t}\n      }\n    }\n    return NULL;\n  }\n  if (pc != NO_BCPOS &&\n      (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL)\n    ;\n  else if (slot1 > 0 && frame + slot1+LJ_FR2 < nextframe)\n    *name = \"(*temporary)\";\n  return frame+slot1;\n}\n\n/* Get name of upvalue. */\nconst char *lj_debug_uvname(GCproto *pt, uint32_t idx)\n{\n  const uint8_t *p = proto_uvinfo(pt);\n  lj_assertX(idx < pt->sizeuv, \"bad upvalue index\");\n  if (!p) return \"\";\n  if (idx) while (*p++ || --idx) ;\n  return (const char *)p;\n}\n\n/* Get name and value of upvalue. */\nconst char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp, GCobj **op)\n{\n  if (tvisfunc(o)) {\n    GCfunc *fn = funcV(o);\n    if (isluafunc(fn)) {\n      GCproto *pt = funcproto(fn);\n      if (idx < pt->sizeuv) {\n\tGCobj *uvo = gcref(fn->l.uvptr[idx]);\n\t*tvp = uvval(&uvo->uv);\n\t*op = uvo;\n\treturn lj_debug_uvname(pt, idx);\n      }\n    } else {\n      if (idx < fn->c.nupvalues) {\n\t*tvp = &fn->c.upvalue[idx];\n\t*op = obj2gco(fn);\n\treturn \"\";\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Deduce name of an object from slot number and PC. */\nconst char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot,\n\t\t\t      const char **name)\n{\n  const char *lname;\nrestart:\n  lname = debug_varname(pt, proto_bcpos(pt, ip), slot);\n  if (lname != NULL) { *name = lname; return \"local\"; }\n  while (--ip > proto_bc(pt)) {\n    BCIns ins = *ip;\n    BCOp op = bc_op(ins);\n    BCReg ra = bc_a(ins);\n    if (bcmode_a(op) == BCMbase) {\n      if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins)))\n\treturn NULL;\n    } else if (bcmode_a(op) == BCMdst && ra == slot) {\n      switch (bc_op(ins)) {\n      case BC_MOV:\n\tif (ra == slot) { slot = bc_d(ins); goto restart; }\n\tbreak;\n      case BC_GGET:\n\t*name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins))));\n\treturn \"global\";\n      case BC_TGETS:\n\t*name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins))));\n\tif (ip > proto_bc(pt)) {\n\t  BCIns insp = ip[-1];\n\t  if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1+LJ_FR2 &&\n\t      bc_d(insp) == bc_b(ins))\n\t    return \"method\";\n\t}\n\treturn \"field\";\n      case BC_UGET:\n\t*name = lj_debug_uvname(pt, bc_d(ins));\n\treturn \"upvalue\";\n      default:\n\treturn NULL;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Deduce function name from caller of a frame. */\nconst char *lj_debug_funcname(lua_State *L, cTValue *frame, const char **name)\n{\n  cTValue *pframe;\n  GCfunc *fn;\n  BCPos pc;\n  if (frame <= tvref(L->stack)+LJ_FR2)\n    return NULL;\n  if (frame_isvarg(frame))\n    frame = frame_prevd(frame);\n  pframe = frame_prev(frame);\n  fn = frame_func(pframe);\n  pc = debug_framepc(L, fn, frame);\n  if (pc != NO_BCPOS) {\n    GCproto *pt = funcproto(fn);\n    const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)];\n    MMS mm = bcmode_mm(bc_op(*ip));\n    if (mm == MM_call) {\n      BCReg slot = bc_a(*ip);\n      if (bc_op(*ip) == BC_ITERC) slot -= 3;\n      return lj_debug_slotname(pt, ip, slot, name);\n    } else if (mm != MM__MAX) {\n      *name = strdata(mmname_str(G(L), mm));\n      return \"metamethod\";\n    }\n  }\n  return NULL;\n}\n\n/* -- Source code locations ----------------------------------------------- */\n\n/* Generate shortened source name. */\nvoid lj_debug_shortname(char *out, GCstr *str, BCLine line)\n{\n  const char *src = strdata(str);\n  if (*src == '=') {\n    strncpy(out, src+1, LUA_IDSIZE);  /* Remove first char. */\n    out[LUA_IDSIZE-1] = '\\0';  /* Ensures null termination. */\n  } else if (*src == '@') {  /* Output \"source\", or \"...source\". */\n    size_t len = str->len-1;\n    src++;  /* Skip the `@' */\n    if (len >= LUA_IDSIZE) {\n      src += len-(LUA_IDSIZE-4);  /* Get last part of file name. */\n      *out++ = '.'; *out++ = '.'; *out++ = '.';\n    }\n    strcpy(out, src);\n  } else {  /* Output [string \"string\"] or [builtin:name]. */\n    size_t len;  /* Length, up to first control char. */\n    for (len = 0; len < LUA_IDSIZE-12; len++)\n      if (((const unsigned char *)src)[len] < ' ') break;\n    strcpy(out, line == ~(BCLine)0 ? \"[builtin:\" : \"[string \\\"\"); out += 9;\n    if (src[len] != '\\0') {  /* Must truncate? */\n      if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15;\n      strncpy(out, src, len); out += len;\n      strcpy(out, \"...\"); out += 3;\n    } else {\n      strcpy(out, src); out += len;\n    }\n    strcpy(out, line == ~(BCLine)0 ? \"]\" : \"\\\"]\");\n  }\n}\n\n/* Add current location of a frame to error message. */\nvoid lj_debug_addloc(lua_State *L, const char *msg,\n\t\t     cTValue *frame, cTValue *nextframe)\n{\n  if (frame) {\n    GCfunc *fn = frame_func(frame);\n    if (isluafunc(fn)) {\n      BCLine line = debug_frameline(L, fn, nextframe);\n      if (line >= 0) {\n\tGCproto *pt = funcproto(fn);\n\tchar buf[LUA_IDSIZE];\n\tlj_debug_shortname(buf, proto_chunkname(pt), pt->firstline);\n\tlj_strfmt_pushf(L, \"%s:%d: %s\", buf, line, msg);\n\treturn;\n      }\n    }\n  }\n  lj_strfmt_pushf(L, \"%s\", msg);\n}\n\n/* Push location string for a bytecode position to Lua stack. */\nvoid lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc)\n{\n  GCstr *name = proto_chunkname(pt);\n  const char *s = strdata(name);\n  MSize i, len = name->len;\n  BCLine line = lj_debug_line(pt, pc);\n  if (pt->firstline == ~(BCLine)0) {\n    lj_strfmt_pushf(L, \"builtin:%s\", s);\n  } else if (*s == '@') {\n    s++; len--;\n    for (i = len; i > 0; i--)\n      if (s[i] == '/' || s[i] == '\\\\') {\n\ts += i+1;\n\tbreak;\n      }\n    lj_strfmt_pushf(L, \"%s:%d\", s, line);\n  } else if (len > 40) {\n    lj_strfmt_pushf(L, \"%p:%d\", pt, line);\n  } else if (*s == '=') {\n    lj_strfmt_pushf(L, \"%s:%d\", s+1, line);\n  } else {\n    lj_strfmt_pushf(L, \"\\\"%s\\\":%d\", s, line);\n  }\n}\n\n/* -- Public debug API ---------------------------------------------------- */\n\n/* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */\n\nLUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)\n{\n  const char *name = NULL;\n  if (ar) {\n    TValue *o = debug_localname(L, ar, &name, (BCReg)n);\n    if (name) {\n      copyTV(L, L->top, o);\n      incr_top(L);\n    }\n  } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) {\n    name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1);\n  }\n  return name;\n}\n\nLUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n)\n{\n  const char *name = NULL;\n  TValue *o = debug_localname(L, ar, &name, (BCReg)n);\n  if (name)\n    copyTV(L, o, L->top-1);\n  L->top--;\n  return name;\n}\n\nint lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)\n{\n  int opt_f = 0, opt_L = 0;\n  TValue *frame = NULL;\n  TValue *nextframe = NULL;\n  GCfunc *fn;\n  if (*what == '>') {\n    TValue *func = L->top - 1;\n    if (!tvisfunc(func)) return 0;\n    fn = funcV(func);\n    L->top--;\n    what++;\n  } else {\n    uint32_t offset = (uint32_t)ar->i_ci & 0xffff;\n    uint32_t size = (uint32_t)ar->i_ci >> 16;\n    lj_assertL(offset != 0, \"bad frame offset\");\n    frame = tvref(L->stack) + offset;\n    if (size) nextframe = frame + size;\n    lj_assertL(frame <= tvref(L->maxstack) &&\n\t       (!nextframe || nextframe <= tvref(L->maxstack)),\n\t       \"broken frame chain\");\n    fn = frame_func(frame);\n    lj_assertL(fn->c.gct == ~LJ_TFUNC, \"bad frame function\");\n  }\n  for (; *what; what++) {\n    if (*what == 'S') {\n      if (isluafunc(fn)) {\n\tGCproto *pt = funcproto(fn);\n\tBCLine firstline = pt->firstline;\n\tGCstr *name = proto_chunkname(pt);\n\tar->source = strdata(name);\n\tlj_debug_shortname(ar->short_src, name, pt->firstline);\n\tar->linedefined = (int)firstline;\n\tar->lastlinedefined = (int)(firstline + pt->numline);\n\tar->what = (firstline || !pt->numline) ? \"Lua\" : \"main\";\n      } else {\n\tar->source = \"=[C]\";\n\tar->short_src[0] = '[';\n\tar->short_src[1] = 'C';\n\tar->short_src[2] = ']';\n\tar->short_src[3] = '\\0';\n\tar->linedefined = -1;\n\tar->lastlinedefined = -1;\n\tar->what = \"C\";\n      }\n    } else if (*what == 'l') {\n      ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1;\n    } else if (*what == 'u') {\n      ar->nups = fn->c.nupvalues;\n      if (ext) {\n\tif (isluafunc(fn)) {\n\t  GCproto *pt = funcproto(fn);\n\t  ar->nparams = pt->numparams;\n\t  ar->isvararg = !!(pt->flags & PROTO_VARARG);\n\t} else {\n\t  ar->nparams = 0;\n\t  ar->isvararg = 1;\n\t}\n      }\n    } else if (*what == 'n') {\n      ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL;\n      if (ar->namewhat == NULL) {\n\tar->namewhat = \"\";\n\tar->name = NULL;\n      }\n    } else if (*what == 'f') {\n      opt_f = 1;\n    } else if (*what == 'L') {\n      opt_L = 1;\n    } else {\n      return 0;  /* Bad option. */\n    }\n  }\n  if (opt_f) {\n    setfuncV(L, L->top, fn);\n    incr_top(L);\n  }\n  if (opt_L) {\n    if (isluafunc(fn)) {\n      GCtab *t = lj_tab_new(L, 0, 0);\n      GCproto *pt = funcproto(fn);\n      const void *lineinfo = proto_lineinfo(pt);\n      if (lineinfo) {\n\tBCLine first = pt->firstline;\n\tint sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;\n\tMSize i, szl = pt->sizebc-1;\n\tfor (i = 0; i < szl; i++) {\n\t  BCLine line = first +\n\t    (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :\n\t     sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :\n\t     (BCLine)((const uint32_t *)lineinfo)[i]);\n\t  setboolV(lj_tab_setint(L, t, line), 1);\n\t}\n      }\n      settabV(L, L->top, t);\n    } else {\n      setnilV(L->top);\n    }\n    incr_top(L);\n  }\n  return 1;  /* Ok. */\n}\n\nLUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)\n{\n  return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0);\n}\n\nLUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)\n{\n  int size;\n  cTValue *frame = lj_debug_frame(L, level, &size);\n  if (frame) {\n    ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack));\n    return 1;\n  } else {\n    ar->i_ci = level - size;\n    return 0;\n  }\n}\n\n#if LJ_HASPROFILE\n/* Put the chunkname into a buffer. */\nstatic int debug_putchunkname(SBuf *sb, GCproto *pt, int pathstrip)\n{\n  GCstr *name = proto_chunkname(pt);\n  const char *p = strdata(name);\n  if (pt->firstline == ~(BCLine)0) {\n    lj_buf_putmem(sb, \"[builtin:\", 9);\n    lj_buf_putstr(sb, name);\n    lj_buf_putb(sb, ']');\n    return 0;\n  }\n  if (*p == '=' || *p == '@') {\n    MSize len = name->len-1;\n    p++;\n    if (pathstrip) {\n      int i;\n      for (i = len-1; i >= 0; i--)\n\tif (p[i] == '/' || p[i] == '\\\\') {\n\t  len -= i+1;\n\t  p = p+i+1;\n\t  break;\n\t}\n    }\n    lj_buf_putmem(sb, p, len);\n  } else {\n    lj_buf_putmem(sb, \"[string]\", 8);\n  }\n  return 1;\n}\n\n/* Put a compact stack dump into a buffer. */\nvoid lj_debug_dumpstack(lua_State *L, SBuf *sb, const char *fmt, int depth)\n{\n  int level = 0, dir = 1, pathstrip = 1;\n  MSize lastlen = 0;\n  if (depth < 0) { level = ~depth; depth = dir = -1; }  /* Reverse frames. */\n  while (level != depth) {  /* Loop through all frame. */\n    int size;\n    cTValue *frame = lj_debug_frame(L, level, &size);\n    if (frame) {\n      cTValue *nextframe = size ? frame+size : NULL;\n      GCfunc *fn = frame_func(frame);\n      const uint8_t *p = (const uint8_t *)fmt;\n      int c;\n      while ((c = *p++)) {\n\tswitch (c) {\n\tcase 'p':  /* Preserve full path. */\n\t  pathstrip = 0;\n\t  break;\n\tcase 'F': case 'f': {  /* Dump function name. */\n\t  const char *name;\n\t  const char *what = lj_debug_funcname(L, frame, &name);\n\t  if (what) {\n\t    if (c == 'F' && isluafunc(fn)) {  /* Dump module:name for 'F'. */\n\t      GCproto *pt = funcproto(fn);\n\t      if (pt->firstline != ~(BCLine)0) {  /* Not a bytecode builtin. */\n\t\tdebug_putchunkname(sb, pt, pathstrip);\n\t\tlj_buf_putb(sb, ':');\n\t      }\n\t    }\n\t    lj_buf_putmem(sb, name, (MSize)strlen(name));\n\t    break;\n\t  }  /* else: can't derive a name, dump module:line. */\n\t  }\n\t  /* fallthrough */\n\tcase 'l':  /* Dump module:line. */\n\t  if (isluafunc(fn)) {\n\t    GCproto *pt = funcproto(fn);\n\t    if (debug_putchunkname(sb, pt, pathstrip)) {\n\t      /* Regular Lua function. */\n\t      BCLine line = c == 'l' ? debug_frameline(L, fn, nextframe) :\n\t\t\t\t       pt->firstline;\n\t      lj_buf_putb(sb, ':');\n\t      lj_strfmt_putint(sb, line >= 0 ? line : pt->firstline);\n\t    }\n\t  } else if (isffunc(fn)) {  /* Dump numbered builtins. */\n\t    lj_buf_putmem(sb, \"[builtin#\", 9);\n\t    lj_strfmt_putint(sb, fn->c.ffid);\n\t    lj_buf_putb(sb, ']');\n\t  } else {  /* Dump C function address. */\n\t    lj_buf_putb(sb, '@');\n\t    lj_strfmt_putptr(sb, fn->c.f);\n\t  }\n\t  break;\n\tcase 'Z':  /* Zap trailing separator. */\n\t  lastlen = sbuflen(sb);\n\t  break;\n\tdefault:\n\t  lj_buf_putb(sb, c);\n\t  break;\n\t}\n      }\n    } else if (dir == 1) {\n      break;\n    } else {\n      level -= size;  /* Reverse frame order: quickly skip missing level. */\n    }\n    level += dir;\n  }\n  if (lastlen)\n    sb->w = sb->b + lastlen;  /* Zap trailing separator. */\n}\n#endif\n\n/* Number of frames for the leading and trailing part of a traceback. */\n#define TRACEBACK_LEVELS1\t12\n#define TRACEBACK_LEVELS2\t10\n\nLUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,\n\t\t\t\tint level)\n{\n  int top = (int)(L->top - L->base);\n  int lim = TRACEBACK_LEVELS1;\n  lua_Debug ar;\n  if (msg) lua_pushfstring(L, \"%s\\n\", msg);\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    GCfunc *fn;\n    if (level > lim) {\n      if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) {\n\tlevel--;\n      } else {\n\tlua_pushliteral(L, \"\\n\\t...\");\n\tlua_getstack(L1, -10, &ar);\n\tlevel = ar.i_ci - TRACEBACK_LEVELS2;\n      }\n      lim = 2147483647;\n      continue;\n    }\n    lua_getinfo(L1, \"Snlf\", &ar);\n    fn = funcV(L1->top-1); L1->top--;\n    if (isffunc(fn) && !*ar.namewhat)\n      lua_pushfstring(L, \"\\n\\t[builtin#%d]:\", fn->c.ffid);\n    else\n      lua_pushfstring(L, \"\\n\\t%s:\", ar.short_src);\n    if (ar.currentline > 0)\n      lua_pushfstring(L, \"%d:\", ar.currentline);\n    if (*ar.namewhat) {\n      lua_pushfstring(L, \" in function \" LUA_QS, ar.name);\n    } else {\n      if (*ar.what == 'm') {\n\tlua_pushliteral(L, \" in main chunk\");\n      } else if (*ar.what == 'C') {\n\tlua_pushfstring(L, \" at %p\", fn->c.f);\n      } else {\n\tlua_pushfstring(L, \" in function <%s:%d>\",\n\t\t\tar.short_src, ar.linedefined);\n      }\n    }\n    if ((int)(L->top - L->base) - top >= 15)\n      lua_concat(L, (int)(L->top - L->base) - top);\n  }\n  lua_concat(L, (int)(L->top - L->base) - top);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_debug.h",
    "content": "/*\n** Debugging and introspection.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DEBUG_H\n#define _LJ_DEBUG_H\n\n#include \"lj_obj.h\"\n\ntypedef struct lj_Debug {\n  /* Common fields. Must be in the same order as in lua.h. */\n  int event;\n  const char *name;\n  const char *namewhat;\n  const char *what;\n  const char *source;\n  int currentline;\n  int nups;\n  int linedefined;\n  int lastlinedefined;\n  char short_src[LUA_IDSIZE];\n  int i_ci;\n  /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/\n  int nparams;\n  int isvararg;\n} lj_Debug;\n\nLJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);\nLJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);\nLJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);\nLJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp,\n\t\t\t\t     GCobj **op);\nLJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,\n\t\t\t\t      BCReg slot, const char **name);\nLJ_FUNC const char *lj_debug_funcname(lua_State *L, cTValue *frame,\n\t\t\t\t      const char **name);\nLJ_FUNC void lj_debug_shortname(char *out, GCstr *str, BCLine line);\nLJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,\n\t\t\t     cTValue *frame, cTValue *nextframe);\nLJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);\nLJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,\n\t\t\t     int ext);\n#if LJ_HASPROFILE\nLJ_FUNC void lj_debug_dumpstack(lua_State *L, SBuf *sb, const char *fmt,\n\t\t\t\tint depth);\n#endif\n\n/* Fixed internal variable names. */\n#define VARNAMEDEF(_) \\\n  _(FOR_IDX, \"(for index)\") \\\n  _(FOR_STOP, \"(for limit)\") \\\n  _(FOR_STEP, \"(for step)\") \\\n  _(FOR_GEN, \"(for generator)\") \\\n  _(FOR_STATE, \"(for state)\") \\\n  _(FOR_CTL, \"(for control)\")\n\nenum {\n  VARNAME_END,\n#define VARNAMEENUM(name, str)\tVARNAME_##name,\n  VARNAMEDEF(VARNAMEENUM)\n#undef VARNAMEENUM\n  VARNAME__MAX\n};\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_def.h",
    "content": "/*\n** LuaJIT common internal definitions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DEF_H\n#define _LJ_DEF_H\n\n#include \"lua.h\"\n\n#if defined(_MSC_VER) && (_MSC_VER < 1700)\n/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */\ntypedef __int8 int8_t;\ntypedef __int16 int16_t;\ntypedef __int32 int32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int8 uint8_t;\ntypedef unsigned __int16 uint16_t;\ntypedef unsigned __int32 uint32_t;\ntypedef unsigned __int64 uint64_t;\n#ifdef _WIN64\ntypedef __int64 intptr_t;\ntypedef unsigned __int64 uintptr_t;\n#else\ntypedef __int32 intptr_t;\ntypedef unsigned __int32 uintptr_t;\n#endif\n#elif defined(__symbian__)\n/* Cough. */\ntypedef signed char int8_t;\ntypedef short int int16_t;\ntypedef int int32_t;\ntypedef long long int64_t;\ntypedef unsigned char uint8_t;\ntypedef unsigned short int uint16_t;\ntypedef unsigned int uint32_t;\ntypedef unsigned long long uint64_t;\ntypedef int intptr_t;\ntypedef unsigned int uintptr_t;\n#else\n#include <stdint.h>\n#endif\n\n/* Needed everywhere. */\n#include <string.h>\n#include <stdlib.h>\n\n/* Various VM limits. */\n#define LJ_MAX_MEM32\t0x7fffff00\t/* Max. 32 bit memory allocation. */\n#define LJ_MAX_MEM64\t((uint64_t)1<<47)  /* Max. 64 bit memory allocation. */\n/* Max. total memory allocation. */\n#define LJ_MAX_MEM\t(LJ_GC64 ? LJ_MAX_MEM64 : LJ_MAX_MEM32)\n#define LJ_MAX_ALLOC\tLJ_MAX_MEM\t/* Max. individual allocation length. */\n#define LJ_MAX_STR\tLJ_MAX_MEM32\t/* Max. string length. */\n#define LJ_MAX_BUF\tLJ_MAX_MEM32\t/* Max. buffer length. */\n#define LJ_MAX_UDATA\tLJ_MAX_MEM32\t/* Max. userdata length. */\n\n#define LJ_MAX_STRTAB\t(1<<26)\t\t/* Max. string table size. */\n#define LJ_MAX_HBITS\t26\t\t/* Max. hash bits. */\n#define LJ_MAX_ABITS\t28\t\t/* Max. bits of array key. */\n#define LJ_MAX_ASIZE\t((1<<(LJ_MAX_ABITS-1))+1)  /* Max. array part size. */\n#define LJ_MAX_COLOSIZE\t16\t\t/* Max. elems for colocated array. */\n\n#define LJ_MAX_LINE\tLJ_MAX_MEM32\t/* Max. source code line number. */\n#define LJ_MAX_XLEVEL\t200\t\t/* Max. syntactic nesting level. */\n#define LJ_MAX_BCINS\t(1<<26)\t\t/* Max. # of bytecode instructions. */\n#define LJ_MAX_SLOTS\t250\t\t/* Max. # of slots in a Lua func. */\n#define LJ_MAX_LOCVAR\t200\t\t/* Max. # of local variables. */\n#define LJ_MAX_UPVAL\t60\t\t/* Max. # of upvalues. */\n\n#define LJ_MAX_IDXCHAIN\t100\t\t/* __index/__newindex chain limit. */\n#define LJ_STACK_EXTRA\t(5+2*LJ_FR2)\t/* Extra stack space (metamethods). */\n\n#define LJ_NUM_CBPAGE\t1\t\t/* Number of FFI callback pages. */\n\n/* Minimum table/buffer sizes. */\n#define LJ_MIN_GLOBAL\t6\t\t/* Min. global table size (hbits). */\n#define LJ_MIN_REGISTRY\t2\t\t/* Min. registry size (hbits). */\n#define LJ_MIN_STRTAB\t256\t\t/* Min. string table size (pow2). */\n#define LJ_MIN_SBUF\t32\t\t/* Min. string buffer length. */\n#define LJ_MIN_VECSZ\t8\t\t/* Min. size for growable vectors. */\n#define LJ_MIN_IRSZ\t32\t\t/* Min. size for growable IR. */\n\n/* JIT compiler limits. */\n#define LJ_MAX_JSLOTS\t250\t\t/* Max. # of stack slots for a trace. */\n#define LJ_MAX_PHI\t64\t\t/* Max. # of PHIs for a loop. */\n#define LJ_MAX_EXITSTUBGR\t16\t/* Max. # of exit stub groups. */\n\n/* Various macros. */\n#ifndef UNUSED\n#define UNUSED(x)\t((void)(x))\t/* to avoid warnings */\n#endif\n\n#define U64x(hi, lo)\t(((uint64_t)0x##hi << 32) + (uint64_t)0x##lo)\n#define i32ptr(p)\t((int32_t)(intptr_t)(void *)(p))\n#define u32ptr(p)\t((uint32_t)(intptr_t)(void *)(p))\n#define i64ptr(p)\t((int64_t)(intptr_t)(void *)(p))\n#define u64ptr(p)\t((uint64_t)(intptr_t)(void *)(p))\n#define igcptr(p)\t(LJ_GC64 ? i64ptr(p) : i32ptr(p))\n\n#define checki8(x)\t((x) == (int32_t)(int8_t)(x))\n#define checku8(x)\t((x) == (int32_t)(uint8_t)(x))\n#define checki16(x)\t((x) == (int32_t)(int16_t)(x))\n#define checku16(x)\t((x) == (int32_t)(uint16_t)(x))\n#define checki32(x)\t((x) == (int32_t)(x))\n#define checku32(x)\t((x) == (uint32_t)(x))\n#define checkptr31(x)\t(((uint64_t)(uintptr_t)(x) >> 31) == 0)\n#define checkptr32(x)\t((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))\n#define checkptr47(x)\t(((uint64_t)(uintptr_t)(x) >> 47) == 0)\n#define checkptrGC(x)\t(LJ_GC64 ? checkptr47((x)) : LJ_64 ? checkptr31((x)) :1)\n\n/* Every half-decent C compiler transforms this into a rotate instruction. */\n#define lj_rol(x, n)\t(((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))\n#define lj_ror(x, n)\t(((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))\n\n/* A really naive Bloom filter. But sufficient for our needs. */\ntypedef uintptr_t BloomFilter;\n#define BLOOM_MASK\t(8*sizeof(BloomFilter) - 1)\n#define bloombit(x)\t((uintptr_t)1 << ((x) & BLOOM_MASK))\n#define bloomset(b, x)\t((b) |= bloombit((x)))\n#define bloomtest(b, x)\t((b) & bloombit((x)))\n\n#if defined(__GNUC__) || defined(__clang__) || defined(__psp2__)\n\n#define LJ_NORET\t__attribute__((noreturn))\n#define LJ_ALIGN(n)\t__attribute__((aligned(n)))\n#define LJ_INLINE\tinline\n#define LJ_AINLINE\tinline __attribute__((always_inline))\n#define LJ_NOINLINE\t__attribute__((noinline))\n\n#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)\n#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))\n#define LJ_NOAPI\textern __attribute__((visibility(\"hidden\")))\n#endif\n#endif\n\n/* Note: it's only beneficial to use fastcall on x86 and then only for up to\n** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only\n** indirect calls and related tail-called C functions are marked as fastcall.\n*/\n#if defined(__i386__)\n#define LJ_FASTCALL\t__attribute__((fastcall))\n#endif\n\n#define LJ_LIKELY(x)\t__builtin_expect(!!(x), 1)\n#define LJ_UNLIKELY(x)\t__builtin_expect(!!(x), 0)\n\n#define lj_ffs(x)\t((uint32_t)__builtin_ctz(x))\n/* Don't ask ... */\n#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__))\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  uint32_t r; __asm__(\"bsrl %1, %0\" : \"=r\" (r) : \"rm\" (x) : \"cc\"); return r;\n}\n#else\n#define lj_fls(x)\t((uint32_t)(__builtin_clz(x)^31))\n#endif\n\n#if defined(__arm__)\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n#if defined(__psp2__)\n  return __builtin_rev(x);\n#else\n  uint32_t r;\n#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\\\n    __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__\n  __asm__(\"rev %0, %1\" : \"=r\" (r) : \"r\" (x));\n  return r;\n#else\n#ifdef __thumb__\n  r = x ^ lj_ror(x, 16);\n#else\n  __asm__(\"eor %0, %1, %1, ror #16\" : \"=r\" (r) : \"r\" (x));\n#endif\n  return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);\n#endif\n#endif\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));\n}\n#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __clang__\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  return (uint32_t)__builtin_bswap32((int32_t)x);\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return (uint64_t)__builtin_bswap64((int64_t)x);\n}\n#elif defined(__i386__) || defined(__x86_64__)\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  uint32_t r; __asm__(\"bswap %0\" : \"=r\" (r) : \"0\" (x)); return r;\n}\n\n#if defined(__i386__)\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));\n}\n#else\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  uint64_t r; __asm__(\"bswap %0\" : \"=r\" (r) : \"0\" (x)); return r;\n}\n#endif\n#else\nstatic LJ_AINLINE uint32_t lj_bswap(uint32_t x)\n{\n  return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24);\n}\n\nstatic LJ_AINLINE uint64_t lj_bswap64(uint64_t x)\n{\n  return (uint64_t)lj_bswap((uint32_t)(x >> 32)) |\n\t ((uint64_t)lj_bswap((uint32_t)x) << 32);\n}\n#endif\n\ntypedef union __attribute__((packed)) Unaligned16 {\n  uint16_t u;\n  uint8_t b[2];\n} Unaligned16;\n\ntypedef union __attribute__((packed)) Unaligned32 {\n  uint32_t u;\n  uint8_t b[4];\n} Unaligned32;\n\n/* Unaligned load of uint16_t. */\nstatic LJ_AINLINE uint16_t lj_getu16(const void *p)\n{\n  return ((const Unaligned16 *)p)->u;\n}\n\n/* Unaligned load of uint32_t. */\nstatic LJ_AINLINE uint32_t lj_getu32(const void *p)\n{\n  return ((const Unaligned32 *)p)->u;\n}\n\n#elif defined(_MSC_VER)\n\n#define LJ_NORET\t__declspec(noreturn)\n#define LJ_ALIGN(n)\t__declspec(align(n))\n#define LJ_INLINE\t__inline\n#define LJ_AINLINE\t__forceinline\n#define LJ_NOINLINE\t__declspec(noinline)\n#if defined(_M_IX86)\n#define LJ_FASTCALL\t__fastcall\n#endif\n\n#ifdef _M_PPC\nunsigned int _CountLeadingZeros(long);\n#pragma intrinsic(_CountLeadingZeros)\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  return _CountLeadingZeros(x) ^ 31;\n}\n#else\nunsigned char _BitScanForward(unsigned long *, unsigned long);\nunsigned char _BitScanReverse(unsigned long *, unsigned long);\n#pragma intrinsic(_BitScanForward)\n#pragma intrinsic(_BitScanReverse)\n\nstatic LJ_AINLINE uint32_t lj_ffs(uint32_t x)\n{\n  unsigned long r; _BitScanForward(&r, x); return (uint32_t)r;\n}\n\nstatic LJ_AINLINE uint32_t lj_fls(uint32_t x)\n{\n  unsigned long r; _BitScanReverse(&r, x); return (uint32_t)r;\n}\n#endif\n\nunsigned long _byteswap_ulong(unsigned long);\nuint64_t _byteswap_uint64(uint64_t);\n#define lj_bswap(x)\t(_byteswap_ulong((x)))\n#define lj_bswap64(x)\t(_byteswap_uint64((x)))\n\n#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)\n/*\n** Replacement for unaligned loads on Xbox 360. Disabled by default since it's\n** usually more costly than the occasional stall when crossing a cache-line.\n*/\nstatic LJ_AINLINE uint16_t lj_getu16(const void *v)\n{\n  const uint8_t *p = (const uint8_t *)v;\n  return (uint16_t)((p[0]<<8) | p[1]);\n}\nstatic LJ_AINLINE uint32_t lj_getu32(const void *v)\n{\n  const uint8_t *p = (const uint8_t *)v;\n  return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);\n}\n#else\n/* Unaligned loads are generally ok on x86/x64. */\n#define lj_getu16(p)\t(*(uint16_t *)(p))\n#define lj_getu32(p)\t(*(uint32_t *)(p))\n#endif\n\n#else\n#error \"missing defines for your compiler\"\n#endif\n\n/* Optional defines. */\n#ifndef LJ_FASTCALL\n#define LJ_FASTCALL\n#endif\n#ifndef LJ_NORET\n#define LJ_NORET\n#endif\n#ifndef LJ_NOAPI\n#define LJ_NOAPI\textern\n#endif\n#ifndef LJ_LIKELY\n#define LJ_LIKELY(x)\t(x)\n#define LJ_UNLIKELY(x)\t(x)\n#endif\n\n/* Attributes for internal functions. */\n#define LJ_DATA\t\tLJ_NOAPI\n#define LJ_DATADEF\n#define LJ_ASMF\t\tLJ_NOAPI\n#define LJ_FUNCA\tLJ_NOAPI\n#if defined(ljamalg_c)\n#define LJ_FUNC\t\tstatic\n#else\n#define LJ_FUNC\t\tLJ_NOAPI\n#endif\n#define LJ_FUNC_NORET\tLJ_FUNC LJ_NORET\n#define LJ_FUNCA_NORET\tLJ_FUNCA LJ_NORET\n#define LJ_ASMF_NORET\tLJ_ASMF LJ_NORET\n\n/* Internal assertions. */\n#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)\n#define lj_assert_check(g, c, ...) \\\n  ((c) ? (void)0 : \\\n   (lj_assert_fail((g), __FILE__, __LINE__, __func__, __VA_ARGS__), 0))\n#define lj_checkapi(c, ...)\tlj_assert_check(G(L), (c), __VA_ARGS__)\n#else\n#define lj_checkapi(c, ...)\t((void)L)\n#endif\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertG_(g, c, ...)\tlj_assert_check((g), (c), __VA_ARGS__)\n#define lj_assertG(c, ...)\tlj_assert_check(g, (c), __VA_ARGS__)\n#define lj_assertL(c, ...)\tlj_assert_check(G(L), (c), __VA_ARGS__)\n#define lj_assertX(c, ...)\tlj_assert_check(NULL, (c), __VA_ARGS__)\n#define check_exp(c, e)\t\t(lj_assertX((c), #c), (e))\n#else\n#define lj_assertG_(g, c, ...)\t((void)0)\n#define lj_assertG(c, ...)\t((void)g)\n#define lj_assertL(c, ...)\t((void)L)\n#define lj_assertX(c, ...)\t((void)0)\n#define check_exp(c, e)\t\t(e)\n#endif\n\n/* Static assertions. */\n#define LJ_ASSERT_NAME2(name, line)\tname ## line\n#define LJ_ASSERT_NAME(line)\t\tLJ_ASSERT_NAME2(lj_assert_, line)\n#ifdef __COUNTER__\n#define LJ_STATIC_ASSERT(cond) \\\n  extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])\n#else\n#define LJ_STATIC_ASSERT(cond) \\\n  extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])\n#endif\n\n/* PRNG state. Need this here, details in lj_prng.h. */\ntypedef struct PRNGState {\n  uint64_t u[4];\n} PRNGState;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_dispatch.c",
    "content": "/*\n** Instruction dispatch handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_dispatch_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_func.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_debug.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n#if LJ_HASFFI\n#include \"lj_ccallback.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASPROFILE\n#include \"lj_profile.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"luajit.h\"\n\n/* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */\nLJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC);\n\n/* -- Dispatch table management ------------------------------------------- */\n\n#if LJ_TARGET_MIPS\n#include <math.h>\nLJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,\n\t\t\t\t\t\t\t  lua_State *co);\n#if !LJ_HASJIT\n#define lj_dispatch_stitch\tlj_dispatch_ins\n#endif\n#if !LJ_HASPROFILE\n#define lj_dispatch_profile\tlj_dispatch_ins\n#endif\n\n#define GOTFUNC(name)\t(ASMFunction)name,\nstatic const ASMFunction dispatch_got[] = {\n  GOTDEF(GOTFUNC)\n};\n#undef GOTFUNC\n#endif\n\n/* Initialize instruction dispatch table and hot counters. */\nvoid lj_dispatch_init(GG_State *GG)\n{\n  uint32_t i;\n  ASMFunction *disp = GG->dispatch;\n  for (i = 0; i < GG_LEN_SDISP; i++)\n    disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]);\n  for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n    disp[i] = makeasmfunc(lj_bc_ofs[i]);\n  /* The JIT engine is off by default. luaopen_jit() turns it on. */\n  disp[BC_FORL] = disp[BC_IFORL];\n  disp[BC_ITERL] = disp[BC_IITERL];\n  /* Workaround for stable v2.1 bytecode. TODO: Replace with BC_IITERN. */\n  disp[BC_ITERN] = &lj_vm_IITERN;\n  disp[BC_LOOP] = disp[BC_ILOOP];\n  disp[BC_FUNCF] = disp[BC_IFUNCF];\n  disp[BC_FUNCV] = disp[BC_IFUNCV];\n  GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0);\n  for (i = 0; i < GG_NUM_ASMFF; i++)\n    GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0);\n#if LJ_TARGET_MIPS\n  memcpy(GG->got, dispatch_got, LJ_GOT__MAX*sizeof(ASMFunction *));\n#endif\n}\n\n#if LJ_HASJIT\n/* Initialize hotcount table. */\nvoid lj_dispatch_init_hotcount(global_State *g)\n{\n  int32_t hotloop = G2J(g)->param[JIT_P_hotloop];\n  HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1);\n  HotCount *hotcount = G2GG(g)->hotcount;\n  uint32_t i;\n  for (i = 0; i < HOTCOUNT_SIZE; i++)\n    hotcount[i] = start;\n}\n#endif\n\n/* Internal dispatch mode bits. */\n#define DISPMODE_CALL\t0x01\t/* Override call dispatch. */\n#define DISPMODE_RET\t0x02\t/* Override return dispatch. */\n#define DISPMODE_INS\t0x04\t/* Override instruction dispatch. */\n#define DISPMODE_JIT\t0x10\t/* JIT compiler on. */\n#define DISPMODE_REC\t0x20\t/* Recording active. */\n#define DISPMODE_PROF\t0x40\t/* Profiling active. */\n\n/* Update dispatch table depending on various flags. */\nvoid lj_dispatch_update(global_State *g)\n{\n  uint8_t oldmode = g->dispatchmode;\n  uint8_t mode = 0;\n#if LJ_HASJIT\n  mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0;\n  mode |= G2J(g)->state != LJ_TRACE_IDLE ?\n\t    (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0;\n#endif\n#if LJ_HASPROFILE\n  mode |= (g->hookmask & HOOK_PROFILE) ? (DISPMODE_PROF|DISPMODE_INS) : 0;\n#endif\n  mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0;\n  mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0;\n  mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0;\n  if (oldmode != mode) {  /* Mode changed? */\n    ASMFunction *disp = G2GG(g)->dispatch;\n    ASMFunction f_forl, f_iterl, f_itern, f_loop, f_funcf, f_funcv;\n    g->dispatchmode = mode;\n\n    /* Hotcount if JIT is on, but not while recording. */\n    if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) {\n      f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]);\n      f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]);\n      f_itern = makeasmfunc(lj_bc_ofs[BC_ITERN]);\n      f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]);\n      f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]);\n      f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]);\n    } else {  /* Otherwise use the non-hotcounting instructions. */\n      f_forl = disp[GG_LEN_DDISP+BC_IFORL];\n      f_iterl = disp[GG_LEN_DDISP+BC_IITERL];\n      f_itern = &lj_vm_IITERN;\n      f_loop = disp[GG_LEN_DDISP+BC_ILOOP];\n      f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]);\n      f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]);\n    }\n    /* Init static counting instruction dispatch first (may be copied below). */\n    disp[GG_LEN_DDISP+BC_FORL] = f_forl;\n    disp[GG_LEN_DDISP+BC_ITERL] = f_iterl;\n    disp[GG_LEN_DDISP+BC_ITERN] = f_itern;\n    disp[GG_LEN_DDISP+BC_LOOP] = f_loop;\n\n    /* Set dynamic instruction dispatch. */\n    if ((oldmode ^ mode) & (DISPMODE_PROF|DISPMODE_REC|DISPMODE_INS)) {\n      /* Need to update the whole table. */\n      if (!(mode & DISPMODE_INS)) {  /* No ins dispatch? */\n\t/* Copy static dispatch table to dynamic dispatch table. */\n\tmemcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction));\n\t/* Overwrite with dynamic return dispatch. */\n\tif ((mode & DISPMODE_RET)) {\n\t  disp[BC_RETM] = lj_vm_rethook;\n\t  disp[BC_RET] = lj_vm_rethook;\n\t  disp[BC_RET0] = lj_vm_rethook;\n\t  disp[BC_RET1] = lj_vm_rethook;\n\t}\n      } else {\n\t/* The recording dispatch also checks for hooks. */\n\tASMFunction f = (mode & DISPMODE_PROF) ? lj_vm_profhook :\n\t\t\t(mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;\n\tuint32_t i;\n\tfor (i = 0; i < GG_LEN_SDISP; i++)\n\t  disp[i] = f;\n      }\n    } else if (!(mode & DISPMODE_INS)) {\n      /* Otherwise set dynamic counting ins. */\n      disp[BC_FORL] = f_forl;\n      disp[BC_ITERL] = f_iterl;\n      disp[BC_ITERN] = f_itern;\n      disp[BC_LOOP] = f_loop;\n      /* Set dynamic return dispatch. */\n      if ((mode & DISPMODE_RET)) {\n\tdisp[BC_RETM] = lj_vm_rethook;\n\tdisp[BC_RET] = lj_vm_rethook;\n\tdisp[BC_RET0] = lj_vm_rethook;\n\tdisp[BC_RET1] = lj_vm_rethook;\n      } else {\n\tdisp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM];\n\tdisp[BC_RET] = disp[GG_LEN_DDISP+BC_RET];\n\tdisp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0];\n\tdisp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1];\n      }\n    }\n\n    /* Set dynamic call dispatch. */\n    if ((oldmode ^ mode) & DISPMODE_CALL) {  /* Update the whole table? */\n      uint32_t i;\n      if ((mode & DISPMODE_CALL) == 0) {  /* No call hooks? */\n\tfor (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n\t  disp[i] = makeasmfunc(lj_bc_ofs[i]);\n      } else {\n\tfor (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)\n\t  disp[i] = lj_vm_callhook;\n      }\n    }\n    if (!(mode & DISPMODE_CALL)) {  /* Overwrite dynamic counting ins. */\n      disp[BC_FUNCF] = f_funcf;\n      disp[BC_FUNCV] = f_funcv;\n    }\n\n#if LJ_HASJIT\n    /* Reset hotcounts for JIT off to on transition. */\n    if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT))\n      lj_dispatch_init_hotcount(g);\n#endif\n  }\n}\n\n/* -- JIT mode setting ---------------------------------------------------- */\n\n#if LJ_HASJIT\n/* Set JIT mode for a single prototype. */\nstatic void setptmode(global_State *g, GCproto *pt, int mode)\n{\n  if ((mode & LUAJIT_MODE_ON)) {  /* (Re-)enable JIT compilation. */\n    pt->flags &= ~PROTO_NOJIT;\n    lj_trace_reenableproto(pt);  /* Unpatch all ILOOP etc. bytecodes. */\n  } else {  /* Flush and/or disable JIT compilation. */\n    if (!(mode & LUAJIT_MODE_FLUSH))\n      pt->flags |= PROTO_NOJIT;\n    lj_trace_flushproto(g, pt);  /* Flush all traces of prototype. */\n  }\n}\n\n/* Recursively set the JIT mode for all children of a prototype. */\nstatic void setptmode_all(global_State *g, GCproto *pt, int mode)\n{\n  ptrdiff_t i;\n  if (!(pt->flags & PROTO_CHILD)) return;\n  for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) {\n    GCobj *o = proto_kgc(pt, i);\n    if (o->gch.gct == ~LJ_TPROTO) {\n      setptmode(g, gco2pt(o), mode);\n      setptmode_all(g, gco2pt(o), mode);\n    }\n  }\n}\n#endif\n\n/* Public API function: control the JIT engine. */\nint luaJIT_setmode(lua_State *L, int idx, int mode)\n{\n  global_State *g = G(L);\n  int mm = mode & LUAJIT_MODE_MASK;\n  lj_trace_abort(g);  /* Abort recording on any state change. */\n  /* Avoid pulling the rug from under our own feet. */\n  if ((g->hookmask & HOOK_GC))\n    lj_err_caller(L, LJ_ERR_NOGCMM);\n  switch (mm) {\n#if LJ_HASJIT\n  case LUAJIT_MODE_ENGINE:\n    if ((mode & LUAJIT_MODE_FLUSH)) {\n      lj_trace_flushall(L);\n    } else {\n      if (!(mode & LUAJIT_MODE_ON))\n\tG2J(g)->flags &= ~(uint32_t)JIT_F_ON;\n      else\n\tG2J(g)->flags |= (uint32_t)JIT_F_ON;\n      lj_dispatch_update(g);\n    }\n    break;\n  case LUAJIT_MODE_FUNC:\n  case LUAJIT_MODE_ALLFUNC:\n  case LUAJIT_MODE_ALLSUBFUNC: {\n    cTValue *tv = idx == 0 ? frame_prev(L->base-1)-LJ_FR2 :\n\t\t  idx > 0 ? L->base + (idx-1) : L->top + idx;\n    GCproto *pt;\n    if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn))\n      pt = funcproto(&gcval(tv)->fn);  /* Cannot use funcV() for frame slot. */\n    else if (tvisproto(tv))\n      pt = protoV(tv);\n    else\n      return 0;  /* Failed. */\n    if (mm != LUAJIT_MODE_ALLSUBFUNC)\n      setptmode(g, pt, mode);\n    if (mm != LUAJIT_MODE_FUNC)\n      setptmode_all(g, pt, mode);\n    break;\n    }\n  case LUAJIT_MODE_TRACE:\n    if (!(mode & LUAJIT_MODE_FLUSH))\n      return 0;  /* Failed. */\n    lj_trace_flush(G2J(g), idx);\n    break;\n#else\n  case LUAJIT_MODE_ENGINE:\n  case LUAJIT_MODE_FUNC:\n  case LUAJIT_MODE_ALLFUNC:\n  case LUAJIT_MODE_ALLSUBFUNC:\n    UNUSED(idx);\n    if ((mode & LUAJIT_MODE_ON))\n      return 0;  /* Failed. */\n    break;\n#endif\n  case LUAJIT_MODE_WRAPCFUNC:\n    if ((mode & LUAJIT_MODE_ON)) {\n      if (idx != 0) {\n\tcTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx;\n\tif (tvislightud(tv))\n\t  g->wrapf = (lua_CFunction)lightudV(g, tv);\n\telse\n\t  return 0;  /* Failed. */\n      } else {\n\treturn 0;  /* Failed. */\n      }\n      g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0);\n    } else {\n      g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0);\n    }\n    break;\n  default:\n    return 0;  /* Failed. */\n  }\n  return 1;  /* OK. */\n}\n\n/* Enforce (dynamic) linker error for version mismatches. See luajit.c. */\nLUA_API void LUAJIT_VERSION_SYM(void)\n{\n}\n\n/* -- Hooks --------------------------------------------------------------- */\n\n/* This function can be called asynchronously (e.g. during a signal). */\nLUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)\n{\n  global_State *g = G(L);\n  mask &= HOOK_EVENTMASK;\n  if (func == NULL || mask == 0) { mask = 0; func = NULL; }  /* Consistency. */\n  g->hookf = func;\n  g->hookcount = g->hookcstart = (int32_t)count;\n  g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask);\n  lj_trace_abort(g);  /* Abort recording on any hook change. */\n  lj_dispatch_update(g);\n  return 1;\n}\n\nLUA_API lua_Hook lua_gethook(lua_State *L)\n{\n  return G(L)->hookf;\n}\n\nLUA_API int lua_gethookmask(lua_State *L)\n{\n  return G(L)->hookmask & HOOK_EVENTMASK;\n}\n\nLUA_API int lua_gethookcount(lua_State *L)\n{\n  return (int)G(L)->hookcstart;\n}\n\n/* Call a hook. */\nstatic void callhook(lua_State *L, int event, BCLine line)\n{\n  global_State *g = G(L);\n  lua_Hook hookf = g->hookf;\n  if (hookf && !hook_active(g)) {\n    lua_Debug ar;\n    lj_trace_abort(g);  /* Abort recording on any hook call. */\n    ar.event = event;\n    ar.currentline = line;\n    /* Top frame, nextframe = NULL. */\n    ar.i_ci = (int)((L->base-1) - tvref(L->stack));\n    lj_state_checkstack(L, 1+LUA_MINSTACK);\n#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF\n    lj_profile_hook_enter(g);\n#else\n    hook_enter(g);\n#endif\n    hookf(L, &ar);\n    lj_assertG(hook_active(g), \"active hook flag removed\");\n    setgcref(g->cur_L, obj2gco(L));\n#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF\n    lj_profile_hook_leave(g);\n#else\n    hook_leave(g);\n#endif\n  }\n}\n\n/* -- Dispatch callbacks -------------------------------------------------- */\n\n/* Calculate number of used stack slots in the current frame. */\nstatic BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres)\n{\n  BCIns ins = pc[-1];\n  if (bc_op(ins) == BC_UCLO)\n    ins = pc[bc_j(ins)];\n  switch (bc_op(ins)) {\n  case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1+LJ_FR2;\n  case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1;\n  case BC_TSETM: return bc_a(ins) + nres-1;\n  default: return pt->framesize;\n  }\n}\n\n/* Instruction dispatch. Used by instr/line/return hooks or when recording. */\nvoid LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  GCproto *pt = funcproto(fn);\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  global_State *g = G(L);\n  BCReg slots;\n  setcframe_pc(cf, pc);\n  slots = cur_topslot(pt, pc, cframe_multres_n(cf));\n  L->top = L->base + slots;  /* Fix top. */\n#if LJ_HASJIT\n  {\n    jit_State *J = G2J(g);\n    if (J->state != LJ_TRACE_IDLE) {\n#ifdef LUA_USE_ASSERT\n      ptrdiff_t delta = L->top - L->base;\n#endif\n      J->L = L;\n      lj_trace_ins(J, pc-1);  /* The interpreter bytecode PC is offset by 1. */\n      lj_assertG(L->top - L->base == delta,\n\t\t \"unbalanced stack after tracing of instruction\");\n    }\n  }\n#endif\n  if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {\n    g->hookcount = g->hookcstart;\n    callhook(L, LUA_HOOKCOUNT, -1);\n    L->top = L->base + slots;  /* Fix top again. */\n  }\n  if ((g->hookmask & LUA_MASKLINE)) {\n    BCPos npc = proto_bcpos(pt, pc) - 1;\n    BCPos opc = proto_bcpos(pt, oldpc) - 1;\n    BCLine line = lj_debug_line(pt, npc);\n    if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) {\n      callhook(L, LUA_HOOKLINE, line);\n      L->top = L->base + slots;  /* Fix top again. */\n    }\n  }\n  if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1])))\n    callhook(L, LUA_HOOKRET, -1);\n  ERRNO_RESTORE\n}\n\n/* Initialize call. Ensure stack space and return # of missing parameters. */\nstatic int call_init(lua_State *L, GCfunc *fn)\n{\n  if (isluafunc(fn)) {\n    GCproto *pt = funcproto(fn);\n    int numparams = pt->numparams;\n    int gotparams = (int)(L->top - L->base);\n    int need = pt->framesize;\n    if ((pt->flags & PROTO_VARARG)) need += 1+gotparams;\n    lj_state_checkstack(L, (MSize)need);\n    numparams -= gotparams;\n    return numparams >= 0 ? numparams : 0;\n  } else {\n    lj_state_checkstack(L, LUA_MINSTACK);\n    return 0;\n  }\n}\n\n/* Call dispatch. Used by call hooks, hot calls or when recording. */\nASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  BCOp op;\n  global_State *g = G(L);\n#if LJ_HASJIT\n  jit_State *J = G2J(g);\n#endif\n  int missing = call_init(L, fn);\n#if LJ_HASJIT\n  J->L = L;\n  if ((uintptr_t)pc & 1) {  /* Marker for hot call. */\n#ifdef LUA_USE_ASSERT\n    ptrdiff_t delta = L->top - L->base;\n#endif\n    pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1);\n    lj_trace_hot(J, pc);\n    lj_assertG(L->top - L->base == delta,\n\t       \"unbalanced stack after hot call\");\n    goto out;\n  } else if (J->state != LJ_TRACE_IDLE &&\n\t     !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n#ifdef LUA_USE_ASSERT\n    ptrdiff_t delta = L->top - L->base;\n#endif\n    /* Record the FUNC* bytecodes, too. */\n    lj_trace_ins(J, pc-1);  /* The interpreter bytecode PC is offset by 1. */\n    lj_assertG(L->top - L->base == delta,\n\t       \"unbalanced stack after hot instruction\");\n  }\n#endif\n  if ((g->hookmask & LUA_MASKCALL)) {\n    int i;\n    for (i = 0; i < missing; i++)  /* Add missing parameters. */\n      setnilV(L->top++);\n    callhook(L, LUA_HOOKCALL, -1);\n    /* Preserve modifications of missing parameters by lua_setlocal(). */\n    while (missing-- > 0 && tvisnil(L->top - 1))\n      L->top--;\n  }\n#if LJ_HASJIT\nout:\n#endif\n  op = bc_op(pc[-1]);  /* Get FUNC* op. */\n#if LJ_HASJIT\n  /* Use the non-hotcounting variants if JIT is off or while recording. */\n  if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) &&\n      (op == BC_FUNCF || op == BC_FUNCV))\n    op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF);\n#endif\n  ERRNO_RESTORE\n  return makeasmfunc(lj_bc_ofs[op]);  /* Return static dispatch target. */\n}\n\n#if LJ_HASJIT\n/* Stitch a new trace. */\nvoid LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc)\n{\n  ERRNO_SAVE\n  lua_State *L = J->L;\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  setcframe_pc(cf, pc);\n  /* Before dispatch, have to bias PC by 1. */\n  L->top = L->base + cur_topslot(curr_proto(L), pc+1, cframe_multres_n(cf));\n  lj_trace_stitch(J, pc-1);  /* Point to the CALL instruction. */\n  setcframe_pc(cf, oldpc);\n  ERRNO_RESTORE\n}\n#endif\n\n#if LJ_HASPROFILE\n/* Profile dispatch. */\nvoid LJ_FASTCALL lj_dispatch_profile(lua_State *L, const BCIns *pc)\n{\n  ERRNO_SAVE\n  GCfunc *fn = curr_func(L);\n  GCproto *pt = funcproto(fn);\n  void *cf = cframe_raw(L->cframe);\n  const BCIns *oldpc = cframe_pc(cf);\n  global_State *g;\n  setcframe_pc(cf, pc);\n  L->top = L->base + cur_topslot(pt, pc, cframe_multres_n(cf));\n  lj_profile_interpreter(L);\n  setcframe_pc(cf, oldpc);\n  g = G(L);\n  setgcref(g->cur_L, obj2gco(L));\n  setvmstate(g, INTERP);\n  ERRNO_RESTORE\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_dispatch.h",
    "content": "/*\n** Instruction dispatch handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_DISPATCH_H\n#define _LJ_DISPATCH_H\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#endif\n\n#if LJ_TARGET_MIPS\n/* Need our own global offset table for the dreaded MIPS calling conventions. */\n\n#ifndef _LJ_VM_H\nLJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b);\n#endif\n\n#if LJ_SOFTFP\n#ifndef _LJ_IRCALL_H\nextern double __adddf3(double a, double b);\nextern double __subdf3(double a, double b);\nextern double __muldf3(double a, double b);\nextern double __divdf3(double a, double b);\n#endif\n#define SFGOTDEF(_)\t_(sqrt) _(__adddf3) _(__subdf3) _(__muldf3) _(__divdf3)\n#else\n#define SFGOTDEF(_)\n#endif\n#if LJ_HASJIT\n#define JITGOTDEF(_)\t_(lj_err_trace) _(lj_trace_exit) _(lj_trace_hot)\n#else\n#define JITGOTDEF(_)\n#endif\n#if LJ_HASFFI\n#define FFIGOTDEF(_) \\\n  _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave)\n#else\n#define FFIGOTDEF(_)\n#endif\n#define GOTDEF(_) \\\n  _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \\\n  _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \\\n  _(pow) _(fmod) _(ldexp) _(lj_vm_modi) \\\n  _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_dispatch_stitch) \\\n  _(lj_dispatch_profile) _(lj_err_throw) \\\n  _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \\\n  _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \\\n  _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \\\n  _(lj_meta_for) _(lj_meta_istype) _(lj_meta_len) _(lj_meta_tget) \\\n  _(lj_meta_tset) _(lj_state_growstack) _(lj_strfmt_number) \\\n  _(lj_str_new) _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) \\\n  _(lj_tab_new) _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \\\n  _(lj_tab_setinth) _(lj_buf_putstr_reverse) _(lj_buf_putstr_lower) \\\n  _(lj_buf_putstr_upper) _(lj_buf_tostr) \\\n  JITGOTDEF(_) FFIGOTDEF(_) SFGOTDEF(_)\n\nenum {\n#define GOTENUM(name) LJ_GOT_##name,\nGOTDEF(GOTENUM)\n#undef GOTENUM\n  LJ_GOT__MAX\n};\n#endif\n\n/* Type of hot counter. Must match the code in the assembler VM. */\n/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */\ntypedef uint16_t HotCount;\n\n/* Number of hot counter hash table entries (must be a power of two). */\n#define HOTCOUNT_SIZE\t\t64\n#define HOTCOUNT_PCMASK\t\t((HOTCOUNT_SIZE-1)*sizeof(HotCount))\n\n/* Hotcount decrements. */\n#define HOTCOUNT_LOOP\t\t2\n#define HOTCOUNT_CALL\t\t1\n\n/* This solves a circular dependency problem -- bump as needed. Sigh. */\n#define GG_NUM_ASMFF\t57\n\n#define GG_LEN_DDISP\t(BC__MAX + GG_NUM_ASMFF)\n#define GG_LEN_SDISP\tBC_FUNCF\n#define GG_LEN_DISP\t(GG_LEN_DDISP + GG_LEN_SDISP)\n\n/* Global state, main thread and extra fields are allocated together. */\ntypedef struct GG_State {\n  lua_State L;\t\t\t\t/* Main thread. */\n  global_State g;\t\t\t/* Global state. */\n#if LJ_TARGET_ARM\n  /* Make g reachable via K12 encoded DISPATCH-relative addressing. */\n  uint8_t align1[(16-sizeof(global_State))&15];\n#endif\n#if LJ_TARGET_MIPS\n  ASMFunction got[LJ_GOT__MAX];\t\t/* Global offset table. */\n#endif\n#if LJ_HASJIT\n  jit_State J;\t\t\t\t/* JIT state. */\n  HotCount hotcount[HOTCOUNT_SIZE];\t/* Hot counters. */\n#if LJ_TARGET_ARM\n  /* Ditto for J. */\n  uint8_t align2[(16-sizeof(jit_State)-sizeof(HotCount)*HOTCOUNT_SIZE)&15];\n#endif\n#endif\n  ASMFunction dispatch[GG_LEN_DISP];\t/* Instruction dispatch tables. */\n  BCIns bcff[GG_NUM_ASMFF];\t\t/* Bytecode for ASM fast functions. */\n} GG_State;\n\n#define GG_OFS(field)\t((int)offsetof(GG_State, field))\n#define G2GG(gl)\t((GG_State *)((char *)(gl) - GG_OFS(g)))\n#define J2GG(j)\t\t((GG_State *)((char *)(j) - GG_OFS(J)))\n#define L2GG(L)\t\t(G2GG(G(L)))\n#define J2G(J)\t\t(&J2GG(J)->g)\n#define G2J(gl)\t\t(&G2GG(gl)->J)\n#define L2J(L)\t\t(&L2GG(L)->J)\n#define GG_G2J\t\t(GG_OFS(J) - GG_OFS(g))\n#define GG_G2DISP\t(GG_OFS(dispatch) - GG_OFS(g))\n#define GG_DISP2G\t(GG_OFS(g) - GG_OFS(dispatch))\n#define GG_DISP2J\t(GG_OFS(J) - GG_OFS(dispatch))\n#define GG_DISP2HOT\t(GG_OFS(hotcount) - GG_OFS(dispatch))\n#define GG_DISP2STATIC\t(GG_LEN_DDISP*(int)sizeof(ASMFunction))\n\n#define hotcount_get(gg, pc) \\\n  (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)]\n#define hotcount_set(gg, pc, val) \\\n  (hotcount_get((gg), (pc)) = (HotCount)(val))\n\n/* Dispatch table management. */\nLJ_FUNC void lj_dispatch_init(GG_State *GG);\n#if LJ_HASJIT\nLJ_FUNC void lj_dispatch_init_hotcount(global_State *g);\n#endif\nLJ_FUNC void lj_dispatch_update(global_State *g);\n\n/* Instruction dispatch callback for hooks or when recording. */\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc);\nLJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc);\n#if LJ_HASJIT\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc);\n#endif\n#if LJ_HASPROFILE\nLJ_FUNCA void LJ_FASTCALL lj_dispatch_profile(lua_State *L, const BCIns *pc);\n#endif\n\n#if LJ_HASFFI && !defined(_BUILDVM_H)\n/* Save/restore errno and GetLastError() around hooks, exits and recording. */\n#include <errno.h>\n#if LJ_TARGET_WINDOWS\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n#define ERRNO_SAVE\tint olderr = errno; DWORD oldwerr = GetLastError();\n#define ERRNO_RESTORE\terrno = olderr; SetLastError(oldwerr);\n#else\n#define ERRNO_SAVE\tint olderr = errno;\n#define ERRNO_RESTORE\terrno = olderr;\n#endif\n#else\n#define ERRNO_SAVE\n#define ERRNO_RESTORE\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_emit_arm.h",
    "content": "/*\n** ARM instruction emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Constant encoding --------------------------------------------------- */\n\nstatic uint8_t emit_invai[16] = {\n  /* AND */ (ARMI_AND^ARMI_BIC) >> 21,\n  /* EOR */ 0,\n  /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21,\n  /* RSB */ 0,\n  /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21,\n  /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21,\n  /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21,\n  /* RSC */ 0,\n  /* TST */ 0,\n  /* TEQ */ 0,\n  /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21,\n  /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21,\n  /* ORR */ 0,\n  /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21,\n  /* BIC */ (ARMI_BIC^ARMI_AND) >> 21,\n  /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21\n};\n\n/* Encode constant in K12 format for data processing instructions. */\nstatic uint32_t emit_isk12(ARMIns ai, int32_t n)\n{\n  uint32_t invai, i, m = (uint32_t)n;\n  /* K12: unsigned 8 bit value, rotated in steps of two bits. */\n  for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))\n    if (m <= 255) return ARMI_K12|m|i;\n  /* Otherwise try negation/complement with the inverse instruction. */\n  invai = emit_invai[((ai >> 21) & 15)];\n  if (!invai) return 0;  /* Failed. No inverse instruction. */\n  m = ~(uint32_t)n;\n  if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) ||\n      invai == (ARMI_CMP^ARMI_CMN) >> 21) m++;\n  for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))\n    if (m <= 255) return ARMI_K12|(invai<<21)|m|i;\n  return 0;  /* Failed. */\n}\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm);\n}\n\nstatic void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm);\n}\n\nstatic void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn)\n{\n  *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn);\n}\n\nstatic void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm);\n}\n\nstatic void emit_d(ASMState *as, ARMIns ai, Reg rd)\n{\n  *--as->mcp = ai | ARMF_D(rd);\n}\n\nstatic void emit_n(ASMState *as, ARMIns ai, Reg rn)\n{\n  *--as->mcp = ai | ARMF_N(rn);\n}\n\nstatic void emit_m(ASMState *as, ARMIns ai, Reg rm)\n{\n  *--as->mcp = ai | ARMF_M(rm);\n}\n\nstatic void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lj_assertA(ofs >= -255 && ofs <= 255,\n\t     \"load/store offset %d out of range\", ofs);\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) |\n\t       ((ofs & 0xf0) << 4) | (ofs & 0x0f);\n}\n\nstatic void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lj_assertA(ofs >= -4095 && ofs <= 4095,\n\t     \"load/store offset %d out of range\", ofs);\n  /* Combine LDR/STR pairs to LDRD/STRD. */\n  if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) &&\n      (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn &&\n      (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) &&\n      as->mcp != as->mcloop) {\n    as->mcp++;\n    emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4);\n    return;\n  }\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs;\n}\n\n#if !LJ_SOFTFP\nstatic void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)\n{\n  lj_assertA(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0,\n\t     \"load/store offset %d out of range\", ofs);\n  if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;\n  *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2);\n}\n#endif\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer spills of BASE/L. */\n#define emit_canremat(ref)\t((ref) < ASMREF_L)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg d, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lj_assertA(r != d, \"dest reg not free\");\n    if (emit_canremat(ref)) {\n      int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);\n      uint32_t k = emit_isk12(ARMI_ADD, delta);\n      if (k) {\n\tif (k == ARMI_K12)\n\t  emit_dm(as, ARMI_MOV, d, r);\n\telse\n\t  emit_dn(as, ARMI_ADD^k, d, r);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Try to find a two step delta relative to another constant. */\nstatic int emit_kdelta2(ASMState *as, Reg rd, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lj_assertA(r != rd, \"dest reg %d not free\", rd);\n    if (emit_canremat(ref)) {\n      int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i;\n      if (other) {\n\tint32_t delta = i - other;\n\tuint32_t sh, inv = 0, k2, k;\n\tif (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; }\n\tsh = lj_ffs(delta) & ~1;\n\tk2 = emit_isk12(0, delta & (255 << sh));\n\tk = emit_isk12(0, delta & ~(255 << sh));\n\tif (k) {\n\t  emit_dn(as, ARMI_ADD^k2^inv, rd, rd);\n\t  emit_dn(as, ARMI_ADD^k^inv, rd, r);\n\t  return 1;\n\t}\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg rd, int32_t i)\n{\n  uint32_t k = emit_isk12(ARMI_MOV, i);\n  lj_assertA(rset_test(as->freeset, rd) || rd == RID_TMP,\n\t     \"dest reg %d not free\", rd);\n  if (k) {\n    /* Standard K12 constant. */\n    emit_d(as, ARMI_MOV^k, rd);\n  } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) {\n    /* 16 bit loword constant for ARMv6T2. */\n    emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), rd);\n  } else if (emit_kdelta1(as, rd, i)) {\n    /* One step delta relative to another constant. */\n  } else if ((as->flags & JIT_F_ARMV6T2)) {\n    /* 32 bit hiword/loword constant for ARMv6T2. */\n    emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), rd);\n    emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), rd);\n  } else if (emit_kdelta2(as, rd, i)) {\n    /* Two step delta relative to another constant. */\n  } else {\n    /* Otherwise construct the constant with up to 4 instructions. */\n    /* NYI: use mvn+bic, use pc-relative loads. */\n    for (;;) {\n      uint32_t sh = lj_ffs(i) & ~1;\n      int32_t m = i & (255 << sh);\n      i &= ~(255 << sh);\n      if (i == 0) {\n\temit_d(as, ARMI_MOV ^ emit_isk12(0, m), rd);\n\tbreak;\n      }\n      emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), rd, rd);\n    }\n  }\n}\n\n#define emit_loada(as, rd, addr)\temit_loadi(as, (rd), i32ptr((addr)))\n\nstatic Reg ra_allock(ASMState *as, intptr_t k, RegSet allow);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p)\n{\n  int32_t i = i32ptr(p);\n  emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)),\n\t   (i & 4095));\n}\n\n#if !LJ_SOFTFP\n/* Load a number constant into an FPR. */\nstatic void emit_loadk64(ASMState *as, Reg r, IRIns *ir)\n{\n  cTValue *tv = ir_knum(ir);\n  int32_t i;\n  if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) {\n    uint32_t hi = tv->u32.hi;\n    uint32_t b = ((hi >> 22) & 0x1ff);\n    if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) {\n      *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) |\n\t\t   ((tv->u32.hi >> 12) & 0x00080000) |\n\t\t   ((tv->u32.hi >> 4) & 0x00070000) |\n\t\t   ((tv->u32.hi >> 16) & 0x0000000f);\n      return;\n    }\n  }\n  i = i32ptr(tv);\n  emit_vlso(as, ARMI_VLDR_D, r,\n\t    ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020));\n}\n#endif\n\n/* Get/set global_State fields. */\n#define emit_getgl(as, r, field) \\\n  emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field)\n#define emit_setgl(as, r, field) \\\n  emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field)\n\n/* Trace number is determined from pc of exit instruction. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_branch(ASMState *as, ARMIns ai, MCode *target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = (target - p) - 1;\n  lj_assertA(((delta + 0x00800000) >> 24) == 0, \"branch target out of range\");\n  *--p = ai | ((uint32_t)delta & 0x00ffffffu);\n  as->mcp = p;\n}\n\n#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target))\n\nstatic void emit_call(ASMState *as, void *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = ((char *)target - (char *)p) - 8;\n  if ((((delta>>2) + 0x00800000) >> 24) == 0) {\n    if ((delta & 1))\n      *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 23);\n    else\n      *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu);\n  } else {  /* Target out of range: need indirect call. But don't use R0-R3. */\n    Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1));\n    *p = ARMI_BLXr | ARMF_M(r);\n  }\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n#if LJ_SOFTFP\n  lj_assertA(!irt_isnum(ir->t), \"unexpected FP op\"); UNUSED(ir);\n#else\n  if (dst >= RID_MAX_GPR) {\n    emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S,\n\t    (dst & 15), (src & 15));\n    return;\n  }\n#endif\n  if (as->mcp != as->mcloop) {  /* Swap early registers for loads/stores. */\n    MCode ins = *as->mcp, swp = (src^dst);\n    if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) {\n      if (!((ins ^ (dst << 16)) & 0x000f0000))\n\t*as->mcp = ins ^ (swp << 16);  /* Swap N in load/store. */\n      if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000))\n\t*as->mcp = ins ^ (swp << 12);  /* Swap D in store. */\n    }\n  }\n  emit_dm(as, ARMI_MOV, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n#if LJ_SOFTFP\n  lj_assertA(!irt_isnum(ir->t), \"unexpected FP op\"); UNUSED(ir);\n#else\n  if (r >= RID_MAX_GPR)\n    emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, base, ofs);\n  else\n#endif\n    emit_lso(as, ARMI_LDR, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n#if LJ_SOFTFP\n  lj_assertA(!irt_isnum(ir->t), \"unexpected FP op\"); UNUSED(ir);\n#else\n  if (r >= RID_MAX_GPR)\n    emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, base, ofs);\n  else\n#endif\n    emit_lso(as, ARMI_STR, r, base, ofs);\n}\n\n/* Emit an arithmetic/logic operation with a constant operand. */\nstatic void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src,\n\t\t     int32_t i, RegSet allow)\n{\n  uint32_t k = emit_isk12(ai, i);\n  if (k)\n    emit_dn(as, ai^k, dest, src);\n  else\n    emit_dnm(as, ai, dest, src, ra_allock(as, i, allow));\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs)\n    emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r));\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_SP, -(ofs))\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_emit_arm64.h",
    "content": "/*\n** ARM64 instruction emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.\n** Sponsored by Cisco Systems, Inc.\n*/\n\n/* -- Constant encoding --------------------------------------------------- */\n\nstatic uint64_t get_k64val(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_KINT64) {\n    return ir_kint64(ir)->u64;\n  } else if (ir->o == IR_KGC) {\n    return (uint64_t)ir_kgc(ir);\n  } else if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n    return (uint64_t)ir_kptr(ir);\n  } else {\n    lj_assertA(ir->o == IR_KINT || ir->o == IR_KNULL,\n\t       \"bad 64 bit const IR op %d\", ir->o);\n    return ir->i;  /* Sign-extended. */\n  }\n}\n\n/* Encode constant in K12 format for data processing instructions. */\nstatic uint32_t emit_isk12(int64_t n)\n{\n  uint64_t k = (n < 0) ? -n : n;\n  uint32_t m = (n < 0) ? 0x40000000 : 0;\n  if (k < 0x1000) {\n    return A64I_K12|m|A64F_U12(k);\n  } else if ((k & 0xfff000) == k) {\n    return A64I_K12|m|0x400000|A64F_U12(k>>12);\n  }\n  return 0;\n}\n\n#define emit_clz64(n)\t__builtin_clzll(n)\n#define emit_ctz64(n)\t__builtin_ctzll(n)\n\n/* Encode constant in K13 format for logical data processing instructions. */\nstatic uint32_t emit_isk13(uint64_t n, int is64)\n{\n  int inv = 0, w = 128, lz, tz;\n  if (n & 1) { n = ~n; w = 64; inv = 1; }  /* Avoid wrap-around of ones. */\n  if (!n) return 0;  /* Neither all-zero nor all-ones are allowed. */\n  do {  /* Find the repeat width. */\n    if (is64 && (uint32_t)(n^(n>>32))) break;\n    n = (uint32_t)n;\n    if (!n) return 0;  /* Ditto when passing n=0xffffffff and is64=0. */\n    w = 32; if ((n^(n>>16)) & 0xffff) break;\n    n = n & 0xffff; w = 16; if ((n^(n>>8)) & 0xff) break;\n    n = n & 0xff; w = 8; if ((n^(n>>4)) & 0xf) break;\n    n = n & 0xf; w = 4; if ((n^(n>>2)) & 0x3) break;\n    n = n & 0x3; w = 2;\n  } while (0);\n  lz = emit_clz64(n);\n  tz = emit_ctz64(n);\n  if ((int64_t)(n << lz) >> (lz+tz) != -1ll) return 0; /* Non-contiguous? */\n  if (inv)\n    return A64I_K13 | (((lz-w) & 127) << 16) | (((lz+tz-w-1) & 63) << 10);\n  else\n    return A64I_K13 | ((w-tz) << 16) | (((63-lz-tz-w-w) & 63) << 10);\n}\n\nstatic uint32_t emit_isfpk64(uint64_t n)\n{\n  uint64_t etop9 = ((n >> 54) & 0x1ff);\n  if ((n << 16) == 0 && (etop9 == 0x100 || etop9 == 0x0ff)) {\n    return (uint32_t)(((n >> 48) & 0x7f) | ((n >> 56) & 0x80));\n  }\n  return ~0u;\n}\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_dnma(ASMState *as, A64Ins ai, Reg rd, Reg rn, Reg rm, Reg ra)\n{\n  *--as->mcp = ai | A64F_D(rd) | A64F_N(rn) | A64F_M(rm) | A64F_A(ra);\n}\n\nstatic void emit_dnm(ASMState *as, A64Ins ai, Reg rd, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | A64F_D(rd) | A64F_N(rn) | A64F_M(rm);\n}\n\nstatic void emit_dm(ASMState *as, A64Ins ai, Reg rd, Reg rm)\n{\n  *--as->mcp = ai | A64F_D(rd) | A64F_M(rm);\n}\n\nstatic void emit_dn(ASMState *as, A64Ins ai, Reg rd, Reg rn)\n{\n  *--as->mcp = ai | A64F_D(rd) | A64F_N(rn);\n}\n\nstatic void emit_nm(ASMState *as, A64Ins ai, Reg rn, Reg rm)\n{\n  *--as->mcp = ai | A64F_N(rn) | A64F_M(rm);\n}\n\nstatic void emit_d(ASMState *as, A64Ins ai, Reg rd)\n{\n  *--as->mcp = ai | A64F_D(rd);\n}\n\nstatic void emit_n(ASMState *as, A64Ins ai, Reg rn)\n{\n  *--as->mcp = ai | A64F_N(rn);\n}\n\nstatic int emit_checkofs(A64Ins ai, int64_t ofs)\n{\n  int scale = (ai >> 30) & 3;\n  if (ofs < 0 || (ofs & ((1<<scale)-1))) {\n    return (ofs >= -256 && ofs <= 255) ? -1 : 0;\n  } else {\n    return (ofs < (4096<<scale)) ? 1 : 0;\n  }\n}\n\nstatic void emit_lso(ASMState *as, A64Ins ai, Reg rd, Reg rn, int64_t ofs)\n{\n  int ot = emit_checkofs(ai, ofs), sc = (ai >> 30) & 3;\n  lj_assertA(ot, \"load/store offset %d out of range\", ofs);\n  /* Combine LDR/STR pairs to LDP/STP. */\n  if ((sc == 2 || sc == 3) &&\n      (!(ai & 0x400000) || rd != rn) &&\n      as->mcp != as->mcloop) {\n    uint32_t prev = *as->mcp & ~A64F_D(31);\n    int ofsm = ofs - (1<<sc), ofsp = ofs + (1<<sc);\n    A64Ins aip;\n    if (prev == (ai | A64F_N(rn) | A64F_U12(ofsm>>sc)) ||\n\tprev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsm&0x1ff))) {\n      aip = (A64F_A(rd) | A64F_D(*as->mcp & 31));\n    } else if (prev == (ai | A64F_N(rn) | A64F_U12(ofsp>>sc)) ||\n\t       prev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsp&0x1ff))) {\n      aip = (A64F_D(rd) | A64F_A(*as->mcp & 31));\n      ofsm = ofs;\n    } else {\n      goto nopair;\n    }\n    if (ofsm >= (int)((unsigned int)-64<<sc) && ofsm <= (63<<sc)) {\n      *as->mcp = aip | A64F_N(rn) | ((ofsm >> sc) << 15) |\n\t(ai ^ ((ai == A64I_LDRx || ai == A64I_STRx) ? 0x50000000 : 0x90000000));\n      return;\n    }\n  }\nnopair:\n  if (ot == 1)\n    *--as->mcp = ai | A64F_D(rd) | A64F_N(rn) | A64F_U12(ofs >> sc);\n  else\n    *--as->mcp = (ai^A64I_LS_U) | A64F_D(rd) | A64F_N(rn) | A64F_S9(ofs & 0x1ff);\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= ASMREF_L)\n\n/* Try to find an N-step delta relative to other consts with N < lim. */\nstatic int emit_kdelta(ASMState *as, Reg rd, uint64_t k, int lim)\n{\n  RegSet work = (~as->freeset & RSET_GPR) | RID2RSET(RID_GL);\n  if (lim <= 1) return 0;  /* Can't beat that. */\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lj_assertA(r != rd, \"dest reg %d not free\", rd);\n    if (ref < REF_TRUE) {\n      uint64_t kx = ra_iskref(ref) ? (uint64_t)ra_krefk(as, ref) :\n\t\t\t\t     get_k64val(as, ref);\n      int64_t delta = (int64_t)(k - kx);\n      if (delta == 0) {\n\temit_dm(as, A64I_MOVx, rd, r);\n\treturn 1;\n      } else {\n\tuint32_t k12 = emit_isk12(delta < 0 ? -delta : delta);\n\tif (k12) {\n\t  emit_dn(as, (delta < 0 ? A64I_SUBx : A64I_ADDx)^k12, rd, r);\n\t  return 1;\n\t}\n\t/* Do other ops or multi-step deltas pay off? Probably not.\n\t** E.g. XOR rarely helps with pointer consts.\n\t*/\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\nstatic void emit_loadk(ASMState *as, Reg rd, uint64_t u64, int is64)\n{\n  int i, zeros = 0, ones = 0, neg;\n  if (!is64) u64 = (int64_t)(int32_t)u64;  /* Sign-extend. */\n  /* Count homogeneous 16 bit fragments. */\n  for (i = 0; i < 4; i++) {\n    uint64_t frag = (u64 >> i*16) & 0xffff;\n    zeros += (frag == 0);\n    ones += (frag == 0xffff);\n  }\n  neg = ones > zeros;  /* Use MOVN if it pays off. */\n  if ((neg ? ones : zeros) < 3) {  /* Need 2+ ins. Try shorter K13 encoding. */\n    uint32_t k13 = emit_isk13(u64, is64);\n    if (k13) {\n      emit_dn(as, (is64|A64I_ORRw)^k13, rd, RID_ZERO);\n      return;\n    }\n  }\n  if (!emit_kdelta(as, rd, u64, 4 - (neg ? ones : zeros))) {\n    int shift = 0, lshift = 0;\n    uint64_t n64 = neg ? ~u64 : u64;\n    if (n64 != 0) {\n      /* Find first/last fragment to be filled. */\n      shift = (63-emit_clz64(n64)) & ~15;\n      lshift = emit_ctz64(n64) & ~15;\n    }\n    /* MOVK requires the original value (u64). */\n    while (shift > lshift) {\n      uint32_t u16 = (u64 >> shift) & 0xffff;\n      /* Skip fragments that are correctly filled by MOVN/MOVZ. */\n      if (u16 != (neg ? 0xffff : 0))\n\temit_d(as, is64 | A64I_MOVKw | A64F_U16(u16) | A64F_LSL16(shift), rd);\n      shift -= 16;\n    }\n    /* But MOVN needs an inverted value (n64). */\n    emit_d(as, (neg ? A64I_MOVNx : A64I_MOVZx) |\n\t       A64F_U16((n64 >> lshift) & 0xffff) | A64F_LSL16(lshift), rd);\n  }\n}\n\n/* Load a 32 bit constant into a GPR. */\n#define emit_loadi(as, rd, i)\temit_loadk(as, rd, i, 0)\n\n/* Load a 64 bit constant into a GPR. */\n#define emit_loadu64(as, rd, i)\temit_loadk(as, rd, i, A64I_X)\n\n#define emit_loada(as, r, addr)\temit_loadu64(as, (r), (uintptr_t)(addr))\n\n#define glofs(as, k) \\\n  ((intptr_t)((uintptr_t)(k) - (uintptr_t)&J2GG(as->J)->g))\n#define mcpofs(as, k) \\\n  ((intptr_t)((uintptr_t)(k) - (uintptr_t)(as->mcp - 1)))\n#define checkmcpofs(as, k) \\\n  (A64F_S_OK(mcpofs(as, k)>>2, 19))\n\nstatic Reg ra_allock(ASMState *as, intptr_t k, RegSet allow);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, A64Ins ai, Reg r, void *p)\n{\n  /* First, check if ip + offset is in range. */\n  if ((ai & 0x00400000) && checkmcpofs(as, p)) {\n    emit_d(as, A64I_LDRLx | A64F_S19(mcpofs(as, p)>>2), r);\n  } else {\n    Reg base = RID_GL;  /* Next, try GL + offset. */\n    int64_t ofs = glofs(as, p);\n    if (!emit_checkofs(ai, ofs)) {  /* Else split up into base reg + offset. */\n      int64_t i64 = i64ptr(p);\n      base = ra_allock(as, (i64 & ~0x7fffull), rset_exclude(RSET_GPR, r));\n      ofs = i64 & 0x7fffull;\n    }\n    emit_lso(as, ai, r, base, ofs);\n  }\n}\n\n/* Load 64 bit IR constant into register. */\nstatic void emit_loadk64(ASMState *as, Reg r, IRIns *ir)\n{\n  const uint64_t *k = &ir_k64(ir)->u64;\n  int64_t ofs;\n  if (r >= RID_MAX_GPR) {\n    uint32_t fpk = emit_isfpk64(*k);\n    if (fpk != ~0u) {\n      emit_d(as, A64I_FMOV_DI | A64F_FP8(fpk), (r & 31));\n      return;\n    }\n  }\n  ofs = glofs(as, k);\n  if (emit_checkofs(A64I_LDRx, ofs)) {\n    emit_lso(as, r >= RID_MAX_GPR ? A64I_LDRd : A64I_LDRx,\n\t     (r & 31), RID_GL, ofs);\n  } else {\n    if (r >= RID_MAX_GPR) {\n      emit_dn(as, A64I_FMOV_D_R, (r & 31), RID_TMP);\n      r = RID_TMP;\n    }\n    if (checkmcpofs(as, k))\n      emit_d(as, A64I_LDRLx | A64F_S19(mcpofs(as, k)>>2), r);\n    else\n      emit_loadu64(as, r, *k);\n  }\n}\n\n/* Get/set global_State fields. */\n#define emit_getgl(as, r, field) \\\n  emit_lsptr(as, A64I_LDRx, (r), (void *)&J2G(as->J)->field)\n#define emit_setgl(as, r, field) \\\n  emit_lsptr(as, A64I_STRx, (r), (void *)&J2G(as->J)->field)\n\n/* Trace number is determined from pc of exit instruction. */\n#define emit_setvmstate(as, i)\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_cond_branch(ASMState *as, A64CC cond, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(A64F_S_OK(delta, 19), \"branch target out of range\");\n  *p = A64I_BCC | A64F_S19(delta) | cond;\n}\n\nstatic void emit_branch(ASMState *as, A64Ins ai, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(A64F_S_OK(delta, 26), \"branch target out of range\");\n  *p = ai | A64F_S26(delta);\n}\n\nstatic void emit_tnb(ASMState *as, A64Ins ai, Reg r, uint32_t bit, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(bit < 63, \"bit number out of range\");\n  lj_assertA(A64F_S_OK(delta, 14), \"branch target out of range\");\n  if (bit > 31) ai |= A64I_X;\n  *p = ai | A64F_BIT(bit & 31) | A64F_S14(delta) | r;\n}\n\nstatic void emit_cnb(ASMState *as, A64Ins ai, Reg r, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(A64F_S_OK(delta, 19), \"branch target out of range\");\n  *p = ai | A64F_S19(delta) | r;\n}\n\n#define emit_jmp(as, target)\temit_branch(as, A64I_B, (target))\n\nstatic void emit_call(ASMState *as, void *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  if (A64F_S_OK(delta>>2, 26)) {\n    *p = A64I_BL | A64F_S26(delta>>2);\n  } else {  /* Target out of range: need indirect call. But don't use R0-R7. */\n    Reg r = ra_allock(as, i64ptr(target),\n\t\t      RSET_RANGE(RID_X8, RID_MAX_GPR)-RSET_FIXED);\n    *p = A64I_BLR | A64F_N(r);\n  }\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  if (dst >= RID_MAX_GPR) {\n    emit_dn(as, irt_isnum(ir->t) ? A64I_FMOV_D : A64I_FMOV_S,\n\t    (dst & 31), (src & 31));\n    return;\n  }\n  if (as->mcp != as->mcloop) {  /* Swap early registers for loads/stores. */\n    MCode ins = *as->mcp, swp = (src^dst);\n    if ((ins & 0xbf800000) == 0xb9000000) {\n      if (!((ins ^ (dst << 5)) & 0x000003e0))\n\t*as->mcp = ins ^ (swp << 5);  /* Swap N in load/store. */\n      if (!(ins & 0x00400000) && !((ins ^ dst) & 0x0000001f))\n\t*as->mcp = ins ^ swp;  /* Swap D in store. */\n    }\n  }\n  emit_dm(as, A64I_MOVx, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r >= RID_MAX_GPR)\n    emit_lso(as, irt_isnum(ir->t) ? A64I_LDRd : A64I_LDRs, (r & 31), base, ofs);\n  else\n    emit_lso(as, irt_is64(ir->t) ? A64I_LDRx : A64I_LDRw, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r >= RID_MAX_GPR)\n    emit_lso(as, irt_isnum(ir->t) ? A64I_STRd : A64I_STRs, (r & 31), base, ofs);\n  else\n    emit_lso(as, irt_is64(ir->t) ? A64I_STRx : A64I_STRw, r, base, ofs);\n}\n\n/* Emit an arithmetic operation with a constant operand. */\nstatic void emit_opk(ASMState *as, A64Ins ai, Reg dest, Reg src,\n\t\t     int32_t i, RegSet allow)\n{\n  uint32_t k = emit_isk12(i);\n  if (k)\n    emit_dn(as, ai^k, dest, src);\n  else\n    emit_dnm(as, ai, dest, src, ra_allock(as, i, allow));\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs)\n    emit_opk(as, ofs < 0 ? A64I_SUBx : A64I_ADDx, r, r,\n\t\t ofs < 0 ? -ofs : ofs, rset_exclude(RSET_GPR, r));\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_SP, -(ofs))\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_emit_mips.h",
    "content": "/*\n** MIPS instruction emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#if LJ_64\nstatic intptr_t get_k64val(ASMState *as, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_KINT64) {\n    return (intptr_t)ir_kint64(ir)->u64;\n  } else if (ir->o == IR_KGC) {\n    return (intptr_t)ir_kgc(ir);\n  } else if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {\n    return (intptr_t)ir_kptr(ir);\n  } else if (LJ_SOFTFP && ir->o == IR_KNUM) {\n    return (intptr_t)ir_knum(ir)->u64;\n  } else {\n    lj_assertA(ir->o == IR_KINT || ir->o == IR_KNULL,\n\t       \"bad 64 bit const IR op %d\", ir->o);\n    return ir->i;  /* Sign-extended. */\n  }\n}\n#endif\n\n#if LJ_64\n#define get_kval(as, ref)\tget_k64val(as, ref)\n#else\n#define get_kval(as, ref)\t(IR((ref))->i)\n#endif\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt)\n{\n  *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt);\n}\n\nstatic void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a)\n{\n  *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a);\n}\n\n#define emit_ds(as, mi, rd, rs)\t\temit_dst(as, (mi), (rd), (rs), 0)\n#define emit_tg(as, mi, rt, rg)\t\temit_dst(as, (mi), (rg)&31, 0, (rt))\n\nstatic void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i)\n{\n  *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff);\n}\n\n#define emit_ti(as, mi, rt, i)\t\temit_tsi(as, (mi), (rt), 0, (i))\n#define emit_hsi(as, mi, rh, rs, i)\temit_tsi(as, (mi), (rh) & 31, (rs), (i))\n\nstatic void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh)\n{\n  *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31);\n}\n\n#define emit_fg(as, mi, rf, rg)\t\temit_fgh(as, (mi), (rf), (rg), 0)\n\nstatic void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift)\n{\n  if (LJ_64 || (as->flags & JIT_F_MIPSXXR2)) {\n    emit_dta(as, MIPSI_ROTR, dest, src, shift);\n  } else {\n    emit_dst(as, MIPSI_OR, dest, dest, tmp);\n    emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31);\n    emit_dta(as, MIPSI_SRL, tmp, src, shift);\n  }\n}\n\n#if LJ_64 || LJ_HASBUFFER\nstatic void emit_tsml(ASMState *as, MIPSIns mi, Reg rt, Reg rs, uint32_t msb,\n\t\t      uint32_t lsb)\n{\n  *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | MIPSF_M(msb) | MIPSF_L(lsb);\n}\n#endif\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg rd, intptr_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lj_assertA(r != rd, \"dest reg %d not free\", rd);\n    if (ref < ASMREF_L) {\n      intptr_t delta = (intptr_t)((uintptr_t)i -\n\t(uintptr_t)(ra_iskref(ref) ? ra_krefk(as, ref) : get_kval(as, ref)));\n      if (checki16(delta)) {\n\temit_tsi(as, MIPSI_AADDIU, rd, r, delta);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  if (checki16(i)) {\n    emit_ti(as, MIPSI_LI, r, i);\n  } else {\n    if ((i & 0xffff)) {\n      intptr_t jgl = (intptr_t)(void *)J2G(as->J);\n      if ((uintptr_t)(i-jgl) < 65536) {\n\temit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768);\n\treturn;\n      } else if (emit_kdelta1(as, r, i)) {\n\treturn;\n      } else if ((i >> 16) == 0) {\n\temit_tsi(as, MIPSI_ORI, r, RID_ZERO, i);\n\treturn;\n      }\n      emit_tsi(as, MIPSI_ORI, r, r, i);\n    }\n    emit_ti(as, MIPSI_LUI, r, (i >> 16));\n  }\n}\n\n#if LJ_64\n/* Load a 64 bit constant into a GPR. */\nstatic void emit_loadu64(ASMState *as, Reg r, uint64_t u64)\n{\n  if (checki32((int64_t)u64)) {\n    emit_loadi(as, r, (int32_t)u64);\n  } else {\n    uint64_t delta = u64 - (uint64_t)(void *)J2G(as->J);\n    if (delta < 65536) {\n      emit_tsi(as, MIPSI_DADDIU, r, RID_JGL, (int32_t)(delta-32768));\n    } else if (emit_kdelta1(as, r, (intptr_t)u64)) {\n      return;\n    } else {\n      /* TODO MIPSR6: Use DAHI & DATI. Caveat: sign-extension. */\n      if ((u64 & 0xffff)) {\n\temit_tsi(as, MIPSI_ORI, r, r, u64 & 0xffff);\n      }\n      if (((u64 >> 16) & 0xffff)) {\n\temit_dta(as, MIPSI_DSLL, r, r, 16);\n\temit_tsi(as, MIPSI_ORI, r, r, (u64 >> 16) & 0xffff);\n\temit_dta(as, MIPSI_DSLL, r, r, 16);\n      } else {\n\temit_dta(as, MIPSI_DSLL32, r, r, 0);\n      }\n      emit_loadi(as, r, (int32_t)(u64 >> 32));\n    }\n    /* TODO: There are probably more optimization opportunities. */\n  }\n}\n\n#define emit_loada(as, r, addr)\t\temit_loadu64(as, (r), u64ptr((addr)))\n#else\n#define emit_loada(as, r, addr)\t\temit_loadi(as, (r), i32ptr((addr)))\n#endif\n\nstatic Reg ra_allock(ASMState *as, intptr_t k, RegSet allow);\nstatic void ra_allockreg(ASMState *as, intptr_t k, Reg r);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow)\n{\n  intptr_t jgl = (intptr_t)(J2G(as->J));\n  intptr_t i = (intptr_t)(p);\n  Reg base;\n  if ((uint32_t)(i-jgl) < 65536) {\n    i = i-jgl-32768;\n    base = RID_JGL;\n  } else {\n    base = ra_allock(as, i-(int16_t)i, allow);\n  }\n  emit_tsi(as, mi, r, base, i);\n}\n\n#if LJ_64\nstatic void emit_loadk64(ASMState *as, Reg r, IRIns *ir)\n{\n  const uint64_t *k = &ir_k64(ir)->u64;\n  Reg r64 = r;\n  if (rset_test(RSET_FPR, r)) {\n    r64 = RID_TMP;\n    emit_tg(as, MIPSI_DMTC1, r64, r);\n  }\n  if ((uint32_t)((intptr_t)k-(intptr_t)J2G(as->J)) < 65536)\n    emit_lsptr(as, MIPSI_LD, r64, (void *)k, 0);\n  else\n    emit_loadu64(as, r64, *k);\n}\n#else\n#define emit_loadk64(as, r, ir) \\\n  emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)&ir_knum((ir))->u64, RSET_GPR)\n#endif\n\n/* Get/set global_State fields. */\nstatic void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs)\n{\n  emit_tsi(as, mi, r, RID_JGL, ofs-32768);\n}\n\n#define emit_getgl(as, r, field) \\\n  emit_lsglptr(as, MIPSI_AL, (r), (int32_t)offsetof(global_State, field))\n#define emit_setgl(as, r, field) \\\n  emit_lsglptr(as, MIPSI_AS, (r), (int32_t)offsetof(global_State, field))\n\n/* Trace number is determined from per-trace exit stubs. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(((delta + 0x8000) >> 16) == 0, \"branch target out of range\");\n  *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu);\n  as->mcp = p;\n}\n\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  *--as->mcp = MIPSI_NOP;\n  emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target));\n}\n\nstatic void emit_call(ASMState *as, void *target, int needcfa)\n{\n  MCode *p = as->mcp;\n#if LJ_TARGET_MIPSR6\n  ptrdiff_t delta = (char *)target - (char *)p;\n  if ((((delta>>2) + 0x02000000) >> 26) == 0) {  /* Try compact call first. */\n    *--p = MIPSI_BALC | (((uintptr_t)delta >>2) & 0x03ffffffu);\n    as->mcp = p;\n    return;\n  }\n#endif\n  *--p = MIPSI_NOP;  /* Delay slot. */\n  if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0) {\n#if !LJ_TARGET_MIPSR6\n    *--p = (((uintptr_t)target & 1) ? MIPSI_JALX : MIPSI_JAL) |\n\t   (((uintptr_t)target >>2) & 0x03ffffffu);\n#else\n    *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu);\n#endif\n  } else {  /* Target out of range: need indirect call. */\n    *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR);\n    needcfa = 1;\n  }\n  as->mcp = p;\n  if (needcfa) ra_allockreg(as, (intptr_t)target, RID_CFUNCADDR);\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n#define emit_move(as, dst, src) \\\n  emit_ds(as, MIPSI_MOVE, (dst), (src))\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  if (dst < RID_MAX_GPR)\n    emit_move(as, dst, src);\n  else\n    emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tsi(as, irt_is64(ir->t) ? MIPSI_LD : MIPSI_LW, r, base, ofs);\n  else\n    emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1,\n\t     (r & 31), base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tsi(as, irt_is64(ir->t) ? MIPSI_SD : MIPSI_SW, r, base, ofs);\n  else\n    emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1,\n\t     (r&31), base, ofs);\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    lj_assertA(checki16(ofs), \"offset %d out of range\", ofs);\n    emit_tsi(as, MIPSI_AADDIU, r, r, ofs);\n  }\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_SP, -(ofs))\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_emit_ppc.h",
    "content": "/*\n** PPC instruction emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Emit basic instructions --------------------------------------------- */\n\nstatic void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb)\n{\n  *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb);\n}\n\n#define emit_asb(as, pi, ra, rs, rb)\temit_tab(as, (pi), (rs), (ra), (rb))\n#define emit_as(as, pi, ra, rs)\t\temit_tab(as, (pi), (rs), (ra), 0)\n#define emit_ab(as, pi, ra, rb)\t\temit_tab(as, (pi), 0, (ra), (rb))\n\nstatic void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i)\n{\n  *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff);\n}\n\n#define emit_ti(as, pi, rt, i)\t\temit_tai(as, (pi), (rt), 0, (i))\n#define emit_ai(as, pi, ra, i)\t\temit_tai(as, (pi), 0, (ra), (i))\n#define emit_asi(as, pi, ra, rs, i)\temit_tai(as, (pi), (rs), (ra), (i))\n\n#define emit_fab(as, pi, rf, ra, rb) \\\n  emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31)\n#define emit_fb(as, pi, rf, rb)\t\temit_tab(as, (pi), (rf)&31, 0, (rb)&31)\n#define emit_fac(as, pi, rf, ra, rc) \\\n  emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0)\n#define emit_facb(as, pi, rf, ra, rc, rb) \\\n  emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31)\n#define emit_fai(as, pi, rf, ra, i)\temit_tai(as, (pi), (rf)&31, (ra), (i))\n\nstatic void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs,\n\t\t     int32_t n, int32_t b, int32_t e)\n{\n  *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) |\n\t       PPCF_MB(b) | PPCF_ME(e);\n}\n\nstatic void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n)\n{\n  lj_assertA(n >= 0 && n < 32, \"shift out or range\");\n  emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n);\n}\n\nstatic void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n)\n{\n  lj_assertA(n >= 0 && n < 32, \"shift out or range\");\n  emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31);\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n/* Try to find a one step delta relative to another constant. */\nstatic int emit_kdelta1(ASMState *as, Reg rd, int32_t i)\n{\n  RegSet work = ~as->freeset & RSET_GPR;\n  while (work) {\n    Reg r = rset_picktop(work);\n    IRRef ref = regcost_ref(as->cost[r]);\n    lj_assertA(r != rd, \"dest reg %d not free\", rd);\n    if (ref < ASMREF_L) {\n      int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);\n      if (checki16(delta)) {\n\temit_tai(as, PPCI_ADDI, rd, r, delta);\n\treturn 1;\n      }\n    }\n    rset_clear(work, r);\n  }\n  return 0;  /* Failed. */\n}\n\n/* Load a 32 bit constant into a GPR. */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  if (checki16(i)) {\n    emit_ti(as, PPCI_LI, r, i);\n  } else {\n    if ((i & 0xffff)) {\n      int32_t jgl = i32ptr(J2G(as->J));\n      if ((uint32_t)(i-jgl) < 65536) {\n\temit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768);\n\treturn;\n      } else if (emit_kdelta1(as, r, i)) {\n\treturn;\n      }\n      emit_asi(as, PPCI_ORI, r, r, i);\n    }\n    emit_ti(as, PPCI_LIS, r, (i >> 16));\n  }\n}\n\n#define emit_loada(as, r, addr)\t\temit_loadi(as, (r), i32ptr((addr)))\n\nstatic Reg ra_allock(ASMState *as, intptr_t k, RegSet allow);\n\n/* Get/set from constant pointer. */\nstatic void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow)\n{\n  int32_t jgl = i32ptr(J2G(as->J));\n  int32_t i = i32ptr(p);\n  Reg base;\n  if ((uint32_t)(i-jgl) < 65536) {\n    i = i-jgl-32768;\n    base = RID_JGL;\n  } else {\n    base = ra_allock(as, i-(int16_t)i, allow);\n  }\n  emit_tai(as, pi, r, base, i);\n}\n\n#define emit_loadk64(as, r, ir) \\\n  emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)&ir_knum((ir))->u64, RSET_GPR)\n\n/* Get/set global_State fields. */\nstatic void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs)\n{\n  emit_tai(as, pi, r, RID_JGL, ofs-32768);\n}\n\n#define emit_getgl(as, r, field) \\\n  emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field))\n#define emit_setgl(as, r, field) \\\n  emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field))\n\n/* Trace number is determined from per-trace exit stubs. */\n#define emit_setvmstate(as, i)\t\tUNUSED(i)\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for internal jumps. */\ntypedef MCode *MCLabel;\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\nstatic void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  lj_assertA(((delta + 0x8000) >> 16) == 0, \"branch target out of range\");\n  pi ^= (delta & 0x8000) * (PPCF_Y/0x8000);\n  *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu);\n}\n\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  *p = PPCI_B | (delta & 0x03fffffcu);\n}\n\nstatic void emit_call(ASMState *as, void *target)\n{\n  MCode *p = --as->mcp;\n  ptrdiff_t delta = (char *)target - (char *)p;\n  if ((((delta>>2) + 0x00800000) >> 24) == 0) {\n    *p = PPCI_BL | (delta & 0x03fffffcu);\n  } else {  /* Target out of range: need indirect call. Don't use arg reg. */\n    RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);\n    Reg r = ra_allock(as, i32ptr(target), allow);\n    *p = PPCI_BCTRL;\n    p[-1] = PPCI_MTCTR | PPCF_T(r);\n    as->mcp = p-1;\n  }\n}\n\n/* -- Emit generic operations --------------------------------------------- */\n\n#define emit_mr(as, dst, src) \\\n  emit_asb(as, PPCI_MR, (dst), (src), (src))\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  UNUSED(ir);\n  if (dst < RID_MAX_GPR)\n    emit_mr(as, dst, src);\n  else\n    emit_fb(as, PPCI_FMR, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tai(as, PPCI_LWZ, r, base, ofs);\n  else\n    emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_tai(as, PPCI_STW, r, base, ofs);\n  else\n    emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, base, ofs);\n}\n\n/* Emit a compare (for equality) with a constant operand. */\nstatic void emit_cmpi(ASMState *as, Reg r, int32_t k)\n{\n  if (checki16(k)) {\n    emit_ai(as, PPCI_CMPWI, r, k);\n  } else if (checku16(k)) {\n    emit_ai(as, PPCI_CMPLWI, r, k);\n  } else {\n    emit_ai(as, PPCI_CMPLWI, RID_TMP, k);\n    emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16));\n  }\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    emit_tai(as, PPCI_ADDI, r, r, ofs);\n    if (!checki16(ofs))\n      emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16);\n  }\n}\n\nstatic void emit_spsub(ASMState *as, int32_t ofs)\n{\n  if (ofs) {\n    emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs);\n    emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP,\n\t     CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0));\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_emit_x86.h",
    "content": "/*\n** x86/x64 instruction emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* -- Emit basic instructions --------------------------------------------- */\n\n#define MODRM(mode, r1, r2)\t((MCode)((mode)+(((r1)&7)<<3)+((r2)&7)))\n\n#if LJ_64\n#define REXRB(p, rr, rb) \\\n    { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \\\n      if (rex != 0x40) *--(p) = rex; }\n#define FORCE_REX\t\t0x200\n#define REX_64\t\t\t(FORCE_REX|0x080000)\n#define VEX_64\t\t\t0x800000\n#else\n#define REXRB(p, rr, rb)\t((void)0)\n#define FORCE_REX\t\t0\n#define REX_64\t\t\t0\n#define VEX_64\t\t\t0\n#endif\n#if LJ_GC64\n#define REX_GC64\t\tREX_64\n#else\n#define REX_GC64\t\t0\n#endif\n\n#define emit_i8(as, i)\t\t(*--as->mcp = (MCode)(i))\n#define emit_i32(as, i)\t\t(*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4)\n#define emit_u32(as, u)\t\t(*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4)\n\n#define emit_x87op(as, xo) \\\n  (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2)\n\n/* op */\nstatic LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx,\n\t\t\t\t MCode *p, int delta)\n{\n  int n = (int8_t)xo;\n  if (n == -60) {  /* VEX-encoded instruction */\n#if LJ_64\n    xo ^= (((rr>>1)&4)+((rx>>2)&2)+((rb>>3)&1))<<13;\n#endif\n    *(uint32_t *)(p+delta-5) = (uint32_t)xo;\n    return p+delta-5;\n  }\n#if defined(__GNUC__) || defined(__clang__)\n  if (__builtin_constant_p(xo) && n == -2)\n    p[delta-2] = (MCode)(xo >> 24);\n  else if (__builtin_constant_p(xo) && n == -3)\n    *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16);\n  else\n#endif\n    *(uint32_t *)(p+delta-5) = (uint32_t)xo;\n  p += n + delta;\n#if LJ_64\n  {\n    uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1);\n    if (rex != 0x40) {\n      rex |= (rr >> 16);\n      if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); }\n      else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; }\n      *--p = (MCode)rex;\n    }\n  }\n#else\n  UNUSED(rr); UNUSED(rb); UNUSED(rx);\n#endif\n  return p;\n}\n\n/* op + modrm */\n#define emit_opm(xo, mode, rr, rb, p, delta) \\\n  (p[(delta)-1] = MODRM((mode), (rr), (rb)), \\\n   emit_op((xo), (rr), (rb), 0, (p), (delta)))\n\n/* op + modrm + sib */\n#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \\\n  (p[-1] = MODRM((scale), (rx), (rb)), \\\n   p[-2] = MODRM((mode), (rr), RID_ESP), \\\n   emit_op((xo), (rr), (rb), (rx), (p), -1))\n\n/* op r1, r2 */\nstatic void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2)\n{\n  MCode *p = as->mcp;\n  as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0);\n}\n\n#if LJ_64 && defined(LUA_USE_ASSERT)\n/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */\nstatic int32_t ptr2addr(const void *p)\n{\n  lj_assertX((uintptr_t)p < (uintptr_t)0x80000000, \"pointer outside 2G range\");\n  return i32ptr(p);\n}\n#else\n#define ptr2addr(p)\t(i32ptr((p)))\n#endif\n\n/* op r, [base+ofs] */\nstatic void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs)\n{\n  MCode *p = as->mcp;\n  x86Mode mode;\n  if (ra_hasreg(rb)) {\n    if (LJ_GC64 && rb == RID_RIP) {\n      mode = XM_OFS0;\n      p -= 4;\n      *(int32_t *)p = ofs;\n    } else if (ofs == 0 && (rb&7) != RID_EBP) {\n      mode = XM_OFS0;\n    } else if (checki8(ofs)) {\n      *--p = (MCode)ofs;\n      mode = XM_OFS8;\n    } else {\n      p -= 4;\n      *(int32_t *)p = ofs;\n      mode = XM_OFS32;\n    }\n    if ((rb&7) == RID_ESP)\n      *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n  } else {\n    *(int32_t *)(p-4) = ofs;\n#if LJ_64\n    p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n    p -= 5;\n    rb = RID_ESP;\n#else\n    p -= 4;\n    rb = RID_EBP;\n#endif\n    mode = XM_OFS0;\n  }\n  as->mcp = emit_opm(xo, mode, rr, rb, p, 0);\n}\n\n/* op r, [base+idx*scale+ofs] */\nstatic void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx,\n\t\t       x86Mode scale, int32_t ofs)\n{\n  MCode *p = as->mcp;\n  x86Mode mode;\n  if (ofs == 0 && (rb&7) != RID_EBP) {\n    mode = XM_OFS0;\n  } else if (checki8(ofs)) {\n    mode = XM_OFS8;\n    *--p = (MCode)ofs;\n  } else {\n    mode = XM_OFS32;\n    p -= 4;\n    *(int32_t *)p = ofs;\n  }\n  as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p);\n}\n\n/* op r, i */\nstatic void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i)\n{\n  MCode *p = as->mcp;\n  x86Op xo;\n  if (checki8(i)) {\n    *--p = (MCode)i;\n    xo = XG_TOXOi8(xg);\n  } else {\n    p -= 4;\n    *(int32_t *)p = i;\n    xo = XG_TOXOi(xg);\n  }\n  as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0);\n}\n\n/* op [base+ofs], i */\nstatic void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs,\n\t\t       int32_t i)\n{\n  x86Op xo;\n  if (checki8(i)) {\n    emit_i8(as, i);\n    xo = XG_TOXOi8(xg);\n  } else {\n    emit_i32(as, i);\n    xo = XG_TOXOi(xg);\n  }\n  emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs);\n}\n\n#define emit_shifti(as, xg, r, i) \\\n  (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r)))\n\n/* op r, rm/mrm */\nstatic void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb)\n{\n  MCode *p = as->mcp;\n  x86Mode mode = XM_REG;\n  if (rb == RID_MRM) {\n    rb = as->mrm.base;\n    if (rb == RID_NONE) {\n      rb = RID_EBP;\n      mode = XM_OFS0;\n      p -= 4;\n      *(int32_t *)p = as->mrm.ofs;\n      if (as->mrm.idx != RID_NONE)\n\tgoto mrmidx;\n#if LJ_64\n      *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n      rb = RID_ESP;\n#endif\n    } else if (LJ_GC64 && rb == RID_RIP) {\n      lj_assertA(as->mrm.idx == RID_NONE, \"RIP-rel mrm cannot have index\");\n      mode = XM_OFS0;\n      p -= 4;\n      *(int32_t *)p = as->mrm.ofs;\n    } else {\n      if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) {\n\tmode = XM_OFS0;\n      } else if (checki8(as->mrm.ofs)) {\n\t*--p = (MCode)as->mrm.ofs;\n\tmode = XM_OFS8;\n      } else {\n\tp -= 4;\n\t*(int32_t *)p = as->mrm.ofs;\n\tmode = XM_OFS32;\n      }\n      if (as->mrm.idx != RID_NONE) {\n      mrmidx:\n\tas->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p);\n\treturn;\n      }\n      if ((rb&7) == RID_ESP)\n\t*--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);\n    }\n  }\n  as->mcp = emit_opm(xo, mode, rr, rb, p, 0);\n}\n\n/* op rm/mrm, i */\nstatic void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i)\n{\n  x86Op xo;\n  if (checki8(i)) {\n    emit_i8(as, i);\n    xo = XG_TOXOi8(xg);\n  } else {\n    emit_i32(as, i);\n    xo = XG_TOXOi(xg);\n  }\n  emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64));\n}\n\n/* -- Emit loads/stores --------------------------------------------------- */\n\n/* mov [base+ofs], i */\nstatic void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i)\n{\n  emit_i32(as, i);\n  emit_rmro(as, XO_MOVmi, 0, base, ofs);\n}\n\n/* mov [base+ofs], r */\n#define emit_movtomro(as, r, base, ofs) \\\n  emit_rmro(as, XO_MOVto, (r), (base), (ofs))\n\n/* Get/set global_State fields. */\n#define emit_opgl(as, xo, r, field) \\\n  emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field)\n#define emit_getgl(as, r, field) emit_opgl(as, XO_MOV, (r)|REX_GC64, field)\n#define emit_setgl(as, r, field) emit_opgl(as, XO_MOVto, (r)|REX_GC64, field)\n\n#define emit_setvmstate(as, i) \\\n  (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate))\n\n/* mov r, i / xor r, r */\nstatic void emit_loadi(ASMState *as, Reg r, int32_t i)\n{\n  /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP/jcc. */\n  if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP ||\n\t\t\t    (as->curins+1 < as->T->nins &&\n\t\t\t     IR(as->curins+1)->o == IR_HIOP))) &&\n\t\t!((*as->mcp == 0x0f && (as->mcp[1] & 0xf0) == XI_JCCn) ||\n\t\t  (*as->mcp & 0xf0) == XI_JCCs)) {\n    emit_rr(as, XO_ARITH(XOg_XOR), r, r);\n  } else {\n    MCode *p = as->mcp;\n    *(int32_t *)(p-4) = i;\n    p[-5] = (MCode)(XI_MOVri+(r&7));\n    p -= 5;\n    REXRB(p, 0, r);\n    as->mcp = p;\n  }\n}\n\n#if LJ_GC64\n#define dispofs(as, k) \\\n  ((intptr_t)((uintptr_t)(k) - (uintptr_t)J2GG(as->J)->dispatch))\n#define mcpofs(as, k) \\\n  ((intptr_t)((uintptr_t)(k) - (uintptr_t)as->mcp))\n#define mctopofs(as, k) \\\n  ((intptr_t)((uintptr_t)(k) - (uintptr_t)as->mctop))\n/* mov r, addr */\n#define emit_loada(as, r, addr) \\\n  emit_loadu64(as, (r), (uintptr_t)(addr))\n#else\n/* mov r, addr */\n#define emit_loada(as, r, addr) \\\n  emit_loadi(as, (r), ptr2addr((addr)))\n#endif\n\n#if LJ_64\n/* mov r, imm64 or shorter 32 bit extended load. */\nstatic void emit_loadu64(ASMState *as, Reg r, uint64_t u64)\n{\n  if (checku32(u64)) {  /* 32 bit load clears upper 32 bits. */\n    emit_loadi(as, r, (int32_t)u64);\n  } else if (checki32((int64_t)u64)) {  /* Sign-extended 32 bit load. */\n    MCode *p = as->mcp;\n    *(int32_t *)(p-4) = (int32_t)u64;\n    as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4);\n#if LJ_GC64\n  } else if (checki32(dispofs(as, u64))) {\n    emit_rmro(as, XO_LEA, r|REX_64, RID_DISPATCH, (int32_t)dispofs(as, u64));\n  } else if (checki32(mcpofs(as, u64)) && checki32(mctopofs(as, u64))) {\n    /* Since as->realign assumes the code size doesn't change, check\n    ** RIP-relative addressing reachability for both as->mcp and as->mctop.\n    */\n    emit_rmro(as, XO_LEA, r|REX_64, RID_RIP, (int32_t)mcpofs(as, u64));\n#endif\n  } else {  /* Full-size 64 bit load. */\n    MCode *p = as->mcp;\n    *(uint64_t *)(p-8) = u64;\n    p[-9] = (MCode)(XI_MOVri+(r&7));\n    p[-10] = 0x48 + ((r>>3)&1);\n    p -= 10;\n    as->mcp = p;\n  }\n}\n#endif\n\n/* op r, [addr] */\nstatic void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr)\n{\n#if LJ_GC64\n  if (checki32(dispofs(as, addr))) {\n    emit_rmro(as, xo, rr, RID_DISPATCH, (int32_t)dispofs(as, addr));\n  } else if (checki32(mcpofs(as, addr)) && checki32(mctopofs(as, addr))) {\n    emit_rmro(as, xo, rr, RID_RIP, (int32_t)mcpofs(as, addr));\n  } else if (!checki32((intptr_t)addr)) {\n    Reg ra = (rr & 15);\n    if (xo != XO_MOV) {\n      /* We can't allocate a register here. Use and restore DISPATCH. Ugly. */\n      uint64_t dispaddr = (uintptr_t)J2GG(as->J)->dispatch;\n      uint8_t i8 = xo == XO_GROUP3b ? *as->mcp++ : 0;\n      ra = RID_DISPATCH;\n      if (checku32(dispaddr)) {\n\temit_loadi(as, ra, (int32_t)dispaddr);\n      } else {  /* Full-size 64 bit load. */\n\tMCode *p = as->mcp;\n\t*(uint64_t *)(p-8) = dispaddr;\n\tp[-9] = (MCode)(XI_MOVri+(ra&7));\n\tp[-10] = 0x48 + ((ra>>3)&1);\n\tp -= 10;\n\tas->mcp = p;\n      }\n      if (xo == XO_GROUP3b) emit_i8(as, i8);\n    }\n    emit_rmro(as, xo, rr, ra, 0);\n    emit_loadu64(as, ra, (uintptr_t)addr);\n  } else\n#endif\n  {\n    MCode *p = as->mcp;\n    *(int32_t *)(p-4) = ptr2addr(addr);\n#if LJ_64\n    p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);\n    as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5);\n#else\n    as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4);\n#endif\n  }\n}\n\n/* Load 64 bit IR constant into register. */\nstatic void emit_loadk64(ASMState *as, Reg r, IRIns *ir)\n{\n  Reg r64;\n  x86Op xo;\n  const uint64_t *k = &ir_k64(ir)->u64;\n  if (rset_test(RSET_FPR, r)) {\n    r64 = r;\n    xo = XO_MOVSD;\n  } else {\n    r64 = r | REX_64;\n    xo = XO_MOV;\n  }\n  if (*k == 0) {\n    emit_rr(as, rset_test(RSET_FPR, r) ? XO_XORPS : XO_ARITH(XOg_XOR), r, r);\n#if LJ_GC64\n  } else if (checki32((intptr_t)k) || checki32(dispofs(as, k)) ||\n\t     (checki32(mcpofs(as, k)) && checki32(mctopofs(as, k)))) {\n    emit_rma(as, xo, r64, k);\n  } else {\n    if (ir->i) {\n      lj_assertA(*k == *(uint64_t*)(as->mctop - ir->i),\n\t\t \"bad interned 64 bit constant\");\n    } else if (as->curins <= as->stopins && rset_test(RSET_GPR, r)) {\n      emit_loadu64(as, r, *k);\n      return;\n    } else {\n      /* If all else fails, add the FP constant at the MCode area bottom. */\n      while ((uintptr_t)as->mcbot & 7) *as->mcbot++ = XI_INT3;\n      *(uint64_t *)as->mcbot = *k;\n      ir->i = (int32_t)(as->mctop - as->mcbot);\n      as->mcbot += 8;\n      as->mclim = as->mcbot + MCLIM_REDZONE;\n      lj_mcode_commitbot(as->J, as->mcbot);\n    }\n    emit_rmro(as, xo, r64, RID_RIP, (int32_t)mcpofs(as, as->mctop - ir->i));\n#else\n  } else {\n    emit_rma(as, xo, r64, k);\n#endif\n  }\n}\n\n/* -- Emit control-flow instructions -------------------------------------- */\n\n/* Label for short jumps. */\ntypedef MCode *MCLabel;\n\n#if LJ_32 && LJ_HASFFI\n/* jmp short target */\nstatic void emit_sjmp(ASMState *as, MCLabel target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(delta == (int8_t)delta, \"short jump target out of range\");\n  p[-1] = (MCode)(int8_t)delta;\n  p[-2] = XI_JMPs;\n  as->mcp = p - 2;\n}\n#endif\n\n/* jcc short target */\nstatic void emit_sjcc(ASMState *as, int cc, MCLabel target)\n{\n  MCode *p = as->mcp;\n  ptrdiff_t delta = target - p;\n  lj_assertA(delta == (int8_t)delta, \"short jump target out of range\");\n  p[-1] = (MCode)(int8_t)delta;\n  p[-2] = (MCode)(XI_JCCs+(cc&15));\n  as->mcp = p - 2;\n}\n\n/* jcc short (pending target) */\nstatic MCLabel emit_sjcc_label(ASMState *as, int cc)\n{\n  MCode *p = as->mcp;\n  p[-1] = 0;\n  p[-2] = (MCode)(XI_JCCs+(cc&15));\n  as->mcp = p - 2;\n  return p;\n}\n\n/* Fixup jcc short target. */\nstatic void emit_sfixup(ASMState *as, MCLabel source)\n{\n  source[-1] = (MCode)(as->mcp-source);\n}\n\n/* Return label pointing to current PC. */\n#define emit_label(as)\t\t((as)->mcp)\n\n/* Compute relative 32 bit offset for jump and call instructions. */\nstatic LJ_AINLINE int32_t jmprel(jit_State *J, MCode *p, MCode *target)\n{\n  ptrdiff_t delta = target - p;\n  UNUSED(J);\n  lj_assertJ(delta == (int32_t)delta, \"jump target out of range\");\n  return (int32_t)delta;\n}\n\n/* jcc target */\nstatic void emit_jcc(ASMState *as, int cc, MCode *target)\n{\n  MCode *p = as->mcp;\n  *(int32_t *)(p-4) = jmprel(as->J, p, target);\n  p[-5] = (MCode)(XI_JCCn+(cc&15));\n  p[-6] = 0x0f;\n  as->mcp = p - 6;\n}\n\n/* jmp target */\nstatic void emit_jmp(ASMState *as, MCode *target)\n{\n  MCode *p = as->mcp;\n  *(int32_t *)(p-4) = jmprel(as->J, p, target);\n  p[-5] = XI_JMP;\n  as->mcp = p - 5;\n}\n\n/* call target */\nstatic void emit_call_(ASMState *as, MCode *target)\n{\n  MCode *p = as->mcp;\n#if LJ_64\n  if (target-p != (int32_t)(target-p)) {\n    /* Assumes RID_RET is never an argument to calls and always clobbered. */\n    emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET);\n    emit_loadu64(as, RID_RET, (uint64_t)target);\n    return;\n  }\n#endif\n  *(int32_t *)(p-4) = jmprel(as->J, p, target);\n  p[-5] = XI_CALL;\n  as->mcp = p - 5;\n}\n\n#define emit_call(as, f)\temit_call_(as, (MCode *)(void *)(f))\n\n/* -- Emit generic operations --------------------------------------------- */\n\n/* Use 64 bit operations to handle 64 bit IR types. */\n#if LJ_64\n#define REX_64IR(ir, r)\t\t((r) + (irt_is64((ir)->t) ? REX_64 : 0))\n#define VEX_64IR(ir, r)\t\t((r) + (irt_is64((ir)->t) ? VEX_64 : 0))\n#else\n#define REX_64IR(ir, r)\t\t(r)\n#define VEX_64IR(ir, r)\t\t(r)\n#endif\n\n/* Generic move between two regs. */\nstatic void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)\n{\n  UNUSED(ir);\n  if (dst < RID_MAX_GPR)\n    emit_rr(as, XO_MOV, REX_64IR(ir, dst), src);\n  else\n    emit_rr(as, XO_MOVAPS, dst, src);\n}\n\n/* Generic load of register with base and (small) offset address. */\nstatic void emit_loadofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_rmro(as, XO_MOV, REX_64IR(ir, r), base, ofs);\n  else\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSD : XO_MOVSS, r, base, ofs);\n}\n\n/* Generic store of register with base and (small) offset address. */\nstatic void emit_storeofs(ASMState *as, IRIns *ir, Reg r, Reg base, int32_t ofs)\n{\n  if (r < RID_MAX_GPR)\n    emit_rmro(as, XO_MOVto, REX_64IR(ir, r), base, ofs);\n  else\n    emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, base, ofs);\n}\n\n/* Add offset to pointer. */\nstatic void emit_addptr(ASMState *as, Reg r, int32_t ofs)\n{\n  if (ofs) {\n    emit_gri(as, XG_ARITHi(XOg_ADD), r|REX_GC64, ofs);\n  }\n}\n\n#define emit_spsub(as, ofs)\temit_addptr(as, RID_ESP|REX_64, -(ofs))\n\n/* Prefer rematerialization of BASE/L from global_State over spills. */\n#define emit_canremat(ref)\t((ref) <= REF_BASE)\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_err.c",
    "content": "/*\n** Error handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_err_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_func.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_ff.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strfmt.h\"\n\n/*\n** LuaJIT can either use internal or external frame unwinding:\n**\n** - Internal frame unwinding (INT) is free-standing and doesn't require\n**   any OS or library support.\n**\n** - External frame unwinding (EXT) uses the system-provided unwind handler.\n**\n** Pros and Cons:\n**\n** - EXT requires unwind tables for *all* functions on the C stack between\n**   the pcall/catch and the error/throw. C modules used by Lua code can\n**   throw errors, so these need to have unwind tables, too. Transitively\n**   this applies to all system libraries used by C modules -- at least\n**   when they have callbacks which may throw an error.\n**\n** - INT is faster when actually throwing errors, but this happens rarely.\n**   Setting up error handlers is zero-cost in any case.\n**\n** - INT needs to save *all* callee-saved registers when entering the\n**   interpreter. EXT only needs to save those actually used inside the\n**   interpreter. JIT-compiled code may need to save some more.\n**\n** - EXT provides full interoperability with C++ exceptions. You can throw\n**   Lua errors or C++ exceptions through a mix of Lua frames and C++ frames.\n**   C++ destructors are called as needed. C++ exceptions caught by pcall\n**   are converted to the string \"C++ exception\". Lua errors can be caught\n**   with catch (...) in C++.\n**\n** - INT has only limited support for automatically catching C++ exceptions\n**   on POSIX systems using DWARF2 stack unwinding. Other systems may use\n**   the wrapper function feature. Lua errors thrown through C++ frames\n**   cannot be caught by C++ code and C++ destructors are not run.\n**\n** - EXT can handle errors from internal helper functions that are called\n**   from JIT-compiled code (except for Windows/x86 and 32 bit ARM).\n**   INT has no choice but to call the panic handler, if this happens.\n**   Note: this is mainly relevant for out-of-memory errors.\n**\n** EXT is the default on all systems where the toolchain produces unwind\n** tables by default (*). This is hard-coded and/or detected in src/Makefile.\n** You can thwart the detection with: TARGET_XCFLAGS=-DLUAJIT_UNWIND_INTERNAL\n**\n** INT is the default on all other systems.\n**\n** EXT can be manually enabled for toolchains that are able to produce\n** conforming unwind tables:\n**   \"TARGET_XCFLAGS=-funwind-tables -DLUAJIT_UNWIND_EXTERNAL\"\n** As explained above, *all* C code used directly or indirectly by LuaJIT\n** must be compiled with -funwind-tables (or -fexceptions). C++ code must\n** *not* be compiled with -fno-exceptions.\n**\n** If you're unsure whether error handling inside the VM works correctly,\n** try running this and check whether it prints \"OK\":\n**\n**   luajit -e \"print(select(2, load('OK')):match('OK'))\"\n**\n** (*) Originally, toolchains only generated unwind tables for C++ code. For\n** interoperability reasons, this can be manually enabled for plain C code,\n** too (with -funwind-tables). With the introduction of the x64 architecture,\n** the corresponding POSIX and Windows ABIs mandated unwind tables for all\n** code. Over the following years most desktop and server platforms have\n** enabled unwind tables by default on all architectures. OTOH mobile and\n** embedded platforms do not consistently mandate unwind tables.\n*/\n\n/* -- Error messages ------------------------------------------------------ */\n\n/* Error message strings. */\nLJ_DATADEF const char *lj_err_allmsg =\n#define ERRDEF(name, msg)\tmsg \"\\0\"\n#include \"lj_errmsg.h\"\n;\n\n/* -- Internal frame unwinding -------------------------------------------- */\n\n/* Unwind Lua stack and move error message to new top. */\nLJ_NOINLINE static void unwindstack(lua_State *L, TValue *top)\n{\n  lj_func_closeuv(L, top);\n  if (top < L->top-1) {\n    copyTV(L, top, L->top-1);\n    L->top = top+1;\n  }\n  lj_state_relimitstack(L);\n}\n\n/* Unwind until stop frame. Optionally cleanup frames. */\nstatic void *err_unwind(lua_State *L, void *stopcf, int errcode)\n{\n  TValue *frame = L->base-1;\n  void *cf = L->cframe;\n  while (cf) {\n    int32_t nres = cframe_nres(cframe_raw(cf));\n    if (nres < 0) {  /* C frame without Lua frame? */\n      TValue *top = restorestack(L, -nres);\n      if (frame < top) {  /* Frame reached? */\n\tif (errcode) {\n\t  L->base = frame+1;\n\t  L->cframe = cframe_prev(cf);\n\t  unwindstack(L, top);\n\t}\n\treturn cf;\n      }\n    }\n    if (frame <= tvref(L->stack)+LJ_FR2)\n      break;\n    switch (frame_typep(frame)) {\n    case FRAME_LUA:  /* Lua frame. */\n    case FRAME_LUAP:\n      frame = frame_prevl(frame);\n      break;\n    case FRAME_C:  /* C frame. */\n    unwind_c:\n#if LJ_UNWIND_EXT\n      if (errcode) {\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cframe_prev(cf);\n\tunwindstack(L, frame - LJ_FR2);\n      } else if (cf != stopcf) {\n\tcf = cframe_prev(cf);\n\tframe = frame_prevd(frame);\n\tbreak;\n      }\n      return NULL;  /* Continue unwinding. */\n#else\n      UNUSED(stopcf);\n      cf = cframe_prev(cf);\n      frame = frame_prevd(frame);\n      break;\n#endif\n    case FRAME_CP:  /* Protected C frame. */\n      if (cframe_canyield(cf)) {  /* Resume? */\n\tif (errcode) {\n\t  hook_leave(G(L));  /* Assumes nobody uses coroutines inside hooks. */\n\t  L->cframe = NULL;\n\t  L->status = (uint8_t)errcode;\n\t}\n\treturn cf;\n      }\n      if (errcode) {\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cframe_prev(cf);\n\tunwindstack(L, frame - LJ_FR2);\n      }\n      return cf;\n    case FRAME_CONT:  /* Continuation frame. */\n      if (frame_iscont_fficb(frame))\n\tgoto unwind_c;\n      /* fallthrough */\n    case FRAME_VARG:  /* Vararg frame. */\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_PCALL:  /* FF pcall() frame. */\n    case FRAME_PCALLH:  /* FF pcall() frame inside hook. */\n      if (errcode) {\n\tif (errcode == LUA_YIELD) {\n\t  frame = frame_prevd(frame);\n\t  break;\n\t}\n\tif (frame_typep(frame) == FRAME_PCALL)\n\t  hook_leave(G(L));\n\tL->base = frame_prevd(frame) + 1;\n\tL->cframe = cf;\n\tunwindstack(L, L->base);\n      }\n      return (void *)((intptr_t)cf | CFRAME_UNWIND_FF);\n    }\n  }\n  /* No C frame. */\n  if (errcode) {\n    L->base = tvref(L->stack)+1+LJ_FR2;\n    L->cframe = NULL;\n    unwindstack(L, L->base);\n    if (G(L)->panic)\n      G(L)->panic(L);\n    exit(EXIT_FAILURE);\n  }\n  return L;  /* Anything non-NULL will do. */\n}\n\n/* -- External frame unwinding -------------------------------------------- */\n\n#if LJ_ABI_WIN\n\n/*\n** Someone in Redmond owes me several days of my life. A lot of this is\n** undocumented or just plain wrong on MSDN. Some of it can be gathered\n** from 3rd party docs or must be found by trial-and-error. They really\n** don't want you to write your own language-specific exception handler\n** or to interact gracefully with MSVC. :-(\n**\n** Apparently MSVC doesn't call C++ destructors for foreign exceptions\n** unless you compile your C++ code with /EHa. Unfortunately this means\n** catch (...) also catches things like access violations. The use of\n** _set_se_translator doesn't really help, because it requires /EHa, too.\n*/\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#if LJ_TARGET_X86\ntypedef void *UndocumentedDispatcherContext;  /* Unused on x86. */\n#else\n/* Taken from: http://www.nynaeve.net/?p=99 */\ntypedef struct UndocumentedDispatcherContext {\n  ULONG64 ControlPc;\n  ULONG64 ImageBase;\n  PRUNTIME_FUNCTION FunctionEntry;\n  ULONG64 EstablisherFrame;\n  ULONG64 TargetIp;\n  PCONTEXT ContextRecord;\n  void (*LanguageHandler)(void);\n  PVOID HandlerData;\n  PUNWIND_HISTORY_TABLE HistoryTable;\n  ULONG ScopeIndex;\n  ULONG Fill0;\n} UndocumentedDispatcherContext;\n#endif\n\n/* Another wild guess. */\nextern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow);\n\n#if LJ_TARGET_X64 && defined(MINGW_SDK_INIT)\n/* Workaround for broken MinGW64 declaration. */\nVOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm(\"RtlUnwindEx\");\n#define RtlUnwindEx RtlUnwindEx_FIXED\n#endif\n\n#define LJ_MSVC_EXCODE\t\t((DWORD)0xe06d7363)\n#define LJ_GCC_EXCODE\t\t((DWORD)0x20474343)\n\n#define LJ_EXCODE\t\t((DWORD)0xe24c4a00)\n#define LJ_EXCODE_MAKE(c)\t(LJ_EXCODE | (DWORD)(c))\n#define LJ_EXCODE_CHECK(cl)\t(((cl) ^ LJ_EXCODE) <= 0xff)\n#define LJ_EXCODE_ERRCODE(cl)\t((int)((cl) & 0xff))\n\n/* Windows exception handler for interpreter frame. */\nLJ_FUNCA int lj_err_unwind_win(EXCEPTION_RECORD *rec,\n  void *f, CONTEXT *ctx, UndocumentedDispatcherContext *dispatch)\n{\n#if LJ_TARGET_X86\n  void *cf = (char *)f - CFRAME_OFS_SEH;\n#else\n  void *cf = f;\n#endif\n  lua_State *L = cframe_L(cf);\n  int errcode = LJ_EXCODE_CHECK(rec->ExceptionCode) ?\n\t\tLJ_EXCODE_ERRCODE(rec->ExceptionCode) : LUA_ERRRUN;\n  if ((rec->ExceptionFlags & 6)) {  /* EH_UNWINDING|EH_EXIT_UNWIND */\n    /* Unwind internal frames. */\n    err_unwind(L, cf, errcode);\n  } else {\n    void *cf2 = err_unwind(L, cf, 0);\n    if (cf2) {  /* We catch it, so start unwinding the upper frames. */\n      if (rec->ExceptionCode == LJ_MSVC_EXCODE ||\n\t  rec->ExceptionCode == LJ_GCC_EXCODE) {\n#if !LJ_TARGET_CYGWIN\n\t__DestructExceptionObject(rec, 1);\n#endif\n\tsetstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n      } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) {\n\t/* Don't catch access violations etc. */\n\treturn 1;  /* ExceptionContinueSearch */\n      }\n#if LJ_TARGET_X86\n      UNUSED(ctx);\n      UNUSED(dispatch);\n      /* Call all handlers for all lower C frames (including ourselves) again\n      ** with EH_UNWINDING set. Then call the specified function, passing cf\n      ** and errcode.\n      */\n      lj_vm_rtlunwind(cf, (void *)rec,\n\t(cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ?\n\t(void *)lj_vm_unwind_ff : (void *)lj_vm_unwind_c, errcode);\n      /* lj_vm_rtlunwind does not return. */\n#else\n      /* Unwind the stack and call all handlers for all lower C frames\n      ** (including ourselves) again with EH_UNWINDING set. Then set\n      ** stack pointer = cf, result = errcode and jump to the specified target.\n      */\n      RtlUnwindEx(cf, (void *)((cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ?\n\t\t\t       lj_vm_unwind_ff_eh :\n\t\t\t       lj_vm_unwind_c_eh),\n\t\t  rec, (void *)(uintptr_t)errcode, ctx, dispatch->HistoryTable);\n      /* RtlUnwindEx should never return. */\n#endif\n    }\n  }\n  return 1;  /* ExceptionContinueSearch */\n}\n\n#if LJ_UNWIND_JIT\n\n#if LJ_TARGET_X64\n#define CONTEXT_REG_PC\tRip\n#elif LJ_TARGET_ARM64\n#define CONTEXT_REG_PC\tPc\n#else\n#error \"NYI: Windows arch-specific unwinder for JIT-compiled code\"\n#endif\n\n/* Windows unwinder for JIT-compiled code. */\nstatic void err_unwind_win_jit(global_State *g, int errcode)\n{\n  CONTEXT ctx;\n  UNWIND_HISTORY_TABLE hist;\n\n  memset(&hist, 0, sizeof(hist));\n  RtlCaptureContext(&ctx);\n  while (1) {\n    uintptr_t frame, base, addr = ctx.CONTEXT_REG_PC;\n    void *hdata;\n    PRUNTIME_FUNCTION func = RtlLookupFunctionEntry(addr, &base, &hist);\n    if (!func) {  /* Found frame without .pdata: must be JIT-compiled code. */\n      ExitNo exitno;\n      uintptr_t stub = lj_trace_unwind(G2J(g), addr - sizeof(MCode), &exitno);\n      if (stub) {  /* Jump to side exit to unwind the trace. */\n\tctx.CONTEXT_REG_PC = stub;\n\tG2J(g)->exitcode = errcode;\n\tRtlRestoreContext(&ctx, NULL);  /* Does not return. */\n      }\n      break;\n    }\n    RtlVirtualUnwind(UNW_FLAG_NHANDLER, base, addr, func,\n\t\t     &ctx, &hdata, &frame, NULL);\n    if (!addr) break;\n  }\n  /* Unwinding failed, if we end up here. */\n}\n#endif\n\n/* Raise Windows exception. */\nstatic void err_raise_ext(global_State *g, int errcode)\n{\n#if LJ_UNWIND_JIT\n  if (tvref(g->jit_base)) {\n    err_unwind_win_jit(g, errcode);\n    return;  /* Unwinding failed. */\n  }\n#elif LJ_HASJIT\n  /* Cannot catch on-trace errors for Windows/x86 SEH. Unwind to interpreter. */\n  setmref(g->jit_base, NULL);\n#endif\n  UNUSED(g);\n  RaiseException(LJ_EXCODE_MAKE(errcode), 1 /* EH_NONCONTINUABLE */, 0, NULL);\n}\n\n#elif !LJ_NO_UNWIND && (defined(__GNUC__) || defined(__clang__))\n\n/*\n** We have to use our own definitions instead of the mandatory (!) unwind.h,\n** since various OS, distros and compilers mess up the header installation.\n*/\n\ntypedef struct _Unwind_Context _Unwind_Context;\n\n#define _URC_OK\t\t\t0\n#define _URC_FATAL_PHASE2_ERROR\t2\n#define _URC_FATAL_PHASE1_ERROR\t3\n#define _URC_HANDLER_FOUND\t6\n#define _URC_INSTALL_CONTEXT\t7\n#define _URC_CONTINUE_UNWIND\t8\n#define _URC_FAILURE\t\t9\n\n#define LJ_UEXCLASS\t\t0x4c55414a49543200ULL\t/* LUAJIT2\\0 */\n#define LJ_UEXCLASS_MAKE(c)\t(LJ_UEXCLASS | (uint64_t)(c))\n#define LJ_UEXCLASS_CHECK(cl)\t(((cl) ^ LJ_UEXCLASS) <= 0xff)\n#define LJ_UEXCLASS_ERRCODE(cl)\t((int)((cl) & 0xff))\n\n#if !LJ_TARGET_ARM\n\ntypedef struct _Unwind_Exception\n{\n  uint64_t exclass;\n  void (*excleanup)(int, struct _Unwind_Exception *);\n  uintptr_t p1, p2;\n} __attribute__((__aligned__)) _Unwind_Exception;\n#define UNWIND_EXCEPTION_TYPE\t_Unwind_Exception\n\nextern uintptr_t _Unwind_GetCFA(_Unwind_Context *);\nextern void _Unwind_SetGR(_Unwind_Context *, int, uintptr_t);\nextern uintptr_t _Unwind_GetIP(_Unwind_Context *);\nextern void _Unwind_SetIP(_Unwind_Context *, uintptr_t);\nextern void _Unwind_DeleteException(_Unwind_Exception *);\nextern int _Unwind_RaiseException(_Unwind_Exception *);\n\n#define _UA_SEARCH_PHASE\t1\n#define _UA_CLEANUP_PHASE\t2\n#define _UA_HANDLER_FRAME\t4\n#define _UA_FORCE_UNWIND\t8\n\n/* DWARF2 personality handler referenced from interpreter .eh_frame. */\nLJ_FUNCA int lj_err_unwind_dwarf(int version, int actions,\n  uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx)\n{\n  void *cf;\n  lua_State *L;\n  if (version != 1)\n    return _URC_FATAL_PHASE1_ERROR;\n  cf = (void *)_Unwind_GetCFA(ctx);\n  L = cframe_L(cf);\n  if ((actions & _UA_SEARCH_PHASE)) {\n#if LJ_UNWIND_EXT\n    if (err_unwind(L, cf, 0) == NULL)\n      return _URC_CONTINUE_UNWIND;\n#endif\n    if (!LJ_UEXCLASS_CHECK(uexclass)) {\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n    }\n    return _URC_HANDLER_FOUND;\n  }\n  if ((actions & _UA_CLEANUP_PHASE)) {\n    int errcode;\n    if (LJ_UEXCLASS_CHECK(uexclass)) {\n      errcode = LJ_UEXCLASS_ERRCODE(uexclass);\n    } else {\n      if ((actions & _UA_HANDLER_FRAME))\n\t_Unwind_DeleteException(uex);\n      errcode = LUA_ERRRUN;\n    }\n#if LJ_UNWIND_EXT\n    cf = err_unwind(L, cf, errcode);\n    if ((actions & _UA_FORCE_UNWIND)) {\n      return _URC_CONTINUE_UNWIND;\n    } else if (cf) {\n      _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);\n      _Unwind_SetIP(ctx, (uintptr_t)(cframe_unwind_ff(cf) ?\n\t\t\t\t     lj_vm_unwind_ff_eh :\n\t\t\t\t     lj_vm_unwind_c_eh));\n      return _URC_INSTALL_CONTEXT;\n    }\n#if LJ_TARGET_X86ORX64\n    else if ((actions & _UA_HANDLER_FRAME)) {\n      /* Workaround for ancient libgcc bug. Still present in RHEL 5.5. :-/\n      ** Real fix: http://gcc.gnu.org/viewcvs/trunk/gcc/unwind-dw2.c?r1=121165&r2=124837&pathrev=153877&diff_format=h\n      */\n      _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);\n      _Unwind_SetIP(ctx, (uintptr_t)lj_vm_unwind_rethrow);\n      return _URC_INSTALL_CONTEXT;\n    }\n#endif\n#else\n    /* This is not the proper way to escape from the unwinder. We get away with\n    ** it on non-x64 because the interpreter restores all callee-saved regs.\n    */\n    lj_err_throw(L, errcode);\n#if LJ_TARGET_X64\n#error \"Broken build system -- only use the provided Makefiles!\"\n#endif\n#endif\n  }\n  return _URC_CONTINUE_UNWIND;\n}\n\n#if LJ_UNWIND_EXT && defined(LUA_USE_ASSERT)\nstruct dwarf_eh_bases { void *tbase, *dbase, *func; };\nextern const void *_Unwind_Find_FDE(void *pc, struct dwarf_eh_bases *bases);\n\n/* Verify that external error handling actually has a chance to work. */\nvoid lj_err_verify(void)\n{\n  struct dwarf_eh_bases ehb;\n  lj_assertX(_Unwind_Find_FDE((void *)lj_err_throw, &ehb), \"broken build: external frame unwinding enabled, but missing -funwind-tables\");\n  /* Check disabled, because of broken Fedora/ARM64. See #722.\n  lj_assertX(_Unwind_Find_FDE((void *)_Unwind_RaiseException, &ehb), \"broken build: external frame unwinding enabled, but system libraries have no unwind tables\");\n  */\n}\n#endif\n\n#if LJ_UNWIND_JIT\n/* DWARF2 personality handler for JIT-compiled code. */\nstatic int err_unwind_jit(int version, int actions,\n  uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx)\n{\n  /* NYI: FFI C++ exception interoperability. */\n  if (version != 1 || !LJ_UEXCLASS_CHECK(uexclass))\n    return _URC_FATAL_PHASE1_ERROR;\n  if ((actions & _UA_SEARCH_PHASE)) {\n    return _URC_HANDLER_FOUND;\n  }\n  if ((actions & _UA_CLEANUP_PHASE)) {\n    global_State *g = *(global_State **)(uex+1);\n    ExitNo exitno;\n    uintptr_t addr = _Unwind_GetIP(ctx);  /* Return address _after_ call. */\n    uintptr_t stub = lj_trace_unwind(G2J(g), addr - sizeof(MCode), &exitno);\n    lj_assertG(tvref(g->jit_base), \"unexpected throw across mcode frame\");\n    if (stub) {  /* Jump to side exit to unwind the trace. */\n      G2J(g)->exitcode = LJ_UEXCLASS_ERRCODE(uexclass);\n#ifdef LJ_TARGET_MIPS\n      _Unwind_SetGR(ctx, 4, stub);\n      _Unwind_SetGR(ctx, 5, exitno);\n      _Unwind_SetIP(ctx, (uintptr_t)(void *)lj_vm_unwind_stub);\n#else\n      _Unwind_SetIP(ctx, stub);\n#endif\n      return _URC_INSTALL_CONTEXT;\n    }\n    return _URC_FATAL_PHASE2_ERROR;\n  }\n  return _URC_FATAL_PHASE1_ERROR;\n}\n\n/* DWARF2 template frame info for JIT-compiled code.\n**\n** After copying the template to the start of the mcode segment,\n** the frame handler function and the code size is patched.\n** The frame handler always installs a new context to jump to the exit,\n** so don't bother to add any unwind opcodes.\n*/\nstatic const uint8_t err_frame_jit_template[] = {\n#if LJ_BE\n  0,0,0,\n#endif\n  LJ_64 ? 0x1c : 0x14,  /* CIE length. */\n#if LJ_LE\n  0,0,0,\n#endif\n  0,0,0,0, 1, 'z','P','R',0,  /* CIE mark, CIE version, augmentation. */\n  1, LJ_64 ? 0x78 : 0x7c, LJ_TARGET_EHRAREG,  /* Code/data align, RA. */\n#if LJ_64\n  10, 0, 0,0,0,0,0,0,0,0, 0x1b,  /* Aug. data ABS handler, PCREL|SDATA4 code. */\n  0,0,0,0,0,  /* Alignment. */\n#else\n  6, 0, 0,0,0,0, 0x1b,  /* Aug. data ABS handler, PCREL|SDATA4 code. */\n  0,  /* Alignment. */\n#endif\n#if LJ_BE\n  0,0,0,\n#endif\n  LJ_64 ? 0x14 : 0x10,  /* FDE length. */\n  0,0,0,\n  LJ_64 ? 0x24 : 0x1c,  /* CIE offset. */\n  0,0,0,\n  LJ_64 ? 0x14 : 0x10,  /* Code offset. After Final FDE. */\n#if LJ_LE\n  0,0,0,\n#endif\n  0,0,0,0, 0, 0,0,0, /* Code size, augmentation length, alignment. */\n#if LJ_64\n  0,0,0,0,  /* Alignment. */\n#endif\n  0,0,0,0  /* Final FDE. */\n};\n\n#define ERR_FRAME_JIT_OFS_HANDLER\t0x12\n#define ERR_FRAME_JIT_OFS_FDE\t\t(LJ_64 ? 0x20 : 0x18)\n#define ERR_FRAME_JIT_OFS_CODE_SIZE\t(LJ_64 ? 0x2c : 0x24)\n#if LJ_TARGET_OSX\n#define ERR_FRAME_JIT_OFS_REGISTER\tERR_FRAME_JIT_OFS_FDE\n#else\n#define ERR_FRAME_JIT_OFS_REGISTER\t0\n#endif\n\nextern void __register_frame(const void *);\nextern void __deregister_frame(const void *);\n\nuint8_t *lj_err_register_mcode(void *base, size_t sz, uint8_t *info)\n{\n  void **handler;\n  memcpy(info, err_frame_jit_template, sizeof(err_frame_jit_template));\n  handler = (void *)err_unwind_jit;\n  memcpy(info + ERR_FRAME_JIT_OFS_HANDLER, &handler, sizeof(handler));\n  *(uint32_t *)(info + ERR_FRAME_JIT_OFS_CODE_SIZE) =\n    (uint32_t)(sz - sizeof(err_frame_jit_template) - (info - (uint8_t *)base));\n  __register_frame(info + ERR_FRAME_JIT_OFS_REGISTER);\n#ifdef LUA_USE_ASSERT\n  {\n    struct dwarf_eh_bases ehb;\n    lj_assertX(_Unwind_Find_FDE(info + sizeof(err_frame_jit_template)+1, &ehb),\n\t       \"bad JIT unwind table registration\");\n  }\n#endif\n  return info + sizeof(err_frame_jit_template);\n}\n\nvoid lj_err_deregister_mcode(void *base, size_t sz, uint8_t *info)\n{\n  UNUSED(base); UNUSED(sz);\n  __deregister_frame(info + ERR_FRAME_JIT_OFS_REGISTER);\n}\n#endif\n\n#else /* LJ_TARGET_ARM */\n\n#define _US_VIRTUAL_UNWIND_FRAME\t0\n#define _US_UNWIND_FRAME_STARTING\t1\n#define _US_ACTION_MASK\t\t\t3\n#define _US_FORCE_UNWIND\t\t8\n\ntypedef struct _Unwind_Control_Block _Unwind_Control_Block;\n#define UNWIND_EXCEPTION_TYPE\t_Unwind_Control_Block\n\nstruct _Unwind_Control_Block {\n  uint64_t exclass;\n  uint32_t misc[20];\n};\n\nextern int _Unwind_RaiseException(_Unwind_Control_Block *);\nextern int __gnu_unwind_frame(_Unwind_Control_Block *, _Unwind_Context *);\nextern int _Unwind_VRS_Set(_Unwind_Context *, int, uint32_t, int, void *);\nextern int _Unwind_VRS_Get(_Unwind_Context *, int, uint32_t, int, void *);\n\nstatic inline uint32_t _Unwind_GetGR(_Unwind_Context *ctx, int r)\n{\n  uint32_t v;\n  _Unwind_VRS_Get(ctx, 0, r, 0, &v);\n  return v;\n}\n\nstatic inline void _Unwind_SetGR(_Unwind_Context *ctx, int r, uint32_t v)\n{\n  _Unwind_VRS_Set(ctx, 0, r, 0, &v);\n}\n\nextern void lj_vm_unwind_ext(void);\n\n/* ARM unwinder personality handler referenced from interpreter .ARM.extab. */\nLJ_FUNCA int lj_err_unwind_arm(int state, _Unwind_Control_Block *ucb,\n\t\t\t       _Unwind_Context *ctx)\n{\n  void *cf = (void *)_Unwind_GetGR(ctx, 13);\n  lua_State *L = cframe_L(cf);\n  int errcode;\n\n  switch ((state & _US_ACTION_MASK)) {\n  case _US_VIRTUAL_UNWIND_FRAME:\n    if ((state & _US_FORCE_UNWIND)) break;\n    return _URC_HANDLER_FOUND;\n  case _US_UNWIND_FRAME_STARTING:\n    if (LJ_UEXCLASS_CHECK(ucb->exclass)) {\n      errcode = LJ_UEXCLASS_ERRCODE(ucb->exclass);\n    } else {\n      errcode = LUA_ERRRUN;\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));\n    }\n    cf = err_unwind(L, cf, errcode);\n    if ((state & _US_FORCE_UNWIND) || cf == NULL) break;\n    _Unwind_SetGR(ctx, 15, (uint32_t)lj_vm_unwind_ext);\n    _Unwind_SetGR(ctx, 0, (uint32_t)ucb);\n    _Unwind_SetGR(ctx, 1, (uint32_t)errcode);\n    _Unwind_SetGR(ctx, 2, cframe_unwind_ff(cf) ?\n\t\t\t    (uint32_t)lj_vm_unwind_ff_eh :\n\t\t\t    (uint32_t)lj_vm_unwind_c_eh);\n    return _URC_INSTALL_CONTEXT;\n  default:\n    return _URC_FAILURE;\n  }\n  if (__gnu_unwind_frame(ucb, ctx) != _URC_OK)\n    return _URC_FAILURE;\n#ifdef LUA_USE_ASSERT\n  /* We should never get here unless this is a forced unwind aka backtrace. */\n  if (_Unwind_GetGR(ctx, 0) == 0xff33aa77) {\n    _Unwind_SetGR(ctx, 0, 0xff33aa88);\n  }\n#endif\n  return _URC_CONTINUE_UNWIND;\n}\n\n#if LJ_UNWIND_EXT && defined(LUA_USE_ASSERT)\ntypedef int (*_Unwind_Trace_Fn)(_Unwind_Context *, void *);\nextern int _Unwind_Backtrace(_Unwind_Trace_Fn, void *);\n\nstatic int err_verify_bt(_Unwind_Context *ctx, int *got)\n{\n  if (_Unwind_GetGR(ctx, 0) == 0xff33aa88) { *got = 2; }\n  else if (*got == 0) { *got = 1; _Unwind_SetGR(ctx, 0, 0xff33aa77); }\n  return _URC_OK;\n}\n\n/* Verify that external error handling actually has a chance to work. */\nvoid lj_err_verify(void)\n{\n  int got = 0;\n  _Unwind_Backtrace((_Unwind_Trace_Fn)err_verify_bt, &got);\n  lj_assertX(got == 2, \"broken build: external frame unwinding enabled, but missing -funwind-tables\");\n}\n#endif\n\n/*\n** Note: LJ_UNWIND_JIT is not implemented for 32 bit ARM.\n**\n** The quirky ARM unwind API doesn't have __register_frame().\n** A potential workaround might involve _Unwind_Backtrace.\n** But most 32 bit ARM targets don't qualify for LJ_UNWIND_EXT, anyway,\n** since they are built without unwind tables by default.\n*/\n\n#endif /* LJ_TARGET_ARM */\n\n\n#if LJ_UNWIND_EXT\nstatic __thread struct {\n  UNWIND_EXCEPTION_TYPE ex;\n  global_State *g;\n} static_uex;\n\n/* Raise external exception. */\nstatic void err_raise_ext(global_State *g, int errcode)\n{\n  memset(&static_uex, 0, sizeof(static_uex));\n  static_uex.ex.exclass = LJ_UEXCLASS_MAKE(errcode);\n  static_uex.g = g;\n  _Unwind_RaiseException(&static_uex.ex);\n}\n\n#endif\n\n#endif\n\n/* -- Error handling ------------------------------------------------------ */\n\n/* Throw error. Find catch frame, unwind stack and continue. */\nLJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode)\n{\n  global_State *g = G(L);\n  lj_trace_abort(g);\n  L->status = LUA_OK;\n#if LJ_UNWIND_EXT\n  err_raise_ext(g, errcode);\n  /*\n  ** A return from this function signals a corrupt C stack that cannot be\n  ** unwound. We have no choice but to call the panic function and exit.\n  **\n  ** Usually this is caused by a C function without unwind information.\n  ** This may happen if you've manually enabled LUAJIT_UNWIND_EXTERNAL\n  ** and forgot to recompile *every* non-C++ file with -funwind-tables.\n  */\n  if (G(L)->panic)\n    G(L)->panic(L);\n#else\n#if LJ_HASJIT\n  setmref(g->jit_base, NULL);\n#endif\n  {\n    void *cf = err_unwind(L, NULL, errcode);\n    if (cframe_unwind_ff(cf))\n      lj_vm_unwind_ff(cframe_raw(cf));\n    else\n      lj_vm_unwind_c(cframe_raw(cf), errcode);\n  }\n#endif\n  exit(EXIT_FAILURE);\n}\n\n/* Return string object for error message. */\nLJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em)\n{\n  return lj_str_newz(L, err2msg(em));\n}\n\n/* Out-of-memory error. */\nLJ_NOINLINE void lj_err_mem(lua_State *L)\n{\n  if (L->status == LUA_ERRERR+1)  /* Don't touch the stack during lua_open. */\n    lj_vm_unwind_c(L->cframe, LUA_ERRMEM);\n  setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM));\n  lj_err_throw(L, LUA_ERRMEM);\n}\n\n/* Find error function for runtime errors. Requires an extra stack traversal. */\nstatic ptrdiff_t finderrfunc(lua_State *L)\n{\n  cTValue *frame = L->base-1, *bot = tvref(L->stack)+LJ_FR2;\n  void *cf = L->cframe;\n  while (frame > bot && cf) {\n    while (cframe_nres(cframe_raw(cf)) < 0) {  /* cframe without frame? */\n      if (frame >= restorestack(L, -cframe_nres(cf)))\n\tbreak;\n      if (cframe_errfunc(cf) >= 0)  /* Error handler not inherited (-1)? */\n\treturn cframe_errfunc(cf);\n      cf = cframe_prev(cf);  /* Else unwind cframe and continue searching. */\n      if (cf == NULL)\n\treturn 0;\n    }\n    switch (frame_typep(frame)) {\n    case FRAME_LUA:\n    case FRAME_LUAP:\n      frame = frame_prevl(frame);\n      break;\n    case FRAME_C:\n      cf = cframe_prev(cf);\n      /* fallthrough */\n    case FRAME_VARG:\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_CONT:\n      if (frame_iscont_fficb(frame))\n\tcf = cframe_prev(cf);\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_CP:\n      if (cframe_canyield(cf)) return 0;\n      if (cframe_errfunc(cf) >= 0)\n\treturn cframe_errfunc(cf);\n      cf = cframe_prev(cf);\n      frame = frame_prevd(frame);\n      break;\n    case FRAME_PCALL:\n    case FRAME_PCALLH:\n      if (frame_func(frame_prevd(frame))->c.ffid == FF_xpcall)\n\treturn savestack(L, frame_prevd(frame)+1);  /* xpcall's errorfunc. */\n      return 0;\n    default:\n      lj_assertL(0, \"bad frame type\");\n      return 0;\n    }\n  }\n  return 0;\n}\n\n/* Runtime error. */\nLJ_NOINLINE void LJ_FASTCALL lj_err_run(lua_State *L)\n{\n  ptrdiff_t ef = (LJ_HASJIT && tvref(G(L)->jit_base)) ? 0 : finderrfunc(L);\n  if (ef) {\n    TValue *errfunc = restorestack(L, ef);\n    TValue *top = L->top;\n    lj_trace_abort(G(L));\n    if (!tvisfunc(errfunc) || L->status == LUA_ERRERR) {\n      setstrV(L, top-1, lj_err_str(L, LJ_ERR_ERRERR));\n      lj_err_throw(L, LUA_ERRERR);\n    }\n    L->status = LUA_ERRERR;\n    copyTV(L, top+LJ_FR2, top-1);\n    copyTV(L, top-1, errfunc);\n    if (LJ_FR2) setnilV(top++);\n    L->top = top+1;\n    lj_vm_call(L, top, 1+1);  /* Stack: |errfunc|msg| -> |msg| */\n  }\n  lj_err_throw(L, LUA_ERRRUN);\n}\n\n#if LJ_HASJIT\nLJ_NOINLINE void LJ_FASTCALL lj_err_trace(lua_State *L, int errcode)\n{\n  if (errcode == LUA_ERRRUN)\n    lj_err_run(L);\n  else\n    lj_err_throw(L, errcode);\n}\n#endif\n\n/* Formatted runtime error message. */\nLJ_NORET LJ_NOINLINE static void err_msgv(lua_State *L, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  if (curr_funcisL(L)) L->top = curr_topL(L);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  lj_debug_addloc(L, msg, L->base-1, NULL);\n  lj_err_run(L);\n}\n\n/* Non-vararg variant for better calling conventions. */\nLJ_NOINLINE void lj_err_msg(lua_State *L, ErrMsg em)\n{\n  err_msgv(L, em);\n}\n\n/* Lexer error. */\nLJ_NOINLINE void lj_err_lex(lua_State *L, GCstr *src, const char *tok,\n\t\t\t    BCLine line, ErrMsg em, va_list argp)\n{\n  char buff[LUA_IDSIZE];\n  const char *msg;\n  lj_debug_shortname(buff, src, line);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  msg = lj_strfmt_pushf(L, \"%s:%d: %s\", buff, line, msg);\n  if (tok)\n    lj_strfmt_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tok);\n  lj_err_throw(L, LUA_ERRSYNTAX);\n}\n\n/* Typecheck error for operands. */\nLJ_NOINLINE void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm)\n{\n  const char *tname = lj_typename(o);\n  const char *opname = err2msg(opm);\n  if (curr_funcisL(L)) {\n    GCproto *pt = curr_proto(L);\n    const BCIns *pc = cframe_Lpc(L) - 1;\n    const char *oname = NULL;\n    const char *kind = lj_debug_slotname(pt, pc, (BCReg)(o-L->base), &oname);\n    if (kind)\n      err_msgv(L, LJ_ERR_BADOPRT, opname, kind, oname, tname);\n  }\n  err_msgv(L, LJ_ERR_BADOPRV, opname, tname);\n}\n\n/* Typecheck error for ordered comparisons. */\nLJ_NOINLINE void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2)\n{\n  const char *t1 = lj_typename(o1);\n  const char *t2 = lj_typename(o2);\n  err_msgv(L, t1 == t2 ? LJ_ERR_BADCMPV : LJ_ERR_BADCMPT, t1, t2);\n  /* This assumes the two \"boolean\" entries are commoned by the C compiler. */\n}\n\n/* Typecheck error for __call. */\nLJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o)\n{\n  /* Gross hack if lua_[p]call or pcall/xpcall fail for a non-callable object:\n  ** L->base still points to the caller. So add a dummy frame with L instead\n  ** of a function. See lua_getstack().\n  */\n  const BCIns *pc = cframe_Lpc(L);\n  if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) {\n    const char *tname = lj_typename(o);\n    setframe_gc(o, obj2gco(L), LJ_TTHREAD);\n    if (LJ_FR2) o++;\n    setframe_pc(o, pc);\n    L->top = L->base = o+1;\n    err_msgv(L, LJ_ERR_BADCALL, tname);\n  }\n  lj_err_optype(L, o, LJ_ERR_OPCALL);\n}\n\n/* Error in context of caller. */\nLJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg)\n{\n  TValue *frame = NULL, *pframe = NULL;\n  if (!(LJ_HASJIT && tvref(G(L)->jit_base))) {\n    frame = L->base-1;\n    if (frame_islua(frame)) {\n      pframe = frame_prevl(frame);\n    } else if (frame_iscont(frame)) {\n      if (frame_iscont_fficb(frame)) {\n\tpframe = frame;\n\tframe = NULL;\n      } else {\n\tpframe = frame_prevd(frame);\n#if LJ_HASFFI\n\t/* Remove frame for FFI metamethods. */\n\tif (frame_func(frame)->c.ffid >= FF_ffi_meta___index &&\n\t    frame_func(frame)->c.ffid <= FF_ffi_meta___tostring) {\n\t  L->base = pframe+1;\n\t  L->top = frame;\n\t  setcframe_pc(cframe_raw(L->cframe), frame_contpc(frame));\n\t}\n#endif\n      }\n    }\n  }\n  lj_debug_addloc(L, msg, pframe, frame);\n  lj_err_run(L);\n}\n\n/* Formatted error in context of caller. */\nLJ_NOINLINE void lj_err_callerv(lua_State *L, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  lj_err_callermsg(L, msg);\n}\n\n/* Error in context of caller. */\nLJ_NOINLINE void lj_err_caller(lua_State *L, ErrMsg em)\n{\n  lj_err_callermsg(L, err2msg(em));\n}\n\n/* Argument error message. */\nLJ_NORET LJ_NOINLINE static void err_argmsg(lua_State *L, int narg,\n\t\t\t\t\t    const char *msg)\n{\n  const char *fname = \"?\";\n  const char *ftype = lj_debug_funcname(L, L->base - 1, &fname);\n  if (narg < 0 && narg > LUA_REGISTRYINDEX)\n    narg = (int)(L->top - L->base) + narg + 1;\n  if (ftype && ftype[3] == 'h' && --narg == 0)  /* Check for \"method\". */\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADSELF), fname, msg);\n  else\n    msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADARG), narg, fname, msg);\n  lj_err_callermsg(L, msg);\n}\n\n/* Formatted argument error. */\nLJ_NOINLINE void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, em);\n  msg = lj_strfmt_pushvf(L, err2msg(em), argp);\n  va_end(argp);\n  err_argmsg(L, narg, msg);\n}\n\n/* Argument error. */\nLJ_NOINLINE void lj_err_arg(lua_State *L, int narg, ErrMsg em)\n{\n  err_argmsg(L, narg, err2msg(em));\n}\n\n/* Typecheck error for arguments. */\nLJ_NOINLINE void lj_err_argtype(lua_State *L, int narg, const char *xname)\n{\n  const char *tname, *msg;\n  if (narg <= LUA_REGISTRYINDEX) {\n    if (narg >= LUA_GLOBALSINDEX) {\n      tname = lj_obj_itypename[~LJ_TTAB];\n    } else {\n      GCfunc *fn = curr_func(L);\n      int idx = LUA_GLOBALSINDEX - narg;\n      if (idx <= fn->c.nupvalues)\n\ttname = lj_typename(&fn->c.upvalue[idx-1]);\n      else\n\ttname = lj_obj_typename[0];\n    }\n  } else {\n    TValue *o = narg < 0 ? L->top + narg : L->base + narg-1;\n    tname = o < L->top ? lj_typename(o) : lj_obj_typename[0];\n  }\n  msg = lj_strfmt_pushf(L, err2msg(LJ_ERR_BADTYPE), xname, tname);\n  err_argmsg(L, narg, msg);\n}\n\n/* Typecheck error for arguments. */\nLJ_NOINLINE void lj_err_argt(lua_State *L, int narg, int tt)\n{\n  lj_err_argtype(L, narg, lj_obj_typename[tt+1]);\n}\n\n/* -- Public error handling API ------------------------------------------- */\n\nLUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)\n{\n  lua_CFunction old = G(L)->panic;\n  G(L)->panic = panicf;\n  return old;\n}\n\n/* Forwarders for the public API (C calling convention and no LJ_NORET). */\nLUA_API int lua_error(lua_State *L)\n{\n  lj_err_run(L);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API int luaL_argerror(lua_State *L, int narg, const char *msg)\n{\n  err_argmsg(L, narg, msg);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API int luaL_typerror(lua_State *L, int narg, const char *xname)\n{\n  lj_err_argtype(L, narg, xname);\n  return 0;  /* unreachable */\n}\n\nLUALIB_API void luaL_where(lua_State *L, int level)\n{\n  int size;\n  cTValue *frame = lj_debug_frame(L, level, &size);\n  lj_debug_addloc(L, \"\", frame, size ? frame+size : NULL);\n}\n\nLUALIB_API int luaL_error(lua_State *L, const char *fmt, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  lj_err_callermsg(L, msg);\n  return 0;  /* unreachable */\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_err.h",
    "content": "/*\n** Error handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_ERR_H\n#define _LJ_ERR_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n\ntypedef enum {\n#define ERRDEF(name, msg) \\\n  LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1,\n#include \"lj_errmsg.h\"\n  LJ_ERR__MAX\n} ErrMsg;\n\nLJ_DATA const char *lj_err_allmsg;\n#define err2msg(em)\t(lj_err_allmsg+(int)(em))\n\nLJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em);\nLJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode);\nLJ_FUNC_NORET void lj_err_mem(lua_State *L);\nLJ_FUNC_NORET void LJ_FASTCALL lj_err_run(lua_State *L);\n#if LJ_HASJIT\nLJ_FUNCA_NORET void LJ_FASTCALL lj_err_trace(lua_State *L, int errcode);\n#endif\nLJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em);\nLJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok,\n\t\t\t      BCLine line, ErrMsg em, va_list argp);\nLJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm);\nLJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2);\nLJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o);\nLJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg);\nLJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...);\nLJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em);\nLJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em);\nLJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...);\nLJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname);\nLJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt);\n\n#if LJ_UNWIND_JIT && !LJ_ABI_WIN\nLJ_FUNC uint8_t *lj_err_register_mcode(void *base, size_t sz, uint8_t *info);\nLJ_FUNC void lj_err_deregister_mcode(void *base, size_t sz, uint8_t *info);\n#else\n#define lj_err_register_mcode(base, sz, info)\t(info)\n#define lj_err_deregister_mcode(base, sz, info)\tUNUSED(base)\n#endif\n\n#if LJ_UNWIND_EXT && !LJ_ABI_WIN && defined(LUA_USE_ASSERT)\nLJ_FUNC void lj_err_verify(void);\n#else\n#define lj_err_verify()\t\t((void)0)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_errmsg.h",
    "content": "/*\n** VM error messages.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* This file may be included multiple times with different ERRDEF macros. */\n\n/* Basic error handling. */\nERRDEF(ERRMEM,\t\"not enough memory\")\nERRDEF(ERRERR,\t\"error in error handling\")\nERRDEF(ERRCPP,\t\"C++ exception\")\n\n/* Allocations. */\nERRDEF(STROV,\t\"string length overflow\")\nERRDEF(UDATAOV,\t\"userdata length overflow\")\nERRDEF(STKOV,\t\"stack overflow\")\nERRDEF(STKOVM,\t\"stack overflow (%s)\")\nERRDEF(TABOV,\t\"table overflow\")\n\n/* Table indexing. */\nERRDEF(NANIDX,\t\"table index is NaN\")\nERRDEF(NILIDX,\t\"table index is nil\")\nERRDEF(NEXTIDX,\t\"invalid key to \" LUA_QL(\"next\"))\n\n/* Metamethod resolving. */\nERRDEF(BADCALL,\t\"attempt to call a %s value\")\nERRDEF(BADOPRT,\t\"attempt to %s %s \" LUA_QS \" (a %s value)\")\nERRDEF(BADOPRV,\t\"attempt to %s a %s value\")\nERRDEF(BADCMPT,\t\"attempt to compare %s with %s\")\nERRDEF(BADCMPV,\t\"attempt to compare two %s values\")\nERRDEF(GETLOOP,\t\"loop in gettable\")\nERRDEF(SETLOOP,\t\"loop in settable\")\nERRDEF(OPCALL,\t\"call\")\nERRDEF(OPINDEX,\t\"index\")\nERRDEF(OPARITH,\t\"perform arithmetic on\")\nERRDEF(OPCAT,\t\"concatenate\")\nERRDEF(OPLEN,\t\"get length of\")\n\n/* Type checks. */\nERRDEF(BADSELF,\t\"calling \" LUA_QS \" on bad self (%s)\")\nERRDEF(BADARG,\t\"bad argument #%d to \" LUA_QS \" (%s)\")\nERRDEF(BADTYPE,\t\"%s expected, got %s\")\nERRDEF(BADVAL,\t\"invalid value\")\nERRDEF(NOVAL,\t\"value expected\")\nERRDEF(NOCORO,\t\"coroutine expected\")\nERRDEF(NOTABN,\t\"nil or table expected\")\nERRDEF(NOLFUNC,\t\"Lua function expected\")\nERRDEF(NOFUNCL,\t\"function or level expected\")\nERRDEF(NOSFT,\t\"string/function/table expected\")\nERRDEF(NOPROXY,\t\"boolean or proxy expected\")\nERRDEF(FORINIT,\tLUA_QL(\"for\") \" initial value must be a number\")\nERRDEF(FORLIM,\tLUA_QL(\"for\") \" limit must be a number\")\nERRDEF(FORSTEP,\tLUA_QL(\"for\") \" step must be a number\")\n\n/* C API checks. */\nERRDEF(NOENV,\t\"no calling environment\")\nERRDEF(CYIELD,\t\"attempt to yield across C-call boundary\")\nERRDEF(BADLU,\t\"bad light userdata pointer\")\nERRDEF(NOGCMM,\t\"bad action while in __gc metamethod\")\n#if LJ_TARGET_WINDOWS\nERRDEF(BADFPU,\t\"bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)\")\n#endif\n\n/* Standard library function errors. */\nERRDEF(ASSERT,\t\"assertion failed!\")\nERRDEF(PROTMT,\t\"cannot change a protected metatable\")\nERRDEF(UNPACK,\t\"too many results to unpack\")\nERRDEF(RDRSTR,\t\"reader function must return a string\")\nERRDEF(PRTOSTR,\tLUA_QL(\"tostring\") \" must return a string to \" LUA_QL(\"print\"))\nERRDEF(NUMRNG,\t\"number out of range\")\nERRDEF(IDXRNG,\t\"index out of range\")\nERRDEF(BASERNG,\t\"base out of range\")\nERRDEF(LVLRNG,\t\"level out of range\")\nERRDEF(INVLVL,\t\"invalid level\")\nERRDEF(INVOPT,\t\"invalid option\")\nERRDEF(INVOPTM,\t\"invalid option \" LUA_QS)\nERRDEF(INVFMT,\t\"invalid format\")\nERRDEF(SETFENV,\tLUA_QL(\"setfenv\") \" cannot change environment of given object\")\nERRDEF(CORUN,\t\"cannot resume running coroutine\")\nERRDEF(CODEAD,\t\"cannot resume dead coroutine\")\nERRDEF(COSUSP,\t\"cannot resume non-suspended coroutine\")\nERRDEF(TABINS,\t\"wrong number of arguments to \" LUA_QL(\"insert\"))\nERRDEF(TABCAT,\t\"invalid value (%s) at index %d in table for \" LUA_QL(\"concat\"))\nERRDEF(TABSORT,\t\"invalid order function for sorting\")\nERRDEF(IOCLFL,\t\"attempt to use a closed file\")\nERRDEF(IOSTDCL,\t\"standard file is closed\")\nERRDEF(OSUNIQF,\t\"unable to generate a unique filename\")\nERRDEF(OSDATEF,\t\"field \" LUA_QS \" missing in date table\")\nERRDEF(STRDUMP,\t\"unable to dump given function\")\nERRDEF(STRSLC,\t\"string slice too long\")\nERRDEF(STRPATB,\t\"missing \" LUA_QL(\"[\") \" after \" LUA_QL(\"%f\") \" in pattern\")\nERRDEF(STRPATC,\t\"invalid pattern capture\")\nERRDEF(STRPATE,\t\"malformed pattern (ends with \" LUA_QL(\"%\") \")\")\nERRDEF(STRPATM,\t\"malformed pattern (missing \" LUA_QL(\"]\") \")\")\nERRDEF(STRPATU,\t\"unbalanced pattern\")\nERRDEF(STRPATX,\t\"pattern too complex\")\nERRDEF(STRCAPI,\t\"invalid capture index\")\nERRDEF(STRCAPN,\t\"too many captures\")\nERRDEF(STRCAPU,\t\"unfinished capture\")\nERRDEF(STRFMT,\t\"invalid option \" LUA_QS \" to \" LUA_QL(\"format\"))\nERRDEF(STRGSRV,\t\"invalid replacement value (a %s)\")\nERRDEF(BADMODN,\t\"name conflict for module \" LUA_QS)\n#if LJ_HASJIT\nERRDEF(JITPROT,\t\"runtime code generation failed, restricted kernel?\")\nERRDEF(NOJIT,\t\"JIT compiler disabled\")\n#elif defined(LJ_ARCH_NOJIT)\nERRDEF(NOJIT,\t\"no JIT compiler for this architecture (yet)\")\n#else\nERRDEF(NOJIT,\t\"JIT compiler permanently disabled by build option\")\n#endif\nERRDEF(JITOPT,\t\"unknown or malformed optimization flag \" LUA_QS)\n\n/* Lexer/parser errors. */\nERRDEF(XMODE,\t\"attempt to load chunk with wrong mode\")\nERRDEF(XNEAR,\t\"%s near \" LUA_QS)\nERRDEF(XLINES,\t\"chunk has too many lines\")\nERRDEF(XLEVELS,\t\"chunk has too many syntax levels\")\nERRDEF(XNUMBER,\t\"malformed number\")\nERRDEF(XLSTR,\t\"unfinished long string\")\nERRDEF(XLCOM,\t\"unfinished long comment\")\nERRDEF(XSTR,\t\"unfinished string\")\nERRDEF(XESC,\t\"invalid escape sequence\")\nERRDEF(XLDELIM,\t\"invalid long string delimiter\")\nERRDEF(XTOKEN,\tLUA_QS \" expected\")\nERRDEF(XJUMP,\t\"control structure too long\")\nERRDEF(XSLOTS,\t\"function or expression too complex\")\nERRDEF(XLIMC,\t\"chunk has more than %d local variables\")\nERRDEF(XLIMM,\t\"main function has more than %d %s\")\nERRDEF(XLIMF,\t\"function at line %d has more than %d %s\")\nERRDEF(XMATCH,\tLUA_QS \" expected (to close \" LUA_QS \" at line %d)\")\nERRDEF(XFIXUP,\t\"function too long for return fixup\")\nERRDEF(XPARAM,\t\"<name> or \" LUA_QL(\"...\") \" expected\")\n#if !LJ_52\nERRDEF(XAMBIG,\t\"ambiguous syntax (function call x new statement)\")\n#endif\nERRDEF(XFUNARG,\t\"function arguments expected\")\nERRDEF(XSYMBOL,\t\"unexpected symbol\")\nERRDEF(XDOTS,\t\"cannot use \" LUA_QL(\"...\") \" outside a vararg function\")\nERRDEF(XSYNTAX,\t\"syntax error\")\nERRDEF(XFOR,\tLUA_QL(\"=\") \" or \" LUA_QL(\"in\") \" expected\")\nERRDEF(XBREAK,\t\"no loop to break\")\nERRDEF(XLUNDEF,\t\"undefined label \" LUA_QS)\nERRDEF(XLDUP,\t\"duplicate label \" LUA_QS)\nERRDEF(XGSCOPE,\t\"<goto %s> jumps into the scope of local \" LUA_QS)\n\n/* Bytecode reader errors. */\nERRDEF(BCFMT,\t\"cannot load incompatible bytecode\")\nERRDEF(BCBAD,\t\"cannot load malformed bytecode\")\n\n#if LJ_HASFFI\n/* FFI errors. */\nERRDEF(FFI_INVTYPE,\t\"invalid C type\")\nERRDEF(FFI_INVSIZE,\t\"size of C type is unknown or too large\")\nERRDEF(FFI_BADSCL,\t\"bad storage class\")\nERRDEF(FFI_DECLSPEC,\t\"declaration specifier expected\")\nERRDEF(FFI_BADTAG,\t\"undeclared or implicit tag \" LUA_QS)\nERRDEF(FFI_REDEF,\t\"attempt to redefine \" LUA_QS)\nERRDEF(FFI_NUMPARAM,\t\"wrong number of type parameters\")\nERRDEF(FFI_INITOV,\t\"too many initializers for \" LUA_QS)\nERRDEF(FFI_BADCONV,\t\"cannot convert \" LUA_QS \" to \" LUA_QS)\nERRDEF(FFI_BADLEN,\t\"attempt to get length of \" LUA_QS)\nERRDEF(FFI_BADCONCAT,\t\"attempt to concatenate \" LUA_QS \" and \" LUA_QS)\nERRDEF(FFI_BADARITH,\t\"attempt to perform arithmetic on \" LUA_QS \" and \" LUA_QS)\nERRDEF(FFI_BADCOMP,\t\"attempt to compare \" LUA_QS \" with \" LUA_QS)\nERRDEF(FFI_BADCALL,\tLUA_QS \" is not callable\")\nERRDEF(FFI_NUMARG,\t\"wrong number of arguments for function call\")\nERRDEF(FFI_BADMEMBER,\tLUA_QS \" has no member named \" LUA_QS)\nERRDEF(FFI_BADIDX,\tLUA_QS \" cannot be indexed\")\nERRDEF(FFI_BADIDXW,\tLUA_QS \" cannot be indexed with \" LUA_QS)\nERRDEF(FFI_BADMM,\tLUA_QS \" has no \" LUA_QS \" metamethod\")\nERRDEF(FFI_WRCONST,\t\"attempt to write to constant location\")\nERRDEF(FFI_NODECL,\t\"missing declaration for symbol \" LUA_QS)\nERRDEF(FFI_BADCBACK,\t\"bad callback\")\n#if LJ_OS_NOJIT\nERRDEF(FFI_CBACKOV,\t\"no support for callbacks on this OS\")\n#else\nERRDEF(FFI_CBACKOV,\t\"too many callbacks\")\n#endif\nERRDEF(FFI_NYIPACKBIT,\t\"NYI: packed bit fields\")\nERRDEF(FFI_NYICALL,\t\"NYI: cannot call this C function (yet)\")\n#endif\n\n#if LJ_HASBUFFER\n/* String buffer errors. */\nERRDEF(BUFFER_SELF,\t\"cannot put buffer into itself\")\nERRDEF(BUFFER_BADOPT,\t\"bad options table\")\nERRDEF(BUFFER_BADENC,\t\"cannot serialize \" LUA_QS)\nERRDEF(BUFFER_BADDEC,\t\"cannot deserialize tag 0x%02x\")\nERRDEF(BUFFER_BADDICTX,\t\"cannot deserialize dictionary index %d\")\nERRDEF(BUFFER_DEPTH,\t\"too deep to serialize\")\nERRDEF(BUFFER_DUPKEY,\t\"duplicate table key\")\nERRDEF(BUFFER_EOB,\t\"unexpected end of buffer\")\nERRDEF(BUFFER_LEFTOV,\t\"left-over data in buffer\")\n#endif\n\n#undef ERRDEF\n\n/* Detecting unused error messages:\n   awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, \"\"); printf \"grep -q LJ_ERR_%s *.[ch] || echo %s\\n\", $1, $1}' lj_errmsg.h | sh\n*/\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ff.h",
    "content": "/*\n** Fast function IDs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FF_H\n#define _LJ_FF_H\n\n/* Fast function ID. */\ntypedef enum {\n  FF_LUA_ = FF_LUA,\t/* Lua function (must be 0). */\n  FF_C_ = FF_C,\t\t/* Regular C function (must be 1). */\n#define FFDEF(name)\tFF_##name,\n#include \"lj_ffdef.h\"\n  FF__MAX\n} FastFunc;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ffrecord.c",
    "content": "/*\n** Fast function call recorder.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ffrecord_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_crecord.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_serialize.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* -- Fast function recording handlers ------------------------------------ */\n\n/* Conventions for fast function call handlers:\n**\n** The argument slots start at J->base[0]. All of them are guaranteed to be\n** valid and type-specialized references. J->base[J->maxslot] is set to 0\n** as a sentinel. The runtime argument values start at rd->argv[0].\n**\n** In general fast functions should check for presence of all of their\n** arguments and for the correct argument types. Some simplifications\n** are allowed if the interpreter throws instead. But even if recording\n** is aborted, the generated IR must be consistent (no zero-refs).\n**\n** The number of results in rd->nres is set to 1. Handlers that return\n** a different number of results need to override it. A negative value\n** prevents return processing (e.g. for pending calls).\n**\n** Results need to be stored starting at J->base[0]. Return processing\n** moves them to the right slots later.\n**\n** The per-ffid auxiliary data is the value of the 2nd part of the\n** LJLIB_REC() annotation. This allows handling similar functionality\n** in a common handler.\n*/\n\n/* Type of handler to record a fast function. */\ntypedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd);\n\n/* Get runtime value of int argument. */\nstatic int32_t argv2int(jit_State *J, TValue *o)\n{\n  if (!lj_strscan_numberobj(o))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  return tvisint(o) ? intV(o) : lj_num2int(numV(o));\n}\n\n/* Get runtime value of string argument. */\nstatic GCstr *argv2str(jit_State *J, TValue *o)\n{\n  if (LJ_LIKELY(tvisstr(o))) {\n    return strV(o);\n  } else {\n    GCstr *s;\n    if (!tvisnumber(o))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    s = lj_strfmt_number(J->L, o);\n    setstrV(J->L, o, s);\n    return s;\n  }\n}\n\n/* Return number of results wanted by caller. */\nstatic ptrdiff_t results_wanted(jit_State *J)\n{\n  TValue *frame = J->L->base-1;\n  if (frame_islua(frame))\n    return (ptrdiff_t)bc_b(frame_pc(frame)[-1]) - 1;\n  else\n    return -1;\n}\n\n/* Trace stitching: add continuation below frame to start a new trace. */\nstatic void recff_stitch(jit_State *J)\n{\n  ASMFunction cont = lj_cont_stitch;\n  lua_State *L = J->L;\n  TValue *base = L->base;\n  BCReg nslot = J->maxslot + 1 + LJ_FR2;\n  TValue *nframe = base + 1 + LJ_FR2;\n  const BCIns *pc = frame_pc(base-1);\n  TValue *pframe = frame_prevl(base-1);\n\n  /* Check for this now. Throwing in lj_record_stop messes up the stack. */\n  if (J->cur.nsnap >= (MSize)J->param[JIT_P_maxsnap])\n    lj_trace_err(J, LJ_TRERR_SNAPOV);\n\n  /* Move func + args up in Lua stack and insert continuation. */\n  memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot);\n  setframe_ftsz(nframe, ((char *)nframe - (char *)pframe) + FRAME_CONT);\n  setcont(base-LJ_FR2, cont);\n  setframe_pc(base, pc);\n  setnilV(base-1-LJ_FR2);  /* Incorrect, but rec_check_slots() won't run anymore. */\n  L->base += 2 + LJ_FR2;\n  L->top += 2 + LJ_FR2;\n\n  /* Ditto for the IR. */\n  memmove(&J->base[1], &J->base[-1-LJ_FR2], sizeof(TRef)*nslot);\n#if LJ_FR2\n  J->base[2] = TREF_FRAME;\n  J->base[-1] = lj_ir_k64(J, IR_KNUM, u64ptr(contptr(cont)));\n  J->base[0] = lj_ir_k64(J, IR_KNUM, u64ptr(pc)) | TREF_CONT;\n#else\n  J->base[0] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT;\n#endif\n  J->ktrace = tref_ref((J->base[-1-LJ_FR2] = lj_ir_ktrace(J)));\n  J->base += 2 + LJ_FR2;\n  J->baseslot += 2 + LJ_FR2;\n  J->framedepth++;\n\n  lj_record_stop(J, LJ_TRLINK_STITCH, 0);\n\n  /* Undo Lua stack changes. */\n  memmove(&base[-1-LJ_FR2], &base[1], sizeof(TValue)*nslot);\n  setframe_pc(base-1, pc);\n  L->base -= 2 + LJ_FR2;\n  L->top -= 2 + LJ_FR2;\n}\n\n/* Fallback handler for fast functions that are not recorded (yet). */\nstatic void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd)\n{\n  if (J->cur.nins < (IRRef)J->param[JIT_P_minstitch] + REF_BASE) {\n    lj_trace_err_info(J, LJ_TRERR_TRACEUV);\n  } else {\n    /* Can only stitch from Lua call. */\n    if (J->framedepth && frame_islua(J->L->base-1)) {\n      BCOp op = bc_op(*frame_pc(J->L->base-1));\n      /* Stitched trace cannot start with *M op with variable # of args. */\n      if (!(op == BC_CALLM || op == BC_CALLMT ||\n\t    op == BC_RETM || op == BC_TSETM)) {\n\tswitch (J->fn->c.ffid) {\n\tcase FF_error:\n\tcase FF_debug_sethook:\n\tcase FF_jit_flush:\n\t  break;  /* Don't stitch across special builtins. */\n\tdefault:\n\t  recff_stitch(J);  /* Use trace stitching. */\n\t  rd->nres = -1;\n\t  return;\n\t}\n      }\n    }\n    /* Otherwise stop trace and return to interpreter. */\n    lj_record_stop(J, LJ_TRLINK_RETURN, 0);\n    rd->nres = -1;\n  }\n}\n\n/* Fallback handler for unsupported variants of fast functions. */\n#define recff_nyiu\trecff_nyi\n\n/* Must stop the trace for classic C functions with arbitrary side-effects. */\n#define recff_c\t\trecff_nyi\n\n/* Emit BUFHDR for the global temporary buffer. */\nstatic TRef recff_bufhdr(jit_State *J)\n{\n  return emitir(IRT(IR_BUFHDR, IRT_PGC),\n\t\tlj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);\n}\n\n/* Emit TMPREF. */\nstatic TRef recff_tmpref(jit_State *J, TRef tr, int mode)\n{\n  if (!LJ_DUALNUM && tref_isinteger(tr))\n    tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n  return emitir(IRT(IR_TMPREF, IRT_PGC), tr, mode);\n}\n\n/* -- Base library fast functions ----------------------------------------- */\n\nstatic void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd)\n{\n  /* Arguments already specialized. The interpreter throws for nil/false. */\n  rd->nres = J->maxslot;  /* Pass through all arguments. */\n}\n\nstatic void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd)\n{\n  /* Arguments already specialized. Result is a constant string. Neat, huh? */\n  uint32_t t;\n  if (tvisnumber(&rd->argv[0]))\n    t = ~LJ_TNUMX;\n  else if (LJ_64 && !LJ_GC64 && tvislightud(&rd->argv[0]))\n    t = ~LJ_TLIGHTUD;\n  else\n    t = ~itype(&rd->argv[0]);\n  J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[t]));\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tr) {\n    RecordIndex ix;\n    ix.tab = tr;\n    copyTV(J->L, &ix.tabv, &rd->argv[0]);\n    if (lj_record_mm_lookup(J, &ix, MM_metatable))\n      J->base[0] = ix.mobj;\n    else\n      J->base[0] = ix.mt;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  TRef mt = J->base[1];\n  if (tref_istab(tr) && (tref_istab(mt) || (mt && tref_isnil(mt)))) {\n    TRef fref, mtref;\n    RecordIndex ix;\n    ix.tab = tr;\n    copyTV(J->L, &ix.tabv, &rd->argv[0]);\n    lj_record_mm_lookup(J, &ix, MM_metatable); /* Guard for no __metatable. */\n    fref = emitir(IRT(IR_FREF, IRT_PGC), tr, IRFL_TAB_META);\n    mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt;\n    emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref);\n    if (!tref_isnil(mt))\n      emitir(IRT(IR_TBAR, IRT_TAB), tr, 0);\n    J->base[0] = tr;\n    J->needsnap = 1;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawget(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0]; ix.key = J->base[1];\n  if (tref_istab(ix.tab) && ix.key) {\n    ix.val = 0; ix.idxchain = 0;\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    copyTV(J->L, &ix.keyv, &rd->argv[1]);\n    J->base[0] = lj_record_idx(J, &ix);\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawset(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0]; ix.key = J->base[1]; ix.val = J->base[2];\n  if (tref_istab(ix.tab) && ix.key && ix.val) {\n    ix.idxchain = 0;\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    copyTV(J->L, &ix.keyv, &rd->argv[1]);\n    copyTV(J->L, &ix.valv, &rd->argv[2]);\n    lj_record_idx(J, &ix);\n    /* Pass through table at J->base[0] as result. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd)\n{\n  TRef tra = J->base[0];\n  TRef trb = J->base[1];\n  if (tra && trb) {\n    int diff = lj_record_objcmp(J, tra, trb, &rd->argv[0], &rd->argv[1]);\n    J->base[0] = diff ? TREF_FALSE : TREF_TRUE;\n  }  /* else: Interpreter will throw. */\n}\n\n#if LJ_52\nstatic void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_isstr(tr))\n    J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);\n  else if (tref_istab(tr))\n    J->base[0] = emitir(IRTI(IR_ALEN), tr, TREF_NIL);\n  /* else: Interpreter will throw. */\n  UNUSED(rd);\n}\n#endif\n\n/* Determine mode of select() call. */\nint32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv)\n{\n  if (tref_isstr(tr) && *strVdata(tv) == '#') {  /* select('#', ...) */\n    if (strV(tv)->len == 1) {\n      emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, strV(tv)));\n    } else {\n      TRef trptr = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0));\n      TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY);\n      emitir(IRTGI(IR_EQ), trchar, lj_ir_kint(J, '#'));\n    }\n    return 0;\n  } else {  /* select(n, ...) */\n    int32_t start = argv2int(J, tv);\n    if (start == 0) lj_trace_err(J, LJ_TRERR_BADTYPE);  /* A bit misleading. */\n    return start;\n  }\n}\n\nstatic void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tr) {\n    ptrdiff_t start = lj_ffrecord_select_mode(J, tr, &rd->argv[0]);\n    if (start == 0) {  /* select('#', ...) */\n      J->base[0] = lj_ir_kint(J, J->maxslot - 1);\n    } else if (tref_isk(tr)) {  /* select(k, ...) */\n      ptrdiff_t n = (ptrdiff_t)J->maxslot;\n      if (start < 0) start += n;\n      else if (start > n) start = n;\n      if (start >= 1) {\n\tptrdiff_t i;\n\trd->nres = n - start;\n\tfor (i = 0; i < n - start; i++)\n\t  J->base[i] = J->base[start+i];\n      }  /* else: Interpreter will throw. */\n    } else {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  TRef base = J->base[1];\n  if (tr && !tref_isnil(base)) {\n    base = lj_opt_narrow_toint(J, base);\n    if (!tref_isk(base) || IR(tref_ref(base))->i != 10) {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n  if (tref_isnumber_str(tr)) {\n    if (tref_isstr(tr)) {\n      TValue tmp;\n      if (!lj_strscan_num(strV(&rd->argv[0]), &tmp)) {\n\trecff_nyiu(J, rd);  /* Would need an inverted STRTO for this case. */\n\treturn;\n      }\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    }\n#if LJ_HASFFI\n  } else if (tref_iscdata(tr)) {\n    lj_crecord_tonumber(J, rd);\n    return;\n#endif\n  } else {\n    tr = TREF_NIL;\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\nstatic TValue *recff_metacall_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  lj_record_tailcall(J, 0, 1);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\nstatic int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  copyTV(J->L, &ix.tabv, &rd->argv[0]);\n  if (lj_record_mm_lookup(J, &ix, mm)) {  /* Has metamethod? */\n    int errcode;\n    TValue argv0;\n    /* Temporarily insert metamethod below object. */\n    J->base[1+LJ_FR2] = J->base[0];\n    J->base[0] = ix.mobj;\n    copyTV(J->L, &argv0, &rd->argv[0]);\n    copyTV(J->L, &rd->argv[1+LJ_FR2], &rd->argv[0]);\n    copyTV(J->L, &rd->argv[0], &ix.mobjv);\n    /* Need to protect lj_record_tailcall because it may throw. */\n    errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp);\n    /* Always undo Lua stack changes to avoid confusing the interpreter. */\n    copyTV(J->L, &rd->argv[0], &argv0);\n    if (errcode)\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    rd->nres = -1;  /* Pending call. */\n    return 1;  /* Tailcalled to metamethod. */\n  }\n  return 0;\n}\n\nstatic void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_isstr(tr)) {\n    /* Ignore __tostring in the string base metatable. */\n    /* Pass on result in J->base[0]. */\n  } else if (tr && !recff_metacall(J, rd, MM_tostring)) {\n    if (tref_isnumber(tr)) {\n      J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr,\n\t\t\t  tref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT);\n    } else if (tref_ispri(tr)) {\n      J->base[0] = lj_ir_kstr(J, lj_strfmt_obj(J->L, &rd->argv[0]));\n    } else {\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n}\n\nstatic void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  if (tref_istab(ix.tab)) {\n    if (!tvisnumber(&rd->argv[1]))  /* No support for string coercion. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    setintV(&ix.keyv, numberVint(&rd->argv[1])+1);\n    settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));\n    ix.val = 0; ix.idxchain = 0;\n    ix.key = lj_opt_narrow_toint(J, J->base[1]);\n    J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1));\n    J->base[1] = lj_record_idx(J, &ix);\n    rd->nres = tref_isnil(J->base[1]) ? 0 : 2;\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_xpairs(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) &&\n\trecff_metacall(J, rd, MM_pairs + rd->data))) {\n    if (tref_istab(tr)) {\n      J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0]));\n      J->base[1] = tr;\n      J->base[2] = rd->data ? lj_ir_kint(J, 0) : TREF_NIL;\n      rd->nres = 3;\n    }  /* else: Interpreter will throw. */\n  }\n}\n\nstatic void LJ_FASTCALL recff_pcall(jit_State *J, RecordFFData *rd)\n{\n  if (J->maxslot >= 1) {\n#if LJ_FR2\n    /* Shift function arguments up. */\n    memmove(J->base + 1, J->base, sizeof(TRef) * J->maxslot);\n#endif\n    lj_record_call(J, 0, J->maxslot - 1);\n    rd->nres = -1;  /* Pending call. */\n    J->needsnap = 1;  /* Start catching on-trace errors. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic TValue *recff_xpcall_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  lj_record_call(J, 1, J->maxslot - 2);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\nstatic void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd)\n{\n  if (J->maxslot >= 2) {\n    TValue argv0, argv1;\n    TRef tmp;\n    int errcode;\n    /* Swap function and traceback. */\n    tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp;\n    copyTV(J->L, &argv0, &rd->argv[0]);\n    copyTV(J->L, &argv1, &rd->argv[1]);\n    copyTV(J->L, &rd->argv[0], &argv1);\n    copyTV(J->L, &rd->argv[1], &argv0);\n#if LJ_FR2\n    /* Shift function arguments up. */\n    memmove(J->base + 2, J->base + 1, sizeof(TRef) * (J->maxslot-1));\n#endif\n    /* Need to protect lj_record_call because it may throw. */\n    errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp);\n    /* Always undo Lua stack swap to avoid confusing the interpreter. */\n    copyTV(J->L, &rd->argv[0], &argv0);\n    copyTV(J->L, &rd->argv[1], &argv1);\n    if (errcode)\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    rd->nres = -1;  /* Pending call. */\n    J->needsnap = 1;  /* Start catching on-trace errors. */\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_getfenv(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  /* Only support getfenv(0) for now. */\n  if (tref_isint(tr) && tref_isk(tr) && IR(tref_ref(tr))->i == 0) {\n    TRef trl = emitir(IRT(IR_LREF, IRT_THREAD), 0, 0);\n    J->base[0] = emitir(IRT(IR_FLOAD, IRT_TAB), trl, IRFL_THREAD_ENV);\n    return;\n  }\n  recff_nyiu(J, rd);\n}\n\nstatic void LJ_FASTCALL recff_next(jit_State *J, RecordFFData *rd)\n{\n#if LJ_BE\n  /* YAGNI: Disabled on big-endian due to issues with lj_vm_next,\n  ** IR_HIOP, RID_RETLO/RID_RETHI and ra_destpair.\n  */\n  recff_nyi(J, rd);\n#else\n  TRef tab = J->base[0];\n  if (tref_istab(tab)) {\n    RecordIndex ix;\n    cTValue *keyv;\n    ix.tab = tab;\n    if (tref_isnil(J->base[1])) {  /* Shortcut for start of traversal. */\n      ix.key = lj_ir_kint(J, 0);\n      keyv = niltvg(J2G(J));\n    } else {\n      TRef tmp = recff_tmpref(J, J->base[1], IRTMPREF_IN1);\n      ix.key = lj_ir_call(J, IRCALL_lj_tab_keyindex, tab, tmp);\n      keyv = &rd->argv[1];\n    }\n    copyTV(J->L, &ix.tabv, &rd->argv[0]);\n    ix.keyv.u32.lo = lj_tab_keyindex(tabV(&ix.tabv), keyv);\n    /* Omit the value, if not used by the caller. */\n    ix.idxchain = (J->framedepth && frame_islua(J->L->base-1) &&\n\t\t   bc_b(frame_pc(J->L->base-1)[-1])-1 < 2);\n    ix.mobj = 0;  /* We don't need the next index. */\n    rd->nres = lj_record_next(J, &ix);\n    J->base[0] = ix.key;\n    J->base[1] = ix.val;\n  }  /* else: Interpreter will throw. */\n#endif\n}\n\n/* -- Math library fast functions ----------------------------------------- */\n\nstatic void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  J->base[0] = emitir(IRTN(IR_ABS), tr, lj_ir_ksimd(J, LJ_KSIMD_ABS));\n  UNUSED(rd);\n}\n\n/* Record rounding functions math.floor and math.ceil. */\nstatic void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (!tref_isinteger(tr)) {  /* Pass through integers unmodified. */\n    tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data);\n    /* Result is integral (or NaN/Inf), but may not fit an int32_t. */\n    if (LJ_DUALNUM) {  /* Try to narrow using a guarded conversion to int. */\n      lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data);\n      if (n == (lua_Number)lj_num2int(n))\n\ttr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK);\n    }\n    J->base[0] = tr;\n  }\n}\n\n/* Record unary math.* functions, mapped to IR_FPMATH opcode. */\nstatic void LJ_FASTCALL recff_math_unary(jit_State *J, RecordFFData *rd)\n{\n  J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data);\n}\n\n/* Record math.log. */\nstatic void LJ_FASTCALL recff_math_log(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  if (J->base[1]) {\n#ifdef LUAJIT_NO_LOG2\n    uint32_t fpm = IRFPM_LOG;\n#else\n    uint32_t fpm = IRFPM_LOG2;\n#endif\n    TRef trb = lj_ir_tonum(J, J->base[1]);\n    tr = emitir(IRTN(IR_FPMATH), tr, fpm);\n    trb = emitir(IRTN(IR_FPMATH), trb, fpm);\n    trb = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), trb);\n    tr = emitir(IRTN(IR_MUL), tr, trb);\n  } else {\n    tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_LOG);\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\n/* Record math.atan2. */\nstatic void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  TRef tr2 = lj_ir_tonum(J, J->base[1]);\n  J->base[0] = lj_ir_call(J, IRCALL_atan2, tr, tr2);\n  UNUSED(rd);\n}\n\n/* Record math.ldexp. */\nstatic void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n#if LJ_TARGET_X86ORX64\n  TRef tr2 = lj_ir_tonum(J, J->base[1]);\n#else\n  TRef tr2 = lj_opt_narrow_toint(J, J->base[1]);\n#endif\n  J->base[0] = emitir(IRTN(IR_LDEXP), tr, tr2);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_math_call(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonum(J, J->base[0]);\n  J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data);\n}\n\nstatic void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd)\n{\n  J->base[0] = lj_opt_narrow_pow(J, J->base[0], J->base[1],\n\t\t\t\t &rd->argv[0], &rd->argv[1]);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_math_minmax(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = lj_ir_tonumber(J, J->base[0]);\n  uint32_t op = rd->data;\n  BCReg i;\n  for (i = 1; J->base[i] != 0; i++) {\n    TRef tr2 = lj_ir_tonumber(J, J->base[i]);\n    IRType t = IRT_INT;\n    if (!(tref_isinteger(tr) && tref_isinteger(tr2))) {\n      if (tref_isinteger(tr)) tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n      if (tref_isinteger(tr2)) tr2 = emitir(IRTN(IR_CONV), tr2, IRCONV_NUM_INT);\n      t = IRT_NUM;\n    }\n    tr = emitir(IRT(op, t), tr, tr2);\n  }\n  J->base[0] = tr;\n}\n\nstatic void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd)\n{\n  GCudata *ud = udataV(&J->fn->c.upvalue[0]);\n  TRef tr, one;\n  lj_ir_kgc(J, obj2gco(ud), IRT_UDATA);  /* Prevent collection. */\n  tr = lj_ir_call(J, IRCALL_lj_prng_u64d, lj_ir_kptr(J, uddata(ud)));\n  one = lj_ir_knum_one(J);\n  tr = emitir(IRTN(IR_SUB), tr, one);\n  if (J->base[0]) {\n    TRef tr1 = lj_ir_tonum(J, J->base[0]);\n    if (J->base[1]) {  /* d = floor(d*(r2-r1+1.0)) + r1 */\n      TRef tr2 = lj_ir_tonum(J, J->base[1]);\n      tr2 = emitir(IRTN(IR_SUB), tr2, tr1);\n      tr2 = emitir(IRTN(IR_ADD), tr2, one);\n      tr = emitir(IRTN(IR_MUL), tr, tr2);\n      tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);\n      tr = emitir(IRTN(IR_ADD), tr, tr1);\n    } else {  /* d = floor(d*r1) + 1.0 */\n      tr = emitir(IRTN(IR_MUL), tr, tr1);\n      tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);\n      tr = emitir(IRTN(IR_ADD), tr, one);\n    }\n  }\n  J->base[0] = tr;\n  UNUSED(rd);\n}\n\n/* -- Bit library fast functions ------------------------------------------ */\n\n/* Record bit.tobit. */\nstatic void LJ_FASTCALL recff_bit_tobit(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n#if LJ_HASFFI\n  if (tref_iscdata(tr)) { recff_bit64_tobit(J, rd); return; }\n#endif\n  J->base[0] = lj_opt_narrow_tobit(J, tr);\n  UNUSED(rd);\n}\n\n/* Record unary bit.bnot, bit.bswap. */\nstatic void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_unary(J, rd))\n    return;\n#endif\n  J->base[0] = emitir(IRTI(rd->data), lj_opt_narrow_tobit(J, J->base[0]), 0);\n}\n\n/* Record N-ary bit.band, bit.bor, bit.bxor. */\nstatic void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_nary(J, rd))\n    return;\n#endif\n  {\n    TRef tr = lj_opt_narrow_tobit(J, J->base[0]);\n    uint32_t ot = IRTI(rd->data);\n    BCReg i;\n    for (i = 1; J->base[i] != 0; i++)\n      tr = emitir(ot, tr, lj_opt_narrow_tobit(J, J->base[i]));\n    J->base[0] = tr;\n  }\n}\n\n/* Record bit shifts. */\nstatic void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  if (recff_bit64_shift(J, rd))\n    return;\n#endif\n  {\n    TRef tr = lj_opt_narrow_tobit(J, J->base[0]);\n    TRef tsh = lj_opt_narrow_tobit(J, J->base[1]);\n    IROp op = (IROp)rd->data;\n    if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n\t!tref_isk(tsh))\n      tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31));\n#ifdef LJ_TARGET_UNIFYROT\n    if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) {\n      op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR;\n      tsh = emitir(IRTI(IR_NEG), tsh, tsh);\n    }\n#endif\n    J->base[0] = emitir(IRTI(op), tr, tsh);\n  }\n}\n\nstatic void LJ_FASTCALL recff_bit_tohex(jit_State *J, RecordFFData *rd)\n{\n#if LJ_HASFFI\n  TRef hdr = recff_bufhdr(J);\n  TRef tr = recff_bit64_tohex(J, rd, hdr);\n  J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n#else\n  recff_nyiu(J, rd);  /* Don't bother working around this NYI. */\n#endif\n}\n\n/* -- String library fast functions --------------------------------------- */\n\n/* Specialize to relative starting position for string. */\nstatic TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr,\n\t\t\t       TRef trlen, TRef tr0)\n{\n  int32_t start = *st;\n  if (start < 0) {\n    emitir(IRTGI(IR_LT), tr, tr0);\n    tr = emitir(IRTI(IR_ADD), trlen, tr);\n    start = start + (int32_t)s->len;\n    emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), tr, tr0);\n    if (start < 0) {\n      tr = tr0;\n      start = 0;\n    }\n  } else if (start == 0) {\n    emitir(IRTGI(IR_EQ), tr, tr0);\n    tr = tr0;\n  } else {\n    tr = emitir(IRTI(IR_ADD), tr, lj_ir_kint(J, -1));\n    emitir(IRTGI(IR_GE), tr, tr0);\n    start--;\n  }\n  *st = start;\n  return tr;\n}\n\n/* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */\nstatic void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)\n{\n  TRef trstr = lj_ir_tostr(J, J->base[0]);\n  TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN);\n  TRef tr0 = lj_ir_kint(J, 0);\n  TRef trstart, trend;\n  GCstr *str = argv2str(J, &rd->argv[0]);\n  int32_t start, end;\n  if (rd->data) {  /* string.sub(str, start [,end]) */\n    start = argv2int(J, &rd->argv[1]);\n    trstart = lj_opt_narrow_toint(J, J->base[1]);\n    trend = J->base[2];\n    if (tref_isnil(trend)) {\n      trend = lj_ir_kint(J, -1);\n      end = -1;\n    } else {\n      trend = lj_opt_narrow_toint(J, trend);\n      end = argv2int(J, &rd->argv[2]);\n    }\n  } else {  /* string.byte(str, [,start [,end]]) */\n    if (tref_isnil(J->base[1])) {\n      start = 1;\n      trstart = lj_ir_kint(J, 1);\n    } else {\n      start = argv2int(J, &rd->argv[1]);\n      trstart = lj_opt_narrow_toint(J, J->base[1]);\n    }\n    if (J->base[1] && !tref_isnil(J->base[2])) {\n      trend = lj_opt_narrow_toint(J, J->base[2]);\n      end = argv2int(J, &rd->argv[2]);\n    } else {\n      trend = trstart;\n      end = start;\n    }\n  }\n  if (end < 0) {\n    emitir(IRTGI(IR_LT), trend, tr0);\n    trend = emitir(IRTI(IR_ADD), emitir(IRTI(IR_ADD), trlen, trend),\n\t\t   lj_ir_kint(J, 1));\n    end = end+(int32_t)str->len+1;\n  } else if ((MSize)end <= str->len) {\n    emitir(IRTGI(IR_ULE), trend, trlen);\n  } else {\n    emitir(IRTGI(IR_UGT), trend, trlen);\n    end = (int32_t)str->len;\n    trend = trlen;\n  }\n  trstart = recff_string_start(J, str, &start, trstart, trlen, tr0);\n  if (rd->data) {  /* Return string.sub result. */\n    if (end - start >= 0) {\n      /* Also handle empty range here, to avoid extra traces. */\n      TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart);\n      emitir(IRTGI(IR_GE), trslen, tr0);\n      trptr = emitir(IRT(IR_STRREF, IRT_PGC), trstr, trstart);\n      J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen);\n    } else {  /* Range underflow: return empty string. */\n      emitir(IRTGI(IR_LT), trend, trstart);\n      J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty);\n    }\n  } else {  /* Return string.byte result(s). */\n    ptrdiff_t i, len = end - start;\n    if (len > 0) {\n      TRef trslen = emitir(IRTI(IR_SUB), trend, trstart);\n      emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len));\n      if (J->baseslot + len > LJ_MAX_JSLOTS)\n\tlj_trace_err_info(J, LJ_TRERR_STACKOV);\n      rd->nres = len;\n      for (i = 0; i < len; i++) {\n\tTRef tmp = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, (int32_t)i));\n\ttmp = emitir(IRT(IR_STRREF, IRT_PGC), trstr, tmp);\n\tJ->base[i] = emitir(IRT(IR_XLOAD, IRT_U8), tmp, IRXLOAD_READONLY);\n      }\n    } else {  /* Empty range or range underflow: return no results. */\n      emitir(IRTGI(IR_LE), trend, trstart);\n      rd->nres = 0;\n    }\n  }\n}\n\nstatic void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd)\n{\n  TRef k255 = lj_ir_kint(J, 255);\n  BCReg i;\n  for (i = 0; J->base[i] != 0; i++) {  /* Convert char values to strings. */\n    TRef tr = lj_opt_narrow_toint(J, J->base[i]);\n    emitir(IRTGI(IR_ULE), tr, k255);\n    J->base[i] = emitir(IRT(IR_TOSTR, IRT_STR), tr, IRTOSTR_CHAR);\n  }\n  if (i > 1) {  /* Concatenate the strings, if there's more than one. */\n    TRef hdr = recff_bufhdr(J), tr = hdr;\n    for (i = 0; J->base[i] != 0; i++)\n      tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, J->base[i]);\n    J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n  } else if (i == 0) {\n    J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty);\n  }\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd)\n{\n  TRef str = lj_ir_tostr(J, J->base[0]);\n  TRef rep = lj_opt_narrow_toint(J, J->base[1]);\n  TRef hdr, tr, str2 = 0;\n  if (!tref_isnil(J->base[2])) {\n    TRef sep = lj_ir_tostr(J, J->base[2]);\n    int32_t vrep = argv2int(J, &rd->argv[1]);\n    emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1));\n    if (vrep > 1) {\n      TRef hdr2 = recff_bufhdr(J);\n      TRef tr2 = emitir(IRTG(IR_BUFPUT, IRT_PGC), hdr2, sep);\n      tr2 = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr2, str);\n      str2 = emitir(IRTG(IR_BUFSTR, IRT_STR), tr2, hdr2);\n    }\n  }\n  tr = hdr = recff_bufhdr(J);\n  if (str2) {\n    tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, str);\n    str = str2;\n    rep = emitir(IRTI(IR_ADD), rep, lj_ir_kint(J, -1));\n  }\n  tr = lj_ir_call(J, IRCALL_lj_buf_putstr_rep, tr, str, rep);\n  J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n}\n\nstatic void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd)\n{\n  TRef str = lj_ir_tostr(J, J->base[0]);\n  TRef hdr = recff_bufhdr(J);\n  TRef tr = lj_ir_call(J, rd->data, hdr, str);\n  J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n}\n\nstatic void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd)\n{\n  TRef trstr = lj_ir_tostr(J, J->base[0]);\n  TRef trpat = lj_ir_tostr(J, J->base[1]);\n  TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN);\n  TRef tr0 = lj_ir_kint(J, 0);\n  TRef trstart;\n  GCstr *str = argv2str(J, &rd->argv[0]);\n  GCstr *pat = argv2str(J, &rd->argv[1]);\n  int32_t start;\n  J->needsnap = 1;\n  if (tref_isnil(J->base[2])) {\n    trstart = lj_ir_kint(J, 1);\n    start = 1;\n  } else {\n    trstart = lj_opt_narrow_toint(J, J->base[2]);\n    start = argv2int(J, &rd->argv[2]);\n  }\n  trstart = recff_string_start(J, str, &start, trstart, trlen, tr0);\n  if ((MSize)start <= str->len) {\n    emitir(IRTGI(IR_ULE), trstart, trlen);\n  } else {\n    emitir(IRTGI(IR_UGT), trstart, trlen);\n#if LJ_52\n    J->base[0] = TREF_NIL;\n    return;\n#else\n    trstart = trlen;\n    start = str->len;\n#endif\n  }\n  /* Fixed arg or no pattern matching chars? (Specialized to pattern string.) */\n  if ((J->base[2] && tref_istruecond(J->base[3])) ||\n      (emitir(IRTG(IR_EQ, IRT_STR), trpat, lj_ir_kstr(J, pat)),\n       !lj_str_haspattern(pat))) {  /* Search for fixed string. */\n    TRef trsptr = emitir(IRT(IR_STRREF, IRT_PGC), trstr, trstart);\n    TRef trpptr = emitir(IRT(IR_STRREF, IRT_PGC), trpat, tr0);\n    TRef trslen = emitir(IRTI(IR_SUB), trlen, trstart);\n    TRef trplen = emitir(IRTI(IR_FLOAD), trpat, IRFL_STR_LEN);\n    TRef tr = lj_ir_call(J, IRCALL_lj_str_find, trsptr, trpptr, trslen, trplen);\n    TRef trp0 = lj_ir_kkptr(J, NULL);\n    if (lj_str_find(strdata(str)+(MSize)start, strdata(pat),\n\t\t    str->len-(MSize)start, pat->len)) {\n      TRef pos;\n      emitir(IRTG(IR_NE, IRT_PGC), tr, trp0);\n      /* Recompute offset. trsptr may not point into trstr after folding. */\n      pos = emitir(IRTI(IR_ADD), emitir(IRTI(IR_SUB), tr, trsptr), trstart);\n      J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1));\n      J->base[1] = emitir(IRTI(IR_ADD), pos, trplen);\n      rd->nres = 2;\n    } else {\n      emitir(IRTG(IR_EQ, IRT_PGC), tr, trp0);\n      J->base[0] = TREF_NIL;\n    }\n  } else {  /* Search for pattern. */\n    recff_nyiu(J, rd);\n    return;\n  }\n}\n\nstatic void recff_format(jit_State *J, RecordFFData *rd, TRef hdr, int sbufx)\n{\n  ptrdiff_t arg = sbufx;\n  TRef tr = hdr, trfmt = lj_ir_tostr(J, J->base[arg]);\n  GCstr *fmt = argv2str(J, &rd->argv[arg]);\n  FormatState fs;\n  SFormat sf;\n  /* Specialize to the format string. */\n  emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt));\n  lj_strfmt_init(&fs, strdata(fmt), fmt->len);\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {  /* Parse format. */\n    TRef tra = sf == STRFMT_LIT ? 0 : J->base[++arg];\n    TRef trsf = lj_ir_kint(J, (int32_t)sf);\n    IRCallID id;\n    switch (STRFMT_TYPE(sf)) {\n    case STRFMT_LIT:\n      tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,\n\t\t  lj_ir_kstr(J, lj_str_new(J->L, fs.str, fs.len)));\n      break;\n    case STRFMT_INT:\n      id = IRCALL_lj_strfmt_putfnum_int;\n    handle_int:\n      if (!tref_isinteger(tra)) {\n#if LJ_HASFFI\n\tif (tref_iscdata(tra)) {\n\t  tra = lj_crecord_loadiu64(J, tra, &rd->argv[arg]);\n\t  tr = lj_ir_call(J, IRCALL_lj_strfmt_putfxint, tr, trsf, tra);\n\t  break;\n\t}\n#endif\n\tgoto handle_num;\n      }\n      if (sf == STRFMT_INT) { /* Shortcut for plain %d. */\n\ttr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,\n\t\t    emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_INT));\n      } else {\n#if LJ_HASFFI\n\ttra = emitir(IRT(IR_CONV, IRT_U64), tra,\n\t\t     (IRT_INT|(IRT_U64<<5)|IRCONV_SEXT));\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfxint, tr, trsf, tra);\n\tlj_needsplit(J);\n#else\n\trecff_nyiu(J, rd);  /* Don't bother working around this NYI. */\n\treturn;\n#endif\n      }\n      break;\n    case STRFMT_UINT:\n      id = IRCALL_lj_strfmt_putfnum_uint;\n      goto handle_int;\n    case STRFMT_NUM:\n      id = IRCALL_lj_strfmt_putfnum;\n    handle_num:\n      tra = lj_ir_tonum(J, tra);\n      tr = lj_ir_call(J, id, tr, trsf, tra);\n      if (LJ_SOFTFP32) lj_needsplit(J);\n      break;\n    case STRFMT_STR:\n      if (!tref_isstr(tra)) {\n\trecff_nyiu(J, rd);  /* NYI: __tostring and non-string types for %s. */\n\t/* NYI: also buffers. */\n\treturn;\n      }\n      if (sf == STRFMT_STR)  /* Shortcut for plain %s. */\n\ttr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, tra);\n      else if ((sf & STRFMT_T_QUOTED))\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putquoted, tr, tra);\n      else\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfstr, tr, trsf, tra);\n      break;\n    case STRFMT_CHAR:\n      tra = lj_opt_narrow_toint(J, tra);\n      if (sf == STRFMT_CHAR)  /* Shortcut for plain %c. */\n\ttr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,\n\t\t    emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_CHAR));\n      else\n\ttr = lj_ir_call(J, IRCALL_lj_strfmt_putfchar, tr, trsf, tra);\n      break;\n    case STRFMT_PTR:  /* NYI */\n    case STRFMT_ERR:\n    default:\n      recff_nyiu(J, rd);\n      return;\n    }\n  }\n  if (sbufx) {\n    emitir(IRT(IR_USE, IRT_NIL), tr, 0);\n  } else {\n    J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n  }\n}\n\nstatic void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)\n{\n  recff_format(J, rd, recff_bufhdr(J), 0);\n}\n\n/* -- Buffer library fast functions --------------------------------------- */\n\n#if LJ_HASBUFFER\n\nstatic LJ_AINLINE TRef recff_sbufx_get_L(jit_State *J, TRef ud)\n{\n  return emitir(IRT(IR_FLOAD, IRT_PGC), ud, IRFL_SBUF_L);\n}\n\nstatic LJ_AINLINE void recff_sbufx_set_L(jit_State *J, TRef ud, TRef val)\n{\n  TRef fref = emitir(IRT(IR_FREF, IRT_PGC), ud, IRFL_SBUF_L);\n  emitir(IRT(IR_FSTORE, IRT_PGC), fref, val);\n}\n\nstatic LJ_AINLINE TRef recff_sbufx_get_ptr(jit_State *J, TRef ud, IRFieldID fl)\n{\n  return emitir(IRT(IR_FLOAD, IRT_PTR), ud, fl);\n}\n\nstatic LJ_AINLINE void recff_sbufx_set_ptr(jit_State *J, TRef ud, IRFieldID fl, TRef val)\n{\n  TRef fref = emitir(IRT(IR_FREF, IRT_PTR), ud, fl);\n  emitir(IRT(IR_FSTORE, IRT_PTR), fref, val);\n}\n\nstatic LJ_AINLINE TRef recff_sbufx_len(jit_State *J, TRef trr, TRef trw)\n{\n  TRef len = emitir(IRT(IR_SUB, IRT_INTP), trw, trr);\n  if (LJ_64)\n    len = emitir(IRTI(IR_CONV), len, (IRT_INT<<5)|IRT_INTP|IRCONV_NONE);\n  return len;\n}\n\n/* Emit typecheck for string buffer. */\nstatic TRef recff_sbufx_check(jit_State *J, RecordFFData *rd, int arg)\n{\n  TRef trtype, ud = J->base[arg];\n  if (!tvisbuf(&rd->argv[arg])) lj_trace_err(J, LJ_TRERR_BADTYPE);\n  trtype = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE);\n  emitir(IRTGI(IR_EQ), trtype, lj_ir_kint(J, UDTYPE_BUFFER));\n  J->needsnap = 1;\n  return ud;\n}\n\n/* Emit BUFHDR for write to extended string buffer. */\nstatic TRef recff_sbufx_write(jit_State *J, TRef ud)\n{\n  TRef trbuf = emitir(IRT(IR_ADD, IRT_PGC), ud, lj_ir_kint(J, sizeof(GCudata)));\n  return emitir(IRT(IR_BUFHDR, IRT_PGC), trbuf, IRBUFHDR_WRITE);\n}\n\n/* Check for integer in range for the buffer API. */\nstatic TRef recff_sbufx_checkint(jit_State *J, RecordFFData *rd, int arg)\n{\n  TRef tr = J->base[arg];\n  TRef trlim = lj_ir_kint(J, LJ_MAX_BUF);\n  if (tref_isinteger(tr)) {\n    emitir(IRTGI(IR_ULE), tr, trlim);\n  } else if (tref_isnum(tr)) {\n    tr = emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY);\n    emitir(IRTGI(IR_ULE), tr, trlim);\n#if LJ_HASFFI\n  } else if (tref_iscdata(tr)) {\n    tr = lj_crecord_loadiu64(J, tr, &rd->argv[arg]);\n    emitir(IRTG(IR_ULE, IRT_U64), tr, lj_ir_kint64(J, LJ_MAX_BUF));\n    tr = emitir(IRTI(IR_CONV), tr, (IRT_INT<<5)|IRT_I64|IRCONV_NONE);\n#else\n    UNUSED(rd);\n#endif\n  } else {\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  return tr;\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_reset(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  SBufExt *sbx = bufV(&rd->argv[0]);\n  int iscow = (int)sbufiscow(sbx);\n  TRef trl = recff_sbufx_get_L(J, ud);\n  TRef trcow = emitir(IRT(IR_BAND, IRT_IGC), trl, lj_ir_kint(J, SBUF_FLAG_COW));\n  TRef zero = lj_ir_kint(J, 0);\n  emitir(IRTG(iscow ? IR_NE : IR_EQ, IRT_IGC), trcow, zero);\n  if (iscow) {\n    trl = emitir(IRT(IR_BXOR, IRT_IGC), trl,\n\t\t LJ_GC64 ? lj_ir_kint64(J, SBUF_FLAG_COW) :\n\t\t\t   lj_ir_kint(J, SBUF_FLAG_COW));\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_W, zero);\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_E, zero);\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_B, zero);\n    recff_sbufx_set_L(J, ud, trl);\n    emitir(IRT(IR_FSTORE, IRT_PGC),\n\t   emitir(IRT(IR_FREF, IRT_PGC), ud, IRFL_SBUF_REF), zero);\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, zero);\n  } else {\n    TRef trb = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_B);\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_W, trb);\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trb);\n  }\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_skip(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trr = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_R);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  TRef len = recff_sbufx_len(J, trr, trw);\n  TRef trn = recff_sbufx_checkint(J, rd, 1);\n  len = emitir(IRTI(IR_MIN), len, trn);\n  trr = emitir(IRT(IR_ADD, IRT_PTR), trr, len);\n  recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trr);\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_set(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef tr = J->base[1];\n  if (tref_isstr(tr)) {\n    TRef trp = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0));\n    TRef len = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);\n    lj_ir_call(J, IRCALL_lj_bufx_set, trbuf, trp, len, tr);\n#if LJ_HASFFI\n  } else if (tref_iscdata(tr)) {\n    TRef trp = lj_crecord_topcvoid(J, tr, &rd->argv[1]);\n    TRef len = recff_sbufx_checkint(J, rd, 2);\n    lj_ir_call(J, IRCALL_lj_bufx_set, trbuf, trp, len, tr);\n#endif\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_put(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef tr;\n  ptrdiff_t arg;\n  if (!J->base[1]) return;\n  for (arg = 1; (tr = J->base[arg]); arg++) {\n    if (tref_isstr(tr)) {\n      trbuf = emitir(IRTG(IR_BUFPUT, IRT_PGC), trbuf, tr);\n    } else if (tref_isnumber(tr)) {\n      trbuf = emitir(IRTG(IR_BUFPUT, IRT_PGC), trbuf,\n\t\t     emitir(IRT(IR_TOSTR, IRT_STR), tr,\n\t\t\t    tref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT));\n    } else if (tref_isudata(tr)) {\n      TRef ud2 = recff_sbufx_check(J, rd, arg);\n      TRef trr = recff_sbufx_get_ptr(J, ud2, IRFL_SBUF_R);\n      TRef trw = recff_sbufx_get_ptr(J, ud2, IRFL_SBUF_W);\n      TRef len = recff_sbufx_len(J, trr, trw);\n      emitir(IRTG(IR_NE, IRT_PGC), ud, ud2);\n      trbuf = lj_ir_call(J, IRCALL_lj_buf_putmem, trbuf, trr, len);\n    } else {\n      recff_nyiu(J, rd);\n    }\n  }\n  emitir(IRT(IR_USE, IRT_NIL), trbuf, 0);\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_putf(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  recff_format(J, rd, trbuf, 1);\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_get(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trr = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_R);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  TRef tr;\n  ptrdiff_t arg;\n  if (!J->base[1]) { J->base[1] = TREF_NIL; J->base[2] = 0; }\n  for (arg = 0; (tr = J->base[arg+1]); arg++) {\n    TRef len = recff_sbufx_len(J, trr, trw);\n    if (tref_isnil(tr)) {\n      J->base[arg] = emitir(IRT(IR_XSNEW, IRT_STR), trr, len);\n      trr = trw;\n    } else {\n      TRef trn = recff_sbufx_checkint(J, rd, arg+1);\n      TRef tru;\n      len = emitir(IRTI(IR_MIN), len, trn);\n      tru = emitir(IRT(IR_ADD, IRT_PTR), trr, len);\n      J->base[arg] = emitir(IRT(IR_XSNEW, IRT_STR), trr, len);\n      trr = tru;  /* Doing the ADD before the SNEW generates better code. */\n    }\n    recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trr);\n  }\n  rd->nres = arg;\n}\n\nstatic void LJ_FASTCALL recff_buffer_method___tostring(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trr = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_R);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), trr, recff_sbufx_len(J, trr, trw));\n}\n\nstatic void LJ_FASTCALL recff_buffer_method___len(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trr = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_R);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  J->base[0] = recff_sbufx_len(J, trr, trw);\n}\n\n#if LJ_HASFFI\nstatic void LJ_FASTCALL recff_buffer_method_putcdata(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef tr = lj_crecord_topcvoid(J, J->base[1], &rd->argv[1]);\n  TRef len = recff_sbufx_checkint(J, rd, 2);\n  trbuf = lj_ir_call(J, IRCALL_lj_buf_putmem, trbuf, tr, len);\n  emitir(IRT(IR_USE, IRT_NIL), trbuf, 0);\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_reserve(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef trsz = recff_sbufx_checkint(J, rd, 1);\n  J->base[1] = lj_ir_call(J, IRCALL_lj_bufx_more, trbuf, trsz);\n  J->base[0] = lj_crecord_topuint8(J, recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W));\n  rd->nres = 2;\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_commit(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef len = recff_sbufx_checkint(J, rd, 1);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  TRef tre = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_E);\n  TRef left = emitir(IRT(IR_SUB, IRT_INTP), tre, trw);\n  if (LJ_64)\n    left = emitir(IRTI(IR_CONV), left, (IRT_INT<<5)|IRT_INTP|IRCONV_NONE);\n  emitir(IRTGI(IR_ULE), len, left);\n  trw = emitir(IRT(IR_ADD, IRT_PTR), trw, len);\n  recff_sbufx_set_ptr(J, ud, IRFL_SBUF_W, trw);\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_ref(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trr = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_R);\n  TRef trw = recff_sbufx_get_ptr(J, ud, IRFL_SBUF_W);\n  J->base[0] = lj_crecord_topuint8(J, trr);\n  J->base[1] = recff_sbufx_len(J, trr, trw);\n  rd->nres = 2;\n}\n#endif\n\nstatic void LJ_FASTCALL recff_buffer_method_encode(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef tmp = recff_tmpref(J, J->base[1], IRTMPREF_IN1);\n  lj_ir_call(J, IRCALL_lj_serialize_put, trbuf, tmp);\n  /* No IR_USE needed, since the call is a store. */\n}\n\nstatic void LJ_FASTCALL recff_buffer_method_decode(jit_State *J, RecordFFData *rd)\n{\n  TRef ud = recff_sbufx_check(J, rd, 0);\n  TRef trbuf = recff_sbufx_write(J, ud);\n  TRef tmp = recff_tmpref(J, TREF_NIL, IRTMPREF_OUT1);\n  TRef trr = lj_ir_call(J, IRCALL_lj_serialize_get, trbuf, tmp);\n  IRType t = (IRType)lj_serialize_peektype(bufV(&rd->argv[0]));\n  /* No IR_USE needed, since the call is a store. */\n  J->base[0] = lj_record_vload(J, tmp, 0, t);\n  /* The sbx->r store must be after the VLOAD type check, in case it fails. */\n  recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trr);\n}\n\nstatic void LJ_FASTCALL recff_buffer_encode(jit_State *J, RecordFFData *rd)\n{\n  TRef tmp = recff_tmpref(J, J->base[0], IRTMPREF_IN1);\n  J->base[0] = lj_ir_call(J, IRCALL_lj_serialize_encode, tmp);\n  /* IR_USE needed for IR_CALLA, because the encoder may throw non-OOM. */\n  emitir(IRT(IR_USE, IRT_NIL), J->base[0], 0);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_buffer_decode(jit_State *J, RecordFFData *rd)\n{\n  if (tvisstr(&rd->argv[0])) {\n    GCstr *str = strV(&rd->argv[0]);\n    SBufExt sbx;\n    IRType t;\n    TRef tmp = recff_tmpref(J, TREF_NIL, IRTMPREF_OUT1);\n    TRef tr = lj_ir_call(J, IRCALL_lj_serialize_decode, tmp, J->base[0]);\n    /* IR_USE needed for IR_CALLA, because the decoder may throw non-OOM.\n    ** That's why IRCALL_lj_serialize_decode needs a fake INT result.\n    */\n    emitir(IRT(IR_USE, IRT_NIL), tr, 0);\n    memset(&sbx, 0, sizeof(SBufExt));\n    lj_bufx_set_cow(J->L, &sbx, strdata(str), str->len);\n    t = (IRType)lj_serialize_peektype(&sbx);\n    J->base[0] = lj_record_vload(J, tmp, 0, t);\n  }  /* else: Interpreter will throw. */\n}\n\n#endif\n\n/* -- Table library fast functions ---------------------------------------- */\n\nstatic void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)\n{\n  RecordIndex ix;\n  ix.tab = J->base[0];\n  ix.val = J->base[1];\n  rd->nres = 0;\n  if (tref_istab(ix.tab) && ix.val) {\n    if (!J->base[2]) {  /* Simple push: t[#t+1] = v */\n      TRef trlen = emitir(IRTI(IR_ALEN), ix.tab, TREF_NIL);\n      GCtab *t = tabV(&rd->argv[0]);\n      ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));\n      settabV(J->L, &ix.tabv, t);\n      setintV(&ix.keyv, lj_tab_len(t) + 1);\n      ix.idxchain = 0;\n      lj_record_idx(J, &ix);  /* Set new value. */\n    } else {  /* Complex case: insert in the middle. */\n      recff_nyiu(J, rd);\n      return;\n    }\n  }  /* else: Interpreter will throw. */\n}\n\nstatic void LJ_FASTCALL recff_table_concat(jit_State *J, RecordFFData *rd)\n{\n  TRef tab = J->base[0];\n  if (tref_istab(tab)) {\n    TRef sep = !tref_isnil(J->base[1]) ?\n\t       lj_ir_tostr(J, J->base[1]) : lj_ir_knull(J, IRT_STR);\n    TRef tri = (J->base[1] && !tref_isnil(J->base[2])) ?\n\t       lj_opt_narrow_toint(J, J->base[2]) : lj_ir_kint(J, 1);\n    TRef tre = (J->base[1] && J->base[2] && !tref_isnil(J->base[3])) ?\n\t       lj_opt_narrow_toint(J, J->base[3]) :\n\t       emitir(IRTI(IR_ALEN), tab, TREF_NIL);\n    TRef hdr = recff_bufhdr(J);\n    TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre);\n    emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL));\n    J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n  }  /* else: Interpreter will throw. */\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_table_new(jit_State *J, RecordFFData *rd)\n{\n  TRef tra = lj_opt_narrow_toint(J, J->base[0]);\n  TRef trh = lj_opt_narrow_toint(J, J->base[1]);\n  J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh);\n  UNUSED(rd);\n}\n\nstatic void LJ_FASTCALL recff_table_clear(jit_State *J, RecordFFData *rd)\n{\n  TRef tr = J->base[0];\n  if (tref_istab(tr)) {\n    rd->nres = 0;\n    lj_ir_call(J, IRCALL_lj_tab_clear, tr);\n    J->needsnap = 1;\n  }  /* else: Interpreter will throw. */\n}\n\n/* -- I/O library fast functions ------------------------------------------ */\n\n/* Get FILE* for I/O function. Any I/O error aborts recording, so there's\n** no need to encode the alternate cases for any of the guards.\n*/\nstatic TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id)\n{\n  TRef tr, ud, fp;\n  if (id) {  /* io.func() */\n    ud = lj_ir_ggfload(J, IRT_UDATA, GG_OFS(g.gcroot[id]));\n  } else {  /* fp:method() */\n    ud = J->base[0];\n    if (!tref_isudata(ud))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE);\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));\n  }\n  *udp = ud;\n  fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE);\n  emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR));\n  return fp;\n}\n\nstatic void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd)\n{\n  TRef ud, fp = recff_io_fp(J, &ud, rd->data);\n  TRef zero = lj_ir_kint(J, 0);\n  TRef one = lj_ir_kint(J, 1);\n  ptrdiff_t i = rd->data == 0 ? 1 : 0;\n  for (; J->base[i]; i++) {\n    TRef str = lj_ir_tostr(J, J->base[i]);\n    TRef buf = emitir(IRT(IR_STRREF, IRT_PGC), str, zero);\n    TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN);\n    if (tref_isk(len) && IR(tref_ref(len))->i == 1) {\n      IRIns *irs = IR(tref_ref(str));\n      TRef tr = (irs->o == IR_TOSTR && irs->op2 == IRTOSTR_CHAR) ?\n\t\tirs->op1 :\n\t\temitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY);\n      tr = lj_ir_call(J, IRCALL_fputc, tr, fp);\n      if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n\temitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1));\n    } else {\n      TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp);\n      if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n\temitir(IRTGI(IR_EQ), tr, len);\n    }\n  }\n  J->base[0] = LJ_52 ? ud : TREF_TRUE;\n}\n\nstatic void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd)\n{\n  TRef ud, fp = recff_io_fp(J, &ud, rd->data);\n  TRef tr = lj_ir_call(J, IRCALL_fflush, fp);\n  if (results_wanted(J) != 0)  /* Check result only if not ignored. */\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));\n  J->base[0] = TREF_TRUE;\n}\n\n/* -- Debug library fast functions ---------------------------------------- */\n\nstatic void LJ_FASTCALL recff_debug_getmetatable(jit_State *J, RecordFFData *rd)\n{\n  GCtab *mt;\n  TRef mtref;\n  TRef tr = J->base[0];\n  if (tref_istab(tr)) {\n    mt = tabref(tabV(&rd->argv[0])->metatable);\n    mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_TAB_META);\n  } else if (tref_isudata(tr)) {\n    mt = tabref(udataV(&rd->argv[0])->metatable);\n    mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_UDATA_META);\n  } else {\n    mt = tabref(basemt_obj(J2G(J), &rd->argv[0]));\n    J->base[0] = mt ? lj_ir_ktab(J, mt) : TREF_NIL;\n    return;\n  }\n  emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB));\n  J->base[0] = mt ? mtref : TREF_NIL;\n}\n\n/* -- Record calls to fast functions -------------------------------------- */\n\n#include \"lj_recdef.h\"\n\nstatic uint32_t recdef_lookup(GCfunc *fn)\n{\n  if (fn->c.ffid < sizeof(recff_idmap)/sizeof(recff_idmap[0]))\n    return recff_idmap[fn->c.ffid];\n  else\n    return 0;\n}\n\n/* Record entry to a fast function or C function. */\nvoid lj_ffrecord_func(jit_State *J)\n{\n  RecordFFData rd;\n  uint32_t m = recdef_lookup(J->fn);\n  rd.data = m & 0xff;\n  rd.nres = 1;  /* Default is one result. */\n  rd.argv = J->L->base;\n  J->base[J->maxslot] = 0;  /* Mark end of arguments. */\n  (recff_func[m >> 8])(J, &rd);  /* Call recff_* handler. */\n  if (rd.nres >= 0) {\n    if (J->postproc == LJ_POST_NONE) J->postproc = LJ_POST_FFRETRY;\n    lj_record_ret(J, 0, rd.nres);\n  }\n}\n\n#undef IR\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ffrecord.h",
    "content": "/*\n** Fast function call recorder.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FFRECORD_H\n#define _LJ_FFRECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* Data used by handlers to record a fast function. */\ntypedef struct RecordFFData {\n  TValue *argv;\t\t/* Runtime argument values. */\n  ptrdiff_t nres;\t/* Number of returned results (defaults to 1). */\n  uint32_t data;\t/* Per-ffid auxiliary data (opcode, literal etc.). */\n} RecordFFData;\n\nLJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv);\nLJ_FUNC void lj_ffrecord_func(jit_State *J);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_frame.h",
    "content": "/*\n** Stack frames.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FRAME_H\n#define _LJ_FRAME_H\n\n#include \"lj_obj.h\"\n#include \"lj_bc.h\"\n\n/* -- Lua stack frame ----------------------------------------------------- */\n\n/* Frame type markers in LSB of PC (4-byte aligned) or delta (8-byte aligned:\n**\n**    PC  00  Lua frame\n** delta 001  C frame\n** delta 010  Continuation frame\n** delta 011  Lua vararg frame\n** delta 101  cpcall() frame\n** delta 110  ff pcall() frame\n** delta 111  ff pcall() frame with active hook\n*/\nenum {\n  FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,\n  FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH\n};\n#define FRAME_TYPE\t\t3\n#define FRAME_P\t\t\t4\n#define FRAME_TYPEP\t\t(FRAME_TYPE|FRAME_P)\n\n/* Macros to access and modify Lua frames. */\n#if LJ_FR2\n/* Two-slot frame info, required for 64 bit PC/GCRef:\n**\n**                   base-2  base-1      |  base  base+1 ...\n**                  [func   PC/delta/ft] | [slots ...]\n**                  ^-- frame            | ^-- base   ^-- top\n**\n** Continuation frames:\n**\n**   base-4  base-3  base-2  base-1      |  base  base+1 ...\n**  [cont      PC ] [func   PC/delta/ft] | [slots ...]\n**                  ^-- frame            | ^-- base   ^-- top\n*/\n#define frame_gc(f)\t\t(gcval((f)-1))\n#define frame_ftsz(f)\t\t((ptrdiff_t)(f)->ftsz)\n#define frame_pc(f)\t\t((const BCIns *)frame_ftsz(f))\n#define setframe_gc(f, p, tp)\t(setgcVraw((f), (p), (tp)))\n#define setframe_ftsz(f, sz)\t((f)->ftsz = (sz))\n#define setframe_pc(f, pc)\t((f)->ftsz = (int64_t)(intptr_t)(pc))\n#else\n/* One-slot frame info, sufficient for 32 bit PC/GCRef:\n**\n**              base-1              |  base  base+1 ...\n**              lo     hi           |\n**             [func | PC/delta/ft] | [slots ...]\n**             ^-- frame            | ^-- base   ^-- top\n**\n** Continuation frames:\n**\n**  base-2      base-1              |  base  base+1 ...\n**  lo     hi   lo     hi           |\n** [cont | PC] [func | PC/delta/ft] | [slots ...]\n**             ^-- frame            | ^-- base   ^-- top\n*/\n#define frame_gc(f)\t\t(gcref((f)->fr.func))\n#define frame_ftsz(f)\t\t((ptrdiff_t)(f)->fr.tp.ftsz)\n#define frame_pc(f)\t\t(mref((f)->fr.tp.pcr, const BCIns))\n#define setframe_gc(f, p, tp)\t(setgcref((f)->fr.func, (p)), UNUSED(tp))\n#define setframe_ftsz(f, sz)\t((f)->fr.tp.ftsz = (int32_t)(sz))\n#define setframe_pc(f, pc)\t(setmref((f)->fr.tp.pcr, (pc)))\n#endif\n\n#define frame_type(f)\t\t(frame_ftsz(f) & FRAME_TYPE)\n#define frame_typep(f)\t\t(frame_ftsz(f) & FRAME_TYPEP)\n#define frame_islua(f)\t\t(frame_type(f) == FRAME_LUA)\n#define frame_isc(f)\t\t(frame_type(f) == FRAME_C)\n#define frame_iscont(f)\t\t(frame_typep(f) == FRAME_CONT)\n#define frame_isvarg(f)\t\t(frame_typep(f) == FRAME_VARG)\n#define frame_ispcall(f)\t((frame_ftsz(f) & 6) == FRAME_PCALL)\n\n#define frame_func(f)\t\t(&frame_gc(f)->fn)\n#define frame_delta(f)\t\t(frame_ftsz(f) >> 3)\n#define frame_sized(f)\t\t(frame_ftsz(f) & ~FRAME_TYPEP)\n\nenum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK };  /* Special continuations. */\n\n#if LJ_FR2\n#define frame_contpc(f)\t\t(frame_pc((f)-2))\n#define frame_contv(f)\t\t(((f)-3)->u64)\n#else\n#define frame_contpc(f)\t\t(frame_pc((f)-1))\n#define frame_contv(f)\t\t(((f)-1)->u32.lo)\n#endif\n#if LJ_FR2\n#define frame_contf(f)\t\t((ASMFunction)(uintptr_t)((f)-3)->u64)\n#elif LJ_64\n#define frame_contf(f) \\\n  ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \\\n\t\t\t (intptr_t)(int32_t)((f)-1)->u32.lo))\n#else\n#define frame_contf(f)\t\t((ASMFunction)gcrefp(((f)-1)->gcr, void))\n#endif\n#define frame_iscont_fficb(f) \\\n  (LJ_HASFFI && frame_contv(f) == LJ_CONT_FFI_CALLBACK)\n\n#define frame_prevl(f)\t\t((f) - (1+LJ_FR2+bc_a(frame_pc(f)[-1])))\n#define frame_prevd(f)\t\t((TValue *)((char *)(f) - frame_sized(f)))\n#define frame_prev(f)\t\t(frame_islua(f)?frame_prevl(f):frame_prevd(f))\n/* Note: this macro does not skip over FRAME_VARG. */\n\n/* -- C stack frame ------------------------------------------------------- */\n\n/* Macros to access and modify the C stack frame chain. */\n\n/* These definitions must match with the arch-specific *.dasc files. */\n#if LJ_TARGET_X86\n#if LJ_ABI_WIN\n#define CFRAME_OFS_ERRF\t\t(19*4)\n#define CFRAME_OFS_NRES\t\t(18*4)\n#define CFRAME_OFS_PREV\t\t(17*4)\n#define CFRAME_OFS_L\t\t(16*4)\n#define CFRAME_OFS_SEH\t\t(9*4)\n#define CFRAME_OFS_PC\t\t(6*4)\n#define CFRAME_OFS_MULTRES\t(5*4)\n#define CFRAME_SIZE\t\t(16*4)\n#define CFRAME_SHIFT_MULTRES\t0\n#else\n#define CFRAME_OFS_ERRF\t\t(15*4)\n#define CFRAME_OFS_NRES\t\t(14*4)\n#define CFRAME_OFS_PREV\t\t(13*4)\n#define CFRAME_OFS_L\t\t(12*4)\n#define CFRAME_OFS_PC\t\t(6*4)\n#define CFRAME_OFS_MULTRES\t(5*4)\n#define CFRAME_SIZE\t\t(12*4)\n#define CFRAME_SHIFT_MULTRES\t0\n#endif\n#elif LJ_TARGET_X64\n#if LJ_ABI_WIN\n#define CFRAME_OFS_PREV\t\t(13*8)\n#if LJ_GC64\n#define CFRAME_OFS_PC\t\t(12*8)\n#define CFRAME_OFS_L\t\t(11*8)\n#define CFRAME_OFS_ERRF\t\t(21*4)\n#define CFRAME_OFS_NRES\t\t(20*4)\n#define CFRAME_OFS_MULTRES\t(8*4)\n#else\n#define CFRAME_OFS_PC\t\t(25*4)\n#define CFRAME_OFS_L\t\t(24*4)\n#define CFRAME_OFS_ERRF\t\t(23*4)\n#define CFRAME_OFS_NRES\t\t(22*4)\n#define CFRAME_OFS_MULTRES\t(21*4)\n#endif\n#define CFRAME_SIZE\t\t(10*8)\n#define CFRAME_SIZE_JIT\t\t(CFRAME_SIZE + 9*16 + 4*8)\n#define CFRAME_SHIFT_MULTRES\t0\n#else\n#define CFRAME_OFS_PREV\t\t(4*8)\n#if LJ_GC64\n#define CFRAME_OFS_PC\t\t(3*8)\n#define CFRAME_OFS_L\t\t(2*8)\n#define CFRAME_OFS_ERRF\t\t(3*4)\n#define CFRAME_OFS_NRES\t\t(2*4)\n#define CFRAME_OFS_MULTRES\t(0*4)\n#else\n#define CFRAME_OFS_PC\t\t(7*4)\n#define CFRAME_OFS_L\t\t(6*4)\n#define CFRAME_OFS_ERRF\t\t(5*4)\n#define CFRAME_OFS_NRES\t\t(4*4)\n#define CFRAME_OFS_MULTRES\t(1*4)\n#endif\n#if LJ_NO_UNWIND\n#define CFRAME_SIZE\t\t(12*8)\n#else\n#define CFRAME_SIZE\t\t(10*8)\n#endif\n#define CFRAME_SIZE_JIT\t\t(CFRAME_SIZE + 16)\n#define CFRAME_SHIFT_MULTRES\t0\n#endif\n#elif LJ_TARGET_ARM\n#define CFRAME_OFS_ERRF\t\t24\n#define CFRAME_OFS_NRES\t\t20\n#define CFRAME_OFS_PREV\t\t16\n#define CFRAME_OFS_L\t\t12\n#define CFRAME_OFS_PC\t\t8\n#define CFRAME_OFS_MULTRES\t4\n#if LJ_ARCH_HASFPU\n#define CFRAME_SIZE\t\t128\n#else\n#define CFRAME_SIZE\t\t64\n#endif\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_TARGET_ARM64\n#define CFRAME_OFS_ERRF\t\t36\n#define CFRAME_OFS_NRES\t\t40\n#define CFRAME_OFS_PREV\t\t0\n#define CFRAME_OFS_L\t\t16\n#define CFRAME_OFS_PC\t\t8\n#define CFRAME_OFS_MULTRES\t32\n#define CFRAME_SIZE\t\t208\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_TARGET_PPC\n#if LJ_TARGET_XBOX360\n#define CFRAME_OFS_ERRF\t\t424\n#define CFRAME_OFS_NRES\t\t420\n#define CFRAME_OFS_PREV\t\t400\n#define CFRAME_OFS_L\t\t416\n#define CFRAME_OFS_PC\t\t412\n#define CFRAME_OFS_MULTRES\t408\n#define CFRAME_SIZE\t\t384\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_ARCH_PPC32ON64\n#define CFRAME_OFS_ERRF\t\t472\n#define CFRAME_OFS_NRES\t\t468\n#define CFRAME_OFS_PREV\t\t448\n#define CFRAME_OFS_L\t\t464\n#define CFRAME_OFS_PC\t\t460\n#define CFRAME_OFS_MULTRES\t456\n#define CFRAME_SIZE\t\t400\n#define CFRAME_SHIFT_MULTRES\t3\n#else\n#define CFRAME_OFS_ERRF\t\t48\n#define CFRAME_OFS_NRES\t\t44\n#define CFRAME_OFS_PREV\t\t40\n#define CFRAME_OFS_L\t\t36\n#define CFRAME_OFS_PC\t\t32\n#define CFRAME_OFS_MULTRES\t28\n#define CFRAME_SIZE\t\t(LJ_ARCH_HASFPU ? 272 : 128)\n#define CFRAME_SHIFT_MULTRES\t3\n#endif\n#elif LJ_TARGET_MIPS32\n#if LJ_ARCH_HASFPU\n#define CFRAME_OFS_ERRF\t\t124\n#define CFRAME_OFS_NRES\t\t120\n#define CFRAME_OFS_PREV\t\t116\n#define CFRAME_OFS_L\t\t112\n#define CFRAME_SIZE\t\t112\n#else\n#define CFRAME_OFS_ERRF\t\t76\n#define CFRAME_OFS_NRES\t\t72\n#define CFRAME_OFS_PREV\t\t68\n#define CFRAME_OFS_L\t\t64\n#define CFRAME_SIZE\t\t64\n#endif\n#define CFRAME_OFS_PC\t\t20\n#define CFRAME_OFS_MULTRES\t16\n#define CFRAME_SHIFT_MULTRES\t3\n#elif LJ_TARGET_MIPS64\n#if LJ_ARCH_HASFPU\n#define CFRAME_OFS_ERRF\t\t188\n#define CFRAME_OFS_NRES\t\t184\n#define CFRAME_OFS_PREV\t\t176\n#define CFRAME_OFS_L\t\t168\n#define CFRAME_OFS_PC\t\t160\n#define CFRAME_SIZE\t\t192\n#else\n#define CFRAME_OFS_ERRF\t\t124\n#define CFRAME_OFS_NRES\t\t120\n#define CFRAME_OFS_PREV\t\t112\n#define CFRAME_OFS_L\t\t104\n#define CFRAME_OFS_PC\t\t96\n#define CFRAME_SIZE\t\t128\n#endif\n#define CFRAME_OFS_MULTRES\t0\n#define CFRAME_SHIFT_MULTRES\t3\n#else\n#error \"Missing CFRAME_* definitions for this architecture\"\n#endif\n\n#ifndef CFRAME_SIZE_JIT\n#define CFRAME_SIZE_JIT\t\tCFRAME_SIZE\n#endif\n\n#define CFRAME_RESUME\t\t1\n#define CFRAME_UNWIND_FF\t2  /* Only used in unwinder. */\n#define CFRAME_RAWMASK\t\t(~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF))\n\n#define cframe_errfunc(cf)\t(*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF))\n#define cframe_nres(cf)\t\t(*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES))\n#define cframe_prev(cf)\t\t(*(void **)(((char *)(cf))+CFRAME_OFS_PREV))\n#define cframe_multres(cf)  (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES))\n#define cframe_multres_n(cf)\t(cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES)\n#define cframe_L(cf) \\\n  (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th)\n#define cframe_pc(cf) \\\n  (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns))\n#define setcframe_L(cf, L) \\\n  (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L)))\n#define setcframe_pc(cf, pc) \\\n  (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc)))\n#define cframe_canyield(cf)\t((intptr_t)(cf) & CFRAME_RESUME)\n#define cframe_unwind_ff(cf)\t((intptr_t)(cf) & CFRAME_UNWIND_FF)\n#define cframe_raw(cf)\t\t((void *)((intptr_t)(cf) & CFRAME_RAWMASK))\n#define cframe_Lpc(L)\t\tcframe_pc(cframe_raw(L->cframe))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_func.c",
    "content": "/*\n** Function handling (prototypes, functions and upvalues).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_func_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_func.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n\n/* -- Prototypes ---------------------------------------------------------- */\n\nvoid LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt)\n{\n  lj_mem_free(g, pt, pt->sizept);\n}\n\n/* -- Upvalues ------------------------------------------------------------ */\n\nstatic void unlinkuv(global_State *g, GCupval *uv)\n{\n  UNUSED(g);\n  lj_assertG(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv,\n\t     \"broken upvalue chain\");\n  setgcrefr(uvnext(uv)->prev, uv->prev);\n  setgcrefr(uvprev(uv)->next, uv->next);\n}\n\n/* Find existing open upvalue for a stack slot or create a new one. */\nstatic GCupval *func_finduv(lua_State *L, TValue *slot)\n{\n  global_State *g = G(L);\n  GCRef *pp = &L->openupval;\n  GCupval *p;\n  GCupval *uv;\n  /* Search the sorted list of open upvalues. */\n  while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) {\n    lj_assertG(!p->closed && uvval(p) != &p->tv, \"closed upvalue in chain\");\n    if (uvval(p) == slot) {  /* Found open upvalue pointing to same slot? */\n      if (isdead(g, obj2gco(p)))  /* Resurrect it, if it's dead. */\n\tflipwhite(obj2gco(p));\n      return p;\n    }\n    pp = &p->nextgc;\n  }\n  /* No matching upvalue found. Create a new one. */\n  uv = lj_mem_newt(L, sizeof(GCupval), GCupval);\n  newwhite(g, uv);\n  uv->gct = ~LJ_TUPVAL;\n  uv->closed = 0;  /* Still open. */\n  setmref(uv->v, slot);  /* Pointing to the stack slot. */\n  /* NOBARRIER: The GCupval is new (marked white) and open. */\n  setgcrefr(uv->nextgc, *pp);  /* Insert into sorted list of open upvalues. */\n  setgcref(*pp, obj2gco(uv));\n  setgcref(uv->prev, obj2gco(&g->uvhead));  /* Insert into GC list, too. */\n  setgcrefr(uv->next, g->uvhead.next);\n  setgcref(uvnext(uv)->prev, obj2gco(uv));\n  setgcref(g->uvhead.next, obj2gco(uv));\n  lj_assertG(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv,\n\t     \"broken upvalue chain\");\n  return uv;\n}\n\n/* Create an empty and closed upvalue. */\nstatic GCupval *func_emptyuv(lua_State *L)\n{\n  GCupval *uv = (GCupval *)lj_mem_newgco(L, sizeof(GCupval));\n  uv->gct = ~LJ_TUPVAL;\n  uv->closed = 1;\n  setnilV(&uv->tv);\n  setmref(uv->v, &uv->tv);\n  return uv;\n}\n\n/* Close all open upvalues pointing to some stack level or above. */\nvoid LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level)\n{\n  GCupval *uv;\n  global_State *g = G(L);\n  while (gcref(L->openupval) != NULL &&\n\t uvval((uv = gco2uv(gcref(L->openupval)))) >= level) {\n    GCobj *o = obj2gco(uv);\n    lj_assertG(!isblack(o), \"bad black upvalue\");\n    lj_assertG(!uv->closed && uvval(uv) != &uv->tv, \"closed upvalue in chain\");\n    setgcrefr(L->openupval, uv->nextgc);  /* No longer in open list. */\n    if (isdead(g, o)) {\n      lj_func_freeuv(g, uv);\n    } else {\n      unlinkuv(g, uv);\n      lj_gc_closeuv(g, uv);\n    }\n  }\n}\n\nvoid LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv)\n{\n  if (!uv->closed)\n    unlinkuv(g, uv);\n  lj_mem_freet(g, uv);\n}\n\n/* -- Functions (closures) ------------------------------------------------ */\n\nGCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env)\n{\n  GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeCfunc(nelems));\n  fn->c.gct = ~LJ_TFUNC;\n  fn->c.ffid = FF_C;\n  fn->c.nupvalues = (uint8_t)nelems;\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  setmref(fn->c.pc, &G(L)->bc_cfunc_ext);\n  setgcref(fn->c.env, obj2gco(env));\n  return fn;\n}\n\nstatic GCfunc *func_newL(lua_State *L, GCproto *pt, GCtab *env)\n{\n  uint32_t count;\n  GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeLfunc((MSize)pt->sizeuv));\n  fn->l.gct = ~LJ_TFUNC;\n  fn->l.ffid = FF_LUA;\n  fn->l.nupvalues = 0;  /* Set to zero until upvalues are initialized. */\n  /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */\n  setmref(fn->l.pc, proto_bc(pt));\n  setgcref(fn->l.env, obj2gco(env));\n  /* Saturating 3 bit counter (0..7) for created closures. */\n  count = (uint32_t)pt->flags + PROTO_CLCOUNT;\n  pt->flags = (uint8_t)(count - ((count >> PROTO_CLC_BITS) & PROTO_CLCOUNT));\n  return fn;\n}\n\n/* Create a new Lua function with empty upvalues. */\nGCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env)\n{\n  GCfunc *fn = func_newL(L, pt, env);\n  MSize i, nuv = pt->sizeuv;\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  for (i = 0; i < nuv; i++) {\n    GCupval *uv = func_emptyuv(L);\n    int32_t v = proto_uv(pt)[i];\n    uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1);\n    uv->dhash = (uint32_t)(uintptr_t)pt ^ (v << 24);\n    setgcref(fn->l.uvptr[i], obj2gco(uv));\n  }\n  fn->l.nupvalues = (uint8_t)nuv;\n  return fn;\n}\n\n/* Do a GC check and create a new Lua function with inherited upvalues. */\nGCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)\n{\n  GCfunc *fn;\n  GCRef *puv;\n  MSize i, nuv;\n  TValue *base;\n  lj_gc_check_fixtop(L);\n  fn = func_newL(L, pt, tabref(parent->env));\n  /* NOBARRIER: The GCfunc is new (marked white). */\n  puv = parent->uvptr;\n  nuv = pt->sizeuv;\n  base = L->base;\n  for (i = 0; i < nuv; i++) {\n    uint32_t v = proto_uv(pt)[i];\n    GCupval *uv;\n    if ((v & PROTO_UV_LOCAL)) {\n      uv = func_finduv(L, base + (v & 0xff));\n      uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1);\n      uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24);\n    } else {\n      uv = &gcref(puv[v])->uv;\n    }\n    setgcref(fn->l.uvptr[i], obj2gco(uv));\n  }\n  fn->l.nupvalues = (uint8_t)nuv;\n  return fn;\n}\n\nvoid LJ_FASTCALL lj_func_free(global_State *g, GCfunc *fn)\n{\n  MSize size = isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :\n\t\t\t       sizeCfunc((MSize)fn->c.nupvalues);\n  lj_mem_free(g, fn, size);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_func.h",
    "content": "/*\n** Function handling (prototypes, functions and upvalues).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_FUNC_H\n#define _LJ_FUNC_H\n\n#include \"lj_obj.h\"\n\n/* Prototypes. */\nLJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt);\n\n/* Upvalues. */\nLJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level);\nLJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv);\n\n/* Functions (closures). */\nLJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env);\nLJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env);\nLJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent);\nLJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_gc.c",
    "content": "/*\n** Garbage collector.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_gc_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_udata.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n\n#define GCSTEPSIZE\t1024u\n#define GCSWEEPMAX\t40\n#define GCSWEEPCOST\t10\n#define GCFINALIZECOST\t100\n\n/* Macros to set GCobj colors and flags. */\n#define white2gray(x)\t\t((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES)\n#define gray2black(x)\t\t((x)->gch.marked |= LJ_GC_BLACK)\n#define isfinalized(u)\t\t((u)->marked & LJ_GC_FINALIZED)\n\n/* -- Mark phase ---------------------------------------------------------- */\n\n/* Mark a TValue (if needed). */\n#define gc_marktv(g, tv) \\\n  { lj_assertG(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct), \\\n\t       \"TValue and GC type mismatch\"); \\\n    if (tviswhite(tv)) gc_mark(g, gcV(tv)); }\n\n/* Mark a GCobj (if needed). */\n#define gc_markobj(g, o) \\\n  { if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); }\n\n/* Mark a string object. */\n#define gc_mark_str(s)\t\t((s)->marked &= (uint8_t)~LJ_GC_WHITES)\n\n/* Mark a white GCobj. */\nstatic void gc_mark(global_State *g, GCobj *o)\n{\n  int gct = o->gch.gct;\n  lj_assertG(iswhite(o), \"mark of non-white object\");\n  lj_assertG(!isdead(g, o), \"mark of dead object\");\n  white2gray(o);\n  if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) {\n    GCtab *mt = tabref(gco2ud(o)->metatable);\n    gray2black(o);  /* Userdata are never gray. */\n    if (mt) gc_markobj(g, mt);\n    gc_markobj(g, tabref(gco2ud(o)->env));\n    if (LJ_HASBUFFER && gco2ud(o)->udtype == UDTYPE_BUFFER) {\n      SBufExt *sbx = (SBufExt *)uddata(gco2ud(o));\n      if (sbufiscow(sbx) && gcref(sbx->cowref))\n\tgc_markobj(g, gcref(sbx->cowref));\n      if (gcref(sbx->dict_str))\n\tgc_markobj(g, gcref(sbx->dict_str));\n      if (gcref(sbx->dict_mt))\n\tgc_markobj(g, gcref(sbx->dict_mt));\n    }\n  } else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) {\n    GCupval *uv = gco2uv(o);\n    gc_marktv(g, uvval(uv));\n    if (uv->closed)\n      gray2black(o);  /* Closed upvalues are never gray. */\n  } else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) {\n    lj_assertG(gct == ~LJ_TFUNC || gct == ~LJ_TTAB ||\n\t       gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO || gct == ~LJ_TTRACE,\n\t       \"bad GC type %d\", gct);\n    setgcrefr(o->gch.gclist, g->gc.gray);\n    setgcref(g->gc.gray, o);\n  }\n}\n\n/* Mark GC roots. */\nstatic void gc_mark_gcroot(global_State *g)\n{\n  ptrdiff_t i;\n  for (i = 0; i < GCROOT_MAX; i++)\n    if (gcref(g->gcroot[i]) != NULL)\n      gc_markobj(g, gcref(g->gcroot[i]));\n}\n\n/* Start a GC cycle and mark the root set. */\nstatic void gc_mark_start(global_State *g)\n{\n  setgcrefnull(g->gc.gray);\n  setgcrefnull(g->gc.grayagain);\n  setgcrefnull(g->gc.weak);\n  gc_markobj(g, mainthread(g));\n  gc_markobj(g, tabref(mainthread(g)->env));\n  gc_marktv(g, &g->registrytv);\n  gc_mark_gcroot(g);\n  g->gc.state = GCSpropagate;\n}\n\n/* Mark open upvalues. */\nstatic void gc_mark_uv(global_State *g)\n{\n  GCupval *uv;\n  for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {\n    lj_assertG(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv,\n\t       \"broken upvalue chain\");\n    if (isgray(obj2gco(uv)))\n      gc_marktv(g, uvval(uv));\n  }\n}\n\n/* Mark userdata in mmudata list. */\nstatic void gc_mark_mmudata(global_State *g)\n{\n  GCobj *root = gcref(g->gc.mmudata);\n  GCobj *u = root;\n  if (u) {\n    do {\n      u = gcnext(u);\n      makewhite(g, u);  /* Could be from previous GC. */\n      gc_mark(g, u);\n    } while (u != root);\n  }\n}\n\n/* Separate userdata objects to be finalized to mmudata list. */\nsize_t lj_gc_separateudata(global_State *g, int all)\n{\n  size_t m = 0;\n  GCRef *p = &mainthread(g)->nextgc;\n  GCobj *o;\n  while ((o = gcref(*p)) != NULL) {\n    if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) {\n      p = &o->gch.nextgc;  /* Nothing to do. */\n    } else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) {\n      markfinalized(o);  /* Done, as there's no __gc metamethod. */\n      p = &o->gch.nextgc;\n    } else {  /* Otherwise move userdata to be finalized to mmudata list. */\n      m += sizeudata(gco2ud(o));\n      markfinalized(o);\n      *p = o->gch.nextgc;\n      if (gcref(g->gc.mmudata)) {  /* Link to end of mmudata list. */\n\tGCobj *root = gcref(g->gc.mmudata);\n\tsetgcrefr(o->gch.nextgc, root->gch.nextgc);\n\tsetgcref(root->gch.nextgc, o);\n\tsetgcref(g->gc.mmudata, o);\n      } else {  /* Create circular list. */\n\tsetgcref(o->gch.nextgc, o);\n\tsetgcref(g->gc.mmudata, o);\n      }\n    }\n  }\n  return m;\n}\n\n/* -- Propagation phase --------------------------------------------------- */\n\n/* Traverse a table. */\nstatic int gc_traverse_tab(global_State *g, GCtab *t)\n{\n  int weak = 0;\n  cTValue *mode;\n  GCtab *mt = tabref(t->metatable);\n  if (mt)\n    gc_markobj(g, mt);\n  mode = lj_meta_fastg(g, mt, MM_mode);\n  if (mode && tvisstr(mode)) {  /* Valid __mode field? */\n    const char *modestr = strVdata(mode);\n    int c;\n    while ((c = *modestr++)) {\n      if (c == 'k') weak |= LJ_GC_WEAKKEY;\n      else if (c == 'v') weak |= LJ_GC_WEAKVAL;\n    }\n    if (weak) {  /* Weak tables are cleared in the atomic phase. */\n#if LJ_HASFFI\n      CTState *cts = ctype_ctsG(g);\n      if (cts && cts->finalizer == t) {\n\tweak = (int)(~0u & ~LJ_GC_WEAKVAL);\n      } else\n#endif\n      {\n\tt->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);\n\tsetgcrefr(t->gclist, g->gc.weak);\n\tsetgcref(g->gc.weak, obj2gco(t));\n      }\n    }\n  }\n  if (weak == LJ_GC_WEAK)  /* Nothing to mark if both keys/values are weak. */\n    return 1;\n  if (!(weak & LJ_GC_WEAKVAL)) {  /* Mark array part. */\n    MSize i, asize = t->asize;\n    for (i = 0; i < asize; i++)\n      gc_marktv(g, arrayslot(t, i));\n  }\n  if (t->hmask > 0) {  /* Mark hash part. */\n    Node *node = noderef(t->node);\n    MSize i, hmask = t->hmask;\n    for (i = 0; i <= hmask; i++) {\n      Node *n = &node[i];\n      if (!tvisnil(&n->val)) {  /* Mark non-empty slot. */\n\tlj_assertG(!tvisnil(&n->key), \"mark of nil key in non-empty slot\");\n\tif (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key);\n\tif (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val);\n      }\n    }\n  }\n  return weak;\n}\n\n/* Traverse a function. */\nstatic void gc_traverse_func(global_State *g, GCfunc *fn)\n{\n  gc_markobj(g, tabref(fn->c.env));\n  if (isluafunc(fn)) {\n    uint32_t i;\n    lj_assertG(fn->l.nupvalues <= funcproto(fn)->sizeuv,\n\t       \"function upvalues out of range\");\n    gc_markobj(g, funcproto(fn));\n    for (i = 0; i < fn->l.nupvalues; i++)  /* Mark Lua function upvalues. */\n      gc_markobj(g, &gcref(fn->l.uvptr[i])->uv);\n  } else {\n    uint32_t i;\n    for (i = 0; i < fn->c.nupvalues; i++)  /* Mark C function upvalues. */\n      gc_marktv(g, &fn->c.upvalue[i]);\n  }\n}\n\n#if LJ_HASJIT\n/* Mark a trace. */\nstatic void gc_marktrace(global_State *g, TraceNo traceno)\n{\n  GCobj *o = obj2gco(traceref(G2J(g), traceno));\n  lj_assertG(traceno != G2J(g)->cur.traceno, \"active trace escaped\");\n  if (iswhite(o)) {\n    white2gray(o);\n    setgcrefr(o->gch.gclist, g->gc.gray);\n    setgcref(g->gc.gray, o);\n  }\n}\n\n/* Traverse a trace. */\nstatic void gc_traverse_trace(global_State *g, GCtrace *T)\n{\n  IRRef ref;\n  if (T->traceno == 0) return;\n  for (ref = T->nk; ref < REF_TRUE; ref++) {\n    IRIns *ir = &T->ir[ref];\n    if (ir->o == IR_KGC)\n      gc_markobj(g, ir_kgc(ir));\n    if (irt_is64(ir->t) && ir->o != IR_KNULL)\n      ref++;\n  }\n  if (T->link) gc_marktrace(g, T->link);\n  if (T->nextroot) gc_marktrace(g, T->nextroot);\n  if (T->nextside) gc_marktrace(g, T->nextside);\n  gc_markobj(g, gcref(T->startpt));\n}\n\n/* The current trace is a GC root while not anchored in the prototype (yet). */\n#define gc_traverse_curtrace(g)\tgc_traverse_trace(g, &G2J(g)->cur)\n#else\n#define gc_traverse_curtrace(g)\tUNUSED(g)\n#endif\n\n/* Traverse a prototype. */\nstatic void gc_traverse_proto(global_State *g, GCproto *pt)\n{\n  ptrdiff_t i;\n  gc_mark_str(proto_chunkname(pt));\n  for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++)  /* Mark collectable consts. */\n    gc_markobj(g, proto_kgc(pt, i));\n#if LJ_HASJIT\n  if (pt->trace) gc_marktrace(g, pt->trace);\n#endif\n}\n\n/* Traverse the frame structure of a stack. */\nstatic MSize gc_traverse_frames(global_State *g, lua_State *th)\n{\n  TValue *frame, *top = th->top-1, *bot = tvref(th->stack);\n  /* Note: extra vararg frame not skipped, marks function twice (harmless). */\n  for (frame = th->base-1; frame > bot+LJ_FR2; frame = frame_prev(frame)) {\n    GCfunc *fn = frame_func(frame);\n    TValue *ftop = frame;\n    if (isluafunc(fn)) ftop += funcproto(fn)->framesize;\n    if (ftop > top) top = ftop;\n    if (!LJ_FR2) gc_markobj(g, fn);  /* Need to mark hidden function (or L). */\n  }\n  top++;  /* Correct bias of -1 (frame == base-1). */\n  if (top > tvref(th->maxstack)) top = tvref(th->maxstack);\n  return (MSize)(top - bot);  /* Return minimum needed stack size. */\n}\n\n/* Traverse a thread object. */\nstatic void gc_traverse_thread(global_State *g, lua_State *th)\n{\n  TValue *o, *top = th->top;\n  for (o = tvref(th->stack)+1+LJ_FR2; o < top; o++)\n    gc_marktv(g, o);\n  if (g->gc.state == GCSatomic) {\n    top = tvref(th->stack) + th->stacksize;\n    for (; o < top; o++)  /* Clear unmarked slots. */\n      setnilV(o);\n  }\n  gc_markobj(g, tabref(th->env));\n  lj_state_shrinkstack(th, gc_traverse_frames(g, th));\n}\n\n/* Propagate one gray object. Traverse it and turn it black. */\nstatic size_t propagatemark(global_State *g)\n{\n  GCobj *o = gcref(g->gc.gray);\n  int gct = o->gch.gct;\n  lj_assertG(isgray(o), \"propagation of non-gray object\");\n  gray2black(o);\n  setgcrefr(g->gc.gray, o->gch.gclist);  /* Remove from gray list. */\n  if (LJ_LIKELY(gct == ~LJ_TTAB)) {\n    GCtab *t = gco2tab(o);\n    if (gc_traverse_tab(g, t) > 0)\n      black2gray(o);  /* Keep weak tables gray. */\n    return sizeof(GCtab) + sizeof(TValue) * t->asize +\n\t\t\t   (t->hmask ? sizeof(Node) * (t->hmask + 1) : 0);\n  } else if (LJ_LIKELY(gct == ~LJ_TFUNC)) {\n    GCfunc *fn = gco2func(o);\n    gc_traverse_func(g, fn);\n    return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :\n\t\t\t   sizeCfunc((MSize)fn->c.nupvalues);\n  } else if (LJ_LIKELY(gct == ~LJ_TPROTO)) {\n    GCproto *pt = gco2pt(o);\n    gc_traverse_proto(g, pt);\n    return pt->sizept;\n  } else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) {\n    lua_State *th = gco2th(o);\n    setgcrefr(th->gclist, g->gc.grayagain);\n    setgcref(g->gc.grayagain, o);\n    black2gray(o);  /* Threads are never black. */\n    gc_traverse_thread(g, th);\n    return sizeof(lua_State) + sizeof(TValue) * th->stacksize;\n  } else {\n#if LJ_HASJIT\n    GCtrace *T = gco2trace(o);\n    gc_traverse_trace(g, T);\n    return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +\n\t   T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry);\n#else\n    lj_assertG(0, \"bad GC type %d\", gct);\n    return 0;\n#endif\n  }\n}\n\n/* Propagate all gray objects. */\nstatic size_t gc_propagate_gray(global_State *g)\n{\n  size_t m = 0;\n  while (gcref(g->gc.gray) != NULL)\n    m += propagatemark(g);\n  return m;\n}\n\n/* -- Sweep phase --------------------------------------------------------- */\n\n/* Type of GC free functions. */\ntypedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o);\n\n/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */\nstatic const GCFreeFunc gc_freefunc[] = {\n  (GCFreeFunc)lj_str_free,\n  (GCFreeFunc)lj_func_freeuv,\n  (GCFreeFunc)lj_state_free,\n  (GCFreeFunc)lj_func_freeproto,\n  (GCFreeFunc)lj_func_free,\n#if LJ_HASJIT\n  (GCFreeFunc)lj_trace_free,\n#else\n  (GCFreeFunc)0,\n#endif\n#if LJ_HASFFI\n  (GCFreeFunc)lj_cdata_free,\n#else\n  (GCFreeFunc)0,\n#endif\n  (GCFreeFunc)lj_tab_free,\n  (GCFreeFunc)lj_udata_free\n};\n\n/* Full sweep of a GC list. */\n#define gc_fullsweep(g, p)\tgc_sweep(g, (p), ~(uint32_t)0)\n\n/* Partial sweep of a GC list. */\nstatic GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim)\n{\n  /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */\n  int ow = otherwhite(g);\n  GCobj *o;\n  while ((o = gcref(*p)) != NULL && lim-- > 0) {\n    if (o->gch.gct == ~LJ_TTHREAD)  /* Need to sweep open upvalues, too. */\n      gc_fullsweep(g, &gco2th(o)->openupval);\n    if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) {  /* Black or current white? */\n      lj_assertG(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED),\n\t\t \"sweep of undead object\");\n      makewhite(g, o);  /* Value is alive, change to the current white. */\n      p = &o->gch.nextgc;\n    } else {  /* Otherwise value is dead, free it. */\n      lj_assertG(isdead(g, o) || ow == LJ_GC_SFIXED,\n\t\t \"sweep of unlive object\");\n      setgcrefr(*p, o->gch.nextgc);\n      if (o == gcref(g->gc.root))\n\tsetgcrefr(g->gc.root, o->gch.nextgc);  /* Adjust list anchor. */\n      gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o);\n    }\n  }\n  return p;\n}\n\n/* Sweep one string interning table chain. Preserves hashalg bit. */\nstatic void gc_sweepstr(global_State *g, GCRef *chain)\n{\n  /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */\n  int ow = otherwhite(g);\n  uintptr_t u = gcrefu(*chain);\n  GCRef q;\n  GCRef *p = &q;\n  GCobj *o;\n  setgcrefp(q, (u & ~(uintptr_t)1));\n  while ((o = gcref(*p)) != NULL) {\n    if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) {  /* Black or current white? */\n      lj_assertG(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED),\n\t\t \"sweep of undead string\");\n      makewhite(g, o);  /* String is alive, change to the current white. */\n      p = &o->gch.nextgc;\n    } else {  /* Otherwise string is dead, free it. */\n      lj_assertG(isdead(g, o) || ow == LJ_GC_SFIXED,\n\t\t \"sweep of unlive string\");\n      setgcrefr(*p, o->gch.nextgc);\n      lj_str_free(g, gco2str(o));\n    }\n  }\n  setgcrefp(*chain, (gcrefu(q) | (u & 1)));\n}\n\n/* Check whether we can clear a key or a value slot from a table. */\nstatic int gc_mayclear(cTValue *o, int val)\n{\n  if (tvisgcv(o)) {  /* Only collectable objects can be weak references. */\n    if (tvisstr(o)) {  /* But strings cannot be used as weak references. */\n      gc_mark_str(strV(o));  /* And need to be marked. */\n      return 0;\n    }\n    if (iswhite(gcV(o)))\n      return 1;  /* Object is about to be collected. */\n    if (tvisudata(o) && val && isfinalized(udataV(o)))\n      return 1;  /* Finalized userdata is dropped only from values. */\n  }\n  return 0;  /* Cannot clear. */\n}\n\n/* Clear collected entries from weak tables. */\nstatic void gc_clearweak(global_State *g, GCobj *o)\n{\n  UNUSED(g);\n  while (o) {\n    GCtab *t = gco2tab(o);\n    lj_assertG((t->marked & LJ_GC_WEAK), \"clear of non-weak table\");\n    if ((t->marked & LJ_GC_WEAKVAL)) {\n      MSize i, asize = t->asize;\n      for (i = 0; i < asize; i++) {\n\t/* Clear array slot when value is about to be collected. */\n\tTValue *tv = arrayslot(t, i);\n\tif (gc_mayclear(tv, 1))\n\t  setnilV(tv);\n      }\n    }\n    if (t->hmask > 0) {\n      Node *node = noderef(t->node);\n      MSize i, hmask = t->hmask;\n      for (i = 0; i <= hmask; i++) {\n\tNode *n = &node[i];\n\t/* Clear hash slot when key or value is about to be collected. */\n\tif (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) ||\n\t\t\t\t  gc_mayclear(&n->val, 1)))\n\t  setnilV(&n->val);\n      }\n    }\n    o = gcref(t->gclist);\n  }\n}\n\n/* Call a userdata or cdata finalizer. */\nstatic void gc_call_finalizer(global_State *g, lua_State *L,\n\t\t\t      cTValue *mo, GCobj *o)\n{\n  /* Save and restore lots of state around the __gc callback. */\n  uint8_t oldh = hook_save(g);\n  GCSize oldt = g->gc.threshold;\n  int errcode;\n  TValue *top;\n  lj_trace_abort(g);\n  hook_entergc(g);  /* Disable hooks and new traces during __gc. */\n  if (LJ_HASPROFILE && (oldh & HOOK_PROFILE)) lj_dispatch_update(g);\n  g->gc.threshold = LJ_MAX_MEM;  /* Prevent GC steps. */\n  top = L->top;\n  copyTV(L, top++, mo);\n  if (LJ_FR2) setnilV(top++);\n  setgcV(L, top, o, ~o->gch.gct);\n  L->top = top+1;\n  errcode = lj_vm_pcall(L, top, 1+0, -1);  /* Stack: |mo|o| -> | */\n  hook_restore(g, oldh);\n  if (LJ_HASPROFILE && (oldh & HOOK_PROFILE)) lj_dispatch_update(g);\n  g->gc.threshold = oldt;  /* Restore GC threshold. */\n  if (errcode)\n    lj_err_throw(L, errcode);  /* Propagate errors. */\n}\n\n/* Finalize one userdata or cdata object from the mmudata list. */\nstatic void gc_finalize(lua_State *L)\n{\n  global_State *g = G(L);\n  GCobj *o = gcnext(gcref(g->gc.mmudata));\n  cTValue *mo;\n  lj_assertG(tvref(g->jit_base) == NULL, \"finalizer called on trace\");\n  /* Unchain from list of userdata to be finalized. */\n  if (o == gcref(g->gc.mmudata))\n    setgcrefnull(g->gc.mmudata);\n  else\n    setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc);\n#if LJ_HASFFI\n  if (o->gch.gct == ~LJ_TCDATA) {\n    TValue tmp, *tv;\n    /* Add cdata back to the GC list and make it white. */\n    setgcrefr(o->gch.nextgc, g->gc.root);\n    setgcref(g->gc.root, o);\n    makewhite(g, o);\n    o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;\n    /* Resolve finalizer. */\n    setcdataV(L, &tmp, gco2cd(o));\n    tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp);\n    if (!tvisnil(tv)) {\n      g->gc.nocdatafin = 0;\n      copyTV(L, &tmp, tv);\n      setnilV(tv);  /* Clear entry in finalizer table. */\n      gc_call_finalizer(g, L, &tmp, o);\n    }\n    return;\n  }\n#endif\n  /* Add userdata back to the main userdata list and make it white. */\n  setgcrefr(o->gch.nextgc, mainthread(g)->nextgc);\n  setgcref(mainthread(g)->nextgc, o);\n  makewhite(g, o);\n  /* Resolve the __gc metamethod. */\n  mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc);\n  if (mo)\n    gc_call_finalizer(g, L, mo, o);\n}\n\n/* Finalize all userdata objects from mmudata list. */\nvoid lj_gc_finalize_udata(lua_State *L)\n{\n  while (gcref(G(L)->gc.mmudata) != NULL)\n    gc_finalize(L);\n}\n\n#if LJ_HASFFI\n/* Finalize all cdata objects from finalizer table. */\nvoid lj_gc_finalize_cdata(lua_State *L)\n{\n  global_State *g = G(L);\n  CTState *cts = ctype_ctsG(g);\n  if (cts) {\n    GCtab *t = cts->finalizer;\n    Node *node = noderef(t->node);\n    ptrdiff_t i;\n    setgcrefnull(t->metatable);  /* Mark finalizer table as disabled. */\n    for (i = (ptrdiff_t)t->hmask; i >= 0; i--)\n      if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) {\n\tGCobj *o = gcV(&node[i].key);\n\tTValue tmp;\n\tmakewhite(g, o);\n\to->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;\n\tcopyTV(L, &tmp, &node[i].val);\n\tsetnilV(&node[i].val);\n\tgc_call_finalizer(g, L, &tmp, o);\n      }\n  }\n}\n#endif\n\n/* Free all remaining GC objects. */\nvoid lj_gc_freeall(global_State *g)\n{\n  MSize i, strmask;\n  /* Free everything, except super-fixed objects (the main thread). */\n  g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED;\n  gc_fullsweep(g, &g->gc.root);\n  strmask = g->str.mask;\n  for (i = 0; i <= strmask; i++)  /* Free all string hash chains. */\n    gc_sweepstr(g, &g->str.tab[i]);\n}\n\n/* -- Collector ----------------------------------------------------------- */\n\n/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */\nstatic void atomic(global_State *g, lua_State *L)\n{\n  size_t udsize;\n\n  gc_mark_uv(g);  /* Need to remark open upvalues (the thread may be dead). */\n  gc_propagate_gray(g);  /* Propagate any left-overs. */\n\n  setgcrefr(g->gc.gray, g->gc.weak);  /* Empty the list of weak tables. */\n  setgcrefnull(g->gc.weak);\n  lj_assertG(!iswhite(obj2gco(mainthread(g))), \"main thread turned white\");\n  gc_markobj(g, L);  /* Mark running thread. */\n  gc_traverse_curtrace(g);  /* Traverse current trace. */\n  gc_mark_gcroot(g);  /* Mark GC roots (again). */\n  gc_propagate_gray(g);  /* Propagate all of the above. */\n\n  setgcrefr(g->gc.gray, g->gc.grayagain);  /* Empty the 2nd chance list. */\n  setgcrefnull(g->gc.grayagain);\n  gc_propagate_gray(g);  /* Propagate it. */\n\n  udsize = lj_gc_separateudata(g, 0);  /* Separate userdata to be finalized. */\n  gc_mark_mmudata(g);  /* Mark them. */\n  udsize += gc_propagate_gray(g);  /* And propagate the marks. */\n\n  /* All marking done, clear weak tables. */\n  gc_clearweak(g, gcref(g->gc.weak));\n\n  lj_buf_shrink(L, &g->tmpbuf);  /* Shrink temp buffer. */\n\n  /* Prepare for sweep phase. */\n  g->gc.currentwhite = (uint8_t)otherwhite(g);  /* Flip current white. */\n  g->strempty.marked = g->gc.currentwhite;\n  setmref(g->gc.sweep, &g->gc.root);\n  g->gc.estimate = g->gc.total - (GCSize)udsize;  /* Initial estimate. */\n}\n\n/* GC state machine. Returns a cost estimate for each step performed. */\nstatic size_t gc_onestep(lua_State *L)\n{\n  global_State *g = G(L);\n  switch (g->gc.state) {\n  case GCSpause:\n    gc_mark_start(g);  /* Start a new GC cycle by marking all GC roots. */\n    return 0;\n  case GCSpropagate:\n    if (gcref(g->gc.gray) != NULL)\n      return propagatemark(g);  /* Propagate one gray object. */\n    g->gc.state = GCSatomic;  /* End of mark phase. */\n    return 0;\n  case GCSatomic:\n    if (tvref(g->jit_base))  /* Don't run atomic phase on trace. */\n      return LJ_MAX_MEM;\n    atomic(g, L);\n    g->gc.state = GCSsweepstring;  /* Start of sweep phase. */\n    g->gc.sweepstr = 0;\n    return 0;\n  case GCSsweepstring: {\n    GCSize old = g->gc.total;\n    gc_sweepstr(g, &g->str.tab[g->gc.sweepstr++]);  /* Sweep one chain. */\n    if (g->gc.sweepstr > g->str.mask)\n      g->gc.state = GCSsweep;  /* All string hash chains sweeped. */\n    lj_assertG(old >= g->gc.total, \"sweep increased memory\");\n    g->gc.estimate -= old - g->gc.total;\n    return GCSWEEPCOST;\n    }\n  case GCSsweep: {\n    GCSize old = g->gc.total;\n    setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));\n    lj_assertG(old >= g->gc.total, \"sweep increased memory\");\n    g->gc.estimate -= old - g->gc.total;\n    if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {\n      if (g->str.num <= (g->str.mask >> 2) && g->str.mask > LJ_MIN_STRTAB*2-1)\n\tlj_str_resize(L, g->str.mask >> 1);  /* Shrink string table. */\n      if (gcref(g->gc.mmudata)) {  /* Need any finalizations? */\n\tg->gc.state = GCSfinalize;\n#if LJ_HASFFI\n\tg->gc.nocdatafin = 1;\n#endif\n      } else {  /* Otherwise skip this phase to help the JIT. */\n\tg->gc.state = GCSpause;  /* End of GC cycle. */\n\tg->gc.debt = 0;\n      }\n    }\n    return GCSWEEPMAX*GCSWEEPCOST;\n    }\n  case GCSfinalize:\n    if (gcref(g->gc.mmudata) != NULL) {\n      if (tvref(g->jit_base))  /* Don't call finalizers on trace. */\n\treturn LJ_MAX_MEM;\n      gc_finalize(L);  /* Finalize one userdata object. */\n      if (g->gc.estimate > GCFINALIZECOST)\n\tg->gc.estimate -= GCFINALIZECOST;\n      return GCFINALIZECOST;\n    }\n#if LJ_HASFFI\n    if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer);\n#endif\n    g->gc.state = GCSpause;  /* End of GC cycle. */\n    g->gc.debt = 0;\n    return 0;\n  default:\n    lj_assertG(0, \"bad GC state\");\n    return 0;\n  }\n}\n\n/* Perform a limited amount of incremental GC steps. */\nint LJ_FASTCALL lj_gc_step(lua_State *L)\n{\n  global_State *g = G(L);\n  GCSize lim;\n  int32_t ostate = g->vmstate;\n  setvmstate(g, GC);\n  lim = (GCSTEPSIZE/100) * g->gc.stepmul;\n  if (lim == 0)\n    lim = LJ_MAX_MEM;\n  if (g->gc.total > g->gc.threshold)\n    g->gc.debt += g->gc.total - g->gc.threshold;\n  do {\n    lim -= (GCSize)gc_onestep(L);\n    if (g->gc.state == GCSpause) {\n      g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;\n      g->vmstate = ostate;\n      return 1;  /* Finished a GC cycle. */\n    }\n  } while (sizeof(lim) == 8 ? ((int64_t)lim > 0) : ((int32_t)lim > 0));\n  if (g->gc.debt < GCSTEPSIZE) {\n    g->gc.threshold = g->gc.total + GCSTEPSIZE;\n    g->vmstate = ostate;\n    return -1;\n  } else {\n    g->gc.debt -= GCSTEPSIZE;\n    g->gc.threshold = g->gc.total;\n    g->vmstate = ostate;\n    return 0;\n  }\n}\n\n/* Ditto, but fix the stack top first. */\nvoid LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)\n{\n  if (curr_funcisL(L)) L->top = curr_topL(L);\n  lj_gc_step(L);\n}\n\n#if LJ_HASJIT\n/* Perform multiple GC steps. Called from JIT-compiled code. */\nint LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)\n{\n  lua_State *L = gco2th(gcref(g->cur_L));\n  L->base = tvref(G(L)->jit_base);\n  L->top = curr_topL(L);\n  while (steps-- > 0 && lj_gc_step(L) == 0)\n    ;\n  /* Return 1 to force a trace exit. */\n  return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize);\n}\n#endif\n\n/* Perform a full GC cycle. */\nvoid lj_gc_fullgc(lua_State *L)\n{\n  global_State *g = G(L);\n  int32_t ostate = g->vmstate;\n  setvmstate(g, GC);\n  if (g->gc.state <= GCSatomic) {  /* Caught somewhere in the middle. */\n    setmref(g->gc.sweep, &g->gc.root);  /* Sweep everything (preserving it). */\n    setgcrefnull(g->gc.gray);  /* Reset lists from partial propagation. */\n    setgcrefnull(g->gc.grayagain);\n    setgcrefnull(g->gc.weak);\n    g->gc.state = GCSsweepstring;  /* Fast forward to the sweep phase. */\n    g->gc.sweepstr = 0;\n  }\n  while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep)\n    gc_onestep(L);  /* Finish sweep. */\n  lj_assertG(g->gc.state == GCSfinalize || g->gc.state == GCSpause,\n\t     \"bad GC state\");\n  /* Now perform a full GC. */\n  g->gc.state = GCSpause;\n  do { gc_onestep(L); } while (g->gc.state != GCSpause);\n  g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;\n  g->vmstate = ostate;\n}\n\n/* -- Write barriers ------------------------------------------------------ */\n\n/* Move the GC propagation frontier forward. */\nvoid lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v)\n{\n  lj_assertG(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o),\n\t     \"bad object states for forward barrier\");\n  lj_assertG(g->gc.state != GCSfinalize && g->gc.state != GCSpause,\n\t     \"bad GC state\");\n  lj_assertG(o->gch.gct != ~LJ_TTAB, \"barrier object is not a table\");\n  /* Preserve invariant during propagation. Otherwise it doesn't matter. */\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_mark(g, v);  /* Move frontier forward. */\n  else\n    makewhite(g, o);  /* Make it white to avoid the following barrier. */\n}\n\n/* Specialized barrier for closed upvalue. Pass &uv->tv. */\nvoid LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv)\n{\n#define TV2MARKED(x) \\\n  (*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked)))\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_mark(g, gcV(tv));\n  else\n    TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g);\n#undef TV2MARKED\n}\n\n/* Close upvalue. Also needs a write barrier. */\nvoid lj_gc_closeuv(global_State *g, GCupval *uv)\n{\n  GCobj *o = obj2gco(uv);\n  /* Copy stack slot to upvalue itself and point to the copy. */\n  copyTV(mainthread(g), &uv->tv, uvval(uv));\n  setmref(uv->v, &uv->tv);\n  uv->closed = 1;\n  setgcrefr(o->gch.nextgc, g->gc.root);\n  setgcref(g->gc.root, o);\n  if (isgray(o)) {  /* A closed upvalue is never gray, so fix this. */\n    if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) {\n      gray2black(o);  /* Make it black and preserve invariant. */\n      if (tviswhite(&uv->tv))\n\tlj_gc_barrierf(g, o, gcV(&uv->tv));\n    } else {\n      makewhite(g, o);  /* Make it white, i.e. sweep the upvalue. */\n      lj_assertG(g->gc.state != GCSfinalize && g->gc.state != GCSpause,\n\t\t \"bad GC state\");\n    }\n  }\n}\n\n#if LJ_HASJIT\n/* Mark a trace if it's saved during the propagation phase. */\nvoid lj_gc_barriertrace(global_State *g, uint32_t traceno)\n{\n  if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)\n    gc_marktrace(g, traceno);\n}\n#endif\n\n/* -- Allocator ----------------------------------------------------------- */\n\n/* Call pluggable memory allocator to allocate or resize a fragment. */\nvoid *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz)\n{\n  global_State *g = G(L);\n  lj_assertG((osz == 0) == (p == NULL), \"realloc API violation\");\n  p = g->allocf(g->allocd, p, osz, nsz);\n  if (p == NULL && nsz > 0)\n    lj_err_mem(L);\n  lj_assertG((nsz == 0) == (p == NULL), \"allocf API violation\");\n  lj_assertG(checkptrGC(p),\n\t     \"allocated memory address %p outside required range\", p);\n  g->gc.total = (g->gc.total - osz) + nsz;\n  return p;\n}\n\n/* Allocate new GC object and link it to the root set. */\nvoid * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size)\n{\n  global_State *g = G(L);\n  GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size);\n  if (o == NULL)\n    lj_err_mem(L);\n  lj_assertG(checkptrGC(o),\n\t     \"allocated memory address %p outside required range\", o);\n  g->gc.total += size;\n  setgcrefr(o->gch.nextgc, g->gc.root);\n  setgcref(g->gc.root, o);\n  newwhite(g, o);\n  return o;\n}\n\n/* Resize growable vector. */\nvoid *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz)\n{\n  MSize sz = (*szp) << 1;\n  if (sz < LJ_MIN_VECSZ)\n    sz = LJ_MIN_VECSZ;\n  if (sz > lim)\n    sz = lim;\n  p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz);\n  *szp = sz;\n  return p;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_gc.h",
    "content": "/*\n** Garbage collector.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_GC_H\n#define _LJ_GC_H\n\n#include \"lj_obj.h\"\n\n/* Garbage collector states. Order matters. */\nenum {\n  GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize\n};\n\n/* Bitmasks for marked field of GCobj. */\n#define LJ_GC_WHITE0\t0x01\n#define LJ_GC_WHITE1\t0x02\n#define LJ_GC_BLACK\t0x04\n#define LJ_GC_FINALIZED\t0x08\n#define LJ_GC_WEAKKEY\t0x08\n#define LJ_GC_WEAKVAL\t0x10\n#define LJ_GC_CDATA_FIN\t0x10\n#define LJ_GC_FIXED\t0x20\n#define LJ_GC_SFIXED\t0x40\n\n#define LJ_GC_WHITES\t(LJ_GC_WHITE0 | LJ_GC_WHITE1)\n#define LJ_GC_COLORS\t(LJ_GC_WHITES | LJ_GC_BLACK)\n#define LJ_GC_WEAK\t(LJ_GC_WEAKKEY | LJ_GC_WEAKVAL)\n\n/* Macros to test and set GCobj colors. */\n#define iswhite(x)\t((x)->gch.marked & LJ_GC_WHITES)\n#define isblack(x)\t((x)->gch.marked & LJ_GC_BLACK)\n#define isgray(x)\t(!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES)))\n#define tviswhite(x)\t(tvisgcv(x) && iswhite(gcV(x)))\n#define otherwhite(g)\t(g->gc.currentwhite ^ LJ_GC_WHITES)\n#define isdead(g, v)\t((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES)\n\n#define curwhite(g)\t((g)->gc.currentwhite & LJ_GC_WHITES)\n#define newwhite(g, x)\t(obj2gco(x)->gch.marked = (uint8_t)curwhite(g))\n#define makewhite(g, x) \\\n  ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))\n#define flipwhite(x)\t((x)->gch.marked ^= LJ_GC_WHITES)\n#define black2gray(x)\t((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)\n#define fixstring(s)\t((s)->marked |= LJ_GC_FIXED)\n#define markfinalized(x)\t((x)->gch.marked |= LJ_GC_FINALIZED)\n\n/* Collector. */\nLJ_FUNC size_t lj_gc_separateudata(global_State *g, int all);\nLJ_FUNC void lj_gc_finalize_udata(lua_State *L);\n#if LJ_HASFFI\nLJ_FUNC void lj_gc_finalize_cdata(lua_State *L);\n#else\n#define lj_gc_finalize_cdata(L)\t\tUNUSED(L)\n#endif\nLJ_FUNC void lj_gc_freeall(global_State *g);\nLJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L);\nLJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L);\n#if LJ_HASJIT\nLJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps);\n#endif\nLJ_FUNC void lj_gc_fullgc(lua_State *L);\n\n/* GC check: drive collector forward if the GC threshold has been reached. */\n#define lj_gc_check(L) \\\n  { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \\\n      lj_gc_step(L); }\n#define lj_gc_check_fixtop(L) \\\n  { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \\\n      lj_gc_step_fixtop(L); }\n\n/* Write barriers. */\nLJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v);\nLJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv);\nLJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv);\n#if LJ_HASJIT\nLJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno);\n#endif\n\n/* Move the GC propagation frontier back for tables (make it gray again). */\nstatic LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)\n{\n  GCobj *o = obj2gco(t);\n  lj_assertG(isblack(o) && !isdead(g, o),\n\t     \"bad object states for backward barrier\");\n  lj_assertG(g->gc.state != GCSfinalize && g->gc.state != GCSpause,\n\t     \"bad GC state\");\n  black2gray(o);\n  setgcrefr(t->gclist, g->gc.grayagain);\n  setgcref(g->gc.grayagain, o);\n}\n\n/* Barrier for stores to table objects. TValue and GCobj variant. */\n#define lj_gc_anybarriert(L, t)  \\\n  { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); }\n#define lj_gc_barriert(L, t, tv) \\\n  { if (tviswhite(tv) && isblack(obj2gco(t))) \\\n      lj_gc_barrierback(G(L), (t)); }\n#define lj_gc_objbarriert(L, t, o)  \\\n  { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \\\n      lj_gc_barrierback(G(L), (t)); }\n\n/* Barrier for stores to any other object. TValue and GCobj variant. */\n#define lj_gc_barrier(L, p, tv) \\\n  { if (tviswhite(tv) && isblack(obj2gco(p))) \\\n      lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); }\n#define lj_gc_objbarrier(L, p, o) \\\n  { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \\\n      lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }\n\n/* Allocator. */\nLJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz);\nLJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size);\nLJ_FUNC void *lj_mem_grow(lua_State *L, void *p,\n\t\t\t  MSize *szp, MSize lim, MSize esz);\n\n#define lj_mem_new(L, s)\tlj_mem_realloc(L, NULL, 0, (s))\n\nstatic LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)\n{\n  g->gc.total -= (GCSize)osize;\n  g->allocf(g->allocd, p, osize, 0);\n}\n\n#define lj_mem_newvec(L, n, t)\t((t *)lj_mem_new(L, (GCSize)((n)*sizeof(t))))\n#define lj_mem_reallocvec(L, p, on, n, t) \\\n  ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (GCSize)((n)*sizeof(t))))\n#define lj_mem_growvec(L, p, n, m, t) \\\n  ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))\n#define lj_mem_freevec(g, p, n, t)\tlj_mem_free(g, (p), (n)*sizeof(t))\n\n#define lj_mem_newobj(L, t)\t((t *)lj_mem_newgco(L, sizeof(t)))\n#define lj_mem_newt(L, s, t)\t((t *)lj_mem_new(L, (s)))\n#define lj_mem_freet(g, p)\tlj_mem_free(g, (p), sizeof(*(p)))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_gdbjit.c",
    "content": "/*\n** Client for the GDB JIT API.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_gdbjit_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_frame.h\"\n#include \"lj_buf.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_jit.h\"\n#include \"lj_dispatch.h\"\n\n/* This is not compiled in by default.\n** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything.\n*/\n#ifdef LUAJIT_USE_GDBJIT\n\n/* The GDB JIT API allows JIT compilers to pass debug information about\n** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher\n** to see it in action.\n**\n** This is a passive API, so it works even when not running under GDB\n** or when attaching to an already running process. Alas, this implies\n** enabling it always has a non-negligible overhead -- do not use in\n** release mode!\n**\n** The LuaJIT GDB JIT client is rather minimal at the moment. It gives\n** each trace a symbol name and adds a source location and frame unwind\n** information. Obviously LuaJIT itself and any embedding C application\n** should be compiled with debug symbols, too (see the Makefile).\n**\n** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace\n** numbers from -jv or -jdump. Use \"break TRACE_1\" or \"tbreak TRACE_1\" etc.\n** to set breakpoints on specific traces (even ahead of their creation).\n**\n** The source location for each trace allows listing the corresponding\n** source lines with the GDB command \"list\" (but only if the Lua source\n** has been loaded from a file). Currently this is always set to the\n** location where the trace has been started.\n**\n** Frame unwind information can be inspected with the GDB command\n** \"info frame\". This also allows proper backtraces across JIT-compiled\n** code with the GDB command \"bt\".\n**\n** You probably want to add the following settings to a .gdbinit file\n** (or add them to ~/.gdbinit):\n**   set disassembly-flavor intel\n**   set breakpoint pending on\n**\n** Here's a sample GDB session:\n** ------------------------------------------------------------------------\n\n$ cat >x.lua\nfor outer=1,100 do\n  for inner=1,100 do end\nend\n^D\n\n$ luajit -jv x.lua\n[TRACE   1 x.lua:2]\n[TRACE   2 (1/3) x.lua:1 -> 1]\n\n$ gdb --quiet --args luajit x.lua\n(gdb) tbreak TRACE_1\nFunction \"TRACE_1\" not defined.\nTemporary breakpoint 1 (TRACE_1) pending.\n(gdb) run\nStarting program: luajit x.lua\n\nTemporary breakpoint 1, TRACE_1 () at x.lua:2\n2\t  for inner=1,100 do end\n(gdb) list\n1\tfor outer=1,100 do\n2\t  for inner=1,100 do end\n3\tend\n(gdb) bt\n#0  TRACE_1 () at x.lua:2\n#1  0x08053690 in lua_pcall [...]\n[...]\n#7  0x0806ff90 in main [...]\n(gdb) disass TRACE_1\nDump of assembler code for function TRACE_1:\n0xf7fd9fba <TRACE_1+0>:\tmov    DWORD PTR ds:0xf7e0e2a0,0x1\n0xf7fd9fc4 <TRACE_1+10>:\tmovsd  xmm7,QWORD PTR [edx+0x20]\n[...]\n0xf7fd9ff8 <TRACE_1+62>:\tjmp    0xf7fd2014\nEnd of assembler dump.\n(gdb) tbreak TRACE_2\nFunction \"TRACE_2\" not defined.\nTemporary breakpoint 2 (TRACE_2) pending.\n(gdb) cont\nContinuing.\n\nTemporary breakpoint 2, TRACE_2 () at x.lua:1\n1\tfor outer=1,100 do\n(gdb) info frame\nStack level 0, frame at 0xffffd7c0:\n eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690\n called by frame at 0xffffd7e0\n source language unknown.\n Arglist at 0xffffd78c, args:\n Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0\n Saved registers:\n  ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4,\n  eip at 0xffffd7bc\n(gdb)\n\n** ------------------------------------------------------------------------\n*/\n\n/* -- GDB JIT API --------------------------------------------------------- */\n\n/* GDB JIT actions. */\nenum {\n  GDBJIT_NOACTION = 0,\n  GDBJIT_REGISTER,\n  GDBJIT_UNREGISTER\n};\n\n/* GDB JIT entry. */\ntypedef struct GDBJITentry {\n  struct GDBJITentry *next_entry;\n  struct GDBJITentry *prev_entry;\n  const char *symfile_addr;\n  uint64_t symfile_size;\n} GDBJITentry;\n\n/* GDB JIT descriptor. */\ntypedef struct GDBJITdesc {\n  uint32_t version;\n  uint32_t action_flag;\n  GDBJITentry *relevant_entry;\n  GDBJITentry *first_entry;\n} GDBJITdesc;\n\nGDBJITdesc __jit_debug_descriptor = {\n  1, GDBJIT_NOACTION, NULL, NULL\n};\n\n/* GDB sets a breakpoint at this function. */\nvoid LJ_NOINLINE __jit_debug_register_code()\n{\n  __asm__ __volatile__(\"\");\n};\n\n/* -- In-memory ELF object definitions ------------------------------------ */\n\n/* ELF definitions. */\ntypedef struct ELFheader {\n  uint8_t emagic[4];\n  uint8_t eclass;\n  uint8_t eendian;\n  uint8_t eversion;\n  uint8_t eosabi;\n  uint8_t eabiversion;\n  uint8_t epad[7];\n  uint16_t type;\n  uint16_t machine;\n  uint32_t version;\n  uintptr_t entry;\n  uintptr_t phofs;\n  uintptr_t shofs;\n  uint32_t flags;\n  uint16_t ehsize;\n  uint16_t phentsize;\n  uint16_t phnum;\n  uint16_t shentsize;\n  uint16_t shnum;\n  uint16_t shstridx;\n} ELFheader;\n\ntypedef struct ELFsectheader {\n  uint32_t name;\n  uint32_t type;\n  uintptr_t flags;\n  uintptr_t addr;\n  uintptr_t ofs;\n  uintptr_t size;\n  uint32_t link;\n  uint32_t info;\n  uintptr_t align;\n  uintptr_t entsize;\n} ELFsectheader;\n\n#define ELFSECT_IDX_ABS\t\t0xfff1\n\nenum {\n  ELFSECT_TYPE_PROGBITS = 1,\n  ELFSECT_TYPE_SYMTAB = 2,\n  ELFSECT_TYPE_STRTAB = 3,\n  ELFSECT_TYPE_NOBITS = 8\n};\n\n#define ELFSECT_FLAGS_WRITE\t1\n#define ELFSECT_FLAGS_ALLOC\t2\n#define ELFSECT_FLAGS_EXEC\t4\n\ntypedef struct ELFsymbol {\n#if LJ_64\n  uint32_t name;\n  uint8_t info;\n  uint8_t other;\n  uint16_t sectidx;\n  uintptr_t value;\n  uint64_t size;\n#else\n  uint32_t name;\n  uintptr_t value;\n  uint32_t size;\n  uint8_t info;\n  uint8_t other;\n  uint16_t sectidx;\n#endif\n} ELFsymbol;\n\nenum {\n  ELFSYM_TYPE_FUNC = 2,\n  ELFSYM_TYPE_FILE = 4,\n  ELFSYM_BIND_LOCAL = 0 << 4,\n  ELFSYM_BIND_GLOBAL = 1 << 4,\n};\n\n/* DWARF definitions. */\n#define DW_CIE_VERSION\t1\n\nenum {\n  DW_CFA_nop = 0x0,\n  DW_CFA_offset_extended = 0x5,\n  DW_CFA_def_cfa = 0xc,\n  DW_CFA_def_cfa_offset = 0xe,\n  DW_CFA_offset_extended_sf = 0x11,\n  DW_CFA_advance_loc = 0x40,\n  DW_CFA_offset = 0x80\n};\n\nenum {\n  DW_EH_PE_udata4 = 3,\n  DW_EH_PE_textrel = 0x20\n};\n\nenum {\n  DW_TAG_compile_unit = 0x11\n};\n\nenum {\n  DW_children_no = 0,\n  DW_children_yes = 1\n};\n\nenum {\n  DW_AT_name = 0x03,\n  DW_AT_stmt_list = 0x10,\n  DW_AT_low_pc = 0x11,\n  DW_AT_high_pc = 0x12\n};\n\nenum {\n  DW_FORM_addr = 0x01,\n  DW_FORM_data4 = 0x06,\n  DW_FORM_string = 0x08\n};\n\nenum {\n  DW_LNS_extended_op = 0,\n  DW_LNS_copy = 1,\n  DW_LNS_advance_pc = 2,\n  DW_LNS_advance_line = 3\n};\n\nenum {\n  DW_LNE_end_sequence = 1,\n  DW_LNE_set_address = 2\n};\n\nenum {\n#if LJ_TARGET_X86\n  DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX,\n  DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI,\n  DW_REG_RA,\n#elif LJ_TARGET_X64\n  /* Yes, the order is strange, but correct. */\n  DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX,\n  DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP,\n  DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11,\n  DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15,\n  DW_REG_RA,\n#elif LJ_TARGET_ARM\n  DW_REG_SP = 13,\n  DW_REG_RA = 14,\n#elif LJ_TARGET_ARM64\n  DW_REG_SP = 31,\n  DW_REG_RA = 30,\n#elif LJ_TARGET_PPC\n  DW_REG_SP = 1,\n  DW_REG_RA = 65,\n  DW_REG_CR = 70,\n#elif LJ_TARGET_MIPS\n  DW_REG_SP = 29,\n  DW_REG_RA = 31,\n#else\n#error \"Unsupported target architecture\"\n#endif\n};\n\n/* Minimal list of sections for the in-memory ELF object. */\nenum {\n  GDBJIT_SECT_NULL,\n  GDBJIT_SECT_text,\n  GDBJIT_SECT_eh_frame,\n  GDBJIT_SECT_shstrtab,\n  GDBJIT_SECT_strtab,\n  GDBJIT_SECT_symtab,\n  GDBJIT_SECT_debug_info,\n  GDBJIT_SECT_debug_abbrev,\n  GDBJIT_SECT_debug_line,\n  GDBJIT_SECT__MAX\n};\n\nenum {\n  GDBJIT_SYM_UNDEF,\n  GDBJIT_SYM_FILE,\n  GDBJIT_SYM_FUNC,\n  GDBJIT_SYM__MAX\n};\n\n/* In-memory ELF object. */\ntypedef struct GDBJITobj {\n  ELFheader hdr;\t\t\t/* ELF header. */\n  ELFsectheader sect[GDBJIT_SECT__MAX];\t/* ELF sections. */\n  ELFsymbol sym[GDBJIT_SYM__MAX];\t/* ELF symbol table. */\n  uint8_t space[4096];\t\t\t/* Space for various section data. */\n} GDBJITobj;\n\n/* Combined structure for GDB JIT entry and ELF object. */\ntypedef struct GDBJITentryobj {\n  GDBJITentry entry;\n  size_t sz;\n  GDBJITobj obj;\n} GDBJITentryobj;\n\n/* Template for in-memory ELF header. */\nstatic const ELFheader elfhdr_template = {\n  .emagic = { 0x7f, 'E', 'L', 'F' },\n  .eclass = LJ_64 ? 2 : 1,\n  .eendian = LJ_ENDIAN_SELECT(1, 2),\n  .eversion = 1,\n#if LJ_TARGET_LINUX\n  .eosabi = 0,  /* Nope, it's not 3. */\n#elif defined(__FreeBSD__)\n  .eosabi = 9,\n#elif defined(__NetBSD__)\n  .eosabi = 2,\n#elif defined(__OpenBSD__)\n  .eosabi = 12,\n#elif defined(__DragonFly__)\n  .eosabi = 0,\n#elif LJ_TARGET_SOLARIS\n  .eosabi = 6,\n#else\n  .eosabi = 0,\n#endif\n  .eabiversion = 0,\n  .epad = { 0, 0, 0, 0, 0, 0, 0 },\n  .type = 1,\n#if LJ_TARGET_X86\n  .machine = 3,\n#elif LJ_TARGET_X64\n  .machine = 62,\n#elif LJ_TARGET_ARM\n  .machine = 40,\n#elif LJ_TARGET_ARM64\n  .machine = 183,\n#elif LJ_TARGET_PPC\n  .machine = 20,\n#elif LJ_TARGET_MIPS\n  .machine = 8,\n#else\n#error \"Unsupported target architecture\"\n#endif\n  .version = 1,\n  .entry = 0,\n  .phofs = 0,\n  .shofs = offsetof(GDBJITobj, sect),\n  .flags = 0,\n  .ehsize = sizeof(ELFheader),\n  .phentsize = 0,\n  .phnum = 0,\n  .shentsize = sizeof(ELFsectheader),\n  .shnum = GDBJIT_SECT__MAX,\n  .shstridx = GDBJIT_SECT_shstrtab\n};\n\n/* -- In-memory ELF object generation ------------------------------------- */\n\n/* Context for generating the ELF object for the GDB JIT API. */\ntypedef struct GDBJITctx {\n  uint8_t *p;\t\t/* Pointer to next address in obj.space. */\n  uint8_t *startp;\t/* Pointer to start address in obj.space. */\n  GCtrace *T;\t\t/* Generate symbols for this trace. */\n  uintptr_t mcaddr;\t/* Machine code address. */\n  MSize szmcode;\t/* Size of machine code. */\n  MSize spadjp;\t\t/* Stack adjustment for parent trace or interpreter. */\n  MSize spadj;\t\t/* Stack adjustment for trace itself. */\n  BCLine lineno;\t/* Starting line number. */\n  const char *filename;\t/* Starting file name. */\n  size_t objsize;\t/* Final size of ELF object. */\n  GDBJITobj obj;\t/* In-memory ELF object. */\n} GDBJITctx;\n\n/* Add a zero-terminated string. */\nstatic uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str)\n{\n  uint8_t *p = ctx->p;\n  uint32_t ofs = (uint32_t)(p - ctx->startp);\n  do {\n    *p++ = (uint8_t)*str;\n  } while (*str++);\n  ctx->p = p;\n  return ofs;\n}\n\n/* Append a decimal number. */\nstatic void gdbjit_catnum(GDBJITctx *ctx, uint32_t n)\n{\n  if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); }\n  *ctx->p++ = '0' + n;\n}\n\n/* Add a SLEB128 value. */\nstatic void gdbjit_sleb128(GDBJITctx *ctx, int32_t v)\n{\n  uint8_t *p = ctx->p;\n  for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7)\n    *p++ = (uint8_t)((v & 0x7f) | 0x80);\n  *p++ = (uint8_t)(v & 0x7f);\n  ctx->p = p;\n}\n\n/* Shortcuts to generate DWARF structures. */\n#define DB(x)\t\t(*p++ = (x))\n#define DI8(x)\t\t(*(int8_t *)p = (x), p++)\n#define DU16(x)\t\t(*(uint16_t *)p = (x), p += 2)\n#define DU32(x)\t\t(*(uint32_t *)p = (x), p += 4)\n#define DADDR(x)\t(*(uintptr_t *)p = (x), p += sizeof(uintptr_t))\n#define DUV(x)\t\t(p = (uint8_t *)lj_strfmt_wuleb128((char *)p, (x)))\n#define DSV(x)\t\t(ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p)\n#define DSTR(str)\t(ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p)\n#define DALIGNNOP(s)\twhile ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop\n#define DSECT(name, stmt) \\\n  { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \\\n    *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \\\n\n/* Initialize ELF section headers. */\nstatic void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx)\n{\n  ELFsectheader *sect;\n\n  *ctx->p++ = '\\0';  /* Empty string at start of string table. */\n\n#define SECTDEF(id, tp, al) \\\n  sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \\\n  sect->name = gdbjit_strz(ctx, \".\" #id); \\\n  sect->type = ELFSECT_TYPE_##tp; \\\n  sect->align = (al)\n\n  SECTDEF(text, NOBITS, 16);\n  sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC;\n  sect->addr = ctx->mcaddr;\n  sect->ofs = 0;\n  sect->size = ctx->szmcode;\n\n  SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t));\n  sect->flags = ELFSECT_FLAGS_ALLOC;\n\n  SECTDEF(shstrtab, STRTAB, 1);\n  SECTDEF(strtab, STRTAB, 1);\n\n  SECTDEF(symtab, SYMTAB, sizeof(uintptr_t));\n  sect->ofs = offsetof(GDBJITobj, sym);\n  sect->size = sizeof(ctx->obj.sym);\n  sect->link = GDBJIT_SECT_strtab;\n  sect->entsize = sizeof(ELFsymbol);\n  sect->info = GDBJIT_SYM_FUNC;\n\n  SECTDEF(debug_info, PROGBITS, 1);\n  SECTDEF(debug_abbrev, PROGBITS, 1);\n  SECTDEF(debug_line, PROGBITS, 1);\n\n#undef SECTDEF\n}\n\n/* Initialize symbol table. */\nstatic void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx)\n{\n  ELFsymbol *sym;\n\n  *ctx->p++ = '\\0';  /* Empty string at start of string table. */\n\n  sym = &ctx->obj.sym[GDBJIT_SYM_FILE];\n  sym->name = gdbjit_strz(ctx, \"JIT mcode\");\n  sym->sectidx = ELFSECT_IDX_ABS;\n  sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;\n\n  sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];\n  sym->name = gdbjit_strz(ctx, \"TRACE_\"); ctx->p--;\n  gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\\0';\n  sym->sectidx = GDBJIT_SECT_text;\n  sym->value = 0;\n  sym->size = ctx->szmcode;\n  sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL;\n}\n\n/* Initialize .eh_frame section. */\nstatic void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n  uint8_t *framep = p;\n\n  /* Emit DWARF EH CIE. */\n  DSECT(CIE,\n    DU32(0);\t\t\t/* Offset to CIE itself. */\n    DB(DW_CIE_VERSION);\n    DSTR(\"zR\");\t\t\t/* Augmentation. */\n    DUV(1);\t\t\t/* Code alignment factor. */\n    DSV(-(int32_t)sizeof(uintptr_t));  /* Data alignment factor. */\n    DB(DW_REG_RA);\t\t/* Return address register. */\n    DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4);  /* Augmentation data. */\n    DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t));\n#if LJ_TARGET_PPC\n    DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1);\n#else\n    DB(DW_CFA_offset|DW_REG_RA); DUV(1);\n#endif\n    DALIGNNOP(sizeof(uintptr_t));\n  )\n\n  /* Emit DWARF EH FDE. */\n  DSECT(FDE,\n    DU32((uint32_t)(p-framep));\t/* Offset to CIE. */\n    DU32(0);\t\t\t/* Machine code offset relative to .text. */\n    DU32(ctx->szmcode);\t\t/* Machine code length. */\n    DB(0);\t\t\t/* Augmentation data. */\n    /* Registers saved in CFRAME. */\n#if LJ_TARGET_X86\n    DB(DW_CFA_offset|DW_REG_BP); DUV(2);\n    DB(DW_CFA_offset|DW_REG_DI); DUV(3);\n    DB(DW_CFA_offset|DW_REG_SI); DUV(4);\n    DB(DW_CFA_offset|DW_REG_BX); DUV(5);\n#elif LJ_TARGET_X64\n    DB(DW_CFA_offset|DW_REG_BP); DUV(2);\n    DB(DW_CFA_offset|DW_REG_BX); DUV(3);\n    DB(DW_CFA_offset|DW_REG_15); DUV(4);\n    DB(DW_CFA_offset|DW_REG_14); DUV(5);\n    /* Extra registers saved for JIT-compiled code. */\n    DB(DW_CFA_offset|DW_REG_13); DUV(LJ_GC64 ? 10 : 9);\n    DB(DW_CFA_offset|DW_REG_12); DUV(LJ_GC64 ? 11 : 10);\n#elif LJ_TARGET_ARM\n    {\n      int i;\n      for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); }\n    }\n#elif LJ_TARGET_ARM64\n    {\n      int i;\n      DB(DW_CFA_offset|31); DUV(2);\n      for (i = 28; i >= 19; i--) { DB(DW_CFA_offset|i); DUV(3+(28-i)); }\n      for (i = 15; i >= 8; i--) { DB(DW_CFA_offset|32|i); DUV(28-i); }\n    }\n#elif LJ_TARGET_PPC\n    {\n      int i;\n      DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55);\n      for (i = 14; i <= 31; i++) {\n\tDB(DW_CFA_offset|i); DUV(37+(31-i));\n\tDB(DW_CFA_offset|32|i); DUV(2+2*(31-i));\n      }\n    }\n#elif LJ_TARGET_MIPS\n    {\n      int i;\n      DB(DW_CFA_offset|30); DUV(2);\n      for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }\n      for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }\n    }\n#else\n#error \"Unsupported target architecture\"\n#endif\n    if (ctx->spadjp != ctx->spadj) {  /* Parent/interpreter stack frame size. */\n      DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp);\n      DB(DW_CFA_advance_loc|1);  /* Only an approximation. */\n    }\n    DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj);  /* Trace stack frame size. */\n    DALIGNNOP(sizeof(uintptr_t));\n  )\n\n  ctx->p = p;\n}\n\n/* Initialize .debug_info section. */\nstatic void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  DSECT(info,\n    DU16(2);\t\t\t/* DWARF version. */\n    DU32(0);\t\t\t/* Abbrev offset. */\n    DB(sizeof(uintptr_t));\t/* Pointer size. */\n\n    DUV(1);\t\t\t/* Abbrev #1: DW_TAG_compile_unit. */\n    DSTR(ctx->filename);\t/* DW_AT_name. */\n    DADDR(ctx->mcaddr);\t\t/* DW_AT_low_pc. */\n    DADDR(ctx->mcaddr + ctx->szmcode);  /* DW_AT_high_pc. */\n    DU32(0);\t\t\t/* DW_AT_stmt_list. */\n  )\n\n  ctx->p = p;\n}\n\n/* Initialize .debug_abbrev section. */\nstatic void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  /* Abbrev #1: DW_TAG_compile_unit. */\n  DUV(1); DUV(DW_TAG_compile_unit);\n  DB(DW_children_no);\n  DUV(DW_AT_name);\tDUV(DW_FORM_string);\n  DUV(DW_AT_low_pc);\tDUV(DW_FORM_addr);\n  DUV(DW_AT_high_pc);\tDUV(DW_FORM_addr);\n  DUV(DW_AT_stmt_list);\tDUV(DW_FORM_data4);\n  DB(0); DB(0);\n\n  ctx->p = p;\n}\n\n#define DLNE(op, s)\t(DB(DW_LNS_extended_op), DUV(1+(s)), DB((op)))\n\n/* Initialize .debug_line section. */\nstatic void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx)\n{\n  uint8_t *p = ctx->p;\n\n  DSECT(line,\n    DU16(2);\t\t\t/* DWARF version. */\n    DSECT(header,\n      DB(1);\t\t\t/* Minimum instruction length. */\n      DB(1);\t\t\t/* is_stmt. */\n      DI8(0);\t\t\t/* Line base for special opcodes. */\n      DB(2);\t\t\t/* Line range for special opcodes. */\n      DB(3+1);\t\t\t/* Opcode base at DW_LNS_advance_line+1. */\n      DB(0); DB(1); DB(1);\t/* Standard opcode lengths. */\n      /* Directory table. */\n      DB(0);\n      /* File name table. */\n      DSTR(ctx->filename); DUV(0); DUV(0); DUV(0);\n      DB(0);\n    )\n\n    DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr);\n    if (ctx->lineno) {\n      DB(DW_LNS_advance_line); DSV(ctx->lineno-1);\n    }\n    DB(DW_LNS_copy);\n    DB(DW_LNS_advance_pc); DUV(ctx->szmcode);\n    DLNE(DW_LNE_end_sequence, 0);\n  )\n\n  ctx->p = p;\n}\n\n#undef DLNE\n\n/* Undef shortcuts. */\n#undef DB\n#undef DI8\n#undef DU16\n#undef DU32\n#undef DADDR\n#undef DUV\n#undef DSV\n#undef DSTR\n#undef DALIGNNOP\n#undef DSECT\n\n/* Type of a section initializer callback. */\ntypedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx);\n\n/* Call section initializer and set the section offset and size. */\nstatic void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf)\n{\n  ctx->startp = ctx->p;\n  ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj);\n  initf(ctx);\n  ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp);\n}\n\n#define SECTALIGN(p, a) \\\n  ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1)))\n\n/* Build in-memory ELF object. */\nstatic void gdbjit_buildobj(GDBJITctx *ctx)\n{\n  GDBJITobj *obj = &ctx->obj;\n  /* Fill in ELF header and clear structures. */\n  memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader));\n  memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX);\n  memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX);\n  /* Initialize sections. */\n  ctx->p = obj->space;\n  gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr);\n  gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev);\n  gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline);\n  SECTALIGN(ctx->p, sizeof(uintptr_t));\n  gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe);\n  ctx->objsize = (size_t)((char *)ctx->p - (char *)obj);\n  lj_assertX(ctx->objsize < sizeof(GDBJITobj), \"GDBJITobj overflow\");\n}\n\n#undef SECTALIGN\n\n/* -- Interface to GDB JIT API -------------------------------------------- */\n\nstatic int gdbjit_lock;\n\nstatic void gdbjit_lock_acquire()\n{\n  while (__sync_lock_test_and_set(&gdbjit_lock, 1)) {\n    /* Just spin; futexes or pthreads aren't worth the portability cost. */\n  }\n}\n\nstatic void gdbjit_lock_release()\n{\n  __sync_lock_release(&gdbjit_lock);\n}\n\n/* Add new entry to GDB JIT symbol chain. */\nstatic void gdbjit_newentry(lua_State *L, GDBJITctx *ctx)\n{\n  /* Allocate memory for GDB JIT entry and ELF object. */\n  MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize);\n  GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj);\n  memcpy(&eo->obj, &ctx->obj, ctx->objsize);  /* Copy ELF object. */\n  eo->sz = sz;\n  ctx->T->gdbjit_entry = (void *)eo;\n  /* Link new entry to chain and register it. */\n  eo->entry.prev_entry = NULL;\n  gdbjit_lock_acquire();\n  eo->entry.next_entry = __jit_debug_descriptor.first_entry;\n  if (eo->entry.next_entry)\n    eo->entry.next_entry->prev_entry = &eo->entry;\n  eo->entry.symfile_addr = (const char *)&eo->obj;\n  eo->entry.symfile_size = ctx->objsize;\n  __jit_debug_descriptor.first_entry = &eo->entry;\n  __jit_debug_descriptor.relevant_entry = &eo->entry;\n  __jit_debug_descriptor.action_flag = GDBJIT_REGISTER;\n  __jit_debug_register_code();\n  gdbjit_lock_release();\n}\n\n/* Add debug info for newly compiled trace and notify GDB. */\nvoid lj_gdbjit_addtrace(jit_State *J, GCtrace *T)\n{\n  GDBJITctx ctx;\n  GCproto *pt = &gcref(T->startpt)->pt;\n  TraceNo parent = T->ir[REF_BASE].op1;\n  const BCIns *startpc = mref(T->startpc, const BCIns);\n  ctx.T = T;\n  ctx.mcaddr = (uintptr_t)T->mcode;\n  ctx.szmcode = T->szmcode;\n  ctx.spadjp = CFRAME_SIZE_JIT +\n\t       (MSize)(parent ? traceref(J, parent)->spadjust : 0);\n  ctx.spadj = CFRAME_SIZE_JIT + T->spadjust;\n  lj_assertJ(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc,\n\t     \"start PC out of range\");\n  ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));\n  ctx.filename = proto_chunknamestr(pt);\n  if (*ctx.filename == '@' || *ctx.filename == '=')\n    ctx.filename++;\n  else\n    ctx.filename = \"(string)\";\n  gdbjit_buildobj(&ctx);\n  gdbjit_newentry(J->L, &ctx);\n}\n\n/* Delete debug info for trace and notify GDB. */\nvoid lj_gdbjit_deltrace(jit_State *J, GCtrace *T)\n{\n  GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry;\n  if (eo) {\n    gdbjit_lock_acquire();\n    if (eo->entry.prev_entry)\n      eo->entry.prev_entry->next_entry = eo->entry.next_entry;\n    else\n      __jit_debug_descriptor.first_entry = eo->entry.next_entry;\n    if (eo->entry.next_entry)\n      eo->entry.next_entry->prev_entry = eo->entry.prev_entry;\n    __jit_debug_descriptor.relevant_entry = &eo->entry;\n    __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER;\n    __jit_debug_register_code();\n    gdbjit_lock_release();\n    lj_mem_free(J2G(J), eo, eo->sz);\n  }\n}\n\n#endif\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_gdbjit.h",
    "content": "/*\n** Client for the GDB JIT API.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_GDBJIT_H\n#define _LJ_GDBJIT_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT)\n\nLJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T);\nLJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T);\n\n#else\n#define lj_gdbjit_addtrace(J, T)\tUNUSED(T)\n#define lj_gdbjit_deltrace(J, T)\tUNUSED(T)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ir.c",
    "content": "/*\n** SSA IR (Intermediate Representation) emitter.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_ir_c\n#define LUA_CORE\n\n/* For pointers to libc/libm functions. */\n#include <stdio.h>\n#include <math.h>\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_serialize.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_prng.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n#define fins\t\t\t(&J->fold.ins)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* -- IR tables ----------------------------------------------------------- */\n\n/* IR instruction modes. */\nLJ_DATADEF const uint8_t lj_ir_mode[IR__MAX+1] = {\nIRDEF(IRMODE)\n  0\n};\n\n/* IR type sizes. */\nLJ_DATADEF const uint8_t lj_ir_type_size[IRT__MAX+1] = {\n#define IRTSIZE(name, size)\tsize,\nIRTDEF(IRTSIZE)\n#undef IRTSIZE\n  0\n};\n\n/* C call info for CALL* instructions. */\nLJ_DATADEF const CCallInfo lj_ir_callinfo[] = {\n#define IRCALLCI(cond, name, nargs, kind, type, flags) \\\n  { (ASMFunction)IRCALLCOND_##cond(name), \\\n    (nargs)|(CCI_CALL_##kind)|(IRT_##type<<CCI_OTSHIFT)|(flags) },\nIRCALLDEF(IRCALLCI)\n#undef IRCALLCI\n  { NULL, 0 }\n};\n\n/* -- IR emitter ---------------------------------------------------------- */\n\n/* Grow IR buffer at the top. */\nvoid LJ_FASTCALL lj_ir_growtop(jit_State *J)\n{\n  IRIns *baseir = J->irbuf + J->irbotlim;\n  MSize szins = J->irtoplim - J->irbotlim;\n  if (szins) {\n    baseir = (IRIns *)lj_mem_realloc(J->L, baseir, szins*sizeof(IRIns),\n\t\t\t\t     2*szins*sizeof(IRIns));\n    J->irtoplim = J->irbotlim + 2*szins;\n  } else {\n    baseir = (IRIns *)lj_mem_realloc(J->L, NULL, 0, LJ_MIN_IRSZ*sizeof(IRIns));\n    J->irbotlim = REF_BASE - LJ_MIN_IRSZ/4;\n    J->irtoplim = J->irbotlim + LJ_MIN_IRSZ;\n  }\n  J->cur.ir = J->irbuf = baseir - J->irbotlim;\n}\n\n/* Grow IR buffer at the bottom or shift it up. */\nstatic void lj_ir_growbot(jit_State *J)\n{\n  IRIns *baseir = J->irbuf + J->irbotlim;\n  MSize szins = J->irtoplim - J->irbotlim;\n  lj_assertJ(szins != 0, \"zero IR size\");\n  lj_assertJ(J->cur.nk == J->irbotlim || J->cur.nk-1 == J->irbotlim,\n\t     \"unexpected IR growth\");\n  if (J->cur.nins + (szins >> 1) < J->irtoplim) {\n    /* More than half of the buffer is free on top: shift up by a quarter. */\n    MSize ofs = szins >> 2;\n    memmove(baseir + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));\n    J->irbotlim -= ofs;\n    J->irtoplim -= ofs;\n    J->cur.ir = J->irbuf = baseir - J->irbotlim;\n  } else {\n    /* Double the buffer size, but split the growth amongst top/bottom. */\n    IRIns *newbase = lj_mem_newt(J->L, 2*szins*sizeof(IRIns), IRIns);\n    MSize ofs = szins >= 256 ? 128 : (szins >> 1);  /* Limit bottom growth. */\n    memcpy(newbase + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));\n    lj_mem_free(G(J->L), baseir, szins*sizeof(IRIns));\n    J->irbotlim -= ofs;\n    J->irtoplim = J->irbotlim + 2*szins;\n    J->cur.ir = J->irbuf = newbase - J->irbotlim;\n  }\n}\n\n/* Emit IR without any optimizations. */\nTRef LJ_FASTCALL lj_ir_emit(jit_State *J)\n{\n  IRRef ref = lj_ir_nextins(J);\n  IRIns *ir = IR(ref);\n  IROp op = fins->o;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\n  ir->o = op;\n  ir->op1 = fins->op1;\n  ir->op2 = fins->op2;\n  J->guardemit.irt |= fins->t.irt;\n  return TREF(ref, irt_t((ir->t = fins->t)));\n}\n\n/* Emit call to a C function. */\nTRef lj_ir_call(jit_State *J, IRCallID id, ...)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[id];\n  uint32_t n = CCI_NARGS(ci);\n  TRef tr = TREF_NIL;\n  va_list argp;\n  va_start(argp, id);\n  if ((ci->flags & CCI_L)) n--;\n  if (n > 0)\n    tr = va_arg(argp, IRRef);\n  while (n-- > 1)\n    tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef));\n  va_end(argp);\n  if (CCI_OP(ci) == IR_CALLS)\n    J->needsnap = 1;  /* Need snapshot after call with side effect. */\n  return emitir(CCI_OPTYPE(ci), tr, id);\n}\n\n/* Load field of type t from GG_State + offset. Must be 32 bit aligned. */\nTRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs)\n{\n  lj_assertJ((ofs & 3) == 0, \"unaligned GG_State field offset\");\n  ofs >>= 2;\n  lj_assertJ(ofs >= IRFL__MAX && ofs <= 0x3ff,\n\t     \"GG_State field offset breaks 10 bit FOLD key limit\");\n  lj_ir_set(J, IRT(IR_FLOAD, t), REF_NIL, ofs);\n  return lj_opt_fold(J);\n}\n\n/* -- Interning of constants ---------------------------------------------- */\n\n/*\n** IR instructions for constants are kept between J->cur.nk >= ref < REF_BIAS.\n** They are chained like all other instructions, but grow downwards.\n** The are interned (like strings in the VM) to facilitate reference\n** comparisons. The same constant must get the same reference.\n*/\n\n/* Get ref of next IR constant and optionally grow IR.\n** Note: this may invalidate all IRIns *!\n*/\nstatic LJ_AINLINE IRRef ir_nextk(jit_State *J)\n{\n  IRRef ref = J->cur.nk;\n  if (LJ_UNLIKELY(ref <= J->irbotlim)) lj_ir_growbot(J);\n  J->cur.nk = --ref;\n  return ref;\n}\n\n/* Get ref of next 64 bit IR constant and optionally grow IR.\n** Note: this may invalidate all IRIns *!\n*/\nstatic LJ_AINLINE IRRef ir_nextk64(jit_State *J)\n{\n  IRRef ref = J->cur.nk - 2;\n  lj_assertJ(J->state != LJ_TRACE_ASM, \"bad JIT state\");\n  if (LJ_UNLIKELY(ref < J->irbotlim)) lj_ir_growbot(J);\n  J->cur.nk = ref;\n  return ref;\n}\n\n#if LJ_GC64\n#define ir_nextkgc ir_nextk64\n#else\n#define ir_nextkgc ir_nextk\n#endif\n\n/* Intern int32_t constant. */\nTRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  for (ref = J->chain[IR_KINT]; ref; ref = cir[ref].prev)\n    if (cir[ref].i == k)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->i = k;\n  ir->t.irt = IRT_INT;\n  ir->o = IR_KINT;\n  ir->prev = J->chain[IR_KINT];\n  J->chain[IR_KINT] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_INT);\n}\n\n/* Intern 64 bit constant, given by its 64 bit pattern. */\nTRef lj_ir_k64(jit_State *J, IROp op, uint64_t u64)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64;\n  for (ref = J->chain[op]; ref; ref = cir[ref].prev)\n    if (ir_k64(&cir[ref])->u64 == u64)\n      goto found;\n  ref = ir_nextk64(J);\n  ir = IR(ref);\n  ir[1].tv.u64 = u64;\n  ir->t.irt = t;\n  ir->o = op;\n  ir->op12 = 0;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Intern FP constant, given by its 64 bit pattern. */\nTRef lj_ir_knum_u64(jit_State *J, uint64_t u64)\n{\n  return lj_ir_k64(J, IR_KNUM, u64);\n}\n\n/* Intern 64 bit integer constant. */\nTRef lj_ir_kint64(jit_State *J, uint64_t u64)\n{\n  return lj_ir_k64(J, IR_KINT64, u64);\n}\n\n/* Check whether a number is int and return it. -0 is NOT considered an int. */\nstatic int numistrueint(lua_Number n, int32_t *kp)\n{\n  int32_t k = lj_num2int(n);\n  if (n == (lua_Number)k) {\n    if (kp) *kp = k;\n    if (k == 0) {  /* Special check for -0. */\n      TValue tv;\n      setnumV(&tv, n);\n      if (tv.u32.hi != 0)\n\treturn 0;\n    }\n    return 1;\n  }\n  return 0;\n}\n\n/* Intern number as int32_t constant if possible, otherwise as FP constant. */\nTRef lj_ir_knumint(jit_State *J, lua_Number n)\n{\n  int32_t k;\n  if (numistrueint(n, &k))\n    return lj_ir_kint(J, k);\n  else\n    return lj_ir_knum(J, n);\n}\n\n/* Intern GC object \"constant\". */\nTRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  lj_assertJ(!isdead(J2G(J), o), \"interning of dead GC object\");\n  for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)\n    if (ir_kgc(&cir[ref]) == o)\n      goto found;\n  ref = ir_nextkgc(J);\n  ir = IR(ref);\n  /* NOBARRIER: Current trace is a GC root. */\n  ir->op12 = 0;\n  setgcref(ir[LJ_GC64].gcr, o);\n  ir->t.irt = (uint8_t)t;\n  ir->o = IR_KGC;\n  ir->prev = J->chain[IR_KGC];\n  J->chain[IR_KGC] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Allocate GCtrace constant placeholder (no interning). */\nTRef lj_ir_ktrace(jit_State *J)\n{\n  IRRef ref = ir_nextkgc(J);\n  IRIns *ir = IR(ref);\n  lj_assertJ(irt_toitype_(IRT_P64) == LJ_TTRACE, \"mismatched type mapping\");\n  ir->t.irt = IRT_P64;\n  ir->o = LJ_GC64 ? IR_KNUM : IR_KNULL;  /* Not IR_KGC yet, but same size. */\n  ir->op12 = 0;\n  ir->prev = 0;\n  return TREF(ref, IRT_P64);\n}\n\n/* Intern pointer constant. */\nTRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n#if LJ_64 && !LJ_GC64\n  lj_assertJ((void *)(uintptr_t)u32ptr(ptr) == ptr, \"out-of-range GC pointer\");\n#endif\n  for (ref = J->chain[op]; ref; ref = cir[ref].prev)\n    if (ir_kptr(&cir[ref]) == ptr)\n      goto found;\n#if LJ_GC64\n  ref = ir_nextk64(J);\n#else\n  ref = ir_nextk(J);\n#endif\n  ir = IR(ref);\n  ir->op12 = 0;\n  setmref(ir[LJ_GC64].ptr, ptr);\n  ir->t.irt = IRT_PGC;\n  ir->o = op;\n  ir->prev = J->chain[op];\n  J->chain[op] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_PGC);\n}\n\n/* Intern typed NULL constant. */\nTRef lj_ir_knull(jit_State *J, IRType t)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef ref;\n  for (ref = J->chain[IR_KNULL]; ref; ref = cir[ref].prev)\n    if (irt_t(cir[ref].t) == t)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->i = 0;\n  ir->t.irt = (uint8_t)t;\n  ir->o = IR_KNULL;\n  ir->prev = J->chain[IR_KNULL];\n  J->chain[IR_KNULL] = (IRRef1)ref;\nfound:\n  return TREF(ref, t);\n}\n\n/* Intern key slot. */\nTRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot)\n{\n  IRIns *ir, *cir = J->cur.ir;\n  IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot);\n  IRRef ref;\n  /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */\n  lj_assertJ(tref_isk(key) && slot == (IRRef)(IRRef1)slot,\n\t     \"out-of-range key/slot\");\n  for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev)\n    if (cir[ref].op12 == op12)\n      goto found;\n  ref = ir_nextk(J);\n  ir = IR(ref);\n  ir->op12 = op12;\n  ir->t.irt = IRT_P32;\n  ir->o = IR_KSLOT;\n  ir->prev = J->chain[IR_KSLOT];\n  J->chain[IR_KSLOT] = (IRRef1)ref;\nfound:\n  return TREF(ref, IRT_P32);\n}\n\n/* -- Access to IR constants ---------------------------------------------- */\n\n/* Copy value of IR constant. */\nvoid lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)\n{\n  UNUSED(L);\n  lj_assertL(ir->o != IR_KSLOT, \"unexpected KSLOT\");  /* Common mistake. */\n  switch (ir->o) {\n  case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break;\n  case IR_KINT: setintV(tv, ir->i); break;\n  case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;\n  case IR_KPTR: case IR_KKPTR:\n    setnumV(tv, (lua_Number)(uintptr_t)ir_kptr(ir));\n    break;\n  case IR_KNULL: setintV(tv, 0); break;\n  case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break;\n#if LJ_HASFFI\n  case IR_KINT64: {\n    GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8);\n    *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64;\n    setcdataV(L, tv, cd);\n    break;\n    }\n#endif\n  default: lj_assertL(0, \"bad IR constant op %d\", ir->o); break;\n  }\n}\n\n/* -- Convert IR operand types -------------------------------------------- */\n\n/* Convert from string to number. */\nTRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr)\n{\n  if (!tref_isnumber(tr)) {\n    if (tref_isstr(tr))\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    else\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  return tr;\n}\n\n/* Convert from integer or string to number. */\nTRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr)\n{\n  if (!tref_isnum(tr)) {\n    if (tref_isinteger(tr))\n      tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n    else if (tref_isstr(tr))\n      tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    else\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n  }\n  return tr;\n}\n\n/* Convert from integer or number to string. */\nTRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr)\n{\n  if (!tref_isstr(tr)) {\n    if (!tref_isnumber(tr))\n      lj_trace_err(J, LJ_TRERR_BADTYPE);\n    tr = emitir(IRT(IR_TOSTR, IRT_STR), tr,\n\t\ttref_isnum(tr) ? IRTOSTR_NUM : IRTOSTR_INT);\n  }\n  return tr;\n}\n\n/* -- Miscellaneous IR ops ------------------------------------------------ */\n\n/* Evaluate numeric comparison. */\nint lj_ir_numcmp(lua_Number a, lua_Number b, IROp op)\n{\n  switch (op) {\n  case IR_EQ: return (a == b);\n  case IR_NE: return (a != b);\n  case IR_LT: return (a < b);\n  case IR_GE: return (a >= b);\n  case IR_LE: return (a <= b);\n  case IR_GT: return (a > b);\n  case IR_ULT: return !(a >= b);\n  case IR_UGE: return !(a < b);\n  case IR_ULE: return !(a > b);\n  case IR_UGT: return !(a <= b);\n  default: lj_assertX(0, \"bad IR op %d\", op); return 0;\n  }\n}\n\n/* Evaluate string comparison. */\nint lj_ir_strcmp(GCstr *a, GCstr *b, IROp op)\n{\n  int res = lj_str_cmp(a, b);\n  switch (op) {\n  case IR_LT: return (res < 0);\n  case IR_GE: return (res >= 0);\n  case IR_LE: return (res <= 0);\n  case IR_GT: return (res > 0);\n  default: lj_assertX(0, \"bad IR op %d\", op); return 0;\n  }\n}\n\n/* Rollback IR to previous state. */\nvoid lj_ir_rollback(jit_State *J, IRRef ref)\n{\n  IRRef nins = J->cur.nins;\n  while (nins > ref) {\n    IRIns *ir;\n    nins--;\n    ir = IR(nins);\n    J->chain[ir->o] = ir->prev;\n  }\n  J->cur.nins = nins;\n}\n\n#undef IR\n#undef fins\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ir.h",
    "content": "/*\n** SSA IR (Intermediate Representation) format.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IR_H\n#define _LJ_IR_H\n\n#include \"lj_obj.h\"\n\n/* -- IR instructions ----------------------------------------------------- */\n\n/* IR instruction definition. Order matters, see below. ORDER IR */\n#define IRDEF(_) \\\n  /* Guarded assertions. */ \\\n  /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \\\n  _(LT,\t\tN , ref, ref) \\\n  _(GE,\t\tN , ref, ref) \\\n  _(LE,\t\tN , ref, ref) \\\n  _(GT,\t\tN , ref, ref) \\\n  \\\n  _(ULT,\tN , ref, ref) \\\n  _(UGE,\tN , ref, ref) \\\n  _(ULE,\tN , ref, ref) \\\n  _(UGT,\tN , ref, ref) \\\n  \\\n  _(EQ,\t\tC , ref, ref) \\\n  _(NE,\t\tC , ref, ref) \\\n  \\\n  _(ABC,\tN , ref, ref) \\\n  _(RETF,\tS , ref, ref) \\\n  \\\n  /* Miscellaneous ops. */ \\\n  _(NOP,\tN , ___, ___) \\\n  _(BASE,\tN , lit, lit) \\\n  _(PVAL,\tN , lit, ___) \\\n  _(GCSTEP,\tS , ___, ___) \\\n  _(HIOP,\tS , ref, ref) \\\n  _(LOOP,\tS , ___, ___) \\\n  _(USE,\tS , ref, ___) \\\n  _(PHI,\tS , ref, ref) \\\n  _(RENAME,\tS , ref, lit) \\\n  _(PROF,\tS , ___, ___) \\\n  \\\n  /* Constants. */ \\\n  _(KPRI,\tN , ___, ___) \\\n  _(KINT,\tN , cst, ___) \\\n  _(KGC,\tN , cst, ___) \\\n  _(KPTR,\tN , cst, ___) \\\n  _(KKPTR,\tN , cst, ___) \\\n  _(KNULL,\tN , cst, ___) \\\n  _(KNUM,\tN , cst, ___) \\\n  _(KINT64,\tN , cst, ___) \\\n  _(KSLOT,\tN , ref, lit) \\\n  \\\n  /* Bit ops. */ \\\n  _(BNOT,\tN , ref, ___) \\\n  _(BSWAP,\tN , ref, ___) \\\n  _(BAND,\tC , ref, ref) \\\n  _(BOR,\tC , ref, ref) \\\n  _(BXOR,\tC , ref, ref) \\\n  _(BSHL,\tN , ref, ref) \\\n  _(BSHR,\tN , ref, ref) \\\n  _(BSAR,\tN , ref, ref) \\\n  _(BROL,\tN , ref, ref) \\\n  _(BROR,\tN , ref, ref) \\\n  \\\n  /* Arithmetic ops. ORDER ARITH */ \\\n  _(ADD,\tC , ref, ref) \\\n  _(SUB,\tN , ref, ref) \\\n  _(MUL,\tC , ref, ref) \\\n  _(DIV,\tN , ref, ref) \\\n  _(MOD,\tN , ref, ref) \\\n  _(POW,\tN , ref, ref) \\\n  _(NEG,\tN , ref, ref) \\\n  \\\n  _(ABS,\tN , ref, ref) \\\n  _(LDEXP,\tN , ref, ref) \\\n  _(MIN,\tC , ref, ref) \\\n  _(MAX,\tC , ref, ref) \\\n  _(FPMATH,\tN , ref, lit) \\\n  \\\n  /* Overflow-checking arithmetic ops. */ \\\n  _(ADDOV,\tCW, ref, ref) \\\n  _(SUBOV,\tNW, ref, ref) \\\n  _(MULOV,\tCW, ref, ref) \\\n  \\\n  /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \\\n  \\\n  /* Memory references. */ \\\n  _(AREF,\tR , ref, ref) \\\n  _(HREFK,\tR , ref, ref) \\\n  _(HREF,\tL , ref, ref) \\\n  _(NEWREF,\tS , ref, ref) \\\n  _(UREFO,\tLW, ref, lit) \\\n  _(UREFC,\tLW, ref, lit) \\\n  _(FREF,\tR , ref, lit) \\\n  _(TMPREF,\tS , ref, lit) \\\n  _(STRREF,\tN , ref, ref) \\\n  _(LREF,\tL , ___, ___) \\\n  \\\n  /* Loads and Stores. These must be in the same order. */ \\\n  _(ALOAD,\tL , ref, ___) \\\n  _(HLOAD,\tL , ref, ___) \\\n  _(ULOAD,\tL , ref, ___) \\\n  _(FLOAD,\tL , ref, lit) \\\n  _(XLOAD,\tL , ref, lit) \\\n  _(SLOAD,\tL , lit, lit) \\\n  _(VLOAD,\tL , ref, lit) \\\n  _(ALEN,\tL , ref, ref) \\\n  \\\n  _(ASTORE,\tS , ref, ref) \\\n  _(HSTORE,\tS , ref, ref) \\\n  _(USTORE,\tS , ref, ref) \\\n  _(FSTORE,\tS , ref, ref) \\\n  _(XSTORE,\tS , ref, ref) \\\n  \\\n  /* Allocations. */ \\\n  _(SNEW,\tN , ref, ref)  /* CSE is ok, not marked as A. */ \\\n  _(XSNEW,\tA , ref, ref) \\\n  _(TNEW,\tAW, lit, lit) \\\n  _(TDUP,\tAW, ref, ___) \\\n  _(CNEW,\tAW, ref, ref) \\\n  _(CNEWI,\tNW, ref, ref)  /* CSE is ok, not marked as A. */ \\\n  \\\n  /* Buffer operations. */ \\\n  _(BUFHDR,\tL , ref, lit) \\\n  _(BUFPUT,\tLW, ref, ref) \\\n  _(BUFSTR,\tAW, ref, ref) \\\n  \\\n  /* Barriers. */ \\\n  _(TBAR,\tS , ref, ___) \\\n  _(OBAR,\tS , ref, ref) \\\n  _(XBAR,\tS , ___, ___) \\\n  \\\n  /* Type conversions. */ \\\n  _(CONV,\tN , ref, lit) \\\n  _(TOBIT,\tN , ref, ref) \\\n  _(TOSTR,\tN , ref, lit) \\\n  _(STRTO,\tN , ref, ___) \\\n  \\\n  /* Calls. */ \\\n  _(CALLN,\tNW, ref, lit) \\\n  _(CALLA,\tAW, ref, lit) \\\n  _(CALLL,\tLW, ref, lit) \\\n  _(CALLS,\tS , ref, lit) \\\n  _(CALLXS,\tS , ref, ref) \\\n  _(CARG,\tN , ref, ref) \\\n  \\\n  /* End of list. */\n\n/* IR opcodes (max. 256). */\ntypedef enum {\n#define IRENUM(name, m, m1, m2)\tIR_##name,\nIRDEF(IRENUM)\n#undef IRENUM\n  IR__MAX\n} IROp;\n\n/* Stored opcode. */\ntypedef uint8_t IROp1;\n\nLJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE);\nLJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE);\nLJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT);\nLJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT);\nLJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT);\n\n/* Delta between xLOAD and xSTORE. */\n#define IRDELTA_L2S\t\t((int)IR_ASTORE - (int)IR_ALOAD)\n\nLJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE);\nLJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE);\nLJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE);\nLJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);\n\n/* -- Named IR literals --------------------------------------------------- */\n\n/* FPMATH sub-functions. ORDER FPM. */\n#define IRFPMDEF(_) \\\n  _(FLOOR) _(CEIL) _(TRUNC)  /* Must be first and in this order. */ \\\n  _(SQRT) _(LOG) _(LOG2) \\\n  _(OTHER)\n\ntypedef enum {\n#define FPMENUM(name)\t\tIRFPM_##name,\nIRFPMDEF(FPMENUM)\n#undef FPMENUM\n  IRFPM__MAX\n} IRFPMathOp;\n\n/* FLOAD fields. */\n#define IRFLDEF(_) \\\n  _(STR_LEN,\toffsetof(GCstr, len)) \\\n  _(FUNC_ENV,\toffsetof(GCfunc, l.env)) \\\n  _(FUNC_PC,\toffsetof(GCfunc, l.pc)) \\\n  _(FUNC_FFID,\toffsetof(GCfunc, l.ffid)) \\\n  _(THREAD_ENV,\toffsetof(lua_State, env)) \\\n  _(TAB_META,\toffsetof(GCtab, metatable)) \\\n  _(TAB_ARRAY,\toffsetof(GCtab, array)) \\\n  _(TAB_NODE,\toffsetof(GCtab, node)) \\\n  _(TAB_ASIZE,\toffsetof(GCtab, asize)) \\\n  _(TAB_HMASK,\toffsetof(GCtab, hmask)) \\\n  _(TAB_NOMM,\toffsetof(GCtab, nomm)) \\\n  _(UDATA_META,\toffsetof(GCudata, metatable)) \\\n  _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \\\n  _(UDATA_FILE,\tsizeof(GCudata)) \\\n  _(SBUF_W,\tsizeof(GCudata) + offsetof(SBufExt, w)) \\\n  _(SBUF_E,\tsizeof(GCudata) + offsetof(SBufExt, e)) \\\n  _(SBUF_B,\tsizeof(GCudata) + offsetof(SBufExt, b)) \\\n  _(SBUF_L,\tsizeof(GCudata) + offsetof(SBufExt, L)) \\\n  _(SBUF_REF,\tsizeof(GCudata) + offsetof(SBufExt, cowref)) \\\n  _(SBUF_R,\tsizeof(GCudata) + offsetof(SBufExt, r)) \\\n  _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \\\n  _(CDATA_PTR,\tsizeof(GCcdata)) \\\n  _(CDATA_INT,\tsizeof(GCcdata)) \\\n  _(CDATA_INT64, sizeof(GCcdata)) \\\n  _(CDATA_INT64_4, sizeof(GCcdata) + 4)\n\ntypedef enum {\n#define FLENUM(name, ofs)\tIRFL_##name,\nIRFLDEF(FLENUM)\n#undef FLENUM\n  IRFL__MAX\n} IRFieldID;\n\n/* TMPREF mode bits, stored in op2. */\n#define IRTMPREF_IN1\t\t0x01\t/* First input value. */\n#define IRTMPREF_OUT1\t\t0x02\t/* First output value. */\n#define IRTMPREF_OUT2\t\t0x04\t/* Second output value. */\n\n/* SLOAD mode bits, stored in op2. */\n#define IRSLOAD_PARENT\t\t0x01\t/* Coalesce with parent trace. */\n#define IRSLOAD_FRAME\t\t0x02\t/* Load 32 bits of ftsz. */\n#define IRSLOAD_TYPECHECK\t0x04\t/* Needs type check. */\n#define IRSLOAD_CONVERT\t\t0x08\t/* Number to integer conversion. */\n#define IRSLOAD_READONLY\t0x10\t/* Read-only, omit slot store. */\n#define IRSLOAD_INHERIT\t\t0x20\t/* Inherited by exits/side traces. */\n#define IRSLOAD_KEYINDEX\t0x40\t/* Table traversal key index. */\n\n/* XLOAD mode bits, stored in op2. */\n#define IRXLOAD_READONLY\t0x01\t/* Load from read-only data. */\n#define IRXLOAD_VOLATILE\t0x02\t/* Load from volatile data. */\n#define IRXLOAD_UNALIGNED\t0x04\t/* Unaligned load. */\n\n/* BUFHDR mode, stored in op2. */\n#define IRBUFHDR_RESET\t\t0\t/* Reset buffer. */\n#define IRBUFHDR_APPEND\t\t1\t/* Append to buffer. */\n#define IRBUFHDR_WRITE\t\t2\t/* Write to string buffer. */\n\n/* CONV mode, stored in op2. */\n#define IRCONV_SRCMASK\t\t0x001f\t/* Source IRType. */\n#define IRCONV_DSTMASK\t\t0x03e0\t/* Dest. IRType (also in ir->t). */\n#define IRCONV_DSH\t\t5\n#define IRCONV_NUM_INT\t\t((IRT_NUM<<IRCONV_DSH)|IRT_INT)\n#define IRCONV_INT_NUM\t\t((IRT_INT<<IRCONV_DSH)|IRT_NUM)\n#define IRCONV_SEXT\t\t0x0800\t/* Sign-extend integer to integer. */\n#define IRCONV_MODEMASK\t\t0x0fff\n#define IRCONV_CONVMASK\t\t0xf000\n#define IRCONV_CSH\t\t12\n/* Number to integer conversion mode. Ordered by strength of the checks. */\n#define IRCONV_TOBIT  (0<<IRCONV_CSH)\t/* None. Cache only: TOBIT conv. */\n#define IRCONV_ANY    (1<<IRCONV_CSH)\t/* Any FP number is ok. */\n#define IRCONV_INDEX  (2<<IRCONV_CSH)\t/* Check + special backprop rules. */\n#define IRCONV_CHECK  (3<<IRCONV_CSH)\t/* Number checked for integerness. */\n#define IRCONV_NONE   IRCONV_ANY\t/* INT|*64 no conv, but change type. */\n\n/* TOSTR mode, stored in op2. */\n#define IRTOSTR_INT\t\t0\t/* Convert integer to string. */\n#define IRTOSTR_NUM\t\t1\t/* Convert number to string. */\n#define IRTOSTR_CHAR\t\t2\t/* Convert char value to string. */\n\n/* -- IR operands --------------------------------------------------------- */\n\n/* IR operand mode (2 bit). */\ntypedef enum {\n  IRMref,\t\t/* IR reference. */\n  IRMlit,\t\t/* 16 bit unsigned literal. */\n  IRMcst,\t\t/* Constant literal: i, gcr or ptr. */\n  IRMnone\t\t/* Unused operand. */\n} IRMode;\n#define IRM___\t\tIRMnone\n\n/* Mode bits: Commutative, {Normal/Ref, Alloc, Load, Store}, Non-weak guard. */\n#define IRM_C\t\t\t0x10\n\n#define IRM_N\t\t\t0x00\n#define IRM_R\t\t\tIRM_N\n#define IRM_A\t\t\t0x20\n#define IRM_L\t\t\t0x40\n#define IRM_S\t\t\t0x60\n\n#define IRM_W\t\t\t0x80\n\n#define IRM_NW\t\t\t(IRM_N|IRM_W)\n#define IRM_CW\t\t\t(IRM_C|IRM_W)\n#define IRM_AW\t\t\t(IRM_A|IRM_W)\n#define IRM_LW\t\t\t(IRM_L|IRM_W)\n\n#define irm_op1(m)\t\t((IRMode)((m)&3))\n#define irm_op2(m)\t\t((IRMode)(((m)>>2)&3))\n#define irm_iscomm(m)\t\t((m) & IRM_C)\n#define irm_kind(m)\t\t((m) & IRM_S)\n\n#define IRMODE(name, m, m1, m2)\t(((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W),\n\nLJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];\n\n/* -- IR instruction types ------------------------------------------------ */\n\n#define IRTSIZE_PGC\t\t(LJ_GC64 ? 8 : 4)\n\n/* Map of itypes to non-negative numbers and their sizes. ORDER LJ_T.\n** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for\n** IRT_P32 and IRT_P64, which never escape the IR.\n** The various integers are only used in the IR and can only escape to\n** a TValue after implicit or explicit conversion. Their types must be\n** contiguous and next to IRT_NUM (see the typerange macros below).\n*/\n#define IRTDEF(_) \\\n  _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) \\\n  _(STR, IRTSIZE_PGC) _(P32, 4) _(THREAD, IRTSIZE_PGC) _(PROTO, IRTSIZE_PGC) \\\n  _(FUNC, IRTSIZE_PGC) _(P64, 8) _(CDATA, IRTSIZE_PGC) _(TAB, IRTSIZE_PGC) \\\n  _(UDATA, IRTSIZE_PGC) \\\n  _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \\\n  _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \\\n  _(SOFTFP, 4)  /* There is room for 8 more types. */\n\n/* IR result type and flags (8 bit). */\ntypedef enum {\n#define IRTENUM(name, size)\tIRT_##name,\nIRTDEF(IRTENUM)\n#undef IRTENUM\n  IRT__MAX,\n\n  /* Native pointer type and the corresponding integer type. */\n  IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32,\n  IRT_PGC = LJ_GC64 ? IRT_P64 : IRT_P32,\n  IRT_IGC = LJ_GC64 ? IRT_I64 : IRT_INT,\n  IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT,\n  IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32,\n\n  /* Additional flags. */\n  IRT_MARK = 0x20,\t/* Marker for misc. purposes. */\n  IRT_ISPHI = 0x40,\t/* Instruction is left or right PHI operand. */\n  IRT_GUARD = 0x80,\t/* Instruction is a guard. */\n\n  /* Masks. */\n  IRT_TYPE = 0x1f,\n  IRT_T = 0xff\n} IRType;\n\n#define irtype_ispri(irt)\t((uint32_t)(irt) <= IRT_TRUE)\n\n/* Stored IRType. */\ntypedef struct IRType1 { uint8_t irt; } IRType1;\n\n#define IRT(o, t)\t\t((uint32_t)(((o)<<8) | (t)))\n#define IRTI(o)\t\t\t(IRT((o), IRT_INT))\n#define IRTN(o)\t\t\t(IRT((o), IRT_NUM))\n#define IRTG(o, t)\t\t(IRT((o), IRT_GUARD|(t)))\n#define IRTGI(o)\t\t(IRT((o), IRT_GUARD|IRT_INT))\n\n#define irt_t(t)\t\t((IRType)(t).irt)\n#define irt_type(t)\t\t((IRType)((t).irt & IRT_TYPE))\n#define irt_sametype(t1, t2)\t((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0)\n#define irt_typerange(t, first, last) \\\n  ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first))\n\n#define irt_isnil(t)\t\t(irt_type(t) == IRT_NIL)\n#define irt_ispri(t)\t\t((uint32_t)irt_type(t) <= IRT_TRUE)\n#define irt_islightud(t)\t(irt_type(t) == IRT_LIGHTUD)\n#define irt_isstr(t)\t\t(irt_type(t) == IRT_STR)\n#define irt_istab(t)\t\t(irt_type(t) == IRT_TAB)\n#define irt_iscdata(t)\t\t(irt_type(t) == IRT_CDATA)\n#define irt_isfloat(t)\t\t(irt_type(t) == IRT_FLOAT)\n#define irt_isnum(t)\t\t(irt_type(t) == IRT_NUM)\n#define irt_isint(t)\t\t(irt_type(t) == IRT_INT)\n#define irt_isi8(t)\t\t(irt_type(t) == IRT_I8)\n#define irt_isu8(t)\t\t(irt_type(t) == IRT_U8)\n#define irt_isi16(t)\t\t(irt_type(t) == IRT_I16)\n#define irt_isu16(t)\t\t(irt_type(t) == IRT_U16)\n#define irt_isu32(t)\t\t(irt_type(t) == IRT_U32)\n#define irt_isi64(t)\t\t(irt_type(t) == IRT_I64)\n#define irt_isu64(t)\t\t(irt_type(t) == IRT_U64)\n\n#define irt_isfp(t)\t\t(irt_isnum(t) || irt_isfloat(t))\n#define irt_isinteger(t)\t(irt_typerange((t), IRT_I8, IRT_INT))\n#define irt_isgcv(t)\t\t(irt_typerange((t), IRT_STR, IRT_UDATA))\n#define irt_isaddr(t)\t\t(irt_typerange((t), IRT_LIGHTUD, IRT_UDATA))\n#define irt_isint64(t)\t\t(irt_typerange((t), IRT_I64, IRT_U64))\n\n#if LJ_GC64\n/* Include IRT_NIL, so IR(ASMREF_L) (aka REF_NIL) is considered 64 bit. */\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|\\\n   (1u<<IRT_LIGHTUD)|(1u<<IRT_STR)|(1u<<IRT_THREAD)|(1u<<IRT_PROTO)|\\\n   (1u<<IRT_FUNC)|(1u<<IRT_CDATA)|(1u<<IRT_TAB)|(1u<<IRT_UDATA)|\\\n   (1u<<IRT_NIL))\n#elif LJ_64\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD))\n#else\n#define IRT_IS64 \\\n  ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64))\n#endif\n\n#define irt_is64(t)\t\t((IRT_IS64 >> irt_type(t)) & 1)\n#define irt_is64orfp(t)\t\t(((IRT_IS64|(1u<<IRT_FLOAT))>>irt_type(t)) & 1)\n\n#define irt_size(t)\t\t(lj_ir_type_size[irt_t((t))])\n\nLJ_DATA const uint8_t lj_ir_type_size[];\n\nstatic LJ_AINLINE IRType itype2irt(const TValue *tv)\n{\n  if (tvisint(tv))\n    return IRT_INT;\n  else if (tvisnum(tv))\n    return IRT_NUM;\n#if LJ_64 && !LJ_GC64\n  else if (tvislightud(tv))\n    return IRT_LIGHTUD;\n#endif\n  else\n    return (IRType)~itype(tv);\n}\n\nstatic LJ_AINLINE uint32_t irt_toitype_(IRType t)\n{\n  lj_assertX(!LJ_64 || LJ_GC64 || t != IRT_LIGHTUD,\n\t     \"no plain type tag for lightuserdata\");\n  if (LJ_DUALNUM && t > IRT_NUM) {\n    return LJ_TISNUM;\n  } else {\n    lj_assertX(t <= IRT_NUM, \"no plain type tag for IR type %d\", t);\n    return ~(uint32_t)t;\n  }\n}\n\n#define irt_toitype(t)\t\tirt_toitype_(irt_type((t)))\n\n#define irt_isguard(t)\t\t((t).irt & IRT_GUARD)\n#define irt_ismarked(t)\t\t((t).irt & IRT_MARK)\n#define irt_setmark(t)\t\t((t).irt |= IRT_MARK)\n#define irt_clearmark(t)\t((t).irt &= ~IRT_MARK)\n#define irt_isphi(t)\t\t((t).irt & IRT_ISPHI)\n#define irt_setphi(t)\t\t((t).irt |= IRT_ISPHI)\n#define irt_clearphi(t)\t\t((t).irt &= ~IRT_ISPHI)\n\n/* Stored combined IR opcode and type. */\ntypedef uint16_t IROpT;\n\n/* -- IR references ------------------------------------------------------- */\n\n/* IR references. */\ntypedef uint16_t IRRef1;\t/* One stored reference. */\ntypedef uint32_t IRRef2;\t/* Two stored references. */\ntypedef uint32_t IRRef;\t\t/* Used to pass around references. */\n\n/* Fixed references. */\nenum {\n  REF_BIAS =\t0x8000,\n  REF_TRUE =\tREF_BIAS-3,\n  REF_FALSE =\tREF_BIAS-2,\n  REF_NIL =\tREF_BIAS-1,\t/* \\--- Constants grow downwards. */\n  REF_BASE =\tREF_BIAS,\t/* /--- IR grows upwards. */\n  REF_FIRST =\tREF_BIAS+1,\n  REF_DROP =\t0xffff\n};\n\n/* Note: IRMlit operands must be < REF_BIAS, too!\n** This allows for fast and uniform manipulation of all operands\n** without looking up the operand mode in lj_ir_mode:\n** - CSE calculates the maximum reference of two operands.\n**   This must work with mixed reference/literal operands, too.\n** - DCE marking only checks for operand >= REF_BIAS.\n** - LOOP needs to substitute reference operands.\n**   Constant references and literals must not be modified.\n*/\n\n#define IRREF2(lo, hi)\t\t((IRRef2)(lo) | ((IRRef2)(hi) << 16))\n\n#define irref_isk(ref)\t\t((ref) < REF_BIAS)\n\n/* Tagged IR references (32 bit).\n**\n** +-------+-------+---------------+\n** |  irt  | flags |      ref      |\n** +-------+-------+---------------+\n**\n** The tag holds a copy of the IRType and speeds up IR type checks.\n*/\ntypedef uint32_t TRef;\n\n#define TREF_REFMASK\t\t0x0000ffff\n#define TREF_FRAME\t\t0x00010000\n#define TREF_CONT\t\t0x00020000\n#define TREF_KEYINDEX\t\t0x00100000\n\n#define TREF(ref, t)\t\t((TRef)((ref) + ((t)<<24)))\n\n#define tref_ref(tr)\t\t((IRRef1)(tr))\n#define tref_t(tr)\t\t((IRType)((tr)>>24))\n#define tref_type(tr)\t\t((IRType)(((tr)>>24) & IRT_TYPE))\n#define tref_typerange(tr, first, last) \\\n  ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first))\n\n#define tref_istype(tr, t)\t(((tr) & (IRT_TYPE<<24)) == ((t)<<24))\n#define tref_isnil(tr)\t\t(tref_istype((tr), IRT_NIL))\n#define tref_isfalse(tr)\t(tref_istype((tr), IRT_FALSE))\n#define tref_istrue(tr)\t\t(tref_istype((tr), IRT_TRUE))\n#define tref_islightud(tr)\t(tref_istype((tr), IRT_LIGHTUD))\n#define tref_isstr(tr)\t\t(tref_istype((tr), IRT_STR))\n#define tref_isfunc(tr)\t\t(tref_istype((tr), IRT_FUNC))\n#define tref_iscdata(tr)\t(tref_istype((tr), IRT_CDATA))\n#define tref_istab(tr)\t\t(tref_istype((tr), IRT_TAB))\n#define tref_isudata(tr)\t(tref_istype((tr), IRT_UDATA))\n#define tref_isnum(tr)\t\t(tref_istype((tr), IRT_NUM))\n#define tref_isint(tr)\t\t(tref_istype((tr), IRT_INT))\n\n#define tref_isbool(tr)\t\t(tref_typerange((tr), IRT_FALSE, IRT_TRUE))\n#define tref_ispri(tr)\t\t(tref_typerange((tr), IRT_NIL, IRT_TRUE))\n#define tref_istruecond(tr)\t(!tref_typerange((tr), IRT_NIL, IRT_FALSE))\n#define tref_isinteger(tr)\t(tref_typerange((tr), IRT_I8, IRT_INT))\n#define tref_isnumber(tr)\t(tref_typerange((tr), IRT_NUM, IRT_INT))\n#define tref_isnumber_str(tr)\t(tref_isnumber((tr)) || tref_isstr((tr)))\n#define tref_isgcv(tr)\t\t(tref_typerange((tr), IRT_STR, IRT_UDATA))\n\n#define tref_isk(tr)\t\t(irref_isk(tref_ref((tr))))\n#define tref_isk2(tr1, tr2)\t(irref_isk(tref_ref((tr1) | (tr2))))\n\n#define TREF_PRI(t)\t\t(TREF(REF_NIL-(t), (t)))\n#define TREF_NIL\t\t(TREF_PRI(IRT_NIL))\n#define TREF_FALSE\t\t(TREF_PRI(IRT_FALSE))\n#define TREF_TRUE\t\t(TREF_PRI(IRT_TRUE))\n\n/* -- IR format ----------------------------------------------------------- */\n\n/* IR instruction format (64 bit).\n**\n**    16      16     8   8   8   8\n** +-------+-------+---+---+---+---+\n** |  op1  |  op2  | t | o | r | s |\n** +-------+-------+---+---+---+---+\n** |  op12/i/gco32 |   ot  | prev  | (alternative fields in union)\n** +-------+-------+---+---+---+---+\n** |  TValue/gco64                 | (2nd IR slot for 64 bit constants)\n** +---------------+-------+-------+\n**        32           16      16\n**\n** prev is only valid prior to register allocation and then reused for r + s.\n*/\n\ntypedef union IRIns {\n  struct {\n    LJ_ENDIAN_LOHI(\n      IRRef1 op1;\t/* IR operand 1. */\n    , IRRef1 op2;\t/* IR operand 2. */\n    )\n    IROpT ot;\t\t/* IR opcode and type (overlaps t and o). */\n    IRRef1 prev;\t/* Previous ins in same chain (overlaps r and s). */\n  };\n  struct {\n    IRRef2 op12;\t/* IR operand 1 and 2 (overlaps op1 and op2). */\n    LJ_ENDIAN_LOHI(\n      IRType1 t;\t/* IR type. */\n    , IROp1 o;\t\t/* IR opcode. */\n    )\n    LJ_ENDIAN_LOHI(\n      uint8_t r;\t/* Register allocation (overlaps prev). */\n    , uint8_t s;\t/* Spill slot allocation (overlaps prev). */\n    )\n  };\n  int32_t i;\t\t/* 32 bit signed integer literal (overlaps op12). */\n  GCRef gcr;\t\t/* GCobj constant (overlaps op12 or entire slot). */\n  MRef ptr;\t\t/* Pointer constant (overlaps op12 or entire slot). */\n  TValue tv;\t\t/* TValue constant (overlaps entire slot). */\n} IRIns;\n\n#define ir_isk64(ir) \\\n  ((ir)->o == IR_KNUM || (ir)->o == IR_KINT64 || \\\n   (LJ_GC64 && \\\n    ((ir)->o == IR_KGC || (ir)->o == IR_KPTR || (ir)->o == IR_KKPTR)))\n\n#define ir_kgc(ir)\tcheck_exp((ir)->o == IR_KGC, gcref((ir)[LJ_GC64].gcr))\n#define ir_kstr(ir)\t(gco2str(ir_kgc((ir))))\n#define ir_ktab(ir)\t(gco2tab(ir_kgc((ir))))\n#define ir_kfunc(ir)\t(gco2func(ir_kgc((ir))))\n#define ir_kcdata(ir)\t(gco2cd(ir_kgc((ir))))\n#define ir_knum(ir)\tcheck_exp((ir)->o == IR_KNUM, &(ir)[1].tv)\n#define ir_kint64(ir)\tcheck_exp((ir)->o == IR_KINT64, &(ir)[1].tv)\n#define ir_k64(ir)\tcheck_exp(ir_isk64(ir), &(ir)[1].tv)\n#define ir_kptr(ir) \\\n  check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, \\\n    mref((ir)[LJ_GC64].ptr, void))\n\n/* A store or any other op with a non-weak guard has a side-effect. */\nstatic LJ_AINLINE int ir_sideeff(IRIns *ir)\n{\n  return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S);\n}\n\nLJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);\n\n/* Replace IR instruction with NOP. */\nstatic LJ_AINLINE void lj_ir_nop(IRIns *ir)\n{\n  ir->ot = IRT(IR_NOP, IRT_NIL);\n  ir->op1 = ir->op2 = 0;\n  ir->prev = 0;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_ircall.h",
    "content": "/*\n** IR CALL* instruction definitions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IRCALL_H\n#define _LJ_IRCALL_H\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n\n/* C call info for CALL* instructions. */\ntypedef struct CCallInfo {\n  ASMFunction func;\t\t/* Function pointer. */\n  uint32_t flags;\t\t/* Number of arguments and flags. */\n} CCallInfo;\n\n#define CCI_NARGS(ci)\t\t((ci)->flags & 0xff)\t/* # of args. */\n#define CCI_NARGS_MAX\t\t32\t\t\t/* Max. # of args. */\n\n#define CCI_OTSHIFT\t\t16\n#define CCI_OPTYPE(ci)\t\t((ci)->flags >> CCI_OTSHIFT)  /* Get op/type. */\n#define CCI_TYPE(ci)\t\t(((ci)->flags>>CCI_OTSHIFT) & IRT_TYPE)\n#define CCI_OPSHIFT\t\t24\n#define CCI_OP(ci)\t\t((ci)->flags >> CCI_OPSHIFT)  /* Get op. */\n\n#define CCI_CALL_N\t\t(IR_CALLN << CCI_OPSHIFT)\n#define CCI_CALL_A\t\t(IR_CALLA << CCI_OPSHIFT)\n#define CCI_CALL_L\t\t(IR_CALLL << CCI_OPSHIFT)\n#define CCI_CALL_S\t\t(IR_CALLS << CCI_OPSHIFT)\n#define CCI_CALL_FN\t\t(CCI_CALL_N|CCI_CC_FASTCALL)\n#define CCI_CALL_FA\t\t(CCI_CALL_A|CCI_CC_FASTCALL)\n#define CCI_CALL_FL\t\t(CCI_CALL_L|CCI_CC_FASTCALL)\n#define CCI_CALL_FS\t\t(CCI_CALL_S|CCI_CC_FASTCALL)\n\n/* C call info flags. */\n#define CCI_T\t\t\t(IRT_GUARD << CCI_OTSHIFT)  /* May throw. */\n#define CCI_L\t\t\t0x0100\t/* Implicit L arg. */\n#define CCI_CASTU64\t\t0x0200\t/* Cast u64 result to number. */\n#define CCI_NOFPRCLOBBER\t0x0400\t/* Does not clobber any FPRs. */\n#define CCI_VARARG\t\t0x0800\t/* Vararg function. */\n\n#define CCI_CC_MASK\t\t0x3000\t/* Calling convention mask. */\n#define CCI_CC_SHIFT\t\t12\n/* ORDER CC */\n#define CCI_CC_CDECL\t\t0x0000\t/* Default cdecl calling convention. */\n#define CCI_CC_THISCALL\t\t0x1000\t/* Thiscall calling convention. */\n#define CCI_CC_FASTCALL\t\t0x2000\t/* Fastcall calling convention. */\n#define CCI_CC_STDCALL\t\t0x3000\t/* Stdcall calling convention. */\n\n/* Extra args for SOFTFP, SPLIT 64 bit. */\n#define CCI_XARGS_SHIFT\t\t14\n#define CCI_XARGS(ci)\t\t(((ci)->flags >> CCI_XARGS_SHIFT) & 3)\n#define CCI_XA\t\t\t(1u << CCI_XARGS_SHIFT)\n\n#if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)\n#define CCI_XNARGS(ci)\t\t(CCI_NARGS((ci)) + CCI_XARGS((ci)))\n#else\n#define CCI_XNARGS(ci)\t\tCCI_NARGS((ci))\n#endif\n\n/* Helpers for conditional function definitions. */\n#define IRCALLCOND_ANY(x)\t\tx\n\n#if LJ_TARGET_X86ORX64\n#define IRCALLCOND_FPMATH(x)\t\tNULL\n#else\n#define IRCALLCOND_FPMATH(x)\t\tx\n#endif\n\n#if LJ_SOFTFP\n#define IRCALLCOND_SOFTFP(x)\t\tx\n#if LJ_HASFFI\n#define IRCALLCOND_SOFTFP_FFI(x)\tx\n#else\n#define IRCALLCOND_SOFTFP_FFI(x)\tNULL\n#endif\n#else\n#define IRCALLCOND_SOFTFP(x)\t\tNULL\n#define IRCALLCOND_SOFTFP_FFI(x)\tNULL\n#endif\n\n#if LJ_SOFTFP && LJ_TARGET_MIPS\n#define IRCALLCOND_SOFTFP_MIPS(x)\tx\n#else\n#define IRCALLCOND_SOFTFP_MIPS(x)\tNULL\n#endif\n\n#if LJ_SOFTFP && LJ_TARGET_MIPS64\n#define IRCALLCOND_SOFTFP_MIPS64(x)\tx\n#else\n#define IRCALLCOND_SOFTFP_MIPS64(x)\tNULL\n#endif\n\n#define LJ_NEED_FP64\t(LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS)\n\n#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)\n#define IRCALLCOND_FP64_FFI(x)\t\tx\n#else\n#define IRCALLCOND_FP64_FFI(x)\t\tNULL\n#endif\n\n#if LJ_HASFFI\n#define IRCALLCOND_FFI(x)\t\tx\n#if LJ_32\n#define IRCALLCOND_FFI32(x)\t\tx\n#else\n#define IRCALLCOND_FFI32(x)\t\tNULL\n#endif\n#else\n#define IRCALLCOND_FFI(x)\t\tNULL\n#define IRCALLCOND_FFI32(x)\t\tNULL\n#endif\n\n#if LJ_HASBUFFER\n#define IRCALLCOND_BUFFER(x)\t\tx\n#else\n#define IRCALLCOND_BUFFER(x)\t\tNULL\n#endif\n\n#if LJ_HASBUFFER && LJ_HASFFI\n#define IRCALLCOND_BUFFFI(x)\t\tx\n#else\n#define IRCALLCOND_BUFFFI(x)\t\tNULL\n#endif\n\n#if LJ_SOFTFP\n#define XA_FP\t\tCCI_XA\n#define XA2_FP\t\t(CCI_XA+CCI_XA)\n#else\n#define XA_FP\t\t0\n#define XA2_FP\t\t0\n#endif\n\n#if LJ_SOFTFP32\n#define XA_FP32\t\tCCI_XA\n#define XA2_FP32\t(CCI_XA+CCI_XA)\n#else\n#define XA_FP32\t\t0\n#define XA2_FP32\t0\n#endif\n\n#if LJ_32\n#define XA_64\t\tCCI_XA\n#define XA2_64\t\t(CCI_XA+CCI_XA)\n#else\n#define XA_64\t\t0\n#define XA2_64\t\t0\n#endif\n\n/* Function definitions for CALL* instructions. */\n#define IRCALLDEF(_) \\\n  _(ANY,\tlj_str_cmp,\t\t2,  FN, INT, CCI_NOFPRCLOBBER) \\\n  _(ANY,\tlj_str_find,\t\t4,   N, PGC, 0) \\\n  _(ANY,\tlj_str_new,\t\t3,   S, STR, CCI_L|CCI_T) \\\n  _(ANY,\tlj_strscan_num,\t\t2,  FN, INT, 0) \\\n  _(ANY,\tlj_strfmt_int,\t\t2,  FN, STR, CCI_L|CCI_T) \\\n  _(ANY,\tlj_strfmt_num,\t\t2,  FN, STR, CCI_L|CCI_T) \\\n  _(ANY,\tlj_strfmt_char,\t\t2,  FN, STR, CCI_L|CCI_T) \\\n  _(ANY,\tlj_strfmt_putint,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_strfmt_putnum,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_strfmt_putquoted,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_strfmt_putfxint,\t3,   L, PGC, XA_64|CCI_T) \\\n  _(ANY,\tlj_strfmt_putfnum_int,\t3,   L, PGC, XA_FP|CCI_T) \\\n  _(ANY,\tlj_strfmt_putfnum_uint,\t3,   L, PGC, XA_FP|CCI_T) \\\n  _(ANY,\tlj_strfmt_putfnum,\t3,   L, PGC, XA_FP|CCI_T) \\\n  _(ANY,\tlj_strfmt_putfstr,\t3,   L, PGC, CCI_T) \\\n  _(ANY,\tlj_strfmt_putfchar,\t3,   L, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putmem,\t\t3,   S, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putstr,\t\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putchar,\t\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putstr_reverse,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putstr_lower,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putstr_upper,\t2,  FL, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_putstr_rep,\t3,   L, PGC, CCI_T) \\\n  _(ANY,\tlj_buf_puttab,\t\t5,   L, PGC, CCI_T) \\\n  _(BUFFER,\tlj_bufx_set,\t\t4,   S, NIL, 0) \\\n  _(BUFFFI,\tlj_bufx_more,\t\t2,  FS, INT, CCI_T) \\\n  _(BUFFER,\tlj_serialize_put,\t2,  FS, PGC, CCI_T) \\\n  _(BUFFER,\tlj_serialize_get,\t2,  FS, PTR, CCI_T) \\\n  _(BUFFER,\tlj_serialize_encode,\t2,  FA, STR, CCI_L|CCI_T) \\\n  _(BUFFER,\tlj_serialize_decode,\t3,   A, INT, CCI_L|CCI_T) \\\n  _(ANY,\tlj_buf_tostr,\t\t1,  FL, STR, CCI_T) \\\n  _(ANY,\tlj_tab_new_ah,\t\t3,   A, TAB, CCI_L|CCI_T) \\\n  _(ANY,\tlj_tab_new1,\t\t2,  FA, TAB, CCI_L|CCI_T) \\\n  _(ANY,\tlj_tab_dup,\t\t2,  FA, TAB, CCI_L|CCI_T) \\\n  _(ANY,\tlj_tab_clear,\t\t1,  FS, NIL, 0) \\\n  _(ANY,\tlj_tab_newkey,\t\t3,   S, PGC, CCI_L|CCI_T) \\\n  _(ANY,\tlj_tab_keyindex,\t2,  FL, INT, 0) \\\n  _(ANY,\tlj_vm_next,\t\t2,  FL, PTR, 0) \\\n  _(ANY,\tlj_tab_len,\t\t1,  FL, INT, 0) \\\n  _(ANY,\tlj_tab_len_hint,\t2,  FL, INT, 0) \\\n  _(ANY,\tlj_gc_step_jit,\t\t2,  FS, NIL, CCI_L) \\\n  _(ANY,\tlj_gc_barrieruv,\t2,  FS, NIL, 0) \\\n  _(ANY,\tlj_mem_newgco,\t\t2,  FA, PGC, CCI_L|CCI_T) \\\n  _(ANY,\tlj_prng_u64d,\t\t1,  FS, NUM, CCI_CASTU64) \\\n  _(ANY,\tlj_vm_modi,\t\t2,  FN, INT, 0) \\\n  _(ANY,\tlog10,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\texp,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tsin,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tcos,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\ttan,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tasin,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tacos,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tatan,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tsinh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tcosh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\ttanh,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tfputc,\t\t\t2,   S, INT, 0) \\\n  _(ANY,\tfwrite,\t\t\t4,   S, INT, 0) \\\n  _(ANY,\tfflush,\t\t\t1,   S, INT, 0) \\\n  /* ORDER FPM */ \\\n  _(FPMATH,\tlj_vm_floor,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tlj_vm_ceil,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tlj_vm_trunc,\t\t1,   N, NUM, XA_FP) \\\n  _(FPMATH,\tsqrt,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlog,\t\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlj_vm_log2,\t\t1,   N, NUM, XA_FP) \\\n  _(ANY,\tlj_vm_powi,\t\t2,   N, NUM, XA_FP) \\\n  _(ANY,\tpow,\t\t\t2,   N, NUM, XA2_FP) \\\n  _(ANY,\tatan2,\t\t\t2,   N, NUM, XA2_FP) \\\n  _(ANY,\tldexp,\t\t\t2,   N, NUM, XA_FP) \\\n  _(SOFTFP,\tlj_vm_tobit,\t\t1,   N, INT, XA_FP32) \\\n  _(SOFTFP,\tsoftfp_add,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP,\tsoftfp_sub,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP,\tsoftfp_mul,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP,\tsoftfp_div,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP,\tsoftfp_cmp,\t\t2,   N, NIL, XA2_FP32) \\\n  _(SOFTFP,\tsoftfp_i2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP,\tsoftfp_d2i,\t\t1,   N, INT, XA_FP32) \\\n  _(SOFTFP_MIPS, lj_vm_sfmin,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP_MIPS, lj_vm_sfmax,\t\t2,   N, NUM, XA2_FP32) \\\n  _(SOFTFP_MIPS64, lj_vm_tointg,\t1,   N, INT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_ui2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2d,\t\t1,   N, NUM, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_d2ui,\t\t1,   N, INT, XA_FP32) \\\n  _(SOFTFP_FFI,\tsoftfp_d2f,\t\t1,   N, FLOAT, XA_FP32) \\\n  _(SOFTFP_FFI,\tsoftfp_i2f,\t\t1,   N, FLOAT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_ui2f,\t\t1,   N, FLOAT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2i,\t\t1,   N, INT, 0) \\\n  _(SOFTFP_FFI,\tsoftfp_f2ui,\t\t1,   N, INT, 0) \\\n  _(FP64_FFI,\tfp64_l2d,\t\t1,   N, NUM, XA_64) \\\n  _(FP64_FFI,\tfp64_ul2d,\t\t1,   N, NUM, XA_64) \\\n  _(FP64_FFI,\tfp64_l2f,\t\t1,   N, FLOAT, XA_64) \\\n  _(FP64_FFI,\tfp64_ul2f,\t\t1,   N, FLOAT, XA_64) \\\n  _(FP64_FFI,\tfp64_d2l,\t\t1,   N, I64, XA_FP) \\\n  _(FP64_FFI,\tfp64_d2ul,\t\t1,   N, U64, XA_FP) \\\n  _(FP64_FFI,\tfp64_f2l,\t\t1,   N, I64, 0) \\\n  _(FP64_FFI,\tfp64_f2ul,\t\t1,   N, U64, 0) \\\n  _(FFI,\tlj_carith_divi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_divu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_modi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_modu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_powi64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_carith_powu64,\t2,   N, U64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI,\tlj_cdata_newv,\t\t4,   S, CDATA, CCI_L) \\\n  _(FFI,\tlj_cdata_setfin,\t4,   S, NIL, CCI_L) \\\n  _(FFI,\tstrlen,\t\t\t1,   L, INTP, 0) \\\n  _(FFI,\tmemcpy,\t\t\t3,   S, PTR, 0) \\\n  _(FFI,\tmemset,\t\t\t3,   S, PTR, 0) \\\n  _(FFI,\tlj_vm_errno,\t\t0,   S, INT, CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_mul64,\t2,   N, I64, XA2_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_shl64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_shr64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_sar64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_rol64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  _(FFI32,\tlj_carith_ror64,\t2,   N, U64, XA_64|CCI_NOFPRCLOBBER) \\\n  \\\n  /* End of list. */\n\ntypedef enum {\n#define IRCALLENUM(cond, name, nargs, kind, type, flags)\tIRCALL_##name,\nIRCALLDEF(IRCALLENUM)\n#undef IRCALLENUM\n  IRCALL__MAX\n} IRCallID;\n\nLJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);\n\nLJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];\n\n/* Soft-float declarations. */\n#if LJ_SOFTFP\n#if LJ_TARGET_ARM\n#define softfp_add __aeabi_dadd\n#define softfp_sub __aeabi_dsub\n#define softfp_mul __aeabi_dmul\n#define softfp_div __aeabi_ddiv\n#define softfp_cmp __aeabi_cdcmple\n#define softfp_i2d __aeabi_i2d\n#define softfp_d2i __aeabi_d2iz\n#define softfp_ui2d __aeabi_ui2d\n#define softfp_f2d __aeabi_f2d\n#define softfp_d2ui __aeabi_d2uiz\n#define softfp_d2f __aeabi_d2f\n#define softfp_i2f __aeabi_i2f\n#define softfp_ui2f __aeabi_ui2f\n#define softfp_f2i __aeabi_f2iz\n#define softfp_f2ui __aeabi_f2uiz\n#define fp64_l2d __aeabi_l2d\n#define fp64_ul2d __aeabi_ul2d\n#define fp64_l2f __aeabi_l2f\n#define fp64_ul2f __aeabi_ul2f\n#if LJ_TARGET_IOS\n#define fp64_d2l __fixdfdi\n#define fp64_d2ul __fixunsdfdi\n#define fp64_f2l __fixsfdi\n#define fp64_f2ul __fixunssfdi\n#else\n#define fp64_d2l __aeabi_d2lz\n#define fp64_d2ul __aeabi_d2ulz\n#define fp64_f2l __aeabi_f2lz\n#define fp64_f2ul __aeabi_f2ulz\n#endif\n#elif LJ_TARGET_MIPS || LJ_TARGET_PPC\n#define softfp_add __adddf3\n#define softfp_sub __subdf3\n#define softfp_mul __muldf3\n#define softfp_div __divdf3\n#define softfp_cmp __ledf2\n#define softfp_i2d __floatsidf\n#define softfp_d2i __fixdfsi\n#define softfp_ui2d __floatunsidf\n#define softfp_f2d __extendsfdf2\n#define softfp_d2ui __fixunsdfsi\n#define softfp_d2f __truncdfsf2\n#define softfp_i2f __floatsisf\n#define softfp_ui2f __floatunsisf\n#define softfp_f2i __fixsfsi\n#define softfp_f2ui __fixunssfsi\n#else\n#error \"Missing soft-float definitions for target architecture\"\n#endif\nextern double softfp_add(double a, double b);\nextern double softfp_sub(double a, double b);\nextern double softfp_mul(double a, double b);\nextern double softfp_div(double a, double b);\nextern void softfp_cmp(double a, double b);\nextern double softfp_i2d(int32_t a);\nextern int32_t softfp_d2i(double a);\n#if LJ_HASFFI\nextern double softfp_ui2d(uint32_t a);\nextern double softfp_f2d(float a);\nextern uint32_t softfp_d2ui(double a);\nextern float softfp_d2f(double a);\nextern float softfp_i2f(int32_t a);\nextern float softfp_ui2f(uint32_t a);\nextern int32_t softfp_f2i(float a);\nextern uint32_t softfp_f2ui(float a);\n#endif\n#if LJ_TARGET_MIPS\nextern double lj_vm_sfmin(double a, double b);\nextern double lj_vm_sfmax(double a, double b);\n#endif\n#endif\n\n#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP)\n#if defined(__GNUC__) || defined(__clang__)\n#define fp64_l2d __floatdidf\n#define fp64_ul2d __floatundidf\n#define fp64_l2f __floatdisf\n#define fp64_ul2f __floatundisf\n#define fp64_d2l __fixdfdi\n#define fp64_d2ul __fixunsdfdi\n#define fp64_f2l __fixsfdi\n#define fp64_f2ul __fixunssfdi\n#else\n#error \"Missing fp64 helper definitions for this compiler\"\n#endif\n#endif\n\n#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)\nextern double fp64_l2d(int64_t a);\nextern double fp64_ul2d(uint64_t a);\nextern float fp64_l2f(int64_t a);\nextern float fp64_ul2f(uint64_t a);\nextern int64_t fp64_d2l(double a);\nextern uint64_t fp64_d2ul(double a);\nextern int64_t fp64_f2l(float a);\nextern uint64_t fp64_f2ul(float a);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_iropt.h",
    "content": "/*\n** Common header for IR emitter and optimizations.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_IROPT_H\n#define _LJ_IROPT_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* IR emitter. */\nLJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J);\n\n/* Save current IR in J->fold.ins, but do not emit it (yet). */\nstatic LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b)\n{\n  J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b;\n}\n\n#define lj_ir_set(J, ot, a, b) \\\n  lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b))\n\n/* Get ref of next IR instruction and optionally grow IR.\n** Note: this may invalidate all IRIns*!\n*/\nstatic LJ_AINLINE IRRef lj_ir_nextins(jit_State *J)\n{\n  IRRef ref = J->cur.nins;\n  if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J);\n  J->cur.nins = ref + 1;\n  return ref;\n}\n\nLJ_FUNC TRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs);\n\n/* Interning of constants. */\nLJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k);\nLJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, uint64_t u64);\nLJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64);\nLJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n);\nLJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64);\nLJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);\nLJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);\nLJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);\nLJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);\nLJ_FUNC TRef lj_ir_ktrace(jit_State *J);\n\n#if LJ_64\n#define lj_ir_kintp(J, k)\tlj_ir_kint64(J, (uint64_t)(k))\n#else\n#define lj_ir_kintp(J, k)\tlj_ir_kint(J, (int32_t)(k))\n#endif\n\nstatic LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n)\n{\n  TValue tv;\n  tv.n = n;\n  return lj_ir_knum_u64(J, tv.u64);\n}\n\n#define lj_ir_kstr(J, str)\tlj_ir_kgc(J, obj2gco((str)), IRT_STR)\n#define lj_ir_ktab(J, tab)\tlj_ir_kgc(J, obj2gco((tab)), IRT_TAB)\n#define lj_ir_kfunc(J, func)\tlj_ir_kgc(J, obj2gco((func)), IRT_FUNC)\n#define lj_ir_kptr(J, ptr)\tlj_ir_kptr_(J, IR_KPTR, (ptr))\n#define lj_ir_kkptr(J, ptr)\tlj_ir_kptr_(J, IR_KKPTR, (ptr))\n\n/* Special FP constants. */\n#define lj_ir_knum_zero(J)\tlj_ir_knum_u64(J, U64x(00000000,00000000))\n#define lj_ir_knum_one(J)\tlj_ir_knum_u64(J, U64x(3ff00000,00000000))\n#define lj_ir_knum_tobit(J)\tlj_ir_knum_u64(J, U64x(43380000,00000000))\n\n/* Special 128 bit SIMD constants. */\n#define lj_ir_ksimd(J, idx) \\\n  lj_ir_ggfload(J, IRT_NUM, (uintptr_t)LJ_KSIMD(J, idx) - (uintptr_t)J2GG(J))\n\n/* Access to constants. */\nLJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir);\n\n/* Convert IR operand types. */\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr);\n\n/* Miscellaneous IR ops. */\nLJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op);\nLJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op);\nLJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref);\n\n/* Emit IR instructions with on-the-fly optimizations. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim);\n\n/* Special return values for the fold functions. */\nenum {\n  NEXTFOLD,\t\t/* Couldn't fold, pass on. */\n  RETRYFOLD,\t\t/* Retry fold with modified fins. */\n  KINTFOLD,\t\t/* Return ref for int constant in fins->i. */\n  FAILFOLD,\t\t/* Guard would always fail. */\n  DROPFOLD,\t\t/* Guard eliminated. */\n  MAX_FOLD\n};\n\n#define INTFOLD(k)\t((J->fold.ins.i = (k)), (TRef)KINTFOLD)\n#define INT64FOLD(k)\t(lj_ir_kint64(J, (k)))\n#define CONDFOLD(cond)\t((TRef)FAILFOLD + (TRef)(cond))\n#define LEFTFOLD\t(J->fold.ins.op1)\n#define RIGHTFOLD\t(J->fold.ins.op2)\n#define CSEFOLD\t\t(lj_opt_cse(J))\n#define EMITFOLD\t(lj_ir_emit(J))\n\n/* Load/store forwarding. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_alen(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J);\nLJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J);\nLJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim);\nLJ_FUNC int LJ_FASTCALL lj_opt_fwd_sbuf(jit_State *J, IRRef lim);\nLJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref);\n\n/* Dead-store elimination. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J);\n\n/* Narrowing. */\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr);\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr);\n#if LJ_HASFFI\nLJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key);\n#endif\nLJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,\n\t\t\t\t TValue *vb, TValue *vc, IROp op);\nLJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc);\nLJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);\nLJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);\nLJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase);\n\n/* Optimization passes. */\nLJ_FUNC void lj_opt_dce(jit_State *J);\nLJ_FUNC int lj_opt_loop(jit_State *J);\n#if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)\nLJ_FUNC void lj_opt_split(jit_State *J);\n#else\n#define lj_opt_split(J)\t\tUNUSED(J)\n#endif\nLJ_FUNC void lj_opt_sink(jit_State *J);\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_jit.h",
    "content": "/*\n** Common definitions for the JIT compiler.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_JIT_H\n#define _LJ_JIT_H\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n\n/* -- JIT engine flags ---------------------------------------------------- */\n\n/* General JIT engine flags. 4 bits. */\n#define JIT_F_ON\t\t0x00000001\n\n/* CPU-specific JIT engine flags. 12 bits. Flags and strings must match. */\n#define JIT_F_CPU\t\t0x00000010\n\n#if LJ_TARGET_X86ORX64\n\n#define JIT_F_SSE3\t\t(JIT_F_CPU << 0)\n#define JIT_F_SSE4_1\t\t(JIT_F_CPU << 1)\n#define JIT_F_BMI2\t\t(JIT_F_CPU << 2)\n\n\n#define JIT_F_CPUSTRING\t\t\"\\4SSE3\\6SSE4.1\\4BMI2\"\n\n#elif LJ_TARGET_ARM\n\n#define JIT_F_ARMV6_\t\t(JIT_F_CPU << 0)\n#define JIT_F_ARMV6T2_\t\t(JIT_F_CPU << 1)\n#define JIT_F_ARMV7\t\t(JIT_F_CPU << 2)\n#define JIT_F_ARMV8\t\t(JIT_F_CPU << 3)\n#define JIT_F_VFPV2\t\t(JIT_F_CPU << 4)\n#define JIT_F_VFPV3\t\t(JIT_F_CPU << 5)\n\n#define JIT_F_ARMV6\t\t(JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)\n#define JIT_F_ARMV6T2\t\t(JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)\n#define JIT_F_VFP\t\t(JIT_F_VFPV2|JIT_F_VFPV3)\n\n#define JIT_F_CPUSTRING\t\t\"\\5ARMv6\\7ARMv6T2\\5ARMv7\\5ARMv8\\5VFPv2\\5VFPv3\"\n\n#elif LJ_TARGET_PPC\n\n#define JIT_F_SQRT\t\t(JIT_F_CPU << 0)\n#define JIT_F_ROUND\t\t(JIT_F_CPU << 1)\n\n#define JIT_F_CPUSTRING\t\t\"\\4SQRT\\5ROUND\"\n\n#elif LJ_TARGET_MIPS\n\n#define JIT_F_MIPSXXR2\t\t(JIT_F_CPU << 0)\n\n#if LJ_TARGET_MIPS32\n#if LJ_TARGET_MIPSR6\n#define JIT_F_CPUSTRING\t\t\"\\010MIPS32R6\"\n#else\n#define JIT_F_CPUSTRING\t\t\"\\010MIPS32R2\"\n#endif\n#else\n#if LJ_TARGET_MIPSR6\n#define JIT_F_CPUSTRING\t\t\"\\010MIPS64R6\"\n#else\n#define JIT_F_CPUSTRING\t\t\"\\010MIPS64R2\"\n#endif\n#endif\n\n#else\n\n#define JIT_F_CPUSTRING\t\t\"\"\n\n#endif\n\n/* Optimization flags. 12 bits. */\n#define JIT_F_OPT\t\t0x00010000\n#define JIT_F_OPT_MASK\t\t0x0fff0000\n\n#define JIT_F_OPT_FOLD\t\t(JIT_F_OPT << 0)\n#define JIT_F_OPT_CSE\t\t(JIT_F_OPT << 1)\n#define JIT_F_OPT_DCE\t\t(JIT_F_OPT << 2)\n#define JIT_F_OPT_FWD\t\t(JIT_F_OPT << 3)\n#define JIT_F_OPT_DSE\t\t(JIT_F_OPT << 4)\n#define JIT_F_OPT_NARROW\t(JIT_F_OPT << 5)\n#define JIT_F_OPT_LOOP\t\t(JIT_F_OPT << 6)\n#define JIT_F_OPT_ABC\t\t(JIT_F_OPT << 7)\n#define JIT_F_OPT_SINK\t\t(JIT_F_OPT << 8)\n#define JIT_F_OPT_FUSE\t\t(JIT_F_OPT << 9)\n\n/* Optimizations names for -O. Must match the order above. */\n#define JIT_F_OPTSTRING\t\\\n  \"\\4fold\\3cse\\3dce\\3fwd\\3dse\\6narrow\\4loop\\3abc\\4sink\\4fuse\"\n\n/* Optimization levels set a fixed combination of flags. */\n#define JIT_F_OPT_0\t0\n#define JIT_F_OPT_1\t(JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE)\n#define JIT_F_OPT_2\t(JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP)\n#define JIT_F_OPT_3\t(JIT_F_OPT_2|\\\n  JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)\n#define JIT_F_OPT_DEFAULT\tJIT_F_OPT_3\n\n/* -- JIT engine parameters ----------------------------------------------- */\n\n#if LJ_TARGET_WINDOWS || LJ_64\n/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */\n#define JIT_P_sizemcode_DEFAULT\t\t64\n#else\n/* Could go as low as 4K, but the mmap() overhead would be rather high. */\n#define JIT_P_sizemcode_DEFAULT\t\t32\n#endif\n\n/* Optimization parameters and their defaults. Length is a char in octal! */\n#define JIT_PARAMDEF(_) \\\n  _(\\010, maxtrace,\t1000)\t/* Max. # of traces in cache. */ \\\n  _(\\011, maxrecord,\t4000)\t/* Max. # of recorded IR instructions. */ \\\n  _(\\012, maxirconst,\t500)\t/* Max. # of IR constants of a trace. */ \\\n  _(\\007, maxside,\t100)\t/* Max. # of side traces of a root trace. */ \\\n  _(\\007, maxsnap,\t500)\t/* Max. # of snapshots for a trace. */ \\\n  _(\\011, minstitch,\t0)\t/* Min. # of IR ins for a stitched trace. */ \\\n  \\\n  _(\\007, hotloop,\t56)\t/* # of iter. to detect a hot loop/call. */ \\\n  _(\\007, hotexit,\t10)\t/* # of taken exits to start a side trace. */ \\\n  _(\\007, tryside,\t4)\t/* # of attempts to compile a side trace. */ \\\n  \\\n  _(\\012, instunroll,\t4)\t/* Max. unroll for instable loops. */ \\\n  _(\\012, loopunroll,\t15)\t/* Max. unroll for loop ops in side traces. */ \\\n  _(\\012, callunroll,\t3)\t/* Max. unroll for recursive calls. */ \\\n  _(\\011, recunroll,\t2)\t/* Min. unroll for true recursion. */ \\\n  \\\n  /* Size of each machine code area (in KBytes). */ \\\n  _(\\011, sizemcode,\tJIT_P_sizemcode_DEFAULT) \\\n  /* Max. total size of all machine code areas (in KBytes). */ \\\n  _(\\010, maxmcode,\t512) \\\n  /* End of list. */\n\nenum {\n#define JIT_PARAMENUM(len, name, value)\tJIT_P_##name,\nJIT_PARAMDEF(JIT_PARAMENUM)\n#undef JIT_PARAMENUM\n  JIT_P__MAX\n};\n\n#define JIT_PARAMSTR(len, name, value)\t#len #name\n#define JIT_P_STRING\tJIT_PARAMDEF(JIT_PARAMSTR)\n\n/* -- JIT engine data structures ------------------------------------------ */\n\n/* Trace compiler state. */\ntypedef enum {\n  LJ_TRACE_IDLE,\t/* Trace compiler idle. */\n  LJ_TRACE_ACTIVE = 0x10,\n  LJ_TRACE_RECORD,\t/* Bytecode recording active. */\n  LJ_TRACE_RECORD_1ST,\t/* Record 1st instruction, too. */\n  LJ_TRACE_START,\t/* New trace started. */\n  LJ_TRACE_END,\t\t/* End of trace. */\n  LJ_TRACE_ASM,\t\t/* Assemble trace. */\n  LJ_TRACE_ERR\t\t/* Trace aborted with error. */\n} TraceState;\n\n/* Post-processing action. */\ntypedef enum {\n  LJ_POST_NONE,\t\t/* No action. */\n  LJ_POST_FIXCOMP,\t/* Fixup comparison and emit pending guard. */\n  LJ_POST_FIXGUARD,\t/* Fixup and emit pending guard. */\n  LJ_POST_FIXGUARDSNAP,\t/* Fixup and emit pending guard and snapshot. */\n  LJ_POST_FIXBOOL,\t/* Fixup boolean result. */\n  LJ_POST_FIXCONST,\t/* Fixup constant results. */\n  LJ_POST_FFRETRY\t/* Suppress recording of retried fast functions. */\n} PostProc;\n\n/* Machine code type. */\n#if LJ_TARGET_X86ORX64\ntypedef uint8_t MCode;\n#else\ntypedef uint32_t MCode;\n#endif\n\n/* Linked list of MCode areas. */\ntypedef struct MCLink {\n  MCode *next;\t\t/* Next area. */\n  size_t size;\t\t/* Size of current area. */\n} MCLink;\n\n/* Stack snapshot header. */\ntypedef struct SnapShot {\n  uint32_t mapofs;\t/* Offset into snapshot map. */\n  IRRef1 ref;\t\t/* First IR ref for this snapshot. */\n  uint16_t mcofs;\t/* Offset into machine code in MCode units. */\n  uint8_t nslots;\t/* Number of valid slots. */\n  uint8_t topslot;\t/* Maximum frame extent. */\n  uint8_t nent;\t\t/* Number of compressed entries. */\n  uint8_t count;\t/* Count of taken exits for this snapshot. */\n} SnapShot;\n\n#define SNAPCOUNT_DONE\t255\t/* Already compiled and linked a side trace. */\n\n/* Compressed snapshot entry. */\ntypedef uint32_t SnapEntry;\n\n#define SNAP_FRAME\t\t0x010000\t/* Frame slot. */\n#define SNAP_CONT\t\t0x020000\t/* Continuation slot. */\n#define SNAP_NORESTORE\t\t0x040000\t/* No need to restore slot. */\n#define SNAP_SOFTFPNUM\t\t0x080000\t/* Soft-float number. */\n#define SNAP_KEYINDEX\t\t0x100000\t/* Traversal key index. */\nLJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME);\nLJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT);\nLJ_STATIC_ASSERT(SNAP_KEYINDEX == TREF_KEYINDEX);\n\n#define SNAP(slot, flags, ref)\t(((SnapEntry)(slot) << 24) + (flags) + (ref))\n#define SNAP_TR(slot, tr) \\\n  (((SnapEntry)(slot) << 24) + \\\n   ((tr) & (TREF_KEYINDEX|TREF_CONT|TREF_FRAME|TREF_REFMASK)))\n#if !LJ_FR2\n#define SNAP_MKPC(pc)\t\t((SnapEntry)u32ptr(pc))\n#endif\n#define SNAP_MKFTSZ(ftsz)\t((SnapEntry)(ftsz))\n#define snap_ref(sn)\t\t((sn) & 0xffff)\n#define snap_slot(sn)\t\t((BCReg)((sn) >> 24))\n#define snap_isframe(sn)\t((sn) & SNAP_FRAME)\n#define snap_setref(sn, ref)\t(((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref))\n\nstatic LJ_AINLINE const BCIns *snap_pc(SnapEntry *sn)\n{\n#if LJ_FR2\n  uint64_t pcbase;\n  memcpy(&pcbase, sn, sizeof(uint64_t));\n  return (const BCIns *)(pcbase >> 8);\n#else\n  return (const BCIns *)(uintptr_t)*sn;\n#endif\n}\n\n/* Snapshot and exit numbers. */\ntypedef uint32_t SnapNo;\ntypedef uint32_t ExitNo;\n\n/* Trace number. */\ntypedef uint32_t TraceNo;\t/* Used to pass around trace numbers. */\ntypedef uint16_t TraceNo1;\t/* Stored trace number. */\n\n/* Type of link. ORDER LJ_TRLINK */\ntypedef enum {\n  LJ_TRLINK_NONE,\t\t/* Incomplete trace. No link, yet. */\n  LJ_TRLINK_ROOT,\t\t/* Link to other root trace. */\n  LJ_TRLINK_LOOP,\t\t/* Loop to same trace. */\n  LJ_TRLINK_TAILREC,\t\t/* Tail-recursion. */\n  LJ_TRLINK_UPREC,\t\t/* Up-recursion. */\n  LJ_TRLINK_DOWNREC,\t\t/* Down-recursion. */\n  LJ_TRLINK_INTERP,\t\t/* Fallback to interpreter. */\n  LJ_TRLINK_RETURN,\t\t/* Return to interpreter. */\n  LJ_TRLINK_STITCH\t\t/* Trace stitching. */\n} TraceLink;\n\n/* Trace object. */\ntypedef struct GCtrace {\n  GCHeader;\n  uint16_t nsnap;\t/* Number of snapshots. */\n  IRRef nins;\t\t/* Next IR instruction. Biased with REF_BIAS. */\n#if LJ_GC64\n  uint32_t unused_gc64;\n#endif\n  GCRef gclist;\n  IRIns *ir;\t\t/* IR instructions/constants. Biased with REF_BIAS. */\n  IRRef nk;\t\t/* Lowest IR constant. Biased with REF_BIAS. */\n  uint32_t nsnapmap;\t/* Number of snapshot map elements. */\n  SnapShot *snap;\t/* Snapshot array. */\n  SnapEntry *snapmap;\t/* Snapshot map. */\n  GCRef startpt;\t/* Starting prototype. */\n  MRef startpc;\t\t/* Bytecode PC of starting instruction. */\n  BCIns startins;\t/* Original bytecode of starting instruction. */\n  MSize szmcode;\t/* Size of machine code. */\n  MCode *mcode;\t\t/* Start of machine code. */\n  MSize mcloop;\t\t/* Offset of loop start in machine code. */\n  uint16_t nchild;\t/* Number of child traces (root trace only). */\n  uint16_t spadjust;\t/* Stack pointer adjustment (offset in bytes). */\n  TraceNo1 traceno;\t/* Trace number. */\n  TraceNo1 link;\t/* Linked trace (or self for loops). */\n  TraceNo1 root;\t/* Root trace of side trace (or 0 for root traces). */\n  TraceNo1 nextroot;\t/* Next root trace for same prototype. */\n  TraceNo1 nextside;\t/* Next side trace of same root trace. */\n  uint8_t sinktags;\t/* Trace has SINK tags. */\n  uint8_t topslot;\t/* Top stack slot already checked to be allocated. */\n  uint8_t linktype;\t/* Type of link. */\n  uint8_t unused1;\n#ifdef LUAJIT_USE_GDBJIT\n  void *gdbjit_entry;\t/* GDB JIT entry. */\n#endif\n} GCtrace;\n\n#define gco2trace(o)\tcheck_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o))\n#define traceref(J, n) \\\n  check_exp((n)>0 && (MSize)(n)<J->sizetrace, (GCtrace *)gcref(J->trace[(n)]))\n\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist));\n\nstatic LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)\n{\n  if (snap+1 == &T->snap[T->nsnap])\n    return T->nsnapmap;\n  else\n    return (snap+1)->mapofs;\n}\n\n/* Round-robin penalty cache for bytecodes leading to aborted traces. */\ntypedef struct HotPenalty {\n  MRef pc;\t\t/* Starting bytecode PC. */\n  uint16_t val;\t\t/* Penalty value, i.e. hotcount start. */\n  uint16_t reason;\t/* Abort reason (really TraceErr). */\n} HotPenalty;\n\n#define PENALTY_SLOTS\t64\t/* Penalty cache slot. Must be a power of 2. */\n#define PENALTY_MIN\t(36*2)\t/* Minimum penalty value. */\n#define PENALTY_MAX\t60000\t/* Maximum penalty value. */\n#define PENALTY_RNDBITS\t4\t/* # of random bits to add to penalty value. */\n\n/* Round-robin backpropagation cache for narrowing conversions. */\ntypedef struct BPropEntry {\n  IRRef1 key;\t\t/* Key: original reference. */\n  IRRef1 val;\t\t/* Value: reference after conversion. */\n  IRRef mode;\t\t/* Mode for this entry (currently IRCONV_*). */\n} BPropEntry;\n\n/* Number of slots for the backpropagation cache. Must be a power of 2. */\n#define BPROP_SLOTS\t16\n\n/* Scalar evolution analysis cache. */\ntypedef struct ScEvEntry {\n  MRef pc;\t\t/* Bytecode PC of FORI. */\n  IRRef1 idx;\t\t/* Index reference. */\n  IRRef1 start;\t\t/* Constant start reference. */\n  IRRef1 stop;\t\t/* Constant stop reference. */\n  IRRef1 step;\t\t/* Constant step reference. */\n  IRType1 t;\t\t/* Scalar type. */\n  uint8_t dir;\t\t/* Direction. 1: +, 0: -. */\n} ScEvEntry;\n\n/* Reverse bytecode map (IRRef -> PC). Only for selected instructions. */\ntypedef struct RBCHashEntry {\n  MRef pc;\t\t/* Bytecode PC. */\n  GCRef pt;\t\t/* Prototype. */\n  IRRef ref;\t\t/* IR reference. */\n} RBCHashEntry;\n\n/* Number of slots in the reverse bytecode hash table. Must be a power of 2. */\n#define RBCHASH_SLOTS\t8\n\n/* 128 bit SIMD constants. */\nenum {\n  LJ_KSIMD_ABS,\n  LJ_KSIMD_NEG,\n  LJ_KSIMD__MAX\n};\n\nenum {\n#if LJ_TARGET_X86ORX64\n  LJ_K64_TOBIT,\t\t/* 2^52 + 2^51 */\n  LJ_K64_2P64,\t\t/* 2^64 */\n  LJ_K64_M2P64,\t\t/* -2^64 */\n#if LJ_32\n  LJ_K64_M2P64_31,\t/* -2^64 or -2^31 */\n#else\n  LJ_K64_M2P64_31 = LJ_K64_M2P64,\n#endif\n#endif\n#if LJ_TARGET_MIPS\n  LJ_K64_2P31,\t\t/* 2^31 */\n#if LJ_64\n  LJ_K64_2P63,\t\t/* 2^63 */\n  LJ_K64_M2P64,\t\t/* -2^64 */\n#endif\n#endif\n  LJ_K64__MAX,\n};\n\nenum {\n#if LJ_TARGET_X86ORX64\n  LJ_K32_M2P64_31,\t/* -2^64 or -2^31 */\n#endif\n#if LJ_TARGET_PPC\n  LJ_K32_2P52_2P31,\t/* 2^52 + 2^31 */\n  LJ_K32_2P52,\t\t/* 2^52 */\n#endif\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS\n  LJ_K32_2P31,\t\t/* 2^31 */\n#endif\n#if LJ_TARGET_MIPS64\n  LJ_K32_2P63,\t\t/* 2^63 */\n  LJ_K32_M2P64,\t\t/* -2^64 */\n#endif\n  LJ_K32__MAX\n};\n\n/* Get 16 byte aligned pointer to SIMD constant. */\n#define LJ_KSIMD(J, n) \\\n  ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))\n\n/* Set/reset flag to activate the SPLIT pass for the current trace. */\n#if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)\n#define lj_needsplit(J)\t\t(J->needsplit = 1)\n#define lj_resetsplit(J)\t(J->needsplit = 0)\n#else\n#define lj_needsplit(J)\t\tUNUSED(J)\n#define lj_resetsplit(J)\tUNUSED(J)\n#endif\n\n/* Fold state is used to fold instructions on-the-fly. */\ntypedef struct FoldState {\n  IRIns ins;\t\t/* Currently emitted instruction. */\n  IRIns left[2];\t/* Instruction referenced by left operand. */\n  IRIns right[2];\t/* Instruction referenced by right operand. */\n} FoldState;\n\n/* JIT compiler state. */\ntypedef struct jit_State {\n  GCtrace cur;\t\t/* Current trace. */\n  GCtrace *curfinal;\t/* Final address of current trace (set during asm). */\n\n  lua_State *L;\t\t/* Current Lua state. */\n  const BCIns *pc;\t/* Current PC. */\n  GCfunc *fn;\t\t/* Current function. */\n  GCproto *pt;\t\t/* Current prototype. */\n  TRef *base;\t\t/* Current frame base, points into J->slots. */\n\n  uint32_t flags;\t/* JIT engine flags. */\n  BCReg maxslot;\t/* Relative to baseslot. */\n  BCReg baseslot;\t/* Current frame base, offset into J->slots. */\n\n  uint8_t mergesnap;\t/* Allowed to merge with next snapshot. */\n  uint8_t needsnap;\t/* Need snapshot before recording next bytecode. */\n  IRType1 guardemit;\t/* Accumulated IRT_GUARD for emitted instructions. */\n  uint8_t bcskip;\t/* Number of bytecode instructions to skip. */\n\n  FoldState fold;\t/* Fold state. */\n\n  const BCIns *bc_min;\t/* Start of allowed bytecode range for root trace. */\n  MSize bc_extent;\t/* Extent of the range. */\n\n  TraceState state;\t/* Trace compiler state. */\n\n  int32_t instunroll;\t/* Unroll counter for instable loops. */\n  int32_t loopunroll;\t/* Unroll counter for loop ops in side traces. */\n  int32_t tailcalled;\t/* Number of successive tailcalls. */\n  int32_t framedepth;\t/* Current frame depth. */\n  int32_t retdepth;\t/* Return frame depth (count of RETF). */\n\n  uint32_t k32[LJ_K32__MAX];  /* Common 4 byte constants used by backends. */\n  TValue ksimd[LJ_KSIMD__MAX*2+1];  /* 16 byte aligned SIMD constants. */\n  TValue k64[LJ_K64__MAX];  /* Common 8 byte constants. */\n\n  IRIns *irbuf;\t\t/* Temp. IR instruction buffer. Biased with REF_BIAS. */\n  IRRef irtoplim;\t/* Upper limit of instuction buffer (biased). */\n  IRRef irbotlim;\t/* Lower limit of instuction buffer (biased). */\n  IRRef loopref;\t/* Last loop reference or ref of final LOOP (or 0). */\n\n  MSize sizesnap;\t/* Size of temp. snapshot buffer. */\n  SnapShot *snapbuf;\t/* Temp. snapshot buffer. */\n  SnapEntry *snapmapbuf;  /* Temp. snapshot map buffer. */\n  MSize sizesnapmap;\t/* Size of temp. snapshot map buffer. */\n\n  PostProc postproc;\t/* Required post-processing after execution. */\n#if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)\n  uint8_t needsplit;\t/* Need SPLIT pass. */\n#endif\n  uint8_t retryrec;\t/* Retry recording. */\n\n  GCRef *trace;\t\t/* Array of traces. */\n  TraceNo freetrace;\t/* Start of scan for next free trace. */\n  MSize sizetrace;\t/* Size of trace array. */\n  IRRef1 ktrace;\t/* Reference to KGC with GCtrace. */\n\n  IRRef1 chain[IR__MAX];  /* IR instruction skip-list chain anchors. */\n  TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA];  /* Stack slot map. */\n\n  int32_t param[JIT_P__MAX];  /* JIT engine parameters. */\n\n  MCode *exitstubgroup[LJ_MAX_EXITSTUBGR];  /* Exit stub group addresses. */\n\n  HotPenalty penalty[PENALTY_SLOTS];  /* Penalty slots. */\n  uint32_t penaltyslot;\t/* Round-robin index into penalty slots. */\n\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  RBCHashEntry rbchash[RBCHASH_SLOTS];  /* Reverse bytecode map. */\n#endif\n\n  BPropEntry bpropcache[BPROP_SLOTS];  /* Backpropagation cache slots. */\n  uint32_t bpropslot;\t/* Round-robin index into bpropcache slots. */\n\n  ScEvEntry scev;\t/* Scalar evolution analysis cache slots. */\n\n  const BCIns *startpc;\t/* Bytecode PC of starting instruction. */\n  TraceNo parent;\t/* Parent of current side trace (0 for root traces). */\n  ExitNo exitno;\t/* Exit number in parent of current side trace. */\n  int exitcode;\t\t/* Exit code from unwound trace. */\n\n  BCIns *patchpc;\t/* PC for pending re-patch. */\n  BCIns patchins;\t/* Instruction for pending re-patch. */\n\n  int mcprot;\t\t/* Protection of current mcode area. */\n  MCode *mcarea;\t/* Base of current mcode area. */\n  MCode *mctop;\t\t/* Top of current mcode area. */\n  MCode *mcbot;\t\t/* Bottom of current mcode area. */\n  size_t szmcarea;\t/* Size of current mcode area. */\n  size_t szallmcarea;\t/* Total size of all allocated mcode areas. */\n\n  TValue errinfo;\t/* Additional info element for trace errors. */\n\n#if LJ_HASPROFILE\n  GCproto *prev_pt;\t/* Previous prototype. */\n  BCLine prev_line;\t/* Previous line. */\n  int prof_mode;\t/* Profiling mode: 0, 'f', 'l'. */\n#endif\n} jit_State;\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertJ(c, ...)\tlj_assertG_(J2G(J), (c), __VA_ARGS__)\n#else\n#define lj_assertJ(c, ...)\t((void)J)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_lex.c",
    "content": "/*\n** Lexical analyzer.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_lex_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#if LJ_HASFFI\n#include \"lj_tab.h\"\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#include \"lualib.h\"\n#endif\n#include \"lj_state.h\"\n#include \"lj_lex.h\"\n#include \"lj_parse.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* Lua lexer token names. */\nstatic const char *const tokennames[] = {\n#define TKSTR1(name)\t\t#name,\n#define TKSTR2(name, sym)\t#sym,\nTKDEF(TKSTR1, TKSTR2)\n#undef TKSTR1\n#undef TKSTR2\n  NULL\n};\n\n/* -- Buffer handling ----------------------------------------------------- */\n\n#define LEX_EOF\t\t\t(-1)\n#define lex_iseol(ls)\t\t(ls->c == '\\n' || ls->c == '\\r')\n\n/* Get more input from reader. */\nstatic LJ_NOINLINE LexChar lex_more(LexState *ls)\n{\n  size_t sz;\n  const char *p = ls->rfunc(ls->L, ls->rdata, &sz);\n  if (p == NULL || sz == 0) return LEX_EOF;\n  if (sz >= LJ_MAX_BUF) {\n    if (sz != ~(size_t)0) lj_err_mem(ls->L);\n    sz = ~(uintptr_t)0 - (uintptr_t)p;\n    if (sz >= LJ_MAX_BUF) sz = LJ_MAX_BUF-1;\n    ls->endmark = 1;\n  }\n  ls->pe = p + sz;\n  ls->p = p + 1;\n  return (LexChar)(uint8_t)p[0];\n}\n\n/* Get next character. */\nstatic LJ_AINLINE LexChar lex_next(LexState *ls)\n{\n  return (ls->c = ls->p < ls->pe ? (LexChar)(uint8_t)*ls->p++ : lex_more(ls));\n}\n\n/* Save character. */\nstatic LJ_AINLINE void lex_save(LexState *ls, LexChar c)\n{\n  lj_buf_putb(&ls->sb, c);\n}\n\n/* Save previous character and get next character. */\nstatic LJ_AINLINE LexChar lex_savenext(LexState *ls)\n{\n  lex_save(ls, ls->c);\n  return lex_next(ls);\n}\n\n/* Skip line break. Handles \"\\n\", \"\\r\", \"\\r\\n\" or \"\\n\\r\". */\nstatic void lex_newline(LexState *ls)\n{\n  LexChar old = ls->c;\n  lj_assertLS(lex_iseol(ls), \"bad usage\");\n  lex_next(ls);  /* Skip \"\\n\" or \"\\r\". */\n  if (lex_iseol(ls) && ls->c != old) lex_next(ls);  /* Skip \"\\n\\r\" or \"\\r\\n\". */\n  if (++ls->linenumber >= LJ_MAX_LINE)\n    lj_lex_error(ls, ls->tok, LJ_ERR_XLINES);\n}\n\n/* -- Scanner for terminals ----------------------------------------------- */\n\n/* Parse a number literal. */\nstatic void lex_number(LexState *ls, TValue *tv)\n{\n  StrScanFmt fmt;\n  LexChar c, xp = 'e';\n  lj_assertLS(lj_char_isdigit(ls->c), \"bad usage\");\n  if ((c = ls->c) == '0' && (lex_savenext(ls) | 0x20) == 'x')\n    xp = 'p';\n  while (lj_char_isident(ls->c) || ls->c == '.' ||\n\t ((ls->c == '-' || ls->c == '+') && (c | 0x20) == xp)) {\n    c = ls->c;\n    lex_savenext(ls);\n  }\n  lex_save(ls, '\\0');\n  fmt = lj_strscan_scan((const uint8_t *)ls->sb.b, sbuflen(&ls->sb)-1, tv,\n\t  (LJ_DUALNUM ? STRSCAN_OPT_TOINT : STRSCAN_OPT_TONUM) |\n\t  (LJ_HASFFI ? (STRSCAN_OPT_LL|STRSCAN_OPT_IMAG) : 0));\n  if (LJ_DUALNUM && fmt == STRSCAN_INT) {\n    setitype(tv, LJ_TISNUM);\n  } else if (fmt == STRSCAN_NUM) {\n    /* Already in correct format. */\n#if LJ_HASFFI\n  } else if (fmt != STRSCAN_ERROR) {\n    lua_State *L = ls->L;\n    GCcdata *cd;\n    lj_assertLS(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG,\n\t\t\"unexpected number format %d\", fmt);\n    ctype_loadffi(L);\n    if (fmt == STRSCAN_IMAG) {\n      cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double));\n      ((double *)cdataptr(cd))[0] = 0;\n      ((double *)cdataptr(cd))[1] = numV(tv);\n    } else {\n      cd = lj_cdata_new_(L, fmt==STRSCAN_I64 ? CTID_INT64 : CTID_UINT64, 8);\n      *(uint64_t *)cdataptr(cd) = tv->u64;\n    }\n    lj_parse_keepcdata(ls, tv, cd);\n#endif\n  } else {\n    lj_assertLS(fmt == STRSCAN_ERROR,\n\t\t\"unexpected number format %d\", fmt);\n    lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER);\n  }\n}\n\n/* Skip equal signs for \"[=...=[\" and \"]=...=]\" and return their count. */\nstatic int lex_skipeq(LexState *ls)\n{\n  int count = 0;\n  LexChar s = ls->c;\n  lj_assertLS(s == '[' || s == ']', \"bad usage\");\n  while (lex_savenext(ls) == '=' && count < 0x20000000)\n    count++;\n  return (ls->c == s) ? count : (-count) - 1;\n}\n\n/* Parse a long string or long comment (tv set to NULL). */\nstatic void lex_longstring(LexState *ls, TValue *tv, int sep)\n{\n  lex_savenext(ls);  /* Skip second '['. */\n  if (lex_iseol(ls))  /* Skip initial newline. */\n    lex_newline(ls);\n  for (;;) {\n    switch (ls->c) {\n    case LEX_EOF:\n      lj_lex_error(ls, TK_eof, tv ? LJ_ERR_XLSTR : LJ_ERR_XLCOM);\n      break;\n    case ']':\n      if (lex_skipeq(ls) == sep) {\n\tlex_savenext(ls);  /* Skip second ']'. */\n\tgoto endloop;\n      }\n      break;\n    case '\\n':\n    case '\\r':\n      lex_save(ls, '\\n');\n      lex_newline(ls);\n      if (!tv) lj_buf_reset(&ls->sb);  /* Don't waste space for comments. */\n      break;\n    default:\n      lex_savenext(ls);\n      break;\n    }\n  } endloop:\n  if (tv) {\n    GCstr *str = lj_parse_keepstr(ls, ls->sb.b + (2 + (MSize)sep),\n\t\t\t\t      sbuflen(&ls->sb) - 2*(2 + (MSize)sep));\n    setstrV(ls->L, tv, str);\n  }\n}\n\n/* Parse a string. */\nstatic void lex_string(LexState *ls, TValue *tv)\n{\n  LexChar delim = ls->c;  /* Delimiter is '\\'' or '\"'. */\n  lex_savenext(ls);\n  while (ls->c != delim) {\n    switch (ls->c) {\n    case LEX_EOF:\n      lj_lex_error(ls, TK_eof, LJ_ERR_XSTR);\n      continue;\n    case '\\n':\n    case '\\r':\n      lj_lex_error(ls, TK_string, LJ_ERR_XSTR);\n      continue;\n    case '\\\\': {\n      LexChar c = lex_next(ls);  /* Skip the '\\\\'. */\n      switch (c) {\n      case 'a': c = '\\a'; break;\n      case 'b': c = '\\b'; break;\n      case 'f': c = '\\f'; break;\n      case 'n': c = '\\n'; break;\n      case 'r': c = '\\r'; break;\n      case 't': c = '\\t'; break;\n      case 'v': c = '\\v'; break;\n      case 'x':  /* Hexadecimal escape '\\xXX'. */\n\tc = (lex_next(ls) & 15u) << 4;\n\tif (!lj_char_isdigit(ls->c)) {\n\t  if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t  c += 9 << 4;\n\t}\n\tc += (lex_next(ls) & 15u);\n\tif (!lj_char_isdigit(ls->c)) {\n\t  if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t  c += 9;\n\t}\n\tbreak;\n      case 'u':  /* Unicode escape '\\u{XX...}'. */\n\tif (lex_next(ls) != '{') goto err_xesc;\n\tlex_next(ls);\n\tc = 0;\n\tdo {\n\t  c = (c << 4) | (ls->c & 15u);\n\t  if (!lj_char_isdigit(ls->c)) {\n\t    if (!lj_char_isxdigit(ls->c)) goto err_xesc;\n\t    c += 9;\n\t  }\n\t  if (c >= 0x110000) goto err_xesc;  /* Out of Unicode range. */\n\t} while (lex_next(ls) != '}');\n\tif (c < 0x800) {\n\t  if (c < 0x80) break;\n\t  lex_save(ls, 0xc0 | (c >> 6));\n\t} else {\n\t  if (c >= 0x10000) {\n\t    lex_save(ls, 0xf0 | (c >> 18));\n\t    lex_save(ls, 0x80 | ((c >> 12) & 0x3f));\n\t  } else {\n\t    if (c >= 0xd800 && c < 0xe000) goto err_xesc;  /* No surrogates. */\n\t    lex_save(ls, 0xe0 | (c >> 12));\n\t  }\n\t  lex_save(ls, 0x80 | ((c >> 6) & 0x3f));\n\t}\n\tc = 0x80 | (c & 0x3f);\n\tbreak;\n      case 'z':  /* Skip whitespace. */\n\tlex_next(ls);\n\twhile (lj_char_isspace(ls->c))\n\t  if (lex_iseol(ls)) lex_newline(ls); else lex_next(ls);\n\tcontinue;\n      case '\\n': case '\\r': lex_save(ls, '\\n'); lex_newline(ls); continue;\n      case '\\\\': case '\\\"': case '\\'': break;\n      case LEX_EOF: continue;\n      default:\n\tif (!lj_char_isdigit(c))\n\t  goto err_xesc;\n\tc -= '0';  /* Decimal escape '\\ddd'. */\n\tif (lj_char_isdigit(lex_next(ls))) {\n\t  c = c*10 + (ls->c - '0');\n\t  if (lj_char_isdigit(lex_next(ls))) {\n\t    c = c*10 + (ls->c - '0');\n\t    if (c > 255) {\n\t    err_xesc:\n\t      lj_lex_error(ls, TK_string, LJ_ERR_XESC);\n\t    }\n\t    lex_next(ls);\n\t  }\n\t}\n\tlex_save(ls, c);\n\tcontinue;\n      }\n      lex_save(ls, c);\n      lex_next(ls);\n      continue;\n      }\n    default:\n      lex_savenext(ls);\n      break;\n    }\n  }\n  lex_savenext(ls);  /* Skip trailing delimiter. */\n  setstrV(ls->L, tv,\n\t  lj_parse_keepstr(ls, ls->sb.b+1, sbuflen(&ls->sb)-2));\n}\n\n/* -- Main lexical scanner ------------------------------------------------ */\n\n/* Get next lexical token. */\nstatic LexToken lex_scan(LexState *ls, TValue *tv)\n{\n  lj_buf_reset(&ls->sb);\n  for (;;) {\n    if (lj_char_isident(ls->c)) {\n      GCstr *s;\n      if (lj_char_isdigit(ls->c)) {  /* Numeric literal. */\n\tlex_number(ls, tv);\n\treturn TK_number;\n      }\n      /* Identifier or reserved word. */\n      do {\n\tlex_savenext(ls);\n      } while (lj_char_isident(ls->c));\n      s = lj_parse_keepstr(ls, ls->sb.b, sbuflen(&ls->sb));\n      setstrV(ls->L, tv, s);\n      if (s->reserved > 0)  /* Reserved word? */\n\treturn TK_OFS + s->reserved;\n      return TK_name;\n    }\n    switch (ls->c) {\n    case '\\n':\n    case '\\r':\n      lex_newline(ls);\n      continue;\n    case ' ':\n    case '\\t':\n    case '\\v':\n    case '\\f':\n      lex_next(ls);\n      continue;\n    case '-':\n      lex_next(ls);\n      if (ls->c != '-') return '-';\n      lex_next(ls);\n      if (ls->c == '[') {  /* Long comment \"--[=*[...]=*]\". */\n\tint sep = lex_skipeq(ls);\n\tlj_buf_reset(&ls->sb);  /* `lex_skipeq' may dirty the buffer */\n\tif (sep >= 0) {\n\t  lex_longstring(ls, NULL, sep);\n\t  lj_buf_reset(&ls->sb);\n\t  continue;\n\t}\n      }\n      /* Short comment \"--.*\\n\". */\n      while (!lex_iseol(ls) && ls->c != LEX_EOF)\n\tlex_next(ls);\n      continue;\n    case '[': {\n      int sep = lex_skipeq(ls);\n      if (sep >= 0) {\n\tlex_longstring(ls, tv, sep);\n\treturn TK_string;\n      } else if (sep == -1) {\n\treturn '[';\n      } else {\n\tlj_lex_error(ls, TK_string, LJ_ERR_XLDELIM);\n\tcontinue;\n      }\n      }\n    case '=':\n      lex_next(ls);\n      if (ls->c != '=') return '='; else { lex_next(ls); return TK_eq; }\n    case '<':\n      lex_next(ls);\n      if (ls->c != '=') return '<'; else { lex_next(ls); return TK_le; }\n    case '>':\n      lex_next(ls);\n      if (ls->c != '=') return '>'; else { lex_next(ls); return TK_ge; }\n    case '~':\n      lex_next(ls);\n      if (ls->c != '=') return '~'; else { lex_next(ls); return TK_ne; }\n    case ':':\n      lex_next(ls);\n      if (ls->c != ':') return ':'; else { lex_next(ls); return TK_label; }\n    case '\"':\n    case '\\'':\n      lex_string(ls, tv);\n      return TK_string;\n    case '.':\n      if (lex_savenext(ls) == '.') {\n\tlex_next(ls);\n\tif (ls->c == '.') {\n\t  lex_next(ls);\n\t  return TK_dots;   /* ... */\n\t}\n\treturn TK_concat;   /* .. */\n      } else if (!lj_char_isdigit(ls->c)) {\n\treturn '.';\n      } else {\n\tlex_number(ls, tv);\n\treturn TK_number;\n      }\n    case LEX_EOF:\n      return TK_eof;\n    default: {\n      LexChar c = ls->c;\n      lex_next(ls);\n      return c;  /* Single-char tokens (+ - / ...). */\n    }\n    }\n  }\n}\n\n/* -- Lexer API ----------------------------------------------------------- */\n\n/* Setup lexer state. */\nint lj_lex_setup(lua_State *L, LexState *ls)\n{\n  int header = 0;\n  ls->L = L;\n  ls->fs = NULL;\n  ls->pe = ls->p = NULL;\n  ls->vstack = NULL;\n  ls->sizevstack = 0;\n  ls->vtop = 0;\n  ls->bcstack = NULL;\n  ls->sizebcstack = 0;\n  ls->tok = 0;\n  ls->lookahead = TK_eof;  /* No look-ahead token. */\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->endmark = 0;\n  lex_next(ls);  /* Read-ahead first char. */\n  if (ls->c == 0xef && ls->p + 2 <= ls->pe && (uint8_t)ls->p[0] == 0xbb &&\n      (uint8_t)ls->p[1] == 0xbf) {  /* Skip UTF-8 BOM (if buffered). */\n    ls->p += 2;\n    lex_next(ls);\n    header = 1;\n  }\n  if (ls->c == '#') {  /* Skip POSIX #! header line. */\n    do {\n      lex_next(ls);\n      if (ls->c == LEX_EOF) return 0;\n    } while (!lex_iseol(ls));\n    lex_newline(ls);\n    header = 1;\n  }\n  if (ls->c == LUA_SIGNATURE[0]) {  /* Bytecode dump. */\n    if (header) {\n      /*\n      ** Loading bytecode with an extra header is disabled for security\n      ** reasons. This may circumvent the usual check for bytecode vs.\n      ** Lua code by looking at the first char. Since this is a potential\n      ** security violation no attempt is made to echo the chunkname either.\n      */\n      setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD));\n      lj_err_throw(L, LUA_ERRSYNTAX);\n    }\n    return 1;\n  }\n  return 0;\n}\n\n/* Cleanup lexer state. */\nvoid lj_lex_cleanup(lua_State *L, LexState *ls)\n{\n  global_State *g = G(L);\n  lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine);\n  lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo);\n  lj_buf_free(g, &ls->sb);\n}\n\n/* Return next lexical token. */\nvoid lj_lex_next(LexState *ls)\n{\n  ls->lastline = ls->linenumber;\n  if (LJ_LIKELY(ls->lookahead == TK_eof)) {  /* No lookahead token? */\n    ls->tok = lex_scan(ls, &ls->tokval);  /* Get next token. */\n  } else {  /* Otherwise return lookahead token. */\n    ls->tok = ls->lookahead;\n    ls->lookahead = TK_eof;\n    ls->tokval = ls->lookaheadval;\n  }\n}\n\n/* Look ahead for the next token. */\nLexToken lj_lex_lookahead(LexState *ls)\n{\n  lj_assertLS(ls->lookahead == TK_eof, \"double lookahead\");\n  ls->lookahead = lex_scan(ls, &ls->lookaheadval);\n  return ls->lookahead;\n}\n\n/* Convert token to string. */\nconst char *lj_lex_token2str(LexState *ls, LexToken tok)\n{\n  if (tok > TK_OFS)\n    return tokennames[tok-TK_OFS-1];\n  else if (!lj_char_iscntrl(tok))\n    return lj_strfmt_pushf(ls->L, \"%c\", tok);\n  else\n    return lj_strfmt_pushf(ls->L, \"char(%d)\", tok);\n}\n\n/* Lexer error. */\nvoid lj_lex_error(LexState *ls, LexToken tok, ErrMsg em, ...)\n{\n  const char *tokstr;\n  va_list argp;\n  if (tok == 0) {\n    tokstr = NULL;\n  } else if (tok == TK_name || tok == TK_string || tok == TK_number) {\n    lex_save(ls, '\\0');\n    tokstr = ls->sb.b;\n  } else {\n    tokstr = lj_lex_token2str(ls, tok);\n  }\n  va_start(argp, em);\n  lj_err_lex(ls->L, ls->chunkname, tokstr, ls->linenumber, em, argp);\n  va_end(argp);\n}\n\n/* Initialize strings for reserved words. */\nvoid lj_lex_init(lua_State *L)\n{\n  uint32_t i;\n  for (i = 0; i < TK_RESERVED; i++) {\n    GCstr *s = lj_str_newz(L, tokennames[i]);\n    fixstring(s);  /* Reserved words are never collected. */\n    s->reserved = (uint8_t)(i+1);\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_lex.h",
    "content": "/*\n** Lexical analyzer.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_LEX_H\n#define _LJ_LEX_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n\n/* Lua lexer tokens. */\n#define TKDEF(_, __) \\\n  _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \\\n  _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \\\n  _(repeat) _(return) _(then) _(true) _(until) _(while) \\\n  __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \\\n  __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \\\n  __(eof, <eof>)\n\nenum {\n  TK_OFS = 256,\n#define TKENUM1(name)\t\tTK_##name,\n#define TKENUM2(name, sym)\tTK_##name,\nTKDEF(TKENUM1, TKENUM2)\n#undef TKENUM1\n#undef TKENUM2\n  TK_RESERVED = TK_while - TK_OFS\n};\n\ntypedef int LexChar;\t/* Lexical character. Unsigned ext. from char. */\ntypedef int LexToken;\t/* Lexical token. */\n\n/* Combined bytecode ins/line. Only used during bytecode generation. */\ntypedef struct BCInsLine {\n  BCIns ins;\t\t/* Bytecode instruction. */\n  BCLine line;\t\t/* Line number for this bytecode. */\n} BCInsLine;\n\n/* Info for local variables. Only used during bytecode generation. */\ntypedef struct VarInfo {\n  GCRef name;\t\t/* Local variable name or goto/label name. */\n  BCPos startpc;\t/* First point where the local variable is active. */\n  BCPos endpc;\t\t/* First point where the local variable is dead. */\n  uint8_t slot;\t\t/* Variable slot. */\n  uint8_t info;\t\t/* Variable/goto/label info. */\n} VarInfo;\n\n/* Lua lexer state. */\ntypedef struct LexState {\n  struct FuncState *fs;\t/* Current FuncState. Defined in lj_parse.c. */\n  struct lua_State *L;\t/* Lua state. */\n  TValue tokval;\t/* Current token value. */\n  TValue lookaheadval;\t/* Lookahead token value. */\n  const char *p;\t/* Current position in input buffer. */\n  const char *pe;\t/* End of input buffer. */\n  LexChar c;\t\t/* Current character. */\n  LexToken tok;\t\t/* Current token. */\n  LexToken lookahead;\t/* Lookahead token. */\n  SBuf sb;\t\t/* String buffer for tokens. */\n  lua_Reader rfunc;\t/* Reader callback. */\n  void *rdata;\t\t/* Reader callback data. */\n  BCLine linenumber;\t/* Input line counter. */\n  BCLine lastline;\t/* Line of last token. */\n  GCstr *chunkname;\t/* Current chunk name (interned string). */\n  const char *chunkarg;\t/* Chunk name argument. */\n  const char *mode;\t/* Allow loading bytecode (b) and/or source text (t). */\n  VarInfo *vstack;\t/* Stack for names and extents of local variables. */\n  MSize sizevstack;\t/* Size of variable stack. */\n  MSize vtop;\t\t/* Top of variable stack. */\n  BCInsLine *bcstack;\t/* Stack for bytecode instructions/line numbers. */\n  MSize sizebcstack;\t/* Size of bytecode stack. */\n  uint32_t level;\t/* Syntactical nesting level. */\n  int endmark;\t\t/* Trust bytecode end marker, even if not at EOF. */\n} LexState;\n\nLJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);\nLJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);\nLJ_FUNC void lj_lex_next(LexState *ls);\nLJ_FUNC LexToken lj_lex_lookahead(LexState *ls);\nLJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken tok);\nLJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken tok, ErrMsg em, ...);\nLJ_FUNC void lj_lex_init(lua_State *L);\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertLS(c, ...)\t(lj_assertG_(G(ls->L), (c), __VA_ARGS__))\n#else\n#define lj_assertLS(c, ...)\t((void)ls)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_lib.c",
    "content": "/*\n** Library function support.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_lib_c\n#define LUA_CORE\n\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_bc.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_lib.h\"\n\n/* -- Library initialization ---------------------------------------------- */\n\nstatic GCtab *lib_create_table(lua_State *L, const char *libname, int hsize)\n{\n  if (libname) {\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 16);\n    lua_getfield(L, -1, libname);\n    if (!tvistab(L->top-1)) {\n      L->top--;\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, hsize) != NULL)\n\tlj_err_callerv(L, LJ_ERR_BADMODN, libname);\n      settabV(L, L->top, tabV(L->top-1));\n      L->top++;\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    L->top--;\n    settabV(L, L->top-1, tabV(L->top));\n  } else {\n    lua_createtable(L, 0, hsize);\n  }\n  return tabV(L->top-1);\n}\n\nstatic const uint8_t *lib_read_lfunc(lua_State *L, const uint8_t *p, GCtab *tab)\n{\n  int len = *p++;\n  GCstr *name = lj_str_new(L, (const char *)p, len);\n  LexState ls;\n  GCproto *pt;\n  GCfunc *fn;\n  memset(&ls, 0, sizeof(ls));\n  ls.L = L;\n  ls.p = (const char *)(p+len);\n  ls.pe = (const char *)~(uintptr_t)0;\n  ls.c = -1;\n  ls.level = (BCDUMP_F_STRIP|(LJ_BE*BCDUMP_F_BE));\n  ls.chunkname = name;\n  pt = lj_bcread_proto(&ls);\n  pt->firstline = ~(BCLine)0;\n  fn = lj_func_newL_empty(L, pt, tabref(L->env));\n  /* NOBARRIER: See below for common barrier. */\n  setfuncV(L, lj_tab_setstr(L, tab, name), fn);\n  return (const uint8_t *)ls.p;\n}\n\nvoid lj_lib_register(lua_State *L, const char *libname,\n\t\t     const uint8_t *p, const lua_CFunction *cf)\n{\n  GCtab *env = tabref(L->env);\n  GCfunc *ofn = NULL;\n  int ffid = *p++;\n  BCIns *bcff = &L2GG(L)->bcff[*p++];\n  GCtab *tab = lib_create_table(L, libname, *p++);\n  ptrdiff_t tpos = L->top - L->base;\n\n  /* Avoid barriers further down. */\n  lj_gc_anybarriert(L, tab);\n  tab->nomm = 0;\n\n  for (;;) {\n    uint32_t tag = *p++;\n    MSize len = tag & LIBINIT_LENMASK;\n    tag &= LIBINIT_TAGMASK;\n    if (tag != LIBINIT_STRING) {\n      const char *name;\n      MSize nuv = (MSize)(L->top - L->base - tpos);\n      GCfunc *fn = lj_func_newC(L, nuv, env);\n      if (nuv) {\n\tL->top = L->base + tpos;\n\tmemcpy(fn->c.upvalue, L->top, sizeof(TValue)*nuv);\n      }\n      fn->c.ffid = (uint8_t)(ffid++);\n      name = (const char *)p;\n      p += len;\n      if (tag == LIBINIT_CF)\n\tsetmref(fn->c.pc, &G(L)->bc_cfunc_int);\n      else\n\tsetmref(fn->c.pc, bcff++);\n      if (tag == LIBINIT_ASM_)\n\tfn->c.f = ofn->c.f;  /* Copy handler from previous function. */\n      else\n\tfn->c.f = *cf++;  /* Get cf or handler from C function table. */\n      if (len) {\n\t/* NOBARRIER: See above for common barrier. */\n\tsetfuncV(L, lj_tab_setstr(L, tab, lj_str_new(L, name, len)), fn);\n      }\n      ofn = fn;\n    } else {\n      switch (tag | len) {\n      case LIBINIT_LUA:\n\tp = lib_read_lfunc(L, p, tab);\n\tbreak;\n      case LIBINIT_SET:\n\tL->top -= 2;\n\tif (tvisstr(L->top+1) && strV(L->top+1)->len == 0)\n\t  env = tabV(L->top);\n\telse  /* NOBARRIER: See above for common barrier. */\n\t  copyTV(L, lj_tab_set(L, tab, L->top+1), L->top);\n\tbreak;\n      case LIBINIT_NUMBER:\n\tmemcpy(&L->top->n, p, sizeof(double));\n\tL->top++;\n\tp += sizeof(double);\n\tbreak;\n      case LIBINIT_COPY:\n\tcopyTV(L, L->top, L->top - *p++);\n\tL->top++;\n\tbreak;\n      case LIBINIT_LASTCL:\n\tsetfuncV(L, L->top++, ofn);\n\tbreak;\n      case LIBINIT_FFID:\n\tffid++;\n\tbreak;\n      case LIBINIT_END:\n\treturn;\n      default:\n\tsetstrV(L, L->top++, lj_str_new(L, (const char *)p, len));\n\tp += len;\n\tbreak;\n      }\n    }\n  }\n}\n\n/* Push internal function on the stack. */\nGCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n)\n{\n  GCfunc *fn;\n  lua_pushcclosure(L, f, n);\n  fn = funcV(L->top-1);\n  fn->c.ffid = (uint8_t)id;\n  setmref(fn->c.pc, &G(L)->bc_cfunc_int);\n  return fn;\n}\n\nvoid lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env)\n{\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\", 4);\n  lua_pushcfunction(L, f);\n  /* NOBARRIER: The function is new (marked white). */\n  setgcref(funcV(L->top-1)->c.env, obj2gco(env));\n  lua_setfield(L, -2, name);\n  L->top--;\n}\n\nint lj_lib_postreg(lua_State *L, lua_CFunction cf, int id, const char *name)\n{\n  GCfunc *fn = lj_lib_pushcf(L, cf, id);\n  GCtab *t = tabref(curr_func(L)->c.env);  /* Reference to parent table. */\n  setfuncV(L, lj_tab_setstr(L, t, lj_str_newz(L, name)), fn);\n  lj_gc_anybarriert(L, t);\n  setfuncV(L, L->top++, fn);\n  return 1;\n}\n\n/* -- Type checks --------------------------------------------------------- */\n\nTValue *lj_lib_checkany(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o >= L->top)\n    lj_err_arg(L, narg, LJ_ERR_NOVAL);\n  return o;\n}\n\nGCstr *lj_lib_checkstr(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o < L->top) {\n    if (LJ_LIKELY(tvisstr(o))) {\n      return strV(o);\n    } else if (tvisnumber(o)) {\n      GCstr *s = lj_strfmt_number(L, o);\n      setstrV(L, o, s);\n      return s;\n    }\n  }\n  lj_err_argt(L, narg, LUA_TSTRING);\n  return NULL;  /* unreachable */\n}\n\nGCstr *lj_lib_optstr(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL;\n}\n\n#if LJ_DUALNUM\nvoid lj_lib_checknumber(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n}\n#endif\n\nlua_Number lj_lib_checknum(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top &&\n\t(tvisnumber(o) || (tvisstr(o) && lj_strscan_num(strV(o), o)))))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_UNLIKELY(tvisint(o))) {\n    lua_Number n = (lua_Number)intV(o);\n    setnumV(o, n);\n    return n;\n  } else {\n    return numV(o);\n  }\n}\n\nint32_t lj_lib_checkint(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && lj_strscan_numberobj(o)))\n    lj_err_argt(L, narg, LUA_TNUMBER);\n  if (LJ_LIKELY(tvisint(o))) {\n    return intV(o);\n  } else {\n    int32_t i = lj_num2int(numV(o));\n    if (LJ_DUALNUM) setintV(o, i);\n    return i;\n  }\n}\n\nint32_t lj_lib_optint(lua_State *L, int narg, int32_t def)\n{\n  TValue *o = L->base + narg-1;\n  return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def;\n}\n\nGCfunc *lj_lib_checkfunc(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tvisfunc(o)))\n    lj_err_argt(L, narg, LUA_TFUNCTION);\n  return funcV(o);\n}\n\nGCtab *lj_lib_checktab(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tvistab(o)))\n    lj_err_argt(L, narg, LUA_TTABLE);\n  return tabV(o);\n}\n\nGCtab *lj_lib_checktabornil(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (o < L->top) {\n    if (tvistab(o))\n      return tabV(o);\n    else if (tvisnil(o))\n      return NULL;\n  }\n  lj_err_arg(L, narg, LJ_ERR_NOTABN);\n  return NULL;  /* unreachable */\n}\n\nint lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst)\n{\n  GCstr *s = def >= 0 ? lj_lib_optstr(L, narg) : lj_lib_checkstr(L, narg);\n  if (s) {\n    const char *opt = strdata(s);\n    MSize len = s->len;\n    int i;\n    for (i = 0; *(const uint8_t *)lst; i++) {\n      if (*(const uint8_t *)lst == len && memcmp(opt, lst+1, len) == 0)\n\treturn i;\n      lst += 1+*(const uint8_t *)lst;\n    }\n    lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt);\n  }\n  return def;\n}\n\n/* -- Strict type checks -------------------------------------------------- */\n\n/* The following type checks do not coerce between strings and numbers.\n** And they handle plain int64_t/uint64_t FFI numbers, too.\n*/\n\n#if LJ_HASBUFFER\nGCstr *lj_lib_checkstrx(lua_State *L, int narg)\n{\n  TValue *o = L->base + narg-1;\n  if (!(o < L->top && tvisstr(o))) lj_err_argt(L, narg, LUA_TSTRING);\n  return strV(o);\n}\n\nint32_t lj_lib_checkintrange(lua_State *L, int narg, int32_t a, int32_t b)\n{\n  TValue *o = L->base + narg-1;\n  lj_assertL(b >= 0, \"expected range must be non-negative\");\n  if (o < L->top) {\n    if (LJ_LIKELY(tvisint(o))) {\n      int32_t i = intV(o);\n      if (i >= a && i <= b) return i;\n    } else if (LJ_LIKELY(tvisnum(o))) {\n      /* For performance reasons, this doesn't check for integerness or\n      ** integer overflow. Overflow detection still works, since all FPUs\n      ** return either MININT or MAXINT, which is then out of range.\n      */\n      int32_t i = (int32_t)numV(o);\n      if (i >= a && i <= b) return i;\n#if LJ_HASFFI\n    } else if (tviscdata(o)) {\n      GCcdata *cd = cdataV(o);\n      if (cd->ctypeid == CTID_INT64) {\n\tint64_t i = *(int64_t *)cdataptr(cd);\n\tif (i >= (int64_t)a && i <= (int64_t)b) return (int32_t)i;\n      } else if (cd->ctypeid == CTID_UINT64) {\n\tuint64_t i = *(uint64_t *)cdataptr(cd);\n\tif ((a < 0 || i >= (uint64_t)a) && i <= (uint64_t)b) return (int32_t)i;\n      } else {\n\tgoto badtype;\n      }\n#endif\n    } else {\n      goto badtype;\n    }\n    lj_err_arg(L, narg, LJ_ERR_NUMRNG);\n  }\nbadtype:\n  lj_err_argt(L, narg, LUA_TNUMBER);\n  return 0;  /* unreachable */\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_lib.h",
    "content": "/*\n** Library function support.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_LIB_H\n#define _LJ_LIB_H\n\n#include \"lj_obj.h\"\n\n/*\n** A fallback handler is called by the assembler VM if the fast path fails:\n**\n** - too few arguments:   unrecoverable.\n** - wrong argument type:   recoverable, if coercion succeeds.\n** - bad argument value:  unrecoverable.\n** - stack overflow:        recoverable, if stack reallocation succeeds.\n** - extra handling:        recoverable.\n**\n** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(),\n** lj_err_caller() or lj_err_callermsg().\n** The recoverable cases return 0 or the number of results + 1.\n** The assembler VM retries the fast path only if 0 is returned.\n** This time the fallback must not be called again or it gets stuck in a loop.\n*/\n\n/* Return values from fallback handler. */\n#define FFH_RETRY\t0\n#define FFH_UNREACHABLE\tFFH_RETRY\n#define FFH_RES(n)\t((n)+1)\n#define FFH_TAILCALL\t(-1)\n\nLJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg);\nLJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg);\nLJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg);\n#if LJ_DUALNUM\nLJ_FUNC void lj_lib_checknumber(lua_State *L, int narg);\n#else\n#define lj_lib_checknumber(L, narg)\tlj_lib_checknum((L), (narg))\n#endif\nLJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg);\nLJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg);\nLJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def);\nLJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg);\nLJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg);\nLJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg);\nLJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);\n\n#if LJ_HASBUFFER\nLJ_FUNC GCstr *lj_lib_checkstrx(lua_State *L, int narg);\nLJ_FUNC int32_t lj_lib_checkintrange(lua_State *L, int narg,\n\t\t\t\t     int32_t a, int32_t b);\n#endif\n\n/* Avoid including lj_frame.h. */\n#if LJ_GC64\n#define lj_lib_upvalue(L, n) \\\n  (&gcval(L->base-2)->fn.c.upvalue[(n)-1])\n#elif LJ_FR2\n#define lj_lib_upvalue(L, n) \\\n  (&gcref((L->base-2)->gcr)->fn.c.upvalue[(n)-1])\n#else\n#define lj_lib_upvalue(L, n) \\\n  (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])\n#endif\n\n#if LJ_TARGET_WINDOWS\n#define lj_lib_checkfpu(L) \\\n  do { setnumV(L->top++, (lua_Number)1437217655); \\\n    if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \\\n    L->top--; } while (0)\n#else\n#define lj_lib_checkfpu(L)\tUNUSED(L)\n#endif\n\nLJ_FUNC GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n);\n#define lj_lib_pushcf(L, fn, id)\t(lj_lib_pushcc(L, (fn), (id), 0))\n\n/* Library function declarations. Scanned by buildvm. */\n#define LJLIB_CF(name)\t\tstatic int lj_cf_##name(lua_State *L)\n#define LJLIB_ASM(name)\t\tstatic int lj_ffh_##name(lua_State *L)\n#define LJLIB_ASM_(name)\n#define LJLIB_LUA(name)\n#define LJLIB_SET(name)\n#define LJLIB_PUSH(arg)\n#define LJLIB_REC(handler)\n#define LJLIB_NOREGUV\n#define LJLIB_NOREG\n\n#define LJ_LIB_REG(L, regname, name) \\\n  lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name)\n\nLJ_FUNC void lj_lib_register(lua_State *L, const char *libname,\n\t\t\t     const uint8_t *init, const lua_CFunction *cf);\nLJ_FUNC void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f,\n\t\t\t   GCtab *env);\nLJ_FUNC int lj_lib_postreg(lua_State *L, lua_CFunction cf, int id,\n\t\t\t   const char *name);\n\n/* Library init data tags. */\n#define LIBINIT_LENMASK\t0x3f\n#define LIBINIT_TAGMASK\t0xc0\n#define LIBINIT_CF\t0x00\n#define LIBINIT_ASM\t0x40\n#define LIBINIT_ASM_\t0x80\n#define LIBINIT_STRING\t0xc0\n#define LIBINIT_MAXSTR\t0x38\n#define LIBINIT_LUA\t0xf9\n#define LIBINIT_SET\t0xfa\n#define LIBINIT_NUMBER\t0xfb\n#define LIBINIT_COPY\t0xfc\n#define LIBINIT_LASTCL\t0xfd\n#define LIBINIT_FFID\t0xfe\n#define LIBINIT_END\t0xff\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_load.c",
    "content": "/*\n** Load and dump code.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n\n#define lj_load_c\n#define LUA_CORE\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_func.h\"\n#include \"lj_frame.h\"\n#include \"lj_vm.h\"\n#include \"lj_lex.h\"\n#include \"lj_bcdump.h\"\n#include \"lj_parse.h\"\n\n/* -- Load Lua source code and bytecode ----------------------------------- */\n\nstatic TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  LexState *ls = (LexState *)ud;\n  GCproto *pt;\n  GCfunc *fn;\n  int bc;\n  UNUSED(dummy);\n  cframe_errfunc(L->cframe) = -1;  /* Inherit error function. */\n  bc = lj_lex_setup(L, ls);\n  if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) {\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE));\n    lj_err_throw(L, LUA_ERRSYNTAX);\n  }\n  pt = bc ? lj_bcread(ls) : lj_parse(ls);\n  fn = lj_func_newL_empty(L, pt, tabref(L->env));\n  /* Don't combine above/below into one statement. */\n  setfuncV(L, L->top++, fn);\n  return NULL;\n}\n\nLUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data,\n\t\t      const char *chunkname, const char *mode)\n{\n  LexState ls;\n  int status;\n  ls.rfunc = reader;\n  ls.rdata = data;\n  ls.chunkarg = chunkname ? chunkname : \"?\";\n  ls.mode = mode;\n  lj_buf_init(L, &ls.sb);\n  status = lj_vm_cpcall(L, NULL, &ls, cpparser);\n  lj_lex_cleanup(L, &ls);\n  lj_gc_check(L);\n  return status;\n}\n\nLUA_API int lua_load(lua_State *L, lua_Reader reader, void *data,\n\t\t     const char *chunkname)\n{\n  return lua_loadx(L, reader, data, chunkname, NULL);\n}\n\ntypedef struct FileReaderCtx {\n  FILE *fp;\n  char buf[LUAL_BUFFERSIZE];\n} FileReaderCtx;\n\nstatic const char *reader_file(lua_State *L, void *ud, size_t *size)\n{\n  FileReaderCtx *ctx = (FileReaderCtx *)ud;\n  UNUSED(L);\n  if (feof(ctx->fp)) return NULL;\n  *size = fread(ctx->buf, 1, sizeof(ctx->buf), ctx->fp);\n  return *size > 0 ? ctx->buf : NULL;\n}\n\nLUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,\n\t\t\t      const char *mode)\n{\n  FileReaderCtx ctx;\n  int status;\n  const char *chunkname;\n  if (filename) {\n    ctx.fp = fopen(filename, \"rb\");\n    if (ctx.fp == NULL) {\n      lua_pushfstring(L, \"cannot open %s: %s\", filename, strerror(errno));\n      return LUA_ERRFILE;\n    }\n    chunkname = lua_pushfstring(L, \"@%s\", filename);\n  } else {\n    ctx.fp = stdin;\n    chunkname = \"=stdin\";\n  }\n  status = lua_loadx(L, reader_file, &ctx, chunkname, mode);\n  if (ferror(ctx.fp)) {\n    L->top -= filename ? 2 : 1;\n    lua_pushfstring(L, \"cannot read %s: %s\", chunkname+1, strerror(errno));\n    if (filename)\n      fclose(ctx.fp);\n    return LUA_ERRFILE;\n  }\n  if (filename) {\n    L->top--;\n    copyTV(L, L->top-1, L->top);\n    fclose(ctx.fp);\n  }\n  return status;\n}\n\nLUALIB_API int luaL_loadfile(lua_State *L, const char *filename)\n{\n  return luaL_loadfilex(L, filename, NULL);\n}\n\ntypedef struct StringReaderCtx {\n  const char *str;\n  size_t size;\n} StringReaderCtx;\n\nstatic const char *reader_string(lua_State *L, void *ud, size_t *size)\n{\n  StringReaderCtx *ctx = (StringReaderCtx *)ud;\n  UNUSED(L);\n  if (ctx->size == 0) return NULL;\n  *size = ctx->size;\n  ctx->size = 0;\n  return ctx->str;\n}\n\nLUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size,\n\t\t\t\tconst char *name, const char *mode)\n{\n  StringReaderCtx ctx;\n  ctx.str = buf;\n  ctx.size = size;\n  return lua_loadx(L, reader_string, &ctx, name, mode);\n}\n\nLUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size,\n\t\t\t       const char *name)\n{\n  return luaL_loadbufferx(L, buf, size, name, NULL);\n}\n\nLUALIB_API int luaL_loadstring(lua_State *L, const char *s)\n{\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n/* -- Dump bytecode ------------------------------------------------------- */\n\nLUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)\n{\n  cTValue *o = L->top-1;\n  lj_checkapi(L->top > L->base, \"top slot empty\");\n  if (tvisfunc(o) && isluafunc(funcV(o)))\n    return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0);\n  else\n    return 1;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_mcode.c",
    "content": "/*\n** Machine code management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_mcode_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#if LJ_HASJIT\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_jit.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_prng.h\"\n#endif\n#if LJ_HASJIT || LJ_HASFFI\n#include \"lj_vm.h\"\n#endif\n\n/* -- OS-specific functions ----------------------------------------------- */\n\n#if LJ_HASJIT || LJ_HASFFI\n\n/* Define this if you want to run LuaJIT with Valgrind. */\n#ifdef LUAJIT_USE_VALGRIND\n#include <valgrind/valgrind.h>\n#endif\n\n#if LJ_TARGET_IOS\nvoid sys_icache_invalidate(void *start, size_t len);\n#endif\n\n/* Synchronize data/instruction cache. */\nvoid lj_mcode_sync(void *start, void *end)\n{\n#ifdef LUAJIT_USE_VALGRIND\n  VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start);\n#endif\n#if LJ_TARGET_X86ORX64\n  UNUSED(start); UNUSED(end);\n#elif LJ_TARGET_IOS\n  sys_icache_invalidate(start, (char *)end-(char *)start);\n#elif LJ_TARGET_PPC\n  lj_vm_cachesync(start, end);\n#elif defined(__GNUC__) || defined(__clang__)\n  __clear_cache(start, end);\n#else\n#error \"Missing builtin to flush instruction cache\"\n#endif\n}\n\n#endif\n\n#if LJ_HASJIT\n\n#if LJ_TARGET_WINDOWS\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#define MCPROT_RW\tPAGE_READWRITE\n#define MCPROT_RX\tPAGE_EXECUTE_READ\n#define MCPROT_RWX\tPAGE_EXECUTE_READWRITE\n\nstatic void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, DWORD prot)\n{\n  void *p = LJ_WIN_VALLOC((void *)hint, sz,\n\t\t\t  MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, prot);\n  if (!p && !hint)\n    lj_trace_err(J, LJ_TRERR_MCODEAL);\n  return p;\n}\n\nstatic void mcode_free(jit_State *J, void *p, size_t sz)\n{\n  UNUSED(J); UNUSED(sz);\n  VirtualFree(p, 0, MEM_RELEASE);\n}\n\nstatic int mcode_setprot(void *p, size_t sz, DWORD prot)\n{\n  DWORD oprot;\n  return !LJ_WIN_VPROTECT(p, sz, prot, &oprot);\n}\n\n#elif LJ_TARGET_POSIX\n\n#include <sys/mman.h>\n\n#ifndef MAP_ANONYMOUS\n#define MAP_ANONYMOUS\tMAP_ANON\n#endif\n\n#define MCPROT_RW\t(PROT_READ|PROT_WRITE)\n#define MCPROT_RX\t(PROT_READ|PROT_EXEC)\n#define MCPROT_RWX\t(PROT_READ|PROT_WRITE|PROT_EXEC)\n#ifdef PROT_MPROTECT\n#define MCPROT_CREATE\t(PROT_MPROTECT(MCPROT_RWX))\n#else\n#define MCPROT_CREATE\t0\n#endif\n\nstatic void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)\n{\n  void *p = mmap((void *)hint, sz, prot|MCPROT_CREATE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);\n  if (p == MAP_FAILED) {\n    if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);\n    p = NULL;\n  }\n  return p;\n}\n\nstatic void mcode_free(jit_State *J, void *p, size_t sz)\n{\n  UNUSED(J);\n  munmap(p, sz);\n}\n\nstatic int mcode_setprot(void *p, size_t sz, int prot)\n{\n  return mprotect(p, sz, prot);\n}\n\n#else\n\n#error \"Missing OS support for explicit placement of executable memory\"\n\n#endif\n\n/* -- MCode area protection ----------------------------------------------- */\n\n#if LUAJIT_SECURITY_MCODE == 0\n\n/* Define this ONLY if page protection twiddling becomes a bottleneck.\n**\n** It's generally considered to be a potential security risk to have\n** pages with simultaneous write *and* execute access in a process.\n**\n** Do not even think about using this mode for server processes or\n** apps handling untrusted external data.\n**\n** The security risk is not in LuaJIT itself -- but if an adversary finds\n** any *other* flaw in your C application logic, then any RWX memory pages\n** simplify writing an exploit considerably.\n*/\n#define MCPROT_GEN\tMCPROT_RWX\n#define MCPROT_RUN\tMCPROT_RWX\n\nstatic void mcode_protect(jit_State *J, int prot)\n{\n  UNUSED(J); UNUSED(prot); UNUSED(mcode_setprot);\n}\n\n#else\n\n/* This is the default behaviour and much safer:\n**\n** Most of the time the memory pages holding machine code are executable,\n** but NONE of them is writable.\n**\n** The current memory area is marked read-write (but NOT executable) only\n** during the short time window while the assembler generates machine code.\n*/\n#define MCPROT_GEN\tMCPROT_RW\n#define MCPROT_RUN\tMCPROT_RX\n\n/* Protection twiddling failed. Probably due to kernel security. */\nstatic LJ_NOINLINE void mcode_protfail(jit_State *J)\n{\n  lua_CFunction panic = J2G(J)->panic;\n  if (panic) {\n    lua_State *L = J->L;\n    setstrV(L, L->top++, lj_err_str(L, LJ_ERR_JITPROT));\n    panic(L);\n  }\n}\n\n/* Change protection of MCode area. */\nstatic void mcode_protect(jit_State *J, int prot)\n{\n  if (J->mcprot != prot) {\n    if (LJ_UNLIKELY(mcode_setprot(J->mcarea, J->szmcarea, prot)))\n      mcode_protfail(J);\n    J->mcprot = prot;\n  }\n}\n\n#endif\n\n/* -- MCode area allocation ----------------------------------------------- */\n\n#if LJ_64\n#define mcode_validptr(p)\t(p)\n#else\n#define mcode_validptr(p)\t((p) && (uintptr_t)(p) < 0xffff0000)\n#endif\n\n#ifdef LJ_TARGET_JUMPRANGE\n\n/* Get memory within relative jump distance of our code in 64 bit mode. */\nstatic void *mcode_alloc(jit_State *J, size_t sz)\n{\n  /* Target an address in the static assembler code (64K aligned).\n  ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB.\n  ** Use half the jump range so every address in the range can reach any other.\n  */\n#if LJ_TARGET_MIPS\n  /* Use the middle of the 256MB-aligned region. */\n  uintptr_t target = ((uintptr_t)(void *)lj_vm_exit_handler &\n\t\t      ~(uintptr_t)0x0fffffffu) + 0x08000000u;\n#else\n  uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;\n#endif\n  const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21);\n  /* First try a contiguous area below the last one. */\n  uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;\n  int i;\n  /* Limit probing iterations, depending on the available pool size. */\n  for (i = 0; i < LJ_TARGET_JUMPRANGE; i++) {\n    if (mcode_validptr(hint)) {\n      void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);\n\n      if (mcode_validptr(p) &&\n\t  ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range))\n\treturn p;\n      if (p) mcode_free(J, p, sz);  /* Free badly placed area. */\n    }\n    /* Next try probing 64K-aligned pseudo-random addresses. */\n    do {\n      hint = lj_prng_u64(&J2G(J)->prng) & ((1u<<LJ_TARGET_JUMPRANGE)-0x10000);\n    } while (!(hint + sz < range+range));\n    hint = target + hint - range;\n  }\n  lj_trace_err(J, LJ_TRERR_MCODEAL);  /* Give up. OS probably ignores hints? */\n  return NULL;\n}\n\n#else\n\n/* All memory addresses are reachable by relative jumps. */\nstatic void *mcode_alloc(jit_State *J, size_t sz)\n{\n#if defined(__OpenBSD__) || defined(__NetBSD__) || LJ_TARGET_UWP\n  /* Allow better executable memory allocation for OpenBSD W^X mode. */\n  void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN);\n  if (p && mcode_setprot(p, sz, MCPROT_GEN)) {\n    mcode_free(J, p, sz);\n    return NULL;\n  }\n  return p;\n#else\n  return mcode_alloc_at(J, 0, sz, MCPROT_GEN);\n#endif\n}\n\n#endif\n\n/* -- MCode area management ----------------------------------------------- */\n\n/* Allocate a new MCode area. */\nstatic void mcode_allocarea(jit_State *J)\n{\n  MCode *oldarea = J->mcarea;\n  size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10;\n  sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);\n  J->mcarea = (MCode *)mcode_alloc(J, sz);\n  J->szmcarea = sz;\n  J->mcprot = MCPROT_GEN;\n  J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea);\n  J->mcbot = (MCode *)((char *)J->mcarea + sizeof(MCLink));\n  ((MCLink *)J->mcarea)->next = oldarea;\n  ((MCLink *)J->mcarea)->size = sz;\n  J->szallmcarea += sz;\n  J->mcbot = (MCode *)lj_err_register_mcode(J->mcarea, sz, (uint8_t *)J->mcbot);\n}\n\n/* Free all MCode areas. */\nvoid lj_mcode_free(jit_State *J)\n{\n  MCode *mc = J->mcarea;\n  J->mcarea = NULL;\n  J->szallmcarea = 0;\n  while (mc) {\n    MCode *next = ((MCLink *)mc)->next;\n    size_t sz = ((MCLink *)mc)->size;\n    lj_err_deregister_mcode(mc, sz, (uint8_t *)mc + sizeof(MCLink));\n    mcode_free(J, mc, sz);\n    mc = next;\n  }\n}\n\n/* -- MCode transactions -------------------------------------------------- */\n\n/* Reserve the remainder of the current MCode area. */\nMCode *lj_mcode_reserve(jit_State *J, MCode **lim)\n{\n  if (!J->mcarea)\n    mcode_allocarea(J);\n  else\n    mcode_protect(J, MCPROT_GEN);\n  *lim = J->mcbot;\n  return J->mctop;\n}\n\n/* Commit the top part of the current MCode area. */\nvoid lj_mcode_commit(jit_State *J, MCode *top)\n{\n  J->mctop = top;\n  mcode_protect(J, MCPROT_RUN);\n}\n\n/* Abort the reservation. */\nvoid lj_mcode_abort(jit_State *J)\n{\n  if (J->mcarea)\n    mcode_protect(J, MCPROT_RUN);\n}\n\n/* Set/reset protection to allow patching of MCode areas. */\nMCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)\n{\n  if (finish) {\n#if LUAJIT_SECURITY_MCODE\n    if (J->mcarea == ptr)\n      mcode_protect(J, MCPROT_RUN);\n    else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN)))\n      mcode_protfail(J);\n#endif\n    return NULL;\n  } else {\n    MCode *mc = J->mcarea;\n    /* Try current area first to use the protection cache. */\n    if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {\n#if LUAJIT_SECURITY_MCODE\n      mcode_protect(J, MCPROT_GEN);\n#endif\n      return mc;\n    }\n    /* Otherwise search through the list of MCode areas. */\n    for (;;) {\n      mc = ((MCLink *)mc)->next;\n      lj_assertJ(mc != NULL, \"broken MCode area chain\");\n      if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {\n#if LUAJIT_SECURITY_MCODE\n\tif (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN)))\n\t  mcode_protfail(J);\n#endif\n\treturn mc;\n      }\n    }\n  }\n}\n\n/* Limit of MCode reservation reached. */\nvoid lj_mcode_limiterr(jit_State *J, size_t need)\n{\n  size_t sizemcode, maxmcode;\n  lj_mcode_abort(J);\n  sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10;\n  sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);\n  maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10;\n  if ((size_t)need > sizemcode)\n    lj_trace_err(J, LJ_TRERR_MCODEOV);  /* Too long for any area. */\n  if (J->szallmcarea + sizemcode > maxmcode)\n    lj_trace_err(J, LJ_TRERR_MCODEAL);\n  mcode_allocarea(J);\n  lj_trace_err(J, LJ_TRERR_MCODELM);  /* Retry with new area. */\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_mcode.h",
    "content": "/*\n** Machine code management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_MCODE_H\n#define _LJ_MCODE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT || LJ_HASFFI\nLJ_FUNC void lj_mcode_sync(void *start, void *end);\n#endif\n\n#if LJ_HASJIT\n\n#include \"lj_jit.h\"\n\nLJ_FUNC void lj_mcode_free(jit_State *J);\nLJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim);\nLJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m);\nLJ_FUNC void lj_mcode_abort(jit_State *J);\nLJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish);\nLJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need);\n\n#define lj_mcode_commitbot(J, m)\t(J->mcbot = (m))\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_meta.c",
    "content": "/*\n** Metamethod handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_meta_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n#include \"lj_lib.h\"\n\n/* -- Metamethod handling ------------------------------------------------- */\n\n/* String interning of metamethod names for fast indexing. */\nvoid lj_meta_init(lua_State *L)\n{\n#define MMNAME(name)\t\"__\" #name\n  const char *metanames = MMDEF(MMNAME);\n#undef MMNAME\n  global_State *g = G(L);\n  const char *p, *q;\n  uint32_t mm;\n  for (mm = 0, p = metanames; *p; mm++, p = q) {\n    GCstr *s;\n    for (q = p+2; *q && *q != '_'; q++) ;\n    s = lj_str_new(L, p, (size_t)(q-p));\n    /* NOBARRIER: g->gcroot[] is a GC root. */\n    setgcref(g->gcroot[GCROOT_MMNAME+mm], obj2gco(s));\n  }\n}\n\n/* Negative caching of a few fast metamethods. See the lj_meta_fast() macro. */\ncTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name)\n{\n  cTValue *mo = lj_tab_getstr(mt, name);\n  lj_assertX(mm <= MM_FAST, \"bad metamethod %d\", mm);\n  if (!mo || tvisnil(mo)) {  /* No metamethod? */\n    mt->nomm |= (uint8_t)(1u<<mm);  /* Set negative cache flag. */\n    return NULL;\n  }\n  return mo;\n}\n\n/* Lookup metamethod for object. */\ncTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm)\n{\n  GCtab *mt;\n  if (tvistab(o))\n    mt = tabref(tabV(o)->metatable);\n  else if (tvisudata(o))\n    mt = tabref(udataV(o)->metatable);\n  else\n    mt = tabref(basemt_obj(G(L), o));\n  if (mt) {\n    cTValue *mo = lj_tab_getstr(mt, mmname_str(G(L), mm));\n    if (mo)\n      return mo;\n  }\n  return niltv(L);\n}\n\n#if LJ_HASFFI\n/* Tailcall from C function. */\nint lj_meta_tailcall(lua_State *L, cTValue *tv)\n{\n  TValue *base = L->base;\n  TValue *top = L->top;\n  const BCIns *pc = frame_pc(base-1);  /* Preserve old PC from frame. */\n  copyTV(L, base-1-LJ_FR2, tv);  /* Replace frame with new object. */\n  if (LJ_FR2)\n    (top++)->u64 = LJ_CONT_TAILCALL;\n  else\n    top->u32.lo = LJ_CONT_TAILCALL;\n  setframe_pc(top++, pc);\n  setframe_gc(top, obj2gco(L), LJ_TTHREAD);  /* Dummy frame object. */\n  if (LJ_FR2) top++;\n  setframe_ftsz(top, ((char *)(top+1) - (char *)base) + FRAME_CONT);\n  L->base = L->top = top+1;\n  /*\n  ** before:   [old_mo|PC]    [... ...]\n  **                         ^base     ^top\n  ** after:    [new_mo|itype] [... ...] [NULL|PC] [dummy|delta]\n  **                                                           ^base/top\n  ** tailcall: [new_mo|PC]    [... ...]\n  **                         ^base     ^top\n  */\n  return 0;\n}\n#endif\n\n/* Setup call to metamethod to be run by Assembler VM. */\nstatic TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo,\n\t\t    cTValue *a, cTValue *b)\n{\n  /*\n  **           |-- framesize -> top       top+1       top+2 top+3\n  ** before:   [func slots ...]\n  ** mm setup: [func slots ...] [cont|?]  [mo|tmtype] [a]   [b]\n  ** in asm:   [func slots ...] [cont|PC] [mo|delta]  [a]   [b]\n  **           ^-- func base                          ^-- mm base\n  ** after mm: [func slots ...]           [result]\n  **                ^-- copy to base[PC_RA] --/     for lj_cont_ra\n  **                          istruecond + branch   for lj_cont_cond*\n  **                                       ignore   for lj_cont_nop\n  ** next PC:  [func slots ...]\n  */\n  TValue *top = L->top;\n  if (curr_funcisL(L)) top = curr_topL(L);\n  setcont(top++, cont);  /* Assembler VM stores PC in upper word or FR2. */\n  if (LJ_FR2) setnilV(top++);\n  copyTV(L, top++, mo);  /* Store metamethod and two arguments. */\n  if (LJ_FR2) setnilV(top++);\n  copyTV(L, top, a);\n  copyTV(L, top+1, b);\n  return top;  /* Return new base. */\n}\n\n/* -- C helpers for some instructions, called from assembler VM ----------- */\n\n/* Helper for TGET*. __index chain and metamethod. */\ncTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k)\n{\n  int loop;\n  for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {\n    cTValue *mo;\n    if (LJ_LIKELY(tvistab(o))) {\n      GCtab *t = tabV(o);\n      cTValue *tv = lj_tab_get(L, t, k);\n      if (!tvisnil(tv) ||\n\t  !(mo = lj_meta_fast(L, tabref(t->metatable), MM_index)))\n\treturn tv;\n    } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_index))) {\n      lj_err_optype(L, o, LJ_ERR_OPINDEX);\n      return NULL;  /* unreachable */\n    }\n    if (tvisfunc(mo)) {\n      L->top = mmcall(L, lj_cont_ra, mo, o, k);\n      return NULL;  /* Trigger metamethod call. */\n    }\n    o = mo;\n  }\n  lj_err_msg(L, LJ_ERR_GETLOOP);\n  return NULL;  /* unreachable */\n}\n\n/* Helper for TSET*. __newindex chain and metamethod. */\nTValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k)\n{\n  TValue tmp;\n  int loop;\n  for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {\n    cTValue *mo;\n    if (LJ_LIKELY(tvistab(o))) {\n      GCtab *t = tabV(o);\n      cTValue *tv = lj_tab_get(L, t, k);\n      if (LJ_LIKELY(!tvisnil(tv))) {\n\tt->nomm = 0;  /* Invalidate negative metamethod cache. */\n\tlj_gc_anybarriert(L, t);\n\treturn (TValue *)tv;\n      } else if (!(mo = lj_meta_fast(L, tabref(t->metatable), MM_newindex))) {\n\tt->nomm = 0;  /* Invalidate negative metamethod cache. */\n\tlj_gc_anybarriert(L, t);\n\tif (tv != niltv(L))\n\t  return (TValue *)tv;\n\tif (tvisnil(k)) lj_err_msg(L, LJ_ERR_NILIDX);\n\telse if (tvisint(k)) { setnumV(&tmp, (lua_Number)intV(k)); k = &tmp; }\n\telse if (tvisnum(k) && tvisnan(k)) lj_err_msg(L, LJ_ERR_NANIDX);\n\treturn lj_tab_newkey(L, t, k);\n      }\n    } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_newindex))) {\n      lj_err_optype(L, o, LJ_ERR_OPINDEX);\n      return NULL;  /* unreachable */\n    }\n    if (tvisfunc(mo)) {\n      L->top = mmcall(L, lj_cont_nop, mo, o, k);\n      /* L->top+2 = v filled in by caller. */\n      return NULL;  /* Trigger metamethod call. */\n    }\n    copyTV(L, &tmp, mo);\n    o = &tmp;\n  }\n  lj_err_msg(L, LJ_ERR_SETLOOP);\n  return NULL;  /* unreachable */\n}\n\nstatic cTValue *str2num(cTValue *o, TValue *n)\n{\n  if (tvisnum(o))\n    return o;\n  else if (tvisint(o))\n    return (setnumV(n, (lua_Number)intV(o)), n);\n  else if (tvisstr(o) && lj_strscan_num(strV(o), n))\n    return n;\n  else\n    return NULL;\n}\n\n/* Helper for arithmetic instructions. Coercion, metamethod. */\nTValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, cTValue *rc,\n\t\t      BCReg op)\n{\n  MMS mm = bcmode_mm(op);\n  TValue tempb, tempc;\n  cTValue *b, *c;\n  if ((b = str2num(rb, &tempb)) != NULL &&\n      (c = str2num(rc, &tempc)) != NULL) {  /* Try coercion first. */\n    setnumV(ra, lj_vm_foldarith(numV(b), numV(c), (int)mm-MM_add));\n    return NULL;\n  } else {\n    cTValue *mo = lj_meta_lookup(L, rb, mm);\n    if (tvisnil(mo)) {\n      mo = lj_meta_lookup(L, rc, mm);\n      if (tvisnil(mo)) {\n\tif (str2num(rb, &tempb) == NULL) rc = rb;\n\tlj_err_optype(L, rc, LJ_ERR_OPARITH);\n\treturn NULL;  /* unreachable */\n      }\n    }\n    return mmcall(L, lj_cont_ra, mo, rb, rc);\n  }\n}\n\n/* Helper for CAT. Coercion, iterative concat, __concat metamethod. */\nTValue *lj_meta_cat(lua_State *L, TValue *top, int left)\n{\n  int fromc = 0;\n  if (left < 0) { left = -left; fromc = 1; }\n  do {\n    if (!(tvisstr(top) || tvisnumber(top) || tvisbuf(top)) ||\n\t!(tvisstr(top-1) || tvisnumber(top-1) || tvisbuf(top-1))) {\n      cTValue *mo = lj_meta_lookup(L, top-1, MM_concat);\n      if (tvisnil(mo)) {\n\tmo = lj_meta_lookup(L, top, MM_concat);\n\tif (tvisnil(mo)) {\n\t  if (tvisstr(top-1) || tvisnumber(top-1)) top++;\n\t  lj_err_optype(L, top-1, LJ_ERR_OPCAT);\n\t  return NULL;  /* unreachable */\n\t}\n      }\n      /* One of the top two elements is not a string, call __cat metamethod:\n      **\n      ** before:    [...][CAT stack .........................]\n      **                                 top-1     top         top+1 top+2\n      ** pick two:  [...][CAT stack ...] [o1]      [o2]\n      ** setup mm:  [...][CAT stack ...] [cont|?]  [mo|tmtype] [o1]  [o2]\n      ** in asm:    [...][CAT stack ...] [cont|PC] [mo|delta]  [o1]  [o2]\n      **            ^-- func base                              ^-- mm base\n      ** after mm:  [...][CAT stack ...] <--push-- [result]\n      ** next step: [...][CAT stack .............]\n      */\n      copyTV(L, top+2*LJ_FR2+2, top);  /* Carefully ordered stack copies! */\n      copyTV(L, top+2*LJ_FR2+1, top-1);\n      copyTV(L, top+LJ_FR2, mo);\n      setcont(top-1, lj_cont_cat);\n      if (LJ_FR2) { setnilV(top); setnilV(top+2); top += 2; }\n      return top+1;  /* Trigger metamethod call. */\n    } else {\n      /* Pick as many strings as possible from the top and concatenate them:\n      **\n      ** before:    [...][CAT stack ...........................]\n      ** pick str:  [...][CAT stack ...] [...... strings ......]\n      ** concat:    [...][CAT stack ...] [result]\n      ** next step: [...][CAT stack ............]\n      */\n      TValue *e, *o = top;\n      uint64_t tlen = tvisstr(o) ? strV(o)->len :\n\t\t      tvisbuf(o) ? sbufxlen(bufV(o)) : STRFMT_MAXBUF_NUM;\n      SBuf *sb;\n      do {\n\to--; tlen += tvisstr(o) ? strV(o)->len :\n\t\t     tvisbuf(o) ? sbufxlen(bufV(o)) : STRFMT_MAXBUF_NUM;\n      } while (--left > 0 && (tvisstr(o-1) || tvisnumber(o-1)));\n      if (tlen >= LJ_MAX_STR) lj_err_msg(L, LJ_ERR_STROV);\n      sb = lj_buf_tmp_(L);\n      lj_buf_more(sb, (MSize)tlen);\n      for (e = top, top = o; o <= e; o++) {\n\tif (tvisstr(o)) {\n\t  GCstr *s = strV(o);\n\t  MSize len = s->len;\n\t  lj_buf_putmem(sb, strdata(s), len);\n\t} else if (tvisbuf(o)) {\n\t  SBufExt *sbx = bufV(o);\n\t  lj_buf_putmem(sb, sbx->r, sbufxlen(sbx));\n\t} else if (tvisint(o)) {\n\t  lj_strfmt_putint(sb, intV(o));\n\t} else {\n\t  lj_strfmt_putfnum(sb, STRFMT_G14, numV(o));\n\t}\n      }\n      setstrV(L, top, lj_buf_str(L, sb));\n    }\n  } while (left >= 1);\n  if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) {\n    if (!fromc) L->top = curr_topL(L);\n    lj_gc_step(L);\n  }\n  return NULL;\n}\n\n/* Helper for LEN. __len metamethod. */\nTValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o)\n{\n  cTValue *mo = lj_meta_lookup(L, o, MM_len);\n  if (tvisnil(mo)) {\n    if (LJ_52 && tvistab(o))\n      tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<<MM_len);\n    else\n      lj_err_optype(L, o, LJ_ERR_OPLEN);\n    return NULL;\n  }\n  return mmcall(L, lj_cont_ra, mo, o, LJ_52 ? o : niltv(L));\n}\n\n/* Helper for equality comparisons. __eq metamethod. */\nTValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)\n{\n  /* Field metatable must be at same offset for GCtab and GCudata! */\n  cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq);\n  if (mo) {\n    TValue *top;\n    uint32_t it;\n    if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) {\n      cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq);\n      if (mo2 == NULL || !lj_obj_equal(mo, mo2))\n\treturn (TValue *)(intptr_t)ne;\n    }\n    top = curr_top(L);\n    setcont(top++, ne ? lj_cont_condf : lj_cont_condt);\n    if (LJ_FR2) setnilV(top++);\n    copyTV(L, top++, mo);\n    if (LJ_FR2) setnilV(top++);\n    it = ~(uint32_t)o1->gch.gct;\n    setgcV(L, top, o1, it);\n    setgcV(L, top+1, o2, it);\n    return top;  /* Trigger metamethod call. */\n  }\n  return (TValue *)(intptr_t)ne;\n}\n\n#if LJ_HASFFI\nTValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins)\n{\n  ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt;\n  int op = (int)bc_op(ins) & ~1;\n  TValue tv;\n  cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)];\n  cTValue *o1mm = o1;\n  if (op == BC_ISEQV) {\n    o2 = &L->base[bc_d(ins)];\n    if (!tviscdata(o1mm)) o1mm = o2;\n  } else if (op == BC_ISEQS) {\n    setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins))));\n    o2 = &tv;\n  } else if (op == BC_ISEQN) {\n    o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)];\n  } else {\n    lj_assertL(op == BC_ISEQP, \"bad bytecode op %d\", op);\n    setpriV(&tv, ~bc_d(ins));\n    o2 = &tv;\n  }\n  mo = lj_meta_lookup(L, o1mm, MM_eq);\n  if (LJ_LIKELY(!tvisnil(mo)))\n    return mmcall(L, cont, mo, o1, o2);\n  else\n    return (TValue *)(intptr_t)(bc_op(ins) & 1);\n}\n#endif\n\n/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */\nTValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op)\n{\n  if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) {\n    ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;\n    MMS mm = (op & 2) ? MM_le : MM_lt;\n    cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm);\n    if (LJ_UNLIKELY(tvisnil(mo))) goto err;\n    return mmcall(L, cont, mo, o1, o2);\n  } else if (LJ_52 || itype(o1) == itype(o2)) {\n    /* Never called with two numbers. */\n    if (tvisstr(o1) && tvisstr(o2)) {\n      int32_t res = lj_str_cmp(strV(o1), strV(o2));\n      return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1));\n    } else {\n    trymt:\n      while (1) {\n\tASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;\n\tMMS mm = (op & 2) ? MM_le : MM_lt;\n\tcTValue *mo = lj_meta_lookup(L, o1, mm);\n#if LJ_52\n\tif (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm))))\n#else\n\tcTValue *mo2 = lj_meta_lookup(L, o2, mm);\n\tif (tvisnil(mo) || !lj_obj_equal(mo, mo2))\n#endif\n\t{\n\t  if (op & 2) {  /* MM_le not found: retry with MM_lt. */\n\t    cTValue *ot = o1; o1 = o2; o2 = ot;  /* Swap operands. */\n\t    op ^= 3;  /* Use LT and flip condition. */\n\t    continue;\n\t  }\n\t  goto err;\n\t}\n\treturn mmcall(L, cont, mo, o1, o2);\n      }\n    }\n  } else if (tvisbool(o1) && tvisbool(o2)) {\n    goto trymt;\n  } else {\n  err:\n    lj_err_comp(L, o1, o2);\n    return NULL;\n  }\n}\n\n/* Helper for ISTYPE and ISNUM. Implicit coercion or error. */\nvoid lj_meta_istype(lua_State *L, BCReg ra, BCReg tp)\n{\n  L->top = curr_topL(L);\n  ra++; tp--;\n  lj_assertL(LJ_DUALNUM || tp != ~LJ_TNUMX, \"bad type for ISTYPE\");\n  if (LJ_DUALNUM && tp == ~LJ_TNUMX) lj_lib_checkint(L, ra);\n  else if (tp == ~LJ_TNUMX+1) lj_lib_checknum(L, ra);\n  else if (tp == ~LJ_TSTR) lj_lib_checkstr(L, ra);\n  else lj_err_argtype(L, ra, lj_obj_itypename[tp]);\n}\n\n/* Helper for calls. __call metamethod. */\nvoid lj_meta_call(lua_State *L, TValue *func, TValue *top)\n{\n  cTValue *mo = lj_meta_lookup(L, func, MM_call);\n  TValue *p;\n  if (!tvisfunc(mo))\n    lj_err_optype_call(L, func);\n  for (p = top; p > func+2*LJ_FR2; p--) copyTV(L, p, p-1);\n  if (LJ_FR2) copyTV(L, func+2, func);\n  copyTV(L, func, mo);\n}\n\n/* Helper for FORI. Coercion. */\nvoid LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o)\n{\n  if (!lj_strscan_numberobj(o)) lj_err_msg(L, LJ_ERR_FORINIT);\n  if (!lj_strscan_numberobj(o+1)) lj_err_msg(L, LJ_ERR_FORLIM);\n  if (!lj_strscan_numberobj(o+2)) lj_err_msg(L, LJ_ERR_FORSTEP);\n  if (LJ_DUALNUM) {\n    /* Ensure all slots are integers or all slots are numbers. */\n    int32_t k[3];\n    int nint = 0;\n    ptrdiff_t i;\n    for (i = 0; i <= 2; i++) {\n      if (tvisint(o+i)) {\n\tk[i] = intV(o+i); nint++;\n      } else {\n\tk[i] = lj_num2int(numV(o+i)); nint += ((lua_Number)k[i] == numV(o+i));\n      }\n    }\n    if (nint == 3) {  /* Narrow to integers. */\n      setintV(o, k[0]);\n      setintV(o+1, k[1]);\n      setintV(o+2, k[2]);\n    } else if (nint != 0) {  /* Widen to numbers. */\n      if (tvisint(o)) setnumV(o, (lua_Number)intV(o));\n      if (tvisint(o+1)) setnumV(o+1, (lua_Number)intV(o+1));\n      if (tvisint(o+2)) setnumV(o+2, (lua_Number)intV(o+2));\n    }\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_meta.h",
    "content": "/*\n** Metamethod handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_META_H\n#define _LJ_META_H\n\n#include \"lj_obj.h\"\n\n/* Metamethod handling */\nLJ_FUNC void lj_meta_init(lua_State *L);\nLJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name);\nLJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm);\n#if LJ_HASFFI\nLJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv);\n#endif\n\n#define lj_meta_fastg(g, mt, mm) \\\n  ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \\\n   lj_meta_cache(mt, mm, mmname_str(g, mm)))\n#define lj_meta_fast(L, mt, mm)\tlj_meta_fastg(G(L), mt, mm)\n\n/* C helpers for some instructions, called from assembler VM. */\nLJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k);\nLJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k);\nLJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb,\n\t\t\t       cTValue *rc, BCReg op);\nLJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left);\nLJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o);\nLJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne);\nLJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins);\nLJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op);\nLJ_FUNCA void lj_meta_istype(lua_State *L, BCReg ra, BCReg tp);\nLJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top);\nLJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_obj.c",
    "content": "/*\n** Miscellaneous object handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_obj_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n/* Object type names. */\nLJ_DATADEF const char *const lj_obj_typename[] = {  /* ORDER LUA_T */\n  \"no value\", \"nil\", \"boolean\", \"userdata\", \"number\", \"string\",\n  \"table\", \"function\", \"userdata\", \"thread\", \"proto\", \"cdata\"\n};\n\nLJ_DATADEF const char *const lj_obj_itypename[] = {  /* ORDER LJ_T */\n  \"nil\", \"boolean\", \"boolean\", \"userdata\", \"string\", \"upval\", \"thread\",\n  \"proto\", \"function\", \"trace\", \"cdata\", \"table\", \"userdata\", \"number\"\n};\n\n/* Compare two objects without calling metamethods. */\nint LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2)\n{\n  if (itype(o1) == itype(o2)) {\n    if (tvispri(o1))\n      return 1;\n    if (!tvisnum(o1))\n      return gcrefeq(o1->gcr, o2->gcr);\n  } else if (!tvisnumber(o1) || !tvisnumber(o2)) {\n    return 0;\n  }\n  return numberVnum(o1) == numberVnum(o2);\n}\n\n/* Return pointer to object or its object data. */\nconst void * LJ_FASTCALL lj_obj_ptr(global_State *g, cTValue *o)\n{\n  UNUSED(g);\n  if (tvisudata(o))\n    return uddata(udataV(o));\n  else if (tvislightud(o))\n    return lightudV(g, o);\n  else if (LJ_HASFFI && tviscdata(o))\n    return cdataptr(cdataV(o));\n  else if (tvisgcv(o))\n    return gcV(o);\n  else\n    return NULL;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_obj.h",
    "content": "/*\n** LuaJIT VM tags, values and objects.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#ifndef _LJ_OBJ_H\n#define _LJ_OBJ_H\n\n#include \"lua.h\"\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* -- Memory references --------------------------------------------------- */\n\n/* Memory and GC object sizes. */\ntypedef uint32_t MSize;\n#if LJ_GC64\ntypedef uint64_t GCSize;\n#else\ntypedef uint32_t GCSize;\n#endif\n\n/* Memory reference */\ntypedef struct MRef {\n#if LJ_GC64\n  uint64_t ptr64;\t/* True 64 bit pointer. */\n#else\n  uint32_t ptr32;\t/* Pseudo 32 bit pointer. */\n#endif\n} MRef;\n\n#if LJ_GC64\n#define mref(r, t)\t((t *)(void *)(r).ptr64)\n#define mrefu(r)\t((r).ptr64)\n\n#define setmref(r, p)\t((r).ptr64 = (uint64_t)(void *)(p))\n#define setmrefu(r, u)\t((r).ptr64 = (uint64_t)(u))\n#define setmrefr(r, v)\t((r).ptr64 = (v).ptr64)\n#else\n#define mref(r, t)\t((t *)(void *)(uintptr_t)(r).ptr32)\n#define mrefu(r)\t((r).ptr32)\n\n#define setmref(r, p)\t((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p))\n#define setmrefu(r, u)\t((r).ptr32 = (uint32_t)(u))\n#define setmrefr(r, v)\t((r).ptr32 = (v).ptr32)\n#endif\n\n/* -- GC object references ------------------------------------------------ */\n\n/* GCobj reference */\ntypedef struct GCRef {\n#if LJ_GC64\n  uint64_t gcptr64;\t/* True 64 bit pointer. */\n#else\n  uint32_t gcptr32;\t/* Pseudo 32 bit pointer. */\n#endif\n} GCRef;\n\n/* Common GC header for all collectable objects. */\n#define GCHeader\tGCRef nextgc; uint8_t marked; uint8_t gct\n/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */\n\n#if LJ_GC64\n#define gcref(r)\t((GCobj *)(r).gcptr64)\n#define gcrefp(r, t)\t((t *)(void *)(r).gcptr64)\n#define gcrefu(r)\t((r).gcptr64)\n#define gcrefeq(r1, r2)\t((r1).gcptr64 == (r2).gcptr64)\n\n#define setgcref(r, gc)\t((r).gcptr64 = (uint64_t)&(gc)->gch)\n#define setgcreft(r, gc, it) \\\n  (r).gcptr64 = (uint64_t)&(gc)->gch | (((uint64_t)(it)) << 47)\n#define setgcrefp(r, p)\t((r).gcptr64 = (uint64_t)(p))\n#define setgcrefnull(r)\t((r).gcptr64 = 0)\n#define setgcrefr(r, v)\t((r).gcptr64 = (v).gcptr64)\n#else\n#define gcref(r)\t((GCobj *)(uintptr_t)(r).gcptr32)\n#define gcrefp(r, t)\t((t *)(void *)(uintptr_t)(r).gcptr32)\n#define gcrefu(r)\t((r).gcptr32)\n#define gcrefeq(r1, r2)\t((r1).gcptr32 == (r2).gcptr32)\n\n#define setgcref(r, gc)\t((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)\n#define setgcrefp(r, p)\t((r).gcptr32 = (uint32_t)(uintptr_t)(p))\n#define setgcrefnull(r)\t((r).gcptr32 = 0)\n#define setgcrefr(r, v)\t((r).gcptr32 = (v).gcptr32)\n#endif\n\n#define gcnext(gc)\t(gcref((gc)->gch.nextgc))\n\n/* IMPORTANT NOTE:\n**\n** All uses of the setgcref* macros MUST be accompanied with a write barrier.\n**\n** This is to ensure the integrity of the incremental GC. The invariant\n** to preserve is that a black object never points to a white object.\n** I.e. never store a white object into a field of a black object.\n**\n** It's ok to LEAVE OUT the write barrier ONLY in the following cases:\n** - The source is not a GC object (NULL).\n** - The target is a GC root. I.e. everything in global_State.\n** - The target is a lua_State field (threads are never black).\n** - The target is a stack slot, see setgcV et al.\n** - The target is an open upvalue, i.e. pointing to a stack slot.\n** - The target is a newly created object (i.e. marked white). But make\n**   sure nothing invokes the GC inbetween.\n** - The target and the source are the same object (self-reference).\n** - The target already contains the object (e.g. moving elements around).\n**\n** The most common case is a store to a stack slot. All other cases where\n** a barrier has been omitted are annotated with a NOBARRIER comment.\n**\n** The same logic applies for stores to table slots (array part or hash\n** part). ALL uses of lj_tab_set* require a barrier for the stored value\n** *and* the stored key, based on the above rules. In practice this means\n** a barrier is needed if *either* of the key or value are a GC object.\n**\n** It's ok to LEAVE OUT the write barrier in the following special cases:\n** - The stored value is nil. The key doesn't matter because it's either\n**   not resurrected or lj_tab_newkey() will take care of the key barrier.\n** - The key doesn't matter if the *previously* stored value is guaranteed\n**   to be non-nil (because the key is kept alive in the table).\n** - The key doesn't matter if it's guaranteed not to be part of the table,\n**   since lj_tab_newkey() takes care of the key barrier. This applies\n**   trivially to new tables, but watch out for resurrected keys. Storing\n**   a nil value leaves the key in the table!\n**\n** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used\n** by the interpreter for all table stores.\n**\n** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark\n** dead keys in tables. The reference is left in, but it's guaranteed to\n** be never dereferenced as long as the value is nil. It's ok if the key is\n** freed or if any object subsequently gets the same address.\n**\n** Not destroying dead keys helps to keep key hash slots stable. This avoids\n** specialization back-off for HREFK when a value flips between nil and\n** non-nil and the GC gets in the way. It also allows safely hoisting\n** HREF/HREFK across GC steps. Dead keys are only removed if a table is\n** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize.\n**\n** The trade-off is that a write barrier for tables must take the key into\n** account, too. Implicitly resurrecting the key by storing a non-nil value\n** may invalidate the incremental GC invariant.\n*/\n\n/* -- Common type definitions --------------------------------------------- */\n\n/* Types for handling bytecodes. Need this here, details in lj_bc.h. */\ntypedef uint32_t BCIns;  /* Bytecode instruction. */\ntypedef uint32_t BCPos;  /* Bytecode position. */\ntypedef uint32_t BCReg;  /* Bytecode register. */\ntypedef int32_t BCLine;  /* Bytecode line number. */\n\n/* Internal assembler functions. Never call these directly from C. */\ntypedef void (*ASMFunction)(void);\n\n/* Resizable string buffer. Need this here, details in lj_buf.h. */\n#define SBufHeader\tchar *w, *e, *b; MRef L\ntypedef struct SBuf {\n  SBufHeader;\n} SBuf;\n\n/* -- Tags and values ----------------------------------------------------- */\n\n/* Frame link. */\ntypedef union {\n  int32_t ftsz;\t\t/* Frame type and size of previous frame. */\n  MRef pcr;\t\t/* Or PC for Lua frames. */\n} FrameLink;\n\n/* Tagged value. */\ntypedef LJ_ALIGN(8) union TValue {\n  uint64_t u64;\t\t/* 64 bit pattern overlaps number. */\n  lua_Number n;\t\t/* Number object overlaps split tag/value object. */\n#if LJ_GC64\n  GCRef gcr;\t\t/* GCobj reference with tag. */\n  int64_t it64;\n  struct {\n    LJ_ENDIAN_LOHI(\n      int32_t i;\t/* Integer value. */\n    , uint32_t it;\t/* Internal object tag. Must overlap MSW of number. */\n    )\n  };\n#else\n  struct {\n    LJ_ENDIAN_LOHI(\n      union {\n\tGCRef gcr;\t/* GCobj reference (if any). */\n\tint32_t i;\t/* Integer value. */\n      };\n    , uint32_t it;\t/* Internal object tag. Must overlap MSW of number. */\n    )\n  };\n#endif\n#if LJ_FR2\n  int64_t ftsz;\t\t/* Frame type and size of previous frame, or PC. */\n#else\n  struct {\n    LJ_ENDIAN_LOHI(\n      GCRef func;\t/* Function for next frame (or dummy L). */\n    , FrameLink tp;\t/* Link to previous frame. */\n    )\n  } fr;\n#endif\n  struct {\n    LJ_ENDIAN_LOHI(\n      uint32_t lo;\t/* Lower 32 bits of number. */\n    , uint32_t hi;\t/* Upper 32 bits of number. */\n    )\n  } u32;\n} TValue;\n\ntypedef const TValue cTValue;\n\n#define tvref(r)\t(mref(r, TValue))\n\n/* More external and GCobj tags for internal objects. */\n#define LAST_TT\t\tLUA_TTHREAD\n#define LUA_TPROTO\t(LAST_TT+1)\n#define LUA_TCDATA\t(LAST_TT+2)\n\n/* Internal object tags.\n**\n** Format for 32 bit GC references (!LJ_GC64):\n**\n** Internal tags overlap the MSW of a number object (must be a double).\n** Interpreted as a double these are special NaNs. The FPU only generates\n** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available\n** for use as internal tags. Small negative numbers are used to shorten the\n** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).\n**\n**                  ---MSW---.---LSW---\n** primitive types |  itype  |         |\n** lightuserdata   |  itype  |  void * |  (32 bit platforms)\n** lightuserdata   |ffff|seg|    ofs   |  (64 bit platforms)\n** GC objects      |  itype  |  GCRef  |\n** int (LJ_DUALNUM)|  itype  |   int   |\n** number           -------double------\n**\n** Format for 64 bit GC references (LJ_GC64):\n**\n** The upper 13 bits must be 1 (0xfff8...) for a special NaN. The next\n** 4 bits hold the internal tag. The lowest 47 bits either hold a pointer,\n** a zero-extended 32 bit integer or all bits set to 1 for primitive types.\n**\n**                     ------MSW------.------LSW------\n** primitive types    |1..1|itype|1..................1|\n** GC objects         |1..1|itype|-------GCRef--------|\n** lightuserdata      |1..1|itype|seg|------ofs-------|\n** int (LJ_DUALNUM)   |1..1|itype|0..0|-----int-------|\n** number              ------------double-------------\n**\n** ORDER LJ_T\n** Primitive types nil/false/true must be first, lightuserdata next.\n** GC objects are at the end, table/userdata must be lowest.\n** Also check lj_ir.h for similar ordering constraints.\n*/\n#define LJ_TNIL\t\t\t(~0u)\n#define LJ_TFALSE\t\t(~1u)\n#define LJ_TTRUE\t\t(~2u)\n#define LJ_TLIGHTUD\t\t(~3u)\n#define LJ_TSTR\t\t\t(~4u)\n#define LJ_TUPVAL\t\t(~5u)\n#define LJ_TTHREAD\t\t(~6u)\n#define LJ_TPROTO\t\t(~7u)\n#define LJ_TFUNC\t\t(~8u)\n#define LJ_TTRACE\t\t(~9u)\n#define LJ_TCDATA\t\t(~10u)\n#define LJ_TTAB\t\t\t(~11u)\n#define LJ_TUDATA\t\t(~12u)\n/* This is just the canonical number type used in some places. */\n#define LJ_TNUMX\t\t(~13u)\n\n/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */\n#if LJ_64 && !LJ_GC64\n#define LJ_TISNUM\t\t0xfffeffffu\n#else\n#define LJ_TISNUM\t\tLJ_TNUMX\n#endif\n#define LJ_TISTRUECOND\t\tLJ_TFALSE\n#define LJ_TISPRI\t\tLJ_TTRUE\n#define LJ_TISGCV\t\t(LJ_TSTR+1)\n#define LJ_TISTABUD\t\tLJ_TTAB\n\n/* Type marker for slot holding a traversal index. Must be lightuserdata. */\n#define LJ_KEYINDEX\t\t0xfffe7fffu\n\n#if LJ_GC64\n#define LJ_GCVMASK\t\t(((uint64_t)1 << 47) - 1)\n#endif\n\n#if LJ_64\n/* To stay within 47 bits, lightuserdata is segmented. */\n#define LJ_LIGHTUD_BITS_SEG\t8\n#define LJ_LIGHTUD_BITS_LO\t(47 - LJ_LIGHTUD_BITS_SEG)\n#endif\n\n/* -- String object ------------------------------------------------------- */\n\ntypedef uint32_t StrHash;\t/* String hash value. */\ntypedef uint32_t StrID;\t\t/* String ID. */\n\n/* String object header. String payload follows. */\ntypedef struct GCstr {\n  GCHeader;\n  uint8_t reserved;\t/* Used by lexer for fast lookup of reserved words. */\n  uint8_t hashalg;\t/* Hash algorithm. */\n  StrID sid;\t\t/* Interned string ID. */\n  StrHash hash;\t\t/* Hash of string. */\n  MSize len;\t\t/* Size of string. */\n} GCstr;\n\n#define strref(r)\t(&gcref((r))->str)\n#define strdata(s)\t((const char *)((s)+1))\n#define strdatawr(s)\t((char *)((s)+1))\n#define strVdata(o)\tstrdata(strV(o))\n\n/* -- Userdata object ----------------------------------------------------- */\n\n/* Userdata object. Payload follows. */\ntypedef struct GCudata {\n  GCHeader;\n  uint8_t udtype;\t/* Userdata type. */\n  uint8_t unused2;\n  GCRef env;\t\t/* Should be at same offset in GCfunc. */\n  MSize len;\t\t/* Size of payload. */\n  GCRef metatable;\t/* Must be at same offset in GCtab. */\n  uint32_t align1;\t/* To force 8 byte alignment of the payload. */\n} GCudata;\n\n/* Userdata types. */\nenum {\n  UDTYPE_USERDATA,\t/* Regular userdata. */\n  UDTYPE_IO_FILE,\t/* I/O library FILE. */\n  UDTYPE_FFI_CLIB,\t/* FFI C library namespace. */\n  UDTYPE_BUFFER,\t/* String buffer. */\n  UDTYPE__MAX\n};\n\n#define uddata(u)\t((void *)((u)+1))\n#define sizeudata(u)\t(sizeof(struct GCudata)+(u)->len)\n\n/* -- C data object ------------------------------------------------------- */\n\n/* C data object. Payload follows. */\ntypedef struct GCcdata {\n  GCHeader;\n  uint16_t ctypeid;\t/* C type ID. */\n} GCcdata;\n\n/* Prepended to variable-sized or realigned C data objects. */\ntypedef struct GCcdataVar {\n  uint16_t offset;\t/* Offset to allocated memory (relative to GCcdata). */\n  uint16_t extra;\t/* Extra space allocated (incl. GCcdata + GCcdatav). */\n  MSize len;\t\t/* Size of payload. */\n} GCcdataVar;\n\n#define cdataptr(cd)\t((void *)((cd)+1))\n#define cdataisv(cd)\t((cd)->marked & 0x80)\n#define cdatav(cd)\t((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar)))\n#define cdatavlen(cd)\tcheck_exp(cdataisv(cd), cdatav(cd)->len)\n#define sizecdatav(cd)\t(cdatavlen(cd) + cdatav(cd)->extra)\n#define memcdatav(cd)\t((void *)((char *)(cd) - cdatav(cd)->offset))\n\n/* -- Prototype object ---------------------------------------------------- */\n\n#define SCALE_NUM_GCO\t((int32_t)sizeof(lua_Number)/sizeof(GCRef))\n#define round_nkgc(n)\t(((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1))\n\ntypedef struct GCproto {\n  GCHeader;\n  uint8_t numparams;\t/* Number of parameters. */\n  uint8_t framesize;\t/* Fixed frame size. */\n  MSize sizebc;\t\t/* Number of bytecode instructions. */\n#if LJ_GC64\n  uint32_t unused_gc64;\n#endif\n  GCRef gclist;\n  MRef k;\t\t/* Split constant array (points to the middle). */\n  MRef uv;\t\t/* Upvalue list. local slot|0x8000 or parent uv idx. */\n  MSize sizekgc;\t/* Number of collectable constants. */\n  MSize sizekn;\t\t/* Number of lua_Number constants. */\n  MSize sizept;\t\t/* Total size including colocated arrays. */\n  uint8_t sizeuv;\t/* Number of upvalues. */\n  uint8_t flags;\t/* Miscellaneous flags (see below). */\n  uint16_t trace;\t/* Anchor for chain of root traces. */\n  /* ------ The following fields are for debugging/tracebacks only ------ */\n  GCRef chunkname;\t/* Name of the chunk this function was defined in. */\n  BCLine firstline;\t/* First line of the function definition. */\n  BCLine numline;\t/* Number of lines for the function definition. */\n  MRef lineinfo;\t/* Compressed map from bytecode ins. to source line. */\n  MRef uvinfo;\t\t/* Upvalue names. */\n  MRef varinfo;\t\t/* Names and compressed extents of local variables. */\n} GCproto;\n\n/* Flags for prototype. */\n#define PROTO_CHILD\t\t0x01\t/* Has child prototypes. */\n#define PROTO_VARARG\t\t0x02\t/* Vararg function. */\n#define PROTO_FFI\t\t0x04\t/* Uses BC_KCDATA for FFI datatypes. */\n#define PROTO_NOJIT\t\t0x08\t/* JIT disabled for this function. */\n#define PROTO_ILOOP\t\t0x10\t/* Patched bytecode with ILOOP etc. */\n/* Only used during parsing. */\n#define PROTO_HAS_RETURN\t0x20\t/* Already emitted a return. */\n#define PROTO_FIXUP_RETURN\t0x40\t/* Need to fixup emitted returns. */\n/* Top bits used for counting created closures. */\n#define PROTO_CLCOUNT\t\t0x20\t/* Base of saturating 3 bit counter. */\n#define PROTO_CLC_BITS\t\t3\n#define PROTO_CLC_POLY\t\t(3*PROTO_CLCOUNT)  /* Polymorphic threshold. */\n\n#define PROTO_UV_LOCAL\t\t0x8000\t/* Upvalue for local slot. */\n#define PROTO_UV_IMMUTABLE\t0x4000\t/* Immutable upvalue. */\n\n#define proto_kgc(pt, idx) \\\n  check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \\\n\t    gcref(mref((pt)->k, GCRef)[(idx)]))\n#define proto_knumtv(pt, idx) \\\n  check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)])\n#define proto_bc(pt)\t\t((BCIns *)((char *)(pt) + sizeof(GCproto)))\n#define proto_bcpos(pt, pc)\t((BCPos)((pc) - proto_bc(pt)))\n#define proto_uv(pt)\t\t(mref((pt)->uv, uint16_t))\n\n#define proto_chunkname(pt)\t(strref((pt)->chunkname))\n#define proto_chunknamestr(pt)\t(strdata(proto_chunkname((pt))))\n#define proto_lineinfo(pt)\t(mref((pt)->lineinfo, const void))\n#define proto_uvinfo(pt)\t(mref((pt)->uvinfo, const uint8_t))\n#define proto_varinfo(pt)\t(mref((pt)->varinfo, const uint8_t))\n\n/* -- Upvalue object ------------------------------------------------------ */\n\ntypedef struct GCupval {\n  GCHeader;\n  uint8_t closed;\t/* Set if closed (i.e. uv->v == &uv->u.value). */\n  uint8_t immutable;\t/* Immutable value. */\n  union {\n    TValue tv;\t\t/* If closed: the value itself. */\n    struct {\t\t/* If open: double linked list, anchored at thread. */\n      GCRef prev;\n      GCRef next;\n    };\n  };\n  MRef v;\t\t/* Points to stack slot (open) or above (closed). */\n  uint32_t dhash;\t/* Disambiguation hash: dh1 != dh2 => cannot alias. */\n} GCupval;\n\n#define uvprev(uv_)\t(&gcref((uv_)->prev)->uv)\n#define uvnext(uv_)\t(&gcref((uv_)->next)->uv)\n#define uvval(uv_)\t(mref((uv_)->v, TValue))\n\n/* -- Function object (closures) ------------------------------------------ */\n\n/* Common header for functions. env should be at same offset in GCudata. */\n#define GCfuncHeader \\\n  GCHeader; uint8_t ffid; uint8_t nupvalues; \\\n  GCRef env; GCRef gclist; MRef pc\n\ntypedef struct GCfuncC {\n  GCfuncHeader;\n  lua_CFunction f;\t/* C function to be called. */\n  TValue upvalue[1];\t/* Array of upvalues (TValue). */\n} GCfuncC;\n\ntypedef struct GCfuncL {\n  GCfuncHeader;\n  GCRef uvptr[1];\t/* Array of _pointers_ to upvalue objects (GCupval). */\n} GCfuncL;\n\ntypedef union GCfunc {\n  GCfuncC c;\n  GCfuncL l;\n} GCfunc;\n\n#define FF_LUA\t\t0\n#define FF_C\t\t1\n#define isluafunc(fn)\t((fn)->c.ffid == FF_LUA)\n#define iscfunc(fn)\t((fn)->c.ffid == FF_C)\n#define isffunc(fn)\t((fn)->c.ffid > FF_C)\n#define funcproto(fn) \\\n  check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))\n#define sizeCfunc(n)\t(sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))\n#define sizeLfunc(n)\t(sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))\n\n/* -- Table object -------------------------------------------------------- */\n\n/* Hash node. */\ntypedef struct Node {\n  TValue val;\t\t/* Value object. Must be first field. */\n  TValue key;\t\t/* Key object. */\n  MRef next;\t\t/* Hash chain. */\n#if !LJ_GC64\n  MRef freetop;\t\t/* Top of free elements (stored in t->node[0]). */\n#endif\n} Node;\n\nLJ_STATIC_ASSERT(offsetof(Node, val) == 0);\n\ntypedef struct GCtab {\n  GCHeader;\n  uint8_t nomm;\t\t/* Negative cache for fast metamethods. */\n  int8_t colo;\t\t/* Array colocation. */\n  MRef array;\t\t/* Array part. */\n  GCRef gclist;\n  GCRef metatable;\t/* Must be at same offset in GCudata. */\n  MRef node;\t\t/* Hash part. */\n  uint32_t asize;\t/* Size of array part (keys [0, asize-1]). */\n  uint32_t hmask;\t/* Hash part mask (size of hash part - 1). */\n#if LJ_GC64\n  MRef freetop;\t\t/* Top of free elements. */\n#endif\n} GCtab;\n\n#define sizetabcolo(n)\t((n)*sizeof(TValue) + sizeof(GCtab))\n#define tabref(r)\t(&gcref((r))->tab)\n#define noderef(r)\t(mref((r), Node))\n#define nextnode(n)\t(mref((n)->next, Node))\n#if LJ_GC64\n#define getfreetop(t, n)\t(noderef((t)->freetop))\n#define setfreetop(t, n, v)\t(setmref((t)->freetop, (v)))\n#else\n#define getfreetop(t, n)\t(noderef((n)->freetop))\n#define setfreetop(t, n, v)\t(setmref((n)->freetop, (v)))\n#endif\n\n/* -- State objects ------------------------------------------------------- */\n\n/* VM states. */\nenum {\n  LJ_VMST_INTERP,\t/* Interpreter. */\n  LJ_VMST_C,\t\t/* C function. */\n  LJ_VMST_GC,\t\t/* Garbage collector. */\n  LJ_VMST_EXIT,\t\t/* Trace exit handler. */\n  LJ_VMST_RECORD,\t/* Trace recorder. */\n  LJ_VMST_OPT,\t\t/* Optimizer. */\n  LJ_VMST_ASM,\t\t/* Assembler. */\n  LJ_VMST__MAX\n};\n\n#define setvmstate(g, st)\t((g)->vmstate = ~LJ_VMST_##st)\n\n/* Metamethods. ORDER MM */\n#ifdef LJ_HASFFI\n#define MMDEF_FFI(_) _(new)\n#else\n#define MMDEF_FFI(_)\n#endif\n\n#if LJ_52 || LJ_HASFFI\n#define MMDEF_PAIRS(_) _(pairs) _(ipairs)\n#else\n#define MMDEF_PAIRS(_)\n#define MM_pairs\t255\n#define MM_ipairs\t255\n#endif\n\n#define MMDEF(_) \\\n  _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \\\n  /* Only the above (fast) metamethods are negative cached (max. 8). */ \\\n  _(lt) _(le) _(concat) _(call) \\\n  /* The following must be in ORDER ARITH. */ \\\n  _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \\\n  /* The following are used in the standard libraries. */ \\\n  _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_)\n\ntypedef enum {\n#define MMENUM(name)\tMM_##name,\nMMDEF(MMENUM)\n#undef MMENUM\n  MM__MAX,\n  MM____ = MM__MAX,\n  MM_FAST = MM_len\n} MMS;\n\n/* GC root IDs. */\ntypedef enum {\n  GCROOT_MMNAME,\t/* Metamethod names. */\n  GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,\n  GCROOT_BASEMT,\t/* Metatables for base types. */\n  GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,\n  GCROOT_IO_INPUT,\t/* Userdata for default I/O input file. */\n  GCROOT_IO_OUTPUT,\t/* Userdata for default I/O output file. */\n  GCROOT_MAX\n} GCRootID;\n\n#define basemt_it(g, it)\t((g)->gcroot[GCROOT_BASEMT+~(it)])\n#define basemt_obj(g, o)\t((g)->gcroot[GCROOT_BASEMT+itypemap(o)])\n#define mmname_str(g, mm)\t(strref((g)->gcroot[GCROOT_MMNAME+(mm)]))\n\n/* Garbage collector state. */\ntypedef struct GCState {\n  GCSize total;\t\t/* Memory currently allocated. */\n  GCSize threshold;\t/* Memory threshold. */\n  uint8_t currentwhite;\t/* Current white color. */\n  uint8_t state;\t/* GC state. */\n  uint8_t nocdatafin;\t/* No cdata finalizer called. */\n#if LJ_64\n  uint8_t lightudnum;\t/* Number of lightuserdata segments - 1. */\n#else\n  uint8_t unused1;\n#endif\n  MSize sweepstr;\t/* Sweep position in string table. */\n  GCRef root;\t\t/* List of all collectable objects. */\n  MRef sweep;\t\t/* Sweep position in root list. */\n  GCRef gray;\t\t/* List of gray objects. */\n  GCRef grayagain;\t/* List of objects for atomic traversal. */\n  GCRef weak;\t\t/* List of weak tables (to be cleared). */\n  GCRef mmudata;\t/* List of userdata (to be finalized). */\n  GCSize debt;\t\t/* Debt (how much GC is behind schedule). */\n  GCSize estimate;\t/* Estimate of memory actually in use. */\n  MSize stepmul;\t/* Incremental GC step granularity. */\n  MSize pause;\t\t/* Pause between successive GC cycles. */\n#if LJ_64\n  MRef lightudseg;\t/* Upper bits of lightuserdata segments. */\n#endif\n} GCState;\n\n/* String interning state. */\ntypedef struct StrInternState {\n  GCRef *tab;\t\t/* String hash table anchors. */\n  MSize mask;\t\t/* String hash mask (size of hash table - 1). */\n  MSize num;\t\t/* Number of strings in hash table. */\n  StrID id;\t\t/* Next string ID. */\n  uint8_t idreseed;\t/* String ID reseed counter. */\n  uint8_t second;\t/* String interning table uses secondary hashing. */\n  uint8_t unused1;\n  uint8_t unused2;\n  LJ_ALIGN(8) uint64_t seed;\t/* Random string seed. */\n} StrInternState;\n\n/* Global state, shared by all threads of a Lua universe. */\ntypedef struct global_State {\n  lua_Alloc allocf;\t/* Memory allocator. */\n  void *allocd;\t\t/* Memory allocator data. */\n  GCState gc;\t\t/* Garbage collector. */\n  GCstr strempty;\t/* Empty string. */\n  uint8_t stremptyz;\t/* Zero terminator of empty string. */\n  uint8_t hookmask;\t/* Hook mask. */\n  uint8_t dispatchmode;\t/* Dispatch mode. */\n  uint8_t vmevmask;\t/* VM event mask. */\n  StrInternState str;\t/* String interning. */\n  volatile int32_t vmstate;  /* VM state or current JIT code trace number. */\n  GCRef mainthref;\t/* Link to main thread. */\n  SBuf tmpbuf;\t\t/* Temporary string buffer. */\n  TValue tmptv, tmptv2;\t/* Temporary TValues. */\n  Node nilnode;\t\t/* Fallback 1-element hash part (nil key and value). */\n  TValue registrytv;\t/* Anchor for registry. */\n  GCupval uvhead;\t/* Head of double-linked list of all open upvalues. */\n  int32_t hookcount;\t/* Instruction hook countdown. */\n  int32_t hookcstart;\t/* Start count for instruction hook counter. */\n  lua_Hook hookf;\t/* Hook function. */\n  lua_CFunction wrapf;\t/* Wrapper for C function calls. */\n  lua_CFunction panic;\t/* Called as a last resort for errors. */\n  BCIns bc_cfunc_int;\t/* Bytecode for internal C function calls. */\n  BCIns bc_cfunc_ext;\t/* Bytecode for external C function calls. */\n  GCRef cur_L;\t\t/* Currently executing lua_State. */\n  MRef jit_base;\t/* Current JIT code L->base or NULL. */\n  MRef ctype_state;\t/* Pointer to C type state. */\n  PRNGState prng;\t/* Global PRNG state. */\n  GCRef gcroot[GCROOT_MAX];  /* GC roots. */\n} global_State;\n\n#define mainthread(g)\t(&gcref(g->mainthref)->th)\n#define niltv(L) \\\n  check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val)\n#define niltvg(g) \\\n  check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val)\n\n/* Hook management. Hook event masks are defined in lua.h. */\n#define HOOK_EVENTMASK\t\t0x0f\n#define HOOK_ACTIVE\t\t0x10\n#define HOOK_ACTIVE_SHIFT\t4\n#define HOOK_VMEVENT\t\t0x20\n#define HOOK_GC\t\t\t0x40\n#define HOOK_PROFILE\t\t0x80\n#define hook_active(g)\t\t((g)->hookmask & HOOK_ACTIVE)\n#define hook_enter(g)\t\t((g)->hookmask |= HOOK_ACTIVE)\n#define hook_entergc(g) \\\n  ((g)->hookmask = ((g)->hookmask | (HOOK_ACTIVE|HOOK_GC)) & ~HOOK_PROFILE)\n#define hook_vmevent(g)\t\t((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))\n#define hook_leave(g)\t\t((g)->hookmask &= ~HOOK_ACTIVE)\n#define hook_save(g)\t\t((g)->hookmask & ~HOOK_EVENTMASK)\n#define hook_restore(g, h) \\\n  ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h))\n\n/* Per-thread state object. */\nstruct lua_State {\n  GCHeader;\n  uint8_t dummy_ffid;\t/* Fake FF_C for curr_funcisL() on dummy frames. */\n  uint8_t status;\t/* Thread status. */\n  MRef glref;\t\t/* Link to global state. */\n  GCRef gclist;\t\t/* GC chain. */\n  TValue *base;\t\t/* Base of currently executing function. */\n  TValue *top;\t\t/* First free slot in the stack. */\n  MRef maxstack;\t/* Last free slot in the stack. */\n  MRef stack;\t\t/* Stack base. */\n  GCRef openupval;\t/* List of open upvalues in the stack. */\n  GCRef env;\t\t/* Thread environment (table of globals). */\n  void *cframe;\t\t/* End of C stack frame chain. */\n  MSize stacksize;\t/* True stack size (incl. LJ_STACK_EXTRA). */\n};\n\n#define G(L)\t\t\t(mref(L->glref, global_State))\n#define registry(L)\t\t(&G(L)->registrytv)\n\n/* Macros to access the currently executing (Lua) function. */\n#if LJ_GC64\n#define curr_func(L)\t\t(&gcval(L->base-2)->fn)\n#elif LJ_FR2\n#define curr_func(L)\t\t(&gcref((L->base-2)->gcr)->fn)\n#else\n#define curr_func(L)\t\t(&gcref((L->base-1)->fr.func)->fn)\n#endif\n#define curr_funcisL(L)\t\t(isluafunc(curr_func(L)))\n#define curr_proto(L)\t\t(funcproto(curr_func(L)))\n#define curr_topL(L)\t\t(L->base + curr_proto(L)->framesize)\n#define curr_top(L)\t\t(curr_funcisL(L) ? curr_topL(L) : L->top)\n\n#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)\nLJ_FUNC_NORET void lj_assert_fail(global_State *g, const char *file, int line,\n\t\t\t\t  const char *func, const char *fmt, ...);\n#endif\n\n/* -- GC object definition and conversions -------------------------------- */\n\n/* GC header for generic access to common fields of GC objects. */\ntypedef struct GChead {\n  GCHeader;\n  uint8_t unused1;\n  uint8_t unused2;\n  GCRef env;\n  GCRef gclist;\n  GCRef metatable;\n} GChead;\n\n/* The env field SHOULD be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env));\nLJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env));\n\n/* The metatable field MUST be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable));\nLJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable));\n\n/* The gclist field MUST be at the same offset for all GC objects. */\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist));\nLJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist));\n\ntypedef union GCobj {\n  GChead gch;\n  GCstr str;\n  GCupval uv;\n  lua_State th;\n  GCproto pt;\n  GCfunc fn;\n  GCcdata cd;\n  GCtab tab;\n  GCudata ud;\n} GCobj;\n\n/* Macros to convert a GCobj pointer into a specific value. */\n#define gco2str(o)\tcheck_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str)\n#define gco2uv(o)\tcheck_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv)\n#define gco2th(o)\tcheck_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th)\n#define gco2pt(o)\tcheck_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt)\n#define gco2func(o)\tcheck_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn)\n#define gco2cd(o)\tcheck_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd)\n#define gco2tab(o)\tcheck_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab)\n#define gco2ud(o)\tcheck_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)\n\n/* Macro to convert any collectable object into a GCobj pointer. */\n#define obj2gco(v)\t((GCobj *)(v))\n\n/* -- TValue getters/setters ---------------------------------------------- */\n\n/* Macros to test types. */\n#if LJ_GC64\n#define itype(o)\t((uint32_t)((o)->it64 >> 47))\n#define tvisnil(o)\t((o)->it64 == -1)\n#else\n#define itype(o)\t((o)->it)\n#define tvisnil(o)\t(itype(o) == LJ_TNIL)\n#endif\n#define tvisfalse(o)\t(itype(o) == LJ_TFALSE)\n#define tvistrue(o)\t(itype(o) == LJ_TTRUE)\n#define tvisbool(o)\t(tvisfalse(o) || tvistrue(o))\n#if LJ_64 && !LJ_GC64\n#define tvislightud(o)\t(((int32_t)itype(o) >> 15) == -2)\n#else\n#define tvislightud(o)\t(itype(o) == LJ_TLIGHTUD)\n#endif\n#define tvisstr(o)\t(itype(o) == LJ_TSTR)\n#define tvisfunc(o)\t(itype(o) == LJ_TFUNC)\n#define tvisthread(o)\t(itype(o) == LJ_TTHREAD)\n#define tvisproto(o)\t(itype(o) == LJ_TPROTO)\n#define tviscdata(o)\t(itype(o) == LJ_TCDATA)\n#define tvistab(o)\t(itype(o) == LJ_TTAB)\n#define tvisudata(o)\t(itype(o) == LJ_TUDATA)\n#define tvisnumber(o)\t(itype(o) <= LJ_TISNUM)\n#define tvisint(o)\t(LJ_DUALNUM && itype(o) == LJ_TISNUM)\n#define tvisnum(o)\t(itype(o) < LJ_TISNUM)\n\n#define tvistruecond(o)\t(itype(o) < LJ_TISTRUECOND)\n#define tvispri(o)\t(itype(o) >= LJ_TISPRI)\n#define tvistabud(o)\t(itype(o) <= LJ_TISTABUD)  /* && !tvisnum() */\n#define tvisgcv(o)\t((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))\n\n/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */\n#define tvisnan(o)\t((o)->n != (o)->n)\n#if LJ_64\n#define tviszero(o)\t(((o)->u64 << 1) == 0)\n#else\n#define tviszero(o)\t(((o)->u32.lo | ((o)->u32.hi << 1)) == 0)\n#endif\n#define tvispzero(o)\t((o)->u64 == 0)\n#define tvismzero(o)\t((o)->u64 == U64x(80000000,00000000))\n#define tvispone(o)\t((o)->u64 == U64x(3ff00000,00000000))\n#define rawnumequal(o1, o2)\t((o1)->u64 == (o2)->u64)\n\n/* Macros to convert type ids. */\n#if LJ_64 && !LJ_GC64\n#define itypemap(o) \\\n  (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))\n#else\n#define itypemap(o)\t(tvisnumber(o) ? ~LJ_TNUMX : ~itype(o))\n#endif\n\n/* Macros to get tagged values. */\n#if LJ_GC64\n#define gcval(o)\t((GCobj *)(gcrefu((o)->gcr) & LJ_GCVMASK))\n#else\n#define gcval(o)\t(gcref((o)->gcr))\n#endif\n#define boolV(o)\tcheck_exp(tvisbool(o), (LJ_TFALSE - itype(o)))\n#if LJ_64\n#define lightudseg(u) \\\n  (((u) >> LJ_LIGHTUD_BITS_LO) & ((1 << LJ_LIGHTUD_BITS_SEG)-1))\n#define lightudlo(u) \\\n  ((u) & (((uint64_t)1 << LJ_LIGHTUD_BITS_LO) - 1))\n#define lightudup(p) \\\n  ((uint32_t)(((p) >> LJ_LIGHTUD_BITS_LO) << (LJ_LIGHTUD_BITS_LO-32)))\nstatic LJ_AINLINE void *lightudV(global_State *g, cTValue *o)\n{\n  uint64_t u = o->u64;\n  uint64_t seg = lightudseg(u);\n  uint32_t *segmap = mref(g->gc.lightudseg, uint32_t);\n  lj_assertG(tvislightud(o), \"lightuserdata expected\");\n  lj_assertG(seg <= g->gc.lightudnum, \"bad lightuserdata segment %d\", seg);\n  return (void *)(((uint64_t)segmap[seg] << 32) | lightudlo(u));\n}\n#else\n#define lightudV(g, o)\tcheck_exp(tvislightud(o), gcrefp((o)->gcr, void))\n#endif\n#define gcV(o)\t\tcheck_exp(tvisgcv(o), gcval(o))\n#define strV(o)\t\tcheck_exp(tvisstr(o), &gcval(o)->str)\n#define funcV(o)\tcheck_exp(tvisfunc(o), &gcval(o)->fn)\n#define threadV(o)\tcheck_exp(tvisthread(o), &gcval(o)->th)\n#define protoV(o)\tcheck_exp(tvisproto(o), &gcval(o)->pt)\n#define cdataV(o)\tcheck_exp(tviscdata(o), &gcval(o)->cd)\n#define tabV(o)\t\tcheck_exp(tvistab(o), &gcval(o)->tab)\n#define udataV(o)\tcheck_exp(tvisudata(o), &gcval(o)->ud)\n#define numV(o)\t\tcheck_exp(tvisnum(o), (o)->n)\n#define intV(o)\t\tcheck_exp(tvisint(o), (int32_t)(o)->i)\n\n/* Macros to set tagged values. */\n#if LJ_GC64\n#define setitype(o, i)\t\t((o)->it = ((i) << 15))\n#define setnilV(o)\t\t((o)->it64 = -1)\n#define setpriV(o, x)\t\t((o)->it64 = (int64_t)~((uint64_t)~(x)<<47))\n#define setboolV(o, x)\t\t((o)->it64 = (int64_t)~((uint64_t)((x)+1)<<47))\n#else\n#define setitype(o, i)\t\t((o)->it = (i))\n#define setnilV(o)\t\t((o)->it = LJ_TNIL)\n#define setboolV(o, x)\t\t((o)->it = LJ_TFALSE-(uint32_t)(x))\n#define setpriV(o, i)\t\t(setitype((o), (i)))\n#endif\n\nstatic LJ_AINLINE void setrawlightudV(TValue *o, void *p)\n{\n#if LJ_GC64\n  o->u64 = (uint64_t)p | (((uint64_t)LJ_TLIGHTUD) << 47);\n#elif LJ_64\n  o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);\n#else\n  setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);\n#endif\n}\n\n#if LJ_FR2 || LJ_32\n#define contptr(f)\t\t((void *)(f))\n#define setcont(o, f)\t\t((o)->u64 = (uint64_t)(uintptr_t)contptr(f))\n#else\n#define contptr(f) \\\n  ((void *)(uintptr_t)(uint32_t)((intptr_t)(f) - (intptr_t)lj_vm_asm_begin))\n#define setcont(o, f) \\\n  ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)\n#endif\n\nstatic LJ_AINLINE void checklivetv(lua_State *L, TValue *o, const char *msg)\n{\n  UNUSED(L); UNUSED(o); UNUSED(msg);\n#if LUA_USE_ASSERT\n  if (tvisgcv(o)) {\n    lj_assertL(~itype(o) == gcval(o)->gch.gct,\n\t       \"mismatch of TValue type %d vs GC type %d\",\n\t       ~itype(o), gcval(o)->gch.gct);\n    /* Copy of isdead check from lj_gc.h to avoid circular include. */\n    lj_assertL(!(gcval(o)->gch.marked & (G(L)->gc.currentwhite ^ 3) & 3), msg);\n  }\n#endif\n}\n\nstatic LJ_AINLINE void setgcVraw(TValue *o, GCobj *v, uint32_t itype)\n{\n#if LJ_GC64\n  setgcreft(o->gcr, v, itype);\n#else\n  setgcref(o->gcr, v); setitype(o, itype);\n#endif\n}\n\nstatic LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t it)\n{\n  setgcVraw(o, v, it);\n  checklivetv(L, o, \"store to dead GC object\");\n}\n\n#define define_setV(name, type, tag) \\\nstatic LJ_AINLINE void name(lua_State *L, TValue *o, const type *v) \\\n{ \\\n  setgcV(L, o, obj2gco(v), tag); \\\n}\ndefine_setV(setstrV, GCstr, LJ_TSTR)\ndefine_setV(setthreadV, lua_State, LJ_TTHREAD)\ndefine_setV(setprotoV, GCproto, LJ_TPROTO)\ndefine_setV(setfuncV, GCfunc, LJ_TFUNC)\ndefine_setV(setcdataV, GCcdata, LJ_TCDATA)\ndefine_setV(settabV, GCtab, LJ_TTAB)\ndefine_setV(setudataV, GCudata, LJ_TUDATA)\n\n#define setnumV(o, x)\t\t((o)->n = (x))\n#define setnanV(o)\t\t((o)->u64 = U64x(fff80000,00000000))\n#define setpinfV(o)\t\t((o)->u64 = U64x(7ff00000,00000000))\n#define setminfV(o)\t\t((o)->u64 = U64x(fff00000,00000000))\n\nstatic LJ_AINLINE void setintV(TValue *o, int32_t i)\n{\n#if LJ_DUALNUM\n  o->i = (uint32_t)i; setitype(o, LJ_TISNUM);\n#else\n  o->n = (lua_Number)i;\n#endif\n}\n\nstatic LJ_AINLINE void setint64V(TValue *o, int64_t i)\n{\n  if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))\n    setintV(o, (int32_t)i);\n  else\n    setnumV(o, (lua_Number)i);\n}\n\n#if LJ_64\n#define setintptrV(o, i)\tsetint64V((o), (i))\n#else\n#define setintptrV(o, i)\tsetintV((o), (i))\n#endif\n\n/* Copy tagged values. */\nstatic LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)\n{\n  *o1 = *o2;\n  checklivetv(L, o1, \"copy of dead GC object\");\n}\n\n/* -- Number to integer conversion ---------------------------------------- */\n\n#if LJ_SOFTFP\nLJ_ASMF int32_t lj_vm_tobit(double x);\n#if LJ_TARGET_MIPS64\nLJ_ASMF int32_t lj_vm_tointg(double x);\n#endif\n#endif\n\nstatic LJ_AINLINE int32_t lj_num2bit(lua_Number n)\n{\n#if LJ_SOFTFP\n  return lj_vm_tobit(n);\n#else\n  TValue o;\n  o.n = n + 6755399441055744.0;  /* 2^52 + 2^51 */\n  return (int32_t)o.u32.lo;\n#endif\n}\n\n#define lj_num2int(n)   ((int32_t)(n))\n\n/*\n** This must match the JIT backend behavior. In particular for archs\n** that don't have a common hardware instruction for this conversion.\n** Note that signed FP to unsigned int conversions have an undefined\n** result and should never be relied upon in portable FFI code.\n** See also: C99 or C11 standard, 6.3.1.4, footnote of (1).\n*/\nstatic LJ_AINLINE uint64_t lj_num2u64(lua_Number n)\n{\n#if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS\n  int64_t i = (int64_t)n;\n  if (i < 0) i = (int64_t)(n - 18446744073709551616.0);\n  return (uint64_t)i;\n#else\n  return (uint64_t)n;\n#endif\n}\n\nstatic LJ_AINLINE int32_t numberVint(cTValue *o)\n{\n  if (LJ_LIKELY(tvisint(o)))\n    return intV(o);\n  else\n    return lj_num2int(numV(o));\n}\n\nstatic LJ_AINLINE lua_Number numberVnum(cTValue *o)\n{\n  if (LJ_UNLIKELY(tvisint(o)))\n    return (lua_Number)intV(o);\n  else\n    return numV(o);\n}\n\n/* -- Miscellaneous object handling --------------------------------------- */\n\n/* Names and maps for internal and external object tags. */\nLJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1];\nLJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];\n\n#define lj_typename(o)\t(lj_obj_itypename[itypemap(o)])\n\n/* Compare two objects without calling metamethods. */\nLJ_FUNC int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2);\nLJ_FUNC const void * LJ_FASTCALL lj_obj_ptr(global_State *g, cTValue *o);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_dce.c",
    "content": "/*\n** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_dce_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Scan through all snapshots and mark all referenced instructions. */\nstatic void dce_marksnap(jit_State *J)\n{\n  SnapNo i, nsnap = J->cur.nsnap;\n  for (i = 0; i < nsnap; i++) {\n    SnapShot *snap = &J->cur.snap[i];\n    SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n    MSize n, nent = snap->nent;\n    for (n = 0; n < nent; n++) {\n      IRRef ref = snap_ref(map[n]);\n      if (ref >= REF_FIRST)\n\tirt_setmark(IR(ref)->t);\n    }\n  }\n}\n\n/* Backwards propagate marks. Replace unused instructions with NOPs. */\nstatic void dce_propagate(jit_State *J)\n{\n  IRRef1 *pchain[IR__MAX];\n  IRRef ins;\n  uint32_t i;\n  for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i];\n  for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) {\n    IRIns *ir = IR(ins);\n    if (irt_ismarked(ir->t)) {\n      irt_clearmark(ir->t);\n      pchain[ir->o] = &ir->prev;\n    } else if (!ir_sideeff(ir)) {\n      *pchain[ir->o] = ir->prev;  /* Reroute original instruction chain. */\n      lj_ir_nop(ir);\n      continue;\n    }\n    if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);\n    if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);\n  }\n}\n\n/* Dead Code Elimination.\n**\n** First backpropagate marks for all used instructions. Then replace\n** the unused ones with a NOP. Note that compressing the IR to eliminate\n** the NOPs does not pay off.\n*/\nvoid lj_opt_dce(jit_State *J)\n{\n  if ((J->flags & JIT_F_OPT_DCE)) {\n    dce_marksnap(J);\n    dce_propagate(J);\n    memset(J->bpropcache, 0, sizeof(J->bpropcache));  /* Invalidate cache. */\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_fold.c",
    "content": "/*\n** FOLD: Constant Folding, Algebraic Simplifications and Reassociation.\n** ABCelim: Array Bounds Check Elimination.\n** CSE: Common-Subexpression Elimination.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_fold_c\n#define LUA_CORE\n\n#include <math.h>\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_carith.h\"\n#endif\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n#include \"lj_strfmt.h\"\n\n/* Here's a short description how the FOLD engine processes instructions:\n**\n** The FOLD engine receives a single instruction stored in fins (J->fold.ins).\n** The instruction and its operands are used to select matching fold rules.\n** These are applied iteratively until a fixed point is reached.\n**\n** The 8 bit opcode of the instruction itself plus the opcodes of the\n** two instructions referenced by its operands form a 24 bit key\n** 'ins left right' (unused operands -> 0, literals -> lowest 8 bits).\n**\n** This key is used for partial matching against the fold rules. The\n** left/right operand fields of the key are successively masked with\n** the 'any' wildcard, from most specific to least specific:\n**\n**   ins left right\n**   ins any  right\n**   ins left any\n**   ins any  any\n**\n** The masked key is used to lookup a matching fold rule in a semi-perfect\n** hash table. If a matching rule is found, the related fold function is run.\n** Multiple rules can share the same fold function. A fold rule may return\n** one of several special values:\n**\n** - NEXTFOLD means no folding was applied, because an additional test\n**   inside the fold function failed. Matching continues against less\n**   specific fold rules. Finally the instruction is passed on to CSE.\n**\n** - RETRYFOLD means the instruction was modified in-place. Folding is\n**   retried as if this instruction had just been received.\n**\n** All other return values are terminal actions -- no further folding is\n** applied:\n**\n** - INTFOLD(i) returns a reference to the integer constant i.\n**\n** - LEFTFOLD and RIGHTFOLD return the left/right operand reference\n**   without emitting an instruction.\n**\n** - CSEFOLD and EMITFOLD pass the instruction directly to CSE or emit\n**   it without passing through any further optimizations.\n**\n** - FAILFOLD, DROPFOLD and CONDFOLD only apply to instructions which have\n**   no result (e.g. guarded assertions): FAILFOLD means the guard would\n**   always fail, i.e. the current trace is pointless. DROPFOLD means\n**   the guard is always true and has been eliminated. CONDFOLD is a\n**   shortcut for FAILFOLD + cond (i.e. drop if true, otherwise fail).\n**\n** - Any other return value is interpreted as an IRRef or TRef. This\n**   can be a reference to an existing or a newly created instruction.\n**   Only the least-significant 16 bits (IRRef1) are used to form a TRef\n**   which is finally returned to the caller.\n**\n** The FOLD engine receives instructions both from the trace recorder and\n** substituted instructions from LOOP unrolling. This means all types\n** of instructions may end up here, even though the recorder bypasses\n** FOLD in some cases. Thus all loads, stores and allocations must have\n** an any/any rule to avoid being passed on to CSE.\n**\n** Carefully read the following requirements before adding or modifying\n** any fold rules:\n**\n** Requirement #1: All fold rules must preserve their destination type.\n**\n** Consistently use INTFOLD() (KINT result) or lj_ir_knum() (KNUM result).\n** Never use lj_ir_knumint() which can have either a KINT or KNUM result.\n**\n** Requirement #2: Fold rules should not create *new* instructions which\n** reference operands *across* PHIs.\n**\n** E.g. a RETRYFOLD with 'fins->op1 = fleft->op1' is invalid if the\n** left operand is a PHI. Then fleft->op1 would point across the PHI\n** frontier to an invariant instruction. Adding a PHI for this instruction\n** would be counterproductive. The solution is to add a barrier which\n** prevents folding across PHIs, i.e. 'PHIBARRIER(fleft)' in this case.\n** The only exception is for recurrences with high latencies like\n** repeated int->num->int conversions.\n**\n** One could relax this condition a bit if the referenced instruction is\n** a PHI, too. But this often leads to worse code due to excessive\n** register shuffling.\n**\n** Note: returning *existing* instructions (e.g. LEFTFOLD) is ok, though.\n** Even returning fleft->op1 would be ok, because a new PHI will added,\n** if needed. But again, this leads to excessive register shuffling and\n** should be avoided.\n**\n** Requirement #3: The set of all fold rules must be monotonic to guarantee\n** termination.\n**\n** The goal is optimization, so one primarily wants to add strength-reducing\n** rules. This means eliminating an instruction or replacing an instruction\n** with one or more simpler instructions. Don't add fold rules which point\n** into the other direction.\n**\n** Some rules (like commutativity) do not directly reduce the strength of\n** an instruction, but enable other fold rules (e.g. by moving constants\n** to the right operand). These rules must be made unidirectional to avoid\n** cycles.\n**\n** Rule of thumb: the trace recorder expands the IR and FOLD shrinks it.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n#define fins\t\t(&J->fold.ins)\n#define fleft\t\t(J->fold.left)\n#define fright\t\t(J->fold.right)\n#define knumleft\t(ir_knum(fleft)->n)\n#define knumright\t(ir_knum(fright)->n)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Fold function type. Fastcall on x86 significantly reduces their size. */\ntypedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J);\n\n/* Macros for the fold specs, so buildvm can recognize them. */\n#define LJFOLD(x)\n#define LJFOLDX(x)\n#define LJFOLDF(name)\tstatic TRef LJ_FASTCALL fold_##name(jit_State *J)\n/* Note: They must be at the start of a line or buildvm ignores them! */\n\n/* Barrier to prevent using operands across PHIs. */\n#define PHIBARRIER(ir)\tif (irt_isphi((ir)->t)) return NEXTFOLD\n\n/* Barrier to prevent folding across a GC step.\n** GC steps can only happen at the head of a trace and at LOOP.\n** And the GC is only driven forward if there's at least one allocation.\n*/\n#define gcstep_barrier(J, ref) \\\n  ((ref) < J->chain[IR_LOOP] && \\\n   (J->chain[IR_SNEW] || J->chain[IR_XSNEW] || \\\n    J->chain[IR_TNEW] || J->chain[IR_TDUP] || \\\n    J->chain[IR_CNEW] || J->chain[IR_CNEWI] || \\\n    J->chain[IR_BUFSTR] || J->chain[IR_TOSTR] || J->chain[IR_CALLA]))\n\n/* -- Constant folding for FP numbers ------------------------------------- */\n\nLJFOLD(ADD KNUM KNUM)\nLJFOLD(SUB KNUM KNUM)\nLJFOLD(MUL KNUM KNUM)\nLJFOLD(DIV KNUM KNUM)\nLJFOLD(LDEXP KNUM KNUM)\nLJFOLD(MIN KNUM KNUM)\nLJFOLD(MAX KNUM KNUM)\nLJFOLDF(kfold_numarith)\n{\n  lua_Number a = knumleft;\n  lua_Number b = knumright;\n  lua_Number y = lj_vm_foldarith(a, b, fins->o - IR_ADD);\n  return lj_ir_knum(J, y);\n}\n\nLJFOLD(NEG KNUM FLOAD)\nLJFOLD(ABS KNUM FLOAD)\nLJFOLDF(kfold_numabsneg)\n{\n  lua_Number a = knumleft;\n  lua_Number y = lj_vm_foldarith(a, a, fins->o - IR_ADD);\n  return lj_ir_knum(J, y);\n}\n\nLJFOLD(LDEXP KNUM KINT)\nLJFOLDF(kfold_ldexp)\n{\n#if LJ_TARGET_X86ORX64\n  UNUSED(J);\n  return NEXTFOLD;\n#else\n  return lj_ir_knum(J, ldexp(knumleft, fright->i));\n#endif\n}\n\nLJFOLD(FPMATH KNUM any)\nLJFOLDF(kfold_fpmath)\n{\n  lua_Number a = knumleft;\n  lua_Number y = lj_vm_foldfpm(a, fins->op2);\n  return lj_ir_knum(J, y);\n}\n\nLJFOLD(CALLN KNUM any)\nLJFOLDF(kfold_fpcall1)\n{\n  const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n  if (CCI_TYPE(ci) == IRT_NUM) {\n    double y = ((double (*)(double))ci->func)(knumleft);\n    return lj_ir_knum(J, y);\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CALLN CARG IRCALL_atan2)\nLJFOLDF(kfold_fpcall2)\n{\n  if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) {\n    const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n    double a = ir_knum(IR(fleft->op1))->n;\n    double b = ir_knum(IR(fleft->op2))->n;\n    double y = ((double (*)(double, double))ci->func)(a, b);\n    return lj_ir_knum(J, y);\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(POW KNUM KINT)\nLJFOLD(POW KNUM KNUM)\nLJFOLDF(kfold_numpow)\n{\n  lua_Number a = knumleft;\n  lua_Number b = fright->o == IR_KINT ? (lua_Number)fright->i : knumright;\n  lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD);\n  return lj_ir_knum(J, y);\n}\n\n/* Must not use kfold_kref for numbers (could be NaN). */\nLJFOLD(EQ KNUM KNUM)\nLJFOLD(NE KNUM KNUM)\nLJFOLD(LT KNUM KNUM)\nLJFOLD(GE KNUM KNUM)\nLJFOLD(LE KNUM KNUM)\nLJFOLD(GT KNUM KNUM)\nLJFOLD(ULT KNUM KNUM)\nLJFOLD(UGE KNUM KNUM)\nLJFOLD(ULE KNUM KNUM)\nLJFOLD(UGT KNUM KNUM)\nLJFOLDF(kfold_numcomp)\n{\n  return CONDFOLD(lj_ir_numcmp(knumleft, knumright, (IROp)fins->o));\n}\n\n/* -- Constant folding for 32 bit integers -------------------------------- */\n\nstatic int32_t kfold_intop(int32_t k1, int32_t k2, IROp op)\n{\n  switch (op) {\n  case IR_ADD: k1 += k2; break;\n  case IR_SUB: k1 -= k2; break;\n  case IR_MUL: k1 *= k2; break;\n  case IR_MOD: k1 = lj_vm_modi(k1, k2); break;\n  case IR_NEG: k1 = -k1; break;\n  case IR_BAND: k1 &= k2; break;\n  case IR_BOR: k1 |= k2; break;\n  case IR_BXOR: k1 ^= k2; break;\n  case IR_BSHL: k1 <<= (k2 & 31); break;\n  case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 31)); break;\n  case IR_BSAR: k1 >>= (k2 & 31); break;\n  case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 31)); break;\n  case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 31)); break;\n  case IR_MIN: k1 = k1 < k2 ? k1 : k2; break;\n  case IR_MAX: k1 = k1 > k2 ? k1 : k2; break;\n  default: lj_assertX(0, \"bad IR op %d\", op); break;\n  }\n  return k1;\n}\n\nLJFOLD(ADD KINT KINT)\nLJFOLD(SUB KINT KINT)\nLJFOLD(MUL KINT KINT)\nLJFOLD(MOD KINT KINT)\nLJFOLD(NEG KINT KINT)\nLJFOLD(BAND KINT KINT)\nLJFOLD(BOR KINT KINT)\nLJFOLD(BXOR KINT KINT)\nLJFOLD(BSHL KINT KINT)\nLJFOLD(BSHR KINT KINT)\nLJFOLD(BSAR KINT KINT)\nLJFOLD(BROL KINT KINT)\nLJFOLD(BROR KINT KINT)\nLJFOLD(MIN KINT KINT)\nLJFOLD(MAX KINT KINT)\nLJFOLDF(kfold_intarith)\n{\n  return INTFOLD(kfold_intop(fleft->i, fright->i, (IROp)fins->o));\n}\n\nLJFOLD(ADDOV KINT KINT)\nLJFOLD(SUBOV KINT KINT)\nLJFOLD(MULOV KINT KINT)\nLJFOLDF(kfold_intovarith)\n{\n  lua_Number n = lj_vm_foldarith((lua_Number)fleft->i, (lua_Number)fright->i,\n\t\t\t\t fins->o - IR_ADDOV);\n  int32_t k = lj_num2int(n);\n  if (n != (lua_Number)k)\n    return FAILFOLD;\n  return INTFOLD(k);\n}\n\nLJFOLD(BNOT KINT)\nLJFOLDF(kfold_bnot)\n{\n  return INTFOLD(~fleft->i);\n}\n\nLJFOLD(BSWAP KINT)\nLJFOLDF(kfold_bswap)\n{\n  return INTFOLD((int32_t)lj_bswap((uint32_t)fleft->i));\n}\n\nLJFOLD(LT KINT KINT)\nLJFOLD(GE KINT KINT)\nLJFOLD(LE KINT KINT)\nLJFOLD(GT KINT KINT)\nLJFOLD(ULT KINT KINT)\nLJFOLD(UGE KINT KINT)\nLJFOLD(ULE KINT KINT)\nLJFOLD(UGT KINT KINT)\nLJFOLD(ABC KINT KINT)\nLJFOLDF(kfold_intcomp)\n{\n  int32_t a = fleft->i, b = fright->i;\n  switch ((IROp)fins->o) {\n  case IR_LT: return CONDFOLD(a < b);\n  case IR_GE: return CONDFOLD(a >= b);\n  case IR_LE: return CONDFOLD(a <= b);\n  case IR_GT: return CONDFOLD(a > b);\n  case IR_ULT: return CONDFOLD((uint32_t)a < (uint32_t)b);\n  case IR_UGE: return CONDFOLD((uint32_t)a >= (uint32_t)b);\n  case IR_ULE: return CONDFOLD((uint32_t)a <= (uint32_t)b);\n  case IR_ABC:\n  case IR_UGT: return CONDFOLD((uint32_t)a > (uint32_t)b);\n  default: lj_assertJ(0, \"bad IR op %d\", fins->o); return FAILFOLD;\n  }\n}\n\nLJFOLD(UGE any KINT)\nLJFOLDF(kfold_intcomp0)\n{\n  if (fright->i == 0)\n    return DROPFOLD;\n  return NEXTFOLD;\n}\n\n/* -- Constant folding for 64 bit integers -------------------------------- */\n\nstatic uint64_t kfold_int64arith(jit_State *J, uint64_t k1, uint64_t k2,\n\t\t\t\t IROp op)\n{\n  UNUSED(J);\n#if LJ_HASFFI\n  switch (op) {\n  case IR_ADD: k1 += k2; break;\n  case IR_SUB: k1 -= k2; break;\n  case IR_MUL: k1 *= k2; break;\n  case IR_BAND: k1 &= k2; break;\n  case IR_BOR: k1 |= k2; break;\n  case IR_BXOR: k1 ^= k2; break;\n  case IR_BSHL: k1 <<= (k2 & 63); break;\n  case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 63)); break;\n  case IR_BSAR: k1 >>= (k2 & 63); break;\n  case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 63)); break;\n  case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 63)); break;\n  default: lj_assertJ(0, \"bad IR op %d\", op); break;\n  }\n#else\n  UNUSED(k2); UNUSED(op);\n  lj_assertJ(0, \"FFI IR op without FFI\");\n#endif\n  return k1;\n}\n\nLJFOLD(ADD KINT64 KINT64)\nLJFOLD(SUB KINT64 KINT64)\nLJFOLD(MUL KINT64 KINT64)\nLJFOLD(BAND KINT64 KINT64)\nLJFOLD(BOR KINT64 KINT64)\nLJFOLD(BXOR KINT64 KINT64)\nLJFOLDF(kfold_int64arith)\n{\n  return INT64FOLD(kfold_int64arith(J, ir_k64(fleft)->u64,\n\t\t\t\t    ir_k64(fright)->u64, (IROp)fins->o));\n}\n\nLJFOLD(DIV KINT64 KINT64)\nLJFOLD(MOD KINT64 KINT64)\nLJFOLD(POW KINT64 KINT64)\nLJFOLDF(kfold_int64arith2)\n{\n#if LJ_HASFFI\n  uint64_t k1 = ir_k64(fleft)->u64, k2 = ir_k64(fright)->u64;\n  if (irt_isi64(fins->t)) {\n    k1 = fins->o == IR_DIV ? lj_carith_divi64((int64_t)k1, (int64_t)k2) :\n\t fins->o == IR_MOD ? lj_carith_modi64((int64_t)k1, (int64_t)k2) :\n\t\t\t     lj_carith_powi64((int64_t)k1, (int64_t)k2);\n  } else {\n    k1 = fins->o == IR_DIV ? lj_carith_divu64(k1, k2) :\n\t fins->o == IR_MOD ? lj_carith_modu64(k1, k2) :\n\t\t\t     lj_carith_powu64(k1, k2);\n  }\n  return INT64FOLD(k1);\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BSHL KINT64 KINT)\nLJFOLD(BSHR KINT64 KINT)\nLJFOLD(BSAR KINT64 KINT)\nLJFOLD(BROL KINT64 KINT)\nLJFOLD(BROR KINT64 KINT)\nLJFOLDF(kfold_int64shift)\n{\n#if LJ_HASFFI\n  uint64_t k = ir_k64(fleft)->u64;\n  int32_t sh = (fright->i & 63);\n  return INT64FOLD(lj_carith_shift64(k, sh, fins->o - IR_BSHL));\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BNOT KINT64)\nLJFOLDF(kfold_bnot64)\n{\n#if LJ_HASFFI\n  return INT64FOLD(~ir_k64(fleft)->u64);\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BSWAP KINT64)\nLJFOLDF(kfold_bswap64)\n{\n#if LJ_HASFFI\n  return INT64FOLD(lj_bswap64(ir_k64(fleft)->u64));\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(LT KINT64 KINT64)\nLJFOLD(GE KINT64 KINT64)\nLJFOLD(LE KINT64 KINT64)\nLJFOLD(GT KINT64 KINT64)\nLJFOLD(ULT KINT64 KINT64)\nLJFOLD(UGE KINT64 KINT64)\nLJFOLD(ULE KINT64 KINT64)\nLJFOLD(UGT KINT64 KINT64)\nLJFOLDF(kfold_int64comp)\n{\n#if LJ_HASFFI\n  uint64_t a = ir_k64(fleft)->u64, b = ir_k64(fright)->u64;\n  switch ((IROp)fins->o) {\n  case IR_LT: return CONDFOLD((int64_t)a < (int64_t)b);\n  case IR_GE: return CONDFOLD((int64_t)a >= (int64_t)b);\n  case IR_LE: return CONDFOLD((int64_t)a <= (int64_t)b);\n  case IR_GT: return CONDFOLD((int64_t)a > (int64_t)b);\n  case IR_ULT: return CONDFOLD(a < b);\n  case IR_UGE: return CONDFOLD(a >= b);\n  case IR_ULE: return CONDFOLD(a <= b);\n  case IR_UGT: return CONDFOLD(a > b);\n  default: lj_assertJ(0, \"bad IR op %d\", fins->o); return FAILFOLD;\n  }\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(UGE any KINT64)\nLJFOLDF(kfold_int64comp0)\n{\n#if LJ_HASFFI\n  if (ir_k64(fright)->u64 == 0)\n    return DROPFOLD;\n  return NEXTFOLD;\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\n/* -- Constant folding for strings ---------------------------------------- */\n\nLJFOLD(SNEW KKPTR KINT)\nLJFOLDF(kfold_snew_kptr)\n{\n  GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i);\n  return lj_ir_kstr(J, s);\n}\n\nLJFOLD(SNEW any KINT)\nLJFOLD(XSNEW any KINT)\nLJFOLDF(kfold_snew_empty)\n{\n  if (fright->i == 0)\n    return lj_ir_kstr(J, &J2G(J)->strempty);\n  return NEXTFOLD;\n}\n\nLJFOLD(STRREF KGC KINT)\nLJFOLDF(kfold_strref)\n{\n  GCstr *str = ir_kstr(fleft);\n  lj_assertJ((MSize)fright->i <= str->len, \"bad string ref\");\n  return lj_ir_kkptr(J, (char *)strdata(str) + fright->i);\n}\n\nLJFOLD(STRREF SNEW any)\nLJFOLDF(kfold_strref_snew)\n{\n  PHIBARRIER(fleft);\n  if (irref_isk(fins->op2) && fright->i == 0) {\n    return fleft->op1;  /* strref(snew(ptr, len), 0) ==> ptr */\n  } else {\n    /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */\n    IRIns *ir = IR(fleft->op1);\n    if (ir->o == IR_STRREF) {\n      IRRef1 str = ir->op1;  /* IRIns * is not valid across emitir. */\n      PHIBARRIER(ir);\n      fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */\n      fins->op1 = str;\n      fins->ot = IRT(IR_STRREF, IRT_PGC);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CALLN CARG IRCALL_lj_str_cmp)\nLJFOLDF(kfold_strcmp)\n{\n  if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) {\n    GCstr *a = ir_kstr(IR(fleft->op1));\n    GCstr *b = ir_kstr(IR(fleft->op2));\n    return INTFOLD(lj_str_cmp(a, b));\n  }\n  return NEXTFOLD;\n}\n\n/* -- Constant folding and forwarding for buffers ------------------------- */\n\n/*\n** Buffer ops perform stores, but their effect is limited to the buffer\n** itself. Also, buffer ops are chained: a use of an op implies a use of\n** all other ops up the chain. Conversely, if an op is unused, all ops\n** up the chain can go unsed. This largely eliminates the need to treat\n** them as stores.\n**\n** Alas, treating them as normal (IRM_N) ops doesn't work, because they\n** cannot be CSEd in isolation. CSE for IRM_N is implicitly done in LOOP\n** or if FOLD is disabled.\n**\n** The compromise is to declare them as loads, emit them like stores and\n** CSE whole chains manually when the BUFSTR is to be emitted. Any chain\n** fragments left over from CSE are eliminated by DCE.\n**\n** The string buffer methods emit a USE instead of a BUFSTR to keep the\n** chain alive.\n*/\n\nLJFOLD(BUFHDR any any)\nLJFOLDF(bufhdr_merge)\n{\n  return fins->op2 == IRBUFHDR_WRITE ? CSEFOLD : EMITFOLD;\n}\n\nLJFOLD(BUFPUT any BUFSTR)\nLJFOLDF(bufput_bufstr)\n{\n  if ((J->flags & JIT_F_OPT_FWD)) {\n    IRRef hdr = fright->op2;\n    /* New buffer, no other buffer op inbetween and same buffer? */\n    if (fleft->o == IR_BUFHDR && fleft->op2 == IRBUFHDR_RESET &&\n\tfleft->prev == hdr &&\n\tfleft->op1 == IR(hdr)->op1) {\n      IRRef ref = fins->op1;\n      IR(ref)->op2 = IRBUFHDR_APPEND;  /* Modify BUFHDR. */\n      IR(ref)->op1 = fright->op1;\n      return ref;\n    }\n    /* Replay puts to global temporary buffer. */\n    if (IR(hdr)->op2 == IRBUFHDR_RESET) {\n      IRIns *ir = IR(fright->op1);\n      /* For now only handle single string.reverse .lower .upper .rep. */\n      if (ir->o == IR_CALLL &&\n\t  ir->op2 >= IRCALL_lj_buf_putstr_reverse &&\n\t  ir->op2 <= IRCALL_lj_buf_putstr_rep) {\n\tIRIns *carg1 = IR(ir->op1);\n\tif (ir->op2 == IRCALL_lj_buf_putstr_rep) {\n\t  IRIns *carg2 = IR(carg1->op1);\n\t  if (carg2->op1 == hdr) {\n\t    return lj_ir_call(J, ir->op2, fins->op1, carg2->op2, carg1->op2);\n\t  }\n\t} else if (carg1->op1 == hdr) {\n\t  return lj_ir_call(J, ir->op2, fins->op1, carg1->op2);\n\t}\n      }\n    }\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(BUFPUT any any)\nLJFOLDF(bufput_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && fright->o == IR_KGC) {\n    GCstr *s2 = ir_kstr(fright);\n    if (s2->len == 0) {  /* Empty string? */\n      return LEFTFOLD;\n    } else {\n      if (fleft->o == IR_BUFPUT && irref_isk(fleft->op2) &&\n\t  !irt_isphi(fleft->t)) {  /* Join two constant string puts in a row. */\n\tGCstr *s1 = ir_kstr(IR(fleft->op2));\n\tIRRef kref = lj_ir_kstr(J, lj_buf_cat2str(J->L, s1, s2));\n\t/* lj_ir_kstr() may realloc the IR and invalidates any IRIns *. */\n\tIR(fins->op1)->op2 = kref;  /* Modify previous BUFPUT. */\n\treturn fins->op1;\n      }\n    }\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(BUFSTR any any)\nLJFOLDF(bufstr_kfold_cse)\n{\n  lj_assertJ(fleft->o == IR_BUFHDR || fleft->o == IR_BUFPUT ||\n\t     fleft->o == IR_CALLL,\n\t     \"bad buffer constructor IR op %d\", fleft->o);\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    if (fleft->o == IR_BUFHDR) {  /* No put operations? */\n      if (fleft->op2 == IRBUFHDR_RESET)  /* Empty buffer? */\n\treturn lj_ir_kstr(J, &J2G(J)->strempty);\n      fins->op1 = fleft->op1;\n      fins->op2 = fleft->prev;  /* Relies on checks in bufput_append. */\n      return CSEFOLD;\n    } else if (fleft->o == IR_BUFPUT) {\n      IRIns *irb = IR(fleft->op1);\n      if (irb->o == IR_BUFHDR && irb->op2 == IRBUFHDR_RESET)\n\treturn fleft->op2;  /* Shortcut for a single put operation. */\n    }\n  }\n  /* Try to CSE the whole chain. */\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef ref = J->chain[IR_BUFSTR];\n    while (ref) {\n      IRIns *irs = IR(ref), *ira = fleft, *irb = IR(irs->op1);\n      while (ira->o == irb->o && ira->op2 == irb->op2) {\n\tlj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||\n\t\t   ira->o == IR_CALLL || ira->o == IR_CARG,\n\t\t   \"bad buffer constructor IR op %d\", ira->o);\n\tif (ira->o == IR_BUFHDR && ira->op2 == IRBUFHDR_RESET)\n\t  return ref;  /* CSE succeeded. */\n\tif (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)\n\t  break;\n\tira = IR(ira->op1);\n\tirb = IR(irb->op1);\n      }\n      ref = irs->prev;\n    }\n  }\n  return EMITFOLD;  /* No CSE possible. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_reverse)\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_upper)\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_lower)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putquoted)\nLJFOLDF(bufput_kfold_op)\n{\n  if (irref_isk(fleft->op2)) {\n    const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n    SBuf *sb = lj_buf_tmp_(J->L);\n    sb = ((SBuf * (LJ_FASTCALL *)(SBuf *, GCstr *))ci->func)(sb,\n\t\t\t\t\t\t       ir_kstr(IR(fleft->op2)));\n    fins->o = IR_BUFPUT;\n    fins->op1 = fleft->op1;\n    fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n    return RETRYFOLD;\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_buf_putstr_rep)\nLJFOLDF(bufput_kfold_rep)\n{\n  if (irref_isk(fleft->op2)) {\n    IRIns *irc = IR(fleft->op1);\n    if (irref_isk(irc->op2)) {\n      SBuf *sb = lj_buf_tmp_(J->L);\n      sb = lj_buf_putstr_rep(sb, ir_kstr(IR(irc->op2)), IR(fleft->op2)->i);\n      fins->o = IR_BUFPUT;\n      fins->op1 = irc->op1;\n      fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n      return RETRYFOLD;\n    }\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfxint)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum_int)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum_uint)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfnum)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfstr)\nLJFOLD(CALLL CARG IRCALL_lj_strfmt_putfchar)\nLJFOLDF(bufput_kfold_fmt)\n{\n  IRIns *irc = IR(fleft->op1);\n  lj_assertJ(irref_isk(irc->op2), \"SFormat must be const\");\n  if (irref_isk(fleft->op2)) {\n    SFormat sf = (SFormat)IR(irc->op2)->i;\n    IRIns *ira = IR(fleft->op2);\n    SBuf *sb = lj_buf_tmp_(J->L);\n    switch (fins->op2) {\n    case IRCALL_lj_strfmt_putfxint:\n      sb = lj_strfmt_putfxint(sb, sf, ir_k64(ira)->u64);\n      break;\n    case IRCALL_lj_strfmt_putfstr:\n      sb = lj_strfmt_putfstr(sb, sf, ir_kstr(ira));\n      break;\n    case IRCALL_lj_strfmt_putfchar:\n      sb = lj_strfmt_putfchar(sb, sf, ira->i);\n      break;\n    case IRCALL_lj_strfmt_putfnum_int:\n    case IRCALL_lj_strfmt_putfnum_uint:\n    case IRCALL_lj_strfmt_putfnum:\n    default: {\n      const CCallInfo *ci = &lj_ir_callinfo[fins->op2];\n      sb = ((SBuf * (*)(SBuf *, SFormat, lua_Number))ci->func)(sb, sf,\n\t\t\t\t\t\t\t ir_knum(ira)->n);\n      break;\n      }\n    }\n    fins->o = IR_BUFPUT;\n    fins->op1 = irc->op1;\n    fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));\n    return RETRYFOLD;\n  }\n  return EMITFOLD;  /* Always emit, CSE later. */\n}\n\n/* -- Constant folding of pointer arithmetic ------------------------------ */\n\nLJFOLD(ADD KGC KINT)\nLJFOLD(ADD KGC KINT64)\nLJFOLDF(kfold_add_kgc)\n{\n  GCobj *o = ir_kgc(fleft);\n#if LJ_64\n  ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;\n#else\n  ptrdiff_t ofs = fright->i;\n#endif\n#if LJ_HASFFI\n  if (irt_iscdata(fleft->t)) {\n    CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid);\n    if (ctype_isnum(ct->info) || ctype_isenum(ct->info) ||\n\tctype_isptr(ct->info) || ctype_isfunc(ct->info) ||\n\tctype_iscomplex(ct->info) || ctype_isvector(ct->info))\n      return lj_ir_kkptr(J, (char *)o + ofs);\n  }\n#endif\n  return lj_ir_kptr(J, (char *)o + ofs);\n}\n\nLJFOLD(ADD KPTR KINT)\nLJFOLD(ADD KPTR KINT64)\nLJFOLD(ADD KKPTR KINT)\nLJFOLD(ADD KKPTR KINT64)\nLJFOLDF(kfold_add_kptr)\n{\n  void *p = ir_kptr(fleft);\n#if LJ_64\n  ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;\n#else\n  ptrdiff_t ofs = fright->i;\n#endif\n  return lj_ir_kptr_(J, fleft->o, (char *)p + ofs);\n}\n\nLJFOLD(ADD any KGC)\nLJFOLD(ADD any KPTR)\nLJFOLD(ADD any KKPTR)\nLJFOLDF(kfold_add_kright)\n{\n  if (fleft->o == IR_KINT || fleft->o == IR_KINT64) {\n    IRRef1 tmp = fins->op1; fins->op1 = fins->op2; fins->op2 = tmp;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* -- Constant folding of conversions ------------------------------------- */\n\nLJFOLD(TOBIT KNUM KNUM)\nLJFOLDF(kfold_tobit)\n{\n  return INTFOLD(lj_num2bit(knumleft));\n}\n\nLJFOLD(CONV KINT IRCONV_NUM_INT)\nLJFOLDF(kfold_conv_kint_num)\n{\n  return lj_ir_knum(J, (lua_Number)fleft->i);\n}\n\nLJFOLD(CONV KINT IRCONV_NUM_U32)\nLJFOLDF(kfold_conv_kintu32_num)\n{\n  return lj_ir_knum(J, (lua_Number)(uint32_t)fleft->i);\n}\n\nLJFOLD(CONV KINT IRCONV_INT_I8)\nLJFOLD(CONV KINT IRCONV_INT_U8)\nLJFOLD(CONV KINT IRCONV_INT_I16)\nLJFOLD(CONV KINT IRCONV_INT_U16)\nLJFOLDF(kfold_conv_kint_ext)\n{\n  int32_t k = fleft->i;\n  if ((fins->op2 & IRCONV_SRCMASK) == IRT_I8) k = (int8_t)k;\n  else if ((fins->op2 & IRCONV_SRCMASK) == IRT_U8) k = (uint8_t)k;\n  else if ((fins->op2 & IRCONV_SRCMASK) == IRT_I16) k = (int16_t)k;\n  else k = (uint16_t)k;\n  return INTFOLD(k);\n}\n\nLJFOLD(CONV KINT IRCONV_I64_INT)\nLJFOLD(CONV KINT IRCONV_U64_INT)\nLJFOLD(CONV KINT IRCONV_I64_U32)\nLJFOLD(CONV KINT IRCONV_U64_U32)\nLJFOLDF(kfold_conv_kint_i64)\n{\n  if ((fins->op2 & IRCONV_SEXT))\n    return INT64FOLD((uint64_t)(int64_t)fleft->i);\n  else\n    return INT64FOLD((uint64_t)(int64_t)(uint32_t)fleft->i);\n}\n\nLJFOLD(CONV KINT64 IRCONV_NUM_I64)\nLJFOLDF(kfold_conv_kint64_num_i64)\n{\n  return lj_ir_knum(J, (lua_Number)(int64_t)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KINT64 IRCONV_NUM_U64)\nLJFOLDF(kfold_conv_kint64_num_u64)\n{\n  return lj_ir_knum(J, (lua_Number)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KINT64 IRCONV_INT_I64)\nLJFOLD(CONV KINT64 IRCONV_U32_I64)\nLJFOLDF(kfold_conv_kint64_int_i64)\n{\n  return INTFOLD((int32_t)ir_kint64(fleft)->u64);\n}\n\nLJFOLD(CONV KNUM IRCONV_INT_NUM)\nLJFOLDF(kfold_conv_knum_int_num)\n{\n  lua_Number n = knumleft;\n  int32_t k = lj_num2int(n);\n  if (irt_isguard(fins->t) && n != (lua_Number)k) {\n    /* We're about to create a guard which always fails, like CONV +1.5.\n    ** Some pathological loops cause this during LICM, e.g.:\n    **   local x,k,t = 0,1.5,{1,[1.5]=2}\n    **   for i=1,200 do x = x+ t[k]; k = k == 1 and 1.5 or 1 end\n    **   assert(x == 300)\n    */\n    return FAILFOLD;\n  }\n  return INTFOLD(k);\n}\n\nLJFOLD(CONV KNUM IRCONV_U32_NUM)\nLJFOLDF(kfold_conv_knum_u32_num)\n{\n#ifdef _MSC_VER\n  {  /* Workaround for MSVC bug. */\n    volatile uint32_t u = (uint32_t)knumleft;\n    return INTFOLD((int32_t)u);\n  }\n#else\n  return INTFOLD((int32_t)(uint32_t)knumleft);\n#endif\n}\n\nLJFOLD(CONV KNUM IRCONV_I64_NUM)\nLJFOLDF(kfold_conv_knum_i64_num)\n{\n  return INT64FOLD((uint64_t)(int64_t)knumleft);\n}\n\nLJFOLD(CONV KNUM IRCONV_U64_NUM)\nLJFOLDF(kfold_conv_knum_u64_num)\n{\n  return INT64FOLD(lj_num2u64(knumleft));\n}\n\nLJFOLD(TOSTR KNUM any)\nLJFOLDF(kfold_tostr_knum)\n{\n  return lj_ir_kstr(J, lj_strfmt_num(J->L, ir_knum(fleft)));\n}\n\nLJFOLD(TOSTR KINT any)\nLJFOLDF(kfold_tostr_kint)\n{\n  return lj_ir_kstr(J, fins->op2 == IRTOSTR_INT ?\n\t\t       lj_strfmt_int(J->L, fleft->i) :\n\t\t       lj_strfmt_char(J->L, fleft->i));\n}\n\nLJFOLD(STRTO KGC)\nLJFOLDF(kfold_strto)\n{\n  TValue n;\n  if (lj_strscan_num(ir_kstr(fleft), &n))\n    return lj_ir_knum(J, numV(&n));\n  return FAILFOLD;\n}\n\n/* -- Constant folding of equality checks --------------------------------- */\n\n/* Don't constant-fold away FLOAD checks against KNULL. */\nLJFOLD(EQ FLOAD KNULL)\nLJFOLD(NE FLOAD KNULL)\nLJFOLDX(lj_opt_cse)\n\n/* But fold all other KNULL compares, since only KNULL is equal to KNULL. */\nLJFOLD(EQ any KNULL)\nLJFOLD(NE any KNULL)\nLJFOLD(EQ KNULL any)\nLJFOLD(NE KNULL any)\nLJFOLD(EQ KINT KINT)  /* Constants are unique, so same refs <==> same value. */\nLJFOLD(NE KINT KINT)\nLJFOLD(EQ KINT64 KINT64)\nLJFOLD(NE KINT64 KINT64)\nLJFOLD(EQ KGC KGC)\nLJFOLD(NE KGC KGC)\nLJFOLDF(kfold_kref)\n{\n  return CONDFOLD((fins->op1 == fins->op2) ^ (fins->o == IR_NE));\n}\n\n/* -- Algebraic shortcuts ------------------------------------------------- */\n\nLJFOLD(FPMATH FPMATH IRFPM_FLOOR)\nLJFOLD(FPMATH FPMATH IRFPM_CEIL)\nLJFOLD(FPMATH FPMATH IRFPM_TRUNC)\nLJFOLDF(shortcut_round)\n{\n  IRFPMathOp op = (IRFPMathOp)fleft->op2;\n  if (op == IRFPM_FLOOR || op == IRFPM_CEIL || op == IRFPM_TRUNC)\n    return LEFTFOLD;  /* round(round_left(x)) = round_left(x) */\n  return NEXTFOLD;\n}\n\nLJFOLD(ABS ABS FLOAD)\nLJFOLDF(shortcut_left)\n{\n  return LEFTFOLD;  /* f(g(x)) ==> g(x) */\n}\n\nLJFOLD(ABS NEG FLOAD)\nLJFOLDF(shortcut_dropleft)\n{\n  PHIBARRIER(fleft);\n  fins->op1 = fleft->op1;  /* abs(neg(x)) ==> abs(x) */\n  return RETRYFOLD;\n}\n\n/* Note: no safe shortcuts with STRTO and TOSTR (\"1e2\" ==> +100 ==> \"100\"). */\nLJFOLD(NEG NEG any)\nLJFOLD(BNOT BNOT)\nLJFOLD(BSWAP BSWAP)\nLJFOLDF(shortcut_leftleft)\n{\n  PHIBARRIER(fleft);  /* See above. Fold would be ok, but not beneficial. */\n  return fleft->op1;  /* f(g(x)) ==> x */\n}\n\n/* -- FP algebraic simplifications ---------------------------------------- */\n\n/* FP arithmetic is tricky -- there's not much to simplify.\n** Please note the following common pitfalls before sending \"improvements\":\n**   x+0 ==> x  is INVALID for x=-0\n**   0-x ==> -x is INVALID for x=+0\n**   x*0 ==> 0  is INVALID for x=-0, x=+-Inf or x=NaN\n*/\n\nLJFOLD(ADD NEG any)\nLJFOLDF(simplify_numadd_negx)\n{\n  PHIBARRIER(fleft);\n  fins->o = IR_SUB;  /* (-a) + b ==> b - a */\n  fins->op1 = fins->op2;\n  fins->op2 = fleft->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(ADD any NEG)\nLJFOLDF(simplify_numadd_xneg)\n{\n  PHIBARRIER(fright);\n  fins->o = IR_SUB;  /* a + (-b) ==> a - b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB any KNUM)\nLJFOLDF(simplify_numsub_k)\n{\n  if (ir_knum(fright)->u64 == 0)  /* x - (+0) ==> x */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB NEG KNUM)\nLJFOLDF(simplify_numsub_negk)\n{\n  PHIBARRIER(fleft);\n  fins->op2 = fleft->op1;  /* (-x) - k ==> (-k) - x */\n  fins->op1 = (IRRef1)lj_ir_knum(J, -knumright);\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB any NEG)\nLJFOLDF(simplify_numsub_xneg)\n{\n  PHIBARRIER(fright);\n  fins->o = IR_ADD;  /* a - (-b) ==> a + b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(MUL any KNUM)\nLJFOLD(DIV any KNUM)\nLJFOLDF(simplify_nummuldiv_k)\n{\n  lua_Number n = knumright;\n  if (n == 1.0) {  /* x o 1 ==> x */\n    return LEFTFOLD;\n  } else if (n == -1.0) {  /* x o -1 ==> -x */\n    IRRef op1 = fins->op1;\n    fins->op2 = (IRRef1)lj_ir_ksimd(J, LJ_KSIMD_NEG);  /* Modifies fins. */\n    fins->op1 = op1;\n    fins->o = IR_NEG;\n    return RETRYFOLD;\n  } else if (fins->o == IR_MUL && n == 2.0) {  /* x * 2 ==> x + x */\n    fins->o = IR_ADD;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  } else if (fins->o == IR_DIV) {  /* x / 2^k ==> x * 2^-k */\n    uint64_t u = ir_knum(fright)->u64;\n    uint32_t ex = ((uint32_t)(u >> 52) & 0x7ff);\n    if ((u & U64x(000fffff,ffffffff)) == 0 && ex - 1 < 0x7fd) {\n      u = (u & ((uint64_t)1 << 63)) | ((uint64_t)(0x7fe - ex) << 52);\n      fins->o = IR_MUL;  /* Multiply by exact reciprocal. */\n      fins->op2 = lj_ir_knum_u64(J, u);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL NEG KNUM)\nLJFOLD(DIV NEG KNUM)\nLJFOLDF(simplify_nummuldiv_negk)\n{\n  PHIBARRIER(fleft);\n  fins->op1 = fleft->op1;  /* (-a) o k ==> a o (-k) */\n  fins->op2 = (IRRef1)lj_ir_knum(J, -knumright);\n  return RETRYFOLD;\n}\n\nLJFOLD(MUL NEG NEG)\nLJFOLD(DIV NEG NEG)\nLJFOLDF(simplify_nummuldiv_negneg)\n{\n  PHIBARRIER(fleft);\n  PHIBARRIER(fright);\n  fins->op1 = fleft->op1;  /* (-a) o (-b) ==> a o b */\n  fins->op2 = fright->op1;\n  return RETRYFOLD;\n}\n\nLJFOLD(POW any KINT)\nLJFOLDF(simplify_numpow_xkint)\n{\n  int32_t k = fright->i;\n  TRef ref = fins->op1;\n  if (k == 0)  /* x ^ 0 ==> 1 */\n    return lj_ir_knum_one(J);  /* Result must be a number, not an int. */\n  if (k == 1)  /* x ^ 1 ==> x */\n    return LEFTFOLD;\n  if ((uint32_t)(k+65536) > 2*65536u)  /* Limit code explosion. */\n    return NEXTFOLD;\n  if (k < 0) {  /* x ^ (-k) ==> (1/x) ^ k. */\n    ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref);\n    k = -k;\n  }\n  /* Unroll x^k for 1 <= k <= 65536. */\n  for (; (k & 1) == 0; k >>= 1)  /* Handle leading zeros. */\n    ref = emitir(IRTN(IR_MUL), ref, ref);\n  if ((k >>= 1) != 0) {  /* Handle trailing bits. */\n    TRef tmp = emitir(IRTN(IR_MUL), ref, ref);\n    for (; k != 1; k >>= 1) {\n      if (k & 1)\n\tref = emitir(IRTN(IR_MUL), ref, tmp);\n      tmp = emitir(IRTN(IR_MUL), tmp, tmp);\n    }\n    ref = emitir(IRTN(IR_MUL), ref, tmp);\n  }\n  return ref;\n}\n\nLJFOLD(POW any KNUM)\nLJFOLDF(simplify_numpow_xknum)\n{\n  if (knumright == 0.5)  /* x ^ 0.5 ==> sqrt(x) */\n    return emitir(IRTN(IR_FPMATH), fins->op1, IRFPM_SQRT);\n  return NEXTFOLD;\n}\n\nLJFOLD(POW KNUM any)\nLJFOLDF(simplify_numpow_kx)\n{\n  lua_Number n = knumleft;\n  if (n == 2.0 && irt_isint(fright->t)) {  /* 2.0 ^ i ==> ldexp(1.0, i) */\n#if LJ_TARGET_X86ORX64\n    /* Different IR_LDEXP calling convention on x86/x64 requires conversion. */\n    fins->o = IR_CONV;\n    fins->op1 = fins->op2;\n    fins->op2 = IRCONV_NUM_INT;\n    fins->op2 = (IRRef1)lj_opt_fold(J);\n#endif\n    fins->op1 = (IRRef1)lj_ir_knum_one(J);\n    fins->o = IR_LDEXP;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* -- Simplify conversions ------------------------------------------------ */\n\nLJFOLD(CONV CONV IRCONV_NUM_INT)  /* _NUM */\nLJFOLDF(shortcut_conv_num_int)\n{\n  PHIBARRIER(fleft);\n  /* Only safe with a guarded conversion to int. */\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_NUM && irt_isguard(fleft->t))\n    return fleft->op1;  /* f(g(x)) ==> x */\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_INT_NUM)  /* _INT */\nLJFOLD(CONV CONV IRCONV_U32_NUM)  /* _U32*/\nLJFOLDF(simplify_conv_int_num)\n{\n  /* Fold even across PHI to avoid expensive num->int conversions in loop. */\n  if ((fleft->op2 & IRCONV_SRCMASK) ==\n      ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH))\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_I64_NUM)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U64_NUM)  /* _INT or _U32 */\nLJFOLDF(simplify_conv_i64_num)\n{\n  PHIBARRIER(fleft);\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    /* Reduce to a sign-extension. */\n    fins->op1 = fleft->op1;\n    fins->op2 = ((IRT_I64<<5)|IRT_INT|IRCONV_SEXT);\n    return RETRYFOLD;\n  } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {\n#if LJ_TARGET_X64\n    return fleft->op1;\n#else\n    /* Reduce to a zero-extension. */\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRT_I64<<5)|IRT_U32;\n    return RETRYFOLD;\n#endif\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_INT_I64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_INT_U64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U32_I64)  /* _INT or _U32 */\nLJFOLD(CONV CONV IRCONV_U32_U64)  /* _INT or _U32 */\nLJFOLDF(simplify_conv_int_i64)\n{\n  int src;\n  PHIBARRIER(fleft);\n  src = (fleft->op2 & IRCONV_SRCMASK);\n  if (src == IRT_INT || src == IRT_U32) {\n    if (src == ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) {\n      return fleft->op1;\n    } else {\n      fins->op2 = ((fins->op2 & IRCONV_DSTMASK) | src);\n      fins->op1 = fleft->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(CONV CONV IRCONV_FLOAT_NUM)  /* _FLOAT */\nLJFOLDF(simplify_conv_flt_num)\n{\n  PHIBARRIER(fleft);\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_FLOAT)\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\n/* Shortcut TOBIT + IRT_NUM <- IRT_INT/IRT_U32 conversion. */\nLJFOLD(TOBIT CONV KNUM)\nLJFOLDF(simplify_tobit_conv)\n{\n  /* Fold even across PHI to avoid expensive num->int conversions in loop. */\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    lj_assertJ(irt_isnum(fleft->t), \"expected TOBIT number arg\");\n    return fleft->op1;\n  } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {\n    lj_assertJ(irt_isnum(fleft->t), \"expected TOBIT number arg\");\n    fins->o = IR_CONV;\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRT_INT<<5)|IRT_U32;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\n/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */\nLJFOLD(FPMATH CONV IRFPM_FLOOR)\nLJFOLD(FPMATH CONV IRFPM_CEIL)\nLJFOLD(FPMATH CONV IRFPM_TRUNC)\nLJFOLDF(simplify_floor_conv)\n{\n  if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT ||\n      (fleft->op2 & IRCONV_SRCMASK) == IRT_U32)\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\n/* Strength reduction of widening. */\nLJFOLD(CONV any IRCONV_I64_INT)\nLJFOLD(CONV any IRCONV_U64_INT)\nLJFOLDF(simplify_conv_sext)\n{\n  IRRef ref = fins->op1;\n  int64_t ofs = 0;\n  if (!(fins->op2 & IRCONV_SEXT))\n    return NEXTFOLD;\n  PHIBARRIER(fleft);\n  if (fleft->o == IR_XLOAD && (irt_isu8(fleft->t) || irt_isu16(fleft->t)))\n    goto ok_reduce;\n  if (fleft->o == IR_ADD && irref_isk(fleft->op2)) {\n    ofs = (int64_t)IR(fleft->op2)->i;\n    ref = fleft->op1;\n  }\n  /* Use scalar evolution analysis results to strength-reduce sign-extension. */\n  if (ref == J->scev.idx) {\n    IRRef lo = J->scev.dir ? J->scev.start : J->scev.stop;\n    lj_assertJ(irt_isint(J->scev.t), \"only int SCEV supported\");\n    if (lo && IR(lo)->o == IR_KINT && IR(lo)->i + ofs >= 0) {\n    ok_reduce:\n#if LJ_TARGET_X64\n      /* Eliminate widening. All 32 bit ops do an implicit zero-extension. */\n      return LEFTFOLD;\n#else\n      /* Reduce to a (cheaper) zero-extension. */\n      fins->op2 &= ~IRCONV_SEXT;\n      return RETRYFOLD;\n#endif\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* Strength reduction of narrowing. */\nLJFOLD(CONV ADD IRCONV_INT_I64)\nLJFOLD(CONV SUB IRCONV_INT_I64)\nLJFOLD(CONV MUL IRCONV_INT_I64)\nLJFOLD(CONV ADD IRCONV_INT_U64)\nLJFOLD(CONV SUB IRCONV_INT_U64)\nLJFOLD(CONV MUL IRCONV_INT_U64)\nLJFOLD(CONV ADD IRCONV_U32_I64)\nLJFOLD(CONV SUB IRCONV_U32_I64)\nLJFOLD(CONV MUL IRCONV_U32_I64)\nLJFOLD(CONV ADD IRCONV_U32_U64)\nLJFOLD(CONV SUB IRCONV_U32_U64)\nLJFOLD(CONV MUL IRCONV_U32_U64)\nLJFOLDF(simplify_conv_narrow)\n{\n#if LJ_64\n  UNUSED(J);\n  return NEXTFOLD;\n#else\n  IROp op = (IROp)fleft->o;\n  IRType t = irt_type(fins->t);\n  IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2;\n  PHIBARRIER(fleft);\n  op1 = emitir(IRT(IR_CONV, t), op1, mode);\n  op2 = emitir(IRT(IR_CONV, t), op2, mode);\n  fins->ot = IRT(op, t);\n  fins->op1 = op1;\n  fins->op2 = op2;\n  return RETRYFOLD;\n#endif\n}\n\n/* Special CSE rule for CONV. */\nLJFOLD(CONV any any)\nLJFOLDF(cse_conv)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef op1 = fins->op1, op2 = (fins->op2 & IRCONV_MODEMASK);\n    uint8_t guard = irt_isguard(fins->t);\n    IRRef ref = J->chain[IR_CONV];\n    while (ref > op1) {\n      IRIns *ir = IR(ref);\n      /* Commoning with stronger checks is ok. */\n      if (ir->op1 == op1 && (ir->op2 & IRCONV_MODEMASK) == op2 &&\n\t  irt_isguard(ir->t) >= guard)\n\treturn ref;\n      ref = ir->prev;\n    }\n  }\n  return EMITFOLD;  /* No fallthrough to regular CSE. */\n}\n\n/* FP conversion narrowing. */\nLJFOLD(TOBIT ADD KNUM)\nLJFOLD(TOBIT SUB KNUM)\nLJFOLD(CONV ADD IRCONV_INT_NUM)\nLJFOLD(CONV SUB IRCONV_INT_NUM)\nLJFOLD(CONV ADD IRCONV_I64_NUM)\nLJFOLD(CONV SUB IRCONV_I64_NUM)\nLJFOLDF(narrow_convert)\n{\n  PHIBARRIER(fleft);\n  /* Narrowing ignores PHIs and repeating it inside the loop is not useful. */\n  if (J->chain[IR_LOOP])\n    return NEXTFOLD;\n  lj_assertJ(fins->o != IR_CONV || (fins->op2&IRCONV_CONVMASK) != IRCONV_TOBIT,\n\t     \"unexpected CONV TOBIT\");\n  return lj_opt_narrow_convert(J);\n}\n\n/* -- Integer algebraic simplifications ----------------------------------- */\n\nLJFOLD(ADD any KINT)\nLJFOLD(ADDOV any KINT)\nLJFOLD(SUBOV any KINT)\nLJFOLDF(simplify_intadd_k)\n{\n  if (fright->i == 0)  /* i o 0 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(MULOV any KINT)\nLJFOLDF(simplify_intmul_k)\n{\n  if (fright->i == 0)  /* i * 0 ==> 0 */\n    return RIGHTFOLD;\n  if (fright->i == 1)  /* i * 1 ==> i */\n    return LEFTFOLD;\n  if (fright->i == 2) {  /* i * 2 ==> i + i */\n    fins->o = IR_ADDOV;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any KINT)\nLJFOLDF(simplify_intsub_k)\n{\n  if (fright->i == 0)  /* i - 0 ==> i */\n    return LEFTFOLD;\n  fins->o = IR_ADD;  /* i - k ==> i + (-k) */\n  fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i);  /* Overflow for -2^31 ok. */\n  return RETRYFOLD;\n}\n\nLJFOLD(SUB KINT any)\nLJFOLD(SUB KINT64 any)\nLJFOLDF(simplify_intsub_kleft)\n{\n  if (fleft->o == IR_KINT ? (fleft->i == 0) : (ir_kint64(fleft)->u64 == 0)) {\n    fins->o = IR_NEG;  /* 0 - i ==> -i */\n    fins->op1 = fins->op2;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(ADD any KINT64)\nLJFOLDF(simplify_intadd_k64)\n{\n  if (ir_kint64(fright)->u64 == 0)  /* i + 0 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any KINT64)\nLJFOLDF(simplify_intsub_k64)\n{\n  uint64_t k = ir_kint64(fright)->u64;\n  if (k == 0)  /* i - 0 ==> i */\n    return LEFTFOLD;\n  fins->o = IR_ADD;  /* i - k ==> i + (-k) */\n  fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k);\n  return RETRYFOLD;\n}\n\nstatic TRef simplify_intmul_k(jit_State *J, int32_t k)\n{\n  /* Note: many more simplifications are possible, e.g. 2^k1 +- 2^k2.\n  ** But this is mainly intended for simple address arithmetic.\n  ** Also it's easier for the backend to optimize the original multiplies.\n  */\n  if (k == 0) {  /* i * 0 ==> 0 */\n    return RIGHTFOLD;\n  } else if (k == 1) {  /* i * 1 ==> i */\n    return LEFTFOLD;\n  } else if ((k & (k-1)) == 0) {  /* i * 2^k ==> i << k */\n    fins->o = IR_BSHL;\n    fins->op2 = lj_ir_kint(J, lj_fls((uint32_t)k));\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL any KINT)\nLJFOLDF(simplify_intmul_k32)\n{\n  if (fright->i >= 0)\n    return simplify_intmul_k(J, fright->i);\n  return NEXTFOLD;\n}\n\nLJFOLD(MUL any KINT64)\nLJFOLDF(simplify_intmul_k64)\n{\n#if LJ_HASFFI\n  if (ir_kint64(fright)->u64 < 0x80000000u)\n    return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64);\n  return NEXTFOLD;\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(MOD any KINT)\nLJFOLDF(simplify_intmod_k)\n{\n  int32_t k = fright->i;\n  lj_assertJ(k != 0, \"integer mod 0\");\n  if (k > 0 && (k & (k-1)) == 0) {  /* i % (2^k) ==> i & (2^k-1) */\n    fins->o = IR_BAND;\n    fins->op2 = lj_ir_kint(J, k-1);\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MOD KINT any)\nLJFOLDF(simplify_intmod_kleft)\n{\n  if (fleft->i == 0)\n    return INTFOLD(0);\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any any)\nLJFOLD(SUBOV any any)\nLJFOLDF(simplify_intsub)\n{\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))  /* i - i ==> 0 */\n    return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB ADD any)\nLJFOLDF(simplify_intsubadd_leftcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    if (fins->op2 == fleft->op1)  /* (i + j) - i ==> j */\n      return fleft->op2;\n    if (fins->op2 == fleft->op2)  /* (i + j) - j ==> i */\n      return fleft->op1;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB SUB any)\nLJFOLDF(simplify_intsubsub_leftcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    if (fins->op2 == fleft->op1) {  /* (i - j) - i ==> 0 - j */\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      fins->op2 = fleft->op2;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any SUB)\nLJFOLDF(simplify_intsubsub_rightcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fright);\n    if (fins->op1 == fright->op1)  /* i - (i - j) ==> j */\n      return fright->op2;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB any ADD)\nLJFOLDF(simplify_intsubadd_rightcancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fright);\n    if (fins->op1 == fright->op1) {  /* i - (i + j) ==> 0 - j */\n      fins->op2 = fright->op2;\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      return RETRYFOLD;\n    }\n    if (fins->op1 == fright->op2) {  /* i - (j + i) ==> 0 - j */\n      fins->op2 = fright->op1;\n      fins->op1 = (IRRef1)lj_ir_kint(J, 0);\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(SUB ADD ADD)\nLJFOLDF(simplify_intsubaddadd_cancel)\n{\n  if (!irt_isnum(fins->t)) {\n    PHIBARRIER(fleft);\n    PHIBARRIER(fright);\n    if (fleft->op1 == fright->op1) {  /* (i + j1) - (i + j2) ==> j1 - j2 */\n      fins->op1 = fleft->op2;\n      fins->op2 = fright->op2;\n      return RETRYFOLD;\n    }\n    if (fleft->op1 == fright->op2) {  /* (i + j1) - (j2 + i) ==> j1 - j2 */\n      fins->op1 = fleft->op2;\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n    if (fleft->op2 == fright->op1) {  /* (j1 + i) - (i + j2) ==> j1 - j2 */\n      fins->op1 = fleft->op1;\n      fins->op2 = fright->op2;\n      return RETRYFOLD;\n    }\n    if (fleft->op2 == fright->op2) {  /* (j1 + i) - (j2 + i) ==> j1 - j2 */\n      fins->op1 = fleft->op1;\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND any KINT)\nLJFOLD(BAND any KINT64)\nLJFOLDF(simplify_band_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i & 0 ==> 0 */\n    return RIGHTFOLD;\n  if (k == -1)  /* i & -1 ==> i */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BOR any KINT)\nLJFOLD(BOR any KINT64)\nLJFOLDF(simplify_bor_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i | 0 ==> i */\n    return LEFTFOLD;\n  if (k == -1)  /* i | -1 ==> -1 */\n    return RIGHTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BXOR any KINT)\nLJFOLD(BXOR any KINT64)\nLJFOLDF(simplify_bxor_k)\n{\n  int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :\n\t\t\t\t     (int64_t)ir_k64(fright)->u64;\n  if (k == 0)  /* i xor 0 ==> i */\n    return LEFTFOLD;\n  if (k == -1) {  /* i xor -1 ==> ~i */\n    fins->o = IR_BNOT;\n    fins->op2 = 0;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL any KINT)\nLJFOLD(BSHR any KINT)\nLJFOLD(BSAR any KINT)\nLJFOLD(BROL any KINT)\nLJFOLD(BROR any KINT)\nLJFOLDF(simplify_shift_ik)\n{\n  int32_t mask = irt_is64(fins->t) ? 63 : 31;\n  int32_t k = (fright->i & mask);\n  if (k == 0)  /* i o 0 ==> i */\n    return LEFTFOLD;\n  if (k == 1 && fins->o == IR_BSHL) {  /* i << 1 ==> i + i */\n    fins->o = IR_ADD;\n    fins->op2 = fins->op1;\n    return RETRYFOLD;\n  }\n  if (k != fright->i) {  /* i o k ==> i o (k & mask) */\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;\n  }\n#ifndef LJ_TARGET_UNIFYROT\n  if (fins->o == IR_BROR) {  /* bror(i, k) ==> brol(i, (-k)&mask) */\n    fins->o = IR_BROL;\n    fins->op2 = (IRRef1)lj_ir_kint(J, (-k)&mask);\n    return RETRYFOLD;\n  }\n#endif\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL any BAND)\nLJFOLD(BSHR any BAND)\nLJFOLD(BSAR any BAND)\nLJFOLD(BROL any BAND)\nLJFOLD(BROR any BAND)\nLJFOLDF(simplify_shift_andk)\n{\n  IRIns *irk = IR(fright->op2);\n  PHIBARRIER(fright);\n  if ((fins->o < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&\n      irk->o == IR_KINT) {  /* i o (j & mask) ==> i o j */\n    int32_t mask = irt_is64(fins->t) ? 63 : 31;\n    int32_t k = irk->i & mask;\n    if (k == mask) {\n      fins->op2 = fright->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL KINT any)\nLJFOLD(BSHR KINT any)\nLJFOLD(BSHL KINT64 any)\nLJFOLD(BSHR KINT64 any)\nLJFOLDF(simplify_shift1_ki)\n{\n  int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :\n\t\t\t\t    (int64_t)ir_k64(fleft)->u64;\n  if (k == 0)  /* 0 o i ==> 0 */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSAR KINT any)\nLJFOLD(BROL KINT any)\nLJFOLD(BROR KINT any)\nLJFOLD(BSAR KINT64 any)\nLJFOLD(BROL KINT64 any)\nLJFOLD(BROR KINT64 any)\nLJFOLDF(simplify_shift2_ki)\n{\n  int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :\n\t\t\t\t    (int64_t)ir_k64(fleft)->u64;\n  if (k == 0 || k == -1)  /* 0 o i ==> 0; -1 o i ==> -1 */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL BAND KINT)\nLJFOLD(BSHR BAND KINT)\nLJFOLD(BROL BAND KINT)\nLJFOLD(BROR BAND KINT)\nLJFOLDF(simplify_shiftk_andk)\n{\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);\n  if (irk->o == IR_KINT) {  /* (i & k1) o k2 ==> (i o k2) & (k1 o k2) */\n    int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);\n    fins->op1 = fleft->op1;\n    fins->op1 = (IRRef1)lj_opt_fold(J);\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    fins->ot = IRTI(IR_BAND);\n    return RETRYFOLD;\n  } else if (irk->o == IR_KINT64) {\n    uint64_t k = kfold_int64arith(J, ir_k64(irk)->u64, fright->i,\n\t\t\t\t  (IROp)fins->o);\n    IROpT ot = fleft->ot;\n    fins->op1 = fleft->op1;\n    fins->op1 = (IRRef1)lj_opt_fold(J);\n    fins->op2 = (IRRef1)lj_ir_kint64(J, k);\n    fins->ot = ot;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND BSHL KINT)\nLJFOLD(BAND BSHR KINT)\nLJFOLDF(simplify_andk_shiftk)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT &&\n      kfold_intop(-1, irk->i, (IROp)fleft->o) == fright->i)\n    return LEFTFOLD;  /* (i o k1) & k2 ==> i, if (-1 o k1) == k2 */\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND BOR KINT)\nLJFOLD(BOR BAND KINT)\nLJFOLDF(simplify_andor_k)\n{\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);\n  if (irk->o == IR_KINT) {\n    int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);\n    /* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */\n    /* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */\n    if (k == (fins->o == IR_BAND ? 0 : -1)) {\n      fins->op1 = fleft->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND BOR KINT64)\nLJFOLD(BOR BAND KINT64)\nLJFOLDF(simplify_andor_k64)\n{\n#if LJ_HASFFI\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);\n  if (irk->o == IR_KINT64) {\n    uint64_t k = kfold_int64arith(J, ir_k64(irk)->u64, ir_k64(fright)->u64,\n\t\t\t\t  (IROp)fins->o);\n    /* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */\n    /* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */\n    if (k == (fins->o == IR_BAND ? (uint64_t)0 : ~(uint64_t)0)) {\n      fins->op1 = fleft->op1;\n      return RETRYFOLD;\n    }\n  }\n  return NEXTFOLD;\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\n/* -- Reassociation ------------------------------------------------------- */\n\nLJFOLD(ADD ADD KINT)\nLJFOLD(MUL MUL KINT)\nLJFOLD(BAND BAND KINT)\nLJFOLD(BOR BOR KINT)\nLJFOLD(BXOR BXOR KINT)\nLJFOLDF(reassoc_intarith_k)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT) {\n    int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);\n    if (k == irk->i)  /* (i o k1) o k2 ==> i o k1, if (k1 o k2) == k1. */\n      return LEFTFOLD;\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;  /* (i o k1) o k2 ==> i o (k1 o k2) */\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(ADD ADD KINT64)\nLJFOLD(MUL MUL KINT64)\nLJFOLD(BAND BAND KINT64)\nLJFOLD(BOR BOR KINT64)\nLJFOLD(BXOR BXOR KINT64)\nLJFOLDF(reassoc_intarith_k64)\n{\n#if LJ_HASFFI\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT64) {\n    uint64_t k = kfold_int64arith(J, ir_k64(irk)->u64, ir_k64(fright)->u64,\n\t\t\t\t  (IROp)fins->o);\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint64(J, k);\n    return RETRYFOLD;  /* (i o k1) o k2 ==> i o (k1 o k2) */\n  }\n  return NEXTFOLD;\n#else\n  UNUSED(J); lj_assertJ(0, \"FFI IR op without FFI\"); return FAILFOLD;\n#endif\n}\n\nLJFOLD(BAND BAND any)\nLJFOLD(BOR BOR any)\nLJFOLDF(reassoc_dup)\n{\n  if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2)\n    return LEFTFOLD;  /* (a o b) o a ==> a o b; (a o b) o b ==> a o b */\n  return NEXTFOLD;\n}\n\nLJFOLD(MIN MIN any)\nLJFOLD(MAX MAX any)\nLJFOLDF(reassoc_dup_minmax)\n{\n  if (fins->op2 == fleft->op2)\n    return LEFTFOLD;  /* (a o b) o b ==> a o b */\n  return NEXTFOLD;\n}\n\nLJFOLD(BXOR BXOR any)\nLJFOLDF(reassoc_bxor)\n{\n  PHIBARRIER(fleft);\n  if (fins->op2 == fleft->op1)  /* (a xor b) xor a ==> b */\n    return fleft->op2;\n  if (fins->op2 == fleft->op2)  /* (a xor b) xor b ==> a */\n    return fleft->op1;\n  return NEXTFOLD;\n}\n\nLJFOLD(BSHL BSHL KINT)\nLJFOLD(BSHR BSHR KINT)\nLJFOLD(BSAR BSAR KINT)\nLJFOLD(BROL BROL KINT)\nLJFOLD(BROR BROR KINT)\nLJFOLDF(reassoc_shift)\n{\n  IRIns *irk = IR(fleft->op2);\n  PHIBARRIER(fleft);  /* The (shift any KINT) rule covers k2 == 0 and more. */\n  if (irk->o == IR_KINT) {  /* (i o k1) o k2 ==> i o (k1 + k2) */\n    int32_t mask = irt_is64(fins->t) ? 63 : 31;\n    int32_t k = (irk->i & mask) + (fright->i & mask);\n    if (k > mask) {  /* Combined shift too wide? */\n      if (fins->o == IR_BSHL || fins->o == IR_BSHR)\n\treturn mask == 31 ? INTFOLD(0) : INT64FOLD(0);\n      else if (fins->o == IR_BSAR)\n\tk = mask;\n      else\n\tk &= mask;\n    }\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, k);\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(MIN MIN KINT)\nLJFOLD(MAX MAX KINT)\nLJFOLDF(reassoc_minmax_k)\n{\n  IRIns *irk = IR(fleft->op2);\n  if (irk->o == IR_KINT) {\n    int32_t a = irk->i;\n    int32_t y = kfold_intop(a, fright->i, fins->o);\n    if (a == y)  /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */\n      return LEFTFOLD;\n    PHIBARRIER(fleft);\n    fins->op1 = fleft->op1;\n    fins->op2 = (IRRef1)lj_ir_kint(J, y);\n    return RETRYFOLD;  /* (x o k1) o k2 ==> x o (k1 o k2) */\n  }\n  return NEXTFOLD;\n}\n\n/* -- Array bounds check elimination -------------------------------------- */\n\n/* Eliminate ABC across PHIs to handle t[i-1] forwarding case.\n** ABC(asize, (i+k)+(-k)) ==> ABC(asize, i), but only if it already exists.\n** Could be generalized to (i+k1)+k2 ==> i+(k1+k2), but needs better disambig.\n*/\nLJFOLD(ABC any ADD)\nLJFOLDF(abc_fwd)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {\n    if (irref_isk(fright->op2)) {\n      IRIns *add2 = IR(fright->op1);\n      if (add2->o == IR_ADD && irref_isk(add2->op2) &&\n\t  IR(fright->op2)->i == -IR(add2->op2)->i) {\n\tIRRef ref = J->chain[IR_ABC];\n\tIRRef lim = add2->op1;\n\tif (fins->op1 > lim) lim = fins->op1;\n\twhile (ref > lim) {\n\t  IRIns *ir = IR(ref);\n\t  if (ir->op1 == fins->op1 && ir->op2 == add2->op1)\n\t    return DROPFOLD;\n\t  ref = ir->prev;\n\t}\n      }\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* Eliminate ABC for constants.\n** ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2))\n** Drop second ABC if k2 is lower. Otherwise patch first ABC with k2.\n*/\nLJFOLD(ABC any KINT)\nLJFOLDF(abc_k)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {\n    IRRef ref = J->chain[IR_ABC];\n    IRRef asize = fins->op1;\n    while (ref > asize) {\n      IRIns *ir = IR(ref);\n      if (ir->op1 == asize && irref_isk(ir->op2)) {\n\tint32_t k = IR(ir->op2)->i;\n\tif (fright->i > k)\n\t  ir->op2 = fins->op2;\n\treturn DROPFOLD;\n      }\n      ref = ir->prev;\n    }\n    return EMITFOLD;  /* Already performed CSE. */\n  }\n  return NEXTFOLD;\n}\n\n/* Eliminate invariant ABC inside loop. */\nLJFOLD(ABC any any)\nLJFOLDF(abc_invar)\n{\n  /* Invariant ABC marked as PTR. Drop if op1 is invariant, too. */\n  if (!irt_isint(fins->t) && fins->op1 < J->chain[IR_LOOP] &&\n      !irt_isphi(IR(fins->op1)->t))\n    return DROPFOLD;\n  return NEXTFOLD;\n}\n\n/* -- Commutativity ------------------------------------------------------- */\n\n/* The refs of commutative ops are canonicalized. Lower refs go to the right.\n** Rationale behind this:\n** - It (also) moves constants to the right.\n** - It reduces the number of FOLD rules (e.g. (BOR any KINT) suffices).\n** - It helps CSE to find more matches.\n** - The assembler generates better code with constants at the right.\n*/\n\nLJFOLD(ADD any any)\nLJFOLD(MUL any any)\nLJFOLD(ADDOV any any)\nLJFOLD(MULOV any any)\nLJFOLDF(comm_swap)\n{\n  if (fins->op1 < fins->op2) {  /* Move lower ref to the right. */\n    IRRef1 tmp = fins->op1;\n    fins->op1 = fins->op2;\n    fins->op2 = tmp;\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(EQ any any)\nLJFOLD(NE any any)\nLJFOLDF(comm_equal)\n{\n  /* For non-numbers only: x == x ==> drop; x ~= x ==> fail */\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))\n    return CONDFOLD(fins->o == IR_EQ);\n  return fold_comm_swap(J);\n}\n\nLJFOLD(LT any any)\nLJFOLD(GE any any)\nLJFOLD(LE any any)\nLJFOLD(GT any any)\nLJFOLD(ULT any any)\nLJFOLD(UGE any any)\nLJFOLD(ULE any any)\nLJFOLD(UGT any any)\nLJFOLDF(comm_comp)\n{\n  /* For non-numbers only: x <=> x ==> drop; x <> x ==> fail */\n  if (fins->op1 == fins->op2 && !irt_isnum(fins->t))\n    return CONDFOLD((fins->o ^ (fins->o >> 1)) & 1);\n  if (fins->op1 < fins->op2) {  /* Move lower ref to the right. */\n    IRRef1 tmp = fins->op1;\n    fins->op1 = fins->op2;\n    fins->op2 = tmp;\n    fins->o ^= 3; /* GT <-> LT, GE <-> LE, does not affect U */\n    return RETRYFOLD;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(BAND any any)\nLJFOLD(BOR any any)\nLJFOLDF(comm_dup)\n{\n  if (fins->op1 == fins->op2)  /* x o x ==> x */\n    return LEFTFOLD;\n  return fold_comm_swap(J);\n}\n\nLJFOLD(MIN any any)\nLJFOLD(MAX any any)\nLJFOLDF(comm_dup_minmax)\n{\n  if (fins->op1 == fins->op2)  /* x o x ==> x */\n    return LEFTFOLD;\n  return NEXTFOLD;\n}\n\nLJFOLD(BXOR any any)\nLJFOLDF(comm_bxor)\n{\n  if (fins->op1 == fins->op2)  /* i xor i ==> 0 */\n    return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);\n  return fold_comm_swap(J);\n}\n\n/* -- Simplification of compound expressions ------------------------------ */\n\nstatic TRef kfold_xload(jit_State *J, IRIns *ir, const void *p)\n{\n  int32_t k;\n  switch (irt_type(ir->t)) {\n  case IRT_NUM: return lj_ir_knum_u64(J, *(uint64_t *)p);\n  case IRT_I8: k = (int32_t)*(int8_t *)p; break;\n  case IRT_U8: k = (int32_t)*(uint8_t *)p; break;\n  case IRT_I16: k = (int32_t)(int16_t)lj_getu16(p); break;\n  case IRT_U16: k = (int32_t)(uint16_t)lj_getu16(p); break;\n  case IRT_INT: case IRT_U32: k = (int32_t)lj_getu32(p); break;\n  case IRT_I64: case IRT_U64: return lj_ir_kint64(J, *(uint64_t *)p);\n  default: return 0;\n  }\n  return lj_ir_kint(J, k);\n}\n\n/* Turn: string.sub(str, a, b) == kstr\n** into: string.byte(str, a) == string.byte(kstr, 1) etc.\n** Note: this creates unaligned XLOADs on x86/x64.\n*/\nLJFOLD(EQ SNEW KGC)\nLJFOLD(NE SNEW KGC)\nLJFOLDF(merge_eqne_snew_kgc)\n{\n  GCstr *kstr = ir_kstr(fright);\n  int32_t len = (int32_t)kstr->len;\n  lj_assertJ(irt_isstr(fins->t), \"bad equality IR type\");\n\n#if LJ_TARGET_UNALIGNED\n#define FOLD_SNEW_MAX_LEN\t4  /* Handle string lengths 0, 1, 2, 3, 4. */\n#define FOLD_SNEW_TYPE8\t\tIRT_I8\t/* Creates shorter immediates. */\n#else\n#define FOLD_SNEW_MAX_LEN\t1  /* Handle string lengths 0 or 1. */\n#define FOLD_SNEW_TYPE8\t\tIRT_U8  /* Prefer unsigned loads. */\n#endif\n\n  PHIBARRIER(fleft);\n  if (len <= FOLD_SNEW_MAX_LEN) {\n    IROp op = (IROp)fins->o;\n    IRRef strref = fleft->op1;\n    if (IR(strref)->o != IR_STRREF)\n      return NEXTFOLD;\n    if (op == IR_EQ) {\n      emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len));\n      /* Caveat: fins/fleft/fright is no longer valid after emitir. */\n    } else {\n      /* NE is not expanded since this would need an OR of two conds. */\n      if (!irref_isk(fleft->op2))  /* Only handle the constant length case. */\n\treturn NEXTFOLD;\n      if (IR(fleft->op2)->i != len)\n\treturn DROPFOLD;\n    }\n    if (len > 0) {\n      /* A 4 byte load for length 3 is ok -- all strings have an extra NUL. */\n      uint16_t ot = (uint16_t)(len == 1 ? IRT(IR_XLOAD, FOLD_SNEW_TYPE8) :\n\t\t\t       len == 2 ? IRT(IR_XLOAD, IRT_U16) :\n\t\t\t       IRTI(IR_XLOAD));\n      TRef tmp = emitir(ot, strref,\n\t\t\tIRXLOAD_READONLY | (len > 1 ? IRXLOAD_UNALIGNED : 0));\n      TRef val = kfold_xload(J, IR(tref_ref(tmp)), strdata(kstr));\n      if (len == 3)\n\ttmp = emitir(IRTI(IR_BAND), tmp,\n\t\t     lj_ir_kint(J, LJ_ENDIAN_SELECT(0x00ffffff, 0xffffff00)));\n      fins->op1 = (IRRef1)tmp;\n      fins->op2 = (IRRef1)val;\n      fins->ot = (IROpT)IRTGI(op);\n      return RETRYFOLD;\n    } else {\n      return DROPFOLD;\n    }\n  }\n  return NEXTFOLD;\n}\n\n/* -- Loads --------------------------------------------------------------- */\n\n/* Loads cannot be folded or passed on to CSE in general.\n** Alias analysis is needed to check for forwarding opportunities.\n**\n** Caveat: *all* loads must be listed here or they end up at CSE!\n*/\n\nLJFOLD(ALOAD any)\nLJFOLDX(lj_opt_fwd_aload)\n\n/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */\nLJFOLD(HLOAD KKPTR)\nLJFOLDF(kfold_hload_kkptr)\n{\n  UNUSED(J);\n  lj_assertJ(ir_kptr(fleft) == niltvg(J2G(J)), \"expected niltv\");\n  return TREF_NIL;\n}\n\nLJFOLD(HLOAD any)\nLJFOLDX(lj_opt_fwd_hload)\n\nLJFOLD(ULOAD any)\nLJFOLDX(lj_opt_fwd_uload)\n\nLJFOLD(ALEN any any)\nLJFOLDX(lj_opt_fwd_alen)\n\n/* Upvalue refs are really loads, but there are no corresponding stores.\n** So CSE is ok for them, except for UREFO across a GC step (see below).\n** If the referenced function is const, its upvalue addresses are const, too.\n** This can be used to improve CSE by looking for the same address,\n** even if the upvalues originate from a different function.\n*/\nLJFOLD(UREFO KGC any)\nLJFOLD(UREFC KGC any)\nLJFOLDF(cse_uref)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    IRRef ref = J->chain[fins->o];\n    GCfunc *fn = ir_kfunc(fleft);\n    GCupval *uv = gco2uv(gcref(fn->l.uvptr[(fins->op2 >> 8)]));\n    while (ref > 0) {\n      IRIns *ir = IR(ref);\n      if (irref_isk(ir->op1)) {\n\tGCfunc *fn2 = ir_kfunc(IR(ir->op1));\n\tif (gco2uv(gcref(fn2->l.uvptr[(ir->op2 >> 8)])) == uv) {\n\t  if (fins->o == IR_UREFO && gcstep_barrier(J, ref))\n\t    break;\n\t  return ref;\n\t}\n      }\n      ref = ir->prev;\n    }\n  }\n  return EMITFOLD;\n}\n\nLJFOLD(HREFK any any)\nLJFOLDX(lj_opt_fwd_hrefk)\n\nLJFOLD(HREF TNEW any)\nLJFOLDF(fwd_href_tnew)\n{\n  if (lj_opt_fwd_href_nokey(J))\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  return NEXTFOLD;\n}\n\nLJFOLD(HREF TDUP KPRI)\nLJFOLD(HREF TDUP KGC)\nLJFOLD(HREF TDUP KNUM)\nLJFOLDF(fwd_href_tdup)\n{\n  TValue keyv;\n  lj_ir_kvalue(J->L, &keyv, fright);\n  if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) &&\n      lj_opt_fwd_href_nokey(J))\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  return NEXTFOLD;\n}\n\n/* We can safely FOLD/CSE array/hash refs and field loads, since there\n** are no corresponding stores. But we need to check for any NEWREF with\n** an aliased table, as it may invalidate all of the pointers and fields.\n** Only HREF needs the NEWREF check -- AREF and HREFK already depend on\n** FLOADs. And NEWREF itself is treated like a store (see below).\n** LREF is constant (per trace) since coroutine switches are not inlined.\n*/\nLJFOLD(FLOAD TNEW IRFL_TAB_ASIZE)\nLJFOLDF(fload_tab_tnew_asize)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD(fleft->op1);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TNEW IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_tnew_hmask)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((1 << fleft->op2)-1);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TDUP IRFL_TAB_ASIZE)\nLJFOLDF(fload_tab_tdup_asize)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->asize);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TDUP IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_tdup_hmask)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))\n    return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->hmask);\n  return NEXTFOLD;\n}\n\nLJFOLD(HREF any any)\nLJFOLD(FLOAD any IRFL_TAB_ARRAY)\nLJFOLD(FLOAD any IRFL_TAB_NODE)\nLJFOLD(FLOAD any IRFL_TAB_ASIZE)\nLJFOLD(FLOAD any IRFL_TAB_HMASK)\nLJFOLDF(fload_tab_ah)\n{\n  TRef tr = lj_opt_cse(J);\n  return lj_opt_fwd_tptr(J, tref_ref(tr)) ? tr : EMITFOLD;\n}\n\n/* Strings are immutable, so we can safely FOLD/CSE the related FLOAD. */\nLJFOLD(FLOAD KGC IRFL_STR_LEN)\nLJFOLDF(fload_str_len_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return INTFOLD((int32_t)ir_kstr(fleft)->len);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD SNEW IRFL_STR_LEN)\nLJFOLDF(fload_str_len_snew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    PHIBARRIER(fleft);\n    return fleft->op2;\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD TOSTR IRFL_STR_LEN)\nLJFOLDF(fload_str_len_tostr)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && fleft->op2 == IRTOSTR_CHAR)\n    return INTFOLD(1);\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD any IRFL_SBUF_W)\nLJFOLD(FLOAD any IRFL_SBUF_E)\nLJFOLD(FLOAD any IRFL_SBUF_B)\nLJFOLD(FLOAD any IRFL_SBUF_L)\nLJFOLD(FLOAD any IRFL_SBUF_REF)\nLJFOLD(FLOAD any IRFL_SBUF_R)\nLJFOLDF(fload_sbuf)\n{\n  TRef tr = lj_opt_fwd_fload(J);\n  return lj_opt_fwd_sbuf(J, tref_ref(tr)) ? tr : EMITFOLD;\n}\n\n/* The fast function ID of function objects is immutable. */\nLJFOLD(FLOAD KGC IRFL_FUNC_FFID)\nLJFOLDF(fload_func_ffid_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return INTFOLD((int32_t)ir_kfunc(fleft)->c.ffid);\n  return NEXTFOLD;\n}\n\n/* The C type ID of cdata objects is immutable. */\nLJFOLD(FLOAD KGC IRFL_CDATA_CTYPEID)\nLJFOLDF(fload_cdata_typeid_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return INTFOLD((int32_t)ir_kcdata(fleft)->ctypeid);\n  return NEXTFOLD;\n}\n\n/* Get the contents of immutable cdata objects. */\nLJFOLD(FLOAD KGC IRFL_CDATA_PTR)\nLJFOLD(FLOAD KGC IRFL_CDATA_INT)\nLJFOLD(FLOAD KGC IRFL_CDATA_INT64)\nLJFOLDF(fload_cdata_int64_kgc)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {\n    void *p = cdataptr(ir_kcdata(fleft));\n    if (irt_is64(fins->t))\n      return INT64FOLD(*(uint64_t *)p);\n    else\n      return INTFOLD(*(int32_t *)p);\n  }\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD CNEW IRFL_CDATA_CTYPEID)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_CTYPEID)\nLJFOLDF(fload_cdata_typeid_cnew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return fleft->op1;  /* No PHI barrier needed. CNEW/CNEWI op1 is const. */\n  return NEXTFOLD;\n}\n\n/* Pointer, int and int64 cdata objects are immutable. */\nLJFOLD(FLOAD CNEWI IRFL_CDATA_PTR)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_INT)\nLJFOLD(FLOAD CNEWI IRFL_CDATA_INT64)\nLJFOLDF(fload_cdata_ptr_int64_cnew)\n{\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))\n    return fleft->op2;  /* Fold even across PHI to avoid allocations. */\n  return NEXTFOLD;\n}\n\nLJFOLD(FLOAD any IRFL_STR_LEN)\nLJFOLD(FLOAD any IRFL_FUNC_ENV)\nLJFOLD(FLOAD any IRFL_THREAD_ENV)\nLJFOLD(FLOAD any IRFL_CDATA_CTYPEID)\nLJFOLD(FLOAD any IRFL_CDATA_PTR)\nLJFOLD(FLOAD any IRFL_CDATA_INT)\nLJFOLD(FLOAD any IRFL_CDATA_INT64)\nLJFOLD(VLOAD any any)  /* Vararg loads have no corresponding stores. */\nLJFOLDX(lj_opt_cse)\n\n/* All other field loads need alias analysis. */\nLJFOLD(FLOAD any any)\nLJFOLDX(lj_opt_fwd_fload)\n\n/* This is for LOOP only. Recording handles SLOADs internally. */\nLJFOLD(SLOAD any any)\nLJFOLDF(fwd_sload)\n{\n  if ((fins->op2 & IRSLOAD_FRAME)) {\n    TRef tr = lj_opt_cse(J);\n    return tref_ref(tr) < J->chain[IR_RETF] ? EMITFOLD : tr;\n  } else {\n    lj_assertJ(J->slot[fins->op1] != 0, \"uninitialized slot accessed\");\n    return J->slot[fins->op1];\n  }\n}\n\n/* Only fold for KKPTR. The pointer _and_ the contents must be const. */\nLJFOLD(XLOAD KKPTR any)\nLJFOLDF(xload_kptr)\n{\n  TRef tr = kfold_xload(J, fins, ir_kptr(fleft));\n  return tr ? tr : NEXTFOLD;\n}\n\nLJFOLD(XLOAD any any)\nLJFOLDX(lj_opt_fwd_xload)\n\n/* -- Frame handling ------------------------------------------------------ */\n\n/* Prevent CSE of a REF_BASE operand across IR_RETF. */\nLJFOLD(SUB any BASE)\nLJFOLD(SUB BASE any)\nLJFOLD(EQ any BASE)\nLJFOLDF(fold_base)\n{\n  return lj_opt_cselim(J, J->chain[IR_RETF]);\n}\n\n/* -- Write barriers ------------------------------------------------------ */\n\n/* Write barriers are amenable to CSE, but not across any incremental\n** GC steps.\n**\n** The same logic applies to open upvalue references, because a stack\n** may be resized during a GC step (not the current stack, but maybe that\n** of a coroutine).\n*/\nLJFOLD(TBAR any)\nLJFOLD(OBAR any any)\nLJFOLD(UREFO any any)\nLJFOLDF(barrier_tab)\n{\n  TRef tr = lj_opt_cse(J);\n  if (gcstep_barrier(J, tref_ref(tr)))  /* CSE across GC step? */\n    return EMITFOLD;  /* Raw emit. Assumes fins is left intact by CSE. */\n  return tr;\n}\n\nLJFOLD(TBAR TNEW)\nLJFOLD(TBAR TDUP)\nLJFOLDF(barrier_tnew_tdup)\n{\n  /* New tables are always white and never need a barrier. */\n  if (fins->op1 < J->chain[IR_LOOP])  /* Except across a GC step. */\n    return NEXTFOLD;\n  return DROPFOLD;\n}\n\n/* -- Profiling ----------------------------------------------------------- */\n\nLJFOLD(PROF any any)\nLJFOLDF(prof)\n{\n  IRRef ref = J->chain[IR_PROF];\n  if (ref+1 == J->cur.nins)  /* Drop neighbouring IR_PROF. */\n    return ref;\n  return EMITFOLD;\n}\n\n/* -- Stores and allocations ---------------------------------------------- */\n\n/* Stores and allocations cannot be folded or passed on to CSE in general.\n** But some stores can be eliminated with dead-store elimination (DSE).\n**\n** Caveat: *all* stores and allocs must be listed here or they end up at CSE!\n*/\n\nLJFOLD(ASTORE any any)\nLJFOLD(HSTORE any any)\nLJFOLDX(lj_opt_dse_ahstore)\n\nLJFOLD(USTORE any any)\nLJFOLDX(lj_opt_dse_ustore)\n\nLJFOLD(FSTORE any any)\nLJFOLDX(lj_opt_dse_fstore)\n\nLJFOLD(XSTORE any any)\nLJFOLDX(lj_opt_dse_xstore)\n\nLJFOLD(NEWREF any any)  /* Treated like a store. */\nLJFOLD(TMPREF any any)\nLJFOLD(CALLA any any)\nLJFOLD(CALLL any any)  /* Safeguard fallback. */\nLJFOLD(CALLS any any)\nLJFOLD(CALLXS any any)\nLJFOLD(XBAR)\nLJFOLD(RETF any any)  /* Modifies BASE. */\nLJFOLD(TNEW any any)\nLJFOLD(TDUP any)\nLJFOLD(CNEW any any)\nLJFOLD(XSNEW any any)\nLJFOLDX(lj_ir_emit)\n\n/* ------------------------------------------------------------------------ */\n\n/* Every entry in the generated hash table is a 32 bit pattern:\n**\n** xxxxxxxx iiiiiii lllllll rrrrrrrrrr\n**\n**   xxxxxxxx = 8 bit index into fold function table\n**    iiiiiii = 7 bit folded instruction opcode\n**    lllllll = 7 bit left instruction opcode\n** rrrrrrrrrr = 8 bit right instruction opcode or 10 bits from literal field\n*/\n\n#include \"lj_folddef.h\"\n\n/* ------------------------------------------------------------------------ */\n\n/* Fold IR instruction. */\nTRef LJ_FASTCALL lj_opt_fold(jit_State *J)\n{\n  uint32_t key, any;\n  IRRef ref;\n\n  if (LJ_UNLIKELY((J->flags & JIT_F_OPT_MASK) != JIT_F_OPT_DEFAULT)) {\n    lj_assertJ(((JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE|JIT_F_OPT_DSE) |\n\t\tJIT_F_OPT_DEFAULT) == JIT_F_OPT_DEFAULT,\n\t       \"bad JIT_F_OPT_DEFAULT\");\n    /* Folding disabled? Chain to CSE, but not for loads/stores/allocs. */\n    if (!(J->flags & JIT_F_OPT_FOLD) && irm_kind(lj_ir_mode[fins->o]) == IRM_N)\n      return lj_opt_cse(J);\n\n    /* No FOLD, forwarding or CSE? Emit raw IR for loads, except for SLOAD. */\n    if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE)) !=\n\t\t    (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE) &&\n\tirm_kind(lj_ir_mode[fins->o]) == IRM_L && fins->o != IR_SLOAD)\n      return lj_ir_emit(J);\n\n    /* No FOLD or DSE? Emit raw IR for stores. */\n    if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_DSE)) !=\n\t\t    (JIT_F_OPT_FOLD|JIT_F_OPT_DSE) &&\n\tirm_kind(lj_ir_mode[fins->o]) == IRM_S)\n      return lj_ir_emit(J);\n  }\n\n  /* Fold engine start/retry point. */\nretry:\n  /* Construct key from opcode and operand opcodes (unless literal/none). */\n  key = ((uint32_t)fins->o << 17);\n  if (fins->op1 >= J->cur.nk) {\n    key += (uint32_t)IR(fins->op1)->o << 10;\n    *fleft = *IR(fins->op1);\n    if (fins->op1 < REF_TRUE)\n      fleft[1] = IR(fins->op1)[1];\n  }\n  if (fins->op2 >= J->cur.nk) {\n    key += (uint32_t)IR(fins->op2)->o;\n    *fright = *IR(fins->op2);\n    if (fins->op2 < REF_TRUE)\n      fright[1] = IR(fins->op2)[1];\n  } else {\n    key += (fins->op2 & 0x3ffu);  /* Literal mask. Must include IRCONV_*MASK. */\n  }\n\n  /* Check for a match in order from most specific to least specific. */\n  any = 0;\n  for (;;) {\n    uint32_t k = key | (any & 0x1ffff);\n    uint32_t h = fold_hashkey(k);\n    uint32_t fh = fold_hash[h];  /* Lookup key in semi-perfect hash table. */\n    if ((fh & 0xffffff) == k || (fh = fold_hash[h+1], (fh & 0xffffff) == k)) {\n      ref = (IRRef)tref_ref(fold_func[fh >> 24](J));\n      if (ref != NEXTFOLD)\n\tbreak;\n    }\n    if (any == 0xfffff)  /* Exhausted folding. Pass on to CSE. */\n      return lj_opt_cse(J);\n    any = (any | (any >> 10)) ^ 0xffc00;\n  }\n\n  /* Return value processing, ordered by frequency. */\n  if (LJ_LIKELY(ref >= MAX_FOLD))\n    return TREF(ref, irt_t(IR(ref)->t));\n  if (ref == RETRYFOLD)\n    goto retry;\n  if (ref == KINTFOLD)\n    return lj_ir_kint(J, fins->i);\n  if (ref == FAILFOLD)\n    lj_trace_err(J, LJ_TRERR_GFAIL);\n  lj_assertJ(ref == DROPFOLD, \"bad fold result\");\n  return REF_DROP;\n}\n\n/* -- Common-Subexpression Elimination ------------------------------------ */\n\n/* CSE an IR instruction. This is very fast due to the skip-list chains. */\nTRef LJ_FASTCALL lj_opt_cse(jit_State *J)\n{\n  /* Avoid narrow to wide store-to-load forwarding stall */\n  IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);\n  IROp op = fins->o;\n  if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {\n    /* Limited search for same operands in per-opcode chain. */\n    IRRef ref = J->chain[op];\n    IRRef lim = fins->op1;\n    if (fins->op2 > lim) lim = fins->op2;  /* Relies on lit < REF_BIAS. */\n    while (ref > lim) {\n      if (IR(ref)->op12 == op12)\n\treturn TREF(ref, irt_t(IR(ref)->t));  /* Common subexpression found. */\n      ref = IR(ref)->prev;\n    }\n  }\n  /* Otherwise emit IR (inlined for speed). */\n  {\n    IRRef ref = lj_ir_nextins(J);\n    IRIns *ir = IR(ref);\n    ir->prev = J->chain[op];\n    ir->op12 = op12;\n    J->chain[op] = (IRRef1)ref;\n    ir->o = fins->o;\n    J->guardemit.irt |= fins->t.irt;\n    return TREF(ref, irt_t((ir->t = fins->t)));\n  }\n}\n\n/* CSE with explicit search limit. */\nTRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim)\n{\n  IRRef ref = J->chain[fins->o];\n  IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);\n  while (ref > lim) {\n    if (IR(ref)->op12 == op12)\n      return ref;\n    ref = IR(ref)->prev;\n  }\n  return lj_ir_emit(J);\n}\n\n/* ------------------------------------------------------------------------ */\n\n#undef IR\n#undef fins\n#undef fleft\n#undef fright\n#undef knumleft\n#undef knumright\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_loop.c",
    "content": "/*\n** LOOP: Loop Optimizations.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_loop_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_vm.h\"\n\n/* Loop optimization:\n**\n** Traditional Loop-Invariant Code Motion (LICM) splits the instructions\n** of a loop into invariant and variant instructions. The invariant\n** instructions are hoisted out of the loop and only the variant\n** instructions remain inside the loop body.\n**\n** Unfortunately LICM is mostly useless for compiling dynamic languages.\n** The IR has many guards and most of the subsequent instructions are\n** control-dependent on them. The first non-hoistable guard would\n** effectively prevent hoisting of all subsequent instructions.\n**\n** That's why we use a special form of unrolling using copy-substitution,\n** combined with redundancy elimination:\n**\n** The recorded instruction stream is re-emitted to the compiler pipeline\n** with substituted operands. The substitution table is filled with the\n** refs returned by re-emitting each instruction. This can be done\n** on-the-fly, because the IR is in strict SSA form, where every ref is\n** defined before its use.\n**\n** This aproach generates two code sections, separated by the LOOP\n** instruction:\n**\n** 1. The recorded instructions form a kind of pre-roll for the loop. It\n** contains a mix of invariant and variant instructions and performs\n** exactly one loop iteration (but not necessarily the 1st iteration).\n**\n** 2. The loop body contains only the variant instructions and performs\n** all remaining loop iterations.\n**\n** On first sight that looks like a waste of space, because the variant\n** instructions are present twice. But the key insight is that the\n** pre-roll honors the control-dependencies for *both* the pre-roll itself\n** *and* the loop body!\n**\n** It also means one doesn't have to explicitly model control-dependencies\n** (which, BTW, wouldn't help LICM much). And it's much easier to\n** integrate sparse snapshotting with this approach.\n**\n** One of the nicest aspects of this approach is that all of the\n** optimizations of the compiler pipeline (FOLD, CSE, FWD, etc.) can be\n** reused with only minor restrictions (e.g. one should not fold\n** instructions across loop-carried dependencies).\n**\n** But in general all optimizations can be applied which only need to look\n** backwards into the generated instruction stream. At any point in time\n** during the copy-substitution process this contains both a static loop\n** iteration (the pre-roll) and a dynamic one (from the to-be-copied\n** instruction up to the end of the partial loop body).\n**\n** Since control-dependencies are implicitly kept, CSE also applies to all\n** kinds of guards. The major advantage is that all invariant guards can\n** be hoisted, too.\n**\n** Load/store forwarding works across loop iterations, too. This is\n** important if loop-carried dependencies are kept in upvalues or tables.\n** E.g. 'self.idx = self.idx + 1' deep down in some OO-style method may\n** become a forwarded loop-recurrence after inlining.\n**\n** Since the IR is in SSA form, loop-carried dependencies have to be\n** modeled with PHI instructions. The potential candidates for PHIs are\n** collected on-the-fly during copy-substitution. After eliminating the\n** redundant ones, PHI instructions are emitted *below* the loop body.\n**\n** Note that this departure from traditional SSA form doesn't change the\n** semantics of the PHI instructions themselves. But it greatly simplifies\n** on-the-fly generation of the IR and the machine code.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- PHI elimination ----------------------------------------------------- */\n\n/* Emit or eliminate collected PHIs. */\nstatic void loop_emit_phi(jit_State *J, IRRef1 *subst, IRRef1 *phi, IRRef nphi,\n\t\t\t  SnapNo onsnap)\n{\n  int passx = 0;\n  IRRef i, j, nslots;\n  IRRef invar = J->chain[IR_LOOP];\n  /* Pass #1: mark redundant and potentially redundant PHIs. */\n  for (i = 0, j = 0; i < nphi; i++) {\n    IRRef lref = phi[i];\n    IRRef rref = subst[lref];\n    if (lref == rref || rref == REF_DROP) {  /* Invariants are redundant. */\n      irt_clearphi(IR(lref)->t);\n    } else {\n      phi[j++] = (IRRef1)lref;\n      if (!(IR(rref)->op1 == lref || IR(rref)->op2 == lref)) {\n\t/* Quick check for simple recurrences failed, need pass2. */\n\tirt_setmark(IR(lref)->t);\n\tpassx = 1;\n      }\n    }\n  }\n  nphi = j;\n  /* Pass #2: traverse variant part and clear marks of non-redundant PHIs. */\n  if (passx) {\n    SnapNo s;\n    for (i = J->cur.nins-1; i > invar; i--) {\n      IRIns *ir = IR(i);\n      if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);\n      if (!irref_isk(ir->op1)) {\n\tirt_clearmark(IR(ir->op1)->t);\n\tif (ir->op1 < invar &&\n\t    ir->o >= IR_CALLN && ir->o <= IR_CARG) {  /* ORDER IR */\n\t  ir = IR(ir->op1);\n\t  while (ir->o == IR_CARG) {\n\t    if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);\n\t    if (irref_isk(ir->op1)) break;\n\t    ir = IR(ir->op1);\n\t    irt_clearmark(ir->t);\n\t  }\n\t}\n      }\n    }\n    for (s = J->cur.nsnap-1; s >= onsnap; s--) {\n      SnapShot *snap = &J->cur.snap[s];\n      SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n      MSize n, nent = snap->nent;\n      for (n = 0; n < nent; n++) {\n\tIRRef ref = snap_ref(map[n]);\n\tif (!irref_isk(ref)) irt_clearmark(IR(ref)->t);\n      }\n    }\n  }\n  /* Pass #3: add PHIs for variant slots without a corresponding SLOAD. */\n  nslots = J->baseslot+J->maxslot;\n  for (i = 1; i < nslots; i++) {\n    IRRef ref = tref_ref(J->slot[i]);\n    while (!irref_isk(ref) && ref != subst[ref]) {\n      IRIns *ir = IR(ref);\n      irt_clearmark(ir->t);  /* Unmark potential uses, too. */\n      if (irt_isphi(ir->t) || irt_ispri(ir->t))\n\tbreak;\n      irt_setphi(ir->t);\n      if (nphi >= LJ_MAX_PHI)\n\tlj_trace_err(J, LJ_TRERR_PHIOV);\n      phi[nphi++] = (IRRef1)ref;\n      ref = subst[ref];\n      if (ref > invar)\n\tbreak;\n    }\n  }\n  /* Pass #4: propagate non-redundant PHIs. */\n  while (passx) {\n    passx = 0;\n    for (i = 0; i < nphi; i++) {\n      IRRef lref = phi[i];\n      IRIns *ir = IR(lref);\n      if (!irt_ismarked(ir->t)) {  /* Propagate only from unmarked PHIs. */\n\tIRIns *irr = IR(subst[lref]);\n\tif (irt_ismarked(irr->t)) {  /* Right ref points to other PHI? */\n\t  irt_clearmark(irr->t);  /* Mark that PHI as non-redundant. */\n\t  passx = 1;  /* Retry. */\n\t}\n      }\n    }\n  }\n  /* Pass #5: emit PHI instructions or eliminate PHIs. */\n  for (i = 0; i < nphi; i++) {\n    IRRef lref = phi[i];\n    IRIns *ir = IR(lref);\n    if (!irt_ismarked(ir->t)) {  /* Emit PHI if not marked. */\n      IRRef rref = subst[lref];\n      if (rref > invar)\n\tirt_setphi(IR(rref)->t);\n      emitir_raw(IRT(IR_PHI, irt_type(ir->t)), lref, rref);\n    } else {  /* Otherwise eliminate PHI. */\n      irt_clearmark(ir->t);\n      irt_clearphi(ir->t);\n    }\n  }\n}\n\n/* -- Loop unrolling using copy-substitution ------------------------------ */\n\n/* Copy-substitute snapshot. */\nstatic void loop_subst_snap(jit_State *J, SnapShot *osnap,\n\t\t\t    SnapEntry *loopmap, IRRef1 *subst)\n{\n  SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs];\n  SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)];\n  MSize nmapofs;\n  MSize on, ln, nn, onent = osnap->nent;\n  BCReg nslots = osnap->nslots;\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap];\n  if (irt_isguard(J->guardemit)) {  /* Guard inbetween? */\n    nmapofs = J->cur.nsnapmap;\n    J->cur.nsnap++;  /* Add new snapshot. */\n  } else {  /* Otherwise overwrite previous snapshot. */\n    snap--;\n    nmapofs = snap->mapofs;\n  }\n  J->guardemit.irt = 0;\n  /* Setup new snapshot. */\n  snap->mapofs = (uint32_t)nmapofs;\n  snap->ref = (IRRef1)J->cur.nins;\n  snap->mcofs = 0;\n  snap->nslots = nslots;\n  snap->topslot = osnap->topslot;\n  snap->count = 0;\n  nmap = &J->cur.snapmap[nmapofs];\n  /* Substitute snapshot slots. */\n  on = ln = nn = 0;\n  while (on < onent) {\n    SnapEntry osn = omap[on], lsn = loopmap[ln];\n    if (snap_slot(lsn) < snap_slot(osn)) {  /* Copy slot from loop map. */\n      nmap[nn++] = lsn;\n      ln++;\n    } else {  /* Copy substituted slot from snapshot map. */\n      if (snap_slot(lsn) == snap_slot(osn)) ln++;  /* Shadowed loop slot. */\n      if (!irref_isk(snap_ref(osn)))\n\tosn = snap_setref(osn, subst[snap_ref(osn)]);\n      nmap[nn++] = osn;\n      on++;\n    }\n  }\n  while (snap_slot(loopmap[ln]) < nslots)  /* Copy remaining loop slots. */\n    nmap[nn++] = loopmap[ln++];\n  snap->nent = (uint8_t)nn;\n  omap += onent;\n  nmap += nn;\n  while (omap < nextmap)  /* Copy PC + frame links. */\n    *nmap++ = *omap++;\n  J->cur.nsnapmap = (uint32_t)(nmap - J->cur.snapmap);\n}\n\ntypedef struct LoopState {\n  jit_State *J;\n  IRRef1 *subst;\n  MSize sizesubst;\n} LoopState;\n\n/* Unroll loop. */\nstatic void loop_unroll(LoopState *lps)\n{\n  jit_State *J = lps->J;\n  IRRef1 phi[LJ_MAX_PHI];\n  uint32_t nphi = 0;\n  IRRef1 *subst;\n  SnapNo onsnap;\n  SnapShot *osnap, *loopsnap;\n  SnapEntry *loopmap, *psentinel;\n  IRRef ins, invar;\n\n  /* Allocate substitution table.\n  ** Only non-constant refs in [REF_BIAS,invar) are valid indexes.\n  */\n  invar = J->cur.nins;\n  lps->sizesubst = invar - REF_BIAS;\n  lps->subst = lj_mem_newvec(J->L, lps->sizesubst, IRRef1);\n  subst = lps->subst - REF_BIAS;\n  subst[REF_BASE] = REF_BASE;\n\n  /* LOOP separates the pre-roll from the loop body. */\n  emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0);\n\n  /* Grow snapshot buffer and map for copy-substituted snapshots.\n  ** Need up to twice the number of snapshots minus #0 and loop snapshot.\n  ** Need up to twice the number of entries plus fallback substitutions\n  ** from the loop snapshot entries for each new snapshot.\n  ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap!\n  */\n  onsnap = J->cur.nsnap;\n  lj_snap_grow_buf(J, 2*onsnap-2);\n  lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent);\n\n  /* The loop snapshot is used for fallback substitutions. */\n  loopsnap = &J->cur.snap[onsnap-1];\n  loopmap = &J->cur.snapmap[loopsnap->mapofs];\n  /* The PC of snapshot #0 and the loop snapshot must match. */\n  psentinel = &loopmap[loopsnap->nent];\n  lj_assertJ(*psentinel == J->cur.snapmap[J->cur.snap[0].nent],\n\t     \"mismatched PC for loop snapshot\");\n  *psentinel = SNAP(255, 0, 0);  /* Replace PC with temporary sentinel. */\n\n  /* Start substitution with snapshot #1 (#0 is empty for root traces). */\n  osnap = &J->cur.snap[1];\n\n  /* Copy and substitute all recorded instructions and snapshots. */\n  for (ins = REF_FIRST; ins < invar; ins++) {\n    IRIns *ir;\n    IRRef op1, op2;\n\n    if (ins >= osnap->ref)  /* Instruction belongs to next snapshot? */\n      loop_subst_snap(J, osnap++, loopmap, subst);  /* Copy-substitute it. */\n\n    /* Substitute instruction operands. */\n    ir = IR(ins);\n    op1 = ir->op1;\n    if (!irref_isk(op1)) op1 = subst[op1];\n    op2 = ir->op2;\n    if (!irref_isk(op2)) op2 = subst[op2];\n    if (irm_kind(lj_ir_mode[ir->o]) == IRM_N &&\n\top1 == ir->op1 && op2 == ir->op2) {  /* Regular invariant ins? */\n      subst[ins] = (IRRef1)ins;  /* Shortcut. */\n    } else {\n      /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */\n      IRType1 t = ir->t;  /* Get this first, since emitir may invalidate ir. */\n      IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2));\n      subst[ins] = (IRRef1)ref;\n      if (ref != ins) {\n\tIRIns *irr = IR(ref);\n\tif (ref < invar) {  /* Loop-carried dependency? */\n\t  /* Potential PHI? */\n\t  if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) {\n\t    irt_setphi(irr->t);\n\t    if (nphi >= LJ_MAX_PHI)\n\t      lj_trace_err(J, LJ_TRERR_PHIOV);\n\t    phi[nphi++] = (IRRef1)ref;\n\t  }\n\t  /* Check all loop-carried dependencies for type instability. */\n\t  if (!irt_sametype(t, irr->t)) {\n\t    if (irt_isinteger(t) && irt_isinteger(irr->t))\n\t      continue;\n\t    else if (irt_isnum(t) && irt_isinteger(irr->t))  /* Fix int->num. */\n\t      ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT));\n\t    else if (irt_isnum(irr->t) && irt_isinteger(t))  /* Fix num->int. */\n\t      ref = tref_ref(emitir(IRTGI(IR_CONV), ref,\n\t\t\t\t    IRCONV_INT_NUM|IRCONV_CHECK));\n\t    else\n\t      lj_trace_err(J, LJ_TRERR_TYPEINS);\n\t    subst[ins] = (IRRef1)ref;\n\t    irr = IR(ref);\n\t    goto phiconv;\n\t  }\n\t} else if (ref != REF_DROP && ref > invar &&\n\t\t   ((irr->o == IR_CONV && irr->op1 < invar) ||\n\t\t    (irr->o == IR_ALEN && irr->op2 < invar &&\n\t\t\t\t\t  irr->op2 != REF_NIL))) {\n\t  /* May need an extra PHI for a CONV or ALEN hint. */\n\t  ref = irr->o == IR_CONV ? irr->op1 : irr->op2;\n\t  irr = IR(ref);\n\tphiconv:\n\t  if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) {\n\t    irt_setphi(irr->t);\n\t    if (nphi >= LJ_MAX_PHI)\n\t      lj_trace_err(J, LJ_TRERR_PHIOV);\n\t    phi[nphi++] = (IRRef1)ref;\n\t  }\n\t}\n      }\n    }\n  }\n  if (!irt_isguard(J->guardemit))  /* Drop redundant snapshot. */\n    J->cur.nsnapmap = (uint32_t)J->cur.snap[--J->cur.nsnap].mapofs;\n  lj_assertJ(J->cur.nsnapmap <= J->sizesnapmap, \"bad snapshot map index\");\n  *psentinel = J->cur.snapmap[J->cur.snap[0].nent];  /* Restore PC. */\n\n  loop_emit_phi(J, subst, phi, nphi, onsnap);\n}\n\n/* Undo any partial changes made by the loop optimization. */\nstatic void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap)\n{\n  ptrdiff_t i;\n  SnapShot *snap = &J->cur.snap[nsnap-1];\n  SnapEntry *map = J->cur.snapmap;\n  map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent];  /* Restore PC. */\n  J->cur.nsnapmap = (uint32_t)nsnapmap;\n  J->cur.nsnap = nsnap;\n  J->guardemit.irt = 0;\n  lj_ir_rollback(J, ins);\n  for (i = 0; i < BPROP_SLOTS; i++) {  /* Remove backprop. cache entries. */\n    BPropEntry *bp = &J->bpropcache[i];\n    if (bp->val >= ins)\n      bp->key = 0;\n  }\n  for (ins--; ins >= REF_FIRST; ins--) {  /* Remove flags. */\n    IRIns *ir = IR(ins);\n    irt_clearphi(ir->t);\n    irt_clearmark(ir->t);\n  }\n}\n\n/* Protected callback for loop optimization. */\nstatic TValue *cploop_opt(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  UNUSED(L); UNUSED(dummy);\n  loop_unroll((LoopState *)ud);\n  return NULL;\n}\n\n/* Loop optimization. */\nint lj_opt_loop(jit_State *J)\n{\n  IRRef nins = J->cur.nins;\n  SnapNo nsnap = J->cur.nsnap;\n  MSize nsnapmap = J->cur.nsnapmap;\n  LoopState lps;\n  int errcode;\n  lps.J = J;\n  lps.subst = NULL;\n  lps.sizesubst = 0;\n  errcode = lj_vm_cpcall(J->L, NULL, &lps, cploop_opt);\n  lj_mem_freevec(J2G(J), lps.subst, lps.sizesubst, IRRef1);\n  if (LJ_UNLIKELY(errcode)) {\n    lua_State *L = J->L;\n    if (errcode == LUA_ERRRUN && tvisnumber(L->top-1)) {  /* Trace error? */\n      int32_t e = numberVint(L->top-1);\n      switch ((TraceError)e) {\n      case LJ_TRERR_TYPEINS:  /* Type instability. */\n      case LJ_TRERR_GFAIL:  /* Guard would always fail. */\n\t/* Unrolling via recording fixes many cases, e.g. a flipped boolean. */\n\tif (--J->instunroll < 0)  /* But do not unroll forever. */\n\t  break;\n\tL->top--;  /* Remove error object. */\n\tloop_undo(J, nins, nsnap, nsnapmap);\n\treturn 1;  /* Loop optimization failed, continue recording. */\n      default:\n\tbreak;\n      }\n    }\n    lj_err_throw(L, errcode);  /* Propagate all other errors. */\n  }\n  return 0;  /* Loop optimization is ok. */\n}\n\n#undef IR\n#undef emitir\n#undef emitir_raw\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_mem.c",
    "content": "/*\n** Memory access optimizations.\n** AA: Alias Analysis using high-level semantic disambiguation.\n** FWD: Load Forwarding (L2L) + Store Forwarding (S2L).\n** DSE: Dead-Store Elimination.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_mem_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_tab.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_ircall.h\"\n#include \"lj_dispatch.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n#define fins\t\t(&J->fold.ins)\n#define fleft\t\t(J->fold.left)\n#define fright\t\t(J->fold.right)\n\n/*\n** Caveat #1: return value is not always a TRef -- only use with tref_ref().\n** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold().\n*/\n\n/* Return values from alias analysis. */\ntypedef enum {\n  ALIAS_NO,\t/* The two refs CANNOT alias (exact). */\n  ALIAS_MAY,\t/* The two refs MAY alias (inexact). */\n  ALIAS_MUST\t/* The two refs MUST alias (exact). */\n} AliasRet;\n\n/* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */\n\n/* Simplified escape analysis: check for intervening stores. */\nstatic AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop)\n{\n  IRRef ref = (IRRef)(ir - J->cur.ir);  /* The ref that might be stored. */\n  for (ir++; ir < stop; ir++)\n    if (ir->op2 == ref &&\n\t(ir->o == IR_ASTORE || ir->o == IR_HSTORE ||\n\t ir->o == IR_USTORE || ir->o == IR_FSTORE))\n      return ALIAS_MAY;  /* Reference was stored and might alias. */\n  return ALIAS_NO;  /* Reference was not stored. */\n}\n\n/* Alias analysis for two different table references. */\nstatic AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb)\n{\n  IRIns *taba = IR(ta), *tabb = IR(tb);\n  int newa, newb;\n  lj_assertJ(ta != tb, \"bad usage\");\n  lj_assertJ(irt_istab(taba->t) && irt_istab(tabb->t), \"bad usage\");\n  /* Disambiguate new allocations. */\n  newa = (taba->o == IR_TNEW || taba->o == IR_TDUP);\n  newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP);\n  if (newa && newb)\n    return ALIAS_NO;  /* Two different allocations never alias. */\n  if (newb) {  /* At least one allocation? */\n    IRIns *tmp = taba; taba = tabb; tabb = tmp;\n  } else if (!newa) {\n    return ALIAS_MAY;  /* Anything else: we just don't know. */\n  }\n  return aa_escape(J, taba, tabb);\n}\n\n/* Alias analysis for array and hash access using key-based disambiguation. */\nstatic AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  IRRef ka = refa->op2;\n  IRRef kb = refb->op2;\n  IRIns *keya, *keyb;\n  IRRef ta, tb;\n  if (refa == refb)\n    return ALIAS_MUST;  /* Shortcut for same refs. */\n  keya = IR(ka);\n  if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); }\n  keyb = IR(kb);\n  if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); }\n  ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1;\n  tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1;\n  if (ka == kb) {\n    /* Same key. Check for same table with different ref (NEWREF vs. HREF). */\n    if (ta == tb)\n      return ALIAS_MUST;  /* Same key, same table. */\n    else\n      return aa_table(J, ta, tb);  /* Same key, possibly different table. */\n  }\n  if (irref_isk(ka) && irref_isk(kb))\n    return ALIAS_NO;  /* Different constant keys. */\n  if (refa->o == IR_AREF) {\n    /* Disambiguate array references based on index arithmetic. */\n    int32_t ofsa = 0, ofsb = 0;\n    IRRef basea = ka, baseb = kb;\n    lj_assertJ(refb->o == IR_AREF, \"expected AREF\");\n    /* Gather base and offset from t[base] or t[base+-ofs]. */\n    if (keya->o == IR_ADD && irref_isk(keya->op2)) {\n      basea = keya->op1;\n      ofsa = IR(keya->op2)->i;\n      if (basea == kb && ofsa != 0)\n\treturn ALIAS_NO;  /* t[base+-ofs] vs. t[base]. */\n    }\n    if (keyb->o == IR_ADD && irref_isk(keyb->op2)) {\n      baseb = keyb->op1;\n      ofsb = IR(keyb->op2)->i;\n      if (ka == baseb && ofsb != 0)\n\treturn ALIAS_NO;  /* t[base] vs. t[base+-ofs]. */\n    }\n    if (basea == baseb && ofsa != ofsb)\n      return ALIAS_NO;  /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */\n  } else {\n    /* Disambiguate hash references based on the type of their keys. */\n    lj_assertJ((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&\n\t       (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF),\n\t       \"bad xREF IR op %d or %d\", refa->o, refb->o);\n    if (!irt_sametype(keya->t, keyb->t))\n      return ALIAS_NO;  /* Different key types. */\n  }\n  if (ta == tb)\n    return ALIAS_MAY;  /* Same table, cannot disambiguate keys. */\n  else\n    return aa_table(J, ta, tb);  /* Try to disambiguate tables. */\n}\n\n/* Array and hash load forwarding. */\nstatic TRef fwd_ahload(jit_State *J, IRRef xref)\n{\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[fins->o+IRDELTA_L2S];\n  while (ref > xref) {\n    IRIns *store = IR(ref);\n    switch (aa_ahref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\n  /* No conflicting store (yet): const-fold loads from allocations. */\n  {\n    IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr;\n    IRRef tab = ir->op1;\n    ir = IR(tab);\n    if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) {\n      /* A NEWREF with a number key may end up pointing to the array part.\n      ** But it's referenced from HSTORE and not found in the ASTORE chain.\n      ** For now simply consider this a conflict without forwarding anything.\n      */\n      if (xr->o == IR_AREF) {\n\tIRRef ref2 = J->chain[IR_NEWREF];\n\twhile (ref2 > tab) {\n\t  IRIns *newref = IR(ref2);\n\t  if (irt_isnum(IR(newref->op2)->t))\n\t    goto cselim;\n\t  ref2 = newref->prev;\n\t}\n      }\n      /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF.\n      ** But the above search for conflicting stores was limited by xref.\n      ** So continue searching, limited by the TNEW/TDUP. Store forwarding\n      ** is ok, too. A conflict does NOT limit the search for a matching load.\n      */\n      while (ref > tab) {\n\tIRIns *store = IR(ref);\n\tswitch (aa_ahref(J, xr, IR(store->op1))) {\n\tcase ALIAS_NO:   break;  /* Continue searching. */\n\tcase ALIAS_MAY:  goto cselim;  /* Conflicting store. */\n\tcase ALIAS_MUST: return store->op2;  /* Store forwarding. */\n\t}\n\tref = store->prev;\n      }\n      if (ir->o == IR_TNEW && !irt_isnil(fins->t))\n\treturn 0;  /* Type instability in loop-carried dependency. */\n      if (irt_ispri(fins->t)) {\n\treturn TREF_PRI(irt_type(fins->t));\n      } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) ||\n\t\t irt_isstr(fins->t)) {\n\tTValue keyv;\n\tcTValue *tv;\n\tIRIns *key = IR(xr->op2);\n\tif (key->o == IR_KSLOT) key = IR(key->op1);\n\tlj_ir_kvalue(J->L, &keyv, key);\n\ttv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv);\n\tlj_assertJ(itype2irt(tv) == irt_type(fins->t),\n\t\t   \"mismatched type in constant table\");\n\tif (irt_isnum(fins->t))\n\t  return lj_ir_knum_u64(J, tv->u64);\n\telse if (LJ_DUALNUM && irt_isint(fins->t))\n\t  return lj_ir_kint(J, intV(tv));\n\telse\n\t  return lj_ir_kstr(J, strV(tv));\n      }\n      /* Othwerwise: don't intern as a constant. */\n    }\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  ref = J->chain[fins->o];\n  while (ref > lim) {\n    IRIns *load = IR(ref);\n    if (load->op1 == xref)\n      return ref;  /* Load forwarding. */\n    ref = load->prev;\n  }\n  return 0;  /* Conflict or no match. */\n}\n\n/* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */\nstatic TRef fwd_aload_reassoc(jit_State *J)\n{\n  IRIns *irx = IR(fins->op1);\n  IRIns *key = IR(irx->op2);\n  if (key->o == IR_ADD && irref_isk(key->op2)) {\n    IRIns *add2 = IR(key->op1);\n    if (add2->o == IR_ADD && irref_isk(add2->op2) &&\n\tIR(key->op2)->i == -IR(add2->op2)->i) {\n      IRRef ref = J->chain[IR_AREF];\n      IRRef lim = add2->op1;\n      if (irx->op1 > lim) lim = irx->op1;\n      while (ref > lim) {\n\tIRIns *ir = IR(ref);\n\tif (ir->op1 == irx->op1 && ir->op2 == add2->op1)\n\t  return fwd_ahload(J, ref);\n\tref = ir->prev;\n      }\n    }\n  }\n  return 0;\n}\n\n/* ALOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J)\n{\n  IRRef ref;\n  if ((ref = fwd_ahload(J, fins->op1)) ||\n      (ref = fwd_aload_reassoc(J)))\n    return ref;\n  return EMITFOLD;\n}\n\n/* HLOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J)\n{\n  IRRef ref = fwd_ahload(J, fins->op1);\n  if (ref)\n    return ref;\n  return EMITFOLD;\n}\n\n/* HREFK forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J)\n{\n  IRRef tab = fleft->op1;\n  IRRef ref = J->chain[IR_NEWREF];\n  while (ref > tab) {\n    IRIns *newref = IR(ref);\n    if (tab == newref->op1) {\n      if (fright->op1 == newref->op2)\n\treturn ref;  /* Forward from NEWREF. */\n      else\n\tgoto docse;\n    } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) {\n      goto docse;\n    }\n    ref = newref->prev;\n  }\n  /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */\n  if (IR(tab)->o == IR_TDUP)\n    fins->t.irt &= ~IRT_GUARD;  /* Drop HREFK guard. */\ndocse:\n  return CSEFOLD;\n}\n\n/* Check whether HREF of TNEW/TDUP can be folded to niltv. */\nint LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J)\n{\n  IRRef lim = fins->op1;  /* Search limit. */\n  IRRef ref;\n\n  /* The key for an ASTORE may end up in the hash part after a NEWREF. */\n  if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) {\n    ref = J->chain[IR_ASTORE];\n    while (ref > lim) {\n      if (ref < J->chain[IR_NEWREF])\n\treturn 0;  /* Conflict. */\n      ref = IR(ref)->prev;\n    }\n  }\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_HSTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO)\n      return 0;  /* Conflict. */\n    ref = store->prev;\n  }\n\n  return 1;  /* No conflict. Can fold to niltv. */\n}\n\n/* Check whether there's no aliasing table.clear. */\nstatic int fwd_aa_tab_clear(jit_State *J, IRRef lim, IRRef ta)\n{\n  IRRef ref = J->chain[IR_CALLS];\n  while (ref > lim) {\n    IRIns *calls = IR(ref);\n    if (calls->op2 == IRCALL_lj_tab_clear &&\n\t(ta == calls->op1 || aa_table(J, ta, calls->op1) != ALIAS_NO))\n      return 0;  /* Conflict. */\n    ref = calls->prev;\n  }\n  return 1;  /* No conflict. Can safely FOLD/CSE. */\n}\n\n/* Check whether there's no aliasing NEWREF/table.clear for the left operand. */\nint LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim)\n{\n  IRRef ta = fins->op1;\n  IRRef ref = J->chain[IR_NEWREF];\n  while (ref > lim) {\n    IRIns *newref = IR(ref);\n    if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO)\n      return 0;  /* Conflict. */\n    ref = newref->prev;\n  }\n  return fwd_aa_tab_clear(J, lim, ta);\n}\n\n/* ASTORE/HSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)\n{\n  IRRef xref = fins->op1;  /* xREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(xref);\n  IRRef1 *refp = &J->chain[fins->o];\n  IRRef ref = *refp;\n  while (ref > xref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_ahref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\t/* Store to MAYBE the same location. */\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\t/* Store to the same location. */\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards (includes conflicting loads).\n\t** Note that lj_tab_keyindex and lj_vm_next don't need guards,\n\t** since they are followed by at least one guarded VLOAD.\n\t*/\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || ir->o == IR_ALEN)\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tlj_ir_nop(store);\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* ALEN forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_alen(jit_State *J)\n{\n  IRRef tab = fins->op1;  /* Table reference. */\n  IRRef lim = tab;  /* Search limit. */\n  IRRef ref;\n\n  /* Search for conflicting HSTORE with numeric key. */\n  ref = J->chain[IR_HSTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    IRIns *href = IR(store->op1);\n    IRIns *key = IR(href->op2);\n    if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {\n      lim = ref;  /* Conflicting store found, limits search for ALEN. */\n      break;\n    }\n    ref = store->prev;\n  }\n\n  /* Try to find a matching ALEN. */\n  ref = J->chain[IR_ALEN];\n  while (ref > lim) {\n    /* CSE for ALEN only depends on the table, not the hint. */\n    if (IR(ref)->op1 == tab) {\n      IRRef sref;\n\n      /* Search for aliasing table.clear. */\n      if (!fwd_aa_tab_clear(J, ref, tab))\n\tbreak;\n\n      /* Search for hint-forwarding or conflicting store. */\n      sref = J->chain[IR_ASTORE];\n      while (sref > ref) {\n\tIRIns *store = IR(sref);\n\tIRIns *aref = IR(store->op1);\n\tIRIns *fref = IR(aref->op1);\n\tif (tab == fref->op1) {  /* ASTORE to the same table. */\n\t  /* Detect t[#t+1] = x idiom for push. */\n\t  IRIns *idx = IR(aref->op2);\n\t  if (!irt_isnil(store->t) &&\n\t      idx->o == IR_ADD && idx->op1 == ref &&\n\t      IR(idx->op2)->o == IR_KINT && IR(idx->op2)->i == 1) {\n\t    /* Note: this requires an extra PHI check in loop unroll. */\n\t    fins->op2 = aref->op2;  /* Set ALEN hint. */\n\t  }\n\t  goto doemit;  /* Conflicting store, possibly giving a hint. */\n\t} else if (aa_table(J, tab, fref->op1) == ALIAS_NO) {\n\t  goto doemit;  /* Conflicting store. */\n\t}\n\tsref = store->prev;\n      }\n\n      return ref;  /* Plain ALEN forwarding. */\n    }\n    ref = IR(ref)->prev;\n  }\ndoemit:\n  return EMITFOLD;\n}\n\n/* -- ULOAD forwarding ---------------------------------------------------- */\n\n/* The current alias analysis for upvalues is very simplistic. It only\n** disambiguates between the unique upvalues of the same function.\n** This is good enough for now, since most upvalues are read-only.\n**\n** A more precise analysis would be feasible with the help of the parser:\n** generate a unique key for every upvalue, even across all prototypes.\n** Lacking a realistic use-case, it's unclear whether this is beneficial.\n*/\nstatic AliasRet aa_uref(IRIns *refa, IRIns *refb)\n{\n  if (refa->o != refb->o)\n    return ALIAS_NO;  /* Different UREFx type. */\n  if (refa->op1 == refb->op1) {  /* Same function. */\n    if (refa->op2 == refb->op2)\n      return ALIAS_MUST;  /* Same function, same upvalue idx. */\n    else\n      return ALIAS_NO;  /* Same function, different upvalue idx. */\n  } else {  /* Different functions, check disambiguation hash values. */\n    if (((refa->op2 ^ refb->op2) & 0xff))\n      return ALIAS_NO;  /* Upvalues with different hash values cannot alias. */\n    else\n      return ALIAS_MAY;  /* No conclusion can be drawn for same hash value. */\n  }\n}\n\n/* ULOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J)\n{\n  IRRef uref = fins->op1;\n  IRRef lim = REF_BASE;  /* Search limit. */\n  IRIns *xr = IR(uref);\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_USTORE];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    switch (aa_uref(xr, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  ref = J->chain[IR_ULOAD];\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op1 == uref ||\n\t(IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o))\n      return ref;  /* Match for identical or equal UREFx (non-CSEable UREFO). */\n    ref = ir->prev;\n  }\n  return lj_ir_emit(J);\n}\n\n/* USTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)\n{\n  IRRef xref = fins->op1;  /* xREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(xref);\n  IRRef1 *refp = &J->chain[IR_USTORE];\n  IRRef ref = *refp;\n  while (ref > xref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_uref(xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\t/* Store to MAYBE the same location. */\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\t/* Store to the same location. */\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards (includes conflicting loads). */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t))\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tlj_ir_nop(store);\n\tif (ref+1 < J->cur.nins &&\n\t    store[1].o == IR_OBAR && store[1].op1 == xref) {\n\t  IRRef1 *bp = &J->chain[IR_OBAR];\n\t  IRIns *obar;\n\t  for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp))\n\t    bp = &obar->prev;\n\t  /* Remove OBAR, too. */\n\t  *bp = obar->prev;\n\t  lj_ir_nop(obar);\n\t}\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- FLOAD forwarding and FSTORE elimination ----------------------------- */\n\n/* Alias analysis for field access.\n** Field loads are cheap and field stores are rare.\n** Simple disambiguation based on field types is good enough.\n*/\nstatic AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  if (refa->op2 != refb->op2)\n    return ALIAS_NO;  /* Different fields. */\n  if (refa->op1 == refb->op1)\n    return ALIAS_MUST;  /* Same field, same object. */\n  else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM)\n    return aa_table(J, refa->op1, refb->op1);  /* Disambiguate tables. */\n  else\n    return ALIAS_MAY;  /* Same field, possibly different object. */\n}\n\n/* Only the loads for mutable fields end up here (see FOLD). */\nTRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J)\n{\n  IRRef oref = fins->op1;  /* Object reference. */\n  IRRef fid = fins->op2;  /* Field ID. */\n  IRRef lim = oref;  /* Search limit. */\n  IRRef ref;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_FSTORE];\n  while (ref > oref) {\n    IRIns *store = IR(ref);\n    switch (aa_fref(J, fins, IR(store->op1))) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST: return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\n  /* No conflicting store: const-fold field loads from allocations. */\n  if (fid == IRFL_TAB_META) {\n    IRIns *ir = IR(oref);\n    if (ir->o == IR_TNEW || ir->o == IR_TDUP)\n      return lj_ir_knull(J, IRT_TAB);\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  return lj_opt_cselim(J, lim);\n}\n\n/* FSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J)\n{\n  IRRef fref = fins->op1;  /* FREF reference. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRIns *xr = IR(fref);\n  IRRef1 *refp = &J->chain[IR_FSTORE];\n  IRRef ref = *refp;\n  while (ref > fref) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_fref(J, xr, IR(store->op1))) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\n      if (store->op2 == val &&\n\t  !(xr->op2 >= IRFL_SBUF_W && xr->op2 <= IRFL_SBUF_R))\n\treturn DROPFOLD;  /* Same value: drop the new store. */\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards or conflicting loads. */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2))\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tlj_ir_nop(store);\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* Check whether there's no aliasing buffer op between IRFL_SBUF_*. */\nint LJ_FASTCALL lj_opt_fwd_sbuf(jit_State *J, IRRef lim)\n{\n  IRRef ref;\n  if (J->chain[IR_BUFPUT] > lim)\n    return 0;  /* Conflict. */\n  ref = J->chain[IR_CALLS];\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op2 >= IRCALL_lj_strfmt_putint && ir->op2 < IRCALL_lj_buf_tostr)\n      return 0;  /* Conflict. */\n    ref = ir->prev;\n  }\n  ref = J->chain[IR_CALLL];\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op2 >= IRCALL_lj_strfmt_putint && ir->op2 < IRCALL_lj_buf_tostr)\n      return 0;  /* Conflict. */\n    ref = ir->prev;\n  }\n  return 1;  /* No conflict. Can safely FOLD/CSE. */\n}\n\n/* -- XLOAD forwarding and XSTORE elimination ----------------------------- */\n\n/* Find cdata allocation for a reference (if any). */\nstatic IRIns *aa_findcnew(jit_State *J, IRIns *ir)\n{\n  while (ir->o == IR_ADD) {\n    if (!irref_isk(ir->op1)) {\n      IRIns *ir1 = aa_findcnew(J, IR(ir->op1));  /* Left-recursion. */\n      if (ir1) return ir1;\n    }\n    if (irref_isk(ir->op2)) return NULL;\n    ir = IR(ir->op2);  /* Flatten right-recursion. */\n  }\n  return ir->o == IR_CNEW ? ir : NULL;\n}\n\n/* Alias analysis for two cdata allocations. */\nstatic AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb)\n{\n  IRIns *cnewa = aa_findcnew(J, refa);\n  IRIns *cnewb = aa_findcnew(J, refb);\n  if (cnewa == cnewb)\n    return ALIAS_MAY;  /* Same allocation or neither is an allocation. */\n  if (cnewa && cnewb)\n    return ALIAS_NO;  /* Two different allocations never alias. */\n  if (cnewb) { cnewa = cnewb; refb = refa; }\n  return aa_escape(J, cnewa, refb);\n}\n\n/* Alias analysis for XLOAD/XSTORE. */\nstatic AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb)\n{\n  ptrdiff_t ofsa = 0, ofsb = 0;\n  IRIns *refb = IR(xb->op1);\n  IRIns *basea = refa, *baseb = refb;\n  if (refa == refb && irt_sametype(xa->t, xb->t))\n    return ALIAS_MUST;  /* Shortcut for same refs with identical type. */\n  /* Offset-based disambiguation. */\n  if (refa->o == IR_ADD && irref_isk(refa->op2)) {\n    IRIns *irk = IR(refa->op2);\n    basea = IR(refa->op1);\n    ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t    (ptrdiff_t)irk->i;\n  }\n  if (refb->o == IR_ADD && irref_isk(refb->op2)) {\n    IRIns *irk = IR(refb->op2);\n    baseb = IR(refb->op1);\n    ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t    (ptrdiff_t)irk->i;\n  }\n  /* Treat constified pointers like base vs. base+offset. */\n  if (basea->o == IR_KPTR && baseb->o == IR_KPTR) {\n    ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea);\n    baseb = basea;\n  }\n  /* This implements (very) strict aliasing rules.\n  ** Different types do NOT alias, except for differences in signedness.\n  ** Type punning through unions is allowed (but forces a reload).\n  */\n  if (basea == baseb) {\n    ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t);\n    if (ofsa == ofsb) {\n      if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t))\n\treturn ALIAS_MUST;  /* Same-sized, same-kind. May need to convert. */\n    } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) {\n      return ALIAS_NO;  /* Non-overlapping base+-o1 vs. base+-o2. */\n    }\n    /* NYI: extract, extend or reinterpret bits (int <-> fp). */\n    return ALIAS_MAY;  /* Overlapping or type punning: force reload. */\n  }\n  if (!irt_sametype(xa->t, xb->t) &&\n      !(irt_typerange(xa->t, IRT_I8, IRT_U64) &&\n\t((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1))\n    return ALIAS_NO;\n  /* NYI: structural disambiguation. */\n  return aa_cnew(J, basea, baseb);  /* Try to disambiguate allocations. */\n}\n\n/* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */\nstatic IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2)\n{\n  IRRef ref = J->chain[op];\n  IRRef lim = op1;\n  if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; }\n  while (ref > lim) {\n    IRIns *ir = IR(ref);\n    if (ir->op1 == op1 && ir->op2 == op2)\n      return ref;\n    ref = ir->prev;\n  }\n  return 0;\n}\n\n/* Reassociate index references. */\nstatic IRRef reassoc_xref(jit_State *J, IRIns *ir)\n{\n  ptrdiff_t ofs = 0;\n  if (ir->o == IR_ADD && irref_isk(ir->op2)) {  /* Get constant offset. */\n    IRIns *irk = IR(ir->op2);\n    ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :\n\t\t\t\t\t   (ptrdiff_t)irk->i;\n    ir = IR(ir->op1);\n  }\n  if (ir->o == IR_ADD) {  /* Add of base + index. */\n    /* Index ref > base ref for loop-carried dependences. Only check op1. */\n    IRIns *ir2, *ir1 = IR(ir->op1);\n    int32_t shift = 0;\n    IRRef idxref;\n    /* Determine index shifts. Don't bother with IR_MUL here. */\n    if (ir1->o == IR_BSHL && irref_isk(ir1->op2))\n      shift = IR(ir1->op2)->i;\n    else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2)\n      shift = 1;\n    else\n      ir1 = ir;\n    ir2 = IR(ir1->op1);\n    /* A non-reassociated add. Must be a loop-carried dependence. */\n    if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2))\n      ofs += (ptrdiff_t)IR(ir2->op2)->i << shift;\n    else\n      return 0;\n    idxref = ir2->op1;\n    /* Try to CSE the reassociated chain. Give up if not found. */\n    if (ir1 != ir &&\n\t!(idxref = reassoc_trycse(J, ir1->o, idxref,\n\t\t\t\t  ir1->o == IR_BSHL ? ir1->op2 : idxref)))\n      return 0;\n    if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2)))\n      return 0;\n    if (ofs != 0) {\n      IRRef refk = tref_ref(lj_ir_kintp(J, ofs));\n      if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk)))\n\treturn 0;\n    }\n    return idxref;  /* Success, found a reassociated index reference. Phew. */\n  }\n  return 0;  /* Failure. */\n}\n\n/* XLOAD forwarding. */\nTRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J)\n{\n  IRRef xref = fins->op1;\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef ref;\n\n  if ((fins->op2 & IRXLOAD_READONLY))\n    goto cselim;\n  if ((fins->op2 & IRXLOAD_VOLATILE))\n    goto doemit;\n\n  /* Search for conflicting stores. */\n  ref = J->chain[IR_XSTORE];\nretry:\n  if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];\n  if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];\n  while (ref > lim) {\n    IRIns *store = IR(ref);\n    switch (aa_xref(J, xr, fins, store)) {\n    case ALIAS_NO:   break;  /* Continue searching. */\n    case ALIAS_MAY:  lim = ref; goto cselim;  /* Limit search for load. */\n    case ALIAS_MUST:\n      /* Emit conversion if the loaded type doesn't match the forwarded type. */\n      if (!irt_sametype(fins->t, IR(store->op2)->t)) {\n\tIRType dt = irt_type(fins->t), st = irt_type(IR(store->op2)->t);\n\tif (dt == IRT_I8 || dt == IRT_I16) {  /* Trunc + sign-extend. */\n\t  st = dt | IRCONV_SEXT;\n\t  dt = IRT_INT;\n\t} else if (dt == IRT_U8 || dt == IRT_U16) {  /* Trunc + zero-extend. */\n\t  st = dt;\n\t  dt = IRT_INT;\n\t}\n\tfins->ot = IRT(IR_CONV, dt);\n\tfins->op1 = store->op2;\n\tfins->op2 = (dt<<5)|st;\n\treturn RETRYFOLD;\n      }\n      return store->op2;  /* Store forwarding. */\n    }\n    ref = store->prev;\n  }\n\ncselim:\n  /* Try to find a matching load. Below the conflicting store, if any. */\n  ref = J->chain[IR_XLOAD];\n  while (ref > lim) {\n    /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */\n    if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t))\n      return ref;\n    ref = IR(ref)->prev;\n  }\n\n  /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */\n  if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] &&\n      xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) {\n    ref = J->chain[IR_XSTORE];\n    while (ref > lim)  /* Skip stores that have already been checked. */\n      ref = IR(ref)->prev;\n    lim = xref;\n    xr = IR(xref);\n    goto retry;  /* Retry with the reassociated reference. */\n  }\ndoemit:\n  return EMITFOLD;\n}\n\n/* XSTORE elimination. */\nTRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J)\n{\n  IRRef xref = fins->op1;\n  IRIns *xr = IR(xref);\n  IRRef lim = xref;  /* Search limit. */\n  IRRef val = fins->op2;  /* Stored value reference. */\n  IRRef1 *refp = &J->chain[IR_XSTORE];\n  IRRef ref = *refp;\n  if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];\n  if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];\n  if (J->chain[IR_XSNEW] > lim) lim = J->chain[IR_XSNEW];\n  while (ref > lim) {  /* Search for redundant or conflicting stores. */\n    IRIns *store = IR(ref);\n    switch (aa_xref(J, xr, fins, store)) {\n    case ALIAS_NO:\n      break;  /* Continue searching. */\n    case ALIAS_MAY:\n      if (store->op2 != val)  /* Conflict if the value is different. */\n\tgoto doemit;\n      break;  /* Otherwise continue searching. */\n    case ALIAS_MUST:\n      if (store->op2 == val)  /* Same value: drop the new store. */\n\treturn DROPFOLD;\n      /* Different value: try to eliminate the redundant store. */\n      if (ref > J->chain[IR_LOOP]) {  /* Quick check to avoid crossing LOOP. */\n\tIRIns *ir;\n\t/* Check for any intervening guards or any XLOADs (no AA performed). */\n\tfor (ir = IR(J->cur.nins-1); ir > store; ir--)\n\t  if (irt_isguard(ir->t) || ir->o == IR_XLOAD)\n\t    goto doemit;  /* No elimination possible. */\n\t/* Remove redundant store from chain and replace with NOP. */\n\t*refp = store->prev;\n\tlj_ir_nop(store);\n\t/* Now emit the new store instead. */\n      }\n      goto doemit;\n    }\n    ref = *(refp = &store->prev);\n  }\ndoemit:\n  return EMITFOLD;  /* Otherwise we have a conflict or simply no match. */\n}\n\n/* -- ASTORE/HSTORE previous type analysis -------------------------------- */\n\n/* Check whether the previous value for a table store is non-nil.\n** This can be derived either from a previous store or from a previous\n** load (because all loads from tables perform a type check).\n**\n** The result of the analysis can be used to avoid the metatable check\n** and the guard against HREF returning niltv. Both of these are cheap,\n** so let's not spend too much effort on the analysis.\n**\n** A result of 1 is exact: previous value CANNOT be nil.\n** A result of 0 is inexact: previous value MAY be nil.\n*/\nint lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref)\n{\n  /* First check stores. */\n  IRRef ref = J->chain[loadop+IRDELTA_L2S];\n  while (ref > xref) {\n    IRIns *store = IR(ref);\n    if (store->op1 == xref) {  /* Same xREF. */\n      /* A nil store MAY alias, but a non-nil store MUST alias. */\n      return !irt_isnil(store->t);\n    } else if (irt_isnil(store->t)) {  /* Must check any nil store. */\n      IRRef skref = IR(store->op1)->op2;\n      IRRef xkref = IR(xref)->op2;\n      /* Same key type MAY alias. Need ALOAD check due to multiple int types. */\n      if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) {\n\tif (skref == xkref || !irref_isk(skref) || !irref_isk(xkref))\n\t  return 0;  /* A nil store with same const key or var key MAY alias. */\n\t/* Different const keys CANNOT alias. */\n      }  /* Different key types CANNOT alias. */\n    }  /* Other non-nil stores MAY alias. */\n    ref = store->prev;\n  }\n\n  /* Check loads since nothing could be derived from stores. */\n  ref = J->chain[loadop];\n  while (ref > xref) {\n    IRIns *load = IR(ref);\n    if (load->op1 == xref) {  /* Same xREF. */\n      /* A nil load MAY alias, but a non-nil load MUST alias. */\n      return !irt_isnil(load->t);\n    }  /* Other non-nil loads MAY alias. */\n    ref = load->prev;\n  }\n  return 0;  /* Nothing derived at all, previous value MAY be nil. */\n}\n\n/* ------------------------------------------------------------------------ */\n\n#undef IR\n#undef fins\n#undef fleft\n#undef fright\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_narrow.c",
    "content": "/*\n** NARROW: Narrowing of numbers to integers (double to int32_t).\n** STRIPOV: Stripping of overflow checks.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_narrow_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_vm.h\"\n#include \"lj_strscan.h\"\n\n/* Rationale for narrowing optimizations:\n**\n** Lua has only a single number type and this is a FP double by default.\n** Narrowing doubles to integers does not pay off for the interpreter on a\n** current-generation x86/x64 machine. Most FP operations need the same\n** amount of execution resources as their integer counterparts, except\n** with slightly longer latencies. Longer latencies are a non-issue for\n** the interpreter, since they are usually hidden by other overhead.\n**\n** The total CPU execution bandwidth is the sum of the bandwidth of the FP\n** and the integer units, because they execute in parallel. The FP units\n** have an equal or higher bandwidth than the integer units. Not using\n** them means losing execution bandwidth. Moving work away from them to\n** the already quite busy integer units is a losing proposition.\n**\n** The situation for JIT-compiled code is a bit different: the higher code\n** density makes the extra latencies much more visible. Tight loops expose\n** the latencies for updating the induction variables. Array indexing\n** requires narrowing conversions with high latencies and additional\n** guards (to check that the index is really an integer). And many common\n** optimizations only work on integers.\n**\n** One solution would be speculative, eager narrowing of all number loads.\n** This causes many problems, like losing -0 or the need to resolve type\n** mismatches between traces. It also effectively forces the integer type\n** to have overflow-checking semantics. This impedes many basic\n** optimizations and requires adding overflow checks to all integer\n** arithmetic operations (whereas FP arithmetics can do without).\n**\n** Always replacing an FP op with an integer op plus an overflow check is\n** counter-productive on a current-generation super-scalar CPU. Although\n** the overflow check branches are highly predictable, they will clog the\n** execution port for the branch unit and tie up reorder buffers. This is\n** turning a pure data-flow dependency into a different data-flow\n** dependency (with slightly lower latency) *plus* a control dependency.\n** In general, you don't want to do this since latencies due to data-flow\n** dependencies can be well hidden by out-of-order execution.\n**\n** A better solution is to keep all numbers as FP values and only narrow\n** when it's beneficial to do so. LuaJIT uses predictive narrowing for\n** induction variables and demand-driven narrowing for index expressions,\n** integer arguments and bit operations. Additionally it can eliminate or\n** hoist most of the resulting overflow checks. Regular arithmetic\n** computations are never narrowed to integers.\n**\n** The integer type in the IR has convenient wrap-around semantics and\n** ignores overflow. Extra operations have been added for\n** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type.\n** Apart from reducing overall complexity of the compiler, this also\n** nicely solves the problem where you want to apply algebraic\n** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can\n** use lea instead of an add for integer ADD, but not for ADDOV (lea does\n** not affect the flags, but it helps to avoid register moves).\n**\n**\n** All of the above has to be reconsidered for architectures with slow FP\n** operations or without a hardware FPU. The dual-number mode of LuaJIT\n** addresses this issue. Arithmetic operations are performed on integers\n** as far as possible and overflow checks are added as needed.\n**\n** This implies that narrowing for integer arguments and bit operations\n** should also strip overflow checks, e.g. replace ADDOV with ADD. The\n** original overflow guards are weak and can be eliminated by DCE, if\n** there's no other use.\n**\n** A slight twist is that it's usually beneficial to use overflow-checked\n** integer arithmetics if all inputs are already integers. This is the only\n** change that affects the single-number mode, too.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n#define fins\t\t\t(&J->fold.ins)\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Elimination of narrowing type conversions --------------------------- */\n\n/* Narrowing of index expressions and bit operations is demand-driven. The\n** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT)\n** in all of these cases (e.g. array indexing or string indexing). FOLD\n** already takes care of eliminating simple redundant conversions like\n** CONV.int.num(CONV.num.int(x)) ==> x.\n**\n** But the surrounding code is FP-heavy and arithmetic operations are\n** performed on FP numbers (for the single-number mode). Consider a common\n** example such as 'x=t[i+1]', with 'i' already an integer (due to induction\n** variable narrowing). The index expression would be recorded as\n**   CONV.int.num(ADD(CONV.num.int(i), 1))\n** which is clearly suboptimal.\n**\n** One can do better by recursively backpropagating the narrowing type\n** conversion across FP arithmetic operations. This turns FP ops into\n** their corresponding integer counterparts. Depending on the semantics of\n** the conversion they also need to check for overflow. Currently only ADD\n** and SUB are supported.\n**\n** The above example can be rewritten as\n**   ADDOV(CONV.int.num(CONV.num.int(i)), 1)\n** and then into ADDOV(i, 1) after folding of the conversions. The original\n** FP ops remain in the IR and are eliminated by DCE since all references to\n** them are gone.\n**\n** [In dual-number mode the trace recorder already emits ADDOV etc., but\n** this can be further reduced. See below.]\n**\n** Special care has to be taken to avoid narrowing across an operation\n** which is potentially operating on non-integral operands. One obvious\n** case is when an expression contains a non-integral constant, but ends\n** up as an integer index at runtime (like t[x+1.5] with x=0.5).\n**\n** Operations with two non-constant operands illustrate a similar problem\n** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there,\n** unless it can be proven that either operand is integral (e.g. by CSEing\n** a previous conversion). As a not-so-obvious corollary this logic also\n** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]).\n**\n** Correctness of the transformation is guaranteed by avoiding to expand\n** the tree by adding more conversions than the one we would need to emit\n** if not backpropagating. TOBIT employs a more optimistic rule, because\n** the conversion has special semantics, designed to make the life of the\n** compiler writer easier. ;-)\n**\n** Using on-the-fly backpropagation of an expression tree doesn't work\n** because it's unknown whether the transform is correct until the end.\n** This either requires IR rollback and cache invalidation for every\n** subtree or a two-pass algorithm. The former didn't work out too well,\n** so the code now combines a recursive collector with a stack-based\n** emitter.\n**\n** [A recursive backpropagation algorithm with backtracking, employing\n** skip-list lookup and round-robin caching, emitting stack operations\n** on-the-fly for a stack-based interpreter -- and all of that in a meager\n** kilobyte? Yep, compilers are a great treasure chest. Throw away your\n** textbooks and read the codebase of a compiler today!]\n**\n** There's another optimization opportunity for array indexing: it's\n** always accompanied by an array bounds-check. The outermost overflow\n** check may be delegated to the ABC operation. This works because ABC is\n** an unsigned comparison and wrap-around due to overflow creates negative\n** numbers.\n**\n** But this optimization is only valid for constants that cannot overflow\n** an int32_t into the range of valid array indexes [0..2^27+1). A check\n** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30\n** wraps to -2^30-1.\n**\n** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are\n** quite common. So the above example finally ends up as ADD(i, 1)!\n**\n** Later on, the assembler is able to fuse the whole array reference and\n** the ADD into the memory operands of loads and other instructions. This\n** is why LuaJIT is able to generate very pretty (and fast) machine code\n** for array indexing. And that, my dear, concludes another story about\n** one of the hidden secrets of LuaJIT ...\n*/\n\n/* Maximum backpropagation depth and maximum stack size. */\n#define NARROW_MAX_BACKPROP\t100\n#define NARROW_MAX_STACK\t256\n\n/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1]\n** The lower 16 bits hold a reference (or 0). The upper 16 bits hold\n** the IR opcode + type or one of the following special opcodes:\n*/\nenum {\n  NARROW_REF,\t\t/* Push ref. */\n  NARROW_CONV,\t\t/* Push conversion of ref. */\n  NARROW_SEXT,\t\t/* Push sign-extension of ref. */\n  NARROW_INT\t\t/* Push KINT ref. The next code holds an int32_t. */\n};\n\ntypedef uint32_t NarrowIns;\n\n#define NARROWINS(op, ref)\t(((op) << 16) + (ref))\n#define narrow_op(ins)\t\t((IROpT)((ins) >> 16))\n#define narrow_ref(ins)\t\t((IRRef1)(ins))\n\n/* Context used for narrowing of type conversions. */\ntypedef struct NarrowConv {\n  jit_State *J;\t\t/* JIT compiler state. */\n  NarrowIns *sp;\t/* Current stack pointer. */\n  NarrowIns *maxsp;\t/* Maximum stack pointer minus redzone. */\n  IRRef mode;\t\t/* Conversion mode (IRCONV_*). */\n  IRType t;\t\t/* Destination type: IRT_INT or IRT_I64. */\n  NarrowIns stack[NARROW_MAX_STACK];  /* Stack holding stack-machine code. */\n} NarrowConv;\n\n/* Lookup a reference in the backpropagation cache. */\nstatic BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode)\n{\n  ptrdiff_t i;\n  for (i = 0; i < BPROP_SLOTS; i++) {\n    BPropEntry *bp = &J->bpropcache[i];\n    /* Stronger checks are ok, too. */\n    if (bp->key == key && bp->mode >= mode &&\n\t((bp->mode ^ mode) & IRCONV_MODEMASK) == 0)\n      return bp;\n  }\n  return NULL;\n}\n\n/* Add an entry to the backpropagation cache. */\nstatic void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode)\n{\n  uint32_t slot = J->bpropslot;\n  BPropEntry *bp = &J->bpropcache[slot];\n  J->bpropslot = (slot + 1) & (BPROP_SLOTS-1);\n  bp->key = key;\n  bp->val = val;\n  bp->mode = mode;\n}\n\n/* Backpropagate overflow stripping. */\nstatic void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth)\n{\n  jit_State *J = nc->J;\n  IRIns *ir = IR(ref);\n  if (ir->o == IR_ADDOV || ir->o == IR_SUBOV ||\n      (ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) {\n    BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT);\n    if (bp) {\n      ref = bp->val;\n    } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {\n      NarrowIns *savesp = nc->sp;\n      narrow_stripov_backprop(nc, ir->op1, depth);\n      if (nc->sp < nc->maxsp) {\n\tnarrow_stripov_backprop(nc, ir->op2, depth);\n\tif (nc->sp < nc->maxsp) {\n\t  *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);\n\t  return;\n\t}\n      }\n      nc->sp = savesp;  /* Path too deep, need to backtrack. */\n    }\n  }\n  *nc->sp++ = NARROWINS(NARROW_REF, ref);\n}\n\n/* Backpropagate narrowing conversion. Return number of needed conversions. */\nstatic int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)\n{\n  jit_State *J = nc->J;\n  IRIns *ir = IR(ref);\n  IRRef cref;\n\n  if (nc->sp >= nc->maxsp) return 10;  /* Path too deep. */\n\n  /* Check the easy cases first. */\n  if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) {\n    if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY)\n      narrow_stripov_backprop(nc, ir->op1, depth+1);\n    else\n      *nc->sp++ = NARROWINS(NARROW_REF, ir->op1);  /* Undo conversion. */\n    if (nc->t == IRT_I64)\n      *nc->sp++ = NARROWINS(NARROW_SEXT, 0);  /* Sign-extend integer. */\n    return 0;\n  } else if (ir->o == IR_KNUM) {  /* Narrow FP constant. */\n    lua_Number n = ir_knum(ir)->n;\n    if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) {\n      /* Allows a wider range of constants. */\n      int64_t k64 = (int64_t)n;\n      if (n == (lua_Number)k64) {  /* Only if const doesn't lose precision. */\n\t*nc->sp++ = NARROWINS(NARROW_INT, 0);\n\t*nc->sp++ = (NarrowIns)k64;  /* But always truncate to 32 bits. */\n\treturn 0;\n      }\n    } else {\n      int32_t k = lj_num2int(n);\n      /* Only if constant is a small integer. */\n      if (checki16(k) && n == (lua_Number)k) {\n\t*nc->sp++ = NARROWINS(NARROW_INT, 0);\n\t*nc->sp++ = (NarrowIns)k;\n\treturn 0;\n      }\n    }\n    return 10;  /* Never narrow other FP constants (this is rare). */\n  }\n\n  /* Try to CSE the conversion. Stronger checks are ok, too. */\n  cref = J->chain[fins->o];\n  while (cref > ref) {\n    IRIns *cr = IR(cref);\n    if (cr->op1 == ref &&\n\t(fins->o == IR_TOBIT ||\n\t ((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) &&\n\t  irt_isguard(cr->t) >= irt_isguard(fins->t)))) {\n      *nc->sp++ = NARROWINS(NARROW_REF, cref);\n      return 0;  /* Already there, no additional conversion needed. */\n    }\n    cref = cr->prev;\n  }\n\n  /* Backpropagate across ADD/SUB. */\n  if (ir->o == IR_ADD || ir->o == IR_SUB) {\n    /* Try cache lookup first. */\n    IRRef mode = nc->mode;\n    BPropEntry *bp;\n    /* Inner conversions need a stronger check. */\n    if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0)\n      mode += IRCONV_CHECK-IRCONV_INDEX;\n    bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);\n    if (bp) {\n      *nc->sp++ = NARROWINS(NARROW_REF, bp->val);\n      return 0;\n    } else if (nc->t == IRT_I64) {\n      /* Try sign-extending from an existing (checked) conversion to int. */\n      mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX;\n      bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);\n      if (bp) {\n\t*nc->sp++ = NARROWINS(NARROW_REF, bp->val);\n\t*nc->sp++ = NARROWINS(NARROW_SEXT, 0);\n\treturn 0;\n      }\n    }\n    if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {\n      NarrowIns *savesp = nc->sp;\n      int count = narrow_conv_backprop(nc, ir->op1, depth);\n      count += narrow_conv_backprop(nc, ir->op2, depth);\n      if (count <= 1) {  /* Limit total number of conversions. */\n\t*nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);\n\treturn count;\n      }\n      nc->sp = savesp;  /* Too many conversions, need to backtrack. */\n    }\n  }\n\n  /* Otherwise add a conversion. */\n  *nc->sp++ = NARROWINS(NARROW_CONV, ref);\n  return 1;\n}\n\n/* Emit the conversions collected during backpropagation. */\nstatic IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc)\n{\n  /* The fins fields must be saved now -- emitir() overwrites them. */\n  IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0;\n  IROpT convot = fins->ot;\n  IRRef1 convop2 = fins->op2;\n  NarrowIns *next = nc->stack;  /* List of instructions from backpropagation. */\n  NarrowIns *last = nc->sp;\n  NarrowIns *sp = nc->stack;  /* Recycle the stack to store operands. */\n  while (next < last) {  /* Simple stack machine to process the ins. list. */\n    NarrowIns ref = *next++;\n    IROpT op = narrow_op(ref);\n    if (op == NARROW_REF) {\n      *sp++ = ref;\n    } else if (op == NARROW_CONV) {\n      *sp++ = emitir_raw(convot, ref, convop2);  /* Raw emit avoids a loop. */\n    } else if (op == NARROW_SEXT) {\n      lj_assertJ(sp >= nc->stack+1, \"stack underflow\");\n      sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1],\n\t\t      (IRT_I64<<5)|IRT_INT|IRCONV_SEXT);\n    } else if (op == NARROW_INT) {\n      lj_assertJ(next < last, \"missing arg to NARROW_INT\");\n      *sp++ = nc->t == IRT_I64 ?\n\t      lj_ir_kint64(J, (int64_t)(int32_t)*next++) :\n\t      lj_ir_kint(J, *next++);\n    } else {  /* Regular IROpT. Pops two operands and pushes one result. */\n      IRRef mode = nc->mode;\n      lj_assertJ(sp >= nc->stack+2, \"stack underflow\");\n      sp--;\n      /* Omit some overflow checks for array indexing. See comments above. */\n      if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) {\n\tif (next == last && irref_isk(narrow_ref(sp[0])) &&\n\t  (uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u)\n\t  guardot = 0;\n\telse  /* Otherwise cache a stronger check. */\n\t  mode += IRCONV_CHECK-IRCONV_INDEX;\n      }\n      sp[-1] = emitir(op+guardot, sp[-1], sp[0]);\n      /* Add to cache. */\n      if (narrow_ref(ref))\n\tnarrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode);\n    }\n  }\n  lj_assertJ(sp == nc->stack+1, \"stack misalignment\");\n  return nc->stack[0];\n}\n\n/* Narrow a type conversion of an arithmetic operation. */\nTRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J)\n{\n  if ((J->flags & JIT_F_OPT_NARROW)) {\n    NarrowConv nc;\n    nc.J = J;\n    nc.sp = nc.stack;\n    nc.maxsp = &nc.stack[NARROW_MAX_STACK-4];\n    nc.t = irt_type(fins->t);\n    if (fins->o == IR_TOBIT) {\n      nc.mode = IRCONV_TOBIT;  /* Used only in the backpropagation cache. */\n    } else {\n      nc.mode = fins->op2;\n    }\n    if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1)\n      return narrow_conv_emit(J, &nc);\n  }\n  return NEXTFOLD;\n}\n\n/* -- Narrowing of implicit conversions ----------------------------------- */\n\n/* Recursively strip overflow checks. */\nstatic TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode)\n{\n  IRRef ref = tref_ref(tr);\n  IRIns *ir = IR(ref);\n  int op = ir->o;\n  if (op >= IR_ADDOV && op <= lastop) {\n    BPropEntry *bp = narrow_bpc_get(J, ref, mode);\n    if (bp) {\n      return TREF(bp->val, irt_t(IR(bp->val)->t));\n    } else {\n      IRRef op1 = ir->op1, op2 = ir->op2;  /* The IR may be reallocated. */\n      op1 = narrow_stripov(J, op1, lastop, mode);\n      op2 = narrow_stripov(J, op2, lastop, mode);\n      tr = emitir(IRT(op - IR_ADDOV + IR_ADD,\n\t\t      ((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2);\n      narrow_bpc_set(J, ref, tref_ref(tr), mode);\n    }\n  } else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) {\n    tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode);\n  }\n  return tr;\n}\n\n/* Narrow array index. */\nTRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr)\n{\n  IRIns *ir;\n  lj_assertJ(tref_isnumber(tr), \"expected number type\");\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX);\n  /* Omit some overflow checks for array indexing. See comments above. */\n  ir = IR(tref_ref(tr));\n  if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) &&\n      (uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u)\n    return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2);\n  return tr;\n}\n\n/* Narrow conversion to integer operand (overflow undefined). */\nTRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr)\n{\n  if (tref_isstr(tr))\n    tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY);\n  if (!tref_isinteger(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  /*\n  ** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV.\n  ** Use IRCONV_TOBIT for the cache entries, since the semantics are the same.\n  */\n  return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);\n}\n\n/* Narrow conversion to bitop operand (overflow wrapped). */\nTRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr)\n{\n  if (tref_isstr(tr))\n    tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n  if (tref_isnum(tr))  /* Conversion may be narrowed, too. See above. */\n    return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J));\n  if (!tref_isinteger(tr))\n    lj_trace_err(J, LJ_TRERR_BADTYPE);\n  /*\n  ** Wrapped overflow semantics allow stripping of ADDOV and SUBOV.\n  ** MULOV cannot be stripped due to precision widening.\n  */\n  return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);\n}\n\n#if LJ_HASFFI\n/* Narrow C array index (overflow undefined). */\nTRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr)\n{\n  lj_assertJ(tref_isnumber(tr), \"expected number type\");\n  if (tref_isnum(tr))\n    return emitir(IRT(IR_CONV, IRT_INTP), tr, (IRT_INTP<<5)|IRT_NUM|IRCONV_ANY);\n  /* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */\n  return narrow_stripov(J, tr, IR_MULOV,\n\t\t\tLJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) :\n\t\t\t\t((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT));\n}\n#endif\n\n/* -- Narrowing of arithmetic operators ----------------------------------- */\n\n/* Check whether a number fits into an int32_t (-0 is ok, too). */\nstatic int numisint(lua_Number n)\n{\n  return (n == (lua_Number)lj_num2int(n));\n}\n\n/* Convert string to number. Error out for non-numeric string values. */\nstatic TRef conv_str_tonum(jit_State *J, TRef tr, TValue *o)\n{\n  if (tref_isstr(tr)) {\n    tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);\n    /* Would need an inverted STRTO for this rare and useless case. */\n    if (!lj_strscan_num(strV(o), o))  /* Convert in-place. Value used below. */\n      lj_trace_err(J, LJ_TRERR_BADTYPE);  /* Punt if non-numeric. */\n  }\n  return tr;\n}\n\n/* Narrowing of arithmetic operations. */\nTRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,\n\t\t\t TValue *vb, TValue *vc, IROp op)\n{\n  rb = conv_str_tonum(J, rb, vb);\n  rc = conv_str_tonum(J, rc, vc);\n  /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */\n  if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) &&\n      tref_isinteger(rb) && tref_isinteger(rc) &&\n      numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc),\n\t\t\t       (int)op - (int)IR_ADD)))\n    return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc);\n  if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT);\n  if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n  return emitir(IRTN(op), rb, rc);\n}\n\n/* Narrowing of unary minus operator. */\nTRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc)\n{\n  rc = conv_str_tonum(J, rc, vc);\n  if (tref_isinteger(rc)) {\n    uint32_t k = (uint32_t)numberVint(vc);\n    if ((LJ_DUALNUM || k != 0) && k != 0x80000000u) {\n      TRef zero = lj_ir_kint(J, 0);\n      if (!LJ_DUALNUM)\n\temitir(IRTGI(IR_NE), rc, zero);\n      return emitir(IRTGI(IR_SUBOV), zero, rc);\n    }\n    rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n  }\n  return emitir(IRTN(IR_NEG), rc, lj_ir_ksimd(J, LJ_KSIMD_NEG));\n}\n\n/* Narrowing of modulo operator. */\nTRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)\n{\n  TRef tmp;\n  rb = conv_str_tonum(J, rb, vb);\n  rc = conv_str_tonum(J, rc, vc);\n  if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) &&\n      tref_isinteger(rb) && tref_isinteger(rc) &&\n      (tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) {\n    emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0));\n    return emitir(IRTI(IR_MOD), rb, rc);\n  }\n  /* b % c ==> b - floor(b/c)*c */\n  rb = lj_ir_tonum(J, rb);\n  rc = lj_ir_tonum(J, rc);\n  tmp = emitir(IRTN(IR_DIV), rb, rc);\n  tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR);\n  tmp = emitir(IRTN(IR_MUL), tmp, rc);\n  return emitir(IRTN(IR_SUB), rb, tmp);\n}\n\n/* Narrowing of power operator or math.pow. */\nTRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)\n{\n  rb = conv_str_tonum(J, rb, vb);\n  rb = lj_ir_tonum(J, rb);  /* Left arg is always treated as an FP number. */\n  rc = conv_str_tonum(J, rc, vc);\n  /* Narrowing must be unconditional to preserve (-x)^i semantics. */\n  if (tvisint(vc) || numisint(numV(vc))) {\n    int checkrange = 0;\n    /* pow() is faster for bigger exponents. But do this only for (+k)^i. */\n    if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) {\n      int32_t k = numberVint(vc);\n      if (!(k >= -65536 && k <= 65536)) goto force_pow_num;\n      checkrange = 1;\n    }\n    if (!tref_isinteger(rc)) {\n      /* Guarded conversion to integer! */\n      rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK);\n    }\n    if (checkrange && !tref_isk(rc)) {  /* Range guard: -65536 <= i <= 65536 */\n      TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536));\n      emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536));\n    }\n  } else {\nforce_pow_num:\n    rc = lj_ir_tonum(J, rc);  /* Want POW(num, num), not POW(num, int). */\n  }\n  return emitir(IRTN(IR_POW), rb, rc);\n}\n\n/* -- Predictive narrowing of induction variables ------------------------- */\n\n/* Narrow a single runtime value. */\nstatic int narrow_forl(jit_State *J, cTValue *o)\n{\n  if (tvisint(o)) return 1;\n  if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o));\n  return 0;\n}\n\n/* Narrow the FORL index type by looking at the runtime values. */\nIRType lj_opt_narrow_forl(jit_State *J, cTValue *tv)\n{\n  lj_assertJ(tvisnumber(&tv[FORL_IDX]) &&\n\t     tvisnumber(&tv[FORL_STOP]) &&\n\t     tvisnumber(&tv[FORL_STEP]),\n\t     \"expected number types\");\n  /* Narrow only if the runtime values of start/stop/step are all integers. */\n  if (narrow_forl(J, &tv[FORL_IDX]) &&\n      narrow_forl(J, &tv[FORL_STOP]) &&\n      narrow_forl(J, &tv[FORL_STEP])) {\n    /* And if the loop index can't possibly overflow. */\n    lua_Number step = numberVnum(&tv[FORL_STEP]);\n    lua_Number sum = numberVnum(&tv[FORL_STOP]) + step;\n    if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0))\n      return IRT_INT;\n  }\n  return IRT_NUM;\n}\n\n#undef IR\n#undef fins\n#undef emitir\n#undef emitir_raw\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_sink.c",
    "content": "/*\n** SINK: Allocation Sinking and Store Sinking.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_sink_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_target.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Check whether the store ref points to an eligible allocation. */\nstatic IRIns *sink_checkalloc(jit_State *J, IRIns *irs)\n{\n  IRIns *ir = IR(irs->op1);\n  if (!irref_isk(ir->op2))\n    return NULL;  /* Non-constant key. */\n  if (ir->o == IR_HREFK || ir->o == IR_AREF)\n    ir = IR(ir->op1);\n  else if (!(ir->o == IR_HREF || ir->o == IR_NEWREF ||\n\t     ir->o == IR_FREF || ir->o == IR_ADD))\n    return NULL;  /* Unhandled reference type (for XSTORE). */\n  ir = IR(ir->op1);\n  if (!(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW))\n    return NULL;  /* Not an allocation. */\n  return ir;  /* Return allocation. */\n}\n\n/* Recursively check whether a value depends on a PHI. */\nstatic int sink_phidep(jit_State *J, IRRef ref)\n{\n  IRIns *ir = IR(ref);\n  if (irt_isphi(ir->t)) return 1;\n  if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1;\n  if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1;\n  return 0;\n}\n\n/* Check whether a value is a sinkable PHI or loop-invariant. */\nstatic int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref)\n{\n  if (ref >= REF_FIRST) {\n    IRIns *ir = IR(ref);\n    if (irt_isphi(ir->t) || (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT &&\n\t\t\t     irt_isphi(IR(ir->op1)->t))) {\n      ira->prev++;\n      return 1;  /* Sinkable PHI. */\n    }\n    /* Otherwise the value must be loop-invariant. */\n    return ref < J->loopref && !sink_phidep(J, ref);\n  }\n  return 1;  /* Constant (non-PHI). */\n}\n\n/* Mark non-sinkable allocations using single-pass backward propagation.\n**\n** Roots for the marking process are:\n** - Some PHIs or snapshots (see below).\n** - Non-PHI, non-constant values stored to PHI allocations.\n** - All guards.\n** - Any remaining loads not eliminated by store-to-load forwarding.\n** - Stores with non-constant keys.\n** - All stored values.\n*/\nstatic void sink_mark_ins(jit_State *J)\n{\n  IRIns *ir, *irlast = IR(J->cur.nins-1);\n  for (ir = irlast ; ; ir--) {\n    switch (ir->o) {\n    case IR_BASE:\n      return;  /* Finished. */\n    case IR_ALOAD: case IR_HLOAD: case IR_XLOAD: case IR_TBAR: case IR_ALEN:\n      irt_setmark(IR(ir->op1)->t);  /* Mark ref for remaining loads. */\n      break;\n    case IR_FLOAD:\n      if (irt_ismarked(ir->t) || ir->op2 == IRFL_TAB_META)\n\tirt_setmark(IR(ir->op1)->t);  /* Mark table for remaining loads. */\n      break;\n    case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {\n      IRIns *ira = sink_checkalloc(J, ir);\n      if (!ira || (irt_isphi(ira->t) && !sink_checkphi(J, ira, ir->op2)))\n\tirt_setmark(IR(ir->op1)->t);  /* Mark ineligible ref. */\n      irt_setmark(IR(ir->op2)->t);  /* Mark stored value. */\n      break;\n      }\n#if LJ_HASFFI\n    case IR_CNEWI:\n      if (irt_isphi(ir->t) &&\n\t  (!sink_checkphi(J, ir, ir->op2) ||\n\t   (LJ_32 && ir+1 < irlast && (ir+1)->o == IR_HIOP &&\n\t    !sink_checkphi(J, ir, (ir+1)->op2))))\n\tirt_setmark(ir->t);  /* Mark ineligible allocation. */\n#endif\n      /* fallthrough */\n    case IR_USTORE:\n      irt_setmark(IR(ir->op2)->t);  /* Mark stored value. */\n      break;\n#if LJ_HASFFI\n    case IR_CALLXS:\n#endif\n    case IR_CALLS:\n      irt_setmark(IR(ir->op1)->t);  /* Mark (potentially) stored values. */\n      break;\n    case IR_PHI: {\n      IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n      irl->prev = irr->prev = 0;  /* Clear PHI value counts. */\n      if (irl->o == irr->o &&\n\t  (irl->o == IR_TNEW || irl->o == IR_TDUP ||\n\t   (LJ_HASFFI && (irl->o == IR_CNEW || irl->o == IR_CNEWI))))\n\tbreak;\n      irt_setmark(irl->t);\n      irt_setmark(irr->t);\n      break;\n      }\n    default:\n      if (irt_ismarked(ir->t) || irt_isguard(ir->t)) {  /* Propagate mark. */\n\tif (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);\n\tif (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);\n      }\n      break;\n    }\n  }\n}\n\n/* Mark all instructions referenced by a snapshot. */\nstatic void sink_mark_snap(jit_State *J, SnapShot *snap)\n{\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    IRRef ref = snap_ref(map[n]);\n    if (!irref_isk(ref))\n      irt_setmark(IR(ref)->t);\n  }\n}\n\n/* Iteratively remark PHI refs with differing marks or PHI value counts. */\nstatic void sink_remark_phi(jit_State *J)\n{\n  IRIns *ir;\n  int remark;\n  do {\n    remark = 0;\n    for (ir = IR(J->cur.nins-1); ir->o == IR_PHI; ir--) {\n      IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);\n      if (!((irl->t.irt ^ irr->t.irt) & IRT_MARK) && irl->prev == irr->prev)\n\tcontinue;\n      remark |= (~(irl->t.irt & irr->t.irt) & IRT_MARK);\n      irt_setmark(IR(ir->op1)->t);\n      irt_setmark(IR(ir->op2)->t);\n    }\n  } while (remark);\n}\n\n/* Sweep instructions and tag sunken allocations and stores. */\nstatic void sink_sweep_ins(jit_State *J)\n{\n  IRIns *ir, *irbase = IR(REF_BASE);\n  for (ir = IR(J->cur.nins-1) ; ir >= irbase; ir--) {\n    switch (ir->o) {\n    case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {\n      IRIns *ira = sink_checkalloc(J, ir);\n      if (ira && !irt_ismarked(ira->t)) {\n\tint delta = (int)(ir - ira);\n\tir->prev = REGSP(RID_SINK, delta > 255 ? 255 : delta);\n      } else {\n\tir->prev = REGSP_INIT;\n      }\n      break;\n      }\n    case IR_NEWREF:\n      if (!irt_ismarked(IR(ir->op1)->t)) {\n\tir->prev = REGSP(RID_SINK, 0);\n      } else {\n\tirt_clearmark(ir->t);\n\tir->prev = REGSP_INIT;\n      }\n      break;\n#if LJ_HASFFI\n    case IR_CNEW: case IR_CNEWI:\n#endif\n    case IR_TNEW: case IR_TDUP:\n      if (!irt_ismarked(ir->t)) {\n\tir->t.irt &= ~IRT_GUARD;\n\tir->prev = REGSP(RID_SINK, 0);\n\tJ->cur.sinktags = 1;  /* Signal present SINK tags to assembler. */\n      } else {\n\tirt_clearmark(ir->t);\n\tir->prev = REGSP_INIT;\n      }\n      break;\n    case IR_PHI: {\n      IRIns *ira = IR(ir->op2);\n      if (!irt_ismarked(ira->t) &&\n\t  (ira->o == IR_TNEW || ira->o == IR_TDUP ||\n\t   (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI)))) {\n\tir->prev = REGSP(RID_SINK, 0);\n      } else {\n\tir->prev = REGSP_INIT;\n      }\n      break;\n      }\n    default:\n      irt_clearmark(ir->t);\n      ir->prev = REGSP_INIT;\n      break;\n    }\n  }\n  for (ir = IR(J->cur.nk); ir < irbase; ir++) {\n    irt_clearmark(ir->t);\n    ir->prev = REGSP_INIT;\n    /* The false-positive of irt_is64() for ASMREF_L (REF_NIL) is OK here. */\n    if (irt_is64(ir->t) && ir->o != IR_KNULL)\n      ir++;\n  }\n}\n\n/* Allocation sinking and store sinking.\n**\n** 1. Mark all non-sinkable allocations.\n** 2. Then sink all remaining allocations and the related stores.\n*/\nvoid lj_opt_sink(jit_State *J)\n{\n  const uint32_t need = (JIT_F_OPT_SINK|JIT_F_OPT_FWD|\n\t\t\t JIT_F_OPT_DCE|JIT_F_OPT_CSE|JIT_F_OPT_FOLD);\n  if ((J->flags & need) == need &&\n      (J->chain[IR_TNEW] || J->chain[IR_TDUP] ||\n       (LJ_HASFFI && (J->chain[IR_CNEW] || J->chain[IR_CNEWI])))) {\n    if (!J->loopref)\n      sink_mark_snap(J, &J->cur.snap[J->cur.nsnap-1]);\n    sink_mark_ins(J);\n    if (J->loopref)\n      sink_remark_phi(J);\n    sink_sweep_ins(J);\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_opt_split.c",
    "content": "/*\n** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_opt_split_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT && (LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI))\n\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n\n/* SPLIT pass:\n**\n** This pass splits up 64 bit IR instructions into multiple 32 bit IR\n** instructions. It's only active for soft-float targets or for 32 bit CPUs\n** which lack native 64 bit integer operations (the FFI is currently the\n** only emitter for 64 bit integer instructions).\n**\n** Splitting the IR in a separate pass keeps each 32 bit IR assembler\n** backend simple. Only a small amount of extra functionality needs to be\n** implemented. This is much easier than adding support for allocating\n** register pairs to each backend (believe me, I tried). A few simple, but\n** important optimizations can be performed by the SPLIT pass, which would\n** be tedious to do in the backend.\n**\n** The basic idea is to replace each 64 bit IR instruction with its 32 bit\n** equivalent plus an extra HIOP instruction. The splitted IR is not passed\n** through FOLD or any other optimizations, so each HIOP is guaranteed to\n** immediately follow it's counterpart. The actual functionality of HIOP is\n** inferred from the previous instruction.\n**\n** The operands of HIOP hold the hiword input references. The output of HIOP\n** is the hiword output reference, which is also used to hold the hiword\n** register or spill slot information. The register allocator treats this\n** instruction independently of any other instruction, which improves code\n** quality compared to using fixed register pairs.\n**\n** It's easier to split up some instructions into two regular 32 bit\n** instructions. E.g. XLOAD is split up into two XLOADs with two different\n** addresses. Obviously 64 bit constants need to be split up into two 32 bit\n** constants, too. Some hiword instructions can be entirely omitted, e.g.\n** when zero-extending a 32 bit value to 64 bits. 64 bit arguments for calls\n** are split up into two 32 bit arguments each.\n**\n** On soft-float targets, floating-point instructions are directly converted\n** to soft-float calls by the SPLIT pass (except for comparisons and MIN/MAX).\n** HIOP for number results has the type IRT_SOFTFP (\"sfp\" in -jdump).\n**\n** Here's the IR and x64 machine code for 'x.b = x.a + 1' for a struct with\n** two int64_t fields:\n**\n** 0100    p32 ADD    base  +8\n** 0101    i64 XLOAD  0100\n** 0102    i64 ADD    0101  +1\n** 0103    p32 ADD    base  +16\n** 0104    i64 XSTORE 0103  0102\n**\n**         mov rax, [esi+0x8]\n**         add rax, +0x01\n**         mov [esi+0x10], rax\n**\n** Here's the transformed IR and the x86 machine code after the SPLIT pass:\n**\n** 0100    p32 ADD    base  +8\n** 0101    int XLOAD  0100\n** 0102    p32 ADD    base  +12\n** 0103    int XLOAD  0102\n** 0104    int ADD    0101  +1\n** 0105    int HIOP   0103  +0\n** 0106    p32 ADD    base  +16\n** 0107    int XSTORE 0106  0104\n** 0108    int HIOP   0106  0105\n**\n**         mov eax, [esi+0x8]\n**         mov ecx, [esi+0xc]\n**         add eax, +0x01\n**         adc ecx, +0x00\n**         mov [esi+0x10], eax\n**         mov [esi+0x14], ecx\n**\n** You may notice the reassociated hiword address computation, which is\n** later fused into the mov operands by the assembler.\n*/\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t(&J->cur.ir[(ref)])\n\n/* Directly emit the transformed IR without updating chains etc. */\nstatic IRRef split_emit(jit_State *J, uint16_t ot, IRRef1 op1, IRRef1 op2)\n{\n  IRRef nref = lj_ir_nextins(J);\n  IRIns *ir = IR(nref);\n  ir->ot = ot;\n  ir->op1 = op1;\n  ir->op2 = op2;\n  return nref;\n}\n\n#if LJ_SOFTFP\n/* Emit a (checked) number to integer conversion. */\nstatic IRRef split_num2int(jit_State *J, IRRef lo, IRRef hi, int check)\n{\n  IRRef tmp, res;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), lo, hi);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hi, lo);\n#endif\n  res = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_softfp_d2i);\n  if (check) {\n    tmp = split_emit(J, IRTI(IR_CALLN), res, IRCALL_softfp_i2d);\n    split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n    split_emit(J, IRTGI(IR_EQ), tmp, lo);\n    split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), tmp+1, hi);\n  }\n  return res;\n}\n\n/* Emit a CALLN with one split 64 bit argument. */\nstatic IRRef split_call_l(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t  IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n}\n#endif\n\n/* Emit a CALLN with one split 64 bit argument and a 32 bit argument. */\nstatic IRRef split_call_li(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t   IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1, op2 = ir->op2;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);\n}\n\n/* Emit a CALLN with two split 64 bit arguments. */\nstatic IRRef split_call_ll(jit_State *J, IRRef1 *hisubst, IRIns *oir,\n\t\t\t   IRIns *ir, IRCallID id)\n{\n  IRRef tmp, op1 = ir->op1, op2 = ir->op2;\n  J->cur.nins--;\n#if LJ_LE\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);\n#else\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);\n  tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);\n#endif\n  ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);\n  return split_emit(J,\n    IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),\n    tmp, tmp);\n}\n\n/* Get a pointer to the other 32 bit word (LE: hiword, BE: loword). */\nstatic IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref)\n{\n  IRRef nref = oir[ref].prev;\n  IRIns *ir = IR(nref);\n  int32_t ofs = 4;\n  if (ir->o == IR_KPTR)\n    return lj_ir_kptr(J, (char *)ir_kptr(ir) + ofs);\n  if (ir->o == IR_ADD && irref_isk(ir->op2) && !irt_isphi(oir[ref].t)) {\n    /* Reassociate address. */\n    ofs += IR(ir->op2)->i;\n    nref = ir->op1;\n    if (ofs == 0) return nref;\n  }\n  return split_emit(J, IRT(IR_ADD, IRT_PTR), nref, lj_ir_kint(J, ofs));\n}\n\n#if LJ_HASFFI\nstatic IRRef split_bitshift(jit_State *J, IRRef1 *hisubst,\n\t\t\t    IRIns *oir, IRIns *nir, IRIns *ir)\n{\n  IROp op = ir->o;\n  IRRef kref = nir->op2;\n  if (irref_isk(kref)) {  /* Optimize constant shifts. */\n    int32_t k = (IR(kref)->i & 63);\n    IRRef lo = nir->op1, hi = hisubst[ir->op1];\n    if (op == IR_BROL || op == IR_BROR) {\n      if (op == IR_BROR) k = (-k & 63);\n      if (k >= 32) { IRRef t = lo; lo = hi; hi = t; k -= 32; }\n      if (k == 0) {\n      passthrough:\n\tJ->cur.nins--;\n\tir->prev = lo;\n\treturn hi;\n      } else {\n\tTRef k1, k2;\n\tIRRef t1, t2, t3, t4;\n\tJ->cur.nins--;\n\tk1 = lj_ir_kint(J, k);\n\tk2 = lj_ir_kint(J, (-k & 31));\n\tt1 = split_emit(J, IRTI(IR_BSHL), lo, k1);\n\tt2 = split_emit(J, IRTI(IR_BSHL), hi, k1);\n\tt3 = split_emit(J, IRTI(IR_BSHR), lo, k2);\n\tt4 = split_emit(J, IRTI(IR_BSHR), hi, k2);\n\tir->prev = split_emit(J, IRTI(IR_BOR), t1, t4);\n\treturn split_emit(J, IRTI(IR_BOR), t2, t3);\n      }\n    } else if (k == 0) {\n      goto passthrough;\n    } else if (k < 32) {\n      if (op == IR_BSHL) {\n\tIRRef t1 = split_emit(J, IRTI(IR_BSHL), hi, kref);\n\tIRRef t2 = split_emit(J, IRTI(IR_BSHR), lo, lj_ir_kint(J, (-k&31)));\n\treturn split_emit(J, IRTI(IR_BOR), t1, t2);\n      } else {\n\tIRRef t1 = ir->prev, t2;\n\tlj_assertJ(op == IR_BSHR || op == IR_BSAR, \"bad usage\");\n\tnir->o = IR_BSHR;\n\tt2 = split_emit(J, IRTI(IR_BSHL), hi, lj_ir_kint(J, (-k&31)));\n\tir->prev = split_emit(J, IRTI(IR_BOR), t1, t2);\n\treturn split_emit(J, IRTI(op), hi, kref);\n      }\n    } else {\n      if (op == IR_BSHL) {\n\tif (k == 32)\n\t  J->cur.nins--;\n\telse\n\t  lo = ir->prev;\n\tir->prev = lj_ir_kint(J, 0);\n\treturn lo;\n      } else {\n\tlj_assertJ(op == IR_BSHR || op == IR_BSAR, \"bad usage\");\n\tif (k == 32) {\n\t  J->cur.nins--;\n\t  ir->prev = hi;\n\t} else {\n\t  nir->op1 = hi;\n\t}\n\tif (op == IR_BSHR)\n\t  return lj_ir_kint(J, 0);\n\telse\n\t  return split_emit(J, IRTI(IR_BSAR), hi, lj_ir_kint(J, 31));\n      }\n    }\n  }\n  return split_call_li(J, hisubst, oir, ir,\n\t\t       op - IR_BSHL + IRCALL_lj_carith_shl64);\n}\n\nstatic IRRef split_bitop(jit_State *J, IRRef1 *hisubst,\n\t\t\t IRIns *nir, IRIns *ir)\n{\n  IROp op = ir->o;\n  IRRef hi, kref = nir->op2;\n  if (irref_isk(kref)) {  /* Optimize bit operations with lo constant. */\n    int32_t k = IR(kref)->i;\n    if (k == 0 || k == -1) {\n      if (op == IR_BAND) k = ~k;\n      if (k == 0) {\n\tJ->cur.nins--;\n\tir->prev = nir->op1;\n      } else if (op == IR_BXOR) {\n\tnir->o = IR_BNOT;\n\tnir->op2 = 0;\n      } else {\n\tJ->cur.nins--;\n\tir->prev = kref;\n      }\n    }\n  }\n  hi = hisubst[ir->op1];\n  kref = hisubst[ir->op2];\n  if (irref_isk(kref)) {  /* Optimize bit operations with hi constant. */\n    int32_t k = IR(kref)->i;\n    if (k == 0 || k == -1) {\n      if (op == IR_BAND) k = ~k;\n      if (k == 0) {\n\treturn hi;\n      } else if (op == IR_BXOR) {\n\treturn split_emit(J, IRTI(IR_BNOT), hi, 0);\n      } else {\n\treturn kref;\n      }\n    }\n  }\n  return split_emit(J, IRTI(op), hi, kref);\n}\n#endif\n\n/* Substitute references of a snapshot. */\nstatic void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir)\n{\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    IRIns *ir = &oir[snap_ref(sn)];\n    if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn))))\n      map[n] = ((sn & 0xffff0000) | ir->prev);\n  }\n}\n\n/* Transform the old IR to the new IR. */\nstatic void split_ir(jit_State *J)\n{\n  IRRef nins = J->cur.nins, nk = J->cur.nk;\n  MSize irlen = nins - nk;\n  MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1));\n  IRIns *oir = (IRIns *)lj_buf_tmp(J->L, need);\n  IRRef1 *hisubst;\n  IRRef ref, snref;\n  SnapShot *snap;\n\n  /* Copy old IR to buffer. */\n  memcpy(oir, IR(nk), irlen*sizeof(IRIns));\n  /* Bias hiword substitution table and old IR. Loword kept in field prev. */\n  hisubst = (IRRef1 *)&oir[irlen] - nk;\n  oir -= nk;\n\n  /* Remove all IR instructions, but retain IR constants. */\n  J->cur.nins = REF_FIRST;\n  J->loopref = 0;\n\n  /* Process constants and fixed references. */\n  for (ref = nk; ref <= REF_BASE; ref++) {\n    IRIns *ir = &oir[ref];\n    if ((LJ_SOFTFP && ir->o == IR_KNUM) || ir->o == IR_KINT64) {\n      /* Split up 64 bit constant. */\n      TValue tv = *ir_k64(ir);\n      ir->prev = lj_ir_kint(J, (int32_t)tv.u32.lo);\n      hisubst[ref] = lj_ir_kint(J, (int32_t)tv.u32.hi);\n    } else {\n      ir->prev = ref;  /* Identity substitution for loword. */\n      hisubst[ref] = 0;\n    }\n    if (irt_is64(ir->t) && ir->o != IR_KNULL)\n      ref++;\n  }\n\n  /* Process old IR instructions. */\n  snap = J->cur.snap;\n  snref = snap->ref;\n  for (ref = REF_FIRST; ref < nins; ref++) {\n    IRIns *ir = &oir[ref];\n    IRRef nref = lj_ir_nextins(J);\n    IRIns *nir = IR(nref);\n    IRRef hi = 0;\n\n    if (ref >= snref) {\n      snap->ref = nref;\n      split_subst_snap(J, snap++, oir);\n      snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0;\n    }\n\n    /* Copy-substitute old instruction to new instruction. */\n    nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev;\n    nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev;\n    ir->prev = nref;  /* Loword substitution. */\n    nir->o = ir->o;\n    nir->t.irt = ir->t.irt & ~(IRT_MARK|IRT_ISPHI);\n    hisubst[ref] = 0;\n\n    /* Split 64 bit instructions. */\n#if LJ_SOFTFP\n    if (irt_isnum(ir->t)) {\n      nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD);  /* Turn into INT op. */\n      /* Note: hi ref = lo ref + 1! Required for SNAP_SOFTFPNUM logic. */\n      switch (ir->o) {\n      case IR_ADD:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_add);\n\tbreak;\n      case IR_SUB:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_sub);\n\tbreak;\n      case IR_MUL:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_mul);\n\tbreak;\n      case IR_DIV:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div);\n\tbreak;\n      case IR_POW:\n\thi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi);\n\tbreak;\n      case IR_FPMATH:\n\thi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2);\n\tbreak;\n      case IR_LDEXP:\n\thi = split_call_li(J, hisubst, oir, ir, IRCALL_ldexp);\n\tbreak;\n      case IR_NEG: case IR_ABS:\n\tnir->o = IR_CONV;  /* Pass through loword. */\n\tnir->op2 = (IRT_INT << 5) | IRT_INT;\n\thi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP),\n\t       hisubst[ir->op1],\n\t       lj_ir_kint(J, (int32_t)(0x7fffffffu + (ir->o == IR_NEG))));\n\tbreak;\n      case IR_SLOAD:\n\tif ((nir->op2 & IRSLOAD_CONVERT)) {  /* Convert from int to number. */\n\t  nir->op2 &= ~IRSLOAD_CONVERT;\n\t  ir->prev = nref = split_emit(J, IRTI(IR_CALLN), nref,\n\t\t\t\t       IRCALL_softfp_i2d);\n\t  hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\t  break;\n\t}\n\t/* fallthrough */\n      case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:\n      case IR_STRTO:\n\thi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tbreak;\n      case IR_FLOAD:\n\tlj_assertJ(ir->op1 == REF_NIL, \"expected FLOAD from GG_State\");\n\thi = lj_ir_kint(J, *(int32_t*)((char*)J2GG(J) + ir->op2 + LJ_LE*4));\n\tnir->op2 += LJ_BE*4;\n\tbreak;\n      case IR_XLOAD: {\n\tIRIns inslo = *nir;  /* Save/undo the emit of the lo XLOAD. */\n\tJ->cur.nins--;\n\thi = split_ptr(J, oir, ir->op1);  /* Insert the hiref ADD. */\n#if LJ_BE\n\thi = split_emit(J, IRT(IR_XLOAD, IRT_INT), hi, ir->op2);\n\tinslo.t.irt = IRT_SOFTFP | (inslo.t.irt & IRT_GUARD);\n#endif\n\tnref = lj_ir_nextins(J);\n\tnir = IR(nref);\n\t*nir = inslo;  /* Re-emit lo XLOAD. */\n#if LJ_LE\n\thi = split_emit(J, IRT(IR_XLOAD, IRT_SOFTFP), hi, ir->op2);\n\tir->prev = nref;\n#else\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n\t}\n      case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_XSTORE:\n\tsplit_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nir->op1, hisubst[ir->op2]);\n\tbreak;\n      case IR_CONV: {  /* Conversion to number. Others handled below. */\n\tIRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n\tUNUSED(st);\n#if LJ_32 && LJ_HASFFI\n\tif (st == IRT_I64 || st == IRT_U64) {\n\t  hi = split_call_l(J, hisubst, oir, ir,\n\t\t st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d);\n\t  break;\n\t}\n#endif\n\tlj_assertJ(st == IRT_INT ||\n\t\t   (LJ_32 && LJ_HASFFI && (st == IRT_U32 || st == IRT_FLOAT)),\n\t\t   \"bad source type for CONV\");\n\tnir->o = IR_CALLN;\n#if LJ_32 && LJ_HASFFI\n\tnir->op2 = st == IRT_INT ? IRCALL_softfp_i2d :\n\t\t   st == IRT_FLOAT ? IRCALL_softfp_f2d :\n\t\t   IRCALL_softfp_ui2d;\n#else\n\tnir->op2 = IRCALL_softfp_i2d;\n#endif\n\thi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tbreak;\n\t}\n      case IR_CALLN:\n      case IR_CALLL:\n      case IR_CALLS:\n      case IR_CALLXS:\n\tgoto split_call;\n      case IR_PHI:\n\tif (nir->op1 == nir->op2)\n\t  J->cur.nins--;  /* Drop useless PHIs. */\n\tif (hisubst[ir->op1] != hisubst[ir->op2])\n\t  split_emit(J, IRT(IR_PHI, IRT_SOFTFP),\n\t\t     hisubst[ir->op1], hisubst[ir->op2]);\n\tbreak;\n      case IR_HIOP:\n\tJ->cur.nins--;  /* Drop joining HIOP. */\n\tir->prev = nir->op1;\n\thi = nir->op2;\n\tbreak;\n      default:\n\tlj_assertJ(ir->o <= IR_NE || ir->o == IR_MIN || ir->o == IR_MAX,\n\t\t   \"bad IR op %d\", ir->o);\n\thi = split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP),\n\t\t\thisubst[ir->op1], hisubst[ir->op2]);\n\tbreak;\n      }\n    } else\n#endif\n#if LJ_32 && LJ_HASFFI\n    if (irt_isint64(ir->t)) {\n      IRRef hiref = hisubst[ir->op1];\n      nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD);  /* Turn into INT op. */\n      switch (ir->o) {\n      case IR_ADD:\n      case IR_SUB:\n\t/* Use plain op for hiword if loword cannot produce a carry/borrow. */\n\tif (irref_isk(nir->op2) && IR(nir->op2)->i == 0) {\n\t  ir->prev = nir->op1;  /* Pass through loword. */\n\t  nir->op1 = hiref; nir->op2 = hisubst[ir->op2];\n\t  hi = nref;\n\t  break;\n\t}\n\t/* fallthrough */\n      case IR_NEG:\n\thi = split_emit(J, IRTI(IR_HIOP), hiref, hisubst[ir->op2]);\n\tbreak;\n      case IR_MUL:\n\thi = split_call_ll(J, hisubst, oir, ir, IRCALL_lj_carith_mul64);\n\tbreak;\n      case IR_DIV:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :\n\t\t\t\t\t      IRCALL_lj_carith_divu64);\n\tbreak;\n      case IR_MOD:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :\n\t\t\t\t\t      IRCALL_lj_carith_modu64);\n\tbreak;\n      case IR_POW:\n\thi = split_call_ll(J, hisubst, oir, ir,\n\t\t\t   irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :\n\t\t\t\t\t      IRCALL_lj_carith_powu64);\n\tbreak;\n      case IR_BNOT:\n\thi = split_emit(J, IRTI(IR_BNOT), hiref, 0);\n\tbreak;\n      case IR_BSWAP:\n\tir->prev = split_emit(J, IRTI(IR_BSWAP), hiref, 0);\n\thi = nref;\n\tbreak;\n      case IR_BAND: case IR_BOR: case IR_BXOR:\n\thi = split_bitop(J, hisubst, nir, ir);\n\tbreak;\n      case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR:\n\thi = split_bitshift(J, hisubst, oir, nir, ir);\n\tbreak;\n      case IR_FLOAD:\n\tlj_assertJ(ir->op2 == IRFL_CDATA_INT64, \"only INT64 supported\");\n\thi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4);\n#if LJ_BE\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n      case IR_XLOAD:\n\thi = split_emit(J, IRTI(IR_XLOAD), split_ptr(J, oir, ir->op1), ir->op2);\n#if LJ_BE\n\tir->prev = hi; hi = nref;\n#endif\n\tbreak;\n      case IR_XSTORE:\n\tsplit_emit(J, IRTI(IR_HIOP), nir->op1, hisubst[ir->op2]);\n\tbreak;\n      case IR_CONV: {  /* Conversion to 64 bit integer. Others handled below. */\n\tIRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if LJ_SOFTFP\n\tif (st == IRT_NUM) {  /* NUM to 64 bit int conv. */\n\t  hi = split_call_l(J, hisubst, oir, ir,\n\t\t irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul);\n\t} else if (st == IRT_FLOAT) {  /* FLOAT to 64 bit int conv. */\n\t  nir->o = IR_CALLN;\n\t  nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul;\n\t  hi = split_emit(J, IRTI(IR_HIOP), nref, nref);\n\t}\n#else\n\tif (st == IRT_NUM || st == IRT_FLOAT) {  /* FP to 64 bit int conv. */\n\t  hi = split_emit(J, IRTI(IR_HIOP), nir->op1, nref);\n\t}\n#endif\n\telse if (st == IRT_I64 || st == IRT_U64) {  /* 64/64 bit cast. */\n\t  /* Drop cast, since assembler doesn't care. But fwd both parts. */\n\t  hi = hiref;\n\t  goto fwdlo;\n\t} else if ((ir->op2 & IRCONV_SEXT)) {  /* Sign-extend to 64 bit. */\n\t  IRRef k31 = lj_ir_kint(J, 31);\n\t  nir = IR(nref);  /* May have been reallocated. */\n\t  ir->prev = nir->op1;  /* Pass through loword. */\n\t  nir->o = IR_BSAR;  /* hi = bsar(lo, 31). */\n\t  nir->op2 = k31;\n\t  hi = nref;\n\t} else {  /* Zero-extend to 64 bit. */\n\t  hi = lj_ir_kint(J, 0);\n\t  goto fwdlo;\n\t}\n\tbreak;\n\t}\n      case IR_CALLXS:\n\tgoto split_call;\n      case IR_PHI: {\n\tIRRef hiref2;\n\tif ((irref_isk(nir->op1) && irref_isk(nir->op2)) ||\n\t    nir->op1 == nir->op2)\n\t  J->cur.nins--;  /* Drop useless PHIs. */\n\thiref2 = hisubst[ir->op2];\n\tif (!((irref_isk(hiref) && irref_isk(hiref2)) || hiref == hiref2))\n\t  split_emit(J, IRTI(IR_PHI), hiref, hiref2);\n\tbreak;\n\t}\n      case IR_HIOP:\n\tJ->cur.nins--;  /* Drop joining HIOP. */\n\tir->prev = nir->op1;\n\thi = nir->op2;\n\tbreak;\n      default:\n\tlj_assertJ(ir->o <= IR_NE, \"bad IR op %d\", ir->o);  /* Comparisons. */\n\tsplit_emit(J, IRTGI(IR_HIOP), hiref, hisubst[ir->op2]);\n\tbreak;\n      }\n    } else\n#endif\n#if LJ_SOFTFP\n    if (ir->o == IR_SLOAD) {\n      if ((nir->op2 & IRSLOAD_CONVERT)) {  /* Convert from number to int. */\n\tnir->op2 &= ~IRSLOAD_CONVERT;\n\tif (!(nir->op2 & IRSLOAD_TYPECHECK))\n\t  nir->t.irt = IRT_INT;  /* Drop guard. */\n\tsplit_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);\n\tir->prev = split_num2int(J, nref, nref+1, irt_isguard(ir->t));\n      }\n    } else if (ir->o == IR_TOBIT) {\n      IRRef tmp, op1 = ir->op1;\n      J->cur.nins--;\n#if LJ_LE\n      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);\n#else\n      tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);\n#endif\n      ir->prev = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_lj_vm_tobit);\n    } else if (ir->o == IR_TOSTR || ir->o == IR_TMPREF) {\n      if (hisubst[ir->op1]) {\n\tif (irref_isk(ir->op1))\n\t  nir->op1 = ir->op1;\n\telse\n\t  split_emit(J, IRT(IR_HIOP, IRT_NIL), hisubst[ir->op1], nref);\n      }\n    } else if (ir->o == IR_HREF || ir->o == IR_NEWREF) {\n      if (irref_isk(ir->op2) && hisubst[ir->op2])\n\tnir->op2 = ir->op2;\n    } else\n#endif\n    if (ir->o == IR_CONV) {  /* See above, too. */\n      IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);\n#if LJ_32 && LJ_HASFFI\n      if (st == IRT_I64 || st == IRT_U64) {  /* Conversion from 64 bit int. */\n#if LJ_SOFTFP\n\tif (irt_isfloat(ir->t)) {\n\t  split_call_l(J, hisubst, oir, ir,\n\t\t       st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f);\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t}\n#else\n\tif (irt_isfp(ir->t)) {  /* 64 bit integer to FP conversion. */\n\t  ir->prev = split_emit(J, IRT(IR_HIOP, irt_type(ir->t)),\n\t\t\t\thisubst[ir->op1], nref);\n\t}\n#endif\n\telse {  /* Truncate to lower 32 bits. */\n\tfwdlo:\n\t  ir->prev = nir->op1;  /* Forward loword. */\n\t  /* Replace with NOP to avoid messing up the snapshot logic. */\n\t  nir->ot = IRT(IR_NOP, IRT_NIL);\n\t  nir->op1 = nir->op2 = 0;\n\t}\n      }\n#endif\n#if LJ_SOFTFP && LJ_32 && LJ_HASFFI\n      else if (irt_isfloat(ir->t)) {\n\tif (st == IRT_NUM) {\n\t  split_call_l(J, hisubst, oir, ir, IRCALL_softfp_d2f);\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t} else {\n\t  nir->o = IR_CALLN;\n\t  nir->op2 = st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f;\n\t}\n      } else if (st == IRT_FLOAT) {\n\tnir->o = IR_CALLN;\n\tnir->op2 = irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui;\n      } else\n#endif\n#if LJ_SOFTFP\n      if (st == IRT_NUM || (LJ_32 && LJ_HASFFI && st == IRT_FLOAT)) {\n\tif (irt_isguard(ir->t)) {\n\t  lj_assertJ(st == IRT_NUM && irt_isint(ir->t), \"bad CONV types\");\n\t  J->cur.nins--;\n\t  ir->prev = split_num2int(J, nir->op1, hisubst[ir->op1], 1);\n\t} else {\n\t  split_call_l(J, hisubst, oir, ir,\n#if LJ_32 && LJ_HASFFI\n\t    st == IRT_NUM ?\n\t      (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) :\n\t      (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui)\n#else\n\t    IRCALL_softfp_d2i\n#endif\n\t  );\n\t  J->cur.nins--;  /* Drop unused HIOP. */\n\t}\n      }\n#endif\n    } else if (ir->o == IR_CALLXS) {\n      IRRef hiref;\n    split_call:\n      hiref = hisubst[ir->op1];\n      if (hiref) {\n\tIROpT ot = nir->ot;\n\tIRRef op2 = nir->op2;\n\tnir->ot = IRT(IR_CARG, IRT_NIL);\n#if LJ_LE\n\tnir->op2 = hiref;\n#else\n\tnir->op2 = nir->op1; nir->op1 = hiref;\n#endif\n\tir->prev = nref = split_emit(J, ot, nref, op2);\n      }\n      if (LJ_SOFTFP ? irt_is64(ir->t) : irt_isint64(ir->t))\n\thi = split_emit(J,\n\t  IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),\n\t  nref, nref);\n    } else if (ir->o == IR_CARG) {\n      IRRef hiref = hisubst[ir->op1];\n      if (hiref) {\n\tIRRef op2 = nir->op2;\n#if LJ_LE\n\tnir->op2 = hiref;\n#else\n\tnir->op2 = nir->op1; nir->op1 = hiref;\n#endif\n\tir->prev = nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);\n\tnir = IR(nref);\n      }\n      hiref = hisubst[ir->op2];\n      if (hiref) {\n#if !LJ_TARGET_X86\n\tint carg = 0;\n\tIRIns *cir;\n\tfor (cir = IR(nir->op1); cir->o == IR_CARG; cir = IR(cir->op1))\n\t  carg++;\n\tif ((carg & 1) == 0) {  /* Align 64 bit arguments. */\n\t  IRRef op2 = nir->op2;\n\t  nir->op2 = REF_NIL;\n\t  nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);\n\t  nir = IR(nref);\n\t}\n#endif\n#if LJ_BE\n\t{ IRRef tmp = nir->op2; nir->op2 = hiref; hiref = tmp; }\n#endif\n\tir->prev = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, hiref);\n      }\n    } else if (ir->o == IR_CNEWI) {\n      if (hisubst[ir->op2])\n\tsplit_emit(J, IRT(IR_HIOP, IRT_NIL), nref, hisubst[ir->op2]);\n    } else if (ir->o == IR_LOOP) {\n      J->loopref = nref;  /* Needed by assembler. */\n    }\n    hisubst[ref] = hi;  /* Store hiword substitution. */\n  }\n  if (snref == nins) {  /* Substitution for last snapshot. */\n    snap->ref = J->cur.nins;\n    split_subst_snap(J, snap, oir);\n  }\n\n  /* Add PHI marks. */\n  for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) {\n    IRIns *ir = IR(ref);\n    if (ir->o != IR_PHI) break;\n    if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t);\n    if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t);\n  }\n}\n\n/* Protected callback for split pass. */\nstatic TValue *cpsplit(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  split_ir(J);\n  UNUSED(L); UNUSED(dummy);\n  return NULL;\n}\n\n#if defined(LUA_USE_ASSERT) || LJ_SOFTFP\n/* Slow, but sure way to check whether a SPLIT pass is needed. */\nstatic int split_needsplit(jit_State *J)\n{\n  IRIns *ir, *irend;\n  IRRef ref;\n  for (ir = IR(REF_FIRST), irend = IR(J->cur.nins); ir < irend; ir++)\n    if (LJ_SOFTFP ? irt_is64orfp(ir->t) : irt_isint64(ir->t))\n      return 1;\n  if (LJ_SOFTFP) {\n    for (ref = J->chain[IR_SLOAD]; ref; ref = IR(ref)->prev)\n      if ((IR(ref)->op2 & IRSLOAD_CONVERT))\n\treturn 1;\n    if (J->chain[IR_TOBIT])\n      return 1;\n  }\n  for (ref = J->chain[IR_CONV]; ref; ref = IR(ref)->prev) {\n    IRType st = (IR(ref)->op2 & IRCONV_SRCMASK);\n    if ((LJ_SOFTFP && (st == IRT_NUM || st == IRT_FLOAT)) ||\n\tst == IRT_I64 || st == IRT_U64)\n      return 1;\n  }\n  return 0;  /* Nope. */\n}\n#endif\n\n/* SPLIT pass. */\nvoid lj_opt_split(jit_State *J)\n{\n#if LJ_SOFTFP\n  if (!J->needsplit)\n    J->needsplit = split_needsplit(J);\n#else\n  lj_assertJ(J->needsplit >= split_needsplit(J), \"bad SPLIT state\");\n#endif\n  if (J->needsplit) {\n    int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit);\n    if (errcode) {\n      /* Completely reset the trace to avoid inconsistent dump on abort. */\n      J->cur.nins = J->cur.nk = REF_BASE;\n      J->cur.nsnap = 0;\n      lj_err_throw(J->L, errcode);  /* Propagate errors. */\n    }\n  }\n}\n\n#undef IR\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_parse.c",
    "content": "/*\n** Lua parser (source code -> bytecode).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_parse_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_strfmt.h\"\n#include \"lj_lex.h\"\n#include \"lj_parse.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n\n/* -- Parser structures and definitions ----------------------------------- */\n\n/* Expression kinds. */\ntypedef enum {\n  /* Constant expressions must be first and in this order: */\n  VKNIL,\n  VKFALSE,\n  VKTRUE,\n  VKSTR,\t/* sval = string value */\n  VKNUM,\t/* nval = number value */\n  VKLAST = VKNUM,\n  VKCDATA,\t/* nval = cdata value, not treated as a constant expression */\n  /* Non-constant expressions follow: */\n  VLOCAL,\t/* info = local register, aux = vstack index */\n  VUPVAL,\t/* info = upvalue index, aux = vstack index */\n  VGLOBAL,\t/* sval = string value */\n  VINDEXED,\t/* info = table register, aux = index reg/byte/string const */\n  VJMP,\t\t/* info = instruction PC */\n  VRELOCABLE,\t/* info = instruction PC */\n  VNONRELOC,\t/* info = result register */\n  VCALL,\t/* info = instruction PC, aux = base */\n  VVOID\n} ExpKind;\n\n/* Expression descriptor. */\ntypedef struct ExpDesc {\n  union {\n    struct {\n      uint32_t info;\t/* Primary info. */\n      uint32_t aux;\t/* Secondary info. */\n    } s;\n    TValue nval;\t/* Number value. */\n    GCstr *sval;\t/* String value. */\n  } u;\n  ExpKind k;\n  BCPos t;\t\t/* True condition jump list. */\n  BCPos f;\t\t/* False condition jump list. */\n} ExpDesc;\n\n/* Macros for expressions. */\n#define expr_hasjump(e)\t\t((e)->t != (e)->f)\n\n#define expr_isk(e)\t\t((e)->k <= VKLAST)\n#define expr_isk_nojump(e)\t(expr_isk(e) && !expr_hasjump(e))\n#define expr_isnumk(e)\t\t((e)->k == VKNUM)\n#define expr_isnumk_nojump(e)\t(expr_isnumk(e) && !expr_hasjump(e))\n#define expr_isstrk(e)\t\t((e)->k == VKSTR)\n\n#define expr_numtv(e)\t\tcheck_exp(expr_isnumk((e)), &(e)->u.nval)\n#define expr_numberV(e)\t\tnumberVnum(expr_numtv((e)))\n\n/* Initialize expression. */\nstatic LJ_AINLINE void expr_init(ExpDesc *e, ExpKind k, uint32_t info)\n{\n  e->k = k;\n  e->u.s.info = info;\n  e->f = e->t = NO_JMP;\n}\n\n/* Check number constant for +-0. */\nstatic int expr_numiszero(ExpDesc *e)\n{\n  TValue *o = expr_numtv(e);\n  return tvisint(o) ? (intV(o) == 0) : tviszero(o);\n}\n\n/* Per-function linked list of scope blocks. */\ntypedef struct FuncScope {\n  struct FuncScope *prev;\t/* Link to outer scope. */\n  MSize vstart;\t\t\t/* Start of block-local variables. */\n  uint8_t nactvar;\t\t/* Number of active vars outside the scope. */\n  uint8_t flags;\t\t/* Scope flags. */\n} FuncScope;\n\n#define FSCOPE_LOOP\t\t0x01\t/* Scope is a (breakable) loop. */\n#define FSCOPE_BREAK\t\t0x02\t/* Break used in scope. */\n#define FSCOPE_GOLA\t\t0x04\t/* Goto or label used in scope. */\n#define FSCOPE_UPVAL\t\t0x08\t/* Upvalue in scope. */\n#define FSCOPE_NOCLOSE\t\t0x10\t/* Do not close upvalues. */\n\n#define NAME_BREAK\t\t((GCstr *)(uintptr_t)1)\n\n/* Index into variable stack. */\ntypedef uint16_t VarIndex;\n#define LJ_MAX_VSTACK\t\t(65536 - LJ_MAX_UPVAL)\n\n/* Variable/goto/label info. */\n#define VSTACK_VAR_RW\t\t0x01\t/* R/W variable. */\n#define VSTACK_GOTO\t\t0x02\t/* Pending goto. */\n#define VSTACK_LABEL\t\t0x04\t/* Label. */\n\n/* Per-function state. */\ntypedef struct FuncState {\n  GCtab *kt;\t\t\t/* Hash table for constants. */\n  LexState *ls;\t\t\t/* Lexer state. */\n  lua_State *L;\t\t\t/* Lua state. */\n  FuncScope *bl;\t\t/* Current scope. */\n  struct FuncState *prev;\t/* Enclosing function. */\n  BCPos pc;\t\t\t/* Next bytecode position. */\n  BCPos lasttarget;\t\t/* Bytecode position of last jump target. */\n  BCPos jpc;\t\t\t/* Pending jump list to next bytecode. */\n  BCReg freereg;\t\t/* First free register. */\n  BCReg nactvar;\t\t/* Number of active local variables. */\n  BCReg nkn, nkgc;\t\t/* Number of lua_Number/GCobj constants */\n  BCLine linedefined;\t\t/* First line of the function definition. */\n  BCInsLine *bcbase;\t\t/* Base of bytecode stack. */\n  BCPos bclim;\t\t\t/* Limit of bytecode stack. */\n  MSize vbase;\t\t\t/* Base of variable stack for this function. */\n  uint8_t flags;\t\t/* Prototype flags. */\n  uint8_t numparams;\t\t/* Number of parameters. */\n  uint8_t framesize;\t\t/* Fixed frame size. */\n  uint8_t nuv;\t\t\t/* Number of upvalues */\n  VarIndex varmap[LJ_MAX_LOCVAR];  /* Map from register to variable idx. */\n  VarIndex uvmap[LJ_MAX_UPVAL];\t/* Map from upvalue to variable idx. */\n  VarIndex uvtmp[LJ_MAX_UPVAL];\t/* Temporary upvalue map. */\n} FuncState;\n\n/* Binary and unary operators. ORDER OPR */\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,  /* ORDER ARITH */\n  OPR_CONCAT,\n  OPR_NE, OPR_EQ,\n  OPR_LT, OPR_GE, OPR_LE, OPR_GT,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\nLJ_STATIC_ASSERT((int)BC_ISGE-(int)BC_ISLT == (int)OPR_GE-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_ISLE-(int)BC_ISLT == (int)OPR_LE-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_ISGT-(int)BC_ISLT == (int)OPR_GT-(int)OPR_LT);\nLJ_STATIC_ASSERT((int)BC_SUBVV-(int)BC_ADDVV == (int)OPR_SUB-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_MULVV-(int)BC_ADDVV == (int)OPR_MUL-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_DIVVV-(int)BC_ADDVV == (int)OPR_DIV-(int)OPR_ADD);\nLJ_STATIC_ASSERT((int)BC_MODVV-(int)BC_ADDVV == (int)OPR_MOD-(int)OPR_ADD);\n\n#ifdef LUA_USE_ASSERT\n#define lj_assertFS(c, ...)\t(lj_assertG_(G(fs->L), (c), __VA_ARGS__))\n#else\n#define lj_assertFS(c, ...)\t((void)fs)\n#endif\n\n/* -- Error handling ------------------------------------------------------ */\n\nLJ_NORET LJ_NOINLINE static void err_syntax(LexState *ls, ErrMsg em)\n{\n  lj_lex_error(ls, ls->tok, em);\n}\n\nLJ_NORET LJ_NOINLINE static void err_token(LexState *ls, LexToken tok)\n{\n  lj_lex_error(ls, ls->tok, LJ_ERR_XTOKEN, lj_lex_token2str(ls, tok));\n}\n\nLJ_NORET static void err_limit(FuncState *fs, uint32_t limit, const char *what)\n{\n  if (fs->linedefined == 0)\n    lj_lex_error(fs->ls, 0, LJ_ERR_XLIMM, limit, what);\n  else\n    lj_lex_error(fs->ls, 0, LJ_ERR_XLIMF, fs->linedefined, limit, what);\n}\n\n#define checklimit(fs, v, l, m)\t\tif ((v) >= (l)) err_limit(fs, l, m)\n#define checklimitgt(fs, v, l, m)\tif ((v) > (l)) err_limit(fs, l, m)\n#define checkcond(ls, c, em)\t\t{ if (!(c)) err_syntax(ls, em); }\n\n/* -- Management of constants --------------------------------------------- */\n\n/* Return bytecode encoding for primitive constant. */\n#define const_pri(e)\t\tcheck_exp((e)->k <= VKTRUE, (e)->k)\n\n#define tvhaskslot(o)\t((o)->u32.hi == 0)\n#define tvkslot(o)\t((o)->u32.lo)\n\n/* Add a number constant. */\nstatic BCReg const_num(FuncState *fs, ExpDesc *e)\n{\n  lua_State *L = fs->L;\n  TValue *o;\n  lj_assertFS(expr_isnumk(e), \"bad usage\");\n  o = lj_tab_set(L, fs->kt, &e->u.nval);\n  if (tvhaskslot(o))\n    return tvkslot(o);\n  o->u64 = fs->nkn;\n  return fs->nkn++;\n}\n\n/* Add a GC object constant. */\nstatic BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)\n{\n  lua_State *L = fs->L;\n  TValue key, *o;\n  setgcV(L, &key, gc, itype);\n  /* NOBARRIER: the key is new or kept alive. */\n  o = lj_tab_set(L, fs->kt, &key);\n  if (tvhaskslot(o))\n    return tvkslot(o);\n  o->u64 = fs->nkgc;\n  return fs->nkgc++;\n}\n\n/* Add a string constant. */\nstatic BCReg const_str(FuncState *fs, ExpDesc *e)\n{\n  lj_assertFS(expr_isstrk(e) || e->k == VGLOBAL, \"bad usage\");\n  return const_gc(fs, obj2gco(e->u.sval), LJ_TSTR);\n}\n\n/* Anchor string constant to avoid GC. */\nGCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len)\n{\n  /* NOBARRIER: the key is new or kept alive. */\n  lua_State *L = ls->L;\n  GCstr *s = lj_str_new(L, str, len);\n  TValue *tv = lj_tab_setstr(L, ls->fs->kt, s);\n  if (tvisnil(tv)) setboolV(tv, 1);\n  lj_gc_check(L);\n  return s;\n}\n\n#if LJ_HASFFI\n/* Anchor cdata to avoid GC. */\nvoid lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd)\n{\n  /* NOBARRIER: the key is new or kept alive. */\n  lua_State *L = ls->L;\n  setcdataV(L, tv, cd);\n  setboolV(lj_tab_set(L, ls->fs->kt, tv), 1);\n}\n#endif\n\n/* -- Jump list handling -------------------------------------------------- */\n\n/* Get next element in jump list. */\nstatic BCPos jmp_next(FuncState *fs, BCPos pc)\n{\n  ptrdiff_t delta = bc_j(fs->bcbase[pc].ins);\n  if ((BCPos)delta == NO_JMP)\n    return NO_JMP;\n  else\n    return (BCPos)(((ptrdiff_t)pc+1)+delta);\n}\n\n/* Check if any of the instructions on the jump list produce no value. */\nstatic int jmp_novalue(FuncState *fs, BCPos list)\n{\n  for (; list != NO_JMP; list = jmp_next(fs, list)) {\n    BCIns p = fs->bcbase[list >= 1 ? list-1 : list].ins;\n    if (!(bc_op(p) == BC_ISTC || bc_op(p) == BC_ISFC || bc_a(p) == NO_REG))\n      return 1;\n  }\n  return 0;\n}\n\n/* Patch register of test instructions. */\nstatic int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg)\n{\n  BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc];\n  BCOp op = bc_op(ilp->ins);\n  if (op == BC_ISTC || op == BC_ISFC) {\n    if (reg != NO_REG && reg != bc_d(ilp->ins)) {\n      setbc_a(&ilp->ins, reg);\n    } else {  /* Nothing to store or already in the right register. */\n      setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC));\n      setbc_a(&ilp->ins, 0);\n    }\n  } else if (bc_a(ilp->ins) == NO_REG) {\n    if (reg == NO_REG) {\n      ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0);\n    } else {\n      setbc_a(&ilp->ins, reg);\n      if (reg >= bc_a(ilp[1].ins))\n\tsetbc_a(&ilp[1].ins, reg+1);\n    }\n  } else {\n    return 0;  /* Cannot patch other instructions. */\n  }\n  return 1;\n}\n\n/* Drop values for all instructions on jump list. */\nstatic void jmp_dropval(FuncState *fs, BCPos list)\n{\n  for (; list != NO_JMP; list = jmp_next(fs, list))\n    jmp_patchtestreg(fs, list, NO_REG);\n}\n\n/* Patch jump instruction to target. */\nstatic void jmp_patchins(FuncState *fs, BCPos pc, BCPos dest)\n{\n  BCIns *jmp = &fs->bcbase[pc].ins;\n  BCPos offset = dest-(pc+1)+BCBIAS_J;\n  lj_assertFS(dest != NO_JMP, \"uninitialized jump target\");\n  if (offset > BCMAX_D)\n    err_syntax(fs->ls, LJ_ERR_XJUMP);\n  setbc_d(jmp, offset);\n}\n\n/* Append to jump list. */\nstatic void jmp_append(FuncState *fs, BCPos *l1, BCPos l2)\n{\n  if (l2 == NO_JMP) {\n    return;\n  } else if (*l1 == NO_JMP) {\n    *l1 = l2;\n  } else {\n    BCPos list = *l1;\n    BCPos next;\n    while ((next = jmp_next(fs, list)) != NO_JMP)  /* Find last element. */\n      list = next;\n    jmp_patchins(fs, list, l2);\n  }\n}\n\n/* Patch jump list and preserve produced values. */\nstatic void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget,\n\t\t\t BCReg reg, BCPos dtarget)\n{\n  while (list != NO_JMP) {\n    BCPos next = jmp_next(fs, list);\n    if (jmp_patchtestreg(fs, list, reg))\n      jmp_patchins(fs, list, vtarget);  /* Jump to target with value. */\n    else\n      jmp_patchins(fs, list, dtarget);  /* Jump to default target. */\n    list = next;\n  }\n}\n\n/* Jump to following instruction. Append to list of pending jumps. */\nstatic void jmp_tohere(FuncState *fs, BCPos list)\n{\n  fs->lasttarget = fs->pc;\n  jmp_append(fs, &fs->jpc, list);\n}\n\n/* Patch jump list to target. */\nstatic void jmp_patch(FuncState *fs, BCPos list, BCPos target)\n{\n  if (target == fs->pc) {\n    jmp_tohere(fs, list);\n  } else {\n    lj_assertFS(target < fs->pc, \"bad jump target\");\n    jmp_patchval(fs, list, target, NO_REG, target);\n  }\n}\n\n/* -- Bytecode register allocator ----------------------------------------- */\n\n/* Bump frame size. */\nstatic void bcreg_bump(FuncState *fs, BCReg n)\n{\n  BCReg sz = fs->freereg + n;\n  if (sz > fs->framesize) {\n    if (sz >= LJ_MAX_SLOTS)\n      err_syntax(fs->ls, LJ_ERR_XSLOTS);\n    fs->framesize = (uint8_t)sz;\n  }\n}\n\n/* Reserve registers. */\nstatic void bcreg_reserve(FuncState *fs, BCReg n)\n{\n  bcreg_bump(fs, n);\n  fs->freereg += n;\n}\n\n/* Free register. */\nstatic void bcreg_free(FuncState *fs, BCReg reg)\n{\n  if (reg >= fs->nactvar) {\n    fs->freereg--;\n    lj_assertFS(reg == fs->freereg, \"bad regfree\");\n  }\n}\n\n/* Free register for expression. */\nstatic void expr_free(FuncState *fs, ExpDesc *e)\n{\n  if (e->k == VNONRELOC)\n    bcreg_free(fs, e->u.s.info);\n}\n\n/* -- Bytecode emitter ---------------------------------------------------- */\n\n/* Emit bytecode instruction. */\nstatic BCPos bcemit_INS(FuncState *fs, BCIns ins)\n{\n  BCPos pc = fs->pc;\n  LexState *ls = fs->ls;\n  jmp_patchval(fs, fs->jpc, pc, NO_REG, pc);\n  fs->jpc = NO_JMP;\n  if (LJ_UNLIKELY(pc >= fs->bclim)) {\n    ptrdiff_t base = fs->bcbase - ls->bcstack;\n    checklimit(fs, ls->sizebcstack, LJ_MAX_BCINS, \"bytecode instructions\");\n    lj_mem_growvec(fs->L, ls->bcstack, ls->sizebcstack, LJ_MAX_BCINS,BCInsLine);\n    fs->bclim = (BCPos)(ls->sizebcstack - base);\n    fs->bcbase = ls->bcstack + base;\n  }\n  fs->bcbase[pc].ins = ins;\n  fs->bcbase[pc].line = ls->lastline;\n  fs->pc = pc+1;\n  return pc;\n}\n\n#define bcemit_ABC(fs, o, a, b, c)\tbcemit_INS(fs, BCINS_ABC(o, a, b, c))\n#define bcemit_AD(fs, o, a, d)\t\tbcemit_INS(fs, BCINS_AD(o, a, d))\n#define bcemit_AJ(fs, o, a, j)\t\tbcemit_INS(fs, BCINS_AJ(o, a, j))\n\n#define bcptr(fs, e)\t\t\t(&(fs)->bcbase[(e)->u.s.info].ins)\n\n/* -- Bytecode emitter for expressions ------------------------------------ */\n\n/* Discharge non-constant expression to any register. */\nstatic void expr_discharge(FuncState *fs, ExpDesc *e)\n{\n  BCIns ins;\n  if (e->k == VUPVAL) {\n    ins = BCINS_AD(BC_UGET, 0, e->u.s.info);\n  } else if (e->k == VGLOBAL) {\n    ins = BCINS_AD(BC_GGET, 0, const_str(fs, e));\n  } else if (e->k == VINDEXED) {\n    BCReg rc = e->u.s.aux;\n    if ((int32_t)rc < 0) {\n      ins = BCINS_ABC(BC_TGETS, 0, e->u.s.info, ~rc);\n    } else if (rc > BCMAX_C) {\n      ins = BCINS_ABC(BC_TGETB, 0, e->u.s.info, rc-(BCMAX_C+1));\n    } else {\n      bcreg_free(fs, rc);\n      ins = BCINS_ABC(BC_TGETV, 0, e->u.s.info, rc);\n    }\n    bcreg_free(fs, e->u.s.info);\n  } else if (e->k == VCALL) {\n    e->u.s.info = e->u.s.aux;\n    e->k = VNONRELOC;\n    return;\n  } else if (e->k == VLOCAL) {\n    e->k = VNONRELOC;\n    return;\n  } else {\n    return;\n  }\n  e->u.s.info = bcemit_INS(fs, ins);\n  e->k = VRELOCABLE;\n}\n\n/* Emit bytecode to set a range of registers to nil. */\nstatic void bcemit_nil(FuncState *fs, BCReg from, BCReg n)\n{\n  if (fs->pc > fs->lasttarget) {  /* No jumps to current position? */\n    BCIns *ip = &fs->bcbase[fs->pc-1].ins;\n    BCReg pto, pfrom = bc_a(*ip);\n    switch (bc_op(*ip)) {  /* Try to merge with the previous instruction. */\n    case BC_KPRI:\n      if (bc_d(*ip) != ~LJ_TNIL) break;\n      if (from == pfrom) {\n\tif (n == 1) return;\n      } else if (from == pfrom+1) {\n\tfrom = pfrom;\n\tn++;\n      } else {\n\tbreak;\n      }\n      *ip = BCINS_AD(BC_KNIL, from, from+n-1);  /* Replace KPRI. */\n      return;\n    case BC_KNIL:\n      pto = bc_d(*ip);\n      if (pfrom <= from && from <= pto+1) {  /* Can we connect both ranges? */\n\tif (from+n-1 > pto)\n\t  setbc_d(ip, from+n-1);  /* Patch previous instruction range. */\n\treturn;\n      }\n      break;\n    default:\n      break;\n    }\n  }\n  /* Emit new instruction or replace old instruction. */\n  bcemit_INS(fs, n == 1 ? BCINS_AD(BC_KPRI, from, VKNIL) :\n\t\t\t  BCINS_AD(BC_KNIL, from, from+n-1));\n}\n\n/* Discharge an expression to a specific register. Ignore branches. */\nstatic void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg)\n{\n  BCIns ins;\n  expr_discharge(fs, e);\n  if (e->k == VKSTR) {\n    ins = BCINS_AD(BC_KSTR, reg, const_str(fs, e));\n  } else if (e->k == VKNUM) {\n#if LJ_DUALNUM\n    cTValue *tv = expr_numtv(e);\n    if (tvisint(tv) && checki16(intV(tv)))\n      ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv));\n    else\n#else\n    lua_Number n = expr_numberV(e);\n    int32_t k = lj_num2int(n);\n    if (checki16(k) && n == (lua_Number)k)\n      ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k);\n    else\n#endif\n      ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e));\n#if LJ_HASFFI\n  } else if (e->k == VKCDATA) {\n    fs->flags |= PROTO_FFI;\n    ins = BCINS_AD(BC_KCDATA, reg,\n\t\t   const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA));\n#endif\n  } else if (e->k == VRELOCABLE) {\n    setbc_a(bcptr(fs, e), reg);\n    goto noins;\n  } else if (e->k == VNONRELOC) {\n    if (reg == e->u.s.info)\n      goto noins;\n    ins = BCINS_AD(BC_MOV, reg, e->u.s.info);\n  } else if (e->k == VKNIL) {\n    bcemit_nil(fs, reg, 1);\n    goto noins;\n  } else if (e->k <= VKTRUE) {\n    ins = BCINS_AD(BC_KPRI, reg, const_pri(e));\n  } else {\n    lj_assertFS(e->k == VVOID || e->k == VJMP, \"bad expr type %d\", e->k);\n    return;\n  }\n  bcemit_INS(fs, ins);\nnoins:\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n/* Forward declaration. */\nstatic BCPos bcemit_jmp(FuncState *fs);\n\n/* Discharge an expression to a specific register. */\nstatic void expr_toreg(FuncState *fs, ExpDesc *e, BCReg reg)\n{\n  expr_toreg_nobranch(fs, e, reg);\n  if (e->k == VJMP)\n    jmp_append(fs, &e->t, e->u.s.info);  /* Add it to the true jump list. */\n  if (expr_hasjump(e)) {  /* Discharge expression with branches. */\n    BCPos jend, jfalse = NO_JMP, jtrue = NO_JMP;\n    if (jmp_novalue(fs, e->t) || jmp_novalue(fs, e->f)) {\n      BCPos jval = (e->k == VJMP) ? NO_JMP : bcemit_jmp(fs);\n      jfalse = bcemit_AD(fs, BC_KPRI, reg, VKFALSE);\n      bcemit_AJ(fs, BC_JMP, fs->freereg, 1);\n      jtrue = bcemit_AD(fs, BC_KPRI, reg, VKTRUE);\n      jmp_tohere(fs, jval);\n    }\n    jend = fs->pc;\n    fs->lasttarget = jend;\n    jmp_patchval(fs, e->f, jend, reg, jfalse);\n    jmp_patchval(fs, e->t, jend, reg, jtrue);\n  }\n  e->f = e->t = NO_JMP;\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n/* Discharge an expression to the next free register. */\nstatic void expr_tonextreg(FuncState *fs, ExpDesc *e)\n{\n  expr_discharge(fs, e);\n  expr_free(fs, e);\n  bcreg_reserve(fs, 1);\n  expr_toreg(fs, e, fs->freereg - 1);\n}\n\n/* Discharge an expression to any register. */\nstatic BCReg expr_toanyreg(FuncState *fs, ExpDesc *e)\n{\n  expr_discharge(fs, e);\n  if (e->k == VNONRELOC) {\n    if (!expr_hasjump(e)) return e->u.s.info;  /* Already in a register. */\n    if (e->u.s.info >= fs->nactvar) {\n      expr_toreg(fs, e, e->u.s.info);  /* Discharge to temp. register. */\n      return e->u.s.info;\n    }\n  }\n  expr_tonextreg(fs, e);  /* Discharge to next register. */\n  return e->u.s.info;\n}\n\n/* Partially discharge expression to a value. */\nstatic void expr_toval(FuncState *fs, ExpDesc *e)\n{\n  if (expr_hasjump(e))\n    expr_toanyreg(fs, e);\n  else\n    expr_discharge(fs, e);\n}\n\n/* Emit store for LHS expression. */\nstatic void bcemit_store(FuncState *fs, ExpDesc *var, ExpDesc *e)\n{\n  BCIns ins;\n  if (var->k == VLOCAL) {\n    fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;\n    expr_free(fs, e);\n    expr_toreg(fs, e, var->u.s.info);\n    return;\n  } else if (var->k == VUPVAL) {\n    fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;\n    expr_toval(fs, e);\n    if (e->k <= VKTRUE)\n      ins = BCINS_AD(BC_USETP, var->u.s.info, const_pri(e));\n    else if (e->k == VKSTR)\n      ins = BCINS_AD(BC_USETS, var->u.s.info, const_str(fs, e));\n    else if (e->k == VKNUM)\n      ins = BCINS_AD(BC_USETN, var->u.s.info, const_num(fs, e));\n    else\n      ins = BCINS_AD(BC_USETV, var->u.s.info, expr_toanyreg(fs, e));\n  } else if (var->k == VGLOBAL) {\n    BCReg ra = expr_toanyreg(fs, e);\n    ins = BCINS_AD(BC_GSET, ra, const_str(fs, var));\n  } else {\n    BCReg ra, rc;\n    lj_assertFS(var->k == VINDEXED, \"bad expr type %d\", var->k);\n    ra = expr_toanyreg(fs, e);\n    rc = var->u.s.aux;\n    if ((int32_t)rc < 0) {\n      ins = BCINS_ABC(BC_TSETS, ra, var->u.s.info, ~rc);\n    } else if (rc > BCMAX_C) {\n      ins = BCINS_ABC(BC_TSETB, ra, var->u.s.info, rc-(BCMAX_C+1));\n    } else {\n#ifdef LUA_USE_ASSERT\n      /* Free late alloced key reg to avoid assert on free of value reg. */\n      /* This can only happen when called from expr_table(). */\n      if (e->k == VNONRELOC && ra >= fs->nactvar && rc >= ra)\n\tbcreg_free(fs, rc);\n#endif\n      ins = BCINS_ABC(BC_TSETV, ra, var->u.s.info, rc);\n    }\n  }\n  bcemit_INS(fs, ins);\n  expr_free(fs, e);\n}\n\n/* Emit method lookup expression. */\nstatic void bcemit_method(FuncState *fs, ExpDesc *e, ExpDesc *key)\n{\n  BCReg idx, func, obj = expr_toanyreg(fs, e);\n  expr_free(fs, e);\n  func = fs->freereg;\n  bcemit_AD(fs, BC_MOV, func+1+LJ_FR2, obj);  /* Copy object to 1st argument. */\n  lj_assertFS(expr_isstrk(key), \"bad usage\");\n  idx = const_str(fs, key);\n  if (idx <= BCMAX_C) {\n    bcreg_reserve(fs, 2+LJ_FR2);\n    bcemit_ABC(fs, BC_TGETS, func, obj, idx);\n  } else {\n    bcreg_reserve(fs, 3+LJ_FR2);\n    bcemit_AD(fs, BC_KSTR, func+2+LJ_FR2, idx);\n    bcemit_ABC(fs, BC_TGETV, func, obj, func+2+LJ_FR2);\n    fs->freereg--;\n  }\n  e->u.s.info = func;\n  e->k = VNONRELOC;\n}\n\n/* -- Bytecode emitter for branches --------------------------------------- */\n\n/* Emit unconditional branch. */\nstatic BCPos bcemit_jmp(FuncState *fs)\n{\n  BCPos jpc = fs->jpc;\n  BCPos j = fs->pc - 1;\n  BCIns *ip = &fs->bcbase[j].ins;\n  fs->jpc = NO_JMP;\n  if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) {\n    setbc_j(ip, NO_JMP);\n    fs->lasttarget = j+1;\n  } else {\n    j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP);\n  }\n  jmp_append(fs, &j, jpc);\n  return j;\n}\n\n/* Invert branch condition of bytecode instruction. */\nstatic void invertcond(FuncState *fs, ExpDesc *e)\n{\n  BCIns *ip = &fs->bcbase[e->u.s.info - 1].ins;\n  setbc_op(ip, bc_op(*ip)^1);\n}\n\n/* Emit conditional branch. */\nstatic BCPos bcemit_branch(FuncState *fs, ExpDesc *e, int cond)\n{\n  BCPos pc;\n  if (e->k == VRELOCABLE) {\n    BCIns *ip = bcptr(fs, e);\n    if (bc_op(*ip) == BC_NOT) {\n      *ip = BCINS_AD(cond ? BC_ISF : BC_IST, 0, bc_d(*ip));\n      return bcemit_jmp(fs);\n    }\n  }\n  if (e->k != VNONRELOC) {\n    bcreg_reserve(fs, 1);\n    expr_toreg_nobranch(fs, e, fs->freereg-1);\n  }\n  bcemit_AD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->u.s.info);\n  pc = bcemit_jmp(fs);\n  expr_free(fs, e);\n  return pc;\n}\n\n/* Emit branch on true condition. */\nstatic void bcemit_branch_t(FuncState *fs, ExpDesc *e)\n{\n  BCPos pc;\n  expr_discharge(fs, e);\n  if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)\n    pc = NO_JMP;  /* Never jump. */\n  else if (e->k == VJMP)\n    invertcond(fs, e), pc = e->u.s.info;\n  else if (e->k == VKFALSE || e->k == VKNIL)\n    expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);\n  else\n    pc = bcemit_branch(fs, e, 0);\n  jmp_append(fs, &e->f, pc);\n  jmp_tohere(fs, e->t);\n  e->t = NO_JMP;\n}\n\n/* Emit branch on false condition. */\nstatic void bcemit_branch_f(FuncState *fs, ExpDesc *e)\n{\n  BCPos pc;\n  expr_discharge(fs, e);\n  if (e->k == VKNIL || e->k == VKFALSE)\n    pc = NO_JMP;  /* Never jump. */\n  else if (e->k == VJMP)\n    pc = e->u.s.info;\n  else if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)\n    expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);\n  else\n    pc = bcemit_branch(fs, e, 1);\n  jmp_append(fs, &e->t, pc);\n  jmp_tohere(fs, e->f);\n  e->f = NO_JMP;\n}\n\n/* -- Bytecode emitter for operators -------------------------------------- */\n\n/* Try constant-folding of arithmetic operators. */\nstatic int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  TValue o;\n  lua_Number n;\n  if (!expr_isnumk_nojump(e1) || !expr_isnumk_nojump(e2)) return 0;\n  n = lj_vm_foldarith(expr_numberV(e1), expr_numberV(e2), (int)opr-OPR_ADD);\n  setnumV(&o, n);\n  if (tvisnan(&o) || tvismzero(&o)) return 0;  /* Avoid NaN and -0 as consts. */\n  if (LJ_DUALNUM) {\n    int32_t k = lj_num2int(n);\n    if ((lua_Number)k == n) {\n      setintV(&e1->u.nval, k);\n      return 1;\n    }\n  }\n  setnumV(&e1->u.nval, n);\n  return 1;\n}\n\n/* Emit arithmetic operator. */\nstatic void bcemit_arith(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  BCReg rb, rc, t;\n  uint32_t op;\n  if (foldarith(opr, e1, e2))\n    return;\n  if (opr == OPR_POW) {\n    op = BC_POW;\n    rc = expr_toanyreg(fs, e2);\n    rb = expr_toanyreg(fs, e1);\n  } else {\n    op = opr-OPR_ADD+BC_ADDVV;\n    /* Must discharge 2nd operand first since VINDEXED might free regs. */\n    expr_toval(fs, e2);\n    if (expr_isnumk(e2) && (rc = const_num(fs, e2)) <= BCMAX_C)\n      op -= BC_ADDVV-BC_ADDVN;\n    else\n      rc = expr_toanyreg(fs, e2);\n    /* 1st operand discharged by bcemit_binop_left, but need KNUM/KSHORT. */\n    lj_assertFS(expr_isnumk(e1) || e1->k == VNONRELOC,\n\t\t\"bad expr type %d\", e1->k);\n    expr_toval(fs, e1);\n    /* Avoid two consts to satisfy bytecode constraints. */\n    if (expr_isnumk(e1) && !expr_isnumk(e2) &&\n\t(t = const_num(fs, e1)) <= BCMAX_B) {\n      rb = rc; rc = t; op -= BC_ADDVV-BC_ADDNV;\n    } else {\n      rb = expr_toanyreg(fs, e1);\n    }\n  }\n  /* Using expr_free might cause asserts if the order is wrong. */\n  if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;\n  if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;\n  e1->u.s.info = bcemit_ABC(fs, op, 0, rb, rc);\n  e1->k = VRELOCABLE;\n}\n\n/* Emit comparison operator. */\nstatic void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)\n{\n  ExpDesc *eret = e1;\n  BCIns ins;\n  expr_toval(fs, e1);\n  if (opr == OPR_EQ || opr == OPR_NE) {\n    BCOp op = opr == OPR_EQ ? BC_ISEQV : BC_ISNEV;\n    BCReg ra;\n    if (expr_isk(e1)) { e1 = e2; e2 = eret; }  /* Need constant in 2nd arg. */\n    ra = expr_toanyreg(fs, e1);  /* First arg must be in a reg. */\n    expr_toval(fs, e2);\n    switch (e2->k) {\n    case VKNIL: case VKFALSE: case VKTRUE:\n      ins = BCINS_AD(op+(BC_ISEQP-BC_ISEQV), ra, const_pri(e2));\n      break;\n    case VKSTR:\n      ins = BCINS_AD(op+(BC_ISEQS-BC_ISEQV), ra, const_str(fs, e2));\n      break;\n    case VKNUM:\n      ins = BCINS_AD(op+(BC_ISEQN-BC_ISEQV), ra, const_num(fs, e2));\n      break;\n    default:\n      ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2));\n      break;\n    }\n  } else {\n    uint32_t op = opr-OPR_LT+BC_ISLT;\n    BCReg ra, rd;\n    if ((op-BC_ISLT) & 1) {  /* GT -> LT, GE -> LE */\n      e1 = e2; e2 = eret;  /* Swap operands. */\n      op = ((op-BC_ISLT)^3)+BC_ISLT;\n      expr_toval(fs, e1);\n      ra = expr_toanyreg(fs, e1);\n      rd = expr_toanyreg(fs, e2);\n    } else {\n      rd = expr_toanyreg(fs, e2);\n      ra = expr_toanyreg(fs, e1);\n    }\n    ins = BCINS_AD(op, ra, rd);\n  }\n  /* Using expr_free might cause asserts if the order is wrong. */\n  if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;\n  if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;\n  bcemit_INS(fs, ins);\n  eret->u.s.info = bcemit_jmp(fs);\n  eret->k = VJMP;\n}\n\n/* Fixup left side of binary operator. */\nstatic void bcemit_binop_left(FuncState *fs, BinOpr op, ExpDesc *e)\n{\n  if (op == OPR_AND) {\n    bcemit_branch_t(fs, e);\n  } else if (op == OPR_OR) {\n    bcemit_branch_f(fs, e);\n  } else if (op == OPR_CONCAT) {\n    expr_tonextreg(fs, e);\n  } else if (op == OPR_EQ || op == OPR_NE) {\n    if (!expr_isk_nojump(e)) expr_toanyreg(fs, e);\n  } else {\n    if (!expr_isnumk_nojump(e)) expr_toanyreg(fs, e);\n  }\n}\n\n/* Emit binary operator. */\nstatic void bcemit_binop(FuncState *fs, BinOpr op, ExpDesc *e1, ExpDesc *e2)\n{\n  if (op <= OPR_POW) {\n    bcemit_arith(fs, op, e1, e2);\n  } else if (op == OPR_AND) {\n    lj_assertFS(e1->t == NO_JMP, \"jump list not closed\");\n    expr_discharge(fs, e2);\n    jmp_append(fs, &e2->f, e1->f);\n    *e1 = *e2;\n  } else if (op == OPR_OR) {\n    lj_assertFS(e1->f == NO_JMP, \"jump list not closed\");\n    expr_discharge(fs, e2);\n    jmp_append(fs, &e2->t, e1->t);\n    *e1 = *e2;\n  } else if (op == OPR_CONCAT) {\n    expr_toval(fs, e2);\n    if (e2->k == VRELOCABLE && bc_op(*bcptr(fs, e2)) == BC_CAT) {\n      lj_assertFS(e1->u.s.info == bc_b(*bcptr(fs, e2))-1,\n\t\t  \"bad CAT stack layout\");\n      expr_free(fs, e1);\n      setbc_b(bcptr(fs, e2), e1->u.s.info);\n      e1->u.s.info = e2->u.s.info;\n    } else {\n      expr_tonextreg(fs, e2);\n      expr_free(fs, e2);\n      expr_free(fs, e1);\n      e1->u.s.info = bcemit_ABC(fs, BC_CAT, 0, e1->u.s.info, e2->u.s.info);\n    }\n    e1->k = VRELOCABLE;\n  } else {\n    lj_assertFS(op == OPR_NE || op == OPR_EQ ||\n\t       op == OPR_LT || op == OPR_GE || op == OPR_LE || op == OPR_GT,\n\t       \"bad binop %d\", op);\n    bcemit_comp(fs, op, e1, e2);\n  }\n}\n\n/* Emit unary operator. */\nstatic void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e)\n{\n  if (op == BC_NOT) {\n    /* Swap true and false lists. */\n    { BCPos temp = e->f; e->f = e->t; e->t = temp; }\n    jmp_dropval(fs, e->f);\n    jmp_dropval(fs, e->t);\n    expr_discharge(fs, e);\n    if (e->k == VKNIL || e->k == VKFALSE) {\n      e->k = VKTRUE;\n      return;\n    } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) {\n      e->k = VKFALSE;\n      return;\n    } else if (e->k == VJMP) {\n      invertcond(fs, e);\n      return;\n    } else if (e->k == VRELOCABLE) {\n      bcreg_reserve(fs, 1);\n      setbc_a(bcptr(fs, e), fs->freereg-1);\n      e->u.s.info = fs->freereg-1;\n      e->k = VNONRELOC;\n    } else {\n      lj_assertFS(e->k == VNONRELOC, \"bad expr type %d\", e->k);\n    }\n  } else {\n    lj_assertFS(op == BC_UNM || op == BC_LEN, \"bad unop %d\", op);\n    if (op == BC_UNM && !expr_hasjump(e)) {  /* Constant-fold negations. */\n#if LJ_HASFFI\n      if (e->k == VKCDATA) {  /* Fold in-place since cdata is not interned. */\n\tGCcdata *cd = cdataV(&e->u.nval);\n\tint64_t *p = (int64_t *)cdataptr(cd);\n\tif (cd->ctypeid == CTID_COMPLEX_DOUBLE)\n\t  p[1] ^= (int64_t)U64x(80000000,00000000);\n\telse\n\t  *p = -*p;\n\treturn;\n      } else\n#endif\n      if (expr_isnumk(e) && !expr_numiszero(e)) {  /* Avoid folding to -0. */\n\tTValue *o = expr_numtv(e);\n\tif (tvisint(o)) {\n\t  int32_t k = intV(o);\n\t  if (k == -k)\n\t    setnumV(o, -(lua_Number)k);\n\t  else\n\t    setintV(o, -k);\n\t  return;\n\t} else {\n\t  o->u64 ^= U64x(80000000,00000000);\n\t  return;\n\t}\n      }\n    }\n    expr_toanyreg(fs, e);\n  }\n  expr_free(fs, e);\n  e->u.s.info = bcemit_AD(fs, op, 0, e->u.s.info);\n  e->k = VRELOCABLE;\n}\n\n/* -- Lexer support ------------------------------------------------------- */\n\n/* Check and consume optional token. */\nstatic int lex_opt(LexState *ls, LexToken tok)\n{\n  if (ls->tok == tok) {\n    lj_lex_next(ls);\n    return 1;\n  }\n  return 0;\n}\n\n/* Check and consume token. */\nstatic void lex_check(LexState *ls, LexToken tok)\n{\n  if (ls->tok != tok)\n    err_token(ls, tok);\n  lj_lex_next(ls);\n}\n\n/* Check for matching token. */\nstatic void lex_match(LexState *ls, LexToken what, LexToken who, BCLine line)\n{\n  if (!lex_opt(ls, what)) {\n    if (line == ls->linenumber) {\n      err_token(ls, what);\n    } else {\n      const char *swhat = lj_lex_token2str(ls, what);\n      const char *swho = lj_lex_token2str(ls, who);\n      lj_lex_error(ls, ls->tok, LJ_ERR_XMATCH, swhat, swho, line);\n    }\n  }\n}\n\n/* Check for string token. */\nstatic GCstr *lex_str(LexState *ls)\n{\n  GCstr *s;\n  if (ls->tok != TK_name && (LJ_52 || ls->tok != TK_goto))\n    err_token(ls, TK_name);\n  s = strV(&ls->tokval);\n  lj_lex_next(ls);\n  return s;\n}\n\n/* -- Variable handling --------------------------------------------------- */\n\n#define var_get(ls, fs, i)\t((ls)->vstack[(fs)->varmap[(i)]])\n\n/* Define a new local variable. */\nstatic void var_new(LexState *ls, BCReg n, GCstr *name)\n{\n  FuncState *fs = ls->fs;\n  MSize vtop = ls->vtop;\n  checklimit(fs, fs->nactvar+n, LJ_MAX_LOCVAR, \"local variables\");\n  if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {\n    if (ls->sizevstack >= LJ_MAX_VSTACK)\n      lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);\n    lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);\n  }\n  lj_assertFS((uintptr_t)name < VARNAME__MAX ||\n\t      lj_tab_getstr(fs->kt, name) != NULL,\n\t      \"unanchored variable name\");\n  /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */\n  setgcref(ls->vstack[vtop].name, obj2gco(name));\n  fs->varmap[fs->nactvar+n] = (uint16_t)vtop;\n  ls->vtop = vtop+1;\n}\n\n#define var_new_lit(ls, n, v) \\\n  var_new(ls, (n), lj_parse_keepstr(ls, \"\" v, sizeof(v)-1))\n\n#define var_new_fixed(ls, n, vn) \\\n  var_new(ls, (n), (GCstr *)(uintptr_t)(vn))\n\n/* Add local variables. */\nstatic void var_add(LexState *ls, BCReg nvars)\n{\n  FuncState *fs = ls->fs;\n  BCReg nactvar = fs->nactvar;\n  while (nvars--) {\n    VarInfo *v = &var_get(ls, fs, nactvar);\n    v->startpc = fs->pc;\n    v->slot = nactvar++;\n    v->info = 0;\n  }\n  fs->nactvar = nactvar;\n}\n\n/* Remove local variables. */\nstatic void var_remove(LexState *ls, BCReg tolevel)\n{\n  FuncState *fs = ls->fs;\n  while (fs->nactvar > tolevel)\n    var_get(ls, fs, --fs->nactvar).endpc = fs->pc;\n}\n\n/* Lookup local variable name. */\nstatic BCReg var_lookup_local(FuncState *fs, GCstr *n)\n{\n  int i;\n  for (i = fs->nactvar-1; i >= 0; i--) {\n    if (n == strref(var_get(fs->ls, fs, i).name))\n      return (BCReg)i;\n  }\n  return (BCReg)-1;  /* Not found. */\n}\n\n/* Lookup or add upvalue index. */\nstatic MSize var_lookup_uv(FuncState *fs, MSize vidx, ExpDesc *e)\n{\n  MSize i, n = fs->nuv;\n  for (i = 0; i < n; i++)\n    if (fs->uvmap[i] == vidx)\n      return i;  /* Already exists. */\n  /* Otherwise create a new one. */\n  checklimit(fs, fs->nuv, LJ_MAX_UPVAL, \"upvalues\");\n  lj_assertFS(e->k == VLOCAL || e->k == VUPVAL, \"bad expr type %d\", e->k);\n  fs->uvmap[n] = (uint16_t)vidx;\n  fs->uvtmp[n] = (uint16_t)(e->k == VLOCAL ? vidx : LJ_MAX_VSTACK+e->u.s.info);\n  fs->nuv = n+1;\n  return n;\n}\n\n/* Forward declaration. */\nstatic void fscope_uvmark(FuncState *fs, BCReg level);\n\n/* Recursively lookup variables in enclosing functions. */\nstatic MSize var_lookup_(FuncState *fs, GCstr *name, ExpDesc *e, int first)\n{\n  if (fs) {\n    BCReg reg = var_lookup_local(fs, name);\n    if ((int32_t)reg >= 0) {  /* Local in this function? */\n      expr_init(e, VLOCAL, reg);\n      if (!first)\n\tfscope_uvmark(fs, reg);  /* Scope now has an upvalue. */\n      return (MSize)(e->u.s.aux = (uint32_t)fs->varmap[reg]);\n    } else {\n      MSize vidx = var_lookup_(fs->prev, name, e, 0);  /* Var in outer func? */\n      if ((int32_t)vidx >= 0) {  /* Yes, make it an upvalue here. */\n\te->u.s.info = (uint8_t)var_lookup_uv(fs, vidx, e);\n\te->k = VUPVAL;\n\treturn vidx;\n      }\n    }\n  } else {  /* Not found in any function, must be a global. */\n    expr_init(e, VGLOBAL, 0);\n    e->u.sval = name;\n  }\n  return (MSize)-1;  /* Global. */\n}\n\n/* Lookup variable name. */\n#define var_lookup(ls, e) \\\n  var_lookup_((ls)->fs, lex_str(ls), (e), 1)\n\n/* -- Goto an label handling ---------------------------------------------- */\n\n/* Add a new goto or label. */\nstatic MSize gola_new(LexState *ls, GCstr *name, uint8_t info, BCPos pc)\n{\n  FuncState *fs = ls->fs;\n  MSize vtop = ls->vtop;\n  if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {\n    if (ls->sizevstack >= LJ_MAX_VSTACK)\n      lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);\n    lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);\n  }\n  lj_assertFS(name == NAME_BREAK || lj_tab_getstr(fs->kt, name) != NULL,\n\t      \"unanchored label name\");\n  /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */\n  setgcref(ls->vstack[vtop].name, obj2gco(name));\n  ls->vstack[vtop].startpc = pc;\n  ls->vstack[vtop].slot = (uint8_t)fs->nactvar;\n  ls->vstack[vtop].info = info;\n  ls->vtop = vtop+1;\n  return vtop;\n}\n\n#define gola_isgoto(v)\t\t((v)->info & VSTACK_GOTO)\n#define gola_islabel(v)\t\t((v)->info & VSTACK_LABEL)\n#define gola_isgotolabel(v)\t((v)->info & (VSTACK_GOTO|VSTACK_LABEL))\n\n/* Patch goto to jump to label. */\nstatic void gola_patch(LexState *ls, VarInfo *vg, VarInfo *vl)\n{\n  FuncState *fs = ls->fs;\n  BCPos pc = vg->startpc;\n  setgcrefnull(vg->name);  /* Invalidate pending goto. */\n  setbc_a(&fs->bcbase[pc].ins, vl->slot);\n  jmp_patch(fs, pc, vl->startpc);\n}\n\n/* Patch goto to close upvalues. */\nstatic void gola_close(LexState *ls, VarInfo *vg)\n{\n  FuncState *fs = ls->fs;\n  BCPos pc = vg->startpc;\n  BCIns *ip = &fs->bcbase[pc].ins;\n  lj_assertFS(gola_isgoto(vg), \"expected goto\");\n  lj_assertFS(bc_op(*ip) == BC_JMP || bc_op(*ip) == BC_UCLO,\n\t      \"bad bytecode op %d\", bc_op(*ip));\n  setbc_a(ip, vg->slot);\n  if (bc_op(*ip) == BC_JMP) {\n    BCPos next = jmp_next(fs, pc);\n    if (next != NO_JMP) jmp_patch(fs, next, pc);  /* Jump to UCLO. */\n    setbc_op(ip, BC_UCLO);  /* Turn into UCLO. */\n    setbc_j(ip, NO_JMP);\n  }\n}\n\n/* Resolve pending forward gotos for label. */\nstatic void gola_resolve(LexState *ls, FuncScope *bl, MSize idx)\n{\n  VarInfo *vg = ls->vstack + bl->vstart;\n  VarInfo *vl = ls->vstack + idx;\n  for (; vg < vl; vg++)\n    if (gcrefeq(vg->name, vl->name) && gola_isgoto(vg)) {\n      if (vg->slot < vl->slot) {\n\tGCstr *name = strref(var_get(ls, ls->fs, vg->slot).name);\n\tlj_assertLS((uintptr_t)name >= VARNAME__MAX, \"expected goto name\");\n\tls->linenumber = ls->fs->bcbase[vg->startpc].line;\n\tlj_assertLS(strref(vg->name) != NAME_BREAK, \"unexpected break\");\n\tlj_lex_error(ls, 0, LJ_ERR_XGSCOPE,\n\t\t     strdata(strref(vg->name)), strdata(name));\n      }\n      gola_patch(ls, vg, vl);\n    }\n}\n\n/* Fixup remaining gotos and labels for scope. */\nstatic void gola_fixup(LexState *ls, FuncScope *bl)\n{\n  VarInfo *v = ls->vstack + bl->vstart;\n  VarInfo *ve = ls->vstack + ls->vtop;\n  for (; v < ve; v++) {\n    GCstr *name = strref(v->name);\n    if (name != NULL) {  /* Only consider remaining valid gotos/labels. */\n      if (gola_islabel(v)) {\n\tVarInfo *vg;\n\tsetgcrefnull(v->name);  /* Invalidate label that goes out of scope. */\n\tfor (vg = v+1; vg < ve; vg++)  /* Resolve pending backward gotos. */\n\t  if (strref(vg->name) == name && gola_isgoto(vg)) {\n\t    if ((bl->flags&FSCOPE_UPVAL) && vg->slot > v->slot)\n\t      gola_close(ls, vg);\n\t    gola_patch(ls, vg, v);\n\t  }\n      } else if (gola_isgoto(v)) {\n\tif (bl->prev) {  /* Propagate goto or break to outer scope. */\n\t  bl->prev->flags |= name == NAME_BREAK ? FSCOPE_BREAK : FSCOPE_GOLA;\n\t  v->slot = bl->nactvar;\n\t  if ((bl->flags & FSCOPE_UPVAL))\n\t    gola_close(ls, v);\n\t} else {  /* No outer scope: undefined goto label or no loop. */\n\t  ls->linenumber = ls->fs->bcbase[v->startpc].line;\n\t  if (name == NAME_BREAK)\n\t    lj_lex_error(ls, 0, LJ_ERR_XBREAK);\n\t  else\n\t    lj_lex_error(ls, 0, LJ_ERR_XLUNDEF, strdata(name));\n\t}\n      }\n    }\n  }\n}\n\n/* Find existing label. */\nstatic VarInfo *gola_findlabel(LexState *ls, GCstr *name)\n{\n  VarInfo *v = ls->vstack + ls->fs->bl->vstart;\n  VarInfo *ve = ls->vstack + ls->vtop;\n  for (; v < ve; v++)\n    if (strref(v->name) == name && gola_islabel(v))\n      return v;\n  return NULL;\n}\n\n/* -- Scope handling ------------------------------------------------------ */\n\n/* Begin a scope. */\nstatic void fscope_begin(FuncState *fs, FuncScope *bl, int flags)\n{\n  bl->nactvar = (uint8_t)fs->nactvar;\n  bl->flags = flags;\n  bl->vstart = fs->ls->vtop;\n  bl->prev = fs->bl;\n  fs->bl = bl;\n  lj_assertFS(fs->freereg == fs->nactvar, \"bad regalloc\");\n}\n\n/* End a scope. */\nstatic void fscope_end(FuncState *fs)\n{\n  FuncScope *bl = fs->bl;\n  LexState *ls = fs->ls;\n  fs->bl = bl->prev;\n  var_remove(ls, bl->nactvar);\n  fs->freereg = fs->nactvar;\n  lj_assertFS(bl->nactvar == fs->nactvar, \"bad regalloc\");\n  if ((bl->flags & (FSCOPE_UPVAL|FSCOPE_NOCLOSE)) == FSCOPE_UPVAL)\n    bcemit_AJ(fs, BC_UCLO, bl->nactvar, 0);\n  if ((bl->flags & FSCOPE_BREAK)) {\n    if ((bl->flags & FSCOPE_LOOP)) {\n      MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc);\n      ls->vtop = idx;  /* Drop break label immediately. */\n      gola_resolve(ls, bl, idx);\n    } else {  /* Need the fixup step to propagate the breaks. */\n      gola_fixup(ls, bl);\n      return;\n    }\n  }\n  if ((bl->flags & FSCOPE_GOLA)) {\n    gola_fixup(ls, bl);\n  }\n}\n\n/* Mark scope as having an upvalue. */\nstatic void fscope_uvmark(FuncState *fs, BCReg level)\n{\n  FuncScope *bl;\n  for (bl = fs->bl; bl && bl->nactvar > level; bl = bl->prev)\n    ;\n  if (bl)\n    bl->flags |= FSCOPE_UPVAL;\n}\n\n/* -- Function state management ------------------------------------------- */\n\n/* Fixup bytecode for prototype. */\nstatic void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, MSize n)\n{\n  BCInsLine *base = fs->bcbase;\n  MSize i;\n  pt->sizebc = n;\n  bc[0] = BCINS_AD((fs->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,\n\t\t   fs->framesize, 0);\n  for (i = 1; i < n; i++)\n    bc[i] = base[i].ins;\n}\n\n/* Fixup upvalues for child prototype, step #2. */\nstatic void fs_fixup_uv2(FuncState *fs, GCproto *pt)\n{\n  VarInfo *vstack = fs->ls->vstack;\n  uint16_t *uv = proto_uv(pt);\n  MSize i, n = pt->sizeuv;\n  for (i = 0; i < n; i++) {\n    VarIndex vidx = uv[i];\n    if (vidx >= LJ_MAX_VSTACK)\n      uv[i] = vidx - LJ_MAX_VSTACK;\n    else if ((vstack[vidx].info & VSTACK_VAR_RW))\n      uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL;\n    else\n      uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL | PROTO_UV_IMMUTABLE;\n  }\n}\n\n/* Fixup constants for prototype. */\nstatic void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr)\n{\n  GCtab *kt;\n  TValue *array;\n  Node *node;\n  MSize i, hmask;\n  checklimitgt(fs, fs->nkn, BCMAX_D+1, \"constants\");\n  checklimitgt(fs, fs->nkgc, BCMAX_D+1, \"constants\");\n  setmref(pt->k, kptr);\n  pt->sizekn = fs->nkn;\n  pt->sizekgc = fs->nkgc;\n  kt = fs->kt;\n  array = tvref(kt->array);\n  for (i = 0; i < kt->asize; i++)\n    if (tvhaskslot(&array[i])) {\n      TValue *tv = &((TValue *)kptr)[tvkslot(&array[i])];\n      if (LJ_DUALNUM)\n\tsetintV(tv, (int32_t)i);\n      else\n\tsetnumV(tv, (lua_Number)i);\n    }\n  node = noderef(kt->node);\n  hmask = kt->hmask;\n  for (i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    if (tvhaskslot(&n->val)) {\n      ptrdiff_t kidx = (ptrdiff_t)tvkslot(&n->val);\n      lj_assertFS(!tvisint(&n->key), \"unexpected integer key\");\n      if (tvisnum(&n->key)) {\n\tTValue *tv = &((TValue *)kptr)[kidx];\n\tif (LJ_DUALNUM) {\n\t  lua_Number nn = numV(&n->key);\n\t  int32_t k = lj_num2int(nn);\n\t  lj_assertFS(!tvismzero(&n->key), \"unexpected -0 key\");\n\t  if ((lua_Number)k == nn)\n\t    setintV(tv, k);\n\t  else\n\t    *tv = n->key;\n\t} else {\n\t  *tv = n->key;\n\t}\n      } else {\n\tGCobj *o = gcV(&n->key);\n\tsetgcref(((GCRef *)kptr)[~kidx], o);\n\tlj_gc_objbarrier(fs->L, pt, o);\n\tif (tvisproto(&n->key))\n\t  fs_fixup_uv2(fs, gco2pt(o));\n      }\n    }\n  }\n}\n\n/* Fixup upvalues for prototype, step #1. */\nstatic void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv)\n{\n  setmref(pt->uv, uv);\n  pt->sizeuv = fs->nuv;\n  memcpy(uv, fs->uvtmp, fs->nuv*sizeof(VarIndex));\n}\n\n#ifndef LUAJIT_DISABLE_DEBUGINFO\n/* Prepare lineinfo for prototype. */\nstatic size_t fs_prep_line(FuncState *fs, BCLine numline)\n{\n  return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);\n}\n\n/* Fixup lineinfo for prototype. */\nstatic void fs_fixup_line(FuncState *fs, GCproto *pt,\n\t\t\t  void *lineinfo, BCLine numline)\n{\n  BCInsLine *base = fs->bcbase + 1;\n  BCLine first = fs->linedefined;\n  MSize i = 0, n = fs->pc-1;\n  pt->firstline = fs->linedefined;\n  pt->numline = numline;\n  setmref(pt->lineinfo, lineinfo);\n  if (LJ_LIKELY(numline < 256)) {\n    uint8_t *li = (uint8_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lj_assertFS(delta >= 0 && delta < 256, \"bad line delta\");\n      li[i] = (uint8_t)delta;\n    } while (++i < n);\n  } else if (LJ_LIKELY(numline < 65536)) {\n    uint16_t *li = (uint16_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lj_assertFS(delta >= 0 && delta < 65536, \"bad line delta\");\n      li[i] = (uint16_t)delta;\n    } while (++i < n);\n  } else {\n    uint32_t *li = (uint32_t *)lineinfo;\n    do {\n      BCLine delta = base[i].line - first;\n      lj_assertFS(delta >= 0, \"bad line delta\");\n      li[i] = (uint32_t)delta;\n    } while (++i < n);\n  }\n}\n\n/* Prepare variable info for prototype. */\nstatic size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar)\n{\n  VarInfo *vs =ls->vstack, *ve;\n  MSize i, n;\n  BCPos lastpc;\n  lj_buf_reset(&ls->sb);  /* Copy to temp. string buffer. */\n  /* Store upvalue names. */\n  for (i = 0, n = fs->nuv; i < n; i++) {\n    GCstr *s = strref(vs[fs->uvmap[i]].name);\n    MSize len = s->len+1;\n    char *p = lj_buf_more(&ls->sb, len);\n    p = lj_buf_wmem(p, strdata(s), len);\n    ls->sb.w = p;\n  }\n  *ofsvar = sbuflen(&ls->sb);\n  lastpc = 0;\n  /* Store local variable names and compressed ranges. */\n  for (ve = vs + ls->vtop, vs += fs->vbase; vs < ve; vs++) {\n    if (!gola_isgotolabel(vs)) {\n      GCstr *s = strref(vs->name);\n      BCPos startpc;\n      char *p;\n      if ((uintptr_t)s < VARNAME__MAX) {\n\tp = lj_buf_more(&ls->sb, 1 + 2*5);\n\t*p++ = (char)(uintptr_t)s;\n      } else {\n\tMSize len = s->len+1;\n\tp = lj_buf_more(&ls->sb, len + 2*5);\n\tp = lj_buf_wmem(p, strdata(s), len);\n      }\n      startpc = vs->startpc;\n      p = lj_strfmt_wuleb128(p, startpc-lastpc);\n      p = lj_strfmt_wuleb128(p, vs->endpc-startpc);\n      ls->sb.w = p;\n      lastpc = startpc;\n    }\n  }\n  lj_buf_putb(&ls->sb, '\\0');  /* Terminator for varinfo. */\n  return sbuflen(&ls->sb);\n}\n\n/* Fixup variable info for prototype. */\nstatic void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)\n{\n  setmref(pt->uvinfo, p);\n  setmref(pt->varinfo, (char *)p + ofsvar);\n  memcpy(p, ls->sb.b, sbuflen(&ls->sb));  /* Copy from temp. buffer. */\n}\n#else\n\n/* Initialize with empty debug info, if disabled. */\n#define fs_prep_line(fs, numline)\t\t(UNUSED(numline), 0)\n#define fs_fixup_line(fs, pt, li, numline) \\\n  pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)\n#define fs_prep_var(ls, fs, ofsvar)\t\t(UNUSED(ofsvar), 0)\n#define fs_fixup_var(ls, pt, p, ofsvar) \\\n  setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL)\n\n#endif\n\n/* Check if bytecode op returns. */\nstatic int bcopisret(BCOp op)\n{\n  switch (op) {\n  case BC_CALLMT: case BC_CALLT:\n  case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:\n    return 1;\n  default:\n    return 0;\n  }\n}\n\n/* Fixup return instruction for prototype. */\nstatic void fs_fixup_ret(FuncState *fs)\n{\n  BCPos lastpc = fs->pc;\n  if (lastpc <= fs->lasttarget || !bcopisret(bc_op(fs->bcbase[lastpc-1].ins))) {\n    if ((fs->bl->flags & FSCOPE_UPVAL))\n      bcemit_AJ(fs, BC_UCLO, 0, 0);\n    bcemit_AD(fs, BC_RET0, 0, 1);  /* Need final return. */\n  }\n  fs->bl->flags |= FSCOPE_NOCLOSE;  /* Handled above. */\n  fscope_end(fs);\n  lj_assertFS(fs->bl == NULL, \"bad scope nesting\");\n  /* May need to fixup returns encoded before first function was created. */\n  if (fs->flags & PROTO_FIXUP_RETURN) {\n    BCPos pc;\n    for (pc = 1; pc < lastpc; pc++) {\n      BCIns ins = fs->bcbase[pc].ins;\n      BCPos offset;\n      switch (bc_op(ins)) {\n      case BC_CALLMT: case BC_CALLT:\n      case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:\n\toffset = bcemit_INS(fs, ins);  /* Copy original instruction. */\n\tfs->bcbase[offset].line = fs->bcbase[pc].line;\n\toffset = offset-(pc+1)+BCBIAS_J;\n\tif (offset > BCMAX_D)\n\t  err_syntax(fs->ls, LJ_ERR_XFIXUP);\n\t/* Replace with UCLO plus branch. */\n\tfs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset);\n\tbreak;\n      case BC_UCLO:\n\treturn;  /* We're done. */\n      default:\n\tbreak;\n      }\n    }\n  }\n}\n\n/* Finish a FuncState and return the new prototype. */\nstatic GCproto *fs_finish(LexState *ls, BCLine line)\n{\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  BCLine numline = line - fs->linedefined;\n  size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar;\n  GCproto *pt;\n\n  /* Apply final fixups. */\n  fs_fixup_ret(fs);\n\n  /* Calculate total size of prototype including all colocated arrays. */\n  sizept = sizeof(GCproto) + fs->pc*sizeof(BCIns) + fs->nkgc*sizeof(GCRef);\n  sizept = (sizept + sizeof(TValue)-1) & ~(sizeof(TValue)-1);\n  ofsk = sizept; sizept += fs->nkn*sizeof(TValue);\n  ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2;\n  ofsli = sizept; sizept += fs_prep_line(fs, numline);\n  ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar);\n\n  /* Allocate prototype and initialize its fields. */\n  pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept);\n  pt->gct = ~LJ_TPROTO;\n  pt->sizept = (MSize)sizept;\n  pt->trace = 0;\n  pt->flags = (uint8_t)(fs->flags & ~(PROTO_HAS_RETURN|PROTO_FIXUP_RETURN));\n  pt->numparams = fs->numparams;\n  pt->framesize = fs->framesize;\n  setgcref(pt->chunkname, obj2gco(ls->chunkname));\n\n  /* Close potentially uninitialized gap between bc and kgc. */\n  *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(fs->nkgc+1)) = 0;\n  fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), fs->pc);\n  fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk));\n  fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv));\n  fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline);\n  fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar);\n\n  lj_vmevent_send(L, BC,\n    setprotoV(L, L->top++, pt);\n  );\n\n  L->top--;  /* Pop table of constants. */\n  ls->vtop = fs->vbase;  /* Reset variable stack. */\n  ls->fs = fs->prev;\n  lj_assertL(ls->fs != NULL || ls->tok == TK_eof, \"bad parser state\");\n  return pt;\n}\n\n/* Initialize a new FuncState. */\nstatic void fs_init(LexState *ls, FuncState *fs)\n{\n  lua_State *L = ls->L;\n  fs->prev = ls->fs; ls->fs = fs;  /* Append to list. */\n  fs->ls = ls;\n  fs->vbase = ls->vtop;\n  fs->L = L;\n  fs->pc = 0;\n  fs->lasttarget = 0;\n  fs->jpc = NO_JMP;\n  fs->freereg = 0;\n  fs->nkgc = 0;\n  fs->nkn = 0;\n  fs->nactvar = 0;\n  fs->nuv = 0;\n  fs->bl = NULL;\n  fs->flags = 0;\n  fs->framesize = 1;  /* Minimum frame size. */\n  fs->kt = lj_tab_new(L, 0, 0);\n  /* Anchor table of constants in stack to avoid being collected. */\n  settabV(L, L->top, fs->kt);\n  incr_top(L);\n}\n\n/* -- Expressions --------------------------------------------------------- */\n\n/* Forward declaration. */\nstatic void expr(LexState *ls, ExpDesc *v);\n\n/* Return string expression. */\nstatic void expr_str(LexState *ls, ExpDesc *e)\n{\n  expr_init(e, VKSTR, 0);\n  e->u.sval = lex_str(ls);\n}\n\n/* Return index expression. */\nstatic void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e)\n{\n  /* Already called: expr_toval(fs, e). */\n  t->k = VINDEXED;\n  if (expr_isnumk(e)) {\n#if LJ_DUALNUM\n    if (tvisint(expr_numtv(e))) {\n      int32_t k = intV(expr_numtv(e));\n      if (checku8(k)) {\n\tt->u.s.aux = BCMAX_C+1+(uint32_t)k;  /* 256..511: const byte key */\n\treturn;\n      }\n    }\n#else\n    lua_Number n = expr_numberV(e);\n    int32_t k = lj_num2int(n);\n    if (checku8(k) && n == (lua_Number)k) {\n      t->u.s.aux = BCMAX_C+1+(uint32_t)k;  /* 256..511: const byte key */\n      return;\n    }\n#endif\n  } else if (expr_isstrk(e)) {\n    BCReg idx = const_str(fs, e);\n    if (idx <= BCMAX_C) {\n      t->u.s.aux = ~idx;  /* -256..-1: const string key */\n      return;\n    }\n  }\n  t->u.s.aux = expr_toanyreg(fs, e);  /* 0..255: register */\n}\n\n/* Parse index expression with named field. */\nstatic void expr_field(LexState *ls, ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc key;\n  expr_toanyreg(fs, v);\n  lj_lex_next(ls);  /* Skip dot or colon. */\n  expr_str(ls, &key);\n  expr_index(fs, v, &key);\n}\n\n/* Parse index expression with brackets. */\nstatic void expr_bracket(LexState *ls, ExpDesc *v)\n{\n  lj_lex_next(ls);  /* Skip '['. */\n  expr(ls, v);\n  expr_toval(ls->fs, v);\n  lex_check(ls, ']');\n}\n\n/* Get value of constant expression. */\nstatic void expr_kvalue(FuncState *fs, TValue *v, ExpDesc *e)\n{\n  UNUSED(fs);\n  if (e->k <= VKTRUE) {\n    setpriV(v, ~(uint32_t)e->k);\n  } else if (e->k == VKSTR) {\n    setgcVraw(v, obj2gco(e->u.sval), LJ_TSTR);\n  } else {\n    lj_assertFS(tvisnumber(expr_numtv(e)), \"bad number constant\");\n    *v = *expr_numtv(e);\n  }\n}\n\n/* Parse table constructor expression. */\nstatic void expr_table(LexState *ls, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  BCLine line = ls->linenumber;\n  GCtab *t = NULL;\n  int vcall = 0, needarr = 0, fixt = 0;\n  uint32_t narr = 1;  /* First array index. */\n  uint32_t nhash = 0;  /* Number of hash entries. */\n  BCReg freg = fs->freereg;\n  BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0);\n  expr_init(e, VNONRELOC, freg);\n  bcreg_reserve(fs, 1);\n  freg++;\n  lex_check(ls, '{');\n  while (ls->tok != '}') {\n    ExpDesc key, val;\n    vcall = 0;\n    if (ls->tok == '[') {\n      expr_bracket(ls, &key);  /* Already calls expr_toval. */\n      if (!expr_isk(&key)) expr_index(fs, e, &key);\n      if (expr_isnumk(&key) && expr_numiszero(&key)) needarr = 1; else nhash++;\n      lex_check(ls, '=');\n    } else if ((ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) &&\n\t       lj_lex_lookahead(ls) == '=') {\n      expr_str(ls, &key);\n      lex_check(ls, '=');\n      nhash++;\n    } else {\n      expr_init(&key, VKNUM, 0);\n      setintV(&key.u.nval, (int)narr);\n      narr++;\n      needarr = vcall = 1;\n    }\n    expr(ls, &val);\n    if (expr_isk(&key) && key.k != VKNIL &&\n\t(key.k == VKSTR || expr_isk_nojump(&val))) {\n      TValue k, *v;\n      if (!t) {  /* Create template table on demand. */\n\tBCReg kidx;\n\tt = lj_tab_new(fs->L, needarr ? narr : 0, hsize2hbits(nhash));\n\tkidx = const_gc(fs, obj2gco(t), LJ_TTAB);\n\tfs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx);\n      }\n      vcall = 0;\n      expr_kvalue(fs, &k, &key);\n      v = lj_tab_set(fs->L, t, &k);\n      lj_gc_anybarriert(fs->L, t);\n      if (expr_isk_nojump(&val)) {  /* Add const key/value to template table. */\n\texpr_kvalue(fs, v, &val);\n      } else {  /* Otherwise create dummy string key (avoids lj_tab_newkey). */\n\tsettabV(fs->L, v, t);  /* Preserve key with table itself as value. */\n\tfixt = 1;   /* Fix this later, after all resizes. */\n\tgoto nonconst;\n      }\n    } else {\n    nonconst:\n      if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; }\n      if (expr_isk(&key)) expr_index(fs, e, &key);\n      bcemit_store(fs, e, &val);\n    }\n    fs->freereg = freg;\n    if (!lex_opt(ls, ',') && !lex_opt(ls, ';')) break;\n  }\n  lex_match(ls, '}', '{', line);\n  if (vcall) {\n    BCInsLine *ilp = &fs->bcbase[fs->pc-1];\n    ExpDesc en;\n    lj_assertFS(bc_a(ilp->ins) == freg &&\n\t\tbc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB),\n\t\t\"bad CALL code generation\");\n    expr_init(&en, VKNUM, 0);\n    en.u.nval.u32.lo = narr-1;\n    en.u.nval.u32.hi = 0x43300000;  /* Biased integer to avoid denormals. */\n    if (narr > 256) { fs->pc--; ilp--; }\n    ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en));\n    setbc_b(&ilp[-1].ins, 0);\n  }\n  if (pc == fs->pc-1) {  /* Make expr relocable if possible. */\n    e->u.s.info = pc;\n    fs->freereg--;\n    e->k = VRELOCABLE;\n  } else {\n    e->k = VNONRELOC;  /* May have been changed by expr_index. */\n  }\n  if (!t) {  /* Construct TNEW RD: hhhhhaaaaaaaaaaa. */\n    BCIns *ip = &fs->bcbase[pc].ins;\n    if (!needarr) narr = 0;\n    else if (narr < 3) narr = 3;\n    else if (narr > 0x7ff) narr = 0x7ff;\n    setbc_d(ip, narr|(hsize2hbits(nhash)<<11));\n  } else {\n    if (needarr && t->asize < narr)\n      lj_tab_reasize(fs->L, t, narr-1);\n    if (fixt) {  /* Fix value for dummy keys in template table. */\n      Node *node = noderef(t->node);\n      uint32_t i, hmask = t->hmask;\n      for (i = 0; i <= hmask; i++) {\n\tNode *n = &node[i];\n\tif (tvistab(&n->val)) {\n\t  lj_assertFS(tabV(&n->val) == t, \"bad dummy key in template table\");\n\t  setnilV(&n->val);  /* Turn value into nil. */\n\t}\n      }\n    }\n    lj_gc_check(fs->L);\n  }\n}\n\n/* Parse function parameters. */\nstatic BCReg parse_params(LexState *ls, int needself)\n{\n  FuncState *fs = ls->fs;\n  BCReg nparams = 0;\n  lex_check(ls, '(');\n  if (needself)\n    var_new_lit(ls, nparams++, \"self\");\n  if (ls->tok != ')') {\n    do {\n      if (ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) {\n\tvar_new(ls, nparams++, lex_str(ls));\n      } else if (ls->tok == TK_dots) {\n\tlj_lex_next(ls);\n\tfs->flags |= PROTO_VARARG;\n\tbreak;\n      } else {\n\terr_syntax(ls, LJ_ERR_XPARAM);\n      }\n    } while (lex_opt(ls, ','));\n  }\n  var_add(ls, nparams);\n  lj_assertFS(fs->nactvar == nparams, \"bad regalloc\");\n  bcreg_reserve(fs, nparams);\n  lex_check(ls, ')');\n  return nparams;\n}\n\n/* Forward declaration. */\nstatic void parse_chunk(LexState *ls);\n\n/* Parse body of a function. */\nstatic void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line)\n{\n  FuncState fs, *pfs = ls->fs;\n  FuncScope bl;\n  GCproto *pt;\n  ptrdiff_t oldbase = pfs->bcbase - ls->bcstack;\n  fs_init(ls, &fs);\n  fscope_begin(&fs, &bl, 0);\n  fs.linedefined = line;\n  fs.numparams = (uint8_t)parse_params(ls, needself);\n  fs.bcbase = pfs->bcbase + pfs->pc;\n  fs.bclim = pfs->bclim - pfs->pc;\n  bcemit_AD(&fs, BC_FUNCF, 0, 0);  /* Placeholder. */\n  parse_chunk(ls);\n  if (ls->tok != TK_end) lex_match(ls, TK_end, TK_function, line);\n  pt = fs_finish(ls, (ls->lastline = ls->linenumber));\n  pfs->bcbase = ls->bcstack + oldbase;  /* May have been reallocated. */\n  pfs->bclim = (BCPos)(ls->sizebcstack - oldbase);\n  /* Store new prototype in the constant array of the parent. */\n  expr_init(e, VRELOCABLE,\n\t    bcemit_AD(pfs, BC_FNEW, 0, const_gc(pfs, obj2gco(pt), LJ_TPROTO)));\n#if LJ_HASFFI\n  pfs->flags |= (fs.flags & PROTO_FFI);\n#endif\n  if (!(pfs->flags & PROTO_CHILD)) {\n    if (pfs->flags & PROTO_HAS_RETURN)\n      pfs->flags |= PROTO_FIXUP_RETURN;\n    pfs->flags |= PROTO_CHILD;\n  }\n  lj_lex_next(ls);\n}\n\n/* Parse expression list. Last expression is left open. */\nstatic BCReg expr_list(LexState *ls, ExpDesc *v)\n{\n  BCReg n = 1;\n  expr(ls, v);\n  while (lex_opt(ls, ',')) {\n    expr_tonextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n/* Parse function argument list. */\nstatic void parse_args(LexState *ls, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc args;\n  BCIns ins;\n  BCReg base;\n  BCLine line = ls->linenumber;\n  if (ls->tok == '(') {\n#if !LJ_52\n    if (line != ls->lastline)\n      err_syntax(ls, LJ_ERR_XAMBIG);\n#endif\n    lj_lex_next(ls);\n    if (ls->tok == ')') {  /* f(). */\n      args.k = VVOID;\n    } else {\n      expr_list(ls, &args);\n      if (args.k == VCALL)  /* f(a, b, g()) or f(a, b, ...). */\n\tsetbc_b(bcptr(fs, &args), 0);  /* Pass on multiple results. */\n    }\n    lex_match(ls, ')', '(', line);\n  } else if (ls->tok == '{') {\n    expr_table(ls, &args);\n  } else if (ls->tok == TK_string) {\n    expr_init(&args, VKSTR, 0);\n    args.u.sval = strV(&ls->tokval);\n    lj_lex_next(ls);\n  } else {\n    err_syntax(ls, LJ_ERR_XFUNARG);\n    return;  /* Silence compiler. */\n  }\n  lj_assertFS(e->k == VNONRELOC, \"bad expr type %d\", e->k);\n  base = e->u.s.info;  /* Base register for call. */\n  if (args.k == VCALL) {\n    ins = BCINS_ABC(BC_CALLM, base, 2, args.u.s.aux - base - 1 - LJ_FR2);\n  } else {\n    if (args.k != VVOID)\n      expr_tonextreg(fs, &args);\n    ins = BCINS_ABC(BC_CALL, base, 2, fs->freereg - base - LJ_FR2);\n  }\n  expr_init(e, VCALL, bcemit_INS(fs, ins));\n  e->u.s.aux = base;\n  fs->bcbase[fs->pc - 1].line = line;\n  fs->freereg = base+1;  /* Leave one result by default. */\n}\n\n/* Parse primary expression. */\nstatic void expr_primary(LexState *ls, ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  /* Parse prefix expression. */\n  if (ls->tok == '(') {\n    BCLine line = ls->linenumber;\n    lj_lex_next(ls);\n    expr(ls, v);\n    lex_match(ls, ')', '(', line);\n    expr_discharge(ls->fs, v);\n  } else if (ls->tok == TK_name || (!LJ_52 && ls->tok == TK_goto)) {\n    var_lookup(ls, v);\n  } else {\n    err_syntax(ls, LJ_ERR_XSYMBOL);\n  }\n  for (;;) {  /* Parse multiple expression suffixes. */\n    if (ls->tok == '.') {\n      expr_field(ls, v);\n    } else if (ls->tok == '[') {\n      ExpDesc key;\n      expr_toanyreg(fs, v);\n      expr_bracket(ls, &key);\n      expr_index(fs, v, &key);\n    } else if (ls->tok == ':') {\n      ExpDesc key;\n      lj_lex_next(ls);\n      expr_str(ls, &key);\n      bcemit_method(fs, v, &key);\n      parse_args(ls, v);\n    } else if (ls->tok == '(' || ls->tok == TK_string || ls->tok == '{') {\n      expr_tonextreg(fs, v);\n      if (LJ_FR2) bcreg_reserve(fs, 1);\n      parse_args(ls, v);\n    } else {\n      break;\n    }\n  }\n}\n\n/* Parse simple expression. */\nstatic void expr_simple(LexState *ls, ExpDesc *v)\n{\n  switch (ls->tok) {\n  case TK_number:\n    expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokval)) ? VKCDATA : VKNUM, 0);\n    copyTV(ls->L, &v->u.nval, &ls->tokval);\n    break;\n  case TK_string:\n    expr_init(v, VKSTR, 0);\n    v->u.sval = strV(&ls->tokval);\n    break;\n  case TK_nil:\n    expr_init(v, VKNIL, 0);\n    break;\n  case TK_true:\n    expr_init(v, VKTRUE, 0);\n    break;\n  case TK_false:\n    expr_init(v, VKFALSE, 0);\n    break;\n  case TK_dots: {  /* Vararg. */\n    FuncState *fs = ls->fs;\n    BCReg base;\n    checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS);\n    bcreg_reserve(fs, 1);\n    base = fs->freereg-1;\n    expr_init(v, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams));\n    v->u.s.aux = base;\n    break;\n  }\n  case '{':  /* Table constructor. */\n    expr_table(ls, v);\n    return;\n  case TK_function:\n    lj_lex_next(ls);\n    parse_body(ls, v, 0, ls->linenumber);\n    return;\n  default:\n    expr_primary(ls, v);\n    return;\n  }\n  lj_lex_next(ls);\n}\n\n/* Manage syntactic levels to avoid blowing up the stack. */\nstatic void synlevel_begin(LexState *ls)\n{\n  if (++ls->level >= LJ_MAX_XLEVEL)\n    lj_lex_error(ls, 0, LJ_ERR_XLEVELS);\n}\n\n#define synlevel_end(ls)\t((ls)->level--)\n\n/* Convert token to binary operator. */\nstatic BinOpr token2binop(LexToken tok)\n{\n  switch (tok) {\n  case '+':\treturn OPR_ADD;\n  case '-':\treturn OPR_SUB;\n  case '*':\treturn OPR_MUL;\n  case '/':\treturn OPR_DIV;\n  case '%':\treturn OPR_MOD;\n  case '^':\treturn OPR_POW;\n  case TK_concat: return OPR_CONCAT;\n  case TK_ne:\treturn OPR_NE;\n  case TK_eq:\treturn OPR_EQ;\n  case '<':\treturn OPR_LT;\n  case TK_le:\treturn OPR_LE;\n  case '>':\treturn OPR_GT;\n  case TK_ge:\treturn OPR_GE;\n  case TK_and:\treturn OPR_AND;\n  case TK_or:\treturn OPR_OR;\n  default:\treturn OPR_NOBINOPR;\n  }\n}\n\n/* Priorities for each binary operator. ORDER OPR. */\nstatic const struct {\n  uint8_t left;\t\t/* Left priority. */\n  uint8_t right;\t/* Right priority. */\n} priority[] = {\n  {6,6}, {6,6}, {7,7}, {7,7}, {7,7},\t/* ADD SUB MUL DIV MOD */\n  {10,9}, {5,4},\t\t\t/* POW CONCAT (right associative) */\n  {3,3}, {3,3},\t\t\t\t/* EQ NE */\n  {3,3}, {3,3}, {3,3}, {3,3},\t\t/* LT GE GT LE */\n  {2,2}, {1,1}\t\t\t\t/* AND OR */\n};\n\n#define UNARY_PRIORITY\t\t8  /* Priority for unary operators. */\n\n/* Forward declaration. */\nstatic BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit);\n\n/* Parse unary expression. */\nstatic void expr_unop(LexState *ls, ExpDesc *v)\n{\n  BCOp op;\n  if (ls->tok == TK_not) {\n    op = BC_NOT;\n  } else if (ls->tok == '-') {\n    op = BC_UNM;\n  } else if (ls->tok == '#') {\n    op = BC_LEN;\n  } else {\n    expr_simple(ls, v);\n    return;\n  }\n  lj_lex_next(ls);\n  expr_binop(ls, v, UNARY_PRIORITY);\n  bcemit_unop(ls->fs, op, v);\n}\n\n/* Parse binary expressions with priority higher than the limit. */\nstatic BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit)\n{\n  BinOpr op;\n  synlevel_begin(ls);\n  expr_unop(ls, v);\n  op = token2binop(ls->tok);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    ExpDesc v2;\n    BinOpr nextop;\n    lj_lex_next(ls);\n    bcemit_binop_left(ls->fs, op, v);\n    /* Parse binary expression with higher priority. */\n    nextop = expr_binop(ls, &v2, priority[op].right);\n    bcemit_binop(ls->fs, op, v, &v2);\n    op = nextop;\n  }\n  synlevel_end(ls);\n  return op;  /* Return unconsumed binary operator (if any). */\n}\n\n/* Parse expression. */\nstatic void expr(LexState *ls, ExpDesc *v)\n{\n  expr_binop(ls, v, 0);  /* Priority 0: parse whole expression. */\n}\n\n/* Assign expression to the next register. */\nstatic void expr_next(LexState *ls)\n{\n  ExpDesc e;\n  expr(ls, &e);\n  expr_tonextreg(ls->fs, &e);\n}\n\n/* Parse conditional expression. */\nstatic BCPos expr_cond(LexState *ls)\n{\n  ExpDesc v;\n  expr(ls, &v);\n  if (v.k == VKNIL) v.k = VKFALSE;\n  bcemit_branch_t(ls->fs, &v);\n  return v.f;\n}\n\n/* -- Assignments --------------------------------------------------------- */\n\n/* List of LHS variables. */\ntypedef struct LHSVarList {\n  ExpDesc v;\t\t\t/* LHS variable. */\n  struct LHSVarList *prev;\t/* Link to previous LHS variable. */\n} LHSVarList;\n\n/* Eliminate write-after-read hazards for local variable assignment. */\nstatic void assign_hazard(LexState *ls, LHSVarList *lh, const ExpDesc *v)\n{\n  FuncState *fs = ls->fs;\n  BCReg reg = v->u.s.info;  /* Check against this variable. */\n  BCReg tmp = fs->freereg;  /* Rename to this temp. register (if needed). */\n  int hazard = 0;\n  for (; lh; lh = lh->prev) {\n    if (lh->v.k == VINDEXED) {\n      if (lh->v.u.s.info == reg) {  /* t[i], t = 1, 2 */\n\thazard = 1;\n\tlh->v.u.s.info = tmp;\n      }\n      if (lh->v.u.s.aux == reg) {  /* t[i], i = 1, 2 */\n\thazard = 1;\n\tlh->v.u.s.aux = tmp;\n      }\n    }\n  }\n  if (hazard) {\n    bcemit_AD(fs, BC_MOV, tmp, reg);  /* Rename conflicting variable. */\n    bcreg_reserve(fs, 1);\n  }\n}\n\n/* Adjust LHS/RHS of an assignment. */\nstatic void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e)\n{\n  FuncState *fs = ls->fs;\n  int32_t extra = (int32_t)nvars - (int32_t)nexps;\n  if (e->k == VCALL) {\n    extra++;  /* Compensate for the VCALL itself. */\n    if (extra < 0) extra = 0;\n    setbc_b(bcptr(fs, e), extra+1);  /* Fixup call results. */\n    if (extra > 1) bcreg_reserve(fs, (BCReg)extra-1);\n  } else {\n    if (e->k != VVOID)\n      expr_tonextreg(fs, e);  /* Close last expression. */\n    if (extra > 0) {  /* Leftover LHS are set to nil. */\n      BCReg reg = fs->freereg;\n      bcreg_reserve(fs, (BCReg)extra);\n      bcemit_nil(fs, reg, (BCReg)extra);\n    }\n  }\n  if (nexps > nvars)\n    ls->fs->freereg -= nexps - nvars;  /* Drop leftover regs. */\n}\n\n/* Recursively parse assignment statement. */\nstatic void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars)\n{\n  ExpDesc e;\n  checkcond(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, LJ_ERR_XSYNTAX);\n  if (lex_opt(ls, ',')) {  /* Collect LHS list and recurse upwards. */\n    LHSVarList vl;\n    vl.prev = lh;\n    expr_primary(ls, &vl.v);\n    if (vl.v.k == VLOCAL)\n      assign_hazard(ls, lh, &vl.v);\n    checklimit(ls->fs, ls->level + nvars, LJ_MAX_XLEVEL, \"variable names\");\n    parse_assignment(ls, &vl, nvars+1);\n  } else {  /* Parse RHS. */\n    BCReg nexps;\n    lex_check(ls, '=');\n    nexps = expr_list(ls, &e);\n    if (nexps == nvars) {\n      if (e.k == VCALL) {\n\tif (bc_op(*bcptr(ls->fs, &e)) == BC_VARG) {  /* Vararg assignment. */\n\t  ls->fs->freereg--;\n\t  e.k = VRELOCABLE;\n\t} else {  /* Multiple call results. */\n\t  e.u.s.info = e.u.s.aux;  /* Base of call is not relocatable. */\n\t  e.k = VNONRELOC;\n\t}\n      }\n      bcemit_store(ls->fs, &lh->v, &e);\n      return;\n    }\n    assign_adjust(ls, nvars, nexps, &e);\n  }\n  /* Assign RHS to LHS and recurse downwards. */\n  expr_init(&e, VNONRELOC, ls->fs->freereg-1);\n  bcemit_store(ls->fs, &lh->v, &e);\n}\n\n/* Parse call statement or assignment. */\nstatic void parse_call_assign(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  LHSVarList vl;\n  expr_primary(ls, &vl.v);\n  if (vl.v.k == VCALL) {  /* Function call statement. */\n    setbc_b(bcptr(fs, &vl.v), 1);  /* No results. */\n  } else {  /* Start of an assignment. */\n    vl.prev = NULL;\n    parse_assignment(ls, &vl, 1);\n  }\n}\n\n/* Parse 'local' statement. */\nstatic void parse_local(LexState *ls)\n{\n  if (lex_opt(ls, TK_function)) {  /* Local function declaration. */\n    ExpDesc v, b;\n    FuncState *fs = ls->fs;\n    var_new(ls, 0, lex_str(ls));\n    expr_init(&v, VLOCAL, fs->freereg);\n    v.u.s.aux = fs->varmap[fs->freereg];\n    bcreg_reserve(fs, 1);\n    var_add(ls, 1);\n    parse_body(ls, &b, 0, ls->linenumber);\n    /* bcemit_store(fs, &v, &b) without setting VSTACK_VAR_RW. */\n    expr_free(fs, &b);\n    expr_toreg(fs, &b, v.u.s.info);\n    /* The upvalue is in scope, but the local is only valid after the store. */\n    var_get(ls, fs, fs->nactvar - 1).startpc = fs->pc;\n  } else {  /* Local variable declaration. */\n    ExpDesc e;\n    BCReg nexps, nvars = 0;\n    do {  /* Collect LHS. */\n      var_new(ls, nvars++, lex_str(ls));\n    } while (lex_opt(ls, ','));\n    if (lex_opt(ls, '=')) {  /* Optional RHS. */\n      nexps = expr_list(ls, &e);\n    } else {  /* Or implicitly set to nil. */\n      e.k = VVOID;\n      nexps = 0;\n    }\n    assign_adjust(ls, nvars, nexps, &e);\n    var_add(ls, nvars);\n  }\n}\n\n/* Parse 'function' statement. */\nstatic void parse_func(LexState *ls, BCLine line)\n{\n  FuncState *fs;\n  ExpDesc v, b;\n  int needself = 0;\n  lj_lex_next(ls);  /* Skip 'function'. */\n  /* Parse function name. */\n  var_lookup(ls, &v);\n  while (ls->tok == '.')  /* Multiple dot-separated fields. */\n    expr_field(ls, &v);\n  if (ls->tok == ':') {  /* Optional colon to signify method call. */\n    needself = 1;\n    expr_field(ls, &v);\n  }\n  parse_body(ls, &b, needself, line);\n  fs = ls->fs;\n  bcemit_store(fs, &v, &b);\n  fs->bcbase[fs->pc - 1].line = line;  /* Set line for the store. */\n}\n\n/* -- Control transfer statements ----------------------------------------- */\n\n/* Check for end of block. */\nstatic int parse_isend(LexToken tok)\n{\n  switch (tok) {\n  case TK_else: case TK_elseif: case TK_end: case TK_until: case TK_eof:\n    return 1;\n  default:\n    return 0;\n  }\n}\n\n/* Parse 'return' statement. */\nstatic void parse_return(LexState *ls)\n{\n  BCIns ins;\n  FuncState *fs = ls->fs;\n  lj_lex_next(ls);  /* Skip 'return'. */\n  fs->flags |= PROTO_HAS_RETURN;\n  if (parse_isend(ls->tok) || ls->tok == ';') {  /* Bare return. */\n    ins = BCINS_AD(BC_RET0, 0, 1);\n  } else {  /* Return with one or more values. */\n    ExpDesc e;  /* Receives the _last_ expression in the list. */\n    BCReg nret = expr_list(ls, &e);\n    if (nret == 1) {  /* Return one result. */\n      if (e.k == VCALL) {  /* Check for tail call. */\n\tBCIns *ip = bcptr(fs, &e);\n\t/* It doesn't pay off to add BC_VARGT just for 'return ...'. */\n\tif (bc_op(*ip) == BC_VARG) goto notailcall;\n\tfs->pc--;\n\tins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip));\n      } else {  /* Can return the result from any register. */\n\tins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2);\n      }\n    } else {\n      if (e.k == VCALL) {  /* Append all results from a call. */\n      notailcall:\n\tsetbc_b(bcptr(fs, &e), 0);\n\tins = BCINS_AD(BC_RETM, fs->nactvar, e.u.s.aux - fs->nactvar);\n      } else {\n\texpr_tonextreg(fs, &e);  /* Force contiguous registers. */\n\tins = BCINS_AD(BC_RET, fs->nactvar, nret+1);\n      }\n    }\n  }\n  if (fs->flags & PROTO_CHILD)\n    bcemit_AJ(fs, BC_UCLO, 0, 0);  /* May need to close upvalues first. */\n  bcemit_INS(fs, ins);\n}\n\n/* Parse 'break' statement. */\nstatic void parse_break(LexState *ls)\n{\n  ls->fs->bl->flags |= FSCOPE_BREAK;\n  gola_new(ls, NAME_BREAK, VSTACK_GOTO, bcemit_jmp(ls->fs));\n}\n\n/* Parse 'goto' statement. */\nstatic void parse_goto(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  GCstr *name = lex_str(ls);\n  VarInfo *vl = gola_findlabel(ls, name);\n  if (vl)  /* Treat backwards goto within same scope like a loop. */\n    bcemit_AJ(fs, BC_LOOP, vl->slot, -1);  /* No BC range check. */\n  fs->bl->flags |= FSCOPE_GOLA;\n  gola_new(ls, name, VSTACK_GOTO, bcemit_jmp(fs));\n}\n\n/* Parse label. */\nstatic void parse_label(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  GCstr *name;\n  MSize idx;\n  fs->lasttarget = fs->pc;\n  fs->bl->flags |= FSCOPE_GOLA;\n  lj_lex_next(ls);  /* Skip '::'. */\n  name = lex_str(ls);\n  if (gola_findlabel(ls, name))\n    lj_lex_error(ls, 0, LJ_ERR_XLDUP, strdata(name));\n  idx = gola_new(ls, name, VSTACK_LABEL, fs->pc);\n  lex_check(ls, TK_label);\n  /* Recursively parse trailing statements: labels and ';' (Lua 5.2 only). */\n  for (;;) {\n    if (ls->tok == TK_label) {\n      synlevel_begin(ls);\n      parse_label(ls);\n      synlevel_end(ls);\n    } else if (LJ_52 && ls->tok == ';') {\n      lj_lex_next(ls);\n    } else {\n      break;\n    }\n  }\n  /* Trailing label is considered to be outside of scope. */\n  if (parse_isend(ls->tok) && ls->tok != TK_until)\n    ls->vstack[idx].slot = fs->bl->nactvar;\n  gola_resolve(ls, fs->bl, idx);\n}\n\n/* -- Blocks, loops and conditional statements ---------------------------- */\n\n/* Parse a block. */\nstatic void parse_block(LexState *ls)\n{\n  FuncState *fs = ls->fs;\n  FuncScope bl;\n  fscope_begin(fs, &bl, 0);\n  parse_chunk(ls);\n  fscope_end(fs);\n}\n\n/* Parse 'while' statement. */\nstatic void parse_while(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos start, loop, condexit;\n  FuncScope bl;\n  lj_lex_next(ls);  /* Skip 'while'. */\n  start = fs->lasttarget = fs->pc;\n  condexit = expr_cond(ls);\n  fscope_begin(fs, &bl, FSCOPE_LOOP);\n  lex_check(ls, TK_do);\n  loop = bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);\n  parse_block(ls);\n  jmp_patch(fs, bcemit_jmp(fs), start);\n  lex_match(ls, TK_end, TK_while, line);\n  fscope_end(fs);\n  jmp_tohere(fs, condexit);\n  jmp_patchins(fs, loop, fs->pc);\n}\n\n/* Parse 'repeat' statement. */\nstatic void parse_repeat(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos loop = fs->lasttarget = fs->pc;\n  BCPos condexit;\n  FuncScope bl1, bl2;\n  fscope_begin(fs, &bl1, FSCOPE_LOOP);  /* Breakable loop scope. */\n  fscope_begin(fs, &bl2, 0);  /* Inner scope. */\n  lj_lex_next(ls);  /* Skip 'repeat'. */\n  bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);\n  parse_chunk(ls);\n  lex_match(ls, TK_until, TK_repeat, line);\n  condexit = expr_cond(ls);  /* Parse condition (still inside inner scope). */\n  if (!(bl2.flags & FSCOPE_UPVAL)) {  /* No upvalues? Just end inner scope. */\n    fscope_end(fs);\n  } else {  /* Otherwise generate: cond: UCLO+JMP out, !cond: UCLO+JMP loop. */\n    parse_break(ls);  /* Break from loop and close upvalues. */\n    jmp_tohere(fs, condexit);\n    fscope_end(fs);  /* End inner scope and close upvalues. */\n    condexit = bcemit_jmp(fs);\n  }\n  jmp_patch(fs, condexit, loop);  /* Jump backwards if !cond. */\n  jmp_patchins(fs, loop, fs->pc);\n  fscope_end(fs);  /* End loop scope. */\n}\n\n/* Parse numeric 'for'. */\nstatic void parse_for_num(LexState *ls, GCstr *varname, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCReg base = fs->freereg;\n  FuncScope bl;\n  BCPos loop, loopend;\n  /* Hidden control variables. */\n  var_new_fixed(ls, FORL_IDX, VARNAME_FOR_IDX);\n  var_new_fixed(ls, FORL_STOP, VARNAME_FOR_STOP);\n  var_new_fixed(ls, FORL_STEP, VARNAME_FOR_STEP);\n  /* Visible copy of index variable. */\n  var_new(ls, FORL_EXT, varname);\n  lex_check(ls, '=');\n  expr_next(ls);\n  lex_check(ls, ',');\n  expr_next(ls);\n  if (lex_opt(ls, ',')) {\n    expr_next(ls);\n  } else {\n    bcemit_AD(fs, BC_KSHORT, fs->freereg, 1);  /* Default step is 1. */\n    bcreg_reserve(fs, 1);\n  }\n  var_add(ls, 3);  /* Hidden control variables. */\n  lex_check(ls, TK_do);\n  loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP);\n  fscope_begin(fs, &bl, 0);  /* Scope for visible variables. */\n  var_add(ls, 1);\n  bcreg_reserve(fs, 1);\n  parse_block(ls);\n  fscope_end(fs);\n  /* Perform loop inversion. Loop control instructions are at the end. */\n  loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP);\n  fs->bcbase[loopend].line = line;  /* Fix line for control ins. */\n  jmp_patchins(fs, loopend, loop+1);\n  jmp_patchins(fs, loop, fs->pc);\n}\n\n/* Try to predict whether the iterator is next() and specialize the bytecode.\n** Detecting next() and pairs() by name is simplistic, but quite effective.\n** The interpreter backs off if the check for the closure fails at runtime.\n*/\nstatic int predict_next(LexState *ls, FuncState *fs, BCPos pc)\n{\n  BCIns ins = fs->bcbase[pc].ins;\n  GCstr *name;\n  cTValue *o;\n  switch (bc_op(ins)) {\n  case BC_MOV:\n    name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name));\n    break;\n  case BC_UGET:\n    name = gco2str(gcref(ls->vstack[fs->uvmap[bc_d(ins)]].name));\n    break;\n  case BC_GGET:\n    /* There's no inverse index (yet), so lookup the strings. */\n    o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, \"pairs\"));\n    if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))\n      return 1;\n    o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, \"next\"));\n    if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))\n      return 1;\n    return 0;\n  default:\n    return 0;\n  }\n  return (name->len == 5 && !strcmp(strdata(name), \"pairs\")) ||\n\t (name->len == 4 && !strcmp(strdata(name), \"next\"));\n}\n\n/* Parse 'for' iterator. */\nstatic void parse_for_iter(LexState *ls, GCstr *indexname)\n{\n  FuncState *fs = ls->fs;\n  ExpDesc e;\n  BCReg nvars = 0;\n  BCLine line;\n  BCReg base = fs->freereg + 3;\n  BCPos loop, loopend, exprpc = fs->pc;\n  FuncScope bl;\n  int isnext;\n  /* Hidden control variables. */\n  var_new_fixed(ls, nvars++, VARNAME_FOR_GEN);\n  var_new_fixed(ls, nvars++, VARNAME_FOR_STATE);\n  var_new_fixed(ls, nvars++, VARNAME_FOR_CTL);\n  /* Visible variables returned from iterator. */\n  var_new(ls, nvars++, indexname);\n  while (lex_opt(ls, ','))\n    var_new(ls, nvars++, lex_str(ls));\n  lex_check(ls, TK_in);\n  line = ls->linenumber;\n  assign_adjust(ls, 3, expr_list(ls, &e), &e);\n  /* The iterator needs another 3 [4] slots (func [pc] | state ctl). */\n  bcreg_bump(fs, 3+LJ_FR2);\n  isnext = (nvars <= 5 && predict_next(ls, fs, exprpc));\n  var_add(ls, 3);  /* Hidden control variables. */\n  lex_check(ls, TK_do);\n  loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP);\n  fscope_begin(fs, &bl, 0);  /* Scope for visible variables. */\n  var_add(ls, nvars-3);\n  bcreg_reserve(fs, nvars-3);\n  parse_block(ls);\n  fscope_end(fs);\n  /* Perform loop inversion. Loop control instructions are at the end. */\n  jmp_patchins(fs, loop, fs->pc);\n  bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1);\n  loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP);\n  fs->bcbase[loopend-1].line = line;  /* Fix line for control ins. */\n  fs->bcbase[loopend].line = line;\n  jmp_patchins(fs, loopend, loop+1);\n}\n\n/* Parse 'for' statement. */\nstatic void parse_for(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  GCstr *varname;\n  FuncScope bl;\n  fscope_begin(fs, &bl, FSCOPE_LOOP);\n  lj_lex_next(ls);  /* Skip 'for'. */\n  varname = lex_str(ls);  /* Get first variable name. */\n  if (ls->tok == '=')\n    parse_for_num(ls, varname, line);\n  else if (ls->tok == ',' || ls->tok == TK_in)\n    parse_for_iter(ls, varname);\n  else\n    err_syntax(ls, LJ_ERR_XFOR);\n  lex_match(ls, TK_end, TK_for, line);\n  fscope_end(fs);  /* Resolve break list. */\n}\n\n/* Parse condition and 'then' block. */\nstatic BCPos parse_then(LexState *ls)\n{\n  BCPos condexit;\n  lj_lex_next(ls);  /* Skip 'if' or 'elseif'. */\n  condexit = expr_cond(ls);\n  lex_check(ls, TK_then);\n  parse_block(ls);\n  return condexit;\n}\n\n/* Parse 'if' statement. */\nstatic void parse_if(LexState *ls, BCLine line)\n{\n  FuncState *fs = ls->fs;\n  BCPos flist;\n  BCPos escapelist = NO_JMP;\n  flist = parse_then(ls);\n  while (ls->tok == TK_elseif) {  /* Parse multiple 'elseif' blocks. */\n    jmp_append(fs, &escapelist, bcemit_jmp(fs));\n    jmp_tohere(fs, flist);\n    flist = parse_then(ls);\n  }\n  if (ls->tok == TK_else) {  /* Parse optional 'else' block. */\n    jmp_append(fs, &escapelist, bcemit_jmp(fs));\n    jmp_tohere(fs, flist);\n    lj_lex_next(ls);  /* Skip 'else'. */\n    parse_block(ls);\n  } else {\n    jmp_append(fs, &escapelist, flist);\n  }\n  jmp_tohere(fs, escapelist);\n  lex_match(ls, TK_end, TK_if, line);\n}\n\n/* -- Parse statements ---------------------------------------------------- */\n\n/* Parse a statement. Returns 1 if it must be the last one in a chunk. */\nstatic int parse_stmt(LexState *ls)\n{\n  BCLine line = ls->linenumber;\n  switch (ls->tok) {\n  case TK_if:\n    parse_if(ls, line);\n    break;\n  case TK_while:\n    parse_while(ls, line);\n    break;\n  case TK_do:\n    lj_lex_next(ls);\n    parse_block(ls);\n    lex_match(ls, TK_end, TK_do, line);\n    break;\n  case TK_for:\n    parse_for(ls, line);\n    break;\n  case TK_repeat:\n    parse_repeat(ls, line);\n    break;\n  case TK_function:\n    parse_func(ls, line);\n    break;\n  case TK_local:\n    lj_lex_next(ls);\n    parse_local(ls);\n    break;\n  case TK_return:\n    parse_return(ls);\n    return 1;  /* Must be last. */\n  case TK_break:\n    lj_lex_next(ls);\n    parse_break(ls);\n    return !LJ_52;  /* Must be last in Lua 5.1. */\n#if LJ_52\n  case ';':\n    lj_lex_next(ls);\n    break;\n#endif\n  case TK_label:\n    parse_label(ls);\n    break;\n  case TK_goto:\n    if (LJ_52 || lj_lex_lookahead(ls) == TK_name) {\n      lj_lex_next(ls);\n      parse_goto(ls);\n      break;\n    }\n    /* fallthrough */\n  default:\n    parse_call_assign(ls);\n    break;\n  }\n  return 0;\n}\n\n/* A chunk is a list of statements optionally separated by semicolons. */\nstatic void parse_chunk(LexState *ls)\n{\n  int islast = 0;\n  synlevel_begin(ls);\n  while (!islast && !parse_isend(ls->tok)) {\n    islast = parse_stmt(ls);\n    lex_opt(ls, ';');\n    lj_assertLS(ls->fs->framesize >= ls->fs->freereg &&\n\t\tls->fs->freereg >= ls->fs->nactvar,\n\t\t\"bad regalloc\");\n    ls->fs->freereg = ls->fs->nactvar;  /* Free registers after each stmt. */\n  }\n  synlevel_end(ls);\n}\n\n/* Entry point of bytecode parser. */\nGCproto *lj_parse(LexState *ls)\n{\n  FuncState fs;\n  FuncScope bl;\n  GCproto *pt;\n  lua_State *L = ls->L;\n#ifdef LUAJIT_DISABLE_DEBUGINFO\n  ls->chunkname = lj_str_newlit(L, \"=\");\n#else\n  ls->chunkname = lj_str_newz(L, ls->chunkarg);\n#endif\n  setstrV(L, L->top, ls->chunkname);  /* Anchor chunkname string. */\n  incr_top(L);\n  ls->level = 0;\n  fs_init(ls, &fs);\n  fs.linedefined = 0;\n  fs.numparams = 0;\n  fs.bcbase = NULL;\n  fs.bclim = 0;\n  fs.flags |= PROTO_VARARG;  /* Main chunk is always a vararg func. */\n  fscope_begin(&fs, &bl, 0);\n  bcemit_AD(&fs, BC_FUNCV, 0, 0);  /* Placeholder. */\n  lj_lex_next(ls);  /* Read-ahead first token. */\n  parse_chunk(ls);\n  if (ls->tok != TK_eof)\n    err_token(ls, TK_eof);\n  pt = fs_finish(ls, ls->linenumber);\n  L->top--;  /* Drop chunkname. */\n  lj_assertL(fs.prev == NULL && ls->fs == NULL, \"mismatched frame nesting\");\n  lj_assertL(pt->sizeuv == 0, \"toplevel proto has upvalues\");\n  return pt;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_parse.h",
    "content": "/*\n** Lua parser (source code -> bytecode).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_PARSE_H\n#define _LJ_PARSE_H\n\n#include \"lj_obj.h\"\n#include \"lj_lex.h\"\n\nLJ_FUNC GCproto *lj_parse(LexState *ls);\nLJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l);\n#if LJ_HASFFI\nLJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_prng.c",
    "content": "/*\n** Pseudo-random number generation.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_prng_c\n#define LUA_CORE\n\n/* To get the syscall prototype. */\n#if defined(__linux__) && !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n#include \"lj_prng.h\"\n\n/* -- PRNG step function -------------------------------------------------- */\n\n/* This implements a Tausworthe PRNG with period 2^223. Based on:\n**   Tables of maximally-equidistributed combined LFSR generators,\n**   Pierre L'Ecuyer, 1991, table 3, 1st entry.\n** Full-period ME-CF generator with L=64, J=4, k=223, N1=49.\n**\n** Important note: This PRNG is NOT suitable for cryptographic use!\n**\n** But it works fine for math.random(), which has an API that's not\n** suitable for cryptography, anyway.\n**\n** When used as a securely seeded global PRNG, it substantially raises\n** the difficulty for various attacks on the VM.\n*/\n\n/* Update generator i and compute a running xor of all states. */\n#define TW223_GEN(rs, z, r, i, k, q, s) \\\n  z = rs->u[i]; \\\n  z = (((z<<q)^z) >> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<<s); \\\n  r ^= z; rs->u[i] = z;\n\n#define TW223_STEP(rs, z, r) \\\n  TW223_GEN(rs, z, r, 0, 63, 31, 18) \\\n  TW223_GEN(rs, z, r, 1, 58, 19, 28) \\\n  TW223_GEN(rs, z, r, 2, 55, 24,  7) \\\n  TW223_GEN(rs, z, r, 3, 47, 21,  8)\n\n/* PRNG step function with uint64_t result. */\nLJ_NOINLINE uint64_t LJ_FASTCALL lj_prng_u64(PRNGState *rs)\n{\n  uint64_t z, r = 0;\n  TW223_STEP(rs, z, r)\n  return r;\n}\n\n/* PRNG step function with double in uint64_t result. */\nLJ_NOINLINE uint64_t LJ_FASTCALL lj_prng_u64d(PRNGState *rs)\n{\n  uint64_t z, r = 0;\n  TW223_STEP(rs, z, r)\n  /* Returns a double bit pattern in the range 1.0 <= d < 2.0. */\n  return (r & U64x(000fffff,ffffffff)) | U64x(3ff00000,00000000);\n}\n\n/* Condition seed: ensure k[i] MSB of u[i] are non-zero. */\nstatic LJ_AINLINE void lj_prng_condition(PRNGState *rs)\n{\n  if (rs->u[0] < (1u << 1)) rs->u[0] += (1u << 1);\n  if (rs->u[1] < (1u << 6)) rs->u[1] += (1u << 6);\n  if (rs->u[2] < (1u << 9)) rs->u[2] += (1u << 9);\n  if (rs->u[3] < (1u << 17)) rs->u[3] += (1u << 17);\n}\n\n/* -- PRNG seeding from OS ------------------------------------------------ */\n\n#if LUAJIT_SECURITY_PRNG == 0\n\n/* Nothing to define. */\n\n#elif LJ_TARGET_XBOX360\n\nextern int XNetRandom(void *buf, unsigned int len);\n\n#elif LJ_TARGET_PS3\n\nextern int sys_get_random_number(void *buf, uint64_t len);\n\n#elif LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n\nextern int sceRandomGetRandomNumber(void *buf, size_t len);\n\n#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOXONE\n\n#define WIN32_LEAN_AND_MEAN\n#include <windows.h>\n\n#if LJ_TARGET_UWP || LJ_TARGET_XBOXONE\n/* Must use BCryptGenRandom. */\n#include <bcrypt.h>\n#pragma comment(lib, \"bcrypt.lib\")\n#else\n/* If you wonder about this mess, then search online for RtlGenRandom. */\ntypedef BOOLEAN (WINAPI *PRGR)(void *buf, ULONG len);\nstatic PRGR libfunc_rgr;\n#endif\n\n#elif LJ_TARGET_POSIX\n\n#if LJ_TARGET_LINUX\n/* Avoid a dependency on glibc 2.25+ and use the getrandom syscall instead. */\n#include <sys/syscall.h>\n#else\n\n#if LJ_TARGET_OSX && !LJ_TARGET_IOS\n/*\n** In their infinite wisdom Apple decided to disallow getentropy() in the\n** iOS App Store. Even though the call is common to all BSD-ish OS, it's\n** recommended by Apple in their own security-related docs, and, to top\n** off the foolery, /dev/urandom is handled by the same kernel code,\n** yet accessing it is actually permitted (but less efficient).\n*/\n#include <Availability.h>\n#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200\n#define LJ_TARGET_HAS_GETENTROPY\t1\n#endif\n#elif (LJ_TARGET_BSD && !defined(__NetBSD__)) || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN\n#define LJ_TARGET_HAS_GETENTROPY\t1\n#endif\n\n#if LJ_TARGET_HAS_GETENTROPY\nextern int getentropy(void *buf, size_t len);\n#ifdef __ELF__\n  __attribute__((weak))\n#endif\n;\n#endif\n\n#endif\n\n/* For the /dev/urandom fallback. */\n#include <fcntl.h>\n#include <unistd.h>\n\n#endif\n\n#if LUAJIT_SECURITY_PRNG == 0\n\n/* If you really don't care about security, then define\n** LUAJIT_SECURITY_PRNG=0. This yields a predictable seed\n** and provides NO SECURITY against various attacks on the VM.\n**\n** BTW: This is NOT the way to get predictable table iteration,\n** predictable trace generation, predictable bytecode generation, etc.\n*/\nint LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs)\n{\n  lj_prng_seed_fixed(rs);  /* The fixed seed is already conditioned. */\n  return 1;\n}\n\n#else\n\n/* Securely seed PRNG from system entropy. Returns 0 on failure. */\nint LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs)\n{\n#if LJ_TARGET_XBOX360\n\n  if (XNetRandom(rs->u, (unsigned int)sizeof(rs->u)) == 0)\n    goto ok;\n\n#elif LJ_TARGET_PS3\n\n  if (sys_get_random_number(rs->u, sizeof(rs->u)) == 0)\n    goto ok;\n\n#elif LJ_TARGET_PS4 || LJ_TARGET_PSVITA\n\n  if (sceRandomGetRandomNumber(rs->u, sizeof(rs->u)) == 0)\n    goto ok;\n\n#elif LJ_TARGET_UWP || LJ_TARGET_XBOXONE\n\n  if (BCryptGenRandom(NULL, (PUCHAR)(rs->u), (ULONG)sizeof(rs->u),\n\t\t      BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0)\n    goto ok;\n\n#elif LJ_TARGET_WINDOWS\n\n  /* Keep the library loaded in case multiple VMs are started. */\n  if (!libfunc_rgr) {\n    HMODULE lib = LJ_WIN_LOADLIBA(\"advapi32.dll\");\n    if (!lib) return 0;\n    libfunc_rgr = (PRGR)GetProcAddress(lib, \"SystemFunction036\");\n    if (!libfunc_rgr) return 0;\n  }\n  if (libfunc_rgr(rs->u, (ULONG)sizeof(rs->u)))\n    goto ok;\n\n#elif LJ_TARGET_POSIX\n\n#if LJ_TARGET_LINUX && defined(SYS_getrandom)\n\n  if (syscall(SYS_getrandom, rs->u, sizeof(rs->u), 0) == (long)sizeof(rs->u))\n    goto ok;\n\n#elif LJ_TARGET_HAS_GETENTROPY\n\n#ifdef __ELF__\n  if (&getentropy && getentropy(rs->u, sizeof(rs->u)) == 0)\n    goto ok;\n#else\n  if (getentropy(rs->u, sizeof(rs->u)) == 0)\n    goto ok;\n#endif\n\n#endif\n\n  /* Fallback to /dev/urandom. This may fail if the device is not\n  ** existent or accessible in a chroot or container, or if the process\n  ** or the OS ran out of file descriptors.\n  */\n  {\n    int fd = open(\"/dev/urandom\", O_RDONLY|O_CLOEXEC);\n    if (fd != -1) {\n      ssize_t n = read(fd, rs->u, sizeof(rs->u));\n      (void)close(fd);\n      if (n == (ssize_t)sizeof(rs->u))\n\tgoto ok;\n    }\n  }\n\n#else\n\n  /* Add an elif above for your OS with a secure PRNG seed.\n  ** Note that fiddling around with rand(), getpid(), time() or coercing\n  ** ASLR to yield a few bits of randomness is not helpful.\n  ** If you don't want any security, then don't pretend you have any\n  ** and simply define LUAJIT_SECURITY_PRNG=0 for the build.\n  */\n#error \"Missing secure PRNG seed for this OS\"\n\n#endif\n  return 0;  /* Fail. */\n\nok:\n  lj_prng_condition(rs);\n  (void)lj_prng_u64(rs);\n  return 1;  /* Success. */\n}\n\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_prng.h",
    "content": "/*\n** Pseudo-random number generation.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_PRNG_H\n#define _LJ_PRNG_H\n\n#include \"lj_def.h\"\n\nLJ_FUNC int LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs);\nLJ_FUNC uint64_t LJ_FASTCALL lj_prng_u64(PRNGState *rs);\nLJ_FUNC uint64_t LJ_FASTCALL lj_prng_u64d(PRNGState *rs);\n\n/* This is just the precomputed result of lib_math.c:random_seed(rs, 0.0). */\nstatic LJ_AINLINE void lj_prng_seed_fixed(PRNGState *rs)\n{\n  rs->u[0] = U64x(a0d27757,0a345b8c);\n  rs->u[1] = U64x(764a296c,5d4aa64f);\n  rs->u[2] = U64x(51220704,070adeaa);\n  rs->u[3] = U64x(2a2717b5,a7b7b927);\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_profile.c",
    "content": "/*\n** Low-overhead profiling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_profile_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASPROFILE\n\n#include \"lj_buf.h\"\n#include \"lj_frame.h\"\n#include \"lj_debug.h\"\n#include \"lj_dispatch.h\"\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#include \"lj_trace.h\"\n#endif\n#include \"lj_profile.h\"\n\n#include \"luajit.h\"\n\n#if LJ_PROFILE_SIGPROF\n\n#include <sys/time.h>\n#include <signal.h>\n#define profile_lock(ps)\tUNUSED(ps)\n#define profile_unlock(ps)\tUNUSED(ps)\n\n#elif LJ_PROFILE_PTHREAD\n\n#include <pthread.h>\n#include <time.h>\n#if LJ_TARGET_PS3\n#include <sys/timer.h>\n#endif\n#define profile_lock(ps)\tpthread_mutex_lock(&ps->lock)\n#define profile_unlock(ps)\tpthread_mutex_unlock(&ps->lock)\n\n#elif LJ_PROFILE_WTHREAD\n\n#define WIN32_LEAN_AND_MEAN\n#if LJ_TARGET_XBOX360\n#include <xtl.h>\n#include <xbox.h>\n#else\n#include <windows.h>\n#endif\ntypedef unsigned int (WINAPI *WMM_TPFUNC)(unsigned int);\n#define profile_lock(ps)\tEnterCriticalSection(&ps->lock)\n#define profile_unlock(ps)\tLeaveCriticalSection(&ps->lock)\n\n#endif\n\n/* Profiler state. */\ntypedef struct ProfileState {\n  global_State *g;\t\t/* VM state that started the profiler. */\n  luaJIT_profile_callback cb;\t/* Profiler callback. */\n  void *data;\t\t\t/* Profiler callback data. */\n  SBuf sb;\t\t\t/* String buffer for stack dumps. */\n  int interval;\t\t\t/* Sample interval in milliseconds. */\n  int samples;\t\t\t/* Number of samples for next callback. */\n  int vmstate;\t\t\t/* VM state when profile timer triggered. */\n#if LJ_PROFILE_SIGPROF\n  struct sigaction oldsa;\t/* Previous SIGPROF state. */\n#elif LJ_PROFILE_PTHREAD\n  pthread_mutex_t lock;\t\t/* g->hookmask update lock. */\n  pthread_t thread;\t\t/* Timer thread. */\n  int abort;\t\t\t/* Abort timer thread. */\n#elif LJ_PROFILE_WTHREAD\n#if LJ_TARGET_WINDOWS\n  HINSTANCE wmm;\t\t/* WinMM library handle. */\n  WMM_TPFUNC wmm_tbp;\t\t/* WinMM timeBeginPeriod function. */\n  WMM_TPFUNC wmm_tep;\t\t/* WinMM timeEndPeriod function. */\n#endif\n  CRITICAL_SECTION lock;\t/* g->hookmask update lock. */\n  HANDLE thread;\t\t/* Timer thread. */\n  int abort;\t\t\t/* Abort timer thread. */\n#endif\n} ProfileState;\n\n/* Sadly, we have to use a static profiler state.\n**\n** The SIGPROF variant needs a static pointer to the global state, anyway.\n** And it would be hard to extend for multiple threads. You can still use\n** multiple VMs in multiple threads, but only profile one at a time.\n*/\nstatic ProfileState profile_state;\n\n/* Default sample interval in milliseconds. */\n#define LJ_PROFILE_INTERVAL_DEFAULT\t10\n\n/* -- Profiler/hook interaction ------------------------------------------- */\n\n#if !LJ_PROFILE_SIGPROF\nvoid LJ_FASTCALL lj_profile_hook_enter(global_State *g)\n{\n  ProfileState *ps = &profile_state;\n  if (ps->g) {\n    profile_lock(ps);\n    hook_enter(g);\n    profile_unlock(ps);\n  } else {\n    hook_enter(g);\n  }\n}\n\nvoid LJ_FASTCALL lj_profile_hook_leave(global_State *g)\n{\n  ProfileState *ps = &profile_state;\n  if (ps->g) {\n    profile_lock(ps);\n    hook_leave(g);\n    profile_unlock(ps);\n  } else {\n    hook_leave(g);\n  }\n}\n#endif\n\n/* -- Profile callbacks --------------------------------------------------- */\n\n/* Callback from profile hook (HOOK_PROFILE already cleared). */\nvoid LJ_FASTCALL lj_profile_interpreter(lua_State *L)\n{\n  ProfileState *ps = &profile_state;\n  global_State *g = G(L);\n  uint8_t mask;\n  profile_lock(ps);\n  mask = (g->hookmask & ~HOOK_PROFILE);\n  if (!(mask & HOOK_VMEVENT)) {\n    int samples = ps->samples;\n    ps->samples = 0;\n    g->hookmask = HOOK_VMEVENT;\n    lj_dispatch_update(g);\n    profile_unlock(ps);\n    ps->cb(ps->data, L, samples, ps->vmstate);  /* Invoke user callback. */\n    profile_lock(ps);\n    mask |= (g->hookmask & HOOK_PROFILE);\n  }\n  g->hookmask = mask;\n  lj_dispatch_update(g);\n  profile_unlock(ps);\n}\n\n/* Trigger profile hook. Asynchronous call from OS-specific profile timer. */\nstatic void profile_trigger(ProfileState *ps)\n{\n  global_State *g = ps->g;\n  uint8_t mask;\n  profile_lock(ps);\n  ps->samples++;  /* Always increment number of samples. */\n  mask = g->hookmask;\n  if (!(mask & (HOOK_PROFILE|HOOK_VMEVENT|HOOK_GC))) {  /* Set profile hook. */\n    int st = g->vmstate;\n    ps->vmstate = st >= 0 ? 'N' :\n\t\t  st == ~LJ_VMST_INTERP ? 'I' :\n\t\t  st == ~LJ_VMST_C ? 'C' :\n\t\t  st == ~LJ_VMST_GC ? 'G' : 'J';\n    g->hookmask = (mask | HOOK_PROFILE);\n    lj_dispatch_update(g);\n  }\n  profile_unlock(ps);\n}\n\n/* -- OS-specific profile timer handling ---------------------------------- */\n\n#if LJ_PROFILE_SIGPROF\n\n/* SIGPROF handler. */\nstatic void profile_signal(int sig)\n{\n  UNUSED(sig);\n  profile_trigger(&profile_state);\n}\n\n/* Start profiling timer. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n  int interval = ps->interval;\n  struct itimerval tm;\n  struct sigaction sa;\n  tm.it_value.tv_sec = tm.it_interval.tv_sec = interval / 1000;\n  tm.it_value.tv_usec = tm.it_interval.tv_usec = (interval % 1000) * 1000;\n  setitimer(ITIMER_PROF, &tm, NULL);\n  sa.sa_flags = SA_RESTART;\n  sa.sa_handler = profile_signal;\n  sigemptyset(&sa.sa_mask);\n  sigaction(SIGPROF, &sa, &ps->oldsa);\n}\n\n/* Stop profiling timer. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  struct itimerval tm;\n  tm.it_value.tv_sec = tm.it_interval.tv_sec = 0;\n  tm.it_value.tv_usec = tm.it_interval.tv_usec = 0;\n  setitimer(ITIMER_PROF, &tm, NULL);\n  sigaction(SIGPROF, &ps->oldsa, NULL);\n}\n\n#elif LJ_PROFILE_PTHREAD\n\n/* POSIX timer thread. */\nstatic void *profile_thread(ProfileState *ps)\n{\n  int interval = ps->interval;\n#if !LJ_TARGET_PS3\n  struct timespec ts;\n  ts.tv_sec = interval / 1000;\n  ts.tv_nsec = (interval % 1000) * 1000000;\n#endif\n  while (1) {\n#if LJ_TARGET_PS3\n    sys_timer_usleep(interval * 1000);\n#else\n    nanosleep(&ts, NULL);\n#endif\n    if (ps->abort) break;\n    profile_trigger(ps);\n  }\n  return NULL;\n}\n\n/* Start profiling timer thread. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n  pthread_mutex_init(&ps->lock, 0);\n  ps->abort = 0;\n  pthread_create(&ps->thread, NULL, (void *(*)(void *))profile_thread, ps);\n}\n\n/* Stop profiling timer thread. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  ps->abort = 1;\n  pthread_join(ps->thread, NULL);\n  pthread_mutex_destroy(&ps->lock);\n}\n\n#elif LJ_PROFILE_WTHREAD\n\n/* Windows timer thread. */\nstatic DWORD WINAPI profile_thread(void *psx)\n{\n  ProfileState *ps = (ProfileState *)psx;\n  int interval = ps->interval;\n#if LJ_TARGET_WINDOWS && !LJ_TARGET_UWP\n  ps->wmm_tbp(interval);\n#endif\n  while (1) {\n    Sleep(interval);\n    if (ps->abort) break;\n    profile_trigger(ps);\n  }\n#if LJ_TARGET_WINDOWS && !LJ_TARGET_UWP\n  ps->wmm_tep(interval);\n#endif\n  return 0;\n}\n\n/* Start profiling timer thread. */\nstatic void profile_timer_start(ProfileState *ps)\n{\n#if LJ_TARGET_WINDOWS && !LJ_TARGET_UWP\n  if (!ps->wmm) {  /* Load WinMM library on-demand. */\n    ps->wmm = LJ_WIN_LOADLIBA(\"winmm.dll\");\n    if (ps->wmm) {\n      ps->wmm_tbp = (WMM_TPFUNC)GetProcAddress(ps->wmm, \"timeBeginPeriod\");\n      ps->wmm_tep = (WMM_TPFUNC)GetProcAddress(ps->wmm, \"timeEndPeriod\");\n      if (!ps->wmm_tbp || !ps->wmm_tep) {\n\tps->wmm = NULL;\n\treturn;\n      }\n    }\n  }\n#endif\n  InitializeCriticalSection(&ps->lock);\n  ps->abort = 0;\n  ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL);\n}\n\n/* Stop profiling timer thread. */\nstatic void profile_timer_stop(ProfileState *ps)\n{\n  ps->abort = 1;\n  WaitForSingleObject(ps->thread, INFINITE);\n  DeleteCriticalSection(&ps->lock);\n}\n\n#endif\n\n/* -- Public profiling API ------------------------------------------------ */\n\n/* Start profiling. */\nLUA_API void luaJIT_profile_start(lua_State *L, const char *mode,\n\t\t\t\t  luaJIT_profile_callback cb, void *data)\n{\n  ProfileState *ps = &profile_state;\n  int interval = LJ_PROFILE_INTERVAL_DEFAULT;\n  while (*mode) {\n    int m = *mode++;\n    switch (m) {\n    case 'i':\n      interval = 0;\n      while (*mode >= '0' && *mode <= '9')\n\tinterval = interval * 10 + (*mode++ - '0');\n      if (interval <= 0) interval = 1;\n      break;\n#if LJ_HASJIT\n    case 'l': case 'f':\n      L2J(L)->prof_mode = m;\n      lj_trace_flushall(L);\n      break;\n#endif\n    default:  /* Ignore unknown mode chars. */\n      break;\n    }\n  }\n  if (ps->g) {\n    luaJIT_profile_stop(L);\n    if (ps->g) return;  /* Profiler in use by another VM. */\n  }\n  ps->g = G(L);\n  ps->interval = interval;\n  ps->cb = cb;\n  ps->data = data;\n  ps->samples = 0;\n  lj_buf_init(L, &ps->sb);\n  profile_timer_start(ps);\n}\n\n/* Stop profiling. */\nLUA_API void luaJIT_profile_stop(lua_State *L)\n{\n  ProfileState *ps = &profile_state;\n  global_State *g = ps->g;\n  if (G(L) == g) {  /* Only stop profiler if started by this VM. */\n    profile_timer_stop(ps);\n    g->hookmask &= ~HOOK_PROFILE;\n    lj_dispatch_update(g);\n#if LJ_HASJIT\n    G2J(g)->prof_mode = 0;\n    lj_trace_flushall(L);\n#endif\n    lj_buf_free(g, &ps->sb);\n    ps->sb.w = ps->sb.e = NULL;\n    ps->g = NULL;\n  }\n}\n\n/* Return a compact stack dump. */\nLUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt,\n\t\t\t\t\t     int depth, size_t *len)\n{\n  ProfileState *ps = &profile_state;\n  SBuf *sb = &ps->sb;\n  setsbufL(sb, L);\n  lj_buf_reset(sb);\n  lj_debug_dumpstack(L, sb, fmt, depth);\n  *len = (size_t)sbuflen(sb);\n  return sb->b;\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_profile.h",
    "content": "/*\n** Low-overhead profiling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_PROFILE_H\n#define _LJ_PROFILE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASPROFILE\n\nLJ_FUNC void LJ_FASTCALL lj_profile_interpreter(lua_State *L);\n#if !LJ_PROFILE_SIGPROF\nLJ_FUNC void LJ_FASTCALL lj_profile_hook_enter(global_State *g);\nLJ_FUNC void LJ_FASTCALL lj_profile_hook_leave(global_State *g);\n#endif\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_record.c",
    "content": "/*\n** Trace recorder (bytecode -> SSA IR).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_record_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_meta.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_bc.h\"\n#include \"lj_ff.h\"\n#if LJ_HASPROFILE\n#include \"lj_debug.h\"\n#endif\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_ircall.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_record.h\"\n#include \"lj_ffrecord.h\"\n#include \"lj_snap.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_prng.h\"\n\n/* Some local macros to save typing. Undef'd at the end. */\n#define IR(ref)\t\t\t(&J->cur.ir[(ref)])\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Sanity checks ------------------------------------------------------- */\n\n#ifdef LUA_USE_ASSERT\n/* Sanity check the whole IR -- sloooow. */\nstatic void rec_check_ir(jit_State *J)\n{\n  IRRef i, nins = J->cur.nins, nk = J->cur.nk;\n  lj_assertJ(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536,\n\t     \"inconsistent IR layout\");\n  for (i = nk; i < nins; i++) {\n    IRIns *ir = IR(i);\n    uint32_t mode = lj_ir_mode[ir->o];\n    IRRef op1 = ir->op1;\n    IRRef op2 = ir->op2;\n    const char *err = NULL;\n    switch (irm_op1(mode)) {\n    case IRMnone:\n      if (op1 != 0) err = \"IRMnone op1 used\";\n      break;\n    case IRMref:\n      if (op1 < nk || (i >= REF_BIAS ? op1 >= i : op1 <= i))\n\terr = \"IRMref op1 out of range\";\n      break;\n    case IRMlit: break;\n    case IRMcst:\n      if (i >= REF_BIAS) { err = \"constant in IR range\"; break; }\n      if (irt_is64(ir->t) && ir->o != IR_KNULL)\n\ti++;\n      continue;\n    }\n    switch (irm_op2(mode)) {\n    case IRMnone:\n      if (op2) err = \"IRMnone op2 used\";\n      break;\n    case IRMref:\n      if (op2 < nk || (i >= REF_BIAS ? op2 >= i : op2 <= i))\n\terr = \"IRMref op2 out of range\";\n      break;\n    case IRMlit: break;\n    case IRMcst: err = \"IRMcst op2\"; break;\n    }\n    if (!err && ir->prev) {\n      if (ir->prev < nk || (i >= REF_BIAS ? ir->prev >= i : ir->prev <= i))\n\terr = \"chain out of range\";\n      else if (ir->o != IR_NOP && IR(ir->prev)->o != ir->o)\n\terr = \"chain to different op\";\n    }\n    lj_assertJ(!err, \"bad IR %04d op %d(%04d,%04d): %s\",\n\t       i-REF_BIAS,\n\t       ir->o,\n\t       irm_op1(mode) == IRMref ? op1-REF_BIAS : op1,\n\t       irm_op2(mode) == IRMref ? op2-REF_BIAS : op2,\n\t       err);\n  }\n}\n\n/* Compare stack slots and frames of the recorder and the VM. */\nstatic void rec_check_slots(jit_State *J)\n{\n  BCReg s, nslots = J->baseslot + J->maxslot;\n  int32_t depth = 0;\n  cTValue *base = J->L->base - J->baseslot;\n  lj_assertJ(J->baseslot >= 1+LJ_FR2, \"bad baseslot\");\n  lj_assertJ(J->baseslot == 1+LJ_FR2 || (J->slot[J->baseslot-1] & TREF_FRAME),\n\t     \"baseslot does not point to frame\");\n  lj_assertJ(nslots <= LJ_MAX_JSLOTS, \"slot overflow\");\n  for (s = 0; s < nslots; s++) {\n    TRef tr = J->slot[s];\n    if (tr) {\n      cTValue *tv = &base[s];\n      IRRef ref = tref_ref(tr);\n      IRIns *ir = NULL;  /* Silence compiler. */\n      if (!LJ_FR2 || ref || !(tr & (TREF_FRAME | TREF_CONT))) {\n\tlj_assertJ(ref >= J->cur.nk && ref < J->cur.nins,\n\t\t   \"slot %d ref %04d out of range\", s, ref - REF_BIAS);\n\tir = IR(ref);\n\tlj_assertJ(irt_t(ir->t) == tref_t(tr), \"slot %d IR type mismatch\", s);\n      }\n      if (s == 0) {\n\tlj_assertJ(tref_isfunc(tr), \"frame slot 0 is not a function\");\n#if LJ_FR2\n      } else if (s == 1) {\n\tlj_assertJ((tr & ~TREF_FRAME) == 0, \"bad frame slot 1\");\n#endif\n      } else if ((tr & TREF_FRAME)) {\n\tGCfunc *fn = gco2func(frame_gc(tv));\n\tBCReg delta = (BCReg)(tv - frame_prev(tv));\n#if LJ_FR2\n\tlj_assertJ(!ref || ir_knum(ir)->u64 == tv->u64,\n\t\t   \"frame slot %d PC mismatch\", s);\n\ttr = J->slot[s-1];\n\tir = IR(tref_ref(tr));\n#endif\n\tlj_assertJ(tref_isfunc(tr),\n\t\t   \"frame slot %d is not a function\", s-LJ_FR2);\n\tlj_assertJ(!tref_isk(tr) || fn == ir_kfunc(ir),\n\t\t   \"frame slot %d function mismatch\", s-LJ_FR2);\n\tlj_assertJ(s > delta + LJ_FR2 ? (J->slot[s-delta] & TREF_FRAME)\n\t\t\t\t      : (s == delta + LJ_FR2),\n\t\t   \"frame slot %d broken chain\", s-LJ_FR2);\n\tdepth++;\n      } else if ((tr & TREF_CONT)) {\n#if LJ_FR2\n\tlj_assertJ(!ref || ir_knum(ir)->u64 == tv->u64,\n\t\t   \"cont slot %d continuation mismatch\", s);\n#else\n\tlj_assertJ(ir_kptr(ir) == gcrefp(tv->gcr, void),\n\t\t   \"cont slot %d continuation mismatch\", s);\n#endif\n\tlj_assertJ((J->slot[s+1+LJ_FR2] & TREF_FRAME),\n\t\t   \"cont slot %d not followed by frame\", s);\n\tdepth++;\n      } else if ((tr & TREF_KEYINDEX)) {\n\tlj_assertJ(tref_isint(tr), \"keyindex slot %d bad type %d\",\n\t\t\t\t   s, tref_type(tr));\n      } else {\n\t/* Number repr. may differ, but other types must be the same. */\n\tlj_assertJ(tvisnumber(tv) ? tref_isnumber(tr) :\n\t\t\t\t    itype2irt(tv) == tref_type(tr),\n\t\t   \"slot %d type mismatch: stack type %d vs IR type %d\",\n\t\t   s, itypemap(tv), tref_type(tr));\n\tif (tref_isk(tr)) {  /* Compare constants. */\n\t  TValue tvk;\n\t  lj_ir_kvalue(J->L, &tvk, ir);\n\t  lj_assertJ((tvisnum(&tvk) && tvisnan(&tvk)) ?\n\t\t     (tvisnum(tv) && tvisnan(tv)) :\n\t\t     lj_obj_equal(tv, &tvk),\n\t\t     \"slot %d const mismatch: stack %016llx vs IR %016llx\",\n\t\t     s, tv->u64, tvk.u64);\n\t}\n      }\n    }\n  }\n  lj_assertJ(J->framedepth == depth,\n\t     \"frame depth mismatch %d vs %d\", J->framedepth, depth);\n}\n#endif\n\n/* -- Type handling and specialization ------------------------------------ */\n\n/* Note: these functions return tagged references (TRef). */\n\n/* Specialize a slot to a specific type. Note: slot can be negative! */\nstatic TRef sloadt(jit_State *J, int32_t slot, IRType t, int mode)\n{\n  /* Caller may set IRT_GUARD in t. */\n  TRef ref = emitir_raw(IRT(IR_SLOAD, t), (int32_t)J->baseslot+slot, mode);\n  J->base[slot] = ref;\n  return ref;\n}\n\n/* Specialize a slot to the runtime type. Note: slot can be negative! */\nstatic TRef sload(jit_State *J, int32_t slot)\n{\n  IRType t = itype2irt(&J->L->base[slot]);\n  TRef ref = emitir_raw(IRTG(IR_SLOAD, t), (int32_t)J->baseslot+slot,\n\t\t\tIRSLOAD_TYPECHECK);\n  if (irtype_ispri(t)) ref = TREF_PRI(t);  /* Canonicalize primitive refs. */\n  J->base[slot] = ref;\n  return ref;\n}\n\n/* Get TRef from slot. Load slot and specialize if not done already. */\n#define getslot(J, s)\t(J->base[(s)] ? J->base[(s)] : sload(J, (int32_t)(s)))\n\n/* Get TRef for current function. */\nstatic TRef getcurrf(jit_State *J)\n{\n  if (J->base[-1-LJ_FR2])\n    return J->base[-1-LJ_FR2];\n  /* Non-base frame functions ought to be loaded already. */\n  lj_assertJ(J->baseslot == 1+LJ_FR2, \"bad baseslot\");\n  return sloadt(J, -1-LJ_FR2, IRT_FUNC, IRSLOAD_READONLY);\n}\n\n/* Compare for raw object equality.\n** Returns 0 if the objects are the same.\n** Returns 1 if they are different, but the same type.\n** Returns 2 for two different types.\n** Comparisons between primitives always return 1 -- no caller cares about it.\n*/\nint lj_record_objcmp(jit_State *J, TRef a, TRef b, cTValue *av, cTValue *bv)\n{\n  int diff = !lj_obj_equal(av, bv);\n  if (!tref_isk2(a, b)) {  /* Shortcut, also handles primitives. */\n    IRType ta = tref_isinteger(a) ? IRT_INT : tref_type(a);\n    IRType tb = tref_isinteger(b) ? IRT_INT : tref_type(b);\n    if (ta != tb) {\n      /* Widen mixed number/int comparisons to number/number comparison. */\n      if (ta == IRT_INT && tb == IRT_NUM) {\n\ta = emitir(IRTN(IR_CONV), a, IRCONV_NUM_INT);\n\tta = IRT_NUM;\n      } else if (ta == IRT_NUM && tb == IRT_INT) {\n\tb = emitir(IRTN(IR_CONV), b, IRCONV_NUM_INT);\n      } else {\n\treturn 2;  /* Two different types are never equal. */\n      }\n    }\n    emitir(IRTG(diff ? IR_NE : IR_EQ, ta), a, b);\n  }\n  return diff;\n}\n\n/* Constify a value. Returns 0 for non-representable object types. */\nTRef lj_record_constify(jit_State *J, cTValue *o)\n{\n  if (tvisgcv(o))\n    return lj_ir_kgc(J, gcV(o), itype2irt(o));\n  else if (tvisint(o))\n    return lj_ir_kint(J, intV(o));\n  else if (tvisnum(o))\n    return lj_ir_knumint(J, numV(o));\n  else if (tvisbool(o))\n    return TREF_PRI(itype2irt(o));\n  else\n    return 0;  /* Can't represent lightuserdata (pointless). */\n}\n\n/* Emit a VLOAD with the correct type. */\nTRef lj_record_vload(jit_State *J, TRef ref, MSize idx, IRType t)\n{\n  TRef tr = emitir(IRTG(IR_VLOAD, t), ref, idx);\n  if (irtype_ispri(t)) tr = TREF_PRI(t);  /* Canonicalize primitives. */\n  return tr;\n}\n\n/* -- Record loop ops ----------------------------------------------------- */\n\n/* Loop event. */\ntypedef enum {\n  LOOPEV_LEAVE,\t\t/* Loop is left or not entered. */\n  LOOPEV_ENTERLO,\t/* Loop is entered with a low iteration count left. */\n  LOOPEV_ENTER\t\t/* Loop is entered. */\n} LoopEvent;\n\n/* Canonicalize slots: convert integers to numbers. */\nstatic void canonicalize_slots(jit_State *J)\n{\n  BCReg s;\n  if (LJ_DUALNUM) return;\n  for (s = J->baseslot+J->maxslot-1; s >= 1; s--) {\n    TRef tr = J->slot[s];\n    if (tref_isinteger(tr) && !(tr & TREF_KEYINDEX)) {\n      IRIns *ir = IR(tref_ref(tr));\n      if (!(ir->o == IR_SLOAD && (ir->op2 & (IRSLOAD_READONLY))))\n\tJ->slot[s] = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);\n    }\n  }\n}\n\n/* Stop recording. */\nvoid lj_record_stop(jit_State *J, TraceLink linktype, TraceNo lnk)\n{\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  if (J->retryrec)\n    lj_trace_err(J, LJ_TRERR_RETRY);\n#endif\n  lj_trace_end(J);\n  J->cur.linktype = (uint8_t)linktype;\n  J->cur.link = (uint16_t)lnk;\n  /* Looping back at the same stack level? */\n  if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) {\n    if ((J->flags & JIT_F_OPT_LOOP))  /* Shall we try to create a loop? */\n      goto nocanon;  /* Do not canonicalize or we lose the narrowing. */\n    if (J->cur.root)  /* Otherwise ensure we always link to the root trace. */\n      J->cur.link = J->cur.root;\n  }\n  canonicalize_slots(J);\nnocanon:\n  /* Note: all loop ops must set J->pc to the following instruction! */\n  lj_snap_add(J);  /* Add loop snapshot. */\n  J->needsnap = 0;\n  J->mergesnap = 1;  /* In case recording continues. */\n}\n\n/* Search bytecode backwards for a int/num constant slot initializer. */\nstatic TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t)\n{\n  /* This algorithm is rather simplistic and assumes quite a bit about\n  ** how the bytecode is generated. It works fine for FORI initializers,\n  ** but it won't necessarily work in other cases (e.g. iterator arguments).\n  ** It doesn't do anything fancy, either (like backpropagating MOVs).\n  */\n  const BCIns *pc, *startpc = proto_bc(J->pt);\n  for (pc = endpc-1; pc > startpc; pc--) {\n    BCIns ins = *pc;\n    BCOp op = bc_op(ins);\n    /* First try to find the last instruction that stores to this slot. */\n    if (bcmode_a(op) == BCMbase && bc_a(ins) <= slot) {\n      return 0;  /* Multiple results, e.g. from a CALL or KNIL. */\n    } else if (bcmode_a(op) == BCMdst && bc_a(ins) == slot) {\n      if (op == BC_KSHORT || op == BC_KNUM) {  /* Found const. initializer. */\n\t/* Now try to verify there's no forward jump across it. */\n\tconst BCIns *kpc = pc;\n\tfor (; pc > startpc; pc--)\n\t  if (bc_op(*pc) == BC_JMP) {\n\t    const BCIns *target = pc+bc_j(*pc)+1;\n\t    if (target > kpc && target <= endpc)\n\t      return 0;  /* Conditional assignment. */\n\t  }\n\tif (op == BC_KSHORT) {\n\t  int32_t k = (int32_t)(int16_t)bc_d(ins);\n\t  return t == IRT_INT ? lj_ir_kint(J, k) : lj_ir_knum(J, (lua_Number)k);\n\t} else {\n\t  cTValue *tv = proto_knumtv(J->pt, bc_d(ins));\n\t  if (t == IRT_INT) {\n\t    int32_t k = numberVint(tv);\n\t    if (tvisint(tv) || numV(tv) == (lua_Number)k)  /* -0 is ok here. */\n\t      return lj_ir_kint(J, k);\n\t    return 0;  /* Type mismatch. */\n\t  } else {\n\t    return lj_ir_knum(J, numberVnum(tv));\n\t  }\n\t}\n      }\n      return 0;  /* Non-constant initializer. */\n    }\n  }\n  return 0;  /* No assignment to this slot found? */\n}\n\n/* Load and optionally convert a FORI argument from a slot. */\nstatic TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode)\n{\n  int conv = (tvisint(&J->L->base[slot]) != (t==IRT_INT)) ? IRSLOAD_CONVERT : 0;\n  return sloadt(J, (int32_t)slot,\n\t\tt + (((mode & IRSLOAD_TYPECHECK) ||\n\t\t      (conv && t == IRT_INT && !(mode >> 16))) ?\n\t\t     IRT_GUARD : 0),\n\t\tmode + conv);\n}\n\n/* Peek before FORI to find a const initializer. Otherwise load from slot. */\nstatic TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,\n\t\t     IRType t, int mode)\n{\n  TRef tr = J->base[slot];\n  if (!tr) {\n    tr = find_kinit(J, fori, slot, t);\n    if (!tr)\n      tr = fori_load(J, slot, t, mode);\n  }\n  return tr;\n}\n\n/* Return the direction of the FOR loop iterator.\n** It's important to exactly reproduce the semantics of the interpreter.\n*/\nstatic int rec_for_direction(cTValue *o)\n{\n  return (tvisint(o) ? intV(o) : (int32_t)o->u32.hi) >= 0;\n}\n\n/* Simulate the runtime behavior of the FOR loop iterator. */\nstatic LoopEvent rec_for_iter(IROp *op, cTValue *o, int isforl)\n{\n  lua_Number stopv = numberVnum(&o[FORL_STOP]);\n  lua_Number idxv = numberVnum(&o[FORL_IDX]);\n  lua_Number stepv = numberVnum(&o[FORL_STEP]);\n  if (isforl)\n    idxv += stepv;\n  if (rec_for_direction(&o[FORL_STEP])) {\n    if (idxv <= stopv) {\n      *op = IR_LE;\n      return idxv + 2*stepv > stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;\n    }\n    *op = IR_GT; return LOOPEV_LEAVE;\n  } else {\n    if (stopv <= idxv) {\n      *op = IR_GE;\n      return idxv + 2*stepv < stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;\n    }\n    *op = IR_LT; return LOOPEV_LEAVE;\n  }\n}\n\n/* Record checks for FOR loop overflow and step direction. */\nstatic void rec_for_check(jit_State *J, IRType t, int dir,\n\t\t\t  TRef stop, TRef step, int init)\n{\n  if (!tref_isk(step)) {\n    /* Non-constant step: need a guard for the direction. */\n    TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J);\n    emitir(IRTG(dir ? IR_GE : IR_LT, t), step, zero);\n    /* Add hoistable overflow checks for a narrowed FORL index. */\n    if (init && t == IRT_INT) {\n      if (tref_isk(stop)) {\n\t/* Constant stop: optimize check away or to a range check for step. */\n\tint32_t k = IR(tref_ref(stop))->i;\n\tif (dir) {\n\t  if (k > 0)\n\t    emitir(IRTGI(IR_LE), step, lj_ir_kint(J, (int32_t)0x7fffffff-k));\n\t} else {\n\t  if (k < 0)\n\t    emitir(IRTGI(IR_GE), step, lj_ir_kint(J, (int32_t)0x80000000-k));\n\t}\n      } else {\n\t/* Stop+step variable: need full overflow check. */\n\tTRef tr = emitir(IRTGI(IR_ADDOV), step, stop);\n\temitir(IRTI(IR_USE), tr, 0);  /* ADDOV is weak. Avoid dead result. */\n      }\n    }\n  } else if (init && t == IRT_INT && !tref_isk(stop)) {\n    /* Constant step: optimize overflow check to a range check for stop. */\n    int32_t k = IR(tref_ref(step))->i;\n    k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k;\n    emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k));\n  }\n}\n\n/* Record a FORL instruction. */\nstatic void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev,\n\t\t\t int init)\n{\n  BCReg ra = bc_a(*fori);\n  cTValue *tv = &J->L->base[ra];\n  TRef idx = J->base[ra+FORL_IDX];\n  IRType t = idx ? tref_type(idx) :\n\t     (init || LJ_DUALNUM) ? lj_opt_narrow_forl(J, tv) : IRT_NUM;\n  int mode = IRSLOAD_INHERIT +\n    ((!LJ_DUALNUM || tvisint(tv) == (t == IRT_INT)) ? IRSLOAD_READONLY : 0);\n  TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode);\n  TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode);\n  int tc, dir = rec_for_direction(&tv[FORL_STEP]);\n  lj_assertJ(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI,\n\t     \"bad bytecode %d instead of FORI/JFORI\", bc_op(*fori));\n  scev->t.irt = t;\n  scev->dir = dir;\n  scev->stop = tref_ref(stop);\n  scev->step = tref_ref(step);\n  rec_for_check(J, t, dir, stop, step, init);\n  scev->start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT));\n  tc = (LJ_DUALNUM &&\n\t!(scev->start && irref_isk(scev->stop) && irref_isk(scev->step) &&\n\t  tvisint(&tv[FORL_IDX]) == (t == IRT_INT))) ?\n\tIRSLOAD_TYPECHECK : 0;\n  if (tc) {\n    J->base[ra+FORL_STOP] = stop;\n    J->base[ra+FORL_STEP] = step;\n  }\n  if (!idx)\n    idx = fori_load(J, ra+FORL_IDX, t,\n\t\t    IRSLOAD_INHERIT + tc + (J->scev.start << 16));\n  if (!init)\n    J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step);\n  J->base[ra+FORL_EXT] = idx;\n  scev->idx = tref_ref(idx);\n  setmref(scev->pc, fori);\n  J->maxslot = ra+FORL_EXT+1;\n}\n\n/* Record FORL/JFORL or FORI/JFORI. */\nstatic LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)\n{\n  BCReg ra = bc_a(*fori);\n  TValue *tv = &J->L->base[ra];\n  TRef *tr = &J->base[ra];\n  IROp op;\n  LoopEvent ev;\n  TRef stop;\n  IRType t;\n  if (isforl) {  /* Handle FORL/JFORL opcodes. */\n    TRef idx = tr[FORL_IDX];\n    if (mref(J->scev.pc, const BCIns) == fori && tref_ref(idx) == J->scev.idx) {\n      t = J->scev.t.irt;\n      stop = J->scev.stop;\n      idx = emitir(IRT(IR_ADD, t), idx, J->scev.step);\n      tr[FORL_EXT] = tr[FORL_IDX] = idx;\n    } else {\n      ScEvEntry scev;\n      rec_for_loop(J, fori, &scev, 0);\n      t = scev.t.irt;\n      stop = scev.stop;\n    }\n  } else {  /* Handle FORI/JFORI opcodes. */\n    BCReg i;\n    lj_meta_for(J->L, tv);\n    t = (LJ_DUALNUM || tref_isint(tr[FORL_IDX])) ? lj_opt_narrow_forl(J, tv) :\n\t\t\t\t\t\t   IRT_NUM;\n    for (i = FORL_IDX; i <= FORL_STEP; i++) {\n      if (!tr[i]) sload(J, ra+i);\n      lj_assertJ(tref_isnumber_str(tr[i]), \"bad FORI argument type\");\n      if (tref_isstr(tr[i]))\n\ttr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);\n      if (t == IRT_INT) {\n\tif (!tref_isinteger(tr[i]))\n\t  tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK);\n      } else {\n\tif (!tref_isnum(tr[i]))\n\t  tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT);\n      }\n    }\n    tr[FORL_EXT] = tr[FORL_IDX];\n    stop = tr[FORL_STOP];\n    rec_for_check(J, t, rec_for_direction(&tv[FORL_STEP]),\n\t\t  stop, tr[FORL_STEP], 1);\n  }\n\n  ev = rec_for_iter(&op, tv, isforl);\n  if (ev == LOOPEV_LEAVE) {\n    J->maxslot = ra+FORL_EXT+1;\n    J->pc = fori+1;\n  } else {\n    J->maxslot = ra;\n    J->pc = fori+bc_j(*fori)+1;\n  }\n  lj_snap_add(J);\n\n  emitir(IRTG(op, t), tr[FORL_IDX], stop);\n\n  if (ev == LOOPEV_LEAVE) {\n    J->maxslot = ra;\n    J->pc = fori+bc_j(*fori)+1;\n  } else {\n    J->maxslot = ra+FORL_EXT+1;\n    J->pc = fori+1;\n  }\n  J->needsnap = 1;\n  return ev;\n}\n\n/* Record ITERL/JITERL. */\nstatic LoopEvent rec_iterl(jit_State *J, const BCIns iterins)\n{\n  BCReg ra = bc_a(iterins);\n  if (!tref_isnil(getslot(J, ra))) {  /* Looping back? */\n    J->base[ra-1] = J->base[ra];  /* Copy result of ITERC to control var. */\n    J->maxslot = ra-1+bc_b(J->pc[-1]);\n    J->pc += bc_j(iterins)+1;\n    return LOOPEV_ENTER;\n  } else {\n    J->maxslot = ra-3;\n    J->pc++;\n    return LOOPEV_LEAVE;\n  }\n}\n\n/* Record LOOP/JLOOP. Now, that was easy. */\nstatic LoopEvent rec_loop(jit_State *J, BCReg ra, int skip)\n{\n  if (ra < J->maxslot) J->maxslot = ra;\n  J->pc += skip;\n  return LOOPEV_ENTER;\n}\n\n/* Check if a loop repeatedly failed to trace because it didn't loop back. */\nstatic int innerloopleft(jit_State *J, const BCIns *pc)\n{\n  ptrdiff_t i;\n  for (i = 0; i < PENALTY_SLOTS; i++)\n    if (mref(J->penalty[i].pc, const BCIns) == pc) {\n      if ((J->penalty[i].reason == LJ_TRERR_LLEAVE ||\n\t   J->penalty[i].reason == LJ_TRERR_LINNER) &&\n\t  J->penalty[i].val >= 2*PENALTY_MIN)\n\treturn 1;\n      break;\n    }\n  return 0;\n}\n\n/* Handle the case when an interpreted loop op is hit. */\nstatic void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev)\n{\n  if (J->parent == 0 && J->exitno == 0) {\n    if (pc == J->startpc && J->framedepth + J->retdepth == 0) {\n      if (bc_op(J->cur.startins) == BC_ITERN) return;  /* See rec_itern(). */\n      /* Same loop? */\n      if (ev == LOOPEV_LEAVE)  /* Must loop back to form a root trace. */\n\tlj_trace_err(J, LJ_TRERR_LLEAVE);\n      lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Looping trace. */\n    } else if (ev != LOOPEV_LEAVE) {  /* Entering inner loop? */\n      /* It's usually better to abort here and wait until the inner loop\n      ** is traced. But if the inner loop repeatedly didn't loop back,\n      ** this indicates a low trip count. In this case try unrolling\n      ** an inner loop even in a root trace. But it's better to be a bit\n      ** more conservative here and only do it for very short loops.\n      */\n      if (bc_j(*pc) != -1 && !innerloopleft(J, pc))\n\tlj_trace_err(J, LJ_TRERR_LINNER);  /* Root trace hit an inner loop. */\n      if ((ev != LOOPEV_ENTERLO &&\n\t   J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0)\n\tlj_trace_err(J, LJ_TRERR_LUNROLL);  /* Limit loop unrolling. */\n      J->loopref = J->cur.nins;\n    }\n  } else if (ev != LOOPEV_LEAVE) {  /* Side trace enters an inner loop. */\n    J->loopref = J->cur.nins;\n    if (--J->loopunroll < 0)\n      lj_trace_err(J, LJ_TRERR_LUNROLL);  /* Limit loop unrolling. */\n  }  /* Side trace continues across a loop that's left or not entered. */\n}\n\n/* Handle the case when an already compiled loop op is hit. */\nstatic void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)\n{\n  if (J->parent == 0 && J->exitno == 0) {  /* Root trace hit an inner loop. */\n    /* Better let the inner loop spawn a side trace back here. */\n    lj_trace_err(J, LJ_TRERR_LINNER);\n  } else if (ev != LOOPEV_LEAVE) {  /* Side trace enters a compiled loop. */\n    J->instunroll = 0;  /* Cannot continue across a compiled loop op. */\n    if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)\n      lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Form extra loop. */\n    else\n      lj_record_stop(J, LJ_TRLINK_ROOT, lnk);  /* Link to the loop. */\n  }  /* Side trace continues across a loop that's left or not entered. */\n}\n\n/* Record ITERN. */\nstatic LoopEvent rec_itern(jit_State *J, BCReg ra, BCReg rb)\n{\n#if LJ_BE\n  /* YAGNI: Disabled on big-endian due to issues with lj_vm_next,\n  ** IR_HIOP, RID_RETLO/RID_RETHI and ra_destpair.\n  */\n  UNUSED(ra); UNUSED(rb);\n  setintV(&J->errinfo, (int32_t)BC_ITERN);\n  lj_trace_err_info(J, LJ_TRERR_NYIBC);\n#else\n  RecordIndex ix;\n  /* Since ITERN is recorded at the start, we need our own loop detection. */\n  if (J->pc == J->startpc &&\n      (J->cur.nins > REF_FIRST+1 ||\n       (J->cur.nins == REF_FIRST+1 && J->cur.ir[REF_FIRST].o != IR_PROF)) &&\n      J->framedepth + J->retdepth == 0 && J->parent == 0 && J->exitno == 0) {\n    lj_record_stop(J, LJ_TRLINK_LOOP, J->cur.traceno);  /* Looping trace. */\n    return LOOPEV_ENTER;\n  }\n  J->maxslot = ra;\n  lj_snap_add(J);  /* Required to make JLOOP the first ins in a side-trace. */\n  ix.tab = getslot(J, ra-2);\n  ix.key = J->base[ra-1] ? J->base[ra-1] :\n\t   sloadt(J, (int32_t)(ra-1), IRT_INT, IRSLOAD_KEYINDEX);\n  copyTV(J->L, &ix.tabv, &J->L->base[ra-2]);\n  copyTV(J->L, &ix.keyv, &J->L->base[ra-1]);\n  ix.idxchain = (rb < 3);  /* Omit value type check, if unused. */\n  ix.mobj = 1;  /* We need the next index, too. */\n  J->maxslot = ra + lj_record_next(J, &ix);\n  J->needsnap = 1;\n  if (!tref_isnil(ix.key)) {  /* Looping back? */\n    J->base[ra-1] = ix.mobj | TREF_KEYINDEX;  /* Control var has next index. */\n    J->base[ra] = ix.key;\n    J->base[ra+1] = ix.val;\n    J->pc += bc_j(J->pc[1])+2;\n    return LOOPEV_ENTER;\n  } else {\n    J->maxslot = ra-3;\n    J->pc += 2;\n    return LOOPEV_LEAVE;\n  }\n#endif\n}\n\n/* Record ISNEXT. */\nstatic void rec_isnext(jit_State *J, BCReg ra)\n{\n  cTValue *b = &J->L->base[ra-3];\n  if (tvisfunc(b) && funcV(b)->c.ffid == FF_next &&\n      tvistab(b+1) && tvisnil(b+2)) {\n    /* These checks are folded away for a compiled pairs(). */\n    TRef func = getslot(J, ra-3);\n    TRef trid = emitir(IRT(IR_FLOAD, IRT_U8), func, IRFL_FUNC_FFID);\n    emitir(IRTGI(IR_EQ), trid, lj_ir_kint(J, FF_next));\n    (void)getslot(J, ra-2); /* Type check for table. */\n    (void)getslot(J, ra-1); /* Type check for nil key. */\n    J->base[ra-1] = lj_ir_kint(J, 0) | TREF_KEYINDEX;\n    J->maxslot = ra;\n  } else {  /* Abort trace. Interpreter will despecialize bytecode. */\n    lj_trace_err(J, LJ_TRERR_RECERR);\n  }\n}\n\n/* -- Record profiler hook checks ----------------------------------------- */\n\n#if LJ_HASPROFILE\n\n/* Need to insert profiler hook check? */\nstatic int rec_profile_need(jit_State *J, GCproto *pt, const BCIns *pc)\n{\n  GCproto *ppt;\n  lj_assertJ(J->prof_mode == 'f' || J->prof_mode == 'l',\n\t     \"bad profiler mode %c\", J->prof_mode);\n  if (!pt)\n    return 0;\n  ppt = J->prev_pt;\n  J->prev_pt = pt;\n  if (pt != ppt && ppt) {\n    J->prev_line = -1;\n    return 1;\n  }\n  if (J->prof_mode == 'l') {\n    BCLine line = lj_debug_line(pt, proto_bcpos(pt, pc));\n    BCLine pline = J->prev_line;\n    J->prev_line = line;\n    if (pline != line)\n      return 1;\n  }\n  return 0;\n}\n\nstatic void rec_profile_ins(jit_State *J, const BCIns *pc)\n{\n  if (J->prof_mode && rec_profile_need(J, J->pt, pc)) {\n    emitir(IRTG(IR_PROF, IRT_NIL), 0, 0);\n    lj_snap_add(J);\n  }\n}\n\nstatic void rec_profile_ret(jit_State *J)\n{\n  if (J->prof_mode == 'f') {\n    emitir(IRTG(IR_PROF, IRT_NIL), 0, 0);\n    J->prev_pt = NULL;\n    lj_snap_add(J);\n  }\n}\n\n#endif\n\n/* -- Record calls and returns -------------------------------------------- */\n\n/* Specialize to the runtime value of the called function or its prototype. */\nstatic TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr)\n{\n  TRef kfunc;\n  if (isluafunc(fn)) {\n    GCproto *pt = funcproto(fn);\n    /* Too many closures created? Probably not a monomorphic function. */\n    if (pt->flags >= PROTO_CLC_POLY) {  /* Specialize to prototype instead. */\n      TRef trpt = emitir(IRT(IR_FLOAD, IRT_PGC), tr, IRFL_FUNC_PC);\n      emitir(IRTG(IR_EQ, IRT_PGC), trpt, lj_ir_kptr(J, proto_bc(pt)));\n      (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);  /* Prevent GC of proto. */\n      return tr;\n    }\n  } else {\n    /* Don't specialize to non-monomorphic builtins. */\n    switch (fn->c.ffid) {\n    case FF_coroutine_wrap_aux:\n    case FF_string_gmatch_aux:\n      /* NYI: io_file_iter doesn't have an ffid, yet. */\n      {  /* Specialize to the ffid. */\n\tTRef trid = emitir(IRT(IR_FLOAD, IRT_U8), tr, IRFL_FUNC_FFID);\n\temitir(IRTGI(IR_EQ), trid, lj_ir_kint(J, fn->c.ffid));\n      }\n      return tr;\n    default:\n      /* NYI: don't specialize to non-monomorphic C functions. */\n      break;\n    }\n  }\n  /* Otherwise specialize to the function (closure) value itself. */\n  kfunc = lj_ir_kfunc(J, fn);\n  emitir(IRTG(IR_EQ, IRT_FUNC), tr, kfunc);\n  return kfunc;\n}\n\n/* Record call setup. */\nstatic void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  RecordIndex ix;\n  TValue *functv = &J->L->base[func];\n  TRef kfunc, *fbase = &J->base[func];\n  ptrdiff_t i;\n  (void)getslot(J, func); /* Ensure func has a reference. */\n  for (i = 1; i <= nargs; i++)\n    (void)getslot(J, func+LJ_FR2+i);  /* Ensure all args have a reference. */\n  if (!tref_isfunc(fbase[0])) {  /* Resolve __call metamethod. */\n    ix.tab = fbase[0];\n    copyTV(J->L, &ix.tabv, functv);\n    if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj))\n      lj_trace_err(J, LJ_TRERR_NOMM);\n    for (i = ++nargs; i > LJ_FR2; i--)  /* Shift arguments up. */\n      fbase[i+LJ_FR2] = fbase[i+LJ_FR2-1];\n#if LJ_FR2\n    fbase[2] = fbase[0];\n#endif\n    fbase[0] = ix.mobj;  /* Replace function. */\n    functv = &ix.mobjv;\n  }\n  kfunc = rec_call_specialize(J, funcV(functv), fbase[0]);\n#if LJ_FR2\n  fbase[0] = kfunc;\n  fbase[1] = TREF_FRAME;\n#else\n  fbase[0] = kfunc | TREF_FRAME;\n#endif\n  J->maxslot = (BCReg)nargs;\n}\n\n/* Record call. */\nvoid lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  rec_call_setup(J, func, nargs);\n  /* Bump frame. */\n  J->framedepth++;\n  J->base += func+1+LJ_FR2;\n  J->baseslot += func+1+LJ_FR2;\n  if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n}\n\n/* Record tail call. */\nvoid lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs)\n{\n  rec_call_setup(J, func, nargs);\n  if (frame_isvarg(J->L->base - 1)) {\n    BCReg cbase = (BCReg)frame_delta(J->L->base - 1);\n    if (--J->framedepth < 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    func += cbase;\n  }\n  /* Move func + args down. */\n  if (LJ_FR2 && J->baseslot == 2)\n    J->base[func+1] = TREF_FRAME;\n  memmove(&J->base[-1-LJ_FR2], &J->base[func], sizeof(TRef)*(J->maxslot+1+LJ_FR2));\n  /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */\n  /* Tailcalls can form a loop, so count towards the loop unroll limit. */\n  if (++J->tailcalled > J->loopunroll)\n    lj_trace_err(J, LJ_TRERR_LUNROLL);\n}\n\n/* Check unroll limits for down-recursion. */\nstatic int check_downrec_unroll(jit_State *J, GCproto *pt)\n{\n  IRRef ptref;\n  for (ptref = J->chain[IR_KGC]; ptref; ptref = IR(ptref)->prev)\n    if (ir_kgc(IR(ptref)) == obj2gco(pt)) {\n      int count = 0;\n      IRRef ref;\n      for (ref = J->chain[IR_RETF]; ref; ref = IR(ref)->prev)\n\tif (IR(ref)->op1 == ptref)\n\t  count++;\n      if (count) {\n\tif (J->pc == J->startpc) {\n\t  if (count + J->tailcalled > J->param[JIT_P_recunroll])\n\t    return 1;\n\t} else {\n\t  lj_trace_err(J, LJ_TRERR_DOWNREC);\n\t}\n      }\n    }\n  return 0;\n}\n\nstatic TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot);\n\n/* Record return. */\nvoid lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)\n{\n  TValue *frame = J->L->base - 1;\n  ptrdiff_t i;\n  for (i = 0; i < gotresults; i++)\n    (void)getslot(J, rbase+i);  /* Ensure all results have a reference. */\n  while (frame_ispcall(frame)) {  /* Immediately resolve pcall() returns. */\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if (--J->framedepth <= 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    lj_assertJ(J->baseslot > 1+LJ_FR2, \"bad baseslot for return\");\n    gotresults++;\n    rbase += cbase;\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    J->base[--rbase] = TREF_TRUE;  /* Prepend true to results. */\n    frame = frame_prevd(frame);\n    J->needsnap = 1;  /* Stop catching on-trace errors. */\n  }\n  /* Return to lower frame via interpreter for unhandled cases. */\n  if (J->framedepth == 0 && J->pt && bc_isret(bc_op(*J->pc)) &&\n       (!frame_islua(frame) ||\n\t(J->parent == 0 && J->exitno == 0 &&\n\t !bc_isret(bc_op(J->cur.startins))))) {\n    /* NYI: specialize to frame type and return directly, not via RET*. */\n    for (i = 0; i < (ptrdiff_t)rbase; i++)\n      J->base[i] = 0;  /* Purge dead slots. */\n    J->maxslot = rbase + (BCReg)gotresults;\n    lj_record_stop(J, LJ_TRLINK_RETURN, 0);  /* Return to interpreter. */\n    return;\n  }\n  if (frame_isvarg(frame)) {\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if (--J->framedepth < 0)  /* NYI: return of vararg func to lower frame. */\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    lj_assertJ(J->baseslot > 1+LJ_FR2, \"bad baseslot for return\");\n    rbase += cbase;\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    frame = frame_prevd(frame);\n  }\n  if (frame_islua(frame)) {  /* Return to Lua frame. */\n    BCIns callins = *(frame_pc(frame)-1);\n    ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults;\n    BCReg cbase = bc_a(callins);\n    GCproto *pt = funcproto(frame_func(frame - (cbase+1+LJ_FR2)));\n    if ((pt->flags & PROTO_NOJIT))\n      lj_trace_err(J, LJ_TRERR_CJITOFF);\n    if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) {\n      if (check_downrec_unroll(J, pt)) {\n\tJ->maxslot = (BCReg)(rbase + gotresults);\n\tlj_snap_purge(J);\n\tlj_record_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno);  /* Down-rec. */\n\treturn;\n      }\n      lj_snap_add(J);\n    }\n    for (i = 0; i < nresults; i++)  /* Adjust results. */\n      J->base[i-1-LJ_FR2] = i < gotresults ? J->base[rbase+i] : TREF_NIL;\n    J->maxslot = cbase+(BCReg)nresults;\n    if (J->framedepth > 0) {  /* Return to a frame that is part of the trace. */\n      J->framedepth--;\n      lj_assertJ(J->baseslot > cbase+1+LJ_FR2, \"bad baseslot for return\");\n      J->baseslot -= cbase+1+LJ_FR2;\n      J->base -= cbase+1+LJ_FR2;\n    } else if (J->parent == 0 && J->exitno == 0 &&\n\t       !bc_isret(bc_op(J->cur.startins))) {\n      /* Return to lower frame would leave the loop in a root trace. */\n      lj_trace_err(J, LJ_TRERR_LLEAVE);\n    } else if (J->needsnap) {  /* Tailcalled to ff with side-effects. */\n      lj_trace_err(J, LJ_TRERR_NYIRETL);  /* No way to insert snapshot here. */\n    } else {  /* Return to lower frame. Guard for the target we return to. */\n      TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);\n      TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame));\n      emitir(IRTG(IR_RETF, IRT_PGC), trpt, trpc);\n      J->retdepth++;\n      J->needsnap = 1;\n      lj_assertJ(J->baseslot == 1+LJ_FR2, \"bad baseslot for return\");\n      /* Shift result slots up and clear the slots of the new frame below. */\n      memmove(J->base + cbase, J->base-1-LJ_FR2, sizeof(TRef)*nresults);\n      memset(J->base-1-LJ_FR2, 0, sizeof(TRef)*(cbase+1+LJ_FR2));\n    }\n  } else if (frame_iscont(frame)) {  /* Return to continuation frame. */\n    ASMFunction cont = frame_contf(frame);\n    BCReg cbase = (BCReg)frame_delta(frame);\n    if ((J->framedepth -= 2) < 0)\n      lj_trace_err(J, LJ_TRERR_NYIRETL);\n    J->baseslot -= (BCReg)cbase;\n    J->base -= cbase;\n    J->maxslot = cbase-(2<<LJ_FR2);\n    if (cont == lj_cont_ra) {\n      /* Copy result to destination slot. */\n      BCReg dst = bc_a(*(frame_contpc(frame)-1));\n      J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL;\n      if (dst >= J->maxslot) {\n\tJ->maxslot = dst+1;\n      }\n    } else if (cont == lj_cont_nop) {\n      /* Nothing to do here. */\n    } else if (cont == lj_cont_cat) {\n      BCReg bslot = bc_b(*(frame_contpc(frame)-1));\n      TRef tr = gotresults ? J->base[cbase+rbase] : TREF_NIL;\n      if (bslot != J->maxslot) {  /* Concatenate the remainder. */\n\tTValue *b = J->L->base, save;  /* Simulate lower frame and result. */\n\t/* Can't handle MM_concat + CALLT + fast func side-effects. */\n\tif (J->postproc != LJ_POST_NONE)\n\t  lj_trace_err(J, LJ_TRERR_NYIRETL);\n\tJ->base[J->maxslot] = tr;\n\tcopyTV(J->L, &save, b-(2<<LJ_FR2));\n\tif (gotresults)\n\t  copyTV(J->L, b-(2<<LJ_FR2), b+rbase);\n\telse\n\t  setnilV(b-(2<<LJ_FR2));\n\tJ->L->base = b - cbase;\n\ttr = rec_cat(J, bslot, cbase-(2<<LJ_FR2));\n\tb = J->L->base + cbase;  /* Undo. */\n\tJ->L->base = b;\n\tcopyTV(J->L, b-(2<<LJ_FR2), &save);\n      }\n      if (tr) {  /* Store final result. */\n\tBCReg dst = bc_a(*(frame_contpc(frame)-1));\n\tJ->base[dst] = tr;\n\tif (dst >= J->maxslot) {\n\t  J->maxslot = dst+1;\n\t}\n      }  /* Otherwise continue with another __concat call. */\n    } else {\n      /* Result type already specialized. */\n      lj_assertJ(cont == lj_cont_condf || cont == lj_cont_condt,\n\t\t \"bad continuation type\");\n    }\n  } else {\n    lj_trace_err(J, LJ_TRERR_NYIRETL);  /* NYI: handle return to C frame. */\n  }\n  lj_assertJ(J->baseslot >= 1+LJ_FR2, \"bad baseslot for return\");\n}\n\n/* -- Metamethod handling ------------------------------------------------- */\n\n/* Prepare to record call to metamethod. */\nstatic BCReg rec_mm_prep(jit_State *J, ASMFunction cont)\n{\n  BCReg s, top = cont == lj_cont_cat ? J->maxslot : curr_proto(J->L)->framesize;\n#if LJ_FR2\n  J->base[top] = lj_ir_k64(J, IR_KNUM, u64ptr(contptr(cont)));\n  J->base[top+1] = TREF_CONT;\n#else\n  J->base[top] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT;\n#endif\n  J->framedepth++;\n  for (s = J->maxslot; s < top; s++)\n    J->base[s] = 0;  /* Clear frame gap to avoid resurrecting previous refs. */\n  return top+1+LJ_FR2;\n}\n\n/* Record metamethod lookup. */\nint lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)\n{\n  RecordIndex mix;\n  GCtab *mt;\n  if (tref_istab(ix->tab)) {\n    mt = tabref(tabV(&ix->tabv)->metatable);\n    mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);\n  } else if (tref_isudata(ix->tab)) {\n    int udtype = udataV(&ix->tabv)->udtype;\n    mt = tabref(udataV(&ix->tabv)->metatable);\n    /* The metatables of special userdata objects are treated as immutable. */\n    if (udtype != UDTYPE_USERDATA) {\n      cTValue *mo;\n      if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {\n\t/* Specialize to the C library namespace object. */\n\temitir(IRTG(IR_EQ, IRT_PGC), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv)));\n      } else {\n\t/* Specialize to the type of userdata. */\n\tTRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE);\n\temitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, udtype));\n      }\n  immutable_mt:\n      mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm));\n      if (!mo || tvisnil(mo))\n\treturn 0;  /* No metamethod. */\n      /* Treat metamethod or index table as immutable, too. */\n      if (!(tvisfunc(mo) || tvistab(mo)))\n\tlj_trace_err(J, LJ_TRERR_BADTYPE);\n      copyTV(J->L, &ix->mobjv, mo);\n      ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB);\n      ix->mtv = mt;\n      ix->mt = TREF_NIL;  /* Dummy value for comparison semantics. */\n      return 1;  /* Got metamethod or index table. */\n    }\n    mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META);\n  } else {\n    /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */\n    mt = tabref(basemt_obj(J2G(J), &ix->tabv));\n    if (mt == NULL) {\n      ix->mt = TREF_NIL;\n      return 0;  /* No metamethod. */\n    }\n    /* The cdata metatable is treated as immutable. */\n    if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt;\n    ix->mt = mix.tab = lj_ir_ggfload(J, IRT_TAB,\n      GG_OFS(g.gcroot[GCROOT_BASEMT+itypemap(&ix->tabv)]));\n    goto nocheck;\n  }\n  ix->mt = mt ? mix.tab : TREF_NIL;\n  emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mix.tab, lj_ir_knull(J, IRT_TAB));\nnocheck:\n  if (mt) {\n    GCstr *mmstr = mmname_str(J2G(J), mm);\n    cTValue *mo = lj_tab_getstr(mt, mmstr);\n    if (mo && !tvisnil(mo))\n      copyTV(J->L, &ix->mobjv, mo);\n    ix->mtv = mt;\n    settabV(J->L, &mix.tabv, mt);\n    setstrV(J->L, &mix.keyv, mmstr);\n    mix.key = lj_ir_kstr(J, mmstr);\n    mix.val = 0;\n    mix.idxchain = 0;\n    ix->mobj = lj_record_idx(J, &mix);\n    return !tref_isnil(ix->mobj);  /* 1 if metamethod found, 0 if not. */\n  }\n  return 0;  /* No metamethod. */\n}\n\n/* Record call to arithmetic metamethod. */\nstatic TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm)\n{\n  /* Set up metamethod call first to save ix->tab and ix->tabv. */\n  BCReg func = rec_mm_prep(J, mm == MM_concat ? lj_cont_cat : lj_cont_ra);\n  TRef *base = J->base + func;\n  TValue *basev = J->L->base + func;\n  base[1+LJ_FR2] = ix->tab; base[2+LJ_FR2] = ix->key;\n  copyTV(J->L, basev+1+LJ_FR2, &ix->tabv);\n  copyTV(J->L, basev+2+LJ_FR2, &ix->keyv);\n  if (!lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n    if (mm != MM_unm) {\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, &ix->keyv);\n      if (lj_record_mm_lookup(J, ix, mm))  /* Lookup mm on 2nd operand. */\n\tgoto ok;\n    }\n    lj_trace_err(J, LJ_TRERR_NOMM);\n  }\nok:\n  base[0] = ix->mobj;\n#if LJ_FR2\n  base[1] = 0;\n#endif\n  copyTV(J->L, basev+0, &ix->mobjv);\n  lj_record_call(J, func, 2);\n  return 0;  /* No result yet. */\n}\n\n/* Record call to __len metamethod. */\nstatic TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)\n{\n  RecordIndex ix;\n  ix.tab = tr;\n  copyTV(J->L, &ix.tabv, tv);\n  if (lj_record_mm_lookup(J, &ix, MM_len)) {\n    BCReg func = rec_mm_prep(J, lj_cont_ra);\n    TRef *base = J->base + func;\n    TValue *basev = J->L->base + func;\n    base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv);\n    base += LJ_FR2;\n    basev += LJ_FR2;\n    base[1] = tr; copyTV(J->L, basev+1, tv);\n#if LJ_52\n    base[2] = tr; copyTV(J->L, basev+2, tv);\n#else\n    base[2] = TREF_NIL; setnilV(basev+2);\n#endif\n    lj_record_call(J, func, 2);\n  } else {\n    if (LJ_52 && tref_istab(tr))\n      return emitir(IRTI(IR_ALEN), tr, TREF_NIL);\n    lj_trace_err(J, LJ_TRERR_NOMM);\n  }\n  return 0;  /* No result yet. */\n}\n\n/* Call a comparison metamethod. */\nstatic void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op)\n{\n  BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt);\n  TRef *base = J->base + func + LJ_FR2;\n  TValue *tv = J->L->base + func + LJ_FR2;\n  base[-LJ_FR2] = ix->mobj; base[1] = ix->val; base[2] = ix->key;\n  copyTV(J->L, tv-LJ_FR2, &ix->mobjv);\n  copyTV(J->L, tv+1, &ix->valv);\n  copyTV(J->L, tv+2, &ix->keyv);\n  lj_record_call(J, func, 2);\n}\n\n/* Record call to equality comparison metamethod (for tab and udata only). */\nstatic void rec_mm_equal(jit_State *J, RecordIndex *ix, int op)\n{\n  ix->tab = ix->val;\n  copyTV(J->L, &ix->tabv, &ix->valv);\n  if (lj_record_mm_lookup(J, ix, MM_eq)) {  /* Lookup mm on 1st operand. */\n    cTValue *bv;\n    TRef mo1 = ix->mobj;\n    TValue mo1v;\n    copyTV(J->L, &mo1v, &ix->mobjv);\n    /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */\n    bv = &ix->keyv;\n    if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {\n      TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);\n      emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n    } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {\n      TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);\n      emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n    } else {  /* Lookup metamethod on 2nd operand and compare both. */\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, bv);\n      if (!lj_record_mm_lookup(J, ix, MM_eq) ||\n\t  lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))\n\treturn;\n    }\n    rec_mm_callcomp(J, ix, op);\n  }\n}\n\n/* Record call to ordered comparison metamethods (for arbitrary objects). */\nstatic void rec_mm_comp(jit_State *J, RecordIndex *ix, int op)\n{\n  ix->tab = ix->val;\n  copyTV(J->L, &ix->tabv, &ix->valv);\n  while (1) {\n    MMS mm = (op & 2) ? MM_le : MM_lt;  /* Try __le + __lt or only __lt. */\n#if LJ_52\n    if (!lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n      ix->tab = ix->key;\n      copyTV(J->L, &ix->tabv, &ix->keyv);\n      if (!lj_record_mm_lookup(J, ix, mm))  /* Lookup mm on 2nd operand. */\n\tgoto nomatch;\n    }\n    rec_mm_callcomp(J, ix, op);\n    return;\n#else\n    if (lj_record_mm_lookup(J, ix, mm)) {  /* Lookup mm on 1st operand. */\n      cTValue *bv;\n      TRef mo1 = ix->mobj;\n      TValue mo1v;\n      copyTV(J->L, &mo1v, &ix->mobjv);\n      /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */\n      bv = &ix->keyv;\n      if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {\n\tTRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);\n\temitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n      } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {\n\tTRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);\n\temitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);\n      } else {  /* Lookup metamethod on 2nd operand and compare both. */\n\tix->tab = ix->key;\n\tcopyTV(J->L, &ix->tabv, bv);\n\tif (!lj_record_mm_lookup(J, ix, mm) ||\n\t    lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))\n\t  goto nomatch;\n      }\n      rec_mm_callcomp(J, ix, op);\n      return;\n    }\n#endif\n  nomatch:\n    /* Lookup failed. Retry with  __lt and swapped operands. */\n    if (!(op & 2)) break;  /* Already at __lt. Interpreter will throw. */\n    ix->tab = ix->key; ix->key = ix->val; ix->val = ix->tab;\n    copyTV(J->L, &ix->tabv, &ix->keyv);\n    copyTV(J->L, &ix->keyv, &ix->valv);\n    copyTV(J->L, &ix->valv, &ix->tabv);\n    op ^= 3;\n  }\n}\n\n#if LJ_HASFFI\n/* Setup call to cdata comparison metamethod. */\nstatic void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm)\n{\n  lj_snap_add(J);\n  if (tref_iscdata(ix->val)) {\n    ix->tab = ix->val;\n    copyTV(J->L, &ix->tabv, &ix->valv);\n  } else {\n    lj_assertJ(tref_iscdata(ix->key), \"cdata expected\");\n    ix->tab = ix->key;\n    copyTV(J->L, &ix->tabv, &ix->keyv);\n  }\n  lj_record_mm_lookup(J, ix, mm);\n  rec_mm_callcomp(J, ix, op);\n}\n#endif\n\n/* -- Indexed access ------------------------------------------------------ */\n\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n/* Bump table allocations in bytecode when they grow during recording. */\nstatic void rec_idx_bump(jit_State *J, RecordIndex *ix)\n{\n  RBCHashEntry *rbc = &J->rbchash[(ix->tab & (RBCHASH_SLOTS-1))];\n  if (tref_ref(ix->tab) == rbc->ref) {\n    const BCIns *pc = mref(rbc->pc, const BCIns);\n    GCtab *tb = tabV(&ix->tabv);\n    uint32_t nhbits;\n    IRIns *ir;\n    if (!tvisnil(&ix->keyv))\n      (void)lj_tab_set(J->L, tb, &ix->keyv);  /* Grow table right now. */\n    nhbits = tb->hmask > 0 ? lj_fls(tb->hmask)+1 : 0;\n    ir = IR(tref_ref(ix->tab));\n    if (ir->o == IR_TNEW) {\n      uint32_t ah = bc_d(*pc);\n      uint32_t asize = ah & 0x7ff, hbits = ah >> 11;\n      if (nhbits > hbits) hbits = nhbits;\n      if (tb->asize > asize) {\n\tasize = tb->asize <= 0x7ff ? tb->asize : 0x7ff;\n      }\n      if ((asize | (hbits<<11)) != ah) {  /* Has the size changed? */\n\t/* Patch bytecode, but continue recording (for more patching). */\n\tsetbc_d(pc, (asize | (hbits<<11)));\n\t/* Patching TNEW operands is only safe if the trace is aborted. */\n\tir->op1 = asize; ir->op2 = hbits;\n\tJ->retryrec = 1;  /* Abort the trace at the end of recording. */\n      }\n    } else if (ir->o == IR_TDUP) {\n      GCtab *tpl = gco2tab(proto_kgc(&gcref(rbc->pt)->pt, ~(ptrdiff_t)bc_d(*pc)));\n      /* Grow template table, but preserve keys with nil values. */\n      if ((tb->asize > tpl->asize && (1u << nhbits)-1 == tpl->hmask) ||\n\t  (tb->asize == tpl->asize && (1u << nhbits)-1 > tpl->hmask)) {\n\tNode *node = noderef(tpl->node);\n\tuint32_t i, hmask = tpl->hmask, asize;\n\tTValue *array;\n\tfor (i = 0; i <= hmask; i++) {\n\t  if (!tvisnil(&node[i].key) && tvisnil(&node[i].val))\n\t    settabV(J->L, &node[i].val, tpl);\n\t}\n\tif (!tvisnil(&ix->keyv) && tref_isk(ix->key)) {\n\t  TValue *o = lj_tab_set(J->L, tpl, &ix->keyv);\n\t  if (tvisnil(o)) settabV(J->L, o, tpl);\n\t}\n\tlj_tab_resize(J->L, tpl, tb->asize, nhbits);\n\tnode = noderef(tpl->node);\n\thmask = tpl->hmask;\n\tfor (i = 0; i <= hmask; i++) {\n\t  /* This is safe, since template tables only hold immutable values. */\n\t  if (tvistab(&node[i].val))\n\t    setnilV(&node[i].val);\n\t}\n\t/* The shape of the table may have changed. Clean up array part, too. */\n\tasize = tpl->asize;\n\tarray = tvref(tpl->array);\n\tfor (i = 0; i < asize; i++) {\n\t  if (tvistab(&array[i]))\n\t    setnilV(&array[i]);\n\t}\n\tJ->retryrec = 1;  /* Abort the trace at the end of recording. */\n      }\n    }\n  }\n}\n#endif\n\n/* Record bounds-check. */\nstatic void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize)\n{\n  /* Try to emit invariant bounds checks. */\n  if ((J->flags & (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) ==\n      (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) {\n    IRRef ref = tref_ref(ikey);\n    IRIns *ir = IR(ref);\n    int32_t ofs = 0;\n    IRRef ofsref = 0;\n    /* Handle constant offsets. */\n    if (ir->o == IR_ADD && irref_isk(ir->op2)) {\n      ofsref = ir->op2;\n      ofs = IR(ofsref)->i;\n      ref = ir->op1;\n      ir = IR(ref);\n    }\n    /* Got scalar evolution analysis results for this reference? */\n    if (ref == J->scev.idx) {\n      int32_t stop;\n      lj_assertJ(irt_isint(J->scev.t) && ir->o == IR_SLOAD,\n\t\t \"only int SCEV supported\");\n      stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]);\n      /* Runtime value for stop of loop is within bounds? */\n      if ((uint64_t)stop + ofs < (uint64_t)asize) {\n\t/* Emit invariant bounds check for stop. */\n\temitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop :\n\t       emitir(IRTI(IR_ADD), J->scev.stop, ofsref));\n\t/* Emit invariant bounds check for start, if not const or negative. */\n\tif (!(J->scev.dir && J->scev.start &&\n\t      (int64_t)IR(J->scev.start)->i + ofs >= 0))\n\t  emitir(IRTG(IR_ABC, IRT_P32), asizeref, ikey);\n\treturn;\n      }\n    }\n  }\n  emitir(IRTGI(IR_ABC), asizeref, ikey);  /* Emit regular bounds check. */\n}\n\n/* Record indexed key lookup. */\nstatic TRef rec_idx_key(jit_State *J, RecordIndex *ix, IRRef *rbref,\n\t\t\tIRType1 *rbguard)\n{\n  TRef key;\n  GCtab *t = tabV(&ix->tabv);\n  ix->oldv = lj_tab_get(J->L, t, &ix->keyv);  /* Lookup previous value. */\n  *rbref = 0;\n  rbguard->irt = 0;\n\n  /* Integer keys are looked up in the array part first. */\n  key = ix->key;\n  if (tref_isnumber(key)) {\n    int32_t k = numberVint(&ix->keyv);\n    if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k)\n      k = LJ_MAX_ASIZE;\n    if ((MSize)k < LJ_MAX_ASIZE) {  /* Potential array key? */\n      TRef ikey = lj_opt_narrow_index(J, key);\n      TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);\n      if ((MSize)k < t->asize) {  /* Currently an array key? */\n\tTRef arrayref;\n\trec_idx_abc(J, asizeref, ikey, t->asize);\n\tarrayref = emitir(IRT(IR_FLOAD, IRT_PGC), ix->tab, IRFL_TAB_ARRAY);\n\treturn emitir(IRT(IR_AREF, IRT_PGC), arrayref, ikey);\n      } else {  /* Currently not in array (may be an array extension)? */\n\temitir(IRTGI(IR_ULE), asizeref, ikey);  /* Inv. bounds check. */\n\tif (k == 0 && tref_isk(key))\n\t  key = lj_ir_knum_zero(J);  /* Canonicalize 0 or +-0.0 to +0.0. */\n\t/* And continue with the hash lookup. */\n      }\n    } else if (!tref_isk(key)) {\n      /* We can rule out const numbers which failed the integerness test\n      ** above. But all other numbers are potential array keys.\n      */\n      if (t->asize == 0) {  /* True sparse tables have an empty array part. */\n\t/* Guard that the array part stays empty. */\n\tTRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);\n\temitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));\n      } else {\n\tlj_trace_err(J, LJ_TRERR_NYITMIX);\n      }\n    }\n  }\n\n  /* Otherwise the key is located in the hash part. */\n  if (t->hmask == 0) {  /* Shortcut for empty hash part. */\n    /* Guard that the hash part stays empty. */\n    TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);\n    emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));\n    return lj_ir_kkptr(J, niltvg(J2G(J)));\n  }\n  if (tref_isinteger(key))  /* Hash keys are based on numbers, not ints. */\n    key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);\n  if (tref_isk(key)) {\n    /* Optimize lookup of constant hash keys. */\n    MSize hslot = (MSize)((char *)ix->oldv - (char *)&noderef(t->node)[0].val);\n    if (t->hmask > 0 && hslot <= t->hmask*(MSize)sizeof(Node) &&\n\thslot <= 65535*(MSize)sizeof(Node)) {\n      TRef node, kslot, hm;\n      *rbref = J->cur.nins;  /* Mark possible rollback point. */\n      *rbguard = J->guardemit;\n      hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);\n      emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask));\n      node = emitir(IRT(IR_FLOAD, IRT_PGC), ix->tab, IRFL_TAB_NODE);\n      kslot = lj_ir_kslot(J, key, hslot / sizeof(Node));\n      return emitir(IRTG(IR_HREFK, IRT_PGC), node, kslot);\n    }\n  }\n  /* Fall back to a regular hash lookup. */\n  return emitir(IRT(IR_HREF, IRT_PGC), ix->tab, key);\n}\n\n/* Determine whether a key is NOT one of the fast metamethod names. */\nstatic int nommstr(jit_State *J, TRef key)\n{\n  if (tref_isstr(key)) {\n    if (tref_isk(key)) {\n      GCstr *str = ir_kstr(IR(tref_ref(key)));\n      uint32_t mm;\n      for (mm = 0; mm <= MM_FAST; mm++)\n\tif (mmname_str(J2G(J), mm) == str)\n\t  return 0;  /* MUST be one the fast metamethod names. */\n    } else {\n      return 0;  /* Variable string key MAY be a metamethod name. */\n    }\n  }\n  return 1;  /* CANNOT be a metamethod name. */\n}\n\n/* Record indexed load/store. */\nTRef lj_record_idx(jit_State *J, RecordIndex *ix)\n{\n  TRef xref;\n  IROp xrefop, loadop;\n  IRRef rbref;\n  IRType1 rbguard;\n  cTValue *oldv;\n\n  while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */\n    /* Never call raw lj_record_idx() on non-table. */\n    lj_assertJ(ix->idxchain != 0, \"bad usage\");\n    if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index))\n      lj_trace_err(J, LJ_TRERR_NOMM);\n  handlemm:\n    if (tref_isfunc(ix->mobj)) {  /* Handle metamethod call. */\n      BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra);\n      TRef *base = J->base + func + LJ_FR2;\n      TValue *tv = J->L->base + func + LJ_FR2;\n      base[-LJ_FR2] = ix->mobj; base[1] = ix->tab; base[2] = ix->key;\n      setfuncV(J->L, tv-LJ_FR2, funcV(&ix->mobjv));\n      copyTV(J->L, tv+1, &ix->tabv);\n      copyTV(J->L, tv+2, &ix->keyv);\n      if (ix->val) {\n\tbase[3] = ix->val;\n\tcopyTV(J->L, tv+3, &ix->valv);\n\tlj_record_call(J, func, 3);  /* mobj(tab, key, val) */\n\treturn 0;\n      } else {\n\tlj_record_call(J, func, 2);  /* res = mobj(tab, key) */\n\treturn 0;  /* No result yet. */\n      }\n    }\n#if LJ_HASBUFFER\n    /* The index table of buffer objects is treated as immutable. */\n    if (ix->mt == TREF_NIL && !ix->val &&\n\ttref_isudata(ix->tab) && udataV(&ix->tabv)->udtype == UDTYPE_BUFFER &&\n\ttref_istab(ix->mobj) && tref_isstr(ix->key) && tref_isk(ix->key)) {\n      cTValue *val = lj_tab_getstr(tabV(&ix->mobjv), strV(&ix->keyv));\n      TRef tr = lj_record_constify(J, val);\n      if (tr) return tr;  /* Specialize to the value, i.e. a method. */\n    }\n#endif\n    /* Otherwise retry lookup with metaobject. */\n    ix->tab = ix->mobj;\n    copyTV(J->L, &ix->tabv, &ix->mobjv);\n    if (--ix->idxchain == 0)\n      lj_trace_err(J, LJ_TRERR_IDXLOOP);\n  }\n\n  /* First catch nil and NaN keys for tables. */\n  if (tvisnil(&ix->keyv) || (tvisnum(&ix->keyv) && tvisnan(&ix->keyv))) {\n    if (ix->val)  /* Better fail early. */\n      lj_trace_err(J, LJ_TRERR_STORENN);\n    if (tref_isk(ix->key)) {\n      if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))\n\tgoto handlemm;\n      return TREF_NIL;\n    }\n  }\n\n  /* Record the key lookup. */\n  xref = rec_idx_key(J, ix, &rbref, &rbguard);\n  xrefop = IR(tref_ref(xref))->o;\n  loadop = xrefop == IR_AREF ? IR_ALOAD : IR_HLOAD;\n  /* The lj_meta_tset() inconsistency is gone, but better play safe. */\n  oldv = xrefop == IR_KKPTR ? (cTValue *)ir_kptr(IR(tref_ref(xref))) : ix->oldv;\n\n  if (ix->val == 0) {  /* Indexed load */\n    IRType t = itype2irt(oldv);\n    TRef res;\n    if (oldv == niltvg(J2G(J))) {\n      emitir(IRTG(IR_EQ, IRT_PGC), xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      res = TREF_NIL;\n    } else {\n      res = emitir(IRTG(loadop, t), xref, 0);\n    }\n    if (tref_ref(res) < rbref) {  /* HREFK + load forwarded? */\n      lj_ir_rollback(J, rbref);  /* Rollback to eliminate hmask guard. */\n      J->guardemit = rbguard;\n    }\n    if (t == IRT_NIL && ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))\n      goto handlemm;\n    if (irtype_ispri(t)) res = TREF_PRI(t);  /* Canonicalize primitives. */\n    return res;\n  } else {  /* Indexed store. */\n    GCtab *mt = tabref(tabV(&ix->tabv)->metatable);\n    int keybarrier = tref_isgcv(ix->key) && !tref_isnil(ix->val);\n    if (tref_ref(xref) < rbref) {  /* HREFK forwarded? */\n      lj_ir_rollback(J, rbref);  /* Rollback to eliminate hmask guard. */\n      J->guardemit = rbguard;\n    }\n    if (tvisnil(oldv)) {  /* Previous value was nil? */\n      /* Need to duplicate the hasmm check for the early guards. */\n      int hasmm = 0;\n      if (ix->idxchain && mt) {\n\tcTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), MM_newindex));\n\thasmm = mo && !tvisnil(mo);\n      }\n      if (hasmm)\n\temitir(IRTG(loadop, IRT_NIL), xref, 0);  /* Guard for nil value. */\n      else if (xrefop == IR_HREF)\n\temitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_PGC),\n\t       xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {\n\tlj_assertJ(hasmm, \"inconsistent metamethod handling\");\n\tgoto handlemm;\n      }\n      lj_assertJ(!hasmm, \"inconsistent metamethod handling\");\n      if (oldv == niltvg(J2G(J))) {  /* Need to insert a new key. */\n\tTRef key = ix->key;\n\tif (tref_isinteger(key))  /* NEWREF needs a TValue as a key. */\n\t  key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);\n\txref = emitir(IRT(IR_NEWREF, IRT_PGC), ix->tab, key);\n\tkeybarrier = 0;  /* NEWREF already takes care of the key barrier. */\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n\tif ((J->flags & JIT_F_OPT_SINK))  /* Avoid a separate flag. */\n\t  rec_idx_bump(J, ix);\n#endif\n      }\n    } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) {\n      /* Cannot derive that the previous value was non-nil, must do checks. */\n      if (xrefop == IR_HREF)  /* Guard against store to niltv. */\n\temitir(IRTG(IR_NE, IRT_PGC), xref, lj_ir_kkptr(J, niltvg(J2G(J))));\n      if (ix->idxchain) {  /* Metamethod lookup required? */\n\t/* A check for NULL metatable is cheaper (hoistable) than a load. */\n\tif (!mt) {\n\t  TRef mtref = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);\n\t  emitir(IRTG(IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB));\n\t} else {\n\t  IRType t = itype2irt(oldv);\n\t  emitir(IRTG(loadop, t), xref, 0);  /* Guard for non-nil value. */\n\t}\n      }\n    } else {\n      keybarrier = 0;  /* Previous non-nil value kept the key alive. */\n    }\n    /* Convert int to number before storing. */\n    if (!LJ_DUALNUM && tref_isinteger(ix->val))\n      ix->val = emitir(IRTN(IR_CONV), ix->val, IRCONV_NUM_INT);\n    emitir(IRT(loadop+IRDELTA_L2S, tref_type(ix->val)), xref, ix->val);\n    if (keybarrier || tref_isgcv(ix->val))\n      emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0);\n    /* Invalidate neg. metamethod cache for stores with certain string keys. */\n    if (!nommstr(J, ix->key)) {\n      TRef fref = emitir(IRT(IR_FREF, IRT_PGC), ix->tab, IRFL_TAB_NOMM);\n      emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0));\n    }\n    J->needsnap = 1;\n    return 0;\n  }\n}\n\n/* Determine result type of table traversal. */\nstatic IRType rec_next_types(GCtab *t, uint32_t idx)\n{\n  for (; idx < t->asize; idx++) {\n    cTValue *a = arrayslot(t, idx);\n    if (LJ_LIKELY(!tvisnil(a)))\n      return (LJ_DUALNUM ? IRT_INT : IRT_NUM) + (itype2irt(a) << 8);\n  }\n  idx -= t->asize;\n  for (; idx <= t->hmask; idx++) {\n    Node *n = &noderef(t->node)[idx];\n    if (!tvisnil(&n->val))\n      return itype2irt(&n->key) + (itype2irt(&n->val) << 8);\n  }\n  return IRT_NIL + (IRT_NIL << 8);\n}\n\n/* Record a table traversal step aka next(). */\nint lj_record_next(jit_State *J, RecordIndex *ix)\n{\n  IRType t, tkey, tval;\n  TRef trvk;\n  t = rec_next_types(tabV(&ix->tabv), ix->keyv.u32.lo);\n  tkey = (t & 0xff); tval = (t >> 8);\n  trvk = lj_ir_call(J, IRCALL_lj_vm_next, ix->tab, ix->key);\n  if (ix->mobj || tkey == IRT_NIL) {\n    TRef idx = emitir(IRTI(IR_HIOP), trvk, trvk);\n    /* Always check for invalid key from next() for nil result. */\n    if (!ix->mobj) emitir(IRTGI(IR_NE), idx, lj_ir_kint(J, -1));\n    ix->mobj = idx;\n  }\n  ix->key = lj_record_vload(J, trvk, 1, tkey);\n  if (tkey == IRT_NIL || ix->idxchain) {  /* Omit value type check. */\n    ix->val = TREF_NIL;\n    return 1;\n  } else {  /* Need value. */\n    ix->val = lj_record_vload(J, trvk, 0, tval);\n    return 2;\n  }\n}\n\nstatic void rec_tsetm(jit_State *J, BCReg ra, BCReg rn, int32_t i)\n{\n  RecordIndex ix;\n  cTValue *basev = J->L->base;\n  GCtab *t = tabV(&basev[ra-1]);\n  settabV(J->L, &ix.tabv, t);\n  ix.tab = getslot(J, ra-1);\n  ix.idxchain = 0;\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  if ((J->flags & JIT_F_OPT_SINK)) {\n    if (t->asize < i+rn-ra)\n      lj_tab_reasize(J->L, t, i+rn-ra);\n    setnilV(&ix.keyv);\n    rec_idx_bump(J, &ix);\n  }\n#endif\n  for (; ra < rn; i++, ra++) {\n    setintV(&ix.keyv, i);\n    ix.key = lj_ir_kint(J, i);\n    copyTV(J->L, &ix.valv, &basev[ra]);\n    ix.val = getslot(J, ra);\n    lj_record_idx(J, &ix);\n  }\n}\n\n/* -- Upvalue access ------------------------------------------------------ */\n\n/* Check whether upvalue is immutable and ok to constify. */\nstatic int rec_upvalue_constify(jit_State *J, GCupval *uvp)\n{\n  if (uvp->immutable) {\n    cTValue *o = uvval(uvp);\n    /* Don't constify objects that may retain large amounts of memory. */\n#if LJ_HASFFI\n    if (tviscdata(o)) {\n      GCcdata *cd = cdataV(o);\n      if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) {\n\tCType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid);\n\tif (!ctype_hassize(ct->info) || ct->size <= 16)\n\t  return 1;\n      }\n      return 0;\n    }\n#else\n    UNUSED(J);\n#endif\n    if (!(tvistab(o) || tvisudata(o) || tvisthread(o)))\n      return 1;\n  }\n  return 0;\n}\n\n/* Record upvalue load/store. */\nstatic TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)\n{\n  GCupval *uvp = &gcref(J->fn->l.uvptr[uv])->uv;\n  TRef fn = getcurrf(J);\n  IRRef uref;\n  int needbarrier = 0;\n  if (rec_upvalue_constify(J, uvp)) {  /* Try to constify immutable upvalue. */\n    TRef tr, kfunc;\n    lj_assertJ(val == 0, \"bad usage\");\n    if (!tref_isk(fn)) {  /* Late specialization of current function. */\n      if (J->pt->flags >= PROTO_CLC_POLY)\n\tgoto noconstify;\n      kfunc = lj_ir_kfunc(J, J->fn);\n      emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc);\n#if LJ_FR2\n      J->base[-2] = kfunc;\n#else\n      J->base[-1] = kfunc | TREF_FRAME;\n#endif\n      fn = kfunc;\n    }\n    tr = lj_record_constify(J, uvval(uvp));\n    if (tr)\n      return tr;\n  }\nnoconstify:\n  /* Note: this effectively limits LJ_MAX_UPVAL to 127. */\n  uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff);\n  if (!uvp->closed) {\n    uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_PGC), fn, uv));\n    /* In current stack? */\n    if (uvval(uvp) >= tvref(J->L->stack) &&\n\tuvval(uvp) < tvref(J->L->maxstack)) {\n      int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));\n      if (slot >= 0) {  /* Aliases an SSA slot? */\n\temitir(IRTG(IR_EQ, IRT_PGC),\n\t       REF_BASE,\n\t       emitir(IRT(IR_ADD, IRT_PGC), uref,\n\t\t      lj_ir_kint(J, (slot - 1 - LJ_FR2) * -8)));\n\tslot -= (int32_t)J->baseslot;  /* Note: slot number may be negative! */\n\tif (val == 0) {\n\t  return getslot(J, slot);\n\t} else {\n\t  J->base[slot] = val;\n\t  if (slot >= (int32_t)J->maxslot) J->maxslot = (BCReg)(slot+1);\n\t  return 0;\n\t}\n      }\n    }\n    emitir(IRTG(IR_UGT, IRT_PGC),\n\t   emitir(IRT(IR_SUB, IRT_PGC), uref, REF_BASE),\n\t   lj_ir_kint(J, (J->baseslot + J->maxslot) * 8));\n  } else {\n    needbarrier = 1;\n    uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_PGC), fn, uv));\n  }\n  if (val == 0) {  /* Upvalue load */\n    IRType t = itype2irt(uvval(uvp));\n    TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0);\n    if (irtype_ispri(t)) res = TREF_PRI(t);  /* Canonicalize primitive refs. */\n    return res;\n  } else {  /* Upvalue store. */\n    /* Convert int to number before storing. */\n    if (!LJ_DUALNUM && tref_isinteger(val))\n      val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);\n    emitir(IRT(IR_USTORE, tref_type(val)), uref, val);\n    if (needbarrier && tref_isgcv(val))\n      emitir(IRT(IR_OBAR, IRT_NIL), uref, val);\n    J->needsnap = 1;\n    return 0;\n  }\n}\n\n/* -- Record calls to Lua functions --------------------------------------- */\n\n/* Check unroll limits for calls. */\nstatic void check_call_unroll(jit_State *J, TraceNo lnk)\n{\n  cTValue *frame = J->L->base - 1;\n  void *pc = mref(frame_func(frame)->l.pc, void);\n  int32_t depth = J->framedepth;\n  int32_t count = 0;\n  if ((J->pt->flags & PROTO_VARARG)) depth--;  /* Vararg frame still missing. */\n  for (; depth > 0; depth--) {  /* Count frames with same prototype. */\n    if (frame_iscont(frame)) depth--;\n    frame = frame_prev(frame);\n    if (mref(frame_func(frame)->l.pc, void) == pc)\n      count++;\n  }\n  if (J->pc == J->startpc) {\n    if (count + J->tailcalled > J->param[JIT_P_recunroll]) {\n      J->pc++;\n      if (J->framedepth + J->retdepth == 0)\n\tlj_record_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno);  /* Tail-rec. */\n      else\n\tlj_record_stop(J, LJ_TRLINK_UPREC, J->cur.traceno);  /* Up-recursion. */\n    }\n  } else {\n    if (count > J->param[JIT_P_callunroll]) {\n      if (lnk) {  /* Possible tail- or up-recursion. */\n\tlj_trace_flush(J, lnk);  /* Flush trace that only returns. */\n\t/* Set a small, pseudo-random hotcount for a quick retry of JFUNC*. */\n\thotcount_set(J2GG(J), J->pc+1, lj_prng_u64(&J2G(J)->prng) & 15u);\n      }\n      lj_trace_err(J, LJ_TRERR_CUNROLL);\n    }\n  }\n}\n\n/* Record Lua function setup. */\nstatic void rec_func_setup(jit_State *J)\n{\n  GCproto *pt = J->pt;\n  BCReg s, numparams = pt->numparams;\n  if ((pt->flags & PROTO_NOJIT))\n    lj_trace_err(J, LJ_TRERR_CJITOFF);\n  if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n  /* Fill up missing parameters with nil. */\n  for (s = J->maxslot; s < numparams; s++)\n    J->base[s] = TREF_NIL;\n  /* The remaining slots should never be read before they are written. */\n  J->maxslot = numparams;\n}\n\n/* Record Lua vararg function setup. */\nstatic void rec_func_vararg(jit_State *J)\n{\n  GCproto *pt = J->pt;\n  BCReg s, fixargs, vframe = J->maxslot+1+LJ_FR2;\n  lj_assertJ((pt->flags & PROTO_VARARG), \"FUNCV in non-vararg function\");\n  if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n  J->base[vframe-1-LJ_FR2] = J->base[-1-LJ_FR2];  /* Copy function up. */\n#if LJ_FR2\n  J->base[vframe-1] = TREF_FRAME;\n#endif\n  /* Copy fixarg slots up and set their original slots to nil. */\n  fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot;\n  for (s = 0; s < fixargs; s++) {\n    J->base[vframe+s] = J->base[s];\n    J->base[s] = TREF_NIL;\n  }\n  J->maxslot = fixargs;\n  J->framedepth++;\n  J->base += vframe;\n  J->baseslot += vframe;\n}\n\n/* Record entry to a Lua function. */\nstatic void rec_func_lua(jit_State *J)\n{\n  rec_func_setup(J);\n  check_call_unroll(J, 0);\n}\n\n/* Record entry to an already compiled function. */\nstatic void rec_func_jit(jit_State *J, TraceNo lnk)\n{\n  GCtrace *T;\n  rec_func_setup(J);\n  T = traceref(J, lnk);\n  if (T->linktype == LJ_TRLINK_RETURN) {  /* Trace returns to interpreter? */\n    check_call_unroll(J, lnk);\n    /* Temporarily unpatch JFUNC* to continue recording across function. */\n    J->patchins = *J->pc;\n    J->patchpc = (BCIns *)J->pc;\n    *J->patchpc = T->startins;\n    return;\n  }\n  J->instunroll = 0;  /* Cannot continue across a compiled function. */\n  if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)\n    lj_record_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno);  /* Extra tail-rec. */\n  else\n    lj_record_stop(J, LJ_TRLINK_ROOT, lnk);  /* Link to the function. */\n}\n\n/* -- Vararg handling ----------------------------------------------------- */\n\n/* Detect y = select(x, ...) idiom. */\nstatic int select_detect(jit_State *J)\n{\n  BCIns ins = J->pc[1];\n  if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) {\n    cTValue *func = &J->L->base[bc_a(ins)];\n    if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) {\n      TRef kfunc = lj_ir_kfunc(J, funcV(func));\n      emitir(IRTG(IR_EQ, IRT_FUNC), getslot(J, bc_a(ins)), kfunc);\n      return 1;\n    }\n  }\n  return 0;\n}\n\n/* Record vararg instruction. */\nstatic void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)\n{\n  int32_t numparams = J->pt->numparams;\n  ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1 - LJ_FR2;\n  lj_assertJ(frame_isvarg(J->L->base-1), \"VARG in non-vararg frame\");\n  if (LJ_FR2 && dst > J->maxslot)\n    J->base[dst-1] = 0;  /* Prevent resurrection of unrelated slot. */\n  if (J->framedepth > 0) {  /* Simple case: varargs defined on-trace. */\n    ptrdiff_t i;\n    if (nvararg < 0) nvararg = 0;\n    if (nresults == -1) {\n      nresults = nvararg;\n      J->maxslot = dst + (BCReg)nvararg;\n    } else if (dst + nresults > J->maxslot) {\n      J->maxslot = dst + (BCReg)nresults;\n    }\n    for (i = 0; i < nresults; i++)\n      J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1 - LJ_FR2) : TREF_NIL;\n  } else {  /* Unknown number of varargs passed to trace. */\n    TRef fr = emitir(IRTI(IR_SLOAD), LJ_FR2, IRSLOAD_READONLY|IRSLOAD_FRAME);\n    int32_t frofs = 8*(1+LJ_FR2+numparams)+FRAME_VARG;\n    if (nresults >= 0) {  /* Known fixed number of results. */\n      ptrdiff_t i;\n      if (nvararg > 0) {\n\tptrdiff_t nload = nvararg >= nresults ? nresults : nvararg;\n\tTRef vbase;\n\tif (nvararg >= nresults)\n\t  emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults));\n\telse\n\t  emitir(IRTGI(IR_EQ), fr,\n\t\t lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1)));\n\tvbase = emitir(IRT(IR_SUB, IRT_IGC), REF_BASE, fr);\n\tvbase = emitir(IRT(IR_ADD, IRT_PGC), vbase, lj_ir_kint(J, frofs-8));\n\tfor (i = 0; i < nload; i++) {\n\t  IRType t = itype2irt(&J->L->base[i-1-LJ_FR2-nvararg]);\n\t  J->base[dst+i] = lj_record_vload(J, vbase, i, t);\n\t}\n      } else {\n\temitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs));\n\tnvararg = 0;\n      }\n      for (i = nvararg; i < nresults; i++)\n\tJ->base[dst+i] = TREF_NIL;\n      if (dst + (BCReg)nresults > J->maxslot)\n\tJ->maxslot = dst + (BCReg)nresults;\n    } else if (select_detect(J)) {  /* y = select(x, ...) */\n      TRef tridx = J->base[dst-1];\n      TRef tr = TREF_NIL;\n      ptrdiff_t idx = lj_ffrecord_select_mode(J, tridx, &J->L->base[dst-1]);\n      if (idx < 0) goto nyivarg;\n      if (idx != 0 && !tref_isinteger(tridx))\n\ttridx = emitir(IRTGI(IR_CONV), tridx, IRCONV_INT_NUM|IRCONV_INDEX);\n      if (idx != 0 && tref_isk(tridx)) {\n\temitir(IRTGI(idx <= nvararg ? IR_GE : IR_LT),\n\t       fr, lj_ir_kint(J, frofs+8*(int32_t)idx));\n\tfrofs -= 8;  /* Bias for 1-based index. */\n      } else if (idx <= nvararg) {  /* Compute size. */\n\tTRef tmp = emitir(IRTI(IR_ADD), fr, lj_ir_kint(J, -frofs));\n\tif (numparams)\n\t  emitir(IRTGI(IR_GE), tmp, lj_ir_kint(J, 0));\n\ttr = emitir(IRTI(IR_BSHR), tmp, lj_ir_kint(J, 3));\n\tif (idx != 0) {\n\t  tridx = emitir(IRTI(IR_ADD), tridx, lj_ir_kint(J, -1));\n\t  rec_idx_abc(J, tr, tridx, (uint32_t)nvararg);\n\t}\n      } else {\n\tTRef tmp = lj_ir_kint(J, frofs);\n\tif (idx != 0) {\n\t  TRef tmp2 = emitir(IRTI(IR_BSHL), tridx, lj_ir_kint(J, 3));\n\t  tmp = emitir(IRTI(IR_ADD), tmp2, tmp);\n\t} else {\n\t  tr = lj_ir_kint(J, 0);\n\t}\n\temitir(IRTGI(IR_LT), fr, tmp);\n      }\n      if (idx != 0 && idx <= nvararg) {\n\tIRType t;\n\tTRef aref, vbase = emitir(IRT(IR_SUB, IRT_IGC), REF_BASE, fr);\n\tvbase = emitir(IRT(IR_ADD, IRT_PGC), vbase,\n\t\t       lj_ir_kint(J, frofs-(8<<LJ_FR2)));\n\tt = itype2irt(&J->L->base[idx-2-LJ_FR2-nvararg]);\n\taref = emitir(IRT(IR_AREF, IRT_PGC), vbase, tridx);\n\ttr = lj_record_vload(J, aref, 0, t);\n      }\n      J->base[dst-2-LJ_FR2] = tr;\n      J->maxslot = dst-1-LJ_FR2;\n      J->bcskip = 2;  /* Skip CALLM + select. */\n    } else {\n    nyivarg:\n      setintV(&J->errinfo, BC_VARG);\n      lj_trace_err_info(J, LJ_TRERR_NYIBC);\n    }\n  }\n  if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS)\n    lj_trace_err(J, LJ_TRERR_STACKOV);\n}\n\n/* -- Record allocations -------------------------------------------------- */\n\nstatic TRef rec_tnew(jit_State *J, uint32_t ah)\n{\n  uint32_t asize = ah & 0x7ff;\n  uint32_t hbits = ah >> 11;\n  TRef tr;\n  if (asize == 0x7ff) asize = 0x801;\n  tr = emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits);\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  J->rbchash[(tr & (RBCHASH_SLOTS-1))].ref = tref_ref(tr);\n  setmref(J->rbchash[(tr & (RBCHASH_SLOTS-1))].pc, J->pc);\n  setgcref(J->rbchash[(tr & (RBCHASH_SLOTS-1))].pt, obj2gco(J->pt));\n#endif\n  return tr;\n}\n\n/* -- Concatenation ------------------------------------------------------- */\n\nstatic TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)\n{\n  TRef *top = &J->base[topslot];\n  TValue savetv[5];\n  BCReg s;\n  RecordIndex ix;\n  lj_assertJ(baseslot < topslot, \"bad CAT arg\");\n  for (s = baseslot; s <= topslot; s++)\n    (void)getslot(J, s);  /* Ensure all arguments have a reference. */\n  if (tref_isnumber_str(top[0]) && tref_isnumber_str(top[-1])) {\n    TRef tr, hdr, *trp, *xbase, *base = &J->base[baseslot];\n    /* First convert numbers to strings. */\n    for (trp = top; trp >= base; trp--) {\n      if (tref_isnumber(*trp))\n\t*trp = emitir(IRT(IR_TOSTR, IRT_STR), *trp,\n\t\t      tref_isnum(*trp) ? IRTOSTR_NUM : IRTOSTR_INT);\n      else if (!tref_isstr(*trp))\n\tbreak;\n    }\n    xbase = ++trp;\n    tr = hdr = emitir(IRT(IR_BUFHDR, IRT_PGC),\n\t\t      lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);\n    do {\n      tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, *trp++);\n    } while (trp <= top);\n    tr = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);\n    J->maxslot = (BCReg)(xbase - J->base);\n    if (xbase == base) return tr;  /* Return simple concatenation result. */\n    /* Pass partial result. */\n    topslot = J->maxslot--;\n    *xbase = tr;\n    top = xbase;\n    setstrV(J->L, &ix.keyv, &J2G(J)->strempty);  /* Simulate string result. */\n  } else {\n    J->maxslot = topslot-1;\n    copyTV(J->L, &ix.keyv, &J->L->base[topslot]);\n  }\n  copyTV(J->L, &ix.tabv, &J->L->base[topslot-1]);\n  ix.tab = top[-1];\n  ix.key = top[0];\n  memcpy(savetv, &J->L->base[topslot-1], sizeof(savetv));  /* Save slots. */\n  rec_mm_arith(J, &ix, MM_concat);  /* Call __concat metamethod. */\n  memcpy(&J->L->base[topslot-1], savetv, sizeof(savetv));  /* Restore slots. */\n  return 0;  /* No result yet. */\n}\n\n/* -- Record bytecode ops ------------------------------------------------- */\n\n/* Prepare for comparison. */\nstatic void rec_comp_prep(jit_State *J)\n{\n  /* Prevent merging with snapshot #0 (GC exit) since we fixup the PC. */\n  if (J->cur.nsnap == 1 && J->cur.snap[0].ref == J->cur.nins)\n    emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);\n  lj_snap_add(J);\n}\n\n/* Fixup comparison. */\nstatic void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond)\n{\n  BCIns jmpins = pc[1];\n  const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0);\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n  /* Set PC to opposite target to avoid re-recording the comp. in side trace. */\n#if LJ_FR2\n  SnapEntry *flink = &J->cur.snapmap[snap->mapofs + snap->nent];\n  uint64_t pcbase;\n  memcpy(&pcbase, flink, sizeof(uint64_t));\n  pcbase = (pcbase & 0xff) | (u64ptr(npc) << 8);\n  memcpy(flink, &pcbase, sizeof(uint64_t));\n#else\n  J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc);\n#endif\n  J->needsnap = 1;\n  if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins);\n  lj_snap_shrink(J);  /* Shrink last snapshot if possible. */\n}\n\n/* Record the next bytecode instruction (_before_ it's executed). */\nvoid lj_record_ins(jit_State *J)\n{\n  cTValue *lbase;\n  RecordIndex ix;\n  const BCIns *pc;\n  BCIns ins;\n  BCOp op;\n  TRef ra, rb, rc;\n\n  /* Perform post-processing action before recording the next instruction. */\n  if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {\n    switch (J->postproc) {\n    case LJ_POST_FIXCOMP:  /* Fixup comparison. */\n      pc = (const BCIns *)(uintptr_t)J2G(J)->tmptv.u64;\n      rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1)));\n      /* fallthrough */\n    case LJ_POST_FIXGUARD:  /* Fixup and emit pending guard. */\n    case LJ_POST_FIXGUARDSNAP:  /* Fixup and emit pending guard and snapshot. */\n      if (!tvistruecond(&J2G(J)->tmptv2)) {\n\tJ->fold.ins.o ^= 1;  /* Flip guard to opposite. */\n\tif (J->postproc == LJ_POST_FIXGUARDSNAP) {\n\t  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n\t  J->cur.snapmap[snap->mapofs+snap->nent-1]--;  /* False -> true. */\n\t}\n      }\n      lj_opt_fold(J);  /* Emit pending guard. */\n      /* fallthrough */\n    case LJ_POST_FIXBOOL:\n      if (!tvistruecond(&J2G(J)->tmptv2)) {\n\tBCReg s;\n\tTValue *tv = J->L->base;\n\tfor (s = 0; s < J->maxslot; s++)  /* Fixup stack slot (if any). */\n\t  if (J->base[s] == TREF_TRUE && tvisfalse(&tv[s])) {\n\t    J->base[s] = TREF_FALSE;\n\t    break;\n\t  }\n      }\n      break;\n    case LJ_POST_FIXCONST:\n      {\n\tBCReg s;\n\tTValue *tv = J->L->base;\n\tfor (s = 0; s < J->maxslot; s++)  /* Constify stack slots (if any). */\n\t  if (J->base[s] == TREF_NIL && !tvisnil(&tv[s]))\n\t    J->base[s] = lj_record_constify(J, &tv[s]);\n      }\n      break;\n    case LJ_POST_FFRETRY:  /* Suppress recording of retried fast function. */\n      if (bc_op(*J->pc) >= BC__MAX)\n\treturn;\n      break;\n    default: lj_assertJ(0, \"bad post-processing mode\"); break;\n    }\n    J->postproc = LJ_POST_NONE;\n  }\n\n  /* Need snapshot before recording next bytecode (e.g. after a store). */\n  if (J->needsnap) {\n    J->needsnap = 0;\n    if (J->pt) lj_snap_purge(J);\n    lj_snap_add(J);\n    J->mergesnap = 1;\n  }\n\n  /* Skip some bytecodes. */\n  if (LJ_UNLIKELY(J->bcskip > 0)) {\n    J->bcskip--;\n    return;\n  }\n\n  /* Record only closed loops for root traces. */\n  pc = J->pc;\n  if (J->framedepth == 0 &&\n     (MSize)((char *)pc - (char *)J->bc_min) >= J->bc_extent)\n    lj_trace_err(J, LJ_TRERR_LLEAVE);\n\n#ifdef LUA_USE_ASSERT\n  rec_check_slots(J);\n  rec_check_ir(J);\n#endif\n\n#if LJ_HASPROFILE\n  rec_profile_ins(J, pc);\n#endif\n\n  /* Keep a copy of the runtime values of var/num/str operands. */\n#define rav\t(&ix.valv)\n#define rbv\t(&ix.tabv)\n#define rcv\t(&ix.keyv)\n\n  lbase = J->L->base;\n  ins = *pc;\n  op = bc_op(ins);\n  ra = bc_a(ins);\n  ix.val = 0;\n  switch (bcmode_a(op)) {\n  case BCMvar:\n    copyTV(J->L, rav, &lbase[ra]); ix.val = ra = getslot(J, ra); break;\n  default: break;  /* Handled later. */\n  }\n  rb = bc_b(ins);\n  rc = bc_c(ins);\n  switch (bcmode_b(op)) {\n  case BCMnone: rb = 0; rc = bc_d(ins); break;  /* Upgrade rc to 'rd'. */\n  case BCMvar:\n    copyTV(J->L, rbv, &lbase[rb]); ix.tab = rb = getslot(J, rb); break;\n  default: break;  /* Handled later. */\n  }\n  switch (bcmode_c(op)) {\n  case BCMvar:\n    copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break;\n  case BCMpri: setpriV(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break;\n  case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc);\n    copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) :\n    lj_ir_knumint(J, numV(tv)); } break;\n  case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc));\n    setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break;\n  default: break;  /* Handled later. */\n  }\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n#if LJ_HASFFI\n    if (tref_iscdata(ra) || tref_iscdata(rc)) {\n      rec_mm_comp_cdata(J, &ix, op, ((int)op & 2) ? MM_le : MM_lt);\n      break;\n    }\n#endif\n    /* Emit nothing for two numeric or string consts. */\n    if (!(tref_isk2(ra,rc) && tref_isnumber_str(ra) && tref_isnumber_str(rc))) {\n      IRType ta = tref_isinteger(ra) ? IRT_INT : tref_type(ra);\n      IRType tc = tref_isinteger(rc) ? IRT_INT : tref_type(rc);\n      int irop;\n      if (ta != tc) {\n\t/* Widen mixed number/int comparisons to number/number comparison. */\n\tif (ta == IRT_INT && tc == IRT_NUM) {\n\t  ra = emitir(IRTN(IR_CONV), ra, IRCONV_NUM_INT);\n\t  ta = IRT_NUM;\n\t} else if (ta == IRT_NUM && tc == IRT_INT) {\n\t  rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);\n\t} else if (LJ_52) {\n\t  ta = IRT_NIL;  /* Force metamethod for different types. */\n\t} else if (!((ta == IRT_FALSE || ta == IRT_TRUE) &&\n\t\t     (tc == IRT_FALSE || tc == IRT_TRUE))) {\n\t  break;  /* Interpreter will throw for two different types. */\n\t}\n      }\n      rec_comp_prep(J);\n      irop = (int)op - (int)BC_ISLT + (int)IR_LT;\n      if (ta == IRT_NUM) {\n\tif ((irop & 1)) irop ^= 4;  /* ISGE/ISGT are unordered. */\n\tif (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))\n\t  irop ^= 5;\n      } else if (ta == IRT_INT) {\n\tif (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))\n\t  irop ^= 1;\n      } else if (ta == IRT_STR) {\n\tif (!lj_ir_strcmp(strV(rav), strV(rcv), (IROp)irop)) irop ^= 1;\n\tra = lj_ir_call(J, IRCALL_lj_str_cmp, ra, rc);\n\trc = lj_ir_kint(J, 0);\n\tta = IRT_INT;\n      } else {\n\trec_mm_comp(J, &ix, (int)op);\n\tbreak;\n      }\n      emitir(IRTG(irop, ta), ra, rc);\n      rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1);\n    }\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n  case BC_ISEQS: case BC_ISNES:\n  case BC_ISEQN: case BC_ISNEN:\n  case BC_ISEQP: case BC_ISNEP:\n#if LJ_HASFFI\n    if (tref_iscdata(ra) || tref_iscdata(rc)) {\n      rec_mm_comp_cdata(J, &ix, op, MM_eq);\n      break;\n    }\n#endif\n    /* Emit nothing for two non-table, non-udata consts. */\n    if (!(tref_isk2(ra, rc) && !(tref_istab(ra) || tref_isudata(ra)))) {\n      int diff;\n      rec_comp_prep(J);\n      diff = lj_record_objcmp(J, ra, rc, rav, rcv);\n      if (diff == 2 || !(tref_istab(ra) || tref_isudata(ra)))\n\trec_comp_fixup(J, J->pc, ((int)op & 1) == !diff);\n      else if (diff == 1)  /* Only check __eq if different, but same type. */\n\trec_mm_equal(J, &ix, (int)op);\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC:\n    if ((op & 1) == tref_istruecond(rc))\n      rc = 0;  /* Don't store if condition is not true. */\n    /* fallthrough */\n  case BC_IST: case BC_ISF:  /* Type specialization suffices. */\n    if (bc_a(pc[1]) < J->maxslot)\n      J->maxslot = bc_a(pc[1]);  /* Shrink used slots. */\n    break;\n\n  case BC_ISTYPE: case BC_ISNUM:\n    /* These coercions need to correspond with lj_meta_istype(). */\n    if (LJ_DUALNUM && rc == ~LJ_TNUMX+1)\n      ra = lj_opt_narrow_toint(J, ra);\n    else if (rc == ~LJ_TNUMX+2)\n      ra = lj_ir_tonum(J, ra);\n    else if (rc == ~LJ_TSTR+1)\n      ra = lj_ir_tostr(J, ra);\n    /* else: type specialization suffices. */\n    J->base[bc_a(ins)] = ra;\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_NOT:\n    /* Type specialization already forces const result. */\n    rc = tref_istruecond(rc) ? TREF_FALSE : TREF_TRUE;\n    break;\n\n  case BC_LEN:\n    if (tref_isstr(rc))\n      rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN);\n    else if (!LJ_52 && tref_istab(rc))\n      rc = emitir(IRTI(IR_ALEN), rc, TREF_NIL);\n    else\n      rc = rec_mm_len(J, rc, rcv);\n    break;\n\n  /* -- Arithmetic ops ---------------------------------------------------- */\n\n  case BC_UNM:\n    if (tref_isnumber_str(rc)) {\n      rc = lj_opt_narrow_unm(J, rc, rcv);\n    } else {\n      ix.tab = rc;\n      copyTV(J->L, &ix.tabv, rcv);\n      rc = rec_mm_arith(J, &ix, MM_unm);\n    }\n    break;\n\n  case BC_ADDNV: case BC_SUBNV: case BC_MULNV: case BC_DIVNV: case BC_MODNV:\n    /* Swap rb/rc and rbv/rcv. rav is temp. */\n    ix.tab = rc; ix.key = rc = rb; rb = ix.tab;\n    copyTV(J->L, rav, rbv);\n    copyTV(J->L, rbv, rcv);\n    copyTV(J->L, rcv, rav);\n    if (op == BC_MODNV)\n      goto recmod;\n    /* fallthrough */\n  case BC_ADDVN: case BC_SUBVN: case BC_MULVN: case BC_DIVVN:\n  case BC_ADDVV: case BC_SUBVV: case BC_MULVV: case BC_DIVVV: {\n    MMS mm = bcmode_mm(op);\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv,\n\t\t\t       (int)mm - (int)MM_add + (int)IR_ADD);\n    else\n      rc = rec_mm_arith(J, &ix, mm);\n    break;\n    }\n\n  case BC_MODVN: case BC_MODVV:\n  recmod:\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_mod(J, rb, rc, rbv, rcv);\n    else\n      rc = rec_mm_arith(J, &ix, MM_mod);\n    break;\n\n  case BC_POW:\n    if (tref_isnumber_str(rb) && tref_isnumber_str(rc))\n      rc = lj_opt_narrow_pow(J, rb, rc, rbv, rcv);\n    else\n      rc = rec_mm_arith(J, &ix, MM_pow);\n    break;\n\n  /* -- Miscellaneous ops ------------------------------------------------- */\n\n  case BC_CAT:\n    rc = rec_cat(J, rb, rc);\n    break;\n\n  /* -- Constant and move ops --------------------------------------------- */\n\n  case BC_MOV:\n    /* Clear gap of method call to avoid resurrecting previous refs. */\n    if (ra > J->maxslot) {\n#if LJ_FR2\n      memset(J->base + J->maxslot, 0, (ra - J->maxslot) * sizeof(TRef));\n#else\n      J->base[ra-1] = 0;\n#endif\n    }\n    break;\n  case BC_KSTR: case BC_KNUM: case BC_KPRI:\n    break;\n  case BC_KSHORT:\n    rc = lj_ir_kint(J, (int32_t)(int16_t)rc);\n    break;\n  case BC_KNIL:\n    if (LJ_FR2 && ra > J->maxslot)\n      J->base[ra-1] = 0;\n    while (ra <= rc)\n      J->base[ra++] = TREF_NIL;\n    if (rc >= J->maxslot) J->maxslot = rc+1;\n    break;\n#if LJ_HASFFI\n  case BC_KCDATA:\n    rc = lj_ir_kgc(J, proto_kgc(J->pt, ~(ptrdiff_t)rc), IRT_CDATA);\n    break;\n#endif\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    rc = rec_upvalue(J, rc, 0);\n    break;\n  case BC_USETV: case BC_USETS: case BC_USETN: case BC_USETP:\n    rec_upvalue(J, ra, rc);\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_GGET: case BC_GSET:\n    settabV(J->L, &ix.tabv, tabref(J->fn->l.env));\n    ix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), getcurrf(J), IRFL_FUNC_ENV);\n    ix.idxchain = LJ_MAX_IDXCHAIN;\n    rc = lj_record_idx(J, &ix);\n    break;\n\n  case BC_TGETB: case BC_TSETB:\n    setintV(&ix.keyv, (int32_t)rc);\n    ix.key = lj_ir_kint(J, (int32_t)rc);\n    /* fallthrough */\n  case BC_TGETV: case BC_TGETS: case BC_TSETV: case BC_TSETS:\n    ix.idxchain = LJ_MAX_IDXCHAIN;\n    rc = lj_record_idx(J, &ix);\n    break;\n  case BC_TGETR: case BC_TSETR:\n    ix.idxchain = 0;\n    rc = lj_record_idx(J, &ix);\n    break;\n\n  case BC_TSETM:\n    rec_tsetm(J, ra, (BCReg)(J->L->top - J->L->base), (int32_t)rcv->u32.lo);\n    break;\n\n  case BC_TNEW:\n    rc = rec_tnew(J, rc);\n    break;\n  case BC_TDUP:\n    rc = emitir(IRTG(IR_TDUP, IRT_TAB),\n\t\tlj_ir_ktab(J, gco2tab(proto_kgc(J->pt, ~(ptrdiff_t)rc))), 0);\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n    J->rbchash[(rc & (RBCHASH_SLOTS-1))].ref = tref_ref(rc);\n    setmref(J->rbchash[(rc & (RBCHASH_SLOTS-1))].pc, pc);\n    setgcref(J->rbchash[(rc & (RBCHASH_SLOTS-1))].pt, obj2gco(J->pt));\n#endif\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_ITERC:\n    J->base[ra] = getslot(J, ra-3);\n    J->base[ra+1+LJ_FR2] = getslot(J, ra-2);\n    J->base[ra+2+LJ_FR2] = getslot(J, ra-1);\n    { /* Do the actual copy now because lj_record_call needs the values. */\n      TValue *b = &J->L->base[ra];\n      copyTV(J->L, b, b-3);\n      copyTV(J->L, b+1+LJ_FR2, b-2);\n      copyTV(J->L, b+2+LJ_FR2, b-1);\n    }\n    lj_record_call(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  /* L->top is set to L->base+ra+rc+NARGS-1+1. See lj_dispatch_ins(). */\n  case BC_CALLM:\n    rc = (BCReg)(J->L->top - J->L->base) - ra - LJ_FR2;\n    /* fallthrough */\n  case BC_CALL:\n    lj_record_call(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  case BC_CALLMT:\n    rc = (BCReg)(J->L->top - J->L->base) - ra - LJ_FR2;\n    /* fallthrough */\n  case BC_CALLT:\n    lj_record_tailcall(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  case BC_VARG:\n    rec_varg(J, ra, (ptrdiff_t)rb-1);\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    /* L->top is set to L->base+ra+rc+NRESULTS-1, see lj_dispatch_ins(). */\n    rc = (BCReg)(J->L->top - J->L->base) - ra + 1;\n    /* fallthrough */\n  case BC_RET: case BC_RET0: case BC_RET1:\n#if LJ_HASPROFILE\n    rec_profile_ret(J);\n#endif\n    lj_record_ret(J, ra, (ptrdiff_t)rc-1);\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORI:\n    if (rec_for(J, pc, 0) != LOOPEV_LEAVE)\n      J->loopref = J->cur.nins;\n    break;\n  case BC_JFORI:\n    lj_assertJ(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL,\n\t       \"JFORI does not point to JFORL\");\n    if (rec_for(J, pc, 0) != LOOPEV_LEAVE)  /* Link to existing loop. */\n      lj_record_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J]));\n    /* Continue tracing if the loop is not entered. */\n    break;\n\n  case BC_FORL:\n    rec_loop_interp(J, pc, rec_for(J, pc+((ptrdiff_t)rc-BCBIAS_J), 1));\n    break;\n  case BC_ITERL:\n    rec_loop_interp(J, pc, rec_iterl(J, *pc));\n    break;\n  case BC_ITERN:\n    rec_loop_interp(J, pc, rec_itern(J, ra, rb));\n    break;\n  case BC_LOOP:\n    rec_loop_interp(J, pc, rec_loop(J, ra, 1));\n    break;\n\n  case BC_JFORL:\n    rec_loop_jit(J, rc, rec_for(J, pc+bc_j(traceref(J, rc)->startins), 1));\n    break;\n  case BC_JITERL:\n    rec_loop_jit(J, rc, rec_iterl(J, traceref(J, rc)->startins));\n    break;\n  case BC_JLOOP:\n    rec_loop_jit(J, rc, rec_loop(J, ra,\n\t\t\t\t !bc_isret(bc_op(traceref(J, rc)->startins))));\n    break;\n\n  case BC_IFORL:\n  case BC_IITERL:\n  case BC_ILOOP:\n  case BC_IFUNCF:\n  case BC_IFUNCV:\n    lj_trace_err(J, LJ_TRERR_BLACKL);\n    break;\n\n  case BC_JMP:\n    if (ra < J->maxslot)\n      J->maxslot = ra;  /* Shrink used slots. */\n    break;\n\n  case BC_ISNEXT:\n    rec_isnext(J, ra);\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    rec_func_lua(J);\n    break;\n  case BC_JFUNCF:\n    rec_func_jit(J, rc);\n    break;\n\n  case BC_FUNCV:\n    rec_func_vararg(J);\n    rec_func_lua(J);\n    break;\n  case BC_JFUNCV:\n    /* Cannot happen. No hotcall counting for varag funcs. */\n    lj_assertJ(0, \"unsupported vararg hotcall\");\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    lj_ffrecord_func(J);\n    break;\n\n  default:\n    if (op >= BC__MAX) {\n      lj_ffrecord_func(J);\n      break;\n    }\n    /* fallthrough */\n  case BC_UCLO:\n  case BC_FNEW:\n    setintV(&J->errinfo, (int32_t)op);\n    lj_trace_err_info(J, LJ_TRERR_NYIBC);\n    break;\n  }\n\n  /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */\n  if (bcmode_a(op) == BCMdst && rc) {\n    J->base[ra] = rc;\n    if (ra >= J->maxslot) {\n#if LJ_FR2\n      if (ra > J->maxslot) J->base[ra-1] = 0;\n#endif\n      J->maxslot = ra+1;\n    }\n  }\n\n#undef rav\n#undef rbv\n#undef rcv\n\n  /* Limit the number of recorded IR instructions and constants. */\n  if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord] ||\n      J->cur.nk < REF_BIAS-(IRRef)J->param[JIT_P_maxirconst])\n    lj_trace_err(J, LJ_TRERR_TRACEOV);\n}\n\n/* -- Recording setup ----------------------------------------------------- */\n\n/* Setup recording for a root trace started by a hot loop. */\nstatic const BCIns *rec_setup_root(jit_State *J)\n{\n  /* Determine the next PC and the bytecode range for the loop. */\n  const BCIns *pcj, *pc = J->pc;\n  BCIns ins = *pc;\n  BCReg ra = bc_a(ins);\n  switch (bc_op(ins)) {\n  case BC_FORL:\n    J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    pc += 1+bc_j(ins);\n    J->bc_min = pc;\n    break;\n  case BC_ITERL:\n    lj_assertJ(bc_op(pc[-1]) == BC_ITERC, \"no ITERC before ITERL\");\n    J->maxslot = ra + bc_b(pc[-1]) - 1;\n    J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    pc += 1+bc_j(ins);\n    lj_assertJ(bc_op(pc[-1]) == BC_JMP, \"ITERL does not point to JMP+1\");\n    J->bc_min = pc;\n    break;\n  case BC_ITERN:\n    lj_assertJ(bc_op(pc[1]) == BC_ITERL, \"no ITERL after ITERN\");\n    J->maxslot = ra;\n    J->bc_extent = (MSize)(-bc_j(pc[1]))*sizeof(BCIns);\n    J->bc_min = pc+2 + bc_j(pc[1]);\n    J->state = LJ_TRACE_RECORD_1ST;  /* Record the first ITERN, too. */\n    break;\n  case BC_LOOP:\n    /* Only check BC range for real loops, but not for \"repeat until true\". */\n    pcj = pc + bc_j(ins);\n    ins = *pcj;\n    if (bc_op(ins) == BC_JMP && bc_j(ins) < 0) {\n      J->bc_min = pcj+1 + bc_j(ins);\n      J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);\n    }\n    J->maxslot = ra;\n    pc++;\n    break;\n  case BC_RET:\n  case BC_RET0:\n  case BC_RET1:\n    /* No bytecode range check for down-recursive root traces. */\n    J->maxslot = ra + bc_d(ins) - 1;\n    break;\n  case BC_FUNCF:\n    /* No bytecode range check for root traces started by a hot call. */\n    J->maxslot = J->pt->numparams;\n    pc++;\n    break;\n  case BC_CALLM:\n  case BC_CALL:\n  case BC_ITERC:\n    /* No bytecode range check for stitched traces. */\n    pc++;\n    break;\n  default:\n    lj_assertJ(0, \"bad root trace start bytecode %d\", bc_op(ins));\n    break;\n  }\n  return pc;\n}\n\n/* Setup for recording a new trace. */\nvoid lj_record_setup(jit_State *J)\n{\n  uint32_t i;\n\n  /* Initialize state related to current trace. */\n  memset(J->slot, 0, sizeof(J->slot));\n  memset(J->chain, 0, sizeof(J->chain));\n#ifdef LUAJIT_ENABLE_TABLE_BUMP\n  memset(J->rbchash, 0, sizeof(J->rbchash));\n#endif\n  memset(J->bpropcache, 0, sizeof(J->bpropcache));\n  J->scev.idx = REF_NIL;\n  setmref(J->scev.pc, NULL);\n\n  J->baseslot = 1+LJ_FR2;  /* Invoking function is at base[-1-LJ_FR2]. */\n  J->base = J->slot + J->baseslot;\n  J->maxslot = 0;\n  J->framedepth = 0;\n  J->retdepth = 0;\n\n  J->instunroll = J->param[JIT_P_instunroll];\n  J->loopunroll = J->param[JIT_P_loopunroll];\n  J->tailcalled = 0;\n  J->loopref = 0;\n\n  J->bc_min = NULL;  /* Means no limit. */\n  J->bc_extent = ~(MSize)0;\n\n  /* Emit instructions for fixed references. Also triggers initial IR alloc. */\n  emitir_raw(IRT(IR_BASE, IRT_PGC), J->parent, J->exitno);\n  for (i = 0; i <= 2; i++) {\n    IRIns *ir = IR(REF_NIL-i);\n    ir->i = 0;\n    ir->t.irt = (uint8_t)(IRT_NIL+i);\n    ir->o = IR_KPRI;\n    ir->prev = 0;\n  }\n  J->cur.nk = REF_TRUE;\n\n  J->startpc = J->pc;\n  setmref(J->cur.startpc, J->pc);\n  if (J->parent) {  /* Side trace. */\n    GCtrace *T = traceref(J, J->parent);\n    TraceNo root = T->root ? T->root : J->parent;\n    J->cur.root = (uint16_t)root;\n    J->cur.startins = BCINS_AD(BC_JMP, 0, 0);\n    /* Check whether we could at least potentially form an extra loop. */\n    if (J->exitno == 0 && T->snap[0].nent == 0) {\n      /* We can narrow a FORL for some side traces, too. */\n      if (J->pc > proto_bc(J->pt) && bc_op(J->pc[-1]) == BC_JFORI &&\n\t  bc_d(J->pc[bc_j(J->pc[-1])-1]) == root) {\n\tlj_snap_add(J);\n\trec_for_loop(J, J->pc-1, &J->scev, 1);\n\tgoto sidecheck;\n      }\n    } else {\n      J->startpc = NULL;  /* Prevent forming an extra loop. */\n    }\n    lj_snap_replay(J, T);\n  sidecheck:\n    if ((traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] ||\n\t T->snap[J->exitno].count >= J->param[JIT_P_hotexit] +\n\t\t\t\t     J->param[JIT_P_tryside])) {\n      if (bc_op(*J->pc) == BC_JLOOP) {\n\tBCIns startins = traceref(J, bc_d(*J->pc))->startins;\n\tif (bc_op(startins) == BC_ITERN)\n\t  rec_itern(J, bc_a(startins), bc_b(startins));\n      }\n      lj_record_stop(J, LJ_TRLINK_INTERP, 0);\n    }\n  } else {  /* Root trace. */\n    J->cur.root = 0;\n    J->cur.startins = *J->pc;\n    J->pc = rec_setup_root(J);\n    /* Note: the loop instruction itself is recorded at the end and not\n    ** at the start! So snapshot #0 needs to point to the *next* instruction.\n    ** The one exception is BC_ITERN, which sets LJ_TRACE_RECORD_1ST.\n    */\n    lj_snap_add(J);\n    if (bc_op(J->cur.startins) == BC_FORL)\n      rec_for_loop(J, J->pc-1, &J->scev, 1);\n    else if (bc_op(J->cur.startins) == BC_ITERC)\n      J->startpc = NULL;\n    if (1 + J->pt->framesize >= LJ_MAX_JSLOTS)\n      lj_trace_err(J, LJ_TRERR_STACKOV);\n  }\n#if LJ_HASPROFILE\n  J->prev_pt = NULL;\n  J->prev_line = -1;\n#endif\n#ifdef LUAJIT_ENABLE_CHECKHOOK\n  /* Regularly check for instruction/line hooks from compiled code and\n  ** exit to the interpreter if the hooks are set.\n  **\n  ** This is a compile-time option and disabled by default, since the\n  ** hook checks may be quite expensive in tight loops.\n  **\n  ** Note this is only useful if hooks are *not* set most of the time.\n  ** Use this only if you want to *asynchronously* interrupt the execution.\n  **\n  ** You can set the instruction hook via lua_sethook() with a count of 1\n  ** from a signal handler or another native thread. Please have a look\n  ** at the first few functions in luajit.c for an example (Ctrl-C handler).\n  */\n  {\n    TRef tr = emitir(IRT(IR_XLOAD, IRT_U8),\n\t\t     lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE);\n    tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT)));\n    emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));\n  }\n#endif\n}\n\n#undef IR\n#undef emitir_raw\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_record.h",
    "content": "/*\n** Trace recorder (bytecode -> SSA IR).\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_RECORD_H\n#define _LJ_RECORD_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\n/* Context for recording an indexed load/store. */\ntypedef struct RecordIndex {\n  TValue tabv;\t\t/* Runtime value of table (or indexed object). */\n  TValue keyv;\t\t/* Runtime value of key. */\n  TValue valv;\t\t/* Runtime value of stored value. */\n  TValue mobjv;\t\t/* Runtime value of metamethod object. */\n  GCtab *mtv;\t\t/* Runtime value of metatable object. */\n  cTValue *oldv;\t/* Runtime value of previously stored value. */\n  TRef tab;\t\t/* Table (or indexed object) reference. */\n  TRef key;\t\t/* Key reference. */\n  TRef val;\t\t/* Value reference for a store or 0 for a load. */\n  TRef mt;\t\t/* Metatable reference. */\n  TRef mobj;\t\t/* Metamethod object reference. */\n  int idxchain;\t\t/* Index indirections left or 0 for raw lookup. */\n} RecordIndex;\n\nLJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,\n\t\t\t     cTValue *av, cTValue *bv);\nLJ_FUNC void lj_record_stop(jit_State *J, TraceLink linktype, TraceNo lnk);\nLJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);\nLJ_FUNC TRef lj_record_vload(jit_State *J, TRef ref, MSize idx, IRType t);\n\nLJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);\nLJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);\nLJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);\n\nLJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);\nLJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);\nLJ_FUNC int lj_record_next(jit_State *J, RecordIndex *ix);\n\nLJ_FUNC void lj_record_ins(jit_State *J);\nLJ_FUNC void lj_record_setup(jit_State *J);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_serialize.c",
    "content": "/*\n** Object de/serialization.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_serialize_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASBUFFER\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_udata.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#endif\n#if LJ_HASJIT\n#include \"lj_ir.h\"\n#endif\n#include \"lj_serialize.h\"\n\n/* Tags for internal serialization format. */\nenum {\n  SER_TAG_NIL,\t\t/* 0x00 */\n  SER_TAG_FALSE,\n  SER_TAG_TRUE,\n  SER_TAG_NULL,\n  SER_TAG_LIGHTUD32,\n  SER_TAG_LIGHTUD64,\n  SER_TAG_INT,\n  SER_TAG_NUM,\n  SER_TAG_TAB,\t\t/* 0x08 */\n  SER_TAG_DICT_MT = SER_TAG_TAB+6,\n  SER_TAG_DICT_STR,\n  SER_TAG_INT64,\t/* 0x10 */\n  SER_TAG_UINT64,\n  SER_TAG_COMPLEX,\n  SER_TAG_0x13,\n  SER_TAG_0x14,\n  SER_TAG_0x15,\n  SER_TAG_0x16,\n  SER_TAG_0x17,\n  SER_TAG_0x18,\t\t/* 0x18 */\n  SER_TAG_0x19,\n  SER_TAG_0x1a,\n  SER_TAG_0x1b,\n  SER_TAG_0x1c,\n  SER_TAG_0x1d,\n  SER_TAG_0x1e,\n  SER_TAG_0x1f,\n  SER_TAG_STR,\t\t/* 0x20 + str->len */\n};\nLJ_STATIC_ASSERT((SER_TAG_TAB & 7) == 0);\n\n/* -- Helper functions ---------------------------------------------------- */\n\nstatic LJ_AINLINE char *serialize_more(char *w, SBufExt *sbx, MSize sz)\n{\n  if (LJ_UNLIKELY(sz > (MSize)(sbx->e - w))) {\n    sbx->w = w;\n    w = lj_buf_more2((SBuf *)sbx, sz);\n  }\n  return w;\n}\n\n/* Write U124 to buffer. */\nstatic LJ_NOINLINE char *serialize_wu124_(char *w, uint32_t v)\n{\n  if (v < 0x1fe0) {\n    v -= 0xe0;\n    *w++ = (char)(0xe0 | (v >> 8)); *w++ = (char)v;\n  } else {\n    *w++ = (char)0xff;\n#if LJ_BE\n    v = lj_bswap(v);\n#endif\n    memcpy(w, &v, 4); w += 4;\n  }\n  return w;\n}\n\nstatic LJ_AINLINE char *serialize_wu124(char *w, uint32_t v)\n{\n  if (LJ_LIKELY(v < 0xe0)) {\n    *w++ = (char)v;\n    return w;\n  } else {\n    return serialize_wu124_(w, v);\n  }\n}\n\nstatic LJ_NOINLINE char *serialize_ru124_(char *r, char *w, uint32_t *pv)\n{\n  uint32_t v = *pv;\n  if (v != 0xff) {\n    if (r >= w) return NULL;\n    v = ((v & 0x1f) << 8) + *(uint8_t *)r + 0xe0; r++;\n  } else {\n    if (r + 4 > w) return NULL;\n    v = lj_getu32(r); r += 4;\n#if LJ_BE\n    v = lj_bswap(v);\n#endif\n  }\n  *pv = v;\n  return r;\n}\n\nstatic LJ_AINLINE char *serialize_ru124(char *r, char *w, uint32_t *pv)\n{\n  if (LJ_LIKELY(r < w)) {\n    uint32_t v = *(uint8_t *)r; r++;\n    *pv = v;\n    if (LJ_UNLIKELY(v >= 0xe0)) {\n      r = serialize_ru124_(r, w, pv);\n    }\n    return r;\n  }\n  return NULL;\n}\n\n/* Prepare string dictionary for use (once). */\nvoid LJ_FASTCALL lj_serialize_dict_prep_str(lua_State *L, GCtab *dict)\n{\n  if (!dict->hmask) {  /* No hash part means not prepared, yet. */\n    MSize i, len = lj_tab_len(dict);\n    if (!len) return;\n    lj_tab_resize(L, dict, dict->asize, hsize2hbits(len));\n    for (i = 1; i <= len && i < dict->asize; i++) {\n      cTValue *o = arrayslot(dict, i);\n      if (tvisstr(o)) {\n\tif (!lj_tab_getstr(dict, strV(o))) {  /* Ignore dups. */\n\t  lj_tab_newkey(L, dict, o)->u64 = (uint64_t)(i-1);\n\t}\n      } else if (!tvisfalse(o)) {\n\tlj_err_caller(L, LJ_ERR_BUFFER_BADOPT);\n      }\n    }\n  }\n}\n\n/* Prepare metatable dictionary for use (once). */\nvoid LJ_FASTCALL lj_serialize_dict_prep_mt(lua_State *L, GCtab *dict)\n{\n  if (!dict->hmask) {  /* No hash part means not prepared, yet. */\n    MSize i, len = lj_tab_len(dict);\n    if (!len) return;\n    lj_tab_resize(L, dict, dict->asize, hsize2hbits(len));\n    for (i = 1; i <= len && i < dict->asize; i++) {\n      cTValue *o = arrayslot(dict, i);\n      if (tvistab(o)) {\n\tif (tvisnil(lj_tab_get(L, dict, o))) {  /* Ignore dups. */\n\t  lj_tab_newkey(L, dict, o)->u64 = (uint64_t)(i-1);\n\t}\n      } else if (!tvisfalse(o)) {\n\tlj_err_caller(L, LJ_ERR_BUFFER_BADOPT);\n      }\n    }\n  }\n}\n\n/* -- Internal serializer ------------------------------------------------- */\n\n/* Put serialized object into buffer. */\nstatic char *serialize_put(char *w, SBufExt *sbx, cTValue *o)\n{\n  if (LJ_LIKELY(tvisstr(o))) {\n    const GCstr *str = strV(o);\n    MSize len = str->len;\n    w = serialize_more(w, sbx, 5+len);\n    w = serialize_wu124(w, SER_TAG_STR + len);\n    w = lj_buf_wmem(w, strdata(str), len);\n  } else if (tvisint(o)) {\n    uint32_t x = LJ_BE ? lj_bswap((uint32_t)intV(o)) : (uint32_t)intV(o);\n    w = serialize_more(w, sbx, 1+4);\n    *w++ = SER_TAG_INT; memcpy(w, &x, 4); w += 4;\n  } else if (tvisnum(o)) {\n    uint64_t x = LJ_BE ? lj_bswap64(o->u64) : o->u64;\n    w = serialize_more(w, sbx, 1+sizeof(lua_Number));\n    *w++ = SER_TAG_NUM; memcpy(w, &x, 8); w += 8;\n  } else if (tvispri(o)) {\n    w = serialize_more(w, sbx, 1);\n    *w++ = (char)(SER_TAG_NIL + ~itype(o));\n  } else if (tvistab(o)) {\n    const GCtab *t = tabV(o);\n    uint32_t narray = 0, nhash = 0, one = 2;\n    if (sbx->depth <= 0) lj_err_caller(sbufL(sbx), LJ_ERR_BUFFER_DEPTH);\n    sbx->depth--;\n    if (t->asize > 0) {  /* Determine max. length of array part. */\n      ptrdiff_t i;\n      TValue *array = tvref(t->array);\n      for (i = (ptrdiff_t)t->asize-1; i >= 0; i--)\n\tif (!tvisnil(&array[i]))\n\t  break;\n      narray = (uint32_t)(i+1);\n      if (narray && tvisnil(&array[0])) one = 4;\n    }\n    if (t->hmask > 0) {  /* Count number of used hash slots. */\n      uint32_t i, hmask = t->hmask;\n      Node *node = noderef(t->node);\n      for (i = 0; i <= hmask; i++)\n\tnhash += !tvisnil(&node[i].val);\n    }\n    /* Write metatable index. */\n    if (LJ_UNLIKELY(tabref(sbx->dict_mt)) && tabref(t->metatable)) {\n      TValue mto;\n      Node *n;\n      settabV(sbufL(sbx), &mto, tabref(t->metatable));\n      n = hashgcref(tabref(sbx->dict_mt), mto.gcr);\n      do {\n\tif (n->key.u64 == mto.u64) {\n\t  uint32_t idx = n->val.u32.lo;\n\t  w = serialize_more(w, sbx, 1+5);\n\t  *w++ = SER_TAG_DICT_MT;\n\t  w = serialize_wu124(w, idx);\n\t  break;\n\t}\n      } while ((n = nextnode(n)));\n    }\n    /* Write number of array slots and hash slots. */\n    w = serialize_more(w, sbx, 1+2*5);\n    *w++ = (char)(SER_TAG_TAB + (nhash ? 1 : 0) + (narray ? one : 0));\n    if (narray) w = serialize_wu124(w, narray);\n    if (nhash) w = serialize_wu124(w, nhash);\n    if (narray) {  /* Write array entries. */\n      cTValue *oa = tvref(t->array) + (one >> 2);\n      cTValue *oe = tvref(t->array) + narray;\n      while (oa < oe) w = serialize_put(w, sbx, oa++);\n    }\n    if (nhash) {  /* Write hash entries. */\n      const Node *node = noderef(t->node) + t->hmask;\n      GCtab *dict_str = tabref(sbx->dict_str);\n      if (LJ_UNLIKELY(dict_str)) {\n\tfor (;; node--)\n\t  if (!tvisnil(&node->val)) {\n\t    if (LJ_LIKELY(tvisstr(&node->key))) {\n\t      /* Inlined lj_tab_getstr is 30% faster. */\n\t      const GCstr *str = strV(&node->key);\n\t      Node *n = hashstr(dict_str, str);\n\t      do {\n\t\tif (tvisstr(&n->key) && strV(&n->key) == str) {\n\t\t  uint32_t idx = n->val.u32.lo;\n\t\t  w = serialize_more(w, sbx, 1+5);\n\t\t  *w++ = SER_TAG_DICT_STR;\n\t\t  w = serialize_wu124(w, idx);\n\t\t  break;\n\t\t}\n\t\tn = nextnode(n);\n\t\tif (!n) {\n\t\t  MSize len = str->len;\n\t\t  w = serialize_more(w, sbx, 5+len);\n\t\t  w = serialize_wu124(w, SER_TAG_STR + len);\n\t\t  w = lj_buf_wmem(w, strdata(str), len);\n\t\t  break;\n\t\t}\n\t      } while (1);\n\t    } else {\n\t      w = serialize_put(w, sbx, &node->key);\n\t    }\n\t    w = serialize_put(w, sbx, &node->val);\n\t    if (--nhash == 0) break;\n\t  }\n      } else {\n\tfor (;; node--)\n\t  if (!tvisnil(&node->val)) {\n\t    w = serialize_put(w, sbx, &node->key);\n\t    w = serialize_put(w, sbx, &node->val);\n\t    if (--nhash == 0) break;\n\t  }\n      }\n    }\n    sbx->depth++;\n#if LJ_HASFFI\n  } else if (tviscdata(o)) {\n    CTState *cts = ctype_cts(sbufL(sbx));\n    CType *s = ctype_raw(cts, cdataV(o)->ctypeid);\n    uint8_t *sp = cdataptr(cdataV(o));\n    if (ctype_isinteger(s->info) && s->size == 8) {\n      w = serialize_more(w, sbx, 1+8);\n      *w++ = (s->info & CTF_UNSIGNED) ? SER_TAG_UINT64 : SER_TAG_INT64;\n#if LJ_BE\n      { uint64_t u = lj_bswap64(*(uint64_t *)sp); memcpy(w, &u, 8); }\n#else\n      memcpy(w, sp, 8);\n#endif\n      w += 8;\n    } else if (ctype_iscomplex(s->info) && s->size == 16) {\n      w = serialize_more(w, sbx, 1+16);\n      *w++ = SER_TAG_COMPLEX;\n#if LJ_BE\n      {  /* Only swap the doubles. The re/im order stays the same. */\n\tuint64_t u = lj_bswap64(((uint64_t *)sp)[0]); memcpy(w, &u, 8);\n\tu = lj_bswap64(((uint64_t *)sp)[1]); memcpy(w+8, &u, 8);\n      }\n#else\n      memcpy(w, sp, 16);\n#endif\n      w += 16;\n    } else {\n      goto badenc;  /* NYI other cdata */\n    }\n#endif\n  } else if (tvislightud(o)) {\n    uintptr_t ud = (uintptr_t)lightudV(G(sbufL(sbx)), o);\n    w = serialize_more(w, sbx, 1+sizeof(ud));\n    if (ud == 0) {\n      *w++ = SER_TAG_NULL;\n    } else if (LJ_32 || checku32(ud)) {\n#if LJ_BE && LJ_64\n      ud = lj_bswap64(ud);\n#elif LJ_BE\n      ud = lj_bswap(ud);\n#endif\n      *w++ = SER_TAG_LIGHTUD32; memcpy(w, &ud, 4); w += 4;\n#if LJ_64\n    } else {\n#if LJ_BE\n      ud = lj_bswap64(ud);\n#endif\n      *w++ = SER_TAG_LIGHTUD64; memcpy(w, &ud, 8); w += 8;\n#endif\n    }\n  } else {\n    /* NYI userdata */\n#if LJ_HASFFI\n  badenc:\n#endif\n    lj_err_callerv(sbufL(sbx), LJ_ERR_BUFFER_BADENC, lj_typename(o));\n  }\n  return w;\n}\n\n/* Get serialized object from buffer. */\nstatic char *serialize_get(char *r, SBufExt *sbx, TValue *o)\n{\n  char *w = sbx->w;\n  uint32_t tp;\n  r = serialize_ru124(r, w, &tp); if (LJ_UNLIKELY(!r)) goto eob;\n  if (LJ_LIKELY(tp >= SER_TAG_STR)) {\n    uint32_t len = tp - SER_TAG_STR;\n    if (LJ_UNLIKELY(len > (uint32_t)(w - r))) goto eob;\n    setstrV(sbufL(sbx), o, lj_str_new(sbufL(sbx), r, len));\n    r += len;\n  } else if (tp == SER_TAG_INT) {\n    if (LJ_UNLIKELY(r + 4 > w)) goto eob;\n    setintV(o, (int32_t)(LJ_BE ? lj_bswap(lj_getu32(r)) : lj_getu32(r)));\n    r += 4;\n  } else if (tp == SER_TAG_NUM) {\n    if (LJ_UNLIKELY(r + 8 > w)) goto eob;\n    memcpy(o, r, 8); r += 8;\n#if LJ_BE\n    o->u64 = lj_bswap64(o->u64);\n#endif\n    if (!tvisnum(o)) setnanV(o);  /* Fix non-canonical NaNs. */\n  } else if (tp <= SER_TAG_TRUE) {\n    setpriV(o, ~tp);\n  } else if (tp == SER_TAG_DICT_STR) {\n    GCtab *dict_str;\n    uint32_t idx;\n    r = serialize_ru124(r, w, &idx); if (LJ_UNLIKELY(!r)) goto eob;\n    idx++;\n    dict_str = tabref(sbx->dict_str);\n    if (dict_str && idx < dict_str->asize && tvisstr(arrayslot(dict_str, idx)))\n      copyTV(sbufL(sbx), o, arrayslot(dict_str, idx));\n    else\n      lj_err_callerv(sbufL(sbx), LJ_ERR_BUFFER_BADDICTX, idx);\n  } else if (tp >= SER_TAG_TAB && tp <= SER_TAG_DICT_MT) {\n    uint32_t narray = 0, nhash = 0;\n    GCtab *t, *mt = NULL;\n    if (sbx->depth <= 0) lj_err_caller(sbufL(sbx), LJ_ERR_BUFFER_DEPTH);\n    sbx->depth--;\n    if (tp == SER_TAG_DICT_MT) {\n      GCtab *dict_mt;\n      uint32_t idx;\n      r = serialize_ru124(r, w, &idx); if (LJ_UNLIKELY(!r)) goto eob;\n      idx++;\n      dict_mt = tabref(sbx->dict_mt);\n      if (dict_mt && idx < dict_mt->asize && tvistab(arrayslot(dict_mt, idx)))\n\tmt = tabV(arrayslot(dict_mt, idx));\n      else\n\tlj_err_callerv(sbufL(sbx), LJ_ERR_BUFFER_BADDICTX, idx);\n      r = serialize_ru124(r, w, &tp); if (LJ_UNLIKELY(!r)) goto eob;\n      if (!(tp >= SER_TAG_TAB && tp < SER_TAG_DICT_MT)) goto badtag;\n    }\n    if (tp >= SER_TAG_TAB+2) {\n      r = serialize_ru124(r, w, &narray); if (LJ_UNLIKELY(!r)) goto eob;\n    }\n    if ((tp & 1)) {\n      r = serialize_ru124(r, w, &nhash); if (LJ_UNLIKELY(!r)) goto eob;\n    }\n    t = lj_tab_new(sbufL(sbx), narray, hsize2hbits(nhash));\n    /* NOBARRIER: The table is new (marked white). */\n    setgcref(t->metatable, obj2gco(mt));\n    settabV(sbufL(sbx), o, t);\n    if (narray) {\n      TValue *oa = tvref(t->array) + (tp >= SER_TAG_TAB+4);\n      TValue *oe = tvref(t->array) + narray;\n      while (oa < oe) r = serialize_get(r, sbx, oa++);\n    }\n    if (nhash) {\n      do {\n\tTValue k, *v;\n\tr = serialize_get(r, sbx, &k);\n\tv = lj_tab_set(sbufL(sbx), t, &k);\n\tif (LJ_UNLIKELY(!tvisnil(v)))\n\t  lj_err_caller(sbufL(sbx), LJ_ERR_BUFFER_DUPKEY);\n\tr = serialize_get(r, sbx, v);\n      } while (--nhash);\n    }\n    sbx->depth++;\n#if LJ_HASFFI\n  } else if (tp >= SER_TAG_INT64 &&  tp <= SER_TAG_COMPLEX) {\n    uint32_t sz = tp == SER_TAG_COMPLEX ? 16 : 8;\n    GCcdata *cd;\n    if (LJ_UNLIKELY(r + sz > w)) goto eob;\n    cd = lj_cdata_new_(sbufL(sbx),\n\t   tp == SER_TAG_INT64 ? CTID_INT64 :\n\t   tp == SER_TAG_UINT64 ? CTID_UINT64 : CTID_COMPLEX_DOUBLE,\n\t   sz);\n    memcpy(cdataptr(cd), r, sz); r += sz;\n#if LJ_BE\n    *(uint64_t *)cdataptr(cd) = lj_bswap64(*(uint64_t *)cdataptr(cd));\n    if (sz == 16)\n      ((uint64_t *)cdataptr(cd))[1] = lj_bswap64(((uint64_t *)cdataptr(cd))[1]);\n#endif\n    if (sz == 16) {  /* Fix non-canonical NaNs. */\n      TValue *cdo = (TValue *)cdataptr(cd);\n      if (!tvisnum(&cdo[0])) setnanV(&cdo[0]);\n      if (!tvisnum(&cdo[1])) setnanV(&cdo[1]);\n    }\n    setcdataV(sbufL(sbx), o, cd);\n#endif\n  } else if (tp <= (LJ_64 ? SER_TAG_LIGHTUD64 : SER_TAG_LIGHTUD32)) {\n    uintptr_t ud = 0;\n    if (tp == SER_TAG_LIGHTUD32) {\n      if (LJ_UNLIKELY(r + 4 > w)) goto eob;\n      ud = (uintptr_t)(LJ_BE ? lj_bswap(lj_getu32(r)) : lj_getu32(r));\n      r += 4;\n    }\n#if LJ_64\n    else if (tp == SER_TAG_LIGHTUD64) {\n      if (LJ_UNLIKELY(r + 8 > w)) goto eob;\n      memcpy(&ud, r, 8); r += 8;\n#if LJ_BE\n      ud = lj_bswap64(ud);\n#endif\n    }\n    setrawlightudV(o, lj_lightud_intern(sbufL(sbx), (void *)ud));\n#else\n    setrawlightudV(o, (void *)ud);\n#endif\n  } else {\nbadtag:\n    lj_err_callerv(sbufL(sbx), LJ_ERR_BUFFER_BADDEC, tp);\n  }\n  return r;\neob:\n  lj_err_caller(sbufL(sbx), LJ_ERR_BUFFER_EOB);\n  return NULL;\n}\n\n/* -- External serialization API ------------------------------------------ */\n\n/* Encode to buffer. */\nSBufExt * LJ_FASTCALL lj_serialize_put(SBufExt *sbx, cTValue *o)\n{\n  sbx->depth = LJ_SERIALIZE_DEPTH;\n  sbx->w = serialize_put(sbx->w, sbx, o);\n  return sbx;\n}\n\n/* Decode from buffer. */\nchar * LJ_FASTCALL lj_serialize_get(SBufExt *sbx, TValue *o)\n{\n  sbx->depth = LJ_SERIALIZE_DEPTH;\n  return serialize_get(sbx->r, sbx, o);\n}\n\n/* Stand-alone encoding, borrowing from global temporary buffer. */\nGCstr * LJ_FASTCALL lj_serialize_encode(lua_State *L, cTValue *o)\n{\n  SBufExt sbx;\n  char *w;\n  memset(&sbx, 0, sizeof(SBufExt));\n  lj_bufx_set_borrow(L, &sbx, &G(L)->tmpbuf);\n  sbx.depth = LJ_SERIALIZE_DEPTH;\n  w = serialize_put(sbx.w, &sbx, o);\n  return lj_str_new(L, sbx.b, (size_t)(w - sbx.b));\n}\n\n/* Stand-alone decoding, copy-on-write from string. */\nvoid lj_serialize_decode(lua_State *L, TValue *o, GCstr *str)\n{\n  SBufExt sbx;\n  char *r;\n  memset(&sbx, 0, sizeof(SBufExt));\n  lj_bufx_set_cow(L, &sbx, strdata(str), str->len);\n  /* No need to set sbx.cowref here. */\n  sbx.depth = LJ_SERIALIZE_DEPTH;\n  r = serialize_get(sbx.r, &sbx, o);\n  if (r != sbx.w) lj_err_caller(L, LJ_ERR_BUFFER_LEFTOV);\n}\n\n#if LJ_HASJIT\n/* Peek into buffer to find the result IRType for specialization purposes. */\nLJ_FUNC MSize LJ_FASTCALL lj_serialize_peektype(SBufExt *sbx)\n{\n  uint32_t tp;\n  if (serialize_ru124(sbx->r, sbx->w, &tp)) {\n    /* This must match the handling of all tags in the decoder above. */\n    switch (tp) {\n    case SER_TAG_NIL: return IRT_NIL;\n    case SER_TAG_FALSE: return IRT_FALSE;\n    case SER_TAG_TRUE: return IRT_TRUE;\n    case SER_TAG_NULL: case SER_TAG_LIGHTUD32: case SER_TAG_LIGHTUD64:\n      return IRT_LIGHTUD;\n    case SER_TAG_INT: return LJ_DUALNUM ? IRT_INT : IRT_NUM;\n    case SER_TAG_NUM: return IRT_NUM;\n    case SER_TAG_TAB: case SER_TAG_TAB+1: case SER_TAG_TAB+2:\n    case SER_TAG_TAB+3: case SER_TAG_TAB+4: case SER_TAG_TAB+5:\n    case SER_TAG_DICT_MT:\n      return IRT_TAB;\n    case SER_TAG_INT64: case SER_TAG_UINT64: case SER_TAG_COMPLEX:\n      return IRT_CDATA;\n    case SER_TAG_DICT_STR:\n    default:\n      return IRT_STR;\n    }\n  }\n  return IRT_NIL;  /* Will fail on actual decode. */\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_serialize.h",
    "content": "/*\n** Object de/serialization.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_SERIALIZE_H\n#define _LJ_SERIALIZE_H\n\n#include \"lj_obj.h\"\n#include \"lj_buf.h\"\n\n#if LJ_HASBUFFER\n\n#define LJ_SERIALIZE_DEPTH\t100\t/* Default depth. */\n\nLJ_FUNC void LJ_FASTCALL lj_serialize_dict_prep_str(lua_State *L, GCtab *dict);\nLJ_FUNC void LJ_FASTCALL lj_serialize_dict_prep_mt(lua_State *L, GCtab *dict);\nLJ_FUNC SBufExt * LJ_FASTCALL lj_serialize_put(SBufExt *sbx, cTValue *o);\nLJ_FUNC char * LJ_FASTCALL lj_serialize_get(SBufExt *sbx, TValue *o);\nLJ_FUNC GCstr * LJ_FASTCALL lj_serialize_encode(lua_State *L, cTValue *o);\nLJ_FUNC void lj_serialize_decode(lua_State *L, TValue *o, GCstr *str);\n#if LJ_HASJIT\nLJ_FUNC MSize LJ_FASTCALL lj_serialize_peektype(SBufExt *sbx);\n#endif\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_snap.c",
    "content": "/*\n** Snapshot handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_snap_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_target.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#include \"lj_cdata.h\"\n#endif\n\n/* Pass IR on to next optimization in chain (FOLD). */\n#define emitir(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))\n\n/* Emit raw IR without passing through optimizations. */\n#define emitir_raw(ot, a, b)\t(lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))\n\n/* -- Snapshot buffer allocation ------------------------------------------ */\n\n/* Grow snapshot buffer. */\nvoid lj_snap_grow_buf_(jit_State *J, MSize need)\n{\n  MSize maxsnap = (MSize)J->param[JIT_P_maxsnap];\n  if (need > maxsnap)\n    lj_trace_err(J, LJ_TRERR_SNAPOV);\n  lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot);\n  J->cur.snap = J->snapbuf;\n}\n\n/* Grow snapshot map buffer. */\nvoid lj_snap_grow_map_(jit_State *J, MSize need)\n{\n  if (need < 2*J->sizesnapmap)\n    need = 2*J->sizesnapmap;\n  else if (need < 64)\n    need = 64;\n  J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,\n\t\t    J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry));\n  J->cur.snapmap = J->snapmapbuf;\n  J->sizesnapmap = need;\n}\n\n/* -- Snapshot generation ------------------------------------------------- */\n\n/* Add all modified slots to the snapshot. */\nstatic MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots)\n{\n  IRRef retf = J->chain[IR_RETF];  /* Limits SLOAD restore elimination. */\n  BCReg s;\n  MSize n = 0;\n  for (s = 0; s < nslots; s++) {\n    TRef tr = J->slot[s];\n    IRRef ref = tref_ref(tr);\n#if LJ_FR2\n    if (s == 1) {  /* Ignore slot 1 in LJ_FR2 mode, except if tailcalled. */\n      if ((tr & TREF_FRAME))\n\tmap[n++] = SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL);\n      continue;\n    }\n    if ((tr & (TREF_FRAME | TREF_CONT)) && !ref) {\n      cTValue *base = J->L->base - J->baseslot;\n      tr = J->slot[s] = (tr & 0xff0000) | lj_ir_k64(J, IR_KNUM, base[s].u64);\n      ref = tref_ref(tr);\n    }\n#endif\n    if (ref) {\n      SnapEntry sn = SNAP_TR(s, tr);\n      IRIns *ir = &J->cur.ir[ref];\n      if ((LJ_FR2 || !(sn & (SNAP_CONT|SNAP_FRAME))) &&\n\t  ir->o == IR_SLOAD && ir->op1 == s && ref > retf) {\n\t/*\n\t** No need to snapshot unmodified non-inherited slots.\n\t** But always snapshot the function below a frame in LJ_FR2 mode.\n\t*/\n\tif (!(ir->op2 & IRSLOAD_INHERIT) &&\n\t    (!LJ_FR2 || s == 0 || s+1 == nslots ||\n\t     !(J->slot[s+1] & (TREF_CONT|TREF_FRAME))))\n\t  continue;\n\t/* No need to restore readonly slots and unmodified non-parent slots. */\n\tif (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) &&\n\t    (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT)\n\t  sn |= SNAP_NORESTORE;\n      }\n      if (LJ_SOFTFP32 && irt_isnum(ir->t))\n\tsn |= SNAP_SOFTFPNUM;\n      map[n++] = sn;\n    }\n  }\n  return n;\n}\n\n/* Add frame links at the end of the snapshot. */\nstatic MSize snapshot_framelinks(jit_State *J, SnapEntry *map, uint8_t *topslot)\n{\n  cTValue *frame = J->L->base - 1;\n  cTValue *lim = J->L->base - J->baseslot + LJ_FR2;\n  GCfunc *fn = frame_func(frame);\n  cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top;\n#if LJ_FR2\n  uint64_t pcbase = (u64ptr(J->pc) << 8) | (J->baseslot - 2);\n  lj_assertJ(2 <= J->baseslot && J->baseslot <= 257, \"bad baseslot\");\n  memcpy(map, &pcbase, sizeof(uint64_t));\n#else\n  MSize f = 0;\n  map[f++] = SNAP_MKPC(J->pc);  /* The current PC is always the first entry. */\n#endif\n  lj_assertJ(!J->pt ||\n\t     (J->pc >= proto_bc(J->pt) &&\n\t      J->pc < proto_bc(J->pt) + J->pt->sizebc), \"bad snapshot PC\");\n  while (frame > lim) {  /* Backwards traversal of all frames above base. */\n    if (frame_islua(frame)) {\n#if !LJ_FR2\n      map[f++] = SNAP_MKPC(frame_pc(frame));\n#endif\n      frame = frame_prevl(frame);\n    } else if (frame_iscont(frame)) {\n#if !LJ_FR2\n      map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));\n      map[f++] = SNAP_MKPC(frame_contpc(frame));\n#endif\n      frame = frame_prevd(frame);\n    } else {\n      lj_assertJ(!frame_isc(frame), \"broken frame chain\");\n#if !LJ_FR2\n      map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));\n#endif\n      frame = frame_prevd(frame);\n      continue;\n    }\n    if (frame + funcproto(frame_func(frame))->framesize > ftop)\n      ftop = frame + funcproto(frame_func(frame))->framesize;\n  }\n  *topslot = (uint8_t)(ftop - lim);\n#if LJ_FR2\n  lj_assertJ(sizeof(SnapEntry) * 2 == sizeof(uint64_t), \"bad SnapEntry def\");\n  return 2;\n#else\n  lj_assertJ(f == (MSize)(1 + J->framedepth), \"miscalculated snapshot size\");\n  return f;\n#endif\n}\n\n/* Take a snapshot of the current stack. */\nstatic void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)\n{\n  BCReg nslots = J->baseslot + J->maxslot;\n  MSize nent;\n  SnapEntry *p;\n  /* Conservative estimate. */\n  lj_snap_grow_map(J, nsnapmap + nslots + (MSize)(LJ_FR2?2:J->framedepth+1));\n  p = &J->cur.snapmap[nsnapmap];\n  nent = snapshot_slots(J, p, nslots);\n  snap->nent = (uint8_t)nent;\n  nent += snapshot_framelinks(J, p + nent, &snap->topslot);\n  snap->mapofs = (uint32_t)nsnapmap;\n  snap->ref = (IRRef1)J->cur.nins;\n  snap->mcofs = 0;\n  snap->nslots = (uint8_t)nslots;\n  snap->count = 0;\n  J->cur.nsnapmap = (uint32_t)(nsnapmap + nent);\n}\n\n/* Add or merge a snapshot. */\nvoid lj_snap_add(jit_State *J)\n{\n  MSize nsnap = J->cur.nsnap;\n  MSize nsnapmap = J->cur.nsnapmap;\n  /* Merge if no ins. inbetween or if requested and no guard inbetween. */\n  if ((nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins) ||\n      (J->mergesnap && !irt_isguard(J->guardemit))) {\n    if (nsnap == 1) {  /* But preserve snap #0 PC. */\n      emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);\n      goto nomerge;\n    }\n    nsnapmap = J->cur.snap[--nsnap].mapofs;\n  } else {\n  nomerge:\n    lj_snap_grow_buf(J, nsnap+1);\n    J->cur.nsnap = (uint16_t)(nsnap+1);\n  }\n  J->mergesnap = 0;\n  J->guardemit.irt = 0;\n  snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap);\n}\n\n/* -- Snapshot modification ----------------------------------------------- */\n\n#define SNAP_USEDEF_SLOTS\t(LJ_MAX_JSLOTS+LJ_STACK_EXTRA)\n\n/* Find unused slots with reaching-definitions bytecode data-flow analysis. */\nstatic BCReg snap_usedef(jit_State *J, uint8_t *udf,\n\t\t\t const BCIns *pc, BCReg maxslot)\n{\n  BCReg s;\n  GCobj *o;\n\n  if (maxslot == 0) return 0;\n#ifdef LUAJIT_USE_VALGRIND\n  /* Avoid errors for harmless reads beyond maxslot. */\n  memset(udf, 1, SNAP_USEDEF_SLOTS);\n#else\n  memset(udf, 1, maxslot);\n#endif\n\n  /* Treat open upvalues as used. */\n  o = gcref(J->L->openupval);\n  while (o) {\n    if (uvval(gco2uv(o)) < J->L->base) break;\n    udf[uvval(gco2uv(o)) - J->L->base] = 0;\n    o = gcref(o->gch.nextgc);\n  }\n\n#define USE_SLOT(s)\t\tudf[(s)] &= ~1\n#define DEF_SLOT(s)\t\tudf[(s)] *= 3\n\n  /* Scan through following bytecode and check for uses/defs. */\n  lj_assertJ(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc,\n\t     \"snapshot PC out of range\");\n  for (;;) {\n    BCIns ins = *pc++;\n    BCOp op = bc_op(ins);\n    switch (bcmode_b(op)) {\n    case BCMvar: USE_SLOT(bc_b(ins)); break;\n    default: break;\n    }\n    switch (bcmode_c(op)) {\n    case BCMvar: USE_SLOT(bc_c(ins)); break;\n    case BCMrbase:\n      lj_assertJ(op == BC_CAT, \"unhandled op %d with RC rbase\", op);\n      for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s);\n      for (; s < maxslot; s++) DEF_SLOT(s);\n      break;\n    case BCMjump:\n    handle_jump: {\n      BCReg minslot = bc_a(ins);\n      if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT;\n      else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1;\n      else if (op == BC_UCLO) {\n\tptrdiff_t delta = bc_j(ins);\n\tif (delta < 0) return maxslot;  /* Prevent loop. */\n\tpc += delta;\n\tbreak;\n      }\n      for (s = minslot; s < maxslot; s++) DEF_SLOT(s);\n      return minslot < maxslot ? minslot : maxslot;\n      }\n    case BCMlit:\n      if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {\n\tgoto handle_jump;\n      } else if (bc_isret(op)) {\n\tBCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1);\n\tfor (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);\n\tfor (; s < top; s++) USE_SLOT(s);\n\tfor (; s < maxslot; s++) DEF_SLOT(s);\n\treturn 0;\n      }\n      break;\n    case BCMfunc: return maxslot;  /* NYI: will abort, anyway. */\n    default: break;\n    }\n    switch (bcmode_a(op)) {\n    case BCMvar: USE_SLOT(bc_a(ins)); break;\n    case BCMdst:\n       if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins));\n       break;\n    case BCMbase:\n      if (op >= BC_CALLM && op <= BC_ITERN) {\n\tBCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ?\n\t\t    maxslot : (bc_a(ins) + bc_c(ins)+LJ_FR2);\n\tif (LJ_FR2) DEF_SLOT(bc_a(ins)+1);\n\ts = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0);\n\tfor (; s < top; s++) USE_SLOT(s);\n\tfor (; s < maxslot; s++) DEF_SLOT(s);\n\tif (op == BC_CALLT || op == BC_CALLMT) {\n\t  for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);\n\t  return 0;\n\t}\n      } else if (op == BC_VARG) {\n\treturn maxslot;  /* NYI: punt. */\n      } else if (op == BC_KNIL) {\n\tfor (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s);\n      } else if (op == BC_TSETM) {\n\tfor (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s);\n      }\n      break;\n    default: break;\n    }\n    lj_assertJ(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc,\n\t       \"use/def analysis PC out of range\");\n  }\n\n#undef USE_SLOT\n#undef DEF_SLOT\n\n  return 0;  /* unreachable */\n}\n\n/* Mark slots used by upvalues of child prototypes as used. */\nvoid snap_useuv(GCproto *pt, uint8_t *udf)\n{\n  /* This is a coarse check, because it's difficult to correlate the lifetime\n  ** of slots and closures. But the number of false positives is quite low.\n  ** A false positive may cause a slot not to be purged, which is just\n  ** a missed optimization.\n  */\n  if ((pt->flags & PROTO_CHILD)) {\n    ptrdiff_t i, j, n = pt->sizekgc;\n    GCRef *kr = mref(pt->k, GCRef) - 1;\n    for (i = 0; i < n; i++, kr--) {\n      GCobj *o = gcref(*kr);\n      if (o->gch.gct == ~LJ_TPROTO) {\n\tfor (j = 0; j < gco2pt(o)->sizeuv; j++) {\n\t  uint32_t v = proto_uv(gco2pt(o))[j];\n\t  if ((v & PROTO_UV_LOCAL)) {\n\t    udf[(v & 0xff)] = 0;\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n/* Purge dead slots before the next snapshot. */\nvoid lj_snap_purge(jit_State *J)\n{\n  uint8_t udf[SNAP_USEDEF_SLOTS];\n  BCReg s, maxslot = J->maxslot;\n  if (bc_op(*J->pc) == BC_FUNCV && maxslot > J->pt->numparams)\n    maxslot = J->pt->numparams;\n  s = snap_usedef(J, udf, J->pc, maxslot);\n  if (s < maxslot) {\n    snap_useuv(J->pt, udf);\n    for (; s < maxslot; s++)\n      if (udf[s] != 0)\n\tJ->base[s] = 0;  /* Purge dead slots. */\n  }\n}\n\n/* Shrink last snapshot. */\nvoid lj_snap_shrink(jit_State *J)\n{\n  SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];\n  SnapEntry *map = &J->cur.snapmap[snap->mapofs];\n  MSize n, m, nlim, nent = snap->nent;\n  uint8_t udf[SNAP_USEDEF_SLOTS];\n  BCReg maxslot = J->maxslot;\n  BCReg baseslot = J->baseslot;\n  BCReg minslot = snap_usedef(J, udf, snap_pc(&map[nent]), maxslot);\n  if (minslot < maxslot) snap_useuv(J->pt, udf);\n  maxslot += baseslot;\n  minslot += baseslot;\n  snap->nslots = (uint8_t)maxslot;\n  for (n = m = 0; n < nent; n++) {  /* Remove unused slots from snapshot. */\n    BCReg s = snap_slot(map[n]);\n    if (s < minslot || (s < maxslot && udf[s-baseslot] == 0))\n      map[m++] = map[n];  /* Only copy used slots. */\n  }\n  snap->nent = (uint8_t)m;\n  nlim = J->cur.nsnapmap - snap->mapofs - 1;\n  while (n <= nlim) map[m++] = map[n++];  /* Move PC + frame links down. */\n  J->cur.nsnapmap = (uint32_t)(snap->mapofs + m);  /* Free up space in map. */\n}\n\n/* -- Snapshot access ----------------------------------------------------- */\n\n/* Initialize a Bloom Filter with all renamed refs.\n** There are very few renames (often none), so the filter has\n** very few bits set. This makes it suitable for negative filtering.\n*/\nstatic BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim)\n{\n  BloomFilter rfilt = 0;\n  IRIns *ir;\n  for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)\n    if (ir->op2 <= lim)\n      bloomset(rfilt, ir->op1);\n  return rfilt;\n}\n\n/* Process matching renames to find the original RegSP. */\nstatic RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs)\n{\n  IRIns *ir;\n  for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)\n    if (ir->op1 == ref && ir->op2 <= lim)\n      rs = ir->prev;\n  return rs;\n}\n\n/* Copy RegSP from parent snapshot to the parent links of the IR. */\nIRIns *lj_snap_regspmap(jit_State *J, GCtrace *T, SnapNo snapno, IRIns *ir)\n{\n  SnapShot *snap = &T->snap[snapno];\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n  BloomFilter rfilt = snap_renamefilter(T, snapno);\n  MSize n = 0;\n  IRRef ref = 0;\n  UNUSED(J);\n  for ( ; ; ir++) {\n    uint32_t rs;\n    if (ir->o == IR_SLOAD) {\n      if (!(ir->op2 & IRSLOAD_PARENT)) break;\n      for ( ; ; n++) {\n\tlj_assertJ(n < snap->nent, \"slot %d not found in snapshot\", ir->op1);\n\tif (snap_slot(map[n]) == ir->op1) {\n\t  ref = snap_ref(map[n++]);\n\t  break;\n\t}\n      }\n    } else if (LJ_SOFTFP32 && ir->o == IR_HIOP) {\n      ref++;\n    } else if (ir->o == IR_PVAL) {\n      ref = ir->op1 + REF_BIAS;\n    } else {\n      break;\n    }\n    rs = T->ir[ref].prev;\n    if (bloomtest(rfilt, ref))\n      rs = snap_renameref(T, snapno, ref, rs);\n    ir->prev = (uint16_t)rs;\n    lj_assertJ(regsp_used(rs), \"unused IR %04d in snapshot\", ref - REF_BIAS);\n  }\n  return ir;\n}\n\n/* -- Snapshot replay ----------------------------------------------------- */\n\n/* Replay constant from parent trace. */\nstatic TRef snap_replay_const(jit_State *J, IRIns *ir)\n{\n  /* Only have to deal with constants that can occur in stack slots. */\n  switch ((IROp)ir->o) {\n  case IR_KPRI: return TREF_PRI(irt_type(ir->t));\n  case IR_KINT: return lj_ir_kint(J, ir->i);\n  case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t));\n  case IR_KNUM: case IR_KINT64:\n    return lj_ir_k64(J, (IROp)ir->o, ir_k64(ir)->u64);\n  case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir));  /* Continuation. */\n  default: lj_assertJ(0, \"bad IR constant op %d\", ir->o); return TREF_NIL;\n  }\n}\n\n/* De-duplicate parent reference. */\nstatic TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref)\n{\n  MSize j;\n  for (j = 0; j < nmax; j++)\n    if (snap_ref(map[j]) == ref)\n      return J->slot[snap_slot(map[j])] & ~(SNAP_KEYINDEX|SNAP_CONT|SNAP_FRAME);\n  return 0;\n}\n\n/* Emit parent reference with de-duplication. */\nstatic TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax,\n\t\t      BloomFilter seen, IRRef ref)\n{\n  IRIns *ir = &T->ir[ref];\n  TRef tr;\n  if (irref_isk(ref))\n    tr = snap_replay_const(J, ir);\n  else if (!regsp_used(ir->prev))\n    tr = 0;\n  else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0)\n    tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0);\n  return tr;\n}\n\n/* Check whether a sunk store corresponds to an allocation. Slow path. */\nstatic int snap_sunk_store2(GCtrace *T, IRIns *ira, IRIns *irs)\n{\n  if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n      irs->o == IR_FSTORE || irs->o == IR_XSTORE) {\n    IRIns *irk = &T->ir[irs->op1];\n    if (irk->o == IR_AREF || irk->o == IR_HREFK)\n      irk = &T->ir[irk->op1];\n    return (&T->ir[irk->op1] == ira);\n  }\n  return 0;\n}\n\n/* Check whether a sunk store corresponds to an allocation. Fast path. */\nstatic LJ_AINLINE int snap_sunk_store(GCtrace *T, IRIns *ira, IRIns *irs)\n{\n  if (irs->s != 255)\n    return (ira + irs->s == irs);  /* Fast check. */\n  return snap_sunk_store2(T, ira, irs);\n}\n\n/* Replay snapshot state to setup side trace. */\nvoid lj_snap_replay(jit_State *J, GCtrace *T)\n{\n  SnapShot *snap = &T->snap[J->exitno];\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n  MSize n, nent = snap->nent;\n  BloomFilter seen = 0;\n  int pass23 = 0;\n  J->framedepth = 0;\n  /* Emit IR for slots inherited from parent snapshot. */\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    BCReg s = snap_slot(sn);\n    IRRef ref = snap_ref(sn);\n    IRIns *ir = &T->ir[ref];\n    TRef tr;\n    /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */\n    if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0)\n      goto setslot;\n    bloomset(seen, ref);\n    if (irref_isk(ref)) {\n      /* See special treatment of LJ_FR2 slot 1 in snapshot_slots() above. */\n      if (LJ_FR2 && (sn == SNAP(1, SNAP_FRAME | SNAP_NORESTORE, REF_NIL)))\n\ttr = 0;\n      else\n\ttr = snap_replay_const(J, ir);\n    } else if (!regsp_used(ir->prev)) {\n      pass23 = 1;\n      lj_assertJ(s != 0, \"unused slot 0 in snapshot\");\n      tr = s;\n    } else {\n      IRType t = irt_type(ir->t);\n      uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT;\n      if (LJ_SOFTFP32 && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM;\n      if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY);\n      if ((sn & SNAP_KEYINDEX)) mode |= IRSLOAD_KEYINDEX;\n      tr = emitir_raw(IRT(IR_SLOAD, t), s, mode);\n    }\n  setslot:\n    /* Same as TREF_* flags. */\n    J->slot[s] = tr | (sn&(SNAP_KEYINDEX|SNAP_CONT|SNAP_FRAME));\n    J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && (s != LJ_FR2));\n    if ((sn & SNAP_FRAME))\n      J->baseslot = s+1;\n  }\n  if (pass23) {\n    IRIns *irlast = &T->ir[snap->ref];\n    pass23 = 0;\n    /* Emit dependent PVALs. */\n    for (n = 0; n < nent; n++) {\n      SnapEntry sn = map[n];\n      IRRef refp = snap_ref(sn);\n      IRIns *ir = &T->ir[refp];\n      if (regsp_reg(ir->r) == RID_SUNK) {\n\tif (J->slot[snap_slot(sn)] != snap_slot(sn)) continue;\n\tpass23 = 1;\n\tlj_assertJ(ir->o == IR_TNEW || ir->o == IR_TDUP ||\n\t\t   ir->o == IR_CNEW || ir->o == IR_CNEWI,\n\t\t   \"sunk parent IR %04d has bad op %d\", refp - REF_BIAS, ir->o);\n\tif (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1);\n\tif (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2);\n\tif (LJ_HASFFI && ir->o == IR_CNEWI) {\n\t  if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP)\n\t    snap_pref(J, T, map, nent, seen, (ir+1)->op2);\n\t} else {\n\t  IRIns *irs;\n\t  for (irs = ir+1; irs < irlast; irs++)\n\t    if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t      if (snap_pref(J, T, map, nent, seen, irs->op2) == 0)\n\t\tsnap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1);\n\t      else if ((LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)) &&\n\t\t       irs+1 < irlast && (irs+1)->o == IR_HIOP)\n\t\tsnap_pref(J, T, map, nent, seen, (irs+1)->op2);\n\t    }\n\t}\n      } else if (!irref_isk(refp) && !regsp_used(ir->prev)) {\n\tlj_assertJ(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT,\n\t\t   \"sunk parent IR %04d has bad op %d\", refp - REF_BIAS, ir->o);\n\tJ->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1);\n      }\n    }\n    /* Replay sunk instructions. */\n    for (n = 0; pass23 && n < nent; n++) {\n      SnapEntry sn = map[n];\n      IRRef refp = snap_ref(sn);\n      IRIns *ir = &T->ir[refp];\n      if (regsp_reg(ir->r) == RID_SUNK) {\n\tTRef op1, op2;\n\tif (J->slot[snap_slot(sn)] != snap_slot(sn)) {  /* De-dup allocs. */\n\t  J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]];\n\t  continue;\n\t}\n\top1 = ir->op1;\n\tif (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1);\n\top2 = ir->op2;\n\tif (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2);\n\tif (LJ_HASFFI && ir->o == IR_CNEWI) {\n\t  if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) {\n\t    lj_needsplit(J);  /* Emit joining HIOP. */\n\t    op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2,\n\t\t\t     snap_pref(J, T, map, nent, seen, (ir+1)->op2));\n\t  }\n\t  J->slot[snap_slot(sn)] = emitir(ir->ot & ~(IRT_MARK|IRT_ISPHI), op1, op2);\n\t} else {\n\t  IRIns *irs;\n\t  TRef tr = emitir(ir->ot, op1, op2);\n\t  J->slot[snap_slot(sn)] = tr;\n\t  for (irs = ir+1; irs < irlast; irs++)\n\t    if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t      IRIns *irr = &T->ir[irs->op1];\n\t      TRef val, key = irr->op2, tmp = tr;\n\t      if (irr->o != IR_FREF) {\n\t\tIRIns *irk = &T->ir[key];\n\t\tif (irr->o == IR_HREFK)\n\t\t  key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]),\n\t\t\t\t    irk->op2);\n\t\telse\n\t\t  key = snap_replay_const(J, irk);\n\t\tif (irr->o == IR_HREFK || irr->o == IR_AREF) {\n\t\t  IRIns *irf = &T->ir[irr->op1];\n\t\t  tmp = emitir(irf->ot, tmp, irf->op2);\n\t\t}\n\t      }\n\t      tmp = emitir(irr->ot, tmp, key);\n\t      val = snap_pref(J, T, map, nent, seen, irs->op2);\n\t      if (val == 0) {\n\t\tIRIns *irc = &T->ir[irs->op2];\n\t\tlj_assertJ(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT,\n\t\t\t   \"sunk store for parent IR %04d with bad op %d\",\n\t\t\t   refp - REF_BIAS, irc->o);\n\t\tval = snap_pref(J, T, map, nent, seen, irc->op1);\n\t\tval = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);\n\t      } else if ((LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)) &&\n\t\t\t irs+1 < irlast && (irs+1)->o == IR_HIOP) {\n\t\tIRType t = IRT_I64;\n\t\tif (LJ_SOFTFP32 && irt_type((irs+1)->t) == IRT_SOFTFP)\n\t\t  t = IRT_NUM;\n\t\tlj_needsplit(J);\n\t\tif (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) {\n\t\t  uint64_t k = (uint32_t)T->ir[irs->op2].i +\n\t\t\t       ((uint64_t)T->ir[(irs+1)->op2].i << 32);\n\t\t  val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM, k);\n\t\t} else {\n\t\t  val = emitir_raw(IRT(IR_HIOP, t), val,\n\t\t\t  snap_pref(J, T, map, nent, seen, (irs+1)->op2));\n\t\t}\n\t\ttmp = emitir(IRT(irs->o, t), tmp, val);\n\t\tcontinue;\n\t      }\n\t      tmp = emitir(irs->ot, tmp, val);\n\t    } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) {\n\t      emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);\n\t    }\n\t}\n      }\n    }\n  }\n  J->base = J->slot + J->baseslot;\n  J->maxslot = snap->nslots - J->baseslot;\n  lj_snap_add(J);\n  if (pass23)  /* Need explicit GC step _after_ initial snapshot. */\n    emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0);\n}\n\n/* -- Snapshot restore ---------------------------------------------------- */\n\nstatic void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\tSnapNo snapno, BloomFilter rfilt,\n\t\t\tIRIns *ir, TValue *o);\n\n/* Restore a value from the trace exit state. */\nstatic void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\t    SnapNo snapno, BloomFilter rfilt,\n\t\t\t    IRRef ref, TValue *o)\n{\n  IRIns *ir = &T->ir[ref];\n  IRType1 t = ir->t;\n  RegSP rs = ir->prev;\n  if (irref_isk(ref)) {  /* Restore constant slot. */\n    if (ir->o == IR_KPTR) {\n      o->u64 = (uint64_t)(uintptr_t)ir_kptr(ir);\n    } else {\n      lj_assertJ(!(ir->o == IR_KKPTR || ir->o == IR_KNULL),\n\t\t \"restore of const from IR %04d with bad op %d\",\n\t\t ref - REF_BIAS, ir->o);\n      lj_ir_kvalue(J->L, o, ir);\n    }\n    return;\n  }\n  if (LJ_UNLIKELY(bloomtest(rfilt, ref)))\n    rs = snap_renameref(T, snapno, ref, rs);\n  if (ra_hasspill(regsp_spill(rs))) {  /* Restore from spill slot. */\n    int32_t *sps = &ex->spill[regsp_spill(rs)];\n    if (irt_isinteger(t)) {\n      setintV(o, *sps);\n#if !LJ_SOFTFP32\n    } else if (irt_isnum(t)) {\n      o->u64 = *(uint64_t *)sps;\n#endif\n#if LJ_64 && !LJ_GC64\n    } else if (irt_islightud(t)) {\n      /* 64 bit lightuserdata which may escape already has the tag bits. */\n      o->u64 = *(uint64_t *)sps;\n#endif\n    } else {\n      lj_assertJ(!irt_ispri(t), \"PRI ref with spill slot\");\n      setgcV(J->L, o, (GCobj *)(uintptr_t)*(GCSize *)sps, irt_toitype(t));\n    }\n  } else {  /* Restore from register. */\n    Reg r = regsp_reg(rs);\n    if (ra_noreg(r)) {\n      lj_assertJ(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT,\n\t\t \"restore from IR %04d has no reg\", ref - REF_BIAS);\n      snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o);\n      if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o));\n      return;\n    } else if (irt_isinteger(t)) {\n      setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);\n#if !LJ_SOFTFP\n    } else if (irt_isnum(t)) {\n      setnumV(o, ex->fpr[r-RID_MIN_FPR]);\n#elif LJ_64  /* && LJ_SOFTFP */\n    } else if (irt_isnum(t)) {\n      o->u64 = ex->gpr[r-RID_MIN_GPR];\n#endif\n#if LJ_64 && !LJ_GC64\n    } else if (irt_is64(t)) {\n      /* 64 bit values that already have the tag bits. */\n      o->u64 = ex->gpr[r-RID_MIN_GPR];\n#endif\n    } else if (irt_ispri(t)) {\n      setpriV(o, irt_toitype(t));\n    } else {\n      setgcV(J->L, o, (GCobj *)ex->gpr[r-RID_MIN_GPR], irt_toitype(t));\n    }\n  }\n}\n\n#if LJ_HASFFI\n/* Restore raw data from the trace exit state. */\nstatic void snap_restoredata(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\t     SnapNo snapno, BloomFilter rfilt,\n\t\t\t     IRRef ref, void *dst, CTSize sz)\n{\n  IRIns *ir = &T->ir[ref];\n  RegSP rs = ir->prev;\n  int32_t *src;\n  uint64_t tmp;\n  UNUSED(J);\n  if (irref_isk(ref)) {\n    if (ir_isk64(ir)) {\n      src = (int32_t *)&ir[1];\n    } else if (sz == 8) {\n      tmp = (uint64_t)(uint32_t)ir->i;\n      src = (int32_t *)&tmp;\n    } else {\n      src = &ir->i;\n    }\n  } else {\n    if (LJ_UNLIKELY(bloomtest(rfilt, ref)))\n      rs = snap_renameref(T, snapno, ref, rs);\n    if (ra_hasspill(regsp_spill(rs))) {\n      src = &ex->spill[regsp_spill(rs)];\n      if (sz == 8 && !irt_is64(ir->t)) {\n\ttmp = (uint64_t)(uint32_t)*src;\n\tsrc = (int32_t *)&tmp;\n      }\n    } else {\n      Reg r = regsp_reg(rs);\n      if (ra_noreg(r)) {\n\t/* Note: this assumes CNEWI is never used for SOFTFP split numbers. */\n\tlj_assertJ(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT,\n\t\t   \"restore from IR %04d has no reg\", ref - REF_BIAS);\n\tsnap_restoredata(J, T, ex, snapno, rfilt, ir->op1, dst, 4);\n\t*(lua_Number *)dst = (lua_Number)*(int32_t *)dst;\n\treturn;\n      }\n      src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];\n#if !LJ_SOFTFP\n      if (r >= RID_MAX_GPR) {\n\tsrc = (int32_t *)&ex->fpr[r-RID_MIN_FPR];\n#if LJ_TARGET_PPC\n\tif (sz == 4) {  /* PPC FPRs are always doubles. */\n\t  *(float *)dst = (float)*(double *)src;\n\t  return;\n\t}\n#else\n\tif (LJ_BE && sz == 4) src++;\n#endif\n      } else\n#endif\n      if (LJ_64 && LJ_BE && sz == 4) src++;\n    }\n  }\n  lj_assertJ(sz == 1 || sz == 2 || sz == 4 || sz == 8,\n\t     \"restore from IR %04d with bad size %d\", ref - REF_BIAS, sz);\n  if (sz == 4) *(int32_t *)dst = *src;\n  else if (sz == 8) *(int64_t *)dst = *(int64_t *)src;\n  else if (sz == 1) *(int8_t *)dst = (int8_t)*src;\n  else *(int16_t *)dst = (int16_t)*src;\n}\n#endif\n\n/* Unsink allocation from the trace exit state. Unsink sunk stores. */\nstatic void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,\n\t\t\tSnapNo snapno, BloomFilter rfilt,\n\t\t\tIRIns *ir, TValue *o)\n{\n  lj_assertJ(ir->o == IR_TNEW || ir->o == IR_TDUP ||\n\t     ir->o == IR_CNEW || ir->o == IR_CNEWI,\n\t     \"sunk allocation with bad op %d\", ir->o);\n#if LJ_HASFFI\n  if (ir->o == IR_CNEW || ir->o == IR_CNEWI) {\n    CTState *cts = ctype_cts(J->L);\n    CTypeID id = (CTypeID)T->ir[ir->op1].i;\n    CTSize sz;\n    CTInfo info = lj_ctype_info(cts, id, &sz);\n    GCcdata *cd = lj_cdata_newx(cts, id, sz, info);\n    setcdataV(J->L, o, cd);\n    if (ir->o == IR_CNEWI) {\n      uint8_t *p = (uint8_t *)cdataptr(cd);\n      lj_assertJ(sz == 4 || sz == 8, \"sunk cdata with bad size %d\", sz);\n      if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) {\n\tsnap_restoredata(J, T, ex, snapno, rfilt, (ir+1)->op2,\n\t\t\t LJ_LE ? p+4 : p, 4);\n\tif (LJ_BE) p += 4;\n\tsz = 4;\n      }\n      snap_restoredata(J, T, ex, snapno, rfilt, ir->op2, p, sz);\n    } else {\n      IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref];\n      for (irs = ir+1; irs < irlast; irs++)\n\tif (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\t  IRIns *iro = &T->ir[T->ir[irs->op1].op2];\n\t  uint8_t *p = (uint8_t *)cd;\n\t  CTSize szs;\n\t  lj_assertJ(irs->o == IR_XSTORE, \"sunk store with bad op %d\", irs->o);\n\t  lj_assertJ(T->ir[irs->op1].o == IR_ADD,\n\t\t     \"sunk store with bad add op %d\", T->ir[irs->op1].o);\n\t  lj_assertJ(iro->o == IR_KINT || iro->o == IR_KINT64,\n\t\t     \"sunk store with bad const offset op %d\", iro->o);\n\t  if (irt_is64(irs->t)) szs = 8;\n\t  else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1;\n\t  else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2;\n\t  else szs = 4;\n\t  if (LJ_64 && iro->o == IR_KINT64)\n\t    p += (int64_t)ir_k64(iro)->u64;\n\t  else\n\t    p += iro->i;\n\t  lj_assertJ(p >= (uint8_t *)cdataptr(cd) &&\n\t\t     p + szs <= (uint8_t *)cdataptr(cd) + sz,\n\t\t     \"sunk store with offset out of range\");\n\t  if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {\n\t    lj_assertJ(szs == 4, \"sunk store with bad size %d\", szs);\n\t    snap_restoredata(J, T, ex, snapno, rfilt, (irs+1)->op2,\n\t\t\t     LJ_LE ? p+4 : p, 4);\n\t    if (LJ_BE) p += 4;\n\t  }\n\t  snap_restoredata(J, T, ex, snapno, rfilt, irs->op2, p, szs);\n\t}\n    }\n  } else\n#endif\n  {\n    IRIns *irs, *irlast;\n    GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) :\n\t\t\t\t  lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1]));\n    settabV(J->L, o, t);\n    irlast = &T->ir[T->snap[snapno].ref];\n    for (irs = ir+1; irs < irlast; irs++)\n      if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {\n\tIRIns *irk = &T->ir[irs->op1];\n\tTValue tmp, *val;\n\tlj_assertJ(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||\n\t\t   irs->o == IR_FSTORE,\n\t\t   \"sunk store with bad op %d\", irs->o);\n\tif (irk->o == IR_FREF) {\n\t  lj_assertJ(irk->op2 == IRFL_TAB_META,\n\t\t     \"sunk store with bad field %d\", irk->op2);\n\t  snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp);\n\t  /* NOBARRIER: The table is new (marked white). */\n\t  setgcref(t->metatable, obj2gco(tabV(&tmp)));\n\t} else {\n\t  irk = &T->ir[irk->op2];\n\t  if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1];\n\t  lj_ir_kvalue(J->L, &tmp, irk);\n\t  val = lj_tab_set(J->L, t, &tmp);\n\t  /* NOBARRIER: The table is new (marked white). */\n\t  snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val);\n\t  if (LJ_SOFTFP32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {\n\t    snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp);\n\t    val->u32.hi = tmp.u32.lo;\n\t  }\n\t}\n      }\n  }\n}\n\n/* Restore interpreter state from exit state with the help of a snapshot. */\nconst BCIns *lj_snap_restore(jit_State *J, void *exptr)\n{\n  ExitState *ex = (ExitState *)exptr;\n  SnapNo snapno = J->exitno;  /* For now, snapno == exitno. */\n  GCtrace *T = traceref(J, J->parent);\n  SnapShot *snap = &T->snap[snapno];\n  MSize n, nent = snap->nent;\n  SnapEntry *map = &T->snapmap[snap->mapofs];\n#if !LJ_FR2 || defined(LUA_USE_ASSERT)\n  SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1-LJ_FR2];\n#endif\n#if !LJ_FR2\n  ptrdiff_t ftsz0;\n#endif\n  TValue *frame;\n  BloomFilter rfilt = snap_renamefilter(T, snapno);\n  const BCIns *pc = snap_pc(&map[nent]);\n  lua_State *L = J->L;\n\n  /* Set interpreter PC to the next PC to get correct error messages. */\n  setcframe_pc(cframe_raw(L->cframe), pc+1);\n\n  /* Make sure the stack is big enough for the slots from the snapshot. */\n  if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) {\n    L->top = curr_topL(L);\n    lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize);\n  }\n\n  /* Fill stack slots with data from the registers and spill slots. */\n  frame = L->base-1-LJ_FR2;\n#if !LJ_FR2\n  ftsz0 = frame_ftsz(frame);  /* Preserve link to previous frame in slot #0. */\n#endif\n  for (n = 0; n < nent; n++) {\n    SnapEntry sn = map[n];\n    if (!(sn & SNAP_NORESTORE)) {\n      TValue *o = &frame[snap_slot(sn)];\n      IRRef ref = snap_ref(sn);\n      IRIns *ir = &T->ir[ref];\n      if (ir->r == RID_SUNK) {\n\tMSize j;\n\tfor (j = 0; j < n; j++)\n\t  if (snap_ref(map[j]) == ref) {  /* De-duplicate sunk allocations. */\n\t    copyTV(L, o, &frame[snap_slot(map[j])]);\n\t    goto dupslot;\n\t  }\n\tsnap_unsink(J, T, ex, snapno, rfilt, ir, o);\n      dupslot:\n\tcontinue;\n      }\n      snap_restoreval(J, T, ex, snapno, rfilt, ref, o);\n      if (LJ_SOFTFP32 && (sn & SNAP_SOFTFPNUM) && tvisint(o)) {\n\tTValue tmp;\n\tsnap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp);\n\to->u32.hi = tmp.u32.lo;\n#if !LJ_FR2\n      } else if ((sn & (SNAP_CONT|SNAP_FRAME))) {\n\t/* Overwrite tag with frame link. */\n\tsetframe_ftsz(o, snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0);\n\tL->base = o+1;\n#endif\n      } else if ((sn & SNAP_KEYINDEX)) {\n\t/* A IRT_INT key index slot is restored as a number. Undo this. */\n\to->u32.lo = (uint32_t)(LJ_DUALNUM ? intV(o) : lj_num2int(numV(o)));\n\to->u32.hi = LJ_KEYINDEX;\n      }\n    }\n  }\n#if LJ_FR2\n  L->base += (map[nent+LJ_BE] & 0xff);\n#endif\n  lj_assertJ(map + nent == flinks, \"inconsistent frames in snapshot\");\n\n  /* Compute current stack top. */\n  switch (bc_op(*pc)) {\n  default:\n    if (bc_op(*pc) < BC_FUNCF) {\n      L->top = curr_topL(L);\n      break;\n    }\n    /* fallthrough */\n  case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM:\n    L->top = frame + snap->nslots;\n    break;\n  }\n  return pc;\n}\n\n#undef emitir_raw\n#undef emitir\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_snap.h",
    "content": "/*\n** Snapshot handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_SNAP_H\n#define _LJ_SNAP_H\n\n#include \"lj_obj.h\"\n#include \"lj_jit.h\"\n\n#if LJ_HASJIT\nLJ_FUNC void lj_snap_add(jit_State *J);\nLJ_FUNC void lj_snap_purge(jit_State *J);\nLJ_FUNC void lj_snap_shrink(jit_State *J);\nLJ_FUNC IRIns *lj_snap_regspmap(jit_State *J, GCtrace *T, SnapNo snapno,\n\t\t\t\tIRIns *ir);\nLJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T);\nLJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr);\nLJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need);\nLJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need);\n\nstatic LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need)\n{\n  if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need);\n}\n\nstatic LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need)\n{\n  if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need);\n}\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_state.c",
    "content": "/*\n** State and stack handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_state_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_func.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_frame.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_trace.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_prng.h\"\n#include \"lj_lex.h\"\n#include \"lj_alloc.h\"\n#include \"luajit.h\"\n\n/* -- Stack handling ------------------------------------------------------ */\n\n/* Stack sizes. */\n#define LJ_STACK_MIN\tLUA_MINSTACK\t/* Min. stack size. */\n#define LJ_STACK_MAX\tLUAI_MAXSTACK\t/* Max. stack size. */\n#define LJ_STACK_START\t(2*LJ_STACK_MIN)\t/* Starting stack size. */\n#define LJ_STACK_MAXEX\t(LJ_STACK_MAX + 1 + LJ_STACK_EXTRA)\n\n/* Explanation of LJ_STACK_EXTRA:\n**\n** Calls to metamethods store their arguments beyond the current top\n** without checking for the stack limit. This avoids stack resizes which\n** would invalidate passed TValue pointers. The stack check is performed\n** later by the function header. This can safely resize the stack or raise\n** an error. Thus we need some extra slots beyond the current stack limit.\n**\n** Most metamethods need 4 slots above top (cont, mobj, arg1, arg2) plus\n** one extra slot if mobj is not a function. Only lj_meta_tset needs 5\n** slots above top, but then mobj is always a function. So we can get by\n** with 5 extra slots.\n** LJ_FR2: We need 2 more slots for the frame PC and the continuation PC.\n*/\n\n/* Resize stack slots and adjust pointers in state. */\nstatic void resizestack(lua_State *L, MSize n)\n{\n  TValue *st, *oldst = tvref(L->stack);\n  ptrdiff_t delta;\n  MSize oldsize = L->stacksize;\n  MSize realsize = n + 1 + LJ_STACK_EXTRA;\n  GCobj *up;\n  lj_assertL((MSize)(tvref(L->maxstack)-oldst) == L->stacksize-LJ_STACK_EXTRA-1,\n\t     \"inconsistent stack size\");\n  st = (TValue *)lj_mem_realloc(L, tvref(L->stack),\n\t\t\t\t(MSize)(oldsize*sizeof(TValue)),\n\t\t\t\t(MSize)(realsize*sizeof(TValue)));\n  setmref(L->stack, st);\n  delta = (char *)st - (char *)oldst;\n  setmref(L->maxstack, st + n);\n  while (oldsize < realsize)  /* Clear new slots. */\n    setnilV(st + oldsize++);\n  L->stacksize = realsize;\n  if ((size_t)(mref(G(L)->jit_base, char) - (char *)oldst) < oldsize)\n    setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta);\n  L->base = (TValue *)((char *)L->base + delta);\n  L->top = (TValue *)((char *)L->top + delta);\n  for (up = gcref(L->openupval); up != NULL; up = gcnext(up))\n    setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta));\n}\n\n/* Relimit stack after error, in case the limit was overdrawn. */\nvoid lj_state_relimitstack(lua_State *L)\n{\n  if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1)\n    resizestack(L, LJ_STACK_MAX);\n}\n\n/* Try to shrink the stack (called from GC). */\nvoid lj_state_shrinkstack(lua_State *L, MSize used)\n{\n  if (L->stacksize > LJ_STACK_MAXEX)\n    return;  /* Avoid stack shrinking while handling stack overflow. */\n  if (4*used < L->stacksize &&\n      2*(LJ_STACK_START+LJ_STACK_EXTRA) < L->stacksize &&\n      /* Don't shrink stack of live trace. */\n      (tvref(G(L)->jit_base) == NULL || obj2gco(L) != gcref(G(L)->cur_L)))\n    resizestack(L, L->stacksize >> 1);\n}\n\n/* Try to grow stack. */\nvoid LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)\n{\n  MSize n;\n  if (L->stacksize > LJ_STACK_MAXEX)  /* Overflow while handling overflow? */\n    lj_err_throw(L, LUA_ERRERR);\n  n = L->stacksize + need;\n  if (n > LJ_STACK_MAX) {\n    n += 2*LUA_MINSTACK;\n  } else if (n < 2*L->stacksize) {\n    n = 2*L->stacksize;\n    if (n >= LJ_STACK_MAX)\n      n = LJ_STACK_MAX;\n  }\n  resizestack(L, n);\n  if (L->stacksize > LJ_STACK_MAXEX)\n    lj_err_msg(L, LJ_ERR_STKOV);\n}\n\nvoid LJ_FASTCALL lj_state_growstack1(lua_State *L)\n{\n  lj_state_growstack(L, 1);\n}\n\n/* Allocate basic stack for new state. */\nstatic void stack_init(lua_State *L1, lua_State *L)\n{\n  TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue);\n  setmref(L1->stack, st);\n  L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA;\n  stend = st + L1->stacksize;\n  setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1);\n  setthreadV(L1, st++, L1);  /* Needed for curr_funcisL() on empty stack. */\n  if (LJ_FR2) setnilV(st++);\n  L1->base = L1->top = st;\n  while (st < stend)  /* Clear new slots. */\n    setnilV(st++);\n}\n\n/* -- State handling ------------------------------------------------------ */\n\n/* Open parts that may cause memory-allocation errors. */\nstatic TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  global_State *g = G(L);\n  UNUSED(dummy);\n  UNUSED(ud);\n  stack_init(L, L);\n  /* NOBARRIER: State initialization, all objects are white. */\n  setgcref(L->env, obj2gco(lj_tab_new(L, 0, LJ_MIN_GLOBAL)));\n  settabV(L, registry(L), lj_tab_new(L, 0, LJ_MIN_REGISTRY));\n  lj_str_init(L);\n  lj_meta_init(L);\n  lj_lex_init(L);\n  fixstring(lj_err_str(L, LJ_ERR_ERRMEM));  /* Preallocate memory error msg. */\n  g->gc.threshold = 4*g->gc.total;\n  lj_trace_initstate(g);\n  lj_err_verify();\n  return NULL;\n}\n\nstatic void close_state(lua_State *L)\n{\n  global_State *g = G(L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lj_gc_freeall(g);\n  lj_assertG(gcref(g->gc.root) == obj2gco(L),\n\t     \"main thread is not first GC object\");\n  lj_assertG(g->str.num == 0, \"leaked %d strings\", g->str.num);\n  lj_trace_freestate(g);\n#if LJ_HASFFI\n  lj_ctype_freestate(g);\n#endif\n  lj_str_freetab(g);\n  lj_buf_free(g, &g->tmpbuf);\n  lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);\n#if LJ_64\n  if (mref(g->gc.lightudseg, uint32_t)) {\n    MSize segnum = g->gc.lightudnum ? (2 << lj_fls(g->gc.lightudnum)) : 2;\n    lj_mem_freevec(g, mref(g->gc.lightudseg, uint32_t), segnum, uint32_t);\n  }\n#endif\n  lj_assertG(g->gc.total == sizeof(GG_State),\n\t     \"memory leak of %lld bytes\",\n\t     (long long)(g->gc.total - sizeof(GG_State)));\n#ifndef LUAJIT_USE_SYSMALLOC\n  if (g->allocf == lj_alloc_f)\n    lj_alloc_destroy(g->allocd);\n  else\n#endif\n    g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0);\n}\n\n#if LJ_64 && !LJ_GC64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC))\nlua_State *lj_state_newstate(lua_Alloc allocf, void *allocd)\n#else\nLUA_API lua_State *lua_newstate(lua_Alloc allocf, void *allocd)\n#endif\n{\n  PRNGState prng;\n  GG_State *GG;\n  lua_State *L;\n  global_State *g;\n  /* We need the PRNG for the memory allocator, so initialize this first. */\n  if (!lj_prng_seed_secure(&prng)) {\n    lj_assertX(0, \"secure PRNG seeding failed\");\n    /* Can only return NULL here, so this errors with \"not enough memory\". */\n    return NULL;\n  }\n#ifndef LUAJIT_USE_SYSMALLOC\n  if (allocf == LJ_ALLOCF_INTERNAL) {\n    allocd = lj_alloc_create(&prng);\n    if (!allocd) return NULL;\n    allocf = lj_alloc_f;\n  }\n#endif\n  GG = (GG_State *)allocf(allocd, NULL, 0, sizeof(GG_State));\n  if (GG == NULL || !checkptrGC(GG)) return NULL;\n  memset(GG, 0, sizeof(GG_State));\n  L = &GG->L;\n  g = &GG->g;\n  L->gct = ~LJ_TTHREAD;\n  L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED;  /* Prevent free. */\n  L->dummy_ffid = FF_C;\n  setmref(L->glref, g);\n  g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED;\n  g->strempty.marked = LJ_GC_WHITE0;\n  g->strempty.gct = ~LJ_TSTR;\n  g->allocf = allocf;\n  g->allocd = allocd;\n  g->prng = prng;\n#ifndef LUAJIT_USE_SYSMALLOC\n  if (allocf == lj_alloc_f) {\n    lj_alloc_setprng(allocd, &g->prng);\n  }\n#endif\n  setgcref(g->mainthref, obj2gco(L));\n  setgcref(g->uvhead.prev, obj2gco(&g->uvhead));\n  setgcref(g->uvhead.next, obj2gco(&g->uvhead));\n  g->str.mask = ~(MSize)0;\n  setnilV(registry(L));\n  setnilV(&g->nilnode.val);\n  setnilV(&g->nilnode.key);\n#if !LJ_GC64\n  setmref(g->nilnode.freetop, &g->nilnode);\n#endif\n  lj_buf_init(NULL, &g->tmpbuf);\n  g->gc.state = GCSpause;\n  setgcref(g->gc.root, obj2gco(L));\n  setmref(g->gc.sweep, &g->gc.root);\n  g->gc.total = sizeof(GG_State);\n  g->gc.pause = LUAI_GCPAUSE;\n  g->gc.stepmul = LUAI_GCMUL;\n  lj_dispatch_init((GG_State *)L);\n  L->status = LUA_ERRERR+1;  /* Avoid touching the stack upon memory error. */\n  if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {\n    /* Memory allocation error: free partial state. */\n    close_state(L);\n    return NULL;\n  }\n  L->status = LUA_OK;\n  return L;\n}\n\nstatic TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  UNUSED(dummy);\n  UNUSED(ud);\n  lj_gc_finalize_cdata(L);\n  lj_gc_finalize_udata(L);\n  /* Frame pop omitted. */\n  return NULL;\n}\n\nLUA_API void lua_close(lua_State *L)\n{\n  global_State *g = G(L);\n  int i;\n  L = mainthread(g);  /* Only the main thread can be closed. */\n#if LJ_HASPROFILE\n  luaJIT_profile_stop(L);\n#endif\n  setgcrefnull(g->cur_L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lj_gc_separateudata(g, 1);  /* Separate udata which have GC metamethods. */\n#if LJ_HASJIT\n  G2J(g)->flags &= ~JIT_F_ON;\n  G2J(g)->state = LJ_TRACE_IDLE;\n  lj_dispatch_update(g);\n#endif\n  for (i = 0;;) {\n    hook_enter(g);\n    L->status = LUA_OK;\n    L->base = L->top = tvref(L->stack) + 1 + LJ_FR2;\n    L->cframe = NULL;\n    if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == LUA_OK) {\n      if (++i >= 10) break;\n      lj_gc_separateudata(g, 1);  /* Separate udata again. */\n      if (gcref(g->gc.mmudata) == NULL)  /* Until nothing is left to do. */\n\tbreak;\n    }\n  }\n  close_state(L);\n}\n\nlua_State *lj_state_new(lua_State *L)\n{\n  lua_State *L1 = lj_mem_newobj(L, lua_State);\n  L1->gct = ~LJ_TTHREAD;\n  L1->dummy_ffid = FF_C;\n  L1->status = LUA_OK;\n  L1->stacksize = 0;\n  setmref(L1->stack, NULL);\n  L1->cframe = NULL;\n  /* NOBARRIER: The lua_State is new (marked white). */\n  setgcrefnull(L1->openupval);\n  setmrefr(L1->glref, L->glref);\n  setgcrefr(L1->env, L->env);\n  stack_init(L1, L);  /* init stack */\n  lj_assertL(iswhite(obj2gco(L1)), \"new thread object is not white\");\n  return L1;\n}\n\nvoid LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)\n{\n  lj_assertG(L != mainthread(g), \"free of main thread\");\n  if (obj2gco(L) == gcref(g->cur_L))\n    setgcrefnull(g->cur_L);\n  lj_func_closeuv(L, tvref(L->stack));\n  lj_assertG(gcref(L->openupval) == NULL, \"stale open upvalues\");\n  lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);\n  lj_mem_freet(g, L);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_state.h",
    "content": "/*\n** State and stack handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STATE_H\n#define _LJ_STATE_H\n\n#include \"lj_obj.h\"\n\n#define incr_top(L) \\\n  (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0))\n\n#define savestack(L, p)\t\t((char *)(p) - mref(L->stack, char))\n#define restorestack(L, n)\t((TValue *)(mref(L->stack, char) + (n)))\n\nLJ_FUNC void lj_state_relimitstack(lua_State *L);\nLJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used);\nLJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need);\nLJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L);\n\nstatic LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)\n{\n  if ((mref(L->maxstack, char) - (char *)L->top) <=\n      (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue))\n    lj_state_growstack(L, need);\n}\n\nLJ_FUNC lua_State *lj_state_new(lua_State *L);\nLJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);\n#if LJ_64 && !LJ_GC64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC))\nLJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);\n#endif\n\n#define LJ_ALLOCF_INTERNAL\t((lua_Alloc)(void *)(uintptr_t)(1237<<4))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_str.c",
    "content": "/*\n** String handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_str_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_str.h\"\n#include \"lj_char.h\"\n#include \"lj_prng.h\"\n\n/* -- String helpers ------------------------------------------------------ */\n\n/* Ordered compare of strings. Assumes string data is 4-byte aligned. */\nint32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b)\n{\n  MSize i, n = a->len > b->len ? b->len : a->len;\n  for (i = 0; i < n; i += 4) {\n    /* Note: innocuous access up to end of string + 3. */\n    uint32_t va = *(const uint32_t *)(strdata(a)+i);\n    uint32_t vb = *(const uint32_t *)(strdata(b)+i);\n    if (va != vb) {\n#if LJ_LE\n      va = lj_bswap(va); vb = lj_bswap(vb);\n#endif\n      i -= n;\n      if ((int32_t)i >= -3) {\n\tva >>= 32+(i<<3); vb >>= 32+(i<<3);\n\tif (va == vb) break;\n      }\n      return va < vb ? -1 : 1;\n    }\n  }\n  return (int32_t)(a->len - b->len);\n}\n\n/* Find fixed string p inside string s. */\nconst char *lj_str_find(const char *s, const char *p, MSize slen, MSize plen)\n{\n  if (plen <= slen) {\n    if (plen == 0) {\n      return s;\n    } else {\n      int c = *(const uint8_t *)p++;\n      plen--; slen -= plen;\n      while (slen) {\n\tconst char *q = (const char *)memchr(s, c, slen);\n\tif (!q) break;\n\tif (memcmp(q+1, p, plen) == 0) return q;\n\tq++; slen -= (MSize)(q-s); s = q;\n      }\n    }\n  }\n  return NULL;\n}\n\n/* Check whether a string has a pattern matching character. */\nint lj_str_haspattern(GCstr *s)\n{\n  const char *p = strdata(s), *q = p + s->len;\n  while (p < q) {\n    int c = *(const uint8_t *)p++;\n    if (lj_char_ispunct(c) && strchr(\"^$*+?.([%-\", c))\n      return 1;  /* Found a pattern matching char. */\n  }\n  return 0;  /* No pattern matching chars found. */\n}\n\n/* -- String hashing ------------------------------------------------------ */\n\n/* Keyed sparse ARX string hash. Constant time. */\nstatic StrHash hash_sparse(uint64_t seed, const char *str, MSize len)\n{\n  /* Constants taken from lookup3 hash by Bob Jenkins. */\n  StrHash a, b, h = len ^ (StrHash)seed;\n  if (len >= 4) {  /* Caveat: unaligned access! */\n    a = lj_getu32(str);\n    h ^= lj_getu32(str+len-4);\n    b = lj_getu32(str+(len>>1)-2);\n    h ^= b; h -= lj_rol(b, 14);\n    b += lj_getu32(str+(len>>2)-1);\n  } else {\n    a = *(const uint8_t *)str;\n    h ^= *(const uint8_t *)(str+len-1);\n    b = *(const uint8_t *)(str+(len>>1));\n    h ^= b; h -= lj_rol(b, 14);\n  }\n  a ^= h; a -= lj_rol(h, 11);\n  b ^= a; b -= lj_rol(a, 25);\n  h ^= b; h -= lj_rol(b, 16);\n  return h;\n}\n\n#if LUAJIT_SECURITY_STRHASH\n/* Keyed dense ARX string hash. Linear time. */\nstatic LJ_NOINLINE StrHash hash_dense(uint64_t seed, StrHash h,\n\t\t\t\t      const char *str, MSize len)\n{\n  StrHash b = lj_bswap(lj_rol(h ^ (StrHash)(seed >> 32), 4));\n  if (len > 12) {\n    StrHash a = (StrHash)seed;\n    const char *pe = str+len-12, *p = pe, *q = str;\n    do {\n      a += lj_getu32(p);\n      b += lj_getu32(p+4);\n      h += lj_getu32(p+8);\n      p = q; q += 12;\n      h ^= b; h -= lj_rol(b, 14);\n      a ^= h; a -= lj_rol(h, 11);\n      b ^= a; b -= lj_rol(a, 25);\n    } while (p < pe);\n    h ^= b; h -= lj_rol(b, 16);\n    a ^= h; a -= lj_rol(h, 4);\n    b ^= a; b -= lj_rol(a, 14);\n  }\n  return b;\n}\n#endif\n\n/* -- String interning ---------------------------------------------------- */\n\n#define LJ_STR_MAXCOLL\t\t32\n\n/* Resize the string interning hash table (grow and shrink). */\nvoid lj_str_resize(lua_State *L, MSize newmask)\n{\n  global_State *g = G(L);\n  GCRef *newtab, *oldtab = g->str.tab;\n  MSize i;\n\n  /* No resizing during GC traversal or if already too big. */\n  if (g->gc.state == GCSsweepstring || newmask >= LJ_MAX_STRTAB-1)\n    return;\n\n  newtab = lj_mem_newvec(L, newmask+1, GCRef);\n  memset(newtab, 0, (newmask+1)*sizeof(GCRef));\n\n#if LUAJIT_SECURITY_STRHASH\n  /* Check which chains need secondary hashes. */\n  if (g->str.second) {\n    int newsecond = 0;\n    /* Compute primary chain lengths. */\n    for (i = g->str.mask; i != ~(MSize)0; i--) {\n      GCobj *o = (GCobj *)(gcrefu(oldtab[i]) & ~(uintptr_t)1);\n      while (o) {\n\tGCstr *s = gco2str(o);\n\tMSize hash = s->hashalg ? hash_sparse(g->str.seed, strdata(s), s->len) :\n\t\t\t\t  s->hash;\n\thash &= newmask;\n\tsetgcrefp(newtab[hash], gcrefu(newtab[hash]) + 1);\n\to = gcnext(o);\n      }\n    }\n    /* Mark secondary chains. */\n    for (i = newmask; i != ~(MSize)0; i--) {\n      int secondary = gcrefu(newtab[i]) > LJ_STR_MAXCOLL;\n      newsecond |= secondary;\n      setgcrefp(newtab[i], secondary);\n    }\n    g->str.second = newsecond;\n  }\n#endif\n\n  /* Reinsert all strings from the old table into the new table. */\n  for (i = g->str.mask; i != ~(MSize)0; i--) {\n    GCobj *o = (GCobj *)(gcrefu(oldtab[i]) & ~(uintptr_t)1);\n    while (o) {\n      GCobj *next = gcnext(o);\n      GCstr *s = gco2str(o);\n      MSize hash = s->hash;\n#if LUAJIT_SECURITY_STRHASH\n      uintptr_t u;\n      if (LJ_LIKELY(!s->hashalg)) {  /* String hashed with primary hash. */\n\thash &= newmask;\n\tu = gcrefu(newtab[hash]);\n\tif (LJ_UNLIKELY(u & 1)) {  /* Switch string to secondary hash. */\n\t  s->hash = hash = hash_dense(g->str.seed, s->hash, strdata(s), s->len);\n\t  s->hashalg = 1;\n\t  hash &= newmask;\n\t  u = gcrefu(newtab[hash]);\n\t}\n      } else {  /* String hashed with secondary hash. */\n\tMSize shash = hash_sparse(g->str.seed, strdata(s), s->len);\n\tu = gcrefu(newtab[shash & newmask]);\n\tif (u & 1) {\n\t  hash &= newmask;\n\t  u = gcrefu(newtab[hash]);\n\t} else {  /* Revert string back to primary hash. */\n\t  s->hash = shash;\n\t  s->hashalg = 0;\n\t  hash = (shash & newmask);\n\t}\n      }\n      /* NOBARRIER: The string table is a GC root. */\n      setgcrefp(o->gch.nextgc, (u & ~(uintptr_t)1));\n      setgcrefp(newtab[hash], ((uintptr_t)o | (u & 1)));\n#else\n      hash &= newmask;\n      /* NOBARRIER: The string table is a GC root. */\n      setgcrefr(o->gch.nextgc, newtab[hash]);\n      setgcref(newtab[hash], o);\n#endif\n      o = next;\n    }\n  }\n\n  /* Free old table and replace with new table. */\n  lj_str_freetab(g);\n  g->str.tab = newtab;\n  g->str.mask = newmask;\n}\n\n#if LUAJIT_SECURITY_STRHASH\n/* Rehash and rechain all strings in a chain. */\nstatic LJ_NOINLINE GCstr *lj_str_rehash_chain(lua_State *L, StrHash hashc,\n\t\t\t\t\t      const char *str, MSize len)\n{\n  global_State *g = G(L);\n  int ow = g->gc.state == GCSsweepstring ? otherwhite(g) : 0;  /* Sweeping? */\n  GCRef *strtab = g->str.tab;\n  MSize strmask = g->str.mask;\n  GCobj *o = gcref(strtab[hashc & strmask]);\n  setgcrefp(strtab[hashc & strmask], (void *)((uintptr_t)1));\n  g->str.second = 1;\n  while (o) {\n    uintptr_t u;\n    GCobj *next = gcnext(o);\n    GCstr *s = gco2str(o);\n    StrHash hash;\n    if (ow) {  /* Must sweep while rechaining. */\n      if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) {  /* String alive? */\n\tlj_assertG(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED),\n\t\t   \"sweep of undead string\");\n\tmakewhite(g, o);\n      } else {  /* Free dead string. */\n\tlj_assertG(isdead(g, o) || ow == LJ_GC_SFIXED,\n\t\t   \"sweep of unlive string\");\n\tlj_str_free(g, s);\n\to = next;\n\tcontinue;\n      }\n    }\n    hash = s->hash;\n    if (!s->hashalg) {  /* Rehash with secondary hash. */\n      hash = hash_dense(g->str.seed, hash, strdata(s), s->len);\n      s->hash = hash;\n      s->hashalg = 1;\n    }\n    /* Rechain. */\n    hash &= strmask;\n    u = gcrefu(strtab[hash]);\n    setgcrefp(o->gch.nextgc, (u & ~(uintptr_t)1));\n    setgcrefp(strtab[hash], ((uintptr_t)o | (u & 1)));\n    o = next;\n  }\n  /* Try to insert the pending string again. */\n  return lj_str_new(L, str, len);\n}\n#endif\n\n/* Reseed String ID from PRNG after random interval < 2^bits. */\n#if LUAJIT_SECURITY_STRID == 1\n#define STRID_RESEED_INTERVAL\t8\n#elif LUAJIT_SECURITY_STRID == 2\n#define STRID_RESEED_INTERVAL\t4\n#elif LUAJIT_SECURITY_STRID >= 3\n#define STRID_RESEED_INTERVAL\t0\n#endif\n\n/* Allocate a new string and add to string interning table. */\nstatic GCstr *lj_str_alloc(lua_State *L, const char *str, MSize len,\n\t\t\t   StrHash hash, int hashalg)\n{\n  GCstr *s = lj_mem_newt(L, lj_str_size(len), GCstr);\n  global_State *g = G(L);\n  uintptr_t u;\n  newwhite(g, s);\n  s->gct = ~LJ_TSTR;\n  s->len = len;\n  s->hash = hash;\n#ifndef STRID_RESEED_INTERVAL\n  s->sid = g->str.id++;\n#elif STRID_RESEED_INTERVAL\n  if (!g->str.idreseed--) {\n    uint64_t r = lj_prng_u64(&g->prng);\n    g->str.id = (StrID)r;\n    g->str.idreseed = (uint8_t)(r >> (64 - STRID_RESEED_INTERVAL));\n  }\n  s->sid = g->str.id++;\n#else\n  s->sid = (StrID)lj_prng_u64(&g->prng);\n#endif\n  s->reserved = 0;\n  s->hashalg = (uint8_t)hashalg;\n  /* Clear last 4 bytes of allocated memory. Implies zero-termination, too. */\n  *(uint32_t *)(strdatawr(s)+(len & ~(MSize)3)) = 0;\n  memcpy(strdatawr(s), str, len);\n  /* Add to string hash table. */\n  hash &= g->str.mask;\n  u = gcrefu(g->str.tab[hash]);\n  setgcrefp(s->nextgc, (u & ~(uintptr_t)1));\n  /* NOBARRIER: The string table is a GC root. */\n  setgcrefp(g->str.tab[hash], ((uintptr_t)s | (u & 1)));\n  if (g->str.num++ > g->str.mask)  /* Allow a 100% load factor. */\n    lj_str_resize(L, (g->str.mask<<1)+1);  /* Grow string table. */\n  return s;  /* Return newly interned string. */\n}\n\n/* Intern a string and return string object. */\nGCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)\n{\n  global_State *g = G(L);\n  if (lenx-1 < LJ_MAX_STR-1) {\n    MSize len = (MSize)lenx;\n    StrHash hash = hash_sparse(g->str.seed, str, len);\n    MSize coll = 0;\n    int hashalg = 0;\n    /* Check if the string has already been interned. */\n    GCobj *o = gcref(g->str.tab[hash & g->str.mask]);\n#if LUAJIT_SECURITY_STRHASH\n    if (LJ_UNLIKELY((uintptr_t)o & 1)) {  /* Secondary hash for this chain? */\n      hashalg = 1;\n      hash = hash_dense(g->str.seed, hash, str, len);\n      o = (GCobj *)(gcrefu(g->str.tab[hash & g->str.mask]) & ~(uintptr_t)1);\n    }\n#endif\n    while (o != NULL) {\n      GCstr *sx = gco2str(o);\n      if (sx->hash == hash && sx->len == len) {\n\tif (memcmp(str, strdata(sx), len) == 0) {\n\t  if (isdead(g, o)) flipwhite(o);  /* Resurrect if dead. */\n\t  return sx;  /* Return existing string. */\n\t}\n\tcoll++;\n      }\n      coll++;\n      o = gcnext(o);\n    }\n#if LUAJIT_SECURITY_STRHASH\n    /* Rehash chain if there are too many collisions. */\n    if (LJ_UNLIKELY(coll > LJ_STR_MAXCOLL) && !hashalg) {\n      return lj_str_rehash_chain(L, hash, str, len);\n    }\n#endif\n    /* Otherwise allocate a new string. */\n    return lj_str_alloc(L, str, len, hash, hashalg);\n  } else {\n    if (lenx)\n      lj_err_msg(L, LJ_ERR_STROV);\n    return &g->strempty;\n  }\n}\n\nvoid LJ_FASTCALL lj_str_free(global_State *g, GCstr *s)\n{\n  g->str.num--;\n  lj_mem_free(g, s, lj_str_size(s->len));\n}\n\nvoid LJ_FASTCALL lj_str_init(lua_State *L)\n{\n  global_State *g = G(L);\n  g->str.seed = lj_prng_u64(&g->prng);\n  lj_str_resize(L, LJ_MIN_STRTAB-1);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_str.h",
    "content": "/*\n** String handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STR_H\n#define _LJ_STR_H\n\n#include <stdarg.h>\n\n#include \"lj_obj.h\"\n\n/* String helpers. */\nLJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);\nLJ_FUNC const char *lj_str_find(const char *s, const char *f,\n\t\t\t\tMSize slen, MSize flen);\nLJ_FUNC int lj_str_haspattern(GCstr *s);\n\n/* String interning. */\nLJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);\nLJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);\nLJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);\nLJ_FUNC void LJ_FASTCALL lj_str_init(lua_State *L);\n#define lj_str_freetab(g) \\\n  (lj_mem_freevec(g, g->str.tab, g->str.mask+1, GCRef))\n\n#define lj_str_newz(L, s)\t(lj_str_new(L, s, strlen(s)))\n#define lj_str_newlit(L, s)\t(lj_str_new(L, \"\" s, sizeof(s)-1))\n#define lj_str_size(len)\t(sizeof(GCstr) + (((len)+4) & ~(MSize)3))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_strfmt.c",
    "content": "/*\n** String formatting.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <stdio.h>\n\n#define lj_strfmt_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_err.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_meta.h\"\n#include \"lj_state.h\"\n#include \"lj_char.h\"\n#include \"lj_strfmt.h\"\n#if LJ_HASFFI\n#include \"lj_ctype.h\"\n#endif\n#include \"lj_lib.h\"\n\n/* -- Format parser ------------------------------------------------------- */\n\nstatic const uint8_t strfmt_map[('x'-'A')+1] = {\n  STRFMT_A,0,0,0,STRFMT_E,STRFMT_F,STRFMT_G,0,0,0,0,0,0,\n  0,0,0,0,0,0,0,0,0,0,STRFMT_X,0,0,\n  0,0,0,0,0,0,\n  STRFMT_A,0,STRFMT_C,STRFMT_D,STRFMT_E,STRFMT_F,STRFMT_G,0,STRFMT_I,0,0,0,0,\n  0,STRFMT_O,STRFMT_P,STRFMT_Q,0,STRFMT_S,0,STRFMT_U,0,0,STRFMT_X\n};\n\nSFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs)\n{\n  const uint8_t *p = fs->p, *e = fs->e;\n  fs->str = (const char *)p;\n  for (; p < e; p++) {\n    if (*p == '%') {  /* Escape char? */\n      if (p[1] == '%') {  /* '%%'? */\n\tfs->p = ++p+1;\n\tgoto retlit;\n      } else {\n\tSFormat sf = 0;\n\tuint32_t c;\n\tif (p != (const uint8_t *)fs->str)\n\t  break;\n\tfor (p++; (uint32_t)*p - ' ' <= (uint32_t)('0' - ' '); p++) {\n\t  /* Parse flags. */\n\t  if (*p == '-') sf |= STRFMT_F_LEFT;\n\t  else if (*p == '+') sf |= STRFMT_F_PLUS;\n\t  else if (*p == '0') sf |= STRFMT_F_ZERO;\n\t  else if (*p == ' ') sf |= STRFMT_F_SPACE;\n\t  else if (*p == '#') sf |= STRFMT_F_ALT;\n\t  else break;\n\t}\n\tif ((uint32_t)*p - '0' < 10) {  /* Parse width. */\n\t  uint32_t width = (uint32_t)*p++ - '0';\n\t  if ((uint32_t)*p - '0' < 10)\n\t    width = (uint32_t)*p++ - '0' + width*10;\n\t  sf |= (width << STRFMT_SH_WIDTH);\n\t}\n\tif (*p == '.') {  /* Parse precision. */\n\t  uint32_t prec = 0;\n\t  p++;\n\t  if ((uint32_t)*p - '0' < 10) {\n\t    prec = (uint32_t)*p++ - '0';\n\t    if ((uint32_t)*p - '0' < 10)\n\t      prec = (uint32_t)*p++ - '0' + prec*10;\n\t  }\n\t  sf |= ((prec+1) << STRFMT_SH_PREC);\n\t}\n\t/* Parse conversion. */\n\tc = (uint32_t)*p - 'A';\n\tif (LJ_LIKELY(c <= (uint32_t)('x' - 'A'))) {\n\t  uint32_t sx = strfmt_map[c];\n\t  if (sx) {\n\t    fs->p = p+1;\n\t    return (sf | sx | ((c & 0x20) ? 0 : STRFMT_F_UPPER));\n\t  }\n\t}\n\t/* Return error location. */\n\tif (*p >= 32) p++;\n\tfs->len = (MSize)(p - (const uint8_t *)fs->str);\n\tfs->p = fs->e;\n\treturn STRFMT_ERR;\n      }\n    }\n  }\n  fs->p = p;\nretlit:\n  fs->len = (MSize)(p - (const uint8_t *)fs->str);\n  return fs->len ? STRFMT_LIT : STRFMT_EOF;\n}\n\n/* -- Raw conversions ----------------------------------------------------- */\n\n#define WINT_R(x, sh, sc) \\\n  { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); }\n\n/* Write integer to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k)\n{\n  uint32_t u = (uint32_t)k;\n  if (k < 0) { u = (uint32_t)-k; *p++ = '-'; }\n  if (u < 10000) {\n    if (u < 10) goto dig1;\n    if (u < 100) goto dig2;\n    if (u < 1000) goto dig3;\n  } else {\n    uint32_t v = u / 10000; u -= v * 10000;\n    if (v < 10000) {\n      if (v < 10) goto dig5;\n      if (v < 100) goto dig6;\n      if (v < 1000) goto dig7;\n    } else {\n      uint32_t w = v / 10000; v -= w * 10000;\n      if (w >= 10) WINT_R(w, 10, 10)\n      *p++ = (char)('0'+w);\n    }\n    WINT_R(v, 23, 1000)\n    dig7: WINT_R(v, 12, 100)\n    dig6: WINT_R(v, 10, 10)\n    dig5: *p++ = (char)('0'+v);\n  }\n  WINT_R(u, 23, 1000)\n  dig3: WINT_R(u, 12, 100)\n  dig2: WINT_R(u, 10, 10)\n  dig1: *p++ = (char)('0'+u);\n  return p;\n}\n#undef WINT_R\n\n/* Write pointer to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v)\n{\n  ptrdiff_t x = (ptrdiff_t)v;\n  MSize i, n = STRFMT_MAXBUF_PTR;\n  if (x == 0) {\n    *p++ = 'N'; *p++ = 'U'; *p++ = 'L'; *p++ = 'L';\n    return p;\n  }\n#if LJ_64\n  /* Shorten output for 64 bit pointers. */\n  n = 2+2*4+((x >> 32) ? 2+2*(lj_fls((uint32_t)(x >> 32))>>3) : 0);\n#endif\n  p[0] = '0';\n  p[1] = 'x';\n  for (i = n-1; i >= 2; i--, x >>= 4)\n    p[i] = \"0123456789abcdef\"[(x & 15)];\n  return p+n;\n}\n\n/* Write ULEB128 to buffer. */\nchar * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v)\n{\n  for (; v >= 0x80; v >>= 7)\n    *p++ = (char)((v & 0x7f) | 0x80);\n  *p++ = (char)v;\n  return p;\n}\n\n/* Return string or write number to tmp buffer and return pointer to start. */\nconst char *lj_strfmt_wstrnum(lua_State *L, cTValue *o, MSize *lenp)\n{\n  SBuf *sb;\n  if (tvisstr(o)) {\n    *lenp = strV(o)->len;\n    return strVdata(o);\n  } else if (tvisbuf(o)) {\n    SBufExt *sbx = bufV(o);\n    *lenp = sbufxlen(sbx);\n    return sbx->r;\n  } else if (tvisint(o)) {\n    sb = lj_strfmt_putint(lj_buf_tmp_(L), intV(o));\n  } else if (tvisnum(o)) {\n    sb = lj_strfmt_putfnum(lj_buf_tmp_(L), STRFMT_G14, o->n);\n  } else {\n    return NULL;\n  }\n  *lenp = sbuflen(sb);\n  return sb->b;\n}\n\n/* -- Unformatted conversions to buffer ----------------------------------- */\n\n/* Add integer to buffer. */\nSBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k)\n{\n  sb->w = lj_strfmt_wint(lj_buf_more(sb, STRFMT_MAXBUF_INT), k);\n  return sb;\n}\n\n#if LJ_HASJIT\n/* Add number to buffer. */\nSBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o)\n{\n  return lj_strfmt_putfnum(sb, STRFMT_G14, o->n);\n}\n#endif\n\nSBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v)\n{\n  sb->w = lj_strfmt_wptr(lj_buf_more(sb, STRFMT_MAXBUF_PTR), v);\n  return sb;\n}\n\n/* Add quoted string to buffer. */\nstatic SBuf *strfmt_putquotedlen(SBuf *sb, const char *s, MSize len)\n{\n  lj_buf_putb(sb, '\"');\n  while (len--) {\n    uint32_t c = (uint32_t)(uint8_t)*s++;\n    char *w = lj_buf_more(sb, 4);\n    if (c == '\"' || c == '\\\\' || c == '\\n') {\n      *w++ = '\\\\';\n    } else if (lj_char_iscntrl(c)) {  /* This can only be 0-31 or 127. */\n      uint32_t d;\n      *w++ = '\\\\';\n      if (c >= 100 || lj_char_isdigit((uint8_t)*s)) {\n\t*w++ = (char)('0'+(c >= 100)); if (c >= 100) c -= 100;\n\tgoto tens;\n      } else if (c >= 10) {\n      tens:\n\td = (c * 205) >> 11; c -= d * 10; *w++ = (char)('0'+d);\n      }\n      c += '0';\n    }\n    *w++ = (char)c;\n    sb->w = w;\n  }\n  lj_buf_putb(sb, '\"');\n  return sb;\n}\n\n#if LJ_HASJIT\nSBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str)\n{\n  return strfmt_putquotedlen(sb, strdata(str), str->len);\n}\n#endif\n\n/* -- Formatted conversions to buffer ------------------------------------- */\n\n/* Add formatted char to buffer. */\nSBuf *lj_strfmt_putfchar(SBuf *sb, SFormat sf, int32_t c)\n{\n  MSize width = STRFMT_WIDTH(sf);\n  char *w = lj_buf_more(sb, width > 1 ? width : 1);\n  if ((sf & STRFMT_F_LEFT)) *w++ = (char)c;\n  while (width-- > 1) *w++ = ' ';\n  if (!(sf & STRFMT_F_LEFT)) *w++ = (char)c;\n  sb->w = w;\n  return sb;\n}\n\n/* Add formatted string to buffer. */\nstatic SBuf *strfmt_putfstrlen(SBuf *sb, SFormat sf, const char *s, MSize len)\n{\n  MSize width = STRFMT_WIDTH(sf);\n  char *w;\n  if (len > STRFMT_PREC(sf)) len = STRFMT_PREC(sf);\n  w = lj_buf_more(sb, width > len ? width : len);\n  if ((sf & STRFMT_F_LEFT)) w = lj_buf_wmem(w, s, len);\n  while (width-- > len) *w++ = ' ';\n  if (!(sf & STRFMT_F_LEFT)) w = lj_buf_wmem(w, s, len);\n  sb->w = w;\n  return sb;\n}\n\n#if LJ_HASJIT\nSBuf *lj_strfmt_putfstr(SBuf *sb, SFormat sf, GCstr *str)\n{\n  return strfmt_putfstrlen(sb, sf, strdata(str), str->len);\n}\n#endif\n\n/* Add formatted signed/unsigned integer to buffer. */\nSBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k)\n{\n  char buf[STRFMT_MAXBUF_XINT], *q = buf + sizeof(buf), *w;\n#ifdef LUA_USE_ASSERT\n  char *ws;\n#endif\n  MSize prefix = 0, len, prec, pprec, width, need;\n\n  /* Figure out signed prefixes. */\n  if (STRFMT_TYPE(sf) == STRFMT_INT) {\n    if ((int64_t)k < 0) {\n      k = (uint64_t)-(int64_t)k;\n      prefix = 256 + '-';\n    } else if ((sf & STRFMT_F_PLUS)) {\n      prefix = 256 + '+';\n    } else if ((sf & STRFMT_F_SPACE)) {\n      prefix = 256 + ' ';\n    }\n  }\n\n  /* Convert number and store to fixed-size buffer in reverse order. */\n  prec = STRFMT_PREC(sf);\n  if ((int32_t)prec >= 0) sf &= ~STRFMT_F_ZERO;\n  if (k == 0) {  /* Special-case zero argument. */\n    if (prec != 0 ||\n\t(sf & (STRFMT_T_OCT|STRFMT_F_ALT)) == (STRFMT_T_OCT|STRFMT_F_ALT))\n      *--q = '0';\n  } else if (!(sf & (STRFMT_T_HEX|STRFMT_T_OCT))) {  /* Decimal. */\n    uint32_t k2;\n    while ((k >> 32)) { *--q = (char)('0' + k % 10); k /= 10; }\n    k2 = (uint32_t)k;\n    do { *--q = (char)('0' + k2 % 10); k2 /= 10; } while (k2);\n  } else if ((sf & STRFMT_T_HEX)) {  /* Hex. */\n    const char *hexdig = (sf & STRFMT_F_UPPER) ? \"0123456789ABCDEF\" :\n\t\t\t\t\t\t \"0123456789abcdef\";\n    do { *--q = hexdig[(k & 15)]; k >>= 4; } while (k);\n    if ((sf & STRFMT_F_ALT)) prefix = 512 + ((sf & STRFMT_F_UPPER) ? 'X' : 'x');\n  } else {  /* Octal. */\n    do { *--q = (char)('0' + (uint32_t)(k & 7)); k >>= 3; } while (k);\n    if ((sf & STRFMT_F_ALT)) *--q = '0';\n  }\n\n  /* Calculate sizes. */\n  len = (MSize)(buf + sizeof(buf) - q);\n  if ((int32_t)len >= (int32_t)prec) prec = len;\n  width = STRFMT_WIDTH(sf);\n  pprec = prec + (prefix >> 8);\n  need = width > pprec ? width : pprec;\n  w = lj_buf_more(sb, need);\n#ifdef LUA_USE_ASSERT\n  ws = w;\n#endif\n\n  /* Format number with leading/trailing whitespace and zeros. */\n  if ((sf & (STRFMT_F_LEFT|STRFMT_F_ZERO)) == 0)\n    while (width-- > pprec) *w++ = ' ';\n  if (prefix) {\n    if ((char)prefix >= 'X') *w++ = '0';\n    *w++ = (char)prefix;\n  }\n  if ((sf & (STRFMT_F_LEFT|STRFMT_F_ZERO)) == STRFMT_F_ZERO)\n    while (width-- > pprec) *w++ = '0';\n  while (prec-- > len) *w++ = '0';\n  while (q < buf + sizeof(buf)) *w++ = *q++;  /* Add number itself. */\n  if ((sf & STRFMT_F_LEFT))\n    while (width-- > pprec) *w++ = ' ';\n\n  lj_assertX(need == (MSize)(w - ws), \"miscalculated format size\");\n  sb->w = w;\n  return sb;\n}\n\n/* Add number formatted as signed integer to buffer. */\nSBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n)\n{\n  int64_t k = (int64_t)n;\n  if (checki32(k) && sf == STRFMT_INT)\n    return lj_strfmt_putint(sb, (int32_t)k);  /* Shortcut for plain %d. */\n  else\n    return lj_strfmt_putfxint(sb, sf, (uint64_t)k);\n}\n\n/* Add number formatted as unsigned integer to buffer. */\nSBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n)\n{\n  int64_t k;\n  if (n >= 9223372036854775808.0)\n    k = (int64_t)(n - 18446744073709551616.0);\n  else\n    k = (int64_t)n;\n  return lj_strfmt_putfxint(sb, sf, (uint64_t)k);\n}\n\n/* Format stack arguments to buffer. */\nint lj_strfmt_putarg(lua_State *L, SBuf *sb, int arg, int retry)\n{\n  int narg = (int)(L->top - L->base);\n  GCstr *fmt = lj_lib_checkstr(L, arg);\n  FormatState fs;\n  SFormat sf;\n  lj_strfmt_init(&fs, strdata(fmt), fmt->len);\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {\n    if (sf == STRFMT_LIT) {\n      lj_buf_putmem(sb, fs.str, fs.len);\n    } else if (sf == STRFMT_ERR) {\n      lj_err_callerv(L, LJ_ERR_STRFMT,\n\t\t     strdata(lj_str_new(L, fs.str, fs.len)));\n    } else {\n      TValue *o = &L->base[arg++];\n      if (arg > narg)\n\tlj_err_arg(L, arg, LJ_ERR_NOVAL);\n      switch (STRFMT_TYPE(sf)) {\n      case STRFMT_INT:\n\tif (tvisint(o)) {\n\t  int32_t k = intV(o);\n\t  if (sf == STRFMT_INT)\n\t    lj_strfmt_putint(sb, k);  /* Shortcut for plain %d. */\n\t  else\n\t    lj_strfmt_putfxint(sb, sf, k);\n\t  break;\n\t}\n#if LJ_HASFFI\n\tif (tviscdata(o)) {\n\t  GCcdata *cd = cdataV(o);\n\t  if (cd->ctypeid == CTID_INT64 || cd->ctypeid == CTID_UINT64) {\n\t    lj_strfmt_putfxint(sb, sf, *(uint64_t *)cdataptr(cd));\n\t    break;\n\t  }\n\t}\n#endif\n\tlj_strfmt_putfnum_int(sb, sf, lj_lib_checknum(L, arg));\n\tbreak;\n      case STRFMT_UINT:\n\tif (tvisint(o)) {\n\t  lj_strfmt_putfxint(sb, sf, intV(o));\n\t  break;\n\t}\n#if LJ_HASFFI\n\tif (tviscdata(o)) {\n\t  GCcdata *cd = cdataV(o);\n\t  if (cd->ctypeid == CTID_INT64 || cd->ctypeid == CTID_UINT64) {\n\t    lj_strfmt_putfxint(sb, sf, *(uint64_t *)cdataptr(cd));\n\t    break;\n\t  }\n\t}\n#endif\n\tlj_strfmt_putfnum_uint(sb, sf, lj_lib_checknum(L, arg));\n\tbreak;\n      case STRFMT_NUM:\n\tlj_strfmt_putfnum(sb, sf, lj_lib_checknum(L, arg));\n\tbreak;\n      case STRFMT_STR: {\n\tMSize len;\n\tconst char *s;\n\tcTValue *mo;\n\tif (LJ_UNLIKELY(!tvisstr(o) && !tvisbuf(o)) && retry >= 0 &&\n\t    !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {\n\t  /* Call __tostring metamethod once. */\n\t  copyTV(L, L->top++, mo);\n\t  copyTV(L, L->top++, o);\n\t  lua_call(L, 1, 1);\n\t  o = &L->base[arg-1];  /* Stack may have been reallocated. */\n\t  copyTV(L, o, --L->top);  /* Replace inline for retry. */\n\t  if (retry < 2) {  /* Global buffer may have been overwritten. */\n\t    retry = 1;\n\t    break;\n\t  }\n\t}\n\tif (LJ_LIKELY(tvisstr(o))) {\n\t  len = strV(o)->len;\n\t  s = strVdata(o);\n#if LJ_HASBUFFER\n\t} else if (tvisbuf(o)) {\n\t  SBufExt *sbx = bufV(o);\n\t  if (sbx == (SBufExt *)sb) lj_err_arg(L, arg+1, LJ_ERR_BUFFER_SELF);\n\t  len = sbufxlen(sbx);\n\t  s = sbx->r;\n#endif\n\t} else {\n\t  GCstr *str = lj_strfmt_obj(L, o);\n\t  len = str->len;\n\t  s = strdata(str);\n\t}\n\tif ((sf & STRFMT_T_QUOTED))\n\t  strfmt_putquotedlen(sb, s, len);  /* No formatting. */\n\telse\n\t  strfmt_putfstrlen(sb, sf, s, len);\n\tbreak;\n\t}\n      case STRFMT_CHAR:\n\tlj_strfmt_putfchar(sb, sf, lj_lib_checkint(L, arg));\n\tbreak;\n      case STRFMT_PTR:  /* No formatting. */\n\tlj_strfmt_putptr(sb, lj_obj_ptr(G(L), o));\n\tbreak;\n      default:\n\tlj_assertL(0, \"bad string format type\");\n\tbreak;\n      }\n    }\n  }\n  return retry;\n}\n\n/* -- Conversions to strings ---------------------------------------------- */\n\n/* Convert integer to string. */\nGCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k)\n{\n  char buf[STRFMT_MAXBUF_INT];\n  MSize len = (MSize)(lj_strfmt_wint(buf, k) - buf);\n  return lj_str_new(L, buf, len);\n}\n\n/* Convert integer or number to string. */\nGCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o)\n{\n  return tvisint(o) ? lj_strfmt_int(L, intV(o)) : lj_strfmt_num(L, o);\n}\n\n#if LJ_HASJIT\n/* Convert char value to string. */\nGCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c)\n{\n  char buf[1];\n  buf[0] = c;\n  return lj_str_new(L, buf, 1);\n}\n#endif\n\n/* Raw conversion of object to string. */\nGCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o)\n{\n  if (tvisstr(o)) {\n    return strV(o);\n  } else if (tvisnumber(o)) {\n    return lj_strfmt_number(L, o);\n  } else if (tvisnil(o)) {\n    return lj_str_newlit(L, \"nil\");\n  } else if (tvisfalse(o)) {\n    return lj_str_newlit(L, \"false\");\n  } else if (tvistrue(o)) {\n    return lj_str_newlit(L, \"true\");\n  } else {\n    char buf[8+2+2+16], *p = buf;\n    p = lj_buf_wmem(p, lj_typename(o), (MSize)strlen(lj_typename(o)));\n    *p++ = ':'; *p++ = ' ';\n    if (tvisfunc(o) && isffunc(funcV(o))) {\n      p = lj_buf_wmem(p, \"builtin#\", 8);\n      p = lj_strfmt_wint(p, funcV(o)->c.ffid);\n    } else {\n      p = lj_strfmt_wptr(p, lj_obj_ptr(G(L), o));\n    }\n    return lj_str_new(L, buf, (size_t)(p - buf));\n  }\n}\n\n/* -- Internal string formatting ------------------------------------------ */\n\n/*\n** These functions are only used for lua_pushfstring(), lua_pushvfstring()\n** and for internal string formatting (e.g. error messages). Caveat: unlike\n** string.format(), only a limited subset of formats and flags are supported!\n**\n** LuaJIT has support for a couple more formats than Lua 5.1/5.2:\n** - %d %u %o %x with full formatting, 32 bit integers only.\n** - %f and other FP formats are really %.14g.\n** - %s %c %p without formatting.\n*/\n\n/* Push formatted message as a string object to Lua stack. va_list variant. */\nconst char *lj_strfmt_pushvf(lua_State *L, const char *fmt, va_list argp)\n{\n  SBuf *sb = lj_buf_tmp_(L);\n  FormatState fs;\n  SFormat sf;\n  GCstr *str;\n  lj_strfmt_init(&fs, fmt, (MSize)strlen(fmt));\n  while ((sf = lj_strfmt_parse(&fs)) != STRFMT_EOF) {\n    switch (STRFMT_TYPE(sf)) {\n    case STRFMT_LIT:\n      lj_buf_putmem(sb, fs.str, fs.len);\n      break;\n    case STRFMT_INT:\n      lj_strfmt_putfxint(sb, sf, va_arg(argp, int32_t));\n      break;\n    case STRFMT_UINT:\n      lj_strfmt_putfxint(sb, sf, va_arg(argp, uint32_t));\n      break;\n    case STRFMT_NUM:\n      lj_strfmt_putfnum(sb, STRFMT_G14, va_arg(argp, lua_Number));\n      break;\n    case STRFMT_STR: {\n      const char *s = va_arg(argp, char *);\n      if (s == NULL) s = \"(null)\";\n      lj_buf_putmem(sb, s, (MSize)strlen(s));\n      break;\n      }\n    case STRFMT_CHAR:\n      lj_buf_putb(sb, va_arg(argp, int));\n      break;\n    case STRFMT_PTR:\n      lj_strfmt_putptr(sb, va_arg(argp, void *));\n      break;\n    case STRFMT_ERR:\n    default:\n      lj_buf_putb(sb, '?');\n      lj_assertL(0, \"bad string format near offset %d\", fs.len);\n      break;\n    }\n  }\n  str = lj_buf_str(L, sb);\n  setstrV(L, L->top, str);\n  incr_top(L);\n  return strdata(str);\n}\n\n/* Push formatted message as a string object to Lua stack. Vararg variant. */\nconst char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)\n{\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = lj_strfmt_pushvf(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_strfmt.h",
    "content": "/*\n** String formatting.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STRFMT_H\n#define _LJ_STRFMT_H\n\n#include \"lj_obj.h\"\n\ntypedef uint32_t SFormat;  /* Format indicator. */\n\n/* Format parser state. */\ntypedef struct FormatState {\n  const uint8_t *p;\t/* Current format string pointer. */\n  const uint8_t *e;\t/* End of format string. */\n  const char *str;\t/* Returned literal string. */\n  MSize len;\t\t/* Size of literal string. */\n} FormatState;\n\n/* Format types (max. 16). */\ntypedef enum FormatType {\n  STRFMT_EOF, STRFMT_ERR, STRFMT_LIT,\n  STRFMT_INT, STRFMT_UINT, STRFMT_NUM, STRFMT_STR, STRFMT_CHAR, STRFMT_PTR\n} FormatType;\n\n/* Format subtypes (bits are reused). */\n#define STRFMT_T_HEX\t0x0010\t/* STRFMT_UINT */\n#define STRFMT_T_OCT\t0x0020\t/* STRFMT_UINT */\n#define STRFMT_T_FP_A\t0x0000\t/* STRFMT_NUM */\n#define STRFMT_T_FP_E\t0x0010\t/* STRFMT_NUM */\n#define STRFMT_T_FP_F\t0x0020\t/* STRFMT_NUM */\n#define STRFMT_T_FP_G\t0x0030\t/* STRFMT_NUM */\n#define STRFMT_T_QUOTED\t0x0010\t/* STRFMT_STR */\n\n/* Format flags. */\n#define STRFMT_F_LEFT\t0x0100\n#define STRFMT_F_PLUS\t0x0200\n#define STRFMT_F_ZERO\t0x0400\n#define STRFMT_F_SPACE\t0x0800\n#define STRFMT_F_ALT\t0x1000\n#define STRFMT_F_UPPER\t0x2000\n\n/* Format indicator fields. */\n#define STRFMT_SH_WIDTH\t16\n#define STRFMT_SH_PREC\t24\n\n#define STRFMT_TYPE(sf)\t\t((FormatType)((sf) & 15))\n#define STRFMT_WIDTH(sf)\t(((sf) >> STRFMT_SH_WIDTH) & 255u)\n#define STRFMT_PREC(sf)\t\t((((sf) >> STRFMT_SH_PREC) & 255u) - 1u)\n#define STRFMT_FP(sf)\t\t(((sf) >> 4) & 3)\n\n/* Formats for conversion characters. */\n#define STRFMT_A\t(STRFMT_NUM|STRFMT_T_FP_A)\n#define STRFMT_C\t(STRFMT_CHAR)\n#define STRFMT_D\t(STRFMT_INT)\n#define STRFMT_E\t(STRFMT_NUM|STRFMT_T_FP_E)\n#define STRFMT_F\t(STRFMT_NUM|STRFMT_T_FP_F)\n#define STRFMT_G\t(STRFMT_NUM|STRFMT_T_FP_G)\n#define STRFMT_I\tSTRFMT_D\n#define STRFMT_O\t(STRFMT_UINT|STRFMT_T_OCT)\n#define STRFMT_P\t(STRFMT_PTR)\n#define STRFMT_Q\t(STRFMT_STR|STRFMT_T_QUOTED)\n#define STRFMT_S\t(STRFMT_STR)\n#define STRFMT_U\t(STRFMT_UINT)\n#define STRFMT_X\t(STRFMT_UINT|STRFMT_T_HEX)\n#define STRFMT_G14\t(STRFMT_G | ((14+1) << STRFMT_SH_PREC))\n\n/* Maximum buffer sizes for conversions. */\n#define STRFMT_MAXBUF_XINT\t(1+22)  /* '0' prefix + uint64_t in octal. */\n#define STRFMT_MAXBUF_INT\t(1+10)  /* Sign + int32_t in decimal. */\n#define STRFMT_MAXBUF_NUM\t32  /* Must correspond with STRFMT_G14. */\n#define STRFMT_MAXBUF_PTR\t(2+2*sizeof(ptrdiff_t))  /* \"0x\" + hex ptr. */\n\n/* Format parser. */\nLJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs);\n\nstatic LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len)\n{\n  fs->p = (const uint8_t *)p;\n  fs->e = (const uint8_t *)p + len;\n  /* Must be NUL-terminated. May have NULs inside, too. */\n  lj_assertX(*fs->e == 0, \"format not NUL-terminated\");\n}\n\n/* Raw conversions. */\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k);\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v);\nLJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v);\nLJ_FUNC const char *lj_strfmt_wstrnum(lua_State *L, cTValue *o, MSize *lenp);\n\n/* Unformatted conversions to buffer. */\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k);\n#if LJ_HASJIT\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o);\n#endif\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v);\n#if LJ_HASJIT\nLJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str);\n#endif\n\n/* Formatted conversions to buffer. */\nLJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k);\nLJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n);\nLJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c);\n#if LJ_HASJIT\nLJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str);\n#endif\nLJ_FUNC int lj_strfmt_putarg(lua_State *L, SBuf *sb, int arg, int retry);\n\n/* Conversions to strings. */\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k);\nLJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o);\nLJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o);\n#if LJ_HASJIT\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c);\n#endif\nLJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o);\n\n/* Internal string formatting. */\nLJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt,\n\t\t\t\t     va_list argp);\nLJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)\n#if defined(__GNUC__) || defined(__clang__)\n  __attribute__ ((format (printf, 2, 3)))\n#endif\n  ;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_strfmt_num.c",
    "content": "/*\n** String formatting for floating-point numbers.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n** Contributed by Peter Cawley.\n*/\n\n#include <stdio.h>\n\n#define lj_strfmt_num_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_buf.h\"\n#include \"lj_str.h\"\n#include \"lj_strfmt.h\"\n\n/* -- Precomputed tables -------------------------------------------------- */\n\n/* Rescale factors to push the exponent of a number towards zero. */\n#define RESCALE_EXPONENTS(P, N) \\\n  P(308), P(289), P(270), P(250), P(231), P(212), P(193), P(173), P(154), \\\n  P(135), P(115), P(96), P(77), P(58), P(38), P(0), P(0), P(0), N(39), N(58), \\\n  N(77), N(96), N(116), N(135), N(154), N(174), N(193), N(212), N(231), \\\n  N(251), N(270), N(289)\n\n#define ONE_E_P(X) 1e+0 ## X\n#define ONE_E_N(X) 1e-0 ## X\nstatic const int16_t rescale_e[] = { RESCALE_EXPONENTS(-, +) };\nstatic const double rescale_n[] = { RESCALE_EXPONENTS(ONE_E_P, ONE_E_N) };\n#undef ONE_E_N\n#undef ONE_E_P\n\n/*\n** For p in range -70 through 57, this table encodes pairs (m, e) such that\n** 4*2^p <= (uint8_t)m*10^e, and is the smallest value for which this holds.\n*/\nstatic const int8_t four_ulp_m_e[] = {\n  34, -21, 68, -21, 14, -20, 28, -20, 55, -20, 2, -19, 3, -19, 5, -19, 9, -19,\n  -82, -18, 35, -18, 7, -17, -117, -17, 28, -17, 56, -17, 112, -16, -33, -16,\n  45, -16, 89, -16, -78, -15, 36, -15, 72, -15, -113, -14, 29, -14, 57, -14,\n  114, -13, -28, -13, 46, -13, 91, -12, -74, -12, 37, -12, 73, -12, 15, -11, 3,\n  -11, 59, -11, 2, -10, 3, -10, 5, -10, 1, -9, -69, -9, 38, -9, 75, -9, 15, -7,\n  3, -7, 6, -7, 12, -6, -17, -7, 48, -7, 96, -7, -65, -6, 39, -6, 77, -6, -103,\n  -5, 31, -5, 62, -5, 123, -4, -11, -4, 49, -4, 98, -4, -60, -3, 4, -2, 79, -3,\n  16, -2, 32, -2, 63, -2, 2, -1, 25, 0, 5, 1, 1, 2, 2, 2, 4, 2, 8, 2, 16, 2,\n  32, 2, 64, 2, -128, 2, 26, 2, 52, 2, 103, 3, -51, 3, 41, 4, 82, 4, -92, 4,\n  33, 4, 66, 4, -124, 5, 27, 5, 53, 5, 105, 6, 21, 6, 42, 6, 84, 6, 17, 7, 34,\n  7, 68, 7, 2, 8, 3, 8, 6, 8, 108, 9, -41, 9, 43, 10, 86, 9, -84, 10, 35, 10,\n  69, 10, -118, 11, 28, 11, 55, 12, 11, 13, 22, 13, 44, 13, 88, 13, -80, 13,\n  36, 13, 71, 13, -115, 14, 29, 14, 57, 14, 113, 15, -30, 15, 46, 15, 91, 15,\n  19, 16, 37, 16, 73, 16, 2, 17, 3, 17, 6, 17\n};\n\n/* min(2^32-1, 10^e-1) for e in range 0 through 10 */\nstatic uint32_t ndigits_dec_threshold[] = {\n  0, 9U, 99U, 999U, 9999U, 99999U, 999999U,\n  9999999U, 99999999U, 999999999U, 0xffffffffU\n};\n\n/* -- Helper functions ---------------------------------------------------- */\n\n/* Compute the number of digits in the decimal representation of x. */\nstatic MSize ndigits_dec(uint32_t x)\n{\n  MSize t = ((lj_fls(x | 1) * 77) >> 8) + 1; /* 2^8/77 is roughly log2(10) */\n  return t + (x > ndigits_dec_threshold[t]);\n}\n\n#define WINT_R(x, sh, sc) \\\n  { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); }\n\n/* Write 9-digit unsigned integer to buffer. */\nstatic char *lj_strfmt_wuint9(char *p, uint32_t u)\n{\n  uint32_t v = u / 10000, w;\n  u -= v * 10000;\n  w = v / 10000;\n  v -= w * 10000;\n  *p++ = (char)('0'+w);\n  WINT_R(v, 23, 1000)\n  WINT_R(v, 12, 100)\n  WINT_R(v, 10, 10)\n  *p++ = (char)('0'+v);\n  WINT_R(u, 23, 1000)\n  WINT_R(u, 12, 100)\n  WINT_R(u, 10, 10)\n  *p++ = (char)('0'+u);\n  return p;\n}\n#undef WINT_R\n\n/* -- Extended precision arithmetic --------------------------------------- */\n\n/*\n** The \"nd\" format is a fixed-precision decimal representation for numbers. It\n** consists of up to 64 uint32_t values, with each uint32_t storing a value\n** in the range [0, 1e9). A number in \"nd\" format consists of three variables:\n**\n**  uint32_t nd[64];\n**  uint32_t ndlo;\n**  uint32_t ndhi;\n**\n** The integral part of the number is stored in nd[0 ... ndhi], the value of\n** which is sum{i in [0, ndhi] | nd[i] * 10^(9*i)}. If the fractional part of\n** the number is zero, ndlo is zero. Otherwise, the fractional part is stored\n** in nd[ndlo ... 63], the value of which is taken to be\n** sum{i in [ndlo, 63] | nd[i] * 10^(9*(i-64))}.\n**\n** If the array part had 128 elements rather than 64, then every double would\n** have an exact representation in \"nd\" format. With 64 elements, all integral\n** doubles have an exact representation, and all non-integral doubles have\n** enough digits to make both %.99e and %.99f do the right thing.\n*/\n\n#if LJ_64\n#define ND_MUL2K_MAX_SHIFT\t29\n#define ND_MUL2K_DIV1E9(val)\t((uint32_t)((val) / 1000000000))\n#else\n#define ND_MUL2K_MAX_SHIFT\t11\n#define ND_MUL2K_DIV1E9(val)\t((uint32_t)((val) >> 9) / 1953125)\n#endif\n\n/* Multiply nd by 2^k and add carry_in (ndlo is assumed to be zero). */\nstatic uint32_t nd_mul2k(uint32_t* nd, uint32_t ndhi, uint32_t k,\n\t\t\t uint32_t carry_in, SFormat sf)\n{\n  uint32_t i, ndlo = 0, start = 1;\n  /* Performance hacks. */\n  if (k > ND_MUL2K_MAX_SHIFT*2 && STRFMT_FP(sf) != STRFMT_FP(STRFMT_T_FP_F)) {\n    start = ndhi - (STRFMT_PREC(sf) + 17) / 8;\n  }\n  /* Real logic. */\n  while (k >= ND_MUL2K_MAX_SHIFT) {\n    for (i = ndlo; i <= ndhi; i++) {\n      uint64_t val = ((uint64_t)nd[i] << ND_MUL2K_MAX_SHIFT) | carry_in;\n      carry_in = ND_MUL2K_DIV1E9(val);\n      nd[i] = (uint32_t)val - carry_in * 1000000000;\n    }\n    if (carry_in) {\n      nd[++ndhi] = carry_in; carry_in = 0;\n      if (start++ == ndlo) ++ndlo;\n    }\n    k -= ND_MUL2K_MAX_SHIFT;\n  }\n  if (k) {\n    for (i = ndlo; i <= ndhi; i++) {\n      uint64_t val = ((uint64_t)nd[i] << k) | carry_in;\n      carry_in = ND_MUL2K_DIV1E9(val);\n      nd[i] = (uint32_t)val - carry_in * 1000000000;\n    }\n    if (carry_in) nd[++ndhi] = carry_in;\n  }\n  return ndhi;\n}\n\n/* Divide nd by 2^k (ndlo is assumed to be zero). */\nstatic uint32_t nd_div2k(uint32_t* nd, uint32_t ndhi, uint32_t k, SFormat sf)\n{\n  uint32_t ndlo = 0, stop1 = ~0, stop2 = ~0;\n  /* Performance hacks. */\n  if (!ndhi) {\n    if (!nd[0]) {\n      return 0;\n    } else {\n      uint32_t s = lj_ffs(nd[0]);\n      if (s >= k) { nd[0] >>= k; return 0; }\n      nd[0] >>= s; k -= s;\n    }\n  }\n  if (k > 18) {\n    if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_F)) {\n      stop1 = 63 - (int32_t)STRFMT_PREC(sf) / 9;\n    } else {\n      int32_t floorlog2 = ndhi * 29 + lj_fls(nd[ndhi]) - k;\n      int32_t floorlog10 = (int32_t)(floorlog2 * 0.30102999566398114);\n      stop1 = 62 + (floorlog10 - (int32_t)STRFMT_PREC(sf)) / 9;\n      stop2 = 61 + ndhi - (int32_t)STRFMT_PREC(sf) / 8;\n    }\n  }\n  /* Real logic. */\n  while (k >= 9) {\n    uint32_t i = ndhi, carry = 0;\n    for (;;) {\n      uint32_t val = nd[i];\n      nd[i] = (val >> 9) + carry;\n      carry = (val & 0x1ff) * 1953125;\n      if (i == ndlo) break;\n      i = (i - 1) & 0x3f;\n    }\n    if (ndlo != stop1 && ndlo != stop2) {\n      if (carry) { ndlo = (ndlo - 1) & 0x3f; nd[ndlo] = carry; }\n      if (!nd[ndhi]) { ndhi = (ndhi - 1) & 0x3f; stop2--; }\n    } else if (!nd[ndhi]) {\n      if (ndhi != ndlo) { ndhi = (ndhi - 1) & 0x3f; stop2--; }\n      else return ndlo;\n    }\n    k -= 9;\n  }\n  if (k) {\n    uint32_t mask = (1U << k) - 1, mul = 1000000000 >> k, i = ndhi, carry = 0;\n    for (;;) {\n      uint32_t val = nd[i];\n      nd[i] = (val >> k) + carry;\n      carry = (val & mask) * mul;\n      if (i == ndlo) break;\n      i = (i - 1) & 0x3f;\n    }\n    if (carry) { ndlo = (ndlo - 1) & 0x3f; nd[ndlo] = carry; }\n  }\n  return ndlo;\n}\n\n/* Add m*10^e to nd (assumes ndlo <= e/9 <= ndhi and 0 <= m <= 9). */\nstatic uint32_t nd_add_m10e(uint32_t* nd, uint32_t ndhi, uint8_t m, int32_t e)\n{\n  uint32_t i, carry;\n  if (e >= 0) {\n    i = (uint32_t)e/9;\n    carry = m * (ndigits_dec_threshold[e - (int32_t)i*9] + 1);\n  } else {\n    int32_t f = (e-8)/9;\n    i = (uint32_t)(64 + f);\n    carry = m * (ndigits_dec_threshold[e - f*9] + 1);\n  }\n  for (;;) {\n    uint32_t val = nd[i] + carry;\n    if (LJ_UNLIKELY(val >= 1000000000)) {\n      val -= 1000000000;\n      nd[i] = val;\n      if (LJ_UNLIKELY(i == ndhi)) {\n\tndhi = (ndhi + 1) & 0x3f;\n\tnd[ndhi] = 1;\n\tbreak;\n      }\n      carry = 1;\n      i = (i + 1) & 0x3f;\n    } else {\n      nd[i] = val;\n      break;\n    }\n  }\n  return ndhi;\n}\n\n/* Test whether two \"nd\" values are equal in their most significant digits. */\nstatic int nd_similar(uint32_t* nd, uint32_t ndhi, uint32_t* ref, MSize hilen,\n\t\t      MSize prec)\n{\n  char nd9[9], ref9[9];\n  if (hilen <= prec) {\n    if (LJ_UNLIKELY(nd[ndhi] != *ref)) return 0;\n    prec -= hilen; ref--; ndhi = (ndhi - 1) & 0x3f;\n    if (prec >= 9) {\n      if (LJ_UNLIKELY(nd[ndhi] != *ref)) return 0;\n      prec -= 9; ref--; ndhi = (ndhi - 1) & 0x3f;\n    }\n  } else {\n    prec -= hilen - 9;\n  }\n  lj_assertX(prec < 9, \"bad precision %d\", prec);\n  lj_strfmt_wuint9(nd9, nd[ndhi]);\n  lj_strfmt_wuint9(ref9, *ref);\n  return !memcmp(nd9, ref9, prec) && (nd9[prec] < '5') == (ref9[prec] < '5');\n}\n\n/* -- Formatted conversions to buffer ------------------------------------- */\n\n/* Write formatted floating-point number to either sb or p. */\nstatic char *lj_strfmt_wfnum(SBuf *sb, SFormat sf, lua_Number n, char *p)\n{\n  MSize width = STRFMT_WIDTH(sf), prec = STRFMT_PREC(sf), len;\n  TValue t;\n  t.n = n;\n  if (LJ_UNLIKELY((t.u32.hi << 1) >= 0xffe00000)) {\n    /* Handle non-finite values uniformly for %a, %e, %f, %g. */\n    int prefix = 0, ch = (sf & STRFMT_F_UPPER) ? 0x202020 : 0;\n    if (((t.u32.hi & 0x000fffff) | t.u32.lo) != 0) {\n      ch ^= ('n' << 16) | ('a' << 8) | 'n';\n      if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    } else {\n      ch ^= ('i' << 16) | ('n' << 8) | 'f';\n      if ((t.u32.hi & 0x80000000)) prefix = '-';\n      else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n      else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    }\n    len = 3 + (prefix != 0);\n    if (!p) p = lj_buf_more(sb, width > len ? width : len);\n    if (!(sf & STRFMT_F_LEFT)) while (width-- > len) *p++ = ' ';\n    if (prefix) *p++ = prefix;\n    *p++ = (char)(ch >> 16); *p++ = (char)(ch >> 8); *p++ = (char)ch;\n  } else if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_A)) {\n    /* %a */\n    const char *hexdig = (sf & STRFMT_F_UPPER) ? \"0123456789ABCDEFPX\"\n\t\t\t\t\t       : \"0123456789abcdefpx\";\n    int32_t e = (t.u32.hi >> 20) & 0x7ff;\n    char prefix = 0, eprefix = '+';\n    if (t.u32.hi & 0x80000000) prefix = '-';\n    else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n    else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    t.u32.hi &= 0xfffff;\n    if (e) {\n      t.u32.hi |= 0x100000;\n      e -= 1023;\n    } else if (t.u32.lo | t.u32.hi) {\n      /* Non-zero denormal - normalise it. */\n      uint32_t shift = t.u32.hi ? 20-lj_fls(t.u32.hi) : 52-lj_fls(t.u32.lo);\n      e = -1022 - shift;\n      t.u64 <<= shift;\n    }\n    /* abs(n) == t.u64 * 2^(e - 52) */\n    /* If n != 0, bit 52 of t.u64 is set, and is the highest set bit. */\n    if ((int32_t)prec < 0) {\n      /* Default precision: use smallest precision giving exact result. */\n      prec = t.u32.lo ? 13-lj_ffs(t.u32.lo)/4 : 5-lj_ffs(t.u32.hi|0x100000)/4;\n    } else if (prec < 13) {\n      /* Precision is sufficiently low as to maybe require rounding. */\n      t.u64 += (((uint64_t)1) << (51 - prec*4));\n    }\n    if (e < 0) {\n      eprefix = '-';\n      e = -e;\n    }\n    len = 5 + ndigits_dec((uint32_t)e) + prec + (prefix != 0)\n\t    + ((prec | (sf & STRFMT_F_ALT)) != 0);\n    if (!p) p = lj_buf_more(sb, width > len ? width : len);\n    if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n      while (width-- > len) *p++ = ' ';\n    }\n    if (prefix) *p++ = prefix;\n    *p++ = '0';\n    *p++ = hexdig[17]; /* x or X */\n    if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n      while (width-- > len) *p++ = '0';\n    }\n    *p++ = '0' + (t.u32.hi >> 20); /* Usually '1', sometimes '0' or '2'. */\n    if ((prec | (sf & STRFMT_F_ALT))) {\n      /* Emit fractional part. */\n      char *q = p + 1 + prec;\n      *p = '.';\n      if (prec < 13) t.u64 >>= (52 - prec*4);\n      else while (prec > 13) p[prec--] = '0';\n      while (prec) { p[prec--] = hexdig[t.u64 & 15]; t.u64 >>= 4; }\n      p = q;\n    }\n    *p++ = hexdig[16]; /* p or P */\n    *p++ = eprefix; /* + or - */\n    p = lj_strfmt_wint(p, e);\n  } else {\n    /* %e or %f or %g - begin by converting n to \"nd\" format. */\n    uint32_t nd[64];\n    uint32_t ndhi = 0, ndlo, i;\n    int32_t e = (t.u32.hi >> 20) & 0x7ff, ndebias = 0;\n    char prefix = 0, *q;\n    if (t.u32.hi & 0x80000000) prefix = '-';\n    else if ((sf & STRFMT_F_PLUS)) prefix = '+';\n    else if ((sf & STRFMT_F_SPACE)) prefix = ' ';\n    prec += ((int32_t)prec >> 31) & 7; /* Default precision is 6. */\n    if (STRFMT_FP(sf) == STRFMT_FP(STRFMT_T_FP_G)) {\n      /* %g - decrement precision if non-zero (to make it like %e). */\n      prec--;\n      prec ^= (uint32_t)((int32_t)prec >> 31);\n    }\n    if ((sf & STRFMT_T_FP_E) && prec < 14 && n != 0) {\n      /* Precision is sufficiently low that rescaling will probably work. */\n      if ((ndebias = rescale_e[e >> 6])) {\n\tt.n = n * rescale_n[e >> 6];\n\tif (LJ_UNLIKELY(!e)) t.n *= 1e10, ndebias -= 10;\n\tt.u64 -= 2; /* Convert 2ulp below (later we convert 2ulp above). */\n\tnd[0] = 0x100000 | (t.u32.hi & 0xfffff);\n\te = ((t.u32.hi >> 20) & 0x7ff) - 1075 - (ND_MUL2K_MAX_SHIFT < 29);\n\tgoto load_t_lo; rescale_failed:\n\tt.n = n;\n\te = (t.u32.hi >> 20) & 0x7ff;\n\tndebias = ndhi = 0;\n      }\n    }\n    nd[0] = t.u32.hi & 0xfffff;\n    if (e == 0) e++; else nd[0] |= 0x100000;\n    e -= 1043;\n    if (t.u32.lo) {\n      e -= 32 + (ND_MUL2K_MAX_SHIFT < 29); load_t_lo:\n#if ND_MUL2K_MAX_SHIFT >= 29\n      nd[0] = (nd[0] << 3) | (t.u32.lo >> 29);\n      ndhi = nd_mul2k(nd, ndhi, 29, t.u32.lo & 0x1fffffff, sf);\n#elif ND_MUL2K_MAX_SHIFT >= 11\n      ndhi = nd_mul2k(nd, ndhi, 11, t.u32.lo >> 21, sf);\n      ndhi = nd_mul2k(nd, ndhi, 11, (t.u32.lo >> 10) & 0x7ff, sf);\n      ndhi = nd_mul2k(nd, ndhi, 11, (t.u32.lo <<  1) & 0x7ff, sf);\n#else\n#error \"ND_MUL2K_MAX_SHIFT too small\"\n#endif\n    }\n    if (e >= 0) {\n      ndhi = nd_mul2k(nd, ndhi, (uint32_t)e, 0, sf);\n      ndlo = 0;\n    } else {\n      ndlo = nd_div2k(nd, ndhi, (uint32_t)-e, sf);\n      if (ndhi && !nd[ndhi]) ndhi--;\n    }\n    /* abs(n) == nd * 10^ndebias (for slightly loose interpretation of ==) */\n    if ((sf & STRFMT_T_FP_E)) {\n      /* %e or %g - assume %e and start by calculating nd's exponent (nde). */\n      char eprefix = '+';\n      int32_t nde = -1;\n      MSize hilen;\n      if (ndlo && !nd[ndhi]) {\n\tndhi = 64; do {} while (!nd[--ndhi]);\n\tnde -= 64 * 9;\n      }\n      hilen = ndigits_dec(nd[ndhi]);\n      nde += ndhi * 9 + hilen;\n      if (ndebias) {\n\t/*\n\t** Rescaling was performed, but this introduced some error, and might\n\t** have pushed us across a rounding boundary. We check whether this\n\t** error affected the result by introducing even more error (2ulp in\n\t** either direction), and seeing whether a rounding boundary was\n\t** crossed. Having already converted the -2ulp case, we save off its\n\t** most significant digits, convert the +2ulp case, and compare them.\n\t*/\n\tint32_t eidx = e + 70 + (ND_MUL2K_MAX_SHIFT < 29)\n\t\t\t + (t.u32.lo >= 0xfffffffe && !(~t.u32.hi << 12));\n\tconst int8_t *m_e = four_ulp_m_e + eidx * 2;\n\tlj_assertG_(G(sbufL(sb)), 0 <= eidx && eidx < 128, \"bad eidx %d\", eidx);\n\tnd[33] = nd[ndhi];\n\tnd[32] = nd[(ndhi - 1) & 0x3f];\n\tnd[31] = nd[(ndhi - 2) & 0x3f];\n\tnd_add_m10e(nd, ndhi, (uint8_t)*m_e, m_e[1]);\n\tif (LJ_UNLIKELY(!nd_similar(nd, ndhi, nd + 33, hilen, prec + 1))) {\n\t  goto rescale_failed;\n\t}\n      }\n      if ((int32_t)(prec - nde) < (0x3f & -(int32_t)ndlo) * 9) {\n\t/* Precision is sufficiently low as to maybe require rounding. */\n\tndhi = nd_add_m10e(nd, ndhi, 5, nde - prec - 1);\n\tnde += (hilen != ndigits_dec(nd[ndhi]));\n      }\n      nde += ndebias;\n      if ((sf & STRFMT_T_FP_F)) {\n\t/* %g */\n\tif ((int32_t)prec >= nde && nde >= -4) {\n\t  if (nde < 0) ndhi = 0;\n\t  prec -= nde;\n\t  goto g_format_like_f;\n\t} else if (!(sf & STRFMT_F_ALT) && prec && width > 5) {\n\t  /* Decrease precision in order to strip trailing zeroes. */\n\t  char tail[9];\n\t  uint32_t maxprec = hilen - 1 + ((ndhi - ndlo) & 0x3f) * 9;\n\t  if (prec >= maxprec) prec = maxprec;\n\t  else ndlo = (ndhi - (((int32_t)(prec - hilen) + 9) / 9)) & 0x3f;\n\t  i = prec - hilen - (((ndhi - ndlo) & 0x3f) * 9) + 10;\n\t  lj_strfmt_wuint9(tail, nd[ndlo]);\n\t  while (prec && tail[--i] == '0') {\n\t    prec--;\n\t    if (!i) {\n\t      if (ndlo == ndhi) { prec = 0; break; }\n\t      lj_strfmt_wuint9(tail, nd[++ndlo]);\n\t      i = 9;\n\t    }\n\t  }\n\t}\n      }\n      if (nde < 0) {\n\t/* Make nde non-negative. */\n\teprefix = '-';\n\tnde = -nde;\n      }\n      len = 3 + prec + (prefix != 0) + ndigits_dec((uint32_t)nde) + (nde < 10)\n\t      + ((prec | (sf & STRFMT_F_ALT)) != 0);\n      if (!p) p = lj_buf_more(sb, (width > len ? width : len) + 5);\n      if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n\twhile (width-- > len) *p++ = ' ';\n      }\n      if (prefix) *p++ = prefix;\n      if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n\twhile (width-- > len) *p++ = '0';\n      }\n      q = lj_strfmt_wint(p + 1, nd[ndhi]);\n      p[0] = p[1]; /* Put leading digit in the correct place. */\n      if ((prec | (sf & STRFMT_F_ALT))) {\n\t/* Emit fractional part. */\n\tp[1] = '.'; p += 2;\n\tprec -= (MSize)(q - p); p = q; /* Account for digits already emitted. */\n\t/* Then emit chunks of 9 digits (this may emit 8 digits too many). */\n\tfor (i = ndhi; (int32_t)prec > 0 && i != ndlo; prec -= 9) {\n\t  i = (i - 1) & 0x3f;\n\t  p = lj_strfmt_wuint9(p, nd[i]);\n\t}\n\tif ((sf & STRFMT_T_FP_F) && !(sf & STRFMT_F_ALT)) {\n\t  /* %g (and not %#g) - strip trailing zeroes. */\n\t  p += (int32_t)prec & ((int32_t)prec >> 31);\n\t  while (p[-1] == '0') p--;\n\t  if (p[-1] == '.') p--;\n\t} else {\n\t  /* %e (or %#g) - emit trailing zeroes. */\n\t  while ((int32_t)prec > 0) { *p++ = '0'; prec--; }\n\t  p += (int32_t)prec;\n\t}\n      } else {\n\tp++;\n      }\n      *p++ = (sf & STRFMT_F_UPPER) ? 'E' : 'e';\n      *p++ = eprefix; /* + or - */\n      if (nde < 10) *p++ = '0'; /* Always at least two digits of exponent. */\n      p = lj_strfmt_wint(p, nde);\n    } else {\n      /* %f (or, shortly, %g in %f style) */\n      if (prec < (MSize)(0x3f & -(int32_t)ndlo) * 9) {\n\t/* Precision is sufficiently low as to maybe require rounding. */\n\tndhi = nd_add_m10e(nd, ndhi, 5, 0 - prec - 1);\n      }\n      g_format_like_f:\n      if ((sf & STRFMT_T_FP_E) && !(sf & STRFMT_F_ALT) && prec && width) {\n\t/* Decrease precision in order to strip trailing zeroes. */\n\tif (ndlo) {\n\t  /* nd has a fractional part; we need to look at its digits. */\n\t  char tail[9];\n\t  uint32_t maxprec = (64 - ndlo) * 9;\n\t  if (prec >= maxprec) prec = maxprec;\n\t  else ndlo = 64 - (prec + 8) / 9;\n\t  i = prec - ((63 - ndlo) * 9);\n\t  lj_strfmt_wuint9(tail, nd[ndlo]);\n\t  while (prec && tail[--i] == '0') {\n\t    prec--;\n\t    if (!i) {\n\t      if (ndlo == 63) { prec = 0; break; }\n\t      lj_strfmt_wuint9(tail, nd[++ndlo]);\n\t      i = 9;\n\t    }\n\t  }\n\t} else {\n\t  /* nd has no fractional part, so precision goes straight to zero. */\n\t  prec = 0;\n\t}\n      }\n      len = ndhi * 9 + ndigits_dec(nd[ndhi]) + prec + (prefix != 0)\n\t\t     + ((prec | (sf & STRFMT_F_ALT)) != 0);\n      if (!p) p = lj_buf_more(sb, (width > len ? width : len) + 8);\n      if (!(sf & (STRFMT_F_LEFT | STRFMT_F_ZERO))) {\n\twhile (width-- > len) *p++ = ' ';\n      }\n      if (prefix) *p++ = prefix;\n      if ((sf & (STRFMT_F_LEFT | STRFMT_F_ZERO)) == STRFMT_F_ZERO) {\n\twhile (width-- > len) *p++ = '0';\n      }\n      /* Emit integer part. */\n      p = lj_strfmt_wint(p, nd[ndhi]);\n      i = ndhi;\n      while (i) p = lj_strfmt_wuint9(p, nd[--i]);\n      if ((prec | (sf & STRFMT_F_ALT))) {\n\t/* Emit fractional part. */\n\t*p++ = '.';\n\t/* Emit chunks of 9 digits (this may emit 8 digits too many). */\n\twhile ((int32_t)prec > 0 && i != ndlo) {\n\t  i = (i - 1) & 0x3f;\n\t  p = lj_strfmt_wuint9(p, nd[i]);\n\t  prec -= 9;\n\t}\n\tif ((sf & STRFMT_T_FP_E) && !(sf & STRFMT_F_ALT)) {\n\t  /* %g (and not %#g) - strip trailing zeroes. */\n\t  p += (int32_t)prec & ((int32_t)prec >> 31);\n\t  while (p[-1] == '0') p--;\n\t  if (p[-1] == '.') p--;\n\t} else {\n\t  /* %f (or %#g) - emit trailing zeroes. */\n\t  while ((int32_t)prec > 0) { *p++ = '0'; prec--; }\n\t  p += (int32_t)prec;\n\t}\n      }\n    }\n  }\n  if ((sf & STRFMT_F_LEFT)) while (width-- > len) *p++ = ' ';\n  return p;\n}\n\n/* Add formatted floating-point number to buffer. */\nSBuf *lj_strfmt_putfnum(SBuf *sb, SFormat sf, lua_Number n)\n{\n  sb->w = lj_strfmt_wfnum(sb, sf, n, NULL);\n  return sb;\n}\n\n/* -- Conversions to strings ---------------------------------------------- */\n\n/* Convert number to string. */\nGCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o)\n{\n  char buf[STRFMT_MAXBUF_NUM];\n  MSize len = (MSize)(lj_strfmt_wfnum(NULL, STRFMT_G14, o->n, buf) - buf);\n  return lj_str_new(L, buf, len);\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_strscan.c",
    "content": "/*\n** String scanning.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <math.h>\n\n#define lj_strscan_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_char.h\"\n#include \"lj_strscan.h\"\n\n/* -- Scanning numbers ---------------------------------------------------- */\n\n/*\n** Rationale for the builtin string to number conversion library:\n**\n** It removes a dependency on libc's strtod(), which is a true portability\n** nightmare. Mainly due to the plethora of supported OS and toolchain\n** combinations. Sadly, the various implementations\n** a) are often buggy, incomplete (no hex floats) and/or imprecise,\n** b) sometimes crash or hang on certain inputs,\n** c) return non-standard NaNs that need to be filtered out, and\n** d) fail if the locale-specific decimal separator is not a dot,\n**    which can only be fixed with atrocious workarounds.\n**\n** Also, most of the strtod() implementations are hopelessly bloated,\n** which is not just an I-cache hog, but a problem for static linkage\n** on embedded systems, too.\n**\n** OTOH the builtin conversion function is very compact. Even though it\n** does a lot more, like parsing long longs, octal or imaginary numbers\n** and returning the result in different formats:\n** a) It needs less than 3 KB (!) of machine code (on x64 with -Os),\n** b) it doesn't perform any dynamic allocation and,\n** c) it needs only around 600 bytes of stack space.\n**\n** The builtin function is faster than strtod() for typical inputs, e.g.\n** \"123\", \"1.5\" or \"1e6\". Arguably, it's slower for very large exponents,\n** which are not very common (this could be fixed, if needed).\n**\n** And most importantly, the builtin function is equally precise on all\n** platforms. It correctly converts and rounds any input to a double.\n** If this is not the case, please send a bug report -- but PLEASE verify\n** that the implementation you're comparing to is not the culprit!\n**\n** The implementation quickly pre-scans the entire string first and\n** handles simple integers on-the-fly. Otherwise, it dispatches to the\n** base-specific parser. Hex and octal is straightforward.\n**\n** Decimal to binary conversion uses a fixed-length circular buffer in\n** base 100. Some simple cases are handled directly. For other cases, the\n** number in the buffer is up-scaled or down-scaled until the integer part\n** is in the proper range. Then the integer part is rounded and converted\n** to a double which is finally rescaled to the result. Denormals need\n** special treatment to prevent incorrect 'double rounding'.\n*/\n\n/* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */\n#define STRSCAN_DIG\t1024\n#define STRSCAN_MAXDIG\t800\t\t/* 772 + extra are sufficient. */\n#define STRSCAN_DDIG\t(STRSCAN_DIG/2)\n#define STRSCAN_DMASK\t(STRSCAN_DDIG-1)\n\n/* Helpers for circular buffer. */\n#define DNEXT(a)\t(((a)+1) & STRSCAN_DMASK)\n#define DPREV(a)\t(((a)-1) & STRSCAN_DMASK)\n#define DLEN(lo, hi)\t((int32_t)(((lo)-(hi)) & STRSCAN_DMASK))\n\n#define casecmp(c, k)\t(((c) | 0x20) == k)\n\n/* Final conversion to double. */\nstatic void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg)\n{\n  double n;\n\n  /* Avoid double rounding for denormals. */\n  if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) {\n    /* NYI: all of this generates way too much code on 32 bit CPUs. */\n#if (defined(__GNUC__) || defined(__clang__)) && LJ_64\n    int32_t b = (int32_t)(__builtin_clzll(x)^63);\n#else\n    int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) :\n\t\t\t  (int32_t)lj_fls((uint32_t)x);\n#endif\n    if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) {\n      uint64_t rb = (uint64_t)1 << (-1075-ex2);\n      if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb;\n      x = (x & ~(rb+rb-1));\n    }\n  }\n\n  /* Convert to double using a signed int64_t conversion, then rescale. */\n  lj_assertX((int64_t)x >= 0, \"bad double conversion\");\n  n = (double)(int64_t)x;\n  if (neg) n = -n;\n  if (ex2) n = ldexp(n, ex2);\n  o->n = n;\n}\n\n/* Parse hexadecimal number. */\nstatic StrScanFmt strscan_hex(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex2, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n  uint32_t i;\n\n  /* Scan hex digits. */\n  for (i = dig > 16 ? 16 : dig ; i; i--, p++) {\n    uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9;\n    x = (x << 4) + (d & 15);\n  }\n\n  /* Summarize rounding-effect of excess digits. */\n  for (i = 16; i < dig; i++, p++)\n    x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4;\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n      o->i = neg ? -(int32_t)x : (int32_t)x;\n      return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n    }\n    if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }\n    /* fallthrough */\n  case STRSCAN_U32:\n    if (dig > 8) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    return STRSCAN_U32;\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    if (dig > 16) return STRSCAN_ERROR;\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    return fmt;\n  default:\n    break;\n  }\n\n  /* Reduce range, then convert to double. */\n  if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }\n  strscan_double(x, o, ex2, neg);\n  return fmt;\n}\n\n/* Parse octal number. */\nstatic StrScanFmt strscan_oct(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n\n  /* Scan octal digits. */\n  if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR;\n  while (dig-- > 0) {\n    if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR;\n    x = (x << 3) + (*p++ & 7);\n  }\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (x >= 0x80000000u+neg) fmt = STRSCAN_U32;\n    /* fallthrough */\n  case STRSCAN_U32:\n    if ((x >> 32)) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    break;\n  default:\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    break;\n  }\n  return fmt;\n}\n\n/* Parse decimal number. */\nstatic StrScanFmt strscan_dec(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex10, int32_t neg, uint32_t dig)\n{\n  uint8_t xi[STRSCAN_DDIG], *xip = xi;\n\n  if (dig) {\n    uint32_t i = dig;\n    if (i > STRSCAN_MAXDIG) {\n      ex10 += (int32_t)(i - STRSCAN_MAXDIG);\n      i = STRSCAN_MAXDIG;\n    }\n    /* Scan unaligned leading digit. */\n    if (((ex10^i) & 1))\n      *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++;\n    /* Scan aligned double-digits. */\n    for ( ; i > 1; i -= 2) {\n      uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++;\n      *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++;\n    }\n    /* Scan and realign trailing digit. */\n    if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, dig++, p++;\n\n    /* Summarize rounding-effect of excess digits. */\n    if (dig > STRSCAN_MAXDIG) {\n      do {\n\tif ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; }\n\tp++;\n      } while (--dig > STRSCAN_MAXDIG);\n      dig = STRSCAN_MAXDIG;\n    } else {  /* Simplify exponent. */\n      while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2;\n    }\n  } else {  /* Only got zeros. */\n    ex10 = 0;\n    xi[0] = 0;\n  }\n\n  /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */\n  if (dig <= 20 && ex10 == 0) {\n    uint8_t *xis;\n    uint64_t x = xi[0];\n    double n;\n    for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis;\n    if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) {  /* No overflow? */\n      /* Format-specific handling. */\n      switch (fmt) {\n      case STRSCAN_INT:\n\tif (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n\t  o->i = neg ? -(int32_t)x : (int32_t)x;\n\t  return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n\t}\n\tif (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }\n\t/* fallthrough */\n      case STRSCAN_U32:\n\tif ((x >> 32) != 0) return STRSCAN_ERROR;\n\to->i = neg ? -(int32_t)x : (int32_t)x;\n\treturn STRSCAN_U32;\n      case STRSCAN_I64:\n      case STRSCAN_U64:\n\to->u64 = neg ? (uint64_t)-(int64_t)x : x;\n\treturn fmt;\n      default:\n      plainnumber:  /* Fast path for plain numbers < 2^63. */\n\tif ((int64_t)x < 0) break;\n\tn = (double)(int64_t)x;\n\tif (neg) n = -n;\n\to->n = n;\n\treturn fmt;\n      }\n    }\n  }\n\n  /* Slow non-integer path. */\n  if (fmt == STRSCAN_INT) {\n    if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;\n    fmt = STRSCAN_NUM;\n  } else if (fmt > STRSCAN_INT) {\n    return STRSCAN_ERROR;\n  }\n  {\n    uint32_t hi = 0, lo = (uint32_t)(xip-xi);\n    int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1);\n\n    lj_assertX(lo > 0 && (ex10 & 1) == 0, \"bad lo %d ex10 %d\", lo, ex10);\n\n    /* Handle simple overflow/underflow. */\n    if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; }\n    else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; }\n\n    /* Scale up until we have at least 17 or 18 integer part digits. */\n    while (idig < 9 && idig < DLEN(lo, hi)) {\n      uint32_t i, cy = 0;\n      ex2 -= 6;\n      for (i = DPREV(lo); ; i = DPREV(i)) {\n\tuint32_t d = (xi[i] << 6) + cy;\n\tcy = (((d >> 2) * 5243) >> 17); d = d - cy * 100;  /* Div/mod 100. */\n\txi[i] = (uint8_t)d;\n\tif (i == hi) break;\n\tif (d == 0 && i == DPREV(lo)) lo = i;\n      }\n      if (cy) {\n\thi = DPREV(hi);\n\tif (xi[DPREV(lo)] == 0) lo = DPREV(lo);\n\telse if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; }\n\txi[hi] = (uint8_t)cy; idig++;\n      }\n    }\n\n    /* Scale down until no more than 17 or 18 integer part digits remain. */\n    while (idig > 9) {\n      uint32_t i = hi, cy = 0;\n      ex2 += 6;\n      do {\n\tcy += xi[i];\n\txi[i] = (cy >> 6);\n\tcy = 100 * (cy & 0x3f);\n\tif (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--;\n\ti = DNEXT(i);\n      } while (i != lo);\n      while (cy) {\n\tif (hi == lo) { xi[DPREV(lo)] |= 1; break; }\n\txi[lo] = (cy >> 6); lo = DNEXT(lo);\n\tcy = 100 * (cy & 0x3f);\n      }\n    }\n\n    /* Collect integer part digits and convert to rescaled double. */\n    {\n      uint64_t x = xi[hi];\n      uint32_t i;\n      for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i))\n\tx = x * 100 + xi[i];\n      if (i == lo) {\n\twhile (--idig >= 0) x = x * 100;\n      } else {  /* Gather round bit from remaining digits. */\n\tx <<= 1; ex2--;\n\tdo {\n\t  if (xi[i]) { x |= 1; break; }\n\t  i = DNEXT(i);\n\t} while (i != lo);\n      }\n      strscan_double(x, o, ex2, neg);\n    }\n  }\n  return fmt;\n}\n\n/* Parse binary number. */\nstatic StrScanFmt strscan_bin(const uint8_t *p, TValue *o,\n\t\t\t      StrScanFmt fmt, uint32_t opt,\n\t\t\t      int32_t ex2, int32_t neg, uint32_t dig)\n{\n  uint64_t x = 0;\n  uint32_t i;\n\n  if (ex2 || dig > 64) return STRSCAN_ERROR;\n\n  /* Scan binary digits. */\n  for (i = dig; i; i--, p++) {\n    if ((*p & ~1) != '0') return STRSCAN_ERROR;\n    x = (x << 1) | (*p & 1);\n  }\n\n  /* Format-specific handling. */\n  switch (fmt) {\n  case STRSCAN_INT:\n    if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {\n      o->i = neg ? -(int32_t)x : (int32_t)x;\n      return STRSCAN_INT;  /* Fast path for 32 bit integers. */\n    }\n    if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }\n    /* fallthrough */\n  case STRSCAN_U32:\n    if (dig > 32) return STRSCAN_ERROR;\n    o->i = neg ? -(int32_t)x : (int32_t)x;\n    return STRSCAN_U32;\n  case STRSCAN_I64:\n  case STRSCAN_U64:\n    o->u64 = neg ? (uint64_t)-(int64_t)x : x;\n    return fmt;\n  default:\n    break;\n  }\n\n  /* Reduce range, then convert to double. */\n  if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }\n  strscan_double(x, o, ex2, neg);\n  return fmt;\n}\n\n/* Scan string containing a number. Returns format. Returns value in o. */\nStrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o,\n\t\t\t   uint32_t opt)\n{\n  int32_t neg = 0;\n  const uint8_t *pe = p + len;\n\n  /* Remove leading space, parse sign and non-numbers. */\n  if (LJ_UNLIKELY(!lj_char_isdigit(*p))) {\n    while (lj_char_isspace(*p)) p++;\n    if (*p == '+' || *p == '-') neg = (*p++ == '-');\n    if (LJ_UNLIKELY(*p >= 'A')) {  /* Parse \"inf\", \"infinity\" or \"nan\". */\n      TValue tmp;\n      setnanV(&tmp);\n      if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) {\n\tif (neg) setminfV(&tmp); else setpinfV(&tmp);\n\tp += 3;\n\tif (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') &&\n\t    casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5;\n      } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) {\n\tp += 3;\n      }\n      while (lj_char_isspace(*p)) p++;\n      if (*p || p < pe) return STRSCAN_ERROR;\n      o->u64 = tmp.u64;\n      return STRSCAN_NUM;\n    }\n  }\n\n  /* Parse regular number. */\n  {\n    StrScanFmt fmt = STRSCAN_INT;\n    int cmask = LJ_CHAR_DIGIT;\n    int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10;\n    const uint8_t *sp, *dp = NULL;\n    uint32_t dig = 0, hasdig = 0, x = 0;\n    int32_t ex = 0;\n\n    /* Determine base and skip leading zeros. */\n    if (LJ_UNLIKELY(*p <= '0')) {\n      if (*p == '0') {\n\tif (casecmp(p[1], 'x'))\n\t  base = 16, cmask = LJ_CHAR_XDIGIT, p += 2;\n\telse if (casecmp(p[1], 'b'))\n\t  base = 2, cmask = LJ_CHAR_DIGIT, p += 2;\n      }\n      for ( ; ; p++) {\n\tif (*p == '0') {\n\t  hasdig = 1;\n\t} else if (*p == '.') {\n\t  if (dp) return STRSCAN_ERROR;\n\t  dp = p;\n\t} else {\n\t  break;\n\t}\n      }\n    }\n\n    /* Preliminary digit and decimal point scan. */\n    for (sp = p; ; p++) {\n      if (LJ_LIKELY(lj_char_isa(*p, cmask))) {\n\tx = x * 10 + (*p & 15);  /* For fast path below. */\n\tdig++;\n      } else if (*p == '.') {\n\tif (dp) return STRSCAN_ERROR;\n\tdp = p;\n      } else {\n\tbreak;\n      }\n    }\n    if (!(hasdig | dig)) return STRSCAN_ERROR;\n\n    /* Handle decimal point. */\n    if (dp) {\n      if (base == 2) return STRSCAN_ERROR;\n      fmt = STRSCAN_NUM;\n      if (dig) {\n\tex = (int32_t)(dp-(p-1)); dp = p-1;\n\twhile (ex < 0 && *dp-- == '0') ex++, dig--;  /* Skip trailing zeros. */\n\tif (base == 16) ex *= 4;\n      }\n    }\n\n    /* Parse exponent. */\n    if (base >= 10 && casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) {\n      uint32_t xx;\n      int negx = 0;\n      fmt = STRSCAN_NUM; p++;\n      if (*p == '+' || *p == '-') negx = (*p++ == '-');\n      if (!lj_char_isdigit(*p)) return STRSCAN_ERROR;\n      xx = (*p++ & 15);\n      while (lj_char_isdigit(*p)) {\n\tif (xx < 65536) xx = xx * 10 + (*p & 15);\n\tp++;\n      }\n      ex += negx ? -(int32_t)xx : (int32_t)xx;\n    }\n\n    /* Parse suffix. */\n    if (*p) {\n      /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */\n      /* NYI: f (float). Not needed until cp_number() handles non-integers. */\n      if (casecmp(*p, 'i')) {\n\tif (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR;\n\tp++; fmt = STRSCAN_IMAG;\n      } else if (fmt == STRSCAN_INT) {\n\tif (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32;\n\tif (casecmp(*p, 'l')) {\n\t  p++;\n\t  if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT;\n\t  else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;\n\t  else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT;\n\t}\n\tif (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64))\n\t  p++, fmt += STRSCAN_U32 - STRSCAN_INT;\n\tif ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) ||\n\t    (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL)))\n\t  return STRSCAN_ERROR;\n      }\n      while (lj_char_isspace(*p)) p++;\n      if (*p) return STRSCAN_ERROR;\n    }\n    if (p < pe) return STRSCAN_ERROR;\n\n    /* Fast path for decimal 32 bit integers. */\n    if (fmt == STRSCAN_INT && base == 10 &&\n\t(dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) {\n      if ((opt & STRSCAN_OPT_TONUM)) {\n\to->n = neg ? -(double)x : (double)x;\n\treturn STRSCAN_NUM;\n      } else {\n\to->i = neg ? -(int32_t)x : (int32_t)x;\n\treturn STRSCAN_INT;\n      }\n    }\n\n    /* Dispatch to base-specific parser. */\n    if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG))\n      return strscan_oct(sp, o, fmt, neg, dig);\n    if (base == 16)\n      fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig);\n    else if (base == 2)\n      fmt = strscan_bin(sp, o, fmt, opt, ex, neg, dig);\n    else\n      fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig);\n\n    /* Try to convert number to integer, if requested. */\n    if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) {\n      double n = o->n;\n      int32_t i = lj_num2int(n);\n      if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; }\n    }\n    return fmt;\n  }\n}\n\nint LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o)\n{\n  StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), str->len, o,\n\t\t\t\t   STRSCAN_OPT_TONUM);\n  lj_assertX(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM, \"bad scan format\");\n  return (fmt != STRSCAN_ERROR);\n}\n\n#if LJ_DUALNUM\nint LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o)\n{\n  StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), str->len, o,\n\t\t\t\t   STRSCAN_OPT_TOINT);\n  lj_assertX(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT,\n\t     \"bad scan format\");\n  if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM);\n  return (fmt != STRSCAN_ERROR);\n}\n#endif\n\n#undef DNEXT\n#undef DPREV\n#undef DLEN\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_strscan.h",
    "content": "/*\n** String scanning.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_STRSCAN_H\n#define _LJ_STRSCAN_H\n\n#include \"lj_obj.h\"\n\n/* Options for accepted/returned formats. */\n#define STRSCAN_OPT_TOINT\t0x01  /* Convert to int32_t, if possible. */\n#define STRSCAN_OPT_TONUM\t0x02  /* Always convert to double. */\n#define STRSCAN_OPT_IMAG\t0x04\n#define STRSCAN_OPT_LL\t\t0x08\n#define STRSCAN_OPT_C\t\t0x10\n\n/* Returned format. */\ntypedef enum {\n  STRSCAN_ERROR,\n  STRSCAN_NUM, STRSCAN_IMAG,\n  STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,\n} StrScanFmt;\n\nLJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o,\n\t\t\t\t   uint32_t opt);\nLJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);\n#if LJ_DUALNUM\nLJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);\n#else\n#define lj_strscan_number(s, o)\t\tlj_strscan_num((s), (o))\n#endif\n\n/* Check for number or convert string to number/int in-place (!). */\nstatic LJ_AINLINE int lj_strscan_numberobj(TValue *o)\n{\n  return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));\n}\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_tab.c",
    "content": "/*\n** Table handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#define lj_tab_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_tab.h\"\n\n/* -- Object hashing ------------------------------------------------------ */\n\n/* Hash an arbitrary key and return its anchor position in the hash table. */\nstatic Node *hashkey(const GCtab *t, cTValue *key)\n{\n  lj_assertX(!tvisint(key), \"attempt to hash integer\");\n  if (tvisstr(key))\n    return hashstr(t, strV(key));\n  else if (tvisnum(key))\n    return hashnum(t, key);\n  else if (tvisbool(key))\n    return hashmask(t, boolV(key));\n  else\n    return hashgcref(t, key->gcr);\n  /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */\n}\n\n/* -- Table creation and destruction -------------------------------------- */\n\n/* Create new hash part for table. */\nstatic LJ_AINLINE void newhpart(lua_State *L, GCtab *t, uint32_t hbits)\n{\n  uint32_t hsize;\n  Node *node;\n  lj_assertL(hbits != 0, \"zero hash size\");\n  if (hbits > LJ_MAX_HBITS)\n    lj_err_msg(L, LJ_ERR_TABOV);\n  hsize = 1u << hbits;\n  node = lj_mem_newvec(L, hsize, Node);\n  setmref(t->node, node);\n  setfreetop(t, node, &node[hsize]);\n  t->hmask = hsize-1;\n}\n\n/*\n** Q: Why all of these copies of t->hmask, t->node etc. to local variables?\n** A: Because alias analysis for C is _really_ tough.\n**    Even state-of-the-art C compilers won't produce good code without this.\n*/\n\n/* Clear hash part of table. */\nstatic LJ_AINLINE void clearhpart(GCtab *t)\n{\n  uint32_t i, hmask = t->hmask;\n  Node *node = noderef(t->node);\n  lj_assertX(t->hmask != 0, \"empty hash part\");\n  for (i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    setmref(n->next, NULL);\n    setnilV(&n->key);\n    setnilV(&n->val);\n  }\n}\n\n/* Clear array part of table. */\nstatic LJ_AINLINE void clearapart(GCtab *t)\n{\n  uint32_t i, asize = t->asize;\n  TValue *array = tvref(t->array);\n  for (i = 0; i < asize; i++)\n    setnilV(&array[i]);\n}\n\n/* Create a new table. Note: the slots are not initialized (yet). */\nstatic GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)\n{\n  GCtab *t;\n  /* First try to colocate the array part. */\n  if (LJ_MAX_COLOSIZE != 0 && asize > 0 && asize <= LJ_MAX_COLOSIZE) {\n    Node *nilnode;\n    lj_assertL((sizeof(GCtab) & 7) == 0, \"bad GCtab size\");\n    t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));\n    t->gct = ~LJ_TTAB;\n    t->nomm = (uint8_t)~0;\n    t->colo = (int8_t)asize;\n    setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));\n    setgcrefnull(t->metatable);\n    t->asize = asize;\n    t->hmask = 0;\n    nilnode = &G(L)->nilnode;\n    setmref(t->node, nilnode);\n#if LJ_GC64\n    setmref(t->freetop, nilnode);\n#endif\n  } else {  /* Otherwise separately allocate the array part. */\n    Node *nilnode;\n    t = lj_mem_newobj(L, GCtab);\n    t->gct = ~LJ_TTAB;\n    t->nomm = (uint8_t)~0;\n    t->colo = 0;\n    setmref(t->array, NULL);\n    setgcrefnull(t->metatable);\n    t->asize = 0;  /* In case the array allocation fails. */\n    t->hmask = 0;\n    nilnode = &G(L)->nilnode;\n    setmref(t->node, nilnode);\n#if LJ_GC64\n    setmref(t->freetop, nilnode);\n#endif\n    if (asize > 0) {\n      if (asize > LJ_MAX_ASIZE)\n\tlj_err_msg(L, LJ_ERR_TABOV);\n      setmref(t->array, lj_mem_newvec(L, asize, TValue));\n      t->asize = asize;\n    }\n  }\n  if (hbits)\n    newhpart(L, t, hbits);\n  return t;\n}\n\n/* Create a new table.\n**\n** IMPORTANT NOTE: The API differs from lua_createtable()!\n**\n** The array size is non-inclusive. E.g. asize=128 creates array slots\n** for 0..127, but not for 128. If you need slots 1..128, pass asize=129\n** (slot 0 is wasted in this case).\n**\n** The hash size is given in hash bits. hbits=0 means no hash part.\n** hbits=1 creates 2 hash slots, hbits=2 creates 4 hash slots and so on.\n*/\nGCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits)\n{\n  GCtab *t = newtab(L, asize, hbits);\n  clearapart(t);\n  if (t->hmask > 0) clearhpart(t);\n  return t;\n}\n\n/* The API of this function conforms to lua_createtable(). */\nGCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h)\n{\n  return lj_tab_new(L, (uint32_t)(a > 0 ? a+1 : 0), hsize2hbits(h));\n}\n\n#if LJ_HASJIT\nGCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize)\n{\n  GCtab *t = newtab(L, ahsize & 0xffffff, ahsize >> 24);\n  clearapart(t);\n  if (t->hmask > 0) clearhpart(t);\n  return t;\n}\n#endif\n\n/* Duplicate a table. */\nGCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt)\n{\n  GCtab *t;\n  uint32_t asize, hmask;\n  t = newtab(L, kt->asize, kt->hmask > 0 ? lj_fls(kt->hmask)+1 : 0);\n  lj_assertL(kt->asize == t->asize && kt->hmask == t->hmask,\n\t     \"mismatched size of table and template\");\n  t->nomm = 0;  /* Keys with metamethod names may be present. */\n  asize = kt->asize;\n  if (asize > 0) {\n    TValue *array = tvref(t->array);\n    TValue *karray = tvref(kt->array);\n    if (asize < 64) {  /* An inlined loop beats memcpy for < 512 bytes. */\n      uint32_t i;\n      for (i = 0; i < asize; i++)\n\tcopyTV(L, &array[i], &karray[i]);\n    } else {\n      memcpy(array, karray, asize*sizeof(TValue));\n    }\n  }\n  hmask = kt->hmask;\n  if (hmask > 0) {\n    uint32_t i;\n    Node *node = noderef(t->node);\n    Node *knode = noderef(kt->node);\n    ptrdiff_t d = (char *)node - (char *)knode;\n    setfreetop(t, node, (Node *)((char *)getfreetop(kt, knode) + d));\n    for (i = 0; i <= hmask; i++) {\n      Node *kn = &knode[i];\n      Node *n = &node[i];\n      Node *next = nextnode(kn);\n      /* Don't use copyTV here, since it asserts on a copy of a dead key. */\n      n->val = kn->val; n->key = kn->key;\n      setmref(n->next, next == NULL? next : (Node *)((char *)next + d));\n    }\n  }\n  return t;\n}\n\n/* Clear a table. */\nvoid LJ_FASTCALL lj_tab_clear(GCtab *t)\n{\n  clearapart(t);\n  if (t->hmask > 0) {\n    Node *node = noderef(t->node);\n    setfreetop(t, node, &node[t->hmask+1]);\n    clearhpart(t);\n  }\n}\n\n/* Free a table. */\nvoid LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)\n{\n  if (t->hmask > 0)\n    lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);\n  if (t->asize > 0 && LJ_MAX_COLOSIZE != 0 && t->colo <= 0)\n    lj_mem_freevec(g, tvref(t->array), t->asize, TValue);\n  if (LJ_MAX_COLOSIZE != 0 && t->colo)\n    lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));\n  else\n    lj_mem_freet(g, t);\n}\n\n/* -- Table resizing ------------------------------------------------------ */\n\n/* Resize a table to fit the new array/hash part sizes. */\nvoid lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits)\n{\n  Node *oldnode = noderef(t->node);\n  uint32_t oldasize = t->asize;\n  uint32_t oldhmask = t->hmask;\n  if (asize > oldasize) {  /* Array part grows? */\n    TValue *array;\n    uint32_t i;\n    if (asize > LJ_MAX_ASIZE)\n      lj_err_msg(L, LJ_ERR_TABOV);\n    if (LJ_MAX_COLOSIZE != 0 && t->colo > 0) {\n      /* A colocated array must be separated and copied. */\n      TValue *oarray = tvref(t->array);\n      array = lj_mem_newvec(L, asize, TValue);\n      t->colo = (int8_t)(t->colo | 0x80);  /* Mark as separated (colo < 0). */\n      for (i = 0; i < oldasize; i++)\n\tcopyTV(L, &array[i], &oarray[i]);\n    } else {\n      array = (TValue *)lj_mem_realloc(L, tvref(t->array),\n\t\t\t  oldasize*sizeof(TValue), asize*sizeof(TValue));\n    }\n    setmref(t->array, array);\n    t->asize = asize;\n    for (i = oldasize; i < asize; i++)  /* Clear newly allocated slots. */\n      setnilV(&array[i]);\n  }\n  /* Create new (empty) hash part. */\n  if (hbits) {\n    newhpart(L, t, hbits);\n    clearhpart(t);\n  } else {\n    global_State *g = G(L);\n    setmref(t->node, &g->nilnode);\n#if LJ_GC64\n    setmref(t->freetop, &g->nilnode);\n#endif\n    t->hmask = 0;\n  }\n  if (asize < oldasize) {  /* Array part shrinks? */\n    TValue *array = tvref(t->array);\n    uint32_t i;\n    t->asize = asize;  /* Note: This 'shrinks' even colocated arrays. */\n    for (i = asize; i < oldasize; i++)  /* Reinsert old array values. */\n      if (!tvisnil(&array[i]))\n\tcopyTV(L, lj_tab_setinth(L, t, (int32_t)i), &array[i]);\n    /* Physically shrink only separated arrays. */\n    if (LJ_MAX_COLOSIZE != 0 && t->colo <= 0)\n      setmref(t->array, lj_mem_realloc(L, array,\n\t      oldasize*sizeof(TValue), asize*sizeof(TValue)));\n  }\n  if (oldhmask > 0) {  /* Reinsert pairs from old hash part. */\n    global_State *g;\n    uint32_t i;\n    for (i = 0; i <= oldhmask; i++) {\n      Node *n = &oldnode[i];\n      if (!tvisnil(&n->val))\n\tcopyTV(L, lj_tab_set(L, t, &n->key), &n->val);\n    }\n    g = G(L);\n    lj_mem_freevec(g, oldnode, oldhmask+1, Node);\n  }\n}\n\nstatic uint32_t countint(cTValue *key, uint32_t *bins)\n{\n  lj_assertX(!tvisint(key), \"bad integer key\");\n  if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if ((uint32_t)k < LJ_MAX_ASIZE && nk == (lua_Number)k) {\n      bins[(k > 2 ? lj_fls((uint32_t)(k-1)) : 0)]++;\n      return 1;\n    }\n  }\n  return 0;\n}\n\nstatic uint32_t countarray(const GCtab *t, uint32_t *bins)\n{\n  uint32_t na, b, i;\n  if (t->asize == 0) return 0;\n  for (na = i = b = 0; b < LJ_MAX_ABITS; b++) {\n    uint32_t n, top = 2u << b;\n    TValue *array;\n    if (top >= t->asize) {\n      top = t->asize-1;\n      if (i > top)\n\tbreak;\n    }\n    array = tvref(t->array);\n    for (n = 0; i <= top; i++)\n      if (!tvisnil(&array[i]))\n\tn++;\n    bins[b] += n;\n    na += n;\n  }\n  return na;\n}\n\nstatic uint32_t counthash(const GCtab *t, uint32_t *bins, uint32_t *narray)\n{\n  uint32_t total, na, i, hmask = t->hmask;\n  Node *node = noderef(t->node);\n  for (total = na = 0, i = 0; i <= hmask; i++) {\n    Node *n = &node[i];\n    if (!tvisnil(&n->val)) {\n      na += countint(&n->key, bins);\n      total++;\n    }\n  }\n  *narray += na;\n  return total;\n}\n\nstatic uint32_t bestasize(uint32_t bins[], uint32_t *narray)\n{\n  uint32_t b, sum, na = 0, sz = 0, nn = *narray;\n  for (b = 0, sum = 0; 2*nn > (1u<<b) && sum != nn; b++)\n    if (bins[b] > 0 && 2*(sum += bins[b]) > (1u<<b)) {\n      sz = (2u<<b)+1;\n      na = sum;\n    }\n  *narray = sz;\n  return na;\n}\n\nstatic void rehashtab(lua_State *L, GCtab *t, cTValue *ek)\n{\n  uint32_t bins[LJ_MAX_ABITS];\n  uint32_t total, asize, na, i;\n  for (i = 0; i < LJ_MAX_ABITS; i++) bins[i] = 0;\n  asize = countarray(t, bins);\n  total = 1 + asize;\n  total += counthash(t, bins, &asize);\n  asize += countint(ek, bins);\n  na = bestasize(bins, &asize);\n  total -= na;\n  lj_tab_resize(L, t, asize, hsize2hbits(total));\n}\n\n#if LJ_HASFFI\nvoid lj_tab_rehash(lua_State *L, GCtab *t)\n{\n  rehashtab(L, t, niltv(L));\n}\n#endif\n\nvoid lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize)\n{\n  lj_tab_resize(L, t, nasize+1, t->hmask > 0 ? lj_fls(t->hmask)+1 : 0);\n}\n\n/* -- Table getters ------------------------------------------------------- */\n\ncTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key)\n{\n  TValue k;\n  Node *n;\n  k.n = (lua_Number)key;\n  n = hashnum(t, &k);\n  do {\n    if (tvisnum(&n->key) && n->key.n == k.n)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return NULL;\n}\n\ncTValue *lj_tab_getstr(GCtab *t, const GCstr *key)\n{\n  Node *n = hashstr(t, key);\n  do {\n    if (tvisstr(&n->key) && strV(&n->key) == key)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return NULL;\n}\n\ncTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key)\n{\n  if (tvisstr(key)) {\n    cTValue *tv = lj_tab_getstr(t, strV(key));\n    if (tv)\n      return tv;\n  } else if (tvisint(key)) {\n    cTValue *tv = lj_tab_getint(t, intV(key));\n    if (tv)\n      return tv;\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if (nk == (lua_Number)k) {\n      cTValue *tv = lj_tab_getint(t, k);\n      if (tv)\n\treturn tv;\n    } else {\n      goto genlookup;  /* Else use the generic lookup. */\n    }\n  } else if (!tvisnil(key)) {\n    Node *n;\n  genlookup:\n    n = hashkey(t, key);\n    do {\n      if (lj_obj_equal(&n->key, key))\n\treturn &n->val;\n    } while ((n = nextnode(n)));\n  }\n  return niltv(L);\n}\n\n/* -- Table setters ------------------------------------------------------- */\n\n/* Insert new key. Use Brent's variation to optimize the chain length. */\nTValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key)\n{\n  Node *n = hashkey(t, key);\n  if (!tvisnil(&n->val) || t->hmask == 0) {\n    Node *nodebase = noderef(t->node);\n    Node *collide, *freenode = getfreetop(t, nodebase);\n    lj_assertL(freenode >= nodebase && freenode <= nodebase+t->hmask+1,\n\t       \"bad freenode\");\n    do {\n      if (freenode == nodebase) {  /* No free node found? */\n\trehashtab(L, t, key);  /* Rehash table. */\n\treturn lj_tab_set(L, t, key);  /* Retry key insertion. */\n      }\n    } while (!tvisnil(&(--freenode)->key));\n    setfreetop(t, nodebase, freenode);\n    lj_assertL(freenode != &G(L)->nilnode, \"store to fallback hash\");\n    collide = hashkey(t, &n->key);\n    if (collide != n) {  /* Colliding node not the main node? */\n      while (noderef(collide->next) != n)  /* Find predecessor. */\n\tcollide = nextnode(collide);\n      setmref(collide->next, freenode);  /* Relink chain. */\n      /* Copy colliding node into free node and free main node. */\n      freenode->val = n->val;\n      freenode->key = n->key;\n      freenode->next = n->next;\n      setmref(n->next, NULL);\n      setnilV(&n->val);\n      /* Rechain pseudo-resurrected string keys with colliding hashes. */\n      while (nextnode(freenode)) {\n\tNode *nn = nextnode(freenode);\n\tif (!tvisnil(&nn->val) && hashkey(t, &nn->key) == n) {\n\t  freenode->next = nn->next;\n\t  nn->next = n->next;\n\t  setmref(n->next, nn);\n\t  /*\n\t  ** Rechaining a resurrected string key creates a new dilemma:\n\t  ** Another string key may have originally been resurrected via\n\t  ** _any_ of the previous nodes as a chain anchor. Including\n\t  ** a node that had to be moved, which makes them unreachable.\n\t  ** It's not feasible to check for all previous nodes, so rechain\n\t  ** any string key that's currently in a non-main positions.\n\t  */\n\t  while ((nn = nextnode(freenode))) {\n\t    if (!tvisnil(&nn->val)) {\n\t      Node *mn = hashkey(t, &nn->key);\n\t      if (mn != freenode && mn != nn) {\n\t\tfreenode->next = nn->next;\n\t\tnn->next = mn->next;\n\t\tsetmref(mn->next, nn);\n\t      } else {\n\t\tfreenode = nn;\n\t      }\n\t    } else {\n\t      freenode = nn;\n\t    }\n\t  }\n\t  break;\n\t} else {\n\t  freenode = nn;\n\t}\n      }\n    } else {  /* Otherwise use free node. */\n      setmrefr(freenode->next, n->next);  /* Insert into chain. */\n      setmref(n->next, freenode);\n      n = freenode;\n    }\n  }\n  n->key.u64 = key->u64;\n  if (LJ_UNLIKELY(tvismzero(&n->key)))\n    n->key.u64 = 0;\n  lj_gc_anybarriert(L, t);\n  lj_assertL(tvisnil(&n->val), \"new hash slot is not empty\");\n  return &n->val;\n}\n\nTValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key)\n{\n  TValue k;\n  Node *n;\n  k.n = (lua_Number)key;\n  n = hashnum(t, &k);\n  do {\n    if (tvisnum(&n->key) && n->key.n == k.n)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return lj_tab_newkey(L, t, &k);\n}\n\nTValue *lj_tab_setstr(lua_State *L, GCtab *t, const GCstr *key)\n{\n  TValue k;\n  Node *n = hashstr(t, key);\n  do {\n    if (tvisstr(&n->key) && strV(&n->key) == key)\n      return &n->val;\n  } while ((n = nextnode(n)));\n  setstrV(L, &k, key);\n  return lj_tab_newkey(L, t, &k);\n}\n\nTValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key)\n{\n  Node *n;\n  t->nomm = 0;  /* Invalidate negative metamethod cache. */\n  if (tvisstr(key)) {\n    return lj_tab_setstr(L, t, strV(key));\n  } else if (tvisint(key)) {\n    return lj_tab_setint(L, t, intV(key));\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if (nk == (lua_Number)k)\n      return lj_tab_setint(L, t, k);\n    if (tvisnan(key))\n      lj_err_msg(L, LJ_ERR_NANIDX);\n    /* Else use the generic lookup. */\n  } else if (tvisnil(key)) {\n    lj_err_msg(L, LJ_ERR_NILIDX);\n  }\n  n = hashkey(t, key);\n  do {\n    if (lj_obj_equal(&n->key, key))\n      return &n->val;\n  } while ((n = nextnode(n)));\n  return lj_tab_newkey(L, t, key);\n}\n\n/* -- Table traversal ----------------------------------------------------- */\n\n/* Table traversal indexes:\n**\n** Array key index: [0 .. t->asize-1]\n** Hash key index:  [t->asize .. t->asize+t->hmask]\n** Invalid key:     ~0\n*/\n\n/* Get the successor traversal index of a key. */\nuint32_t LJ_FASTCALL lj_tab_keyindex(GCtab *t, cTValue *key)\n{\n  TValue tmp;\n  if (tvisint(key)) {\n    int32_t k = intV(key);\n    if ((uint32_t)k < t->asize)\n      return (uint32_t)k + 1;\n    setnumV(&tmp, (lua_Number)k);\n    key = &tmp;\n  } else if (tvisnum(key)) {\n    lua_Number nk = numV(key);\n    int32_t k = lj_num2int(nk);\n    if ((uint32_t)k < t->asize && nk == (lua_Number)k)\n      return (uint32_t)k + 1;\n  }\n  if (!tvisnil(key)) {\n    Node *n = hashkey(t, key);\n    do {\n      if (lj_obj_equal(&n->key, key))\n\treturn t->asize + (uint32_t)((n+1) - noderef(t->node));\n    } while ((n = nextnode(n)));\n    if (key->u32.hi == LJ_KEYINDEX)  /* Despecialized ITERN while running. */\n      return key->u32.lo;\n    return ~0u;  /* Invalid key to next. */\n  }\n  return 0;  /* A nil key starts the traversal. */\n}\n\n/* Get the next key/value pair of a table traversal. */\nint lj_tab_next(GCtab *t, cTValue *key, TValue *o)\n{\n  uint32_t idx = lj_tab_keyindex(t, key);  /* Find successor index of key. */\n  /* First traverse the array part. */\n  for (; idx < t->asize; idx++) {\n    cTValue *a = arrayslot(t, idx);\n    if (LJ_LIKELY(!tvisnil(a))) {\n      setintV(o, idx);\n      o[1] = *a;\n      return 1;\n    }\n  }\n  idx -= t->asize;\n  /* Then traverse the hash part. */\n  for (; idx <= t->hmask; idx++) {\n    Node *n = &noderef(t->node)[idx];\n    if (!tvisnil(&n->val)) {\n      o[0] = n->key;\n      o[1] = n->val;\n      return 1;\n    }\n  }\n  return (int32_t)idx < 0 ? -1 : 0;  /* Invalid key or end of traversal. */\n}\n\n/* -- Table length calculation -------------------------------------------- */\n\n/* Compute table length. Slow path with mixed array/hash lookups. */\nLJ_NOINLINE static MSize tab_len_slow(GCtab *t, size_t hi)\n{\n  cTValue *tv;\n  size_t lo = hi;\n  hi++;\n  /* Widening search for an upper bound. */\n  while ((tv = lj_tab_getint(t, (int32_t)hi)) && !tvisnil(tv)) {\n    lo = hi;\n    hi += hi;\n    if (hi > (size_t)(INT_MAX-2)) {  /* Punt and do a linear search. */\n      lo = 1;\n      while ((tv = lj_tab_getint(t, (int32_t)lo)) && !tvisnil(tv)) lo++;\n      return (MSize)(lo - 1);\n    }\n  }\n  /* Binary search to find a non-nil to nil transition. */\n  while (hi - lo > 1) {\n    size_t mid = (lo+hi) >> 1;\n    cTValue *tvb = lj_tab_getint(t, (int32_t)mid);\n    if (tvb && !tvisnil(tvb)) lo = mid; else hi = mid;\n  }\n  return (MSize)lo;\n}\n\n/* Compute table length. Fast path. */\nMSize LJ_FASTCALL lj_tab_len(GCtab *t)\n{\n  size_t hi = (size_t)t->asize;\n  if (hi) hi--;\n  /* In a growing array the last array element is very likely nil. */\n  if (hi > 0 && LJ_LIKELY(tvisnil(arrayslot(t, hi)))) {\n    /* Binary search to find a non-nil to nil transition in the array. */\n    size_t lo = 0;\n    while (hi - lo > 1) {\n      size_t mid = (lo+hi) >> 1;\n      if (tvisnil(arrayslot(t, mid))) hi = mid; else lo = mid;\n    }\n    return (MSize)lo;\n  }\n  /* Without a hash part, there's an implicit nil after the last element. */\n  return t->hmask ? tab_len_slow(t, hi) : (MSize)hi;\n}\n\n#if LJ_HASJIT\n/* Verify hinted table length or compute it. */\nMSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint)\n{\n  size_t asize = (size_t)t->asize;\n  cTValue *tv = arrayslot(t, hint);\n  if (LJ_LIKELY(hint+1 < asize)) {\n    if (LJ_LIKELY(!tvisnil(tv) && tvisnil(tv+1))) return (MSize)hint;\n  } else if (hint+1 <= asize && LJ_LIKELY(t->hmask == 0) && !tvisnil(tv)) {\n    return (MSize)hint;\n  }\n  return lj_tab_len(t);\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_tab.h",
    "content": "/*\n** Table handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TAB_H\n#define _LJ_TAB_H\n\n#include \"lj_obj.h\"\n\n/* Hash constants. Tuned using a brute force search. */\n#define HASH_BIAS\t(-0x04c11db7)\n#define HASH_ROT1\t14\n#define HASH_ROT2\t5\n#define HASH_ROT3\t13\n\n/* Scramble the bits of numbers and pointers. */\nstatic LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi)\n{\n#if LJ_TARGET_X86ORX64\n  /* Prefer variant that compiles well for a 2-operand CPU. */\n  lo ^= hi; hi = lj_rol(hi, HASH_ROT1);\n  lo -= hi; hi = lj_rol(hi, HASH_ROT2);\n  hi ^= lo; hi -= lj_rol(lo, HASH_ROT3);\n#else\n  lo ^= hi;\n  lo = lo - lj_rol(hi, HASH_ROT1);\n  hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2);\n  hi = hi - lj_rol(lo, HASH_ROT3);\n#endif\n  return hi;\n}\n\n/* Hash values are masked with the table hash mask and used as an index. */\nstatic LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash)\n{\n  Node *n = noderef(t->node);\n  return &n[hash & t->hmask];\n}\n\n/* String IDs are generated when a string is interned. */\n#define hashstr(t, s)\t\thashmask(t, (s)->sid)\n\n#define hashlohi(t, lo, hi)\thashmask((t), hashrot((lo), (hi)))\n#define hashnum(t, o)\t\thashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1))\n#if LJ_GC64\n#define hashgcref(t, r) \\\n  hashlohi((t), (uint32_t)gcrefu(r), (uint32_t)(gcrefu(r) >> 32))\n#else\n#define hashgcref(t, r)\t\thashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS)\n#endif\n\n#define hsize2hbits(s)\t((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)\n\nLJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);\nLJ_FUNC GCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h);\n#if LJ_HASJIT\nLJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);\n#endif\nLJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);\nLJ_FUNC void LJ_FASTCALL lj_tab_clear(GCtab *t);\nLJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);\n#if LJ_HASFFI\nLJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);\n#endif\nLJ_FUNC void lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits);\nLJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);\n\n/* Caveat: all getters except lj_tab_get() can return NULL! */\n\nLJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key);\nLJ_FUNC cTValue *lj_tab_getstr(GCtab *t, const GCstr *key);\nLJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);\n\n/* Caveat: all setters require a write barrier for the stored value. */\n\nLJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);\nLJ_FUNCA TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);\nLJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, const GCstr *key);\nLJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);\n\n#define inarray(t, key)\t\t((MSize)(key) < (MSize)(t)->asize)\n#define arrayslot(t, i)\t\t(&tvref((t)->array)[(i)])\n#define lj_tab_getint(t, key) \\\n  (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))\n#define lj_tab_setint(L, t, key) \\\n  (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))\n\nLJ_FUNC uint32_t LJ_FASTCALL lj_tab_keyindex(GCtab *t, cTValue *key);\nLJ_FUNCA int lj_tab_next(GCtab *t, cTValue *key, TValue *o);\nLJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);\n#if LJ_HASJIT\nLJ_FUNC MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target.h",
    "content": "/*\n** Definitions for target CPU.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_H\n#define _LJ_TARGET_H\n\n#include \"lj_def.h\"\n#include \"lj_arch.h\"\n\n/* -- Registers and spill slots ------------------------------------------- */\n\n/* Register type (uint8_t in ir->r). */\ntypedef uint32_t Reg;\n\n/* The hi-bit is NOT set for an allocated register. This means the value\n** can be directly used without masking. The hi-bit is set for a register\n** allocation hint or for RID_INIT, RID_SINK or RID_SUNK.\n*/\n#define RID_NONE\t\t0x80\n#define RID_MASK\t\t0x7f\n#define RID_INIT\t\t(RID_NONE|RID_MASK)\n#define RID_SINK\t\t(RID_INIT-1)\n#define RID_SUNK\t\t(RID_INIT-2)\n\n#define ra_noreg(r)\t\t((r) & RID_NONE)\n#define ra_hasreg(r)\t\t(!((r) & RID_NONE))\n\n/* The ra_hashint() macro assumes a previous test for ra_noreg(). */\n#define ra_hashint(r)\t\t((r) < RID_SUNK)\n#define ra_gethint(r)\t\t((Reg)((r) & RID_MASK))\n#define ra_sethint(rr, r)\trr = (uint8_t)((r)|RID_NONE)\n#define ra_samehint(r1, r2)\t(ra_gethint((r1)^(r2)) == 0)\n\n/* Spill slot 0 means no spill slot has been allocated. */\n#define SPS_NONE\t\t0\n\n#define ra_hasspill(s)\t\t((s) != SPS_NONE)\n\n/* Combined register and spill slot (uint16_t in ir->prev). */\ntypedef uint32_t RegSP;\n\n#define REGSP(r, s)\t\t((r) + ((s) << 8))\n#define REGSP_HINT(r)\t\t((r)|RID_NONE)\n#define REGSP_INIT\t\tREGSP(RID_INIT, 0)\n\n#define regsp_reg(rs)\t\t((rs) & 255)\n#define regsp_spill(rs)\t\t((rs) >> 8)\n#define regsp_used(rs) \\\n  (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0))\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Bitset for registers. 32 registers suffice for most architectures.\n** Note that one set holds bits for both GPRs and FPRs.\n*/\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS || LJ_TARGET_ARM64\ntypedef uint64_t RegSet;\n#else\ntypedef uint32_t RegSet;\n#endif\n\n#define RID2RSET(r)\t\t(((RegSet)1) << (r))\n#define RSET_EMPTY\t\t((RegSet)0)\n#define RSET_RANGE(lo, hi)\t((RID2RSET((hi)-(lo))-1) << (lo))\n\n#define rset_test(rs, r)\t((int)((rs) >> (r)) & 1)\n#define rset_set(rs, r)\t\t(rs |= RID2RSET(r))\n#define rset_clear(rs, r)\t(rs &= ~RID2RSET(r))\n#define rset_exclude(rs, r)\t(rs & ~RID2RSET(r))\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS || LJ_TARGET_ARM64\n#define rset_picktop(rs)\t((Reg)(__builtin_clzll(rs)^63))\n#define rset_pickbot(rs)\t((Reg)__builtin_ctzll(rs))\n#else\n#define rset_picktop(rs)\t((Reg)lj_fls(rs))\n#define rset_pickbot(rs)\t((Reg)lj_ffs(rs))\n#endif\n\n/* -- Register allocation cost -------------------------------------------- */\n\n/* The register allocation heuristic keeps track of the cost for allocating\n** a specific register:\n**\n** A free register (obviously) has a cost of 0 and a 1-bit in the free mask.\n**\n** An already allocated register has the (non-zero) IR reference in the lowest\n** bits and the result of a blended cost-model in the higher bits.\n**\n** The allocator first checks the free mask for a hit. Otherwise an (unrolled)\n** linear search for the minimum cost is used. The search doesn't need to\n** keep track of the position of the minimum, which makes it very fast.\n** The lowest bits of the minimum cost show the desired IR reference whose\n** register is the one to evict.\n**\n** Without the cost-model this degenerates to the standard heuristics for\n** (reverse) linear-scan register allocation. Since code generation is done\n** in reverse, a live interval extends from the last use to the first def.\n** For an SSA IR the IR reference is the first (and only) def and thus\n** trivially marks the end of the interval. The LSRA heuristics says to pick\n** the register whose live interval has the furthest extent, i.e. the lowest\n** IR reference in our case.\n**\n** A cost-model should take into account other factors, like spill-cost and\n** restore- or rematerialization-cost, which depend on the kind of instruction.\n** E.g. constants have zero spill costs, variant instructions have higher\n** costs than invariants and PHIs should preferably never be spilled.\n**\n** Here's a first cut at simple, but effective blended cost-model for R-LSRA:\n** - Due to careful design of the IR, constants already have lower IR\n**   references than invariants and invariants have lower IR references\n**   than variants.\n** - The cost in the upper 16 bits is the sum of the IR reference and a\n**   weighted score. The score currently only takes into account whether\n**   the IRT_ISPHI bit is set in the instruction type.\n** - The PHI weight is the minimum distance (in IR instructions) a PHI\n**   reference has to be further apart from a non-PHI reference to be spilled.\n** - It should be a power of two (for speed) and must be between 2 and 32768.\n**   Good values for the PHI weight seem to be between 40 and 150.\n** - Further study is required.\n*/\n#define REGCOST_PHI_WEIGHT\t64\n\n/* Cost for allocating a specific register. */\ntypedef uint32_t RegCost;\n\n/* Note: assumes 16 bit IRRef1. */\n#define REGCOST(cost, ref)\t((RegCost)(ref) + ((RegCost)(cost) << 16))\n#define regcost_ref(rc)\t\t((IRRef1)(rc))\n\n#define REGCOST_T(t) \\\n  ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI))\n#define REGCOST_REF_T(ref, t)\t(REGCOST((ref), (ref)) + REGCOST_T((t)))\n\n/* -- Target-specific definitions ----------------------------------------- */\n\n#if LJ_TARGET_X86ORX64\n#include \"lj_target_x86.h\"\n#elif LJ_TARGET_ARM\n#include \"lj_target_arm.h\"\n#elif LJ_TARGET_ARM64\n#include \"lj_target_arm64.h\"\n#elif LJ_TARGET_PPC\n#include \"lj_target_ppc.h\"\n#elif LJ_TARGET_MIPS\n#include \"lj_target_mips.h\"\n#else\n#error \"Missing include for target CPU\"\n#endif\n\n#ifdef EXITSTUBS_PER_GROUP\n/* Return the address of an exit stub. */\nstatic LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno)\n{\n  lj_assertX(group[exitno / EXITSTUBS_PER_GROUP] != NULL,\n\t     \"exit stub group for exit %d uninitialized\", exitno);\n  return (char *)group[exitno / EXITSTUBS_PER_GROUP] +\n\t EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP);\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_addr(J, exitno) \\\n  ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno)))\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_arm.h",
    "content": "/*\n** Definitions for ARM CPUs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_ARM_H\n#define _LJ_TARGET_ARM_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC)\n#if LJ_SOFTFP\n#define FPRDEF(_)\n#else\n#define FPRDEF(_) \\\n  _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \\\n  _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15)\n#endif\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_LR,\n\n  /* Calling conventions. */\n  RID_RET = RID_R0,\n  RID_RETLO = RID_R0,\n  RID_RETHI = RID_R1,\n#if LJ_SOFTFP\n  RID_FPRET = RID_R0,\n#else\n  RID_FPRET = RID_D0,\n#endif\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R9,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R6,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R7,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R8,\t\t/* Interpreter L. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_PC+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n#if LJ_SOFTFP\n  RID_MAX_FPR = RID_MIN_FPR,\n#else\n  RID_MAX_FPR = RID_D15+1,\n#endif\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except sp, lr and pc. */\n#define RSET_GPR\t\t(RSET_RANGE(RID_MIN_GPR, RID_R12+1))\n#define RSET_GPREVEN \\\n  (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \\\n   RID2RSET(RID_R8)|RID2RSET(RID_R10))\n#define RSET_GPRODD \\\n  (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \\\n   RID2RSET(RID_R9)|RID2RSET(RID_R11))\n#if LJ_SOFTFP\n#define RSET_FPR\t\t0\n#else\n#define RSET_FPR\t\t(RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))\n#endif\n#define RSET_ALL\t\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\t\tRSET_ALL\n\n/* ABI-specific register sets. lr is an implicit scratch register. */\n#define RSET_SCRATCH_GPR_\t(RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12))\n#ifdef __APPLE__\n#define RSET_SCRATCH_GPR\t(RSET_SCRATCH_GPR_|RID2RSET(RID_R9))\n#else\n#define RSET_SCRATCH_GPR\tRSET_SCRATCH_GPR_\n#endif\n#if LJ_SOFTFP\n#define RSET_SCRATCH_FPR\t0\n#else\n#define RSET_SCRATCH_FPR\t(RSET_RANGE(RID_D0, RID_D7+1))\n#endif\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R0\n#define REGARG_LASTGPR\t\tRID_R3\n#define REGARG_NUMGPR\t\t4\n#if LJ_ABI_SOFTFP\n#define REGARG_FIRSTFPR\t\t0\n#define REGARG_LASTFPR\t\t0\n#define REGARG_NUMFPR\t\t0\n#else\n#define REGARG_FIRSTFPR\t\tRID_D0\n#define REGARG_LASTFPR\t\tRID_D7\n#define REGARG_NUMFPR\t\t8\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#define SPS_FIXED\t2\n#define SPS_FIRST\t2\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 1) & ~1)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n#if !LJ_SOFTFP\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n#endif\n  int32_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* PC after instruction that caused an exit. Used to find the trace number. */\n#define EXITSTATE_PCREG\t\tRID_PC\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n#define EXITSTUB_SPACING        4\n#define EXITSTUBS_PER_GROUP     32\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define ARMF_CC(ai, cc)\t(((ai) ^ ARMI_CCAL) | ((cc) << 28))\n#define ARMF_N(r)\t((r) << 16)\n#define ARMF_D(r)\t((r) << 12)\n#define ARMF_S(r)\t((r) << 8)\n#define ARMF_M(r)\t(r)\n#define ARMF_SH(sh, n)\t(((sh) << 5) | ((n) << 7))\n#define ARMF_RSH(sh, r)\t(0x10 | ((sh) << 5) | ARMF_S(r))\n\ntypedef enum ARMIns {\n  ARMI_CCAL = 0xe0000000,\n  ARMI_S = 0x000100000,\n  ARMI_K12 = 0x02000000,\n  ARMI_KNEG = 0x00200000,\n  ARMI_LS_W = 0x00200000,\n  ARMI_LS_U = 0x00800000,\n  ARMI_LS_P = 0x01000000,\n  ARMI_LS_R = 0x02000000,\n  ARMI_LSX_I = 0x00400000,\n\n  ARMI_AND = 0xe0000000,\n  ARMI_EOR = 0xe0200000,\n  ARMI_SUB = 0xe0400000,\n  ARMI_RSB = 0xe0600000,\n  ARMI_ADD = 0xe0800000,\n  ARMI_ADC = 0xe0a00000,\n  ARMI_SBC = 0xe0c00000,\n  ARMI_RSC = 0xe0e00000,\n  ARMI_TST = 0xe1100000,\n  ARMI_TEQ = 0xe1300000,\n  ARMI_CMP = 0xe1500000,\n  ARMI_CMN = 0xe1700000,\n  ARMI_ORR = 0xe1800000,\n  ARMI_MOV = 0xe1a00000,\n  ARMI_BIC = 0xe1c00000,\n  ARMI_MVN = 0xe1e00000,\n\n  ARMI_NOP = 0xe1a00000,\n\n  ARMI_MUL = 0xe0000090,\n  ARMI_SMULL = 0xe0c00090,\n\n  ARMI_LDR = 0xe4100000,\n  ARMI_LDRB = 0xe4500000,\n  ARMI_LDRH = 0xe01000b0,\n  ARMI_LDRSB = 0xe01000d0,\n  ARMI_LDRSH = 0xe01000f0,\n  ARMI_LDRD = 0xe00000d0,\n  ARMI_STR = 0xe4000000,\n  ARMI_STRB = 0xe4400000,\n  ARMI_STRH = 0xe00000b0,\n  ARMI_STRD = 0xe00000f0,\n  ARMI_PUSH = 0xe92d0000,\n\n  ARMI_B = 0xea000000,\n  ARMI_BL = 0xeb000000,\n  ARMI_BLX = 0xfa000000,\n  ARMI_BLXr = 0xe12fff30,\n\n  /* ARMv6 */\n  ARMI_REV = 0xe6bf0f30,\n  ARMI_SXTB = 0xe6af0070,\n  ARMI_SXTH = 0xe6bf0070,\n  ARMI_UXTB = 0xe6ef0070,\n  ARMI_UXTH = 0xe6ff0070,\n\n  /* ARMv6T2 */\n  ARMI_MOVW = 0xe3000000,\n  ARMI_MOVT = 0xe3400000,\n  ARMI_BFI = 0xe7c00010,\n\n  /* VFP */\n  ARMI_VMOV_D = 0xeeb00b40,\n  ARMI_VMOV_S = 0xeeb00a40,\n  ARMI_VMOVI_D = 0xeeb00b00,\n\n  ARMI_VMOV_R_S = 0xee100a10,\n  ARMI_VMOV_S_R = 0xee000a10,\n  ARMI_VMOV_RR_D = 0xec500b10,\n  ARMI_VMOV_D_RR = 0xec400b10,\n\n  ARMI_VADD_D = 0xee300b00,\n  ARMI_VSUB_D = 0xee300b40,\n  ARMI_VMUL_D = 0xee200b00,\n  ARMI_VMLA_D = 0xee000b00,\n  ARMI_VMLS_D = 0xee000b40,\n  ARMI_VNMLS_D = 0xee100b00,\n  ARMI_VDIV_D = 0xee800b00,\n\n  ARMI_VABS_D = 0xeeb00bc0,\n  ARMI_VNEG_D = 0xeeb10b40,\n  ARMI_VSQRT_D = 0xeeb10bc0,\n\n  ARMI_VCMP_D = 0xeeb40b40,\n  ARMI_VCMPZ_D = 0xeeb50b40,\n\n  ARMI_VMRS = 0xeef1fa10,\n\n  ARMI_VCVT_S32_F32 = 0xeebd0ac0,\n  ARMI_VCVT_S32_F64 = 0xeebd0bc0,\n  ARMI_VCVT_U32_F32 = 0xeebc0ac0,\n  ARMI_VCVT_U32_F64 = 0xeebc0bc0,\n  ARMI_VCVT_F32_S32 = 0xeeb80ac0,\n  ARMI_VCVT_F64_S32 = 0xeeb80bc0,\n  ARMI_VCVT_F32_U32 = 0xeeb80a40,\n  ARMI_VCVT_F64_U32 = 0xeeb80b40,\n  ARMI_VCVT_F32_F64 = 0xeeb70bc0,\n  ARMI_VCVT_F64_F32 = 0xeeb70ac0,\n\n  ARMI_VLDR_S = 0xed100a00,\n  ARMI_VLDR_D = 0xed100b00,\n  ARMI_VSTR_S = 0xed000a00,\n  ARMI_VSTR_D = 0xed000b00,\n} ARMIns;\n\ntypedef enum ARMShift {\n  ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR\n} ARMShift;\n\n/* ARM condition codes. */\ntypedef enum ARMCC {\n  CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,\n  CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,\n  CC_HS = CC_CS, CC_LO = CC_CC\n} ARMCC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_arm64.h",
    "content": "/*\n** Definitions for ARM64 CPUs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_ARM64_H\n#define _LJ_TARGET_ARM64_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(X0) _(X1) _(X2) _(X3) _(X4) _(X5) _(X6) _(X7) \\\n  _(X8) _(X9) _(X10) _(X11) _(X12) _(X13) _(X14) _(X15) \\\n  _(X16) _(X17) _(X18) _(X19) _(X20) _(X21) _(X22) _(X23) \\\n  _(X24) _(X25) _(X26) _(X27) _(X28) _(FP) _(LR) _(SP)\n#define FPRDEF(_) \\\n  _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \\\n  _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15) \\\n  _(D16) _(D17) _(D18) _(D19) _(D20) _(D21) _(D22) _(D23) \\\n  _(D24) _(D25) _(D26) _(D27) _(D28) _(D29) _(D30) _(D31)\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_LR,\n  RID_ZERO = RID_SP,\n\n  /* Calling conventions. */\n  RID_RET = RID_X0,\n  RID_RETLO = RID_X0,\n  RID_RETHI = RID_X1,\n  RID_FPRET = RID_D0,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_X19,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_X21,\t\t/* Interpreter PC. */\n  RID_GL = RID_X22,\t\t/* Interpreter GL. */\n  RID_LREG = RID_X23,\t\t/* Interpreter L. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_X0,\n  RID_MAX_GPR = RID_SP+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n  RID_MAX_FPR = RID_D31+1,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_X0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except for x18, fp, lr and sp. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_X18)|RID2RSET(RID_FP)|RID2RSET(RID_LR)|RID2RSET(RID_SP)|\\\n   RID2RSET(RID_GL))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#define RSET_FPR\tRSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n/* lr is an implicit scratch register. */\n#define RSET_SCRATCH_GPR\t(RSET_RANGE(RID_X0, RID_X17+1))\n#define RSET_SCRATCH_FPR \\\n  (RSET_RANGE(RID_D0, RID_D7+1)|RSET_RANGE(RID_D16, RID_D31+1))\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_X0\n#define REGARG_LASTGPR\t\tRID_X7\n#define REGARG_NUMGPR\t\t8\n#define REGARG_FIRSTFPR\t\tRID_D0\n#define REGARG_LASTFPR\t\tRID_D7\n#define REGARG_NUMFPR\t\t8\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the vm_arm64.dasc file.\n** Pre-allocate some slots to avoid sp adjust in every root trace.\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#define SPS_FIXED\t4\n#define SPS_FIRST\t2\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 3) & ~3)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n/* Return the address of a per-trace exit stub. */\nstatic LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)\n{\n  while (*p == (LJ_LE ? 0xd503201f : 0x1f2003d5)) p++;  /* Skip A64I_NOP. */\n  return p + 3 + exitno;\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_trace_addr(T, exitno) \\\n  exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* ARM64 instructions are always little-endian. Swap for ARM64BE. */\n#if LJ_BE\n#define A64I_LE(x)\t(lj_bswap(x))\n#else\n#define A64I_LE(x)\t(x)\n#endif\n\n/* Instruction fields. */\n#define A64F_D(r)\t(r)\n#define A64F_N(r)\t((r) << 5)\n#define A64F_A(r)\t((r) << 10)\n#define A64F_M(r)\t((r) << 16)\n#define A64F_IMMS(x)\t((x) << 10)\n#define A64F_IMMR(x)\t((x) << 16)\n#define A64F_U16(x)\t((x) << 5)\n#define A64F_U12(x)\t((x) << 10)\n#define A64F_S26(x)\t(((uint32_t)(x) & 0x03ffffffu))\n#define A64F_S19(x)\t(((uint32_t)(x) & 0x7ffffu) << 5)\n#define A64F_S14(x)\t(((uint32_t)(x) & 0x3fffu) << 5)\n#define A64F_S9(x)\t((x) << 12)\n#define A64F_BIT(x)\t((x) << 19)\n#define A64F_SH(sh, x)\t(((sh) << 22) | ((x) << 10))\n#define A64F_EX(ex)\t(A64I_EX | ((ex) << 13))\n#define A64F_EXSH(ex,x)\t(A64I_EX | ((ex) << 13) | ((x) << 10))\n#define A64F_FP8(x)\t((x) << 13)\n#define A64F_CC(cc)\t((cc) << 12)\n#define A64F_LSL16(x)\t(((x) / 16) << 21)\n#define A64F_BSH(sh)\t((sh) << 10)\n\n/* Check for valid field range. */\n#define A64F_S_OK(x, b)\t((((x) + (1 << (b-1))) >> (b)) == 0)\n\ntypedef enum A64Ins {\n  A64I_S = 0x20000000,\n  A64I_X = 0x80000000,\n  A64I_EX = 0x00200000,\n  A64I_ON = 0x00200000,\n  A64I_K12 = 0x1a000000,\n  A64I_K13 = 0x18000000,\n  A64I_LS_U = 0x01000000,\n  A64I_LS_S = 0x00800000,\n  A64I_LS_R = 0x01200800,\n  A64I_LS_SH = 0x00001000,\n  A64I_LS_UXTWx = 0x00004000,\n  A64I_LS_SXTWx = 0x0000c000,\n  A64I_LS_SXTXx = 0x0000e000,\n  A64I_LS_LSLx = 0x00006000,\n\n  A64I_ADDw = 0x0b000000,\n  A64I_ADDx = 0x8b000000,\n  A64I_ADDSw = 0x2b000000,\n  A64I_ADDSx = 0xab000000,\n  A64I_NEGw = 0x4b0003e0,\n  A64I_NEGx = 0xcb0003e0,\n  A64I_SUBw = 0x4b000000,\n  A64I_SUBx = 0xcb000000,\n  A64I_SUBSw = 0x6b000000,\n  A64I_SUBSx = 0xeb000000,\n\n  A64I_MULw = 0x1b007c00,\n  A64I_MULx = 0x9b007c00,\n  A64I_SMULL = 0x9b207c00,\n\n  A64I_ANDw = 0x0a000000,\n  A64I_ANDx = 0x8a000000,\n  A64I_ANDSw = 0x6a000000,\n  A64I_ANDSx = 0xea000000,\n  A64I_EORw = 0x4a000000,\n  A64I_EORx = 0xca000000,\n  A64I_ORRw = 0x2a000000,\n  A64I_ORRx = 0xaa000000,\n  A64I_TSTw  = 0x6a00001f,\n  A64I_TSTx  = 0xea00001f,\n\n  A64I_CMPw = 0x6b00001f,\n  A64I_CMPx = 0xeb00001f,\n  A64I_CMNw = 0x2b00001f,\n  A64I_CMNx = 0xab00001f,\n  A64I_CCMPw = 0x7a400000,\n  A64I_CCMPx = 0xfa400000,\n  A64I_CSELw = 0x1a800000,\n  A64I_CSELx = 0x9a800000,\n\n  A64I_ASRw = 0x13007c00,\n  A64I_ASRx = 0x9340fc00,\n  A64I_LSLx = 0xd3400000,\n  A64I_LSRx = 0xd340fc00,\n  A64I_SHRw = 0x1ac02000,\n  A64I_SHRx = 0x9ac02000,\t/* lsl/lsr/asr/ror x0, x0, x0 */\n  A64I_REVw = 0x5ac00800,\n  A64I_REVx = 0xdac00c00,\n\n  A64I_EXTRw = 0x13800000,\n  A64I_EXTRx = 0x93c00000,\n  A64I_BFMw = 0x33000000,\n  A64I_BFMx = 0xb3400000,\n  A64I_SBFMw = 0x13000000,\n  A64I_SBFMx = 0x93400000,\n  A64I_SXTBw = 0x13001c00,\n  A64I_SXTHw = 0x13003c00,\n  A64I_SXTW = 0x93407c00,\n  A64I_UBFMw = 0x53000000,\n  A64I_UBFMx = 0xd3400000,\n  A64I_UXTBw = 0x53001c00,\n  A64I_UXTHw = 0x53003c00,\n\n  A64I_MOVw = 0x2a0003e0,\n  A64I_MOVx = 0xaa0003e0,\n  A64I_MVNw = 0x2a2003e0,\n  A64I_MVNx = 0xaa2003e0,\n  A64I_MOVKw = 0x72800000,\n  A64I_MOVKx = 0xf2800000,\n  A64I_MOVZw = 0x52800000,\n  A64I_MOVZx = 0xd2800000,\n  A64I_MOVNw = 0x12800000,\n  A64I_MOVNx = 0x92800000,\n\n  A64I_LDRB = 0x39400000,\n  A64I_LDRH = 0x79400000,\n  A64I_LDRw = 0xb9400000,\n  A64I_LDRx = 0xf9400000,\n  A64I_LDRLw = 0x18000000,\n  A64I_LDRLx = 0x58000000,\n  A64I_STRB = 0x39000000,\n  A64I_STRH = 0x79000000,\n  A64I_STRw = 0xb9000000,\n  A64I_STRx = 0xf9000000,\n  A64I_STPw = 0x29000000,\n  A64I_STPx = 0xa9000000,\n  A64I_LDPw = 0x29400000,\n  A64I_LDPx = 0xa9400000,\n\n  A64I_B = 0x14000000,\n  A64I_BCC = 0x54000000,\n  A64I_BL = 0x94000000,\n  A64I_BR = 0xd61f0000,\n  A64I_BLR = 0xd63f0000,\n  A64I_TBZ = 0x36000000,\n  A64I_TBNZ = 0x37000000,\n  A64I_CBZ = 0x34000000,\n  A64I_CBNZ = 0x35000000,\n\n  A64I_NOP = 0xd503201f,\n\n  /* FP */\n  A64I_FADDd = 0x1e602800,\n  A64I_FSUBd = 0x1e603800,\n  A64I_FMADDd = 0x1f400000,\n  A64I_FMSUBd = 0x1f408000,\n  A64I_FNMADDd = 0x1f600000,\n  A64I_FNMSUBd = 0x1f608000,\n  A64I_FMULd = 0x1e600800,\n  A64I_FDIVd = 0x1e601800,\n  A64I_FNEGd = 0x1e614000,\n  A64I_FABS = 0x1e60c000,\n  A64I_FSQRTd = 0x1e61c000,\n  A64I_LDRs = 0xbd400000,\n  A64I_LDRd = 0xfd400000,\n  A64I_STRs = 0xbd000000,\n  A64I_STRd = 0xfd000000,\n  A64I_LDPs = 0x2d400000,\n  A64I_LDPd = 0x6d400000,\n  A64I_STPs = 0x2d000000,\n  A64I_STPd = 0x6d000000,\n  A64I_FCMPd = 0x1e602000,\n  A64I_FCMPZd = 0x1e602008,\n  A64I_FCSELd = 0x1e600c00,\n  A64I_FRINTMd = 0x1e654000,\n  A64I_FRINTPd = 0x1e64c000,\n  A64I_FRINTZd = 0x1e65c000,\n\n  A64I_FCVT_F32_F64 = 0x1e624000,\n  A64I_FCVT_F64_F32 = 0x1e22c000,\n  A64I_FCVT_F32_S32 = 0x1e220000,\n  A64I_FCVT_F64_S32 = 0x1e620000,\n  A64I_FCVT_F32_U32 = 0x1e230000,\n  A64I_FCVT_F64_U32 = 0x1e630000,\n  A64I_FCVT_F32_S64 = 0x9e220000,\n  A64I_FCVT_F64_S64 = 0x9e620000,\n  A64I_FCVT_F32_U64 = 0x9e230000,\n  A64I_FCVT_F64_U64 = 0x9e630000,\n  A64I_FCVT_S32_F64 = 0x1e780000,\n  A64I_FCVT_S32_F32 = 0x1e380000,\n  A64I_FCVT_U32_F64 = 0x1e790000,\n  A64I_FCVT_U32_F32 = 0x1e390000,\n  A64I_FCVT_S64_F64 = 0x9e780000,\n  A64I_FCVT_S64_F32 = 0x9e380000,\n  A64I_FCVT_U64_F64 = 0x9e790000,\n  A64I_FCVT_U64_F32 = 0x9e390000,\n\n  A64I_FMOV_S = 0x1e204000,\n  A64I_FMOV_D = 0x1e604000,\n  A64I_FMOV_R_S = 0x1e260000,\n  A64I_FMOV_S_R = 0x1e270000,\n  A64I_FMOV_R_D = 0x9e660000,\n  A64I_FMOV_D_R = 0x9e670000,\n  A64I_FMOV_DI = 0x1e601000,\n} A64Ins;\n\ntypedef enum A64Shift {\n  A64SH_LSL, A64SH_LSR, A64SH_ASR, A64SH_ROR\n} A64Shift;\n\ntypedef enum A64Extend {\n  A64EX_UXTB, A64EX_UXTH, A64EX_UXTW, A64EX_UXTX,\n  A64EX_SXTB, A64EX_SXTH, A64EX_SXTW, A64EX_SXTX,\n} A64Extend;\n\n/* ARM condition codes. */\ntypedef enum A64CC {\n  CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,\n  CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,\n  CC_HS = CC_CS, CC_LO = CC_CC\n} A64CC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_mips.h",
    "content": "/*\n** Definitions for MIPS CPUs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_MIPS_H\n#define _LJ_TARGET_MIPS_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \\\n  _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \\\n  _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA)\n#if LJ_SOFTFP\n#define FPRDEF(_)\n#else\n#define FPRDEF(_) \\\n  _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \\\n  _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \\\n  _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \\\n  _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)\n#endif\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_ZERO = RID_R0,\n  RID_TMP = RID_RA,\n  RID_GP = RID_R28,\n\n  /* Calling conventions. */\n  RID_RET = RID_R2,\n#if LJ_LE\n  RID_RETHI = RID_R3,\n  RID_RETLO = RID_R2,\n#else\n  RID_RETHI = RID_R2,\n  RID_RETLO = RID_R3,\n#endif\n#if LJ_SOFTFP\n  RID_FPRET = RID_R2,\n#else\n  RID_FPRET = RID_F0,\n#endif\n  RID_CFUNCADDR = RID_R25,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R16,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R18,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R19,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R20,\t\t/* Interpreter L. */\n  RID_JGL = RID_R30,\t\t/* On-trace: global_State + 32768. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_RA+1,\n  RID_MIN_FPR = RID_MAX_GPR,\n#if LJ_SOFTFP\n  RID_MAX_FPR = RID_MIN_FPR,\n#else\n  RID_MAX_FPR = RID_F31+1,\n#endif\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\t/* Only even regs are used. */\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2, JGL and GP. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\\\n   RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)|RID2RSET(RID_GP))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#if LJ_SOFTFP\n#define RSET_FPR\t\t0\n#else\n#if LJ_32\n#define RSET_FPR \\\n  (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\\\n   RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\\\n   RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\\\n   RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30))\n#else\n#define RSET_FPR\t\tRSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)\n#endif\n#endif\n#define RSET_ALL\t\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\t\tRSET_ALL\n\n#define RSET_SCRATCH_GPR \\\n  (RSET_RANGE(RID_R1, RID_R15+1)|\\\n   RID2RSET(RID_R24)|RID2RSET(RID_R25))\n#if LJ_SOFTFP\n#define RSET_SCRATCH_FPR\t0\n#else\n#if LJ_32\n#define RSET_SCRATCH_FPR \\\n  (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\\\n   RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\\\n   RID2RSET(RID_F16)|RID2RSET(RID_F18))\n#else\n#define RSET_SCRATCH_FPR\tRSET_RANGE(RID_F0, RID_F24)\n#endif\n#endif\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R4\n#if LJ_32\n#define REGARG_LASTGPR\t\tRID_R7\n#define REGARG_NUMGPR\t\t4\n#else\n#define REGARG_LASTGPR\t\tRID_R11\n#define REGARG_NUMGPR\t\t8\n#endif\n#if LJ_ABI_SOFTFP\n#define REGARG_FIRSTFPR\t\t0\n#define REGARG_LASTFPR\t\t0\n#define REGARG_NUMFPR\t\t0\n#else\n#define REGARG_FIRSTFPR\t\tRID_F12\n#if LJ_32\n#define REGARG_LASTFPR\t\tRID_F14\n#define REGARG_NUMFPR\t\t2\n#else\n#define REGARG_LASTFPR\t\tRID_F19\n#define REGARG_NUMFPR\t\t8\n#endif\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use.\n*/\n#if LJ_32\n#define SPS_FIXED\t5\n#else\n#define SPS_FIXED\t4\n#endif\n#define SPS_FIRST\t4\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 1) & ~1)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n#if !LJ_SOFTFP\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n#endif\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n/* Return the address of a per-trace exit stub. */\nstatic LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p)\n{\n  while (*p == 0x00000000) p++;  /* Skip MIPSI_NOP. */\n  return p;\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_trace_addr(T, exitno) \\\n  exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode))\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define MIPSF_S(r)\t((r) << 21)\n#define MIPSF_T(r)\t((r) << 16)\n#define MIPSF_D(r)\t((r) << 11)\n#define MIPSF_R(r)\t((r) << 21)\n#define MIPSF_H(r)\t((r) << 16)\n#define MIPSF_G(r)\t((r) << 11)\n#define MIPSF_F(r)\t((r) << 6)\n#define MIPSF_A(n)\t((n) << 6)\n#define MIPSF_M(n)\t((n) << 11)\n#define MIPSF_L(n)\t((n) << 6)\n\ntypedef enum MIPSIns {\n  MIPSI_D = 0x38,\n  MIPSI_DV = 0x10,\n  MIPSI_D32 = 0x3c,\n  /* Integer instructions. */\n  MIPSI_MOVE = 0x00000025,\n  MIPSI_NOP = 0x00000000,\n\n  MIPSI_LI = 0x24000000,\n  MIPSI_LU = 0x34000000,\n  MIPSI_LUI = 0x3c000000,\n\n  MIPSI_AND = 0x00000024,\n  MIPSI_ANDI = 0x30000000,\n  MIPSI_OR = 0x00000025,\n  MIPSI_ORI = 0x34000000,\n  MIPSI_XOR = 0x00000026,\n  MIPSI_XORI = 0x38000000,\n  MIPSI_NOR = 0x00000027,\n\n  MIPSI_SLT = 0x0000002a,\n  MIPSI_SLTU = 0x0000002b,\n  MIPSI_SLTI = 0x28000000,\n  MIPSI_SLTIU = 0x2c000000,\n\n  MIPSI_ADDU = 0x00000021,\n  MIPSI_ADDIU = 0x24000000,\n  MIPSI_SUB = 0x00000022,\n  MIPSI_SUBU = 0x00000023,\n\n#if !LJ_TARGET_MIPSR6\n  MIPSI_MUL = 0x70000002,\n  MIPSI_DIV = 0x0000001a,\n  MIPSI_DIVU = 0x0000001b,\n\n  MIPSI_MOVZ = 0x0000000a,\n  MIPSI_MOVN = 0x0000000b,\n  MIPSI_MFHI = 0x00000010,\n  MIPSI_MFLO = 0x00000012,\n  MIPSI_MULT = 0x00000018,\n#else\n  MIPSI_MUL = 0x00000098,\n  MIPSI_MUH = 0x000000d8,\n  MIPSI_DIV = 0x0000009a,\n  MIPSI_DIVU = 0x0000009b,\n\n  MIPSI_SELEQZ = 0x00000035,\n  MIPSI_SELNEZ = 0x00000037,\n#endif\n\n  MIPSI_SLL = 0x00000000,\n  MIPSI_SRL = 0x00000002,\n  MIPSI_SRA = 0x00000003,\n  MIPSI_ROTR = 0x00200002,\t/* MIPSXXR2 */\n  MIPSI_DROTR = 0x0020003a,\n  MIPSI_DROTR32 = 0x0020003e,\n  MIPSI_SLLV = 0x00000004,\n  MIPSI_SRLV = 0x00000006,\n  MIPSI_SRAV = 0x00000007,\n  MIPSI_ROTRV = 0x00000046,\t/* MIPSXXR2 */\n  MIPSI_DROTRV = 0x00000056,\n\n  MIPSI_INS = 0x7c000004,\t/* MIPSXXR2 */\n\n  MIPSI_SEB = 0x7c000420,\t/* MIPSXXR2 */\n  MIPSI_SEH = 0x7c000620,\t/* MIPSXXR2 */\n  MIPSI_WSBH = 0x7c0000a0,\t/* MIPSXXR2 */\n  MIPSI_DSBH = 0x7c0000a4,\n\n  MIPSI_B = 0x10000000,\n  MIPSI_J = 0x08000000,\n  MIPSI_JAL = 0x0c000000,\n#if !LJ_TARGET_MIPSR6\n  MIPSI_JALX = 0x74000000,\n  MIPSI_JR = 0x00000008,\n#else\n  MIPSI_JR = 0x00000009,\n  MIPSI_BALC = 0xe8000000,\n#endif\n  MIPSI_JALR = 0x0000f809,\n\n  MIPSI_BEQ = 0x10000000,\n  MIPSI_BNE = 0x14000000,\n  MIPSI_BLEZ = 0x18000000,\n  MIPSI_BGTZ = 0x1c000000,\n  MIPSI_BLTZ = 0x04000000,\n  MIPSI_BGEZ = 0x04010000,\n\n  /* Load/store instructions. */\n  MIPSI_LW = 0x8c000000,\n  MIPSI_LD = 0xdc000000,\n  MIPSI_SW = 0xac000000,\n  MIPSI_SD = 0xfc000000,\n  MIPSI_LB = 0x80000000,\n  MIPSI_SB = 0xa0000000,\n  MIPSI_LH = 0x84000000,\n  MIPSI_SH = 0xa4000000,\n  MIPSI_LBU = 0x90000000,\n  MIPSI_LHU = 0x94000000,\n  MIPSI_LWC1 = 0xc4000000,\n  MIPSI_SWC1 = 0xe4000000,\n  MIPSI_LDC1 = 0xd4000000,\n  MIPSI_SDC1 = 0xf4000000,\n\n  /* MIPS64 instructions. */\n  MIPSI_DADD = 0x0000002c,\n  MIPSI_DADDU = 0x0000002d,\n  MIPSI_DADDIU = 0x64000000,\n  MIPSI_DSUB = 0x0000002e,\n  MIPSI_DSUBU = 0x0000002f,\n#if !LJ_TARGET_MIPSR6\n  MIPSI_DDIV = 0x0000001e,\n  MIPSI_DDIVU = 0x0000001f,\n  MIPSI_DMULT = 0x0000001c,\n  MIPSI_DMULTU = 0x0000001d,\n#else\n  MIPSI_DDIV = 0x0000009e,\n  MIPSI_DMOD = 0x000000de,\n  MIPSI_DDIVU = 0x0000009f,\n  MIPSI_DMODU = 0x000000df,\n  MIPSI_DMUL = 0x0000009c,\n  MIPSI_DMUH = 0x000000dc,\n#endif\n\n  MIPSI_DSLL = 0x00000038,\n  MIPSI_DSRL = 0x0000003a,\n  MIPSI_DSLLV = 0x00000014,\n  MIPSI_DSRLV = 0x00000016,\n  MIPSI_DSRA = 0x0000003b,\n  MIPSI_DSRAV = 0x00000017,\n  MIPSI_DSRA32 = 0x0000003f,\n  MIPSI_DSLL32 = 0x0000003c,\n  MIPSI_DSRL32 = 0x0000003e,\n  MIPSI_DSHD = 0x7c000164,\n\n  MIPSI_AADDU = LJ_32 ? MIPSI_ADDU : MIPSI_DADDU,\n  MIPSI_AADDIU = LJ_32 ? MIPSI_ADDIU : MIPSI_DADDIU,\n  MIPSI_ASUBU = LJ_32 ? MIPSI_SUBU : MIPSI_DSUBU,\n  MIPSI_AL = LJ_32 ? MIPSI_LW : MIPSI_LD,\n  MIPSI_AS = LJ_32 ? MIPSI_SW : MIPSI_SD,\n#if LJ_TARGET_MIPSR6\n  MIPSI_LSA = 0x00000005,\n  MIPSI_DLSA = 0x00000015,\n  MIPSI_ALSA = LJ_32 ? MIPSI_LSA : MIPSI_DLSA,\n#endif\n\n  /* Extract/insert instructions. */\n  MIPSI_DEXTM = 0x7c000001,\n  MIPSI_DEXTU = 0x7c000002,\n  MIPSI_DEXT = 0x7c000003,\n  MIPSI_DINSM = 0x7c000005,\n  MIPSI_DINSU = 0x7c000006,\n  MIPSI_DINS = 0x7c000007,\n\n  MIPSI_FLOOR_D = 0x4620000b,\n\n  /* FP instructions. */\n  MIPSI_MOV_S = 0x46000006,\n  MIPSI_MOV_D = 0x46200006,\n#if !LJ_TARGET_MIPSR6\n  MIPSI_MOVT_D = 0x46210011,\n  MIPSI_MOVF_D = 0x46200011,\n#else\n  MIPSI_MIN_D = 0x4620001C,\n  MIPSI_MAX_D = 0x4620001E,\n  MIPSI_SEL_D = 0x46200010,\n#endif\n\n  MIPSI_ABS_D = 0x46200005,\n  MIPSI_NEG_D = 0x46200007,\n\n  MIPSI_ADD_D = 0x46200000,\n  MIPSI_SUB_D = 0x46200001,\n  MIPSI_MUL_D = 0x46200002,\n  MIPSI_DIV_D = 0x46200003,\n  MIPSI_SQRT_D = 0x46200004,\n\n  MIPSI_ADD_S = 0x46000000,\n  MIPSI_SUB_S = 0x46000001,\n\n  MIPSI_CVT_D_S = 0x46000021,\n  MIPSI_CVT_W_S = 0x46000024,\n  MIPSI_CVT_S_D = 0x46200020,\n  MIPSI_CVT_W_D = 0x46200024,\n  MIPSI_CVT_S_W = 0x46800020,\n  MIPSI_CVT_D_W = 0x46800021,\n  MIPSI_CVT_S_L = 0x46a00020,\n  MIPSI_CVT_D_L = 0x46a00021,\n\n  MIPSI_TRUNC_W_S = 0x4600000d,\n  MIPSI_TRUNC_W_D = 0x4620000d,\n  MIPSI_TRUNC_L_S = 0x46000009,\n  MIPSI_TRUNC_L_D = 0x46200009,\n  MIPSI_FLOOR_W_S = 0x4600000f,\n  MIPSI_FLOOR_W_D = 0x4620000f,\n\n  MIPSI_MFC1 = 0x44000000,\n  MIPSI_MTC1 = 0x44800000,\n  MIPSI_DMTC1 = 0x44a00000,\n  MIPSI_DMFC1 = 0x44200000,\n\n#if !LJ_TARGET_MIPSR6\n  MIPSI_BC1F = 0x45000000,\n  MIPSI_BC1T = 0x45010000,\n  MIPSI_C_EQ_D = 0x46200032,\n  MIPSI_C_OLT_S = 0x46000034,\n  MIPSI_C_OLT_D = 0x46200034,\n  MIPSI_C_ULT_D = 0x46200035,\n  MIPSI_C_OLE_D = 0x46200036,\n  MIPSI_C_ULE_D = 0x46200037,\n#else\n  MIPSI_BC1EQZ = 0x45200000,\n  MIPSI_BC1NEZ = 0x45a00000,\n  MIPSI_CMP_EQ_D = 0x46a00002,\n  MIPSI_CMP_LT_S = 0x46800004,\n  MIPSI_CMP_LT_D = 0x46a00004,\n#endif\n\n} MIPSIns;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_ppc.h",
    "content": "/*\n** Definitions for PPC CPUs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_PPC_H\n#define _LJ_TARGET_PPC_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \\\n  _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \\\n  _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31)\n#define FPRDEF(_) \\\n  _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \\\n  _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \\\n  _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \\\n  _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)\n#define VRIDDEF(_)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_TMP = RID_R0,\n\n  /* Calling conventions. */\n  RID_RET = RID_R3,\n  RID_RETHI = RID_R3,\n  RID_RETLO = RID_R4,\n  RID_FPRET = RID_F1,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R14,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R16,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R17,\t/* Interpreter DISPATCH table. */\n  RID_LREG = RID_R18,\t\t/* Interpreter L. */\n  RID_JGL = RID_R31,\t\t/* On-trace: global_State + 32768. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MAX_GPR = RID_R31+1,\n  RID_MIN_FPR = RID_F0,\n  RID_MAX_FPR = RID_F31+1,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR\n};\n\n#define RID_NUM_KREF\t\tRID_NUM_GPR\n#define RID_MIN_KREF\t\tRID_R0\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */\n#define RSET_FIXED \\\n  (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\\\n   RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)\n#define RSET_FPR\tRSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n#define RSET_SCRATCH_GPR\t(RSET_RANGE(RID_R3, RID_R12+1))\n#define RSET_SCRATCH_FPR\t(RSET_RANGE(RID_F0, RID_F13+1))\n#define RSET_SCRATCH\t\t(RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)\n#define REGARG_FIRSTGPR\t\tRID_R3\n#define REGARG_LASTGPR\t\tRID_R10\n#define REGARG_NUMGPR\t\t8\n#define REGARG_FIRSTFPR\t\tRID_F1\n#define REGARG_LASTFPR\t\tRID_F8\n#define REGARG_NUMFPR\t\t8\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use.\n** [sp+12] tmplo word \\\n** [sp+ 8] tmphi word / tmp dword, parameter area for callee\n** [sp+ 4] tmpw, LR of callee\n** [sp+ 0] stack chain\n*/\n#define SPS_FIXED\t7\n#define SPS_FIRST\t4\n\n/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */\n#define SPOFS_TMPW\t4\n#define SPOFS_TMP\t8\n#define SPOFS_TMPHI\t8\n#define SPOFS_TMPLO\t12\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 3) & ~3)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Highest exit + 1 indicates stack check. */\n#define EXITSTATE_CHECKEXIT\t1\n\n/* Return the address of a per-trace exit stub. */\nstatic LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)\n{\n  while (*p == 0x60000000) p++;  /* Skip PPCI_NOP. */\n  return p + 3 + exitno;\n}\n/* Avoid dependence on lj_jit.h if only including lj_target.h. */\n#define exitstub_trace_addr(T, exitno) \\\n  exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))\n\n/* -- Instructions -------------------------------------------------------- */\n\n/* Instruction fields. */\n#define PPCF_CC(cc)\t((((cc) & 3) << 16) | (((cc) & 4) << 22))\n#define PPCF_T(r)\t((r) << 21)\n#define PPCF_A(r)\t((r) << 16)\n#define PPCF_B(r)\t((r) << 11)\n#define PPCF_C(r)\t((r) << 6)\n#define PPCF_MB(n)\t((n) << 6)\n#define PPCF_ME(n)\t((n) << 1)\n#define PPCF_Y\t\t0x00200000\n#define PPCF_DOT\t0x00000001\n\ntypedef enum PPCIns {\n  /* Integer instructions. */\n  PPCI_MR = 0x7c000378,\n  PPCI_NOP = 0x60000000,\n\n  PPCI_LI = 0x38000000,\n  PPCI_LIS = 0x3c000000,\n\n  PPCI_ADD = 0x7c000214,\n  PPCI_ADDC = 0x7c000014,\n  PPCI_ADDO = 0x7c000614,\n  PPCI_ADDE = 0x7c000114,\n  PPCI_ADDZE = 0x7c000194,\n  PPCI_ADDME = 0x7c0001d4,\n  PPCI_ADDI = 0x38000000,\n  PPCI_ADDIS = 0x3c000000,\n  PPCI_ADDIC = 0x30000000,\n  PPCI_ADDICDOT = 0x34000000,\n\n  PPCI_SUBF = 0x7c000050,\n  PPCI_SUBFC = 0x7c000010,\n  PPCI_SUBFO = 0x7c000450,\n  PPCI_SUBFE = 0x7c000110,\n  PPCI_SUBFZE = 0x7c000190,\n  PPCI_SUBFME = 0x7c0001d0,\n  PPCI_SUBFIC = 0x20000000,\n\n  PPCI_NEG = 0x7c0000d0,\n\n  PPCI_AND = 0x7c000038,\n  PPCI_ANDC = 0x7c000078,\n  PPCI_NAND = 0x7c0003b8,\n  PPCI_ANDIDOT = 0x70000000,\n  PPCI_ANDISDOT = 0x74000000,\n\n  PPCI_OR = 0x7c000378,\n  PPCI_NOR = 0x7c0000f8,\n  PPCI_ORI = 0x60000000,\n  PPCI_ORIS = 0x64000000,\n\n  PPCI_XOR = 0x7c000278,\n  PPCI_EQV = 0x7c000238,\n  PPCI_XORI = 0x68000000,\n  PPCI_XORIS = 0x6c000000,\n\n  PPCI_CMPW = 0x7c000000,\n  PPCI_CMPLW = 0x7c000040,\n  PPCI_CMPWI = 0x2c000000,\n  PPCI_CMPLWI = 0x28000000,\n\n  PPCI_MULLW = 0x7c0001d6,\n  PPCI_MULLI = 0x1c000000,\n  PPCI_MULLWO = 0x7c0005d6,\n\n  PPCI_EXTSB = 0x7c000774,\n  PPCI_EXTSH = 0x7c000734,\n\n  PPCI_SLW = 0x7c000030,\n  PPCI_SRW = 0x7c000430,\n  PPCI_SRAW = 0x7c000630,\n  PPCI_SRAWI = 0x7c000670,\n\n  PPCI_RLWNM = 0x5c000000,\n  PPCI_RLWINM = 0x54000000,\n  PPCI_RLWIMI = 0x50000000,\n\n  PPCI_B = 0x48000000,\n  PPCI_BL = 0x48000001,\n  PPCI_BC = 0x40800000,\n  PPCI_BCL = 0x40800001,\n  PPCI_BCTR = 0x4e800420,\n  PPCI_BCTRL = 0x4e800421,\n\n  PPCI_CRANDC = 0x4c000102,\n  PPCI_CRXOR = 0x4c000182,\n  PPCI_CRAND = 0x4c000202,\n  PPCI_CREQV = 0x4c000242,\n  PPCI_CRORC = 0x4c000342,\n  PPCI_CROR = 0x4c000382,\n\n  PPCI_MFLR = 0x7c0802a6,\n  PPCI_MTCTR = 0x7c0903a6,\n\n  PPCI_MCRXR = 0x7c000400,\n\n  /* Load/store instructions. */\n  PPCI_LWZ = 0x80000000,\n  PPCI_LBZ = 0x88000000,\n  PPCI_STW = 0x90000000,\n  PPCI_STB = 0x98000000,\n  PPCI_LHZ = 0xa0000000,\n  PPCI_LHA = 0xa8000000,\n  PPCI_STH = 0xb0000000,\n\n  PPCI_STWU = 0x94000000,\n\n  PPCI_LFS = 0xc0000000,\n  PPCI_LFD = 0xc8000000,\n  PPCI_STFS = 0xd0000000,\n  PPCI_STFD = 0xd8000000,\n\n  PPCI_LWZX = 0x7c00002e,\n  PPCI_LBZX = 0x7c0000ae,\n  PPCI_STWX = 0x7c00012e,\n  PPCI_STBX = 0x7c0001ae,\n  PPCI_LHZX = 0x7c00022e,\n  PPCI_LHAX = 0x7c0002ae,\n  PPCI_STHX = 0x7c00032e,\n\n  PPCI_LWBRX = 0x7c00042c,\n  PPCI_STWBRX = 0x7c00052c,\n\n  PPCI_LFSX = 0x7c00042e,\n  PPCI_LFDX = 0x7c0004ae,\n  PPCI_STFSX = 0x7c00052e,\n  PPCI_STFDX = 0x7c0005ae,\n\n  /* FP instructions. */\n  PPCI_FMR = 0xfc000090,\n  PPCI_FNEG = 0xfc000050,\n  PPCI_FABS = 0xfc000210,\n\n  PPCI_FRSP = 0xfc000018,\n  PPCI_FCTIWZ = 0xfc00001e,\n\n  PPCI_FADD = 0xfc00002a,\n  PPCI_FSUB = 0xfc000028,\n  PPCI_FMUL = 0xfc000032,\n  PPCI_FDIV = 0xfc000024,\n  PPCI_FSQRT = 0xfc00002c,\n\n  PPCI_FMADD = 0xfc00003a,\n  PPCI_FMSUB = 0xfc000038,\n  PPCI_FNMSUB = 0xfc00003c,\n\n  PPCI_FCMPU = 0xfc000000,\n  PPCI_FSEL = 0xfc00002e,\n} PPCIns;\n\ntypedef enum PPCCC {\n  CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO\n} PPCCC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_s390x.h",
    "content": "/*\n** Definitions for IBM z/Architecture (s390x) CPUs.\n** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_S390X_H\n#define _LJ_TARGET_S390X_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#define GPRDEF(_) \\\n  _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \\\n  _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15)\n#define FPRDEF(_) \\\n  _(F0) _(F1) _(F2) _(F3) \\\n  _(F4) _(F5) _(F6) _(F7) \\\n  _(F8) _(F9) _(F10) _(F11) \\\n  _(F12) _(F13) _(F14) _(F15) \n// TODO: VREG?\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n\n  /* Calling conventions. */\n  RID_SP = RID_R15,\n  RID_RET = RID_R2,\n  RID_FPRET = RID_F0,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_R7,\t\t/* Interpreter BASE. */\n  RID_LPC = RID_R9,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R10,\t/* Interpreter DISPATCH table. */\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_R0,\n  RID_MIN_FPR = RID_F0,\n  RID_MAX_GPR = RID_MIN_FPR,\n  RID_MAX_FPR = RID_MAX,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR,\n};\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#define SPS_FIXED\t2\n#define SPS_FIRST\t2\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 1) & ~1)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  int32_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n#define EXITSTUB_SPACING        4\n#define EXITSTUBS_PER_GROUP     32\n\n/* -- Instructions -------------------------------------------------------- */\n\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_target_x86.h",
    "content": "/*\n** Definitions for x86 and x64 CPUs.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TARGET_X86_H\n#define _LJ_TARGET_X86_H\n\n/* -- Registers IDs ------------------------------------------------------- */\n\n#if LJ_64\n#define GPRDEF(_) \\\n  _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \\\n  _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D)\n#define FPRDEF(_) \\\n  _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \\\n  _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15)\n#else\n#define GPRDEF(_) \\\n  _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI)\n#define FPRDEF(_) \\\n  _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7)\n#endif\n#define VRIDDEF(_) \\\n  _(MRM) _(RIP)\n\n#define RIDENUM(name)\tRID_##name,\n\nenum {\n  GPRDEF(RIDENUM)\t\t/* General-purpose registers (GPRs). */\n  FPRDEF(RIDENUM)\t\t/* Floating-point registers (FPRs). */\n  RID_MAX,\n  RID_MRM = RID_MAX,\t\t/* Pseudo-id for ModRM operand. */\n  RID_RIP = RID_MAX+5,\t\t/* Pseudo-id for RIP (x64 only), rm bits = 5. */\n\n  /* Calling conventions. */\n  RID_SP = RID_ESP,\n  RID_RET = RID_EAX,\n#if LJ_64\n  RID_FPRET = RID_XMM0,\n#endif\n  RID_RETLO = RID_EAX,\n  RID_RETHI = RID_EDX,\n\n  /* These definitions must match with the *.dasc file(s): */\n  RID_BASE = RID_EDX,\t\t/* Interpreter BASE. */\n#if LJ_64 && !LJ_ABI_WIN\n  RID_LPC = RID_EBX,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_R14D,\t/* Interpreter DISPATCH table. */\n#else\n  RID_LPC = RID_ESI,\t\t/* Interpreter PC. */\n  RID_DISPATCH = RID_EBX,\t/* Interpreter DISPATCH table. */\n#endif\n\n  /* Register ranges [min, max) and number of registers. */\n  RID_MIN_GPR = RID_EAX,\n  RID_MIN_FPR = RID_XMM0,\n  RID_MAX_GPR = RID_MIN_FPR,\n  RID_MAX_FPR = RID_MAX,\n  RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,\n  RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR,\n};\n\n/* -- Register sets ------------------------------------------------------- */\n\n/* Make use of all registers, except the stack pointer (and maybe DISPATCH). */\n#define RSET_GPR\t(RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) \\\n\t\t\t - RID2RSET(RID_ESP) \\\n\t\t\t - LJ_GC64*RID2RSET(RID_DISPATCH))\n#define RSET_FPR\t(RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))\n#define RSET_ALL\t(RSET_GPR|RSET_FPR)\n#define RSET_INIT\tRSET_ALL\n\n#if LJ_64\n/* Note: this requires the use of FORCE_REX! */\n#define RSET_GPR8\tRSET_GPR\n#else\n#define RSET_GPR8\t(RSET_RANGE(RID_EAX, RID_EBX+1))\n#endif\n\n/* ABI-specific register sets. */\n#define RSET_ACD\t(RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))\n#if LJ_64\n#if LJ_ABI_WIN\n/* Windows x64 ABI. */\n#define RSET_SCRATCH \\\n  (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))\n#define REGARG_GPRS \\\n  (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5))\n#define REGARG_NUMGPR\t4\n#define REGARG_NUMFPR\t4\n#define REGARG_FIRSTFPR\tRID_XMM0\n#define REGARG_LASTFPR\tRID_XMM3\n#define STACKARG_OFS\t(4*8)\n#else\n/* The rest of the civilized x64 world has a common ABI. */\n#define RSET_SCRATCH \\\n  (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR)\n#define REGARG_GPRS \\\n  (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \\\n   <<5))<<5))<<5))<<5))<<5))\n#define REGARG_NUMGPR\t6\n#define REGARG_NUMFPR\t8\n#define REGARG_FIRSTFPR\tRID_XMM0\n#define REGARG_LASTFPR\tRID_XMM7\n#define STACKARG_OFS\t0\n#endif\n#else\n/* Common x86 ABI. */\n#define RSET_SCRATCH\t(RSET_ACD|RSET_FPR)\n#define REGARG_GPRS\t(RID_ECX|(RID_EDX<<5))  /* Fastcall only. */\n#define REGARG_NUMGPR\t2  /* Fastcall only. */\n#define REGARG_NUMFPR\t0\n#define STACKARG_OFS\t0\n#endif\n\n#if LJ_64\n/* Prefer the low 8 regs of each type to reduce REX prefixes. */\n#undef rset_picktop\n#define rset_picktop(rs)\t(lj_fls(lj_bswap(rs)) ^ 0x18)\n#endif\n\n/* -- Spill slots --------------------------------------------------------- */\n\n/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.\n**\n** SPS_FIXED: Available fixed spill slots in interpreter frame.\n** This definition must match with the *.dasc file(s).\n**\n** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.\n*/\n#if LJ_64\n#if LJ_ABI_WIN\n#define SPS_FIXED\t(4*2)\n#define SPS_FIRST\t(4*2)\t/* Don't use callee register save area. */\n#else\n#if LJ_GC64\n#define SPS_FIXED\t2\n#else\n#define SPS_FIXED\t4\n#endif\n#define SPS_FIRST\t2\n#endif\n#else\n#define SPS_FIXED\t6\n#define SPS_FIRST\t2\n#endif\n\n#define SPOFS_TMP\t0\n\n#define sps_scale(slot)\t\t(4 * (int32_t)(slot))\n#define sps_align(slot)\t\t(((slot) - SPS_FIXED + 3) & ~3)\n\n/* -- Exit state ---------------------------------------------------------- */\n\n/* This definition must match with the *.dasc file(s). */\ntypedef struct {\n  lua_Number fpr[RID_NUM_FPR];\t/* Floating-point registers. */\n  intptr_t gpr[RID_NUM_GPR];\t/* General-purpose registers. */\n  int32_t spill[256];\t\t/* Spill slots. */\n} ExitState;\n\n/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */\n#define EXITSTUB_SPACING\t(2+2)\n#define EXITSTUBS_PER_GROUP\t32\n\n#define EXITTRACE_VMSTATE\t1\t/* g->vmstate has traceno on exit. */\n\n/* -- x86 ModRM operand encoding ------------------------------------------ */\n\ntypedef enum {\n  XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0,\n  XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0,\n  XM_MASK = 0xc0\n} x86Mode;\n\n/* Structure to hold variable ModRM operand. */\ntypedef struct {\n  int32_t ofs;\t\t/* Offset. */\n  uint8_t base;\t\t/* Base register or RID_NONE. */\n  uint8_t idx;\t\t/* Index register or RID_NONE. */\n  uint8_t scale;\t/* Index scale (XM_SCALE1 .. XM_SCALE8). */\n} x86ModRM;\n\n/* -- Opcodes ------------------------------------------------------------- */\n\n/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */\n#define XO_(o)\t\t((uint32_t)(0x0000fe + (0x##o<<24)))\n#define XO_FPU(a,b)\t((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24)))\n#define XO_0f(o)\t((uint32_t)(0x0f00fd + (0x##o<<24)))\n#define XO_66(o)\t((uint32_t)(0x6600fd + (0x##o<<24)))\n#define XO_660f(o)\t((uint32_t)(0x0f66fc + (0x##o<<24)))\n#define XO_f20f(o)\t((uint32_t)(0x0ff2fc + (0x##o<<24)))\n#define XO_f30f(o)\t((uint32_t)(0x0ff3fc + (0x##o<<24)))\n\n#define XV_660f38(o)\t((uint32_t)(0x79e2c4 + (0x##o<<24)))\n#define XV_f20f38(o)\t((uint32_t)(0x7be2c4 + (0x##o<<24)))\n#define XV_f20f3a(o)\t((uint32_t)(0x7be3c4 + (0x##o<<24)))\n#define XV_f30f38(o)\t((uint32_t)(0x7ae2c4 + (0x##o<<24)))\n\n/* This list of x86 opcodes is not intended to be complete. Opcodes are only\n** included when needed. Take a look at DynASM or jit.dis_x86 to see the\n** whole mess.\n*/\ntypedef enum {\n  /* Fixed length opcodes. XI_* prefix. */\n  XI_O16 =\t0x66,\n  XI_NOP =\t0x90,\n  XI_XCHGa =\t0x90,\n  XI_CALL =\t0xe8,\n  XI_JMP =\t0xe9,\n  XI_JMPs =\t0xeb,\n  XI_PUSH =\t0x50, /* Really 50+r. */\n  XI_JCCs =\t0x70, /* Really 7x. */\n  XI_JCCn =\t0x80, /* Really 0f8x. */\n  XI_LEA =\t0x8d,\n  XI_MOVrib =\t0xb0, /* Really b0+r. */\n  XI_MOVri =\t0xb8, /* Really b8+r. */\n  XI_ARITHib =\t0x80,\n  XI_ARITHi =\t0x81,\n  XI_ARITHi8 =\t0x83,\n  XI_PUSHi8 =\t0x6a,\n  XI_TESTb =\t0x84,\n  XI_TEST =\t0x85,\n  XI_INT3 =\t0xcc,\n  XI_MOVmi =\t0xc7,\n  XI_GROUP5 =\t0xff,\n\n  /* Note: little-endian byte-order! */\n  XI_FLDZ =\t0xeed9,\n  XI_FLD1 =\t0xe8d9,\n  XI_FDUP =\t0xc0d9,  /* Really fld st0. */\n  XI_FPOP =\t0xd8dd,  /* Really fstp st0. */\n  XI_FPOP1 =\t0xd9dd,  /* Really fstp st1. */\n  XI_FRNDINT =\t0xfcd9,\n  XI_FSCALE =\t0xfdd9,\n  XI_FYL2X =\t0xf1d9,\n\n  /* VEX-encoded instructions. XV_* prefix. */\n  XV_RORX =\tXV_f20f3a(f0),\n  XV_SARX =\tXV_f30f38(f7),\n  XV_SHLX =\tXV_660f38(f7),\n  XV_SHRX =\tXV_f20f38(f7),\n\n  /* Variable-length opcodes. XO_* prefix. */\n  XO_OR =\tXO_(0b),\n  XO_MOV =\tXO_(8b),\n  XO_MOVto =\tXO_(89),\n  XO_MOVtow =\tXO_66(89),\n  XO_MOVtob =\tXO_(88),\n  XO_MOVmi =\tXO_(c7),\n  XO_MOVmib =\tXO_(c6),\n  XO_LEA =\tXO_(8d),\n  XO_ARITHib =\tXO_(80),\n  XO_ARITHi =\tXO_(81),\n  XO_ARITHi8 =\tXO_(83),\n  XO_ARITHiw8 =\tXO_66(83),\n  XO_SHIFTi =\tXO_(c1),\n  XO_SHIFT1 =\tXO_(d1),\n  XO_SHIFTcl =\tXO_(d3),\n  XO_IMUL =\tXO_0f(af),\n  XO_IMULi =\tXO_(69),\n  XO_IMULi8 =\tXO_(6b),\n  XO_CMP =\tXO_(3b),\n  XO_TESTb =\tXO_(84),\n  XO_TEST =\tXO_(85),\n  XO_GROUP3b =\tXO_(f6),\n  XO_GROUP3 =\tXO_(f7),\n  XO_GROUP5b =\tXO_(fe),\n  XO_GROUP5 =\tXO_(ff),\n  XO_MOVZXb =\tXO_0f(b6),\n  XO_MOVZXw =\tXO_0f(b7),\n  XO_MOVSXb =\tXO_0f(be),\n  XO_MOVSXw =\tXO_0f(bf),\n  XO_MOVSXd =\tXO_(63),\n  XO_BSWAP =\tXO_0f(c8),\n  XO_CMOV =\tXO_0f(40),\n\n  XO_MOVSD =\tXO_f20f(10),\n  XO_MOVSDto =\tXO_f20f(11),\n  XO_MOVSS =\tXO_f30f(10),\n  XO_MOVSSto =\tXO_f30f(11),\n  XO_MOVLPD =\tXO_660f(12),\n  XO_MOVAPS =\tXO_0f(28),\n  XO_XORPS =\tXO_0f(57),\n  XO_ANDPS =\tXO_0f(54),\n  XO_ADDSD =\tXO_f20f(58),\n  XO_SUBSD =\tXO_f20f(5c),\n  XO_MULSD =\tXO_f20f(59),\n  XO_DIVSD =\tXO_f20f(5e),\n  XO_SQRTSD =\tXO_f20f(51),\n  XO_MINSD =\tXO_f20f(5d),\n  XO_MAXSD =\tXO_f20f(5f),\n  XO_ROUNDSD =\t0x0b3a0ffc,  /* Really 66 0f 3a 0b. See asm_fpmath. */\n  XO_UCOMISD =\tXO_660f(2e),\n  XO_CVTSI2SD =\tXO_f20f(2a),\n  XO_CVTTSD2SI=\tXO_f20f(2c),\n  XO_CVTSI2SS =\tXO_f30f(2a),\n  XO_CVTTSS2SI=\tXO_f30f(2c),\n  XO_CVTSS2SD =\tXO_f30f(5a),\n  XO_CVTSD2SS =\tXO_f20f(5a),\n  XO_ADDSS =\tXO_f30f(58),\n  XO_MOVD =\tXO_660f(6e),\n  XO_MOVDto =\tXO_660f(7e),\n\n  XO_FLDd =\tXO_(d9), XOg_FLDd = 0,\n  XO_FLDq =\tXO_(dd), XOg_FLDq = 0,\n  XO_FILDd =\tXO_(db), XOg_FILDd = 0,\n  XO_FILDq =\tXO_(df), XOg_FILDq = 5,\n  XO_FSTPd =\tXO_(d9), XOg_FSTPd = 3,\n  XO_FSTPq =\tXO_(dd), XOg_FSTPq = 3,\n  XO_FISTPq =\tXO_(df), XOg_FISTPq = 7,\n  XO_FISTTPq =\tXO_(dd), XOg_FISTTPq = 1,\n  XO_FADDq =\tXO_(dc), XOg_FADDq = 0,\n  XO_FLDCW =\tXO_(d9), XOg_FLDCW = 5,\n  XO_FNSTCW =\tXO_(d9), XOg_FNSTCW = 7\n} x86Op;\n\n/* x86 opcode groups. */\ntypedef uint32_t x86Group;\n\n#define XG_(i8, i, g)\t((x86Group)(((i8) << 16) + ((i) << 8) + (g)))\n#define XG_ARITHi(g)\tXG_(XI_ARITHi8, XI_ARITHi, g)\n#define XG_TOXOi(xg)\t((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000)))\n#define XG_TOXOi8(xg)\t((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000)))\n\n#define XO_ARITH(a)\t((x86Op)(0x030000fe + ((a)<<27)))\n#define XO_ARITHw(a)\t((x86Op)(0x036600fd + ((a)<<27)))\n\ntypedef enum {\n  XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP,\n  XOg_X_IMUL\n} x86Arith;\n\ntypedef enum {\n  XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR\n} x86Shift;\n\ntypedef enum {\n  XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV\n} x86Group3;\n\ntypedef enum {\n  XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH\n} x86Group5;\n\n/* x86 condition codes. */\ntypedef enum {\n  CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE,\n  CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE,\n  CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB,\n  CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE,\n  CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL,\n  CC_NG = CC_LE, CC_G = CC_NLE\n} x86CC;\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_trace.c",
    "content": "/*\n** Trace management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_trace_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_debug.h\"\n#include \"lj_str.h\"\n#include \"lj_frame.h\"\n#include \"lj_state.h\"\n#include \"lj_bc.h\"\n#include \"lj_ir.h\"\n#include \"lj_jit.h\"\n#include \"lj_iropt.h\"\n#include \"lj_mcode.h\"\n#include \"lj_trace.h\"\n#include \"lj_snap.h\"\n#include \"lj_gdbjit.h\"\n#include \"lj_record.h\"\n#include \"lj_asm.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n#include \"lj_target.h\"\n#include \"lj_prng.h\"\n\n/* -- Error handling ------------------------------------------------------ */\n\n/* Synchronous abort with error message. */\nvoid lj_trace_err(jit_State *J, TraceError e)\n{\n  setnilV(&J->errinfo);  /* No error info. */\n  setintV(J->L->top++, (int32_t)e);\n  lj_err_throw(J->L, LUA_ERRRUN);\n}\n\n/* Synchronous abort with error message and error info. */\nvoid lj_trace_err_info(jit_State *J, TraceError e)\n{\n  setintV(J->L->top++, (int32_t)e);\n  lj_err_throw(J->L, LUA_ERRRUN);\n}\n\n/* -- Trace management ---------------------------------------------------- */\n\n/* The current trace is first assembled in J->cur. The variable length\n** arrays point to shared, growable buffers (J->irbuf etc.). When trace\n** recording ends successfully, the current trace and its data structures\n** are copied to a new (compact) GCtrace object.\n*/\n\n/* Find a free trace number. */\nstatic TraceNo trace_findfree(jit_State *J)\n{\n  MSize osz, lim;\n  if (J->freetrace == 0)\n    J->freetrace = 1;\n  for (; J->freetrace < J->sizetrace; J->freetrace++)\n    if (traceref(J, J->freetrace) == NULL)\n      return J->freetrace++;\n  /* Need to grow trace array. */\n  lim = (MSize)J->param[JIT_P_maxtrace] + 1;\n  if (lim < 2) lim = 2; else if (lim > 65535) lim = 65535;\n  osz = J->sizetrace;\n  if (osz >= lim)\n    return 0;  /* Too many traces. */\n  lj_mem_growvec(J->L, J->trace, J->sizetrace, lim, GCRef);\n  for (; osz < J->sizetrace; osz++)\n    setgcrefnull(J->trace[osz]);\n  return J->freetrace;\n}\n\n#define TRACE_APPENDVEC(field, szfield, tp) \\\n  T->field = (tp *)p; \\\n  memcpy(p, J->cur.field, J->cur.szfield*sizeof(tp)); \\\n  p += J->cur.szfield*sizeof(tp);\n\n#ifdef LUAJIT_USE_PERFTOOLS\n/*\n** Create symbol table of JIT-compiled code. For use with Linux perf tools.\n** Example usage:\n**   perf record -f -e cycles luajit test.lua\n**   perf report -s symbol\n**   rm perf.data /tmp/perf-*.map\n*/\n#include <stdio.h>\n#include <unistd.h>\n\nstatic void perftools_addtrace(GCtrace *T)\n{\n  static FILE *fp;\n  GCproto *pt = &gcref(T->startpt)->pt;\n  const BCIns *startpc = mref(T->startpc, const BCIns);\n  const char *name = proto_chunknamestr(pt);\n  BCLine lineno;\n  if (name[0] == '@' || name[0] == '=')\n    name++;\n  else\n    name = \"(string)\";\n  lj_assertX(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc,\n\t     \"trace PC out of range\");\n  lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));\n  if (!fp) {\n    char fname[40];\n    sprintf(fname, \"/tmp/perf-%d.map\", getpid());\n    if (!(fp = fopen(fname, \"w\"))) return;\n    setlinebuf(fp);\n  }\n  fprintf(fp, \"%lx %x TRACE_%d::%s:%u\\n\",\n\t  (long)T->mcode, T->szmcode, T->traceno, name, lineno);\n}\n#endif\n\n/* Allocate space for copy of T. */\nGCtrace * LJ_FASTCALL lj_trace_alloc(lua_State *L, GCtrace *T)\n{\n  size_t sztr = ((sizeof(GCtrace)+7)&~7);\n  size_t szins = (T->nins-T->nk)*sizeof(IRIns);\n  size_t sz = sztr + szins +\n\t      T->nsnap*sizeof(SnapShot) +\n\t      T->nsnapmap*sizeof(SnapEntry);\n  GCtrace *T2 = lj_mem_newt(L, (MSize)sz, GCtrace);\n  char *p = (char *)T2 + sztr;\n  T2->gct = ~LJ_TTRACE;\n  T2->marked = 0;\n  T2->traceno = 0;\n  T2->ir = (IRIns *)p - T->nk;\n  T2->nins = T->nins;\n  T2->nk = T->nk;\n  T2->nsnap = T->nsnap;\n  T2->nsnapmap = T->nsnapmap;\n  memcpy(p, T->ir + T->nk, szins);\n  return T2;\n}\n\n/* Save current trace by copying and compacting it. */\nstatic void trace_save(jit_State *J, GCtrace *T)\n{\n  size_t sztr = ((sizeof(GCtrace)+7)&~7);\n  size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);\n  char *p = (char *)T + sztr;\n  memcpy(T, &J->cur, sizeof(GCtrace));\n  setgcrefr(T->nextgc, J2G(J)->gc.root);\n  setgcrefp(J2G(J)->gc.root, T);\n  newwhite(J2G(J), T);\n  T->gct = ~LJ_TTRACE;\n  T->ir = (IRIns *)p - J->cur.nk;  /* The IR has already been copied above. */\n  p += szins;\n  TRACE_APPENDVEC(snap, nsnap, SnapShot)\n  TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry)\n  J->cur.traceno = 0;\n  J->curfinal = NULL;\n  setgcrefp(J->trace[T->traceno], T);\n  lj_gc_barriertrace(J2G(J), T->traceno);\n  lj_gdbjit_addtrace(J, T);\n#ifdef LUAJIT_USE_PERFTOOLS\n  perftools_addtrace(T);\n#endif\n}\n\nvoid LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T)\n{\n  jit_State *J = G2J(g);\n  if (T->traceno) {\n    lj_gdbjit_deltrace(J, T);\n    if (T->traceno < J->freetrace)\n      J->freetrace = T->traceno;\n    setgcrefnull(J->trace[T->traceno]);\n  }\n  lj_mem_free(g, T,\n    ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +\n    T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry));\n}\n\n/* Re-enable compiling a prototype by unpatching any modified bytecode. */\nvoid lj_trace_reenableproto(GCproto *pt)\n{\n  if ((pt->flags & PROTO_ILOOP)) {\n    BCIns *bc = proto_bc(pt);\n    BCPos i, sizebc = pt->sizebc;\n    pt->flags &= ~PROTO_ILOOP;\n    if (bc_op(bc[0]) == BC_IFUNCF)\n      setbc_op(&bc[0], BC_FUNCF);\n    for (i = 1; i < sizebc; i++) {\n      BCOp op = bc_op(bc[i]);\n      if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP)\n\tsetbc_op(&bc[i], (int)op+(int)BC_LOOP-(int)BC_ILOOP);\n    }\n  }\n}\n\n/* Unpatch the bytecode modified by a root trace. */\nstatic void trace_unpatch(jit_State *J, GCtrace *T)\n{\n  BCOp op = bc_op(T->startins);\n  BCIns *pc = mref(T->startpc, BCIns);\n  UNUSED(J);\n  if (op == BC_JMP)\n    return;  /* No need to unpatch branches in parent traces (yet). */\n  switch (bc_op(*pc)) {\n  case BC_JFORL:\n    lj_assertJ(traceref(J, bc_d(*pc)) == T, \"JFORL references other trace\");\n    *pc = T->startins;\n    pc += bc_j(T->startins);\n    lj_assertJ(bc_op(*pc) == BC_JFORI, \"FORL does not point to JFORI\");\n    setbc_op(pc, BC_FORI);\n    break;\n  case BC_JITERL:\n  case BC_JLOOP:\n    lj_assertJ(op == BC_ITERL || op == BC_ITERN || op == BC_LOOP ||\n\t       bc_isret(op), \"bad original bytecode %d\", op);\n    *pc = T->startins;\n    break;\n  case BC_JMP:\n    lj_assertJ(op == BC_ITERL, \"bad original bytecode %d\", op);\n    pc += bc_j(*pc)+2;\n    if (bc_op(*pc) == BC_JITERL) {\n      lj_assertJ(traceref(J, bc_d(*pc)) == T, \"JITERL references other trace\");\n      *pc = T->startins;\n    }\n    break;\n  case BC_JFUNCF:\n    lj_assertJ(op == BC_FUNCF, \"bad original bytecode %d\", op);\n    *pc = T->startins;\n    break;\n  default:  /* Already unpatched. */\n    break;\n  }\n}\n\n/* Flush a root trace. */\nstatic void trace_flushroot(jit_State *J, GCtrace *T)\n{\n  GCproto *pt = &gcref(T->startpt)->pt;\n  lj_assertJ(T->root == 0, \"not a root trace\");\n  lj_assertJ(pt != NULL, \"trace has no prototype\");\n  /* First unpatch any modified bytecode. */\n  trace_unpatch(J, T);\n  /* Unlink root trace from chain anchored in prototype. */\n  if (pt->trace == T->traceno) {  /* Trace is first in chain. Easy. */\n    pt->trace = T->nextroot;\n  } else if (pt->trace) {  /* Otherwise search in chain of root traces. */\n    GCtrace *T2 = traceref(J, pt->trace);\n    if (T2) {\n      for (; T2->nextroot; T2 = traceref(J, T2->nextroot))\n\tif (T2->nextroot == T->traceno) {\n\t  T2->nextroot = T->nextroot;  /* Unlink from chain. */\n\t  break;\n\t}\n    }\n  }\n}\n\n/* Flush a trace. Only root traces are considered. */\nvoid lj_trace_flush(jit_State *J, TraceNo traceno)\n{\n  if (traceno > 0 && traceno < J->sizetrace) {\n    GCtrace *T = traceref(J, traceno);\n    if (T && T->root == 0)\n      trace_flushroot(J, T);\n  }\n}\n\n/* Flush all traces associated with a prototype. */\nvoid lj_trace_flushproto(global_State *g, GCproto *pt)\n{\n  while (pt->trace != 0)\n    trace_flushroot(G2J(g), traceref(G2J(g), pt->trace));\n}\n\n/* Flush all traces. */\nint lj_trace_flushall(lua_State *L)\n{\n  jit_State *J = L2J(L);\n  ptrdiff_t i;\n  if ((J2G(J)->hookmask & HOOK_GC))\n    return 1;\n  for (i = (ptrdiff_t)J->sizetrace-1; i > 0; i--) {\n    GCtrace *T = traceref(J, i);\n    if (T) {\n      if (T->root == 0)\n\ttrace_flushroot(J, T);\n      lj_gdbjit_deltrace(J, T);\n      T->traceno = T->link = 0;  /* Blacklist the link for cont_stitch. */\n      setgcrefnull(J->trace[i]);\n    }\n  }\n  J->cur.traceno = 0;\n  J->freetrace = 0;\n  /* Clear penalty cache. */\n  memset(J->penalty, 0, sizeof(J->penalty));\n  /* Free the whole machine code and invalidate all exit stub groups. */\n  lj_mcode_free(J);\n  memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"flush\"));\n  );\n  return 0;\n}\n\n/* Initialize JIT compiler state. */\nvoid lj_trace_initstate(global_State *g)\n{\n  jit_State *J = G2J(g);\n  TValue *tv;\n\n  /* Initialize aligned SIMD constants. */\n  tv = LJ_KSIMD(J, LJ_KSIMD_ABS);\n  tv[0].u64 = U64x(7fffffff,ffffffff);\n  tv[1].u64 = U64x(7fffffff,ffffffff);\n  tv = LJ_KSIMD(J, LJ_KSIMD_NEG);\n  tv[0].u64 = U64x(80000000,00000000);\n  tv[1].u64 = U64x(80000000,00000000);\n\n  /* Initialize 32/64 bit constants. */\n#if LJ_TARGET_X86ORX64\n  J->k64[LJ_K64_TOBIT].u64 = U64x(43380000,00000000);\n#if LJ_32\n  J->k64[LJ_K64_M2P64_31].u64 = U64x(c1e00000,00000000);\n#endif\n  J->k64[LJ_K64_2P64].u64 = U64x(43f00000,00000000);\n  J->k32[LJ_K32_M2P64_31] = LJ_64 ? 0xdf800000 : 0xcf000000;\n#endif\n#if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS64\n  J->k64[LJ_K64_M2P64].u64 = U64x(c3f00000,00000000);\n#endif\n#if LJ_TARGET_PPC\n  J->k32[LJ_K32_2P52_2P31] = 0x59800004;\n  J->k32[LJ_K32_2P52] = 0x59800000;\n#endif\n#if LJ_TARGET_PPC || LJ_TARGET_MIPS\n  J->k32[LJ_K32_2P31] = 0x4f000000;\n#endif\n#if LJ_TARGET_MIPS\n  J->k64[LJ_K64_2P31].u64 = U64x(41e00000,00000000);\n#if LJ_64\n  J->k64[LJ_K64_2P63].u64 = U64x(43e00000,00000000);\n  J->k32[LJ_K32_2P63] = 0x5f000000;\n  J->k32[LJ_K32_M2P64] = 0xdf800000;\n#endif\n#endif\n}\n\n/* Free everything associated with the JIT compiler state. */\nvoid lj_trace_freestate(global_State *g)\n{\n  jit_State *J = G2J(g);\n#ifdef LUA_USE_ASSERT\n  {  /* This assumes all traces have already been freed. */\n    ptrdiff_t i;\n    for (i = 1; i < (ptrdiff_t)J->sizetrace; i++)\n      lj_assertG(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL,\n\t\t \"trace still allocated\");\n  }\n#endif\n  lj_mcode_free(J);\n  lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry);\n  lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot);\n  lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns);\n  lj_mem_freevec(g, J->trace, J->sizetrace, GCRef);\n}\n\n/* -- Penalties and blacklisting ------------------------------------------ */\n\n/* Blacklist a bytecode instruction. */\nstatic void blacklist_pc(GCproto *pt, BCIns *pc)\n{\n  if (bc_op(*pc) == BC_ITERN) {\n    setbc_op(pc, BC_ITERC);\n    setbc_op(pc+1+bc_j(pc[1]), BC_JMP);\n  } else {\n    setbc_op(pc, (int)bc_op(*pc)+(int)BC_ILOOP-(int)BC_LOOP);\n    pt->flags |= PROTO_ILOOP;\n  }\n}\n\n/* Penalize a bytecode instruction. */\nstatic void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)\n{\n  uint32_t i, val = PENALTY_MIN;\n  for (i = 0; i < PENALTY_SLOTS; i++)\n    if (mref(J->penalty[i].pc, const BCIns) == pc) {  /* Cache slot found? */\n      /* First try to bump its hotcount several times. */\n      val = ((uint32_t)J->penalty[i].val << 1) +\n\t    (lj_prng_u64(&J2G(J)->prng) & ((1u<<PENALTY_RNDBITS)-1));\n      if (val > PENALTY_MAX) {\n\tblacklist_pc(pt, pc);  /* Blacklist it, if that didn't help. */\n\treturn;\n      }\n      goto setpenalty;\n    }\n  /* Assign a new penalty cache slot. */\n  i = J->penaltyslot;\n  J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1);\n  setmref(J->penalty[i].pc, pc);\nsetpenalty:\n  J->penalty[i].val = (uint16_t)val;\n  J->penalty[i].reason = e;\n  hotcount_set(J2GG(J), pc+1, val);\n}\n\n/* -- Trace compiler state machine ---------------------------------------- */\n\n/* Start tracing. */\nstatic void trace_start(jit_State *J)\n{\n  lua_State *L;\n  TraceNo traceno;\n\n  if ((J->pt->flags & PROTO_NOJIT)) {  /* JIT disabled for this proto? */\n    if (J->parent == 0 && J->exitno == 0 && bc_op(*J->pc) != BC_ITERN) {\n      /* Lazy bytecode patching to disable hotcount events. */\n      lj_assertJ(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL ||\n\t\t bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF,\n\t\t \"bad hot bytecode %d\", bc_op(*J->pc));\n      setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP);\n      J->pt->flags |= PROTO_ILOOP;\n    }\n    J->state = LJ_TRACE_IDLE;  /* Silently ignored. */\n    return;\n  }\n\n  /* Get a new trace number. */\n  traceno = trace_findfree(J);\n  if (LJ_UNLIKELY(traceno == 0)) {  /* No free trace? */\n    lj_assertJ((J2G(J)->hookmask & HOOK_GC) == 0,\n\t       \"recorder called from GC hook\");\n    lj_trace_flushall(J->L);\n    J->state = LJ_TRACE_IDLE;  /* Silently ignored. */\n    return;\n  }\n  setgcrefp(J->trace[traceno], &J->cur);\n\n  /* Setup enough of the current trace to be able to send the vmevent. */\n  memset(&J->cur, 0, sizeof(GCtrace));\n  J->cur.traceno = traceno;\n  J->cur.nins = J->cur.nk = REF_BASE;\n  J->cur.ir = J->irbuf;\n  J->cur.snap = J->snapbuf;\n  J->cur.snapmap = J->snapmapbuf;\n  J->mergesnap = 0;\n  J->needsnap = 0;\n  J->bcskip = 0;\n  J->guardemit.irt = 0;\n  J->postproc = LJ_POST_NONE;\n  lj_resetsplit(J);\n  J->retryrec = 0;\n  J->ktrace = 0;\n  setgcref(J->cur.startpt, obj2gco(J->pt));\n\n  L = J->L;\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"start\"));\n    setintV(L->top++, traceno);\n    setfuncV(L, L->top++, J->fn);\n    setintV(L->top++, proto_bcpos(J->pt, J->pc));\n    if (J->parent) {\n      setintV(L->top++, J->parent);\n      setintV(L->top++, J->exitno);\n    } else {\n      BCOp op = bc_op(*J->pc);\n      if (op == BC_CALLM || op == BC_CALL || op == BC_ITERC) {\n\tsetintV(L->top++, J->exitno);  /* Parent of stitched trace. */\n\tsetintV(L->top++, -1);\n      }\n    }\n  );\n  lj_record_setup(J);\n}\n\n/* Stop tracing. */\nstatic void trace_stop(jit_State *J)\n{\n  BCIns *pc = mref(J->cur.startpc, BCIns);\n  BCOp op = bc_op(J->cur.startins);\n  GCproto *pt = &gcref(J->cur.startpt)->pt;\n  TraceNo traceno = J->cur.traceno;\n  GCtrace *T = J->curfinal;\n  lua_State *L;\n\n  switch (op) {\n  case BC_FORL:\n    setbc_op(pc+bc_j(J->cur.startins), BC_JFORI);  /* Patch FORI, too. */\n    /* fallthrough */\n  case BC_LOOP:\n  case BC_ITERL:\n  case BC_FUNCF:\n    /* Patch bytecode of starting instruction in root trace. */\n    setbc_op(pc, (int)op+(int)BC_JLOOP-(int)BC_LOOP);\n    setbc_d(pc, traceno);\n  addroot:\n    /* Add to root trace chain in prototype. */\n    J->cur.nextroot = pt->trace;\n    pt->trace = (TraceNo1)traceno;\n    break;\n  case BC_ITERN:\n  case BC_RET:\n  case BC_RET0:\n  case BC_RET1:\n    *pc = BCINS_AD(BC_JLOOP, J->cur.snap[0].nslots, traceno);\n    goto addroot;\n  case BC_JMP:\n    /* Patch exit branch in parent to side trace entry. */\n    lj_assertJ(J->parent != 0 && J->cur.root != 0, \"not a side trace\");\n    lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode);\n    /* Avoid compiling a side trace twice (stack resizing uses parent exit). */\n    {\n      SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno];\n      snap->count = SNAPCOUNT_DONE;\n      if (J->cur.topslot > snap->topslot) snap->topslot = J->cur.topslot;\n    }\n    /* Add to side trace chain in root trace. */\n    {\n      GCtrace *root = traceref(J, J->cur.root);\n      root->nchild++;\n      J->cur.nextside = root->nextside;\n      root->nextside = (TraceNo1)traceno;\n    }\n    break;\n  case BC_CALLM:\n  case BC_CALL:\n  case BC_ITERC:\n    /* Trace stitching: patch link of previous trace. */\n    traceref(J, J->exitno)->link = traceno;\n    break;\n  default:\n    lj_assertJ(0, \"bad stop bytecode %d\", op);\n    break;\n  }\n\n  /* Commit new mcode only after all patching is done. */\n  lj_mcode_commit(J, J->cur.mcode);\n  J->postproc = LJ_POST_NONE;\n  trace_save(J, T);\n\n  L = J->L;\n  lj_vmevent_send(L, TRACE,\n    setstrV(L, L->top++, lj_str_newlit(L, \"stop\"));\n    setintV(L->top++, traceno);\n    setfuncV(L, L->top++, J->fn);\n  );\n}\n\n/* Start a new root trace for down-recursion. */\nstatic int trace_downrec(jit_State *J)\n{\n  /* Restart recording at the return instruction. */\n  lj_assertJ(J->pt != NULL, \"no active prototype\");\n  lj_assertJ(bc_isret(bc_op(*J->pc)), \"not at a return bytecode\");\n  if (bc_op(*J->pc) == BC_RETM)\n    return 0;  /* NYI: down-recursion with RETM. */\n  J->parent = 0;\n  J->exitno = 0;\n  J->state = LJ_TRACE_RECORD;\n  trace_start(J);\n  return 1;\n}\n\n/* Abort tracing. */\nstatic int trace_abort(jit_State *J)\n{\n  lua_State *L = J->L;\n  TraceError e = LJ_TRERR_RECERR;\n  TraceNo traceno;\n\n  J->postproc = LJ_POST_NONE;\n  lj_mcode_abort(J);\n  if (J->curfinal) {\n    lj_trace_free(J2G(J), J->curfinal);\n    J->curfinal = NULL;\n  }\n  if (tvisnumber(L->top-1))\n    e = (TraceError)numberVint(L->top-1);\n  if (e == LJ_TRERR_MCODELM) {\n    L->top--;  /* Remove error object */\n    J->state = LJ_TRACE_ASM;\n    return 1;  /* Retry ASM with new MCode area. */\n  }\n  /* Penalize or blacklist starting bytecode instruction. */\n  if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) {\n    if (J->exitno == 0) {\n      BCIns *startpc = mref(J->cur.startpc, BCIns);\n      if (e == LJ_TRERR_RETRY)\n\thotcount_set(J2GG(J), startpc+1, 1);  /* Immediate retry. */\n      else\n\tpenalty_pc(J, &gcref(J->cur.startpt)->pt, startpc, e);\n    } else {\n      traceref(J, J->exitno)->link = J->exitno;  /* Self-link is blacklisted. */\n    }\n  }\n\n  /* Is there anything to abort? */\n  traceno = J->cur.traceno;\n  if (traceno) {\n    ptrdiff_t errobj = savestack(L, L->top-1);  /* Stack may be resized. */\n    J->cur.link = 0;\n    J->cur.linktype = LJ_TRLINK_NONE;\n    lj_vmevent_send(L, TRACE,\n      TValue *frame;\n      const BCIns *pc;\n      GCfunc *fn;\n      setstrV(L, L->top++, lj_str_newlit(L, \"abort\"));\n      setintV(L->top++, traceno);\n      /* Find original Lua function call to generate a better error message. */\n      frame = J->L->base-1;\n      pc = J->pc;\n      while (!isluafunc(frame_func(frame))) {\n\tpc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;\n\tframe = frame_prev(frame);\n      }\n      fn = frame_func(frame);\n      setfuncV(L, L->top++, fn);\n      setintV(L->top++, proto_bcpos(funcproto(fn), pc));\n      copyTV(L, L->top++, restorestack(L, errobj));\n      copyTV(L, L->top++, &J->errinfo);\n    );\n    /* Drop aborted trace after the vmevent (which may still access it). */\n    setgcrefnull(J->trace[traceno]);\n    if (traceno < J->freetrace)\n      J->freetrace = traceno;\n    J->cur.traceno = 0;\n  }\n  L->top--;  /* Remove error object */\n  if (e == LJ_TRERR_DOWNREC)\n    return trace_downrec(J);\n  else if (e == LJ_TRERR_MCODEAL)\n    lj_trace_flushall(L);\n  return 0;\n}\n\n/* Perform pending re-patch of a bytecode instruction. */\nstatic LJ_AINLINE void trace_pendpatch(jit_State *J, int force)\n{\n  if (LJ_UNLIKELY(J->patchpc)) {\n    if (force || J->bcskip == 0) {\n      *J->patchpc = J->patchins;\n      J->patchpc = NULL;\n    } else {\n      J->bcskip = 0;\n    }\n  }\n}\n\n/* State machine for the trace compiler. Protected callback. */\nstatic TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  jit_State *J = (jit_State *)ud;\n  UNUSED(dummy);\n  do {\n  retry:\n    switch (J->state) {\n    case LJ_TRACE_START:\n      J->state = LJ_TRACE_RECORD;  /* trace_start() may change state. */\n      trace_start(J);\n      lj_dispatch_update(J2G(J));\n      if (J->state != LJ_TRACE_RECORD_1ST)\n\tbreak;\n      /* fallthrough */\n\n    case LJ_TRACE_RECORD_1ST:\n      J->state = LJ_TRACE_RECORD;\n      /* fallthrough */\n    case LJ_TRACE_RECORD:\n      trace_pendpatch(J, 0);\n      setvmstate(J2G(J), RECORD);\n      lj_vmevent_send_(L, RECORD,\n\t/* Save/restore tmptv state for trace recorder. */\n\tTValue savetv = J2G(J)->tmptv;\n\tTValue savetv2 = J2G(J)->tmptv2;\n\tsetintV(L->top++, J->cur.traceno);\n\tsetfuncV(L, L->top++, J->fn);\n\tsetintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1);\n\tsetintV(L->top++, J->framedepth);\n      ,\n\tJ2G(J)->tmptv = savetv;\n\tJ2G(J)->tmptv2 = savetv2;\n      );\n      lj_record_ins(J);\n      break;\n\n    case LJ_TRACE_END:\n      trace_pendpatch(J, 1);\n      J->loopref = 0;\n      if ((J->flags & JIT_F_OPT_LOOP) &&\n\t  J->cur.link == J->cur.traceno && J->framedepth + J->retdepth == 0) {\n\tsetvmstate(J2G(J), OPT);\n\tlj_opt_dce(J);\n\tif (lj_opt_loop(J)) {  /* Loop optimization failed? */\n\t  J->cur.link = 0;\n\t  J->cur.linktype = LJ_TRLINK_NONE;\n\t  J->loopref = J->cur.nins;\n\t  J->state = LJ_TRACE_RECORD;  /* Try to continue recording. */\n\t  break;\n\t}\n\tJ->loopref = J->chain[IR_LOOP];  /* Needed by assembler. */\n      }\n      lj_opt_split(J);\n      lj_opt_sink(J);\n      if (!J->loopref) J->cur.snap[J->cur.nsnap-1].count = SNAPCOUNT_DONE;\n      J->state = LJ_TRACE_ASM;\n      break;\n\n    case LJ_TRACE_ASM:\n      setvmstate(J2G(J), ASM);\n      lj_asm_trace(J, &J->cur);\n      trace_stop(J);\n      setvmstate(J2G(J), INTERP);\n      J->state = LJ_TRACE_IDLE;\n      lj_dispatch_update(J2G(J));\n      return NULL;\n\n    default:  /* Trace aborted asynchronously. */\n      setintV(L->top++, (int32_t)LJ_TRERR_RECERR);\n      /* fallthrough */\n    case LJ_TRACE_ERR:\n      trace_pendpatch(J, 1);\n      if (trace_abort(J))\n\tgoto retry;\n      setvmstate(J2G(J), INTERP);\n      J->state = LJ_TRACE_IDLE;\n      lj_dispatch_update(J2G(J));\n      return NULL;\n    }\n  } while (J->state > LJ_TRACE_RECORD);\n  return NULL;\n}\n\n/* -- Event handling ------------------------------------------------------ */\n\n/* A bytecode instruction is about to be executed. Record it. */\nvoid lj_trace_ins(jit_State *J, const BCIns *pc)\n{\n  /* Note: J->L must already be set. pc is the true bytecode PC here. */\n  J->pc = pc;\n  J->fn = curr_func(J->L);\n  J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL;\n  while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0)\n    J->state = LJ_TRACE_ERR;\n}\n\n/* A hotcount triggered. Start recording a root trace. */\nvoid LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc)\n{\n  /* Note: pc is the interpreter bytecode PC here. It's offset by 1. */\n  ERRNO_SAVE\n  /* Reset hotcount. */\n  hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP);\n  /* Only start a new trace if not recording or inside __gc call or vmevent. */\n  if (J->state == LJ_TRACE_IDLE &&\n      !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n    J->parent = 0;  /* Root trace. */\n    J->exitno = 0;\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc-1);\n  }\n  ERRNO_RESTORE\n}\n\n/* Check for a hot side exit. If yes, start recording a side trace. */\nstatic void trace_hotside(jit_State *J, const BCIns *pc)\n{\n  SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno];\n  if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) &&\n      isluafunc(curr_func(J->L)) &&\n      snap->count != SNAPCOUNT_DONE &&\n      ++snap->count >= J->param[JIT_P_hotexit]) {\n    lj_assertJ(J->state == LJ_TRACE_IDLE, \"hot side exit while recording\");\n    /* J->parent is non-zero for a side trace. */\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc);\n  }\n}\n\n/* Stitch a new trace to the previous trace. */\nvoid LJ_FASTCALL lj_trace_stitch(jit_State *J, const BCIns *pc)\n{\n  /* Only start a new trace if not recording or inside __gc call or vmevent. */\n  if (J->state == LJ_TRACE_IDLE &&\n      !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {\n    J->parent = 0;  /* Have to treat it like a root trace. */\n    /* J->exitno is set to the invoking trace. */\n    J->state = LJ_TRACE_START;\n    lj_trace_ins(J, pc);\n  }\n}\n\n\n/* Tiny struct to pass data to protected call. */\ntypedef struct ExitDataCP {\n  jit_State *J;\n  void *exptr;\t\t/* Pointer to exit state. */\n  const BCIns *pc;\t/* Restart interpreter at this PC. */\n} ExitDataCP;\n\n/* Need to protect lj_snap_restore because it may throw. */\nstatic TValue *trace_exit_cp(lua_State *L, lua_CFunction dummy, void *ud)\n{\n  ExitDataCP *exd = (ExitDataCP *)ud;\n  /* Always catch error here and don't call error function. */\n  cframe_errfunc(L->cframe) = 0;\n  cframe_nres(L->cframe) = -2*LUAI_MAXSTACK*(int)sizeof(TValue);\n  exd->pc = lj_snap_restore(exd->J, exd->exptr);\n  UNUSED(dummy);\n  return NULL;\n}\n\n#ifndef LUAJIT_DISABLE_VMEVENT\n/* Push all registers from exit state. */\nstatic void trace_exit_regs(lua_State *L, ExitState *ex)\n{\n  int32_t i;\n  setintV(L->top++, RID_NUM_GPR);\n  setintV(L->top++, RID_NUM_FPR);\n  for (i = 0; i < RID_NUM_GPR; i++) {\n    if (sizeof(ex->gpr[i]) == sizeof(int32_t))\n      setintV(L->top++, (int32_t)ex->gpr[i]);\n    else\n      setnumV(L->top++, (lua_Number)ex->gpr[i]);\n  }\n#if !LJ_SOFTFP\n  for (i = 0; i < RID_NUM_FPR; i++) {\n    setnumV(L->top, ex->fpr[i]);\n    if (LJ_UNLIKELY(tvisnan(L->top)))\n      setnanV(L->top);\n    L->top++;\n  }\n#endif\n}\n#endif\n\n#if defined(EXITSTATE_PCREG) || (LJ_UNWIND_JIT && !EXITTRACE_VMSTATE)\n/* Determine trace number from pc of exit instruction. */\nstatic TraceNo trace_exit_find(jit_State *J, MCode *pc)\n{\n  TraceNo traceno;\n  for (traceno = 1; traceno < J->sizetrace; traceno++) {\n    GCtrace *T = traceref(J, traceno);\n    if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode))\n      return traceno;\n  }\n  lj_assertJ(0, \"bad exit pc\");\n  return 0;\n}\n#endif\n\n/* A trace exited. Restore interpreter state. */\nint LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)\n{\n  ERRNO_SAVE\n  lua_State *L = J->L;\n  ExitState *ex = (ExitState *)exptr;\n  ExitDataCP exd;\n  int errcode, exitcode = J->exitcode;\n  TValue exiterr;\n  const BCIns *pc;\n  void *cf;\n  GCtrace *T;\n\n  setnilV(&exiterr);\n  if (exitcode) {  /* Trace unwound with error code. */\n    J->exitcode = 0;\n    copyTV(L, &exiterr, L->top-1);\n  }\n\n#ifdef EXITSTATE_PCREG\n  J->parent = trace_exit_find(J, (MCode *)(intptr_t)ex->gpr[EXITSTATE_PCREG]);\n#endif\n  T = traceref(J, J->parent); UNUSED(T);\n#ifdef EXITSTATE_CHECKEXIT\n  if (J->exitno == T->nsnap) {  /* Treat stack check like a parent exit. */\n    lj_assertJ(T->root != 0, \"stack check in root trace\");\n    J->exitno = T->ir[REF_BASE].op2;\n    J->parent = T->ir[REF_BASE].op1;\n    T = traceref(J, J->parent);\n  }\n#endif\n  lj_assertJ(T != NULL && J->exitno < T->nsnap, \"bad trace or exit number\");\n  exd.J = J;\n  exd.exptr = exptr;\n  errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp);\n  if (errcode)\n    return -errcode;  /* Return negated error code. */\n\n  if (exitcode) copyTV(L, L->top++, &exiterr);  /* Anchor the error object. */\n\n  if (!(LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)))\n    lj_vmevent_send(L, TEXIT,\n      lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);\n      setintV(L->top++, J->parent);\n      setintV(L->top++, J->exitno);\n      trace_exit_regs(L, ex);\n    );\n\n  pc = exd.pc;\n  cf = cframe_raw(L->cframe);\n  setcframe_pc(cf, pc);\n  if (exitcode) {\n    return -exitcode;\n  } else if (LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)) {\n    /* Just exit to interpreter. */\n  } else if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {\n    if (!(G(L)->hookmask & HOOK_GC))\n      lj_gc_step(L);  /* Exited because of GC: drive GC forward. */\n  } else {\n    trace_hotside(J, pc);\n  }\n  if (bc_op(*pc) == BC_JLOOP) {\n    BCIns *retpc = &traceref(J, bc_d(*pc))->startins;\n    int isret = bc_isret(bc_op(*retpc));\n    if (isret || bc_op(*retpc) == BC_ITERN) {\n      if (J->state == LJ_TRACE_RECORD) {\n\tJ->patchins = *pc;\n\tJ->patchpc = (BCIns *)pc;\n\t*J->patchpc = *retpc;\n\tJ->bcskip = 1;\n      } else if (isret) {\n\tpc = retpc;\n\tsetcframe_pc(cf, pc);\n      }\n    }\n  }\n  /* Return MULTRES or 0. */\n  ERRNO_RESTORE\n  switch (bc_op(*pc)) {\n  case BC_CALLM: case BC_CALLMT:\n    return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc) - LJ_FR2);\n  case BC_RETM:\n    return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc));\n  case BC_TSETM:\n    return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc));\n  default:\n    if (bc_op(*pc) >= BC_FUNCF)\n      return (int)((BCReg)(L->top - L->base) + 1);\n    return 0;\n  }\n}\n\n#if LJ_UNWIND_JIT\n/* Given an mcode address determine trace exit address for unwinding. */\nuintptr_t LJ_FASTCALL lj_trace_unwind(jit_State *J, uintptr_t addr, ExitNo *ep)\n{\n#if EXITTRACE_VMSTATE\n  TraceNo traceno = J2G(J)->vmstate;\n#else\n  TraceNo traceno = trace_exit_find(J, (MCode *)addr);\n#endif\n  GCtrace *T = traceref(J, traceno);\n  if (T\n#if EXITTRACE_VMSTATE\n      && addr >= (uintptr_t)T->mcode && addr < (uintptr_t)T->mcode + T->szmcode\n#endif\n     ) {\n    SnapShot *snap = T->snap;\n    SnapNo lo = 0, exitno = T->nsnap;\n    uintptr_t ofs = (uintptr_t)((MCode *)addr - T->mcode);  /* MCode units! */\n    /* Rightmost binary search for mcode offset to determine exit number. */\n    do {\n      SnapNo mid = (lo+exitno) >> 1;\n      if (ofs < snap[mid].mcofs) exitno = mid; else lo = mid + 1;\n    } while (lo < exitno);\n    exitno--;\n    *ep = exitno;\n#ifdef EXITSTUBS_PER_GROUP\n    return (uintptr_t)exitstub_addr(J, exitno);\n#else\n    return (uintptr_t)exitstub_trace_addr(T, exitno);\n#endif\n  }\n  /* Cannot correlate addr with trace/exit. This will be fatal. */\n  lj_assertJ(0, \"bad exit pc\");\n  return 0;\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_trace.h",
    "content": "/*\n** Trace management.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_TRACE_H\n#define _LJ_TRACE_H\n\n#include \"lj_obj.h\"\n\n#if LJ_HASJIT\n#include \"lj_jit.h\"\n#include \"lj_dispatch.h\"\n\n/* Trace errors. */\ntypedef enum {\n#define TREDEF(name, msg)\tLJ_TRERR_##name,\n#include \"lj_traceerr.h\"\n  LJ_TRERR__MAX\n} TraceError;\n\nLJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);\nLJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);\n\n/* Trace management. */\nLJ_FUNC GCtrace * LJ_FASTCALL lj_trace_alloc(lua_State *L, GCtrace *T);\nLJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);\nLJ_FUNC void lj_trace_reenableproto(GCproto *pt);\nLJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);\nLJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno);\nLJ_FUNC int lj_trace_flushall(lua_State *L);\nLJ_FUNC void lj_trace_initstate(global_State *g);\nLJ_FUNC void lj_trace_freestate(global_State *g);\n\n/* Event handling. */\nLJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc);\nLJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc);\nLJ_FUNCA void LJ_FASTCALL lj_trace_stitch(jit_State *J, const BCIns *pc);\nLJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);\n#if LJ_UNWIND_EXT\nLJ_FUNC uintptr_t LJ_FASTCALL lj_trace_unwind(jit_State *J, uintptr_t addr, ExitNo *ep);\n#endif\n\n/* Signal asynchronous abort of trace or end of trace. */\n#define lj_trace_abort(g)\t(G2J(g)->state &= ~LJ_TRACE_ACTIVE)\n#define lj_trace_end(J)\t\t(J->state = LJ_TRACE_END)\n\n#else\n\n#define lj_trace_flushall(L)\t(UNUSED(L), 0)\n#define lj_trace_initstate(g)\tUNUSED(g)\n#define lj_trace_freestate(g)\tUNUSED(g)\n#define lj_trace_abort(g)\tUNUSED(g)\n#define lj_trace_end(J)\t\tUNUSED(J)\n\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_traceerr.h",
    "content": "/*\n** Trace compiler error messages.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n/* This file may be included multiple times with different TREDEF macros. */\n\n/* Recording. */\nTREDEF(RECERR,\t\"error thrown or hook called during recording\")\nTREDEF(TRACEUV,\t\"trace too short\")\nTREDEF(TRACEOV,\t\"trace too long\")\nTREDEF(STACKOV,\t\"trace too deep\")\nTREDEF(SNAPOV,\t\"too many snapshots\")\nTREDEF(BLACKL,\t\"blacklisted\")\nTREDEF(RETRY,\t\"retry recording\")\nTREDEF(NYIBC,\t\"NYI: bytecode %d\")\n\n/* Recording loop ops. */\nTREDEF(LLEAVE,\t\"leaving loop in root trace\")\nTREDEF(LINNER,\t\"inner loop in root trace\")\nTREDEF(LUNROLL,\t\"loop unroll limit reached\")\n\n/* Recording calls/returns. */\nTREDEF(BADTYPE,\t\"bad argument type\")\nTREDEF(CJITOFF,\t\"JIT compilation disabled for function\")\nTREDEF(CUNROLL,\t\"call unroll limit reached\")\nTREDEF(DOWNREC,\t\"down-recursion, restarting\")\nTREDEF(NYIFFU,\t\"NYI: unsupported variant of FastFunc %s\")\nTREDEF(NYIRETL,\t\"NYI: return to lower frame\")\n\n/* Recording indexed load/store. */\nTREDEF(STORENN,\t\"store with nil or NaN key\")\nTREDEF(NOMM,\t\"missing metamethod\")\nTREDEF(IDXLOOP,\t\"looping index lookup\")\nTREDEF(NYITMIX,\t\"NYI: mixed sparse/dense table\")\n\n/* Recording C data operations. */\nTREDEF(NOCACHE,\t\"symbol not in cache\")\nTREDEF(NYICONV,\t\"NYI: unsupported C type conversion\")\nTREDEF(NYICALL,\t\"NYI: unsupported C function type\")\n\n/* Optimizations. */\nTREDEF(GFAIL,\t\"guard would always fail\")\nTREDEF(PHIOV,\t\"too many PHIs\")\nTREDEF(TYPEINS,\t\"persistent type instability\")\n\n/* Assembler. */\nTREDEF(MCODEAL,\t\"failed to allocate mcode memory\")\nTREDEF(MCODEOV,\t\"machine code too long\")\nTREDEF(MCODELM,\t\"hit mcode limit (retrying)\")\nTREDEF(SPILLOV,\t\"too many spill slots\")\nTREDEF(BADRA,\t\"inconsistent register allocation\")\nTREDEF(NYIIR,\t\"NYI: cannot assemble IR instruction %d\")\nTREDEF(NYIPHI,\t\"NYI: PHI shuffling too complex\")\nTREDEF(NYICOAL,\t\"NYI: register coalescing too complex\")\n\n#undef TREDEF\n\n/* Detecting unused error messages:\n   awk -F, '/^TREDEF/ { gsub(/TREDEF./, \"\"); printf \"grep -q LJ_TRERR_%s *.[ch] || echo %s\\n\", $1, $1}' lj_traceerr.h | sh\n*/\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_udata.c",
    "content": "/*\n** Userdata handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_udata_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_gc.h\"\n#include \"lj_err.h\"\n#include \"lj_udata.h\"\n\nGCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)\n{\n  GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata);\n  global_State *g = G(L);\n  newwhite(g, ud);  /* Not finalized. */\n  ud->gct = ~LJ_TUDATA;\n  ud->udtype = UDTYPE_USERDATA;\n  ud->len = sz;\n  /* NOBARRIER: The GCudata is new (marked white). */\n  setgcrefnull(ud->metatable);\n  setgcref(ud->env, obj2gco(env));\n  /* Chain to userdata list (after main thread). */\n  setgcrefr(ud->nextgc, mainthread(g)->nextgc);\n  setgcref(mainthread(g)->nextgc, obj2gco(ud));\n  return ud;\n}\n\nvoid LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)\n{\n  lj_mem_free(g, ud, sizeudata(ud));\n}\n\n#if LJ_64\nvoid *lj_lightud_intern(lua_State *L, void *p)\n{\n  global_State *g = G(L);\n  uint64_t u = (uint64_t)p;\n  uint32_t up = lightudup(u);\n  uint32_t *segmap = mref(g->gc.lightudseg, uint32_t);\n  MSize segnum = g->gc.lightudnum;\n  if (segmap) {\n    MSize seg;\n    for (seg = 0; seg <= segnum; seg++)\n      if (segmap[seg] == up)  /* Fast path. */\n\treturn (void *)(((uint64_t)seg << LJ_LIGHTUD_BITS_LO) | lightudlo(u));\n    segnum++;\n    /* Leave last segment unused to avoid clash with ITERN key. */\n    if (segnum >= (1 << LJ_LIGHTUD_BITS_SEG)-1) lj_err_msg(L, LJ_ERR_BADLU);\n  }\n  if (!((segnum-1) & segnum) && segnum != 1) {\n    lj_mem_reallocvec(L, segmap, segnum, segnum ? 2*segnum : 2u, uint32_t);\n    setmref(g->gc.lightudseg, segmap);\n  }\n  g->gc.lightudnum = segnum;\n  segmap[segnum] = up;\n  return (void *)(((uint64_t)segnum << LJ_LIGHTUD_BITS_LO) | lightudlo(u));\n}\n#endif\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_udata.h",
    "content": "/*\n** Userdata handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_UDATA_H\n#define _LJ_UDATA_H\n\n#include \"lj_obj.h\"\n\nLJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);\nLJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);\n#if LJ_64\nLJ_FUNC void * LJ_FASTCALL lj_lightud_intern(lua_State *L, void *p);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_vm.h",
    "content": "/*\n** Assembler VM interface definitions.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_VM_H\n#define _LJ_VM_H\n\n#include \"lj_obj.h\"\n\n/* Entry points for ASM parts of VM. */\nLJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1);\nLJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);\ntypedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud);\nLJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,\n\t\t\t lua_CPFunction cp);\nLJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);\nLJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);\nLJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);\n#if LJ_ABI_WIN && LJ_TARGET_X86\nLJ_ASMF_NORET void LJ_FASTCALL lj_vm_rtlunwind(void *cframe, void *excptrec,\n\t\t\t\t\t       void *unwinder, int errcode);\n#endif\nLJ_ASMF void lj_vm_unwind_c_eh(void);\nLJ_ASMF void lj_vm_unwind_ff_eh(void);\n#if LJ_TARGET_X86ORX64\nLJ_ASMF void lj_vm_unwind_rethrow(void);\n#endif\n#if LJ_TARGET_MIPS\nLJ_ASMF void lj_vm_unwind_stub(void);\n#endif\n\n/* Miscellaneous functions. */\n#if LJ_TARGET_X86ORX64\nLJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]);\n#endif\n#if LJ_TARGET_PPC\nvoid lj_vm_cachesync(void *start, void *end);\n#endif\nLJ_ASMF double lj_vm_foldarith(double x, double y, int op);\n#if LJ_HASJIT\nLJ_ASMF double lj_vm_foldfpm(double x, int op);\n#endif\n#if !LJ_ARCH_HASFPU\n/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */\n#endif\n\n/* Dispatch targets for recording and hooks. */\nLJ_ASMF void lj_vm_record(void);\nLJ_ASMF void lj_vm_inshook(void);\nLJ_ASMF void lj_vm_rethook(void);\nLJ_ASMF void lj_vm_callhook(void);\nLJ_ASMF void lj_vm_profhook(void);\nLJ_ASMF void lj_vm_IITERN(void);\n\n/* Trace exit handling. */\nLJ_ASMF void lj_vm_exit_handler(void);\nLJ_ASMF void lj_vm_exit_interp(void);\n\n/* Internal math helper functions. */\n#if LJ_TARGET_PPC || LJ_TARGET_ARM64 || (LJ_TARGET_MIPS && LJ_ABI_SOFTFP)\n#define lj_vm_floor\tfloor\n#define lj_vm_ceil\tceil\n#else\nLJ_ASMF double lj_vm_floor(double);\nLJ_ASMF double lj_vm_ceil(double);\n#if LJ_TARGET_ARM\nLJ_ASMF double lj_vm_floor_sf(double);\nLJ_ASMF double lj_vm_ceil_sf(double);\n#endif\n#endif\n#ifdef LUAJIT_NO_LOG2\nLJ_ASMF double lj_vm_log2(double);\n#else\n#define lj_vm_log2\tlog2\n#endif\n#if !(defined(_LJ_DISPATCH_H) && LJ_TARGET_MIPS)\nLJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t);\n#endif\n\n#if LJ_HASJIT\n#if LJ_TARGET_X86ORX64\nLJ_ASMF void lj_vm_floor_sse(void);\nLJ_ASMF void lj_vm_ceil_sse(void);\nLJ_ASMF void lj_vm_trunc_sse(void);\nLJ_ASMF void lj_vm_powi_sse(void);\n#define lj_vm_powi\tNULL\n#else\nLJ_ASMF double lj_vm_powi(double, int32_t);\n#endif\n#if LJ_TARGET_PPC || LJ_TARGET_ARM64\n#define lj_vm_trunc\ttrunc\n#else\nLJ_ASMF double lj_vm_trunc(double);\n#if LJ_TARGET_ARM\nLJ_ASMF double lj_vm_trunc_sf(double);\n#endif\n#endif\n#if LJ_HASFFI\nLJ_ASMF int lj_vm_errno(void);\n#endif\nLJ_ASMF TValue *lj_vm_next(GCtab *t, uint32_t idx);\n#endif\n\n/* Continuations for metamethods. */\nLJ_ASMF void lj_cont_cat(void);  /* Continue with concatenation. */\nLJ_ASMF void lj_cont_ra(void);  /* Store result in RA from instruction. */\nLJ_ASMF void lj_cont_nop(void);  /* Do nothing, just continue execution. */\nLJ_ASMF void lj_cont_condt(void);  /* Branch if result is true. */\nLJ_ASMF void lj_cont_condf(void);  /* Branch if result is false. */\nLJ_ASMF void lj_cont_hook(void);  /* Continue from hook yield. */\nLJ_ASMF void lj_cont_stitch(void);  /* Trace stitching. */\n\n/* Start of the ASM code. */\nLJ_ASMF char lj_vm_asm_begin[];\n\n/* Bytecode offsets are relative to lj_vm_asm_begin. */\n#define makeasmfunc(ofs)\t((ASMFunction)(lj_vm_asm_begin + (ofs)))\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_vmevent.c",
    "content": "/*\n** VM event handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#include <stdio.h>\n\n#define lj_vmevent_c\n#define LUA_CORE\n\n#include \"lj_obj.h\"\n#include \"lj_str.h\"\n#include \"lj_tab.h\"\n#include \"lj_state.h\"\n#include \"lj_dispatch.h\"\n#include \"lj_vm.h\"\n#include \"lj_vmevent.h\"\n\nptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)\n{\n  global_State *g = G(L);\n  GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY);\n  cTValue *tv = lj_tab_getstr(tabV(registry(L)), s);\n  if (tvistab(tv)) {\n    int hash = VMEVENT_HASH(ev);\n    tv = lj_tab_getint(tabV(tv), hash);\n    if (tv && tvisfunc(tv)) {\n      lj_state_checkstack(L, LUA_MINSTACK);\n      setfuncV(L, L->top++, funcV(tv));\n      if (LJ_FR2) setnilV(L->top++);\n      return savestack(L, L->top);\n    }\n  }\n  g->vmevmask &= ~VMEVENT_MASK(ev);  /* No handler: cache this fact. */\n  return 0;\n}\n\nvoid lj_vmevent_call(lua_State *L, ptrdiff_t argbase)\n{\n  global_State *g = G(L);\n  uint8_t oldmask = g->vmevmask;\n  uint8_t oldh = hook_save(g);\n  int status;\n  g->vmevmask = 0;  /* Disable all events. */\n  hook_vmevent(g);\n  status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0);\n  if (LJ_UNLIKELY(status)) {\n    /* Really shouldn't use stderr here, but where else to complain? */\n    L->top--;\n    fputs(\"VM handler failed: \", stderr);\n    fputs(tvisstr(L->top) ? strVdata(L->top) : \"?\", stderr);\n    fputc('\\n', stderr);\n  }\n  hook_restore(g, oldh);\n  if (g->vmevmask != VMEVENT_NOCACHE)\n    g->vmevmask = oldmask;  /* Restore event mask, but not if not modified. */\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_vmevent.h",
    "content": "/*\n** VM event handling.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LJ_VMEVENT_H\n#define _LJ_VMEVENT_H\n\n#include \"lj_obj.h\"\n\n/* Registry key for VM event handler table. */\n#define LJ_VMEVENTS_REGKEY\t\"_VMEVENTS\"\n#define LJ_VMEVENTS_HSIZE\t4\n\n#define VMEVENT_MASK(ev)\t((uint8_t)1 << ((int)(ev) & 7))\n#define VMEVENT_HASH(ev)\t((int)(ev) & ~7)\n#define VMEVENT_HASHIDX(h)\t((int)(h) << 3)\n#define VMEVENT_NOCACHE\t\t255\n\n#define VMEVENT_DEF(name, hash) \\\n  LJ_VMEVENT_##name##_, \\\n  LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)\n\n/* VM event IDs. */\ntypedef enum {\n  VMEVENT_DEF(BC,\t0x00003883),\n  VMEVENT_DEF(TRACE,\t0xb2d91467),\n  VMEVENT_DEF(RECORD,\t0x9284bf4f),\n  VMEVENT_DEF(TEXIT,\t0xb29df2b0),\n  LJ_VMEVENT__MAX\n} VMEvent;\n\n#ifdef LUAJIT_DISABLE_VMEVENT\n#define lj_vmevent_send(L, ev, args)\t\tUNUSED(L)\n#define lj_vmevent_send_(L, ev, args, post)\tUNUSED(L)\n#else\n#define lj_vmevent_send(L, ev, args) \\\n  if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \\\n    ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \\\n    if (argbase) { \\\n      args \\\n      lj_vmevent_call(L, argbase); \\\n    } \\\n  }\n#define lj_vmevent_send_(L, ev, args, post) \\\n  if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \\\n    ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \\\n    if (argbase) { \\\n      args \\\n      lj_vmevent_call(L, argbase); \\\n      post \\\n    } \\\n  }\n\nLJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);\nLJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lj_vmmath.c",
    "content": "/*\n** Math helper functions for assembler VM.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define lj_vmmath_c\n#define LUA_CORE\n\n#include <errno.h>\n#include <math.h>\n\n#include \"lj_obj.h\"\n#include \"lj_ir.h\"\n#include \"lj_vm.h\"\n\n/* -- Wrapper functions --------------------------------------------------- */\n\n#if LJ_TARGET_X86 && __ELF__ && __PIC__\n/* Wrapper functions to deal with the ELF/x86 PIC disaster. */\nLJ_FUNCA double lj_wrap_log(double x) { return log(x); }\nLJ_FUNCA double lj_wrap_log10(double x) { return log10(x); }\nLJ_FUNCA double lj_wrap_exp(double x) { return exp(x); }\nLJ_FUNCA double lj_wrap_sin(double x) { return sin(x); }\nLJ_FUNCA double lj_wrap_cos(double x) { return cos(x); }\nLJ_FUNCA double lj_wrap_tan(double x) { return tan(x); }\nLJ_FUNCA double lj_wrap_asin(double x) { return asin(x); }\nLJ_FUNCA double lj_wrap_acos(double x) { return acos(x); }\nLJ_FUNCA double lj_wrap_atan(double x) { return atan(x); }\nLJ_FUNCA double lj_wrap_sinh(double x) { return sinh(x); }\nLJ_FUNCA double lj_wrap_cosh(double x) { return cosh(x); }\nLJ_FUNCA double lj_wrap_tanh(double x) { return tanh(x); }\nLJ_FUNCA double lj_wrap_atan2(double x, double y) { return atan2(x, y); }\nLJ_FUNCA double lj_wrap_pow(double x, double y) { return pow(x, y); }\nLJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); }\n#endif\n\n/* -- Helper functions for generated machine code ------------------------- */\n\ndouble lj_vm_foldarith(double x, double y, int op)\n{\n  switch (op) {\n  case IR_ADD - IR_ADD: return x+y; break;\n  case IR_SUB - IR_ADD: return x-y; break;\n  case IR_MUL - IR_ADD: return x*y; break;\n  case IR_DIV - IR_ADD: return x/y; break;\n  case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break;\n  case IR_POW - IR_ADD: return pow(x, y); break;\n  case IR_NEG - IR_ADD: return -x; break;\n  case IR_ABS - IR_ADD: return fabs(x); break;\n#if LJ_HASJIT\n  case IR_LDEXP - IR_ADD: return ldexp(x, (int)y); break;\n  case IR_MIN - IR_ADD: return x < y ? x : y; break;\n  case IR_MAX - IR_ADD: return x > y ? x : y; break;\n#endif\n  default: return x;\n  }\n}\n\n#if (LJ_HASJIT && !(LJ_TARGET_ARM || LJ_TARGET_ARM64 || LJ_TARGET_PPC)) || LJ_TARGET_MIPS\nint32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b)\n{\n  uint32_t y, ua, ub;\n  /* This must be checked before using this function. */\n  lj_assertX(b != 0, \"modulo with zero divisor\");\n  ua = a < 0 ? (uint32_t)-a : (uint32_t)a;\n  ub = b < 0 ? (uint32_t)-b : (uint32_t)b;\n  y = ua % ub;\n  if (y != 0 && (a^b) < 0) y = y - ub;\n  if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y;\n  return (int32_t)y;\n}\n#endif\n\n#if LJ_HASJIT\n\n#ifdef LUAJIT_NO_LOG2\ndouble lj_vm_log2(double a)\n{\n  return log(a) * 1.4426950408889634074;\n}\n#endif\n\n#if !LJ_TARGET_X86ORX64\n/* Unsigned x^k. */\nstatic double lj_vm_powui(double x, uint32_t k)\n{\n  double y;\n  lj_assertX(k != 0, \"pow with zero exponent\");\n  for (; (k & 1) == 0; k >>= 1) x *= x;\n  y = x;\n  if ((k >>= 1) != 0) {\n    for (;;) {\n      x *= x;\n      if (k == 1) break;\n      if (k & 1) y *= x;\n      k >>= 1;\n    }\n    y *= x;\n  }\n  return y;\n}\n\n/* Signed x^k. */\ndouble lj_vm_powi(double x, int32_t k)\n{\n  if (k > 1)\n    return lj_vm_powui(x, (uint32_t)k);\n  else if (k == 1)\n    return x;\n  else if (k == 0)\n    return 1.0;\n  else\n    return 1.0 / lj_vm_powui(x, (uint32_t)-k);\n}\n#endif\n\n/* Computes fpm(x) for extended math functions. */\ndouble lj_vm_foldfpm(double x, int fpm)\n{\n  switch (fpm) {\n  case IRFPM_FLOOR: return lj_vm_floor(x);\n  case IRFPM_CEIL: return lj_vm_ceil(x);\n  case IRFPM_TRUNC: return lj_vm_trunc(x);\n  case IRFPM_SQRT: return sqrt(x);\n  case IRFPM_LOG: return log(x);\n  case IRFPM_LOG2: return lj_vm_log2(x);\n  default: lj_assertX(0, \"bad fpm %d\", fpm);\n  }\n  return 0;\n}\n\n#if LJ_HASFFI\nint lj_vm_errno(void)\n{\n  return errno;\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/ljamalg.c",
    "content": "/*\n** LuaJIT core and libraries amalgamation.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#define ljamalg_c\n#define LUA_CORE\n\n/* To get the mremap prototype. Must be defined before any system includes. */\n#if defined(__linux__) && !defined(_GNU_SOURCE)\n#define _GNU_SOURCE\n#endif\n\n#ifndef WINVER\n#define WINVER 0x0501\n#endif\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"lj_assert.c\"\n#include \"lj_gc.c\"\n#include \"lj_err.c\"\n#include \"lj_char.c\"\n#include \"lj_bc.c\"\n#include \"lj_obj.c\"\n#include \"lj_buf.c\"\n#include \"lj_str.c\"\n#include \"lj_tab.c\"\n#include \"lj_func.c\"\n#include \"lj_udata.c\"\n#include \"lj_meta.c\"\n#include \"lj_debug.c\"\n#include \"lj_prng.c\"\n#include \"lj_state.c\"\n#include \"lj_dispatch.c\"\n#include \"lj_vmevent.c\"\n#include \"lj_vmmath.c\"\n#include \"lj_strscan.c\"\n#include \"lj_strfmt.c\"\n#include \"lj_strfmt_num.c\"\n#include \"lj_serialize.c\"\n#include \"lj_api.c\"\n#include \"lj_profile.c\"\n#include \"lj_lex.c\"\n#include \"lj_parse.c\"\n#include \"lj_bcread.c\"\n#include \"lj_bcwrite.c\"\n#include \"lj_load.c\"\n#include \"lj_ctype.c\"\n#include \"lj_cdata.c\"\n#include \"lj_cconv.c\"\n#include \"lj_ccall.c\"\n#include \"lj_ccallback.c\"\n#include \"lj_carith.c\"\n#include \"lj_clib.c\"\n#include \"lj_cparse.c\"\n#include \"lj_lib.c\"\n#include \"lj_ir.c\"\n#include \"lj_opt_mem.c\"\n#include \"lj_opt_fold.c\"\n#include \"lj_opt_narrow.c\"\n#include \"lj_opt_dce.c\"\n#include \"lj_opt_loop.c\"\n#include \"lj_opt_split.c\"\n#include \"lj_opt_sink.c\"\n#include \"lj_mcode.c\"\n#include \"lj_snap.c\"\n#include \"lj_record.c\"\n#include \"lj_crecord.c\"\n#include \"lj_ffrecord.c\"\n#include \"lj_asm.c\"\n#include \"lj_trace.c\"\n#include \"lj_gdbjit.c\"\n#include \"lj_alloc.c\"\n\n#include \"lib_aux.c\"\n#include \"lib_base.c\"\n#include \"lib_math.c\"\n#include \"lib_string.c\"\n#include \"lib_table.c\"\n#include \"lib_io.c\"\n#include \"lib_os.c\"\n#include \"lib_package.c\"\n#include \"lib_debug.c\"\n#include \"lib_bit.c\"\n#include \"lib_jit.c\"\n#include \"lib_ffi.c\"\n#include \"lib_buffer.c\"\n#include \"lib_init.c\"\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $\n** Lua - An Extensible Extension Language\n** Lua.org, PUC-Rio, Brazil (https://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION\t\"Lua 5.1\"\n#define LUA_RELEASE\t\"Lua 5.1.4\"\n#define LUA_VERSION_NUM\t501\n#define LUA_COPYRIGHT\t\"Copyright (C) 1994-2008 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS\t\"R. Ierusalimschy, L. H. de Figueiredo & W. Celes\"\n\n\n/* mark for precompiled code (`<esc>Lua') */\n#define\tLUA_SIGNATURE\t\"\\033Lua\"\n\n/* option for multiple returns in `lua_pcall' and `lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** pseudo-indices\n*/\n#define LUA_REGISTRYINDEX\t(-10000)\n#define LUA_ENVIRONINDEX\t(-10001)\n#define LUA_GLOBALSINDEX\t(-10002)\n#define lua_upvalueindex(i)\t(LUA_GLOBALSINDEX-(i))\n\n\n/* thread status */\n#define LUA_OK\t\t0\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\n\ntypedef int (*lua_CFunction) (lua_State *L);\n\n\n/*\n** functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);\n\n\n/*\n** prototype for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_remove) (lua_State *L, int idx);\nLUA_API void  (lua_insert) (lua_State *L, int idx);\nLUA_API void  (lua_replace) (lua_State *L, int idx);\nLUA_API int   (lua_checkstack) (lua_State *L, int sz);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);\n\nLUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);\nLUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_objlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void  (lua_pushnil) (lua_State *L);\nLUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);\nLUA_API void  (lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API void  (lua_gettable) (lua_State *L, int idx);\nLUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawget) (lua_State *L, int idx);\nLUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_getfenv) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setfenv) (lua_State *L, int idx);\n\n\n/*\n** `load' and `call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);\nLUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);\nLUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                                        const char *chunkname);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yield) (lua_State *L, int nresults);\nLUA_API int  (lua_resume) (lua_State *L, int narg);\nLUA_API int  (lua_status) (lua_State *L);\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCISRUNNING\t\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_strlen(L,i)\t\tlua_objlen(L, (i))\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\t\\\n\tlua_pushlstring(L, \"\" s, (sizeof(s)/sizeof(char))-1)\n\n#define lua_setglobal(L,s)\tlua_setfield(L, LUA_GLOBALSINDEX, (s))\n#define lua_getglobal(L,s)\tlua_getfield(L, LUA_GLOBALSINDEX, (s))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n\n/*\n** compatibility macros and functions\n*/\n\n#define lua_open()\tluaL_newstate()\n\n#define lua_getregistry(L)\tlua_pushvalue(L, LUA_REGISTRYINDEX)\n\n#define lua_getgccount(L)\tlua_gc(L, LUA_GCCOUNT, 0)\n\n#define lua_Chunkreader\t\tlua_Reader\n#define lua_Chunkwriter\t\tlua_Writer\n\n\n/* hack */\nLUA_API void lua_setlevel\t(lua_State *from, lua_State *to);\n\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILRET 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debuger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook lua_gethook (lua_State *L);\nLUA_API int lua_gethookmask (lua_State *L);\nLUA_API int lua_gethookcount (lua_State *L);\n\n/* From Lua 5.2. */\nLUA_API void *lua_upvalueid (lua_State *L, int idx, int n);\nLUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);\nLUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,\n\t\t       const char *chunkname, const char *mode);\nLUA_API const lua_Number *lua_version (lua_State *L);\nLUA_API void lua_copy (lua_State *L, int fromidx, int toidx);\nLUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum);\nLUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum);\n\n/* From Lua 5.3. */\nLUA_API int lua_isyieldable (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) `global', `local', `field', `method' */\n  const char *what;\t/* (S) `Lua', `C', `main', `tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int nups;\t\t/* (u) number of upvalues */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  int i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lua.hpp",
    "content": "// C++ wrapper for LuaJIT header files.\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include \"luajit.h\"\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/luaconf.h",
    "content": "/*\n** Configuration header.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef luaconf_h\n#define luaconf_h\n\n#ifndef WINVER\n#define WINVER 0x0501\n#endif\n#include <limits.h>\n#include <stddef.h>\n\n/* Default path for loading Lua and C modules with require(). */\n#if defined(_WIN32)\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_PATH_DEFAULT \\\n  \".\\\\?.lua;\" LUA_LDIR\"?.lua;\" LUA_LDIR\"?\\\\init.lua;\"\n#define LUA_CPATH_DEFAULT \\\n  \".\\\\?.dll;\" LUA_CDIR\"?.dll;\" LUA_CDIR\"loadall.dll\"\n#else\n/*\n** Note to distribution maintainers: do NOT patch the following lines!\n** Please read ../doc/install.html#distro and pass PREFIX=/usr instead.\n*/\n#ifndef LUA_MULTILIB\n#define LUA_MULTILIB\t\"lib\"\n#endif\n#ifndef LUA_LMULTILIB\n#define LUA_LMULTILIB\t\"lib\"\n#endif\n#define LUA_LROOT\t\"/usr/local\"\n#define LUA_LUADIR\t\"/lua/5.1/\"\n#define LUA_LJDIR\t\"/luajit-2.1.0-beta3/\"\n\n#ifdef LUA_ROOT\n#define LUA_JROOT\tLUA_ROOT\n#define LUA_RLDIR\tLUA_ROOT \"/share\" LUA_LUADIR\n#define LUA_RCDIR\tLUA_ROOT \"/\" LUA_MULTILIB LUA_LUADIR\n#define LUA_RLPATH\t\";\" LUA_RLDIR \"?.lua;\" LUA_RLDIR \"?/init.lua\"\n#define LUA_RCPATH\t\";\" LUA_RCDIR \"?.so\"\n#else\n#define LUA_JROOT\tLUA_LROOT\n#define LUA_RLPATH\n#define LUA_RCPATH\n#endif\n\n#define LUA_JPATH\t\";\" LUA_JROOT \"/share\" LUA_LJDIR \"?.lua\"\n#define LUA_LLDIR\tLUA_LROOT \"/share\" LUA_LUADIR\n#define LUA_LCDIR\tLUA_LROOT \"/\" LUA_LMULTILIB LUA_LUADIR\n#define LUA_LLPATH\t\";\" LUA_LLDIR \"?.lua;\" LUA_LLDIR \"?/init.lua\"\n#define LUA_LCPATH1\t\";\" LUA_LCDIR \"?.so\"\n#define LUA_LCPATH2\t\";\" LUA_LCDIR \"loadall.so\"\n\n#define LUA_PATH_DEFAULT\t\"./?.lua\" LUA_JPATH LUA_LLPATH LUA_RLPATH\n#define LUA_CPATH_DEFAULT\t\"./?.so\" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2\n#endif\n\n/* Environment variable names for path overrides and initialization code. */\n#define LUA_PATH\t\"LUA_PATH\"\n#define LUA_CPATH\t\"LUA_CPATH\"\n#define LUA_INIT\t\"LUA_INIT\"\n\n/* Special file system characters. */\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n#define LUA_PATHSEP\t\";\"\n#define LUA_PATH_MARK\t\"?\"\n#define LUA_EXECDIR\t\"!\"\n#define LUA_IGMARK\t\"-\"\n#define LUA_PATH_CONFIG \\\n  LUA_DIRSEP \"\\n\" LUA_PATHSEP \"\\n\" LUA_PATH_MARK \"\\n\" \\\n  LUA_EXECDIR \"\\n\" LUA_IGMARK \"\\n\"\n\n/* Quoting in error messages. */\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n/* Various tunables. */\n#define LUAI_MAXSTACK\t65500\t/* Max. # of stack slots for a thread (<64K). */\n#define LUAI_MAXCSTACK\t8000\t/* Max. # of stack slots for a C func (<10K). */\n#define LUAI_GCPAUSE\t200\t/* Pause GC until memory is at 200%. */\n#define LUAI_GCMUL\t200\t/* Run GC at 200% of allocation speed. */\n#define LUA_MAXCAPTURES\t32\t/* Max. pattern captures. */\n\n/* Configuration for the frontend (the luajit executable). */\n#if defined(luajit_c)\n#define LUA_PROGNAME\t\"luajit\"  /* Fallback frontend name. */\n#define LUA_PROMPT\t\"> \"\t/* Interactive prompt. */\n#define LUA_PROMPT2\t\">> \"\t/* Continuation prompt. */\n#define LUA_MAXINPUT\t512\t/* Max. input line length. */\n#endif\n\n/* Note: changing the following defines breaks the Lua 5.1 ABI. */\n#define LUA_INTEGER\tptrdiff_t\n#define LUA_IDSIZE\t60\t/* Size of lua_Debug.short_src. */\n/*\n** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using\n** unreasonable amounts of stack space, but still retain ABI compatibility.\n** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it.\n*/\n#define LUAL_BUFFERSIZE\t(BUFSIZ > 16384 ? 8192 : BUFSIZ)\n\n/* The following defines are here only for compatibility with luaconf.h\n** from the standard Lua distribution. They must not be changed for LuaJIT.\n*/\n#define LUA_NUMBER_DOUBLE\n#define LUA_NUMBER\t\tdouble\n#define LUAI_UACNUMBER\t\tdouble\n#define LUA_NUMBER_SCAN\t\t\"%lf\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n#define lua_number2str(s, n)\tsprintf((s), LUA_NUMBER_FMT, (n))\n#define LUAI_MAXNUMBER2STR\t32\n#define LUA_INTFRMLEN\t\t\"l\"\n#define LUA_INTFRM_T\t\tlong\n\n/* Linkage of public API functions. */\n#if defined(LUA_BUILD_AS_DLL)\n#if defined(LUA_CORE) || defined(LUA_LIB)\n#define LUA_API\t\t__declspec(dllexport)\n#else\n#define LUA_API\t\t__declspec(dllimport)\n#endif\n#else\n#define LUA_API\t\textern\n#endif\n\n#define LUALIB_API\tLUA_API\n\n/* Compatibility support for assertions. */\n#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)\n#include <assert.h>\n#endif\n#ifdef LUA_USE_ASSERT\n#define lua_assert(x)\t\tassert(x)\n#endif\n#ifdef LUA_USE_APICHECK\n#define luai_apicheck(L, o)\t{ (void)L; assert(o); }\n#else\n#define luai_apicheck(L, o)\t{ (void)L; }\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/luajit.c",
    "content": "/*\n** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n**\n** Major portions taken verbatim or adapted from the Lua interpreter.\n** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define luajit_c\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include \"luajit.h\"\n\n#include \"lj_arch.h\"\n\n#if LJ_TARGET_POSIX\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n#elif LJ_TARGET_WINDOWS\n#include <io.h>\n#ifdef __BORLANDC__\n#define lua_stdin_is_tty()\tisatty(_fileno(stdin))\n#else\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n#endif\n#else\n#define lua_stdin_is_tty()\t1\n#endif\n\n#if !LJ_TARGET_CONSOLE\n#include <signal.h>\n#endif\n\nstatic lua_State *globalL = NULL;\nstatic const char *progname = LUA_PROGNAME;\n\n#if !LJ_TARGET_CONSOLE\nstatic void lstop(lua_State *L, lua_Debug *ar)\n{\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);\n  /* Avoid luaL_error -- a C hook doesn't add an extra frame. */\n  luaL_where(L, 0);\n  lua_pushfstring(L, \"%sinterrupted!\", lua_tostring(L, -1));\n  lua_error(L);\n}\n\nstatic void laction(int i)\n{\n  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,\n\t\t\t terminate process (default action) */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n#endif\n\nstatic void print_usage(void)\n{\n  fputs(\"usage: \", stderr);\n  fputs(progname, stderr);\n  fputs(\" [options]... [script [args]...].\\n\"\n  \"Available options are:\\n\"\n  \"  -e chunk  Execute string \" LUA_QL(\"chunk\") \".\\n\"\n  \"  -l name   Require library \" LUA_QL(\"name\") \".\\n\"\n  \"  -b ...    Save or list bytecode.\\n\"\n  \"  -j cmd    Perform LuaJIT control command.\\n\"\n  \"  -O[opt]   Control LuaJIT optimizations.\\n\"\n  \"  -i        Enter interactive mode after executing \" LUA_QL(\"script\") \".\\n\"\n  \"  -v        Show version information.\\n\"\n  \"  -E        Ignore environment variables.\\n\"\n  \"  --        Stop handling options.\\n\"\n  \"  -         Execute stdin and stop handling options.\\n\", stderr);\n  fflush(stderr);\n}\n\nstatic void l_message(const char *pname, const char *msg)\n{\n  if (pname) { fputs(pname, stderr); fputc(':', stderr); fputc(' ', stderr); }\n  fputs(msg, stderr); fputc('\\n', stderr);\n  fflush(stderr);\n}\n\nstatic int report(lua_State *L, int status)\n{\n  if (status && !lua_isnil(L, -1)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg == NULL) msg = \"(error object is not a string)\";\n    l_message(progname, msg);\n    lua_pop(L, 1);\n  }\n  return status;\n}\n\nstatic int traceback(lua_State *L)\n{\n  if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */\n    if (lua_isnoneornil(L, 1) ||\n\t!luaL_callmeta(L, 1, \"__tostring\") ||\n\t!lua_isstring(L, -1))\n      return 1;  /* Return non-string error object. */\n    lua_remove(L, 1);  /* Replace object by result of __tostring metamethod. */\n  }\n  luaL_traceback(L, L, lua_tostring(L, 1), 1);\n  return 1;\n}\n\nstatic int docall(lua_State *L, int narg, int clear)\n{\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, traceback);  /* push traceback function */\n  lua_insert(L, base);  /* put it under chunk and args */\n#if !LJ_TARGET_CONSOLE\n  signal(SIGINT, laction);\n#endif\n  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n#if !LJ_TARGET_CONSOLE\n  signal(SIGINT, SIG_DFL);\n#endif\n  lua_remove(L, base);  /* remove traceback function */\n  /* force a complete garbage collection in case of errors */\n  if (status != LUA_OK) lua_gc(L, LUA_GCCOLLECT, 0);\n  return status;\n}\n\nstatic void print_version(void)\n{\n  fputs(LUAJIT_VERSION \" -- \" LUAJIT_COPYRIGHT \". \" LUAJIT_URL \"\\n\", stdout);\n}\n\nstatic void print_jit_status(lua_State *L)\n{\n  int n;\n  const char *s;\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit\");  /* Get jit.* module table. */\n  lua_remove(L, -2);\n  lua_getfield(L, -1, \"status\");\n  lua_remove(L, -2);\n  n = lua_gettop(L);\n  lua_call(L, 0, LUA_MULTRET);\n  fputs(lua_toboolean(L, n) ? \"JIT: ON\" : \"JIT: OFF\", stdout);\n  for (n++; (s = lua_tostring(L, n)); n++) {\n    putc(' ', stdout);\n    fputs(s, stdout);\n  }\n  putc('\\n', stdout);\n  lua_settop(L, 0);  /* clear stack */\n}\n\nstatic void createargtable(lua_State *L, char **argv, int argc, int argf)\n{\n  int i;\n  lua_createtable(L, argc - argf, argf);\n  for (i = 0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - argf);\n  }\n  lua_setglobal(L, \"arg\");\n}\n\nstatic int dofile(lua_State *L, const char *name)\n{\n  int status = luaL_loadfile(L, name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\nstatic int dostring(lua_State *L, const char *s, const char *name)\n{\n  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\nstatic int dolibrary(lua_State *L, const char *name)\n{\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  return report(L, docall(L, 1, 1));\n}\n\nstatic void write_prompt(lua_State *L, int firstline)\n{\n  const char *p;\n  lua_getfield(L, LUA_GLOBALSINDEX, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2;\n  fputs(p, stdout);\n  fflush(stdout);\n  lua_pop(L, 1);  /* remove global */\n}\n\nstatic int incomplete(lua_State *L, int status)\n{\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    const char *tp = msg + lmsg - (sizeof(LUA_QL(\"<eof>\")) - 1);\n    if (strstr(msg, LUA_QL(\"<eof>\")) == tp) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\nstatic int pushline(lua_State *L, int firstline)\n{\n  char buf[LUA_MAXINPUT];\n  write_prompt(L, firstline);\n  if (fgets(buf, LUA_MAXINPUT, stdin)) {\n    size_t len = strlen(buf);\n    if (len > 0 && buf[len-1] == '\\n')\n      buf[len-1] = '\\0';\n    if (firstline && buf[0] == '=')\n      lua_pushfstring(L, \"return %s\", buf+1);\n    else\n      lua_pushstring(L, buf);\n    return 1;\n  }\n  return 0;\n}\n\nstatic int loadline(lua_State *L)\n{\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  for (;;) {  /* repeat until gets a complete line */\n    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), \"=stdin\");\n    if (!incomplete(L, status)) break;  /* cannot try to add lines? */\n    if (!pushline(L, 0))  /* no more input? */\n      return -1;\n    lua_pushliteral(L, \"\\n\");  /* add a new line... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n  lua_remove(L, 1);  /* remove line */\n  return status;\n}\n\nstatic void dotty(lua_State *L)\n{\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;\n  while ((status = loadline(L)) != -1) {\n    if (status == LUA_OK) status = docall(L, 0, 0);\n    report(L, status);\n    if (status == LUA_OK && lua_gettop(L) > 0) {  /* any result to print? */\n      lua_getglobal(L, \"print\");\n      lua_insert(L, 1);\n      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)\n\tl_message(progname,\n\t  lua_pushfstring(L, \"error calling \" LUA_QL(\"print\") \" (%s)\",\n\t\t\t      lua_tostring(L, -1)));\n    }\n  }\n  lua_settop(L, 0);  /* clear stack */\n  fputs(\"\\n\", stdout);\n  fflush(stdout);\n  progname = oldprogname;\n}\n\nstatic int handle_script(lua_State *L, char **argx)\n{\n  int status;\n  const char *fname = argx[0];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argx[-1], \"--\") != 0)\n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  if (status == LUA_OK) {\n    /* Fetch args from arg table. LUA_INIT or -e might have changed them. */\n    int narg = 0;\n    lua_getglobal(L, \"arg\");\n    if (lua_istable(L, -1)) {\n      do {\n\tnarg++;\n\tlua_rawgeti(L, -narg, narg);\n      } while (!lua_isnil(L, -1));\n      lua_pop(L, 1);\n      lua_remove(L, -narg);\n      narg--;\n    } else {\n      lua_pop(L, 1);\n    }\n    status = docall(L, narg, 0);\n  }\n  return report(L, status);\n}\n\n/* Load add-on module. */\nstatic int loadjitmodule(lua_State *L)\n{\n  lua_getglobal(L, \"require\");\n  lua_pushliteral(L, \"jit.\");\n  lua_pushvalue(L, -3);\n  lua_concat(L, 2);\n  if (lua_pcall(L, 1, 1, 0)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg && !strncmp(msg, \"module \", 7))\n      goto nomodule;\n    return report(L, 1);\n  }\n  lua_getfield(L, -1, \"start\");\n  if (lua_isnil(L, -1)) {\n  nomodule:\n    l_message(progname,\n\t      \"unknown luaJIT command or jit.* modules not installed\");\n    return 1;\n  }\n  lua_remove(L, -2);  /* Drop module table. */\n  return 0;\n}\n\n/* Run command with options. */\nstatic int runcmdopt(lua_State *L, const char *opt)\n{\n  int narg = 0;\n  if (opt && *opt) {\n    for (;;) {  /* Split arguments. */\n      const char *p = strchr(opt, ',');\n      narg++;\n      if (!p) break;\n      if (p == opt)\n\tlua_pushnil(L);\n      else\n\tlua_pushlstring(L, opt, (size_t)(p - opt));\n      opt = p + 1;\n    }\n    if (*opt)\n      lua_pushstring(L, opt);\n    else\n      lua_pushnil(L);\n  }\n  return report(L, lua_pcall(L, narg, 0, 0));\n}\n\n/* JIT engine control command: try jit library first or load add-on module. */\nstatic int dojitcmd(lua_State *L, const char *cmd)\n{\n  const char *opt = strchr(cmd, '=');\n  lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd));\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit\");  /* Get jit.* module table. */\n  lua_remove(L, -2);\n  lua_pushvalue(L, -2);\n  lua_gettable(L, -2);  /* Lookup library function. */\n  if (!lua_isfunction(L, -1)) {\n    lua_pop(L, 2);  /* Drop non-function and jit.* table, keep module name. */\n    if (loadjitmodule(L))\n      return 1;\n  } else {\n    lua_remove(L, -2);  /* Drop jit.* table. */\n  }\n  lua_remove(L, -2);  /* Drop module name. */\n  return runcmdopt(L, opt ? opt+1 : opt);\n}\n\n/* Optimization flags. */\nstatic int dojitopt(lua_State *L, const char *opt)\n{\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, -1, \"jit.opt\");  /* Get jit.opt.* module table. */\n  lua_remove(L, -2);\n  lua_getfield(L, -1, \"start\");\n  lua_remove(L, -2);\n  return runcmdopt(L, opt);\n}\n\n/* Save or list bytecode. */\nstatic int dobytecode(lua_State *L, char **argv)\n{\n  int narg = 0;\n  lua_pushliteral(L, \"bcsave\");\n  if (loadjitmodule(L))\n    return 1;\n  if (argv[0][2]) {\n    narg++;\n    argv[0][1] = '-';\n    lua_pushstring(L, argv[0]+1);\n  }\n  for (argv++; *argv != NULL; narg++, argv++)\n    lua_pushstring(L, *argv);\n  report(L, lua_pcall(L, narg, 0, 0));\n  return -1;\n}\n\n/* check that argument has no extra characters at the end */\n#define notail(x)\t{if ((x)[2] != '\\0') return -1;}\n\n#define FLAGS_INTERACTIVE\t1\n#define FLAGS_VERSION\t\t2\n#define FLAGS_EXEC\t\t4\n#define FLAGS_OPTION\t\t8\n#define FLAGS_NOENV\t\t16\n\nstatic int collectargs(char **argv, int *flags)\n{\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    if (argv[i][0] != '-')  /* Not an option? */\n      return i;\n    switch (argv[i][1]) {  /* Check option. */\n    case '-':\n      notail(argv[i]);\n      return i+1;\n    case '\\0':\n      return i;\n    case 'i':\n      notail(argv[i]);\n      *flags |= FLAGS_INTERACTIVE;\n      /* fallthrough */\n    case 'v':\n      notail(argv[i]);\n      *flags |= FLAGS_VERSION;\n      break;\n    case 'e':\n      *flags |= FLAGS_EXEC;\n      /* fallthrough */\n    case 'j':  /* LuaJIT extension */\n    case 'l':\n      *flags |= FLAGS_OPTION;\n      if (argv[i][2] == '\\0') {\n\ti++;\n\tif (argv[i] == NULL) return -1;\n      }\n      break;\n    case 'O': break;  /* LuaJIT extension */\n    case 'b':  /* LuaJIT extension */\n      if (*flags) return -1;\n      *flags |= FLAGS_EXEC;\n      return i+1;\n    case 'E':\n      *flags |= FLAGS_NOENV;\n      break;\n    default: return -1;  /* invalid option */\n    }\n  }\n  return i;\n}\n\nstatic int runargs(lua_State *L, char **argv, int argn)\n{\n  int i;\n  for (i = 1; i < argn; i++) {\n    if (argv[i] == NULL) continue;\n    lua_assert(argv[i][0] == '-');\n    switch (argv[i][1]) {\n    case 'e': {\n      const char *chunk = argv[i] + 2;\n      if (*chunk == '\\0') chunk = argv[++i];\n      lua_assert(chunk != NULL);\n      if (dostring(L, chunk, \"=(command line)\") != 0)\n\treturn 1;\n      break;\n      }\n    case 'l': {\n      const char *filename = argv[i] + 2;\n      if (*filename == '\\0') filename = argv[++i];\n      lua_assert(filename != NULL);\n      if (dolibrary(L, filename))\n\treturn 1;\n      break;\n      }\n    case 'j': {  /* LuaJIT extension. */\n      const char *cmd = argv[i] + 2;\n      if (*cmd == '\\0') cmd = argv[++i];\n      lua_assert(cmd != NULL);\n      if (dojitcmd(L, cmd))\n\treturn 1;\n      break;\n      }\n    case 'O':  /* LuaJIT extension. */\n      if (dojitopt(L, argv[i] + 2))\n\treturn 1;\n      break;\n    case 'b':  /* LuaJIT extension. */\n      return dobytecode(L, argv+i);\n    default: break;\n    }\n  }\n  return LUA_OK;\n}\n\nstatic int handle_luainit(lua_State *L)\n{\n#if LJ_TARGET_CONSOLE\n  const char *init = NULL;\n#else\n  const char *init = getenv(LUA_INIT);\n#endif\n  if (init == NULL)\n    return LUA_OK;\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, \"=\" LUA_INIT);\n}\n\nstatic struct Smain {\n  char **argv;\n  int argc;\n  int status;\n} smain;\n\nstatic int pmain(lua_State *L)\n{\n  struct Smain *s = &smain;\n  char **argv = s->argv;\n  int argn;\n  int flags = 0;\n  globalL = L;\n  if (argv[0] && argv[0][0]) progname = argv[0];\n\n  LUAJIT_VERSION_SYM();  /* Linker-enforced version check. */\n\n  argn = collectargs(argv, &flags);\n  if (argn < 0) {  /* Invalid args? */\n    print_usage();\n    s->status = 1;\n    return 0;\n  }\n\n  if ((flags & FLAGS_NOENV)) {\n    lua_pushboolean(L, 1);\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_NOENV\");\n  }\n\n  /* Stop collector during library initialization. */\n  lua_gc(L, LUA_GCSTOP, 0);\n  luaL_openlibs(L);\n  lua_gc(L, LUA_GCRESTART, -1);\n\n  createargtable(L, argv, s->argc, argn);\n\n  if (!(flags & FLAGS_NOENV)) {\n    s->status = handle_luainit(L);\n    if (s->status != LUA_OK) return 0;\n  }\n\n  if ((flags & FLAGS_VERSION)) print_version();\n\n  s->status = runargs(L, argv, argn);\n  if (s->status != LUA_OK) return 0;\n\n  if (s->argc > argn) {\n    s->status = handle_script(L, argv + argn);\n    if (s->status != LUA_OK) return 0;\n  }\n\n  if ((flags & FLAGS_INTERACTIVE)) {\n    print_jit_status(L);\n    dotty(L);\n  } else if (s->argc == argn && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {\n    if (lua_stdin_is_tty()) {\n      print_version();\n      print_jit_status(L);\n      dotty(L);\n    } else {\n      dofile(L, NULL);  /* Executes stdin as a file. */\n    }\n  }\n  return 0;\n}\n\nint main(int argc, char **argv)\n{\n  int status;\n  lua_State *L = lua_open();\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  smain.argc = argc;\n  smain.argv = argv;\n  status = lua_cpcall(L, pmain, NULL);\n  report(L, status);\n  lua_close(L);\n  return (status || smain.status > 0) ? EXIT_FAILURE : EXIT_SUCCESS;\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/luajit.h",
    "content": "/*\n** LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/\n**\n** Copyright (C) 2005-2021 Mike Pall. All rights reserved.\n**\n** Permission is hereby granted, free of charge, to any person obtaining\n** a copy of this software and associated documentation files (the\n** \"Software\"), to deal in the Software without restriction, including\n** without limitation the rights to use, copy, modify, merge, publish,\n** distribute, sublicense, and/or sell copies of the Software, and to\n** permit persons to whom the Software is furnished to do so, subject to\n** the following conditions:\n**\n** The above copyright notice and this permission notice shall be\n** included in all copies or substantial portions of the Software.\n**\n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n**\n** [ MIT license: https://www.opensource.org/licenses/mit-license.php ]\n*/\n\n#ifndef _LUAJIT_H\n#define _LUAJIT_H\n\n#include \"lua.h\"\n\n#define LUAJIT_VERSION\t\t\"LuaJIT 2.1.0-beta3\"\n#define LUAJIT_VERSION_NUM\t20100  /* Version 2.1.0 = 02.01.00. */\n#define LUAJIT_VERSION_SYM\tluaJIT_version_2_1_0_beta3\n#define LUAJIT_COPYRIGHT\t\"Copyright (C) 2005-2021 Mike Pall\"\n#define LUAJIT_URL\t\t\"https://luajit.org/\"\n\n/* Modes for luaJIT_setmode. */\n#define LUAJIT_MODE_MASK\t0x00ff\n\nenum {\n  LUAJIT_MODE_ENGINE,\t\t/* Set mode for whole JIT engine. */\n  LUAJIT_MODE_DEBUG,\t\t/* Set debug mode (idx = level). */\n\n  LUAJIT_MODE_FUNC,\t\t/* Change mode for a function. */\n  LUAJIT_MODE_ALLFUNC,\t\t/* Recurse into subroutine protos. */\n  LUAJIT_MODE_ALLSUBFUNC,\t/* Change only the subroutines. */\n\n  LUAJIT_MODE_TRACE,\t\t/* Flush a compiled trace. */\n\n  LUAJIT_MODE_WRAPCFUNC = 0x10,\t/* Set wrapper mode for C function calls. */\n\n  LUAJIT_MODE_MAX\n};\n\n/* Flags or'ed in to the mode. */\n#define LUAJIT_MODE_OFF\t\t0x0000\t/* Turn feature off. */\n#define LUAJIT_MODE_ON\t\t0x0100\t/* Turn feature on. */\n#define LUAJIT_MODE_FLUSH\t0x0200\t/* Flush JIT-compiled code. */\n\n/* LuaJIT public C API. */\n\n/* Control the JIT engine. */\nLUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);\n\n/* Low-overhead profiling API. */\ntypedef void (*luaJIT_profile_callback)(void *data, lua_State *L,\n\t\t\t\t\tint samples, int vmstate);\nLUA_API void luaJIT_profile_start(lua_State *L, const char *mode,\n\t\t\t\t  luaJIT_profile_callback cb, void *data);\nLUA_API void luaJIT_profile_stop(lua_State *L);\nLUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt,\n\t\t\t\t\t     int depth, size_t *len);\n\n/* Enforce (dynamic) linker error for version mismatches. Call from main. */\nLUA_API void LUAJIT_VERSION_SYM(void);\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/lualib.h",
    "content": "/*\n** Standard library header.\n** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n*/\n\n#ifndef _LUALIB_H\n#define _LUALIB_H\n\n#include \"lua.h\"\n\n#define LUA_FILEHANDLE\t\"FILE*\"\n\n#define LUA_COLIBNAME\t\"coroutine\"\n#define LUA_MATHLIBNAME\t\"math\"\n#define LUA_STRLIBNAME\t\"string\"\n#define LUA_TABLIBNAME\t\"table\"\n#define LUA_IOLIBNAME\t\"io\"\n#define LUA_OSLIBNAME\t\"os\"\n#define LUA_LOADLIBNAME\t\"package\"\n#define LUA_DBLIBNAME\t\"debug\"\n#define LUA_BITLIBNAME\t\"bit\"\n#define LUA_JITLIBNAME\t\"jit\"\n#define LUA_FFILIBNAME\t\"ffi\"\n\nLUALIB_API int luaopen_base(lua_State *L);\nLUALIB_API int luaopen_math(lua_State *L);\nLUALIB_API int luaopen_string(lua_State *L);\nLUALIB_API int luaopen_table(lua_State *L);\nLUALIB_API int luaopen_io(lua_State *L);\nLUALIB_API int luaopen_os(lua_State *L);\nLUALIB_API int luaopen_package(lua_State *L);\nLUALIB_API int luaopen_debug(lua_State *L);\nLUALIB_API int luaopen_bit(lua_State *L);\nLUALIB_API int luaopen_jit(lua_State *L);\nLUALIB_API int luaopen_ffi(lua_State *L);\nLUALIB_API int luaopen_string_buffer(lua_State *L);\n\nLUALIB_API void luaL_openlibs(lua_State *L);\n\n#ifndef lua_assert\n#define lua_assert(x)\t((void)0)\n#endif\n\n#endif\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/msvcbuild.bat",
    "content": "@rem Script to build LuaJIT with MSVC.\r\n@rem Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\r\n@rem\r\n@rem Open a \"Visual Studio Command Prompt\" (either x86 or x64).\r\n@rem Then cd to this directory and run this script. Use the following\r\n@rem options (in order), if needed. The default is a dynamic release build.\r\n@rem\r\n@rem   nogc64   disable LJ_GC64 mode for x64\r\n@rem   debug    emit debug symbols\r\n@rem   amalg    amalgamated build\r\n@rem   static   static linkage\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n\r\n@setlocal\r\n@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_APICHECK\r\n@set DEBUGCFLAGS=\r\n@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set LJLIB=lib /nologo /nodefaultlib\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set DASC=vm_x64.dasc\r\n@set LJDLLNAME=lua51.dll\r\n@set LJLIBNAME=lua51.lib\r\n@set BUILDTYPE=release\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64\r\n@set LJARCH=x64\r\n@minilua\r\n@if errorlevel 8 goto :X64\r\n@set DASC=vm_x86.dasc\r\n@set DASMFLAGS=-D WIN -D JIT -D FFI\r\n@set LJARCH=x86\r\n@set LJCOMPILE=%LJCOMPILE% /arch:SSE2\r\n:X64\r\n@if \"%1\" neq \"nogc64\" goto :GC64\r\n@shift\r\n@set DASC=vm_x86.dasc\r\n@set LJCOMPILE=%LJCOMPILE% /DLUAJIT_DISABLE_GC64\r\n:GC64\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h %DASC%\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m peobj -o lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@if \"%1\" neq \"debug\" goto :NODEBUG\r\n@shift\r\n@set BUILDTYPE=debug\r\n@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS%\r\n@set LJLINK=%LJLINK% /opt:ref /opt:icf /incremental:no\r\n:NODEBUG\r\n@set LJLINK=%LJLINK% /%BUILDTYPE%\r\n@if \"%1\"==\"amalg\" goto :AMALGDLL\r\n@if \"%1\"==\"static\" goto :STATIC\r\n%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :MTDLL\r\n:STATIC\r\n%LJCOMPILE% lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :MTDLL\r\n:AMALGDLL\r\n%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\n:MTDLL\r\nif exist %LJDLLNAME%.manifest^\r\n  %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2\r\n\r\n%LJCOMPILE% luajit.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%\r\n@if errorlevel 1 goto :BAD\r\nif exist luajit.exe.manifest^\r\n  %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe\r\n\r\n@del *.obj *.manifest minilua.exe buildvm.exe\r\n@del host\\buildvm_arch.h\r\n@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h\r\n@echo.\r\n@echo === Successfully built LuaJIT for Windows/%LJARCH% ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\u0007\r\n@goto :END\r\n:FAIL\r\n@echo You must open a \"Visual Studio Command Prompt\" to run this script\r\n:END\r\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/msvcbuild_mt.bat",
    "content": "@rem Script to build LuaJIT with MSVC.\r\n@rem Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h\r\n@rem\r\n@rem Either open a \"Visual Studio .NET Command Prompt\"\r\n@rem (Note that the Express Edition does not contain an x64 compiler)\r\n@rem -or-\r\n@rem Open a \"Windows SDK Command Shell\" and set the compiler environment:\r\n@rem     setenv /release /x86\r\n@rem   -or-\r\n@rem     setenv /release /x64\r\n@rem\r\n@rem Then cd to this directory and run this script.\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n\r\n@setlocal\r\n@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set LJLIB=lib /nologo /nodefaultlib\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set DASC=vm_x86.dasc\r\n@set LJDLLNAME=lua51.dll\r\n@set LJLIBNAME=lua51.lib\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64\r\n@set LJARCH=x64\r\n@minilua\r\n@if errorlevel 8 goto :X64\r\n@set DASMFLAGS=-D WIN -D JIT -D FFI\r\n@set LJARCH=x86\r\n@set LJCOMPILE=%LJCOMPILE% /arch:SSE2\r\n:X64\r\n@if \"%1\" neq \"gc64\" goto :NOGC64\r\n@shift\r\n@set DASC=vm_x64.dasc\r\n@set LJCOMPILE=%LJCOMPILE% /DLUAJIT_ENABLE_GC64\r\n:NOGC64\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h %DASC%\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m peobj -o lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@if \"%1\" neq \"debug\" goto :NODEBUG\r\n@shift\r\n@set LJCOMPILE=%LJCOMPILE% /Zi\r\n@set LJLINK=%LJLINK% /debug /opt:ref /opt:icf /incremental:no\r\n:NODEBUG\r\n@if \"%1\"==\"amalg\" goto :AMALGDLL\r\n@if \"%1\"==\"static\" goto :STATIC\r\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :MTDLL\r\n:STATIC\r\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :MTDLL\r\n:AMALGDLL\r\n%LJCOMPILE% /MT /DLUA_BUILD_AS_DLL ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\n:MTDLL\r\nif exist %LJDLLNAME%.manifest^\r\n  %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2\r\n\r\n%LJCOMPILE% luajit.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%\r\n@if errorlevel 1 goto :BAD\r\nif exist luajit.exe.manifest^\r\n  %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe\r\n\r\n@del *.obj *.manifest minilua.exe buildvm.exe\r\n@del host\\buildvm_arch.h\r\n@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h\r\n@echo.\r\n@echo === Successfully built LuaJIT for Windows/%LJARCH% ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\u0007\r\n@goto :END\r\n:FAIL\r\n@echo You must open a \"Visual Studio .NET Command Prompt\" to run this script\r\n:END\r\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/ps4build.bat",
    "content": "@rem Script to build LuaJIT with the PS4 SDK.\r\n@rem Donated to the public domain.\r\n@rem\r\n@rem Open a \"Visual Studio .NET Command Prompt\" (64 bit host compiler)\r\n@rem or \"VS2015 x64 Native Tools Command Prompt\".\r\n@rem\r\n@rem Then cd to this directory and run this script.\r\n@rem\r\n@rem Recommended invocation:\r\n@rem\r\n@rem ps4build        release build, amalgamated, 64-bit GC\r\n@rem ps4build debug    debug build, amalgamated, 64-bit GC\r\n@rem\r\n@rem Additional command-line options (not generally recommended):\r\n@rem\r\n@rem gc32 (before debug)    32-bit GC\r\n@rem noamalg (after debug)  non-amalgamated build\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n@if not defined SCE_ORBIS_SDK_DIR goto :FAIL\r\n\r\n@setlocal\r\n@rem ---- Host compiler ----\r\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n@set GC64=\r\n@set DASC=vm_x64.dasc\r\n\r\n@if \"%1\" neq \"gc32\" goto :NOGC32\r\n@shift\r\n@set GC64=-DLUAJIT_DISABLE_GC64\r\n@set DASC=vm_x86.dasc\r\n:NOGC32\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@rem Check for 64 bit host compiler.\r\n@minilua\r\n@if not errorlevel 8 goto :FAIL\r\n\r\n@set DASMFLAGS=-D P64 -D NO_UNWIND\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h %DASC%\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% %GC64% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m elfasm -o lj_vm.s\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@rem ---- Cross compiler ----\r\n@set LJCOMPILE=\"%SCE_ORBIS_SDK_DIR%\\host_tools\\bin\\orbis-clang\" -c -Wall -DLUAJIT_DISABLE_FFI %GC64%\r\n@set LJLIB=\"%SCE_ORBIS_SDK_DIR%\\host_tools\\bin\\orbis-ar\" rcus\r\n@set INCLUDE=\"\"\r\n\r\norbis-as -o lj_vm.o lj_vm.s\r\n\r\n@if \"%1\" neq \"debug\" goto :NODEBUG\r\n@shift\r\n@set LJCOMPILE=%LJCOMPILE% -g -O0\r\n@set TARGETLIB=libluajitD_ps4.a\r\ngoto :BUILD\r\n:NODEBUG\r\n@set LJCOMPILE=%LJCOMPILE% -O2\r\n@set TARGETLIB=libluajit_ps4.a\r\n:BUILD\r\ndel %TARGETLIB%\r\n@if \"%1\" neq \"noamalg\" goto :AMALG\r\nfor %%f in (lj_*.c lib_*.c) do (\r\n  %LJCOMPILE% %%f\r\n  @if errorlevel 1 goto :BAD\r\n)\r\n\r\n%LJLIB% %TARGETLIB% lj_*.o lib_*.o\r\n@if errorlevel 1 goto :BAD\r\n@goto :NOAMALG\r\n:AMALG\r\n%LJCOMPILE% ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o\r\n@if errorlevel 1 goto :BAD\r\n:NOAMALG\r\n\r\n@del *.o *.obj *.manifest minilua.exe buildvm.exe\r\n@echo.\r\n@echo === Successfully built LuaJIT for PS4 ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\u0007\r\n@goto :END\r\n:FAIL\r\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\r\n@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too.\r\n:END\r\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/psvitabuild.bat",
    "content": "@rem Script to build LuaJIT with the PS Vita SDK.\r\n@rem Donated to the public domain.\r\n@rem\r\n@rem Open a \"Visual Studio .NET Command Prompt\" (32 bit host compiler)\r\n@rem Then cd to this directory and run this script.\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n@if not defined SCE_PSP2_SDK_DIR goto :FAIL\r\n\r\n@setlocal\r\n@rem ---- Host compiler ----\r\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@rem Check for 32 bit host compiler.\r\n@minilua\r\n@if errorlevel 8 goto :FAIL\r\n\r\n@set DASMFLAGS=-D FPU -D HFABI\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_arm.dasc\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLJ_TARGET_PSVITA=1 host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m elfasm -o lj_vm.s\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@rem ---- Cross compiler ----\r\n@set LJCOMPILE=\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2snc\" -c -w -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC\r\n@set LJLIB=\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2ld32\" -r --output=\r\n@set INCLUDE=\"\"\r\n\r\n\"%SCE_PSP2_SDK_DIR%\\host_tools\\build\\bin\\psp2as\" -o lj_vm.o lj_vm.s\r\n\r\n@if \"%1\" neq \"debug\" goto :NODEBUG\r\n@shift\r\n@set LJCOMPILE=%LJCOMPILE% -g -O0\r\n@set TARGETLIB=libluajitD.a\r\ngoto :BUILD\r\n:NODEBUG\r\n@set LJCOMPILE=%LJCOMPILE% -O2\r\n@set TARGETLIB=libluajit.a\r\n:BUILD\r\ndel %TARGETLIB%\r\n\r\n%LJCOMPILE% ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB%%TARGETLIB% ljamalg.o lj_vm.o\r\n@if errorlevel 1 goto :BAD\r\n\r\n@del *.o *.obj *.manifest minilua.exe buildvm.exe\r\n@echo.\r\n@echo === Successfully built LuaJIT for PS Vita ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\u0007\r\n@goto :END\r\n:FAIL\r\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\r\n@echo (32 bit host compiler). The PS Vita SDK must be installed, too.\r\n:END\r\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_arm.dasc",
    "content": "|// Low-level VM code for ARM CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch arm\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|\n|// The following must be C callee-save.\n|.define MASKR8,\tr4\t// 255*8 constant for fast bytecode decoding.\n|.define KBASE,\t\tr5\t// Constants of current Lua function.\n|.define PC,\t\tr6\t// Next PC.\n|.define DISPATCH,\tr7\t// Opcode dispatch table.\n|.define LREG,\t\tr8\t// Register holding lua_State (also in SAVE_L).\n|\n|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.\n|.define BASE,\t\tr9\t// Base of current Lua stack frame.\n|\n|// The following temporaries are not saved across C calls, except for RA/RC.\n|.define RA,\t\tr10\t// Callee-save.\n|.define RC,\t\tr11\t// Callee-save.\n|.define RB,\t\tr12\n|.define OP,\t\tr12\t// Overlaps RB, must not be lr.\n|.define INS,\t\tlr\n|\n|// Calling conventions. Also used as temporaries.\n|.define CARG1,\t\tr0\n|.define CARG2,\t\tr1\n|.define CARG3,\t\tr2\n|.define CARG4,\t\tr3\n|.define CARG12,\tr0\t// For 1st soft-fp double.\n|.define CARG34,\tr2\t// For 2nd soft-fp double.\n|\n|.define CRET1,\t\tr0\n|.define CRET2,\t\tr1\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.define SAVE_R4,\t[sp, #28]\n|.define CFRAME_SPACE,\t#28\n|.define SAVE_ERRF,\t[sp, #24]\n|.define SAVE_NRES,\t[sp, #20]\n|.define SAVE_CFRAME,\t[sp, #16]\n|.define SAVE_L,\t[sp, #12]\n|.define SAVE_PC,\t[sp, #8]\n|.define SAVE_MULTRES,\t[sp, #4]\n|.define ARG5,\t\t[sp]\n|\n|.define TMPDhi,\t[sp, #4]\n|.define TMPDlo,\t[sp]\n|.define TMPD,\t\t[sp]\n|.define TMPDp,\t\tsp\n|\n|.if FPU\n|.macro saveregs\n|  push {r5, r6, r7, r8, r9, r10, r11, lr}\n|  vpush {d8-d15}\n|  sub sp, sp, CFRAME_SPACE+4\n|  str r4, SAVE_R4\n|.endmacro\n|.macro restoreregs_ret\n|  ldr r4, SAVE_R4\n|  add sp, sp, CFRAME_SPACE+4\n|  vpop {d8-d15}\n|  pop {r5, r6, r7, r8, r9, r10, r11, pc}\n|.endmacro\n|.else\n|.macro saveregs\n|  push {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n|  sub sp, sp, CFRAME_SPACE\n|.endmacro\n|.macro restoreregs_ret\n|  add sp, sp, CFRAME_SPACE\n|  pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}\n|.endmacro\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; ud; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_FUNC,\t#-8\n|.define FRAME_PC,\t#-4\n|\n|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro\n|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro\n|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro\n|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro\n|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  ldrb OP, [PC]\n|.endmacro\n|.macro ins_NEXT2\n|   ldr INS, [PC], #4\n|.endmacro\n|// Instruction decode+dispatch.\n|.macro ins_NEXT3\n|  ldr OP, [DISPATCH, OP, lsl #2]\n|   decode_RA8 RA, INS\n|   decode_RD RC, INS\n|  bx OP\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|  ins_NEXT3\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|  .define ins_next3, ins_NEXT3\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|  .endmacro\n|  .macro ins_next3\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Avoid register name substitution for field name.\n#define field_pc\tpc\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  ldr PC, LFUNC:CARG3->field_pc\n|  ldrb OP, [PC]  // STALL: load PC. early PC.\n|   ldr INS, [PC], #4\n|  ldr OP, [DISPATCH, OP, lsl #2]  // STALL: load OP. early OP.\n|   decode_RA8 RA, INS\n|   add RA, RA, BASE\n|  bx OP\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  str PC, [BASE, FRAME_PC]\n|  ins_callt  // STALL: locked PC.\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro\n|.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro\n|.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta\n|  lsr CARG1, PC, #1\n|  and CARG1, CARG1, #126\n|  sub CARG1, CARG1, #-GG_DISP2HOT\n|  ldrh CARG2, [DISPATCH, CARG1]\n|  subs CARG2, CARG2, #delta\n|  strh CARG2, [DISPATCH, CARG1]\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP\n|  blo ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL\n|  blo ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro\n|.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)]\n|   bic mark, mark, #LJ_GC_BLACK\t\t// black2gray(tab)\n|  str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)]\n|   strb mark, tab->marked\n|  str tmp, tab->gclist\n|.endmacro\n|\n|.macro .IOS, a, b\n|.if IOS\n|  a, b\n|.endif\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n#if !LJ_DUALNUM\n#error \"Only dual-number mode supported for ARM target\"\n#endif\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: RB = previous base.\n  |  tst PC, #FRAME_P\n  |  beq ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  ldr PC, [RB, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   mvn CARG2, #~LJ_TTRUE\n  |  mov BASE, RB\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   str CARG2, [RA, FRAME_PC]\t\t// Prepend true to results.\n  |  sub RA, RA, #8\n  |\n  |->vm_returnc:\n  |  adds RC, RC, #8\t\t\t// RC = (nresults+1)*8.\n  |  mov CRET1, #LUA_YIELD\n  |  beq ->vm_unwind_c_eh\n  |  str RC, SAVE_MULTRES\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return\n  |  // CARG1 = PC & FRAME_TYPE\n  |  bic RB, PC, #FRAME_TYPEP\n  |   cmp CARG1, #FRAME_C\n  |  sub RB, BASE, RB\t\t\t// RB = previous base.\n  |   bne ->vm_returnp\n  |\n  |  str RB, L->base\n  |   ldr KBASE, SAVE_NRES\n  |    mv_vmstate CARG4, C\n  |   sub BASE, BASE, #8\n  |  subs CARG3, RC, #8\n  |   lsl KBASE, KBASE, #3\t\t// KBASE = (nresults_wanted+1)*8\n  |    st_vmstate CARG4\n  |  beq >2\n  |1:\n  |  subs CARG3, CARG3, #8\n  |   ldrd CARG12, [RA], #8\n  |   strd CARG12, [BASE], #8\n  |  bne <1\n  |2:\n  |  cmp KBASE, RC\t\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  str BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  ldr RC, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   mov CRET1, #0\t\t\t// Ok return status for vm_pcall.\n  |  str RC, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs_ret\n  |\n  |6:\n  |  blt >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  ldr CARG3, L->maxstack\n  |   mvn CARG2, #~LJ_TNIL\n  |  cmp BASE, CARG3\n  |  bhs >8\n  |   str CARG2, [BASE, #4]\n  |  add RC, RC, #8\n  |  add BASE, BASE, #8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  sub CARG1, RC, KBASE\n  |  cmp KBASE, #0\t\t\t// LUA_MULTRET+1 case?\n  |  subne BASE, BASE, CARG1\t\t// Either keep top or shrink it.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  str BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |  lsr CARG2, KBASE, #3\n  |  mov CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov sp, CARG1\n  |  mov CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mv_vmstate CARG4, C\n  |  ldr GL:CARG3, L->glref\n  |   str CARG4, GL:CARG3->vmstate\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  bic CARG1, CARG1, #~CFRAME_RAWMASK\t// Use two steps: bic sp is deprecated.\n  |  mov sp, CARG1\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mov MASKR8, #255\n  |    mov RC, #16\t\t\t// 2 results: false + error message.\n  |   lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |  ldr BASE, L->base\n  |   ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |    mvn CARG1, #~LJ_TFALSE\n  |  sub RA, BASE, #8\t\t\t// Results start at BASE-8.\n  |  ldr PC, [BASE, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   add DISPATCH, DISPATCH, #GG_G2DISP\n  |   mv_vmstate CARG2, INTERP\n  |    str CARG1, [BASE, #-4]\t\t// Prepend false to error message.\n  |   st_vmstate CARG2\n  |  b ->vm_returnc\n  |\n  |->vm_unwind_ext:\t\t\t// Complete external unwind.\n#if !LJ_NO_UNWIND\n  |  push {r0, r1, r2, lr}\n  |  bl extern _Unwind_Complete\n  |  ldr r0, [sp]\n  |  bl extern _Unwind_DeleteException\n  |  pop {r0, r1, r2, lr}\n  |  mov r0, r1\n  |  bx r2\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  // CARG1 = L\n  |  mov CARG2, #LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |    mov CARG1, L\n  |  str BASE, L->base\n  |   add PC, PC, #4\t\t\t// Must point after first instruction.\n  |  str RC, L->top\n  |   lsr CARG2, RA, #3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  str PC, SAVE_PC\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |   ldr RC, L->top\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L, CARG1\n  |    ldr DISPATCH, L:CARG1->glref\t// Setup pointer to dispatch table.\n  |  mov BASE, CARG2\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |   str L, SAVE_L\n  |  mov PC, #FRAME_CP\n  |   str CARG3, SAVE_NRES\n  |    add CARG2, sp, #CFRAME_RESUME\n  |  ldrb CARG1, L->status\n  |   str CARG3, SAVE_ERRF\n  |   str L, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   str CARG3, SAVE_CFRAME\n  |  cmp CARG1, #0\n  |    str CARG2, L->cframe\n  |  beq >3\n  |\n  |  // Resume after yield (like a return).\n  |  str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  mov RA, BASE\n  |   ldr BASE, L->base\n  |   ldr CARG1, L->top\n  |    mov MASKR8, #255\n  |     strb CARG3, L->status\n  |   sub RC, CARG1, BASE\n  |  ldr PC, [BASE, FRAME_PC]\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |     mv_vmstate CARG2, INTERP\n  |   add RC, RC, #8\n  |  ands CARG1, PC, #FRAME_TYPE\n  |     st_vmstate CARG2\n  |   str RC, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, #FRAME_CP\n  |  str CARG4, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, #FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  ldr RC, L:CARG1->cframe\n  |   str CARG3, SAVE_NRES\n  |    mov L, CARG1\n  |   str CARG1, SAVE_L\n  |    ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     mov BASE, CARG2\n  |   str CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  str RC, SAVE_CFRAME\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |  str sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  ldr RB, L->base\t\t\t// RB = old base (for vmeta_call).\n  |   ldr CARG1, L->top\n  |    mov MASKR8, #255\n  |  add PC, PC, BASE\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |  sub PC, PC, RB\t\t\t// PC = frame delta + frame type\n  |    mv_vmstate CARG2, INTERP\n  |   sub NARGS8:RC, CARG1, BASE\n  |    st_vmstate CARG2\n  |\n  |->vm_call_dispatch:\n  |  // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  ldrd CARG34, [BASE, FRAME_FUNC]\n  |  checkfunc CARG4, ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L, CARG1\n  |   ldr RA, L:CARG1->stack\n  |  str CARG1, SAVE_L\n  |    ldr DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   ldr RB, L->top\n  |  str CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  ldr RC, L->cframe\n  |    add DISPATCH, DISPATCH, #GG_G2DISP\n  |   sub RA, RA, RB\t\t\t// Compute -savestack(L, L->top).\n  |  mov RB, #0\n  |   str RA, SAVE_NRES\t\t\t// Neg. delta means cframe w/o frame.\n  |  str RB, SAVE_ERRF\t\t\t// No error function.\n  |  str RC, SAVE_CFRAME\n  |  str sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |  blx CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  movs BASE, CRET1\n  |   mov PC, #FRAME_CP\n  |  bne <3\t\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RC = (nresults+1)*8\n  |  ldr LFUNC:CARG3, [RB, FRAME_FUNC]\n  |    ldr CARG1, [BASE, #-16]\t\t// Get continuation.\n  |   mov CARG4, BASE\n  |   mov BASE, RB\t\t\t// Restore caller BASE.\n  |.if FFI\n  |    cmp CARG1, #1\n  |.endif\n  |   ldr PC, [CARG4, #-12]\t\t// Restore PC from [cont|PC].\n  |    mvn INS, #~LJ_TNIL\n  |    add CARG2, RA, RC\n  |    str INS, [CARG2, #-4]\t\t// Ensure one valid arg.\n  |.if FFI\n  |    bls >1\n  |.endif\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  // BASE = base, RA = resultptr, CARG4 = meta base\n  |    bx CARG1\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |  sub CARG4, CARG4, #16\n  |  sub RC, CARG4, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, CARG4 = meta base\n  |  ldr INS, [PC, #-4]\n  |   sub CARG2, CARG4, #16\n  |   ldrd CARG34, [RA]\n  |     str BASE, L->base\n  |  decode_RB8 RC, INS\n  |   decode_RA8 RA, INS\n  |  add CARG1, BASE, RC\n  |  subs CARG1, CARG2, CARG1\n  |   strdne CARG34, [CARG2]\n  |   movne CARG3, CARG1\n  |  bne ->BC_CAT_Z\n  |   strd CARG34, [BASE, RA]\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  add CARG2, BASE, RB\n  |  b >2\n  |\n  |->vmeta_tgets:\n  |  sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)\n  |   mvn CARG4, #~LJ_TTAB\n  |  str TAB:RB, [CARG2]\n  |   str CARG4, [CARG2, #4]\n  |2:\n  |   mvn CARG4, #~LJ_TSTR\n  |  str STR:RC, TMPDlo\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// RC = index\n  |  decode_RB8 RB, INS\n  |   str RC, TMPDlo\n  |   mvn CARG4, #~LJ_TISNUM\n  |  add CARG2, BASE, RB\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tgetv:\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |  beq >3\n  |  ldrd CARG34, [CRET1]\n  |   ins_next1\n  |   ins_next2\n  |  strd CARG34, [BASE, RA]\n  |   ins_next3\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |   rsb CARG1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(t, k).\n  |    str PC, [BASE, #-12]\t\t// [cont|PC]\n  |   add PC, CARG1, BASE\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  .IOS mov RC, BASE\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  .IOS mov BASE, RC\n  |  cmp CRET1, #0\n  |  ldrdne CARG12, [CRET1]\n  |  mvneq CARG2, #~LJ_TNIL\n  |  b ->BC_TGETR_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  add CARG2, BASE, RB\n  |  b >2\n  |\n  |->vmeta_tsets:\n  |  sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)\n  |   mvn CARG4, #~LJ_TTAB\n  |  str TAB:RB, [CARG2]\n  |   str CARG4, [CARG2, #4]\n  |2:\n  |   mvn CARG4, #~LJ_TSTR\n  |  str STR:RC, TMPDlo\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// RC = index\n  |  decode_RB8 RB, INS\n  |   str RC, TMPDlo\n  |   mvn CARG4, #~LJ_TISNUM\n  |  add CARG2, BASE, RB\n  |   str CARG4, TMPDhi\n  |  mov CARG3, TMPDp\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |   ldrd CARG34, [BASE, RA]\n  |  beq >3\n  |   ins_next1\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  strd CARG34, [CRET1]\n  |   ins_next2\n  |   ins_next3\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |   rsb CARG1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #24\t\t// 3 args for func(t, k, v).\n  |   strd CARG34, [BASE, #16]\t\t// Copy value to third argument.\n  |    str PC, [BASE, #-12]\t\t// [cont|PC]\n  |   add PC, CARG1, BASE\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  str BASE, L->base\n  |  .IOS mov RC, BASE\n  |  mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |  .IOS mov BASE, RC\n  |  b ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  mov CARG1, L\n  |   sub PC, PC, #4\n  |  mov CARG2, RA\n  |   str BASE, L->base\n  |  mov CARG3, RC\n  |   str PC, SAVE_PC\n  |  decode_OP CARG4, INS\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #1\n  |  bhi ->vmeta_binop\n  |4:\n  |  ldrh RB, [PC, #2]\n  |   add PC, PC, #4\n  |  add RB, PC, RB, lsl #2\n  |  subhs PC, RB, #0x20000\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  ldr INS, [PC, #-4]\n  |   ldrd CARG12, [RA]\n  |  decode_RA8 CARG3, INS\n  |   strd CARG12, [BASE, CARG3]\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  ldr CARG2, [RA, #4]\n  |   mvn CARG1, #~LJ_TTRUE\n  |  cmp CARG1, CARG2\t\t\t// Branch if result is true.\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  ldr CARG2, [RA, #4]\n  |  checktp CARG2, LJ_TFALSE\t\t// Branch if result is false.\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, INS\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   lsr CARG2, RA, #3\n  |   mov CARG3, RC\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  .IOS ldr BASE, L->base\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vn:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG3, BASE, RB\n  |   add CARG4, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_nv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG4, BASE, RB\n  |   add CARG3, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_unm:\n  |  ldr INS, [PC, #-8]\n  |   sub PC, PC, #4\n  |  add CARG3, BASE, RC\n  |  add CARG4, BASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG3, BASE, RB\n  |   add CARG4, BASE, RC\n  |1:\n  |  decode_OP OP, INS\n  |   add CARG2, BASE, RA\n  |    str BASE, L->base\n  |   mov CARG1, L\n  |    str PC, SAVE_PC\n  |  str OP, ARG5\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |  beq ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub CARG2, CRET1, BASE\n  |   str PC, [CRET1, #-12]\t\t// [cont|PC]\n  |  add PC, CARG2, #FRAME_CONT\n  |   mov BASE, CRET1\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  add CARG2, BASE, RC\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n  |  .IOS ldr BASE, L->base\n#if LJ_52\n  |  cmp CRET1, #0\n  |  bne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  ldr TAB:CARG1, [BASE, RC]\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // RB = old base, BASE = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str RB, L->base\t\t\t// This is the callers base!\n  |  sub CARG2, BASE, #8\n  |   str PC, SAVE_PC\n  |  add CARG3, BASE, NARGS8:RC\n  |  .IOS mov RA, BASE\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  .IOS mov BASE, RA\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  sub CARG2, RA, #8\n  |   str PC, SAVE_PC\n  |  add CARG3, RA, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  .IOS ldr BASE, L->base\n  |  ldr LFUNC:CARG3, [RA, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   ldr PC, [BASE, FRAME_PC]\n  |    add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  b ->BC_CALLT2_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, RA\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  .IOS ldr BASE, L->base\n  |.if JIT\n  |   ldrb OP, [PC, #-4]\n  |.endif\n  |  ldr INS, [PC, #-4]\n  |.if JIT\n  |   cmp OP, #BC_JFORI\n  |.endif\n  |  decode_RA8 RA, INS\n  |  decode_RD RC, INS\n  |.if JIT\n  |   beq =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  ldrd CARG12, [BASE]\n  |   ldrd CARG34, [BASE, #8]\n  |    cmp NARGS8:RC, #16\n  |    blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc_1 name\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc_2 name\n  |  checktp CARG2, LJ_TISNUM\n  |  cmnlo CARG4, #-LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_d, name\n  |  .ffunc name\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |  vldr d0, [BASE]\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_dd, name\n  |  .ffunc name\n  |  ldr CARG2, [BASE, #4]\n  |  ldr CARG4, [BASE, #12]\n  |   cmp NARGS8:RC, #16\n  |  vldr d0, [BASE]\n  |  vldr d1, [BASE, #8]\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  cmnlo CARG4, #-LJ_TISNUM\n  |  bhs ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.\n  |.macro ffgccheck\n  |  ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)]\n  |  ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)]\n  |  cmp CARG1, CARG2\n  |  blge ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  checktp CARG2, LJ_TTRUE\n  |  bhi ->fff_fallback\n  |   ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |  mov RB, BASE\n  |  subs RA, NARGS8:RC, #8\n  |   add RC, NARGS8:RC, #8\t\t// Compute (nresults+1)*8.\n  |  beq ->fff_res\t\t\t// Done if exactly 1 argument.\n  |1:\n  |   ldrd CARG12, [RB, #8]\n  |  subs RA, RA, #8\n  |   strd CARG12, [RB], #8\n  |  bne <1\n  |  b ->fff_res\n  |\n  |.ffunc type\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  mvnlo CARG2, #~LJ_TISNUM\n  |  rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1\n  |  lsl CARG4, CARG4, #3\n  |  ldrd CARG12, [CFUNC:CARG3, CARG4]\n  |  b ->fff_restv\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  checktp CARG2, LJ_TTAB\n  |  cmnne CARG2, #-LJ_TUDATA\n  |  bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  ldr TAB:RB, TAB:CARG1->metatable\n  |2:\n  |   mvn CARG2, #~LJ_TNIL\n  |   ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])]\n  |  cmp TAB:RB, #0\n  |  beq ->fff_restv\n  |  ldr CARG3, TAB:RB->hmask\n  |   ldr CARG4, STR:RC->sid\n  |    ldr NODE:INS, TAB:RB->node\n  |  and CARG3, CARG3, CARG4\t\t// idx = str->sid & tab->hmask\n  |  add CARG3, CARG3, CARG3, lsl #1\n  |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  ldrd CARG34, NODE:INS->key  // STALL: early NODE:INS.\n  |   ldrd CARG12, NODE:INS->val\n  |    ldr NODE:INS, NODE:INS->next\n  |  checktp CARG4, LJ_TSTR\n  |  cmpeq CARG3, STR:RC\n  |  beq >5\n  |  cmp NODE:INS, #0\n  |  bne <3\n  |4:\n  |  mov CARG1, RB\t\t\t// Use metatable as default result.\n  |  mvn CARG2, #~LJ_TTAB\n  |  b ->fff_restv\n  |5:\n  |  checktp CARG2, LJ_TNIL\n  |  bne ->fff_restv\n  |  b <4\n  |\n  |6:\n  |  checktp CARG2, LJ_TISNUM\n  |  mvnhs CARG2, CARG2\n  |  movlo CARG2, #~LJ_TISNUM\n  |  add CARG4, DISPATCH, CARG2, lsl #2\n  |  ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  checktp CARG2, LJ_TTAB\n  |   ldreq TAB:RB, TAB:CARG1->metatable\n  |  checktpeq CARG4, LJ_TTAB\n  |    ldrbeq CARG4, TAB:CARG1->marked\n  |   cmpeq TAB:RB, #0\n  |  bne ->fff_fallback\n  |    tst CARG4, #LJ_GC_BLACK\t\t// isblack(table)\n  |     str TAB:CARG3, TAB:CARG1->metatable\n  |    beq ->fff_restv\n  |  barrierback TAB:CARG1, CARG4, CARG3\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  ldrd CARG34, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |   mov CARG2, CARG3\n  |  checktab CARG4, ->fff_fallback\n  |   mov CARG1, L\n  |   add CARG3, BASE, #8\n  |  .IOS mov RA, BASE\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |  .IOS mov BASE, RA\n  |  ldrd CARG12, [CRET1]\n  |  b ->fff_restv\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   bne ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bls ->fff_restv\n  |  b ->fff_fallback\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  checktp CARG2, LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])]\n  |   str BASE, L->base\n  |  checktp CARG2, LJ_TISNUM\n  |  cmpls CARG4, #0\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  bhi ->fff_fallback\n  |  ffgccheck\n  |  mov CARG1, L\n  |  mov CARG2, BASE\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |  mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |   mvn CARG4, #~LJ_TNIL\n  |  checktab CARG2, ->fff_fallback\n  |   strd CARG34, [BASE, NARGS8:RC]\t// Set missing 2nd arg to nil.\n  |   ldr PC, [BASE, FRAME_PC]\n  |  add CARG2, BASE, #8\n  |  sub CARG3, BASE, #8\n  |  bl extern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |  // Returns 1=found, 0=end, -1=error.\n  |  .IOS ldr BASE, L->base\n  |  cmp CRET1, #0\n  |   mov RC, #(2+1)*8\n  |  bgt ->fff_res\t\t\t// Found key/value.\n  |  bmi ->fff_fallback\t\t\t// Invalid key.\n  |  // End of traversal: return nil.\n  |  mvn CRET2, #~LJ_TNIL\n  |  b ->fff_restv\n  |\n  |.ffunc_1 pairs\n  |  checktab CARG2, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:RB, TAB:CARG1->metatable\n#endif\n  |   ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cmp TAB:RB, #0\n  |  bne ->fff_fallback\n#endif\n  |  mvn CARG2, #~LJ_TNIL\n  |    mov RC, #(3+1)*8\n  |   strd CFUNC:CARG34, [BASE, #-8]\n  |  str CARG2, [BASE, #12]\n  |  b ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  checktp CARG2, LJ_TTAB\n  |  checktpeq CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  ldr RB, TAB:CARG1->asize\n  |   ldr RC, TAB:CARG1->array\n  |  add CARG3, CARG3, #1\n  |    ldr PC, [BASE, FRAME_PC]\n  |  cmp CARG3, RB\n  |   add RC, RC, CARG3, lsl #3\n  |  strd CARG34, [BASE, #-8]\n  |   ldrdlo CARG12, [RC]\n  |   mov RC, #(0+1)*8\n  |  bhs >2\t\t\t\t// Not in array part?\n  |1:\n  |   checktp CARG2, LJ_TNIL\n  |   movne RC, #(2+1)*8\n  |   strdne CARG12, [BASE]\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  ldr RB, TAB:CARG1->hmask\n  |   mov CARG2, CARG3\n  |  cmp RB, #0\n  |  beq ->fff_res\n  |  .IOS mov RA, BASE\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  .IOS mov BASE, RA\n  |  cmp CRET1, #0\n  |  beq ->fff_res\n  |  ldrd CARG12, [CRET1]\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktab CARG2, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:RB, TAB:CARG1->metatable\n#endif\n  |   ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cmp TAB:RB, #0\n  |  bne ->fff_fallback\n#endif\n  |  mov CARG1, #0\n  |  mvn CARG2, #~LJ_TISNUM\n  |    mov RC, #(3+1)*8\n  |   strd CFUNC:CARG34, [BASE, #-8]\n  |  strd CARG12, [BASE, #8]\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |  tst RA, #HOOK_ACTIVE\t\t// Remember active hook before pcall.\n  |   mov RB, BASE\n  |   add BASE, BASE, #8\n  |  moveq PC, #8+FRAME_PCALL\n  |  movne PC, #8+FRAME_PCALLH\n  |   sub NARGS8:RC, NARGS8:RC, #8\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  checkfunc CARG4, ->fff_fallback\t// Traceback must be a function.\n  |   mov RB, BASE\n  |  strd CARG12, [BASE, #8]\t\t// Swap function and traceback.\n  |   strd CARG34, [BASE]\n  |  tst RA, #HOOK_ACTIVE\t\t// Remember active hook before pcall.\n  |   add BASE, BASE, #16\n  |  moveq PC, #16+FRAME_PCALL\n  |  movne PC, #16+FRAME_PCALLH\n  |   sub NARGS8:RC, NARGS8:RC, #16\n  |  b ->vm_call_dispatch\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  checktp CARG2, LJ_TTHREAD\n  |  bne ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr\n  |.endif\n  |   ldr PC, [BASE, FRAME_PC]\n  |     str BASE, L->base\n  |  ldr CARG2, L:CARG1->top\n  |   ldrb RA, L:CARG1->status\n  |    ldr RB, L:CARG1->base\n  |  add CARG3, CARG2, NARGS8:RC\n  |  add CARG4, CARG2, RA\n  |   str PC, SAVE_PC\n  |  cmp CARG4, RB\n  |  beq ->fff_fallback\n  |   ldr CARG4, L:CARG1->maxstack\n  |    ldr RB, L:CARG1->cframe\n  |   cmp RA, #LUA_YIELD\n  |   cmpls CARG3, CARG4\n  |    cmpls RB, #0\n  |    bhi ->fff_fallback\n  |1:\n  |.if resume\n  |  sub CARG3, CARG3, #8\t\t// Keep resumed thread in stack for GC.\n  |  add BASE, BASE, #8\n  |  sub NARGS8:RC, NARGS8:RC, #8\n  |.endif\n  |  str CARG3, L:CARG1->top\n  |  str BASE, L->top\n  |2:  // Move args to coroutine.\n  |   ldrd CARG34, [BASE, RB]\n  |  cmp RB, NARGS8:RC\n  |   strdne CARG34, [CARG2, RB]\n  |  add RB, RB, #8\n  |  bne <2\n  |\n  |  mov CARG3, #0\n  |   mov L:RA, L:CARG1\n  |  mov CARG4, #0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  ldr CARG3, L:RA->base\n  |    mv_vmstate CARG2, INTERP\n  |  ldr CARG4, L:RA->top\n  |   cmp CRET1, #LUA_YIELD\n  |  ldr BASE, L->base\n  |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |    st_vmstate CARG2\n  |   bhi >8\n  |  subs RC, CARG4, CARG3\n  |   ldr CARG1, L->maxstack\n  |   add CARG2, BASE, RC\n  |  beq >6\t\t\t\t// No results?\n  |  cmp CARG2, CARG1\n  |   mov RB, #0\n  |  bhi >9\t\t\t\t// Need to grow stack?\n  |\n  |  sub CARG4, RC, #8\n  |   str CARG3, L:RA->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |   ldrd CARG12, [CARG3, RB]\n  |  cmp RB, CARG4\n  |   strd CARG12, [BASE, RB]\n  |  add RB, RB, #8\n  |  bne <5\n  |6:\n  |.if resume\n  |  mvn CARG3, #~LJ_TTRUE\n  |   add RC, RC, #16\n  |7:\n  |  str CARG3, [BASE, #-4]\t\t// Prepend true/false to results.\n  |   sub RA, BASE, #8\n  |.else\n  |   mov RA, BASE\n  |   add RC, RC, #8\n  |.endif\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str PC, SAVE_PC\n  |   str RC, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  ldrd CARG12, [CARG4, #-8]!\n  |   mvn CARG3, #~LJ_TFALSE\n  |    mov RC, #(2+1)*8\n  |  str CARG4, L:RA->top\t\t// Remove error from coroutine stack.\n  |  strd CARG12, [BASE]\t\t// Copy error message.\n  |  b <7\n  |.else\n  |  mov CARG1, L\n  |  mov CARG2, L:RA\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Never returns.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov CARG1, L\n  |  lsr CARG2, RC, #3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov CRET1, #0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  ldr CARG1, L->cframe\n  |   add CARG2, BASE, NARGS8:RC\n  |   str BASE, L->base\n  |  tst CARG1, #CFRAME_RESUME\n  |   str CARG2, L->top\n  |    mov CRET1, #LUA_YIELD\n  |   mov CARG3, #0\n  |  beq ->fff_fallback\n  |   str CARG3, L->cframe\n  |    strb CRET1, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.macro math_round, func\n  |  .ffunc_1 math_ .. func\n  |  checktp CARG2, LJ_TISNUM\n  |  beq ->fff_restv\n  |  bhi ->fff_fallback\n  |  // Round FP value and normalize result.\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  bpl >2\t\t\t\t// |x| < 1?\n  |  mvn CARG4, #0x3e0\n  |    subs RB, CARG4, RB, asr #21\n  |  lsl CARG4, CARG2, #11\n  |   lsl CARG3, CARG1, #11\n  |  orr CARG4, CARG4, #0x80000000\n  |   rsb INS, RB, #32\n  |  orr CARG4, CARG4, CARG1, lsr #21\n  |    bls >3\t\t\t\t// |x| >= 2^31?\n  |   orr CARG3, CARG3, CARG4, lsl INS\n  |  lsr CARG1, CARG4, RB\n  |.if \"func\" == \"floor\"\n  |   tst CARG3, CARG2, asr #31\n  |   addne CARG1, CARG1, #1\n  |.else\n  |   bics CARG3, CARG3, CARG2, asr #31\n  |   addsne CARG1, CARG1, #1\n  |   ldrdvs CARG12, >9\n  |   bvs ->fff_restv\n  |.endif\n  |    cmp CARG2, #0\n  |    rsblt CARG1, CARG1, #0\n  |1:\n  |   mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |2:  // |x| < 1\n  |  bcs ->fff_restv\t\t\t// |x| is not finite.\n  |  orr CARG3, CARG3, CARG1\t\t// ztest = abs(hi) | lo\n  |.if \"func\" == \"floor\"\n  |  tst CARG3, CARG2, asr #31\t\t// return (ztest & sign) == 0 ? 0 : -1\n  |  moveq CARG1, #0\n  |  mvnne CARG1, #0\n  |.else\n  |  bics CARG3, CARG3, CARG2, asr #31\t// return (ztest & ~sign) == 0 ? 0 : 1\n  |  moveq CARG1, #0\n  |  movne CARG1, #1\n  |.endif\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |3:  // |x| >= 2^31. Check for x == -(2^31).\n  |  cmpeq CARG4, #0x80000000\n  |.if \"func\" == \"floor\"\n  |  cmpeq CARG3, #0\n  |.endif\n  |  bne >4\n  |  cmp CARG2, #0\n  |  movmi CARG1, #0x80000000\n  |  bmi <1\n  |4:\n  |  bl ->vm_..func.._sf\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.align 8\n  |9:\n  |  .long 0x00000000, 0x41e00000\t// 2^31.\n  |\n  |.ffunc_1 math_abs\n  |  checktp CARG2, LJ_TISNUM\n  |  bhi ->fff_fallback\n  |  bicne CARG2, CARG2, #0x80000000\n  |  bne ->fff_restv\n  |  cmp CARG1, #0\n  |  rsbslt CARG1, CARG1, #0\n  |  ldrdvs CARG12, <9\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG12 = TValue result.\n  |  ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |->fff_res1:\n  |  // PC = return.\n  |  mov RC, #(1+1)*8\n  |->fff_res:\n  |  // RC = (nresults+1)*8, PC = return.\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  ldreq INS, [PC, #-4]\n  |   str RC, SAVE_MULTRES\n  |  sub RA, BASE, #8\n  |  bne ->vm_return\n  |  decode_RB8 RB, INS\n  |5:\n  |  cmp RB, RC\t\t\t\t// More results expected?\n  |  bhi >6\n  |  decode_RA8 CARG1, INS\n  |   ins_next1\n  |   ins_next2\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  sub BASE, RA, CARG1\n  |   ins_next3\n  |\n  |6:  // Fill up results with nil.\n  |  add CARG2, RA, RC\n  |  mvn CARG1, #~LJ_TNIL\n  |   add RC, RC, #8\n  |  str CARG1, [CARG2, #-4]\n  |  b <5\n  |\n  |.macro math_extern, func\n  |.if HFABI\n  |  .ffunc_d math_ .. func\n  |.else\n  |  .ffunc_n math_ .. func\n  |.endif\n  |  .IOS mov RA, BASE\n  |  bl extern func\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |.if HFABI\n  |  .ffunc_dd math_ .. func\n  |.else\n  |  .ffunc_nn math_ .. func\n  |.endif\n  |  .IOS mov RA, BASE\n  |  bl extern func\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |.endmacro\n  |\n  |.if FPU\n  |  .ffunc_d math_sqrt\n  |  vsqrt.f64 d0, d0\n  |->fff_resd:\n  |  ldr PC, [BASE, FRAME_PC]\n  |  vstr d0, [BASE, #-8]\n  |  b ->fff_res1\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |.ffunc math_log\n  |.if HFABI\n  |  ldr CARG2, [BASE, #4]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |  vldr d0, [BASE]\n  |   bne ->fff_fallback\n  |.else\n  |  ldrd CARG12, [BASE]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |   bne ->fff_fallback\n  |.endif\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern log\n  |  .IOS mov BASE, RA\n  |.if HFABI\n  |  b ->fff_resd\n  |.else\n  |  b ->fff_restv\n  |.endif\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if HFABI\n  |  .ffunc math_ldexp\n  |  ldr CARG4, [BASE, #4]\n  |  ldrd CARG12, [BASE, #8]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  vldr d0, [BASE]\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  .IOS mov BASE, RA\n  |  b ->fff_resd\n  |.else\n  |.ffunc_2 math_ldexp\n  |  checktp CARG2, LJ_TISNUM\n  |  bhs ->fff_fallback\n  |  checktp CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  .IOS mov RA, BASE\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  .IOS mov BASE, RA\n  |  b ->fff_restv\n  |.endif\n  |\n  |.if HFABI\n  |.ffunc_d math_frexp\n  |  mov CARG1, sp\n  |  .IOS mov RA, BASE\n  |  bl extern frexp\n  |  .IOS mov BASE, RA\n  |   ldr CARG3, [sp]\n  |   mvn CARG4, #~LJ_TISNUM\n  |    ldr PC, [BASE, FRAME_PC]\n  |  vstr d0, [BASE, #-8]\n  |    mov RC, #(2+1)*8\n  |   strd CARG34, [BASE]\n  |  b ->fff_res\n  |.else\n  |.ffunc_n math_frexp\n  |  mov CARG3, sp\n  |  .IOS mov RA, BASE\n  |  bl extern frexp\n  |  .IOS mov BASE, RA\n  |   ldr CARG3, [sp]\n  |   mvn CARG4, #~LJ_TISNUM\n  |    ldr PC, [BASE, FRAME_PC]\n  |  strd CARG12, [BASE, #-8]\n  |    mov RC, #(2+1)*8\n  |   strd CARG34, [BASE]\n  |  b ->fff_res\n  |.endif\n  |\n  |.if HFABI\n  |.ffunc_d math_modf\n  |  sub CARG1, BASE, #8\n  |   ldr PC, [BASE, FRAME_PC]\n  |  .IOS mov RA, BASE\n  |  bl extern modf\n  |  .IOS mov BASE, RA\n  |   mov RC, #(2+1)*8\n  |  vstr d0, [BASE]\n  |  b ->fff_res\n  |.else\n  |.ffunc_n math_modf\n  |  sub CARG3, BASE, #8\n  |   ldr PC, [BASE, FRAME_PC]\n  |  .IOS mov RA, BASE\n  |  bl extern modf\n  |  .IOS mov BASE, RA\n  |   mov RC, #(2+1)*8\n  |  strd CARG12, [BASE]\n  |  b ->fff_res\n  |.endif\n  |\n  |.macro math_minmax, name, cond, fcond\n  |.if FPU\n  |  .ffunc_1 name\n  |   add RB, BASE, RC\n  |  checktp CARG2, LJ_TISNUM\n  |   add RA, BASE, #8\n  |  bne >4\n  |1:  // Handle integers.\n  |  ldrd CARG34, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bne >3\n  |  cmp CARG1, CARG3\n  |   add RA, RA, #8\n  |  mov..cond CARG1, CARG3\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  vmov s4, CARG1\n  |  bhi ->fff_fallback\n  |  vldr d1, [RA]\n  |  vcvt.f64.s32 d0, s4\n  |  b >6\n  |\n  |4:\n  |  vldr d0, [BASE]\n  |  bhi ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldrd CARG34, [RA]\n  |  vldr d1, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_resd\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs >7\n  |6:\n  |  vcmp.f64 d0, d1\n  |  vmrs\n  |   add RA, RA, #8\n  |  vmov..fcond.f64 d0, d1\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  vmov s4, CARG3\n  |  bhi ->fff_fallback\n  |  vcvt.f64.s32 d1, s4\n  |  b <6\n  |\n  |.else\n  |\n  |  .ffunc_1 name\n  |  checktp CARG2, LJ_TISNUM\n  |   mov RA, #8\n  |  bne >4\n  |1:  // Handle integers.\n  |  ldrd CARG34, [BASE, RA]\n  |   cmp RA, RC\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bne >3\n  |  cmp CARG1, CARG3\n  |   add RA, RA, #8\n  |  mov..cond CARG1, CARG3\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  bhi ->fff_fallback\n  |  bl extern __aeabi_i2d\n  |  ldrd CARG34, [BASE, RA]\n  |  b >6\n  |\n  |4:\n  |  bhi ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldrd CARG34, [BASE, RA]\n  |   cmp RA, RC\n  |   bhs ->fff_restv\n  |  checktp CARG4, LJ_TISNUM\n  |  bhs >7\n  |6:\n  |  bl extern __aeabi_cdcmple\n  |   add RA, RA, #8\n  |  mov..fcond CARG1, CARG3\n  |  mov..fcond CARG2, CARG4\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  bhi ->fff_fallback\n  |  strd CARG12, TMPD\n  |  mov CARG1, CARG3\n  |  bl extern __aeabi_i2d\n  |  ldrd CARG34, TMPD\n  |  b <6\n  |.endif\n  |.endmacro\n  |\n  |  math_minmax math_min, gt, pl\n  |  math_minmax math_max, lt, le\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  ldrd CARG12, [BASE]\n  |    ldr PC, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\n  |   checktpeq CARG2, LJ_TSTR\t\t// Need exactly 1 argument.\n  |   bne ->fff_fallback\n  |  ldr CARG3, STR:CARG1->len\n  |   ldrb CARG1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   mvn CARG2, #~LJ_TISNUM\n  |  cmp CARG3, #0\n  |  moveq RC, #(0+1)*8\n  |  movne RC, #(1+1)*8\n  |   strd CARG12, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  ldrd CARG12, [BASE]\n  |    ldr PC, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\t\t\t// Need exactly 1 argument.\n  |   checktpeq CARG2, LJ_TISNUM\n  |   bicseq CARG4, CARG1, #255\n  |  mov CARG3, #1\n  |   bne ->fff_fallback\n  |  str CARG1, TMPD\n  |  mov CARG2, TMPDp\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  // CARG2 = str, CARG3 = len.\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |   mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  ldrd CARG12, [BASE]\n  |   ldrd CARG34, [BASE, #16]\n  |    cmp NARGS8:RC, #16\n  |     mvn RB, #0\n  |    beq >1\n  |    blo ->fff_fallback\n  |   checktp CARG4, LJ_TISNUM\n  |    mov RB, CARG3\n  |   bne ->fff_fallback\n  |1:\n  |  ldrd CARG34, [BASE, #8]\n  |  checktp CARG2, LJ_TSTR\n  |   ldreq CARG2, STR:CARG1->len\n  |  checktpeq CARG4, LJ_TISNUM\n  |  bne ->fff_fallback\n  |  // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end\n  |  add CARG4, CARG2, #1\n  |  cmp CARG3, #0\t\t\t// if (start < 0) start += len+1\n  |  addlt CARG3, CARG3, CARG4\n  |  cmp CARG3, #1\t\t\t// if (start < 1) start = 1\n  |  movlt CARG3, #1\n  |  cmp RB, #0\t\t\t\t// if (end < 0) end += len+1\n  |  addlt RB, RB, CARG4\n  |  bic RB, RB, RB, asr #31\t\t// if (end < 0) end = 0\n  |  cmp RB, CARG2\t\t\t// if (end > len) end = len\n  |   add CARG1, STR:CARG1, #sizeof(GCstr)-1\n  |  movgt RB, CARG2\n  |   add CARG2, CARG1, CARG3\n  |  subs CARG3, RB, CARG3\t\t// len = end - start\n  |   add CARG3, CARG3, #1\t\t// len += 1\n  |  bge ->fff_newstr\n  |->fff_emptystr:\n  |  sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)\n  |  mvn CARG2, #~LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  ldr CARG3, [BASE, #4]\n  |   cmp NARGS8:RC, #8\n  |  ldr STR:CARG2, [BASE]\n  |   blo ->fff_fallback\n  |  sub SBUF:CARG1, DISPATCH, #-DISPATCH_GL(tmpbuf)\n  |  checkstr CARG3, ->fff_fallback\n  |  ldr CARG4, SBUF:CARG1->b\n  |   str BASE, L->base\n  |   str PC, SAVE_PC\n  |   str L, SBUF:CARG1->L\n  |  str CARG4, SBUF:CARG1->w\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |// FP number to bit conversion for soft-float. Clobbers r0-r3.\n  |->vm_tobit_fb:\n  |  bhi ->fff_fallback\n  |->vm_tobit:\n  |  lsl RB, CARG2, #1\n  |  adds RB, RB, #0x00200000\n  |  movpl CARG1, #0\t\t\t// |x| < 1?\n  |  bxpl lr\n  |  mvn CARG4, #0x3e0\n  |  subs RB, CARG4, RB, asr #21\n  |  bmi >1\t\t\t\t// |x| >= 2^32?\n  |  lsl CARG4, CARG2, #11\n  |  orr CARG4, CARG4, #0x80000000\n  |  orr CARG4, CARG4, CARG1, lsr #21\n  |   cmp CARG2, #0\n  |  lsr CARG1, CARG4, RB\n  |   rsblt CARG1, CARG1, #0\n  |  bx lr\n  |1:\n  |  add RB, RB, #21\n  |  lsr CARG4, CARG1, RB\n  |  rsb RB, RB, #20\n  |  lsl CARG1, CARG2, #12\n  |   cmp CARG2, #0\n  |  orr CARG1, CARG4, CARG1, lsl RB\n  |   rsblt CARG1, CARG1, #0\n  |  bx lr\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |.endmacro\n  |\n  |.ffunc_bit tobit\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  mov CARG3, CARG1\n  |  mov RA, #8\n  |1:\n  |  ldrd CARG12, [BASE, RA]\n  |   cmp RA, NARGS8:RC\n  |    add RA, RA, #8\n  |   bge >2\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |  ins CARG3, CARG3, CARG1\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, orr\n  |.ffunc_bit_op bxor, eor\n  |\n  |2:\n  |  mvn CARG4, #~LJ_TISNUM\n  |   ldr PC, [BASE, FRAME_PC]\n  |  strd CARG34, [BASE, #-8]\n  |  b ->fff_res1\n  |\n  |.ffunc_bit bswap\n  |  eor CARG3, CARG1, CARG1, ror #16\n  |  bic CARG3, CARG3, #0x00ff0000\n  |  ror CARG1, CARG1, #8\n  |   mvn CARG2, #~LJ_TISNUM\n  |  eor CARG1, CARG1, CARG3, lsr #8\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bnot\n  |  mvn CARG1, CARG1\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc bit_..name\n  |  ldrd CARG12, [BASE, #8]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |.if shmod == 0\n  |  and RA, CARG1, #31\n  |.else\n  |  rsb RA, CARG1, #0\n  |.endif\n  |  ldrd CARG12, [BASE]\n  |  checktp CARG2, LJ_TISNUM\n  |  blne ->vm_tobit_fb\n  |  ins CARG1, CARG1, RA\n  |  mvn CARG2, #~LJ_TISNUM\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, lsl, 0\n  |.ffunc_bit_sh rshift, lsr, 0\n  |.ffunc_bit_sh arshift, asr, 0\n  |.ffunc_bit_sh rol, ror, 1\n  |.ffunc_bit_sh ror, ror, 0\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RC = nargs*8\n  |   ldr CARG3, [BASE, FRAME_FUNC]\n  |  ldr CARG2, L->maxstack\n  |  add CARG1, BASE, NARGS8:RC\n  |    ldr PC, [BASE, FRAME_PC]\t\t// Fallback may overwrite PC.\n  |  str CARG1, L->top\n  |   ldr CARG3, CFUNC:CARG3->f\n  |    str BASE, L->base\n  |  add CARG1, CARG1, #8*LUA_MINSTACK\n  |    str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  cmp CARG1, CARG2\n  |   mov CARG1, L\n  |  bhi >5\t\t\t\t// Need to grow stack.\n  |   blx CARG3\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |   ldr BASE, L->base\n  |  cmp CRET1, #0\n  |   lsl RC, CRET1, #3\n  |   sub RA, BASE, #8\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |   ldr CARG1, L->top\n  |    ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, CARG1, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   bic CARG2, PC, #FRAME_TYPEP\n  |  ldreq INS, [PC, #-4]\n  |  andeq CARG2, MASKR8, INS, lsr #5\t// Conditional decode_RA8.\n  |  addeq CARG2, CARG2, #8\n  |  sub RB, BASE, CARG2\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2, #LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |  cmp CARG1, CARG1\t\t\t// Set zero-flag to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  mov RA, lr\n  |   str BASE, L->base\n  |  add CARG2, BASE, NARGS8:RC\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  str CARG2, L->top\n  |  mov CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |   ldr BASE, L->base\n  |  mov lr, RA\t\t\t\t// Help return address predictor.\n  |   ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  bx lr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  tst CARG1, #HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  bne >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |   ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  tst CARG1, #HOOK_ACTIVE\n  |  bne >1\n  |   sub CARG2, CARG2, #1\n  |  tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT\n  |   strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  b >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |  tst CARG1, #HOOK_ACTIVE\t\t// Hook already active?\n  |  beq >1\n  |5:  // Re-dispatch to static ins.\n  |  decode_OP OP, INS\n  |  add OP, DISPATCH, OP, lsl #2\n  |  ldr pc, [OP, #GG_DISP2STATIC]\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]\n  |   ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |  tst CARG1, #HOOK_ACTIVE\t\t// Hook already active?\n  |  bne <5\n  |  tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT\n  |  beq <5\n  |   subs CARG2, CARG2, #1\n  |   str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]\n  |   beq >1\n  |  tst CARG1, #LUA_MASKLINE\n  |  beq <5\n  |1:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  ldr BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  ldrb OP, [PC, #-4]\n  |   ldr INS, [PC, #-4]\n  |  add OP, DISPATCH, OP, lsl #2\n  |  ldr OP, [OP, #GG_DISP2STATIC]\n  |   decode_RA8 RA, INS\n  |   decode_RD RC, INS\n  |  bx OP\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  ldr CARG1, [CARG4, #-24]\n  |   add PC, PC, #4\n  |  str CARG1, SAVE_MULTRES\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Same as curr_topL(L).\n  |   sub CARG1, DISPATCH, #-GG_DISP2J\n  |   str PC, SAVE_PC\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |   mov CARG2, PC\n  |   str L, [DISPATCH, #DISPATCH_J(L)]\n  |  ldrb CARG3, [CARG3, #PC2PROTO(framesize)]\n  |   str BASE, L->base\n  |  add CARG3, BASE, CARG3, lsl #3\n  |  str CARG3, L->top\n  |  bl extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  b <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  orr CARG2, PC, #1\n  |1:\n  |.endif\n  |  add CARG4, BASE, RC\n  |   str PC, SAVE_PC\n  |    mov CARG1, L\n  |   str BASE, L->base\n  |    sub RA, RA, BASE\n  |  str CARG4, L->top\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  ldr BASE, L->base\n  |   ldr CARG4, L->top\n  |    mov CARG2, #0\n  |  add RA, BASE, RA\n  |   sub NARGS8:RC, CARG4, BASE\n  |    str CARG2, SAVE_PC\t\t// Invalidate for subsequent line hook.\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   ldr INS, [PC, #-4]\n  |  bx CRET1\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, CARG4 = meta base\n  |   ldr RB, SAVE_MULTRES\n  |  ldr INS, [PC, #-4]\n  |    ldr TRACE:CARG3, [CARG4, #-24]\t// Save previous trace.\n  |   subs RB, RB, #8\n  |  decode_RA8 RC, INS\t\t\t// Call base.\n  |   beq >2\n  |1:  // Move results down.\n  |  ldrd CARG12, [RA]\n  |    add RA, RA, #8\n  |   subs RB, RB, #8\n  |  strd CARG12, [BASE, RC]\n  |    add RC, RC, #8\n  |   bne <1\n  |2:\n  |   decode_RA8 RA, INS\n  |   decode_RB8 RB, INS\n  |   add RA, RA, RB\n  |3:\n  |   cmp RA, RC\n  |  mvn CARG2, #~LJ_TNIL\n  |   bhi >9\t\t\t\t// More results wanted?\n  |\n  |  ldrh RA, TRACE:CARG3->traceno\n  |  ldrh RC, TRACE:CARG3->link\n  |  cmp RC, RA\n  |  beq ->cont_nop\t\t\t// Blacklisted.\n  |  cmp RC, #0\n  |  bne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  str RA, [DISPATCH, #DISPATCH_J(exitno)]\n  |  str L, [DISPATCH, #DISPATCH_J(L)]\n  |  str BASE, L->base\n  |  sub CARG1, DISPATCH, #-GG_DISP2J\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  ldr BASE, L->base\n  |  b ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  strd CARG12, [BASE, RC]\n  |  add RC, RC, #8\n  |  b <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  ldr BASE, L->base\n  |  sub PC, PC, #4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |  sub sp, sp, #12\n  |  push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}\n  |  ldr CARG1, [sp, #64]\t// Load original value of lr.\n  |   ldr DISPATCH, [lr]\t// Load DISPATCH.\n  |    add CARG3, sp, #64\t// Recompute original value of sp.\n  |   mv_vmstate CARG4, EXIT\n  |    str CARG3, [sp, #52]\t// Store sp in RID_SP\n  |   st_vmstate CARG4\n  |  ldr CARG2, [CARG1, #-4]!\t// Get exit instruction.\n  |   str CARG1, [sp, #56]\t// Store exit pc in RID_LR and RID_PC.\n  |   str CARG1, [sp, #60]\n  |.if FPU\n  |  vpush {d0-d15}\n  |.endif\n  |  lsl CARG2, CARG2, #8\n  |  add CARG1, CARG1, CARG2, asr #6\n  |   ldr CARG2, [lr, #4]\t// Load exit stub group offset.\n  |   sub CARG1, CARG1, lr\n  |  ldr L, [DISPATCH, #DISPATCH_GL(cur_L)]\n  |   add CARG1, CARG2, CARG1, lsr #2\t// Compute exit number.\n  |    ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |   str CARG1, [DISPATCH, #DISPATCH_J(exitno)]\n  |   mov CARG4, #0\n  |    str BASE, L->base\n  |  str L, [DISPATCH, #DISPATCH_J(L)]\n  |   str CARG4, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |  sub CARG1, DISPATCH, #-GG_DISP2J\n  |  mov CARG2, sp\n  |  bl extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  ldr CARG2, L->cframe\n  |   ldr BASE, L->base\n  |  bic CARG2, CARG2, #~CFRAME_RAWMASK\t// Use two steps: bic sp is deprecated.\n  |  mov sp, CARG2\n  |   ldr PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  str L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |  b >1\n  |.endif\n  |->vm_exit_interp:\n  |  // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |  ldr L, SAVE_L\n  |1:\n  |  cmp CARG1, #0\n  |  blt >9\t\t\t\t// Check for error from exit.\n  |   lsl RC, CARG1, #3\n  |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n  |   str RC, SAVE_MULTRES\n  |   mov CARG3, #0\n  |   str BASE, L->base\n  |  ldr CARG2, LFUNC:CARG2->field_pc\n  |   str CARG3, [DISPATCH, #DISPATCH_GL(jit_base)]\n  |    mv_vmstate CARG4, INTERP\n  |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  ldrb OP, [PC]\n  |     mov MASKR8, #255\n  |   ldr INS, [PC], #4\n  |     lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |    st_vmstate CARG4\n  |  cmp OP, #BC_FUNCC+2\t\t// Fast function?\n  |  bhs >4\n  |2:\n  |  cmp OP, #BC_FUNCF\t\t\t// Function header?\n  |  ldr OP, [DISPATCH, OP, lsl #2]\n  |   decode_RA8 RA, INS\n  |   lsrlo RC, INS, #16\t// No: Decode operands A*8 and D.\n  |   subhs RC, RC, #8\n  |   addhs RA, RA, BASE\t// Yes: RA = BASE+framesize*8, RC = nargs*8\n  |   ldrhs CARG3, [BASE, FRAME_FUNC]\n  |  bx OP\n  |\n  |4:  // Check frame below fast function.\n  |  ldr CARG1, [BASE, FRAME_PC]\n  |  ands CARG2, CARG1, #FRAME_TYPE\n  |  bne <2\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  ldr CARG3, [CARG1, #-4]\n  |  decode_RA8 CARG1, CARG3\n  |  sub CARG2, BASE, CARG1\n  |  ldr LFUNC:CARG3, [CARG2, #-16]\n  |  ldr CARG3, LFUNC:CARG3->field_pc\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  b <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  rsb CARG2, CARG1, #0\n  |  mov CARG1, L\n  |  bl extern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called from JIT code.\n  |//\n  |// double lj_vm_floor/ceil/trunc(double x);\n  |.macro vm_round, func, hf\n  |.if hf == 1\n  |  vmov CARG1, CARG2, d0\n  |.endif\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  bpl >2\t\t\t\t// |x| < 1?\n  |  mvn CARG4, #0x3cc\n  |  subs RB, CARG4, RB, asr #21\t// 2^0: RB = 51, 2^51: RB = 0.\n  |  bxlo lr\t\t\t\t// |x| >= 2^52: done.\n  |  mvn CARG4, #1\n  |   bic CARG3, CARG1, CARG4, lsl RB\t// ztest = lo & ~lomask\n  |  and CARG1, CARG1, CARG4, lsl RB\t// lo &= lomask\n  |  subs RB, RB, #32\n  |   bicpl CARG4, CARG2, CARG4, lsl RB\t// |x| <= 2^20: ztest |= hi & ~himask\n  |   orrpl CARG3, CARG3, CARG4\n  |   mvnpl CARG4, #1\n  |  andpl CARG2, CARG2, CARG4, lsl RB\t// |x| <= 2^20: hi &= himask\n  |.if \"func\" == \"floor\"\n  |   tst CARG3, CARG2, asr #31\t\t// iszero = ((ztest & signmask) == 0)\n  |.else\n  |   bics CARG3, CARG3, CARG2, asr #31\t// iszero = ((ztest & ~signmask) == 0)\n  |.endif\n  |.if hf == 1\n  |  vmoveq d0, CARG1, CARG2\n  |.endif\n  |  bxeq lr\t\t\t\t// iszero: done.\n  |  mvn CARG4, #1\n  |  cmp RB, #0\n  |  lslpl CARG3, CARG4, RB\n  |  mvnmi CARG3, #0\n  |  add RB, RB, #32\n  |  subs CARG1, CARG1, CARG4, lsl RB\t// lo = lo-lomask\n  |  sbc CARG2, CARG2, CARG3\t\t// hi = hi-himask+carry\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |\n  |2:  // |x| < 1:\n  |  bxcs lr\t\t\t\t// |x| is not finite.\n  |  orr CARG3, CARG3, CARG1\t\t// ztest = (2*hi) | lo\n  |.if \"func\" == \"floor\"\n  |  tst CARG3, CARG2, asr #31\t\t// iszero = ((ztest & signmask) == 0)\n  |.else\n  |  bics CARG3, CARG3, CARG2, asr #31\t// iszero = ((ztest & ~signmask) == 0)\n  |.endif\n  |  mov CARG1, #0\t\t\t// lo = 0\n  |  and CARG2, CARG2, #0x80000000\n  |  ldrne CARG4, <9\t\t\t// hi = sign(x) | (iszero ? 0.0 : 1.0)\n  |  orrne CARG2, CARG2, CARG4\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |.endmacro\n  |\n  |9:\n  |  .long 0x3ff00000\t\t\t// hiword(+1.0)\n  |\n  |->vm_floor:\n  |.if HFABI\n  |  vm_round floor, 1\n  |.endif\n  |->vm_floor_sf:\n  |  vm_round floor, 0\n  |\n  |->vm_ceil:\n  |.if HFABI\n  |  vm_round ceil, 1\n  |.endif\n  |->vm_ceil_sf:\n  |  vm_round ceil, 0\n  |\n  |.macro vm_trunc, hf\n  |.if JIT\n  |.if hf == 1\n  |  vmov CARG1, CARG2, d0\n  |.endif\n  |  lsl CARG3, CARG2, #1\n  |  adds RB, CARG3, #0x00200000\n  |  andpl CARG2, CARG2, #0x80000000\t// |x| < 1? hi = sign(x), lo = 0.\n  |  movpl CARG1, #0\n  |.if hf == 1\n  |  vmovpl d0, CARG1, CARG2\n  |.endif\n  |  bxpl lr\n  |  mvn CARG4, #0x3cc\n  |  subs RB, CARG4, RB, asr #21\t// 2^0: RB = 51, 2^51: RB = 0.\n  |  bxlo lr\t\t\t\t// |x| >= 2^52: already done.\n  |  mvn CARG4, #1\n  |  and CARG1, CARG1, CARG4, lsl RB\t// lo &= lomask\n  |  subs RB, RB, #32\n  |  andpl CARG2, CARG2, CARG4, lsl RB\t// |x| <= 2^20: hi &= himask\n  |.if hf == 1\n  |  vmov d0, CARG1, CARG2\n  |.endif\n  |  bx lr\n  |.endif\n  |.endmacro\n  |\n  |->vm_trunc:\n  |.if HFABI\n  |  vm_trunc 1\n  |.endif\n  |->vm_trunc_sf:\n  |  vm_trunc 0\n  |\n  |  // double lj_vm_mod(double dividend, double divisor);\n  |->vm_mod:\n  |.if FPU\n  |  // Special calling convention. Also, RC (r11) is not preserved.\n  |  vdiv.f64 d0, d6, d7\n  |   mov RC, lr\n  |  vmov CARG1, CARG2, d0\n  |  bl ->vm_floor_sf\n  |  vmov d0, CARG1, CARG2\n  |  vmul.f64 d0, d0, d7\n  |   mov lr, RC\n  |  vsub.f64 d6, d6, d0\n  |  bx lr\n  |.else\n  |  push {r0, r1, r2, r3, r4, lr}\n  |  bl extern __aeabi_ddiv\n  |  bl ->vm_floor_sf\n  |  ldrd CARG34, [sp, #8]\n  |  bl extern __aeabi_dmul\n  |  ldrd CARG34, [sp]\n  |  eor CARG2, CARG2, #0x80000000\n  |  bl extern __aeabi_dadd\n  |  add sp, sp, #20\n  |  pop {pc}\n  |.endif\n  |\n  |  // int lj_vm_modi(int dividend, int divisor);\n  |->vm_modi:\n  |  ands RB, CARG1, #0x80000000\n  |  rsbmi CARG1, CARG1, #0\t\t// a = |dividend|\n  |  eor RB, RB, CARG2, asr #1\t\t// Keep signdiff and sign(divisor).\n  |  cmp CARG2, #0\n  |  rsbmi CARG2, CARG2, #0\t\t// b = |divisor|\n  |  subs CARG4, CARG2, #1\n  |  cmpne CARG1, CARG2\n  |  moveq CARG1, #0\t\t\t// if (b == 1 || a == b) a = 0\n  |  tsthi CARG2, CARG4\n  |  andeq CARG1, CARG1, CARG4\t\t// else if ((b & (b-1)) == 0) a &= b-1\n  |  bls >1\n  |  // Use repeated subtraction to get the remainder.\n  |  clz CARG3, CARG1\n  |  clz CARG4, CARG2\n  |  sub CARG4, CARG4, CARG3\n  |  rsbs CARG3, CARG4, #31\t\t// entry = (31-(clz(b)-clz(a)))*8\n  |  addne pc, pc, CARG3, lsl #3\t// Duff's device.\n  |  nop\n  {\n    int i;\n    for (i = 31; i >= 0; i--) {\n      |  cmp CARG1, CARG2, lsl #i\n      |  subhs CARG1, CARG1, CARG2, lsl #i\n    }\n  }\n  |1:\n  |  cmp CARG1, #0\n  |  cmpne RB, #0\n  |  submi CARG1, CARG1, CARG2\t\t// if (y != 0 && signdiff) y = y - b\n  |  eors CARG2, CARG1, RB, lsl #1\n  |  rsbmi CARG1, CARG1, #0\t\t// if (sign(divisor) != sign(y)) y = -y\n  |  bx lr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.define NEXT_TAB,\t\tTAB:CARG1\n  |.define NEXT_RES,\t\tCARG1\n  |.define NEXT_IDX,\t\tCARG2\n  |.define NEXT_TMP0,\t\tCARG3\n  |.define NEXT_TMP1,\t\tCARG4\n  |.define NEXT_LIM,\t\tr12\n  |.define NEXT_RES_PTR,\tsp\n  |.define NEXT_RES_VAL,\t[sp]\n  |.define NEXT_RES_KEY_I,\t[sp, #8]\n  |.define NEXT_RES_KEY_IT,\t[sp, #12]\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in CRET2.\n  |->vm_next:\n  |.if JIT\n  |  ldr NEXT_TMP0, NEXT_TAB->array\n  |   ldr NEXT_LIM, NEXT_TAB->asize\n  |  add NEXT_TMP0, NEXT_TMP0, NEXT_IDX, lsl #3\n  |1:  // Traverse array part.\n  |   subs NEXT_TMP1, NEXT_IDX, NEXT_LIM\n  |   bhs >5\n  |  ldr NEXT_TMP1, [NEXT_TMP0, #4]\n  |   str NEXT_IDX, NEXT_RES_KEY_I\n  |   add NEXT_TMP0, NEXT_TMP0, #8\n  |   add NEXT_IDX, NEXT_IDX, #1\n  |  checktp NEXT_TMP1, LJ_TNIL\n  |  beq <1\t\t\t\t// Skip holes in array part.\n  |  ldr NEXT_TMP0, [NEXT_TMP0, #-8]\n  |   mov NEXT_RES, NEXT_RES_PTR\n  |  strd NEXT_TMP0, NEXT_RES_VAL\t// Stores NEXT_TMP1, too.\n  |  mvn NEXT_TMP0, #~LJ_TISNUM\n  |  str NEXT_TMP0, NEXT_RES_KEY_IT\n  |  bx lr\n  |\n  |5:  // Traverse hash part.\n  |  ldr NEXT_TMP0, NEXT_TAB->hmask\n  |   ldr NODE:NEXT_RES, NEXT_TAB->node\n  |   add NEXT_TMP1, NEXT_TMP1, NEXT_TMP1, lsl #1\n  |  add NEXT_LIM, NEXT_LIM, NEXT_TMP0\n  |   add NODE:NEXT_RES, NODE:NEXT_RES, NEXT_TMP1, lsl #3\n  |6:\n  |  cmp NEXT_IDX, NEXT_LIM\n  |  bhi >9\n  |  ldr NEXT_TMP1, NODE:NEXT_RES->val.it\n  |  checktp NEXT_TMP1, LJ_TNIL\n  |   add NEXT_IDX, NEXT_IDX, #1\n  |  bxne lr\n  |  // Skip holes in hash part.\n  |  add NEXT_RES, NEXT_RES, #sizeof(Node)\n  |  b <6\n  |\n  |9:  // End of iteration. Set the key to nil (not the value).\n  |  mvn NEXT_TMP0, #0\n  |   mov NEXT_RES, NEXT_RES_PTR\n  |  str NEXT_TMP0, NEXT_RES_KEY_IT\n  |  bx lr\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions.\n  |// Saveregs already performed. Callback slot number in [sp], g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  ldr CTSTATE, GL:r12->ctype_state\n  |   add DISPATCH, r12, #GG_G2DISP\n  |.if FPU\n  |  str r4, SAVE_R4\n  |  add r4, sp, CFRAME_SPACE+4+8*8\n  |  vstmdb r4!, {d8-d15}\n  |.endif\n  |.if HFABI\n  |  add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])\n  |.endif\n  |  strd CARG34, CTSTATE->cb.gpr[2]\n  |  strd CARG12, CTSTATE->cb.gpr[0]\n  |.if HFABI\n  |  vstmdb r12!, {d0-d7}\n  |.endif\n  |  ldr CARG4, [sp]\n  |   add CARG3, sp, #CFRAME_SIZE\n  |    mov CARG1, CTSTATE\n  |  lsr CARG4, CARG4, #3\n  |   str CARG3, CTSTATE->cb.stack\n  |    mov CARG2, sp\n  |  str CARG4, CTSTATE->cb.slot\n  |  str CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  ldr BASE, L:CRET1->base\n  |    mv_vmstate CARG2, INTERP\n  |  ldr RC, L:CRET1->top\n  |    mov MASKR8, #255\n  |   ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |    mov L, CRET1\n  |  sub RC, RC, BASE\n  |    lsl MASKR8, MASKR8, #3\t\t// MASKR8 = 255*8.\n  |    st_vmstate CARG2\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]\n  |   str BASE, L->base\n  |   str CARG4, L->top\n  |  str L, CTSTATE->L\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RA\n  |  bl extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  ldrd CARG12, CTSTATE->cb.gpr[0]\n  |.if HFABI\n  |  vldr d0, CTSTATE->cb.fpr[0]\n  |.endif\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, r4\n  |  push {CCSTATE, r5, r11, lr}\n  |  mov CCSTATE, CARG1\n  |  ldr CARG1, CCSTATE:CARG1->spadj\n  |   ldrb CARG2, CCSTATE->nsp\n  |    add CARG3, CCSTATE, #offsetof(CCallState, stack)\n  |.if HFABI\n  |  add RB, CCSTATE, #offsetof(CCallState, fpr[0])\n  |.endif\n  |  mov r11, sp\n  |  sub sp, sp, CARG1\t\t\t// Readjust stack.\n  |   subs CARG2, CARG2, #1\n  |.if HFABI\n  |  vldm RB, {d0-d7}\n  |.endif\n  |    ldr RB, CCSTATE->func\n  |   bmi >2\n  |1:  // Copy stack slots.\n  |  ldr CARG4, [CARG3, CARG2, lsl #2]\n  |  str CARG4, [sp, CARG2, lsl #2]\n  |  subs CARG2, CARG2, #1\n  |  bpl <1\n  |2:\n  |  ldrd CARG12, CCSTATE->gpr[0]\n  |  ldrd CARG34, CCSTATE->gpr[2]\n  |  blx RB\n  |  mov sp, r11\n  |.if HFABI\n  |  add r12, CCSTATE, #offsetof(CCallState, fpr[4])\n  |.endif\n  |  strd CRET1, CCSTATE->gpr[0]\n  |.if HFABI\n  |  vstmdb r12!, {d0-d3}\n  |.endif\n  |  pop {CCSTATE, r5, r11, pc}\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RC = src2, JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, BASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TISNUM\n    |  bne >3\n    |  checktp CARG4, LJ_TISNUM\n    |  bne >4\n    |  cmp CARG1, CARG3\n    if (op == BC_ISLT) {\n      |  sublt PC, RB, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subge PC, RB, #0x20000\n    } else if (op == BC_ISLE) {\n      |  suble PC, RB, #0x20000\n    } else {\n      |  subgt PC, RB, #0x20000\n    }\n    |1:\n    |  ins_next\n    |\n    |3: // CARG12 is not an integer.\n    |.if FPU\n    |   vldr d0, [RA]\n    |  bhi ->vmeta_comp\n    |  // d0 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |   vldr d1, [RC]\n    |  blo >5\n    |  bhi ->vmeta_comp\n    |  // d0 is a number, CARG3 is an integer.\n    |  vmov s4, CARG3\n    |  vcvt.f64.s32 d1, s4\n    |  b >5\n    |4:  // CARG1 is an integer, CARG34 is not an integer.\n    |   vldr d1, [RC]\n    |  bhi ->vmeta_comp\n    |  // CARG1 is an integer, d1 is a number.\n    |  vmov s4, CARG1\n    |  vcvt.f64.s32 d0, s4\n    |5:  // d0 and d1 are numbers.\n    |  vcmp.f64 d0, d1\n    |  vmrs\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  sublo PC, RB, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subhs PC, RB, #0x20000\n    } else if (op == BC_ISLE) {\n      |  subls PC, RB, #0x20000\n    } else {\n      |  subhi PC, RB, #0x20000\n    }\n    |  b <1\n    |.else\n    |  bhi ->vmeta_comp\n    |  // CARG12 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |  movlo RA, RB\t\t\t// Save RB.\n    |  blo >5\n    |  bhi ->vmeta_comp\n    |  // CARG12 is a number, CARG3 is an integer.\n    |  mov CARG1, CARG3\n    |  mov RC, RA\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  mov CARG3, CARG1\n    |  mov CARG4, CARG2\n    |  ldrd CARG12, [RC]\t\t// Restore first operand.\n    |  b >5\n    |4:  // CARG1 is an integer, CARG34 is not an integer.\n    |  bhi ->vmeta_comp\n    |  // CARG1 is an integer, CARG34 is a number.\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  ldrd CARG34, [RC]\t\t// Restore second operand.\n    |5:  // CARG12 and CARG34 are numbers.\n    |  bl extern __aeabi_cdcmple\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  sublo PC, RA, #0x20000\n    } else if (op == BC_ISGE) {\n      |  subhs PC, RA, #0x20000\n    } else if (op == BC_ISLE) {\n      |  subls PC, RA, #0x20000\n    } else {\n      |  subhi PC, RA, #0x20000\n    }\n    |  b <1\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RC = src2, JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, BASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TISNUM\n    |  cmnls CARG4, #-LJ_TISNUM\n    if (vk) {\n      |  bls ->BC_ISEQN_Z\n    } else {\n      |  bls ->BC_ISNEN_Z\n    }\n    |  // Either or both types are not numbers.\n    |.if FFI\n    |  checktp CARG2, LJ_TCDATA\n    |  checktpne CARG4, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG2, CARG4\t\t\t// Compare types.\n    |  bne >2\t\t\t\t// Not the same type?\n    |  checktp CARG2, LJ_TISPRI\n    |  bhs >1\t\t\t\t// Same type and primitive type?\n    |\n    |  // Same types and not a primitive type. Compare GCobj or pvalue.\n    |  cmp CARG1, CARG3\n    if (vk) {\n      |  bne >3\t\t\t\t// Different GCobjs or pvalues?\n      |1:  // Branch if same.\n      |  sub PC, RB, #0x20000\n      |2:  // Different.\n      |  ins_next\n      |3:\n      |  checktp CARG2, LJ_TISTABUD\n      |  bhi <2\t\t\t\t// Different objects and not table/ud?\n    } else {\n      |  beq >1\t\t\t\t// Same GCobjs or pvalues?\n      |  checktp CARG2, LJ_TISTABUD\n      |  bhi >2\t\t\t\t// Different objects and not table/ud?\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    if (vk) {\n      |  beq <2\t\t\t// No metatable?\n    } else {\n      |  beq >2\t\t\t// No metatable?\n    }\n    |  ldrb RA, TAB:RA->nomm\n    |   mov CARG4, #1-vk\t\t// ne = 0 or 1.\n    |   mov CARG2, CARG1\n    |  tst RA, #1<<MM_eq\n    |  beq ->vmeta_equal\t\t// 'no __eq' flag not set?\n    if (vk) {\n      |  b <2\n    } else {\n      |2:  // Branch if different.\n      |  sub PC, RB, #0x20000\n      |1:  // Same.\n      |  ins_next\n    }\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RC = str_const (~), JMP with RC = target\n    |   mvn RC, RC\n    |  ldrd CARG12, [BASE, RA]\n    |    ldrh RB, [PC, #2]\n    |   ldr STR:CARG3, [KBASE, RC, lsl #2]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TSTR\n    |.if FFI\n    |  bne >7\n    |  cmp CARG1, CARG3\n    |.else\n    |  cmpeq CARG1, CARG3\n    |.endif\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n      |1:\n    } else {\n      |1:\n      |  subne PC, RB, #0x20000\n    }\n    |  ins_next\n    |\n    |.if FFI\n    |7:\n    |  checktp CARG2, LJ_TCDATA\n    |  bne <1\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RC = num_const (~), JMP with RC = target\n    |   lsl RC, RC, #3\n    |  ldrd CARG12, [RA, BASE]!\n    |    ldrh RB, [PC, #2]\n    |   ldrd CARG34, [RC, KBASE]!\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  checktp CARG2, LJ_TISNUM\n    |  bne >3\n    |  checktp CARG4, LJ_TISNUM\n    |  bne >4\n    |  cmp CARG1, CARG3\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n      |1:\n    } else {\n      |1:\n      |  subne PC, RB, #0x20000\n    }\n    |2:\n    |  ins_next\n    |\n    |3:  // CARG12 is not an integer.\n    |.if FFI\n    |  bhi >7\n    |.else\n    if (!vk) {\n      |  subhi PC, RB, #0x20000\n    }\n    |  bhi <2\n    |.endif\n    |.if FPU\n    |  checktp CARG4, LJ_TISNUM\n    |  vmov s4, CARG3\n    |   vldr d0, [RA]\n    |  vldrlo d1, [RC]\n    |  vcvths.f64.s32 d1, s4\n    |  b >5\n    |4:  // CARG1 is an integer, d1 is a number.\n    |  vmov s4, CARG1\n    |   vldr d1, [RC]\n    |  vcvt.f64.s32 d0, s4\n    |5:  // d0 and d1 are numbers.\n    |  vcmp.f64 d0, d1\n    |  vmrs\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n    } else {\n      |  subne PC, RB, #0x20000\n    }\n    |  b <2\n    |.else\n    |  // CARG12 is a number.\n    |  checktp CARG4, LJ_TISNUM\n    |  movlo RA, RB\t\t\t// Save RB.\n    |  blo >5\n    |  // CARG12 is a number, CARG3 is an integer.\n    |  mov CARG1, CARG3\n    |  mov RC, RA\n    |4:  // CARG1 is an integer, CARG34 is a number.\n    |  mov RA, RB\t\t\t// Save RB.\n    |  bl extern __aeabi_i2d\n    |  ldrd CARG34, [RC]\t\t// Restore other operand.\n    |5:  // CARG12 and CARG34 are numbers.\n    |  bl extern __aeabi_cdcmpeq\n    if (vk) {\n      |  subeq PC, RA, #0x20000\n    } else {\n      |  subne PC, RA, #0x20000\n    }\n    |  b <2\n    |.endif\n    |\n    |.if FFI\n    |7:\n    |  checktp CARG2, LJ_TCDATA\n    |  bne <1\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RC = primitive_type (~), JMP with RC = target\n    |  ldrd CARG12, [BASE, RA]\n    |   ldrh RB, [PC, #2]\n    |   add PC, PC, #4\n    |  mvn RC, RC\n    |   add RB, PC, RB, lsl #2\n    |.if FFI\n    |  checktp CARG2, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG2, RC\n    if (vk) {\n      |  subeq PC, RB, #0x20000\n    } else {\n      |  subne PC, RB, #0x20000\n    }\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RC = src, JMP with RC = target\n    |  add RC, BASE, RC, lsl #3\n    |   ldrh RB, [PC, #2]\n    |  ldrd CARG12, [RC]\n    |   add PC, PC, #4\n    |   add RB, PC, RB, lsl #2\n    |  checktp CARG2, LJ_TTRUE\n    if (op == BC_ISTC || op == BC_IST) {\n      |  subls PC, RB, #0x20000\n      if (op == BC_ISTC) {\n\t|  strdls CARG12, [BASE, RA]\n      }\n    } else {\n      |  subhi PC, RB, #0x20000\n      if (op == BC_ISFC) {\n\t|  strdhi CARG12, [BASE, RA]\n      }\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RC = -type\n    |  ldrd CARG12, [BASE, RA]\n    |   ins_next1\n    |  cmn CARG2, RC\n    |   ins_next2\n    |  bne ->vmeta_istype\n    |   ins_next3\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RC = -(TISNUM-1)\n    |  ldrd CARG12, [BASE, RA]\n    |   ins_next1\n    |  checktp CARG2, LJ_TISNUM\n    |   ins_next2\n    |  bhs ->vmeta_istype\n    |   ins_next3\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |   ins_next1\n    |  ldrd CARG12, [BASE, RC]\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RC = src\n    |  add RC, BASE, RC, lsl #3\n    |   ins_next1\n    |  ldr CARG1, [RC, #4]\n    |   add RA, BASE, RA\n    |   ins_next2\n    |  checktp CARG1, LJ_TTRUE\n    |  mvnls CARG2, #~LJ_TFALSE\n    |  mvnhi CARG2, #~LJ_TTRUE\n    |  str CARG2, [RA, #4]\n    |   ins_next3\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |  ldrd CARG12, [BASE, RC]\n    |   ins_next1\n    |   ins_next2\n    |  checktp CARG2, LJ_TISNUM\n    |  bhi ->vmeta_unm\n    |  eorne CARG2, CARG2, #0x80000000\n    |  bne >5\n    |  rsbseq CARG1, CARG1, #0\n    |  ldrdvs CARG12, >9\n    |5:\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |\n    |.align 8\n    |9:\n    |  .long 0x00000000, 0x41e00000\t// 2^31.\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RC = src\n    |  lsl RC, RC, #3\n    |  ldrd CARG12, [BASE, RC]\n    |  checkstr CARG2, >2\n    |  ldr CARG1, STR:CARG1->len\n    |1:\n    |  mvn CARG2, #~LJ_TISNUM\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |2:\n    |  checktab CARG2, ->vmeta_len\n#if LJ_52\n    |  ldr TAB:CARG3, TAB:CARG1->metatable\n    |  cmp TAB:CARG3, #0\n    |  bne >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  .IOS mov RC, BASE\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  .IOS mov BASE, RC\n    |  b <1\n#if LJ_52\n    |9:\n    |  ldrb CARG4, TAB:CARG3->nomm\n    |  tst CARG4, #1<<MM_len\n    |  bne <3\t\t\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithcheck, cond, ncond, target\n    ||if (vk == 1) {\n    |   cmn CARG4, #-LJ_TISNUM\n    |    cmn..cond CARG2, #-LJ_TISNUM\n    ||} else {\n    |   cmn CARG2, #-LJ_TISNUM\n    |    cmn..cond CARG4, #-LJ_TISNUM\n    ||}\n    |  b..ncond target\n    |.endmacro\n    |.macro ins_arithcheck_int, target\n    |  ins_arithcheck eq, ne, target\n    |.endmacro\n    |.macro ins_arithcheck_num, target\n    |  ins_arithcheck lo, hs, target\n    |.endmacro\n    |\n    |.macro ins_arithpre\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   .if FPU\n    |   ldrd CARG12, [RB, BASE]!\n    |    ldrd CARG34, [RC, KBASE]!\n    |   .else\n    |   ldrd CARG12, [BASE, RB]\n    |    ldrd CARG34, [KBASE, RC]\n    |   .endif\n    ||  break;\n    ||case 1:\n    |   .if FPU\n    |   ldrd CARG34, [RB, BASE]!\n    |    ldrd CARG12, [RC, KBASE]!\n    |   .else\n    |   ldrd CARG34, [BASE, RB]\n    |    ldrd CARG12, [KBASE, RC]\n    |   .endif\n    ||  break;\n    ||default:\n    |   .if FPU\n    |   ldrd CARG12, [RB, BASE]!\n    |    ldrd CARG34, [RC, BASE]!\n    |   .else\n    |   ldrd CARG12, [BASE, RB]\n    |    ldrd CARG34, [BASE, RC]\n    |   .endif\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithpre_fpu, reg1, reg2\n    |.if FPU\n    ||if (vk == 1) {\n    |  vldr reg2, [RB]\n    |  vldr reg1, [RC]\n    ||} else {\n    |  vldr reg1, [RB]\n    |  vldr reg2, [RC]\n    ||}\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithpost_fpu, reg\n    |   ins_next1\n    |  add RA, BASE, RA\n    |   ins_next2\n    |  vstr reg, [RA]\n    |   ins_next3\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins, fpcall\n    |  ins_arithpre\n    |.if \"intins\" ~= \"vm_modi\" and not FPU\n    |   ins_next1\n    |.endif\n    |  ins_arithcheck_int >5\n    |.if \"intins\" == \"smull\"\n    |  smull CARG1, RC, CARG3, CARG1\n    |  cmp RC, CARG1, asr #31\n    |  ins_arithfallback bne\n    |.elif \"intins\" == \"vm_modi\"\n    |  movs CARG2, CARG3\n    |  ins_arithfallback beq\n    |  bl ->vm_modi\n    |  mvn CARG2, #~LJ_TISNUM\n    |.else\n    |  intins CARG1, CARG1, CARG3\n    |  ins_arithfallback bvs\n    |.endif\n    |4:\n    |.if \"intins\" == \"vm_modi\" or FPU\n    |   ins_next1\n    |.endif\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |5:  // FP variant.\n    |  ins_arithpre_fpu d6, d7\n    |  ins_arithfallback ins_arithcheck_num\n    |.if FPU\n    |.if \"intins\" == \"vm_modi\"\n    |  bl fpcall\n    |.else\n    |  fpins d6, d6, d7\n    |.endif\n    |  ins_arithpost_fpu d6\n    |.else\n    |  bl fpcall\n    |.if \"intins\" ~= \"vm_modi\"\n    |  ins_next1\n    |.endif\n    |  b <4\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins, fpcall\n    |  ins_arithpre\n    |.if \"fpins\" ~= \"extern\" or HFABI\n    |  ins_arithpre_fpu d0, d1\n    |.endif\n    |  ins_arithfallback ins_arithcheck_num\n    |.if \"fpins\" == \"extern\"\n    |  .IOS mov RC, BASE\n    |  bl fpcall\n    |  .IOS mov BASE, RC\n    |.elif FPU\n    |  fpins d0, d0, d1\n    |.else\n    |  bl fpcall\n    |.endif\n    |.if (\"fpins\" ~= \"extern\" or HFABI) and FPU\n    |  ins_arithpost_fpu d0\n    |.else\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |.endif\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arithdn adds, vadd.f64, extern __aeabi_dadd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arithdn subs, vsub.f64, extern __aeabi_dsub\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arithdn smull, vmul.f64, extern __aeabi_dmul\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp vdiv.f64, extern __aeabi_ddiv\n    break;\n  case BC_MODVN: case BC_MODNV: case BC_MODVV:\n    |  ins_arithdn vm_modi, vm_mod, ->vm_mod\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  ins_arithfp extern, extern pow\n    break;\n\n  case BC_CAT:\n    |  decode_RB8 RC, INS\n    |   decode_RC8 RB, INS\n    |  // RA = dst*8, RC = src_start*8, RB = src_end*8  (note: RB/RC swapped!)\n    |  sub CARG3, RB, RC\n    |   str BASE, L->base\n    |  add CARG2, BASE, RB\n    |->BC_CAT_Z:\n    |  // RA = dst*8, RC = src_start*8, CARG2 = top-1\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  lsr CARG3, CARG3, #3\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  ldr BASE, L->base\n    |  cmp CRET1, #0\n    |  bne ->vmeta_binop\n    |  ldrd CARG34, [BASE, RC]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\t\t// Copy result to RA.\n    |   ins_next3\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RC = str_const (~)\n    |  mvn RC, RC\n    |   ins_next1\n    |  ldr CARG1, [KBASE, RC, lsl #2]\n    |  mvn CARG2, #~LJ_TSTR\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RC = cdata_const (~)\n    |  mvn RC, RC\n    |   ins_next1\n    |  ldr CARG1, [KBASE, RC, lsl #2]\n    |  mvn CARG2, #~LJ_TCDATA\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, (RC = int16_literal)\n    |  mov CARG1, INS, asr #16\t\t\t// Refetch sign-extended reg.\n    |  mvn CARG2, #~LJ_TISNUM\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RC = num_const\n    |  lsl RC, RC, #3\n    |   ins_next1\n    |  ldrd CARG12, [KBASE, RC]\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RC = primitive_type (~)\n    |  add RA, BASE, RA\n    |  mvn RC, RC\n    |   ins_next1\n    |   ins_next2\n    |  str RC, [RA, #4]\n    |   ins_next3\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RC = end\n    |  add RA, BASE, RA\n    |   add RC, BASE, RC, lsl #3\n    |  mvn CARG1, #~LJ_TNIL\n    |  str CARG1, [RA, #4]\n    |   add RA, RA, #8\n    |1:\n    |  str CARG1, [RA, #4]\n    |  cmp RA, RC\n    |   add RA, RA, #8\n    |  blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RC = uvnum\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsl RC, RC, #2\n    |   add RC, RC, #offsetof(GCfuncL, uvptr)\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RC]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |  ldrd CARG34, [CARG2]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RC = src\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    lsl RC, RC, #3\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldrd CARG34, [BASE, RC]\n    |  ldrb RB, UPVAL:CARG2->marked\n    |  ldrb RC, UPVAL:CARG2->closed\n    |    ldr CARG2, UPVAL:CARG2->v\n    |  tst RB, #LJ_GC_BLACK\t\t// isblack(uv)\n    |   add RB, CARG4, #-LJ_TISGCV\n    |  cmpne RC, #0\n    |   strd CARG34, [CARG2]\n    |  bne >2\t\t\t\t// Upvalue is closed and black?\n    |1:\n    |   ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  cmn RB, #-(LJ_TNUMX - LJ_TISGCV)\n    |   ldrbhi RC, GCOBJ:CARG3->gch.marked\n    |  bls <1\t\t\t\t// tvisgcv(v)\n    |    sub CARG1, DISPATCH, #-GG_DISP2G\n    |   tst RC, #LJ_GC_WHITES\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if IOS\n    |  beq <1\n    |  mov RC, BASE\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RC\n    |.else\n    |  blne extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.endif\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    mvn RC, RC\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldr STR:CARG3, [KBASE, RC, lsl #2]\n    |  ldrb RB, UPVAL:CARG2->marked\n    |     ldrb RC, UPVAL:CARG2->closed\n    |   ldr CARG2, UPVAL:CARG2->v\n    |    mvn CARG4, #~LJ_TSTR\n    |  tst RB, #LJ_GC_BLACK\t\t// isblack(uv)\n    |    ldrb RB, STR:CARG3->marked\n    |   strd CARG34, [CARG2]\n    |  bne >2\n    |1:\n    |   ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  tst RB, #LJ_GC_WHITES\t\t// iswhite(str)\n    |  cmpne RC, #0\n    |   sub CARG1, DISPATCH, #-GG_DISP2G\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if IOS\n    |  beq <1\n    |  mov RC, BASE\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RC\n    |.else\n    |  blne extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.endif\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RC = num_const\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |    lsl RC, RC, #3\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |    ldrd CARG34, [KBASE, RC]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [CARG2]\n    |   ins_next3\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RC = primitive_type (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   lsr RA, RA, #1\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA]\n    |   mvn RC, RC\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   ins_next1\n    |   ins_next2\n    |  str RC, [CARG2, #4]\n    |   ins_next3\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RC = target\n    |  ldr CARG3, L->openupval\n    |   add RC, PC, RC, lsl #2\n    |   str BASE, L->base\n    |  cmp CARG3, #0\n    |   sub PC, RC, #0x20000\n    |  beq >1\n    |   mov CARG1, L\n    |   add CARG2, BASE, RA\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  ldr BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RC = proto_const (~) (holding function prototype)\n    |  mvn RC, RC\n    |   str BASE, L->base\n    |  ldr CARG2, [KBASE, RC, lsl #2]\n    |   str PC, SAVE_PC\n    |  ldr CARG3, [BASE, FRAME_FUNC]\n    |   mov CARG1, L\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  ldr BASE, L->base\n    |  mvn CARG2, #~LJ_TFUNC\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RC = (hbits|asize) | tab_const (~)\n    if (op == BC_TDUP) {\n      |  mvn RC, RC\n    }\n    |  ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]\n    |   ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]\n    |    str BASE, L->base\n    |    str PC, SAVE_PC\n    |  cmp CARG3, CARG4\n    |   mov CARG1, L\n    |  bhs >5\n    |1:\n    if (op == BC_TNEW) {\n      |  lsl CARG2, RC, #21\n      |   lsr CARG3, RC, #11\n      |  asr RC, CARG2, #21\n      |  lsr CARG2, CARG2, #21\n      |  cmn RC, #1\n      |  addeq CARG2, CARG2, #2\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns GCtab *.\n    } else {\n      |  ldr CARG2, [KBASE, RC, lsl #2]\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns GCtab *.\n    }\n    |  ldr BASE, L->base\n    |  mvn CARG2, #~LJ_TTAB\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    |5:\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mov CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RC = str_const (~)\n  case BC_GSET:\n    |  // RA = dst*8, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   mvn RC, RC\n    |  ldr TAB:CARG1, LFUNC:CARG2->env\n    |   ldr STR:RC, [KBASE, RC, lsl #2]\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  ldrd TAB:CARG12, [BASE, RB]\n    |   ldrd CARG34, [BASE, RC]\n    |  checktab CARG2, ->vmeta_tgetv  // STALL: load CARG12.\n    |   checktp CARG4, LJ_TISNUM\t// Integer key?\n    |  ldreq CARG4, TAB:CARG1->array\n    |    ldreq CARG2, TAB:CARG1->asize\n    |   bne >9\n    |\n    |  add CARG4, CARG4, CARG3, lsl #3\n    |    cmp CARG3, CARG2\t\t// In array part?\n    |  ldrdlo CARG34, [CARG4]\n    |    bhs ->vmeta_tgetv\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  beq >5\n    |1:\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cmp TAB:CARG2, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG2->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  decode_RB8 RB, INS\t\t// Restore RB.\n    |  b ->vmeta_tgetv\n    |\n    |9:\n    |  checktp CARG4, LJ_TSTR\t\t// String key?\n    |   moveq STR:RC, CARG3\n    |  beq ->BC_TGETS_Z\n    |  b ->vmeta_tgetv\n    break;\n  case BC_TGETS:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst*8, RB = table*8, RC = str_const (~)\n    |  ldrd CARG12, [BASE, RB]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #2]  // STALL: early RC.\n    |  checktab CARG2, ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  ldr CARG3, TAB:CARG1->hmask\n    |   ldr CARG4, STR:RC->sid\n    |    ldr NODE:INS, TAB:CARG1->node\n    |     mov TAB:RB, TAB:CARG1\n    |  and CARG3, CARG3, CARG4\t\t\t// idx = str->sid & tab->hmask\n    |  add CARG3, CARG3, CARG3, lsl #1\n    |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n    |1:\n    |  ldrd CARG12, NODE:INS->key  // STALL: early NODE:INS.\n    |   ldrd CARG34, NODE:INS->val\n    |    ldr NODE:INS, NODE:INS->next\n    |  checktp CARG2, LJ_TSTR\n    |  cmpeq CARG1, STR:RC\n    |  bne >4\n    |   checktp CARG4, LJ_TNIL\n    |   beq >5\n    |3:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |4:  // Follow hash chain.\n    |  cmp NODE:INS, #0\n    |  bne <1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |   mov CARG3, #0  // Optional clear of undef. value (during load stall).\n    |   mvn CARG4, #~LJ_TNIL\n    |  cmp TAB:CARG1, #0\n    |  beq <3\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG1->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <3\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst*8, RB = table*8, RC = index\n    |  ldrd CARG12, [BASE, RB]\n    |  checktab CARG2, ->vmeta_tgetb  // STALL: load CARG12.\n    |   ldr CARG3, TAB:CARG1->asize\n    |  ldr CARG4, TAB:CARG1->array\n    |  lsl CARG2, RC, #3\n    |   cmp RC, CARG3\n    |  ldrdlo CARG34, [CARG4, CARG2]\n    |   bhs ->vmeta_tgetb\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  beq >5\n    |1:\n    |   ins_next2\n    |  strd CARG34, [BASE, RA]\n    |   ins_next3\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cmp TAB:CARG2, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb CARG2, TAB:CARG2->nomm\n    |  tst CARG2, #1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\n    break;\n  case BC_TGETR:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  ldr TAB:CARG1, [BASE, RB]\n    |   ldr CARG2, [BASE, RC]\n    |  ldr CARG4, TAB:CARG1->array\n    |    ldr CARG3, TAB:CARG1->asize\n    |  add CARG4, CARG4, CARG2, lsl #3\n    |    cmp CARG2, CARG3\t\t// In array part?\n    |    bhs ->vmeta_tgetr\n    |  ldrd CARG12, [CARG4]\n    |->BC_TGETR_Z:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, [BASE, RA]\n    |   ins_next3\n    break;\n\n  case BC_TSETV:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  ldrd TAB:CARG12, [BASE, RB]\n    |   ldrd CARG34, [BASE, RC]\n    |  checktab CARG2, ->vmeta_tsetv  // STALL: load CARG12.\n    |   checktp CARG4, LJ_TISNUM\t// Integer key?\n    |  ldreq CARG2, TAB:CARG1->array\n    |    ldreq CARG4, TAB:CARG1->asize\n    |   bne >9\n    |\n    |  add CARG2, CARG2, CARG3, lsl #3\n    |    cmp CARG3, CARG4\t\t// In array part?\n    |  ldrlo INS, [CARG2, #4]\n    |    bhs ->vmeta_tsetv\n    |   ins_next1  // Overwrites RB!\n    |  checktp INS, LJ_TNIL\n    |  ldrb INS, TAB:CARG1->marked\n    |   ldrd CARG34, [BASE, RA]\n    |  beq >5\n    |1:\n    |  tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |   strd CARG34, [CARG2]\n    |  bne >7\n    |2:\n    |   ins_next2\n    |   ins_next3\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb RA, TAB:RA->nomm\n    |  tst RA, #1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  ldr INS, [PC, #-4]\t\t// Restore RA and RB.\n    |  decode_RB8 RB, INS\n    |  decode_RA8 RA, INS\n    |  b ->vmeta_tsetv\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG1, INS, CARG3\n    |  b <2\n    |\n    |9:\n    |  checktp CARG4, LJ_TSTR\t\t// String key?\n    |   moveq STR:RC, CARG3\n    |  beq ->BC_TSETS_Z\n    |  b ->vmeta_tsetv\n    break;\n  case BC_TSETS:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = src*8, RB = table*8, RC = str_const (~)\n    |  ldrd CARG12, [BASE, RB]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #2]  // STALL: early RC.\n    |  checktab CARG2, ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  ldr CARG3, TAB:CARG1->hmask\n    |   ldr CARG4, STR:RC->sid\n    |    ldr NODE:INS, TAB:CARG1->node\n    |     mov TAB:RB, TAB:CARG1\n    |  and CARG3, CARG3, CARG4\t\t\t// idx = str->sid & tab->hmask\n    |  add CARG3, CARG3, CARG3, lsl #1\n    |   mov CARG4, #0\n    |    add NODE:INS, NODE:INS, CARG3, lsl #3\t// node = tab->node + idx*3*8\n    |   strb CARG4, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |1:\n    |  ldrd CARG12, NODE:INS->key\n    |   ldr CARG4, NODE:INS->val.it\n    |    ldr NODE:CARG3, NODE:INS->next\n    |  checktp CARG2, LJ_TSTR\n    |  cmpeq CARG1, STR:RC\n    |  bne >5\n    |  ldrb CARG2, TAB:RB->marked\n    |   checktp CARG4, LJ_TNIL\t\t// Key found, but nil value?\n    |    ldrd CARG34, [BASE, RA]\n    |   beq >4\n    |2:\n    |  tst CARG2, #LJ_GC_BLACK\t\t// isblack(table)\n    |    strd CARG34, NODE:INS->val\n    |  bne >7\n    |3:\n    |   ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |  cmp TAB:CARG1, #0\n    |  beq <2\t\t\t\t// No metatable: done.\n    |  ldrb CARG1, TAB:CARG1->nomm\n    |  tst CARG1, #1<<MM_newindex\n    |  bne <2\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  movs NODE:INS, NODE:CARG3\n    |  bne <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  ldr TAB:CARG1, TAB:RB->metatable\n    |   mov CARG3, TMPDp\n    |   str PC, SAVE_PC\n    |  cmp TAB:CARG1, #0\t\t// No metatable: continue.\n    |   str BASE, L->base\n    |  ldrbne CARG2, TAB:CARG1->nomm\n    |   mov CARG1, L\n    |  beq >6\n    |  tst CARG2, #1<<MM_newindex\n    |  beq ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mvn CARG4, #~LJ_TSTR\n    |   str STR:RC, TMPDlo\n    |   mov CARG2, TAB:RB\n    |  str CARG4, TMPDhi\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  ldr BASE, L->base\n    |  ldrd CARG34, [BASE, RA]\n    |  strd CARG34, [CRET1]\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, CARG2, CARG3\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  decode_RB8 RB, INS\n    |   and RC, RC, #255\n    |  // RA = src*8, RB = table*8, RC = index\n    |  ldrd CARG12, [BASE, RB]\n    |  checktab CARG2, ->vmeta_tsetb  // STALL: load CARG12.\n    |   ldr CARG3, TAB:CARG1->asize\n    |  ldr RB, TAB:CARG1->array\n    |  lsl CARG2, RC, #3\n    |   cmp RC, CARG3\n    |  ldrdlo CARG34, [CARG2, RB]!\n    |   bhs ->vmeta_tsetb\n    |   ins_next1  // Overwrites RB!\n    |  checktp CARG4, LJ_TNIL\n    |  ldrb INS, TAB:CARG1->marked\n    |   ldrd CARG34, [BASE, RA]\n    |  beq >5\n    |1:\n    |  tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |    strd CARG34, [CARG2]\n    |  bne >7\n    |2:\n    |   ins_next2\n    |   ins_next3\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:RA, TAB:CARG1->metatable\n    |  cmp TAB:RA, #0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  ldrb RA, TAB:RA->nomm\n    |  tst RA, #1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  ldr INS, [PC, #-4]\t\t// Restore INS.\n    |  decode_RA8 RA, INS\n    |  b ->vmeta_tsetb\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG1, INS, CARG3\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  ldr TAB:CARG2, [BASE, RB]\n    |   ldr CARG3, [BASE, RC]\n    |     ldrb INS, TAB:CARG2->marked\n    |  ldr CARG1, TAB:CARG2->array\n    |    ldr CARG4, TAB:CARG2->asize\n    |     tst INS, #LJ_GC_BLACK\t\t// isblack(table)\n    |  add CARG1, CARG1, CARG3, lsl #3\n    |     bne >7\n    |2:\n    |    cmp CARG3, CARG4\t\t// In array part?\n    |    bhs ->vmeta_tsetr\n    |->BC_TSETR_Z:\n    |  ldrd CARG34, [BASE, RA]\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG34, [CARG1]\n    |   ins_next3\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, INS, RB\n    |  b <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RC = num_const (start index)\n    |  add RA, BASE, RA\n    |1:\n    |   ldr RB, SAVE_MULTRES\n    |  ldr TAB:CARG2, [RA, #-8]\t\t// Guaranteed to be a table.\n    |  ldr CARG1, [KBASE, RC, lsl #3]\t// Integer constant is in lo-word.\n    |   subs RB, RB, #8\n    |  ldr CARG4, TAB:CARG2->asize\n    |   beq >4\t\t\t\t// Nothing to copy?\n    |  add CARG3, CARG1, RB, lsr #3\n    |  cmp CARG3, CARG4\n    |   ldr CARG4, TAB:CARG2->array\n    |    add RB, RA, RB\n    |  bhi >5\n    |   add INS, CARG4, CARG1, lsl #3\n    |    ldrb CARG1, TAB:CARG2->marked\n    |3:  // Copy result slots to table.\n    |   ldrd CARG34, [RA], #8\n    |   strd CARG34, [INS], #8\n    |  cmp RA, RB\n    |  blo <3\n    |    tst CARG1, #LJ_GC_BLACK\t// isblack(table)\n    |    bne >7\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   str BASE, L->base\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  .IOS ldr BASE, L->base\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, CARG1, CARG3\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = nresults+1,) RC = extra_nargs\n    |  ldr CARG1, SAVE_MULTRES\n    |  decode_RC8 NARGS8:RC, INS\n    |  add NARGS8:RC, NARGS8:RC, CARG1\n    |  b ->BC_CALL_Z\n    break;\n  case BC_CALL:\n    |  decode_RC8 NARGS8:RC, INS\n    |  // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8\n    |->BC_CALL_Z:\n    |  mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  ldrd CARG34, [BASE, RA]!\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add BASE, BASE, #8\n    |  checkfunc CARG4, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs\n    |  ldr CARG1, SAVE_MULTRES\n    |  add NARGS8:RC, CARG1, RC, lsl #3\n    |  b ->BC_CALLT1_Z\n    break;\n  case BC_CALLT:\n    |  lsl NARGS8:RC, RC, #3\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |->BC_CALLT1_Z:\n    |  ldrd LFUNC:CARG34, [RA, BASE]!\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add RA, RA, #8\n    |  checkfunc CARG4, ->vmeta_callt\n    |  ldr PC, [BASE, FRAME_PC]\n    |->BC_CALLT2_Z:\n    |   mov RB, #0\n    |   ldrb CARG4, LFUNC:CARG3->ffid\n    |  tst PC, #FRAME_TYPE\n    |  bne >7\n    |1:\n    |  str LFUNC:CARG3, [BASE, FRAME_FUNC]  // Copy function down, but keep PC.\n    |  cmp NARGS8:RC, #0\n    |  beq >3\n    |2:\n    |  ldrd CARG12, [RA, RB]\n    |   add INS, RB, #8\n    |   cmp INS, NARGS8:RC\n    |  strd CARG12, [BASE, RB]\n    |    mov RB, INS\n    |   bne <2\n    |3:\n    |  cmp CARG4, #1\t\t\t// (> FF_C) Calling a fast function?\n    |  bhi >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  ldr INS, [PC, #-4]\n    |  decode_RA8 RA, INS\n    |  sub CARG1, BASE, RA\n    |  ldr LFUNC:CARG1, [CARG1, #-16]\n    |  ldr CARG1, LFUNC:CARG1->field_pc\n    |  ldr KBASE, [CARG1, #PC2PROTO(k)]\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  eor PC, PC, #FRAME_VARG\n    |  tst PC, #FRAME_TYPEP\t\t// Vararg frame below?\n    |  movne CARG4, #0\t\t\t// Clear ffid if no Lua function below.\n    |  bne <1\n    |  sub BASE, BASE, PC\n    |  ldr PC, [BASE, FRAME_PC]\n    |  tst PC, #FRAME_TYPE\n    |  movne CARG4, #0\t\t\t// Clear ffid if no Lua function below.\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA\n    |   mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  ldrd CARG34, [RA, #-16]\n    |   ldrd CARG12, [RA, #-8]\n    |    add BASE, RA, #8\n    |  strd CARG34, [RA, #8]\t\t// Copy state.\n    |   strd CARG12, [RA, #16]\t\t// Copy control var.\n    |  // STALL: locked CARG34.\n    |  ldrd LFUNC:CARG34, [RA, #-24]\n    |    mov NARGS8:RC, #16\t\t// Iterators get 2 arguments.\n    |  // STALL: load CARG34.\n    |  strd LFUNC:CARG34, [RA]\t\t// Copy callable.\n    |  checkfunc CARG4, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |->vm_IITERN:\n    |  // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA\n    |  ldr TAB:RB, [RA, #-16]\n    |  ldr CARG1, [RA, #-8]\t\t// Get index from control var.\n    |  ldr INS, TAB:RB->asize\n    |   ldr CARG2, TAB:RB->array\n    |    add PC, PC, #4\n    |1:  // Traverse array part.\n    |  subs RC, CARG1, INS\n    |   add CARG3, CARG2, CARG1, lsl #3\n    |  bhs >5\t\t\t\t// Index points after array part?\n    |   ldrd CARG34, [CARG3]\n    |   checktp CARG4, LJ_TNIL\n    |   addeq CARG1, CARG1, #1\t\t// Skip holes in array part.\n    |   beq <1\n    |  ldrh RC, [PC, #-2]\n    |   mvn CARG2, #~LJ_TISNUM\n    |    strd CARG34, [RA, #8]\n    |  add RC, PC, RC, lsl #2\n    |    add RB, CARG1, #1\n    |   strd CARG12, [RA]\n    |  sub PC, RC, #0x20000\n    |    str RB, [RA, #-8]\t\t// Update control var.\n    |3:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  ldr CARG4, TAB:RB->hmask\n    |   ldr NODE:RB, TAB:RB->node\n    |6:\n    |   add CARG1, RC, RC, lsl #1\n    |  cmp RC, CARG4\t\t\t// End of iteration? Branch to ITERL+1.\n    |   add NODE:CARG3, NODE:RB, CARG1, lsl #3  // node = tab->node + idx*3*8\n    |  bhi <3\n    |   ldrd CARG12, NODE:CARG3->val\n    |   checktp CARG2, LJ_TNIL\n    |   add RC, RC, #1\n    |   beq <6\t\t\t\t// Skip holes in hash part.\n    |  ldrh RB, [PC, #-2]\n    |   add RC, RC, INS\n    |    ldrd CARG34, NODE:CARG3->key\n    |   str RC, [RA, #-8]\t\t// Update control var.\n    |   strd CARG12, [RA, #8]\n    |  add RC, PC, RB, lsl #2\n    |  sub PC, RC, #0x20000\n    |    strd CARG34, [RA]\n    |  b <3\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RC = target (points to ITERN)\n    |  add RA, BASE, RA\n    |     add RC, PC, RC, lsl #2\n    |  ldrd CFUNC:CARG12, [RA, #-24]\n    |   ldr CARG3, [RA, #-12]\n    |    ldr CARG4, [RA, #-4]\n    |  checktp CARG2, LJ_TFUNC\n    |  ldrbeq CARG1, CFUNC:CARG1->ffid\n    |   checktpeq CARG3, LJ_TTAB\n    |    checktpeq CARG4, LJ_TNIL\n    |  cmpeq CARG1, #FF_next_N\n    |     subeq PC, RC, #0x20000\n    |  bne >5\n    |   ins_next1\n    |   ins_next2\n    |  mov CARG1, #0\n    |  mvn CARG2, #~LJ_KEYINDEX\n    |  strd CARG1, [RA, #-8]\t\t// Initialize control var.\n    |1:\n    |   ins_next3\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov CARG1, #BC_JMP\n    |   mov OP, #BC_ITERC\n    |  strb CARG1, [PC, #-4]\n    |   sub PC, RC, #0x20000\n    |.if JIT\n    |   ldrb CARG1, [PC]\n    |   cmp CARG1, #BC_ITERN\n    |   bne >6\n    |.endif\n    |   strb OP, [PC]\t\t\t// Subsumes ins_next1.\n    |   ins_next2\n    |  b <1\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]\n    |  ldrh CARG2, [PC, #2]\n    |  ldr TRACE:CARG1, [CARG1, CARG2, lsl #2]\n    |  // Subsumes ins_next1 and ins_next2.\n    |  ldr INS, TRACE:CARG1->startins\n    |  bfi INS, OP, #0, #8\n    |  str INS, [PC], #4\n    |  b <1\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  decode_RB8 RB, INS\n    |   decode_RC8 RC, INS\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  ldr CARG1, [BASE, FRAME_PC]\n    |  add RC, BASE, RC\n    |   add RA, BASE, RA\n    |  add RC, RC, #FRAME_VARG\n    |   add CARG4, RA, RB\n    |  sub CARG3, BASE, #8\t\t// CARG3 = vtop\n    |  sub RC, RC, CARG1\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  cmp RB, #0\n    |   sub CARG1, CARG3, RC\n    |  beq >5\t\t\t\t// Copy all varargs?\n    |   sub CARG4, CARG4, #16\n    |1:  // Copy vararg slots to destination slots.\n    |  cmp RC, CARG3\n    |  ldrdlo CARG12, [RC], #8\n    |  mvnhs CARG2, #~LJ_TNIL\n    |   cmp RA, CARG4\n    |  strd CARG12, [RA], #8\n    |   blo <1\n    |2:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  ldr CARG4, L->maxstack\n    |   cmp CARG1, #0\n    |   movle RB, #8\t\t\t// MULTRES = (0+1)*8\n    |   addgt RB, CARG1, #8\n    |  add CARG2, RA, CARG1\n    |   str RB, SAVE_MULTRES\n    |   ble <2\n    |  cmp CARG2, CARG4\n    |  bhi >7\n    |6:\n    |   ldrd CARG12, [RC], #8\n    |   strd CARG12, [RA], #8\n    |  cmp RC, CARG3\n    |  blo <6\n    |  b <2\n    |\n    |7:  // Grow stack for varargs.\n    |  lsr CARG2, CARG1, #3\n    |   str RA, L->top\n    |  mov CARG1, L\n    |   str BASE, L->base\n    |  sub RC, RC, BASE\t\t\t// Need delta, because BASE may change.\n    |   str PC, SAVE_PC\n    |  sub RA, RA, BASE\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  ldr BASE, L->base\n    |  add RA, BASE, RA\n    |  add RC, BASE, RC\n    |  sub CARG3, BASE, #8\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RC = extra results\n    |  ldr CARG1, SAVE_MULTRES\n    |   ldr PC, [BASE, FRAME_PC]\n    |    add RA, BASE, RA\n    |  add RC, CARG1, RC, lsl #3\n    |  b ->BC_RETM_Z\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |    add RA, BASE, RA\n    |->BC_RETM_Z:\n    |   str RC, SAVE_MULTRES\n    |1:\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV2_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return\n    |  ldr INS, [PC, #-4]\n    |  subs CARG4, RC, #8\n    |   sub CARG3, BASE, #8\n    |  beq >3\n    |2:\n    |  ldrd CARG12, [RA], #8\n    |   add BASE, BASE, #8\n    |   subs CARG4, CARG4, #8\n    |  strd CARG12, [BASE, #-16]\n    |   bne <2\n    |3:\n    |  decode_RA8 RA, INS\n    |  sub CARG4, CARG3, RA\n    |   decode_RB8 RB, INS\n    |  ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]\n    |5:\n    |  cmp RB, RC\t\t\t// More results expected?\n    |  bhi >6\n    |  mov BASE, CARG4\n    |  ldr CARG2, LFUNC:CARG1->field_pc\n    |   ins_next1\n    |   ins_next2\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next3\n    |\n    |6:  // Fill up results with nil.\n    |  mvn CARG2, #~LJ_TNIL\n    |  add BASE, BASE, #8\n    |   add RC, RC, #8\n    |  str CARG2, [BASE, #-12]\n    |  b <5\n    |\n    |->BC_RETV1_Z:  // Non-standard return case.\n    |  add RA, BASE, RA\n    |->BC_RETV2_Z:\n    |  tst CARG2, #FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, CARG2\n    |  ldr PC, [BASE, FRAME_PC]\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |   str RC, SAVE_MULTRES\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |   ldreq INS, [PC, #-4]\n    |  bne ->BC_RETV1_Z\n    if (op == BC_RET1) {\n      |  ldrd CARG12, [BASE, RA]\n    }\n    |  sub CARG4, BASE, #8\n    |   decode_RA8 RA, INS\n    if (op == BC_RET1) {\n      |  strd CARG12, [CARG4]\n    }\n    |  sub BASE, CARG4, RA\n    |   decode_RB8 RB, INS\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |5:\n    |  cmp RB, RC\n    |  bhi >6\n    |  ldr CARG2, LFUNC:CARG1->field_pc\n    |   ins_next1\n    |   ins_next2\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next3\n    |\n    |6:  // Fill up results with nil.\n    |  sub CARG2, CARG4, #4\n    |  mvn CARG3, #~LJ_TNIL\n    |  str CARG3, [CARG2, RC]\n    |  add RC, RC, #8\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];      .define FOR_TIDX,  [RA, #4]\n  |.define FOR_STOP, [RA, #8];  .define FOR_TSTOP, [RA, #12]\n  |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]\n  |.define FOR_EXT,  [RA, #24]; .define FOR_TEXT,  [RA, #28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RC = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ldrd CARG12, [RA, BASE]!\n    if (op != BC_JFORL) {\n      |   add RC, PC, RC, lsl #2\n    }\n    if (!vk) {\n      |  ldrd CARG34, FOR_STOP\n      |   checktp CARG2, LJ_TISNUM\n      |  ldr RB, FOR_TSTEP\n      |   bne >5\n      |  checktp CARG4, LJ_TISNUM\n      |   ldr CARG4, FOR_STEP\n      |  checktpeq RB, LJ_TISNUM\n      |  bne ->vmeta_for\n      |  cmp CARG4, #0\n      |  blt >4\n      |  cmp CARG1, CARG3\n    } else {\n      |  ldrd CARG34, FOR_STEP\n      |   checktp CARG2, LJ_TISNUM\n      |   bne >5\n      |  adds CARG1, CARG1, CARG3\n      |   ldr CARG4, FOR_STOP\n      if (op == BC_IFORL) {\n\t|  addvs RC, PC, #0x20000\t\t// Overflow: prevent branch.\n      } else {\n\t|  bvs >2\t\t\t\t// Overflow: do not enter mcode.\n      }\n      |  cmp CARG3, #0\n      |  blt >4\n      |  cmp CARG1, CARG4\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  subgt PC, RC, #0x20000\n    } else if (op == BC_JFORI) {\n      |  sub PC, RC, #0x20000\n      |  ldrhle RC, [PC, #-2]\n    } else if (op == BC_IFORL) {\n      |  suble PC, RC, #0x20000\n    }\n    if (vk) {\n      |  strd CARG12, FOR_IDX\n    }\n    |2:\n    |   ins_next1\n    |   ins_next2\n    |  strd CARG12, FOR_EXT\n    if (op == BC_JFORI || op == BC_JFORL) {\n      |  ble =>BC_JLOOP\n    }\n    |3:\n    |   ins_next3\n    |\n    |4:  // Invert check for negative step.\n    if (!vk) {\n      |  cmp CARG3, CARG1\n    } else {\n      |  cmp CARG4, CARG1\n    }\n    |  b <1\n    |\n    |5:  // FP loop.\n    if (!vk) {\n      |  cmnlo CARG4, #-LJ_TISNUM\n      |  cmnlo RB, #-LJ_TISNUM\n      |  bhs ->vmeta_for\n      |.if FPU\n      |  vldr d0, FOR_IDX\n      |  vldr d1, FOR_STOP\n      |  cmp RB, #0\n      |  vstr d0, FOR_EXT\n      |.else\n      |  cmp RB, #0\n      |   strd CARG12, FOR_EXT\n      |  blt >8\n      |.endif\n    } else {\n      |.if FPU\n      |  vldr d0, FOR_IDX\n      |  vldr d2, FOR_STEP\n      |  vldr d1, FOR_STOP\n      |  cmp CARG4, #0\n      |  vadd.f64 d0, d0, d2\n      |.else\n      |  cmp CARG4, #0\n      |  blt >8\n      |  bl extern __aeabi_dadd\n      |   strd CARG12, FOR_IDX\n      |  ldrd CARG34, FOR_STOP\n      |   strd CARG12, FOR_EXT\n      |.endif\n    }\n    |6:\n    |.if FPU\n    |  vcmpge.f64 d0, d1\n    |  vcmplt.f64 d1, d0\n    |  vmrs\n    |.else\n    |  bl extern __aeabi_cdcmple\n    |.endif\n    if (vk) {\n      |.if FPU\n      |  vstr d0, FOR_IDX\n      |  vstr d0, FOR_EXT\n      |.endif\n    }\n    if (op == BC_FORI) {\n      |  subhi PC, RC, #0x20000\n    } else if (op == BC_JFORI) {\n      |  sub PC, RC, #0x20000\n      |  ldrhls RC, [PC, #-2]\n      |  bls =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  subls PC, RC, #0x20000\n    } else {\n      |  bls =>BC_JLOOP\n    }\n    |  ins_next1\n    |  ins_next2\n    |  b <3\n    |\n    |.if not FPU\n    |8:  // Invert check for negative step.\n    if (vk) {\n      |  bl extern __aeabi_dadd\n      |  strd CARG12, FOR_IDX\n      |  strd CARG12, FOR_EXT\n    }\n    |  mov CARG3, CARG1\n    |  mov CARG4, CARG2\n    |  ldrd CARG12, FOR_STOP\n    |  b <6\n    |.endif\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RC = target\n    |  ldrd CARG12, [RA, BASE]!\n    if (op == BC_JITERL) {\n      |  cmn CARG2, #-LJ_TNIL\t\t// Stop if iterator returned nil.\n      |  strdne CARG12, [RA, #-8]\n      |  bne =>BC_JLOOP\n    } else {\n      |   add RC, PC, RC, lsl #2\n      |  // STALL: load CARG12.\n      |  cmn CARG2, #-LJ_TNIL\t\t// Stop if iterator returned nil.\n      |  subne PC, RC, #0x20000\t\t// Otherwise save control var + branch.\n      |  strdne CARG12, [RA, #-8]\n    }\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RC = target (loop extent)\n    |  // Note: RA/RC is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RC = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base (ignored), RC = traceno\n    |  ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]\n    |   mov CARG2, #0  // Traces on ARM don't store the trace number, so use 0.\n    |  ldr TRACE:RC, [CARG1, RC, lsl #2]\n    |   st_vmstate CARG2\n    |  ldr RA, TRACE:RC->mcode\n    |   str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]\n    |   str L, [DISPATCH, #DISPATCH_GL(tmpbuf.L)]\n    |  bx RA\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RC = target\n    |  add RC, PC, RC, lsl #2\n    |  sub PC, RC, #0x20000\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |  bhi ->vm_growstack_l\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n      |  ins_next2\n    }\n    |2:\n    |  cmp NARGS8:RC, CARG2, lsl #3\t// Check for missing parameters.\n    |   mvn CARG4, #~LJ_TNIL\n    |  blo >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD RC, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next3\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  strd CARG34, [BASE, NARGS8:RC]\n    |  add NARGS8:RC, NARGS8:RC, #8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   add CARG4, BASE, RC\n    |  add RA, RA, RC\n    |   str LFUNC:CARG3, [CARG4]\t// Store copy of LFUNC.\n    |   add CARG2, RC, #8+FRAME_VARG\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |   str CARG2, [CARG4, #4]\t\t// Store delta + FRAME_VARG.\n    |  bhs ->vm_growstack_l\n    |  ldrb RB, [PC, #-4+PC2PROTO(numparams)]\n    |   mov RA, BASE\n    |   mov RC, CARG4\n    |  cmp RB, #0\n    |   add BASE, CARG4, #8\n    |  beq >3\n    |  mvn CARG3, #~LJ_TNIL\n    |1:\n    |  cmp RA, RC\t\t\t// Less args than parameters?\n    |   ldrdlo CARG12, [RA], #8\n    |   movhs CARG2, CARG3\n    |    strlo CARG3, [RA, #-4]\t\t// Clear old fixarg slot (help the GC).\n    |2:\n    |  subs RB, RB, #1\n    |   strd CARG12, [CARG4, #8]!\n    |  bne <1\n    |3:\n    |  ins_next\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  ldr CARG4, CFUNC:CARG3->f\n    } else {\n      |  ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]\n    }\n    |   add CARG2, RA, NARGS8:RC\n    |   ldr CARG1, L->maxstack\n    |  add RC, BASE, NARGS8:RC\n    |    str BASE, L->base\n    |   cmp CARG2, CARG1\n    |  str RC, L->top\n    if (op == BC_FUNCCW) {\n      |  ldr CARG2, CFUNC:CARG3->f\n    }\n    |    mv_vmstate CARG3, C\n    |  mov CARG1, L\n    |   bhi ->vm_growstack_c\t\t// Need to grow stack.\n    |    st_vmstate CARG3\n    |  blx CARG4\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  ldr BASE, L->base\n    |    mv_vmstate CARG3, INTERP\n    |   ldr CRET2, L->top\n    |    str L, [DISPATCH, #DISPATCH_GL(cur_L)]\n    |   lsl RC, CRET1, #3\n    |    st_vmstate CARG3\n    |  ldr PC, [BASE, FRAME_PC]\n    |   sub RA, CRET2, RC\t\t// RA = L->top - nresults*8\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 0xe\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0xd\\n\\t.uleb128 0\\n\"\t/* def_cfa sp */\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 1\\n\",\t\t/* offset lr */\n\tfcofs, CFRAME_SIZE);\n    for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--)  /* offset r4-r11 */\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 2+(11-i));\n#if LJ_ARCH_HASFPU\n    for (i = 15; i >= 8; i--)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 %d, %d\\n\",\n\t64+2*i, 10+2*(15-i));\n    fprintf(ctx->fp, \"\\t.byte 0x84\\n\\t.uleb128 %d\\n\", 25);  /* offset r4 */\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long lj_vm_ffi_call\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 2\\n\"\t\t/* offset r11 */\n\t\"\\t.byte 0x85\\n\\t.uleb128 3\\n\"\t\t/* offset r5 */\n\t\"\\t.byte 0x84\\n\\t.uleb128 4\\n\"\t\t/* offset r4 */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xb\\n\"\t\t/* def_cfa_register r11 */\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_arm64.dasc",
    "content": "|// Low-level VM code for ARM64 CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch arm64\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// ARM64 registers and the AAPCS64 ABI 1.0 at a glance:\n|//\n|// x0-x17 temp, x19-x28 callee-saved, x29 fp, x30 lr\n|// x18 is reserved on most platforms. Don't use it, save it or restore it.\n|// x31 doesn't exist. Register number 31 either means xzr/wzr (zero) or sp,\n|// depending on the instruction.\n|// v0-v7 temp, v8-v15 callee-saved (only d8-d15 preserved), v16-v31 temp\n|//\n|// x0-x7/v0-v7 hold parameters and results.\n|\n|// Fixed register assignments for the interpreter.\n|\n|// The following must be C callee-save.\n|.define BASE,\t\tx19\t// Base of current Lua stack frame.\n|.define KBASE,\t\tx20\t// Constants of current Lua function.\n|.define PC,\t\tx21\t// Next PC.\n|.define GLREG,\t\tx22\t// Global state.\n|.define LREG,\t\tx23\t// Register holding lua_State (also in SAVE_L).\n|.define TISNUM,\tx24\t// Constant LJ_TISNUM << 47.\n|.define TISNUMhi,\tx25\t// Constant LJ_TISNUM << 15.\n|.define TISNIL,\tx26\t// Constant -1LL.\n|.define fp,\t\tx29\t// Yes, we have to maintain a frame pointer.\n|\n|.define ST_INTERP,\tw26\t// Constant -1.\n|\n|// The following temporaries are not saved across C calls, except for RA/RC.\n|.define RA,\t\tx27\n|.define RC,\t\tx28\n|.define RB,\t\tx17\n|.define RAw,\t\tw27\n|.define RCw,\t\tw28\n|.define RBw,\t\tw17\n|.define INS,\t\tx16\n|.define INSw,\t\tw16\n|.define ITYPE,\t\tx15\n|.define TMP0,\t\tx8\n|.define TMP1,\t\tx9\n|.define TMP2,\t\tx10\n|.define TMP3,\t\tx11\n|.define TMP0w,\t\tw8\n|.define TMP1w,\t\tw9\n|.define TMP2w,\t\tw10\n|.define TMP3w,\t\tw11\n|\n|// Calling conventions. Also used as temporaries.\n|.define CARG1,\t\tx0\n|.define CARG2,\t\tx1\n|.define CARG3,\t\tx2\n|.define CARG4,\t\tx3\n|.define CARG5,\t\tx4\n|.define CARG1w,\tw0\n|.define CARG2w,\tw1\n|.define CARG3w,\tw2\n|.define CARG4w,\tw3\n|.define CARG5w,\tw4\n|\n|.define FARG1,\t\td0\n|.define FARG2,\t\td1\n|\n|.define CRET1,\t\tx0\n|.define CRET1w,\tw0\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|\n|.define CFRAME_SPACE,\t208\n|//----- 16 byte aligned, <-- sp entering interpreter\n|.define SAVE_FP_LR_,\t192\n|.define SAVE_GPR_,\t112\t\t// 112+10*8: 64 bit GPR saves\n|.define SAVE_FPR_,\t48\t\t// 48+8*8: 64 bit FPR saves\n|// Unused\t\t[sp, #44]\t// 32 bit values\n|.define SAVE_NRES,\t[sp, #40]\n|.define SAVE_ERRF,\t[sp, #36]\n|.define SAVE_MULTRES,\t[sp, #32]\n|.define TMPD,\t\t[sp, #24]\t// 64 bit values\n|.define SAVE_L,\t[sp, #16]\n|.define SAVE_PC,\t[sp, #8]\n|.define SAVE_CFRAME,\t[sp, #0]\n|//----- 16 byte aligned, <-- sp while in interpreter.\n|\n|.define TMPDofs,\t#24\n|\n|.macro save_, gpr1, gpr2, fpr1, fpr2\n|  stp d..fpr2, d..fpr1, [sp, # SAVE_FPR_+(14-fpr1)*8]\n|  stp x..gpr2, x..gpr1, [sp, # SAVE_GPR_+(27-gpr1)*8]\n|.endmacro\n|.macro rest_, gpr1, gpr2, fpr1, fpr2\n|  ldp d..fpr2, d..fpr1, [sp, # SAVE_FPR_+(14-fpr1)*8]\n|  ldp x..gpr2, x..gpr1, [sp, # SAVE_GPR_+(27-gpr1)*8]\n|.endmacro\n|\n|.macro saveregs\n|  sub sp, sp, # CFRAME_SPACE\n|  stp fp, lr, [sp, # SAVE_FP_LR_]\n|  add fp, sp, # SAVE_FP_LR_\n|  stp x20, x19, [sp, # SAVE_GPR_+(27-19)*8]\n|  save_ 21, 22, 8, 9\n|  save_ 23, 24, 10, 11\n|  save_ 25, 26, 12, 13\n|  save_ 27, 28, 14, 15\n|.endmacro\n|.macro restoreregs\n|  ldp x20, x19, [sp, # SAVE_GPR_+(27-19)*8]\n|  rest_ 21, 22, 8, 9\n|  rest_ 23, 24, 10, 11\n|  rest_ 25, 26, 12, 13\n|  rest_ 27, 28, 14, 15\n|  ldp fp, lr, [sp, # SAVE_FP_LR_]\n|  add sp, sp, # CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State,\tGLREG\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; brk; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_FUNC,\t#-16\n|.define FRAME_PC,\t#-8\n|\n|// Endian-specific defines.\n|.if ENDIAN_LE\n|.define LO,\t\t0\n|.define OFS_RD,\t2\n|.define OFS_RB,\t3\n|.define OFS_RA,\t1\n|.define OFS_OP,\t0\n|.else\n|.define LO,\t\t4\n|.define OFS_RD,\t0\n|.define OFS_RB,\t0\n|.define OFS_RA,\t2\n|.define OFS_OP,\t3\n|.endif\n|\n|.macro decode_RA, dst, ins; ubfx dst, ins, #8, #8; .endmacro\n|.macro decode_RB, dst, ins; ubfx dst, ins, #24, #8; .endmacro\n|.macro decode_RC, dst, ins; ubfx dst, ins, #16, #8; .endmacro\n|.macro decode_RD, dst, ins; ubfx dst, ins, #16, #16; .endmacro\n|.macro decode_RC8RD, dst, src; ubfiz dst, src, #3, #8; .endmacro\n|\n|// Instruction decode+dispatch.\n|.macro ins_NEXT\n|  ldr INSw, [PC], #4\n|  add TMP1, GL, INS, uxtb #3\n|   decode_RA RA, INS\n|  ldr TMP0, [TMP1, #GG_G2DISP]\n|   decode_RD RC, INS\n|  br TMP0\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  ldr PC, LFUNC:CARG3->pc\n|  ldr INSw, [PC], #4\n|  add TMP1, GL, INS, uxtb #3\n|   decode_RA RA, INS\n|  ldr TMP0, [TMP1, #GG_G2DISP]\n|   add RA, BASE, RA, lsl #3\n|  br TMP0\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  str PC, [BASE, FRAME_PC]\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to check the TValue type and extract the GCobj. Branch on failure.\n|.macro checktp, reg, tp, target\n|  asr ITYPE, reg, #47\n|  cmn ITYPE, #-tp\n|   and reg, reg, #LJ_GCVMASK\n|  bne target\n|.endmacro\n|.macro checktp, dst, reg, tp, target\n|  asr ITYPE, reg, #47\n|  cmn ITYPE, #-tp\n|   and dst, reg, #LJ_GCVMASK\n|  bne target\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC, target; .endmacro\n|.macro checkint, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  bne target\n|.endmacro\n|.macro checknum, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  bls target\n|.endmacro\n|.macro checknumber, reg, target\n|  cmp TISNUMhi, reg, lsr #32\n|  blo target\n|.endmacro\n|\n|.macro mov_false, reg; movn reg, #0x8000, lsl #32; .endmacro\n|.macro mov_true, reg; movn reg, #0x0001, lsl #48; .endmacro\n|\n#define GL_J(field)\t(GG_G2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta\n|  lsr CARG1, PC, #1\n|  and CARG1, CARG1, #126\n|  add CARG1, CARG1, #GG_G2DISP+GG_DISP2HOT\n|  ldrh CARG2w, [GL, CARG1]\n|  subs CARG2, CARG2, #delta\n|  strh CARG2w, [GL, CARG1]\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP\n|  blo ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL\n|  blo ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro mv_vmstate, reg, st; movn reg, #LJ_VMST_..st; .endmacro\n|.macro st_vmstate, reg; str reg, GL->vmstate; .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  ldr tmp, GL->gc.grayagain\n|   and mark, mark, #~LJ_GC_BLACK\t// black2gray(tab)\n|  str tab, GL->gc.grayagain\n|   strb mark, tab->marked\n|  str tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n#if !LJ_DUALNUM\n#error \"Only dual-number mode supported for ARM64 target\"\n#endif\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: RB = previous base.\n  |  tbz PC, #2, ->cont_dispatch\t// (PC & FRAME_P) == 0?\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  ldr PC, [RB, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |   mov_true TMP0\n  |  mov BASE, RB\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   str TMP0, [RA, #-8]!\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  adds RC, RC, #8\t\t\t// RC = (nresults+1)*8.\n  |  mov CRET1, #LUA_YIELD\n  |  beq ->vm_unwind_c_eh\n  |  str RCw, SAVE_MULTRES\n  |  ands CARG1, PC, #FRAME_TYPE\n  |  beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return\n  |  // CARG1 = PC & FRAME_TYPE\n  |  and RB, PC, #~FRAME_TYPEP\n  |   cmp CARG1, #FRAME_C\n  |  sub RB, BASE, RB\t\t\t// RB = previous base.\n  |   bne ->vm_returnp\n  |\n  |  str RB, L->base\n  |   ldrsw CARG2, SAVE_NRES\t\t// CARG2 = nresults+1.\n  |    mv_vmstate TMP0w, C\n  |   sub BASE, BASE, #16\n  |  subs TMP2, RC, #8\n  |    st_vmstate TMP0w\n  |  beq >2\n  |1:\n  |  subs TMP2, TMP2, #8\n  |   ldr TMP0, [RA], #8\n  |   str TMP0, [BASE], #8\n  |  bne <1\n  |2:\n  |  cmp RC, CARG2, lsl #3\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  str BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  ldr RC, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   mov CRET1, #0\t\t\t// Ok return status for vm_pcall.\n  |  str RC, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  bgt >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  ldr CARG3, L->maxstack\n  |  cmp BASE, CARG3\n  |  bhs >8\n  |   str TISNIL, [BASE], #8\n  |  add RC, RC, #8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  cbz CARG2, <3\t\t\t// LUA_MULTRET+1 case?\n  |  sub CARG1, RC, CARG2, lsl #3\n  |  sub BASE, BASE, CARG1\t\t// Shrink top.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  str BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |  mov CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  ldrsw CARG2, SAVE_NRES\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov sp, CARG1\n  |  mov CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |   mv_vmstate TMP0w, C\n  |  ldr GL, L->glref\n  |   st_vmstate TMP0w\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  and sp, CARG1, #CFRAME_RAWMASK\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  ldr L, SAVE_L\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |    movn TISNIL, #0\n  |    mov RC, #16\t\t\t// 2 results: false + error message.\n  |  ldr BASE, L->base\n  |   ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |    mov_false TMP0\n  |  sub RA, BASE, #8\t\t\t// Results start at BASE-8.\n  |  ldr PC, [BASE, FRAME_PC]\t\t// Fetch PC of previous frame.\n  |    str TMP0, [BASE, #-8]\t\t// Prepend false to error message.\n  |   st_vmstate ST_INTERP\n  |  b ->vm_returnc\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  // CARG1 = L\n  |  mov CARG2, #LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |    mov CARG1, L\n  |  stp BASE, RC, L->base\n  |   add PC, PC, #4\t\t\t// Must point after first instruction.\n  |   lsr CARG2, RA, #3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  str PC, SAVE_PC\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldp BASE, RC, L->base\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, RC, BASE\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L, CARG1\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |  mov BASE, CARG2\n  |   str L, SAVE_L\n  |  mov PC, #FRAME_CP\n  |   str wzr, SAVE_NRES\n  |    add TMP0, sp, #CFRAME_RESUME\n  |  ldrb TMP1w, L->status\n  |   str wzr, SAVE_ERRF\n  |   str L, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   str xzr, SAVE_CFRAME\n  |    str TMP0, L->cframe\n  |  cbz TMP1w, >3\n  |\n  |  // Resume after yield (like a return).\n  |  str L, GL->cur_L\n  |  mov RA, BASE\n  |   ldp BASE, CARG1, L->base\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |  ldr PC, [BASE, FRAME_PC]\n  |     strb wzr, L->status\n  |    movn TISNIL, #0\n  |   sub RC, CARG1, BASE\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   add RC, RC, #8\n  |     st_vmstate ST_INTERP\n  |   str RCw, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, #FRAME_CP\n  |  str CARG4w, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, #FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  ldr RC, L:CARG1->cframe\n  |   str CARG3w, SAVE_NRES\n  |    mov L, CARG1\n  |   str CARG1, SAVE_L\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |     mov BASE, CARG2\n  |   str CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  add TMP0, sp, #0\n  |   str RC, SAVE_CFRAME\n  |  str TMP0, L->cframe\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  str L, GL->cur_L\n  |  ldp RB, CARG1, L->base\t\t// RB = old base (for vmeta_call).\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |  add PC, PC, BASE\n  |    movn TISNIL, #0\n  |  sub PC, PC, RB\t\t\t// PC = frame delta + frame type\n  |   sub NARGS8:RC, CARG1, BASE\n  |    st_vmstate ST_INTERP\n  |\n  |->vm_call_dispatch:\n  |  // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  ldr CARG3, [BASE, FRAME_FUNC]\n  |  checkfunc CARG3, ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L, CARG1\n  |   ldr RA, L:CARG1->stack\n  |  str CARG1, SAVE_L\n  |    ldr GL, L->glref\t\t\t// Setup pointer to global state.\n  |   ldr RB, L->top\n  |  str CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  ldr RC, L->cframe\n  |   sub RA, RA, RB\t\t\t// Compute -savestack(L, L->top).\n  |   str RAw, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  str wzr, SAVE_ERRF\t\t\t// No error function.\n  |  add TMP0, sp, #0\n  |   str RC, SAVE_CFRAME\n  |  str TMP0, L->cframe\t\t// Add our C frame to cframe chain.\n  |    str L, GL->cur_L\n  |  blr CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  mov BASE, CRET1\n  |   mov PC, #FRAME_CP\n  |  cbnz BASE, <3\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RC = (nresults+1)*8\n  |  ldr LFUNC:CARG3, [RB, FRAME_FUNC]\n  |    ldr CARG1, [BASE, #-32]\t\t// Get continuation.\n  |   mov CARG4, BASE\n  |   mov BASE, RB\t\t\t// Restore caller BASE.\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |.if FFI\n  |    cmp CARG1, #1\n  |.endif\n  |   ldr PC, [CARG4, #-24]\t\t// Restore PC from [cont|PC].\n  |    add TMP0, RA, RC\n  |    str TISNIL, [TMP0, #-8]\t\t// Ensure one valid arg.\n  |.if FFI\n  |    bls >1\n  |.endif\n  |  ldr CARG3, LFUNC:CARG3->pc\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  // BASE = base, RA = resultptr, CARG4 = meta base\n  |    br CARG1\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |   sub CARG4, CARG4, #32\n  |   sub RC, CARG4, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, CARG4 = meta base\n  |  ldr INSw, [PC, #-4]\n  |   sub CARG2, CARG4, #32\n  |   ldr TMP0, [RA]\n  |     str BASE, L->base\n  |  decode_RB RB, INS\n  |   decode_RA RA, INS\n  |  add TMP1, BASE, RB, lsl #3\n  |  subs TMP1, CARG2, TMP1\n  |  beq >1\n  |   str TMP0, [CARG2]\n  |  lsr CARG3, TMP1, #3\n  |  b ->BC_CAT_Z\n  |\n  |1:\n  |   str TMP0, [BASE, RA, lsl #3]\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  movn CARG4, #~LJ_TSTR\n  |   add CARG2, BASE, RB, lsl #3\n  |  add CARG4, STR:RC, CARG4, lsl #47\n  |  b >2\n  |\n  |->vmeta_tgets:\n  |  movk CARG2, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  str CARG2, GL->tmptv\n  |  add CARG2, GL, #offsetof(global_State, tmptv)\n  |2:\n  |   add CARG3, sp, TMPDofs\n  |  str CARG4, TMPD\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// RB = table, RC = index\n  |  add RC, RC, TISNUM\n  |   add CARG2, BASE, RB, lsl #3\n  |   add CARG3, sp, TMPDofs\n  |  str RC, TMPD\n  |  b >1\n  |\n  |->vmeta_tgetv:\t\t\t// RB = table, RC = key\n  |  add CARG2, BASE, RB, lsl #3\n  |   add CARG3, BASE, RC, lsl #3\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cbz CRET1, >3\n  |  ldr TMP0, [CRET1]\n  |  str TMP0, [BASE, RA, lsl #3]\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |   sub TMP1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #16\t\t// 2 args for func(t, k).\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |    str PC, [BASE, #-24]\t\t// [cont|PC]\n  |   sub PC, BASE, TMP1\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  sxtw CARG2, TMP1w\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  mov TMP0, TISNIL\n  |  cbz CRET1, ->BC_TGETR_Z\n  |  ldr TMP0, [CRET1]\n  |  b ->BC_TGETR_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  movn CARG4, #~LJ_TSTR\n  |   add CARG2, BASE, RB, lsl #3\n  |  add CARG4, STR:RC, CARG4, lsl #47\n  |  b >2\n  |\n  |->vmeta_tsets:\n  |  movk CARG2, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  str CARG2, GL->tmptv\n  |  add CARG2, GL, #offsetof(global_State, tmptv)\n  |2:\n  |   add CARG3, sp, TMPDofs\n  |  str CARG4, TMPD\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// RB = table, RC = index\n  |  add RC, RC, TISNUM\n  |   add CARG2, BASE, RB, lsl #3\n  |   add CARG3, sp, TMPDofs\n  |  str RC, TMPD\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  add CARG2, BASE, RB, lsl #3\n  |   add CARG3, BASE, RC, lsl #3\n  |1:\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |   ldr TMP0, [BASE, RA, lsl #3]\n  |  cbz CRET1, >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |   str TMP0, [CRET1]\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |   sub TMP1, BASE, #FRAME_CONT\n  |  ldr BASE, L->top\n  |    mov NARGS8:RC, #24\t\t// 3 args for func(t, k, v).\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   str TMP0, [BASE, #16]\t\t// Copy value to third argument.\n  |    str PC, [BASE, #-24]\t\t// [cont|PC]\n  |   sub PC, BASE, TMP1\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  sxtw CARG3, TMP1w\n  |  str BASE, L->base\n  |  mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |  b ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  add CARG2, BASE, RA, lsl #3\n  |   sub PC, PC, #4\n  |  add CARG3, BASE, RC, lsl #3\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  uxtb CARG4w, INSw\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  cmp CRET1, #1\n  |  bhi ->vmeta_binop\n  |4:\n  |   ldrh RBw, [PC, # OFS_RD]\n  |    add PC, PC, #4\n  |   add RB, PC, RB, lsl #2\n  |   sub RB, RB, #0x20000\n  |  csel PC, PC, RB, lo\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  ldr INSw, [PC, #-4]\n  |   ldr TMP0, [RA]\n  |  decode_RA TMP1, INS\n  |   str TMP0, [BASE, TMP1, lsl #3]\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  ldr TMP0, [RA]\n  |   mov_true TMP1\n  |  cmp TMP1, TMP0\t\t\t// Branch if result is true.\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  ldr TMP0, [RA]\n  |   mov_false TMP1\n  |  cmp TMP0, TMP1\t\t\t// Branch if result is false.\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  and TAB:CARG3, CARG3, #LJ_GCVMASK\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, INS\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  sub PC, PC, #4\n  |   str BASE, L->base\n  |   mov CARG1, L\n  |   mov CARG2, RA\n  |   mov CARG3, RC\n  |  str PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vn:\n  |  add CARG3, BASE, RB, lsl #3\n  |   add CARG4, KBASE, RC, lsl #3\n  |  b >1\n  |\n  |->vmeta_arith_nv:\n  |  add CARG4, BASE, RB, lsl #3\n  |   add CARG3, KBASE, RC, lsl #3\n  |  b >1\n  |\n  |->vmeta_unm:\n  |  add CARG3, BASE, RC, lsl #3\n  |  mov CARG4, CARG3\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  add CARG3, BASE, RB, lsl #3\n  |   add CARG4, BASE, RC, lsl #3\n  |1:\n  |  uxtb CARG5w, INSw\n  |   add CARG2, BASE, RA, lsl #3\n  |    str BASE, L->base\n  |   mov CARG1, L\n  |    str PC, SAVE_PC\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  cbz CRET1, ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub TMP1, CRET1, BASE\n  |   str PC, [CRET1, #-24]\t\t// [cont|PC]\n  |  add PC, TMP1, #FRAME_CONT\n  |  mov BASE, CRET1\n  |   mov NARGS8:RC, #16\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  add CARG2, BASE, RC, lsl #3\n#if LJ_52\n  |  mov TAB:RC, TAB:CARG1\t\t// Save table (ignored for other types).\n#endif\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  cbnz CRET1, ->vmeta_binop\t\t// Binop call for compatibility.\n  |  mov TAB:CARG1, TAB:RC\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // RB = old base, BASE = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str RB, L->base\t\t\t// This is the callers base!\n  |  sub CARG2, BASE, #16\n  |   str PC, SAVE_PC\n  |  add CARG3, BASE, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Guaranteed to be a function here.\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  sub CARG2, RA, #16\n  |   str PC, SAVE_PC\n  |  add CARG3, RA, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  ldr TMP1, [RA, FRAME_FUNC]\t\t// Guaranteed to be a function here.\n  |   ldr PC, [BASE, FRAME_PC]\n  |   add NARGS8:RC, NARGS8:RC, #8\t// Got one more argument now.\n  |  and LFUNC:CARG3, TMP1, #LJ_GCVMASK\n  |  b ->BC_CALLT2_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, RA\n  |   str PC, SAVE_PC\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  ldr INSw, [PC, #-4]\n  |.if JIT\n  |   uxtb TMP0w, INSw\n  |.endif\n  |  decode_RA RA, INS\n  |  decode_RD RC, INS\n  |.if JIT\n  |   cmp TMP0, #BC_JFORI\n  |   beq =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  ldp CARG1, CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc name\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr FARG1, [BASE]\n  |   blo ->fff_fallback\n  |  checknum CARG1, ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc name\n  |  ldp CARG1, CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |  ldp FARG1, FARG2, [BASE]\n  |   blo ->fff_fallback\n  |  checknum CARG1, ->fff_fallback\n  |  checknum CARG2, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.\n  |.macro ffgccheck\n  |  ldp CARG1, CARG2, GL->gc.total\t// Assumes threshold follows total.\n  |  cmp CARG1, CARG2\n  |  blt >1\n  |  bl ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |   ldr PC, [BASE, FRAME_PC]\n  |  mov_false TMP1\n  |  cmp CARG1, TMP1\n  |  bhs ->fff_fallback\n  |  str CARG1, [BASE, #-16]\n  |  sub RB, BASE, #8\n  |  subs RA, NARGS8:RC, #8\n  |   add RC, NARGS8:RC, #8\t\t// Compute (nresults+1)*8.\n  |  cbz RA, ->fff_res\t\t\t// Done if exactly 1 argument.\n  |1:\n  |   ldr CARG1, [RB, #16]\n  |  sub RA, RA, #8\n  |   str CARG1, [RB], #8\n  |  cbnz RA, <1\n  |  b ->fff_res\n  |\n  |.ffunc_1 type\n  |  mov TMP0, #~LJ_TISNUM\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #~LJ_TISNUM\n  |  csinv TMP1, TMP0, ITYPE, lo\n  |  add TMP1, TMP1, #offsetof(GCfuncC, upvalue)/8\n  |  ldr CARG1, [CFUNC:CARG3, TMP1, lsl #3]\n  |  b ->fff_restv\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #-LJ_TTAB\n  |  ccmn ITYPE, #-LJ_TUDATA, #4, ne\n  |   and TAB:CARG1, CARG1, #LJ_GCVMASK\n  |  bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  ldr TAB:RB, TAB:CARG1->metatable\n  |2:\n  |   mov CARG1, TISNIL\n  |   ldr STR:RC, GL->gcroot[GCROOT_MMNAME+MM_metatable]\n  |  cbz TAB:RB, ->fff_restv\n  |  ldr TMP1w, TAB:RB->hmask\n  |   ldr TMP2w, STR:RC->sid\n  |    ldr NODE:CARG3, TAB:RB->node\n  |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->sid & tab->hmask\n  |  add TMP1, TMP1, TMP1, lsl #1\n  |  movn CARG4, #~LJ_TSTR\n  |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n  |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  ldp CARG1, TMP0, NODE:CARG3->val\n  |   ldr NODE:CARG3, NODE:CARG3->next\n  |  cmp TMP0, CARG4\n  |  beq >5\n  |  cbnz NODE:CARG3, <3\n  |4:\n  |  mov CARG1, RB\t\t\t// Use metatable as default result.\n  |  movk CARG1, #(LJ_TTAB>>1)&0xffff, lsl #48\n  |  b ->fff_restv\n  |5:\n  |  cmp TMP0, TISNIL\n  |  bne ->fff_restv\n  |  b <4\n  |\n  |6:\n  |  movn TMP0, #~LJ_TISNUM\n  |  cmp ITYPE, TMP0\n  |  csel ITYPE, ITYPE, TMP0, hs\n  |  sub TMP1, GL, ITYPE, lsl #3\n  |  ldr TAB:RB, [TMP1, #offsetof(global_State, gcroot[GCROOT_BASEMT])-8]\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n  |   ldr TAB:TMP0, TAB:TMP1->metatable\n  |  asr ITYPE, CARG2, #47\n  |   ldrb TMP2w, TAB:TMP1->marked\n  |  cmn ITYPE, #-LJ_TTAB\n  |    and TAB:CARG2, CARG2, #LJ_GCVMASK\n  |  ccmp TAB:TMP0, #0, #0, eq\n  |  bne ->fff_fallback\n  |    str TAB:CARG2, TAB:TMP1->metatable\n  |   tbz TMP2w, #2, ->fff_restv\t// isblack(table)\n  |  barrierback TAB:TMP1, TMP2w, TMP0\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  ldr CARG2, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  checktab CARG2, ->fff_fallback\n  |   mov CARG1, L\n  |   add CARG3, BASE, #8\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |  ldr CARG1, [CRET1]\n  |  b ->fff_restv\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |   bne ->fff_fallback\n  |  checknumber CARG1, ->fff_fallback\n  |  b ->fff_restv\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  asr ITYPE, CARG1, #47\n  |  cmn ITYPE, #-LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  ldr TMP1, GL->gcroot[GCROOT_BASEMT_NUM]\n  |   str BASE, L->base\n  |  cmn ITYPE, #-LJ_TISNUM\n  |  ccmp TMP1, #0, #0, ls\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  bne ->fff_fallback\n  |  ffgccheck\n  |  mov CARG1, L\n  |  mov CARG2, BASE\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |  // Returns GCstr *.\n  |   movn TMP1, #~LJ_TSTR\n  |  ldr BASE, L->base\n  |   add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  checktp CARG1, LJ_TTAB, ->fff_fallback\n  |  str TISNIL, [BASE, NARGS8:RC]\t// Set missing 2nd arg to nil.\n  |  ldr PC, [BASE, FRAME_PC]\n  |  add CARG2, BASE, #8\n  |  sub CARG3, BASE, #16\n  |  bl extern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |  // Returns 1=found, 0=end, -1=error.\n  |   mov RC, #(2+1)*8\n  |  tbnz CRET1w, #31, ->fff_fallback\t// Invalid key.\n  |  cbnz CRET1, ->fff_res\t\t// Found key/value.\n  |  // End of traversal: return nil.\n  |  str TISNIL, [BASE, #-16]\n  |  b ->fff_res1\n  |\n  |.ffunc_1 pairs\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:CARG2, TAB:TMP1->metatable\n#endif\n  |   ldr CFUNC:CARG4, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cbnz TAB:CARG2, ->fff_fallback\n#endif\n  |  mov RC, #(3+1)*8\n  |  stp CARG1, TISNIL, [BASE, #-8]\n  |   str CFUNC:CARG4, [BASE, #-16]\n  |  b ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  checktab CARG1, ->fff_fallback\n  |   checkint CARG2, ->fff_fallback\n  |  ldr TMP1w, TAB:CARG1->asize\n  |   ldr CARG3, TAB:CARG1->array\n  |    ldr TMP0w, TAB:CARG1->hmask\n  |  add CARG2w, CARG2w, #1\n  |  cmp CARG2w, TMP1w\n  |    ldr PC, [BASE, FRAME_PC]\n  |     add TMP2, CARG2, TISNUM\n  |   mov RC, #(0+1)*8\n  |     str TMP2, [BASE, #-16]\n  |  bhs >2\t\t\t\t// Not in array part?\n  |  ldr TMP0, [CARG3, CARG2, lsl #3]\n  |1:\n  |   mov TMP1, #(2+1)*8\n  |   cmp TMP0, TISNIL\n  |  str TMP0, [BASE, #-8]\n  |   csel RC, RC, TMP1, eq\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cbz TMP0w, ->fff_res\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cbz CRET1, ->fff_res\n  |  ldr TMP0, [CRET1]\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktp TMP1, CARG1, LJ_TTAB, ->fff_fallback\n#if LJ_52\n  |  ldr TAB:CARG2, TAB:TMP1->metatable\n#endif\n  |   ldr CFUNC:CARG4, CFUNC:CARG3->upvalue[0]\n  |    ldr PC, [BASE, FRAME_PC]\n#if LJ_52\n  |  cbnz TAB:CARG2, ->fff_fallback\n#endif\n  |  mov RC, #(3+1)*8\n  |  stp CARG1, TISNUM, [BASE, #-8]\n  |   str CFUNC:CARG4, [BASE, #-16]\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |   cmp NARGS8:RC, #8\n  |  ldrb TMP0w, GL->hookmask\n  |   blo ->fff_fallback\n  |   sub NARGS8:RC, NARGS8:RC, #8\n  |    mov RB, BASE\n  |    add BASE, BASE, #16\n  |  ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1\n  |  add PC, TMP0, #16+FRAME_PCALL\n  |   beq ->vm_call_dispatch\n  |1:\n  |   add TMP2, BASE, NARGS8:RC\n  |2:\n  |   ldr TMP0, [TMP2, #-16]\n  |   str TMP0, [TMP2, #-8]!\n  |  cmp TMP2, BASE\n  |  bne <2\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc xpcall\n  |     ldp CARG1, CARG2, [BASE]\n  |  ldrb TMP0w, GL->hookmask\n  |   subs NARGS8:TMP1, NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |    mov RB, BASE\n  |     asr ITYPE, CARG2, #47\n  |  ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1\n  |     cmn ITYPE, #-LJ_TFUNC\n  |  add PC, TMP0, #24+FRAME_PCALL\n  |     bne ->fff_fallback\t\t// Traceback must be a function.\n  |   mov NARGS8:RC, NARGS8:TMP1\n  |    add BASE, BASE, #24\n  |     stp CARG2, CARG1, [RB]\t\t// Swap function and traceback.\n  |   cbz NARGS8:RC, ->vm_call_dispatch\n  |  b <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  checktp CARG1, LJ_TTHREAD, ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr\n  |  and L:CARG1, CARG1, #LJ_GCVMASK\n  |.endif\n  |   ldr PC, [BASE, FRAME_PC]\n  |     str BASE, L->base\n  |  ldp RB, CARG2, L:CARG1->base\n  |   ldrb TMP1w, L:CARG1->status\n  |  add TMP0, CARG2, TMP1\n  |   str PC, SAVE_PC\n  |  cmp TMP0, RB\n  |  beq ->fff_fallback\n  |   cmp TMP1, #LUA_YIELD\n  |    add TMP0, CARG2, #8\n  |   csel CARG2, CARG2, TMP0, hs\n  |   ldr CARG4, L:CARG1->maxstack\n  |   add CARG3, CARG2, NARGS8:RC\n  |    ldr RB, L:CARG1->cframe\n  |   ccmp CARG3, CARG4, #2, ls\n  |    ccmp RB, #0, #2, ls\n  |    bhi ->fff_fallback\n  |.if resume\n  |  sub CARG3, CARG3, #8\t\t// Keep resumed thread in stack for GC.\n  |  add BASE, BASE, #8\n  |  sub NARGS8:RC, NARGS8:RC, #8\n  |.endif\n  |  str CARG3, L:CARG1->top\n  |  str BASE, L->top\n  |  cbz NARGS8:RC, >3\n  |2:  // Move args to coroutine.\n  |   ldr TMP0, [BASE, RB]\n  |  cmp RB, NARGS8:RC\n  |   str TMP0, [CARG2, RB]\n  |   add RB, RB, #8\n  |  bne <2\n  |3:\n  |  mov CARG3, #0\n  |   mov L:RA, L:CARG1\n  |  mov CARG4, #0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  ldp CARG3, CARG4, L:RA->base\n  |   cmp CRET1, #LUA_YIELD\n  |  ldr BASE, L->base\n  |    str L, GL->cur_L\n  |    st_vmstate ST_INTERP\n  |   bhi >8\n  |  sub RC, CARG4, CARG3\n  |   ldr CARG1, L->maxstack\n  |   add CARG2, BASE, RC\n  |  cbz RC, >6\t\t\t\t// No results?\n  |  cmp CARG2, CARG1\n  |   mov RB, #0\n  |  bhi >9\t\t\t\t// Need to grow stack?\n  |\n  |  sub CARG4, RC, #8\n  |   str CARG3, L:RA->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |   ldr TMP0, [CARG3, RB]\n  |  cmp RB, CARG4\n  |   str TMP0, [BASE, RB]\n  |   add RB, RB, #8\n  |  bne <5\n  |6:\n  |.if resume\n  |  mov_true TMP1\n  |   add RC, RC, #16\n  |7:\n  |  str TMP1, [BASE, #-8]\t\t// Prepend true/false to results.\n  |   sub RA, BASE, #8\n  |.else\n  |   mov RA, BASE\n  |   add RC, RC, #8\n  |.endif\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str PC, SAVE_PC\n  |   str RCw, SAVE_MULTRES\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  ldr TMP0, [CARG4, #-8]!\n  |   mov_false TMP1\n  |    mov RC, #(2+1)*8\n  |  str CARG4, L:RA->top\t\t// Remove error from coroutine stack.\n  |  str TMP0, [BASE]\t\t\t// Copy error message.\n  |  b <7\n  |.else\n  |  mov CARG1, L\n  |  mov CARG2, L:RA\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Never returns.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov CARG1, L\n  |  lsr CARG2, RC, #3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov CRET1, #0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  ldr TMP0, L->cframe\n  |   add TMP1, BASE, NARGS8:RC\n  |    mov CRET1, #LUA_YIELD\n  |   stp BASE, TMP1, L->base\n  |  tbz TMP0, #0, ->fff_fallback\n  |   str xzr, L->cframe\n  |    strb CRET1w, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.macro math_round, func, round\n  |  .ffunc math_ .. func\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr d0, [BASE]\n  |   blo ->fff_fallback\n  |  cmp TISNUMhi, CARG1, lsr #32\n  |  beq ->fff_restv\n  |  blo ->fff_fallback\n  |  round d0, d0\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |  math_round floor, frintm\n  |  math_round ceil, frintp\n  |\n  |.ffunc_1 math_abs\n  |  checknumber CARG1, ->fff_fallback\n  |  and CARG1, CARG1, #U64x(7fffffff,ffffffff)\n  |  bne ->fff_restv\n  |  eor CARG2w, CARG1w, CARG1w, asr #31\n  |   movz CARG3, #0x41e0, lsl #48\t// 2^31.\n  |  subs CARG1w, CARG2w, CARG1w, asr #31\n  |   add CARG1, CARG1, TISNUM\n  |  csel CARG1, CARG1, CARG3, pl\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG1 = TValue result.\n  |  ldr PC, [BASE, FRAME_PC]\n  |  str CARG1, [BASE, #-16]\n  |->fff_res1:\n  |  // PC = return.\n  |  mov RC, #(1+1)*8\n  |->fff_res:\n  |  // RC = (nresults+1)*8, PC = return.\n  |  ands CARG1, PC, #FRAME_TYPE\n  |   str RCw, SAVE_MULTRES\n  |   sub RA, BASE, #16\n  |  bne ->vm_return\n  |  ldr INSw, [PC, #-4]\n  |  decode_RB RB, INS\n  |5:\n  |  cmp RC, RB, lsl #3\t\t\t// More results expected?\n  |  blo >6\n  |  decode_RA TMP1, INS\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  sub BASE, RA, TMP1, lsl #3\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  add TMP1, RA, RC\n  |   add RC, RC, #8\n  |  str TISNIL, [TMP1, #-8]\n  |  b <5\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  bl extern func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  bl extern func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.ffunc_n math_sqrt\n  |  fsqrt d0, d0\n  |->fff_resn:\n  |  ldr PC, [BASE, FRAME_PC]\n  |  str d0, [BASE, #-16]\n  |  b ->fff_res1\n  |\n  |.ffunc math_log\n  |  ldr CARG1, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  ldr FARG1, [BASE]\n  |   bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |  checknum CARG1, ->fff_fallback\n  |  bl extern log\n  |  b ->fff_resn\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_2 math_ldexp\n  |  ldr FARG1, [BASE]\n  |  checknum CARG1, ->fff_fallback\n  |  checkint CARG2, ->fff_fallback\n  |  sxtw CARG1, CARG2w\n  |  bl extern ldexp\t\t\t// (double x, int exp)\n  |  b ->fff_resn\n  |\n  |.ffunc_n math_frexp\n  |  add CARG1, sp, TMPDofs\n  |  bl extern frexp\n  |   ldr CARG2w, TMPD\n  |    ldr PC, [BASE, FRAME_PC]\n  |  str d0, [BASE, #-16]\n  |    mov RC, #(2+1)*8\n  |   add CARG2, CARG2, TISNUM\n  |   str CARG2, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.ffunc_n math_modf\n  |  sub CARG1, BASE, #16\n  |   ldr PC, [BASE, FRAME_PC]\n  |  bl extern modf\n  |   mov RC, #(2+1)*8\n  |  str d0, [BASE, #-8]\n  |  b ->fff_res\n  |\n  |.macro math_minmax, name, cond, fcond\n  |  .ffunc_1 name\n  |   add RB, BASE, RC\n  |   add RA, BASE, #8\n  |  checkint CARG1, >4\n  |1:  // Handle integers.\n  |  ldr CARG2, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_restv\n  |  checkint CARG2, >3\n  |  cmp CARG1w, CARG2w\n  |   add RA, RA, #8\n  |  csel CARG1, CARG2, CARG1, cond\n  |  b <1\n  |3:  // Convert intermediate result to number and continue below.\n  |  scvtf d0, CARG1w\n  |  blo ->fff_fallback\n  |  ldr d1, [RA]\n  |  b >6\n  |\n  |4:\n  |  ldr d0, [BASE]\n  |  blo ->fff_fallback\n  |5:  // Handle numbers.\n  |  ldr CARG2, [RA]\n  |  ldr d1, [RA]\n  |   cmp RA, RB\n  |   bhs ->fff_resn\n  |  checknum CARG2, >7\n  |6:\n  |  fcmp d0, d1\n  |   add RA, RA, #8\n  |  fcsel d0, d1, d0, fcond\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |  scvtf d1, CARG2w\n  |  blo ->fff_fallback\n  |  b <6\n  |.endmacro\n  |\n  |  math_minmax math_min, gt, pl\n  |  math_minmax math_max, lt, le\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  ldp PC, CARG1, [BASE, FRAME_PC]\n  |   cmp NARGS8:RC, #8\n  |  asr ITYPE, CARG1, #47\n  |  ccmn ITYPE, #-LJ_TSTR, #0, eq\n  |   and STR:CARG1, CARG1, #LJ_GCVMASK\n  |  bne ->fff_fallback\n  |  ldrb TMP0w, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   ldr CARG3w, STR:CARG1->len\n  |  add TMP0, TMP0, TISNUM\n  |  str TMP0, [BASE, #-16]\n  |  mov RC, #(0+1)*8\n  |   cbz CARG3, ->fff_res\n  |  b ->fff_res1\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  ldp PC, CARG1, [BASE, FRAME_PC]\n  |  cmp CARG1w, #255\n  |   ccmp NARGS8:RC, #8, #0, ls\t\t// Need exactly 1 argument.\n  |  bne ->fff_fallback\n  |  checkint CARG1, ->fff_fallback\n  |  mov CARG3, #1\n  |  // Point to the char inside the integer in the stack slot.\n  |.if ENDIAN_LE\n  |  mov CARG2, BASE\n  |.else\n  |  add CARG2, BASE, #7\n  |.endif\n  |->fff_newstr:\n  |  // CARG2 = str, CARG3 = len.\n  |   str BASE, L->base\n  |  mov CARG1, L\n  |   str PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  ldr BASE, L->base\n  |   movn TMP1, #~LJ_TSTR\n  |  add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  ldr CARG1, [BASE]\n  |    ldr CARG3, [BASE, #16]\n  |   cmp NARGS8:RC, #16\n  |    movn RB, #0\n  |   beq >1\n  |   blo ->fff_fallback\n  |    checkint CARG3, ->fff_fallback\n  |    sxtw RB, CARG3w\n  |1:\n  |  ldr CARG2, [BASE, #8]\n  |  checkstr CARG1, ->fff_fallback\n  |   ldr TMP1w, STR:CARG1->len\n  |  checkint CARG2, ->fff_fallback\n  |  sxtw CARG2, CARG2w\n  |  // CARG1 = str, TMP1 = str->len, CARG2 = start, RB = end\n  |   add TMP2, RB, TMP1\n  |   cmp RB, #0\n  |  add TMP0, CARG2, TMP1\n  |   csinc RB, RB, TMP2, ge\t\t// if (end < 0) end += len+1\n  |  cmp CARG2, #0\n  |  csinc CARG2, CARG2, TMP0, ge\t// if (start < 0) start += len+1\n  |   cmp RB, #0\n  |   csel RB, RB, xzr, ge\t\t// if (end < 0) end = 0\n  |  cmp CARG2, #1\n  |  csinc CARG2, CARG2, xzr, ge\t// if (start < 1) start = 1\n  |   cmp RB, TMP1\n  |   csel RB, RB, TMP1, le\t\t// if (end > len) end = len\n  |  add CARG1, STR:CARG1, #sizeof(GCstr)-1\n  |   subs CARG3, RB, CARG2\t\t// len = end - start\n  |  add CARG2, CARG1, CARG2\n  |   add CARG3, CARG3, #1\t\t// len += 1\n  |   bge ->fff_newstr\n  |  add STR:CARG1, GL, #offsetof(global_State, strempty)\n  |   movn TMP1, #~LJ_TSTR\n  |  add CARG1, CARG1, TMP1, lsl #47\n  |  b ->fff_restv\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  ldr CARG2, [BASE]\n  |   cmp NARGS8:RC, #8\n  |  asr ITYPE, CARG2, #47\n  |  ccmn ITYPE, #-LJ_TSTR, #0, hs\n  |   and STR:CARG2, CARG2, #LJ_GCVMASK\n  |  bne ->fff_fallback\n  |  ldr TMP0, GL->tmpbuf.b\n  |   add SBUF:CARG1, GL, #offsetof(global_State, tmpbuf)\n  |   str BASE, L->base\n  |   str PC, SAVE_PC\n  |   str L, GL->tmpbuf.L\n  |  str TMP0, GL->tmpbuf.w\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |// FP number to bit conversion for soft-float. Clobbers CARG1-CARG3\n  |->vm_tobit_fb:\n  |  bls ->fff_fallback\n  |  add CARG2, CARG1, CARG1\n  |  mov CARG3, #1076\n  |  sub CARG3, CARG3, CARG2, lsr #53\n  |  cmp CARG3, #53\n  |  bhi >1\n  |  and CARG2, CARG2, #U64x(001fffff,ffffffff)\n  |  orr CARG2, CARG2, #U64x(00200000,00000000)\n  |   cmp CARG1, #0\n  |  lsr CARG2, CARG2, CARG3\n  |   cneg CARG1w, CARG2w, mi\n  |  br lr\n  |1:\n  |  mov CARG1w, #0\n  |  br lr\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  adr lr, >1\n  |  checkint CARG1, ->vm_tobit_fb\n  |1:\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  mov RA, #8\n  |  mov TMP0w, CARG1w\n  |  adr lr, >2\n  |1:\n  |  ldr CARG1, [BASE, RA]\n  |   cmp RA, NARGS8:RC\n  |    add RA, RA, #8\n  |   bge >9\n  |  checkint CARG1, ->vm_tobit_fb\n  |2:\n  |  ins TMP0w, TMP0w, CARG1w\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, orr\n  |.ffunc_bit_op bxor, eor\n  |\n  |.ffunc_bit tobit\n  |  mov TMP0w, CARG1w\n  |9:  // Label reused by .ffunc_bit_op users.\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bswap\n  |  rev TMP0w, CARG1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.ffunc_bit bnot\n  |  mvn TMP0w, CARG1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc bit_..name\n  |  ldp TMP0, CARG1, [BASE]\n  |   cmp NARGS8:RC, #16\n  |   blo ->fff_fallback\n  |  adr lr, >1\n  |  checkint CARG1, ->vm_tobit_fb\n  |1:\n  |.if shmod == 0\n  |  mov TMP1, CARG1\n  |.else\n  |  neg TMP1, CARG1\n  |.endif\n  |  mov CARG1, TMP0\n  |  adr lr, >2\n  |  checkint CARG1, ->vm_tobit_fb\n  |2:\n  |  ins TMP0w, CARG1w, TMP1w\n  |  add CARG1, TMP0, TISNUM\n  |  b ->fff_restv\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, lsl, 0\n  |.ffunc_bit_sh rshift, lsr, 0\n  |.ffunc_bit_sh arshift, asr, 0\n  |.ffunc_bit_sh rol, ror, 1\n  |.ffunc_bit_sh ror, ror, 0\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RC = nargs*8\n  |   ldp CFUNC:CARG3, PC, [BASE, FRAME_FUNC]\t// Fallback may overwrite PC.\n  |  ldr TMP2, L->maxstack\n  |  add TMP1, BASE, NARGS8:RC\n  |  stp BASE, TMP1, L->base\n  |   and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  add TMP1, TMP1, #8*LUA_MINSTACK\n  |   ldr CARG3, CFUNC:CARG3->f\n  |    str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  cmp TMP1, TMP2\n  |   mov CARG1, L\n  |  bhi >5\t\t\t\t// Need to grow stack.\n  |   blr CARG3\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |   ldr BASE, L->base\n  |  cmp CRET1w, #0\n  |   lsl RC, CRET1, #3\n  |   sub RA, BASE, #16\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |   ldr CARG1, L->top\n  |    ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |   sub NARGS8:RC, CARG1, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |    and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  ands TMP0, PC, #FRAME_TYPE\n  |   and TMP1, PC, #~FRAME_TYPEP\n  |  bne >3\n  |  ldrb RAw, [PC, #-4+OFS_RA]\n  |  lsl RA, RA, #3\n  |  add TMP1, RA, #16\n  |3:\n  |  sub RB, BASE, TMP1\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2, #LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  ldr BASE, L->base\n  |  cmp CARG1, CARG1\t\t\t// Set zero-flag to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |   add CARG2, BASE, NARGS8:RC\t// Calculate L->top.\n  |  mov RA, lr\n  |   stp BASE, CARG2, L->base\n  |   str PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  mov CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |  ldp BASE, CARG2, L->base\n  |   ldr CFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  mov lr, RA\t\t\t\t// Help return address predictor.\n  |  sub NARGS8:RC, CARG2, BASE\t\t// Calculate nargs*8.\n  |   and CFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  ldrb CARG1w, GL->hookmask\n  |  tst CARG1, #HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  bne >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |   ldr CARG2w, GL->hookcount\n  |  tst CARG1, #HOOK_ACTIVE\n  |  bne >1\n  |   sub CARG2w, CARG2w, #1\n  |  tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT\n  |  beq >1\n  |   str CARG2w, GL->hookcount\n  |  b >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  ldrb TMP2w, GL->hookmask\n  |  tbz TMP2w, #HOOK_ACTIVE_SHIFT, >1\t// Hook already active?\n  |5:  // Re-dispatch to static ins.\n  |  ldr TMP0, [TMP1, #GG_G2DISP+GG_DISP2STATIC]\n  |  br TMP0\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  ldrb TMP2w, GL->hookmask\n  |   ldr TMP3w, GL->hookcount\n  |  tbnz TMP2w, #HOOK_ACTIVE_SHIFT, <5\t// Hook already active?\n  |  tst TMP2w, #LUA_MASKLINE|LUA_MASKCOUNT\n  |  beq <5\n  |   sub TMP3w, TMP3w, #1\n  |   str TMP3w, GL->hookcount\n  |   cbz TMP3w, >1\n  |  tbz TMP2w, #LUA_HOOKLINE, <5\n  |1:\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  ldr BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  ldr INSw, [PC, #-4]\n  |  add TMP1, GL, INS, uxtb #3\n  |   decode_RA RA, INS\n  |  ldr TMP0, [TMP1, #GG_G2DISP+GG_DISP2STATIC]\n  |   decode_RD RC, INS\n  |  br TMP0\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  ldr CARG1, [CARG4, #-40]\n  |   add PC, PC, #4\n  |  str CARG1w, SAVE_MULTRES\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]  // Same as curr_topL(L).\n  |   add CARG1, GL, #GG_G2DISP+GG_DISP2J\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |   str PC, SAVE_PC\n  |  ldr CARG3, LFUNC:CARG3->pc\n  |   mov CARG2, PC\n  |   str L, [GL, #GL_J(L)]\n  |  ldrb CARG3w, [CARG3, #PC2PROTO(framesize)]\n  |   str BASE, L->base\n  |  add CARG3, BASE, CARG3, lsl #3\n  |  str CARG3, L->top\n  |  bl extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  b <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  orr CARG2, PC, #1\n  |1:\n  |.endif\n  |  add TMP1, BASE, NARGS8:RC\n  |   str PC, SAVE_PC\n  |   mov CARG1, L\n  |   sub RA, RA, BASE\n  |  stp BASE, TMP1, L->base\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  ldp BASE, TMP1, L->base\n  |   str xzr, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  add RA, BASE, RA\n  |  sub NARGS8:RC, TMP1, BASE\n  |   ldr INSw, [PC, #-4]\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  br CRET1\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, CARG4 = meta base\n  |   ldr RBw, SAVE_MULTRES\n  |  ldr INSw, [PC, #-4]\n  |    ldr TRACE:CARG3, [CARG4, #-40]\t// Save previous trace.\n  |   subs RB, RB, #8\n  |  decode_RA RC, INS\t\t\t// Call base.\n  |    and CARG3, CARG3, #LJ_GCVMASK\n  |   beq >2\n  |1:  // Move results down.\n  |  ldr CARG1, [RA]\n  |    add RA, RA, #8\n  |   subs RB, RB, #8\n  |  str CARG1, [BASE, RC, lsl #3]\n  |    add RC, RC, #1\n  |   bne <1\n  |2:\n  |   decode_RA RA, INS\n  |   decode_RB RB, INS\n  |   add RA, RA, RB\n  |3:\n  |   cmp RA, RC\n  |   bhi >9\t\t\t\t// More results wanted?\n  |\n  |  ldrh RAw, TRACE:CARG3->traceno\n  |  ldrh RCw, TRACE:CARG3->link\n  |  cmp RCw, RAw\n  |  beq ->cont_nop\t\t\t// Blacklisted.\n  |  cmp RCw, #0\n  |  bne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  mov CARG1, #GL_J(exitno)\n  |  str RAw, [GL, CARG1]\n  |  mov CARG1, #GL_J(L)\n  |  str L, [GL, CARG1]\n  |  str BASE, L->base\n  |  add CARG1, GL, #GG_G2J\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  ldr BASE, L->base\n  |  b ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  str TISNIL, [BASE, RC, lsl #3]\n  |  add RC, RC, #1\n  |  b <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov CARG1, L\n  |   str BASE, L->base\n  |  mov CARG2, PC\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  ldr BASE, L->base\n  |  sub PC, PC, #4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b\n  |  stp d..a, d..b, [sp, #a*8]\n  |  stp x..a, x..b, [sp, #32*8+a*8]\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |  sub     sp, sp, #(64*8)\n  |  savex_, 0, 1\n  |  savex_, 2, 3\n  |  savex_, 4, 5\n  |  savex_, 6, 7\n  |  savex_, 8, 9\n  |  savex_, 10, 11\n  |  savex_, 12, 13\n  |  savex_, 14, 15\n  |  savex_, 16, 17\n  |  savex_, 18, 19\n  |  savex_, 20, 21\n  |  savex_, 22, 23\n  |  savex_, 24, 25\n  |  savex_, 26, 27\n  |  savex_, 28, 29\n  |  stp d30, d31, [sp, #30*8]\n  |  ldr CARG1, [sp, #64*8]\t// Load original value of lr.\n  |   add CARG3, sp, #64*8\t// Recompute original value of sp.\n  |    mv_vmstate CARG4w, EXIT\n  |   stp xzr, CARG3, [sp, #62*8]\t// Store 0/sp in RID_LR/RID_SP.\n  |  sub CARG1, CARG1, lr\n  |   ldr L, GL->cur_L\n  |  lsr CARG1, CARG1, #2\n  |   ldr BASE, GL->jit_base\n  |  sub CARG1, CARG1, #2\n  |   ldr CARG2w, [lr]\t\t// Load trace number.\n  |    st_vmstate CARG4w\n  |.if ENDIAN_BE\n  |   rev32 CARG2, CARG2\n  |.endif\n  |   str BASE, L->base\n  |  ubfx CARG2w, CARG2w, #5, #16\n  |  str CARG1w, [GL, #GL_J(exitno)]\n  |   str CARG2w, [GL, #GL_J(parent)]\n  |   str L, [GL, #GL_J(L)]\n  |  str xzr, GL->jit_base\n  |  add CARG1, GL, #GG_G2J\n  |  mov CARG2, sp\n  |  bl extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  ldr CARG2, L->cframe\n  |   ldr BASE, L->base\n  |  and sp, CARG2, #CFRAME_RAWMASK\n  |   ldr PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  str L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |  b >1\n  |.endif\n  |\n  |->vm_exit_interp:\n  |  // CARG1 = MULTRES or negated error code, BASE, PC and GL set.\n  |.if JIT\n  |  ldr L, SAVE_L\n  |1:\n  |  cmp CARG1w, #0\n  |  blt >9\t\t\t\t// Check for error from exit.\n  |   lsl RC, CARG1, #3\n  |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n  |    movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |    movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |    movn TISNIL, #0\n  |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n  |   str RCw, SAVE_MULTRES\n  |   str BASE, L->base\n  |  ldr CARG2, LFUNC:CARG2->pc\n  |   str xzr, GL->jit_base\n  |    mv_vmstate CARG4w, INTERP\n  |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  ldrb RBw, [PC, # OFS_OP]\n  |   ldr INSw, [PC], #4\n  |    st_vmstate CARG4w\n  |  cmp RBw, #BC_FUNCC+2\t\t// Fast function?\n  |   add TMP1, GL, INS, uxtb #3\n  |  bhs >4\n  |2:\n  |  cmp RBw, #BC_FUNCF\t\t\t// Function header?\n  |  add TMP0, GL, RB, uxtb #3\n  |  ldr RB, [TMP0, #GG_G2DISP]\n  |   decode_RA RA, INS\n  |   lsr TMP0, INS, #16\n  |   csel RC, TMP0, RC, lo\n  |   blo >5\n  |   ldr CARG3, [BASE, FRAME_FUNC]\n  |   sub RC, RC, #8\n  |   add RA, BASE, RA, lsl #3\t// Yes: RA = BASE+framesize*8, RC = nargs*8\n  |   and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |5:\n  |  br RB\n  |\n  |4:  // Check frame below fast function.\n  |  ldr CARG1, [BASE, FRAME_PC]\n  |  ands CARG2, CARG1, #FRAME_TYPE\n  |  bne <2\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  ldr CARG3w, [CARG1, #-4]\n  |  decode_RA CARG1, CARG3\n  |  sub CARG2, BASE, CARG1, lsl #3\n  |  ldr LFUNC:CARG3, [CARG2, #-32]\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ldr CARG3, LFUNC:CARG3->pc\n  |  ldr KBASE, [CARG3, #PC2PROTO(k)]\n  |  b <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  neg CARG2w, CARG1w\n  |  mov CARG1, L\n  |  bl extern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |  // int lj_vm_modi(int dividend, int divisor);\n  |->vm_modi:\n  |    eor CARG4w, CARG1w, CARG2w\n  |    cmp CARG4w, #0\n  |  eor CARG3w, CARG1w, CARG1w, asr #31\n  |   eor CARG4w, CARG2w, CARG2w, asr #31\n  |  sub CARG3w, CARG3w, CARG1w, asr #31\n  |   sub CARG4w, CARG4w, CARG2w, asr #31\n  |  udiv CARG1w, CARG3w, CARG4w\n  |  msub CARG1w, CARG1w, CARG4w, CARG3w\n  |    ccmp CARG1w, #0, #4, mi\n  |    sub CARG3w, CARG1w, CARG4w\n  |    csel CARG1w, CARG1w, CARG3w, eq\n  |  eor CARG3w, CARG1w, CARG2w\n  |  cmp CARG3w, #0\n  |  cneg CARG1w, CARG1w, mi\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.define NEXT_TAB,\t\tTAB:CARG1\n  |.define NEXT_RES,\t\tCARG1\n  |.define NEXT_IDX,\t\tCARG2w\n  |.define NEXT_LIM,\t\tCARG3w\n  |.define NEXT_TMP0,\t\tTMP0\n  |.define NEXT_TMP0w,\t\tTMP0w\n  |.define NEXT_TMP1,\t\tTMP1\n  |.define NEXT_TMP1w,\t\tTMP1w\n  |.define NEXT_RES_PTR,\tsp\n  |.define NEXT_RES_VAL,\t[sp]\n  |.define NEXT_RES_KEY,\t[sp, #8]\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in CRET2w.\n  |->vm_next:\n  |.if JIT\n  |  ldr NEXT_LIM, NEXT_TAB->asize\n  |   ldr NEXT_TMP1, NEXT_TAB->array\n  |1:  // Traverse array part.\n  |  subs NEXT_TMP0w, NEXT_IDX, NEXT_LIM\n  |  bhs >5\t\t\t\t// Index points after array part?\n  |  ldr NEXT_TMP0, [NEXT_TMP1, NEXT_IDX, uxtw #3]\n  |  cmn NEXT_TMP0, #-LJ_TNIL\n  |   cinc NEXT_IDX, NEXT_IDX, eq\n  |  beq <1\t\t\t\t// Skip holes in array part.\n  |  str NEXT_TMP0, NEXT_RES_VAL\n  |   movz NEXT_TMP0w, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |   stp NEXT_IDX, NEXT_TMP0w, NEXT_RES_KEY\n  |  add NEXT_IDX, NEXT_IDX, #1\n  |  mov NEXT_RES, NEXT_RES_PTR\n  |4:\n  |  ret\n  |\n  |5:  // Traverse hash part.\n  |  ldr NEXT_TMP1w, NEXT_TAB->hmask\n  |   ldr NODE:NEXT_RES, NEXT_TAB->node\n  |   add NEXT_TMP0w, NEXT_TMP0w, NEXT_TMP0w, lsl #1\n  |  add NEXT_LIM, NEXT_LIM, NEXT_TMP1w\n  |   add NODE:NEXT_RES, NODE:NEXT_RES, NEXT_TMP0w, uxtw #3\n  |6:\n  |  cmp NEXT_IDX, NEXT_LIM\n  |  bhi >9\n  |  ldr NEXT_TMP0, NODE:NEXT_RES->val\n  |  cmn NEXT_TMP0, #-LJ_TNIL\n  |   add NEXT_IDX, NEXT_IDX, #1\n  |  bne <4\n  |  // Skip holes in hash part.\n  |  add NODE:NEXT_RES, NODE:NEXT_RES, #sizeof(Node)\n  |  b <6\n  |\n  |9:  // End of iteration. Set the key to nil (not the value).\n  |  movn NEXT_TMP0, #0\n  |  str NEXT_TMP0, NEXT_RES_KEY\n  |  mov NEXT_RES, NEXT_RES_PTR\n  |  ret\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions.\n  |// Saveregs already performed. Callback slot number in [sp], g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  ldr CTSTATE, GL:x10->ctype_state\n  |  mov GL, x10\n  |    add x10, sp, # CFRAME_SPACE\n  |  str w9, CTSTATE->cb.slot\n  |  stp x0, x1, CTSTATE->cb.gpr[0]\n  |   stp d0, d1, CTSTATE->cb.fpr[0]\n  |  stp x2, x3, CTSTATE->cb.gpr[2]\n  |   stp d2, d3, CTSTATE->cb.fpr[2]\n  |  stp x4, x5, CTSTATE->cb.gpr[4]\n  |   stp d4, d5, CTSTATE->cb.fpr[4]\n  |  stp x6, x7, CTSTATE->cb.gpr[6]\n  |   stp d6, d7, CTSTATE->cb.fpr[6]\n  |    str x10, CTSTATE->cb.stack\n  |  mov CARG1, CTSTATE\n  |   str CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  mov CARG2, sp\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  ldp BASE, RC, L:CRET1->base\n  |   movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48\n  |   movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16\n  |   movn TISNIL, #0\n  |   mov L, CRET1\n  |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n  |  sub RC, RC, BASE\n  |   st_vmstate ST_INTERP\n  |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  ldr CTSTATE, GL->ctype_state\n  |   stp BASE, CARG4, L->base\n  |  str L, CTSTATE->L\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RA\n  |  bl extern lj_ccallback_leave       // (CTState *cts, TValue *o)\n  |  ldp x0, x1, CTSTATE->cb.gpr[0]\n  |   ldp d0, d1, CTSTATE->cb.fpr[0]\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, x19\n  |  stp x20, CCSTATE, [sp, #-32]!\n  |  stp fp, lr, [sp, #16]\n  |  add fp, sp, #16\n  |  mov CCSTATE, x0\n  |  ldr TMP0w, CCSTATE:x0->spadj\n  |   ldrb TMP1w, CCSTATE->nsp\n  |    add TMP2, CCSTATE, #offsetof(CCallState, stack)\n  |   subs TMP1, TMP1, #1\n  |    ldr TMP3, CCSTATE->func\n  |  sub sp, sp, TMP0\n  |   bmi >2\n  |1:  // Copy stack slots\n  |  ldr TMP0, [TMP2, TMP1, lsl #3]\n  |  str TMP0, [sp, TMP1, lsl #3]\n  |  subs TMP1, TMP1, #1\n  |  bpl <1\n  |2:\n  |  ldp x0, x1, CCSTATE->gpr[0]\n  |   ldp d0, d1, CCSTATE->fpr[0]\n  |  ldp x2, x3, CCSTATE->gpr[2]\n  |   ldp d2, d3, CCSTATE->fpr[2]\n  |  ldp x4, x5, CCSTATE->gpr[4]\n  |   ldp d4, d5, CCSTATE->fpr[4]\n  |  ldp x6, x7, CCSTATE->gpr[6]\n  |   ldp d6, d7, CCSTATE->fpr[6]\n  |  ldr x8, CCSTATE->retp\n  |  blr TMP3\n  |  sub sp, fp, #16\n  |  stp x0, x1, CCSTATE->gpr[0]\n  |   stp d0, d1, CCSTATE->fpr[0]\n  |   stp d2, d3, CCSTATE->fpr[2]\n  |  ldp fp, lr, [sp, #16]\n  |  ldp x20, CCSTATE, [sp], #32\n  |  ret\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RC = src2, JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |    ldrh RBw, [PC, # OFS_RD]\n    |   ldr CARG2, [BASE, RC, lsl #3]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    |  checkint CARG1, >3\n    |   checkint CARG2, >4\n    |  cmp CARG1w, CARG2w\n    if (op == BC_ISLT) {\n      |  csel PC, RB, PC, lt\n    } else if (op == BC_ISGE) {\n      |  csel PC, RB, PC, ge\n    } else if (op == BC_ISLE) {\n      |  csel PC, RB, PC, le\n    } else {\n      |  csel PC, RB, PC, gt\n    }\n    |1:\n    |  ins_next\n    |\n    |3:  // RA not int.\n    |    ldr FARG1, [BASE, RA, lsl #3]\n    |  blo ->vmeta_comp\n    |    ldr FARG2, [BASE, RC, lsl #3]\n    |   cmp TISNUMhi, CARG2, lsr #32\n    |   bhi >5\n    |   bne ->vmeta_comp\n    |  // RA number, RC int.\n    |  scvtf FARG2, CARG2w\n    |  b >5\n    |\n    |4:  // RA int, RC not int\n    |    ldr FARG2, [BASE, RC, lsl #3]\n    |   blo ->vmeta_comp\n    |  // RA int, RC number.\n    |  scvtf FARG1, CARG1w\n    |\n    |5:  // RA number, RC number\n    |  fcmp FARG1, FARG2\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    if (op == BC_ISLT) {\n      |  csel PC, RB, PC, lo\n    } else if (op == BC_ISGE) {\n      |  csel PC, RB, PC, hs\n    } else if (op == BC_ISLE) {\n      |  csel PC, RB, PC, ls\n    } else {\n      |  csel PC, RB, PC, hi\n    }\n    |  b <1\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1, RC = src2, JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add RC, BASE, RC, lsl #3\n    |    ldrh RBw, [PC, # OFS_RD]\n    |   ldr CARG3, [RC]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    |  asr ITYPE, CARG3, #47\n    |  cmn ITYPE, #-LJ_TISNUM\n    if (vk) {\n      |  bls ->BC_ISEQN_Z\n    } else {\n      |  bls ->BC_ISNEN_Z\n    }\n    |  // RC is not a number.\n    |   asr TMP0, CARG1, #47\n    |.if FFI\n    |  // Check if RC or RA is a cdata.\n    |  cmn ITYPE, #-LJ_TCDATA\n    |   ccmn TMP0, #-LJ_TCDATA, #4, ne\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG1, CARG3\n    |  bne >2\n    |  // Tag and value are equal.\n    if (vk) {\n      |->BC_ISEQV_Z:\n      |  mov PC, RB\t\t\t// Perform branch.\n    }\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if the tags are the same and it's a table or userdata.\n    |  cmp ITYPE, TMP0\n    |  ccmn ITYPE, #-LJ_TISTABUD, #2, eq\n    if (vk) {\n      |  bhi <1\n    } else {\n      |  bhi ->BC_ISEQV_Z\t\t// Reuse code from opposite instruction.\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  and TAB:CARG2, CARG1, #LJ_GCVMASK\n    |  ldr TAB:TMP2, TAB:CARG2->metatable\n    if (vk) {\n      |  cbz TAB:TMP2, <1\t\t// No metatable?\n      |  ldrb TMP1w, TAB:TMP2->nomm\n      |   mov CARG4, #0\t\t\t// ne = 0\n      |  tbnz TMP1w, #MM_eq, <1\t\t// 'no __eq' flag set: done.\n    } else {\n      |  cbz TAB:TMP2, ->BC_ISEQV_Z\t// No metatable?\n      |  ldrb TMP1w, TAB:TMP2->nomm\n      |   mov CARG4, #1\t\t\t// ne = 1.\n      |  tbnz TMP1w, #MM_eq, ->BC_ISEQV_Z\t// 'no __eq' flag set: done.\n    }\n    |  b ->vmeta_equal\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src, RC = str_const (~), JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   mvn RC, RC\n    |    ldrh RBw, [PC, # OFS_RD]\n    |   ldr CARG2, [KBASE, RC, lsl #3]\n    |    add PC, PC, #4\n    |   movn TMP0, #~LJ_TSTR\n    |.if FFI\n    |  asr ITYPE, CARG1, #47\n    |.endif\n    |    add RB, PC, RB, lsl #2\n    |   add CARG2, CARG2, TMP0, lsl #47\n    |    sub RB, RB, #0x20000\n    |.if FFI\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  cmp CARG1, CARG2\n    if (vk) {\n      |  csel PC, RB, PC, eq\n    } else {\n      |  csel PC, RB, PC, ne\n    }\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src, RC = num_const (~), JMP with RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add RC, KBASE, RC, lsl #3\n    |    ldrh RBw, [PC, # OFS_RD]\n    |   ldr CARG3, [RC]\n    |    add PC, PC, #4\n    |    add RB, PC, RB, lsl #2\n    |    sub RB, RB, #0x20000\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  checkint CARG1, >4\n    |   checkint CARG3, >6\n    |  cmp CARG1w, CARG3w\n    |1:\n    if (vk) {\n      |  csel PC, RB, PC, eq\n      |2:\n    } else {\n      |2:\n      |  csel PC, RB, PC, ne\n    }\n    |3:\n    |  ins_next\n    |\n    |4:  // RA not int.\n    |.if FFI\n    |  blo >7\n    |.else\n    |  blo <2\n    |.endif\n    |    ldr FARG1, [BASE, RA, lsl #3]\n    |    ldr FARG2, [RC]\n    |   cmp TISNUMhi, CARG3, lsr #32\n    |   bne >5\n    |  // RA number, RC int.\n    |  scvtf FARG2, CARG3w\n    |5:\n    |  // RA number, RC number.\n    |  fcmp FARG1, FARG2\n    |  b <1\n    |\n    |6:  // RA int, RC number\n    |  ldr FARG2, [RC]\n    |  scvtf FARG1, CARG1w\n    |  fcmp FARG1, FARG2\n    |  b <1\n    |\n    |.if FFI\n    |7:\n    |  asr ITYPE, CARG1, #47\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  bne <2\n    |  b ->vmeta_equal_cd\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src, RC = primitive_type (~), JMP with RC = target\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |   ldrh RBw, [PC, # OFS_RD]\n    |   add PC, PC, #4\n    |  add RC, RC, #1\n    |   add RB, PC, RB, lsl #2\n    |.if FFI\n    |  asr ITYPE, TMP0, #47\n    |  cmn ITYPE, #-LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |  cmn RC, ITYPE\n    |.else\n    |  cmn RC, TMP0, asr #47\n    |.endif\n    |   sub RB, RB, #0x20000\n    if (vk) {\n      |  csel PC, RB, PC, eq\n    } else {\n      |  csel PC, RB, PC, ne\n    }\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst or unused, RC = src, JMP with RC = target\n    |   ldrh RBw, [PC, # OFS_RD]\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |   add PC, PC, #4\n    |  mov_false TMP1\n    |   add RB, PC, RB, lsl #2\n    |  cmp TMP0, TMP1\n    |   sub RB, RB, #0x20000\n    if (op == BC_ISTC || op == BC_IST) {\n      if (op == BC_ISTC) {\n\t|  csel RA, RA, RC, lo\n      }\n      |  csel PC, RB, PC, lo\n    } else {\n      if (op == BC_ISFC) {\n\t|  csel RA, RA, RC, hs\n      }\n      |  csel PC, RB, PC, hs\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  str TMP0, [BASE, RA, lsl #3]\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src, RC = -type\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |  cmn RC, TMP0, asr #47\n    |  bne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  // RA = src, RC = -(TISNUM-1)\n    |  ldr TMP0, [BASE, RA]\n    |  checknum TMP0, ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_NOT:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |   mov_false TMP1\n    |   mov_true TMP2\n    |  cmp TMP0, TMP1\n    |  csel TMP0, TMP1, TMP2, lo\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  // RA = dst, RC = src\n    |  ldr TMP0, [BASE, RC, lsl #3]\n    |  asr ITYPE, TMP0, #47\n    |  cmn ITYPE, #-LJ_TISNUM\n    |  bhi ->vmeta_unm\n    |  eor TMP0, TMP0, #U64x(80000000,00000000)\n    |  bne >5\n    |  negs TMP0w, TMP0w\n    |   movz CARG3, #0x41e0, lsl #48\t// 2^31.\n    |   add TMP0, TMP0, TISNUM\n    |  csel TMP0, TMP0, CARG3, vc\n    |5:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_LEN:\n    |  // RA = dst, RC = src\n    |  ldr CARG1, [BASE, RC, lsl #3]\n    |  asr ITYPE, CARG1, #47\n    |  cmn ITYPE, #-LJ_TSTR\n    |   and CARG1, CARG1, #LJ_GCVMASK\n    |  bne >2\n    |  ldr CARG1w, STR:CARG1->len\n    |1:\n    |  add CARG1, CARG1, TISNUM\n    |  str CARG1, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |2:\n    |  cmn ITYPE, #-LJ_TTAB\n    |  bne ->vmeta_len\n#if LJ_52\n    |  ldr TAB:CARG2, TAB:CARG1->metatable\n    |  cbnz TAB:CARG2, >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n    |\n#if LJ_52\n    |9:\n    |  ldrb TMP1w, TAB:CARG2->nomm\n    |  tbnz TMP1w, #MM_len, <3\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithcheck_int, target\n    |  checkint CARG1, target\n    |  checkint CARG2, target\n    |.endmacro\n    |\n    |.macro ins_arithcheck_num, target\n    |  checknum CARG1, target\n    |  checknum CARG2, target\n    |.endmacro\n    |\n    |.macro ins_arithcheck_nzdiv, target\n    |  cbz CARG2w, target\n    |.endmacro\n    |\n    |.macro ins_arithhead\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||if (vk == 1) {\n    |   and RC, RC, #255\n    |    decode_RB RB, INS\n    ||} else {\n    |   decode_RB RB, INS\n    |    and RC, RC, #255\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithload, reg1, reg2\n    |  // RA = dst, RB = src1, RC = src2 | num_const\n    ||switch (vk) {\n    ||case 0:\n    |   ldr reg1, [BASE, RB, lsl #3]\n    |    ldr reg2, [KBASE, RC, lsl #3]\n    ||  break;\n    ||case 1:\n    |   ldr reg1, [KBASE, RC, lsl #3]\n    |    ldr reg2, [BASE, RB, lsl #3]\n    ||  break;\n    ||default:\n    |   ldr reg1, [BASE, RB, lsl #3]\n    |    ldr reg2, [BASE, RC, lsl #3]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithmod, res, reg1, reg2\n    |  fdiv d2, reg1, reg2\n    |  frintm d2, d2\n    |  fmsub res, d2, reg2, reg1\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins\n    |  ins_arithhead\n    |  ins_arithload CARG1, CARG2\n    |  ins_arithcheck_int >5\n    |.if \"intins\" == \"smull\"\n    |  smull CARG1, CARG1w, CARG2w\n    |  cmp CARG1, CARG1, sxtw\n    |   mov CARG1w, CARG1w\n    |  ins_arithfallback bne\n    |.elif \"intins\" == \"ins_arithmodi\"\n    |  ins_arithfallback ins_arithcheck_nzdiv\n    |  bl ->vm_modi\n    |.else\n    |  intins CARG1w, CARG1w, CARG2w\n    |  ins_arithfallback bvs\n    |.endif\n    |  add CARG1, CARG1, TISNUM\n    |  str CARG1, [BASE, RA, lsl #3]\n    |4:\n    |  ins_next\n    |\n    |5:  // FP variant.\n    |  ins_arithload FARG1, FARG2\n    |  ins_arithfallback ins_arithcheck_num\n    |  fpins FARG1, FARG1, FARG2\n    |  str FARG1, [BASE, RA, lsl #3]\n    |  b <4\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins\n    |  ins_arithhead\n    |  ins_arithload CARG1, CARG2\n    |  ins_arithload FARG1, FARG2\n    |  ins_arithfallback ins_arithcheck_num\n    |.if \"fpins\" == \"fpow\"\n    |  bl extern pow\n    |.else\n    |  fpins FARG1, FARG1, FARG2\n    |.endif\n    |  str FARG1, [BASE, RA, lsl #3]\n    |  ins_next\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arithdn adds, fadd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arithdn subs, fsub\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arithdn smull, fmul\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp fdiv\n    break;\n  case BC_MODVN: case BC_MODNV: case BC_MODVV:\n    |  ins_arithdn ins_arithmodi, ins_arithmod\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  ins_arithfp fpow\n    break;\n\n  case BC_CAT:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = src_start, RC = src_end\n    |   str BASE, L->base\n    |  sub CARG3, RC, RB\n    |  add CARG2, BASE, RC, lsl #3\n    |->BC_CAT_Z:\n    |  // RA = dst, CARG2 = top-1, CARG3 = left\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  ldrb RBw, [PC, #-4+OFS_RB]\n    |   ldr BASE, L->base\n    |   cbnz CRET1, ->vmeta_binop\n    |  ldr TMP0, [BASE, RB, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\t// Copy result to RA.\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst, RC = str_const (~)\n    |  mvn RC, RC\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |   movn TMP1, #~LJ_TSTR\n    |  add TMP0, TMP0, TMP1, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst, RC = cdata_const (~)\n    |  mvn RC, RC\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |   movn TMP1, #~LJ_TCDATA\n    |  add TMP0, TMP0, TMP1, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst, RC = int16_literal\n    |  sxth RCw, RCw\n    |  add TMP0, RC, TISNUM\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  // RA = dst, RC = num_const\n    |  ldr TMP0, [KBASE, RC, lsl #3]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  // RA = dst, RC = primitive_type (~)\n    |  mvn TMP0, RC, lsl #47\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  // RA = base, RC = end\n    |  add RA, BASE, RA, lsl #3\n    |   add RC, BASE, RC, lsl #3\n    |  str TISNIL, [RA], #8\n    |1:\n    |   cmp RA, RC\n    |  str TISNIL, [RA], #8\n    |   blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst, RC = uvnum\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RC, RC, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RC, lsl #3]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |  ldr TMP0, [CARG2]\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n  case BC_USETV:\n    |  // RA = uvnum, RC = src\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG1, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr CARG3, [BASE, RC, lsl #3]\n    |    ldr CARG2, UPVAL:CARG1->v\n    |  ldrb TMP2w, UPVAL:CARG1->marked\n    |  ldrb TMP0w, UPVAL:CARG1->closed\n    |    asr ITYPE, CARG3, #47\n    |   str CARG3, [CARG2]\n    |    add ITYPE, ITYPE, #-LJ_TISGCV\n    |  tst TMP2w, #LJ_GC_BLACK\t\t// isblack(uv)\n    |  ccmp TMP0w, #0, #4, ne\t\t// && uv->closed\n    |    ccmn ITYPE, #-(LJ_TNUMX - LJ_TISGCV), #0, ne\t// && tvisgcv(v)\n    |  bhi >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is white.\n    |  and GCOBJ:CARG3, CARG3, #LJ_GCVMASK\n    |  ldrb TMP1w, GCOBJ:CARG3->gch.marked\n    |  tst TMP1w, #LJ_GC_WHITES\t\t// iswhite(str)\n    |  beq <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov CARG1, GL\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum, RC = str_const (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |    mvn RC, RC\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG1, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr STR:CARG3, [KBASE, RC, lsl #3]\n    |   movn TMP0, #~LJ_TSTR\n    |    ldr CARG2, UPVAL:CARG1->v\n    |  ldrb TMP2w, UPVAL:CARG1->marked\n    |   add TMP0, STR:CARG3, TMP0, lsl #47\n    |    ldrb TMP1w, STR:CARG3->marked\n    |   str TMP0, [CARG2]\n    |  tbnz TMP2w, #2, >2\t\t// isblack(uv)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  ldrb TMP0w, UPVAL:CARG1->closed\n    |    tst TMP1w, #LJ_GC_WHITES\t// iswhite(str)\n    |  ccmp TMP0w, #0, #4, ne\n    |  beq <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov CARG1, GL\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum, RC = num_const\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA, lsl #3]\n    |   ldr TMP0, [KBASE, RC, lsl #3]\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   str TMP0, [CARG2]\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  // RA = uvnum, RC = primitive_type (~)\n    |  ldr LFUNC:CARG2, [BASE, FRAME_FUNC]\n    |   add RA, RA, #offsetof(GCfuncL, uvptr)/8\n    |  and LFUNC:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr UPVAL:CARG2, [LFUNC:CARG2, RA, lsl #3]\n    |   mvn TMP0, RC, lsl #47\n    |  ldr CARG2, UPVAL:CARG2->v\n    |   str TMP0, [CARG2]\n    |  ins_next\n    break;\n\n  case BC_UCLO:\n    |  // RA = level, RC = target\n    |  ldr CARG3, L->openupval\n    |   add RC, PC, RC, lsl #2\n    |    str BASE, L->base\n    |   sub PC, RC, #0x20000\n    |  cbz CARG3, >1\n    |  mov CARG1, L\n    |  add CARG2, BASE, RA, lsl #3\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  ldr BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst, RC = proto_const (~) (holding function prototype)\n    |  mvn RC, RC\n    |   str BASE, L->base\n    |  ldr LFUNC:CARG3, [BASE, FRAME_FUNC]\n    |    str PC, SAVE_PC\n    |   ldr CARG2, [KBASE, RC, lsl #3]\n    |    mov CARG1, L\n    |  and LFUNC:CARG3, CARG3, #LJ_GCVMASK\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  ldr BASE, L->base\n    |   movn TMP0, #~LJ_TFUNC\n    |   add CRET1, CRET1, TMP0, lsl #47\n    |  str CRET1, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst, RC = (hbits|asize) | tab_const (~)\n    |  ldp CARG3, CARG4, GL->gc.total\t// Assumes threshold follows total.\n    |   str BASE, L->base\n    |   str PC, SAVE_PC\n    |   mov CARG1, L\n    |  cmp CARG3, CARG4\n    |  bhs >5\n    |1:\n    if (op == BC_TNEW) {\n      |  and CARG2, RC, #0x7ff\n      |   lsr CARG3, RC, #11\n      |  cmp CARG2, #0x7ff\n      |  mov TMP0, #0x801\n      |  csel CARG2, CARG2, TMP0, ne\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns GCtab *.\n    } else {\n      |  mvn RC, RC\n      |  ldr CARG2, [KBASE, RC, lsl #3]\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns GCtab *.\n    }\n    |  ldr BASE, L->base\n    |   movk CRET1, #(LJ_TTAB>>1)&0xffff, lsl #48\n    |  str CRET1, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mov CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst, RC = str_const (~)\n  case BC_GSET:\n    |  // RA = src, RC = str_const (~)\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |   mvn RC, RC\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr TAB:CARG2, LFUNC:CARG1->env\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tgetv\n    |  checkint TMP1, >9\t\t// Integer key?\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, TMP1, uxtw #3\n    |   cmp TMP1w, CARG1w\t\t// In array part?\n    |   bhs ->vmeta_tgetv\n    |  ldr TMP0, [CARG3]\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |1:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <1\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetv\n    |\n    |9:\n    |  asr ITYPE, TMP1, #47\n    |  cmn ITYPE, #-LJ_TSTR\t\t// String key?\n    |  bne ->vmeta_tgetv\n    |   and STR:RC, TMP1, #LJ_GCVMASK\n    |  b ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = str_const (~)\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // TAB:CARG2 = GCtab *, STR:RC = GCstr *, RA = dst\n    |  ldr TMP1w, TAB:CARG2->hmask\n    |   ldr TMP2w, STR:RC->sid\n    |    ldr NODE:CARG3, TAB:CARG2->node\n    |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->sid & tab->hmask\n    |  add TMP1, TMP1, TMP1, lsl #1\n    |  movn CARG4, #~LJ_TSTR\n    |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n    |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n    |1:\n    |  ldp TMP0, CARG1, NODE:CARG3->val\n    |   ldr NODE:CARG3, NODE:CARG3->next\n    |  cmp CARG1, CARG4\n    |  bne >4\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |3:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  cbnz NODE:CARG3, <1\n    |  // End of hash chain: key not found, nil result.\n    |   mov TMP0, TISNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <3\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <3\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = index\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |  checktab CARG2, ->vmeta_tgetb\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, RC, lsl #3\n    |   cmp RCw, CARG1w\t\t\t// In array part?\n    |   bhs ->vmeta_tgetb\n    |  ldr TMP0, [CARG3]\n    |  cmp TMP0, TISNIL\n    |  beq >5\n    |1:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_index, <1\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\n    break;\n  case BC_TGETR:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = key\n    |  ldr CARG1, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  and TAB:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG3, TAB:CARG1->array\n    |   ldr TMP2w, TAB:CARG1->asize\n    |  add CARG3, CARG3, TMP1w, uxtw #3\n    |   cmp TMP1w, TMP2w\t\t// In array part?\n    |   bhs ->vmeta_tgetr\n    |  ldr TMP0, [CARG3]\n    |->BC_TGETR_Z:\n    |  str TMP0, [BASE, RA, lsl #3]\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tsetv\n    |  checkint TMP1, >9\t\t// Integer key?\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, TMP1, uxtw #3\n    |   cmp TMP1w, CARG1w\t\t// In array part?\n    |   bhs ->vmeta_tsetv\n    |  ldr TMP1, [CARG3]\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >5\n    |1:\n    |   str TMP0, [CARG3]\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <1\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetv\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <2\n    |\n    |9:\n    |  asr ITYPE, TMP1, #47\n    |  cmn ITYPE, #-LJ_TSTR\t\t// String key?\n    |  bne ->vmeta_tsetv\n    |   and STR:RC, TMP1, #LJ_GCVMASK\n    |  b ->BC_TSETS_Z\n    break;\n  case BC_TSETS:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = dst, RB = table, RC = str_const (~)\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   mvn RC, RC\n    |   ldr STR:RC, [KBASE, RC, lsl #3]\n    |  checktab CARG2, ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // TAB:CARG2 = GCtab *, STR:RC = GCstr *, RA = src\n    |  ldr TMP1w, TAB:CARG2->hmask\n    |   ldr TMP2w, STR:RC->sid\n    |    ldr NODE:CARG3, TAB:CARG2->node\n    |  and TMP1w, TMP1w, TMP2w\t\t// idx = str->sid & tab->hmask\n    |  add TMP1, TMP1, TMP1, lsl #1\n    |  movn CARG4, #~LJ_TSTR\n    |    add NODE:CARG3, NODE:CARG3, TMP1, lsl #3  // node = tab->node + idx*3*8\n    |  add CARG4, STR:RC, CARG4, lsl #47\t// Tagged key to look for.\n    |   strb wzr, TAB:CARG2->nomm\t// Clear metamethod cache.\n    |1:\n    |  ldp TMP1, CARG1, NODE:CARG3->val\n    |   ldr NODE:TMP3, NODE:CARG3->next\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp CARG1, CARG4\n    |  bne >5\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >4\n    |2:\n    |   str TMP0, NODE:CARG3->val\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <2\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <2\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:CARG3, NODE:TMP3\n    |  cbnz NODE:TMP3, <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, >6\t\t// No metatable: continue.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  // 'no __newindex' flag NOT set: check.\n    |  tbz TMP1w, #MM_newindex, ->vmeta_tsets\n    |6:\n    |  movn TMP1, #~LJ_TSTR\n    |   str PC, SAVE_PC\n    |  add TMP0, STR:RC, TMP1, lsl #47\n    |   str BASE, L->base\n    |   mov CARG1, L\n    |  str TMP0, TMPD\n    |   add CARG3, sp, TMPDofs\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  ldr BASE, L->base\n    |  ldr TMP0, [BASE, RA, lsl #3]\n    |  str TMP0, [CRET1]\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = index\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |  checktab CARG2, ->vmeta_tsetb\n    |  ldr CARG3, TAB:CARG2->array\n    |   ldr CARG1w, TAB:CARG2->asize\n    |  add CARG3, CARG3, RC, lsl #3\n    |   cmp RCw, CARG1w\t\t\t// In array part?\n    |   bhs ->vmeta_tsetb\n    |  ldr TMP1, [CARG3]\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |  cmp TMP1, TISNIL\t\t\t// Previous value is nil?\n    |  beq >5\n    |1:\n    |   str TMP0, [CARG3]\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ldr TAB:CARG1, TAB:CARG2->metatable\n    |  cbz TAB:CARG1, <1\t\t// No metatable: done.\n    |  ldrb TMP1w, TAB:CARG1->nomm\n    |  tbnz TMP1w, #MM_newindex, <1\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetb\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = src, RB = table, RC = key\n    |  ldr CARG2, [BASE, RB, lsl #3]\n    |   ldr TMP1, [BASE, RC, lsl #3]\n    |  and TAB:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr CARG1, TAB:CARG2->array\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |   ldr CARG4w, TAB:CARG2->asize\n    |  add CARG1, CARG1, TMP1, uxtw #3\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |2:\n    |   cmp TMP1w, CARG4w\t\t// In array part?\n    |   bhs ->vmeta_tsetr\n    |->BC_TSETR_Z:\n    |   ldr TMP0, [BASE, RA, lsl #3]\n    |   str TMP0, [CARG1]\n    |   ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP0\n    |  b <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base (table at base-1), RC = num_const (start index)\n    |  add RA, BASE, RA, lsl #3\n    |1:\n    |   ldr RBw, SAVE_MULTRES\n    |  ldr TAB:CARG2, [RA, #-8]\t\t// Guaranteed to be a table.\n    |   ldr TMP1, [KBASE, RC, lsl #3]\t// Integer constant is in lo-word.\n    |    sub RB, RB, #8\n    |    cbz RB, >4\t\t\t// Nothing to copy?\n    |  and TAB:CARG2, CARG2, #LJ_GCVMASK\n    |  ldr CARG1w, TAB:CARG2->asize\n    |   add CARG3w, TMP1w, RBw, lsr #3\n    |   ldr CARG4, TAB:CARG2->array\n    |  cmp CARG3, CARG1\n    |    add RB, RA, RB\n    |  bhi >5\n    |   add TMP1, CARG4, TMP1w, uxtw #3\n    |    ldrb TMP2w, TAB:CARG2->marked\n    |3:  // Copy result slots to table.\n    |   ldr TMP0, [RA], #8\n    |   str TMP0, [TMP1], #8\n    |  cmp RA, RB\n    |  blo <3\n    |    tbnz TMP2w, #2, >7\t\t// isblack(table)\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   str BASE, L->base\n    |  mov CARG1, L\n    |   str PC, SAVE_PC\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP2w, TMP1\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base, (RB = nresults+1,) RC = extra_nargs\n    |  ldr TMP0w, SAVE_MULTRES\n    |  decode_RC8RD NARGS8:RC, RC\n    |  add NARGS8:RC, NARGS8:RC, TMP0\n    |  b ->BC_CALL_Z\n    break;\n  case BC_CALL:\n    |  decode_RC8RD NARGS8:RC, RC\n    |  // RA = base, (RB = nresults+1,) RC = (nargs+1)*8\n    |->BC_CALL_Z:\n    |  mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |  add BASE, BASE, RA, lsl #3\n    |  ldr CARG3, [BASE]\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add BASE, BASE, #16\n    |  checkfunc CARG3, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base, (RB = 0,) RC = extra_nargs\n    |  ldr TMP0w, SAVE_MULTRES\n    |  add NARGS8:RC, TMP0, RC, lsl #3\n    |  b ->BC_CALLT1_Z\n    break;\n  case BC_CALLT:\n    |  lsl NARGS8:RC, RC, #3\n    |  // RA = base, (RB = 0,) RC = (nargs+1)*8\n    |->BC_CALLT1_Z:\n    |  add RA, BASE, RA, lsl #3\n    |  ldr TMP1, [RA]\n    |   sub NARGS8:RC, NARGS8:RC, #8\n    |   add RA, RA, #16\n    |  checktp CARG3, TMP1, LJ_TFUNC, ->vmeta_callt\n    |  ldr PC, [BASE, FRAME_PC]\n    |->BC_CALLT2_Z:\n    |   mov RB, #0\n    |   ldrb TMP2w, LFUNC:CARG3->ffid\n    |  tst PC, #FRAME_TYPE\n    |  bne >7\n    |1:\n    |  str TMP1, [BASE, FRAME_FUNC]\t// Copy function down, but keep PC.\n    |  cbz NARGS8:RC, >3\n    |2:\n    |  ldr TMP0, [RA, RB]\n    |   add TMP1, RB, #8\n    |   cmp TMP1, NARGS8:RC\n    |  str TMP0, [BASE, RB]\n    |    mov RB, TMP1\n    |   bne <2\n    |3:\n    |  cmp TMP2, #1\t\t\t// (> FF_C) Calling a fast function?\n    |  bhi >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  ldrb RAw, [PC, #-4+OFS_RA]\n    |  sub CARG1, BASE, RA, lsl #3\n    |  ldr LFUNC:CARG1, [CARG1, #-32]\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG1, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG1, #PC2PROTO(k)]\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  eor PC, PC, #FRAME_VARG\n    |  tst PC, #FRAME_TYPEP\t\t// Vararg frame below?\n    |  csel TMP2, RB, TMP2, ne\t\t// Clear ffid if no Lua function below.\n    |  bne <1\n    |  sub BASE, BASE, PC\n    |  ldr PC, [BASE, FRAME_PC]\n    |  tst PC, #FRAME_TYPE\n    |  csel TMP2, RB, TMP2, ne\t\t// Clear ffid if no Lua function below.\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA, lsl #3\n    |  ldr CARG3, [RA, #-24]\n    |    mov RB, BASE\t\t\t// Save old BASE for vmeta_call.\n    |   ldp CARG1, CARG2, [RA, #-16]\n    |    add BASE, RA, #16\n    |    mov NARGS8:RC, #16\t\t// Iterators get 2 arguments.\n    |  str CARG3, [RA]\t\t\t// Copy callable.\n    |   stp CARG1, CARG2, [RA, #16]\t// Copy state and control var.\n    |  checkfunc CARG3, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |->vm_IITERN:\n    |  // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  add RA, BASE, RA, lsl #3\n    |  ldr TAB:RB, [RA, #-16]\n    |    ldrh TMP3w, [PC, # OFS_RD]\n    |  ldr CARG1w, [RA, #-8+LO]\t\t// Get index from control var.\n    |    add PC, PC, #4\n    |    add TMP3, PC, TMP3, lsl #2\n    |  and TAB:RB, RB, #LJ_GCVMASK\n    |    sub TMP3, TMP3, #0x20000\n    |  ldr TMP1w, TAB:RB->asize\n    |   ldr CARG2, TAB:RB->array\n    |1:  // Traverse array part.\n    |  subs RC, CARG1, TMP1\n    |   add CARG3, CARG2, CARG1, lsl #3\n    |  bhs >5\t\t\t\t// Index points after array part?\n    |   ldr TMP0, [CARG3]\n    |   cmp TMP0, TISNIL\n    |   cinc CARG1, CARG1, eq\t\t// Skip holes in array part.\n    |   beq <1\n    |   add CARG1, CARG1, TISNUM\n    |   stp CARG1, TMP0, [RA]\n    |    add CARG1, CARG1, #1\n    |3:\n    |    str CARG1w, [RA, #-8+LO]\t// Update control var.\n    |  mov PC, TMP3\n    |4:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  ldr TMP2w, TAB:RB->hmask\n    |   ldr NODE:RB, TAB:RB->node\n    |6:\n    |   add CARG1, RC, RC, lsl #1\n    |  cmp RC, TMP2\t\t\t// End of iteration? Branch to ITERN+1.\n    |   add NODE:CARG3, NODE:RB, CARG1, lsl #3  // node = tab->node + idx*3*8\n    |  bhi <4\n    |  ldp TMP0, CARG1, NODE:CARG3->val\n    |  cmp TMP0, TISNIL\n    |   add RC, RC, #1\n    |  beq <6\t\t\t\t// Skip holes in hash part.\n    |  stp CARG1, TMP0, [RA]\n    |  add CARG1, RC, TMP1\n    |  b <3\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base, RC = target (points to ITERN)\n    |  add RA, BASE, RA, lsl #3\n    |  ldr CFUNC:CARG1, [RA, #-24]\n    |     add RC, PC, RC, lsl #2\n    |   ldp TAB:CARG3, CARG4, [RA, #-16]\n    |     sub RC, RC, #0x20000\n    |  checkfunc CFUNC:CARG1, >5\n    |   asr TMP0, TAB:CARG3, #47\n    |  ldrb TMP1w, CFUNC:CARG1->ffid\n    |   cmn TMP0, #-LJ_TTAB\n    |   ccmp CARG4, TISNIL, #0, eq\n    |  ccmp TMP1w, #FF_next_N, #0, eq\n    |  bne >5\n    |  mov TMP0w, #0xfffe7fff\t\t// LJ_KEYINDEX\n    |  lsl TMP0, TMP0, #32\n    |  str TMP0, [RA, #-8]\t\t// Initialize control var.\n    |1:\n    |     mov PC, RC\n    |  ins_next\n    |\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |.if JIT\n    |  ldrb TMP2w, [RC, # OFS_OP]\n    |.endif\n    |  mov TMP0, #BC_JMP\n    |   mov TMP1, #BC_ITERC\n    |  strb TMP0w, [PC, #-4+OFS_OP]\n    |.if JIT\n    |  cmp TMP2w, #BC_ITERN\n    |  bne >6\n    |.endif\n    |   strb TMP1w, [RC, # OFS_OP]\n    |  b <1\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  ldr RA, [GL, #GL_J(trace)]\n    |  ldrh TMP2w, [RC, # OFS_RD]\n    |  ldr TRACE:RA, [RA, TMP2, lsl #3]\n    |  ldr TMP2w, TRACE:RA->startins\n    |  bfxil TMP2w, TMP1w, #0, #8\n    |  str TMP2w, [RC]\n    |  b <1\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  decode_RB RB, INS\n    |   and RC, RC, #255\n    |  // RA = base, RB = (nresults+1), RC = numparams\n    |  ldr TMP1, [BASE, FRAME_PC]\n    |  add RC, BASE, RC, lsl #3\n    |   add RA, BASE, RA, lsl #3\n    |  add RC, RC, #FRAME_VARG\n    |   add TMP2, RA, RB, lsl #3\n    |  sub RC, RC, TMP1\t\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |   sub TMP3, BASE, #16\t\t// TMP3 = vtop\n    |  cbz RB, >5\n    |   sub TMP2, TMP2, #16\n    |1:  // Copy vararg slots to destination slots.\n    |  cmp RC, TMP3\n    |  ldr TMP0, [RC], #8\n    |  csel TMP0, TMP0, TISNIL, lo\n    |   cmp RA, TMP2\n    |  str TMP0, [RA], #8\n    |   blo <1\n    |2:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  ldr TMP0, L->maxstack\n    |   subs TMP2, TMP3, RC\n    |   csel RB, xzr, TMP2, le\t\t// MULTRES = (max(vtop-vbase,0)+1)*8\n    |   add RB, RB, #8\n    |  add TMP1, RA, TMP2\n    |   str RBw, SAVE_MULTRES\n    |   ble <2\t\t\t\t// Nothing to copy.\n    |  cmp TMP1, TMP0\n    |  bhi >7\n    |6:\n    |  ldr TMP0, [RC], #8\n    |  str TMP0, [RA], #8\n    |  cmp RC, TMP3\n    |  blo <6\n    |  b <2\n    |\n    |7:  // Grow stack for varargs.\n    |  lsr CARG2, TMP2, #3\n    |   stp BASE, RA, L->base\n    |  mov CARG1, L\n    |  sub RC, RC, BASE\t\t\t// Need delta, because BASE may change.\n    |   str PC, SAVE_PC\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  ldp BASE, RA, L->base\n    |  add RC, BASE, RC\n    |  sub TMP3, BASE, #16\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results, RC = extra results\n    |  ldr TMP0w, SAVE_MULTRES\n    |   ldr PC, [BASE, FRAME_PC]\n    |    add RA, BASE, RA, lsl #3\n    |  add RC, TMP0, RC, lsl #3\n    |  b ->BC_RETM_Z\n    break;\n\n  case BC_RET:\n    |  // RA = results, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |    add RA, BASE, RA, lsl #3\n    |->BC_RETM_Z:\n    |   str RCw, SAVE_MULTRES\n    |1:\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV2_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return\n    |  ldr INSw, [PC, #-4]\n    |  subs TMP1, RC, #8\n    |   sub CARG3, BASE, #16\n    |  beq >3\n    |2:\n    |  ldr TMP0, [RA], #8\n    |   add BASE, BASE, #8\n    |   sub TMP1, TMP1, #8\n    |  str TMP0, [BASE, #-24]\n    |   cbnz TMP1, <2\n    |3:\n    |  decode_RA RA, INS\n    |  sub CARG4, CARG3, RA, lsl #3\n    |   decode_RB RB, INS\n    |  ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]\n    |5:\n    |  cmp RC, RB, lsl #3\t\t// More results expected?\n    |  blo >6\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  mov BASE, CARG4\n    |  ldr CARG2, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |   ins_next\n    |\n    |6:  // Fill up results with nil.\n    |  add BASE, BASE, #8\n    |   add RC, RC, #8\n    |  str TISNIL, [BASE, #-24]\n    |  b <5\n    |\n    |->BC_RETV1_Z:  // Non-standard return case.\n    |  add RA, BASE, RA, lsl #3\n    |->BC_RETV2_Z:\n    |  tst CARG2, #FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, CARG2\n    |  ldr PC, [BASE, FRAME_PC]\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results, RC = nresults+1\n    |  ldr PC, [BASE, FRAME_PC]\n    |   lsl RC, RC, #3\n    |   str RCw, SAVE_MULTRES\n    |  ands CARG1, PC, #FRAME_TYPE\n    |   eor CARG2, PC, #FRAME_VARG\n    |  bne ->BC_RETV1_Z\n    |   ldr INSw, [PC, #-4]\n    if (op == BC_RET1) {\n      |  ldr TMP0, [BASE, RA, lsl #3]\n    }\n    |  sub CARG4, BASE, #16\n    |   decode_RA RA, INS\n    |  sub BASE, CARG4, RA, lsl #3\n    if (op == BC_RET1) {\n      |  str TMP0, [CARG4], #8\n    }\n    |   decode_RB RB, INS\n    |  ldr LFUNC:CARG1, [BASE, FRAME_FUNC]\n    |5:\n    |  cmp RC, RB, lsl #3\n    |  blo >6\n    |  and LFUNC:CARG1, CARG1, #LJ_GCVMASK\n    |  ldr CARG2, LFUNC:CARG1->pc\n    |  ldr KBASE, [CARG2, #PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    |  add RC, RC, #8\n    |  str TISNIL, [CARG4], #8\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];      .define FOR_TIDX,  [RA, #4]\n  |.define FOR_STOP, [RA, #8];  .define FOR_TSTOP, [RA, #12]\n  |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]\n  |.define FOR_EXT,  [RA, #24]; .define FOR_TEXT,  [RA, #28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base, RC = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  add RA, BASE, RA, lsl #3\n    |  ldp CARG1, CARG2, FOR_IDX\t\t// CARG1 = IDX, CARG2 = STOP\n    |   ldr CARG3, FOR_STEP\t\t\t// CARG3 = STEP\n    if (op != BC_JFORL) {\n      |   add RC, PC, RC, lsl #2\n      |   sub RC, RC, #0x20000\n    }\n    |  checkint CARG1, >5\n    if (!vk) {\n      |  checkint CARG2, ->vmeta_for\n      |   checkint CARG3, ->vmeta_for\n      |  tbnz CARG3w, #31, >4\n      |  cmp CARG1w, CARG2w\n    } else {\n      |  adds CARG1w, CARG1w, CARG3w\n      |  bvs >2\n      |   add TMP0, CARG1, TISNUM\n      |  tbnz CARG3w, #31, >4\n      |  cmp CARG1w, CARG2w\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  csel PC, RC, PC, gt\n    } else if (op == BC_JFORI) {\n      |  mov PC, RC\n      |  ldrh RCw, [RC, #-4+OFS_RD]\n    } else if (op == BC_IFORL) {\n      |  csel PC, RC, PC, le\n    }\n    if (vk) {\n      |   str TMP0, FOR_IDX\n      |   str TMP0, FOR_EXT\n    } else {\n      |  str CARG1, FOR_EXT\n    }\n    if (op == BC_JFORI || op == BC_JFORL) {\n      |  ble =>BC_JLOOP\n    }\n    |2:\n    |   ins_next\n    |\n    |4:  // Invert check for negative step.\n    |  cmp CARG2w, CARG1w\n    |  b <1\n    |\n    |5:  // FP loop.\n    |  ldp d0, d1, FOR_IDX\n    |  blo ->vmeta_for\n    if (!vk) {\n      |  checknum CARG2, ->vmeta_for\n      |   checknum CARG3, ->vmeta_for\n      |  str d0, FOR_EXT\n    } else {\n      |  ldr d2, FOR_STEP\n      |  fadd d0, d0, d2\n    }\n    |  tbnz CARG3, #63, >7\n    |  fcmp d0, d1\n    |6:\n    if (vk) {\n      |  str d0, FOR_IDX\n      |  str d0, FOR_EXT\n    }\n    if (op == BC_FORI) {\n      |  csel PC, RC, PC, hi\n    } else if (op == BC_JFORI) {\n      |  ldrh RCw, [RC, #-4+OFS_RD]\n      |  bls =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  csel PC, RC, PC, ls\n    } else {\n      |  bls =>BC_JLOOP\n    }\n    |  b <2\n    |\n    |7:  // Invert check for negative step.\n    |  fcmp d1, d0\n    |  b <6\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base, RC = target\n    |  ldr CARG1, [BASE, RA, lsl #3]\n    |   add TMP1, BASE, RA, lsl #3\n    |  cmp CARG1, TISNIL\n    |  beq >1\t\t\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  str CARG1, [TMP1, #-8]\n      |  b =>BC_JLOOP\n    } else {\n      |  add TMP0, PC, RC, lsl #2\t// Otherwise save control var + branch.\n      |  sub PC, TMP0, #0x20000\n      |  str CARG1, [TMP1, #-8]\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base, RC = target (loop extent)\n    |  // Note: RA/RC is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base, RC = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base (ignored), RC = traceno\n    |  ldr CARG1, [GL, #GL_J(trace)]\n    |   mov CARG2w, #0  // Traces on ARM64 don't store the trace #, so use 0.\n    |  ldr TRACE:RC, [CARG1, RC, lsl #3]\n    |   st_vmstate CARG2w\n    |  ldr RA, TRACE:RC->mcode\n    |   str BASE, GL->jit_base\n    |   str L, GL->tmpbuf.L\n    |  sub sp, sp, #16\t// See SPS_FIXED. Avoids sp adjust in every root trace.\n    |  br RA\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base (only used by trace recorder), RC = target\n    |  add RC, PC, RC, lsl #2\n    |  sub PC, RC, #0x20000\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   ldrb TMP1w, [PC, #-4+PC2PROTO(numparams)]\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |  bhi ->vm_growstack_l\n    |2:\n    |  cmp NARGS8:RC, TMP1, lsl #3\t// Check for missing parameters.\n    |  blo >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD RC, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  str TISNIL, [BASE, NARGS8:RC]\n    |  add NARGS8:RC, NARGS8:RC, #8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8\n    |  ldr CARG1, L->maxstack\n    |   movn TMP0, #~LJ_TFUNC\n    |   add TMP2, BASE, RC\n    |   add LFUNC:CARG3, CARG3, TMP0, lsl #47\n    |  add RA, RA, RC\n    |   add TMP0, RC, #16+FRAME_VARG\n    |   str LFUNC:CARG3, [TMP2], #8\t// Store (tagged) copy of LFUNC.\n    |    ldr KBASE, [PC, #-4+PC2PROTO(k)]\n    |  cmp RA, CARG1\n    |   str TMP0, [TMP2], #8\t\t// Store delta + FRAME_VARG.\n    |  bhs ->vm_growstack_l\n    |   sub RC, TMP2, #16\n    |  ldrb TMP1w, [PC, #-4+PC2PROTO(numparams)]\n    |   mov RA, BASE\n    |   mov BASE, TMP2\n    |  cbz TMP1, >2\n    |1:\n    |  cmp RA, RC\t\t\t// Less args than parameters?\n    |  bhs >3\n    |   ldr TMP0, [RA]\n    |  sub TMP1, TMP1, #1\n    |    str TISNIL, [RA], #8\t\t// Clear old fixarg slot (help the GC).\n    |   str TMP0, [TMP2], #8\n    |  cbnz TMP1, <1\n    |2:\n    |  ins_next\n    |\n    |3:\n    |  sub TMP1, TMP1, #1\n    |   str TISNIL, [TMP2], #8\n    |  cbz TMP1, <2\n    |  b <3\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  ldr CARG4, CFUNC:CARG3->f\n    } else {\n      |  ldr CARG4, GL->wrapf\n    }\n    |   add CARG2, RA, NARGS8:RC\n    |   ldr CARG1, L->maxstack\n    |  add RC, BASE, NARGS8:RC\n    |   cmp CARG2, CARG1\n    |  stp BASE, RC, L->base\n    if (op == BC_FUNCCW) {\n      |  ldr CARG2, CFUNC:CARG3->f\n    }\n    |    mv_vmstate TMP0w, C\n    |  mov CARG1, L\n    |   bhi ->vm_growstack_c\t\t// Need to grow stack.\n    |    st_vmstate TMP0w\n    |  blr CARG4\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  ldp BASE, TMP1, L->base\n    |    str L, GL->cur_L\n    |   sbfiz RC, CRET1, #3, #32\n    |    st_vmstate ST_INTERP\n    |  ldr PC, [BASE, FRAME_PC]\n    |   sub RA, TMP1, RC\t\t// RA = L->top - nresults*8\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 16\\n\"\t/* def_cfa fp 16 */\n\t\"\\t.align 3\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\",\t\t/* offset fp */\n\tfcofs);\n    for (i = 19; i <= 28; i++)  /* offset x19-x28 */\n      fprintf(ctx->fp, \"\\t.byte 0x%x\\n\\t.uleb128 %d\\n\", 0x80+i, i+(3-19));\n    for (i = 8; i <= 15; i++)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 0x%x\\n\\t.uleb128 %d\\n\",\n\t      64+i, i+(3+(28-19+1)-8));\n    fprintf(ctx->fp,\n\t\"\\t.align 3\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x93\\n\\t.uleb128 3\\n\"\t\t/* offset x19 */\n\t\"\\t.byte 0x94\\n\\t.uleb128 4\\n\"\t\t/* offset x20 */\n\t\"\\t.align 3\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",%%progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 16\\n\"\t/* def_cfa fp 16 */\n\t\"\\t.align 3\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\",\t\t/* offset fp */\n\tfcofs);\n    for (i = 19; i <= 28; i++)  /* offset x19-x28 */\n      fprintf(ctx->fp, \"\\t.byte 0x%x\\n\\t.uleb128 %d\\n\", 0x80+i, i+(3-19));\n    for (i = 8; i <= 15; i++)  /* offset d8-d15 */\n      fprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 0x%x\\n\\t.uleb128 %d\\n\",\n\t      64+i, i+(3+(28-19+1)-8));\n    fprintf(ctx->fp,\n\t\"\\t.align 3\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 16\\n\"\t/* def_cfa fp 16 */\n\t\"\\t.align 3\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x93\\n\\t.uleb128 3\\n\"\t\t/* offset x19 */\n\t\"\\t.byte 0x94\\n\\t.uleb128 4\\n\"\t\t/* offset x20 */\n\t\"\\t.align 3\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n    break;\n#if !LJ_NO_UNWIND\n  case BUILD_machasm: {\n#if LJ_HASFFI\n    int fcsize = 0;\n#endif\n    int j;\n    fprintf(ctx->fp, \"\\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\\n\");\n    fprintf(ctx->fp,\n\t\"EH_frame1:\\n\"\n\t\"\\t.set L$set$x,LECIEX-LSCIEX\\n\"\n\t\"\\t.long L$set$x\\n\"\n\t\"LSCIEX:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zPR\\\\0\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9b\\n\"\t\t\t/* indirect|pcrel|sdata4 */\n\t\"\\t.long _lj_err_unwind_dwarf@GOT-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 16\\n\"\t/* def_cfa fp 16 */\n\t\"\\t.align 3\\n\"\n\t\"LECIEX:\\n\\n\");\n    for (j = 0; j < ctx->nsym; j++) {\n      const char *name = ctx->sym[j].name;\n      int32_t size = ctx->sym[j+1].ofs - ctx->sym[j].ofs;\n      if (size == 0) continue;\n#if LJ_HASFFI\n      if (!strcmp(name, \"_lj_vm_ffi_call\")) { fcsize = size; continue; }\n#endif\n      fprintf(ctx->fp,\n\t\"LSFDE%d:\\n\"\n\t\"\\t.set L$set$%d,LEFDE%d-LASFDE%d\\n\"\n\t\"\\t.long L$set$%d\\n\"\n\t\"LASFDE%d:\\n\"\n\t\"\\t.long LASFDE%d-EH_frame1\\n\"\n\t\"\\t.long %s-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\",\t\t/* offset fp */\n\tj, j, j, j, j, j, j, name, size);\n      for (i = 19; i <= 28; i++)  /* offset x19-x28 */\n\tfprintf(ctx->fp, \"\\t.byte 0x%x\\n\\t.uleb128 %d\\n\", 0x80+i, i+(3-19));\n      for (i = 8; i <= 15; i++)  /* offset d8-d15 */\n\tfprintf(ctx->fp, \"\\t.byte 5\\n\\t.uleb128 0x%x\\n\\t.uleb128 %d\\n\",\n\t\t64+i, i+(3+(28-19+1)-8));\n      fprintf(ctx->fp,\n\t\"\\t.align 3\\n\"\n\t\"LEFDE%d:\\n\\n\", j);\n    }\n#if LJ_HASFFI\n    if (fcsize) {\n      fprintf(ctx->fp,\n\t\"EH_frame2:\\n\"\n\t\"\\t.set L$set$y,LECIEY-LSCIEY\\n\"\n\t\"\\t.long L$set$y\\n\"\n\t\"LSCIEY:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zR\\\\0\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 30\\n\"\t\t\t\t/* Return address is in lr. */\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 16\\n\"\t/* def_cfa fp 16 */\n\t\"\\t.align 3\\n\"\n\t\"LECIEY:\\n\\n\");\n      fprintf(ctx->fp,\n\t\"LSFDEY:\\n\"\n\t\"\\t.set L$set$yy,LEFDEY-LASFDEY\\n\"\n\t\"\\t.long L$set$yy\\n\"\n\t\"LASFDEY:\\n\"\n\t\"\\t.long LASFDEY-EH_frame2\\n\"\n\t\"\\t.long _lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9e\\n\\t.uleb128 1\\n\"\t\t/* offset lr */\n\t\"\\t.byte 0x9d\\n\\t.uleb128 2\\n\"\t\t/* offset fp */\n\t\"\\t.byte 0x93\\n\\t.uleb128 3\\n\"\t\t/* offset x19 */\n\t\"\\t.byte 0x94\\n\\t.uleb128 4\\n\"\t\t/* offset x20 */\n\t\"\\t.align 3\\n\"\n\t\"LEFDEY:\\n\\n\", fcsize);\n    }\n#endif\n    fprintf(ctx->fp, \".subsections_via_symbols\\n\");\n    }\n    break;\n#endif\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_mips.dasc",
    "content": "|// Low-level VM code for MIPS CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|//\n|// MIPS soft-float support contributed by Djordje Kovacevic and\n|// Stefan Pejic from RT-RK.com, sponsored by Cisco Systems, Inc.\n|\n|.arch mips\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra\n|\n|.macro .FPU, a, b\n|.if FPU\n|  a, b\n|.endif\n|.endmacro\n|\n|// The following must be C callee-save (but BASE is often refetched).\n|.define BASE,\t\tr16\t// Base of current Lua stack frame.\n|.define KBASE,\t\tr17\t// Constants of current Lua function.\n|.define PC,\t\tr18\t// Next PC.\n|.define DISPATCH,\tr19\t// Opcode dispatch table.\n|.define LREG,\t\tr20\t// Register holding lua_State (also in SAVE_L).\n|.define MULTRES,\tr21\t// Size of multi-result: (nresults+1)*8.\n|\n|.define JGL,\t\tr30\t// On-trace: global_State + 32768.\n|\n|// Constants for type-comparisons, stores and conversions. C callee-save.\n|.define TISNUM,\tr22\n|.define TISNIL,\tr30\n|.if FPU\n|.define TOBIT,\t\tf30\t// 2^52 + 2^51.\n|.endif\n|\n|// The following temporaries are not saved across C calls, except for RA.\n|.define RA,\t\tr23\t// Callee-save.\n|.define RB,\t\tr8\n|.define RC,\t\tr9\n|.define RD,\t\tr10\n|.define INS,\t\tr11\n|\n|.define AT,\t\tr1\t// Assembler temporary.\n|.define TMP0,\t\tr12\n|.define TMP1,\t\tr13\n|.define TMP2,\t\tr14\n|.define TMP3,\t\tr15\n|\n|// MIPS o32 calling convention.\n|.define CFUNCADDR,\tr25\n|.define CARG1,\t\tr4\n|.define CARG2,\t\tr5\n|.define CARG3,\t\tr6\n|.define CARG4,\t\tr7\n|\n|.define CRET1,\t\tr2\n|.define CRET2,\t\tr3\n|\n|.if ENDIAN_LE\n|.define SFRETLO,\tCRET1\n|.define SFRETHI,\tCRET2\n|.define SFARG1LO,\tCARG1\n|.define SFARG1HI,\tCARG2\n|.define SFARG2LO,\tCARG3\n|.define SFARG2HI,\tCARG4\n|.else\n|.define SFRETLO,\tCRET2\n|.define SFRETHI,\tCRET1\n|.define SFARG1LO,\tCARG2\n|.define SFARG1HI,\tCARG1\n|.define SFARG2LO,\tCARG4\n|.define SFARG2HI,\tCARG3\n|.endif\n|\n|.if FPU\n|.define FARG1,\t\tf12\n|.define FARG2,\t\tf14\n|\n|.define FRET1,\t\tf0\n|.define FRET2,\t\tf2\n|.endif\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.if FPU\t\t// MIPS32 hard-float.\n|\n|.define CFRAME_SPACE,\t112\t// Delta for sp.\n|\n|.define SAVE_ERRF,\t124(sp)\t// 32 bit C frame info.\n|.define SAVE_NRES,\t120(sp)\n|.define SAVE_CFRAME,\t116(sp)\n|.define SAVE_L,\t112(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.\n|.define SAVE_GPR_,\t72\t// .. 72+10*4: 32 bit GPR saves.\n|.define SAVE_FPR_,\t24\t// .. 24+6*8: 64 bit FPR saves.\n|\n|.else\t\t\t// MIPS32 soft-float\n|\n|.define CFRAME_SPACE,\t64\t// Delta for sp.\n|\n|.define SAVE_ERRF,\t76(sp)\t// 32 bit C frame info.\n|.define SAVE_NRES,\t72(sp)\n|.define SAVE_CFRAME,\t68(sp)\n|.define SAVE_L,\t64(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.\n|.define SAVE_GPR_,\t24\t// .. 24+10*4: 32 bit GPR saves.\n|\n|.endif\n|\n|.define SAVE_PC,\t20(sp)\n|.define ARG5,\t\t16(sp)\n|.define CSAVE_4,\t12(sp)\n|.define CSAVE_3,\t8(sp)\n|.define CSAVE_2,\t4(sp)\n|.define CSAVE_1,\t0(sp)\n|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee.\n|\n|.define ARG5_OFS,\t16\n|.define SAVE_MULTRES,\tARG5\n|\n|//-----------------------------------------------------------------------\n|\n|.macro saveregs\n|  addiu sp, sp, -CFRAME_SPACE\n|  sw ra, SAVE_GPR_+9*4(sp)\n|  sw r30, SAVE_GPR_+8*4(sp)\n|   .FPU sdc1 f30, SAVE_FPR_+5*8(sp)\n|  sw r23, SAVE_GPR_+7*4(sp)\n|  sw r22, SAVE_GPR_+6*4(sp)\n|   .FPU sdc1 f28, SAVE_FPR_+4*8(sp)\n|  sw r21, SAVE_GPR_+5*4(sp)\n|  sw r20, SAVE_GPR_+4*4(sp)\n|   .FPU sdc1 f26, SAVE_FPR_+3*8(sp)\n|  sw r19, SAVE_GPR_+3*4(sp)\n|  sw r18, SAVE_GPR_+2*4(sp)\n|   .FPU sdc1 f24, SAVE_FPR_+2*8(sp)\n|  sw r17, SAVE_GPR_+1*4(sp)\n|  sw r16, SAVE_GPR_+0*4(sp)\n|   .FPU sdc1 f22, SAVE_FPR_+1*8(sp)\n|   .FPU sdc1 f20, SAVE_FPR_+0*8(sp)\n|.endmacro\n|\n|.macro restoreregs_ret\n|  lw ra, SAVE_GPR_+9*4(sp)\n|  lw r30, SAVE_GPR_+8*4(sp)\n|   .FPU ldc1 f30, SAVE_FPR_+5*8(sp)\n|  lw r23, SAVE_GPR_+7*4(sp)\n|  lw r22, SAVE_GPR_+6*4(sp)\n|   .FPU ldc1 f28, SAVE_FPR_+4*8(sp)\n|  lw r21, SAVE_GPR_+5*4(sp)\n|  lw r20, SAVE_GPR_+4*4(sp)\n|   .FPU ldc1 f26, SAVE_FPR_+3*8(sp)\n|  lw r19, SAVE_GPR_+3*4(sp)\n|  lw r18, SAVE_GPR_+2*4(sp)\n|   .FPU ldc1 f24, SAVE_FPR_+2*8(sp)\n|  lw r17, SAVE_GPR_+1*4(sp)\n|  lw r16, SAVE_GPR_+0*4(sp)\n|   .FPU ldc1 f22, SAVE_FPR_+1*8(sp)\n|   .FPU ldc1 f20, SAVE_FPR_+0*8(sp)\n|  jr ra\n|  addiu sp, sp, CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; .long 0xec1cf0f0; .endmacro\n|\n|// Macros to mark delay slots.\n|.macro ., a; a; .endmacro\n|.macro ., a,b; a,b; .endmacro\n|.macro ., a,b,c; a,b,c; .endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Endian-specific defines.\n|.if ENDIAN_LE\n|.define FRAME_PC,\t-4\n|.define FRAME_FUNC,\t-8\n|.define HI,\t\t4\n|.define LO,\t\t0\n|.define OFS_RD,\t2\n|.define OFS_RA,\t1\n|.define OFS_OP,\t0\n|.else\n|.define FRAME_PC,\t-8\n|.define FRAME_FUNC,\t-4\n|.define HI,\t\t0\n|.define LO,\t\t4\n|.define OFS_RD,\t0\n|.define OFS_RA,\t2\n|.define OFS_OP,\t3\n|.endif\n|\n|// Instruction decode.\n|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro\n|.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro\n|.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro\n|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro\n|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro\n|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro\n|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro\n|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro\n|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  lw INS, 0(PC)\n|   addiu PC, PC, 4\n|.endmacro\n|// Instruction decode+dispatch.\n|.macro ins_NEXT2\n|  decode_OP4a TMP1, INS\n|  decode_OP4b TMP1\n|  addu TMP0, DISPATCH, TMP1\n|   decode_RD8a RD, INS\n|  lw AT, 0(TMP0)\n|   decode_RA8a RA, INS\n|   decode_RD8b RD\n|  jr AT\n|   decode_RA8b RA\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  lw PC, LFUNC:RB->pc\n|  lw INS, 0(PC)\n|   addiu PC, PC, 4\n|  decode_OP4a TMP1, INS\n|   decode_RA8a RA, INS\n|  decode_OP4b TMP1\n|   decode_RA8b RA\n|  addu TMP0, DISPATCH, TMP1\n|  lw TMP0, 0(TMP0)\n|  jr TMP0\n|   addu RA, RA, BASE\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  sw PC, FRAME_PC(BASE)\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|.macro branch_RD\n|  srl TMP0, RD, 1\n|  lui AT, (-(BCBIAS_J*4 >> 16) & 65535)\n|  addu TMP0, TMP0, AT\n|  addu PC, PC, TMP0\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n#define GG_DISP2GOT\t\t(GG_OFS(got) - GG_OFS(dispatch))\n#define DISPATCH_GOT(name)\t(GG_DISP2GOT + 4*LJ_GOT_##name)\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro load_got, func\n|  lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)\n|.endmacro\n|// Much faster. Sadly, there's no easy way to force the required code layout.\n|// .macro call_intern, func; bal extern func; .endmacro\n|.macro call_intern, func; jalr CFUNCADDR; .endmacro\n|.macro call_extern; jalr CFUNCADDR; .endmacro\n|.macro jmp_extern; jr CFUNCADDR; .endmacro\n|\n|.macro hotcheck, delta, target\n|  srl TMP1, PC, 1\n|  andi TMP1, TMP1, 126\n|  addu TMP1, TMP1, DISPATCH\n|  lhu TMP2, GG_DISP2HOT(TMP1)\n|  addiu TMP2, TMP2, -delta\n|  bltz TMP2, target\n|.  sh TMP2, GG_DISP2HOT(TMP1)\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL, ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state. Uses TMP0.\n|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro\n|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp, target\n|  lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   andi mark, mark, ~LJ_GC_BLACK & 255\t\t// black2gray(tab)\n|  sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   sb mark, tab->marked\n|  b target\n|.  sw tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: TMP2 = previous base.\n  |  andi AT, PC, FRAME_P\n  |  beqz AT, ->cont_dispatch\n  |.  li TMP1, LJ_TTRUE\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  lw PC, FRAME_PC(TMP2)\t\t// Fetch PC of previous frame.\n  |  move BASE, TMP2\t\t\t// Restore caller base.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   sw TMP1, FRAME_PC(RA)\t\t// Prepend true to results.\n  |   addiu RA, RA, -8\n  |\n  |->vm_returnc:\n  |   addiu RD, RD, 8\t\t\t// RD = (nresults+1)*8.\n  |  andi TMP0, PC, FRAME_TYPE\n  |   beqz RD, ->vm_unwind_c_eh\n  |.   li CRET1, LUA_YIELD\n  |  beqz TMP0, ->BC_RET_Z\t\t// Handle regular return to Lua.\n  |.  move MULTRES, RD\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return\n  |  // TMP0 = PC & FRAME_TYPE\n  |   li TMP2, -8\n  |  xori AT, TMP0, FRAME_C\n  |   and TMP2, PC, TMP2\n  |  bnez AT, ->vm_returnp\n  |.  subu TMP2, BASE, TMP2\t\t// TMP2 = previous base.\n  |\n  |  addiu TMP1, RD, -8\n  |   sw TMP2, L->base\n  |    li_vmstate C\n  |   lw TMP2, SAVE_NRES\n  |   addiu BASE, BASE, -8\n  |    st_vmstate\n  |  beqz TMP1, >2\n  |.   sll TMP2, TMP2, 3\n  |1:\n  |  addiu TMP1, TMP1, -8\n  |   lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |    addiu RA, RA, 8\n  |   sw SFRETHI, HI(BASE)\n  |    sw SFRETLO, LO(BASE)\n  |  bnez TMP1, <1\n  |.  addiu BASE, BASE, 8\n  |\n  |2:\n  |  bne TMP2, RD, >6\n  |3:\n  |.  sw BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  lw TMP0, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   move CRET1, r0\t\t\t// Ok return status for vm_pcall.\n  |  sw TMP0, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs_ret\n  |\n  |6:\n  |  lw TMP1, L->maxstack\n  |  slt AT, TMP2, RD\n  |  bnez AT, >7\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |.  slt AT, BASE, TMP1\n  |  beqz AT, >8\n  |.  nop\n  |  sw TISNIL, HI(BASE)\n  |  addiu RD, RD, 8\n  |  b <2\n  |.  addiu BASE, BASE, 8\n  |\n  |7:  // Less results wanted.\n  |  subu TMP0, RD, TMP2\n  |  subu TMP0, BASE, TMP0\t\t// Either keep top or shrink it.\n  |  b <3\n  |.  movn BASE, TMP0, TMP2\t\t// LUA_MULTRET+1 case?\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  load_got lj_state_growstack\n  |   move MULTRES, RD\n  |  srl CARG2, TMP2, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |    lw TMP2, SAVE_NRES\n  |  lw BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |   move RD, MULTRES\n  |  b <2\n  |.   sll TMP2, TMP2, 3\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  move sp, CARG1\n  |  move CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  lw L, SAVE_L\n  |   li TMP0, ~LJ_VMST_C\n  |  lw GL:TMP1, L->glref\n  |  b ->vm_leave_unw\n  |.  sw TMP0, GL:TMP1->vmstate\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  li AT, -4\n  |  and sp, CARG1, AT\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  lw L, SAVE_L\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |     li TISNIL, LJ_TNIL\n  |  lw BASE, L->base\n  |   lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     .FPU mtc1 TMP3, TOBIT\n  |  li TMP1, LJ_TFALSE\n  |    li_vmstate INTERP\n  |  lw PC, FRAME_PC(BASE)\t\t// Fetch PC of previous frame.\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  addiu RA, BASE, -8\t\t\t// Results start at BASE-8.\n  |   addiu DISPATCH, DISPATCH, GG_G2DISP\n  |  sw TMP1, HI(RA)\t\t\t// Prepend false to error message.\n  |    st_vmstate\n  |  b ->vm_returnc\n  |.  li RD, 16\t\t\t\t// 2 results: false + error message.\n  |\n  |->vm_unwind_stub:\t\t\t// Jump to exit stub from unwinder.\n  |  jr CARG1\n  |.  move ra, CARG2\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  b >2\n  |.  li CARG2, LUA_MINSTACK\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  addu RC, BASE, RC\n  |   subu RA, RA, BASE\n  |  sw BASE, L->base\n  |   addiu PC, PC, 4\t\t\t// Must point after first instruction.\n  |  sw RC, L->top\n  |   srl CARG2, RA, 3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  load_got lj_state_growstack\n  |   sw PC, SAVE_PC\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  lw BASE, L->base\n  |  lw RC, L->top\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  subu RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  move L, CARG1\n  |    lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  move BASE, CARG2\n  |    lbu TMP1, L->status\n  |   sw L, SAVE_L\n  |  li PC, FRAME_CP\n  |  addiu TMP0, sp, CFRAME_RESUME\n  |    addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw r0, SAVE_NRES\n  |   sw r0, SAVE_ERRF\n  |   sw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |   sw r0, SAVE_CFRAME\n  |    beqz TMP1, >3\n  |. sw TMP0, L->cframe\n  |\n  |  // Resume after yield (like a return).\n  |  sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  move RA, BASE\n  |   lw BASE, L->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lw TMP1, L->top\n  |  lw PC, FRAME_PC(BASE)\n  |     .FPU  lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   subu RD, TMP1, BASE\n  |     .FPU  mtc1 TMP3, TOBIT\n  |    sb r0, L->status\n  |     .FPU  cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |   addiu RD, RD, 8\n  |    st_vmstate\n  |   move MULTRES, RD\n  |  andi TMP0, PC, FRAME_TYPE\n  |  beqz TMP0, ->BC_RET_Z\n  |.    li TISNIL, LJ_TNIL\n  |  b ->vm_return\n  |.  nop\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  sw CARG4, SAVE_ERRF\n  |  b >1\n  |.  li PC, FRAME_CP\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  li PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  lw TMP1, L:CARG1->cframe\n  |    move L, CARG1\n  |   sw CARG3, SAVE_NRES\n  |    lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   sw CARG1, SAVE_L\n  |     move BASE, CARG2\n  |    addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  sw TMP1, SAVE_CFRAME\n  |  sw sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  lw TMP2, L->base\t\t\t// TMP2 = old base (used in vmeta_call).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   lw TMP1, L->top\n  |     .FPU mtc1 TMP3, TOBIT\n  |  addu PC, PC, BASE\n  |   subu NARGS8:RC, TMP1, BASE\n  |  subu PC, PC, TMP2\t\t\t// PC = frame delta + frame type\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |     li TISNIL, LJ_TNIL\n  |    st_vmstate\n  |\n  |->vm_call_dispatch:\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  lw TMP0, FRAME_PC(BASE)\n  |  li AT, LJ_TFUNC\n  |  bne TMP0, AT, ->vmeta_call\n  |.  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  move L, CARG1\n  |   lw TMP0, L:CARG1->stack\n  |  sw CARG1, SAVE_L\n  |   lw TMP1, L->top\n  |     lw DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  sw CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   subu TMP0, TMP0, TMP1\t\t// Compute -savestack(L, L->top).\n  |    lw TMP1, L->cframe\n  |     addiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw TMP0, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  sw r0, SAVE_ERRF\t\t\t// No error function.\n  |    sw TMP1, SAVE_CFRAME\n  |    sw sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |     sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  jalr CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.  move CFUNCADDR, CARG4\n  |  move BASE, CRET1\n  |  bnez CRET1, <3\t\t\t// Else continue with the call.\n  |.  li PC, FRAME_CP\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |.  nop\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the\n  |// stack, so BASE doesn't need to be reloaded across these calls.\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8\n  |  lw TMP0, -16+LO(BASE)\t\t// Continuation.\n  |   move RB, BASE\n  |   move BASE, TMP2\t\t\t// Restore caller BASE.\n  |    lw LFUNC:TMP1, FRAME_FUNC(TMP2)\n  |.if FFI\n  |  sltiu AT, TMP0, 2\n  |.endif\n  |     lw PC, -16+HI(RB)\t\t// Restore PC from [cont|PC].\n  |   addu TMP2, RA, RD\n  |.if FFI\n  |  bnez AT, >1\n  |.endif\n  |.  sw TISNIL, -8+HI(TMP2)\t\t// Ensure one valid arg.\n  |    lw TMP1, LFUNC:TMP1->pc\n  |  // BASE = base, RA = resultptr, RB = meta base\n  |  jr TMP0\t\t\t\t// Jump to continuation.\n  |.  lw KBASE, PC2PROTO(k)(TMP1)\n  |\n  |.if FFI\n  |1:\n  |  bnez TMP0, ->cont_ffi_callback\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |.  addiu TMP1, RB, -16\n  |  b ->vm_call_tail\n  |.  subu RC, TMP1, BASE\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |   addiu CARG2, RB, -16\n  |  lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |  decode_RB8a MULTRES, INS\n  |   decode_RA8a RA, INS\n  |  decode_RB8b MULTRES\n  |   decode_RA8b RA\n  |  addu TMP1, BASE, MULTRES\n  |   sw BASE, L->base\n  |   subu CARG3, CARG2, TMP1\n  |  sw SFRETHI, HI(CARG2)\n  |  bne TMP1, CARG2, ->BC_CAT_Z\n  |.  sw SFRETLO, LO(CARG2)\n  |  addu RA, BASE, RA\n  |  sw SFRETHI, HI(RA)\n  |  b ->cont_nop\n  |.  sw SFRETLO, LO(RA)\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP0, HI(CARG3)\n  |\n  |->vmeta_tgets:\n  |  addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |  sw TAB:RB, LO(CARG2)\n  |   addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sw TMP0, HI(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP1, HI(CARG3)\n  |\n  |->vmeta_tgetb:\t\t\t// TMP0 = index\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  sw TMP0, LO(CARG3)\n  |  sw TISNUM, HI(CARG3)\n  |\n  |->vmeta_tgetv:\n  |1:\n  |  load_got lj_meta_tget\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  beqz CRET1, >3\n  |.  addiu TMP1, BASE, -FRAME_CONT\n  |  lw SFARG1HI, HI(CRET1)\n  |   lw SFARG2HI, LO(CRET1)\n  |  ins_next1\n  |  sw SFARG1HI, HI(RA)\n  |   sw SFARG2HI, LO(RA)\n  |  ins_next2\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  lw BASE, L->top\n  |  sw PC, -16+HI(BASE)\t\t// [cont|PC]\n  |   subu PC, BASE, TMP1\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(t, k).\n  |\n  |->vmeta_tgetr:\n  |  load_got lj_tab_getinth\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  nop\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->BC_TGETR_Z\n  |.  move SFARG2HI, TISNIL\n  |  lw SFARG2HI, HI(CRET1)\n  |  b ->BC_TGETR_Z\n  |.  lw SFARG2LO, LO(CRET1)\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP0, HI(CARG3)\n  |\n  |->vmeta_tsets:\n  |  addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |  sw TAB:RB, LO(CARG2)\n  |   addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sw TMP0, HI(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   sw STR:RC, LO(CARG3)\n  |  b >1\n  |.  sw TMP1, HI(CARG3)\n  |\n  |->vmeta_tsetb:\t\t\t// TMP0 = index\n  |  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  sw TMP0, LO(CARG3)\n  |  sw TISNUM, HI(CARG3)\n  |\n  |->vmeta_tsetv:\n  |1:\n  |  load_got lj_meta_tset\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  lw SFARG1HI, HI(RA)\n  |  beqz CRET1, >3\n  |.  lw SFARG1LO, LO(RA)\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  ins_next1\n  |  sw SFARG1HI, HI(CRET1)\n  |   sw SFARG1LO, LO(CRET1)\n  |  ins_next2\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  addiu TMP1, BASE, -FRAME_CONT\n  |  lw BASE, L->top\n  |  sw PC, -16+HI(BASE)\t\t// [cont|PC]\n  |   subu PC, BASE, TMP1\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  sw SFARG1HI, 16+HI(BASE)\t\t// Copy value to third argument.\n  |   sw SFARG1LO, 16+LO(BASE)\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 24\t\t\t// 3 args for func(t, k, v)\n  |\n  |->vmeta_tsetr:\n  |  load_got lj_tab_setinth\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  call_intern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |.  move CARG1, L\n  |  // Returns TValue *.\n  |  b ->BC_TSETR_Z\n  |.  nop\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  // RA/RD point to o1/o2.\n  |  move CARG2, RA\n  |  move CARG3, RD\n  |  load_got lj_meta_comp\n  |  addiu PC, PC, -4\n  |  sw BASE, L->base\n  |  sw PC, SAVE_PC\n  |  decode_OP1 CARG4, INS\n  |  call_intern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  sltiu AT, CRET1, 2\n  |  beqz AT, ->vmeta_binop\n  |   negu TMP2, CRET1\n  |4:\n  |  lhu RD, OFS_RD(PC)\n  |   addiu PC, PC, 4\n  |   lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)\n  |  sll RD, RD, 2\n  |  addu RD, RD, TMP1\n  |  and RD, RD, TMP2\n  |  addu PC, PC, RD\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  lbu TMP1, -4+OFS_RA(PC)\n  |   lw SFRETHI, HI(RA)\n  |    lw SFRETLO, LO(RA)\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, BASE, TMP1\n  |   sw SFRETHI, HI(TMP1)\n  |  b ->cont_nop\n  |.   sw SFRETLO, LO(TMP1)\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  lw TMP0, HI(RA)\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  negu TMP2, AT\t\t\t// Branch if result is true.\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  lw TMP0, HI(RA)\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  addiu TMP2, AT, -1\t\t// Branch if result is false.\n  |\n  |->vmeta_equal:\n  |  // SFARG1LO/SFARG2LO point to o1/o2. TMP0 is set to 0/1.\n  |  load_got lj_meta_equal\n  |   move CARG2, SFARG1LO\n  |   move CARG3, SFARG2LO\n  |   move CARG4, TMP0\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  load_got lj_meta_equal_cd\n  |  move CARG2, INS\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_equal_cd\t// (lua_State *L, BCIns op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |->vmeta_istype:\n  |  load_got lj_meta_istype\n  |  addiu PC, PC, -4\n  |   sw BASE, L->base\n  |   srl CARG2, RA, 3\n  |   srl CARG3, RD, 3\n  |  sw PC, SAVE_PC\n  |  call_intern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |.  move CARG1, L\n  |  b ->cont_nop\n  |.  nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_unm:\n  |  move RC, RB\n  |\n  |->vmeta_arith:\n  |  load_got lj_meta_arith\n  |  decode_OP1 TMP0, INS\n  |   sw BASE, L->base\n  |  move CARG2, RA\n  |   sw PC, SAVE_PC\n  |  move CARG3, RB\n  |  move CARG4, RC\n  |  sw TMP0, ARG5\n  |  call_intern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |.  move CARG1, L\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  beqz CRET1, ->cont_nop\n  |.  nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  subu TMP1, CRET1, BASE\n  |   sw PC, -16+HI(CRET1)\t\t// [cont|PC]\n  |   move TMP2, BASE\n  |  addiu PC, TMP1, FRAME_CONT\n  |   move BASE, CRET1\n  |  b ->vm_call_dispatch\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(o1, o2).\n  |\n  |->vmeta_len:\n  |  // CARG2 already set by BC_LEN.\n#if LJ_52\n  |  move MULTRES, CARG1\n#endif\n  |  load_got lj_meta_len\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |.  move CARG1, L\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  bnez CRET1, ->vmeta_binop\t\t// Binop call for compatibility.\n  |.  nop\n  |  b ->BC_LEN_Z\n  |.  move CARG1, MULTRES\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |.  nop\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sw TMP2, L->base\t\t\t// This is the callers base!\n  |  addiu CARG2, BASE, -8\n  |   sw PC, SAVE_PC\n  |  addu CARG3, BASE, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   addiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sw BASE, L->base\n  |  addiu CARG2, RA, -8\n  |   sw PC, SAVE_PC\n  |  addu CARG3, RA, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |  lw TMP1, FRAME_PC(BASE)\n  |   lw LFUNC:RB, FRAME_FUNC(RA)\t// Guaranteed to be a function here.\n  |  b ->BC_CALLT_Z\n  |.  addiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  load_got lj_meta_for\n  |   sw BASE, L->base\n  |  move CARG2, RA\n  |   sw PC, SAVE_PC\n  |  move MULTRES, INS\n  |  call_intern lj_meta_for\t// (lua_State *L, TValue *base)\n  |.  move CARG1, L\n  |.if JIT\n  |  decode_OP1 TMP0, MULTRES\n  |  li AT, BC_JFORI\n  |.endif\n  |  decode_RA8a RA, MULTRES\n  |   decode_RD8a RD, MULTRES\n  |  decode_RA8b RA\n  |.if JIT\n  |  beq TMP0, AT, =>BC_JFORI\n  |.  decode_RD8b RD\n  |  b =>BC_FORI\n  |.  nop\n  |.else\n  |  b =>BC_FORI\n  |.  decode_RD8b RD\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw SFARG1LO, LO(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.   lw SFARG2HI, 8+HI(BASE)\n  |   lw SFARG1LO, LO(BASE)\n  |    lw SFARG2LO, 8+LO(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  lw SFARG1HI, HI(BASE)\n  |.if FPU\n  |   ldc1 FARG1, 0(BASE)\n  |.else\n  |   lw SFARG1LO, LO(BASE)\n  |.endif\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  lw SFARG2HI, 8+HI(BASE)\n  |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n  |.if FPU\n  |   ldc1 FARG1, 0(BASE)\n  |.else\n  |   lw SFARG1LO, LO(BASE)\n  |.endif\n  |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n  |.if FPU\n  |   ldc1 FARG2, 8(BASE)\n  |.else\n  |   lw SFARG2LO, 8+LO(BASE)\n  |.endif\n  |  and TMP0, TMP0, TMP1\n  |  beqz TMP0, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!\n  |.macro ffgccheck\n  |  lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n  |  lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n  |  subu AT, TMP0, TMP1\n  |  bgezal AT, ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  sltiu AT, SFARG1HI, LJ_TISTRUECOND\n  |  beqz AT, ->fff_fallback\n  |.  addiu RA, BASE, -8\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RD, NARGS8:RC, 8\t\t// Compute (nresults+1)*8.\n  |  addu TMP2, RA, NARGS8:RC\n  |   sw SFARG1HI, HI(RA)\n  |  addiu TMP1, BASE, 8\n  |  beq BASE, TMP2, ->fff_res\t\t// Done if exactly 1 argument.\n  |.  sw SFARG1LO, LO(RA)\n  |1:\n  |  lw SFRETHI, HI(TMP1)\n  |   lw SFRETLO, LO(TMP1)\n  |  sw SFRETHI, -8+HI(TMP1)\n  |   sw SFRETLO, -8+LO(TMP1)\n  |  bne TMP1, TMP2, <1\n  |.  addiu TMP1, TMP1, 8\n  |  b ->fff_res\n  |.  nop\n  |\n  |.ffunc type\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  sltiu TMP0, SFARG1HI, LJ_TISNUM\n  |  movn SFARG1HI, TISNUM, TMP0\n  |  not TMP1, SFARG1HI\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, CFUNC:RB, TMP1\n  |  lw SFARG1HI, CFUNC:TMP1->upvalue[0].u32.hi\n  |  b ->fff_restv\n  |.  lw SFARG1LO, CFUNC:TMP1->upvalue[0].u32.lo\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, >6\n  |.  li AT, LJ_TUDATA\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  lw TAB:SFARG1LO, TAB:SFARG1LO->metatable\n  |2:\n  |  lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)\n  |  beqz TAB:SFARG1LO, ->fff_restv\n  |.  li SFARG1HI, LJ_TNIL\n  |  lw TMP0, TAB:SFARG1LO->hmask\n  |   li SFARG1HI, LJ_TTAB\t\t// Use metatable as default result.\n  |  lw TMP1, STR:RC->sid\n  |  lw NODE:TMP2, TAB:SFARG1LO->node\n  |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n  |  sll TMP0, TMP1, 5\n  |  sll TMP1, TMP1, 3\n  |  subu TMP1, TMP0, TMP1\n  |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n  |  li AT, LJ_TSTR\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  lw CARG4, offsetof(Node, key)+HI(NODE:TMP2)\n  |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n  |    lw NODE:TMP3, NODE:TMP2->next\n  |  bne CARG4, AT, >4\n  |.    lw CARG3, offsetof(Node, val)+HI(NODE:TMP2)\n  |  beq TMP0, STR:RC, >5\n  |.    lw TMP1, offsetof(Node, val)+LO(NODE:TMP2)\n  |4:\n  |  beqz NODE:TMP3, ->fff_restv\t// Not found, keep default result.\n  |.  move NODE:TMP2, NODE:TMP3\n  |  b <3\n  |.  nop\n  |5:\n  |  beq CARG3, TISNIL, ->fff_restv\t// Ditto for nil value.\n  |.  nop\n  |  move SFARG1HI, CARG3\t\t// Return value of mt.__metatable.\n  |  b ->fff_restv\n  |.  move SFARG1LO, TMP1\n  |\n  |6:\n  |  beq SFARG1HI, AT, <1\n  |.  sltu AT, TISNUM, SFARG1HI\n  |  movz SFARG1HI, TISNUM, AT\n  |  not TMP1, SFARG1HI\n  |  sll TMP1, TMP1, 2\n  |  addu TMP1, DISPATCH, TMP1\n  |  b <2\n  |.  lw TAB:SFARG1LO, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1)\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  addiu SFARG2HI, SFARG2HI, -LJ_TTAB\n  |  lw TAB:TMP1, TAB:SFARG1LO->metatable\n  |   lbu TMP3, TAB:SFARG1LO->marked\n  |  or AT, SFARG2HI, TAB:TMP1\n  |  bnez AT, ->fff_fallback\n  |.  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n  |  beqz AT, ->fff_restv\n  |.  sw TAB:SFARG2LO, TAB:SFARG1LO->metatable\n  |  barrierback TAB:SFARG1LO, TMP3, TMP0, ->fff_restv\n  |\n  |.ffunc rawget\n  |  lw CARG4, HI(BASE)\n  |   sltiu AT, NARGS8:RC, 16\n  |    lw TAB:CARG2, LO(BASE)\n  |  load_got lj_tab_get\n  |  addiu CARG4, CARG4, -LJ_TTAB\n  |  or AT, AT, CARG4\n  |  bnez AT, ->fff_fallback\n  |   addiu CARG3, BASE, 8\n  |  call_intern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |.  move CARG1, L\n  |  // Returns cTValue *.\n  |  lw SFARG1HI, HI(CRET1)\n  |  b ->fff_restv\n  |.  lw SFARG1LO, LO(CRET1)\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  lw CARG1, HI(BASE)\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly one number argument.\n  |  sltu TMP0, TISNUM, CARG1\n  |  or AT, AT, TMP0\n  |  bnez AT, ->fff_fallback\n  |.  lw SFARG1HI, HI(BASE)\n  |  b ->fff_restv\n  |.  lw SFARG1LO, LO(BASE)\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  li AT, LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq SFARG1HI, AT, ->fff_restv\t// String key?\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |.  lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)\n  |  sltu TMP0, TISNUM, SFARG1HI\n  |  or TMP0, TMP0, TMP1\n  |  bnez TMP0, ->fff_fallback\n  |.  sw BASE, L->base\t\t\t// Add frame since C call can throw.\n  |  ffgccheck\n  |.  sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  load_got lj_strfmt_number\n  |  move CARG1, L\n  |  call_intern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |.  move CARG2, BASE\n  |  // Returns GCstr *.\n  |  li SFARG1HI, LJ_TSTR\n  |  b ->fff_restv\n  |.  move SFARG1LO, CRET1\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc next\n  |  lw CARG2, HI(BASE)\n  |   lw TAB:CARG1, LO(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  addu TMP2, BASE, NARGS8:RC\n  |  li AT, LJ_TTAB\n  |   sw TISNIL, HI(TMP2)\t\t// Set missing 2nd arg to nil.\n  |  bne CARG2, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n  |  load_got lj_tab_next\n  |  addiu CARG2, BASE, 8\n  |  call_intern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |.  addiu CARG3, BASE, -8\n  |  // Returns 1=found, 0=end, -1=error.\n  |   addiu RA, BASE, -8\n  |  bgtz CRET1, ->fff_res\t\t// Found key/value.\n  |.  li RD, (2+1)*8\n  |  beqz CRET1, ->fff_restv\t\t// End of traversal: return nil.\n  |.  li SFARG1HI, LJ_TNIL\n  |   lw CFUNC:RB, FRAME_FUNC(BASE)\n  |  b ->fff_fallback\t\t\t// Invalid key.\n  |.  li RC, 2*8\n  |\n  |.ffunc_1 pairs\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n#if LJ_52\n  |  lw TAB:TMP2, TAB:SFARG1LO->metatable\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n#endif\n  |.  addiu RA, BASE, -8\n  |   sw TISNIL, 8+HI(BASE)\n  |  sw TMP0, HI(RA)\n  |   sw TMP1, LO(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |.ffunc ipairs_aux\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw CARG3, HI(BASE)\n  |    lw TAB:CARG1, LO(BASE)\n  |   lw CARG4, 8+HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  addiu CARG3, CARG3, -LJ_TTAB\n  |  xor CARG4, CARG4, TISNUM\n  |  and AT, CARG3, CARG4\n  |  bnez AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n  |  lw TMP2, 8+LO(BASE)\n  |   lw TMP0, TAB:CARG1->asize\n  |   lw TMP1, TAB:CARG1->array\n  |  addiu TMP2, TMP2, 1\n  |  sw TISNUM, -8+HI(BASE)\n  |  sltu AT, TMP2, TMP0\n  |   sw TMP2, -8+LO(BASE)\n  |  beqz AT, >2\t\t\t// Not in array part?\n  |.  addiu RA, BASE, -8\n  |   sll TMP3, TMP2, 3\n  |   addu TMP3, TMP1, TMP3\n  |  lw TMP1, HI(TMP3)\n  |   lw TMP2, LO(TMP3)\n  |1:\n  |  beq TMP1, TISNIL, ->fff_res\t// End of iteration, return 0 results.\n  |.  li RD, (0+1)*8\n  |  sw TMP1, 8+HI(RA)\n  |   sw TMP2, 8+LO(RA)\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lw TMP0, TAB:CARG1->hmask\n  |  load_got lj_tab_getinth\n  |  beqz TMP0, ->fff_res\n  |.  li RD, (0+1)*8\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  move CARG2, TMP2\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->fff_res\n  |.  li RD, (0+1)*8\n  |  lw TMP1, HI(CRET1)\n  |  b <1\n  |.  lw TMP2, LO(CRET1)\n  |\n  |.ffunc_1 ipairs\n  |  li AT, LJ_TTAB\n  |  bne SFARG1HI, AT, ->fff_fallback\n  |.  lw PC, FRAME_PC(BASE)\n#if LJ_52\n  |  lw TAB:TMP2, TAB:SFARG1LO->metatable\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  lw TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |   lw TMP1, CFUNC:RB->upvalue[0].u32.lo\n#endif\n  |.  addiu RA, BASE, -8\n  |   sw TISNUM, 8+HI(BASE)\n  |   sw r0, 8+LO(BASE)\n  |  sw TMP0, HI(RA)\n  |   sw TMP1, LO(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |   move TMP2, BASE\n  |   addiu BASE, BASE, 8\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |  andi TMP3, TMP3, 1\n  |  addiu PC, TMP3, 8+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |.  addiu NARGS8:RC, NARGS8:RC, -8\n  |\n  |.ffunc xpcall\n  |    sltiu AT, NARGS8:RC, 16\n  |  lw CARG4, 8+HI(BASE)\n  |    bnez AT, ->fff_fallback\n  |.  lw CARG3, 8+LO(BASE)\n  |   lw CARG1, LO(BASE)\n  |    lw CARG2, HI(BASE)\n  |    lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)\n  |  li AT, LJ_TFUNC\n  |   move TMP2, BASE\n  |  bne CARG4, AT, ->fff_fallback  // Traceback must be a function.\n  |   addiu BASE, BASE, 16\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |   sw CARG3, LO(TMP2)\t// Swap function and traceback.\n  |   sw CARG4, HI(TMP2)\n  |  andi TMP3, TMP3, 1\n  |   sw CARG1, 8+LO(TMP2)\n  |    sw CARG2, 8+HI(TMP2)\n  |  addiu PC, TMP3, 16+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |.  addiu NARGS8:RC, NARGS8:RC, -16\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc coroutine_resume\n  |  lw CARG3, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw CARG1, LO(BASE)\n  |  li AT, LJ_TTHREAD\n  |  bne CARG3, AT, ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  lw L:CARG1, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  lbu TMP0, L:CARG1->status\n  |   lw TMP1, L:CARG1->cframe\n  |    lw CARG2, L:CARG1->top\n  |    lw TMP2, L:CARG1->base\n  |  addiu TMP3, TMP0, -LUA_YIELD\n  |  bgtz TMP3, ->fff_fallback\t\t// st > LUA_YIELD?\n  |.   xor TMP2, TMP2, CARG2\n  |  bnez TMP1, ->fff_fallback\t\t// cframe != 0?\n  |.  or AT, TMP2, TMP0\n  |  lw TMP0, L:CARG1->maxstack\n  |  beqz AT, ->fff_fallback\t\t// base == top && st == 0?\n  |.  lw PC, FRAME_PC(BASE)\n  |  addu TMP2, CARG2, NARGS8:RC\n  |  sltu AT, TMP0, TMP2\n  |  bnez AT, ->fff_fallback\t\t// Stack overflow?\n  |.  sw PC, SAVE_PC\n  |   sw BASE, L->base\n  |1:\n  |.if resume\n  |  addiu BASE, BASE, 8\t\t// Keep resumed thread in stack for GC.\n  |  addiu NARGS8:RC, NARGS8:RC, -8\n  |  addiu TMP2, TMP2, -8\n  |.endif\n  |  sw TMP2, L:CARG1->top\n  |  addu TMP1, BASE, NARGS8:RC\n  |  move CARG3, CARG2\n  |  sw BASE, L->top\n  |2:  // Move args to coroutine.\n  |   lw SFRETHI, HI(BASE)\n  |    lw SFRETLO, LO(BASE)\n  |  sltu AT, BASE, TMP1\n  |  beqz AT, >3\n  |.  addiu BASE, BASE, 8\n  |   sw SFRETHI, HI(CARG3)\n  |    sw SFRETLO, LO(CARG3)\n  |  b <2\n  |.  addiu CARG3, CARG3, 8\n  |3:\n  |  bal ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |.  move L:RA, L:CARG1\n  |  // Returns thread status.\n  |4:\n  |  lw TMP2, L:RA->base\n  |   sltiu AT, CRET1, LUA_YIELD+1\n  |  lw TMP3, L:RA->top\n  |    li_vmstate INTERP\n  |  lw BASE, L->base\n  |    sw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |    st_vmstate\n  |   beqz AT, >8\n  |. subu RD, TMP3, TMP2\n  |   lw TMP0, L->maxstack\n  |  beqz RD, >6\t\t\t// No results?\n  |.  addu TMP1, BASE, RD\n  |  sltu AT, TMP0, TMP1\n  |  bnez AT, >9\t\t\t// Need to grow stack?\n  |.  addu TMP3, TMP2, RD\n  |  sw TMP2, L:RA->top\t\t\t// Clear coroutine stack.\n  |  move TMP1, BASE\n  |5:  // Move results from coroutine.\n  |   lw SFRETHI, HI(TMP2)\n  |    lw SFRETLO, LO(TMP2)\n  |  addiu TMP2, TMP2, 8\n  |  sltu AT, TMP2, TMP3\n  |   sw SFRETHI, HI(TMP1)\n  |    sw SFRETLO, LO(TMP1)\n  |  bnez AT, <5\n  |.  addiu TMP1, TMP1, 8\n  |6:\n  |  andi TMP0, PC, FRAME_TYPE\n  |.if resume\n  |  li TMP1, LJ_TTRUE\n  |   addiu RA, BASE, -8\n  |  sw TMP1, -8+HI(BASE)\t\t// Prepend true to results.\n  |  addiu RD, RD, 16\n  |.else\n  |  move RA, BASE\n  |  addiu RD, RD, 8\n  |.endif\n  |7:\n  |  sw PC, SAVE_PC\n  |  beqz TMP0, ->BC_RET_Z\n  |.  move MULTRES, RD\n  |  b ->vm_return\n  |.  nop\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  addiu TMP3, TMP3, -8\n  |   li TMP1, LJ_TFALSE\n  |  lw SFRETHI, HI(TMP3)\n  |   lw SFRETLO, LO(TMP3)\n  |   sw TMP3, L:RA->top\t\t// Remove error from coroutine stack.\n  |    li RD, (2+1)*8\n  |   sw TMP1, -8+HI(BASE)\t\t// Prepend false to results.\n  |    addiu RA, BASE, -8\n  |  sw SFRETHI, HI(BASE)\t\t// Copy error message.\n  |   sw SFRETLO, LO(BASE)\n  |  b <7\n  |.  andi TMP0, PC, FRAME_TYPE\n  |.else\n  |  load_got lj_ffh_coroutine_wrap_err\n  |  move CARG2, L:RA\n  |  call_intern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |.  move CARG1, L\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  load_got lj_state_growstack\n  |  srl CARG2, RD, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  b <4\n  |.  li CRET1, 0\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  lw TMP0, L->cframe\n  |   addu TMP1, BASE, NARGS8:RC\n  |   sw BASE, L->base\n  |  andi TMP0, TMP0, CFRAME_RESUME\n  |   sw TMP1, L->top\n  |  beqz TMP0, ->fff_fallback\n  |.   li CRET1, LUA_YIELD\n  |  sw r0, L->cframe\n  |  b ->vm_leave_unw\n  |.   sb CRET1, L->status\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  bne SFARG1HI, TISNUM, >1\n  |.  sra TMP0, SFARG1LO, 31\n  |  xor TMP1, SFARG1LO, TMP0\n  |  subu SFARG1LO, TMP1, TMP0\n  |  bgez SFARG1LO, ->fff_restv\n  |.  nop\n  |  lui SFARG1HI, 0x41e0\t\t// 2^31 as a double.\n  |  b ->fff_restv\n  |.  li SFARG1LO, 0\n  |1:\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  sll SFARG1HI, SFARG1HI, 1\n  |  srl SFARG1HI, SFARG1HI, 1\n  |// fallthrough\n  |\n  |->fff_restv:\n  |  // SFARG1LO/SFARG1HI = TValue result.\n  |  lw PC, FRAME_PC(BASE)\n  |   sw SFARG1HI, -8+HI(BASE)\n  |  addiu RA, BASE, -8\n  |   sw SFARG1LO, -8+LO(BASE)\n  |->fff_res1:\n  |  // RA = results, PC = return.\n  |  li RD, (1+1)*8\n  |->fff_res:\n  |  // RA = results, RD = (nresults+1)*8, PC = return.\n  |  andi TMP0, PC, FRAME_TYPE\n  |  bnez TMP0, ->vm_return\n  |.  move MULTRES, RD\n  |  lw INS, -4(PC)\n  |  decode_RB8a RB, INS\n  |  decode_RB8b RB\n  |5:\n  |  sltu AT, RD, RB\n  |  bnez AT, >6\t\t\t// More results expected?\n  |.  decode_RA8a TMP0, INS\n  |  decode_RA8b TMP0\n  |  ins_next1\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |   subu BASE, RA, TMP0\n  |  ins_next2\n  |\n  |6:  // Fill up results with nil.\n  |  addu TMP1, RA, RD\n  |   addiu RD, RD, 8\n  |  b <5\n  |.  sw TISNIL, -8+HI(TMP1)\n  |\n  |.macro math_extern, func\n  |  .ffunc math_ .. func\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  load_got func\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |.  load_got func\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |// TODO: Return integer type if result is integer (own sf implementation).\n  |.macro math_round, func\n  |->ff_math_ .. func:\n  |  lw SFARG1HI, HI(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  lw SFARG1LO, LO(BASE)\n  |  beq SFARG1HI, TISNUM, ->fff_restv\n  |.  sltu AT, SFARG1HI, TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  bal ->vm_ .. func\n  |.else\n  |.  load_got func\n  |  call_extern\n  |.endif\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  li AT, 8\n  |  bne NARGS8:RC, AT, ->fff_fallback\t// Exactly 1 argument.\n  |.  lw SFARG1HI, HI(BASE)\n  |  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  load_got log\n  |.if FPU\n  |  call_extern\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |  call_extern\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  b ->fff_resn\n  |.  nop\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if FPU\n  |.ffunc_n math_sqrt\n  |.  sqrt.d FRET1, FARG1\n  |// fallthrough to ->fff_resn\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |->fff_resn:\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |  b ->fff_res1\n  |.  sdc1 FRET1, -8(BASE)\n  |.else\n  |  sw SFRETHI, -8+HI(BASE)\n  |  b ->fff_res1\n  |.  sw SFRETLO, -8+LO(BASE)\n  |.endif\n  |\n  |\n  |.ffunc math_ldexp\n  |  sltiu AT, NARGS8:RC, 16\n  |   lw SFARG1HI, HI(BASE)\n  |  bnez AT, ->fff_fallback\n  |.   lw CARG4, 8+HI(BASE)\n  |  bne CARG4, TISNUM, ->fff_fallback\n  |  load_got ldexp\n  |.  sltu AT, SFARG1HI, TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |.  lw SFARG1LO, LO(BASE)\n  |.endif\n  |  call_extern\n  |.  lw CARG3, 8+LO(BASE)\n  |  b ->fff_resn\n  |.  nop\n  |\n  |.ffunc_n math_frexp\n  |  load_got frexp\n  |   lw PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |   lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |   mtc1 TMP1, FARG2\n  |  sdc1 FRET1, 0(RA)\n  |   cvt.d.w FARG2, FARG2\n  |   sdc1 FARG2, 8(RA)\n  |.else\n  |  sw SFRETLO, LO(RA)\n  |  sw SFRETHI, HI(RA)\n  |  sw TMP1, 8+LO(RA)\n  |  sw TISNUM, 8+HI(RA)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.ffunc_n math_modf\n  |  load_got modf\n  |   lw PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  addiu CARG3, BASE, -8\n  |  addiu RA, BASE, -8\n  |.if FPU\n  |  sdc1 FRET1, 0(BASE)\n  |.else\n  |  sw SFRETLO, LO(BASE)\n  |  sw SFRETHI, HI(BASE)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.macro math_minmax, name, intins, ismax\n  |  .ffunc_1 name\n  |  addu TMP3, BASE, NARGS8:RC\n  |  bne SFARG1HI, TISNUM, >5\n  |.  addiu TMP2, BASE, 8\n  |1:  // Handle integers.\n  |.  lw SFARG2HI, HI(TMP2)\n  |  beq TMP2, TMP3, ->fff_restv\n  |.  lw SFARG2LO, LO(TMP2)\n  |  bne SFARG2HI, TISNUM, >3\n  |.  slt AT, SFARG1LO, SFARG2LO\n  |  intins SFARG1LO, SFARG2LO, AT\n  |  b <1\n  |.  addiu TMP2, TMP2, 8\n  |\n  |3:  // Convert intermediate result to number and continue with number loop.\n  |  sltiu AT, SFARG2HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  mtc1 SFARG1LO, FRET1\n  |  cvt.d.w FRET1, FRET1\n  |  b >7\n  |.  ldc1 FARG1, 0(TMP2)\n  |.else\n  |.  nop\n  |  bal ->vm_sfi2d_1\n  |.  nop\n  |  b >7\n  |.  nop\n  |.endif\n  |\n  |5:\n  |.  sltiu AT, SFARG1HI, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FRET1, 0(BASE)\n  |.endif\n  |\n  |6:  // Handle numbers.\n  |.  lw SFARG2HI, HI(TMP2)\n  |.if FPU\n  |  beq TMP2, TMP3, ->fff_resn\n  |.else\n  |  beq TMP2, TMP3, ->fff_restv\n  |.endif\n  |.  sltiu AT, SFARG2HI, LJ_TISNUM\n  |  beqz AT, >8\n  |.if FPU\n  |.  ldc1 FARG1, 0(TMP2)\n  |.else\n  |.  lw SFARG2LO, LO(TMP2)\n  |.endif\n  |7:\n  |.if FPU\n  |.if ismax\n  |  c.olt.d FARG1, FRET1\n  |.else\n  |  c.olt.d FRET1, FARG1\n  |.endif\n  |  movf.d FRET1, FARG1\n  |.else\n  |.if ismax\n  |  bal ->vm_sfcmpogt\n  |.else\n  |  bal ->vm_sfcmpolt\n  |.endif\n  |.  nop\n  |  movz SFARG1LO, SFARG2LO, CRET1\n  |  movz SFARG1HI, SFARG2HI, CRET1\n  |.endif\n  |  b <6\n  |.  addiu TMP2, TMP2, 8\n  |\n  |8:  // Convert integer to number and continue with number loop.\n  |  bne SFARG2HI, TISNUM, ->fff_fallback\n  |.if FPU\n  |.  lwc1 FARG1, LO(TMP2)\n  |  b <7\n  |.  cvt.d.w FARG1, FARG1\n  |.else\n  |.  nop\n  |  bal ->vm_sfi2d_2\n  |.  nop\n  |  b <7\n  |.  nop\n  |.endif\n  |\n  |.endmacro\n  |\n  |  math_minmax math_min, movz, 0\n  |  math_minmax math_max, movn, 1\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  lw CARG3, HI(BASE)\n  |   lw STR:CARG1, LO(BASE)\n  |  xori AT, NARGS8:RC, 8\n  |  addiu CARG3, CARG3, -LJ_TSTR\n  |  or AT, AT, CARG3\n  |  bnez AT, ->fff_fallback\t\t// Need exactly 1 string argument.\n  |.  nop\n  |  lw TMP0, STR:CARG1->len\n  |    addiu RA, BASE, -8\n  |    lw PC, FRAME_PC(BASE)\n  |  sltu RD, r0, TMP0\n  |   lbu TMP1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |  addiu RD, RD, 1\n  |  sll RD, RD, 3\t\t\t// RD = ((str->len != 0)+1)*8\n  |  sw TISNUM, HI(RA)\n  |  b ->fff_res\n  |.  sw TMP1, LO(RA)\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |.  nop\n  |  lw CARG3, HI(BASE)\n  |   lw CARG1, LO(BASE)\n  |  li TMP1, 255\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly 1 argument.\n  |  xor TMP0, CARG3, TISNUM\t\t// Integer.\n  |   sltu TMP1, TMP1, CARG1\t\t// !(255 < n).\n  |  or AT, AT, TMP0\n  |   or AT, AT, TMP1\n  |  bnez AT, ->fff_fallback\n  |.  li CARG3, 1\n  |  addiu CARG2, sp, ARG5_OFS\n  |  sb CARG1, ARG5\n  |->fff_newstr:\n  |  load_got lj_str_new\n  |   sw BASE, L->base\n  |   sw PC, SAVE_PC\n  |  call_intern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |.  move CARG1, L\n  |  // Returns GCstr *.\n  |  lw BASE, L->base\n  |->fff_resstr:\n  |  move SFARG1LO, CRET1\n  |  b ->fff_restv\n  |.  li SFARG1HI, LJ_TSTR\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |.  nop\n  |  addiu AT, NARGS8:RC, -16\n  |   lw CARG3, 16+HI(BASE)\n  |   lw TMP0, HI(BASE)\n  |    lw STR:CARG1, LO(BASE)\n  |  bltz AT, ->fff_fallback\n  |.  lw CARG2, 8+HI(BASE)\n  |  beqz AT, >1\n  |.  li CARG4, -1\n  |  bne CARG3, TISNUM, ->fff_fallback\n  |.  lw CARG4, 16+LO(BASE)\n  |1:\n  |  bne CARG2, TISNUM, ->fff_fallback\n  |.  li AT, LJ_TSTR\n  |  bne TMP0, AT, ->fff_fallback\n  |.  lw CARG3, 8+LO(BASE)\n  |  lw CARG2, STR:CARG1->len\n  |  // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end\n  |  slt AT, CARG4, r0\n  |  addiu TMP0, CARG2, 1\n  |  addu TMP1, CARG4, TMP0\n  |   slt TMP3, CARG3, r0\n  |  movn CARG4, TMP1, AT\t\t// if (end < 0) end += len+1\n  |   addu TMP1, CARG3, TMP0\n  |   movn CARG3, TMP1, TMP3\t\t// if (start < 0) start += len+1\n  |   li TMP2, 1\n  |  slt AT, CARG4, r0\n  |   slt TMP3, r0, CARG3\n  |  movn CARG4, r0, AT\t\t\t// if (end < 0) end = 0\n  |   movz CARG3, TMP2, TMP3\t\t// if (start < 1) start = 1\n  |  slt AT, CARG2, CARG4\n  |  movn CARG4, CARG2, AT\t\t// if (end > len) end = len\n  |   addu CARG2, STR:CARG1, CARG3\n  |  subu CARG3, CARG4, CARG3\t\t// len = end - start\n  |   addiu CARG2, CARG2, sizeof(GCstr)-1\n  |  bgez CARG3, ->fff_newstr\n  |.  addiu CARG3, CARG3, 1\t\t// len++\n  |->fff_emptystr:  // Return empty string.\n  |  addiu STR:SFARG1LO, DISPATCH, DISPATCH_GL(strempty)\n  |  b ->fff_restv\n  |.  li SFARG1HI, LJ_TSTR\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |.  nop\n  |  lw CARG3, HI(BASE)\n  |   lw STR:CARG2, LO(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  li AT, LJ_TSTR\n  |  bne CARG3, AT, ->fff_fallback\n  |.  addiu SBUF:CARG1, DISPATCH, DISPATCH_GL(tmpbuf)\n  |  load_got lj_buf_putstr_ .. name\n  |  lw TMP0, SBUF:CARG1->b\n  |   sw L, SBUF:CARG1->L\n  |   sw BASE, L->base\n  |  sw TMP0, SBUF:CARG1->w\n  |  call_intern extern lj_buf_putstr_ .. name\n  |.  sw PC, SAVE_PC\n  |  load_got lj_buf_tostr\n  |  call_intern lj_buf_tostr\n  |.  move SBUF:CARG1, SBUF:CRET1\n  |  b ->fff_resstr\n  |.  lw BASE, L->base\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |->vm_tobit_fb:\n  |  beqz TMP1, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  add.d FARG1, FARG1, TOBIT\n  |  jr ra\n  |.  mfc1 CRET1, FARG1\n  |.else\n  |// FP number to bit conversion for soft-float.\n  |->vm_tobit:\n  |  sll TMP0, SFARG1HI, 1\n  |  lui AT, 0x0020\n  |  addu TMP0, TMP0, AT\n  |  slt AT, TMP0, r0\n  |  movz SFARG1LO, r0, AT\n  |  beqz AT, >2\n  |.  li TMP1, 0x3e0\n  |  not TMP1, TMP1\n  |  sra TMP0, TMP0, 21\n  |  subu TMP0, TMP1, TMP0\n  |  slt AT, TMP0, r0\n  |  bnez AT, >1\n  |.  sll TMP1, SFARG1HI, 11\n  |  lui AT, 0x8000\n  |  or TMP1, TMP1, AT\n  |  srl AT, SFARG1LO, 21\n  |  or TMP1, TMP1, AT\n  |  slt AT, SFARG1HI, r0\n  |  beqz AT, >2\n  |.  srlv SFARG1LO, TMP1, TMP0\n  |  subu SFARG1LO, r0, SFARG1LO\n  |2:\n  |  jr ra\n  |.  move CRET1, SFARG1LO\n  |1:\n  |  addiu TMP0, TMP0, 21\n  |  srlv TMP1, SFARG1LO, TMP0\n  |  li AT, 20\n  |  subu TMP0, AT, TMP0\n  |  sll SFARG1LO, SFARG1HI, 12\n  |  sllv AT, SFARG1LO, TMP0\n  |  or SFARG1LO, TMP1, AT\n  |  slt AT, SFARG1HI, r0\n  |  beqz AT, <2\n  |.  nop\n  |  jr ra\n  |.  subu CRET1, r0, SFARG1LO\n  |.endif\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  beq SFARG1HI, TISNUM, >6\n  |.  move CRET1, SFARG1LO\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |6:\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  addiu TMP2, BASE, 8\n  |  addu TMP3, BASE, NARGS8:RC\n  |1:\n  |  lw SFARG1HI, HI(TMP2)\n  |  beq TMP2, TMP3, ->fff_resi\n  |.  lw SFARG1LO, LO(TMP2)\n  |.if FPU\n  |  bne SFARG1HI, TISNUM, >2\n  |.  addiu TMP2, TMP2, 8\n  |  b <1\n  |.  ins CRET1, CRET1, SFARG1LO\n  |2:\n  |   ldc1 FARG1, -8(TMP2)\n  |  sltu TMP1, SFARG1HI, TISNUM\n  |  beqz TMP1, ->fff_fallback\n  |.  add.d FARG1, FARG1, TOBIT\n  |  mfc1 SFARG1LO, FARG1\n  |  b <1\n  |.  ins CRET1, CRET1, SFARG1LO\n  |.else\n  |  beq SFARG1HI, TISNUM, >2\n  |.  move CRET2, CRET1\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |  move SFARG1LO, CRET2\n  |2:\n  |  ins CRET1, CRET1, SFARG1LO\n  |  b <1\n  |.  addiu TMP2, TMP2, 8\n  |.endif\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, or\n  |.ffunc_bit_op bxor, xor\n  |\n  |.ffunc_bit bswap\n  |  srl TMP0, CRET1, 24\n  |   srl TMP2, CRET1, 8\n  |  sll TMP1, CRET1, 24\n  |   andi TMP2, TMP2, 0xff00\n  |  or TMP0, TMP0, TMP1\n  |   andi CRET1, CRET1, 0xff00\n  |  or TMP0, TMP0, TMP2\n  |   sll CRET1, CRET1, 8\n  |  b ->fff_resi\n  |.  or CRET1, TMP0, CRET1\n  |\n  |.ffunc_bit bnot\n  |  b ->fff_resi\n  |.  not CRET1, CRET1\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |  .ffunc_2 bit_..name\n  |  beq SFARG1HI, TISNUM, >1\n  |.  nop\n  |  bal ->vm_tobit_fb\n  |.  sltu TMP1, SFARG1HI, TISNUM\n  |  move SFARG1LO, CRET1\n  |1:\n  |  bne SFARG2HI, TISNUM, ->fff_fallback\n  |.  nop\n  |.if shmod == 1\n  |  li AT, 32\n  |  subu TMP0, AT, SFARG2LO\n  |  sllv SFARG2LO, SFARG1LO, SFARG2LO\n  |  srlv SFARG1LO, SFARG1LO, TMP0\n  |.elif shmod == 2\n  |  li AT, 32\n  |  subu TMP0, AT, SFARG2LO\n  |  srlv SFARG2LO, SFARG1LO, SFARG2LO\n  |  sllv SFARG1LO, SFARG1LO, TMP0\n  |.endif\n  |  b ->fff_resi\n  |.  ins CRET1, SFARG1LO, SFARG2LO\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, sllv, 0\n  |.ffunc_bit_sh rshift, srlv, 0\n  |.ffunc_bit_sh arshift, srav, 0\n  |// Can't use rotrv, since it's only in MIPS32R2.\n  |.ffunc_bit_sh rol, or, 1\n  |.ffunc_bit_sh ror, or, 2\n  |\n  |.ffunc_bit tobit\n  |->fff_resi:\n  |  lw PC, FRAME_PC(BASE)\n  |  addiu RA, BASE, -8\n  |  sw TISNUM, -8+HI(BASE)\n  |  b ->fff_res1\n  |.  sw CRET1, -8+LO(BASE)\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RB = CFUNC, RC = nargs*8\n  |  lw TMP3, CFUNC:RB->f\n  |    addu TMP1, BASE, NARGS8:RC\n  |   lw PC, FRAME_PC(BASE)\t\t// Fallback may overwrite PC.\n  |    addiu TMP0, TMP1, 8*LUA_MINSTACK\n  |     lw TMP2, L->maxstack\n  |   sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sltu AT, TMP2, TMP0\n  |     sw BASE, L->base\n  |    sw TMP1, L->top\n  |  bnez AT, >5\t\t\t// Need to grow stack.\n  |.  move CFUNCADDR, TMP3\n  |  jalr TMP3\t\t\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  lw BASE, L->base\n  |   sll RD, CRET1, 3\n  |  bgtz CRET1, ->fff_res\t\t// Returned nresults+1?\n  |.  addiu RA, BASE, -8\n  |1:  // Returned 0 or -1: retry fast path.\n  |  lw TMP0, L->top\n  |   lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  bnez CRET1, ->vm_call_tail\t\t// Returned -1?\n  |.  subu NARGS8:RC, TMP0, BASE\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  andi TMP0, PC, FRAME_TYPE\n  |   li AT, -4\n  |  bnez TMP0, >3\n  |.  and TMP1, PC, AT\n  |  lbu TMP1, OFS_RA(PC)\n  |  sll TMP1, TMP1, 3\n  |  addiu TMP1, TMP1, 8\n  |3:\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |.  subu TMP2, BASE, TMP1\n  |\n  |5:  // Grow stack for fallback handler.\n  |  load_got lj_state_growstack\n  |  li CARG2, LUA_MINSTACK\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  lw BASE, L->base\n  |  b <1\n  |.  li CRET1, 0\t\t\t// Force retry.\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  move MULTRES, ra\n  |  load_got lj_gc_step\n  |   sw BASE, L->base\n  |  addu TMP0, BASE, NARGS8:RC\n  |   sw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sw TMP0, L->top\n  |  call_intern lj_gc_step\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |   lw BASE, L->base\n  |  move ra, MULTRES\n  |    lw TMP0, L->top\n  |  lw CFUNC:RB, FRAME_FUNC(BASE)\n  |  jr ra\n  |.  subu NARGS8:RC, TMP0, BASE\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_VMEVENT\t// No recording while in vmevent.\n  |  bnez AT, >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |.  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\n  |  bnez AT, >1\n  |.  addiu TMP2, TMP2, -1\n  |  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, >1\n  |.  nop\n  |  b >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  beqz AT, >1\n  |5:  // Re-dispatch to static ins.\n  |.  lw AT, GG_DISP2STATIC(TMP0)\t// Assumes TMP0 holds DISPATCH+OP*4.\n  |  jr AT\n  |.  nop\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  bnez AT, <5\n  |.  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, <5\n  |.  addiu TMP2, TMP2, -1\n  |  beqz TMP2, >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, LUA_MASKLINE\n  |  beqz AT, <5\n  |1:\n  |.  load_got lj_dispatch_ins\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sw BASE, L->base\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call_intern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |3:\n  |  lw BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  lw INS, -4(PC)\n  |  decode_OP4a TMP1, INS\n  |  decode_OP4b TMP1\n  |  addu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  lw AT, GG_DISP2STATIC(TMP0)\n  |   decode_RA8a RA, INS\n  |   decode_RD8b RD\n  |  jr AT\n  |   decode_RA8b RA\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  addiu PC, PC, 4\n  |  b <4\n  |.  lw MULTRES, -24+LO(RB)\t\t// Restore MULTRES for *M ins.\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n  |   addiu CARG1, DISPATCH, GG_DISP2J\n  |   sw PC, SAVE_PC\n  |  lw TMP1, LFUNC:TMP1->pc\n  |   move CARG2, PC\n  |   sw L, DISPATCH_J(L)(DISPATCH)\n  |  lbu TMP1, PC2PROTO(framesize)(TMP1)\n  |  load_got lj_trace_hot\n  |   sw BASE, L->base\n  |  sll TMP1, TMP1, 3\n  |  addu TMP1, BASE, TMP1\n  |  call_intern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |.  sw TMP1, L->top\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |.if JIT\n  |  b >1\n  |.endif\n  |.  move CARG2, PC\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  ori CARG2, PC, 1\n  |1:\n  |.endif\n  |  load_got lj_dispatch_call\n  |  addu TMP0, BASE, RC\n  |   sw PC, SAVE_PC\n  |   sw BASE, L->base\n  |  subu RA, RA, BASE\n  |   sw TMP0, L->top\n  |  call_intern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // Returns ASMFunction.\n  |  lw BASE, L->base\n  |   lw TMP0, L->top\n  |   sw r0, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  subu NARGS8:RC, TMP0, BASE\n  |  addu RA, BASE, RA\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |  jr CRET1\n  |.  lw INS, -4(PC)\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |    lw TMP2, -24+LO(RB)\t\t// Save previous trace.\n  |  decode_RA8a RC, INS\n  |   addiu AT, MULTRES, -8\n  |  decode_RA8b RC\n  |   beqz AT, >2\n  |. addu RC, BASE, RC\t\t\t// Call base.\n  |1:  // Move results down.\n  |  lw SFRETHI, HI(RA)\n  |   lw SFRETLO, LO(RA)\n  |   addiu AT, AT, -8\n  |    addiu RA, RA, 8\n  |  sw SFRETHI, HI(RC)\n  |   sw SFRETLO, LO(RC)\n  |   bnez AT, <1\n  |.   addiu RC, RC, 8\n  |2:\n  |   decode_RA8a RA, INS\n  |    decode_RB8a RB, INS\n  |   decode_RA8b RA\n  |    decode_RB8b RB\n  |   addu RA, RA, RB\n  |   addu RA, BASE, RA\n  |3:\n  |   sltu AT, RC, RA\n  |   bnez AT, >9\t\t\t// More results wanted?\n  |.   nop\n  |\n  |  lhu TMP3, TRACE:TMP2->traceno\n  |  lhu RD, TRACE:TMP2->link\n  |  beq RD, TMP3, ->cont_nop\t\t// Blacklisted.\n  |.  load_got lj_dispatch_stitch\n  |  bnez RD, =>BC_JLOOP\t\t// Jump to stitched trace.\n  |.  sll RD, RD, 3\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  sw TMP3, DISPATCH_J(exitno)(DISPATCH)\n  |  sw L, DISPATCH_J(L)(DISPATCH)\n  |  sw BASE, L->base\n  |  addiu CARG1, DISPATCH, GG_DISP2J\n  |  call_intern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |.  move CARG2, PC\n  |  b ->cont_nop\n  |.  lw BASE, L->base\n  |\n  |9:\n  |  sw TISNIL, HI(RC)\n  |  b <3\n  |.  addiu RC, RC, 8\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  load_got lj_dispatch_profile\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sw BASE, L->base\n  |  call_intern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  addiu PC, PC, -4\n  |  b ->cont_nop\n  |.  lw BASE, L->base\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b\n  |.if FPU\n  |  sdc1 f..a, 16+a*8(sp)\n  |  sw r..a, 16+32*8+a*4(sp)\n  |  sw r..b, 16+32*8+b*4(sp)\n  |.else\n  |  sw r..a, 16+a*4(sp)\n  |  sw r..b, 16+b*4(sp)\n  |.endif\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |.if FPU\n  |  addiu sp, sp, -(16+32*8+32*4)\n  |.else\n  |  addiu sp, sp, -(16+32*4)\n  |.endif\n  |  savex_ 0, 1\n  |  savex_ 2, 3\n  |  savex_ 4, 5\n  |  savex_ 6, 7\n  |  savex_ 8, 9\n  |  savex_ 10, 11\n  |  savex_ 12, 13\n  |  savex_ 14, 15\n  |  savex_ 16, 17\n  |  savex_ 18, 19\n  |  savex_ 20, 21\n  |  savex_ 22, 23\n  |  savex_ 24, 25\n  |  savex_ 26, 27\n  |.if FPU\n  |  sdc1 f28, 16+28*8(sp)\n  |  sdc1 f30, 16+30*8(sp)\n  |  sw r28, 16+32*8+28*4(sp)\n  |  sw r30, 16+32*8+30*4(sp)\n  |  sw r0, 16+32*8+31*4(sp)\t\t// Clear RID_TMP.\n  |  addiu TMP2, sp, 16+32*8+32*4\t// Recompute original value of sp.\n  |  sw TMP2, 16+32*8+29*4(sp)\t\t// Store sp in RID_SP\n  |.else\n  |  sw r28, 16+28*4(sp)\n  |  sw r30, 16+30*4(sp)\n  |  sw r0, 16+31*4(sp)\t\t\t// Clear RID_TMP.\n  |  addiu TMP2, sp, 16+32*4\t\t// Recompute original value of sp.\n  |  sw TMP2, 16+29*4(sp)\t\t// Store sp in RID_SP\n  |.endif\n  |  li_vmstate EXIT\n  |  addiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  lw TMP1, 0(TMP2)\t\t\t// Load exit number.\n  |  st_vmstate\n  |  lw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |   lw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n  |  load_got lj_trace_exit\n  |  sw L, DISPATCH_J(L)(DISPATCH)\n  |  sw ra, DISPATCH_J(parent)(DISPATCH)  // Store trace number.\n  |   sw BASE, L->base\n  |  sw TMP1, DISPATCH_J(exitno)(DISPATCH)  // Store exit number.\n  |  addiu CARG1, DISPATCH, GG_DISP2J\n  |   sw r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  call_intern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |.  addiu CARG2, sp, 16\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  lw TMP1, L->cframe\n  |  li AT, -4\n  |   lw BASE, L->base\n  |  and sp, TMP1, AT\n  |   lw PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  b >1\n  |.  sw L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |.endif\n  |->vm_exit_interp:\n  |.if JIT\n  |  // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.\n  |  lw L, SAVE_L\n  |   addiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  sw BASE, L->base\n  |1:\n  |  bltz CRET1, >9\t\t\t// Check for error from exit.\n  |.  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |    .FPU lui TMP3, 0x59c0\t\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  sll MULTRES, CRET1, 3\n  |    li TISNIL, LJ_TNIL\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  sw MULTRES, SAVE_MULTRES\n  |    .FPU mtc1 TMP3, TOBIT\n  |  lw TMP1, LFUNC:RB->pc\n  |   sw r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  lw KBASE, PC2PROTO(k)(TMP1)\n  |    .FPU cvt.d.s TOBIT, TOBIT\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  lw INS, 0(PC)\n  |   addiu PC, PC, 4\n  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1\n  |    sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)\n  |  decode_OP4a TMP1, INS\n  |  decode_OP4b TMP1\n  |    sltiu TMP2, TMP1, BC_FUNCF*4\n  |  addu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  lw AT, 0(TMP0)\n  |   decode_RA8a RA, INS\n  |    beqz TMP2, >2\n  |.  decode_RA8b RA\n  |  jr AT\n  |.  decode_RD8b RD\n  |2:\n  |  sltiu TMP2, TMP1, (BC_FUNCC+2)*4\t// Fast function?\n  |  bnez TMP2, >3\n  |.  lw TMP1, FRAME_PC(BASE)\n  |  // Check frame below fast function.\n  |  andi TMP0, TMP1, FRAME_TYPE\n  |  bnez TMP0, >3\t\t\t// Trace stitching continuation?\n  |.  nop\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  lw TMP2, -4(TMP1)\n  |  decode_RA8a TMP0, TMP2\n  |  decode_RA8b TMP0\n  |  subu TMP1, BASE, TMP0\n  |  lw LFUNC:TMP2, -8+FRAME_FUNC(TMP1)\n  |  lw TMP1, LFUNC:TMP2->pc\n  |  lw KBASE, PC2PROTO(k)(TMP1)\n  |3:\n  |  addiu RC, MULTRES, -8\n  |  jr AT\n  |.  addu RA, RA, BASE\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  load_got lj_err_trace\n  |  sub CARG2, r0, CRET1\n  |  call_intern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.  move CARG1, L\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Hard-float round to integer.\n  |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.\n  |.macro vm_round_hf, func\n  |  lui TMP0, 0x4330\t\t\t// Hiword of 2^52 (double).\n  |  mtc1 r0, f4\n  |  mtc1 TMP0, f5\n  |  abs.d FRET2, FARG1\t\t\t// |x|\n  |    mfc1 AT, f13\n  |  c.olt.d 0, FRET2, f4\n  |   add.d FRET1, FRET2, f4\t\t// (|x| + 2^52) - 2^52\n  |  bc1f 0, >1\t\t\t\t// Truncate only if |x| < 2^52.\n  |.  sub.d FRET1, FRET1, f4\n  |    slt AT, AT, r0\n  |.if \"func\" == \"ceil\"\n  |   lui TMP0, 0xbff0\t\t\t// Hiword of -1 (double). Preserves -0.\n  |.else\n  |   lui TMP0, 0x3ff0\t\t\t// Hiword of +1 (double).\n  |.endif\n  |.if \"func\" == \"trunc\"\n  |   mtc1 TMP0, f5\n  |  c.olt.d 0, FRET2, FRET1\t\t// |x| < result?\n  |   sub.d FRET2, FRET1, f4\n  |  movt.d FRET1, FRET2, 0\t\t// If yes, subtract +1.\n  |  neg.d FRET2, FRET1\n  |  jr ra\n  |.  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.else\n  |  neg.d FRET2, FRET1\n  |   mtc1 TMP0, f5\n  |  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.if \"func\" == \"ceil\"\n  |  c.olt.d 0, FRET1, FARG1\t\t// x > result?\n  |.else\n  |  c.olt.d 0, FARG1, FRET1\t\t// x < result?\n  |.endif\n  |   sub.d FRET2, FRET1, f4\t\t// If yes, subtract +-1.\n  |  jr ra\n  |.  movt.d FRET1, FRET2, 0\n  |.endif\n  |1:\n  |  jr ra\n  |.  mov.d FRET1, FARG1\n  |.endmacro\n  |\n  |.macro vm_round, func\n  |.if FPU\n  |  vm_round_hf, func\n  |.endif\n  |.endmacro\n  |\n  |->vm_floor:\n  |  vm_round floor\n  |->vm_ceil:\n  |  vm_round ceil\n  |->vm_trunc:\n  |.if JIT\n  |  vm_round trunc\n  |.endif\n  |\n  |// Soft-float integer to number conversion.\n  |.macro sfi2d, AHI, ALO\n  |.if not FPU\n  |  beqz ALO, >9\t\t\t// Handle zero first.\n  |.  sra TMP0, ALO, 31\n  |  xor TMP1, ALO, TMP0\n  |  subu TMP1, TMP1, TMP0\t\t// Absolute value in TMP1.\n  |  clz AHI, TMP1\n  |    andi TMP0, TMP0, 0x800\t\t// Mask sign bit.\n  |  li AT, 0x3ff+31-1\n  |   sllv TMP1, TMP1, AHI\t\t// Align mantissa left with leading 1.\n  |  subu AHI, AT, AHI\t\t\t// Exponent - 1 in AHI.\n  |   sll ALO, TMP1, 21\n  |  or AHI, AHI, TMP0\t\t\t// Sign | Exponent.\n  |   srl TMP1, TMP1, 11\n  |  sll AHI, AHI, 20\t\t\t// Align left.\n  |  jr ra\n  |.  addu AHI, AHI, TMP1\t\t// Add mantissa, increment exponent.\n  |9:\n  |  jr ra\n  |.  li AHI, 0\n  |.endif\n  |.endmacro\n  |\n  |// Input SFARG1LO. Output: SFARG1*. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_1:\n  |  sfi2d SFARG1HI, SFARG1LO\n  |\n  |// Input SFARG2LO. Output: SFARG2*. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_2:\n  |  sfi2d SFARG2HI, SFARG2LO\n  |\n  |// Soft-float comparison. Equivalent to c.eq.d.\n  |// Input: SFARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpeq:\n  |.if not FPU\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  xor TMP0, SFARG1HI, SFARG2HI\n  |  xor TMP1, SFARG1LO, SFARG2LO\n  |  or AT, TMP0, TMP1\n  |  jr ra\n  |.  sltiu CRET1, AT, 1\t\t// Same values: return 1.\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ult.d and c.olt.d.\n  |// Input: SFARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1, CRET2.\n  |->vm_sfcmpult:\n  |.if not FPU\n  |  b >1\n  |.  li CRET2, 1\n  |.endif\n  |\n  |->vm_sfcmpolt:\n  |.if not FPU\n  |  li CRET2, 0\n  |1:\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 0.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0 or 1;\n  |.  and AT, SFARG1HI, SFARG2HI\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  beq SFARG1HI, SFARG2HI, >8\n  |.  sltu CRET1, SFARG1LO, SFARG2LO\n  |  jr ra\n  |.  slt CRET1, SFARG1HI, SFARG2HI\n  |5:  // Swap conditions if both operands are negative.\n  |  beq SFARG1HI, SFARG2HI, >8\n  |.  sltu CRET1, SFARG2LO, SFARG1LO\n  |  jr ra\n  |.  slt CRET1, SFARG2HI, SFARG1HI\n  |8:\n  |  jr ra\n  |.  nop\n  |9:\n  |  jr ra\n  |.  move CRET1, CRET2\n  |.endif\n  |\n  |->vm_sfcmpogt:\n  |.if not FPU\n  |  sll AT, SFARG2HI, 1\n  |  sll TMP0, SFARG1HI, 1\n  |  or CRET1, SFARG2LO, SFARG1LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 0.\n  |.  sltu CRET1, r0, SFARG2LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG1LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0 or 1;\n  |.  and AT, SFARG2HI, SFARG1HI\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  beq SFARG2HI, SFARG1HI, >8\n  |.  sltu CRET1, SFARG2LO, SFARG1LO\n  |  jr ra\n  |.  slt CRET1, SFARG2HI, SFARG1HI\n  |5:  // Swap conditions if both operands are negative.\n  |  beq SFARG2HI, SFARG1HI, >8\n  |.  sltu CRET1, SFARG1LO, SFARG2LO\n  |  jr ra\n  |.  slt CRET1, SFARG1HI, SFARG2HI\n  |8:\n  |  jr ra\n  |.  nop\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ole.d a, b or c.ole.d b, a.\n  |// Input: SFARG*, TMP3. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpolex:\n  |.if not FPU\n  |  sll AT, SFARG1HI, 1\n  |  sll TMP0, SFARG2HI, 1\n  |  or CRET1, SFARG1LO, SFARG2LO\n  |  or TMP1, AT, TMP0\n  |  or TMP1, TMP1, CRET1\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  sltu CRET1, r0, SFARG1LO\n  |  lui TMP1, 0xffe0\n  |  addu AT, AT, CRET1\n  |   sltu CRET1, r0, SFARG2LO\n  |  sltu AT, TMP1, AT\n  |   addu TMP0, TMP0, CRET1\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  and AT, SFARG1HI, SFARG2HI\n  |  xor AT, AT, TMP3\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  beq SFARG1HI, SFARG2HI, >6\n  |.  sltu CRET1, SFARG2LO, SFARG1LO\n  |  jr ra\n  |.  slt CRET1, SFARG2HI, SFARG1HI\n  |5:  // Swap conditions if both operands are negative.\n  |  beq SFARG1HI, SFARG2HI, >6\n  |.  sltu CRET1, SFARG1LO, SFARG2LO\n  |  slt CRET1, SFARG1HI, SFARG2HI\n  |6:\n  |  jr ra\n  |.  nop\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |.macro sfmin_max, name, fpcall\n  |->vm_sf .. name:\n  |.if JIT and not FPU\n  |  move TMP2, ra\n  |  bal ->fpcall\n  |.  nop\n  |  move TMP0, CRET1\n  |  move SFRETHI, SFARG1HI\n  |   move SFRETLO, SFARG1LO\n  |  move ra, TMP2\n  |  movz SFRETHI, SFARG2HI, TMP0\n  |  jr ra\n  |.  movz SFRETLO, SFARG2LO, TMP0\n  |.endif\n  |.endmacro\n  |\n  |  sfmin_max min, vm_sfcmpolt\n  |  sfmin_max max, vm_sfcmpogt\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.define NEXT_TAB,\t\tTAB:CARG1\n  |.define NEXT_IDX,\t\tCARG2\n  |.define NEXT_ASIZE,\t\tCARG3\n  |.define NEXT_NIL,\t\tCARG4\n  |.define NEXT_TMP0,\t\tr12\n  |.define NEXT_TMP1,\t\tr13\n  |.define NEXT_TMP2,\t\tr14\n  |.define NEXT_RES_VK,\t\tCRET1\n  |.define NEXT_RES_IDX,\tCRET2\n  |.define NEXT_RES_PTR,\tsp\n  |.define NEXT_RES_VAL_I,\t0(sp)\n  |.define NEXT_RES_VAL_IT,\t4(sp)\n  |.define NEXT_RES_KEY_I,\t8(sp)\n  |.define NEXT_RES_KEY_IT,\t12(sp)\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in CRET2.\n  |->vm_next:\n  |.if JIT and ENDIAN_LE\n  |   lw NEXT_ASIZE, NEXT_TAB->asize\n  |  lw NEXT_TMP0, NEXT_TAB->array\n  |    li NEXT_NIL, LJ_TNIL\n  |1:  // Traverse array part.\n  |   sltu AT, NEXT_IDX, NEXT_ASIZE\n  |    sll NEXT_TMP1, NEXT_IDX, 3\n  |   beqz AT, >5\n  |.   addu NEXT_TMP1, NEXT_TMP0, NEXT_TMP1\n  |  lw NEXT_TMP2, 4(NEXT_TMP1)\n  |   sw NEXT_IDX, NEXT_RES_KEY_I\n  |  beq NEXT_TMP2, NEXT_NIL, <1\n  |.  addiu NEXT_IDX, NEXT_IDX, 1\n  |    lw NEXT_TMP0, 0(NEXT_TMP1)\n  |   li AT, LJ_TISNUM\n  |  sw NEXT_TMP2, NEXT_RES_VAL_IT\n  |   sw AT, NEXT_RES_KEY_IT\n  |    sw NEXT_TMP0, NEXT_RES_VAL_I\n  |  move NEXT_RES_VK, NEXT_RES_PTR\n  |  jr ra\n  |.  move NEXT_RES_IDX, NEXT_IDX\n  |\n  |5:  // Traverse hash part.\n  |  subu NEXT_RES_IDX, NEXT_IDX, NEXT_ASIZE\n  |   lw NODE:NEXT_RES_VK, NEXT_TAB->node\n  |    sll NEXT_TMP2, NEXT_RES_IDX, 5\n  |  lw NEXT_TMP0, NEXT_TAB->hmask\n  |    sll AT, NEXT_RES_IDX, 3\n  |    subu AT, NEXT_TMP2, AT\n  |   addu NODE:NEXT_RES_VK, NODE:NEXT_RES_VK, AT\n  |6:\n  |  sltu AT, NEXT_TMP0, NEXT_RES_IDX\n  |  bnez AT, >8\n  |.  nop\n  |  lw NEXT_TMP2, NODE:NEXT_RES_VK->val.it\n  |  bne NEXT_TMP2, NEXT_NIL, >9\n  |.  addiu NEXT_RES_IDX, NEXT_RES_IDX, 1\n  |  // Skip holes in hash part.\n  |  b <6\n  |.  addiu NODE:NEXT_RES_VK, NODE:NEXT_RES_VK, sizeof(Node)\n  |\n  |8:  // End of iteration. Set the key to nil (not the value).\n  |  sw NEXT_NIL, NEXT_RES_KEY_IT\n  |  move NEXT_RES_VK, NEXT_RES_PTR\n  |9:\n  |  jr ra\n  |.  addu NEXT_RES_IDX, NEXT_RES_IDX, NEXT_ASIZE\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in r1, g in r2.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  lw CTSTATE, GL:r2->ctype_state\n  |   addiu DISPATCH, r2, GG_G2DISP\n  |  load_got lj_ccallback_enter\n  |  sw r1, CTSTATE->cb.slot\n  |  sw CARG1, CTSTATE->cb.gpr[0]\n  |  sw CARG2, CTSTATE->cb.gpr[1]\n  |   .FPU sdc1 FARG1, CTSTATE->cb.fpr[0]\n  |  sw CARG3, CTSTATE->cb.gpr[2]\n  |  sw CARG4, CTSTATE->cb.gpr[3]\n  |   .FPU sdc1 FARG2, CTSTATE->cb.fpr[1]\n  |  addiu TMP0, sp, CFRAME_SPACE+16\n  |  sw TMP0, CTSTATE->cb.stack\n  |  sw r0, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   move CARG2, sp\n  |  call_intern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |.  move CARG1, CTSTATE\n  |  // Returns lua_State *.\n  |  lw BASE, L:CRET1->base\n  |  lw RC, L:CRET1->top\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   move L, CRET1\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  lw LFUNC:RB, FRAME_FUNC(BASE)\n  |     .FPU mtc1 TMP3, TOBIT\n  |    li_vmstate INTERP\n  |     li TISNIL, LJ_TNIL\n  |  subu RC, RC, BASE\n  |    st_vmstate\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  load_got lj_ccallback_leave\n  |  lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)\n  |   sw BASE, L->base\n  |   sw RB, L->top\n  |  sw L, CTSTATE->L\n  |  move CARG2, RA\n  |  call_intern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |.  move CARG1, CTSTATE\n  |   .FPU ldc1 FRET1, CTSTATE->cb.fpr[0]\n  |  lw CRET1, CTSTATE->cb.gpr[0]\n  |   .FPU ldc1 FRET2, CTSTATE->cb.fpr[1]\n  |  b ->vm_leave_unw\n  |.  lw CRET2, CTSTATE->cb.gpr[1]\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, CARG1\n  |  lw TMP1, CCSTATE->spadj\n  |   lbu CARG2, CCSTATE->nsp\n  |  move TMP2, sp\n  |  subu sp, sp, TMP1\n  |  sw ra, -4(TMP2)\n  |   sll CARG2, CARG2, 2\n  |  sw r16, -8(TMP2)\n  |  sw CCSTATE, -12(TMP2)\n  |  move r16, TMP2\n  |  addiu TMP1, CCSTATE, offsetof(CCallState, stack)\n  |  addiu TMP2, sp, 16\n  |  beqz CARG2, >2\n  |.  addu TMP3, TMP1, CARG2\n  |1:\n  |   lw TMP0, 0(TMP1)\n  |  addiu TMP1, TMP1, 4\n  |  sltu AT, TMP1, TMP3\n  |   sw TMP0, 0(TMP2)\n  |  bnez AT, <1\n  |.  addiu TMP2, TMP2, 4\n  |2:\n  |  lw CFUNCADDR, CCSTATE->func\n  |  lw CARG2, CCSTATE->gpr[1]\n  |  lw CARG3, CCSTATE->gpr[2]\n  |  lw CARG4, CCSTATE->gpr[3]\n  |  .FPU ldc1 FARG1, CCSTATE->fpr[0]\n  |  .FPU ldc1 FARG2, CCSTATE->fpr[1]\n  |  jalr CFUNCADDR\n  |.  lw CARG1, CCSTATE->gpr[0]\t\t// Do this last, since CCSTATE is CARG1.\n  |  lw CCSTATE:TMP1, -12(r16)\n  |  lw TMP2, -8(r16)\n  |  lw ra, -4(r16)\n  |  sw CRET1, CCSTATE:TMP1->gpr[0]\n  |  sw CRET2, CCSTATE:TMP1->gpr[1]\n  |.if FPU\n  |  sdc1 FRET1, CCSTATE:TMP1->fpr[0]\n  |  sdc1 FRET2, CCSTATE:TMP1->fpr[1]\n  |.else\n  |  sw CARG1, CCSTATE:TMP1->gpr[2]\t// Soft-float: complex double .im part.\n  |  sw CARG2, CCSTATE:TMP1->gpr[3]\n  |.endif\n  |  move sp, r16\n  |  jr ra\n  |.  move r16, TMP2\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.macro bc_comp, FRA, FRD, RAHI, RALO, RDHI, RDLO, movop, fmovop, fcomp, sfcomp\n    |  addu RA, BASE, RA\n    |   addu RD, BASE, RD\n    |  lw RAHI, HI(RA)\n    |   lw RDHI, HI(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |    addiu PC, PC, 4\n    |  bne RAHI, TISNUM, >2\n    |.  lw RALO, LO(RA)\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  lw RDLO, LO(RD)\n    |  bne RDHI, TISNUM, >5\n    |.   decode_RD4b TMP2\n    |  slt AT, SFARG1LO, SFARG2LO\n    |    addu TMP2, TMP2, TMP3\n    |  movop TMP2, r0, AT\n    |1:\n    |  addu PC, PC, TMP2\n    |  ins_next\n    |\n    |2:  // RA is not an integer.\n    |  sltiu AT, RAHI, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |.   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sltiu AT, RDHI, LJ_TISNUM\n    |.if FPU\n    |  ldc1 FRA, 0(RA)\n    |   ldc1 FRD, 0(RD)\n    |.else\n    |   lw RDLO, LO(RD)\n    |.endif\n    |  beqz AT, >4\n    |.   decode_RD4b TMP2\n    |3:  // RA and RD are both numbers.\n    |.if FPU\n    |  fcomp f20, f22\n    |   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.  fmovop TMP2, r0\n    |.else\n    |  bal sfcomp\n    |.   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.  movop TMP2, r0, CRET1\n    |.endif\n    |\n    |4:  // RA is a number, RD is not a number.\n    |  bne RDHI, TISNUM, ->vmeta_comp\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 FRD, LO(RD)\n    |  b <3\n    |.  cvt.d.w FRD, FRD\n    |.else\n    |.  nop\n    |.if \"RDHI\" == \"SFARG1HI\"\n    |  bal ->vm_sfi2d_1\n    |.else\n    |  bal ->vm_sfi2d_2\n    |.endif\n    |.  nop\n    |  b <3\n    |.  nop\n    |.endif\n    |\n    |5:  // RA is an integer, RD is not an integer\n    |  sltiu AT, RDHI, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |.  mtc1 RALO, FRA\n    |   ldc1 FRD, 0(RD)\n    |  b <3\n    |   cvt.d.w FRA, FRA\n    |.else\n    |.  nop\n    |.if \"RAHI\" == \"SFARG1HI\"\n    |  bal ->vm_sfi2d_1\n    |.else\n    |  bal ->vm_sfi2d_2\n    |.endif\n    |.  nop\n    |  b <3\n    |.  nop\n    |.endif\n    |.endmacro\n    |\n    if (op == BC_ISLT) {\n      |  bc_comp f20, f22, SFARG1HI, SFARG1LO, SFARG2HI, SFARG2LO, movz, movf, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISGE) {\n      |  bc_comp f20, f22, SFARG1HI, SFARG1LO, SFARG2HI, SFARG2LO, movn, movt, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISLE) {\n      |  bc_comp f22, f20, SFARG2HI, SFARG2LO, SFARG1HI, SFARG1LO, movn, movt, c.ult.d, ->vm_sfcmpult\n    } else {\n      |  bc_comp f22, f20, SFARG2HI, SFARG2LO, SFARG1HI, SFARG1LO, movz, movf, c.ult.d, ->vm_sfcmpult\n    }\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |  addu RA, BASE, RA\n    |    addiu PC, PC, 4\n    |  addu RD, BASE, RD\n    |  lw SFARG1HI, HI(RA)\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |  lw SFARG2HI, HI(RD)\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sltu AT, TISNUM, SFARG1HI\n    |  sltu TMP0, TISNUM, SFARG2HI\n    |  or AT, AT, TMP0\n    if (vk) {\n      |  beqz AT, ->BC_ISEQN_Z\n    } else {\n      |  beqz AT, ->BC_ISNEN_Z\n    }\n    |.   decode_RD4b TMP2\n    |  // Either or both types are not numbers.\n    |  lw SFARG1LO, LO(RA)\n    |  lw SFARG2LO, LO(RD)\n    |  addu TMP2, TMP2, TMP3\n    |.if FFI\n    |  li TMP3, LJ_TCDATA\n    |  beq SFARG1HI, TMP3, ->vmeta_equal_cd\n    |.endif\n    |.  sltiu AT, SFARG1HI, LJ_TISPRI\t\t// Not a primitive?\n    |.if FFI\n    |  beq SFARG2HI, TMP3, ->vmeta_equal_cd\n    |.endif\n    |.  xor TMP3, SFARG1LO, SFARG2LO\t\t// Same tv?\n    |  xor SFARG2HI, SFARG2HI, SFARG1HI\t\t// Same type?\n    |  sltiu TMP0, SFARG1HI, LJ_TISTABUD+1\t// Table or userdata?\n    |  movz TMP3, r0, AT\t\t\t// Ignore tv if primitive.\n    |  movn TMP0, r0, SFARG2HI\t\t\t// Tab/ud and same type?\n    |  or AT, SFARG2HI, TMP3\t\t\t// Same type && (pri||same tv).\n    |  movz TMP0, r0, AT\n    |  beqz TMP0, >1\t// Done if not tab/ud or not same type or same tv.\n    if (vk) {\n      |.  movn TMP2, r0, AT\n    } else {\n      |.  movz TMP2, r0, AT\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |  lw TAB:TMP1, TAB:SFARG1LO->metatable\n    |  beqz TAB:TMP1, >1\t\t// No metatable?\n    |.  nop\n    |  lbu TMP1, TAB:TMP1->nomm\n    |  andi TMP1, TMP1, 1<<MM_eq\n    |  bnez TMP1, >1\t\t\t// Or 'no __eq' flag set?\n    |.  nop\n    |  b ->vmeta_equal\t\t\t// Handle __eq metamethod.\n    |.  li TMP0, 1-vk\t\t\t// ne = 0 or 1.\n    |1:\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target\n    |  addu RA, BASE, RA\n    |   addiu PC, PC, 4\n    |  lw TMP0, HI(RA)\n    |   srl RD, RD, 1\n    |  lw STR:TMP3, LO(RA)\n    |   subu RD, KBASE, RD\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |.if FFI\n    |  li AT, LJ_TCDATA\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  lw STR:TMP1, -4(RD)\t\t// KBASE-4-str_const*4\n    |  addiu TMP0, TMP0, -LJ_TSTR\n    |   decode_RD4b TMP2\n    |  xor TMP1, STR:TMP1, STR:TMP3\n    |  or TMP0, TMP0, TMP1\n    |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |   addu TMP2, TMP2, TMP3\n    if (vk) {\n      |  movn TMP2, r0, TMP0\n    } else {\n      |  movz TMP2, r0, TMP0\n    }\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RD = num_const*8, JMP with RD = target\n    |  addu RA, BASE, RA\n    |   addu RD, KBASE, RD\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG2HI, HI(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |    addiu PC, PC, 4\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |    decode_RD4b TMP2\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  bne SFARG1HI, TISNUM, >3\n    |.  lw SFARG1LO, LO(RA)\n    |  lw SFARG2LO, LO(RD)\n    |    addu TMP2, TMP2, TMP3\n    |  bne SFARG2HI, TISNUM, >6\n    |.  xor AT, SFARG1LO, SFARG2LO\n    if (vk) {\n      |  movn TMP2, r0, AT\n      |1:\n      |  addu PC, PC, TMP2\n      |2:\n    } else {\n      |  movz TMP2, r0, AT\n      |1:\n      |2:\n      |  addu PC, PC, TMP2\n    }\n    |  ins_next\n    |\n    |3:  // RA is not an integer.\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |.if FFI\n    |  beqz AT, >8\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |.   addu TMP2, TMP2, TMP3\n    |  sltiu AT, SFARG2HI, LJ_TISNUM\n    |.if FPU\n    |  ldc1 f20, 0(RA)\n    |   ldc1 f22, 0(RD)\n    |.endif\n    |  beqz AT, >5\n    |.  lw SFARG2LO, LO(RD)\n    |4:  // RA and RD are both numbers.\n    |.if FPU\n    |  c.eq.d f20, f22\n    |  b <1\n    if (vk) {\n      |.  movf TMP2, r0\n    } else {\n      |.  movt TMP2, r0\n    }\n    |.else\n    |  bal ->vm_sfcmpeq\n    |.  nop\n    |  b <1\n    if (vk) {\n      |.  movz TMP2, r0, CRET1\n    } else {\n      |.  movn TMP2, r0, CRET1\n    }\n    |.endif\n    |\n    |5:  // RA is a number, RD is not a number.\n    |.if FFI\n    |  bne SFARG2HI, TISNUM, >9\n    |.else\n    |  bne SFARG2HI, TISNUM, <2\n    |.endif\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 f22, LO(RD)\n    |  b <4\n    |.  cvt.d.w f22, f22\n    |.else\n    |.  nop\n    |  bal ->vm_sfi2d_2\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |6:  // RA is an integer, RD is not an integer\n    |  sltiu AT, SFARG2HI, LJ_TISNUM\n    |.if FFI\n    |  beqz AT, >9\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |.  mtc1 SFARG1LO, f20\n    |   ldc1 f22, 0(RD)\n    |  b <4\n    |   cvt.d.w f20, f20\n    |.else\n    |.  nop\n    |  bal ->vm_sfi2d_1\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |.if FFI\n    |8:\n    |  li AT, LJ_TCDATA\n    |  bne SFARG1HI, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |9:\n    |  li AT, LJ_TCDATA\n    |  bne SFARG2HI, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target\n    |  addu RA, BASE, RA\n    |   srl TMP1, RD, 3\n    |  lw TMP0, HI(RA)\n    |    lhu TMP2, OFS_RD(PC)\n    |   not TMP1, TMP1\n    |    addiu PC, PC, 4\n    |.if FFI\n    |  li AT, LJ_TCDATA\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  xor TMP0, TMP0, TMP1\n    |  decode_RD4b TMP2\n    |  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  addu TMP2, TMP2, TMP3\n    if (vk) {\n      |  movn TMP2, r0, TMP0\n    } else {\n      |  movz TMP2, r0, TMP0\n    }\n    |  addu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target\n    |  addu RD, BASE, RD\n    |   lhu TMP2, OFS_RD(PC)\n    |  lw TMP0, HI(RD)\n    |   addiu PC, PC, 4\n    if (op == BC_IST || op == BC_ISF) {\n      |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      if (op == BC_IST) {\n\t|  movz TMP2, r0, TMP0\n      } else {\n\t|  movn TMP2, r0, TMP0\n      }\n      |  addu PC, PC, TMP2\n    } else {\n      |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n      |  lw SFRETHI, HI(RD)\n      |   lw SFRETLO, LO(RD)\n      if (op == BC_ISTC) {\n\t|  beqz TMP0, >1\n      } else {\n\t|  bnez TMP0, >1\n      }\n      |.  addu RA, BASE, RA\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      |  sw SFRETHI, HI(RA)\n      |   sw SFRETLO, LO(RA)\n      |   addu PC, PC, TMP2\n      |1:\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RD = -type*8\n    |  addu TMP2, BASE, RA\n    |  srl TMP1, RD, 3\n    |  lw TMP0, HI(TMP2)\n    |  ins_next1\n    |  addu AT, TMP0, TMP1\n    |  bnez AT, ->vmeta_istype\n    |.  ins_next2\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RD = -(TISNUM-1)*8\n    |  addu TMP2, BASE, RA\n    |  lw TMP0, HI(TMP2)\n    |  ins_next1\n    |  sltiu AT, TMP0, LJ_TISNUM\n    |  beqz AT, ->vmeta_istype\n    |.  ins_next2\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RD = src*8\n    |  addu RD, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw SFRETHI, HI(RD)\n    |   lw SFRETLO, LO(RD)\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RD = src*8\n    |  addu RD, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw TMP0, HI(RD)\n    |   li TMP1, LJ_TFALSE\n    |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n    |  addiu TMP1, TMP0, LJ_TTRUE\n    |  ins_next1\n    |  sw TMP1, HI(RA)\n    |  ins_next2\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RD = src*8\n    |  addu RB, BASE, RD\n    |  lw SFARG1HI, HI(RB)\n    |   addu RA, BASE, RA\n    |  bne SFARG1HI, TISNUM, >2\n    |.  lw SFARG1LO, LO(RB)\n    |  lui TMP1, 0x8000\n    |  beq SFARG1LO, TMP1, ->vmeta_unm\t// Meta handler deals with -2^31.\n    |.  negu SFARG1LO, SFARG1LO\n    |1:\n    |  ins_next1\n    |  sw SFARG1HI, HI(RA)\n    |   sw SFARG1LO, LO(RA)\n    |  ins_next2\n    |2:\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |  beqz AT, ->vmeta_unm\n    |.  lui TMP1, 0x8000\n    |  b <1\n    |.  xor SFARG1HI, SFARG1HI, TMP1\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RD = src*8\n    |  addu CARG2, BASE, RD\n    |   addu RA, BASE, RA\n    |  lw TMP0, HI(CARG2)\n    |   lw CARG1, LO(CARG2)\n    |  li AT, LJ_TSTR\n    |  bne TMP0, AT, >2\n    |.  li AT, LJ_TTAB\n    |   lw CRET1, STR:CARG1->len\n    |1:\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw CRET1, LO(RA)\n    |  ins_next2\n    |2:\n    |  bne TMP0, AT, ->vmeta_len\n    |.  nop\n#if LJ_52\n    |  lw TAB:TMP2, TAB:CARG1->metatable\n    |  bnez TAB:TMP2, >9\n    |.  nop\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  load_got lj_tab_len\n    |  call_intern lj_tab_len\t\t// (GCtab *t)\n    |.  nop\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n    |.  nop\n#if LJ_52\n    |9:\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_len\n    |  bnez TMP0, <3\t\t\t// 'no __len' flag set: done.\n    |.  nop\n    |  b ->vmeta_len\n    |.  nop\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro fpmod, a, b, c\n    |  bal ->vm_floor     // floor(b/c)\n    |.  div.d FARG1, b, c\n    |  mul.d a, FRET1, c\n    |  sub.d a, b, a      // b - floor(b/c)*c\n    |.endmacro\n\n    |.macro sfpmod\n    |  addiu sp, sp, -16\n    |\n    |  load_got __divdf3\n    |  sw SFARG1HI, HI(sp)\n    |   sw SFARG1LO, LO(sp)\n    |  sw SFARG2HI, 8+HI(sp)\n    |  call_extern\n    |.  sw SFARG2LO, 8+LO(sp)\n    |\n    |  load_got floor\n    |  move SFARG1HI, SFRETHI\n    |  call_extern\n    |.  move SFARG1LO, SFRETLO\n    |\n    |  load_got __muldf3\n    |  move SFARG1HI, SFRETHI\n    |   move SFARG1LO, SFRETLO\n    |  lw SFARG2HI, 8+HI(sp)\n    |  call_extern\n    |.  lw SFARG2LO, 8+LO(sp)\n    |\n    |  load_got __subdf3\n    |  lw SFARG1HI, HI(sp)\n    |   lw SFARG1LO, LO(sp)\n    |  move SFARG2HI, SFRETHI\n    |  call_extern\n    |.  move SFARG2LO, SFRETLO\n    |\n    |  addiu sp, sp, 16\n    |.endmacro\n\n    |.macro ins_arithpre, label\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||switch (vk) {\n    ||case 0:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = num_const*8\n    |   addu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RC, KBASE, RC\n    ||  break;\n    ||case 1:\n    |   decode_RB8a RC, INS\n    |   decode_RB8b RC\n    |    decode_RDtoRC8 RB, RD\n    |   // RA = dst*8, RB = num_const*8, RC = src1*8\n    |   addu RC, BASE, RC\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RB, KBASE, RB\n    ||  break;\n    ||default:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = src2*8\n    |   addu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   addu RC, BASE, RC\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arith, intins, fpins, fpcall, label\n    |  ins_arithpre none\n    |\n    |.if \"label\" ~= \"none\"\n    |label:\n    |.endif\n    |\n    |  lw SFARG1HI, HI(RB)\n    |   lw SFARG2HI, HI(RC)\n    |\n    |.if \"intins\" ~= \"div\"\n    |\n    |  // Check for two integers.\n    |  lw SFARG1LO, LO(RB)\n    |  bne SFARG1HI, TISNUM, >5\n    |.  lw SFARG2LO, LO(RC)\n    |  bne SFARG2HI, TISNUM, >5\n    |\n    |.if \"intins\" == \"addu\"\n    |.  intins CRET1, SFARG1LO, SFARG2LO\n    |  xor TMP1, CRET1, SFARG1LO\t// ((y^a) & (y^b)) < 0: overflow.\n    |  xor TMP2, CRET1, SFARG2LO\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.elif \"intins\" == \"subu\"\n    |.  intins CRET1, SFARG1LO, SFARG2LO\n    |  xor TMP1, CRET1, SFARG1LO\t// ((y^a) & (a^b)) < 0: overflow.\n    |  xor TMP2, SFARG1LO, SFARG2LO\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.elif \"intins\" == \"mult\"\n    |.  intins SFARG1LO, SFARG2LO\n    |  mflo CRET1\n    |  mfhi TMP2\n    |  sra TMP1, CRET1, 31\n    |  bne TMP1, TMP2, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.else\n    |.  load_got lj_vm_modi\n    |  beqz SFARG2LO, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.if ENDIAN_BE\n    |  move CARG1, SFARG1LO\n    |.endif\n    |  call_extern\n    |.  move CARG2, SFARG2LO\n    |.endif\n    |\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw CRET1, LO(RA)\n    |3:\n    |  ins_next2\n    |\n    |.elif not FPU\n    |\n    |  lw SFARG1LO, LO(RB)\n    |   lw SFARG2LO, LO(RC)\n    |\n    |.endif\n    |\n    |5:  // Check for two numbers.\n    |  .FPU ldc1 f20, 0(RB)\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |   sltiu TMP0, SFARG2HI, LJ_TISNUM\n    |  .FPU ldc1 f22, 0(RC)\n    |   and AT, AT, TMP0\n    |   beqz AT, ->vmeta_arith\n    |.   addu RA, BASE, RA\n    |\n    |.if FPU\n    |  fpins FRET1, f20, f22\n    |.elif \"fpcall\" == \"sfpmod\"\n    |  sfpmod\n    |.else\n    |  load_got fpcall\n    |  call_extern\n    |.  nop\n    |.endif\n    |\n    |  ins_next1\n    |.if not FPU\n    |  sw SFRETHI, HI(RA)\n    |.endif\n    |.if \"intins\" ~= \"div\"\n    |  b <3\n    |.endif\n    |.if FPU\n    |.  sdc1 FRET1, 0(RA)\n    |.else\n    |.  sw SFRETLO, LO(RA)\n    |.endif\n    |.if \"intins\" == \"div\"\n    |  ins_next2\n    |.endif\n    |\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith addu, add.d, __adddf3, none\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith subu, sub.d, __subdf3, none\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith mult, mul.d, __muldf3, none\n    break;\n  case BC_DIVVN:\n    |  ins_arith div, div.d, __divdf3, ->BC_DIVVN_Z\n    break;\n  case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithpre ->BC_DIVVN_Z\n    break;\n  case BC_MODVN:\n    |  ins_arith modi, fpmod, sfpmod, ->BC_MODVN_Z\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre ->BC_MODVN_Z\n    break;\n  case BC_POW:\n    |  ins_arithpre none\n    |  lw SFARG1HI, HI(RB)\n    |   lw SFARG2HI, HI(RC)\n    |  sltiu AT, SFARG1HI, LJ_TISNUM\n    |  sltiu TMP0, SFARG2HI, LJ_TISNUM\n    |  and AT, AT, TMP0\n    |  load_got pow\n    |  beqz AT, ->vmeta_arith\n    |.  addu RA, BASE, RA\n    |.if FPU\n    |  ldc1 FARG1, 0(RB)\n    |  ldc1 FARG2, 0(RC)\n    |.else\n    |  lw SFARG1LO, LO(RB)\n    |   lw SFARG2LO, LO(RC)\n    |.endif\n    |  call_extern\n    |.  nop\n    |  ins_next1\n    |.if FPU\n    |  sdc1 FRET1, 0(RA)\n    |.else\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  case BC_CAT:\n    |  // RA = dst*8, RB = src_start*8, RC = src_end*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  subu CARG3, RC, RB\n    |   sw BASE, L->base\n    |  addu CARG2, BASE, RC\n    |  move MULTRES, RB\n    |->BC_CAT_Z:\n    |  load_got lj_meta_cat\n    |  srl CARG3, CARG3, 3\n    |   sw PC, SAVE_PC\n    |  call_intern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |.  move CARG1, L\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  bnez CRET1, ->vmeta_binop\n    |.  lw BASE, L->base\n    |  addu RB, BASE, MULTRES\n    |  lw SFRETHI, HI(RB)\n    |   lw SFRETLO, LO(RB)\n    |   addu RA, BASE, RA\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RD = str_const*8 (~)\n    |  srl TMP1, RD, 1\n    |  subu TMP1, KBASE, TMP1\n    |  ins_next1\n    |  lw TMP0, -4(TMP1)\t\t// KBASE-4-str_const*4\n    |  addu RA, BASE, RA\n    |   li TMP2, LJ_TSTR\n    |  sw TMP0, LO(RA)\n    |   sw TMP2, HI(RA)\n    |  ins_next2\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RD = cdata_const*8 (~)\n    |  srl TMP1, RD, 1\n    |  subu TMP1, KBASE, TMP1\n    |  ins_next1\n    |  lw TMP0, -4(TMP1)\t\t// KBASE-4-cdata_const*4\n    |  addu RA, BASE, RA\n    |   li TMP2, LJ_TCDATA\n    |  sw TMP0, LO(RA)\n    |   sw TMP2, HI(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, RD = int16_literal*8\n    |  sra RD, INS, 16\n    |  addu RA, BASE, RA\n    |  ins_next1\n    |  sw TISNUM, HI(RA)\n    |   sw RD, LO(RA)\n    |  ins_next2\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RD = num_const*8\n    |  addu RD, KBASE, RD\n    |   addu RA, BASE, RA\n    |  lw SFRETHI, HI(RD)\n    |   lw SFRETLO, LO(RD)\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RD = primitive_type*8 (~)\n    |  srl TMP1, RD, 3\n    |   addu RA, BASE, RA\n    |  not TMP0, TMP1\n    |  ins_next1\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RD = end*8\n    |  addu RA, BASE, RA\n    |  sw TISNIL, HI(RA)\n    |   addiu RA, RA, 8\n    |  addu RD, BASE, RD\n    |1:\n    |  sw TISNIL, HI(RA)\n    |  slt AT, RA, RD\n    |  bnez AT, <1\n    |.  addiu RA, RA, 8\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RD = uvnum*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RD, RD, 1\n    |   addu RD, RD, LFUNC:RB\n    |  lw UPVAL:RB, LFUNC:RD->uvptr\n    |  ins_next1\n    |  lw TMP1, UPVAL:RB->v\n    |  lw SFRETHI, HI(TMP1)\n    |   lw SFRETLO, LO(TMP1)\n    |  addu RA, BASE, RA\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RD = src*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |    srl RA, RA, 1\n    |   addu RD, BASE, RD\n    |    addu RA, RA, LFUNC:RB\n    |  lw UPVAL:RB, LFUNC:RA->uvptr\n    |   lw SFRETHI, HI(RD)\n    |    lw SFRETLO, LO(RD)\n    |  lbu TMP3, UPVAL:RB->marked\n    |   lw CARG2, UPVAL:RB->v\n    |  andi TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |  lbu TMP0, UPVAL:RB->closed\n    |   sw SFRETHI, HI(CARG2)\n    |    sw SFRETLO, LO(CARG2)\n    |  li AT, LJ_GC_BLACK|1\n    |  or TMP3, TMP3, TMP0\n    |  beq TMP3, AT, >2\t\t\t// Upvalue is closed and black?\n    |.  addiu TMP2, SFRETHI, -(LJ_TNUMX+1)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)\n    |  beqz AT, <1\t\t\t// tvisgcv(v)\n    |.  nop\n    |  lbu TMP3, GCOBJ:SFRETLO->gch.marked\n    |  andi TMP3, TMP3, LJ_GC_WHITES\t// iswhite(v)\n    |  beqz TMP3, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  addiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RD = str_const*8 (~)\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |    srl RA, RA, 1\n    |   srl TMP1, RD, 1\n    |    addu RA, RA, LFUNC:RB\n    |   subu TMP1, KBASE, TMP1\n    |  lw UPVAL:RB, LFUNC:RA->uvptr\n    |   lw STR:TMP1, -4(TMP1)\t\t// KBASE-4-str_const*4\n    |  lbu TMP2, UPVAL:RB->marked\n    |   lw CARG2, UPVAL:RB->v\n    |   lbu TMP3, STR:TMP1->marked\n    |  andi AT, TMP2, LJ_GC_BLACK\t// isblack(uv)\n    |   lbu TMP2, UPVAL:RB->closed\n    |   li TMP0, LJ_TSTR\n    |   sw STR:TMP1, LO(CARG2)\n    |  bnez AT, >2\n    |.  sw TMP0, HI(CARG2)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  beqz TMP2, <1\n    |.  andi AT, TMP3, LJ_GC_WHITES\t// iswhite(str)\n    |  beqz AT, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  addiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RD = num_const*8\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RA, RA, 1\n    |    addu RD, KBASE, RD\n    |   addu RA, RA, LFUNC:RB\n    |   lw UPVAL:RB, LFUNC:RA->uvptr\n    |    lw SFRETHI, HI(RD)\n    |     lw SFRETLO, LO(RD)\n    |   lw TMP1, UPVAL:RB->v\n    |  ins_next1\n    |    sw SFRETHI, HI(TMP1)\n    |     sw SFRETLO, LO(TMP1)\n    |  ins_next2\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RD = primitive_type*8 (~)\n    |  lw LFUNC:RB, FRAME_FUNC(BASE)\n    |   srl RA, RA, 1\n    |    srl TMP0, RD, 3\n    |   addu RA, RA, LFUNC:RB\n    |    not TMP0, TMP0\n    |   lw UPVAL:RB, LFUNC:RA->uvptr\n    |  ins_next1\n    |   lw TMP1, UPVAL:RB->v\n    |   sw TMP0, HI(TMP1)\n    |  ins_next2\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RD = target\n    |  lw TMP2, L->openupval\n    |  branch_RD\t\t\t// Do this first since RD is not saved.\n    |  load_got lj_func_closeuv\n    |   sw BASE, L->base\n    |  beqz TMP2, >1\n    |.  move CARG1, L\n    |  call_intern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |.  addu CARG2, BASE, RA\n    |  lw BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)\n    |  srl TMP1, RD, 1\n    |  load_got lj_func_newL_gc\n    |  subu TMP1, KBASE, TMP1\n    |  lw CARG3, FRAME_FUNC(BASE)\n    |  lw CARG2, -4(TMP1)\t\t// KBASE-4-tab_const*4\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call_intern lj_func_newL_gc\n    |.  move CARG1, L\n    |  // Returns GCfuncL *.\n    |  lw BASE, L->base\n    |   li TMP0, LJ_TFUNC\n    |  ins_next1\n    |  addu RA, BASE, RA\n    |  sw LFUNC:CRET1, LO(RA)\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)\n    |  lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n    |  lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, >5\n    |1:\n    if (op == BC_TNEW) {\n      |  load_got lj_tab_new\n      |  srl CARG2, RD, 3\n      |  andi CARG2, CARG2, 0x7ff\n      |  li TMP0, 0x801\n      |  addiu AT, CARG2, -0x7ff\n      |   srl CARG3, RD, 14\n      |  movz CARG2, TMP0, AT\n      |  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  call_intern lj_tab_new\n      |.  move CARG1, L\n      |  // Returns Table *.\n    } else {\n      |  load_got lj_tab_dup\n      |  srl TMP1, RD, 1\n      |  subu TMP1, KBASE, TMP1\n      |  move CARG1, L\n      |  call_intern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n      |.  lw CARG2, -4(TMP1)\t\t// KBASE-4-str_const*4\n      |  // Returns Table *.\n    }\n    |  lw BASE, L->base\n    |  ins_next1\n    |  addu RA, BASE, RA\n    |   li TMP0, LJ_TTAB\n    |  sw TAB:CRET1, LO(RA)\n    |   sw TMP0, HI(RA)\n    |  ins_next2\n    |5:\n    |  load_got lj_gc_step_fixtop\n    |  move MULTRES, RD\n    |  call_intern lj_gc_step_fixtop\t// (lua_State *L)\n    |.  move CARG1, L\n    |  b <1\n    |.  move RD, MULTRES\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RD = str_const*8 (~)\n  case BC_GSET:\n    |  // RA = src*8, RD = str_const*8 (~)\n    |  lw LFUNC:TMP2, FRAME_FUNC(BASE)\n    |   srl TMP1, RD, 1\n    |   subu TMP1, KBASE, TMP1\n    |  lw TAB:RB, LFUNC:TMP2->env\n    |  lw STR:RC, -4(TMP1)\t\t// KBASE-4-str_const*4\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    |.  addu RA, BASE, RA\n    break;\n\n  case BC_TGETV:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG2, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TMP1, HI(CARG2)\n    |   lw TMP2, HI(CARG3)\n    |    lw TAB:RB, LO(CARG2)\n    |  li AT, LJ_TTAB\n    |  bne TMP1, AT, ->vmeta_tgetv\n    |.  addu RA, BASE, RA\n    |  bne TMP2, TISNUM, >5\n    |.  lw RC, LO(CARG3)\n    |  lw TMP0, TAB:RB->asize\n    |   lw TMP1, TAB:RB->array\n    |  sltu AT, RC, TMP0\n    |   sll TMP2, RC, 3\n    |  beqz AT, ->vmeta_tgetv\t\t// Integer key and in array part?\n    |.  addu TMP2, TMP1, TMP2\n    |  lw SFRETHI, HI(TMP2)\n    |  beq SFRETHI, TISNIL, >2\n    |.  lw SFRETLO, LO(TMP2)\n    |1:\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetv\n    |.  nop\n    |\n    |5:\n    |  li AT, LJ_TSTR\n    |  bne TMP2, AT, ->vmeta_tgetv\n    |.  nop\n    |  b ->BC_TGETS_Z\t\t\t// String key?\n    |.  nop\n    break;\n  case BC_TGETS:\n    |  // RA = dst*8, RB = table*8, RC = str_const*4 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RC4a RC, INS\n    |  lw TMP0, HI(CARG2)\n    |   decode_RC4b RC\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   subu CARG3, KBASE, RC\n    |   lw STR:RC, -4(CARG3)\t\t// KBASE-4-str_const*4\n    |  bne TMP0, AT, ->vmeta_tgets1\n    |.  addu RA, BASE, RA\n    |->BC_TGETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  lw TMP0, TAB:RB->hmask\n    |  lw TMP1, STR:RC->sid\n    |  lw NODE:TMP2, TAB:RB->node\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)\n    |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n    |    lw NODE:TMP1, NODE:TMP2->next\n    |    lw SFRETHI, offsetof(Node, val)+HI(NODE:TMP2)\n    |  addiu CARG1, CARG1, -LJ_TSTR\n    |   xor TMP0, TMP0, STR:RC\n    |  or AT, CARG1, TMP0\n    |  bnez AT, >4\n    |.  lw TAB:TMP3, TAB:RB->metatable\n    |    beq SFRETHI, TISNIL, >5\t// Key found, but nil value?\n    |.    lw SFRETLO, offsetof(Node, val)+LO(NODE:TMP2)\n    |3:\n    |  ins_next1\n    |    sw SFRETHI, HI(RA)\n    |     sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |4:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  beqz TAB:TMP3, <3\t\t// No metatable: done.\n    |.  li SFRETHI, LJ_TNIL\n    |  lbu TMP0, TAB:TMP3->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <3\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgets\n    |.  nop\n    break;\n  case BC_TGETB:\n    |  // RA = dst*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  lw CARG1, HI(CARG2)\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   addu RA, BASE, RA\n    |  bne CARG1, AT, ->vmeta_tgetb\n    |.  srl TMP0, RC, 3\n    |  lw TMP1, TAB:RB->asize\n    |   lw TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tgetb\n    |.  addu RC, TMP2, RC\n    |  lw SFRETHI, HI(RC)\n    |  beq SFRETHI, TISNIL, >5\n    |.  lw SFRETLO, LO(RC)\n    |1:\n    |  ins_next1\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  ins_next2\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_index\n    |  bnez TMP1, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    break;\n  case BC_TGETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu RB, BASE, RB\n    |   addu RC, BASE, RC\n    |  lw TAB:CARG1, LO(RB)\n    |   lw CARG2, LO(RC)\n    |    addu RA, BASE, RA\n    |  lw TMP0, TAB:CARG1->asize\n    |   lw TMP1, TAB:CARG1->array\n    |  sltu AT, CARG2, TMP0\n    |   sll TMP2, CARG2, 3\n    |  beqz AT, ->vmeta_tgetr\t\t// In array part?\n    |.  addu CRET1, TMP1, TMP2\n    |  lw SFARG2HI, HI(CRET1)\n    |   lw SFARG2LO, LO(CRET1)\n    |->BC_TGETR_Z:\n    |  ins_next1\n    |  sw SFARG2HI, HI(RA)\n    |   sw SFARG2LO, LO(RA)\n    |  ins_next2\n    break;\n\n  case BC_TSETV:\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG2, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TMP1, HI(CARG2)\n    |   lw TMP2, HI(CARG3)\n    |    lw TAB:RB, LO(CARG2)\n    |  li AT, LJ_TTAB\n    |  bne TMP1, AT, ->vmeta_tsetv\n    |.  addu RA, BASE, RA\n    |  bne TMP2, TISNUM, >5\n    |.  lw RC, LO(CARG3)\n    |  lw TMP0, TAB:RB->asize\n    |   lw TMP1, TAB:RB->array\n    |  sltu AT, RC, TMP0\n    |   sll TMP2, RC, 3\n    |  beqz AT, ->vmeta_tsetv\t\t// Integer key and in array part?\n    |.  addu TMP1, TMP1, TMP2\n    |  lw TMP0, HI(TMP1)\n    |   lbu TMP3, TAB:RB->marked\n    |  lw SFRETHI, HI(RA)\n    |  beq TMP0, TISNIL, >3\n    |.  lw SFRETLO, LO(RA)\n    |1:\n    |   andi AT, TMP3, LJ_GC_BLACK  // isblack(table)\n    |  sw SFRETHI, HI(TMP1)\n    |  bnez AT, >7\n    |.  sw SFRETLO, LO(TMP1)\n    |2:\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP2, TAB:TMP2->nomm\n    |  andi TMP2, TMP2, 1<<MM_newindex\n    |  bnez TMP2, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetv\n    |.  nop\n    |\n    |5:\n    |  li AT, LJ_TSTR\n    |  bne TMP2, AT, ->vmeta_tsetv\n    |.  nop\n    |  b ->BC_TSETS_Z\t\t\t// String key?\n    |.  nop\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETS:\n    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RC4a RC, INS\n    |  lw TMP0, HI(CARG2)\n    |   decode_RC4b RC\n    |  li AT, LJ_TTAB\n    |   subu CARG3, KBASE, RC\n    |    lw TAB:RB, LO(CARG2)\n    |   lw STR:RC, -4(CARG3)\t\t// KBASE-4-str_const*4\n    |  bne TMP0, AT, ->vmeta_tsets1\n    |.  addu RA, BASE, RA\n    |->BC_TSETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8\n    |  lw TMP0, TAB:RB->hmask\n    |  lw TMP1, STR:RC->sid\n    |  lw NODE:TMP2, TAB:RB->node\n    |   sb r0, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |  addu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |.if FPU\n    |   ldc1 f20, 0(RA)\n    |.else\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |.endif\n    |1:\n    |  lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)\n    |   lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)\n    |  li AT, LJ_TSTR\n    |    lw NODE:TMP1, NODE:TMP2->next\n    |  bne CARG1, AT, >5\n    |.   lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)\n    |   bne TMP0, STR:RC, >5\n    |.    lbu TMP3, TAB:RB->marked\n    |    beq CARG2, TISNIL, >4\t\t// Key found, but nil value?\n    |.    lw TAB:TMP0, TAB:RB->metatable\n    |2:\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |.if FPU\n    |  bnez AT, >7\n    |.  sdc1 f20, NODE:TMP2->val\n    |.else\n    |   sw SFRETHI, NODE:TMP2->val.u32.hi\n    |  bnez AT, >7\n    |.   sw SFRETLO, NODE:TMP2->val.u32.lo\n    |.endif\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  beqz TAB:TMP0, <2\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP0->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  bnez TMP0, <2\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsets\n    |.  nop\n    |\n    |5:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, add a new one\n    |\n    |  // But check for __newindex first.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, >6\t\t// No metatable: continue.\n    |.  addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  beqz TMP0, ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |.  li AT, LJ_TSTR\n    |6:\n    |  load_got lj_tab_newkey\n    |  sw STR:RC, LO(CARG3)\n    |  sw AT, HI(CARG3)\n    |   sw BASE, L->base\n    |  move CARG2, TAB:RB\n    |   sw PC, SAVE_PC\n    |  call_intern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k\n    |.  move CARG1, L\n    |  // Returns TValue *.\n    |  lw BASE, L->base\n    |.if FPU\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sdc1 f20, 0(CRET1)\n    |.else\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG1LO, LO(RA)\n    |  sw SFARG1HI, HI(CRET1)\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sw SFARG1LO, LO(CRET1)\n    |.endif\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <3\n    break;\n  case BC_TSETB:\n    |  // RA = src*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  addu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  lw CARG1, HI(CARG2)\n    |  li AT, LJ_TTAB\n    |   lw TAB:RB, LO(CARG2)\n    |   addu RA, BASE, RA\n    |  bne CARG1, AT, ->vmeta_tsetb\n    |.  srl TMP0, RC, 3\n    |  lw TMP1, TAB:RB->asize\n    |   lw TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tsetb\n    |.  addu RC, TMP2, RC\n    |  lw TMP1, HI(RC)\n    |   lbu TMP3, TAB:RB->marked\n    |  beq TMP1, TISNIL, >5\n    |1:\n    |.  lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |   sw SFRETHI, HI(RC)\n    |  bnez AT, >7\n    |.   sw SFRETLO, LO(RC)\n    |2:\n    |  ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  lw TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_newindex\n    |  bnez TMP1, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  addu CARG1, BASE, RB\n    |   addu CARG3, BASE, RC\n    |  lw TAB:CARG2, LO(CARG1)\n    |   lw CARG3, LO(CARG3)\n    |  lbu TMP3, TAB:CARG2->marked\n    |   lw TMP0, TAB:CARG2->asize\n    |    lw TMP1, TAB:CARG2->array\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.  addu RA, BASE, RA\n    |2:\n    |  sltu AT, CARG3, TMP0\n    |   sll TMP2, CARG3, 3\n    |  beqz AT, ->vmeta_tsetr\t\t// In array part?\n    |.  addu CRET1, TMP1, TMP2\n    |->BC_TSETR_Z:\n    |  lw SFARG1HI, HI(RA)\n    |   lw SFARG1LO, LO(RA)\n    |  ins_next1\n    |  sw SFARG1HI, HI(CRET1)\n    |   sw SFARG1LO, LO(CRET1)\n    |  ins_next2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, CRET1, <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)\n    |  addu RA, BASE, RA\n    |1:\n    |   addu TMP3, KBASE, RD\n    |  lw TAB:CARG2, -8+LO(RA)\t\t// Guaranteed to be a table.\n    |    addiu TMP0, MULTRES, -8\n    |   lw TMP3, LO(TMP3)\t\t// Integer constant is in lo-word.\n    |    beqz TMP0, >4\t\t\t// Nothing to copy?\n    |.    srl CARG3, TMP0, 3\n    |  addu CARG3, CARG3, TMP3\n    |  lw TMP2, TAB:CARG2->asize\n    |   sll TMP1, TMP3, 3\n    |    lbu TMP3, TAB:CARG2->marked\n    |   lw CARG1, TAB:CARG2->array\n    |  sltu AT, TMP2, CARG3\n    |  bnez AT, >5\n    |.  addu TMP2, RA, TMP0\n    |   addu TMP1, TMP1, CARG1\n    |  andi TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |3:  // Copy result slots to table.\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  sltu AT, RA, TMP2\n    |   sw SFRETHI, HI(TMP1)\n    |    sw SFRETLO, LO(TMP1)\n    |  bnez AT, <3\n    |.   addiu TMP1, TMP1, 8\n    |  bnez TMP0, >7\n    |. nop\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  load_got lj_tab_reasize\n    |   sw BASE, L->base\n    |   sw PC, SAVE_PC\n    |  move BASE, RD\n    |  call_intern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |.  move CARG1, L\n    |  // Must not reallocate the stack.\n    |  move RD, BASE\n    |  b <1\n    |.  lw BASE, L->base\t// Reload BASE for lack of a saved register.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP0, <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |  b ->BC_CALL_Z\n    |.  addu NARGS8:RC, NARGS8:RC, MULTRES\n    break;\n  case BC_CALL:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |->BC_CALL_Z:\n    |  move TMP2, BASE\n    |  addu BASE, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP0, HI(BASE)\n    |   lw LFUNC:RB, LO(BASE)\n    |   addiu BASE, BASE, 8\n    |  bne TMP0, AT, ->vmeta_call\n    |.  addiu NARGS8:RC, NARGS8:RC, -8\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8\n    |  addu NARGS8:RD, NARGS8:RD, MULTRES\t// BC_CALLT gets RC from RD.\n    |  // Fall through. Assumes BC_CALLT follows.\n    break;\n  case BC_CALLT:\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |  addu RA, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP0, HI(RA)\n    |   lw LFUNC:RB, LO(RA)\n    |   move NARGS8:RC, RD\n    |    lw TMP1, FRAME_PC(BASE)\n    |   addiu RA, RA, 8\n    |  bne TMP0, AT, ->vmeta_callt\n    |.  addiu NARGS8:RC, NARGS8:RC, -8\n    |->BC_CALLT_Z:\n    |  andi TMP0, TMP1, FRAME_TYPE\t// Caveat: preserve TMP0 until the 'or'.\n    |   lbu TMP3, LFUNC:RB->ffid\n    |  bnez TMP0, >7\n    |.  xori TMP2, TMP1, FRAME_VARG\n    |1:\n    |  sw LFUNC:RB, FRAME_FUNC(BASE)\t// Copy function down, but keep PC.\n    |  sltiu AT, TMP3, 2\t\t// (> FF_C) Calling a fast function?\n    |  move TMP2, BASE\n    |  beqz NARGS8:RC, >3\n    |.  move TMP3, NARGS8:RC\n    |2:\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  addiu TMP3, TMP3, -8\n    |   sw SFRETHI, HI(TMP2)\n    |    sw SFRETLO, LO(TMP2)\n    |  bnez TMP3, <2\n    |.   addiu TMP2, TMP2, 8\n    |3:\n    |  or TMP0, TMP0, AT\n    |  beqz TMP0, >5\n    |.  nop\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  lw INS, -4(TMP1)\n    |  decode_RA8a RA, INS\n    |  decode_RA8b RA\n    |  subu TMP1, BASE, RA\n    |  lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1)\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  b <4\n    |.  lw KBASE, PC2PROTO(k)(TMP1)\t// Need to prepare KBASE.\n    |\n    |7:  // Tailcall from a vararg function.\n    |  andi AT, TMP2, FRAME_TYPEP\n    |  bnez AT, <1\t\t\t// Vararg frame below?\n    |.  subu TMP2, BASE, TMP2\t\t// Relocate BASE down.\n    |  move BASE, TMP2\n    |  lw TMP1, FRAME_PC(TMP2)\n    |  b <1\n    |.  andi TMP0, TMP1, FRAME_TYPE\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))\n    |  move TMP2, BASE\n    |  addu BASE, BASE, RA\n    |   li AT, LJ_TFUNC\n    |  lw TMP1, -24+HI(BASE)\n    |   lw LFUNC:RB, -24+LO(BASE)\n    |    lw SFARG1HI, -16+HI(BASE)\n    |     lw SFARG1LO, -16+LO(BASE)\n    |    lw SFARG2HI, -8+HI(BASE)\n    |     lw SFARG2LO, -8+LO(BASE)\n    |  sw TMP1, HI(BASE)\t\t// Copy callable.\n    |   sw LFUNC:RB, LO(BASE)\n    |    sw SFARG1HI, 8+HI(BASE)\t// Copy state.\n    |     sw SFARG1LO, 8+LO(BASE)\n    |    sw SFARG2HI, 16+HI(BASE)\t// Copy control var.\n    |     sw SFARG2LO, 16+LO(BASE)\n    |   addiu BASE, BASE, 8\n    |  bne TMP1, AT, ->vmeta_call\n    |.  li NARGS8:RC, 16\t\t// Iterators get 2 arguments.\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT and ENDIAN_LE\n    |  hotloop\n    |.endif\n    |->vm_IITERN:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)\n    |  addu RA, BASE, RA\n    |  lw TAB:RB, -16+LO(RA)\n    |  lw RC, -8+LO(RA)\t\t\t// Get index from control var.\n    |  lw TMP0, TAB:RB->asize\n    |  lw TMP1, TAB:RB->array\n    |   addiu PC, PC, 4\n    |1:  // Traverse array part.\n    |  sltu AT, RC, TMP0\n    |  beqz AT, >5\t\t\t// Index points after array part?\n    |.  sll TMP3, RC, 3\n    |  addu TMP3, TMP1, TMP3\n    |  lw SFARG1HI, HI(TMP3)\n    |   lw SFARG1LO, LO(TMP3)\n    |     lhu RD, -4+OFS_RD(PC)\n    |  sw TISNUM, HI(RA)\n    |   sw RC, LO(RA)\n    |  beq SFARG1HI, TISNIL, <1\t\t// Skip holes in array part.\n    |.  addiu RC, RC, 1\n    |  sw SFARG1HI, 8+HI(RA)\n    |   sw SFARG1LO, 8+LO(RA)\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |     decode_RD4b RD\n    |     addu RD, RD, TMP3\n    |   sw RC, -8+LO(RA)\t\t// Update control var.\n    |     addu PC, PC, RD\n    |3:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  lw TMP1, TAB:RB->hmask\n    |  subu RC, RC, TMP0\n    |   lw TMP2, TAB:RB->node\n    |6:\n    |  sltu AT, TMP1, RC\t\t// End of iteration? Branch to ITERL+1.\n    |  bnez AT, <3\n    |.  sll TMP3, RC, 5\n    |   sll RB, RC, 3\n    |   subu TMP3, TMP3, RB\n    |  addu NODE:TMP3, TMP3, TMP2\n    |  lw SFARG1HI, NODE:TMP3->val.u32.hi\n    |   lw SFARG1LO, NODE:TMP3->val.u32.lo\n    |     lhu RD, -4+OFS_RD(PC)\n    |  beq SFARG1HI, TISNIL, <6\t\t// Skip holes in hash part.\n    |.  addiu RC, RC, 1\n    |  lw SFARG2HI, NODE:TMP3->key.u32.hi\n    |   lw SFARG2LO, NODE:TMP3->key.u32.lo\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sw SFARG1HI, 8+HI(RA)\n    |   sw SFARG1LO, 8+LO(RA)\n    |    addu RC, RC, TMP0\n    |     decode_RD4b RD\n    |     addu RD, RD, TMP3\n    |  sw SFARG2HI, HI(RA)\n    |   sw SFARG2LO, LO(RA)\n    |     addu PC, PC, RD\n    |  b <3\n    |.  sw RC, -8+LO(RA)\t\t// Update control var.\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RD = target (points to ITERN)\n    |  addu RA, BASE, RA\n    |    srl TMP0, RD, 1\n    |  lw CARG1, -24+HI(RA)\n    |  lw CFUNC:CARG2, -24+LO(RA)\n    |    addu TMP0, PC, TMP0\n    |   lw CARG3, -16+HI(RA)\n    |   lw CARG4, -8+HI(RA)\n    |  li AT, LJ_TFUNC\n    |  bne CARG1, AT, >5\n    |.   lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  lbu CARG2, CFUNC:CARG2->ffid\n    |   addiu CARG3, CARG3, -LJ_TTAB\n    |   addiu CARG4, CARG4, -LJ_TNIL\n    |   or CARG3, CARG3, CARG4\n    |  addiu CARG2, CARG2, -FF_next_N\n    |  or CARG2, CARG2, CARG3\n    |  bnez CARG2, >5\n    |.  lui TMP1, (LJ_KEYINDEX >> 16)\n    |  addu PC, TMP0, TMP2\n    |  ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)\n    |  sw r0, -8+LO(RA)\t\t\t// Initialize control var.\n    |  sw TMP1, -8+HI(RA)\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  li TMP3, BC_JMP\n    |   li TMP1, BC_ITERC\n    |  sb TMP3, -4+OFS_OP(PC)\n    |  addu PC, TMP0, TMP2\n    |.if JIT\n    |  lb TMP0, OFS_OP(PC)\n    |  li AT, BC_ITERN\n    |  bne TMP0, AT, >6\n    |.  lhu TMP2, OFS_RD(PC)\n    |.endif\n    |  b <1\n    |.  sb TMP1, OFS_OP(PC)\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  lw TMP0, DISPATCH_J(trace)(DISPATCH)\n    |   sll TMP2, TMP2, 2\n    |  addu TMP0, TMP0, TMP2\n    |  lw TRACE:TMP2, 0(TMP0)\n    |  lw TMP0, TRACE:TMP2->startins\n    |   li AT, -256\n    |  and TMP0, TMP0, AT\n    |  or TMP0, TMP0, TMP1\n    |  b <1\n    |.  sw TMP0, 0(PC)\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  lw TMP0, FRAME_PC(BASE)\n    |  decode_RDtoRC8 RC, RD\n    |   decode_RB8a RB, INS\n    |  addu RC, BASE, RC\n    |   decode_RB8b RB\n    |   addu RA, BASE, RA\n    |  addiu RC, RC, FRAME_VARG\n    |   addu TMP2, RA, RB\n    |  addiu TMP3, BASE, -8\t\t// TMP3 = vtop\n    |  subu RC, RC, TMP0\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  beqz RB, >5\t\t\t// Copy all varargs?\n    |.  subu TMP1, TMP3, RC\n    |  addiu TMP2, TMP2, -16\n    |1:  // Copy vararg slots to destination slots.\n    |  lw CARG1, HI(RC)\n    |  sltu AT, RC, TMP3\n    |   lw CARG2, LO(RC)\n    |    addiu RC, RC, 8\n    |  movz CARG1, TISNIL, AT\n    |  sw CARG1, HI(RA)\n    |   sw CARG2, LO(RA)\n    |  sltu AT, RA, TMP2\n    |  bnez AT, <1\n    |.   addiu RA, RA, 8\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  lw TMP0, L->maxstack\n    |  blez TMP1, <3\t\t\t// No vararg slots?\n    |.  li MULTRES, 8\t\t\t// MULTRES = (0+1)*8\n    |  addu TMP2, RA, TMP1\n    |  sltu AT, TMP0, TMP2\n    |  bnez AT, >7\n    |.  addiu MULTRES, TMP1, 8\n    |6:\n    |  lw SFRETHI, HI(RC)\n    |   lw SFRETLO, LO(RC)\n    |   addiu RC, RC, 8\n    |  sw SFRETHI, HI(RA)\n    |   sw SFRETLO, LO(RA)\n    |  sltu AT, RC, TMP3\n    |  bnez AT, <6\t\t\t// More vararg slots?\n    |.  addiu RA, RA, 8\n    |  b <3\n    |.  nop\n    |\n    |7:  // Grow stack for varargs.\n    |  load_got lj_state_growstack\n    |   sw RA, L->top\n    |  subu RA, RA, BASE\n    |   sw BASE, L->base\n    |  subu BASE, RC, BASE\t\t// Need delta, because BASE may change.\n    |   sw PC, SAVE_PC\n    |  srl CARG2, TMP1, 3\n    |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n    |.  move CARG1, L\n    |  move RC, BASE\n    |  lw BASE, L->base\n    |  addu RA, BASE, RA\n    |  addu RC, BASE, RC\n    |  b <6\n    |.  addiu TMP3, BASE, -8\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RD = extra_nresults*8\n    |  addu RD, RD, MULTRES\t\t// MULTRES >= 8, so RD >= 8.\n    |  // Fall through. Assumes BC_RET follows.\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lw PC, FRAME_PC(BASE)\n    |   addu RA, BASE, RA\n    |    move MULTRES, RD\n    |1:\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return\n    |   lw INS, -4(PC)\n    |    addiu TMP2, BASE, -8\n    |    addiu RC, RD, -8\n    |  decode_RA8a TMP0, INS\n    |   decode_RB8a RB, INS\n    |  decode_RA8b TMP0\n    |   decode_RB8b RB\n    |   addu TMP3, TMP2, RB\n    |  beqz RC, >3\n    |.  subu BASE, TMP2, TMP0\n    |2:\n    |   lw SFRETHI, HI(RA)\n    |    lw SFRETLO, LO(RA)\n    |    addiu RA, RA, 8\n    |  addiu RC, RC, -8\n    |   sw SFRETHI, HI(TMP2)\n    |    sw SFRETLO, LO(TMP2)\n    |  bnez RC, <2\n    |.   addiu TMP2, TMP2, 8\n    |3:\n    |  addiu TMP3, TMP3, -8\n    |5:\n    |  sltu AT, TMP2, TMP3\n    |  bnez AT, >6\n    |.  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  lw KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  sw TISNIL, HI(TMP2)\n    |  b <5\n    |.  addiu TMP2, TMP2, 8\n    |\n    |->BC_RETV_Z:  // Non-standard return case.\n    |  andi TMP2, TMP1, FRAME_TYPEP\n    |  bnez TMP2, ->vm_return\n    |.  nop\n    |  // Return from vararg function: relocate BASE down.\n    |  subu BASE, BASE, TMP1\n    |  b <1\n    |.  lw PC, FRAME_PC(BASE)\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lw PC, FRAME_PC(BASE)\n    |   addu RA, BASE, RA\n    |    move MULTRES, RD\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |\n    |  lw INS, -4(PC)\n    |   addiu TMP2, BASE, -8\n    if (op == BC_RET1) {\n      |  lw SFRETHI, HI(RA)\n      |   lw SFRETLO, LO(RA)\n    }\n    |  decode_RB8a RB, INS\n    |   decode_RA8a RA, INS\n    |  decode_RB8b RB\n    |   decode_RA8b RA\n    if (op == BC_RET1) {\n      |  sw SFRETHI, HI(TMP2)\n      |   sw SFRETLO, LO(TMP2)\n    }\n    |   subu BASE, TMP2, RA\n    |5:\n    |  sltu AT, RD, RB\n    |  bnez AT, >6\n    |.  lw LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lw TMP1, LFUNC:TMP1->pc\n    |  lw KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  addiu TMP2, TMP2, 8\n    |  addiu RD, RD, 8\n    |  b <5\n    if (op == BC_RET1) {\n      |.  sw TISNIL, HI(TMP2)\n    } else {\n      |.  sw TISNIL, -8+HI(TMP2)\n    }\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RD = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  addu RA, BASE, RA\n    |  lw SFARG1HI, FORL_IDX*8+HI(RA)\n    |   lw SFARG1LO, FORL_IDX*8+LO(RA)\n    if (op != BC_JFORL) {\n      |  srl RD, RD, 1\n      |  lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n      |  addu TMP2, RD, TMP2\n    }\n    if (!vk) {\n      |  lw SFARG2HI, FORL_STOP*8+HI(RA)\n      |   lw SFARG2LO, FORL_STOP*8+LO(RA)\n      |  bne SFARG1HI, TISNUM, >5\n      |.  lw SFRETHI, FORL_STEP*8+HI(RA)\n      |  xor AT, SFARG2HI, TISNUM\n      |   lw SFRETLO, FORL_STEP*8+LO(RA)\n      |  xor TMP0, SFRETHI, TISNUM\n      |  or AT, AT, TMP0\n      |  bnez AT, ->vmeta_for\n      |.  slt AT, SFRETLO, r0\n      |  slt CRET1, SFARG2LO, SFARG1LO\n      |  slt TMP1, SFARG1LO, SFARG2LO\n      |  movn CRET1, TMP1, AT\n    } else {\n      |  bne SFARG1HI, TISNUM, >5\n      |.  lw SFARG2LO, FORL_STEP*8+LO(RA)\n      |  lw SFRETLO, FORL_STOP*8+LO(RA)\n      |  move TMP3, SFARG1LO\n      |  addu SFARG1LO, SFARG1LO, SFARG2LO\n      |  xor TMP0, SFARG1LO, TMP3\n      |  xor TMP1, SFARG1LO, SFARG2LO\n      |  and TMP0, TMP0, TMP1\n      |  slt TMP1, SFARG1LO, SFRETLO\n      |  slt CRET1, SFRETLO, SFARG1LO\n      |  slt AT, SFARG2LO, r0\n      |   slt TMP0, TMP0, r0\t\t// ((y^a) & (y^b)) < 0: overflow.\n      |  movn CRET1, TMP1, AT\n      |   or CRET1, CRET1, TMP0\n    }\n    |1:\n    if (op == BC_FORI) {\n      |  movz TMP2, r0, CRET1\n      |  addu PC, PC, TMP2\n    } else if (op == BC_JFORI) {\n      |  addu PC, PC, TMP2\n      |  lhu RD, -4+OFS_RD(PC)\n    } else if (op == BC_IFORL) {\n      |  movn TMP2, r0, CRET1\n      |  addu PC, PC, TMP2\n    }\n    if (vk) {\n      |  sw SFARG1HI, FORL_IDX*8+HI(RA)\n      |   sw SFARG1LO, FORL_IDX*8+LO(RA)\n    }\n    |  ins_next1\n    |  sw SFARG1HI, FORL_EXT*8+HI(RA)\n    |   sw SFARG1LO, FORL_EXT*8+LO(RA)\n    |2:\n    if (op == BC_JFORI) {\n      |  beqz CRET1, =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else if (op == BC_JFORL) {\n      |  beqz CRET1, =>BC_JLOOP\n    }\n    |  ins_next2\n    |\n    |5:  // FP loop.\n    |.if FPU\n    if (!vk) {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f2, FORL_STOP*8(RA)\n      |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n      |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n      |  sltiu AT, SFRETHI, LJ_TISNUM\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  slt TMP3, SFRETHI, r0\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |  li CRET1, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  b <1\n      |.  movn CRET1, AT, TMP3\n    } else {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f4, FORL_STEP*8(RA)\n      |    ldc1 f2, FORL_STOP*8(RA)\n      |   lw SFARG2HI, FORL_STEP*8+HI(RA)\n      |  add.d f0, f0, f4\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |   slt TMP3, SFARG2HI, r0\n      |  li CRET1, 1\n      |  li AT, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  movn CRET1, AT, TMP3\n      if (op == BC_IFORL) {\n\t|  movn TMP2, r0, CRET1\n\t|  addu PC, PC, TMP2\n      }\n      |  sdc1 f0, FORL_IDX*8(RA)\n      |  ins_next1\n      |  b <2\n      |.  sdc1 f0, FORL_EXT*8(RA)\n    }\n    |.else\n    if (!vk) {\n      |  sltiu TMP0, SFARG1HI, LJ_TISNUM\n      |  sltiu TMP1, SFARG2HI, LJ_TISNUM\n      |  sltiu AT, SFRETHI, LJ_TISNUM\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  nop\n      |  bal ->vm_sfcmpolex\n      |.  move TMP3, SFRETHI\n      |  b <1\n      |.  nop\n    } else {\n      |   lw SFARG2HI, FORL_STEP*8+HI(RA)\n      |  load_got __adddf3\n      |  call_extern\n      |.  sw TMP2, ARG5\n      |  lw SFARG2HI, FORL_STOP*8+HI(RA)\n      |   lw SFARG2LO, FORL_STOP*8+LO(RA)\n      |  move SFARG1HI, SFRETHI\n      |   move SFARG1LO, SFRETLO\n      |  bal ->vm_sfcmpolex\n      |.  lw TMP3, FORL_STEP*8+HI(RA)\n      if ( op == BC_JFORL ) {\n\t|   lhu RD, -4+OFS_RD(PC)\n\t|  lw TMP2, ARG5\n\t|  b <1\n\t|.  decode_RD8b RD\n      } else {\n\t|  b <1\n\t|.  lw TMP2, ARG5\n      }\n    }\n    |.endif\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RD = target\n    |  addu RA, BASE, RA\n    |  lw TMP1, HI(RA)\n    |  beq TMP1, TISNIL, >1\t\t// Stop if iterator returned nil.\n    |.  lw TMP2, LO(RA)\n    if (op == BC_JITERL) {\n      |  sw TMP1, -8+HI(RA)\n      |  b =>BC_JLOOP\n      |.  sw TMP2, -8+LO(RA)\n    } else {\n      |  branch_RD\t\t\t// Otherwise save control var + branch.\n      |  sw TMP1, -8+HI(RA)\n      |   sw TMP2, -8+LO(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base*8 (ignored), RD = traceno*8\n    |  lw TMP1, DISPATCH_J(trace)(DISPATCH)\n    |  srl RD, RD, 1\n    |   li AT, 0\n    |  addu TMP1, TMP1, RD\n    |  // Traces on MIPS don't store the trace number, so use 0.\n    |   sw AT, DISPATCH_GL(vmstate)(DISPATCH)\n    |  lw TRACE:TMP2, 0(TMP1)\n    |   sw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n    |  lw TMP2, TRACE:TMP2->mcode\n    |   sw L, DISPATCH_GL(tmpbuf.L)(DISPATCH)\n    |  jr TMP2\n    |.  addiu JGL, DISPATCH, GG_DISP2G+32768\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RD = target\n    |  branch_RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lw TMP2, L->maxstack\n    |   lbu TMP1, -4+PC2PROTO(numparams)(PC)\n    |    lw KBASE, -4+PC2PROTO(k)(PC)\n    |  sltu AT, TMP2, RA\n    |  bnez AT, ->vm_growstack_l\n    |.  sll TMP1, TMP1, 3\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n    }\n    |2:\n    |  sltu AT, NARGS8:RC, TMP1\t\t// Check for missing parameters.\n    |  bnez AT, >3\n    |.  addu AT, BASE, NARGS8:RC\n    if (op == BC_JFUNCF) {\n      |  decode_RD8a RD, INS\n      |  b =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else {\n      |  ins_next2\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  sw TISNIL, HI(AT)\n    |  b <2\n    |.  addiu NARGS8:RC, NARGS8:RC, 8\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |   addu TMP1, BASE, RC\n    |  lw TMP2, L->maxstack\n    |  addu TMP0, RA, RC\n    |   sw LFUNC:RB, LO(TMP1)\t\t// Store copy of LFUNC.\n    |   addiu TMP3, RC, 8+FRAME_VARG\n    |  sltu AT, TMP0, TMP2\n    |    lw KBASE, -4+PC2PROTO(k)(PC)\n    |  beqz AT, ->vm_growstack_l\n    |.  sw TMP3, HI(TMP1)\t\t// Store delta + FRAME_VARG.\n    |  lbu TMP2, -4+PC2PROTO(numparams)(PC)\n    |   move RA, BASE\n    |   move RC, TMP1\n    |  ins_next1\n    |  beqz TMP2, >3\n    |.  addiu BASE, TMP1, 8\n    |1:\n    |  lw TMP0, HI(RA)\n    |   lw TMP3, LO(RA)\n    |  sltu AT, RA, RC\t\t\t// Less args than parameters?\n    |  move CARG1, TMP0\n    |  movz TMP0, TISNIL, AT\t\t// Clear missing parameters.\n    |  movn CARG1, TISNIL, AT\t\t// Clear old fixarg slot (help the GC).\n    |   sw TMP3, 8+LO(TMP1)\n    |    addiu TMP2, TMP2, -1\n    |  sw TMP0, 8+HI(TMP1)\n    |    addiu TMP1, TMP1, 8\n    |  sw CARG1, HI(RA)\n    |  bnez TMP2, <1\n    |.   addiu RA, RA, 8\n    |3:\n    |  ins_next2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  lw CFUNCADDR, CFUNC:RB->f\n    } else {\n      |  lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)\n    }\n    |  addu TMP1, RA, NARGS8:RC\n    |  lw TMP2, L->maxstack\n    |   addu RC, BASE, NARGS8:RC\n    |  sw BASE, L->base\n    |  sltu AT, TMP2, TMP1\n    |   sw RC, L->top\n    |    li_vmstate C\n    if (op == BC_FUNCCW) {\n      |  lw CARG2, CFUNC:RB->f\n    }\n    |  bnez AT, ->vm_growstack_c\t// Need to grow stack.\n    |.  move CARG1, L\n    |  jalr CFUNCADDR\t\t\t// (lua_State *L [, lua_CFunction f])\n    |.   st_vmstate\n    |  // Returns nresults.\n    |  lw BASE, L->base\n    |   sll RD, CRET1, 3\n    |  lw TMP1, L->top\n    |    li_vmstate INTERP\n    |  lw PC, FRAME_PC(BASE)\t\t// Fetch PC of caller.\n    |   subu RA, TMP1, RD\t\t// RA = L->top - nresults*8\n    |    sw L, DISPATCH_GL(cur_L)(DISPATCH)\n    |  b ->vm_returnc\n    |.   st_vmstate\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.4byte .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.4byte 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.4byte .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.4byte .Lbegin\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.sleb128 1\\n\"\n\t\"\\t.byte 0x9e\\n\\t.sleb128 2\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 23; i >= 16; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 26-i);\n#if !LJ_SOFTFP\n    for (i = 30; i >= 20; i -= 2)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+32+i, 42-i);\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.4byte .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.4byte lj_vm_ffi_call\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.uleb128 1\\n\"\n\t\"\\t.byte 0x90\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x10\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"aw\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\"\\t.globl lj_err_unwind_dwarf\\n\"\n\t\".Lframe1:\\n\"\n\t\"\\t.4byte .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.4byte 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0\\n\"\n\t\"\\t.4byte lj_err_unwind_dwarf\\n\"\n\t\"\\t.byte 0\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.4byte .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.4byte .LASFDE2-.Lframe1\\n\"\n\t\"\\t.4byte .Lbegin\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.sleb128 1\\n\"\n\t\"\\t.byte 0x9e\\n\\t.sleb128 2\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 23; i >= 16; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 26-i);\n#if !LJ_SOFTFP\n    for (i = 30; i >= 20; i -= 2)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+32+i, 42-i);\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.4byte .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.4byte 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.4byte .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.4byte .LASFDE3-.Lframe2\\n\"\n\t\"\\t.4byte lj_vm_ffi_call\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9f\\n\\t.uleb128 1\\n\"\n\t\"\\t.byte 0x90\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x10\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_mips64.dasc",
    "content": "|// Low-level VM code for MIPS64 CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|//\n|// Contributed by Djordje Kovacevic and Stefan Pejic from RT-RK.com.\n|// Sponsored by Cisco Systems, Inc.\n|\n|.arch mips64\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra\n|\n|.macro .FPU, a, b\n|.if FPU\n|  a, b\n|.endif\n|.endmacro\n|\n|// The following must be C callee-save (but BASE is often refetched).\n|.define BASE,\t\tr16\t// Base of current Lua stack frame.\n|.define KBASE,\t\tr17\t// Constants of current Lua function.\n|.define PC,\t\tr18\t// Next PC.\n|.define DISPATCH,\tr19\t// Opcode dispatch table.\n|.define LREG,\t\tr20\t// Register holding lua_State (also in SAVE_L).\n|.define MULTRES,\tr21\t// Size of multi-result: (nresults+1)*8.\n|\n|.define JGL,\t\tr30\t// On-trace: global_State + 32768.\n|\n|// Constants for type-comparisons, stores and conversions. C callee-save.\n|.define TISNIL,\tr30\n|.define TISNUM,\tr22\n|.if FPU\n|.define TOBIT,\t\tf30\t// 2^52 + 2^51.\n|.endif\n|\n|// The following temporaries are not saved across C calls, except for RA.\n|.define RA,\t\tr23\t// Callee-save.\n|.define RB,\t\tr8\n|.define RC,\t\tr9\n|.define RD,\t\tr10\n|.define INS,\t\tr11\n|\n|.define AT,\t\tr1\t// Assembler temporary.\n|.define TMP0,\t\tr12\n|.define TMP1,\t\tr13\n|.define TMP2,\t\tr14\n|.define TMP3,\t\tr15\n|\n|// MIPS n64 calling convention.\n|.define CFUNCADDR,\tr25\n|.define CARG1,\t\tr4\n|.define CARG2,\t\tr5\n|.define CARG3,\t\tr6\n|.define CARG4,\t\tr7\n|.define CARG5,\t\tr8\n|.define CARG6,\t\tr9\n|.define CARG7,\t\tr10\n|.define CARG8,\t\tr11\n|\n|.define CRET1,\t\tr2\n|.define CRET2,\t\tr3\n|\n|.if FPU\n|.define FARG1,\t\tf12\n|.define FARG2,\t\tf13\n|.define FARG3,\t\tf14\n|.define FARG4,\t\tf15\n|.define FARG5,\t\tf16\n|.define FARG6,\t\tf17\n|.define FARG7,\t\tf18\n|.define FARG8,\t\tf19\n|\n|.define FRET1,\t\tf0\n|.define FRET2,\t\tf2\n|\n|.define FTMP0,\t\tf20\n|.define FTMP1,\t\tf21\n|.define FTMP2,\t\tf22\n|.endif\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.if FPU\t\t// MIPS64 hard-float.\n|\n|.define CFRAME_SPACE,\t192\t// Delta for sp.\n|\n|//----- 16 byte aligned, <-- sp entering interpreter\n|.define SAVE_ERRF,\t188(sp)\t// 32 bit values.\n|.define SAVE_NRES,\t184(sp)\n|.define SAVE_CFRAME,\t176(sp)\t// 64 bit values.\n|.define SAVE_L,\t168(sp)\n|.define SAVE_PC,\t160(sp)\n|//----- 16 byte aligned\n|.define SAVE_GPR_,\t80\t// .. 80+10*8: 64 bit GPR saves.\n|.define SAVE_FPR_,\t16\t// .. 16+8*8: 64 bit FPR saves.\n|\n|.else\t\t\t// MIPS64 soft-float\n|\n|.define CFRAME_SPACE,\t128\t// Delta for sp.\n|\n|//----- 16 byte aligned, <-- sp entering interpreter\n|.define SAVE_ERRF,\t124(sp)\t// 32 bit values.\n|.define SAVE_NRES,\t120(sp)\n|.define SAVE_CFRAME,\t112(sp)\t// 64 bit values.\n|.define SAVE_L,\t104(sp)\n|.define SAVE_PC,\t96(sp)\n|//----- 16 byte aligned\n|.define SAVE_GPR_,\t16\t// .. 16+10*8: 64 bit GPR saves.\n|\n|.endif\n|\n|.define TMPX,\t\t8(sp)\t// Unused by interpreter, temp for JIT code.\n|.define TMPD,\t\t0(sp)\n|//----- 16 byte aligned\n|\n|.define TMPD_OFS,\t0\n|\n|.define SAVE_MULTRES,\tTMPD\n|\n|//-----------------------------------------------------------------------\n|\n|.macro saveregs\n|  daddiu sp, sp, -CFRAME_SPACE\n|  sd ra, SAVE_GPR_+9*8(sp)\n|  sd r30, SAVE_GPR_+8*8(sp)\n|   .FPU sdc1 f31, SAVE_FPR_+7*8(sp)\n|  sd r23, SAVE_GPR_+7*8(sp)\n|   .FPU sdc1 f30, SAVE_FPR_+6*8(sp)\n|  sd r22, SAVE_GPR_+6*8(sp)\n|   .FPU sdc1 f29, SAVE_FPR_+5*8(sp)\n|  sd r21, SAVE_GPR_+5*8(sp)\n|   .FPU sdc1 f28, SAVE_FPR_+4*8(sp)\n|  sd r20, SAVE_GPR_+4*8(sp)\n|   .FPU sdc1 f27, SAVE_FPR_+3*8(sp)\n|  sd r19, SAVE_GPR_+3*8(sp)\n|   .FPU sdc1 f26, SAVE_FPR_+2*8(sp)\n|  sd r18, SAVE_GPR_+2*8(sp)\n|   .FPU sdc1 f25, SAVE_FPR_+1*8(sp)\n|  sd r17, SAVE_GPR_+1*8(sp)\n|   .FPU sdc1 f24, SAVE_FPR_+0*8(sp)\n|  sd r16, SAVE_GPR_+0*8(sp)\n|.endmacro\n|\n|.macro restoreregs_ret\n|  ld ra, SAVE_GPR_+9*8(sp)\n|  ld r30, SAVE_GPR_+8*8(sp)\n|  ld r23, SAVE_GPR_+7*8(sp)\n|   .FPU ldc1 f31, SAVE_FPR_+7*8(sp)\n|  ld r22, SAVE_GPR_+6*8(sp)\n|   .FPU ldc1 f30, SAVE_FPR_+6*8(sp)\n|  ld r21, SAVE_GPR_+5*8(sp)\n|   .FPU ldc1 f29, SAVE_FPR_+5*8(sp)\n|  ld r20, SAVE_GPR_+4*8(sp)\n|   .FPU ldc1 f28, SAVE_FPR_+4*8(sp)\n|  ld r19, SAVE_GPR_+3*8(sp)\n|   .FPU ldc1 f27, SAVE_FPR_+3*8(sp)\n|  ld r18, SAVE_GPR_+2*8(sp)\n|   .FPU ldc1 f26, SAVE_FPR_+2*8(sp)\n|  ld r17, SAVE_GPR_+1*8(sp)\n|   .FPU ldc1 f25, SAVE_FPR_+1*8(sp)\n|  ld r16, SAVE_GPR_+0*8(sp)\n|   .FPU ldc1 f24, SAVE_FPR_+0*8(sp)\n|  jr ra\n|  daddiu sp, sp, CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; .long 0xec1cf0f0; .endmacro\n|\n|// Macros to mark delay slots.\n|.macro ., a; a; .endmacro\n|.macro ., a,b; a,b; .endmacro\n|.macro ., a,b,c; a,b,c; .endmacro\n|.macro ., a,b,c,d; a,b,c,d; .endmacro\n|\n|.define FRAME_PC,\t-8\n|.define FRAME_FUNC,\t-16\n|\n|//-----------------------------------------------------------------------\n|\n|// Endian-specific defines.\n|.if ENDIAN_LE\n|.define HI,\t\t4\n|.define LO,\t\t0\n|.define OFS_RD,\t2\n|.define OFS_RA,\t1\n|.define OFS_OP,\t0\n|.else\n|.define HI,\t\t0\n|.define LO,\t\t4\n|.define OFS_RD,\t0\n|.define OFS_RA,\t2\n|.define OFS_OP,\t3\n|.endif\n|\n|// Instruction decode.\n|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP8a, dst, ins; andi dst, ins, 0xff; .endmacro\n|.macro decode_OP8b, dst; sll dst, dst, 3; .endmacro\n|.macro decode_RC8a, dst, ins; srl dst, ins, 13; .endmacro\n|.macro decode_RC8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro\n|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro\n|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro\n|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro\n|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro\n|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro\n|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  lw INS, 0(PC)\n|   daddiu PC, PC, 4\n|.endmacro\n|// Instruction decode+dispatch.\n|.macro ins_NEXT2\n|  decode_OP8a TMP1, INS\n|  decode_OP8b TMP1\n|  daddu TMP0, DISPATCH, TMP1\n|   decode_RD8a RD, INS\n|  ld AT, 0(TMP0)\n|   decode_RA8a RA, INS\n|   decode_RD8b RD\n|  jr AT\n|   decode_RA8b RA\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  ld PC, LFUNC:RB->pc\n|  lw INS, 0(PC)\n|   daddiu PC, PC, 4\n|  decode_OP8a TMP1, INS\n|   decode_RA8a RA, INS\n|  decode_OP8b TMP1\n|   decode_RA8b RA\n|  daddu TMP0, DISPATCH, TMP1\n|  ld TMP0, 0(TMP0)\n|  jr TMP0\n|   daddu RA, RA, BASE\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  sd PC, FRAME_PC(BASE)\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|.macro branch_RD\n|  srl TMP0, RD, 1\n|  lui AT, (-(BCBIAS_J*4 >> 16) & 65535)\n|  addu TMP0, TMP0, AT\n|  daddu PC, PC, TMP0\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n#define GG_DISP2GOT\t\t(GG_OFS(got) - GG_OFS(dispatch))\n#define DISPATCH_GOT(name)\t(GG_DISP2GOT + sizeof(void*)*LJ_GOT_##name)\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro load_got, func\n|  ld CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)\n|.endmacro\n|// Much faster. Sadly, there's no easy way to force the required code layout.\n|// .macro call_intern, func; bal extern func; .endmacro\n|.macro call_intern, func; jalr CFUNCADDR; .endmacro\n|.macro call_extern; jalr CFUNCADDR; .endmacro\n|.macro jmp_extern; jr CFUNCADDR; .endmacro\n|\n|.macro hotcheck, delta, target\n|  dsrl TMP1, PC, 1\n|  andi TMP1, TMP1, 126\n|  daddu TMP1, TMP1, DISPATCH\n|  lhu TMP2, GG_DISP2HOT(TMP1)\n|  addiu TMP2, TMP2, -delta\n|  bltz TMP2, target\n|.  sh TMP2, GG_DISP2HOT(TMP1)\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL, ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state. Uses TMP0.\n|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro\n|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp, target\n|  ld tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   andi mark, mark, ~LJ_GC_BLACK & 255\t\t// black2gray(tab)\n|  sd tab, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   sb mark, tab->marked\n|  b target\n|.  sd tmp, tab->gclist\n|.endmacro\n|\n|// Clear type tag. Isolate lowest 14+32+1=47 bits of reg.\n|.macro cleartp, reg; dextm reg, reg, 0, 14; .endmacro\n|.macro cleartp, dst, reg; dextm dst, reg, 0, 14; .endmacro\n|\n|// Set type tag: Merge 17 type bits into bits [15+32=47, 31+32+1=64) of dst.\n|.macro settp, dst, tp; dinsu dst, tp, 15, 31; .endmacro\n|\n|// Extract (negative) type tag.\n|.macro gettp, dst, src; dsra dst, src, 47; .endmacro\n|\n|// Macros to check the TValue type and extract the GCobj. Branch on failure.\n|.macro checktp, reg, tp, target\n|  gettp AT, reg\n|  daddiu AT, AT, tp\n|  bnez AT, target\n|.  cleartp reg\n|.endmacro\n|.macro checktp, dst, reg, tp, target\n|  gettp AT, reg\n|  daddiu AT, AT, tp\n|  bnez AT, target\n|.  cleartp dst, reg\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, -LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, -LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, -LJ_TFUNC, target; .endmacro\n|.macro checkint, reg, target\t// Caveat: has delay slot!\n|  gettp AT, reg\n|  bne AT, TISNUM, target\n|.endmacro\n|.macro checknum, reg, target\t// Caveat: has delay slot!\n|  gettp AT, reg\n|  sltiu AT, AT, LJ_TISNUM\n|  beqz AT, target\n|.endmacro\n|\n|.macro mov_false, reg\n|  lu reg, 0x8000\n|  dsll reg, reg, 32\n|  not reg, reg\n|.endmacro\n|.macro mov_true, reg\n|  li reg, 0x0001\n|  dsll reg, reg, 48\n|  not reg, reg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: TMP2 = previous base.\n  |  andi AT, PC, FRAME_P\n  |  beqz AT, ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |.  mov_true TMP1\n  |  ld PC, FRAME_PC(TMP2)\t\t// Fetch PC of previous frame.\n  |  move BASE, TMP2\t\t\t// Restore caller base.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   sd TMP1, -8(RA)\t\t\t// Prepend true to results.\n  |   daddiu RA, RA, -8\n  |\n  |->vm_returnc:\n  |   addiu RD, RD, 8\t\t\t// RD = (nresults+1)*8.\n  |  andi TMP0, PC, FRAME_TYPE\n  |   beqz RD, ->vm_unwind_c_eh\n  |.   li CRET1, LUA_YIELD\n  |  beqz TMP0, ->BC_RET_Z\t\t// Handle regular return to Lua.\n  |.  move MULTRES, RD\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return\n  |  // TMP0 = PC & FRAME_TYPE\n  |   li TMP2, -8\n  |  xori AT, TMP0, FRAME_C\n  |   and TMP2, PC, TMP2\n  |  bnez AT, ->vm_returnp\n  |   dsubu TMP2, BASE, TMP2\t\t// TMP2 = previous base.\n  |\n  |  addiu TMP1, RD, -8\n  |   sd TMP2, L->base\n  |    li_vmstate C\n  |   lw TMP2, SAVE_NRES\n  |   daddiu BASE, BASE, -16\n  |    st_vmstate\n  |  beqz TMP1, >2\n  |.   sll TMP2, TMP2, 3\n  |1:\n  |  addiu TMP1, TMP1, -8\n  |   ld CRET1, 0(RA)\n  |    daddiu RA, RA, 8\n  |   sd CRET1, 0(BASE)\n  |  bnez TMP1, <1\n  |.  daddiu BASE, BASE, 8\n  |\n  |2:\n  |  bne TMP2, RD, >6\n  |3:\n  |.  sd BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  ld TMP0, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   move CRET1, r0\t\t\t// Ok return status for vm_pcall.\n  |  sd TMP0, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs_ret\n  |\n  |6:\n  |  ld TMP1, L->maxstack\n  |  slt AT, TMP2, RD\n  |  bnez AT, >7\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |.  slt AT, BASE, TMP1\n  |  beqz AT, >8\n  |.  nop\n  |  sd TISNIL, 0(BASE)\n  |  addiu RD, RD, 8\n  |  b <2\n  |.  daddiu BASE, BASE, 8\n  |\n  |7:  // Less results wanted.\n  |  subu TMP0, RD, TMP2\n  |  dsubu TMP0, BASE, TMP0\t\t// Either keep top or shrink it.\n  |.if MIPSR6\n  |  selnez TMP0, TMP0, TMP2\t\t// LUA_MULTRET+1 case?\n  |  seleqz BASE, BASE, TMP2\n  |  b <3\n  |.  or BASE, BASE, TMP0\n  |.else\n  |  b <3\n  |.  movn BASE, TMP0, TMP2\t\t// LUA_MULTRET+1 case?\n  |.endif\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  load_got lj_state_growstack\n  |   move MULTRES, RD\n  |  srl CARG2, TMP2, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |    lw TMP2, SAVE_NRES\n  |  ld BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |   move RD, MULTRES\n  |  b <2\n  |.   sll TMP2, TMP2, 3\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  move sp, CARG1\n  |  move CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  ld L, SAVE_L\n  |   li TMP0, ~LJ_VMST_C\n  |  ld GL:TMP1, L->glref\n  |  b ->vm_leave_unw\n  |.  sw TMP0, GL:TMP1->vmstate\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  li AT, -4\n  |  and sp, CARG1, AT\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  ld L, SAVE_L\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |     li TISNIL, LJ_TNIL\n  |    li TISNUM, LJ_TISNUM\n  |  ld BASE, L->base\n  |   ld DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     .FPU mtc1 TMP3, TOBIT\n  |  mov_false TMP1\n  |    li_vmstate INTERP\n  |  ld PC, FRAME_PC(BASE)\t\t// Fetch PC of previous frame.\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  daddiu RA, BASE, -8\t\t// Results start at BASE-8.\n  |   daddiu DISPATCH, DISPATCH, GG_G2DISP\n  |  sd TMP1, 0(RA)\t\t\t// Prepend false to error message.\n  |    st_vmstate\n  |  b ->vm_returnc\n  |.  li RD, 16\t\t\t\t// 2 results: false + error message.\n  |\n  |->vm_unwind_stub:\t\t\t// Jump to exit stub from unwinder.\n  |  jr CARG1\n  |.  move ra, CARG2\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  b >2\n  |.  li CARG2, LUA_MINSTACK\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  daddu RC, BASE, RC\n  |   dsubu RA, RA, BASE\n  |  sd BASE, L->base\n  |   daddiu PC, PC, 4\t\t\t// Must point after first instruction.\n  |  sd RC, L->top\n  |   srl CARG2, RA, 3\n  |2:\n  |  // L->base = new base, L->top = top\n  |  load_got lj_state_growstack\n  |   sd PC, SAVE_PC\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  ld BASE, L->base\n  |  ld RC, L->top\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\n  |  dsubu RC, RC, BASE\n  |  cleartp LFUNC:RB\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  move L, CARG1\n  |    ld DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  move BASE, CARG2\n  |    lbu TMP1, L->status\n  |   sd L, SAVE_L\n  |  li PC, FRAME_CP\n  |  daddiu TMP0, sp, CFRAME_RESUME\n  |    daddiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw r0, SAVE_NRES\n  |   sw r0, SAVE_ERRF\n  |   sd CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   sd r0, SAVE_CFRAME\n  |    beqz TMP1, >3\n  |. sd TMP0, L->cframe\n  |\n  |  // Resume after yield (like a return).\n  |  sd L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  move RA, BASE\n  |   ld BASE, L->base\n  |   ld TMP1, L->top\n  |  ld PC, FRAME_PC(BASE)\n  |     .FPU  lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   dsubu RD, TMP1, BASE\n  |     .FPU  mtc1 TMP3, TOBIT\n  |    sb r0, L->status\n  |     .FPU  cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |   daddiu RD, RD, 8\n  |    st_vmstate\n  |   move MULTRES, RD\n  |  andi TMP0, PC, FRAME_TYPE\n  |    li TISNIL, LJ_TNIL\n  |  beqz TMP0, ->BC_RET_Z\n  |.    li TISNUM, LJ_TISNUM\n  |  b ->vm_return\n  |.  nop\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  sw CARG4, SAVE_ERRF\n  |  b >1\n  |.  li PC, FRAME_CP\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  li PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  ld TMP1, L:CARG1->cframe\n  |    move L, CARG1\n  |   sw CARG3, SAVE_NRES\n  |    ld DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   sd CARG1, SAVE_L\n  |     move BASE, CARG2\n  |    daddiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sd CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  sd TMP1, SAVE_CFRAME\n  |  sd sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  sd L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  ld TMP2, L->base\t\t\t// TMP2 = old base (used in vmeta_call).\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   ld TMP1, L->top\n  |     .FPU mtc1 TMP3, TOBIT\n  |  daddu PC, PC, BASE\n  |   dsubu NARGS8:RC, TMP1, BASE\n  |     li TISNUM, LJ_TISNUM\n  |  dsubu PC, PC, TMP2\t\t\t// PC = frame delta + frame type\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |    li_vmstate INTERP\n  |     li TISNIL, LJ_TNIL\n  |    st_vmstate\n  |\n  |->vm_call_dispatch:\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\n  |  checkfunc LFUNC:RB, ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  move L, CARG1\n  |   ld TMP0, L:CARG1->stack\n  |  sd CARG1, SAVE_L\n  |   ld TMP1, L->top\n  |     ld DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  sd CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   dsubu TMP0, TMP0, TMP1\t\t// Compute -savestack(L, L->top).\n  |    ld TMP1, L->cframe\n  |     daddiu DISPATCH, DISPATCH, GG_G2DISP\n  |   sw TMP0, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  sw r0, SAVE_ERRF\t\t\t// No error function.\n  |    sd TMP1, SAVE_CFRAME\n  |    sd sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |     sd L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  jalr CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.  move CFUNCADDR, CARG4\n  |  move BASE, CRET1\n  |  bnez CRET1, <3\t\t\t// Else continue with the call.\n  |.  li PC, FRAME_CP\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |.  nop\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the\n  |// stack, so BASE doesn't need to be reloaded across these calls.\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8\n  |  ld TMP0, -32(BASE)\t\t\t// Continuation.\n  |   move RB, BASE\n  |   move BASE, TMP2\t\t\t// Restore caller BASE.\n  |    ld LFUNC:TMP1, FRAME_FUNC(TMP2)\n  |.if FFI\n  |  sltiu AT, TMP0, 2\n  |.endif\n  |     ld PC, -24(RB)\t\t\t// Restore PC from [cont|PC].\n  |    cleartp LFUNC:TMP1\n  |   daddu TMP2, RA, RD\n  |.if FFI\n  |  bnez AT, >1\n  |.endif\n  |.  sd TISNIL, -8(TMP2)\t\t// Ensure one valid arg.\n  |    ld TMP1, LFUNC:TMP1->pc\n  |  // BASE = base, RA = resultptr, RB = meta base\n  |  jr TMP0\t\t\t\t// Jump to continuation.\n  |.  ld KBASE, PC2PROTO(k)(TMP1)\n  |\n  |.if FFI\n  |1:\n  |  bnez TMP0, ->cont_ffi_callback\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |.  daddiu TMP1, RB, -32\n  |  b ->vm_call_tail\n  |.  dsubu RC, TMP1, BASE\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |   daddiu CARG2, RB, -32\n  |  ld CRET1, 0(RA)\n  |  decode_RB8a MULTRES, INS\n  |   decode_RA8a RA, INS\n  |  decode_RB8b MULTRES\n  |   decode_RA8b RA\n  |  daddu TMP1, BASE, MULTRES\n  |   sd BASE, L->base\n  |   dsubu CARG3, CARG2, TMP1\n  |  bne TMP1, CARG2, ->BC_CAT_Z\n  |.  sd CRET1, 0(CARG2)\n  |  daddu RA, BASE, RA\n  |  b ->cont_nop\n  |.  sd CRET1, 0(RA)\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  settp STR:RC, TMP0\n  |  b >1\n  |.  sd STR:RC, 0(CARG3)\n  |\n  |->vmeta_tgets:\n  |  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |   li TMP1, LJ_TSTR\n  |  settp TAB:RB, TMP0\n  |   daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sd TAB:RB, 0(CARG2)\n  |   settp STR:RC, TMP1\n  |  b >1\n  |.  sd STR:RC, 0(CARG3)\n  |\n  |->vmeta_tgetb:\t\t\t// TMP0 = index\n  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  settp TMP0, TISNUM\n  |  sd TMP0, 0(CARG3)\n  |\n  |->vmeta_tgetv:\n  |1:\n  |  load_got lj_meta_tget\n  |  sd BASE, L->base\n  |  sd PC, SAVE_PC\n  |  call_intern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  beqz CRET1, >3\n  |.  daddiu TMP1, BASE, -FRAME_CONT\n  |  ld CARG1, 0(CRET1)\n  |  ins_next1\n  |  sd CARG1, 0(RA)\n  |  ins_next2\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  ld BASE, L->top\n  |  sd PC, -24(BASE)\t\t\t// [cont|PC]\n  |   dsubu PC, BASE, TMP1\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  cleartp LFUNC:RB\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(t, k).\n  |\n  |->vmeta_tgetr:\n  |  load_got lj_tab_getinth\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  nop\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->BC_TGETR_Z\n  |.  move CARG2, TISNIL\n  |  b ->BC_TGETR_Z\n  |.  ld CARG2, 0(CRET1)\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TSTR\n  |  settp STR:RC, TMP0\n  |  b >1\n  |.  sd STR:RC, 0(CARG3)\n  |\n  |->vmeta_tsets:\n  |  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |  li TMP0, LJ_TTAB\n  |   li TMP1, LJ_TSTR\n  |  settp TAB:RB, TMP0\n  |   daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)\n  |  sd TAB:RB, 0(CARG2)\n  |   settp STR:RC, TMP1\n  |  b >1\n  |.  sd STR:RC, 0(CARG3)\n  |\n  |->vmeta_tsetb:\t\t\t// TMP0 = index\n  |  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n  |  settp TMP0, TISNUM\n  |  sd TMP0, 0(CARG3)\n  |\n  |->vmeta_tsetv:\n  |1:\n  |  load_got lj_meta_tset\n  |  sd BASE, L->base\n  |  sd PC, SAVE_PC\n  |  call_intern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |.  move CARG1, L\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  beqz CRET1, >3\n  |.  ld CARG1, 0(RA)\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  ins_next1\n  |  sd CARG1, 0(CRET1)\n  |  ins_next2\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  daddiu TMP1, BASE, -FRAME_CONT\n  |  ld BASE, L->top\n  |  sd PC, -24(BASE)\t\t\t// [cont|PC]\n  |   dsubu PC, BASE, TMP1\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |  cleartp LFUNC:RB\n  |  sd CARG1, 16(BASE)\t\t\t// Copy value to third argument.\n  |  b ->vm_call_dispatch_f\n  |.  li NARGS8:RC, 24\t\t\t// 3 args for func(t, k, v)\n  |\n  |->vmeta_tsetr:\n  |  load_got lj_tab_setinth\n  |  sd BASE, L->base\n  |  sd PC, SAVE_PC\n  |  call_intern lj_tab_setinth\t// (lua_State *L, GCtab *t, int32_t key)\n  |.  move CARG1, L\n  |  // Returns TValue *.\n  |  b ->BC_TSETR_Z\n  |.  nop\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  // RA/RD point to o1/o2.\n  |  move CARG2, RA\n  |  move CARG3, RD\n  |  load_got lj_meta_comp\n  |  daddiu PC, PC, -4\n  |  sd BASE, L->base\n  |  sd PC, SAVE_PC\n  |  decode_OP1 CARG4, INS\n  |  call_intern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  sltiu AT, CRET1, 2\n  |  beqz AT, ->vmeta_binop\n  |   negu TMP2, CRET1\n  |4:\n  |  lhu RD, OFS_RD(PC)\n  |   daddiu PC, PC, 4\n  |   lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)\n  |  sll RD, RD, 2\n  |  addu RD, RD, TMP1\n  |  and RD, RD, TMP2\n  |  daddu PC, PC, RD\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  lbu TMP1, -4+OFS_RA(PC)\n  |   ld CRET1, 0(RA)\n  |  sll TMP1, TMP1, 3\n  |  daddu TMP1, BASE, TMP1\n  |  b ->cont_nop\n  |.   sd CRET1, 0(TMP1)\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  ld TMP0, 0(RA)\n  |  gettp TMP0, TMP0\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  negu TMP2, AT\t\t\t// Branch if result is true.\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  ld TMP0, 0(RA)\n  |  gettp TMP0, TMP0\n  |  sltiu AT, TMP0, LJ_TISTRUECOND\n  |  b <4\n  |.  addiu TMP2, AT, -1\t\t// Branch if result is false.\n  |\n  |->vmeta_equal:\n  |  // CARG1/CARG2 point to o1/o2. TMP0 is set to 0/1.\n  |  load_got lj_meta_equal\n  |   cleartp LFUNC:CARG3, CARG2\n  |  cleartp LFUNC:CARG2, CARG1\n  |    move CARG4, TMP0\n  |  daddiu PC, PC, -4\n  |   sd BASE, L->base\n  |   sd PC, SAVE_PC\n  |  call_intern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  load_got lj_meta_equal_cd\n  |  move CARG2, INS\n  |  daddiu PC, PC, -4\n  |   sd BASE, L->base\n  |   sd PC, SAVE_PC\n  |  call_intern lj_meta_equal_cd\t// (lua_State *L, BCIns op)\n  |.  move CARG1, L\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |->vmeta_istype:\n  |  load_got lj_meta_istype\n  |  daddiu PC, PC, -4\n  |   sd BASE, L->base\n  |   srl CARG2, RA, 3\n  |   srl CARG3, RD, 3\n  |  sd PC, SAVE_PC\n  |  call_intern lj_meta_istype\t// (lua_State *L, BCReg ra, BCReg tp)\n  |.  move CARG1, L\n  |  b ->cont_nop\n  |.  nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_unm:\n  |  move RC, RB\n  |\n  |->vmeta_arith:\n  |  load_got lj_meta_arith\n  |   sd BASE, L->base\n  |  move CARG2, RA\n  |   sd PC, SAVE_PC\n  |  move CARG3, RB\n  |  move CARG4, RC\n  |  decode_OP1 CARG5, INS\t// CARG5 == RB.\n  |  call_intern lj_meta_arith\t// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |.  move CARG1, L\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  beqz CRET1, ->cont_nop\n  |.  nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  dsubu TMP1, CRET1, BASE\n  |   sd PC, -24(CRET1)\t\t\t// [cont|PC]\n  |   move TMP2, BASE\n  |  daddiu PC, TMP1, FRAME_CONT\n  |   move BASE, CRET1\n  |  b ->vm_call_dispatch\n  |.  li NARGS8:RC, 16\t\t\t// 2 args for func(o1, o2).\n  |\n  |->vmeta_len:\n  |  // CARG2 already set by BC_LEN.\n#if LJ_52\n  |  move MULTRES, CARG1\n#endif\n  |  load_got lj_meta_len\n  |   sd BASE, L->base\n  |   sd PC, SAVE_PC\n  |  call_intern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |.  move CARG1, L\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  bnez CRET1, ->vmeta_binop\t\t// Binop call for compatibility.\n  |.  nop\n  |  b ->BC_LEN_Z\n  |.  move CARG1, MULTRES\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |.  nop\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sd TMP2, L->base\t\t\t// This is the callers base!\n  |  daddiu CARG2, BASE, -16\n  |   sd PC, SAVE_PC\n  |  daddu CARG3, BASE, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   daddiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |  cleartp LFUNC:RB\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  load_got lj_meta_call\n  |   sd BASE, L->base\n  |  daddiu CARG2, RA, -16\n  |   sd PC, SAVE_PC\n  |  daddu CARG3, RA, RC\n  |   move MULTRES, NARGS8:RC\n  |  call_intern lj_meta_call\t\t// (lua_State *L, TValue *func, TValue *top)\n  |.  move CARG1, L\n  |   ld RB, FRAME_FUNC(RA)\t\t// Guaranteed to be a function here.\n  |  ld TMP1, FRAME_PC(BASE)\n  |  daddiu NARGS8:RC, MULTRES, 8\t// Got one more argument now.\n  |  b ->BC_CALLT_Z\n  |.  cleartp LFUNC:CARG3, RB\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  load_got lj_meta_for\n  |   sd BASE, L->base\n  |  move CARG2, RA\n  |   sd PC, SAVE_PC\n  |  move MULTRES, INS\n  |  call_intern lj_meta_for\t// (lua_State *L, TValue *base)\n  |.  move CARG1, L\n  |.if JIT\n  |  decode_OP1 TMP0, MULTRES\n  |  li AT, BC_JFORI\n  |.endif\n  |  decode_RA8a RA, MULTRES\n  |   decode_RD8a RD, MULTRES\n  |  decode_RA8b RA\n  |.if JIT\n  |  beq TMP0, AT, =>BC_JFORI\n  |.  decode_RD8b RD\n  |  b =>BC_FORI\n  |.  nop\n  |.else\n  |  b =>BC_FORI\n  |.  decode_RD8b RD\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  ld CARG1, 0(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  sltiu AT, NARGS8:RC, 16\n  |  ld CARG1, 0(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  ld CARG2, 8(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  ld CARG1, 0(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |  // Either ldc1 or the 1st instruction of checknum is in the delay slot.\n  |  .FPU ldc1 FARG1, 0(BASE)\n  |  checknum CARG1, ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\t// Caveat: has delay slot!\n  |->ff_ .. name:\n  |  ld CARG1, 0(BASE)\n  |    sltiu AT, NARGS8:RC, 16\n  |   ld CARG2, 8(BASE)\n  |  bnez AT, ->fff_fallback\n  |.  gettp TMP0, CARG1\n  |   gettp TMP1, CARG2\n  |  sltiu TMP0, TMP0, LJ_TISNUM\n  |   sltiu TMP1, TMP1, LJ_TISNUM\n  |  .FPU ldc1 FARG1, 0(BASE)\n  |  and TMP0, TMP0, TMP1\n  |   .FPU ldc1 FARG2, 8(BASE)\n  |  beqz TMP0, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!\n  |// MIPSR6: no delay slot, but a forbidden slot.\n  |.macro ffgccheck\n  |  ld TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n  |  ld TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n  |  dsubu AT, TMP0, TMP1\n  |.if MIPSR6\n  |  bgezalc AT, ->fff_gcstep\n  |.else\n  |  bgezal AT, ->fff_gcstep\n  |.endif\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |.ffunc_1 assert\n  |  gettp AT, CARG1\n  |  sltiu AT, AT, LJ_TISTRUECOND\n  |  beqz AT, ->fff_fallback\n  |.  daddiu RA, BASE, -16\n  |  ld PC, FRAME_PC(BASE)\n  |  addiu RD, NARGS8:RC, 8\t\t// Compute (nresults+1)*8.\n  |  daddu TMP2, RA, RD\n  |  daddiu TMP1, BASE, 8\n  |  beq BASE, TMP2, ->fff_res\t\t// Done if exactly 1 argument.\n  |.  sd CARG1, 0(RA)\n  |1:\n  |  ld CRET1, 0(TMP1)\n  |  sd CRET1, -16(TMP1)\n  |  bne TMP1, TMP2, <1\n  |.  daddiu TMP1, TMP1, 8\n  |  b ->fff_res\n  |.  nop\n  |\n  |.ffunc_1 type\n  |  gettp TMP0, CARG1\n  |  sltu TMP1, TISNUM, TMP0\n  |  not TMP2, TMP0\n  |  li TMP3, ~LJ_TISNUM\n  |.if MIPSR6\n  |  selnez TMP2, TMP2, TMP1\n  |  seleqz TMP3, TMP3, TMP1\n  |  or TMP2, TMP2, TMP3\n  |.else\n  |  movz TMP2, TMP3, TMP1\n  |.endif\n  |  dsll TMP2, TMP2, 3\n  |  daddu TMP2, CFUNC:RB, TMP2\n  |  b ->fff_restv\n  |.  ld CARG1, CFUNC:TMP2->upvalue\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  gettp TMP2, CARG1\n  |  daddiu TMP0, TMP2, -LJ_TTAB\n  |  daddiu TMP1, TMP2, -LJ_TUDATA\n  |.if MIPSR6\n  |  selnez TMP0, TMP1, TMP0\n  |.else\n  |  movn TMP0, TMP1, TMP0\n  |.endif\n  |  bnez TMP0, >6\n  |.  cleartp TAB:CARG1\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  ld TAB:RB, TAB:CARG1->metatable\n  |2:\n  |  ld STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)\n  |  beqz TAB:RB, ->fff_restv\n  |.  li CARG1, LJ_TNIL\n  |  lw TMP0, TAB:RB->hmask\n  |   lw TMP1, STR:RC->sid\n  |    ld NODE:TMP2, TAB:RB->node\n  |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n  |  dsll TMP0, TMP1, 5\n  |  dsll TMP1, TMP1, 3\n  |  dsubu TMP1, TMP0, TMP1\n  |  daddu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n  |  li CARG4, LJ_TSTR\n  |  settp STR:RC, CARG4\t\t// Tagged key to look for.\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  ld TMP0, NODE:TMP2->key\n  |   ld CARG1, NODE:TMP2->val\n  |    ld NODE:TMP2, NODE:TMP2->next\n  |  beq RC, TMP0, >5\n  |.  li AT, LJ_TTAB\n  |  bnez NODE:TMP2, <3\n  |.  nop\n  |4:\n  |  move CARG1, RB\n  |  b ->fff_restv\t\t\t// Not found, keep default result.\n  |.  settp CARG1, AT\n  |5:\n  |  bne CARG1, TISNIL, ->fff_restv\n  |.  nop\n  |  b <4\t\t\t\t// Ditto for nil value.\n  |.  nop\n  |\n  |6:\n  |  sltiu AT, TMP2, LJ_TISNUM\n  |.if MIPSR6\n  |  selnez TMP0, TISNUM, AT\n  |  seleqz AT, TMP2, AT\n  |  or TMP2, TMP0, AT\n  |.else\n  |  movn TMP2, TISNUM, AT\n  |.endif\n  |  dsll TMP2, TMP2, 3\n  |   dsubu TMP0, DISPATCH, TMP2\n  |  b <2\n  |.  ld TAB:RB, DISPATCH_GL(gcroot[GCROOT_BASEMT])-8(TMP0)\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  checktp TMP1, CARG1, -LJ_TTAB, ->fff_fallback\n  |  gettp TMP3, CARG2\n  |   ld TAB:TMP0, TAB:TMP1->metatable\n  |   lbu TMP2, TAB:TMP1->marked\n  |  daddiu AT, TMP3, -LJ_TTAB\n  |   cleartp TAB:CARG2\n  |  or AT, AT, TAB:TMP0\n  |  bnez AT, ->fff_fallback\n  |.  andi AT, TMP2, LJ_GC_BLACK\t// isblack(table)\n  |  beqz AT, ->fff_restv\n  |.  sd TAB:CARG2, TAB:TMP1->metatable\n  |  barrierback TAB:TMP1, TMP2, TMP0, ->fff_restv\n  |\n  |.ffunc rawget\n  |  ld CARG2, 0(BASE)\n  |  sltiu AT, NARGS8:RC, 16\n  |  load_got lj_tab_get\n  |  gettp TMP0, CARG2\n  |   cleartp CARG2\n  |  daddiu TMP0, TMP0, -LJ_TTAB\n  |  or AT, AT, TMP0\n  |  bnez AT, ->fff_fallback\n  |.  daddiu CARG3, BASE, 8\n  |  call_intern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |.  move CARG1, L\n  |  b ->fff_restv\n  |.  ld CARG1, 0(CRET1)\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  ld CARG1, 0(BASE)\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly one number argument.\n  |  gettp TMP1, CARG1\n  |  sltu TMP0, TISNUM, TMP1\n  |  or AT, AT, TMP0\n  |  bnez AT, ->fff_fallback\n  |.  nop\n  |  b ->fff_restv\n  |.  nop\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  gettp TMP0, CARG1\n  |  daddiu AT, TMP0, -LJ_TSTR\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beqz AT, ->fff_restv\t// String key?\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |.  ld TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)\n  |  sltu TMP0, TISNUM, TMP0\n  |  or TMP0, TMP0, TMP1\n  |  bnez TMP0, ->fff_fallback\n  |.  sd BASE, L->base\t\t\t// Add frame since C call can throw.\n  |.if MIPSR6\n  |  sd PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  ffgccheck\n  |.else\n  |  ffgccheck\n  |.  sd PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |.endif\n  |  load_got lj_strfmt_number\n  |  move CARG1, L\n  |  call_intern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |.  move CARG2, BASE\n  |  // Returns GCstr *.\n  |  li AT, LJ_TSTR\n  |  settp CRET1, AT\n  |  b ->fff_restv\n  |.  move CARG1, CRET1\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  checktp CARG1, -LJ_TTAB, ->fff_fallback\n  |  daddu TMP2, BASE, NARGS8:RC\n  |  sd TISNIL, 0(TMP2)\t\t\t// Set missing 2nd arg to nil.\n  |  load_got lj_tab_next\n  |  ld PC, FRAME_PC(BASE)\n  |  daddiu CARG2, BASE, 8\n  |  call_intern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |.  daddiu CARG3, BASE, -16\n  |  // Returns 1=found, 0=end, -1=error.\n  |   daddiu RA, BASE, -16\n  |  bgtz CRET1, ->fff_res\t\t// Found key/value.\n  |.  li RD, (2+1)*8\n  |  beqz CRET1, ->fff_restv\t\t// End of traversal: return nil.\n  |.  move CARG1, TISNIL\n  |   ld CFUNC:RB, FRAME_FUNC(BASE)\n  |   cleartp CFUNC:RB\n  |  b ->fff_fallback\t\t\t// Invalid key.\n  |.  li RC, 2*8\n  |\n  |.ffunc_1 pairs\n  |  checktp TAB:TMP1, CARG1, -LJ_TTAB, ->fff_fallback\n  |  ld PC, FRAME_PC(BASE)\n#if LJ_52\n  |  ld TAB:TMP2, TAB:TMP1->metatable\n  |  ld TMP0, CFUNC:RB->upvalue[0]\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  ld TMP0, CFUNC:RB->upvalue[0]\n#endif\n  |.  daddiu RA, BASE, -16\n  |  sd TISNIL, 0(BASE)\n  |   sd CARG1, -8(BASE)\n  |    sd TMP0, 0(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |.ffunc_2 ipairs_aux\n  |  checktab CARG1, ->fff_fallback\n  |   checkint CARG2, ->fff_fallback\n  |.  lw TMP0, TAB:CARG1->asize\n  |   ld TMP1, TAB:CARG1->array\n  |    ld PC, FRAME_PC(BASE)\n  |  sextw TMP2, CARG2\n  |  addiu TMP2, TMP2, 1\n  |  sltu AT, TMP2, TMP0\n  |    daddiu RA, BASE, -16\n  |   zextw TMP0, TMP2\n  |   settp TMP0, TISNUM\n  |  beqz AT, >2\t\t\t// Not in array part?\n  |.  sd TMP0, 0(RA)\n  |  dsll TMP3, TMP2, 3\n  |  daddu TMP3, TMP1, TMP3\n  |  ld TMP1, 0(TMP3)\n  |1:\n  |  beq TMP1, TISNIL, ->fff_res\t// End of iteration, return 0 results.\n  |.  li RD, (0+1)*8\n  |  sd TMP1, -8(BASE)\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lw TMP0, TAB:CARG1->hmask\n  |  load_got lj_tab_getinth\n  |  beqz TMP0, ->fff_res\n  |.  li RD, (0+1)*8\n  |  call_intern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |.  move CARG2, TMP2\n  |  // Returns cTValue * or NULL.\n  |  beqz CRET1, ->fff_res\n  |.  li RD, (0+1)*8\n  |  b <1\n  |.  ld TMP1, 0(CRET1)\n  |\n  |.ffunc_1 ipairs\n  |  checktp TAB:TMP1, CARG1, -LJ_TTAB, ->fff_fallback\n  |  ld PC, FRAME_PC(BASE)\n#if LJ_52\n  |  ld TAB:TMP2, TAB:TMP1->metatable\n  |  ld CFUNC:TMP0, CFUNC:RB->upvalue[0]\n  |  bnez TAB:TMP2, ->fff_fallback\n#else\n  |  ld TMP0, CFUNC:RB->upvalue[0]\n#endif\n  |  daddiu RA, BASE, -16\n  |  dsll AT, TISNUM, 47\n  |  sd CARG1, -8(BASE)\n  |   sd AT, 0(BASE)\n  |    sd CFUNC:TMP0, 0(RA)\n  |  b ->fff_res\n  |.  li RD, (3+1)*8\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  daddiu NARGS8:RC, NARGS8:RC, -8\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  bltz NARGS8:RC, ->fff_fallback\n  |.   move TMP2, BASE\n  |   daddiu BASE, BASE, 16\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |  andi TMP3, TMP3, 1\n  |  daddiu PC, TMP3, 16+FRAME_PCALL\n  |  beqz NARGS8:RC, ->vm_call_dispatch\n  |1:\n  |.  daddu TMP0, BASE, NARGS8:RC\n  |2:\n  |  ld TMP1, -16(TMP0)\n  |  sd TMP1, -8(TMP0)\n  |  daddiu TMP0, TMP0, -8\n  |  bne TMP0, BASE, <2\n  |.  nop\n  |  b ->vm_call_dispatch\n  |.  nop\n  |\n  |.ffunc xpcall\n  |  daddiu NARGS8:TMP0, NARGS8:RC, -16\n  |  ld CARG1, 0(BASE)\n  |   ld CARG2, 8(BASE)\n  |    bltz NARGS8:TMP0, ->fff_fallback\n  |.    lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)\n  |  gettp AT, CARG2\n  |  daddiu AT, AT, -LJ_TFUNC\n  |  bnez AT, ->fff_fallback\t\t// Traceback must be a function.\n  |.   move TMP2, BASE\n  |  move NARGS8:RC, NARGS8:TMP0\n  |   daddiu BASE, BASE, 24\n  |  // Remember active hook before pcall.\n  |  srl TMP3, TMP3, HOOK_ACTIVE_SHIFT\n  |   sd CARG2, 0(TMP2)\t\t\t// Swap function and traceback.\n  |  andi TMP3, TMP3, 1\n  |   sd CARG1, 8(TMP2)\n  |  beqz NARGS8:RC, ->vm_call_dispatch\n  |.  daddiu PC, TMP3, 24+FRAME_PCALL\n  |  b <1\n  |.  nop\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  checktp CARG1, CARG1, -LJ_TTHREAD, ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  ld L:CARG1, CFUNC:RB->upvalue[0].gcr\n  |  cleartp L:CARG1\n  |.endif\n  |  lbu TMP0, L:CARG1->status\n  |   ld TMP1, L:CARG1->cframe\n  |    ld CARG2, L:CARG1->top\n  |    ld TMP2, L:CARG1->base\n  |  addiu AT, TMP0, -LUA_YIELD\n  |    daddu CARG3, CARG2, TMP0\n  |   daddiu TMP3, CARG2, 8\n  |.if MIPSR6\n  |  seleqz CARG2, CARG2, AT\n  |  selnez TMP3, TMP3, AT\n  |  bgtz AT, ->fff_fallback\t\t// st > LUA_YIELD?\n  |.  or CARG2, TMP3, CARG2\n  |.else\n  |  bgtz AT, ->fff_fallback\t\t// st > LUA_YIELD?\n  |.  movn CARG2, TMP3, AT\n  |.endif\n  |   xor TMP2, TMP2, CARG3\n  |  bnez TMP1, ->fff_fallback\t\t// cframe != 0?\n  |.  or AT, TMP2, TMP0\n  |  ld TMP0, L:CARG1->maxstack\n  |  beqz AT, ->fff_fallback\t\t// base == top && st == 0?\n  |.  ld PC, FRAME_PC(BASE)\n  |  daddu TMP2, CARG2, NARGS8:RC\n  |  sltu AT, TMP0, TMP2\n  |  bnez AT, ->fff_fallback\t\t// Stack overflow?\n  |.  sd PC, SAVE_PC\n  |   sd BASE, L->base\n  |1:\n  |.if resume\n  |  daddiu BASE, BASE, 8\t\t// Keep resumed thread in stack for GC.\n  |  daddiu NARGS8:RC, NARGS8:RC, -8\n  |  daddiu TMP2, TMP2, -8\n  |.endif\n  |  sd TMP2, L:CARG1->top\n  |  daddu TMP1, BASE, NARGS8:RC\n  |  move CARG3, CARG2\n  |  sd BASE, L->top\n  |2:  // Move args to coroutine.\n  |   ld CRET1, 0(BASE)\n  |  sltu AT, BASE, TMP1\n  |  beqz AT, >3\n  |.  daddiu BASE, BASE, 8\n  |   sd CRET1, 0(CARG3)\n  |  b <2\n  |.  daddiu CARG3, CARG3, 8\n  |3:\n  |  bal ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |.  move L:RA, L:CARG1\n  |  // Returns thread status.\n  |4:\n  |  ld TMP2, L:RA->base\n  |   sltiu AT, CRET1, LUA_YIELD+1\n  |  ld TMP3, L:RA->top\n  |    li_vmstate INTERP\n  |  ld BASE, L->base\n  |    sd L, DISPATCH_GL(cur_L)(DISPATCH)\n  |    st_vmstate\n  |   beqz AT, >8\n  |. dsubu RD, TMP3, TMP2\n  |   ld TMP0, L->maxstack\n  |  beqz RD, >6\t\t\t// No results?\n  |.  daddu TMP1, BASE, RD\n  |  sltu AT, TMP0, TMP1\n  |  bnez AT, >9\t\t\t// Need to grow stack?\n  |.  daddu TMP3, TMP2, RD\n  |  sd TMP2, L:RA->top\t\t\t// Clear coroutine stack.\n  |  move TMP1, BASE\n  |5:  // Move results from coroutine.\n  |   ld CRET1, 0(TMP2)\n  |  daddiu TMP2, TMP2, 8\n  |  sltu AT, TMP2, TMP3\n  |   sd CRET1, 0(TMP1)\n  |  bnez AT, <5\n  |.  daddiu TMP1, TMP1, 8\n  |6:\n  |  andi TMP0, PC, FRAME_TYPE\n  |.if resume\n  |  mov_true TMP1\n  |   daddiu RA, BASE, -8\n  |  sd TMP1, -8(BASE)\t\t\t// Prepend true to results.\n  |  daddiu RD, RD, 16\n  |.else\n  |  move RA, BASE\n  |  daddiu RD, RD, 8\n  |.endif\n  |7:\n  |  sd PC, SAVE_PC\n  |  beqz TMP0, ->BC_RET_Z\n  |.  move MULTRES, RD\n  |  b ->vm_return\n  |.  nop\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  daddiu TMP3, TMP3, -8\n  |   mov_false TMP1\n  |  ld CRET1, 0(TMP3)\n  |   sd TMP3, L:RA->top\t\t// Remove error from coroutine stack.\n  |    li RD, (2+1)*8\n  |   sd TMP1, -8(BASE)\t\t\t// Prepend false to results.\n  |    daddiu RA, BASE, -8\n  |  sd CRET1, 0(BASE)\t\t\t// Copy error message.\n  |  b <7\n  |.  andi TMP0, PC, FRAME_TYPE\n  |.else\n  |  load_got lj_ffh_coroutine_wrap_err\n  |  move CARG2, L:RA\n  |  call_intern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |.  move CARG1, L\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  load_got lj_state_growstack\n  |  srl CARG2, RD, 3\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  b <4\n  |.  li CRET1, 0\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  ld TMP0, L->cframe\n  |   daddu TMP1, BASE, NARGS8:RC\n  |   sd BASE, L->base\n  |  andi TMP0, TMP0, CFRAME_RESUME\n  |   sd TMP1, L->top\n  |  beqz TMP0, ->fff_fallback\n  |.   li CRET1, LUA_YIELD\n  |  sd r0, L->cframe\n  |  b ->vm_leave_unw\n  |.   sb CRET1, L->status\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  gettp CARG2, CARG1\n  |  daddiu AT, CARG2, -LJ_TISNUM\n  |  bnez AT, >1\n  |.  sextw TMP1, CARG1\n  |  sra TMP0, TMP1, 31\t\t\t// Extract sign.\n  |  xor TMP1, TMP1, TMP0\n  |  dsubu CARG1, TMP1, TMP0\n  |  dsll TMP3, CARG1, 32\n  |  bgez TMP3, ->fff_restv\n  |.  settp CARG1, TISNUM\n  |  li CARG1, 0x41e0\t\t\t// 2^31 as a double.\n  |  b ->fff_restv\n  |.  dsll CARG1, CARG1, 48\n  |1:\n  |  sltiu AT, CARG2, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  dextm CARG1, CARG1, 0, 30\n  |// fallthrough\n  |\n  |->fff_restv:\n  |  // CARG1 = TValue result.\n  |  ld PC, FRAME_PC(BASE)\n  |  daddiu RA, BASE, -16\n  |   sd CARG1, -16(BASE)\n  |->fff_res1:\n  |  // RA = results, PC = return.\n  |  li RD, (1+1)*8\n  |->fff_res:\n  |  // RA = results, RD = (nresults+1)*8, PC = return.\n  |  andi TMP0, PC, FRAME_TYPE\n  |  bnez TMP0, ->vm_return\n  |.  move MULTRES, RD\n  |  lw INS, -4(PC)\n  |  decode_RB8a RB, INS\n  |  decode_RB8b RB\n  |5:\n  |  sltu AT, RD, RB\n  |  bnez AT, >6\t\t\t// More results expected?\n  |.  decode_RA8a TMP0, INS\n  |  decode_RA8b TMP0\n  |  ins_next1\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |   dsubu BASE, RA, TMP0\n  |  ins_next2\n  |\n  |6:  // Fill up results with nil.\n  |  daddu TMP1, RA, RD\n  |   daddiu RD, RD, 8\n  |  b <5\n  |.  sd TISNIL, -8(TMP1)\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  load_got func\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |.  load_got func\n  |  call_extern\n  |.  nop\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |// TODO: Return integer type if result is integer (own sf implementation).\n  |.macro math_round, func\n  |->ff_math_ .. func:\n  |  ld CARG1, 0(BASE)\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  gettp TMP0, CARG1\n  |  beq TMP0, TISNUM, ->fff_restv\n  |.  sltu AT, TMP0, TISNUM\n  |  beqz AT, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  bal ->vm_ .. func\n  |.  nop\n  |.else\n  |.  load_got func\n  |  call_extern\n  |.  nop\n  |.endif\n  |  b ->fff_resn\n  |.  nop\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  li AT, 8\n  |  bne NARGS8:RC, AT, ->fff_fallback\t// Exactly 1 argument.\n  |.  ld CARG1, 0(BASE)\n  |  checknum CARG1, ->fff_fallback\n  |.  load_got log\n  |.if FPU\n  |  call_extern\n  |.  ldc1 FARG1, 0(BASE)\n  |.else\n  |  call_extern\n  |.  nop\n  |.endif\n  |  b ->fff_resn\n  |.  nop\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if FPU\n  |.ffunc_n math_sqrt\n  |.  sqrt.d FRET1, FARG1\n  |// fallthrough to ->fff_resn\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |->fff_resn:\n  |  ld PC, FRAME_PC(BASE)\n  |  daddiu RA, BASE, -16\n  |  b ->fff_res1\n  |.if FPU\n  |.  sdc1 FRET1, 0(RA)\n  |.else\n  |.  sd CRET1, 0(RA)\n  |.endif\n  |\n  |\n  |.ffunc_2 math_ldexp\n  |  checknum CARG1, ->fff_fallback\n  |  checkint CARG2, ->fff_fallback\n  |.  load_got ldexp\n  |  .FPU ldc1 FARG1, 0(BASE)\n  |  call_extern\n  |.  lw CARG2, 8+LO(BASE)\n  |  b ->fff_resn\n  |.  nop\n  |\n  |.ffunc_n math_frexp\n  |  load_got frexp\n  |   ld PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  daddiu CARG2, DISPATCH, DISPATCH_GL(tmptv)\n  |   lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)\n  |  daddiu RA, BASE, -16\n  |.if FPU\n  |   mtc1 TMP1, FARG2\n  |  sdc1 FRET1, 0(RA)\n  |   cvt.d.w FARG2, FARG2\n  |   sdc1 FARG2, 8(RA)\n  |.else\n  |  sd CRET1, 0(RA)\n  |  zextw TMP1, TMP1\n  |  settp TMP1, TISNUM\n  |  sd TMP1, 8(RA)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.ffunc_n math_modf\n  |  load_got modf\n  |   ld PC, FRAME_PC(BASE)\n  |  call_extern\n  |.  daddiu CARG2, BASE, -16\n  |  daddiu RA, BASE, -16\n  |.if FPU\n  |  sdc1 FRET1, -8(BASE)\n  |.else\n  |  sd CRET1, -8(BASE)\n  |.endif\n  |  b ->fff_res\n  |.  li RD, (2+1)*8\n  |\n  |.macro math_minmax, name, intins, intinsc, fpins\n  |  .ffunc_1 name\n  |  daddu TMP3, BASE, NARGS8:RC\n  |  checkint CARG1, >5\n  |.  daddiu TMP2, BASE, 8\n  |1:  // Handle integers.\n  |  beq TMP2, TMP3, ->fff_restv\n  |.  ld CARG2, 0(TMP2)\n  |  checkint CARG2, >3\n  |.  sextw CARG1, CARG1\n  |  lw CARG2, LO(TMP2)\n  |.  slt AT, CARG1, CARG2\n  |.if MIPSR6\n  |  intins TMP1, CARG2, AT\n  |  intinsc CARG1, CARG1, AT\n  |  or CARG1, CARG1, TMP1\n  |.else\n  |  intins CARG1, CARG2, AT\n  |.endif\n  |  daddiu TMP2, TMP2, 8\n  |  zextw CARG1, CARG1\n  |  b <1\n  |.  settp CARG1, TISNUM\n  |\n  |3:  // Convert intermediate result to number and continue with number loop.\n  |  checknum CARG2, ->fff_fallback\n  |.if FPU\n  |.  mtc1 CARG1, FRET1\n  |  cvt.d.w FRET1, FRET1\n  |  b >7\n  |.  ldc1 FARG1, 0(TMP2)\n  |.else\n  |.  nop\n  |  bal ->vm_sfi2d_1\n  |.  nop\n  |  b >7\n  |.  nop\n  |.endif\n  |\n  |5:\n  |  .FPU ldc1 FRET1, 0(BASE)\n  |  checknum CARG1, ->fff_fallback\n  |6:  // Handle numbers.\n  |.  ld CARG2, 0(TMP2)\n  |  beq TMP2, TMP3, ->fff_resn\n  |.if FPU\n  |  ldc1 FARG1, 0(TMP2)\n  |.else\n  |  move CRET1, CARG1\n  |.endif\n  |  checknum CARG2, >8\n  |.  nop\n  |7:\n  |.if FPU\n  |.if MIPSR6\n  |  fpins FRET1, FRET1, FARG1\n  |.else\n  |.if fpins  // ismax\n  |  c.olt.d FARG1, FRET1\n  |.else\n  |  c.olt.d FRET1, FARG1\n  |.endif\n  |  movf.d FRET1, FARG1\n  |.endif\n  |.else\n  |.if fpins  // ismax\n  |  bal ->vm_sfcmpogt\n  |.else\n  |  bal ->vm_sfcmpolt\n  |.endif\n  |.  nop\n  |.if MIPSR6\n  |  seleqz AT, CARG2, CRET1\n  |  selnez CARG1, CARG1, CRET1\n  |  or CARG1, CARG1, AT\n  |.else\n  |  movz CARG1, CARG2, CRET1\n  |.endif\n  |.endif\n  |  b <6\n  |.  daddiu TMP2, TMP2, 8\n  |\n  |8:  // Convert integer to number and continue with number loop.\n  |  checkint CARG2, ->fff_fallback\n  |.if FPU\n  |.  lwc1 FARG1, LO(TMP2)\n  |  b <7\n  |.  cvt.d.w FARG1, FARG1\n  |.else\n  |.  lw CARG2, LO(TMP2)\n  |  bal ->vm_sfi2d_2\n  |.  nop\n  |  b <7\n  |.  nop\n  |.endif\n  |\n  |.endmacro\n  |\n  |.if MIPSR6\n  |  math_minmax math_min, seleqz, selnez, min.d\n  |  math_minmax math_max, selnez, seleqz, max.d\n  |.else\n  |  math_minmax math_min, movz, _, 0\n  |  math_minmax math_max, movn, _, 1\n  |.endif\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  ld CARG1, 0(BASE)\n  |  gettp TMP0, CARG1\n  |  xori AT, NARGS8:RC, 8\n  |  daddiu TMP0, TMP0, -LJ_TSTR\n  |  or AT, AT, TMP0\n  |  bnez AT, ->fff_fallback\t\t// Need exactly 1 string argument.\n  |.  cleartp STR:CARG1\n  |  lw TMP0, STR:CARG1->len\n  |    daddiu RA, BASE, -16\n  |    ld PC, FRAME_PC(BASE)\n  |  sltu RD, r0, TMP0\n  |   lbu TMP1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |  addiu RD, RD, 1\n  |  sll RD, RD, 3\t\t\t// RD = ((str->len != 0)+1)*8\n  |  settp TMP1, TISNUM\n  |  b ->fff_res\n  |.  sd TMP1, 0(RA)\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |.if not MIPSR6\n  |.  nop\n  |.endif\n  |  ld CARG1, 0(BASE)\n  |  gettp TMP0, CARG1\n  |  xori AT, NARGS8:RC, 8\t\t// Exactly 1 argument.\n  |  daddiu TMP0, TMP0, -LJ_TISNUM\t// Integer.\n  |  li TMP1, 255\n  |   sextw CARG1, CARG1\n  |  or AT, AT, TMP0\n  |   sltu TMP1, TMP1, CARG1\t\t// !(255 < n).\n  |   or AT, AT, TMP1\n  |  bnez AT, ->fff_fallback\n  |.  li CARG3, 1\n  |  daddiu CARG2, sp, TMPD_OFS\n  |  sb CARG1, TMPD\n  |->fff_newstr:\n  |  load_got lj_str_new\n  |   sd BASE, L->base\n  |   sd PC, SAVE_PC\n  |  call_intern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |.  move CARG1, L\n  |  // Returns GCstr *.\n  |  ld BASE, L->base\n  |->fff_resstr:\n  |  li AT, LJ_TSTR\n  |  settp CRET1, AT\n  |  b ->fff_restv\n  |.  move CARG1, CRET1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |.if not MIPSR6\n  |.  nop\n  |.endif\n  |  addiu AT, NARGS8:RC, -16\n  |  ld TMP0, 0(BASE)\n  |  bltz AT, ->fff_fallback\n  |.  gettp TMP3, TMP0\n  |  cleartp STR:CARG1, TMP0\n  |  ld CARG2, 8(BASE)\n  |  beqz AT, >1\n  |.  li CARG4, -1\n  |  ld CARG3, 16(BASE)\n  |  checkint CARG3, ->fff_fallback\n  |.  sextw CARG4, CARG3\n  |1:\n  |  checkint CARG2, ->fff_fallback\n  |.  li AT, LJ_TSTR\n  |  bne TMP3, AT, ->fff_fallback\n  |.  sextw CARG3, CARG2\n  |  lw CARG2, STR:CARG1->len\n  |  // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end\n  |  slt AT, CARG4, r0\n  |  addiu TMP0, CARG2, 1\n  |  addu TMP1, CARG4, TMP0\n  |   slt TMP3, CARG3, r0\n  |.if MIPSR6\n  |  seleqz CARG4, CARG4, AT\n  |  selnez TMP1, TMP1, AT\n  |  or CARG4, TMP1, CARG4\t\t// if (end < 0) end += len+1\n  |.else\n  |  movn CARG4, TMP1, AT\t\t// if (end < 0) end += len+1\n  |.endif\n  |   addu TMP1, CARG3, TMP0\n  |.if MIPSR6\n  |   selnez TMP1, TMP1, TMP3\n  |   seleqz CARG3, CARG3, TMP3\n  |   or CARG3, TMP1, CARG3\t\t// if (start < 0) start += len+1\n  |   li TMP2, 1\n  |  slt AT, CARG4, r0\n  |   slt TMP3, r0, CARG3\n  |  seleqz CARG4, CARG4, AT\t\t// if (end < 0) end = 0\n  |   selnez CARG3, CARG3, TMP3\n  |   seleqz TMP2, TMP2, TMP3\n  |   or CARG3, TMP2, CARG3\t\t// if (start < 1) start = 1\n  |  slt AT, CARG2, CARG4\n  |  seleqz CARG4, CARG4, AT\n  |  selnez CARG2, CARG2, AT\n  |  or CARG4, CARG2, CARG4\t\t// if (end > len) end = len\n  |.else\n  |   movn CARG3, TMP1, TMP3\t\t// if (start < 0) start += len+1\n  |   li TMP2, 1\n  |  slt AT, CARG4, r0\n  |   slt TMP3, r0, CARG3\n  |  movn CARG4, r0, AT\t\t\t// if (end < 0) end = 0\n  |   movz CARG3, TMP2, TMP3\t\t// if (start < 1) start = 1\n  |  slt AT, CARG2, CARG4\n  |  movn CARG4, CARG2, AT\t\t// if (end > len) end = len\n  |.endif\n  |   daddu CARG2, STR:CARG1, CARG3\n  |  subu CARG3, CARG4, CARG3\t\t// len = end - start\n  |   daddiu CARG2, CARG2, sizeof(GCstr)-1\n  |  bgez CARG3, ->fff_newstr\n  |.  addiu CARG3, CARG3, 1\t\t// len++\n  |->fff_emptystr:  // Return empty string.\n  |  li AT, LJ_TSTR\n  |  daddiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty)\n  |  b ->fff_restv\n  |.  settp CARG1, AT\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |.  nop\n  |  beqz NARGS8:RC, ->fff_fallback\n  |.  ld CARG2, 0(BASE)\n  |  checkstr STR:CARG2, ->fff_fallback\n  |  daddiu SBUF:CARG1, DISPATCH, DISPATCH_GL(tmpbuf)\n  |  load_got lj_buf_putstr_ .. name\n  |  ld TMP0, SBUF:CARG1->b\n  |   sd L, SBUF:CARG1->L\n  |   sd BASE, L->base\n  |  sd TMP0, SBUF:CARG1->w\n  |  call_intern extern lj_buf_putstr_ .. name\n  |.  sd PC, SAVE_PC\n  |  load_got lj_buf_tostr\n  |  call_intern lj_buf_tostr\n  |.  move SBUF:CARG1, SBUF:CRET1\n  |  b ->fff_resstr\n  |.  ld BASE, L->base\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |->vm_tobit_fb:\n  |  beqz TMP1, ->fff_fallback\n  |.if FPU\n  |.  ldc1 FARG1, 0(BASE)\n  |  add.d FARG1, FARG1, TOBIT\n  |  mfc1 CRET1, FARG1\n  |  jr ra\n  |.  zextw CRET1, CRET1\n  |.else\n  |// FP number to bit conversion for soft-float.\n  |->vm_tobit:\n  |  dsll TMP0, CARG1, 1\n  |  li CARG3, 1076\n  |  dsrl AT, TMP0, 53\n  |  dsubu CARG3, CARG3, AT\n  |  sltiu AT, CARG3, 54\n  |  beqz AT, >1\n  |.  dextm TMP0, TMP0, 0, 20\n  |  dinsu TMP0, AT, 21, 21\n  |  slt AT, CARG1, r0\n  |  dsrlv CRET1, TMP0, CARG3\n  |  dsubu TMP0, r0, CRET1\n  |.if MIPSR6\n  |  selnez TMP0, TMP0, AT\n  |  seleqz CRET1, CRET1, AT\n  |  or CRET1, CRET1, TMP0\n  |.else\n  |  movn CRET1, TMP0, AT\n  |.endif\n  |  jr ra\n  |.  zextw CRET1, CRET1\n  |1:\n  |  jr ra\n  |.  move CRET1, r0\n  |\n  |// FP number to int conversion with a check for soft-float.\n  |// Modifies CARG1, CRET1, CRET2, TMP0, AT.\n  |->vm_tointg:\n  |.if JIT\n  |  dsll CRET2, CARG1, 1\n  |  beqz CRET2, >2\n  |.  li TMP0, 1076\n  |  dsrl AT, CRET2, 53\n  |  dsubu TMP0, TMP0, AT\n  |  sltiu AT, TMP0, 54\n  |  beqz AT, >1\n  |.  dextm CRET2, CRET2, 0, 20\n  |  dinsu CRET2, AT, 21, 21\n  |  slt AT, CARG1, r0\n  |  dsrlv CRET1, CRET2, TMP0\n  |  dsubu CARG1, r0, CRET1\n  |.if MIPSR6\n  |  seleqz CRET1, CRET1, AT\n  |  selnez CARG1, CARG1, AT\n  |  or CRET1, CRET1, CARG1\n  |.else\n  |  movn CRET1, CARG1, AT\n  |.endif\n  |  li CARG1, 64\n  |  subu TMP0, CARG1, TMP0\n  |  dsllv CRET2, CRET2, TMP0\t// Integer check.\n  |  sextw AT, CRET1\n  |  xor AT, CRET1, AT\t\t// Range check.\n  |.if MIPSR6\n  |  seleqz AT, AT, CRET2\n  |  selnez CRET2, CRET2, CRET2\n  |  jr ra\n  |.  or CRET2, AT, CRET2\n  |.else\n  |  jr ra\n  |.  movz CRET2, AT, CRET2\n  |.endif\n  |1:\n  |  jr ra\n  |.  li CRET2, 1\n  |2:\n  |  jr ra\n  |.  move CRET1, r0\n  |.endif\n  |.endif\n  |\n  |.macro .ffunc_bit, name\n  |  .ffunc_1 bit_..name\n  |  gettp TMP0, CARG1\n  |  beq TMP0, TISNUM, >6\n  |.  zextw CRET1, CARG1\n  |  bal ->vm_tobit_fb\n  |.  sltiu TMP1, TMP0, LJ_TISNUM\n  |6:\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, bins\n  |  .ffunc_bit name\n  |  daddiu TMP2, BASE, 8\n  |  daddu TMP3, BASE, NARGS8:RC\n  |1:\n  |  beq TMP2, TMP3, ->fff_resi\n  |.  ld CARG1, 0(TMP2)\n  |  gettp TMP0, CARG1\n  |.if FPU\n  |  bne TMP0, TISNUM, >2\n  |.  daddiu TMP2, TMP2, 8\n  |  zextw CARG1, CARG1\n  |  b <1\n  |.  bins CRET1, CRET1, CARG1\n  |2:\n  |   ldc1 FARG1, -8(TMP2)\n  |  sltiu AT, TMP0, LJ_TISNUM\n  |  beqz AT, ->fff_fallback\n  |.  add.d FARG1, FARG1, TOBIT\n  |  mfc1 CARG1, FARG1\n  |  zextw CARG1, CARG1\n  |  b <1\n  |.  bins CRET1, CRET1, CARG1\n  |.else\n  |  beq TMP0, TISNUM, >2\n  |.  move CRET2, CRET1\n  |  bal ->vm_tobit_fb\n  |.  sltiu TMP1, TMP0, LJ_TISNUM\n  |  move CARG1, CRET2\n  |2:\n  |  zextw CARG1, CARG1\n  |  bins CRET1, CRET1, CARG1\n  |  b <1\n  |.  daddiu TMP2, TMP2, 8\n  |.endif\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, or\n  |.ffunc_bit_op bxor, xor\n  |\n  |.ffunc_bit bswap\n  |  dsrl TMP0, CRET1, 8\n  |   dsrl TMP1, CRET1, 24\n  |  andi TMP2, TMP0, 0xff00\n  |   dins TMP1, CRET1, 24, 31\n  |  dins TMP2, TMP0, 16, 23\n  |  b ->fff_resi\n  |.  or CRET1, TMP1, TMP2\n  |\n  |.ffunc_bit bnot\n  |  not CRET1, CRET1\n  |  b ->fff_resi\n  |.  zextw CRET1, CRET1\n  |\n  |.macro .ffunc_bit_sh, name, shins, shmod\n  |  .ffunc_2 bit_..name\n  |  gettp TMP0, CARG1\n  |  beq TMP0, TISNUM, >1\n  |.  nop\n  |  bal ->vm_tobit_fb\n  |.  sltiu TMP1, TMP0, LJ_TISNUM\n  |  move CARG1, CRET1\n  |1:\n  |  gettp TMP0, CARG2\n  |  bne TMP0, TISNUM, ->fff_fallback\n  |.  zextw CARG2, CARG2\n  |  sextw CARG1, CARG1\n  |.if shmod == 1\n  |  negu CARG2, CARG2\n  |.endif\n  |  shins CRET1, CARG1, CARG2\n  |  b ->fff_resi\n  |.  zextw CRET1, CRET1\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, sllv, 0\n  |.ffunc_bit_sh rshift, srlv, 0\n  |.ffunc_bit_sh arshift, srav, 0\n  |.ffunc_bit_sh rol, rotrv, 1\n  |.ffunc_bit_sh ror, rotrv, 0\n  |\n  |.ffunc_bit tobit\n  |->fff_resi:\n  |  ld PC, FRAME_PC(BASE)\n  |  daddiu RA, BASE, -16\n  |  settp CRET1, TISNUM\n  |  b ->fff_res1\n  |.  sd CRET1, -16(BASE)\n  |\n  |//-----------------------------------------------------------------------\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RB = CFUNC, RC = nargs*8\n  |  ld TMP3, CFUNC:RB->f\n  |    daddu TMP1, BASE, NARGS8:RC\n  |   ld PC, FRAME_PC(BASE)\t\t// Fallback may overwrite PC.\n  |    daddiu TMP0, TMP1, 8*LUA_MINSTACK\n  |     ld TMP2, L->maxstack\n  |   sd PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sltu AT, TMP2, TMP0\n  |     sd BASE, L->base\n  |    sd TMP1, L->top\n  |  bnez AT, >5\t\t\t// Need to grow stack.\n  |.  move CFUNCADDR, TMP3\n  |  jalr TMP3\t\t\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  ld BASE, L->base\n  |   sll RD, CRET1, 3\n  |  bgtz CRET1, ->fff_res\t\t// Returned nresults+1?\n  |.  daddiu RA, BASE, -16\n  |1:  // Returned 0 or -1: retry fast path.\n  |   ld LFUNC:RB, FRAME_FUNC(BASE)\n  |  ld TMP0, L->top\n  |   cleartp LFUNC:RB\n  |  bnez CRET1, ->vm_call_tail\t\t// Returned -1?\n  |.  dsubu NARGS8:RC, TMP0, BASE\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  andi TMP0, PC, FRAME_TYPE\n  |   li AT, -4\n  |  bnez TMP0, >3\n  |.  and TMP1, PC, AT\n  |  lbu TMP1, OFS_RA(PC)\n  |  sll TMP1, TMP1, 3\n  |  addiu TMP1, TMP1, 16\n  |3:\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |.  dsubu TMP2, BASE, TMP1\n  |\n  |5:  // Grow stack for fallback handler.\n  |  load_got lj_state_growstack\n  |  li CARG2, LUA_MINSTACK\n  |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n  |.  move CARG1, L\n  |  ld BASE, L->base\n  |  b <1\n  |.  li CRET1, 0\t\t\t// Force retry.\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  move MULTRES, ra\n  |  load_got lj_gc_step\n  |   sd BASE, L->base\n  |  daddu TMP0, BASE, NARGS8:RC\n  |   sd PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  sd TMP0, L->top\n  |  call_intern lj_gc_step\t\t// (lua_State *L)\n  |.  move CARG1, L\n  |   ld BASE, L->base\n  |  move ra, MULTRES\n  |    ld TMP0, L->top\n  |  ld CFUNC:RB, FRAME_FUNC(BASE)\n  |  cleartp CFUNC:RB\n  |  jr ra\n  |.  dsubu NARGS8:RC, TMP0, BASE\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_VMEVENT\t// No recording while in vmevent.\n  |  bnez AT, >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |.  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\n  |  bnez AT, >1\n  |.  addiu TMP2, TMP2, -1\n  |  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, >1\n  |.  nop\n  |  b >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  beqz AT, >1\n  |5:  // Re-dispatch to static ins.\n  |.  ld AT, GG_DISP2STATIC(TMP0)\t// Assumes TMP0 holds DISPATCH+OP*4.\n  |  jr AT\n  |.  nop\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, HOOK_ACTIVE\t\t// Hook already active?\n  |  bnez AT, <5\n  |.  andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqz AT, <5\n  |.  addiu TMP2, TMP2, -1\n  |  beqz TMP2, >1\n  |.  sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andi AT, TMP3, LUA_MASKLINE\n  |  beqz AT, <5\n  |1:\n  |.  load_got lj_dispatch_ins\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sd BASE, L->base\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call_intern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |3:\n  |  ld BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  lw INS, -4(PC)\n  |  decode_OP8a TMP1, INS\n  |  decode_OP8b TMP1\n  |  daddu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  ld AT, GG_DISP2STATIC(TMP0)\n  |   decode_RA8a RA, INS\n  |   decode_RD8b RD\n  |  jr AT\n  |   decode_RA8b RA\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  daddiu PC, PC, 4\n  |  b <4\n  |.  lw MULTRES, -24+LO(RB)\t\t// Restore MULTRES for *M ins.\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  ld LFUNC:TMP1, FRAME_FUNC(BASE)\n  |   daddiu CARG1, DISPATCH, GG_DISP2J\n  |  cleartp LFUNC:TMP1\n  |   sd PC, SAVE_PC\n  |  ld TMP1, LFUNC:TMP1->pc\n  |   move CARG2, PC\n  |   sd L, DISPATCH_J(L)(DISPATCH)\n  |  lbu TMP1, PC2PROTO(framesize)(TMP1)\n  |  load_got lj_trace_hot\n  |   sd BASE, L->base\n  |  dsll TMP1, TMP1, 3\n  |  daddu TMP1, BASE, TMP1\n  |  call_intern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |.  sd TMP1, L->top\n  |  b <3\n  |.  nop\n  |.endif\n  |\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |.if JIT\n  |  b >1\n  |.endif\n  |.  move CARG2, PC\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  ori CARG2, PC, 1\n  |1:\n  |.endif\n  |  load_got lj_dispatch_call\n  |  daddu TMP0, BASE, RC\n  |   sd PC, SAVE_PC\n  |   sd BASE, L->base\n  |  dsubu RA, RA, BASE\n  |   sd TMP0, L->top\n  |  call_intern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // Returns ASMFunction.\n  |  ld BASE, L->base\n  |   ld TMP0, L->top\n  |   sd r0, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  dsubu NARGS8:RC, TMP0, BASE\n  |  daddu RA, BASE, RA\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\n  |  cleartp LFUNC:RB\n  |  jr CRET1\n  |.  lw INS, -4(PC)\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, RB = meta base\n  |  lw INS, -4(PC)\n  |    ld TRACE:TMP2, -40(RB)\t\t// Save previous trace.\n  |  decode_RA8a RC, INS\n  |   daddiu AT, MULTRES, -8\n  |    cleartp TRACE:TMP2\n  |  decode_RA8b RC\n  |   beqz AT, >2\n  |. daddu RC, BASE, RC\t\t\t// Call base.\n  |1:  // Move results down.\n  |  ld CARG1, 0(RA)\n  |   daddiu AT, AT, -8\n  |    daddiu RA, RA, 8\n  |  sd CARG1, 0(RC)\n  |   bnez AT, <1\n  |.   daddiu RC, RC, 8\n  |2:\n  |   decode_RA8a RA, INS\n  |    decode_RB8a RB, INS\n  |   decode_RA8b RA\n  |    decode_RB8b RB\n  |   daddu RA, RA, RB\n  |   daddu RA, BASE, RA\n  |3:\n  |   sltu AT, RC, RA\n  |   bnez AT, >9\t\t\t// More results wanted?\n  |.   nop\n  |\n  |  lhu TMP3, TRACE:TMP2->traceno\n  |  lhu RD, TRACE:TMP2->link\n  |  beq RD, TMP3, ->cont_nop\t\t// Blacklisted.\n  |.  load_got lj_dispatch_stitch\n  |  bnez RD, =>BC_JLOOP\t\t// Jump to stitched trace.\n  |.  sll RD, RD, 3\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  sw TMP3, DISPATCH_J(exitno)(DISPATCH)\n  |  sd L, DISPATCH_J(L)(DISPATCH)\n  |  sd BASE, L->base\n  |  daddiu CARG1, DISPATCH, GG_DISP2J\n  |  call_intern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |.  move CARG2, PC\n  |  b ->cont_nop\n  |.  ld BASE, L->base\n  |\n  |9:\n  |  sd TISNIL, 0(RC)\n  |  b <3\n  |.  daddiu RC, RC, 8\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  load_got lj_dispatch_profile\n  |   sw MULTRES, SAVE_MULTRES\n  |  move CARG2, PC\n  |   sd BASE, L->base\n  |  call_intern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |.  move CARG1, L\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  daddiu PC, PC, -4\n  |  b ->cont_nop\n  |.  ld BASE, L->base\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b\n  |.if FPU\n  |  sdc1 f..a, a*8(sp)\n  |  sdc1 f..b, b*8(sp)\n  |  sd r..a, 32*8+a*8(sp)\n  |  sd r..b, 32*8+b*8(sp)\n  |.else\n  |  sd r..a, a*8(sp)\n  |  sd r..b, b*8(sp)\n  |.endif\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |.if FPU\n  |  daddiu sp, sp, -(32*8+32*8)\n  |.else\n  |  daddiu sp, sp, -(32*8)\n  |.endif\n  |  savex_ 0, 1\n  |  savex_ 2, 3\n  |  savex_ 4, 5\n  |  savex_ 6, 7\n  |  savex_ 8, 9\n  |  savex_ 10, 11\n  |  savex_ 12, 13\n  |  savex_ 14, 15\n  |  savex_ 16, 17\n  |  savex_ 18, 19\n  |  savex_ 20, 21\n  |  savex_ 22, 23\n  |  savex_ 24, 25\n  |  savex_ 26, 27\n  |  savex_ 28, 30\n  |.if FPU\n  |  sdc1 f29, 29*8(sp)\n  |  sdc1 f31, 31*8(sp)\n  |  sd r0, 32*8+31*8(sp)\t\t// Clear RID_TMP.\n  |  daddiu TMP2, sp, 32*8+32*8\t\t// Recompute original value of sp.\n  |  sd TMP2, 32*8+29*8(sp)\t\t// Store sp in RID_SP\n  |.else\n  |  sd r0, 31*8(sp)\t\t\t// Clear RID_TMP.\n  |  daddiu TMP2, sp, 32*8\t\t// Recompute original value of sp.\n  |  sd TMP2, 29*8(sp)\t\t\t// Store sp in RID_SP\n  |.endif\n  |  li_vmstate EXIT\n  |  daddiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  lw TMP1, 0(TMP2)\t\t\t// Load exit number.\n  |  st_vmstate\n  |  ld L, DISPATCH_GL(cur_L)(DISPATCH)\n  |   ld BASE, DISPATCH_GL(jit_base)(DISPATCH)\n  |  load_got lj_trace_exit\n  |  sd L, DISPATCH_J(L)(DISPATCH)\n  |  sw ra, DISPATCH_J(parent)(DISPATCH)  // Store trace number.\n  |   sd BASE, L->base\n  |  sw TMP1, DISPATCH_J(exitno)(DISPATCH)  // Store exit number.\n  |  daddiu CARG1, DISPATCH, GG_DISP2J\n  |   sd r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  call_intern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |.  move CARG2, sp\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  ld TMP1, L->cframe\n  |  li AT, -4\n  |   ld BASE, L->base\n  |  and sp, TMP1, AT\n  |   ld PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  b >1\n  |.  sd L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |.endif\n  |->vm_exit_interp:\n  |.if JIT\n  |  // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.\n  |  ld L, SAVE_L\n  |   daddiu DISPATCH, JGL, -GG_DISP2G-32768\n  |  sd BASE, L->base\n  |1:\n  |  bltz CRET1, >9\t\t\t// Check for error from exit.\n  |.  ld LFUNC:RB, FRAME_FUNC(BASE)\n  |    .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  dsll MULTRES, CRET1, 3\n  |  cleartp LFUNC:RB\n  |  sw MULTRES, SAVE_MULTRES\n  |    li TISNIL, LJ_TNIL\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |    .FPU mtc1 TMP3, TOBIT\n  |  ld TMP1, LFUNC:RB->pc\n  |   sd r0, DISPATCH_GL(jit_base)(DISPATCH)\n  |  ld KBASE, PC2PROTO(k)(TMP1)\n  |    .FPU cvt.d.s TOBIT, TOBIT\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  lw INS, 0(PC)\n  |   daddiu PC, PC, 4\n  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1\n  |    sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)\n  |  decode_OP8a TMP1, INS\n  |  decode_OP8b TMP1\n  |    sltiu TMP2, TMP1, BC_FUNCF*8\n  |  daddu TMP0, DISPATCH, TMP1\n  |   decode_RD8a RD, INS\n  |  ld AT, 0(TMP0)\n  |   decode_RA8a RA, INS\n  |    beqz TMP2, >2\n  |.  decode_RA8b RA\n  |  jr AT\n  |.  decode_RD8b RD\n  |2:\n  |  sltiu TMP2, TMP1, (BC_FUNCC+2)*8\t// Fast function?\n  |  bnez TMP2, >3\n  |.  ld TMP1, FRAME_PC(BASE)\n  |  // Check frame below fast function.\n  |  andi TMP0, TMP1, FRAME_TYPE\n  |  bnez TMP0, >3\t\t\t// Trace stitching continuation?\n  |.  nop\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  lw TMP2, -4(TMP1)\n  |  decode_RA8a TMP0, TMP2\n  |  decode_RA8b TMP0\n  |  dsubu TMP1, BASE, TMP0\n  |  ld LFUNC:TMP2, -32(TMP1)\n  |  cleartp LFUNC:TMP2\n  |  ld TMP1, LFUNC:TMP2->pc\n  |  ld KBASE, PC2PROTO(k)(TMP1)\n  |3:\n  |  daddiu RC, MULTRES, -8\n  |  jr AT\n  |.  daddu RA, RA, BASE\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  load_got lj_err_trace\n  |  sub CARG2, r0, CRET1\n  |  call_intern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.  move CARG1, L\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Hard-float round to integer.\n  |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.\n  |// MIPSR6: Modifies FTMP1, too.\n  |.macro vm_round_hf, func\n  |  lui TMP0, 0x4330\t\t\t// Hiword of 2^52 (double).\n  |  dsll TMP0, TMP0, 32\n  |  dmtc1 TMP0, f4\n  |  abs.d FRET2, FARG1\t\t\t// |x|\n  |    dmfc1 AT, FARG1\n  |.if MIPSR6\n  |  cmp.lt.d FTMP1, FRET2, f4\n  |   add.d FRET1, FRET2, f4\t\t// (|x| + 2^52) - 2^52\n  |  bc1eqz FTMP1, >1\t\t\t// Truncate only if |x| < 2^52.\n  |.else\n  |  c.olt.d 0, FRET2, f4\n  |   add.d FRET1, FRET2, f4\t\t// (|x| + 2^52) - 2^52\n  |  bc1f 0, >1\t\t\t\t// Truncate only if |x| < 2^52.\n  |.endif\n  |.  sub.d FRET1, FRET1, f4\n  |    slt AT, AT, r0\n  |.if \"func\" == \"ceil\"\n  |   lui TMP0, 0xbff0\t\t\t// Hiword of -1 (double). Preserves -0.\n  |.else\n  |   lui TMP0, 0x3ff0\t\t\t// Hiword of +1 (double).\n  |.endif\n  |.if \"func\" == \"trunc\"\n  |   dsll TMP0, TMP0, 32\n  |   dmtc1 TMP0, f4\n  |.if MIPSR6\n  |  cmp.lt.d FTMP1, FRET2, FRET1\t// |x| < result?\n  |   sub.d FRET2, FRET1, f4\n  |  sel.d  FTMP1, FRET1, FRET2\t\t// If yes, subtract +1.\n  |  dmtc1 AT, FRET1\n  |  neg.d FRET2, FTMP1\n  |  jr ra\n  |.  sel.d FRET1, FTMP1, FRET2\t\t// Merge sign bit back in.\n  |.else\n  |  c.olt.d 0, FRET2, FRET1\t\t// |x| < result?\n  |   sub.d FRET2, FRET1, f4\n  |  movt.d FRET1, FRET2, 0\t\t// If yes, subtract +1.\n  |  neg.d FRET2, FRET1\n  |  jr ra\n  |.  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.endif\n  |.else\n  |  neg.d FRET2, FRET1\n  |   dsll TMP0, TMP0, 32\n  |   dmtc1 TMP0, f4\n  |.if MIPSR6\n  |  dmtc1 AT, FTMP1\n  |  sel.d FTMP1, FRET1, FRET2\n  |.if \"func\" == \"ceil\"\n  |  cmp.lt.d FRET1, FTMP1, FARG1\t// x > result?\n  |.else\n  |  cmp.lt.d FRET1, FARG1, FTMP1\t// x < result?\n  |.endif\n  |   sub.d FRET2, FTMP1, f4\t\t// If yes, subtract +-1.\n  |  jr ra\n  |.  sel.d FRET1, FTMP1, FRET2\n  |.else\n  |  movn.d FRET1, FRET2, AT\t\t// Merge sign bit back in.\n  |.if \"func\" == \"ceil\"\n  |  c.olt.d 0, FRET1, FARG1\t\t// x > result?\n  |.else\n  |  c.olt.d 0, FARG1, FRET1\t\t// x < result?\n  |.endif\n  |   sub.d FRET2, FRET1, f4\t\t// If yes, subtract +-1.\n  |  jr ra\n  |.  movt.d FRET1, FRET2, 0\n  |.endif\n  |.endif\n  |1:\n  |  jr ra\n  |.  mov.d FRET1, FARG1\n  |.endmacro\n  |\n  |.macro vm_round, func\n  |.if FPU\n  |  vm_round_hf, func\n  |.endif\n  |.endmacro\n  |\n  |->vm_floor:\n  |  vm_round floor\n  |->vm_ceil:\n  |  vm_round ceil\n  |->vm_trunc:\n  |.if JIT\n  |  vm_round trunc\n  |.endif\n  |\n  |// Soft-float integer to number conversion.\n  |.macro sfi2d, ARG\n  |.if not FPU\n  |  beqz ARG, >9\t\t\t// Handle zero first.\n  |.  sra TMP0, ARG, 31\n  |  xor TMP1, ARG, TMP0\n  |  dsubu TMP1, TMP1, TMP0\t\t// Absolute value in TMP1.\n  |  dclz ARG, TMP1\n  |  addiu ARG, ARG, -11\n  |  li AT, 0x3ff+63-11-1\n  |   dsllv TMP1, TMP1, ARG\t\t// Align mantissa left with leading 1.\n  |  subu ARG, AT, ARG\t\t\t// Exponent - 1.\n  |  ins ARG, TMP0, 11, 11\t\t// Sign | Exponent.\n  |  dsll ARG, ARG, 52\t\t\t// Align left.\n  |  jr ra\n  |.  daddu ARG, ARG, TMP1\t\t// Add mantissa, increment exponent.\n  |9:\n  |  jr ra\n  |.  nop\n  |.endif\n  |.endmacro\n  |\n  |// Input CARG1. Output: CARG1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_1:\n  |  sfi2d CARG1\n  |\n  |// Input CARG2. Output: CARG2. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfi2d_2:\n  |  sfi2d CARG2\n  |\n  |// Soft-float comparison. Equivalent to c.eq.d.\n  |// Input: CARG*. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpeq:\n  |.if not FPU\n  |  dsll AT, CARG1, 1\n  |  dsll TMP0, CARG2, 1\n  |  or TMP1, AT, TMP0\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  lui TMP1, 0xffe0\n  |  dsll TMP1, TMP1, 32\n  |   sltu AT, TMP1, AT\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  xor AT, CARG1, CARG2\n  |  jr ra\n  |.  sltiu CRET1, AT, 1\t\t// Same values: return 1.\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ult.d and c.olt.d.\n  |// Input: CARG1, CARG2. Output: CRET1. Temporaries: AT, TMP0, TMP1, CRET2.\n  |->vm_sfcmpult:\n  |.if not FPU\n  |  b >1\n  |.  li CRET2, 1\n  |.endif\n  |\n  |->vm_sfcmpolt:\n  |.if not FPU\n  |  li CRET2, 0\n  |1:\n  |  dsll AT, CARG1, 1\n  |  dsll TMP0, CARG2, 1\n  |  or TMP1, AT, TMP0\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 0.\n  |.  lui TMP1, 0xffe0\n  |  dsll TMP1, TMP1, 32\n  |   sltu AT, TMP1, AT\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0 or 1;\n  |.  and AT, CARG1, CARG2\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  jr ra\n  |.  slt CRET1, CARG1, CARG2\n  |5:  // Swap conditions if both operands are negative.\n  |  jr ra\n  |.  slt CRET1, CARG2, CARG1\n  |8:\n  |  jr ra\n  |.  li CRET1, 0\n  |9:\n  |  jr ra\n  |.  move CRET1, CRET2\n  |.endif\n  |\n  |->vm_sfcmpogt:\n  |.if not FPU\n  |  dsll AT, CARG2, 1\n  |  dsll TMP0, CARG1, 1\n  |  or TMP1, AT, TMP0\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 0.\n  |.  lui TMP1, 0xffe0\n  |  dsll TMP1, TMP1, 32\n  |   sltu AT, TMP1, AT\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0 or 1;\n  |.  and AT, CARG2, CARG1\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  jr ra\n  |.  slt CRET1, CARG2, CARG1\n  |5:  // Swap conditions if both operands are negative.\n  |  jr ra\n  |.  slt CRET1, CARG1, CARG2\n  |8:\n  |  jr ra\n  |.  li CRET1, 0\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |// Soft-float comparison. Equivalent to c.ole.d a, b or c.ole.d b, a.\n  |// Input: CARG1, CARG2, TMP3. Output: CRET1. Temporaries: AT, TMP0, TMP1.\n  |->vm_sfcmpolex:\n  |.if not FPU\n  |  dsll AT, CARG1, 1\n  |  dsll TMP0, CARG2, 1\n  |  or TMP1, AT, TMP0\n  |  beqz TMP1, >8\t\t\t// Both args +-0: return 1.\n  |.  lui TMP1, 0xffe0\n  |  dsll TMP1, TMP1, 32\n  |   sltu AT, TMP1, AT\n  |   sltu TMP0, TMP1, TMP0\n  |  or TMP1, AT, TMP0\n  |  bnez TMP1, >9\t\t\t// Either arg is NaN: return 0;\n  |.  and AT, CARG1, CARG2\n  |  xor AT, AT, TMP3\n  |  bltz AT, >5\t\t\t// Both args negative?\n  |.  nop\n  |  jr ra\n  |.  slt CRET1, CARG2, CARG1\n  |5:  // Swap conditions if both operands are negative.\n  |  jr ra\n  |.  slt CRET1, CARG1, CARG2\n  |8:\n  |  jr ra\n  |.  li CRET1, 1\n  |9:\n  |  jr ra\n  |.  li CRET1, 0\n  |.endif\n  |\n  |.macro sfmin_max, name, fpcall\n  |->vm_sf .. name:\n  |.if JIT and not FPU\n  |  move TMP2, ra\n  |  bal ->fpcall\n  |.  nop\n  |  move ra, TMP2\n  |  move TMP0, CRET1\n  |  move CRET1, CARG1\n  |.if MIPSR6\n  |  selnez CRET1, CRET1, TMP0\n  |  seleqz TMP0, CARG2, TMP0\n  |  jr ra\n  |.  or CRET1, CRET1, TMP0\n  |.else\n  |  jr ra\n  |.  movz CRET1, CARG2, TMP0\n  |.endif\n  |.endif\n  |.endmacro\n  |\n  |  sfmin_max min, vm_sfcmpolt\n  |  sfmin_max max, vm_sfcmpogt\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.define NEXT_TAB,\t\tTAB:CARG1\n  |.define NEXT_IDX,\t\tCARG2\n  |.define NEXT_ASIZE,\t\tCARG3\n  |.define NEXT_NIL,\t\tCARG4\n  |.define NEXT_TMP0,\t\tr12\n  |.define NEXT_TMP1,\t\tr13\n  |.define NEXT_TMP2,\t\tr14\n  |.define NEXT_RES_VK,\t\tCRET1\n  |.define NEXT_RES_IDX,\tCRET2\n  |.define NEXT_RES_PTR,\tsp\n  |.define NEXT_RES_VAL,\t0(sp)\n  |.define NEXT_RES_KEY,\t8(sp)\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in CRET2.\n  |->vm_next:\n  |.if JIT and ENDIAN_LE\n  |   lw NEXT_ASIZE, NEXT_TAB->asize\n  |  ld NEXT_TMP0, NEXT_TAB->array\n  |    li NEXT_NIL, LJ_TNIL\n  |1:  // Traverse array part.\n  |   sltu AT, NEXT_IDX, NEXT_ASIZE\n  |    sll NEXT_TMP1, NEXT_IDX, 3\n  |   beqz AT, >5\n  |.   daddu NEXT_TMP1, NEXT_TMP0, NEXT_TMP1\n  |   li AT, LJ_TISNUM\n  |  ld NEXT_TMP2, 0(NEXT_TMP1)\n  |   dsll AT, AT, 47\n  |   or NEXT_TMP1, NEXT_IDX, AT\n  |  beq NEXT_TMP2, NEXT_NIL, <1\n  |.  addiu NEXT_IDX, NEXT_IDX, 1\n  |  sd NEXT_TMP2, NEXT_RES_VAL\n  |   sd NEXT_TMP1, NEXT_RES_KEY\n  |  move NEXT_RES_VK, NEXT_RES_PTR\n  |  jr ra\n  |.  move NEXT_RES_IDX, NEXT_IDX\n  |\n  |5:  // Traverse hash part.\n  |  subu NEXT_RES_IDX, NEXT_IDX, NEXT_ASIZE\n  |   ld NODE:NEXT_RES_VK, NEXT_TAB->node\n  |    sll NEXT_TMP2, NEXT_RES_IDX, 5\n  |  lw NEXT_TMP0, NEXT_TAB->hmask\n  |    sll AT, NEXT_RES_IDX, 3\n  |    subu AT, NEXT_TMP2, AT\n  |   daddu NODE:NEXT_RES_VK, NODE:NEXT_RES_VK, AT\n  |6:\n  |  sltu AT, NEXT_TMP0, NEXT_RES_IDX\n  |  bnez AT, >8\n  |.  nop\n  |  ld NEXT_TMP2, NODE:NEXT_RES_VK->val\n  |  bne NEXT_TMP2, NEXT_NIL, >9\n  |.  addiu NEXT_RES_IDX, NEXT_RES_IDX, 1\n  |  // Skip holes in hash part.\n  |  b <6\n  |.  daddiu NODE:NEXT_RES_VK, NODE:NEXT_RES_VK, sizeof(Node)\n  |\n  |8:  // End of iteration. Set the key to nil (not the value).\n  |  sd NEXT_NIL, NEXT_RES_KEY\n  |  move NEXT_RES_VK, NEXT_RES_PTR\n  |9:\n  |  jr ra\n  |.  addu NEXT_RES_IDX, NEXT_RES_IDX, NEXT_ASIZE\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in r1, g in r2.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  ld CTSTATE, GL:r2->ctype_state\n  |   daddiu DISPATCH, r2, GG_G2DISP\n  |  load_got lj_ccallback_enter\n  |  sw r1, CTSTATE->cb.slot\n  |  sd CARG1, CTSTATE->cb.gpr[0]\n  |  .FPU sdc1 FARG1, CTSTATE->cb.fpr[0]\n  |  sd CARG2, CTSTATE->cb.gpr[1]\n  |  .FPU sdc1 FARG2, CTSTATE->cb.fpr[1]\n  |  sd CARG3, CTSTATE->cb.gpr[2]\n  |  .FPU sdc1 FARG3, CTSTATE->cb.fpr[2]\n  |  sd CARG4, CTSTATE->cb.gpr[3]\n  |  .FPU sdc1 FARG4, CTSTATE->cb.fpr[3]\n  |  sd CARG5, CTSTATE->cb.gpr[4]\n  |  .FPU sdc1 FARG5, CTSTATE->cb.fpr[4]\n  |  sd CARG6, CTSTATE->cb.gpr[5]\n  |  .FPU sdc1 FARG6, CTSTATE->cb.fpr[5]\n  |  sd CARG7, CTSTATE->cb.gpr[6]\n  |  .FPU sdc1 FARG7, CTSTATE->cb.fpr[6]\n  |  sd CARG8, CTSTATE->cb.gpr[7]\n  |  .FPU sdc1 FARG8, CTSTATE->cb.fpr[7]\n  |  daddiu TMP0, sp, CFRAME_SPACE\n  |  sd TMP0, CTSTATE->cb.stack\n  |  sd r0, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   move CARG2, sp\n  |  call_intern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |.  move CARG1, CTSTATE\n  |  // Returns lua_State *.\n  |  ld BASE, L:CRET1->base\n  |  ld RC, L:CRET1->top\n  |   move L, CRET1\n  |     .FPU lui TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  ld LFUNC:RB, FRAME_FUNC(BASE)\n  |     .FPU mtc1 TMP3, TOBIT\n  |      li TISNIL, LJ_TNIL\n  |       li TISNUM, LJ_TISNUM\n  |    li_vmstate INTERP\n  |  subu RC, RC, BASE\n  |   cleartp LFUNC:RB\n  |    st_vmstate\n  |     .FPU cvt.d.s TOBIT, TOBIT\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  load_got lj_ccallback_leave\n  |  ld CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)\n  |   sd BASE, L->base\n  |   sd RB, L->top\n  |  sd L, CTSTATE->L\n  |  move CARG2, RA\n  |  call_intern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |.  move CARG1, CTSTATE\n  |  .FPU ldc1 FRET1, CTSTATE->cb.fpr[0]\n  |  ld CRET1, CTSTATE->cb.gpr[0]\n  |  .FPU ldc1 FRET2, CTSTATE->cb.fpr[1]\n  |  b ->vm_leave_unw\n  |.  ld CRET2, CTSTATE->cb.gpr[1]\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, CARG1\n  |  lw TMP1, CCSTATE->spadj\n  |   lbu CARG2, CCSTATE->nsp\n  |  move TMP2, sp\n  |  dsubu sp, sp, TMP1\n  |  sd ra, -8(TMP2)\n  |   sll CARG2, CARG2, 3\n  |  sd r16, -16(TMP2)\n  |  sd CCSTATE, -24(TMP2)\n  |  move r16, TMP2\n  |  daddiu TMP1, CCSTATE, offsetof(CCallState, stack)\n  |  move TMP2, sp\n  |  beqz CARG2, >2\n  |.  daddu TMP3, TMP1, CARG2\n  |1:\n  |   ld TMP0, 0(TMP1)\n  |  daddiu TMP1, TMP1, 8\n  |  sltu AT, TMP1, TMP3\n  |   sd TMP0, 0(TMP2)\n  |  bnez AT, <1\n  |.  daddiu TMP2, TMP2, 8\n  |2:\n  |  ld CFUNCADDR, CCSTATE->func\n  |  .FPU ldc1 FARG1, CCSTATE->gpr[0]\n  |  ld CARG2, CCSTATE->gpr[1]\n  |  .FPU ldc1 FARG2, CCSTATE->gpr[1]\n  |  ld CARG3, CCSTATE->gpr[2]\n  |  .FPU ldc1 FARG3, CCSTATE->gpr[2]\n  |  ld CARG4, CCSTATE->gpr[3]\n  |  .FPU ldc1 FARG4, CCSTATE->gpr[3]\n  |  ld CARG5, CCSTATE->gpr[4]\n  |  .FPU ldc1 FARG5, CCSTATE->gpr[4]\n  |  ld CARG6, CCSTATE->gpr[5]\n  |  .FPU ldc1 FARG6, CCSTATE->gpr[5]\n  |  ld CARG7, CCSTATE->gpr[6]\n  |  .FPU ldc1 FARG7, CCSTATE->gpr[6]\n  |  ld CARG8, CCSTATE->gpr[7]\n  |  .FPU ldc1 FARG8, CCSTATE->gpr[7]\n  |  jalr CFUNCADDR\n  |.  ld CARG1, CCSTATE->gpr[0]\t\t// Do this last, since CCSTATE is CARG1.\n  |  ld CCSTATE:TMP1, -24(r16)\n  |  ld TMP2, -16(r16)\n  |  ld ra, -8(r16)\n  |  sd CRET1, CCSTATE:TMP1->gpr[0]\n  |  sd CRET2, CCSTATE:TMP1->gpr[1]\n  |.if FPU\n  |  sdc1 FRET1, CCSTATE:TMP1->fpr[0]\n  |  sdc1 FRET2, CCSTATE:TMP1->fpr[1]\n  |.else\n  |  sd CARG1, CCSTATE:TMP1->gpr[2]\t// 2nd FP struct field for soft-float.\n  |.endif\n  |  move sp, r16\n  |  jr ra\n  |.  move r16, TMP2\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.macro bc_comp, FRA, FRD, ARGRA, ARGRD, movop, fmovop, fcomp, sfcomp\n    |  daddu RA, BASE, RA\n    |   daddu RD, BASE, RD\n    |  ld ARGRA, 0(RA)\n    |   ld ARGRD, 0(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |  gettp CARG3, ARGRA\n    |   gettp CARG4, ARGRD\n    |  bne CARG3, TISNUM, >2\n    |.   daddiu PC, PC, 4\n    |  bne CARG4, TISNUM, >5\n    |.   decode_RD4b TMP2\n    |  sextw ARGRA, ARGRA\n    |   sextw ARGRD, ARGRD\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  slt AT, CARG1, CARG2\n    |    addu TMP2, TMP2, TMP3\n    |.if MIPSR6\n    |  movop TMP2, TMP2, AT\n    |.else\n    |  movop TMP2, r0, AT\n    |.endif\n    |1:\n    |  daddu PC, PC, TMP2\n    |  ins_next\n    |\n    |2:  // RA is not an integer.\n    |  sltiu AT, CARG3, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |.   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sltiu AT, CARG4, LJ_TISNUM\n    |  beqz AT, >4\n    |.   decode_RD4b TMP2\n    |.if FPU\n    |  ldc1 FRA, 0(RA)\n    |   ldc1 FRD, 0(RD)\n    |.endif\n    |3:  // RA and RD are both numbers.\n    |.if FPU\n    |.if MIPSR6\n    |  fcomp FTMP0, FTMP0, FTMP2\n    |   addu TMP2, TMP2, TMP3\n    |  mfc1 TMP3, FTMP0\n    |  b <1\n    |.  fmovop TMP2, TMP2, TMP3\n    |.else\n    |  fcomp FTMP0, FTMP2\n    |   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.  fmovop TMP2, r0\n    |.endif\n    |.else\n    |  bal sfcomp\n    |.   addu TMP2, TMP2, TMP3\n    |  b <1\n    |.if MIPSR6\n    |.  movop TMP2, TMP2, CRET1\n    |.else\n    |.  movop TMP2, r0, CRET1\n    |.endif\n    |.endif\n    |\n    |4:  // RA is a number, RD is not a number.\n    |  bne CARG4, TISNUM, ->vmeta_comp\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 FRD, LO(RD)\n    |  ldc1 FRA, 0(RA)\n    |  b <3\n    |.  cvt.d.w FRD, FRD\n    |.else\n    |.if \"ARGRD\" == \"CARG1\"\n    |.  sextw CARG1, CARG1\n    |  bal ->vm_sfi2d_1\n    |.  nop\n    |.else\n    |.  sextw CARG2, CARG2\n    |  bal ->vm_sfi2d_2\n    |.  nop\n    |.endif\n    |  b <3\n    |.  nop\n    |.endif\n    |\n    |5:  // RA is an integer, RD is not an integer\n    |  sltiu AT, CARG4, LJ_TISNUM\n    |  beqz AT, ->vmeta_comp\n    |.  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |   lwc1 FRA, LO(RA)\n    |   ldc1 FRD, 0(RD)\n    |  b <3\n    |   cvt.d.w FRA, FRA\n    |.else\n    |.if \"ARGRA\" == \"CARG1\"\n    |  bal ->vm_sfi2d_1\n    |.  sextw CARG1, CARG1\n    |.else\n    |  bal ->vm_sfi2d_2\n    |.  sextw CARG2, CARG2\n    |.endif\n    |  b <3\n    |.  nop\n    |.endif\n    |.endmacro\n    |\n    |.if MIPSR6\n    if (op == BC_ISLT) {\n      |  bc_comp FTMP0, FTMP2, CARG1, CARG2, selnez, selnez, cmp.lt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISGE) {\n      |  bc_comp FTMP0, FTMP2, CARG1, CARG2, seleqz, seleqz, cmp.lt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISLE) {\n      |  bc_comp FTMP2, FTMP0, CARG2, CARG1, seleqz, seleqz, cmp.ult.d, ->vm_sfcmpult\n    } else {\n      |  bc_comp FTMP2, FTMP0, CARG2, CARG1, selnez, selnez, cmp.ult.d, ->vm_sfcmpult\n    }\n    |.else\n    if (op == BC_ISLT) {\n      |  bc_comp FTMP0, FTMP2, CARG1, CARG2, movz, movf, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISGE) {\n      |  bc_comp FTMP0, FTMP2, CARG1, CARG2, movn, movt, c.olt.d, ->vm_sfcmpolt\n    } else if (op == BC_ISLE) {\n      |  bc_comp FTMP2, FTMP0, CARG2, CARG1, movn, movt, c.ult.d, ->vm_sfcmpult\n    } else {\n      |  bc_comp FTMP2, FTMP0, CARG2, CARG1, movz, movf, c.ult.d, ->vm_sfcmpult\n    }\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |  daddu RA, BASE, RA\n    |    daddiu PC, PC, 4\n    |   daddu RD, BASE, RD\n    |  ld CARG1, 0(RA)\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |   ld CARG2, 0(RD)\n    |  gettp CARG3, CARG1\n    |   gettp CARG4, CARG2\n    |  sltu AT, TISNUM, CARG3\n    |   sltu TMP1, TISNUM, CARG4\n    |  or AT, AT, TMP1\n    if (vk) {\n      |  beqz AT, ->BC_ISEQN_Z\n    } else {\n      |  beqz AT, ->BC_ISNEN_Z\n    }\n    |  // Either or both types are not numbers.\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |.if FFI\n    |.  li AT, LJ_TCDATA\n    |  beq CARG3, AT, ->vmeta_equal_cd\n    |.endif\n    |   decode_RD4b TMP2\n    |.if FFI\n    |  beq CARG4, AT, ->vmeta_equal_cd\n    |.  nop\n    |.endif\n    |  bne CARG1, CARG2, >2\n    |.  addu TMP2, TMP2, TMP3\n    |  // Tag and value are equal.\n    if (vk) {\n      |->BC_ISEQV_Z:\n      |  daddu PC, PC, TMP2\n    }\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if the tags are the same and it's a table or userdata.\n    |  xor AT, CARG3, CARG4\t\t\t// Same type?\n    |  sltiu TMP0, CARG3, LJ_TISTABUD+1\t\t// Table or userdata?\n    |.if MIPSR6\n    |  seleqz TMP0, TMP0, AT\n    |.else\n    |  movn TMP0, r0, AT\n    |.endif\n    if (vk) {\n      |  beqz TMP0, <1\n    } else {\n      |  beqz TMP0, ->BC_ISEQV_Z  // Reuse code from opposite instruction.\n    }\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |.  cleartp TAB:TMP1, CARG1\n    |  ld TAB:TMP3, TAB:TMP1->metatable\n    if (vk) {\n      |  beqz TAB:TMP3, <1\t\t// No metatable?\n      |.  nop\n      |  lbu TMP3, TAB:TMP3->nomm\n      |  andi TMP3, TMP3, 1<<MM_eq\n      |  bnez TMP3, >1\t\t\t// Or 'no __eq' flag set?\n    } else {\n      |  beqz TAB:TMP3,->BC_ISEQV_Z\t// No metatable?\n      |.  nop\n      |  lbu TMP3, TAB:TMP3->nomm\n      |  andi TMP3, TMP3, 1<<MM_eq\n      |  bnez TMP3, ->BC_ISEQV_Z\t// Or 'no __eq' flag set?\n    }\n    |.  nop\n    |  b ->vmeta_equal\t\t\t// Handle __eq metamethod.\n    |.  li TMP0, 1-vk\t\t\t// ne = 0 or 1.\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target\n    |  daddu RA, BASE, RA\n    |   daddiu PC, PC, 4\n    |  ld CARG1, 0(RA)\n    |   dsubu RD, KBASE, RD\n    |    lhu TMP2, -4+OFS_RD(PC)\n    |   ld CARG2, -8(RD)\t\t// KBASE-8-str_const*8\n    |.if FFI\n    |  gettp TMP0, CARG1\n    |  li AT, LJ_TCDATA\n    |.endif\n    |  li TMP1, LJ_TSTR\n    |   decode_RD4b TMP2\n    |.if FFI\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  settp CARG2, TMP1\n    |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  xor TMP1, CARG1, CARG2\n    |   addu TMP2, TMP2, TMP3\n    |.if MIPSR6\n    if (vk) {\n      |  seleqz TMP2, TMP2, TMP1\n    } else {\n      |  selnez TMP2, TMP2, TMP1\n    }\n    |.else\n    if (vk) {\n      |  movn TMP2, r0, TMP1\n    } else {\n      |  movz TMP2, r0, TMP1\n    }\n    |.endif\n    |  daddu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RD = num_const*8, JMP with RD = target\n    |  daddu RA, BASE, RA\n    |   daddu RD, KBASE, RD\n    |  ld CARG1, 0(RA)\n    |   ld CARG2, 0(RD)\n    |    lhu TMP2, OFS_RD(PC)\n    |  gettp CARG3, CARG1\n    |   gettp CARG4, CARG2\n    |    daddiu PC, PC, 4\n    |    lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  bne CARG3, TISNUM, >3\n    |.   decode_RD4b TMP2\n    |  bne CARG4, TISNUM, >6\n    |.   addu TMP2, TMP2, TMP3\n    |  xor AT, CARG1, CARG2\n    |.if MIPSR6\n    if (vk) {\n      | seleqz TMP2, TMP2, AT\n      |1:\n      |  daddu PC, PC, TMP2\n      |2:\n    } else {\n      |  selnez TMP2, TMP2, AT\n      |1:\n      |2:\n      |  daddu PC, PC, TMP2\n    }\n    |.else\n    if (vk) {\n      | movn TMP2, r0, AT\n      |1:\n      |  daddu PC, PC, TMP2\n      |2:\n    } else {\n      |  movz TMP2, r0, AT\n      |1:\n      |2:\n      |  daddu PC, PC, TMP2\n    }\n    |.endif\n    |  ins_next\n    |\n    |3:  // RA is not an integer.\n    |  sltu AT, CARG3, TISNUM\n    |.if FFI\n    |  beqz AT, >8\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |.   addu TMP2, TMP2, TMP3\n    |  sltu AT, CARG4, TISNUM\n    |.if FPU\n    |  ldc1 FTMP0, 0(RA)\n    |   ldc1 FTMP2, 0(RD)\n    |.endif\n    |  beqz AT, >5\n    |.  nop\n    |4:  // RA and RD are both numbers.\n    |.if FPU\n    |.if MIPSR6\n    |  cmp.eq.d FTMP0, FTMP0, FTMP2\n    |  dmfc1 TMP1, FTMP0\n    |  b <1\n    if (vk) {\n      |.  selnez TMP2, TMP2, TMP1\n    } else {\n      |.  seleqz TMP2, TMP2, TMP1\n    }\n    |.else\n    |  c.eq.d FTMP0, FTMP2\n    |  b <1\n    if (vk) {\n      |.  movf TMP2, r0\n    } else {\n      |.  movt TMP2, r0\n    }\n    |.endif\n    |.else\n    |  bal ->vm_sfcmpeq\n    |.  nop\n    |  b <1\n    |.if MIPSR6\n    if (vk) {\n      |.  selnez TMP2, TMP2, CRET1\n    } else {\n      |.  seleqz TMP2, TMP2, CRET1\n    }\n    |.else\n    if (vk) {\n      |.  movz TMP2, r0, CRET1\n    } else {\n      |.  movn TMP2, r0, CRET1\n    }\n    |.endif\n    |.endif\n    |\n    |5:  // RA is a number, RD is not a number.\n    |.if FFI\n    |  bne CARG4, TISNUM, >9\n    |.else\n    |  bne CARG4, TISNUM, <2\n    |.endif\n    |  // RA is a number, RD is an integer. Convert RD to a number.\n    |.if FPU\n    |.  lwc1 FTMP2, LO(RD)\n    |  b <4\n    |.  cvt.d.w FTMP2, FTMP2\n    |.else\n    |.  sextw CARG2, CARG2\n    |  bal ->vm_sfi2d_2\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |6:  // RA is an integer, RD is not an integer\n    |  sltu AT, CARG4, TISNUM\n    |.if FFI\n    |  beqz AT, >9\n    |.else\n    |  beqz AT, <2\n    |.endif\n    |  // RA is an integer, RD is a number. Convert RA to a number.\n    |.if FPU\n    |.  lwc1 FTMP0, LO(RA)\n    |   ldc1 FTMP2, 0(RD)\n    |  b <4\n    |   cvt.d.w FTMP0, FTMP0\n    |.else\n    |.  sextw CARG1, CARG1\n    |  bal ->vm_sfi2d_1\n    |.  nop\n    |  b <4\n    |.  nop\n    |.endif\n    |\n    |.if FFI\n    |8:\n    |  li AT, LJ_TCDATA\n    |  bne CARG3, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |9:\n    |  li AT, LJ_TCDATA\n    |  bne CARG4, AT, <2\n    |.  nop\n    |  b ->vmeta_equal_cd\n    |.  nop\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target\n    |  daddu RA, BASE, RA\n    |   srl TMP1, RD, 3\n    |  ld TMP0, 0(RA)\n    |    lhu TMP2, OFS_RD(PC)\n    |   not TMP1, TMP1\n    |  gettp TMP0, TMP0\n    |    daddiu PC, PC, 4\n    |.if FFI\n    |  li AT, LJ_TCDATA\n    |  beq TMP0, AT, ->vmeta_equal_cd\n    |.endif\n    |.  xor TMP0, TMP0, TMP1\n    |  decode_RD4b TMP2\n    |  lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  addu TMP2, TMP2, TMP3\n    |.if MIPSR6\n    if (vk) {\n      |  seleqz TMP2, TMP2, TMP0\n    } else {\n      |  selnez TMP2, TMP2, TMP0\n    }\n    |.else\n    if (vk) {\n      |  movn TMP2, r0, TMP0\n    } else {\n      |  movz TMP2, r0, TMP0\n    }\n    |.endif\n    |  daddu PC, PC, TMP2\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target\n    |  daddu RD, BASE, RD\n    |   lhu TMP2, OFS_RD(PC)\n    |  ld TMP0, 0(RD)\n    |   daddiu PC, PC, 4\n    |  gettp TMP0, TMP0\n    |  sltiu TMP0, TMP0, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISF) {\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      |.if MIPSR6\n      if (op == BC_IST) {\n\t|  selnez TMP2, TMP2, TMP0;\n      } else {\n\t|  seleqz TMP2, TMP2, TMP0;\n      }\n      |.else\n      if (op == BC_IST) {\n\t|  movz TMP2, r0, TMP0\n      } else {\n\t|  movn TMP2, r0, TMP0\n      }\n      |.endif\n      |  daddu PC, PC, TMP2\n    } else {\n      |  ld CRET1, 0(RD)\n      if (op == BC_ISTC) {\n\t|  beqz TMP0, >1\n      } else {\n\t|  bnez TMP0, >1\n      }\n      |.  daddu RA, BASE, RA\n      |   decode_RD4b TMP2\n      |   lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n      |   addu TMP2, TMP2, TMP3\n      |  sd CRET1, 0(RA)\n      |   daddu PC, PC, TMP2\n      |1:\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RD = -type*8\n    |  daddu TMP2, BASE, RA\n    |  srl TMP1, RD, 3\n    |  ld TMP0, 0(TMP2)\n    |  ins_next1\n    |  gettp TMP0, TMP0\n    |  daddu AT, TMP0, TMP1\n    |  bnez AT, ->vmeta_istype\n    |.  ins_next2\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RD = -(TISNUM-1)*8\n    |  daddu TMP2, BASE, RA\n    |  ld TMP0, 0(TMP2)\n    |  ins_next1\n    |  checknum TMP0, ->vmeta_istype\n    |.  ins_next2\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RD = src*8\n    |  daddu RD, BASE, RD\n    |   daddu RA, BASE, RA\n    |  ld CRET1, 0(RD)\n    |  ins_next1\n    |  sd CRET1, 0(RA)\n    |  ins_next2\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RD = src*8\n    |  daddu RD, BASE, RD\n    |   daddu RA, BASE, RA\n    |  ld TMP0, 0(RD)\n    |   li AT, LJ_TTRUE\n    |  gettp TMP0, TMP0\n    |  sltu TMP0, AT, TMP0\n    |  addiu TMP0, TMP0, 1\n    |  dsll TMP0, TMP0, 47\n    |  not TMP0, TMP0\n    |  ins_next1\n    |   sd TMP0, 0(RA)\n    |  ins_next2\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RD = src*8\n    |  daddu RB, BASE, RD\n    |  ld CARG1, 0(RB)\n    |    daddu RA, BASE, RA\n    |  gettp CARG3, CARG1\n    |  bne CARG3, TISNUM, >2\n    |.  lui TMP1, 0x8000\n    |  sextw CARG1, CARG1\n    |  beq CARG1, TMP1, ->vmeta_unm\t// Meta handler deals with -2^31.\n    |.  negu CARG1, CARG1\n    |  zextw CARG1, CARG1\n    |  settp CARG1, TISNUM\n    |1:\n    |  ins_next1\n    |   sd CARG1, 0(RA)\n    |  ins_next2\n    |2:\n    |  sltiu AT, CARG3, LJ_TISNUM\n    |  beqz AT, ->vmeta_unm\n    |.  dsll TMP1, TMP1, 32\n    |  b <1\n    |.  xor CARG1, CARG1, TMP1\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RD = src*8\n    |  daddu CARG2, BASE, RD\n    |   daddu RA, BASE, RA\n    |  ld TMP0, 0(CARG2)\n    |  gettp TMP1, TMP0\n    |  daddiu AT, TMP1, -LJ_TSTR\n    |  bnez AT, >2\n    |.  cleartp STR:CARG1, TMP0\n    |   lw CRET1, STR:CARG1->len\n    |1:\n    |  settp CRET1, TISNUM\n    |  ins_next1\n    |  sd CRET1, 0(RA)\n    |  ins_next2\n    |2:\n    |  daddiu AT, TMP1, -LJ_TTAB\n    |  bnez AT, ->vmeta_len\n    |.  nop\n#if LJ_52\n    |  ld TAB:TMP2, TAB:CARG1->metatable\n    |  bnez TAB:TMP2, >9\n    |.  nop\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  load_got lj_tab_len\n    |  call_intern lj_tab_len\t\t// (GCtab *t)\n    |.  nop\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n    |.  nop\n#if LJ_52\n    |9:\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_len\n    |  bnez TMP0, <3\t\t\t// 'no __len' flag set: done.\n    |.  nop\n    |  b ->vmeta_len\n    |.  nop\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro fpmod, a, b, c\n    |  bal ->vm_floor\t\t// floor(b/c)\n    |.  div.d FARG1, b, c\n    |  mul.d a, FRET1, c\n    |  sub.d a, b, a\t\t// b - floor(b/c)*c\n    |.endmacro\n\n    |.macro sfpmod\n    |  daddiu sp, sp, -16\n    |\n    |  load_got __divdf3\n    |  sd CARG1, 0(sp)\n    |  call_extern\n    |.  sd CARG2, 8(sp)\n    |\n    |  load_got floor\n    |  call_extern\n    |.  move CARG1, CRET1\n    |\n    |  load_got __muldf3\n    |  move CARG1, CRET1\n    |  call_extern\n    |.  ld CARG2, 8(sp)\n    |\n    |  load_got __subdf3\n    |  ld CARG1, 0(sp)\n    |  call_extern\n    |.  move CARG2, CRET1\n    |\n    |  daddiu sp, sp, 16\n    |.endmacro\n\n    |.macro ins_arithpre, label\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||switch (vk) {\n    ||case 0:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = num_const*8\n    |   daddu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   daddu RC, KBASE, RC\n    ||  break;\n    ||case 1:\n    |   decode_RB8a RC, INS\n    |   decode_RB8b RC\n    |    decode_RDtoRC8 RB, RD\n    |   // RA = dst*8, RB = num_const*8, RC = src1*8\n    |   daddu RC, BASE, RC\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   daddu RB, KBASE, RB\n    ||  break;\n    ||default:\n    |   decode_RB8a RB, INS\n    |   decode_RB8b RB\n    |    decode_RDtoRC8 RC, RD\n    |   // RA = dst*8, RB = src1*8, RC = src2*8\n    |   daddu RB, BASE, RB\n    |.if \"label\" ~= \"none\"\n    |   b label\n    |.endif\n    |.   daddu RC, BASE, RC\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arith, intins, fpins, fpcall, label\n    |  ins_arithpre none\n    |\n    |.if \"label\" ~= \"none\"\n    |label:\n    |.endif\n    |\n    |// Used in 5.\n    |  ld CARG1, 0(RB)\n    |   ld CARG2, 0(RC)\n    |  gettp TMP0, CARG1\n    |   gettp TMP1, CARG2\n    |\n    |.if \"intins\" ~= \"div\"\n    |\n    |  // Check for two integers.\n    |  sextw CARG3, CARG1\n    |  bne TMP0, TISNUM, >5\n    |.  sextw CARG4, CARG2\n    |  bne TMP1, TISNUM, >5\n    |\n    |.if \"intins\" == \"addu\"\n    |.  intins CRET1, CARG3, CARG4\n    |  xor TMP1, CRET1, CARG3\t\t// ((y^a) & (y^b)) < 0: overflow.\n    |  xor TMP2, CRET1, CARG4\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  daddu RA, BASE, RA\n    |.elif \"intins\" == \"subu\"\n    |.  intins CRET1, CARG3, CARG4\n    |  xor TMP1, CRET1, CARG3\t\t// ((y^a) & (a^b)) < 0: overflow.\n    |  xor TMP2, CARG3, CARG4\n    |  and TMP1, TMP1, TMP2\n    |  bltz TMP1, ->vmeta_arith\n    |.  daddu RA, BASE, RA\n    |.elif \"intins\" == \"mult\"\n    |.if MIPSR6\n    |.  nop\n    |  mul CRET1, CARG3, CARG4\n    |  muh TMP2, CARG3, CARG4\n    |.else\n    |.  intins CARG3, CARG4\n    |  mflo CRET1\n    |  mfhi TMP2\n    |.endif\n    |  sra TMP1, CRET1, 31\n    |  bne TMP1, TMP2, ->vmeta_arith\n    |.  daddu RA, BASE, RA\n    |.else\n    |.  load_got lj_vm_modi\n    |  beqz CARG4, ->vmeta_arith\n    |.  daddu RA, BASE, RA\n    |  move CARG1, CARG3\n    |  call_extern\n    |.  move CARG2, CARG4\n    |.endif\n    |\n    |  zextw CRET1, CRET1\n    |  settp CRET1, TISNUM\n    |  ins_next1\n    |  sd CRET1, 0(RA)\n    |3:\n    |  ins_next2\n    |\n    |.endif\n    |\n    |5:  // Check for two numbers.\n    |  .FPU ldc1 FTMP0, 0(RB)\n    |  sltu AT, TMP0, TISNUM\n    |   sltu TMP0, TMP1, TISNUM\n    |  .FPU ldc1 FTMP2, 0(RC)\n    |   and AT, AT, TMP0\n    |   beqz AT, ->vmeta_arith\n    |.   daddu RA, BASE, RA\n    |\n    |.if FPU\n    |  fpins FRET1, FTMP0, FTMP2\n    |.elif \"fpcall\" == \"sfpmod\"\n    |  sfpmod\n    |.else\n    |  load_got fpcall\n    |  call_extern\n    |.  nop\n    |.endif\n    |\n    |  ins_next1\n    |.if \"intins\" ~= \"div\"\n    |  b <3\n    |.endif\n    |.if FPU\n    |.  sdc1 FRET1, 0(RA)\n    |.else\n    |.  sd CRET1, 0(RA)\n    |.endif\n    |.if \"intins\" == \"div\"\n    |  ins_next2\n    |.endif\n    |\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith addu, add.d, __adddf3, none\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith subu, sub.d, __subdf3, none\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith mult, mul.d, __muldf3, none\n    break;\n  case BC_DIVVN:\n    |  ins_arith div, div.d, __divdf3, ->BC_DIVVN_Z\n    break;\n  case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithpre ->BC_DIVVN_Z\n    break;\n  case BC_MODVN:\n    |  ins_arith modi, fpmod, sfpmod, ->BC_MODVN_Z\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre ->BC_MODVN_Z\n    break;\n  case BC_POW:\n    |  ins_arithpre none\n    |  ld CARG1, 0(RB)\n    |   ld CARG2, 0(RC)\n    |  gettp TMP0, CARG1\n    |   gettp TMP1, CARG2\n    |  sltiu TMP0, TMP0, LJ_TISNUM\n    |   sltiu TMP1, TMP1, LJ_TISNUM\n    |  and AT, TMP0, TMP1\n    |  load_got pow\n    |  beqz AT, ->vmeta_arith\n    |.  daddu RA, BASE, RA\n    |.if FPU\n    |  ldc1 FARG1, 0(RB)\n    |  ldc1 FARG2, 0(RC)\n    |.endif\n    |  call_extern\n    |.  nop\n    |  ins_next1\n    |.if FPU\n    |  sdc1 FRET1, 0(RA)\n    |.else\n    |  sd CRET1, 0(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  case BC_CAT:\n    |  // RA = dst*8, RB = src_start*8, RC = src_end*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  dsubu CARG3, RC, RB\n    |   sd BASE, L->base\n    |  daddu CARG2, BASE, RC\n    |  move MULTRES, RB\n    |->BC_CAT_Z:\n    |  load_got lj_meta_cat\n    |  srl CARG3, CARG3, 3\n    |   sd PC, SAVE_PC\n    |  call_intern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |.  move CARG1, L\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  bnez CRET1, ->vmeta_binop\n    |.  ld BASE, L->base\n    |  daddu RB, BASE, MULTRES\n    |  ld CRET1, 0(RB)\n    |   daddu RA, BASE, RA\n    |  ins_next1\n    |  sd CRET1, 0(RA)\n    |  ins_next2\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RD = str_const*8 (~)\n    |  dsubu TMP1, KBASE, RD\n    |  ins_next1\n    |   li TMP2, LJ_TSTR\n    |  ld TMP0, -8(TMP1)\t\t// KBASE-8-str_const*8\n    |  daddu RA, BASE, RA\n    |   settp TMP0, TMP2\n    |  sd TMP0, 0(RA)\n    |  ins_next2\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RD = cdata_const*8 (~)\n    |  dsubu TMP1, KBASE, RD\n    |  ins_next1\n    |  ld TMP0, -8(TMP1)\t\t// KBASE-8-cdata_const*8\n    |   li TMP2, LJ_TCDATA\n    |  daddu RA, BASE, RA\n    |   settp TMP0, TMP2\n    |  sd TMP0, 0(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, RD = int16_literal*8\n    |   sra RD, INS, 16\n    |  daddu RA, BASE, RA\n    |   zextw RD, RD\n    |  ins_next1\n    |   settp RD, TISNUM\n    |   sd RD, 0(RA)\n    |  ins_next2\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RD = num_const*8\n    |  daddu RD, KBASE, RD\n    |   daddu RA, BASE, RA\n    |  ld CRET1, 0(RD)\n    |  ins_next1\n    |  sd CRET1, 0(RA)\n    |  ins_next2\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RD = primitive_type*8 (~)\n    |   daddu RA, BASE, RA\n    |  dsll TMP0, RD, 44\n    |  not TMP0, TMP0\n    |  ins_next1\n    |   sd TMP0, 0(RA)\n    |  ins_next2\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RD = end*8\n    |  daddu RA, BASE, RA\n    |  sd TISNIL, 0(RA)\n    |   daddiu RA, RA, 8\n    |  daddu RD, BASE, RD\n    |1:\n    |  sd TISNIL, 0(RA)\n    |  slt AT, RA, RD\n    |  bnez AT, <1\n    |.  daddiu RA, RA, 8\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RD = uvnum*8\n    |  ld LFUNC:RB, FRAME_FUNC(BASE)\n    |   daddu RA, BASE, RA\n    |  cleartp LFUNC:RB\n    |  daddu RD, RD, LFUNC:RB\n    |  ld UPVAL:RB, LFUNC:RD->uvptr\n    |  ins_next1\n    |  ld TMP1, UPVAL:RB->v\n    |  ld CRET1, 0(TMP1)\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RD = src*8\n    |  ld LFUNC:RB, FRAME_FUNC(BASE)\n    |   daddu RD, BASE, RD\n    |  cleartp LFUNC:RB\n    |  daddu RA, RA, LFUNC:RB\n    |  ld UPVAL:RB, LFUNC:RA->uvptr\n    |   ld CRET1, 0(RD)\n    |  lbu TMP3, UPVAL:RB->marked\n    |   ld CARG2, UPVAL:RB->v\n    |  andi TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |  lbu TMP0, UPVAL:RB->closed\n    |   gettp TMP2, CRET1\n    |   sd CRET1, 0(CARG2)\n    |  li AT, LJ_GC_BLACK|1\n    |  or TMP3, TMP3, TMP0\n    |  beq TMP3, AT, >2\t\t\t// Upvalue is closed and black?\n    |.  daddiu TMP2, TMP2, -(LJ_TNUMX+1)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)\n    |  beqz AT, <1\t\t\t// tvisgcv(v)\n    |.  cleartp GCOBJ:CRET1, CRET1\n    |  lbu TMP3, GCOBJ:CRET1->gch.marked\n    |  andi TMP3, TMP3, LJ_GC_WHITES\t// iswhite(v)\n    |  beqz TMP3, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  daddiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RD = str_const*8 (~)\n    |  ld LFUNC:RB, FRAME_FUNC(BASE)\n    |   dsubu TMP1, KBASE, RD\n    |  cleartp LFUNC:RB\n    |  daddu RA, RA, LFUNC:RB\n    |  ld UPVAL:RB, LFUNC:RA->uvptr\n    |   ld STR:TMP1, -8(TMP1)\t\t// KBASE-8-str_const*8\n    |  lbu TMP2, UPVAL:RB->marked\n    |   ld CARG2, UPVAL:RB->v\n    |   lbu TMP3, STR:TMP1->marked\n    |  andi AT, TMP2, LJ_GC_BLACK\t// isblack(uv)\n    |   lbu TMP2, UPVAL:RB->closed\n    |   li TMP0, LJ_TSTR\n    |   settp TMP1, TMP0\n    |  bnez AT, >2\n    |.  sd TMP1, 0(CARG2)\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  beqz TMP2, <1\n    |.  andi AT, TMP3, LJ_GC_WHITES\t// iswhite(str)\n    |  beqz AT, <1\n    |.  load_got lj_gc_barrieruv\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  call_intern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |.  daddiu CARG1, DISPATCH, GG_DISP2G\n    |  b <1\n    |.  nop\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RD = num_const*8\n    |  ld LFUNC:RB, FRAME_FUNC(BASE)\n    |   daddu RD, KBASE, RD\n    |  cleartp LFUNC:RB\n    |  daddu RA, RA, LFUNC:RB\n    |  ld UPVAL:RB, LFUNC:RA->uvptr\n    |   ld CRET1, 0(RD)\n    |  ld TMP1, UPVAL:RB->v\n    |  ins_next1\n    |   sd CRET1, 0(TMP1)\n    |  ins_next2\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RD = primitive_type*8 (~)\n    |  ld LFUNC:RB, FRAME_FUNC(BASE)\n    |   dsll TMP0, RD, 44\n    |  cleartp LFUNC:RB\n    |  daddu RA, RA, LFUNC:RB\n    |   not TMP0, TMP0\n    |  ld UPVAL:RB, LFUNC:RA->uvptr\n    |  ins_next1\n    |  ld TMP1, UPVAL:RB->v\n    |   sd TMP0, 0(TMP1)\n    |  ins_next2\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RD = target\n    |  ld TMP2, L->openupval\n    |  branch_RD\t\t\t// Do this first since RD is not saved.\n    |  load_got lj_func_closeuv\n    |   sd BASE, L->base\n    |  beqz TMP2, >1\n    |.  move CARG1, L\n    |  call_intern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |.  daddu CARG2, BASE, RA\n    |  ld BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)\n    |  load_got lj_func_newL_gc\n    |  dsubu TMP1, KBASE, RD\n    |  ld CARG3, FRAME_FUNC(BASE)\n    |   ld CARG2, -8(TMP1)\t\t// KBASE-8-tab_const*8\n    |    sd BASE, L->base\n    |    sd PC, SAVE_PC\n    |  cleartp CARG3\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call_intern lj_func_newL_gc\n    |.  move CARG1, L\n    |  // Returns GCfuncL *.\n    |   li TMP0, LJ_TFUNC\n    |  ld BASE, L->base\n    |  ins_next1\n    |   settp CRET1, TMP0\n    |  daddu RA, BASE, RA\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)\n    |  ld TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n    |  ld TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n    |   sd BASE, L->base\n    |   sd PC, SAVE_PC\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, >5\n    |1:\n    if (op == BC_TNEW) {\n      |  load_got lj_tab_new\n      |  srl CARG2, RD, 3\n      |  andi CARG2, CARG2, 0x7ff\n      |  li TMP0, 0x801\n      |  addiu AT, CARG2, -0x7ff\n      |   srl CARG3, RD, 14\n      |.if MIPSR6\n      |  seleqz TMP0, TMP0, AT\n      |  selnez CARG2, CARG2, AT\n      |  or CARG2, CARG2, TMP0\n      |.else\n      |  movz CARG2, TMP0, AT\n      |.endif\n      |  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  call_intern lj_tab_new\n      |.  move CARG1, L\n      |  // Returns Table *.\n    } else {\n      |  load_got lj_tab_dup\n      |  dsubu TMP1, KBASE, RD\n      |  move CARG1, L\n      |  call_intern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n      |.  ld CARG2, -8(TMP1)\t\t// KBASE-8-str_const*8\n      |  // Returns Table *.\n    }\n    |   li TMP0, LJ_TTAB\n    |  ld BASE, L->base\n    |  ins_next1\n    |  daddu RA, BASE, RA\n    |   settp CRET1, TMP0\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    |5:\n    |  load_got lj_gc_step_fixtop\n    |  move MULTRES, RD\n    |  call_intern lj_gc_step_fixtop\t// (lua_State *L)\n    |.  move CARG1, L\n    |  b <1\n    |.  move RD, MULTRES\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RD = str_const*8 (~)\n  case BC_GSET:\n    |  // RA = src*8, RD = str_const*8 (~)\n    |  ld LFUNC:TMP2, FRAME_FUNC(BASE)\n    |   dsubu TMP1, KBASE, RD\n    |   ld STR:RC, -8(TMP1)\t\t// KBASE-8-str_const*8\n    |  cleartp LFUNC:TMP2\n    |  ld TAB:RB, LFUNC:TMP2->env\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    |.  daddu RA, BASE, RA\n    break;\n\n  case BC_TGETV:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  daddu CARG2, BASE, RB\n    |   daddu CARG3, BASE, RC\n    |  ld TAB:RB, 0(CARG2)\n    |   ld TMP2, 0(CARG3)\n    |   daddu RA, BASE, RA\n    |  checktab TAB:RB, ->vmeta_tgetv\n    |   gettp TMP3, TMP2\n    |  bne TMP3, TISNUM, >5\t\t// Integer key?\n    |.  lw TMP0, TAB:RB->asize\n    |  sextw TMP2, TMP2\n    |   ld TMP1, TAB:RB->array\n    |  sltu AT, TMP2, TMP0\n    |   sll TMP2, TMP2, 3\n    |  beqz AT, ->vmeta_tgetv\t\t// Integer key and in array part?\n    |.  daddu TMP2, TMP1, TMP2\n    |  ld AT, 0(TMP2)\n    |  beq AT, TISNIL, >2\n    |.   ld CRET1, 0(TMP2)\n    |1:\n    |  ins_next1\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    |\n    |2:  // Check for __index if table value is nil.\n    |  ld TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetv\n    |.  nop\n    |\n    |5:\n    |  li AT, LJ_TSTR\n    |  bne TMP3, AT, ->vmeta_tgetv\n    |.  cleartp RC, TMP2\n    |  b ->BC_TGETS_Z\t\t\t// String key?\n    |.  nop\n    break;\n  case BC_TGETS:\n    |  // RA = dst*8, RB = table*8, RC = str_const*8 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RC8a RC, INS\n    |  daddu CARG2, BASE, RB\n    |   decode_RC8b RC\n    |  ld TAB:RB, 0(CARG2)\n    |   dsubu CARG3, KBASE, RC\n    |  daddu RA, BASE, RA\n    |   ld STR:RC, -8(CARG3)\t\t// KBASE-8-str_const*8\n    |  checktab TAB:RB, ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  lw TMP0, TAB:RB->hmask\n    |   lw TMP1, STR:RC->sid\n    |    ld NODE:TMP2, TAB:RB->node\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |   li TMP3, LJ_TSTR\n    |  daddu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |   settp STR:RC, TMP3\t\t// Tagged key to look for.\n    |1:\n    |  ld CARG1, NODE:TMP2->key\n    |   ld CRET1, NODE:TMP2->val\n    |    ld NODE:TMP1, NODE:TMP2->next\n    |  bne CARG1, RC, >4\n    |.  ld TAB:TMP3, TAB:RB->metatable\n    |  beq CRET1, TISNIL, >5\t\t// Key found, but nil value?\n    |.  nop\n    |3:\n    |  ins_next1\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    |\n    |4:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  beqz TAB:TMP3, <3\t\t// No metatable: done.\n    |.  move CRET1, TISNIL\n    |  lbu TMP0, TAB:TMP3->nomm\n    |  andi TMP0, TMP0, 1<<MM_index\n    |  bnez TMP0, <3\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgets\n    |.  nop\n    break;\n  case BC_TGETB:\n    |  // RA = dst*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  daddu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  ld TAB:RB, 0(CARG2)\n    |   daddu RA, BASE, RA\n    |  srl TMP0, RC, 3\n    |  checktab TAB:RB, ->vmeta_tgetb\n    |  lw TMP1, TAB:RB->asize\n    |   ld TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tgetb\n    |.  daddu RC, TMP2, RC\n    |  ld AT, 0(RC)\n    |  beq AT, TISNIL, >5\n    |.  ld CRET1, 0(RC)\n    |1:\n    |  ins_next1\n    |   sd CRET1, 0(RA)\n    |  ins_next2\n    |\n    |5:  // Check for __index if table value is nil.\n    |  ld TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_index\n    |  bnez TMP1, <1\t\t\t// 'no __index' flag set: done.\n    |.  nop\n    |  b ->vmeta_tgetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    break;\n  case BC_TGETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  daddu RB, BASE, RB\n    |   daddu RC, BASE, RC\n    |  ld TAB:CARG1, 0(RB)\n    |   lw CARG2, LO(RC)\n    |    daddu RA, BASE, RA\n    |  cleartp TAB:CARG1\n    |  lw TMP0, TAB:CARG1->asize\n    |   ld TMP1, TAB:CARG1->array\n    |  sltu AT, CARG2, TMP0\n    |   sll TMP2, CARG2, 3\n    |  beqz AT, ->vmeta_tgetr\t\t// In array part?\n    |.  daddu CRET1, TMP1, TMP2\n    |   ld CARG2, 0(CRET1)\n    |->BC_TGETR_Z:\n    |  ins_next1\n    |   sd CARG2, 0(RA)\n    |  ins_next2\n    break;\n\n  case BC_TSETV:\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  daddu CARG2, BASE, RB\n    |   daddu CARG3, BASE, RC\n    |  ld RB, 0(CARG2)\n    |   ld TMP2, 0(CARG3)\n    |  daddu RA, BASE, RA\n    |  checktab RB, ->vmeta_tsetv\n    |  checkint TMP2, >5\n    |.  sextw RC, TMP2\n    |  lw TMP0, TAB:RB->asize\n    |   ld TMP1, TAB:RB->array\n    |  sltu AT, RC, TMP0\n    |   sll TMP2, RC, 3\n    |  beqz AT, ->vmeta_tsetv\t\t// Integer key and in array part?\n    |.  daddu TMP1, TMP1, TMP2\n    |  ld TMP0, 0(TMP1)\n    |   lbu TMP3, TAB:RB->marked\n    |  beq TMP0, TISNIL, >3\n    |.  ld CRET1, 0(RA)\n    |1:\n    |   andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.  sd CRET1, 0(TMP1)\n    |2:\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  ld TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP2, TAB:TMP2->nomm\n    |  andi TMP2, TMP2, 1<<MM_newindex\n    |  bnez TMP2, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetv\n    |.  nop\n    |\n    |5:\n    |  gettp AT, TMP2\n    |  daddiu AT, AT, -LJ_TSTR\n    |  bnez AT, ->vmeta_tsetv\n    |.  nop\n    |  b ->BC_TSETS_Z\t\t\t// String key?\n    |.  cleartp STR:RC, TMP2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETS:\n    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  daddu CARG2, BASE, RB\n    |   decode_RC8a RC, INS\n    |    ld TAB:RB, 0(CARG2)\n    |   decode_RC8b RC\n    |   dsubu CARG3, KBASE, RC\n    |   ld RC, -8(CARG3)\t\t// KBASE-8-str_const*8\n    |  daddu RA, BASE, RA\n    |   cleartp STR:RC\n    |  checktab TAB:RB, ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8\n    |  lw TMP0, TAB:RB->hmask\n    |   lw TMP1, STR:RC->sid\n    |    ld NODE:TMP2, TAB:RB->node\n    |   sb r0, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |  sll TMP0, TMP1, 5\n    |  sll TMP1, TMP1, 3\n    |  subu TMP1, TMP0, TMP1\n    |   li TMP3, LJ_TSTR\n    |  daddu NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |   settp STR:RC, TMP3\t\t// Tagged key to look for.\n    |.if FPU\n    |   ldc1 FTMP0, 0(RA)\n    |.else\n    |   ld CRET1, 0(RA)\n    |.endif\n    |1:\n    |  ld TMP0, NODE:TMP2->key\n    |   ld CARG2, NODE:TMP2->val\n    |    ld NODE:TMP1, NODE:TMP2->next\n    |  bne TMP0, RC, >5\n    |.    lbu TMP3, TAB:RB->marked\n    |   beq CARG2, TISNIL, >4\t\t// Key found, but nil value?\n    |.   ld TAB:TMP0, TAB:RB->metatable\n    |2:\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.if FPU\n    |.  sdc1 FTMP0, NODE:TMP2->val\n    |.else\n    |.  sd CRET1, NODE:TMP2->val\n    |.endif\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  beqz TAB:TMP0, <2\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP0, TAB:TMP0->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  bnez TMP0, <2\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsets\n    |.  nop\n    |\n    |5:  // Follow hash chain.\n    |  bnez NODE:TMP1, <1\n    |.  move NODE:TMP2, NODE:TMP1\n    |  // End of hash chain: key not found, add a new one\n    |\n    |  // But check for __newindex first.\n    |  ld TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, >6\t\t// No metatable: continue.\n    |.  daddiu CARG3, DISPATCH, DISPATCH_GL(tmptv)\n    |  lbu TMP0, TAB:TMP2->nomm\n    |  andi TMP0, TMP0, 1<<MM_newindex\n    |  beqz TMP0, ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  load_got lj_tab_newkey\n    |  sd RC, 0(CARG3)\n    |   sd BASE, L->base\n    |  move CARG2, TAB:RB\n    |   sd PC, SAVE_PC\n    |  call_intern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k\n    |.  move CARG1, L\n    |  // Returns TValue *.\n    |  ld BASE, L->base\n    |.if FPU\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sdc1 FTMP0, 0(CRET1)\n    |.else\n    |  ld CARG1, 0(RA)\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |.  sd CARG1, 0(CRET1)\n    |.endif\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <3\n    break;\n  case BC_TSETB:\n    |  // RA = src*8, RB = table*8, RC = index*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |  daddu CARG2, BASE, RB\n    |   decode_RDtoRC8 RC, RD\n    |  ld TAB:RB, 0(CARG2)\n    |   daddu RA, BASE, RA\n    |  srl TMP0, RC, 3\n    |  checktab RB, ->vmeta_tsetb\n    |  lw TMP1, TAB:RB->asize\n    |   ld TMP2, TAB:RB->array\n    |  sltu AT, TMP0, TMP1\n    |  beqz AT, ->vmeta_tsetb\n    |.  daddu RC, TMP2, RC\n    |  ld TMP1, 0(RC)\n    |   lbu TMP3, TAB:RB->marked\n    |  beq TMP1, TISNIL, >5\n    |1:\n    |.  ld CRET1, 0(RA)\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.   sd CRET1, 0(RC)\n    |2:\n    |  ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  ld TAB:TMP2, TAB:RB->metatable\n    |  beqz TAB:TMP2, <1\t\t// No metatable: done.\n    |.  nop\n    |  lbu TMP1, TAB:TMP2->nomm\n    |  andi TMP1, TMP1, 1<<MM_newindex\n    |  bnez TMP1, <1\t\t\t// 'no __newindex' flag set: done.\n    |.  nop\n    |  b ->vmeta_tsetb\t\t\t// Caveat: preserve TMP0 and CARG2!\n    |.  nop\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0, <2\n    break;\n  case BC_TSETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  decode_RB8a RB, INS\n    |  decode_RB8b RB\n    |   decode_RDtoRC8 RC, RD\n    |  daddu CARG1, BASE, RB\n    |   daddu CARG3, BASE, RC\n    |  ld TAB:CARG2, 0(CARG1)\n    |   lw CARG3, LO(CARG3)\n    |  cleartp TAB:CARG2\n    |  lbu TMP3, TAB:CARG2->marked\n    |   lw TMP0, TAB:CARG2->asize\n    |    ld TMP1, TAB:CARG2->array\n    |  andi AT, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bnez AT, >7\n    |.  daddu RA, BASE, RA\n    |2:\n    |  sltu AT, CARG3, TMP0\n    |   sll TMP2, CARG3, 3\n    |  beqz AT, ->vmeta_tsetr\t\t// In array part?\n    |.  daddu CRET1, TMP1, TMP2\n    |->BC_TSETR_Z:\n    |  ld CARG1, 0(RA)\n    |  ins_next1\n    |  sd CARG1, 0(CRET1)\n    |  ins_next2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, CRET1, <2\n    break;\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)\n    |  daddu RA, BASE, RA\n    |1:\n    |   daddu TMP3, KBASE, RD\n    |  ld TAB:CARG2, -8(RA)\t\t// Guaranteed to be a table.\n    |    addiu TMP0, MULTRES, -8\n    |   lw TMP3, LO(TMP3)\t\t// Integer constant is in lo-word.\n    |    beqz TMP0, >4\t\t\t// Nothing to copy?\n    |.    srl CARG3, TMP0, 3\n    |  cleartp CARG2\n    |  addu CARG3, CARG3, TMP3\n    |  lw TMP2, TAB:CARG2->asize\n    |   sll TMP1, TMP3, 3\n    |    lbu TMP3, TAB:CARG2->marked\n    |   ld CARG1, TAB:CARG2->array\n    |  sltu AT, TMP2, CARG3\n    |  bnez AT, >5\n    |.  daddu TMP2, RA, TMP0\n    |   daddu TMP1, TMP1, CARG1\n    |  andi TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |3:  // Copy result slots to table.\n    |   ld CRET1, 0(RA)\n    |    daddiu RA, RA, 8\n    |  sltu AT, RA, TMP2\n    |   sd CRET1, 0(TMP1)\n    |  bnez AT, <3\n    |.   daddiu TMP1, TMP1, 8\n    |  bnez TMP0, >7\n    |.  nop\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  load_got lj_tab_reasize\n    |   sd BASE, L->base\n    |   sd PC, SAVE_PC\n    |  move BASE, RD\n    |  call_intern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |.  move CARG1, L\n    |  // Must not reallocate the stack.\n    |  move RD, BASE\n    |  b <1\n    |.  ld BASE, L->base\t// Reload BASE for lack of a saved register.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP0, <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |  b ->BC_CALL_Z\n    |.  addu NARGS8:RC, NARGS8:RC, MULTRES\n    break;\n  case BC_CALL:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8\n    |  decode_RDtoRC8 NARGS8:RC, RD\n    |->BC_CALL_Z:\n    |  move TMP2, BASE\n    |  daddu BASE, BASE, RA\n    |   ld LFUNC:RB, 0(BASE)\n    |   daddiu BASE, BASE, 16\n    |  addiu NARGS8:RC, NARGS8:RC, -8\n    |  checkfunc RB, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8\n    |  addu NARGS8:RD, NARGS8:RD, MULTRES\t// BC_CALLT gets RC from RD.\n    |  // Fall through. Assumes BC_CALLT follows.\n    break;\n  case BC_CALLT:\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |  daddu RA, BASE, RA\n    |  ld RB, 0(RA)\n    |   move NARGS8:RC, RD\n    |    ld TMP1, FRAME_PC(BASE)\n    |   daddiu RA, RA, 16\n    |  addiu NARGS8:RC, NARGS8:RC, -8\n    |  checktp CARG3, RB, -LJ_TFUNC, ->vmeta_callt\n    |->BC_CALLT_Z:\n    |  andi TMP0, TMP1, FRAME_TYPE\t// Caveat: preserve TMP0 until the 'or'.\n    |   lbu TMP3, LFUNC:CARG3->ffid\n    |  bnez TMP0, >7\n    |.  xori TMP2, TMP1, FRAME_VARG\n    |1:\n    |  sd RB, FRAME_FUNC(BASE)\t\t// Copy function down, but keep PC.\n    |  sltiu AT, TMP3, 2\t\t// (> FF_C) Calling a fast function?\n    |  move TMP2, BASE\n    |  move RB, CARG3\n    |  beqz NARGS8:RC, >3\n    |.  move TMP3, NARGS8:RC\n    |2:\n    |   ld CRET1, 0(RA)\n    |    daddiu RA, RA, 8\n    |  addiu TMP3, TMP3, -8\n    |   sd CRET1, 0(TMP2)\n    |  bnez TMP3, <2\n    |.   daddiu TMP2, TMP2, 8\n    |3:\n    |  or TMP0, TMP0, AT\n    |  beqz TMP0, >5\n    |.  nop\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  lw INS, -4(TMP1)\n    |  decode_RA8a RA, INS\n    |  decode_RA8b RA\n    |  dsubu TMP1, BASE, RA\n    |  ld TMP1, -32(TMP1)\n    |  cleartp LFUNC:TMP1\n    |  ld TMP1, LFUNC:TMP1->pc\n    |  b <4\n    |.  ld KBASE, PC2PROTO(k)(TMP1)\t// Need to prepare KBASE.\n    |\n    |7:  // Tailcall from a vararg function.\n    |  andi AT, TMP2, FRAME_TYPEP\n    |  bnez AT, <1\t\t\t// Vararg frame below?\n    |.  dsubu TMP2, BASE, TMP2\t\t// Relocate BASE down.\n    |  move BASE, TMP2\n    |  ld TMP1, FRAME_PC(TMP2)\n    |  b <1\n    |.  andi TMP0, TMP1, FRAME_TYPE\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))\n    |  move TMP2, BASE\t\t\t// Save old BASE fir vmeta_call.\n    |  daddu BASE, BASE, RA\n    |  ld RB, -24(BASE)\n    |   ld CARG1, -16(BASE)\n    |    ld CARG2, -8(BASE)\n    |  li NARGS8:RC, 16\t\t\t// Iterators get 2 arguments.\n    |  sd RB, 0(BASE)\t\t\t// Copy callable.\n    |   sd CARG1, 16(BASE)\t\t// Copy state.\n    |    sd CARG2, 24(BASE)\t\t// Copy control var.\n    |   daddiu BASE, BASE, 16\n    |  checkfunc RB, ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT and ENDIAN_LE\n    |  hotloop\n    |.endif\n    |->vm_IITERN:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)\n    |  daddu RA, BASE, RA\n    |  ld TAB:RB, -16(RA)\n    |   lw RC, -8+LO(RA)\t\t// Get index from control var.\n    |  cleartp TAB:RB\n    |   daddiu PC, PC, 4\n    |  lw TMP0, TAB:RB->asize\n    |   ld TMP1, TAB:RB->array\n    |  dsll CARG3, TISNUM, 47\n    |1:  // Traverse array part.\n    |  sltu AT, RC, TMP0\n    |  beqz AT, >5\t\t\t// Index points after array part?\n    |.  sll TMP3, RC, 3\n    |  daddu TMP3, TMP1, TMP3\n    |  ld CARG1, 0(TMP3)\n    |     lhu RD, -4+OFS_RD(PC)\n    |   or TMP2, RC, CARG3\n    |  beq CARG1, TISNIL, <1\t\t// Skip holes in array part.\n    |.  addiu RC, RC, 1\n    |   sd TMP2, 0(RA)\n    |  sd CARG1, 8(RA)\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |     decode_RD4b RD\n    |     daddu RD, RD, TMP3\n    |   sw RC, -8+LO(RA)\t\t// Update control var.\n    |     daddu PC, PC, RD\n    |3:\n    |  ins_next\n    |\n    |5:  // Traverse hash part.\n    |  lw TMP1, TAB:RB->hmask\n    |  subu RC, RC, TMP0\n    |   ld TMP2, TAB:RB->node\n    |6:\n    |  sltu AT, TMP1, RC\t\t// End of iteration? Branch to ITERL+1.\n    |  bnez AT, <3\n    |.  sll TMP3, RC, 5\n    |   sll RB, RC, 3\n    |   subu TMP3, TMP3, RB\n    |  daddu NODE:TMP3, TMP3, TMP2\n    |  ld CARG1, 0(NODE:TMP3)\n    |     lhu RD, -4+OFS_RD(PC)\n    |  beq CARG1, TISNIL, <6\t\t// Skip holes in hash part.\n    |.  addiu RC, RC, 1\n    |  ld CARG2, NODE:TMP3->key\n    |     lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  sd CARG1, 8(RA)\n    |    addu RC, RC, TMP0\n    |     decode_RD4b RD\n    |     addu RD, RD, TMP3\n    |  sd CARG2, 0(RA)\n    |     daddu PC, PC, RD\n    |  b <3\n    |.  sw RC, -8+LO(RA)\t\t// Update control var.\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RD = target (points to ITERN)\n    |  daddu RA, BASE, RA\n    |    srl TMP0, RD, 1\n    |  ld CFUNC:CARG1, -24(RA)\n    |    daddu TMP0, PC, TMP0\n    |   ld CARG2, -16(RA)\n    |   ld CARG3, -8(RA)\n    |    lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n    |  checkfunc CFUNC:CARG1, >5\n    |  gettp CARG2, CARG2\n    |  daddiu CARG2, CARG2, -LJ_TTAB\n    |  lbu TMP1, CFUNC:CARG1->ffid\n    |  daddiu CARG3, CARG3, -LJ_TNIL\n    |  or AT, CARG2, CARG3\n    |  daddiu TMP1, TMP1, -FF_next_N\n    |  or AT, AT, TMP1\n    |  bnez AT, >5\n    |.  lui TMP1, (LJ_KEYINDEX >> 16)\n    |  daddu PC, TMP0, TMP2\n    |  ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)\n    |  dsll TMP1, TMP1, 32\n    |  sd TMP1, -8(RA)\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  li TMP3, BC_JMP\n    |   li TMP1, BC_ITERC\n    |  sb TMP3, -4+OFS_OP(PC)\n    |   daddu PC, TMP0, TMP2\n    |.if JIT\n    |  lb TMP0, OFS_OP(PC)\n    |  li AT, BC_ITERN\n    |  bne TMP0, AT, >6\n    |.  lhu TMP2, OFS_RD(PC)\n    |.endif\n    |  b <1\n    |.  sb TMP1, OFS_OP(PC)\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  ld TMP0, DISPATCH_J(trace)(DISPATCH)\n    |   sll TMP2, TMP2, 3\n    |  daddu TMP0, TMP0, TMP2\n    |  ld TRACE:TMP2, 0(TMP0)\n    |  lw TMP0, TRACE:TMP2->startins\n    |   li AT, -256\n    |  and TMP0, TMP0, AT\n    |  or TMP0, TMP0, TMP1\n    |  b <1\n    |.  sw TMP0, 0(PC)\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  ld TMP0, FRAME_PC(BASE)\n    |  decode_RDtoRC8 RC, RD\n    |   decode_RB8a RB, INS\n    |  daddu RC, BASE, RC\n    |   decode_RB8b RB\n    |   daddu RA, BASE, RA\n    |  daddiu RC, RC, FRAME_VARG\n    |   daddu TMP2, RA, RB\n    |  daddiu TMP3, BASE, -16\t\t// TMP3 = vtop\n    |  dsubu RC, RC, TMP0\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  beqz RB, >5\t\t\t// Copy all varargs?\n    |.  dsubu TMP1, TMP3, RC\n    |  daddiu TMP2, TMP2, -16\n    |1:  // Copy vararg slots to destination slots.\n    |  ld CARG1, 0(RC)\n    |  sltu AT, RC, TMP3\n    |    daddiu RC, RC, 8\n    |.if MIPSR6\n    |  selnez CARG1, CARG1, AT\n    |  seleqz AT, TISNIL, AT\n    |  or CARG1, CARG1, AT\n    |.else\n    |  movz CARG1, TISNIL, AT\n    |.endif\n    |  sd CARG1, 0(RA)\n    |  sltu AT, RA, TMP2\n    |  bnez AT, <1\n    |.   daddiu RA, RA, 8\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  ld TMP0, L->maxstack\n    |  blez TMP1, <3\t\t\t// No vararg slots?\n    |.  li MULTRES, 8\t\t\t// MULTRES = (0+1)*8\n    |  daddu TMP2, RA, TMP1\n    |  sltu AT, TMP0, TMP2\n    |  bnez AT, >7\n    |.  daddiu MULTRES, TMP1, 8\n    |6:\n    |  ld CRET1, 0(RC)\n    |   daddiu RC, RC, 8\n    |  sd CRET1, 0(RA)\n    |  sltu AT, RC, TMP3\n    |  bnez AT, <6\t\t\t// More vararg slots?\n    |.  daddiu RA, RA, 8\n    |  b <3\n    |.  nop\n    |\n    |7:  // Grow stack for varargs.\n    |  load_got lj_state_growstack\n    |   sd RA, L->top\n    |  dsubu RA, RA, BASE\n    |   sd BASE, L->base\n    |  dsubu BASE, RC, BASE\t\t// Need delta, because BASE may change.\n    |   sd PC, SAVE_PC\n    |  srl CARG2, TMP1, 3\n    |  call_intern lj_state_growstack\t// (lua_State *L, int n)\n    |.  move CARG1, L\n    |  move RC, BASE\n    |  ld BASE, L->base\n    |  daddu RA, BASE, RA\n    |  daddu RC, BASE, RC\n    |  b <6\n    |.  daddiu TMP3, BASE, -16\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RD = extra_nresults*8\n    |  addu RD, RD, MULTRES\t\t// MULTRES >= 8, so RD >= 8.\n    |  // Fall through. Assumes BC_RET follows.\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  ld PC, FRAME_PC(BASE)\n    |   daddu RA, BASE, RA\n    |    move MULTRES, RD\n    |1:\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return\n    |   lw INS, -4(PC)\n    |    daddiu TMP2, BASE, -16\n    |    daddiu RC, RD, -8\n    |  decode_RA8a TMP0, INS\n    |   decode_RB8a RB, INS\n    |  decode_RA8b TMP0\n    |   decode_RB8b RB\n    |   daddu TMP3, TMP2, RB\n    |  beqz RC, >3\n    |.  dsubu BASE, TMP2, TMP0\n    |2:\n    |   ld CRET1, 0(RA)\n    |    daddiu RA, RA, 8\n    |  daddiu RC, RC, -8\n    |   sd CRET1, 0(TMP2)\n    |  bnez RC, <2\n    |.   daddiu TMP2, TMP2, 8\n    |3:\n    |  daddiu TMP3, TMP3, -8\n    |5:\n    |  sltu AT, TMP2, TMP3\n    |  bnez AT, >6\n    |.  ld LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  cleartp LFUNC:TMP1\n    |  ld TMP1, LFUNC:TMP1->pc\n    |  ld KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  sd TISNIL, 0(TMP2)\n    |  b <5\n    |.  daddiu TMP2, TMP2, 8\n    |\n    |->BC_RETV_Z:  // Non-standard return case.\n    |  andi TMP2, TMP1, FRAME_TYPEP\n    |  bnez TMP2, ->vm_return\n    |.  nop\n    |  // Return from vararg function: relocate BASE down.\n    |  dsubu BASE, BASE, TMP1\n    |  b <1\n    |.  ld PC, FRAME_PC(BASE)\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  ld PC, FRAME_PC(BASE)\n    |   daddu RA, BASE, RA\n    |    move MULTRES, RD\n    |  andi TMP0, PC, FRAME_TYPE\n    |  bnez TMP0, ->BC_RETV_Z\n    |.  xori TMP1, PC, FRAME_VARG\n    |  lw INS, -4(PC)\n    |   daddiu TMP2, BASE, -16\n    if (op == BC_RET1) {\n      |  ld CRET1, 0(RA)\n    }\n    |  decode_RB8a RB, INS\n    |   decode_RA8a RA, INS\n    |  decode_RB8b RB\n    |   decode_RA8b RA\n    |   dsubu BASE, TMP2, RA\n    if (op == BC_RET1) {\n      |  sd CRET1, 0(TMP2)\n    }\n    |5:\n    |  sltu AT, RD, RB\n    |  bnez AT, >6\n    |.  ld TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  cleartp LFUNC:TMP1\n    |  ld TMP1, LFUNC:TMP1->pc\n    |  ld KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  daddiu TMP2, TMP2, 8\n    |  daddiu RD, RD, 8\n    |  b <5\n    if (op == BC_RET1) {\n      |.  sd TISNIL, 0(TMP2)\n    } else {\n      |.  sd TISNIL, -8(TMP2)\n    }\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RD = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  daddu RA, BASE, RA\n    |  ld CARG1, FORL_IDX*8(RA)\t\t// IDX CARG1 - CARG3 type\n    |  gettp CARG3, CARG1\n    if (op != BC_JFORL) {\n      |  srl RD, RD, 1\n      |  lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)\n      |  daddu TMP2, RD, TMP2\n    }\n    if (!vk) {\n      |  ld CARG2, FORL_STOP*8(RA)\t// STOP CARG2 - CARG4 type\n      |  ld CRET1, FORL_STEP*8(RA)\t// STEP CRET1 - CRET2 type\n      |  gettp CARG4, CARG2\n      |  bne CARG3, TISNUM, >5\n      |.  gettp CRET2, CRET1\n      |  bne CARG4, TISNUM, ->vmeta_for\n      |.  sextw CARG3, CARG1\n      |  bne CRET2, TISNUM, ->vmeta_for\n      |.  sextw CARG2, CARG2\n      |  dext AT, CRET1, 31, 0\n      |  slt CRET1, CARG2, CARG3\n      |  slt TMP1, CARG3, CARG2\n      |.if MIPSR6\n      |  selnez TMP1, TMP1, AT\n      |  seleqz CRET1, CRET1, AT\n      |  or CRET1, CRET1, TMP1\n      |.else\n      |  movn CRET1, TMP1, AT\n      |.endif\n    } else {\n      |  bne CARG3, TISNUM, >5\n      |.  ld CARG2, FORL_STEP*8(RA)\t// STEP CARG2 - CARG4 type\n      |    ld CRET1, FORL_STOP*8(RA)\t// STOP CRET1 - CRET2 type\n      |  sextw TMP3, CARG1\n      |   sextw CARG2, CARG2\n      |    sextw CRET1, CRET1\n      |  addu CARG1, TMP3, CARG2\n      |  xor TMP0, CARG1, TMP3\n      |  xor TMP1, CARG1, CARG2\n      |  and TMP0, TMP0, TMP1\n      |  slt TMP1, CARG1, CRET1\n      |  slt CRET1, CRET1, CARG1\n      |  slt AT, CARG2, r0\n      |   slt TMP0, TMP0, r0\t\t// ((y^a) & (y^b)) < 0: overflow.\n      |.if MIPSR6\n      |  selnez TMP1, TMP1, AT\n      |  seleqz CRET1, CRET1, AT\n      |  or CRET1, CRET1, TMP1\n      |.else\n      |  movn CRET1, TMP1, AT\n      |.endif\n      |   or CRET1, CRET1, TMP0\n      |  zextw CARG1, CARG1\n      |  settp CARG1, TISNUM\n    }\n    |1:\n    if (op == BC_FORI) {\n      |.if MIPSR6\n      |  selnez TMP2, TMP2, CRET1\n      |.else\n      |  movz TMP2, r0, CRET1\n      |.endif\n      |  daddu PC, PC, TMP2\n    } else if (op == BC_JFORI) {\n      |  daddu PC, PC, TMP2\n      |  lhu RD, -4+OFS_RD(PC)\n    } else if (op == BC_IFORL) {\n      |.if MIPSR6\n      |  seleqz TMP2, TMP2, CRET1\n      |.else\n      |  movn TMP2, r0, CRET1\n      |.endif\n      |  daddu PC, PC, TMP2\n    }\n    if (vk) {\n      |  sd CARG1, FORL_IDX*8(RA)\n    }\n    |  ins_next1\n    |  sd CARG1, FORL_EXT*8(RA)\n    |2:\n    if (op == BC_JFORI) {\n      |  beqz CRET1, =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else if (op == BC_JFORL) {\n      |  beqz CRET1, =>BC_JLOOP\n    }\n    |  ins_next2\n    |\n    |5:  // FP loop.\n    |.if FPU\n    if (!vk) {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f2, FORL_STOP*8(RA)\n      |  sltiu TMP0, CARG3, LJ_TISNUM\n      |  sltiu TMP1, CARG4, LJ_TISNUM\n      |  sltiu AT, CRET2, LJ_TISNUM\n      |   ld TMP3, FORL_STEP*8(RA)\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  slt TMP3, TMP3, r0\n      |.if MIPSR6\n      |   dmtc1 TMP3, FTMP2\n      |  cmp.lt.d FTMP0, f0, f2\n      |  cmp.lt.d FTMP1, f2, f0\n      |  sel.d FTMP2, FTMP1, FTMP0\n      |  b <1\n      |.  dmfc1 CRET1, FTMP2\n      |.else\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |  li CRET1, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  b <1\n      |.  movn CRET1, AT, TMP3\n      |.endif\n    } else {\n      |  ldc1 f0, FORL_IDX*8(RA)\n      |   ldc1 f4, FORL_STEP*8(RA)\n      |    ldc1 f2, FORL_STOP*8(RA)\n      |   ld TMP3, FORL_STEP*8(RA)\n      |  add.d f0, f0, f4\n      |.if MIPSR6\n      |   slt TMP3, TMP3, r0\n      |   dmtc1 TMP3, FTMP2\n      |  cmp.lt.d FTMP0, f0, f2\n      |  cmp.lt.d FTMP1, f2, f0\n      |  sel.d FTMP2, FTMP1, FTMP0\n      |  dmfc1 CRET1, FTMP2\n      if (op == BC_IFORL) {\n\t|  seleqz TMP2, TMP2, CRET1\n\t|  daddu PC, PC, TMP2\n      }\n      |.else\n      |  c.ole.d 0, f0, f2\n      |  c.ole.d 1, f2, f0\n      |   slt TMP3, TMP3, r0\n      |  li CRET1, 1\n      |  li AT, 1\n      |  movt CRET1, r0, 0\n      |  movt AT, r0, 1\n      |  movn CRET1, AT, TMP3\n      if (op == BC_IFORL) {\n\t|  movn TMP2, r0, CRET1\n\t|  daddu PC, PC, TMP2\n      }\n      |.endif\n      |  sdc1 f0, FORL_IDX*8(RA)\n      |  ins_next1\n      |  b <2\n      |.  sdc1 f0, FORL_EXT*8(RA)\n    }\n    |.else\n    if (!vk) {\n      |  sltiu TMP0, CARG3, LJ_TISNUM\n      |  sltiu TMP1, CARG4, LJ_TISNUM\n      |  sltiu AT, CRET2, LJ_TISNUM\n      |  and TMP0, TMP0, TMP1\n      |  and AT, AT, TMP0\n      |  beqz AT, ->vmeta_for\n      |.  nop\n      |  bal ->vm_sfcmpolex\n      |.  lw TMP3, FORL_STEP*8+HI(RA)\n      |  b <1\n      |.  nop\n    } else {\n      |  load_got __adddf3\n      |  call_extern\n      |.  sw TMP2, TMPD\n      |  ld CARG2, FORL_STOP*8(RA)\n      |  move CARG1, CRET1\n      if ( op == BC_JFORL ) {\n\t|  lhu RD, -4+OFS_RD(PC)\n\t|  decode_RD8b RD\n      }\n      |  bal ->vm_sfcmpolex\n      |.  lw TMP3, FORL_STEP*8+HI(RA)\n      |  b <1\n      |.  lw TMP2, TMPD\n    }\n    |.endif\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RD = target\n    |  daddu RA, BASE, RA\n    |  ld TMP1, 0(RA)\n    |  beq TMP1, TISNIL, >1\t\t// Stop if iterator returned nil.\n    |.  nop\n    if (op == BC_JITERL) {\n      |  b =>BC_JLOOP\n      |.  sd TMP1, -8(RA)\n    } else {\n      |  branch_RD\t\t\t// Otherwise save control var + branch.\n      |  sd TMP1, -8(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base*8 (ignored), RD = traceno*8\n    |  ld TMP1, DISPATCH_J(trace)(DISPATCH)\n    |   li AT, 0\n    |  daddu TMP1, TMP1, RD\n    |  // Traces on MIPS don't store the trace number, so use 0.\n    |   sd AT, DISPATCH_GL(vmstate)(DISPATCH)\n    |  ld TRACE:TMP2, 0(TMP1)\n    |   sd BASE, DISPATCH_GL(jit_base)(DISPATCH)\n    |  ld TMP2, TRACE:TMP2->mcode\n    |   sd L, DISPATCH_GL(tmpbuf.L)(DISPATCH)\n    |  jr TMP2\n    |.  daddiu JGL, DISPATCH, GG_DISP2G+32768\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RD = target\n    |  branch_RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  ld TMP2, L->maxstack\n    |   lbu TMP1, -4+PC2PROTO(numparams)(PC)\n    |    ld KBASE, -4+PC2PROTO(k)(PC)\n    |  sltu AT, TMP2, RA\n    |  bnez AT, ->vm_growstack_l\n    |.  sll TMP1, TMP1, 3\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n    }\n    |2:\n    |  sltu AT, NARGS8:RC, TMP1\t\t// Check for missing parameters.\n    |  bnez AT, >3\n    |.  daddu AT, BASE, NARGS8:RC\n    if (op == BC_JFUNCF) {\n      |  decode_RD8a RD, INS\n      |  b =>BC_JLOOP\n      |.  decode_RD8b RD\n    } else {\n      |  ins_next2\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  sd TISNIL, 0(AT)\n    |  b <2\n    |.  addiu NARGS8:RC, NARGS8:RC, 8\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |   li TMP0, LJ_TFUNC\n    |   daddu TMP1, BASE, RC\n    |  ld TMP2, L->maxstack\n    |   settp LFUNC:RB, TMP0\n    |  daddu TMP0, RA, RC\n    |   sd LFUNC:RB, 0(TMP1)\t\t// Store (tagged) copy of LFUNC.\n    |   daddiu TMP3, RC, 16+FRAME_VARG\n    |  sltu AT, TMP0, TMP2\n    |    ld KBASE, -4+PC2PROTO(k)(PC)\n    |  beqz AT, ->vm_growstack_l\n    |.  sd TMP3, 8(TMP1)\t\t// Store delta + FRAME_VARG.\n    |  lbu TMP2, -4+PC2PROTO(numparams)(PC)\n    |   move RA, BASE\n    |   move RC, TMP1\n    |  ins_next1\n    |  beqz TMP2, >3\n    |.  daddiu BASE, TMP1, 16\n    |1:\n    |  ld TMP0, 0(RA)\n    |  sltu AT, RA, RC\t\t\t// Less args than parameters?\n    |  move CARG1, TMP0\n    |.if MIPSR6\n    |  selnez TMP0, TMP0, AT\n    |  seleqz TMP3, TISNIL, AT\n    |  or TMP0, TMP0, TMP3\n    |  seleqz TMP3, CARG1, AT\n    |  selnez CARG1, TISNIL, AT\n    |  or CARG1, CARG1, TMP3\n    |.else\n    |  movz TMP0, TISNIL, AT\t\t// Clear missing parameters.\n    |  movn CARG1, TISNIL, AT\t\t// Clear old fixarg slot (help the GC).\n    |.endif\n    |    addiu TMP2, TMP2, -1\n    |  sd TMP0, 16(TMP1)\n    |    daddiu TMP1, TMP1, 8\n    |  sd CARG1, 0(RA)\n    |  bnez TMP2, <1\n    |.   daddiu RA, RA, 8\n    |3:\n    |  ins_next2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  ld CFUNCADDR, CFUNC:RB->f\n    } else {\n      |  ld CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)\n    }\n    |  daddu TMP1, RA, NARGS8:RC\n    |  ld TMP2, L->maxstack\n    |   daddu RC, BASE, NARGS8:RC\n    |  sd BASE, L->base\n    |  sltu AT, TMP2, TMP1\n    |   sd RC, L->top\n    |    li_vmstate C\n    if (op == BC_FUNCCW) {\n      |  ld CARG2, CFUNC:RB->f\n    }\n    |  bnez AT, ->vm_growstack_c\t// Need to grow stack.\n    |.  move CARG1, L\n    |  jalr CFUNCADDR\t\t\t// (lua_State *L [, lua_CFunction f])\n    |.   st_vmstate\n    |  // Returns nresults.\n    |  ld BASE, L->base\n    |   sll RD, CRET1, 3\n    |  ld TMP1, L->top\n    |    li_vmstate INTERP\n    |  ld PC, FRAME_PC(BASE)\t\t// Fetch PC of caller.\n    |   dsubu RA, TMP1, RD\t\t// RA = L->top - nresults*8\n    |    sd L, DISPATCH_GL(cur_L)(DISPATCH)\n    |  b ->vm_returnc\n    |.   st_vmstate\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.4byte .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.4byte 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 31\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 29\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.4byte .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.8byte .Lbegin\\n\"\n\t\"\\t.8byte %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.sleb128 2*5\\n\"\n\t\"\\t.byte 0x9e\\n\\t.sleb128 2*6\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 23; i >= 16; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+i, 2*(30-i));\n#if !LJ_SOFTFP\n    for (i = 31; i >= 24; i--)\n      fprintf(ctx->fp, \"\\t.byte %d\\n\\t.uleb128 %d\\n\", 0x80+32+i, 2*(46-i));\n#endif\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.4byte .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.4byte .Lframe0\\n\"\n\t\"\\t.4byte lj_vm_ffi_call\\n\"\n\t\"\\t.4byte %d\\n\"\n\t\"\\t.byte 0x9f\\n\\t.uleb128 2*1\\n\"\n\t\"\\t.byte 0x90\\n\\t.uleb128 2*2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x10\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    /* NYI */\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_ppc.dasc",
    "content": "|// Low-level VM code for PowerPC 32 bit or 32on64 bit mode.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch ppc\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|// Note: The ragged indentation of the instructions is intentional.\n|//       The starting columns indicate data dependencies.\n|\n|//-----------------------------------------------------------------------\n|\n|// DynASM defines used by the PPC port:\n|//\n|// P64     64 bit pointers (only for GPR64 testing).\n|// GPR64   64 bit registers (but possibly 32 bit pointers, e.g. PS3).\n|//         Affects reg saves, stack layout, carry/overflow/dot flags etc.\n|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360).\n|// TOC     Need table of contents (64 bit or 32 bit variant, e.g. PS3).\n|//         Function pointers are really a struct: code, TOC, env (optional).\n|// TOCENV  Function pointers have an environment pointer, too (not on PS3).\n|// PPE     Power Processor Element of Cell (PS3) or Xenon (Xbox 360).\n|//         Must avoid (slow) micro-coded instructions.\n|\n|.if P64\n|.define TOC, 1\n|.define TOCENV, 1\n|.macro lpx, a, b, c; ldx a, b, c; .endmacro\n|.macro lp, a, b; ld a, b; .endmacro\n|.macro stp, a, b; std a, b; .endmacro\n|.define decode_OPP, decode_OP8\n|.if FFI\n|// Missing: Calling conventions, 64 bit regs, TOC.\n|.error lib_ffi not yet implemented for PPC64\n|.endif\n|.else\n|.macro lpx, a, b, c; lwzx a, b, c; .endmacro\n|.macro lp, a, b; lwz a, b; .endmacro\n|.macro stp, a, b; stw a, b; .endmacro\n|.define decode_OPP, decode_OP4\n|.endif\n|\n|// Convenience macros for TOC handling.\n|.if TOC\n|// Linker needs a TOC patch area for every external call relocation.\n|.macro blex, target; bl extern target@plt; nop; .endmacro\n|.macro .toc, a, b; a, b; .endmacro\n|.if P64\n|.define TOC_OFS,\t 8\n|.define ENV_OFS,\t16\n|.else\n|.define TOC_OFS,\t4\n|.define ENV_OFS,\t8\n|.endif\n|.else  // No TOC.\n|.macro blex, target; bl extern target@plt; .endmacro\n|.macro .toc, a, b; .endmacro\n|.endif\n|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro\n|\n|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro\n|\n|.macro andix., y, a, i\n|.if PPE\n|  rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i)\n|  cmpwi y, 0\n|.else\n|  andi. y, a, i\n|.endif\n|.endmacro\n|\n|.macro clrso, reg\n|.if PPE\n|  li reg, 0\n|  mtxer reg\n|.else\n|  mcrxr cr0\n|.endif\n|.endmacro\n|\n|.macro checkov, reg, noov\n|.if PPE\n|  mfxer reg\n|  add reg, reg, reg\n|  cmpwi reg, 0\n|   li reg, 0\n|   mtxer reg\n|  bgey noov\n|.else\n|  mcrxr cr0\n|  bley noov\n|.endif\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter.\n|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA)\n|\n|.macro .FPU, a, b\n|.if FPU\n|  a, b\n|.endif\n|.endmacro\n|\n|.macro .FPU, a, b, c\n|.if FPU\n|  a, b, c\n|.endif\n|.endmacro\n|\n|// The following must be C callee-save (but BASE is often refetched).\n|.define BASE,\t\tr14\t// Base of current Lua stack frame.\n|.define KBASE,\t\tr15\t// Constants of current Lua function.\n|.define PC,\t\tr16\t// Next PC.\n|.define DISPATCH,\tr17\t// Opcode dispatch table.\n|.define LREG,\t\tr18\t// Register holding lua_State (also in SAVE_L).\n|.define MULTRES,\tr19\t// Size of multi-result: (nresults+1)*8.\n|.define JGL,\t\tr31\t// On-trace: global_State + 32768.\n|\n|// Constants for type-comparisons, stores and conversions. C callee-save.\n|.define TISNUM,\tr22\n|.define TISNIL,\tr23\n|.define ZERO,\t\tr24\n|.if FPU\n|.define TOBIT,\t\tf30\t// 2^52 + 2^51.\n|.define TONUM,\t\tf31\t// 2^52 + 2^51 + 2^31.\n|.endif\n|\n|// The following temporaries are not saved across C calls, except for RA.\n|.define RA,\t\tr20\t// Callee-save.\n|.define RB,\t\tr10\n|.define RC,\t\tr11\n|.define RD,\t\tr12\n|.define INS,\t\tr7\t// Overlaps CARG5.\n|\n|.define TMP0,\t\tr0\n|.define TMP1,\t\tr8\n|.define TMP2,\t\tr9\n|.define TMP3,\t\tr6\t// Overlaps CARG4.\n|\n|// Saved temporaries.\n|.define SAVE0,\t\tr21\n|.define SAVE1,\t\tr25\n|\n|// Calling conventions.\n|.define CARG1,\t\tr3\n|.define CARG2,\t\tr4\n|.define CARG3,\t\tr5\n|.define CARG4,\t\tr6\t// Overlaps TMP3.\n|.define CARG5,\t\tr7\t// Overlaps INS.\n|\n|.if FPU\n|.define FARG1,\t\tf1\n|.define FARG2,\t\tf2\n|.endif\n|\n|.define CRET1,\t\tr3\n|.define CRET2,\t\tr4\n|\n|.define TOCREG,\tr2\t// TOC register (only used by C code).\n|.define ENVREG,\tr11\t// Environment pointer (nested C functions).\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.if GPR64\n|.if FRAME32\n|\n|//\t\t\t456(sp) // \\ 32/64 bit C frame info\n|.define TONUM_LO,\t452(sp) // |\n|.define TONUM_HI,\t448(sp) // |\n|.define TMPD_LO,\t444(sp) // |\n|.define TMPD_HI,\t440(sp) // |\n|.define SAVE_CR,\t432(sp) // | 64 bit CR save.\n|.define SAVE_ERRF,\t424(sp) //  > Parameter save area.\n|.define SAVE_NRES,\t420(sp) // |\n|.define SAVE_L,\t416(sp) // |\n|.define SAVE_PC,\t412(sp) // |\n|.define SAVE_MULTRES,\t408(sp) // |\n|.define SAVE_CFRAME,\t400(sp) // / 64 bit C frame chain.\n|//\t\t\t392(sp) // Reserved.\n|.define CFRAME_SPACE,\t384     // Delta for sp.\n|// Back chain for sp:\t384(sp) <-- sp entering interpreter\n|.define SAVE_LR,\t376(sp) // 32 bit LR stored in hi-part.\n|.define SAVE_GPR_,\t232     // .. 232+18*8: 64 bit GPR saves.\n|.define SAVE_FPR_,\t88      // .. 88+18*8: 64 bit FPR saves.\n|//\t\t\t80(sp) // Needed for 16 byte stack frame alignment.\n|//\t\t\t16(sp)  // Callee parameter save area (ABI mandated).\n|//\t\t\t8(sp)   // Reserved\n|// Back chain for sp:\t0(sp)   <-- sp while in interpreter\n|// 32 bit sp stored in hi-part of 0(sp).\n|\n|.define TMPD_BLO,\t447(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|\n|.else\n|\n|//\t\t\t508(sp) // \\ 32 bit C frame info.\n|.define SAVE_ERRF,\t472(sp) // |\n|.define SAVE_NRES,\t468(sp) // |\n|.define SAVE_L,\t464(sp) //  > Parameter save area.\n|.define SAVE_PC,\t460(sp) // |\n|.define SAVE_MULTRES,\t456(sp) // |\n|.define SAVE_CFRAME,\t448(sp) // / 64 bit C frame chain.\n|.define SAVE_LR,\t416(sp)\n|.define CFRAME_SPACE,\t400     // Delta for sp.\n|// Back chain for sp:\t400(sp) <-- sp entering interpreter\n|.define SAVE_FPR_,\t256     // .. 256+18*8: 64 bit FPR saves.\n|.define SAVE_GPR_,\t112     // .. 112+18*8: 64 bit GPR saves.\n|//\t\t\t48(sp)  // Callee parameter save area (ABI mandated).\n|.define SAVE_TOC,\t40(sp)  // TOC save area.\n|.define TMPD_LO,\t36(sp)  // \\ Link editor temp (ABI mandated).\n|.define TMPD_HI,\t32(sp)  // /\n|.define TONUM_LO,\t28(sp)  // \\ Compiler temp (ABI mandated).\n|.define TONUM_HI,\t24(sp)  // /\n|// Next frame lr:\t16(sp)\n|.define SAVE_CR,\t8(sp)  // 64 bit CR save.\n|// Back chain for sp:\t0(sp)\t<-- sp while in interpreter\n|\n|.define TMPD_BLO,\t39(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|\n|.endif\n|.else\n|\n|.if FPU\n|.define SAVE_LR,\t276(sp)\n|.define CFRAME_SPACE,\t272     // Delta for sp.\n|// Back chain for sp:\t272(sp) <-- sp entering interpreter\n|.define SAVE_FPR_,\t128     // .. 128+18*8: 64 bit FPR saves.\n|.else\n|.define SAVE_LR,\t132(sp)\n|.define CFRAME_SPACE,\t128     // Delta for sp.\n|// Back chain for sp:\t128(sp) <-- sp entering interpreter\n|.endif\n|.define SAVE_GPR_,\t56      // .. 56+18*4: 32 bit GPR saves.\n|.define SAVE_CR,\t52(sp)  // 32 bit CR save.\n|.define SAVE_ERRF,\t48(sp)  // 32 bit C frame info.\n|.define SAVE_NRES,\t44(sp)\n|.define SAVE_CFRAME,\t40(sp)\n|.define SAVE_L,\t36(sp)\n|.define SAVE_PC,\t32(sp)\n|.define SAVE_MULTRES,\t28(sp)\n|.define UNUSED1,\t24(sp)\n|.if FPU\n|.define TMPD_LO,\t20(sp)\n|.define TMPD_HI,\t16(sp)\n|.define TONUM_LO,\t12(sp)\n|.define TONUM_HI,\t8(sp)\n|.else\n|.define SFSAVE_4,\t20(sp)\n|.define SFSAVE_3,\t16(sp)\n|.define SFSAVE_2,\t12(sp)\n|.define SFSAVE_1,\t8(sp)\n|.endif\n|// Next frame lr:\t4(sp)\n|// Back chain for sp:\t0(sp)\t<-- sp while in interpreter\n|\n|.if FPU\n|.define TMPD_BLO,\t23(sp)\n|.define TMPD,\t\tTMPD_HI\n|.define TONUM_D,\tTONUM_HI\n|.endif\n|\n|.endif\n|\n|.macro save_, reg\n|.if GPR64\n|  std r..reg, SAVE_GPR_+(reg-14)*8(sp)\n|.else\n|  stw r..reg, SAVE_GPR_+(reg-14)*4(sp)\n|.endif\n|  .FPU stfd f..reg, SAVE_FPR_+(reg-14)*8(sp)\n|.endmacro\n|.macro rest_, reg\n|.if GPR64\n|  ld r..reg, SAVE_GPR_+(reg-14)*8(sp)\n|.else\n|  lwz r..reg, SAVE_GPR_+(reg-14)*4(sp)\n|.endif\n|  .FPU lfd f..reg, SAVE_FPR_+(reg-14)*8(sp)\n|.endmacro\n|\n|.macro saveregs\n|.if GPR64 and not FRAME32\n|  stdu sp, -CFRAME_SPACE(sp)\n|.else\n|  stwu sp, -CFRAME_SPACE(sp)\n|.endif\n|  save_ 14; save_ 15; save_ 16\n|  mflr r0\n|  save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22\n|.if GPR64 and not FRAME32\n|  std r0, SAVE_LR\n|.else\n|  stw r0, SAVE_LR\n|.endif\n|  save_ 23; save_ 24; save_ 25\n|  mfcr r0\n|  save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31\n|.if GPR64\n|  std r0, SAVE_CR\n|.else\n|  stw r0, SAVE_CR\n|.endif\n|  .toc std TOCREG, SAVE_TOC\n|.endmacro\n|\n|.macro restoreregs\n|.if GPR64 and not FRAME32\n|  ld r0, SAVE_LR\n|.else\n|  lwz r0, SAVE_LR\n|.endif\n|.if GPR64\n|  ld r12, SAVE_CR\n|.else\n|  lwz r12, SAVE_CR\n|.endif\n|  rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19\n|  mtlr r0;\n|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif\n|  rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25\n|.if PPE; mtocrf 0x10, r12; .endif\n|  rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31\n|.if PPE; mtocrf 0x08, r12; .endif\n|  addi sp, sp, CFRAME_SPACE\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State,\tLREG\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS8,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Trap for not-yet-implemented parts.\n|.macro NYI; tw 4, sp, sp; .endmacro\n|\n|.if FPU\n|// int/FP conversions.\n|.macro tonum_i, freg, reg\n|  xoris reg, reg, 0x8000\n|  stw reg, TONUM_LO\n|  lfd freg, TONUM_D\n|  fsub freg, freg, TONUM\n|.endmacro\n|\n|.macro tonum_u, freg, reg\n|  stw reg, TONUM_LO\n|  lfd freg, TONUM_D\n|  fsub freg, freg, TOBIT\n|.endmacro\n|\n|.macro toint, reg, freg, tmpfreg\n|  fctiwz tmpfreg, freg\n|  stfd tmpfreg, TMPD\n|  lwz reg, TMPD_LO\n|.endmacro\n|\n|.macro toint, reg, freg\n|  toint reg, freg, freg\n|.endmacro\n|.endif\n|\n|//-----------------------------------------------------------------------\n|\n|// Access to frame relative to BASE.\n|.define FRAME_PC,\t-8\n|.define FRAME_FUNC,\t-4\n|\n|// Instruction decode.\n|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro\n|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro\n|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro\n|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro\n|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro\n|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro\n|\n|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro\n|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro\n|\n|// Instruction fetch.\n|.macro ins_NEXT1\n|  lwz INS, 0(PC)\n|   addi PC, PC, 4\n|.endmacro\n|// Instruction decode+dispatch. Note: optimized for e300!\n|.macro ins_NEXT2\n|  decode_OPP TMP1, INS\n|  lpx TMP0, DISPATCH, TMP1\n|  mtctr TMP0\n|   decode_RB8 RB, INS\n|   decode_RD8 RD, INS\n|   decode_RA8 RA, INS\n|   decode_RC8 RC, INS\n|  bctr\n|.endmacro\n|.macro ins_NEXT\n|  ins_NEXT1\n|  ins_NEXT2\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|  .define ins_next1, ins_NEXT1\n|  .define ins_next2, ins_NEXT2\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  .macro ins_next\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next1\n|  .endmacro\n|  .macro ins_next2\n|    b ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n|  lwz PC, LFUNC:RB->pc\n|  lwz INS, 0(PC)\n|   addi PC, PC, 4\n|  decode_OPP TMP1, INS\n|   decode_RA8 RA, INS\n|  lpx TMP0, DISPATCH, TMP1\n|   add RA, RA, BASE\n|  mtctr TMP0\n|  bctr\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC\n|  stw PC, FRAME_PC(BASE)\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checknum, reg; cmplw reg, TISNUM; .endmacro\n|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro\n|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro\n|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro\n|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro\n|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro\n|\n|.macro branch_RD\n|  srwi TMP0, RD, 1\n|  addis PC, PC, -(BCBIAS_J*4 >> 16)\n|  add PC, PC, TMP0\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|.macro hotcheck, delta, target\n|  rlwinm TMP1, PC, 31, 25, 30\n|  addi TMP1, TMP1, GG_DISP2HOT\n|  lhzx TMP2, DISPATCH, TMP1\n|  addic. TMP2, TMP2, -delta\n|  sthx TMP2, DISPATCH, TMP1\n|  blt target\n|.endmacro\n|\n|.macro hotloop\n|  hotcheck HOTCOUNT_LOOP, ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall\n|  hotcheck HOTCOUNT_CALL, ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state. Uses TMP0.\n|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro\n|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro\n|\n|// Move table write barrier back. Overwrites mark and tmp.\n|.macro barrierback, tab, mark, tmp\n|  lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|  // Assumes LJ_GC_BLACK is 0x04.\n|   rlwinm mark, mark, 0, 30, 28\t\t// black2gray(tab)\n|  stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)\n|   stb mark, tab->marked\n|  stw tmp, tab->gclist\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  // See vm_return. Also: TMP2 = previous base.\n  |  andix. TMP0, PC, FRAME_P\n  |   li TMP1, LJ_TTRUE\n  |  beq ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  lwz PC, FRAME_PC(TMP2)\t\t// Fetch PC of previous frame.\n  |  mr BASE, TMP2\t\t\t// Restore caller base.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |   stwu TMP1, FRAME_PC(RA)\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  addi RD, RD, 8\t\t\t// RD = (nresults+1)*8.\n  |   andix. TMP0, PC, FRAME_TYPE\n  |  cmpwi cr1, RD, 0\n  |  li CRET1, LUA_YIELD\n  |  beq cr1, ->vm_unwind_c_eh\n  |  mr MULTRES, RD\n  |   beq ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return\n  |  // TMP0 = PC & FRAME_TYPE\n  |  cmpwi TMP0, FRAME_C\n  |   rlwinm TMP2, PC, 0, 0, 28\n  |    li_vmstate C\n  |   sub TMP2, BASE, TMP2\t\t// TMP2 = previous base.\n  |  bney ->vm_returnp\n  |\n  |  addic. TMP1, RD, -8\n  |   stp TMP2, L->base\n  |   lwz TMP2, SAVE_NRES\n  |    subi BASE, BASE, 8\n  |    st_vmstate\n  |   slwi TMP2, TMP2, 3\n  |  beq >2\n  |1:\n  |  addic. TMP1, TMP1, -8\n  |.if FPU\n  |   lfd f0, 0(RA)\n  |.else\n  |   lwz CARG1, 0(RA)\n  |   lwz CARG2, 4(RA)\n  |.endif\n  |    addi RA, RA, 8\n  |.if FPU\n  |   stfd f0, 0(BASE)\n  |.else\n  |   stw CARG1, 0(BASE)\n  |   stw CARG2, 4(BASE)\n  |.endif\n  |    addi BASE, BASE, 8\n  |  bney <1\n  |\n  |2:\n  |  cmpw TMP2, RD\t\t\t// More/less results wanted?\n  |  bne >6\n  |3:\n  |  stp BASE, L->top\t\t\t// Store new top.\n  |\n  |->vm_leave_cp:\n  |  lp TMP0, SAVE_CFRAME\t\t// Restore previous C frame.\n  |   li CRET1, 0\t\t\t// Ok return status for vm_pcall.\n  |  stp TMP0, L->cframe\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  blr\n  |\n  |6:\n  |  ble >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  lwz TMP1, L->maxstack\n  |  cmplw BASE, TMP1\n  |  bge >8\n  |  stw TISNIL, 0(BASE)\n  |  addi RD, RD, 8\n  |  addi BASE, BASE, 8\n  |  b <2\n  |\n  |7:  // Less results wanted.\n  |  subfic TMP3, TMP2, 0\t\t// LUA_MULTRET+1 case?\n  |   sub TMP0, RD, TMP2\n  |  subfe TMP1, TMP1, TMP1\t\t// TMP1 = TMP2 == 0 ? 0 : -1\n  |   and TMP0, TMP0, TMP1\n  |  sub BASE, BASE, TMP0\t\t// Either keep top or shrink it.\n  |  b <3\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  stp BASE, L->top\t\t\t// Save current top held in BASE (yes).\n  |   mr SAVE0, RD\n  |  srwi CARG2, TMP2, 3\n  |  mr CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |    lwz TMP2, SAVE_NRES\n  |   mr RD, SAVE0\n  |    slwi TMP2, TMP2, 3\n  |  lp BASE, L->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  b <2\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mr sp, CARG1\n  |  mr CRET1, CARG2\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  lwz L, SAVE_L\n  |  .toc ld TOCREG, SAVE_TOC\n  |   li TMP0, ~LJ_VMST_C\n  |  lwz GL:TMP1, L->glref\n  |   stw TMP0, GL:TMP1->vmstate\n  |  b ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |.if GPR64\n  |  rldicr sp, CARG1, 0, 61\n  |.else\n  |  rlwinm sp, CARG1, 0, 0, 29\n  |.endif\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  lwz L, SAVE_L\n  |  .toc ld TOCREG, SAVE_TOC\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  lp BASE, L->base\n  |     .FPU lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |   lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |     li ZERO, 0\n  |     .FPU stw TMP3, TMPD\n  |  li TMP1, LJ_TFALSE\n  |     .FPU ori TMP3, TMP3, 0x0004\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     li TISNIL, LJ_TNIL\n  |    li_vmstate INTERP\n  |     .FPU lfs TOBIT, TMPD\n  |  lwz PC, FRAME_PC(BASE)\t\t// Fetch PC of previous frame.\n  |  la RA, -8(BASE)\t\t\t// Results start at BASE-8.\n  |     .FPU stw TMP3, TMPD\n  |   addi DISPATCH, DISPATCH, GG_G2DISP\n  |  stw TMP1, 0(RA)\t\t\t// Prepend false to error message.\n  |  li RD, 16\t\t\t\t// 2 results: false + error message.\n  |    st_vmstate\n  |     .FPU lfs TONUM, TMPD\n  |  b ->vm_returnc\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  li CARG2, LUA_MINSTACK\n  |  b >2\n  |\n  |->vm_growstack_l:\t\t\t// Grow stack for Lua function.\n  |  // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC\n  |  add RC, BASE, RC\n  |   sub RA, RA, BASE\n  |  stp BASE, L->base\n  |   addi PC, PC, 4\t\t\t// Must point after first instruction.\n  |  stp RC, L->top\n  |   srwi CARG2, RA, 3\n  |2:\n  |  // L->base = new base, L->top = top\n  |   stw PC, SAVE_PC\n  |  mr CARG1, L\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lp BASE, L->base\n  |  lp RC, L->top\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  sub RC, RC, BASE\n  |  // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mr L, CARG1\n  |    lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  mr BASE, CARG2\n  |    lbz TMP1, L->status\n  |   stw L, SAVE_L\n  |  li PC, FRAME_CP\n  |  addi TMP0, sp, CFRAME_RESUME\n  |    addi DISPATCH, DISPATCH, GG_G2DISP\n  |   stw CARG3, SAVE_NRES\n  |    cmplwi TMP1, 0\n  |   stw CARG3, SAVE_ERRF\n  |   stp CARG3, SAVE_CFRAME\n  |   stw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  stp TMP0, L->cframe\n  |    beq >3\n  |\n  |  // Resume after yield (like a return).\n  |  stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  mr RA, BASE\n  |   lp BASE, L->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lp TMP1, L->top\n  |  lwz PC, FRAME_PC(BASE)\n  |     .FPU lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |    stb CARG3, L->status\n  |     .FPU stw TMP3, TMPD\n  |     .FPU ori TMP3, TMP3, 0x0004\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     .FPU lfs TOBIT, TMPD\n  |   sub RD, TMP1, BASE\n  |     .FPU stw TMP3, TMPD\n  |     .FPU lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |   addi RD, RD, 8\n  |     .FPU stw TMP0, TONUM_HI\n  |    li_vmstate INTERP\n  |     li ZERO, 0\n  |    st_vmstate\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   mr MULTRES, RD\n  |     .FPU lfs TONUM, TMPD\n  |     li TISNIL, LJ_TNIL\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  li PC, FRAME_CP\n  |  stw CARG4, SAVE_ERRF\n  |  b >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  li PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  lp TMP1, L:CARG1->cframe\n  |    mr L, CARG1\n  |   stw CARG3, SAVE_NRES\n  |    lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |   stw CARG1, SAVE_L\n  |     mr BASE, CARG2\n  |    addi DISPATCH, DISPATCH, GG_G2DISP\n  |   stw CARG1, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |  stp TMP1, SAVE_CFRAME\n  |  stp sp, L->cframe\t\t\t// Add our C frame to cframe chain.\n  |\n  |3:  // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).\n  |  stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  lp TMP2, L->base\t\t\t// TMP2 = old base (used in vmeta_call).\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |   lp TMP1, L->top\n  |     .FPU lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  add PC, PC, BASE\n  |     .FPU stw TMP3, TMPD\n  |     li ZERO, 0\n  |     .FPU ori TMP3, TMP3, 0x0004\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     .FPU lfs TOBIT, TMPD\n  |  sub PC, PC, TMP2\t\t\t// PC = frame delta + frame type\n  |     .FPU stw TMP3, TMPD\n  |     .FPU lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |   sub NARGS8:RC, TMP1, BASE\n  |     .FPU stw TMP0, TONUM_HI\n  |    li_vmstate INTERP\n  |     .FPU lfs TONUM, TMPD\n  |     li TISNIL, LJ_TNIL\n  |    st_vmstate\n  |\n  |->vm_call_dispatch:\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC\n  |  lwz TMP0, FRAME_PC(BASE)\n  |   lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  checkfunc TMP0; bne ->vmeta_call\n  |\n  |->vm_call_dispatch_f:\n  |  ins_call\n  |  // BASE = new base, RB = func, RC = nargs*8, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mr L, CARG1\n  |   lwz TMP0, L:CARG1->stack\n  |  stw CARG1, SAVE_L\n  |   lp TMP1, L->top\n  |     lwz DISPATCH, L->glref\t\t// Setup pointer to dispatch table.\n  |  stw CARG1, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |   sub TMP0, TMP0, TMP1\t\t// Compute -savestack(L, L->top).\n  |    lp TMP1, L->cframe\n  |     addi DISPATCH, DISPATCH, GG_G2DISP\n  |  .toc lp CARG4, 0(CARG4)\n  |  li TMP2, 0\n  |   stw TMP0, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |  stw TMP2, SAVE_ERRF\t\t// No error function.\n  |    stp TMP1, SAVE_CFRAME\n  |    stp sp, L->cframe\t\t// Add our C frame to cframe chain.\n  |     stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  mtctr CARG4\n  |  bctrl\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.if PPE\n  |  mr BASE, CRET1\n  |  cmpwi CRET1, 0\n  |.else\n  |  mr. BASE, CRET1\n  |.endif\n  |   li PC, FRAME_CP\n  |  bne <3\t\t\t\t// Else continue with the call.\n  |  b ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the\n  |// stack, so BASE doesn't need to be reloaded across these calls.\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultptr, RD = (nresults+1)*8\n  |  lwz TMP0, -12(BASE)\t\t// Continuation.\n  |   mr RB, BASE\n  |   mr BASE, TMP2\t\t\t// Restore caller BASE.\n  |    lwz LFUNC:TMP1, FRAME_FUNC(TMP2)\n  |.if FFI\n  |  cmplwi TMP0, 1\n  |.endif\n  |     lwz PC, -16(RB)\t\t\t// Restore PC from [cont|PC].\n  |   subi TMP2, RD, 8\n  |   stwx TISNIL, RA, TMP2\t\t// Ensure one valid arg.\n  |.if FFI\n  |  ble >1\n  |.endif\n  |    lwz TMP1, LFUNC:TMP1->pc\n  |    lwz KBASE, PC2PROTO(k)(TMP1)\n  |  // BASE = base, RA = resultptr, RB = meta base\n  |  mtctr TMP0\n  |  bctr\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  beq ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: tailcall from C function.\n  |  subi TMP1, RB, 16\n  |  sub RC, TMP1, BASE\n  |  b ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// RA = resultptr, RB = meta base\n  |  lwz INS, -4(PC)\n  |   subi CARG2, RB, 16\n  |  decode_RB8 SAVE0, INS\n  |.if FPU\n  |   lfd f0, 0(RA)\n  |.else\n  |   lwz TMP2, 0(RA)\n  |   lwz TMP3, 4(RA)\n  |.endif\n  |  add TMP1, BASE, SAVE0\n  |   stp BASE, L->base\n  |  cmplw TMP1, CARG2\n  |   sub CARG3, CARG2, TMP1\n  |  decode_RA8 RA, INS\n  |.if FPU\n  |   stfd f0, 0(CARG2)\n  |.else\n  |   stw TMP2, 0(CARG2)\n  |   stw TMP3, 4(CARG2)\n  |.endif\n  |  bney ->BC_CAT_Z\n  |.if FPU\n  |   stfdx f0, BASE, RA\n  |.else\n  |   stwux TMP2, RA, BASE\n  |   stw TMP3, 4(RA)\n  |.endif\n  |  b ->cont_nop\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets1:\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TSTR\n  |   decode_RB8 RB, INS\n  |  stw STR:RC, 4(CARG3)\n  |   add CARG2, BASE, RB\n  |  stw TMP0, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tgets:\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TTAB\n  |  stw TAB:RB, 4(CARG2)\n  |   la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)\n  |  stw TMP0, 0(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   stw STR:RC, 4(CARG3)\n  |   stw TMP1, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tgetb:\t\t\t// TMP0 = index\n  |.if not DUALNUM\n  |  tonum_u f0, TMP0\n  |.endif\n  |   decode_RB8 RB, INS\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |   add CARG2, BASE, RB\n  |.if DUALNUM\n  |  stw TISNUM, 0(CARG3)\n  |  stw TMP0, 4(CARG3)\n  |.else\n  |  stfd f0, 0(CARG3)\n  |.endif\n  |  b >1\n  |\n  |->vmeta_tgetv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |  stp BASE, L->base\n  |  mr CARG1, L\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cmplwi CRET1, 0\n  |  beq >3\n  |.if FPU\n  |   lfd f0, 0(CRET1)\n  |.else\n  |   lwz TMP0, 0(CRET1)\n  |   lwz TMP1, 4(CRET1)\n  |.endif\n  |  ins_next1\n  |.if FPU\n  |   stfdx f0, BASE, RA\n  |.else\n  |   stwux TMP0, RA, BASE\n  |   stw TMP1, 4(RA)\n  |.endif\n  |  ins_next2\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  subfic TMP1, BASE, FRAME_CONT\n  |  lp BASE, L->top\n  |  stw PC, -16(BASE)\t\t\t// [cont|PC]\n  |   add PC, TMP1, BASE\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   li NARGS8:RC, 16\t\t\t// 2 args for func(t, k).\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cmplwi CRET1, 0\n  |  beq >1\n  |.if FPU\n  |  lfd f14, 0(CRET1)\n  |.else\n  |  lwz SAVE0, 0(CRET1)\n  |  lwz SAVE1, 4(CRET1)\n  |.endif\n  |  b ->BC_TGETR_Z\n  |1:\n  |  stwx TISNIL, BASE, RA\n  |  b ->cont_nop\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets1:\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TSTR\n  |   decode_RB8 RB, INS\n  |  stw STR:RC, 4(CARG3)\n  |   add CARG2, BASE, RB\n  |  stw TMP0, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tsets:\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |  li TMP0, LJ_TTAB\n  |  stw TAB:RB, 4(CARG2)\n  |   la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)\n  |  stw TMP0, 0(CARG2)\n  |   li TMP1, LJ_TSTR\n  |   stw STR:RC, 4(CARG3)\n  |   stw TMP1, 0(CARG3)\n  |  b >1\n  |\n  |->vmeta_tsetb:\t\t\t// TMP0 = index\n  |.if not DUALNUM\n  |  tonum_u f0, TMP0\n  |.endif\n  |   decode_RB8 RB, INS\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |   add CARG2, BASE, RB\n  |.if DUALNUM\n  |  stw TISNUM, 0(CARG3)\n  |  stw TMP0, 4(CARG3)\n  |.else\n  |  stfd f0, 0(CARG3)\n  |.endif\n  |  b >1\n  |\n  |->vmeta_tsetv:\n  |  decode_RB8 RB, INS\n  |   decode_RC8 RC, INS\n  |  add CARG2, BASE, RB\n  |   add CARG3, BASE, RC\n  |1:\n  |  stp BASE, L->base\n  |  mr CARG1, L\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // Returns TValue * (finished) or NULL (metamethod).\n  |  cmplwi CRET1, 0\n  |.if FPU\n  |   lfdx f0, BASE, RA\n  |.else\n  |   lwzux TMP2, RA, BASE\n  |   lwz TMP3, 4(RA)\n  |.endif\n  |  beq >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  ins_next1\n  |.if FPU\n  |   stfd f0, 0(CRET1)\n  |.else\n  |   stw TMP2, 0(CRET1)\n  |   stw TMP3, 4(CRET1)\n  |.endif\n  |  ins_next2\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  subfic TMP1, BASE, FRAME_CONT\n  |  lp BASE, L->top\n  |  stw PC, -16(BASE)\t\t\t// [cont|PC]\n  |   add PC, TMP1, BASE\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   li NARGS8:RC, 24\t\t\t// 3 args for func(t, k, v)\n  |.if FPU\n  |  stfd f0, 16(BASE)\t\t\t// Copy value to third argument.\n  |.else\n  |  stw TMP2, 16(BASE)\n  |  stw TMP3, 20(BASE)\n  |.endif\n  |  b ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  stp BASE, L->base\n  |  mr CARG1, L\n  |  stw PC, SAVE_PC\n  |  bl extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // Returns TValue *.\n  |.if FPU\n  |  stfd f14, 0(CRET1)\n  |.else\n  |  stw SAVE0, 0(CRET1)\n  |  stw SAVE1, 4(CRET1)\n  |.endif\n  |  b ->cont_nop\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  mr CARG1, L\n  |   subi PC, PC, 4\n  |.if DUALNUM\n  |  mr CARG2, RA\n  |.else\n  |  add CARG2, BASE, RA\n  |.endif\n  |   stw PC, SAVE_PC\n  |.if DUALNUM\n  |  mr CARG3, RD\n  |.else\n  |  add CARG3, BASE, RD\n  |.endif\n  |   stp BASE, L->base\n  |  decode_OP1 CARG4, INS\n  |  bl extern lj_meta_comp  // (lua_State *L, TValue *o1, *o2, int op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |3:\n  |  cmplwi CRET1, 1\n  |  bgt ->vmeta_binop\n  |  subfic CRET1, CRET1, 0\n  |4:\n  |  lwz INS, 0(PC)\n  |   addi PC, PC, 4\n  |  decode_RD4 TMP2, INS\n  |  addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n  |  and TMP2, TMP2, CRET1\n  |  add PC, PC, TMP2\n  |->cont_nop:\n  |  ins_next\n  |\n  |->cont_ra:\t\t\t\t// RA = resultptr\n  |  lwz INS, -4(PC)\n  |.if FPU\n  |   lfd f0, 0(RA)\n  |.else\n  |   lwz CARG1, 0(RA)\n  |   lwz CARG2, 4(RA)\n  |.endif\n  |  decode_RA8 TMP1, INS\n  |.if FPU\n  |   stfdx f0, BASE, TMP1\n  |.else\n  |   stwux CARG1, TMP1, BASE\n  |   stw CARG2, 4(TMP1)\n  |.endif\n  |  b ->cont_nop\n  |\n  |->cont_condt:\t\t\t// RA = resultptr\n  |  lwz TMP0, 0(RA)\n  |  .gpr64 extsw TMP0, TMP0\n  |  subfic TMP0, TMP0, LJ_TTRUE\t// Branch if result is true.\n  |  subfe CRET1, CRET1, CRET1\n  |  not CRET1, CRET1\n  |  b <4\n  |\n  |->cont_condf:\t\t\t// RA = resultptr\n  |  lwz TMP0, 0(RA)\n  |  .gpr64 extsw TMP0, TMP0\n  |  subfic TMP0, TMP0, LJ_TTRUE\t// Branch if result is false.\n  |  subfe CRET1, CRET1, CRET1\n  |  b <4\n  |\n  |->vmeta_equal:\n  |  // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_equal  // (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  mr CARG2, INS\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_equal_cd\t\t// (lua_State *L, BCIns op)\n  |  // Returns 0/1 or TValue * (metamethod).\n  |  b <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  subi PC, PC, 4\n  |   stp BASE, L->base\n  |   srwi CARG2, RA, 3\n  |   mr CARG1, L\n  |   srwi CARG3, RD, 3\n  |  stw PC, SAVE_PC\n  |  bl extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  b ->cont_nop\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_nv:\n  |  add CARG3, KBASE, RC\n  |  add CARG4, BASE, RB\n  |  b >1\n  |->vmeta_arith_nv2:\n  |.if DUALNUM\n  |  mr CARG3, RC\n  |  mr CARG4, RB\n  |  b >1\n  |.endif\n  |\n  |->vmeta_unm:\n  |  mr CARG3, RD\n  |  mr CARG4, RD\n  |  b >1\n  |\n  |->vmeta_arith_vn:\n  |  add CARG3, BASE, RB\n  |  add CARG4, KBASE, RC\n  |  b >1\n  |\n  |->vmeta_arith_vv:\n  |  add CARG3, BASE, RB\n  |  add CARG4, BASE, RC\n  |.if DUALNUM\n  |  b >1\n  |.endif\n  |->vmeta_arith_vn2:\n  |->vmeta_arith_vv2:\n  |.if DUALNUM\n  |  mr CARG3, RB\n  |  mr CARG4, RC\n  |.endif\n  |1:\n  |  add CARG2, BASE, RA\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  decode_OP1 CARG5, INS\t\t// Caveat: CARG5 overlaps INS.\n  |  bl extern lj_meta_arith  // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // Returns NULL (finished) or TValue * (metamethod).\n  |  cmplwi CRET1, 0\n  |  beq ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2\n  |  sub TMP1, CRET1, BASE\n  |   stw PC, -16(CRET1)\t\t// [cont|PC]\n  |   mr TMP2, BASE\n  |  addi PC, TMP1, FRAME_CONT\n  |   mr BASE, CRET1\n  |  li NARGS8:RC, 16\t\t\t// 2 args for func(o1, o2).\n  |  b ->vm_call_dispatch\n  |\n  |->vmeta_len:\n#if LJ_52\n  |  mr SAVE0, CARG1\n#endif\n  |  mr CARG2, RD\n  |   stp BASE, L->base\n  |  mr CARG1, L\n  |   stw PC, SAVE_PC\n  |  bl extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // Returns NULL (retry) or TValue * (metamethod base).\n#if LJ_52\n  |  cmplwi CRET1, 0\n  |  bne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  mr CARG1, SAVE0\n  |  b ->BC_LEN_Z\n#else\n  |  b ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // TMP2 = old base, BASE = new base, RC = nargs*8\n  |  mr CARG1, L\n  |   stp TMP2, L->base\t\t\t// This is the callers base!\n  |  subi CARG2, BASE, 8\n  |   stw PC, SAVE_PC\n  |  add CARG3, BASE, RC\n  |   mr SAVE0, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\t// Guaranteed to be a function here.\n  |   addi NARGS8:RC, SAVE0, 8\t\t// Got one more argument now.\n  |  ins_call\n  |\n  |->vmeta_callt:\t\t\t// Resolve __call for BC_CALLT.\n  |  // BASE = old base, RA = new base, RC = nargs*8\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  subi CARG2, RA, 8\n  |   stw PC, SAVE_PC\n  |  add CARG3, RA, RC\n  |   mr SAVE0, NARGS8:RC\n  |  bl extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  lwz TMP1, FRAME_PC(BASE)\n  |   addi NARGS8:RC, SAVE0, 8\t\t// Got one more argument now.\n  |   lwz LFUNC:RB, FRAME_FUNC(RA)\t// Guaranteed to be a function here.\n  |  b ->BC_CALLT_Z\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  mr CARG2, RA\n  |   stw PC, SAVE_PC\n  |  mr SAVE0, INS\n  |  bl extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |.if JIT\n  |   decode_OP1 TMP0, SAVE0\n  |.endif\n  |  decode_RA8 RA, SAVE0\n  |.if JIT\n  |   cmpwi TMP0, BC_JFORI\n  |.endif\n  |  decode_RD8 RD, SAVE0\n  |.if JIT\n  |   beqy =>BC_JFORI\n  |.endif\n  |  b =>BC_FORI\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz CARG1, 4(BASE)\n  |  blt ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lwz CARG4, 8(BASE)\n  |   lwz CARG1, 4(BASE)\n  |    lwz CARG2, 12(BASE)\n  |  blt ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |.if FPU\n  |    lfd FARG1, 0(BASE)\n  |.else\n  |    lwz CARG2, 4(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checknum CARG1; bge ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |->ff_ .. name:\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG1, 0(BASE)\n  |.if FPU\n  |    lfd FARG1, 0(BASE)\n  |   lwz CARG3, 8(BASE)\n  |    lfd FARG2, 8(BASE)\n  |.else\n  |    lwz CARG2, 4(BASE)\n  |   lwz CARG3, 8(BASE)\n  |    lwz CARG4, 12(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checknum CARG1; bge ->fff_fallback\n  |  checknum CARG3; bge ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1.\n  |.macro ffgccheck\n  |  lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n  |  lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n  |  cmplw TMP0, TMP1\n  |  bgel ->fff_gcstep\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  li TMP1, LJ_TFALSE\n  |   la RA, -8(BASE)\n  |  cmplw cr1, CARG3, TMP1\n  |    lwz PC, FRAME_PC(BASE)\n  |  bge cr1, ->fff_fallback\n  |   stw CARG3, 0(RA)\n  |  addi RD, NARGS8:RC, 8\t\t// Compute (nresults+1)*8.\n  |  addi TMP1, BASE, 8\n  |  add TMP2, RA, NARGS8:RC\n  |   stw CARG1, 4(RA)\n  |  beq ->fff_res\t\t\t// Done if exactly 1 argument.\n  |1:\n  |  cmplw TMP1, TMP2\n  |.if FPU\n  |   lfd f0, 0(TMP1)\n  |   stfd f0, 0(TMP1)\n  |.else\n  |   lwz CARG1, 0(TMP1)\n  |   lwz CARG2, 4(TMP1)\n  |   stw CARG1, -8(TMP1)\n  |   stw CARG2, -4(TMP1)\n  |.endif\n  |    addi TMP1, TMP1, 8\n  |  bney <1\n  |  b ->fff_res\n  |\n  |.ffunc type\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |  blt ->fff_fallback\n  |  .gpr64 extsw CARG1, CARG1\n  |  subfc TMP0, TISNUM, CARG1\n  |  subfe TMP2, CARG1, CARG1\n  |  orc TMP1, TMP2, TMP0\n  |  addi TMP1, TMP1, ~LJ_TISNUM+1\n  |  slwi TMP1, TMP1, 3\n  |.if FPU\n  |   la TMP2, CFUNC:RB->upvalue\n  |  lfdx FARG1, TMP2, TMP1\n  |.else\n  |  add TMP1, CFUNC:RB, TMP1\n  |  lwz CARG1, CFUNC:TMP1->upvalue[0].u32.hi\n  |  lwz CARG2, CFUNC:TMP1->upvalue[0].u32.lo\n  |.endif\n  |  b ->fff_resn\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  checktab CARG3; bne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  lwz TAB:CARG1, TAB:CARG1->metatable\n  |2:\n  |  li CARG3, LJ_TNIL\n  |   cmplwi TAB:CARG1, 0\n  |  lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)\n  |   beq ->fff_restv\n  |  lwz TMP0, TAB:CARG1->hmask\n  |   li CARG3, LJ_TTAB\t\t\t// Use metatable as default result.\n  |  lwz TMP1, STR:RC->sid\n  |  lwz NODE:TMP2, TAB:CARG1->node\n  |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n  |  slwi TMP0, TMP1, 5\n  |  slwi TMP1, TMP1, 3\n  |  sub TMP1, TMP0, TMP1\n  |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  lwz CARG4, NODE:TMP2->key\n  |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n  |    lwz CARG2, NODE:TMP2->val\n  |     lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)\n  |  checkstr CARG4; bne >4\n  |   cmpw TMP0, STR:RC; beq >5\n  |4:\n  |  lwz NODE:TMP2, NODE:TMP2->next\n  |  cmplwi NODE:TMP2, 0\n  |  beq ->fff_restv\t\t\t// Not found, keep default result.\n  |  b <3\n  |5:\n  |  checknil CARG2\n  |  beq ->fff_restv\t\t\t// Ditto for nil value.\n  |  mr CARG3, CARG2\t\t\t// Return value of mt.__metatable.\n  |  mr CARG1, TMP1\n  |  b ->fff_restv\n  |\n  |6:\n  |  cmpwi CARG3, LJ_TUDATA; beq <1\n  |  .gpr64 extsw CARG3, CARG3\n  |  subfc TMP0, TISNUM, CARG3\n  |  subfe TMP2, CARG3, CARG3\n  |  orc TMP1, TMP2, TMP0\n  |  addi TMP1, TMP1, ~LJ_TISNUM+1\n  |  slwi TMP1, TMP1, 2\n  |   la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH)\n  |  lwzx TAB:CARG1, TMP2, TMP1\n  |  b <2\n  |\n  |.ffunc_2 setmetatable\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |   checktab CARG3; bne ->fff_fallback\n  |  lwz TAB:TMP1, TAB:CARG1->metatable\n  |   checktab CARG4; bne ->fff_fallback\n  |  cmplwi TAB:TMP1, 0\n  |   lbz TMP3, TAB:CARG1->marked\n  |  bne ->fff_fallback\n  |   andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n  |    stw TAB:CARG2, TAB:CARG1->metatable\n  |   beq ->fff_restv\n  |  barrierback TAB:CARG1, TMP3, TMP0\n  |  b ->fff_restv\n  |\n  |.ffunc rawget\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG4, 0(BASE)\n  |    lwz TAB:CARG2, 4(BASE)\n  |  blt ->fff_fallback\n  |  checktab CARG4; bne ->fff_fallback\n  |   la CARG3, 8(BASE)\n  |   mr CARG1, L\n  |  bl extern lj_tab_get  // (lua_State *L, GCtab *t, cTValue *key)\n  |  // Returns cTValue *.\n  |.if FPU\n  |  lfd FARG1, 0(CRET1)\n  |.else\n  |  lwz CARG2, 4(CRET1)\n  |  lwz CARG1, 0(CRET1)\t// Caveat: CARG1 == CRET1.\n  |.endif\n  |  b ->fff_resn\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |.if FPU\n  |    lfd FARG1, 0(BASE)\n  |.else\n  |    lwz CARG2, 4(BASE)\n  |.endif\n  |  bne ->fff_fallback\t\t\t// Exactly one argument.\n  |   checknum CARG1; bgt ->fff_fallback\n  |  b ->fff_resn\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  checkstr CARG3\n  |  // A __tostring method in the string base metatable is ignored.\n  |  beq ->fff_restv\t\t\t// String key?\n  |  // Handle numbers inline, unless a number base metatable is present.\n  |  lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)\n  |  checknum CARG3\n  |  cmplwi cr1, TMP0, 0\n  |   stp BASE, L->base\t\t\t// Add frame since C call can throw.\n  |  crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  beq ->fff_fallback\n  |  ffgccheck\n  |  mr CARG1, L\n  |  mr CARG2, BASE\n  |.if DUALNUM\n  |  bl extern lj_strfmt_number\t\t// (lua_State *L, cTValue *o)\n  |.else\n  |  bl extern lj_strfmt_num\t\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // Returns GCstr *.\n  |  li CARG3, LJ_TSTR\n  |  b ->fff_restv\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |   stwx TISNIL, BASE, NARGS8:RC\t// Set missing 2nd arg to nil.\n  |  checktab CARG3\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n  |  la CARG2, 8(BASE)\n  |  la CARG3, -8(BASE)\n  |  bl extern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |  // Returns 1=found, 0=end, -1=error.\n  |  cmpwi CRET1, 0\n  |   la RA, -8(BASE)\n  |   li RD, (2+1)*8\n  |  bgt ->fff_res\t\t\t// Found key/value.\n  |   li CARG3, LJ_TNIL\n  |  beq ->fff_restv\t\t\t// End of traversal: return nil.\n  |   lwz CFUNC:RB, FRAME_FUNC(BASE)\n  |   li NARGS8:RC, 2*8\n  |  b ->fff_fallback\t\t\t// Invalid key.\n  |\n  |.ffunc_1 pairs\n  |  checktab CARG3\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n#if LJ_52\n  |   lwz TAB:TMP2, TAB:CARG1->metatable\n  |.if FPU\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |.else\n  |  lwz TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |  lwz TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |.endif\n  |   cmplwi TAB:TMP2, 0\n  |  la RA, -8(BASE)\n  |   bne ->fff_fallback\n#else\n  |.if FPU\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |.else\n  |  lwz TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |  lwz TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |.endif\n  |  la RA, -8(BASE)\n#endif\n  |   stw TISNIL, 8(BASE)\n  |  li RD, (3+1)*8\n  |.if FPU\n  |  stfd f0, 0(RA)\n  |.else\n  |  stw TMP0, 0(RA)\n  |  stw TMP1, 4(RA)\n  |.endif\n  |  b ->fff_res\n  |\n  |.ffunc ipairs_aux\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 0(BASE)\n  |    lwz TAB:CARG1, 4(BASE)\n  |   lwz CARG4, 8(BASE)\n  |.if DUALNUM\n  |    lwz TMP2, 12(BASE)\n  |.else\n  |    lfd FARG2, 8(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checktab CARG3\n  |  checknum cr1, CARG4\n  |   lwz PC, FRAME_PC(BASE)\n  |.if DUALNUM\n  |  bne ->fff_fallback\n  |  bne cr1, ->fff_fallback\n  |.else\n  |    lus TMP0, 0x3ff0\n  |    stw ZERO, TMPD_LO\n  |  bne ->fff_fallback\n  |    stw TMP0, TMPD_HI\n  |  bge cr1, ->fff_fallback\n  |    lfd FARG1, TMPD\n  |  toint TMP2, FARG2, f0\n  |.endif\n  |   lwz TMP0, TAB:CARG1->asize\n  |   lwz TMP1, TAB:CARG1->array\n  |.if not DUALNUM\n  |  fadd FARG2, FARG2, FARG1\n  |.endif\n  |  addi TMP2, TMP2, 1\n  |   la RA, -8(BASE)\n  |  cmplw TMP0, TMP2\n  |.if DUALNUM\n  |  stw TISNUM, 0(RA)\n  |   slwi TMP3, TMP2, 3\n  |  stw TMP2, 4(RA)\n  |.else\n  |   slwi TMP3, TMP2, 3\n  |  stfd FARG2, 0(RA)\n  |.endif\n  |  ble >2\t\t\t\t// Not in array part?\n  |.if FPU\n  |  lwzx TMP2, TMP1, TMP3\n  |  lfdx f0, TMP1, TMP3\n  |.else\n  |  lwzux TMP2, TMP1, TMP3\n  |  lwz TMP3, 4(TMP1)\n  |.endif\n  |1:\n  |  checknil TMP2\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\t\t\t// End of iteration, return 0 results.\n  |   li RD, (2+1)*8\n  |.if FPU\n  |  stfd f0, 8(RA)\n  |.else\n  |  stw TMP2, 8(RA)\n  |  stw TMP3, 12(RA)\n  |.endif\n  |  b ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lwz TMP0, TAB:CARG1->hmask\n  |  cmplwi TMP0, 0\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\n  |   mr CARG2, TMP2\n  |  bl extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // Returns cTValue * or NULL.\n  |  cmplwi CRET1, 0\n  |   li RD, (0+1)*8\n  |  beq ->fff_res\n  |  lwz TMP2, 0(CRET1)\n  |.if FPU\n  |  lfd f0, 0(CRET1)\n  |.else\n  |  lwz TMP3, 4(CRET1)\n  |.endif\n  |  b <1\n  |\n  |.ffunc_1 ipairs\n  |  checktab CARG3\n  |   lwz PC, FRAME_PC(BASE)\n  |  bne ->fff_fallback\n#if LJ_52\n  |   lwz TAB:TMP2, TAB:CARG1->metatable\n  |.if FPU\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |.else\n  |  lwz TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |  lwz TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |.endif\n  |   cmplwi TAB:TMP2, 0\n  |  la RA, -8(BASE)\n  |   bne ->fff_fallback\n#else\n  |.if FPU\n  |  lfd f0, CFUNC:RB->upvalue[0]\n  |.else\n  |  lwz TMP0, CFUNC:RB->upvalue[0].u32.hi\n  |  lwz TMP1, CFUNC:RB->upvalue[0].u32.lo\n  |.endif\n  |  la RA, -8(BASE)\n#endif\n  |.if DUALNUM\n  |  stw TISNUM, 8(BASE)\n  |.else\n  |  stw ZERO, 8(BASE)\n  |.endif\n  |   stw ZERO, 12(BASE)\n  |  li RD, (3+1)*8\n  |.if FPU\n  |  stfd f0, 0(RA)\n  |.else\n  |  stw TMP0, 0(RA)\n  |  stw TMP1, 4(RA)\n  |.endif\n  |  b ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc pcall\n  |  cmplwi NARGS8:RC, 8\n  |   lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  blt ->fff_fallback\n  |   mr TMP2, BASE\n  |   la BASE, 8(BASE)\n  |  // Remember active hook before pcall.\n  |  rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31\n  |   subi NARGS8:RC, NARGS8:RC, 8\n  |  addi PC, TMP3, 8+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |\n  |.ffunc xpcall\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 8(BASE)\n  |.if FPU\n  |    lfd FARG2, 8(BASE)\n  |    lfd FARG1, 0(BASE)\n  |.else\n  |    lwz CARG1, 0(BASE)\n  |    lwz CARG2, 4(BASE)\n  |    lwz CARG4, 12(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH)\n  |   mr TMP2, BASE\n  |  checkfunc CARG3; bne ->fff_fallback  // Traceback must be a function.\n  |   la BASE, 16(BASE)\n  |  // Remember active hook before pcall.\n  |  rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31\n  |.if FPU\n  |    stfd FARG2, 0(TMP2)\t\t// Swap function and traceback.\n  |    stfd FARG1, 8(TMP2)\n  |.else\n  |    stw CARG3, 0(TMP2)\n  |    stw CARG4, 4(TMP2)\n  |    stw CARG1, 8(TMP2)\n  |    stw CARG2, 12(TMP2)\n  |.endif\n  |  subi NARGS8:RC, NARGS8:RC, 16\n  |  addi PC, TMP1, 16+FRAME_PCALL\n  |  b ->vm_call_dispatch\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  lwz L:CARG1, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  lbz TMP0, L:CARG1->status\n  |   lp TMP1, L:CARG1->cframe\n  |    lp CARG2, L:CARG1->top\n  |  cmplwi cr0, TMP0, LUA_YIELD\n  |    lp TMP2, L:CARG1->base\n  |   cmplwi cr1, TMP1, 0\n  |   lwz TMP0, L:CARG1->maxstack\n  |    cmplw cr7, CARG2, TMP2\n  |   lwz PC, FRAME_PC(BASE)\n  |  crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq\t\t// st>LUA_YIELD || cframe!=0\n  |   add TMP2, CARG2, NARGS8:RC\n  |  crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq\t// base==top && st!=LUA_YIELD\n  |   cmplw cr1, TMP2, TMP0\n  |  cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt\n  |   stw PC, SAVE_PC\n  |  cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt\t\t// cond1 || cond2 || stackov\n  |   stp BASE, L->base\n  |  blt cr6, ->fff_fallback\n  |1:\n  |.if resume\n  |  addi BASE, BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |  subi NARGS8:RC, NARGS8:RC, 8\n  |  subi TMP2, TMP2, 8\n  |.endif\n  |  stp TMP2, L:CARG1->top\n  |  li TMP1, 0\n  |  stp BASE, L->top\n  |2:  // Move args to coroutine.\n  |  cmpw TMP1, NARGS8:RC\n  |.if FPU\n  |   lfdx f0, BASE, TMP1\n  |.else\n  |   add CARG3, BASE, TMP1\n  |   lwz TMP2, 0(CARG3)\n  |   lwz TMP3, 4(CARG3)\n  |.endif\n  |  beq >3\n  |.if FPU\n  |   stfdx f0, CARG2, TMP1\n  |.else\n  |   add CARG3, CARG2, TMP1\n  |   stw TMP2, 0(CARG3)\n  |   stw TMP3, 4(CARG3)\n  |.endif\n  |  addi TMP1, TMP1, 8\n  |  b <2\n  |3:\n  |  li CARG3, 0\n  |   mr L:SAVE0, L:CARG1\n  |  li CARG4, 0\n  |  bl ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |  // Returns thread status.\n  |4:\n  |  lp TMP2, L:SAVE0->base\n  |   cmplwi CRET1, LUA_YIELD\n  |  lp TMP3, L:SAVE0->top\n  |    li_vmstate INTERP\n  |  lp BASE, L->base\n  |    stw L, DISPATCH_GL(cur_L)(DISPATCH)\n  |    st_vmstate\n  |   bgt >8\n  |  sub RD, TMP3, TMP2\n  |   lwz TMP0, L->maxstack\n  |  cmplwi RD, 0\n  |   add TMP1, BASE, RD\n  |  beq >6\t\t\t\t// No results?\n  |  cmplw TMP1, TMP0\n  |   li TMP1, 0\n  |  bgt >9\t\t\t\t// Need to grow stack?\n  |\n  |  subi TMP3, RD, 8\n  |   stp TMP2, L:SAVE0->top\t\t// Clear coroutine stack.\n  |5:  // Move results from coroutine.\n  |  cmplw TMP1, TMP3\n  |.if FPU\n  |   lfdx f0, TMP2, TMP1\n  |   stfdx f0, BASE, TMP1\n  |.else\n  |   add CARG3, TMP2, TMP1\n  |   lwz CARG1, 0(CARG3)\n  |   lwz CARG2, 4(CARG3)\n  |   add CARG3, BASE, TMP1\n  |   stw CARG1, 0(CARG3)\n  |   stw CARG2, 4(CARG3)\n  |.endif\n  |    addi TMP1, TMP1, 8\n  |  bne <5\n  |6:\n  |  andix. TMP0, PC, FRAME_TYPE\n  |.if resume\n  |  li TMP1, LJ_TTRUE\n  |   la RA, -8(BASE)\n  |  stw TMP1, -8(BASE)\t\t\t// Prepend true to results.\n  |  addi RD, RD, 16\n  |.else\n  |  mr RA, BASE\n  |  addi RD, RD, 8\n  |.endif\n  |7:\n  |    stw PC, SAVE_PC\n  |   mr MULTRES, RD\n  |  beq ->BC_RET_Z\n  |  b ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  andix. TMP0, PC, FRAME_TYPE\n  |  la TMP3, -8(TMP3)\n  |   li TMP1, LJ_TFALSE\n  |.if FPU\n  |  lfd f0, 0(TMP3)\n  |.else\n  |  lwz CARG1, 0(TMP3)\n  |  lwz CARG2, 4(TMP3)\n  |.endif\n  |   stp TMP3, L:SAVE0->top\t\t// Remove error from coroutine stack.\n  |    li RD, (2+1)*8\n  |   stw TMP1, -8(BASE)\t\t// Prepend false to results.\n  |    la RA, -8(BASE)\n  |.if FPU\n  |  stfd f0, 0(BASE)\t\t\t// Copy error message.\n  |.else\n  |  stw CARG1, 0(BASE)\t\t\t// Copy error message.\n  |  stw CARG2, 4(BASE)\n  |.endif\n  |  b <7\n  |.else\n  |  mr CARG1, L\n  |  mr CARG2, L:SAVE0\n  |  bl extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mr CARG1, L\n  |  srwi CARG2, RD, 3\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  li CRET1, 0\n  |  b <4\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  lp TMP0, L->cframe\n  |   add TMP1, BASE, NARGS8:RC\n  |   stp BASE, L->base\n  |  andix. TMP0, TMP0, CFRAME_RESUME\n  |   stp TMP1, L->top\n  |    li CRET1, LUA_YIELD\n  |  beq ->fff_fallback\n  |   stp ZERO, L->cframe\n  |    stb CRET1, L->status\n  |  b ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  checknum CARG3\n  |.if DUALNUM\n  |  bne >2\n  |  srawi TMP1, CARG1, 31\n  |  xor TMP2, TMP1, CARG1\n  |.if GPR64\n  |  lus TMP0, 0x8000\n  |  sub CARG1, TMP2, TMP1\n  |  cmplw CARG1, TMP0\n  |  beq >1\n  |.else\n  |  sub. CARG1, TMP2, TMP1\n  |  blt >1\n  |.endif\n  |->fff_resi:\n  |  lwz PC, FRAME_PC(BASE)\n  |  la RA, -8(BASE)\n  |  stw TISNUM, -8(BASE)\n  |  stw CRET1, -4(BASE)\n  |  b ->fff_res1\n  |1:\n  |  lus CARG3, 0x41e0\t// 2^31.\n  |  li CARG1, 0\n  |  b ->fff_restv\n  |2:\n  |.endif\n  |  bge ->fff_fallback\n  |  rlwinm CARG3, CARG3, 0, 1, 31\n  |  // Fallthrough.\n  |\n  |->fff_restv:\n  |  // CARG3/CARG1 = TValue result.\n  |  lwz PC, FRAME_PC(BASE)\n  |   stw CARG3, -8(BASE)\n  |  la RA, -8(BASE)\n  |   stw CARG1, -4(BASE)\n  |->fff_res1:\n  |  // RA = results, PC = return.\n  |  li RD, (1+1)*8\n  |->fff_res:\n  |  // RA = results, RD = (nresults+1)*8, PC = return.\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   mr MULTRES, RD\n  |  bney ->vm_return\n  |  lwz INS, -4(PC)\n  |  decode_RB8 RB, INS\n  |5:\n  |  cmplw RB, RD\t\t\t// More results expected?\n  |   decode_RA8 TMP0, INS\n  |  bgt >6\n  |  ins_next1\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |   sub BASE, RA, TMP0\n  |  ins_next2\n  |\n  |6:  // Fill up results with nil.\n  |  subi TMP1, RD, 8\n  |   addi RD, RD, 8\n  |  stwx TISNIL, RA, TMP1\n  |  b <5\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.macro math_round, func\n  |  .ffunc_1 math_ .. func\n  |   checknum CARG3; beqy ->fff_restv\n  |  rlwinm TMP2, CARG3, 12, 21, 31\n  |   bge ->fff_fallback\n  |  addic. TMP2, TMP2, -1023\t\t// exp = exponent(x) - 1023\n  |  cmplwi cr1, TMP2, 31\t\t// 0 <= exp < 31?\n  |   subfic TMP0, TMP2, 31\n  |  blt >3\n  |  slwi TMP1, CARG3, 11\n  |   srwi TMP3, CARG1, 21\n  |  oris TMP1, TMP1, 0x8000\n  |   addi TMP2, TMP2, 1\n  |  or TMP1, TMP1, TMP3\n  |   slwi CARG2, CARG1, 11\n  |  bge cr1, >4\n  |   slw TMP3, TMP1, TMP2\n  |  srw RD, TMP1, TMP0\n  |   or TMP3, TMP3, CARG2\n  |  srawi TMP2, CARG3, 31\n  |.if \"func\" == \"floor\"\n  |  and TMP1, TMP3, TMP2\n  |  addic TMP0, TMP1, -1\n  |  subfe TMP1, TMP0, TMP1\n  |  add CARG1, RD, TMP1\n  |  xor CARG1, CARG1, TMP2\n  |  sub CARG1, CARG1, TMP2\n  |  b ->fff_resi\n  |.else\n  |  andc TMP1, TMP3, TMP2\n  |  addic TMP0, TMP1, -1\n  |  subfe TMP1, TMP0, TMP1\n  |  add CARG1, RD, TMP1\n  |  cmpw CARG1, RD\n  |  xor CARG1, CARG1, TMP2\n  |  sub CARG1, CARG1, TMP2\n  |  bge ->fff_resi\n  |  // Overflow to 2^31.\n  |  lus CARG3, 0x41e0\t\t\t// 2^31.\n  |  li CARG1, 0\n  |  b ->fff_restv\n  |.endif\n  |3:  // |x| < 1\n  |  slwi TMP2, CARG3, 1\n  |   srawi TMP1, CARG3, 31\n  |  or TMP2, CARG1, TMP2\t\t// ztest = (hi+hi) | lo\n  |.if \"func\" == \"floor\"\n  |  and TMP1, TMP2, TMP1\t\t// (ztest & sign) == 0 ? 0 : -1\n  |  subfic TMP2, TMP1, 0\n  |  subfe CARG1, CARG1, CARG1\n  |.else\n  |  andc TMP1, TMP2, TMP1\t\t// (ztest & ~sign) == 0 ? 0 : 1\n  |  addic TMP2, TMP1, -1\n  |  subfe CARG1, TMP2, TMP1\n  |.endif\n  |  b ->fff_resi\n  |4:  // exp >= 31. Check for -(2^31).\n  |  xoris TMP1, TMP1, 0x8000\n  |  srawi TMP2, CARG3, 31\n  |.if \"func\" == \"floor\"\n  |  or TMP1, TMP1, CARG2\n  |.endif\n  |.if PPE\n  |  orc TMP1, TMP1, TMP2\n  |  cmpwi TMP1, 0\n  |.else\n  |  orc. TMP1, TMP1, TMP2\n  |.endif\n  |  crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n  |  lus CARG1, 0x8000\t\t\t// -(2^31).\n  |  beqy ->fff_resi\n  |5:\n  |.if FPU\n  |  lfd FARG1, 0(BASE)\n  |.else\n  |  lwz CARG1, 0(BASE)\n  |  lwz CARG2, 4(BASE)\n  |.endif\n  |  blex func\n  |  b ->fff_resn\n  |.endmacro\n  |\n  |.if DUALNUM\n  |  math_round floor\n  |  math_round ceil\n  |.else\n  |  // NYI: use internal implementation.\n  |  math_extern floor\n  |  math_extern ceil\n  |.endif\n  |\n  |.if SQRT\n  |.ffunc_n math_sqrt\n  |  fsqrt FARG1, FARG1\n  |  b ->fff_resn\n  |.else\n  |  math_extern sqrt\n  |.endif\n  |\n  |.ffunc math_log\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG1, 0(BASE)\n  |  bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |  checknum CARG1; bge ->fff_fallback\n  |.if FPU\n  |  lfd FARG1, 0(BASE)\n  |.else\n  |  lwz CARG2, 4(BASE)\n  |.endif\n  |  blex log\n  |  b ->fff_resn\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.if DUALNUM\n  |.ffunc math_ldexp\n  |  cmplwi NARGS8:RC, 16\n  |   lwz TMP0, 0(BASE)\n  |.if FPU\n  |    lfd FARG1, 0(BASE)\n  |.else\n  |    lwz CARG1, 0(BASE)\n  |    lwz CARG2, 4(BASE)\n  |.endif\n  |   lwz TMP1, 8(BASE)\n  |.if GPR64\n  |    lwz CARG2, 12(BASE)\n  |.elif FPU\n  |    lwz CARG1, 12(BASE)\n  |.else\n  |    lwz CARG3, 12(BASE)\n  |.endif\n  |  blt ->fff_fallback\n  |  checknum TMP0; bge ->fff_fallback\n  |  checknum TMP1; bne ->fff_fallback\n  |.else\n  |.ffunc_nn math_ldexp\n  |.if GPR64\n  |  toint CARG2, FARG2\n  |.else\n  |  toint CARG1, FARG2\n  |.endif\n  |.endif\n  |  blex ldexp\n  |  b ->fff_resn\n  |\n  |.ffunc_n math_frexp\n  |.if GPR64\n  |  la CARG2, DISPATCH_GL(tmptv)(DISPATCH)\n  |.elif FPU\n  |  la CARG1, DISPATCH_GL(tmptv)(DISPATCH)\n  |.else\n  |  la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n  |.endif\n  |   lwz PC, FRAME_PC(BASE)\n  |  blex frexp\n  |   lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH)\n  |   la RA, -8(BASE)\n  |.if not DUALNUM\n  |   tonum_i FARG2, TMP1\n  |.endif\n  |.if FPU\n  |  stfd FARG1, 0(RA)\n  |.else\n  |  stw CRET1, 0(RA)\n  |  stw CRET2, 4(RA)\n  |.endif\n  |  li RD, (2+1)*8\n  |.if DUALNUM\n  |   stw TISNUM, 8(RA)\n  |   stw TMP1, 12(RA)\n  |.else\n  |   stfd FARG2, 8(RA)\n  |.endif\n  |  b ->fff_res\n  |\n  |.ffunc_n math_modf\n  |.if GPR64\n  |  la CARG2, -8(BASE)\n  |.elif FPU\n  |  la CARG1, -8(BASE)\n  |.else\n  |  la CARG3, -8(BASE)\n  |.endif\n  |   lwz PC, FRAME_PC(BASE)\n  |  blex modf\n  |   la RA, -8(BASE)\n  |.if FPU\n  |  stfd FARG1, 0(BASE)\n  |.else\n  |  stw CRET1, 0(BASE)\n  |  stw CRET2, 4(BASE)\n  |.endif\n  |  li RD, (2+1)*8\n  |  b ->fff_res\n  |\n  |.macro math_minmax, name, ismax\n  |.if DUALNUM\n  |  .ffunc_1 name\n  |  checknum CARG3\n  |   addi SAVE0, BASE, 8\n  |   add SAVE1, BASE, NARGS8:RC\n  |  bne >4\n  |1:  // Handle integers.\n  |  lwz CARG4, 0(SAVE0)\n  |   cmplw cr1, SAVE0, SAVE1\n  |  lwz CARG2, 4(SAVE0)\n  |   bge cr1, ->fff_resi\n  |  checknum CARG4\n  |   xoris TMP0, CARG1, 0x8000\n  |   xoris TMP3, CARG2, 0x8000\n  |  bne >3\n  |  subfc TMP3, TMP3, TMP0\n  |  subfe TMP0, TMP0, TMP0\n  |.if ismax\n  |  andc TMP3, TMP3, TMP0\n  |.else\n  |  and TMP3, TMP3, TMP0\n  |.endif\n  |  add CARG1, TMP3, CARG2\n  |.if GPR64\n  |  rldicl CARG1, CARG1, 0, 32\n  |.endif\n  |   addi SAVE0, SAVE0, 8\n  |  b <1\n  |3:\n  |  bge ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |.if FPU\n  |  tonum_i FARG1, CARG1\n  |  lfd FARG2, 0(SAVE0)\n  |.else\n  |  mr CARG2, CARG1\n  |  bl ->vm_sfi2d_1\n  |  lwz CARG3, 0(SAVE0)\n  |  lwz CARG4, 4(SAVE0)\n  |.endif\n  |  b >6\n  |4:\n  |.if FPU\n  |   lfd FARG1, 0(BASE)\n  |.else\n  |   lwz CARG1, 0(BASE)\n  |   lwz CARG2, 4(BASE)\n  |.endif\n  |  bge ->fff_fallback\n  |5:  // Handle numbers.\n  |  lwz CARG3, 0(SAVE0)\n  |   cmplw cr1, SAVE0, SAVE1\n  |.if FPU\n  |  lfd FARG2, 0(SAVE0)\n  |.else\n  |  lwz CARG4, 4(SAVE0)\n  |.endif\n  |   bge cr1, ->fff_resn\n  |  checknum CARG3; bge >7\n  |6:\n  |   addi SAVE0, SAVE0, 8\n  |.if FPU\n  |.if ismax\n  |  fsub f0, FARG1, FARG2\n  |.else\n  |  fsub f0, FARG2, FARG1\n  |.endif\n  |  fsel FARG1, f0, FARG1, FARG2\n  |.else\n  |  stw CARG1, SFSAVE_1\n  |  stw CARG2, SFSAVE_2\n  |  stw CARG3, SFSAVE_3\n  |  stw CARG4, SFSAVE_4\n  |  blex __ledf2\n  |  cmpwi CRET1, 0\n  |.if ismax\n  |  blt >8\n  |.else\n  |  bge >8\n  |.endif\n  |  lwz CARG1, SFSAVE_1\n  |  lwz CARG2, SFSAVE_2\n  |  b <5\n  |8:\n  |  lwz CARG1, SFSAVE_3\n  |  lwz CARG2, SFSAVE_4\n  |.endif\n  |  b <5\n  |7:  // Convert integer to number and continue above.\n  |   lwz CARG3, 4(SAVE0)\n  |  bne ->fff_fallback\n  |.if FPU\n  |  tonum_i FARG2, CARG3\n  |.else\n  |  bl ->vm_sfi2d_2\n  |.endif\n  |  b <6\n  |.else\n  |  .ffunc_n name\n  |  li TMP1, 8\n  |1:\n  |   lwzx CARG2, BASE, TMP1\n  |   lfdx FARG2, BASE, TMP1\n  |  cmplw cr1, TMP1, NARGS8:RC\n  |   checknum CARG2\n  |  bge cr1, ->fff_resn\n  |   bge ->fff_fallback\n  |.if ismax\n  |  fsub f0, FARG1, FARG2\n  |.else\n  |  fsub f0, FARG2, FARG1\n  |.endif\n  |   addi TMP1, TMP1, 8\n  |  fsel FARG1, f0, FARG1, FARG2\n  |  b <1\n  |.endif\n  |.endmacro\n  |\n  |  math_minmax math_min, 0\n  |  math_minmax math_max, 1\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz STR:CARG1, 4(BASE)\n  |  bne ->fff_fallback\t\t\t// Need exactly 1 argument.\n  |   checkstr CARG3\n  |   bne ->fff_fallback\n  |  lwz TMP0, STR:CARG1->len\n  |.if DUALNUM\n  |   lbz CARG1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |   li RD, (0+1)*8\n  |   lwz PC, FRAME_PC(BASE)\n  |  cmplwi TMP0, 0\n  |   la RA, -8(BASE)\n  |  beqy ->fff_res\n  |  b ->fff_resi\n  |.else\n  |   lbz TMP1, STR:CARG1[1]\t\t// Access is always ok (NUL at end).\n  |  addic TMP3, TMP0, -1\t\t// RD = ((str->len != 0)+1)*8\n  |  subfe RD, TMP3, TMP0\n  |   stw TMP1, TONUM_LO\t\t// Inlined tonum_u f0, TMP1.\n  |  addi RD, RD, 1\n  |   lfd f0, TONUM_D\n  |  la RA, -8(BASE)\n  |  lwz PC, FRAME_PC(BASE)\n  |   fsub f0, f0, TOBIT\n  |  slwi RD, RD, 3\n  |   stfd f0, 0(RA)\n  |  b ->fff_res\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |.if DUALNUM\n  |    lwz TMP0, 4(BASE)\n  |  bne ->fff_fallback\t\t\t// Exactly 1 argument.\n  |  checknum CARG3; bne ->fff_fallback\n  |   la CARG2, 7(BASE)\n  |.else\n  |    lfd FARG1, 0(BASE)\n  |  bne ->fff_fallback\t\t\t// Exactly 1 argument.\n  |  checknum CARG3; bge ->fff_fallback\n  |  toint TMP0, FARG1\n  |   la CARG2, TMPD_BLO\n  |.endif\n  |   li CARG3, 1\n  |  cmplwi TMP0, 255; bgt ->fff_fallback\n  |->fff_newstr:\n  |  mr CARG1, L\n  |  stp BASE, L->base\n  |  stw PC, SAVE_PC\n  |  bl extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // Returns GCstr *.\n  |  lp BASE, L->base\n  |  li CARG3, LJ_TSTR\n  |  b ->fff_restv\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 16\n  |   lwz CARG3, 16(BASE)\n  |.if not DUALNUM\n  |    lfd f0, 16(BASE)\n  |.endif\n  |   lwz TMP0, 0(BASE)\n  |    lwz STR:CARG1, 4(BASE)\n  |  blt ->fff_fallback\n  |   lwz CARG2, 8(BASE)\n  |.if DUALNUM\n  |    lwz TMP1, 12(BASE)\n  |.else\n  |    lfd f1, 8(BASE)\n  |.endif\n  |   li TMP2, -1\n  |  beq >1\n  |.if DUALNUM\n  |  checknum CARG3\n  |   lwz TMP2, 20(BASE)\n  |  bne ->fff_fallback\n  |1:\n  |  checknum CARG2; bne ->fff_fallback\n  |.else\n  |  checknum CARG3; bge ->fff_fallback\n  |  toint TMP2, f0\n  |1:\n  |  checknum CARG2; bge ->fff_fallback\n  |.endif\n  |  checkstr TMP0; bne ->fff_fallback\n  |.if not DUALNUM\n  |   toint TMP1, f1\n  |.endif\n  |   lwz TMP0, STR:CARG1->len\n  |  cmplw TMP0, TMP2\t\t\t// len < end? (unsigned compare)\n  |   addi TMP3, TMP2, 1\n  |  blt >5\n  |2:\n  |  cmpwi TMP1, 0\t\t\t// start <= 0?\n  |   add TMP3, TMP1, TMP0\n  |  ble >7\n  |3:\n  |  sub CARG3, TMP2, TMP1\n  |    addi CARG2, STR:CARG1, #STR-1\n  |  srawi TMP0, CARG3, 31\n  |   addi CARG3, CARG3, 1\n  |    add CARG2, CARG2, TMP1\n  |  andc CARG3, CARG3, TMP0\n  |.if GPR64\n  |  rldicl CARG2, CARG2, 0, 32\n  |  rldicl CARG3, CARG3, 0, 32\n  |.endif\n  |  b ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  cmpw TMP0, TMP2\t\t\t// len >= end? (signed compare)\n  |   add TMP2, TMP0, TMP3\t\t// Negative end: end = end+len+1.\n  |  bge <2\n  |   mr TMP2, TMP0\t\t\t// Overflow: end = len.\n  |  b <2\n  |\n  |7:  // Negative start or underflow.\n  |  .gpr64 extsw TMP1, TMP1\n  |  addic CARG3, TMP1, -1\n  |  subfe CARG3, CARG3, CARG3\n  |   srawi CARG2, TMP3, 31\t\t// Note: modifies carry.\n  |  andc TMP3, TMP3, CARG3\n  |   andc TMP1, TMP3, CARG2\n  |  addi TMP1, TMP1, 1\t\t\t// start = 1 + (start ? start+len : 0)\n  |  b <3\n  |\n  |.macro ffstring_op, name\n  |  .ffunc string_ .. name\n  |  ffgccheck\n  |  cmplwi NARGS8:RC, 8\n  |   lwz CARG3, 0(BASE)\n  |    lwz STR:CARG2, 4(BASE)\n  |  blt ->fff_fallback\n  |  checkstr CARG3\n  |   la SBUF:CARG1, DISPATCH_GL(tmpbuf)(DISPATCH)\n  |  bne ->fff_fallback\n  |   lwz TMP0, SBUF:CARG1->b\n  |  stw L, SBUF:CARG1->L\n  |  stp BASE, L->base\n  |  stw PC, SAVE_PC\n  |   stw TMP0, SBUF:CARG1->w\n  |  bl extern lj_buf_putstr_ .. name\n  |  bl extern lj_buf_tostr\n  |  b ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name\n  |.if DUALNUM\n  |  .ffunc_1 bit_..name\n  |  checknum CARG3; bnel ->fff_tobit_fb\n  |.else\n  |  .ffunc_n bit_..name\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |.endif\n  |.endmacro\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name\n  |  addi SAVE0, BASE, 8\n  |  add SAVE1, BASE, NARGS8:RC\n  |1:\n  |  lwz CARG4, 0(SAVE0)\n  |   cmplw cr1, SAVE0, SAVE1\n  |.if DUALNUM\n  |  lwz CARG2, 4(SAVE0)\n  |.else\n  |  lfd FARG1, 0(SAVE0)\n  |.endif\n  |   bgey cr1, ->fff_resi\n  |  checknum CARG4\n  |.if DUALNUM\n  |.if FPU\n  |  bnel ->fff_bitop_fb\n  |.else\n  |  beq >3\n  |  stw CARG1, SFSAVE_1\n  |  bl ->fff_bitop_fb\n  |  mr CARG2, CARG1\n  |  lwz CARG1, SFSAVE_1\n  |3:\n  |.endif\n  |.else\n  |  fadd FARG1, FARG1, TOBIT\n  |  bge ->fff_fallback\n  |  stfd FARG1, TMPD\n  |  lwz CARG2, TMPD_LO\n  |.endif\n  |  ins CARG1, CARG1, CARG2\n  |   addi SAVE0, SAVE0, 8\n  |  b <1\n  |.endmacro\n  |\n  |.ffunc_bit_op band, and\n  |.ffunc_bit_op bor, or\n  |.ffunc_bit_op bxor, xor\n  |\n  |.ffunc_bit bswap\n  |  rotlwi TMP0, CARG1, 8\n  |  rlwimi TMP0, CARG1, 24, 0, 7\n  |  rlwimi TMP0, CARG1, 24, 16, 23\n  |  mr CRET1, TMP0\n  |  b ->fff_resi\n  |\n  |.ffunc_bit bnot\n  |  not CRET1, CARG1\n  |  b ->fff_resi\n  |\n  |.macro .ffunc_bit_sh, name, ins, shmod\n  |.if DUALNUM\n  |  .ffunc_2 bit_..name\n  |.if FPU\n  |  checknum CARG3; bnel ->fff_tobit_fb\n  |.else\n  |  checknum CARG3; beq >1\n  |  bl ->fff_tobit_fb\n  |  lwz CARG2, 12(BASE)\t// Conversion polluted CARG2.\n  |1:\n  |.endif\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  checknum CARG4; bne ->fff_fallback\n  |.else\n  |  .ffunc_nn bit_..name\n  |  fadd FARG1, FARG1, TOBIT\n  |  fadd FARG2, FARG2, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |  stfd FARG2, TMPD\n  |  lwz CARG2, TMPD_LO\n  |.endif\n  |.if shmod == 1\n  |  rlwinm CARG2, CARG2, 0, 27, 31\n  |.elif shmod == 2\n  |  neg CARG2, CARG2\n  |.endif\n  |  ins CRET1, CARG1, CARG2\n  |  b ->fff_resi\n  |.endmacro\n  |\n  |.ffunc_bit_sh lshift, slw, 1\n  |.ffunc_bit_sh rshift, srw, 1\n  |.ffunc_bit_sh arshift, sraw, 1\n  |.ffunc_bit_sh rol, rotlw, 0\n  |.ffunc_bit_sh ror, rotlw, 2\n  |\n  |.ffunc_bit tobit\n  |.if DUALNUM\n  |  b ->fff_resi\n  |.else\n  |->fff_resi:\n  |  tonum_i FARG1, CRET1\n  |.endif\n  |->fff_resn:\n  |  lwz PC, FRAME_PC(BASE)\n  |  la RA, -8(BASE)\n  |.if FPU\n  |  stfd FARG1, -8(BASE)\n  |.else\n  |  stw CARG1, -8(BASE)\n  |  stw CARG2, -4(BASE)\n  |.endif\n  |  b ->fff_res1\n  |\n  |// Fallback FP number to bit conversion.\n  |->fff_tobit_fb:\n  |.if DUALNUM\n  |.if FPU\n  |  lfd FARG1, 0(BASE)\n  |  bgt ->fff_fallback\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG1, TMPD_LO\n  |  blr\n  |.else\n  |  bgt ->fff_fallback\n  |  mr CARG2, CARG1\n  |  mr CARG1, CARG3\n  |// Modifies: CARG1, CARG2, TMP0, TMP1, TMP2.\n  |->vm_tobit:\n  |  slwi TMP2, CARG1, 1\n  |  addis TMP2, TMP2, 0x0020\n  |  cmpwi TMP2, 0\n  |  bge >2\n  |   li TMP1, 0x3e0\n  |  srawi TMP2, TMP2, 21\n  |   not TMP1, TMP1\n  |  sub. TMP2, TMP1, TMP2\n  |    cmpwi cr7, CARG1, 0\n  |  blt >1\n  |   slwi TMP1, CARG1, 11\n  |    srwi TMP0, CARG2, 21\n  |   oris TMP1, TMP1, 0x8000\n  |   or TMP1, TMP1, TMP0\n  |   srw CARG1, TMP1, TMP2\n  |  bclr 4, 28\t\t\t// Return if cr7[lt] == 0, no hint.\n  |   neg CARG1, CARG1\n  |  blr\n  |1:\n  |  addi TMP2, TMP2, 21\n  |  srw TMP1, CARG2, TMP2\n  |   slwi CARG2, CARG1, 12\n  |  subfic TMP2, TMP2, 20\n  |   slw TMP0, CARG2, TMP2\n  |   or CARG1, TMP1, TMP0\n  |  bclr 4, 28\t\t\t// Return if cr7[lt] == 0, no hint.\n  |   neg CARG1, CARG1\n  |  blr\n  |2:\n  |  li CARG1, 0\n  |  blr\n  |.endif\n  |.endif\n  |->fff_bitop_fb:\n  |.if DUALNUM\n  |.if FPU\n  |  lfd FARG1, 0(SAVE0)\n  |  bgt ->fff_fallback\n  |  fadd FARG1, FARG1, TOBIT\n  |  stfd FARG1, TMPD\n  |  lwz CARG2, TMPD_LO\n  |  blr\n  |.else\n  |  bgt ->fff_fallback\n  |  mr CARG1, CARG4\n  |  b ->vm_tobit\n  |.endif\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RB = CFUNC, RC = nargs*8\n  |  lp TMP3, CFUNC:RB->f\n  |    add TMP1, BASE, NARGS8:RC\n  |   lwz PC, FRAME_PC(BASE)\t\t// Fallback may overwrite PC.\n  |    addi TMP0, TMP1, 8*LUA_MINSTACK\n  |     lwz TMP2, L->maxstack\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  .toc lp TMP3, 0(TMP3)\n  |  cmplw TMP0, TMP2\n  |     stp BASE, L->base\n  |    stp TMP1, L->top\n  |   mr CARG1, L\n  |  bgt >5\t\t\t\t// Need to grow stack.\n  |  mtctr TMP3\n  |  bctrl\t\t\t\t// (lua_State *L)\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  lp BASE, L->base\n  |  cmpwi CRET1, 0\n  |   slwi RD, CRET1, 3\n  |   la RA, -8(BASE)\n  |  bgt ->fff_res\t\t\t// Returned nresults+1?\n  |1:  // Returned 0 or -1: retry fast path.\n  |  lp TMP0, L->top\n  |   lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  sub NARGS8:RC, TMP0, BASE\n  |  bne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  andix. TMP0, PC, FRAME_TYPE\n  |   rlwinm TMP1, PC, 0, 0, 28\n  |  bne >3\n  |  lwz INS, -4(PC)\n  |  decode_RA8 TMP1, INS\n  |  addi TMP1, TMP1, 8\n  |3:\n  |  sub TMP2, BASE, TMP1\n  |  b ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  li CARG2, LUA_MINSTACK\n  |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lp BASE, L->base\n  |  cmpw TMP0, TMP0\t\t\t// Set 4*cr0+eq to force retry.\n  |  b <1\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RC = nargs*8\n  |  mflr SAVE0\n  |   stp BASE, L->base\n  |  add TMP0, BASE, NARGS8:RC\n  |   stw PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  stp TMP0, L->top\n  |  mr CARG1, L\n  |  bl extern lj_gc_step\t\t// (lua_State *L)\n  |   lp BASE, L->base\n  |  mtlr SAVE0\n  |    lp TMP0, L->top\n  |   sub NARGS8:RC, TMP0, BASE\n  |   lwz CFUNC:RB, FRAME_FUNC(BASE)\n  |  blr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_VMEVENT\t// No recording while in vmevent.\n  |  bne >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |   lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\n  |  bne >1\n  |   subi TMP2, TMP2, 1\n  |  andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT\n  |  beqy >1\n  |   stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  b >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\t// Hook already active?\n  |  beq >1\n  |5:  // Re-dispatch to static ins.\n  |  addi TMP1, TMP1, GG_DISP2STATIC\t// Assumes decode_OPP TMP1, INS.\n  |  lpx TMP0, DISPATCH, TMP1\n  |  mtctr TMP0\n  |  bctr\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)\n  |  lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  andix. TMP0, TMP3, HOOK_ACTIVE\t// Hook already active?\n  |   rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0\n  |  bne <5\n  |\n  |   cmpwi cr1, TMP0, 0\n  |  addic. TMP2, TMP2, -1\n  |   beq cr1, <5\n  |  stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)\n  |  beq >1\n  |   bge cr1, <5\n  |1:\n  |  mr CARG1, L\n  |   stw MULTRES, SAVE_MULTRES\n  |  mr CARG2, PC\n  |   stp BASE, L->base\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  bl extern lj_dispatch_ins\t\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  lp BASE, L->base\n  |4:  // Re-dispatch to static ins.\n  |  lwz INS, -4(PC)\n  |  decode_OPP TMP1, INS\n  |   decode_RB8 RB, INS\n  |  addi TMP1, TMP1, GG_DISP2STATIC\n  |   decode_RD8 RD, INS\n  |  lpx TMP0, DISPATCH, TMP1\n  |   decode_RA8 RA, INS\n  |   decode_RC8 RC, INS\n  |  mtctr TMP0\n  |  bctr\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  addi PC, PC, 4\n  |  lwz MULTRES, -20(RB)\t\t// Restore MULTRES for *M ins.\n  |  b <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n  |   addi CARG1, DISPATCH, GG_DISP2J\n  |   stw PC, SAVE_PC\n  |  lwz TMP1, LFUNC:TMP1->pc\n  |   mr CARG2, PC\n  |   stw L, DISPATCH_J(L)(DISPATCH)\n  |  lbz TMP1, PC2PROTO(framesize)(TMP1)\n  |   stp BASE, L->base\n  |  slwi TMP1, TMP1, 3\n  |  add TMP1, BASE, TMP1\n  |  stp TMP1, L->top\n  |  bl extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  b <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mr CARG2, PC\n  |.if JIT\n  |  b >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  ori CARG2, PC, 1\n  |1:\n  |.endif\n  |  add TMP0, BASE, RC\n  |   stw PC, SAVE_PC\n  |  mr CARG1, L\n  |   stp BASE, L->base\n  |  sub RA, RA, BASE\n  |   stp TMP0, L->top\n  |  bl extern lj_dispatch_call\t\t// (lua_State *L, const BCIns *pc)\n  |  // Returns ASMFunction.\n  |  lp BASE, L->base\n  |   lp TMP0, L->top\n  |   stw ZERO, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |  sub NARGS8:RC, TMP0, BASE\n  |  add RA, BASE, RA\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |  lwz INS, -4(PC)\n  |  mtctr CRET1\n  |  bctr\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // RA = resultptr, RB = meta base\n  |  lwz INS, -4(PC)\n  |    lwz TRACE:TMP2, -20(RB)\t\t// Save previous trace.\n  |   addic. TMP1, MULTRES, -8\n  |  decode_RA8 RC, INS\t\t\t// Call base.\n  |   beq >2\n  |1:  // Move results down.\n  |.if FPU\n  |  lfd f0, 0(RA)\n  |.else\n  |  lwz CARG1, 0(RA)\n  |  lwz CARG2, 4(RA)\n  |.endif\n  |   addic. TMP1, TMP1, -8\n  |    addi RA, RA, 8\n  |.if FPU\n  |  stfdx f0, BASE, RC\n  |.else\n  |  add CARG3, BASE, RC\n  |  stw CARG1, 0(CARG3)\n  |  stw CARG2, 4(CARG3)\n  |.endif\n  |    addi RC, RC, 8\n  |   bne <1\n  |2:\n  |   decode_RA8 RA, INS\n  |   decode_RB8 RB, INS\n  |   add RA, RA, RB\n  |3:\n  |   cmplw RA, RC\n  |   bgt >9\t\t\t\t// More results wanted?\n  |\n  |  lhz TMP3, TRACE:TMP2->traceno\n  |  lhz RD, TRACE:TMP2->link\n  |  cmpw RD, TMP3\n  |   cmpwi cr1, RD, 0\n  |  beq ->cont_nop\t\t\t// Blacklisted.\n  |    slwi RD, RD, 3\n  |   bne cr1, =>BC_JLOOP\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  stw TMP3, DISPATCH_J(exitno)(DISPATCH)\n  |  stp L, DISPATCH_J(L)(DISPATCH)\n  |  stp BASE, L->base\n  |  addi CARG1, DISPATCH, GG_DISP2J\n  |  mr CARG2, PC\n  |  bl extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  lp BASE, L->base\n  |  b ->cont_nop\n  |\n  |9:\n  |  stwx TISNIL, BASE, RC\n  |  addi RC, RC, 8\n  |  b <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mr CARG1, L\n  |   stw MULTRES, SAVE_MULTRES\n  |  mr CARG2, PC\n  |   stp BASE, L->base\n  |  bl extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  lp BASE, L->base\n  |  subi PC, PC, 4\n  |  b ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro savex_, a, b, c, d\n  |.if FPU\n  |  stfd f..a, 16+a*8(sp)\n  |  stfd f..b, 16+b*8(sp)\n  |  stfd f..c, 16+c*8(sp)\n  |  stfd f..d, 16+d*8(sp)\n  |.endif\n  |.endmacro\n  |\n  |->vm_exit_handler:\n  |.if JIT\n  |  addi sp, sp, -(16+32*8+32*4)\n  |  stmw r2, 16+32*8+2*4(sp)\n  |    addi DISPATCH, JGL, -GG_DISP2G-32768\n  |    li CARG2, ~LJ_VMST_EXIT\n  |   lwz CARG1, 16+32*8+32*4(sp)\t// Get stack chain.\n  |    stw CARG2, DISPATCH_GL(vmstate)(DISPATCH)\n  |  savex_ 0,1,2,3\n  |   stw CARG1, 0(sp)\t\t\t// Store extended stack chain.\n  |   clrso TMP1\n  |  savex_ 4,5,6,7\n  |   addi CARG2, sp, 16+32*8+32*4\t// Recompute original value of sp.\n  |  savex_ 8,9,10,11\n  |   stw CARG2, 16+32*8+1*4(sp)\t// Store sp in RID_SP.\n  |  savex_ 12,13,14,15\n  |   mflr CARG3\n  |   li TMP1, 0\n  |  savex_ 16,17,18,19\n  |   stw TMP1, 16+32*8+0*4(sp)\t\t// Clear RID_TMP.\n  |  savex_ 20,21,22,23\n  |   lhz CARG4, 2(CARG3)\t\t// Load trace number.\n  |  savex_ 24,25,26,27\n  |  lwz L, DISPATCH_GL(cur_L)(DISPATCH)\n  |  savex_ 28,29,30,31\n  |   sub CARG3, TMP0, CARG3\t\t// Compute exit number.\n  |  lp BASE, DISPATCH_GL(jit_base)(DISPATCH)\n  |   srwi CARG3, CARG3, 2\n  |  stp L, DISPATCH_J(L)(DISPATCH)\n  |   subi CARG3, CARG3, 2\n  |  stp BASE, L->base\n  |   stw CARG4, DISPATCH_J(parent)(DISPATCH)\n  |  stw TMP1, DISPATCH_GL(jit_base)(DISPATCH)\n  |  addi CARG1, DISPATCH, GG_DISP2J\n  |   stw CARG3, DISPATCH_J(exitno)(DISPATCH)\n  |  addi CARG2, sp, 16\n  |  bl extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // Returns MULTRES (unscaled) or negated error code.\n  |  lp TMP1, L->cframe\n  |  lwz TMP2, 0(sp)\n  |   lp BASE, L->base\n  |.if GPR64\n  |  rldicr sp, TMP1, 0, 61\n  |.else\n  |  rlwinm sp, TMP1, 0, 0, 29\n  |.endif\n  |   lwz PC, SAVE_PC\t\t\t// Get SAVE_PC.\n  |  stw TMP2, 0(sp)\n  |  stw L, SAVE_L\t\t\t// Set SAVE_L (on-trace resume/yield).\n  |  b >1\n  |.endif\n  |->vm_exit_interp:\n  |.if JIT\n  |  // CARG1 = MULTRES or negated error code, BASE, PC and JGL set.\n  |  lwz L, SAVE_L\n  |  addi DISPATCH, JGL, -GG_DISP2G-32768\n  |  stp BASE, L->base\n  |1:\n  |  cmpwi CARG1, 0\n  |  blt >9\t\t\t\t// Check for error from exit.\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |   slwi MULTRES, CARG1, 3\n  |    li TMP2, 0\n  |   stw MULTRES, SAVE_MULTRES\n  |  lwz TMP1, LFUNC:RB->pc\n  |    stw TMP2, DISPATCH_GL(jit_base)(DISPATCH)\n  |  lwz KBASE, PC2PROTO(k)(TMP1)\n  |  // Setup type comparison constants.\n  |  li TISNUM, LJ_TISNUM\n  |  .FPU lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |  .FPU stw TMP3, TMPD\n  |  li ZERO, 0\n  |  .FPU ori TMP3, TMP3, 0x0004\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |  .FPU lfs TOBIT, TMPD\n  |  .FPU stw TMP3, TMPD\n  |  .FPU lus TMP0, 0x4338\t\t\t// Hiword of 2^52 + 2^51 (double)\n  |    li TISNIL, LJ_TNIL\n  |  .FPU stw TMP0, TONUM_HI\n  |  .FPU lfs TONUM, TMPD\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  lwz INS, 0(PC)\n  |   addi PC, PC, 4\n  |    // Assumes TISNIL == ~LJ_VMST_INTERP == -1.\n  |    stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)\n  |  decode_OPP TMP1, INS\n  |   decode_RA8 RA, INS\n  |  lpx TMP0, DISPATCH, TMP1\n  |  mtctr TMP0\n  |  cmplwi TMP1, BC_FUNCF*4\t\t// Function header?\n  |  bge >2\n  |   decode_RB8 RB, INS\n  |   decode_RD8 RD, INS\n  |   decode_RC8 RC, INS\n  |  bctr\n  |2:\n  |  cmplwi TMP1, (BC_FUNCC+2)*4\t// Fast function?\n  |  blt >3\n  |  // Check frame below fast function.\n  |  lwz TMP1, FRAME_PC(BASE)\n  |  andix. TMP0, TMP1, FRAME_TYPE\n  |  bney >3\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  lwz TMP2, -4(TMP1)\n  |  decode_RA8 TMP0, TMP2\n  |  sub TMP1, BASE, TMP0\n  |  lwz LFUNC:TMP2, -12(TMP1)\n  |  lwz TMP1, LFUNC:TMP2->pc\n  |  lwz KBASE, PC2PROTO(k)(TMP1)\n  |3:\n  |   subi RC, MULTRES, 8\n  |   add RA, RA, BASE\n  |  bctr\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  neg CARG2, CARG1\n  |  mr CARG1, L\n  |  bl extern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// NYI: Use internal implementations of floor, ceil, trunc, sfcmp.\n  |\n  |.macro sfi2d, AHI, ALO\n  |.if not FPU\n  |  mr. AHI, ALO\n  |  bclr 12, 2\t\t\t\t// Handle zero first.\n  |  srawi TMP0, ALO, 31\n  |  xor TMP1, ALO, TMP0\n  |  sub TMP1, TMP1, TMP0\t\t// Absolute value in TMP1.\n  |  cntlzw AHI, TMP1\n  |  andix. TMP0, TMP0, 0x800\t\t// Mask sign bit.\n  |  slw TMP1, TMP1, AHI\t\t// Align mantissa left with leading 1.\n  |  subfic AHI, AHI, 0x3ff+31-1\t// Exponent -1 in AHI.\n  |  slwi ALO, TMP1, 21\n  |  or AHI, AHI, TMP0\t\t\t// Sign | Exponent.\n  |  srwi TMP1, TMP1, 11\n  |  slwi AHI, AHI, 20\t\t\t// Align left.\n  |  add AHI, AHI, TMP1\t\t\t// Add mantissa, increment exponent.\n  |  blr\n  |.endif\n  |.endmacro\n  |\n  |// Input: CARG2. Output: CARG1, CARG2. Temporaries: TMP0, TMP1.\n  |->vm_sfi2d_1:\n  |  sfi2d CARG1, CARG2\n  |\n  |// Input: CARG4. Output: CARG3, CARG4. Temporaries: TMP0, TMP1.\n  |->vm_sfi2d_2:\n  |  sfi2d CARG3, CARG4\n  |\n  |->vm_modi:\n  |  divwo. TMP0, CARG1, CARG2\n  |  bso >1\n  |.if GPR64\n  |   xor CARG3, CARG1, CARG2\n  |   cmpwi CARG3, 0\n  |.else\n  |   xor. CARG3, CARG1, CARG2\n  |.endif\n  |  mullw TMP0, TMP0, CARG2\n  |  sub CARG1, CARG1, TMP0\n  |   bgelr\n  |  cmpwi CARG1, 0; beqlr\n  |  add CARG1, CARG1, CARG2\n  |  blr\n  |1:\n  |  cmpwi CARG2, 0\n  |   li CARG1, 0\n  |  beqlr\n  |  clrso TMP0\t\t\t// Clear SO for -2147483648 % -1 and return 0.\n  |  blr\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// void lj_vm_cachesync(void *start, void *end)\n  |// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size.\n  |// This is a good lower bound, except for very ancient PPC models.\n  |->vm_cachesync:\n  |.if JIT or FFI\n  |  // Compute start of first cache line and number of cache lines.\n  |  rlwinm CARG1, CARG1, 0, 0, 26\n  |  sub CARG2, CARG2, CARG1\n  |  addi CARG2, CARG2, 31\n  |  rlwinm. CARG2, CARG2, 27, 5, 31\n  |  beqlr\n  |  mtctr CARG2\n  |  mr CARG3, CARG1\n  |1:  // Flush D-Cache.\n  |  dcbst r0, CARG1\n  |  addi CARG1, CARG1, 32\n  |  bdnz <1\n  |  sync\n  |  mtctr CARG2\n  |1:  // Invalidate I-Cache.\n  |  icbi r0, CARG3\n  |  addi CARG3, CARG3, 32\n  |  bdnz <1\n  |  isync\n  |  blr\n  |.endif\n  |\n  |->vm_next:\n  |.if JIT\n  |  NYI  // On big-endian.\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in r11, g in r12.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs\n  |  lwz CTSTATE, GL:r12->ctype_state\n  |   addi DISPATCH, r12, GG_G2DISP\n  |  stw r11, CTSTATE->cb.slot\n  |  stw r3, CTSTATE->cb.gpr[0]\n  |   .FPU stfd f1, CTSTATE->cb.fpr[0]\n  |  stw r4, CTSTATE->cb.gpr[1]\n  |   .FPU stfd f2, CTSTATE->cb.fpr[1]\n  |  stw r5, CTSTATE->cb.gpr[2]\n  |   .FPU stfd f3, CTSTATE->cb.fpr[2]\n  |  stw r6, CTSTATE->cb.gpr[3]\n  |   .FPU stfd f4, CTSTATE->cb.fpr[3]\n  |  stw r7, CTSTATE->cb.gpr[4]\n  |   .FPU stfd f5, CTSTATE->cb.fpr[4]\n  |  stw r8, CTSTATE->cb.gpr[5]\n  |   .FPU stfd f6, CTSTATE->cb.fpr[5]\n  |  stw r9, CTSTATE->cb.gpr[6]\n  |   .FPU stfd f7, CTSTATE->cb.fpr[6]\n  |  stw r10, CTSTATE->cb.gpr[7]\n  |   .FPU stfd f8, CTSTATE->cb.fpr[7]\n  |  addi TMP0, sp, CFRAME_SPACE+8\n  |  stw TMP0, CTSTATE->cb.stack\n  |   mr CARG1, CTSTATE\n  |  stw CTSTATE, SAVE_PC\t\t// Any value outside of bytecode is ok.\n  |   mr CARG2, sp\n  |  bl extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // Returns lua_State *.\n  |  lp BASE, L:CRET1->base\n  |     li TISNUM, LJ_TISNUM\t\t// Setup type comparison constants.\n  |  lp RC, L:CRET1->top\n  |     .FPU lus TMP3, 0x59c0\t\t// TOBIT = 2^52 + 2^51 (float).\n  |     li ZERO, 0\n  |   mr L, CRET1\n  |     .FPU stw TMP3, TMPD\n  |     .FPU lus TMP0, 0x4338\t\t// Hiword of 2^52 + 2^51 (double)\n  |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n  |     .FPU ori TMP3, TMP3, 0x0004\t// TONUM = 2^52 + 2^51 + 2^31 (float).\n  |     .FPU stw TMP0, TONUM_HI\n  |     li TISNIL, LJ_TNIL\n  |    li_vmstate INTERP\n  |     .FPU lfs TOBIT, TMPD\n  |     .FPU stw TMP3, TMPD\n  |  sub RC, RC, BASE\n  |    st_vmstate\n  |     .FPU lfs TONUM, TMPD\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)\n  |   stp BASE, L->base\n  |   stp RB, L->top\n  |  stp L, CTSTATE->L\n  |  mr CARG1, CTSTATE\n  |  mr CARG2, RA\n  |  bl extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  lwz CRET1, CTSTATE->cb.gpr[0]\n  |  .FPU lfd FARG1, CTSTATE->cb.fpr[0]\n  |  lwz CRET2, CTSTATE->cb.gpr[1]\n  |  b ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, CARG1\n  |  lwz TMP1, CCSTATE->spadj\n  |    mflr TMP0\n  |   lbz CARG2, CCSTATE->nsp\n  |   lbz CARG3, CCSTATE->nfpr\n  |  neg TMP1, TMP1\n  |    stw TMP0, 4(sp)\n  |   cmpwi cr1, CARG3, 0\n  |  mr TMP2, sp\n  |   addic. CARG2, CARG2, -1\n  |  stwux sp, sp, TMP1\n  |   crnot 4*cr1+eq, 4*cr1+eq\t\t// For vararg calls.\n  |  stw r14, -4(TMP2)\n  |  stw CCSTATE, -8(TMP2)\n  |  mr r14, TMP2\n  |  la TMP1, CCSTATE->stack\n  |   slwi CARG2, CARG2, 2\n  |   blty >2\n  |  la TMP2, 8(sp)\n  |1:\n  |  lwzx TMP0, TMP1, CARG2\n  |  stwx TMP0, TMP2, CARG2\n  |   addic. CARG2, CARG2, -4\n  |  bge <1\n  |2:\n  |  bney cr1, >3\n  |  .FPU lfd f1, CCSTATE->fpr[0]\n  |  .FPU lfd f2, CCSTATE->fpr[1]\n  |  .FPU lfd f3, CCSTATE->fpr[2]\n  |  .FPU lfd f4, CCSTATE->fpr[3]\n  |  .FPU lfd f5, CCSTATE->fpr[4]\n  |  .FPU lfd f6, CCSTATE->fpr[5]\n  |  .FPU lfd f7, CCSTATE->fpr[6]\n  |  .FPU lfd f8, CCSTATE->fpr[7]\n  |3:\n  |   lp TMP0, CCSTATE->func\n  |  lwz CARG2, CCSTATE->gpr[1]\n  |  lwz CARG3, CCSTATE->gpr[2]\n  |  lwz CARG4, CCSTATE->gpr[3]\n  |  lwz CARG5, CCSTATE->gpr[4]\n  |   mtctr TMP0\n  |  lwz r8, CCSTATE->gpr[5]\n  |  lwz r9, CCSTATE->gpr[6]\n  |  lwz r10, CCSTATE->gpr[7]\n  |  lwz CARG1, CCSTATE->gpr[0]\t\t// Do this last, since CCSTATE is CARG1.\n  |   bctrl\n  |  lwz CCSTATE:TMP1, -8(r14)\n  |  lwz TMP2, -4(r14)\n  |   lwz TMP0, 4(r14)\n  |  stw CARG1, CCSTATE:TMP1->gpr[0]\n  |  .FPU stfd FARG1, CCSTATE:TMP1->fpr[0]\n  |  stw CARG2, CCSTATE:TMP1->gpr[1]\n  |   mtlr TMP0\n  |  stw CARG3, CCSTATE:TMP1->gpr[2]\n  |   mr sp, r14\n  |  stw CARG4, CCSTATE:TMP1->gpr[3]\n  |   mr r14, TMP2\n  |  blr\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux CARG1, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux CARG3, RD, BASE\n    |    lwz TMP2, -4(PC)\n    |  checknum cr0, CARG1\n    |   lwz CARG4, 4(RD)\n    |    decode_RD4 TMP2, TMP2\n    |  checknum cr1, CARG3\n    |    addis SAVE0, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bne cr0, >7\n    |  bne cr1, >8\n    |   cmpw CARG2, CARG4\n    if (op == BC_ISLT) {\n      |  bge >2\n    } else if (op == BC_ISGE) {\n      |  blt >2\n    } else if (op == BC_ISLE) {\n      |  bgt >2\n    } else {\n      |  ble >2\n    }\n    |1:\n    |  add PC, PC, SAVE0\n    |2:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  bgt cr0, ->vmeta_comp\n    |  // RA is a number.\n    |   .FPU lfd f0, 0(RA)\n    |  bgt cr1, ->vmeta_comp\n    |  blt cr1, >4\n    |  // RA is a number, RD is an integer.\n    |.if FPU\n    |  tonum_i f1, CARG4\n    |.else\n    |  bl ->vm_sfi2d_2\n    |.endif\n    |  b >5\n    |\n    |8: // RA is an integer, RD is not an integer.\n    |  bgt cr1, ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |.if FPU\n    |  tonum_i f0, CARG2\n    |.else\n    |  bl ->vm_sfi2d_1\n    |.endif\n    |4:\n    |  .FPU lfd f1, 0(RD)\n    |5:\n    |.if FPU\n    |  fcmpu cr0, f0, f1\n    |.else\n    |  blex __ledf2\n    |  cmpwi CRET1, 0\n    |.endif\n    if (op == BC_ISLT) {\n      |  bge <2\n    } else if (op == BC_ISGE) {\n      |  blt <2\n    } else if (op == BC_ISLE) {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  bge <2\n    } else {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  blt <2\n    }\n    |  b <1\n    |.else\n    |  lwzx TMP0, BASE, RA\n    |    addi PC, PC, 4\n    |   lfdx f0, BASE, RA\n    |  lwzx TMP1, BASE, RD\n    |  checknum cr0, TMP0\n    |    lwz TMP2, -4(PC)\n    |   lfdx f1, BASE, RD\n    |  checknum cr1, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |  bge cr0, ->vmeta_comp\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  bge cr1, ->vmeta_comp\n    |  fcmpu cr0, f0, f1\n    if (op == BC_ISLT) {\n      |  bge >1\n    } else if (op == BC_ISGE) {\n      |  blt >1\n    } else if (op == BC_ISLE) {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  bge >1\n    } else {\n      |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq\n      |  blt >1\n    }\n    |  add PC, PC, TMP2\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  // RA = src1*8, RD = src2*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux CARG1, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux CARG3, RD, BASE\n    |  checknum cr0, CARG1\n    |    lwz SAVE0, -4(PC)\n    |  checknum cr1, CARG3\n    |    decode_RD4 SAVE0, SAVE0\n    |   lwz CARG4, 4(RD)\n    |  cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt\n    |    addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)\n    if (vk) {\n      |  ble cr7, ->BC_ISEQN_Z\n    } else {\n      |  ble cr7, ->BC_ISNEN_Z\n    }\n    |.else\n    |  lwzux CARG1, RA, BASE\n    |   lwz SAVE0, 0(PC)\n    |    lfd f0, 0(RA)\n    |   addi PC, PC, 4\n    |  lwzux CARG3, RD, BASE\n    |  checknum cr0, CARG1\n    |   decode_RD4 SAVE0, SAVE0\n    |    lfd f1, 0(RD)\n    |  checknum cr1, CARG3\n    |   addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)\n    |  bge cr0, >5\n    |  bge cr1, >5\n    |  fcmpu cr0, f0, f1\n    if (vk) {\n      |  bne >1\n      |  add PC, PC, SAVE0\n    } else {\n      |  beq >1\n      |  add PC, PC, SAVE0\n    }\n    |1:\n    |  ins_next\n    |.endif\n    |5:  // Either or both types are not numbers.\n    |.if not DUALNUM\n    |    lwz CARG2, 4(RA)\n    |    lwz CARG4, 4(RD)\n    |.endif\n    |.if FFI\n    |  cmpwi cr7, CARG1, LJ_TCDATA\n    |  cmpwi cr5, CARG3, LJ_TCDATA\n    |.endif\n    |   not TMP2, CARG1\n    |  cmplw CARG1, CARG3\n    |   cmplwi cr1, TMP2, ~LJ_TISPRI\t\t// Primitive?\n    |.if FFI\n    |  cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq\n    |.endif\n    |   cmplwi cr6, TMP2, ~LJ_TISTABUD\t\t// Table or userdata?\n    |.if FFI\n    |  beq cr7, ->vmeta_equal_cd\n    |.endif\n    |    cmplw cr5, CARG2, CARG4\n    |  crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt\t// 2: Same type and primitive.\n    |  crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq\t// 1: Same tv or different type.\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq\t// 0: Same type and same tv.\n    |   mr SAVE1, PC\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt\t// 0 or 2.\n    |  cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt\t// 1 or 2.\n    if (vk) {\n      |  bne cr0, >6\n      |  add PC, PC, SAVE0\n      |6:\n    } else {\n      |  beq cr0, >6\n      |  add PC, PC, SAVE0\n      |6:\n    }\n    |.if DUALNUM\n    |  bge cr0, >2\t\t\t// Done if 1 or 2.\n    |1:\n    |  ins_next\n    |2:\n    |.else\n    |  blt cr0, <1\t\t\t// Done if 1 or 2.\n    |.endif\n    |  blt cr6, <1\t\t\t// Done if not tab/ud.\n    |\n    |  // Different tables or userdatas. Need to check __eq metamethod.\n    |  // Field metatable must be at same offset for GCtab and GCudata!\n    |   mr CARG3, CARG4\n    |  lwz TAB:TMP2, TAB:CARG2->metatable\n    |   li CARG4, 1-vk\t\t\t// ne = 0 or 1.\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable?\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_eq\n    |  bne <1\t\t\t\t// Or 'no __eq' flag set?\n    |  mr PC, SAVE1\t\t\t// Restore old PC.\n    |  b ->vmeta_equal\t\t\t// Handle __eq metamethod.\n    break;\n\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  // RA = src*8, RD = str_const*8 (~), JMP with RD = target\n    |  lwzux TMP0, RA, BASE\n    |   srwi RD, RD, 1\n    |  lwz STR:TMP3, 4(RA)\n    |    lwz TMP2, 0(PC)\n    |   subfic RD, RD, -4\n    |    addi PC, PC, 4\n    |.if FFI\n    |  cmpwi TMP0, LJ_TCDATA\n    |.endif\n    |   lwzx STR:TMP1, KBASE, RD\t// KBASE-4-str_const*4\n    |  .gpr64 extsw TMP0, TMP0\n    |  subfic TMP0, TMP0, LJ_TSTR\n    |.if FFI\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |  sub TMP1, STR:TMP1, STR:TMP3\n    |  or TMP0, TMP0, TMP1\n    |    decode_RD4 TMP2, TMP2\n    |  subfic TMP0, TMP0, 0\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  subfe TMP1, TMP1, TMP1\n    if (vk) {\n      |  andc TMP2, TMP2, TMP1\n    } else {\n      |  and TMP2, TMP2, TMP1\n    }\n    |  add PC, PC, TMP2\n    |  ins_next\n    break;\n\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  // RA = src*8, RD = num_const*8, JMP with RD = target\n    |.if DUALNUM\n    |  lwzux CARG1, RA, BASE\n    |    addi PC, PC, 4\n    |   lwz CARG2, 4(RA)\n    |  lwzux CARG3, RD, KBASE\n    |  checknum cr0, CARG1\n    |    lwz SAVE0, -4(PC)\n    |  checknum cr1, CARG3\n    |    decode_RD4 SAVE0, SAVE0\n    |   lwz CARG4, 4(RD)\n    |    addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)\n    if (vk) {\n      |->BC_ISEQN_Z:\n    } else {\n      |->BC_ISNEN_Z:\n    }\n    |  bne cr0, >7\n    |  bne cr1, >8\n    |   cmpw CARG2, CARG4\n    |4:\n    |.else\n    if (vk) {\n      |->BC_ISEQN_Z:  // Dummy label.\n    } else {\n      |->BC_ISNEN_Z:  // Dummy label.\n    }\n    |  lwzx CARG1, BASE, RA\n    |    addi PC, PC, 4\n    |   lfdx f0, BASE, RA\n    |    lwz SAVE0, -4(PC)\n    |  lfdx f1, KBASE, RD\n    |    decode_RD4 SAVE0, SAVE0\n    |  checknum CARG1\n    |    addis SAVE0, SAVE0, -(BCBIAS_J*4 >> 16)\n    |  bge >3\n    |  fcmpu cr0, f0, f1\n    |.endif\n    if (vk) {\n      |  bne >1\n      |  add PC, PC, SAVE0\n      |1:\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |  beq >2\n      |1:\n      |.if not FFI\n      |3:\n      |.endif\n      |  add PC, PC, SAVE0\n      |2:\n    }\n    |  ins_next\n    |.if FFI\n    |3:\n    |  cmpwi CARG1, LJ_TCDATA\n    |  beq ->vmeta_equal_cd\n    |  b <1\n    |.endif\n    |.if DUALNUM\n    |7:  // RA is not an integer.\n    |  bge cr0, <3\n    |  // RA is a number.\n    |   .FPU lfd f0, 0(RA)\n    |  blt cr1, >1\n    |  // RA is a number, RD is an integer.\n    |.if FPU\n    |  tonum_i f1, CARG4\n    |.else\n    |  bl ->vm_sfi2d_2\n    |.endif\n    |  b >2\n    |\n    |8: // RA is an integer, RD is a number.\n    |.if FPU\n    |  tonum_i f0, CARG2\n    |.else\n    |  bl ->vm_sfi2d_1\n    |.endif\n    |1:\n    |  .FPU lfd f1, 0(RD)\n    |2:\n    |.if FPU\n    |  fcmpu cr0, f0, f1\n    |.else\n    |  blex __ledf2\n    |  cmpwi CRET1, 0\n    |.endif\n    |  b <4\n    |.endif\n    break;\n\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target\n    |  lwzx TMP0, BASE, RA\n    |   srwi TMP1, RD, 3\n    |    lwz TMP2, 0(PC)\n    |   not TMP1, TMP1\n    |    addi PC, PC, 4\n    |.if FFI\n    |  cmpwi TMP0, LJ_TCDATA\n    |.endif\n    |  sub TMP0, TMP0, TMP1\n    |.if FFI\n    |  beq ->vmeta_equal_cd\n    |.endif\n    |    decode_RD4 TMP2, TMP2\n    |  .gpr64 extsw TMP0, TMP0\n    |  addic TMP0, TMP0, -1\n    |    addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n    |  subfe TMP1, TMP1, TMP1\n    if (vk) {\n      |  and TMP2, TMP2, TMP1\n    } else {\n      |  andc TMP2, TMP2, TMP1\n    }\n    |  add PC, PC, TMP2\n    |  ins_next\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  // RA = dst*8 or unused, RD = src*8, JMP with RD = target\n    |  lwzx TMP0, BASE, RD\n    |   lwz INS, 0(PC)\n    |   addi PC, PC, 4\n    if (op == BC_IST || op == BC_ISF) {\n      |  .gpr64 extsw TMP0, TMP0\n      |  subfic TMP0, TMP0, LJ_TTRUE\n      |   decode_RD4 TMP2, INS\n      |  subfe TMP1, TMP1, TMP1\n      |   addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)\n      if (op == BC_IST) {\n\t|  andc TMP2, TMP2, TMP1\n      } else {\n\t|  and TMP2, TMP2, TMP1\n      }\n      |  add PC, PC, TMP2\n    } else {\n      |  li TMP1, LJ_TFALSE\n      |.if FPU\n      |   lfdx f0, BASE, RD\n      |.else\n      |   lwzux CARG1, RD, BASE\n      |   lwz CARG2, 4(RD)\n      |.endif\n      |  cmplw TMP0, TMP1\n      if (op == BC_ISTC) {\n\t|  bge >1\n      } else {\n\t|  blt >1\n      }\n      |  addis PC, PC, -(BCBIAS_J*4 >> 16)\n      |  decode_RD4 TMP2, INS\n      |.if FPU\n      |   stfdx f0, BASE, RA\n      |.else\n      |   stwux CARG1, RA, BASE\n      |   stw CARG2, 4(RA)\n      |.endif\n      |  add PC, PC, TMP2\n      |1:\n    }\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  // RA = src*8, RD = -type*8\n    |  lwzx TMP0, BASE, RA\n    |  srwi TMP1, RD, 3\n    |  ins_next1\n    |.if not PPE and not GPR64\n    |  add. TMP0, TMP0, TMP1\n    |.else\n    |  neg TMP1, TMP1\n    |  cmpw TMP0, TMP1\n    |.endif\n    |  bne ->vmeta_istype\n    |  ins_next2\n    break;\n  case BC_ISNUM:\n    |  // RA = src*8, RD = -(TISNUM-1)*8\n    |  lwzx TMP0, BASE, RA\n    |  ins_next1\n    |  checknum TMP0\n    |  bge ->vmeta_istype\n    |  ins_next2\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  // RA = dst*8, RD = src*8\n    |  ins_next1\n    |.if FPU\n    |  lfdx f0, BASE, RD\n    |  stfdx f0, BASE, RA\n    |.else\n    |  lwzux TMP0, RD, BASE\n    |  lwz TMP1, 4(RD)\n    |  stwux TMP0, RA, BASE\n    |  stw TMP1, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n  case BC_NOT:\n    |  // RA = dst*8, RD = src*8\n    |  ins_next1\n    |  lwzx TMP0, BASE, RD\n    |  .gpr64 extsw TMP0, TMP0\n    |  subfic TMP1, TMP0, LJ_TTRUE\n    |  adde TMP0, TMP0, TMP1\n    |  stwx TMP0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_UNM:\n    |  // RA = dst*8, RD = src*8\n    |  lwzux TMP1, RD, BASE\n    |   lwz TMP0, 4(RD)\n    |  checknum TMP1\n    |.if DUALNUM\n    |  bne >5\n    |.if GPR64\n    |  lus TMP2, 0x8000\n    |  neg TMP0, TMP0\n    |  cmplw TMP0, TMP2\n    |  beq >4\n    |.else\n    |  nego. TMP0, TMP0\n    |  bso >4\n    |1:\n    |.endif\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |   stw TMP0, 4(RA)\n    |3:\n    |  ins_next2\n    |4:\n    |.if not GPR64\n    |  // Potential overflow.\n    |  checkov TMP1, <1\t\t\t// Ignore unrelated overflow.\n    |.endif\n    |  lus TMP1, 0x41e0\t\t\t// 2^31.\n    |  li TMP0, 0\n    |  b >7\n    |.endif\n    |5:\n    |  bge ->vmeta_unm\n    |  xoris TMP1, TMP1, 0x8000\n    |7:\n    |  ins_next1\n    |  stwux TMP1, RA, BASE\n    |   stw TMP0, 4(RA)\n    |.if DUALNUM\n    |  b <3\n    |.else\n    |  ins_next2\n    |.endif\n    break;\n  case BC_LEN:\n    |  // RA = dst*8, RD = src*8\n    |  lwzux TMP0, RD, BASE\n    |   lwz CARG1, 4(RD)\n    |  checkstr TMP0; bne >2\n    |  lwz CRET1, STR:CARG1->len\n    |1:\n    |.if DUALNUM\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |   stw CRET1, 4(RA)\n    |.else\n    |  tonum_u f0, CRET1\t\t// Result is a non-negative integer.\n    |  ins_next1\n    |  stfdx f0, BASE, RA\n    |.endif\n    |  ins_next2\n    |2:\n    |  checktab TMP0; bne ->vmeta_len\n#if LJ_52\n    |  lwz TAB:TMP2, TAB:CARG1->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  bne >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  bl extern lj_tab_len\t\t// (GCtab *t)\n    |  // Returns uint32_t (but less than 2^31).\n    |  b <1\n#if LJ_52\n    |9:\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_len\n    |  bne <3\t\t\t\t// 'no __len' flag set: done.\n    |  b ->vmeta_len\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   lwzx CARG1, BASE, RB\n    |   .if DUALNUM\n    |     lwzx CARG3, KBASE, RC\n    |   .endif\n    |   .if FPU\n    |    lfdx f14, BASE, RB\n    |    lfdx f15, KBASE, RC\n    |   .else\n    |    add TMP1, BASE, RB\n    |    add TMP2, KBASE, RC\n    |    lwz CARG2, 4(TMP1)\n    |    lwz CARG4, 4(TMP2)\n    |   .endif\n    |   .if DUALNUM\n    |     checknum cr0, CARG1\n    |     checknum cr1, CARG3\n    |     crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |     bge ->vmeta_arith_vn\n    |   .else\n    |     checknum CARG1; bge ->vmeta_arith_vn\n    |   .endif\n    ||  break;\n    ||case 1:\n    |   lwzx CARG1, BASE, RB\n    |   .if DUALNUM\n    |     lwzx CARG3, KBASE, RC\n    |   .endif\n    |   .if FPU\n    |    lfdx f15, BASE, RB\n    |    lfdx f14, KBASE, RC\n    |   .else\n    |    add TMP1, BASE, RB\n    |    add TMP2, KBASE, RC\n    |    lwz CARG2, 4(TMP1)\n    |    lwz CARG4, 4(TMP2)\n    |   .endif\n    |   .if DUALNUM\n    |     checknum cr0, CARG1\n    |     checknum cr1, CARG3\n    |     crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |     bge ->vmeta_arith_nv\n    |   .else\n    |     checknum CARG1; bge ->vmeta_arith_nv\n    |   .endif\n    ||  break;\n    ||default:\n    |   lwzx CARG1, BASE, RB\n    |   lwzx CARG3, BASE, RC\n    |   .if FPU\n    |    lfdx f14, BASE, RB\n    |    lfdx f15, BASE, RC\n    |   .else\n    |    add TMP1, BASE, RB\n    |    add TMP2, BASE, RC\n    |    lwz CARG2, 4(TMP1)\n    |    lwz CARG4, 4(TMP2)\n    |   .endif\n    |   checknum cr0, CARG1\n    |   checknum cr1, CARG3\n    |   crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |   bge ->vmeta_arith_vv\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithfallback, ins\n    ||switch (vk) {\n    ||case 0:\n    |   ins ->vmeta_arith_vn2\n    ||  break;\n    ||case 1:\n    |   ins ->vmeta_arith_nv2\n    ||  break;\n    ||default:\n    |   ins ->vmeta_arith_vv2\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro intmod, a, b, c\n    |  bl ->vm_modi\n    |.endmacro\n    |\n    |.macro fpmod, a, b, c\n    |->BC_MODVN_Z:\n    |  fdiv FARG1, b, c\n    |  // NYI: Use internal implementation of floor.\n    |  blex floor\t\t\t// floor(b/c)\n    |  fmul a, FARG1, c\n    |  fsub a, b, a\t\t\t// b - floor(b/c)*c\n    |.endmacro\n    |\n    |.macro sfpmod\n    |->BC_MODVN_Z:\n    |  stw CARG1, SFSAVE_1\n    |  stw CARG2, SFSAVE_2\n    |  mr SAVE0, CARG3\n    |  mr SAVE1, CARG4\n    |  blex __divdf3\n    |  blex floor\n    |  mr CARG3, SAVE0\n    |  mr CARG4, SAVE1\n    |  blex __muldf3\n    |  mr CARG3, CRET1\n    |  mr CARG4, CRET2\n    |  lwz CARG1, SFSAVE_1\n    |  lwz CARG2, SFSAVE_2\n    |  blex __subdf3\n    |.endmacro\n    |\n    |.macro ins_arithfp, fpins\n    |  ins_arithpre\n    |.if \"fpins\" == \"fpmod_\"\n    |  b ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    |.elif FPU\n    |  fpins f0, f14, f15\n    |  ins_next1\n    |  stfdx f0, BASE, RA\n    |  ins_next2\n    |.else\n    |  blex __divdf3\t\t\t// Only soft-float div uses this macro.\n    |  ins_next1\n    |  stwux CRET1, RA, BASE\n    |  stw CRET2, 4(RA)\n    |  ins_next2\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins, fpins, fpcall\n    |  // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   lwzux CARG1, RB, BASE\n    |   lwzux CARG3, RC, KBASE\n    |    lwz CARG2, 4(RB)\n    |   checknum cr0, CARG1\n    |    lwz CARG4, 4(RC)\n    |   checknum cr1, CARG3\n    ||  break;\n    ||case 1:\n    |   lwzux CARG3, RB, BASE\n    |   lwzux CARG1, RC, KBASE\n    |    lwz CARG4, 4(RB)\n    |   checknum cr0, CARG3\n    |    lwz CARG2, 4(RC)\n    |   checknum cr1, CARG1\n    ||  break;\n    ||default:\n    |   lwzux CARG1, RB, BASE\n    |   lwzux CARG3, RC, BASE\n    |    lwz CARG2, 4(RB)\n    |   checknum cr0, CARG1\n    |    lwz CARG4, 4(RC)\n    |   checknum cr1, CARG3\n    ||  break;\n    ||}\n    |  bne >5\n    |  bne cr1, >5\n    |.if \"intins\" == \"intmod\"\n    |  mr CARG1, CARG2\n    |  mr CARG2, CARG4\n    |.endif\n    |  intins CARG1, CARG2, CARG4\n    |  bso >4\n    |1:\n    |  ins_next1\n    |  stwux TISNUM, RA, BASE\n    |  stw CARG1, 4(RA)\n    |2:\n    |  ins_next2\n    |4:  // Overflow.\n    |  checkov TMP0, <1\t\t\t// Ignore unrelated overflow.\n    |  ins_arithfallback b\n    |5:  // FP variant.\n    |.if FPU\n    ||if (vk == 1) {\n    |  lfd f15, 0(RB)\n    |  lfd f14, 0(RC)\n    ||} else {\n    |  lfd f14, 0(RB)\n    |  lfd f15, 0(RC)\n    ||}\n    |.endif\n    |  crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |   ins_arithfallback bge\n    |.if \"fpins\" == \"fpmod_\"\n    |  b ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    |.else\n    |.if FPU\n    |  fpins f0, f14, f15\n    |  stfdx f0, BASE, RA\n    |.else\n    |.if \"fpcall\" == \"sfpmod\"\n    |  sfpmod\n    |.else\n    |  blex fpcall\n    |.endif\n    |  stwux CRET1, RA, BASE\n    |  stw CRET2, 4(RA)\n    |.endif\n    |  ins_next1\n    |  b <2\n    |.endif\n    |.endmacro\n    |\n    |.macro ins_arith, intins, fpins, fpcall\n    |.if DUALNUM\n    |  ins_arithdn intins, fpins, fpcall\n    |.else\n    |  ins_arithfp fpins\n    |.endif\n    |.endmacro\n\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |.if GPR64\n    |.macro addo32., y, a, b\n    |  // Need to check overflow for (a<<32) + (b<<32).\n    |  rldicr TMP0, a, 32, 31\n    |  rldicr TMP1, b, 32, 31\n    |  addo. TMP0, TMP0, TMP1\n    |  add y, a, b\n    |.endmacro\n    |  ins_arith addo32., fadd, __adddf3\n    |.else\n    |  ins_arith addo., fadd, __adddf3\n    |.endif\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |.if GPR64\n    |.macro subo32., y, a, b\n    |  // Need to check overflow for (a<<32) - (b<<32).\n    |  rldicr TMP0, a, 32, 31\n    |  rldicr TMP1, b, 32, 31\n    |  subo. TMP0, TMP0, TMP1\n    |  sub y, a, b\n    |.endmacro\n    |  ins_arith subo32., fsub, __subdf3\n    |.else\n    |  ins_arith subo., fsub, __subdf3\n    |.endif\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith mullwo., fmul, __muldf3\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp fdiv\n    break;\n  case BC_MODVN:\n    |  ins_arith intmod, fpmod, sfpmod\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arith intmod, fpmod_, sfpmod\n    break;\n  case BC_POW:\n    |  // NYI: (partial) integer arithmetic.\n    |  lwzx CARG1, BASE, RB\n    |  lwzx CARG3, BASE, RC\n    |.if FPU\n    |   lfdx FARG1, BASE, RB\n    |   lfdx FARG2, BASE, RC\n    |.else\n    |   add TMP1, BASE, RB\n    |   add TMP2, BASE, RC\n    |   lwz CARG2, 4(TMP1)\n    |   lwz CARG4, 4(TMP2)\n    |.endif\n    |  checknum cr0, CARG1\n    |  checknum cr1, CARG3\n    |  crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n    |  bge ->vmeta_arith_vv\n    |  blex pow\n    |  ins_next1\n    |.if FPU\n    |  stfdx FARG1, BASE, RA\n    |.else\n    |  stwux CARG1, RA, BASE\n    |  stw CARG2, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  case BC_CAT:\n    |  // RA = dst*8, RB = src_start*8, RC = src_end*8\n    |  sub CARG3, RC, RB\n    |   stp BASE, L->base\n    |  add CARG2, BASE, RC\n    |  mr SAVE0, RB\n    |->BC_CAT_Z:\n    |   stw PC, SAVE_PC\n    |  mr CARG1, L\n    |  srwi CARG3, CARG3, 3\n    |  bl extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // Returns NULL (finished) or TValue * (metamethod).\n    |  cmplwi CRET1, 0\n    |   lp BASE, L->base\n    |  bne ->vmeta_binop\n    |  ins_next1\n    |.if FPU\n    |  lfdx f0, BASE, SAVE0\t\t// Copy result from RB to RA.\n    |  stfdx f0, BASE, RA\n    |.else\n    |  lwzux TMP0, SAVE0, BASE\n    |  lwz TMP1, 4(SAVE0)\n    |  stwux TMP0, RA, BASE\n    |  stw TMP1, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  // RA = dst*8, RD = str_const*8 (~)\n    |  srwi TMP1, RD, 1\n    |  subfic TMP1, TMP1, -4\n    |  ins_next1\n    |  lwzx TMP0, KBASE, TMP1\t\t// KBASE-4-str_const*4\n    |  li TMP2, LJ_TSTR\n    |  stwux TMP2, RA, BASE\n    |  stw TMP0, 4(RA)\n    |  ins_next2\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  // RA = dst*8, RD = cdata_const*8 (~)\n    |  srwi TMP1, RD, 1\n    |  subfic TMP1, TMP1, -4\n    |  ins_next1\n    |  lwzx TMP0, KBASE, TMP1\t\t// KBASE-4-cdata_const*4\n    |  li TMP2, LJ_TCDATA\n    |  stwux TMP2, RA, BASE\n    |  stw TMP0, 4(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  // RA = dst*8, RD = int16_literal*8\n    |.if DUALNUM\n    |  slwi RD, RD, 13\n    |  srawi RD, RD, 16\n    |  ins_next1\n    |   stwux TISNUM, RA, BASE\n    |   stw RD, 4(RA)\n    |  ins_next2\n    |.else\n    |  // The soft-float approach is faster.\n    |  slwi RD, RD, 13\n    |  srawi TMP1, RD, 31\n    |  xor TMP2, TMP1, RD\n    |  sub TMP2, TMP2, TMP1\t\t// TMP2 = abs(x)\n    |  cntlzw TMP3, TMP2\n    |  subfic TMP1, TMP3, 0x40d\t\t// TMP1 = exponent-1\n    |   slw TMP2, TMP2, TMP3\t\t// TMP2 = left aligned mantissa\n    |    subfic TMP3, RD, 0\n    |  slwi TMP1, TMP1, 20\n    |   rlwimi RD, TMP2, 21, 1, 31\t// hi = sign(x) | (mantissa>>11)\n    |    subfe TMP0, TMP0, TMP0\n    |   add RD, RD, TMP1\t\t// hi = hi + exponent-1\n    |    and RD, RD, TMP0\t\t// hi = x == 0 ? 0 : hi\n    |  ins_next1\n    |    stwux RD, RA, BASE\n    |    stw ZERO, 4(RA)\n    |  ins_next2\n    |.endif\n    break;\n  case BC_KNUM:\n    |  // RA = dst*8, RD = num_const*8\n    |  ins_next1\n    |.if FPU\n    |  lfdx f0, KBASE, RD\n    |  stfdx f0, BASE, RA\n    |.else\n    |  lwzux TMP0, RD, KBASE\n    |  lwz TMP1, 4(RD)\n    |  stwux TMP0, RA, BASE\n    |  stw TMP1, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n  case BC_KPRI:\n    |  // RA = dst*8, RD = primitive_type*8 (~)\n    |  srwi TMP1, RD, 3\n    |  not TMP0, TMP1\n    |  ins_next1\n    |  stwx TMP0, BASE, RA\n    |  ins_next2\n    break;\n  case BC_KNIL:\n    |  // RA = base*8, RD = end*8\n    |  stwx TISNIL, BASE, RA\n    |   addi RA, RA, 8\n    |1:\n    |  stwx TISNIL, BASE, RA\n    |  cmpw RA, RD\n    |   addi RA, RA, 8\n    |  blt <1\n    |  ins_next_\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  // RA = dst*8, RD = uvnum*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RD, RD, 1\n    |   addi RD, RD, offsetof(GCfuncL, uvptr)\n    |  lwzx UPVAL:RB, LFUNC:RB, RD\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |.if FPU\n    |  lfd f0, 0(TMP1)\n    |  stfdx f0, BASE, RA\n    |.else\n    |  lwz TMP2, 0(TMP1)\n    |  lwz TMP3, 4(TMP1)\n    |  stwux TMP2, RA, BASE\n    |  stw TMP3, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n  case BC_USETV:\n    |  // RA = uvnum*8, RD = src*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |    srwi RA, RA, 1\n    |    addi RA, RA, offsetof(GCfuncL, uvptr)\n    |.if FPU\n    |   lfdux f0, RD, BASE\n    |.else\n    |   lwzux CARG1, RD, BASE\n    |   lwz CARG3, 4(RD)\n    |.endif\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  lbz TMP3, UPVAL:RB->marked\n    |   lwz CARG2, UPVAL:RB->v\n    |  andix. TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |    lbz TMP0, UPVAL:RB->closed\n    |   lwz TMP2, 0(RD)\n    |.if FPU\n    |   stfd f0, 0(CARG2)\n    |.else\n    |   stw CARG1, 0(CARG2)\n    |   stw CARG3, 4(CARG2)\n    |.endif\n    |    cmplwi cr1, TMP0, 0\n    |   lwz TMP1, 4(RD)\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n    |   subi TMP2, TMP2, (LJ_TNUMX+1)\n    |  bne >2\t\t\t\t// Upvalue is closed and black?\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if new value is collectable.\n    |  cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1)\n    |  bge <1\t\t\t\t// tvisgcv(v)\n    |  lbz TMP3, GCOBJ:TMP1->gch.marked\n    |  andix. TMP3, TMP3, LJ_GC_WHITES\t// iswhite(v)\n    |   la CARG1, GG_DISP2G(DISPATCH)\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  beq <1\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETS:\n    |  // RA = uvnum*8, RD = str_const*8 (~)\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi TMP1, RD, 1\n    |    srwi RA, RA, 1\n    |   subfic TMP1, TMP1, -4\n    |    addi RA, RA, offsetof(GCfuncL, uvptr)\n    |   lwzx STR:TMP1, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  lbz TMP3, UPVAL:RB->marked\n    |   lwz CARG2, UPVAL:RB->v\n    |  andix. TMP3, TMP3, LJ_GC_BLACK\t// isblack(uv)\n    |   lbz TMP3, STR:TMP1->marked\n    |   lbz TMP2, UPVAL:RB->closed\n    |   li TMP0, LJ_TSTR\n    |   stw STR:TMP1, 4(CARG2)\n    |   stw TMP0, 0(CARG2)\n    |  bne >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  andix. TMP3, TMP3, LJ_GC_WHITES\t// iswhite(str)\n    |   cmplwi cr1, TMP2, 0\n    |  cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n    |   la CARG1, GG_DISP2G(DISPATCH)\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  beq <1\n    |  bl extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  b <1\n    break;\n  case BC_USETN:\n    |  // RA = uvnum*8, RD = num_const*8\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RA, RA, 1\n    |   addi RA, RA, offsetof(GCfuncL, uvptr)\n    |.if FPU\n    |    lfdx f0, KBASE, RD\n    |.else\n    |    lwzux TMP2, RD, KBASE\n    |    lwz TMP3, 4(RD)\n    |.endif\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |.if FPU\n    |  stfd f0, 0(TMP1)\n    |.else\n    |  stw TMP2, 0(TMP1)\n    |  stw TMP3, 4(TMP1)\n    |.endif\n    |  ins_next2\n    break;\n  case BC_USETP:\n    |  // RA = uvnum*8, RD = primitive_type*8 (~)\n    |  lwz LFUNC:RB, FRAME_FUNC(BASE)\n    |   srwi RA, RA, 1\n    |    srwi TMP0, RD, 3\n    |   addi RA, RA, offsetof(GCfuncL, uvptr)\n    |    not TMP0, TMP0\n    |  lwzx UPVAL:RB, LFUNC:RB, RA\n    |  ins_next1\n    |  lwz TMP1, UPVAL:RB->v\n    |  stw TMP0, 0(TMP1)\n    |  ins_next2\n    break;\n\n  case BC_UCLO:\n    |  // RA = level*8, RD = target\n    |  lwz TMP1, L->openupval\n    |  branch_RD\t\t\t// Do this first since RD is not saved.\n    |   stp BASE, L->base\n    |  cmplwi TMP1, 0\n    |   mr CARG1, L\n    |  beq >1\n    |   add CARG2, BASE, RA\n    |  bl extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  lp BASE, L->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)\n    |  srwi TMP1, RD, 1\n    |   stp BASE, L->base\n    |  subfic TMP1, TMP1, -4\n    |   stw PC, SAVE_PC\n    |  lwzx CARG2, KBASE, TMP1\t\t// KBASE-4-tab_const*4\n    |   mr CARG1, L\n    |  lwz CARG3, FRAME_FUNC(BASE)\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  bl extern lj_func_newL_gc\n    |  // Returns GCfuncL *.\n    |  lp BASE, L->base\n    |   li TMP0, LJ_TFUNC\n    |  stwux TMP0, RA, BASE\n    |  stw LFUNC:CRET1, 4(RA)\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n  case BC_TDUP:\n    |  // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)\n    |  lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)\n    |   mr CARG1, L\n    |  lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)\n    |   stp BASE, L->base\n    |  cmplw TMP0, TMP1\n    |   stw PC, SAVE_PC\n    |  bge >5\n    |1:\n    if (op == BC_TNEW) {\n      |  rlwinm CARG2, RD, 29, 21, 31\n      |  rlwinm CARG3, RD, 18, 27, 31\n      |  cmpwi CARG2, 0x7ff; beq >3\n      |2:\n      |  bl extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n      |  // Returns Table *.\n    } else {\n      |  srwi TMP1, RD, 1\n      |  subfic TMP1, TMP1, -4\n      |  lwzx CARG2, KBASE, TMP1\t\t// KBASE-4-tab_const*4\n      |  bl extern lj_tab_dup  // (lua_State *L, Table *kt)\n      |  // Returns Table *.\n    }\n    |  lp BASE, L->base\n    |   li TMP0, LJ_TTAB\n    |  stwux TMP0, RA, BASE\n    |  stw TAB:CRET1, 4(RA)\n    |  ins_next\n    if (op == BC_TNEW) {\n      |3:\n      |  li CARG2, 0x801\n      |  b <2\n    }\n    |5:\n    |  mr SAVE0, RD\n    |  bl extern lj_gc_step_fixtop  // (lua_State *L)\n    |  mr RD, SAVE0\n    |  mr CARG1, L\n    |  b <1\n    break;\n\n  case BC_GGET:\n    |  // RA = dst*8, RD = str_const*8 (~)\n  case BC_GSET:\n    |  // RA = src*8, RD = str_const*8 (~)\n    |  lwz LFUNC:TMP2, FRAME_FUNC(BASE)\n    |   srwi TMP1, RD, 1\n    |  lwz TAB:RB, LFUNC:TMP2->env\n    |   subfic TMP1, TMP1, -4\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    if (op == BC_GGET) {\n      |  b ->BC_TGETS_Z\n    } else {\n      |  b ->BC_TSETS_Z\n    }\n    break;\n\n  case BC_TGETV:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  lwzux CARG1, RB, BASE\n    |  lwzux CARG2, RC, BASE\n    |   lwz TAB:RB, 4(RB)\n    |.if DUALNUM\n    |   lwz RC, 4(RC)\n    |.else\n    |   lfd f0, 0(RC)\n    |.endif\n    |  checktab CARG1\n    |   checknum cr1, CARG2\n    |  bne ->vmeta_tgetv\n    |.if DUALNUM\n    |  lwz TMP0, TAB:RB->asize\n    |   bne cr1, >5\n    |   lwz TMP1, TAB:RB->array\n    |  cmplw TMP0, RC\n    |   slwi TMP2, RC, 3\n    |.else\n    |   bge cr1, >5\n    |  // Convert number key to integer, check for integerness and range.\n    |  fctiwz f1, f0\n    |    fadd f2, f0, TOBIT\n    |  stfd f1, TMPD\n    |   lwz TMP0, TAB:RB->asize\n    |    fsub f2, f2, TOBIT\n    |  lwz TMP2, TMPD_LO\n    |   lwz TMP1, TAB:RB->array\n    |    fcmpu cr1, f0, f2\n    |  cmplw cr0, TMP0, TMP2\n    |  crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq\n    |   slwi TMP2, TMP2, 3\n    |.endif\n    |  ble ->vmeta_tgetv\t\t// Integer key and in array part?\n    |  lwzx TMP0, TMP1, TMP2\n    |.if FPU\n    |   lfdx f14, TMP1, TMP2\n    |.else\n    |   lwzux SAVE0, TMP1, TMP2\n    |   lwz SAVE1, 4(TMP1)\n    |.endif\n    |  checknil TMP0; beq >2\n    |1:\n    |  ins_next1\n    |.if FPU\n    |   stfdx f14, BASE, RA\n    |.else\n    |   stwux SAVE0, RA, BASE\n    |   stw SAVE1, 4(RA)\n    |.endif\n    |  ins_next2\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetv\n    |\n    |5:\n    |  checkstr CARG2; bne ->vmeta_tgetv\n    |.if not DUALNUM\n    |  lwz STR:RC, 4(RC)\n    |.endif\n    |  b ->BC_TGETS_Z\t\t\t// String key?\n    break;\n  case BC_TGETS:\n    |  // RA = dst*8, RB = table*8, RC = str_const*8 (~)\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP1, RC, 1\n    |    lwz TAB:RB, 4(RB)\n    |   subfic TMP1, TMP1, -4\n    |  checktab CARG1\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  bne ->vmeta_tgets1\n    |->BC_TGETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8\n    |  lwz TMP0, TAB:RB->hmask\n    |  lwz TMP1, STR:RC->sid\n    |  lwz NODE:TMP2, TAB:RB->node\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |  slwi TMP0, TMP1, 5\n    |  slwi TMP1, TMP1, 3\n    |  sub TMP1, TMP0, TMP1\n    |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lwz CARG1, NODE:TMP2->key\n    |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n    |    lwz CARG2, NODE:TMP2->val\n    |     lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)\n    |  checkstr CARG1; bne >4\n    |   cmpw TMP0, STR:RC; bne >4\n    |    checknil CARG2; beq >5\t\t// Key found, but nil value?\n    |3:\n    |    stwux CARG2, RA, BASE\n    |     stw TMP1, 4(RA)\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  lwz NODE:TMP2, NODE:TMP2->next\n    |  cmplwi NODE:TMP2, 0\n    |  bne <1\n    |  // End of hash chain: key not found, nil result.\n    |   li CARG2, LJ_TNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <3\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP2->nomm\n    |  andix. TMP0, TMP0, 1<<MM_index\n    |  bne <3\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgets\n    break;\n  case BC_TGETB:\n    |  // RA = dst*8, RB = table*8, RC = index*8\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP0, RC, 3\n    |   lwz TAB:RB, 4(RB)\n    |  checktab CARG1; bne ->vmeta_tgetb\n    |  lwz TMP1, TAB:RB->asize\n    |   lwz TMP2, TAB:RB->array\n    |  cmplw TMP0, TMP1; bge ->vmeta_tgetb\n    |.if FPU\n    |  lwzx TMP1, TMP2, RC\n    |   lfdx f0, TMP2, RC\n    |.else\n    |  lwzux TMP1, TMP2, RC\n    |   lwz TMP3, 4(TMP2)\n    |.endif\n    |  checknil TMP1; beq >5\n    |1:\n    |  ins_next1\n    |.if FPU\n    |   stfdx f0, BASE, RA\n    |.else\n    |   stwux TMP1, RA, BASE\n    |   stw TMP3, 4(RA)\n    |.endif\n    |  ins_next2\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_index\n    |  bne <1\t\t\t\t// 'no __index' flag set: done.\n    |  b ->vmeta_tgetb\t\t\t// Caveat: preserve TMP0!\n    break;\n  case BC_TGETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  add RB, BASE, RB\n    |  lwz TAB:CARG1, 4(RB)\n    |.if DUALNUM\n    |  add RC, BASE, RC\n    |  lwz TMP0, TAB:CARG1->asize\n    |  lwz CARG2, 4(RC)\n    |   lwz TMP1, TAB:CARG1->array\n    |.else\n    |  lfdx f0, BASE, RC\n    |  lwz TMP0, TAB:CARG1->asize\n    |  toint CARG2, f0\n    |   lwz TMP1, TAB:CARG1->array\n    |.endif\n    |  cmplw TMP0, CARG2\n    |   slwi TMP2, CARG2, 3\n    |  ble ->vmeta_tgetr\t\t// In array part?\n    |.if FPU\n    |   lfdx f14, TMP1, TMP2\n    |.else\n    |   lwzux SAVE0, TMP2, TMP1\n    |   lwz SAVE1, 4(TMP2)\n    |.endif\n    |->BC_TGETR_Z:\n    |  ins_next1\n    |.if FPU\n    |   stfdx f14, BASE, RA\n    |.else\n    |   stwux SAVE0, RA, BASE\n    |   stw SAVE1, 4(RA)\n    |.endif\n    |  ins_next2\n    break;\n\n  case BC_TSETV:\n    |  // RA = src*8, RB = table*8, RC = key*8\n    |  lwzux CARG1, RB, BASE\n    |  lwzux CARG2, RC, BASE\n    |   lwz TAB:RB, 4(RB)\n    |.if DUALNUM\n    |   lwz RC, 4(RC)\n    |.else\n    |   lfd f0, 0(RC)\n    |.endif\n    |  checktab CARG1\n    |   checknum cr1, CARG2\n    |  bne ->vmeta_tsetv\n    |.if DUALNUM\n    |  lwz TMP0, TAB:RB->asize\n    |   bne cr1, >5\n    |   lwz TMP1, TAB:RB->array\n    |  cmplw TMP0, RC\n    |   slwi TMP0, RC, 3\n    |.else\n    |   bge cr1, >5\n    |  // Convert number key to integer, check for integerness and range.\n    |  fctiwz f1, f0\n    |    fadd f2, f0, TOBIT\n    |  stfd f1, TMPD\n    |   lwz TMP0, TAB:RB->asize\n    |    fsub f2, f2, TOBIT\n    |  lwz TMP2, TMPD_LO\n    |   lwz TMP1, TAB:RB->array\n    |    fcmpu cr1, f0, f2\n    |  cmplw cr0, TMP0, TMP2\n    |  crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq\n    |   slwi TMP0, TMP2, 3\n    |.endif\n    |  ble ->vmeta_tsetv\t\t// Integer key and in array part?\n    |   lwzx TMP2, TMP1, TMP0\n    |  lbz TMP3, TAB:RB->marked\n    |.if FPU\n    |    lfdx f14, BASE, RA\n    |.else\n    |    add SAVE1, BASE, RA\n    |    lwz SAVE0, 0(SAVE1)\n    |    lwz SAVE1, 4(SAVE1)\n    |.endif\n    |   checknil TMP2; beq >3\n    |1:\n    |  andix. TMP2, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |.if FPU\n    |    stfdx f14, TMP1, TMP0\n    |.else\n    |    stwux SAVE0, TMP1, TMP0\n    |    stw SAVE1, 4(TMP1)\n    |.endif\n    |  bne >7\n    |2:\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP2, TAB:RB->metatable\n    |  cmplwi TAB:TMP2, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP2, TAB:TMP2->nomm\n    |  andix. TMP2, TMP2, 1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetv\n    |\n    |5:\n    |  checkstr CARG2; bne ->vmeta_tsetv\n    |.if not DUALNUM\n    |  lwz STR:RC, 4(RC)\n    |.endif\n    |  b ->BC_TSETS_Z\t\t\t// String key?\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <2\n    break;\n  case BC_TSETS:\n    |  // RA = src*8, RB = table*8, RC = str_const*8 (~)\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP1, RC, 1\n    |    lwz TAB:RB, 4(RB)\n    |   subfic TMP1, TMP1, -4\n    |  checktab CARG1\n    |   lwzx STR:RC, KBASE, TMP1\t// KBASE-4-str_const*4\n    |  bne ->vmeta_tsets1\n    |->BC_TSETS_Z:\n    |  // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8\n    |  lwz TMP0, TAB:RB->hmask\n    |  lwz TMP1, STR:RC->sid\n    |  lwz NODE:TMP2, TAB:RB->node\n    |    stb ZERO, TAB:RB->nomm\t\t// Clear metamethod cache.\n    |  and TMP1, TMP1, TMP0\t\t// idx = str->sid & tab->hmask\n    |.if FPU\n    |    lfdx f14, BASE, RA\n    |.else\n    |    add CARG2, BASE, RA\n    |    lwz SAVE0, 0(CARG2)\n    |    lwz SAVE1, 4(CARG2)\n    |.endif\n    |  slwi TMP0, TMP1, 5\n    |  slwi TMP1, TMP1, 3\n    |  sub TMP1, TMP0, TMP1\n    |    lbz TMP3, TAB:RB->marked\n    |  add NODE:TMP2, NODE:TMP2, TMP1\t// node = tab->node + (idx*32-idx*8)\n    |1:\n    |  lwz CARG1, NODE:TMP2->key\n    |   lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)\n    |    lwz CARG2, NODE:TMP2->val\n    |     lwz NODE:TMP1, NODE:TMP2->next\n    |  checkstr CARG1; bne >5\n    |   cmpw TMP0, STR:RC; bne >5\n    |    checknil CARG2; beq >4\t\t// Key found, but nil value?\n    |2:\n    |  andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |.if FPU\n    |    stfd f14, NODE:TMP2->val\n    |.else\n    |    stw SAVE0, NODE:TMP2->val.u32.hi\n    |    stw SAVE1, NODE:TMP2->val.u32.lo\n    |.endif\n    |  bne >7\n    |3:\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |  cmplwi TAB:TMP1, 0\n    |  beq <2\t\t\t\t// No metatable: done.\n    |  lbz TMP0, TAB:TMP1->nomm\n    |  andix. TMP0, TMP0, 1<<MM_newindex\n    |  bne <2\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsets\n    |\n    |5:  // Follow hash chain.\n    |  cmplwi NODE:TMP1, 0\n    |   mr NODE:TMP2, NODE:TMP1\n    |  bne <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |   la CARG3, DISPATCH_GL(tmptv)(DISPATCH)\n    |   stw PC, SAVE_PC\n    |   mr CARG1, L\n    |  cmplwi TAB:TMP1, 0\n    |   stp BASE, L->base\n    |  beq >6\t\t\t\t// No metatable: continue.\n    |  lbz TMP0, TAB:TMP1->nomm\n    |  andix. TMP0, TMP0, 1<<MM_newindex\n    |  beq ->vmeta_tsets\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  li TMP0, LJ_TSTR\n    |   stw STR:RC, 4(CARG3)\n    |   mr CARG2, TAB:RB\n    |  stw TMP0, 0(CARG3)\n    |  bl extern lj_tab_newkey\t\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Returns TValue *.\n    |  lp BASE, L->base\n    |.if FPU\n    |  stfd f14, 0(CRET1)\n    |.else\n    |  stw SAVE0, 0(CRET1)\n    |  stw SAVE1, 4(CRET1)\n    |.endif\n    |  b <3\t\t\t\t// No 2nd write barrier needed.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <3\n    break;\n  case BC_TSETB:\n    |  // RA = src*8, RB = table*8, RC = index*8\n    |  lwzux CARG1, RB, BASE\n    |   srwi TMP0, RC, 3\n    |   lwz TAB:RB, 4(RB)\n    |  checktab CARG1; bne ->vmeta_tsetb\n    |  lwz TMP1, TAB:RB->asize\n    |   lwz TMP2, TAB:RB->array\n    |    lbz TMP3, TAB:RB->marked\n    |  cmplw TMP0, TMP1\n    |.if FPU\n    |   lfdx f14, BASE, RA\n    |.else\n    |   add CARG2, BASE, RA\n    |   lwz SAVE0, 0(CARG2)\n    |   lwz SAVE1, 4(CARG2)\n    |.endif\n    |  bge ->vmeta_tsetb\n    |  lwzx TMP1, TMP2, RC\n    |  checknil TMP1; beq >5\n    |1:\n    |  andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |.if FPU\n    |   stfdx f14, TMP2, RC\n    |.else\n    |   stwux SAVE0, RC, TMP2\n    |   stw SAVE1, 4(RC)\n    |.endif\n    |  bne >7\n    |2:\n    |  ins_next\n    |\n    |5:  // Check for __newindex if previous value is nil.\n    |  lwz TAB:TMP1, TAB:RB->metatable\n    |  cmplwi TAB:TMP1, 0\n    |  beq <1\t\t\t\t// No metatable: done.\n    |  lbz TMP1, TAB:TMP1->nomm\n    |  andix. TMP1, TMP1, 1<<MM_newindex\n    |  bne <1\t\t\t\t// 'no __newindex' flag set: done.\n    |  b ->vmeta_tsetb\t\t\t// Caveat: preserve TMP0!\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMP3, TMP0\n    |  b <2\n    break;\n  case BC_TSETR:\n    |  // RA = dst*8, RB = table*8, RC = key*8\n    |  add RB, BASE, RB\n    |  lwz TAB:CARG2, 4(RB)\n    |.if DUALNUM\n    |  add RC, BASE, RC\n    |    lbz TMP3, TAB:CARG2->marked\n    |  lwz TMP0, TAB:CARG2->asize\n    |  lwz CARG3, 4(RC)\n    |   lwz TMP1, TAB:CARG2->array\n    |.else\n    |  lfdx f0, BASE, RC\n    |    lbz TMP3, TAB:CARG2->marked\n    |  lwz TMP0, TAB:CARG2->asize\n    |  toint CARG3, f0\n    |   lwz TMP1, TAB:CARG2->array\n    |.endif\n    |  andix. TMP2, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |  bne >7\n    |2:\n    |  cmplw TMP0, CARG3\n    |   slwi TMP2, CARG3, 3\n    |.if FPU\n    |   lfdx f14, BASE, RA\n    |.else\n    |  lwzux SAVE0, RA, BASE\n    |  lwz SAVE1, 4(RA)\n    |.endif\n    |  ble ->vmeta_tsetr\t\t// In array part?\n    |  ins_next1\n    |.if FPU\n    |   stfdx f14, TMP1, TMP2\n    |.else\n    |   stwux SAVE0, TMP1, TMP2\n    |   stw SAVE1, 4(TMP1)\n    |.endif\n    |  ins_next2\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP2\n    |  b <2\n    break;\n\n\n  case BC_TSETM:\n    |  // RA = base*8 (table at base-1), RD = num_const*8 (start index)\n    |  add RA, BASE, RA\n    |1:\n    |   add TMP3, KBASE, RD\n    |  lwz TAB:CARG2, -4(RA)\t\t// Guaranteed to be a table.\n    |    addic. TMP0, MULTRES, -8\n    |   lwz TMP3, 4(TMP3)\t\t// Integer constant is in lo-word.\n    |    srwi CARG3, TMP0, 3\n    |    beq >4\t\t\t\t// Nothing to copy?\n    |  add CARG3, CARG3, TMP3\n    |  lwz TMP2, TAB:CARG2->asize\n    |   slwi TMP1, TMP3, 3\n    |    lbz TMP3, TAB:CARG2->marked\n    |  cmplw CARG3, TMP2\n    |   add TMP2, RA, TMP0\n    |   lwz TMP0, TAB:CARG2->array\n    |  bgt >5\n    |   add TMP1, TMP1, TMP0\n    |    andix. TMP0, TMP3, LJ_GC_BLACK\t// isblack(table)\n    |3:  // Copy result slots to table.\n    |.if FPU\n    |   lfd f0, 0(RA)\n    |.else\n    |   lwz SAVE0, 0(RA)\n    |   lwz SAVE1, 4(RA)\n    |.endif\n    |  addi RA, RA, 8\n    |  cmpw cr1, RA, TMP2\n    |.if FPU\n    |   stfd f0, 0(TMP1)\n    |.else\n    |   stw SAVE0, 0(TMP1)\n    |   stw SAVE1, 4(TMP1)\n    |.endif\n    |    addi TMP1, TMP1, 8\n    |  blt cr1, <3\n    |  bne >7\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |   stp BASE, L->base\n    |  mr CARG1, L\n    |   stw PC, SAVE_PC\n    |  mr SAVE0, RD\n    |  bl extern lj_tab_reasize\t\t// (lua_State *L, GCtab *t, int nasize)\n    |  // Must not reallocate the stack.\n    |  mr RD, SAVE0\n    |  b <1\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:CARG2, TMP3, TMP0\n    |  b <4\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALLM:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8\n    |  add NARGS8:RC, NARGS8:RC, MULTRES\n    |  // Fall through. Assumes BC_CALL follows.\n    break;\n  case BC_CALL:\n    |  // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8\n    |  mr TMP2, BASE\n    |  lwzux TMP0, BASE, RA\n    |   lwz LFUNC:RB, 4(BASE)\n    |    subi NARGS8:RC, NARGS8:RC, 8\n    |   addi BASE, BASE, 8\n    |  checkfunc TMP0; bne ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  // RA = base*8, (RB = 0,) RC = extra_nargs*8\n    |  add NARGS8:RC, NARGS8:RC, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows.\n    break;\n  case BC_CALLT:\n    |  // RA = base*8, (RB = 0,) RC = (nargs+1)*8\n    |  lwzux TMP0, RA, BASE\n    |   lwz LFUNC:RB, 4(RA)\n    |    subi NARGS8:RC, NARGS8:RC, 8\n    |    lwz TMP1, FRAME_PC(BASE)\n    |  checkfunc TMP0\n    |   addi RA, RA, 8\n    |  bne ->vmeta_callt\n    |->BC_CALLT_Z:\n    |  andix. TMP0, TMP1, FRAME_TYPE\t// Caveat: preserve cr0 until the crand.\n    |   lbz TMP3, LFUNC:RB->ffid\n    |    xori TMP2, TMP1, FRAME_VARG\n    |    cmplwi cr1, NARGS8:RC, 0\n    |  bne >7\n    |1:\n    |  stw LFUNC:RB, FRAME_FUNC(BASE)\t// Copy function down, but keep PC.\n    |  li TMP2, 0\n    |   cmplwi cr7, TMP3, 1\t\t// (> FF_C) Calling a fast function?\n    |    beq cr1, >3\n    |2:\n    |  addi TMP3, TMP2, 8\n    |.if FPU\n    |   lfdx f0, RA, TMP2\n    |.else\n    |   add CARG3, RA, TMP2\n    |   lwz CARG1, 0(CARG3)\n    |   lwz CARG2, 4(CARG3)\n    |.endif\n    |  cmplw cr1, TMP3, NARGS8:RC\n    |.if FPU\n    |   stfdx f0, BASE, TMP2\n    |.else\n    |   stwux CARG1, TMP2, BASE\n    |   stw CARG2, 4(TMP2)\n    |.endif\n    |  mr TMP2, TMP3\n    |  bne cr1, <2\n    |3:\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt\n    |  beq >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function with a Lua frame below.\n    |  lwz INS, -4(TMP1)\n    |  decode_RA8 RA, INS\n    |  sub TMP1, BASE, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1)\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\t// Need to prepare KBASE.\n    |  b <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  andix. TMP0, TMP2, FRAME_TYPEP\n    |  bne <1\t\t\t\t// Vararg frame below?\n    |  sub BASE, BASE, TMP2\t\t// Relocate BASE down.\n    |  lwz TMP1, FRAME_PC(BASE)\n    |  andix. TMP0, TMP1, FRAME_TYPE\n    |  b <1\n    break;\n\n  case BC_ITERC:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))\n    |  mr TMP2, BASE\n    |  add BASE, BASE, RA\n    |  lwz TMP1, -24(BASE)\n    |   lwz LFUNC:RB, -20(BASE)\n    |.if FPU\n    |    lfd f1, -8(BASE)\n    |    lfd f0, -16(BASE)\n    |.else\n    |    lwz CARG1, -8(BASE)\n    |    lwz CARG2, -4(BASE)\n    |    lwz CARG3, -16(BASE)\n    |    lwz CARG4, -12(BASE)\n    |.endif\n    |  stw TMP1, 0(BASE)\t\t// Copy callable.\n    |   stw LFUNC:RB, 4(BASE)\n    |  checkfunc TMP1\n    |     li NARGS8:RC, 16\t\t// Iterators get 2 arguments.\n    |.if FPU\n    |    stfd f1, 16(BASE)\t\t// Copy control var.\n    |    stfdu f0, 8(BASE)\t\t// Copy state.\n    |.else\n    |    stw CARG1, 16(BASE)\t\t// Copy control var.\n    |    stw CARG2, 20(BASE)\n    |    stwu CARG3, 8(BASE)\t\t// Copy state.\n    |    stw CARG4, 4(BASE)\n    |.endif\n    |  bne ->vmeta_call\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)\n    |.if JIT\n    |  // NYI on big-endian\n    |.endif\n    |->vm_IITERN:\n    |  add RA, BASE, RA\n    |  lwz TAB:RB, -12(RA)\n    |  lwz RC, -4(RA)\t\t\t// Get index from control var.\n    |  lwz TMP0, TAB:RB->asize\n    |  lwz TMP1, TAB:RB->array\n    |   addi PC, PC, 4\n    |1:  // Traverse array part.\n    |  cmplw RC, TMP0\n    |   slwi TMP3, RC, 3\n    |  bge >5\t\t\t\t// Index points after array part?\n    |  lwzx TMP2, TMP1, TMP3\n    |.if FPU\n    |   lfdx f0, TMP1, TMP3\n    |.else\n    |   lwzux CARG1, TMP3, TMP1\n    |   lwz CARG2, 4(TMP3)\n    |.endif\n    |  checknil TMP2\n    |     lwz INS, -4(PC)\n    |  beq >4\n    |.if DUALNUM\n    |   stw RC, 4(RA)\n    |   stw TISNUM, 0(RA)\n    |.else\n    |   tonum_u f1, RC\n    |.endif\n    |    addi RC, RC, 1\n    |     addis TMP3, PC, -(BCBIAS_J*4 >> 16)\n    |.if FPU\n    |  stfd f0, 8(RA)\n    |.else\n    |  stw CARG1, 8(RA)\n    |  stw CARG2, 12(RA)\n    |.endif\n    |     decode_RD4 TMP1, INS\n    |    stw RC, -4(RA)\t\t\t// Update control var.\n    |     add PC, TMP1, TMP3\n    |.if not DUALNUM\n    |   stfd f1, 0(RA)\n    |.endif\n    |3:\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  addi RC, RC, 1\n    |  b <1\n    |\n    |5:  // Traverse hash part.\n    |  lwz TMP1, TAB:RB->hmask\n    |  sub RC, RC, TMP0\n    |   lwz TMP2, TAB:RB->node\n    |6:\n    |  cmplw RC, TMP1\t\t\t// End of iteration? Branch to ITERL+1.\n    |   slwi TMP3, RC, 5\n    |  bgty <3\n    |   slwi RB, RC, 3\n    |   sub TMP3, TMP3, RB\n    |  lwzx RB, TMP2, TMP3\n    |.if FPU\n    |  lfdx f0, TMP2, TMP3\n    |.else\n    |  add CARG3, TMP2, TMP3\n    |  lwz CARG1, 0(CARG3)\n    |  lwz CARG2, 4(CARG3)\n    |.endif\n    |   add NODE:TMP3, TMP2, TMP3\n    |  checknil RB\n    |     lwz INS, -4(PC)\n    |  beq >7\n    |.if FPU\n    |   lfd f1, NODE:TMP3->key\n    |.else\n    |   lwz CARG3, NODE:TMP3->key.u32.hi\n    |   lwz CARG4, NODE:TMP3->key.u32.lo\n    |.endif\n    |     addis TMP2, PC, -(BCBIAS_J*4 >> 16)\n    |.if FPU\n    |  stfd f0, 8(RA)\n    |.else\n    |  stw CARG1, 8(RA)\n    |  stw CARG2, 12(RA)\n    |.endif\n    |    add RC, RC, TMP0\n    |     decode_RD4 TMP1, INS\n    |.if FPU\n    |   stfd f1, 0(RA)\n    |.else\n    |   stw CARG3, 0(RA)\n    |   stw CARG4, 4(RA)\n    |.endif\n    |    addi RC, RC, 1\n    |     add PC, TMP1, TMP2\n    |    stw RC, -4(RA)\t\t\t// Update control var.\n    |  b <3\n    |\n    |7:  // Skip holes in hash part.\n    |  addi RC, RC, 1\n    |  b <6\n    break;\n\n  case BC_ISNEXT:\n    |  // RA = base*8, RD = target (points to ITERN)\n    |  add RA, BASE, RA\n    |  lwz TMP0, -24(RA)\n    |  lwz CFUNC:TMP1, -20(RA)\n    |   lwz TMP2, -16(RA)\n    |    lwz TMP3, -8(RA)\n    |   cmpwi cr0, TMP2, LJ_TTAB\n    |  cmpwi cr1, TMP0, LJ_TFUNC\n    |    cmpwi cr6, TMP3, LJ_TNIL\n    |  bne cr1, >5\n    |  lbz TMP1, CFUNC:TMP1->ffid\n    |   crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq\n    |  cmpwi cr7, TMP1, FF_next_N\n    |    srwi TMP0, RD, 1\n    |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq\n    |    add TMP3, PC, TMP0\n    |  bne cr0, >5\n    |  lus TMP1, (LJ_KEYINDEX >> 16)\n    |  ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff)\n    |  stw ZERO, -4(RA)\t\t\t// Initialize control var.\n    |  stw TMP1, -8(RA)\n    |    addis PC, TMP3, -(BCBIAS_J*4 >> 16)\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  li TMP0, BC_JMP\n    |   li TMP1, BC_ITERC\n    |  stb TMP0, -1(PC)\n    |    addis PC, TMP3, -(BCBIAS_J*4 >> 16)\n    |  // NYI on big-endian: unpatch JLOOP.\n    |   stb TMP1, 3(PC)\n    |  b <1\n    break;\n\n  case BC_VARG:\n    |  // RA = base*8, RB = (nresults+1)*8, RC = numparams*8\n    |  lwz TMP0, FRAME_PC(BASE)\n    |  add RC, BASE, RC\n    |   add RA, BASE, RA\n    |  addi RC, RC, FRAME_VARG\n    |   add TMP2, RA, RB\n    |  subi TMP3, BASE, 8\t\t// TMP3 = vtop\n    |  sub RC, RC, TMP0\t\t\t// RC = vbase\n    |  // Note: RC may now be even _above_ BASE if nargs was < numparams.\n    |  cmplwi cr1, RB, 0\n    |.if PPE\n    |   sub TMP1, TMP3, RC\n    |   cmpwi TMP1, 0\n    |.else\n    |   sub. TMP1, TMP3, RC\n    |.endif\n    |  beq cr1, >5\t\t\t// Copy all varargs?\n    |   subi TMP2, TMP2, 16\n    |   ble >2\t\t\t\t// No vararg slots?\n    |1:  // Copy vararg slots to destination slots.\n    |.if FPU\n    |  lfd f0, 0(RC)\n    |.else\n    |  lwz CARG1, 0(RC)\n    |  lwz CARG2, 4(RC)\n    |.endif\n    |   addi RC, RC, 8\n    |.if FPU\n    |  stfd f0, 0(RA)\n    |.else\n    |  stw CARG1, 0(RA)\n    |  stw CARG2, 4(RA)\n    |.endif\n    |  cmplw RA, TMP2\n    |   cmplw cr1, RC, TMP3\n    |  bge >3\t\t\t\t// All destination slots filled?\n    |    addi RA, RA, 8\n    |   blt cr1, <1\t\t\t// More vararg slots?\n    |2:  // Fill up remainder with nil.\n    |  stw TISNIL, 0(RA)\n    |  cmplw RA, TMP2\n    |   addi RA, RA, 8\n    |  blt <2\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  lwz TMP0, L->maxstack\n    |   li MULTRES, 8\t\t\t// MULTRES = (0+1)*8\n    |  bley <3\t\t\t\t// No vararg slots?\n    |  add TMP2, RA, TMP1\n    |  cmplw TMP2, TMP0\n    |   addi MULTRES, TMP1, 8\n    |  bgt >7\n    |6:\n    |.if FPU\n    |  lfd f0, 0(RC)\n    |.else\n    |  lwz CARG1, 0(RC)\n    |  lwz CARG2, 4(RC)\n    |.endif\n    |   addi RC, RC, 8\n    |.if FPU\n    |  stfd f0, 0(RA)\n    |.else\n    |  stw CARG1, 0(RA)\n    |  stw CARG2, 4(RA)\n    |.endif\n    |  cmplw RC, TMP3\n    |   addi RA, RA, 8\n    |  blt <6\t\t\t\t// More vararg slots?\n    |  b <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mr CARG1, L\n    |   stp RA, L->top\n    |  sub SAVE0, RC, BASE\t\t// Need delta, because BASE may change.\n    |   stp BASE, L->base\n    |  sub RA, RA, BASE\n    |   stw PC, SAVE_PC\n    |  srwi CARG2, TMP1, 3\n    |  bl extern lj_state_growstack\t// (lua_State *L, int n)\n    |  lp BASE, L->base\n    |  add RA, BASE, RA\n    |  add RC, BASE, SAVE0\n    |  subi TMP3, BASE, 8\n    |  b <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  // RA = results*8, RD = extra_nresults*8\n    |  add RD, RD, MULTRES\t\t// MULTRES >= 8, so RD >= 8.\n    |  // Fall through. Assumes BC_RET follows.\n    break;\n\n  case BC_RET:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lwz PC, FRAME_PC(BASE)\n    |   add RA, BASE, RA\n    |    mr MULTRES, RD\n    |1:\n    |  andix. TMP0, PC, FRAME_TYPE\n    |   xori TMP1, PC, FRAME_VARG\n    |  bne ->BC_RETV_Z\n    |\n    |->BC_RET_Z:\n    |  // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return\n    |   lwz INS, -4(PC)\n    |  cmpwi RD, 8\n    |   subi TMP2, BASE, 8\n    |   subi RC, RD, 8\n    |   decode_RB8 RB, INS\n    |  beq >3\n    |   li TMP1, 0\n    |2:\n    |  addi TMP3, TMP1, 8\n    |.if FPU\n    |   lfdx f0, RA, TMP1\n    |.else\n    |   add CARG3, RA, TMP1\n    |   lwz CARG1, 0(CARG3)\n    |   lwz CARG2, 4(CARG3)\n    |.endif\n    |  cmpw TMP3, RC\n    |.if FPU\n    |   stfdx f0, TMP2, TMP1\n    |.else\n    |   add CARG3, TMP2, TMP1\n    |   stw CARG1, 0(CARG3)\n    |   stw CARG2, 4(CARG3)\n    |.endif\n    |  beq >3\n    |  addi TMP1, TMP3, 8\n    |.if FPU\n    |   lfdx f1, RA, TMP3\n    |.else\n    |   add CARG3, RA, TMP3\n    |   lwz CARG1, 0(CARG3)\n    |   lwz CARG2, 4(CARG3)\n    |.endif\n    |  cmpw TMP1, RC\n    |.if FPU\n    |   stfdx f1, TMP2, TMP3\n    |.else\n    |   add CARG3, TMP2, TMP3\n    |   stw CARG1, 0(CARG3)\n    |   stw CARG2, 4(CARG3)\n    |.endif\n    |  bne <2\n    |3:\n    |5:\n    |  cmplw RB, RD\n    |   decode_RA8 RA, INS\n    |  bgt >6\n    |   sub BASE, TMP2, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  subi TMP1, RD, 8\n    |   addi RD, RD, 8\n    |  stwx TISNIL, TMP2, TMP1\n    |  b <5\n    |\n    |->BC_RETV_Z:  // Non-standard return case.\n    |  andix. TMP2, TMP1, FRAME_TYPEP\n    |  bne ->vm_return\n    |  // Return from vararg function: relocate BASE down.\n    |  sub BASE, BASE, TMP1\n    |  lwz PC, FRAME_PC(BASE)\n    |  b <1\n    break;\n\n  case BC_RET0: case BC_RET1:\n    |  // RA = results*8, RD = (nresults+1)*8\n    |  lwz PC, FRAME_PC(BASE)\n    |   add RA, BASE, RA\n    |    mr MULTRES, RD\n    |  andix. TMP0, PC, FRAME_TYPE\n    |   xori TMP1, PC, FRAME_VARG\n    |  bney ->BC_RETV_Z\n    |\n    |  lwz INS, -4(PC)\n    |   subi TMP2, BASE, 8\n    |  decode_RB8 RB, INS\n    if (op == BC_RET1) {\n      |.if FPU\n      |  lfd f0, 0(RA)\n      |  stfd f0, 0(TMP2)\n      |.else\n      |  lwz CARG1, 0(RA)\n      |  lwz CARG2, 4(RA)\n      |  stw CARG1, 0(TMP2)\n      |  stw CARG2, 4(TMP2)\n      |.endif\n    }\n    |5:\n    |  cmplw RB, RD\n    |   decode_RA8 RA, INS\n    |  bgt >6\n    |   sub BASE, TMP2, RA\n    |  lwz LFUNC:TMP1, FRAME_FUNC(BASE)\n    |  ins_next1\n    |  lwz TMP1, LFUNC:TMP1->pc\n    |  lwz KBASE, PC2PROTO(k)(TMP1)\n    |  ins_next2\n    |\n    |6:  // Fill up results with nil.\n    |  subi TMP1, RD, 8\n    |   addi RD, RD, 8\n    |  stwx TISNIL, TMP2, TMP1\n    |  b <5\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IFORL follows.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    |  // RA = base*8, RD = target (after end of loop or start of loop)\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |.if DUALNUM\n    |  // Integer loop.\n    |  lwzux TMP1, RA, BASE\n    |   lwz CARG1, FORL_IDX*8+4(RA)\n    |  cmplw cr0, TMP1, TISNUM\n    if (vk) {\n      |   lwz CARG3, FORL_STEP*8+4(RA)\n      |  bne >9\n      |.if GPR64\n      |  // Need to check overflow for (a<<32) + (b<<32).\n      |  rldicr TMP0, CARG1, 32, 31\n      |  rldicr TMP2, CARG3, 32, 31\n      |  add CARG1, CARG1, CARG3\n      |  addo. TMP0, TMP0, TMP2\n      |.else\n      |  addo. CARG1, CARG1, CARG3\n      |.endif\n      |    cmpwi cr6, CARG3, 0\n      |   lwz CARG2, FORL_STOP*8+4(RA)\n      |  bso >6\n      |4:\n      |  stw CARG1, FORL_IDX*8+4(RA)\n    } else {\n      |  lwz SAVE0, FORL_STEP*8(RA)\n      |   lwz CARG3, FORL_STEP*8+4(RA)\n      |  lwz TMP2, FORL_STOP*8(RA)\n      |   lwz CARG2, FORL_STOP*8+4(RA)\n      |  cmplw cr7, SAVE0, TISNUM\n      |  cmplw cr1, TMP2, TISNUM\n      |  crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq\n      |  crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq\n      |    cmpwi cr6, CARG3, 0\n      |  bne >9\n    }\n    |    blt cr6, >5\n    |  cmpw CARG1, CARG2\n    |1:\n    |   stw TISNUM, FORL_EXT*8(RA)\n    if (op != BC_JFORL) {\n      |  srwi RD, RD, 1\n    }\n    |   stw CARG1, FORL_EXT*8+4(RA)\n    if (op != BC_JFORL) {\n      |  add RD, PC, RD\n    }\n    if (op == BC_FORI) {\n      |  bgt >3  // See FP loop below.\n    } else if (op == BC_JFORI) {\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n      |  bley >7\n    } else if (op == BC_IFORL) {\n      |  bgt >2\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else {\n      |  bley =>BC_JLOOP\n    }\n    |2:\n    |  ins_next\n    |5:  // Invert check for negative step.\n    |  cmpw CARG2, CARG1\n    |  b <1\n    if (vk) {\n      |6:  // Potential overflow.\n      |  checkov TMP0, <4\t\t// Ignore unrelated overflow.\n      |  b <2\n    }\n    |.endif\n    if (vk) {\n      |.if DUALNUM\n      |9:  // FP loop.\n      |.if FPU\n      |  lfd f1, FORL_IDX*8(RA)\n      |.else\n      |  lwz CARG1, FORL_IDX*8(RA)\n      |  lwz CARG2, FORL_IDX*8+4(RA)\n      |.endif\n      |.else\n      |  lfdux f1, RA, BASE\n      |.endif\n      |.if FPU\n      |  lfd f3, FORL_STEP*8(RA)\n      |  lfd f2, FORL_STOP*8(RA)\n      |  fadd f1, f1, f3\n      |  stfd f1, FORL_IDX*8(RA)\n      |.else\n      |  lwz CARG3, FORL_STEP*8(RA)\n      |  lwz CARG4, FORL_STEP*8+4(RA)\n      |  mr SAVE1, RD\n      |  blex __adddf3\n      |  mr RD, SAVE1\n      |  stw CRET1, FORL_IDX*8(RA)\n      |  stw CRET2, FORL_IDX*8+4(RA)\n      |  lwz CARG3, FORL_STOP*8(RA)\n      |  lwz CARG4, FORL_STOP*8+4(RA)\n      |.endif\n      |   lwz SAVE0, FORL_STEP*8(RA)\n    } else {\n      |.if DUALNUM\n      |9:  // FP loop.\n      |.else\n      |  lwzux TMP1, RA, BASE\n      |  lwz SAVE0, FORL_STEP*8(RA)\n      |  lwz TMP2, FORL_STOP*8(RA)\n      |  cmplw cr0, TMP1, TISNUM\n      |  cmplw cr7, SAVE0, TISNUM\n      |  cmplw cr1, TMP2, TISNUM\n      |.endif\n      |.if FPU\n      |   lfd f1, FORL_IDX*8(RA)\n      |.else\n      |   lwz CARG1, FORL_IDX*8(RA)\n      |   lwz CARG2, FORL_IDX*8+4(RA)\n      |.endif\n      |  crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt\n      |  crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt\n      |.if FPU\n      |   lfd f2, FORL_STOP*8(RA)\n      |.else\n      |   lwz CARG3, FORL_STOP*8(RA)\n      |   lwz CARG4, FORL_STOP*8+4(RA)\n      |.endif\n      |  bge ->vmeta_for\n    }\n    |  cmpwi cr6, SAVE0, 0\n    if (op != BC_JFORL) {\n      |  srwi RD, RD, 1\n    }\n    |.if FPU\n    |   stfd f1, FORL_EXT*8(RA)\n    |.else\n    |   stw CARG1, FORL_EXT*8(RA)\n    |   stw CARG2, FORL_EXT*8+4(RA)\n    |.endif\n    if (op != BC_JFORL) {\n      |  add RD, PC, RD\n    }\n    |.if FPU\n    |  fcmpu cr0, f1, f2\n    |.else\n    |  mr SAVE1, RD\n    |  blex __ledf2\n    |  cmpwi CRET1, 0\n    |  mr RD, SAVE1\n    |.endif\n    if (op == BC_JFORI) {\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    }\n    |  blt cr6, >5\n    if (op == BC_FORI) {\n      |  bgt >3\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  bgty <2\n      |.else\n      |  bgt >2\n      |.endif\n      |1:\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else if (op == BC_JFORI) {\n      |  bley >7\n    } else {\n      |  bley =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  b <2\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |5:  // Negative step.\n    if (op == BC_FORI) {\n      |  bge <2\n      |3:  // Used by integer loop, too.\n      |  addis PC, RD, -(BCBIAS_J*4 >> 16)\n    } else if (op == BC_IFORL) {\n      |  bgey <1\n    } else if (op == BC_JFORI) {\n      |  bgey >7\n    } else {\n      |  bgey =>BC_JLOOP\n    }\n    |  b <2\n    if (op == BC_JFORI) {\n      |7:\n      |  lwz INS, -4(PC)\n      |  decode_RD8 RD, INS\n      |  b =>BC_JLOOP\n    }\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_IITERL follows.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  // RA = base*8, RD = target\n    |  lwzux TMP1, RA, BASE\n    |   lwz TMP2, 4(RA)\n    |  checknil TMP1; beq >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  stw TMP1, -8(RA)\n      |   stw TMP2, -4(RA)\n      |  b =>BC_JLOOP\n    } else {\n      |  branch_RD\t\t\t// Otherwise save control var + branch.\n      |  stw TMP1, -8(RA)\n      |   stw TMP2, -4(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop\n    |.endif\n    |  // Fall through. Assumes BC_ILOOP follows.\n    break;\n\n  case BC_ILOOP:\n    |  // RA = base*8, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  // RA = base*8 (ignored), RD = traceno*8\n    |  lwz TMP1, DISPATCH_J(trace)(DISPATCH)\n    |  srwi RD, RD, 1\n    |  // Traces on PPC don't store the trace number, so use 0.\n    |   stw ZERO, DISPATCH_GL(vmstate)(DISPATCH)\n    |  lwzx TRACE:TMP2, TMP1, RD\n    |  clrso TMP1\n    |  lp TMP2, TRACE:TMP2->mcode\n    |   stw BASE, DISPATCH_GL(jit_base)(DISPATCH)\n    |  mtctr TMP2\n    |   addi JGL, DISPATCH, GG_DISP2G+32768\n    |   stw L, DISPATCH_GL(tmpbuf.L)(DISPATCH)\n    |  bctr\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  // RA = base*8 (only used by trace recorder), RD = target\n    |  branch_RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    |  // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lwz TMP2, L->maxstack\n    |   lbz TMP1, -4+PC2PROTO(numparams)(PC)\n    |    lwz KBASE, -4+PC2PROTO(k)(PC)\n    |  cmplw RA, TMP2\n    |   slwi TMP1, TMP1, 3\n    |  bgt ->vm_growstack_l\n    if (op != BC_JFUNCF) {\n      |  ins_next1\n    }\n    |2:\n    |  cmplw NARGS8:RC, TMP1\t\t// Check for missing parameters.\n    |  blt >3\n    if (op == BC_JFUNCF) {\n      |  decode_RD8 RD, INS\n      |  b =>BC_JLOOP\n    } else {\n      |  ins_next2\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  stwx TISNIL, BASE, NARGS8:RC\n    |  addi NARGS8:RC, NARGS8:RC, 8\n    |  b <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    |  NYI  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8\n    |  lwz TMP2, L->maxstack\n    |   add TMP1, BASE, RC\n    |  add TMP0, RA, RC\n    |   stw LFUNC:RB, 4(TMP1)\t\t// Store copy of LFUNC.\n    |   addi TMP3, RC, 8+FRAME_VARG\n    |    lwz KBASE, -4+PC2PROTO(k)(PC)\n    |  cmplw TMP0, TMP2\n    |   stw TMP3, 0(TMP1)\t\t// Store delta + FRAME_VARG.\n    |  bge ->vm_growstack_l\n    |  lbz TMP2, -4+PC2PROTO(numparams)(PC)\n    |   mr RA, BASE\n    |   mr RC, TMP1\n    |  ins_next1\n    |  cmpwi TMP2, 0\n    |   addi BASE, TMP1, 8\n    |  beq >3\n    |1:\n    |  cmplw RA, RC\t\t\t// Less args than parameters?\n    |   lwz TMP0, 0(RA)\n    |   lwz TMP3, 4(RA)\n    |  bge >4\n    |    stw TISNIL, 0(RA)\t\t// Clear old fixarg slot (help the GC).\n    |    addi RA, RA, 8\n    |2:\n    |  addic. TMP2, TMP2, -1\n    |   stw TMP0, 8(TMP1)\n    |   stw TMP3, 12(TMP1)\n    |    addi TMP1, TMP1, 8\n    |  bne <1\n    |3:\n    |  ins_next2\n    |\n    |4:  // Clear missing parameters.\n    |  li TMP0, LJ_TNIL\n    |  b <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8\n    if (op == BC_FUNCC) {\n      |  lp RD, CFUNC:RB->f\n    } else {\n      |  lp RD, DISPATCH_GL(wrapf)(DISPATCH)\n    }\n    |   add TMP1, RA, NARGS8:RC\n    |   lwz TMP2, L->maxstack\n    |  .toc lp TMP3, 0(RD)\n    |    add RC, BASE, NARGS8:RC\n    |   stp BASE, L->base\n    |   cmplw TMP1, TMP2\n    |    stp RC, L->top\n    |     li_vmstate C\n    |.if TOC\n    |  mtctr TMP3\n    |.else\n    |  mtctr RD\n    |.endif\n    if (op == BC_FUNCCW) {\n      |  lp CARG2, CFUNC:RB->f\n    }\n    |  mr CARG1, L\n    |   bgt ->vm_growstack_c\t\t// Need to grow stack.\n    |  .toc lp TOCREG, TOC_OFS(RD)\n    |  .tocenv lp ENVREG, ENV_OFS(RD)\n    |     st_vmstate\n    |  bctrl\t\t\t\t// (lua_State *L [, lua_CFunction f])\n    |  // Returns nresults.\n    |  lp BASE, L->base\n    |  .toc ld TOCREG, SAVE_TOC\n    |   slwi RD, CRET1, 3\n    |  lp TMP1, L->top\n    |    li_vmstate INTERP\n    |  lwz PC, FRAME_PC(BASE)\t\t// Fetch PC of caller.\n    |    stw L, DISPATCH_GL(cur_L)(DISPATCH)\n    |   sub RA, TMP1, RD\t\t// RA = L->top - nresults*8\n    |    st_vmstate\n    |  b ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n\n  dasm_growpc(Dst, BC__MAX);\n\n  build_subroutines(ctx);\n\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  int i;\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x5\\n\\t.uleb128 70\\n\\t.uleb128 55\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 14; i <= 31; i++)\n      fprintf(ctx->fp,\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\",\n\t0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE0:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_TARGET_PS3\n\t\"\\t.long .lj_vm_ffi_call\\n\"\n#else\n\t\"\\t.long lj_vm_ffi_call\\n\"\n#endif\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x8e\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xe\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x5\\n\\t.uleb128 70\\n\\t.uleb128 55\\n\",\n\tfcofs, CFRAME_SIZE);\n    for (i = 14; i <= 31; i++)\n      fprintf(ctx->fp,\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\"\n\t\"\\t.byte %d\\n\\t.uleb128 %d\\n\",\n\t0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));\n    fprintf(ctx->fp,\n\t\"\\t.align 2\\n\"\n\t\".LEFDE2:\\n\\n\");\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -4\\n\"\n\t\"\\t.byte 65\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 1\\n\\t.uleb128 0\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x11\\n\\t.uleb128 65\\n\\t.sleb128 -1\\n\"\n\t\"\\t.byte 0x8e\\n\\t.uleb128 2\\n\"\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xe\\n\"\n\t\"\\t.align 2\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n  default:\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_s390x.dasc",
    "content": "|// Low-level VM code for IBM z/Architecture (s390x) CPUs in LJ_GC64 mode.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h\n|\n|// This assembly targets the instruction set available on z10 (and newer)\n|// machines.\n|\n|// ELF ABI registers:\n|// r0,r1       |                            | volatile |\n|// r2          | parameter and return value | volatile |\n|// r3-r5       | parameter                  | volatile |\n|// r6          | parameter                  | saved    |\n|// r7-r11      |                            | saved    |\n|// r12         | GOT pointer (needed?)      | saved    |\n|// r13         | literal pool (not needed)  | saved    |\n|// r14         | return address             | volatile |\n|// r15         | stack pointer              | saved    |\n|// f0,f2,f4,f6 | parameter and return value | volatile |\n|// f1,f3,f5,f7 |                            | volatile |\n|// f8-f15      |                            | saved    |\n|// ar0,ar1     | TLS                        | volatile |\n|// ar2-ar15    |                            | volatile |\n|\n|.arch s390x\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|//-----------------------------------------------------------------------\n|\n|// Fixed register assignments for the interpreter, callee-saved.\n|.define KBASE,\t\t\tr8\t// Constants of current Lua function.\n|.define PC,\t\t\tr9\t// Next PC.\n|.define DISPATCH,\t\tr10\t// Opcode dispatch table.\n|.define ITYPE,\t\t\tr11\t// Temporary used for type information.\n|.define BASE,\t\t\tr13\t// Base of current Lua stack frame.\n|\n|// The following temporaries are not saved across C calls, except for RB.\n|.define RA,\t\t\tr4\t// Overlaps CARG3.\n|.define RB,\t\t\tr7\t// Must be callee-save.\n|.define RC,\t\t\tr5\t// Overlaps CARG4.\n|.define RD,\t\t\tr6\t// Overlaps CARG5.\n|\n|// Calling conventions. Also used as temporaries.\n|.define CARG1,\t\t\tr2\n|.define CARG2,\t\t\tr3\n|.define CARG3,\t\t\tr4\n|.define CARG4,\t\t\tr5\n|.define CARG5,\t\t\tr6\n|\n|.define FARG1,\t\t\tf0\n|.define FARG2,\t\t\tf2\n|.define FARG3,\t\t\tf4\n|.define FARG4,\t\t\tf6\n|\n|.define CRET1,\t\t\tr2\n|\n|.define TMPR0,\t\t\tr0\n|.define TMPR1,\t\t\tr1\n|.define OP,\t\t\tr2\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|.define CFRAME_SPACE,\t240\t// Delta for sp, 8 byte aligned.\n|\n|// Register save area.\n|.define SAVE_GPRS,\t288(sp)\t// Save area for r6-r15 (10*8 bytes).\n|.define SAVE_GPRS_P,\t48(sp)  // Save area for r6-r15 (10*8 bytes) in prologue (before stack frame is allocated).\n|\n|// Argument save area.\n|.define SAVE_ERRF,\t280(sp) // Argument 4, in r5.\n|.define SAVE_NRES,\t272(sp)\t// Argument 3, in r4. Size is 4-bytes.\n|.define SAVE_CFRAME,\t264(sp)\t// Argument 2, in r3.\n|.define SAVE_L,\t256(sp)\t// Argument 1, in r2.\n|.define RESERVED,\t248(sp)\t// Reserved for compiler use.\n|.define BACKCHAIN,\t240(sp)\t// <- sp entering interpreter.\n|\n|// Interpreter stack frame.\n|.define SAVE_FPR15,\t232(sp)\n|.define SAVE_FPR14,\t224(sp)\n|.define SAVE_FPR13,\t216(sp)\n|.define SAVE_FPR12,\t208(sp)\n|.define SAVE_FPR11,\t200(sp)\n|.define SAVE_FPR10,\t192(sp)\n|.define SAVE_FPR9,\t184(sp)\n|.define SAVE_FPR8,\t176(sp)\n|.define SAVE_PC,\t168(sp)\n|.define SAVE_MULTRES,\t160(sp)\n|.define SAVE_TMP,\t160(sp) // Overlaps SAVE_MULTRES\n|.define SAVE_TMP_HI,\t164(sp) // High 32-bits (to avoid SAVE_MULTRES).\n|\n|// Callee save area (allocated by interpreter).\n|.define CALLEESAVE,\t000(sp) // <- sp in interpreter.\n|\n|.macro saveregs\n|  stmg r6, r15, SAVE_GPRS_P\n|  lay sp, -CFRAME_SPACE(sp)\t// Allocate stack frame.\n|  std f8, SAVE_FPR8\t\t// f8-f15 are callee-saved.\n|  std f9, SAVE_FPR9\n|  std f10, SAVE_FPR10\n|  std f11, SAVE_FPR11\n|  std f12, SAVE_FPR12\n|  std f13, SAVE_FPR13\n|  std f14, SAVE_FPR14\n|  std f15, SAVE_FPR15\n|.endmacro\n|\n|.macro restoreregs\n|  ld f8, SAVE_FPR8\t\t// f8-f15 are callee-saved.\n|  ld f9, SAVE_FPR9\n|  ld f10, SAVE_FPR10\n|  ld f11, SAVE_FPR11\n|  ld f12, SAVE_FPR12\n|  ld f13, SAVE_FPR13\n|  ld f14, SAVE_FPR14\n|  ld f15, SAVE_FPR15\n|  lmg r6, r15, SAVE_GPRS\t// Restores the stack pointer.\n|.endmacro\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|//-----------------------------------------------------------------------\n|\n|// Instruction headers.\n|.macro ins_A; .endmacro\n|.macro ins_AD; .endmacro\n|.macro ins_AJ; .endmacro\n|.macro ins_ABC; srlg RB, RD, 8; llgcr RC, RD; .endmacro\n|.macro ins_AB_; srlg RB, RD, 8; .endmacro\n|.macro ins_A_C; llgcr RC, RD; .endmacro\n|.macro ins_AND; lghi TMPR1, -1; xgr RD, TMPR1; .endmacro // RD = ~RD\n|\n|// Instruction decode+dispatch.\n|.macro ins_NEXT\n|  llgc OP, 3(PC)\n|  llgh RD, 0(PC)\n|  llgc RA, 2(PC)\n|  sllg TMPR1, OP, 3\n|  lg TMPR1, 0(TMPR1, DISPATCH)\n|  la PC, 4(PC)\n|  br TMPR1\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  .macro ins_next\n|    j ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC, RD = nargs+1, -8(BASE) = PC\n|  lg PC, LFUNC:RB->pc\n|  llgc OP, 3(PC)\n|  llgc RA, 2(PC)\n|  sllg TMPR1, OP, 3\n|  la PC, 4(PC)\n|  lg TMPR1, 0(TMPR1, DISPATCH)\n|  br TMPR1\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC, RD = nargs+1\n|  stg PC, -8(BASE)\n|  ins_callt\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to clear or set tags.\n|.macro cleartp, reg\n|  nihf reg, 0x7fff\n|.endmacro\n|.macro settp, reg, tp\n|  oihf reg, tp<<15\n|.endmacro\n|.macro settp, dst, reg, tp\n|  llihf dst, tp<<15\n|  ogr dst, reg\n|.endmacro\n|.macro setint, reg\n|  settp reg, LJ_TISNUM\n|.endmacro\n|.macro setint, dst, reg\n|  settp dst, reg, LJ_TISNUM\n|.endmacro\n|\n|// Macros to test operand types.\n|.macro checktp_nc, reg, tp, target\n|  srag ITYPE, reg, 47\n|  clfi ITYPE, tp\n|  jne target\n|.endmacro\n|.macro checktp, reg, tp, target\n|  srag ITYPE, reg, 47\n|  cleartp reg\n|  clfi ITYPE, tp\n|  jne target\n|.endmacro\n|.macro checktptp, src, tp, target\n|  srag ITYPE, src, 47\n|  clfi ITYPE, tp\n|  jne target\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC, target; .endmacro\n|\n|.macro checknumx, reg, target, jump\n|  srag ITYPE, reg, 47\n|  clfi ITYPE, LJ_TISNUM\n|  jump target\n|.endmacro\n|.macro checkint, reg, target; checknumx reg, target, jne; .endmacro\n|.macro checkinttp, src, target; checknumx src, target, jne; .endmacro\n|.macro checknum, reg, target; checknumx reg, target, jhe; .endmacro\n|.macro checknumtp, src, target; checknumx src, target, jhe; .endmacro\n|.macro checknumber, src, target; checknumx src, target, jh; .endmacro\n|\n|.macro load_false, reg; lghi reg, -1; iihl reg, 0x7fff; .endmacro\t// assumes LJ_TFALSE == ~(1<<47)\n|.macro load_true, reg; lghi reg, -1; iihh reg, 0xfffe; .endmacro\t// assumes LJ_TTRUE  == ~(2<<47)\n|\n|.define PC_OP, -1(PC)\n|.define PC_RA, -2(PC)\n|.define PC_RB, -4(PC)\n|.define PC_RC, -3(PC)\n|.define PC_RD, -4(PC)\n|\n|.macro branchPC, reg\n|  // Must not clobber condition code.\n|  sllg TMPR1, reg, 2\n|  lay PC, (-BCBIAS_J*4)(TMPR1, PC)\n|.endmacro\n|\n|// Set current VM state.\n|.macro set_vmstate, st\n|  lghi TMPR1, ~LJ_VMST_..st\n|  stg TMPR1, DISPATCH_GL(vmstate)(DISPATCH)\n|.endmacro\n|\n|// Synthesize binary floating-point constants.\n|.macro bfpconst_tobit, reg, tmp\t// Synthesize 2^52 + 2^51.\n|  llihh tmp, 0x4338\n|  ldgr reg, tmp\n|.endmacro\n|\n|// Move table write barrier back. Overwrites reg.\n|.macro barrierback, tab, reg\n|  ni tab->marked, ~LJ_GC_BLACK // black2gray(tab)\n|  lg reg, (DISPATCH_GL(gc.grayagain))(DISPATCH)\n|  stg tab, (DISPATCH_GL(gc.grayagain))(DISPATCH)\n|  stg reg, tab->gclist\n|.endmacro\n\n#if !LJ_DUALNUM\n#error \"Only dual-number mode supported for s390x target\"\n#endif\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  tmll PC, FRAME_P\n  |  je ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  nill PC, -8\n  |  sgr BASE, PC\t\t\t// Restore caller base.\n  |  lay RA, -8(RA, PC)\t\t\t// Rebase RA and prepend one result.\n  |  lg PC, -8(BASE)\t\t\t// Fetch PC of previous frame.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |  load_true ITYPE\n  |  stg ITYPE, 0(RA, BASE)\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  aghi RD, 1\t\t\t\t// RD = nresults+1\n  |  je ->vm_unwind_yield\n  |  st RD, SAVE_MULTRES\n  |  tmll PC, FRAME_TYPE\n  |  je ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return\n  |  lghi TMPR1, FRAME_C\n  |  xgr PC, TMPR1\n  |  tmll PC, FRAME_TYPE\n  |  jne ->vm_returnp\n  |\n  |  // Return to C.\n  |  set_vmstate C\n  |  nill PC, -8\n  |  sgr PC, BASE\n  |  lcgr PC, PC\t\t\t// Previous base = BASE - delta.\n  |\n  |  aghi RD, -1\n  |  je >2\n  |1:  // Move results down.\n  |  lg RB, 0(BASE, RA)\n  |  stg RB, -16(BASE)\n  |  la BASE, 8(BASE)\n  |  aghi RD, -1\n  |  jne <1\n  |2:\n  |  lg L:RB, SAVE_L\n  |  stg PC, L:RB->base\n  |3:\n  |  llgf RD, SAVE_MULTRES\n  |  lgf RA, SAVE_NRES\t\t\t// RA = wanted nresults+1\n  |4:\n  |  cgr RA, RD\n  |  jne >6\t\t\t\t// More/less results wanted?\n  |5:\n  |  lay BASE, -16(BASE)\n  |  stg BASE, L:RB->top\n  |\n  |->vm_leave_cp:\n  |  lg RA, SAVE_CFRAME\t\t\t// Restore previous C frame.\n  |  stg RA, L:RB->cframe\n  |  lghi CRET1, 0\t\t\t// Ok return status for vm_pcall.\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  br r14\n  |\n  |6:\n  |  jl >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  cg BASE, L:RB->maxstack\n  |  jh >8\n  |  lghi TMPR1, LJ_TNIL\n  |  stg TMPR1, -16(BASE)\n  |  la BASE, 8(BASE)\n  |  aghi RD, 1\n  |  j <4\n  |\n  |7:  // Fewer results wanted.\n  |  cghi RA, 0\n  |  je <5\t\t\t\t// But check for LUA_MULTRET+1.\n  |  sgr RA, RD\t\t\t\t// Negative result!\n  |  sllg TMPR1, RA, 3\n  |  la BASE, 0(TMPR1, BASE)\t\t// Correct top.\n  |  j <5\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  stg BASE, L:RB->top\t\t// Save current top held in BASE (yes).\n  |  st RD, SAVE_MULTRES\t\t// Need to fill only remainder with nil.\n  |  lgr CARG2, RA\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lg BASE, L:RB->top\t\t\t// Need the (realloced) L->top in BASE.\n  |  j <3\n  |\n  |->vm_unwind_yield:\n  |  lghi CRET1, LUA_YIELD\n  |  j ->vm_unwind_c_eh\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  lgr sp, CARG1\n  |  lgfr CARG2, CRET1\t\t\t// Error return status for vm_pcall.\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  lg L:RB, SAVE_L\n  |  lg GL:RB, L:RB->glref\n  |  lghi TMPR1, ~LJ_VMST_C\n  |  stg TMPR1, GL:RB->vmstate\n  |  j ->vm_leave_unw\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  nill CARG1, CFRAME_RAWMASK\t\t// Assumes high 48-bits set in CFRAME_RAWMASK.\n  |  lgr sp, CARG1\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  lg L:RB, SAVE_L\n  |  lghi RD, 1+1\t\t\t// Really 1+2 results, incr. later.\n  |  lg BASE, L:RB->base\n  |  lg DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  la DISPATCH, GG_G2DISP(DISPATCH)\n  |  lg PC, -8(BASE)\t\t\t// Fetch PC of previous frame.\n  |  load_false RA\n  |  lg RB, 0(BASE)\n  |  stg RA, -16(BASE)\t\t\t// Prepend false to error message.\n  |  stg RB, -8(BASE)\n  |  lghi RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  set_vmstate INTERP\n  |  j ->vm_returnc\t\t\t// Increments RD/MULTRES and returns.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  lghi CARG2, LUA_MINSTACK\n  |  j >2\n  |\n  |->vm_growstack_v:\t\t\t// Grow stack for vararg Lua function.\n  |  aghi RD, -16\t\t\t// LJ_FR2\n  |  j >1\n  |\n  |->vm_growstack_f:\t\t\t// Grow stack for fixarg Lua function.\n  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -8(RD, BASE)\n  |1:\n  |  llgc RA, (PC2PROTO(framesize)-4)(PC)\n  |  la PC, 4(PC)\t\t\t// Must point after first instruction.\n  |  stg BASE, L:RB->base\n  |  stg RD, L:RB->top\n  |  stg PC, SAVE_PC\n  |  lgr CARG2, RA\n  |2:\n  |  // RB = L, L->base = new base, L->top = top\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lg BASE, L:RB->base\n  |  lg RD, L:RB->top\n  |  lg LFUNC:RB, -16(BASE)\n  |  cleartp LFUNC:RB\n  |  sgr RD, BASE\n  |  srlg RD, RD, 3\n  |  aghi NARGS:RD, 1\n  |  // BASE = new base, RB = LFUNC, RD = nargs+1\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  lgr L:RB, CARG1\n  |  stg CARG1, SAVE_L\n  |  lgr RA, CARG2\n  |  lghi PC, FRAME_CP\n  |  lghi RD, 0\n  |  la KBASE, CFRAME_RESUME(sp)\n  |  lg DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  aghi DISPATCH, GG_G2DISP\n  |  stg RD, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  stg RD, SAVE_CFRAME\n  |  st RD, SAVE_NRES\n  |  stg RD, SAVE_ERRF\n  |  stg KBASE, L:RB->cframe\n  |  clm RD, 1, L:RB->status\n  |  je >2\t\t\t\t// Initial resume (like a call).\n  |\n  |  // Resume after yield (like a return).\n  |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)\n  |  set_vmstate INTERP\n  |  stc RD, L:RB->status\n  |  lg BASE, L:RB->base\n  |  lg RD, L:RB->top\n  |  sgr RD, RA\n  |  srlg RD, RD, 3\n  |  aghi RD, 1\t\t\t\t// RD = nresults+1\n  |  sgr RA, BASE\t\t\t// RA = resultofs\n  |  lg PC, -8(BASE)\n  |  st RD, SAVE_MULTRES\n  |  tmll PC, FRAME_TYPE\n  |  je ->BC_RET_Z\n  |  j ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  lghi PC, FRAME_CP\n  |  llgfr CARG4, CARG4\n  |  stg CARG4, SAVE_ERRF\n  |  j >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  lghi PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  st CARG3, SAVE_NRES\n  |  lgr L:RB, CARG1\n  |  stg CARG1, SAVE_L\n  |  lgr RA, CARG2\t\t\t// Caveat: RA = CARG3.\n  |\n  |  lg DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  lg KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  stg KBASE, SAVE_CFRAME\n  |  stg L:RB, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |  aghi DISPATCH, GG_G2DISP\n  |  stg sp, L:RB->cframe\n  |\n  |2: // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).\n  |  stg L:RB, DISPATCH_GL(cur_L)(DISPATCH)\n  |  set_vmstate INTERP\n  |  lg BASE, L:RB->base\t\t// BASE = old base (used in vmeta_call).\n  |  agr PC, RA\n  |  sgr PC, BASE\t\t\t// PC = frame delta + frame type\n  |\n  |  lg RD, L:RB->top\n  |  sgr RD, RA\n  |  srlg NARGS:RD, NARGS:RD, 3\n  |  aghi NARGS:RD, 1\t\t\t// RD = nargs+1\n  |\n  |->vm_call_dispatch:\n  |  lg LFUNC:RB, -16(RA)\n  |  checkfunc LFUNC:RB, ->vmeta_call\t// Ensure KBASE defined and != BASE.\n  |\n  |->vm_call_dispatch_f:\n  |  lgr BASE, RA\n  |  ins_call\n  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  lgr L:RB, CARG1\n  |  stg L:RB, SAVE_L\n  |  stg L:RB, SAVE_PC\t\t\t// Any value outside of bytecode is ok.\n  |\n  |  lg KBASE, L:RB->stack\t\t// Compute -savestack(L, L->top).\n  |  sg KBASE, L:RB->top\n  |   lg DISPATCH, L:RB->glref\t// Setup pointer to dispatch table.\n  |  lghi TMPR0, 0\n  |  stg TMPR0, SAVE_ERRF\t\t// No error function.\n  |  st KBASE, SAVE_NRES\t\t// Neg. delta means cframe w/o frame.\n  |   aghi DISPATCH, GG_G2DISP\n  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).\n  |\n  |  lg KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  stg KBASE, SAVE_CFRAME\n  |  stg sp, L:RB->cframe\n  |  stg L:RB, DISPATCH_GL(cur_L)(DISPATCH)\n  |\n  |  basr r14, CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  // TValue * (new base) or NULL returned in r2 (CRET1/).\n  |  cghi CRET1, 0\n  |  je ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |  lgr RA, CRET1\n  |  lghi PC, FRAME_CP\n  |  j <2\t\t\t\t// Else continue with the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)\n  |  agr RA, BASE\n  |  nill PC, -8\n  |  lgr RB, BASE\n  |  sgr BASE, PC\t\t\t// Restore caller BASE.\n  |  sllg TMPR1, RD, 3\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, -8(RA, TMPR1)\t\t// Ensure one valid arg.\n  |  lgr RC, RA\t\t\t\t// ... in [RC]\n  |  lg PC, -24(RB)\t\t\t// Restore PC from [cont|PC].\n  |  lg RA, -32(RB)\n  |.if FFI\n  |  clfi RA, 1\n  |  jle >1\n  |.endif\n  |  lg LFUNC:KBASE, -16(BASE)\n  |  cleartp LFUNC:KBASE\n  |  lg KBASE, LFUNC:KBASE->pc\n  |  lg KBASE, (PC2PROTO(k))(KBASE)\n  |  // BASE = base, RC = result, RB = meta base\n  |  br RA\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  je ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: Tail call from C function.\n  |  sgr RB, BASE\n  |  srl RB, 3\n  |  ahi RB, -3\n  |  llgfr RD, RB\n  |  j ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// BASE = base, RC = result, RB = mbase\n  |  llgc RA, PC_RB\n  |  sllg RA, RA, 3\n  |  aghi RB, -32\n  |  la RA, 0(RA, BASE)\n  |  sgr RA, RB\n  |  je ->cont_ra\n  |  lcgr RA, RA\n  |  srlg RA, RA, 3\n  |  lg L:CARG1, SAVE_L\n  |  stg BASE, L:CARG1->base\n  |  lgfr CARG3, RA\t\t\t// Caveat: RA == CARG3.\n  |  lg TMPR0, 0(RC)\n  |  stg TMPR0, 0(RB)\n  |  lgr CARG2, RB\n  |  j ->BC_CAT_Z\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets:\n  |  settp STR:RC, LJ_TSTR\t\t\t// STR:RC = GCstr *\n  |  stg STR:RC, SAVE_TMP\n  |  la RC, SAVE_TMP\n  |  llgc TMPR1, PC_OP\n  |  cghi TMPR1, BC_GGET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t\t// TAB:RB = GCtab *\n  |  lay RB, (DISPATCH_GL(tmptv))(DISPATCH)\t// Store fn->l.env in g->tmptv.\n  |  stg TAB:RA, 0(RB)\n  |  j >2\n  |\n  |->vmeta_tgetb:\n  |  llgc RC, PC_RC\n  |  setint RC\n  |  stg RC, SAVE_TMP\n  |  la RC, SAVE_TMP\n  |  j >1\n  |\n  |->vmeta_tgetv:\n  |  llgc RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  sllg RC, RC, 3\n  |  la RC, 0(RC, BASE)\n  |1:\n  |  llgc RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  sllg RB, RB, 3\n  |  la RB, 0(RB, BASE)\n  |2:\n  |  lg L:CARG1, SAVE_L\n  |  stg BASE, L:CARG1->base\n  |  lgr CARG2, RB\n  |  lgr CARG3, RC\n  |  lgr L:RB, L:CARG1\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_tget\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in r2 (CRET1).\n  |  lg BASE, L:RB->base\n  |  ltgr RC, CRET1\n  |  je >3\n  |->cont_ra:\t\t\t\t// BASE = base, RC = result\n  |  llgc RA, PC_RA\n  |  sllg RA, RA, 3\n  |  lg RB, 0(RC)\n  |  stg RB, 0(RA, BASE)\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  lg RA, L:RB->top\n  |  stg PC, -24(RA)\t\t\t// [cont|PC]\n  |  la PC, FRAME_CONT(RA)\n  |  sgr PC, BASE\n  |  lg LFUNC:RB, -16(RA)\t\t// Guaranteed to be a function here.\n  |  lghi NARGS:RD, 2+1\t\t\t// 2 args for func(t, k).\n  |  cleartp LFUNC:RB\n  |  j ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  lgr CARG1, TAB:RB\n  |  lgfr CARG2, RC\n  |  brasl r14, extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in r2 (CRET1).\n  |  llgc RA, PC_RA\n  |  ltgr RC, CRET1\n  |  jne ->BC_TGETR_Z\n  |  lghi ITYPE, LJ_TNIL\n  |  j ->BC_TGETR2_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets:\n  |  settp STR:RC, LJ_TSTR\t\t\t// STR:RC = GCstr *\n  |  stg STR:RC, SAVE_TMP\n  |  la RC, SAVE_TMP\n  |  llgc TMPR0, PC_OP\n  |  cghi TMPR0, BC_GSET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t\t// TAB:RB = GCtab *\n  |  lay RB, (DISPATCH_GL(tmptv))(DISPATCH)\t// Store fn->l.env in g->tmptv.\n  |  stg TAB:RA, 0(RB)\n  |  j >2\n  |\n  |->vmeta_tsetb:\n  |  llgc RC, PC_RC\n  |  setint RC\n  |  stg RC, SAVE_TMP\n  |  la RC, SAVE_TMP\n  |  j >1\n  |\n  |->vmeta_tsetv:\n  |  llgc RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  sllg RC, RC, 3\n  |  la RC, 0(RC, BASE)\n  |1:\n  |  llgc RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  sllg RB, RB, 3\n  |  la RB, 0(RB, BASE)\n  |2:\n  |  lg L:CARG1, SAVE_L\n  |  stg BASE, L:CARG1->base\n  |  lgr CARG2, RB\n  |  lgr CARG3, RC\n  |  lgr L:RB, L:CARG1\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_tset\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in r2 (CRET1).\n  |  lg BASE, L:RB->base\n  |  ltgr RC, CRET1\n  |  je >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  llgc RA, PC_RA\n  |  sllg RA, RA, 3\n  |  lg RB, 0(RA, BASE)\n  |  stg RB, 0(RC)\n  |->cont_nop:\t\t\t\t// BASE = base, (RC = result)\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  lg RA, L:RB->top\n  |  stg PC, -24(RA)\t\t\t// [cont|PC]\n  |  llgc RC, PC_RA\n  |  // Copy value to third argument.\n  |  sllg RB, RC, 3\n  |  lg RB, 0(RB, BASE)\n  |  stg RB, 16(RA)\n  |  la PC, FRAME_CONT(RA)\n  |  sgr PC, BASE\n  |  lg LFUNC:RB, -16(RA)\t\t// Guaranteed to be a function here.\n  |  lghi NARGS:RD, 3+1\t\t\t// 3 args for func(t, k, v).\n  |  cleartp LFUNC:RB\n  |  j ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |  lg L:CARG1, SAVE_L\n  |  lgr CARG2, TAB:RB\n  |  stg BASE, L:CARG1->base\n  |  lgfr CARG3, RC\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // TValue * returned in r2 (CRET1).\n  |  lgr RC, CRET1\n  |  llgc RA, PC_RA\n  |  j ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  llgh RD, PC_RD\n  |  sllg RD, RD, 3\n  |  llgc RA, PC_RA\n  |  sllg RA, RA, 3\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  la CARG2, 0(RA, BASE)\n  |  la CARG3, 0(RD, BASE)\t\t// Caveat: RA == CARG3\n  |  lgr CARG1, L:RB\n  |  llgc CARG4, PC_OP\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).\n  |3:\n  |  lgr RC, CRET1\n  |  lg BASE, L:RB->base\n  |  clgfi RC, 1\n  |  jh ->vmeta_binop\n  |4:\n  |  la PC, 4(PC)\n  |  jl >6\n  |5:\n  |  llgh RD, PC_RD\n  |  branchPC RD\n  |6:\n  |  ins_next\n  |\n  |->cont_condt:\t\t\t// BASE = base, RC = result\n  |  la PC, 4(PC)\n  |  lg ITYPE, 0(RC)\n  |  srag ITYPE, ITYPE, 47\n  |  lghi TMPR0, LJ_TISTRUECOND\n  |  clr ITYPE, TMPR0\t\t// Branch if result is true.\n  |  jl <5\n  |  j <6\n  |\n  |->cont_condf:\t\t\t// BASE = base, RC = result\n  |  lg ITYPE, 0(RC)\n  |  srag ITYPE, ITYPE, 47\n  |  lghi TMPR0, LJ_TISTRUECOND\n  |  clr ITYPE, TMPR0\t\t// Branch if result is false.\n  |  j <4\n  |\n  |->vmeta_equal:\n  |  cleartp TAB:RD\n  |  lay PC, -4(PC)\n  |  lgr CARG2, RA\n  |  lgfr CARG4, RB\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  lgr CARG3, RD\n  |  lgr CARG1, L:RB\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).\n  |  j <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  lay PC, -4(PC)\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  lgr CARG1, L:RB\n  |  llgf CARG2, -4(PC)\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_equal_cd\t// (lua_State *L, BCIns ins)\n  |  // 0/1 or TValue * (metamethod) returned in r2 (CRET1).\n  |  j <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  llgfr CARG2, RA\n  |  llgfr CARG3, RD\t\t\t// Caveat: CARG3 == RA.\n  |  lgr L:CARG1, L:RB\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  lg BASE, L:RB->base\n  |  j <6\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vno:\n  |  llgc RB, PC_RB\n  |  llgc RC, PC_RC\n  |->vmeta_arith_vn:\n  |  sllg RB, RB, 3\n  |  sllg RC, RC, 3\n  |  la RB, 0(RB, BASE)\n  |  la RC, 0(RC, KBASE)\n  |  j >1\n  |\n  |->vmeta_arith_nvo:\n  |  llgc RC, PC_RC\n  |  llgc RB, PC_RB\n  |->vmeta_arith_nv:\n  |  sllg RC, RC, 3\n  |  sllg RB, RB, 3\n  |  la TMPR1, 0(RC, KBASE)\n  |  la RC, 0(RB, BASE)\n  |  lgr RB, TMPR1\n  |  j >1\n  |\n  |->vmeta_unm:\n  |  llgh RD, PC_RD\n  |  sllg RD, RD, 3\n  |  la RC, 0(RD, BASE)\n  |  lgr RB, RC\n  |  j >1\n  |\n  |->vmeta_arith_vvo:\n  |  llgc RB, PC_RB\n  |  llgc RC, PC_RC\n  |->vmeta_arith_vv:\n  |  sllg RC, RC, 3\n  |  sllg RB, RB, 3\n  |  la RB, 0(RB, BASE)\n  |  la RC, 0(RC, BASE)\n  |1:\n  |  llgc RA, PC_RA\n  |  sllg RA, RA, 3\n  |  la RA, 0(RA, BASE)\n  |  llgc CARG5, PC_OP\t\t\t// Caveat: CARG5 == RD.\n  |  lgr CARG2, RA\n  |  lgr CARG3, RB\t\t\t// Caveat: CARG3 == RA.\n  |  // lgr CARG4, RC\t\t\t// Caveat: CARG4 == RC (nop, so commented out).\n  |  lg L:CARG1, SAVE_L\n  |  stg BASE, L:CARG1->base\n  |  lgr L:RB, L:CARG1\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // NULL (finished) or TValue * (metamethod) returned in r2 (CRET1).\n  |  lg BASE, L:RB->base\n  |  cghi CRET1, 0\n  |  lgr RC, CRET1\n  |  je ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = base, RC = new base, stack = cont/func/o1/o2\n  |  lgr RA, RC\n  |  sgr RC, BASE\n  |  stg PC, -24(RA)\t\t\t// [cont|PC]\n  |  la PC, FRAME_CONT(RC)\n  |  lghi NARGS:RD, 2+1\t\t\t// 2 args for func(o1, o2).\n  |  j ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  llgh RD, PC_RD\n  |  sllg RD, RD, 3\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  la CARG2, 0(RD, BASE)\n  |  lgr L:CARG1, L:RB\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_len\t// (lua_State *L, TValue *o)\n  |  // NULL (retry) or TValue * (metamethod) returned in r2 (CRET1).\n  |  lgr RC, CRET1\n  |  lg BASE, L:RB->base\n#if LJ_52\n  |  cghi RC, 0\n  |  jne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  llgh RD, PC_RD\n  |  sllg RD, RD, 3\n  |  lg TAB:CARG1, 0(RD, BASE)\n  |  cleartp TAB:CARG1\n  |  j ->BC_LEN_Z\n#else\n  |  j ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call_ra:\n  |  la RA, 16(RA, BASE)\t\t// RA previously set to RA*8.\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return\n  |  stg NARGS:RD, SAVE_TMP\t\t// Save RA, RC for us (not sure about this).\n  |  lgr RB, RA\n  |  lg L:CARG1, SAVE_L\n  |  stg BASE, L:CARG1->base\n  |  lay CARG2, -16(RA)\n  |  sllg RD, RD, 3\n  |  lay CARG3, -8(RA, RD)\t\t// Caveat: CARG3 == RA.\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  lgr RA, RB\n  |  lg L:RB, SAVE_L\n  |  lg BASE, L:RB->base\n  |  lg NARGS:RD, SAVE_TMP\n  |  lg LFUNC:RB, -16(RA)\n  |  aghi NARGS:RD, 1\t\t\t// 32-bit on x64.\n  |  // This is fragile. L->base must not move, KBASE must always be defined.\n  |  cgr KBASE, BASE\t\t\t// Continue with CALLT if flag set.\n  |  je ->BC_CALLT_Z\n  |  cleartp LFUNC:RB\n  |  lgr BASE, RA\n  |  ins_call\t\t\t\t// Otherwise call resolved metamethod.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  lgr CARG2, RA\n  |  lgr CARG1, RB\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  lg BASE, L:RB->base\n  |  llgc OP, PC_OP\n  |  llgc RA, PC_RA\n  |  llgh RD, PC_RD\n  |  sllg TMPR1, OP, 3\n  |  lg TMPR1, GG_DISP2STATIC(TMPR1, DISPATCH)\t// Retry FORI or JFORI.\n  |  br TMPR1\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  clfi NARGS:RD, 1+1; jl ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  clfi NARGS:RD, 2+1; jl ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name, op\n  |  .ffunc_1 name\n  |  lg TMPR0, 0(BASE)\n  |  checknumtp TMPR0, ->fff_fallback\n  |  op f0, 0(BASE)\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc_n name, ld\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc_2 name\n  |  lg TMPR1, 0(BASE)\n  |  lg TMPR0, 8(BASE)\n  |  ld FARG1, 0(BASE)\n  |  ld FARG2, 8(BASE)\n  |  checknumtp TMPR1, ->fff_fallback\n  |  checknumtp TMPR0, ->fff_fallback\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses label 1.\n  |.macro ffgccheck\n  |  lg RB, (DISPATCH_GL(gc.total))(DISPATCH)\n  |  clg RB, (DISPATCH_GL(gc.threshold))(DISPATCH)\n  |  jl >1\n  |  brasl r14, ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  lg RB, 0(BASE)\n  |  srag ITYPE, RB, 47\n  |  clfi ITYPE, LJ_TISTRUECOND; jhe ->fff_fallback\n  |  lg PC, -8(BASE)\n  |  st RD, SAVE_MULTRES\n  |  lg RB, 0(BASE)\n  |  stg RB, -16(BASE)\n  |  ahi RD, -2\n  |  je >2\n  |  lgr RA, BASE\n  |1:\n  |  la RA, 8(RA)\n  |  lg RB, 0(RA)\n  |  stg RB, -16(RA)\n  |  brct RD, <1\n  |2:\n  |  llgf RD, SAVE_MULTRES\n  |  j ->fff_res_\n  |\n  |.ffunc_1 type\n  |  lg RC, 0(BASE)\n  |  srag RC, RC, 47\n  |  lghi RB, LJ_TISNUM\n  |  clgr RC, RB\n  |  jnl >1\n  |  lgr RC, RB\n  |1:\n  |  lghi TMPR0, -1\n  |  xgr RC, TMPR0\n  |2:\n  |  lg CFUNC:RB, -16(BASE)\n  |  cleartp CFUNC:RB\n  |  sllg RC, RC, 3\n  |  lg STR:RC, ((char *)(&((GCfuncC *)0)->upvalue))(RC, CFUNC:RB)\n  |  lg PC, -8(BASE)\n  |  settp STR:RC, LJ_TSTR\n  |  stg STR:RC, -16(BASE)\n  |  j ->fff_res1\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  lg TAB:RB, 0(BASE)\n  |  lg PC, -8(BASE)\n  |  checktab TAB:RB, >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  lg TAB:RB, TAB:RB->metatable\n  |2:\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, -16(BASE)\n  |  cghi TAB:RB, 0\n  |  je ->fff_res1\n  |  settp TAB:RC, TAB:RB, LJ_TTAB\n  |  stg TAB:RC, -16(BASE)\t\t// Store metatable as default result.\n  |  lg STR:RC, (DISPATCH_GL(gcroot)+8*(GCROOT_MMNAME+MM_metatable))(DISPATCH)\n  |  llgf RA, TAB:RB->hmask\n  |  n RA, STR:RC->hash\n  |  settp STR:RC, LJ_TSTR\n  |  mghi RA, #NODE\n  |  ag NODE:RA, TAB:RB->node\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  cg STR:RC, NODE:RA->key\n  |  je >5\n  |4:\n  |  ltg NODE:RA, NODE:RA->next\n  |  jne <3\n  |  j ->fff_res1\t\t\t// Not found, keep default result.\n  |5:\n  |  lg RB, NODE:RA->val\n  |  cghi RB, LJ_TNIL; je ->fff_res1\t// Ditto for nil value.\n  |  stg RB, -16(BASE)\t\t\t// Return value of mt.__metatable.\n  |  j ->fff_res1\n  |\n  |6:\n  |  clfi ITYPE, LJ_TUDATA; je <1\n  |  clfi ITYPE, LJ_TISNUM; jh >7\n  |  lhi ITYPE, LJ_TISNUM\n  |7:\n  |  lhi TMPR0, -1\n  |  xr ITYPE, TMPR0 // not ITYPE\n  |  llgfr ITYPE, ITYPE\n  |  sllg ITYPE, ITYPE, 3\n  |  lg TAB:RB, (DISPATCH_GL(gcroot[GCROOT_BASEMT]))(ITYPE, DISPATCH)\n  |  j <2\n  |\n  |.ffunc_2 setmetatable\n  |  lg TAB:RB, 0(BASE)\n  |  lgr TAB:TMPR1, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  lghi TMPR0, 0\n  |  cg TMPR0, TAB:RB->metatable; jne ->fff_fallback\n  |  lg TAB:RA, 8(BASE)\n  |  checktab TAB:RA, ->fff_fallback\n  |  stg TAB:RA, TAB:RB->metatable\n  |  lg PC, -8(BASE)\n  |  stg TAB:TMPR1, -16(BASE)\t\t\t// Return original table.\n  |  tm TAB:RB->marked, LJ_GC_BLACK\t\t// isblack(table)\n  |  je >1\n  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.\n  |  barrierback TAB:RB, RC\n  |1:\n  |  j ->fff_res1\n  |\n  |.ffunc_2 rawget\n  |  lg TAB:CARG2, 0(BASE)\n  |  checktab TAB:CARG2, ->fff_fallback\n  |  la CARG3, 8(BASE)\n  |  lg CARG1, SAVE_L\n  |  brasl r14, extern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |  // cTValue * returned in r2 (CRET1).\n  |  // Copy table slot.\n  |  lg RB, 0(CRET1)\n  |  lg PC, -8(BASE)\n  |  stg RB, -16(BASE)\n  |  j ->fff_res1\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  clfi NARGS:RD, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  lg RB, 0(BASE)\n  |  checknumber RB, ->fff_fallback\n  |  lg PC, -8(BASE)\n  |  stg RB, -16(BASE)\n  |  j ->fff_res1\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  lg PC, -8(BASE)\n  |  lg STR:RB, 0(BASE)\n  |  checktp_nc STR:RB, LJ_TSTR, >3\n  |  // A __tostring method in the string base metatable is ignored.\n  |2:\n  |  stg STR:RB, -16(BASE)\n  |  j ->fff_res1\n  |3:  // Handle numbers inline, unless a number base metatable is present.\n  |  clfi ITYPE, LJ_TISNUM; jh ->fff_fallback_1\n  |  lghi TMPR0, 0\n  |  cg TMPR0, (DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM]))(DISPATCH)\n  |  jne ->fff_fallback\n  |  ffgccheck\t\t\t\t// Caveat: uses label 1.\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\t\t// Add frame since C call can throw.\n  |  stg PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  lgr CARG2, BASE\t\t\t// Otherwise: CARG2 == BASE\n  |  lgr L:CARG1, L:RB\n  |  brasl r14, extern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |  // GCstr returned in r2 (CRET1).\n  |  lg BASE, L:RB->base\n  |  settp STR:RB, CRET1, LJ_TSTR\n  |  j <2\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  je >2\t\t\t\t// Missing 2nd arg?\n  |1:\n  |  lg CARG2, 0(BASE)\n  |  checktab CARG2, ->fff_fallback\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\t\t// Add frame since C call can throw.\n  |  stg BASE, L:RB->top\t\t// Dummy frame length is ok.\n  |  lg PC, -8(BASE)\n  |  la CARG3, 8(BASE)\n  |  lgr CARG1, L:RB\n  |  stg PC, SAVE_PC\t\t\t// Needed for ITERN fallback.\n  |  brasl r14, extern lj_tab_next\t// (lua_State *L, GCtab *t, TValue *key)\n  |  // Flag returned in r2 (CRET1).\n  |  lg BASE, L:RB->base\n  |  ltr RD, CRET1;  je >3\t\t// End of traversal?\n  |  // Copy key and value to results.\n  |  lg RB, 8(BASE)\n  |  lg RD, 16(BASE)\n  |  stg RB, -16(BASE)\n  |  stg RD, -8(BASE)\n  |->fff_res2:\n  |  lghi RD, 1+2\n  |  j ->fff_res\n  |2:  // Set missing 2nd arg to nil.\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, 8(BASE)\n  |  j <1\n  |3:  // End of traversal: return nil.\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, -16(BASE)\n  |  j ->fff_res1\n  |\n  |.ffunc_1 pairs\n  |  lg TAB:RB, 0(BASE)\n  |  lgr TMPR1, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  ltg TMPR0, TAB:RB->metatable; jne ->fff_fallback\n#endif\n  |  lg CFUNC:RD, -16(BASE)\n  |  cleartp CFUNC:RD\n  |  lg CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  lg PC, -8(BASE)\n  |  stg CFUNC:RD, -16(BASE)\n  |  stg TMPR1, -8(BASE)\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, 0(BASE)\n  |  lghi RD, 1+3\n  |  j ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  lg TAB:RB, 0(BASE)\n  |  checktab TAB:RB, ->fff_fallback\n  |  lg RA, 8(BASE)\n  |  checkint RA, ->fff_fallback\n  |  lg PC, -8(BASE)\n  |  aghi RA, 1\n  |  setint ITYPE, RA\n  |  stg ITYPE, -16(BASE)\n  |  cl RA, TAB:RB->asize;  jhe >2\t// Not in array part?\n  |  lg RD, TAB:RB->array\n  |  lgfr TMPR1, RA\n  |  sllg TMPR1, TMPR1, 3\n  |  la RD, 0(TMPR1, RD)\n  |1:\n  |  lg TMPR0, 0(RD)\n  |  cghi TMPR0, LJ_TNIL;  je ->fff_res0\n  |  // Copy array slot.\n  |  stg TMPR0, -8(BASE)\n  |  j ->fff_res2\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  lt TMPR0, TAB:RB->hmask; je ->fff_res0\n  |  lgr CARG1, TAB:RB\n  |  lgfr CARG2, RA\n  |  brasl r14, extern lj_tab_getinth\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in r2 (CRET1).\n  |  ltgr RD, CRET1\n  |  jne <1\n  |->fff_res0:\n  |  lghi RD, 1+0\n  |  j ->fff_res\n  |\n  |.ffunc_1 ipairs\n  |  lg TAB:RB, 0(BASE)\n  |  lgr TMPR1, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  lghi TMPR0, 0\n  |  cg TMPR0, TAB:RB->metatable; jne ->fff_fallback\n#endif\n  |  lg CFUNC:RD, -16(BASE)\n  |  cleartp CFUNC:RD\n  |  lg CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  lg PC, -8(BASE)\n  |  stg CFUNC:RD, -16(BASE)\n  |  stg TMPR1, -8(BASE)\n  |  llihf RD, LJ_TISNUM<<15\n  |  stg RD, 0(BASE)\n  |  lghi RD, 1+3\n  |  j ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc_1 pcall\n  |  la RA, 16(BASE)\n  |  aghi NARGS:RD, -1\n  |  lghi PC, 16+FRAME_PCALL\n  |1:\n  |  llgc RB, (DISPATCH_GL(hookmask))(DISPATCH)\n  |  srlg RB, RB, HOOK_ACTIVE_SHIFT(r0)\n  |  nill RB, 1\t\t\t\t// High bits already zero (from load).\n  |  agr PC, RB\t\t\t\t// Remember active hook before pcall.\n  |  // Note: this does a (harmless) copy of the function to the PC slot, too.\n  |  lgr KBASE, RD\n  |2:\n  |  sllg TMPR1, KBASE, 3\n  |  lg RB, -24(TMPR1, RA)\n  |  stg RB, -16(TMPR1, RA)\n  |  aghi KBASE, -1\n  |  jh <2\n  |  j ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  lg LFUNC:RA, 8(BASE)\n  |  checktp_nc LFUNC:RA, LJ_TFUNC, ->fff_fallback\n  |  lg LFUNC:RB, 0(BASE)\t\t// Swap function and traceback.\n  |  stg LFUNC:RA, 0(BASE)\n  |  stg LFUNC:RB, 8(BASE)\n  |  la RA, 24(BASE)\n  |  aghi NARGS:RD, -2\n  |  lghi PC, 24+FRAME_PCALL\n  |  j <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  lg L:RB, 0(BASE)\n  |  lgr L:TMPR0, L:RB\t\t\t// Save type for checktptp.\n  |  cleartp L:RB\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  lg CFUNC:RB, -16(BASE)\n  |  cleartp CFUNC:RB\n  |  lg L:RB, CFUNC:RB->upvalue[0].gcr\n  |  cleartp L:RB\n  |.endif\n  |  lg PC, -8(BASE)\n  |  stg PC, SAVE_PC\n  |  stg L:RB, SAVE_TMP\n  |.if resume\n  |  checktptp L:TMPR0, LJ_TTHREAD, ->fff_fallback\n  |.endif\n  |  ltg TMPR0, L:RB->cframe; jne ->fff_fallback\n  |  cli L:RB->status, LUA_YIELD; jh ->fff_fallback\n  |  lg RA, L:RB->top\n  |  je >1\t\t\t\t// Status != LUA_YIELD (i.e. 0)?\n  |  cg RA, L:RB->base\t\t\t// Check for presence of initial func.\n  |  je ->fff_fallback\n  |  lg PC, -8(RA)\t\t\t// Move initial function up.\n  |  stg PC, 0(RA)\n  |  la RA, 8(RA)\n  |1:\n  |  sllg TMPR1, NARGS:RD, 3\n  |.if resume\n  |  lay PC, -16(TMPR1, RA)\t\t// Check stack space (-1-thread).\n  |.else\n  |  lay PC, -8(TMPR1, RA)\t\t// Check stack space (-1).\n  |.endif\n  |  clg PC, L:RB->maxstack; jh ->fff_fallback\n  |  stg PC, L:RB->top\n  |\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |.if resume\n  |  la BASE, 8(BASE)\t\t\t// Keep resumed thread in stack for GC.\n  |.endif\n  |  stg BASE, L:RB->top\n  |.if resume\n  |  lay RB, -24(TMPR1, BASE)\t\t// RB = end of source for stack move.\n  |.else\n  |  lay RB, -16(TMPR1, BASE)\t\t// RB = end of source for stack move.\n  |.endif\n  |  sgr RB, PC\t\t\t// Relative to PC.\n  |\n  |  cgr PC, RA\n  |  je >3\n  |2:  // Move args to coroutine.\n  |  lg RC, 0(RB, PC)\n  |  stg RC, -8(PC)\n  |  lay PC, -8(PC)\n  |  cgr PC, RA\n  |  jne <2\n  |3:\n  |  lgr CARG2, RA\n  |  lg L:CARG1, SAVE_TMP\n  |  lghi CARG3, 0\n  |  lghi CARG4, 0\n  |  brasl r14, ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |\n  |  lg L:RB, SAVE_L\n  |  lg L:PC, SAVE_TMP\n  |  lg BASE, L:RB->base\n  |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)\n  |  set_vmstate INTERP\n  |\n  |  clfi CRET1, LUA_YIELD\n  |  jh >8\n  |4:\n  |  lg RA, L:PC->base\n  |  lg KBASE, L:PC->top\n  |  stg RA, L:PC->top\t\t\t// Clear coroutine stack.\n  |  lgr PC, KBASE\n  |  sgr PC, RA\n  |  je >6\t\t\t\t// No results?\n  |  la RD, 0(PC, BASE)\n  |  llgfr PC, PC\n  |  srlg PC, PC, 3\n  |  clg RD, L:RB->maxstack\n  |  jh >9\t\t\t\t// Need to grow stack?\n  |\n  |  lgr RB, BASE\n  |  sgr RB, RA\n  |5:  // Move results from coroutine.\n  |  lg RD, 0(RA)\n  |  stg RD, 0(RA, RB)\n  |  la RA, 8(RA)\n  |  cgr RA, KBASE\n  |  jne <5\n  |6:\n  |.if resume\n  |  la RD, 2(PC)\t\t\t// nresults+1 = 1 + true + results.\n  |  load_true ITYPE\t\t\t// Prepend true to results.\n  |  stg ITYPE, -8(BASE)\n  |.else\n  |  la RD, 1(PC)\t\t\t// nresults+1 = 1 + results.\n  |.endif\n  |7:\n  |  lg PC, SAVE_PC\n  |  st RD, SAVE_MULTRES\n  |.if resume\n  |  lghi RA, -8\n  |.else\n  |  lghi RA, 0\n  |.endif\n  |  tmll PC, FRAME_TYPE\n  |  je ->BC_RET_Z\n  |  j ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  load_false ITYPE\t\t\t// Prepend false to results.\n  |  stg ITYPE, -8(BASE)\n  |  lg RA, L:PC->top\n  |  aghi RA, -8\n  |  stg RA, L:PC->top\t\t\t// Clear error from coroutine stack.\n  |  // Copy error message.\n  |  lg RD, 0(RA)\n  |  stg RD, 0(BASE)\n  |  lghi RD, 1+2\t\t\t// nresults+1 = 1 + false + error.\n  |  j <7\n  |.else\n  |  lgr CARG2, L:PC\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Error function does not return.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  lg L:RA, SAVE_TMP\n  |  stg KBASE, L:RA->top\t\t// Undo coroutine stack clearing.\n  |  lgr CARG2, PC\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lg L:PC, SAVE_TMP\n  |  lg BASE, L:RB->base\n  |  j <4\t\t\t\t// Retry the stack move.\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  lg L:RB, SAVE_L\n  |  lg TMPR0, L:RB->cframe\n  |  tmll TMPR0, CFRAME_RESUME\n  |  je ->fff_fallback\n  |  stg BASE, L:RB->base\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -8(RD, BASE)\n  |  stg RD, L:RB->top\n  |  lghi RD, 0\n  |  stg RD, L:RB->cframe\n  |  lghi CRET1, LUA_YIELD\n  |  stc CRET1, L:RB->status\n  |  j ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.ffunc_1 math_abs\n  |  lg RB, 0(BASE)\n  |  checkint RB, >3\n  |  lpr RB, RB; jo >2\n  |->fff_resbit:\n  |->fff_resi:\n  |  setint RB\n  |->fff_resRB:\n  |  lg PC, -8(BASE)\n  |  stg RB, -16(BASE)\n  |  j ->fff_res1\n  |2:\n  |  llihh RB, 0x41e0\t// 2^31\n  |  j ->fff_resRB\n  |3:\n  |  jh ->fff_fallback\n  |  nihh RB, 0x7fff\t// Clear sign bit.\n  |  lg PC, -8(BASE)\n  |  stg RB, -16(BASE)\n  |  j ->fff_res1\n  |\n  |.ffunc_n math_sqrt, sqdb\n  |->fff_resf0:\n  |  lg PC, -8(BASE)\n  |  stdy f0, -16(BASE)\n  |  // fallthrough\n  |\n  |->fff_res1:\n  |  lghi RD, 1+1\n  |->fff_res:\n  |  st RD, SAVE_MULTRES\n  |->fff_res_:\n  |  tmll PC, FRAME_TYPE\n  |  jne >7\n  |5:\n  |  llgc TMPR1, PC_RB\n  |  clgr TMPR1, RD\t\t\t// More results expected?\n  |  jh >6\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  llgc RA, PC_RA\n  |  lcgr RA, RA\n  |  sllg RA, RA, 3\n  |  lay BASE, -16(RA, BASE)\t\t// base = base - (RA+2)*8\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  sllg TMPR1, RD, 3\n  |  lghi TMPR0, LJ_TNIL\n  |  stg TMPR0, -24(TMPR1, BASE)\n  |  la RD, 1(RD)\n  |  j <5\n  |\n  |7:  // Non-standard return case.\n  |  lghi RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  j ->vm_return\n  |\n  |.macro math_round, func\n  |  .ffunc math_ .. func\n  |  lg RB, 0(BASE)\n  |  ld f0, 0(BASE)\n  |  checknumx RB, ->fff_resRB, je\n  |  jh ->fff_fallback\n  |  brasl r14, ->vm_ .. func\n  |  cfdbr RB, 0, f0\n  |  jo ->fff_resf0\n  |  llgfr RB, RB\n  |  j ->fff_resi\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  chi NARGS:RD, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  lg TMPR0, 0(BASE)\n  |  ld FARG1, 0(BASE)\n  |  checknumtp TMPR0, ->fff_fallback\n  |  brasl r14, extern log\n  |  j ->fff_resf0\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  brasl r14, extern func\n  |  j ->fff_resf0\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  brasl r14, extern func\n  |  j ->fff_resf0\n  |.endmacro\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_2 math_ldexp\n  |  lg TMPR0, 0(BASE)\n  |  ld FARG1, 0(BASE)\n  |  lg CARG1, 8(BASE)\n  |  checknumtp TMPR0, ->fff_fallback\n  |  checkinttp CARG1, ->fff_fallback\n  |  lgfr CARG1, CARG1\n  |  brasl r14, extern ldexp\t// (double, int)\n  |  j ->fff_resf0\n  |\n  |.ffunc_n math_frexp\n  |  la CARG1, SAVE_TMP\n  |  brasl r14, extern frexp\n  |  llgf RB, SAVE_TMP\n  |  lg PC, -8(BASE)\n  |  stdy f0, -16(BASE)\n  |  setint RB\n  |  stg RB, -8(BASE)\n  |  lghi RD, 1+2\n  |  j ->fff_res\n  |\n  |.ffunc_n math_modf\n  |  lay CARG1, -16(BASE)\n  |  brasl r14, extern modf\t// (double, double*)\n  |  lg PC, -8(BASE)\n  |  stdy f0, -8(BASE)\n  |  lghi RD, 1+2\n  |  j ->fff_res\n  |\n  |.macro math_minmax, name, cjmp\n  |  .ffunc name\n  |  lghi RA, 2*8\n  |  sllg TMPR1, RD, 3\n  |  lg RB, 0(BASE)\n  |  ld f0, 0(BASE)\n  |  checkint RB, >4\n  |1:  // Handle integers.\n  |  clgr RA, TMPR1; jhe ->fff_resRB\n  |  lg TMPR0, -8(RA, BASE)\n  |  checkint TMPR0, >3\n  |  cr RB, TMPR0\n  |  cjmp >2\n  |  lgr RB, TMPR0\n  |2:\n  |  aghi RA, 8\n  |  j <1\n  |3:\n  |  jh ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  cdfbr f0, RB\n  |  ldgr f1, TMPR0\n  |  j >6\n  |4:\n  |  jh ->fff_fallback\n  |5:  // Handle numbers or integers.\n  |  clgr RA, TMPR1; jhe ->fff_resf0\n  |  lg RB, -8(RA, BASE)\n  |  ldy f1, -8(RA, BASE)\n  |  checknumx RB, >6, jl\n  |  jh ->fff_fallback\n  |  cdfbr f1, RB\n  |6:\n  |  cdbr f0, f1\n  |  cjmp >7\n  |  ldr f0, f1\n  |7:\n  |  aghi RA, 8\n  |  j <5\n  |.endmacro\n  |\n  |  math_minmax math_min, jnh\n  |  math_minmax math_max, jnl\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  chi NARGS:RD, 1+1;  jne ->fff_fallback\n  |  lg STR:RB, 0(BASE)\n  |  checkstr STR:RB, ->fff_fallback\n  |  lg PC, -8(BASE)\n  |  ltg TMPR0, STR:RB->len\n  |  je ->fff_res0\t\t\t// Return no results for empty string.\n  |  llgc RB, STR:RB[1]\n  |  j ->fff_resi\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  chi NARGS:RD, 1+1;  jne ->fff_fallback\t// *Exactly* 1 arg.\n  |  lg RB, 0(BASE)\n  |  checkint RB, ->fff_fallback\n  |  clfi RB, 255;  jh ->fff_fallback\n  |  strvh RB, SAVE_TMP\t\t// Store [c,0].\n  |  lghi TMPR1, 1\n  |  la RD, SAVE_TMP\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  llgfr CARG3, TMPR1\t\t\t// Zero-extended to size_t.\n  |  lgr CARG2, RD\n  |  lgr CARG1, L:RB\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_str_new\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // GCstr * returned in r2 (CRET1).\n  |  lgr STR:RD, CRET1\n  |  lg BASE, L:RB->base\n  |  lg PC, -8(BASE)\n  |  settp STR:RD, LJ_TSTR\n  |  stg STR:RD, -16(BASE)\n  |  j ->fff_res1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  lghi TMPR1, -1\n  |  clfi NARGS:RD, 1+2;  jl ->fff_fallback\n  |  jnh >1\n  |  lg TMPR1, 16(BASE)\n  |  checkint TMPR1, ->fff_fallback\n  |1:\n  |  lg STR:RB, 0(BASE)\n  |  checkstr STR:RB, ->fff_fallback\n  |  lg ITYPE, 8(BASE)\n  |  lgfr RA, ITYPE\n  |  srag ITYPE, ITYPE, 47\n  |  cghi ITYPE, LJ_TISNUM\n  |  jne ->fff_fallback\n  |  llgf RC, STR:RB->len\n  |  clr RC, TMPR1\t\t\t// len < end? (unsigned compare)\n  |  jl >5\n  |2:\n  |  cghi RA, 0\t\t\t\t// start <= 0?\n  |  jle >7\n  |3:\n  |  sr TMPR1, RA\t\t\t// start > end?\n  |  jnhe ->fff_emptystr\n  |  la RD, (#STR-1)(RA, STR:RB)\n  |  ahi TMPR1, 1\n  |4:\n  |  j ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  chi TMPR1, 0\n  |  jnl >6\n  |  ahi TMPR1, 1\n  |  ar TMPR1, RC\t\t\t// end = end+(len+1)\n  |  j <2\n  |6:  // Overflow.\n  |  lr TMPR1, RC\t\t\t// end = len\n  |  j <2\n  |\n  |7:  // Negative start or underflow.\n  |  je >8\n  |  agr RA, RC\t\t\t// start = start+(len+1)\n  |  aghi RA, 1\n  |  jh <3\t\t\t\t// start > 0?\n  |8:  // Underflow.\n  |  lghi RA, 1\t\t\t\t// start = 1\n  |  j <3\n  |\n  |->fff_emptystr:  // Range underflow.\n  |  lghi TMPR1, 0\n  |  j <4\n  |\n  |.macro ffstring_op, name\n  |  .ffunc_1 string_ .. name\n  |  ffgccheck\n  |  lg STR:CARG2, 0(BASE)\n  |  checkstr STR:CARG2, ->fff_fallback\n  |  lg L:RB, SAVE_L\n  |   lay SBUF:CARG1, (DISPATCH_GL(tmpbuf))(DISPATCH)\n  |  stg BASE, L:RB->base\n  |   lg RC, SBUF:CARG1->b\n  |   stg L:RB, SBUF:CARG1->L\n  |   stg RC, SBUF:CARG1->p\n  |  stg PC, SAVE_PC\n  |  brasl r14, extern lj_buf_putstr_ .. name\n  |  // lgr CARG1, CRET1 (nop, CARG1==CRET1)\n  |  brasl r14, extern lj_buf_tostr\n  |  j ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name, kind, fdef\n  |  fdef name\n  |.if kind == 2\n  |  bfpconst_tobit f1, RB\n  |.endif\n  |  lg RB, 0(BASE)\n  |  ld f0, 0(BASE)\n  |  checkint RB, >1\n  |.if kind > 0\n  |  j >2\n  |.else\n  |  j ->fff_resbit\n  |.endif\n  |1:\n  |  jh ->fff_fallback\n  |.if kind < 2\n  |  bfpconst_tobit f1, RB\n  |.endif\n  |  adbr f0, f1\n  |  lgdr RB, f0\n  |  llgfr RB, RB\n  |2:\n  |.endmacro\n  |\n  |.macro .ffunc_bit, name, kind\n  |  .ffunc_bit name, kind, .ffunc_1\n  |.endmacro\n  |\n  |.ffunc_bit bit_tobit, 0\n  |  j ->fff_resbit\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name, 2\n  |  lgr TMPR1, NARGS:RD\t\t// Save for fallback.\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -16(RD, BASE)\n  |1:\n  |  clgr RD, BASE\n  |  jle ->fff_resbit\n  |  lg RA, 0(RD)\n  |  checkint RA, >2\n  |  ins RB, RA\n  |  aghi RD, -8\n  |  j <1\n  |2:\n  |  jh ->fff_fallback_bit_op\n  |  ldgr f0, RA\n  |  adbr f0, f1\n  |  lgdr RA, f0\n  |  ins RB, RA\n  |  aghi RD, -8\n  |  j <1\n  |.endmacro\n  |\n  |.ffunc_bit_op bit_band, nr\n  |.ffunc_bit_op bit_bor, or\n  |.ffunc_bit_op bit_bxor, xr\n  |\n  |.ffunc_bit bit_bswap, 1\n  |  lrvr RB, RB\n  |  j ->fff_resbit\n  |\n  |.ffunc_bit bit_bnot, 1\n  |  xilf RB, -1\n  |  j ->fff_resbit\n  |\n  |->fff_fallback_bit_op:\n  |  lgr NARGS:RD, TMPR1\t\t// Restore for fallback\n  |  j ->fff_fallback\n  |\n  |.macro .ffunc_bit_sh, name, ins\n  |  .ffunc_bit name, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  lg RA, 8(BASE)\n  |  checkint RA, ->fff_fallback\n  |  nill RA, 0x1f\t// Limit shift to 5-bits.\n  |  ins RB, 0(RA)\n  |  j ->fff_resbit\n  |.endmacro\n  |\n  |.ffunc_bit_sh bit_lshift, sll\n  |.ffunc_bit_sh bit_rshift, srl\n  |.ffunc_bit_sh bit_arshift, sra\n  |\n  |.ffunc_bit bit_rol, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  lg RA, 8(BASE)\n  |  checkint RA, ->fff_fallback\n  |  rll RB, RB, 0(RA)\n  |  j ->fff_resbit\n  |\n  |.ffunc_bit bit_ror, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  lg RA, 8(BASE)\n  |  checkint RA, ->fff_fallback\n  |  lcr RA, RA\t\t// Right rotate equivalent to negative left rotate.\n  |  rll RB, RB, 0(RA)\n  |  j ->fff_resbit\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback_2:\n  |  lghi NARGS:RD, 1+2\t\t\t// Other args are ignored, anyway.\n  |  j ->fff_fallback\n  |->fff_fallback_1:\n  |  lghi NARGS:RD, 1+1\t\t\t// Other args are ignored, anyway.\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RD = nargs+1\n  |  lg L:RB, SAVE_L\n  |  lg PC, -8(BASE)\t\t\t// Fallback may overwrite PC.\n  |  stg PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  stg BASE, L:RB->base\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -8(RD, BASE)\n  |  la RA, (8*LUA_MINSTACK)(RD)\t// Ensure enough space for handler.\n  |  stg RD, L:RB->top\n  |  lg CFUNC:RD, -16(BASE)\n  |  cleartp CFUNC:RD\n  |  clg RA, L:RB->maxstack\n  |  jh >5\t\t\t\t// Need to grow stack.\n  |  lgr CARG1, L:RB\n  |  lg TMPR1, CFUNC:RD->f\n  |  basr r14, TMPR1\t\t\t// (lua_State *L)\n  |  lg BASE, L:RB->base\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  lgr RD, CRET1\n  |  cghi RD, 0; jh ->fff_res\t// Returned nresults+1?\n  |1:\n  |  lg RA, L:RB->top\n  |  sgr RA, BASE\n  |  srlg RA, RA, 3\n  |  cghi RD, 0\n  |    la NARGS:RD, 1(RA)\n  |    lg LFUNC:RB, -16(BASE)\n  |  jne ->vm_call_tail\t\t\t// Returned -1?\n  |  cleartp LFUNC:RB\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  lgr RA, BASE\n  |  tmll PC, FRAME_TYPE\n  |  jne >3\n  |  llgc RB, PC_RA\n  |  lcgr RB, RB\n  |  sllg RB, RB, 3\n  |  lay BASE, -16(RB, BASE)\t\t// base = base - (RB+2)*8\n  |  j ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |3:\n  |  lgr RB, PC\n  |  nill RB, -8\n  |  sgr BASE, RB\n  |  j ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  lghi CARG2, LUA_MINSTACK\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_state_growstack\t// (lua_State *L, int n)\n  |  lg BASE, L:RB->base\n  |  lghi RD, 0\t\t\t\t// Simulate a return 0.\n  |  j <1\t\t\t\t// Dumb retry (goes through ff first).\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RD = nargs+1\n  |  stg r14, SAVE_TMP\t\t\t// Save return address\n  |  lg L:RB, SAVE_L\n  |  stg PC, SAVE_PC\t\t\t// Redundant (but a defined value).\n  |  stg BASE, L:RB->base\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -8(RD, BASE)\n  |  lgr CARG1, L:RB\n  |  stg RD, L:RB->top\n  |  brasl r14, extern lj_gc_step\t// (lua_State *L)\n  |  lg BASE, L:RB->base\n  |  lg RD, L:RB->top\n  |  sgr RD, BASE\n  |  srlg RD, RD, 3\n  |  aghi NARGS:RD, 1\n  |  lg r14, SAVE_TMP\t\t\t// Restore return address.\n  |  br r14\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  llgc RD, (DISPATCH_GL(hookmask))(DISPATCH)\n  |  tmll RD, HOOK_ACTIVE\n  |  jne >5\n  |  j >1\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  llgc RD, (DISPATCH_GL(hookmask))(DISPATCH)\n  |  tmll RD, HOOK_ACTIVE\t\t// Hook already active?\n  |  jne >5\n  |\n  |  tmll RD, LUA_MASKLINE|LUA_MASKCOUNT\n  |  je >5\n  |  ly TMPR0, (DISPATCH_GL(hookcount))(DISPATCH)\n  |  ahi TMPR0, -1\n  |  sty TMPR0, (DISPATCH_GL(hookcount))(DISPATCH)\n  |  je >1\n  |  tmll RD, LUA_MASKLINE\n  |  je >5\n  |1:\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  lgr CARG2, PC\n  |  lgr CARG1, L:RB\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  brasl r14, extern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  lg BASE, L:RB->base\n  |4:\n  |  llgc RA, PC_RA\n  |5:\n  |  llgc OP, PC_OP\n  |  sllg TMPR1, OP, 3\n  |  llgh RD, PC_RD\n  |  lg TMPR1, GG_DISP2STATIC(TMPR1, DISPATCH)\n  |  br TMPR1\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  stg PC, SAVE_PC\n  |.if JIT\n  |  j >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  stg PC, SAVE_PC\n  |  oill PC, 1\t\t\t\t// Marker for hot call.\n  |1:\n  |.endif\n  |  sllg RD, NARGS:RD, 3\n  |  lay RD, -8(RD, BASE)\n  |  lg L:RB, SAVE_L\n  |  stg BASE, L:RB->base\n  |  stg RD, L:RB->top\n  |  lgr CARG2, PC\n  |  lgr CARG1, L:RB\n  |  brasl r14, extern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |  // ASMFunction returned in r2 (CRET1).\n  |  lghi TMPR0, 0\n  |  stg TMPR0, SAVE_PC\t\t\t// Invalidate for subsequent line hook.\n  |.if JIT\n  |  nill PC, -2\n  |.endif\n  |  lg BASE, L:RB->base\n  |  lg RD, L:RB->top\n  |  sgr RD, BASE\n  |  lgr RB, CRET1\n  |  llgc RA, PC_RA\n  |  srl RD, 3\n  |  ahi NARGS:RD, 1\n  |  llgfr RD, RD\n  |  br RB\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Called from an exit stub with the exit number on the stack.\n  |// The 16 bit exit number is stored with two (sign-extended) push imm8.\n  |->vm_exit_handler:\n  |  stg r0, 0\n  |  stg r0, 0\n  |->vm_exit_interp:\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called by math.floor/math.ceil fast functions.\n  |// Value to round is in f0. May clobber f0-f7 and r0. Return address is r14.\n  |.macro vm_round, name, mask\n  |->name:\n  |  lghi r0, 1\n  |  cdfbr f1, r0\n  |  didbr f0, f2, f1, mask // f0=remainder, f2=quotient.\n  |  jnle >1\n  |  ldr f0, f2\n  |  br r14\n  |1: // partial remainder (sanity check)\n  |  stg r0, 0\n  |.endmacro\n  |\n  |  vm_round vm_floor, 7 // Round towards -inf.\n  |  vm_round vm_ceil,  6 // Round towards +inf.\n  |  vm_round vm_trunc, 5 // Round towards 0.\n  |\n  |// FP modulo x%y. Called by BC_MOD* and vm_arith.\n  |->vm_mod: // NYI.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Assertions ---------------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->assert_bad_for_arg_type:\n  |  stg r0, 0\n  |  stg r0, 0\n#ifdef LUA_USE_ASSERT\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in ah/al.\n  |->vm_ffi_callback:\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |  stg r0, 0\n  |  stg r0, 0\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, r8\n  |  stmg r6, r15, 48(sp)\n  |  lgr r13, sp\t\t\t// Use r13 as frame pointer.\n  |  lgr CCSTATE, CARG1\n  |  lg r7, CCSTATE->func\n  |\n  |  // Readjust stack.\n  |  sgf sp, CCSTATE->spadj\n  |\n  |  // Copy stack slots.\n  |  llgc r1, CCSTATE->nsp\n  |  chi r1, 0\n  |  jh >2\n  |1:\n  |  lmg CARG1, CARG5, CCSTATE->gpr[0]\n  |  // TODO: conditionally load FPRs?\n  |  ld FARG1, CCSTATE->fpr[0]\n  |  ld FARG2, CCSTATE->fpr[1]\n  |  ld FARG3, CCSTATE->fpr[2]\n  |  ld FARG4, CCSTATE->fpr[3]\n  |  basr r14, r7\n  |\n  |  stg CRET1, CCSTATE->gpr[0]\n  |  std f0, CCSTATE->fpr[0]\n  |\n  |  lgr sp, r13\n  |  lmg r6, r15, 48(sp)\n  |  br r14\n  |\n  |2:\n  |  sll r1, 3\n  |  la r10, (offsetof(CCallState, stack))(CCSTATE)\t// Source.\n  |  la r11, (CCALL_SPS_EXTRA*8)(sp)\t\t\t// Destination.\n  |3:\n  |  chi r1, 256\n  |  jl >4\n  |  mvc 0(256, r11), 0(r10)\n  |  la r10, 256(r10)\n  |  la r11, 256(r11)\n  |  ahi r1, -256\n  |  j <3\n  |\n  |4:\n  |  ahi r1, -1\n  |  jl <1\n  |  larl r9, >5\n  |  ex r1, 0(r9)\n  |  j <1\n  |\n  |5:\n  |  // exrl target\n  |  mvc 0(1, r11), 0(r10)\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  (void)vk;\n  |// Note: aligning all instructions does not pay off.\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  |.macro jmp_comp, lt, ge, le, gt, target\n  ||switch (op) {\n  ||case BC_ISLT:\n  |   lt target\n  ||break;\n  ||case BC_ISGE:\n  |   ge target\n  ||break;\n  ||case BC_ISLE:\n  |   le target\n  ||break;\n  ||case BC_ISGT:\n  |   gt target\n  ||break;\n  ||default: break;  /* Shut up GCC. */\n  ||}\n  |.endmacro\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RD = src2, JMP with RD = target\n    |  ins_AD\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  ld f0, 0(RA, BASE)\n    |  ld f1, 0(RD, BASE)\n    |  lg RA, 0(RA, BASE)\n    |  lg RD, 0(RD, BASE)\n    |  srag ITYPE, RA, 47\n    |  srag RB, RD, 47\n    |\n    |  clfi ITYPE, LJ_TISNUM; jne >7\n    |  clfi RB, LJ_TISNUM; jne >8\n    |  // Both are integers.\n    |  la PC, 4(PC)\n    |  cr RA, RD\n    |  jmp_comp jhe, jl, jh, jle, >9\n    |6:\n    |  llgh RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  jh ->vmeta_comp\n    |  // RA is a number.\n    |  clfi RB, LJ_TISNUM; jl >1; jne ->vmeta_comp\n    |  // RA is a number, RD is an integer.\n    |  cdfbr f1, RD\n    |  j >1\n    |\n    |8:  // RA is an integer, RD is not an integer.\n    |  jh ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  cdfbr f0, RA\n    |1:\n    |  la PC, 4(PC)\n    |  cdbr f0, f1\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    |  jmp_comp jnl, jl, jnle, jle, <9\n    |  j <6\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  ins_AD\t// RA = src1, RD = src2, JMP with RD = target\n    |  sllg RD, RD, 3\n    |  ld f1, 0(RD, BASE)\n    |  lg RD, 0(RD, BASE)\n    |  sllg RA, RA, 3\n    |  ld f0, 0(RA, BASE)\n    |  lg RA, 0(RA, BASE)\n    |  la PC, 4(PC)\n    |  srag RB, RD, 47\n    |  srag ITYPE, RA, 47\n    |  clfi RB, LJ_TISNUM; jne >7\n    |  clfi ITYPE, LJ_TISNUM; jne >8\n    |  cr RD, RA\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  llgh RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RD is not an integer.\n    |  jh >5\n    |  // RD is a number.\n    |  clfi ITYPE, LJ_TISNUM; jl >1; jne >5\n    |  // RD is a number, RA is an integer.\n    |  cdfbr f0, RA\n    |  j >1\n    |\n    |8:  // RD is an integer, RA is not an integer.\n    |  jh >5\n    |  // RD is an integer, RA is a number.\n    |  cdfbr f1, RD\n    |  j >1\n    |\n    |1:\n    |  cdbr f0, f1\n    |4:\n  iseqne_fp:\n    if (vk) {\n      |  jne >2\t\t\t\t// Unordered means not equal.\n    } else {\n      |  je >1\t\t\t\t// Unordered means not equal.\n    }\n  iseqne_end:\n    if (vk) {\n      |1:\t\t\t\t// EQ: Branch to the target.\n      |  llgh RD, PC_RD\n      |  branchPC RD\n      |2:\t\t\t\t// NE: Fallthrough to next instruction.\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |.if not FFI\n      |3:\n      |.endif\n      |2:\t\t\t\t// NE: Branch to the target.\n      |  llgh RD, PC_RD\n      |  branchPC RD\n      |1:\t\t\t\t// EQ: Fallthrough to next instruction.\n    }\n    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||\n\t\t       op == BC_ISEQN || op == BC_ISNEN)) {\n      |  j <9\n    } else {\n      |  ins_next\n    }\n    |\n    if (op == BC_ISEQV || op == BC_ISNEV) {\n      |5:  // Either or both types are not numbers.\n      |.if FFI\n      |  clfi RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  clfi ITYPE, LJ_TCDATA; je ->vmeta_equal_cd\n      |.endif\n      |  cgr RA, RD\n      |  je <1\t\t\t\t// Same GCobjs or pvalues?\n      |  cr RB, ITYPE\n      |  jne <2\t\t\t\t// Not the same type?\n      |  clfi RB, LJ_TISTABUD\n      |  jh <2\t\t\t\t// Different objects and not table/ud?\n      |\n      |  // Different tables or userdatas. Need to check __eq metamethod.\n      |  // Field metatable must be at same offset for GCtab and GCudata!\n      |  cleartp TAB:RA\n      |  lg TAB:RB, TAB:RA->metatable\n      |  cghi TAB:RB, 0\n      |  je <2\t\t\t\t// No metatable?\n      |  tm TAB:RB->nomm, 1<<MM_eq\n      |  jne <2\t\t\t\t// Or 'no __eq' flag set?\n      if (vk) {\n\t|  lghi RB, 0\t\t\t// ne = 0\n      } else {\n\t|  lghi RB, 1\t\t\t// ne = 1\n      }\n      |  j ->vmeta_equal\t\t// Handle __eq metamethod.\n    } else {\n      |.if FFI\n      |3:\n      |  clfi ITYPE, LJ_TCDATA\n      if (LJ_DUALNUM && vk) {\n\t|  jne <9\n      } else {\n\t|  jne <2\n      }\n      |  j ->vmeta_equal_cd\n      |.endif\n    }\n    break;\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  ins_AND\t// RA = src, RD = str const, JMP with RD = target\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  lg RB, 0(RA, BASE)\n    |  la PC, 4(PC)\n    |  checkstr RB, >3\n    |  cg RB, 0(RD, KBASE)\n  iseqne_test:\n    if (vk) {\n      |  jne >2\n    } else {\n      |  je >1\n    }\n    goto iseqne_end;\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  ins_AD\t// RA = src, RD = num const, JMP with RD = target\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  ld f0, 0(RA, BASE)\n    |  lg RB, 0(RA, BASE)\n    |  ld f1, 0(RD, KBASE)\n    |  lg RD, 0(RD, KBASE)\n    |  la PC, 4(PC)\n    |  checkint RB, >7\n    |  checkint RD, >8\n    |  cr RB, RD\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  llgh RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  jh >3\n    |  // RA is a number.\n    |  checkint RD, >1\n    |  // RA is a number, RD is an integer.\n    |  cdfbr f1, RD\n    |  j >1\n    |\n    |8:  // RA is an integer, RD is a number.\n    |  cdfbr f0, RB\n    |  cdbr f0, f1\n    |  j >4\n    |1:\n    |  cdbr f0, f1\n    |4:\n    goto iseqne_fp;\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  ins_AND\t// RA = src, RD = primitive type (~), JMP with RD = target\n    |  sllg RA, RA, 3\n    |  lg RB, 0(RA, BASE)\n    |  srag RB, RB, 47\n    |  la PC, 4(PC)\n    |  cr RB, RD\n    if (!LJ_HASFFI) goto iseqne_test;\n    if (vk) {\n      |  jne >3\n      |  llgh RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n      |3:\n      |  cghi RB, LJ_TCDATA; jne <2\n      |  j ->vmeta_equal_cd\n    } else {\n      |  je >2\n      |  cghi RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  llgh RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  ins_AD\t// RA = dst or unused, RD = src, JMP with RD = target\n    |  sllg RD, RD, 3\n    |  sllg RA, RA, 3\n    |  lg ITYPE, 0(RD, BASE)\n    |  la PC, 4(PC)\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  lgr RB, ITYPE\n    }\n    |  srag ITYPE, ITYPE, 47\n    |  clfi ITYPE, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISTC) {\n      |  jhe >1\n    } else {\n      |  jl >1\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  stg RB, 0(RA, BASE)\n    }\n    |  llgh RD, PC_RD\n    |  branchPC RD\n    |1:\t\t\t\t\t// Fallthrough to the next instruction.\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  ins_AD\t// RA = src, RD = -type\n    |  lghr RD, RD\n    |  sllg RA, RA, 3\n    |  lg RB, 0(RA, BASE)\n    |  srag RB, RB, 47\n    |  agr RB, RD\n    |  jne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  ins_AD\t// RA = src, RD = -(TISNUM-1)\n    |  sllg TMPR1, RA, 3\n    |  lg TMPR1, 0(TMPR1, BASE)\n    |  checknumtp TMPR1, ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_MOV:\n    |  ins_AD\t// RA = dst, RD = src\n    |  sllg RD, RD, 3\n    |  lg RB, 0(RD, BASE)\n    |  sllg RA, RA, 3\n    |  stg RB, 0(RA, BASE)\n    |  ins_next_\n    break;\n  case BC_NOT:\n    |  ins_AD\t// RA = dst, RD = src\n    |  sllg RD, RD, 3\n    |  sllg RA, RA, 3\n    |  lg RB, 0(RD, BASE)\n    |  srag RB, RB, 47\n    |  load_false RC\n    |  cghi RB, LJ_TTRUE\n    |  je >1\n    |  load_true RC\n    |1:\n    |  stg RC, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  ins_AD\t// RA = dst, RD = src\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  lg RB, 0(RD, BASE)\n    |  checkint RB, >3\n    |  lcr RB, RB; jo >2\n    |1:\n    |  stg RB, 0(RA, BASE)\n    |  ins_next\n    |2:\n    |  llihh RB, 0x41e0 // (double)2^31\n    |  j <1\n    |3:\n    |  jh ->vmeta_unm\n    |  // Toggle sign bit.\n    |  llihh TMPR0, 0x8000\n    |  xgr RB, TMPR0\n    |  j <1\n    break;\n  case BC_LEN:\n    |  ins_AD\t// RA = dst, RD = src\n    |  sllg RD, RD, 3\n    |  lg RD, 0(RD, BASE)\n    |  checkstr RD, >2\n    |  llgf RD, STR:RD->len\n    |1:\n    |  sllg RA, RA, 3\n    |  setint RD\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    |2:\n    |  cghi ITYPE, LJ_TTAB; jne ->vmeta_len\n    |  lgr TAB:CARG1, TAB:RD\n#if LJ_52\n    |  lg TAB:RB, TAB:RD->metatable\n    |  cghi TAB:RB, 0\n    |  jne >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  brasl r14, extern lj_tab_len\t// (GCtab *t)\n    |  // Length of table returned in r2 (CRET1).\n    |  lgr RD, CRET1\n    |  llgc RA, PC_RA\n    |  j <1\n#if LJ_52\n    |9:  // Check for __len.\n    |  tm TAB:RB->nomm, 1<<MM_len\n    |  jne <3\n    |  j ->vmeta_len\t\t\t// 'no __len' flag NOT set: check.\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre\n    |  ins_ABC\n    |  sllg RB, RB, 3\n    |  sllg RC, RC, 3\n    |  sllg RA, RA, 3\n    |.endmacro\n    |\n    |.macro ins_arithfp, ins\n    |  ins_arithpre\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   ld f0, 0(RB, BASE)\n    |   ld f1, 0(RC, KBASE)\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, KBASE)\n    |   checknumtp RB, ->vmeta_arith_vno\n    |   checknumtp RC, ->vmeta_arith_vno\n    |   ins f0, f1\n    ||  break;\n    ||case 1:\n    |   ld f1, 0(RB, BASE)\n    |   ld f0, 0(RC, KBASE)\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, KBASE)\n    |   checknumtp RB, ->vmeta_arith_nvo\n    |   checknumtp RC, ->vmeta_arith_nvo\n    |   ins f0, f1\n    ||  break;\n    ||default:\n    |   ld f0, 0(RB, BASE)\n    |   ld f1, 0(RC, BASE)\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, BASE)\n    |   checknumtp RB, ->vmeta_arith_vvo\n    |   checknumtp RC, ->vmeta_arith_vvo\n    |   ins f0, f1\n    ||  break;\n    ||}\n    |  std f0, 0(RA, BASE)\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins\n    |  ins_arithpre\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, KBASE)\n    |   checkint RB, ->vmeta_arith_vno\n    |   checkint RC, ->vmeta_arith_vno\n    |   intins RB, RC; jo ->vmeta_arith_vno\n    ||  break;\n    ||case 1:\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, KBASE)\n    |   checkint RB, ->vmeta_arith_nvo\n    |   checkint RC, ->vmeta_arith_nvo\n    |   intins RC, RB; jo ->vmeta_arith_nvo\n    ||  break;\n    ||default:\n    |   lg RB, 0(RB, BASE)\n    |   lg RC, 0(RC, BASE)\n    |   checkint RB, ->vmeta_arith_vvo\n    |   checkint RC, ->vmeta_arith_vvo\n    |   intins RB, RC; jo ->vmeta_arith_vvo\n    ||  break;\n    ||}\n    ||if (vk == 1) {\n    |   // setint RC\n    |   stg RC, 0(RA, BASE)\n    ||} else {\n    |   // setint RB\n    |   stg RB, 0(RA, BASE)\n    ||}\n    |  ins_next\n    |.endmacro\n\n    |  // RA = dst, RB = src1 or num const, RC = src2 or num const\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arithdn ar\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arithdn sr\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arithpre\n    |  // For multiplication we use msgfr and check if the result\n    |  // fits in an int32_t.\n    switch(op) {\n    case BC_MULVN:\n      |  lg RB, 0(RB, BASE)\n      |  lg RC, 0(RC, KBASE)\n      |  checkint RB, ->vmeta_arith_vno\n      |  checkint RC, ->vmeta_arith_vno\n      |  lgfr RB, RB\n      |  msgfr RB, RC\n      |  lgfr RC, RB\n      |  cgr RB, RC; jne ->vmeta_arith_vno\n      break;\n    case BC_MULNV:\n      |  lg RB, 0(RB, BASE)\n      |  lg RC, 0(RC, KBASE)\n      |  checkint RB, ->vmeta_arith_nvo\n      |  checkint RC, ->vmeta_arith_nvo\n      |  lgfr RB, RB\n      |  msgfr RB, RC\n      |  lgfr RC, RB\n      |  cgr RB, RC; jne ->vmeta_arith_nvo\n      break;\n    default:\n      |  lg RB, 0(RB, BASE)\n      |  lg RC, 0(RC, BASE)\n      |  checkint RB, ->vmeta_arith_vvo\n      |  checkint RC, ->vmeta_arith_vvo\n      |  lgfr RB, RB\n      |  msgfr RB, RC\n      |  lgfr RC, RB\n      |  cgr RB, RC; jne ->vmeta_arith_vvo\n      break;\n    }\n    |  llgfr RB, RB\n    |  setint RB\n    |  stg RB, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arithfp ddbr\n    break;\n  // TODO: implement fast mod operation.\n  // x86_64 does floating point mod, however it might be better to use integer mod.\n  case BC_MODVN:\n    |  j ->vmeta_arith_vno\n    break;\n  case BC_MODNV:\n    |  j ->vmeta_arith_nvo\n    break;\n  case BC_MODVV:\n    |  j ->vmeta_arith_vvo\n    break;\n  case BC_POW:\n    |  ins_ABC\n    |  sllg RB, RB, 3\n    |  sllg RC, RC, 3\n    |  ld FARG1, 0(RB, BASE)\n    |  ld FARG2, 0(RC, BASE)\n    |  lg TMPR0, 0(RB, BASE)\n    |  checknumtp TMPR0, ->vmeta_arith_vvo\n    |  lg TMPR0, 0(RC, BASE)\n    |  checknumtp TMPR0, ->vmeta_arith_vvo\n    |  brasl r14, extern pow\t// double pow(double x, double y), result in f0.\n    |  llgc RA, PC_RA\n    |  sllg RA, RA, 3\n    |  std f0, 0(RA, BASE)\n    |  ins_next\n    break;\n\n  case BC_CAT:\n    |  ins_ABC\t// RA = dst, RB = src_start, RC = src_end\n    |  lg L:CARG1, SAVE_L\n    |  stg BASE, L:CARG1->base\n    |  lgr CARG3, RC\n    |  sgr CARG3, RB\n    |  sllg RC, RC, 3\n    |  la CARG2, 0(RC, BASE)\n    |->BC_CAT_Z:\n    |  lgr L:RB, L:CARG1\n    |  stg PC, SAVE_PC\n    |  brasl r14, extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // NULL (finished) or TValue * (metamethod) returned in r2 (CRET1).\n    |  lg BASE, L:RB->base\n    |  ltgr RC, CRET1\n    |  jne ->vmeta_binop\n    |  llgc RB, PC_RB\t\t\t// Copy result to Stk[RA] from Stk[RB].\n    |  sllg RB, RB, 3\n    |  llgc RA, PC_RA\n    |  sllg RA, RA, 3\n    |  lg RC, 0(RB, BASE)\n    |  stg RC, 0(RA, BASE)\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  sllg RD, RD, 3\n    |  lg RD, 0(RD, KBASE)\n    |  settp RD, LJ_TSTR\n    |  sllg RA, RA, 3\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  ins_AND\t// RA = dst, RD = cdata const (~)\n    |  sllg RD, RD, 3\n    |  sllg RA, RA, 3\n    |  lg RD, 0(RD, KBASE)\n    |  settp RD, LJ_TCDATA\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  ins_AD\t// RA = dst, RD = signed int16 literal\n    |  // Assumes DUALNUM.\n    |  lhr RD, RD\t\t\t// Sign-extend literal to 32-bits.\n    |  setint RD\n    |  sllg RA, RA, 3\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  ins_AD\t// RA = dst, RD = num const\n    |  sllg RD, RD, 3\n    |  ld f0, 0(RD, KBASE)\n    |  sllg RA, RA, 3\n    |  std f0, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  ins_AD\t// RA = dst, RD = primitive type (~)\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 47\n    |  lghi TMPR0, -1\n    |  xgr RD, TMPR0 // not\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  ins_AD\t// RA = dst_start, RD = dst_end\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  la RA, 8(RA, BASE)\n    |  la RD, 0(RD, BASE)\n    |  lghi RB, LJ_TNIL\n    |  stg RB, -8(RA)\t\t\t// Sets minimum 2 slots.\n    |1:\n    |  stg RB, 0(RA)\n    |  la RA, 8(RA)\n    |  clgr RA, RD\n    |  jle <1\n    |  ins_next\n    break;\n\n/* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  ins_AD\t// RA = dst, RD = upvalue #\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  lg LFUNC:RB, -16(BASE)\n    |  cleartp LFUNC:RB\n    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RD, LFUNC:RB)\n    |  lg RB, UPVAL:RB->v\n    |  lg RD, 0(RB)\n    |  stg RD, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_USETV:\n#define TV2MARKOFS \\\n ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))\n    |  ins_AD\t// RA = upvalue #, RD = src\n    |  lg LFUNC:RB, -16(BASE)\n    |  cleartp LFUNC:RB\n    |  sllg RA, RA, 3\n    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)\n    |  tm UPVAL:RB->closed, 0xff\n    |  lg RB, UPVAL:RB->v\n    |  sllg TMPR1, RD, 3\n    |  lg RA, 0(TMPR1, BASE)\n    |  stg RA, 0(RB)\n    |  je >1\n    |  // Check barrier for closed upvalue.\n    |  tmy TV2MARKOFS(RB), LJ_GC_BLACK\t\t// isblack(uv)\n    |  jne >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Upvalue is black. Check if new value is collectable and white.\n    |  srag RD, RA, 47\n    |  ahi RD, -LJ_TISGCV\n    |  clfi RD, LJ_TNUMX - LJ_TISGCV\t\t// tvisgcv(v)\n    |  jle <1\n    |  cleartp GCOBJ:RA\n    |  tm GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(v)\n    |  je <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  lgr CARG2, RB\n    |  lay GL:CARG1, GG_DISP2G(DISPATCH)\n    |  brasl r14, extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  j <1\n    break;\n#undef TV2MARKOFS\n  case BC_USETS:\n    |  ins_AND\t// RA = upvalue #, RD = str const (~)\n    |  lg LFUNC:RB, -16(BASE)\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  cleartp LFUNC:RB\n    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)\n    |  lg STR:RA, 0(RD, KBASE)\n    |  lg RD, UPVAL:RB->v\n    |  settp STR:ITYPE, STR:RA, LJ_TSTR\n    |  stg STR:ITYPE, 0(RD)\n    |  tm UPVAL:RB->marked, LJ_GC_BLACK\t\t// isblack(uv)\n    |  jne >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  tm GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(str)\n    |  je <1\n    |  tm UPVAL:RB->closed, 0xff\n    |  je <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  lgr CARG2, RD\n    |  lay GL:CARG1, GG_DISP2G(DISPATCH)\n    |  brasl r14, extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  j <1\n    break;\n  case BC_USETN:\n    |  ins_AD\t// RA = upvalue #, RD = num const\n    |  lg LFUNC:RB, -16(BASE)\n    |  sllg RA, RA, 3\n    |  sllg RD, RD, 3\n    |  cleartp LFUNC:RB\n    |  ld f0, 0(RD, KBASE)\n    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)\n    |  lg RA, UPVAL:RB->v\n    |  std f0, 0(RA)\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  ins_AD\t// RA = upvalue #, RD = primitive type (~)\n    |  lg LFUNC:RB, -16(BASE)\n    |  sllg RA, RA, 3\n    |  cleartp LFUNC:RB\n    |  lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RA, LFUNC:RB)\n    |  sllg RD, RD, 47\n    |  lghi TMPR0, -1\n    |  xgr RD, TMPR0\n    |  lg RA, UPVAL:RB->v\n    |  stg RD, 0(RA)\n    |  ins_next\n    break;\n  case BC_UCLO:\n    |  ins_AD\t// RA = level, RD = target\n    |  branchPC RD\t\t\t\t// Do this first to free RD.\n    |  lg L:RB, SAVE_L\n    |  ltg TMPR0, L:RB->openupval\n    |  je >1\n    |  stg BASE, L:RB->base\n    |  sllg RA, RA, 3\n    |  la CARG2, 0(RA, BASE)\n    |  lgr L:CARG1, L:RB\n    |  brasl r14, extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  lg BASE, L:RB->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  ins_AND\t// RA = dst, RD = proto const (~) (holding function prototype)\n    |  lg L:RB, SAVE_L\n    |  stg BASE, L:RB->base\n    |  lg CARG3, -16(BASE)\n    |  cleartp CARG3\n    |  sllg RD, RD, 3\n    |  lg CARG2, 0(RD, KBASE)\t\t// Fetch GCproto *.\n    |  lgr CARG1, L:RB\n    |  stg PC, SAVE_PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  brasl r14, extern lj_func_newL_gc\n    |  // GCfuncL * returned in r2 (CRET1).\n    |  lg BASE, L:RB->base\n    |  llgc RA, PC_RA\n    |  sllg RA, RA, 3\n    |  settp LFUNC:CRET1, LJ_TFUNC\n    |  stg LFUNC:CRET1, 0(RA, BASE)\n    |  ins_next\n    break;\n  case BC_TNEW:\n    |  ins_AD\t// RA = dst, RD = hbits|asize\n    |  lg L:RB, SAVE_L\n    |  stg BASE, L:RB->base\n    |  lg RA, (DISPATCH_GL(gc.total))(DISPATCH)\n    |  clg RA, (DISPATCH_GL(gc.threshold))(DISPATCH)\n    |  stg PC, SAVE_PC\n    |  jhe >5\n    |1:\n    |  srlg CARG3, RD, 11\n    |  llill TMPR0, 0x7ff\n    |  nr RD, TMPR0\n    |  cr RD, TMPR0\n    |  je >3\n    |2:\n    |  lgr L:CARG1, L:RB\n    |  llgfr CARG2, RD\n    |  brasl r14, extern lj_tab_new  // (lua_State *L, uint32_t asize, uint32_t hbits)\n    |  // Table * returned in r2 (CRET1).\n    |  lg BASE, L:RB->base\n    |  llgc RA, PC_RA\n    |  sllg RA, RA, 3\n    |  settp TAB:CRET1, LJ_TTAB\n    |  stg TAB:CRET1, 0(RA, BASE)\n    |  ins_next\n    |3:  // Turn 0x7ff into 0x801.\n    |  llill RD, 0x801\n    |  j <2\n    |5:\n    |  lgr L:CARG1, L:RB\n    |  brasl r14, extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  llgh RD, PC_RD\n    |  j <1\n    break;\n  case BC_TDUP:\n    |  ins_AND\t// RA = dst, RD = table const (~) (holding template table)\n    |  lg L:RB, SAVE_L\n    |  lg RA, (DISPATCH_GL(gc.total))(DISPATCH)\n    |  stg PC, SAVE_PC\n    |  clg RA, (DISPATCH_GL(gc.threshold))(DISPATCH)\n    |  stg BASE, L:RB->base\n    |  jhe >3\n    |2:\n    |  sllg RD, RD, 3\n    |  lg TAB:CARG2, 0(RD, KBASE)\n    |  lgr L:CARG1, L:RB\n    |  brasl r14, extern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n    |  // Table * returned in r2 (CRET1).\n    |  lg BASE, L:RB->base\n    |  llgc RA, PC_RA\n    |  settp TAB:CRET1, LJ_TTAB\n    |  sllg RA, RA, 3\n    |  stg TAB:CRET1, 0(RA, BASE)\n    |  ins_next\n    |3:\n    |  lgr L:CARG1, L:RB\n    |  brasl r14, extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  llgh RD, PC_RD\t\t\t\t// Need to reload RD.\n    |  lghi TMPR0, -1\n    |  xgr RD, TMPR0\t\t\t\t// not RD\n    |  j <2\n    break;\n\n  case BC_GGET:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  lg LFUNC:RB, -16(BASE)\n    |  cleartp LFUNC:RB\n    |  lg TAB:RB, LFUNC:RB->env\n    |  sllg TMPR1, RD, 3\n    |  lg STR:RC, 0(TMPR1, KBASE)\n    |  j ->BC_TGETS_Z\n    break;\n  case BC_GSET:\n    |  ins_AND\t// RA = src, RD = str const (~)\n    |  lg LFUNC:RB, -16(BASE)\n    |  cleartp LFUNC:RB\n    |  lg TAB:RB, LFUNC:RB->env\n    |  sllg TMPR1, RD, 3\n    |  lg STR:RC, 0(TMPR1, KBASE)\n    |  j ->BC_TSETS_Z\n    break;\n\n  case BC_TGETV:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  sllg RC, RC, 3\n    |  lg RC, 0(RC, BASE)\n    |  checktab TAB:RB, ->vmeta_tgetv\n    |\n    |  // Integer key?\n    |  checkint RC, >5\n    |  cl RC, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jhe ->vmeta_tgetv\t\t// Not in array part? Use fallback.\n    |  llgfr RC, RC\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  // Get array slot.\n    |  lg ITYPE, 0(RC)\n    |  cghi ITYPE, LJ_TNIL\t\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |1:\n    |  sllg RA, RA, 3\n    |  stg ITYPE, 0(RA, BASE)\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je <1\n    |  tm TAB:TMPR1->nomm, 1<<MM_index\n    |  je ->vmeta_tgetv\t\t\t// 'no __index' flag NOT set: check.\n    |  j <1\n    |\n    |5:  // String key?\n    |  cghi ITYPE, LJ_TSTR; jne ->vmeta_tgetv\n    |  cleartp STR:RC\n    |  j ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  ins_ABC\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  lghi TMPR1, -1\n    |  xgr RC, TMPR1\n    |  sllg RC, RC, 3\n    |  lg STR:RC, 0(RC, KBASE)\n    |  checktab TAB:RB, ->vmeta_tgets\n    |->BC_TGETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  l TMPR1, TAB:RB->hmask\n    |  n TMPR1, STR:RC->hash\n    |  lgfr TMPR1, TMPR1\n    |  mghi TMPR1, #NODE\n    |  ag NODE:TMPR1, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cg ITYPE, NODE:TMPR1->key\n    |  jne >4\n    |  // Get node value.\n    |  lg ITYPE, NODE:TMPR1->val\n    |  cghi ITYPE, LJ_TNIL\n    |  je >5\t\t\t\t// Key found, but nil value?\n    |2:\n    |  sllg RA, RA, 3\n    |  stg ITYPE, 0(RA, BASE)\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  lg NODE:TMPR1, NODE:TMPR1->next\n    |  cghi NODE:TMPR1, 0\n    |  jne <1\n    |  // End of hash chain: key not found, nil result.\n    |  lghi ITYPE, LJ_TNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je <2\t\t\t\t// No metatable: done.\n    |  tm TAB:TMPR1->nomm, 1<<MM_index\n    |  jne <2\t\t\t\t// 'no __index' flag set: done.\n    |  j ->vmeta_tgets\t\t\t// Caveat: preserve STR:RC.\n    break;\n  case BC_TGETB:\n    |  ins_ABC\t// RA = dst, RB = table, RC = byte literal\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  checktab TAB:RB, ->vmeta_tgetb\n    |  cl RC, TAB:RB->asize\n    |  jhe ->vmeta_tgetb\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  // Get array slot.\n    |  lg ITYPE, 0(RC)\n    |  cghi ITYPE, LJ_TNIL\n    |  je >2\n    |1:\n    |  sllg RA, RA, 3\n    |  stg ITYPE, 0(RA, BASE)\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je <1\n    |  tm TAB:TMPR1->nomm, 1<<MM_index\n    |  je ->vmeta_tgetb\t\t\t// 'no __index' flag NOT set: check.\n    |  j <1\n    break;\n  case BC_TGETR:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  cleartp TAB:RB\n    |  sllg RC, RC, 3\n    |  llgf RC, 4(RC, BASE)\t\t// Load low word (big endian).\n    |  cl RC, TAB:RB->asize\n    |  jhe ->vmeta_tgetr\t\t// Not in array part? Use fallback.\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  // Get array slot.\n    |->BC_TGETR_Z:\n    |  lg ITYPE, 0(RC)\n    |->BC_TGETR2_Z:\n    |  sllg RA, RA, 3\n    |  stg ITYPE, 0(RA, BASE)\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  sllg RC, RC, 3\n    |  lg RC, 0(RC, BASE)\n    |  checktab TAB:RB, ->vmeta_tsetv\n    |\n    |  // Integer key?\n    |  checkint RC, >5\n    |  cl RC, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jhe ->vmeta_tsetv\n    |  llgfr RC, RC\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  lghi TMPR0, LJ_TNIL\n    |  cg TMPR0, 0(RC)\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  tm TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jne >7\n    |2:  // Set array slot.\n    |  sllg RA, RA, 3\n    |  lg RB, 0(RA, BASE)\n    |  stg RB, 0(RC)\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je <1\n    |  tm TAB:TMPR1->nomm, 1<<MM_newindex\n    |  je ->vmeta_tsetv\t\t\t// 'no __newindex' flag NOT set: check.\n    |  j <1\n    |\n    |5:  // String key?\n    |  cghi ITYPE, LJ_TSTR; jne ->vmeta_tsetv\n    |  cleartp STR:RC\n    |  j ->BC_TSETS_Z\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR1\n    |  j <2\n    break;\n  case BC_TSETS:\n    |  ins_ABC\t// RA = src, RB = table, RC = str const (~)\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  lghi TMPR0, -1\n    |  xgr RC, TMPR0 // ~RC\n    |  sllg RC, RC, 3\n    |  lg STR:RC, 0(RC, KBASE)\n    |  checktab TAB:RB, ->vmeta_tsets\n    |->BC_TSETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  l TMPR1, TAB:RB->hmask\n    |  n TMPR1, STR:RC->hash\n    |  lgfr TMPR1, TMPR1\n    |  mghi TMPR1, #NODE\n    |  mvi TAB:RB->nomm, 0\t\t// Clear metamethod cache.\n    |  ag NODE:TMPR1, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cg ITYPE, NODE:TMPR1->key\n    |  jne >5\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  lghi TMPR0, LJ_TNIL\n    |  cg TMPR0, 0(TMPR1)\n    |  je >4\t\t\t\t// Previous value is nil?\n    |2:\n    |  tm TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jne >7\n    |3:  // Set node value.\n    |  sllg RA, RA, 3\n    |  lg ITYPE, 0(RA, BASE)\n    |  stg ITYPE, 0(TMPR1)\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  lg TAB:ITYPE, TAB:RB->metatable\n    |  cghi TAB:ITYPE, 0\n    |  je <2\n    |  tm TAB:ITYPE->nomm, 1<<MM_newindex\n    |  je ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |  j <2\n    |\n    |5:  // Follow hash chain.\n    |  lg NODE:TMPR1, NODE:TMPR1->next\n    |  cghi NODE:TMPR1, 0\n    |  jne <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je >6\t\t\t\t// No metatable: continue.\n    |  tm TAB:TMPR1->nomm, 1<<MM_newindex\n    |  je ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  stg ITYPE, SAVE_TMP\n    |  lg L:CARG1, SAVE_L\n    |  stg BASE, L:CARG1->base\n    |  la CARG3, SAVE_TMP\n    |  lgr CARG2, TAB:RB\n    |  stg PC, SAVE_PC\n    |  brasl r14, extern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Handles write barrier for the new key. TValue * returned in r2 (CRET1).\n    |  lgr TMPR1, CRET1\n    |  lg L:CRET1, SAVE_L\n    |  lg BASE, L:CRET1->base\n    |  llgc RA, PC_RA\n    |  j <2\t\t\t\t// Must check write barrier for value.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, ITYPE\n    |  j <3\n    break;\n  case BC_TSETB:\n    |  ins_ABC\t// RA = src, RB = table, RC = byte literal\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  checktab TAB:RB, ->vmeta_tsetb\n    |  cl RC, TAB:RB->asize\n    |  jhe ->vmeta_tsetb\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  lghi TMPR0, LJ_TNIL\n    |  cg TMPR0, 0(RC)\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  tm TAB:RB->marked, LJ_GC_BLACK\t\t// isblack(table)\n    |  jne >7\n    |2:\t // Set array slot.\n    |  sllg RA, RA, 3\n    |  lg ITYPE, 0(RA, BASE)\n    |  stg ITYPE, 0(RC)\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  lg TAB:TMPR1, TAB:RB->metatable\n    |  cghi TAB:TMPR1, 0\n    |  je <1\n    |  tm TAB:TMPR1->nomm, 1<<MM_newindex\n    |  je ->vmeta_tsetb\t\t\t// 'no __newindex' flag NOT set: check.\n    |  j <1\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR1\n    |  j <2\n    break;\n  case BC_TSETR:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  sllg RB, RB, 3\n    |  lg TAB:RB, 0(RB, BASE)\n    |  cleartp TAB:RB\n    |  sllg RC, RC, 3\n    |  lg RC, 0(RC, BASE)\n    |  tm TAB:RB->marked, LJ_GC_BLACK\t\t\t// isblack(table)\n    |  jne >7\n    |2:\n    |  cl RC, TAB:RB->asize\n    |  jhe ->vmeta_tsetr\n    |  llgfr RC, RC\n    |  sllg RC, RC, 3\n    |  ag RC, TAB:RB->array\n    |  // Set array slot.\n    |->BC_TSETR_Z:\n    |  sllg RA, RA, 3\n    |  lg ITYPE, 0(RA, BASE)\n    |  stg ITYPE, 0(RC)\n    |  ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR1\n    |  j <2\n    break;\n\n  case BC_TSETM:\n    |  ins_AD\t// RA = base (table at base-1), RD = num const (start index)\n    |1:\n    |  sllg RA, RA, 3\n    |  sllg TMPR1, RD, 3\n    |  llgf TMPR1, 4(TMPR1, KBASE)\t// Integer constant is in lo-word.\n    |  la RA, 0(RA, BASE)\n    |  lg TAB:RB, -8(RA)\t\t// Guaranteed to be a table.\n    |  cleartp TAB:RB\n    |  tm TAB:RB->marked, LJ_GC_BLACK\t\t// isblack(table)\n    |  jne >7\n    |2:\n    |  llgf RD, SAVE_MULTRES\n    |  aghi RD, -1\n    |  je >4\t\t\t\t// Nothing to copy?\n    |  agr RD, TMPR1\t\t\t// Compute needed size.\n    |  clgf RD, TAB:RB->asize\n    |  jh >5\t\t\t\t// Doesn't fit into array part?\n    |  sgr RD, TMPR1\n    |  sllg TMPR1, TMPR1, 3\n    |  ag TMPR1, TAB:RB->array\n    |3:  // Copy result slots to table.\n    |  lg RB, 0(RA)\n    |  la RA, 8(RA)\n    |  stg RB, 0(TMPR1)\n    |  la TMPR1, 8(TMPR1)\n    |  brctg RD, <3\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  lg L:CARG1, SAVE_L\n    |  stg BASE, L:CARG1->base\n    |  lgr CARG2, TAB:RB\n    |  lgfr CARG3, RD\n    |  lgr L:RB, L:CARG1\n    |  stg PC, SAVE_PC\n    |  brasl r14, extern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |  lg BASE, L:RB->base\n    |  llgc RA, PC_RA\t\t\t// Restore RA.\n    |  llgh RD, PC_RD\t\t\t// Restore RD.\n    |  j <1\t\t\t\t// Retry.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:RB, RD\n    |  j <2\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALL: case BC_CALLM:\n    |  ins_A_C\t// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs\n    |  sllg RA, RA, 3\n    |  lgr RD, RC\n    if (op == BC_CALLM) {\n      |  agf NARGS:RD, SAVE_MULTRES\n    }\n    |  lg LFUNC:RB, 0(RA, BASE)\n    |  checkfunc LFUNC:RB, ->vmeta_call_ra\n    |  la BASE, 16(RA, BASE)\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  ins_AD\t// RA = base, RD = extra_nargs\n    |  a NARGS:RD, SAVE_MULTRES\n    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.\n    break;\n  case BC_CALLT:\n    |  ins_AD\t// RA = base, RD = nargs+1\n    |  sllg RA, RA, 3\n    |  la RA, 16(RA, BASE)\n    |  lgr KBASE, BASE\t\t\t// Use KBASE for move + vmeta_call hint.\n    |  lg LFUNC:RB, -16(RA)\n    |  checktp_nc LFUNC:RB, LJ_TFUNC, ->vmeta_call\n    |->BC_CALLT_Z:\n    |  lg PC, -8(BASE)\n    |  tmll PC, FRAME_TYPE\n    |  jne >7\n    |1:\n    |  stg LFUNC:RB, -16(BASE)\t\t// Copy func+tag down, reloaded below.\n    |  st NARGS:RD, SAVE_MULTRES\n    |  aghi NARGS:RD, -1\n    |  je >3\n    |2:  // Move args down.\n    |  lg RB, 0(RA)\n    |  la RA, 8(RA)\n    |  stg RB, 0(KBASE)\n    |  la KBASE, 8(KBASE)\n    |  brctg NARGS:RD, <2\n    |\n    |  lg LFUNC:RB, -16(BASE)\n    |3:\n    |  cleartp LFUNC:RB\n    |  llgf NARGS:RD, SAVE_MULTRES\n    |  llgc TMPR1, LFUNC:RB->ffid\n    |  cghi TMPR1, 1\t\t\t// (> FF_C) Calling a fast function?\n    |  jh >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function.\n    |  tmll PC, FRAME_TYPE\t\t// Lua frame below?\n    |  jne <4\n    |  llgc RA, PC_RA\n    |  lcgr RA, RA\n    |  sllg RA, RA, 3\n    |  lg LFUNC:KBASE, -32(RA, BASE)\t// Need to prepare KBASE.\n    |  cleartp LFUNC:KBASE\n    |  lg KBASE, LFUNC:KBASE->pc\n    |  lg KBASE, (PC2PROTO(k))(KBASE)\n    |  j <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  aghi PC, -FRAME_VARG\n    |  tmll PC, FRAME_TYPEP\n    |  jne >8\t\t\t\t// Vararg frame below?\n    |  sgr BASE, PC\t\t\t// Need to relocate BASE/KBASE down.\n    |  lgr KBASE, BASE\n    |  lg PC, -8(BASE)\n    |  j <1\n    |8:\n    |  aghi PC, FRAME_VARG\n    |  j <1\n    break;\n\n  case BC_ITERC:\n    |  ins_A\t// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)\n    |  sllg RA, RA, 3\n    |  la RA, 16(RA, BASE)\t\t// fb = base+2\n    |  lg RB, -32(RA)\t\t\t// Copy state. fb[0] = fb[-4].\n    |  lg RC, -24(RA)\t\t\t// Copy control var. fb[1] = fb[-3].\n    |  stg RB, 0(RA)\n    |  stg RC, 8(RA)\n    |  lg LFUNC:RB, -40(RA)\t\t// Copy callable. fb[-2] = fb[-5]\n    |  stg LFUNC:RB, -16(RA)\n    |  lghi NARGS:RD, 2+1\t\t// Handle like a regular 2-arg call.\n    |  checkfunc LFUNC:RB, ->vmeta_call\n    |  lgr BASE, RA\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |  ins_A\t// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |.if JIT\n    |  // NYI: add hotloop, record BC_ITERN.\n    |.endif\n    |  sllg RA, RA, 3\n    |  lg TAB:RB, -16(RA, BASE)\n    |  cleartp TAB:RB\n    |  llgf RC, -4(RA, BASE)\t\t// Get index from control var.\n    |  llgf TMPR1, TAB:RB->asize\n    |  la PC, 4(PC)\n    |  lg ITYPE, TAB:RB->array\n    |1:  // Traverse array part.\n    |  clr RC, TMPR1; jhe >5\t\t// Index points after array part?\n    |  sllg RD, RC, 3\t\t// Warning: won't work if RD==RC!\n    |  lg TMPR0, 0(RD, ITYPE)\n    |  cghi TMPR0, LJ_TNIL;  je >4\n    |  // Copy array slot to returned value.\n    |  lgr RB, TMPR0\n    |  stg RB, 8(RA, BASE)\n    |  // Return array index as a numeric key.\n    |  setint ITYPE, RC\n    |  stg ITYPE, 0(RA, BASE)\n    |  ahi RC, 1\n    |  sty RC, -4(RA, BASE)\t\t// Update control var.\n    |2:\n    |  llgh RD, PC_RD\t\t\t// Get target from ITERL.\n    |  branchPC RD\n    |3:\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  ahi RC, 1\n    |  j <1\n    |\n    |5:  // Traverse hash part.\n    |  sr RC, TMPR1\n    |6:\n    |  cl RC, TAB:RB->hmask; jh <3\t// End of iteration? Branch to ITERL+1.\n    |  llgfr ITYPE, RC\n    |  mghi ITYPE, #NODE\n    |  ag NODE:ITYPE, TAB:RB->node\n    |  lghi TMPR0, LJ_TNIL\n    |  cg TMPR0, NODE:ITYPE->val; je >7\n    |  ar TMPR1, RC\n    |  ahi TMPR1, 1\n    |  // Copy key and value from hash slot.\n    |  lg RB, NODE:ITYPE->key\n    |  lg RC, NODE:ITYPE->val\n    |  stg RB, 0(RA, BASE)\n    |  stg RC, 8(RA, BASE)\n    |  sty TMPR1, -4(RA, BASE)\n    |  j <2\n    |\n    |7:  // Skip holes in hash part.\n    |  ahi RC, 1\n    |  j <6\n    break;\n\n  case BC_ISNEXT:\n    |  ins_AD\t// RA = base, RD = target (points to ITERN)\n    |  sllg RA, RA, 3\n    |  lg CFUNC:RB, -24(RA, BASE)\n    |  checkfunc CFUNC:RB, >5\n    |  lg TMPR1, -16(RA, BASE)\n    |  checktptp TMPR1, LJ_TTAB, >5\n    |  lghi TMPR0, LJ_TNIL\n    |  cg TMPR0, -8(RA, BASE); jne >5\n    |  llgc TMPR1, CFUNC:RB->ffid\n    |  clfi TMPR1, (uint8_t)FF_next_N; jne >5\n    |  branchPC RD\n    |  llihl TMPR1, 0x7fff\n    |  iihh TMPR1, 0xfffe\n    |  stg TMPR1, -8(RA, BASE)\t\t// Initialize control var.\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  lghi TMPR0, BC_JMP\n    |  stcy  TMPR0, PC_OP\n    |  branchPC RD\n    |  mvi 3(PC), BC_ITERC\n    |  j <1\n    break;\n\n  case BC_VARG:\n    |  ins_ABC\t// RA = base, RB = nresults+1, RC = numparams\n    |  sllg RA, RA, 3\n    |  sllg RB, RB, 3\n    |  sllg RC, RC, 3\n    |  la TMPR1, (16+FRAME_VARG)(RC, BASE)\n    |  la RA, 0(RA, BASE)\n    |  sg TMPR1, -8(BASE)\n    |  // Note: TMPR1 may now be even _above_ BASE if nargs was < numparams.\n    |  cghi RB, 0\n    |  je >5\t\t\t\t// Copy all varargs?\n    |  lay RB, -8(RA, RB)\n    |  clgr TMPR1, BASE\t\t\t// No vararg slots?\n    |  lghi TMPR0, LJ_TNIL\n    |  jnl >2\n    |1:  // Copy vararg slots to destination slots.\n    |  lg RC, -16(TMPR1)\n    |  la TMPR1, 8(TMPR1)\n    |  stg RC, 0(RA)\n    |  la RA, 8(RA)\n    |  clgr RA, RB\t\t\t// All destination slots filled?\n    |  jnl >3\n    |  clgr TMPR1, BASE\t\t\t// No more vararg slots?\n    |  jl <1\n    |2:  // Fill up remainder with nil.\n    |  stg TMPR0, 0(RA)\n    |  la RA, 8(RA)\n    |  clgr RA, RB\n    |  jl <2\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  lghi TMPR0, 1\n    |  st TMPR0, SAVE_MULTRES\t\t// MULTRES = 0+1\n    |  lgr RC, BASE\n    |  slgr RC, TMPR1\n    |  jno <3\t\t\t\t// No vararg slots? (borrow or zero)\n    |  llgfr RB, RC\n    |  srlg RB, RB, 3\n    |  ahi RB, 1\n    |  st RB, SAVE_MULTRES\t\t// MULTRES = #varargs+1\n    |  lg L:RB, SAVE_L\n    |  agr RC, RA\n    |  clg RC, L:RB->maxstack\n    |  jh >7\t\t\t\t// Need to grow stack?\n    |6:  // Copy all vararg slots.\n    |  lg RC, -16(TMPR1)\n    |  la TMPR1, 8(TMPR1)\n    |  stg RC, 0(RA)\n    |  la RA, 8(RA)\n    |  clgr TMPR1, BASE\t\t\t// No more vararg slots?\n    |  jl <6\n    |  j <3\n    |\n    |7:  // Grow stack for varargs.\n    |  stg BASE, L:RB->base\n    |  stg RA, L:RB->top\n    |  stg PC, SAVE_PC\n    |  sgr TMPR1, BASE\t\t\t// Need delta, because BASE may change.\n    |  st TMPR1, SAVE_TMP_HI\n    |  llgf CARG2, SAVE_MULTRES\n    |  aghi CARG2, -1\n    |  lgr CARG1, L:RB\n    |  brasl r14, extern lj_state_growstack\t// (lua_State *L, int n)\n    |  lg BASE, L:RB->base\n    |  lgf TMPR1, SAVE_TMP_HI\n    |  lg RA, L:RB->top\n    |  agr TMPR1, BASE\n    |  j <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  ins_AD\t// RA = results, RD = extra_nresults\n    |  agf RD, SAVE_MULTRES\t\t\t// MULTRES >=1, so RD >=1.\n    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.\n    break;\n\n  case BC_RET: case BC_RET0: case BC_RET1:\n    |  ins_AD\t// RA = results, RD = nresults+1\n    if (op != BC_RET0) {\n      |  sllg RA, RA, 3\n    }\n    |1:\n    |  lg PC, -8(BASE)\n    |  st RD, SAVE_MULTRES\t\t// Save nresults+1.\n    |  tmll PC, FRAME_TYPE\t\t// Check frame type marker.\n    |  jne >7\t\t\t\t// Not returning to a fixarg Lua func?\n    switch (op) {\n    case BC_RET:\n      |->BC_RET_Z:\n      |  lgr KBASE, BASE\t\t// Use KBASE for result move.\n      |  aghi RD, -1\n      |  je >3\n      |2:  // Move results down.\n      |  lg RB, 0(KBASE, RA)\n      |  stg RB, -16(KBASE)\n      |  la KBASE, 8(KBASE)\n      |  brctg RD, <2\n      |3:\n      |  llgf RD, SAVE_MULTRES\t\t// Note: MULTRES may be >256.\n      |  llgc RB, PC_RB\n      |5:\n      |  cgr RB, RD\t\t\t// More results expected?\n      |  jh >6\n      break;\n    case BC_RET1:\n      |  lg RB, 0(BASE, RA)\n      |  stg RB, -16(BASE)\n      /* fallthrough */\n    case BC_RET0:\n      |5:\n      |  llgc TMPR1, PC_RB\n      |  cgr TMPR1, RD\n      |  jh >6\n    default:\n      break;\n    }\n    |  llgc RA, PC_RA\n    |  lcgr RA, RA\n    |  sllg RA, RA, 3\n    |  lay BASE, -16(RA, BASE)\t\t// base = base - (RA+2)*8\n    |  lg LFUNC:KBASE, -16(BASE)\n    |  cleartp LFUNC:KBASE\n    |  lg KBASE, LFUNC:KBASE->pc\n    |  lg KBASE, PC2PROTO(k)(KBASE)\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    |  lghi TMPR1, LJ_TNIL\n    if (op == BC_RET) {\n      |  stg TMPR1, -16(KBASE)\t\t// Note: relies on shifted base.\n      |  la KBASE, 8(KBASE)\n    } else {\n      |  sllg RC, RD, 3 \t\t// RC used as temp.\n      |  stg TMPR1, -24(RC, BASE)\n    }\n    |  la RD, 1(RD)\n    |  j <5\n    |\n    |7:  // Non-standard return case.\n    |  lay RB, -FRAME_VARG(PC)\n    |  tmll RB, FRAME_TYPEP\n    |  jne ->vm_return\n    |  // Return from vararg function: relocate BASE down and RA up.\n    |  sgr BASE, RB\n    if (op != BC_RET0) {\n      |  agr RA, RB\n    }\n    |  j <1\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  0(RA)\n  |.define FOR_STOP, 8(RA)\n  |.define FOR_STEP, 16(RA)\n  |.define FOR_EXT,  24(RA)\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ins_AJ\t// RA = base, RD = target (after end of loop or start of loop)\n    |  sllg RA, RA, 3\n    |  la RA, 0(RA, BASE)\n    |  lg RB, FOR_IDX\n    |  checkint RB, >9\n    |  lg TMPR1, FOR_STOP\n    if (!vk) {\n      |  checkint TMPR1, ->vmeta_for\n      |  lg ITYPE, FOR_STEP\n      |  chi ITYPE, 0; jl >5\n      |  srag ITYPE, ITYPE, 47\n      |  cghi ITYPE, LJ_TISNUM; jne ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  // lg TMPR1, FOR_STOP\n      |  checkinttp TMPR1, ->assert_bad_for_arg_type\n      |  lg TMPR0, FOR_STEP\n      |  checkinttp TMPR0, ->assert_bad_for_arg_type\n#endif\n      |  lg ITYPE, FOR_STEP\n      |  chi ITYPE, 0; jl >5\n      |  ar RB, ITYPE; jo >1\n      |  setint RB\n      |  stg RB, FOR_IDX\n    }\n    |  cr RB, TMPR1\n    |  stg RB, FOR_EXT\n    if (op == BC_FORI) {\n      |  jle >7\n      |1:\n      |6:\n      |  branchPC RD\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  llgh RD, PC_RD\n      |  jle =>BC_JLOOP\n      |1:\n      |6:\n    } else if (op == BC_IFORL) {\n      |  jh >7\n      |6:\n      |  branchPC RD\n      |1:\n    } else {\n      |  jle =>BC_JLOOP\n      |1:\n      |6:\n    }\n    |7:\n    |  ins_next\n    |\n    |5:  // Invert check for negative step.\n    if (!vk) {\n      |  srag ITYPE, ITYPE, 47\n      |  cghi ITYPE, LJ_TISNUM; jne ->vmeta_for\n    } else {\n      |  ar RB, ITYPE; jo <1\n      |  setint RB\n      |  stg RB, FOR_IDX\n    }\n    |  cr RB, TMPR1\n    |  stg RB, FOR_EXT\n    if (op == BC_FORI) {\n      |  jhe <7\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  llgh RD, PC_RD\n      |  jhe =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  jl <7\n    } else {\n      |  jhe =>BC_JLOOP\n    }\n    |  j <6\n    |9:  // Fallback to FP variant.\n    if (!vk) {\n      |  jhe ->vmeta_for\n    }\n    if (!vk) {\n      |  lg TMPR0, FOR_STOP\n      |  checknumtp TMPR0, ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  lg TMPR0, FOR_STOP\n      |  checknumtp TMPR0, ->assert_bad_for_arg_type\n      |  lg TMPR0, FOR_STEP\n      |  checknumtp TMPR0, ->assert_bad_for_arg_type\n#endif\n    }\n    |  lg RB, FOR_STEP\n    if (!vk) {\n      |  checknum RB, ->vmeta_for\n    }\n    |  ld f0, FOR_IDX\n    |  ld f1, FOR_STOP\n    if (vk) {\n      |  adb f0, FOR_STEP\n      |  std f0, FOR_IDX\n    }\n    |  cghi RB, 0; jl >3\n    |  cdbr f1, f0\n    |1:\n    |  std f0, FOR_EXT\n    if (op == BC_FORI) {\n      |  jnl <7\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  llgh RD, PC_RD\n      |  jnl =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |  jl <7\n    } else {\n      |  jnl =>BC_JLOOP\n    }\n    |  j <6\n    |\n    |3:  // Invert comparison if step is negative.\n    |  cdbr f0, f1\n    |  j <1\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  ins_AJ\t// RA = base, RD = target\n    |  sllg RA, RA, 3\n    |  la RA, 0(RA, BASE)\n    |  lg RB, 0(RA)\n    |  cghi RB, LJ_TNIL; je >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  stg RB, -8(RA)\n      |  j =>BC_JLOOP\n    } else {\n      |  branchPC RD\t\t\t// Otherwise save control var + branch.\n      |  stg RB, -8(RA)\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.\n    break;\n\n  case BC_ILOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |  stg r0, 0\n    |  stg r0, 0\n    break;\n\n  case BC_JMP:\n    |  ins_AJ\t// RA = unused, RD = target\n    |  branchPC RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n   /*\n   ** Reminder: A function may be called with func/args above L->maxstack,\n   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,\n   ** too. This means all FUNC* ops (including fast functions) must check\n   ** for stack overflow _before_ adding more slots!\n   */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  stg r0, 0\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  lg KBASE, (PC2PROTO(k)-4)(PC)\n    |  lg L:RB, SAVE_L\n    |  sllg RA, RA, 3\n    |  la RA, 0(RA, BASE)\t\t// Top of frame.\n    |  clg RA, L:RB->maxstack\n    |  jh ->vm_growstack_f\n    |  llgc RA, (PC2PROTO(numparams)-4)(PC)\n    |  clgr NARGS:RD, RA\t\t// Check for missing parameters.\n    |  jle >3\n    |2:\n    if (op == BC_JFUNCF) {\n      |  llgh RD, PC_RD\n      |  j =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  sllg TMPR1, NARGS:RD, 3\n    |  lghi TMPR0, LJ_TNIL\n    |4:\n    |  stg TMPR0, -8(TMPR1, BASE)\n    |  la TMPR1, 8(TMPR1)\n    |  la RD, 1(RD)\n    |  clgr RD, RA\n    |  jle <4\n    |  j <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    | stg r0, 0  // NYI: compiled vararg functions\n    break;           /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  sllg TMPR1, NARGS:RD, 3\n    |  la RB, (FRAME_VARG+8)(TMPR1)\n    |  la RD, 8(TMPR1, BASE)\n    |  lg LFUNC:KBASE, -16(BASE)\n    |  stg RB, -8(RD)\t\t\t// Store delta + FRAME_VARG.\n    |  stg LFUNC:KBASE, -16(RD)\t\t// Store copy of LFUNC.\n    |  lg L:RB, SAVE_L\n    |  sllg RA, RA, 3\n    |  la RA, 0(RA, RD)\n    |  cg RA, L:RB->maxstack\n    |  jh ->vm_growstack_v\t\t// Need to grow stack.\n    |  lgr RA, BASE\n    |  lgr BASE, RD\n    |  llgc RB, (PC2PROTO(numparams)-4)(PC)\n    |  cghi RB, 0\n    |  je >2\n    |  aghi RA, 8\n    |  lghi TMPR1, LJ_TNIL\n    |1:  // Copy fixarg slots up to new frame.\n    |  la RA, 8(RA)\n    |  cgr RA, BASE\n    |  jnl >3\t\t\t\t// Less args than parameters?\n    |  lg KBASE, -16(RA)\n    |  stg KBASE, 0(RD)\n    |  la RD, 8(RD)\n    |  stg TMPR1, -16(RA)\t// Clear old fixarg slot (help the GC).\n    |  brctg RB, <1\n    |2:\n    if (op == BC_JFUNCV) {\n      |  llgh RD, PC_RD\n      |  j =>BC_JLOOP\n    } else {\n      |  lg KBASE, (PC2PROTO(k)-4)(PC)\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  stg TMPR1, 0(RD)\t\t\t// TMPR1=LJ_TNIL (-1) here.\n    |  la RD, 8(RD)\n    |  brctg RB, <3\n    |  j <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  ins_AD  // BASE = new base, RD = nargs+1\n    |  lg CFUNC:RB, -16(BASE)\n    |  cleartp CFUNC:RB\n    |  lg KBASE, CFUNC:RB->f\n    |  lg L:RB, SAVE_L\n    |  sllg RD, NARGS:RD, 3\n    |  lay RD, -8(RD,BASE)\n    |  stg BASE, L:RB->base\n    |  la RA, (8*LUA_MINSTACK)(RD)\n    |  clg RA, L:RB->maxstack\n    |  stg RD, L:RB->top\n    |  lgr CARG1, L:RB\n    if (op != BC_FUNCC) {\n      |  lgr CARG2, KBASE\n    }\n    |  jh ->vm_growstack_c\t\t// Need to grow stack.\n    |  set_vmstate C\n    if (op == BC_FUNCC) {\n      |  basr r14, KBASE\t\t// (lua_State *L)\n    } else {\n      |  // (lua_State *L, lua_CFunction f)\n      |  lg TMPR1, (DISPATCH_GL(wrapf))(DISPATCH)\n      |  basr r14, TMPR1\n    }\n    |  // nresults returned in r2 (CRET1).\n    |  lgr RD, CRET1\n    |  lg BASE, L:RB->base\n    |  stg L:RB, (DISPATCH_GL(cur_L))(DISPATCH)\n    |  set_vmstate INTERP\n    |  sllg TMPR1, RD, 3\n    |  la RA, 0(TMPR1, BASE)\n    |  lcgr RA, RA\n    |  ag RA, L:RB->top\t\t\t// RA = (L->top-(L->base+nresults))*8\n    |  lg PC, -8(BASE)\t\t\t// Fetch PC of caller.\n    |  j ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n  dasm_growpc(Dst, BC__MAX);\n  build_subroutines(ctx);\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0xe\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 0xf\\n\\t.uleb128 160\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0xe\\n\"\t/* offset r6 */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0xd\\n\"\t/* offset r7 */\n\t\"\\t.byte 0x88\\n\\t.uleb128 0xc\\n\"\t/* offset r8 */\n\t\"\\t.byte 0x89\\n\\t.uleb128 0xb\\n\"\t/* offset r9 */\n\t\"\\t.byte 0x8a\\n\\t.uleb128 0xa\\n\"\t/* offset r10 */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 0x9\\n\"\t/* offset r11 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x8\\n\"\t/* offset r12 */\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x7\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x6\\n\"\t/* offset r14 */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x5\\n\"\t/* offset r15 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE0:\\n\\n\", fcofs, CFRAME_SIZE+160);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 160\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xd\\n\"\t\t/* def_cfa_register r13 (FP) */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0xe\\n\"\t/* offset r6 */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0xd\\n\"\t/* offset r7 */\n\t\"\\t.byte 0x88\\n\\t.uleb128 0xc\\n\"\t/* offset r8 */\n\t\"\\t.byte 0x89\\n\\t.uleb128 0xb\\n\"\t/* offset r9 */\n\t\"\\t.byte 0x8a\\n\\t.uleb128 0xa\\n\"\t/* offset r10 */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 0x9\\n\"\t/* offset r11 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x8\\n\"\t/* offset r12 */\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x7\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x6\\n\"\t/* offset r14 */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x5\\n\"\t/* offset r15 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0xe\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0xf\\n\\t.uleb128 160\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0xe\\n\"\t/* offset r6 */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0xd\\n\"\t/* offset r7 */\n\t\"\\t.byte 0x88\\n\\t.uleb128 0xc\\n\"\t/* offset r8 */\n\t\"\\t.byte 0x89\\n\\t.uleb128 0xb\\n\"\t/* offset r9 */\n\t\"\\t.byte 0x8a\\n\\t.uleb128 0xa\\n\"\t/* offset r10 */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 0x9\\n\"\t/* offset r11 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x8\\n\"\t/* offset r12 */\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x7\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x6\\n\"\t/* offset r14 */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x5\\n\"\t/* offset r15 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE2:\\n\\n\", fcofs, CFRAME_SIZE+160);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0xe\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0xf\\n\\t.uleb128 160\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 160\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0xd\\n\"\t\t/* def_cfa_register r13 (FP) */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0xe\\n\"\t/* offset r6 */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0xd\\n\"\t/* offset r7 */\n\t\"\\t.byte 0x88\\n\\t.uleb128 0xc\\n\"\t/* offset r8 */\n\t\"\\t.byte 0x89\\n\\t.uleb128 0xb\\n\"\t/* offset r9 */\n\t\"\\t.byte 0x8a\\n\\t.uleb128 0xa\\n\"\t/* offset r10 */\n\t\"\\t.byte 0x8b\\n\\t.uleb128 0x9\\n\"\t/* offset r11 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x8\\n\"\t/* offset r12 */\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x7\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x6\\n\"\t/* offset r14 */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x5\\n\"\t/* offset r15 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n  default:  /* No other modes. */\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_x64.dasc",
    "content": "|// Low-level VM code for x64 CPUs in LJ_GC64 mode.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|\n|.arch x64\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|//-----------------------------------------------------------------------\n|\n|.if WIN\n|.define X64WIN, 1\t\t\t// Windows/x64 calling conventions.\n|.endif\n|\n|// Fixed register assignments for the interpreter.\n|// This is very fragile and has many dependencies. Caveat emptor.\n|.define BASE,\t\trdx\t\t// Not C callee-save, refetched anyway.\n|.if X64WIN\n|.define KBASE,\t\trdi\t\t// Must be C callee-save.\n|.define PC,\t\trsi\t\t// Must be C callee-save.\n|.define DISPATCH,\trbx\t\t// Must be C callee-save.\n|.define KBASEd,\tedi\n|.define PCd,\t\tesi\n|.define DISPATCHd,\tebx\n|.else\n|.define KBASE,\t\tr15\t\t// Must be C callee-save.\n|.define PC,\t\trbx\t\t// Must be C callee-save.\n|.define DISPATCH,\tr14\t\t// Must be C callee-save.\n|.define KBASEd,\tr15d\n|.define PCd,\t\tebx\n|.define DISPATCHd,\tr14d\n|.endif\n|\n|.define RA,\t\trcx\n|.define RAd,\t\tecx\n|.define RAH,\t\tch\n|.define RAL,\t\tcl\n|.define RB,\t\trbp\t\t// Must be rbp (C callee-save).\n|.define RBd,\t\tebp\n|.define RC,\t\trax\t\t// Must be rax.\n|.define RCd,\t\teax\n|.define RCW,\t\tax\n|.define RCH,\t\tah\n|.define RCL,\t\tal\n|.define OP,\t\tRBd\n|.define RD,\t\tRC\n|.define RDd,\t\tRCd\n|.define RDW,\t\tRCW\n|.define RDL,\t\tRCL\n|.define TMPR,\t\tr10\n|.define TMPRd,\t\tr10d\n|.define ITYPE,\t\tr11\n|.define ITYPEd,\tr11d\n|\n|.if X64WIN\n|.define CARG1,\t\trcx\t\t// x64/WIN64 C call arguments.\n|.define CARG2,\t\trdx\n|.define CARG3,\t\tr8\n|.define CARG4,\t\tr9\n|.define CARG1d,\tecx\n|.define CARG2d,\tedx\n|.define CARG3d,\tr8d\n|.define CARG4d,\tr9d\n|.else\n|.define CARG1,\t\trdi\t\t// x64/POSIX C call arguments.\n|.define CARG2,\t\trsi\n|.define CARG3,\t\trdx\n|.define CARG4,\t\trcx\n|.define CARG5,\t\tr8\n|.define CARG6,\t\tr9\n|.define CARG1d,\tedi\n|.define CARG2d,\tesi\n|.define CARG3d,\tedx\n|.define CARG4d,\tecx\n|.define CARG5d,\tr8d\n|.define CARG6d,\tr9d\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|//-----------------------------------------------------------------------\n|.if X64WIN\t\t// x64/Windows stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rdi; push rsi; push rbx\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|  pop rbx; pop rsi; pop rdi; pop rbp\n|.endmacro\n|\n|.define SAVE_CFRAME,\taword [rsp+aword*13]\n|.define SAVE_PC,\taword [rsp+aword*12]\n|.define SAVE_L,\taword [rsp+aword*11]\n|.define SAVE_ERRF,\tdword [rsp+dword*21]\n|.define SAVE_NRES,\tdword [rsp+dword*20]\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.define ARG5,\t\taword [rsp+aword*4]\n|.define CSAVE_4,\taword [rsp+aword*3]\n|.define CSAVE_3,\taword [rsp+aword*2]\n|.define CSAVE_2,\taword [rsp+aword*1]\n|.define CSAVE_1,\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee\n|\n|.define ARG5d,\t\tdword [rsp+dword*8]\n|.define TMP1,\t\tARG5\t\t\t// TMP1 overlaps ARG5\n|.define TMP1d,\t\tARG5d\n|.define TMP1hi,\tdword [rsp+dword*9]\n|.define MULTRES,\tTMP1d\t\t\t// MULTRES overlaps TMP1d.\n|\n|//-----------------------------------------------------------------------\n|.else\t\t\t// x64/POSIX stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rbx; push r15; push r14\n|.if NO_UNWIND\n|  push r13; push r12\n|.endif\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|.if NO_UNWIND\n|  pop r12; pop r13\n|.endif\n|  pop r14; pop r15; pop rbx; pop rbp\n|.endmacro\n|\n|//----- 16 byte aligned,\n|.if NO_UNWIND\n|.define SAVE_RET,\taword [rsp+aword*11]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*10]\n|.define SAVE_R3,\taword [rsp+aword*9]\n|.define SAVE_R2,\taword [rsp+aword*8]\n|.define SAVE_R1,\taword [rsp+aword*7]\n|.define SAVE_RU2,\taword [rsp+aword*6]\n|.define SAVE_RU1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.else\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.endif\n|.define SAVE_CFRAME,\taword [rsp+aword*4]\n|.define SAVE_PC,\taword [rsp+aword*3]\n|.define SAVE_L,\taword [rsp+aword*2]\n|.define SAVE_ERRF,\tdword [rsp+dword*3]\n|.define SAVE_NRES,\tdword [rsp+dword*2]\n|.define TMP1,\t\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned\n|\n|.define TMP1d,\t\tdword [rsp]\n|.define TMP1hi,\tdword [rsp+dword*1]\n|.define MULTRES,\tTMP1d\t\t\t// MULTRES overlaps TMP1d.\n|\n|.endif\n|\n|//-----------------------------------------------------------------------\n|\n|// Instruction headers.\n|.macro ins_A; .endmacro\n|.macro ins_AD; .endmacro\n|.macro ins_AJ; .endmacro\n|.macro ins_ABC; movzx RBd, RCH; movzx RCd, RCL; .endmacro\n|.macro ins_AB_; movzx RBd, RCH; .endmacro\n|.macro ins_A_C; movzx RCd, RCL; .endmacro\n|.macro ins_AND; not RD; .endmacro\n|\n|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).\n|.macro ins_NEXT\n|  mov RCd, [PC]\n|  movzx RAd, RCH\n|  movzx OP, RCL\n|  add PC, 4\n|  shr RCd, 16\n|  jmp aword [DISPATCH+OP*8]\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  // Around 10%-30% slower on Core2, a lot more slower on P4.\n|  .macro ins_next\n|    jmp ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-8] = PC\n|  mov PC, LFUNC:RB->pc\n|  mov RAd, [PC]\n|  movzx OP, RAL\n|  movzx RAd, RAH\n|  add PC, 4\n|  jmp aword [DISPATCH+OP*8]\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC, RD = nargs+1\n|  mov [BASE-8], PC\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to clear or set tags.\n|.macro cleartp, reg; shl reg, 17; shr reg, 17; .endmacro\n|.macro settp, reg, tp\n|  mov64 ITYPE, ((uint64_t)tp<<47)\n|  or reg, ITYPE\n|.endmacro\n|.macro settp, dst, reg, tp\n|  mov64 dst, ((uint64_t)tp<<47)\n|  or dst, reg\n|.endmacro\n|.macro setint, reg\n|  settp reg, LJ_TISNUM\n|.endmacro\n|.macro setint, dst, reg\n|  settp dst, reg, LJ_TISNUM\n|.endmacro\n|\n|// Macros to test operand types.\n|.macro checktp_nc, reg, tp, target\n|  mov ITYPE, reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checktp, reg, tp, target\n|  mov ITYPE, reg\n|  cleartp reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checktptp, src, tp, target\n|  mov ITYPE, src\n|  sar ITYPE, 47\n|  cmp ITYPEd, tp\n|  jne target\n|.endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR, target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB, target; .endmacro\n|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC, target; .endmacro\n|\n|.macro checknumx, reg, target, jump\n|  mov ITYPE, reg\n|  sar ITYPE, 47\n|  cmp ITYPEd, LJ_TISNUM\n|  jump target\n|.endmacro\n|.macro checkint, reg, target; checknumx reg, target, jne; .endmacro\n|.macro checkinttp, src, target; checknumx src, target, jne; .endmacro\n|.macro checknum, reg, target; checknumx reg, target, jae; .endmacro\n|.macro checknumtp, src, target; checknumx src, target, jae; .endmacro\n|.macro checknumber, src, target; checknumx src, target, ja; .endmacro\n|\n|.macro mov_false, reg; mov64 reg, (int64_t)~((uint64_t)1<<47); .endmacro\n|.macro mov_true, reg; mov64 reg, (int64_t)~((uint64_t)2<<47); .endmacro\n|\n|// These operands must be used with movzx.\n|.define PC_OP, byte [PC-4]\n|.define PC_RA, byte [PC-3]\n|.define PC_RB, byte [PC-1]\n|.define PC_RC, byte [PC-2]\n|.define PC_RD, word [PC-2]\n|\n|.macro branchPC, reg\n|  lea PC, [PC+reg*4-BCBIAS_J*4]\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|// Decrement hashed hotcount and trigger trace recorder if zero.\n|.macro hotloop, reg\n|  mov reg, PCd\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP\n|  jb ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall, reg\n|  mov reg, PCd\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL\n|  jb ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro set_vmstate, st\n|  mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st\n|.endmacro\n|\n|.macro fpop1; fstp st1; .endmacro\n|\n|// Synthesize SSE FP constants.\n|.macro sseconst_abs, reg, tmp\t\t// Synthesize abs mask.\n|  mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp\n|.endmacro\n|\n|.macro sseconst_hi, reg, tmp, val\t// Synthesize hi-32 bit const.\n|  mov64 tmp, U64x(val,00000000); movd reg, tmp\n|.endmacro\n|\n|.macro sseconst_sign, reg, tmp\t\t// Synthesize sign mask.\n|  sseconst_hi reg, tmp, 80000000\n|.endmacro\n|.macro sseconst_1, reg, tmp\t\t// Synthesize 1.0.\n|  sseconst_hi reg, tmp, 3ff00000\n|.endmacro\n|.macro sseconst_m1, reg, tmp\t\t// Synthesize -1.0.\n|  sseconst_hi reg, tmp, bff00000\n|.endmacro\n|.macro sseconst_2p52, reg, tmp\t\t// Synthesize 2^52.\n|  sseconst_hi reg, tmp, 43300000\n|.endmacro\n|.macro sseconst_tobit, reg, tmp\t// Synthesize 2^52 + 2^51.\n|  sseconst_hi reg, tmp, 43380000\n|.endmacro\n|\n|// Move table write barrier back. Overwrites reg.\n|.macro barrierback, tab, reg\n|  and byte tab->marked, (uint8_t)~LJ_GC_BLACK\t// black2gray(tab)\n|  mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]\n|  mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab\n|  mov tab->gclist, reg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  test PCd, FRAME_P\n  |  jz ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  and PC, -8\n  |  sub BASE, PC\t\t\t// Restore caller base.\n  |  lea RA, [RA+PC-8]\t\t\t// Rebase RA and prepend one result.\n  |  mov PC, [BASE-8]\t\t\t// Fetch PC of previous frame.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |  mov_true ITYPE\n  |  mov aword [BASE+RA], ITYPE\t\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  add RDd, 1\t\t\t\t// RD = nresults+1\n  |  jz ->vm_unwind_yield\n  |  mov MULTRES, RDd\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return\n  |  xor PC, FRAME_C\n  |  test PCd, FRAME_TYPE\n  |  jnz ->vm_returnp\n  |\n  |  // Return to C.\n  |  set_vmstate C\n  |  and PC, -8\n  |  sub PC, BASE\n  |  neg PC\t\t\t\t// Previous base = BASE - delta.\n  |\n  |  sub RDd, 1\n  |  jz >2\n  |1:  // Move results down.\n  |  mov RB, [BASE+RA]\n  |  mov [BASE-16], RB\n  |  add BASE, 8\n  |  sub RDd, 1\n  |  jnz <1\n  |2:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, PC\n  |3:\n  |  mov RDd, MULTRES\n  |  mov RAd, SAVE_NRES\t\t\t// RA = wanted nresults+1\n  |4:\n  |  cmp RAd, RDd\n  |  jne >6\t\t\t\t// More/less results wanted?\n  |5:\n  |  sub BASE, 16\n  |  mov L:RB->top, BASE\n  |\n  |->vm_leave_cp:\n  |  mov RA, SAVE_CFRAME\t\t// Restore previous C frame.\n  |  mov L:RB->cframe, RA\n  |  xor eax, eax\t\t\t// Ok return status for vm_pcall.\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  jb >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  cmp BASE, L:RB->maxstack\n  |  ja >8\n  |  mov aword [BASE-16], LJ_TNIL\n  |  add BASE, 8\n  |  add RDd, 1\n  |  jmp <4\n  |\n  |7:  // Less results wanted.\n  |  test RAd, RAd\n  |  jz <5\t\t\t\t// But check for LUA_MULTRET+1.\n  |  sub RA, RD\t\t\t\t// Negative result!\n  |  lea BASE, [BASE+RA*8]\t\t// Correct top.\n  |  jmp <5\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  mov L:RB->top, BASE\t\t// Save current top held in BASE (yes).\n  |  mov MULTRES, RDd\t\t\t// Need to fill only remainder with nil.\n  |  mov CARG2d, RAd\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->top\t\t// Need the (realloced) L->top in BASE.\n  |  jmp <3\n  |\n  |->vm_unwind_yield:\n  |  mov al, LUA_YIELD\n  |  jmp ->vm_unwind_c_eh\n  |\n  |->vm_unwind_c:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |  mov eax, CARG2d\t\t\t// Error return status for vm_pcall.\n  |  mov rsp, CARG1\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov GL:RB, L:RB->glref\n  |  mov dword GL:RB->vmstate, ~LJ_VMST_C\n  |  jmp ->vm_leave_unw\n  |\n  |->vm_unwind_rethrow:\n  |.if not X64WIN\n  |  mov CARG1, SAVE_L\n  |  mov CARG2d, eax\n  |  restoreregs\n  |  jmp extern lj_err_throw\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |->vm_unwind_ff:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |  and CARG1, CFRAME_RAWMASK\n  |  mov rsp, CARG1\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov RDd, 1+1\t\t\t// Really 1+2 results, incr. later.\n  |  mov BASE, L:RB->base\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov PC, [BASE-8]\t\t\t// Fetch PC of previous frame.\n  |  mov_false RA\n  |  mov RB, [BASE]\n  |  mov [BASE-16], RA\t\t\t// Prepend false to error message.\n  |  mov [BASE-8], RB\n  |  mov RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  set_vmstate INTERP\n  |  jmp ->vm_returnc\t\t\t// Increments RD/MULTRES and returns.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  mov CARG2d, LUA_MINSTACK\n  |  jmp >2\n  |\n  |->vm_growstack_v:\t\t\t// Grow stack for vararg Lua function.\n  |  sub RD, 16\t\t\t\t// LJ_FR2\n  |  jmp >1\n  |\n  |->vm_growstack_f:\t\t\t// Grow stack for fixarg Lua function.\n  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |1:\n  |  movzx RAd, byte [PC-4+PC2PROTO(framesize)]\n  |  add PC, 4\t\t\t\t// Must point after first instruction.\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov SAVE_PC, PC\n  |  mov CARG2, RA\n  |2:\n  |  // RB = L, L->base = new base, L->top = top\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  mov LFUNC:RB, [BASE-16]\n  |  cleartp LFUNC:RB\n  |  sub RD, BASE\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  // BASE = new base, RB = LFUNC, RD = nargs+1\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov RA, CARG2\n  |  mov PCd, FRAME_CP\n  |  xor RDd, RDd\n  |  lea KBASE, [esp+CFRAME_RESUME]\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov SAVE_PC, RD\t\t\t// Any value outside of bytecode is ok.\n  |  mov SAVE_CFRAME, RD\n  |  mov SAVE_NRES, RDd\n  |  mov SAVE_ERRF, RDd\n  |  mov L:RB->cframe, KBASE\n  |  cmp byte L:RB->status, RDL\n  |  je >2\t\t\t\t// Initial resume (like a call).\n  |\n  |  // Resume after yield (like a return).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov byte L:RB->status, RDL\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr RDd, 3\n  |  add RDd, 1\t\t\t\t// RD = nresults+1\n  |  sub RA, BASE\t\t\t// RA = resultofs\n  |  mov PC, [BASE-8]\n  |  mov MULTRES, RDd\n  |  test PCd, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PCd, FRAME_CP\n  |  mov SAVE_ERRF, CARG4d\n  |  jmp >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PCd, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |  mov SAVE_NRES, CARG3d\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov RA, CARG2\n  |\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |  add DISPATCH, GG_G2DISP\n  |  mov L:RB->cframe, rsp\n  |\n  |2:  // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov BASE, L:RB->base\t\t// BASE = old base (used in vmeta_call).\n  |  add PC, RA\n  |  sub PC, BASE\t\t\t// PC = frame delta + frame type\n  |\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr NARGS:RDd, 3\n  |  add NARGS:RDd, 1\t\t\t// RD = nargs+1\n  |\n  |->vm_call_dispatch:\n  |  mov LFUNC:RB, [RA-16]\n  |  checkfunc LFUNC:RB, ->vmeta_call\t// Ensure KBASE defined and != BASE.\n  |\n  |->vm_call_dispatch_f:\n  |  mov BASE, RA\n  |  ins_call\n  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |  mov L:RB, CARG1\t\t\t// Caveat: CARG1 may be RA.\n  |  mov SAVE_L, CARG1\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |\n  |  mov KBASE, L:RB->stack\t\t// Compute -savestack(L, L->top).\n  |  sub KBASE, L:RB->top\n  |   mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov SAVE_ERRF, 0\t\t\t// No error function.\n  |  mov SAVE_NRES, KBASEd\t\t// Neg. delta means cframe w/o frame.\n  |   add DISPATCH, GG_G2DISP\n  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).\n  |\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov L:RB->cframe, rsp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |  // TValue * (new base) or NULL returned in eax (RC).\n  |  test RC, RC\n  |  jz ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |  mov RA, RC\n  |  mov PCd, FRAME_CP\n  |  jmp <2\t\t\t\t// Else continue with the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)\n  |  add RA, BASE\n  |  and PC, -8\n  |  mov RB, BASE\n  |  sub BASE, PC\t\t\t// Restore caller BASE.\n  |  mov aword [RA+RD*8-8], LJ_TNIL\t// Ensure one valid arg.\n  |  mov RC, RA\t\t\t\t// ... in [RC]\n  |  mov PC, [RB-24]\t\t\t// Restore PC from [cont|PC].\n  |  mov RA, qword [RB-32]\t\t// May be negative on WIN64 with debug.\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |  mov LFUNC:KBASE, [BASE-16]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  // BASE = base, RC = result, RB = meta base\n  |  jmp RA\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  je ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: Tail call from C function.\n  |  sub RB, BASE\n  |  shr RBd, 3\n  |  lea RDd, [RBd-3]\n  |  jmp ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// BASE = base, RC = result, RB = mbase\n  |  movzx RAd, PC_RB\n  |  sub RB, 32\n  |  lea RA, [BASE+RA*8]\n  |  sub RA, RB\n  |  je ->cont_ra\n  |  neg RA\n  |  shr RAd, 3\n  |.if X64WIN\n  |  mov CARG3d, RAd\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\n  |  mov RC, [RC]\n  |  mov [RB], RC\n  |  mov CARG2, RB\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\n  |  mov CARG3d, RAd\n  |  mov RA, [RC]\n  |  mov [RB], RA\n  |  mov CARG2, RB\n  |.endif\n  |  jmp ->BC_CAT_Z\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets:\n  |  settp STR:RC, LJ_TSTR\t\t// STR:RC = GCstr *\n  |  mov TMP1, STR:RC\n  |  lea RC, TMP1\n  |  cmp PC_OP, BC_GGET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t// TAB:RB = GCtab *\n  |  lea RB, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RB], TAB:RA\n  |  jmp >2\n  |\n  |->vmeta_tgetb:\n  |  movzx RCd, PC_RC\n  |.if DUALNUM\n  |  setint RC\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RCd\n  |  movsd TMP1, xmm0\n  |.endif\n  |  lea RC, TMP1\n  |  jmp >1\n  |\n  |->vmeta_tgetv:\n  |  movzx RCd, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RBd, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2, RB\n  |  mov CARG3, RC\n  |  mov L:RB, L:CARG1\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |->cont_ra:\t\t\t\t// BASE = base, RC = result\n  |  movzx RAd, PC_RA\n  |  mov RB, [RC]\n  |  mov [BASE+RA*8], RB\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  mov RA, L:RB->top\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-16]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RDd, 2+1\t\t\t// 2 args for func(t, k).\n  |  cleartp LFUNC:RB\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  mov CARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, RCd\t\t\t// Caveat: CARG2 == BASE\n  |  call extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RC).\n  |  movzx RAd, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RC, RC\n  |  jnz ->BC_TGETR_Z\n  |  mov ITYPE, LJ_TNIL\n  |  jmp ->BC_TGETR2_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets:\n  |  settp STR:RC, LJ_TSTR\t\t// STR:RC = GCstr *\n  |  mov TMP1, STR:RC\n  |  lea RC, TMP1\n  |  cmp PC_OP, BC_GSET\n  |  jne >1\n  |  settp TAB:RA, TAB:RB, LJ_TTAB\t// TAB:RB = GCtab *\n  |  lea RB, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RB], TAB:RA\n  |  jmp >2\n  |\n  |->vmeta_tsetb:\n  |  movzx RCd, PC_RC\n  |.if DUALNUM\n  |  setint RC\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RCd\n  |  movsd TMP1, xmm0\n  |.endif\n  |  lea RC, TMP1\n  |  jmp >1\n  |\n  |->vmeta_tsetv:\n  |  movzx RCd, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RBd, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2, RB\n  |  mov CARG3, RC\n  |  mov L:RB, L:CARG1\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  movzx RAd, PC_RA\n  |  mov RB, [BASE+RA*8]\n  |  mov [RC], RB\n  |->cont_nop:\t\t\t\t// BASE = base, (RC = result)\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  mov RA, L:RB->top\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  movzx RCd, PC_RA\n  |  // Copy value to third argument.\n  |  mov RB, [BASE+RC*8]\n  |  mov [RA+16], RB\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-16]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RDd, 3+1\t\t\t// 3 args for func(t, k, v).\n  |  cleartp LFUNC:RB\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |.if X64WIN\n  |  mov L:CARG1, SAVE_L\n  |  mov CARG3d, RCd\n  |  mov L:CARG1->base, BASE\n  |  xchg CARG2, TAB:RB\t\t\t// Caveat: CARG2 == BASE.\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov CARG2, TAB:RB\n  |  mov L:CARG1->base, BASE\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG3d, RCd\t\t\t// Caveat: CARG3 == BASE.\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // TValue * returned in eax (RC).\n  |  movzx RAd, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  jmp ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |  movzx RDd, PC_RD\n  |  movzx RAd, PC_RA\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 == BASE.\n  |.if X64WIN\n  |  lea CARG3, [BASE+RD*8]\n  |  lea CARG2, [BASE+RA*8]\n  |.else\n  |  lea CARG2, [BASE+RA*8]\n  |  lea CARG3, [BASE+RD*8]\n  |.endif\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1/CARG4 == RA.\n  |  movzx CARG4d, PC_OP\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |3:\n  |  mov BASE, L:RB->base\n  |  cmp RC, 1\n  |  ja ->vmeta_binop\n  |4:\n  |  lea PC, [PC+4]\n  |  jb >6\n  |5:\n  |  movzx RDd, PC_RD\n  |  branchPC RD\n  |6:\n  |  ins_next\n  |\n  |->cont_condt:\t\t\t// BASE = base, RC = result\n  |  add PC, 4\n  |  mov ITYPE, [RC]\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND\t\t// Branch if result is true.\n  |  jb <5\n  |  jmp <6\n  |\n  |->cont_condf:\t\t\t// BASE = base, RC = result\n  |  mov ITYPE, [RC]\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND\t\t// Branch if result is false.\n  |  jmp <4\n  |\n  |->vmeta_equal:\n  |  cleartp TAB:RD\n  |  sub PC, 4\n  |.if X64WIN\n  |  mov CARG3, RD\n  |  mov CARG4d, RBd\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG2, RA\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1 == RA.\n  |.else\n  |  mov CARG2, RA\n  |  mov CARG4d, RBd\t\t\t// Caveat: CARG4 == RA.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG3, RD\n  |  mov CARG1, L:RB\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, 4\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG1, L:RB\n  |  mov CARG2d, dword [PC-4]\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal_cd\t// (lua_State *L, BCIns ins)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n  |  mov CARG2d, RAd\n  |  mov CARG3d, RDd\n  |  mov L:CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  mov BASE, L:RB->base\n  |  jmp <6\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vno:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_vn:\n  |  lea RC, [KBASE+RC*8]\n  |  jmp >1\n  |\n  |->vmeta_arith_nvo:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_nv:\n  |  lea TMPR, [KBASE+RC*8]\n  |  lea RC, [BASE+RB*8]\n  |  mov RB, TMPR\n  |  jmp >2\n  |\n  |->vmeta_unm:\n  |  lea RC, [BASE+RD*8]\n  |  mov RB, RC\n  |  jmp >2\n  |\n  |->vmeta_arith_vvo:\n  |.if DUALNUM\n  |  movzx RBd, PC_RB\n  |  movzx RCd, PC_RC\n  |.endif\n  |->vmeta_arith_vv:\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  lea RA, [BASE+RA*8]\n  |.if X64WIN\n  |  mov CARG3, RB\n  |  mov CARG4, RC\n  |  movzx RCd, PC_OP\n  |  mov ARG5d, RCd\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG2, RA\n  |  mov CARG1, L:RB\t\t\t// Caveat: CARG1 == RA.\n  |.else\n  |  movzx CARG5d, PC_OP\n  |  mov CARG2, RA\n  |  mov CARG4, RC\t\t\t// Caveat: CARG4 == RA.\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG3, RB\n  |  mov L:RB, L:CARG1\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_arith\t// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = base, RC = new base, stack = cont/func/o1/o2\n  |  mov RA, RC\n  |  sub RC, BASE\n  |  mov [RA-24], PC\t\t\t// [cont|PC]\n  |  lea PC, [RC+FRAME_CONT]\n  |  mov NARGS:RDd, 2+1\t\t\t// 2 args for func(o1, o2).\n  |  jmp ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  movzx RDd, PC_RD\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  lea CARG2, [BASE+RD*8]\t\t// Caveat: CARG2 == BASE\n  |  mov L:CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_len\t\t// (lua_State *L, TValue *o)\n  |  // NULL (retry) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n#if LJ_52\n  |  test RC, RC\n  |  jne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  movzx RDd, PC_RD\n  |  mov TAB:CARG1, [BASE+RD*8]\n  |  cleartp TAB:CARG1\n  |  jmp ->BC_LEN_Z\n#else\n  |  jmp ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call_ra:\n  |  lea RA, [BASE+RA*8+16]\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return\n  |  mov TMP1d, NARGS:RDd\t\t// Save RA, RC for us.\n  |  mov RB, RA\n  |.if X64WIN\n  |  mov L:TMPR, SAVE_L\n  |  mov L:TMPR->base, BASE\t\t// Caveat: CARG2 is BASE.\n  |  lea CARG2, [RA-16]\n  |  lea CARG3, [RA+NARGS:RD*8-8]\n  |  mov CARG1, L:TMPR\t\t\t// Caveat: CARG1 is RA.\n  |.else\n  |  mov L:CARG1, SAVE_L\n  |  mov L:CARG1->base, BASE\t\t// Caveat: CARG3 is BASE.\n  |  lea CARG2, [RA-16]\n  |  lea CARG3, [RA+NARGS:RD*8-8]\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  mov RA, RB\n  |  mov L:RB, SAVE_L\n  |  mov BASE, L:RB->base\n  |  mov NARGS:RDd, TMP1d\n  |  mov LFUNC:RB, [RA-16]\n  |  add NARGS:RDd, 1\n  |  // This is fragile. L->base must not move, KBASE must always be defined.\n  |  cmp KBASE, BASE\t\t\t// Continue with CALLT if flag set.\n  |  je ->BC_CALLT_Z\n  |  cleartp LFUNC:RB\n  |  mov BASE, RA\n  |  ins_call\t\t\t\t// Otherwise call resolved metamethod.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, RA\t\t\t// Caveat: CARG2 == BASE\n  |  mov L:CARG1, L:RB\t\t\t// Caveat: CARG1 == RA\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_for\t// (lua_State *L, TValue *base)\n  |  mov BASE, L:RB->base\n  |  mov RCd, [PC-4]\n  |  movzx RAd, RCH\n  |  movzx OP, RCL\n  |  shr RCd, 16\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmp NARGS:RDd, 1+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmp NARGS:RDd, 2+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_n, name, op\n  |  .ffunc_1 name\n  |  checknumtp [BASE], ->fff_fallback\n  |  op xmm0, qword [BASE]\n  |.endmacro\n  |\n  |.macro .ffunc_n, name\n  |  .ffunc_n name, movsd\n  |.endmacro\n  |\n  |.macro .ffunc_nn, name\n  |  .ffunc_2 name\n  |  checknumtp [BASE], ->fff_fallback\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  movsd xmm1, qword [BASE+8]\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses label 1.\n  |.macro ffgccheck\n  |  mov RB, [DISPATCH+DISPATCH_GL(gc.total)]\n  |  cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]\n  |  jb >1\n  |  call ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  mov ITYPE, [BASE]\n  |  mov RB, ITYPE\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISTRUECOND; jae ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  mov MULTRES, RDd\n  |  mov RB, [BASE]\n  |  mov [BASE-16], RB\n  |  sub RDd, 2\n  |  jz >2\n  |  mov RA, BASE\n  |1:\n  |  add RA, 8\n  |  mov RB, [RA]\n  |  mov [RA-16], RB\n  |  sub RDd, 1\n  |  jnz <1\n  |2:\n  |  mov RDd, MULTRES\n  |  jmp ->fff_res_\n  |\n  |.ffunc_1 type\n  |  mov RC, [BASE]\n  |  sar RC, 47\n  |  mov RBd, LJ_TISNUM\n  |  cmp RCd, RBd\n  |  cmovb RCd, RBd\n  |  not RCd\n  |2:\n  |  mov CFUNC:RB, [BASE-16]\n  |  cleartp CFUNC:RB\n  |  mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]\n  |  mov PC, [BASE-8]\n  |  settp STR:RC, LJ_TSTR\n  |  mov [BASE-16], STR:RC\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  mov TAB:RB, [BASE]\n  |  mov PC, [BASE-8]\n  |  checktab TAB:RB, >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  mov TAB:RB, TAB:RB->metatable\n  |2:\n  |  test TAB:RB, TAB:RB\n  |  mov aword [BASE-16], LJ_TNIL\n  |  jz ->fff_res1\n  |  settp TAB:RC, TAB:RB, LJ_TTAB\n  |  mov [BASE-16], TAB:RC\t\t// Store metatable as default result.\n  |  mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+8*(GCROOT_MMNAME+MM_metatable)]\n  |  mov RAd, TAB:RB->hmask\n  |  and RAd, STR:RC->sid\n  |  settp STR:RC, LJ_TSTR\n  |  imul RAd, #NODE\n  |  add NODE:RA, TAB:RB->node\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  cmp NODE:RA->key, STR:RC\n  |  je >5\n  |4:\n  |  mov NODE:RA, NODE:RA->next\n  |  test NODE:RA, NODE:RA\n  |  jnz <3\n  |  jmp ->fff_res1\t\t\t// Not found, keep default result.\n  |5:\n  |  mov RB, NODE:RA->val\n  |  cmp RB, LJ_TNIL; je ->fff_res1\t// Ditto for nil value.\n  |  mov [BASE-16], RB\t\t\t// Return value of mt.__metatable.\n  |  jmp ->fff_res1\n  |\n  |6:\n  |  cmp ITYPEd, LJ_TUDATA; je <1\n  |  cmp ITYPEd, LJ_TISNUM; ja >7\n  |  mov ITYPEd, LJ_TISNUM\n  |7:\n  |  not ITYPEd\n  |  mov TAB:RB, [DISPATCH+ITYPE*8+DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  jmp <2\n  |\n  |.ffunc_2 setmetatable\n  |  mov TAB:RB, [BASE]\n  |  mov TAB:TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n  |  mov TAB:RA, [BASE+8]\n  |  checktab TAB:RA, ->fff_fallback\n  |  mov TAB:RB->metatable, TAB:RA\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], TAB:TMPR\t\t\t// Return original table.\n  |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n  |  jz >1\n  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.\n  |  barrierback TAB:RB, RC\n  |1:\n  |  jmp ->fff_res1\n  |\n  |.ffunc_2 rawget\n  |.if X64WIN\n  |  mov TAB:RA, [BASE]\n  |  checktab TAB:RA, ->fff_fallback\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3, [BASE+8]\n  |  mov CARG2, TAB:RA\t\t\t// Caveat: CARG2 == BASE.\n  |  mov CARG1, SAVE_L\n  |.else\n  |  mov TAB:CARG2, [BASE]\n  |  checktab TAB:CARG2, ->fff_fallback\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3, [BASE+8]\t\t// Caveat: CARG3 == BASE.\n  |  mov CARG1, SAVE_L\n  |.endif\n  |  call extern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |  // cTValue * returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  // Copy table slot.\n  |  mov RB, [RD]\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\t// Exactly one argument.\n  |  mov RB, [BASE]\n  |  checknumber RB, ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  mov PC, [BASE-8]\n  |  mov STR:RB, [BASE]\n  |  checktp_nc STR:RB, LJ_TSTR, >3\n  |  // A __tostring method in the string base metatable is ignored.\n  |2:\n  |  mov [BASE-16], STR:RB\n  |  jmp ->fff_res1\n  |3:  // Handle numbers inline, unless a number base metatable is present.\n  |  cmp ITYPEd, LJ_TISNUM;  ja ->fff_fallback_1\n  |  cmp aword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0\n  |  jne ->fff_fallback\n  |  ffgccheck\t\t\t\t// Caveat: uses label 1.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |.if not X64WIN\n  |  mov CARG2, BASE\t\t\t// Otherwise: CARG2 == BASE\n  |.endif\n  |  mov L:CARG1, L:RB\n  |.if DUALNUM\n  |  call extern lj_strfmt_number\t// (lua_State *L, cTValue *o)\n  |.else\n  |  call extern lj_strfmt_num\t\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // GCstr returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  settp STR:RB, RD, LJ_TSTR\n  |  jmp <2\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  je >2\t\t\t\t// Missing 2nd arg?\n  |1:\n  |  mov CARG1, [BASE]\n  |  mov PC, [BASE-8]\n  |  checktab CARG1, ->fff_fallback\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |.if X64WIN\n  |  lea CARG3, [BASE-16]\n  |  lea CARG2, [BASE+8]\t\t// Caveat: CARG2 == BASE.\n  |.else\n  |  lea CARG2, [BASE+8]\n  |  lea CARG3, [BASE-16]\t\t// Caveat: CARG3 == BASE.\n  |.endif\n  |  call extern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |  // 1=found, 0=end, -1=error returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RDd, RDd;  jg ->fff_res2\t// Found key/value.\n  |  js ->fff_fallback_2\t\t// Invalid key.\n  |  // End of traversal: return nil.\n  |  mov aword [BASE-16], LJ_TNIL\n  |  jmp ->fff_res1\n  |2:  // Set missing 2nd arg to nil.\n  |  mov aword [BASE+8], LJ_TNIL\n  |  jmp <1\n  |\n  |.ffunc_1 pairs\n  |  mov TAB:RB, [BASE]\n  |  mov TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  mov CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], CFUNC:RD\n  |  mov [BASE-8], TMPR\n  |  mov aword [BASE], LJ_TNIL\n  |  mov RDd, 1+3\n  |  jmp ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  mov TAB:RB, [BASE]\n  |  checktab TAB:RB, ->fff_fallback\n  |.if DUALNUM\n  |  mov RA, [BASE+8]\n  |  checkint RA, ->fff_fallback\n  |.else\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  movsd xmm0, qword [BASE+8]\n  |.endif\n  |  mov PC, [BASE-8]\n  |.if DUALNUM\n  |  add RAd, 1\n  |  setint ITYPE, RA\n  |  mov [BASE-16], ITYPE\n  |.else\n  |  sseconst_1 xmm1, TMPR\n  |  addsd xmm0, xmm1\n  |  cvttsd2si RAd, xmm0\n  |  movsd qword [BASE-16], xmm0\n  |.endif\n  |  cmp RAd, TAB:RB->asize;  jae >2\t// Not in array part?\n  |  mov RD, TAB:RB->array\n  |  lea RD, [RD+RA*8]\n  |1:\n  |  cmp aword [RD], LJ_TNIL;  je ->fff_res0\n  |  // Copy array slot.\n  |  mov RB, [RD]\n  |  mov [BASE-8], RB\n  |->fff_res2:\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cmp dword TAB:RB->hmask, 0; je ->fff_res0\n  |.if X64WIN\n  |  mov TMPR, BASE\n  |  mov CARG2d, RAd\n  |  mov CARG1, TAB:RB\n  |  mov RB, TMPR\n  |.else\n  |  mov CARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, RAd\t\t\t// Caveat: CARG2 == BASE\n  |.endif\n  |  call extern lj_tab_getinth\t\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RD).\n  |  mov BASE, RB\n  |  test RD, RD\n  |  jnz <1\n  |->fff_res0:\n  |  mov RDd, 1+0\n  |  jmp ->fff_res\n  |\n  |.ffunc_1 ipairs\n  |  mov TAB:RB, [BASE]\n  |  mov TMPR, TAB:RB\n  |  checktab TAB:RB, ->fff_fallback\n#if LJ_52\n  |  cmp aword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  mov CFUNC:RD, CFUNC:RD->upvalue[0]\n  |  settp CFUNC:RD, LJ_TFUNC\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], CFUNC:RD\n  |  mov [BASE-8], TMPR\n  |.if DUALNUM\n  |  mov64 RD, ((uint64_t)LJ_TISNUM<<47)\n  |  mov [BASE], RD\n  |.else\n  |  mov qword [BASE], 0\n  |.endif\n  |  mov RDd, 1+3\n  |  jmp ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc_1 pcall\n  |  lea RA, [BASE+16]\n  |  sub NARGS:RDd, 1\n  |  mov PCd, 16+FRAME_PCALL\n  |1:\n  |  movzx RBd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  shr RB, HOOK_ACTIVE_SHIFT\n  |  and RB, 1\n  |  add PC, RB\t\t\t\t// Remember active hook before pcall.\n  |  // Note: this does a (harmless) copy of the function to the PC slot, too.\n  |  mov KBASE, RD\n  |2:\n  |  mov RB, [RA+KBASE*8-24]\n  |  mov [RA+KBASE*8-16], RB\n  |  sub KBASE, 1\n  |  ja <2\n  |  jmp ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  mov LFUNC:RA, [BASE+8]\n  |  checktp_nc LFUNC:RA, LJ_TFUNC, ->fff_fallback\n  |  mov LFUNC:RB, [BASE]\t\t// Swap function and traceback.\n  |  mov [BASE], LFUNC:RA\n  |  mov [BASE+8], LFUNC:RB\n  |  lea RA, [BASE+24]\n  |  sub NARGS:RDd, 2\n  |  mov PCd, 24+FRAME_PCALL\n  |  jmp <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  mov L:RB, [BASE]\n  |  cleartp L:RB\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  mov CFUNC:RB, [BASE-16]\n  |  cleartp CFUNC:RB\n  |  mov L:RB, CFUNC:RB->upvalue[0].gcr\n  |  cleartp L:RB\n  |.endif\n  |  mov PC, [BASE-8]\n  |  mov SAVE_PC, PC\n  |  mov TMP1, L:RB\n  |.if resume\n  |  checktptp [BASE], LJ_TTHREAD, ->fff_fallback\n  |.endif\n  |  cmp aword L:RB->cframe, 0; jne ->fff_fallback\n  |  cmp byte L:RB->status, LUA_YIELD;  ja ->fff_fallback\n  |  mov RA, L:RB->top\n  |  je >1\t\t\t\t// Status != LUA_YIELD (i.e. 0)?\n  |  cmp RA, L:RB->base\t\t\t// Check for presence of initial func.\n  |  je ->fff_fallback\n  |  mov PC, [RA-8]\t\t\t// Move initial function up.\n  |  mov [RA], PC\n  |  add RA, 8\n  |1:\n  |.if resume\n  |  lea PC, [RA+NARGS:RD*8-16]\t\t// Check stack space (-1-thread).\n  |.else\n  |  lea PC, [RA+NARGS:RD*8-8]\t\t// Check stack space (-1).\n  |.endif\n  |  cmp PC, L:RB->maxstack; ja ->fff_fallback\n  |  mov L:RB->top, PC\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if resume\n  |  add BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |.endif\n  |  mov L:RB->top, BASE\n  |.if resume\n  |  lea RB, [BASE+NARGS:RD*8-24]\t// RB = end of source for stack move.\n  |.else\n  |  lea RB, [BASE+NARGS:RD*8-16]\t// RB = end of source for stack move.\n  |.endif\n  |  sub RB, PC\t\t\t// Relative to PC.\n  |\n  |  cmp PC, RA\n  |  je >3\n  |2:  // Move args to coroutine.\n  |  mov RC, [PC+RB]\n  |  mov [PC-8], RC\n  |  sub PC, 8\n  |  cmp PC, RA\n  |  jne <2\n  |3:\n  |  mov CARG2, RA\n  |  mov CARG1, TMP1\n  |  call ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:PC, TMP1\n  |  mov BASE, L:RB->base\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |\n  |  cmp eax, LUA_YIELD\n  |  ja >8\n  |4:\n  |  mov RA, L:PC->base\n  |  mov KBASE, L:PC->top\n  |  mov L:PC->top, RA\t\t\t// Clear coroutine stack.\n  |  mov PC, KBASE\n  |  sub PC, RA\n  |  je >6\t\t\t\t// No results?\n  |  lea RD, [BASE+PC]\n  |  shr PCd, 3\n  |  cmp RD, L:RB->maxstack\n  |  ja >9\t\t\t\t// Need to grow stack?\n  |\n  |  mov RB, BASE\n  |  sub RB, RA\n  |5:  // Move results from coroutine.\n  |  mov RD, [RA]\n  |  mov [RA+RB], RD\n  |  add RA, 8\n  |  cmp RA, KBASE\n  |  jne <5\n  |6:\n  |.if resume\n  |  lea RDd, [PCd+2]\t\t\t// nresults+1 = 1 + true + results.\n  |  mov_true ITYPE\t\t\t// Prepend true to results.\n  |  mov [BASE-8], ITYPE\n  |.else\n  |  lea RDd, [PCd+1]\t\t\t// nresults+1 = 1 + results.\n  |.endif\n  |7:\n  |  mov PC, SAVE_PC\n  |  mov MULTRES, RDd\n  |.if resume\n  |  mov RA, -8\n  |.else\n  |  xor RAd, RAd\n  |.endif\n  |  test PCd, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  mov_false ITYPE\t\t\t// Prepend false to results.\n  |  mov [BASE-8], ITYPE\n  |  mov RA, L:PC->top\n  |  sub RA, 8\n  |  mov L:PC->top, RA\t\t\t// Clear error from coroutine stack.\n  |  // Copy error message.\n  |  mov RD, [RA]\n  |  mov [BASE], RD\n  |  mov RDd, 1+2\t\t\t// nresults+1 = 1 + false + error.\n  |  jmp <7\n  |.else\n  |  mov CARG2, L:PC\n  |  mov CARG1, L:RB\n  |  call extern lj_ffh_coroutine_wrap_err  // (lua_State *L, lua_State *co)\n  |  // Error function does not return.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |  mov L:RA, TMP1\n  |  mov L:RA->top, KBASE\t\t// Undo coroutine stack clearing.\n  |  mov CARG2, PC\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov L:PC, TMP1\n  |  mov BASE, L:RB->base\n  |  jmp <4\t\t\t\t// Retry the stack move.\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  mov L:RB, SAVE_L\n  |  test aword L:RB->cframe, CFRAME_RESUME\n  |  jz ->fff_fallback\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB->top, RD\n  |  xor RDd, RDd\n  |  mov aword L:RB->cframe, RD\n  |  mov al, LUA_YIELD\n  |  mov byte L:RB->status, al\n  |  jmp ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |  .ffunc_1 math_abs\n  |  mov RB, [BASE]\n  |.if DUALNUM\n  |  checkint RB, >3\n  |  cmp RBd, 0; jns ->fff_resi\n  |  neg RBd; js >2\n  |->fff_resbit:\n  |->fff_resi:\n  |  setint RB\n  |->fff_resRB:\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |2:\n  |  mov64 RB, U64x(41e00000,00000000)  // 2^31.\n  |  jmp ->fff_resRB\n  |3:\n  |  ja ->fff_fallback\n  |.else\n  |  checknum RB, ->fff_fallback\n  |.endif\n  |  shl RB, 1\n  |  shr RB, 1\n  |  mov PC, [BASE-8]\n  |  mov [BASE-16], RB\n  |  jmp ->fff_res1\n  |\n  |.ffunc_n math_sqrt, sqrtsd\n  |->fff_resxmm0:\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-16], xmm0\n  |  // fallthrough\n  |\n  |->fff_res1:\n  |  mov RDd, 1+1\n  |->fff_res:\n  |  mov MULTRES, RDd\n  |->fff_res_:\n  |  test PCd, FRAME_TYPE\n  |  jnz >7\n  |5:\n  |  cmp PC_RB, RDL\t\t\t// More results expected?\n  |  ja >6\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  movzx RAd, PC_RA\n  |  neg RA\n  |  lea BASE, [BASE+RA*8-16]\t\t// base = base - (RA+2)*8\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  mov aword [BASE+RD*8-24], LJ_TNIL\n  |  add RD, 1\n  |  jmp <5\n  |\n  |7:  // Non-standard return case.\n  |  mov RA, -16\t\t\t// Results start at BASE+RA = BASE-16.\n  |  jmp ->vm_return\n  |\n  |.macro math_round, func\n  |  .ffunc math_ .. func\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checknumx RB, ->fff_resRB, je\n  |  ja ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  call ->vm_ .. func .. _sse\n  |.if DUALNUM\n  |  cvttsd2si RBd, xmm0\n  |  cmp RBd, 0x80000000\n  |  jne ->fff_resi\n  |  cvtsi2sd xmm1, RBd\n  |  ucomisd xmm0, xmm1\n  |  jp ->fff_resxmm0\n  |  je ->fff_resi\n  |.endif\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc math_log\n  |  cmp NARGS:RDd, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  checknumtp [BASE], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  mov RB, BASE\n  |  call extern log\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |\n  |.macro math_extern, func\n  |  .ffunc_n math_ .. func\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nn math_ .. func\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_2 math_ldexp\n  |  checknumtp [BASE], ->fff_fallback\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  fld qword [BASE+8]\n  |  fld qword [BASE]\n  |  fscale\n  |  fpop1\n  |  mov PC, [BASE-8]\n  |  fstp qword [BASE-16]\n  |  jmp ->fff_res1\n  |\n  |.ffunc_n math_frexp\n  |  mov RB, BASE\n  |.if X64WIN\n  |  lea CARG2, TMP1\t\t// Caveat: CARG2 == BASE\n  |.else\n  |  lea CARG1, TMP1\n  |.endif\n  |  call extern frexp\n  |  mov BASE, RB\n  |  mov RBd, TMP1d\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-16], xmm0\n  |.if DUALNUM\n  |  setint RB\n  |  mov [BASE-8], RB\n  |.else\n  |  cvtsi2sd xmm1, RBd\n  |  movsd qword [BASE-8], xmm1\n  |.endif\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |\n  |.ffunc_n math_modf\n  |  mov RB, BASE\n  |.if X64WIN\n  |  lea CARG2, [BASE-16]\t// Caveat: CARG2 == BASE\n  |.else\n  |  lea CARG1, [BASE-16]\n  |.endif\n  |  call extern modf\n  |  mov BASE, RB\n  |  mov PC, [BASE-8]\n  |  movsd qword [BASE-8], xmm0\n  |  mov RDd, 1+2\n  |  jmp ->fff_res\n  |\n  |.macro math_minmax, name, cmovop, sseop\n  |  .ffunc_1 name\n  |  mov RAd, 2\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, >4\n  |1:  // Handle integers.\n  |  cmp RAd, RDd; jae ->fff_resRB\n  |  mov TMPR, [BASE+RA*8-8]\n  |  checkint TMPR, >3\n  |  cmp RBd, TMPRd\n  |  cmovop RB, TMPR\n  |  add RAd, 1\n  |  jmp <1\n  |3:\n  |  ja ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  cvtsi2sd xmm0, RBd\n  |  jmp >6\n  |4:\n  |  ja ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |.endif\n  |\n  |  movsd xmm0, qword [BASE]\n  |5:  // Handle numbers or integers.\n  |  cmp RAd, RDd; jae ->fff_resxmm0\n  |.if DUALNUM\n  |  mov RB, [BASE+RA*8-8]\n  |  checknumx RB, >6, jb\n  |  ja ->fff_fallback\n  |  cvtsi2sd xmm1, RBd\n  |  jmp >7\n  |.else\n  |  checknumtp [BASE+RA*8-8], ->fff_fallback\n  |.endif\n  |6:\n  |  movsd xmm1, qword [BASE+RA*8-8]\n  |7:\n  |  sseop xmm0, xmm1\n  |  add RAd, 1\n  |  jmp <5\n  |.endmacro\n  |\n  |  math_minmax math_min, cmovg, minsd\n  |  math_minmax math_max, cmovl, maxsd\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\n  |  mov STR:RB, [BASE]\n  |  checkstr STR:RB, ->fff_fallback\n  |  mov PC, [BASE-8]\n  |  cmp dword STR:RB->len, 1\n  |  jb ->fff_res0\t\t\t// Return no results for empty string.\n  |  movzx RBd, byte STR:RB[1]\n  |.if DUALNUM\n  |  jmp ->fff_resi\n  |.else\n  |  cvtsi2sd xmm0, RBd; jmp ->fff_resxmm0\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmp NARGS:RDd, 1+1;  jne ->fff_fallback\t// *Exactly* 1 arg.\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, ->fff_fallback\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |  cvttsd2si RBd, qword [BASE]\n  |.endif\n  |  cmp RBd, 255;  ja ->fff_fallback\n  |  mov TMP1d, RBd\n  |  mov TMPRd, 1\n  |  lea RD, TMP1\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG3d, TMPRd\t\t\t// Zero-extended to size_t.\n  |  mov CARG2, RD\n  |  mov CARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // GCstr * returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  mov PC, [BASE-8]\n  |  settp STR:RD, LJ_TSTR\n  |  mov [BASE-16], STR:RD\n  |  jmp ->fff_res1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  mov TMPRd, -1\n  |  cmp NARGS:RDd, 1+2;  jb ->fff_fallback\n  |  jna >1\n  |.if DUALNUM\n  |  mov TMPR, [BASE+16]\n  |  checkint TMPR, ->fff_fallback\n  |.else\n  |  checknumtp [BASE+16], ->fff_fallback\n  |  cvttsd2si TMPRd, qword [BASE+16]\n  |.endif\n  |1:\n  |  mov STR:RB, [BASE]\n  |  checkstr STR:RB, ->fff_fallback\n  |.if DUALNUM\n  |  mov ITYPE, [BASE+8]\n  |  mov RAd, ITYPEd\t\t\t// Must clear hiword for lea below.\n  |  sar ITYPE, 47\n  |  cmp ITYPEd, LJ_TISNUM\n  |  jne ->fff_fallback\n  |.else\n  |  checknumtp [BASE+8], ->fff_fallback\n  |  cvttsd2si RAd, qword [BASE+8]\n  |.endif\n  |  mov RCd, STR:RB->len\n  |  cmp RCd, TMPRd\t\t\t// len < end? (unsigned compare)\n  |  jb >5\n  |2:\n  |  test RAd, RAd\t\t\t// start <= 0?\n  |  jle >7\n  |3:\n  |  sub TMPRd, RAd\t\t\t// start > end?\n  |  jl ->fff_emptystr\n  |  lea RD, [STR:RB+RAd+#STR-1]\n  |  add TMPRd, 1\n  |4:\n  |  jmp ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  jl >6\n  |  lea TMPRd, [TMPRd+RCd+1]\t\t// end = end+(len+1)\n  |  jmp <2\n  |6:  // Overflow.\n  |  mov TMPRd, RCd\t\t\t// end = len\n  |  jmp <2\n  |\n  |7:  // Negative start or underflow.\n  |  je >8\n  |  add RAd, RCd\t\t\t// start = start+(len+1)\n  |  add RAd, 1\n  |  jg <3\t\t\t\t// start > 0?\n  |8:  // Underflow.\n  |  mov RAd, 1\t\t\t\t// start = 1\n  |  jmp <3\n  |\n  |->fff_emptystr:  // Range underflow.\n  |  xor TMPRd, TMPRd\t\t\t// Zero length. Any ptr in RD is ok.\n  |  jmp <4\n  |\n  |.macro ffstring_op, name\n  |  .ffunc_1 string_ .. name\n  |  ffgccheck\n  |.if X64WIN\n  |  mov STR:TMPR, [BASE]\n  |  checkstr STR:TMPR, ->fff_fallback\n  |.else\n  |  mov STR:CARG2, [BASE]\n  |  checkstr STR:CARG2, ->fff_fallback\n  |.endif\n  |  mov L:RB, SAVE_L\n  |   lea SBUF:CARG1, [DISPATCH+DISPATCH_GL(tmpbuf)]\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  mov STR:CARG2, STR:TMPR\t\t// Caveat: CARG2 == BASE\n  |.endif\n  |   mov RC, SBUF:CARG1->b\n  |   mov SBUF:CARG1->L, L:RB\n  |   mov SBUF:CARG1->w, RC\n  |  mov SAVE_PC, PC\n  |  call extern lj_buf_putstr_ .. name\n  |  mov CARG1, rax\n  |  call extern lj_buf_tostr\n  |  jmp ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name, kind, fdef\n  |  fdef name\n  |.if kind == 2\n  |  sseconst_tobit xmm1, RB\n  |.endif\n  |.if DUALNUM\n  |  mov RB, [BASE]\n  |  checkint RB, >1\n  |.if kind > 0\n  |  jmp >2\n  |.else\n  |  jmp ->fff_resbit\n  |.endif\n  |1:\n  |  ja ->fff_fallback\n  |  movd xmm0, RB\n  |.else\n  |  checknumtp [BASE], ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |.endif\n  |.if kind < 2\n  |  sseconst_tobit xmm1, RB\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RBd, xmm0\n  |2:\n  |.endmacro\n  |\n  |.macro .ffunc_bit, name, kind\n  |  .ffunc_bit name, kind, .ffunc_1\n  |.endmacro\n  |\n  |.ffunc_bit bit_tobit, 0\n  |  jmp ->fff_resbit\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name, 2\n  |  mov TMPRd, NARGS:RDd\t\t// Save for fallback.\n  |  lea RD, [BASE+NARGS:RD*8-16]\n  |1:\n  |  cmp RD, BASE\n  |  jbe ->fff_resbit\n  |.if DUALNUM\n  |  mov RA, [RD]\n  |  checkint RA, >2\n  |  ins RBd, RAd\n  |  sub RD, 8\n  |  jmp <1\n  |2:\n  |  ja ->fff_fallback_bit_op\n  |  movd xmm0, RA\n  |.else\n  |  checknumtp [RD], ->fff_fallback_bit_op\n  |  movsd xmm0, qword [RD]\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RAd, xmm0\n  |  ins RBd, RAd\n  |  sub RD, 8\n  |  jmp <1\n  |.endmacro\n  |\n  |.ffunc_bit_op bit_band, and\n  |.ffunc_bit_op bit_bor, or\n  |.ffunc_bit_op bit_bxor, xor\n  |\n  |.ffunc_bit bit_bswap, 1\n  |  bswap RBd\n  |  jmp ->fff_resbit\n  |\n  |.ffunc_bit bit_bnot, 1\n  |  not RBd\n  |.if DUALNUM\n  |  jmp ->fff_resbit\n  |.else\n  |->fff_resbit:\n  |  cvtsi2sd xmm0, RBd\n  |  jmp ->fff_resxmm0\n  |.endif\n  |\n  |->fff_fallback_bit_op:\n  |  mov NARGS:RDd, TMPRd\t\t// Restore for fallback\n  |  jmp ->fff_fallback\n  |\n  |.macro .ffunc_bit_sh, name, ins\n  |.if DUALNUM\n  |  .ffunc_bit name, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  mov RA, [BASE+8]\n  |  checkint RA, ->fff_fallback\n  |.else\n  |  .ffunc_nn name\n  |  sseconst_tobit xmm2, RB\n  |  addsd xmm0, xmm2\n  |  addsd xmm1, xmm2\n  |  movd RBd, xmm0\n  |  movd RAd, xmm1\n  |.endif\n  |  ins RBd, cl\t\t\t// Assumes RA is ecx.\n  |  jmp ->fff_resbit\n  |.endmacro\n  |\n  |.ffunc_bit_sh bit_lshift, shl\n  |.ffunc_bit_sh bit_rshift, shr\n  |.ffunc_bit_sh bit_arshift, sar\n  |.ffunc_bit_sh bit_rol, rol\n  |.ffunc_bit_sh bit_ror, ror\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback_2:\n  |  mov NARGS:RDd, 1+2\t\t\t// Other args are ignored, anyway.\n  |  jmp ->fff_fallback\n  |->fff_fallback_1:\n  |  mov NARGS:RDd, 1+1\t\t\t// Other args are ignored, anyway.\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RD = nargs+1\n  |  mov L:RB, SAVE_L\n  |  mov PC, [BASE-8]\t\t\t// Fallback may overwrite PC.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  lea RA, [RD+8*LUA_MINSTACK]\t// Ensure enough space for handler.\n  |  mov L:RB->top, RD\n  |  mov CFUNC:RD, [BASE-16]\n  |  cleartp CFUNC:RD\n  |  cmp RA, L:RB->maxstack\n  |  ja >5\t\t\t\t// Need to grow stack.\n  |  mov CARG1, L:RB\n  |  call aword CFUNC:RD->f\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  test RDd, RDd; jg ->fff_res\t// Returned nresults+1?\n  |1:\n  |  mov RA, L:RB->top\n  |  sub RA, BASE\n  |  shr RAd, 3\n  |  test RDd, RDd\n  |  lea NARGS:RDd, [RAd+1]\n  |  mov LFUNC:RB, [BASE-16]\n  |  jne ->vm_call_tail\t\t\t// Returned -1?\n  |  cleartp LFUNC:RB\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  mov RA, BASE\n  |  test PCd, FRAME_TYPE\n  |  jnz >3\n  |  movzx RBd, PC_RA\n  |  neg RB\n  |  lea BASE, [BASE+RB*8-16]\t\t// base = base - (RB+2)*8\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |3:\n  |  mov RB, PC\n  |  and RB, -8\n  |  sub BASE, RB\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov CARG2d, LUA_MINSTACK\n  |  mov CARG1, L:RB\n  |  call extern lj_state_growstack\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  xor RDd, RDd\t\t\t// Simulate a return 0.\n  |  jmp <1\t\t\t\t// Dumb retry (goes through ff first).\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RD = nargs+1\n  |  pop RB\t\t\t\t// Must keep stack at same level.\n  |  mov TMP1, RB\t\t\t// Save return address\n  |  mov L:RB, SAVE_L\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov CARG1, L:RB\n  |  mov L:RB->top, RD\n  |  call extern lj_gc_step\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  mov RB, TMP1\n  |  push RB\t\t\t\t// Restore return address.\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  jnz >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |  test RDL, HOOK_ACTIVE\n  |  jnz >1\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >1\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jmp >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |  jmp >1\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  movzx RDd, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >5\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jz >1\n  |  test RDL, LUA_MASKLINE\n  |  jz >5\n  |1:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\t\t\t// Caveat: CARG2 == BASE\n  |  mov CARG1, L:RB\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call extern lj_dispatch_ins\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  mov BASE, L:RB->base\n  |4:\n  |  movzx RAd, PC_RA\n  |5:\n  |  movzx OP, PC_OP\n  |  movzx RDd, PC_RD\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  add PC, 4\n  |  mov RA, [RB-40]\n  |  mov MULTRES, RAd\t\t\t// Restore MULTRES for *M ins.\n  |  jmp <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  mov LFUNC:RB, [BASE-16]\t\t// Same as curr_topL(L).\n  |  cleartp LFUNC:RB\n  |  mov RB, LFUNC:RB->pc\n  |  movzx RDd, byte [RB+PC2PROTO(framesize)]\n  |  lea RD, [BASE+RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov CARG2, PC\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_trace_hot\t\t// (jit_State *J, const BCIns *pc)\n  |  jmp <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov SAVE_PC, PC\n  |.if JIT\n  |  jmp >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  mov SAVE_PC, PC\n  |  or PC, 1\t\t\t\t// Marker for hot call.\n  |1:\n  |.endif\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov CARG2, PC\n  |  mov CARG1, L:RB\n  |  call extern lj_dispatch_call\t// (lua_State *L, const BCIns *pc)\n  |  // ASMFunction returned in eax/rax (RD).\n  |  mov SAVE_PC, 0\t\t\t// Invalidate for subsequent line hook.\n  |.if JIT\n  |  and PC, -2\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov RA, RD\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  mov RB, RA\n  |  movzx RAd, PC_RA\n  |  shr RDd, 3\n  |  add NARGS:RDd, 1\n  |  jmp RB\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // BASE = base, RC = result, RB = mbase\n  |  mov TRACE:ITYPE, [RB-40]\t\t// Save previous trace.\n  |  cleartp TRACE:ITYPE\n  |  mov TMPRd, MULTRES\n  |  movzx RAd, PC_RA\n  |  lea RA, [BASE+RA*8]\t\t// Call base.\n  |  sub TMPRd, 1\n  |  jz >2\n  |1:  // Move results down.\n  |  mov RB, [RC]\n  |  mov [RA], RB\n  |  add RC, 8\n  |  add RA, 8\n  |  sub TMPRd, 1\n  |  jnz <1\n  |2:\n  |  movzx RCd, PC_RA\n  |  movzx RBd, PC_RB\n  |  add RC, RB\n  |  lea RC, [BASE+RC*8-8]\n  |3:\n  |  cmp RC, RA\n  |  ja >9\t\t\t\t// More results wanted?\n  |\n  |  test TRACE:ITYPE, TRACE:ITYPE\n  |  jz ->cont_nop\n  |  movzx RBd, word TRACE:ITYPE->traceno\n  |  movzx RDd, word TRACE:ITYPE->link\n  |  cmp RDd, RBd\n  |  je ->cont_nop\t\t\t// Blacklisted.\n  |  test RDd, RDd\n  |  jne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  call extern lj_dispatch_stitch\t// (jit_State *J, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  jmp ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  mov aword [RA], LJ_TNIL\n  |  add RA, 8\n  |  jmp <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov CARG2, PC\t\t\t// Caveat: CARG2 == BASE\n  |  mov CARG1, L:RB\n  |  call extern lj_dispatch_profile\t// (lua_State *L, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  sub PC, 4\n  |  jmp ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Called from an exit stub with the exit number on the stack.\n  |// The 16 bit exit number is stored with two (sign-extended) push imm8.\n  |->vm_exit_handler:\n  |.if JIT\n  |  push r13; push r12\n  |  push r11; push r10; push r9; push r8\n  |  push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp\n  |  push rbx; push rdx; push rcx; push rax\n  |  movzx RCd, byte [rbp-8]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [rbp-16]\n  |  mov [rbp-8], r15; mov [rbp-16], r14\n  |  // DISPATCH is preserved on-trace in LJ_GC64 mode.\n  |  mov RAd, [DISPATCH+DISPATCH_GL(vmstate)]\t// Get trace number.\n  |  set_vmstate EXIT\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RCd\n  |  mov [DISPATCH+DISPATCH_J(parent)], RAd\n  |.if X64WIN\n  |  sub rsp, 16*8+4*8\t\t\t// Room for SSE regs + save area.\n  |.else\n  |  sub rsp, 16*8\t\t\t// Room for SSE regs.\n  |.endif\n  |  add rbp, -128\n  |  movsd qword [rbp-8],   xmm15; movsd qword [rbp-16],  xmm14\n  |  movsd qword [rbp-24],  xmm13; movsd qword [rbp-32],  xmm12\n  |  movsd qword [rbp-40],  xmm11; movsd qword [rbp-48],  xmm10\n  |  movsd qword [rbp-56],  xmm9;  movsd qword [rbp-64],  xmm8\n  |  movsd qword [rbp-72],  xmm7;  movsd qword [rbp-80],  xmm6\n  |  movsd qword [rbp-88],  xmm5;  movsd qword [rbp-96],  xmm4\n  |  movsd qword [rbp-104], xmm3;  movsd qword [rbp-112], xmm2\n  |  movsd qword [rbp-120], xmm1;  movsd qword [rbp-128], xmm0\n  |  // Caveat: RB is rbp.\n  |  mov L:RB, [DISPATCH+DISPATCH_GL(cur_L)]\n  |  mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RB\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  lea CARG2, [rsp+4*8]\n  |.else\n  |  mov CARG2, rsp\n  |.endif\n  |  lea CARG1, [DISPATCH+GG_DISP2J]\n  |  mov qword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  call extern lj_trace_exit\t\t// (jit_State *J, ExitState *ex)\n  |  // MULTRES or negated error code returned in eax (RD).\n  |  mov RA, L:RB->cframe\n  |  and RA, CFRAME_RAWMASK\n  |  mov [RA+CFRAME_OFS_L], L:RB\t// Set SAVE_L (on-trace resume/yield).\n  |  mov BASE, L:RB->base\n  |  mov PC, [RA+CFRAME_OFS_PC]\t// Get SAVE_PC.\n  |  jmp >1\n  |.endif\n  |->vm_exit_interp:\n  |  // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |  // Restore additional callee-save registers only used in compiled code.\n  |.if X64WIN\n  |  lea RA, [rsp+10*16+4*8]\n  |1:\n  |  movdqa xmm15, [RA-10*16]\n  |  movdqa xmm14, [RA-9*16]\n  |  movdqa xmm13, [RA-8*16]\n  |  movdqa xmm12, [RA-7*16]\n  |  movdqa xmm11, [RA-6*16]\n  |  movdqa xmm10, [RA-5*16]\n  |  movdqa xmm9, [RA-4*16]\n  |  movdqa xmm8, [RA-3*16]\n  |  movdqa xmm7, [RA-2*16]\n  |  mov rsp, RA\t\t\t// Reposition stack to C frame.\n  |  movdqa xmm6, [RA-1*16]\n  |  mov r15, CSAVE_1\n  |  mov r14, CSAVE_2\n  |  mov r13, CSAVE_3\n  |  mov r12, CSAVE_4\n  |.else\n  |  lea RA, [rsp+16]\n  |1:\n  |  mov r13, [RA-8]\n  |  mov r12, [RA]\n  |  mov rsp, RA\t\t\t// Reposition stack to C frame.\n  |.endif\n  |  test RDd, RDd; js >9\t\t// Check for error from exit.\n  |  mov L:RB, SAVE_L\n  |  mov MULTRES, RDd\n  |  mov LFUNC:KBASE, [BASE-16]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  mov L:RB->base, BASE\n  |  mov qword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  set_vmstate INTERP\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  mov RCd, [PC]\n  |  movzx RAd, RCH\n  |  movzx OP, RCL\n  |  add PC, 4\n  |  shr RCd, 16\n  |  cmp OP, BC_FUNCF\t\t\t// Function header?\n  |  jb >3\n  |  cmp OP, BC_FUNCC+2\t\t\t// Fast function?\n  |  jae >4\n  |2:\n  |  mov RCd, MULTRES\t\t\t// RC/RD holds nres+1.\n  |3:\n  |  jmp aword [DISPATCH+OP*8]\n  |\n  |4:  // Check frame below fast function.\n  |  mov RC, [BASE-8]\n  |  test RCd, FRAME_TYPE\n  |  jnz <2\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  movzx RCd, byte [RC-3]\n  |  neg RC\n  |  mov LFUNC:KBASE, [BASE+RC*8-32]\n  |  cleartp LFUNC:KBASE\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  jmp <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  mov CARG2d, RDd\n  |  mov CARG1, L:RB\n  |  neg CARG2d\n  |  call extern lj_err_trace\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called by math.floor/math.ceil fast functions\n  |// and from JIT code. arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.\n  |.macro vm_round, name, mode, cond\n  |->name:\n  |->name .. _sse:\n  |  sseconst_abs xmm2, RD\n  |  sseconst_2p52 xmm3, RD\n  |  movaps xmm1, xmm0\n  |  andpd xmm1, xmm2\t\t\t// |x|\n  |  ucomisd xmm3, xmm1\t\t\t// No truncation if 2^52 <= |x|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |.if mode == 2\t\t// trunc(x)?\n  |  movaps xmm0, xmm1\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  sseconst_1 xmm3, RD\n  |  cmpsd xmm0, xmm1, 1\t\t// |x| < result?\n  |  andpd xmm0, xmm3\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract -1.\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |.else\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |  .if mode == 1\t\t// ceil(x)?\n  |    sseconst_m1 xmm2, RD\t\t// Must subtract -1 to preserve -0.\n  |    cmpsd xmm0, xmm1, 6\t\t// x > result?\n  |  .else\t\t\t// floor(x)?\n  |    sseconst_1 xmm2, RD\n  |    cmpsd xmm0, xmm1, 1\t\t// x < result?\n  |  .endif\n  |  andpd xmm0, xmm2\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract +-1.\n  |.endif\n  |  movaps xmm0, xmm1\n  |1:\n  |  ret\n  |.endmacro\n  |\n  |  vm_round vm_floor, 0, 1\n  |  vm_round vm_ceil,  1, JIT\n  |  vm_round vm_trunc, 2, JIT\n  |\n  |// FP modulo x%y. Called by BC_MOD* and vm_arith.\n  |->vm_mod:\n  |// Args in xmm0/xmm1, return value in xmm0.\n  |// Caveat: xmm0-xmm5 and RC (eax) modified!\n  |  movaps xmm5, xmm0\n  |  divsd xmm0, xmm1\n  |  sseconst_abs xmm2, RD\n  |  sseconst_2p52 xmm3, RD\n  |  movaps xmm4, xmm0\n  |  andpd xmm4, xmm2\t\t\t// |x/y|\n  |  ucomisd xmm3, xmm4\t\t\t// No truncation if 2^52 <= |x/y|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |  addsd xmm4, xmm3\t\t\t// (|x/y| + 2^52) - 2^52\n  |  subsd xmm4, xmm3\n  |  orpd xmm4, xmm2\t\t\t// Merge sign bit back in.\n  |  sseconst_1 xmm2, RD\n  |  cmpsd xmm0, xmm4, 1\t\t// x/y < result?\n  |  andpd xmm0, xmm2\n  |  subsd xmm4, xmm0\t\t\t// If yes, subtract 1.0.\n  |  movaps xmm0, xmm5\n  |  mulsd xmm1, xmm4\n  |  subsd xmm0, xmm1\n  |  ret\n  |1:\n  |  mulsd xmm1, xmm0\n  |  movaps xmm0, xmm5\n  |  subsd xmm0, xmm1\n  |  ret\n  |\n  |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.\n  |->vm_powi_sse:\n  |  cmp eax, 1; jle >6\t\t\t// i<=1?\n  |  // Now 1 < (unsigned)i <= 0x80000000.\n  |1:  // Handle leading zeros.\n  |  test eax, 1; jnz >2\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1\n  |  jmp <1\n  |2:\n  |  shr eax, 1; jz >5\n  |  movaps xmm1, xmm0\n  |3:  // Handle trailing bits.\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1; jz >4\n  |  jnc <3\n  |  mulsd xmm1, xmm0\n  |  jmp <3\n  |4:\n  |  mulsd xmm0, xmm1\n  |5:\n  |  ret\n  |6:\n  |  je <5\t\t\t\t// x^1 ==> x\n  |  jb >7\t\t\t\t// x^0 ==> 1\n  |  neg eax\n  |  call <1\n  |  sseconst_1 xmm1, RD\n  |  divsd xmm1, xmm0\n  |  movaps xmm0, xmm1\n  |  ret\n  |7:\n  |  sseconst_1 xmm0, RD\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])\n  |->vm_cpuid:\n  |  mov eax, CARG1d\n  |  .if X64WIN; push rsi; mov rsi, CARG2; .endif\n  |  push rbx\n  |  xor ecx, ecx\n  |  cpuid\n  |  mov [rsi], eax\n  |  mov [rsi+4], ebx\n  |  mov [rsi+8], ecx\n  |  mov [rsi+12], edx\n  |  pop rbx\n  |  .if X64WIN; pop rsi; .endif\n  |  ret\n  |\n  |.define NEXT_TAB,\t\tTAB:CARG1\n  |.define NEXT_IDX,\t\tCARG2d\n  |.define NEXT_IDXa,\t\tCARG2\n  |.define NEXT_PTR,\t\tRC\n  |.define NEXT_PTRd,\t\tRCd\n  |.define NEXT_TMP,\t\tCARG3\n  |.define NEXT_ASIZE,\t\tCARG4d\n  |.macro NEXT_RES_IDXL, op2;\tlea edx, [NEXT_IDX+op2]; .endmacro\n  |.if X64WIN\n  |.define NEXT_RES_PTR,\t[rsp+aword*5]\n  |.macro NEXT_RES_IDX, op2;\tadd NEXT_IDX, op2; .endmacro\n  |.else\n  |.define NEXT_RES_PTR,\t[rsp+aword*1]\n  |.macro NEXT_RES_IDX, op2;\tlea edx, [NEXT_IDX+op2]; .endmacro\n  |.endif\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in edx.\n  |->vm_next:\n  |.if JIT\n  |  mov NEXT_ASIZE, NEXT_TAB->asize\n  |1:  // Traverse array part.\n  |  cmp NEXT_IDX, NEXT_ASIZE;  jae >5\n  |  mov NEXT_TMP, NEXT_TAB->array\n  |  mov NEXT_TMP, qword [NEXT_TMP+NEXT_IDX*8]\n  |  cmp NEXT_TMP, LJ_TNIL;  je >2\n  |  lea NEXT_PTR, NEXT_RES_PTR\n  |  mov qword [NEXT_PTR], NEXT_TMP\n  |.if DUALNUM\n  |  setint NEXT_TMP, NEXT_IDXa\n  |  mov qword [NEXT_PTR+qword*1], NEXT_TMP\n  |.else\n  |  cvtsi2sd xmm0, NEXT_IDX\n  |  movsd qword [NEXT_PTR+qword*1], xmm0\n  |.endif\n  |  NEXT_RES_IDX 1\n  |  ret\n  |2:  // Skip holes in array part.\n  |  add NEXT_IDX, 1\n  |  jmp <1\n  |\n  |5:  // Traverse hash part.\n  |  sub NEXT_IDX, NEXT_ASIZE\n  |6:\n  |  cmp NEXT_IDX, NEXT_TAB->hmask; ja >9\n  |  imul NEXT_PTRd, NEXT_IDX, #NODE\n  |  add NODE:NEXT_PTR, NEXT_TAB->node\n  |  cmp qword NODE:NEXT_PTR->val, LJ_TNIL; je >7\n  |  NEXT_RES_IDXL NEXT_ASIZE+1\n  |  ret\n  |7:  // Skip holes in hash part.\n  |  add NEXT_IDX, 1\n  |  jmp <6\n  |\n  |9:  // End of iteration. Set the key to nil (not the value).\n  |  NEXT_RES_IDX NEXT_ASIZE\n  |  lea NEXT_PTR, NEXT_RES_PTR\n  |  mov qword [NEXT_PTR+qword*1], LJ_TNIL\n  |  ret\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Assertions ---------------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->assert_bad_for_arg_type:\n#ifdef LUA_USE_ASSERT\n  |  int3\n#endif\n  |  int3\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in ah/al.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |  saveregs_\t// ebp/rbp already saved. ebp now holds global_State *.\n  |  lea DISPATCH, [ebp+GG_G2DISP]\n  |  mov CTSTATE, GL:ebp->ctype_state\n  |  movzx eax, ax\n  |  mov CTSTATE->cb.slot, eax\n  |  mov CTSTATE->cb.gpr[0], CARG1\n  |  mov CTSTATE->cb.gpr[1], CARG2\n  |  mov CTSTATE->cb.gpr[2], CARG3\n  |  mov CTSTATE->cb.gpr[3], CARG4\n  |  movsd qword CTSTATE->cb.fpr[0], xmm0\n  |  movsd qword CTSTATE->cb.fpr[1], xmm1\n  |  movsd qword CTSTATE->cb.fpr[2], xmm2\n  |  movsd qword CTSTATE->cb.fpr[3], xmm3\n  |.if X64WIN\n  |  lea rax, [rsp+CFRAME_SIZE+4*8]\n  |.else\n  |  lea rax, [rsp+CFRAME_SIZE]\n  |  mov CTSTATE->cb.gpr[4], CARG5\n  |  mov CTSTATE->cb.gpr[5], CARG6\n  |  movsd qword CTSTATE->cb.fpr[4], xmm4\n  |  movsd qword CTSTATE->cb.fpr[5], xmm5\n  |  movsd qword CTSTATE->cb.fpr[6], xmm6\n  |  movsd qword CTSTATE->cb.fpr[7], xmm7\n  |.endif\n  |  mov CTSTATE->cb.stack, rax\n  |  mov CARG2, rsp\n  |  mov SAVE_PC, CTSTATE\t\t// Any value outside of bytecode is ok.\n  |  mov CARG1, CTSTATE\n  |  call extern lj_ccallback_enter\t// (CTState *cts, void *cf)\n  |  // lua_State * returned in eax (RD).\n  |  set_vmstate INTERP\n  |  mov BASE, L:RD->base\n  |  mov RD, L:RD->top\n  |  sub RD, BASE\n  |  mov LFUNC:RB, [BASE-16]\n  |  cleartp LFUNC:RB\n  |  shr RD, 3\n  |  add RD, 1\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  mov L:RA, SAVE_L\n  |  mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]\n  |  mov aword CTSTATE->L, L:RA\n  |  mov L:RA->base, BASE\n  |  mov L:RA->top, RB\n  |  mov CARG1, CTSTATE\n  |  mov CARG2, RC\n  |  call extern lj_ccallback_leave\t// (CTState *cts, TValue *o)\n  |  mov rax, CTSTATE->cb.gpr[0]\n  |  movsd xmm0, qword CTSTATE->cb.fpr[0]\n  |  jmp ->vm_leave_unw\n  |.endif\n  |\n  |->vm_ffi_call:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |  .type CCSTATE, CCallState, rbx\n  |  push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1\n  |\n  |  // Readjust stack.\n  |  mov eax, CCSTATE->spadj\n  |  sub rsp, rax\n  |\n  |  // Copy stack slots.\n  |  movzx ecx, byte CCSTATE->nsp\n  |  sub ecx, 1\n  |  js >2\n  |1:\n  |  mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]\n  |  mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax\n  |  sub ecx, 1\n  |  jns <1\n  |2:\n  |\n  |  movzx eax, byte CCSTATE->nfpr\n  |  mov CARG1, CCSTATE->gpr[0]\n  |  mov CARG2, CCSTATE->gpr[1]\n  |  mov CARG3, CCSTATE->gpr[2]\n  |  mov CARG4, CCSTATE->gpr[3]\n  |.if not X64WIN\n  |  mov CARG5, CCSTATE->gpr[4]\n  |  mov CARG6, CCSTATE->gpr[5]\n  |.endif\n  |  test eax, eax; jz >5\n  |  movaps xmm0, CCSTATE->fpr[0]\n  |  movaps xmm1, CCSTATE->fpr[1]\n  |  movaps xmm2, CCSTATE->fpr[2]\n  |  movaps xmm3, CCSTATE->fpr[3]\n  |.if not X64WIN\n  |  cmp eax, 4; jbe >5\n  |  movaps xmm4, CCSTATE->fpr[4]\n  |  movaps xmm5, CCSTATE->fpr[5]\n  |  movaps xmm6, CCSTATE->fpr[6]\n  |  movaps xmm7, CCSTATE->fpr[7]\n  |.endif\n  |5:\n  |\n  |  call aword CCSTATE->func\n  |\n  |  mov CCSTATE->gpr[0], rax\n  |  movaps CCSTATE->fpr[0], xmm0\n  |.if not X64WIN\n  |  mov CCSTATE->gpr[1], rdx\n  |  movaps CCSTATE->fpr[1], xmm1\n  |.endif\n  |\n  |  mov rbx, [rbp-8]; leave; ret\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |// Note: aligning all instructions does not pay off.\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  |.macro jmp_comp, lt, ge, le, gt, target\n  ||switch (op) {\n  ||case BC_ISLT:\n  |   lt target\n  ||break;\n  ||case BC_ISGE:\n  |   ge target\n  ||break;\n  ||case BC_ISLE:\n  |   le target\n  ||break;\n  ||case BC_ISGT:\n  |   gt target\n  ||break;\n  ||default: break;  /* Shut up GCC. */\n  ||}\n  |.endmacro\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RD = src2, JMP with RD = target\n    |  ins_AD\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov RB, [BASE+RD*8]\n    |  mov RA, ITYPE\n    |  mov RD, RB\n    |  sar ITYPE, 47\n    |  sar RB, 47\n    |.if DUALNUM\n    |  cmp ITYPEd, LJ_TISNUM; jne >7\n    |  cmp RBd, LJ_TISNUM; jne >8\n    |  add PC, 4\n    |  cmp RAd, RDd\n    |  jmp_comp jge, jl, jg, jle, >9\n    |6:\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is a number.\n    |  cmp RBd, LJ_TISNUM; jb >1; jne ->vmeta_comp\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, RDd\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm1, RAd\n    |  movd xmm0, RD\n    |  jmp >3\n    |.else\n    |  cmp ITYPEd, LJ_TISNUM; jae ->vmeta_comp\n    |  cmp RBd, LJ_TISNUM; jae ->vmeta_comp\n    |.endif\n    |1:\n    |  movd xmm0, RD\n    |2:\n    |  movd xmm1, RA\n    |3:\n    |  add PC, 4\n    |  ucomisd xmm0, xmm1\n    |  // Unordered: all of ZF CF PF set, ordered: PF clear.\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    |.if DUALNUM\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  jmp_comp jbe, ja, jb, jae, >1\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  ins_AD\t// RA = src1, RD = src2, JMP with RD = target\n    |  mov RB, [BASE+RD*8]\n    |  mov ITYPE, [BASE+RA*8]\n    |  add PC, 4\n    |  mov RD, RB\n    |  mov RA, ITYPE\n    |  sar RB, 47\n    |  sar ITYPE, 47\n    |.if DUALNUM\n    |  cmp RBd, LJ_TISNUM; jne >7\n    |  cmp ITYPEd, LJ_TISNUM; jne >8\n    |  cmp RDd, RAd\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RD is not an integer.\n    |  ja >5\n    |  // RD is a number.\n    |  movd xmm1, RD\n    |  cmp ITYPEd, LJ_TISNUM; jb >1; jne >5\n    |  // RD is a number, RA is an integer.\n    |  cvtsi2sd xmm0, RAd\n    |  jmp >2\n    |\n    |8:  // RD is an integer, RA is not an integer.\n    |  ja >5\n    |  // RD is an integer, RA is a number.\n    |  cvtsi2sd xmm1, RDd\n    |  jmp >1\n    |\n    |.else\n    |  cmp RBd, LJ_TISNUM; jae >5\n    |  cmp ITYPEd, LJ_TISNUM; jae >5\n    |  movd xmm1, RD\n    |.endif\n    |1:\n    |  movd xmm0, RA\n    |2:\n    |  ucomisd xmm0, xmm1\n    |4:\n  iseqne_fp:\n    if (vk) {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  jne >2\n    } else {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  je >1\n    }\n  iseqne_end:\n    if (vk) {\n      |1:\t\t\t\t// EQ: Branch to the target.\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\t\t\t\t// NE: Fallthrough to next instruction.\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |.if not FFI\n      |3:\n      |.endif\n      |2:\t\t\t\t// NE: Branch to the target.\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |1:\t\t\t\t// EQ: Fallthrough to next instruction.\n    }\n    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||\n\t\t       op == BC_ISEQN || op == BC_ISNEN)) {\n      |  jmp <9\n    } else {\n      |  ins_next\n    }\n    |\n    if (op == BC_ISEQV || op == BC_ISNEV) {\n      |5:  // Either or both types are not numbers.\n      |.if FFI\n      |  cmp RBd, LJ_TCDATA; je ->vmeta_equal_cd\n      |  cmp ITYPEd, LJ_TCDATA; je ->vmeta_equal_cd\n      |.endif\n      |  cmp RA, RD\n      |  je <1\t\t\t\t// Same GCobjs or pvalues?\n      |  cmp RBd, ITYPEd\n      |  jne <2\t\t\t\t// Not the same type?\n      |  cmp RBd, LJ_TISTABUD\n      |  ja <2\t\t\t\t// Different objects and not table/ud?\n      |\n      |  // Different tables or userdatas. Need to check __eq metamethod.\n      |  // Field metatable must be at same offset for GCtab and GCudata!\n      |  cleartp TAB:RA\n      |  mov TAB:RB, TAB:RA->metatable\n      |  test TAB:RB, TAB:RB\n      |  jz <2\t\t\t\t// No metatable?\n      |  test byte TAB:RB->nomm, 1<<MM_eq\n      |  jnz <2\t\t\t\t// Or 'no __eq' flag set?\n      if (vk) {\n\t|  xor RBd, RBd\t\t\t// ne = 0\n      } else {\n\t|  mov RBd, 1\t\t\t// ne = 1\n      }\n      |  jmp ->vmeta_equal\t\t// Handle __eq metamethod.\n    } else {\n      |.if FFI\n      |3:\n      |  cmp ITYPEd, LJ_TCDATA\n      if (LJ_DUALNUM && vk) {\n\t|  jne <9\n      } else {\n\t|  jne <2\n      }\n      |  jmp ->vmeta_equal_cd\n      |.endif\n    }\n    break;\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  ins_AND\t// RA = src, RD = str const, JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  add PC, 4\n    |  checkstr RB, >3\n    |  cmp RB, [KBASE+RD*8]\n  iseqne_test:\n    if (vk) {\n      |  jne >2\n    } else {\n      |  je >1\n    }\n    goto iseqne_end;\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  ins_AD\t// RA = src, RD = num const, JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  add PC, 4\n    |.if DUALNUM\n    |  checkint RB, >7\n    |  mov RD, [KBASE+RD*8]\n    |  checkint RD, >8\n    |  cmp RBd, RDd\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja >3\n    |  // RA is a number.\n    |  mov RD, [KBASE+RD*8]\n    |  checkint RD, >1\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, RDd\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm0, RBd\n    |  movd xmm1, RD\n    |  ucomisd xmm0, xmm1\n    |  jmp >4\n    |1:\n    |  movd xmm0, RD\n    |.else\n    |  checknum RB, >3\n    |1:\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |.endif\n    |2:\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |4:\n    goto iseqne_fp;\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  ins_AND\t// RA = src, RD = primitive type (~), JMP with RD = target\n    |  mov RB, [BASE+RA*8]\n    |  sar RB, 47\n    |  add PC, 4\n    |  cmp RBd, RDd\n    if (!LJ_HASFFI) goto iseqne_test;\n    if (vk) {\n      |  jne >3\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n      |3:\n      |  cmp RBd, LJ_TCDATA; jne <2\n      |  jmp ->vmeta_equal_cd\n    } else {\n      |  je >2\n      |  cmp RBd, LJ_TCDATA; je ->vmeta_equal_cd\n      |  movzx RDd, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  ins_AD\t// RA = dst or unused, RD = src, JMP with RD = target\n    |  mov ITYPE, [BASE+RD*8]\n    |  add PC, 4\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov RB, ITYPE\n    }\n    |  sar ITYPE, 47\n    |  cmp ITYPEd, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISTC) {\n      |  jae >1\n    } else {\n      |  jb >1\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov [BASE+RA*8], RB\n    }\n    |  movzx RDd, PC_RD\n    |  branchPC RD\n    |1:\t\t\t\t\t// Fallthrough to the next instruction.\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  ins_AD\t// RA = src, RD = -type\n    |  mov RB, [BASE+RA*8]\n    |  sar RB, 47\n    |  add RBd, RDd\n    |  jne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  ins_AD\t// RA = src, RD = -(TISNUM-1)\n    |  checknumtp [BASE+RA*8], ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |  mov [BASE+RA*8], RB\n    |  ins_next_\n    break;\n  case BC_NOT:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |  sar RB, 47\n    |  mov RCd, 2\n    |  cmp RB, LJ_TISTRUECOND\n    |  sbb RCd, 0\n    |  shl RC, 47\n    |  not RC\n    |  mov [BASE+RA*8], RC\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RB, [BASE+RD*8]\n    |.if DUALNUM\n    |  checkint RB, >5\n    |  neg RBd\n    |  jo >4\n    |  setint RB\n    |9:\n    |  mov [BASE+RA*8], RB\n    |  ins_next\n    |4:\n    |  mov64 RB, U64x(41e00000,00000000)  // 2^31.\n    |  jmp <9\n    |5:\n    |  ja ->vmeta_unm\n    |.else\n    |  checknum RB, ->vmeta_unm\n    |.endif\n    |  mov64 RD, U64x(80000000,00000000)\n    |  xor RB, RD\n    |.if DUALNUM\n    |  jmp <9\n    |.else\n    |  mov [BASE+RA*8], RB\n    |  ins_next\n    |.endif\n    break;\n  case BC_LEN:\n    |  ins_AD\t// RA = dst, RD = src\n    |  mov RD, [BASE+RD*8]\n    |  checkstr RD, >2\n    |.if DUALNUM\n    |  mov RDd, dword STR:RD->len\n    |1:\n    |  setint RD\n    |  mov [BASE+RA*8], RD\n    |.else\n    |  xorps xmm0, xmm0\n    |  cvtsi2sd xmm0, dword STR:RD->len\n    |1:\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    |2:\n    |  cmp ITYPEd, LJ_TTAB; jne ->vmeta_len\n    |  mov TAB:CARG1, TAB:RD\n#if LJ_52\n    |  mov TAB:RB, TAB:RD->metatable\n    |  cmp TAB:RB, 0\n    |  jnz >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |  call extern lj_tab_len\t\t// (GCtab *t)\n    |  // Length of table returned in eax (RD).\n    |.if DUALNUM\n    |  // Nothing to do.\n    |.else\n    |  cvtsi2sd xmm0, RDd\n    |.endif\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  movzx RAd, PC_RA\n    |  jmp <1\n#if LJ_52\n    |9:  // Check for __len.\n    |  test byte TAB:RB->nomm, 1<<MM_len\n    |  jnz <3\n    |  jmp ->vmeta_len\t\t\t// 'no __len' flag NOT set: check.\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre, sseins, ssereg\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_vn\n    |   .if DUALNUM\n    |     checknumtp [KBASE+RC*8], ->vmeta_arith_vn\n    |   .endif\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [KBASE+RC*8]\n    ||  break;\n    ||case 1:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_nv\n    |   .if DUALNUM\n    |     checknumtp [KBASE+RC*8], ->vmeta_arith_nv\n    |   .endif\n    |   movsd xmm0, qword [KBASE+RC*8]\n    |   sseins ssereg, qword [BASE+RB*8]\n    ||  break;\n    ||default:\n    |   checknumtp [BASE+RB*8], ->vmeta_arith_vv\n    |   checknumtp [BASE+RC*8], ->vmeta_arith_vv\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [BASE+RC*8]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [KBASE+RC*8]\n    |   checkint RB, ->vmeta_arith_vno\n    |   checkint RC, ->vmeta_arith_vno\n    |   intins RBd, RCd; jo ->vmeta_arith_vno\n    ||  break;\n    ||case 1:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [KBASE+RC*8]\n    |   checkint RB, ->vmeta_arith_nvo\n    |   checkint RC, ->vmeta_arith_nvo\n    |   intins RCd, RBd; jo ->vmeta_arith_nvo\n    ||  break;\n    ||default:\n    |   mov RB, [BASE+RB*8]\n    |   mov RC, [BASE+RC*8]\n    |   checkint RB, ->vmeta_arith_vvo\n    |   checkint RC, ->vmeta_arith_vvo\n    |   intins RBd, RCd; jo ->vmeta_arith_vvo\n    ||  break;\n    ||}\n    ||if (vk == 1) {\n    |   setint RC\n    |   mov [BASE+RA*8], RC\n    ||} else {\n    |   setint RB\n    |   mov [BASE+RA*8], RB\n    ||}\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arithpost\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endmacro\n    |\n    |.macro ins_arith, sseins\n    |  ins_arithpre sseins, xmm0\n    |  ins_arithpost\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arith, intins, sseins\n    |.if DUALNUM\n    |  ins_arithdn intins\n    |.else\n    |  ins_arith, sseins\n    |.endif\n    |.endmacro\n\n    |  // RA = dst, RB = src1 or num const, RC = src2 or num const\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith add, addsd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith sub, subsd\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith imul, mulsd\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arith divsd\n    break;\n  case BC_MODVN:\n    |  ins_arithpre movsd, xmm1\n    |->BC_MODVN_Z:\n    |  call ->vm_mod\n    |  ins_arithpost\n    |  ins_next\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre movsd, xmm1\n    |  jmp ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    break;\n  case BC_POW:\n    |  ins_arithpre movsd, xmm1\n    |  mov RB, BASE\n    |  call extern pow\n    |  movzx RAd, PC_RA\n    |  mov BASE, RB\n    |  ins_arithpost\n    |  ins_next\n    break;\n\n  case BC_CAT:\n    |  ins_ABC\t// RA = dst, RB = src_start, RC = src_end\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\n    |  lea CARG2, [BASE+RC*8]\n    |  mov CARG3d, RCd\n    |  sub CARG3d, RBd\n    |->BC_CAT_Z:\n    |  mov L:RB, L:CARG1\n    |  mov SAVE_PC, PC\n    |  call extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  test RC, RC\n    |  jnz ->vmeta_binop\n    |  movzx RBd, PC_RB\t\t\t// Copy result to Stk[RA] from Stk[RB].\n    |  movzx RAd, PC_RA\n    |  mov RC, [BASE+RB*8]\n    |  mov [BASE+RA*8], RC\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov RD, [KBASE+RD*8]\n    |  settp RD, LJ_TSTR\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  ins_AND\t// RA = dst, RD = cdata const (~)\n    |  mov RD, [KBASE+RD*8]\n    |  settp RD, LJ_TCDATA\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  ins_AD\t// RA = dst, RD = signed int16 literal\n    |.if DUALNUM\n    |  movsx RDd, RDW\n    |  setint RD\n    |  mov [BASE+RA*8], RD\n    |.else\n    |  movsx RDd, RDW\t\t\t// Sign-extend literal.\n    |  cvtsi2sd xmm0, RDd\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  ins_AD\t// RA = dst, RD = num const\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  movsd qword [BASE+RA*8], xmm0\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  ins_AD\t// RA = dst, RD = primitive type (~)\n    |  shl RD, 47\n    |  not RD\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  ins_AD\t// RA = dst_start, RD = dst_end\n    |  lea RA, [BASE+RA*8+8]\n    |  lea RD, [BASE+RD*8]\n    |  mov RB, LJ_TNIL\n    |  mov [RA-8], RB\t\t\t// Sets minimum 2 slots.\n    |1:\n    |  mov [RA], RB\n    |  add RA, 8\n    |  cmp RA, RD\n    |  jbe <1\n    |  ins_next\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  ins_AD\t// RA = dst, RD = upvalue #\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RD*8+offsetof(GCfuncL, uvptr)]\n    |  mov RB, UPVAL:RB->v\n    |  mov RD, [RB]\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_USETV:\n#define TV2MARKOFS \\\n ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))\n    |  ins_AD\t// RA = upvalue #, RD = src\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  cmp byte UPVAL:RB->closed, 0\n    |  mov RB, UPVAL:RB->v\n    |  mov RA, [BASE+RD*8]\n    |  mov [RB], RA\n    |  jz >1\n    |  // Check barrier for closed upvalue.\n    |  test byte [RB+TV2MARKOFS], LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Upvalue is black. Check if new value is collectable and white.\n    |  mov RD, RA\n    |  sar RD, 47\n    |  sub RDd, LJ_TISGCV\n    |  cmp RDd, LJ_TNUMX - LJ_TISGCV\t\t\t// tvisgcv(v)\n    |  jbe <1\n    |  cleartp GCOBJ:RA\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(v)\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if not X64WIN\n    |  mov CARG2, RB\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |.else\n    |  xchg CARG2, RB\t\t\t// Save BASE (CARG2 == BASE).\n    |.endif\n    |  lea GL:CARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n#undef TV2MARKOFS\n  case BC_USETS:\n    |  ins_AND\t// RA = upvalue #, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  mov STR:RA, [KBASE+RD*8]\n    |  mov RD, UPVAL:RB->v\n    |  settp STR:ITYPE, STR:RA, LJ_TSTR\n    |  mov [RD], STR:ITYPE\n    |  test byte UPVAL:RB->marked, LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(str)\n    |  jz <1\n    |  cmp byte UPVAL:RB->closed, 0\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov RB, BASE\t\t\t// Save BASE (CARG2 == BASE).\n    |  mov CARG2, RD\n    |  lea GL:CARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n  case BC_USETN:\n    |  ins_AD\t// RA = upvalue #, RD = num const\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  movsd qword [RA], xmm0\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  ins_AD\t// RA = upvalue #, RD = primitive type (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov UPVAL:RB, [LFUNC:RB+RA*8+offsetof(GCfuncL, uvptr)]\n    |  shl RD, 47\n    |  not RD\n    |  mov RA, UPVAL:RB->v\n    |  mov [RA], RD\n    |  ins_next\n    break;\n  case BC_UCLO:\n    |  ins_AD\t// RA = level, RD = target\n    |  branchPC RD\t\t\t// Do this first to free RD.\n    |  mov L:RB, SAVE_L\n    |  cmp aword L:RB->openupval, 0\n    |  je >1\n    |  mov L:RB->base, BASE\n    |  lea CARG2, [BASE+RA*8]\t\t// Caveat: CARG2 == BASE\n    |  mov L:CARG1, L:RB\t\t// Caveat: CARG1 == RA\n    |  call extern lj_func_closeuv\t// (lua_State *L, TValue *level)\n    |  mov BASE, L:RB->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  ins_AND\t// RA = dst, RD = proto const (~) (holding function prototype)\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n    |  mov CARG3, [BASE-16]\n    |  cleartp CARG3\n    |  mov CARG2, [KBASE+RD*8]\t\t// Fetch GCproto *.\n    |  mov CARG1, L:RB\n    |  mov SAVE_PC, PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call extern lj_func_newL_gc\n    |  // GCfuncL * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp LFUNC:RC, LJ_TFUNC\n    |  mov [BASE+RA*8], LFUNC:RC\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n    |  ins_AD\t// RA = dst, RD = hbits|asize\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov SAVE_PC, PC\n    |  jae >5\n    |1:\n    |  mov CARG3d, RDd\n    |  and RDd, 0x7ff\n    |  shr CARG3d, 11\n    |  cmp RDd, 0x7ff\n    |  je >3\n    |2:\n    |  mov L:CARG1, L:RB\n    |  mov CARG2d, RDd\n    |  call extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp TAB:RC, LJ_TTAB\n    |  mov [BASE+RA*8], TAB:RC\n    |  ins_next\n    |3:  // Turn 0x7ff into 0x801.\n    |  mov RDd, 0x801\n    |  jmp <2\n    |5:\n    |  mov L:CARG1, L:RB\n    |  call extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  movzx RDd, PC_RD\n    |  jmp <1\n    break;\n  case BC_TDUP:\n    |  ins_AND\t// RA = dst, RD = table const (~) (holding template table)\n    |  mov L:RB, SAVE_L\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  mov SAVE_PC, PC\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov L:RB->base, BASE\n    |  jae >3\n    |2:\n    |  mov TAB:CARG2, [KBASE+RD*8]\t// Caveat: CARG2 == BASE\n    |  mov L:CARG1, L:RB\t\t// Caveat: CARG1 == RA\n    |  call extern lj_tab_dup\t\t// (lua_State *L, Table *kt)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\n    |  settp TAB:RC, LJ_TTAB\n    |  mov [BASE+RA*8], TAB:RC\n    |  ins_next\n    |3:\n    |  mov L:CARG1, L:RB\n    |  call extern lj_gc_step_fixtop\t// (lua_State *L)\n    |  movzx RDd, PC_RD\t\t\t// Need to reload RD.\n    |  not RD\n    |  jmp <2\n    break;\n\n  case BC_GGET:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*8]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_GSET:\n    |  ins_AND\t// RA = src, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-16]\n    |  cleartp LFUNC:RB\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*8]\n    |  jmp ->BC_TSETS_Z\n    break;\n\n  case BC_TGETV:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  mov RC, [BASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tgetv\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movd xmm0, RC\n    |  cvttsd2si RCd, xmm0\n    |  cvtsi2sd xmm1, RCd\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tgetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RCd, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tgetv\t\t// Not in array part? Use fallback.\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |  mov ITYPE, [RC]\n    |  cmp ITYPE, LJ_TNIL\t\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |1:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetv\t\t\t// 'no __index' flag NOT set: check.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  cmp ITYPEd, LJ_TSTR; jne ->vmeta_tgetv\n    |  cleartp STR:RC\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  ins_ABC\t// RA = dst, RB = table, RC = str const (~)\n    |  mov TAB:RB, [BASE+RB*8]\n    |  not RC\n    |  mov STR:RC, [KBASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tgets\n    |->BC_TGETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  mov TMPRd, TAB:RB->hmask\n    |  and TMPRd, STR:RC->sid\n    |  imul TMPRd, #NODE\n    |  add NODE:TMPR, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cmp NODE:TMPR->key, ITYPE\n    |  jne >4\n    |  // Get node value.\n    |  mov ITYPE, NODE:TMPR->val\n    |  cmp ITYPE, LJ_TNIL\n    |  je >5\t\t\t\t// Key found, but nil value?\n    |2:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |4:  // Follow hash chain.\n    |  mov NODE:TMPR, NODE:TMPR->next\n    |  test NODE:TMPR, NODE:TMPR\n    |  jnz <1\n    |  // End of hash chain: key not found, nil result.\n    |  mov ITYPE, LJ_TNIL\n    |\n    |5:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <2\t\t\t\t// No metatable: done.\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jnz <2\t\t\t\t// 'no __index' flag set: done.\n    |  jmp ->vmeta_tgets\t\t// Caveat: preserve STR:RC.\n    break;\n  case BC_TGETB:\n    |  ins_ABC\t// RA = dst, RB = table, RC = byte literal\n    |  mov TAB:RB, [BASE+RB*8]\n    |  checktab TAB:RB, ->vmeta_tgetb\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tgetb\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |  mov ITYPE, [RC]\n    |  cmp ITYPE, LJ_TNIL\n    |  je >2\n    |1:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetb\t\t\t// 'no __index' flag NOT set: check.\n    |  jmp <1\n    break;\n  case BC_TGETR:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cleartp TAB:RB\n    |.if DUALNUM\n    |  mov RCd, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RCd, qword [BASE+RC*8]\n    |.endif\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tgetr\t\t// Not in array part? Use fallback.\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |->BC_TGETR_Z:\n    |  mov ITYPE, [RC]\n    |->BC_TGETR2_Z:\n    |  mov [BASE+RA*8], ITYPE\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  mov RC, [BASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tsetv\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movd xmm0, RC\n    |  cvttsd2si RCd, xmm0\n    |  cvtsi2sd xmm1, RCd\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tsetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RCd, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tsetv\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  cmp aword [RC], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:  // Set array slot.\n    |  mov RB, [BASE+RA*8]\n    |  mov [RC], RB\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetv\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  cmp ITYPEd, LJ_TSTR; jne ->vmeta_tsetv\n    |  cleartp STR:RC\n    |  jmp ->BC_TSETS_Z\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n  case BC_TSETS:\n    |  ins_ABC\t// RA = src, RB = table, RC = str const (~)\n    |  mov TAB:RB, [BASE+RB*8]\n    |  not RC\n    |  mov STR:RC, [KBASE+RC*8]\n    |  checktab TAB:RB, ->vmeta_tsets\n    |->BC_TSETS_Z:\t// RB = GCtab *, RC = GCstr *\n    |  mov TMPRd, TAB:RB->hmask\n    |  and TMPRd, STR:RC->sid\n    |  imul TMPRd, #NODE\n    |  mov byte TAB:RB->nomm, 0\t\t// Clear metamethod cache.\n    |  add NODE:TMPR, TAB:RB->node\n    |  settp ITYPE, STR:RC, LJ_TSTR\n    |1:\n    |  cmp NODE:TMPR->key, ITYPE\n    |  jne >5\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp aword [TMPR], LJ_TNIL\n    |  je >4\t\t\t\t// Previous value is nil?\n    |2:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |3:  // Set node value.\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [TMPR], ITYPE\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  mov TAB:ITYPE, TAB:RB->metatable\n    |  test TAB:ITYPE, TAB:ITYPE\n    |  jz <2\n    |  test byte TAB:ITYPE->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <2\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:TMPR, NODE:TMPR->next\n    |  test NODE:TMPR, NODE:TMPR\n    |  jnz <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz >6\t\t\t\t// No metatable: continue.\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mov TMP1, ITYPE\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\n    |  lea CARG3, TMP1\n    |  mov CARG2, TAB:RB\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Handles write barrier for the new key. TValue * returned in eax (RC).\n    |  mov L:CARG1, SAVE_L\n    |  mov BASE, L:CARG1->base\n    |  mov TMPR, rax\n    |  movzx RAd, PC_RA\n    |  jmp <2\t\t\t\t// Must check write barrier for value.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, ITYPE\n    |  jmp <3\n    break;\n  case BC_TSETB:\n    |  ins_ABC\t// RA = src, RB = table, RC = byte literal\n    |  mov TAB:RB, [BASE+RB*8]\n    |  checktab TAB:RB, ->vmeta_tsetb\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tsetb\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  cmp aword [RC], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\t // Set array slot.\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [RC], ITYPE\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  mov TAB:TMPR, TAB:RB->metatable\n    |  test TAB:TMPR, TAB:TMPR\n    |  jz <1\n    |  test byte TAB:TMPR->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetb\t\t\t// 'no __newindex' flag NOT set: check.\n    |  jmp <1\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n  case BC_TSETR:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cleartp TAB:RB\n    |.if DUALNUM\n    |  mov RC, [BASE+RC*8]\n    |.else\n    |  cvttsd2si RCd, qword [BASE+RC*8]\n    |.endif\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  cmp RCd, TAB:RB->asize\n    |  jae ->vmeta_tsetr\n    |  shl RCd, 3\n    |  add RC, TAB:RB->array\n    |  // Set array slot.\n    |->BC_TSETR_Z:\n    |  mov ITYPE, [BASE+RA*8]\n    |  mov [RC], ITYPE\n    |  ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, TMPR\n    |  jmp <2\n    break;\n\n  case BC_TSETM:\n    |  ins_AD\t// RA = base (table at base-1), RD = num const (start index)\n    |1:\n    |  mov TMPRd, dword [KBASE+RD*8]\t// Integer constant is in lo-word.\n    |  lea RA, [BASE+RA*8]\n    |  mov TAB:RB, [RA-8]\t\t// Guaranteed to be a table.\n    |  cleartp TAB:RB\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  mov RDd, MULTRES\n    |  sub RDd, 1\n    |  jz >4\t\t\t\t// Nothing to copy?\n    |  add RDd, TMPRd\t\t\t// Compute needed size.\n    |  cmp RDd, TAB:RB->asize\n    |  ja >5\t\t\t\t// Doesn't fit into array part?\n    |  sub RDd, TMPRd\n    |  shl TMPRd, 3\n    |  add TMPR, TAB:RB->array\n    |3:  // Copy result slots to table.\n    |  mov RB, [RA]\n    |  add RA, 8\n    |  mov [TMPR], RB\n    |  add TMPR, 8\n    |  sub RDd, 1\n    |  jnz <3\n    |4:\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |  mov L:CARG1, SAVE_L\n    |  mov L:CARG1->base, BASE\t\t// Caveat: CARG2/CARG3 may be BASE.\n    |  mov CARG2, TAB:RB\n    |  mov CARG3d, RDd\n    |  mov L:RB, L:CARG1\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |  mov BASE, L:RB->base\n    |  movzx RAd, PC_RA\t\t\t// Restore RA.\n    |  movzx RDd, PC_RD\t\t\t// Restore RD.\n    |  jmp <1\t\t\t\t// Retry.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:RB, RD\n    |  jmp <2\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALL: case BC_CALLM:\n    |  ins_A_C\t// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs\n    if (op == BC_CALLM) {\n      |  add NARGS:RDd, MULTRES\n    }\n    |  mov LFUNC:RB, [BASE+RA*8]\n    |  checkfunc LFUNC:RB, ->vmeta_call_ra\n    |  lea BASE, [BASE+RA*8+16]\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  ins_AD\t// RA = base, RD = extra_nargs\n    |  add NARGS:RDd, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.\n    break;\n  case BC_CALLT:\n    |  ins_AD\t// RA = base, RD = nargs+1\n    |  lea RA, [BASE+RA*8+16]\n    |  mov KBASE, BASE\t\t\t// Use KBASE for move + vmeta_call hint.\n    |  mov LFUNC:RB, [RA-16]\n    |  checktp_nc LFUNC:RB, LJ_TFUNC, ->vmeta_call\n    |->BC_CALLT_Z:\n    |  mov PC, [BASE-8]\n    |  test PCd, FRAME_TYPE\n    |  jnz >7\n    |1:\n    |  mov [BASE-16], LFUNC:RB\t\t// Copy func+tag down, reloaded below.\n    |  mov MULTRES, NARGS:RDd\n    |  sub NARGS:RDd, 1\n    |  jz >3\n    |2:  // Move args down.\n    |  mov RB, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RB\n    |  add KBASE, 8\n    |  sub NARGS:RDd, 1\n    |  jnz <2\n    |\n    |  mov LFUNC:RB, [BASE-16]\n    |3:\n    |  cleartp LFUNC:RB\n    |  mov NARGS:RDd, MULTRES\n    |  cmp byte LFUNC:RB->ffid, 1\t// (> FF_C) Calling a fast function?\n    |  ja >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function.\n    |  test PCd, FRAME_TYPE\t\t// Lua frame below?\n    |  jnz <4\n    |  movzx RAd, PC_RA\n    |  neg RA\n    |  mov LFUNC:KBASE, [BASE+RA*8-32]\t// Need to prepare KBASE.\n    |  cleartp LFUNC:KBASE\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  jmp <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  sub PC, FRAME_VARG\n    |  test PCd, FRAME_TYPEP\n    |  jnz >8\t\t\t\t// Vararg frame below?\n    |  sub BASE, PC\t\t\t// Need to relocate BASE/KBASE down.\n    |  mov KBASE, BASE\n    |  mov PC, [BASE-8]\n    |  jmp <1\n    |8:\n    |  add PCd, FRAME_VARG\n    |  jmp <1\n    break;\n\n  case BC_ITERC:\n    |  ins_A\t// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)\n    |  lea RA, [BASE+RA*8+16]\t\t// fb = base+2\n    |  mov RB, [RA-32]\t\t\t// Copy state. fb[0] = fb[-4].\n    |  mov RC, [RA-24]\t\t\t// Copy control var. fb[1] = fb[-3].\n    |  mov [RA], RB\n    |  mov [RA+8], RC\n    |  mov LFUNC:RB, [RA-40]\t\t// Copy callable. fb[-2] = fb[-5]\n    |  mov [RA-16], LFUNC:RB\n    |  mov NARGS:RDd, 2+1\t\t// Handle like a regular 2-arg call.\n    |  checkfunc LFUNC:RB, ->vmeta_call\n    |  mov BASE, RA\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    |->vm_IITERN:\n    |  ins_A\t// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  mov TAB:RB, [BASE+RA*8-16]\n    |  cleartp TAB:RB\n    |  mov RCd, [BASE+RA*8-8]\t\t// Get index from control var.\n    |  mov TMPRd, TAB:RB->asize\n    |  add PC, 4\n    |  mov ITYPE, TAB:RB->array\n    |1:  // Traverse array part.\n    |  cmp RCd, TMPRd; jae >5\t\t// Index points after array part?\n    |  cmp aword [ITYPE+RC*8], LJ_TNIL; je >4\n    |.if not DUALNUM\n    |  cvtsi2sd xmm0, RCd\n    |.endif\n    |  // Copy array slot to returned value.\n    |  mov RB, [ITYPE+RC*8]\n    |  mov [BASE+RA*8+8], RB\n    |  // Return array index as a numeric key.\n    |.if DUALNUM\n    |  setint ITYPE, RC\n    |  mov [BASE+RA*8], ITYPE\n    |.else\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  add RCd, 1\n    |  mov [BASE+RA*8-8], RCd\t\t// Update control var.\n    |2:\n    |  movzx RDd, PC_RD\t\t\t// Get target from ITERL.\n    |  branchPC RD\n    |3:\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  add RCd, 1\n    |  jmp <1\n    |\n    |5:  // Traverse hash part.\n    |  sub RCd, TMPRd\n    |6:\n    |  cmp RCd, TAB:RB->hmask; ja <3\t// End of iteration? Branch to ITERL+1.\n    |  imul ITYPEd, RCd, #NODE\n    |  add NODE:ITYPE, TAB:RB->node\n    |  cmp aword NODE:ITYPE->val, LJ_TNIL; je >7\n    |  lea TMPRd, [RCd+TMPRd+1]\n    |  // Copy key and value from hash slot.\n    |  mov RB, NODE:ITYPE->key\n    |  mov RC, NODE:ITYPE->val\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+8], RC\n    |  mov [BASE+RA*8-8], TMPRd\n    |  jmp <2\n    |\n    |7:  // Skip holes in hash part.\n    |  add RCd, 1\n    |  jmp <6\n    break;\n\n  case BC_ISNEXT:\n    |  ins_AD\t// RA = base, RD = target (points to ITERN)\n    |  mov CFUNC:RB, [BASE+RA*8-24]\n    |  checkfunc CFUNC:RB, >5\n    |  checktptp [BASE+RA*8-16], LJ_TTAB, >5\n    |  cmp aword [BASE+RA*8-8], LJ_TNIL; jne >5\n    |  cmp byte CFUNC:RB->ffid, FF_next_N; jne >5\n    |  branchPC RD\n    |  mov64 TMPR, ((uint64_t)LJ_KEYINDEX << 32)\n    |  mov [BASE+RA*8-8], TMPR\t\t// Initialize control var.\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov PC_OP, BC_JMP\n    |  branchPC RD\n    |.if JIT\n    |  cmp byte [PC], BC_ITERN\n    |  jne >6\n    |.endif\n    |  mov byte [PC], BC_ITERC\n    |  jmp <1\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  movzx RCd, word [PC+2]\n    |  mov TRACE:RA, [RA+RC*8]\n    |  mov eax, TRACE:RA->startins\n    |  mov al, BC_ITERC\n    |  mov dword [PC], eax\n    |  jmp <1\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  ins_ABC\t// RA = base, RB = nresults+1, RC = numparams\n    |  lea TMPR, [BASE+RC*8+(16+FRAME_VARG)]\n    |  lea RA, [BASE+RA*8]\n    |  sub TMPR, [BASE-8]\n    |  // Note: TMPR may now be even _above_ BASE if nargs was < numparams.\n    |  test RB, RB\n    |  jz >5\t\t\t\t// Copy all varargs?\n    |  lea RB, [RA+RB*8-8]\n    |  cmp TMPR, BASE\t\t\t// No vararg slots?\n    |  jnb >2\n    |1:  // Copy vararg slots to destination slots.\n    |  mov RC, [TMPR-16]\n    |  add TMPR, 8\n    |  mov [RA], RC\n    |  add RA, 8\n    |  cmp RA, RB\t\t\t// All destination slots filled?\n    |  jnb >3\n    |  cmp TMPR, BASE\t\t\t// No more vararg slots?\n    |  jb <1\n    |2:  // Fill up remainder with nil.\n    |  mov aword [RA], LJ_TNIL\n    |  add RA, 8\n    |  cmp RA, RB\n    |  jb <2\n    |3:\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  mov MULTRES, 1\t\t\t// MULTRES = 0+1\n    |  mov RC, BASE\n    |  sub RC, TMPR\n    |  jbe <3\t\t\t\t// No vararg slots?\n    |  mov RBd, RCd\n    |  shr RBd, 3\n    |  add RBd, 1\n    |  mov MULTRES, RBd\t\t\t// MULTRES = #varargs+1\n    |  mov L:RB, SAVE_L\n    |  add RC, RA\n    |  cmp RC, L:RB->maxstack\n    |  ja >7\t\t\t\t// Need to grow stack?\n    |6:  // Copy all vararg slots.\n    |  mov RC, [TMPR-16]\n    |  add TMPR, 8\n    |  mov [RA], RC\n    |  add RA, 8\n    |  cmp TMPR, BASE\t\t\t// No more vararg slots?\n    |  jb <6\n    |  jmp <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mov L:RB->base, BASE\n    |  mov L:RB->top, RA\n    |  mov SAVE_PC, PC\n    |  sub TMPR, BASE\t\t\t// Need delta, because BASE may change.\n    |  mov TMP1hi, TMPRd\n    |  mov CARG2d, MULTRES\n    |  sub CARG2d, 1\n    |  mov CARG1, L:RB\n    |  call extern lj_state_growstack\t// (lua_State *L, int n)\n    |  mov BASE, L:RB->base\n    |  movsxd TMPR, TMP1hi\n    |  mov RA, L:RB->top\n    |  add TMPR, BASE\n    |  jmp <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  ins_AD\t// RA = results, RD = extra_nresults\n    |  add RDd, MULTRES\t\t\t// MULTRES >=1, so RD >=1.\n    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.\n    break;\n\n  case BC_RET: case BC_RET0: case BC_RET1:\n    |  ins_AD\t// RA = results, RD = nresults+1\n    if (op != BC_RET0) {\n      |  shl RAd, 3\n    }\n    |1:\n    |  mov PC, [BASE-8]\n    |  mov MULTRES, RDd\t\t\t// Save nresults+1.\n    |  test PCd, FRAME_TYPE\t\t// Check frame type marker.\n    |  jnz >7\t\t\t\t// Not returning to a fixarg Lua func?\n    switch (op) {\n    case BC_RET:\n      |->BC_RET_Z:\n      |  mov KBASE, BASE\t\t// Use KBASE for result move.\n      |  sub RDd, 1\n      |  jz >3\n      |2:  // Move results down.\n      |  mov RB, [KBASE+RA]\n      |  mov [KBASE-16], RB\n      |  add KBASE, 8\n      |  sub RDd, 1\n      |  jnz <2\n      |3:\n      |  mov RDd, MULTRES\t\t// Note: MULTRES may be >255.\n      |  movzx RBd, PC_RB\t\t// So cannot compare with RDL!\n      |5:\n      |  cmp RBd, RDd\t\t\t// More results expected?\n      |  ja >6\n      break;\n    case BC_RET1:\n      |  mov RB, [BASE+RA]\n      |  mov [BASE-16], RB\n      /* fallthrough */\n    case BC_RET0:\n      |5:\n      |  cmp PC_RB, RDL\t\t\t// More results expected?\n      |  ja >6\n    default:\n      break;\n    }\n    |  movzx RAd, PC_RA\n    |  neg RA\n    |  lea BASE, [BASE+RA*8-16]\t\t// base = base - (RA+2)*8\n    |  mov LFUNC:KBASE, [BASE-16]\n    |  cleartp LFUNC:KBASE\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    if (op == BC_RET) {\n      |  mov aword [KBASE-16], LJ_TNIL\t// Note: relies on shifted base.\n      |  add KBASE, 8\n    } else {\n      |  mov aword [BASE+RD*8-24], LJ_TNIL\n    }\n    |  add RD, 1\n    |  jmp <5\n    |\n    |7:  // Non-standard return case.\n    |  lea RB, [PC-FRAME_VARG]\n    |  test RBd, FRAME_TYPEP\n    |  jnz ->vm_return\n    |  // Return from vararg function: relocate BASE down and RA up.\n    |  sub BASE, RB\n    if (op != BC_RET0) {\n      |  add RA, RB\n    }\n    |  jmp <1\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA]\n  |.define FOR_STOP, [RA+8]\n  |.define FOR_STEP, [RA+16]\n  |.define FOR_EXT,  [RA+24]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ins_AJ\t// RA = base, RD = target (after end of loop or start of loop)\n    |  lea RA, [BASE+RA*8]\n    if (LJ_DUALNUM) {\n      |  mov RB, FOR_IDX\n      |  checkint RB, >9\n      |  mov TMPR, FOR_STOP\n      if (!vk) {\n\t|  checkint TMPR, ->vmeta_for\n\t|  mov ITYPE, FOR_STEP\n\t|  test ITYPEd, ITYPEd; js >5\n\t|  sar ITYPE, 47;\n\t|  cmp ITYPEd, LJ_TISNUM; jne ->vmeta_for\n      } else {\n#ifdef LUA_USE_ASSERT\n\t|  checkinttp FOR_STOP, ->assert_bad_for_arg_type\n\t|  checkinttp FOR_STEP, ->assert_bad_for_arg_type\n#endif\n\t|  mov ITYPE, FOR_STEP\n\t|  test ITYPEd, ITYPEd; js >5\n\t|  add RBd, ITYPEd; jo >1\n\t|  setint RB\n\t|  mov FOR_IDX, RB\n      }\n      |  cmp RBd, TMPRd\n      |  mov FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jle >7\n\t|1:\n\t|6:\n\t|  branchPC RD\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RDd, PC_RD\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      } else if (op == BC_IFORL) {\n\t|  jg >7\n\t|6:\n\t|  branchPC RD\n\t|1:\n      } else {\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      }\n      |7:\n      |  ins_next\n      |\n      |5:  // Invert check for negative step.\n      if (!vk) {\n\t|  sar ITYPE, 47;\n\t|  cmp ITYPEd, LJ_TISNUM; jne ->vmeta_for\n      } else {\n\t|  add RBd, ITYPEd; jo <1\n\t|  setint RB\n\t|  mov FOR_IDX, RB\n      }\n      |  cmp RBd, TMPRd\n      |  mov FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jge <7\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RDd, PC_RD\n\t|  jge =>BC_JLOOP\n      } else if (op == BC_IFORL) {\n\t|  jl <7\n      } else {\n\t|  jge =>BC_JLOOP\n      }\n      |  jmp <6\n      |9:  // Fallback to FP variant.\n      if (!vk) {\n\t|  jae ->vmeta_for\n      }\n    } else if (!vk) {\n      |  checknumtp FOR_IDX, ->vmeta_for\n    }\n    if (!vk) {\n      |  checknumtp FOR_STOP, ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  checknumtp FOR_STOP, ->assert_bad_for_arg_type\n      |  checknumtp FOR_STEP, ->assert_bad_for_arg_type\n#endif\n    }\n    |  mov RB, FOR_STEP\n    if (!vk) {\n      |  checknum RB, ->vmeta_for\n    }\n    |  movsd xmm0, qword FOR_IDX\n    |  movsd xmm1, qword FOR_STOP\n    if (vk) {\n      |  addsd xmm0, qword FOR_STEP\n      |  movsd qword FOR_IDX, xmm0\n      |  test RB, RB; js >3\n    } else {\n      |  jl >3\n    }\n    |  ucomisd xmm1, xmm0\n    |1:\n    |  movsd qword FOR_EXT, xmm0\n    if (op == BC_FORI) {\n      |.if DUALNUM\n      |  jnb <7\n      |.else\n      |  jnb >2\n      |  branchPC RD\n      |.endif\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  movzx RDd, PC_RD\n      |  jnb =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  jb <7\n      |.else\n      |  jb >2\n      |  branchPC RD\n      |.endif\n    } else {\n      |  jnb =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  jmp <6\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |\n    |3:  // Invert comparison if step is negative.\n    |  ucomisd xmm0, xmm1\n    |  jmp <1\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  ins_AJ\t// RA = base, RD = target\n    |  lea RA, [BASE+RA*8]\n    |  mov RB, [RA]\n    |  cmp RB, LJ_TNIL; je >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  mov [RA-8], RB\n      |  jmp =>BC_JLOOP\n    } else {\n      |  branchPC RD\t\t\t// Otherwise save control var + branch.\n      |  mov [RA-8], RB\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop RBd\n    |.endif\n    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.\n    break;\n\n  case BC_ILOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  ins_AD\t// RA = base (ignored), RD = traceno\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  mov TRACE:RD, [RA+RD*8]\n    |  mov RD, TRACE:RD->mcode\n    |  mov L:RB, SAVE_L\n    |  mov [DISPATCH+DISPATCH_GL(jit_base)], BASE\n    |  mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB\n    |  // Save additional callee-save registers only used in compiled code.\n    |.if X64WIN\n    |  mov CSAVE_4, r12\n    |  mov CSAVE_3, r13\n    |  mov CSAVE_2, r14\n    |  mov CSAVE_1, r15\n    |  mov RA, rsp\n    |  sub rsp, 10*16+4*8\n    |  movdqa [RA-1*16], xmm6\n    |  movdqa [RA-2*16], xmm7\n    |  movdqa [RA-3*16], xmm8\n    |  movdqa [RA-4*16], xmm9\n    |  movdqa [RA-5*16], xmm10\n    |  movdqa [RA-6*16], xmm11\n    |  movdqa [RA-7*16], xmm12\n    |  movdqa [RA-8*16], xmm13\n    |  movdqa [RA-9*16], xmm14\n    |  movdqa [RA-10*16], xmm15\n    |.else\n    |  sub rsp, 16\n    |  mov [rsp+16], r12\n    |  mov [rsp+8], r13\n    |.endif\n    |  jmp RD\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  ins_AJ\t// RA = unused, RD = target\n    |  branchPC RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n   /*\n   ** Reminder: A function may be called with func/args above L->maxstack,\n   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,\n   ** too. This means all FUNC* ops (including fast functions) must check\n   ** for stack overflow _before_ adding more slots!\n   */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall RBd\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  mov KBASE, [PC-4+PC2PROTO(k)]\n    |  mov L:RB, SAVE_L\n    |  lea RA, [BASE+RA*8]\t\t// Top of frame.\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_f\n    |  movzx RAd, byte [PC-4+PC2PROTO(numparams)]\n    |  cmp NARGS:RDd, RAd\t\t// Check for missing parameters.\n    |  jbe >3\n    |2:\n    if (op == BC_JFUNCF) {\n      |  movzx RDd, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov aword [BASE+NARGS:RD*8-8], LJ_TNIL\n    |  add NARGS:RDd, 1\n    |  cmp NARGS:RDd, RAd\n    |  jbe <3\n    |  jmp <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    | int3  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  lea RBd, [NARGS:RD*8+FRAME_VARG+8]\n    |  lea RD, [BASE+NARGS:RD*8+8]\n    |  mov LFUNC:KBASE, [BASE-16]\n    |  mov [RD-8], RB\t\t\t// Store delta + FRAME_VARG.\n    |  mov [RD-16], LFUNC:KBASE\t\t// Store copy of LFUNC.\n    |  mov L:RB, SAVE_L\n    |  lea RA, [RD+RA*8]\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_v\t\t// Need to grow stack.\n    |  mov RA, BASE\n    |  mov BASE, RD\n    |  movzx RBd, byte [PC-4+PC2PROTO(numparams)]\n    |  test RBd, RBd\n    |  jz >2\n    |  add RA, 8\n    |1:  // Copy fixarg slots up to new frame.\n    |  add RA, 8\n    |  cmp RA, BASE\n    |  jnb >3\t\t\t\t// Less args than parameters?\n    |  mov KBASE, [RA-16]\n    |  mov [RD], KBASE\n    |  add RD, 8\n    |  mov aword [RA-16], LJ_TNIL\t// Clear old fixarg slot (help the GC).\n    |  sub RBd, 1\n    |  jnz <1\n    |2:\n    if (op == BC_JFUNCV) {\n      |  movzx RDd, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  mov KBASE, [PC-4+PC2PROTO(k)]\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov aword [RD], LJ_TNIL\n    |  add RD, 8\n    |  sub RBd, 1\n    |  jnz <3\n    |  jmp <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  ins_AD  // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1\n    |  mov CFUNC:RB, [BASE-16]\n    |  cleartp CFUNC:RB\n    |  mov KBASE, CFUNC:RB->f\n    |  mov L:RB, SAVE_L\n    |  lea RD, [BASE+NARGS:RD*8-8]\n    |  mov L:RB->base, BASE\n    |  lea RA, [RD+8*LUA_MINSTACK]\n    |  cmp RA, L:RB->maxstack\n    |  mov L:RB->top, RD\n    if (op == BC_FUNCC) {\n      |  mov CARG1, L:RB\t\t// Caveat: CARG1 may be RA.\n    } else {\n      |  mov CARG2, KBASE\n      |  mov CARG1, L:RB\t\t// Caveat: CARG1 may be RA.\n    }\n    |  ja ->vm_growstack_c\t\t// Need to grow stack.\n    |  set_vmstate C\n    if (op == BC_FUNCC) {\n      |  call KBASE\t\t\t// (lua_State *L)\n    } else {\n      |  // (lua_State *L, lua_CFunction f)\n      |  call aword [DISPATCH+DISPATCH_GL(wrapf)]\n    }\n    |  // nresults returned in eax (RD).\n    |  mov BASE, L:RB->base\n    |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n    |  set_vmstate INTERP\n    |  lea RA, [BASE+RD*8]\n    |  neg RA\n    |  add RA, L:RB->top\t\t// RA = (L->top-(L->base+nresults))*8\n    |  mov PC, [BASE-8]\t\t\t// Fetch PC of caller.\n    |  jmp ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n  dasm_growpc(Dst, BC__MAX);\n  build_subroutines(ctx);\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#if LJ_NO_UNWIND\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x6\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x7\\n\"\t/* offset r12 */\n#endif\n\t\"\\t.align 8\\n\"\n\t\".LEFDE0:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n#if LJ_TARGET_SOLARIS\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@unwind\\n\");\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n#endif\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE2:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 0x7\\n\\t.uleb128 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align 8\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.align 8\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n#if !LJ_NO_UNWIND\n  /* Mental note: never let Apple design an assembler.\n  ** Or a linker. Or a plastic case. But I digress.\n  */\n  case BUILD_machasm: {\n#if LJ_HASFFI\n    int fcsize = 0;\n#endif\n    int i;\n    fprintf(ctx->fp, \"\\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\\n\");\n    fprintf(ctx->fp,\n\t\"EH_frame1:\\n\"\n\t\"\\t.set L$set$x,LECIEX-LSCIEX\\n\"\n\t\"\\t.long L$set$x\\n\"\n\t\"LSCIEX:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zPR\\\\0\\\"\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.byte 128-8\\n\"\n\t\"\\t.byte 0x10\\n\"\n\t\"\\t.byte 6\\n\"\t\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9b\\n\"\t\t\t/* indirect|pcrel|sdata4 */\n\t\"\\t.long _lj_err_unwind_dwarf+4@GOTPCREL\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte 0x7\\n\\t.byte 8\\n\"\n\t\"\\t.byte 0x80+0x10\\n\\t.byte 0x1\\n\"\n\t\"\\t.align 3\\n\"\n\t\"LECIEX:\\n\\n\");\n    for (i = 0; i < ctx->nsym; i++) {\n      const char *name = ctx->sym[i].name;\n      int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;\n      if (size == 0) continue;\n#if LJ_HASFFI\n      if (!strcmp(name, \"_lj_vm_ffi_call\")) { fcsize = size; continue; }\n#endif\n      fprintf(ctx->fp,\n\t  \"%s.eh:\\n\"\n\t  \"LSFDE%d:\\n\"\n\t  \"\\t.set L$set$%d,LEFDE%d-LASFDE%d\\n\"\n\t  \"\\t.long L$set$%d\\n\"\n\t  \"LASFDE%d:\\n\"\n\t  \"\\t.long LASFDE%d-EH_frame1\\n\"\n\t  \"\\t.long %s-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte %d\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.byte 0x8f\\n\\t.byte 0x4\\n\"\t\t/* offset r15 */\n\t  \"\\t.byte 0x8e\\n\\t.byte 0x5\\n\"\t\t/* offset r14 */\n\t  \"\\t.align 3\\n\"\n\t  \"LEFDE%d:\\n\\n\",\n\t  name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);\n    }\n#if LJ_HASFFI\n    if (fcsize) {\n      fprintf(ctx->fp,\n\t  \"EH_frame2:\\n\"\n\t  \"\\t.set L$set$y,LECIEY-LSCIEY\\n\"\n\t  \"\\t.long L$set$y\\n\"\n\t  \"LSCIEY:\\n\"\n\t  \"\\t.long 0\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.ascii \\\"zR\\\\0\\\"\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.byte 128-8\\n\"\n\t  \"\\t.byte 0x10\\n\"\n\t  \"\\t.byte 1\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte 0x7\\n\\t.byte 8\\n\"\n\t  \"\\t.byte 0x80+0x10\\n\\t.byte 0x1\\n\"\n\t  \"\\t.align 3\\n\"\n\t  \"LECIEY:\\n\\n\");\n      fprintf(ctx->fp,\n\t  \"_lj_vm_ffi_call.eh:\\n\"\n\t  \"LSFDEY:\\n\"\n\t  \"\\t.set L$set$yy,LEFDEY-LASFDEY\\n\"\n\t  \"\\t.long L$set$yy\\n\"\n\t  \"LASFDEY:\\n\"\n\t  \"\\t.long LASFDEY-EH_frame2\\n\"\n\t  \"\\t.long _lj_vm_ffi_call-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte 16\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0xd\\n\\t.byte 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.align 3\\n\"\n\t  \"LEFDEY:\\n\\n\", fcsize);\n    }\n#endif\n    fprintf(ctx->fp, \".subsections_via_symbols\\n\");\n    }\n    break;\n#endif\n  default:  /* Difficult for other modes. */\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/vm_x86.dasc",
    "content": "|// Low-level VM code for x86 CPUs.\n|// Bytecode interpreter, fast functions and helper functions.\n|// Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h\n|\n|.if P64\n|.arch x64\n|.else\n|.arch x86\n|.endif\n|.section code_op, code_sub\n|\n|.actionlist build_actionlist\n|.globals GLOB_\n|.globalnames globnames\n|.externnames extnames\n|\n|//-----------------------------------------------------------------------\n|\n|.if P64\n|.define X64, 1\n|.if WIN\n|.define X64WIN, 1\n|.endif\n|.endif\n|\n|// Fixed register assignments for the interpreter.\n|// This is very fragile and has many dependencies. Caveat emptor.\n|.define BASE,\t\tedx\t\t// Not C callee-save, refetched anyway.\n|.if not X64\n|.define KBASE,\t\tedi\t\t// Must be C callee-save.\n|.define KBASEa,\tKBASE\n|.define PC,\t\tesi\t\t// Must be C callee-save.\n|.define PCa,\t\tPC\n|.define DISPATCH,\tebx\t\t// Must be C callee-save.\n|.elif X64WIN\n|.define KBASE,\t\tedi\t\t// Must be C callee-save.\n|.define KBASEa,\trdi\n|.define PC,\t\tesi\t\t// Must be C callee-save.\n|.define PCa,\t\trsi\n|.define DISPATCH,\tebx\t\t// Must be C callee-save.\n|.else\n|.define KBASE,\t\tr15d\t\t// Must be C callee-save.\n|.define KBASEa,\tr15\n|.define PC,\t\tebx\t\t// Must be C callee-save.\n|.define PCa,\t\trbx\n|.define DISPATCH,\tr14d\t\t// Must be C callee-save.\n|.endif\n|\n|.define RA,\t\tecx\n|.define RAH,\t\tch\n|.define RAL,\t\tcl\n|.define RB,\t\tebp\t\t// Must be ebp (C callee-save).\n|.define RC,\t\teax\t\t// Must be eax.\n|.define RCW,\t\tax\n|.define RCH,\t\tah\n|.define RCL,\t\tal\n|.define OP,\t\tRB\n|.define RD,\t\tRC\n|.define RDW,\t\tRCW\n|.define RDL,\t\tRCL\n|.if X64\n|.define RAa, rcx\n|.define RBa, rbp\n|.define RCa, rax\n|.define RDa, rax\n|.else\n|.define RAa, RA\n|.define RBa, RB\n|.define RCa, RC\n|.define RDa, RD\n|.endif\n|\n|.if not X64\n|.define FCARG1,\tecx\t\t// x86 fastcall arguments.\n|.define FCARG2,\tedx\n|.elif X64WIN\n|.define CARG1,\t\trcx\t\t// x64/WIN64 C call arguments.\n|.define CARG2,\t\trdx\n|.define CARG3,\t\tr8\n|.define CARG4,\t\tr9\n|.define CARG1d,\tecx\n|.define CARG2d,\tedx\n|.define CARG3d,\tr8d\n|.define CARG4d,\tr9d\n|.define FCARG1,\tCARG1d\t\t// Upwards compatible to x86 fastcall.\n|.define FCARG2,\tCARG2d\n|.else\n|.define CARG1,\t\trdi\t\t// x64/POSIX C call arguments.\n|.define CARG2,\t\trsi\n|.define CARG3,\t\trdx\n|.define CARG4,\t\trcx\n|.define CARG5,\t\tr8\n|.define CARG6,\t\tr9\n|.define CARG1d,\tedi\n|.define CARG2d,\tesi\n|.define CARG3d,\tedx\n|.define CARG4d,\tecx\n|.define CARG5d,\tr8d\n|.define CARG6d,\tr9d\n|.define FCARG1,\tCARG1d\t\t// Simulate x86 fastcall.\n|.define FCARG2,\tCARG2d\n|.endif\n|\n|// Type definitions. Some of these are only used for documentation.\n|.type L,\t\tlua_State\n|.type GL,\t\tglobal_State\n|.type TVALUE,\t\tTValue\n|.type GCOBJ,\t\tGCobj\n|.type STR,\t\tGCstr\n|.type TAB,\t\tGCtab\n|.type LFUNC,\t\tGCfuncL\n|.type CFUNC,\t\tGCfuncC\n|.type PROTO,\t\tGCproto\n|.type UPVAL,\t\tGCupval\n|.type NODE,\t\tNode\n|.type NARGS,\t\tint\n|.type TRACE,\t\tGCtrace\n|.type SBUF,\t\tSBuf\n|\n|// Stack layout while in interpreter. Must match with lj_frame.h.\n|//-----------------------------------------------------------------------\n|.if not X64\t\t// x86 stack layout.\n|\n|.if WIN\n|\n|.define CFRAME_SPACE,\taword*9\t\t\t// Delta for esp (see <--).\n|.macro saveregs_\n|  push edi; push esi; push ebx\n|  push extern lj_err_unwind_win\n|  fs; push dword [0]\n|  fs; mov [0], esp\n|  sub esp, CFRAME_SPACE\n|.endmacro\n|.macro restoreregs\n|  add esp, CFRAME_SPACE\n|  fs; pop dword [0]\n|  pop edi\t// Short for esp += 4.\n|  pop ebx; pop esi; pop edi; pop ebp\n|.endmacro\n|\n|.else\n|\n|.define CFRAME_SPACE,\taword*7\t\t\t// Delta for esp (see <--).\n|.macro saveregs_\n|  push edi; push esi; push ebx\n|  sub esp, CFRAME_SPACE\n|.endmacro\n|.macro restoreregs\n|  add esp, CFRAME_SPACE\n|  pop ebx; pop esi; pop edi; pop ebp\n|.endmacro\n|\n|.endif\n|\n|.macro saveregs\n|  push ebp; saveregs_\n|.endmacro\n|\n|.if WIN\n|.define SAVE_ERRF,\taword [esp+aword*19]\t// vm_pcall/vm_cpcall only.\n|.define SAVE_NRES,\taword [esp+aword*18]\n|.define SAVE_CFRAME,\taword [esp+aword*17]\n|.define SAVE_L,\taword [esp+aword*16]\n|//----- 16 byte aligned, ^^^ arguments from C caller\n|.define SAVE_RET,\taword [esp+aword*15]\t//<-- esp entering interpreter.\n|.define SAVE_R4,\taword [esp+aword*14]\n|.define SAVE_R3,\taword [esp+aword*13]\n|.define SAVE_R2,\taword [esp+aword*12]\n|//----- 16 byte aligned\n|.define SAVE_R1,\taword [esp+aword*11]\n|.define SEH_FUNC,\taword [esp+aword*10]\n|.define SEH_NEXT,\taword [esp+aword*9]\t//<-- esp after register saves.\n|.define UNUSED2,\taword [esp+aword*8]\n|//----- 16 byte aligned\n|.define UNUSED1,\taword [esp+aword*7]\n|.define SAVE_PC,\taword [esp+aword*6]\n|.define TMP2,\t\taword [esp+aword*5]\n|.define TMP1,\t\taword [esp+aword*4]\n|//----- 16 byte aligned\n|.define ARG4,\t\taword [esp+aword*3]\n|.define ARG3,\t\taword [esp+aword*2]\n|.define ARG2,\t\taword [esp+aword*1]\n|.define ARG1,\t\taword [esp]\t\t//<-- esp while in interpreter.\n|//----- 16 byte aligned, ^^^ arguments for C callee\n|.else\n|.define SAVE_ERRF,\taword [esp+aword*15]\t// vm_pcall/vm_cpcall only.\n|.define SAVE_NRES,\taword [esp+aword*14]\n|.define SAVE_CFRAME,\taword [esp+aword*13]\n|.define SAVE_L,\taword [esp+aword*12]\n|//----- 16 byte aligned, ^^^ arguments from C caller\n|.define SAVE_RET,\taword [esp+aword*11]\t//<-- esp entering interpreter.\n|.define SAVE_R4,\taword [esp+aword*10]\n|.define SAVE_R3,\taword [esp+aword*9]\n|.define SAVE_R2,\taword [esp+aword*8]\n|//----- 16 byte aligned\n|.define SAVE_R1,\taword [esp+aword*7]\t//<-- esp after register saves.\n|.define SAVE_PC,\taword [esp+aword*6]\n|.define TMP2,\t\taword [esp+aword*5]\n|.define TMP1,\t\taword [esp+aword*4]\n|//----- 16 byte aligned\n|.define ARG4,\t\taword [esp+aword*3]\n|.define ARG3,\t\taword [esp+aword*2]\n|.define ARG2,\t\taword [esp+aword*1]\n|.define ARG1,\t\taword [esp]\t\t//<-- esp while in interpreter.\n|//----- 16 byte aligned, ^^^ arguments for C callee\n|.endif\n|\n|// FPARGx overlaps ARGx and ARG(x+1) on x86.\n|.define FPARG3,\tqword [esp+qword*1]\n|.define FPARG1,\tqword [esp]\n|// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [esp+aword*4]\n|.define TMP3,\t\tARG4\n|.define ARG5,\t\tTMP1\n|.define TMPa,\t\tTMP1\n|.define MULTRES,\tTMP2\n|\n|// Arguments for vm_call and vm_pcall.\n|.define INARG_BASE,\tSAVE_CFRAME\t\t// Overwritten by SAVE_CFRAME!\n|\n|// Arguments for vm_cpcall.\n|.define INARG_CP_CALL,\tSAVE_ERRF\n|.define INARG_CP_UD,\tSAVE_NRES\n|.define INARG_CP_FUNC,\tSAVE_CFRAME\n|\n|//-----------------------------------------------------------------------\n|.elif X64WIN\t\t// x64/Windows stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rdi; push rsi; push rbx\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|  pop rbx; pop rsi; pop rdi; pop rbp\n|.endmacro\n|\n|.define SAVE_CFRAME,\taword [rsp+aword*13]\n|.define SAVE_PC,\tdword [rsp+dword*25]\n|.define SAVE_L,\tdword [rsp+dword*24]\n|.define SAVE_ERRF,\tdword [rsp+dword*23]\n|.define SAVE_NRES,\tdword [rsp+dword*22]\n|.define TMP2,\t\tdword [rsp+dword*21]\n|.define TMP1,\t\tdword [rsp+dword*20]\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.define ARG5,\t\taword [rsp+aword*4]\n|.define CSAVE_4,\taword [rsp+aword*3]\n|.define CSAVE_3,\taword [rsp+aword*2]\n|.define CSAVE_2,\taword [rsp+aword*1]\n|.define CSAVE_1,\taword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee\n|\n|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [rsp+aword*10]\n|.define MULTRES,\tTMP2\n|.define TMPa,\t\tARG5\n|.define ARG5d,\t\tdword [rsp+aword*4]\n|.define TMP3,\t\tARG5d\n|\n|//-----------------------------------------------------------------------\n|.else\t\t\t// x64/POSIX stack layout\n|\n|.define CFRAME_SPACE,\taword*5\t\t\t// Delta for rsp (see <--).\n|.macro saveregs_\n|  push rbx; push r15; push r14\n|.if NO_UNWIND\n|  push r13; push r12\n|.endif\n|  sub rsp, CFRAME_SPACE\n|.endmacro\n|.macro saveregs\n|  push rbp; saveregs_\n|.endmacro\n|.macro restoreregs\n|  add rsp, CFRAME_SPACE\n|.if NO_UNWIND\n|  pop r12; pop r13\n|.endif\n|  pop r14; pop r15; pop rbx; pop rbp\n|.endmacro\n|\n|//----- 16 byte aligned,\n|.if NO_UNWIND\n|.define SAVE_RET,\taword [rsp+aword*11]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*10]\n|.define SAVE_R3,\taword [rsp+aword*9]\n|.define SAVE_R2,\taword [rsp+aword*8]\n|.define SAVE_R1,\taword [rsp+aword*7]\n|.define SAVE_RU2,\taword [rsp+aword*6]\n|.define SAVE_RU1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.else\n|.define SAVE_RET,\taword [rsp+aword*9]\t//<-- rsp entering interpreter.\n|.define SAVE_R4,\taword [rsp+aword*8]\n|.define SAVE_R3,\taword [rsp+aword*7]\n|.define SAVE_R2,\taword [rsp+aword*6]\n|.define SAVE_R1,\taword [rsp+aword*5]\t//<-- rsp after register saves.\n|.endif\n|.define SAVE_CFRAME,\taword [rsp+aword*4]\n|.define SAVE_PC,\tdword [rsp+dword*7]\n|.define SAVE_L,\tdword [rsp+dword*6]\n|.define SAVE_ERRF,\tdword [rsp+dword*5]\n|.define SAVE_NRES,\tdword [rsp+dword*4]\n|.define TMPa,\t\taword [rsp+aword*1]\n|.define TMP2,\t\tdword [rsp+dword*1]\n|.define TMP1,\t\tdword [rsp]\t\t//<-- rsp while in interpreter.\n|//----- 16 byte aligned\n|\n|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).\n|.define TMPQ,\t\tqword [rsp]\n|.define TMP3,\t\tdword [rsp+aword*1]\n|.define MULTRES,\tTMP2\n|\n|.endif\n|\n|//-----------------------------------------------------------------------\n|\n|// Instruction headers.\n|.macro ins_A; .endmacro\n|.macro ins_AD; .endmacro\n|.macro ins_AJ; .endmacro\n|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro\n|.macro ins_AB_; movzx RB, RCH; .endmacro\n|.macro ins_A_C; movzx RC, RCL; .endmacro\n|.macro ins_AND; not RDa; .endmacro\n|\n|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).\n|.macro ins_NEXT\n|  mov RC, [PC]\n|  movzx RA, RCH\n|  movzx OP, RCL\n|  add PC, 4\n|  shr RC, 16\n|.if X64\n|  jmp aword [DISPATCH+OP*8]\n|.else\n|  jmp aword [DISPATCH+OP*4]\n|.endif\n|.endmacro\n|\n|// Instruction footer.\n|.if 1\n|  // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.\n|  .define ins_next, ins_NEXT\n|  .define ins_next_, ins_NEXT\n|.else\n|  // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.\n|  // Affects only certain kinds of benchmarks (and only with -j off).\n|  // Around 10%-30% slower on Core2, a lot more slower on P4.\n|  .macro ins_next\n|    jmp ->ins_next\n|  .endmacro\n|  .macro ins_next_\n|  ->ins_next:\n|    ins_NEXT\n|  .endmacro\n|.endif\n|\n|// Call decode and dispatch.\n|.macro ins_callt\n|  // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC\n|  mov PC, LFUNC:RB->pc\n|  mov RA, [PC]\n|  movzx OP, RAL\n|  movzx RA, RAH\n|  add PC, 4\n|.if X64\n|  jmp aword [DISPATCH+OP*8]\n|.else\n|  jmp aword [DISPATCH+OP*4]\n|.endif\n|.endmacro\n|\n|.macro ins_call\n|  // BASE = new base, RB = LFUNC, RD = nargs+1\n|  mov [BASE-4], PC\n|  ins_callt\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n|\n|// Macros to test operand types.\n|.macro checktp, reg, tp;  cmp dword [BASE+reg*8+4], tp; .endmacro\n|.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro\n|.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro\n|.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro\n|.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro\n|\n|// These operands must be used with movzx.\n|.define PC_OP, byte [PC-4]\n|.define PC_RA, byte [PC-3]\n|.define PC_RB, byte [PC-1]\n|.define PC_RC, byte [PC-2]\n|.define PC_RD, word [PC-2]\n|\n|.macro branchPC, reg\n|  lea PC, [PC+reg*4-BCBIAS_J*4]\n|.endmacro\n|\n|// Assumes DISPATCH is relative to GL.\n#define DISPATCH_GL(field)\t(GG_DISP2G + (int)offsetof(global_State, field))\n#define DISPATCH_J(field)\t(GG_DISP2J + (int)offsetof(jit_State, field))\n|\n#define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))\n|\n|// Decrement hashed hotcount and trigger trace recorder if zero.\n|.macro hotloop, reg\n|  mov reg, PC\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP\n|  jb ->vm_hotloop\n|.endmacro\n|\n|.macro hotcall, reg\n|  mov reg, PC\n|  shr reg, 1\n|  and reg, HOTCOUNT_PCMASK\n|  sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL\n|  jb ->vm_hotcall\n|.endmacro\n|\n|// Set current VM state.\n|.macro set_vmstate, st\n|  mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st\n|.endmacro\n|\n|// x87 compares.\n|.macro fcomparepp\t\t\t// Compare and pop st0 >< st1.\n|  fucomip st1\n|  fpop\n|.endmacro\n|\n|.macro fpop1; fstp st1; .endmacro\n|\n|// Synthesize SSE FP constants.\n|.macro sseconst_abs, reg, tmp\t\t// Synthesize abs mask.\n|.if X64\n|  mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp\n|.else\n|  pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1\n|.endif\n|.endmacro\n|\n|.macro sseconst_hi, reg, tmp, val\t// Synthesize hi-32 bit const.\n|.if X64\n|  mov64 tmp, U64x(val,00000000); movd reg, tmp\n|.else\n|  mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51\n|.endif\n|.endmacro\n|\n|.macro sseconst_sign, reg, tmp\t\t// Synthesize sign mask.\n|  sseconst_hi reg, tmp, 80000000\n|.endmacro\n|.macro sseconst_1, reg, tmp\t\t// Synthesize 1.0.\n|  sseconst_hi reg, tmp, 3ff00000\n|.endmacro\n|.macro sseconst_m1, reg, tmp\t\t// Synthesize -1.0.\n|  sseconst_hi reg, tmp, bff00000\n|.endmacro\n|.macro sseconst_2p52, reg, tmp\t\t// Synthesize 2^52.\n|  sseconst_hi reg, tmp, 43300000\n|.endmacro\n|.macro sseconst_tobit, reg, tmp\t// Synthesize 2^52 + 2^51.\n|  sseconst_hi reg, tmp, 43380000\n|.endmacro\n|\n|// Move table write barrier back. Overwrites reg.\n|.macro barrierback, tab, reg\n|  and byte tab->marked, (uint8_t)~LJ_GC_BLACK\t// black2gray(tab)\n|  mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]\n|  mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab\n|  mov tab->gclist, reg\n|.endmacro\n|\n|//-----------------------------------------------------------------------\n\n/* Generate subroutines used by opcodes and other parts of the VM. */\n/* The .code_sub section should be last to help static branch prediction. */\nstatic void build_subroutines(BuildCtx *ctx)\n{\n  |.code_sub\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Return handling ----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_returnp:\n  |  test PC, FRAME_P\n  |  jz ->cont_dispatch\n  |\n  |  // Return from pcall or xpcall fast func.\n  |  and PC, -8\n  |  sub BASE, PC\t\t\t// Restore caller base.\n  |  lea RAa, [RA+PC-8]\t\t\t// Rebase RA and prepend one result.\n  |  mov PC, [BASE-4]\t\t\t// Fetch PC of previous frame.\n  |  // Prepending may overwrite the pcall frame, so do it at the end.\n  |  mov dword [BASE+RA+4], LJ_TTRUE\t// Prepend true to results.\n  |\n  |->vm_returnc:\n  |  add RD, 1\t\t\t\t// RD = nresults+1\n  |  jz ->vm_unwind_yield\n  |  mov MULTRES, RD\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\t\t\t// Handle regular return to Lua.\n  |\n  |->vm_return:\n  |  // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return\n  |  xor PC, FRAME_C\n  |  test PC, FRAME_TYPE\n  |  jnz ->vm_returnp\n  |\n  |  // Return to C.\n  |  set_vmstate C\n  |  and PC, -8\n  |  sub PC, BASE\n  |  neg PC\t\t\t\t// Previous base = BASE - delta.\n  |\n  |  sub RD, 1\n  |  jz >2\n  |1:  // Move results down.\n  |.if X64\n  |  mov RBa, [BASE+RA]\n  |  mov [BASE-8], RBa\n  |.else\n  |  mov RB, [BASE+RA]\n  |  mov [BASE-8], RB\n  |  mov RB, [BASE+RA+4]\n  |  mov [BASE-4], RB\n  |.endif\n  |  add BASE, 8\n  |  sub RD, 1\n  |  jnz <1\n  |2:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, PC\n  |3:\n  |  mov RD, MULTRES\n  |  mov RA, SAVE_NRES\t\t\t// RA = wanted nresults+1\n  |4:\n  |  cmp RA, RD\n  |  jne >6\t\t\t\t// More/less results wanted?\n  |5:\n  |  sub BASE, 8\n  |  mov L:RB->top, BASE\n  |\n  |->vm_leave_cp:\n  |  mov RAa, SAVE_CFRAME\t\t// Restore previous C frame.\n  |  mov L:RB->cframe, RAa\n  |  xor eax, eax\t\t\t// Ok return status for vm_pcall.\n  |\n  |->vm_leave_unw:\n  |  restoreregs\n  |  ret\n  |\n  |6:\n  |  jb >7\t\t\t\t// Less results wanted?\n  |  // More results wanted. Check stack size and fill up results with nil.\n  |  cmp BASE, L:RB->maxstack\n  |  ja >8\n  |  mov dword [BASE-4], LJ_TNIL\n  |  add BASE, 8\n  |  add RD, 1\n  |  jmp <4\n  |\n  |7:  // Less results wanted.\n  |  test RA, RA\n  |  jz <5\t\t\t\t// But check for LUA_MULTRET+1.\n  |  sub RA, RD\t\t\t\t// Negative result!\n  |  lea BASE, [BASE+RA*8]\t\t// Correct top.\n  |  jmp <5\n  |\n  |8:  // Corner case: need to grow stack for filling up results.\n  |  // This can happen if:\n  |  // - A C function grows the stack (a lot).\n  |  // - The GC shrinks the stack in between.\n  |  // - A return back from a lua_call() with (high) nresults adjustment.\n  |  mov L:RB->top, BASE\t\t// Save current top held in BASE (yes).\n  |  mov MULTRES, RD\t\t\t// Need to fill only remainder with nil.\n  |  mov FCARG2, RA\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->top\t\t// Need the (realloced) L->top in BASE.\n  |  jmp <3\n  |\n  |->vm_unwind_yield:\n  |  mov al, LUA_YIELD\n  |  jmp ->vm_unwind_c_eh\n  |\n  |->vm_unwind_c@8:\t\t\t// Unwind C stack, return from vm_pcall.\n  |  // (void *cframe, int errcode)\n  |.if X64\n  |  mov eax, CARG2d\t\t\t// Error return status for vm_pcall.\n  |  mov rsp, CARG1\n  |.else\n  |  mov eax, FCARG2\t\t\t// Error return status for vm_pcall.\n  |  mov esp, FCARG1\n  |.if WIN\n  |  lea FCARG1, SEH_NEXT\n  |  fs; mov [0], FCARG1\n  |.endif\n  |.endif\n  |->vm_unwind_c_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov GL:RB, L:RB->glref\n  |  mov dword GL:RB->vmstate, ~LJ_VMST_C\n  |  jmp ->vm_leave_unw\n  |\n  |->vm_unwind_rethrow:\n  |.if X64 and not X64WIN\n  |  mov FCARG1, SAVE_L\n  |  mov FCARG2, eax\n  |  restoreregs\n  |  jmp extern lj_err_throw@8\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |->vm_unwind_ff@4:\t\t\t// Unwind C stack, return from ff pcall.\n  |  // (void *cframe)\n  |.if X64\n  |  and CARG1, CFRAME_RAWMASK\n  |  mov rsp, CARG1\n  |.else\n  |  and FCARG1, CFRAME_RAWMASK\n  |  mov esp, FCARG1\n  |.if WIN\n  |  lea FCARG1, SEH_NEXT\n  |  fs; mov [0], FCARG1\n  |.endif\n  |.endif\n  |->vm_unwind_ff_eh:\t\t\t// Landing pad for external unwinder.\n  |  mov L:RB, SAVE_L\n  |  mov RAa, -8\t\t\t// Results start at BASE+RA = BASE-8.\n  |  mov RD, 1+1\t\t\t// Really 1+2 results, incr. later.\n  |  mov BASE, L:RB->base\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov PC, [BASE-4]\t\t\t// Fetch PC of previous frame.\n  |  mov dword [BASE-4], LJ_TFALSE\t// Prepend false to error message.\n  |  set_vmstate INTERP\n  |  jmp ->vm_returnc\t\t\t// Increments RD/MULTRES and returns.\n  |\n  |.if WIN and not X64\n  |->vm_rtlunwind@16:\t\t\t// Thin layer around RtlUnwind.\n  |  // (void *cframe, void *excptrec, void *unwinder, int errcode)\n  |  mov [esp], FCARG1\t\t\t// Return value for RtlUnwind.\n  |  push FCARG2\t\t\t// Exception record for RtlUnwind.\n  |  push 0\t\t\t\t// Ignored by RtlUnwind.\n  |  push dword [FCARG1+CFRAME_OFS_SEH]\n  |  call extern RtlUnwind@16\t\t// Violates ABI (clobbers too much).\n  |  mov FCARG1, eax\n  |  mov FCARG2, [esp+4]\t\t// errcode (for vm_unwind_c).\n  |  ret\t\t\t\t// Jump to unwinder.\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Grow stack for calls -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_growstack_c:\t\t\t// Grow stack for C function.\n  |  mov FCARG2, LUA_MINSTACK\n  |  jmp >2\n  |\n  |->vm_growstack_v:\t\t\t// Grow stack for vararg Lua function.\n  |  sub RD, 8\n  |  jmp >1\n  |\n  |->vm_growstack_f:\t\t\t// Grow stack for fixarg Lua function.\n  |  // BASE = new base, RD = nargs+1, RB = L, PC = first PC\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |1:\n  |  movzx RA, byte [PC-4+PC2PROTO(framesize)]\n  |  add PC, 4\t\t\t\t// Must point after first instruction.\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov SAVE_PC, PC\n  |  mov FCARG2, RA\n  |2:\n  |  // RB = L, L->base = new base, L->top = top\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  mov LFUNC:RB, [BASE-8]\n  |  sub RD, BASE\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  // BASE = new base, RB = LFUNC, RD = nargs+1\n  |  ins_callt\t\t\t\t// Just retry the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Entry points into the assembler VM ---------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_resume:\t\t\t\t// Setup C frame and resume thread.\n  |  // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)\n  |  saveregs\n  |.if X64\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |  mov RA, CARG2d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov RA, INARG_BASE\t\t\t// Caveat: overlaps SAVE_CFRAME!\n  |.endif\n  |  mov PC, FRAME_CP\n  |  xor RD, RD\n  |  lea KBASEa, [esp+CFRAME_RESUME]\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  add DISPATCH, GG_G2DISP\n  |  mov SAVE_PC, RD\t\t\t// Any value outside of bytecode is ok.\n  |  mov SAVE_CFRAME, RDa\n  |.if X64\n  |  mov SAVE_NRES, RD\n  |  mov SAVE_ERRF, RD\n  |.endif\n  |  mov L:RB->cframe, KBASEa\n  |  cmp byte L:RB->status, RDL\n  |  je >2\t\t\t\t// Initial resume (like a call).\n  |\n  |  // Resume after yield (like a return).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov byte L:RB->status, RDL\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr RD, 3\n  |  add RD, 1\t\t\t\t// RD = nresults+1\n  |  sub RA, BASE\t\t\t// RA = resultofs\n  |  mov PC, [BASE-4]\n  |  mov MULTRES, RD\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |->vm_pcall:\t\t\t\t// Setup protected C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)\n  |  saveregs\n  |  mov PC, FRAME_CP\n  |.if X64\n  |  mov SAVE_ERRF, CARG4d\n  |.endif\n  |  jmp >1\n  |\n  |->vm_call:\t\t\t\t// Setup C frame and enter VM.\n  |  // (lua_State *L, TValue *base, int nres1)\n  |  saveregs\n  |  mov PC, FRAME_C\n  |\n  |1:  // Entry point for vm_pcall above (PC = ftype).\n  |.if X64\n  |  mov SAVE_NRES, CARG3d\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |  mov RA, CARG2d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov RA, INARG_BASE\t\t\t// Caveat: overlaps SAVE_CFRAME!\n  |.endif\n  |\n  |  mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov KBASEa, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASEa\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |  add DISPATCH, GG_G2DISP\n  |.if X64\n  |  mov L:RB->cframe, rsp\n  |.else\n  |  mov L:RB->cframe, esp\n  |.endif\n  |\n  |2:  // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype).\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |  mov BASE, L:RB->base\t\t// BASE = old base (used in vmeta_call).\n  |  add PC, RA\n  |  sub PC, BASE\t\t\t// PC = frame delta + frame type\n  |\n  |  mov RD, L:RB->top\n  |  sub RD, RA\n  |  shr NARGS:RD, 3\n  |  add NARGS:RD, 1\t\t\t// RD = nargs+1\n  |\n  |->vm_call_dispatch:\n  |  mov LFUNC:RB, [RA-8]\n  |  cmp dword [RA-4], LJ_TFUNC\n  |  jne ->vmeta_call\t\t\t// Ensure KBASE defined and != BASE.\n  |\n  |->vm_call_dispatch_f:\n  |  mov BASE, RA\n  |  ins_call\n  |  // BASE = new base, RB = func, RD = nargs+1, PC = caller PC\n  |\n  |->vm_cpcall:\t\t\t\t// Setup protected C frame, call C.\n  |  // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)\n  |  saveregs\n  |.if X64\n  |  mov L:RB, CARG1d\t\t\t// Caveat: CARG1d may be RA.\n  |  mov SAVE_L, CARG1d\n  |.else\n  |  mov L:RB, SAVE_L\n  |  // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap!\n  |  mov RC, INARG_CP_UD\t\t// Get args before they are overwritten.\n  |  mov RA, INARG_CP_FUNC\n  |  mov BASE, INARG_CP_CALL\n  |.endif\n  |  mov SAVE_PC, L:RB\t\t\t// Any value outside of bytecode is ok.\n  |\n  |  mov KBASE, L:RB->stack\t\t// Compute -savestack(L, L->top).\n  |  sub KBASE, L:RB->top\n  |   mov DISPATCH, L:RB->glref\t\t// Setup pointer to dispatch table.\n  |  mov SAVE_ERRF, 0\t\t\t// No error function.\n  |  mov SAVE_NRES, KBASE\t\t// Neg. delta means cframe w/o frame.\n  |   add DISPATCH, GG_G2DISP\n  |  // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).\n  |\n  |.if X64\n  |  mov KBASEa, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASEa\n  |  mov L:RB->cframe, rsp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call CARG4\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.else\n  |  mov ARG3, RC\t\t\t// Have to copy args downwards.\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |\n  |  mov KBASE, L:RB->cframe\t\t// Add our C frame to cframe chain.\n  |  mov SAVE_CFRAME, KBASE\n  |  mov L:RB->cframe, esp\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |\n  |  call BASE\t\t\t// (lua_State *L, lua_CFunction func, void *ud)\n  |.endif\n  |  // TValue * (new base) or NULL returned in eax (RC).\n  |  test RC, RC\n  |  jz ->vm_leave_cp\t\t\t// No base? Just remove C frame.\n  |  mov RA, RC\n  |  mov PC, FRAME_CP\n  |  jmp <2\t\t\t\t// Else continue with the call.\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Metamethod handling ------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |//-- Continuation dispatch ----------------------------------------------\n  |\n  |->cont_dispatch:\n  |  // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)\n  |  add RA, BASE\n  |  and PC, -8\n  |  mov RB, BASE\n  |  sub BASE, PC\t\t\t// Restore caller BASE.\n  |  mov dword [RA+RD*8-4], LJ_TNIL\t// Ensure one valid arg.\n  |  mov RC, RA\t\t\t\t// ... in [RC]\n  |  mov PC, [RB-12]\t\t\t// Restore PC from [cont|PC].\n  |.if X64\n  |  movsxd RAa, dword [RB-16]\t\t// May be negative on WIN64 with debug.\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |  lea KBASEa, qword [=>0]\n  |  add RAa, KBASEa\n  |.else\n  |  mov RA, dword [RB-16]\n  |.if FFI\n  |  cmp RA, 1\n  |  jbe >1\n  |.endif\n  |.endif\n  |  mov LFUNC:KBASE, [BASE-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  // BASE = base, RC = result, RB = meta base\n  |  jmp RAa\t\t\t\t// Jump to continuation.\n  |\n  |.if FFI\n  |1:\n  |  je ->cont_ffi_callback\t\t// cont = 1: return from FFI callback.\n  |  // cont = 0: Tail call from C function.\n  |  sub RB, BASE\n  |  shr RB, 3\n  |  lea RD, [RB-1]\n  |  jmp ->vm_call_tail\n  |.endif\n  |\n  |->cont_cat:\t\t\t\t// BASE = base, RC = result, RB = mbase\n  |  movzx RA, PC_RB\n  |  sub RB, 16\n  |  lea RA, [BASE+RA*8]\n  |  sub RA, RB\n  |  je ->cont_ra\n  |  neg RA\n  |  shr RA, 3\n  |.if X64WIN\n  |  mov CARG3d, RA\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\n  |  mov RCa, [RC]\n  |  mov [RB], RCa\n  |  mov CARG2d, RB\n  |.elif X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\n  |  mov CARG3d, RA\n  |  mov RAa, [RC]\n  |  mov [RB], RAa\n  |  mov CARG2d, RB\n  |.else\n  |  mov ARG3, RA\n  |  mov RA, [RC+4]\n  |  mov RC, [RC]\n  |  mov [RB+4], RA\n  |  mov [RB], RC\n  |  mov ARG2, RB\n  |.endif\n  |  jmp ->BC_CAT_Z\n  |\n  |//-- Table indexing metamethods -----------------------------------------\n  |\n  |->vmeta_tgets:\n  |  mov TMP1, RC\t\t\t// RC = GCstr *\n  |  mov TMP2, LJ_TSTR\n  |  lea RCa, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n  |  cmp PC_OP, BC_GGET\n  |  jne >1\n  |  lea RA, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RA], TAB:RB\t\t\t// RB = GCtab *\n  |  mov dword [RA+4], LJ_TTAB\n  |  mov RB, RA\n  |  jmp >2\n  |\n  |->vmeta_tgetb:\n  |  movzx RC, PC_RC\n  |.if DUALNUM\n  |  mov TMP2, LJ_TISNUM\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RC\n  |  movsd TMPQ, xmm0\n  |.endif\n  |  lea RCa, TMPQ\t\t\t// Store temp. TValue in TMPQ.\n  |  jmp >1\n  |\n  |->vmeta_tgetv:\n  |  movzx RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |.if X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RB\n  |  mov CARG3, RCa\t\t\t// May be 64 bit ptr to stack.\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG2, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tget\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |->cont_ra:\t\t\t\t// BASE = base, RC = result\n  |  movzx RA, PC_RA\n  |.if X64\n  |  mov RBa, [RC]\n  |  mov [BASE+RA*8], RBa\n  |.else\n  |  mov RB, [RC+4]\n  |  mov RC, [RC]\n  |  mov [BASE+RA*8+4], RB\n  |  mov [BASE+RA*8], RC\n  |.endif\n  |  ins_next\n  |\n  |3:  // Call __index metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k\n  |  mov RA, L:RB->top\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-8]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RD, 2+1\t\t\t// 2 args for func(t, k).\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tgetr:\n  |  mov FCARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov FCARG2, RC\t\t\t// Caveat: FCARG2 == BASE\n  |  call extern lj_tab_getinth@8\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RC).\n  |  movzx RA, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RC, RC\n  |  jnz ->BC_TGETR_Z\n  |  mov dword [BASE+RA*8+4], LJ_TNIL\n  |  jmp ->BC_TGETR2_Z\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->vmeta_tsets:\n  |  mov TMP1, RC\t\t\t// RC = GCstr *\n  |  mov TMP2, LJ_TSTR\n  |  lea RCa, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n  |  cmp PC_OP, BC_GSET\n  |  jne >1\n  |  lea RA, [DISPATCH+DISPATCH_GL(tmptv)]  // Store fn->l.env in g->tmptv.\n  |  mov [RA], TAB:RB\t\t\t// RB = GCtab *\n  |  mov dword [RA+4], LJ_TTAB\n  |  mov RB, RA\n  |  jmp >2\n  |\n  |->vmeta_tsetb:\n  |  movzx RC, PC_RC\n  |.if DUALNUM\n  |  mov TMP2, LJ_TISNUM\n  |  mov TMP1, RC\n  |.else\n  |  cvtsi2sd xmm0, RC\n  |  movsd TMPQ, xmm0\n  |.endif\n  |  lea RCa, TMPQ\t\t\t// Store temp. TValue in TMPQ.\n  |  jmp >1\n  |\n  |->vmeta_tsetv:\n  |  movzx RC, PC_RC\t\t\t// Reload TValue *k from RC.\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  movzx RB, PC_RB\t\t\t// Reload TValue *t from RB.\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |.if X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RB\n  |  mov CARG3, RCa\t\t\t// May be 64 bit ptr to stack.\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG2, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_tset\t\t// (lua_State *L, TValue *o, TValue *k)\n  |  // TValue * (finished) or NULL (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz >3\n  |  // NOBARRIER: lj_meta_tset ensures the table is not black.\n  |  movzx RA, PC_RA\n  |.if X64\n  |  mov RBa, [BASE+RA*8]\n  |  mov [RC], RBa\n  |.else\n  |  mov RB, [BASE+RA*8+4]\n  |  mov RA, [BASE+RA*8]\n  |  mov [RC+4], RB\n  |  mov [RC], RA\n  |.endif\n  |->cont_nop:\t\t\t\t// BASE = base, (RC = result)\n  |  ins_next\n  |\n  |3:  // Call __newindex metamethod.\n  |  // BASE = base, L->top = new base, stack = cont/func/t/k/(v)\n  |  mov RA, L:RB->top\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  movzx RC, PC_RA\n  |  // Copy value to third argument.\n  |.if X64\n  |  mov RBa, [BASE+RC*8]\n  |  mov [RA+16], RBa\n  |.else\n  |  mov RB, [BASE+RC*8+4]\n  |  mov RC, [BASE+RC*8]\n  |  mov [RA+20], RB\n  |  mov [RA+16], RC\n  |.endif\n  |  lea PC, [RA+FRAME_CONT]\n  |  sub PC, BASE\n  |  mov LFUNC:RB, [RA-8]\t\t// Guaranteed to be a function here.\n  |  mov NARGS:RD, 3+1\t\t\t// 3 args for func(t, k, v).\n  |  jmp ->vm_call_dispatch_f\n  |\n  |->vmeta_tsetr:\n  |.if X64WIN\n  |  mov L:CARG1d, SAVE_L\n  |  mov CARG3d, RC\n  |  mov L:CARG1d->base, BASE\n  |  xchg CARG2d, TAB:RB\t\t// Caveat: CARG2d == BASE.\n  |.elif X64\n  |  mov L:CARG1d, SAVE_L\n  |  mov CARG2d, TAB:RB\n  |  mov L:CARG1d->base, BASE\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG3d, RC\t\t\t// Caveat: CARG3d == BASE.\n  |.else\n  |  mov L:RA, SAVE_L\n  |  mov ARG2, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov ARG3, RC\n  |  mov ARG1, L:RA\n  |  mov L:RA->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_tab_setinth  // (lua_State *L, GCtab *t, int32_t key)\n  |  // TValue * returned in eax (RC).\n  |  movzx RA, PC_RA\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  jmp ->BC_TSETR_Z\n  |\n  |//-- Comparison metamethods ---------------------------------------------\n  |\n  |->vmeta_comp:\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d == BASE.\n  |.if X64WIN\n  |  lea CARG3d, [BASE+RD*8]\n  |  lea CARG2d, [BASE+RA*8]\n  |.else\n  |  lea CARG2d, [BASE+RA*8]\n  |  lea CARG3d, [BASE+RD*8]\n  |.endif\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d/CARG4d == RA.\n  |  movzx CARG4d, PC_OP\n  |.else\n  |  movzx RB, PC_OP\n  |  lea RD, [BASE+RD*8]\n  |  lea RA, [BASE+RA*8]\n  |  mov ARG4, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_comp\t// (lua_State *L, TValue *o1, *o2, int op)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |3:\n  |  mov BASE, L:RB->base\n  |  cmp RC, 1\n  |  ja ->vmeta_binop\n  |4:\n  |  lea PC, [PC+4]\n  |  jb >6\n  |5:\n  |  movzx RD, PC_RD\n  |  branchPC RD\n  |6:\n  |  ins_next\n  |\n  |->cont_condt:\t\t\t// BASE = base, RC = result\n  |  add PC, 4\n  |  cmp dword [RC+4], LJ_TISTRUECOND\t// Branch if result is true.\n  |  jb <5\n  |  jmp <6\n  |\n  |->cont_condf:\t\t\t// BASE = base, RC = result\n  |  cmp dword [RC+4], LJ_TISTRUECOND\t// Branch if result is false.\n  |  jmp <4\n  |\n  |->vmeta_equal:\n  |  sub PC, 4\n  |.if X64WIN\n  |  mov CARG3d, RD\n  |  mov CARG4d, RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG2d, RA\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d == RA.\n  |.elif X64\n  |  mov CARG2d, RA\n  |  mov CARG4d, RB\t\t\t// Caveat: CARG4d == RA.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG3d, RD\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG4, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG2, RA\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal\t// (lua_State *L, GCobj *o1, *o2, int ne)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |\n  |->vmeta_equal_cd:\n  |.if FFI\n  |  sub PC, 4\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG1, L:RB\n  |  mov FCARG2, dword [PC-4]\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_equal_cd@8\t// (lua_State *L, BCIns ins)\n  |  // 0/1 or TValue * (metamethod) returned in eax (RC).\n  |  jmp <3\n  |.endif\n  |\n  |->vmeta_istype:\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RA\n  |  movzx CARG3d, PC_RD\n  |  mov L:CARG1d, L:RB\n  |.else\n  |  movzx RD, PC_RD\n  |  mov ARG2, RA\n  |  mov L:RB, SAVE_L\n  |  mov ARG3, RD\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_istype  // (lua_State *L, BCReg ra, BCReg tp)\n  |  mov BASE, L:RB->base\n  |  jmp <6\n  |\n  |//-- Arithmetic metamethods ---------------------------------------------\n  |\n  |->vmeta_arith_vno:\n  |.if DUALNUM\n  |  movzx RB, PC_RB\n  |.endif\n  |->vmeta_arith_vn:\n  |  lea RC, [KBASE+RC*8]\n  |  jmp >1\n  |\n  |->vmeta_arith_nvo:\n  |.if DUALNUM\n  |  movzx RC, PC_RC\n  |.endif\n  |->vmeta_arith_nv:\n  |  lea RC, [KBASE+RC*8]\n  |  lea RB, [BASE+RB*8]\n  |  xchg RB, RC\n  |  jmp >2\n  |\n  |->vmeta_unm:\n  |  lea RC, [BASE+RD*8]\n  |  mov RB, RC\n  |  jmp >2\n  |\n  |->vmeta_arith_vvo:\n  |.if DUALNUM\n  |  movzx RB, PC_RB\n  |.endif\n  |->vmeta_arith_vv:\n  |  lea RC, [BASE+RC*8]\n  |1:\n  |  lea RB, [BASE+RB*8]\n  |2:\n  |  lea RA, [BASE+RA*8]\n  |.if X64WIN\n  |  mov CARG3d, RB\n  |  mov CARG4d, RC\n  |  movzx RC, PC_OP\n  |  mov ARG5d, RC\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG2d, RA\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d == RA.\n  |.elif X64\n  |  movzx CARG5d, PC_OP\n  |  mov CARG2d, RA\n  |  mov CARG4d, RC\t\t\t// Caveat: CARG4d == RA.\n  |  mov L:CARG1d, SAVE_L\n  |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG3d, RB\n  |  mov L:RB, L:CARG1d\n  |.else\n  |  mov ARG3, RB\n  |  mov L:RB, SAVE_L\n  |  mov ARG4, RC\n  |  movzx RC, PC_OP\n  |  mov ARG2, RA\n  |  mov ARG5, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_arith\t// (lua_State *L, TValue *ra,*rb,*rc, BCReg op)\n  |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n  |  test RC, RC\n  |  jz ->cont_nop\n  |\n  |  // Call metamethod for binary op.\n  |->vmeta_binop:\n  |  // BASE = base, RC = new base, stack = cont/func/o1/o2\n  |  mov RA, RC\n  |  sub RC, BASE\n  |  mov [RA-12], PC\t\t\t// [cont|PC]\n  |  lea PC, [RC+FRAME_CONT]\n  |  mov NARGS:RD, 2+1\t\t\t// 2 args for func(o1, o2).\n  |  jmp ->vm_call_dispatch\n  |\n  |->vmeta_len:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  lea FCARG2, [BASE+RD*8]\t\t// Caveat: FCARG2 == BASE\n  |  mov L:FCARG1, L:RB\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_len@8\t\t// (lua_State *L, TValue *o)\n  |  // NULL (retry) or TValue * (metamethod) returned in eax (RC).\n  |  mov BASE, L:RB->base\n#if LJ_52\n  |  test RC, RC\n  |  jne ->vmeta_binop\t\t\t// Binop call for compatibility.\n  |  movzx RD, PC_RD\n  |  mov TAB:FCARG1, [BASE+RD*8]\n  |  jmp ->BC_LEN_Z\n#else\n  |  jmp ->vmeta_binop\t\t\t// Binop call for compatibility.\n#endif\n  |\n  |//-- Call metamethod ----------------------------------------------------\n  |\n  |->vmeta_call_ra:\n  |  lea RA, [BASE+RA*8+8]\n  |->vmeta_call:\t\t\t// Resolve and call __call metamethod.\n  |  // BASE = old base, RA = new base, RC = nargs+1, PC = return\n  |  mov TMP2, RA\t\t\t// Save RA, RC for us.\n  |  mov TMP1, NARGS:RD\n  |  sub RA, 8\n  |.if X64\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n  |  mov CARG2d, RA\n  |  lea CARG3d, [RA+NARGS:RD*8]\n  |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n  |.else\n  |  lea RC, [RA+NARGS:RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov ARG2, RA\n  |  mov ARG3, RC\n  |  mov ARG1, L:RB\n  |  mov L:RB->base, BASE\t\t// This is the callers base!\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_call\t// (lua_State *L, TValue *func, TValue *top)\n  |  mov BASE, L:RB->base\n  |  mov RA, TMP2\n  |  mov NARGS:RD, TMP1\n  |  mov LFUNC:RB, [RA-8]\n  |  add NARGS:RD, 1\n  |  // This is fragile. L->base must not move, KBASE must always be defined.\n  |.if x64\n  |  cmp KBASEa, rdx\t\t\t// Continue with CALLT if flag set.\n  |.else\n  |  cmp KBASE, BASE\t\t\t// Continue with CALLT if flag set.\n  |.endif\n  |  je ->BC_CALLT_Z\n  |  mov BASE, RA\n  |  ins_call\t\t\t\t// Otherwise call resolved metamethod.\n  |\n  |//-- Argument coercion for 'for' statement ------------------------------\n  |\n  |->vmeta_for:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, RA\t\t\t// Caveat: FCARG2 == BASE\n  |  mov L:FCARG1, L:RB\t\t\t// Caveat: FCARG1 == RA\n  |  mov SAVE_PC, PC\n  |  call extern lj_meta_for@8\t// (lua_State *L, TValue *base)\n  |  mov BASE, L:RB->base\n  |  mov RC, [PC-4]\n  |  movzx RA, RCH\n  |  movzx OP, RCL\n  |  shr RC, 16\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |.else\n  |  jmp aword [DISPATCH+OP*4+GG_DISP2STATIC]\t// Retry FORI or JFORI.\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Fast functions -----------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |.macro .ffunc, name\n  |->ff_ .. name:\n  |.endmacro\n  |\n  |.macro .ffunc_1, name\n  |->ff_ .. name:\n  |  cmp NARGS:RD, 1+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_2, name\n  |->ff_ .. name:\n  |  cmp NARGS:RD, 2+1;  jb ->fff_fallback\n  |.endmacro\n  |\n  |.macro .ffunc_nsse, name, op\n  |  .ffunc_1 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  op xmm0, qword [BASE]\n  |.endmacro\n  |\n  |.macro .ffunc_nsse, name\n  |  .ffunc_nsse name, movsd\n  |.endmacro\n  |\n  |.macro .ffunc_nnsse, name\n  |  .ffunc_2 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM;  jae ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |  movsd xmm1, qword [BASE+8]\n  |.endmacro\n  |\n  |.macro .ffunc_nnr, name\n  |  .ffunc_2 name\n  |  cmp dword [BASE+4], LJ_TISNUM;  jae ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM;  jae ->fff_fallback\n  |  fld qword [BASE+8]\n  |  fld qword [BASE]\n  |.endmacro\n  |\n  |// Inlined GC threshold check. Caveat: uses label 1.\n  |.macro ffgccheck\n  |  mov RB, [DISPATCH+DISPATCH_GL(gc.total)]\n  |  cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]\n  |  jb >1\n  |  call ->fff_gcstep\n  |1:\n  |.endmacro\n  |\n  |//-- Base library: checks -----------------------------------------------\n  |\n  |.ffunc_1 assert\n  |  mov RB, [BASE+4]\n  |  cmp RB, LJ_TISTRUECOND;  jae ->fff_fallback\n  |  mov PC, [BASE-4]\n  |  mov MULTRES, RD\n  |  mov [BASE-4], RB\n  |  mov RB, [BASE]\n  |  mov [BASE-8], RB\n  |  sub RD, 2\n  |  jz >2\n  |  mov RA, BASE\n  |1:\n  |  add RA, 8\n  |.if X64\n  |  mov RBa, [RA]\n  |  mov [RA-8], RBa\n  |.else\n  |  mov RB, [RA+4]\n  |  mov [RA-4], RB\n  |  mov RB, [RA]\n  |  mov [RA-8], RB\n  |.endif\n  |  sub RD, 1\n  |  jnz <1\n  |2:\n  |  mov RD, MULTRES\n  |  jmp ->fff_res_\n  |\n  |.ffunc_1 type\n  |  mov RB, [BASE+4]\n  |.if X64\n  |  mov RA, RB\n  |  sar RA, 15\n  |  cmp RA, -2\n  |  je >3\n  |.endif\n  |  mov RC, ~LJ_TNUMX\n  |  not RB\n  |  cmp RC, RB\n  |  cmova RC, RB\n  |2:\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RC\n  |  jmp ->fff_res1\n  |.if X64\n  |3:\n  |  mov RC, ~LJ_TLIGHTUD\n  |  jmp <2\n  |.endif\n  |\n  |//-- Base library: getters and setters ---------------------------------\n  |\n  |.ffunc_1 getmetatable\n  |  mov RB, [BASE+4]\n  |  mov PC, [BASE-4]\n  |  cmp RB, LJ_TTAB;  jne >6\n  |1:  // Field metatable must be at same offset for GCtab and GCudata!\n  |  mov TAB:RB, [BASE]\n  |  mov TAB:RB, TAB:RB->metatable\n  |2:\n  |  test TAB:RB, TAB:RB\n  |  mov dword [BASE-4], LJ_TNIL\n  |  jz ->fff_res1\n  |  mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)]\n  |  mov dword [BASE-4], LJ_TTAB\t// Store metatable as default result.\n  |  mov [BASE-8], TAB:RB\n  |  mov RA, TAB:RB->hmask\n  |  and RA, STR:RC->sid\n  |  imul RA, #NODE\n  |  add NODE:RA, TAB:RB->node\n  |3:  // Rearranged logic, because we expect _not_ to find the key.\n  |  cmp dword NODE:RA->key.it, LJ_TSTR\n  |  jne >4\n  |  cmp dword NODE:RA->key.gcr, STR:RC\n  |  je >5\n  |4:\n  |  mov NODE:RA, NODE:RA->next\n  |  test NODE:RA, NODE:RA\n  |  jnz <3\n  |  jmp ->fff_res1\t\t\t// Not found, keep default result.\n  |5:\n  |  mov RB, [RA+4]\n  |  cmp RB, LJ_TNIL;  je ->fff_res1\t// Ditto for nil value.\n  |  mov RC, [RA]\n  |  mov [BASE-4], RB\t\t\t// Return value of mt.__metatable.\n  |  mov [BASE-8], RC\n  |  jmp ->fff_res1\n  |\n  |6:\n  |  cmp RB, LJ_TUDATA;  je <1\n  |.if X64\n  |  cmp RB, LJ_TNUMX;  ja >8\n  |  cmp RB, LJ_TISNUM;  jbe >7\n  |  mov RB, LJ_TLIGHTUD\n  |  jmp >8\n  |7:\n  |.else\n  |  cmp RB, LJ_TISNUM;  ja >8\n  |.endif\n  |  mov RB, LJ_TNUMX\n  |8:\n  |  not RB\n  |  mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]\n  |  jmp <2\n  |\n  |.ffunc_2 setmetatable\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  // Fast path: no mt for table yet and not clearing the mt.\n  |  mov TAB:RB, [BASE]\n  |  cmp dword TAB:RB->metatable, 0;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TTAB;  jne ->fff_fallback\n  |  mov TAB:RC, [BASE+8]\n  |  mov TAB:RB->metatable, TAB:RC\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TTAB\t\t// Return original table.\n  |  mov [BASE-8], TAB:RB\n  |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n  |  jz >1\n  |  // Possible write barrier. Table is black, but skip iswhite(mt) check.\n  |  barrierback TAB:RB, RC\n  |1:\n  |  jmp ->fff_res1\n  |\n  |.ffunc_2 rawget\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |.if X64WIN\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  lea CARG3d, [BASE+8]\n  |  mov CARG2d, [BASE]\t\t\t// Caveat: CARG2d == BASE.\n  |  mov CARG1d, SAVE_L\n  |.elif X64\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov CARG2d, [BASE]\n  |  lea CARG3d, [BASE+8]\t\t// Caveat: CARG3d == BASE.\n  |  mov CARG1d, SAVE_L\n  |.else\n  |  mov TAB:RD, [BASE]\n  |  mov L:RB, SAVE_L\n  |  mov ARG2, TAB:RD\n  |  mov ARG1, L:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  add BASE, 8\n  |  mov ARG3, BASE\n  |.endif\n  |  call extern lj_tab_get\t// (lua_State *L, GCtab *t, cTValue *key)\n  |  // cTValue * returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  // Copy table slot.\n  |.if X64\n  |  mov RBa, [RD]\n  |  mov PC, [BASE-4]\n  |  mov [BASE-8], RBa\n  |.else\n  |  mov RB, [RD]\n  |  mov RD, [RD+4]\n  |  mov PC, [BASE-4]\n  |  mov [BASE-8], RB\n  |  mov [BASE-4], RD\n  |.endif\n  |  jmp ->fff_res1\n  |\n  |//-- Base library: conversions ------------------------------------------\n  |\n  |.ffunc tonumber\n  |  // Only handles the number case inline (without a base argument).\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\t// Exactly one argument.\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >1\n  |  mov RB, dword [BASE]; jmp ->fff_resi\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]; jmp ->fff_resxmm0\n  |\n  |.ffunc_1 tostring\n  |  // Only handles the string or number case inline.\n  |  mov PC, [BASE-4]\n  |  cmp dword [BASE+4], LJ_TSTR;  jne >3\n  |  // A __tostring method in the string base metatable is ignored.\n  |  mov STR:RD, [BASE]\n  |2:\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RD\n  |  jmp ->fff_res1\n  |3:  // Handle numbers inline, unless a number base metatable is present.\n  |  cmp dword [BASE+4], LJ_TISNUM;  ja ->fff_fallback\n  |  cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0\n  |  jne ->fff_fallback\n  |  ffgccheck\t\t\t\t// Caveat: uses label 1.\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\t\t// Add frame since C call can throw.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |.if X64 and not X64WIN\n  |  mov FCARG2, BASE\t\t\t// Otherwise: FCARG2 == BASE\n  |.endif\n  |  mov L:FCARG1, L:RB\n  |.if DUALNUM\n  |  call extern lj_strfmt_number@8\t// (lua_State *L, cTValue *o)\n  |.else\n  |  call extern lj_strfmt_num@8\t// (lua_State *L, lua_Number *np)\n  |.endif\n  |  // GCstr returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  jmp <2\n  |\n  |//-- Base library: iterators -------------------------------------------\n  |\n  |.ffunc_1 next\n  |  je >2\t\t\t\t// Missing 2nd arg?\n  |1:\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  mov PC, [BASE-4]\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |.if X64WIN\n  |  mov CARG1d, [BASE]\n  |  lea CARG3d, [BASE-8]\n  |  lea CARG2d, [BASE+8]\t\t// Caveat: CARG2d == BASE.\n  |.elif X64\n  |  mov CARG1d, [BASE]\n  |  lea CARG2d, [BASE+8]\n  |  lea CARG3d, [BASE-8]\t\t// Caveat: CARG3d == BASE.\n  |.else\n  |  mov TAB:RD, [BASE]\n  |  mov ARG1, TAB:RD\n  |  add BASE, 8\n  |  mov ARG2, BASE\n  |  sub BASE, 8+8\n  |  mov ARG3, BASE\n  |.endif\n  |  call extern lj_tab_next\t\t// (GCtab *t, cTValue *key, TValue *o)\n  |  // 1=found, 0=end, -1=error returned in eax (RD).\n  |  mov BASE, RB\t\t\t// Restore BASE.\n  |  test RD, RD;  jg ->fff_res2\t// Found key/value.\n  |  js ->fff_fallback_2\t\t// Invalid key.\n  |  // End of traversal: return nil.\n  |  mov dword [BASE-4], LJ_TNIL\n  |  jmp ->fff_res1\n  |2:  // Set missing 2nd arg to nil.\n  |  mov dword [BASE+12], LJ_TNIL\n  |  jmp <1\n  |\n  |.ffunc_1 pairs\n  |  mov TAB:RB, [BASE]\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n#if LJ_52\n  |  cmp dword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov CFUNC:RD, CFUNC:RB->upvalue[0]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TFUNC\n  |  mov [BASE-8], CFUNC:RD\n  |  mov dword [BASE+12], LJ_TNIL\n  |  mov RD, 1+3\n  |  jmp ->fff_res\n  |\n  |.ffunc_2 ipairs_aux\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  mov PC, [BASE-4]\n  |.if DUALNUM\n  |  mov RD, dword [BASE+8]\n  |  add RD, 1\n  |  mov dword [BASE-4], LJ_TISNUM\n  |  mov dword [BASE-8], RD\n  |.else\n  |  movsd xmm0, qword [BASE+8]\n  |  sseconst_1 xmm1, RBa\n  |  addsd xmm0, xmm1\n  |  cvttsd2si RD, xmm0\n  |  movsd qword [BASE-8], xmm0\n  |.endif\n  |  mov TAB:RB, [BASE]\n  |  cmp RD, TAB:RB->asize;  jae >2\t// Not in array part?\n  |  shl RD, 3\n  |  add RD, TAB:RB->array\n  |1:\n  |  cmp dword [RD+4], LJ_TNIL;  je ->fff_res0\n  |  // Copy array slot.\n  |.if X64\n  |  mov RBa, [RD]\n  |  mov [BASE], RBa\n  |.else\n  |  mov RB, [RD]\n  |  mov RD, [RD+4]\n  |  mov [BASE], RB\n  |  mov [BASE+4], RD\n  |.endif\n  |->fff_res2:\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |2:  // Check for empty hash part first. Otherwise call C function.\n  |  cmp dword TAB:RB->hmask, 0; je ->fff_res0\n  |  mov FCARG1, TAB:RB\n  |  mov RB, BASE\t\t\t// Save BASE.\n  |  mov FCARG2, RD\t\t\t// Caveat: FCARG2 == BASE\n  |  call extern lj_tab_getinth@8\t// (GCtab *t, int32_t key)\n  |  // cTValue * or NULL returned in eax (RD).\n  |  mov BASE, RB\n  |  test RD, RD\n  |  jnz <1\n  |->fff_res0:\n  |  mov RD, 1+0\n  |  jmp ->fff_res\n  |\n  |.ffunc_1 ipairs\n  |  mov TAB:RB, [BASE]\n  |  cmp dword [BASE+4], LJ_TTAB;  jne ->fff_fallback\n#if LJ_52\n  |  cmp dword TAB:RB->metatable, 0; jne ->fff_fallback\n#endif\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov CFUNC:RD, CFUNC:RB->upvalue[0]\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TFUNC\n  |  mov [BASE-8], CFUNC:RD\n  |.if DUALNUM\n  |  mov dword [BASE+12], LJ_TISNUM\n  |  mov dword [BASE+8], 0\n  |.else\n  |  xorps xmm0, xmm0\n  |  movsd qword [BASE+8], xmm0\n  |.endif\n  |  mov RD, 1+3\n  |  jmp ->fff_res\n  |\n  |//-- Base library: catch errors ----------------------------------------\n  |\n  |.ffunc_1 pcall\n  |  lea RA, [BASE+8]\n  |  sub NARGS:RD, 1\n  |  mov PC, 8+FRAME_PCALL\n  |1:\n  |  movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  shr RB, HOOK_ACTIVE_SHIFT\n  |  and RB, 1\n  |  add PC, RB\t\t\t\t// Remember active hook before pcall.\n  |  jmp ->vm_call_dispatch\n  |\n  |.ffunc_2 xpcall\n  |  cmp dword [BASE+12], LJ_TFUNC;  jne ->fff_fallback\n  |  mov RB, [BASE+4]\t\t\t// Swap function and traceback.\n  |  mov [BASE+12], RB\n  |  mov dword [BASE+4], LJ_TFUNC\n  |  mov LFUNC:RB, [BASE]\n  |  mov PC, [BASE+8]\n  |  mov [BASE+8], LFUNC:RB\n  |  mov [BASE], PC\n  |  lea RA, [BASE+16]\n  |  sub NARGS:RD, 2\n  |  mov PC, 16+FRAME_PCALL\n  |  jmp <1\n  |\n  |//-- Coroutine library --------------------------------------------------\n  |\n  |.macro coroutine_resume_wrap, resume\n  |.if resume\n  |.ffunc_1 coroutine_resume\n  |  mov L:RB, [BASE]\n  |.else\n  |.ffunc coroutine_wrap_aux\n  |  mov CFUNC:RB, [BASE-8]\n  |  mov L:RB, CFUNC:RB->upvalue[0].gcr\n  |.endif\n  |  mov PC, [BASE-4]\n  |  mov SAVE_PC, PC\n  |.if X64\n  |  mov TMP1, L:RB\n  |.else\n  |  mov ARG1, L:RB\n  |.endif\n  |.if resume\n  |  cmp dword [BASE+4], LJ_TTHREAD;  jne ->fff_fallback\n  |.endif\n  |  cmp aword L:RB->cframe, 0; jne ->fff_fallback\n  |  cmp byte L:RB->status, LUA_YIELD;  ja ->fff_fallback\n  |  mov RA, L:RB->top\n  |  je >1\t\t\t\t// Status != LUA_YIELD (i.e. 0)?\n  |  cmp RA, L:RB->base\t\t\t// Check for presence of initial func.\n  |  je ->fff_fallback\n  |1:\n  |.if resume\n  |  lea PC, [RA+NARGS:RD*8-16]\t\t// Check stack space (-1-thread).\n  |.else\n  |  lea PC, [RA+NARGS:RD*8-8]\t\t// Check stack space (-1).\n  |.endif\n  |  cmp PC, L:RB->maxstack; ja ->fff_fallback\n  |  mov L:RB->top, PC\n  |\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if resume\n  |  add BASE, 8\t\t\t// Keep resumed thread in stack for GC.\n  |.endif\n  |  mov L:RB->top, BASE\n  |.if resume\n  |  lea RB, [BASE+NARGS:RD*8-24]\t// RB = end of source for stack move.\n  |.else\n  |  lea RB, [BASE+NARGS:RD*8-16]\t// RB = end of source for stack move.\n  |.endif\n  |  sub RBa, PCa\t\t\t// Relative to PC.\n  |\n  |  cmp PC, RA\n  |  je >3\n  |2:  // Move args to coroutine.\n  |.if X64\n  |  mov RCa, [PC+RB]\n  |  mov [PC-8], RCa\n  |.else\n  |  mov RC, [PC+RB+4]\n  |  mov [PC-4], RC\n  |  mov RC, [PC+RB]\n  |  mov [PC-8], RC\n  |.endif\n  |  sub PC, 8\n  |  cmp PC, RA\n  |  jne <2\n  |3:\n  |.if X64\n  |  mov CARG2d, RA\n  |  mov CARG1d, TMP1\n  |.else\n  |  mov ARG2, RA\n  |  xor RA, RA\n  |  mov ARG4, RA\n  |  mov ARG3, RA\n  |.endif\n  |  call ->vm_resume\t\t\t// (lua_State *L, TValue *base, 0, 0)\n  |\n  |  mov L:RB, SAVE_L\n  |.if X64\n  |  mov L:PC, TMP1\n  |.else\n  |  mov L:PC, ARG1\t\t\t// The callee doesn't modify SAVE_L.\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n  |  set_vmstate INTERP\n  |\n  |  cmp eax, LUA_YIELD\n  |  ja >8\n  |4:\n  |  mov RA, L:PC->base\n  |  mov KBASE, L:PC->top\n  |  mov L:PC->top, RA\t\t\t// Clear coroutine stack.\n  |  mov PC, KBASE\n  |  sub PC, RA\n  |  je >6\t\t\t\t// No results?\n  |  lea RD, [BASE+PC]\n  |  shr PC, 3\n  |  cmp RD, L:RB->maxstack\n  |  ja >9\t\t\t\t// Need to grow stack?\n  |\n  |  mov RB, BASE\n  |  sub RBa, RAa\n  |5:  // Move results from coroutine.\n  |.if X64\n  |  mov RDa, [RA]\n  |  mov [RA+RB], RDa\n  |.else\n  |  mov RD, [RA]\n  |  mov [RA+RB], RD\n  |  mov RD, [RA+4]\n  |  mov [RA+RB+4], RD\n  |.endif\n  |  add RA, 8\n  |  cmp RA, KBASE\n  |  jne <5\n  |6:\n  |.if resume\n  |  lea RD, [PC+2]\t\t\t// nresults+1 = 1 + true + results.\n  |  mov dword [BASE-4], LJ_TTRUE\t// Prepend true to results.\n  |.else\n  |  lea RD, [PC+1]\t\t\t// nresults+1 = 1 + results.\n  |.endif\n  |7:\n  |  mov PC, SAVE_PC\n  |  mov MULTRES, RD\n  |.if resume\n  |  mov RAa, -8\n  |.else\n  |  xor RA, RA\n  |.endif\n  |  test PC, FRAME_TYPE\n  |  jz ->BC_RET_Z\n  |  jmp ->vm_return\n  |\n  |8:  // Coroutine returned with error (at co->top-1).\n  |.if resume\n  |  mov dword [BASE-4], LJ_TFALSE\t// Prepend false to results.\n  |  mov RA, L:PC->top\n  |  sub RA, 8\n  |  mov L:PC->top, RA\t\t\t// Clear error from coroutine stack.\n  |  // Copy error message.\n  |.if X64\n  |  mov RDa, [RA]\n  |  mov [BASE], RDa\n  |.else\n  |  mov RD, [RA]\n  |  mov [BASE], RD\n  |  mov RD, [RA+4]\n  |  mov [BASE+4], RD\n  |.endif\n  |  mov RD, 1+2\t\t\t// nresults+1 = 1 + false + error.\n  |  jmp <7\n  |.else\n  |  mov FCARG2, L:PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_ffh_coroutine_wrap_err@8  // (lua_State *L, lua_State *co)\n  |  // Error function does not return.\n  |.endif\n  |\n  |9:  // Handle stack expansion on return from yield.\n  |.if X64\n  |  mov L:RA, TMP1\n  |.else\n  |  mov L:RA, ARG1\t\t\t// The callee doesn't modify SAVE_L.\n  |.endif\n  |  mov L:RA->top, KBASE\t\t// Undo coroutine stack clearing.\n  |  mov FCARG2, PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |.if X64\n  |  mov L:PC, TMP1\n  |.else\n  |  mov L:PC, ARG1\n  |.endif\n  |  mov BASE, L:RB->base\n  |  jmp <4\t\t\t\t// Retry the stack move.\n  |.endmacro\n  |\n  |  coroutine_resume_wrap 1\t\t// coroutine.resume\n  |  coroutine_resume_wrap 0\t\t// coroutine.wrap\n  |\n  |.ffunc coroutine_yield\n  |  mov L:RB, SAVE_L\n  |  test aword L:RB->cframe, CFRAME_RESUME\n  |  jz ->fff_fallback\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB->top, RD\n  |  xor RD, RD\n  |  mov aword L:RB->cframe, RDa\n  |  mov al, LUA_YIELD\n  |  mov byte L:RB->status, al\n  |  jmp ->vm_leave_unw\n  |\n  |//-- Math library -------------------------------------------------------\n  |\n  |.if not DUALNUM\n  |->fff_resi:  // Dummy.\n  |.endif\n  |\n  |->fff_resn:\n  |  mov PC, [BASE-4]\n  |  fstp qword [BASE-8]\n  |  jmp ->fff_res1\n  |\n  |  .ffunc_1 math_abs\n  |.if DUALNUM\n  |  cmp dword [BASE+4], LJ_TISNUM; jne >2\n  |  mov RB, dword [BASE]\n  |  cmp RB, 0; jns ->fff_resi\n  |  neg RB; js >1\n  |->fff_resbit:\n  |->fff_resi:\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TISNUM\n  |  mov dword [BASE-8], RB\n  |  jmp ->fff_res1\n  |1:\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], 0x41e00000  // 2^31.\n  |  mov dword [BASE-8], 0\n  |  jmp ->fff_res1\n  |2:\n  |  ja ->fff_fallback\n  |.else\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  sseconst_abs xmm1, RDa\n  |  andps xmm0, xmm1\n  |->fff_resxmm0:\n  |  mov PC, [BASE-4]\n  |  movsd qword [BASE-8], xmm0\n  |  // fallthrough\n  |\n  |->fff_res1:\n  |  mov RD, 1+1\n  |->fff_res:\n  |  mov MULTRES, RD\n  |->fff_res_:\n  |  test PC, FRAME_TYPE\n  |  jnz >7\n  |5:\n  |  cmp PC_RB, RDL\t\t\t// More results expected?\n  |  ja >6\n  |  // Adjust BASE. KBASE is assumed to be set for the calling frame.\n  |  movzx RA, PC_RA\n  |  not RAa\t\t\t\t// Note: ~RA = -(RA+1)\n  |  lea BASE, [BASE+RA*8]\t\t// base = base - (RA+1)*8\n  |  ins_next\n  |\n  |6:  // Fill up results with nil.\n  |  mov dword [BASE+RD*8-12], LJ_TNIL\n  |  add RD, 1\n  |  jmp <5\n  |\n  |7:  // Non-standard return case.\n  |  mov RAa, -8\t\t\t// Results start at BASE+RA = BASE-8.\n  |  jmp ->vm_return\n  |\n  |.if X64\n  |.define fff_resfp, fff_resxmm0\n  |.else\n  |.define fff_resfp, fff_resn\n  |.endif\n  |\n  |.macro math_round, func\n  |  .ffunc math_ .. func\n  |.if DUALNUM\n  |  cmp dword [BASE+4], LJ_TISNUM; jne >1\n  |  mov RB, dword [BASE]; jmp ->fff_resi\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |  call ->vm_ .. func .. _sse\n  |.if DUALNUM\n  |  cvttsd2si RB, xmm0\n  |  cmp RB, 0x80000000\n  |  jne ->fff_resi\n  |  cvtsi2sd xmm1, RB\n  |  ucomisd xmm0, xmm1\n  |  jp ->fff_resxmm0\n  |  je ->fff_resi\n  |.endif\n  |  jmp ->fff_resxmm0\n  |.endmacro\n  |\n  |  math_round floor\n  |  math_round ceil\n  |\n  |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0\n  |\n  |.ffunc math_log\n  |  cmp NARGS:RD, 1+1; jne ->fff_fallback\t// Exactly one argument.\n  |  cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback\n  |  movsd xmm0, qword [BASE]\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |.endif\n  |  mov RB, BASE\n  |  call extern log\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |\n  |.macro math_extern, func\n  |  .ffunc_nsse math_ .. func\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |.endif\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |.endmacro\n  |\n  |.macro math_extern2, func\n  |  .ffunc_nnsse math_ .. func\n  |.if not X64\n  |  movsd FPARG1, xmm0\n  |  movsd FPARG3, xmm1\n  |.endif\n  |  mov RB, BASE\n  |  call extern func\n  |  mov BASE, RB\n  |  jmp ->fff_resfp\n  |.endmacro\n  |\n  |  math_extern log10\n  |  math_extern exp\n  |  math_extern sin\n  |  math_extern cos\n  |  math_extern tan\n  |  math_extern asin\n  |  math_extern acos\n  |  math_extern atan\n  |  math_extern sinh\n  |  math_extern cosh\n  |  math_extern tanh\n  |  math_extern2 pow\n  |  math_extern2 atan2\n  |  math_extern2 fmod\n  |\n  |.ffunc_nnr math_ldexp;\tfscale; fpop1;\tjmp ->fff_resn\n  |\n  |.ffunc_1 math_frexp\n  |  mov RB, [BASE+4]\n  |  cmp RB, LJ_TISNUM;  jae ->fff_fallback\n  |  mov PC, [BASE-4]\n  |  mov RC, [BASE]\n  |  mov [BASE-4], RB; mov [BASE-8], RC\n  |  shl RB, 1; cmp RB, 0xffe00000; jae >3\n  |  or RC, RB; jz >3\n  |  mov RC, 1022\n  |  cmp RB, 0x00200000; jb >4\n  |1:\n  |  shr RB, 21; sub RB, RC\t\t// Extract and unbias exponent.\n  |  cvtsi2sd xmm0, RB\n  |  mov RB, [BASE-4]\n  |  and RB, 0x800fffff\t\t\t// Mask off exponent.\n  |  or RB, 0x3fe00000\t\t\t// Put mantissa in range [0.5,1) or 0.\n  |  mov [BASE-4], RB\n  |2:\n  |  movsd qword [BASE], xmm0\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |3:  // Return +-0, +-Inf, NaN unmodified and an exponent of 0.\n  |  xorps xmm0, xmm0; jmp <2\n  |4:  // Handle denormals by multiplying with 2^54 and adjusting the bias.\n  |  movsd xmm0, qword [BASE]\n  |  sseconst_hi xmm1, RBa, 43500000  // 2^54.\n  |  mulsd xmm0, xmm1\n  |  movsd qword [BASE-8], xmm0\n  |  mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1\n  |\n  |.ffunc_nsse math_modf\n  |  mov RB, [BASE+4]\n  |  mov PC, [BASE-4]\n  |  shl RB, 1; cmp RB, 0xffe00000; je >4\t// +-Inf?\n  |  movaps xmm4, xmm0\n  |  call ->vm_trunc_sse\n  |  subsd xmm4, xmm0\n  |1:\n  |  movsd qword [BASE-8], xmm0\n  |  movsd qword [BASE], xmm4\n  |  mov RC, [BASE-4]; mov RB, [BASE+4]\n  |  xor RC, RB; js >3\t\t\t\t// Need to adjust sign?\n  |2:\n  |  mov RD, 1+2\n  |  jmp ->fff_res\n  |3:\n  |  xor RB, 0x80000000; mov [BASE+4], RB\t// Flip sign of fraction.\n  |  jmp <2\n  |4:\n  |  xorps xmm4, xmm4; jmp <1\t\t\t// Return +-Inf and +-0.\n  |\n  |.macro math_minmax, name, cmovop, sseop\n  |  .ffunc_1 name\n  |  mov RA, 2\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >4\n  |  mov RB, dword [BASE]\n  |1:  // Handle integers.\n  |  cmp RA, RD; jae ->fff_resi\n  |  cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3\n  |  cmp RB, dword [BASE+RA*8-8]\n  |  cmovop RB, dword [BASE+RA*8-8]\n  |  add RA, 1\n  |  jmp <1\n  |3:\n  |  ja ->fff_fallback\n  |  // Convert intermediate result to number and continue below.\n  |  cvtsi2sd xmm0, RB\n  |  jmp >6\n  |4:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |\n  |  movsd xmm0, qword [BASE]\n  |5:  // Handle numbers or integers.\n  |  cmp RA, RD; jae ->fff_resxmm0\n  |  cmp dword [BASE+RA*8-4], LJ_TISNUM\n  |.if DUALNUM\n  |  jb >6\n  |  ja ->fff_fallback\n  |  cvtsi2sd xmm1, dword [BASE+RA*8-8]\n  |  jmp >7\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |6:\n  |  movsd xmm1, qword [BASE+RA*8-8]\n  |7:\n  |  sseop xmm0, xmm1\n  |  add RA, 1\n  |  jmp <5\n  |.endmacro\n  |\n  |  math_minmax math_min, cmovg, minsd\n  |  math_minmax math_max, cmovl, maxsd\n  |\n  |//-- String library -----------------------------------------------------\n  |\n  |.ffunc string_byte\t\t\t// Only handle the 1-arg case here.\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  mov STR:RB, [BASE]\n  |  mov PC, [BASE-4]\n  |  cmp dword STR:RB->len, 1\n  |  jb ->fff_res0\t\t\t// Return no results for empty string.\n  |  movzx RB, byte STR:RB[1]\n  |.if DUALNUM\n  |  jmp ->fff_resi\n  |.else\n  |  cvtsi2sd xmm0, RB; jmp ->fff_resxmm0\n  |.endif\n  |\n  |.ffunc string_char\t\t\t// Only handle the 1-arg case here.\n  |  ffgccheck\n  |  cmp NARGS:RD, 1+1;  jne ->fff_fallback\t// *Exactly* 1 arg.\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |  mov RB, dword [BASE]\n  |  cmp RB, 255;  ja ->fff_fallback\n  |  mov TMP2, RB\n  |.else\n  |  jae ->fff_fallback\n  |  cvttsd2si RB, qword [BASE]\n  |  cmp RB, 255;  ja ->fff_fallback\n  |  mov TMP2, RB\n  |.endif\n  |.if X64\n  |  mov TMP3, 1\n  |.else\n  |  mov ARG3, 1\n  |.endif\n  |  lea RDa, TMP2\t\t\t// Points to stack. Little-endian.\n  |->fff_newstr:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |.if X64\n  |  mov CARG3d, TMP3\t\t\t// Zero-extended to size_t.\n  |  mov CARG2, RDa\t\t\t// May be 64 bit ptr to stack.\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG2, RD\n  |  mov ARG1, L:RB\n  |.endif\n  |  mov SAVE_PC, PC\n  |  call extern lj_str_new\t\t// (lua_State *L, char *str, size_t l)\n  |->fff_resstr:\n  |  // GCstr * returned in eax (RD).\n  |  mov BASE, L:RB->base\n  |  mov PC, [BASE-4]\n  |  mov dword [BASE-4], LJ_TSTR\n  |  mov [BASE-8], STR:RD\n  |  jmp ->fff_res1\n  |\n  |.ffunc string_sub\n  |  ffgccheck\n  |  mov TMP2, -1\n  |  cmp NARGS:RD, 1+2;  jb ->fff_fallback\n  |  jna >1\n  |  cmp dword [BASE+20], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |  mov RB, dword [BASE+16]\n  |  mov TMP2, RB\n  |.else\n  |  jae ->fff_fallback\n  |  cvttsd2si RB, qword [BASE+16]\n  |  mov TMP2, RB\n  |.endif\n  |1:\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  cmp dword [BASE+12], LJ_TISNUM\n  |.if DUALNUM\n  |  jne ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  mov STR:RB, [BASE]\n  |  mov TMP3, STR:RB\n  |  mov RB, STR:RB->len\n  |.if DUALNUM\n  |  mov RA, dword [BASE+8]\n  |.else\n  |  cvttsd2si RA, qword [BASE+8]\n  |.endif\n  |  mov RC, TMP2\n  |  cmp RB, RC\t\t\t\t// len < end? (unsigned compare)\n  |  jb >5\n  |2:\n  |  test RA, RA\t\t\t// start <= 0?\n  |  jle >7\n  |3:\n  |  mov STR:RB, TMP3\n  |  sub RC, RA\t\t\t\t// start > end?\n  |  jl ->fff_emptystr\n  |  lea RB, [STR:RB+RA+#STR-1]\n  |  add RC, 1\n  |4:\n  |.if X64\n  |  mov TMP3, RC\n  |.else\n  |  mov ARG3, RC\n  |.endif\n  |  mov RD, RB\n  |  jmp ->fff_newstr\n  |\n  |5:  // Negative end or overflow.\n  |  jl >6\n  |  lea RC, [RC+RB+1]\t\t\t// end = end+(len+1)\n  |  jmp <2\n  |6:  // Overflow.\n  |  mov RC, RB\t\t\t\t// end = len\n  |  jmp <2\n  |\n  |7:  // Negative start or underflow.\n  |  je >8\n  |  add RA, RB\t\t\t\t// start = start+(len+1)\n  |  add RA, 1\n  |  jg <3\t\t\t\t// start > 0?\n  |8:  // Underflow.\n  |  mov RA, 1\t\t\t\t// start = 1\n  |  jmp <3\n  |\n  |->fff_emptystr:  // Range underflow.\n  |  xor RC, RC\t\t\t\t// Zero length. Any ptr in RB is ok.\n  |  jmp <4\n  |\n  |.macro ffstring_op, name\n  |  .ffunc_1 string_ .. name\n  |  ffgccheck\n  |  cmp dword [BASE+4], LJ_TSTR;  jne ->fff_fallback\n  |  mov L:RB, SAVE_L\n  |   lea SBUF:FCARG1, [DISPATCH+DISPATCH_GL(tmpbuf)]\n  |  mov L:RB->base, BASE\n  |  mov STR:FCARG2, [BASE]\t\t// Caveat: FCARG2 == BASE\n  |   mov RCa, SBUF:FCARG1->b\n  |   mov SBUF:FCARG1->L, L:RB\n  |   mov SBUF:FCARG1->w, RCa\n  |  mov SAVE_PC, PC\n  |  call extern lj_buf_putstr_ .. name .. @8\n  |  mov FCARG1, eax\n  |  call extern lj_buf_tostr@4\n  |  jmp ->fff_resstr\n  |.endmacro\n  |\n  |ffstring_op reverse\n  |ffstring_op lower\n  |ffstring_op upper\n  |\n  |//-- Bit library --------------------------------------------------------\n  |\n  |.macro .ffunc_bit, name, kind, fdef\n  |  fdef name\n  |.if kind == 2\n  |  sseconst_tobit xmm1, RBa\n  |.endif\n  |  cmp dword [BASE+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >1\n  |  mov RB, dword [BASE]\n  |.if kind > 0\n  |  jmp >2\n  |.else\n  |  jmp ->fff_resbit\n  |.endif\n  |1:\n  |  ja ->fff_fallback\n  |.else\n  |  jae ->fff_fallback\n  |.endif\n  |  movsd xmm0, qword [BASE]\n  |.if kind < 2\n  |  sseconst_tobit xmm1, RBa\n  |.endif\n  |  addsd xmm0, xmm1\n  |  movd RB, xmm0\n  |2:\n  |.endmacro\n  |\n  |.macro .ffunc_bit, name, kind\n  |  .ffunc_bit name, kind, .ffunc_1\n  |.endmacro\n  |\n  |.ffunc_bit bit_tobit, 0\n  |  jmp ->fff_resbit\n  |\n  |.macro .ffunc_bit_op, name, ins\n  |  .ffunc_bit name, 2\n  |  mov TMP2, NARGS:RD\t\t\t// Save for fallback.\n  |  lea RD, [BASE+NARGS:RD*8-16]\n  |1:\n  |  cmp RD, BASE\n  |  jbe ->fff_resbit\n  |  cmp dword [RD+4], LJ_TISNUM\n  |.if DUALNUM\n  |  jne >2\n  |  ins RB, dword [RD]\n  |  sub RD, 8\n  |  jmp <1\n  |2:\n  |  ja ->fff_fallback_bit_op\n  |.else\n  |  jae ->fff_fallback_bit_op\n  |.endif\n  |  movsd xmm0, qword [RD]\n  |  addsd xmm0, xmm1\n  |  movd RA, xmm0\n  |  ins RB, RA\n  |  sub RD, 8\n  |  jmp <1\n  |.endmacro\n  |\n  |.ffunc_bit_op bit_band, and\n  |.ffunc_bit_op bit_bor, or\n  |.ffunc_bit_op bit_bxor, xor\n  |\n  |.ffunc_bit bit_bswap, 1\n  |  bswap RB\n  |  jmp ->fff_resbit\n  |\n  |.ffunc_bit bit_bnot, 1\n  |  not RB\n  |.if DUALNUM\n  |  jmp ->fff_resbit\n  |.else\n  |->fff_resbit:\n  |  cvtsi2sd xmm0, RB\n  |  jmp ->fff_resxmm0\n  |.endif\n  |\n  |->fff_fallback_bit_op:\n  |  mov NARGS:RD, TMP2\t\t\t// Restore for fallback\n  |  jmp ->fff_fallback\n  |\n  |.macro .ffunc_bit_sh, name, ins\n  |.if DUALNUM\n  |  .ffunc_bit name, 1, .ffunc_2\n  |  // Note: no inline conversion from number for 2nd argument!\n  |  cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback\n  |  mov RA, dword [BASE+8]\n  |.else\n  |  .ffunc_nnsse name\n  |  sseconst_tobit xmm2, RBa\n  |  addsd xmm0, xmm2\n  |  addsd xmm1, xmm2\n  |  movd RB, xmm0\n  |  movd RA, xmm1\n  |.endif\n  |  ins RB, cl\t\t\t\t// Assumes RA is ecx.\n  |  jmp ->fff_resbit\n  |.endmacro\n  |\n  |.ffunc_bit_sh bit_lshift, shl\n  |.ffunc_bit_sh bit_rshift, shr\n  |.ffunc_bit_sh bit_arshift, sar\n  |.ffunc_bit_sh bit_rol, rol\n  |.ffunc_bit_sh bit_ror, ror\n  |\n  |//-----------------------------------------------------------------------\n  |\n  |->fff_fallback_2:\n  |  mov NARGS:RD, 1+2\t\t\t// Other args are ignored, anyway.\n  |  jmp ->fff_fallback\n  |->fff_fallback_1:\n  |  mov NARGS:RD, 1+1\t\t\t// Other args are ignored, anyway.\n  |->fff_fallback:\t\t\t// Call fast function fallback handler.\n  |  // BASE = new base, RD = nargs+1\n  |  mov L:RB, SAVE_L\n  |  mov PC, [BASE-4]\t\t\t// Fallback may overwrite PC.\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  lea RA, [RD+8*LUA_MINSTACK]\t// Ensure enough space for handler.\n  |  mov L:RB->top, RD\n  |  mov CFUNC:RD, [BASE-8]\n  |  cmp RA, L:RB->maxstack\n  |  ja >5\t\t\t\t// Need to grow stack.\n  |.if X64\n  |  mov CARG1d, L:RB\n  |.else\n  |  mov ARG1, L:RB\n  |.endif\n  |  call aword CFUNC:RD->f\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  // Either throws an error, or recovers and returns -1, 0 or nresults+1.\n  |  test RD, RD;  jg ->fff_res\t\t// Returned nresults+1?\n  |1:\n  |  mov RA, L:RB->top\n  |  sub RA, BASE\n  |  shr RA, 3\n  |  test RD, RD\n  |  lea NARGS:RD, [RA+1]\n  |  mov LFUNC:RB, [BASE-8]\n  |  jne ->vm_call_tail\t\t\t// Returned -1?\n  |  ins_callt\t\t\t\t// Returned 0: retry fast path.\n  |\n  |// Reconstruct previous base for vmeta_call during tailcall.\n  |->vm_call_tail:\n  |  mov RA, BASE\n  |  test PC, FRAME_TYPE\n  |  jnz >3\n  |  movzx RB, PC_RA\n  |  not RBa\t\t\t\t// Note: ~RB = -(RB+1)\n  |  lea BASE, [BASE+RB*8]\t\t// base = base - (RB+1)*8\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |3:\n  |  mov RB, PC\n  |  and RB, -8\n  |  sub BASE, RB\n  |  jmp ->vm_call_dispatch\t\t// Resolve again for tailcall.\n  |\n  |5:  // Grow stack for fallback handler.\n  |  mov FCARG2, LUA_MINSTACK\n  |  mov FCARG1, L:RB\n  |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n  |  mov BASE, L:RB->base\n  |  xor RD, RD\t\t\t\t// Simulate a return 0.\n  |  jmp <1\t\t\t\t// Dumb retry (goes through ff first).\n  |\n  |->fff_gcstep:\t\t\t// Call GC step function.\n  |  // BASE = new base, RD = nargs+1\n  |  pop RBa\t\t\t\t// Must keep stack at same level.\n  |  mov TMPa, RBa\t\t\t// Save return address\n  |  mov L:RB, SAVE_L\n  |  mov SAVE_PC, PC\t\t\t// Redundant (but a defined value).\n  |  mov L:RB->base, BASE\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov FCARG1, L:RB\n  |  mov L:RB->top, RD\n  |  call extern lj_gc_step@4\t\t// (lua_State *L)\n  |  mov BASE, L:RB->base\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  mov RBa, TMPa\n  |  push RBa\t\t\t\t// Restore return address.\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Special dispatch targets -------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->vm_record:\t\t\t\t// Dispatch target for recording phase.\n  |.if JIT\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_VMEVENT\t\t// No recording while in vmevent.\n  |  jnz >5\n  |  // Decrement the hookcount for consistency, but always do the call.\n  |  test RDL, HOOK_ACTIVE\n  |  jnz >1\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >1\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jmp >1\n  |.endif\n  |\n  |->vm_rethook:\t\t\t// Dispatch target for return hooks.\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |  jmp >1\n  |\n  |->vm_inshook:\t\t\t// Dispatch target for instr/line hooks.\n  |  movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]\n  |  test RDL, HOOK_ACTIVE\t\t// Hook already active?\n  |  jnz >5\n  |\n  |  test RDL, LUA_MASKLINE|LUA_MASKCOUNT\n  |  jz >5\n  |  dec dword [DISPATCH+DISPATCH_GL(hookcount)]\n  |  jz >1\n  |  test RDL, LUA_MASKLINE\n  |  jz >5\n  |1:\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\t\t\t// Caveat: FCARG2 == BASE\n  |  mov FCARG1, L:RB\n  |  // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.\n  |  call extern lj_dispatch_ins@8\t// (lua_State *L, const BCIns *pc)\n  |3:\n  |  mov BASE, L:RB->base\n  |4:\n  |  movzx RA, PC_RA\n  |5:\n  |  movzx OP, PC_OP\n  |  movzx RD, PC_RD\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |.else\n  |  jmp aword [DISPATCH+OP*4+GG_DISP2STATIC]\t// Re-dispatch to static ins.\n  |.endif\n  |\n  |->cont_hook:\t\t\t\t// Continue from hook yield.\n  |  add PC, 4\n  |  mov RA, [RB-24]\n  |  mov MULTRES, RA\t\t\t// Restore MULTRES for *M ins.\n  |  jmp <4\n  |\n  |->vm_hotloop:\t\t\t// Hot loop counter underflow.\n  |.if JIT\n  |  mov LFUNC:RB, [BASE-8]\t\t// Same as curr_topL(L).\n  |  mov RB, LFUNC:RB->pc\n  |  movzx RD, byte [RB+PC2PROTO(framesize)]\n  |  lea RD, [BASE+RD*8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov FCARG2, PC\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  mov SAVE_PC, PC\n  |  call extern lj_trace_hot@8\t\t// (jit_State *J, const BCIns *pc)\n  |  jmp <3\n  |.endif\n  |\n  |->vm_callhook:\t\t\t// Dispatch target for call hooks.\n  |  mov SAVE_PC, PC\n  |.if JIT\n  |  jmp >1\n  |.endif\n  |\n  |->vm_hotcall:\t\t\t// Hot call counter underflow.\n  |.if JIT\n  |  mov SAVE_PC, PC\n  |  or PC, 1\t\t\t\t// Marker for hot call.\n  |1:\n  |.endif\n  |  lea RD, [BASE+NARGS:RD*8-8]\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov L:RB->top, RD\n  |  mov FCARG2, PC\n  |  mov FCARG1, L:RB\n  |  call extern lj_dispatch_call@8\t// (lua_State *L, const BCIns *pc)\n  |  // ASMFunction returned in eax/rax (RDa).\n  |  mov SAVE_PC, 0\t\t\t// Invalidate for subsequent line hook.\n  |.if JIT\n  |  and PC, -2\n  |.endif\n  |  mov BASE, L:RB->base\n  |  mov RAa, RDa\n  |  mov RD, L:RB->top\n  |  sub RD, BASE\n  |  mov RBa, RAa\n  |  movzx RA, PC_RA\n  |  shr RD, 3\n  |  add NARGS:RD, 1\n  |  jmp RBa\n  |\n  |->cont_stitch:\t\t\t// Trace stitching.\n  |.if JIT\n  |  // BASE = base, RC = result, RB = mbase\n  |  mov TRACE:RA, [RB-24]\t\t// Save previous trace.\n  |  mov TMP1, TRACE:RA\n  |  mov TMP3, DISPATCH\t\t\t// Need one more register.\n  |  mov DISPATCH, MULTRES\n  |  movzx RA, PC_RA\n  |  lea RA, [BASE+RA*8]\t\t// Call base.\n  |  sub DISPATCH, 1\n  |  jz >2\n  |1:  // Move results down.\n  |.if X64\n  |  mov RBa, [RC]\n  |  mov [RA], RBa\n  |.else\n  |  mov RB, [RC]\n  |  mov [RA], RB\n  |  mov RB, [RC+4]\n  |  mov [RA+4], RB\n  |.endif\n  |  add RC, 8\n  |  add RA, 8\n  |  sub DISPATCH, 1\n  |  jnz <1\n  |2:\n  |  movzx RC, PC_RA\n  |  movzx RB, PC_RB\n  |  add RC, RB\n  |  lea RC, [BASE+RC*8-8]\n  |3:\n  |  cmp RC, RA\n  |  ja >9\t\t\t\t// More results wanted?\n  |\n  |  mov DISPATCH, TMP3\n  |  mov TRACE:RD, TMP1\t\t\t// Get previous trace.\n  |  movzx RB, word TRACE:RD->traceno\n  |  movzx RD, word TRACE:RD->link\n  |  cmp RD, RB\n  |  je ->cont_nop\t\t\t// Blacklisted.\n  |  test RD, RD\n  |  jne =>BC_JLOOP\t\t\t// Jump to stitched trace.\n  |\n  |  // Stitch a new trace to the previous trace.\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RB\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  call extern lj_dispatch_stitch@8\t// (jit_State *J, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  jmp ->cont_nop\n  |\n  |9:  // Fill up results with nil.\n  |  mov dword [RA+4], LJ_TNIL\n  |  add RA, 8\n  |  jmp <3\n  |.endif\n  |\n  |->vm_profhook:\t\t\t// Dispatch target for profiler hook.\n#if LJ_HASPROFILE\n  |  mov L:RB, SAVE_L\n  |  mov L:RB->base, BASE\n  |  mov FCARG2, PC\t\t\t// Caveat: FCARG2 == BASE\n  |  mov FCARG1, L:RB\n  |  call extern lj_dispatch_profile@8\t// (lua_State *L, const BCIns *pc)\n  |  mov BASE, L:RB->base\n  |  // HOOK_PROFILE is off again, so re-dispatch to dynamic instruction.\n  |  sub PC, 4\n  |  jmp ->cont_nop\n#endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Trace exit handler -------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Called from an exit stub with the exit number on the stack.\n  |// The 16 bit exit number is stored with two (sign-extended) push imm8.\n  |->vm_exit_handler:\n  |.if JIT\n  |.if X64\n  |  push r13; push r12\n  |  push r11; push r10; push r9; push r8\n  |  push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp\n  |  push rbx; push rdx; push rcx; push rax\n  |  movzx RC, byte [rbp-8]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [rbp-16]\n  |  mov [rbp-8], r15; mov [rbp-16], r14\n  |.else\n  |  push ebp; lea ebp, [esp+12]; push ebp\n  |  push ebx; push edx; push ecx; push eax\n  |  movzx RC, byte [ebp-4]\t\t// Reconstruct exit number.\n  |  mov RCH, byte [ebp-8]\n  |  mov [ebp-4], edi; mov [ebp-8], esi\n  |.endif\n  |  // Caveat: DISPATCH is ebx.\n  |  mov DISPATCH, [ebp]\n  |  mov RA, [DISPATCH+DISPATCH_GL(vmstate)]\t// Get trace number.\n  |  set_vmstate EXIT\n  |  mov [DISPATCH+DISPATCH_J(exitno)], RC\n  |  mov [DISPATCH+DISPATCH_J(parent)], RA\n  |.if X64\n  |.if X64WIN\n  |  sub rsp, 16*8+4*8\t\t\t// Room for SSE regs + save area.\n  |.else\n  |  sub rsp, 16*8\t\t\t// Room for SSE regs.\n  |.endif\n  |  add rbp, -128\n  |  movsd qword [rbp-8],   xmm15; movsd qword [rbp-16],  xmm14\n  |  movsd qword [rbp-24],  xmm13; movsd qword [rbp-32],  xmm12\n  |  movsd qword [rbp-40],  xmm11; movsd qword [rbp-48],  xmm10\n  |  movsd qword [rbp-56],  xmm9;  movsd qword [rbp-64],  xmm8\n  |  movsd qword [rbp-72],  xmm7;  movsd qword [rbp-80],  xmm6\n  |  movsd qword [rbp-88],  xmm5;  movsd qword [rbp-96],  xmm4\n  |  movsd qword [rbp-104], xmm3;  movsd qword [rbp-112], xmm2\n  |  movsd qword [rbp-120], xmm1;  movsd qword [rbp-128], xmm0\n  |.else\n  |  sub esp, 8*8+16\t\t\t// Room for SSE regs + args.\n  |  movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6\n  |  movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4\n  |  movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2\n  |  movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0\n  |.endif\n  |  // Caveat: RB is ebp.\n  |  mov L:RB, [DISPATCH+DISPATCH_GL(cur_L)]\n  |  mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]\n  |  mov aword [DISPATCH+DISPATCH_J(L)], L:RBa\n  |  mov L:RB->base, BASE\n  |.if X64WIN\n  |  lea CARG2, [rsp+4*8]\n  |.elif X64\n  |  mov CARG2, rsp\n  |.else\n  |  lea FCARG2, [esp+16]\n  |.endif\n  |  lea FCARG1, [DISPATCH+GG_DISP2J]\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  call extern lj_trace_exit@8\t// (jit_State *J, ExitState *ex)\n  |  // MULTRES or negated error code returned in eax (RD).\n  |  mov RAa, L:RB->cframe\n  |  and RAa, CFRAME_RAWMASK\n  |.if X64WIN\n  |  // Reposition stack later.\n  |.elif X64\n  |  mov rsp, RAa\t\t\t// Reposition stack to C frame.\n  |.else\n  |  mov esp, RAa\t\t\t// Reposition stack to C frame.\n  |.endif\n  |  mov [RAa+CFRAME_OFS_L], L:RB\t// Set SAVE_L (on-trace resume/yield).\n  |  mov BASE, L:RB->base\n  |  mov PC, [RAa+CFRAME_OFS_PC]\t// Get SAVE_PC.\n  |.if X64\n  |  jmp >1\n  |.endif\n  |.endif\n  |->vm_exit_interp:\n  |  // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.\n  |.if JIT\n  |.if X64\n  |  // Restore additional callee-save registers only used in compiled code.\n  |.if X64WIN\n  |  lea RAa, [rsp+9*16+4*8]\n  |1:\n  |  movdqa xmm15, [RAa-9*16]\n  |  movdqa xmm14, [RAa-8*16]\n  |  movdqa xmm13, [RAa-7*16]\n  |  movdqa xmm12, [RAa-6*16]\n  |  movdqa xmm11, [RAa-5*16]\n  |  movdqa xmm10, [RAa-4*16]\n  |  movdqa xmm9, [RAa-3*16]\n  |  movdqa xmm8, [RAa-2*16]\n  |  movdqa xmm7, [RAa-1*16]\n  |  mov rsp, RAa\t\t\t// Reposition stack to C frame.\n  |  movdqa xmm6, [RAa]\n  |  mov r15, CSAVE_3\n  |  mov r14, CSAVE_4\n  |.else\n  |  add rsp, 16\t\t\t// Reposition stack to C frame.\n  |1:\n  |.endif\n  |  mov r13, TMPa\n  |  mov r12, TMPQ\n  |.endif\n  |  test RD, RD; js >9\t\t\t// Check for error from exit.\n  |  mov L:RB, SAVE_L\n  |  mov MULTRES, RD\n  |  mov LFUNC:KBASE, [BASE-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  mov L:RB->base, BASE\n  |  mov dword [DISPATCH+DISPATCH_GL(jit_base)], 0\n  |  set_vmstate INTERP\n  |  // Modified copy of ins_next which handles function header dispatch, too.\n  |  mov RC, [PC]\n  |  movzx RA, RCH\n  |  movzx OP, RCL\n  |  add PC, 4\n  |  shr RC, 16\n  |  cmp OP, BC_FUNCF\t\t\t// Function header?\n  |  jb >3\n  |  cmp OP, BC_FUNCC+2\t\t\t// Fast function?\n  |  jae >4\n  |2:\n  |  mov RC, MULTRES\t\t\t// RC/RD holds nres+1.\n  |3:\n  |.if X64\n  |  jmp aword [DISPATCH+OP*8]\n  |.else\n  |  jmp aword [DISPATCH+OP*4]\n  |.endif\n  |\n  |4:  // Check frame below fast function.\n  |  mov RC, [BASE-4]\n  |  test RC, FRAME_TYPE\n  |  jnz <2\t\t\t\t// Trace stitching continuation?\n  |  // Otherwise set KBASE for Lua function below fast function.\n  |  movzx RC, byte [RC-3]\n  |  not RCa\n  |  mov LFUNC:KBASE, [BASE+RC*8-8]\n  |  mov KBASE, LFUNC:KBASE->pc\n  |  mov KBASE, [KBASE+PC2PROTO(k)]\n  |  jmp <2\n  |\n  |9:  // Rethrow error from the right C frame.\n  |  mov FCARG2, RD\n  |  mov FCARG1, L:RB\n  |  neg FCARG2\n  |  call extern lj_err_trace@8\t\t// (lua_State *L, int errcode)\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Math helper functions ----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// FP value rounding. Called by math.floor/math.ceil fast functions\n  |// and from JIT code. arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.\n  |.macro vm_round, name, mode, cond\n  |->name:\n  |.if not X64 and cond\n  |  movsd xmm0, qword [esp+4]\n  |  call ->name .. _sse\n  |  movsd qword [esp+4], xmm0  // Overwrite callee-owned arg.\n  |  fld qword [esp+4]\n  |  ret\n  |.endif\n  |\n  |->name .. _sse:\n  |  sseconst_abs xmm2, RDa\n  |  sseconst_2p52 xmm3, RDa\n  |  movaps xmm1, xmm0\n  |  andpd xmm1, xmm2\t\t\t// |x|\n  |  ucomisd xmm3, xmm1\t\t\t// No truncation if 2^52 <= |x|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |.if mode == 2\t\t// trunc(x)?\n  |  movaps xmm0, xmm1\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  sseconst_1 xmm3, RDa\n  |  cmpsd xmm0, xmm1, 1\t\t// |x| < result?\n  |  andpd xmm0, xmm3\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract -1.\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |.else\n  |  addsd xmm1, xmm3\t\t\t// (|x| + 2^52) - 2^52\n  |  subsd xmm1, xmm3\n  |  orpd xmm1, xmm2\t\t\t// Merge sign bit back in.\n  |  .if mode == 1\t\t// ceil(x)?\n  |    sseconst_m1 xmm2, RDa\t\t// Must subtract -1 to preserve -0.\n  |    cmpsd xmm0, xmm1, 6\t\t// x > result?\n  |  .else\t\t\t// floor(x)?\n  |    sseconst_1 xmm2, RDa\n  |    cmpsd xmm0, xmm1, 1\t\t// x < result?\n  |  .endif\n  |  andpd xmm0, xmm2\n  |  subsd xmm1, xmm0\t\t\t// If yes, subtract +-1.\n  |.endif\n  |  movaps xmm0, xmm1\n  |1:\n  |  ret\n  |.endmacro\n  |\n  |  vm_round vm_floor, 0, 1\n  |  vm_round vm_ceil,  1, JIT\n  |  vm_round vm_trunc, 2, JIT\n  |\n  |// FP modulo x%y. Called by BC_MOD* and vm_arith.\n  |->vm_mod:\n  |// Args in xmm0/xmm1, return value in xmm0.\n  |// Caveat: xmm0-xmm5 and RC (eax) modified!\n  |  movaps xmm5, xmm0\n  |  divsd xmm0, xmm1\n  |  sseconst_abs xmm2, RDa\n  |  sseconst_2p52 xmm3, RDa\n  |  movaps xmm4, xmm0\n  |  andpd xmm4, xmm2\t\t\t// |x/y|\n  |  ucomisd xmm3, xmm4\t\t\t// No truncation if 2^52 <= |x/y|.\n  |  jbe >1\n  |  andnpd xmm2, xmm0\t\t\t// Isolate sign bit.\n  |  addsd xmm4, xmm3\t\t\t// (|x/y| + 2^52) - 2^52\n  |  subsd xmm4, xmm3\n  |  orpd xmm4, xmm2\t\t\t// Merge sign bit back in.\n  |  sseconst_1 xmm2, RDa\n  |  cmpsd xmm0, xmm4, 1\t\t// x/y < result?\n  |  andpd xmm0, xmm2\n  |  subsd xmm4, xmm0\t\t\t// If yes, subtract 1.0.\n  |  movaps xmm0, xmm5\n  |  mulsd xmm1, xmm4\n  |  subsd xmm0, xmm1\n  |  ret\n  |1:\n  |  mulsd xmm1, xmm0\n  |  movaps xmm0, xmm5\n  |  subsd xmm0, xmm1\n  |  ret\n  |\n  |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.\n  |->vm_powi_sse:\n  |  cmp eax, 1; jle >6\t\t\t// i<=1?\n  |  // Now 1 < (unsigned)i <= 0x80000000.\n  |1:  // Handle leading zeros.\n  |  test eax, 1; jnz >2\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1\n  |  jmp <1\n  |2:\n  |  shr eax, 1; jz >5\n  |  movaps xmm1, xmm0\n  |3:  // Handle trailing bits.\n  |  mulsd xmm0, xmm0\n  |  shr eax, 1; jz >4\n  |  jnc <3\n  |  mulsd xmm1, xmm0\n  |  jmp <3\n  |4:\n  |  mulsd xmm0, xmm1\n  |5:\n  |  ret\n  |6:\n  |  je <5\t\t\t\t// x^1 ==> x\n  |  jb >7\t\t\t\t// x^0 ==> 1\n  |  neg eax\n  |  call <1\n  |  sseconst_1 xmm1, RDa\n  |  divsd xmm1, xmm0\n  |  movaps xmm0, xmm1\n  |  ret\n  |7:\n  |  sseconst_1 xmm0, RDa\n  |  ret\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Miscellaneous functions --------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])\n  |->vm_cpuid:\n  |.if X64\n  |  mov eax, CARG1d\n  |  .if X64WIN; push rsi; mov rsi, CARG2; .endif\n  |  push rbx\n  |  xor ecx, ecx\n  |  cpuid\n  |  mov [rsi], eax\n  |  mov [rsi+4], ebx\n  |  mov [rsi+8], ecx\n  |  mov [rsi+12], edx\n  |  pop rbx\n  |  .if X64WIN; pop rsi; .endif\n  |  ret\n  |.else\n  |  pushfd\n  |  pop edx\n  |  mov ecx, edx\n  |  xor edx, 0x00200000\t\t// Toggle ID bit in flags.\n  |  push edx\n  |  popfd\n  |  pushfd\n  |  pop edx\n  |  xor eax, eax\t\t\t// Zero means no features supported.\n  |  cmp ecx, edx\n  |  jz >1\t\t\t\t// No ID toggle means no CPUID support.\n  |  mov eax, [esp+4]\t\t\t// Argument 1 is function number.\n  |  push edi\n  |  push ebx\n  |  xor ecx, ecx\n  |  cpuid\n  |  mov edi, [esp+16]\t\t\t// Argument 2 is result area.\n  |  mov [edi], eax\n  |  mov [edi+4], ebx\n  |  mov [edi+8], ecx\n  |  mov [edi+12], edx\n  |  pop ebx\n  |  pop edi\n  |1:\n  |  ret\n  |.endif\n  |\n  |.define NEXT_TAB,\t\tTAB:FCARG1\n  |.define NEXT_IDX,\t\tFCARG2\n  |.define NEXT_PTR,\t\tRCa\n  |.define NEXT_PTRd,\t\tRC\n  |.macro NEXT_RES_IDXL, op2;\tlea edx, [NEXT_IDX+op2]; .endmacro\n  |.if X64\n  |.define NEXT_TMP,\t\tCARG3d\n  |.define NEXT_TMPq,\t\tCARG3\n  |.define NEXT_ASIZE,\t\tCARG4d\n  |.macro NEXT_ENTER;\t\t.endmacro\n  |.macro NEXT_LEAVE;\t\tret; .endmacro\n  |.if X64WIN\n  |.define NEXT_RES_PTR,\t[rsp+aword*5]\n  |.macro NEXT_RES_IDX, op2;\tadd NEXT_IDX, op2; .endmacro\n  |.else\n  |.define NEXT_RES_PTR,\t[rsp+aword*1]\n  |.macro NEXT_RES_IDX, op2;\tlea edx, [NEXT_IDX+op2]; .endmacro\n  |.endif\n  |.else\n  |.define NEXT_ASIZE,\t\tesi\n  |.define NEXT_TMP,\t\tedi\n  |.macro NEXT_ENTER;\t\tpush esi; push edi; .endmacro\n  |.macro NEXT_LEAVE;\t\tpop edi; pop esi; ret; .endmacro\n  |.define NEXT_RES_PTR,\t[esp+dword*3]\n  |.macro NEXT_RES_IDX, op2;\tadd NEXT_IDX, op2; .endmacro\n  |.endif\n  |\n  |// TValue *lj_vm_next(GCtab *t, uint32_t idx)\n  |// Next idx returned in edx.\n  |->vm_next:\n  |.if JIT\n  |  NEXT_ENTER\n  |  mov NEXT_ASIZE, NEXT_TAB->asize\n  |1:  // Traverse array part.\n  |  cmp NEXT_IDX, NEXT_ASIZE;  jae >5\n  |  mov NEXT_TMP, NEXT_TAB->array\n  |  cmp dword [NEXT_TMP+NEXT_IDX*8+4], LJ_TNIL;  je >2\n  |  lea NEXT_PTR, NEXT_RES_PTR\n  |.if X64\n  |  mov NEXT_TMPq, qword [NEXT_TMP+NEXT_IDX*8]\n  |  mov qword [NEXT_PTR], NEXT_TMPq\n  |.else\n  |  mov NEXT_ASIZE, dword [NEXT_TMP+NEXT_IDX*8+4]\n  |  mov NEXT_TMP, dword [NEXT_TMP+NEXT_IDX*8]\n  |  mov dword [NEXT_PTR+4], NEXT_ASIZE\n  |  mov dword [NEXT_PTR], NEXT_TMP\n  |.endif\n  |.if DUALNUM\n  |  mov dword [NEXT_PTR+dword*3], LJ_TISNUM\n  |  mov dword [NEXT_PTR+dword*2], NEXT_IDX\n  |.else\n  |  cvtsi2sd xmm0, NEXT_IDX\n  |  movsd qword [NEXT_PTR+dword*2], xmm0\n  |.endif\n  |  NEXT_RES_IDX 1\n  |  NEXT_LEAVE\n  |2:  // Skip holes in array part.\n  |  add NEXT_IDX, 1\n  |  jmp <1\n  |\n  |5:  // Traverse hash part.\n  |  sub NEXT_IDX, NEXT_ASIZE\n  |6:\n  |  cmp NEXT_IDX, NEXT_TAB->hmask; ja >9\n  |  imul NEXT_PTRd, NEXT_IDX, #NODE\n  |  add NODE:NEXT_PTRd, dword NEXT_TAB->node\n  |  cmp dword NODE:NEXT_PTR->val.it, LJ_TNIL; je >7\n  |  NEXT_RES_IDXL NEXT_ASIZE+1\n  |  NEXT_LEAVE\n  |7:  // Skip holes in hash part.\n  |  add NEXT_IDX, 1\n  |  jmp <6\n  |\n  |9:  // End of iteration. Set the key to nil (not the value).\n  |  NEXT_RES_IDX NEXT_ASIZE\n  |  lea NEXT_PTR, NEXT_RES_PTR\n  |  mov dword [NEXT_PTR+dword*3], LJ_TNIL\n  |  NEXT_LEAVE\n  |.endif\n  |\n  |//-----------------------------------------------------------------------\n  |//-- Assertions ---------------------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |->assert_bad_for_arg_type:\n#ifdef LUA_USE_ASSERT\n  |  int3\n#endif\n  |  int3\n  |\n  |//-----------------------------------------------------------------------\n  |//-- FFI helper functions -----------------------------------------------\n  |//-----------------------------------------------------------------------\n  |\n  |// Handler for callback functions. Callback slot number in ah/al.\n  |->vm_ffi_callback:\n  |.if FFI\n  |.type CTSTATE, CTState, PC\n  |.if not X64\n  |  sub esp, 16\t\t\t// Leave room for SAVE_ERRF etc.\n  |.endif\n  |  saveregs_\t// ebp/rbp already saved. ebp now holds global_State *.\n  |  lea DISPATCH, [ebp+GG_G2DISP]\n  |  mov CTSTATE, GL:ebp->ctype_state\n  |  movzx eax, ax\n  |  mov CTSTATE->cb.slot, eax\n  |.if X64\n  |  mov CTSTATE->cb.gpr[0], CARG1\n  |  mov CTSTATE->cb.gpr[1], CARG2\n  |  mov CTSTATE->cb.gpr[2], CARG3\n  |  mov CTSTATE->cb.gpr[3], CARG4\n  |  movsd qword CTSTATE->cb.fpr[0], xmm0\n  |  movsd qword CTSTATE->cb.fpr[1], xmm1\n  |  movsd qword CTSTATE->cb.fpr[2], xmm2\n  |  movsd qword CTSTATE->cb.fpr[3], xmm3\n  |.if X64WIN\n  |  lea rax, [rsp+CFRAME_SIZE+4*8]\n  |.else\n  |  lea rax, [rsp+CFRAME_SIZE]\n  |  mov CTSTATE->cb.gpr[4], CARG5\n  |  mov CTSTATE->cb.gpr[5], CARG6\n  |  movsd qword CTSTATE->cb.fpr[4], xmm4\n  |  movsd qword CTSTATE->cb.fpr[5], xmm5\n  |  movsd qword CTSTATE->cb.fpr[6], xmm6\n  |  movsd qword CTSTATE->cb.fpr[7], xmm7\n  |.endif\n  |  mov CTSTATE->cb.stack, rax\n  |  mov CARG2, rsp\n  |.else\n  |  lea eax, [esp+CFRAME_SIZE+16]\n  |  mov CTSTATE->cb.gpr[0], FCARG1\n  |  mov CTSTATE->cb.gpr[1], FCARG2\n  |  mov CTSTATE->cb.stack, eax\n  |  mov FCARG1, [esp+CFRAME_SIZE+12]\t// Move around misplaced retaddr/ebp.\n  |  mov FCARG2, [esp+CFRAME_SIZE+8]\n  |  mov SAVE_RET, FCARG1\n  |  mov SAVE_R4, FCARG2\n  |  mov FCARG2, esp\n  |.endif\n  |  mov SAVE_PC, CTSTATE\t\t// Any value outside of bytecode is ok.\n  |  mov FCARG1, CTSTATE\n  |  call extern lj_ccallback_enter@8\t// (CTState *cts, void *cf)\n  |  // lua_State * returned in eax (RD).\n  |  set_vmstate INTERP\n  |  mov BASE, L:RD->base\n  |  mov RD, L:RD->top\n  |  sub RD, BASE\n  |  mov LFUNC:RB, [BASE-8]\n  |  shr RD, 3\n  |  add RD, 1\n  |  ins_callt\n  |.endif\n  |\n  |->cont_ffi_callback:\t\t\t// Return from FFI callback.\n  |.if FFI\n  |  mov L:RA, SAVE_L\n  |  mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]\n  |  mov aword CTSTATE->L, L:RAa\n  |  mov L:RA->base, BASE\n  |  mov L:RA->top, RB\n  |  mov FCARG1, CTSTATE\n  |  mov FCARG2, RC\n  |  call extern lj_ccallback_leave@8\t// (CTState *cts, TValue *o)\n  |.if X64\n  |  mov rax, CTSTATE->cb.gpr[0]\n  |  movsd xmm0, qword CTSTATE->cb.fpr[0]\n  |  jmp ->vm_leave_unw\n  |.else\n  |  mov L:RB, SAVE_L\n  |  mov eax, CTSTATE->cb.gpr[0]\n  |  mov edx, CTSTATE->cb.gpr[1]\n  |  cmp dword CTSTATE->cb.gpr[2], 1\n  |  jb >7\n  |  je >6\n  |  fld qword CTSTATE->cb.fpr[0].d\n  |  jmp >7\n  |6:\n  |  fld dword CTSTATE->cb.fpr[0].f\n  |7:\n  |  mov ecx, L:RB->top\n  |  movzx ecx, word [ecx+6]\t\t// Get stack adjustment and copy up.\n  |  mov SAVE_L, ecx\t\t\t// Must be one slot above SAVE_RET\n  |  restoreregs\n  |  pop ecx\t\t\t\t// Move return addr from SAVE_RET.\n  |  add esp, [esp]\t\t\t// Adjust stack.\n  |  add esp, 16\n  |  push ecx\n  |  ret\n  |.endif\n  |.endif\n  |\n  |->vm_ffi_call@4:\t\t\t// Call C function via FFI.\n  |  // Caveat: needs special frame unwinding, see below.\n  |.if FFI\n  |.if X64\n  |  .type CCSTATE, CCallState, rbx\n  |  push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1\n  |.else\n  |  .type CCSTATE, CCallState, ebx\n  |  push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1\n  |.endif\n  |\n  |  // Readjust stack.\n  |.if X64\n  |  mov eax, CCSTATE->spadj\n  |  sub rsp, rax\n  |.else\n  |  sub esp, CCSTATE->spadj\n  |.if WIN\n  |  mov CCSTATE->spadj, esp\n  |.endif\n  |.endif\n  |\n  |  // Copy stack slots.\n  |  movzx ecx, byte CCSTATE->nsp\n  |  sub ecx, 1\n  |  js >2\n  |1:\n  |.if X64\n  |  mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]\n  |  mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax\n  |.else\n  |  mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)]\n  |  mov [esp+ecx*4], eax\n  |.endif\n  |  sub ecx, 1\n  |  jns <1\n  |2:\n  |\n  |.if X64\n  |  movzx eax, byte CCSTATE->nfpr\n  |  mov CARG1, CCSTATE->gpr[0]\n  |  mov CARG2, CCSTATE->gpr[1]\n  |  mov CARG3, CCSTATE->gpr[2]\n  |  mov CARG4, CCSTATE->gpr[3]\n  |.if not X64WIN\n  |  mov CARG5, CCSTATE->gpr[4]\n  |  mov CARG6, CCSTATE->gpr[5]\n  |.endif\n  |  test eax, eax; jz >5\n  |  movaps xmm0, CCSTATE->fpr[0]\n  |  movaps xmm1, CCSTATE->fpr[1]\n  |  movaps xmm2, CCSTATE->fpr[2]\n  |  movaps xmm3, CCSTATE->fpr[3]\n  |.if not X64WIN\n  |  cmp eax, 4; jbe >5\n  |  movaps xmm4, CCSTATE->fpr[4]\n  |  movaps xmm5, CCSTATE->fpr[5]\n  |  movaps xmm6, CCSTATE->fpr[6]\n  |  movaps xmm7, CCSTATE->fpr[7]\n  |.endif\n  |5:\n  |.else\n  |  mov FCARG1, CCSTATE->gpr[0]\n  |  mov FCARG2, CCSTATE->gpr[1]\n  |.endif\n  |\n  |  call aword CCSTATE->func\n  |\n  |.if X64\n  |  mov CCSTATE->gpr[0], rax\n  |  movaps CCSTATE->fpr[0], xmm0\n  |.if not X64WIN\n  |  mov CCSTATE->gpr[1], rdx\n  |  movaps CCSTATE->fpr[1], xmm1\n  |.endif\n  |.else\n  |  mov CCSTATE->gpr[0], eax\n  |  mov CCSTATE->gpr[1], edx\n  |  cmp byte CCSTATE->resx87, 1\n  |  jb >7\n  |  je >6\n  |  fstp qword CCSTATE->fpr[0].d[0]\n  |  jmp >7\n  |6:\n  |  fstp dword CCSTATE->fpr[0].f[0]\n  |7:\n  |.if WIN\n  |  sub CCSTATE->spadj, esp\n  |.endif\n  |.endif\n  |\n  |.if X64\n  |  mov rbx, [rbp-8]; leave; ret\n  |.else\n  |  mov ebx, [ebp-4]; leave; ret\n  |.endif\n  |.endif\n  |// Note: vm_ffi_call must be the last function in this object file!\n  |\n  |//-----------------------------------------------------------------------\n}\n\n/* Generate the code for a single instruction. */\nstatic void build_ins(BuildCtx *ctx, BCOp op, int defop)\n{\n  int vk = 0;\n  |// Note: aligning all instructions does not pay off.\n  |=>defop:\n\n  switch (op) {\n\n  /* -- Comparison ops ---------------------------------------------------- */\n\n  /* Remember: all ops branch for a true comparison, fall through otherwise. */\n\n  |.macro jmp_comp, lt, ge, le, gt, target\n  ||switch (op) {\n  ||case BC_ISLT:\n  |   lt target\n  ||break;\n  ||case BC_ISGE:\n  |   ge target\n  ||break;\n  ||case BC_ISLE:\n  |   le target\n  ||break;\n  ||case BC_ISGT:\n  |   gt target\n  ||break;\n  ||default: break;  /* Shut up GCC. */\n  ||}\n  |.endmacro\n\n  case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:\n    |  // RA = src1, RD = src2, JMP with RD = target\n    |  ins_AD\n    |.if DUALNUM\n    |  checkint RA, >7\n    |  checkint RD, >8\n    |  mov RB, dword [BASE+RA*8]\n    |  add PC, 4\n    |  cmp RB, dword [BASE+RD*8]\n    |  jmp_comp jge, jl, jg, jle, >9\n    |6:\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is a number.\n    |  cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, dword [BASE+RD*8]\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is not an integer.\n    |  ja ->vmeta_comp\n    |  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm1, dword [BASE+RA*8]\n    |  movsd xmm0, qword [BASE+RD*8]\n    |  add PC, 4\n    |  ucomisd xmm0, xmm1\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  checknum RA, ->vmeta_comp\n    |  checknum RD, ->vmeta_comp\n    |.endif\n    |1:\n    |  movsd xmm0, qword [BASE+RD*8]\n    |2:\n    |  add PC, 4\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |3:\n    |  // Unordered: all of ZF CF PF set, ordered: PF clear.\n    |  // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.\n    |.if DUALNUM\n    |  jmp_comp jbe, ja, jb, jae, <9\n    |  jmp <6\n    |.else\n    |  jmp_comp jbe, ja, jb, jae, >1\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |1:\n    |  ins_next\n    |.endif\n    break;\n\n  case BC_ISEQV: case BC_ISNEV:\n    vk = op == BC_ISEQV;\n    |  ins_AD\t// RA = src1, RD = src2, JMP with RD = target\n    |  mov RB, [BASE+RD*8+4]\n    |  add PC, 4\n    |.if DUALNUM\n    |  cmp RB, LJ_TISNUM; jne >7\n    |  checkint RA, >8\n    |  mov RB, dword [BASE+RD*8]\n    |  cmp RB, dword [BASE+RA*8]\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RD is not an integer.\n    |  ja >5\n    |  // RD is a number.\n    |  cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5\n    |  // RD is a number, RA is an integer.\n    |  cvtsi2sd xmm0, dword [BASE+RA*8]\n    |  jmp >2\n    |\n    |8:  // RD is an integer, RA is not an integer.\n    |  ja >5\n    |  // RD is an integer, RA is a number.\n    |  cvtsi2sd xmm0, dword [BASE+RD*8]\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |  jmp >4\n    |\n    |.else\n    |  cmp RB, LJ_TISNUM; jae >5\n    |  checknum RA, >5\n    |.endif\n    |1:\n    |  movsd xmm0, qword [BASE+RA*8]\n    |2:\n    |  ucomisd xmm0, qword [BASE+RD*8]\n    |4:\n  iseqne_fp:\n    if (vk) {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  jne >2\n    } else {\n      |  jp >2\t\t\t\t// Unordered means not equal.\n      |  je >1\n    }\n  iseqne_end:\n    if (vk) {\n      |1:\t\t\t\t// EQ: Branch to the target.\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\t\t\t\t// NE: Fallthrough to next instruction.\n      |.if not FFI\n      |3:\n      |.endif\n    } else {\n      |.if not FFI\n      |3:\n      |.endif\n      |2:\t\t\t\t// NE: Branch to the target.\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |1:\t\t\t\t// EQ: Fallthrough to next instruction.\n    }\n    if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||\n\t\t       op == BC_ISEQN || op == BC_ISNEN)) {\n      |  jmp <9\n    } else {\n      |  ins_next\n    }\n    |\n    if (op == BC_ISEQV || op == BC_ISNEV) {\n      |5:  // Either or both types are not numbers.\n      |.if FFI\n      |  cmp RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  checktp RA, LJ_TCDATA; je ->vmeta_equal_cd\n      |.endif\n      |  checktp RA, RB\t\t\t// Compare types.\n      |  jne <2\t\t\t\t// Not the same type?\n      |  cmp RB, LJ_TISPRI\n      |  jae <1\t\t\t\t// Same type and primitive type?\n      |\n      |  // Same types and not a primitive type. Compare GCobj or pvalue.\n      |  mov RA, [BASE+RA*8]\n      |  mov RD, [BASE+RD*8]\n      |  cmp RA, RD\n      |  je <1\t\t\t\t// Same GCobjs or pvalues?\n      |  cmp RB, LJ_TISTABUD\n      |  ja <2\t\t\t\t// Different objects and not table/ud?\n      |.if X64\n      |  cmp RB, LJ_TUDATA\t\t// And not 64 bit lightuserdata.\n      |  jb <2\n      |.endif\n      |\n      |  // Different tables or userdatas. Need to check __eq metamethod.\n      |  // Field metatable must be at same offset for GCtab and GCudata!\n      |  mov TAB:RB, TAB:RA->metatable\n      |  test TAB:RB, TAB:RB\n      |  jz <2\t\t\t\t// No metatable?\n      |  test byte TAB:RB->nomm, 1<<MM_eq\n      |  jnz <2\t\t\t\t// Or 'no __eq' flag set?\n      if (vk) {\n\t|  xor RB, RB\t\t\t// ne = 0\n      } else {\n\t|  mov RB, 1\t\t\t// ne = 1\n      }\n      |  jmp ->vmeta_equal\t\t// Handle __eq metamethod.\n    } else {\n      |.if FFI\n      |3:\n      |  cmp RB, LJ_TCDATA\n      if (LJ_DUALNUM && vk) {\n\t|  jne <9\n      } else {\n\t|  jne <2\n      }\n      |  jmp ->vmeta_equal_cd\n      |.endif\n    }\n    break;\n  case BC_ISEQS: case BC_ISNES:\n    vk = op == BC_ISEQS;\n    |  ins_AND\t// RA = src, RD = str const, JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |  cmp RB, LJ_TSTR; jne >3\n    |  mov RA, [BASE+RA*8]\n    |  cmp RA, [KBASE+RD*4]\n  iseqne_test:\n    if (vk) {\n      |  jne >2\n    } else {\n      |  je >1\n    }\n    goto iseqne_end;\n  case BC_ISEQN: case BC_ISNEN:\n    vk = op == BC_ISEQN;\n    |  ins_AD\t// RA = src, RD = num const, JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |.if DUALNUM\n    |  cmp RB, LJ_TISNUM; jne >7\n    |  cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8\n    |  mov RB, dword [KBASE+RD*8]\n    |  cmp RB, dword [BASE+RA*8]\n    if (vk) {\n      |  jne >9\n    } else {\n      |  je >9\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |9:\n    |  ins_next\n    |\n    |7:  // RA is not an integer.\n    |  ja >3\n    |  // RA is a number.\n    |  cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1\n    |  // RA is a number, RD is an integer.\n    |  cvtsi2sd xmm0, dword [KBASE+RD*8]\n    |  jmp >2\n    |\n    |8:  // RA is an integer, RD is a number.\n    |  cvtsi2sd xmm0, dword [BASE+RA*8]\n    |  ucomisd xmm0, qword [KBASE+RD*8]\n    |  jmp >4\n    |.else\n    |  cmp RB, LJ_TISNUM; jae >3\n    |.endif\n    |1:\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |2:\n    |  ucomisd xmm0, qword [BASE+RA*8]\n    |4:\n    goto iseqne_fp;\n  case BC_ISEQP: case BC_ISNEP:\n    vk = op == BC_ISEQP;\n    |  ins_AND\t// RA = src, RD = primitive type (~), JMP with RD = target\n    |  mov RB, [BASE+RA*8+4]\n    |  add PC, 4\n    |  cmp RB, RD\n    if (!LJ_HASFFI) goto iseqne_test;\n    if (vk) {\n      |  jne >3\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n      |3:\n      |  cmp RB, LJ_TCDATA; jne <2\n      |  jmp ->vmeta_equal_cd\n    } else {\n      |  je >2\n      |  cmp RB, LJ_TCDATA; je ->vmeta_equal_cd\n      |  movzx RD, PC_RD\n      |  branchPC RD\n      |2:\n      |  ins_next\n    }\n    break;\n\n  /* -- Unary test and copy ops ------------------------------------------- */\n\n  case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:\n    |  ins_AD\t// RA = dst or unused, RD = src, JMP with RD = target\n    |  mov RB, [BASE+RD*8+4]\n    |  add PC, 4\n    |  cmp RB, LJ_TISTRUECOND\n    if (op == BC_IST || op == BC_ISTC) {\n      |  jae >1\n    } else {\n      |  jb >1\n    }\n    if (op == BC_ISTC || op == BC_ISFC) {\n      |  mov [BASE+RA*8+4], RB\n      |  mov RB, [BASE+RD*8]\n      |  mov [BASE+RA*8], RB\n    }\n    |  movzx RD, PC_RD\n    |  branchPC RD\n    |1:\t\t\t\t\t// Fallthrough to the next instruction.\n    |  ins_next\n    break;\n\n  case BC_ISTYPE:\n    |  ins_AD\t// RA = src, RD = -type\n    |  add RD, [BASE+RA*8+4]\n    |  jne ->vmeta_istype\n    |  ins_next\n    break;\n  case BC_ISNUM:\n    |  ins_AD\t// RA = src, RD = -(TISNUM-1)\n    |  checknum RA, ->vmeta_istype\n    |  ins_next\n    break;\n\n  /* -- Unary ops --------------------------------------------------------- */\n\n  case BC_MOV:\n    |  ins_AD\t// RA = dst, RD = src\n    |.if X64\n    |  mov RBa, [BASE+RD*8]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [BASE+RD*8+4]\n    |  mov RD, [BASE+RD*8]\n    |  mov [BASE+RA*8+4], RB\n    |  mov [BASE+RA*8], RD\n    |.endif\n    |  ins_next_\n    break;\n  case BC_NOT:\n    |  ins_AD\t// RA = dst, RD = src\n    |  xor RB, RB\n    |  checktp RD, LJ_TISTRUECOND\n    |  adc RB, LJ_TTRUE\n    |  mov [BASE+RA*8+4], RB\n    |  ins_next\n    break;\n  case BC_UNM:\n    |  ins_AD\t// RA = dst, RD = src\n    |.if DUALNUM\n    |  checkint RD, >5\n    |  mov RB, [BASE+RD*8]\n    |  neg RB\n    |  jo >4\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RB\n    |9:\n    |  ins_next\n    |4:\n    |  mov dword [BASE+RA*8+4], 0x41e00000  // 2^31.\n    |  mov dword [BASE+RA*8], 0\n    |  jmp <9\n    |5:\n    |  ja ->vmeta_unm\n    |.else\n    |  checknum RD, ->vmeta_unm\n    |.endif\n    |  movsd xmm0, qword [BASE+RD*8]\n    |  sseconst_sign xmm1, RDa\n    |  xorps xmm0, xmm1\n    |  movsd qword [BASE+RA*8], xmm0\n    |.if DUALNUM\n    |  jmp <9\n    |.else\n    |  ins_next\n    |.endif\n    break;\n  case BC_LEN:\n    |  ins_AD\t// RA = dst, RD = src\n    |  checkstr RD, >2\n    |  mov STR:RD, [BASE+RD*8]\n    |.if DUALNUM\n    |  mov RD, dword STR:RD->len\n    |1:\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RD\n    |.else\n    |  xorps xmm0, xmm0\n    |  cvtsi2sd xmm0, dword STR:RD->len\n    |1:\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    |2:\n    |  checktab RD, ->vmeta_len\n    |  mov TAB:FCARG1, [BASE+RD*8]\n#if LJ_52\n    |  mov TAB:RB, TAB:FCARG1->metatable\n    |  cmp TAB:RB, 0\n    |  jnz >9\n    |3:\n#endif\n    |->BC_LEN_Z:\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |  call extern lj_tab_len@4\t\t// (GCtab *t)\n    |  // Length of table returned in eax (RD).\n    |.if DUALNUM\n    |  // Nothing to do.\n    |.else\n    |  cvtsi2sd xmm0, RD\n    |.endif\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  movzx RA, PC_RA\n    |  jmp <1\n#if LJ_52\n    |9:  // Check for __len.\n    |  test byte TAB:RB->nomm, 1<<MM_len\n    |  jnz <3\n    |  jmp ->vmeta_len\t\t\t// 'no __len' flag NOT set: check.\n#endif\n    break;\n\n  /* -- Binary ops -------------------------------------------------------- */\n\n    |.macro ins_arithpre, sseins, ssereg\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checknum RB, ->vmeta_arith_vn\n    |   .if DUALNUM\n    |     cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn\n    |   .endif\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [KBASE+RC*8]\n    ||  break;\n    ||case 1:\n    |   checknum RB, ->vmeta_arith_nv\n    |   .if DUALNUM\n    |     cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv\n    |   .endif\n    |   movsd xmm0, qword [KBASE+RC*8]\n    |   sseins ssereg, qword [BASE+RB*8]\n    ||  break;\n    ||default:\n    |   checknum RB, ->vmeta_arith_vv\n    |   checknum RC, ->vmeta_arith_vv\n    |   movsd xmm0, qword [BASE+RB*8]\n    |   sseins ssereg, qword [BASE+RC*8]\n    ||  break;\n    ||}\n    |.endmacro\n    |\n    |.macro ins_arithdn, intins\n    |  ins_ABC\n    ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);\n    ||switch (vk) {\n    ||case 0:\n    |   checkint RB, ->vmeta_arith_vn\n    |   cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn\n    |   mov RB, [BASE+RB*8]\n    |   intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno\n    ||  break;\n    ||case 1:\n    |   checkint RB, ->vmeta_arith_nv\n    |   cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv\n    |   mov RC, [KBASE+RC*8]\n    |   intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo\n    ||  break;\n    ||default:\n    |   checkint RB, ->vmeta_arith_vv\n    |   checkint RC, ->vmeta_arith_vv\n    |   mov RB, [BASE+RB*8]\n    |   intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo\n    ||  break;\n    ||}\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    ||if (vk == 1) {\n    |   mov dword [BASE+RA*8], RC\n    ||} else {\n    |   mov dword [BASE+RA*8], RB\n    ||}\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arithpost\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endmacro\n    |\n    |.macro ins_arith, sseins\n    |  ins_arithpre sseins, xmm0\n    |  ins_arithpost\n    |  ins_next\n    |.endmacro\n    |\n    |.macro ins_arith, intins, sseins\n    |.if DUALNUM\n    |  ins_arithdn intins\n    |.else\n    |  ins_arith, sseins\n    |.endif\n    |.endmacro\n\n    |  // RA = dst, RB = src1 or num const, RC = src2 or num const\n  case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:\n    |  ins_arith add, addsd\n    break;\n  case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:\n    |  ins_arith sub, subsd\n    break;\n  case BC_MULVN: case BC_MULNV: case BC_MULVV:\n    |  ins_arith imul, mulsd\n    break;\n  case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:\n    |  ins_arith divsd\n    break;\n  case BC_MODVN:\n    |  ins_arithpre movsd, xmm1\n    |->BC_MODVN_Z:\n    |  call ->vm_mod\n    |  ins_arithpost\n    |  ins_next\n    break;\n  case BC_MODNV: case BC_MODVV:\n    |  ins_arithpre movsd, xmm1\n    |  jmp ->BC_MODVN_Z\t\t\t// Avoid 3 copies. It's slow anyway.\n    break;\n  case BC_POW:\n    |  ins_arithpre movsd, xmm1\n    |  mov RB, BASE\n    |.if not X64\n    |  movsd FPARG1, xmm0\n    |  movsd FPARG3, xmm1\n    |.endif\n    |  call extern pow\n    |  movzx RA, PC_RA\n    |  mov BASE, RB\n    |.if X64\n    |  ins_arithpost\n    |.else\n    |  fstp qword [BASE+RA*8]\n    |.endif\n    |  ins_next\n    break;\n\n  case BC_CAT:\n    |  ins_ABC\t// RA = dst, RB = src_start, RC = src_end\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\n    |  lea CARG2d, [BASE+RC*8]\n    |  mov CARG3d, RC\n    |  sub CARG3d, RB\n    |->BC_CAT_Z:\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  lea RA, [BASE+RC*8]\n    |  sub RC, RB\n    |  mov ARG2, RA\n    |  mov ARG3, RC\n    |->BC_CAT_Z:\n    |  mov L:RB, SAVE_L\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_meta_cat\t\t// (lua_State *L, TValue *top, int left)\n    |  // NULL (finished) or TValue * (metamethod) returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  test RC, RC\n    |  jnz ->vmeta_binop\n    |  movzx RB, PC_RB\t\t\t// Copy result to Stk[RA] from Stk[RB].\n    |  movzx RA, PC_RA\n    |.if X64\n    |  mov RCa, [BASE+RB*8]\n    |  mov [BASE+RA*8], RCa\n    |.else\n    |  mov RC, [BASE+RB*8+4]\n    |  mov RB, [BASE+RB*8]\n    |  mov [BASE+RA*8+4], RC\n    |  mov [BASE+RA*8], RB\n    |.endif\n    |  ins_next\n    break;\n\n  /* -- Constant ops ------------------------------------------------------ */\n\n  case BC_KSTR:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov RD, [KBASE+RD*4]\n    |  mov dword [BASE+RA*8+4], LJ_TSTR\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    break;\n  case BC_KCDATA:\n    |.if FFI\n    |  ins_AND\t// RA = dst, RD = cdata const (~)\n    |  mov RD, [KBASE+RD*4]\n    |  mov dword [BASE+RA*8+4], LJ_TCDATA\n    |  mov [BASE+RA*8], RD\n    |  ins_next\n    |.endif\n    break;\n  case BC_KSHORT:\n    |  ins_AD\t// RA = dst, RD = signed int16 literal\n    |.if DUALNUM\n    |  movsx RD, RDW\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RD\n    |.else\n    |  movsx RD, RDW\t\t\t// Sign-extend literal.\n    |  cvtsi2sd xmm0, RD\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  ins_next\n    break;\n  case BC_KNUM:\n    |  ins_AD\t// RA = dst, RD = num const\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  movsd qword [BASE+RA*8], xmm0\n    |  ins_next\n    break;\n  case BC_KPRI:\n    |  ins_AND\t// RA = dst, RD = primitive type (~)\n    |  mov [BASE+RA*8+4], RD\n    |  ins_next\n    break;\n  case BC_KNIL:\n    |  ins_AD\t// RA = dst_start, RD = dst_end\n    |  lea RA, [BASE+RA*8+12]\n    |  lea RD, [BASE+RD*8+4]\n    |  mov RB, LJ_TNIL\n    |  mov [RA-8], RB\t\t\t// Sets minimum 2 slots.\n    |1:\n    |  mov [RA], RB\n    |  add RA, 8\n    |  cmp RA, RD\n    |  jbe <1\n    |  ins_next\n    break;\n\n  /* -- Upvalue and function ops ------------------------------------------ */\n\n  case BC_UGET:\n    |  ins_AD\t// RA = dst, RD = upvalue #\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)]\n    |  mov RB, UPVAL:RB->v\n    |.if X64\n    |  mov RDa, [RB]\n    |  mov [BASE+RA*8], RDa\n    |.else\n    |  mov RD, [RB+4]\n    |  mov RB, [RB]\n    |  mov [BASE+RA*8+4], RD\n    |  mov [BASE+RA*8], RB\n    |.endif\n    |  ins_next\n    break;\n  case BC_USETV:\n#define TV2MARKOFS \\\n ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))\n    |  ins_AD\t// RA = upvalue #, RD = src\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  cmp byte UPVAL:RB->closed, 0\n    |  mov RB, UPVAL:RB->v\n    |  mov RA, [BASE+RD*8]\n    |  mov RD, [BASE+RD*8+4]\n    |  mov [RB], RA\n    |  mov [RB+4], RD\n    |  jz >1\n    |  // Check barrier for closed upvalue.\n    |  test byte [RB+TV2MARKOFS], LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Upvalue is black. Check if new value is collectable and white.\n    |  sub RD, LJ_TISGCV\n    |  cmp RD, LJ_TNUMX - LJ_TISGCV\t\t\t// tvisgcv(v)\n    |  jbe <1\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(v)\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |.if X64 and not X64WIN\n    |  mov FCARG2, RB\n    |  mov RB, BASE\t\t\t// Save BASE.\n    |.else\n    |  xchg FCARG2, RB\t\t\t// Save BASE (FCARG2 == BASE).\n    |.endif\n    |  lea GL:FCARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv@8\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n#undef TV2MARKOFS\n  case BC_USETS:\n    |  ins_AND\t// RA = upvalue #, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov GCOBJ:RA, [KBASE+RD*4]\n    |  mov RD, UPVAL:RB->v\n    |  mov [RD], GCOBJ:RA\n    |  mov dword [RD+4], LJ_TSTR\n    |  test byte UPVAL:RB->marked, LJ_GC_BLACK\t\t// isblack(uv)\n    |  jnz >2\n    |1:\n    |  ins_next\n    |\n    |2:  // Check if string is white and ensure upvalue is closed.\n    |  test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES\t// iswhite(str)\n    |  jz <1\n    |  cmp byte UPVAL:RB->closed, 0\n    |  jz <1\n    |  // Crossed a write barrier. Move the barrier forward.\n    |  mov RB, BASE\t\t\t// Save BASE (FCARG2 == BASE).\n    |  mov FCARG2, RD\n    |  lea GL:FCARG1, [DISPATCH+GG_DISP2G]\n    |  call extern lj_gc_barrieruv@8\t// (global_State *g, TValue *tv)\n    |  mov BASE, RB\t\t\t// Restore BASE.\n    |  jmp <1\n    break;\n  case BC_USETN:\n    |  ins_AD\t// RA = upvalue #, RD = num const\n    |  mov LFUNC:RB, [BASE-8]\n    |  movsd xmm0, qword [KBASE+RD*8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  movsd qword [RA], xmm0\n    |  ins_next\n    break;\n  case BC_USETP:\n    |  ins_AND\t// RA = upvalue #, RD = primitive type (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]\n    |  mov RA, UPVAL:RB->v\n    |  mov [RA+4], RD\n    |  ins_next\n    break;\n  case BC_UCLO:\n    |  ins_AD\t// RA = level, RD = target\n    |  branchPC RD\t\t\t// Do this first to free RD.\n    |  mov L:RB, SAVE_L\n    |  cmp dword L:RB->openupval, 0\n    |  je >1\n    |  mov L:RB->base, BASE\n    |  lea FCARG2, [BASE+RA*8]\t\t// Caveat: FCARG2 == BASE\n    |  mov L:FCARG1, L:RB\t\t// Caveat: FCARG1 == RA\n    |  call extern lj_func_closeuv@8\t// (lua_State *L, TValue *level)\n    |  mov BASE, L:RB->base\n    |1:\n    |  ins_next\n    break;\n\n  case BC_FNEW:\n    |  ins_AND\t// RA = dst, RD = proto const (~) (holding function prototype)\n    |.if X64\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n    |  mov CARG3d, [BASE-8]\n    |  mov CARG2d, [KBASE+RD*4]\t\t// Fetch GCproto *.\n    |  mov CARG1d, L:RB\n    |.else\n    |  mov LFUNC:RA, [BASE-8]\n    |  mov PROTO:RD, [KBASE+RD*4]\t// Fetch GCproto *.\n    |  mov L:RB, SAVE_L\n    |  mov ARG3, LFUNC:RA\n    |  mov ARG2, PROTO:RD\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  // (lua_State *L, GCproto *pt, GCfuncL *parent)\n    |  call extern lj_func_newL_gc\n    |  // GCfuncL * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], LFUNC:RC\n    |  mov dword [BASE+RA*8+4], LJ_TFUNC\n    |  ins_next\n    break;\n\n  /* -- Table ops --------------------------------------------------------- */\n\n  case BC_TNEW:\n    |  ins_AD\t// RA = dst, RD = hbits|asize\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov SAVE_PC, PC\n    |  jae >5\n    |1:\n    |.if X64\n    |  mov CARG3d, RD\n    |  and RD, 0x7ff\n    |  shr CARG3d, 11\n    |.else\n    |  mov RA, RD\n    |  and RD, 0x7ff\n    |  shr RA, 11\n    |  mov ARG3, RA\n    |.endif\n    |  cmp RD, 0x7ff\n    |  je >3\n    |2:\n    |.if X64\n    |  mov L:CARG1d, L:RB\n    |  mov CARG2d, RD\n    |.else\n    |  mov ARG1, L:RB\n    |  mov ARG2, RD\n    |.endif\n    |  call extern lj_tab_new  // (lua_State *L, int32_t asize, uint32_t hbits)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], TAB:RC\n    |  mov dword [BASE+RA*8+4], LJ_TTAB\n    |  ins_next\n    |3:  // Turn 0x7ff into 0x801.\n    |  mov RD, 0x801\n    |  jmp <2\n    |5:\n    |  mov L:FCARG1, L:RB\n    |  call extern lj_gc_step_fixtop@4\t// (lua_State *L)\n    |  movzx RD, PC_RD\n    |  jmp <1\n    break;\n  case BC_TDUP:\n    |  ins_AND\t// RA = dst, RD = table const (~) (holding template table)\n    |  mov L:RB, SAVE_L\n    |  mov RA, [DISPATCH+DISPATCH_GL(gc.total)]\n    |  mov SAVE_PC, PC\n    |  cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]\n    |  mov L:RB->base, BASE\n    |  jae >3\n    |2:\n    |  mov TAB:FCARG2, [KBASE+RD*4]\t// Caveat: FCARG2 == BASE\n    |  mov L:FCARG1, L:RB\t\t// Caveat: FCARG1 == RA\n    |  call extern lj_tab_dup@8\t\t// (lua_State *L, Table *kt)\n    |  // Table * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\n    |  mov [BASE+RA*8], TAB:RC\n    |  mov dword [BASE+RA*8+4], LJ_TTAB\n    |  ins_next\n    |3:\n    |  mov L:FCARG1, L:RB\n    |  call extern lj_gc_step_fixtop@4\t// (lua_State *L)\n    |  movzx RD, PC_RD\t\t\t// Need to reload RD.\n    |  not RDa\n    |  jmp <2\n    break;\n\n  case BC_GGET:\n    |  ins_AND\t// RA = dst, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*4]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_GSET:\n    |  ins_AND\t// RA = src, RD = str const (~)\n    |  mov LFUNC:RB, [BASE-8]\n    |  mov TAB:RB, LFUNC:RB->env\n    |  mov STR:RC, [KBASE+RD*4]\n    |  jmp ->BC_TSETS_Z\n    break;\n\n  case BC_TGETV:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  checktab RB, ->vmeta_tgetv\n    |  mov TAB:RB, [BASE+RB*8]\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movsd xmm0, qword [BASE+RC*8]\n    |  cvttsd2si RC, xmm0\n    |  cvtsi2sd xmm1, RC\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tgetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RC, TAB:RB->asize\t// Takes care of unordered, too.\n    |  jae ->vmeta_tgetv\t\t// Not in array part? Use fallback.\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |  // Get array slot.\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |1:\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz >3\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetv\t\t\t// 'no __index' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |3:\n    |  mov dword [BASE+RA*8+4], LJ_TNIL\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  checkstr RC, ->vmeta_tgetv\n    |  mov STR:RC, [BASE+RC*8]\n    |  jmp ->BC_TGETS_Z\n    break;\n  case BC_TGETS:\n    |  ins_ABC\t// RA = dst, RB = table, RC = str const (~)\n    |  not RCa\n    |  mov STR:RC, [KBASE+RC*4]\n    |  checktab RB, ->vmeta_tgets\n    |  mov TAB:RB, [BASE+RB*8]\n    |->BC_TGETS_Z:\t// RB = GCtab *, RC = GCstr *, refetches PC_RA.\n    |  mov RA, TAB:RB->hmask\n    |  and RA, STR:RC->sid\n    |  imul RA, #NODE\n    |  add NODE:RA, TAB:RB->node\n    |1:\n    |  cmp dword NODE:RA->key.it, LJ_TSTR\n    |  jne >4\n    |  cmp dword NODE:RA->key.gcr, STR:RC\n    |  jne >4\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp dword [RA+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >5\t\t\t\t// Key found, but nil value?\n    |  movzx RC, PC_RA\n    |  // Get node value.\n    |.if X64\n    |  mov RBa, [RA]\n    |  mov [BASE+RC*8], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov RA, [RA+4]\n    |  mov [BASE+RC*8], RB\n    |  mov [BASE+RC*8+4], RA\n    |.endif\n    |2:\n    |  ins_next\n    |\n    |3:\n    |  movzx RC, PC_RA\n    |  mov dword [BASE+RC*8+4], LJ_TNIL\n    |  jmp <2\n    |\n    |4:  // Follow hash chain.\n    |  mov NODE:RA, NODE:RA->next\n    |  test NODE:RA, NODE:RA\n    |  jnz <1\n    |  // End of hash chain: key not found, nil result.\n    |\n    |5:  // Check for __index if table value is nil.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test TAB:RA, TAB:RA\n    |  jz <3\t\t\t\t// No metatable: done.\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jnz <3\t\t\t\t// 'no __index' flag set: done.\n    |  jmp ->vmeta_tgets\t\t// Caveat: preserve STR:RC.\n    break;\n  case BC_TGETB:\n    |  ins_ABC\t// RA = dst, RB = table, RC = byte literal\n    |  checktab RB, ->vmeta_tgetb\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tgetb\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\t// Avoid overwriting RB in fastpath.\n    |  je >2\n    |  // Get array slot.\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |1:\n    |  ins_next\n    |\n    |2:  // Check for __index if table value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz >3\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_index\n    |  jz ->vmeta_tgetb\t\t\t// 'no __index' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |3:\n    |  mov dword [BASE+RA*8+4], LJ_TNIL\n    |  jmp <1\n    break;\n  case BC_TGETR:\n    |  ins_ABC\t// RA = dst, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |.if DUALNUM\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RC, qword [BASE+RC*8]\n    |.endif\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tgetr\t\t// Not in array part? Use fallback.\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  // Get array slot.\n    |->BC_TGETR_Z:\n    |.if X64\n    |  mov RBa, [RC]\n    |  mov [BASE+RA*8], RBa\n    |.else\n    |  mov RB, [RC]\n    |  mov RC, [RC+4]\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |.endif\n    |->BC_TGETR2_Z:\n    |  ins_next\n    break;\n\n  case BC_TSETV:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  checktab RB, ->vmeta_tsetv\n    |  mov TAB:RB, [BASE+RB*8]\n    |\n    |  // Integer key?\n    |.if DUALNUM\n    |  checkint RC, >5\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  // Convert number to int and back and compare.\n    |  checknum RC, >5\n    |  movsd xmm0, qword [BASE+RC*8]\n    |  cvttsd2si RC, xmm0\n    |  cvtsi2sd xmm1, RC\n    |  ucomisd xmm0, xmm1\n    |  jne ->vmeta_tsetv\t\t// Generic numeric key? Use fallback.\n    |.endif\n    |  cmp RC, TAB:RB->asize\t\t// Takes care of unordered, too.\n    |  jae ->vmeta_tsetv\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:  // Set array slot.\n    |.if X64\n    |  mov RBa, [BASE+RA*8]\n    |  mov [RC], RBa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <1\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetv\t\t\t// 'no __newindex' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\n    |\n    |5:  // String key?\n    |  checkstr RC, ->vmeta_tsetv\n    |  mov STR:RC, [BASE+RC*8]\n    |  jmp ->BC_TSETS_Z\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n  case BC_TSETS:\n    |  ins_ABC\t// RA = src, RB = table, RC = str const (~)\n    |  not RCa\n    |  mov STR:RC, [KBASE+RC*4]\n    |  checktab RB, ->vmeta_tsets\n    |  mov TAB:RB, [BASE+RB*8]\n    |->BC_TSETS_Z:\t// RB = GCtab *, RC = GCstr *, refetches PC_RA.\n    |  mov RA, TAB:RB->hmask\n    |  and RA, STR:RC->sid\n    |  imul RA, #NODE\n    |  mov byte TAB:RB->nomm, 0\t\t// Clear metamethod cache.\n    |  add NODE:RA, TAB:RB->node\n    |1:\n    |  cmp dword NODE:RA->key.it, LJ_TSTR\n    |  jne >5\n    |  cmp dword NODE:RA->key.gcr, STR:RC\n    |  jne >5\n    |  // Ok, key found. Assumes: offsetof(Node, val) == 0\n    |  cmp dword [RA+4], LJ_TNIL\n    |  je >4\t\t\t\t// Previous value is nil?\n    |2:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |3:  // Set node value.\n    |  movzx RC, PC_RA\n    |.if X64\n    |  mov RBa, [BASE+RC*8]\n    |  mov [RA], RBa\n    |.else\n    |  mov RB, [BASE+RC*8+4]\n    |  mov RC, [BASE+RC*8]\n    |  mov [RA+4], RB\n    |  mov [RA], RC\n    |.endif\n    |  ins_next\n    |\n    |4:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <2\n    |  mov TMP1, RA\t\t\t// Save RA.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |  mov RA, TMP1\t\t\t// Restore RA.\n    |  jmp <2\n    |\n    |5:  // Follow hash chain.\n    |  mov NODE:RA, NODE:RA->next\n    |  test NODE:RA, NODE:RA\n    |  jnz <1\n    |  // End of hash chain: key not found, add a new one.\n    |\n    |  // But check for __newindex first.\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test TAB:RA, TAB:RA\n    |  jz >6\t\t\t\t// No metatable: continue.\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsets\t\t\t// 'no __newindex' flag NOT set: check.\n    |6:\n    |  mov TMP1, STR:RC\n    |  mov TMP2, LJ_TSTR\n    |  mov TMP3, TAB:RB\t\t\t// Save TAB:RB for us.\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\n    |  lea CARG3, TMP1\n    |  mov CARG2d, TAB:RB\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  lea RC, TMP1\t\t\t// Store temp. TValue in TMP1/TMP2.\n    |  mov ARG2, TAB:RB\n    |  mov L:RB, SAVE_L\n    |  mov ARG3, RC\n    |  mov ARG1, L:RB\n    |  mov L:RB->base, BASE\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_newkey\t// (lua_State *L, GCtab *t, TValue *k)\n    |  // Handles write barrier for the new key. TValue * returned in eax (RC).\n    |  mov BASE, L:RB->base\n    |  mov TAB:RB, TMP3\t\t\t// Need TAB:RB for barrier.\n    |  mov RA, eax\n    |  jmp <2\t\t\t\t// Must check write barrier for value.\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RC\t\t// Destroys STR:RC.\n    |  jmp <3\n    break;\n  case BC_TSETB:\n    |  ins_ABC\t// RA = src, RB = table, RC = byte literal\n    |  checktab RB, ->vmeta_tsetb\n    |  mov TAB:RB, [BASE+RB*8]\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tsetb\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  cmp dword [RC+4], LJ_TNIL\n    |  je >3\t\t\t\t// Previous value is nil?\n    |1:\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\t // Set array slot.\n    |.if X64\n    |  mov RAa, [BASE+RA*8]\n    |  mov [RC], RAa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |3:  // Check for __newindex if previous value is nil.\n    |  cmp dword TAB:RB->metatable, 0\t// Shouldn't overwrite RA for fastpath.\n    |  jz <1\n    |  mov TAB:RA, TAB:RB->metatable\n    |  test byte TAB:RA->nomm, 1<<MM_newindex\n    |  jz ->vmeta_tsetb\t\t\t// 'no __newindex' flag NOT set: check.\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n  case BC_TSETR:\n    |  ins_ABC\t// RA = src, RB = table, RC = key\n    |  mov TAB:RB, [BASE+RB*8]\n    |.if DUALNUM\n    |  mov RC, dword [BASE+RC*8]\n    |.else\n    |  cvttsd2si RC, qword [BASE+RC*8]\n    |.endif\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  cmp RC, TAB:RB->asize\n    |  jae ->vmeta_tsetr\n    |  shl RC, 3\n    |  add RC, TAB:RB->array\n    |  // Set array slot.\n    |->BC_TSETR_Z:\n    |.if X64\n    |  mov RBa, [BASE+RA*8]\n    |  mov [RC], RBa\n    |.else\n    |  mov RB, [BASE+RA*8+4]\n    |  mov RA, [BASE+RA*8]\n    |  mov [RC+4], RB\n    |  mov [RC], RA\n    |.endif\n    |  ins_next\n    |\n    |7:  // Possible table write barrier for the value. Skip valiswhite check.\n    |  barrierback TAB:RB, RA\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <2\n    break;\n\n  case BC_TSETM:\n    |  ins_AD\t// RA = base (table at base-1), RD = num const (start index)\n    |  mov TMP1, KBASE\t\t\t// Need one more free register.\n    |  mov KBASE, dword [KBASE+RD*8]\t// Integer constant is in lo-word.\n    |1:\n    |  lea RA, [BASE+RA*8]\n    |  mov TAB:RB, [RA-8]\t\t// Guaranteed to be a table.\n    |  test byte TAB:RB->marked, LJ_GC_BLACK\t// isblack(table)\n    |  jnz >7\n    |2:\n    |  mov RD, MULTRES\n    |  sub RD, 1\n    |  jz >4\t\t\t\t// Nothing to copy?\n    |  add RD, KBASE\t\t\t// Compute needed size.\n    |  cmp RD, TAB:RB->asize\n    |  ja >5\t\t\t\t// Doesn't fit into array part?\n    |  sub RD, KBASE\n    |  shl KBASE, 3\n    |  add KBASE, TAB:RB->array\n    |3:  // Copy result slots to table.\n    |.if X64\n    |  mov RBa, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov [KBASE], RB\n    |  mov RB, [RA+4]\n    |  add RA, 8\n    |  mov [KBASE+4], RB\n    |.endif\n    |  add KBASE, 8\n    |  sub RD, 1\n    |  jnz <3\n    |4:\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |5:  // Need to resize array part.\n    |.if X64\n    |  mov L:CARG1d, SAVE_L\n    |  mov L:CARG1d->base, BASE\t\t// Caveat: CARG2d/CARG3d may be BASE.\n    |  mov CARG2d, TAB:RB\n    |  mov CARG3d, RD\n    |  mov L:RB, L:CARG1d\n    |.else\n    |  mov ARG2, TAB:RB\n    |  mov L:RB, SAVE_L\n    |  mov L:RB->base, BASE\n    |  mov ARG3, RD\n    |  mov ARG1, L:RB\n    |.endif\n    |  mov SAVE_PC, PC\n    |  call extern lj_tab_reasize\t// (lua_State *L, GCtab *t, int nasize)\n    |  mov BASE, L:RB->base\n    |  movzx RA, PC_RA\t\t\t// Restore RA.\n    |  jmp <1\t\t\t\t// Retry.\n    |\n    |7:  // Possible table write barrier for any value. Skip valiswhite check.\n    |  barrierback TAB:RB, RD\n    |  jmp <2\n    break;\n\n  /* -- Calls and vararg handling ----------------------------------------- */\n\n  case BC_CALL: case BC_CALLM:\n    |  ins_A_C\t// RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs\n    if (op == BC_CALLM) {\n      |  add NARGS:RD, MULTRES\n    }\n    |  cmp dword [BASE+RA*8+4], LJ_TFUNC\n    |  mov LFUNC:RB, [BASE+RA*8]\n    |  jne ->vmeta_call_ra\n    |  lea BASE, [BASE+RA*8+8]\n    |  ins_call\n    break;\n\n  case BC_CALLMT:\n    |  ins_AD\t// RA = base, RD = extra_nargs\n    |  add NARGS:RD, MULTRES\n    |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.\n    break;\n  case BC_CALLT:\n    |  ins_AD\t// RA = base, RD = nargs+1\n    |  lea RA, [BASE+RA*8+8]\n    |  mov KBASE, BASE\t\t\t// Use KBASE for move + vmeta_call hint.\n    |  mov LFUNC:RB, [RA-8]\n    |  cmp dword [RA-4], LJ_TFUNC\n    |  jne ->vmeta_call\n    |->BC_CALLT_Z:\n    |  mov PC, [BASE-4]\n    |  test PC, FRAME_TYPE\n    |  jnz >7\n    |1:\n    |  mov [BASE-8], LFUNC:RB\t\t// Copy function down, reloaded below.\n    |  mov MULTRES, NARGS:RD\n    |  sub NARGS:RD, 1\n    |  jz >3\n    |2:  // Move args down.\n    |.if X64\n    |  mov RBa, [RA]\n    |  add RA, 8\n    |  mov [KBASE], RBa\n    |.else\n    |  mov RB, [RA]\n    |  mov [KBASE], RB\n    |  mov RB, [RA+4]\n    |  add RA, 8\n    |  mov [KBASE+4], RB\n    |.endif\n    |  add KBASE, 8\n    |  sub NARGS:RD, 1\n    |  jnz <2\n    |\n    |  mov LFUNC:RB, [BASE-8]\n    |3:\n    |  mov NARGS:RD, MULTRES\n    |  cmp byte LFUNC:RB->ffid, 1\t// (> FF_C) Calling a fast function?\n    |  ja >5\n    |4:\n    |  ins_callt\n    |\n    |5:  // Tailcall to a fast function.\n    |  test PC, FRAME_TYPE\t\t// Lua frame below?\n    |  jnz <4\n    |  movzx RA, PC_RA\n    |  not RAa\n    |  mov LFUNC:KBASE, [BASE+RA*8-8]\t// Need to prepare KBASE.\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  jmp <4\n    |\n    |7:  // Tailcall from a vararg function.\n    |  sub PC, FRAME_VARG\n    |  test PC, FRAME_TYPEP\n    |  jnz >8\t\t\t\t// Vararg frame below?\n    |  sub BASE, PC\t\t\t// Need to relocate BASE/KBASE down.\n    |  mov KBASE, BASE\n    |  mov PC, [BASE-4]\n    |  jmp <1\n    |8:\n    |  add PC, FRAME_VARG\n    |  jmp <1\n    break;\n\n  case BC_ITERC:\n    |  ins_A\t// RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)\n    |  lea RA, [BASE+RA*8+8]\t\t// fb = base+1\n    |.if X64\n    |  mov RBa, [RA-24]\t\t\t// Copy state. fb[0] = fb[-3].\n    |  mov RCa, [RA-16]\t\t\t// Copy control var. fb[1] = fb[-2].\n    |  mov [RA], RBa\n    |  mov [RA+8], RCa\n    |.else\n    |  mov RB, [RA-24]\t\t\t// Copy state. fb[0] = fb[-3].\n    |  mov RC, [RA-20]\n    |  mov [RA], RB\n    |  mov [RA+4], RC\n    |  mov RB, [RA-16]\t\t\t// Copy control var. fb[1] = fb[-2].\n    |  mov RC, [RA-12]\n    |  mov [RA+8], RB\n    |  mov [RA+12], RC\n    |.endif\n    |  mov LFUNC:RB, [RA-32]\t\t// Copy callable. fb[-1] = fb[-4]\n    |  mov RC, [RA-28]\n    |  mov [RA-8], LFUNC:RB\n    |  mov [RA-4], RC\n    |  cmp RC, LJ_TFUNC\t\t\t// Handle like a regular 2-arg call.\n    |  mov NARGS:RD, 2+1\n    |  jne ->vmeta_call\n    |  mov BASE, RA\n    |  ins_call\n    break;\n\n  case BC_ITERN:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    |->vm_IITERN:\n    |  ins_A\t// RA = base, (RB = nresults+1, RC = nargs+1 (2+1))\n    |  mov TMP1, KBASE\t\t\t// Need two more free registers.\n    |  mov TMP2, DISPATCH\n    |  mov TAB:RB, [BASE+RA*8-16]\n    |  mov RC, [BASE+RA*8-8]\t\t// Get index from control var.\n    |  mov DISPATCH, TAB:RB->asize\n    |  add PC, 4\n    |  mov KBASE, TAB:RB->array\n    |1:  // Traverse array part.\n    |  cmp RC, DISPATCH; jae >5\t\t// Index points after array part?\n    |  cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4\n    |.if DUALNUM\n    |  mov dword [BASE+RA*8+4], LJ_TISNUM\n    |  mov dword [BASE+RA*8], RC\n    |.else\n    |  cvtsi2sd xmm0, RC\n    |.endif\n    |  // Copy array slot to returned value.\n    |.if X64\n    |  mov RBa, [KBASE+RC*8]\n    |  mov [BASE+RA*8+8], RBa\n    |.else\n    |  mov RB, [KBASE+RC*8+4]\n    |  mov [BASE+RA*8+12], RB\n    |  mov RB, [KBASE+RC*8]\n    |  mov [BASE+RA*8+8], RB\n    |.endif\n    |  add RC, 1\n    |  // Return array index as a numeric key.\n    |.if DUALNUM\n    |  // See above.\n    |.else\n    |  movsd qword [BASE+RA*8], xmm0\n    |.endif\n    |  mov [BASE+RA*8-8], RC\t\t// Update control var.\n    |2:\n    |  movzx RD, PC_RD\t\t\t// Get target from ITERL.\n    |  branchPC RD\n    |3:\n    |  mov DISPATCH, TMP2\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |4:  // Skip holes in array part.\n    |  add RC, 1\n    |  jmp <1\n    |\n    |5:  // Traverse hash part.\n    |  sub RC, DISPATCH\n    |6:\n    |  cmp RC, TAB:RB->hmask; ja <3\t// End of iteration? Branch to ITERL+1.\n    |  imul KBASE, RC, #NODE\n    |  add NODE:KBASE, TAB:RB->node\n    |  cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7\n    |  lea DISPATCH, [RC+DISPATCH+1]\n    |  // Copy key and value from hash slot.\n    |.if X64\n    |  mov RBa, NODE:KBASE->key\n    |  mov RCa, NODE:KBASE->val\n    |  mov [BASE+RA*8], RBa\n    |  mov [BASE+RA*8+8], RCa\n    |.else\n    |  mov RB, NODE:KBASE->key.gcr\n    |  mov RC, NODE:KBASE->key.it\n    |  mov [BASE+RA*8], RB\n    |  mov [BASE+RA*8+4], RC\n    |  mov RB, NODE:KBASE->val.gcr\n    |  mov RC, NODE:KBASE->val.it\n    |  mov [BASE+RA*8+8], RB\n    |  mov [BASE+RA*8+12], RC\n    |.endif\n    |  mov [BASE+RA*8-8], DISPATCH\n    |  jmp <2\n    |\n    |7:  // Skip holes in hash part.\n    |  add RC, 1\n    |  jmp <6\n    break;\n\n  case BC_ISNEXT:\n    |  ins_AD\t// RA = base, RD = target (points to ITERN)\n    |  cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5\n    |  mov CFUNC:RB, [BASE+RA*8-24]\n    |  cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5\n    |  cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5\n    |  cmp byte CFUNC:RB->ffid, FF_next_N; jne >5\n    |  branchPC RD\n    |  mov dword [BASE+RA*8-8], 0\t// Initialize control var.\n    |  mov dword [BASE+RA*8-4], LJ_KEYINDEX\n    |1:\n    |  ins_next\n    |5:  // Despecialize bytecode if any of the checks fail.\n    |  mov PC_OP, BC_JMP\n    |  branchPC RD\n    |.if JIT\n    |  cmp byte [PC], BC_ITERN\n    |  jne >6\n    |.endif\n    |  mov byte [PC], BC_ITERC\n    |  jmp <1\n    |.if JIT\n    |6:  // Unpatch JLOOP.\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  movzx RC, word [PC+2]\n    |  mov TRACE:RA, [RA+RC*4]\n    |  mov eax, TRACE:RA->startins\n    |  mov al, BC_ITERC\n    |  mov dword [PC], eax\n    |  jmp <1\n    |.endif\n    break;\n\n  case BC_VARG:\n    |  ins_ABC\t// RA = base, RB = nresults+1, RC = numparams\n    |  mov TMP1, KBASE\t\t\t// Need one more free register.\n    |  lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]\n    |  lea RA, [BASE+RA*8]\n    |  sub KBASE, [BASE-4]\n    |  // Note: KBASE may now be even _above_ BASE if nargs was < numparams.\n    |  test RB, RB\n    |  jz >5\t\t\t\t// Copy all varargs?\n    |  lea RB, [RA+RB*8-8]\n    |  cmp KBASE, BASE\t\t\t// No vararg slots?\n    |  jnb >2\n    |1:  // Copy vararg slots to destination slots.\n    |.if X64\n    |  mov RCa, [KBASE-8]\n    |  add KBASE, 8\n    |  mov [RA], RCa\n    |.else\n    |  mov RC, [KBASE-8]\n    |  mov [RA], RC\n    |  mov RC, [KBASE-4]\n    |  add KBASE, 8\n    |  mov [RA+4], RC\n    |.endif\n    |  add RA, 8\n    |  cmp RA, RB\t\t\t// All destination slots filled?\n    |  jnb >3\n    |  cmp KBASE, BASE\t\t\t// No more vararg slots?\n    |  jb <1\n    |2:  // Fill up remainder with nil.\n    |  mov dword [RA+4], LJ_TNIL\n    |  add RA, 8\n    |  cmp RA, RB\n    |  jb <2\n    |3:\n    |  mov KBASE, TMP1\n    |  ins_next\n    |\n    |5:  // Copy all varargs.\n    |  mov MULTRES, 1\t\t\t// MULTRES = 0+1\n    |  mov RC, BASE\n    |  sub RC, KBASE\n    |  jbe <3\t\t\t\t// No vararg slots?\n    |  mov RB, RC\n    |  shr RB, 3\n    |  add RB, 1\n    |  mov MULTRES, RB\t\t\t// MULTRES = #varargs+1\n    |  mov L:RB, SAVE_L\n    |  add RC, RA\n    |  cmp RC, L:RB->maxstack\n    |  ja >7\t\t\t\t// Need to grow stack?\n    |6:  // Copy all vararg slots.\n    |.if X64\n    |  mov RCa, [KBASE-8]\n    |  add KBASE, 8\n    |  mov [RA], RCa\n    |.else\n    |  mov RC, [KBASE-8]\n    |  mov [RA], RC\n    |  mov RC, [KBASE-4]\n    |  add KBASE, 8\n    |  mov [RA+4], RC\n    |.endif\n    |  add RA, 8\n    |  cmp KBASE, BASE\t\t\t// No more vararg slots?\n    |  jb <6\n    |  jmp <3\n    |\n    |7:  // Grow stack for varargs.\n    |  mov L:RB->base, BASE\n    |  mov L:RB->top, RA\n    |  mov SAVE_PC, PC\n    |  sub KBASE, BASE\t\t\t// Need delta, because BASE may change.\n    |  mov FCARG2, MULTRES\n    |  sub FCARG2, 1\n    |  mov FCARG1, L:RB\n    |  call extern lj_state_growstack@8\t// (lua_State *L, int n)\n    |  mov BASE, L:RB->base\n    |  mov RA, L:RB->top\n    |  add KBASE, BASE\n    |  jmp <6\n    break;\n\n  /* -- Returns ----------------------------------------------------------- */\n\n  case BC_RETM:\n    |  ins_AD\t// RA = results, RD = extra_nresults\n    |  add RD, MULTRES\t\t\t// MULTRES >=1, so RD >=1.\n    |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.\n    break;\n\n  case BC_RET: case BC_RET0: case BC_RET1:\n    |  ins_AD\t// RA = results, RD = nresults+1\n    if (op != BC_RET0) {\n      |  shl RA, 3\n    }\n    |1:\n    |  mov PC, [BASE-4]\n    |  mov MULTRES, RD\t\t\t// Save nresults+1.\n    |  test PC, FRAME_TYPE\t\t// Check frame type marker.\n    |  jnz >7\t\t\t\t// Not returning to a fixarg Lua func?\n    switch (op) {\n    case BC_RET:\n      |->BC_RET_Z:\n      |  mov KBASE, BASE\t\t// Use KBASE for result move.\n      |  sub RD, 1\n      |  jz >3\n      |2:  // Move results down.\n      |.if X64\n      |  mov RBa, [KBASE+RA]\n      |  mov [KBASE-8], RBa\n      |.else\n      |  mov RB, [KBASE+RA]\n      |  mov [KBASE-8], RB\n      |  mov RB, [KBASE+RA+4]\n      |  mov [KBASE-4], RB\n      |.endif\n      |  add KBASE, 8\n      |  sub RD, 1\n      |  jnz <2\n      |3:\n      |  mov RD, MULTRES\t\t// Note: MULTRES may be >255.\n      |  movzx RB, PC_RB\t\t// So cannot compare with RDL!\n      |5:\n      |  cmp RB, RD\t\t\t// More results expected?\n      |  ja >6\n      break;\n    case BC_RET1:\n      |.if X64\n      |  mov RBa, [BASE+RA]\n      |  mov [BASE-8], RBa\n      |.else\n      |  mov RB, [BASE+RA+4]\n      |  mov [BASE-4], RB\n      |  mov RB, [BASE+RA]\n      |  mov [BASE-8], RB\n      |.endif\n      /* fallthrough */\n    case BC_RET0:\n      |5:\n      |  cmp PC_RB, RDL\t\t\t// More results expected?\n      |  ja >6\n    default:\n      break;\n    }\n    |  movzx RA, PC_RA\n    |  not RAa\t\t\t\t// Note: ~RA = -(RA+1)\n    |  lea BASE, [BASE+RA*8]\t\t// base = base - (RA+1)*8\n    |  mov LFUNC:KBASE, [BASE-8]\n    |  mov KBASE, LFUNC:KBASE->pc\n    |  mov KBASE, [KBASE+PC2PROTO(k)]\n    |  ins_next\n    |\n    |6:  // Fill up results with nil.\n    if (op == BC_RET) {\n      |  mov dword [KBASE-4], LJ_TNIL\t// Note: relies on shifted base.\n      |  add KBASE, 8\n    } else {\n      |  mov dword [BASE+RD*8-12], LJ_TNIL\n    }\n    |  add RD, 1\n    |  jmp <5\n    |\n    |7:  // Non-standard return case.\n    |  lea RB, [PC-FRAME_VARG]\n    |  test RB, FRAME_TYPEP\n    |  jnz ->vm_return\n    |  // Return from vararg function: relocate BASE down and RA up.\n    |  sub BASE, RB\n    if (op != BC_RET0) {\n      |  add RA, RB\n    }\n    |  jmp <1\n    break;\n\n  /* -- Loops and branches ------------------------------------------------ */\n\n  |.define FOR_IDX,  [RA];    .define FOR_TIDX,  dword [RA+4]\n  |.define FOR_STOP, [RA+8];  .define FOR_TSTOP, dword [RA+12]\n  |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20]\n  |.define FOR_EXT,  [RA+24]; .define FOR_TEXT,  dword [RA+28]\n\n  case BC_FORL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JFORI:\n  case BC_JFORL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_FORI:\n  case BC_IFORL:\n    vk = (op == BC_IFORL || op == BC_JFORL);\n    |  ins_AJ\t// RA = base, RD = target (after end of loop or start of loop)\n    |  lea RA, [BASE+RA*8]\n    if (LJ_DUALNUM) {\n      |  cmp FOR_TIDX, LJ_TISNUM; jne >9\n      if (!vk) {\n\t|  cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for\n\t|  cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for\n\t|  mov RB, dword FOR_IDX\n\t|  cmp dword FOR_STEP, 0; jl >5\n      } else {\n#ifdef LUA_USE_ASSERT\n\t|  cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type\n\t|  cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type\n#endif\n\t|  mov RB, dword FOR_STEP\n\t|  test RB, RB; js >5\n\t|  add RB, dword FOR_IDX; jo >1\n\t|  mov dword FOR_IDX, RB\n      }\n      |  cmp RB, dword FOR_STOP\n      |  mov FOR_TEXT, LJ_TISNUM\n      |  mov dword FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jle >7\n\t|1:\n\t|6:\n\t|  branchPC RD\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RD, PC_RD\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      } else if (op == BC_IFORL) {\n\t|  jg >7\n\t|6:\n\t|  branchPC RD\n\t|1:\n      } else {\n\t|  jle =>BC_JLOOP\n\t|1:\n\t|6:\n      }\n      |7:\n      |  ins_next\n      |\n      |5:  // Invert check for negative step.\n      if (vk) {\n\t|  add RB, dword FOR_IDX; jo <1\n\t|  mov dword FOR_IDX, RB\n      }\n      |  cmp RB, dword FOR_STOP\n      |  mov FOR_TEXT, LJ_TISNUM\n      |  mov dword FOR_EXT, RB\n      if (op == BC_FORI) {\n\t|  jge <7\n      } else if (op == BC_JFORI) {\n\t|  branchPC RD\n\t|  movzx RD, PC_RD\n\t|  jge =>BC_JLOOP\n      } else if (op == BC_IFORL) {\n\t|  jl <7\n      } else {\n\t|  jge =>BC_JLOOP\n      }\n      |  jmp <6\n      |9:  // Fallback to FP variant.\n    } else if (!vk) {\n      |  cmp FOR_TIDX, LJ_TISNUM\n    }\n    if (!vk) {\n      |  jae ->vmeta_for\n      |  cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for\n    } else {\n#ifdef LUA_USE_ASSERT\n      |  cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type\n      |  cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type\n#endif\n    }\n    |  mov RB, FOR_TSTEP\t\t// Load type/hiword of for step.\n    if (!vk) {\n      |  cmp RB, LJ_TISNUM; jae ->vmeta_for\n    }\n    |  movsd xmm0, qword FOR_IDX\n    |  movsd xmm1, qword FOR_STOP\n    if (vk) {\n      |  addsd xmm0, qword FOR_STEP\n      |  movsd qword FOR_IDX, xmm0\n      |  test RB, RB; js >3\n    } else {\n      |  jl >3\n    }\n    |  ucomisd xmm1, xmm0\n    |1:\n    |  movsd qword FOR_EXT, xmm0\n    if (op == BC_FORI) {\n      |.if DUALNUM\n      |  jnb <7\n      |.else\n      |  jnb >2\n      |  branchPC RD\n      |.endif\n    } else if (op == BC_JFORI) {\n      |  branchPC RD\n      |  movzx RD, PC_RD\n      |  jnb =>BC_JLOOP\n    } else if (op == BC_IFORL) {\n      |.if DUALNUM\n      |  jb <7\n      |.else\n      |  jb >2\n      |  branchPC RD\n      |.endif\n    } else {\n      |  jnb =>BC_JLOOP\n    }\n    |.if DUALNUM\n    |  jmp <6\n    |.else\n    |2:\n    |  ins_next\n    |.endif\n    |\n    |3:  // Invert comparison if step is negative.\n    |  ucomisd xmm0, xmm1\n    |  jmp <1\n    break;\n\n  case BC_ITERL:\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.\n    break;\n\n  case BC_JITERL:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IITERL:\n    |  ins_AJ\t// RA = base, RD = target\n    |  lea RA, [BASE+RA*8]\n    |  mov RB, [RA+4]\n    |  cmp RB, LJ_TNIL; je >1\t\t// Stop if iterator returned nil.\n    if (op == BC_JITERL) {\n      |  mov [RA-4], RB\n      |  mov RB, [RA]\n      |  mov [RA-8], RB\n      |  jmp =>BC_JLOOP\n    } else {\n      |  branchPC RD\t\t\t// Otherwise save control var + branch.\n      |  mov RD, [RA]\n      |  mov [RA-4], RB\n      |  mov [RA-8], RD\n    }\n    |1:\n    |  ins_next\n    break;\n\n  case BC_LOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  // Note: RA/RD is only used by trace recorder to determine scope/extent\n    |  // This opcode does NOT jump, it's only purpose is to detect a hot loop.\n    |.if JIT\n    |  hotloop RB\n    |.endif\n    | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.\n    break;\n\n  case BC_ILOOP:\n    |  ins_A\t// RA = base, RD = target (loop extent)\n    |  ins_next\n    break;\n\n  case BC_JLOOP:\n    |.if JIT\n    |  ins_AD\t// RA = base (ignored), RD = traceno\n    |  mov RA, [DISPATCH+DISPATCH_J(trace)]\n    |  mov TRACE:RD, [RA+RD*4]\n    |  mov RDa, TRACE:RD->mcode\n    |  mov L:RB, SAVE_L\n    |  mov [DISPATCH+DISPATCH_GL(jit_base)], BASE\n    |  mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB\n    |  // Save additional callee-save registers only used in compiled code.\n    |.if X64WIN\n    |  mov TMPQ, r12\n    |  mov TMPa, r13\n    |  mov CSAVE_4, r14\n    |  mov CSAVE_3, r15\n    |  mov RAa, rsp\n    |  sub rsp, 9*16+4*8\n    |  movdqa [RAa], xmm6\n    |  movdqa [RAa-1*16], xmm7\n    |  movdqa [RAa-2*16], xmm8\n    |  movdqa [RAa-3*16], xmm9\n    |  movdqa [RAa-4*16], xmm10\n    |  movdqa [RAa-5*16], xmm11\n    |  movdqa [RAa-6*16], xmm12\n    |  movdqa [RAa-7*16], xmm13\n    |  movdqa [RAa-8*16], xmm14\n    |  movdqa [RAa-9*16], xmm15\n    |.elif X64\n    |  mov TMPQ, r12\n    |  mov TMPa, r13\n    |  sub rsp, 16\n    |.endif\n    |  jmp RDa\n    |.endif\n    break;\n\n  case BC_JMP:\n    |  ins_AJ\t// RA = unused, RD = target\n    |  branchPC RD\n    |  ins_next\n    break;\n\n  /* -- Function headers -------------------------------------------------- */\n\n   /*\n   ** Reminder: A function may be called with func/args above L->maxstack,\n   ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,\n   ** too. This means all FUNC* ops (including fast functions) must check\n   ** for stack overflow _before_ adding more slots!\n   */\n\n  case BC_FUNCF:\n    |.if JIT\n    |  hotcall RB\n    |.endif\n  case BC_FUNCV:  /* NYI: compiled vararg functions. */\n    | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.\n    break;\n\n  case BC_JFUNCF:\n#if !LJ_HASJIT\n    break;\n#endif\n  case BC_IFUNCF:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  mov KBASE, [PC-4+PC2PROTO(k)]\n    |  mov L:RB, SAVE_L\n    |  lea RA, [BASE+RA*8]\t\t// Top of frame.\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_f\n    |  movzx RA, byte [PC-4+PC2PROTO(numparams)]\n    |  cmp NARGS:RD, RA\t\t\t// Check for missing parameters.\n    |  jbe >3\n    |2:\n    if (op == BC_JFUNCF) {\n      |  movzx RD, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov dword [BASE+NARGS:RD*8-4], LJ_TNIL\n    |  add NARGS:RD, 1\n    |  cmp NARGS:RD, RA\n    |  jbe <3\n    |  jmp <2\n    break;\n\n  case BC_JFUNCV:\n#if !LJ_HASJIT\n    break;\n#endif\n    | int3  // NYI: compiled vararg functions\n    break;  /* NYI: compiled vararg functions. */\n\n  case BC_IFUNCV:\n    |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1\n    |  lea RB, [NARGS:RD*8+FRAME_VARG]\n    |  lea RD, [BASE+NARGS:RD*8]\n    |  mov LFUNC:KBASE, [BASE-8]\n    |  mov [RD-4], RB\t\t\t// Store delta + FRAME_VARG.\n    |  mov [RD-8], LFUNC:KBASE\t\t// Store copy of LFUNC.\n    |  mov L:RB, SAVE_L\n    |  lea RA, [RD+RA*8]\n    |  cmp RA, L:RB->maxstack\n    |  ja ->vm_growstack_v\t\t// Need to grow stack.\n    |  mov RA, BASE\n    |  mov BASE, RD\n    |  movzx RB, byte [PC-4+PC2PROTO(numparams)]\n    |  test RB, RB\n    |  jz >2\n    |1:  // Copy fixarg slots up to new frame.\n    |  add RA, 8\n    |  cmp RA, BASE\n    |  jnb >3\t\t\t\t// Less args than parameters?\n    |  mov KBASE, [RA-8]\n    |  mov [RD], KBASE\n    |  mov KBASE, [RA-4]\n    |  mov [RD+4], KBASE\n    |  add RD, 8\n    |  mov dword [RA-4], LJ_TNIL\t// Clear old fixarg slot (help the GC).\n    |  sub RB, 1\n    |  jnz <1\n    |2:\n    if (op == BC_JFUNCV) {\n      |  movzx RD, PC_RD\n      |  jmp =>BC_JLOOP\n    } else {\n      |  mov KBASE, [PC-4+PC2PROTO(k)]\n      |  ins_next\n    }\n    |\n    |3:  // Clear missing parameters.\n    |  mov dword [RD+4], LJ_TNIL\n    |  add RD, 8\n    |  sub RB, 1\n    |  jnz <3\n    |  jmp <2\n    break;\n\n  case BC_FUNCC:\n  case BC_FUNCCW:\n    |  ins_AD  // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1\n    |  mov CFUNC:RB, [BASE-8]\n    |  mov KBASEa, CFUNC:RB->f\n    |  mov L:RB, SAVE_L\n    |  lea RD, [BASE+NARGS:RD*8-8]\n    |  mov L:RB->base, BASE\n    |  lea RA, [RD+8*LUA_MINSTACK]\n    |  cmp RA, L:RB->maxstack\n    |  mov L:RB->top, RD\n    if (op == BC_FUNCC) {\n      |.if X64\n      |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n      |.else\n      |  mov ARG1, L:RB\n      |.endif\n    } else {\n      |.if X64\n      |  mov CARG2, KBASEa\n      |  mov CARG1d, L:RB\t\t\t// Caveat: CARG1d may be RA.\n      |.else\n      |  mov ARG2, KBASEa\n      |  mov ARG1, L:RB\n      |.endif\n    }\n    |  ja ->vm_growstack_c\t\t// Need to grow stack.\n    |  set_vmstate C\n    if (op == BC_FUNCC) {\n      |  call KBASEa\t\t\t// (lua_State *L)\n    } else {\n      |  // (lua_State *L, lua_CFunction f)\n      |  call aword [DISPATCH+DISPATCH_GL(wrapf)]\n    }\n    |  // nresults returned in eax (RD).\n    |  mov BASE, L:RB->base\n    |  mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB\n    |  set_vmstate INTERP\n    |  lea RA, [BASE+RD*8]\n    |  neg RA\n    |  add RA, L:RB->top\t\t// RA = (L->top-(L->base+nresults))*8\n    |  mov PC, [BASE-4]\t\t\t// Fetch PC of caller.\n    |  jmp ->vm_returnc\n    break;\n\n  /* ---------------------------------------------------------------------- */\n\n  default:\n    fprintf(stderr, \"Error: undefined opcode BC_%s\\n\", bc_names[op]);\n    exit(2);\n    break;\n  }\n}\n\nstatic int build_backend(BuildCtx *ctx)\n{\n  int op;\n  dasm_growpc(Dst, BC__MAX);\n  build_subroutines(ctx);\n  |.code_op\n  for (op = 0; op < BC__MAX; op++)\n    build_ins(ctx, (BCOp)op, op);\n  return BC__MAX;\n}\n\n/* Emit pseudo frame-info for all assembler functions. */\nstatic void emit_asm_debug(BuildCtx *ctx)\n{\n  int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);\n#if LJ_64\n#define SZPTR\t\"8\"\n#define BSZPTR\t\"3\"\n#define REG_SP\t\"0x7\"\n#define REG_RA\t\"0x10\"\n#else\n#define SZPTR\t\"4\"\n#define BSZPTR\t\"2\"\n#define REG_SP\t\"0x4\"\n#define REG_RA\t\"0x8\"\n#endif\n  switch (ctx->mode) {\n  case BUILD_elfasm:\n    fprintf(ctx->fp, \"\\t.section .debug_frame,\\\"\\\",@progbits\\n\");\n    fprintf(ctx->fp,\n\t\".Lframe0:\\n\"\n\t\"\\t.long .LECIE0-.LSCIE0\\n\"\n\t\".LSCIE0:\\n\"\n\t\"\\t.long 0xffffffff\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE0:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE0:\\n\"\n\t\"\\t.long .LEFDE0-.LASFDE0\\n\"\n\t\".LASFDE0:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_64\n\t\"\\t.quad .Lbegin\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#if LJ_NO_UNWIND\n\t\"\\t.byte 0x8d\\n\\t.uleb128 0x6\\n\"\t/* offset r13 */\n\t\"\\t.byte 0x8c\\n\\t.uleb128 0x7\\n\"\t/* offset r12 */\n#endif\n#else\n\t\"\\t.long .Lbegin\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0x3\\n\"\t/* offset edi */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x4\\n\"\t/* offset esi */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x5\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE0:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".LSFDE1:\\n\"\n\t\"\\t.long .LEFDE1-.LASFDE1\\n\"\n\t\".LASFDE1:\\n\"\n\t\"\\t.long .Lframe0\\n\"\n#if LJ_64\n\t\"\\t.quad lj_vm_ffi_call\\n\"\n\t\"\\t.quad %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n#else\n\t\"\\t.long lj_vm_ffi_call\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.byte 0xe\\n\\t.uleb128 8\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x5\\n\"\t\t/* def_cfa_register ebp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE1:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#if !LJ_NO_UNWIND\n#if LJ_TARGET_SOLARIS\n#if LJ_64\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@unwind\\n\");\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"aw\\\",@progbits\\n\");\n#endif\n#else\n    fprintf(ctx->fp, \"\\t.section .eh_frame,\\\"a\\\",@progbits\\n\");\n#endif\n    fprintf(ctx->fp,\n\t\".Lframe1:\\n\"\n\t\"\\t.long .LECIE1-.LSCIE1\\n\"\n\t\".LSCIE1:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zPR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.uleb128 6\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.long lj_err_unwind_dwarf-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE1:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE2:\\n\"\n\t\"\\t.long .LEFDE2-.LASFDE2\\n\"\n\t\".LASFDE2:\\n\"\n\t\"\\t.long .LASFDE2-.Lframe1\\n\"\n\t\"\\t.long .Lbegin-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0xe\\n\\t.uleb128 %d\\n\"\t\t/* def_cfa_offset */\n#if LJ_64\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n\t\"\\t.byte 0x8f\\n\\t.uleb128 0x4\\n\"\t/* offset r15 */\n\t\"\\t.byte 0x8e\\n\\t.uleb128 0x5\\n\"\t/* offset r14 */\n#else\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0x87\\n\\t.uleb128 0x3\\n\"\t/* offset edi */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x4\\n\"\t/* offset esi */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x5\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE2:\\n\\n\", fcofs, CFRAME_SIZE);\n#if LJ_HASFFI\n    fprintf(ctx->fp,\n\t\".Lframe2:\\n\"\n\t\"\\t.long .LECIE2-.LSCIE2\\n\"\n\t\".LSCIE2:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.string \\\"zR\\\"\\n\"\n\t\"\\t.uleb128 0x1\\n\"\n\t\"\\t.sleb128 -\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.uleb128 1\\n\"\t\t\t/* augmentation length */\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.uleb128 \" REG_SP \"\\n\\t.uleb128 \" SZPTR \"\\n\"\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.uleb128 0x1\\n\"\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LECIE2:\\n\\n\");\n    fprintf(ctx->fp,\n\t\".LSFDE3:\\n\"\n\t\"\\t.long .LEFDE3-.LASFDE3\\n\"\n\t\".LASFDE3:\\n\"\n\t\"\\t.long .LASFDE3-.Lframe2\\n\"\n\t\"\\t.long lj_vm_ffi_call-.\\n\"\n\t\"\\t.long %d\\n\"\n\t\"\\t.uleb128 0\\n\"\t\t\t/* augmentation length */\n#if LJ_64\n\t\"\\t.byte 0xe\\n\\t.uleb128 16\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x86\\n\\t.uleb128 0x2\\n\"\t/* offset rbp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset rbx */\n#else\n\t\"\\t.byte 0xe\\n\\t.uleb128 8\\n\"\t\t/* def_cfa_offset */\n\t\"\\t.byte 0x85\\n\\t.uleb128 0x2\\n\"\t/* offset ebp */\n\t\"\\t.byte 0xd\\n\\t.uleb128 0x5\\n\"\t\t/* def_cfa_register ebp */\n\t\"\\t.byte 0x83\\n\\t.uleb128 0x3\\n\"\t/* offset ebx */\n#endif\n\t\"\\t.align \" SZPTR \"\\n\"\n\t\".LEFDE3:\\n\\n\", (int)ctx->codesz - fcofs);\n#endif\n#endif\n    break;\n#if !LJ_NO_UNWIND\n  /* Mental note: never let Apple design an assembler.\n  ** Or a linker. Or a plastic case. But I digress.\n  */\n  case BUILD_machasm: {\n#if LJ_HASFFI\n    int fcsize = 0;\n#endif\n    int i;\n    fprintf(ctx->fp, \"\\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\\n\");\n    fprintf(ctx->fp,\n\t\"EH_frame1:\\n\"\n\t\"\\t.set L$set$x,LECIEX-LSCIEX\\n\"\n\t\"\\t.long L$set$x\\n\"\n\t\"LSCIEX:\\n\"\n\t\"\\t.long 0\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.ascii \\\"zPR\\\\0\\\"\\n\"\n\t\"\\t.byte 0x1\\n\"\n\t\"\\t.byte 128-\" SZPTR \"\\n\"\n\t\"\\t.byte \" REG_RA \"\\n\"\n\t\"\\t.byte 6\\n\"\t\t\t\t/* augmentation length */\n\t\"\\t.byte 0x9b\\n\"\t\t\t/* indirect|pcrel|sdata4 */\n#if LJ_64\n\t\"\\t.long _lj_err_unwind_dwarf+4@GOTPCREL\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte \" REG_SP \"\\n\\t.byte \" SZPTR \"\\n\"\n#else\n\t\"\\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\\n\"\n\t\"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t\"\\t.byte 0xc\\n\\t.byte 0x5\\n\\t.byte 0x4\\n\"  /* esp=5 on 32 bit MACH-O. */\n#endif\n\t\"\\t.byte 0x80+\" REG_RA \"\\n\\t.byte 0x1\\n\"\n\t\"\\t.align \" BSZPTR \"\\n\"\n\t\"LECIEX:\\n\\n\");\n    for (i = 0; i < ctx->nsym; i++) {\n      const char *name = ctx->sym[i].name;\n      int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;\n      if (size == 0) continue;\n#if LJ_HASFFI\n      if (!strcmp(name, \"_lj_vm_ffi_call\")) { fcsize = size; continue; }\n#endif\n      fprintf(ctx->fp,\n\t  \"%s.eh:\\n\"\n\t  \"LSFDE%d:\\n\"\n\t  \"\\t.set L$set$%d,LEFDE%d-LASFDE%d\\n\"\n\t  \"\\t.long L$set$%d\\n\"\n\t  \"LASFDE%d:\\n\"\n\t  \"\\t.long LASFDE%d-EH_frame1\\n\"\n\t  \"\\t.long %s-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n\t  \"\\t.byte 0xe\\n\\t.byte %d\\n\"\t\t/* def_cfa_offset */\n#if LJ_64\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n\t  \"\\t.byte 0x8f\\n\\t.byte 0x4\\n\"\t\t/* offset r15 */\n\t  \"\\t.byte 0x8e\\n\\t.byte 0x5\\n\"\t\t/* offset r14 */\n#else\n\t  \"\\t.byte 0x84\\n\\t.byte 0x2\\n\"\t\t/* offset ebp (4 for MACH-O)*/\n\t  \"\\t.byte 0x87\\n\\t.byte 0x3\\n\"\t\t/* offset edi */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x4\\n\"\t\t/* offset esi */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x5\\n\"\t\t/* offset ebx */\n#endif\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LEFDE%d:\\n\\n\",\n\t  name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);\n    }\n#if LJ_HASFFI\n    if (fcsize) {\n      fprintf(ctx->fp,\n\t  \"EH_frame2:\\n\"\n\t  \"\\t.set L$set$y,LECIEY-LSCIEY\\n\"\n\t  \"\\t.long L$set$y\\n\"\n\t  \"LSCIEY:\\n\"\n\t  \"\\t.long 0\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.ascii \\\"zR\\\\0\\\"\\n\"\n\t  \"\\t.byte 0x1\\n\"\n\t  \"\\t.byte 128-\" SZPTR \"\\n\"\n\t  \"\\t.byte \" REG_RA \"\\n\"\n\t  \"\\t.byte 1\\n\"\t\t\t\t/* augmentation length */\n#if LJ_64\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte \" REG_SP \"\\n\\t.byte \" SZPTR \"\\n\"\n#else\n\t  \"\\t.byte 0x1b\\n\"\t\t\t/* pcrel|sdata4 */\n\t  \"\\t.byte 0xc\\n\\t.byte 0x5\\n\\t.byte 0x4\\n\"  /* esp=5 on 32 bit MACH. */\n#endif\n\t  \"\\t.byte 0x80+\" REG_RA \"\\n\\t.byte 0x1\\n\"\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LECIEY:\\n\\n\");\n      fprintf(ctx->fp,\n\t  \"_lj_vm_ffi_call.eh:\\n\"\n\t  \"LSFDEY:\\n\"\n\t  \"\\t.set L$set$yy,LEFDEY-LASFDEY\\n\"\n\t  \"\\t.long L$set$yy\\n\"\n\t  \"LASFDEY:\\n\"\n\t  \"\\t.long LASFDEY-EH_frame2\\n\"\n\t  \"\\t.long _lj_vm_ffi_call-.\\n\"\n\t  \"\\t.long %d\\n\"\n\t  \"\\t.byte 0\\n\"\t\t\t\t/* augmentation length */\n#if LJ_64\n\t  \"\\t.byte 0xe\\n\\t.byte 16\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x86\\n\\t.byte 0x2\\n\"\t\t/* offset rbp */\n\t  \"\\t.byte 0xd\\n\\t.byte 0x6\\n\"\t\t/* def_cfa_register rbp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset rbx */\n#else\n\t  \"\\t.byte 0xe\\n\\t.byte 8\\n\"\t\t/* def_cfa_offset */\n\t  \"\\t.byte 0x84\\n\\t.byte 0x2\\n\"\t\t/* offset ebp (4 for MACH-O)*/\n\t  \"\\t.byte 0xd\\n\\t.byte 0x4\\n\"\t\t/* def_cfa_register ebp */\n\t  \"\\t.byte 0x83\\n\\t.byte 0x3\\n\"\t\t/* offset ebx */\n#endif\n\t  \"\\t.align \" BSZPTR \"\\n\"\n\t  \"LEFDEY:\\n\\n\", fcsize);\n    }\n#endif\n#if !LJ_64\n    fprintf(ctx->fp,\n      \"\\t.non_lazy_symbol_pointer\\n\"\n      \"L_lj_err_unwind_dwarf$non_lazy_ptr:\\n\"\n      \".indirect_symbol _lj_err_unwind_dwarf\\n\"\n      \".long 0\\n\\n\");\n    fprintf(ctx->fp, \"\\t.section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5\\n\");\n    {\n      const char *const *xn;\n      for (xn = ctx->extnames; *xn; xn++)\n\tif (strncmp(*xn, LABEL_PREFIX, sizeof(LABEL_PREFIX)-1))\n\t  fprintf(ctx->fp, \"L_%s$stub:\\n\\t.indirect_symbol _%s\\n\\t.ascii \\\"\\\\364\\\\364\\\\364\\\\364\\\\364\\\"\\n\", *xn, *xn);\n    }\n#endif\n    fprintf(ctx->fp, \".subsections_via_symbols\\n\");\n    }\n    break;\n#endif\n  default:  /* Difficult for other modes. */\n    break;\n  }\n}\n\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/Makefile",
    "content": ".PHONY: default test benchmark clean\n\ndefault:\n\t@echo \"make target include: test bechmark clean\"\n\ntest:\n\t$(MAKE) -C test test\n\nbenchmark:\n\t$(MAKE) -C test benchmark\n\nclean:\n\t$(MAKE) -C test clean\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/src/lj_str_hash_x64.h",
    "content": "/*\n * This file defines string hash function using CRC32. It takes advantage of\n * Intel hardware support (crc32 instruction, SSE 4.2) to speedup the CRC32\n * computation. The hash functions try to compute CRC32 of length and up\n * to 128 bytes of given string.\n */\n\n#ifndef _LJ_STR_HASH_X64_H_\n#define _LJ_STR_HASH_X64_H_\n\n#if defined(__SSE4_2__) && defined(__x86_64) && defined(__GNUC__)\n\n#include <stdint.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <time.h>\n#include <smmintrin.h>\n\n#include \"../../lj_def.h\"\n\n#undef LJ_AINLINE\n#define LJ_AINLINE\n\n#ifdef __MINGW32__\n#define random()  ((long) rand())\n#define srandom(seed)  srand(seed)\n#endif\n\nstatic const uint64_t* cast_uint64p(const char* str)\n{\n  return (const uint64_t*)(void*)str;\n}\n\nstatic const uint32_t* cast_uint32p(const char* str)\n{\n  return (const uint32_t*)(void*)str;\n}\n\n/* hash string with len in [1, 4) */\nstatic LJ_AINLINE uint32_t lj_str_hash_1_4(const char* str, uint32_t len)\n{\n#if 0\n  /* TODO: The if-1 part (i.e the original algorithm) is working better when\n   * the load-factor is high, as revealed by conflict benchmark (via\n   * 'make benchmark' command); need to understand why it's so.\n   */\n  uint32_t v = str[0];\n  v = (v << 8) | str[len >> 1];\n  v = (v << 8) | str[len - 1];\n  v = (v << 8) | len;\n  return _mm_crc32_u32(0, v);\n#else\n  uint32_t a, b, h = len;\n\n  a = *(const uint8_t *)str;\n  h ^= *(const uint8_t *)(str+len-1);\n  b = *(const uint8_t *)(str+(len>>1));\n  h ^= b; h -= lj_rol(b, 14);\n\n  a ^= h; a -= lj_rol(h, 11);\n  b ^= a; b -= lj_rol(a, 25);\n  h ^= b; h -= lj_rol(b, 16);\n\n  return h;\n#endif\n}\n\n/* hash string with len in [4, 16) */\nstatic LJ_AINLINE uint32_t lj_str_hash_4_16(const char* str, uint32_t len)\n{\n  uint64_t v1, v2, h;\n\n  if (len >= 8) {\n    v1 = *cast_uint64p(str);\n    v2 = *cast_uint64p(str + len - 8);\n  } else {\n    v1 = *cast_uint32p(str);\n    v2 = *cast_uint32p(str + len - 4);\n  }\n\n  h = _mm_crc32_u32(0, len);\n  h = _mm_crc32_u64(h, v1);\n  h = _mm_crc32_u64(h, v2);\n  return h;\n}\n\n/* hash string with length in [16, 128) */\nstatic uint32_t lj_str_hash_16_128(const char* str, uint32_t len)\n{\n  uint64_t h1, h2;\n  uint32_t i;\n\n  h1 = _mm_crc32_u32(0, len);\n  h2 = 0;\n\n  for (i = 0; i < len - 16; i += 16) {\n    h1 += _mm_crc32_u64(h1, *cast_uint64p(str + i));\n    h2 += _mm_crc32_u64(h2, *cast_uint64p(str + i + 8));\n  };\n\n  h1 = _mm_crc32_u64(h1, *cast_uint64p(str + len - 16));\n  h2 = _mm_crc32_u64(h2, *cast_uint64p(str + len - 8));\n\n  return _mm_crc32_u32(h1, h2);\n}\n\n/* **************************************************************************\n *\n *  Following is code about hashing string with length >= 128\n *\n * **************************************************************************\n */\nstatic uint32_t random_pos[32][2];\nstatic const int8_t log2_tab[128] = { -1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,\n  4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,\n  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 };\n\n/* return floor(log2(n)) */\nstatic LJ_AINLINE uint32_t log2_floor(uint32_t n)\n{\n  if (n <= 127) {\n    return log2_tab[n];\n  }\n\n  if ((n >> 8) <= 127) {\n    return log2_tab[n >> 8] + 8;\n  }\n\n  if ((n >> 16) <= 127) {\n    return log2_tab[n >> 16] + 16;\n  }\n\n  if ((n >> 24) <= 127) {\n    return log2_tab[n >> 24] + 24;\n  }\n\n  return 31;\n}\n\n#define POW2_MASK(n) ((1L << (n)) - 1)\n\n/* This function is to populate `random_pos` such that random_pos[i][*]\n * contains random value in the range of [2**i, 2**(i+1)).\n */\nstatic void x64_init_random(void)\n{\n  int i, seed, rml;\n\n  /* Calculate the ceil(log2(RAND_MAX)) */\n  rml = log2_floor(RAND_MAX);\n  if (RAND_MAX & (RAND_MAX - 1)) {\n    rml += 1;\n  }\n\n  /* Init seed */\n  seed = _mm_crc32_u32(0, getpid());\n  seed = _mm_crc32_u32(seed, time(NULL));\n  srandom(seed);\n\n  /* Now start to populate the random_pos[][]. */\n  for (i = 0; i < 3; i++) {\n    /* No need to provide random value for chunk smaller than 8 bytes */\n    random_pos[i][0] = random_pos[i][1] = 0;\n  }\n\n  for (; i < rml; i++) {\n    random_pos[i][0] = random() & POW2_MASK(i+1);\n    random_pos[i][1] = random() & POW2_MASK(i+1);\n  }\n\n  for (; i < 31; i++) {\n    int j;\n    for (j = 0; j < 2; j++) {\n      uint32_t v, scale;\n      scale = random_pos[i - rml][0];\n      if (scale == 0) {\n        scale = 1;\n      }\n      v = (random() * scale) & POW2_MASK(i+1);\n      random_pos[i][j] = v;\n    }\n  }\n}\n#undef POW2_MASK\n\nvoid __attribute__((constructor)) x64_init_random_constructor()\n{\n    x64_init_random();\n}\n\n/* Return a pre-computed random number in the range of [1**chunk_sz_order,\n * 1**(chunk_sz_order+1)). It is \"unsafe\" in the sense that the return value\n * may be greater than chunk-size; it is up to the caller to make sure\n * \"chunk-base + return-value-of-this-func\" has valid virtual address.\n */\nstatic LJ_AINLINE uint32_t get_random_pos_unsafe(uint32_t chunk_sz_order,\n                                                 uint32_t idx)\n{\n  uint32_t pos = random_pos[chunk_sz_order][idx & 1];\n  return pos;\n}\n\nstatic LJ_NOINLINE uint32_t lj_str_hash_128_above(const char* str,\n    uint32_t len)\n{\n  uint32_t chunk_num, chunk_sz, chunk_sz_log2, i, pos1, pos2;\n  uint64_t h1, h2, v;\n  const char* chunk_ptr;\n\n  chunk_num = 16;\n  chunk_sz = len / chunk_num;\n  chunk_sz_log2 = log2_floor(chunk_sz);\n\n  pos1 = get_random_pos_unsafe(chunk_sz_log2, 0);\n  pos2 = get_random_pos_unsafe(chunk_sz_log2, 1);\n\n  h1 = _mm_crc32_u32(0, len);\n  h2 = 0;\n\n  /* loop over 14 chunks, 2 chunks at a time */\n  for (i = 0, chunk_ptr = str; i < (chunk_num / 2 - 1);\n       chunk_ptr += chunk_sz, i++) {\n\n    v = *cast_uint64p(chunk_ptr + pos1);\n    h1 = _mm_crc32_u64(h1, v);\n\n    v = *cast_uint64p(chunk_ptr + chunk_sz + pos2);\n    h2 = _mm_crc32_u64(h2, v);\n  }\n\n  /* the last two chunks */\n  v = *cast_uint64p(chunk_ptr + pos1);\n  h1 = _mm_crc32_u64(h1, v);\n\n  v = *cast_uint64p(chunk_ptr + chunk_sz - 8 - pos2);\n  h2 = _mm_crc32_u64(h2, v);\n\n  /* process the trailing part */\n  h1 = _mm_crc32_u64(h1, *cast_uint64p(str));\n  h2 = _mm_crc32_u64(h2, *cast_uint64p(str + len - 8));\n\n  h1 = _mm_crc32_u32(h1, h2);\n  return h1;\n}\n\n/* NOTE: the \"len\" should not be zero */\nstatic LJ_AINLINE uint32_t lj_str_hash(const char* str, size_t len)\n{\n  if (len < 128) {\n    if (len >= 16) { /* [16, 128) */\n      return lj_str_hash_16_128(str, len);\n    }\n\n    if (len >= 4) { /* [4, 16) */\n      return lj_str_hash_4_16(str, len);\n    }\n\n    /* [0, 4) */\n    return lj_str_hash_1_4(str, len);\n  }\n  /* [128, inf) */\n  return lj_str_hash_128_above(str, len);\n}\n\n#define LJ_ARCH_STR_HASH lj_str_hash\n#else\n#undef LJ_ARCH_STR_HASH\n#endif\n#endif /*_LJ_STR_HASH_X64_H_*/\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/Makefile",
    "content": ".PHONY: default test benchmark\n\ndefault: test benchmark\n\nCOMMON_OBJ := test_util.o\n\nTEST_PROGRAM := ht_test\nBENCHMARK_PROGRAM := ht_benchmark\n\nTEST_PROGRAM_OBJ := $(COMMON_OBJ) test.o\nBENCHMARK_PROGRAM_OBJ := $(COMMON_OBJ) benchmark.o\n\nifeq ($(WITH_VALGRIND), 1)\n    VALGRIND := valgrind --leak-check=full\nelse\n    VALGRIND :=\nendif\n\nCXXFLAGS := -O3 -MD -g -msse4.2 -Wall -I../src -I../../../src\n\n%.o: %.cxx\n\t$(CXX) $(CXXFLAGS) -MD -c $<\n\ntest: $(TEST_PROGRAM)\n\t@echo \"some unit test\"\n\t$(VALGRIND) ./$(TEST_PROGRAM)\n\t./unit_test.sh\n\n\t@echo \"smoke test\"\n\t../../luajit test_str_comp.lua\n\nbenchmark: $(BENCHMARK_PROGRAM)\n\t# micro benchmark\n\t./$(BENCHMARK_PROGRAM)\n\n$(TEST_PROGRAM) : $(TEST_PROGRAM_OBJ)\n\tcat $(TEST_PROGRAM_OBJ:.o=.d) > dep1.txt\n\t$(CXX) $+ $(CXXFLAGS) -lm -o $@\n\n$(BENCHMARK_PROGRAM): $(BENCHMARK_PROGRAM_OBJ)\n\tcat $(BENCHMARK_PROGRAM_OBJ:.o=.d) > dep2.txt\n\t$(CXX) $+ $(CXXFLAGS) -o $@\n\n-include dep1.txt\n-include dep2.txt\n\nclean:\n\t-rm -f *.o *.d dep*.txt $(BENCHMARK_PROGRAM) $(TEST_PROGRAM)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/benchmark.cxx",
    "content": "#include <sys/time.h> // for gettimeofday()\nextern \"C\" {\n#include \"lj_str_hash_x64.h\"\n}\n#include <string>\n#include <vector>\n#include <utility>\n#include <algorithm>\n#include \"test_util.hpp\"\n#include <stdio.h>\n#include <math.h>\n\nusing namespace std;\n\n#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))\n#define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))\n\nconst char* separator = \"-------------------------------------------\";\n\nstatic uint32_t LJ_AINLINE\nlj_original_hash(const char *str, size_t len)\n{\n  uint32_t a, b, h = len;\n  if (len >= 4) {\n    a = lj_getu32(str); h ^= lj_getu32(str+len-4);\n    b = lj_getu32(str+(len>>1)-2);\n    h ^= b; h -= lj_rol(b, 14);\n    b += lj_getu32(str+(len>>2)-1);\n    a ^= h; a -= lj_rol(h, 11);\n    b ^= a; b -= lj_rol(a, 25);\n    h ^= b; h -= lj_rol(b, 16);\n  } else {\n    a = *(const uint8_t *)str;\n    h ^= *(const uint8_t *)(str+len-1);\n    b = *(const uint8_t *)(str+(len>>1));\n    h ^= b; h -= lj_rol(b, 14);\n  }\n\n  a ^= h; a -= lj_rol(h, 11);\n  b ^= a; b -= lj_rol(a, 25);\n  h ^= b; h -= lj_rol(b, 16);\n\n  return h;\n}\n\ntemplate<class T> double\nBenchmarkHashTmpl(T func, char* buf, size_t len)\n{\n  TestClock timer;\n  uint32_t h = 0;\n\n  timer.start();\n  for(int i = 1; i < 1000000 * 100; i++) {\n    // So the buf is not loop invariant, hence the F(...)\n    buf[i % 4096] = i;\n    h += func(buf, len) ^ i;\n  }\n  timer.stop();\n\n  // make h alive\n  test_printf(\"%x\", h);\n  return timer.getElapseInSecond();\n}\n\nstruct TestFuncWas\n{\n  uint32_t operator()(const char* buf, uint32_t len) {\n    return lj_original_hash(buf, len);\n  }\n};\n\nstruct TestFuncIs\n{\n  uint32_t operator()(const char* buf, uint32_t len) {\n    return lj_str_hash(buf, len);\n  }\n};\n\nstatic void\nbenchmarkIndividual(char* buf)\n{\n  fprintf(stdout,\"\\n\\nCompare performance of particular len (in second)\\n\");\n  fprintf(stdout, \"%-12s%-8s%-8s%s\\n\", \"len\", \"was\", \"is\", \"diff\");\n  fprintf(stdout, \"-------------------------------------------\\n\");\n\n  uint32_t lens[] = {3, 4, 7, 10, 15, 16, 20, 32, 36, 63, 80, 100,\n                     120, 127, 280, 290, 400};\n  for (unsigned i = 0; i < sizeof(lens)/sizeof(lens[0]); i++) {\n    uint32_t len = lens[i];\n    double e1 = BenchmarkHashTmpl(TestFuncWas(), buf, len);\n    double e2 = BenchmarkHashTmpl(TestFuncIs(), buf, len);\n    fprintf(stdout, \"len = %4d: %-7.3lf %-7.3lf %.2f\\n\", len, e1, e2, (e1-e2)/e1);\n  }\n}\n\ntemplate<class T> double\nBenchmarkChangeLenTmpl(T func, char* buf, uint32_t* len_vect, uint32_t len_num)\n{\n  TestClock timer;\n  uint32_t h = 0;\n\n  timer.start();\n  for(int i = 1; i < 1000000 * 100; i++) {\n    for (int j = 0; j < (int)len_num; j++) {\n      // So the buf is not loop invariant, hence the F(...)\n      buf[(i + j) % 4096] = i;\n      h += func(buf, len_vect[j]) ^ j;\n    }\n  }\n  timer.stop();\n\n  // make h alive\n  test_printf(\"%x\", h);\n  return timer.getElapseInSecond();\n}\n\n// It is to measure the performance when length is changing.\n// The purpose is to see how balanced branches impact the performance.\n//\nstatic void\nbenchmarkToggleLens(char* buf)\n{\n  double e1, e2;\n  fprintf(stdout,\"\\nChanging length (in second):\");\n  fprintf(stdout, \"\\n%-20s%-8s%-8s%s\\n%s\\n\", \"len\", \"was\", \"is\", \"diff\",\n          separator);\n\n  uint32_t lens1[] = {4, 9};\n  e1 = BenchmarkChangeLenTmpl(TestFuncWas(), buf, lens1, 2);\n  e2 = BenchmarkChangeLenTmpl(TestFuncIs(), buf, lens1, 2);\n  fprintf(stdout, \"%-20s%-7.3lf %-7.3lf %.2f\\n\", \"4,9\", e1, e2, (e1-e2)/e1);\n\n  uint32_t lens2[] = {1, 4, 9};\n  e1 = BenchmarkChangeLenTmpl(TestFuncWas(), buf, lens2, 3);\n  e2 = BenchmarkChangeLenTmpl(TestFuncIs(), buf, lens2, 3);\n  fprintf(stdout, \"%-20s%-7.3lf %-7.3lf %.2f\\n\", \"1,4,9\", e1, e2, (e1-e2)/e1);\n\n  uint32_t lens3[] = {1, 33, 4, 9};\n  e1 = BenchmarkChangeLenTmpl(TestFuncWas(), buf, lens3, 4);\n  e2 = BenchmarkChangeLenTmpl(TestFuncIs(), buf, lens3, 4);\n  fprintf(stdout, \"%-20s%-7.3lf %-7.3lf %.2f\\n\", \"1,33,4,9\",\n          e1, e2, (e1-e2)/e1);\n}\n\nstatic void\ngenRandomString(uint32_t min, uint32_t max,\n                uint32_t num, vector<string>& result)\n{\n  double scale = (max - min) / (RAND_MAX + 1.0);\n  result.clear();\n  result.reserve(num);\n  for (uint32_t i = 0; i < num; i++) {\n    uint32_t len = (rand() * scale) + min;\n\n    char* buf = new char[len];\n    for (uint32_t l = 0; l < len; l++) {\n      buf[l] = rand() % 255;\n    }\n    result.push_back(string(buf, len));\n    delete[] buf;\n  }\n}\n\n// Return the standard deviation of given array of number\nstatic double\nstandarDeviation(const vector<uint32_t>& v)\n{\n  uint64_t total = 0;\n  for (vector<uint32_t>::const_iterator i = v.begin(), e = v.end();\n      i != e; ++i) {\n    total += *i;\n  }\n\n  double avg = total / (double)v.size();\n  double sd = 0;\n\n  for (vector<uint32_t>::const_iterator i = v.begin(), e = v.end();\n       i != e; ++i) {\n    double t = avg - *i;\n    sd = sd + t*t;\n  }\n\n  return sqrt(sd/v.size());\n}\n\nstatic pair<double, double>\nbenchmarkConflictHelper(uint32_t bucketNum, const vector<string>& strs)\n{\n  if (bucketNum & (bucketNum - 1)) {\n    bucketNum = (1L << (log2_floor(bucketNum) + 1));\n  }\n  uint32_t mask = bucketNum - 1;\n\n  vector<uint32_t> conflictWas(bucketNum);\n  vector<uint32_t> conflictIs(bucketNum);\n\n  conflictWas.resize(bucketNum);\n  conflictIs.resize(bucketNum);\n\n  for (vector<string>::const_iterator i = strs.begin(), e = strs.end();\n       i != e; ++i) {\n    uint32_t h1 = lj_original_hash(i->c_str(), i->size());\n    uint32_t h2 = lj_str_hash(i->c_str(), i->size());\n\n    conflictWas[h1 & mask]++;\n    conflictIs[h2 & mask]++;\n  }\n\n#if 0\n  std::sort(conflictWas.begin(), conflictWas.end(), std::greater<int>());\n  std::sort(conflictIs.begin(), conflictIs.end(), std::greater<int>());\n\n  fprintf(stderr, \"%d %d %d %d vs %d %d %d %d\\n\",\n          conflictWas[0], conflictWas[1], conflictWas[2], conflictWas[3],\n          conflictIs[0], conflictIs[1], conflictIs[2], conflictIs[3]);\n#endif\n\n  return pair<double, double>(standarDeviation(conflictWas),\n                              standarDeviation(conflictIs));\n}\n\nstatic void\nbenchmarkConflict()\n{\n  srand(time(0));\n\n  float loadFactor[] = { 0.5f, 1.0f, 2.0f, 4.0f, 8.0f };\n  int bucketNum[] = { 512, 1024, 2048, 4096, 8192, 16384};\n  int lenRange[][2] = { {1,3}, {4, 15}, {16, 127}, {128, 1024}, {1, 1024}};\n\n  fprintf(stdout,\n          \"\\nBechmarking conflict (stand deviation of conflict)\\n%s\\n\",\n          separator);\n\n  for (uint32_t k = 0; k < sizeof(lenRange)/sizeof(lenRange[0]); k++) {\n    fprintf(stdout, \"\\nlen range from %d - %d\\n\", lenRange[k][0],\n            lenRange[k][1]);\n    fprintf(stdout, \"%-10s %-12s %-10s %-10s diff\\n%s\\n\",\n            \"bucket\", \"load-factor\", \"was\", \"is\", separator);\n    for (uint32_t i = 0; i < sizeof(bucketNum)/sizeof(bucketNum[0]); ++i) {\n      for (uint32_t j = 0;\n           j < sizeof(loadFactor)/sizeof(loadFactor[0]);\n           ++j) {\n        int strNum = bucketNum[i] * loadFactor[j];\n        vector<string> strs(strNum);\n        genRandomString(lenRange[k][0], lenRange[k][1], strNum, strs);\n\n        pair<double, double> p;\n        p = benchmarkConflictHelper(bucketNum[i], strs);\n        fprintf(stdout, \"%-10d %-12.2f %-10.2f %-10.2f %.2f\\n\",\n                bucketNum[i], loadFactor[j], p.first, p.second,\n                p.first - p.second);\n      }\n    }\n  }\n}\n\nstatic void\nbenchmarkHashFunc()\n{\n  char buf[4096];\n  char c = getpid() % 'a';\n  for (int i = 0; i < (int)sizeof(buf); i++) {\n    buf[i] = (c + i) % 255;\n  }\n\n  benchmarkConflict();\n  benchmarkIndividual(buf);\n  benchmarkToggleLens(buf);\n}\n\nint\nmain(int argc, char** argv)\n{\n  fprintf(stdout, \"========================\\nMicro benchmark...\\n\");\n  benchmarkHashFunc();\n  return 0;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/test.cpp",
    "content": "#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <map>\n#include \"test_util.hpp\"\n#include \"lj_str_hash_x64.h\"\n\nusing namespace std;\n\nstatic bool\nsmoke_test()\n{\n  fprintf(stdout, \"running smoke tests...\\n\");\n\tchar buf[1024];\n  char c = getpid() % 'a';\n\n  for (int i = 0; i < (int)sizeof(buf); i++) {\n    buf[i] = (c + i) % 255;\n  }\n\n  uint32_t lens[] = {3, 4, 5, 7, 8, 16, 17, 24, 25, 32, 33, 127, 128,\n                     255, 256, 257};\n  for (unsigned i = 0; i < sizeof(lens)/sizeof(lens[0]); i++) {\n    string s(buf, lens[i]);\n    test_printf(\"%d\", lj_str_hash(s.c_str(), lens[i]));\n  }\n\n  return true;\n}\n\nstatic bool\nverify_log2()\n{\n  fprintf(stdout, \"verify log2...\\n\");\n  bool err = false;\n  std::map<uint32_t, uint32_t> lm;\n  lm[0] =(uint32_t)-1;\n  lm[1] = 0;\n  lm[2] = 1;\n  for (int i = 2; i < 31; i++) {\n    lm[(1<<i) - 2] = i - 1;\n    lm[(1<<i) - 1] = i - 1;\n    lm[1<<i] = i;\n    lm[(1<<i) + 1] = i;\n  }\n  lm[(uint32_t)-1] = 31;\n\n  for (map<uint32_t, uint32_t>::iterator iter = lm.begin(), iter_e = lm.end();\n       iter != iter_e; ++iter) {\n    uint32_t v = (*iter).first;\n    uint32_t log2_expect = (*iter).second;\n    uint32_t log2_get = log2_floor(v);\n    if (log2_expect != log2_get) {\n      err = true;\n      fprintf(stderr, \"log2(%u) expect %u, get %u\\n\", v, log2_expect, log2_get);\n      exit(1);\n    }\n  }\n  return !err;\n}\n\nint\nmain(int argc, char** argv)\n{\n  fprintf(stdout, \"=======================\\nRun unit testing...\\n\");\n\n  ASSERT(smoke_test(), \"smoke_test test failed\");\n  ASSERT(verify_log2(), \"log2 failed\");\n\n  fprintf(stdout, TestErrMsgMgr::noError() ? \"succ\\n\\n\" : \"fail\\n\\n\");\n\n  return TestErrMsgMgr::noError() ? 0 : -1;\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/test_str_comp.lua",
    "content": "--[[\n Given two content-idental string s1, s2, test if they end up to be the\n same string object. The purpose of this test is to make sure hash function\n do not accidently include extraneous bytes before and after the string in\n question.\n]]\n\nlocal ffi = require(\"ffi\")\nlocal C = ffi.C\n\nffi.cdef[[\n    void free(void*);\n    char* malloc(size_t);\n    void *memset(void*, int, size_t);\n    void *memcpy(void*, void*, size_t);\n    long time(void*);\n    void srandom(unsigned);\n    long random(void);\n]]\n\n\nlocal function test_equal(len_min, len_max)\n    -- source string is wrapped by 16-byte-junk both before and after the\n    -- string\n    local x = C.random()\n    local l = len_min + x % (len_max - len_min);\n    local buf_len = tonumber(l + 16 * 2)\n\n    local src_buf = C.malloc(buf_len)\n    for i = 0, buf_len - 1 do\n        src_buf[i] = C.random() % 255\n    end\n\n    -- dest string is the clone of the source string, but it is sandwiched\n    -- by different junk bytes\n    local dest_buf = C.malloc(buf_len)\n    C.memset(dest_buf, 0x5a, buf_len)\n\n    local ofst = 8 + (C.random() % 8)\n    C.memcpy(dest_buf + ofst, src_buf + 16, l);\n\n    local str1 = ffi.string(src_buf + 16, l)\n    local str2 = ffi.string(dest_buf + ofst, l)\n\n    C.free(src_buf)\n    C.free(dest_buf)\n\n    if str1 ~= str2 then\n        -- Oops, look like hash function mistakenly include extraneous bytes\n        -- close to the string\n        return 1 -- wtf\n    end\nend\n\n--local lens = {1, 4, 16, 128, 1024}\nlocal lens = {128, 1024}\nlocal iter = 1000\n\nfor i = 1, #lens - 1 do\n    for j = 1, iter do\n        if test_equal(lens[i], lens[i+1]) ~= nil then\n            os.exit(1)\n        end\n    end\nend\n\nos.exit(0)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/test_util.cxx",
    "content": "#include <stdarg.h>\n#include <stdio.h>\n#include \"test_util.hpp\"\n\nusing namespace std;\n\nstd::vector<TestErrMsg> TestErrMsgMgr::_errMsg;\n\nvoid\ntest_printf(const char* format, ...)\n{\n  va_list args;\n  va_start (args, format);\n\n  FILE* devNull = fopen(\"/dev/null\", \"w\");\n  if (devNull != 0) {\n    (void)vfprintf (devNull, format, args);\n  }\n  fclose(devNull);\n  va_end (args);\n}\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/test_util.hpp",
    "content": "#ifndef _TEST_UTIL_HPP_\n#define _TEST_UTIL_HPP_\n\n#include <sys/time.h> // gettimeofday()\n#include <string>\n#include <vector>\n\nstruct TestErrMsg\n{\n  const char* fileName;\n  unsigned lineNo;\n  std::string errMsg;\n\n  TestErrMsg(const char* FN, unsigned LN, const char* Err):\n             fileName(FN), lineNo(LN), errMsg(Err) {}\n};\n\nclass TestErrMsgMgr\n{\npublic:\n  static std::vector<TestErrMsg> getError();\n  static void\n  addError(const char* fileName, unsigned lineNo, const char* Err) {\n    _errMsg.push_back(TestErrMsg(fileName, lineNo, Err));\n  }\n\n  static bool noError() {\n    return _errMsg.empty();\n  }\n\nprivate:\n  static std::vector<TestErrMsg> _errMsg;\n};\n\n#define ASSERT(c, e) \\\n  if (!(c)) { TestErrMsgMgr::addError(__FILE__, __LINE__, (e)); }\n\nclass TestClock\n{\npublic:\n  void start() { gettimeofday(&_start, 0); }\n  void stop() { gettimeofday(&_end, 0); }\n  double getElapseInSecond() {\n    return (_end.tv_sec - _start.tv_sec)\n            + ((long)_end.tv_usec - (long)_start.tv_usec) / 1000000.0;\n  }\n\nprivate:\n  struct timeval _start, _end;\n};\n\n// write to /dev/null, the only purpose is to make the data fed to the\n// function alive.\nextern void test_printf(const char* format, ...)\n  __attribute__ ((format (printf, 1, 2)));\n\n#endif //_TEST_UTIL_HPP_\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/unit/ffi/test_abi.lua",
    "content": "local ffi = require \"ffi\"\n\n-- TODO: test \"gc64\" and \"win\" parameters\nassert((ffi.abi(\"32bit\") or ffi.abi(\"64bit\"))\n        and ffi.abi(\"le\")\n        and not ffi.abi(\"be\")\n        and ffi.abi(\"fpu\")\n        and not ffi.abi(\"softfp\")\n        and ffi.abi(\"hardfp\")\n        and not ffi.abi(\"eabi\"))\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/unit/ffi/test_line_directive.lua",
    "content": "local x = [=[\nlocal ffi = require \"ffi\"\n\nffi.cdef [[\n    #line 100\n    typedef Int xxx\n]]\n]=]\n\nlocal function foo()\n    loadstring(x)()\nend\n\nlocal r, e = pcall(foo)\nassert(string.find(e, \"declaration specifier expected near 'Int' at line 100\") ~= nil)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/unit/ffi/test_pragma_pack_pushpop.lua",
    "content": "local ffi = require \"ffi\"\n\nffi.cdef[[\n#pragma pack(push, 1)\ntypedef struct {\n    char x;\n    double y;\n} foo;\n#pragma pack(pop)\n]]\n\nassert(ffi.sizeof(\"foo\") == 9)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/unit/ffi/test_var_attribute.lua",
    "content": "local ffi = require \"ffi\"\n\nffi.cdef[[\ntypedef struct { int a; char b; } __attribute__((packed)) myty1;\ntypedef struct { int a; char b; } __attribute__((__packed__)) myty1_a;\n\ntypedef struct { int a; char b; } __attribute__((aligned(16))) myty2_a;\ntypedef struct { int a; char b; } __attribute__((__aligned__(16))) myty2;\n\ntypedef int __attribute__ ((vector_size (32))) myty3;\ntypedef int __attribute__ ((__vector_size__ (32))) myty3_a;\n\ntypedef int __attribute__ ((mode(DI))) myty4;\n]]\n\nassert(ffi.sizeof(\"myty1\") == 5 and\n       ffi.sizeof(\"myty1_a\") == 5 and\n       ffi.alignof(\"myty2\") == 16 and\n       ffi.alignof(\"myty2_a\") == 16 and\n       ffi.sizeof(\"myty3\") == 32 and\n       ffi.sizeof(\"myty3_a\") == 32 and\n       ffi.sizeof(\"myty4\") == 8)\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/x64/test/unit_test.sh",
    "content": "#!/bin/sh\nDIR=$(cd $(dirname $0); pwd)\ncd $DIR\n\nLUAJIT=$DIR/../../luajit\nHASERR=0\n\nfind $DIR/unit -name \"*.lua\" -print | while read x; do\n    $LUAJIT $x >/dev/null 2>/dev/null\n    if [ $? -eq 0 ]; then\n        echo \"$x ok\"\n    else\n        HASERR=1\n        echo \"$x failed\"\n    fi\ndone\n\nif [ $HASERR -eq 0 ]; then\n    exit 0\nfi\n\nexit 1\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/xb1build.bat",
    "content": "@rem Script to build LuaJIT with the Xbox One SDK.\r\n@rem Donated to the public domain.\r\n@rem\r\n@rem Open a \"Visual Studio .NET Command Prompt\" (64 bit host compiler)\r\n@rem Then cd to this directory and run this script.\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n@if not defined DurangoXDK goto :FAIL\r\n\r\n@setlocal\r\n@echo ---- Host compiler ----\r\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@rem Error out for 64 bit host compiler\r\n@minilua\r\n@if not errorlevel 8 goto :FAIL\r\n\r\n@set DASMFLAGS=-D WIN -D FFI -D P64\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_x64.dasc\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% /D_DURANGO host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m peobj -o lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@echo ---- Cross compiler ----\r\n\r\n@set CWD=%cd%\r\n@call \"%DurangoXDK%\\xdk\\DurangoVars.cmd\" XDK\r\n@cd /D \"%CWD%\"\r\n@shift\r\n\r\n@set LJCOMPILE=\"cl\" /nologo /c /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /D_LIB /D_UNICODE /D_DURANGO\r\n@set LJLIB=\"lib\" /nologo\r\n\r\n@if \"%1\"==\"debug\" (\r\n  @shift\r\n  @set LJCOMPILE=%LJCOMPILE% /Zi /MDd /Od\r\n  @set LJLINK=%LJLINK% /debug \r\n) else (\r\n  @set LJCOMPILE=%LJCOMPILE% /MD /O2 /DNDEBUG\r\n)\r\n\r\n@if \"%1\"==\"amalg\" goto :AMALG\r\n%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:luajit.lib lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :NOAMALG\r\n:AMALG\r\n%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:luajit.lib ljamalg.obj lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\n:NOAMALG\r\n\r\n@del *.obj *.manifest minilua.exe buildvm.exe\r\n@echo.\r\n@echo === Successfully built LuaJIT for Xbox One ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\r\n@goto :END\r\n:FAIL\r\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\r\n@echo (64 bit host compiler). The Xbox One SDK must be installed, too.\r\n:END\r\n"
  },
  {
    "path": "build/luajit-2.1.0b3/src/xedkbuild.bat",
    "content": "@rem Script to build LuaJIT with the Xbox 360 SDK.\r\n@rem Donated to the public domain.\r\n@rem\r\n@rem Open a \"Visual Studio .NET Command Prompt\" (32 bit host compiler)\r\n@rem Then cd to this directory and run this script.\r\n\r\n@if not defined INCLUDE goto :FAIL\r\n@if not defined XEDK goto :FAIL\r\n\r\n@setlocal\r\n@rem ---- Host compiler ----\r\n@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r\n@set LJLINK=link /nologo\r\n@set LJMT=mt /nologo\r\n@set DASMDIR=..\\dynasm\r\n@set DASM=%DASMDIR%\\dynasm.lua\r\n@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c\r\n\r\n%LJCOMPILE% host\\minilua.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:minilua.exe minilua.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist minilua.exe.manifest^\r\n  %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r\n\r\n@rem Error out for 64 bit host compiler\r\n@minilua\r\n@if errorlevel 8 goto :FAIL\r\n\r\n@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM\r\nminilua %DASM% -LN %DASMFLAGS% -o host\\buildvm_arch.h vm_ppc.dasc\r\n@if errorlevel 1 goto :BAD\r\n\r\n%LJCOMPILE% /I \".\" /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC  host\\buildvm*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLINK% /out:buildvm.exe buildvm*.obj\r\n@if errorlevel 1 goto :BAD\r\nif exist buildvm.exe.manifest^\r\n  %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r\n\r\nbuildvm -m peobj -o lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m libdef -o lj_libdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m recdef -o lj_recdef.h %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m vmdef -o jit\\vmdef.lua %ALL_LIB%\r\n@if errorlevel 1 goto :BAD\r\nbuildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r\n@if errorlevel 1 goto :BAD\r\n\r\n@rem ---- Cross compiler ----\r\n@set LJCOMPILE=\"%XEDK%\\bin\\win32\\cl\" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC\r\n@set LJLIB=\"%XEDK%\\bin\\win32\\lib\" /nologo\r\n@set \"INCLUDE=%XEDK%\\include\\xbox\"\r\n\r\n@if \"%1\" neq \"debug\" goto :NODEBUG\r\n@shift\r\n@set \"LJCOMPILE=%LJCOMPILE% /Zi\"\r\n:NODEBUG\r\n@if \"%1\"==\"amalg\" goto :AMALG\r\n%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj\r\n@if errorlevel 1 goto :BAD\r\n@goto :NOAMALG\r\n:AMALG\r\n%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c\r\n@if errorlevel 1 goto :BAD\r\n%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj\r\n@if errorlevel 1 goto :BAD\r\n:NOAMALG\r\n\r\n@del *.obj *.manifest minilua.exe buildvm.exe\r\n@echo.\r\n@echo === Successfully built LuaJIT for Xbox 360 ===\r\n\r\n@goto :END\r\n:BAD\r\n@echo.\r\n@echo *******************************************************\r\n@echo *** Build FAILED -- Please check the error messages ***\r\n@echo *******************************************************\u0007\r\n@goto :END\r\n:FAIL\r\n@echo To run this script you must open a \"Visual Studio .NET Command Prompt\"\r\n@echo (32 bit host compiler). The Xbox 360 SDK must be installed, too.\r\n:END\r\n"
  },
  {
    "path": "build/luasocket/auxiliar.c",
    "content": "/*=========================================================================*\\\r\n* Auxiliar routines for class hierarchy manipulation\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h>\r\n#include <stdio.h>\r\n\r\n#include \"auxiliar.h\"\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes the module\r\n\\*-------------------------------------------------------------------------*/\r\nint auxiliar_open(lua_State *L) {\r\n    (void) L;\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates a new class with given methods\r\n* Methods whose names start with __ are passed directly to the metatable.\r\n\\*-------------------------------------------------------------------------*/\r\nvoid auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {\r\n    luaL_newmetatable(L, classname); /* mt */\r\n    /* create __index table to place methods */\r\n    lua_pushstring(L, \"__index\");    /* mt,\"__index\" */\r\n    lua_newtable(L);                 /* mt,\"__index\",it */ \r\n    /* put class name into class metatable */\r\n    lua_pushstring(L, \"class\");      /* mt,\"__index\",it,\"class\" */\r\n    lua_pushstring(L, classname);    /* mt,\"__index\",it,\"class\",classname */\r\n    lua_rawset(L, -3);               /* mt,\"__index\",it */\r\n    /* pass all methods that start with _ to the metatable, and all others\r\n     * to the index table */\r\n    for (; func->name; func++) {     /* mt,\"__index\",it */\r\n        lua_pushstring(L, func->name);\r\n        lua_pushcfunction(L, func->func);\r\n        lua_rawset(L, func->name[0] == '_' ? -5: -3);\r\n    }\r\n    lua_rawset(L, -3);               /* mt */\r\n    lua_pop(L, 1);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Prints the value of a class in a nice way\r\n\\*-------------------------------------------------------------------------*/\r\nint auxiliar_tostring(lua_State *L) {\r\n    char buf[32];\r\n    if (!lua_getmetatable(L, 1)) goto error;\r\n    lua_pushstring(L, \"__index\");\r\n    lua_gettable(L, -2);\r\n    if (!lua_istable(L, -1)) goto error;\r\n    lua_pushstring(L, \"class\");\r\n    lua_gettable(L, -2);\r\n    if (!lua_isstring(L, -1)) goto error;\r\n    sprintf(buf, \"%p\", lua_touserdata(L, 1));\r\n    lua_pushfstring(L, \"%s: %s\", lua_tostring(L, -1), buf);\r\n    return 1;\r\nerror:\r\n    lua_pushstring(L, \"invalid object passed to 'auxiliar.c:__tostring'\");\r\n    lua_error(L);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Insert class into group\r\n\\*-------------------------------------------------------------------------*/\r\nvoid auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) {\r\n    luaL_getmetatable(L, classname);\r\n    lua_pushstring(L, groupname);\r\n    lua_pushboolean(L, 1);\r\n    lua_rawset(L, -3);\r\n    lua_pop(L, 1);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Make sure argument is a boolean\r\n\\*-------------------------------------------------------------------------*/\r\nint auxiliar_checkboolean(lua_State *L, int objidx) {\r\n    if (!lua_isboolean(L, objidx))\r\n        auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));\r\n    return lua_toboolean(L, objidx);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Return userdata pointer if object belongs to a given class, abort with \r\n* error otherwise\r\n\\*-------------------------------------------------------------------------*/\r\nvoid *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {\r\n    void *data = auxiliar_getclassudata(L, classname, objidx);\r\n    if (!data) {\r\n        char msg[45];\r\n        sprintf(msg, \"%.35s expected\", classname);\r\n        luaL_argerror(L, objidx, msg);\r\n    }\r\n    return data;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Return userdata pointer if object belongs to a given group, abort with \r\n* error otherwise\r\n\\*-------------------------------------------------------------------------*/\r\nvoid *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {\r\n    void *data = auxiliar_getgroupudata(L, groupname, objidx);\r\n    if (!data) {\r\n        char msg[45];\r\n        sprintf(msg, \"%.35s expected\", groupname);\r\n        luaL_argerror(L, objidx, msg);\r\n    }\r\n    return data;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Set object class\r\n\\*-------------------------------------------------------------------------*/\r\nvoid auxiliar_setclass(lua_State *L, const char *classname, int objidx) {\r\n    luaL_getmetatable(L, classname);\r\n    if (objidx < 0) objidx--;\r\n    lua_setmetatable(L, objidx);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Get a userdata pointer if object belongs to a given group. Return NULL \r\n* otherwise\r\n\\*-------------------------------------------------------------------------*/\r\nvoid *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {\r\n    if (!lua_getmetatable(L, objidx))\r\n        return NULL;\r\n    lua_pushstring(L, groupname);\r\n    lua_rawget(L, -2);\r\n    if (lua_isnil(L, -1)) {\r\n        lua_pop(L, 2);\r\n        return NULL;\r\n    } else {\r\n        lua_pop(L, 2);\r\n        return lua_touserdata(L, objidx);\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Get a userdata pointer if object belongs to a given class. Return NULL \r\n* otherwise\r\n\\*-------------------------------------------------------------------------*/\r\nvoid *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {\r\n    return luaL_checkudata(L, objidx, classname);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Throws error when argument does not have correct type.\r\n* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2.\r\n\\*-------------------------------------------------------------------------*/\r\nint auxiliar_typeerror (lua_State *L, int narg, const char *tname) {\r\n  const char *msg = lua_pushfstring(L, \"%s expected, got %s\", tname, \r\n      luaL_typename(L, narg));\r\n  return luaL_argerror(L, narg, msg);\r\n}\r\n\r\n"
  },
  {
    "path": "build/luasocket/auxiliar.h",
    "content": "#ifndef AUXILIAR_H\r\n#define AUXILIAR_H\r\n/*=========================================================================*\\\r\n* Auxiliar routines for class hierarchy manipulation\r\n* LuaSocket toolkit (but completely independent of other LuaSocket modules)\r\n*\r\n* A LuaSocket class is a name associated with Lua metatables. A LuaSocket \r\n* group is a name associated with a class. A class can belong to any number \r\n* of groups. This module provides the functionality to:\r\n*\r\n*   - create new classes \r\n*   - add classes to groups \r\n*   - set the class of objects\r\n*   - check if an object belongs to a given class or group\r\n*   - get the userdata associated to objects\r\n*   - print objects in a pretty way\r\n*\r\n* LuaSocket class names follow the convention <module>{<class>}. Modules\r\n* can define any number of classes and groups. The module tcp.c, for\r\n* example, defines the classes tcp{master}, tcp{client} and tcp{server} and\r\n* the groups tcp{client,server} and tcp{any}. Module functions can then\r\n* perform type-checking on their arguments by either class or group.\r\n*\r\n* LuaSocket metatables define the __index metamethod as being a table. This\r\n* table has one field for each method supported by the class, and a field\r\n* \"class\" with the class name.\r\n*\r\n* The mapping from class name to the corresponding metatable and the\r\n* reverse mapping are done using lauxlib. \r\n\\*=========================================================================*/\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\nint auxiliar_open(lua_State *L);\r\nvoid auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);\r\nvoid auxiliar_add2group(lua_State *L, const char *classname, const char *group);\r\nvoid auxiliar_setclass(lua_State *L, const char *classname, int objidx);\r\nvoid *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);\r\nvoid *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx);\r\nvoid *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);\r\nvoid *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx);\r\nint auxiliar_checkboolean(lua_State *L, int objidx);\r\nint auxiliar_tostring(lua_State *L);\r\nint auxiliar_typeerror(lua_State *L, int narg, const char *tname);\r\n\r\n#endif /* AUXILIAR_H */\r\n"
  },
  {
    "path": "build/luasocket/buffer.c",
    "content": "/*=========================================================================*\\\r\n* Input/Output interface for Lua programs\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"buffer.h\"\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes\r\n\\*=========================================================================*/\r\nstatic int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b);\r\nstatic int recvline(p_buffer buf, luaL_Buffer *b);\r\nstatic int recvall(p_buffer buf, luaL_Buffer *b);\r\nstatic int buffer_get(p_buffer buf, const char **data, size_t *count);\r\nstatic void buffer_skip(p_buffer buf, size_t count);\r\nstatic int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent);\r\n\r\n/* min and max macros */\r\n#ifndef MIN\r\n#define MIN(x, y) ((x) < (y) ? x : y)\r\n#endif\r\n#ifndef MAX\r\n#define MAX(x, y) ((x) > (y) ? x : y)\r\n#endif\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_open(lua_State *L) {\r\n    (void) L;\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes C structure \r\n\\*-------------------------------------------------------------------------*/\r\nvoid buffer_init(p_buffer buf, p_io io, p_timeout tm) {\r\n    buf->first = buf->last = 0;\r\n    buf->io = io;\r\n    buf->tm = tm;\r\n    buf->received = buf->sent = 0;\r\n    buf->birthday = timeout_gettime();\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* object:getstats() interface\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_meth_getstats(lua_State *L, p_buffer buf) {\r\n    lua_pushnumber(L, (lua_Number) buf->received);\r\n    lua_pushnumber(L, (lua_Number) buf->sent);\r\n    lua_pushnumber(L, timeout_gettime() - buf->birthday);\r\n    return 3;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* object:setstats() interface\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_meth_setstats(lua_State *L, p_buffer buf) {\r\n    buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); \r\n    buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); \r\n    if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* object:send() interface\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_meth_send(lua_State *L, p_buffer buf) {\r\n    int top = lua_gettop(L);\r\n    int err = IO_DONE;\r\n    size_t size = 0, sent = 0;\r\n    const char *data = luaL_checklstring(L, 2, &size);\r\n    long start = (long) luaL_optnumber(L, 3, 1);\r\n    long end = (long) luaL_optnumber(L, 4, -1);\r\n#ifdef LUASOCKET_DEBUG\r\n    p_timeout tm = timeout_markstart(buf->tm);\r\n#endif\r\n    if (start < 0) start = (long) (size+start+1);\r\n    if (end < 0) end = (long) (size+end+1);\r\n    if (start < 1) start = (long) 1;\r\n    if (end > (long) size) end = (long) size;\r\n    if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent);\r\n    /* check if there was an error */\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, buf->io->error(buf->io->ctx, err)); \r\n        lua_pushnumber(L, (lua_Number) (sent+start-1));\r\n    } else {\r\n        lua_pushnumber(L, (lua_Number) (sent+start-1));\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n    }\r\n#ifdef LUASOCKET_DEBUG\r\n    /* push time elapsed during operation as the last return value */\r\n    lua_pushnumber(L, timeout_gettime() - timeout_getstart(tm));\r\n#endif\r\n    return lua_gettop(L) - top;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* object:receive() interface\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_meth_receive(lua_State *L, p_buffer buf) {\r\n    int err = IO_DONE, top = lua_gettop(L);\r\n    luaL_Buffer b;\r\n    size_t size;\r\n    const char *part = luaL_optlstring(L, 3, \"\", &size);\r\n#ifdef LUASOCKET_DEBUG\r\n    p_timeout tm = timeout_markstart(buf->tm);\r\n#endif\r\n    /* initialize buffer with optional extra prefix \r\n     * (useful for concatenating previous partial results) */\r\n    luaL_buffinit(L, &b);\r\n    luaL_addlstring(&b, part, size);\r\n    /* receive new patterns */\r\n    if (!lua_isnumber(L, 2)) {\r\n        const char *p= luaL_optstring(L, 2, \"*l\");\r\n        if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);\r\n        else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); \r\n        else luaL_argcheck(L, 0, 2, \"invalid receive pattern\");\r\n    /* get a fixed number of bytes (minus what was already partially \r\n     * received) */\r\n    } else {\r\n        double n = lua_tonumber(L, 2); \r\n        size_t wanted = (size_t) n;\r\n        luaL_argcheck(L, n >= 0, 2, \"invalid receive pattern\");\r\n        if (size == 0 || wanted > size)\r\n            err = recvraw(buf, wanted-size, &b);\r\n    }\r\n    /* check if there was an error */\r\n    if (err != IO_DONE) {\r\n        /* we can't push anyting in the stack before pushing the\r\n         * contents of the buffer. this is the reason for the complication */\r\n        luaL_pushresult(&b);\r\n        lua_pushstring(L, buf->io->error(buf->io->ctx, err)); \r\n        lua_pushvalue(L, -2); \r\n        lua_pushnil(L);\r\n        lua_replace(L, -4);\r\n    } else {\r\n        luaL_pushresult(&b);\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n    }\r\n#ifdef LUASOCKET_DEBUG\r\n    /* push time elapsed during operation as the last return value */\r\n    lua_pushnumber(L, timeout_gettime() - timeout_getstart(tm));\r\n#endif\r\n    return lua_gettop(L) - top;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Determines if there is any data in the read buffer\r\n\\*-------------------------------------------------------------------------*/\r\nint buffer_isempty(p_buffer buf) {\r\n    return buf->first >= buf->last;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Internal functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Sends a block of data (unbuffered)\r\n\\*-------------------------------------------------------------------------*/\r\n#define STEPSIZE 8192\r\nstatic int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent) {\r\n    p_io io = buf->io;\r\n    p_timeout tm = buf->tm;\r\n    size_t total = 0;\r\n    int err = IO_DONE;\r\n    while (total < count && err == IO_DONE) {\r\n        size_t done = 0;\r\n        size_t step = (count-total <= STEPSIZE)? count-total: STEPSIZE;\r\n        err = io->send(io->ctx, data+total, step, &done, tm);\r\n        total += done;\r\n    }\r\n    *sent = total;\r\n    buf->sent += total;\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Reads a fixed number of bytes (buffered)\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b) {\r\n    int err = IO_DONE;\r\n    size_t total = 0;\r\n    while (err == IO_DONE) {\r\n        size_t count; const char *data;\r\n        err = buffer_get(buf, &data, &count);\r\n        count = MIN(count, wanted - total);\r\n        luaL_addlstring(b, data, count);\r\n        buffer_skip(buf, count);\r\n        total += count;\r\n        if (total >= wanted) break;\r\n    }\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Reads everything until the connection is closed (buffered)\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int recvall(p_buffer buf, luaL_Buffer *b) {\r\n    int err = IO_DONE;\r\n    size_t total = 0;\r\n    while (err == IO_DONE) {\r\n        const char *data; size_t count;\r\n        err = buffer_get(buf, &data, &count);\r\n        total += count;\r\n        luaL_addlstring(b, data, count);\r\n        buffer_skip(buf, count);\r\n    }\r\n    if (err == IO_CLOSED) {\r\n        if (total > 0) return IO_DONE;\r\n        else return IO_CLOSED;\r\n    } else return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Reads a line terminated by a CR LF pair or just by a LF. The CR and LF \r\n* are not returned by the function and are discarded from the buffer\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int recvline(p_buffer buf, luaL_Buffer *b) {\r\n    int err = IO_DONE;\r\n    while (err == IO_DONE) {\r\n        size_t count, pos; const char *data;\r\n        err = buffer_get(buf, &data, &count);\r\n        pos = 0;\r\n        while (pos < count && data[pos] != '\\n') {\r\n            /* we ignore all \\r's */\r\n            if (data[pos] != '\\r') luaL_addchar(b, data[pos]);\r\n            pos++;\r\n        }\r\n        if (pos < count) { /* found '\\n' */\r\n            buffer_skip(buf, pos+1); /* skip '\\n' too */\r\n            break; /* we are done */\r\n        } else /* reached the end of the buffer */\r\n            buffer_skip(buf, pos);\r\n    }\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Skips a given number of bytes from read buffer. No data is read from the\r\n* transport layer\r\n\\*-------------------------------------------------------------------------*/\r\nstatic void buffer_skip(p_buffer buf, size_t count) {\r\n    buf->received += count;\r\n    buf->first += count;\r\n    if (buffer_isempty(buf)) \r\n        buf->first = buf->last = 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Return any data available in buffer, or get more data from transport layer\r\n* if buffer is empty\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int buffer_get(p_buffer buf, const char **data, size_t *count) {\r\n    int err = IO_DONE;\r\n    p_io io = buf->io;\r\n    p_timeout tm = buf->tm;\r\n    if (buffer_isempty(buf)) {\r\n        size_t got;\r\n        err = io->recv(io->ctx, buf->data, BUF_SIZE, &got, tm);\r\n        buf->first = 0;\r\n        buf->last = got;\r\n    }\r\n    *count = buf->last - buf->first;\r\n    *data = buf->data + buf->first;\r\n    return err;\r\n}\r\n"
  },
  {
    "path": "build/luasocket/buffer.h",
    "content": "#ifndef BUF_H\r\n#define BUF_H \r\n/*=========================================================================*\\\r\n* Input/Output interface for Lua programs\r\n* LuaSocket toolkit\r\n*\r\n* Line patterns require buffering. Reading one character at a time involves\r\n* too many system calls and is very slow. This module implements the\r\n* LuaSocket interface for input/output on connected objects, as seen by \r\n* Lua programs. \r\n*\r\n* Input is buffered. Output is *not* buffered because there was no simple\r\n* way of making sure the buffered output data would ever be sent.\r\n*\r\n* The module is built on top of the I/O abstraction defined in io.h and the\r\n* timeout management is done with the timeout.h interface.\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n#include \"io.h\"\r\n#include \"timeout.h\"\r\n\r\n/* buffer size in bytes */\r\n#define BUF_SIZE 8192\r\n\r\n/* buffer control structure */\r\ntypedef struct t_buffer_ {\r\n    double birthday;        /* throttle support info: creation time, */\r\n    size_t sent, received;  /* bytes sent, and bytes received */\r\n    p_io io;                /* IO driver used for this buffer */\r\n    p_timeout tm;           /* timeout management for this buffer */\r\n    size_t first, last;     /* index of first and last bytes of stored data */\r\n    char data[BUF_SIZE];    /* storage space for buffer data */\r\n} t_buffer;\r\ntypedef t_buffer *p_buffer;\r\n\r\nint buffer_open(lua_State *L);\r\nvoid buffer_init(p_buffer buf, p_io io, p_timeout tm);\r\nint buffer_meth_send(lua_State *L, p_buffer buf);\r\nint buffer_meth_receive(lua_State *L, p_buffer buf);\r\nint buffer_meth_getstats(lua_State *L, p_buffer buf);\r\nint buffer_meth_setstats(lua_State *L, p_buffer buf);\r\nint buffer_isempty(p_buffer buf);\r\n\r\n#endif /* BUF_H */\r\n"
  },
  {
    "path": "build/luasocket/except.c",
    "content": "/*=========================================================================*\\\r\n* Simple exception support\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <stdio.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"except.h\"\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes.\r\n\\*=========================================================================*/\r\nstatic int global_protect(lua_State *L);\r\nstatic int global_newtry(lua_State *L);\r\nstatic int protected_(lua_State *L);\r\nstatic int finalize(lua_State *L);\r\nstatic int do_nothing(lua_State *L);\r\n\r\n/* except functions */\r\nstatic luaL_Reg func[] = {\r\n    {\"newtry\",    global_newtry},\r\n    {\"protect\",   global_protect},\r\n    {NULL,        NULL}\r\n};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Try factory\r\n\\*-------------------------------------------------------------------------*/\r\nstatic void wrap(lua_State *L) {\r\n    lua_newtable(L);\r\n    lua_pushnumber(L, 1);\r\n    lua_pushvalue(L, -3);\r\n    lua_settable(L, -3);\r\n    lua_insert(L, -2);\r\n    lua_pop(L, 1);\r\n}\r\n\r\nstatic int finalize(lua_State *L) {\r\n    if (!lua_toboolean(L, 1)) {\r\n        lua_pushvalue(L, lua_upvalueindex(1));\r\n        lua_pcall(L, 0, 0, 0);\r\n        lua_settop(L, 2);\r\n        wrap(L);\r\n        lua_error(L);\r\n        return 0;\r\n    } else return lua_gettop(L);\r\n}\r\n\r\nstatic int do_nothing(lua_State *L) { \r\n    (void) L;\r\n    return 0; \r\n}\r\n\r\nstatic int global_newtry(lua_State *L) {\r\n    lua_settop(L, 1);\r\n    if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing);\r\n    lua_pushcclosure(L, finalize, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Protect factory\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int unwrap(lua_State *L) {\r\n    if (lua_istable(L, -1)) {\r\n        lua_pushnumber(L, 1);\r\n        lua_gettable(L, -2);\r\n        lua_pushnil(L);\r\n        lua_insert(L, -2);\r\n        return 1;\r\n    } else return 0;\r\n}\r\n\r\nstatic int protected_(lua_State *L) {\r\n    lua_pushvalue(L, lua_upvalueindex(1));\r\n    lua_insert(L, 1);\r\n    if (lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0) != 0) {\r\n        if (unwrap(L)) return 2;\r\n        else lua_error(L);\r\n        return 0;\r\n    } else return lua_gettop(L);\r\n}\r\n\r\nstatic int global_protect(lua_State *L) {\r\n    lua_pushcclosure(L, protected_, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Init module\r\n\\*-------------------------------------------------------------------------*/\r\nint except_open(lua_State *L) {\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    return 0;\r\n}\r\n"
  },
  {
    "path": "build/luasocket/except.h",
    "content": "#ifndef EXCEPT_H\r\n#define EXCEPT_H\r\n/*=========================================================================*\\\r\n* Exception control\r\n* LuaSocket toolkit (but completely independent from other modules)\r\n*\r\n* This provides support for simple exceptions in Lua. During the\r\n* development of the HTTP/FTP/SMTP support, it became aparent that\r\n* error checking was taking a substantial amount of the coding. These\r\n* function greatly simplify the task of checking errors.\r\n*\r\n* The main idea is that functions should return nil as its first return\r\n* value when it finds an error, and return an error message (or value)\r\n* following nil. In case of success, as long as the first value is not nil,\r\n* the other values don't matter.\r\n*\r\n* The idea is to nest function calls with the \"try\" function. This function\r\n* checks the first value, and calls \"error\" on the second if the first is\r\n* nil. Otherwise, it returns all values it received. \r\n*\r\n* The protect function returns a new function that behaves exactly like the\r\n* function it receives, but the new function doesn't throw exceptions: it\r\n* returns nil followed by the error message instead.\r\n*\r\n* With these two function, it's easy to write functions that throw\r\n* exceptions on error, but that don't interrupt the user script. \r\n\\*=========================================================================*/\r\n\r\n#include \"lua.h\"\r\n\r\nint except_open(lua_State *L);\r\n\r\n#endif\r\n"
  },
  {
    "path": "build/luasocket/inet.c",
    "content": "/*=========================================================================*\\\r\n* Internet domain functions\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"inet.h\"\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes.\r\n\\*=========================================================================*/\r\nstatic int inet_global_toip(lua_State *L);\r\nstatic int inet_global_getaddrinfo(lua_State *L);\r\nstatic int inet_global_tohostname(lua_State *L);\r\nstatic int inet_global_getnameinfo(lua_State *L);\r\nstatic void inet_pushresolved(lua_State *L, struct hostent *hp);\r\nstatic int inet_global_gethostname(lua_State *L);\r\n\r\n/* DNS functions */\r\nstatic luaL_Reg func[] = {\r\n    { \"toip\", inet_global_toip},\r\n    { \"getaddrinfo\", inet_global_getaddrinfo},\r\n    { \"tohostname\", inet_global_tohostname},\r\n    { \"getnameinfo\", inet_global_getnameinfo},\r\n    { \"gethostname\", inet_global_gethostname},\r\n    { NULL, NULL}\r\n};\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint inet_open(lua_State *L)\r\n{\r\n    lua_pushstring(L, \"dns\");\r\n    lua_newtable(L);\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    lua_settable(L, -3);\r\n    return 0;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Global Lua functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns all information provided by the resolver given a host name\r\n* or ip address\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int inet_gethost(const char *address, struct hostent **hp) {\r\n    struct in_addr addr;\r\n    if (inet_aton(address, &addr))\r\n        return socket_gethostbyaddr((char *) &addr, sizeof(addr), hp);\r\n    else\r\n        return socket_gethostbyname(address, hp);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns all information provided by the resolver given a host name\r\n* or ip address\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int inet_global_tohostname(lua_State *L) {\r\n    const char *address = luaL_checkstring(L, 1);\r\n    struct hostent *hp = NULL;\r\n    int err = inet_gethost(address, &hp);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_hoststrerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, hp->h_name);\r\n    inet_pushresolved(L, hp);\r\n    return 2;\r\n}\r\n\r\nstatic int inet_global_getnameinfo(lua_State *L) {\r\n    char hbuf[NI_MAXHOST];\r\n    char sbuf[NI_MAXSERV];\r\n    int i, ret;\r\n    struct addrinfo hints;\r\n    struct addrinfo *resolved, *iter;\r\n    const char *host = luaL_optstring(L, 1, NULL);\r\n    const char *serv = luaL_optstring(L, 2, NULL);\r\n\r\n    if (!(host || serv))\r\n        luaL_error(L, \"host and serv cannot be both nil\");\r\n\r\n    memset(&hints, 0, sizeof(hints));\r\n    hints.ai_socktype = SOCK_STREAM;\r\n    hints.ai_family = PF_UNSPEC;\r\n\r\n    ret = getaddrinfo(host, serv, &hints, &resolved);\r\n    if (ret != 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_gaistrerror(ret));\r\n        return 2;\r\n    }\r\n\r\n    lua_newtable(L);\r\n    for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) {\r\n        getnameinfo(iter->ai_addr, (socklen_t) iter->ai_addrlen, \r\n            hbuf, host? (socklen_t) sizeof(hbuf): 0, \r\n            sbuf, serv? (socklen_t) sizeof(sbuf): 0, 0);\r\n        if (host) {\r\n            lua_pushnumber(L, i);\r\n            lua_pushstring(L, hbuf);\r\n            lua_settable(L, -3);\r\n        }\r\n    }\r\n    freeaddrinfo(resolved);\r\n\r\n    if (serv) {\r\n        lua_pushstring(L, sbuf);\r\n        return 2;\r\n    } else {\r\n        return 1;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns all information provided by the resolver given a host name\r\n* or ip address\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int inet_global_toip(lua_State *L)\r\n{\r\n    const char *address = luaL_checkstring(L, 1);\r\n    struct hostent *hp = NULL;\r\n    int err = inet_gethost(address, &hp);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_hoststrerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, inet_ntoa(*((struct in_addr *) hp->h_addr)));\r\n    inet_pushresolved(L, hp);\r\n    return 2;\r\n}\r\n\r\nint inet_optfamily(lua_State* L, int narg, const char* def)\r\n{\r\n    static const char* optname[] = { \"unspec\", \"inet\", \"inet6\", NULL };\r\n    static int optvalue[] = { PF_UNSPEC, PF_INET, PF_INET6, 0 };\r\n\r\n    return optvalue[luaL_checkoption(L, narg, def, optname)];\r\n}\r\n\r\nint inet_optsocktype(lua_State* L, int narg, const char* def)\r\n{\r\n    static const char* optname[] = { \"stream\", \"dgram\", NULL };\r\n    static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 };\r\n\r\n    return optvalue[luaL_checkoption(L, narg, def, optname)];\r\n}\r\n\r\nstatic int inet_global_getaddrinfo(lua_State *L)\r\n{\r\n    const char *hostname = luaL_checkstring(L, 1);\r\n    struct addrinfo *iterator = NULL, *resolved = NULL;\r\n    struct addrinfo hints;\r\n    int i = 1, ret = 0;\r\n    memset(&hints, 0, sizeof(hints));\r\n    hints.ai_socktype = SOCK_STREAM;\r\n    hints.ai_family = PF_UNSPEC;\r\n    ret = getaddrinfo(hostname, NULL, &hints, &resolved);\r\n    if (ret != 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_gaistrerror(ret));\r\n        return 2;\r\n    }\r\n    lua_newtable(L);\r\n    for (iterator = resolved; iterator; iterator = iterator->ai_next) {\r\n        char hbuf[NI_MAXHOST];\r\n        ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, \r\n            hbuf, (socklen_t) sizeof(hbuf), NULL, 0, NI_NUMERICHOST);\r\n        if (ret){\r\n          lua_pushnil(L);\r\n          lua_pushstring(L, socket_gaistrerror(ret));\r\n          return 2;\r\n        }\r\n        lua_pushnumber(L, i);\r\n        lua_newtable(L);\r\n        switch (iterator->ai_family) {\r\n            case AF_INET:\r\n                lua_pushliteral(L, \"family\");\r\n                lua_pushliteral(L, \"inet\");\r\n                lua_settable(L, -3);\r\n                break;\r\n            case AF_INET6:\r\n                lua_pushliteral(L, \"family\");\r\n                lua_pushliteral(L, \"inet6\");\r\n                lua_settable(L, -3);\r\n                break;\r\n        }\r\n        lua_pushliteral(L, \"addr\");\r\n        lua_pushstring(L, hbuf);\r\n        lua_settable(L, -3);\r\n        lua_settable(L, -3);\r\n        i++;\r\n    }\r\n    freeaddrinfo(resolved);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Gets the host name\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int inet_global_gethostname(lua_State *L)\r\n{\r\n    char name[257];\r\n    name[256] = '\\0';\r\n    if (gethostname(name, 256) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(errno));\r\n        return 2;\r\n    } else {\r\n        lua_pushstring(L, name);\r\n        return 1;\r\n    }\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Lua methods\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Retrieves socket peer name\r\n\\*-------------------------------------------------------------------------*/\r\nint inet_meth_getpeername(lua_State *L, p_socket ps, int family)\r\n{\r\n    int err;\r\n    struct sockaddr_storage peer;\r\n    socklen_t peer_len = sizeof(peer);\r\n    char name[INET6_ADDRSTRLEN];\r\n    char port[6]; /* 65535 = 5 bytes + 0 to terminate it */\r\n    if (getpeername(*ps, (SA *) &peer, &peer_len) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(errno));\r\n        return 2;\r\n    }\r\n\terr = getnameinfo((struct sockaddr *) &peer, peer_len,\r\n        name, INET6_ADDRSTRLEN,\r\n        port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, gai_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, name);\r\n    lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));\r\n    if (family == PF_INET) {\r\n        lua_pushliteral(L, \"inet\");\r\n    } else if (family == PF_INET6) {\r\n        lua_pushliteral(L, \"inet6\");\r\n    } else {\r\n        lua_pushliteral(L, \"uknown family\");\r\n    }\r\n    return 3;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Retrieves socket local name\r\n\\*-------------------------------------------------------------------------*/\r\nint inet_meth_getsockname(lua_State *L, p_socket ps, int family)\r\n{\r\n    int err;\r\n    struct sockaddr_storage peer;\r\n    socklen_t peer_len = sizeof(peer);\r\n    char name[INET6_ADDRSTRLEN];\r\n    char port[6]; /* 65535 = 5 bytes + 0 to terminate it */\r\n    if (getsockname(*ps, (SA *) &peer, &peer_len) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(errno));\r\n        return 2;\r\n    }\r\n\terr=getnameinfo((struct sockaddr *)&peer, peer_len, \r\n\t\tname, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, gai_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, name);\r\n    lua_pushstring(L, port);\r\n    if (family == PF_INET) {\r\n        lua_pushliteral(L, \"inet\");\r\n    } else if (family == PF_INET6) {\r\n        lua_pushliteral(L, \"inet6\");\r\n    } else {\r\n        lua_pushliteral(L, \"uknown family\");\r\n    }\r\n    return 3;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Internal functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Passes all resolver information to Lua as a table\r\n\\*-------------------------------------------------------------------------*/\r\nstatic void inet_pushresolved(lua_State *L, struct hostent *hp)\r\n{\r\n    char **alias;\r\n    struct in_addr **addr;\r\n    int i, resolved;\r\n    lua_newtable(L); resolved = lua_gettop(L);\r\n    lua_pushstring(L, \"name\");\r\n    lua_pushstring(L, hp->h_name);\r\n    lua_settable(L, resolved);\r\n    lua_pushstring(L, \"ip\");\r\n    lua_pushstring(L, \"alias\");\r\n    i = 1;\r\n    alias = hp->h_aliases;\r\n    lua_newtable(L);\r\n    if (alias) {\r\n        while (*alias) {\r\n            lua_pushnumber(L, i);\r\n            lua_pushstring(L, *alias);\r\n            lua_settable(L, -3);\r\n            i++; alias++;\r\n        }\r\n    }\r\n    lua_settable(L, resolved);\r\n    i = 1;\r\n    lua_newtable(L);\r\n    addr = (struct in_addr **) hp->h_addr_list;\r\n    if (addr) {\r\n        while (*addr) {\r\n            lua_pushnumber(L, i);\r\n            lua_pushstring(L, inet_ntoa(**addr));\r\n            lua_settable(L, -3);\r\n            i++; addr++;\r\n        }\r\n    }\r\n    lua_settable(L, resolved);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Tries to create a new inet socket\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *inet_trycreate(p_socket ps, int family, int type) {\r\n    return socket_strerror(socket_create(ps, family, type, 0));\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* \"Disconnects\" a DGRAM socket\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)\r\n{\r\n    switch (family) {\r\n        case PF_INET: {\r\n            struct sockaddr_in sin;\r\n            memset((char *) &sin, 0, sizeof(sin));\r\n            sin.sin_family = AF_UNSPEC;\r\n            sin.sin_addr.s_addr = INADDR_ANY;\r\n            return socket_strerror(socket_connect(ps, (SA *) &sin, \r\n                sizeof(sin), tm));\r\n        }\r\n        case PF_INET6: {\r\n            struct sockaddr_in6 sin6;\r\n            struct in6_addr addrany = IN6ADDR_ANY_INIT; \r\n            memset((char *) &sin6, 0, sizeof(sin6));\r\n            sin6.sin6_family = AF_UNSPEC;\r\n            sin6.sin6_addr = addrany;\r\n            return socket_strerror(socket_connect(ps, (SA *) &sin6, \r\n                sizeof(sin6), tm));\r\n        }\r\n    }\r\n    return NULL;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Tries to connect to remote address (address, port)\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *inet_tryconnect(p_socket ps, int *family, const char *address,\r\n        const char *serv, p_timeout tm, struct addrinfo *connecthints)\r\n{\r\n    struct addrinfo *iterator = NULL, *resolved = NULL;\r\n    const char *err = NULL;\r\n    /* try resolving */\r\n    err = socket_gaistrerror(getaddrinfo(address, serv,\r\n                connecthints, &resolved));\r\n    if (err != NULL) {\r\n        if (resolved) freeaddrinfo(resolved);\r\n        return err;\r\n    }\r\n    for (iterator = resolved; iterator; iterator = iterator->ai_next) {\r\n        timeout_markstart(tm);\r\n        /* create new socket if necessary. if there was no\r\n         * bind, we need to create one for every new family\r\n         * that shows up while iterating. if there was a\r\n         * bind, all families will be the same and we will\r\n         * not enter this branch. */\r\n        if (*family != iterator->ai_family) {\r\n            socket_destroy(ps);\r\n            err = socket_strerror(socket_create(ps, iterator->ai_family, \r\n                iterator->ai_socktype, iterator->ai_protocol));\r\n            if (err != NULL) {\r\n                freeaddrinfo(resolved);\r\n                return err;\r\n            }\r\n            *family = iterator->ai_family;\r\n            /* all sockets initially non-blocking */\r\n            socket_setnonblocking(ps);\r\n        }\r\n        /* try connecting to remote address */\r\n        err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, \r\n            (socklen_t) iterator->ai_addrlen, tm));\r\n        /* if success, break out of loop */\r\n        if (err == NULL) break;\r\n    }\r\n    freeaddrinfo(resolved);\r\n    /* here, if err is set, we failed */\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Tries to accept a socket\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *inet_tryaccept(p_socket server, int family, p_socket client, \r\n    p_timeout tm)\r\n{\r\n\tsocklen_t len;\r\n\tt_sockaddr_storage addr;\r\n\tif (family == PF_INET6) {\r\n\t\tlen = sizeof(struct sockaddr_in6);\r\n\t} else {\r\n\t\tlen = sizeof(struct sockaddr_in);\r\n\t}\r\n\treturn socket_strerror(socket_accept(server, client, (SA *) &addr, \r\n        &len, tm));\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Tries to bind socket to (address, port)\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *inet_trybind(p_socket ps, const char *address, const char *serv,\r\n        struct addrinfo *bindhints)\r\n{\r\n    struct addrinfo *iterator = NULL, *resolved = NULL;\r\n    const char *err = NULL;\r\n    t_socket sock = *ps;\r\n    /* translate luasocket special values to C */\r\n    if (strcmp(address, \"*\") == 0) address = NULL;\r\n    if (!serv) serv = \"0\";\r\n    /* try resolving */\r\n    err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved));\r\n    if (err) {\r\n        if (resolved) freeaddrinfo(resolved);\r\n        return err;\r\n    }\r\n    /* iterate over resolved addresses until one is good */\r\n    for (iterator = resolved; iterator; iterator = iterator->ai_next) {\r\n        if(sock == SOCKET_INVALID) {\r\n            err = socket_strerror(socket_create(&sock, iterator->ai_family,\r\n                        iterator->ai_socktype, iterator->ai_protocol));\r\n            if(err)\r\n                continue;\r\n        }\r\n        /* try binding to local address */\r\n        err = socket_strerror(socket_bind(&sock,\r\n            (SA *) iterator->ai_addr,\r\n            (socklen_t) iterator->ai_addrlen));\r\n\r\n        /* keep trying unless bind succeeded */\r\n        if (err) {\r\n            if(sock != *ps)\r\n                socket_destroy(&sock);\r\n        } else {\r\n            /* remember what we connected to, particularly the family */\r\n            *bindhints = *iterator;\r\n            break;\r\n        }\r\n    }\r\n    /* cleanup and return error */\r\n    freeaddrinfo(resolved);\r\n    *ps = sock;\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Some systems do not provide these so that we provide our own. \r\n\\*-------------------------------------------------------------------------*/\r\n#ifdef LUASOCKET_INET_ATON\r\nint inet_aton(const char *cp, struct in_addr *inp)\r\n{\r\n    unsigned int a = 0, b = 0, c = 0, d = 0;\r\n    int n = 0, r;\r\n    unsigned long int addr = 0;\r\n    r = sscanf(cp, \"%u.%u.%u.%u%n\", &a, &b, &c, &d, &n);\r\n    if (r == 0 || n == 0) return 0;\r\n    cp += n;\r\n    if (*cp) return 0;\r\n    if (a > 255 || b > 255 || c > 255 || d > 255) return 0;\r\n    if (inp) {\r\n        addr += a; addr <<= 8;\r\n        addr += b; addr <<= 8;\r\n        addr += c; addr <<= 8;\r\n        addr += d;\r\n        inp->s_addr = htonl(addr);\r\n    }\r\n    return 1;\r\n}\r\n#endif\r\n\r\n#ifdef LUASOCKET_INET_PTON\r\nint inet_pton_w32(int af, const char *src, void *dst) \r\n{\r\n    struct addrinfo hints, *res;\r\n    int ret = 1;\r\n    memset(&hints, 0, sizeof(struct addrinfo));\r\n    hints.ai_family = af;\r\n    hints.ai_flags = AI_NUMERICHOST;\r\n    if (getaddrinfo(src, NULL, &hints, &res) != 0) return -1;\r\n    if (af == AF_INET) {\r\n        struct sockaddr_in *in = (struct sockaddr_in *) res->ai_addr;\r\n        memcpy(dst, &in->sin_addr, sizeof(in->sin_addr));\r\n    } else if (af == AF_INET6) {\r\n        struct sockaddr_in6 *in = (struct sockaddr_in6 *) res->ai_addr;\r\n        memcpy(dst, &in->sin6_addr, sizeof(in->sin6_addr));\r\n    } else {\r\n        ret = -1;\r\n    }\r\n    freeaddrinfo(res); \r\n    return ret;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "build/luasocket/inet.h",
    "content": "#ifndef INET_H \r\n#define INET_H \r\n/*=========================================================================*\\\r\n* Internet domain functions\r\n* LuaSocket toolkit\r\n*\r\n* This module implements the creation and connection of internet domain\r\n* sockets, on top of the socket.h interface, and the interface of with the\r\n* resolver. \r\n*\r\n* The function inet_aton is provided for the platforms where it is not\r\n* available. The module also implements the interface of the internet\r\n* getpeername and getsockname functions as seen by Lua programs.\r\n*\r\n* The Lua functions toip and tohostname are also implemented here.\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n#include \"socket.h\"\r\n#include \"timeout.h\"\r\n\r\n#ifdef _WIN32\r\n#define LUASOCKET_INET_ATON\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define LUASOCKET_INET_PTON\r\n#else\r\n#define inet_pton_w32 inet_pton\r\n#endif\r\n\r\nint inet_open(lua_State *L);\r\n\r\nconst char *inet_trycreate(p_socket ps, int family, int type);\r\nconst char *inet_tryconnect(p_socket ps, int *family, const char *address,\r\n        const char *serv, p_timeout tm, struct addrinfo *connecthints);\r\nconst char *inet_trybind(p_socket ps, const char *address, const char *serv,\r\n        struct addrinfo *bindhints);\r\nconst char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);\r\nconst char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);\r\n\r\nint inet_meth_getpeername(lua_State *L, p_socket ps, int family);\r\nint inet_meth_getsockname(lua_State *L, p_socket ps, int family);\r\n\r\nint inet_optfamily(lua_State* L, int narg, const char* def);\r\nint inet_optsocktype(lua_State* L, int narg, const char* def);\r\n\r\n#ifdef LUASOCKET_INET_ATON\r\nint inet_aton(const char *cp, struct in_addr *inp);\r\n#endif\r\n\r\n#ifdef LUASOCKET_INET_PTON\r\n//const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);\r\nint inet_pton_w32(int af, const char *src, void *dst);\r\n#endif\r\n\r\n#endif /* INET_H */\r\n"
  },
  {
    "path": "build/luasocket/io.c",
    "content": "/*=========================================================================*\\\r\n* Input/Output abstraction\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include \"io.h\"\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes C structure\r\n\\*-------------------------------------------------------------------------*/\r\nvoid io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) {\r\n    io->send = send;\r\n    io->recv = recv;\r\n    io->error = error;\r\n    io->ctx = ctx;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* I/O error strings\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *io_strerror(int err) {\r\n    switch (err) {\r\n        case IO_DONE: return NULL;\r\n        case IO_CLOSED: return \"closed\";\r\n        case IO_TIMEOUT: return \"timeout\";\r\n        default: return \"unknown error\"; \r\n    }\r\n}\r\n"
  },
  {
    "path": "build/luasocket/io.h",
    "content": "#ifndef IO_H\r\n#define IO_H\r\n/*=========================================================================*\\\r\n* Input/Output abstraction\r\n* LuaSocket toolkit\r\n*\r\n* This module defines the interface that LuaSocket expects from the\r\n* transport layer for streamed input/output. The idea is that if any\r\n* transport implements this interface, then the buffer.c functions\r\n* automatically work on it.\r\n*\r\n* The module socket.h implements this interface, and thus the module tcp.h\r\n* is very simple.\r\n\\*=========================================================================*/\r\n#include <stdio.h>\r\n#include \"lua.h\"\r\n\r\n#include \"timeout.h\"\r\n\r\n/* IO error codes */\r\nenum {\r\n    IO_DONE = 0,        /* operation completed successfully */\r\n    IO_TIMEOUT = -1,    /* operation timed out */\r\n    IO_CLOSED = -2,     /* the connection has been closed */\r\n\tIO_UNKNOWN = -3     \r\n};\r\n\r\n/* interface to error message function */\r\ntypedef const char *(*p_error) (\r\n    void *ctx,          /* context needed by send */\r\n    int err             /* error code */\r\n);\r\n\r\n/* interface to send function */\r\ntypedef int (*p_send) (\r\n    void *ctx,          /* context needed by send */\r\n    const char *data,   /* pointer to buffer with data to send */\r\n    size_t count,       /* number of bytes to send from buffer */\r\n    size_t *sent,       /* number of bytes sent uppon return */\r\n    p_timeout tm        /* timeout control */\r\n);\r\n\r\n/* interface to recv function */\r\ntypedef int (*p_recv) (\r\n    void *ctx,          /* context needed by recv */\r\n    char *data,         /* pointer to buffer where data will be writen */\r\n    size_t count,       /* number of bytes to receive into buffer */\r\n    size_t *got,        /* number of bytes received uppon return */\r\n    p_timeout tm        /* timeout control */\r\n);\r\n\r\n/* IO driver definition */\r\ntypedef struct t_io_ {\r\n    void *ctx;          /* context needed by send/recv */\r\n    p_send send;        /* send function pointer */\r\n    p_recv recv;        /* receive function pointer */\r\n    p_error error;      /* strerror function */\r\n} t_io;\r\ntypedef t_io *p_io;\r\n\r\nvoid io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);\r\nconst char *io_strerror(int err);\r\n\r\n#endif /* IO_H */\r\n\r\n"
  },
  {
    "path": "build/luasocket/luasocket.c",
    "content": "/*=========================================================================*\\\r\n* LuaSocket toolkit\r\n* Networking support for the Lua language\r\n* Diego Nehab\r\n* 26/11/1999\r\n*\r\n* This library is part of an  effort to progressively increase the network\r\n* connectivity  of  the Lua  language.  The  Lua interface  to  networking\r\n* functions follows the Sockets API  closely, trying to simplify all tasks\r\n* involved in setting up both  client and server connections. The provided\r\n* IO routines, however, follow the Lua  style, being very similar  to the\r\n* standard Lua read and write functions.\r\n\\*=========================================================================*/\r\n\r\n/*=========================================================================*\\\r\n* Standard include files\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n\r\n/*=========================================================================*\\\r\n* LuaSocket includes\r\n\\*=========================================================================*/\r\n#include \"luasocket.h\"\r\n#include \"auxiliar.h\"\r\n#include \"except.h\"\r\n#include \"timeout.h\"\r\n#include \"buffer.h\"\r\n#include \"inet.h\"\r\n#include \"tcp.h\"\r\n#include \"udp.h\"\r\n#include \"select.h\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Internal function prototypes\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_skip(lua_State *L);\r\nstatic int global_unload(lua_State *L);\r\nstatic int base_open(lua_State *L);\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Modules and functions\r\n\\*-------------------------------------------------------------------------*/\r\nstatic const luaL_Reg mod[] = {\r\n    {\"auxiliar\", auxiliar_open},\r\n    {\"except\", except_open},\r\n    {\"timeout\", timeout_open},\r\n    {\"buffer\", buffer_open},\r\n    {\"inet\", inet_open},\r\n    {\"tcp\", tcp_open},\r\n    {\"udp\", udp_open},\r\n    {\"select\", select_open},\r\n    {NULL, NULL}\r\n};\r\n\r\nstatic luaL_Reg func[] = {\r\n    {\"skip\",      global_skip},\r\n    {\"__unload\",  global_unload},\r\n    {NULL,        NULL}\r\n};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Skip a few arguments\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_skip(lua_State *L) {\r\n    int amount = luaL_checkint(L, 1);\r\n    int ret = lua_gettop(L) - amount - 1;\r\n    return ret >= 0 ? ret : 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Unloads the library\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_unload(lua_State *L) {\r\n    (void) L;\r\n    socket_close();\r\n    return 0;\r\n}\r\n\r\n#if LUA_VERSION_NUM > 501\r\nint luaL_typerror (lua_State *L, int narg, const char *tname) {\r\n  const char *msg = lua_pushfstring(L, \"%s expected, got %s\",\r\n                                    tname, luaL_typename(L, narg));\r\n  return luaL_argerror(L, narg, msg);\r\n}\r\n#endif\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Setup basic stuff.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int base_open(lua_State *L) {\r\n    if (socket_open()) {\r\n        /* export functions (and leave namespace table on top of stack) */\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n        lua_newtable(L);\r\n        luaL_setfuncs(L, func, 0);\r\n#else\r\n        luaL_openlib(L, \"socket\", func, 0);\r\n#endif\r\n#ifdef LUASOCKET_DEBUG\r\n        lua_pushstring(L, \"_DEBUG\");\r\n        lua_pushboolean(L, 1);\r\n        lua_rawset(L, -3);\r\n#endif\r\n        /* make version string available to scripts */\r\n        lua_pushstring(L, \"_VERSION\");\r\n        lua_pushstring(L, LUASOCKET_VERSION);\r\n        lua_rawset(L, -3);\r\n        return 1;\r\n    } else {\r\n        lua_pushstring(L, \"unable to initialize library\");\r\n        lua_error(L);\r\n        return 0;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes all library modules.\r\n\\*-------------------------------------------------------------------------*/\r\nLUA_API int luaopen_socket_core(lua_State *L) {\r\n    int i;\r\n    base_open(L);\r\n    for (i = 0; mod[i].name; i++) mod[i].func(L);\r\n    return 1;\r\n}\r\n"
  },
  {
    "path": "build/luasocket/luasocket.h",
    "content": "#ifndef LUASOCKET_H\r\n#define LUASOCKET_H\r\n/*=========================================================================*\\\r\n* LuaSocket toolkit\r\n* Networking support for the Lua language\r\n* Diego Nehab\r\n* 9/11/1999\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Current socket library version\r\n\\*-------------------------------------------------------------------------*/\r\n#define LUASOCKET_VERSION    \"LuaSocket 3.0-rc1\"\r\n#define LUASOCKET_COPYRIGHT  \"Copyright (C) 1999-2013 Diego Nehab\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes the library.\r\n\\*-------------------------------------------------------------------------*/\r\nLUA_API int luaopen_socket_core(lua_State *L);\r\n\r\n#endif /* LUASOCKET_H */\r\n"
  },
  {
    "path": "build/luasocket/luasocket_scripts.c",
    "content": "\r\n/* luasocket_scripts.c */\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n#include \"luasocket_scripts.h\"\r\n\r\n/* ltn12 */\r\nstatic const char *lua_m_ltn12 = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- LTN12 - Filters, sources, sinks and pumps.\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local table = require(\\\"table\\\")\\n\"\r\n\"local base = _G\\n\"\r\n\"local _M = {}\\n\"\r\n\"if module then -- heuristic for exporting a global package table\\n\"\r\n\"    ltn12 = _M\\n\"\r\n\"end\\n\"\r\n\"local filter,source,sink,pump = {},{},{},{}\\n\"\r\n\"\\n\"\r\n\"_M.filter = filter\\n\"\r\n\"_M.source = source\\n\"\r\n\"_M.sink = sink\\n\"\r\n\"_M.pump = pump\\n\"\r\n\"\\n\"\r\n\"-- 2048 seems to be better in windows...\\n\"\r\n\"_M.BLOCKSIZE = 2048\\n\"\r\n\"_M._VERSION = \\\"LTN12 1.0.3\\\"\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Filter stuff\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- returns a high level filter that cycles a low-level filter\\n\"\r\n\"function filter.cycle(low, ctx, extra)\\n\"\r\n\"    base.assert(low)\\n\"\r\n\"    return function(chunk)\\n\"\r\n\"        local ret\\n\"\r\n\"        ret, ctx = low(ctx, chunk, extra)\\n\"\r\n\"        return ret\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- chains a bunch of filters together\\n\"\r\n\"-- (thanks to Wim Couwenberg)\\n\"\r\n\"function filter.chain(...)\\n\"\r\n\"    local arg = {...}\\n\"\r\n\"    local n = select('#',...)\\n\"\r\n\"    local top, index = 1, 1\\n\"\r\n\"    local retry = \\\"\\\"\\n\"\r\n\"    return function(chunk)\\n\"\r\n\"        retry = chunk and retry\\n\"\r\n\"        while true do\\n\"\r\n\"            if index == top then\\n\"\r\n\"                chunk = arg[index](chunk)\\n\"\r\n\"                if chunk == \\\"\\\" or top == n then return chunk\\n\"\r\n\"                elseif chunk then index = index + 1\\n\"\r\n\"                else\\n\"\r\n\"                    top = top+1\\n\"\r\n\"                    index = top\\n\"\r\n\"                end\\n\"\r\n\"            else\\n\"\r\n\"                chunk = arg[index](chunk or \\\"\\\")\\n\"\r\n\"                if chunk == \\\"\\\" then\\n\"\r\n\"                    index = index - 1\\n\"\r\n\"                    chunk = retry\\n\"\r\n\"                elseif chunk then\\n\"\r\n\"                    if index == n then return chunk\\n\"\r\n\"                    else index = index + 1 end\\n\"\r\n\"                else base.error(\\\"filter returned inappropriate nil\\\") end\\n\"\r\n\"            end\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Source stuff\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- create an empty source\\n\"\r\n\"local function empty()\\n\"\r\n\"    return nil\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function source.empty()\\n\"\r\n\"    return empty\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- returns a source that just outputs an error\\n\"\r\n\"function source.error(err)\\n\"\r\n\"    return function()\\n\"\r\n\"        return nil, err\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates a file source\\n\"\r\n\"function source.file(handle, io_err)\\n\"\r\n\"    if handle then\\n\"\r\n\"        return function()\\n\"\r\n\"            local chunk = handle:read(_M.BLOCKSIZE)\\n\"\r\n\"            if not chunk then handle:close() end\\n\"\r\n\"            return chunk\\n\"\r\n\"        end\\n\"\r\n\"    else return source.error(io_err or \\\"unable to open file\\\") end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- turns a fancy source into a simple source\\n\"\r\n\"function source.simplify(src)\\n\"\r\n\"    base.assert(src)\\n\"\r\n\"    return function()\\n\"\r\n\"        local chunk, err_or_new = src()\\n\"\r\n\"        src = err_or_new or src\\n\"\r\n\"        if not chunk then return nil, err_or_new\\n\"\r\n\"        else return chunk end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates string source\\n\"\r\n\"function source.string(s)\\n\"\r\n\"    if s then\\n\"\r\n\"        local i = 1\\n\"\r\n\"        return function()\\n\"\r\n\"            local chunk = string.sub(s, i, i+_M.BLOCKSIZE-1)\\n\"\r\n\"            i = i + _M.BLOCKSIZE\\n\"\r\n\"            if chunk ~= \\\"\\\" then return chunk\\n\"\r\n\"            else return nil end\\n\"\r\n\"        end\\n\"\r\n\"    else return source.empty() end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates rewindable source\\n\"\r\n\"function source.rewind(src)\\n\"\r\n\"    base.assert(src)\\n\"\r\n\"    local t = {}\\n\"\r\n\"    return function(chunk)\\n\"\r\n\"        if not chunk then\\n\"\r\n\"            chunk = table.remove(t)\\n\"\r\n\"            if not chunk then return src()\\n\"\r\n\"            else return chunk end\\n\"\r\n\"        else\\n\"\r\n\"            table.insert(t, chunk)\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function source.chain(src, f)\\n\"\r\n\"    base.assert(src and f)\\n\"\r\n\"    local last_in, last_out = \\\"\\\", \\\"\\\"\\n\"\r\n\"    local state = \\\"feeding\\\"\\n\"\r\n\"    local err\\n\"\r\n\"    return function()\\n\"\r\n\"        if not last_out then\\n\"\r\n\"            base.error('source is empty!', 2)\\n\"\r\n\"        end\\n\"\r\n\"        while true do\\n\"\r\n\"            if state == \\\"feeding\\\" then\\n\"\r\n\"                last_in, err = src()\\n\"\r\n\"                if err then return nil, err end\\n\"\r\n\"                last_out = f(last_in)\\n\"\r\n\"                if not last_out then\\n\"\r\n\"                    if last_in then\\n\"\r\n\"                        base.error('filter returned inappropriate nil')\\n\"\r\n\"                    else\\n\"\r\n\"                        return nil\\n\"\r\n\"                    end\\n\"\r\n\"                elseif last_out ~= \\\"\\\" then\\n\"\r\n\"                    state = \\\"eating\\\"\\n\"\r\n\"                    if last_in then last_in = \\\"\\\" end\\n\"\r\n\"                    return last_out\\n\"\r\n\"                end\\n\"\r\n\"            else\\n\"\r\n\"                last_out = f(last_in)\\n\"\r\n\"                if last_out == \\\"\\\" then\\n\"\r\n\"                    if last_in == \\\"\\\" then\\n\"\r\n\"                        state = \\\"feeding\\\"\\n\"\r\n\"                    else\\n\"\r\n\"                        base.error('filter returned \\\"\\\"')\\n\"\r\n\"                    end\\n\"\r\n\"                elseif not last_out then\\n\"\r\n\"                    if last_in then\\n\"\r\n\"                        base.error('filter returned inappropriate nil')\\n\"\r\n\"                    else\\n\"\r\n\"                        return nil\\n\"\r\n\"                    end\\n\"\r\n\"                else\\n\"\r\n\"                    return last_out\\n\"\r\n\"                end\\n\"\r\n\"            end\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates a source that produces contents of several sources, one after the\\n\"\r\n\"-- other, as if they were concatenated\\n\"\r\n\"-- (thanks to Wim Couwenberg)\\n\"\r\n\"function source.cat(...)\\n\"\r\n\"    local arg = {...}\\n\"\r\n\"    local src = table.remove(arg, 1)\\n\"\r\n\"    return function()\\n\"\r\n\"        while src do\\n\"\r\n\"            local chunk, err = src()\\n\"\r\n\"            if chunk then return chunk end\\n\"\r\n\"            if err then return nil, err end\\n\"\r\n\"            src = table.remove(arg, 1)\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Sink stuff\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- creates a sink that stores into a table\\n\"\r\n\"function sink.table(t)\\n\"\r\n\"    t = t or {}\\n\"\r\n\"    local f = function(chunk, err)\\n\"\r\n\"        if chunk then table.insert(t, chunk) end\\n\"\r\n\"        return 1\\n\"\r\n\"    end\\n\"\r\n\"    return f, t\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- turns a fancy sink into a simple sink\\n\"\r\n\"function sink.simplify(snk)\\n\"\r\n\"    base.assert(snk)\\n\"\r\n\"    return function(chunk, err)\\n\"\r\n\"        local ret, err_or_new = snk(chunk, err)\\n\"\r\n\"        if not ret then return nil, err_or_new end\\n\"\r\n\"        snk = err_or_new or snk\\n\"\r\n\"        return 1\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates a file sink\\n\"\r\n\"function sink.file(handle, io_err)\\n\"\r\n\"    if handle then\\n\"\r\n\"        return function(chunk, err)\\n\"\r\n\"            if not chunk then\\n\"\r\n\"                handle:close()\\n\"\r\n\"                return 1\\n\"\r\n\"            else return handle:write(chunk) end\\n\"\r\n\"        end\\n\"\r\n\"    else return sink.error(io_err or \\\"unable to open file\\\") end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates a sink that discards data\\n\"\r\n\"local function null()\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function sink.null()\\n\"\r\n\"    return null\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- creates a sink that just returns an error\\n\"\r\n\"function sink.error(err)\\n\"\r\n\"    return function()\\n\"\r\n\"        return nil, err\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- chains a sink with a filter\\n\"\r\n\"function sink.chain(f, snk)\\n\"\r\n\"    base.assert(f and snk)\\n\"\r\n\"    return function(chunk, err)\\n\"\r\n\"        if chunk ~= \\\"\\\" then\\n\"\r\n\"            local filtered = f(chunk)\\n\"\r\n\"            local done = chunk and \\\"\\\"\\n\"\r\n\"            while true do\\n\"\r\n\"                local ret, snkerr = snk(filtered, err)\\n\"\r\n\"                if not ret then return nil, snkerr end\\n\"\r\n\"                if filtered == done then return 1 end\\n\"\r\n\"                filtered = f(done)\\n\"\r\n\"            end\\n\"\r\n\"        else return 1 end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Pump stuff\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- pumps one chunk from the source to the sink\\n\"\r\n\"function pump.step(src, snk)\\n\"\r\n\"    local chunk, src_err = src()\\n\"\r\n\"    local ret, snk_err = snk(chunk, src_err)\\n\"\r\n\"    if chunk and ret then return 1\\n\"\r\n\"    else return nil, src_err or snk_err end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- pumps all data from a source to a sink, using a step function\\n\"\r\n\"function pump.all(src, snk, step)\\n\"\r\n\"    base.assert(src and snk)\\n\"\r\n\"    step = step or pump.step\\n\"\r\n\"    while true do\\n\"\r\n\"        local ret, err = step(src, snk)\\n\"\r\n\"        if not ret then\\n\"\r\n\"            if err then return nil, err\\n\"\r\n\"            else return 1 end\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* mime */\r\nstatic const char *lua_m_mime = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- MIME support for the Lua language.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-- Conforming to RFCs 2045-2049\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local base = _G\\n\"\r\n\"local ltn12 = require(\\\"ltn12\\\")\\n\"\r\n\"local mime = require(\\\"mime.core\\\")\\n\"\r\n\"local io = require(\\\"io\\\")\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local _M = mime\\n\"\r\n\"\\n\"\r\n\"-- encode, decode and wrap algorithm tables\\n\"\r\n\"local encodet, decodet, wrapt = {},{},{}\\n\"\r\n\"\\n\"\r\n\"_M.encodet = encodet\\n\"\r\n\"_M.decodet = decodet\\n\"\r\n\"_M.wrapt   = wrapt  \\n\"\r\n\"\\n\"\r\n\"-- creates a function that chooses a filter by name from a given table\\n\"\r\n\"local function choose(table)\\n\"\r\n\"    return function(name, opt1, opt2)\\n\"\r\n\"        if base.type(name) ~= \\\"string\\\" then\\n\"\r\n\"            name, opt1, opt2 = \\\"default\\\", name, opt1\\n\"\r\n\"        end\\n\"\r\n\"        local f = table[name or \\\"nil\\\"]\\n\"\r\n\"        if not f then \\n\"\r\n\"            base.error(\\\"unknown key (\\\" .. base.tostring(name) .. \\\")\\\", 3)\\n\"\r\n\"        else return f(opt1, opt2) end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- define the encoding filters\\n\"\r\n\"encodet['base64'] = function()\\n\"\r\n\"    return ltn12.filter.cycle(_M.b64, \\\"\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"encodet['quoted-printable'] = function(mode)\\n\"\r\n\"    return ltn12.filter.cycle(_M.qp, \\\"\\\",\\n\"\r\n\"        (mode == \\\"binary\\\") and \\\"=0D=0A\\\" or \\\"\\\\r\\\\n\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- define the decoding filters\\n\"\r\n\"decodet['base64'] = function()\\n\"\r\n\"    return ltn12.filter.cycle(_M.unb64, \\\"\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"decodet['quoted-printable'] = function()\\n\"\r\n\"    return ltn12.filter.cycle(_M.unqp, \\\"\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function format(chunk)\\n\"\r\n\"    if chunk then\\n\"\r\n\"        if chunk == \\\"\\\" then return \\\"''\\\"\\n\"\r\n\"        else return string.len(chunk) end\\n\"\r\n\"    else return \\\"nil\\\" end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- define the line-wrap filters\\n\"\r\n\"wrapt['text'] = function(length)\\n\"\r\n\"    length = length or 76\\n\"\r\n\"    return ltn12.filter.cycle(_M.wrp, length, length)\\n\"\r\n\"end\\n\"\r\n\"wrapt['base64'] = wrapt['text']\\n\"\r\n\"wrapt['default'] = wrapt['text']\\n\"\r\n\"\\n\"\r\n\"wrapt['quoted-printable'] = function()\\n\"\r\n\"    return ltn12.filter.cycle(_M.qpwrp, 76, 76)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- function that choose the encoding, decoding or wrap algorithm\\n\"\r\n\"_M.encode = choose(encodet)\\n\"\r\n\"_M.decode = choose(decodet)\\n\"\r\n\"_M.wrap = choose(wrapt)\\n\"\r\n\"\\n\"\r\n\"-- define the end-of-line normalization filter\\n\"\r\n\"function _M.normalize(marker)\\n\"\r\n\"    return ltn12.filter.cycle(_M.eol, 0, marker)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- high level stuffing filter\\n\"\r\n\"function _M.stuff()\\n\"\r\n\"    return ltn12.filter.cycle(_M.dot, 2)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"return _M\\n\";\r\n\r\n/* socket.ftp */\r\nstatic const char *lua_m_socket_ftp = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- FTP support for the Lua language\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local base = _G\\n\"\r\n\"local table = require(\\\"table\\\")\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local math = require(\\\"math\\\")\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"local url = require(\\\"socket.url\\\")\\n\"\r\n\"local tp = require(\\\"socket.tp\\\")\\n\"\r\n\"local ltn12 = require(\\\"ltn12\\\")\\n\"\r\n\"socket.ftp = {}\\n\"\r\n\"local _M = socket.ftp\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Program constants\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- timeout in seconds before the program gives up on a connection\\n\"\r\n\"_M.TIMEOUT = 60\\n\"\r\n\"-- default port for ftp service\\n\"\r\n\"_M.PORT = 21\\n\"\r\n\"-- this is the default anonymous password. used when no password is\\n\"\r\n\"-- provided in url. should be changed to your e-mail.\\n\"\r\n\"_M.USER = \\\"ftp\\\"\\n\"\r\n\"_M.PASSWORD = \\\"anonymous@anonymous.org\\\"\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Low level FTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local metat = { __index = {} }\\n\"\r\n\"\\n\"\r\n\"function _M.open(server, port, create)\\n\"\r\n\"    local tp = socket.try(tp.connect(server, port or _M.PORT, _M.TIMEOUT, create))\\n\"\r\n\"    local f = base.setmetatable({ tp = tp }, metat)\\n\"\r\n\"    -- make sure everything gets closed in an exception\\n\"\r\n\"    f.try = socket.newtry(function() f:close() end)\\n\"\r\n\"    return f\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:portconnect()\\n\"\r\n\"    self.try(self.server:settimeout(_M.TIMEOUT))\\n\"\r\n\"    self.data = self.try(self.server:accept())\\n\"\r\n\"    self.try(self.data:settimeout(_M.TIMEOUT))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:pasvconnect()\\n\"\r\n\"    self.data = self.try(socket.tcp())\\n\"\r\n\"    self.try(self.data:settimeout(_M.TIMEOUT))\\n\"\r\n\"    self.try(self.data:connect(self.pasvt.ip, self.pasvt.port))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:login(user, password)\\n\"\r\n\"    self.try(self.tp:command(\\\"user\\\", user or _M.USER))\\n\"\r\n\"    local code, reply = self.try(self.tp:check{\\\"2..\\\", 331})\\n\"\r\n\"    if code == 331 then\\n\"\r\n\"        self.try(self.tp:command(\\\"pass\\\", password or _M.PASSWORD))\\n\"\r\n\"        self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"    end\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:pasv()\\n\"\r\n\"    self.try(self.tp:command(\\\"pasv\\\"))\\n\"\r\n\"    local code, reply = self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"    local pattern = \\\"(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)\\\"\\n\"\r\n\"    local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern))\\n\"\r\n\"    self.try(a and b and c and d and p1 and p2, reply)\\n\"\r\n\"    self.pasvt = {\\n\"\r\n\"        ip = string.format(\\\"%d.%d.%d.%d\\\", a, b, c, d),\\n\"\r\n\"        port = p1*256 + p2\\n\"\r\n\"    }\\n\"\r\n\"    if self.server then\\n\"\r\n\"        self.server:close()\\n\"\r\n\"        self.server = nil\\n\"\r\n\"    end\\n\"\r\n\"    return self.pasvt.ip, self.pasvt.port\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:port(ip, port)\\n\"\r\n\"    self.pasvt = nil\\n\"\r\n\"    if not ip then\\n\"\r\n\"        ip, port = self.try(self.tp:getcontrol():getsockname())\\n\"\r\n\"        self.server = self.try(socket.bind(ip, 0))\\n\"\r\n\"        ip, port = self.try(self.server:getsockname())\\n\"\r\n\"        self.try(self.server:settimeout(_M.TIMEOUT))\\n\"\r\n\"    end\\n\"\r\n\"    local pl = math.mod(port, 256)\\n\"\r\n\"    local ph = (port - pl)/256\\n\"\r\n\"    local arg = string.gsub(string.format(\\\"%s,%d,%d\\\", ip, ph, pl), \\\"%.\\\", \\\",\\\")\\n\"\r\n\"    self.try(self.tp:command(\\\"port\\\", arg))\\n\"\r\n\"    self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:send(sendt)\\n\"\r\n\"    self.try(self.pasvt or self.server, \\\"need port or pasv first\\\")\\n\"\r\n\"    -- if there is a pasvt table, we already sent a PASV command\\n\"\r\n\"    -- we just get the data connection into self.data\\n\"\r\n\"    if self.pasvt then self:pasvconnect() end\\n\"\r\n\"    -- get the transfer argument and command\\n\"\r\n\"    local argument = sendt.argument or\\n\"\r\n\"        url.unescape(string.gsub(sendt.path or \\\"\\\", \\\"^[/\\\\\\\\]\\\", \\\"\\\"))\\n\"\r\n\"    if argument == \\\"\\\" then argument = nil end\\n\"\r\n\"    local command = sendt.command or \\\"stor\\\"\\n\"\r\n\"    -- send the transfer command and check the reply\\n\"\r\n\"    self.try(self.tp:command(command, argument))\\n\"\r\n\"    local code, reply = self.try(self.tp:check{\\\"2..\\\", \\\"1..\\\"})\\n\"\r\n\"    -- if there is not a a pasvt table, then there is a server\\n\"\r\n\"    -- and we already sent a PORT command\\n\"\r\n\"    if not self.pasvt then self:portconnect() end\\n\"\r\n\"    -- get the sink, source and step for the transfer\\n\"\r\n\"    local step = sendt.step or ltn12.pump.step\\n\"\r\n\"    local readt = {self.tp.c}\\n\"\r\n\"    local checkstep = function(src, snk)\\n\"\r\n\"        -- check status in control connection while downloading\\n\"\r\n\"        local readyt = socket.select(readt, nil, 0)\\n\"\r\n\"        if readyt[tp] then code = self.try(self.tp:check(\\\"2..\\\")) end\\n\"\r\n\"        return step(src, snk)\\n\"\r\n\"    end\\n\"\r\n\"    local sink = socket.sink(\\\"close-when-done\\\", self.data)\\n\"\r\n\"    -- transfer all data and check error\\n\"\r\n\"    self.try(ltn12.pump.all(sendt.source, sink, checkstep))\\n\"\r\n\"    if string.find(code, \\\"1..\\\") then self.try(self.tp:check(\\\"2..\\\")) end\\n\"\r\n\"    -- done with data connection\\n\"\r\n\"    self.data:close()\\n\"\r\n\"    -- find out how many bytes were sent\\n\"\r\n\"    local sent = socket.skip(1, self.data:getstats())\\n\"\r\n\"    self.data = nil\\n\"\r\n\"    return sent\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receive(recvt)\\n\"\r\n\"    self.try(self.pasvt or self.server, \\\"need port or pasv first\\\")\\n\"\r\n\"    if self.pasvt then self:pasvconnect() end\\n\"\r\n\"    local argument = recvt.argument or\\n\"\r\n\"        url.unescape(string.gsub(recvt.path or \\\"\\\", \\\"^[/\\\\\\\\]\\\", \\\"\\\"))\\n\"\r\n\"    if argument == \\\"\\\" then argument = nil end\\n\"\r\n\"    local command = recvt.command or \\\"retr\\\"\\n\"\r\n\"    self.try(self.tp:command(command, argument))\\n\"\r\n\"    local code,reply = self.try(self.tp:check{\\\"1..\\\", \\\"2..\\\"})\\n\"\r\n\"    if (code >= 200) and (code <= 299) then\\n\"\r\n\"        recvt.sink(reply)\\n\"\r\n\"        return 1\\n\"\r\n\"    end\\n\"\r\n\"    if not self.pasvt then self:portconnect() end\\n\"\r\n\"    local source = socket.source(\\\"until-closed\\\", self.data)\\n\"\r\n\"    local step = recvt.step or ltn12.pump.step\\n\"\r\n\"    self.try(ltn12.pump.all(source, recvt.sink, step))\\n\"\r\n\"    if string.find(code, \\\"1..\\\") then self.try(self.tp:check(\\\"2..\\\")) end\\n\"\r\n\"    self.data:close()\\n\"\r\n\"    self.data = nil\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:cwd(dir)\\n\"\r\n\"    self.try(self.tp:command(\\\"cwd\\\", dir))\\n\"\r\n\"    self.try(self.tp:check(250))\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:type(type)\\n\"\r\n\"    self.try(self.tp:command(\\\"type\\\", type))\\n\"\r\n\"    self.try(self.tp:check(200))\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:greet()\\n\"\r\n\"    local code = self.try(self.tp:check{\\\"1..\\\", \\\"2..\\\"})\\n\"\r\n\"    if string.find(code, \\\"1..\\\") then self.try(self.tp:check(\\\"2..\\\")) end\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:quit()\\n\"\r\n\"    self.try(self.tp:command(\\\"quit\\\"))\\n\"\r\n\"    self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:close()\\n\"\r\n\"    if self.data then self.data:close() end\\n\"\r\n\"    if self.server then self.server:close() end\\n\"\r\n\"    return self.tp:close()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- High level FTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local function override(t)\\n\"\r\n\"    if t.url then\\n\"\r\n\"        local u = url.parse(t.url)\\n\"\r\n\"        for i,v in base.pairs(t) do\\n\"\r\n\"            u[i] = v\\n\"\r\n\"        end\\n\"\r\n\"        return u\\n\"\r\n\"    else return t end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function tput(putt)\\n\"\r\n\"    putt = override(putt)\\n\"\r\n\"    socket.try(putt.host, \\\"missing hostname\\\")\\n\"\r\n\"    local f = _M.open(putt.host, putt.port, putt.create)\\n\"\r\n\"    f:greet()\\n\"\r\n\"    f:login(putt.user, putt.password)\\n\"\r\n\"    if putt.type then f:type(putt.type) end\\n\"\r\n\"    f:pasv()\\n\"\r\n\"    local sent = f:send(putt)\\n\"\r\n\"    f:quit()\\n\"\r\n\"    f:close()\\n\"\r\n\"    return sent\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local default = {\\n\"\r\n\"    path = \\\"/\\\",\\n\"\r\n\"    scheme = \\\"ftp\\\"\\n\"\r\n\"}\\n\"\r\n\"\\n\"\r\n\"local function parse(u)\\n\"\r\n\"    local t = socket.try(url.parse(u, default))\\n\"\r\n\"    socket.try(t.scheme == \\\"ftp\\\", \\\"wrong scheme '\\\" .. t.scheme .. \\\"'\\\")\\n\"\r\n\"    socket.try(t.host, \\\"missing hostname\\\")\\n\"\r\n\"    local pat = \\\"^type=(.)$\\\"\\n\"\r\n\"    if t.params then\\n\"\r\n\"        t.type = socket.skip(2, string.find(t.params, pat))\\n\"\r\n\"        socket.try(t.type == \\\"a\\\" or t.type == \\\"i\\\",\\n\"\r\n\"            \\\"invalid type '\\\" .. t.type .. \\\"'\\\")\\n\"\r\n\"    end\\n\"\r\n\"    return t\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function sput(u, body)\\n\"\r\n\"    local putt = parse(u)\\n\"\r\n\"    putt.source = ltn12.source.string(body)\\n\"\r\n\"    return tput(putt)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"_M.put = socket.protect(function(putt, body)\\n\"\r\n\"    if base.type(putt) == \\\"string\\\" then return sput(putt, body)\\n\"\r\n\"    else return tput(putt) end\\n\"\r\n\"end)\\n\"\r\n\"\\n\"\r\n\"local function tget(gett)\\n\"\r\n\"    gett = override(gett)\\n\"\r\n\"    socket.try(gett.host, \\\"missing hostname\\\")\\n\"\r\n\"    local f = _M.open(gett.host, gett.port, gett.create)\\n\"\r\n\"    f:greet()\\n\"\r\n\"    f:login(gett.user, gett.password)\\n\"\r\n\"    if gett.type then f:type(gett.type) end\\n\"\r\n\"    f:pasv()\\n\"\r\n\"    f:receive(gett)\\n\"\r\n\"    f:quit()\\n\"\r\n\"    return f:close()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function sget(u)\\n\"\r\n\"    local gett = parse(u)\\n\"\r\n\"    local t = {}\\n\"\r\n\"    gett.sink = ltn12.sink.table(t)\\n\"\r\n\"    tget(gett)\\n\"\r\n\"    return table.concat(t)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"_M.command = socket.protect(function(cmdt)\\n\"\r\n\"    cmdt = override(cmdt)\\n\"\r\n\"    socket.try(cmdt.host, \\\"missing hostname\\\")\\n\"\r\n\"    socket.try(cmdt.command, \\\"missing command\\\")\\n\"\r\n\"    local f = open(cmdt.host, cmdt.port, cmdt.create)\\n\"\r\n\"    f:greet()\\n\"\r\n\"    f:login(cmdt.user, cmdt.password)\\n\"\r\n\"    f.try(f.tp:command(cmdt.command, cmdt.argument))\\n\"\r\n\"    if cmdt.check then f.try(f.tp:check(cmdt.check)) end\\n\"\r\n\"    f:quit()\\n\"\r\n\"    return f:close()\\n\"\r\n\"end)\\n\"\r\n\"\\n\"\r\n\"_M.get = socket.protect(function(gett)\\n\"\r\n\"    if base.type(gett) == \\\"string\\\" then return sget(gett)\\n\"\r\n\"    else return tget(gett) end\\n\"\r\n\"end)\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.headers */\r\nstatic const char *lua_m_socket_headers = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Canonic header field capitalization\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"socket.headers = {}\\n\"\r\n\"local _M = socket.headers\\n\"\r\n\"\\n\"\r\n\"_M.canonic = {\\n\"\r\n\"    [\\\"accept\\\"] = \\\"Accept\\\",\\n\"\r\n\"    [\\\"accept-charset\\\"] = \\\"Accept-Charset\\\",\\n\"\r\n\"    [\\\"accept-encoding\\\"] = \\\"Accept-Encoding\\\",\\n\"\r\n\"    [\\\"accept-language\\\"] = \\\"Accept-Language\\\",\\n\"\r\n\"    [\\\"accept-ranges\\\"] = \\\"Accept-Ranges\\\",\\n\"\r\n\"    [\\\"action\\\"] = \\\"Action\\\",\\n\"\r\n\"    [\\\"alternate-recipient\\\"] = \\\"Alternate-Recipient\\\",\\n\"\r\n\"    [\\\"age\\\"] = \\\"Age\\\",\\n\"\r\n\"    [\\\"allow\\\"] = \\\"Allow\\\",\\n\"\r\n\"    [\\\"arrival-date\\\"] = \\\"Arrival-Date\\\",\\n\"\r\n\"    [\\\"authorization\\\"] = \\\"Authorization\\\",\\n\"\r\n\"    [\\\"bcc\\\"] = \\\"Bcc\\\",\\n\"\r\n\"    [\\\"cache-control\\\"] = \\\"Cache-Control\\\",\\n\"\r\n\"    [\\\"cc\\\"] = \\\"Cc\\\",\\n\"\r\n\"    [\\\"comments\\\"] = \\\"Comments\\\",\\n\"\r\n\"    [\\\"connection\\\"] = \\\"Connection\\\",\\n\"\r\n\"    [\\\"content-description\\\"] = \\\"Content-Description\\\",\\n\"\r\n\"    [\\\"content-disposition\\\"] = \\\"Content-Disposition\\\",\\n\"\r\n\"    [\\\"content-encoding\\\"] = \\\"Content-Encoding\\\",\\n\"\r\n\"    [\\\"content-id\\\"] = \\\"Content-ID\\\",\\n\"\r\n\"    [\\\"content-language\\\"] = \\\"Content-Language\\\",\\n\"\r\n\"    [\\\"content-length\\\"] = \\\"Content-Length\\\",\\n\"\r\n\"    [\\\"content-location\\\"] = \\\"Content-Location\\\",\\n\"\r\n\"    [\\\"content-md5\\\"] = \\\"Content-MD5\\\",\\n\"\r\n\"    [\\\"content-range\\\"] = \\\"Content-Range\\\",\\n\"\r\n\"    [\\\"content-transfer-encoding\\\"] = \\\"Content-Transfer-Encoding\\\",\\n\"\r\n\"    [\\\"content-type\\\"] = \\\"Content-Type\\\",\\n\"\r\n\"    [\\\"cookie\\\"] = \\\"Cookie\\\",\\n\"\r\n\"    [\\\"date\\\"] = \\\"Date\\\",\\n\"\r\n\"    [\\\"diagnostic-code\\\"] = \\\"Diagnostic-Code\\\",\\n\"\r\n\"    [\\\"dsn-gateway\\\"] = \\\"DSN-Gateway\\\",\\n\"\r\n\"    [\\\"etag\\\"] = \\\"ETag\\\",\\n\"\r\n\"    [\\\"expect\\\"] = \\\"Expect\\\",\\n\"\r\n\"    [\\\"expires\\\"] = \\\"Expires\\\",\\n\"\r\n\"    [\\\"final-log-id\\\"] = \\\"Final-Log-ID\\\",\\n\"\r\n\"    [\\\"final-recipient\\\"] = \\\"Final-Recipient\\\",\\n\"\r\n\"    [\\\"from\\\"] = \\\"From\\\",\\n\"\r\n\"    [\\\"host\\\"] = \\\"Host\\\",\\n\"\r\n\"    [\\\"if-match\\\"] = \\\"If-Match\\\",\\n\"\r\n\"    [\\\"if-modified-since\\\"] = \\\"If-Modified-Since\\\",\\n\"\r\n\"    [\\\"if-none-match\\\"] = \\\"If-None-Match\\\",\\n\"\r\n\"    [\\\"if-range\\\"] = \\\"If-Range\\\",\\n\"\r\n\"    [\\\"if-unmodified-since\\\"] = \\\"If-Unmodified-Since\\\",\\n\"\r\n\"    [\\\"in-reply-to\\\"] = \\\"In-Reply-To\\\",\\n\"\r\n\"    [\\\"keywords\\\"] = \\\"Keywords\\\",\\n\"\r\n\"    [\\\"last-attempt-date\\\"] = \\\"Last-Attempt-Date\\\",\\n\"\r\n\"    [\\\"last-modified\\\"] = \\\"Last-Modified\\\",\\n\"\r\n\"    [\\\"location\\\"] = \\\"Location\\\",\\n\"\r\n\"    [\\\"max-forwards\\\"] = \\\"Max-Forwards\\\",\\n\"\r\n\"    [\\\"message-id\\\"] = \\\"Message-ID\\\",\\n\"\r\n\"    [\\\"mime-version\\\"] = \\\"MIME-Version\\\",\\n\"\r\n\"    [\\\"original-envelope-id\\\"] = \\\"Original-Envelope-ID\\\",\\n\"\r\n\"    [\\\"original-recipient\\\"] = \\\"Original-Recipient\\\",\\n\"\r\n\"    [\\\"pragma\\\"] = \\\"Pragma\\\",\\n\"\r\n\"    [\\\"proxy-authenticate\\\"] = \\\"Proxy-Authenticate\\\",\\n\"\r\n\"    [\\\"proxy-authorization\\\"] = \\\"Proxy-Authorization\\\",\\n\"\r\n\"    [\\\"range\\\"] = \\\"Range\\\",\\n\"\r\n\"    [\\\"received\\\"] = \\\"Received\\\",\\n\"\r\n\"    [\\\"received-from-mta\\\"] = \\\"Received-From-MTA\\\",\\n\"\r\n\"    [\\\"references\\\"] = \\\"References\\\",\\n\"\r\n\"    [\\\"referer\\\"] = \\\"Referer\\\",\\n\"\r\n\"    [\\\"remote-mta\\\"] = \\\"Remote-MTA\\\",\\n\"\r\n\"    [\\\"reply-to\\\"] = \\\"Reply-To\\\",\\n\"\r\n\"    [\\\"reporting-mta\\\"] = \\\"Reporting-MTA\\\",\\n\"\r\n\"    [\\\"resent-bcc\\\"] = \\\"Resent-Bcc\\\",\\n\"\r\n\"    [\\\"resent-cc\\\"] = \\\"Resent-Cc\\\",\\n\"\r\n\"    [\\\"resent-date\\\"] = \\\"Resent-Date\\\",\\n\"\r\n\"    [\\\"resent-from\\\"] = \\\"Resent-From\\\",\\n\"\r\n\"    [\\\"resent-message-id\\\"] = \\\"Resent-Message-ID\\\",\\n\"\r\n\"    [\\\"resent-reply-to\\\"] = \\\"Resent-Reply-To\\\",\\n\"\r\n\"    [\\\"resent-sender\\\"] = \\\"Resent-Sender\\\",\\n\"\r\n\"    [\\\"resent-to\\\"] = \\\"Resent-To\\\",\\n\"\r\n\"    [\\\"retry-after\\\"] = \\\"Retry-After\\\",\\n\"\r\n\"    [\\\"return-path\\\"] = \\\"Return-Path\\\",\\n\"\r\n\"    [\\\"sender\\\"] = \\\"Sender\\\",\\n\"\r\n\"    [\\\"server\\\"] = \\\"Server\\\",\\n\"\r\n\"    [\\\"smtp-remote-recipient\\\"] = \\\"SMTP-Remote-Recipient\\\",\\n\"\r\n\"    [\\\"status\\\"] = \\\"Status\\\",\\n\"\r\n\"    [\\\"subject\\\"] = \\\"Subject\\\",\\n\"\r\n\"    [\\\"te\\\"] = \\\"TE\\\",\\n\"\r\n\"    [\\\"to\\\"] = \\\"To\\\",\\n\"\r\n\"    [\\\"trailer\\\"] = \\\"Trailer\\\",\\n\"\r\n\"    [\\\"transfer-encoding\\\"] = \\\"Transfer-Encoding\\\",\\n\"\r\n\"    [\\\"upgrade\\\"] = \\\"Upgrade\\\",\\n\"\r\n\"    [\\\"user-agent\\\"] = \\\"User-Agent\\\",\\n\"\r\n\"    [\\\"vary\\\"] = \\\"Vary\\\",\\n\"\r\n\"    [\\\"via\\\"] = \\\"Via\\\",\\n\"\r\n\"    [\\\"warning\\\"] = \\\"Warning\\\",\\n\"\r\n\"    [\\\"will-retry-until\\\"] = \\\"Will-Retry-Until\\\",\\n\"\r\n\"    [\\\"www-authenticate\\\"] = \\\"WWW-Authenticate\\\",\\n\"\r\n\"    [\\\"x-mailer\\\"] = \\\"X-Mailer\\\",\\n\"\r\n\"}\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.http */\r\nstatic const char *lua_m_socket_http = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- HTTP/1.1 client support for the Lua language.\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-------------------------------------------------------------------------------\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"local url = require(\\\"socket.url\\\")\\n\"\r\n\"local ltn12 = require(\\\"socket.ltn12\\\")\\n\"\r\n\"local mime = require(\\\"socket.mime\\\")\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local headers = require(\\\"socket.headers\\\")\\n\"\r\n\"local base = _G\\n\"\r\n\"local table = require(\\\"table\\\")\\n\"\r\n\"socket.http = {}\\n\"\r\n\"local _M = socket.http\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Program constants\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- connection timeout in seconds\\n\"\r\n\"TIMEOUT = 60\\n\"\r\n\"-- default port for document retrieval\\n\"\r\n\"_M.PORT = 80\\n\"\r\n\"-- user agent field sent in request\\n\"\r\n\"_M.USERAGENT = socket._VERSION\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Reads MIME headers from a connection, unfolding where needed\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local function receiveheaders(sock, headers)\\n\"\r\n\"    local line, name, value, err\\n\"\r\n\"    headers = headers or {}\\n\"\r\n\"    -- get first line\\n\"\r\n\"    line, err = sock:receive()\\n\"\r\n\"    if err then return nil, err end\\n\"\r\n\"    -- headers go until a blank line is found\\n\"\r\n\"    while line ~= \\\"\\\" do\\n\"\r\n\"        -- get field-name and value\\n\"\r\n\"        name, value = socket.skip(2, string.find(line, \\\"^(.-):%s*(.*)\\\"))\\n\"\r\n\"        if not (name and value) then return nil, \\\"malformed reponse headers\\\" end\\n\"\r\n\"        name = string.lower(name)\\n\"\r\n\"        -- get next line (value might be folded)\\n\"\r\n\"        line, err  = sock:receive()\\n\"\r\n\"        if err then return nil, err end\\n\"\r\n\"        -- unfold any folded values\\n\"\r\n\"        while string.find(line, \\\"^%s\\\") do\\n\"\r\n\"            value = value .. line\\n\"\r\n\"            line = sock:receive()\\n\"\r\n\"            if err then return nil, err end\\n\"\r\n\"        end\\n\"\r\n\"        -- save pair in table\\n\"\r\n\"        if headers[name] then headers[name] = headers[name] .. \\\", \\\" .. value\\n\"\r\n\"        else headers[name] = value end\\n\"\r\n\"    end\\n\"\r\n\"    return headers\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Extra sources and sinks\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"socket.sourcet[\\\"http-chunked\\\"] = function(sock, headers)\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function()\\n\"\r\n\"            -- get chunk size, skip extention\\n\"\r\n\"            local line, err = sock:receive()\\n\"\r\n\"            if err then return nil, err end\\n\"\r\n\"            local size = base.tonumber(string.gsub(line, \\\";.*\\\", \\\"\\\"), 16)\\n\"\r\n\"            if not size then return nil, \\\"invalid chunk size\\\" end\\n\"\r\n\"            -- was it the last chunk?\\n\"\r\n\"            if size > 0 then\\n\"\r\n\"                -- if not, get chunk and skip terminating CRLF\\n\"\r\n\"                local chunk, err, part = sock:receive(size)\\n\"\r\n\"                if chunk then sock:receive() end\\n\"\r\n\"                return chunk, err\\n\"\r\n\"            else\\n\"\r\n\"                -- if it was, read trailers into headers table\\n\"\r\n\"                headers, err = receiveheaders(sock, headers)\\n\"\r\n\"                if not headers then return nil, err end\\n\"\r\n\"            end\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"socket.sinkt[\\\"http-chunked\\\"] = function(sock)\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function(self, chunk, err)\\n\"\r\n\"            if not chunk then return sock:send(\\\"0\\\\r\\\\n\\\\r\\\\n\\\") end\\n\"\r\n\"            local size = string.format(\\\"%X\\\\r\\\\n\\\", string.len(chunk))\\n\"\r\n\"            return sock:send(size ..  chunk .. \\\"\\\\r\\\\n\\\")\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Low level HTTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local metat = { __index = {} }\\n\"\r\n\"\\n\"\r\n\"function _M.open(host, port, create)\\n\"\r\n\"    -- create socket with user connect function, or with default\\n\"\r\n\"    local c = socket.try((create or socket.tcp)())\\n\"\r\n\"    local h = base.setmetatable({ c = c }, metat)\\n\"\r\n\"    -- create finalized try\\n\"\r\n\"    h.try = socket.newtry(function() h:close() end)\\n\"\r\n\"    -- set timeout before connecting\\n\"\r\n\"    h.try(c:settimeout(_M.TIMEOUT))\\n\"\r\n\"    h.try(c:connect(host, port or _M.PORT))\\n\"\r\n\"    -- here everything worked\\n\"\r\n\"    return h\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:sendrequestline(method, uri)\\n\"\r\n\"    local reqline = string.format(\\\"%s %s HTTP/1.1\\\\r\\\\n\\\", method or \\\"GET\\\", uri)\\n\"\r\n\"    return self.try(self.c:send(reqline))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:sendheaders(tosend)\\n\"\r\n\"    local canonic = headers.canonic\\n\"\r\n\"    local h = \\\"\\\\r\\\\n\\\"\\n\"\r\n\"    for f, v in base.pairs(tosend) do\\n\"\r\n\"        h = (canonic[f] or f) .. \\\": \\\" .. v .. \\\"\\\\r\\\\n\\\" .. h\\n\"\r\n\"    end\\n\"\r\n\"    self.try(self.c:send(h))\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:sendbody(headers, source, step)\\n\"\r\n\"    source = source or ltn12.source.empty()\\n\"\r\n\"    step = step or ltn12.pump.step\\n\"\r\n\"    -- if we don't know the size in advance, send chunked and hope for the best\\n\"\r\n\"    local mode = \\\"http-chunked\\\"\\n\"\r\n\"    if headers[\\\"content-length\\\"] then mode = \\\"keep-open\\\" end\\n\"\r\n\"    return self.try(ltn12.pump.all(source, socket.sink(mode, self.c), step))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receivestatusline()\\n\"\r\n\"    local status = self.try(self.c:receive(5))\\n\"\r\n\"    -- identify HTTP/0.9 responses, which do not contain a status line\\n\"\r\n\"    -- this is just a heuristic, but is what the RFC recommends\\n\"\r\n\"    if status ~= \\\"HTTP/\\\" then return nil, status end\\n\"\r\n\"    -- otherwise proceed reading a status line\\n\"\r\n\"    status = self.try(self.c:receive(\\\"*l\\\", status))\\n\"\r\n\"    local code = socket.skip(2, string.find(status, \\\"HTTP/%d*%.%d* (%d%d%d)\\\"))\\n\"\r\n\"    return self.try(base.tonumber(code), status)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receiveheaders()\\n\"\r\n\"    return self.try(receiveheaders(self.c))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receivebody(headers, sink, step)\\n\"\r\n\"    sink = sink or ltn12.sink.null()\\n\"\r\n\"    step = step or ltn12.pump.step\\n\"\r\n\"    local length = base.tonumber(headers[\\\"content-length\\\"])\\n\"\r\n\"    local t = headers[\\\"transfer-encoding\\\"] -- shortcut\\n\"\r\n\"    local mode = \\\"default\\\" -- connection close\\n\"\r\n\"    if t and t ~= \\\"identity\\\" then mode = \\\"http-chunked\\\"\\n\"\r\n\"    elseif base.tonumber(headers[\\\"content-length\\\"]) then mode = \\\"by-length\\\" end\\n\"\r\n\"    return self.try(ltn12.pump.all(socket.source(mode, self.c, length),\\n\"\r\n\"        sink, step))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receive09body(status, sink, step)\\n\"\r\n\"    local source = ltn12.source.rewind(socket.source(\\\"until-closed\\\", self.c))\\n\"\r\n\"    source(status)\\n\"\r\n\"    return self.try(ltn12.pump.all(source, sink, step))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:close()\\n\"\r\n\"    return self.c:close()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- High level HTTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local function adjusturi(reqt)\\n\"\r\n\"    local u = reqt\\n\"\r\n\"    -- if there is a proxy, we need the full url. otherwise, just a part.\\n\"\r\n\"    if not reqt.proxy and not PROXY then\\n\"\r\n\"        u = {\\n\"\r\n\"           path = socket.try(reqt.path, \\\"invalid path 'nil'\\\"),\\n\"\r\n\"           params = reqt.params,\\n\"\r\n\"           query = reqt.query,\\n\"\r\n\"           fragment = reqt.fragment\\n\"\r\n\"        }\\n\"\r\n\"    end\\n\"\r\n\"    return url.build(u)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function adjustproxy(reqt)\\n\"\r\n\"    local proxy = reqt.proxy or PROXY\\n\"\r\n\"    if proxy then\\n\"\r\n\"        proxy = url.parse(proxy)\\n\"\r\n\"        return proxy.host, proxy.port or 3128\\n\"\r\n\"    else\\n\"\r\n\"        return reqt.host, reqt.port\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function adjustheaders(reqt)\\n\"\r\n\"    -- default headers\\n\"\r\n\"    local lower = {\\n\"\r\n\"        [\\\"user-agent\\\"] = _M.USERAGENT,\\n\"\r\n\"        [\\\"host\\\"] = reqt.host,\\n\"\r\n\"        [\\\"connection\\\"] = \\\"close, TE\\\",\\n\"\r\n\"        [\\\"te\\\"] = \\\"trailers\\\"\\n\"\r\n\"    }\\n\"\r\n\"    -- if we have authentication information, pass it along\\n\"\r\n\"    if reqt.user and reqt.password then\\n\"\r\n\"        lower[\\\"authorization\\\"] =\\n\"\r\n\"            \\\"Basic \\\" ..  (mime.b64(reqt.user .. \\\":\\\" .. reqt.password))\\n\"\r\n\"    end\\n\"\r\n\"    -- override with user headers\\n\"\r\n\"    for i,v in base.pairs(reqt.headers or lower) do\\n\"\r\n\"        lower[string.lower(i)] = v\\n\"\r\n\"    end\\n\"\r\n\"    return lower\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- default url parts\\n\"\r\n\"local default = {\\n\"\r\n\"    host = \\\"\\\",\\n\"\r\n\"    port = _M.PORT,\\n\"\r\n\"    path =\\\"/\\\",\\n\"\r\n\"    scheme = \\\"http\\\"\\n\"\r\n\"}\\n\"\r\n\"\\n\"\r\n\"local function adjustrequest(reqt)\\n\"\r\n\"    -- parse url if provided\\n\"\r\n\"    local nreqt = reqt.url and url.parse(reqt.url, default) or {}\\n\"\r\n\"    -- explicit components override url\\n\"\r\n\"    for i,v in base.pairs(reqt) do nreqt[i] = v end\\n\"\r\n\"    if nreqt.port == \\\"\\\" then nreqt.port = 80 end\\n\"\r\n\"    socket.try(nreqt.host and nreqt.host ~= \\\"\\\",\\n\"\r\n\"        \\\"invalid host '\\\" .. base.tostring(nreqt.host) .. \\\"'\\\")\\n\"\r\n\"    -- compute uri if user hasn't overriden\\n\"\r\n\"    nreqt.uri = reqt.uri or adjusturi(nreqt)\\n\"\r\n\"    -- ajust host and port if there is a proxy\\n\"\r\n\"    nreqt.host, nreqt.port = adjustproxy(nreqt)\\n\"\r\n\"    -- adjust headers in request\\n\"\r\n\"    nreqt.headers = adjustheaders(nreqt)\\n\"\r\n\"    return nreqt\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function shouldredirect(reqt, code, headers)\\n\"\r\n\"    return headers.location and\\n\"\r\n\"           string.gsub(headers.location, \\\"%s\\\", \\\"\\\") ~= \\\"\\\" and\\n\"\r\n\"           (reqt.redirect ~= false) and\\n\"\r\n\"           (code == 301 or code == 302 or code == 303 or code == 307) and\\n\"\r\n\"           (not reqt.method or reqt.method == \\\"GET\\\" or reqt.method == \\\"HEAD\\\")\\n\"\r\n\"           and (not reqt.nredirects or reqt.nredirects < 5)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function shouldreceivebody(reqt, code)\\n\"\r\n\"    if reqt.method == \\\"HEAD\\\" then return nil end\\n\"\r\n\"    if code == 204 or code == 304 then return nil end\\n\"\r\n\"    if code >= 100 and code < 200 then return nil end\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- forward declarations\\n\"\r\n\"local trequest, tredirect\\n\"\r\n\"\\n\"\r\n\"--[[local]] function tredirect(reqt, location)\\n\"\r\n\"    local result, code, headers, status = trequest {\\n\"\r\n\"        -- the RFC says the redirect URL has to be absolute, but some\\n\"\r\n\"        -- servers do not respect that\\n\"\r\n\"        url = url.absolute(reqt.url, location),\\n\"\r\n\"        source = reqt.source,\\n\"\r\n\"        sink = reqt.sink,\\n\"\r\n\"        headers = reqt.headers,\\n\"\r\n\"        proxy = reqt.proxy,\\n\"\r\n\"        nredirects = (reqt.nredirects or 0) + 1,\\n\"\r\n\"        create = reqt.create\\n\"\r\n\"    }\\n\"\r\n\"    -- pass location header back as a hint we redirected\\n\"\r\n\"    headers = headers or {}\\n\"\r\n\"    headers.location = headers.location or location\\n\"\r\n\"    return result, code, headers, status\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"--[[local]] function trequest(reqt)\\n\"\r\n\"    -- we loop until we get what we want, or\\n\"\r\n\"    -- until we are sure there is no way to get it\\n\"\r\n\"    local nreqt = adjustrequest(reqt)\\n\"\r\n\"    local h = _M.open(nreqt.host, nreqt.port, nreqt.create)\\n\"\r\n\"    -- send request line and headers\\n\"\r\n\"    h:sendrequestline(nreqt.method, nreqt.uri)\\n\"\r\n\"    h:sendheaders(nreqt.headers)\\n\"\r\n\"    -- if there is a body, send it\\n\"\r\n\"    if nreqt.source then\\n\"\r\n\"        h:sendbody(nreqt.headers, nreqt.source, nreqt.step)\\n\"\r\n\"    end\\n\"\r\n\"    local code, status = h:receivestatusline()\\n\"\r\n\"    -- if it is an HTTP/0.9 server, simply get the body and we are done\\n\"\r\n\"    if not code then\\n\"\r\n\"        h:receive09body(status, nreqt.sink, nreqt.step)\\n\"\r\n\"        return 1, 200\\n\"\r\n\"    end\\n\"\r\n\"    local headers\\n\"\r\n\"    -- ignore any 100-continue messages\\n\"\r\n\"    while code == 100 do\\n\"\r\n\"        headers = h:receiveheaders()\\n\"\r\n\"        code, status = h:receivestatusline()\\n\"\r\n\"    end\\n\"\r\n\"    headers = h:receiveheaders()\\n\"\r\n\"    -- at this point we should have a honest reply from the server\\n\"\r\n\"    -- we can't redirect if we already used the source, so we report the error\\n\"\r\n\"    if shouldredirect(nreqt, code, headers) and not nreqt.source then\\n\"\r\n\"        h:close()\\n\"\r\n\"        return tredirect(reqt, headers.location)\\n\"\r\n\"    end\\n\"\r\n\"    -- here we are finally done\\n\"\r\n\"    if shouldreceivebody(nreqt, code) then\\n\"\r\n\"        h:receivebody(headers, nreqt.sink, nreqt.step)\\n\"\r\n\"    end\\n\"\r\n\"    h:close()\\n\"\r\n\"    return 1, code, headers, status\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"local function srequest(u, b)\\n\"\r\n\"    local t = {}\\n\"\r\n\"    local reqt = {\\n\"\r\n\"        url = u,\\n\"\r\n\"        sink = ltn12.sink.table(t)\\n\"\r\n\"    }\\n\"\r\n\"    if b then\\n\"\r\n\"        reqt.source = ltn12.source.string(b)\\n\"\r\n\"        reqt.headers = {\\n\"\r\n\"            [\\\"content-length\\\"] = string.len(b),\\n\"\r\n\"            [\\\"content-type\\\"] = \\\"application/x-www-form-urlencoded\\\"\\n\"\r\n\"        }\\n\"\r\n\"        reqt.method = \\\"POST\\\"\\n\"\r\n\"    end\\n\"\r\n\"    local code, headers, status = socket.skip(1, trequest(reqt))\\n\"\r\n\"    return table.concat(t), code, headers, status\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"_M.request = socket.protect(function(reqt, body)\\n\"\r\n\"    if base.type(reqt) == \\\"string\\\" then return srequest(reqt, body)\\n\"\r\n\"    else return trequest(reqt) end\\n\"\r\n\"end)\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.mbox */\r\nstatic const char *lua_m_socket_mbox = \r\n\"local _M = {}\\n\"\r\n\"\\n\"\r\n\"if module then\\n\"\r\n\"    mbox = _M\\n\"\r\n\"end \\n\"\r\n\"\\n\"\r\n\"function _M.split_message(message_s)\\n\"\r\n\"    local message = {}\\n\"\r\n\"    message_s = string.gsub(message_s, \\\"\\\\r\\\\n\\\", \\\"\\\\n\\\")\\n\"\r\n\"    string.gsub(message_s, \\\"^(.-\\\\n)\\\\n\\\", function (h) message.headers = h end)\\n\"\r\n\"    string.gsub(message_s, \\\"^.-\\\\n\\\\n(.*)\\\", function (b) message.body = b end)\\n\"\r\n\"    if not message.body then\\n\"\r\n\"        string.gsub(message_s, \\\"^\\\\n(.*)\\\", function (b) message.body = b end)\\n\"\r\n\"    end\\n\"\r\n\"    if not message.headers and not message.body then\\n\"\r\n\"        message.headers = message_s\\n\"\r\n\"    end\\n\"\r\n\"    return message.headers or \\\"\\\", message.body or \\\"\\\"\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.split_headers(headers_s)\\n\"\r\n\"    local headers = {}\\n\"\r\n\"    headers_s = string.gsub(headers_s, \\\"\\\\r\\\\n\\\", \\\"\\\\n\\\")\\n\"\r\n\"    headers_s = string.gsub(headers_s, \\\"\\\\n[ ]+\\\", \\\" \\\")\\n\"\r\n\"    string.gsub(\\\"\\\\n\\\" .. headers_s, \\\"\\\\n([^\\\\n]+)\\\", function (h) table.insert(headers, h) end)\\n\"\r\n\"    return headers\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.parse_header(header_s)\\n\"\r\n\"    header_s = string.gsub(header_s, \\\"\\\\n[ ]+\\\", \\\" \\\")\\n\"\r\n\"    header_s = string.gsub(header_s, \\\"\\\\n+\\\", \\\"\\\")\\n\"\r\n\"    local _, __, name, value = string.find(header_s, \\\"([^%s:]-):%s*(.*)\\\")\\n\"\r\n\"    return name, value\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.parse_headers(headers_s)\\n\"\r\n\"    local headers_t = _M.split_headers(headers_s)\\n\"\r\n\"    local headers = {}\\n\"\r\n\"    for i = 1, #headers_t do\\n\"\r\n\"        local name, value = _M.parse_header(headers_t[i])\\n\"\r\n\"        if name then\\n\"\r\n\"            name = string.lower(name)\\n\"\r\n\"            if headers[name] then\\n\"\r\n\"                headers[name] = headers[name] .. \\\", \\\" .. value\\n\"\r\n\"            else headers[name] = value end\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"    return headers\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.parse_from(from)\\n\"\r\n\"    local _, __, name, address = string.find(from, \\\"^%s*(.-)%s*%<(.-)%>\\\")\\n\"\r\n\"    if not address then\\n\"\r\n\"        _, __, address = string.find(from, \\\"%s*(.+)%s*\\\")\\n\"\r\n\"    end\\n\"\r\n\"    name = name or \\\"\\\"\\n\"\r\n\"    address = address or \\\"\\\"\\n\"\r\n\"    if name == \\\"\\\" then name = address end\\n\"\r\n\"    name = string.gsub(name, '\\\"', \\\"\\\")\\n\"\r\n\"    return name, address\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.split_mbox(mbox_s)\\n\"\r\n\"    mbox = {}\\n\"\r\n\"    mbox_s = string.gsub(mbox_s, \\\"\\\\r\\\\n\\\", \\\"\\\\n\\\") ..\\\"\\\\n\\\\nFrom \\\\n\\\"\\n\"\r\n\"    local nj, i, j = 1, 1, 1\\n\"\r\n\"    while 1 do\\n\"\r\n\"        i, nj = string.find(mbox_s, \\\"\\\\n\\\\nFrom .-\\\\n\\\", j)\\n\"\r\n\"        if not i then break end\\n\"\r\n\"        local message = string.sub(mbox_s, j, i-1)\\n\"\r\n\"        table.insert(mbox, message)\\n\"\r\n\"        j = nj+1\\n\"\r\n\"    end\\n\"\r\n\"    return mbox\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.parse(mbox_s)\\n\"\r\n\"    local mbox = _M.split_mbox(mbox_s)\\n\"\r\n\"    for i = 1, #mbox do\\n\"\r\n\"        mbox[i] = _M.parse_message(mbox[i])\\n\"\r\n\"    end\\n\"\r\n\"    return mbox\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.parse_message(message_s)\\n\"\r\n\"    local message = {}\\n\"\r\n\"    message.headers, message.body = _M.split_message(message_s)\\n\"\r\n\"    message.headers = _M.parse_headers(message.headers)\\n\"\r\n\"    return message\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.smtp */\r\nstatic const char *lua_m_socket_smtp = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- SMTP client support for the Lua language.\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local base = _G\\n\"\r\n\"local coroutine = require(\\\"coroutine\\\")\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local math = require(\\\"math\\\")\\n\"\r\n\"local os = require(\\\"os\\\")\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"local tp = require(\\\"socket.tp\\\")\\n\"\r\n\"local ltn12 = require(\\\"socket.ltn12\\\")\\n\"\r\n\"local headers = require(\\\"socket.headers\\\")\\n\"\r\n\"local mime = require(\\\"socket.mime\\\")\\n\"\r\n\"\\n\"\r\n\"socket.smtp = {}\\n\"\r\n\"local _M = socket.smtp\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Program constants\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- timeout for connection\\n\"\r\n\"_M.TIMEOUT = 60\\n\"\r\n\"-- default server used to send e-mails\\n\"\r\n\"_M.SERVER = \\\"localhost\\\"\\n\"\r\n\"-- default port\\n\"\r\n\"_M.PORT = 25\\n\"\r\n\"-- domain used in HELO command and default sendmail\\n\"\r\n\"-- If we are under a CGI, try to get from environment\\n\"\r\n\"_M.DOMAIN = os.getenv(\\\"SERVER_NAME\\\") or \\\"localhost\\\"\\n\"\r\n\"-- default time zone (means we don't know)\\n\"\r\n\"_M.ZONE = \\\"-0000\\\"\\n\"\r\n\"\\n\"\r\n\"---------------------------------------------------------------------------\\n\"\r\n\"-- Low level SMTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local metat = { __index = {} }\\n\"\r\n\"\\n\"\r\n\"function metat.__index:greet(domain)\\n\"\r\n\"    self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"    self.try(self.tp:command(\\\"EHLO\\\", domain or _M.DOMAIN))\\n\"\r\n\"    return socket.skip(1, self.try(self.tp:check(\\\"2..\\\")))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:mail(from)\\n\"\r\n\"    self.try(self.tp:command(\\\"MAIL\\\", \\\"FROM:\\\" .. from))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:rcpt(to)\\n\"\r\n\"    self.try(self.tp:command(\\\"RCPT\\\", \\\"TO:\\\" .. to))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:data(src, step)\\n\"\r\n\"    self.try(self.tp:command(\\\"DATA\\\"))\\n\"\r\n\"    self.try(self.tp:check(\\\"3..\\\"))\\n\"\r\n\"    self.try(self.tp:source(src, step))\\n\"\r\n\"    self.try(self.tp:send(\\\"\\\\r\\\\n.\\\\r\\\\n\\\"))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:quit()\\n\"\r\n\"    self.try(self.tp:command(\\\"QUIT\\\"))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:close()\\n\"\r\n\"    return self.tp:close()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:login(user, password)\\n\"\r\n\"    self.try(self.tp:command(\\\"AUTH\\\", \\\"LOGIN\\\"))\\n\"\r\n\"    self.try(self.tp:check(\\\"3..\\\"))\\n\"\r\n\"    self.try(self.tp:send(mime.b64(user) .. \\\"\\\\r\\\\n\\\"))\\n\"\r\n\"    self.try(self.tp:check(\\\"3..\\\"))\\n\"\r\n\"    self.try(self.tp:send(mime.b64(password) .. \\\"\\\\r\\\\n\\\"))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:plain(user, password)\\n\"\r\n\"    local auth = \\\"PLAIN \\\" .. mime.b64(\\\"\\\\0\\\" .. user .. \\\"\\\\0\\\" .. password)\\n\"\r\n\"    self.try(self.tp:command(\\\"AUTH\\\", auth))\\n\"\r\n\"    return self.try(self.tp:check(\\\"2..\\\"))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:auth(user, password, ext)\\n\"\r\n\"    if not user or not password then return 1 end\\n\"\r\n\"    if string.find(ext, \\\"AUTH[^\\\\n]+LOGIN\\\") then\\n\"\r\n\"        return self:login(user, password)\\n\"\r\n\"    elseif string.find(ext, \\\"AUTH[^\\\\n]+PLAIN\\\") then\\n\"\r\n\"        return self:plain(user, password)\\n\"\r\n\"    else\\n\"\r\n\"        self.try(nil, \\\"authentication not supported\\\")\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- send message or throw an exception\\n\"\r\n\"function metat.__index:send(mailt)\\n\"\r\n\"    self:mail(mailt.from)\\n\"\r\n\"    if base.type(mailt.rcpt) == \\\"table\\\" then\\n\"\r\n\"        for i,v in base.ipairs(mailt.rcpt) do\\n\"\r\n\"            self:rcpt(v)\\n\"\r\n\"        end\\n\"\r\n\"    else\\n\"\r\n\"        self:rcpt(mailt.rcpt)\\n\"\r\n\"    end\\n\"\r\n\"    self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.open(server, port, create)\\n\"\r\n\"    local tp = socket.try(tp.connect(server or _M.SERVER, port or _M.PORT,\\n\"\r\n\"        _M.TIMEOUT, create))\\n\"\r\n\"    local s = base.setmetatable({tp = tp}, metat)\\n\"\r\n\"    -- make sure tp is closed if we get an exception\\n\"\r\n\"    s.try = socket.newtry(function()\\n\"\r\n\"        s:close()\\n\"\r\n\"    end)\\n\"\r\n\"    return s\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- convert headers to lowercase\\n\"\r\n\"local function lower_headers(headers)\\n\"\r\n\"    local lower = {}\\n\"\r\n\"    for i,v in base.pairs(headers or lower) do\\n\"\r\n\"        lower[string.lower(i)] = v\\n\"\r\n\"    end\\n\"\r\n\"    return lower\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"---------------------------------------------------------------------------\\n\"\r\n\"-- Multipart message source\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- returns a hopefully unique mime boundary\\n\"\r\n\"local seqno = 0\\n\"\r\n\"local function newboundary()\\n\"\r\n\"    seqno = seqno + 1\\n\"\r\n\"    return string.format('%s%05d==%05u', os.date('%d%m%Y%H%M%S'),\\n\"\r\n\"        math.random(0, 99999), seqno)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- send_message forward declaration\\n\"\r\n\"local send_message\\n\"\r\n\"\\n\"\r\n\"-- yield the headers all at once, it's faster\\n\"\r\n\"local function send_headers(tosend)\\n\"\r\n\"    local canonic = headers.canonic\\n\"\r\n\"    local h = \\\"\\\\r\\\\n\\\"\\n\"\r\n\"    for f,v in base.pairs(tosend) do\\n\"\r\n\"        h = (canonic[f] or f) .. ': ' .. v .. \\\"\\\\r\\\\n\\\" .. h\\n\"\r\n\"    end\\n\"\r\n\"    coroutine.yield(h)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- yield multipart message body from a multipart message table\\n\"\r\n\"local function send_multipart(mesgt)\\n\"\r\n\"    -- make sure we have our boundary and send headers\\n\"\r\n\"    local bd = newboundary()\\n\"\r\n\"    local headers = lower_headers(mesgt.headers or {})\\n\"\r\n\"    headers['content-type'] = headers['content-type'] or 'multipart/mixed'\\n\"\r\n\"    headers['content-type'] = headers['content-type'] ..\\n\"\r\n\"        '; boundary=\\\"' ..  bd .. '\\\"'\\n\"\r\n\"    send_headers(headers)\\n\"\r\n\"    -- send preamble\\n\"\r\n\"    if mesgt.body.preamble then\\n\"\r\n\"        coroutine.yield(mesgt.body.preamble)\\n\"\r\n\"        coroutine.yield(\\\"\\\\r\\\\n\\\")\\n\"\r\n\"    end\\n\"\r\n\"    -- send each part separated by a boundary\\n\"\r\n\"    for i, m in base.ipairs(mesgt.body) do\\n\"\r\n\"        coroutine.yield(\\\"\\\\r\\\\n--\\\" .. bd .. \\\"\\\\r\\\\n\\\")\\n\"\r\n\"        send_message(m)\\n\"\r\n\"    end\\n\"\r\n\"    -- send last boundary\\n\"\r\n\"    coroutine.yield(\\\"\\\\r\\\\n--\\\" .. bd .. \\\"--\\\\r\\\\n\\\\r\\\\n\\\")\\n\"\r\n\"    -- send epilogue\\n\"\r\n\"    if mesgt.body.epilogue then\\n\"\r\n\"        coroutine.yield(mesgt.body.epilogue)\\n\"\r\n\"        coroutine.yield(\\\"\\\\r\\\\n\\\")\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- yield message body from a source\\n\"\r\n\"local function send_source(mesgt)\\n\"\r\n\"    -- make sure we have a content-type\\n\"\r\n\"    local headers = lower_headers(mesgt.headers or {})\\n\"\r\n\"    headers['content-type'] = headers['content-type'] or\\n\"\r\n\"        'text/plain; charset=\\\"iso-8859-1\\\"'\\n\"\r\n\"    send_headers(headers)\\n\"\r\n\"    -- send body from source\\n\"\r\n\"    while true do\\n\"\r\n\"        local chunk, err = mesgt.body()\\n\"\r\n\"        if err then coroutine.yield(nil, err)\\n\"\r\n\"        elseif chunk then coroutine.yield(chunk)\\n\"\r\n\"        else break end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- yield message body from a string\\n\"\r\n\"local function send_string(mesgt)\\n\"\r\n\"    -- make sure we have a content-type\\n\"\r\n\"    local headers = lower_headers(mesgt.headers or {})\\n\"\r\n\"    headers['content-type'] = headers['content-type'] or\\n\"\r\n\"        'text/plain; charset=\\\"iso-8859-1\\\"'\\n\"\r\n\"    send_headers(headers)\\n\"\r\n\"    -- send body from string\\n\"\r\n\"    coroutine.yield(mesgt.body)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- message source\\n\"\r\n\"function send_message(mesgt)\\n\"\r\n\"    if base.type(mesgt.body) == \\\"table\\\" then send_multipart(mesgt)\\n\"\r\n\"    elseif base.type(mesgt.body) == \\\"function\\\" then send_source(mesgt)\\n\"\r\n\"    else send_string(mesgt) end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- set defaul headers\\n\"\r\n\"local function adjust_headers(mesgt)\\n\"\r\n\"    local lower = lower_headers(mesgt.headers)\\n\"\r\n\"    lower[\\\"date\\\"] = lower[\\\"date\\\"] or\\n\"\r\n\"        os.date(\\\"!%a, %d %b %Y %H:%M:%S \\\") .. (mesgt.zone or _M.ZONE)\\n\"\r\n\"    lower[\\\"x-mailer\\\"] = lower[\\\"x-mailer\\\"] or socket._VERSION\\n\"\r\n\"    -- this can't be overriden\\n\"\r\n\"    lower[\\\"mime-version\\\"] = \\\"1.0\\\"\\n\"\r\n\"    return lower\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.message(mesgt)\\n\"\r\n\"    mesgt.headers = adjust_headers(mesgt)\\n\"\r\n\"    -- create and return message source\\n\"\r\n\"    local co = coroutine.create(function() send_message(mesgt) end)\\n\"\r\n\"    return function()\\n\"\r\n\"        local ret, a, b = coroutine.resume(co)\\n\"\r\n\"        if ret then return a, b\\n\"\r\n\"        else return nil, a end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"---------------------------------------------------------------------------\\n\"\r\n\"-- High level SMTP API\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"_M.send = socket.protect(function(mailt)\\n\"\r\n\"    local s = _M.open(mailt.server, mailt.port, mailt.create)\\n\"\r\n\"    local ext = s:greet(mailt.domain)\\n\"\r\n\"    s:auth(mailt.user, mailt.password, ext)\\n\"\r\n\"    s:send(mailt)\\n\"\r\n\"    s:quit()\\n\"\r\n\"    return s:close()\\n\"\r\n\"end)\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.tp */\r\nstatic const char *lua_m_socket_tp = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Unified SMTP/FTP subsystem\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local base = _G\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"local ltn12 = require(\\\"socket.ltn12\\\")\\n\"\r\n\"\\n\"\r\n\"socket.tp = {}\\n\"\r\n\"local _M = socket.tp\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Program constants\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"_M.TIMEOUT = 60\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Implementation\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- gets server reply (works for SMTP and FTP)\\n\"\r\n\"local function get_reply(c)\\n\"\r\n\"    local code, current, sep\\n\"\r\n\"    local line, err = c:receive()\\n\"\r\n\"    local reply = line\\n\"\r\n\"    if err then return nil, err end\\n\"\r\n\"    code, sep = socket.skip(2, string.find(line, \\\"^(%d%d%d)(.?)\\\"))\\n\"\r\n\"    if not code then return nil, \\\"invalid server reply\\\" end\\n\"\r\n\"    if sep == \\\"-\\\" then -- reply is multiline\\n\"\r\n\"        repeat\\n\"\r\n\"            line, err = c:receive()\\n\"\r\n\"            if err then return nil, err end\\n\"\r\n\"            current, sep = socket.skip(2, string.find(line, \\\"^(%d%d%d)(.?)\\\"))\\n\"\r\n\"            reply = reply .. \\\"\\\\n\\\" .. line\\n\"\r\n\"        -- reply ends with same code\\n\"\r\n\"        until code == current and sep == \\\" \\\"\\n\"\r\n\"    end\\n\"\r\n\"    return code, reply\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- metatable for sock object\\n\"\r\n\"local metat = { __index = {} }\\n\"\r\n\"\\n\"\r\n\"function metat.__index:check(ok)\\n\"\r\n\"    local code, reply = get_reply(self.c)\\n\"\r\n\"    if not code then return nil, reply end\\n\"\r\n\"    if base.type(ok) ~= \\\"function\\\" then\\n\"\r\n\"        if base.type(ok) == \\\"table\\\" then\\n\"\r\n\"            for i, v in base.ipairs(ok) do\\n\"\r\n\"                if string.find(code, v) then\\n\"\r\n\"                    return base.tonumber(code), reply\\n\"\r\n\"                end\\n\"\r\n\"            end\\n\"\r\n\"            return nil, reply\\n\"\r\n\"        else\\n\"\r\n\"            if string.find(code, ok) then return base.tonumber(code), reply\\n\"\r\n\"            else return nil, reply end\\n\"\r\n\"        end\\n\"\r\n\"    else return ok(base.tonumber(code), reply) end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:command(cmd, arg)\\n\"\r\n\"    cmd = string.upper(cmd)\\n\"\r\n\"    if arg then\\n\"\r\n\"        return self.c:send(cmd .. \\\" \\\" .. arg.. \\\"\\\\r\\\\n\\\")\\n\"\r\n\"    else\\n\"\r\n\"        return self.c:send(cmd .. \\\"\\\\r\\\\n\\\")\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:sink(snk, pat)\\n\"\r\n\"    local chunk, err = c:receive(pat)\\n\"\r\n\"    return snk(chunk, err)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:send(data)\\n\"\r\n\"    return self.c:send(data)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:receive(pat)\\n\"\r\n\"    return self.c:receive(pat)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:getfd()\\n\"\r\n\"    return self.c:getfd()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:dirty()\\n\"\r\n\"    return self.c:dirty()\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:getcontrol()\\n\"\r\n\"    return self.c\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function metat.__index:source(source, step)\\n\"\r\n\"    local sink = socket.sink(\\\"keep-open\\\", self.c)\\n\"\r\n\"    local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step)\\n\"\r\n\"    return ret, err\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- closes the underlying c\\n\"\r\n\"function metat.__index:close()\\n\"\r\n\"    self.c:close()\\n\"\r\n\"    return 1\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- connect with server and return c object\\n\"\r\n\"function _M.connect(host, port, timeout, create)\\n\"\r\n\"    local c, e = (create or socket.tcp)()\\n\"\r\n\"    if not c then return nil, e end\\n\"\r\n\"    c:settimeout(timeout or _M.TIMEOUT)\\n\"\r\n\"    local r, e = c:connect(host, port)\\n\"\r\n\"    if not r then\\n\"\r\n\"        c:close()\\n\"\r\n\"        return nil, e\\n\"\r\n\"    end\\n\"\r\n\"    return base.setmetatable({c = c}, metat)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket.url */\r\nstatic const char *lua_m_socket_url = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- URI parsing, composition and relative URL resolution\\n\"\r\n\"-- LuaSocket toolkit.\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local base = _G\\n\"\r\n\"local table = require(\\\"table\\\")\\n\"\r\n\"local socket = require(\\\"socket.socket\\\")\\n\"\r\n\"\\n\"\r\n\"socket.url = {}\\n\"\r\n\"local _M = socket.url\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Module version\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"_M._VERSION = \\\"URL 1.0.3\\\"\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Encodes a string into its escaped hexadecimal representation\\n\"\r\n\"-- Input\\n\"\r\n\"--   s: binary string to be encoded\\n\"\r\n\"-- Returns\\n\"\r\n\"--   escaped representation of string binary\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.escape(s)\\n\"\r\n\"    return (string.gsub(s, \\\"([^A-Za-z0-9_])\\\", function(c)\\n\"\r\n\"        return string.format(\\\"%%%02x\\\", string.byte(c))\\n\"\r\n\"    end))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Protects a path segment, to prevent it from interfering with the\\n\"\r\n\"-- url parsing.\\n\"\r\n\"-- Input\\n\"\r\n\"--   s: binary string to be encoded\\n\"\r\n\"-- Returns\\n\"\r\n\"--   escaped representation of string binary\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local function make_set(t)\\n\"\r\n\"    local s = {}\\n\"\r\n\"    for i,v in base.ipairs(t) do\\n\"\r\n\"        s[t[i]] = 1\\n\"\r\n\"    end\\n\"\r\n\"    return s\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-- these are allowed withing a path segment, along with alphanum\\n\"\r\n\"-- other characters must be escaped\\n\"\r\n\"local segment_set = make_set {\\n\"\r\n\"    \\\"-\\\", \\\"_\\\", \\\".\\\", \\\"!\\\", \\\"~\\\", \\\"*\\\", \\\"'\\\", \\\"(\\\",\\n\"\r\n\"    \\\")\\\", \\\":\\\", \\\"@\\\", \\\"&\\\", \\\"=\\\", \\\"+\\\", \\\"$\\\", \\\",\\\",\\n\"\r\n\"}\\n\"\r\n\"\\n\"\r\n\"local function protect_segment(s)\\n\"\r\n\"    return string.gsub(s, \\\"([^A-Za-z0-9_])\\\", function (c)\\n\"\r\n\"        if segment_set[c] then return c\\n\"\r\n\"        else return string.format(\\\"%%%02x\\\", string.byte(c)) end\\n\"\r\n\"    end)\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Encodes a string into its escaped hexadecimal representation\\n\"\r\n\"-- Input\\n\"\r\n\"--   s: binary string to be encoded\\n\"\r\n\"-- Returns\\n\"\r\n\"--   escaped representation of string binary\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.unescape(s)\\n\"\r\n\"    return (string.gsub(s, \\\"%%(%x%x)\\\", function(hex)\\n\"\r\n\"        return string.char(base.tonumber(hex, 16))\\n\"\r\n\"    end))\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Builds a path from a base path and a relative path\\n\"\r\n\"-- Input\\n\"\r\n\"--   base_path\\n\"\r\n\"--   relative_path\\n\"\r\n\"-- Returns\\n\"\r\n\"--   corresponding absolute path\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local function absolute_path(base_path, relative_path)\\n\"\r\n\"    if string.sub(relative_path, 1, 1) == \\\"/\\\" then return relative_path end\\n\"\r\n\"    local path = string.gsub(base_path, \\\"[^/]*$\\\", \\\"\\\")\\n\"\r\n\"    path = path .. relative_path\\n\"\r\n\"    path = string.gsub(path, \\\"([^/]*%./)\\\", function (s)\\n\"\r\n\"        if s ~= \\\"./\\\" then return s else return \\\"\\\" end\\n\"\r\n\"    end)\\n\"\r\n\"    path = string.gsub(path, \\\"/%.$\\\", \\\"/\\\")\\n\"\r\n\"    local reduced\\n\"\r\n\"    while reduced ~= path do\\n\"\r\n\"        reduced = path\\n\"\r\n\"        path = string.gsub(reduced, \\\"([^/]*/%.%./)\\\", function (s)\\n\"\r\n\"            if s ~= \\\"../../\\\" then return \\\"\\\" else return s end\\n\"\r\n\"        end)\\n\"\r\n\"    end\\n\"\r\n\"    path = string.gsub(reduced, \\\"([^/]*/%.%.)$\\\", function (s)\\n\"\r\n\"        if s ~= \\\"../..\\\" then return \\\"\\\" else return s end\\n\"\r\n\"    end)\\n\"\r\n\"    return path\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Parses a url and returns a table with all its parts according to RFC 2396\\n\"\r\n\"-- The following grammar describes the names given to the URL parts\\n\"\r\n\"-- <url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment>\\n\"\r\n\"-- <authority> ::= <userinfo>@<host>:<port>\\n\"\r\n\"-- <userinfo> ::= <user>[:<password>]\\n\"\r\n\"-- <path> :: = {<segment>/}<segment>\\n\"\r\n\"-- Input\\n\"\r\n\"--   url: uniform resource locator of request\\n\"\r\n\"--   default: table with default values for each field\\n\"\r\n\"-- Returns\\n\"\r\n\"--   table with the following fields, where RFC naming conventions have\\n\"\r\n\"--   been preserved:\\n\"\r\n\"--     scheme, authority, userinfo, user, password, host, port,\\n\"\r\n\"--     path, params, query, fragment\\n\"\r\n\"-- Obs:\\n\"\r\n\"--   the leading '/' in {/<path>} is considered part of <path>\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.parse(url, default)\\n\"\r\n\"    -- initialize default parameters\\n\"\r\n\"    local parsed = {}\\n\"\r\n\"    for i,v in base.pairs(default or parsed) do parsed[i] = v end\\n\"\r\n\"    -- empty url is parsed to nil\\n\"\r\n\"    if not url or url == \\\"\\\" then return nil, \\\"invalid url\\\" end\\n\"\r\n\"    -- remove whitespace\\n\"\r\n\"    -- url = string.gsub(url, \\\"%s\\\", \\\"\\\")\\n\"\r\n\"    -- get fragment\\n\"\r\n\"    url = string.gsub(url, \\\"#(.*)$\\\", function(f)\\n\"\r\n\"        parsed.fragment = f\\n\"\r\n\"        return \\\"\\\"\\n\"\r\n\"    end)\\n\"\r\n\"    -- get scheme\\n\"\r\n\"    url = string.gsub(url, \\\"^([%w][%w%+%-%.]*)%:\\\",\\n\"\r\n\"        function(s) parsed.scheme = s; return \\\"\\\" end)\\n\"\r\n\"    -- get authority\\n\"\r\n\"    url = string.gsub(url, \\\"^//([^/]*)\\\", function(n)\\n\"\r\n\"        parsed.authority = n\\n\"\r\n\"        return \\\"\\\"\\n\"\r\n\"    end)\\n\"\r\n\"    -- get query string\\n\"\r\n\"    url = string.gsub(url, \\\"%?(.*)\\\", function(q)\\n\"\r\n\"        parsed.query = q\\n\"\r\n\"        return \\\"\\\"\\n\"\r\n\"    end)\\n\"\r\n\"    -- get params\\n\"\r\n\"    url = string.gsub(url, \\\"%;(.*)\\\", function(p)\\n\"\r\n\"        parsed.params = p\\n\"\r\n\"        return \\\"\\\"\\n\"\r\n\"    end)\\n\"\r\n\"    -- path is whatever was left\\n\"\r\n\"    if url ~= \\\"\\\" then parsed.path = url end\\n\"\r\n\"    local authority = parsed.authority\\n\"\r\n\"    if not authority then return parsed end\\n\"\r\n\"    authority = string.gsub(authority,\\\"^([^@]*)@\\\",\\n\"\r\n\"        function(u) parsed.userinfo = u; return \\\"\\\" end)\\n\"\r\n\"    authority = string.gsub(authority, \\\":([^:%]]*)$\\\",\\n\"\r\n\"        function(p) parsed.port = p; return \\\"\\\" end)\\n\"\r\n\"    if authority ~= \\\"\\\" then\\n\"\r\n\"        -- IPv6?\\n\"\r\n\"        parsed.host = string.match(authority, \\\"^%[(.+)%]$\\\") or authority\\n\"\r\n\"    end\\n\"\r\n\"    local userinfo = parsed.userinfo\\n\"\r\n\"    if not userinfo then return parsed end\\n\"\r\n\"    userinfo = string.gsub(userinfo, \\\":([^:]*)$\\\",\\n\"\r\n\"        function(p) parsed.password = p; return \\\"\\\" end)\\n\"\r\n\"    parsed.user = userinfo\\n\"\r\n\"    return parsed\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Rebuilds a parsed URL from its components.\\n\"\r\n\"-- Components are protected if any reserved or unallowed characters are found\\n\"\r\n\"-- Input\\n\"\r\n\"--   parsed: parsed URL, as returned by parse\\n\"\r\n\"-- Returns\\n\"\r\n\"--   a stringing with the corresponding URL\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.build(parsed)\\n\"\r\n\"    local ppath = _M.parse_path(parsed.path or \\\"\\\")\\n\"\r\n\"    local url = _M.build_path(ppath)\\n\"\r\n\"    if parsed.params then url = url .. \\\";\\\" .. parsed.params end\\n\"\r\n\"    if parsed.query then url = url .. \\\"?\\\" .. parsed.query end\\n\"\r\n\"    local authority = parsed.authority\\n\"\r\n\"    if parsed.host then\\n\"\r\n\"        authority = parsed.host\\n\"\r\n\"        if string.find(authority, \\\":\\\") then -- IPv6?\\n\"\r\n\"            authority = \\\"[\\\" .. authority .. \\\"]\\\"\\n\"\r\n\"        end\\n\"\r\n\"        if parsed.port then authority = authority .. \\\":\\\" .. parsed.port end\\n\"\r\n\"        local userinfo = parsed.userinfo\\n\"\r\n\"        if parsed.user then\\n\"\r\n\"            userinfo = parsed.user\\n\"\r\n\"            if parsed.password then\\n\"\r\n\"                userinfo = userinfo .. \\\":\\\" .. parsed.password\\n\"\r\n\"            end\\n\"\r\n\"        end\\n\"\r\n\"        if userinfo then authority = userinfo .. \\\"@\\\" .. authority end\\n\"\r\n\"    end\\n\"\r\n\"    if authority then url = \\\"//\\\" .. authority .. url end\\n\"\r\n\"    if parsed.scheme then url = parsed.scheme .. \\\":\\\" .. url end\\n\"\r\n\"    if parsed.fragment then url = url .. \\\"#\\\" .. parsed.fragment end\\n\"\r\n\"    -- url = string.gsub(url, \\\"%s\\\", \\\"\\\")\\n\"\r\n\"    return url\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Builds a absolute URL from a base and a relative URL according to RFC 2396\\n\"\r\n\"-- Input\\n\"\r\n\"--   base_url\\n\"\r\n\"--   relative_url\\n\"\r\n\"-- Returns\\n\"\r\n\"--   corresponding absolute url\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.absolute(base_url, relative_url)\\n\"\r\n\"    if base.type(base_url) == \\\"table\\\" then\\n\"\r\n\"        base_parsed = base_url\\n\"\r\n\"        base_url = _M.build(base_parsed)\\n\"\r\n\"    else\\n\"\r\n\"        base_parsed = _M.parse(base_url)\\n\"\r\n\"    end\\n\"\r\n\"    local relative_parsed = _M.parse(relative_url)\\n\"\r\n\"    if not base_parsed then return relative_url\\n\"\r\n\"    elseif not relative_parsed then return base_url\\n\"\r\n\"    elseif relative_parsed.scheme then return relative_url\\n\"\r\n\"    else\\n\"\r\n\"        relative_parsed.scheme = base_parsed.scheme\\n\"\r\n\"        if not relative_parsed.authority then\\n\"\r\n\"            relative_parsed.authority = base_parsed.authority\\n\"\r\n\"            if not relative_parsed.path then\\n\"\r\n\"                relative_parsed.path = base_parsed.path\\n\"\r\n\"                if not relative_parsed.params then\\n\"\r\n\"                    relative_parsed.params = base_parsed.params\\n\"\r\n\"                    if not relative_parsed.query then\\n\"\r\n\"                        relative_parsed.query = base_parsed.query\\n\"\r\n\"                    end\\n\"\r\n\"                end\\n\"\r\n\"            else\\n\"\r\n\"                relative_parsed.path = absolute_path(base_parsed.path or \\\"\\\",\\n\"\r\n\"                    relative_parsed.path)\\n\"\r\n\"            end\\n\"\r\n\"        end\\n\"\r\n\"        return _M.build(relative_parsed)\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Breaks a path into its segments, unescaping the segments\\n\"\r\n\"-- Input\\n\"\r\n\"--   path\\n\"\r\n\"-- Returns\\n\"\r\n\"--   segment: a table with one entry per segment\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.parse_path(path)\\n\"\r\n\"    local parsed = {}\\n\"\r\n\"    path = path or \\\"\\\"\\n\"\r\n\"    --path = string.gsub(path, \\\"%s\\\", \\\"\\\")\\n\"\r\n\"    string.gsub(path, \\\"([^/]+)\\\", function (s) table.insert(parsed, s) end)\\n\"\r\n\"    for i = 1, #parsed do\\n\"\r\n\"        parsed[i] = _M.unescape(parsed[i])\\n\"\r\n\"    end\\n\"\r\n\"    if string.sub(path, 1, 1) == \\\"/\\\" then parsed.is_absolute = 1 end\\n\"\r\n\"    if string.sub(path, -1, -1) == \\\"/\\\" then parsed.is_directory = 1 end\\n\"\r\n\"    return parsed\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Builds a path component from its segments, escaping protected characters.\\n\"\r\n\"-- Input\\n\"\r\n\"--   parsed: path segments\\n\"\r\n\"--   unsafe: if true, segments are not protected before path is built\\n\"\r\n\"-- Returns\\n\"\r\n\"--   path: corresponding path stringing\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.build_path(parsed, unsafe)\\n\"\r\n\"    local path = \\\"\\\"\\n\"\r\n\"    local n = #parsed\\n\"\r\n\"    if unsafe then\\n\"\r\n\"        for i = 1, n-1 do\\n\"\r\n\"            path = path .. parsed[i]\\n\"\r\n\"            path = path .. \\\"/\\\"\\n\"\r\n\"        end\\n\"\r\n\"        if n > 0 then\\n\"\r\n\"            path = path .. parsed[n]\\n\"\r\n\"            if parsed.is_directory then path = path .. \\\"/\\\" end\\n\"\r\n\"        end\\n\"\r\n\"    else\\n\"\r\n\"        for i = 1, n-1 do\\n\"\r\n\"            path = path .. protect_segment(parsed[i])\\n\"\r\n\"            path = path .. \\\"/\\\"\\n\"\r\n\"        end\\n\"\r\n\"        if n > 0 then\\n\"\r\n\"            path = path .. protect_segment(parsed[n])\\n\"\r\n\"            if parsed.is_directory then path = path .. \\\"/\\\" end\\n\"\r\n\"        end\\n\"\r\n\"    end\\n\"\r\n\"    if parsed.is_absolute then path = \\\"/\\\" .. path end\\n\"\r\n\"    return path\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n/* socket */\r\nstatic const char *lua_m_socket = \r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- LuaSocket helper module\\n\"\r\n\"-- Author: Diego Nehab\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Declare module and import dependencies\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"local base = _G\\n\"\r\n\"local string = require(\\\"string\\\")\\n\"\r\n\"local math = require(\\\"math\\\")\\n\"\r\n\"local socket = require(\\\"socket.core\\\")\\n\"\r\n\"\\n\"\r\n\"local _M = socket\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Exported auxiliar functions\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"function _M.connect4(address, port, laddress, lport)\\n\"\r\n\"    return socket.connect(address, port, laddress, lport, \\\"inet\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.connect6(address, port, laddress, lport)\\n\"\r\n\"    return socket.connect(address, port, laddress, lport, \\\"inet6\\\")\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"function _M.bind(host, port, backlog)\\n\"\r\n\"    if host == \\\"*\\\" then host = \\\"0.0.0.0\\\" end\\n\"\r\n\"    local addrinfo, err = socket.dns.getaddrinfo(host);\\n\"\r\n\"    if not addrinfo then return nil, err end\\n\"\r\n\"    local sock, res\\n\"\r\n\"    err = \\\"no info on address\\\"\\n\"\r\n\"    for i, alt in base.ipairs(addrinfo) do\\n\"\r\n\"        if alt.family == \\\"inet\\\" then\\n\"\r\n\"            sock, err = socket.tcp()\\n\"\r\n\"        else\\n\"\r\n\"            sock, err = socket.tcp6()\\n\"\r\n\"        end\\n\"\r\n\"        if not sock then return nil, err end\\n\"\r\n\"        sock:setoption(\\\"reuseaddr\\\", true)\\n\"\r\n\"        res, err = sock:bind(alt.addr, port)\\n\"\r\n\"        if not res then \\n\"\r\n\"            sock:close()\\n\"\r\n\"        else \\n\"\r\n\"            res, err = sock:listen(backlog)\\n\"\r\n\"            if not res then \\n\"\r\n\"                sock:close()\\n\"\r\n\"            else\\n\"\r\n\"                return sock\\n\"\r\n\"            end\\n\"\r\n\"        end \\n\"\r\n\"    end\\n\"\r\n\"    return nil, err\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"_M.try = _M.newtry()\\n\"\r\n\"\\n\"\r\n\"function _M.choose(table)\\n\"\r\n\"    return function(name, opt1, opt2)\\n\"\r\n\"        if base.type(name) ~= \\\"string\\\" then\\n\"\r\n\"            name, opt1, opt2 = \\\"default\\\", name, opt1\\n\"\r\n\"        end\\n\"\r\n\"        local f = table[name or \\\"nil\\\"]\\n\"\r\n\"        if not f then base.error(\\\"unknown key (\\\".. base.tostring(name) ..\\\")\\\", 3)\\n\"\r\n\"        else return f(opt1, opt2) end\\n\"\r\n\"    end\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- Socket sources and sinks, conforming to LTN12\\n\"\r\n\"-----------------------------------------------------------------------------\\n\"\r\n\"-- create namespaces inside LuaSocket namespace\\n\"\r\n\"local sourcet, sinkt = {}, {}\\n\"\r\n\"_M.sourcet = sourcet\\n\"\r\n\"_M.sinkt = sinkt\\n\"\r\n\"\\n\"\r\n\"_M.BLOCKSIZE = 2048\\n\"\r\n\"\\n\"\r\n\"sinkt[\\\"close-when-done\\\"] = function(sock)\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function(self, chunk, err)\\n\"\r\n\"            if not chunk then\\n\"\r\n\"                sock:close()\\n\"\r\n\"                return 1\\n\"\r\n\"            else return sock:send(chunk) end\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"sinkt[\\\"keep-open\\\"] = function(sock)\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function(self, chunk, err)\\n\"\r\n\"            if chunk then return sock:send(chunk)\\n\"\r\n\"            else return 1 end\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"sinkt[\\\"default\\\"] = sinkt[\\\"keep-open\\\"]\\n\"\r\n\"\\n\"\r\n\"_M.sink = _M.choose(sinkt)\\n\"\r\n\"\\n\"\r\n\"sourcet[\\\"by-length\\\"] = function(sock, length)\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function()\\n\"\r\n\"            if length <= 0 then return nil end\\n\"\r\n\"            local size = math.min(socket.BLOCKSIZE, length)\\n\"\r\n\"            local chunk, err = sock:receive(size)\\n\"\r\n\"            if err then return nil, err end\\n\"\r\n\"            length = length - string.len(chunk)\\n\"\r\n\"            return chunk\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"sourcet[\\\"until-closed\\\"] = function(sock)\\n\"\r\n\"    local done\\n\"\r\n\"    return base.setmetatable({\\n\"\r\n\"        getfd = function() return sock:getfd() end,\\n\"\r\n\"        dirty = function() return sock:dirty() end\\n\"\r\n\"    }, {\\n\"\r\n\"        __call = function()\\n\"\r\n\"            if done then return nil end\\n\"\r\n\"            local chunk, err, partial = sock:receive(socket.BLOCKSIZE)\\n\"\r\n\"            if not err then return chunk\\n\"\r\n\"            elseif err == \\\"closed\\\" then\\n\"\r\n\"                sock:close()\\n\"\r\n\"                done = 1\\n\"\r\n\"                return partial\\n\"\r\n\"            else return nil, err end\\n\"\r\n\"        end\\n\"\r\n\"    })\\n\"\r\n\"end\\n\"\r\n\"\\n\"\r\n\"\\n\"\r\n\"sourcet[\\\"default\\\"] = sourcet[\\\"until-closed\\\"]\\n\"\r\n\"\\n\"\r\n\"_M.source = _M.choose(sourcet)\\n\"\r\n\"\\n\"\r\n\"return _M\\n\"\r\n\"\\n\";\r\n\r\n\r\n\r\nint luaopen_lua_m_ltn12(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_ltn12);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_mime(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_mime);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_ftp(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_ftp);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_headers(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_headers);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_http(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_http);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_mbox(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_mbox);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_smtp(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_smtp);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_tp(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_tp);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket_url(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket_url);\r\n    return 1;\r\n}\r\n\r\n\r\nint luaopen_lua_m_socket(lua_State *L) {\r\n    luaL_loadstring(L, lua_m_socket);\r\n    return 1;\r\n}\r\n\r\n\r\nstatic luaL_Reg luasocket_scripts_modules[] = {\r\n    {\"ltn12\", luaopen_lua_m_ltn12},\r\n    {\"mime\", luaopen_lua_m_mime},\r\n    {\"socket.ftp\", luaopen_lua_m_socket_ftp},\r\n    {\"socket.headers\", luaopen_lua_m_socket_headers},\r\n    {\"socket.http\", luaopen_lua_m_socket_http},\r\n    {\"socket.mbox\", luaopen_lua_m_socket_mbox},\r\n    {\"socket.smtp\", luaopen_lua_m_socket_smtp},\r\n    {\"socket.tp\", luaopen_lua_m_socket_tp},\r\n    {\"socket.url\", luaopen_lua_m_socket_url},\r\n    {\"socket\", luaopen_lua_m_socket},\r\n    {NULL, NULL}\r\n};\r\n\r\nvoid luaopen_luasocket_scripts(lua_State* L)\r\n{\r\n    luaL_Reg* lib = luasocket_scripts_modules;\r\n    lua_getglobal(L, \"package\");\r\n    lua_getfield(L, -1, \"preload\");\r\n    for (; lib->func; lib++)\r\n    {\r\n        lib->func(L);\r\n        lua_setfield(L, -2, lib->name);\r\n    }\r\n    lua_pop(L, 2);\r\n}\r\n"
  },
  {
    "path": "build/luasocket/luasocket_scripts.h",
    "content": "\r\n/* luasocket_scripts.h.h */\r\n\r\n#ifndef __LUA_MODULES_606BA1C00D116CA81B695C141D124DB7_H_\r\n#define __LUA_MODULES_606BA1C00D116CA81B695C141D124DB7_H_\r\n\r\n#if __cplusplus\r\nextern \"C\" {\r\n#endif\r\n\r\n#include \"lua.h\"\r\n\r\nvoid luaopen_luasocket_scripts(lua_State* L);\r\n\r\n/*\r\nint luaopen_lua_m_ltn12(lua_State* L);\r\nint luaopen_lua_m_mime(lua_State* L);\r\nint luaopen_lua_m_socket_ftp(lua_State* L);\r\nint luaopen_lua_m_socket_headers(lua_State* L);\r\nint luaopen_lua_m_socket_http(lua_State* L);\r\nint luaopen_lua_m_socket_mbox(lua_State* L);\r\nint luaopen_lua_m_socket_smtp(lua_State* L);\r\nint luaopen_lua_m_socket_tp(lua_State* L);\r\nint luaopen_lua_m_socket_url(lua_State* L);\r\nint luaopen_lua_m_socket(lua_State* L);\r\n*/\r\n\r\n#if __cplusplus\r\n}\r\n#endif\r\n\r\n#endif /* __LUA_MODULES_606BA1C00D116CA81B695C141D124DB7_H_ */\r\n"
  },
  {
    "path": "build/luasocket/mime.c",
    "content": "/*=========================================================================*\\\r\n* MIME support functions\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)\r\n#include \"compat-5.1.h\"\r\n#endif\r\n\r\n#include \"mime.h\"\r\n\r\n/*=========================================================================*\\\r\n* Don't want to trust escape character constants\r\n\\*=========================================================================*/\r\ntypedef unsigned char UC;\r\nstatic const char CRLF[] = \"\\r\\n\";\r\nstatic const char EQCRLF[] = \"=\\r\\n\";\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes.\r\n\\*=========================================================================*/\r\nstatic int mime_global_wrp(lua_State *L);\r\nstatic int mime_global_b64(lua_State *L);\r\nstatic int mime_global_unb64(lua_State *L);\r\nstatic int mime_global_qp(lua_State *L);\r\nstatic int mime_global_unqp(lua_State *L);\r\nstatic int mime_global_qpwrp(lua_State *L);\r\nstatic int mime_global_eol(lua_State *L);\r\nstatic int mime_global_dot(lua_State *L);\r\n\r\nstatic size_t dot(int c, size_t state, luaL_Buffer *buffer);\r\nstatic void b64setup(UC *base);\r\nstatic size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer);\r\nstatic size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer);\r\nstatic size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer);\r\n\r\nstatic void qpsetup(UC *class, UC *unbase);\r\nstatic void qpquote(UC c, luaL_Buffer *buffer);\r\nstatic size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer);\r\nstatic size_t qpencode(UC c, UC *input, size_t size, \r\n        const char *marker, luaL_Buffer *buffer);\r\nstatic size_t qppad(UC *input, size_t size, luaL_Buffer *buffer);\r\n\r\n/* code support functions */\r\nstatic luaL_Reg func[] = {\r\n    { \"dot\", mime_global_dot },\r\n    { \"b64\", mime_global_b64 },\r\n    { \"eol\", mime_global_eol },\r\n    { \"qp\", mime_global_qp },\r\n    { \"qpwrp\", mime_global_qpwrp },\r\n    { \"unb64\", mime_global_unb64 },\r\n    { \"unqp\", mime_global_unqp },\r\n    { \"wrp\", mime_global_wrp },\r\n    { NULL, NULL }\r\n};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Quoted-printable globals\r\n\\*-------------------------------------------------------------------------*/\r\nstatic UC qpclass[256];\r\nstatic UC qpbase[] = \"0123456789ABCDEF\";\r\nstatic UC qpunbase[256];\r\nenum {QP_PLAIN, QP_QUOTED, QP_CR, QP_IF_LAST};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Base64 globals\r\n\\*-------------------------------------------------------------------------*/\r\nstatic const UC b64base[] =\r\n        \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\r\nstatic UC b64unbase[256];\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nMIME_API int luaopen_mime_core(lua_State *L)\r\n{\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    lua_newtable(L);\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, \"mime\", func, 0);\r\n#endif\r\n    /* make version string available to scripts */\r\n    lua_pushstring(L, \"_VERSION\");\r\n    lua_pushstring(L, MIME_VERSION);\r\n    lua_rawset(L, -3);\r\n    /* initialize lookup tables */\r\n    qpsetup(qpclass, qpunbase);\r\n    b64setup(b64unbase);\r\n    return 1;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Global Lua functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementaly breaks a string into lines. The string can have CRLF breaks.\r\n* A, n = wrp(l, B, length)\r\n* A is a copy of B, broken into lines of at most 'length' bytes. \r\n* 'l' is how many bytes are left for the first line of B. \r\n* 'n' is the number of bytes left in the last line of A. \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_wrp(lua_State *L)\r\n{\r\n    size_t size = 0;\r\n    int left = (int) luaL_checknumber(L, 1);\r\n    const UC *input = (UC *) luaL_optlstring(L, 2, NULL, &size);\r\n    const UC *last = input + size;\r\n    int length = (int) luaL_optnumber(L, 3, 76);\r\n    luaL_Buffer buffer;\r\n    /* end of input black-hole */\r\n    if (!input) {\r\n        /* if last line has not been terminated, add a line break */\r\n        if (left < length) lua_pushstring(L, CRLF);\r\n        /* otherwise, we are done */\r\n        else lua_pushnil(L);\r\n        lua_pushnumber(L, length);\r\n        return 2;\r\n    } \r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last) {\r\n        switch (*input) {\r\n            case '\\r':\r\n                break;\r\n            case '\\n':\r\n                luaL_addstring(&buffer, CRLF);\r\n                left = length;\r\n                break;\r\n            default:\r\n                if (left <= 0) {\r\n                    left = length;\r\n                    luaL_addstring(&buffer, CRLF);\r\n                }\r\n                luaL_addchar(&buffer, *input);\r\n                left--;\r\n                break;\r\n        }\r\n        input++;\r\n    }\r\n    luaL_pushresult(&buffer);\r\n    lua_pushnumber(L, left);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Fill base64 decode map. \r\n\\*-------------------------------------------------------------------------*/\r\nstatic void b64setup(UC *unbase) \r\n{\r\n    int i;\r\n    for (i = 0; i <= 255; i++) unbase[i] = (UC) 255;\r\n    for (i = 0; i < 64; i++) unbase[b64base[i]] = (UC) i;\r\n    unbase['='] = 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Acumulates bytes in input buffer until 3 bytes are available. \r\n* Translate the 3 bytes into Base64 form and append to buffer.\r\n* Returns new number of bytes in buffer.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t b64encode(UC c, UC *input, size_t size, \r\n        luaL_Buffer *buffer)\r\n{\r\n    input[size++] = c;\r\n    if (size == 3) {\r\n        UC code[4];\r\n        unsigned long value = 0;\r\n        value += input[0]; value <<= 8;\r\n        value += input[1]; value <<= 8;\r\n        value += input[2]; \r\n        code[3] = b64base[value & 0x3f]; value >>= 6;\r\n        code[2] = b64base[value & 0x3f]; value >>= 6;\r\n        code[1] = b64base[value & 0x3f]; value >>= 6;\r\n        code[0] = b64base[value];\r\n        luaL_addlstring(buffer, (char *) code, 4);\r\n        size = 0;\r\n    }\r\n    return size;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Encodes the Base64 last 1 or 2 bytes and adds padding '=' \r\n* Result, if any, is appended to buffer.\r\n* Returns 0.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t b64pad(const UC *input, size_t size, \r\n        luaL_Buffer *buffer)\r\n{\r\n    unsigned long value = 0;\r\n    UC code[4] = {'=', '=', '=', '='};\r\n    switch (size) {\r\n        case 1:\r\n            value = input[0] << 4;\r\n            code[1] = b64base[value & 0x3f]; value >>= 6;\r\n            code[0] = b64base[value];\r\n            luaL_addlstring(buffer, (char *) code, 4);\r\n            break;\r\n        case 2:\r\n            value = input[0]; value <<= 8; \r\n            value |= input[1]; value <<= 2;\r\n            code[2] = b64base[value & 0x3f]; value >>= 6;\r\n            code[1] = b64base[value & 0x3f]; value >>= 6;\r\n            code[0] = b64base[value];\r\n            luaL_addlstring(buffer, (char *) code, 4);\r\n            break;\r\n        default:\r\n            break;\r\n    }\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Acumulates bytes in input buffer until 4 bytes are available. \r\n* Translate the 4 bytes from Base64 form and append to buffer.\r\n* Returns new number of bytes in buffer.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t b64decode(UC c, UC *input, size_t size, \r\n        luaL_Buffer *buffer)\r\n{\r\n    /* ignore invalid characters */\r\n    if (b64unbase[c] > 64) return size;\r\n    input[size++] = c;\r\n    /* decode atom */\r\n    if (size == 4) {\r\n        UC decoded[3];\r\n        int valid, value = 0;\r\n        value =  b64unbase[input[0]]; value <<= 6;\r\n        value |= b64unbase[input[1]]; value <<= 6;\r\n        value |= b64unbase[input[2]]; value <<= 6;\r\n        value |= b64unbase[input[3]];\r\n        decoded[2] = (UC) (value & 0xff); value >>= 8;\r\n        decoded[1] = (UC) (value & 0xff); value >>= 8;\r\n        decoded[0] = (UC) value;\r\n        /* take care of paddding */\r\n        valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; \r\n        luaL_addlstring(buffer, (char *) decoded, valid);\r\n        return 0;\r\n    /* need more data */\r\n    } else return size;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally applies the Base64 transfer content encoding to a string\r\n* A, B = b64(C, D)\r\n* A is the encoded version of the largest prefix of C .. D that is\r\n* divisible by 3. B has the remaining bytes of C .. D, *without* encoding.\r\n* The easiest thing would be to concatenate the two strings and \r\n* encode the result, but we can't afford that or Lua would dupplicate\r\n* every chunk we received.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_b64(lua_State *L)\r\n{\r\n    UC atom[3];\r\n    size_t isize = 0, asize = 0;\r\n    const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);\r\n    const UC *last = input + isize;\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* make sure we don't confuse buffer stuff with arguments */\r\n    lua_settop(L, 2);\r\n    /* process first part of the input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last) \r\n        asize = b64encode(*input++, atom, asize, &buffer);\r\n    input = (UC *) luaL_optlstring(L, 2, NULL, &isize);\r\n    /* if second part is nil, we are done */\r\n    if (!input) {\r\n        size_t osize = 0;\r\n        asize = b64pad(atom, asize, &buffer);\r\n        luaL_pushresult(&buffer);\r\n        /* if the output is empty  and the input is nil, return nil */\r\n        lua_tolstring(L, -1, &osize);\r\n        if (osize == 0) lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* otherwise process the second part */\r\n    last = input + isize;\r\n    while (input < last) \r\n        asize = b64encode(*input++, atom, asize, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushlstring(L, (char *) atom, asize);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally removes the Base64 transfer content encoding from a string\r\n* A, B = b64(C, D)\r\n* A is the encoded version of the largest prefix of C .. D that is\r\n* divisible by 4. B has the remaining bytes of C .. D, *without* encoding.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_unb64(lua_State *L)\r\n{\r\n    UC atom[4];\r\n    size_t isize = 0, asize = 0;\r\n    const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);\r\n    const UC *last = input + isize;\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* make sure we don't confuse buffer stuff with arguments */\r\n    lua_settop(L, 2);\r\n    /* process first part of the input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last) \r\n        asize = b64decode(*input++, atom, asize, &buffer);\r\n    input = (UC *) luaL_optlstring(L, 2, NULL, &isize);\r\n    /* if second is nil, we are done */\r\n    if (!input) {\r\n        size_t osize = 0;\r\n        luaL_pushresult(&buffer);\r\n        /* if the output is empty  and the input is nil, return nil */\r\n        lua_tolstring(L, -1, &osize);\r\n        if (osize == 0) lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* otherwise, process the rest of the input */\r\n    last = input + isize;\r\n    while (input < last) \r\n        asize = b64decode(*input++, atom, asize, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushlstring(L, (char *) atom, asize);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Quoted-printable encoding scheme\r\n* all (except CRLF in text) can be =XX\r\n* CLRL in not text must be =XX=XX\r\n* 33 through 60 inclusive can be plain\r\n* 62 through 126 inclusive can be plain\r\n* 9 and 32 can be plain, unless in the end of a line, where must be =XX\r\n* encoded lines must be no longer than 76 not counting CRLF\r\n* soft line-break are =CRLF\r\n* To encode one byte, we need to see the next two. \r\n* Worst case is when we see a space, and wonder if a CRLF is comming\r\n\\*-------------------------------------------------------------------------*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Split quoted-printable characters into classes\r\n* Precompute reverse map for encoding\r\n\\*-------------------------------------------------------------------------*/\r\nstatic void qpsetup(UC *cl, UC *unbase)\r\n{\r\n    int i;\r\n    for (i = 0; i < 256; i++) cl[i] = QP_QUOTED;\r\n    for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN;\r\n    for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN;\r\n    cl['\\t'] = QP_IF_LAST; \r\n    cl[' '] = QP_IF_LAST;\r\n    cl['\\r'] = QP_CR;\r\n    for (i = 0; i < 256; i++) unbase[i] = 255;\r\n    unbase['0'] = 0; unbase['1'] = 1; unbase['2'] = 2;\r\n    unbase['3'] = 3; unbase['4'] = 4; unbase['5'] = 5;\r\n    unbase['6'] = 6; unbase['7'] = 7; unbase['8'] = 8;\r\n    unbase['9'] = 9; unbase['A'] = 10; unbase['a'] = 10;\r\n    unbase['B'] = 11; unbase['b'] = 11; unbase['C'] = 12;\r\n    unbase['c'] = 12; unbase['D'] = 13; unbase['d'] = 13;\r\n    unbase['E'] = 14; unbase['e'] = 14; unbase['F'] = 15;\r\n    unbase['f'] = 15;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Output one character in form =XX\r\n\\*-------------------------------------------------------------------------*/\r\nstatic void qpquote(UC c, luaL_Buffer *buffer)\r\n{\r\n    luaL_addchar(buffer, '=');\r\n    luaL_addchar(buffer, qpbase[c >> 4]);\r\n    luaL_addchar(buffer, qpbase[c & 0x0F]);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Accumulate characters until we are sure about how to deal with them.\r\n* Once we are sure, output to the buffer, in the correct form. \r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t qpencode(UC c, UC *input, size_t size, \r\n        const char *marker, luaL_Buffer *buffer)\r\n{\r\n    input[size++] = c;\r\n    /* deal with all characters we can have */\r\n    while (size > 0) {\r\n        switch (qpclass[input[0]]) {\r\n            /* might be the CR of a CRLF sequence */\r\n            case QP_CR:\r\n                if (size < 2) return size;\r\n                if (input[1] == '\\n') {\r\n                    luaL_addstring(buffer, marker);\r\n                    return 0;\r\n                } else qpquote(input[0], buffer);\r\n                break;\r\n            /* might be a space and that has to be quoted if last in line */\r\n            case QP_IF_LAST:\r\n                if (size < 3) return size;\r\n                /* if it is the last, quote it and we are done */\r\n                if (input[1] == '\\r' && input[2] == '\\n') {\r\n                    qpquote(input[0], buffer);\r\n                    luaL_addstring(buffer, marker);\r\n                    return 0;\r\n                } else luaL_addchar(buffer, input[0]);\r\n                break;\r\n                /* might have to be quoted always */\r\n            case QP_QUOTED:\r\n                qpquote(input[0], buffer);\r\n                break;\r\n                /* might never have to be quoted */\r\n            default:\r\n                luaL_addchar(buffer, input[0]);\r\n                break;\r\n        }\r\n        input[0] = input[1]; input[1] = input[2];\r\n        size--;\r\n    }\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Deal with the final characters \r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)\r\n{\r\n    size_t i;\r\n    for (i = 0; i < size; i++) {\r\n        if (qpclass[input[i]] == QP_PLAIN) luaL_addchar(buffer, input[i]);\r\n        else qpquote(input[i], buffer);\r\n    }\r\n    if (size > 0) luaL_addstring(buffer, EQCRLF);\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally converts a string to quoted-printable\r\n* A, B = qp(C, D, marker)\r\n* Marker is the text to be used to replace CRLF sequences found in A.\r\n* A is the encoded version of the largest prefix of C .. D that \r\n* can be encoded without doubts. \r\n* B has the remaining bytes of C .. D, *without* encoding.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_qp(lua_State *L)\r\n{\r\n\r\n    size_t asize = 0, isize = 0;\r\n    UC atom[3];\r\n    const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);\r\n    const UC *last = input + isize;\r\n    const char *marker = luaL_optstring(L, 3, CRLF);\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* make sure we don't confuse buffer stuff with arguments */\r\n    lua_settop(L, 3);\r\n    /* process first part of input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last)\r\n        asize = qpencode(*input++, atom, asize, marker, &buffer);\r\n    input = (UC *) luaL_optlstring(L, 2, NULL, &isize);\r\n    /* if second part is nil, we are done */\r\n    if (!input) {\r\n        asize = qppad(atom, asize, &buffer);\r\n        luaL_pushresult(&buffer);\r\n        if (!(*lua_tostring(L, -1))) lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* otherwise process rest of input */\r\n    last = input + isize;\r\n    while (input < last)\r\n        asize = qpencode(*input++, atom, asize, marker, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushlstring(L, (char *) atom, asize);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Accumulate characters until we are sure about how to deal with them.\r\n* Once we are sure, output the to the buffer, in the correct form. \r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {\r\n    int d;\r\n    input[size++] = c;\r\n    /* deal with all characters we can deal */\r\n    switch (input[0]) {\r\n        /* if we have an escape character */\r\n        case '=': \r\n            if (size < 3) return size; \r\n            /* eliminate soft line break */\r\n            if (input[1] == '\\r' && input[2] == '\\n') return 0;\r\n            /* decode quoted representation */\r\n            c = qpunbase[input[1]]; d = qpunbase[input[2]];\r\n            /* if it is an invalid, do not decode */\r\n            if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);\r\n            else luaL_addchar(buffer, (char) ((c << 4) + d));\r\n            return 0;\r\n        case '\\r':\r\n            if (size < 2) return size; \r\n            if (input[1] == '\\n') luaL_addlstring(buffer, (char *)input, 2);\r\n            return 0;\r\n        default:\r\n            if (input[0] == '\\t' || (input[0] > 31 && input[0] < 127))\r\n                luaL_addchar(buffer, input[0]);\r\n            return 0;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally decodes a string in quoted-printable\r\n* A, B = qp(C, D)\r\n* A is the decoded version of the largest prefix of C .. D that \r\n* can be decoded without doubts. \r\n* B has the remaining bytes of C .. D, *without* decoding.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_unqp(lua_State *L)\r\n{\r\n    size_t asize = 0, isize = 0;\r\n    UC atom[3];\r\n    const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);\r\n    const UC *last = input + isize;\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    }\r\n    /* make sure we don't confuse buffer stuff with arguments */\r\n    lua_settop(L, 2);\r\n    /* process first part of input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last)\r\n        asize = qpdecode(*input++, atom, asize, &buffer);\r\n    input = (UC *) luaL_optlstring(L, 2, NULL, &isize);\r\n    /* if second part is nil, we are done */\r\n    if (!input) {\r\n        luaL_pushresult(&buffer);\r\n        if (!(*lua_tostring(L, -1))) lua_pushnil(L);\r\n        lua_pushnil(L);\r\n        return 2;\r\n    } \r\n    /* otherwise process rest of input */\r\n    last = input + isize;\r\n    while (input < last)\r\n        asize = qpdecode(*input++, atom, asize, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushlstring(L, (char *) atom, asize);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally breaks a quoted-printed string into lines\r\n* A, n = qpwrp(l, B, length)\r\n* A is a copy of B, broken into lines of at most 'length' bytes. \r\n* 'l' is how many bytes are left for the first line of B. \r\n* 'n' is the number of bytes left in the last line of A. \r\n* There are two complications: lines can't be broken in the middle\r\n* of an encoded =XX, and there might be line breaks already\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_qpwrp(lua_State *L)\r\n{\r\n    size_t size = 0;\r\n    int left = (int) luaL_checknumber(L, 1);\r\n    const UC *input = (UC *) luaL_optlstring(L, 2, NULL, &size);\r\n    const UC *last = input + size;\r\n    int length = (int) luaL_optnumber(L, 3, 76);\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        if (left < length) lua_pushstring(L, EQCRLF);\r\n        else lua_pushnil(L);\r\n        lua_pushnumber(L, length);\r\n        return 2;\r\n    }\r\n    /* process all input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last) {\r\n        switch (*input) {\r\n            case '\\r':\r\n                break;\r\n            case '\\n':\r\n                left = length;\r\n                luaL_addstring(&buffer, CRLF);\r\n                break;\r\n            case '=':\r\n                if (left <= 3) {\r\n                    left = length;\r\n                    luaL_addstring(&buffer, EQCRLF);\r\n                } \r\n                luaL_addchar(&buffer, *input);\r\n                left--;\r\n                break;\r\n            default: \r\n                if (left <= 1) {\r\n                    left = length;\r\n                    luaL_addstring(&buffer, EQCRLF);\r\n                }\r\n                luaL_addchar(&buffer, *input);\r\n                left--;\r\n                break;\r\n        }\r\n        input++;\r\n    }\r\n    luaL_pushresult(&buffer);\r\n    lua_pushnumber(L, left);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Here is what we do: \\n, and \\r are considered candidates for line\r\n* break. We issue *one* new line marker if any of them is seen alone, or\r\n* followed by a different one. That is, \\n\\n and \\r\\r will issue two\r\n* end of line markers each, but \\r\\n, \\n\\r etc will only issue *one*\r\n* marker.  This covers Mac OS, Mac OS X, VMS, Unix and DOS, as well as\r\n* probably other more obscure conventions.\r\n*\r\n* c is the current character being processed\r\n* last is the previous character\r\n\\*-------------------------------------------------------------------------*/\r\n#define eolcandidate(c) (c == '\\r' || c == '\\n')\r\nstatic int eolprocess(int c, int last, const char *marker, \r\n        luaL_Buffer *buffer)\r\n{\r\n    if (eolcandidate(c)) {\r\n        if (eolcandidate(last)) {\r\n            if (c == last) luaL_addstring(buffer, marker);\r\n            return 0;\r\n        } else {\r\n            luaL_addstring(buffer, marker);\r\n            return c;\r\n        }\r\n    } else {\r\n        luaL_addchar(buffer, (char) c);\r\n        return 0;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Converts a string to uniform EOL convention. \r\n* A, n = eol(o, B, marker)\r\n* A is the converted version of the largest prefix of B that can be\r\n* converted unambiguously. 'o' is the context returned by the previous \r\n* call. 'n' is the new context.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_eol(lua_State *L)\r\n{\r\n    int ctx = luaL_checkint(L, 1);\r\n    size_t isize = 0;\r\n    const char *input = luaL_optlstring(L, 2, NULL, &isize);\r\n    const char *last = input + isize;\r\n    const char *marker = luaL_optstring(L, 3, CRLF);\r\n    luaL_Buffer buffer;\r\n    luaL_buffinit(L, &buffer);\r\n    /* end of input blackhole */\r\n    if (!input) {\r\n       lua_pushnil(L);\r\n       lua_pushnumber(L, 0);\r\n       return 2;\r\n    }\r\n    /* process all input */\r\n    while (input < last)\r\n        ctx = eolprocess(*input++, ctx, marker, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushnumber(L, ctx);\r\n    return 2;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Takes one byte and stuff it if needed. \r\n\\*-------------------------------------------------------------------------*/\r\nstatic size_t dot(int c, size_t state, luaL_Buffer *buffer)\r\n{\r\n    luaL_addchar(buffer, (char) c);\r\n    switch (c) {\r\n        case '\\r': \r\n            return 1;\r\n        case '\\n': \r\n            return (state == 1)? 2: 0; \r\n        case '.':  \r\n            if (state == 2) \r\n                luaL_addchar(buffer, '.');\r\n        default:\r\n            return 0;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Incrementally applies smtp stuffing to a string\r\n* A, n = dot(l, D)\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int mime_global_dot(lua_State *L)\r\n{\r\n    size_t isize = 0, state = (size_t) luaL_checknumber(L, 1);\r\n    const char *input = luaL_optlstring(L, 2, NULL, &isize);\r\n    const char *last = input + isize;\r\n    luaL_Buffer buffer;\r\n    /* end-of-input blackhole */\r\n    if (!input) {\r\n        lua_pushnil(L);\r\n        lua_pushnumber(L, 2);\r\n        return 2;\r\n    }\r\n    /* process all input */\r\n    luaL_buffinit(L, &buffer);\r\n    while (input < last) \r\n        state = dot(*input++, state, &buffer);\r\n    luaL_pushresult(&buffer);\r\n    lua_pushnumber(L, (lua_Number) state);\r\n    return 2;\r\n}\r\n\r\n"
  },
  {
    "path": "build/luasocket/mime.h",
    "content": "#ifndef MIME_H \r\n#define MIME_H \r\n/*=========================================================================*\\\r\n* Core MIME support\r\n* LuaSocket toolkit\r\n*\r\n* This module provides functions to implement transfer content encodings\r\n* and formatting conforming to RFC 2045. It is used by mime.lua, which\r\n* provide a higher level interface to this functionality. \r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Current MIME library version\r\n\\*-------------------------------------------------------------------------*/\r\n#define MIME_VERSION    \"MIME 1.0.3\"\r\n#define MIME_COPYRIGHT  \"Copyright (C) 2004-2013 Diego Nehab\"\r\n#define MIME_AUTHORS    \"Diego Nehab\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* This macro prefixes all exported API functions\r\n\\*-------------------------------------------------------------------------*/\r\n#ifndef MIME_API\r\n#define MIME_API extern\r\n#endif\r\n\r\nMIME_API int luaopen_mime_core(lua_State *L);\r\n\r\n#endif /* MIME_H */\r\n"
  },
  {
    "path": "build/luasocket/options.c",
    "content": "/*=========================================================================*\\\r\n* Common option interface \r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h> \r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"options.h\"\r\n#include \"inet.h\"\r\n\r\n\r\n\r\n/*=========================================================================*\\\r\n* Internal functions prototypes\r\n\\*=========================================================================*/\r\nstatic int opt_setmembership(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_setboolean(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_getboolean(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_setint(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_getint(lua_State *L, p_socket ps, int level, int name);\r\nstatic int opt_set(lua_State *L, p_socket ps, int level, int name, \r\n        void *val, int len);\r\nstatic int opt_get(lua_State *L, p_socket ps, int level, int name, \r\n        void *val, int* len);\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Calls appropriate option handler\r\n\\*-------------------------------------------------------------------------*/\r\nint opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps)\r\n{\r\n    const char *name = luaL_checkstring(L, 2);      /* obj, name, ... */\r\n    while (opt->name && strcmp(name, opt->name))\r\n        opt++;\r\n    if (!opt->func) {\r\n        char msg[45];\r\n        sprintf(msg, \"unsupported option `%.35s'\", name);\r\n        luaL_argerror(L, 2, msg);\r\n    }\r\n    return opt->func(L, ps);\r\n}\r\n\r\nint opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)\r\n{\r\n    const char *name = luaL_checkstring(L, 2);      /* obj, name, ... */\r\n    while (opt->name && strcmp(name, opt->name))\r\n        opt++;\r\n    if (!opt->func) {\r\n        char msg[45];\r\n        sprintf(msg, \"unsupported option `%.35s'\", name);\r\n        luaL_argerror(L, 2, msg);\r\n    }\r\n    return opt->func(L, ps);\r\n}\r\n\r\n/* enables reuse of local address */\r\nint opt_set_reuseaddr(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); \r\n}\r\n\r\nint opt_get_reuseaddr(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); \r\n}\r\n\r\n/* enables reuse of local port */\r\nint opt_set_reuseport(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); \r\n}\r\n\r\nint opt_get_reuseport(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); \r\n}\r\n\r\n/* disables the Naggle algorithm */\r\nint opt_set_tcp_nodelay(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); \r\n}\r\n\r\nint opt_get_tcp_nodelay(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);\r\n}\r\n\r\nint opt_set_keepalive(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); \r\n}\r\n\r\nint opt_get_keepalive(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); \r\n}\r\n\r\nint opt_set_dontroute(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);\r\n}\r\n\r\nint opt_set_broadcast(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST);\r\n}\r\n\r\nint opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)\r\n{\r\n  return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);\r\n}\r\n\r\nint opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)\r\n{\r\n  return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);\r\n}\r\n\r\nint opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)\r\n{\r\n  return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);\r\n}\r\n\r\nint opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)\r\n{\r\n  return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);\r\n}\r\n\r\nint opt_set_ip_multicast_loop(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);\r\n}\r\n\r\nint opt_get_ip_multicast_loop(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);\r\n}\r\n\r\nint opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);\r\n}\r\n\r\nint opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);\r\n}\r\n\r\nint opt_set_linger(lua_State *L, p_socket ps)\r\n{\r\n    struct linger li;                      /* obj, name, table */\r\n    if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));\r\n    lua_pushstring(L, \"on\");\r\n    lua_gettable(L, 3);\r\n    if (!lua_isboolean(L, -1)) \r\n        luaL_argerror(L, 3, \"boolean 'on' field expected\");\r\n    li.l_onoff = (u_short) lua_toboolean(L, -1);\r\n    lua_pushstring(L, \"timeout\");\r\n    lua_gettable(L, 3);\r\n    if (!lua_isnumber(L, -1)) \r\n        luaL_argerror(L, 3, \"number 'timeout' field expected\");\r\n    li.l_linger = (u_short) lua_tonumber(L, -1);\r\n    return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));\r\n}\r\n\r\nint opt_get_linger(lua_State *L, p_socket ps)\r\n{\r\n    struct linger li;                      /* obj, name */\r\n    int len = sizeof(li);\r\n    int err = opt_get(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, &len);\r\n    if (err)\r\n        return err;\r\n    lua_newtable(L);\r\n    lua_pushboolean(L, li.l_onoff);\r\n    lua_setfield(L, -2, \"on\");\r\n    lua_pushinteger(L, li.l_linger);\r\n    lua_setfield(L, -2, \"timeout\");\r\n    return 1;\r\n}\r\n\r\nint opt_set_ip_multicast_ttl(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL);\r\n}\r\n\r\nint opt_set_ip_multicast_if(lua_State *L, p_socket ps)\r\n{\r\n    const char *address = luaL_checkstring(L, 3);    /* obj, name, ip */\r\n    struct in_addr val;\r\n    val.s_addr = htonl(INADDR_ANY);\r\n    if (strcmp(address, \"*\") && !inet_aton(address, &val))\r\n        luaL_argerror(L, 3, \"ip expected\");\r\n    return opt_set(L, ps, IPPROTO_IP, IP_MULTICAST_IF, \r\n        (char *) &val, sizeof(val));\r\n}\r\n\r\nint opt_get_ip_multicast_if(lua_State *L, p_socket ps)\r\n{\r\n    struct in_addr val;\r\n    socklen_t len = sizeof(val);\r\n    if (getsockopt(*ps, IPPROTO_IP, IP_MULTICAST_IF, (char *) &val, &len) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, \"getsockopt failed\");\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, inet_ntoa(val));\r\n    return 1;\r\n}\r\n\r\nint opt_set_ip_add_membership(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP);\r\n}\r\n\r\nint opt_set_ip_drop_membersip(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);\r\n}\r\n\r\nint opt_set_ip6_add_membership(lua_State *L, p_socket ps)\r\n{\r\n    return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);\r\n}\r\n\r\nint opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)\r\n{\r\n    return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);\r\n}\r\n\r\nint opt_get_ip6_v6only(lua_State *L, p_socket ps)\r\n{\r\n    return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);\r\n}\r\n\r\nint opt_set_ip6_v6only(lua_State *L, p_socket ps)\r\n{\r\n    return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Auxiliar functions\r\n\\*=========================================================================*/\r\nstatic int opt_setmembership(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    struct ip_mreq val;                   /* obj, name, table */\r\n    if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));\r\n    lua_pushstring(L, \"multiaddr\");\r\n    lua_gettable(L, 3);\r\n    if (!lua_isstring(L, -1)) \r\n        luaL_argerror(L, 3, \"string 'multiaddr' field expected\");\r\n    if (!inet_aton(lua_tostring(L, -1), &val.imr_multiaddr)) \r\n        luaL_argerror(L, 3, \"invalid 'multiaddr' ip address\");\r\n    lua_pushstring(L, \"interface\");\r\n    lua_gettable(L, 3);\r\n    if (!lua_isstring(L, -1)) \r\n        luaL_argerror(L, 3, \"string 'interface' field expected\");\r\n    val.imr_interface.s_addr = htonl(INADDR_ANY);\r\n    if (strcmp(lua_tostring(L, -1), \"*\") &&\r\n            !inet_aton(lua_tostring(L, -1), &val.imr_interface)) \r\n        luaL_argerror(L, 3, \"invalid 'interface' ip address\");\r\n    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));\r\n}\r\n\r\nstatic int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    struct ipv6_mreq val;                   /* obj, opt-name, table */\r\n    memset(&val, 0, sizeof(val));\r\n    if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));\r\n    lua_pushstring(L, \"multiaddr\");\r\n    lua_gettable(L, 3);\r\n    if (!lua_isstring(L, -1)) \r\n        luaL_argerror(L, 3, \"string 'multiaddr' field expected\");\r\n    if (!inet_pton_w32(AF_INET6, lua_tostring(L, -1), &val.ipv6mr_multiaddr)) \r\n        luaL_argerror(L, 3, \"invalid 'multiaddr' ip address\");\r\n    lua_pushstring(L, \"interface\");\r\n    lua_gettable(L, 3);\r\n    /* By default we listen to interface on default route\r\n     * (sigh). However, interface= can override it. We should \r\n     * support either number, or name for it. Waiting for\r\n     * windows port of if_nametoindex */\r\n    if (!lua_isnil(L, -1)) {\r\n        if (lua_isnumber(L, -1)) {\r\n            val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1);\r\n        } else\r\n          luaL_argerror(L, -1, \"number 'interface' field expected\");\r\n    }\r\n    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));\r\n}\r\n\r\nstatic \r\nint opt_get(lua_State *L, p_socket ps, int level, int name, void *val, int* len)\r\n{\r\n    socklen_t socklen = *len;\r\n    if (getsockopt(*ps, level, name, (char *) val, &socklen) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, \"getsockopt failed\");\r\n        return 2;\r\n    }\r\n    *len = socklen;\r\n    return 0;\r\n}\r\n\r\nstatic \r\nint opt_set(lua_State *L, p_socket ps, int level, int name, void *val, int len)\r\n{\r\n    if (setsockopt(*ps, level, name, (char *) val, len) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, \"setsockopt failed\");\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\nstatic int opt_getboolean(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    int val = 0;\r\n    int len = sizeof(val);\r\n    int err = opt_get(L, ps, level, name, (char *) &val, &len);\r\n    if (err)\r\n        return err;\r\n    lua_pushboolean(L, val);\r\n    return 1;\r\n}\r\n\r\nint opt_get_error(lua_State *L, p_socket ps)\r\n{\r\n    int val = 0;\r\n    socklen_t len = sizeof(val);\r\n    if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, \"getsockopt failed\");\r\n        return 2;\r\n    }\r\n    lua_pushstring(L, socket_strerror(val));\r\n    return 1;\r\n}\r\n\r\nstatic int opt_setboolean(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    int val = auxiliar_checkboolean(L, 3);             /* obj, name, bool */\r\n    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));\r\n}\r\n\r\nstatic int opt_getint(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    int val = 0;\r\n    int len = sizeof(val);\r\n    int err = opt_get(L, ps, level, name, (char *) &val, &len);\r\n    if (err)\r\n        return err;\r\n    lua_pushnumber(L, val);\r\n    return 1;\r\n}\r\n\r\nstatic int opt_setint(lua_State *L, p_socket ps, int level, int name)\r\n{\r\n    int val = (int) lua_tonumber(L, 3);             /* obj, name, int */\r\n    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));\r\n}\r\n"
  },
  {
    "path": "build/luasocket/options.h",
    "content": "#ifndef OPTIONS_H\r\n#define OPTIONS_H\r\n/*=========================================================================*\\\r\n* Common option interface \r\n* LuaSocket toolkit\r\n*\r\n* This module provides a common interface to socket options, used mainly by\r\n* modules UDP and TCP. \r\n\\*=========================================================================*/\r\n\r\n#include \"lua.h\"\r\n#include \"socket.h\"\r\n\r\n/* option registry */\r\ntypedef struct t_opt {\r\n  const char *name;\r\n  int (*func)(lua_State *L, p_socket ps);\r\n} t_opt;\r\ntypedef t_opt *p_opt;\r\n\r\n/* supported options for setoption */\r\nint opt_set_dontroute(lua_State *L, p_socket ps);\r\nint opt_set_broadcast(lua_State *L, p_socket ps);\r\nint opt_set_reuseaddr(lua_State *L, p_socket ps);\r\nint opt_set_tcp_nodelay(lua_State *L, p_socket ps);\r\nint opt_set_keepalive(lua_State *L, p_socket ps);\r\nint opt_set_linger(lua_State *L, p_socket ps);\r\nint opt_set_reuseaddr(lua_State *L, p_socket ps);\r\nint opt_set_reuseport(lua_State *L, p_socket ps);\r\nint opt_set_ip_multicast_if(lua_State *L, p_socket ps);\r\nint opt_set_ip_multicast_ttl(lua_State *L, p_socket ps);\r\nint opt_set_ip_multicast_loop(lua_State *L, p_socket ps);\r\nint opt_set_ip_add_membership(lua_State *L, p_socket ps);\r\nint opt_set_ip_drop_membersip(lua_State *L, p_socket ps);\r\nint opt_set_ip6_unicast_hops(lua_State *L, p_socket ps);\r\nint opt_set_ip6_multicast_hops(lua_State *L, p_socket ps);\r\nint opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);\r\nint opt_set_ip6_add_membership(lua_State *L, p_socket ps);\r\nint opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);\r\nint opt_set_ip6_v6only(lua_State *L, p_socket ps);\r\n\r\n/* supported options for getoption */\r\nint opt_get_reuseaddr(lua_State *L, p_socket ps);\r\nint opt_get_tcp_nodelay(lua_State *L, p_socket ps);\r\nint opt_get_keepalive(lua_State *L, p_socket ps);\r\nint opt_get_linger(lua_State *L, p_socket ps);\r\nint opt_get_reuseaddr(lua_State *L, p_socket ps);\r\nint opt_get_ip_multicast_loop(lua_State *L, p_socket ps);\r\nint opt_get_ip_multicast_if(lua_State *L, p_socket ps);\r\nint opt_get_error(lua_State *L, p_socket ps);\r\nint opt_get_ip6_multicast_loop(lua_State *L, p_socket ps);\r\nint opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);\r\nint opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);\r\nint opt_get_ip6_v6only(lua_State *L, p_socket ps); \r\n\r\n/* invokes the appropriate option handler */\r\nint opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps);\r\nint opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps);\r\n\r\n#endif\r\n"
  },
  {
    "path": "build/luasocket/select.c",
    "content": "/*=========================================================================*\\\r\n* Select implementation\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"socket.h\"\r\n#include \"timeout.h\"\r\n#include \"select.h\"\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes.\r\n\\*=========================================================================*/\r\nstatic t_socket getfd(lua_State *L);\r\nstatic int dirty(lua_State *L);\r\nstatic void collect_fd(lua_State *L, int tab, int itab, \r\n        fd_set *set, t_socket *max_fd);\r\nstatic int check_dirty(lua_State *L, int tab, int dtab, fd_set *set);\r\nstatic void return_fd(lua_State *L, fd_set *set, t_socket max_fd, \r\n        int itab, int tab, int start);\r\nstatic void make_assoc(lua_State *L, int tab);\r\nstatic int global_select(lua_State *L);\r\n\r\n/* functions in library namespace */\r\nstatic luaL_Reg func[] = {\r\n    {\"select\", global_select},\r\n    {NULL,     NULL}\r\n};\r\n\r\n/*=========================================================================*\\\r\n* Exported functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint select_open(lua_State *L) {\r\n    lua_pushstring(L, \"_SETSIZE\");\r\n    lua_pushnumber(L, FD_SETSIZE);\r\n    lua_rawset(L, -3);\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    return 0;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Global Lua functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Waits for a set of sockets until a condition is met or timeout.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_select(lua_State *L) {\r\n    int rtab, wtab, itab, ret, ndirty;\r\n    t_socket max_fd = SOCKET_INVALID;\r\n    fd_set rset, wset;\r\n    t_timeout tm;\r\n    double t = luaL_optnumber(L, 3, -1);\r\n    FD_ZERO(&rset); FD_ZERO(&wset);\r\n    lua_settop(L, 3);\r\n    lua_newtable(L); itab = lua_gettop(L);\r\n    lua_newtable(L); rtab = lua_gettop(L);\r\n    lua_newtable(L); wtab = lua_gettop(L);\r\n    collect_fd(L, 1, itab, &rset, &max_fd);\r\n    collect_fd(L, 2, itab, &wset, &max_fd);\r\n    ndirty = check_dirty(L, 1, rtab, &rset);\r\n    t = ndirty > 0? 0.0: t;\r\n    timeout_init(&tm, t, -1);\r\n    timeout_markstart(&tm);\r\n    ret = socket_select(max_fd+1, &rset, &wset, NULL, &tm);\r\n    if (ret > 0 || ndirty > 0) {\r\n        return_fd(L, &rset, max_fd+1, itab, rtab, ndirty);\r\n        return_fd(L, &wset, max_fd+1, itab, wtab, 0);\r\n        make_assoc(L, rtab);\r\n        make_assoc(L, wtab);\r\n        return 2;\r\n    } else if (ret == 0) {\r\n        lua_pushstring(L, \"timeout\");\r\n        return 3;\r\n    } else {\r\n        luaL_error(L, \"select failed\");\r\n        return 3;\r\n    }\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Internal functions\r\n\\*=========================================================================*/\r\nstatic t_socket getfd(lua_State *L) {\r\n    t_socket fd = SOCKET_INVALID;\r\n    lua_pushstring(L, \"getfd\");\r\n    lua_gettable(L, -2);\r\n    if (!lua_isnil(L, -1)) {\r\n        lua_pushvalue(L, -2);\r\n        lua_call(L, 1, 1);\r\n        if (lua_isnumber(L, -1)) {\r\n            double numfd = lua_tonumber(L, -1); \r\n            fd = (numfd >= 0.0)? (t_socket) numfd: SOCKET_INVALID;\r\n        }\r\n    } \r\n    lua_pop(L, 1);\r\n    return fd;\r\n}\r\n\r\nstatic int dirty(lua_State *L) {\r\n    int is = 0;\r\n    lua_pushstring(L, \"dirty\");\r\n    lua_gettable(L, -2);\r\n    if (!lua_isnil(L, -1)) {\r\n        lua_pushvalue(L, -2);\r\n        lua_call(L, 1, 1);\r\n        is = lua_toboolean(L, -1);\r\n    } \r\n    lua_pop(L, 1);\r\n    return is;\r\n}\r\n\r\nstatic void collect_fd(lua_State *L, int tab, int itab, \r\n        fd_set *set, t_socket *max_fd) {\r\n    int i = 1, n = 0;\r\n    /* nil is the same as an empty table */\r\n    if (lua_isnil(L, tab)) return;\r\n    /* otherwise we need it to be a table */\r\n    luaL_checktype(L, tab, LUA_TTABLE);\r\n    for ( ;; ) {\r\n        t_socket fd;\r\n        lua_pushnumber(L, i);\r\n        lua_gettable(L, tab);\r\n        if (lua_isnil(L, -1)) {\r\n            lua_pop(L, 1);\r\n            break;\r\n        }\r\n        /* getfd figures out if this is a socket */\r\n        fd = getfd(L);\r\n        if (fd != SOCKET_INVALID) {\r\n            /* make sure we don't overflow the fd_set */\r\n#ifdef _WIN32\r\n            if (n >= FD_SETSIZE) \r\n                luaL_argerror(L, tab, \"too many sockets\");\r\n#else\r\n            if (fd >= FD_SETSIZE) \r\n                luaL_argerror(L, tab, \"descriptor too large for set size\");\r\n#endif\r\n            FD_SET(fd, set);\r\n            n++;\r\n            /* keep track of the largest descriptor so far */\r\n            if (*max_fd == SOCKET_INVALID || *max_fd < fd) \r\n                *max_fd = fd;\r\n            /* make sure we can map back from descriptor to the object */\r\n            lua_pushnumber(L, (lua_Number) fd);\r\n            lua_pushvalue(L, -2);\r\n            lua_settable(L, itab);\r\n        }\r\n        lua_pop(L, 1);\r\n        i = i + 1;\r\n    }\r\n}\r\n\r\nstatic int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) {\r\n    int ndirty = 0, i = 1;\r\n    if (lua_isnil(L, tab)) \r\n        return 0;\r\n    for ( ;; ) { \r\n        t_socket fd;\r\n        lua_pushnumber(L, i);\r\n        lua_gettable(L, tab);\r\n        if (lua_isnil(L, -1)) {\r\n            lua_pop(L, 1);\r\n            break;\r\n        }\r\n        fd = getfd(L);\r\n        if (fd != SOCKET_INVALID && dirty(L)) {\r\n            lua_pushnumber(L, ++ndirty);\r\n            lua_pushvalue(L, -2);\r\n            lua_settable(L, dtab);\r\n            FD_CLR(fd, set);\r\n        }\r\n        lua_pop(L, 1);\r\n        i = i + 1;\r\n    }\r\n    return ndirty;\r\n}\r\n\r\nstatic void return_fd(lua_State *L, fd_set *set, t_socket max_fd, \r\n        int itab, int tab, int start) {\r\n    t_socket fd;\r\n    for (fd = 0; fd < max_fd; fd++) {\r\n        if (FD_ISSET(fd, set)) {\r\n            lua_pushnumber(L, ++start);\r\n            lua_pushnumber(L, (lua_Number) fd);\r\n            lua_gettable(L, itab);\r\n            lua_settable(L, tab);\r\n        }\r\n    }\r\n}\r\n\r\nstatic void make_assoc(lua_State *L, int tab) {\r\n    int i = 1, atab;\r\n    lua_newtable(L); atab = lua_gettop(L);\r\n    for ( ;; ) {\r\n        lua_pushnumber(L, i);\r\n        lua_gettable(L, tab);\r\n        if (!lua_isnil(L, -1)) {\r\n            lua_pushnumber(L, i);\r\n            lua_pushvalue(L, -2);\r\n            lua_settable(L, atab);\r\n            lua_pushnumber(L, i);\r\n            lua_settable(L, atab);\r\n        } else {\r\n            lua_pop(L, 1);\r\n            break;\r\n        }\r\n        i = i+1;\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "build/luasocket/select.h",
    "content": "#ifndef SELECT_H\r\n#define SELECT_H\r\n/*=========================================================================*\\\r\n* Select implementation\r\n* LuaSocket toolkit\r\n*\r\n* Each object that can be passed to the select function has to export \r\n* method getfd() which returns the descriptor to be passed to the\r\n* underlying select function. Another method, dirty(), should return \r\n* true if there is data ready for reading (required for buffered input).\r\n\\*=========================================================================*/\r\n\r\nint select_open(lua_State *L);\r\n\r\n#endif /* SELECT_H */\r\n"
  },
  {
    "path": "build/luasocket/serial.c",
    "content": "/*=========================================================================*\\\r\n* Serial stream\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h> \r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"socket.h\"\r\n#include \"options.h\"\r\n#include \"unix.h\"\r\n#include \"luasocket.h\"\r\n#include <sys/un.h> \r\n\r\n/*\r\nReuses userdata definition from unix.h, since it is useful for all\r\nstream-like objects.\r\n\r\nIf we stored the serial path for use in error messages or userdata\r\nprinting, we might need our own userdata definition.\r\n\r\nGroup usage is semi-inherited from unix.c, but unnecessary since we\r\nhave only one object type.\r\n*/\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes\r\n\\*=========================================================================*/\r\nstatic int global_create(lua_State *L);\r\nstatic int meth_send(lua_State *L);\r\nstatic int meth_receive(lua_State *L);\r\nstatic int meth_close(lua_State *L);\r\nstatic int meth_settimeout(lua_State *L);\r\nstatic int meth_getfd(lua_State *L);\r\nstatic int meth_setfd(lua_State *L);\r\nstatic int meth_dirty(lua_State *L);\r\nstatic int meth_getstats(lua_State *L);\r\nstatic int meth_setstats(lua_State *L);\r\n\r\n/* serial object methods */\r\nstatic luaL_Reg serial_methods[] = {\r\n    {\"__gc\",        meth_close},\r\n    {\"__tostring\",  auxiliar_tostring},\r\n    {\"close\",       meth_close},\r\n    {\"dirty\",       meth_dirty},\r\n    {\"getfd\",       meth_getfd},\r\n    {\"getstats\",    meth_getstats},\r\n    {\"setstats\",    meth_setstats},\r\n    {\"receive\",     meth_receive},\r\n    {\"send\",        meth_send},\r\n    {\"setfd\",       meth_setfd},\r\n    {\"settimeout\",  meth_settimeout},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* our socket creation function */\r\n/* this is an ad-hoc module that returns a single function \r\n * as such, do not include other functions in this array. */\r\nstatic luaL_Reg func[] = {\r\n    {\"serial\", global_create},\r\n    {NULL,          NULL}\r\n};\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nLUA_API int luaopen_socket_serial(lua_State *L) {\r\n    /* create classes */\r\n    auxiliar_newclass(L, \"serial{client}\", serial_methods);\r\n    /* create class groups */\r\n    auxiliar_add2group(L, \"serial{client}\", \"serial{any}\");\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    lua_pushcfunction(L, global_create);\r\n    (void) func;\r\n#else\r\n    /* set function into socket namespace */\r\n    luaL_openlib(L, \"socket\", func, 0);\r\n    lua_pushcfunction(L, global_create);\r\n#endif\r\n    return 1;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Lua methods\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call buffered IO methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_send(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"serial{client}\", 1);\r\n    return buffer_meth_send(L, &un->buf);\r\n}\r\n\r\nstatic int meth_receive(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"serial{client}\", 1);\r\n    return buffer_meth_receive(L, &un->buf);\r\n}\r\n\r\nstatic int meth_getstats(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"serial{client}\", 1);\r\n    return buffer_meth_getstats(L, &un->buf);\r\n}\r\n\r\nstatic int meth_setstats(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"serial{client}\", 1);\r\n    return buffer_meth_setstats(L, &un->buf);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select support methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfd(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"serial{any}\", 1);\r\n    lua_pushnumber(L, (int) un->sock);\r\n    return 1;\r\n}\r\n\r\n/* this is very dangerous, but can be handy for those that are brave enough */\r\nstatic int meth_setfd(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"serial{any}\", 1);\r\n    un->sock = (t_socket) luaL_checknumber(L, 2); \r\n    return 0;\r\n}\r\n\r\nstatic int meth_dirty(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"serial{any}\", 1);\r\n    lua_pushboolean(L, !buffer_isempty(&un->buf));\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Closes socket used by object \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_close(lua_State *L)\r\n{\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"serial{any}\", 1);\r\n    socket_destroy(&un->sock);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call tm methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_settimeout(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"serial{any}\", 1);\r\n    return timeout_meth_settimeout(L, &un->tm);\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Library functions\r\n\\*=========================================================================*/\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates a serial object \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_create(lua_State *L) {\r\n    const char* path = luaL_checkstring(L, 1);\r\n\r\n    /* allocate unix object */\r\n    p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix));\r\n\r\n    /* open serial device */\r\n    t_socket sock = open(path, O_NOCTTY|O_RDWR);\r\n\r\n    /*printf(\"open %s on %d\\n\", path, sock);*/\r\n\r\n    if (sock < 0)  {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(errno));\r\n        lua_pushnumber(L, errno);\r\n        return 3;\r\n    }\r\n    /* set its type as client object */\r\n    auxiliar_setclass(L, \"serial{client}\", -1);\r\n    /* initialize remaining structure fields */\r\n    socket_setnonblocking(&sock);\r\n    un->sock = sock;\r\n    io_init(&un->io, (p_send) socket_write, (p_recv) socket_read, \r\n            (p_error) socket_ioerror, &un->sock);\r\n    timeout_init(&un->tm, -1, -1);\r\n    buffer_init(&un->buf, &un->io, &un->tm);\r\n    return 1;\r\n}\r\n"
  },
  {
    "path": "build/luasocket/socket.h",
    "content": "#ifndef SOCKET_H\r\n#define SOCKET_H\r\n/*=========================================================================*\\\r\n* Socket compatibilization module\r\n* LuaSocket toolkit\r\n*\r\n* BSD Sockets and WinSock are similar, but there are a few irritating\r\n* differences. Also, not all *nix platforms behave the same. This module\r\n* (and the associated usocket.h and wsocket.h) factor these differences and\r\n* creates a interface compatible with the io.h module.\r\n\\*=========================================================================*/\r\n#include \"io.h\"\r\n\r\n/*=========================================================================*\\\r\n* Platform specific compatibilization\r\n\\*=========================================================================*/\r\n#ifdef _WIN32\r\n#include \"wsocket.h\"\r\n#else\r\n#include \"usocket.h\"\r\n#endif\r\n\r\n/*=========================================================================*\\\r\n* The connect and accept functions accept a timeout and their\r\n* implementations are somewhat complicated. We chose to move\r\n* the timeout control into this module for these functions in\r\n* order to simplify the modules that use them. \r\n\\*=========================================================================*/\r\n#include \"timeout.h\"\r\n\r\n/* we are lazy... */\r\ntypedef struct sockaddr SA;\r\n\r\n/*=========================================================================*\\\r\n* Functions bellow implement a comfortable platform independent \r\n* interface to sockets\r\n\\*=========================================================================*/\r\nint socket_open(void);\r\nint socket_close(void);\r\nvoid socket_destroy(p_socket ps);\r\nvoid socket_shutdown(p_socket ps, int how); \r\nint socket_sendto(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);\r\nint socket_recvfrom(p_socket ps, char *data, size_t count, \r\n        size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);\r\n\r\nvoid socket_setnonblocking(p_socket ps);\r\nvoid socket_setblocking(p_socket ps);\r\n\r\nint socket_waitfd(p_socket ps, int sw, p_timeout tm);\r\nint socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, \r\n        p_timeout tm);\r\n\r\nint socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); \r\nint socket_create(p_socket ps, int domain, int type, int protocol);\r\nint socket_bind(p_socket ps, SA *addr, socklen_t addr_len); \r\nint socket_listen(p_socket ps, int backlog);\r\nint socket_accept(p_socket ps, p_socket pa, SA *addr, \r\n        socklen_t *addr_len, p_timeout tm);\r\n\r\nconst char *socket_hoststrerror(int err);\r\nconst char *socket_gaistrerror(int err);\r\nconst char *socket_strerror(int err);\r\n\r\n/* these are perfect to use with the io abstraction module \r\n   and the buffered input module */\r\nint socket_send(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, p_timeout tm);\r\nint socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);\r\nint socket_write(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, p_timeout tm);\r\nint socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);\r\nconst char *socket_ioerror(p_socket ps, int err);\r\n\r\nint socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);\r\nint socket_gethostbyname(const char *addr, struct hostent **hp);\r\n\r\n#endif /* SOCKET_H */\r\n"
  },
  {
    "path": "build/luasocket/tcp.c",
    "content": "﻿#include <string.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"socket.h\"\r\n#include \"inet.h\"\r\n#include \"options.h\"\r\n#include \"tcp.h\"\r\n#include \"buffer.h\"\r\n\r\n\r\nstatic int global_create(lua_State *L);\r\nstatic int global_create6(lua_State *L);\r\nstatic int global_connect(lua_State *L);\r\nstatic int meth_connect(lua_State *L);\r\nstatic int meth_listen(lua_State *L);\r\nstatic int meth_getfamily(lua_State *L);\r\nstatic int meth_bind(lua_State *L);\r\nstatic int meth_send(lua_State *L);\r\nstatic int meth_getstats(lua_State *L);\r\nstatic int meth_setstats(lua_State *L);\r\nstatic int meth_getsockname(lua_State *L);\r\nstatic int meth_getpeername(lua_State *L);\r\nstatic int meth_shutdown(lua_State *L);\r\nstatic int meth_receive(lua_State *L);\r\nstatic int meth_accept(lua_State *L);\r\nstatic int meth_close(lua_State *L);\r\nstatic int meth_getoption(lua_State *L);\r\nstatic int meth_setoption(lua_State *L);\r\nstatic int meth_settimeout(lua_State *L);\r\nstatic int meth_getfd(lua_State *L);\r\nstatic int meth_setfd(lua_State *L);\r\nstatic int meth_dirty(lua_State *L);\r\n\r\n/* tcp object methods */\r\nstatic luaL_Reg tcp_methods[] = {\r\n    {\"__gc\",        meth_close},\r\n    {\"__tostring\",  auxiliar_tostring},\r\n    {\"accept\",      meth_accept},\r\n    {\"bind\",        meth_bind},\r\n    {\"close\",       meth_close},\r\n    {\"connect\",     meth_connect},\r\n    {\"dirty\",       meth_dirty},\r\n    {\"getfamily\",   meth_getfamily},\r\n    {\"getfd\",       meth_getfd},\r\n    {\"getoption\",   meth_getoption},\r\n    {\"getpeername\", meth_getpeername},\r\n    {\"getsockname\", meth_getsockname},\r\n    {\"getstats\",    meth_getstats},\r\n    {\"setstats\",    meth_setstats},\r\n    {\"listen\",      meth_listen},\r\n    {\"receive\",     meth_receive},\r\n    {\"send\",        meth_send},\r\n    {\"setfd\",       meth_setfd},\r\n    {\"setoption\",   meth_setoption},\r\n    {\"setpeername\", meth_connect},\r\n    {\"setsockname\", meth_bind},\r\n    {\"settimeout\",  meth_settimeout},\r\n    {\"shutdown\",    meth_shutdown},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* socket option handlers */\r\nstatic t_opt optget[] = {\r\n    {\"keepalive\",   opt_get_keepalive},\r\n    {\"reuseaddr\",   opt_get_reuseaddr},\r\n    {\"tcp-nodelay\", opt_get_tcp_nodelay},\r\n    {\"linger\",      opt_get_linger},\r\n    {\"error\",       opt_get_error},\r\n    {NULL,          NULL}\r\n};\r\n\r\nstatic t_opt optset[] = {\r\n    {\"keepalive\",   opt_set_keepalive},\r\n    {\"reuseaddr\",   opt_set_reuseaddr},\r\n    {\"tcp-nodelay\", opt_set_tcp_nodelay},\r\n    {\"ipv6-v6only\", opt_set_ip6_v6only},\r\n    {\"linger\",      opt_set_linger},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* functions in library namespace */\r\nstatic luaL_Reg func[] = {\r\n    {\"tcp\", global_create},\r\n    {\"tcp6\", global_create6},\r\n    {\"connect\", global_connect},\r\n    {NULL, NULL}\r\n};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint tcp_open(lua_State *L)\r\n{\r\n    /* create classes */\r\n    auxiliar_newclass(L, \"tcp{master}\", tcp_methods);\r\n    auxiliar_newclass(L, \"tcp{client}\", tcp_methods);\r\n    auxiliar_newclass(L, \"tcp{server}\", tcp_methods);\r\n    /* create class groups */\r\n    auxiliar_add2group(L, \"tcp{master}\", \"tcp{any}\");\r\n    auxiliar_add2group(L, \"tcp{client}\", \"tcp{any}\");\r\n    auxiliar_add2group(L, \"tcp{server}\", \"tcp{any}\");\r\n    /* define library functions */\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    return 0;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Lua methods\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call buffered IO methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_send(lua_State *L) {\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{client}\", 1);\r\n    return buffer_meth_send(L, &tcp->buf);\r\n}\r\n\r\nstatic int meth_receive(lua_State *L) {\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{client}\", 1);\r\n    return buffer_meth_receive(L, &tcp->buf);\r\n}\r\n\r\nstatic int meth_getstats(lua_State *L) {\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{client}\", 1);\r\n    return buffer_meth_getstats(L, &tcp->buf);\r\n}\r\n\r\nstatic int meth_setstats(lua_State *L) {\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{client}\", 1);\r\n    return buffer_meth_setstats(L, &tcp->buf);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call option handler\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getoption(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    return opt_meth_getoption(L, optget, &tcp->sock);\r\n}\r\n\r\nstatic int meth_setoption(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    return opt_meth_setoption(L, optset, &tcp->sock);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select support methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfd(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    lua_pushnumber(L, (int) tcp->sock);\r\n    return 1;\r\n}\r\n\r\n/* this is very dangerous, but can be handy for those that are brave enough */\r\nstatic int meth_setfd(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    tcp->sock = (t_socket) luaL_checknumber(L, 2);\r\n    return 0;\r\n}\r\n\r\nstatic int meth_dirty(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    lua_pushboolean(L, !buffer_isempty(&tcp->buf));\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Waits for and returns a client object attempting connection to the\r\n* server object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_accept(lua_State *L)\r\n{\r\n    p_tcp server = (p_tcp) auxiliar_checkclass(L, \"tcp{server}\", 1);\r\n    p_timeout tm = timeout_markstart(&server->tm);\r\n    t_socket sock;\r\n    const char *err = inet_tryaccept(&server->sock, server->family, &sock, tm);\r\n    /* if successful, push client socket */\r\n    if (err == NULL) {\r\n        p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));\r\n        auxiliar_setclass(L, \"tcp{client}\", -1);\r\n        /* initialize structure fields */\r\n        memset(clnt, 0, sizeof(t_tcp));\r\n        socket_setnonblocking(&sock);\r\n        clnt->sock = sock;\r\n        io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv,\r\n                (p_error) socket_ioerror, &clnt->sock);\r\n        timeout_init(&clnt->tm, -1, -1);\r\n        buffer_init(&clnt->buf, &clnt->io, &clnt->tm);\r\n        clnt->family = server->family;\r\n        return 1;\r\n    } else {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Binds an object to an address\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_bind(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{master}\", 1);\r\n    const char *address =  luaL_checkstring(L, 2);\r\n    const char *port = luaL_checkstring(L, 3);\r\n    const char *err;\r\n    struct addrinfo bindhints;\r\n    memset(&bindhints, 0, sizeof(bindhints));\r\n    bindhints.ai_socktype = SOCK_STREAM;\r\n    bindhints.ai_family = tcp->family;\r\n    bindhints.ai_flags = AI_PASSIVE;\r\n    err = inet_trybind(&tcp->sock, address, port, &bindhints);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Turns a master tcp object into a client object.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_connect(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    const char *address =  luaL_checkstring(L, 2);\r\n    const char *port = luaL_checkstring(L, 3);\r\n    struct addrinfo connecthints;\r\n    const char *err;\r\n    memset(&connecthints, 0, sizeof(connecthints));\r\n    connecthints.ai_socktype = SOCK_STREAM;\r\n    /* make sure we try to connect only to the same family */\r\n    connecthints.ai_family = tcp->family;\r\n    timeout_markstart(&tcp->tm);\r\n    err = inet_tryconnect(&tcp->sock, &tcp->family, address, port, \r\n        &tcp->tm, &connecthints);\r\n    /* have to set the class even if it failed due to non-blocking connects */\r\n    auxiliar_setclass(L, \"tcp{client}\", 1);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Closes socket used by object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_close(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    socket_destroy(&tcp->sock);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns family as string\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfamily(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    if (tcp->family == PF_INET6) {\r\n        lua_pushliteral(L, \"inet6\");\r\n        return 1;\r\n    } else {\r\n        lua_pushliteral(L, \"inet4\");\r\n        return 1;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Puts the sockt in listen mode\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_listen(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{master}\", 1);\r\n    int backlog = (int) luaL_optnumber(L, 2, 32);\r\n    int err = socket_listen(&tcp->sock, backlog);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(err));\r\n        return 2;\r\n    }\r\n    /* turn master object into a server object */\r\n    auxiliar_setclass(L, \"tcp{server}\", 1);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Shuts the connection down partially\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_shutdown(lua_State *L)\r\n{\r\n    /* SHUT_RD,  SHUT_WR,  SHUT_RDWR  have  the value 0, 1, 2, so we can use method index directly */\r\n    static const char* methods[] = { \"receive\", \"send\", \"both\", NULL };\r\n    p_tcp tcp = (p_tcp) auxiliar_checkclass(L, \"tcp{client}\", 1);\r\n    int how = luaL_checkoption(L, 2, \"both\", methods);\r\n    socket_shutdown(&tcp->sock, how);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call inet methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getpeername(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    return inet_meth_getpeername(L, &tcp->sock, tcp->family);\r\n}\r\n\r\nstatic int meth_getsockname(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    return inet_meth_getsockname(L, &tcp->sock, tcp->family);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call tm methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_settimeout(lua_State *L)\r\n{\r\n    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, \"tcp{any}\", 1);\r\n    return timeout_meth_settimeout(L, &tcp->tm);\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Library functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates a master tcp object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int tcp_create(lua_State *L, int family) {\r\n    t_socket sock;\r\n    const char *err = inet_trycreate(&sock, family, SOCK_STREAM);\r\n    /* try to allocate a system socket */\r\n    if (!err) {\r\n        /* allocate tcp object */\r\n        p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));\r\n        memset(tcp, 0, sizeof(t_tcp));\r\n        /* set its type as master object */\r\n        auxiliar_setclass(L, \"tcp{master}\", -1);\r\n        /* initialize remaining structure fields */\r\n        socket_setnonblocking(&sock);\r\n        if (family == PF_INET6) {\r\n            int yes = 1;\r\n            setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,\r\n                (void *)&yes, sizeof(yes));\r\n        }\r\n        tcp->sock = sock;\r\n        io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,\r\n                (p_error) socket_ioerror, &tcp->sock);\r\n        timeout_init(&tcp->tm, -1, -1);\r\n        buffer_init(&tcp->buf, &tcp->io, &tcp->tm);\r\n        tcp->family = family;\r\n        return 1;\r\n    } else {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n}\r\n\r\nstatic int global_create(lua_State *L) {\r\n    return tcp_create(L, AF_INET);\r\n}\r\n\r\nstatic int global_create6(lua_State *L) {\r\n    return tcp_create(L, AF_INET6);\r\n}\r\n\r\n#if 0\r\nstatic const char *tryconnect6(const char *remoteaddr, const char *remoteserv,\r\n    struct addrinfo *connecthints, p_tcp tcp) {\r\n    struct addrinfo *iterator = NULL, *resolved = NULL;\r\n    const char *err = NULL;\r\n    /* try resolving */\r\n    err = socket_gaistrerror(getaddrinfo(remoteaddr, remoteserv,\r\n                connecthints, &resolved));\r\n    if (err != NULL) {\r\n        if (resolved) freeaddrinfo(resolved);\r\n        return err;\r\n    }\r\n    /* iterate over all returned addresses trying to connect */\r\n    for (iterator = resolved; iterator; iterator = iterator->ai_next) {\r\n        p_timeout tm = timeout_markstart(&tcp->tm);\r\n        /* create new socket if necessary. if there was no\r\n         * bind, we need to create one for every new family\r\n         * that shows up while iterating. if there was a\r\n         * bind, all families will be the same and we will\r\n         * not enter this branch. */\r\n        if (tcp->family != iterator->ai_family) {\r\n            socket_destroy(&tcp->sock);\r\n            err = socket_strerror(socket_create(&tcp->sock,\r\n                iterator->ai_family, iterator->ai_socktype,\r\n                iterator->ai_protocol));\r\n            if (err != NULL) {\r\n                freeaddrinfo(resolved);\r\n                return err;\r\n            }\r\n            tcp->family = iterator->ai_family;\r\n            /* all sockets initially non-blocking */\r\n            socket_setnonblocking(&tcp->sock);\r\n        }\r\n        /* finally try connecting to remote address */\r\n        err = socket_strerror(socket_connect(&tcp->sock,\r\n            (SA *) iterator->ai_addr,\r\n            (socklen_t) iterator->ai_addrlen, tm));\r\n        /* if success, break out of loop */\r\n        if (err == NULL) break;\r\n    }\r\n\r\n    freeaddrinfo(resolved);\r\n    /* here, if err is set, we failed */\r\n    return err;\r\n}\r\n#endif\r\n\r\nstatic int global_connect(lua_State *L) {\r\n    const char *remoteaddr = luaL_checkstring(L, 1);\r\n    const char *remoteserv = luaL_checkstring(L, 2);\r\n    const char *localaddr  = luaL_optstring(L, 3, NULL);\r\n    const char *localserv  = luaL_optstring(L, 4, \"0\");\r\n    int family = inet_optfamily(L, 5, \"unspec\");\r\n    p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));\r\n    struct addrinfo bindhints, connecthints;\r\n    const char *err = NULL;\r\n    /* initialize tcp structure */\r\n    memset(tcp, 0, sizeof(t_tcp));\r\n    io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,\r\n            (p_error) socket_ioerror, &tcp->sock);\r\n    timeout_init(&tcp->tm, -1, -1);\r\n    buffer_init(&tcp->buf, &tcp->io, &tcp->tm);\r\n    tcp->sock = SOCKET_INVALID;\r\n    tcp->family = PF_UNSPEC;\r\n    /* allow user to pick local address and port */\r\n    memset(&bindhints, 0, sizeof(bindhints));\r\n    bindhints.ai_socktype = SOCK_STREAM;\r\n    bindhints.ai_family = family;\r\n    bindhints.ai_flags = AI_PASSIVE;\r\n    if (localaddr) {\r\n        err = inet_trybind(&tcp->sock, localaddr, localserv, &bindhints);\r\n        if (err) {\r\n            lua_pushnil(L);\r\n            lua_pushstring(L, err);\r\n            return 2;\r\n        }\r\n        tcp->family = bindhints.ai_family;\r\n    }\r\n    /* try to connect to remote address and port */\r\n    memset(&connecthints, 0, sizeof(connecthints));\r\n    connecthints.ai_socktype = SOCK_STREAM;\r\n    /* make sure we try to connect only to the same family */\r\n    connecthints.ai_family = bindhints.ai_family;\r\n    err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv,\r\n         &tcp->tm, &connecthints);\r\n    if (err) {\r\n        socket_destroy(&tcp->sock);\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    auxiliar_setclass(L, \"tcp{client}\", -1);\r\n    return 1;\r\n}\r\n"
  },
  {
    "path": "build/luasocket/tcp.h",
    "content": "#ifndef TCP_H\r\n#define TCP_H\r\n/*=========================================================================*\\\r\n* TCP object\r\n* LuaSocket toolkit\r\n*\r\n* The tcp.h module is basicly a glue that puts together modules buffer.h,\r\n* timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET,\r\n* SOCK_STREAM) support.\r\n*\r\n* Three classes are defined: master, client and server. The master class is\r\n* a newly created tcp object, that has not been bound or connected. Server\r\n* objects are tcp objects bound to some local address. Client objects are\r\n* tcp objects either connected to some address or returned by the accept\r\n* method of a server object.\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n#include \"buffer.h\"\r\n#include \"timeout.h\"\r\n#include \"socket.h\"\r\n\r\ntypedef struct t_tcp_ {\r\n    t_socket sock;\r\n    t_io io;\r\n    t_buffer buf;\r\n    t_timeout tm;\r\n    int family;\r\n} t_tcp;\r\n\r\ntypedef t_tcp *p_tcp;\r\n\r\nint tcp_open(lua_State *L);\r\n\r\n#endif /* TCP_H */\r\n"
  },
  {
    "path": "build/luasocket/timeout.c",
    "content": "/*=========================================================================*\\\r\n* Timeout management functions\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <stdio.h>\r\n#include <limits.h>\r\n#include <float.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"timeout.h\"\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#else\r\n#include <time.h>\r\n#include <sys/time.h>\r\n#endif\r\n\r\n/* min and max macros */\r\n#ifndef MIN\r\n#define MIN(x, y) ((x) < (y) ? x : y)\r\n#endif\r\n#ifndef MAX\r\n#define MAX(x, y) ((x) > (y) ? x : y)\r\n#endif\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes\r\n\\*=========================================================================*/\r\nstatic int timeout_lua_gettime(lua_State *L);\r\nstatic int timeout_lua_sleep(lua_State *L);\r\n\r\nstatic luaL_Reg func[] = {\r\n    { \"gettime\", timeout_lua_gettime },\r\n    { \"sleep\", timeout_lua_sleep },\r\n    { NULL, NULL }\r\n};\r\n\r\n/*=========================================================================*\\\r\n* Exported functions.\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Initialize structure\r\n\\*-------------------------------------------------------------------------*/\r\nvoid timeout_init(p_timeout tm, double block, double total) {\r\n    tm->block = block;\r\n    tm->total = total;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Determines how much time we have left for the next system call,\r\n* if the previous call was successful \r\n* Input\r\n*   tm: timeout control structure\r\n* Returns\r\n*   the number of ms left or -1 if there is no time limit\r\n\\*-------------------------------------------------------------------------*/\r\ndouble timeout_get(p_timeout tm) {\r\n    if (tm->block < 0.0 && tm->total < 0.0) {\r\n        return -1;\r\n    } else if (tm->block < 0.0) {\r\n        double t = tm->total - timeout_gettime() + tm->start;\r\n        return MAX(t, 0.0);\r\n    } else if (tm->total < 0.0) {\r\n        return tm->block;\r\n    } else {\r\n        double t = tm->total - timeout_gettime() + tm->start;\r\n        return MIN(tm->block, MAX(t, 0.0));\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns time since start of operation\r\n* Input\r\n*   tm: timeout control structure\r\n* Returns\r\n*   start field of structure\r\n\\*-------------------------------------------------------------------------*/\r\ndouble timeout_getstart(p_timeout tm) {\r\n    return tm->start;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Determines how much time we have left for the next system call,\r\n* if the previous call was a failure\r\n* Input\r\n*   tm: timeout control structure\r\n* Returns\r\n*   the number of ms left or -1 if there is no time limit\r\n\\*-------------------------------------------------------------------------*/\r\ndouble timeout_getretry(p_timeout tm) {\r\n    if (tm->block < 0.0 && tm->total < 0.0) {\r\n        return -1;\r\n    } else if (tm->block < 0.0) {\r\n        double t = tm->total - timeout_gettime() + tm->start;\r\n        return MAX(t, 0.0);\r\n    } else if (tm->total < 0.0) {\r\n        double t = tm->block - timeout_gettime() + tm->start;\r\n        return MAX(t, 0.0);\r\n    } else {\r\n        double t = tm->total - timeout_gettime() + tm->start;\r\n        return MIN(tm->block, MAX(t, 0.0));\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Marks the operation start time in structure \r\n* Input\r\n*   tm: timeout control structure\r\n\\*-------------------------------------------------------------------------*/\r\np_timeout timeout_markstart(p_timeout tm) {\r\n    tm->start = timeout_gettime();\r\n    return tm;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Gets time in s, relative to January 1, 1970 (UTC) \r\n* Returns\r\n*   time in s.\r\n\\*-------------------------------------------------------------------------*/\r\n#ifdef _WIN32\r\ndouble timeout_gettime(void) {\r\n    FILETIME ft;\r\n    double t;\r\n    GetSystemTimeAsFileTime(&ft);\r\n    /* Windows file time (time since January 1, 1601 (UTC)) */\r\n    t  = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);\r\n    /* convert to Unix Epoch time (time since January 1, 1970 (UTC)) */\r\n    return (t - 11644473600.0);\r\n}\r\n#else\r\ndouble timeout_gettime(void) {\r\n    struct timeval v;\r\n    gettimeofday(&v, (struct timezone *) NULL);\r\n    /* Unix Epoch time (time since January 1, 1970 (UTC)) */\r\n    return v.tv_sec + v.tv_usec/1.0e6;\r\n}\r\n#endif\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint timeout_open(lua_State *L) {\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    return 0;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Sets timeout values for IO operations\r\n* Lua Input: base, time [, mode]\r\n*   time: time out value in seconds\r\n*   mode: \"b\" for block timeout, \"t\" for total timeout. (default: b)\r\n\\*-------------------------------------------------------------------------*/\r\nint timeout_meth_settimeout(lua_State *L, p_timeout tm) {\r\n    double t = luaL_optnumber(L, 2, -1);\r\n    const char *mode = luaL_optstring(L, 3, \"b\");\r\n    switch (*mode) {\r\n        case 'b':\r\n            tm->block = t; \r\n            break;\r\n        case 'r': case 't':\r\n            tm->total = t;\r\n            break;\r\n        default:\r\n            luaL_argcheck(L, 0, 3, \"invalid timeout mode\");\r\n            break;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Test support functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns the time the system has been up, in secconds.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int timeout_lua_gettime(lua_State *L)\r\n{\r\n    lua_pushnumber(L, timeout_gettime());\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Sleep for n seconds.\r\n\\*-------------------------------------------------------------------------*/\r\n#ifdef _WIN32\r\nint timeout_lua_sleep(lua_State *L)\r\n{\r\n    double n = luaL_checknumber(L, 1);\r\n    if (n < 0.0) n = 0.0;\r\n    if (n < DBL_MAX/1000.0) n *= 1000.0;\r\n    if (n > INT_MAX) n = INT_MAX;\r\n    Sleep((int)n);\r\n    return 0;\r\n}\r\n#else\r\nint timeout_lua_sleep(lua_State *L)\r\n{\r\n    double n = luaL_checknumber(L, 1);\r\n    struct timespec t, r;\r\n    if (n < 0.0) n = 0.0;\r\n    if (n > INT_MAX) n = INT_MAX;\r\n    t.tv_sec = (int) n;\r\n    n -= t.tv_sec;\r\n    t.tv_nsec = (int) (n * 1000000000);\r\n    if (t.tv_nsec >= 1000000000) t.tv_nsec = 999999999;\r\n    while (nanosleep(&t, &r) != 0) {\r\n        t.tv_sec = r.tv_sec;\r\n        t.tv_nsec = r.tv_nsec;\r\n    }\r\n    return 0;\r\n}\r\n#endif\r\n"
  },
  {
    "path": "build/luasocket/timeout.h",
    "content": "#ifndef TIMEOUT_H\r\n#define TIMEOUT_H\r\n/*=========================================================================*\\\r\n* Timeout management functions\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n/* timeout control structure */\r\ntypedef struct t_timeout_ {\r\n    double block;          /* maximum time for blocking calls */\r\n    double total;          /* total number of miliseconds for operation */\r\n    double start;          /* time of start of operation */\r\n} t_timeout;\r\ntypedef t_timeout *p_timeout;\r\n\r\nint timeout_open(lua_State *L);\r\nvoid timeout_init(p_timeout tm, double block, double total);\r\ndouble timeout_get(p_timeout tm);\r\ndouble timeout_getretry(p_timeout tm);\r\np_timeout timeout_markstart(p_timeout tm);\r\ndouble timeout_getstart(p_timeout tm);\r\ndouble timeout_gettime(void);\r\nint timeout_meth_settimeout(lua_State *L, p_timeout tm);\r\n\r\n#define timeout_iszero(tm)   ((tm)->block == 0.0)\r\n\r\n#endif /* TIMEOUT_H */\r\n"
  },
  {
    "path": "build/luasocket/udp.c",
    "content": "/*=========================================================================*\\\r\n* UDP object\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h>\r\n#include <stdlib.h>\r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"socket.h\"\r\n#include \"inet.h\"\r\n#include \"options.h\"\r\n#include \"udp.h\"\r\n\r\n/* min and max macros */\r\n#ifndef MIN\r\n#define MIN(x, y) ((x) < (y) ? x : y)\r\n#endif\r\n#ifndef MAX\r\n#define MAX(x, y) ((x) > (y) ? x : y)\r\n#endif\r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes\r\n\\*=========================================================================*/\r\nstatic int global_create(lua_State *L);\r\nstatic int global_create6(lua_State *L);\r\nstatic int meth_send(lua_State *L);\r\nstatic int meth_sendto(lua_State *L);\r\nstatic int meth_receive(lua_State *L);\r\nstatic int meth_receivefrom(lua_State *L);\r\nstatic int meth_getfamily(lua_State *L);\r\nstatic int meth_getsockname(lua_State *L);\r\nstatic int meth_getpeername(lua_State *L);\r\nstatic int meth_setsockname(lua_State *L);\r\nstatic int meth_setpeername(lua_State *L);\r\nstatic int meth_close(lua_State *L);\r\nstatic int meth_setoption(lua_State *L);\r\nstatic int meth_getoption(lua_State *L);\r\nstatic int meth_settimeout(lua_State *L);\r\nstatic int meth_getfd(lua_State *L);\r\nstatic int meth_setfd(lua_State *L);\r\nstatic int meth_dirty(lua_State *L);\r\n\r\n/* udp object methods */\r\nstatic luaL_Reg udp_methods[] = {\r\n    {\"__gc\",        meth_close},\r\n    {\"__tostring\",  auxiliar_tostring},\r\n    {\"close\",       meth_close},\r\n    {\"dirty\",       meth_dirty},\r\n    {\"getfamily\",   meth_getfamily},\r\n    {\"getfd\",       meth_getfd},\r\n    {\"getpeername\", meth_getpeername},\r\n    {\"getsockname\", meth_getsockname},\r\n    {\"receive\",     meth_receive},\r\n    {\"receivefrom\", meth_receivefrom},\r\n    {\"send\",        meth_send},\r\n    {\"sendto\",      meth_sendto},\r\n    {\"setfd\",       meth_setfd},\r\n    {\"setoption\",   meth_setoption},\r\n    {\"getoption\",   meth_getoption},\r\n    {\"setpeername\", meth_setpeername},\r\n    {\"setsockname\", meth_setsockname},\r\n    {\"settimeout\",  meth_settimeout},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* socket options for setoption */\r\nstatic t_opt optset[] = {\r\n    {\"dontroute\",            opt_set_dontroute},\r\n    {\"broadcast\",            opt_set_broadcast},\r\n    {\"reuseaddr\",            opt_set_reuseaddr},\r\n    {\"reuseport\",            opt_set_reuseport},\r\n    {\"ip-multicast-if\",      opt_set_ip_multicast_if},\r\n    {\"ip-multicast-ttl\",     opt_set_ip_multicast_ttl},\r\n    {\"ip-multicast-loop\",    opt_set_ip_multicast_loop},\r\n    {\"ip-add-membership\",    opt_set_ip_add_membership},\r\n    {\"ip-drop-membership\",   opt_set_ip_drop_membersip},\r\n    {\"ipv6-unicast-hops\",    opt_set_ip6_unicast_hops},\r\n    {\"ipv6-multicast-hops\",  opt_set_ip6_unicast_hops},\r\n    {\"ipv6-multicast-loop\",  opt_set_ip6_multicast_loop},\r\n    {\"ipv6-add-membership\",  opt_set_ip6_add_membership},\r\n    {\"ipv6-drop-membership\", opt_set_ip6_drop_membersip},\r\n    {\"ipv6-v6only\",          opt_set_ip6_v6only},\r\n    {NULL,                   NULL}\r\n};\r\n\r\n/* socket options for getoption */\r\nstatic t_opt optget[] = {\r\n    {\"ip-multicast-if\",      opt_get_ip_multicast_if},\r\n    {\"ip-multicast-loop\",    opt_get_ip_multicast_loop},\r\n    {\"error\",                opt_get_error},\r\n    {\"ipv6-unicast-hops\",    opt_get_ip6_unicast_hops},\r\n    {\"ipv6-multicast-hops\",  opt_get_ip6_unicast_hops},\r\n    {\"ipv6-multicast-loop\",  opt_get_ip6_multicast_loop},\r\n    {\"ipv6-v6only\",          opt_get_ip6_v6only},\r\n    {NULL,                   NULL}\r\n};\r\n\r\n/* functions in library namespace */\r\nstatic luaL_Reg func[] = {\r\n    {\"udp\", global_create},\r\n    {\"udp6\", global_create6},\r\n    {NULL, NULL}\r\n};\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint udp_open(lua_State *L)\r\n{\r\n    /* create classes */\r\n    auxiliar_newclass(L, \"udp{connected}\", udp_methods);\r\n    auxiliar_newclass(L, \"udp{unconnected}\", udp_methods);\r\n    /* create class groups */\r\n    auxiliar_add2group(L, \"udp{connected}\",   \"udp{any}\");\r\n    auxiliar_add2group(L, \"udp{unconnected}\", \"udp{any}\");\r\n    auxiliar_add2group(L, \"udp{connected}\",   \"select{able}\");\r\n    auxiliar_add2group(L, \"udp{unconnected}\", \"select{able}\");\r\n    /* define library functions */\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    luaL_setfuncs(L, func, 0);\r\n#else\r\n    luaL_openlib(L, NULL, func, 0);\r\n#endif\r\n    return 0;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Lua methods\r\n\\*=========================================================================*/\r\nconst char *udp_strerror(int err) {\r\n    /* a 'closed' error on an unconnected means the target address was not\r\n     * accepted by the transport layer */\r\n    if (err == IO_CLOSED) return \"refused\";\r\n    else return socket_strerror(err);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Send data through connected udp socket\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_send(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkclass(L, \"udp{connected}\", 1);\r\n    p_timeout tm = &udp->tm;\r\n    size_t count, sent = 0;\r\n    int err;\r\n    const char *data = luaL_checklstring(L, 2, &count);\r\n    timeout_markstart(tm);\r\n    err = socket_send(&udp->sock, data, count, &sent, tm);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, udp_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, (lua_Number) sent);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Send data through unconnected udp socket\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_sendto(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkclass(L, \"udp{unconnected}\", 1);\r\n    size_t count, sent = 0;\r\n    const char *data = luaL_checklstring(L, 2, &count);\r\n    const char *ip = luaL_checkstring(L, 3);\r\n    const char *port = luaL_checkstring(L, 4);\r\n    p_timeout tm = &udp->tm;\r\n    int err;\r\n    struct addrinfo aihint;\r\n    struct addrinfo *ai;\r\n    memset(&aihint, 0, sizeof(aihint));\r\n    aihint.ai_family = udp->family;\r\n    aihint.ai_socktype = SOCK_DGRAM;\r\n    aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;\r\n    err = getaddrinfo(ip, port, &aihint, &ai);\r\n\tif (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, gai_strerror(err));\r\n        return 2;\r\n    }\r\n    timeout_markstart(tm);\r\n    err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, \r\n        (socklen_t) ai->ai_addrlen, tm);\r\n    freeaddrinfo(ai);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, udp_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, (lua_Number) sent);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Receives data from a UDP socket\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_receive(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    char buffer[UDP_DATAGRAMSIZE];\r\n    size_t got, count = (size_t) luaL_optnumber(L, 2, sizeof(buffer));\r\n    int err;\r\n    p_timeout tm = &udp->tm;\r\n    count = MIN(count, sizeof(buffer));\r\n    timeout_markstart(tm);\r\n    err = socket_recv(&udp->sock, buffer, count, &got, tm);\r\n    /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */\r\n    if (err == IO_CLOSED)\r\n        err = IO_DONE;\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, udp_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushlstring(L, buffer, got);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Receives data and sender from a UDP socket\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_receivefrom(lua_State *L)\r\n{\r\n    p_udp udp = (p_udp) auxiliar_checkclass(L, \"udp{unconnected}\", 1);\r\n    char buffer[UDP_DATAGRAMSIZE];\r\n    size_t got, count = (size_t) luaL_optnumber(L, 2, sizeof(buffer));\r\n    int err;\r\n    p_timeout tm = &udp->tm;\r\n    struct sockaddr_storage addr;\r\n    socklen_t addr_len = sizeof(addr);\r\n    char addrstr[INET6_ADDRSTRLEN];\r\n    char portstr[6];\r\n    timeout_markstart(tm);\r\n    count = MIN(count, sizeof(buffer));\r\n    err = socket_recvfrom(&udp->sock, buffer, count, &got, (SA *) &addr, \r\n            &addr_len, tm);\r\n    /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */\r\n    if (err == IO_CLOSED)\r\n        err = IO_DONE;\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, udp_strerror(err));\r\n        return 2;\r\n    }\r\n    err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr, \r\n        INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV);\r\n\tif (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, gai_strerror(err));\r\n        return 2;\r\n    }\r\n    lua_pushlstring(L, buffer, got);\r\n    lua_pushstring(L, addrstr);\r\n    lua_pushinteger(L, (int) strtol(portstr, (char **) NULL, 10));\r\n    return 3;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Returns family as string\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfamily(lua_State *L)\r\n{\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    if (udp->family == PF_INET6) {\r\n        lua_pushliteral(L, \"inet6\");\r\n        return 1;\r\n    } else {\r\n        lua_pushliteral(L, \"inet4\");\r\n        return 1;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select support methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfd(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    lua_pushnumber(L, (int) udp->sock);\r\n    return 1;\r\n}\r\n\r\n/* this is very dangerous, but can be handy for those that are brave enough */\r\nstatic int meth_setfd(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    udp->sock = (t_socket) luaL_checknumber(L, 2);\r\n    return 0;\r\n}\r\n\r\nstatic int meth_dirty(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    (void) udp;\r\n    lua_pushboolean(L, 0);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call inet methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getpeername(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkclass(L, \"udp{connected}\", 1);\r\n    return inet_meth_getpeername(L, &udp->sock, udp->family);\r\n}\r\n\r\nstatic int meth_getsockname(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    return inet_meth_getsockname(L, &udp->sock, udp->family);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call option handler\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_setoption(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    return opt_meth_setoption(L, optset, &udp->sock);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call option handler\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getoption(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    return opt_meth_getoption(L, optget, &udp->sock);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call tm methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_settimeout(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    return timeout_meth_settimeout(L, &udp->tm);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Turns a master udp object into a client object.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_setpeername(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    p_timeout tm = &udp->tm;\r\n    const char *address = luaL_checkstring(L, 2);\r\n    int connecting = strcmp(address, \"*\");\r\n    const char *port = connecting? luaL_checkstring(L, 3): \"0\";\r\n    struct addrinfo connecthints;\r\n    const char *err;\r\n    memset(&connecthints, 0, sizeof(connecthints));\r\n    connecthints.ai_socktype = SOCK_DGRAM;\r\n    /* make sure we try to connect only to the same family */\r\n    connecthints.ai_family = udp->family;\r\n    if (connecting) {\r\n        err = inet_tryconnect(&udp->sock, &udp->family, address, \r\n            port, tm, &connecthints);\r\n        if (err) {\r\n            lua_pushnil(L);\r\n            lua_pushstring(L, err);\r\n            return 2;\r\n        }\r\n        auxiliar_setclass(L, \"udp{connected}\", 1);\r\n    } else {\r\n        /* we ignore possible errors because Mac OS X always\r\n         * returns EAFNOSUPPORT */\r\n        inet_trydisconnect(&udp->sock, udp->family, tm);\r\n        auxiliar_setclass(L, \"udp{unconnected}\", 1);\r\n    }\r\n    /* change class to connected or unconnected depending on address */\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Closes socket used by object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_close(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkgroup(L, \"udp{any}\", 1);\r\n    socket_destroy(&udp->sock);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Turns a master object into a server object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_setsockname(lua_State *L) {\r\n    p_udp udp = (p_udp) auxiliar_checkclass(L, \"udp{unconnected}\", 1);\r\n    const char *address =  luaL_checkstring(L, 2);\r\n    const char *port = luaL_checkstring(L, 3);\r\n    const char *err;\r\n    struct addrinfo bindhints;\r\n    memset(&bindhints, 0, sizeof(bindhints));\r\n    bindhints.ai_socktype = SOCK_DGRAM;\r\n    bindhints.ai_family = udp->family;\r\n    bindhints.ai_flags = AI_PASSIVE;\r\n    err = inet_trybind(&udp->sock, address, port, &bindhints);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Library functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates a master udp object\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int udp_create(lua_State *L, int family) {\r\n    t_socket sock;\r\n    const char *err = inet_trycreate(&sock, family, SOCK_DGRAM);\r\n    /* try to allocate a system socket */\r\n    if (!err) {\r\n        /* allocate udp object */\r\n        p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp));\r\n        auxiliar_setclass(L, \"udp{unconnected}\", -1);\r\n        /* initialize remaining structure fields */\r\n        socket_setnonblocking(&sock);\r\n        if (family == PF_INET6) {\r\n            int yes = 1;\r\n            setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,\r\n                (void *)&yes, sizeof(yes));\r\n        }\r\n        udp->sock = sock;\r\n        timeout_init(&udp->tm, -1, -1);\r\n        udp->family = family;\r\n        return 1;\r\n    } else {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n}\r\n\r\nstatic int global_create(lua_State *L) {\r\n    return udp_create(L, AF_INET);\r\n}\r\n\r\nstatic int global_create6(lua_State *L) {\r\n    return udp_create(L, AF_INET6);\r\n}\r\n"
  },
  {
    "path": "build/luasocket/udp.h",
    "content": "#ifndef UDP_H\r\n#define UDP_H\r\n/*=========================================================================*\\\r\n* UDP object\r\n* LuaSocket toolkit\r\n*\r\n* The udp.h module provides LuaSocket with support for UDP protocol\r\n* (AF_INET, SOCK_DGRAM).\r\n*\r\n* Two classes are defined: connected and unconnected. UDP objects are\r\n* originally unconnected. They can be \"connected\" to a given address \r\n* with a call to the setpeername function. The same function can be used to\r\n* break the connection.\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n#include \"timeout.h\"\r\n#include \"socket.h\"\r\n\r\n/* can't be larger than wsocket.c MAXCHUNK!!! */\r\n#define UDP_DATAGRAMSIZE 8192\r\n\r\ntypedef struct t_udp_ {\r\n    t_socket sock;\r\n    t_timeout tm;\r\n    int family;\r\n} t_udp;\r\ntypedef t_udp *p_udp;\r\n\r\nint udp_open(lua_State *L);\r\n\r\n#endif /* UDP_H */\r\n"
  },
  {
    "path": "build/luasocket/unix.c",
    "content": "/*=========================================================================*\\\r\n* Unix domain socket \r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n#include <string.h> \r\n\r\n#include \"lua.h\"\r\n#include \"lauxlib.h\"\r\n\r\n#include \"auxiliar.h\"\r\n#include \"socket.h\"\r\n#include \"options.h\"\r\n#include \"unix.h\"\r\n#include <sys/un.h> \r\n\r\n/*=========================================================================*\\\r\n* Internal function prototypes\r\n\\*=========================================================================*/\r\nstatic int global_create(lua_State *L);\r\nstatic int meth_connect(lua_State *L);\r\nstatic int meth_listen(lua_State *L);\r\nstatic int meth_bind(lua_State *L);\r\nstatic int meth_send(lua_State *L);\r\nstatic int meth_shutdown(lua_State *L);\r\nstatic int meth_receive(lua_State *L);\r\nstatic int meth_accept(lua_State *L);\r\nstatic int meth_close(lua_State *L);\r\nstatic int meth_setoption(lua_State *L);\r\nstatic int meth_settimeout(lua_State *L);\r\nstatic int meth_getfd(lua_State *L);\r\nstatic int meth_setfd(lua_State *L);\r\nstatic int meth_dirty(lua_State *L);\r\nstatic int meth_getstats(lua_State *L);\r\nstatic int meth_setstats(lua_State *L);\r\n\r\nstatic const char *unix_tryconnect(p_unix un, const char *path);\r\nstatic const char *unix_trybind(p_unix un, const char *path);\r\n\r\n/* unix object methods */\r\nstatic luaL_Reg unix_methods[] = {\r\n    {\"__gc\",        meth_close},\r\n    {\"__tostring\",  auxiliar_tostring},\r\n    {\"accept\",      meth_accept},\r\n    {\"bind\",        meth_bind},\r\n    {\"close\",       meth_close},\r\n    {\"connect\",     meth_connect},\r\n    {\"dirty\",       meth_dirty},\r\n    {\"getfd\",       meth_getfd},\r\n    {\"getstats\",    meth_getstats},\r\n    {\"setstats\",    meth_setstats},\r\n    {\"listen\",      meth_listen},\r\n    {\"receive\",     meth_receive},\r\n    {\"send\",        meth_send},\r\n    {\"setfd\",       meth_setfd},\r\n    {\"setoption\",   meth_setoption},\r\n    {\"setpeername\", meth_connect},\r\n    {\"setsockname\", meth_bind},\r\n    {\"settimeout\",  meth_settimeout},\r\n    {\"shutdown\",    meth_shutdown},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* socket option handlers */\r\nstatic t_opt optset[] = {\r\n    {\"keepalive\",   opt_set_keepalive},\r\n    {\"reuseaddr\",   opt_set_reuseaddr},\r\n    {\"linger\",      opt_set_linger},\r\n    {NULL,          NULL}\r\n};\r\n\r\n/* our socket creation function */\r\n/* this is an ad-hoc module that returns a single function \r\n * as such, do not include other functions in this array. */\r\nstatic luaL_Reg func[] = {\r\n    {\"unix\", global_create},\r\n    {NULL,          NULL}\r\n};\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module\r\n\\*-------------------------------------------------------------------------*/\r\nint luaopen_socket_unix(lua_State *L) {\r\n    /* create classes */\r\n    auxiliar_newclass(L, \"unix{master}\", unix_methods);\r\n    auxiliar_newclass(L, \"unix{client}\", unix_methods);\r\n    auxiliar_newclass(L, \"unix{server}\", unix_methods);\r\n    /* create class groups */\r\n    auxiliar_add2group(L, \"unix{master}\", \"unix{any}\");\r\n    auxiliar_add2group(L, \"unix{client}\", \"unix{any}\");\r\n    auxiliar_add2group(L, \"unix{server}\", \"unix{any}\");\r\n#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)\r\n    lua_pushcfunction(L, global_create);\r\n    (void) func;\r\n#else\r\n    /* set function into socket namespace */\r\n    luaL_openlib(L, \"socket\", func, 0);\r\n    lua_pushcfunction(L, global_create);\r\n#endif\r\n    /* return the function instead of the 'socket' table */\r\n    return 1;\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Lua methods\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call buffered IO methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_send(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{client}\", 1);\r\n    return buffer_meth_send(L, &un->buf);\r\n}\r\n\r\nstatic int meth_receive(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{client}\", 1);\r\n    return buffer_meth_receive(L, &un->buf);\r\n}\r\n\r\nstatic int meth_getstats(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{client}\", 1);\r\n    return buffer_meth_getstats(L, &un->buf);\r\n}\r\n\r\nstatic int meth_setstats(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{client}\", 1);\r\n    return buffer_meth_setstats(L, &un->buf);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call option handler\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_setoption(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    return opt_meth_setoption(L, optset, &un->sock);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select support methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_getfd(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    lua_pushnumber(L, (int) un->sock);\r\n    return 1;\r\n}\r\n\r\n/* this is very dangerous, but can be handy for those that are brave enough */\r\nstatic int meth_setfd(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    un->sock = (t_socket) luaL_checknumber(L, 2); \r\n    return 0;\r\n}\r\n\r\nstatic int meth_dirty(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    lua_pushboolean(L, !buffer_isempty(&un->buf));\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Waits for and returns a client object attempting connection to the \r\n* server object \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_accept(lua_State *L) {\r\n    p_unix server = (p_unix) auxiliar_checkclass(L, \"unix{server}\", 1);\r\n    p_timeout tm = timeout_markstart(&server->tm);\r\n    t_socket sock;\r\n    int err = socket_accept(&server->sock, &sock, NULL, NULL, tm);\r\n    /* if successful, push client socket */\r\n    if (err == IO_DONE) {\r\n        p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix));\r\n        auxiliar_setclass(L, \"unix{client}\", -1);\r\n        /* initialize structure fields */\r\n        socket_setnonblocking(&sock);\r\n        clnt->sock = sock;\r\n        io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, \r\n                (p_error) socket_ioerror, &clnt->sock);\r\n        timeout_init(&clnt->tm, -1, -1);\r\n        buffer_init(&clnt->buf, &clnt->io, &clnt->tm);\r\n        return 1;\r\n    } else {\r\n        lua_pushnil(L); \r\n        lua_pushstring(L, socket_strerror(err));\r\n        return 2;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Binds an object to an address \r\n\\*-------------------------------------------------------------------------*/\r\nstatic const char *unix_trybind(p_unix un, const char *path) {\r\n    struct sockaddr_un local;\r\n    size_t len = strlen(path);\r\n    int err;\r\n    if (len >= sizeof(local.sun_path)) return \"path too long\";\r\n    memset(&local, 0, sizeof(local));\r\n    strcpy(local.sun_path, path);\r\n    local.sun_family = AF_UNIX;\r\n#ifdef UNIX_HAS_SUN_LEN\r\n    local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) \r\n        + len + 1;\r\n    err = socket_bind(&un->sock, (SA *) &local, local.sun_len);\r\n\r\n#else \r\n    err = socket_bind(&un->sock, (SA *) &local, \r\n            sizeof(local.sun_family) + len);\r\n#endif\r\n    if (err != IO_DONE) socket_destroy(&un->sock);\r\n    return socket_strerror(err); \r\n}\r\n\r\nstatic int meth_bind(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{master}\", 1);\r\n    const char *path =  luaL_checkstring(L, 2);\r\n    const char *err = unix_trybind(un, path);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Turns a master unix object into a client object.\r\n\\*-------------------------------------------------------------------------*/\r\nstatic const char *unix_tryconnect(p_unix un, const char *path)\r\n{\r\n    struct sockaddr_un remote;\r\n    int err;\r\n    size_t len = strlen(path);\r\n    if (len >= sizeof(remote.sun_path)) return \"path too long\";\r\n    memset(&remote, 0, sizeof(remote));\r\n    strcpy(remote.sun_path, path);\r\n    remote.sun_family = AF_UNIX;\r\n    timeout_markstart(&un->tm);\r\n#ifdef UNIX_HAS_SUN_LEN\r\n    remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) \r\n        + len + 1;\r\n    err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm);\r\n#else\r\n    err = socket_connect(&un->sock, (SA *) &remote, \r\n            sizeof(remote.sun_family) + len, &un->tm);\r\n#endif\r\n    if (err != IO_DONE) socket_destroy(&un->sock);\r\n    return socket_strerror(err);\r\n}\r\n\r\nstatic int meth_connect(lua_State *L)\r\n{\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{master}\", 1);\r\n    const char *path =  luaL_checkstring(L, 2);\r\n    const char *err = unix_tryconnect(un, path);\r\n    if (err) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, err);\r\n        return 2;\r\n    }\r\n    /* turn master object into a client object */\r\n    auxiliar_setclass(L, \"unix{client}\", 1);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Closes socket used by object \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_close(lua_State *L)\r\n{\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    socket_destroy(&un->sock);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Puts the sockt in listen mode\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_listen(lua_State *L)\r\n{\r\n    p_unix un = (p_unix) auxiliar_checkclass(L, \"unix{master}\", 1);\r\n    int backlog = (int) luaL_optnumber(L, 2, 32);\r\n    int err = socket_listen(&un->sock, backlog);\r\n    if (err != IO_DONE) {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(err));\r\n        return 2;\r\n    }\r\n    /* turn master object into a server object */\r\n    auxiliar_setclass(L, \"unix{server}\", 1);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Shuts the connection down partially\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_shutdown(lua_State *L)\r\n{\r\n    /* SHUT_RD,  SHUT_WR,  SHUT_RDWR  have  the value 0, 1, 2, so we can use method index directly */\r\n    static const char* methods[] = { \"receive\", \"send\", \"both\", NULL };\r\n    p_unix tcp = (p_unix) auxiliar_checkclass(L, \"unix{client}\", 1);\r\n    int how = luaL_checkoption(L, 2, \"both\", methods);\r\n    socket_shutdown(&tcp->sock, how);\r\n    lua_pushnumber(L, 1);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Just call tm methods\r\n\\*-------------------------------------------------------------------------*/\r\nstatic int meth_settimeout(lua_State *L) {\r\n    p_unix un = (p_unix) auxiliar_checkgroup(L, \"unix{any}\", 1);\r\n    return timeout_meth_settimeout(L, &un->tm);\r\n}\r\n\r\n/*=========================================================================*\\\r\n* Library functions\r\n\\*=========================================================================*/\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates a master unix object \r\n\\*-------------------------------------------------------------------------*/\r\nstatic int global_create(lua_State *L) {\r\n    t_socket sock;\r\n    int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0);\r\n    /* try to allocate a system socket */\r\n    if (err == IO_DONE) { \r\n        /* allocate unix object */\r\n        p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix));\r\n        /* set its type as master object */\r\n        auxiliar_setclass(L, \"unix{master}\", -1);\r\n        /* initialize remaining structure fields */\r\n        socket_setnonblocking(&sock);\r\n        un->sock = sock;\r\n        io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, \r\n                (p_error) socket_ioerror, &un->sock);\r\n        timeout_init(&un->tm, -1, -1);\r\n        buffer_init(&un->buf, &un->io, &un->tm);\r\n        return 1;\r\n    } else {\r\n        lua_pushnil(L);\r\n        lua_pushstring(L, socket_strerror(err));\r\n        return 2;\r\n    }\r\n}\r\n"
  },
  {
    "path": "build/luasocket/unix.h",
    "content": "#ifndef UNIX_H\r\n#define UNIX_H\r\n/*=========================================================================*\\\r\n* Unix domain object\r\n* LuaSocket toolkit\r\n*\r\n* This module is just an example of how to extend LuaSocket with a new \r\n* domain.\r\n\\*=========================================================================*/\r\n#include \"lua.h\"\r\n\r\n#include \"buffer.h\"\r\n#include \"timeout.h\"\r\n#include \"socket.h\"\r\n\r\n#ifndef UNIX_API\r\n#define UNIX_API extern\r\n#endif\r\n\r\ntypedef struct t_unix_ {\r\n    t_socket sock;\r\n    t_io io;\r\n    t_buffer buf;\r\n    t_timeout tm;\r\n} t_unix;\r\ntypedef t_unix *p_unix;\r\n\r\nUNIX_API int luaopen_socket_unix(lua_State *L);\r\n\r\n#endif /* UNIX_H */\r\n"
  },
  {
    "path": "build/luasocket/usocket.c",
    "content": "/*=========================================================================*\\\r\n* Socket compatibilization module for Unix\r\n* LuaSocket toolkit\r\n*\r\n* The code is now interrupt-safe.\r\n* The penalty of calling select to avoid busy-wait is only paid when\r\n* the I/O call fail in the first place. \r\n\\*=========================================================================*/\r\n#include <string.h> \r\n#include <signal.h>\r\n\r\n#include \"socket.h\"\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Wait for readable/writable/connected socket with timeout\r\n\\*-------------------------------------------------------------------------*/\r\n#ifndef SOCKET_SELECT\r\n#include <sys/poll.h>\r\n\r\n#define WAITFD_R        POLLIN\r\n#define WAITFD_W        POLLOUT\r\n#define WAITFD_C        (POLLIN|POLLOUT)\r\nint socket_waitfd(p_socket ps, int sw, p_timeout tm) {\r\n    int ret;\r\n    struct pollfd pfd;\r\n    pfd.fd = *ps;\r\n    pfd.events = sw;\r\n    pfd.revents = 0;\r\n    if (timeout_iszero(tm)) return IO_TIMEOUT;  /* optimize timeout == 0 case */\r\n    do {\r\n        int t = (int)(timeout_getretry(tm)*1e3);\r\n        ret = poll(&pfd, 1, t >= 0? t: -1);\r\n    } while (ret == -1 && errno == EINTR);\r\n    if (ret == -1) return errno;\r\n    if (ret == 0) return IO_TIMEOUT;\r\n    if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED;\r\n    return IO_DONE;\r\n}\r\n#else\r\n\r\n#define WAITFD_R        1\r\n#define WAITFD_W        2\r\n#define WAITFD_C        (WAITFD_R|WAITFD_W)\r\n\r\nint socket_waitfd(p_socket ps, int sw, p_timeout tm) {\r\n    int ret;\r\n    fd_set rfds, wfds, *rp, *wp;\r\n    struct timeval tv, *tp;\r\n    double t;\r\n    if (*ps >= FD_SETSIZE) return EINVAL;\r\n    if (timeout_iszero(tm)) return IO_TIMEOUT;  /* optimize timeout == 0 case */\r\n    do {\r\n        /* must set bits within loop, because select may have modifed them */\r\n        rp = wp = NULL;\r\n        if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(*ps, &rfds); rp = &rfds; }\r\n        if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; }\r\n        t = timeout_getretry(tm);\r\n        tp = NULL;\r\n        if (t >= 0.0) {\r\n            tv.tv_sec = (int)t;\r\n            tv.tv_usec = (int)((t-tv.tv_sec)*1.0e6);\r\n            tp = &tv;\r\n        }\r\n        ret = select(*ps+1, rp, wp, NULL, tp);\r\n    } while (ret == -1 && errno == EINTR);\r\n    if (ret == -1) return errno;\r\n    if (ret == 0) return IO_TIMEOUT;\r\n    if (sw == WAITFD_C && FD_ISSET(*ps, &rfds)) return IO_CLOSED;\r\n    return IO_DONE;\r\n}\r\n#endif\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_open(void) {\r\n    /* instals a handler to ignore sigpipe or it will crash us */\r\n    signal(SIGPIPE, SIG_IGN);\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Close module \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_close(void) {\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Close and inutilize socket\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_destroy(p_socket ps) {\r\n    if (*ps != SOCKET_INVALID) {\r\n        socket_setblocking(ps);\r\n        close(*ps);\r\n        *ps = SOCKET_INVALID;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select with timeout control\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, \r\n        p_timeout tm) {\r\n    int ret;\r\n    do {\r\n        struct timeval tv;\r\n        double t = timeout_getretry(tm);\r\n        tv.tv_sec = (int) t;\r\n        tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6);\r\n        /* timeout = 0 means no wait */\r\n        ret = select(n, rfds, wfds, efds, t >= 0.0 ? &tv: NULL);\r\n    } while (ret < 0 && errno == EINTR);\r\n    return ret;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates and sets up a socket\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_create(p_socket ps, int domain, int type, int protocol) {\r\n    *ps = socket(domain, type, protocol);\r\n    if (*ps != SOCKET_INVALID) return IO_DONE; \r\n    else return errno; \r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Binds or returns error message\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_bind(p_socket ps, SA *addr, socklen_t len) {\r\n    int err = IO_DONE;\r\n    socket_setblocking(ps);\r\n    if (bind(*ps, addr, len) < 0) err = errno; \r\n    socket_setnonblocking(ps);\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_listen(p_socket ps, int backlog) {\r\n    int err = IO_DONE; \r\n    socket_setblocking(ps);\r\n    if (listen(*ps, backlog)) err = errno; \r\n    socket_setnonblocking(ps);\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* \r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_shutdown(p_socket ps, int how) {\r\n    socket_setblocking(ps);\r\n    shutdown(*ps, how);\r\n    socket_setnonblocking(ps);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Connects or returns error message\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {\r\n    int err;\r\n    /* avoid calling on closed sockets */\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    /* call connect until done or failed without being interrupted */\r\n    do if (connect(*ps, addr, len) == 0) return IO_DONE;\r\n    while ((err = errno) == EINTR);\r\n    /* if connection failed immediately, return error code */\r\n    if (err != EINPROGRESS && err != EAGAIN) return err; \r\n    /* zero timeout case optimization */\r\n    if (timeout_iszero(tm)) return IO_TIMEOUT;\r\n    /* wait until we have the result of the connection attempt or timeout */\r\n    err = socket_waitfd(ps, WAITFD_C, tm);\r\n    if (err == IO_CLOSED) {\r\n        if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE;\r\n        else return errno;\r\n    } else return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Accept with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_timeout tm) {\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED; \r\n    for ( ;; ) {\r\n        int err;\r\n        if ((*pa = accept(*ps, addr, len)) != SOCKET_INVALID) return IO_DONE;\r\n        err = errno;\r\n        if (err == EINTR) continue;\r\n        if (err != EAGAIN && err != ECONNABORTED) return err;\r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;\r\n    }\r\n    /* can't reach here */\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Send with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_send(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, p_timeout tm)\r\n{\r\n    int err;\r\n    *sent = 0;\r\n    /* avoid making system calls on closed sockets */\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    /* loop until we send something or we give up on error */\r\n    for ( ;; ) {\r\n        long put = (long) send(*ps, data, count, 0);\r\n        /* if we sent anything, we are done */\r\n        if (put >= 0) {\r\n            *sent = put;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        /* EPIPE means the connection was closed */\r\n        if (err == EPIPE) return IO_CLOSED;\r\n        /* we call was interrupted, just try again */\r\n        if (err == EINTR) continue;\r\n        /* if failed fatal reason, report error */\r\n        if (err != EAGAIN) return err;\r\n        /* wait until we can send something or we timeout */\r\n        if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;\r\n    }\r\n    /* can't reach here */\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Sendto with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, \r\n        SA *addr, socklen_t len, p_timeout tm)\r\n{\r\n    int err;\r\n    *sent = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        long put = (long) sendto(*ps, data, count, 0, addr, len);  \r\n        if (put >= 0) {\r\n            *sent = put;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        if (err == EPIPE) return IO_CLOSED;\r\n        if (err == EINTR) continue;\r\n        if (err != EAGAIN) return err;\r\n        if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;\r\n    }\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Receive with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {\r\n    int err;\r\n    *got = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        long taken = (long) recv(*ps, data, count, 0);\r\n        if (taken > 0) {\r\n            *got = taken;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        if (taken == 0) return IO_CLOSED;\r\n        if (err == EINTR) continue;\r\n        if (err != EAGAIN) return err; \r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; \r\n    }\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Recvfrom with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, \r\n        SA *addr, socklen_t *len, p_timeout tm) {\r\n    int err;\r\n    *got = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        long taken = (long) recvfrom(*ps, data, count, 0, addr, len);\r\n        if (taken > 0) {\r\n            *got = taken;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        if (taken == 0) return IO_CLOSED;\r\n        if (err == EINTR) continue;\r\n        if (err != EAGAIN) return err; \r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; \r\n    }\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Write with timeout\r\n*\r\n* socket_read and socket_write are cut-n-paste of socket_send and socket_recv,\r\n* with send/recv replaced with write/read. We can't just use write/read\r\n* in the socket version, because behaviour when size is zero is different.\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_write(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, p_timeout tm)\r\n{\r\n    int err;\r\n    *sent = 0;\r\n    /* avoid making system calls on closed sockets */\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    /* loop until we send something or we give up on error */\r\n    for ( ;; ) {\r\n        long put = (long) write(*ps, data, count);\r\n        /* if we sent anything, we are done */\r\n        if (put >= 0) {\r\n            *sent = put;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        /* EPIPE means the connection was closed */\r\n        if (err == EPIPE) return IO_CLOSED;\r\n        /* we call was interrupted, just try again */\r\n        if (err == EINTR) continue;\r\n        /* if failed fatal reason, report error */\r\n        if (err != EAGAIN) return err;\r\n        /* wait until we can send something or we timeout */\r\n        if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;\r\n    }\r\n    /* can't reach here */\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Read with timeout\r\n* See note for socket_write\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {\r\n    int err;\r\n    *got = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        long taken = (long) read(*ps, data, count);\r\n        if (taken > 0) {\r\n            *got = taken;\r\n            return IO_DONE;\r\n        }\r\n        err = errno;\r\n        if (taken == 0) return IO_CLOSED;\r\n        if (err == EINTR) continue;\r\n        if (err != EAGAIN) return err; \r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; \r\n    }\r\n    return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Put socket into blocking mode\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_setblocking(p_socket ps) {\r\n    int flags = fcntl(*ps, F_GETFL, 0);\r\n    flags &= (~(O_NONBLOCK));\r\n    fcntl(*ps, F_SETFL, flags);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Put socket into non-blocking mode\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_setnonblocking(p_socket ps) {\r\n    int flags = fcntl(*ps, F_GETFL, 0);\r\n    flags |= O_NONBLOCK;\r\n    fcntl(*ps, F_SETFL, flags);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* DNS helpers \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {\r\n    *hp = gethostbyaddr(addr, len, AF_INET);\r\n    if (*hp) return IO_DONE;\r\n    else if (h_errno) return h_errno;\r\n    else if (errno) return errno;\r\n    else return IO_UNKNOWN;\r\n}\r\n\r\nint socket_gethostbyname(const char *addr, struct hostent **hp) {\r\n    *hp = gethostbyname(addr);\r\n    if (*hp) return IO_DONE;\r\n    else if (h_errno) return h_errno;\r\n    else if (errno) return errno;\r\n    else return IO_UNKNOWN;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Error translation functions\r\n* Make sure important error messages are standard\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *socket_hoststrerror(int err) {\r\n    if (err <= 0) return io_strerror(err);\r\n    switch (err) {\r\n        case HOST_NOT_FOUND: return \"host not found\";\r\n        default: return hstrerror(err);\r\n    }\r\n}\r\n\r\nconst char *socket_strerror(int err) {\r\n    if (err <= 0) return io_strerror(err);\r\n    switch (err) {\r\n        case EADDRINUSE: return \"address already in use\";\r\n        case EISCONN: return \"already connected\";\r\n        case EACCES: return \"permission denied\";\r\n        case ECONNREFUSED: return \"connection refused\";\r\n        case ECONNABORTED: return \"closed\";\r\n        case ECONNRESET: return \"closed\";\r\n        case ETIMEDOUT: return \"timeout\";\r\n        default: return strerror(err);\r\n    }\r\n}\r\n\r\nconst char *socket_ioerror(p_socket ps, int err) {\r\n    (void) ps;\r\n    return socket_strerror(err);\r\n} \r\n\r\nconst char *socket_gaistrerror(int err) {\r\n    if (err == 0) return NULL; \r\n    switch (err) {\r\n        case EAI_AGAIN: return \"temporary failure in name resolution\";\r\n        case EAI_BADFLAGS: return \"invalid value for ai_flags\";\r\n#ifdef EAI_BADHINTS\r\n        case EAI_BADHINTS: return \"invalid value for hints\";\r\n#endif\r\n        case EAI_FAIL: return \"non-recoverable failure in name resolution\";\r\n        case EAI_FAMILY: return \"ai_family not supported\";\r\n        case EAI_MEMORY: return \"memory allocation failure\";\r\n        case EAI_NONAME: \r\n            return \"host or service not provided, or not known\";\r\n        case EAI_OVERFLOW: return \"argument buffer overflow\";\r\n#ifdef EAI_PROTOCOL\r\n        case EAI_PROTOCOL: return \"resolved protocol is unknown\";\r\n#endif\r\n        case EAI_SERVICE: return \"service not supported for socket type\";\r\n        case EAI_SOCKTYPE: return \"ai_socktype not supported\";\r\n        case EAI_SYSTEM: return strerror(errno); \r\n        default: return gai_strerror(err);\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "build/luasocket/usocket.h",
    "content": "#ifndef USOCKET_H\r\n#define USOCKET_H\r\n/*=========================================================================*\\\r\n* Socket compatibilization module for Unix\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n\r\n/*=========================================================================*\\\r\n* BSD include files\r\n\\*=========================================================================*/\r\n/* error codes */\r\n#include <errno.h>\r\n/* close function */\r\n#include <unistd.h>\r\n/* fnctnl function and associated constants */\r\n#include <fcntl.h>\r\n/* struct sockaddr */\r\n#include <sys/types.h>\r\n/* socket function */\r\n#include <sys/socket.h>\r\n/* struct timeval */\r\n#include <sys/time.h>\r\n/* gethostbyname and gethostbyaddr functions */\r\n#include <netdb.h>\r\n/* sigpipe handling */\r\n#include <signal.h>\r\n/* IP stuff*/\r\n#include <netinet/in.h>\r\n#include <arpa/inet.h>\r\n/* TCP options (nagle algorithm disable) */\r\n#include <netinet/tcp.h>\r\n#include <net/if.h>\r\n\r\n#ifndef SO_REUSEPORT\r\n#define SO_REUSEPORT SO_REUSEADDR\r\n#endif\r\n\r\n/* Some platforms use IPV6_JOIN_GROUP instead if\r\n * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */\r\n#ifndef IPV6_ADD_MEMBERSHIP\r\n#ifdef IPV6_JOIN_GROUP\r\n#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP\r\n#endif /* IPV6_JOIN_GROUP */\r\n#endif /* !IPV6_ADD_MEMBERSHIP */\r\n\r\n/* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */\r\n#ifndef IPV6_DROP_MEMBERSHIP\r\n#ifdef IPV6_LEAVE_GROUP\r\n#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP\r\n#endif /* IPV6_LEAVE_GROUP */\r\n#endif /* !IPV6_DROP_MEMBERSHIP */\r\n\r\ntypedef int t_socket;\r\ntypedef t_socket *p_socket;\r\ntypedef struct sockaddr_storage t_sockaddr_storage;\r\n\r\n#define SOCKET_INVALID (-1)\r\n\r\n#endif /* USOCKET_H */\r\n"
  },
  {
    "path": "build/luasocket/wsocket.c",
    "content": "#include <string.h>\r\n#include \"socket.h\"\r\n\r\nstatic const char *wstrerror(int err);\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Initializes module \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_open(void) {\r\n    WSADATA wsaData;\r\n    WORD wVersionRequested = MAKEWORD(2, 0); \r\n    int err = WSAStartup(wVersionRequested, &wsaData );\r\n    if (err != 0) return 0;\r\n    if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) &&\r\n        (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) {\r\n        WSACleanup();\r\n        return 0; \r\n    }\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Close module \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_close(void) {\r\n    WSACleanup();\r\n    return 1;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Wait for readable/writable/connected socket with timeout\r\n\\*-------------------------------------------------------------------------*/\r\n#define WAITFD_R        1\r\n#define WAITFD_W        2\r\n#define WAITFD_E        4\r\n#define WAITFD_C        (WAITFD_E|WAITFD_W)\r\n\r\nint socket_waitfd(p_socket ps, int sw, p_timeout tm) {\r\n    int ret;\r\n    fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL;\r\n    struct timeval tv, *tp = NULL;\r\n    double t;\r\n    if (timeout_iszero(tm)) return IO_TIMEOUT;  /* optimize timeout == 0 case */\r\n    if (sw & WAITFD_R) { \r\n        FD_ZERO(&rfds); \r\n        FD_SET(*ps, &rfds);\r\n        rp = &rfds; \r\n    }\r\n    if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; }\r\n    if (sw & WAITFD_C) { FD_ZERO(&efds); FD_SET(*ps, &efds); ep = &efds; }\r\n    if ((t = timeout_get(tm)) >= 0.0) {\r\n        tv.tv_sec = (int) t;\r\n        tv.tv_usec = (int) ((t-tv.tv_sec)*1.0e6);\r\n        tp = &tv;\r\n    }\r\n    ret = select(0, rp, wp, ep, tp);\r\n    if (ret == -1) return WSAGetLastError();\r\n    if (ret == 0) return IO_TIMEOUT;\r\n    if (sw == WAITFD_C && FD_ISSET(*ps, &efds)) return IO_CLOSED;\r\n    return IO_DONE;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Select with int timeout in ms\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, \r\n        p_timeout tm) {\r\n    struct timeval tv; \r\n    double t = timeout_get(tm);\r\n    tv.tv_sec = (int) t;\r\n    tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6);\r\n    if (n <= 0) {\r\n        Sleep((DWORD) (1000*t));\r\n        return 0;\r\n    } else return select(0, rfds, wfds, efds, t >= 0.0? &tv: NULL);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Close and inutilize socket\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_destroy(p_socket ps) {\r\n    if (*ps != SOCKET_INVALID) {\r\n        socket_setblocking(ps); /* close can take a long time on WIN32 */\r\n        closesocket(*ps);\r\n        *ps = SOCKET_INVALID;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* \r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_shutdown(p_socket ps, int how) {\r\n    socket_setblocking(ps);\r\n    shutdown(*ps, how);\r\n    socket_setnonblocking(ps);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Creates and sets up a socket\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_create(p_socket ps, int domain, int type, int protocol) {\r\n    *ps = socket(domain, type, protocol);\r\n    if (*ps != SOCKET_INVALID) return IO_DONE;\r\n    else return WSAGetLastError();\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Connects or returns error message\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {\r\n    int err;\r\n    /* don't call on closed socket */\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    /* ask system to connect */\r\n    if (connect(*ps, addr, len) == 0) return IO_DONE;\r\n    /* make sure the system is trying to connect */\r\n    err = WSAGetLastError();\r\n    if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err;\r\n    /* zero timeout case optimization */\r\n    if (timeout_iszero(tm)) return IO_TIMEOUT;\r\n    /* we wait until something happens */\r\n    err = socket_waitfd(ps, WAITFD_C, tm);\r\n    if (err == IO_CLOSED) {\r\n        int len = sizeof(err);\r\n        /* give windows time to set the error (yes, disgusting) */\r\n        Sleep(10);\r\n        /* find out why we failed */\r\n        getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); \r\n        /* we KNOW there was an error. if 'why' is 0, we will return\r\n        * \"unknown error\", but it's not really our fault */\r\n        return err > 0? err: IO_UNKNOWN; \r\n    } else return err;\r\n\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Binds or returns error message\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_bind(p_socket ps, SA *addr, socklen_t len) {\r\n    int err = IO_DONE;\r\n    socket_setblocking(ps);\r\n    if (bind(*ps, addr, len) < 0) err = WSAGetLastError();\r\n    socket_setnonblocking(ps);\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_listen(p_socket ps, int backlog) {\r\n    int err = IO_DONE;\r\n    socket_setblocking(ps);\r\n    if (listen(*ps, backlog) < 0) err = WSAGetLastError();\r\n    socket_setnonblocking(ps);\r\n    return err;\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Accept with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, \r\n        p_timeout tm) {\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        int err;\r\n        /* try to get client socket */\r\n        if ((*pa = accept(*ps, addr, len)) != SOCKET_INVALID) return IO_DONE;\r\n        /* find out why we failed */\r\n        err = WSAGetLastError(); \r\n        /* if we failed because there was no connectoin, keep trying */\r\n        if (err != WSAEWOULDBLOCK && err != WSAECONNABORTED) return err;\r\n        /* call select to avoid busy wait */\r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;\r\n    } \r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Send with timeout\r\n* On windows, if you try to send 10MB, the OS will buffer EVERYTHING \r\n* this can take an awful lot of time and we will end up blocked. \r\n* Therefore, whoever calls this function should not pass a huge buffer.\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_send(p_socket ps, const char *data, size_t count, \r\n        size_t *sent, p_timeout tm)\r\n{\r\n    int err;\r\n    *sent = 0;\r\n    /* avoid making system calls on closed sockets */\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    /* loop until we send something or we give up on error */\r\n    for ( ;; ) {\r\n        /* try to send something */\r\n        int put = send(*ps, data, (int) count, 0);\r\n        /* if we sent something, we are done */\r\n        if (put > 0) {\r\n            *sent = put;\r\n            return IO_DONE;\r\n        }\r\n        /* deal with failure */\r\n        err = WSAGetLastError(); \r\n        /* we can only proceed if there was no serious error */\r\n        if (err != WSAEWOULDBLOCK) return err;\r\n        /* avoid busy wait */\r\n        if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;\r\n    } \r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Sendto with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, \r\n        SA *addr, socklen_t len, p_timeout tm)\r\n{\r\n    int err;\r\n    *sent = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        int put = sendto(*ps, data, (int) count, 0, addr, len);\r\n        if (put > 0) {\r\n            *sent = put;\r\n            return IO_DONE;\r\n        }\r\n        err = WSAGetLastError(); \r\n        if (err != WSAEWOULDBLOCK) return err;\r\n        if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;\r\n    } \r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Receive with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_recv(p_socket ps, char *data, size_t count, size_t *got, \r\n        p_timeout tm) \r\n{\r\n    int err, prev = IO_DONE;\r\n    *got = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        int taken = recv(*ps, data, (int) count, 0);\r\n        if (taken > 0) {\r\n            *got = taken;\r\n            return IO_DONE;\r\n        }\r\n        if (taken == 0) return IO_CLOSED;\r\n        err = WSAGetLastError();\r\n        /* On UDP, a connreset simply means the previous send failed. \r\n         * So we try again. \r\n         * On TCP, it means our socket is now useless, so the error passes. \r\n         * (We will loop again, exiting because the same error will happen) */\r\n        if (err != WSAEWOULDBLOCK) {\r\n            if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;\r\n            prev = err;\r\n        }\r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Recvfrom with timeout\r\n\\*-------------------------------------------------------------------------*/\r\nint socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, \r\n        SA *addr, socklen_t *len, p_timeout tm) \r\n{\r\n    int err, prev = IO_DONE;\r\n    *got = 0;\r\n    if (*ps == SOCKET_INVALID) return IO_CLOSED;\r\n    for ( ;; ) {\r\n        int taken = recvfrom(*ps, data, (int) count, 0, addr, len);\r\n        if (taken > 0) {\r\n            *got = taken;\r\n            return IO_DONE;\r\n        }\r\n        if (taken == 0) return IO_CLOSED;\r\n        err = WSAGetLastError();\r\n        /* On UDP, a connreset simply means the previous send failed. \r\n         * So we try again. \r\n         * On TCP, it means our socket is now useless, so the error passes.\r\n         * (We will loop again, exiting because the same error will happen) */\r\n        if (err != WSAEWOULDBLOCK) {\r\n            if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;\r\n            prev = err;\r\n        }\r\n        if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;\r\n    }\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Put socket into blocking mode\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_setblocking(p_socket ps) {\r\n    u_long argp = 0;\r\n    ioctlsocket(*ps, FIONBIO, &argp);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Put socket into non-blocking mode\r\n\\*-------------------------------------------------------------------------*/\r\nvoid socket_setnonblocking(p_socket ps) {\r\n    u_long argp = 1;\r\n    ioctlsocket(*ps, FIONBIO, &argp);\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* DNS helpers \r\n\\*-------------------------------------------------------------------------*/\r\nint socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {\r\n    *hp = gethostbyaddr(addr, len, AF_INET);\r\n    if (*hp) return IO_DONE;\r\n    else return WSAGetLastError();\r\n}\r\n\r\nint socket_gethostbyname(const char *addr, struct hostent **hp) {\r\n    *hp = gethostbyname(addr);\r\n    if (*hp) return IO_DONE;\r\n    else return  WSAGetLastError();\r\n}\r\n\r\n/*-------------------------------------------------------------------------*\\\r\n* Error translation functions\r\n\\*-------------------------------------------------------------------------*/\r\nconst char *socket_hoststrerror(int err) {\r\n    if (err <= 0) return io_strerror(err);\r\n    switch (err) {\r\n        case WSAHOST_NOT_FOUND: return \"host not found\";\r\n        default: return wstrerror(err); \r\n    }\r\n}\r\n\r\nconst char *socket_strerror(int err) {\r\n    if (err <= 0) return io_strerror(err);\r\n    switch (err) {\r\n        case WSAEADDRINUSE: return \"address already in use\";\r\n        case WSAECONNREFUSED: return \"connection refused\";\r\n        case WSAEISCONN: return \"already connected\";\r\n        case WSAEACCES: return \"permission denied\";\r\n        case WSAECONNABORTED: return \"closed\";\r\n        case WSAECONNRESET: return \"closed\";\r\n        case WSAETIMEDOUT: return \"timeout\";\r\n        default: return wstrerror(err);\r\n    }\r\n}\r\n\r\nconst char *socket_ioerror(p_socket ps, int err) {\r\n    (void) ps;\r\n    return socket_strerror(err);\r\n}\r\n\r\nstatic const char *wstrerror(int err) {\r\n    switch (err) {\r\n        case WSAEINTR: return \"Interrupted function call\";\r\n        case WSAEACCES: return \"Permission denied\";\r\n        case WSAEFAULT: return \"Bad address\";\r\n        case WSAEINVAL: return \"Invalid argument\";\r\n        case WSAEMFILE: return \"Too many open files\";\r\n        case WSAEWOULDBLOCK: return \"Resource temporarily unavailable\";\r\n        case WSAEINPROGRESS: return \"Operation now in progress\";\r\n        case WSAEALREADY: return \"Operation already in progress\";\r\n        case WSAENOTSOCK: return \"Socket operation on nonsocket\";\r\n        case WSAEDESTADDRREQ: return \"Destination address required\";\r\n        case WSAEMSGSIZE: return \"Message too long\";\r\n        case WSAEPROTOTYPE: return \"Protocol wrong type for socket\";\r\n        case WSAENOPROTOOPT: return \"Bad protocol option\";\r\n        case WSAEPROTONOSUPPORT: return \"Protocol not supported\";\r\n        case WSAESOCKTNOSUPPORT: return \"Socket type not supported\";\r\n        case WSAEOPNOTSUPP: return \"Operation not supported\";\r\n        case WSAEPFNOSUPPORT: return \"Protocol family not supported\";\r\n        case WSAEAFNOSUPPORT: \r\n            return \"Address family not supported by protocol family\"; \r\n        case WSAEADDRINUSE: return \"Address already in use\";\r\n        case WSAEADDRNOTAVAIL: return \"Cannot assign requested address\";\r\n        case WSAENETDOWN: return \"Network is down\";\r\n        case WSAENETUNREACH: return \"Network is unreachable\";\r\n        case WSAENETRESET: return \"Network dropped connection on reset\";\r\n        case WSAECONNABORTED: return \"Software caused connection abort\";\r\n        case WSAECONNRESET: return \"Connection reset by peer\";\r\n        case WSAENOBUFS: return \"No buffer space available\";\r\n        case WSAEISCONN: return \"Socket is already connected\";\r\n        case WSAENOTCONN: return \"Socket is not connected\";\r\n        case WSAESHUTDOWN: return \"Cannot send after socket shutdown\";\r\n        case WSAETIMEDOUT: return \"Connection timed out\";\r\n        case WSAECONNREFUSED: return \"Connection refused\";\r\n        case WSAEHOSTDOWN: return \"Host is down\";\r\n        case WSAEHOSTUNREACH: return \"No route to host\";\r\n        case WSAEPROCLIM: return \"Too many processes\";\r\n        case WSASYSNOTREADY: return \"Network subsystem is unavailable\";\r\n        case WSAVERNOTSUPPORTED: return \"Winsock.dll version out of range\";\r\n        case WSANOTINITIALISED: \r\n            return \"Successful WSAStartup not yet performed\";\r\n        case WSAEDISCON: return \"Graceful shutdown in progress\";\r\n        case WSAHOST_NOT_FOUND: return \"Host not found\";\r\n        case WSATRY_AGAIN: return \"Nonauthoritative host not found\";\r\n        case WSANO_RECOVERY: return \"Nonrecoverable name lookup error\"; \r\n        case WSANO_DATA: return \"Valid name, no data record of requested type\";\r\n        default: return \"Unknown error\";\r\n    }\r\n}\r\n\r\nconst char *socket_gaistrerror(int err) {\r\n    if (err == 0) return NULL; \r\n    switch (err) {\r\n        case EAI_AGAIN: return \"temporary failure in name resolution\";\r\n        case EAI_BADFLAGS: return \"invalid value for ai_flags\";\r\n#ifdef EAI_BADHINTS\r\n        case EAI_BADHINTS: return \"invalid value for hints\";\r\n#endif\r\n        case EAI_FAIL: return \"non-recoverable failure in name resolution\";\r\n        case EAI_FAMILY: return \"ai_family not supported\";\r\n        case EAI_MEMORY: return \"memory allocation failure\";\r\n        case EAI_NONAME: \r\n            return \"host or service not provided, or not known\";\r\n#ifdef EAI_OVERFLOW\r\n        case EAI_OVERFLOW: return \"argument buffer overflow\";\r\n#endif\r\n#ifdef EAI_PROTOCOL\r\n        case EAI_PROTOCOL: return \"resolved protocol is unknown\";\r\n#endif\r\n        case EAI_SERVICE: return \"service not supported for socket type\";\r\n        case EAI_SOCKTYPE: return \"ai_socktype not supported\";\r\n#ifdef EAI_SYSTEM\r\n        case EAI_SYSTEM: return strerror(errno); \r\n#endif\r\n        default: return gai_strerror(err);\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "build/luasocket/wsocket.h",
    "content": "#ifndef WSOCKET_H\r\n#define WSOCKET_H\r\n/*=========================================================================*\\\r\n* Socket compatibilization module for Win32\r\n* LuaSocket toolkit\r\n\\*=========================================================================*/\r\n\r\n/*=========================================================================*\\\r\n* WinSock include files\r\n\\*=========================================================================*/\r\n#include <winsock2.h>\r\n#include <ws2tcpip.h>\r\n\r\ntypedef int socklen_t;\r\ntypedef SOCKADDR_STORAGE t_sockaddr_storage;\r\ntypedef SOCKET t_socket;\r\ntypedef t_socket *p_socket;\r\n\r\n#ifndef IPV6_V6ONLY\r\n#define IPV6_V6ONLY 27\r\n#endif\r\n\r\n#define SOCKET_INVALID (INVALID_SOCKET)\r\n\r\n#ifndef SO_REUSEPORT\r\n#define SO_REUSEPORT SO_REUSEADDR\r\n#endif\r\n\r\n#ifndef AI_NUMERICSERV\r\n#define AI_NUMERICSERV (0)\r\n#endif\r\n\r\n#endif /* WSOCKET_H */\r\n"
  },
  {
    "path": "build/make_android_lua53.sh",
    "content": "if [ -n \"$ANDROID_NDK\" ]; then\n    export NDK=${ANDROID_NDK}\nelif [ -n \"$ANDROID_NDK_HOME\" ]; then\n    export NDK=${ANDROID_NDK_HOME}\nelif [ -n \"$ANDROID_NDK_HOME\" ]; then\n    export NDK=${ANDROID_NDK_HOME}\nelse\n    export NDK=~/android-ndk-r15c\nfi\n\nif [ ! -d \"$NDK\" ]; then\n    echo \"Please set ANDROID_NDK environment to the root of NDK.\"\n    exit 1\nfi\n\nfunction build() {\n    API=$1\n    ABI=$2\n    TOOLCHAIN_ANME=$3\n    BUILD_PATH=build.Android.${ABI}\n    cmake -H. -B${BUILD_PATH} -DANDROID_ABI=${ABI} -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=${API} -DANDROID_TOOLCHAIN=clang -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_ANME}\n    cmake --build ${BUILD_PATH} --config Release\n    mkdir -p plugin_lua53/Plugins/Android/libs/${ABI}/\n    cp ${BUILD_PATH}/libxlua.so plugin_lua53/Plugins/Android/libs/${ABI}/libxlua.so\n}\n\nbuild android-16 armeabi-v7a arm-linux-androideabi-4.9\nbuild android-16 arm64-v8a  arm-linux-androideabi-clang\nbuild android-16 x86 x86-4.9\n"
  },
  {
    "path": "build/make_android_lua53_arm64.sh",
    "content": "source ./make_android_lua53.sh\n\nbuild android-16 arm64-v8a aarch64-linux-android-4.9\n"
  },
  {
    "path": "build/make_android_lua54.sh",
    "content": "if [ -n \"$ANDROID_NDK\" ]; then\n    export NDK=${ANDROID_NDK}\nelif [ -n \"$ANDROID_NDK_HOME\" ]; then\n    export NDK=${ANDROID_NDK_HOME}\nelif [ -n \"$ANDROID_NDK_HOME\" ]; then\n    export NDK=${ANDROID_NDK_HOME}\nelse\n    export NDK=~/android-ndk-r15c\nfi\n\nif [ ! -d \"$NDK\" ]; then\n    echo \"Please set ANDROID_NDK environment to the root of NDK.\"\n    exit 1\nfi\n\nfunction build() {\n    API=$1\n    ABI=$2\n    TOOLCHAIN_ANME=$3\n    BUILD_PATH=build54.Android.${ABI}\n    cmake -H. -B${BUILD_PATH} -DLUA_VERSION=5.4.1 -DANDROID_ABI=${ABI} -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=${API} -DANDROID_TOOLCHAIN=clang -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_ANME}\n    cmake --build ${BUILD_PATH} --config Release\n    mkdir -p plugin_lua54/Plugins/Android/libs/${ABI}/\n    cp ${BUILD_PATH}/libxlua.so plugin_lua54/Plugins/Android/libs/${ABI}/libxlua.so\n}\n\nbuild android-18 armeabi-v7a arm-linux-androideabi-4.9\nbuild android-18 arm64-v8a  arm-linux-androideabi-clang\nbuild android-18 x86 x86-4.9\n"
  },
  {
    "path": "build/make_android_luajit.sh",
    "content": "if [ -z \"$ANDROID_NDK\" ]; then\n    export ANDROID_NDK=~/android-ndk-r10e\nfi\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\nSRCDIR=$DIR/luajit-2.1.0b3\n# ANDROID_NDK=~/android-ndk-r10e\n\nOS=`uname -s`\nPREBUILT_PLATFORM=linux-x86_64\nif [[ \"$OS\" == \"Darwin\" ]]; then\n    PREBUILT_PLATFORM=darwin-x86_64\nfi\n\necho \"Building armv7 lib\"\nNDKVER=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8  \nNDKP=$NDKVER/prebuilt/$PREBUILT_PLATFORM/bin/arm-linux-androideabi-  \nNDKARCH=\"-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8\"  \nNDKABI=14 \nNDKF=\"--sysroot $ANDROID_NDK/platforms/android-$NDKABI/arch-arm\"\ncd \"$SRCDIR\"\nmake clean\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS=\"$NDKF $NDKARCH\"\n\ncd \"$DIR\"\nmkdir -p build_lj_v7a && cd build_lj_v7a\ncmake -DUSING_LUAJIT=ON -DANDROID_ABI=armeabi-v7a  -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.6 -DANDROID_NATIVE_API_LEVEL=android-9 ../\ncd \"$DIR\"\ncmake --build build_lj_v7a --config Release\nmkdir -p plugin_luajit/Plugins/Android/libs/armeabi-v7a/\ncp build_lj_v7a/libxlua.so plugin_luajit/Plugins/Android/libs/armeabi-v7a/libxlua.so\n\n\necho \"Building x86 lib\"\nNDKVER=$ANDROID_NDK/toolchains/x86-4.8  \nNDKP=$NDKVER/prebuilt/$PREBUILT_PLATFORM/bin/i686-linux-android-  \nNDKABI=14  \nNDKF=\"--sysroot $ANDROID_NDK/platforms/android-$NDKABI/arch-x86\"  \ncd \"$SRCDIR\"\nmake clean\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS=\"$NDKF\"\n\ncd \"$DIR\"\nmkdir -p build_lj_x86 && cd build_lj_x86\ncmake -DUSING_LUAJIT=ON -DANDROID_ABI=x86 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=x86-clang3.5 -DANDROID_NATIVE_API_LEVEL=android-9 ../\ncd \"$DIR\"\ncmake --build build_lj_x86 --config Release\nmkdir -p plugin_luajit/Plugins/Android/libs/x86/\ncp build_lj_x86/libxlua.so plugin_luajit/Plugins/Android/libs/x86/libxlua.so\n\n\n"
  },
  {
    "path": "build/make_android_luajit_arm64.sh",
    "content": "#if [ -z \"$ANDROID_NDK\" ]; then\n    export ANDROID_NDK=~/android-ndk-r15c\n#fi\n\nDIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\nSRCDIR=$DIR/luajit-2.1.0b3\n# ANDROID_NDK=~/android-ndk-r10e\n\nOS=`uname -s`\nPREBUILT_PLATFORM=linux-x86_64\nif [[ \"$OS\" == \"Darwin\" ]]; then\n    PREBUILT_PLATFORM=darwin-x86_64\nfi\n\nNDKABI=21\n\n\necho \"Building arm64-v8a lib\"\nNDKVER=$ANDROID_NDK/toolchains/aarch64-linux-android-4.9\nNDKP=$NDKVER/prebuilt/$PREBUILT_PLATFORM/bin/aarch64-linux-android-\nNDKARCH=\"-DLJ_ABI_SOFTFP=0 -DLJ_ARCH_HASFPU=1 -DLUAJIT_ENABLE_GC64=1\"  \nNDKF=\"--sysroot $ANDROID_NDK/platforms/android-$NDKABI/arch-arm64\"\ncd \"$SRCDIR\"\nmake clean\nmake HOST_CC=\"gcc -m64\" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS=\"$NDKF $NDKARCH\"\n\ncd \"$DIR\"\nmkdir -p build_lj_v8a && cd build_lj_v8a\ncmake -DUSING_LUAJIT=ON -DANDROID_ABI=arm64-v8a -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang -DANDROID_NATIVE_API_LEVEL=android-21 ../\ncd \"$DIR\"\ncmake --build build_lj_v8a --config Release\nmkdir -p plugin_luajit/Plugins/Android/libs/arm64-v8a/\ncp build_lj_v8a/libxlua.so plugin_luajit/Plugins/Android/libs/arm64-v8a/libxlua.so\n\n\necho \"Building armv7 lib\"\nNDKVER=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9\nNDKP=$NDKVER/prebuilt/$PREBUILT_PLATFORM/bin/arm-linux-androideabi-\nNDKARCH=\"-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8\"\nNDKF=\"--sysroot $ANDROID_NDK/platforms/android-$NDKABI/arch-arm\"\ncd \"$SRCDIR\"\nmake clean\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS=\"$NDKF $NDKARCH\"\n\ncd \"$DIR\"\nmkdir -p build_lj_v7a && cd build_lj_v7a\ncmake -DUSING_LUAJIT=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=../cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_NATIVE_API_LEVEL=android-21 ../\ncd \"$DIR\"\ncmake --build build_lj_v7a --config Release\nmkdir -p plugin_luajit/Plugins/Android/libs/armeabi-v7a/\ncp build_lj_v7a/libxlua.so plugin_luajit/Plugins/Android/libs/armeabi-v7a/libxlua.so\n\necho \"Building x86 lib\"\nNDKVER=$ANDROID_NDK/toolchains/x86-4.9\nNDKP=$NDKVER/prebuilt/$PREBUILT_PLATFORM/bin/i686-linux-android-\nNDKF=\"--sysroot $ANDROID_NDK/platforms/android-$NDKABI/arch-x86\"\ncd \"$SRCDIR\"\nmake clean\nmake HOST_CC=\"gcc -m32\" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS=\"$NDKF\"\n\ncd \"$DIR\"\nmkdir -p build_lj_x86 && cd build_lj_x86\ncmake -DUSING_LUAJIT=ON -DANDROID_ABI=x86 -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=x86-clang -DANDROID_NATIVE_API_LEVEL=android-21 ../\ncd \"$DIR\"\ncmake --build build_lj_x86 --config Release\nmkdir -p plugin_luajit/Plugins/Android/libs/x86/\ncp build_lj_x86/libxlua.so plugin_luajit/Plugins/Android/libs/x86/libxlua.so\n\n"
  },
  {
    "path": "build/make_ios_lua53.sh",
    "content": "mkdir -p build_ios && cd build_ios\ncmake -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64 -GXcode ../\ncd ..\ncmake --build build_ios --config Release\nmkdir -p plugin_lua53/Plugins/iOS/\ncp build_ios/Release-iphoneos/libxlua.a plugin_lua53/Plugins/iOS/libxlua.a \n\n"
  },
  {
    "path": "build/make_ios_lua54.sh",
    "content": "mkdir -p build_ios_54 && cd build_ios_54\ncmake -DLUA_VERSION=5.4.1 -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64 -GXcode ../\ncd ..\ncmake --build build_ios_54 --config Release\nmkdir -p plugin_lua54/Plugins/iOS/\ncp build_ios_54/Release-iphoneos/libxlua.a plugin_lua54/Plugins/iOS/libxlua.a \n\n"
  },
  {
    "path": "build/make_ios_luajit.sh",
    "content": "cd \"$( dirname \"${BASH_SOURCE[0]}\" )\"\nLIPO=\"xcrun -sdk iphoneos lipo\"\nSTRIP=\"xcrun -sdk iphoneos strip\"\n\nIXCODE=`xcode-select -print-path`\nISDK=$IXCODE/Platforms/iPhoneOS.platform/Developer\nISDKVER=iPhoneOS.sdk\nISDKP=$IXCODE/usr/bin/\n\nif [ ! -e $ISDKP/ar ]; then \n  sudo cp /usr/bin/ar $ISDKP\nfi\n\nif [ ! -e $ISDKP/ranlib ]; then\n  sudo cp /usr/bin/ranlib $ISDKP\nfi\n\nif [ ! -e $ISDKP/strip ]; then\n  sudo cp /usr/bin/strip $ISDKP\nfi\n\ncd luajit-2.1.0b3\n\nXCODEVER=`xcodebuild -version|head -n 1|sed 's/Xcode \\([0-9]*\\)/\\1/g'`\nISOLD_XCODEVER=`echo \"$XCODEVER < 10\" | bc`\nif [ ISOLD_XCODEVER == 1 ]\nthen\n    make clean\n    ISDKF=\"-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER -miphoneos-version-min=7.0\"\n    make HOST_CC=\"gcc -m32 -std=c99\" TARGET_FLAGS=\"$ISDKF\" TARGET=armv7 TARGET_SYS=iOS LUAJIT_A=libxluav7.a\n    \n    \n    make clean\n    ISDKF=\"-arch armv7s -isysroot $ISDK/SDKs/$ISDKVER -miphoneos-version-min=7.0\"\n    make HOST_CC=\"gcc -m32 -std=c99\" TARGET_FLAGS=\"$ISDKF\" TARGET=armv7s TARGET_SYS=iOS LUAJIT_A=libxluav7s.a\nfi\n\nmake clean\nISDKF=\"-arch arm64 -isysroot $ISDK/SDKs/$ISDKVER -miphoneos-version-min=7.0\"\nmake HOST_CC=\"gcc -std=c99\" TARGET_FLAGS=\"$ISDKF\" TARGET=arm64 TARGET_SYS=iOS LUAJIT_A=libxlua64.a\n\ncd src\nif [ ISOLD_XCODEVER == 1 ]\nthen\n    lipo libxluav7.a -create libxluav7s.a libxlua64.a -output libluajit.a\nelse\n    mv libxlua64.a libluajit.a\nfi\ncd ../..\n\nmkdir -p build_lj_ios && cd build_lj_ios\ncmake -DUSING_LUAJIT=ON  -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64  -GXcode ../\ncd ..\ncmake --build build_lj_ios --config Release\n\nmkdir -p plugin_luajit/Plugins/iOS/\nlibtool -static -o plugin_luajit/Plugins/iOS/libxlua.a build_lj_ios/Release-iphoneos/libxlua.a luajit-2.1.0b3/src/libluajit.a\n"
  },
  {
    "path": "build/make_linux32_lua53.sh",
    "content": "mkdir -p build_linux32 && cd build_linux32\ncmake -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_SHARED_LINKER_FLAGS=-m32 ../\ncd ..\ncmake --build build_linux32 --config Release\n\n"
  },
  {
    "path": "build/make_linux32_luajit.sh",
    "content": "cd luajit-2.1.0b3\nmake clean\nmake CC=\"gcc -m32\"\ncd ..\nmkdir -p build_linux32_lj && cd build_linux32_lj\ncmake -DUSING_LUAJIT=ON -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_SHARED_LINKER_FLAGS=-m32 ../\ncd ..\ncmake --build build_linux32_lj --config Release\n\n"
  },
  {
    "path": "build/make_linux64_lua53.sh",
    "content": "mkdir -p build_linux64 && cd build_linux64\ncmake ../\ncd ..\ncmake --build build_linux64 --config Release\nmkdir -p plugin_lua53/Plugins/x86_64/\ncp build_linux64/libxlua.so plugin_lua53/Plugins/x86_64/libxlua.so \n"
  },
  {
    "path": "build/make_linux64_luajit.sh",
    "content": "cd luajit-2.1.0b3\nmake clean\nmake CFLAGS=-fPIC\ncd ..\nmkdir -p build_linux64_lj && cd build_linux64_lj\ncmake -DUSING_LUAJIT=ON ../\ncd ..\ncmake --build build_linux64_lj --config Release\nmkdir -p plugin_luajit/Plugins/x86_64/\ncp build_linux64_lj/libxlua.so plugin_luajit/Plugins/x86_64/libxlua.so \n\n"
  },
  {
    "path": "build/make_linux_lua54.sh",
    "content": "mkdir -p build_linux64_54 && cd build_linux64_54\ncmake -DLUA_VERSION=5.4.1 ../\ncd ..\ncmake --build build_linux64_54 --config Release\nmkdir -p plugin_lua54/Plugins/x86_64/\ncp build_linux64_54/libxlua.so plugin_lua54/Plugins/x86_64/libxlua.so \n"
  },
  {
    "path": "build/make_nx64_lua53.bat",
    "content": "set CUR_DIR=%~dp0\r\ncd %CUR_DIR%\r\n\r\ndel /s/q buildnx64\r\nmkdir buildnx64 & pushd buildnx64\r\nrem fix for io_tmpfile & os_tmpname\r\necho #if !__ASSEMBLER__ > switch_fix.h\r\necho static inline struct _IO_FILE* tmpfile(){ return 0; } >> switch_fix.h\r\necho static inline char* tmpnam(char* n){ return 0; } >> switch_fix.h\r\necho #endif >> switch_fix.h\r\n\r\nset \"NINTENDO_SDK_ROOT_CMAKE=%NINTENDO_SDK_ROOT:\\=/%\"\r\ncmake -DCMAKE_C_COMPILER=\"%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang.exe\" ^\r\n\t-DCMAKE_CXX_COMPILER=\"%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang++.exe\" ^\r\n\t-G \"Unix Makefiles\" -DCMAKE_SYSTEM_NAME=Switch ^\r\n\t-DCMAKE_C_FLAGS=\"-includeswitch_fix.h -I%CUR_DIR%buildnx64\" ^\r\n\t..\r\npopd\r\ncmake --build buildnx64 --config Release\r\nmkdir plugin_lua53\\Plugins\\Switch\r\ncopy /Y buildnx64\\libxlua.a plugin_lua53\\Plugins\\Switch\\libxlua.a\r\n\r\nrem may need to set package.cpath = \"\" in lua\r\nrem as any read attempt to undefined location will crash\r\n"
  },
  {
    "path": "build/make_nx64_luajit_gc64.bat",
    "content": "set CUR_DIR=%~dp0\r\ncd %CUR_DIR%\r\n\r\ndel /s/q buildnx64\r\nmkdir buildnx64 & pushd buildnx64\r\nrem fix for io_tmpfile & os_tmpname\r\necho #if !__ASSEMBLER__ > switch_fix.h\r\necho static inline struct _IO_FILE* tmpfile(){ return 0; } >> switch_fix.h\r\necho static inline char* tmpnam(char* n){ return 0; } >> switch_fix.h\r\necho #endif >> switch_fix.h\r\npopd\r\n\r\npushd luajit-2.1.0b3\r\nrem use cygwin64 to compile because msvc treat zero-length array as error\r\nrem define LUAJIT_USE_SYSMALLOC as no mmap for switch\r\nfor /F \"tokens=* USEBACKQ\" %%F IN (`cygpath %NINTENDO_SDK_ROOT%`) DO set NINTENDO_SDK_ROOT_CYG=%%F\r\nset COMPILER=\"%NINTENDO_SDK_ROOT_CYG%/Compilers/NX/bin/nx-clang.exe\"\r\nset \"SWITCH_CFLAGS=-m64 -mcpu=cortex-a57+fp+simd+crypto+crc -fno-common -fno-short-enums -ffunction-sections -fdata-sections -fPIC -fms-extensions\"\r\nset \"LUAJIT_CFLAGS=-DLJ_TARGET_CONSOLE -DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_JIT -DLUAJIT_ENABLE_GC64 -DLUAJIT_DISABLE_FFI\"\r\nset \"FIX_FLAGS=-includeswitch_fix.h -I%CUR_DIR%buildnx64\"\r\nbash -c \"make clean\"\r\nbash -c \"make -C src TARGET_CC=\\\"%COMPILER% %SWITCH_CFLAGS% %FIX_FLAGS%\\\" TARGET_LD=%COMPILER% BUILDMODE=static TARGET_SYS=switch CFLAGS=\\\"%LUAJIT_CFLAGS%\\\" libluajit.a\"\r\npopd\r\n\r\npushd buildnx64\r\nset \"NINTENDO_SDK_ROOT_CMAKE=%NINTENDO_SDK_ROOT:\\=/%\"\r\ncmake -DCMAKE_C_COMPILER=\"%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang.exe\" ^\r\n\t-DCMAKE_CXX_COMPILER=\"%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang++.exe\" ^\r\n\t-G \"Unix Makefiles\" -DCMAKE_SYSTEM_NAME=Switch ^\r\n\t-DUSING_LUAJIT=ON ^\r\n\t..\r\npopd\r\ncmake --build buildnx64 --config Release\r\nmkdir plugin_luajit\\Plugins\\Switch\r\ncopy /Y buildnx64\\libxlua.a plugin_luajit\\Plugins\\Switch\\libxlua.a\r\ncopy /Y luajit-2.1.0b3\\src\\libluajit.a plugin_luajit\\Plugins\\Switch\\libluajit.a\r\n\r\nrem may need to set package.cpath = \"\" in lua\r\nrem as any read attempt to undefined location will crash\r\n"
  },
  {
    "path": "build/make_ohos_lua53.sh",
    "content": "#!/bin/bash\n\nif [ -n \"$OHOS_NDK\" ]; then\n    export NDK=${OHOS_NDK}\nelif [ -n \"$OHOS_NDK_HOME\" ]; then\n    export NDK=${OHOS_NDK_HOME}\nelse\n    export NDK=~/ohos-sdk/linux/native\nfi\n\nexport PATH=${NDK}/build-tools/cmake/bin:$PATH\n\nfunction build() {\n    ABI=$1\n    BUILD_PATH=build.OHOS.${ABI}\n    cmake -H. -DOHOS_STL=c++_shared -B${BUILD_PATH} -DOHOS_ARCH=${ABI} -DOHOS_PLATFORM=OHOS -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/ohos.toolchain.cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON\n    cmake --build ${BUILD_PATH} --config Release\n    mkdir -p plugin_lua53/Plugins/OpenHarmony/libs/${ABI}/\n    cp ${BUILD_PATH}/libxlua.so plugin_lua53/Plugins/OpenHarmony/libs/${ABI}/libxlua.so\n}\n\nbuild armeabi-v7a\nbuild arm64-v8a\n"
  },
  {
    "path": "build/make_ohos_lua54.sh",
    "content": "#!/bin/bash\n\nif [ -n \"$OHOS_NDK\" ]; then\n    export NDK=${OHOS_NDK}\nelif [ -n \"$OHOS_NDK_HOME\" ]; then\n    export NDK=${OHOS_NDK_HOME}\nelse\n    export NDK=~/ohos-sdk/linux/native\nfi\n\nexport PATH=${NDK}/build-tools/cmake/bin:$PATH\n\nfunction build() {\n    ABI=$1\n    BUILD_PATH=build54.OHOS.${ABI}\n    cmake -H. -DLUA_VERSION=5.4.1 -DOHOS_STL=c++_shared -B${BUILD_PATH} -DOHOS_ARCH=${ABI} -DOHOS_PLATFORM=OHOS -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/ohos.toolchain.cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON\n    cmake --build ${BUILD_PATH} --config Release\n    mkdir -p plugin_lua54/Plugins/OpenHarmony/libs/${ABI}/\n    cp ${BUILD_PATH}/libxlua.so plugin_lua54/Plugins/OpenHarmony/libs/${ABI}/libxlua.so\n}\n\nbuild armeabi-v7a\nbuild arm64-v8a\n"
  },
  {
    "path": "build/make_osx_lua53.sh",
    "content": "mkdir -p build_osx && cd build_osx\ncmake -GXcode ../\ncd ..\ncmake --build build_osx --config Release\nmkdir -p plugin_lua53/Plugins/xlua.bundle/Contents/MacOS/\ncp build_osx/Release/xlua.bundle/Contents/MacOS/xlua plugin_lua53/Plugins/xlua.bundle/Contents/MacOS/xlua\n\n"
  },
  {
    "path": "build/make_osx_lua54.sh",
    "content": "mkdir -p build_osx_54 && cd build_osx_54\ncmake -DLUA_VERSION=5.4.1 -GXcode ../\ncd ..\ncmake --build build_osx_54 --config Release\nmkdir -p plugin_lua54/Plugins/xlua.bundle/Contents/MacOS/\ncp build_osx_54/Release/xlua.bundle/Contents/MacOS/xlua plugin_lua54/Plugins/xlua.bundle/Contents/MacOS/xlua\n\n"
  },
  {
    "path": "build/make_osx_luajit.sh",
    "content": "mkdir -p build_lj_osx && cd build_lj_osx\ncmake -DUSING_LUAJIT=ON  -GXcode ../\ncd ..\ncmake --build build_lj_osx --config Release\nmkdir -p plugin_luajit/Plugins/xlua.bundle/Contents/MacOS/\ncp build_lj_osx/Release/xlua.bundle/Contents/MacOS/xlua plugin_luajit/Plugins/xlua.bundle/Contents/MacOS/xlua\n\n"
  },
  {
    "path": "build/make_osx_silicon_lua53.sh",
    "content": "mkdir -p build_osx_silicon && cd build_osx_silicon\ncmake -DBUILD_SILICON=ON -GXcode ../\ncd ..\ncmake --build build_osx_silicon --config Release\nmkdir -p plugin_lua53/Plugins/arm64/\ncp build_osx_silicon/Release/libxlua.dylib plugin_lua53/Plugins/arm64/\n\n"
  },
  {
    "path": "build/make_osx_silicon_lua54.sh",
    "content": "mkdir -p build_osx_54_silicon && cd build_osx_54_silicon\ncmake -DBUILD_SILICON=ON -DLUA_VERSION=5.4.1 -GXcode ../\ncd ..\ncmake --build build_osx_54_silicon --config Release\nmkdir -p plugin_lua54/Plugins/arm64\ncp build_osx_54_silicon/Release/libxlua.dylib plugin_lua54/Plugins/arm64/\n\n"
  },
  {
    "path": "build/make_osx_silicon_luajit.sh",
    "content": "mkdir -p build_lj_osx && cd build_lj_osx\ncmake -DBUILD_SILICON=ON -DUSING_LUAJIT=ON  -GXcode ../\ncd ..\ncmake --build build_lj_osx --config Release\nmkdir -p plugin_luajit/Plugins/xlua.bundle/Contents/MacOS/\ncp build_lj_osx/Release/xlua.bundle/Contents/MacOS/xlua plugin_luajit/Plugins/xlua.bundle/Contents/MacOS/xlua\n\n"
  },
  {
    "path": "build/make_uwp.bat",
    "content": "mkdir build_uwp & pushd build_uwp\ncmake -G \"Visual Studio 16 2019\" -A Win32 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp --config Release\nmd plugin_lua53\\Plugins\\WSA\\x86\ncopy /Y build_uwp\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\x86\\xlua.dll\n\nmkdir build_uwp64 & pushd build_uwp64\ncmake -G \"Visual Studio 16 2019\" -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp64 --config Release\nmd plugin_lua53\\Plugins\\WSA\\x64\ncopy /Y build_uwp64\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\x64\\xlua.dll\n\nmkdir build_uwp_arm & pushd build_uwp_arm\ncmake -G \"Visual Studio 16 2019\" -A ARM -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_arm --config Release\nmd plugin_lua53\\Plugins\\WSA\\ARM\ncopy /Y build_uwp_arm\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\ARM\\xlua.dll\n\nmkdir build_uwp_arm64 & pushd build_uwp_arm64\ncmake -G \"Visual Studio 16 2019\" -A ARM64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_arm64 --config Release\nmd plugin_lua53\\Plugins\\WSA\\ARM64\ncopy /Y build_uwp_arm64\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\ARM64\\xlua.dll\n\npause\n"
  },
  {
    "path": "build/make_uwp_lua54.bat",
    "content": "mkdir build_uwp_54 & pushd build_uwp_54\ncmake -DLUA_VERSION=5.4.1 -G \"Visual Studio 16 2019\" -A Win32 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_54 --config Release\nmd plugin_lua54\\Plugins\\WSA\\x86\ncopy /Y build_uwp_54\\Release\\xlua.dll plugin_lua54\\Plugins\\WSA\\x86\\xlua.dll\n\nmkdir build_uwp64_54 & pushd build_uwp64_54\ncmake -DLUA_VERSION=5.4.1 -G \"Visual Studio 16 2019\" -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp64_54 --config Release\nmd plugin_lua54\\Plugins\\WSA\\x64\ncopy /Y build_uwp64_54\\Release\\xlua.dll plugin_lua54\\Plugins\\WSA\\x64\\xlua.dll\n\nmkdir build_uwp_arm_54 & pushd build_uwp_arm_54\ncmake -DLUA_VERSION=5.4.1 -G \"Visual Studio 16 2019\" -A ARM -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_arm_54 --config Release\nmd plugin_lua54\\Plugins\\WSA\\ARM\ncopy /Y build_uwp_arm_54\\Release\\xlua.dll plugin_lua54\\Plugins\\WSA\\ARM\\xlua.dll\n\nmkdir build_uwp_arm64_54 & pushd build_uwp_arm64_54\ncmake -DLUA_VERSION=5.4.1 -G \"Visual Studio 16 2019\" -A ARM64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_arm64_54 --config Release\nmd plugin_lua54\\Plugins\\WSA\\ARM64\ncopy /Y build_uwp_arm64_54\\Release\\xlua.dll plugin_lua54\\Plugins\\WSA\\ARM64\\xlua.dll\n\npause\n"
  },
  {
    "path": "build/make_win32_lua53.bat",
    "content": "\r\nset \"__VS=Visual Studio 16 2019\"\r\nset \"__VSWhere=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\r\nset \"__VSDISPLAY=\"\r\nset \"__VSVER=\"\r\nif exist \"%__VSWhere%\" (\r\n    for /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productLineVersion'\r\n\t) do set __VSDISPLAY=%%p\r\n\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productDisplayVersion'\r\n\t) do set __VSVER=%%p\r\n\t\r\n)\r\nif \"%__VSVER%\" neq \"\" (\t\r\n\tset __VS=Visual Studio %__VSVER:~0,2% %__VSDisplay%\r\n)\r\n\r\nmkdir build32 & pushd build32\r\ncmake -G \"%__VS%\" -A Win32 ..\r\npopd\r\ncmake --build build32 --config Release\r\nmd plugin_lua53\\Plugins\\x86\r\ncopy /Y build32\\Release\\xlua.dll plugin_lua53\\Plugins\\x86\\xlua.dll\r\npause"
  },
  {
    "path": "build/make_win32_luajit.bat",
    "content": "@echo off\r\n\r\ncall \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars32.bat\"\r\n\r\necho Swtich to x86 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat static\r\ncd ..\\..\r\n\r\nmkdir build_lj32 & pushd build_lj32\r\ncmake -DUSING_LUAJIT=ON -G \"Visual Studio 16 2019\" -A Win32 ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -G \"Visual Studio 16 2019\" -A Win32 ..\r\npopd\r\ncmake --build build_lj32 --config Release\r\nmd plugin_luajit\\Plugins\\x86\r\ncopy /Y build_lj32\\Release\\xlua.dll plugin_luajit\\Plugins\\x86\\xlua.dll\r\npause"
  },
  {
    "path": "build/make_win64_lua53.bat",
    "content": "\r\nset \"__VS=Visual Studio 16 2019\"\r\nset \"__VSWhere=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\r\nset \"__VSDISPLAY=\"\r\nset \"__VSVER=\"\r\nif exist \"%__VSWhere%\" (\r\n    for /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productLineVersion'\r\n\t) do set __VSDISPLAY=%%p\r\n\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productDisplayVersion'\r\n\t) do set __VSVER=%%p\r\n\t\r\n)\r\nif \"%__VSVER%\" neq \"\" (\t\r\n\tset __VS=Visual Studio %__VSVER:~0,2% %__VSDisplay%\r\n)\r\n\r\nmkdir build64 & pushd build64\r\ncmake -G \"%__VS%\" -A x64 ..\r\npopd\r\ncmake --build build64 --config Release\r\nmd plugin_lua53\\Plugins\\x86_64\r\ncopy /Y build64\\Release\\xlua.dll plugin_lua53\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/make_win64_luajit.bat",
    "content": "@echo off\r\n\r\ncall \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\"\r\n\r\necho Swtich to x64 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat static\r\ncd ..\\..\r\n\r\nmkdir build_lj64 & pushd build_lj64\r\ncmake -DUSING_LUAJIT=ON -G \"Visual Studio 16 2019\" -A x64 ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -G \"Visual Studio 16 2019\" -A x64 ..\r\npopd\r\ncmake --build build_lj64 --config Release\r\nmd plugin_luajit\\Plugins\\x86_64\r\ncopy /Y build_lj64\\Release\\xlua.dll plugin_luajit\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/make_win64_luajit_gc64.bat",
    "content": "@echo off\r\ncall \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\"\r\n\r\necho Swtich to x64 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat gc64 static\r\ncd ..\\..\r\n\r\nmkdir build_lj64 & pushd build_lj64\r\ncmake -DUSING_LUAJIT=ON -DGC64=ON -G \"Visual Studio 15 2017 Win64\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -DGC64=ON -G \"Visual Studio 15 2017 Win64\" ..\r\npopd\r\ncmake --build build_lj64 --config Release\r\nmd plugin_luajit\\Plugins\\x86_64\r\ncopy /Y build_lj64\\Release\\xlua.dll plugin_luajit\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/make_win_lua54.bat",
    "content": "\r\nset \"__VS=Visual Studio 16 2019\"\r\nset \"__VSWhere=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\r\nset \"__VSDISPLAY=\"\r\nset \"__VSVER=\"\r\n\r\nif exist \"%__VSWhere%\" (\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productLineVersion'\r\n\t) do set __VSDISPLAY=%%p\r\n\r\n\tfor /f \"tokens=*\" %%p in (\r\n\t\t'\"%__VSWhere%\" -latest -property catalog_productDisplayVersion'\r\n\t) do set __VSVER=%%p\r\n)\r\n\r\nif \"%__VSVER%\" neq \"\" (\t\r\n\tset __VS=Visual Studio %__VSVER:~0,2% %__VSDisplay%\r\n)\r\n\r\n\r\nmkdir build64_54 & pushd build64_54\r\ncmake -DLUA_VERSION=5.4.1 -G \"%__VS%\" -A x64  ..\r\npopd\r\ncmake --build build64_54 --config Release\r\nmd plugin_lua54\\Plugins\\x86_64\r\ncopy /Y build64_54\\Release\\xlua.dll plugin_lua54\\Plugins\\x86_64\\xlua.dll\r\n\r\nmkdir build32_54 & pushd build32_54\r\ncmake -DLUA_VERSION=5.4.1 -G \"%__VS%\" -A Win32 ..\r\npopd\r\ncmake --build build32_54 --config Release\r\nmd plugin_lua54\\Plugins\\x86\r\ncopy /Y build32_54\\Release\\xlua.dll plugin_lua54\\Plugins\\x86\\xlua.dll\r\n\r\npause"
  },
  {
    "path": "build/memory_leak_checker.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#include <stdio.h>\n#include <string.h>\n#include \"ltable.h\"\n#include \"lstate.h\"\n#include \"lobject.h\"\n#include \"lapi.h\"\n#include \"lgc.h\"\n\n#define gnodelast(h)\tgnode(h, cast(size_t, sizenode(h)))\n\nstatic int table_size (Table *h, int fast)\n{\n\tif (fast)\n\t{\n#if LUA_VERSION_NUM >= 504\n\t\treturn (int)sizenode(h) + (int)h->alimit;\n#else\n\t\treturn (int)sizenode(h) + (int)h->sizearray;\n#endif\n\t}\n\telse\n\t{\n\t\tNode *n, *limit = gnodelast(h);\n\t\tint i = (int)luaH_getn(h);\n\t\tfor (n = gnode(h, 0); n < limit; n++)\n\t\t{ \n\t\t\tif (!ttisnil(gval(n)))\n\t\t\t{\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn i;\n\t}\n}\n\ntypedef void (*TableSizeReport) (const void *p, int size);\n\n// type: 1: value of table(key is string), 2: value of table(key is number), 3: key of table, 4: metatable of table, 5: upvalue of closure\ntypedef void (*ObjectRelationshipReport) (const void *parent, const void *child, int type, const char *key, double d, const char *key2);\n\nLUA_API void xlua_report_table_size(lua_State *L, TableSizeReport cb, int fast)\n{\n\tGCObject *p = G(L)->allgc;\n\twhile (p != NULL)\n\t{\n\t\tif (p->tt == LUA_TTABLE)\n\t\t{\n\t\t\tTable *h = gco2t(p);\n\t\t\tcb(h, table_size(h, fast));\n\t\t}\n\t\tp = p->next;\n\t}\n}\n\n\nstatic void report_table(Table *h, ObjectRelationshipReport cb)\n{\n\tNode *n, *limit = gnodelast(h);\n    unsigned int i;\n\t\n\tif (h->metatable != NULL)\n\t{\n\t\tcb(h, h->metatable, 4, NULL, 0, NULL);\n\t}\n\n#if LUA_VERSION_NUM >= 504\n    for (i = 0; i < h->alimit; i++)\n#else\n\tfor (i = 0; i < h->sizearray; i++)\n#endif\n\t{\n\t\tconst TValue *item = &h->array[i];\n\t\tif (ttistable(item))\n\t\t{\n\t\t    cb(h, gcvalue(item), 2, NULL, i + 1, NULL);\n\t\t}\n\t}\n\n    for (n = gnode(h, 0); n < limit; n++)\n\t{\n        if (!ttisnil(gval(n)))\n        {\n#if LUA_VERSION_NUM >= 504\n\t\t\tconst TValue* key = (const TValue *)&(n->u.key_val);\n#else\n            const TValue *key = gkey(n);\n#endif\n\t\t\tif (ttistable(key))\n\t\t\t{\n\t\t\t\tcb(h, gcvalue(key), 3, NULL, 0, NULL);\n\t\t\t}\n            const TValue *value = gval(n);\n\t\t\tif (ttistable(value))\n\t\t\t{\n\t\t\t\tif (ttisstring(key))\n\t\t\t\t{\n\t\t\t\t\tcb(h, gcvalue(value), 1, getstr(tsvalue(key)), 0, NULL);\n\t\t\t\t}\n\t\t\t\telse if(ttisnumber(key))\n\t\t\t\t{\n\t\t\t\t\tcb(h, gcvalue(value), 2, NULL, nvalue(key), NULL);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t// ???\n#if LUA_VERSION_NUM >= 504\n\t\t\t\t\tcb(h, gcvalue(value), 1, NULL, novariant(key->tt_), NULL);\n#else\n\t\t\t\t\tcb(h, gcvalue(value), 1, NULL, ttnov(key), NULL);\n#endif\n\t\t\t\t}\n\t\t\t}\n\t\t}\n    }\n}\n\n\nLUA_API void xlua_report_object_relationship(lua_State *L, ObjectRelationshipReport cb)\n{\n\tGCObject *p = G(L)->allgc;\n\tlua_Debug ar;\n\tint i;\n\tconst char *name;\n\t\n\twhile (p != NULL)\n\t{\n\t\tif (p->tt == LUA_TTABLE)\n\t\t{\n\t\t\tTable *h = gco2t(p);\n\t\t\treport_table(h, cb);\n\t\t}\n#if LUA_VERSION_NUM >= 504\n\t\telse if (p->tt == LUA_VLCL)\n#else\n\t\telse if (p->tt == LUA_TLCL)\n#endif\n\t\t{\n\t\t\tLClosure *cl = gco2lcl(p);\n\t\t\tlua_lock(L);\n#if LUA_VERSION_NUM >= 504 && LUA_VERSION_RELEASE_NUM >= 50406\n\t\t\tsetclLvalue2s(L, L->top.p, cl);\n#else\n\t\t\tsetclLvalue(L, L->top, cl);\n#endif\n\t\t\tapi_incr_top(L);\n\t\t\tlua_unlock(L);\n\t\t\t\n\t\t\tlua_pushvalue(L, -1);\n\t\t\t\n\t\t\tlua_getinfo(L, \">S\", &ar);\n\t\t\t\n\t\t\tfor (i=1;;i++)\n\t\t\t{\n\t\t\t\tname = lua_getupvalue(L,-1,i);\n\t\t\t\tif (name == NULL)\n\t\t\t\t\tbreak;\n\t\t\t\tconst void *pv = lua_topointer(L, -1);\n\t\t\t\t\n\t\t\t\tif (*name != '\\0' && LUA_TTABLE == lua_type(L, -1))\n\t\t\t\t{\n\t\t\t\t\tcb(cl, pv, 5, ar.short_src, ar.linedefined, name);\n\t\t\t\t}\n\t\t\t\tlua_pop(L, 1);\n\t\t\t}\n\t\t\t\n\t\t\tlua_pop(L, 1);\n\t\t}\n\t\tp = p->next;\n\t}\n}\n\nLUA_API void *xlua_registry_pointer(lua_State *L)\n{\n\treturn gcvalue(&G(L)->l_registry);\n}\n\nLUA_API void *xlua_global_pointer(lua_State *L)\n{\n\tTable *reg = hvalue(&G(L)->l_registry);\n\tconst TValue *global;\n    lua_lock(L);\n\tglobal = luaH_getint(reg, LUA_RIDX_GLOBALS);\n\tlua_unlock(L);\n\treturn gcvalue(global);\n}\n"
  },
  {
    "path": "build/plugin_lua53/Plugins/xlua.bundle/Contents/Info.plist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>BuildMachineOSBuild</key>\n\t<string>15G31</string>\n\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleExecutable</key>\n\t<string>xlua</string>\n\t<key>CFBundleIdentifier</key>\n\t<string>com.xlua</string>\n\t<key>CFBundleInfoDictionaryVersion</key>\n\t<string>6.0</string>\n\t<key>CFBundleName</key>\n\t<string>xlua</string>\n\t<key>CFBundlePackageType</key>\n\t<string>BNDL</string>\n\t<key>CFBundleShortVersionString</key>\n\t<string>1.0</string>\n\t<key>CFBundleSignature</key>\n\t<string>????</string>\n\t<key>CFBundleSupportedPlatforms</key>\n\t<array>\n\t\t<string>MacOSX</string>\n\t</array>\n\t<key>CFBundleVersion</key>\n\t<string>1</string>\n\t<key>DTCompiler</key>\n\t<string>com.apple.compilers.llvm.clang.1_0</string>\n\t<key>DTPlatformBuild</key>\n\t<string>7D1014</string>\n\t<key>DTPlatformVersion</key>\n\t<string>GM</string>\n\t<key>DTSDKBuild</key>\n\t<string>15E60</string>\n\t<key>DTSDKName</key>\n\t<string>macosx10.11</string>\n\t<key>DTXcode</key>\n\t<string>0731</string>\n\t<key>DTXcodeBuild</key>\n\t<string>7D1014</string>\n\t<key>NSHumanReadableCopyright</key>\n\t<string>Copyright @2017 THL A29 Limited, a Tencent company.  All rights reserved.</string>\n</dict>\n</plist>\n"
  },
  {
    "path": "build/plugin_luajit/Plugins/xlua.bundle/Contents/Info.plist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>BuildMachineOSBuild</key>\n\t<string>15G31</string>\n\t<key>CFBundleDevelopmentRegion</key>\n\t<string>en</string>\n\t<key>CFBundleExecutable</key>\n\t<string>xlua</string>\n\t<key>CFBundleIdentifier</key>\n\t<string>com.xlua</string>\n\t<key>CFBundleInfoDictionaryVersion</key>\n\t<string>6.0</string>\n\t<key>CFBundleName</key>\n\t<string>xlua</string>\n\t<key>CFBundlePackageType</key>\n\t<string>BNDL</string>\n\t<key>CFBundleShortVersionString</key>\n\t<string>1.0</string>\n\t<key>CFBundleSignature</key>\n\t<string>????</string>\n\t<key>CFBundleSupportedPlatforms</key>\n\t<array>\n\t\t<string>MacOSX</string>\n\t</array>\n\t<key>CFBundleVersion</key>\n\t<string>1</string>\n\t<key>DTCompiler</key>\n\t<string>com.apple.compilers.llvm.clang.1_0</string>\n\t<key>DTPlatformBuild</key>\n\t<string>7D1014</string>\n\t<key>DTPlatformVersion</key>\n\t<string>GM</string>\n\t<key>DTSDKBuild</key>\n\t<string>15E60</string>\n\t<key>DTSDKName</key>\n\t<string>macosx10.11</string>\n\t<key>DTXcode</key>\n\t<string>0731</string>\n\t<key>DTXcodeBuild</key>\n\t<string>7D1014</string>\n\t<key>NSHumanReadableCopyright</key>\n\t<string>Copyright @2017 THL A29 Limited, a Tencent company.  All rights reserved.</string>\n</dict>\n</plist>\n"
  },
  {
    "path": "build/vs2015/make_uwp.bat",
    "content": "mkdir build_uwp & pushd build_uwp\ncmake -G \"Visual Studio 14 2015\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\nIF %ERRORLEVEL% NEQ 0 cmake -G \"Visual Studio 15 2017\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp --config Release\nmd plugin_lua53\\Plugins\\WSA\\x86\ncopy /Y build_uwp\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\x86\\xlua.dll\n\nmkdir build_uwp64 & pushd build_uwp64\ncmake -G \"Visual Studio 14 2015 Win64\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\nIF %ERRORLEVEL% NEQ 0 cmake -G \"Visual Studio 15 2017 Win64\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp64 --config Release\nmd plugin_lua53\\Plugins\\WSA\\x64\ncopy /Y build_uwp64\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\x64\\xlua.dll\n\nmkdir build_uwp_arm & pushd build_uwp_arm\ncmake -G \"Visual Studio 14 2015 ARM\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\nIF %ERRORLEVEL% NEQ 0 cmake -G \"Visual Studio 15 2017 ARM\" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 ..\npopd\ncmake --build build_uwp_arm --config Release\nmd plugin_lua53\\Plugins\\WSA\\ARM\ncopy /Y build_uwp_arm\\Release\\xlua.dll plugin_lua53\\Plugins\\WSA\\ARM\\xlua.dll\n\npause\n"
  },
  {
    "path": "build/vs2015/make_win32_lua53.bat",
    "content": "mkdir build32 & pushd build32\r\ncmake -G \"Visual Studio 14 2015\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -G \"Visual Studio 15 2017\" ..\r\npopd\r\ncmake --build build32 --config Release\r\nmd plugin_lua53\\Plugins\\x86\r\ncopy /Y build32\\Release\\xlua.dll plugin_lua53\\Plugins\\x86\\xlua.dll\r\npause"
  },
  {
    "path": "build/vs2015/make_win32_luajit.bat",
    "content": "@echo off\r\nif exist \"%VS140COMNTOOLS%\" (\r\n\tset VCVARS=\"%VS140COMNTOOLS%..\\..\\VC\\bin\\\"\r\n\tgoto build\r\n\t)  else (goto missing)\r\n\r\n\r\n:build\r\n\r\n@set ENV32=\"%VCVARS%vcvars32.bat\"\r\n\r\ncall \"%ENV32%\"\r\n\r\necho Swtich to x86 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat static\r\ncd ..\\..\r\n\r\ngoto :buildxlua\r\n\r\n:missing\r\necho Can't find Visual Studio 2015.\r\npause\r\ngoto :eof\r\n\r\n:buildxlua\r\nmkdir build_lj32 & pushd build_lj32\r\ncmake -DUSING_LUAJIT=ON -G \"Visual Studio 14 2015\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -G \"Visual Studio 15 2017\" ..\r\npopd\r\ncmake --build build_lj32 --config Release\r\nmd plugin_luajit\\Plugins\\x86\r\ncopy /Y build_lj32\\Release\\xlua.dll plugin_luajit\\Plugins\\x86\\xlua.dll\r\npause"
  },
  {
    "path": "build/vs2015/make_win64_lua53.bat",
    "content": "mkdir build64 & pushd build64\r\ncmake -G \"Visual Studio 14 2015 Win64\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -G \"Visual Studio 15 2017 Win64\" ..\r\npopd\r\ncmake --build build64 --config Release\r\nmd plugin_lua53\\Plugins\\x86_64\r\ncopy /Y build64\\Release\\xlua.dll plugin_lua53\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/vs2015/make_win64_luajit.bat",
    "content": "@echo off\r\nif exist \"%VS140COMNTOOLS%\" (\r\n\tset VCVARS=\"%VS140COMNTOOLS%..\\..\\VC\\bin\\\"\r\n\tgoto build\r\n\t)  else (goto missing)\r\n\r\n\r\n:build\r\n\r\n@set ENV64=\"%VCVARS%amd64\\vcvars64.bat\"\r\n\r\ncall \"%ENV64%\"\r\n\r\necho Swtich to x64 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat static\r\ncd ..\\..\r\n\r\ngoto :buildxlua\r\n\r\n:missing\r\necho Can't find Visual Studio 2015.\r\npause\r\ngoto :eof\r\n\r\n:buildxlua\r\nmkdir build_lj64 & pushd build_lj64\r\ncmake -DUSING_LUAJIT=ON -G \"Visual Studio 14 2015 Win64\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -G \"Visual Studio 15 2017 Win64\" ..\r\npopd\r\ncmake --build build_lj64 --config Release\r\nmd plugin_luajit\\Plugins\\x86_64\r\ncopy /Y build_lj64\\Release\\xlua.dll plugin_luajit\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/vs2015/make_win64_luajit_gc64.bat",
    "content": "@echo off\r\nif exist \"%VS140COMNTOOLS%\" (\r\n\tset VCVARS=\"%VS140COMNTOOLS%..\\..\\VC\\bin\\\"\r\n\tgoto build\r\n\t)  else (goto missing)\r\n\r\n\r\n:build\r\n\r\n@set ENV64=\"%VCVARS%amd64\\vcvars64.bat\"\r\n\r\ncall \"%ENV64%\"\r\n\r\necho Swtich to x64 build env\r\ncd %~dp0\\luajit-2.1.0b3\\src\r\ncall msvcbuild_mt.bat gc64 static\r\ncd ..\\..\r\n\r\ngoto :buildxlua\r\n\r\n:missing\r\necho Can't find Visual Studio 2015.\r\npause\r\ngoto :eof\r\n\r\n:buildxlua\r\nmkdir build_lj64 & pushd build_lj64\r\ncmake -DUSING_LUAJIT=ON -DGC64=ON -G \"Visual Studio 14 2015 Win64\" ..\r\nIF %ERRORLEVEL% NEQ 0 cmake -DUSING_LUAJIT=ON -DGC64=ON -G \"Visual Studio 15 2017 Win64\" ..\r\npopd\r\ncmake --build build_lj64 --config Release\r\nmd plugin_luajit\\Plugins\\x86_64\r\ncopy /Y build_lj64\\Release\\xlua.dll plugin_luajit\\Plugins\\x86_64\\xlua.dll\r\npause"
  },
  {
    "path": "build/xlua.c",
    "content": "/*\n *Tencent is pleased to support the open source community by making xLua available.\n *Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n *Licensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n *http://opensource.org/licenses/MIT\n *Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n*/\n\n#define LUA_LIB\n\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n#include <string.h>\n#include <stdint.h>\n#include \"i64lib.h\"\n\n#if USING_LUAJIT\n#include \"lj_obj.h\"\n#else\n#include \"lstate.h\"\n#endif\n\n/*\n** stdcall C function support\n*/\n\nstatic int tag = 0;\nstatic const char *const hooknames[] = {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\nstatic int hook_index = -1;\n\nLUA_API void *xlua_tag () \n{\n\treturn &tag;\n}\n\nLUA_API int xlua_get_registry_index() {\n\treturn LUA_REGISTRYINDEX;\n}\n\nLUA_API int xlua_get_lib_version() {\n\treturn 105;\n}\n\nLUA_API int xlua_tocsobj_safe(lua_State *L,int index) {\n\tint *udata = (int *)lua_touserdata (L,index);\n\tif (udata != NULL) {\n\t\tif (lua_getmetatable(L,index)) {\n\t\t    lua_pushlightuserdata(L, &tag);\n\t\t\tlua_rawget(L,-2);\n\t\t\tif (!lua_isnil (L,-1)) {\n\t\t\t\tlua_pop (L, 2);\n\t\t\t\treturn *udata;\n\t\t\t}\n\t\t\tlua_pop (L, 2);\n\t\t}\n\t}\n\treturn -1;\n}\n\nLUA_API int xlua_tocsobj_fast (lua_State *L,int index) {\n\tint *udata = (int *)lua_touserdata (L,index);\n\n\tif(udata!=NULL) \n\t\treturn *udata;\n\treturn -1;\n}\n\n#if LUA_VERSION_NUM == 501\n#undef lua_getglobal\nLUA_API int lua_getglobal (lua_State *L, const char *name) {\n\tlua_getfield(L, LUA_GLOBALSINDEX, name);\n\treturn 0;\n}\n\n#undef lua_setglobal\nLUA_API void lua_setglobal (lua_State *L, const char *name) {\n\tlua_setfield(L, LUA_GLOBALSINDEX, name);\n}\n\nLUA_API int lua_isinteger (lua_State *L, int idx) {\n\treturn 0;\n}\n\nLUA_API uint32_t xlua_objlen (lua_State *L, int idx) {\n\treturn lua_objlen (L, idx);\n}\n\nLUA_API uint32_t xlua_touint (lua_State *L, int idx) {\n\treturn (uint32_t)lua_tonumber(L, idx);\n}\n\nLUA_API void xlua_pushuint (lua_State *L, uint32_t n) {\n\tlua_pushnumber(L, n);\n}\n#endif\n\n#if LUA_VERSION_NUM >= 503\nLUA_API int lua_setfenv(lua_State *L, int idx)\n{\n    int type = lua_type(L, idx);\n    if(type == LUA_TUSERDATA || type == LUA_TFUNCTION)\n    {\n        lua_setupvalue(L, idx, 1);\n        return 1;\n    }\n    else\n    {\n        return 0;\n    }\n}\n\nLUA_API uint32_t xlua_objlen (lua_State *L, int idx) {\n\treturn (uint32_t)luaL_len (L, idx);\n}\n\nLUA_API uint32_t xlua_touint (lua_State *L, int idx) {\n\treturn lua_isinteger(L, idx) ? (uint32_t)lua_tointeger(L, idx) : (uint32_t) lua_tonumber(L, idx);\n}\n\nLUA_API void xlua_pushuint (lua_State *L, uint32_t n) {\n\tlua_pushinteger(L, n);\n}\n\n#undef lua_insert\nLUA_API void lua_insert (lua_State *L, int idx) {\n    lua_rotate(L, idx, 1);\n}\n\n#undef lua_remove\nLUA_API void lua_remove (lua_State *L, int idx) {\n\tlua_rotate(L, idx, -1);\n\tlua_pop(L, 1);\n}\n\n#undef lua_replace\nLUA_API void lua_replace (lua_State *L, int idx) {\n\tlua_copy(L, -1, idx);\n\tlua_pop(L, 1);\n}\n\n#undef lua_pcall\nLUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {\n\treturn lua_pcallk(L, nargs, nresults, errfunc, 0, NULL);\n}\n\n#undef lua_tonumber\nLUA_API lua_Number lua_tonumber (lua_State *L, int idx) {\n\treturn lua_tonumberx(L, idx, NULL);\n}\n\n#endif\n\n#if LUA_VERSION_NUM < 503\n#define lua_absindex(L, index) ((index > 0 || index <= LUA_REGISTRYINDEX) ? index : lua_gettop(L) + index + 1)\n#endif\n\nLUA_API void xlua_getloaders (lua_State *L) {\n\tlua_getglobal(L, \"package\");\n#if LUA_VERSION_NUM == 501\n    lua_getfield(L, -1, \"loaders\");\n#else\n\tlua_getfield(L, -1, \"searchers\");\n#endif\n\tlua_remove(L, -2);\n}\n\nLUA_API void xlua_rawgeti (lua_State *L, int idx, int64_t n) {\n\tlua_rawgeti(L, idx, (lua_Integer)n);\n}\n\nLUA_API void xlua_rawseti (lua_State *L, int idx, int64_t n) {\n\tlua_rawseti(L, idx, (lua_Integer)n);\n}\n\nLUA_API int xlua_ref_indirect(lua_State *L, int indirectRef) {\n\tint ret = 0;\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, indirectRef);\n\tlua_pushvalue(L, -2);\n\tret = luaL_ref(L, -2);\n\tlua_pop(L, 2);\n\treturn ret;\n}\n\nLUA_API void xlua_getref_indirect(lua_State *L, int indirectRef, int reference) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, indirectRef);\n\tlua_rawgeti(L, -1, reference);\n\tlua_remove(L, -2);\n}\n\nLUA_API int xlua_tointeger (lua_State *L, int idx) {\n\treturn (int)lua_tointeger(L, idx);\n}\n\nLUA_API void xlua_pushinteger (lua_State *L, int n) {\n\tlua_pushinteger(L, n);\n}\n\nLUA_API void xlua_pushlstring (lua_State *L, const char *s, int len) {\n\tlua_pushlstring(L, s, len);\n}\n\nLUALIB_API int xluaL_loadbuffer (lua_State *L, const char *buff, int size,\n                                const char *name) {\n\treturn luaL_loadbuffer(L, buff, size, name);\n}\n\nstatic int c_lua_gettable(lua_State* L) {    \n    lua_gettable(L, 1);    \n    return 1;\n}\n\nLUA_API int xlua_pgettable(lua_State* L, int idx) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_gettable);\n    lua_pushvalue(L, idx);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    return lua_pcall(L, 2, 1, 0);\n}\n\nstatic int c_lua_gettable_bypath(lua_State* L) {\n\tsize_t len = 0;\n\tconst char * pos = NULL;\n\tconst char * path = lua_tolstring(L, 2, &len);\n\tlua_pushvalue(L, 1);\n\tdo {\n\t\tpos = strchr(path, '.');\n\t\tif (NULL == pos) {\n\t\t\tlua_pushlstring(L, path, len);\n\t\t} else {\n\t\t\tlua_pushlstring(L, path, pos - path);\n\t\t\tlen = len - (pos - path + 1);\n\t\t\tpath = pos + 1;\n\t\t}\n\t\tlua_gettable(L, -2);\n\t\tif (lua_type(L, -1) != LUA_TTABLE) {\n\t\t\tif (NULL != pos) { // not found in path\n\t\t\t\tlua_pushnil(L);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tlua_remove(L, -2);\n\t} while(pos);\n    return 1;\n}\n\nLUA_API int xlua_pgettable_bypath(lua_State* L, int idx, const char *path) {\n\tidx = lua_absindex(L, idx);\n\tlua_pushcfunction(L, c_lua_gettable_bypath);\n\tlua_pushvalue(L, idx);\n\tlua_pushstring(L, path);\n\treturn lua_pcall(L, 2, 1, 0);\n}\n\nstatic int c_lua_settable(lua_State* L) {\n    lua_settable(L, 1);\n    return 0;\n}\n\nLUA_API int xlua_psettable(lua_State* L, int idx) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_settable);\n    lua_pushvalue(L, idx);\n    lua_pushvalue(L, top - 1);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    lua_remove(L, top - 1);\n    return lua_pcall(L, 3, 0, 0);\n}\n\nstatic int c_lua_settable_bypath(lua_State* L) {\n    size_t len = 0;\n\tconst char * pos = NULL;\n\tconst char * path = lua_tolstring(L, 2, &len);\n\tlua_pushvalue(L, 1);\n\tdo {\n\t\tpos = strchr(path, '.');\n\t\tif (NULL == pos) { // last\n\t\t\tlua_pushlstring(L, path, len);\n\t\t\tlua_pushvalue(L, 3);\n\t\t\tlua_settable(L, -3);\n\t\t\tlua_pop(L, 1);\n\t\t\tbreak;\n\t\t} else {\n\t\t\tlua_pushlstring(L, path, pos - path);\n\t\t\tlen = len - (pos - path + 1);\n\t\t\tpath = pos + 1;\n\t\t}\n\t\tlua_gettable(L, -2);\n\t\tif (lua_type(L, -1) != LUA_TTABLE) {\n\t\t\treturn luaL_error(L, \"can not set value to %s\", lua_tostring(L, 2));\n\t\t}\n\t\tlua_remove(L, -2);\n\t} while(pos);\n    return 0;\n}\n\nLUA_API int xlua_psettable_bypath(lua_State* L, int idx, const char *path) {\n    int top = lua_gettop(L);\n    idx = lua_absindex(L, idx);\n    lua_pushcfunction(L, c_lua_settable_bypath);\n    lua_pushvalue(L, idx);\n    lua_pushstring(L, path);\n    lua_pushvalue(L, top);\n    lua_remove(L, top);\n    return lua_pcall(L, 3, 0, 0);\n}\n\nstatic int c_lua_getglobal(lua_State* L) {\n\tlua_getglobal(L, lua_tostring(L, 1));\n\treturn 1;\n}\n\nLUA_API int xlua_getglobal (lua_State *L, const char *name) {\n\tlua_pushcfunction(L, c_lua_getglobal);\n\tlua_pushstring(L, name);\n\treturn lua_pcall(L, 1, 1, 0);\n}\n\nstatic int c_lua_setglobal(lua_State* L) {\n\tlua_setglobal(L, lua_tostring(L, 1));\n\treturn 0;\n}\n\nLUA_API int xlua_setglobal (lua_State *L, const char *name) {\n\tint top = lua_gettop(L);\n\tlua_pushcfunction(L, c_lua_setglobal);\n\tlua_pushstring(L, name);\n\tlua_pushvalue(L, top);\n\tlua_remove(L, top);\n\treturn lua_pcall(L, 2, 0, 0);\n}\n\nLUA_API int xlua_tryget_cachedud(lua_State *L, int key, int cache_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);\n\tlua_rawgeti(L, -1, key);\n\tif (!lua_isnil(L, -1))\n\t{\n\t\tlua_remove(L, -2);\n\t\treturn 1;\n\t}\n\tlua_pop(L, 2);\n\treturn 0;\n}\n\nstatic void cacheud(lua_State *L, int key, int cache_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);\n\tlua_pushvalue(L, -2);\n\tlua_rawseti(L, -2, key);\n\tlua_pop(L, 1);\n}\n\n\nLUA_API void xlua_pushcsobj(lua_State *L, int key, int meta_ref, int need_cache, int cache_ref) {\n\tint* pointer = (int*)lua_newuserdata(L, sizeof(int));\n\t*pointer = key;\n\t\n\tif (need_cache) cacheud(L, key, cache_ref);\n\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\n\tlua_setmetatable(L, -2);\n}\n\nvoid print_top(lua_State *L) {\n\tlua_getglobal(L, \"print\");\n\tlua_pushvalue(L, -2);\n\tlua_call(L, 1, 0);\n}\n\nvoid print_str(lua_State *L, char *str) {\n\tlua_getglobal(L, \"print\");\n\tlua_pushstring(L, str);\n\tlua_call(L, 1, 0);\n}\n\nvoid print_value(lua_State *L,  char *str, int idx) {\n\tidx = lua_absindex(L, idx);\n\tlua_getglobal(L, \"print\");\n\tlua_pushstring(L, str);\n\tlua_pushvalue(L, idx);\n\tlua_call(L, 2, 0);\n}\n\n//upvalue --- [1]: methods, [2]:getters, [3]:csindexer, [4]:base, [5]:indexfuncs, [6]:arrayindexer, [7]:baseindex\n//param   --- [1]: obj, [2]: key\nLUA_API int obj_indexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has method\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(2));\n\t\tif (!lua_isnil(L, -1)) {//has getter\n\t\t\tlua_pushvalue(L, 1);\n\t\t\tlua_call(L, 1, 1);\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(6)) && lua_type(L, 2) == LUA_TNUMBER) {\n\t\tlua_pushvalue(L, lua_upvalueindex(6));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_call(L, 2, 2);\n\t\tif (lua_toboolean(L, -2)) {\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 2);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(4))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(4));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(5));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(7)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(4));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(7))) {\n\t\tlua_settop(L, 2);\n\t\tlua_pushvalue(L, lua_upvalueindex(7));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n\nLUA_API int gen_obj_indexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, obj_indexer, 7);\n\treturn 0;\n}\n\n//upvalue --- [1]:setters, [2]:csnewindexer, [3]:base, [4]:newindexfuncs, [5]:arrayindexer, [6]:basenewindex\n//param   --- [1]: obj, [2]: key, [3]: value\nLUA_API int obj_newindexer(lua_State *L) {\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has setter\n\t\t\tlua_pushvalue(L, 1);\n\t\t\tlua_pushvalue(L, 3);\n\t\t\tlua_call(L, 2, 0);\n\t\t\treturn 0;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(2));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_pushvalue(L, 3);\n\t\tlua_call(L, 3, 1);\n\t\tif (lua_toboolean(L, -1)) {\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(5)) && lua_type(L, 2) == LUA_TNUMBER) {\n\t\tlua_pushvalue(L, lua_upvalueindex(5));\n\t\tlua_pushvalue(L, 1);\n\t\tlua_pushvalue(L, 2);\n\t\tlua_pushvalue(L, 3);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(4));\n\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(6)); //basenewindex = newindexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(3));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(6))) {\n\t\tlua_settop(L, 3);\n\t\tlua_pushvalue(L, lua_upvalueindex(6));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t} else {\n\t\treturn luaL_error(L, \"cannot set %s, no such field\", lua_tostring(L, 2));\n\t}\n}\n\nLUA_API int gen_obj_newindexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, obj_newindexer, 6);\n\treturn 0;\n}\n\n//upvalue --- [1]:getters, [2]:feilds, [3]:base, [4]:indexfuncs, [5]:baseindex\n//param   --- [1]: obj, [2]: key\nLUA_API int cls_indexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has getter\n\t\t\tlua_call(L, 0, 1);\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_rawget(L, lua_upvalueindex(2));\n\t\tif (!lua_isnil(L, -1)) {//has feild\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(3))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(3));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(4));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(5)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(3));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(5))) {\n\t\tlua_settop(L, 2);\n\t\tlua_pushvalue(L, lua_upvalueindex(5));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 2, 1);\n\t\treturn 1;\n\t} else {\n\t\tlua_pushnil(L);\n\t\treturn 1;\n\t}\n}\n\nLUA_API int gen_cls_indexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, cls_indexer, 5);\n\treturn 0;\n}\n\n//upvalue --- [1]:setters, [2]:base, [3]:indexfuncs, [4]:baseindex\n//param   --- [1]: obj, [2]: key, [3]: value\nLUA_API int cls_newindexer(lua_State *L) {\t\n\tif (!lua_isnil(L, lua_upvalueindex(1))) {\n\t\tlua_pushvalue(L, 2);\n\t\tlua_gettable(L, lua_upvalueindex(1));\n\t\tif (!lua_isnil(L, -1)) {//has setter\n\t\t    lua_pushvalue(L, 3);\n\t\t\tlua_call(L, 1, 0);\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(2))) {\n\t\tlua_pushvalue(L, lua_upvalueindex(2));\n\t\twhile(!lua_isnil(L, -1)) {\n\t\t\tlua_pushvalue(L, -1);\n\t\t\tlua_gettable(L, lua_upvalueindex(3));\n\t\t\tif (!lua_isnil(L, -1)) // found\n\t\t\t{\n\t\t\t\tlua_replace(L, lua_upvalueindex(4)); //baseindex = indexfuncs[base]\n\t\t\t\tlua_pop(L, 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlua_pop(L, 1);\n\t\t\tlua_getfield(L, -1, \"BaseType\");\n\t\t\tlua_remove(L, -2);\n\t\t}\n\t\tlua_pushnil(L);\n\t\tlua_replace(L, lua_upvalueindex(2));//base = nil\n\t}\n\t\n\tif (!lua_isnil(L, lua_upvalueindex(4))) {\n\t\tlua_settop(L, 3);\n\t\tlua_pushvalue(L, lua_upvalueindex(4));\n\t\tlua_insert(L, 1);\n\t\tlua_call(L, 3, 0);\n\t\treturn 0;\n\t} else {\n\t\treturn luaL_error(L, \"no static field %s\", lua_tostring(L, 2));\n\t}\n}\n\nLUA_API int gen_cls_newindexer(lua_State *L) {\n\tlua_pushnil(L);\n\tlua_pushcclosure(L, cls_newindexer, 4);\n\treturn 0;\n}\n\nLUA_API int errorfunc(lua_State *L) {\n\tlua_getglobal(L, \"debug\");\n\tlua_getfield(L, -1, \"traceback\");\n\tlua_remove(L, -2);\n\tlua_pushvalue(L, 1);\n\tlua_pushnumber(L, 2);\n\tlua_call(L, 2, 1);\n    return 1;\n}\n\nLUA_API int get_error_func_ref(lua_State *L) {\n\tlua_pushcclosure(L, errorfunc, 0);\n\treturn luaL_ref(L, LUA_REGISTRYINDEX);\n}\n\nLUA_API int load_error_func(lua_State *L, int ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, ref);\n\treturn lua_gettop(L);\n}\n\nLUA_API int pcall_prepare(lua_State *L, int error_func_ref, int func_ref) {\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, error_func_ref);\n\tlua_rawgeti(L, LUA_REGISTRYINDEX, func_ref);\n\treturn lua_gettop(L) - 1;\n}\n\nstatic void hook(lua_State *L, lua_Debug *ar)\n{\n\tint event;\n\t\n\tlua_pushlightuserdata(L, &hook_index);\n\tlua_rawget(L, LUA_REGISTRYINDEX);\n\n\tevent = ar->event;\n\tlua_pushstring(L, hooknames[event]);\n  \n\tlua_getinfo(L, \"nS\", ar);\n\tif (*(ar->what) == 'C') {\n\t\tlua_pushfstring(L, \"[?%s]\", ar->name);\n\t} else {\n\t\tlua_pushfstring(L, \"%s:%d\", ar->short_src, ar->linedefined > 0 ? ar->linedefined : 0);\n\t}\n\n\tlua_call(L, 2, 0);\n}\n\nstatic void call_ret_hook(lua_State *L) {\n\tlua_Debug ar;\n\t\n\tif (lua_gethook(L)) {\n\t\tlua_getstack(L, 0, &ar);\n\t\tlua_getinfo(L, \"n\", &ar);\n\t\t\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_rawget(L, LUA_REGISTRYINDEX);\n\t\t\n\t\tif (lua_type(L, -1) != LUA_TFUNCTION){\n\t\t\tlua_pop(L, 1);\n\t\t\treturn;\n        }\n\t\t\n\t\tlua_pushliteral(L, \"return\");\n\t\tlua_pushfstring(L, \"[?%s]\", ar.name);\n\t\tlua_pushliteral(L, \"[C#]\");\n\t\t\n\t\tlua_sethook(L, 0, 0, 0);\n\t\tlua_call(L, 3, 0);\n\t\tlua_sethook(L, hook, LUA_MASKCALL | LUA_MASKRET, 0);\n\t}\n}\n\nstatic int profiler_set_hook(lua_State *L) {\n\tif (lua_isnoneornil(L, 1)) {\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_pushnil(L);\n\t\tlua_rawset(L, LUA_REGISTRYINDEX);\n\t\t\t\n\t\tlua_sethook(L, 0, 0, 0);\n\t} else {\n\t\tluaL_checktype(L, 1, LUA_TFUNCTION);\n\t\tlua_pushlightuserdata(L, &hook_index);\n\t\tlua_pushvalue(L, 1);\n\t\tlua_rawset(L, LUA_REGISTRYINDEX);\n\t\tlua_sethook(L, hook, LUA_MASKCALL | LUA_MASKRET, 0);\n\t}\n\treturn 0;\n}\n\nstatic int csharp_function_wrap(lua_State *L) {\n\tlua_CFunction fn = (lua_CFunction)lua_tocfunction(L, lua_upvalueindex(1));\n    int ret = fn(L);    \n    \n    if (lua_toboolean(L, lua_upvalueindex(2)))\n    {\n        lua_pushboolean(L, 0);\n        lua_replace(L, lua_upvalueindex(2));\n        return lua_error(L);\n    }\n    \n\tif (lua_gethook(L)) {\n\t\tcall_ret_hook(L);\n\t}\n\t\n    return ret;\n}\n\nLUA_API void xlua_push_csharp_function(lua_State* L, lua_CFunction fn, int n)\n{ \n    lua_pushcfunction(L, fn);\n\tif (n > 0) {\n\t\tlua_insert(L, -1 - n);\n\t}\n\tlua_pushboolean(L, 0);\n\tif (n > 0) {\n\t\tlua_insert(L, -1 - n);\n\t}\n    lua_pushcclosure(L, csharp_function_wrap, 2 + (n > 0 ? n : 0));\n}\n\ntypedef int (*lua_CSWrapperCaller) (lua_State *L, int wrapperid, int top);\n\nstatic lua_CSWrapperCaller g_csharp_wrapper_caller = NULL;\n\nLUA_API void xlua_set_csharp_wrapper_caller(lua_CSWrapperCaller wrapper_caller)\n{\n\tg_csharp_wrapper_caller = wrapper_caller;\n}\n\nstatic int csharp_function_wrapper_wrapper(lua_State *L) {\n    int ret = 0;\n\t\n\tif (g_csharp_wrapper_caller == NULL) {\n\t\treturn luaL_error(L, \"g_csharp_wrapper_caller not set\");\n\t}\n\t\n\tret = g_csharp_wrapper_caller(L, xlua_tointeger(L, lua_upvalueindex(1)), lua_gettop(L));    \n    \n    if (lua_toboolean(L, lua_upvalueindex(2)))\n    {\n        lua_pushboolean(L, 0);\n        lua_replace(L, lua_upvalueindex(2));\n        return lua_error(L);\n    }\n    \n\tif (lua_gethook(L)) {\n\t\tcall_ret_hook(L);\n\t}\n\t\n    return ret;\n}\n\nLUA_API void xlua_push_csharp_wrapper(lua_State* L, int wrapperid)\n{ \n\tlua_pushinteger(L, wrapperid);\n\tlua_pushboolean(L, 0);\n    lua_pushcclosure(L, csharp_function_wrapper_wrapper, 2);\n}\n\nLUALIB_API int xlua_upvalueindex(int n) {\n\treturn lua_upvalueindex(2 + n);\n}\n\nLUALIB_API int xlua_csharp_str_error(lua_State* L, const char* msg)\n{\n    lua_pushboolean(L, 1);\n    lua_replace(L, lua_upvalueindex(2));\n    lua_pushstring(L, msg);\n    return 1;\n}\n\nLUALIB_API int xlua_csharp_error(lua_State* L)\n{\n    lua_pushboolean(L, 1);\n    lua_replace(L, lua_upvalueindex(2));\n    return 1;\n}\n\ntypedef struct {\n\tint fake_id;\n    unsigned int len;\n\tchar data[1];\n} CSharpStruct;\n\nLUA_API void *xlua_pushstruct(lua_State *L, unsigned int size, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_newuserdata(L, size + sizeof(int) + sizeof(unsigned int));\n\tcss->fake_id = -1;\n\tcss->len = size;\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n\treturn css;\n}\n\nLUA_API void xlua_pushcstable(lua_State *L, unsigned int size, int meta_ref) {\n\tlua_createtable(L, 0, size);\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n}\n\nLUA_API void *xlua_newstruct(lua_State *L, int size, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_newuserdata(L, size + sizeof(int) + sizeof(unsigned int));\n\tcss->fake_id = -1;\n\tcss->len = size;\n    lua_rawgeti(L, LUA_REGISTRYINDEX, meta_ref);\n\tlua_setmetatable(L, -2);\n\treturn css->data;\n}\n\nLUA_API void *xlua_tostruct(lua_State *L, int idx, int meta_ref) {\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, idx);\n\tif (NULL != css) {\n\t\tif (lua_getmetatable (L, idx)) {\n\t\t\tlua_rawgeti(L, -1, 1);\n\t\t\tif (lua_type(L, -1) == LUA_TNUMBER && (int)lua_tointeger(L, -1) == meta_ref) {\n\t\t\t\tlua_pop(L, 2);\n\t\t\t\treturn css->data; \n\t\t\t}\n\t\t\tlua_pop(L, 2);\n\t\t}\n\t}\n\treturn NULL;\n}\n\nLUA_API int xlua_gettypeid(lua_State *L, int idx) {\n\tint type_id = -1;\n\tif (lua_type(L, idx) == LUA_TUSERDATA) {\n\t\tif (lua_getmetatable (L, idx)) {\n\t\t\tlua_rawgeti(L, -1, 1);\n\t\t\tif (lua_type(L, -1) == LUA_TNUMBER) {\n\t\t\t\ttype_id = (int)lua_tointeger(L, -1);\n\t\t\t}\n\t\t\tlua_pop(L, 2);\n\t\t}\n\t}\n\treturn type_id;\n}\n\n#define PACK_UNPACK_OF(type) \\\nLUALIB_API int xlua_pack_##type(void *p, int offset, type field) {\\\n\tCSharpStruct *css = (CSharpStruct *)p;\\\n\tif (css->fake_id != -1 || css->len < offset + sizeof(field)) {\\\n\t\treturn 0;\\\n\t} else {\\\n\t\tmemcpy((&(css->data[0]) + offset), &field, sizeof(field));\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\\\nLUALIB_API int xlua_unpack_##type(void *p, int offset, type *pfield) { \\\n\tCSharpStruct *css = (CSharpStruct *)p;\\\n\tif (css->fake_id != -1 || css->len < offset + sizeof(*pfield)) {\\\n\t\treturn 0;\\\n\t} else {\\\n\t\tmemcpy(pfield, (&(css->data[0]) + offset), sizeof(*pfield));\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\nPACK_UNPACK_OF(int8_t);\nPACK_UNPACK_OF(int16_t);\nPACK_UNPACK_OF(int32_t);\nPACK_UNPACK_OF(int64_t);\nPACK_UNPACK_OF(float);\nPACK_UNPACK_OF(double);\n\nLUALIB_API int xlua_pack_float2(void *p, int offset, float f1, float f2) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 2) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float2(void *p, int offset, float *f1, float *f2) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 2) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float3(void *p, int offset, float f1, float f2, float f3) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 3) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float3(void *p, int offset, float *f1, float *f2, float *f3) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 3) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float4(void *p, int offset, float f1, float f2, float f3, float f4) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float4(void *p, int offset, float *f1, float *f2, float *f3, float *f4) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float5(void *p, int offset, float f1, float f2, float f3, float f4, float f5) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 5) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\tpos[4] = f5;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float5(void *p, int offset, float *f1, float *f2, float *f3, float *f4, float *f5) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 5) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\t*f5 = pos[4];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_float6(void *p, int offset, float f1, float f2, float f3, float f4, float f5, float f6) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 6) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\tpos[0] = f1;\n\t\tpos[1] = f2;\n\t\tpos[2] = f3;\n\t\tpos[3] = f4;\n\t\tpos[4] = f5;\n\t\tpos[5] = f6;\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_unpack_float6(void *p, int offset, float *f1, float *f2, float *f3, float *f4, float *f5, float *f6) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < offset + sizeof(float) * 6) {\n\t\treturn 0;\n\t} else {\n\t\tfloat *pos = (float *)(&(css->data[0]) + offset);\n\t\t*f1 = pos[0];\n\t\t*f2 = pos[1];\n\t\t*f3 = pos[2];\n\t\t*f4 = pos[3];\n\t\t*f5 = pos[4];\n\t\t*f6 = pos[5];\n\t\treturn 1;\n\t}\n}\n\nLUALIB_API int xlua_pack_decimal(void *p, int offset, const int * decimal) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < sizeof(int) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tint *pos = (int *)(&(css->data[0]) + offset);\n\t\tpos[0] = decimal[0];\n\t\tpos[1] = decimal[1];\n\t\tpos[2] = decimal[2];\n\t\tpos[3] = decimal[3];\n\t\treturn 1;\n\t}\n}\n\ntypedef struct tagDEC {\n    uint16_t    wReserved;\n    uint8_t     scale;\n    uint8_t     sign;\n    int         Hi32;\n    uint64_t    Lo64;\n} DECIMAL;\n\nLUALIB_API int xlua_unpack_decimal(void *p, int offset, uint8_t *scale, uint8_t *sign, int *hi32, uint64_t *lo64) {\n\tCSharpStruct *css = (CSharpStruct *)p;\n\tif (css->fake_id != -1 || css->len < sizeof(int) * 4) {\n\t\treturn 0;\n\t} else {\n\t\tDECIMAL *dec = (DECIMAL *)(&(css->data[0]) + offset);\n\t\t*scale = dec->scale;\n\t\t*sign = dec->sign;\n\t\t*hi32 = dec->Hi32;\n\t\t*lo64 = dec->Lo64;\n\t\treturn 1;\n\t}\n}\n\nLUA_API int xlua_is_eq_str(lua_State *L, int idx, const char* str, int str_len) {\n\tsize_t lmsg;\n    const char *msg;\n\tif (lua_type(L, idx) == LUA_TSTRING) {\n        msg = lua_tolstring(L, idx, &lmsg);\n\t\treturn (lmsg == str_len) && (memcmp(msg, str, lmsg) == 0);\n\t} else {\n\t\treturn 0;\n\t}\n}\n\n#define T_INT8   0\n#define T_UINT8  1\n#define T_INT16  2\n#define T_UINT16 3\n#define T_INT32  4\n#define T_UINT32 5\n#define T_INT64  6\n#define T_UINT64 7\n#define T_FLOAT  8\n#define T_DOUBLE 9\n\n#define DIRECT_ACCESS(type, push_func, to_func) \\\nint xlua_struct_get_##type(lua_State *L) {\\\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, 1);\\\n\tint offset = xlua_tointeger(L, lua_upvalueindex(1));\\\n\ttype val;\\\n\tif (css == NULL || css->fake_id != -1 || css->len < offset + sizeof(type)) {\\\n\t\treturn luaL_error(L, \"invalid c# struct!\");\\\n\t} else {\\\n\t\tmemcpy(&val, (&(css->data[0]) + offset), sizeof(type));\\\n\t\tpush_func(L, val);\\\n\t\treturn 1;\\\n\t}\\\n}\\\n\\\nint xlua_struct_set_##type(lua_State *L) { \\\n\tCSharpStruct *css = (CSharpStruct *)lua_touserdata(L, 1);\\\n\tint offset = xlua_tointeger(L, lua_upvalueindex(1));\\\n\ttype val;\\\n\tif (css == NULL || css->fake_id != -1 || css->len < offset + sizeof(type)) {\\\n\t\treturn luaL_error(L, \"invalid c# struct!\");\\\n\t} else {\\\n\t    val = (type)to_func(L, 2);\\\n\t\tmemcpy((&(css->data[0]) + offset), &val, sizeof(type));\\\n\t\treturn 0;\\\n\t}\\\n}\\\n\nDIRECT_ACCESS(int8_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint8_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(int16_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint16_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(int32_t, xlua_pushinteger, xlua_tointeger);\nDIRECT_ACCESS(uint32_t, xlua_pushuint, xlua_touint);\nDIRECT_ACCESS(int64_t, lua_pushint64, lua_toint64);\nDIRECT_ACCESS(uint64_t, lua_pushuint64, lua_touint64);\nDIRECT_ACCESS(float, lua_pushnumber, lua_tonumber);\nDIRECT_ACCESS(double, lua_pushnumber, lua_tonumber);\n\nstatic const lua_CFunction direct_getters[10] = {\n\txlua_struct_get_int8_t,\n\txlua_struct_get_uint8_t,\n\txlua_struct_get_int16_t,\n\txlua_struct_get_uint16_t,\n\txlua_struct_get_int32_t,\n\txlua_struct_get_uint32_t,\n\txlua_struct_get_int64_t,\n\txlua_struct_get_uint64_t,\n\txlua_struct_get_float,\n\txlua_struct_get_double\n};\n\nstatic const lua_CFunction direct_setters[10] = {\n\txlua_struct_set_int8_t,\n\txlua_struct_set_uint8_t,\n\txlua_struct_set_int16_t,\n\txlua_struct_set_uint16_t,\n\txlua_struct_set_int32_t,\n\txlua_struct_set_uint32_t,\n\txlua_struct_set_int64_t,\n\txlua_struct_set_uint64_t,\n\txlua_struct_set_float,\n\txlua_struct_set_double\n};\n\nint nop(lua_State *L) {\n\treturn 0;\n}\n\nLUA_API int gen_css_access(lua_State *L) {\n\tint offset = xlua_tointeger(L, 1);\n\tint type = xlua_tointeger(L, 2);\n\tif (offset < 0) {\n\t\treturn luaL_error(L, \"offset must larger than 0\");\n\t}\n\tif (type < T_INT8 || type > T_DOUBLE) {\n\t\treturn luaL_error(L, \"unknow tag[%d]\", type);\n\t}\n\tlua_pushvalue(L, 1);\n\tlua_pushcclosure(L, direct_getters[type], 1);\n\tlua_pushvalue(L, 1);\n\tlua_pushcclosure(L, direct_setters[type], 1);\n\tlua_pushcclosure(L, nop, 0);\n\treturn 3;\n}\n\nstatic int is_cs_data(lua_State *L, int idx) {\n\tif (LUA_TUSERDATA == lua_type(L, idx) && lua_getmetatable(L, idx)) {\n\t\tlua_pushlightuserdata(L, &tag);\n\t\tlua_rawget(L,-2);\n\t\tif (!lua_isnil (L,-1)) {\n\t\t\tlua_pop (L, 2);\n\t\t\treturn 1;\n\t\t}\n\t\tlua_pop (L, 2);\n\t}\n\treturn 0;\n}\n\nLUA_API int css_clone(lua_State *L) {\n\tCSharpStruct *from = (CSharpStruct *)lua_touserdata(L, 1);\n\tCSharpStruct *to = NULL;\n\tif (!is_cs_data(L, 1) || from->fake_id != -1) {\n\t\treturn luaL_error(L, \"invalid c# struct!\");\n\t}\n\t\n\tto = (CSharpStruct *)lua_newuserdata(L, from->len + sizeof(int) + sizeof(unsigned int));\n\tto->fake_id = -1;\n\tto->len = from->len;\n\tmemcpy(&(to->data[0]), &(from->data[0]), from->len);\n    lua_getmetatable(L, 1);\n\tlua_setmetatable(L, -2);\n\treturn 1;\n}\n\nLUA_API void* xlua_gl(lua_State *L) {\n\treturn G(L);\n}\n\nstatic const luaL_Reg xlualib[] = {\n\t{\"sethook\", profiler_set_hook},\n\t{\"genaccessor\", gen_css_access},\n\t{\"structclone\", css_clone},\n\t{NULL, NULL}\n};\n\nLUA_API void luaopen_xlua(lua_State *L) {\n\tluaL_openlibs(L);\n\t\n#if LUA_VERSION_NUM >= 503\n\tluaL_newlib(L, xlualib);\n\tlua_setglobal(L, \"xlua\");\n#else\n\tluaL_register(L, \"xlua\", xlualib);\n    lua_pop(L, 1);\n#endif\n}\n\n"
  },
  {
    "path": "docs/.gitignore",
    "content": ".DS_Store\nThumbs.db\ndb.json\n*.log\nnode_modules/\n.deploy*/"
  },
  {
    "path": "docs/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"zh\">\n  <head>\n    <title>XLua</title>\n    <meta charset=\"utf-8\" />\n    <meta name=\"description\" content=\"XLua\" />\n    <meta\n      name=\"viewport\"\n      content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\"\n    />\n  </head>\n\n  <body>\n    <script>\n      window.location.href = \"public/v1/guide/index.html\";\n    </script>\n  </body>\n</html>\n"
  },
  {
    "path": "docs/public/css/index.css",
    "content": "body,\nfooter,\nheader,\nh1,\nh2,\nh3,\nh4,\nh5,\nh6,\nhr,\np,\nblockquote,\ndl,\ndt,\ndd,\nul,\nol,\nli,\nform,\nfieldset,\nlegend,\nbutton,\ninput,\ntextarea,\nth,\ntd {\n  margin: 0;\n  padding: 0;\n}\ntext-align center {\n  -webkit-text-size-adjust: none;\n  color: #3d9cff;\n}\nbody,\nbutton,\ninput,\nselect,\ntextarea,\nol,\np,\nblockquote,\ndl,\ndt,\ndd,\nul,\nli,\nform,\nfieldset,\nlegend,\nth,\ntd {\n  outline: none;\n  font: 1em \"Helvetica Neue\", \"Helvetica\", \"Lucida Grande\", \"Arial\", \"Hiragino Sans GB\", \"Microsoft Yahei\", \"WenQuanYi Micro Hei\", \"sans-serif\", arial, sans-serif;\n  text-align: left;\n  color: #3d9cff;\n}\nbody {\n  background-color: #fff;\n  background-attachment: fixed;\n}\nul,\nol {\n  list-style: none;\n}\na {\n  color: #3d9cff;\n  text-decoration: none;\n}\na text-decoration none {\n  transition: all 0.5s;\n  -moz-transition: all 0.5s;\n  -webkit-transition: all 0.5s;\n  -o-transition: all 0.5s;\n  cursor: pointer;\n}\na:hover {\n  text-decoration: underline;\n  outline: 0;\n  color: #3d9cff;\n}\n.abs {\n  position: absolute;\n}\n.clear:after {\n  content: \".\";\n  display: block;\n  height: 0;\n  clear: both;\n  visibility: hidden;\n}\n.clear {\n  zoom: 1;\n}\nbutton {\n  border: none;\n}\nhtml {\n  overflow-x: hidden;\n}\nbody {\n  min-width: 20rem;\n  overflow-x: hidden;\n}\n.border {\n  padding-left: 1rem;\n  padding-right: 1rem;\n}\n#footer {\n  color: #7d7d7d;\n  background-color: #171f26;\n  text-align: center;\n  font-size: 14px;\n  padding: 85px;\n}\n#footer p {\n  padding-top: 5px;\n}\n#footer p a {\n  color: #7d7d7d;\n}\n#mobile-header {\n  display: none;\n}\n#header {\n  background-color: #3d9cff;\n  height: 32px;\n  padding: 6px 20px;\n  position: relative;\n  z-index: 999;\n}\n#nav {\n  list-style-type: none;\n  margin: 0;\n  padding: 0;\n  position: absolute;\n  right: 30px;\n  top: 6px;\n  height: 32px;\n  line-height: 32px;\n}\n#nav .break {\n  display: none;\n}\n#nav li {\n  display: inline-block;\n  position: relative;\n  margin: 0 0.6em;\n  color: #fff;\n}\n#nav li a {\n  color: #fff;\n}\n#logo {\n  display: inline-block;\n  font-size: 1.5em;\n  line-height: 32px;\n  color: #2c3e50;\n  font-family: $logo-font;\n  font-weight: 500;\n}\n#logo img {\n  vertical-align: middle;\n  margin-right: 6px;\n  width: 32px;\n  height: 32px;\n}\n.search-query {\n  height: 26px;\n  line-height: 30px;\n  padding: 0 15px 0 30px;\n  margin-bottom: 3px;\n  border: 1px solid #fff;\n  color: #2c3e50;\n  outline: none;\n  border-radius: 15px;\n  margin-right: 5px;\n  transition: 0.2s ease;\n  background: url(\"../images/search.png\") 8px 4px no-repeat;\n  background-size: 20px;\n  vertical-align: middle !important;\n}\n.search-query:focus {\n  background: #fff url(\"../images/search.focus.png\") 8px 4px no-repeat;\n  background-size: 20px;\n}\n@media screen and (max-width: 899px) {\n  #mobile-header {\n    position: relative;\n    padding: 6px 20px;\n    height: 32px;\n    display: block;\n    background-color: #3d9cff;\n  }\n  #mobile-header #github {\n    display: block;\n    float: right;\n  }\n  #mobile-header #github img {\n    width: 32px;\n    height: 32px;\n  }\n  #mobile-header #mobile-nav-toggle {\n    padding-top: 4px;\n    float: left;\n  }\n  #mobile-header #mobile-nav-toggle .mobile-nav-toggle-bar {\n    border-bottom: 2px solid #fff;\n    display: block;\n    width: 25px;\n    height: 2px;\n    margin-bottom: 4px;\n  }\n  #header {\n    display: none;\n  }\n}\n#index-body {\n  background: #3d9cff;\n  height: 325px;\n  text-align: center;\n}\n#index-body h2 {\n  color: #fff;\n  padding: 40px 40px;\n  line-height: 50px;\n  font-size: 24px;\n  margin-bottom: 30px;\n}\n#index-body #get-start {\n  border: 1px solid #fff;\n  padding: 12px 40px;\n  color: #fff;\n}\n#index-body #get-start:hover {\n  background-color: #fff;\n  color: #3d9cff;\n}\n@media screen and (max-width: 699px) {\n  #index-content {\n    padding: 60px 40px 40px 40px;\n    text-align: center;\n  }\n  #index-content .intro-feature {\n    height: 135px;\n    padding-bottom: 60px;\n    text-align: center;\n  }\n  #index-content .intro-feature img {\n    width: 45px;\n    height: 45px;\n  }\n  #index-content .intro-feature h3 {\n    color: #3d9cff;\n    font-size: 20px;\n    padding-bottom: 20px;\n  }\n  #index-content .intro-feature p {\n    text-align: center;\n    font-size: 14px;\n  }\n}\n@media screen and (min-width: 700px) {\n  #index-body {\n    height: 500px;\n  }\n  #index-body h2 {\n    padding: 120px 80px 80px 80px;\n    font-size: 36px;\n  }\n  #index-content {\n    padding: 60px 40px 40px 40px;\n    text-align: center;\n  }\n  #index-content li {\n    width: 50%;\n    float: left;\n  }\n  #index-content li .intro-feature {\n    text-align: center;\n    height: 135px;\n    padding-bottom: 60px;\n  }\n  #index-content li .intro-feature img {\n    width: 45px;\n    height: 45px;\n  }\n  #index-content li .intro-feature h3 {\n    color: #3d9cff;\n    font-size: 24px;\n  }\n  #index-content li .intro-feature p {\n    text-align: center;\n    font-size: 15px;\n  }\n  #index-content ul {\n    margin: 0 auto;\n    max-width: 1150px;\n  }\n}\n"
  },
  {
    "path": "docs/public/css/page.css",
    "content": "body,\nfooter,\nheader,\nh1,\nh2,\nh3,\nh4,\nh5,\nh6,\nhr,\np,\nblockquote,\ndl,\ndt,\ndd,\nul,\nol,\nli,\nform,\nfieldset,\nlegend,\nbutton,\ninput,\ntextarea,\nth,\ntd {\n  margin: 0;\n  padding: 0;\n}\ntext-align center {\n  -webkit-text-size-adjust: none;\n  color: #3d9cff;\n}\nbody,\nbutton,\ninput,\nselect,\ntextarea,\nol,\np,\nblockquote,\ndl,\ndt,\ndd,\nul,\nli,\nform,\nfieldset,\nlegend,\nth,\ntd {\n  outline: none;\n  font: 1em \"Helvetica Neue\", \"Helvetica\", \"Lucida Grande\", \"Arial\", \"Hiragino Sans GB\", \"Microsoft Yahei\", \"WenQuanYi Micro Hei\", \"sans-serif\", arial, sans-serif;\n  text-align: left;\n  color: #3d9cff;\n}\nbody {\n  background-color: #fff;\n  background-attachment: fixed;\n}\nul,\nol {\n  list-style: none;\n}\na {\n  color: #3d9cff;\n  text-decoration: none;\n}\na text-decoration none {\n  transition: all 0.5s;\n  -moz-transition: all 0.5s;\n  -webkit-transition: all 0.5s;\n  -o-transition: all 0.5s;\n  cursor: pointer;\n}\na:hover {\n  text-decoration: underline;\n  outline: 0;\n  color: #3d9cff;\n}\n.abs {\n  position: absolute;\n}\n.clear:after {\n  content: \".\";\n  display: block;\n  height: 0;\n  clear: both;\n  visibility: hidden;\n}\n.clear {\n  zoom: 1;\n}\nbutton {\n  border: none;\n}\nhtml {\n  overflow-x: hidden;\n}\nbody {\n  min-width: 20rem;\n  overflow-x: hidden;\n}\n.border {\n  padding-left: 1rem;\n  padding-right: 1rem;\n}\n.sidebar ul {\n  padding-bottom: 0.9375rem;\n}\n.sidebar ul h3 {\n  color: #525252;\n  font-size: 1.125rem;\n  padding-bottom: 0.625rem;\n  margin-bottom: 0.625rem;\n  padding-top: 1.25rem;\n  font-weight: normal;\n}\n.sidebar ul li {\n  font-size: 0.875rem;\n  padding-bottom: 0.5rem;\n  text-indent: 1em;\n}\n.sidebar ul li p {\n  padding-left: 1rem;\n}\n.sub-nav ul h3 {\n  color: #525252;\n  font-weight: 700;\n  margin-bottom: 1rem;\n  padding-left: 0.5rem;\n}\n.sub-nav ul li {\n  margin-bottom: 0.25rem;\n  padding-left: 0.5rem;\n}\n.sub-nav ul li p {\n  padding-left: 1rem;\n}\n.sub-nav ul li.select {\n  border-left: 0.125rem #f4645f solid;\n  padding-left: 0.375rem;\n}\narticle {\n  color: #525252;\n  text-align: left;\n}\narticle h1,\narticle h2 {\n  font-size: 2.25rem;\n  font-weight: 500;\n  margin-bottom: 3rem;\n}\narticle h3,\narticle h4,\narticle h5 {\n  font-weight: 400;\n}\narticle h3 {\n  font-size: 1.375rem;\n  margin-top: 3.125rem;\n  margin-bottom: 1.875rem;\n}\narticle h3:before {\n  content: \"#\";\n  margin-right: 0.25rem;\n  color: #3d9cff;\n  opacity: 0.3;\n}\narticle h4 {\n  font-size: 1rem;\n  margin-top: 2.125rem;\n  margin-bottom: 1.25rem;\n}\narticle h5 {\n  font-size: 1rem;\n  margin-left: 1.25rem;\n  margin-top: 2.125rem;\n}\narticle p {\n  font-size: 1rem;\n  margin-bottom: 1.25rem;\n  margin-top: 0.625rem;\n  line-height: 1.8;\n  color: #525252;\n}\narticle ul {\n  padding-left: 2rem;\n  position: inherit;\n  list-style: disc;\n  font-size: 0.9rem;\n}\narticle ul li {\n  padding-top: 0.25rem;\n  color: #525252;\n}\narticle table {\n  width: 100%;\n  border-collapse: collapse;\n  border: 0;\n  border-spacing: 0;\n  margin-bottom: 1rem;\n  margin-top: 1rem;\n}\narticle table tr:nth-child(even) td {\n  background-color: #f7f7f7;\n}\narticle table .title-row {\n  background-color: #ededed;\n}\narticle table tr th,\narticle table tr td {\n  padding: 0.5rem 1rem 0.5rem 1rem;\n  color: #525252;\n}\narticle table tr th {\n  background-color: #e8e8e8;\n  font-weight: bold;\n  font-size: 0.85rem;\n}\narticle table tr td {\n  font-size: 0.75rem;\n}\narticle blockquote {\n  padding: 12px 24px 12px 30px;\n  margin: 2em 0;\n  border-left: 4px solid #3d9cff;\n  background-color: #f8f8f8;\n  position: relative;\n}\narticle blockquote p {\n  padding: 0;\n  margin: 0;\n}\narticle blockquote:before {\n  position: absolute;\n  top: 14px;\n  left: -12px;\n  background-color: #3d9cff;\n  color: #fff;\n  content: \"!\";\n  width: 20px;\n  height: 20px;\n  border-radius: 100%;\n  text-align: center;\n  line-height: 20px;\n  font-weight: bold;\n  font-family: 'Roboto Mono', Monaco, courier, monospace;\n  font-size: 14px;\n}\narticle blockquote code {\n  background-color: #efefef;\n}\narticle blockquote em {\n  color: $medium;\n}\narticle code {\n  border-radius: 3px;\n  background-color: #f0f2f1;\n  font-size: 0.75rem;\n  line-height: 1.8;\n  padding: 1px 5px 1px 5px;\n  color: #3d9cff;\n  font-family: source-code-pro, monospace;\n  margin-left: 5px;\n  margin-right: 5px;\n  text-shadow: 0px 1px #fff;\n}\narticle p.tip {\n  background-color: #3d9cff;\n  border-radius: 3px;\n  color: #fff;\n  padding: 10px 15px 10px 15px;\n  margin-bottom: 50px;\n}\narticle p.tip a {\n  color: #fff;\n}\narticle p.tip p {\n  color: #fff;\n  margin: 0 auto;\n}\narticle p.tip p a {\n  text-decoration: underline;\n  color: #fff;\n}\narticle p.tip p a:hover {\n  color: #fcd8d6;\n}\narticle ol {\n  list-style-type: none;\n  counter-reset: sectioncounter;\n  padding-left: 1rem;\n  position: inherit;\n  font-size: 0.9rem;\n}\narticle ol li {\n  color: #525252;\n  padding-top: 0.25rem;\n}\narticle ol li:before {\n  content: counter(sectioncounter) \". \";\n  counter-increment: sectioncounter;\n}\narticle hr {\n  height: 1px;\n  border: none;\n  border-top: 1px dashed #dcdcdc;\n}\narticle figure {\n  margin: 1.2rem 0;\n}\narticle .highlight {\n  overflow-x: auto;\n  position: relative;\n  padding: 0;\n  background-color: #f8f8f8;\n  padding: 0.8rem 0.8rem 0.4rem;\n  line-height: 1.1rem;\n  border-radius: $radius;\n  font-size: 0.85rem;\n}\narticle .highlight table,\narticle .highlight tr,\narticle .highlight td {\n  width: 100%;\n  border-collapse: collapse;\n  padding: 0;\n  margin: 0;\n}\narticle .highlight .gutter {\n  width: 1.5rem;\n}\narticle .highlight .code {\n  color: #525252;\n  font-size: 0.825rem;\n}\narticle .highlight .code pre {\n  padding: 1.2rem 1.4rem;\n  line-height: 1.5rem;\n  margin: 0;\n}\narticle .highlight .code .line {\n  min-height: 1.5rem;\n}\narticle .highlight.html .code:after,\narticle .highlight.js .code:after,\narticle .highlight.bash .code:after,\narticle .highlight.css .code:after,\narticle .highlight.csharp .code:after,\narticle .highlight.lua .code:after {\n  position: absolute;\n  top: 0;\n  right: 0;\n  color: #ccc;\n  text-align: right;\n  font-size: 0.75rem;\n  padding: 5px 10px 0;\n  line-height: 15px;\n  height: 15px;\n  font-weight: 600;\n}\narticle .highlight.html .code:after {\n  content: 'HTML';\n}\narticle .highlight.csharp .code:after {\n  content: 'C#';\n}\narticle .highlight.lua .code:after {\n  content: 'Lua';\n}\narticle .highlight.js .code:after {\n  content: 'JS';\n}\narticle .highlight.bash .code:after {\n  content: 'Shell';\n}\narticle .highlight.css .code:after {\n  content: 'CSS';\n}\narticle .gutter pre {\n  color: #999;\n}\narticle pre {\n  color: #525252;\n}\narticle pre .function .keyword,\narticle pre .constant {\n  color: #3d9cff;\n}\narticle pre .keyword,\narticle pre .attribute {\n  color: #3d9cff;\n}\narticle pre .number,\narticle pre .literal {\n  color: #ae81ff;\n}\narticle pre .tag,\narticle pre .tag .title,\narticle pre .change,\narticle pre .winutils,\narticle pre .flow,\narticle pre .lisp .title,\narticle pre .clojure .built_in,\narticle pre .nginx .title,\narticle pre .tex .special {\n  color: #2973b7;\n}\narticle pre .class .title {\n  color: #fff;\n}\narticle pre .symbol,\narticle pre .symbol .string,\narticle pre .value,\narticle pre .regexp {\n  color: #3d9cff;\n}\narticle pre .title {\n  color: #2973b7;\n}\narticle pre .tag .value,\narticle pre .string,\narticle pre .subst,\narticle pre .haskell .type,\narticle pre .preprocessor,\narticle pre .ruby .class .parent,\narticle pre .built_in,\narticle pre .sql .aggregate,\narticle pre .django .template_tag,\narticle pre .django .variable,\narticle pre .smalltalk .class,\narticle pre .javadoc,\narticle pre .django .filter .argument,\narticle pre .smalltalk .localvars,\narticle pre .smalltalk .array,\narticle pre .attr_selector,\narticle pre .pseudo,\narticle pre .addition,\narticle pre .stream,\narticle pre .envvar,\narticle pre .apache .tag,\narticle pre .apache .cbracket,\narticle pre .tex .command,\narticle pre .prompt {\n  color: #3d9cff;\n}\narticle pre .comment,\narticle pre .java .annotation,\narticle pre .python .decorator,\narticle pre .template_comment,\narticle pre .pi,\narticle pre .doctype,\narticle pre .deletion,\narticle pre .shebang,\narticle pre .apache .sqbracket,\narticle pre .tex .formula {\n  color: #b3b3b3;\n}\narticle pre .coffeescript .javascript,\narticle pre .javascript .xml,\narticle pre .tex .formula,\narticle pre .xml .javascript,\narticle pre .xml .vbscript,\narticle pre .xml .css,\narticle pre .xml .cdata {\n  opacity: 0.5;\n}\n@media screen and (min-width: 960px) {\n  article .highlight {\n    font-size: 1.125rem;\n  }\n}\nnav {\n  height: 5rem;\n  background-color: #fafafa;\n  position: absolute;\n  width: 100%;\n  z-index: 9999;\n}\nnav img {\n  width: 140px;\n  height: 42px;\n  float: left;\n  position: absolute;\n  margin-top: 1rem;\n}\nnav .nav-link li {\n  float: right;\n  padding: 1.75rem 1rem;\n}\nnav .nav-link li a {\n  color: #3d9cff;\n}\nnav button {\n  float: right;\n  margin-top: 1rem;\n  padding: 0.75rem 1.25rem;\n  background-color: #3d9cff;\n  color: #fff;\n  border-radius: 5px;\n  margin-top: 0.4rem;\n}\n.container {\n  margin: 0 auto;\n  max-width: 80rem;\n  padding: 0rem 10rem 3rem 15rem;\n  position: relative;\n}\n.sidebar {\n  padding: 2.187rem;\n  padding-top: 7rem;\n  width: 11.25rem;\n  margin-left: -15rem;\n  float: left;\n}\narticle {\n  padding: 7.75rem 7.75rem 0rem 3.25rem;\n  margin-left: 1.25rem;\n}\n.sub-nav {\n  position: absolute;\n  top: 15rem;\n  right: 0;\n  width: 10rem;\n}\n.sub-nav dl dt {\n  color: #525252;\n  font-weight: 700;\n  margin-bottom: 1rem;\n  padding-left: 0.5rem;\n}\n.sub-nav dl dd {\n  margin-bottom: 0.25rem;\n  padding-left: 0.5rem;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.sub-nav dl dd.select {\n  border-left: 0.125rem #f4645f solid;\n  padding-left: 0.375rem;\n}\n.footer {\n  text-align: center;\n  margin-top: 2.75rem;\n  color: #c8c8c8;\n  font-size: 0.75rem;\n}\nfooter {\n  background-color: #343434;\n  height: 3.125rem;\n  padding: 1.875rem;\n}\nfooter p {\n  text-align: center;\n  color: #aeaeae;\n  font-size: 0.8125rem;\n  line-height: 1.8;\n}\n.disable {\n  color: #afafaf;\n}\n.disable:hover {\n  color: #afafaf;\n  text-decoration: none;\n}\n@media screen and (min-width: 960px) {\n  .hiden-in-pc {\n    display: none;\n  }\n  .hiden-in-phone {\n    display: inline;\n  }\n  nav button {\n    margin-top: 1rem;\n  }\n  nav button:hover {\n    background-color: #dc504b;\n  }\n  footer {\n    padding: 3.125rem;\n  }\n}\n@media screen and (max-width: 960px) {\n  .hiden-in-pc {\n    display: inline;\n  }\n  .hiden-in-phone {\n    display: none;\n  }\n  nav {\n    height: 3rem;\n    position: fixed;\n  }\n  nav button {\n    margin-top: 0.4rem;\n    padding: 0.35rem 0.75rem;\n  }\n  nav img {\n    width: 110px;\n    height: 30px;\n    margin-top: 0.5rem;\n  }\n  .container {\n    margin: 0;\n    padding: 0rem 0rem 3rem 0rem;\n  }\n  .sidebar {\n    display: none;\n  }\n  article {\n    padding: 5.5rem 1.75rem 0.2rem 0.2rem;\n    min-height: 35rem;\n  }\n}\n"
  },
  {
    "path": "docs/public/index.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>XLua — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/index.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <script>window.location.href='v1/guide/index.html';</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/js/jquery.js",
    "content": "/*! jQuery v3.2.1 | (c) JS Foundation and other contributors | jquery.org/license */\n!function(a,b){\"use strict\";\"object\"==typeof module&&\"object\"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error(\"jQuery requires a window with a document\");return b(a)}:b(a)}(\"undefined\"!=typeof window?window:this,function(a,b){\"use strict\";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement(\"script\");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q=\"3.2.1\",r=function(a,b){return new r.fn.init(a,b)},s=/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null==a?f.call(this):a<0?this[a+this.length]:this[a]},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.prevObject=this,b},each:function(a){return r.each(this,a)},map:function(a){return this.pushStack(r.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(f.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(a<0?b:0);return this.pushStack(c>=0&&c<b?[this[c]]:[])},end:function(){return this.prevObject||this.constructor()},push:h,sort:c.sort,splice:c.splice},r.extend=r.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for(\"boolean\"==typeof g&&(j=g,g=arguments[h]||{},h++),\"object\"==typeof g||r.isFunction(g)||(g={}),h===i&&(g=this,h--);h<i;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(r.isPlainObject(d)||(e=Array.isArray(d)))?(e?(e=!1,f=c&&Array.isArray(c)?c:[]):f=c&&r.isPlainObject(c)?c:{},g[b]=r.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},r.extend({expando:\"jQuery\"+(q+Math.random()).replace(/\\D/g,\"\"),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return\"function\"===r.type(a)},isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){var b=r.type(a);return(\"number\"===b||\"string\"===b)&&!isNaN(a-parseFloat(a))},isPlainObject:function(a){var b,c;return!(!a||\"[object Object]\"!==k.call(a))&&(!(b=e(a))||(c=l.call(b,\"constructor\")&&b.constructor,\"function\"==typeof c&&m.call(c)===n))},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+\"\":\"object\"==typeof a||\"function\"==typeof a?j[k.call(a)]||\"object\":typeof a},globalEval:function(a){p(a)},camelCase:function(a){return a.replace(t,\"ms-\").replace(u,v)},each:function(a,b){var c,d=0;if(w(a)){for(c=a.length;d<c;d++)if(b.call(a[d],d,a[d])===!1)break}else for(d in a)if(b.call(a[d],d,a[d])===!1)break;return a},trim:function(a){return null==a?\"\":(a+\"\").replace(s,\"\")},makeArray:function(a,b){var c=b||[];return null!=a&&(w(Object(a))?r.merge(c,\"string\"==typeof a?[a]:a):h.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:i.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;d<c;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;f<g;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,e,f=0,h=[];if(w(a))for(d=a.length;f<d;f++)e=b(a[f],f,c),null!=e&&h.push(e);else for(f in a)e=b(a[f],f,c),null!=e&&h.push(e);return g.apply([],h)},guid:1,proxy:function(a,b){var c,d,e;if(\"string\"==typeof b&&(c=a[b],b=a,a=c),r.isFunction(a))return d=f.call(arguments,2),e=function(){return a.apply(b||this,d.concat(f.call(arguments)))},e.guid=a.guid=a.guid||r.guid++,e},now:Date.now,support:o}),\"function\"==typeof Symbol&&(r.fn[Symbol.iterator]=c[Symbol.iterator]),r.each(\"Boolean Number String Function Array Date RegExp Object Error Symbol\".split(\" \"),function(a,b){j[\"[object \"+b+\"]\"]=b.toLowerCase()});function w(a){var b=!!a&&\"length\"in a&&a.length,c=r.type(a);return\"function\"!==c&&!r.isWindow(a)&&(\"array\"===c||0===b||\"number\"==typeof b&&b>0&&b-1 in a)}var x=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u=\"sizzle\"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c]===b)return c;return-1},J=\"checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped\",K=\"[\\\\x20\\\\t\\\\r\\\\n\\\\f]\",L=\"(?:\\\\\\\\.|[\\\\w-]|[^\\0-\\\\xa0])+\",M=\"\\\\[\"+K+\"*(\"+L+\")(?:\"+K+\"*([*^$|!~]?=)\"+K+\"*(?:'((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\"|(\"+L+\"))|)\"+K+\"*\\\\]\",N=\":(\"+L+\")(?:\\\\((('((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\")|((?:\\\\\\\\.|[^\\\\\\\\()[\\\\]]|\"+M+\")*)|.*)\\\\)|)\",O=new RegExp(K+\"+\",\"g\"),P=new RegExp(\"^\"+K+\"+|((?:^|[^\\\\\\\\])(?:\\\\\\\\.)*)\"+K+\"+$\",\"g\"),Q=new RegExp(\"^\"+K+\"*,\"+K+\"*\"),R=new RegExp(\"^\"+K+\"*([>+~]|\"+K+\")\"+K+\"*\"),S=new RegExp(\"=\"+K+\"*([^\\\\]'\\\"]*?)\"+K+\"*\\\\]\",\"g\"),T=new RegExp(N),U=new RegExp(\"^\"+L+\"$\"),V={ID:new RegExp(\"^#(\"+L+\")\"),CLASS:new RegExp(\"^\\\\.(\"+L+\")\"),TAG:new RegExp(\"^(\"+L+\"|[*])\"),ATTR:new RegExp(\"^\"+M),PSEUDO:new RegExp(\"^\"+N),CHILD:new RegExp(\"^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\\\(\"+K+\"*(even|odd|(([+-]|)(\\\\d*)n|)\"+K+\"*(?:([+-]|)\"+K+\"*(\\\\d+)|))\"+K+\"*\\\\)|)\",\"i\"),bool:new RegExp(\"^(?:\"+J+\")$\",\"i\"),needsContext:new RegExp(\"^\"+K+\"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\\\(\"+K+\"*((?:-\\\\d)?\\\\d*)\"+K+\"*\\\\)|)(?=[^-]|$)\",\"i\")},W=/^(?:input|select|textarea|button)$/i,X=/^h\\d$/i,Y=/^[^{]+\\{\\s*\\[native \\w/,Z=/^(?:#([\\w-]+)|(\\w+)|\\.([\\w-]+))$/,$=/[+~]/,_=new RegExp(\"\\\\\\\\([\\\\da-f]{1,6}\"+K+\"?|(\"+K+\")|.)\",\"ig\"),aa=function(a,b,c){var d=\"0x\"+b-65536;return d!==d||c?b:d<0?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ba=/([\\0-\\x1f\\x7f]|^-?\\d)|^-$|[^\\0-\\x1f\\x7f-\\uFFFF\\w-]/g,ca=function(a,b){return b?\"\\0\"===a?\"\\ufffd\":a.slice(0,-1)+\"\\\\\"+a.charCodeAt(a.length-1).toString(16)+\" \":\"\\\\\"+a},da=function(){m()},ea=ta(function(a){return a.disabled===!0&&(\"form\"in a||\"label\"in a)},{dir:\"parentNode\",next:\"legend\"});try{G.apply(D=H.call(v.childNodes),v.childNodes),D[v.childNodes.length].nodeType}catch(fa){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s=b&&b.ownerDocument,w=b?b.nodeType:9;if(d=d||[],\"string\"!=typeof a||!a||1!==w&&9!==w&&11!==w)return d;if(!e&&((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,p)){if(11!==w&&(l=Z.exec(a)))if(f=l[1]){if(9===w){if(!(j=b.getElementById(f)))return d;if(j.id===f)return d.push(j),d}else if(s&&(j=s.getElementById(f))&&t(b,j)&&j.id===f)return d.push(j),d}else{if(l[2])return G.apply(d,b.getElementsByTagName(a)),d;if((f=l[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(f)),d}if(c.qsa&&!A[a+\" \"]&&(!q||!q.test(a))){if(1!==w)s=b,r=a;else if(\"object\"!==b.nodeName.toLowerCase()){(k=b.getAttribute(\"id\"))?k=k.replace(ba,ca):b.setAttribute(\"id\",k=u),o=g(a),h=o.length;while(h--)o[h]=\"#\"+k+\" \"+sa(o[h]);r=o.join(\",\"),s=$.test(a)&&qa(b.parentNode)||b}if(r)try{return G.apply(d,s.querySelectorAll(r)),d}catch(x){}finally{k===u&&b.removeAttribute(\"id\")}}}return i(a.replace(P,\"$1\"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+\" \")>d.cacheLength&&delete b[a.shift()],b[c+\" \"]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement(\"fieldset\");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split(\"|\"),e=c.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&a.sourceIndex-b.sourceIndex;if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return\"input\"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return(\"input\"===c||\"button\"===c)&&b.type===a}}function oa(a){return function(b){return\"form\"in b?b.parentNode&&b.disabled===!1?\"label\"in b?\"label\"in b.parentNode?b.parentNode.disabled===a:b.disabled===a:b.isDisabled===a||b.isDisabled!==!a&&ea(b)===a:b.disabled===a:\"label\"in b&&b.disabled===a}}function pa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function qa(a){return a&&\"undefined\"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return!!b&&\"HTML\"!==b.nodeName},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=n.documentElement,p=!f(n),v!==n&&(e=n.defaultView)&&e.top!==e&&(e.addEventListener?e.addEventListener(\"unload\",da,!1):e.attachEvent&&e.attachEvent(\"onunload\",da)),c.attributes=ja(function(a){return a.className=\"i\",!a.getAttribute(\"className\")}),c.getElementsByTagName=ja(function(a){return a.appendChild(n.createComment(\"\")),!a.getElementsByTagName(\"*\").length}),c.getElementsByClassName=Y.test(n.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!n.getElementsByName||!n.getElementsByName(u).length}),c.getById?(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){return a.getAttribute(\"id\")===b}},d.find.ID=function(a,b){if(\"undefined\"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c?[c]:[]}}):(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){var c=\"undefined\"!=typeof a.getAttributeNode&&a.getAttributeNode(\"id\");return c&&c.value===b}},d.find.ID=function(a,b){if(\"undefined\"!=typeof b.getElementById&&p){var c,d,e,f=b.getElementById(a);if(f){if(c=f.getAttributeNode(\"id\"),c&&c.value===a)return[f];e=b.getElementsByName(a),d=0;while(f=e[d++])if(c=f.getAttributeNode(\"id\"),c&&c.value===a)return[f]}return[]}}),d.find.TAG=c.getElementsByTagName?function(a,b){return\"undefined\"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if(\"*\"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){if(\"undefined\"!=typeof b.getElementsByClassName&&p)return b.getElementsByClassName(a)},r=[],q=[],(c.qsa=Y.test(n.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML=\"<a id='\"+u+\"'></a><select id='\"+u+\"-\\r\\\\' msallowcapture=''><option selected=''></option></select>\",a.querySelectorAll(\"[msallowcapture^='']\").length&&q.push(\"[*^$]=\"+K+\"*(?:''|\\\"\\\")\"),a.querySelectorAll(\"[selected]\").length||q.push(\"\\\\[\"+K+\"*(?:value|\"+J+\")\"),a.querySelectorAll(\"[id~=\"+u+\"-]\").length||q.push(\"~=\"),a.querySelectorAll(\":checked\").length||q.push(\":checked\"),a.querySelectorAll(\"a#\"+u+\"+*\").length||q.push(\".#.+[+~]\")}),ja(function(a){a.innerHTML=\"<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>\";var b=n.createElement(\"input\");b.setAttribute(\"type\",\"hidden\"),a.appendChild(b).setAttribute(\"name\",\"D\"),a.querySelectorAll(\"[name=d]\").length&&q.push(\"name\"+K+\"*[*^$|!~]?=\"),2!==a.querySelectorAll(\":enabled\").length&&q.push(\":enabled\",\":disabled\"),o.appendChild(a).disabled=!0,2!==a.querySelectorAll(\":disabled\").length&&q.push(\":enabled\",\":disabled\"),a.querySelectorAll(\"*,:x\"),q.push(\",.*:\")})),(c.matchesSelector=Y.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,\"*\"),s.call(a,\"[s!='']:x\"),r.push(\"!=\",N)}),q=q.length&&new RegExp(q.join(\"|\")),r=r.length&&new RegExp(r.join(\"|\")),b=Y.test(o.compareDocumentPosition),t=b||Y.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===n||a.ownerDocument===v&&t(v,a)?-1:b===n||b.ownerDocument===v&&t(v,b)?1:k?I(k,a)-I(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,g=[a],h=[b];if(!e||!f)return a===n?-1:b===n?1:e?-1:f?1:k?I(k,a)-I(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)g.unshift(c);c=b;while(c=c.parentNode)h.unshift(c);while(g[d]===h[d])d++;return d?la(g[d],h[d]):g[d]===v?-1:h[d]===v?1:0},n):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(S,\"='$1']\"),c.matchesSelector&&p&&!A[b+\" \"]&&(!r||!r.test(b))&&(!q||!q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.escape=function(a){return(a+\"\").replace(ba,ca)},ga.error=function(a){throw new Error(\"Syntax error, unrecognized expression: \"+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c=\"\",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if(\"string\"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:V,attrHandle:{},find:{},relative:{\">\":{dir:\"parentNode\",first:!0},\" \":{dir:\"parentNode\"},\"+\":{dir:\"previousSibling\",first:!0},\"~\":{dir:\"previousSibling\"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(_,aa),a[3]=(a[3]||a[4]||a[5]||\"\").replace(_,aa),\"~=\"===a[2]&&(a[3]=\" \"+a[3]+\" \"),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),\"nth\"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*(\"even\"===a[3]||\"odd\"===a[3])),a[5]=+(a[7]+a[8]||\"odd\"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return V.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||\"\":c&&T.test(c)&&(b=g(c,!0))&&(b=c.indexOf(\")\",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(_,aa).toLowerCase();return\"*\"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+\" \"];return b||(b=new RegExp(\"(^|\"+K+\")\"+a+\"(\"+K+\"|$)\"))&&y(a,function(a){return b.test(\"string\"==typeof a.className&&a.className||\"undefined\"!=typeof a.getAttribute&&a.getAttribute(\"class\")||\"\")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?\"!=\"===b:!b||(e+=\"\",\"=\"===b?e===c:\"!=\"===b?e!==c:\"^=\"===b?c&&0===e.indexOf(c):\"*=\"===b?c&&e.indexOf(c)>-1:\"$=\"===b?c&&e.slice(-c.length)===c:\"~=\"===b?(\" \"+e.replace(O,\" \")+\" \").indexOf(c)>-1:\"|=\"===b&&(e===c||e.slice(0,c.length+1)===c+\"-\"))}},CHILD:function(a,b,c,d,e){var f=\"nth\"!==a.slice(0,3),g=\"last\"!==a.slice(-4),h=\"of-type\"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?\"nextSibling\":\"previousSibling\",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h,t=!1;if(q){if(f){while(p){m=b;while(m=m[p])if(h?m.nodeName.toLowerCase()===r:1===m.nodeType)return!1;o=p=\"only\"===a&&!o&&\"nextSibling\"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){m=q,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n&&j[2],m=n&&q.childNodes[n];while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if(1===m.nodeType&&++t&&m===b){k[a]=[w,n,t];break}}else if(s&&(m=b,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n),t===!1)while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if((h?m.nodeName.toLowerCase()===r:1===m.nodeType)&&++t&&(s&&(l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),k[a]=[w,t]),m===b))break;return t-=e,t===d||t%d===0&&t/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error(\"unsupported pseudo: \"+a);return e[u]?e(b):e.length>1?(c=[a,a,\"\",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(P,\"$1\"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(_,aa),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return U.test(a||\"\")||ga.error(\"unsupported lang: \"+a),a=a.replace(_,aa).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute(\"xml:lang\")||b.getAttribute(\"lang\"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+\"-\");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:oa(!1),disabled:oa(!0),checked:function(a){var b=a.nodeName.toLowerCase();return\"input\"===b&&!!a.checked||\"option\"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return\"input\"===b&&\"button\"===a.type||\"button\"===b},text:function(a){var b;return\"input\"===a.nodeName.toLowerCase()&&\"text\"===a.type&&(null==(b=a.getAttribute(\"type\"))||\"text\"===b.toLowerCase())},first:pa(function(){return[0]}),last:pa(function(a,b){return[b-1]}),eq:pa(function(a,b,c){return[c<0?c+b:c]}),even:pa(function(a,b){for(var c=0;c<b;c+=2)a.push(c);return a}),odd:pa(function(a,b){for(var c=1;c<b;c+=2)a.push(c);return a}),lt:pa(function(a,b,c){for(var d=c<0?c+b:c;--d>=0;)a.push(d);return a}),gt:pa(function(a,b,c){for(var d=c<0?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=ma(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=na(b);function ra(){}ra.prototype=d.filters=d.pseudos,d.setFilters=new ra,g=ga.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+\" \"];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){c&&!(e=Q.exec(h))||(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=R.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(P,\" \")}),h=h.slice(c.length));for(g in d.filter)!(e=V[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?ga.error(a):z(a,i).slice(0)};function sa(a){for(var b=0,c=a.length,d=\"\";b<c;b++)d+=a[b].value;return d}function ta(a,b,c){var d=b.dir,e=b.next,f=e||d,g=c&&\"parentNode\"===f,h=x++;return b.first?function(b,c,e){while(b=b[d])if(1===b.nodeType||g)return a(b,c,e);return!1}:function(b,c,i){var j,k,l,m=[w,h];if(i){while(b=b[d])if((1===b.nodeType||g)&&a(b,c,i))return!0}else while(b=b[d])if(1===b.nodeType||g)if(l=b[u]||(b[u]={}),k=l[b.uniqueID]||(l[b.uniqueID]={}),e&&e===b.nodeName.toLowerCase())b=b[d]||b;else{if((j=k[f])&&j[0]===w&&j[1]===h)return m[2]=j[2];if(k[f]=m,m[2]=a(b,c,i))return!0}return!1}}function ua(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function va(a,b,c){for(var d=0,e=b.length;d<e;d++)ga(a,b[d],c);return c}function wa(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;h<i;h++)(f=a[h])&&(c&&!c(f,d,e)||(g.push(f),j&&b.push(h)));return g}function xa(a,b,c,d,e,f){return d&&!d[u]&&(d=xa(d)),e&&!e[u]&&(e=xa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||va(b||\"*\",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:wa(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=wa(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?I(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=wa(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ya(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[\" \"],i=g?1:0,k=ta(function(a){return a===b},h,!0),l=ta(function(a){return I(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];i<f;i++)if(c=d.relative[a[i].type])m=[ta(ua(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;e<f;e++)if(d.relative[a[e].type])break;return xa(i>1&&ua(m),i>1&&sa(a.slice(0,i-1).concat({value:\" \"===a[i-2].type?\"*\":\"\"})).replace(P,\"$1\"),c,i<e&&ya(a.slice(i,e)),e<f&&ya(a=a.slice(e)),e<f&&sa(a))}m.push(c)}return ua(m)}function za(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,o,q,r=0,s=\"0\",t=f&&[],u=[],v=j,x=f||e&&d.find.TAG(\"*\",k),y=w+=null==v?1:Math.random()||.1,z=x.length;for(k&&(j=g===n||g||k);s!==z&&null!=(l=x[s]);s++){if(e&&l){o=0,g||l.ownerDocument===n||(m(l),h=!p);while(q=a[o++])if(q(l,g||n,h)){i.push(l);break}k&&(w=y)}c&&((l=!q&&l)&&r--,f&&t.push(l))}if(r+=s,c&&s!==r){o=0;while(q=b[o++])q(t,u,g,h);if(f){if(r>0)while(s--)t[s]||u[s]||(u[s]=E.call(i));u=wa(u)}G.apply(i,u),k&&!f&&u.length>0&&r+b.length>1&&ga.uniqueSort(i)}return k&&(w=y,j=v),t};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+\" \"];if(!f){b||(b=g(a)),c=b.length;while(c--)f=ya(b[c]),f[u]?d.push(f):e.push(f);f=A(a,za(e,d)),f.selector=a}return f},i=ga.select=function(a,b,c,e){var f,i,j,k,l,m=\"function\"==typeof a&&a,n=!e&&g(a=m.selector||a);if(c=c||[],1===n.length){if(i=n[0]=n[0].slice(0),i.length>2&&\"ID\"===(j=i[0]).type&&9===b.nodeType&&p&&d.relative[i[1].type]){if(b=(d.find.ID(j.matches[0].replace(_,aa),b)||[])[0],!b)return c;m&&(b=b.parentNode),a=a.slice(i.shift().value.length)}f=V.needsContext.test(a)?0:i.length;while(f--){if(j=i[f],d.relative[k=j.type])break;if((l=d.find[k])&&(e=l(j.matches[0].replace(_,aa),$.test(i[0].type)&&qa(b.parentNode)||b))){if(i.splice(f,1),a=e.length&&sa(i),!a)return G.apply(c,e),c;break}}}return(m||h(a,n))(e,b,!p,c,!b||$.test(a)&&qa(b.parentNode)||b),c},c.sortStable=u.split(\"\").sort(B).join(\"\")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement(\"fieldset\"))}),ja(function(a){return a.innerHTML=\"<a href='#'></a>\",\"#\"===a.firstChild.getAttribute(\"href\")})||ka(\"type|href|height|width\",function(a,b,c){if(!c)return a.getAttribute(b,\"type\"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML=\"<input/>\",a.firstChild.setAttribute(\"value\",\"\"),\"\"===a.firstChild.getAttribute(\"value\")})||ka(\"value\",function(a,b,c){if(!c&&\"input\"===a.nodeName.toLowerCase())return a.defaultValue}),ja(function(a){return null==a.getAttribute(\"disabled\")})||ka(J,function(a,b,c){var d;if(!c)return a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);r.find=x,r.expr=x.selectors,r.expr[\":\"]=r.expr.pseudos,r.uniqueSort=r.unique=x.uniqueSort,r.text=x.getText,r.isXMLDoc=x.isXML,r.contains=x.contains,r.escapeSelector=x.escape;var y=function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&r(a).is(c))break;d.push(a)}return d},z=function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c},A=r.expr.match.needsContext;function B(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()}var C=/^<([a-z][^\\/\\0>:\\x20\\t\\r\\n\\f]*)[\\x20\\t\\r\\n\\f]*\\/?>(?:<\\/\\1>|)$/i,D=/^.[^:#\\[\\.,]*$/;function E(a,b,c){return r.isFunction(b)?r.grep(a,function(a,d){return!!b.call(a,d,a)!==c}):b.nodeType?r.grep(a,function(a){return a===b!==c}):\"string\"!=typeof b?r.grep(a,function(a){return i.call(b,a)>-1!==c}):D.test(b)?r.filter(b,a,c):(b=r.filter(b,a),r.grep(a,function(a){return i.call(b,a)>-1!==c&&1===a.nodeType}))}r.filter=function(a,b,c){var d=b[0];return c&&(a=\":not(\"+a+\")\"),1===b.length&&1===d.nodeType?r.find.matchesSelector(d,a)?[d]:[]:r.find.matches(a,r.grep(b,function(a){return 1===a.nodeType}))},r.fn.extend({find:function(a){var b,c,d=this.length,e=this;if(\"string\"!=typeof a)return this.pushStack(r(a).filter(function(){for(b=0;b<d;b++)if(r.contains(e[b],this))return!0}));for(c=this.pushStack([]),b=0;b<d;b++)r.find(a,e[b],c);return d>1?r.uniqueSort(c):c},filter:function(a){return this.pushStack(E(this,a||[],!1))},not:function(a){return this.pushStack(E(this,a||[],!0))},is:function(a){return!!E(this,\"string\"==typeof a&&A.test(a)?r(a):a||[],!1).length}});var F,G=/^(?:\\s*(<[\\w\\W]+>)[^>]*|#([\\w-]+))$/,H=r.fn.init=function(a,b,c){var e,f;if(!a)return this;if(c=c||F,\"string\"==typeof a){if(e=\"<\"===a[0]&&\">\"===a[a.length-1]&&a.length>=3?[null,a,null]:G.exec(a),!e||!e[1]&&b)return!b||b.jquery?(b||c).find(a):this.constructor(b).find(a);if(e[1]){if(b=b instanceof r?b[0]:b,r.merge(this,r.parseHTML(e[1],b&&b.nodeType?b.ownerDocument||b:d,!0)),C.test(e[1])&&r.isPlainObject(b))for(e in b)r.isFunction(this[e])?this[e](b[e]):this.attr(e,b[e]);return this}return f=d.getElementById(e[2]),f&&(this[0]=f,this.length=1),this}return a.nodeType?(this[0]=a,this.length=1,this):r.isFunction(a)?void 0!==c.ready?c.ready(a):a(r):r.makeArray(a,this)};H.prototype=r.fn,F=r(d);var I=/^(?:parents|prev(?:Until|All))/,J={children:!0,contents:!0,next:!0,prev:!0};r.fn.extend({has:function(a){var b=r(a,this),c=b.length;return this.filter(function(){for(var a=0;a<c;a++)if(r.contains(this,b[a]))return!0})},closest:function(a,b){var c,d=0,e=this.length,f=[],g=\"string\"!=typeof a&&r(a);if(!A.test(a))for(;d<e;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&r.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?r.uniqueSort(f):f)},index:function(a){return a?\"string\"==typeof a?i.call(r(a),this[0]):i.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(r.uniqueSort(r.merge(this.get(),r(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function K(a,b){while((a=a[b])&&1!==a.nodeType);return a}r.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return y(a,\"parentNode\")},parentsUntil:function(a,b,c){return y(a,\"parentNode\",c)},next:function(a){return K(a,\"nextSibling\")},prev:function(a){return K(a,\"previousSibling\")},nextAll:function(a){return y(a,\"nextSibling\")},prevAll:function(a){return y(a,\"previousSibling\")},nextUntil:function(a,b,c){return y(a,\"nextSibling\",c)},prevUntil:function(a,b,c){return y(a,\"previousSibling\",c)},siblings:function(a){return z((a.parentNode||{}).firstChild,a)},children:function(a){return z(a.firstChild)},contents:function(a){return B(a,\"iframe\")?a.contentDocument:(B(a,\"template\")&&(a=a.content||a),r.merge([],a.childNodes))}},function(a,b){r.fn[a]=function(c,d){var e=r.map(this,b,c);return\"Until\"!==a.slice(-5)&&(d=c),d&&\"string\"==typeof d&&(e=r.filter(d,e)),this.length>1&&(J[a]||r.uniqueSort(e),I.test(a)&&e.reverse()),this.pushStack(e)}});var L=/[^\\x20\\t\\r\\n\\f]+/g;function M(a){var b={};return r.each(a.match(L)||[],function(a,c){b[c]=!0}),b}r.Callbacks=function(a){a=\"string\"==typeof a?M(a):r.extend({},a);var b,c,d,e,f=[],g=[],h=-1,i=function(){for(e=e||a.once,d=b=!0;g.length;h=-1){c=g.shift();while(++h<f.length)f[h].apply(c[0],c[1])===!1&&a.stopOnFalse&&(h=f.length,c=!1)}a.memory||(c=!1),b=!1,e&&(f=c?[]:\"\")},j={add:function(){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&\"string\"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this},remove:function(){return r.each(arguments,function(a,b){var c;while((c=r.inArray(b,f,c))>-1)f.splice(c,1),c<=h&&h--}),this},has:function(a){return a?r.inArray(a,f)>-1:f.length>0},empty:function(){return f&&(f=[]),this},disable:function(){return e=g=[],f=c=\"\",this},disabled:function(){return!f},lock:function(){return e=g=[],c||b||(f=c=\"\"),this},locked:function(){return!!e},fireWith:function(a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this},fire:function(){return j.fireWith(this,arguments),this},fired:function(){return!!d}};return j};function N(a){return a}function O(a){throw a}function P(a,b,c,d){var e;try{a&&r.isFunction(e=a.promise)?e.call(a).done(b).fail(c):a&&r.isFunction(e=a.then)?e.call(a,b,c):b.apply(void 0,[a].slice(d))}catch(a){c.apply(void 0,[a])}}r.extend({Deferred:function(b){var c=[[\"notify\",\"progress\",r.Callbacks(\"memory\"),r.Callbacks(\"memory\"),2],[\"resolve\",\"done\",r.Callbacks(\"once memory\"),r.Callbacks(\"once memory\"),0,\"resolved\"],[\"reject\",\"fail\",r.Callbacks(\"once memory\"),r.Callbacks(\"once memory\"),1,\"rejected\"]],d=\"pending\",e={state:function(){return d},always:function(){return f.done(arguments).fail(arguments),this},\"catch\":function(a){return e.then(null,a)},pipe:function(){var a=arguments;return r.Deferred(function(b){r.each(c,function(c,d){var e=r.isFunction(a[d[4]])&&a[d[4]];f[d[1]](function(){var a=e&&e.apply(this,arguments);a&&r.isFunction(a.promise)?a.promise().progress(b.notify).done(b.resolve).fail(b.reject):b[d[0]+\"With\"](this,e?[a]:arguments)})}),a=null}).promise()},then:function(b,d,e){var f=0;function g(b,c,d,e){return function(){var h=this,i=arguments,j=function(){var a,j;if(!(b<f)){if(a=d.apply(h,i),a===c.promise())throw new TypeError(\"Thenable self-resolution\");j=a&&(\"object\"==typeof a||\"function\"==typeof a)&&a.then,r.isFunction(j)?e?j.call(a,g(f,c,N,e),g(f,c,O,e)):(f++,j.call(a,g(f,c,N,e),g(f,c,O,e),g(f,c,N,c.notifyWith))):(d!==N&&(h=void 0,i=[a]),(e||c.resolveWith)(h,i))}},k=e?j:function(){try{j()}catch(a){r.Deferred.exceptionHook&&r.Deferred.exceptionHook(a,k.stackTrace),b+1>=f&&(d!==O&&(h=void 0,i=[a]),c.rejectWith(h,i))}};b?k():(r.Deferred.getStackHook&&(k.stackTrace=r.Deferred.getStackHook()),a.setTimeout(k))}}return r.Deferred(function(a){c[0][3].add(g(0,a,r.isFunction(e)?e:N,a.notifyWith)),c[1][3].add(g(0,a,r.isFunction(b)?b:N)),c[2][3].add(g(0,a,r.isFunction(d)?d:O))}).promise()},promise:function(a){return null!=a?r.extend(a,e):e}},f={};return r.each(c,function(a,b){var g=b[2],h=b[5];e[b[1]]=g.add,h&&g.add(function(){d=h},c[3-a][2].disable,c[0][2].lock),g.add(b[3].fire),f[b[0]]=function(){return f[b[0]+\"With\"](this===f?void 0:this,arguments),this},f[b[0]+\"With\"]=g.fireWith}),e.promise(f),b&&b.call(f,f),f},when:function(a){var b=arguments.length,c=b,d=Array(c),e=f.call(arguments),g=r.Deferred(),h=function(a){return function(c){d[a]=this,e[a]=arguments.length>1?f.call(arguments):c,--b||g.resolveWith(d,e)}};if(b<=1&&(P(a,g.done(h(c)).resolve,g.reject,!b),\"pending\"===g.state()||r.isFunction(e[c]&&e[c].then)))return g.then();while(c--)P(e[c],h(c),g.reject);return g.promise()}});var Q=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;r.Deferred.exceptionHook=function(b,c){a.console&&a.console.warn&&b&&Q.test(b.name)&&a.console.warn(\"jQuery.Deferred exception: \"+b.message,b.stack,c)},r.readyException=function(b){a.setTimeout(function(){throw b})};var R=r.Deferred();r.fn.ready=function(a){return R.then(a)[\"catch\"](function(a){r.readyException(a)}),this},r.extend({isReady:!1,readyWait:1,ready:function(a){(a===!0?--r.readyWait:r.isReady)||(r.isReady=!0,a!==!0&&--r.readyWait>0||R.resolveWith(d,[r]))}}),r.ready.then=R.then;function S(){d.removeEventListener(\"DOMContentLoaded\",S),\na.removeEventListener(\"load\",S),r.ready()}\"complete\"===d.readyState||\"loading\"!==d.readyState&&!d.documentElement.doScroll?a.setTimeout(r.ready):(d.addEventListener(\"DOMContentLoaded\",S),a.addEventListener(\"load\",S));var T=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if(\"object\"===r.type(c)){e=!0;for(h in c)T(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,r.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(r(a),c)})),b))for(;h<i;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},U=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function V(){this.expando=r.expando+V.uid++}V.uid=1,V.prototype={cache:function(a){var b=a[this.expando];return b||(b={},U(a)&&(a.nodeType?a[this.expando]=b:Object.defineProperty(a,this.expando,{value:b,configurable:!0}))),b},set:function(a,b,c){var d,e=this.cache(a);if(\"string\"==typeof b)e[r.camelCase(b)]=c;else for(d in b)e[r.camelCase(d)]=b[d];return e},get:function(a,b){return void 0===b?this.cache(a):a[this.expando]&&a[this.expando][r.camelCase(b)]},access:function(a,b,c){return void 0===b||b&&\"string\"==typeof b&&void 0===c?this.get(a,b):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d=a[this.expando];if(void 0!==d){if(void 0!==b){Array.isArray(b)?b=b.map(r.camelCase):(b=r.camelCase(b),b=b in d?[b]:b.match(L)||[]),c=b.length;while(c--)delete d[b[c]]}(void 0===b||r.isEmptyObject(d))&&(a.nodeType?a[this.expando]=void 0:delete a[this.expando])}},hasData:function(a){var b=a[this.expando];return void 0!==b&&!r.isEmptyObject(b)}};var W=new V,X=new V,Y=/^(?:\\{[\\w\\W]*\\}|\\[[\\w\\W]*\\])$/,Z=/[A-Z]/g;function $(a){return\"true\"===a||\"false\"!==a&&(\"null\"===a?null:a===+a+\"\"?+a:Y.test(a)?JSON.parse(a):a)}function _(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d=\"data-\"+b.replace(Z,\"-$&\").toLowerCase(),c=a.getAttribute(d),\"string\"==typeof c){try{c=$(c)}catch(e){}X.set(a,b,c)}else c=void 0;return c}r.extend({hasData:function(a){return X.hasData(a)||W.hasData(a)},data:function(a,b,c){return X.access(a,b,c)},removeData:function(a,b){X.remove(a,b)},_data:function(a,b,c){return W.access(a,b,c)},_removeData:function(a,b){W.remove(a,b)}}),r.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=X.get(f),1===f.nodeType&&!W.get(f,\"hasDataAttrs\"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf(\"data-\")&&(d=r.camelCase(d.slice(5)),_(f,d,e[d])));W.set(f,\"hasDataAttrs\",!0)}return e}return\"object\"==typeof a?this.each(function(){X.set(this,a)}):T(this,function(b){var c;if(f&&void 0===b){if(c=X.get(f,a),void 0!==c)return c;if(c=_(f,a),void 0!==c)return c}else this.each(function(){X.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){X.remove(this,a)})}}),r.extend({queue:function(a,b,c){var d;if(a)return b=(b||\"fx\")+\"queue\",d=W.get(a,b),c&&(!d||Array.isArray(c)?d=W.access(a,b,r.makeArray(c)):d.push(c)),d||[]},dequeue:function(a,b){b=b||\"fx\";var c=r.queue(a,b),d=c.length,e=c.shift(),f=r._queueHooks(a,b),g=function(){r.dequeue(a,b)};\"inprogress\"===e&&(e=c.shift(),d--),e&&(\"fx\"===b&&c.unshift(\"inprogress\"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+\"queueHooks\";return W.get(a,c)||W.access(a,c,{empty:r.Callbacks(\"once memory\").add(function(){W.remove(a,[b+\"queue\",c])})})}}),r.fn.extend({queue:function(a,b){var c=2;return\"string\"!=typeof a&&(b=a,a=\"fx\",c--),arguments.length<c?r.queue(this[0],a):void 0===b?this:this.each(function(){var c=r.queue(this,a,b);r._queueHooks(this,a),\"fx\"===a&&\"inprogress\"!==c[0]&&r.dequeue(this,a)})},dequeue:function(a){return this.each(function(){r.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||\"fx\",[])},promise:function(a,b){var c,d=1,e=r.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};\"string\"!=typeof a&&(b=a,a=void 0),a=a||\"fx\";while(g--)c=W.get(f[g],a+\"queueHooks\"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var aa=/[+-]?(?:\\d*\\.|)\\d+(?:[eE][+-]?\\d+|)/.source,ba=new RegExp(\"^(?:([+-])=|)(\"+aa+\")([a-z%]*)$\",\"i\"),ca=[\"Top\",\"Right\",\"Bottom\",\"Left\"],da=function(a,b){return a=b||a,\"none\"===a.style.display||\"\"===a.style.display&&r.contains(a.ownerDocument,a)&&\"none\"===r.css(a,\"display\")},ea=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};function fa(a,b,c,d){var e,f=1,g=20,h=d?function(){return d.cur()}:function(){return r.css(a,b,\"\")},i=h(),j=c&&c[3]||(r.cssNumber[b]?\"\":\"px\"),k=(r.cssNumber[b]||\"px\"!==j&&+i)&&ba.exec(r.css(a,b));if(k&&k[3]!==j){j=j||k[3],c=c||[],k=+i||1;do f=f||\".5\",k/=f,r.style(a,b,k+j);while(f!==(f=h()/i)&&1!==f&&--g)}return c&&(k=+k||+i||0,e=c[1]?k+(c[1]+1)*c[2]:+c[2],d&&(d.unit=j,d.start=k,d.end=e)),e}var ga={};function ha(a){var b,c=a.ownerDocument,d=a.nodeName,e=ga[d];return e?e:(b=c.body.appendChild(c.createElement(d)),e=r.css(b,\"display\"),b.parentNode.removeChild(b),\"none\"===e&&(e=\"block\"),ga[d]=e,e)}function ia(a,b){for(var c,d,e=[],f=0,g=a.length;f<g;f++)d=a[f],d.style&&(c=d.style.display,b?(\"none\"===c&&(e[f]=W.get(d,\"display\")||null,e[f]||(d.style.display=\"\")),\"\"===d.style.display&&da(d)&&(e[f]=ha(d))):\"none\"!==c&&(e[f]=\"none\",W.set(d,\"display\",c)));for(f=0;f<g;f++)null!=e[f]&&(a[f].style.display=e[f]);return a}r.fn.extend({show:function(){return ia(this,!0)},hide:function(){return ia(this)},toggle:function(a){return\"boolean\"==typeof a?a?this.show():this.hide():this.each(function(){da(this)?r(this).show():r(this).hide()})}});var ja=/^(?:checkbox|radio)$/i,ka=/<([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]+)/i,la=/^$|\\/(?:java|ecma)script/i,ma={option:[1,\"<select multiple='multiple'>\",\"</select>\"],thead:[1,\"<table>\",\"</table>\"],col:[2,\"<table><colgroup>\",\"</colgroup></table>\"],tr:[2,\"<table><tbody>\",\"</tbody></table>\"],td:[3,\"<table><tbody><tr>\",\"</tr></tbody></table>\"],_default:[0,\"\",\"\"]};ma.optgroup=ma.option,ma.tbody=ma.tfoot=ma.colgroup=ma.caption=ma.thead,ma.th=ma.td;function na(a,b){var c;return c=\"undefined\"!=typeof a.getElementsByTagName?a.getElementsByTagName(b||\"*\"):\"undefined\"!=typeof a.querySelectorAll?a.querySelectorAll(b||\"*\"):[],void 0===b||b&&B(a,b)?r.merge([a],c):c}function oa(a,b){for(var c=0,d=a.length;c<d;c++)W.set(a[c],\"globalEval\",!b||W.get(b[c],\"globalEval\"))}var pa=/<|&#?\\w+;/;function qa(a,b,c,d,e){for(var f,g,h,i,j,k,l=b.createDocumentFragment(),m=[],n=0,o=a.length;n<o;n++)if(f=a[n],f||0===f)if(\"object\"===r.type(f))r.merge(m,f.nodeType?[f]:f);else if(pa.test(f)){g=g||l.appendChild(b.createElement(\"div\")),h=(ka.exec(f)||[\"\",\"\"])[1].toLowerCase(),i=ma[h]||ma._default,g.innerHTML=i[1]+r.htmlPrefilter(f)+i[2],k=i[0];while(k--)g=g.lastChild;r.merge(m,g.childNodes),g=l.firstChild,g.textContent=\"\"}else m.push(b.createTextNode(f));l.textContent=\"\",n=0;while(f=m[n++])if(d&&r.inArray(f,d)>-1)e&&e.push(f);else if(j=r.contains(f.ownerDocument,f),g=na(l.appendChild(f),\"script\"),j&&oa(g),c){k=0;while(f=g[k++])la.test(f.type||\"\")&&c.push(f)}return l}!function(){var a=d.createDocumentFragment(),b=a.appendChild(d.createElement(\"div\")),c=d.createElement(\"input\");c.setAttribute(\"type\",\"radio\"),c.setAttribute(\"checked\",\"checked\"),c.setAttribute(\"name\",\"t\"),b.appendChild(c),o.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML=\"<textarea>x</textarea>\",o.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var ra=d.documentElement,sa=/^key/,ta=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,ua=/^([^.]*)(?:\\.(.+)|)/;function va(){return!0}function wa(){return!1}function xa(){try{return d.activeElement}catch(a){}}function ya(a,b,c,d,e,f){var g,h;if(\"object\"==typeof b){\"string\"!=typeof c&&(d=d||c,c=void 0);for(h in b)ya(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&(\"string\"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=wa;else if(!e)return a;return 1===f&&(g=e,e=function(a){return r().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=r.guid++)),a.each(function(){r.event.add(this,b,e,d,c)})}r.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.get(a);if(q){c.handler&&(f=c,c=f.handler,e=f.selector),e&&r.find.matchesSelector(ra,e),c.guid||(c.guid=r.guid++),(i=q.events)||(i=q.events={}),(g=q.handle)||(g=q.handle=function(b){return\"undefined\"!=typeof r&&r.event.triggered!==b.type?r.event.dispatch.apply(a,arguments):void 0}),b=(b||\"\").match(L)||[\"\"],j=b.length;while(j--)h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||\"\").split(\".\").sort(),n&&(l=r.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=r.event.special[n]||{},k=r.extend({type:n,origType:p,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&r.expr.match.needsContext.test(e),namespace:o.join(\".\")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,o,g)!==!1||a.addEventListener&&a.addEventListener(n,g)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),r.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.hasData(a)&&W.get(a);if(q&&(i=q.events)){b=(b||\"\").match(L)||[\"\"],j=b.length;while(j--)if(h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||\"\").split(\".\").sort(),n){l=r.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp(\"(^|\\\\.)\"+o.join(\"\\\\.(?:.*\\\\.|)\")+\"(\\\\.|$)\"),g=f=m.length;while(f--)k=m[f],!e&&p!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&(\"**\"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,o,q.handle)!==!1||r.removeEvent(a,n,q.handle),delete i[n])}else for(n in i)r.event.remove(a,n+b[j],c,d,!0);r.isEmptyObject(i)&&W.remove(a,\"handle events\")}},dispatch:function(a){var b=r.event.fix(a),c,d,e,f,g,h,i=new Array(arguments.length),j=(W.get(this,\"events\")||{})[b.type]||[],k=r.event.special[b.type]||{};for(i[0]=b,c=1;c<arguments.length;c++)i[c]=arguments[c];if(b.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,b)!==!1){h=r.event.handlers.call(this,b,j),c=0;while((f=h[c++])&&!b.isPropagationStopped()){b.currentTarget=f.elem,d=0;while((g=f.handlers[d++])&&!b.isImmediatePropagationStopped())b.rnamespace&&!b.rnamespace.test(g.namespace)||(b.handleObj=g,b.data=g.data,e=((r.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(b.result=e)===!1&&(b.preventDefault(),b.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,b),b.result}},handlers:function(a,b){var c,d,e,f,g,h=[],i=b.delegateCount,j=a.target;if(i&&j.nodeType&&!(\"click\"===a.type&&a.button>=1))for(;j!==this;j=j.parentNode||this)if(1===j.nodeType&&(\"click\"!==a.type||j.disabled!==!0)){for(f=[],g={},c=0;c<i;c++)d=b[c],e=d.selector+\" \",void 0===g[e]&&(g[e]=d.needsContext?r(e,this).index(j)>-1:r.find(e,this,null,[j]).length),g[e]&&f.push(d);f.length&&h.push({elem:j,handlers:f})}return j=this,i<b.length&&h.push({elem:j,handlers:b.slice(i)}),h},addProp:function(a,b){Object.defineProperty(r.Event.prototype,a,{enumerable:!0,configurable:!0,get:r.isFunction(b)?function(){if(this.originalEvent)return b(this.originalEvent)}:function(){if(this.originalEvent)return this.originalEvent[a]},set:function(b){Object.defineProperty(this,a,{enumerable:!0,configurable:!0,writable:!0,value:b})}})},fix:function(a){return a[r.expando]?a:new r.Event(a)},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==xa()&&this.focus)return this.focus(),!1},delegateType:\"focusin\"},blur:{trigger:function(){if(this===xa()&&this.blur)return this.blur(),!1},delegateType:\"focusout\"},click:{trigger:function(){if(\"checkbox\"===this.type&&this.click&&B(this,\"input\"))return this.click(),!1},_default:function(a){return B(a.target,\"a\")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}}},r.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c)},r.Event=function(a,b){return this instanceof r.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?va:wa,this.target=a.target&&3===a.target.nodeType?a.target.parentNode:a.target,this.currentTarget=a.currentTarget,this.relatedTarget=a.relatedTarget):this.type=a,b&&r.extend(this,b),this.timeStamp=a&&a.timeStamp||r.now(),void(this[r.expando]=!0)):new r.Event(a,b)},r.Event.prototype={constructor:r.Event,isDefaultPrevented:wa,isPropagationStopped:wa,isImmediatePropagationStopped:wa,isSimulated:!1,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=va,a&&!this.isSimulated&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=va,a&&!this.isSimulated&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=va,a&&!this.isSimulated&&a.stopImmediatePropagation(),this.stopPropagation()}},r.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,\"char\":!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(a){var b=a.button;return null==a.which&&sa.test(a.type)?null!=a.charCode?a.charCode:a.keyCode:!a.which&&void 0!==b&&ta.test(a.type)?1&b?1:2&b?3:4&b?2:0:a.which}},r.event.addProp),r.each({mouseenter:\"mouseover\",mouseleave:\"mouseout\",pointerenter:\"pointerover\",pointerleave:\"pointerout\"},function(a,b){r.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return e&&(e===d||r.contains(d,e))||(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),r.fn.extend({on:function(a,b,c,d){return ya(this,a,b,c,d)},one:function(a,b,c,d){return ya(this,a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,r(a.delegateTarget).off(d.namespace?d.origType+\".\"+d.namespace:d.origType,d.selector,d.handler),this;if(\"object\"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return b!==!1&&\"function\"!=typeof b||(c=b,b=void 0),c===!1&&(c=wa),this.each(function(){r.event.remove(this,a,c,b)})}});var za=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]*)[^>]*)\\/>/gi,Aa=/<script|<style|<link/i,Ba=/checked\\s*(?:[^=]|=\\s*.checked.)/i,Ca=/^true\\/(.*)/,Da=/^\\s*<!(?:\\[CDATA\\[|--)|(?:\\]\\]|--)>\\s*$/g;function Ea(a,b){return B(a,\"table\")&&B(11!==b.nodeType?b:b.firstChild,\"tr\")?r(\">tbody\",a)[0]||a:a}function Fa(a){return a.type=(null!==a.getAttribute(\"type\"))+\"/\"+a.type,a}function Ga(a){var b=Ca.exec(a.type);return b?a.type=b[1]:a.removeAttribute(\"type\"),a}function Ha(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(W.hasData(a)&&(f=W.access(a),g=W.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;c<d;c++)r.event.add(b,e,j[e][c])}X.hasData(a)&&(h=X.access(a),i=r.extend({},h),X.set(b,i))}}function Ia(a,b){var c=b.nodeName.toLowerCase();\"input\"===c&&ja.test(a.type)?b.checked=a.checked:\"input\"!==c&&\"textarea\"!==c||(b.defaultValue=a.defaultValue)}function Ja(a,b,c,d){b=g.apply([],b);var e,f,h,i,j,k,l=0,m=a.length,n=m-1,q=b[0],s=r.isFunction(q);if(s||m>1&&\"string\"==typeof q&&!o.checkClone&&Ba.test(q))return a.each(function(e){var f=a.eq(e);s&&(b[0]=q.call(this,e,f.html())),Ja(f,b,c,d)});if(m&&(e=qa(b,a[0].ownerDocument,!1,a,d),f=e.firstChild,1===e.childNodes.length&&(e=f),f||d)){for(h=r.map(na(e,\"script\"),Fa),i=h.length;l<m;l++)j=e,l!==n&&(j=r.clone(j,!0,!0),i&&r.merge(h,na(j,\"script\"))),c.call(a[l],j,l);if(i)for(k=h[h.length-1].ownerDocument,r.map(h,Ga),l=0;l<i;l++)j=h[l],la.test(j.type||\"\")&&!W.access(j,\"globalEval\")&&r.contains(k,j)&&(j.src?r._evalUrl&&r._evalUrl(j.src):p(j.textContent.replace(Da,\"\"),k))}return a}function Ka(a,b,c){for(var d,e=b?r.filter(b,a):a,f=0;null!=(d=e[f]);f++)c||1!==d.nodeType||r.cleanData(na(d)),d.parentNode&&(c&&r.contains(d.ownerDocument,d)&&oa(na(d,\"script\")),d.parentNode.removeChild(d));return a}r.extend({htmlPrefilter:function(a){return a.replace(za,\"<$1></$2>\")},clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=r.contains(a.ownerDocument,a);if(!(o.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||r.isXMLDoc(a)))for(g=na(h),f=na(a),d=0,e=f.length;d<e;d++)Ia(f[d],g[d]);if(b)if(c)for(f=f||na(a),g=g||na(h),d=0,e=f.length;d<e;d++)Ha(f[d],g[d]);else Ha(a,h);return g=na(h,\"script\"),g.length>0&&oa(g,!i&&na(a,\"script\")),h},cleanData:function(a){for(var b,c,d,e=r.event.special,f=0;void 0!==(c=a[f]);f++)if(U(c)){if(b=c[W.expando]){if(b.events)for(d in b.events)e[d]?r.event.remove(c,d):r.removeEvent(c,d,b.handle);c[W.expando]=void 0}c[X.expando]&&(c[X.expando]=void 0)}}}),r.fn.extend({detach:function(a){return Ka(this,a,!0)},remove:function(a){return Ka(this,a)},text:function(a){return T(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)},append:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.appendChild(a)}})},prepend:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(r.cleanData(na(a,!1)),a.textContent=\"\");return this},clone:function(a,b){return a=null!=a&&a,b=null==b?a:b,this.map(function(){return r.clone(this,a,b)})},html:function(a){return T(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if(\"string\"==typeof a&&!Aa.test(a)&&!ma[(ka.exec(a)||[\"\",\"\"])[1].toLowerCase()]){a=r.htmlPrefilter(a);try{for(;c<d;c++)b=this[c]||{},1===b.nodeType&&(r.cleanData(na(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=[];return Ja(this,arguments,function(b){var c=this.parentNode;r.inArray(this,a)<0&&(r.cleanData(na(this)),c&&c.replaceChild(b,this))},a)}}),r.each({appendTo:\"append\",prependTo:\"prepend\",insertBefore:\"before\",insertAfter:\"after\",replaceAll:\"replaceWith\"},function(a,b){r.fn[a]=function(a){for(var c,d=[],e=r(a),f=e.length-1,g=0;g<=f;g++)c=g===f?this:this.clone(!0),r(e[g])[b](c),h.apply(d,c.get());return this.pushStack(d)}});var La=/^margin/,Ma=new RegExp(\"^(\"+aa+\")(?!px)[a-z%]+$\",\"i\"),Na=function(b){var c=b.ownerDocument.defaultView;return c&&c.opener||(c=a),c.getComputedStyle(b)};!function(){function b(){if(i){i.style.cssText=\"box-sizing:border-box;position:relative;display:block;margin:auto;border:1px;padding:1px;top:1%;width:50%\",i.innerHTML=\"\",ra.appendChild(h);var b=a.getComputedStyle(i);c=\"1%\"!==b.top,g=\"2px\"===b.marginLeft,e=\"4px\"===b.width,i.style.marginRight=\"50%\",f=\"4px\"===b.marginRight,ra.removeChild(h),i=null}}var c,e,f,g,h=d.createElement(\"div\"),i=d.createElement(\"div\");i.style&&(i.style.backgroundClip=\"content-box\",i.cloneNode(!0).style.backgroundClip=\"\",o.clearCloneStyle=\"content-box\"===i.style.backgroundClip,h.style.cssText=\"border:0;width:8px;height:0;top:0;left:-9999px;padding:0;margin-top:1px;position:absolute\",h.appendChild(i),r.extend(o,{pixelPosition:function(){return b(),c},boxSizingReliable:function(){return b(),e},pixelMarginRight:function(){return b(),f},reliableMarginLeft:function(){return b(),g}}))}();function Oa(a,b,c){var d,e,f,g,h=a.style;return c=c||Na(a),c&&(g=c.getPropertyValue(b)||c[b],\"\"!==g||r.contains(a.ownerDocument,a)||(g=r.style(a,b)),!o.pixelMarginRight()&&Ma.test(g)&&La.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+\"\":g}function Pa(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}var Qa=/^(none|table(?!-c[ea]).+)/,Ra=/^--/,Sa={position:\"absolute\",visibility:\"hidden\",display:\"block\"},Ta={letterSpacing:\"0\",fontWeight:\"400\"},Ua=[\"Webkit\",\"Moz\",\"ms\"],Va=d.createElement(\"div\").style;function Wa(a){if(a in Va)return a;var b=a[0].toUpperCase()+a.slice(1),c=Ua.length;while(c--)if(a=Ua[c]+b,a in Va)return a}function Xa(a){var b=r.cssProps[a];return b||(b=r.cssProps[a]=Wa(a)||a),b}function Ya(a,b,c){var d=ba.exec(b);return d?Math.max(0,d[2]-(c||0))+(d[3]||\"px\"):b}function Za(a,b,c,d,e){var f,g=0;for(f=c===(d?\"border\":\"content\")?4:\"width\"===b?1:0;f<4;f+=2)\"margin\"===c&&(g+=r.css(a,c+ca[f],!0,e)),d?(\"content\"===c&&(g-=r.css(a,\"padding\"+ca[f],!0,e)),\"margin\"!==c&&(g-=r.css(a,\"border\"+ca[f]+\"Width\",!0,e))):(g+=r.css(a,\"padding\"+ca[f],!0,e),\"padding\"!==c&&(g+=r.css(a,\"border\"+ca[f]+\"Width\",!0,e)));return g}function $a(a,b,c){var d,e=Na(a),f=Oa(a,b,e),g=\"border-box\"===r.css(a,\"boxSizing\",!1,e);return Ma.test(f)?f:(d=g&&(o.boxSizingReliable()||f===a.style[b]),\"auto\"===f&&(f=a[\"offset\"+b[0].toUpperCase()+b.slice(1)]),f=parseFloat(f)||0,f+Za(a,b,c||(g?\"border\":\"content\"),d,e)+\"px\")}r.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Oa(a,\"opacity\");return\"\"===c?\"1\":c}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{\"float\":\"cssFloat\"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=r.camelCase(b),i=Ra.test(b),j=a.style;return i||(b=Xa(h)),g=r.cssHooks[b]||r.cssHooks[h],void 0===c?g&&\"get\"in g&&void 0!==(e=g.get(a,!1,d))?e:j[b]:(f=typeof c,\"string\"===f&&(e=ba.exec(c))&&e[1]&&(c=fa(a,b,e),f=\"number\"),null!=c&&c===c&&(\"number\"===f&&(c+=e&&e[3]||(r.cssNumber[h]?\"\":\"px\")),o.clearCloneStyle||\"\"!==c||0!==b.indexOf(\"background\")||(j[b]=\"inherit\"),g&&\"set\"in g&&void 0===(c=g.set(a,c,d))||(i?j.setProperty(b,c):j[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=r.camelCase(b),i=Ra.test(b);return i||(b=Xa(h)),g=r.cssHooks[b]||r.cssHooks[h],g&&\"get\"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=Oa(a,b,d)),\"normal\"===e&&b in Ta&&(e=Ta[b]),\"\"===c||c?(f=parseFloat(e),c===!0||isFinite(f)?f||0:e):e}}),r.each([\"height\",\"width\"],function(a,b){r.cssHooks[b]={get:function(a,c,d){if(c)return!Qa.test(r.css(a,\"display\"))||a.getClientRects().length&&a.getBoundingClientRect().width?$a(a,b,d):ea(a,Sa,function(){return $a(a,b,d)})},set:function(a,c,d){var e,f=d&&Na(a),g=d&&Za(a,b,d,\"border-box\"===r.css(a,\"boxSizing\",!1,f),f);return g&&(e=ba.exec(c))&&\"px\"!==(e[3]||\"px\")&&(a.style[b]=c,c=r.css(a,b)),Ya(a,c,g)}}}),r.cssHooks.marginLeft=Pa(o.reliableMarginLeft,function(a,b){if(b)return(parseFloat(Oa(a,\"marginLeft\"))||a.getBoundingClientRect().left-ea(a,{marginLeft:0},function(){return a.getBoundingClientRect().left}))+\"px\"}),r.each({margin:\"\",padding:\"\",border:\"Width\"},function(a,b){r.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f=\"string\"==typeof c?c.split(\" \"):[c];d<4;d++)e[a+ca[d]+b]=f[d]||f[d-2]||f[0];return e}},La.test(a)||(r.cssHooks[a+b].set=Ya)}),r.fn.extend({css:function(a,b){return T(this,function(a,b,c){var d,e,f={},g=0;if(Array.isArray(b)){for(d=Na(a),e=b.length;g<e;g++)f[b[g]]=r.css(a,b[g],!1,d);return f}return void 0!==c?r.style(a,b,c):r.css(a,b)},a,b,arguments.length>1)}});function _a(a,b,c,d,e){return new _a.prototype.init(a,b,c,d,e)}r.Tween=_a,_a.prototype={constructor:_a,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||r.easing._default,this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(r.cssNumber[c]?\"\":\"px\")},cur:function(){var a=_a.propHooks[this.prop];return a&&a.get?a.get(this):_a.propHooks._default.get(this)},run:function(a){var b,c=_a.propHooks[this.prop];return this.options.duration?this.pos=b=r.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):_a.propHooks._default.set(this),this}},_a.prototype.init.prototype=_a.prototype,_a.propHooks={_default:{get:function(a){var b;return 1!==a.elem.nodeType||null!=a.elem[a.prop]&&null==a.elem.style[a.prop]?a.elem[a.prop]:(b=r.css(a.elem,a.prop,\"\"),b&&\"auto\"!==b?b:0)},set:function(a){r.fx.step[a.prop]?r.fx.step[a.prop](a):1!==a.elem.nodeType||null==a.elem.style[r.cssProps[a.prop]]&&!r.cssHooks[a.prop]?a.elem[a.prop]=a.now:r.style(a.elem,a.prop,a.now+a.unit)}}},_a.propHooks.scrollTop=_a.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},r.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2},_default:\"swing\"},r.fx=_a.prototype.init,r.fx.step={};var ab,bb,cb=/^(?:toggle|show|hide)$/,db=/queueHooks$/;function eb(){bb&&(d.hidden===!1&&a.requestAnimationFrame?a.requestAnimationFrame(eb):a.setTimeout(eb,r.fx.interval),r.fx.tick())}function fb(){return a.setTimeout(function(){ab=void 0}),ab=r.now()}function gb(a,b){var c,d=0,e={height:a};for(b=b?1:0;d<4;d+=2-b)c=ca[d],e[\"margin\"+c]=e[\"padding\"+c]=a;return b&&(e.opacity=e.width=a),e}function hb(a,b,c){for(var d,e=(kb.tweeners[b]||[]).concat(kb.tweeners[\"*\"]),f=0,g=e.length;f<g;f++)if(d=e[f].call(c,b,a))return d}function ib(a,b,c){var d,e,f,g,h,i,j,k,l=\"width\"in b||\"height\"in b,m=this,n={},o=a.style,p=a.nodeType&&da(a),q=W.get(a,\"fxshow\");c.queue||(g=r._queueHooks(a,\"fx\"),null==g.unqueued&&(g.unqueued=0,h=g.empty.fire,g.empty.fire=function(){g.unqueued||h()}),g.unqueued++,m.always(function(){m.always(function(){g.unqueued--,r.queue(a,\"fx\").length||g.empty.fire()})}));for(d in b)if(e=b[d],cb.test(e)){if(delete b[d],f=f||\"toggle\"===e,e===(p?\"hide\":\"show\")){if(\"show\"!==e||!q||void 0===q[d])continue;p=!0}n[d]=q&&q[d]||r.style(a,d)}if(i=!r.isEmptyObject(b),i||!r.isEmptyObject(n)){l&&1===a.nodeType&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=q&&q.display,null==j&&(j=W.get(a,\"display\")),k=r.css(a,\"display\"),\"none\"===k&&(j?k=j:(ia([a],!0),j=a.style.display||j,k=r.css(a,\"display\"),ia([a]))),(\"inline\"===k||\"inline-block\"===k&&null!=j)&&\"none\"===r.css(a,\"float\")&&(i||(m.done(function(){o.display=j}),null==j&&(k=o.display,j=\"none\"===k?\"\":k)),o.display=\"inline-block\")),c.overflow&&(o.overflow=\"hidden\",m.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]})),i=!1;for(d in n)i||(q?\"hidden\"in q&&(p=q.hidden):q=W.access(a,\"fxshow\",{display:j}),f&&(q.hidden=!p),p&&ia([a],!0),m.done(function(){p||ia([a]),W.remove(a,\"fxshow\");for(d in n)r.style(a,d,n[d])})),i=hb(p?q[d]:0,d,m),d in q||(q[d]=i.start,p&&(i.end=i.start,i.start=0))}}function jb(a,b){var c,d,e,f,g;for(c in a)if(d=r.camelCase(c),e=b[d],f=a[c],Array.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=r.cssHooks[d],g&&\"expand\"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function kb(a,b,c){var d,e,f=0,g=kb.prefilters.length,h=r.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=ab||fb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;g<i;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),f<1&&i?c:(i||h.notifyWith(a,[j,1,0]),h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:r.extend({},b),opts:r.extend(!0,{specialEasing:{},easing:r.easing._default},c),originalProperties:b,originalOptions:c,startTime:ab||fb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=r.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;c<d;c++)j.tweens[c].run(1);return b?(h.notifyWith(a,[j,1,0]),h.resolveWith(a,[j,b])):h.rejectWith(a,[j,b]),this}}),k=j.props;for(jb(k,j.opts.specialEasing);f<g;f++)if(d=kb.prefilters[f].call(j,a,k,j.opts))return r.isFunction(d.stop)&&(r._queueHooks(j.elem,j.opts.queue).stop=r.proxy(d.stop,d)),d;return r.map(k,hb,j),r.isFunction(j.opts.start)&&j.opts.start.call(a,j),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always),r.fx.timer(r.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j}r.Animation=r.extend(kb,{tweeners:{\"*\":[function(a,b){var c=this.createTween(a,b);return fa(c.elem,a,ba.exec(b),c),c}]},tweener:function(a,b){r.isFunction(a)?(b=a,a=[\"*\"]):a=a.match(L);for(var c,d=0,e=a.length;d<e;d++)c=a[d],kb.tweeners[c]=kb.tweeners[c]||[],kb.tweeners[c].unshift(b)},prefilters:[ib],prefilter:function(a,b){b?kb.prefilters.unshift(a):kb.prefilters.push(a)}}),r.speed=function(a,b,c){var d=a&&\"object\"==typeof a?r.extend({},a):{complete:c||!c&&b||r.isFunction(a)&&a,duration:a,easing:c&&b||b&&!r.isFunction(b)&&b};return r.fx.off?d.duration=0:\"number\"!=typeof d.duration&&(d.duration in r.fx.speeds?d.duration=r.fx.speeds[d.duration]:d.duration=r.fx.speeds._default),null!=d.queue&&d.queue!==!0||(d.queue=\"fx\"),d.old=d.complete,d.complete=function(){r.isFunction(d.old)&&d.old.call(this),d.queue&&r.dequeue(this,d.queue)},d},r.fn.extend({fadeTo:function(a,b,c,d){return this.filter(da).css(\"opacity\",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=r.isEmptyObject(a),f=r.speed(b,c,d),g=function(){var b=kb(this,r.extend({},a),f);(e||W.get(this,\"finish\"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return\"string\"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||\"fx\",[]),this.each(function(){var b=!0,e=null!=a&&a+\"queueHooks\",f=r.timers,g=W.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&db.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));!b&&c||r.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||\"fx\"),this.each(function(){var b,c=W.get(this),d=c[a+\"queue\"],e=c[a+\"queueHooks\"],f=r.timers,g=d?d.length:0;for(c.finish=!0,r.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;b<g;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),r.each([\"toggle\",\"show\",\"hide\"],function(a,b){var c=r.fn[b];r.fn[b]=function(a,d,e){return null==a||\"boolean\"==typeof a?c.apply(this,arguments):this.animate(gb(b,!0),a,d,e)}}),r.each({slideDown:gb(\"show\"),slideUp:gb(\"hide\"),slideToggle:gb(\"toggle\"),fadeIn:{opacity:\"show\"},fadeOut:{opacity:\"hide\"},fadeToggle:{opacity:\"toggle\"}},function(a,b){r.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),r.timers=[],r.fx.tick=function(){var a,b=0,c=r.timers;for(ab=r.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||r.fx.stop(),ab=void 0},r.fx.timer=function(a){r.timers.push(a),r.fx.start()},r.fx.interval=13,r.fx.start=function(){bb||(bb=!0,eb())},r.fx.stop=function(){bb=null},r.fx.speeds={slow:600,fast:200,_default:400},r.fn.delay=function(b,c){return b=r.fx?r.fx.speeds[b]||b:b,c=c||\"fx\",this.queue(c,function(c,d){var e=a.setTimeout(c,b);d.stop=function(){a.clearTimeout(e)}})},function(){var a=d.createElement(\"input\"),b=d.createElement(\"select\"),c=b.appendChild(d.createElement(\"option\"));a.type=\"checkbox\",o.checkOn=\"\"!==a.value,o.optSelected=c.selected,a=d.createElement(\"input\"),a.value=\"t\",a.type=\"radio\",o.radioValue=\"t\"===a.value}();var lb,mb=r.expr.attrHandle;r.fn.extend({attr:function(a,b){return T(this,r.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){r.removeAttr(this,a)})}}),r.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return\"undefined\"==typeof a.getAttribute?r.prop(a,b,c):(1===f&&r.isXMLDoc(a)||(e=r.attrHooks[b.toLowerCase()]||(r.expr.match.bool.test(b)?lb:void 0)),void 0!==c?null===c?void r.removeAttr(a,b):e&&\"set\"in e&&void 0!==(d=e.set(a,c,b))?d:(a.setAttribute(b,c+\"\"),c):e&&\"get\"in e&&null!==(d=e.get(a,b))?d:(d=r.find.attr(a,b),\nnull==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&\"radio\"===b&&B(a,\"input\")){var c=a.value;return a.setAttribute(\"type\",b),c&&(a.value=c),b}}}},removeAttr:function(a,b){var c,d=0,e=b&&b.match(L);if(e&&1===a.nodeType)while(c=e[d++])a.removeAttribute(c)}}),lb={set:function(a,b,c){return b===!1?r.removeAttr(a,c):a.setAttribute(c,c),c}},r.each(r.expr.match.bool.source.match(/\\w+/g),function(a,b){var c=mb[b]||r.find.attr;mb[b]=function(a,b,d){var e,f,g=b.toLowerCase();return d||(f=mb[g],mb[g]=e,e=null!=c(a,b,d)?g:null,mb[g]=f),e}});var nb=/^(?:input|select|textarea|button)$/i,ob=/^(?:a|area)$/i;r.fn.extend({prop:function(a,b){return T(this,r.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[r.propFix[a]||a]})}}),r.extend({prop:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return 1===f&&r.isXMLDoc(a)||(b=r.propFix[b]||b,e=r.propHooks[b]),void 0!==c?e&&\"set\"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&\"get\"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=r.find.attr(a,\"tabindex\");return b?parseInt(b,10):nb.test(a.nodeName)||ob.test(a.nodeName)&&a.href?0:-1}}},propFix:{\"for\":\"htmlFor\",\"class\":\"className\"}}),o.optSelected||(r.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null},set:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex)}}),r.each([\"tabIndex\",\"readOnly\",\"maxLength\",\"cellSpacing\",\"cellPadding\",\"rowSpan\",\"colSpan\",\"useMap\",\"frameBorder\",\"contentEditable\"],function(){r.propFix[this.toLowerCase()]=this});function pb(a){var b=a.match(L)||[];return b.join(\" \")}function qb(a){return a.getAttribute&&a.getAttribute(\"class\")||\"\"}r.fn.extend({addClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).addClass(a.call(this,b,qb(this)))});if(\"string\"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&\" \"+pb(e)+\" \"){g=0;while(f=b[g++])d.indexOf(\" \"+f+\" \")<0&&(d+=f+\" \");h=pb(d),e!==h&&c.setAttribute(\"class\",h)}}return this},removeClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).removeClass(a.call(this,b,qb(this)))});if(!arguments.length)return this.attr(\"class\",\"\");if(\"string\"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&\" \"+pb(e)+\" \"){g=0;while(f=b[g++])while(d.indexOf(\" \"+f+\" \")>-1)d=d.replace(\" \"+f+\" \",\" \");h=pb(d),e!==h&&c.setAttribute(\"class\",h)}}return this},toggleClass:function(a,b){var c=typeof a;return\"boolean\"==typeof b&&\"string\"===c?b?this.addClass(a):this.removeClass(a):r.isFunction(a)?this.each(function(c){r(this).toggleClass(a.call(this,c,qb(this),b),b)}):this.each(function(){var b,d,e,f;if(\"string\"===c){d=0,e=r(this),f=a.match(L)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else void 0!==a&&\"boolean\"!==c||(b=qb(this),b&&W.set(this,\"__className__\",b),this.setAttribute&&this.setAttribute(\"class\",b||a===!1?\"\":W.get(this,\"__className__\")||\"\"))})},hasClass:function(a){var b,c,d=0;b=\" \"+a+\" \";while(c=this[d++])if(1===c.nodeType&&(\" \"+pb(qb(c))+\" \").indexOf(b)>-1)return!0;return!1}});var rb=/\\r/g;r.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=r.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,r(this).val()):a,null==e?e=\"\":\"number\"==typeof e?e+=\"\":Array.isArray(e)&&(e=r.map(e,function(a){return null==a?\"\":a+\"\"})),b=r.valHooks[this.type]||r.valHooks[this.nodeName.toLowerCase()],b&&\"set\"in b&&void 0!==b.set(this,e,\"value\")||(this.value=e))});if(e)return b=r.valHooks[e.type]||r.valHooks[e.nodeName.toLowerCase()],b&&\"get\"in b&&void 0!==(c=b.get(e,\"value\"))?c:(c=e.value,\"string\"==typeof c?c.replace(rb,\"\"):null==c?\"\":c)}}}),r.extend({valHooks:{option:{get:function(a){var b=r.find.attr(a,\"value\");return null!=b?b:pb(r.text(a))}},select:{get:function(a){var b,c,d,e=a.options,f=a.selectedIndex,g=\"select-one\"===a.type,h=g?null:[],i=g?f+1:e.length;for(d=f<0?i:g?f:0;d<i;d++)if(c=e[d],(c.selected||d===f)&&!c.disabled&&(!c.parentNode.disabled||!B(c.parentNode,\"optgroup\"))){if(b=r(c).val(),g)return b;h.push(b)}return h},set:function(a,b){var c,d,e=a.options,f=r.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=r.inArray(r.valHooks.option.get(d),f)>-1)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),r.each([\"radio\",\"checkbox\"],function(){r.valHooks[this]={set:function(a,b){if(Array.isArray(b))return a.checked=r.inArray(r(a).val(),b)>-1}},o.checkOn||(r.valHooks[this].get=function(a){return null===a.getAttribute(\"value\")?\"on\":a.value})});var sb=/^(?:focusinfocus|focusoutblur)$/;r.extend(r.event,{trigger:function(b,c,e,f){var g,h,i,j,k,m,n,o=[e||d],p=l.call(b,\"type\")?b.type:b,q=l.call(b,\"namespace\")?b.namespace.split(\".\"):[];if(h=i=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!sb.test(p+r.event.triggered)&&(p.indexOf(\".\")>-1&&(q=p.split(\".\"),p=q.shift(),q.sort()),k=p.indexOf(\":\")<0&&\"on\"+p,b=b[r.expando]?b:new r.Event(p,\"object\"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=q.join(\".\"),b.rnamespace=b.namespace?new RegExp(\"(^|\\\\.)\"+q.join(\"\\\\.(?:.*\\\\.|)\")+\"(\\\\.|$)\"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:r.makeArray(c,[b]),n=r.event.special[p]||{},f||!n.trigger||n.trigger.apply(e,c)!==!1)){if(!f&&!n.noBubble&&!r.isWindow(e)){for(j=n.delegateType||p,sb.test(j+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),i=h;i===(e.ownerDocument||d)&&o.push(i.defaultView||i.parentWindow||a)}g=0;while((h=o[g++])&&!b.isPropagationStopped())b.type=g>1?j:n.bindType||p,m=(W.get(h,\"events\")||{})[b.type]&&W.get(h,\"handle\"),m&&m.apply(h,c),m=k&&h[k],m&&m.apply&&U(h)&&(b.result=m.apply(h,c),b.result===!1&&b.preventDefault());return b.type=p,f||b.isDefaultPrevented()||n._default&&n._default.apply(o.pop(),c)!==!1||!U(e)||k&&r.isFunction(e[p])&&!r.isWindow(e)&&(i=e[k],i&&(e[k]=null),r.event.triggered=p,e[p](),r.event.triggered=void 0,i&&(e[k]=i)),b.result}},simulate:function(a,b,c){var d=r.extend(new r.Event,c,{type:a,isSimulated:!0});r.event.trigger(d,null,b)}}),r.fn.extend({trigger:function(a,b){return this.each(function(){r.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];if(c)return r.event.trigger(a,b,c,!0)}}),r.each(\"blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu\".split(\" \"),function(a,b){r.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),r.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),o.focusin=\"onfocusin\"in a,o.focusin||r.each({focus:\"focusin\",blur:\"focusout\"},function(a,b){var c=function(a){r.event.simulate(b,a.target,r.event.fix(a))};r.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=W.access(d,b);e||d.addEventListener(a,c,!0),W.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=W.access(d,b)-1;e?W.access(d,b,e):(d.removeEventListener(a,c,!0),W.remove(d,b))}}});var tb=a.location,ub=r.now(),vb=/\\?/;r.parseXML=function(b){var c;if(!b||\"string\"!=typeof b)return null;try{c=(new a.DOMParser).parseFromString(b,\"text/xml\")}catch(d){c=void 0}return c&&!c.getElementsByTagName(\"parsererror\").length||r.error(\"Invalid XML: \"+b),c};var wb=/\\[\\]$/,xb=/\\r?\\n/g,yb=/^(?:submit|button|image|reset|file)$/i,zb=/^(?:input|select|textarea|keygen)/i;function Ab(a,b,c,d){var e;if(Array.isArray(b))r.each(b,function(b,e){c||wb.test(a)?d(a,e):Ab(a+\"[\"+(\"object\"==typeof e&&null!=e?b:\"\")+\"]\",e,c,d)});else if(c||\"object\"!==r.type(b))d(a,b);else for(e in b)Ab(a+\"[\"+e+\"]\",b[e],c,d)}r.param=function(a,b){var c,d=[],e=function(a,b){var c=r.isFunction(b)?b():b;d[d.length]=encodeURIComponent(a)+\"=\"+encodeURIComponent(null==c?\"\":c)};if(Array.isArray(a)||a.jquery&&!r.isPlainObject(a))r.each(a,function(){e(this.name,this.value)});else for(c in a)Ab(c,a[c],b,e);return d.join(\"&\")},r.fn.extend({serialize:function(){return r.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=r.prop(this,\"elements\");return a?r.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!r(this).is(\":disabled\")&&zb.test(this.nodeName)&&!yb.test(a)&&(this.checked||!ja.test(a))}).map(function(a,b){var c=r(this).val();return null==c?null:Array.isArray(c)?r.map(c,function(a){return{name:b.name,value:a.replace(xb,\"\\r\\n\")}}):{name:b.name,value:c.replace(xb,\"\\r\\n\")}}).get()}});var Bb=/%20/g,Cb=/#.*$/,Db=/([?&])_=[^&]*/,Eb=/^(.*?):[ \\t]*([^\\r\\n]*)$/gm,Fb=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Gb=/^(?:GET|HEAD)$/,Hb=/^\\/\\//,Ib={},Jb={},Kb=\"*/\".concat(\"*\"),Lb=d.createElement(\"a\");Lb.href=tb.href;function Mb(a){return function(b,c){\"string\"!=typeof b&&(c=b,b=\"*\");var d,e=0,f=b.toLowerCase().match(L)||[];if(r.isFunction(c))while(d=f[e++])\"+\"===d[0]?(d=d.slice(1)||\"*\",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Nb(a,b,c,d){var e={},f=a===Jb;function g(h){var i;return e[h]=!0,r.each(a[h]||[],function(a,h){var j=h(b,c,d);return\"string\"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e[\"*\"]&&g(\"*\")}function Ob(a,b){var c,d,e=r.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&r.extend(!0,a,d),a}function Pb(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while(\"*\"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader(\"Content-Type\"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+\" \"+i[0]]){f=e;break}g||(g=e)}f=f||g}if(f)return f!==i[0]&&i.unshift(f),c[f]}function Qb(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if(\"*\"===f)f=i;else if(\"*\"!==i&&i!==f){if(g=j[i+\" \"+f]||j[\"* \"+f],!g)for(e in j)if(h=e.split(\" \"),h[1]===f&&(g=j[i+\" \"+h[0]]||j[\"* \"+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a[\"throws\"])b=g(b);else try{b=g(b)}catch(l){return{state:\"parsererror\",error:g?l:\"No conversion from \"+i+\" to \"+f}}}return{state:\"success\",data:b}}r.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:tb.href,type:\"GET\",isLocal:Fb.test(tb.protocol),global:!0,processData:!0,async:!0,contentType:\"application/x-www-form-urlencoded; charset=UTF-8\",accepts:{\"*\":Kb,text:\"text/plain\",html:\"text/html\",xml:\"application/xml, text/xml\",json:\"application/json, text/javascript\"},contents:{xml:/\\bxml\\b/,html:/\\bhtml/,json:/\\bjson\\b/},responseFields:{xml:\"responseXML\",text:\"responseText\",json:\"responseJSON\"},converters:{\"* text\":String,\"text html\":!0,\"text json\":JSON.parse,\"text xml\":r.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Ob(Ob(a,r.ajaxSettings),b):Ob(r.ajaxSettings,a)},ajaxPrefilter:Mb(Ib),ajaxTransport:Mb(Jb),ajax:function(b,c){\"object\"==typeof b&&(c=b,b=void 0),c=c||{};var e,f,g,h,i,j,k,l,m,n,o=r.ajaxSetup({},c),p=o.context||o,q=o.context&&(p.nodeType||p.jquery)?r(p):r.event,s=r.Deferred(),t=r.Callbacks(\"once memory\"),u=o.statusCode||{},v={},w={},x=\"canceled\",y={readyState:0,getResponseHeader:function(a){var b;if(k){if(!h){h={};while(b=Eb.exec(g))h[b[1].toLowerCase()]=b[2]}b=h[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return k?g:null},setRequestHeader:function(a,b){return null==k&&(a=w[a.toLowerCase()]=w[a.toLowerCase()]||a,v[a]=b),this},overrideMimeType:function(a){return null==k&&(o.mimeType=a),this},statusCode:function(a){var b;if(a)if(k)y.always(a[y.status]);else for(b in a)u[b]=[u[b],a[b]];return this},abort:function(a){var b=a||x;return e&&e.abort(b),A(0,b),this}};if(s.promise(y),o.url=((b||o.url||tb.href)+\"\").replace(Hb,tb.protocol+\"//\"),o.type=c.method||c.type||o.method||o.type,o.dataTypes=(o.dataType||\"*\").toLowerCase().match(L)||[\"\"],null==o.crossDomain){j=d.createElement(\"a\");try{j.href=o.url,j.href=j.href,o.crossDomain=Lb.protocol+\"//\"+Lb.host!=j.protocol+\"//\"+j.host}catch(z){o.crossDomain=!0}}if(o.data&&o.processData&&\"string\"!=typeof o.data&&(o.data=r.param(o.data,o.traditional)),Nb(Ib,o,c,y),k)return y;l=r.event&&o.global,l&&0===r.active++&&r.event.trigger(\"ajaxStart\"),o.type=o.type.toUpperCase(),o.hasContent=!Gb.test(o.type),f=o.url.replace(Cb,\"\"),o.hasContent?o.data&&o.processData&&0===(o.contentType||\"\").indexOf(\"application/x-www-form-urlencoded\")&&(o.data=o.data.replace(Bb,\"+\")):(n=o.url.slice(f.length),o.data&&(f+=(vb.test(f)?\"&\":\"?\")+o.data,delete o.data),o.cache===!1&&(f=f.replace(Db,\"$1\"),n=(vb.test(f)?\"&\":\"?\")+\"_=\"+ub++ +n),o.url=f+n),o.ifModified&&(r.lastModified[f]&&y.setRequestHeader(\"If-Modified-Since\",r.lastModified[f]),r.etag[f]&&y.setRequestHeader(\"If-None-Match\",r.etag[f])),(o.data&&o.hasContent&&o.contentType!==!1||c.contentType)&&y.setRequestHeader(\"Content-Type\",o.contentType),y.setRequestHeader(\"Accept\",o.dataTypes[0]&&o.accepts[o.dataTypes[0]]?o.accepts[o.dataTypes[0]]+(\"*\"!==o.dataTypes[0]?\", \"+Kb+\"; q=0.01\":\"\"):o.accepts[\"*\"]);for(m in o.headers)y.setRequestHeader(m,o.headers[m]);if(o.beforeSend&&(o.beforeSend.call(p,y,o)===!1||k))return y.abort();if(x=\"abort\",t.add(o.complete),y.done(o.success),y.fail(o.error),e=Nb(Jb,o,c,y)){if(y.readyState=1,l&&q.trigger(\"ajaxSend\",[y,o]),k)return y;o.async&&o.timeout>0&&(i=a.setTimeout(function(){y.abort(\"timeout\")},o.timeout));try{k=!1,e.send(v,A)}catch(z){if(k)throw z;A(-1,z)}}else A(-1,\"No Transport\");function A(b,c,d,h){var j,m,n,v,w,x=c;k||(k=!0,i&&a.clearTimeout(i),e=void 0,g=h||\"\",y.readyState=b>0?4:0,j=b>=200&&b<300||304===b,d&&(v=Pb(o,y,d)),v=Qb(o,v,y,j),j?(o.ifModified&&(w=y.getResponseHeader(\"Last-Modified\"),w&&(r.lastModified[f]=w),w=y.getResponseHeader(\"etag\"),w&&(r.etag[f]=w)),204===b||\"HEAD\"===o.type?x=\"nocontent\":304===b?x=\"notmodified\":(x=v.state,m=v.data,n=v.error,j=!n)):(n=x,!b&&x||(x=\"error\",b<0&&(b=0))),y.status=b,y.statusText=(c||x)+\"\",j?s.resolveWith(p,[m,x,y]):s.rejectWith(p,[y,x,n]),y.statusCode(u),u=void 0,l&&q.trigger(j?\"ajaxSuccess\":\"ajaxError\",[y,o,j?m:n]),t.fireWith(p,[y,x]),l&&(q.trigger(\"ajaxComplete\",[y,o]),--r.active||r.event.trigger(\"ajaxStop\")))}return y},getJSON:function(a,b,c){return r.get(a,b,c,\"json\")},getScript:function(a,b){return r.get(a,void 0,b,\"script\")}}),r.each([\"get\",\"post\"],function(a,b){r[b]=function(a,c,d,e){return r.isFunction(c)&&(e=e||d,d=c,c=void 0),r.ajax(r.extend({url:a,type:b,dataType:e,data:c,success:d},r.isPlainObject(a)&&a))}}),r._evalUrl=function(a){return r.ajax({url:a,type:\"GET\",dataType:\"script\",cache:!0,async:!1,global:!1,\"throws\":!0})},r.fn.extend({wrapAll:function(a){var b;return this[0]&&(r.isFunction(a)&&(a=a.call(this[0])),b=r(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this},wrapInner:function(a){return r.isFunction(a)?this.each(function(b){r(this).wrapInner(a.call(this,b))}):this.each(function(){var b=r(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=r.isFunction(a);return this.each(function(c){r(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(a){return this.parent(a).not(\"body\").each(function(){r(this).replaceWith(this.childNodes)}),this}}),r.expr.pseudos.hidden=function(a){return!r.expr.pseudos.visible(a)},r.expr.pseudos.visible=function(a){return!!(a.offsetWidth||a.offsetHeight||a.getClientRects().length)},r.ajaxSettings.xhr=function(){try{return new a.XMLHttpRequest}catch(b){}};var Rb={0:200,1223:204},Sb=r.ajaxSettings.xhr();o.cors=!!Sb&&\"withCredentials\"in Sb,o.ajax=Sb=!!Sb,r.ajaxTransport(function(b){var c,d;if(o.cors||Sb&&!b.crossDomain)return{send:function(e,f){var g,h=b.xhr();if(h.open(b.type,b.url,b.async,b.username,b.password),b.xhrFields)for(g in b.xhrFields)h[g]=b.xhrFields[g];b.mimeType&&h.overrideMimeType&&h.overrideMimeType(b.mimeType),b.crossDomain||e[\"X-Requested-With\"]||(e[\"X-Requested-With\"]=\"XMLHttpRequest\");for(g in e)h.setRequestHeader(g,e[g]);c=function(a){return function(){c&&(c=d=h.onload=h.onerror=h.onabort=h.onreadystatechange=null,\"abort\"===a?h.abort():\"error\"===a?\"number\"!=typeof h.status?f(0,\"error\"):f(h.status,h.statusText):f(Rb[h.status]||h.status,h.statusText,\"text\"!==(h.responseType||\"text\")||\"string\"!=typeof h.responseText?{binary:h.response}:{text:h.responseText},h.getAllResponseHeaders()))}},h.onload=c(),d=h.onerror=c(\"error\"),void 0!==h.onabort?h.onabort=d:h.onreadystatechange=function(){4===h.readyState&&a.setTimeout(function(){c&&d()})},c=c(\"abort\");try{h.send(b.hasContent&&b.data||null)}catch(i){if(c)throw i}},abort:function(){c&&c()}}}),r.ajaxPrefilter(function(a){a.crossDomain&&(a.contents.script=!1)}),r.ajaxSetup({accepts:{script:\"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript\"},contents:{script:/\\b(?:java|ecma)script\\b/},converters:{\"text script\":function(a){return r.globalEval(a),a}}}),r.ajaxPrefilter(\"script\",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type=\"GET\")}),r.ajaxTransport(\"script\",function(a){if(a.crossDomain){var b,c;return{send:function(e,f){b=r(\"<script>\").prop({charset:a.scriptCharset,src:a.url}).on(\"load error\",c=function(a){b.remove(),c=null,a&&f(\"error\"===a.type?404:200,a.type)}),d.head.appendChild(b[0])},abort:function(){c&&c()}}}});var Tb=[],Ub=/(=)\\?(?=&|$)|\\?\\?/;r.ajaxSetup({jsonp:\"callback\",jsonpCallback:function(){var a=Tb.pop()||r.expando+\"_\"+ub++;return this[a]=!0,a}}),r.ajaxPrefilter(\"json jsonp\",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(Ub.test(b.url)?\"url\":\"string\"==typeof b.data&&0===(b.contentType||\"\").indexOf(\"application/x-www-form-urlencoded\")&&Ub.test(b.data)&&\"data\");if(h||\"jsonp\"===b.dataTypes[0])return e=b.jsonpCallback=r.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(Ub,\"$1\"+e):b.jsonp!==!1&&(b.url+=(vb.test(b.url)?\"&\":\"?\")+b.jsonp+\"=\"+e),b.converters[\"script json\"]=function(){return g||r.error(e+\" was not called\"),g[0]},b.dataTypes[0]=\"json\",f=a[e],a[e]=function(){g=arguments},d.always(function(){void 0===f?r(a).removeProp(e):a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,Tb.push(e)),g&&r.isFunction(f)&&f(g[0]),g=f=void 0}),\"script\"}),o.createHTMLDocument=function(){var a=d.implementation.createHTMLDocument(\"\").body;return a.innerHTML=\"<form></form><form></form>\",2===a.childNodes.length}(),r.parseHTML=function(a,b,c){if(\"string\"!=typeof a)return[];\"boolean\"==typeof b&&(c=b,b=!1);var e,f,g;return b||(o.createHTMLDocument?(b=d.implementation.createHTMLDocument(\"\"),e=b.createElement(\"base\"),e.href=d.location.href,b.head.appendChild(e)):b=d),f=C.exec(a),g=!c&&[],f?[b.createElement(f[1])]:(f=qa([a],b,g),g&&g.length&&r(g).remove(),r.merge([],f.childNodes))},r.fn.load=function(a,b,c){var d,e,f,g=this,h=a.indexOf(\" \");return h>-1&&(d=pb(a.slice(h)),a=a.slice(0,h)),r.isFunction(b)?(c=b,b=void 0):b&&\"object\"==typeof b&&(e=\"POST\"),g.length>0&&r.ajax({url:a,type:e||\"GET\",dataType:\"html\",data:b}).done(function(a){f=arguments,g.html(d?r(\"<div>\").append(r.parseHTML(a)).find(d):a)}).always(c&&function(a,b){g.each(function(){c.apply(this,f||[a.responseText,b,a])})}),this},r.each([\"ajaxStart\",\"ajaxStop\",\"ajaxComplete\",\"ajaxError\",\"ajaxSuccess\",\"ajaxSend\"],function(a,b){r.fn[b]=function(a){return this.on(b,a)}}),r.expr.pseudos.animated=function(a){return r.grep(r.timers,function(b){return a===b.elem}).length},r.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=r.css(a,\"position\"),l=r(a),m={};\"static\"===k&&(a.style.position=\"relative\"),h=l.offset(),f=r.css(a,\"top\"),i=r.css(a,\"left\"),j=(\"absolute\"===k||\"fixed\"===k)&&(f+i).indexOf(\"auto\")>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),r.isFunction(b)&&(b=b.call(a,c,r.extend({},h))),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),\"using\"in b?b.using.call(a,m):l.css(m)}},r.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){r.offset.setOffset(this,a,b)});var b,c,d,e,f=this[0];if(f)return f.getClientRects().length?(d=f.getBoundingClientRect(),b=f.ownerDocument,c=b.documentElement,e=b.defaultView,{top:d.top+e.pageYOffset-c.clientTop,left:d.left+e.pageXOffset-c.clientLeft}):{top:0,left:0}},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return\"fixed\"===r.css(c,\"position\")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),B(a[0],\"html\")||(d=a.offset()),d={top:d.top+r.css(a[0],\"borderTopWidth\",!0),left:d.left+r.css(a[0],\"borderLeftWidth\",!0)}),{top:b.top-d.top-r.css(c,\"marginTop\",!0),left:b.left-d.left-r.css(c,\"marginLeft\",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent;while(a&&\"static\"===r.css(a,\"position\"))a=a.offsetParent;return a||ra})}}),r.each({scrollLeft:\"pageXOffset\",scrollTop:\"pageYOffset\"},function(a,b){var c=\"pageYOffset\"===b;r.fn[a]=function(d){return T(this,function(a,d,e){var f;return r.isWindow(a)?f=a:9===a.nodeType&&(f=a.defaultView),void 0===e?f?f[b]:a[d]:void(f?f.scrollTo(c?f.pageXOffset:e,c?e:f.pageYOffset):a[d]=e)},a,d,arguments.length)}}),r.each([\"top\",\"left\"],function(a,b){r.cssHooks[b]=Pa(o.pixelPosition,function(a,c){if(c)return c=Oa(a,b),Ma.test(c)?r(a).position()[b]+\"px\":c})}),r.each({Height:\"height\",Width:\"width\"},function(a,b){r.each({padding:\"inner\"+a,content:b,\"\":\"outer\"+a},function(c,d){r.fn[d]=function(e,f){var g=arguments.length&&(c||\"boolean\"!=typeof e),h=c||(e===!0||f===!0?\"margin\":\"border\");return T(this,function(b,c,e){var f;return r.isWindow(b)?0===d.indexOf(\"outer\")?b[\"inner\"+a]:b.document.documentElement[\"client\"+a]:9===b.nodeType?(f=b.documentElement,Math.max(b.body[\"scroll\"+a],f[\"scroll\"+a],b.body[\"offset\"+a],f[\"offset\"+a],f[\"client\"+a])):void 0===e?r.css(b,c,h):r.style(b,c,e,h)},b,g?e:void 0,g)}})}),r.fn.extend({bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,\"**\"):this.off(b,a||\"**\",c)}}),r.holdReady=function(a){a?r.readyWait++:r.ready(!0)},r.isArray=Array.isArray,r.parseJSON=JSON.parse,r.nodeName=B,\"function\"==typeof define&&define.amd&&define(\"jquery\",[],function(){return r});var Vb=a.jQuery,Wb=a.$;return r.noConflict=function(b){return a.$===r&&(a.$=Wb),b&&a.jQuery===r&&(a.jQuery=Vb),r},b||(a.jQuery=a.$=r),r});"
  },
  {
    "path": "docs/public/js/vue.js",
    "content": "/*!\n * Vue.js v2.3.0\n * (c) 2014-2017 Evan You\n * Released under the MIT License.\n */\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\t(global.Vue = factory());\n}(this, (function () { 'use strict';\n\n/*  */\n\n// these helpers produces better vm code in JS engines due to their\n// explicitness and function inlining\nfunction isUndef (v) {\n  return v === undefined || v === null\n}\n\nfunction isDef (v) {\n  return v !== undefined && v !== null\n}\n\nfunction isTrue (v) {\n  return v === true\n}\n\n/**\n * Check if value is primitive\n */\nfunction isPrimitive (value) {\n  return typeof value === 'string' || typeof value === 'number'\n}\n\n/**\n * Quick object check - this is primarily used to tell\n * Objects from primitive values when we know the value\n * is a JSON-compliant type.\n */\nfunction isObject (obj) {\n  return obj !== null && typeof obj === 'object'\n}\n\nvar toString = Object.prototype.toString;\n\n/**\n * Strict object type check. Only returns true\n * for plain JavaScript objects.\n */\nfunction isPlainObject (obj) {\n  return toString.call(obj) === '[object Object]'\n}\n\nfunction isRegExp (v) {\n  return toString.call(v) === '[object RegExp]'\n}\n\n/**\n * Convert a value to a string that is actually rendered.\n */\nfunction _toString (val) {\n  return val == null\n    ? ''\n    : typeof val === 'object'\n      ? JSON.stringify(val, null, 2)\n      : String(val)\n}\n\n/**\n * Convert a input value to a number for persistence.\n * If the conversion fails, return original string.\n */\nfunction toNumber (val) {\n  var n = parseFloat(val);\n  return isNaN(n) ? val : n\n}\n\n/**\n * Make a map and return a function for checking if a key\n * is in that map.\n */\nfunction makeMap (\n  str,\n  expectsLowerCase\n) {\n  var map = Object.create(null);\n  var list = str.split(',');\n  for (var i = 0; i < list.length; i++) {\n    map[list[i]] = true;\n  }\n  return expectsLowerCase\n    ? function (val) { return map[val.toLowerCase()]; }\n    : function (val) { return map[val]; }\n}\n\n/**\n * Check if a tag is a built-in tag.\n */\nvar isBuiltInTag = makeMap('slot,component', true);\n\n/**\n * Remove an item from an array\n */\nfunction remove (arr, item) {\n  if (arr.length) {\n    var index = arr.indexOf(item);\n    if (index > -1) {\n      return arr.splice(index, 1)\n    }\n  }\n}\n\n/**\n * Check whether the object has the property.\n */\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nfunction hasOwn (obj, key) {\n  return hasOwnProperty.call(obj, key)\n}\n\n/**\n * Create a cached version of a pure function.\n */\nfunction cached (fn) {\n  var cache = Object.create(null);\n  return (function cachedFn (str) {\n    var hit = cache[str];\n    return hit || (cache[str] = fn(str))\n  })\n}\n\n/**\n * Camelize a hyphen-delimited string.\n */\nvar camelizeRE = /-(\\w)/g;\nvar camelize = cached(function (str) {\n  return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })\n});\n\n/**\n * Capitalize a string.\n */\nvar capitalize = cached(function (str) {\n  return str.charAt(0).toUpperCase() + str.slice(1)\n});\n\n/**\n * Hyphenate a camelCase string.\n */\nvar hyphenateRE = /([^-])([A-Z])/g;\nvar hyphenate = cached(function (str) {\n  return str\n    .replace(hyphenateRE, '$1-$2')\n    .replace(hyphenateRE, '$1-$2')\n    .toLowerCase()\n});\n\n/**\n * Simple bind, faster than native\n */\nfunction bind (fn, ctx) {\n  function boundFn (a) {\n    var l = arguments.length;\n    return l\n      ? l > 1\n        ? fn.apply(ctx, arguments)\n        : fn.call(ctx, a)\n      : fn.call(ctx)\n  }\n  // record original fn length\n  boundFn._length = fn.length;\n  return boundFn\n}\n\n/**\n * Convert an Array-like object to a real Array.\n */\nfunction toArray (list, start) {\n  start = start || 0;\n  var i = list.length - start;\n  var ret = new Array(i);\n  while (i--) {\n    ret[i] = list[i + start];\n  }\n  return ret\n}\n\n/**\n * Mix properties into target object.\n */\nfunction extend (to, _from) {\n  for (var key in _from) {\n    to[key] = _from[key];\n  }\n  return to\n}\n\n/**\n * Merge an Array of Objects into a single Object.\n */\nfunction toObject (arr) {\n  var res = {};\n  for (var i = 0; i < arr.length; i++) {\n    if (arr[i]) {\n      extend(res, arr[i]);\n    }\n  }\n  return res\n}\n\n/**\n * Perform no operation.\n */\nfunction noop () {}\n\n/**\n * Always return false.\n */\nvar no = function () { return false; };\n\n/**\n * Return same value\n */\nvar identity = function (_) { return _; };\n\n/**\n * Generate a static keys string from compiler modules.\n */\nfunction genStaticKeys (modules) {\n  return modules.reduce(function (keys, m) {\n    return keys.concat(m.staticKeys || [])\n  }, []).join(',')\n}\n\n/**\n * Check if two values are loosely equal - that is,\n * if they are plain objects, do they have the same shape?\n */\nfunction looseEqual (a, b) {\n  var isObjectA = isObject(a);\n  var isObjectB = isObject(b);\n  if (isObjectA && isObjectB) {\n    try {\n      return JSON.stringify(a) === JSON.stringify(b)\n    } catch (e) {\n      // possible circular reference\n      return a === b\n    }\n  } else if (!isObjectA && !isObjectB) {\n    return String(a) === String(b)\n  } else {\n    return false\n  }\n}\n\nfunction looseIndexOf (arr, val) {\n  for (var i = 0; i < arr.length; i++) {\n    if (looseEqual(arr[i], val)) { return i }\n  }\n  return -1\n}\n\n/**\n * Ensure a function is called only once.\n */\nfunction once (fn) {\n  var called = false;\n  return function () {\n    if (!called) {\n      called = true;\n      fn.apply(this, arguments);\n    }\n  }\n}\n\nvar SSR_ATTR = 'data-server-rendered';\n\nvar ASSET_TYPES = [\n  'component',\n  'directive',\n  'filter'\n];\n\nvar LIFECYCLE_HOOKS = [\n  'beforeCreate',\n  'created',\n  'beforeMount',\n  'mounted',\n  'beforeUpdate',\n  'updated',\n  'beforeDestroy',\n  'destroyed',\n  'activated',\n  'deactivated'\n];\n\n/*  */\n\nvar config = ({\n  /**\n   * Option merge strategies (used in core/util/options)\n   */\n  optionMergeStrategies: Object.create(null),\n\n  /**\n   * Whether to suppress warnings.\n   */\n  silent: false,\n\n  /**\n   * Show production mode tip message on boot?\n   */\n  productionTip: \"development\" !== 'production',\n\n  /**\n   * Whether to enable devtools\n   */\n  devtools: \"development\" !== 'production',\n\n  /**\n   * Whether to record perf\n   */\n  performance: false,\n\n  /**\n   * Error handler for watcher errors\n   */\n  errorHandler: null,\n\n  /**\n   * Ignore certain custom elements\n   */\n  ignoredElements: [],\n\n  /**\n   * Custom user key aliases for v-on\n   */\n  keyCodes: Object.create(null),\n\n  /**\n   * Check if a tag is reserved so that it cannot be registered as a\n   * component. This is platform-dependent and may be overwritten.\n   */\n  isReservedTag: no,\n\n  /**\n   * Check if an attribute is reserved so that it cannot be used as a component\n   * prop. This is platform-dependent and may be overwritten.\n   */\n  isReservedAttr: no,\n\n  /**\n   * Check if a tag is an unknown element.\n   * Platform-dependent.\n   */\n  isUnknownElement: no,\n\n  /**\n   * Get the namespace of an element\n   */\n  getTagNamespace: noop,\n\n  /**\n   * Parse the real tag name for the specific platform.\n   */\n  parsePlatformTagName: identity,\n\n  /**\n   * Check if an attribute must be bound using property, e.g. value\n   * Platform-dependent.\n   */\n  mustUseProp: no,\n\n  /**\n   * Exposed for legacy reasons\n   */\n  _lifecycleHooks: LIFECYCLE_HOOKS\n});\n\n/*  */\n\nvar emptyObject = Object.freeze({});\n\n/**\n * Check if a string starts with $ or _\n */\nfunction isReserved (str) {\n  var c = (str + '').charCodeAt(0);\n  return c === 0x24 || c === 0x5F\n}\n\n/**\n * Define a property.\n */\nfunction def (obj, key, val, enumerable) {\n  Object.defineProperty(obj, key, {\n    value: val,\n    enumerable: !!enumerable,\n    writable: true,\n    configurable: true\n  });\n}\n\n/**\n * Parse simple path.\n */\nvar bailRE = /[^\\w.$]/;\nfunction parsePath (path) {\n  if (bailRE.test(path)) {\n    return\n  }\n  var segments = path.split('.');\n  return function (obj) {\n    for (var i = 0; i < segments.length; i++) {\n      if (!obj) { return }\n      obj = obj[segments[i]];\n    }\n    return obj\n  }\n}\n\nvar warn = noop;\nvar tip = noop;\nvar formatComponentName;\n\n{\n  var hasConsole = typeof console !== 'undefined';\n  var classifyRE = /(?:^|[-_])(\\w)/g;\n  var classify = function (str) { return str\n    .replace(classifyRE, function (c) { return c.toUpperCase(); })\n    .replace(/[-_]/g, ''); };\n\n  warn = function (msg, vm) {\n    if (hasConsole && (!config.silent)) {\n      console.error(\"[Vue warn]: \" + msg + (\n        vm ? generateComponentTrace(vm) : ''\n      ));\n    }\n  };\n\n  tip = function (msg, vm) {\n    if (hasConsole && (!config.silent)) {\n      console.warn(\"[Vue tip]: \" + msg + (\n        vm ? generateComponentTrace(vm) : ''\n      ));\n    }\n  };\n\n  formatComponentName = function (vm, includeFile) {\n    if (vm.$root === vm) {\n      return '<Root>'\n    }\n    var name = typeof vm === 'string'\n      ? vm\n      : typeof vm === 'function' && vm.options\n        ? vm.options.name\n        : vm._isVue\n          ? vm.$options.name || vm.$options._componentTag\n          : vm.name;\n\n    var file = vm._isVue && vm.$options.__file;\n    if (!name && file) {\n      var match = file.match(/([^/\\\\]+)\\.vue$/);\n      name = match && match[1];\n    }\n\n    return (\n      (name ? (\"<\" + (classify(name)) + \">\") : \"<Anonymous>\") +\n      (file && includeFile !== false ? (\" at \" + file) : '')\n    )\n  };\n\n  var repeat = function (str, n) {\n    var res = '';\n    while (n) {\n      if (n % 2 === 1) { res += str; }\n      if (n > 1) { str += str; }\n      n >>= 1;\n    }\n    return res\n  };\n\n  var generateComponentTrace = function (vm) {\n    if (vm._isVue && vm.$parent) {\n      var tree = [];\n      var currentRecursiveSequence = 0;\n      while (vm) {\n        if (tree.length > 0) {\n          var last = tree[tree.length - 1];\n          if (last.constructor === vm.constructor) {\n            currentRecursiveSequence++;\n            vm = vm.$parent;\n            continue\n          } else if (currentRecursiveSequence > 0) {\n            tree[tree.length - 1] = [last, currentRecursiveSequence];\n            currentRecursiveSequence = 0;\n          }\n        }\n        tree.push(vm);\n        vm = vm.$parent;\n      }\n      return '\\n\\nfound in\\n\\n' + tree\n        .map(function (vm, i) { return (\"\" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm)\n            ? ((formatComponentName(vm[0])) + \"... (\" + (vm[1]) + \" recursive calls)\")\n            : formatComponentName(vm))); })\n        .join('\\n')\n    } else {\n      return (\"\\n\\n(found in \" + (formatComponentName(vm)) + \")\")\n    }\n  };\n}\n\nfunction handleError (err, vm, info) {\n  if (config.errorHandler) {\n    config.errorHandler.call(null, err, vm, info);\n  } else {\n    {\n      warn((\"Error in \" + info + \": \\\"\" + (err.toString()) + \"\\\"\"), vm);\n    }\n    /* istanbul ignore else */\n    if (inBrowser && typeof console !== 'undefined') {\n      console.error(err);\n    } else {\n      throw err\n    }\n  }\n}\n\n/*  */\n/* globals MutationObserver */\n\n// can we use __proto__?\nvar hasProto = '__proto__' in {};\n\n// Browser environment sniffing\nvar inBrowser = typeof window !== 'undefined';\nvar UA = inBrowser && window.navigator.userAgent.toLowerCase();\nvar isIE = UA && /msie|trident/.test(UA);\nvar isIE9 = UA && UA.indexOf('msie 9.0') > 0;\nvar isEdge = UA && UA.indexOf('edge/') > 0;\nvar isAndroid = UA && UA.indexOf('android') > 0;\nvar isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);\nvar isChrome = UA && /chrome\\/\\d+/.test(UA) && !isEdge;\n\nvar supportsPassive = false;\nif (inBrowser) {\n  try {\n    var opts = {};\n    Object.defineProperty(opts, 'passive', ({\n      get: function get () {\n        /* istanbul ignore next */\n        supportsPassive = true;\n      }\n    } )); // https://github.com/facebook/flow/issues/285\n    window.addEventListener('test-passive', null, opts);\n  } catch (e) {}\n}\n\n// this needs to be lazy-evaled because vue may be required before\n// vue-server-renderer can set VUE_ENV\nvar _isServer;\nvar isServerRendering = function () {\n  if (_isServer === undefined) {\n    /* istanbul ignore if */\n    if (!inBrowser && typeof global !== 'undefined') {\n      // detect presence of vue-server-renderer and avoid\n      // Webpack shimming the process\n      _isServer = global['process'].env.VUE_ENV === 'server';\n    } else {\n      _isServer = false;\n    }\n  }\n  return _isServer\n};\n\n// detect devtools\nvar devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;\n\n/* istanbul ignore next */\nfunction isNative (Ctor) {\n  return typeof Ctor === 'function' && /native code/.test(Ctor.toString())\n}\n\nvar hasSymbol =\n  typeof Symbol !== 'undefined' && isNative(Symbol) &&\n  typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);\n\n/**\n * Defer a task to execute it asynchronously.\n */\nvar nextTick = (function () {\n  var callbacks = [];\n  var pending = false;\n  var timerFunc;\n\n  function nextTickHandler () {\n    pending = false;\n    var copies = callbacks.slice(0);\n    callbacks.length = 0;\n    for (var i = 0; i < copies.length; i++) {\n      copies[i]();\n    }\n  }\n\n  // the nextTick behavior leverages the microtask queue, which can be accessed\n  // via either native Promise.then or MutationObserver.\n  // MutationObserver has wider support, however it is seriously bugged in\n  // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It\n  // completely stops working after triggering a few times... so, if native\n  // Promise is available, we will use it:\n  /* istanbul ignore if */\n  if (typeof Promise !== 'undefined' && isNative(Promise)) {\n    var p = Promise.resolve();\n    var logError = function (err) { console.error(err); };\n    timerFunc = function () {\n      p.then(nextTickHandler).catch(logError);\n      // in problematic UIWebViews, Promise.then doesn't completely break, but\n      // it can get stuck in a weird state where callbacks are pushed into the\n      // microtask queue but the queue isn't being flushed, until the browser\n      // needs to do some other work, e.g. handle a timer. Therefore we can\n      // \"force\" the microtask queue to be flushed by adding an empty timer.\n      if (isIOS) { setTimeout(noop); }\n    };\n  } else if (typeof MutationObserver !== 'undefined' && (\n    isNative(MutationObserver) ||\n    // PhantomJS and iOS 7.x\n    MutationObserver.toString() === '[object MutationObserverConstructor]'\n  )) {\n    // use MutationObserver where native Promise is not available,\n    // e.g. PhantomJS IE11, iOS7, Android 4.4\n    var counter = 1;\n    var observer = new MutationObserver(nextTickHandler);\n    var textNode = document.createTextNode(String(counter));\n    observer.observe(textNode, {\n      characterData: true\n    });\n    timerFunc = function () {\n      counter = (counter + 1) % 2;\n      textNode.data = String(counter);\n    };\n  } else {\n    // fallback to setTimeout\n    /* istanbul ignore next */\n    timerFunc = function () {\n      setTimeout(nextTickHandler, 0);\n    };\n  }\n\n  return function queueNextTick (cb, ctx) {\n    var _resolve;\n    callbacks.push(function () {\n      if (cb) {\n        try {\n          cb.call(ctx);\n        } catch (e) {\n          handleError(e, ctx, 'nextTick');\n        }\n      } else if (_resolve) {\n        _resolve(ctx);\n      }\n    });\n    if (!pending) {\n      pending = true;\n      timerFunc();\n    }\n    if (!cb && typeof Promise !== 'undefined') {\n      return new Promise(function (resolve, reject) {\n        _resolve = resolve;\n      })\n    }\n  }\n})();\n\nvar _Set;\n/* istanbul ignore if */\nif (typeof Set !== 'undefined' && isNative(Set)) {\n  // use native Set when available.\n  _Set = Set;\n} else {\n  // a non-standard Set polyfill that only works with primitive keys.\n  _Set = (function () {\n    function Set () {\n      this.set = Object.create(null);\n    }\n    Set.prototype.has = function has (key) {\n      return this.set[key] === true\n    };\n    Set.prototype.add = function add (key) {\n      this.set[key] = true;\n    };\n    Set.prototype.clear = function clear () {\n      this.set = Object.create(null);\n    };\n\n    return Set;\n  }());\n}\n\n/*  */\n\n\nvar uid = 0;\n\n/**\n * A dep is an observable that can have multiple\n * directives subscribing to it.\n */\nvar Dep = function Dep () {\n  this.id = uid++;\n  this.subs = [];\n};\n\nDep.prototype.addSub = function addSub (sub) {\n  this.subs.push(sub);\n};\n\nDep.prototype.removeSub = function removeSub (sub) {\n  remove(this.subs, sub);\n};\n\nDep.prototype.depend = function depend () {\n  if (Dep.target) {\n    Dep.target.addDep(this);\n  }\n};\n\nDep.prototype.notify = function notify () {\n  // stabilize the subscriber list first\n  var subs = this.subs.slice();\n  for (var i = 0, l = subs.length; i < l; i++) {\n    subs[i].update();\n  }\n};\n\n// the current target watcher being evaluated.\n// this is globally unique because there could be only one\n// watcher being evaluated at any time.\nDep.target = null;\nvar targetStack = [];\n\nfunction pushTarget (_target) {\n  if (Dep.target) { targetStack.push(Dep.target); }\n  Dep.target = _target;\n}\n\nfunction popTarget () {\n  Dep.target = targetStack.pop();\n}\n\n/*\n * not type checking this file because flow doesn't play well with\n * dynamically accessing methods on Array prototype\n */\n\nvar arrayProto = Array.prototype;\nvar arrayMethods = Object.create(arrayProto);[\n  'push',\n  'pop',\n  'shift',\n  'unshift',\n  'splice',\n  'sort',\n  'reverse'\n]\n.forEach(function (method) {\n  // cache original method\n  var original = arrayProto[method];\n  def(arrayMethods, method, function mutator () {\n    var arguments$1 = arguments;\n\n    // avoid leaking arguments:\n    // http://jsperf.com/closure-with-arguments\n    var i = arguments.length;\n    var args = new Array(i);\n    while (i--) {\n      args[i] = arguments$1[i];\n    }\n    var result = original.apply(this, args);\n    var ob = this.__ob__;\n    var inserted;\n    switch (method) {\n      case 'push':\n        inserted = args;\n        break\n      case 'unshift':\n        inserted = args;\n        break\n      case 'splice':\n        inserted = args.slice(2);\n        break\n    }\n    if (inserted) { ob.observeArray(inserted); }\n    // notify change\n    ob.dep.notify();\n    return result\n  });\n});\n\n/*  */\n\nvar arrayKeys = Object.getOwnPropertyNames(arrayMethods);\n\n/**\n * By default, when a reactive property is set, the new value is\n * also converted to become reactive. However when passing down props,\n * we don't want to force conversion because the value may be a nested value\n * under a frozen data structure. Converting it would defeat the optimization.\n */\nvar observerState = {\n  shouldConvert: true,\n  isSettingProps: false\n};\n\n/**\n * Observer class that are attached to each observed\n * object. Once attached, the observer converts target\n * object's property keys into getter/setters that\n * collect dependencies and dispatches updates.\n */\nvar Observer = function Observer (value) {\n  this.value = value;\n  this.dep = new Dep();\n  this.vmCount = 0;\n  def(value, '__ob__', this);\n  if (Array.isArray(value)) {\n    var augment = hasProto\n      ? protoAugment\n      : copyAugment;\n    augment(value, arrayMethods, arrayKeys);\n    this.observeArray(value);\n  } else {\n    this.walk(value);\n  }\n};\n\n/**\n * Walk through each property and convert them into\n * getter/setters. This method should only be called when\n * value type is Object.\n */\nObserver.prototype.walk = function walk (obj) {\n  var keys = Object.keys(obj);\n  for (var i = 0; i < keys.length; i++) {\n    defineReactive$$1(obj, keys[i], obj[keys[i]]);\n  }\n};\n\n/**\n * Observe a list of Array items.\n */\nObserver.prototype.observeArray = function observeArray (items) {\n  for (var i = 0, l = items.length; i < l; i++) {\n    observe(items[i]);\n  }\n};\n\n// helpers\n\n/**\n * Augment an target Object or Array by intercepting\n * the prototype chain using __proto__\n */\nfunction protoAugment (target, src) {\n  /* eslint-disable no-proto */\n  target.__proto__ = src;\n  /* eslint-enable no-proto */\n}\n\n/**\n * Augment an target Object or Array by defining\n * hidden properties.\n */\n/* istanbul ignore next */\nfunction copyAugment (target, src, keys) {\n  for (var i = 0, l = keys.length; i < l; i++) {\n    var key = keys[i];\n    def(target, key, src[key]);\n  }\n}\n\n/**\n * Attempt to create an observer instance for a value,\n * returns the new observer if successfully observed,\n * or the existing observer if the value already has one.\n */\nfunction observe (value, asRootData) {\n  if (!isObject(value)) {\n    return\n  }\n  var ob;\n  if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {\n    ob = value.__ob__;\n  } else if (\n    observerState.shouldConvert &&\n    !isServerRendering() &&\n    (Array.isArray(value) || isPlainObject(value)) &&\n    Object.isExtensible(value) &&\n    !value._isVue\n  ) {\n    ob = new Observer(value);\n  }\n  if (asRootData && ob) {\n    ob.vmCount++;\n  }\n  return ob\n}\n\n/**\n * Define a reactive property on an Object.\n */\nfunction defineReactive$$1 (\n  obj,\n  key,\n  val,\n  customSetter\n) {\n  var dep = new Dep();\n\n  var property = Object.getOwnPropertyDescriptor(obj, key);\n  if (property && property.configurable === false) {\n    return\n  }\n\n  // cater for pre-defined getter/setters\n  var getter = property && property.get;\n  var setter = property && property.set;\n\n  var childOb = observe(val);\n  Object.defineProperty(obj, key, {\n    enumerable: true,\n    configurable: true,\n    get: function reactiveGetter () {\n      var value = getter ? getter.call(obj) : val;\n      if (Dep.target) {\n        dep.depend();\n        if (childOb) {\n          childOb.dep.depend();\n        }\n        if (Array.isArray(value)) {\n          dependArray(value);\n        }\n      }\n      return value\n    },\n    set: function reactiveSetter (newVal) {\n      var value = getter ? getter.call(obj) : val;\n      /* eslint-disable no-self-compare */\n      if (newVal === value || (newVal !== newVal && value !== value)) {\n        return\n      }\n      /* eslint-enable no-self-compare */\n      if (\"development\" !== 'production' && customSetter) {\n        customSetter();\n      }\n      if (setter) {\n        setter.call(obj, newVal);\n      } else {\n        val = newVal;\n      }\n      childOb = observe(newVal);\n      dep.notify();\n    }\n  });\n}\n\n/**\n * Set a property on an object. Adds the new property and\n * triggers change notification if the property doesn't\n * already exist.\n */\nfunction set (target, key, val) {\n  if (Array.isArray(target) && typeof key === 'number') {\n    target.length = Math.max(target.length, key);\n    target.splice(key, 1, val);\n    return val\n  }\n  if (hasOwn(target, key)) {\n    target[key] = val;\n    return val\n  }\n  var ob = (target ).__ob__;\n  if (target._isVue || (ob && ob.vmCount)) {\n    \"development\" !== 'production' && warn(\n      'Avoid adding reactive properties to a Vue instance or its root $data ' +\n      'at runtime - declare it upfront in the data option.'\n    );\n    return val\n  }\n  if (!ob) {\n    target[key] = val;\n    return val\n  }\n  defineReactive$$1(ob.value, key, val);\n  ob.dep.notify();\n  return val\n}\n\n/**\n * Delete a property and trigger change if necessary.\n */\nfunction del (target, key) {\n  if (Array.isArray(target) && typeof key === 'number') {\n    target.splice(key, 1);\n    return\n  }\n  var ob = (target ).__ob__;\n  if (target._isVue || (ob && ob.vmCount)) {\n    \"development\" !== 'production' && warn(\n      'Avoid deleting properties on a Vue instance or its root $data ' +\n      '- just set it to null.'\n    );\n    return\n  }\n  if (!hasOwn(target, key)) {\n    return\n  }\n  delete target[key];\n  if (!ob) {\n    return\n  }\n  ob.dep.notify();\n}\n\n/**\n * Collect dependencies on array elements when the array is touched, since\n * we cannot intercept array element access like property getters.\n */\nfunction dependArray (value) {\n  for (var e = (void 0), i = 0, l = value.length; i < l; i++) {\n    e = value[i];\n    e && e.__ob__ && e.__ob__.dep.depend();\n    if (Array.isArray(e)) {\n      dependArray(e);\n    }\n  }\n}\n\n/*  */\n\n/**\n * Option overwriting strategies are functions that handle\n * how to merge a parent option value and a child option\n * value into the final value.\n */\nvar strats = config.optionMergeStrategies;\n\n/**\n * Options with restrictions\n */\n{\n  strats.el = strats.propsData = function (parent, child, vm, key) {\n    if (!vm) {\n      warn(\n        \"option \\\"\" + key + \"\\\" can only be used during instance \" +\n        'creation with the `new` keyword.'\n      );\n    }\n    return defaultStrat(parent, child)\n  };\n}\n\n/**\n * Helper that recursively merges two data objects together.\n */\nfunction mergeData (to, from) {\n  if (!from) { return to }\n  var key, toVal, fromVal;\n  var keys = Object.keys(from);\n  for (var i = 0; i < keys.length; i++) {\n    key = keys[i];\n    toVal = to[key];\n    fromVal = from[key];\n    if (!hasOwn(to, key)) {\n      set(to, key, fromVal);\n    } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {\n      mergeData(toVal, fromVal);\n    }\n  }\n  return to\n}\n\n/**\n * Data\n */\nstrats.data = function (\n  parentVal,\n  childVal,\n  vm\n) {\n  if (!vm) {\n    // in a Vue.extend merge, both should be functions\n    if (!childVal) {\n      return parentVal\n    }\n    if (typeof childVal !== 'function') {\n      \"development\" !== 'production' && warn(\n        'The \"data\" option should be a function ' +\n        'that returns a per-instance value in component ' +\n        'definitions.',\n        vm\n      );\n      return parentVal\n    }\n    if (!parentVal) {\n      return childVal\n    }\n    // when parentVal & childVal are both present,\n    // we need to return a function that returns the\n    // merged result of both functions... no need to\n    // check if parentVal is a function here because\n    // it has to be a function to pass previous merges.\n    return function mergedDataFn () {\n      return mergeData(\n        childVal.call(this),\n        parentVal.call(this)\n      )\n    }\n  } else if (parentVal || childVal) {\n    return function mergedInstanceDataFn () {\n      // instance merge\n      var instanceData = typeof childVal === 'function'\n        ? childVal.call(vm)\n        : childVal;\n      var defaultData = typeof parentVal === 'function'\n        ? parentVal.call(vm)\n        : undefined;\n      if (instanceData) {\n        return mergeData(instanceData, defaultData)\n      } else {\n        return defaultData\n      }\n    }\n  }\n};\n\n/**\n * Hooks and props are merged as arrays.\n */\nfunction mergeHook (\n  parentVal,\n  childVal\n) {\n  return childVal\n    ? parentVal\n      ? parentVal.concat(childVal)\n      : Array.isArray(childVal)\n        ? childVal\n        : [childVal]\n    : parentVal\n}\n\nLIFECYCLE_HOOKS.forEach(function (hook) {\n  strats[hook] = mergeHook;\n});\n\n/**\n * Assets\n *\n * When a vm is present (instance creation), we need to do\n * a three-way merge between constructor options, instance\n * options and parent options.\n */\nfunction mergeAssets (parentVal, childVal) {\n  var res = Object.create(parentVal || null);\n  return childVal\n    ? extend(res, childVal)\n    : res\n}\n\nASSET_TYPES.forEach(function (type) {\n  strats[type + 's'] = mergeAssets;\n});\n\n/**\n * Watchers.\n *\n * Watchers hashes should not overwrite one\n * another, so we merge them as arrays.\n */\nstrats.watch = function (parentVal, childVal) {\n  /* istanbul ignore if */\n  if (!childVal) { return Object.create(parentVal || null) }\n  if (!parentVal) { return childVal }\n  var ret = {};\n  extend(ret, parentVal);\n  for (var key in childVal) {\n    var parent = ret[key];\n    var child = childVal[key];\n    if (parent && !Array.isArray(parent)) {\n      parent = [parent];\n    }\n    ret[key] = parent\n      ? parent.concat(child)\n      : [child];\n  }\n  return ret\n};\n\n/**\n * Other object hashes.\n */\nstrats.props =\nstrats.methods =\nstrats.computed = function (parentVal, childVal) {\n  if (!childVal) { return Object.create(parentVal || null) }\n  if (!parentVal) { return childVal }\n  var ret = Object.create(null);\n  extend(ret, parentVal);\n  extend(ret, childVal);\n  return ret\n};\n\n/**\n * Default strategy.\n */\nvar defaultStrat = function (parentVal, childVal) {\n  return childVal === undefined\n    ? parentVal\n    : childVal\n};\n\n/**\n * Validate component names\n */\nfunction checkComponents (options) {\n  for (var key in options.components) {\n    var lower = key.toLowerCase();\n    if (isBuiltInTag(lower) || config.isReservedTag(lower)) {\n      warn(\n        'Do not use built-in or reserved HTML elements as component ' +\n        'id: ' + key\n      );\n    }\n  }\n}\n\n/**\n * Ensure all props option syntax are normalized into the\n * Object-based format.\n */\nfunction normalizeProps (options) {\n  var props = options.props;\n  if (!props) { return }\n  var res = {};\n  var i, val, name;\n  if (Array.isArray(props)) {\n    i = props.length;\n    while (i--) {\n      val = props[i];\n      if (typeof val === 'string') {\n        name = camelize(val);\n        res[name] = { type: null };\n      } else {\n        warn('props must be strings when using array syntax.');\n      }\n    }\n  } else if (isPlainObject(props)) {\n    for (var key in props) {\n      val = props[key];\n      name = camelize(key);\n      res[name] = isPlainObject(val)\n        ? val\n        : { type: val };\n    }\n  }\n  options.props = res;\n}\n\n/**\n * Normalize raw function directives into object format.\n */\nfunction normalizeDirectives (options) {\n  var dirs = options.directives;\n  if (dirs) {\n    for (var key in dirs) {\n      var def = dirs[key];\n      if (typeof def === 'function') {\n        dirs[key] = { bind: def, update: def };\n      }\n    }\n  }\n}\n\n/**\n * Merge two option objects into a new one.\n * Core utility used in both instantiation and inheritance.\n */\nfunction mergeOptions (\n  parent,\n  child,\n  vm\n) {\n  {\n    checkComponents(child);\n  }\n\n  if (typeof child === 'function') {\n    child = child.options;\n  }\n\n  normalizeProps(child);\n  normalizeDirectives(child);\n  var extendsFrom = child.extends;\n  if (extendsFrom) {\n    parent = mergeOptions(parent, extendsFrom, vm);\n  }\n  if (child.mixins) {\n    for (var i = 0, l = child.mixins.length; i < l; i++) {\n      parent = mergeOptions(parent, child.mixins[i], vm);\n    }\n  }\n  var options = {};\n  var key;\n  for (key in parent) {\n    mergeField(key);\n  }\n  for (key in child) {\n    if (!hasOwn(parent, key)) {\n      mergeField(key);\n    }\n  }\n  function mergeField (key) {\n    var strat = strats[key] || defaultStrat;\n    options[key] = strat(parent[key], child[key], vm, key);\n  }\n  return options\n}\n\n/**\n * Resolve an asset.\n * This function is used because child instances need access\n * to assets defined in its ancestor chain.\n */\nfunction resolveAsset (\n  options,\n  type,\n  id,\n  warnMissing\n) {\n  /* istanbul ignore if */\n  if (typeof id !== 'string') {\n    return\n  }\n  var assets = options[type];\n  // check local registration variations first\n  if (hasOwn(assets, id)) { return assets[id] }\n  var camelizedId = camelize(id);\n  if (hasOwn(assets, camelizedId)) { return assets[camelizedId] }\n  var PascalCaseId = capitalize(camelizedId);\n  if (hasOwn(assets, PascalCaseId)) { return assets[PascalCaseId] }\n  // fallback to prototype chain\n  var res = assets[id] || assets[camelizedId] || assets[PascalCaseId];\n  if (\"development\" !== 'production' && warnMissing && !res) {\n    warn(\n      'Failed to resolve ' + type.slice(0, -1) + ': ' + id,\n      options\n    );\n  }\n  return res\n}\n\n/*  */\n\nfunction validateProp (\n  key,\n  propOptions,\n  propsData,\n  vm\n) {\n  var prop = propOptions[key];\n  var absent = !hasOwn(propsData, key);\n  var value = propsData[key];\n  // handle boolean props\n  if (isType(Boolean, prop.type)) {\n    if (absent && !hasOwn(prop, 'default')) {\n      value = false;\n    } else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) {\n      value = true;\n    }\n  }\n  // check default value\n  if (value === undefined) {\n    value = getPropDefaultValue(vm, prop, key);\n    // since the default value is a fresh copy,\n    // make sure to observe it.\n    var prevShouldConvert = observerState.shouldConvert;\n    observerState.shouldConvert = true;\n    observe(value);\n    observerState.shouldConvert = prevShouldConvert;\n  }\n  {\n    assertProp(prop, key, value, vm, absent);\n  }\n  return value\n}\n\n/**\n * Get the default value of a prop.\n */\nfunction getPropDefaultValue (vm, prop, key) {\n  // no default, return undefined\n  if (!hasOwn(prop, 'default')) {\n    return undefined\n  }\n  var def = prop.default;\n  // warn against non-factory defaults for Object & Array\n  if (\"development\" !== 'production' && isObject(def)) {\n    warn(\n      'Invalid default value for prop \"' + key + '\": ' +\n      'Props with type Object/Array must use a factory function ' +\n      'to return the default value.',\n      vm\n    );\n  }\n  // the raw prop value was also undefined from previous render,\n  // return previous default value to avoid unnecessary watcher trigger\n  if (vm && vm.$options.propsData &&\n    vm.$options.propsData[key] === undefined &&\n    vm._props[key] !== undefined) {\n    return vm._props[key]\n  }\n  // call factory function for non-Function types\n  // a value is Function if its prototype is function even across different execution context\n  return typeof def === 'function' && getType(prop.type) !== 'Function'\n    ? def.call(vm)\n    : def\n}\n\n/**\n * Assert whether a prop is valid.\n */\nfunction assertProp (\n  prop,\n  name,\n  value,\n  vm,\n  absent\n) {\n  if (prop.required && absent) {\n    warn(\n      'Missing required prop: \"' + name + '\"',\n      vm\n    );\n    return\n  }\n  if (value == null && !prop.required) {\n    return\n  }\n  var type = prop.type;\n  var valid = !type || type === true;\n  var expectedTypes = [];\n  if (type) {\n    if (!Array.isArray(type)) {\n      type = [type];\n    }\n    for (var i = 0; i < type.length && !valid; i++) {\n      var assertedType = assertType(value, type[i]);\n      expectedTypes.push(assertedType.expectedType || '');\n      valid = assertedType.valid;\n    }\n  }\n  if (!valid) {\n    warn(\n      'Invalid prop: type check failed for prop \"' + name + '\".' +\n      ' Expected ' + expectedTypes.map(capitalize).join(', ') +\n      ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',\n      vm\n    );\n    return\n  }\n  var validator = prop.validator;\n  if (validator) {\n    if (!validator(value)) {\n      warn(\n        'Invalid prop: custom validator check failed for prop \"' + name + '\".',\n        vm\n      );\n    }\n  }\n}\n\nvar simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/;\n\nfunction assertType (value, type) {\n  var valid;\n  var expectedType = getType(type);\n  if (simpleCheckRE.test(expectedType)) {\n    valid = typeof value === expectedType.toLowerCase();\n  } else if (expectedType === 'Object') {\n    valid = isPlainObject(value);\n  } else if (expectedType === 'Array') {\n    valid = Array.isArray(value);\n  } else {\n    valid = value instanceof type;\n  }\n  return {\n    valid: valid,\n    expectedType: expectedType\n  }\n}\n\n/**\n * Use function string name to check built-in types,\n * because a simple equality check will fail when running\n * across different vms / iframes.\n */\nfunction getType (fn) {\n  var match = fn && fn.toString().match(/^\\s*function (\\w+)/);\n  return match ? match[1] : ''\n}\n\nfunction isType (type, fn) {\n  if (!Array.isArray(fn)) {\n    return getType(fn) === getType(type)\n  }\n  for (var i = 0, len = fn.length; i < len; i++) {\n    if (getType(fn[i]) === getType(type)) {\n      return true\n    }\n  }\n  /* istanbul ignore next */\n  return false\n}\n\nvar mark;\nvar measure;\n\n{\n  var perf = inBrowser && window.performance;\n  /* istanbul ignore if */\n  if (\n    perf &&\n    perf.mark &&\n    perf.measure &&\n    perf.clearMarks &&\n    perf.clearMeasures\n  ) {\n    mark = function (tag) { return perf.mark(tag); };\n    measure = function (name, startTag, endTag) {\n      perf.measure(name, startTag, endTag);\n      perf.clearMarks(startTag);\n      perf.clearMarks(endTag);\n      perf.clearMeasures(name);\n    };\n  }\n}\n\n/* not type checking this file because flow doesn't play well with Proxy */\n\nvar initProxy;\n\n{\n  var allowedGlobals = makeMap(\n    'Infinity,undefined,NaN,isFinite,isNaN,' +\n    'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +\n    'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +\n    'require' // for Webpack/Browserify\n  );\n\n  var warnNonPresent = function (target, key) {\n    warn(\n      \"Property or method \\\"\" + key + \"\\\" is not defined on the instance but \" +\n      \"referenced during render. Make sure to declare reactive data \" +\n      \"properties in the data option.\",\n      target\n    );\n  };\n\n  var hasProxy =\n    typeof Proxy !== 'undefined' &&\n    Proxy.toString().match(/native code/);\n\n  if (hasProxy) {\n    var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta');\n    config.keyCodes = new Proxy(config.keyCodes, {\n      set: function set (target, key, value) {\n        if (isBuiltInModifier(key)) {\n          warn((\"Avoid overwriting built-in modifier in config.keyCodes: .\" + key));\n          return false\n        } else {\n          target[key] = value;\n          return true\n        }\n      }\n    });\n  }\n\n  var hasHandler = {\n    has: function has (target, key) {\n      var has = key in target;\n      var isAllowed = allowedGlobals(key) || key.charAt(0) === '_';\n      if (!has && !isAllowed) {\n        warnNonPresent(target, key);\n      }\n      return has || !isAllowed\n    }\n  };\n\n  var getHandler = {\n    get: function get (target, key) {\n      if (typeof key === 'string' && !(key in target)) {\n        warnNonPresent(target, key);\n      }\n      return target[key]\n    }\n  };\n\n  initProxy = function initProxy (vm) {\n    if (hasProxy) {\n      // determine which proxy handler to use\n      var options = vm.$options;\n      var handlers = options.render && options.render._withStripped\n        ? getHandler\n        : hasHandler;\n      vm._renderProxy = new Proxy(vm, handlers);\n    } else {\n      vm._renderProxy = vm;\n    }\n  };\n}\n\n/*  */\n\nvar VNode = function VNode (\n  tag,\n  data,\n  children,\n  text,\n  elm,\n  context,\n  componentOptions\n) {\n  this.tag = tag;\n  this.data = data;\n  this.children = children;\n  this.text = text;\n  this.elm = elm;\n  this.ns = undefined;\n  this.context = context;\n  this.functionalContext = undefined;\n  this.key = data && data.key;\n  this.componentOptions = componentOptions;\n  this.componentInstance = undefined;\n  this.parent = undefined;\n  this.raw = false;\n  this.isStatic = false;\n  this.isRootInsert = true;\n  this.isComment = false;\n  this.isCloned = false;\n  this.isOnce = false;\n};\n\nvar prototypeAccessors = { child: {} };\n\n// DEPRECATED: alias for componentInstance for backwards compat.\n/* istanbul ignore next */\nprototypeAccessors.child.get = function () {\n  return this.componentInstance\n};\n\nObject.defineProperties( VNode.prototype, prototypeAccessors );\n\nvar createEmptyVNode = function () {\n  var node = new VNode();\n  node.text = '';\n  node.isComment = true;\n  return node\n};\n\nfunction createTextVNode (val) {\n  return new VNode(undefined, undefined, undefined, String(val))\n}\n\n// optimized shallow clone\n// used for static nodes and slot nodes because they may be reused across\n// multiple renders, cloning them avoids errors when DOM manipulations rely\n// on their elm reference.\nfunction cloneVNode (vnode) {\n  var cloned = new VNode(\n    vnode.tag,\n    vnode.data,\n    vnode.children,\n    vnode.text,\n    vnode.elm,\n    vnode.context,\n    vnode.componentOptions\n  );\n  cloned.ns = vnode.ns;\n  cloned.isStatic = vnode.isStatic;\n  cloned.key = vnode.key;\n  cloned.isCloned = true;\n  return cloned\n}\n\nfunction cloneVNodes (vnodes) {\n  var len = vnodes.length;\n  var res = new Array(len);\n  for (var i = 0; i < len; i++) {\n    res[i] = cloneVNode(vnodes[i]);\n  }\n  return res\n}\n\n/*  */\n\nvar normalizeEvent = cached(function (name) {\n  var passive = name.charAt(0) === '&';\n  name = passive ? name.slice(1) : name;\n  var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first\n  name = once$$1 ? name.slice(1) : name;\n  var capture = name.charAt(0) === '!';\n  name = capture ? name.slice(1) : name;\n  return {\n    name: name,\n    once: once$$1,\n    capture: capture,\n    passive: passive\n  }\n});\n\nfunction createFnInvoker (fns) {\n  function invoker () {\n    var arguments$1 = arguments;\n\n    var fns = invoker.fns;\n    if (Array.isArray(fns)) {\n      for (var i = 0; i < fns.length; i++) {\n        fns[i].apply(null, arguments$1);\n      }\n    } else {\n      // return handler return value for single handlers\n      return fns.apply(null, arguments)\n    }\n  }\n  invoker.fns = fns;\n  return invoker\n}\n\nfunction updateListeners (\n  on,\n  oldOn,\n  add,\n  remove$$1,\n  vm\n) {\n  var name, cur, old, event;\n  for (name in on) {\n    cur = on[name];\n    old = oldOn[name];\n    event = normalizeEvent(name);\n    if (isUndef(cur)) {\n      \"development\" !== 'production' && warn(\n        \"Invalid handler for event \\\"\" + (event.name) + \"\\\": got \" + String(cur),\n        vm\n      );\n    } else if (isUndef(old)) {\n      if (isUndef(cur.fns)) {\n        cur = on[name] = createFnInvoker(cur);\n      }\n      add(event.name, cur, event.once, event.capture, event.passive);\n    } else if (cur !== old) {\n      old.fns = cur;\n      on[name] = old;\n    }\n  }\n  for (name in oldOn) {\n    if (isUndef(on[name])) {\n      event = normalizeEvent(name);\n      remove$$1(event.name, oldOn[name], event.capture);\n    }\n  }\n}\n\n/*  */\n\nfunction mergeVNodeHook (def, hookKey, hook) {\n  var invoker;\n  var oldHook = def[hookKey];\n\n  function wrappedHook () {\n    hook.apply(this, arguments);\n    // important: remove merged hook to ensure it's called only once\n    // and prevent memory leak\n    remove(invoker.fns, wrappedHook);\n  }\n\n  if (isUndef(oldHook)) {\n    // no existing hook\n    invoker = createFnInvoker([wrappedHook]);\n  } else {\n    /* istanbul ignore if */\n    if (isDef(oldHook.fns) && isTrue(oldHook.merged)) {\n      // already a merged invoker\n      invoker = oldHook;\n      invoker.fns.push(wrappedHook);\n    } else {\n      // existing plain hook\n      invoker = createFnInvoker([oldHook, wrappedHook]);\n    }\n  }\n\n  invoker.merged = true;\n  def[hookKey] = invoker;\n}\n\n/*  */\n\nfunction extractPropsFromVNodeData (\n  data,\n  Ctor,\n  tag\n) {\n  // we are only extracting raw values here.\n  // validation and default values are handled in the child\n  // component itself.\n  var propOptions = Ctor.options.props;\n  if (isUndef(propOptions)) {\n    return\n  }\n  var res = {};\n  var attrs = data.attrs;\n  var props = data.props;\n  if (isDef(attrs) || isDef(props)) {\n    for (var key in propOptions) {\n      var altKey = hyphenate(key);\n      {\n        var keyInLowerCase = key.toLowerCase();\n        if (\n          key !== keyInLowerCase &&\n          attrs && hasOwn(attrs, keyInLowerCase)\n        ) {\n          tip(\n            \"Prop \\\"\" + keyInLowerCase + \"\\\" is passed to component \" +\n            (formatComponentName(tag || Ctor)) + \", but the declared prop name is\" +\n            \" \\\"\" + key + \"\\\". \" +\n            \"Note that HTML attributes are case-insensitive and camelCased \" +\n            \"props need to use their kebab-case equivalents when using in-DOM \" +\n            \"templates. You should probably use \\\"\" + altKey + \"\\\" instead of \\\"\" + key + \"\\\".\"\n          );\n        }\n      }\n      checkProp(res, props, key, altKey, true) ||\n      checkProp(res, attrs, key, altKey, false);\n    }\n  }\n  return res\n}\n\nfunction checkProp (\n  res,\n  hash,\n  key,\n  altKey,\n  preserve\n) {\n  if (isDef(hash)) {\n    if (hasOwn(hash, key)) {\n      res[key] = hash[key];\n      if (!preserve) {\n        delete hash[key];\n      }\n      return true\n    } else if (hasOwn(hash, altKey)) {\n      res[key] = hash[altKey];\n      if (!preserve) {\n        delete hash[altKey];\n      }\n      return true\n    }\n  }\n  return false\n}\n\n/*  */\n\n// The template compiler attempts to minimize the need for normalization by\n// statically analyzing the template at compile time.\n//\n// For plain HTML markup, normalization can be completely skipped because the\n// generated render function is guaranteed to return Array<VNode>. There are\n// two cases where extra normalization is needed:\n\n// 1. When the children contains components - because a functional component\n// may return an Array instead of a single root. In this case, just a simple\n// normalization is needed - if any child is an Array, we flatten the whole\n// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep\n// because functional components already normalize their own children.\nfunction simpleNormalizeChildren (children) {\n  for (var i = 0; i < children.length; i++) {\n    if (Array.isArray(children[i])) {\n      return Array.prototype.concat.apply([], children)\n    }\n  }\n  return children\n}\n\n// 2. When the children contains constructs that always generated nested Arrays,\n// e.g. <template>, <slot>, v-for, or when the children is provided by user\n// with hand-written render functions / JSX. In such cases a full normalization\n// is needed to cater to all possible types of children values.\nfunction normalizeChildren (children) {\n  return isPrimitive(children)\n    ? [createTextVNode(children)]\n    : Array.isArray(children)\n      ? normalizeArrayChildren(children)\n      : undefined\n}\n\nfunction normalizeArrayChildren (children, nestedIndex) {\n  var res = [];\n  var i, c, last;\n  for (i = 0; i < children.length; i++) {\n    c = children[i];\n    if (isUndef(c) || typeof c === 'boolean') { continue }\n    last = res[res.length - 1];\n    //  nested\n    if (Array.isArray(c)) {\n      res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + \"_\" + i)));\n    } else if (isPrimitive(c)) {\n      if (isDef(last) && isDef(last.text)) {\n        (last).text += String(c);\n      } else if (c !== '') {\n        // convert primitive to vnode\n        res.push(createTextVNode(c));\n      }\n    } else {\n      if (isDef(c.text) && isDef(last) && isDef(last.text)) {\n        res[res.length - 1] = createTextVNode(last.text + c.text);\n      } else {\n        // default key for nested array children (likely generated by v-for)\n        if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {\n          c.key = \"__vlist\" + ((nestedIndex)) + \"_\" + i + \"__\";\n        }\n        res.push(c);\n      }\n    }\n  }\n  return res\n}\n\n/*  */\n\nfunction ensureCtor (comp, base) {\n  return isObject(comp)\n    ? base.extend(comp)\n    : comp\n}\n\nfunction resolveAsyncComponent (\n  factory,\n  baseCtor,\n  context\n) {\n  if (isTrue(factory.error) && isDef(factory.errorComp)) {\n    return factory.errorComp\n  }\n\n  if (isDef(factory.resolved)) {\n    return factory.resolved\n  }\n\n  if (isTrue(factory.loading) && isDef(factory.loadingComp)) {\n    return factory.loadingComp\n  }\n\n  if (isDef(factory.contexts)) {\n    // already pending\n    factory.contexts.push(context);\n  } else {\n    var contexts = factory.contexts = [context];\n    var sync = true;\n\n    var forceRender = function () {\n      for (var i = 0, l = contexts.length; i < l; i++) {\n        contexts[i].$forceUpdate();\n      }\n    };\n\n    var resolve = once(function (res) {\n      // cache resolved\n      factory.resolved = ensureCtor(res, baseCtor);\n      // invoke callbacks only if this is not a synchronous resolve\n      // (async resolves are shimmed as synchronous during SSR)\n      if (!sync) {\n        forceRender();\n      }\n    });\n\n    var reject = once(function (reason) {\n      \"development\" !== 'production' && warn(\n        \"Failed to resolve async component: \" + (String(factory)) +\n        (reason ? (\"\\nReason: \" + reason) : '')\n      );\n      if (isDef(factory.errorComp)) {\n        factory.error = true;\n        forceRender();\n      }\n    });\n\n    var res = factory(resolve, reject);\n\n    if (isObject(res)) {\n      if (typeof res.then === 'function') {\n        // () => Promise\n        if (isUndef(factory.resolved)) {\n          res.then(resolve, reject);\n        }\n      } else if (isDef(res.component) && typeof res.component.then === 'function') {\n        res.component.then(resolve, reject);\n\n        if (isDef(res.error)) {\n          factory.errorComp = ensureCtor(res.error, baseCtor);\n        }\n\n        if (isDef(res.loading)) {\n          factory.loadingComp = ensureCtor(res.loading, baseCtor);\n          if (res.delay === 0) {\n            factory.loading = true;\n          } else {\n            setTimeout(function () {\n              if (isUndef(factory.resolved) && isUndef(factory.error)) {\n                factory.loading = true;\n                forceRender();\n              }\n            }, res.delay || 200);\n          }\n        }\n\n        if (isDef(res.timeout)) {\n          setTimeout(function () {\n            reject(\n              \"timeout (\" + (res.timeout) + \"ms)\"\n            );\n          }, res.timeout);\n        }\n      }\n    }\n\n    sync = false;\n    // return in case resolved synchronously\n    return factory.loading\n      ? factory.loadingComp\n      : factory.resolved\n  }\n}\n\n/*  */\n\nfunction getFirstComponentChild (children) {\n  if (Array.isArray(children)) {\n    for (var i = 0; i < children.length; i++) {\n      var c = children[i];\n      if (isDef(c) && isDef(c.componentOptions)) {\n        return c\n      }\n    }\n  }\n}\n\n/*  */\n\n/*  */\n\nfunction initEvents (vm) {\n  vm._events = Object.create(null);\n  vm._hasHookEvent = false;\n  // init parent attached events\n  var listeners = vm.$options._parentListeners;\n  if (listeners) {\n    updateComponentListeners(vm, listeners);\n  }\n}\n\nvar target;\n\nfunction add (event, fn, once$$1) {\n  if (once$$1) {\n    target.$once(event, fn);\n  } else {\n    target.$on(event, fn);\n  }\n}\n\nfunction remove$1 (event, fn) {\n  target.$off(event, fn);\n}\n\nfunction updateComponentListeners (\n  vm,\n  listeners,\n  oldListeners\n) {\n  target = vm;\n  updateListeners(listeners, oldListeners || {}, add, remove$1, vm);\n}\n\nfunction eventsMixin (Vue) {\n  var hookRE = /^hook:/;\n  Vue.prototype.$on = function (event, fn) {\n    var this$1 = this;\n\n    var vm = this;\n    if (Array.isArray(event)) {\n      for (var i = 0, l = event.length; i < l; i++) {\n        this$1.$on(event[i], fn);\n      }\n    } else {\n      (vm._events[event] || (vm._events[event] = [])).push(fn);\n      // optimize hook:event cost by using a boolean flag marked at registration\n      // instead of a hash lookup\n      if (hookRE.test(event)) {\n        vm._hasHookEvent = true;\n      }\n    }\n    return vm\n  };\n\n  Vue.prototype.$once = function (event, fn) {\n    var vm = this;\n    function on () {\n      vm.$off(event, on);\n      fn.apply(vm, arguments);\n    }\n    on.fn = fn;\n    vm.$on(event, on);\n    return vm\n  };\n\n  Vue.prototype.$off = function (event, fn) {\n    var this$1 = this;\n\n    var vm = this;\n    // all\n    if (!arguments.length) {\n      vm._events = Object.create(null);\n      return vm\n    }\n    // array of events\n    if (Array.isArray(event)) {\n      for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {\n        this$1.$off(event[i$1], fn);\n      }\n      return vm\n    }\n    // specific event\n    var cbs = vm._events[event];\n    if (!cbs) {\n      return vm\n    }\n    if (arguments.length === 1) {\n      vm._events[event] = null;\n      return vm\n    }\n    // specific handler\n    var cb;\n    var i = cbs.length;\n    while (i--) {\n      cb = cbs[i];\n      if (cb === fn || cb.fn === fn) {\n        cbs.splice(i, 1);\n        break\n      }\n    }\n    return vm\n  };\n\n  Vue.prototype.$emit = function (event) {\n    var vm = this;\n    {\n      var lowerCaseEvent = event.toLowerCase();\n      if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {\n        tip(\n          \"Event \\\"\" + lowerCaseEvent + \"\\\" is emitted in component \" +\n          (formatComponentName(vm)) + \" but the handler is registered for \\\"\" + event + \"\\\". \" +\n          \"Note that HTML attributes are case-insensitive and you cannot use \" +\n          \"v-on to listen to camelCase events when using in-DOM templates. \" +\n          \"You should probably use \\\"\" + (hyphenate(event)) + \"\\\" instead of \\\"\" + event + \"\\\".\"\n        );\n      }\n    }\n    var cbs = vm._events[event];\n    if (cbs) {\n      cbs = cbs.length > 1 ? toArray(cbs) : cbs;\n      var args = toArray(arguments, 1);\n      for (var i = 0, l = cbs.length; i < l; i++) {\n        cbs[i].apply(vm, args);\n      }\n    }\n    return vm\n  };\n}\n\n/*  */\n\n/**\n * Runtime helper for resolving raw children VNodes into a slot object.\n */\nfunction resolveSlots (\n  children,\n  context\n) {\n  var slots = {};\n  if (!children) {\n    return slots\n  }\n  var defaultSlot = [];\n  for (var i = 0, l = children.length; i < l; i++) {\n    var child = children[i];\n    // named slots should only be respected if the vnode was rendered in the\n    // same context.\n    if ((child.context === context || child.functionalContext === context) &&\n        child.data && child.data.slot != null) {\n      var name = child.data.slot;\n      var slot = (slots[name] || (slots[name] = []));\n      if (child.tag === 'template') {\n        slot.push.apply(slot, child.children);\n      } else {\n        slot.push(child);\n      }\n    } else {\n      defaultSlot.push(child);\n    }\n  }\n  // ignore whitespace\n  if (!defaultSlot.every(isWhitespace)) {\n    slots.default = defaultSlot;\n  }\n  return slots\n}\n\nfunction isWhitespace (node) {\n  return node.isComment || node.text === ' '\n}\n\nfunction resolveScopedSlots (\n  fns\n) {\n  var res = {};\n  for (var i = 0; i < fns.length; i++) {\n    res[fns[i][0]] = fns[i][1];\n  }\n  return res\n}\n\n/*  */\n\nvar activeInstance = null;\n\nfunction initLifecycle (vm) {\n  var options = vm.$options;\n\n  // locate first non-abstract parent\n  var parent = options.parent;\n  if (parent && !options.abstract) {\n    while (parent.$options.abstract && parent.$parent) {\n      parent = parent.$parent;\n    }\n    parent.$children.push(vm);\n  }\n\n  vm.$parent = parent;\n  vm.$root = parent ? parent.$root : vm;\n\n  vm.$children = [];\n  vm.$refs = {};\n\n  vm._watcher = null;\n  vm._inactive = null;\n  vm._directInactive = false;\n  vm._isMounted = false;\n  vm._isDestroyed = false;\n  vm._isBeingDestroyed = false;\n}\n\nfunction lifecycleMixin (Vue) {\n  Vue.prototype._update = function (vnode, hydrating) {\n    var vm = this;\n    if (vm._isMounted) {\n      callHook(vm, 'beforeUpdate');\n    }\n    var prevEl = vm.$el;\n    var prevVnode = vm._vnode;\n    var prevActiveInstance = activeInstance;\n    activeInstance = vm;\n    vm._vnode = vnode;\n    // Vue.prototype.__patch__ is injected in entry points\n    // based on the rendering backend used.\n    if (!prevVnode) {\n      // initial render\n      vm.$el = vm.__patch__(\n        vm.$el, vnode, hydrating, false /* removeOnly */,\n        vm.$options._parentElm,\n        vm.$options._refElm\n      );\n    } else {\n      // updates\n      vm.$el = vm.__patch__(prevVnode, vnode);\n    }\n    activeInstance = prevActiveInstance;\n    // update __vue__ reference\n    if (prevEl) {\n      prevEl.__vue__ = null;\n    }\n    if (vm.$el) {\n      vm.$el.__vue__ = vm;\n    }\n    // if parent is an HOC, update its $el as well\n    if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {\n      vm.$parent.$el = vm.$el;\n    }\n    // updated hook is called by the scheduler to ensure that children are\n    // updated in a parent's updated hook.\n  };\n\n  Vue.prototype.$forceUpdate = function () {\n    var vm = this;\n    if (vm._watcher) {\n      vm._watcher.update();\n    }\n  };\n\n  Vue.prototype.$destroy = function () {\n    var vm = this;\n    if (vm._isBeingDestroyed) {\n      return\n    }\n    callHook(vm, 'beforeDestroy');\n    vm._isBeingDestroyed = true;\n    // remove self from parent\n    var parent = vm.$parent;\n    if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {\n      remove(parent.$children, vm);\n    }\n    // teardown watchers\n    if (vm._watcher) {\n      vm._watcher.teardown();\n    }\n    var i = vm._watchers.length;\n    while (i--) {\n      vm._watchers[i].teardown();\n    }\n    // remove reference from data ob\n    // frozen object may not have observer.\n    if (vm._data.__ob__) {\n      vm._data.__ob__.vmCount--;\n    }\n    // call the last hook...\n    vm._isDestroyed = true;\n    // invoke destroy hooks on current rendered tree\n    vm.__patch__(vm._vnode, null);\n    // fire destroyed hook\n    callHook(vm, 'destroyed');\n    // turn off all instance listeners.\n    vm.$off();\n    // remove __vue__ reference\n    if (vm.$el) {\n      vm.$el.__vue__ = null;\n    }\n    // remove reference to DOM nodes (prevents leak)\n    vm.$options._parentElm = vm.$options._refElm = null;\n  };\n}\n\nfunction mountComponent (\n  vm,\n  el,\n  hydrating\n) {\n  vm.$el = el;\n  if (!vm.$options.render) {\n    vm.$options.render = createEmptyVNode;\n    {\n      /* istanbul ignore if */\n      if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') ||\n        vm.$options.el || el) {\n        warn(\n          'You are using the runtime-only build of Vue where the template ' +\n          'compiler is not available. Either pre-compile the templates into ' +\n          'render functions, or use the compiler-included build.',\n          vm\n        );\n      } else {\n        warn(\n          'Failed to mount component: template or render function not defined.',\n          vm\n        );\n      }\n    }\n  }\n  callHook(vm, 'beforeMount');\n\n  var updateComponent;\n  /* istanbul ignore if */\n  if (\"development\" !== 'production' && config.performance && mark) {\n    updateComponent = function () {\n      var name = vm._name;\n      var id = vm._uid;\n      var startTag = \"vue-perf-start:\" + id;\n      var endTag = \"vue-perf-end:\" + id;\n\n      mark(startTag);\n      var vnode = vm._render();\n      mark(endTag);\n      measure((name + \" render\"), startTag, endTag);\n\n      mark(startTag);\n      vm._update(vnode, hydrating);\n      mark(endTag);\n      measure((name + \" patch\"), startTag, endTag);\n    };\n  } else {\n    updateComponent = function () {\n      vm._update(vm._render(), hydrating);\n    };\n  }\n\n  vm._watcher = new Watcher(vm, updateComponent, noop);\n  hydrating = false;\n\n  // manually mounted instance, call mounted on self\n  // mounted is called for render-created child components in its inserted hook\n  if (vm.$vnode == null) {\n    vm._isMounted = true;\n    callHook(vm, 'mounted');\n  }\n  return vm\n}\n\nfunction updateChildComponent (\n  vm,\n  propsData,\n  listeners,\n  parentVnode,\n  renderChildren\n) {\n  // determine whether component has slot children\n  // we need to do this before overwriting $options._renderChildren\n  var hasChildren = !!(\n    renderChildren ||               // has new static slots\n    vm.$options._renderChildren ||  // has old static slots\n    parentVnode.data.scopedSlots || // has new scoped slots\n    vm.$scopedSlots !== emptyObject // has old scoped slots\n  );\n\n  vm.$options._parentVnode = parentVnode;\n  vm.$vnode = parentVnode; // update vm's placeholder node without re-render\n  if (vm._vnode) { // update child tree's parent\n    vm._vnode.parent = parentVnode;\n  }\n  vm.$options._renderChildren = renderChildren;\n\n  // update props\n  if (propsData && vm.$options.props) {\n    observerState.shouldConvert = false;\n    {\n      observerState.isSettingProps = true;\n    }\n    var props = vm._props;\n    var propKeys = vm.$options._propKeys || [];\n    for (var i = 0; i < propKeys.length; i++) {\n      var key = propKeys[i];\n      props[key] = validateProp(key, vm.$options.props, propsData, vm);\n    }\n    observerState.shouldConvert = true;\n    {\n      observerState.isSettingProps = false;\n    }\n    // keep a copy of raw propsData\n    vm.$options.propsData = propsData;\n  }\n  // update listeners\n  if (listeners) {\n    var oldListeners = vm.$options._parentListeners;\n    vm.$options._parentListeners = listeners;\n    updateComponentListeners(vm, listeners, oldListeners);\n  }\n  // resolve slots + force update if has children\n  if (hasChildren) {\n    vm.$slots = resolveSlots(renderChildren, parentVnode.context);\n    vm.$forceUpdate();\n  }\n}\n\nfunction isInInactiveTree (vm) {\n  while (vm && (vm = vm.$parent)) {\n    if (vm._inactive) { return true }\n  }\n  return false\n}\n\nfunction activateChildComponent (vm, direct) {\n  if (direct) {\n    vm._directInactive = false;\n    if (isInInactiveTree(vm)) {\n      return\n    }\n  } else if (vm._directInactive) {\n    return\n  }\n  if (vm._inactive || vm._inactive === null) {\n    vm._inactive = false;\n    for (var i = 0; i < vm.$children.length; i++) {\n      activateChildComponent(vm.$children[i]);\n    }\n    callHook(vm, 'activated');\n  }\n}\n\nfunction deactivateChildComponent (vm, direct) {\n  if (direct) {\n    vm._directInactive = true;\n    if (isInInactiveTree(vm)) {\n      return\n    }\n  }\n  if (!vm._inactive) {\n    vm._inactive = true;\n    for (var i = 0; i < vm.$children.length; i++) {\n      deactivateChildComponent(vm.$children[i]);\n    }\n    callHook(vm, 'deactivated');\n  }\n}\n\nfunction callHook (vm, hook) {\n  var handlers = vm.$options[hook];\n  if (handlers) {\n    for (var i = 0, j = handlers.length; i < j; i++) {\n      try {\n        handlers[i].call(vm);\n      } catch (e) {\n        handleError(e, vm, (hook + \" hook\"));\n      }\n    }\n  }\n  if (vm._hasHookEvent) {\n    vm.$emit('hook:' + hook);\n  }\n}\n\n/*  */\n\n\nvar MAX_UPDATE_COUNT = 100;\n\nvar queue = [];\nvar activatedChildren = [];\nvar has = {};\nvar circular = {};\nvar waiting = false;\nvar flushing = false;\nvar index = 0;\n\n/**\n * Reset the scheduler's state.\n */\nfunction resetSchedulerState () {\n  queue.length = activatedChildren.length = 0;\n  has = {};\n  {\n    circular = {};\n  }\n  waiting = flushing = false;\n}\n\n/**\n * Flush both queues and run the watchers.\n */\nfunction flushSchedulerQueue () {\n  flushing = true;\n  var watcher, id;\n\n  // Sort queue before flush.\n  // This ensures that:\n  // 1. Components are updated from parent to child. (because parent is always\n  //    created before the child)\n  // 2. A component's user watchers are run before its render watcher (because\n  //    user watchers are created before the render watcher)\n  // 3. If a component is destroyed during a parent component's watcher run,\n  //    its watchers can be skipped.\n  queue.sort(function (a, b) { return a.id - b.id; });\n\n  // do not cache length because more watchers might be pushed\n  // as we run existing watchers\n  for (index = 0; index < queue.length; index++) {\n    watcher = queue[index];\n    id = watcher.id;\n    has[id] = null;\n    watcher.run();\n    // in dev build, check and stop circular updates.\n    if (\"development\" !== 'production' && has[id] != null) {\n      circular[id] = (circular[id] || 0) + 1;\n      if (circular[id] > MAX_UPDATE_COUNT) {\n        warn(\n          'You may have an infinite update loop ' + (\n            watcher.user\n              ? (\"in watcher with expression \\\"\" + (watcher.expression) + \"\\\"\")\n              : \"in a component render function.\"\n          ),\n          watcher.vm\n        );\n        break\n      }\n    }\n  }\n\n  // keep copies of post queues before resetting state\n  var activatedQueue = activatedChildren.slice();\n  var updatedQueue = queue.slice();\n\n  resetSchedulerState();\n\n  // call component updated and activated hooks\n  callActivatedHooks(activatedQueue);\n  callUpdateHooks(updatedQueue);\n\n  // devtool hook\n  /* istanbul ignore if */\n  if (devtools && config.devtools) {\n    devtools.emit('flush');\n  }\n}\n\nfunction callUpdateHooks (queue) {\n  var i = queue.length;\n  while (i--) {\n    var watcher = queue[i];\n    var vm = watcher.vm;\n    if (vm._watcher === watcher && vm._isMounted) {\n      callHook(vm, 'updated');\n    }\n  }\n}\n\n/**\n * Queue a kept-alive component that was activated during patch.\n * The queue will be processed after the entire tree has been patched.\n */\nfunction queueActivatedComponent (vm) {\n  // setting _inactive to false here so that a render function can\n  // rely on checking whether it's in an inactive tree (e.g. router-view)\n  vm._inactive = false;\n  activatedChildren.push(vm);\n}\n\nfunction callActivatedHooks (queue) {\n  for (var i = 0; i < queue.length; i++) {\n    queue[i]._inactive = true;\n    activateChildComponent(queue[i], true /* true */);\n  }\n}\n\n/**\n * Push a watcher into the watcher queue.\n * Jobs with duplicate IDs will be skipped unless it's\n * pushed when the queue is being flushed.\n */\nfunction queueWatcher (watcher) {\n  var id = watcher.id;\n  if (has[id] == null) {\n    has[id] = true;\n    if (!flushing) {\n      queue.push(watcher);\n    } else {\n      // if already flushing, splice the watcher based on its id\n      // if already past its id, it will be run next immediately.\n      var i = queue.length - 1;\n      while (i >= 0 && queue[i].id > watcher.id) {\n        i--;\n      }\n      queue.splice(Math.max(i, index) + 1, 0, watcher);\n    }\n    // queue the flush\n    if (!waiting) {\n      waiting = true;\n      nextTick(flushSchedulerQueue);\n    }\n  }\n}\n\n/*  */\n\nvar uid$2 = 0;\n\n/**\n * A watcher parses an expression, collects dependencies,\n * and fires callback when the expression value changes.\n * This is used for both the $watch() api and directives.\n */\nvar Watcher = function Watcher (\n  vm,\n  expOrFn,\n  cb,\n  options\n) {\n  this.vm = vm;\n  vm._watchers.push(this);\n  // options\n  if (options) {\n    this.deep = !!options.deep;\n    this.user = !!options.user;\n    this.lazy = !!options.lazy;\n    this.sync = !!options.sync;\n  } else {\n    this.deep = this.user = this.lazy = this.sync = false;\n  }\n  this.cb = cb;\n  this.id = ++uid$2; // uid for batching\n  this.active = true;\n  this.dirty = this.lazy; // for lazy watchers\n  this.deps = [];\n  this.newDeps = [];\n  this.depIds = new _Set();\n  this.newDepIds = new _Set();\n  this.expression = expOrFn.toString();\n  // parse expression for getter\n  if (typeof expOrFn === 'function') {\n    this.getter = expOrFn;\n  } else {\n    this.getter = parsePath(expOrFn);\n    if (!this.getter) {\n      this.getter = function () {};\n      \"development\" !== 'production' && warn(\n        \"Failed watching path: \\\"\" + expOrFn + \"\\\" \" +\n        'Watcher only accepts simple dot-delimited paths. ' +\n        'For full control, use a function instead.',\n        vm\n      );\n    }\n  }\n  this.value = this.lazy\n    ? undefined\n    : this.get();\n};\n\n/**\n * Evaluate the getter, and re-collect dependencies.\n */\nWatcher.prototype.get = function get () {\n  pushTarget(this);\n  var value;\n  var vm = this.vm;\n  if (this.user) {\n    try {\n      value = this.getter.call(vm, vm);\n    } catch (e) {\n      handleError(e, vm, (\"getter for watcher \\\"\" + (this.expression) + \"\\\"\"));\n    }\n  } else {\n    value = this.getter.call(vm, vm);\n  }\n  // \"touch\" every property so they are all tracked as\n  // dependencies for deep watching\n  if (this.deep) {\n    traverse(value);\n  }\n  popTarget();\n  this.cleanupDeps();\n  return value\n};\n\n/**\n * Add a dependency to this directive.\n */\nWatcher.prototype.addDep = function addDep (dep) {\n  var id = dep.id;\n  if (!this.newDepIds.has(id)) {\n    this.newDepIds.add(id);\n    this.newDeps.push(dep);\n    if (!this.depIds.has(id)) {\n      dep.addSub(this);\n    }\n  }\n};\n\n/**\n * Clean up for dependency collection.\n */\nWatcher.prototype.cleanupDeps = function cleanupDeps () {\n    var this$1 = this;\n\n  var i = this.deps.length;\n  while (i--) {\n    var dep = this$1.deps[i];\n    if (!this$1.newDepIds.has(dep.id)) {\n      dep.removeSub(this$1);\n    }\n  }\n  var tmp = this.depIds;\n  this.depIds = this.newDepIds;\n  this.newDepIds = tmp;\n  this.newDepIds.clear();\n  tmp = this.deps;\n  this.deps = this.newDeps;\n  this.newDeps = tmp;\n  this.newDeps.length = 0;\n};\n\n/**\n * Subscriber interface.\n * Will be called when a dependency changes.\n */\nWatcher.prototype.update = function update () {\n  /* istanbul ignore else */\n  if (this.lazy) {\n    this.dirty = true;\n  } else if (this.sync) {\n    this.run();\n  } else {\n    queueWatcher(this);\n  }\n};\n\n/**\n * Scheduler job interface.\n * Will be called by the scheduler.\n */\nWatcher.prototype.run = function run () {\n  if (this.active) {\n    var value = this.get();\n    if (\n      value !== this.value ||\n      // Deep watchers and watchers on Object/Arrays should fire even\n      // when the value is the same, because the value may\n      // have mutated.\n      isObject(value) ||\n      this.deep\n    ) {\n      // set new value\n      var oldValue = this.value;\n      this.value = value;\n      if (this.user) {\n        try {\n          this.cb.call(this.vm, value, oldValue);\n        } catch (e) {\n          handleError(e, this.vm, (\"callback for watcher \\\"\" + (this.expression) + \"\\\"\"));\n        }\n      } else {\n        this.cb.call(this.vm, value, oldValue);\n      }\n    }\n  }\n};\n\n/**\n * Evaluate the value of the watcher.\n * This only gets called for lazy watchers.\n */\nWatcher.prototype.evaluate = function evaluate () {\n  this.value = this.get();\n  this.dirty = false;\n};\n\n/**\n * Depend on all deps collected by this watcher.\n */\nWatcher.prototype.depend = function depend () {\n    var this$1 = this;\n\n  var i = this.deps.length;\n  while (i--) {\n    this$1.deps[i].depend();\n  }\n};\n\n/**\n * Remove self from all dependencies' subscriber list.\n */\nWatcher.prototype.teardown = function teardown () {\n    var this$1 = this;\n\n  if (this.active) {\n    // remove self from vm's watcher list\n    // this is a somewhat expensive operation so we skip it\n    // if the vm is being destroyed.\n    if (!this.vm._isBeingDestroyed) {\n      remove(this.vm._watchers, this);\n    }\n    var i = this.deps.length;\n    while (i--) {\n      this$1.deps[i].removeSub(this$1);\n    }\n    this.active = false;\n  }\n};\n\n/**\n * Recursively traverse an object to evoke all converted\n * getters, so that every nested property inside the object\n * is collected as a \"deep\" dependency.\n */\nvar seenObjects = new _Set();\nfunction traverse (val) {\n  seenObjects.clear();\n  _traverse(val, seenObjects);\n}\n\nfunction _traverse (val, seen) {\n  var i, keys;\n  var isA = Array.isArray(val);\n  if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {\n    return\n  }\n  if (val.__ob__) {\n    var depId = val.__ob__.dep.id;\n    if (seen.has(depId)) {\n      return\n    }\n    seen.add(depId);\n  }\n  if (isA) {\n    i = val.length;\n    while (i--) { _traverse(val[i], seen); }\n  } else {\n    keys = Object.keys(val);\n    i = keys.length;\n    while (i--) { _traverse(val[keys[i]], seen); }\n  }\n}\n\n/*  */\n\nvar sharedPropertyDefinition = {\n  enumerable: true,\n  configurable: true,\n  get: noop,\n  set: noop\n};\n\nfunction proxy (target, sourceKey, key) {\n  sharedPropertyDefinition.get = function proxyGetter () {\n    return this[sourceKey][key]\n  };\n  sharedPropertyDefinition.set = function proxySetter (val) {\n    this[sourceKey][key] = val;\n  };\n  Object.defineProperty(target, key, sharedPropertyDefinition);\n}\n\nfunction initState (vm) {\n  vm._watchers = [];\n  var opts = vm.$options;\n  if (opts.props) { initProps(vm, opts.props); }\n  if (opts.methods) { initMethods(vm, opts.methods); }\n  if (opts.data) {\n    initData(vm);\n  } else {\n    observe(vm._data = {}, true /* asRootData */);\n  }\n  if (opts.computed) { initComputed(vm, opts.computed); }\n  if (opts.watch) { initWatch(vm, opts.watch); }\n}\n\nvar isReservedProp = {\n  key: 1,\n  ref: 1,\n  slot: 1\n};\n\nfunction initProps (vm, propsOptions) {\n  var propsData = vm.$options.propsData || {};\n  var props = vm._props = {};\n  // cache prop keys so that future props updates can iterate using Array\n  // instead of dynamic object key enumeration.\n  var keys = vm.$options._propKeys = [];\n  var isRoot = !vm.$parent;\n  // root instance props should be converted\n  observerState.shouldConvert = isRoot;\n  var loop = function ( key ) {\n    keys.push(key);\n    var value = validateProp(key, propsOptions, propsData, vm);\n    /* istanbul ignore else */\n    {\n      if (isReservedProp[key] || config.isReservedAttr(key)) {\n        warn(\n          (\"\\\"\" + key + \"\\\" is a reserved attribute and cannot be used as component prop.\"),\n          vm\n        );\n      }\n      defineReactive$$1(props, key, value, function () {\n        if (vm.$parent && !observerState.isSettingProps) {\n          warn(\n            \"Avoid mutating a prop directly since the value will be \" +\n            \"overwritten whenever the parent component re-renders. \" +\n            \"Instead, use a data or computed property based on the prop's \" +\n            \"value. Prop being mutated: \\\"\" + key + \"\\\"\",\n            vm\n          );\n        }\n      });\n    }\n    // static props are already proxied on the component's prototype\n    // during Vue.extend(). We only need to proxy props defined at\n    // instantiation here.\n    if (!(key in vm)) {\n      proxy(vm, \"_props\", key);\n    }\n  };\n\n  for (var key in propsOptions) loop( key );\n  observerState.shouldConvert = true;\n}\n\nfunction initData (vm) {\n  var data = vm.$options.data;\n  data = vm._data = typeof data === 'function'\n    ? getData(data, vm)\n    : data || {};\n  if (!isPlainObject(data)) {\n    data = {};\n    \"development\" !== 'production' && warn(\n      'data functions should return an object:\\n' +\n      'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',\n      vm\n    );\n  }\n  // proxy data on instance\n  var keys = Object.keys(data);\n  var props = vm.$options.props;\n  var i = keys.length;\n  while (i--) {\n    if (props && hasOwn(props, keys[i])) {\n      \"development\" !== 'production' && warn(\n        \"The data property \\\"\" + (keys[i]) + \"\\\" is already declared as a prop. \" +\n        \"Use prop default value instead.\",\n        vm\n      );\n    } else if (!isReserved(keys[i])) {\n      proxy(vm, \"_data\", keys[i]);\n    }\n  }\n  // observe data\n  observe(data, true /* asRootData */);\n}\n\nfunction getData (data, vm) {\n  try {\n    return data.call(vm)\n  } catch (e) {\n    handleError(e, vm, \"data()\");\n    return {}\n  }\n}\n\nvar computedWatcherOptions = { lazy: true };\n\nfunction initComputed (vm, computed) {\n  var watchers = vm._computedWatchers = Object.create(null);\n\n  for (var key in computed) {\n    var userDef = computed[key];\n    var getter = typeof userDef === 'function' ? userDef : userDef.get;\n    {\n      if (getter === undefined) {\n        warn(\n          (\"No getter function has been defined for computed property \\\"\" + key + \"\\\".\"),\n          vm\n        );\n        getter = noop;\n      }\n    }\n    // create internal watcher for the computed property.\n    watchers[key] = new Watcher(vm, getter, noop, computedWatcherOptions);\n\n    // component-defined computed properties are already defined on the\n    // component prototype. We only need to define computed properties defined\n    // at instantiation here.\n    if (!(key in vm)) {\n      defineComputed(vm, key, userDef);\n    } else {\n      if (key in vm.$data) {\n        warn((\"The computed property \\\"\" + key + \"\\\" is already defined in data.\"), vm);\n      } else if (vm.$options.props && key in vm.$options.props) {\n        warn((\"The computed property \\\"\" + key + \"\\\" is already defined as a prop.\"), vm);\n      }\n    }\n  }\n}\n\nfunction defineComputed (target, key, userDef) {\n  if (typeof userDef === 'function') {\n    sharedPropertyDefinition.get = createComputedGetter(key);\n    sharedPropertyDefinition.set = noop;\n  } else {\n    sharedPropertyDefinition.get = userDef.get\n      ? userDef.cache !== false\n        ? createComputedGetter(key)\n        : userDef.get\n      : noop;\n    sharedPropertyDefinition.set = userDef.set\n      ? userDef.set\n      : noop;\n  }\n  Object.defineProperty(target, key, sharedPropertyDefinition);\n}\n\nfunction createComputedGetter (key) {\n  return function computedGetter () {\n    var watcher = this._computedWatchers && this._computedWatchers[key];\n    if (watcher) {\n      if (watcher.dirty) {\n        watcher.evaluate();\n      }\n      if (Dep.target) {\n        watcher.depend();\n      }\n      return watcher.value\n    }\n  }\n}\n\nfunction initMethods (vm, methods) {\n  var props = vm.$options.props;\n  for (var key in methods) {\n    vm[key] = methods[key] == null ? noop : bind(methods[key], vm);\n    {\n      if (methods[key] == null) {\n        warn(\n          \"method \\\"\" + key + \"\\\" has an undefined value in the component definition. \" +\n          \"Did you reference the function correctly?\",\n          vm\n        );\n      }\n      if (props && hasOwn(props, key)) {\n        warn(\n          (\"method \\\"\" + key + \"\\\" has already been defined as a prop.\"),\n          vm\n        );\n      }\n    }\n  }\n}\n\nfunction initWatch (vm, watch) {\n  for (var key in watch) {\n    var handler = watch[key];\n    if (Array.isArray(handler)) {\n      for (var i = 0; i < handler.length; i++) {\n        createWatcher(vm, key, handler[i]);\n      }\n    } else {\n      createWatcher(vm, key, handler);\n    }\n  }\n}\n\nfunction createWatcher (vm, key, handler) {\n  var options;\n  if (isPlainObject(handler)) {\n    options = handler;\n    handler = handler.handler;\n  }\n  if (typeof handler === 'string') {\n    handler = vm[handler];\n  }\n  vm.$watch(key, handler, options);\n}\n\nfunction stateMixin (Vue) {\n  // flow somehow has problems with directly declared definition object\n  // when using Object.defineProperty, so we have to procedurally build up\n  // the object here.\n  var dataDef = {};\n  dataDef.get = function () { return this._data };\n  var propsDef = {};\n  propsDef.get = function () { return this._props };\n  {\n    dataDef.set = function (newData) {\n      warn(\n        'Avoid replacing instance root $data. ' +\n        'Use nested data properties instead.',\n        this\n      );\n    };\n    propsDef.set = function () {\n      warn(\"$props is readonly.\", this);\n    };\n  }\n  Object.defineProperty(Vue.prototype, '$data', dataDef);\n  Object.defineProperty(Vue.prototype, '$props', propsDef);\n\n  Vue.prototype.$set = set;\n  Vue.prototype.$delete = del;\n\n  Vue.prototype.$watch = function (\n    expOrFn,\n    cb,\n    options\n  ) {\n    var vm = this;\n    options = options || {};\n    options.user = true;\n    var watcher = new Watcher(vm, expOrFn, cb, options);\n    if (options.immediate) {\n      cb.call(vm, watcher.value);\n    }\n    return function unwatchFn () {\n      watcher.teardown();\n    }\n  };\n}\n\n/*  */\n\nfunction initProvide (vm) {\n  var provide = vm.$options.provide;\n  if (provide) {\n    vm._provided = typeof provide === 'function'\n      ? provide.call(vm)\n      : provide;\n  }\n}\n\nfunction initInjections (vm) {\n  var result = resolveInject(vm.$options.inject, vm);\n  if (result) {\n    Object.keys(result).forEach(function (key) {\n      /* istanbul ignore else */\n      {\n        defineReactive$$1(vm, key, result[key], function () {\n          warn(\n            \"Avoid mutating an injected value directly since the changes will be \" +\n            \"overwritten whenever the provided component re-renders. \" +\n            \"injection being mutated: \\\"\" + key + \"\\\"\",\n            vm\n          );\n        });\n      }\n    });\n  }\n}\n\nfunction resolveInject (inject, vm) {\n  if (inject) {\n    // inject is :any because flow is not smart enough to figure out cached\n    // isArray here\n    var isArray = Array.isArray(inject);\n    var result = Object.create(null);\n    var keys = isArray\n      ? inject\n      : hasSymbol\n        ? Reflect.ownKeys(inject)\n        : Object.keys(inject);\n\n    for (var i = 0; i < keys.length; i++) {\n      var key = keys[i];\n      var provideKey = isArray ? key : inject[key];\n      var source = vm;\n      while (source) {\n        if (source._provided && provideKey in source._provided) {\n          result[key] = source._provided[provideKey];\n          break\n        }\n        source = source.$parent;\n      }\n    }\n    return result\n  }\n}\n\n/*  */\n\nfunction createFunctionalComponent (\n  Ctor,\n  propsData,\n  data,\n  context,\n  children\n) {\n  var props = {};\n  var propOptions = Ctor.options.props;\n  if (isDef(propOptions)) {\n    for (var key in propOptions) {\n      props[key] = validateProp(key, propOptions, propsData);\n    }\n  } else {\n    if (isDef(data.attrs)) { mergeProps(props, data.attrs); }\n    if (isDef(data.props)) { mergeProps(props, data.props); }\n  }\n  // ensure the createElement function in functional components\n  // gets a unique context - this is necessary for correct named slot check\n  var _context = Object.create(context);\n  var h = function (a, b, c, d) { return createElement(_context, a, b, c, d, true); };\n  var vnode = Ctor.options.render.call(null, h, {\n    data: data,\n    props: props,\n    children: children,\n    parent: context,\n    listeners: data.on || {},\n    injections: resolveInject(Ctor.options.inject, context),\n    slots: function () { return resolveSlots(children, context); }\n  });\n  if (vnode instanceof VNode) {\n    vnode.functionalContext = context;\n    if (data.slot) {\n      (vnode.data || (vnode.data = {})).slot = data.slot;\n    }\n  }\n  return vnode\n}\n\nfunction mergeProps (to, from) {\n  for (var key in from) {\n    to[camelize(key)] = from[key];\n  }\n}\n\n/*  */\n\n// hooks to be invoked on component VNodes during patch\nvar componentVNodeHooks = {\n  init: function init (\n    vnode,\n    hydrating,\n    parentElm,\n    refElm\n  ) {\n    if (!vnode.componentInstance || vnode.componentInstance._isDestroyed) {\n      var child = vnode.componentInstance = createComponentInstanceForVnode(\n        vnode,\n        activeInstance,\n        parentElm,\n        refElm\n      );\n      child.$mount(hydrating ? vnode.elm : undefined, hydrating);\n    } else if (vnode.data.keepAlive) {\n      // kept-alive components, treat as a patch\n      var mountedNode = vnode; // work around flow\n      componentVNodeHooks.prepatch(mountedNode, mountedNode);\n    }\n  },\n\n  prepatch: function prepatch (oldVnode, vnode) {\n    var options = vnode.componentOptions;\n    var child = vnode.componentInstance = oldVnode.componentInstance;\n    updateChildComponent(\n      child,\n      options.propsData, // updated props\n      options.listeners, // updated listeners\n      vnode, // new parent vnode\n      options.children // new children\n    );\n  },\n\n  insert: function insert (vnode) {\n    var context = vnode.context;\n    var componentInstance = vnode.componentInstance;\n    if (!componentInstance._isMounted) {\n      componentInstance._isMounted = true;\n      callHook(componentInstance, 'mounted');\n    }\n    if (vnode.data.keepAlive) {\n      if (context._isMounted) {\n        // vue-router#1212\n        // During updates, a kept-alive component's child components may\n        // change, so directly walking the tree here may call activated hooks\n        // on incorrect children. Instead we push them into a queue which will\n        // be processed after the whole patch process ended.\n        queueActivatedComponent(componentInstance);\n      } else {\n        activateChildComponent(componentInstance, true /* direct */);\n      }\n    }\n  },\n\n  destroy: function destroy (vnode) {\n    var componentInstance = vnode.componentInstance;\n    if (!componentInstance._isDestroyed) {\n      if (!vnode.data.keepAlive) {\n        componentInstance.$destroy();\n      } else {\n        deactivateChildComponent(componentInstance, true /* direct */);\n      }\n    }\n  }\n};\n\nvar hooksToMerge = Object.keys(componentVNodeHooks);\n\nfunction createComponent (\n  Ctor,\n  data,\n  context,\n  children,\n  tag\n) {\n  if (isUndef(Ctor)) {\n    return\n  }\n\n  var baseCtor = context.$options._base;\n\n  // plain options object: turn it into a constructor\n  if (isObject(Ctor)) {\n    Ctor = baseCtor.extend(Ctor);\n  }\n\n  // if at this stage it's not a constructor or an async component factory,\n  // reject.\n  if (typeof Ctor !== 'function') {\n    {\n      warn((\"Invalid Component definition: \" + (String(Ctor))), context);\n    }\n    return\n  }\n\n  // async component\n  if (isUndef(Ctor.cid)) {\n    Ctor = resolveAsyncComponent(Ctor, baseCtor, context);\n    if (Ctor === undefined) {\n      // return nothing if this is indeed an async component\n      // wait for the callback to trigger parent update.\n      return\n    }\n  }\n\n  // resolve constructor options in case global mixins are applied after\n  // component constructor creation\n  resolveConstructorOptions(Ctor);\n\n  data = data || {};\n\n  // transform component v-model data into props & events\n  if (isDef(data.model)) {\n    transformModel(Ctor.options, data);\n  }\n\n  // extract props\n  var propsData = extractPropsFromVNodeData(data, Ctor, tag);\n\n  // functional component\n  if (isTrue(Ctor.options.functional)) {\n    return createFunctionalComponent(Ctor, propsData, data, context, children)\n  }\n\n  // extract listeners, since these needs to be treated as\n  // child component listeners instead of DOM listeners\n  var listeners = data.on;\n  // replace with listeners with .native modifier\n  data.on = data.nativeOn;\n\n  if (isTrue(Ctor.options.abstract)) {\n    // abstract components do not keep anything\n    // other than props & listeners\n    data = {};\n  }\n\n  // merge component management hooks onto the placeholder node\n  mergeHooks(data);\n\n  // return a placeholder vnode\n  var name = Ctor.options.name || tag;\n  var vnode = new VNode(\n    (\"vue-component-\" + (Ctor.cid) + (name ? (\"-\" + name) : '')),\n    data, undefined, undefined, undefined, context,\n    { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children }\n  );\n  return vnode\n}\n\nfunction createComponentInstanceForVnode (\n  vnode, // we know it's MountedComponentVNode but flow doesn't\n  parent, // activeInstance in lifecycle state\n  parentElm,\n  refElm\n) {\n  var vnodeComponentOptions = vnode.componentOptions;\n  var options = {\n    _isComponent: true,\n    parent: parent,\n    propsData: vnodeComponentOptions.propsData,\n    _componentTag: vnodeComponentOptions.tag,\n    _parentVnode: vnode,\n    _parentListeners: vnodeComponentOptions.listeners,\n    _renderChildren: vnodeComponentOptions.children,\n    _parentElm: parentElm || null,\n    _refElm: refElm || null\n  };\n  // check inline-template render functions\n  var inlineTemplate = vnode.data.inlineTemplate;\n  if (isDef(inlineTemplate)) {\n    options.render = inlineTemplate.render;\n    options.staticRenderFns = inlineTemplate.staticRenderFns;\n  }\n  return new vnodeComponentOptions.Ctor(options)\n}\n\nfunction mergeHooks (data) {\n  if (!data.hook) {\n    data.hook = {};\n  }\n  for (var i = 0; i < hooksToMerge.length; i++) {\n    var key = hooksToMerge[i];\n    var fromParent = data.hook[key];\n    var ours = componentVNodeHooks[key];\n    data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;\n  }\n}\n\nfunction mergeHook$1 (one, two) {\n  return function (a, b, c, d) {\n    one(a, b, c, d);\n    two(a, b, c, d);\n  }\n}\n\n// transform component v-model info (value and callback) into\n// prop and event handler respectively.\nfunction transformModel (options, data) {\n  var prop = (options.model && options.model.prop) || 'value';\n  var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value;\n  var on = data.on || (data.on = {});\n  if (isDef(on[event])) {\n    on[event] = [data.model.callback].concat(on[event]);\n  } else {\n    on[event] = data.model.callback;\n  }\n}\n\n/*  */\n\nvar SIMPLE_NORMALIZE = 1;\nvar ALWAYS_NORMALIZE = 2;\n\n// wrapper function for providing a more flexible interface\n// without getting yelled at by flow\nfunction createElement (\n  context,\n  tag,\n  data,\n  children,\n  normalizationType,\n  alwaysNormalize\n) {\n  if (Array.isArray(data) || isPrimitive(data)) {\n    normalizationType = children;\n    children = data;\n    data = undefined;\n  }\n  if (isTrue(alwaysNormalize)) {\n    normalizationType = ALWAYS_NORMALIZE;\n  }\n  return _createElement(context, tag, data, children, normalizationType)\n}\n\nfunction _createElement (\n  context,\n  tag,\n  data,\n  children,\n  normalizationType\n) {\n  if (isDef(data) && isDef((data).__ob__)) {\n    \"development\" !== 'production' && warn(\n      \"Avoid using observed data object as vnode data: \" + (JSON.stringify(data)) + \"\\n\" +\n      'Always create fresh vnode data objects in each render!',\n      context\n    );\n    return createEmptyVNode()\n  }\n  if (!tag) {\n    // in case of component :is set to falsy value\n    return createEmptyVNode()\n  }\n  // support single function children as default scoped slot\n  if (Array.isArray(children) &&\n      typeof children[0] === 'function') {\n    data = data || {};\n    data.scopedSlots = { default: children[0] };\n    children.length = 0;\n  }\n  if (normalizationType === ALWAYS_NORMALIZE) {\n    children = normalizeChildren(children);\n  } else if (normalizationType === SIMPLE_NORMALIZE) {\n    children = simpleNormalizeChildren(children);\n  }\n  var vnode, ns;\n  if (typeof tag === 'string') {\n    var Ctor;\n    ns = config.getTagNamespace(tag);\n    if (config.isReservedTag(tag)) {\n      // platform built-in elements\n      vnode = new VNode(\n        config.parsePlatformTagName(tag), data, children,\n        undefined, undefined, context\n      );\n    } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {\n      // component\n      vnode = createComponent(Ctor, data, context, children, tag);\n    } else {\n      // unknown or unlisted namespaced elements\n      // check at runtime because it may get assigned a namespace when its\n      // parent normalizes children\n      vnode = new VNode(\n        tag, data, children,\n        undefined, undefined, context\n      );\n    }\n  } else {\n    // direct component options / constructor\n    vnode = createComponent(tag, data, context, children);\n  }\n  if (vnode !== undefined) {\n    if (ns) { applyNS(vnode, ns); }\n    return vnode\n  } else {\n    return createEmptyVNode()\n  }\n}\n\nfunction applyNS (vnode, ns) {\n  vnode.ns = ns;\n  if (vnode.tag === 'foreignObject') {\n    // use default namespace inside foreignObject\n    return\n  }\n  if (Array.isArray(vnode.children)) {\n    for (var i = 0, l = vnode.children.length; i < l; i++) {\n      var child = vnode.children[i];\n      if (isDef(child.tag) && isUndef(child.ns)) {\n        applyNS(child, ns);\n      }\n    }\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering v-for lists.\n */\nfunction renderList (\n  val,\n  render\n) {\n  var ret, i, l, keys, key;\n  if (Array.isArray(val) || typeof val === 'string') {\n    ret = new Array(val.length);\n    for (i = 0, l = val.length; i < l; i++) {\n      ret[i] = render(val[i], i);\n    }\n  } else if (typeof val === 'number') {\n    ret = new Array(val);\n    for (i = 0; i < val; i++) {\n      ret[i] = render(i + 1, i);\n    }\n  } else if (isObject(val)) {\n    keys = Object.keys(val);\n    ret = new Array(keys.length);\n    for (i = 0, l = keys.length; i < l; i++) {\n      key = keys[i];\n      ret[i] = render(val[key], key, i);\n    }\n  }\n  return ret\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering <slot>\n */\nfunction renderSlot (\n  name,\n  fallback,\n  props,\n  bindObject\n) {\n  var scopedSlotFn = this.$scopedSlots[name];\n  if (scopedSlotFn) { // scoped slot\n    props = props || {};\n    if (bindObject) {\n      extend(props, bindObject);\n    }\n    return scopedSlotFn(props) || fallback\n  } else {\n    var slotNodes = this.$slots[name];\n    // warn duplicate slot usage\n    if (slotNodes && \"development\" !== 'production') {\n      slotNodes._rendered && warn(\n        \"Duplicate presence of slot \\\"\" + name + \"\\\" found in the same render tree \" +\n        \"- this will likely cause render errors.\",\n        this\n      );\n      slotNodes._rendered = true;\n    }\n    return slotNodes || fallback\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for resolving filters\n */\nfunction resolveFilter (id) {\n  return resolveAsset(this.$options, 'filters', id, true) || identity\n}\n\n/*  */\n\n/**\n * Runtime helper for checking keyCodes from config.\n */\nfunction checkKeyCodes (\n  eventKeyCode,\n  key,\n  builtInAlias\n) {\n  var keyCodes = config.keyCodes[key] || builtInAlias;\n  if (Array.isArray(keyCodes)) {\n    return keyCodes.indexOf(eventKeyCode) === -1\n  } else {\n    return keyCodes !== eventKeyCode\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for merging v-bind=\"object\" into a VNode's data.\n */\nfunction bindObjectProps (\n  data,\n  tag,\n  value,\n  asProp\n) {\n  if (value) {\n    if (!isObject(value)) {\n      \"development\" !== 'production' && warn(\n        'v-bind without argument expects an Object or Array value',\n        this\n      );\n    } else {\n      if (Array.isArray(value)) {\n        value = toObject(value);\n      }\n      var hash;\n      for (var key in value) {\n        if (key === 'class' || key === 'style') {\n          hash = data;\n        } else {\n          var type = data.attrs && data.attrs.type;\n          hash = asProp || config.mustUseProp(tag, type, key)\n            ? data.domProps || (data.domProps = {})\n            : data.attrs || (data.attrs = {});\n        }\n        if (!(key in hash)) {\n          hash[key] = value[key];\n        }\n      }\n    }\n  }\n  return data\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering static trees.\n */\nfunction renderStatic (\n  index,\n  isInFor\n) {\n  var tree = this._staticTrees[index];\n  // if has already-rendered static tree and not inside v-for,\n  // we can reuse the same tree by doing a shallow clone.\n  if (tree && !isInFor) {\n    return Array.isArray(tree)\n      ? cloneVNodes(tree)\n      : cloneVNode(tree)\n  }\n  // otherwise, render a fresh tree.\n  tree = this._staticTrees[index] =\n    this.$options.staticRenderFns[index].call(this._renderProxy);\n  markStatic(tree, (\"__static__\" + index), false);\n  return tree\n}\n\n/**\n * Runtime helper for v-once.\n * Effectively it means marking the node as static with a unique key.\n */\nfunction markOnce (\n  tree,\n  index,\n  key\n) {\n  markStatic(tree, (\"__once__\" + index + (key ? (\"_\" + key) : \"\")), true);\n  return tree\n}\n\nfunction markStatic (\n  tree,\n  key,\n  isOnce\n) {\n  if (Array.isArray(tree)) {\n    for (var i = 0; i < tree.length; i++) {\n      if (tree[i] && typeof tree[i] !== 'string') {\n        markStaticNode(tree[i], (key + \"_\" + i), isOnce);\n      }\n    }\n  } else {\n    markStaticNode(tree, key, isOnce);\n  }\n}\n\nfunction markStaticNode (node, key, isOnce) {\n  node.isStatic = true;\n  node.key = key;\n  node.isOnce = isOnce;\n}\n\n/*  */\n\nfunction initRender (vm) {\n  vm._vnode = null; // the root of the child tree\n  vm._staticTrees = null;\n  var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree\n  var renderContext = parentVnode && parentVnode.context;\n  vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext);\n  vm.$scopedSlots = emptyObject;\n  // bind the createElement fn to this instance\n  // so that we get proper render context inside it.\n  // args order: tag, data, children, normalizationType, alwaysNormalize\n  // internal version is used by render functions compiled from templates\n  vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); };\n  // normalization is always applied for the public version, used in\n  // user-written render functions.\n  vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); };\n}\n\nfunction renderMixin (Vue) {\n  Vue.prototype.$nextTick = function (fn) {\n    return nextTick(fn, this)\n  };\n\n  Vue.prototype._render = function () {\n    var vm = this;\n    var ref = vm.$options;\n    var render = ref.render;\n    var staticRenderFns = ref.staticRenderFns;\n    var _parentVnode = ref._parentVnode;\n\n    if (vm._isMounted) {\n      // clone slot nodes on re-renders\n      for (var key in vm.$slots) {\n        vm.$slots[key] = cloneVNodes(vm.$slots[key]);\n      }\n    }\n\n    vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject;\n\n    if (staticRenderFns && !vm._staticTrees) {\n      vm._staticTrees = [];\n    }\n    // set parent vnode. this allows render functions to have access\n    // to the data on the placeholder node.\n    vm.$vnode = _parentVnode;\n    // render self\n    var vnode;\n    try {\n      vnode = render.call(vm._renderProxy, vm.$createElement);\n    } catch (e) {\n      handleError(e, vm, \"render function\");\n      // return error render result,\n      // or previous vnode to prevent render error causing blank component\n      /* istanbul ignore else */\n      {\n        vnode = vm.$options.renderError\n          ? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e)\n          : vm._vnode;\n      }\n    }\n    // return empty vnode in case the render function errored out\n    if (!(vnode instanceof VNode)) {\n      if (\"development\" !== 'production' && Array.isArray(vnode)) {\n        warn(\n          'Multiple root nodes returned from render function. Render function ' +\n          'should return a single root node.',\n          vm\n        );\n      }\n      vnode = createEmptyVNode();\n    }\n    // set parent\n    vnode.parent = _parentVnode;\n    return vnode\n  };\n\n  // internal render helpers.\n  // these are exposed on the instance prototype to reduce generated render\n  // code size.\n  Vue.prototype._o = markOnce;\n  Vue.prototype._n = toNumber;\n  Vue.prototype._s = _toString;\n  Vue.prototype._l = renderList;\n  Vue.prototype._t = renderSlot;\n  Vue.prototype._q = looseEqual;\n  Vue.prototype._i = looseIndexOf;\n  Vue.prototype._m = renderStatic;\n  Vue.prototype._f = resolveFilter;\n  Vue.prototype._k = checkKeyCodes;\n  Vue.prototype._b = bindObjectProps;\n  Vue.prototype._v = createTextVNode;\n  Vue.prototype._e = createEmptyVNode;\n  Vue.prototype._u = resolveScopedSlots;\n}\n\n/*  */\n\nvar uid$1 = 0;\n\nfunction initMixin (Vue) {\n  Vue.prototype._init = function (options) {\n    var vm = this;\n    // a uid\n    vm._uid = uid$1++;\n\n    var startTag, endTag;\n    /* istanbul ignore if */\n    if (\"development\" !== 'production' && config.performance && mark) {\n      startTag = \"vue-perf-init:\" + (vm._uid);\n      endTag = \"vue-perf-end:\" + (vm._uid);\n      mark(startTag);\n    }\n\n    // a flag to avoid this being observed\n    vm._isVue = true;\n    // merge options\n    if (options && options._isComponent) {\n      // optimize internal component instantiation\n      // since dynamic options merging is pretty slow, and none of the\n      // internal component options needs special treatment.\n      initInternalComponent(vm, options);\n    } else {\n      vm.$options = mergeOptions(\n        resolveConstructorOptions(vm.constructor),\n        options || {},\n        vm\n      );\n    }\n    /* istanbul ignore else */\n    {\n      initProxy(vm);\n    }\n    // expose real self\n    vm._self = vm;\n    initLifecycle(vm);\n    initEvents(vm);\n    initRender(vm);\n    callHook(vm, 'beforeCreate');\n    initInjections(vm); // resolve injections before data/props\n    initState(vm);\n    initProvide(vm); // resolve provide after data/props\n    callHook(vm, 'created');\n\n    /* istanbul ignore if */\n    if (\"development\" !== 'production' && config.performance && mark) {\n      vm._name = formatComponentName(vm, false);\n      mark(endTag);\n      measure(((vm._name) + \" init\"), startTag, endTag);\n    }\n\n    if (vm.$options.el) {\n      vm.$mount(vm.$options.el);\n    }\n  };\n}\n\nfunction initInternalComponent (vm, options) {\n  var opts = vm.$options = Object.create(vm.constructor.options);\n  // doing this because it's faster than dynamic enumeration.\n  opts.parent = options.parent;\n  opts.propsData = options.propsData;\n  opts._parentVnode = options._parentVnode;\n  opts._parentListeners = options._parentListeners;\n  opts._renderChildren = options._renderChildren;\n  opts._componentTag = options._componentTag;\n  opts._parentElm = options._parentElm;\n  opts._refElm = options._refElm;\n  if (options.render) {\n    opts.render = options.render;\n    opts.staticRenderFns = options.staticRenderFns;\n  }\n}\n\nfunction resolveConstructorOptions (Ctor) {\n  var options = Ctor.options;\n  if (Ctor.super) {\n    var superOptions = resolveConstructorOptions(Ctor.super);\n    var cachedSuperOptions = Ctor.superOptions;\n    if (superOptions !== cachedSuperOptions) {\n      // super option changed,\n      // need to resolve new options.\n      Ctor.superOptions = superOptions;\n      // check if there are any late-modified/attached options (#4976)\n      var modifiedOptions = resolveModifiedOptions(Ctor);\n      // update base extend options\n      if (modifiedOptions) {\n        extend(Ctor.extendOptions, modifiedOptions);\n      }\n      options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);\n      if (options.name) {\n        options.components[options.name] = Ctor;\n      }\n    }\n  }\n  return options\n}\n\nfunction resolveModifiedOptions (Ctor) {\n  var modified;\n  var latest = Ctor.options;\n  var extended = Ctor.extendOptions;\n  var sealed = Ctor.sealedOptions;\n  for (var key in latest) {\n    if (latest[key] !== sealed[key]) {\n      if (!modified) { modified = {}; }\n      modified[key] = dedupe(latest[key], extended[key], sealed[key]);\n    }\n  }\n  return modified\n}\n\nfunction dedupe (latest, extended, sealed) {\n  // compare latest and sealed to ensure lifecycle hooks won't be duplicated\n  // between merges\n  if (Array.isArray(latest)) {\n    var res = [];\n    sealed = Array.isArray(sealed) ? sealed : [sealed];\n    extended = Array.isArray(extended) ? extended : [extended];\n    for (var i = 0; i < latest.length; i++) {\n      // push original options and not sealed options to exclude duplicated options\n      if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) {\n        res.push(latest[i]);\n      }\n    }\n    return res\n  } else {\n    return latest\n  }\n}\n\nfunction Vue$3 (options) {\n  if (\"development\" !== 'production' &&\n    !(this instanceof Vue$3)) {\n    warn('Vue is a constructor and should be called with the `new` keyword');\n  }\n  this._init(options);\n}\n\ninitMixin(Vue$3);\nstateMixin(Vue$3);\neventsMixin(Vue$3);\nlifecycleMixin(Vue$3);\nrenderMixin(Vue$3);\n\n/*  */\n\nfunction initUse (Vue) {\n  Vue.use = function (plugin) {\n    /* istanbul ignore if */\n    if (plugin.installed) {\n      return\n    }\n    // additional parameters\n    var args = toArray(arguments, 1);\n    args.unshift(this);\n    if (typeof plugin.install === 'function') {\n      plugin.install.apply(plugin, args);\n    } else if (typeof plugin === 'function') {\n      plugin.apply(null, args);\n    }\n    plugin.installed = true;\n    return this\n  };\n}\n\n/*  */\n\nfunction initMixin$1 (Vue) {\n  Vue.mixin = function (mixin) {\n    this.options = mergeOptions(this.options, mixin);\n  };\n}\n\n/*  */\n\nfunction initExtend (Vue) {\n  /**\n   * Each instance constructor, including Vue, has a unique\n   * cid. This enables us to create wrapped \"child\n   * constructors\" for prototypal inheritance and cache them.\n   */\n  Vue.cid = 0;\n  var cid = 1;\n\n  /**\n   * Class inheritance\n   */\n  Vue.extend = function (extendOptions) {\n    extendOptions = extendOptions || {};\n    var Super = this;\n    var SuperId = Super.cid;\n    var cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {});\n    if (cachedCtors[SuperId]) {\n      return cachedCtors[SuperId]\n    }\n\n    var name = extendOptions.name || Super.options.name;\n    {\n      if (!/^[a-zA-Z][\\w-]*$/.test(name)) {\n        warn(\n          'Invalid component name: \"' + name + '\". Component names ' +\n          'can only contain alphanumeric characters and the hyphen, ' +\n          'and must start with a letter.'\n        );\n      }\n    }\n\n    var Sub = function VueComponent (options) {\n      this._init(options);\n    };\n    Sub.prototype = Object.create(Super.prototype);\n    Sub.prototype.constructor = Sub;\n    Sub.cid = cid++;\n    Sub.options = mergeOptions(\n      Super.options,\n      extendOptions\n    );\n    Sub['super'] = Super;\n\n    // For props and computed properties, we define the proxy getters on\n    // the Vue instances at extension time, on the extended prototype. This\n    // avoids Object.defineProperty calls for each instance created.\n    if (Sub.options.props) {\n      initProps$1(Sub);\n    }\n    if (Sub.options.computed) {\n      initComputed$1(Sub);\n    }\n\n    // allow further extension/mixin/plugin usage\n    Sub.extend = Super.extend;\n    Sub.mixin = Super.mixin;\n    Sub.use = Super.use;\n\n    // create asset registers, so extended classes\n    // can have their private assets too.\n    ASSET_TYPES.forEach(function (type) {\n      Sub[type] = Super[type];\n    });\n    // enable recursive self-lookup\n    if (name) {\n      Sub.options.components[name] = Sub;\n    }\n\n    // keep a reference to the super options at extension time.\n    // later at instantiation we can check if Super's options have\n    // been updated.\n    Sub.superOptions = Super.options;\n    Sub.extendOptions = extendOptions;\n    Sub.sealedOptions = extend({}, Sub.options);\n\n    // cache constructor\n    cachedCtors[SuperId] = Sub;\n    return Sub\n  };\n}\n\nfunction initProps$1 (Comp) {\n  var props = Comp.options.props;\n  for (var key in props) {\n    proxy(Comp.prototype, \"_props\", key);\n  }\n}\n\nfunction initComputed$1 (Comp) {\n  var computed = Comp.options.computed;\n  for (var key in computed) {\n    defineComputed(Comp.prototype, key, computed[key]);\n  }\n}\n\n/*  */\n\nfunction initAssetRegisters (Vue) {\n  /**\n   * Create asset registration methods.\n   */\n  ASSET_TYPES.forEach(function (type) {\n    Vue[type] = function (\n      id,\n      definition\n    ) {\n      if (!definition) {\n        return this.options[type + 's'][id]\n      } else {\n        /* istanbul ignore if */\n        {\n          if (type === 'component' && config.isReservedTag(id)) {\n            warn(\n              'Do not use built-in or reserved HTML elements as component ' +\n              'id: ' + id\n            );\n          }\n        }\n        if (type === 'component' && isPlainObject(definition)) {\n          definition.name = definition.name || id;\n          definition = this.options._base.extend(definition);\n        }\n        if (type === 'directive' && typeof definition === 'function') {\n          definition = { bind: definition, update: definition };\n        }\n        this.options[type + 's'][id] = definition;\n        return definition\n      }\n    };\n  });\n}\n\n/*  */\n\nvar patternTypes = [String, RegExp];\n\nfunction getComponentName (opts) {\n  return opts && (opts.Ctor.options.name || opts.tag)\n}\n\nfunction matches (pattern, name) {\n  if (typeof pattern === 'string') {\n    return pattern.split(',').indexOf(name) > -1\n  } else if (isRegExp(pattern)) {\n    return pattern.test(name)\n  }\n  /* istanbul ignore next */\n  return false\n}\n\nfunction pruneCache (cache, current, filter) {\n  for (var key in cache) {\n    var cachedNode = cache[key];\n    if (cachedNode) {\n      var name = getComponentName(cachedNode.componentOptions);\n      if (name && !filter(name)) {\n        if (cachedNode !== current) {\n          pruneCacheEntry(cachedNode);\n        }\n        cache[key] = null;\n      }\n    }\n  }\n}\n\nfunction pruneCacheEntry (vnode) {\n  if (vnode) {\n    vnode.componentInstance.$destroy();\n  }\n}\n\nvar KeepAlive = {\n  name: 'keep-alive',\n  abstract: true,\n\n  props: {\n    include: patternTypes,\n    exclude: patternTypes\n  },\n\n  created: function created () {\n    this.cache = Object.create(null);\n  },\n\n  destroyed: function destroyed () {\n    var this$1 = this;\n\n    for (var key in this$1.cache) {\n      pruneCacheEntry(this$1.cache[key]);\n    }\n  },\n\n  watch: {\n    include: function include (val) {\n      pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); });\n    },\n    exclude: function exclude (val) {\n      pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); });\n    }\n  },\n\n  render: function render () {\n    var vnode = getFirstComponentChild(this.$slots.default);\n    var componentOptions = vnode && vnode.componentOptions;\n    if (componentOptions) {\n      // check pattern\n      var name = getComponentName(componentOptions);\n      if (name && (\n        (this.include && !matches(this.include, name)) ||\n        (this.exclude && matches(this.exclude, name))\n      )) {\n        return vnode\n      }\n      var key = vnode.key == null\n        // same constructor may get registered as different local components\n        // so cid alone is not enough (#3269)\n        ? componentOptions.Ctor.cid + (componentOptions.tag ? (\"::\" + (componentOptions.tag)) : '')\n        : vnode.key;\n      if (this.cache[key]) {\n        vnode.componentInstance = this.cache[key].componentInstance;\n      } else {\n        this.cache[key] = vnode;\n      }\n      vnode.data.keepAlive = true;\n    }\n    return vnode\n  }\n};\n\nvar builtInComponents = {\n  KeepAlive: KeepAlive\n};\n\n/*  */\n\nfunction initGlobalAPI (Vue) {\n  // config\n  var configDef = {};\n  configDef.get = function () { return config; };\n  {\n    configDef.set = function () {\n      warn(\n        'Do not replace the Vue.config object, set individual fields instead.'\n      );\n    };\n  }\n  Object.defineProperty(Vue, 'config', configDef);\n\n  // exposed util methods.\n  // NOTE: these are not considered part of the public API - avoid relying on\n  // them unless you are aware of the risk.\n  Vue.util = {\n    warn: warn,\n    extend: extend,\n    mergeOptions: mergeOptions,\n    defineReactive: defineReactive$$1\n  };\n\n  Vue.set = set;\n  Vue.delete = del;\n  Vue.nextTick = nextTick;\n\n  Vue.options = Object.create(null);\n  ASSET_TYPES.forEach(function (type) {\n    Vue.options[type + 's'] = Object.create(null);\n  });\n\n  // this is used to identify the \"base\" constructor to extend all plain-object\n  // components with in Weex's multi-instance scenarios.\n  Vue.options._base = Vue;\n\n  extend(Vue.options.components, builtInComponents);\n\n  initUse(Vue);\n  initMixin$1(Vue);\n  initExtend(Vue);\n  initAssetRegisters(Vue);\n}\n\ninitGlobalAPI(Vue$3);\n\nObject.defineProperty(Vue$3.prototype, '$isServer', {\n  get: isServerRendering\n});\n\nVue$3.version = '2.3.0';\n\n/*  */\n\n// these are reserved for web because they are directly compiled away\n// during template compilation\nvar isReservedAttr = makeMap('style,class');\n\n// attributes that should be using props for binding\nvar acceptValue = makeMap('input,textarea,option,select');\nvar mustUseProp = function (tag, type, attr) {\n  return (\n    (attr === 'value' && acceptValue(tag)) && type !== 'button' ||\n    (attr === 'selected' && tag === 'option') ||\n    (attr === 'checked' && tag === 'input') ||\n    (attr === 'muted' && tag === 'video')\n  )\n};\n\nvar isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');\n\nvar isBooleanAttr = makeMap(\n  'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +\n  'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +\n  'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +\n  'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +\n  'required,reversed,scoped,seamless,selected,sortable,translate,' +\n  'truespeed,typemustmatch,visible'\n);\n\nvar xlinkNS = 'http://www.w3.org/1999/xlink';\n\nvar isXlink = function (name) {\n  return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'\n};\n\nvar getXlinkProp = function (name) {\n  return isXlink(name) ? name.slice(6, name.length) : ''\n};\n\nvar isFalsyAttrValue = function (val) {\n  return val == null || val === false\n};\n\n/*  */\n\nfunction genClassForVnode (vnode) {\n  var data = vnode.data;\n  var parentNode = vnode;\n  var childNode = vnode;\n  while (isDef(childNode.componentInstance)) {\n    childNode = childNode.componentInstance._vnode;\n    if (childNode.data) {\n      data = mergeClassData(childNode.data, data);\n    }\n  }\n  while (isDef(parentNode = parentNode.parent)) {\n    if (parentNode.data) {\n      data = mergeClassData(data, parentNode.data);\n    }\n  }\n  return genClassFromData(data)\n}\n\nfunction mergeClassData (child, parent) {\n  return {\n    staticClass: concat(child.staticClass, parent.staticClass),\n    class: isDef(child.class)\n      ? [child.class, parent.class]\n      : parent.class\n  }\n}\n\nfunction genClassFromData (data) {\n  var dynamicClass = data.class;\n  var staticClass = data.staticClass;\n  if (isDef(staticClass) || isDef(dynamicClass)) {\n    return concat(staticClass, stringifyClass(dynamicClass))\n  }\n  /* istanbul ignore next */\n  return ''\n}\n\nfunction concat (a, b) {\n  return a ? b ? (a + ' ' + b) : a : (b || '')\n}\n\nfunction stringifyClass (value) {\n  if (isUndef(value)) {\n    return ''\n  }\n  if (typeof value === 'string') {\n    return value\n  }\n  var res = '';\n  if (Array.isArray(value)) {\n    var stringified;\n    for (var i = 0, l = value.length; i < l; i++) {\n      if (isDef(value[i])) {\n        if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {\n          res += stringified + ' ';\n        }\n      }\n    }\n    return res.slice(0, -1)\n  }\n  if (isObject(value)) {\n    for (var key in value) {\n      if (value[key]) { res += key + ' '; }\n    }\n    return res.slice(0, -1)\n  }\n  /* istanbul ignore next */\n  return res\n}\n\n/*  */\n\nvar namespaceMap = {\n  svg: 'http://www.w3.org/2000/svg',\n  math: 'http://www.w3.org/1998/Math/MathML'\n};\n\nvar isHTMLTag = makeMap(\n  'html,body,base,head,link,meta,style,title,' +\n  'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +\n  'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' +\n  'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +\n  's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +\n  'embed,object,param,source,canvas,script,noscript,del,ins,' +\n  'caption,col,colgroup,table,thead,tbody,td,th,tr,' +\n  'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +\n  'output,progress,select,textarea,' +\n  'details,dialog,menu,menuitem,summary,' +\n  'content,element,shadow,template'\n);\n\n// this map is intentionally selective, only covering SVG elements that may\n// contain child elements.\nvar isSVG = makeMap(\n  'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +\n  'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +\n  'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',\n  true\n);\n\nvar isPreTag = function (tag) { return tag === 'pre'; };\n\nvar isReservedTag = function (tag) {\n  return isHTMLTag(tag) || isSVG(tag)\n};\n\nfunction getTagNamespace (tag) {\n  if (isSVG(tag)) {\n    return 'svg'\n  }\n  // basic support for MathML\n  // note it doesn't support other MathML elements being component roots\n  if (tag === 'math') {\n    return 'math'\n  }\n}\n\nvar unknownElementCache = Object.create(null);\nfunction isUnknownElement (tag) {\n  /* istanbul ignore if */\n  if (!inBrowser) {\n    return true\n  }\n  if (isReservedTag(tag)) {\n    return false\n  }\n  tag = tag.toLowerCase();\n  /* istanbul ignore if */\n  if (unknownElementCache[tag] != null) {\n    return unknownElementCache[tag]\n  }\n  var el = document.createElement(tag);\n  if (tag.indexOf('-') > -1) {\n    // http://stackoverflow.com/a/28210364/1070244\n    return (unknownElementCache[tag] = (\n      el.constructor === window.HTMLUnknownElement ||\n      el.constructor === window.HTMLElement\n    ))\n  } else {\n    return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()))\n  }\n}\n\n/*  */\n\n/**\n * Query an element selector if it's not an element already.\n */\nfunction query (el) {\n  if (typeof el === 'string') {\n    var selected = document.querySelector(el);\n    if (!selected) {\n      \"development\" !== 'production' && warn(\n        'Cannot find element: ' + el\n      );\n      return document.createElement('div')\n    }\n    return selected\n  } else {\n    return el\n  }\n}\n\n/*  */\n\nfunction createElement$1 (tagName, vnode) {\n  var elm = document.createElement(tagName);\n  if (tagName !== 'select') {\n    return elm\n  }\n  // false or null will remove the attribute but undefined will not\n  if (vnode.data && vnode.data.attrs && vnode.data.attrs.multiple !== undefined) {\n    elm.setAttribute('multiple', 'multiple');\n  }\n  return elm\n}\n\nfunction createElementNS (namespace, tagName) {\n  return document.createElementNS(namespaceMap[namespace], tagName)\n}\n\nfunction createTextNode (text) {\n  return document.createTextNode(text)\n}\n\nfunction createComment (text) {\n  return document.createComment(text)\n}\n\nfunction insertBefore (parentNode, newNode, referenceNode) {\n  parentNode.insertBefore(newNode, referenceNode);\n}\n\nfunction removeChild (node, child) {\n  node.removeChild(child);\n}\n\nfunction appendChild (node, child) {\n  node.appendChild(child);\n}\n\nfunction parentNode (node) {\n  return node.parentNode\n}\n\nfunction nextSibling (node) {\n  return node.nextSibling\n}\n\nfunction tagName (node) {\n  return node.tagName\n}\n\nfunction setTextContent (node, text) {\n  node.textContent = text;\n}\n\nfunction setAttribute (node, key, val) {\n  node.setAttribute(key, val);\n}\n\n\nvar nodeOps = Object.freeze({\n\tcreateElement: createElement$1,\n\tcreateElementNS: createElementNS,\n\tcreateTextNode: createTextNode,\n\tcreateComment: createComment,\n\tinsertBefore: insertBefore,\n\tremoveChild: removeChild,\n\tappendChild: appendChild,\n\tparentNode: parentNode,\n\tnextSibling: nextSibling,\n\ttagName: tagName,\n\tsetTextContent: setTextContent,\n\tsetAttribute: setAttribute\n});\n\n/*  */\n\nvar ref = {\n  create: function create (_, vnode) {\n    registerRef(vnode);\n  },\n  update: function update (oldVnode, vnode) {\n    if (oldVnode.data.ref !== vnode.data.ref) {\n      registerRef(oldVnode, true);\n      registerRef(vnode);\n    }\n  },\n  destroy: function destroy (vnode) {\n    registerRef(vnode, true);\n  }\n};\n\nfunction registerRef (vnode, isRemoval) {\n  var key = vnode.data.ref;\n  if (!key) { return }\n\n  var vm = vnode.context;\n  var ref = vnode.componentInstance || vnode.elm;\n  var refs = vm.$refs;\n  if (isRemoval) {\n    if (Array.isArray(refs[key])) {\n      remove(refs[key], ref);\n    } else if (refs[key] === ref) {\n      refs[key] = undefined;\n    }\n  } else {\n    if (vnode.data.refInFor) {\n      if (Array.isArray(refs[key]) && refs[key].indexOf(ref) < 0) {\n        refs[key].push(ref);\n      } else {\n        refs[key] = [ref];\n      }\n    } else {\n      refs[key] = ref;\n    }\n  }\n}\n\n/**\n * Virtual DOM patching algorithm based on Snabbdom by\n * Simon Friis Vindum (@paldepind)\n * Licensed under the MIT License\n * https://github.com/paldepind/snabbdom/blob/master/LICENSE\n *\n * modified by Evan You (@yyx990803)\n *\n\n/*\n * Not type-checking this because this file is perf-critical and the cost\n * of making flow understand it is not worth it.\n */\n\nvar emptyNode = new VNode('', {}, []);\n\nvar hooks = ['create', 'activate', 'update', 'remove', 'destroy'];\n\nfunction sameVnode (a, b) {\n  return (\n    a.key === b.key &&\n    a.tag === b.tag &&\n    a.isComment === b.isComment &&\n    isDef(a.data) === isDef(b.data) &&\n    sameInputType(a, b)\n  )\n}\n\n// Some browsers do not support dynamically changing type for <input>\n// so they need to be treated as different nodes\nfunction sameInputType (a, b) {\n  if (a.tag !== 'input') { return true }\n  var i;\n  var typeA = isDef(i = a.data) && isDef(i = i.attrs) && i.type;\n  var typeB = isDef(i = b.data) && isDef(i = i.attrs) && i.type;\n  return typeA === typeB\n}\n\nfunction createKeyToOldIdx (children, beginIdx, endIdx) {\n  var i, key;\n  var map = {};\n  for (i = beginIdx; i <= endIdx; ++i) {\n    key = children[i].key;\n    if (isDef(key)) { map[key] = i; }\n  }\n  return map\n}\n\nfunction createPatchFunction (backend) {\n  var i, j;\n  var cbs = {};\n\n  var modules = backend.modules;\n  var nodeOps = backend.nodeOps;\n\n  for (i = 0; i < hooks.length; ++i) {\n    cbs[hooks[i]] = [];\n    for (j = 0; j < modules.length; ++j) {\n      if (isDef(modules[j][hooks[i]])) {\n        cbs[hooks[i]].push(modules[j][hooks[i]]);\n      }\n    }\n  }\n\n  function emptyNodeAt (elm) {\n    return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)\n  }\n\n  function createRmCb (childElm, listeners) {\n    function remove$$1 () {\n      if (--remove$$1.listeners === 0) {\n        removeNode(childElm);\n      }\n    }\n    remove$$1.listeners = listeners;\n    return remove$$1\n  }\n\n  function removeNode (el) {\n    var parent = nodeOps.parentNode(el);\n    // element may have already been removed due to v-html / v-text\n    if (isDef(parent)) {\n      nodeOps.removeChild(parent, el);\n    }\n  }\n\n  var inPre = 0;\n  function createElm (vnode, insertedVnodeQueue, parentElm, refElm, nested) {\n    vnode.isRootInsert = !nested; // for transition enter check\n    if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {\n      return\n    }\n\n    var data = vnode.data;\n    var children = vnode.children;\n    var tag = vnode.tag;\n    if (isDef(tag)) {\n      {\n        if (data && data.pre) {\n          inPre++;\n        }\n        if (\n          !inPre &&\n          !vnode.ns &&\n          !(config.ignoredElements.length && config.ignoredElements.indexOf(tag) > -1) &&\n          config.isUnknownElement(tag)\n        ) {\n          warn(\n            'Unknown custom element: <' + tag + '> - did you ' +\n            'register the component correctly? For recursive components, ' +\n            'make sure to provide the \"name\" option.',\n            vnode.context\n          );\n        }\n      }\n      vnode.elm = vnode.ns\n        ? nodeOps.createElementNS(vnode.ns, tag)\n        : nodeOps.createElement(tag, vnode);\n      setScope(vnode);\n\n      /* istanbul ignore if */\n      {\n        createChildren(vnode, children, insertedVnodeQueue);\n        if (isDef(data)) {\n          invokeCreateHooks(vnode, insertedVnodeQueue);\n        }\n        insert(parentElm, vnode.elm, refElm);\n      }\n\n      if (\"development\" !== 'production' && data && data.pre) {\n        inPre--;\n      }\n    } else if (isTrue(vnode.isComment)) {\n      vnode.elm = nodeOps.createComment(vnode.text);\n      insert(parentElm, vnode.elm, refElm);\n    } else {\n      vnode.elm = nodeOps.createTextNode(vnode.text);\n      insert(parentElm, vnode.elm, refElm);\n    }\n  }\n\n  function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) {\n    var i = vnode.data;\n    if (isDef(i)) {\n      var isReactivated = isDef(vnode.componentInstance) && i.keepAlive;\n      if (isDef(i = i.hook) && isDef(i = i.init)) {\n        i(vnode, false /* hydrating */, parentElm, refElm);\n      }\n      // after calling the init hook, if the vnode is a child component\n      // it should've created a child instance and mounted it. the child\n      // component also has set the placeholder vnode's elm.\n      // in that case we can just return the element and be done.\n      if (isDef(vnode.componentInstance)) {\n        initComponent(vnode, insertedVnodeQueue);\n        if (isTrue(isReactivated)) {\n          reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm);\n        }\n        return true\n      }\n    }\n  }\n\n  function initComponent (vnode, insertedVnodeQueue) {\n    if (isDef(vnode.data.pendingInsert)) {\n      insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert);\n    }\n    vnode.elm = vnode.componentInstance.$el;\n    if (isPatchable(vnode)) {\n      invokeCreateHooks(vnode, insertedVnodeQueue);\n      setScope(vnode);\n    } else {\n      // empty component root.\n      // skip all element-related modules except for ref (#3455)\n      registerRef(vnode);\n      // make sure to invoke the insert hook\n      insertedVnodeQueue.push(vnode);\n    }\n  }\n\n  function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) {\n    var i;\n    // hack for #4339: a reactivated component with inner transition\n    // does not trigger because the inner node's created hooks are not called\n    // again. It's not ideal to involve module-specific logic in here but\n    // there doesn't seem to be a better way to do it.\n    var innerNode = vnode;\n    while (innerNode.componentInstance) {\n      innerNode = innerNode.componentInstance._vnode;\n      if (isDef(i = innerNode.data) && isDef(i = i.transition)) {\n        for (i = 0; i < cbs.activate.length; ++i) {\n          cbs.activate[i](emptyNode, innerNode);\n        }\n        insertedVnodeQueue.push(innerNode);\n        break\n      }\n    }\n    // unlike a newly created component,\n    // a reactivated keep-alive component doesn't insert itself\n    insert(parentElm, vnode.elm, refElm);\n  }\n\n  function insert (parent, elm, ref) {\n    if (isDef(parent)) {\n      if (isDef(ref)) {\n        if (ref.parentNode === parent) {\n          nodeOps.insertBefore(parent, elm, ref);\n        }\n      } else {\n        nodeOps.appendChild(parent, elm);\n      }\n    }\n  }\n\n  function createChildren (vnode, children, insertedVnodeQueue) {\n    if (Array.isArray(children)) {\n      for (var i = 0; i < children.length; ++i) {\n        createElm(children[i], insertedVnodeQueue, vnode.elm, null, true);\n      }\n    } else if (isPrimitive(vnode.text)) {\n      nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text));\n    }\n  }\n\n  function isPatchable (vnode) {\n    while (vnode.componentInstance) {\n      vnode = vnode.componentInstance._vnode;\n    }\n    return isDef(vnode.tag)\n  }\n\n  function invokeCreateHooks (vnode, insertedVnodeQueue) {\n    for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) {\n      cbs.create[i$1](emptyNode, vnode);\n    }\n    i = vnode.data.hook; // Reuse variable\n    if (isDef(i)) {\n      if (isDef(i.create)) { i.create(emptyNode, vnode); }\n      if (isDef(i.insert)) { insertedVnodeQueue.push(vnode); }\n    }\n  }\n\n  // set scope id attribute for scoped CSS.\n  // this is implemented as a special case to avoid the overhead\n  // of going through the normal attribute patching process.\n  function setScope (vnode) {\n    var i;\n    var ancestor = vnode;\n    while (ancestor) {\n      if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) {\n        nodeOps.setAttribute(vnode.elm, i, '');\n      }\n      ancestor = ancestor.parent;\n    }\n    // for slot content they should also get the scopeId from the host instance.\n    if (isDef(i = activeInstance) &&\n        i !== vnode.context &&\n        isDef(i = i.$options._scopeId)) {\n      nodeOps.setAttribute(vnode.elm, i, '');\n    }\n  }\n\n  function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx, insertedVnodeQueue) {\n    for (; startIdx <= endIdx; ++startIdx) {\n      createElm(vnodes[startIdx], insertedVnodeQueue, parentElm, refElm);\n    }\n  }\n\n  function invokeDestroyHook (vnode) {\n    var i, j;\n    var data = vnode.data;\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.destroy)) { i(vnode); }\n      for (i = 0; i < cbs.destroy.length; ++i) { cbs.destroy[i](vnode); }\n    }\n    if (isDef(i = vnode.children)) {\n      for (j = 0; j < vnode.children.length; ++j) {\n        invokeDestroyHook(vnode.children[j]);\n      }\n    }\n  }\n\n  function removeVnodes (parentElm, vnodes, startIdx, endIdx) {\n    for (; startIdx <= endIdx; ++startIdx) {\n      var ch = vnodes[startIdx];\n      if (isDef(ch)) {\n        if (isDef(ch.tag)) {\n          removeAndInvokeRemoveHook(ch);\n          invokeDestroyHook(ch);\n        } else { // Text node\n          removeNode(ch.elm);\n        }\n      }\n    }\n  }\n\n  function removeAndInvokeRemoveHook (vnode, rm) {\n    if (isDef(rm) || isDef(vnode.data)) {\n      var i;\n      var listeners = cbs.remove.length + 1;\n      if (isDef(rm)) {\n        // we have a recursively passed down rm callback\n        // increase the listeners count\n        rm.listeners += listeners;\n      } else {\n        // directly removing\n        rm = createRmCb(vnode.elm, listeners);\n      }\n      // recursively invoke hooks on child component root node\n      if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) {\n        removeAndInvokeRemoveHook(i, rm);\n      }\n      for (i = 0; i < cbs.remove.length; ++i) {\n        cbs.remove[i](vnode, rm);\n      }\n      if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {\n        i(vnode, rm);\n      } else {\n        rm();\n      }\n    } else {\n      removeNode(vnode.elm);\n    }\n  }\n\n  function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {\n    var oldStartIdx = 0;\n    var newStartIdx = 0;\n    var oldEndIdx = oldCh.length - 1;\n    var oldStartVnode = oldCh[0];\n    var oldEndVnode = oldCh[oldEndIdx];\n    var newEndIdx = newCh.length - 1;\n    var newStartVnode = newCh[0];\n    var newEndVnode = newCh[newEndIdx];\n    var oldKeyToIdx, idxInOld, elmToMove, refElm;\n\n    // removeOnly is a special flag used only by <transition-group>\n    // to ensure removed elements stay in correct relative positions\n    // during leaving transitions\n    var canMove = !removeOnly;\n\n    while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {\n      if (isUndef(oldStartVnode)) {\n        oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left\n      } else if (isUndef(oldEndVnode)) {\n        oldEndVnode = oldCh[--oldEndIdx];\n      } else if (sameVnode(oldStartVnode, newStartVnode)) {\n        patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);\n        oldStartVnode = oldCh[++oldStartIdx];\n        newStartVnode = newCh[++newStartIdx];\n      } else if (sameVnode(oldEndVnode, newEndVnode)) {\n        patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);\n        oldEndVnode = oldCh[--oldEndIdx];\n        newEndVnode = newCh[--newEndIdx];\n      } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right\n        patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);\n        canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));\n        oldStartVnode = oldCh[++oldStartIdx];\n        newEndVnode = newCh[--newEndIdx];\n      } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left\n        patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);\n        canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);\n        oldEndVnode = oldCh[--oldEndIdx];\n        newStartVnode = newCh[++newStartIdx];\n      } else {\n        if (isUndef(oldKeyToIdx)) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); }\n        idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null;\n        if (isUndef(idxInOld)) { // New element\n          createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);\n          newStartVnode = newCh[++newStartIdx];\n        } else {\n          elmToMove = oldCh[idxInOld];\n          /* istanbul ignore if */\n          if (\"development\" !== 'production' && !elmToMove) {\n            warn(\n              'It seems there are duplicate keys that is causing an update error. ' +\n              'Make sure each v-for item has a unique key.'\n            );\n          }\n          if (sameVnode(elmToMove, newStartVnode)) {\n            patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);\n            oldCh[idxInOld] = undefined;\n            canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);\n            newStartVnode = newCh[++newStartIdx];\n          } else {\n            // same key but different element. treat as new element\n            createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);\n            newStartVnode = newCh[++newStartIdx];\n          }\n        }\n      }\n    }\n    if (oldStartIdx > oldEndIdx) {\n      refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;\n      addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);\n    } else if (newStartIdx > newEndIdx) {\n      removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);\n    }\n  }\n\n  function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {\n    if (oldVnode === vnode) {\n      return\n    }\n    // reuse element for static trees.\n    // note we only do this if the vnode is cloned -\n    // if the new node is not cloned it means the render functions have been\n    // reset by the hot-reload-api and we need to do a proper re-render.\n    if (isTrue(vnode.isStatic) &&\n        isTrue(oldVnode.isStatic) &&\n        vnode.key === oldVnode.key &&\n        (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))) {\n      vnode.elm = oldVnode.elm;\n      vnode.componentInstance = oldVnode.componentInstance;\n      return\n    }\n    var i;\n    var data = vnode.data;\n    if (isDef(data) && isDef(i = data.hook) && isDef(i = i.prepatch)) {\n      i(oldVnode, vnode);\n    }\n    var elm = vnode.elm = oldVnode.elm;\n    var oldCh = oldVnode.children;\n    var ch = vnode.children;\n    if (isDef(data) && isPatchable(vnode)) {\n      for (i = 0; i < cbs.update.length; ++i) { cbs.update[i](oldVnode, vnode); }\n      if (isDef(i = data.hook) && isDef(i = i.update)) { i(oldVnode, vnode); }\n    }\n    if (isUndef(vnode.text)) {\n      if (isDef(oldCh) && isDef(ch)) {\n        if (oldCh !== ch) { updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly); }\n      } else if (isDef(ch)) {\n        if (isDef(oldVnode.text)) { nodeOps.setTextContent(elm, ''); }\n        addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);\n      } else if (isDef(oldCh)) {\n        removeVnodes(elm, oldCh, 0, oldCh.length - 1);\n      } else if (isDef(oldVnode.text)) {\n        nodeOps.setTextContent(elm, '');\n      }\n    } else if (oldVnode.text !== vnode.text) {\n      nodeOps.setTextContent(elm, vnode.text);\n    }\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.postpatch)) { i(oldVnode, vnode); }\n    }\n  }\n\n  function invokeInsertHook (vnode, queue, initial) {\n    // delay insert hooks for component root nodes, invoke them after the\n    // element is really inserted\n    if (isTrue(initial) && isDef(vnode.parent)) {\n      vnode.parent.data.pendingInsert = queue;\n    } else {\n      for (var i = 0; i < queue.length; ++i) {\n        queue[i].data.hook.insert(queue[i]);\n      }\n    }\n  }\n\n  var bailed = false;\n  // list of modules that can skip create hook during hydration because they\n  // are already rendered on the client or has no need for initialization\n  var isRenderedModule = makeMap('attrs,style,class,staticClass,staticStyle,key');\n\n  // Note: this is a browser-only function so we can assume elms are DOM nodes.\n  function hydrate (elm, vnode, insertedVnodeQueue) {\n    {\n      if (!assertNodeMatch(elm, vnode)) {\n        return false\n      }\n    }\n    vnode.elm = elm;\n    var tag = vnode.tag;\n    var data = vnode.data;\n    var children = vnode.children;\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.init)) { i(vnode, true /* hydrating */); }\n      if (isDef(i = vnode.componentInstance)) {\n        // child component. it should have hydrated its own tree.\n        initComponent(vnode, insertedVnodeQueue);\n        return true\n      }\n    }\n    if (isDef(tag)) {\n      if (isDef(children)) {\n        // empty element, allow client to pick up and populate children\n        if (!elm.hasChildNodes()) {\n          createChildren(vnode, children, insertedVnodeQueue);\n        } else {\n          var childrenMatch = true;\n          var childNode = elm.firstChild;\n          for (var i$1 = 0; i$1 < children.length; i$1++) {\n            if (!childNode || !hydrate(childNode, children[i$1], insertedVnodeQueue)) {\n              childrenMatch = false;\n              break\n            }\n            childNode = childNode.nextSibling;\n          }\n          // if childNode is not null, it means the actual childNodes list is\n          // longer than the virtual children list.\n          if (!childrenMatch || childNode) {\n            if (\"development\" !== 'production' &&\n                typeof console !== 'undefined' &&\n                !bailed) {\n              bailed = true;\n              console.warn('Parent: ', elm);\n              console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children);\n            }\n            return false\n          }\n        }\n      }\n      if (isDef(data)) {\n        for (var key in data) {\n          if (!isRenderedModule(key)) {\n            invokeCreateHooks(vnode, insertedVnodeQueue);\n            break\n          }\n        }\n      }\n    } else if (elm.data !== vnode.text) {\n      elm.data = vnode.text;\n    }\n    return true\n  }\n\n  function assertNodeMatch (node, vnode) {\n    if (isDef(vnode.tag)) {\n      return (\n        vnode.tag.indexOf('vue-component') === 0 ||\n        vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase())\n      )\n    } else {\n      return node.nodeType === (vnode.isComment ? 8 : 3)\n    }\n  }\n\n  return function patch (oldVnode, vnode, hydrating, removeOnly, parentElm, refElm) {\n    if (isUndef(vnode)) {\n      if (isDef(oldVnode)) { invokeDestroyHook(oldVnode); }\n      return\n    }\n\n    var isInitialPatch = false;\n    var insertedVnodeQueue = [];\n\n    if (isUndef(oldVnode)) {\n      // empty mount (likely as component), create new root element\n      isInitialPatch = true;\n      createElm(vnode, insertedVnodeQueue, parentElm, refElm);\n    } else {\n      var isRealElement = isDef(oldVnode.nodeType);\n      if (!isRealElement && sameVnode(oldVnode, vnode)) {\n        // patch existing root node\n        patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly);\n      } else {\n        if (isRealElement) {\n          // mounting to a real element\n          // check if this is server-rendered content and if we can perform\n          // a successful hydration.\n          if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {\n            oldVnode.removeAttribute(SSR_ATTR);\n            hydrating = true;\n          }\n          if (isTrue(hydrating)) {\n            if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {\n              invokeInsertHook(vnode, insertedVnodeQueue, true);\n              return oldVnode\n            } else {\n              warn(\n                'The client-side rendered virtual DOM tree is not matching ' +\n                'server-rendered content. This is likely caused by incorrect ' +\n                'HTML markup, for example nesting block-level elements inside ' +\n                '<p>, or missing <tbody>. Bailing hydration and performing ' +\n                'full client-side render.'\n              );\n            }\n          }\n          // either not server-rendered, or hydration failed.\n          // create an empty node and replace it\n          oldVnode = emptyNodeAt(oldVnode);\n        }\n        // replacing existing element\n        var oldElm = oldVnode.elm;\n        var parentElm$1 = nodeOps.parentNode(oldElm);\n        createElm(\n          vnode,\n          insertedVnodeQueue,\n          // extremely rare edge case: do not insert if old element is in a\n          // leaving transition. Only happens when combining transition +\n          // keep-alive + HOCs. (#4590)\n          oldElm._leaveCb ? null : parentElm$1,\n          nodeOps.nextSibling(oldElm)\n        );\n\n        if (isDef(vnode.parent)) {\n          // component root element replaced.\n          // update parent placeholder node element, recursively\n          var ancestor = vnode.parent;\n          while (ancestor) {\n            ancestor.elm = vnode.elm;\n            ancestor = ancestor.parent;\n          }\n          if (isPatchable(vnode)) {\n            for (var i = 0; i < cbs.create.length; ++i) {\n              cbs.create[i](emptyNode, vnode.parent);\n            }\n          }\n        }\n\n        if (isDef(parentElm$1)) {\n          removeVnodes(parentElm$1, [oldVnode], 0, 0);\n        } else if (isDef(oldVnode.tag)) {\n          invokeDestroyHook(oldVnode);\n        }\n      }\n    }\n\n    invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch);\n    return vnode.elm\n  }\n}\n\n/*  */\n\nvar directives = {\n  create: updateDirectives,\n  update: updateDirectives,\n  destroy: function unbindDirectives (vnode) {\n    updateDirectives(vnode, emptyNode);\n  }\n};\n\nfunction updateDirectives (oldVnode, vnode) {\n  if (oldVnode.data.directives || vnode.data.directives) {\n    _update(oldVnode, vnode);\n  }\n}\n\nfunction _update (oldVnode, vnode) {\n  var isCreate = oldVnode === emptyNode;\n  var isDestroy = vnode === emptyNode;\n  var oldDirs = normalizeDirectives$1(oldVnode.data.directives, oldVnode.context);\n  var newDirs = normalizeDirectives$1(vnode.data.directives, vnode.context);\n\n  var dirsWithInsert = [];\n  var dirsWithPostpatch = [];\n\n  var key, oldDir, dir;\n  for (key in newDirs) {\n    oldDir = oldDirs[key];\n    dir = newDirs[key];\n    if (!oldDir) {\n      // new directive, bind\n      callHook$1(dir, 'bind', vnode, oldVnode);\n      if (dir.def && dir.def.inserted) {\n        dirsWithInsert.push(dir);\n      }\n    } else {\n      // existing directive, update\n      dir.oldValue = oldDir.value;\n      callHook$1(dir, 'update', vnode, oldVnode);\n      if (dir.def && dir.def.componentUpdated) {\n        dirsWithPostpatch.push(dir);\n      }\n    }\n  }\n\n  if (dirsWithInsert.length) {\n    var callInsert = function () {\n      for (var i = 0; i < dirsWithInsert.length; i++) {\n        callHook$1(dirsWithInsert[i], 'inserted', vnode, oldVnode);\n      }\n    };\n    if (isCreate) {\n      mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert);\n    } else {\n      callInsert();\n    }\n  }\n\n  if (dirsWithPostpatch.length) {\n    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', function () {\n      for (var i = 0; i < dirsWithPostpatch.length; i++) {\n        callHook$1(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode);\n      }\n    });\n  }\n\n  if (!isCreate) {\n    for (key in oldDirs) {\n      if (!newDirs[key]) {\n        // no longer present, unbind\n        callHook$1(oldDirs[key], 'unbind', oldVnode, oldVnode, isDestroy);\n      }\n    }\n  }\n}\n\nvar emptyModifiers = Object.create(null);\n\nfunction normalizeDirectives$1 (\n  dirs,\n  vm\n) {\n  var res = Object.create(null);\n  if (!dirs) {\n    return res\n  }\n  var i, dir;\n  for (i = 0; i < dirs.length; i++) {\n    dir = dirs[i];\n    if (!dir.modifiers) {\n      dir.modifiers = emptyModifiers;\n    }\n    res[getRawDirName(dir)] = dir;\n    dir.def = resolveAsset(vm.$options, 'directives', dir.name, true);\n  }\n  return res\n}\n\nfunction getRawDirName (dir) {\n  return dir.rawName || ((dir.name) + \".\" + (Object.keys(dir.modifiers || {}).join('.')))\n}\n\nfunction callHook$1 (dir, hook, vnode, oldVnode, isDestroy) {\n  var fn = dir.def && dir.def[hook];\n  if (fn) {\n    try {\n      fn(vnode.elm, dir, vnode, oldVnode, isDestroy);\n    } catch (e) {\n      handleError(e, vnode.context, (\"directive \" + (dir.name) + \" \" + hook + \" hook\"));\n    }\n  }\n}\n\nvar baseModules = [\n  ref,\n  directives\n];\n\n/*  */\n\nfunction updateAttrs (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) {\n    return\n  }\n  var key, cur, old;\n  var elm = vnode.elm;\n  var oldAttrs = oldVnode.data.attrs || {};\n  var attrs = vnode.data.attrs || {};\n  // clone observed objects, as the user probably wants to mutate it\n  if (isDef(attrs.__ob__)) {\n    attrs = vnode.data.attrs = extend({}, attrs);\n  }\n\n  for (key in attrs) {\n    cur = attrs[key];\n    old = oldAttrs[key];\n    if (old !== cur) {\n      setAttr(elm, key, cur);\n    }\n  }\n  // #4391: in IE9, setting type can reset value for input[type=radio]\n  /* istanbul ignore if */\n  if (isIE9 && attrs.value !== oldAttrs.value) {\n    setAttr(elm, 'value', attrs.value);\n  }\n  for (key in oldAttrs) {\n    if (isUndef(attrs[key])) {\n      if (isXlink(key)) {\n        elm.removeAttributeNS(xlinkNS, getXlinkProp(key));\n      } else if (!isEnumeratedAttr(key)) {\n        elm.removeAttribute(key);\n      }\n    }\n  }\n}\n\nfunction setAttr (el, key, value) {\n  if (isBooleanAttr(key)) {\n    // set attribute for blank value\n    // e.g. <option disabled>Select one</option>\n    if (isFalsyAttrValue(value)) {\n      el.removeAttribute(key);\n    } else {\n      el.setAttribute(key, key);\n    }\n  } else if (isEnumeratedAttr(key)) {\n    el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true');\n  } else if (isXlink(key)) {\n    if (isFalsyAttrValue(value)) {\n      el.removeAttributeNS(xlinkNS, getXlinkProp(key));\n    } else {\n      el.setAttributeNS(xlinkNS, key, value);\n    }\n  } else {\n    if (isFalsyAttrValue(value)) {\n      el.removeAttribute(key);\n    } else {\n      el.setAttribute(key, value);\n    }\n  }\n}\n\nvar attrs = {\n  create: updateAttrs,\n  update: updateAttrs\n};\n\n/*  */\n\nfunction updateClass (oldVnode, vnode) {\n  var el = vnode.elm;\n  var data = vnode.data;\n  var oldData = oldVnode.data;\n  if (\n    isUndef(data.staticClass) &&\n    isUndef(data.class) && (\n      isUndef(oldData) || (\n        isUndef(oldData.staticClass) &&\n        isUndef(oldData.class)\n      )\n    )\n  ) {\n    return\n  }\n\n  var cls = genClassForVnode(vnode);\n\n  // handle transition classes\n  var transitionClass = el._transitionClasses;\n  if (isDef(transitionClass)) {\n    cls = concat(cls, stringifyClass(transitionClass));\n  }\n\n  // set the class\n  if (cls !== el._prevClass) {\n    el.setAttribute('class', cls);\n    el._prevClass = cls;\n  }\n}\n\nvar klass = {\n  create: updateClass,\n  update: updateClass\n};\n\n/*  */\n\nvar validDivisionCharRE = /[\\w).+\\-_$\\]]/;\n\nfunction parseFilters (exp) {\n  var inSingle = false;\n  var inDouble = false;\n  var inTemplateString = false;\n  var inRegex = false;\n  var curly = 0;\n  var square = 0;\n  var paren = 0;\n  var lastFilterIndex = 0;\n  var c, prev, i, expression, filters;\n\n  for (i = 0; i < exp.length; i++) {\n    prev = c;\n    c = exp.charCodeAt(i);\n    if (inSingle) {\n      if (c === 0x27 && prev !== 0x5C) { inSingle = false; }\n    } else if (inDouble) {\n      if (c === 0x22 && prev !== 0x5C) { inDouble = false; }\n    } else if (inTemplateString) {\n      if (c === 0x60 && prev !== 0x5C) { inTemplateString = false; }\n    } else if (inRegex) {\n      if (c === 0x2f && prev !== 0x5C) { inRegex = false; }\n    } else if (\n      c === 0x7C && // pipe\n      exp.charCodeAt(i + 1) !== 0x7C &&\n      exp.charCodeAt(i - 1) !== 0x7C &&\n      !curly && !square && !paren\n    ) {\n      if (expression === undefined) {\n        // first filter, end of expression\n        lastFilterIndex = i + 1;\n        expression = exp.slice(0, i).trim();\n      } else {\n        pushFilter();\n      }\n    } else {\n      switch (c) {\n        case 0x22: inDouble = true; break         // \"\n        case 0x27: inSingle = true; break         // '\n        case 0x60: inTemplateString = true; break // `\n        case 0x28: paren++; break                 // (\n        case 0x29: paren--; break                 // )\n        case 0x5B: square++; break                // [\n        case 0x5D: square--; break                // ]\n        case 0x7B: curly++; break                 // {\n        case 0x7D: curly--; break                 // }\n      }\n      if (c === 0x2f) { // /\n        var j = i - 1;\n        var p = (void 0);\n        // find first non-whitespace prev char\n        for (; j >= 0; j--) {\n          p = exp.charAt(j);\n          if (p !== ' ') { break }\n        }\n        if (!p || !validDivisionCharRE.test(p)) {\n          inRegex = true;\n        }\n      }\n    }\n  }\n\n  if (expression === undefined) {\n    expression = exp.slice(0, i).trim();\n  } else if (lastFilterIndex !== 0) {\n    pushFilter();\n  }\n\n  function pushFilter () {\n    (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());\n    lastFilterIndex = i + 1;\n  }\n\n  if (filters) {\n    for (i = 0; i < filters.length; i++) {\n      expression = wrapFilter(expression, filters[i]);\n    }\n  }\n\n  return expression\n}\n\nfunction wrapFilter (exp, filter) {\n  var i = filter.indexOf('(');\n  if (i < 0) {\n    // _f: resolveFilter\n    return (\"_f(\\\"\" + filter + \"\\\")(\" + exp + \")\")\n  } else {\n    var name = filter.slice(0, i);\n    var args = filter.slice(i + 1);\n    return (\"_f(\\\"\" + name + \"\\\")(\" + exp + \",\" + args)\n  }\n}\n\n/*  */\n\nfunction baseWarn (msg) {\n  console.error((\"[Vue compiler]: \" + msg));\n}\n\nfunction pluckModuleFunction (\n  modules,\n  key\n) {\n  return modules\n    ? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; })\n    : []\n}\n\nfunction addProp (el, name, value) {\n  (el.props || (el.props = [])).push({ name: name, value: value });\n}\n\nfunction addAttr (el, name, value) {\n  (el.attrs || (el.attrs = [])).push({ name: name, value: value });\n}\n\nfunction addDirective (\n  el,\n  name,\n  rawName,\n  value,\n  arg,\n  modifiers\n) {\n  (el.directives || (el.directives = [])).push({ name: name, rawName: rawName, value: value, arg: arg, modifiers: modifiers });\n}\n\nfunction addHandler (\n  el,\n  name,\n  value,\n  modifiers,\n  important,\n  warn\n) {\n  // warn prevent and passive modifier\n  /* istanbul ignore if */\n  if (\n    \"development\" !== 'production' && warn &&\n    modifiers && modifiers.prevent && modifiers.passive\n  ) {\n    warn(\n      'passive and prevent can\\'t be used together. ' +\n      'Passive handler can\\'t prevent default event.'\n    );\n  }\n  // check capture modifier\n  if (modifiers && modifiers.capture) {\n    delete modifiers.capture;\n    name = '!' + name; // mark the event as captured\n  }\n  if (modifiers && modifiers.once) {\n    delete modifiers.once;\n    name = '~' + name; // mark the event as once\n  }\n  /* istanbul ignore if */\n  if (modifiers && modifiers.passive) {\n    delete modifiers.passive;\n    name = '&' + name; // mark the event as passive\n  }\n  var events;\n  if (modifiers && modifiers.native) {\n    delete modifiers.native;\n    events = el.nativeEvents || (el.nativeEvents = {});\n  } else {\n    events = el.events || (el.events = {});\n  }\n  var newHandler = { value: value, modifiers: modifiers };\n  var handlers = events[name];\n  /* istanbul ignore if */\n  if (Array.isArray(handlers)) {\n    important ? handlers.unshift(newHandler) : handlers.push(newHandler);\n  } else if (handlers) {\n    events[name] = important ? [newHandler, handlers] : [handlers, newHandler];\n  } else {\n    events[name] = newHandler;\n  }\n}\n\nfunction getBindingAttr (\n  el,\n  name,\n  getStatic\n) {\n  var dynamicValue =\n    getAndRemoveAttr(el, ':' + name) ||\n    getAndRemoveAttr(el, 'v-bind:' + name);\n  if (dynamicValue != null) {\n    return parseFilters(dynamicValue)\n  } else if (getStatic !== false) {\n    var staticValue = getAndRemoveAttr(el, name);\n    if (staticValue != null) {\n      return JSON.stringify(staticValue)\n    }\n  }\n}\n\nfunction getAndRemoveAttr (el, name) {\n  var val;\n  if ((val = el.attrsMap[name]) != null) {\n    var list = el.attrsList;\n    for (var i = 0, l = list.length; i < l; i++) {\n      if (list[i].name === name) {\n        list.splice(i, 1);\n        break\n      }\n    }\n  }\n  return val\n}\n\n/*  */\n\n/**\n * Cross-platform code generation for component v-model\n */\nfunction genComponentModel (\n  el,\n  value,\n  modifiers\n) {\n  var ref = modifiers || {};\n  var number = ref.number;\n  var trim = ref.trim;\n\n  var baseValueExpression = '$$v';\n  var valueExpression = baseValueExpression;\n  if (trim) {\n    valueExpression =\n      \"(typeof \" + baseValueExpression + \" === 'string'\" +\n        \"? \" + baseValueExpression + \".trim()\" +\n        \": \" + baseValueExpression + \")\";\n  }\n  if (number) {\n    valueExpression = \"_n(\" + valueExpression + \")\";\n  }\n  var assignment = genAssignmentCode(value, valueExpression);\n\n  el.model = {\n    value: (\"(\" + value + \")\"),\n    expression: (\"\\\"\" + value + \"\\\"\"),\n    callback: (\"function (\" + baseValueExpression + \") {\" + assignment + \"}\")\n  };\n}\n\n/**\n * Cross-platform codegen helper for generating v-model value assignment code.\n */\nfunction genAssignmentCode (\n  value,\n  assignment\n) {\n  var modelRs = parseModel(value);\n  if (modelRs.idx === null) {\n    return (value + \"=\" + assignment)\n  } else {\n    return \"var $$exp = \" + (modelRs.exp) + \", $$idx = \" + (modelRs.idx) + \";\" +\n      \"if (!Array.isArray($$exp)){\" +\n        value + \"=\" + assignment + \"}\" +\n      \"else{$$exp.splice($$idx, 1, \" + assignment + \")}\"\n  }\n}\n\n/**\n * parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val)\n *\n * for loop possible cases:\n *\n * - test\n * - test[idx]\n * - test[test1[idx]]\n * - test[\"a\"][idx]\n * - xxx.test[a[a].test1[idx]]\n * - test.xxx.a[\"asa\"][test1[idx]]\n *\n */\n\nvar len;\nvar str;\nvar chr;\nvar index$1;\nvar expressionPos;\nvar expressionEndPos;\n\nfunction parseModel (val) {\n  str = val;\n  len = str.length;\n  index$1 = expressionPos = expressionEndPos = 0;\n\n  if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {\n    return {\n      exp: val,\n      idx: null\n    }\n  }\n\n  while (!eof()) {\n    chr = next();\n    /* istanbul ignore if */\n    if (isStringStart(chr)) {\n      parseString(chr);\n    } else if (chr === 0x5B) {\n      parseBracket(chr);\n    }\n  }\n\n  return {\n    exp: val.substring(0, expressionPos),\n    idx: val.substring(expressionPos + 1, expressionEndPos)\n  }\n}\n\nfunction next () {\n  return str.charCodeAt(++index$1)\n}\n\nfunction eof () {\n  return index$1 >= len\n}\n\nfunction isStringStart (chr) {\n  return chr === 0x22 || chr === 0x27\n}\n\nfunction parseBracket (chr) {\n  var inBracket = 1;\n  expressionPos = index$1;\n  while (!eof()) {\n    chr = next();\n    if (isStringStart(chr)) {\n      parseString(chr);\n      continue\n    }\n    if (chr === 0x5B) { inBracket++; }\n    if (chr === 0x5D) { inBracket--; }\n    if (inBracket === 0) {\n      expressionEndPos = index$1;\n      break\n    }\n  }\n}\n\nfunction parseString (chr) {\n  var stringQuote = chr;\n  while (!eof()) {\n    chr = next();\n    if (chr === stringQuote) {\n      break\n    }\n  }\n}\n\n/*  */\n\nvar warn$1;\n\n// in some cases, the event used has to be determined at runtime\n// so we used some reserved tokens during compile.\nvar RANGE_TOKEN = '__r';\nvar CHECKBOX_RADIO_TOKEN = '__c';\n\nfunction model (\n  el,\n  dir,\n  _warn\n) {\n  warn$1 = _warn;\n  var value = dir.value;\n  var modifiers = dir.modifiers;\n  var tag = el.tag;\n  var type = el.attrsMap.type;\n\n  {\n    var dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type'];\n    if (tag === 'input' && dynamicType) {\n      warn$1(\n        \"<input :type=\\\"\" + dynamicType + \"\\\" v-model=\\\"\" + value + \"\\\">:\\n\" +\n        \"v-model does not support dynamic input types. Use v-if branches instead.\"\n      );\n    }\n    // inputs with type=\"file\" are read only and setting the input's\n    // value will throw an error.\n    if (tag === 'input' && type === 'file') {\n      warn$1(\n        \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\" type=\\\"file\\\">:\\n\" +\n        \"File inputs are read only. Use a v-on:change listener instead.\"\n      );\n    }\n  }\n\n  if (tag === 'select') {\n    genSelect(el, value, modifiers);\n  } else if (tag === 'input' && type === 'checkbox') {\n    genCheckboxModel(el, value, modifiers);\n  } else if (tag === 'input' && type === 'radio') {\n    genRadioModel(el, value, modifiers);\n  } else if (tag === 'input' || tag === 'textarea') {\n    genDefaultModel(el, value, modifiers);\n  } else if (!config.isReservedTag(tag)) {\n    genComponentModel(el, value, modifiers);\n    // component v-model doesn't need extra runtime\n    return false\n  } else {\n    warn$1(\n      \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\">: \" +\n      \"v-model is not supported on this element type. \" +\n      'If you are working with contenteditable, it\\'s recommended to ' +\n      'wrap a library dedicated for that purpose inside a custom component.'\n    );\n  }\n\n  // ensure runtime directive metadata\n  return true\n}\n\nfunction genCheckboxModel (\n  el,\n  value,\n  modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var valueBinding = getBindingAttr(el, 'value') || 'null';\n  var trueValueBinding = getBindingAttr(el, 'true-value') || 'true';\n  var falseValueBinding = getBindingAttr(el, 'false-value') || 'false';\n  addProp(el, 'checked',\n    \"Array.isArray(\" + value + \")\" +\n      \"?_i(\" + value + \",\" + valueBinding + \")>-1\" + (\n        trueValueBinding === 'true'\n          ? (\":(\" + value + \")\")\n          : (\":_q(\" + value + \",\" + trueValueBinding + \")\")\n      )\n  );\n  addHandler(el, CHECKBOX_RADIO_TOKEN,\n    \"var $$a=\" + value + \",\" +\n        '$$el=$event.target,' +\n        \"$$c=$$el.checked?(\" + trueValueBinding + \"):(\" + falseValueBinding + \");\" +\n    'if(Array.isArray($$a)){' +\n      \"var $$v=\" + (number ? '_n(' + valueBinding + ')' : valueBinding) + \",\" +\n          '$$i=_i($$a,$$v);' +\n      \"if($$c){$$i<0&&(\" + value + \"=$$a.concat($$v))}\" +\n      \"else{$$i>-1&&(\" + value + \"=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}\" +\n    \"}else{\" + (genAssignmentCode(value, '$$c')) + \"}\",\n    null, true\n  );\n}\n\nfunction genRadioModel (\n    el,\n    value,\n    modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var valueBinding = getBindingAttr(el, 'value') || 'null';\n  valueBinding = number ? (\"_n(\" + valueBinding + \")\") : valueBinding;\n  addProp(el, 'checked', (\"_q(\" + value + \",\" + valueBinding + \")\"));\n  addHandler(el, CHECKBOX_RADIO_TOKEN, genAssignmentCode(value, valueBinding), null, true);\n}\n\nfunction genSelect (\n    el,\n    value,\n    modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var selectedVal = \"Array.prototype.filter\" +\n    \".call($event.target.options,function(o){return o.selected})\" +\n    \".map(function(o){var val = \\\"_value\\\" in o ? o._value : o.value;\" +\n    \"return \" + (number ? '_n(val)' : 'val') + \"})\";\n\n  var assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';\n  var code = \"var $$selectedVal = \" + selectedVal + \";\";\n  code = code + \" \" + (genAssignmentCode(value, assignment));\n  addHandler(el, 'change', code, null, true);\n}\n\nfunction genDefaultModel (\n  el,\n  value,\n  modifiers\n) {\n  var type = el.attrsMap.type;\n  var ref = modifiers || {};\n  var lazy = ref.lazy;\n  var number = ref.number;\n  var trim = ref.trim;\n  var needCompositionGuard = !lazy && type !== 'range';\n  var event = lazy\n    ? 'change'\n    : type === 'range'\n      ? RANGE_TOKEN\n      : 'input';\n\n  var valueExpression = '$event.target.value';\n  if (trim) {\n    valueExpression = \"$event.target.value.trim()\";\n  }\n  if (number) {\n    valueExpression = \"_n(\" + valueExpression + \")\";\n  }\n\n  var code = genAssignmentCode(value, valueExpression);\n  if (needCompositionGuard) {\n    code = \"if($event.target.composing)return;\" + code;\n  }\n\n  addProp(el, 'value', (\"(\" + value + \")\"));\n  addHandler(el, event, code, null, true);\n  if (trim || number || type === 'number') {\n    addHandler(el, 'blur', '$forceUpdate()');\n  }\n}\n\n/*  */\n\n// normalize v-model event tokens that can only be determined at runtime.\n// it's important to place the event as the first in the array because\n// the whole point is ensuring the v-model callback gets called before\n// user-attached handlers.\nfunction normalizeEvents (on) {\n  var event;\n  /* istanbul ignore if */\n  if (isDef(on[RANGE_TOKEN])) {\n    // IE input[type=range] only supports `change` event\n    event = isIE ? 'change' : 'input';\n    on[event] = [].concat(on[RANGE_TOKEN], on[event] || []);\n    delete on[RANGE_TOKEN];\n  }\n  if (isDef(on[CHECKBOX_RADIO_TOKEN])) {\n    // Chrome fires microtasks in between click/change, leads to #4521\n    event = isChrome ? 'click' : 'change';\n    on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || []);\n    delete on[CHECKBOX_RADIO_TOKEN];\n  }\n}\n\nvar target$1;\n\nfunction add$1 (\n  event,\n  handler,\n  once$$1,\n  capture,\n  passive\n) {\n  if (once$$1) {\n    var oldHandler = handler;\n    var _target = target$1; // save current target element in closure\n    handler = function (ev) {\n      var res = arguments.length === 1\n        ? oldHandler(ev)\n        : oldHandler.apply(null, arguments);\n      if (res !== null) {\n        remove$2(event, handler, capture, _target);\n      }\n    };\n  }\n  target$1.addEventListener(\n    event,\n    handler,\n    supportsPassive\n      ? { capture: capture, passive: passive }\n      : capture\n  );\n}\n\nfunction remove$2 (\n  event,\n  handler,\n  capture,\n  _target\n) {\n  (_target || target$1).removeEventListener(event, handler, capture);\n}\n\nfunction updateDOMListeners (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) {\n    return\n  }\n  var on = vnode.data.on || {};\n  var oldOn = oldVnode.data.on || {};\n  target$1 = vnode.elm;\n  normalizeEvents(on);\n  updateListeners(on, oldOn, add$1, remove$2, vnode.context);\n}\n\nvar events = {\n  create: updateDOMListeners,\n  update: updateDOMListeners\n};\n\n/*  */\n\nfunction updateDOMProps (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {\n    return\n  }\n  var key, cur;\n  var elm = vnode.elm;\n  var oldProps = oldVnode.data.domProps || {};\n  var props = vnode.data.domProps || {};\n  // clone observed objects, as the user probably wants to mutate it\n  if (isDef(props.__ob__)) {\n    props = vnode.data.domProps = extend({}, props);\n  }\n\n  for (key in oldProps) {\n    if (isUndef(props[key])) {\n      elm[key] = '';\n    }\n  }\n  for (key in props) {\n    cur = props[key];\n    // ignore children if the node has textContent or innerHTML,\n    // as these will throw away existing DOM nodes and cause removal errors\n    // on subsequent patches (#3360)\n    if (key === 'textContent' || key === 'innerHTML') {\n      if (vnode.children) { vnode.children.length = 0; }\n      if (cur === oldProps[key]) { continue }\n    }\n\n    if (key === 'value') {\n      // store value as _value as well since\n      // non-string values will be stringified\n      elm._value = cur;\n      // avoid resetting cursor position when value is the same\n      var strCur = cur == null ? '' : String(cur);\n      if (shouldUpdateValue(elm, vnode, strCur)) {\n        elm.value = strCur;\n      }\n    } else {\n      elm[key] = cur;\n    }\n  }\n}\n\n// check platforms/web/util/attrs.js acceptValue\n\n\nfunction shouldUpdateValue (\n  elm,\n  vnode,\n  checkVal\n) {\n  return (!elm.composing && (\n    vnode.tag === 'option' ||\n    isDirty(elm, checkVal) ||\n    isInputChanged(elm, checkVal)\n  ))\n}\n\nfunction isDirty (elm, checkVal) {\n  // return true when textbox (.number and .trim) loses focus and its value is not equal to the updated value\n  return document.activeElement !== elm && elm.value !== checkVal\n}\n\nfunction isInputChanged (elm, newVal) {\n  var value = elm.value;\n  var modifiers = elm._vModifiers; // injected by v-model runtime\n  if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') {\n    return toNumber(value) !== toNumber(newVal)\n  }\n  if (isDef(modifiers) && modifiers.trim) {\n    return value.trim() !== newVal.trim()\n  }\n  return value !== newVal\n}\n\nvar domProps = {\n  create: updateDOMProps,\n  update: updateDOMProps\n};\n\n/*  */\n\nvar parseStyleText = cached(function (cssText) {\n  var res = {};\n  var listDelimiter = /;(?![^(]*\\))/g;\n  var propertyDelimiter = /:(.+)/;\n  cssText.split(listDelimiter).forEach(function (item) {\n    if (item) {\n      var tmp = item.split(propertyDelimiter);\n      tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());\n    }\n  });\n  return res\n});\n\n// merge static and dynamic style data on the same vnode\nfunction normalizeStyleData (data) {\n  var style = normalizeStyleBinding(data.style);\n  // static style is pre-processed into an object during compilation\n  // and is always a fresh object, so it's safe to merge into it\n  return data.staticStyle\n    ? extend(data.staticStyle, style)\n    : style\n}\n\n// normalize possible array / string values into Object\nfunction normalizeStyleBinding (bindingStyle) {\n  if (Array.isArray(bindingStyle)) {\n    return toObject(bindingStyle)\n  }\n  if (typeof bindingStyle === 'string') {\n    return parseStyleText(bindingStyle)\n  }\n  return bindingStyle\n}\n\n/**\n * parent component style should be after child's\n * so that parent component's style could override it\n */\nfunction getStyle (vnode, checkChild) {\n  var res = {};\n  var styleData;\n\n  if (checkChild) {\n    var childNode = vnode;\n    while (childNode.componentInstance) {\n      childNode = childNode.componentInstance._vnode;\n      if (childNode.data && (styleData = normalizeStyleData(childNode.data))) {\n        extend(res, styleData);\n      }\n    }\n  }\n\n  if ((styleData = normalizeStyleData(vnode.data))) {\n    extend(res, styleData);\n  }\n\n  var parentNode = vnode;\n  while ((parentNode = parentNode.parent)) {\n    if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {\n      extend(res, styleData);\n    }\n  }\n  return res\n}\n\n/*  */\n\nvar cssVarRE = /^--/;\nvar importantRE = /\\s*!important$/;\nvar setProp = function (el, name, val) {\n  /* istanbul ignore if */\n  if (cssVarRE.test(name)) {\n    el.style.setProperty(name, val);\n  } else if (importantRE.test(val)) {\n    el.style.setProperty(name, val.replace(importantRE, ''), 'important');\n  } else {\n    var normalizedName = normalize(name);\n    if (Array.isArray(val)) {\n      // Support values array created by autoprefixer, e.g.\n      // {display: [\"-webkit-box\", \"-ms-flexbox\", \"flex\"]}\n      // Set them one by one, and the browser will only set those it can recognize\n      for (var i = 0, len = val.length; i < len; i++) {\n        el.style[normalizedName] = val[i];\n      }\n    } else {\n      el.style[normalizedName] = val;\n    }\n  }\n};\n\nvar prefixes = ['Webkit', 'Moz', 'ms'];\n\nvar testEl;\nvar normalize = cached(function (prop) {\n  testEl = testEl || document.createElement('div');\n  prop = camelize(prop);\n  if (prop !== 'filter' && (prop in testEl.style)) {\n    return prop\n  }\n  var upper = prop.charAt(0).toUpperCase() + prop.slice(1);\n  for (var i = 0; i < prefixes.length; i++) {\n    var prefixed = prefixes[i] + upper;\n    if (prefixed in testEl.style) {\n      return prefixed\n    }\n  }\n});\n\nfunction updateStyle (oldVnode, vnode) {\n  var data = vnode.data;\n  var oldData = oldVnode.data;\n\n  if (isUndef(data.staticStyle) && isUndef(data.style) &&\n      isUndef(oldData.staticStyle) && isUndef(oldData.style)) {\n    return\n  }\n\n  var cur, name;\n  var el = vnode.elm;\n  var oldStaticStyle = oldData.staticStyle;\n  var oldStyleBinding = oldData.normalizedStyle || oldData.style || {};\n\n  // if static style exists, stylebinding already merged into it when doing normalizeStyleData\n  var oldStyle = oldStaticStyle || oldStyleBinding;\n\n  var style = normalizeStyleBinding(vnode.data.style) || {};\n\n  // store normalized style under a different key for next diff\n  // make sure to clone it if it's reactive, since the user likley wants\n  // to mutate it.\n  vnode.data.normalizedStyle = isDef(style.__ob__)\n    ? extend({}, style)\n    : style;\n\n  var newStyle = getStyle(vnode, true);\n\n  for (name in oldStyle) {\n    if (isUndef(newStyle[name])) {\n      setProp(el, name, '');\n    }\n  }\n  for (name in newStyle) {\n    cur = newStyle[name];\n    if (cur !== oldStyle[name]) {\n      // ie9 setting to null has no effect, must use empty string\n      setProp(el, name, cur == null ? '' : cur);\n    }\n  }\n}\n\nvar style = {\n  create: updateStyle,\n  update: updateStyle\n};\n\n/*  */\n\n/**\n * Add class with compatibility for SVG since classList is not supported on\n * SVG elements in IE\n */\nfunction addClass (el, cls) {\n  /* istanbul ignore if */\n  if (!cls || !(cls = cls.trim())) {\n    return\n  }\n\n  /* istanbul ignore else */\n  if (el.classList) {\n    if (cls.indexOf(' ') > -1) {\n      cls.split(/\\s+/).forEach(function (c) { return el.classList.add(c); });\n    } else {\n      el.classList.add(cls);\n    }\n  } else {\n    var cur = \" \" + (el.getAttribute('class') || '') + \" \";\n    if (cur.indexOf(' ' + cls + ' ') < 0) {\n      el.setAttribute('class', (cur + cls).trim());\n    }\n  }\n}\n\n/**\n * Remove class with compatibility for SVG since classList is not supported on\n * SVG elements in IE\n */\nfunction removeClass (el, cls) {\n  /* istanbul ignore if */\n  if (!cls || !(cls = cls.trim())) {\n    return\n  }\n\n  /* istanbul ignore else */\n  if (el.classList) {\n    if (cls.indexOf(' ') > -1) {\n      cls.split(/\\s+/).forEach(function (c) { return el.classList.remove(c); });\n    } else {\n      el.classList.remove(cls);\n    }\n  } else {\n    var cur = \" \" + (el.getAttribute('class') || '') + \" \";\n    var tar = ' ' + cls + ' ';\n    while (cur.indexOf(tar) >= 0) {\n      cur = cur.replace(tar, ' ');\n    }\n    el.setAttribute('class', cur.trim());\n  }\n}\n\n/*  */\n\nfunction resolveTransition (def$$1) {\n  if (!def$$1) {\n    return\n  }\n  /* istanbul ignore else */\n  if (typeof def$$1 === 'object') {\n    var res = {};\n    if (def$$1.css !== false) {\n      extend(res, autoCssTransition(def$$1.name || 'v'));\n    }\n    extend(res, def$$1);\n    return res\n  } else if (typeof def$$1 === 'string') {\n    return autoCssTransition(def$$1)\n  }\n}\n\nvar autoCssTransition = cached(function (name) {\n  return {\n    enterClass: (name + \"-enter\"),\n    enterToClass: (name + \"-enter-to\"),\n    enterActiveClass: (name + \"-enter-active\"),\n    leaveClass: (name + \"-leave\"),\n    leaveToClass: (name + \"-leave-to\"),\n    leaveActiveClass: (name + \"-leave-active\")\n  }\n});\n\nvar hasTransition = inBrowser && !isIE9;\nvar TRANSITION = 'transition';\nvar ANIMATION = 'animation';\n\n// Transition property/event sniffing\nvar transitionProp = 'transition';\nvar transitionEndEvent = 'transitionend';\nvar animationProp = 'animation';\nvar animationEndEvent = 'animationend';\nif (hasTransition) {\n  /* istanbul ignore if */\n  if (window.ontransitionend === undefined &&\n    window.onwebkittransitionend !== undefined) {\n    transitionProp = 'WebkitTransition';\n    transitionEndEvent = 'webkitTransitionEnd';\n  }\n  if (window.onanimationend === undefined &&\n    window.onwebkitanimationend !== undefined) {\n    animationProp = 'WebkitAnimation';\n    animationEndEvent = 'webkitAnimationEnd';\n  }\n}\n\n// binding to window is necessary to make hot reload work in IE in strict mode\nvar raf = inBrowser && window.requestAnimationFrame\n  ? window.requestAnimationFrame.bind(window)\n  : setTimeout;\n\nfunction nextFrame (fn) {\n  raf(function () {\n    raf(fn);\n  });\n}\n\nfunction addTransitionClass (el, cls) {\n  (el._transitionClasses || (el._transitionClasses = [])).push(cls);\n  addClass(el, cls);\n}\n\nfunction removeTransitionClass (el, cls) {\n  if (el._transitionClasses) {\n    remove(el._transitionClasses, cls);\n  }\n  removeClass(el, cls);\n}\n\nfunction whenTransitionEnds (\n  el,\n  expectedType,\n  cb\n) {\n  var ref = getTransitionInfo(el, expectedType);\n  var type = ref.type;\n  var timeout = ref.timeout;\n  var propCount = ref.propCount;\n  if (!type) { return cb() }\n  var event = type === TRANSITION ? transitionEndEvent : animationEndEvent;\n  var ended = 0;\n  var end = function () {\n    el.removeEventListener(event, onEnd);\n    cb();\n  };\n  var onEnd = function (e) {\n    if (e.target === el) {\n      if (++ended >= propCount) {\n        end();\n      }\n    }\n  };\n  setTimeout(function () {\n    if (ended < propCount) {\n      end();\n    }\n  }, timeout + 1);\n  el.addEventListener(event, onEnd);\n}\n\nvar transformRE = /\\b(transform|all)(,|$)/;\n\nfunction getTransitionInfo (el, expectedType) {\n  var styles = window.getComputedStyle(el);\n  var transitionDelays = styles[transitionProp + 'Delay'].split(', ');\n  var transitionDurations = styles[transitionProp + 'Duration'].split(', ');\n  var transitionTimeout = getTimeout(transitionDelays, transitionDurations);\n  var animationDelays = styles[animationProp + 'Delay'].split(', ');\n  var animationDurations = styles[animationProp + 'Duration'].split(', ');\n  var animationTimeout = getTimeout(animationDelays, animationDurations);\n\n  var type;\n  var timeout = 0;\n  var propCount = 0;\n  /* istanbul ignore if */\n  if (expectedType === TRANSITION) {\n    if (transitionTimeout > 0) {\n      type = TRANSITION;\n      timeout = transitionTimeout;\n      propCount = transitionDurations.length;\n    }\n  } else if (expectedType === ANIMATION) {\n    if (animationTimeout > 0) {\n      type = ANIMATION;\n      timeout = animationTimeout;\n      propCount = animationDurations.length;\n    }\n  } else {\n    timeout = Math.max(transitionTimeout, animationTimeout);\n    type = timeout > 0\n      ? transitionTimeout > animationTimeout\n        ? TRANSITION\n        : ANIMATION\n      : null;\n    propCount = type\n      ? type === TRANSITION\n        ? transitionDurations.length\n        : animationDurations.length\n      : 0;\n  }\n  var hasTransform =\n    type === TRANSITION &&\n    transformRE.test(styles[transitionProp + 'Property']);\n  return {\n    type: type,\n    timeout: timeout,\n    propCount: propCount,\n    hasTransform: hasTransform\n  }\n}\n\nfunction getTimeout (delays, durations) {\n  /* istanbul ignore next */\n  while (delays.length < durations.length) {\n    delays = delays.concat(delays);\n  }\n\n  return Math.max.apply(null, durations.map(function (d, i) {\n    return toMs(d) + toMs(delays[i])\n  }))\n}\n\nfunction toMs (s) {\n  return Number(s.slice(0, -1)) * 1000\n}\n\n/*  */\n\nfunction enter (vnode, toggleDisplay) {\n  var el = vnode.elm;\n\n  // call leave callback now\n  if (isDef(el._leaveCb)) {\n    el._leaveCb.cancelled = true;\n    el._leaveCb();\n  }\n\n  var data = resolveTransition(vnode.data.transition);\n  if (isUndef(data)) {\n    return\n  }\n\n  /* istanbul ignore if */\n  if (isDef(el._enterCb) || el.nodeType !== 1) {\n    return\n  }\n\n  var ref = (data);\n  var css = ref.css;\n  var type = ref.type;\n  var enterClass = ref.enterClass;\n  var enterToClass = ref.enterToClass;\n  var enterActiveClass = ref.enterActiveClass;\n  var appearClass = ref.appearClass;\n  var appearToClass = ref.appearToClass;\n  var appearActiveClass = ref.appearActiveClass;\n  var beforeEnter = ref.beforeEnter;\n  var enter = ref.enter;\n  var afterEnter = ref.afterEnter;\n  var enterCancelled = ref.enterCancelled;\n  var beforeAppear = ref.beforeAppear;\n  var appear = ref.appear;\n  var afterAppear = ref.afterAppear;\n  var appearCancelled = ref.appearCancelled;\n  var duration = ref.duration;\n\n  // activeInstance will always be the <transition> component managing this\n  // transition. One edge case to check is when the <transition> is placed\n  // as the root node of a child component. In that case we need to check\n  // <transition>'s parent for appear check.\n  var context = activeInstance;\n  var transitionNode = activeInstance.$vnode;\n  while (transitionNode && transitionNode.parent) {\n    transitionNode = transitionNode.parent;\n    context = transitionNode.context;\n  }\n\n  var isAppear = !context._isMounted || !vnode.isRootInsert;\n\n  if (isAppear && !appear && appear !== '') {\n    return\n  }\n\n  var startClass = isAppear && appearClass\n    ? appearClass\n    : enterClass;\n  var activeClass = isAppear && appearActiveClass\n    ? appearActiveClass\n    : enterActiveClass;\n  var toClass = isAppear && appearToClass\n    ? appearToClass\n    : enterToClass;\n\n  var beforeEnterHook = isAppear\n    ? (beforeAppear || beforeEnter)\n    : beforeEnter;\n  var enterHook = isAppear\n    ? (typeof appear === 'function' ? appear : enter)\n    : enter;\n  var afterEnterHook = isAppear\n    ? (afterAppear || afterEnter)\n    : afterEnter;\n  var enterCancelledHook = isAppear\n    ? (appearCancelled || enterCancelled)\n    : enterCancelled;\n\n  var explicitEnterDuration = toNumber(\n    isObject(duration)\n      ? duration.enter\n      : duration\n  );\n\n  if (\"development\" !== 'production' && explicitEnterDuration != null) {\n    checkDuration(explicitEnterDuration, 'enter', vnode);\n  }\n\n  var expectsCSS = css !== false && !isIE9;\n  var userWantsControl = getHookArgumentsLength(enterHook);\n\n  var cb = el._enterCb = once(function () {\n    if (expectsCSS) {\n      removeTransitionClass(el, toClass);\n      removeTransitionClass(el, activeClass);\n    }\n    if (cb.cancelled) {\n      if (expectsCSS) {\n        removeTransitionClass(el, startClass);\n      }\n      enterCancelledHook && enterCancelledHook(el);\n    } else {\n      afterEnterHook && afterEnterHook(el);\n    }\n    el._enterCb = null;\n  });\n\n  if (!vnode.data.show) {\n    // remove pending leave element on enter by injecting an insert hook\n    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {\n      var parent = el.parentNode;\n      var pendingNode = parent && parent._pending && parent._pending[vnode.key];\n      if (pendingNode &&\n          pendingNode.tag === vnode.tag &&\n          pendingNode.elm._leaveCb) {\n        pendingNode.elm._leaveCb();\n      }\n      enterHook && enterHook(el, cb);\n    });\n  }\n\n  // start enter transition\n  beforeEnterHook && beforeEnterHook(el);\n  if (expectsCSS) {\n    addTransitionClass(el, startClass);\n    addTransitionClass(el, activeClass);\n    nextFrame(function () {\n      addTransitionClass(el, toClass);\n      removeTransitionClass(el, startClass);\n      if (!cb.cancelled && !userWantsControl) {\n        if (isValidDuration(explicitEnterDuration)) {\n          setTimeout(cb, explicitEnterDuration);\n        } else {\n          whenTransitionEnds(el, type, cb);\n        }\n      }\n    });\n  }\n\n  if (vnode.data.show) {\n    toggleDisplay && toggleDisplay();\n    enterHook && enterHook(el, cb);\n  }\n\n  if (!expectsCSS && !userWantsControl) {\n    cb();\n  }\n}\n\nfunction leave (vnode, rm) {\n  var el = vnode.elm;\n\n  // call enter callback now\n  if (isDef(el._enterCb)) {\n    el._enterCb.cancelled = true;\n    el._enterCb();\n  }\n\n  var data = resolveTransition(vnode.data.transition);\n  if (isUndef(data)) {\n    return rm()\n  }\n\n  /* istanbul ignore if */\n  if (isDef(el._leaveCb) || el.nodeType !== 1) {\n    return\n  }\n\n  var ref = (data);\n  var css = ref.css;\n  var type = ref.type;\n  var leaveClass = ref.leaveClass;\n  var leaveToClass = ref.leaveToClass;\n  var leaveActiveClass = ref.leaveActiveClass;\n  var beforeLeave = ref.beforeLeave;\n  var leave = ref.leave;\n  var afterLeave = ref.afterLeave;\n  var leaveCancelled = ref.leaveCancelled;\n  var delayLeave = ref.delayLeave;\n  var duration = ref.duration;\n\n  var expectsCSS = css !== false && !isIE9;\n  var userWantsControl = getHookArgumentsLength(leave);\n\n  var explicitLeaveDuration = toNumber(\n    isObject(duration)\n      ? duration.leave\n      : duration\n  );\n\n  if (\"development\" !== 'production' && explicitLeaveDuration != null) {\n    checkDuration(explicitLeaveDuration, 'leave', vnode);\n  }\n\n  var cb = el._leaveCb = once(function () {\n    if (el.parentNode && el.parentNode._pending) {\n      el.parentNode._pending[vnode.key] = null;\n    }\n    if (expectsCSS) {\n      removeTransitionClass(el, leaveToClass);\n      removeTransitionClass(el, leaveActiveClass);\n    }\n    if (cb.cancelled) {\n      if (expectsCSS) {\n        removeTransitionClass(el, leaveClass);\n      }\n      leaveCancelled && leaveCancelled(el);\n    } else {\n      rm();\n      afterLeave && afterLeave(el);\n    }\n    el._leaveCb = null;\n  });\n\n  if (delayLeave) {\n    delayLeave(performLeave);\n  } else {\n    performLeave();\n  }\n\n  function performLeave () {\n    // the delayed leave may have already been cancelled\n    if (cb.cancelled) {\n      return\n    }\n    // record leaving element\n    if (!vnode.data.show) {\n      (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode;\n    }\n    beforeLeave && beforeLeave(el);\n    if (expectsCSS) {\n      addTransitionClass(el, leaveClass);\n      addTransitionClass(el, leaveActiveClass);\n      nextFrame(function () {\n        addTransitionClass(el, leaveToClass);\n        removeTransitionClass(el, leaveClass);\n        if (!cb.cancelled && !userWantsControl) {\n          if (isValidDuration(explicitLeaveDuration)) {\n            setTimeout(cb, explicitLeaveDuration);\n          } else {\n            whenTransitionEnds(el, type, cb);\n          }\n        }\n      });\n    }\n    leave && leave(el, cb);\n    if (!expectsCSS && !userWantsControl) {\n      cb();\n    }\n  }\n}\n\n// only used in dev mode\nfunction checkDuration (val, name, vnode) {\n  if (typeof val !== 'number') {\n    warn(\n      \"<transition> explicit \" + name + \" duration is not a valid number - \" +\n      \"got \" + (JSON.stringify(val)) + \".\",\n      vnode.context\n    );\n  } else if (isNaN(val)) {\n    warn(\n      \"<transition> explicit \" + name + \" duration is NaN - \" +\n      'the duration expression might be incorrect.',\n      vnode.context\n    );\n  }\n}\n\nfunction isValidDuration (val) {\n  return typeof val === 'number' && !isNaN(val)\n}\n\n/**\n * Normalize a transition hook's argument length. The hook may be:\n * - a merged hook (invoker) with the original in .fns\n * - a wrapped component method (check ._length)\n * - a plain function (.length)\n */\nfunction getHookArgumentsLength (fn) {\n  if (isUndef(fn)) {\n    return false\n  }\n  var invokerFns = fn.fns;\n  if (isDef(invokerFns)) {\n    // invoker\n    return getHookArgumentsLength(\n      Array.isArray(invokerFns)\n        ? invokerFns[0]\n        : invokerFns\n    )\n  } else {\n    return (fn._length || fn.length) > 1\n  }\n}\n\nfunction _enter (_, vnode) {\n  if (vnode.data.show !== true) {\n    enter(vnode);\n  }\n}\n\nvar transition = inBrowser ? {\n  create: _enter,\n  activate: _enter,\n  remove: function remove$$1 (vnode, rm) {\n    /* istanbul ignore else */\n    if (vnode.data.show !== true) {\n      leave(vnode, rm);\n    } else {\n      rm();\n    }\n  }\n} : {};\n\nvar platformModules = [\n  attrs,\n  klass,\n  events,\n  domProps,\n  style,\n  transition\n];\n\n/*  */\n\n// the directive module should be applied last, after all\n// built-in modules have been applied.\nvar modules = platformModules.concat(baseModules);\n\nvar patch = createPatchFunction({ nodeOps: nodeOps, modules: modules });\n\n/**\n * Not type checking this file because flow doesn't like attaching\n * properties to Elements.\n */\n\n/* istanbul ignore if */\nif (isIE9) {\n  // http://www.matts411.com/post/internet-explorer-9-oninput/\n  document.addEventListener('selectionchange', function () {\n    var el = document.activeElement;\n    if (el && el.vmodel) {\n      trigger(el, 'input');\n    }\n  });\n}\n\nvar model$1 = {\n  inserted: function inserted (el, binding, vnode) {\n    if (vnode.tag === 'select') {\n      var cb = function () {\n        setSelected(el, binding, vnode.context);\n      };\n      cb();\n      /* istanbul ignore if */\n      if (isIE || isEdge) {\n        setTimeout(cb, 0);\n      }\n    } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') {\n      el._vModifiers = binding.modifiers;\n      if (!binding.modifiers.lazy) {\n        // Safari < 10.2 & UIWebView doesn't fire compositionend when\n        // switching focus before confirming composition choice\n        // this also fixes the issue where some browsers e.g. iOS Chrome\n        // fires \"change\" instead of \"input\" on autocomplete.\n        el.addEventListener('change', onCompositionEnd);\n        if (!isAndroid) {\n          el.addEventListener('compositionstart', onCompositionStart);\n          el.addEventListener('compositionend', onCompositionEnd);\n        }\n        /* istanbul ignore if */\n        if (isIE9) {\n          el.vmodel = true;\n        }\n      }\n    }\n  },\n  componentUpdated: function componentUpdated (el, binding, vnode) {\n    if (vnode.tag === 'select') {\n      setSelected(el, binding, vnode.context);\n      // in case the options rendered by v-for have changed,\n      // it's possible that the value is out-of-sync with the rendered options.\n      // detect such cases and filter out values that no longer has a matching\n      // option in the DOM.\n      var needReset = el.multiple\n        ? binding.value.some(function (v) { return hasNoMatchingOption(v, el.options); })\n        : binding.value !== binding.oldValue && hasNoMatchingOption(binding.value, el.options);\n      if (needReset) {\n        trigger(el, 'change');\n      }\n    }\n  }\n};\n\nfunction setSelected (el, binding, vm) {\n  var value = binding.value;\n  var isMultiple = el.multiple;\n  if (isMultiple && !Array.isArray(value)) {\n    \"development\" !== 'production' && warn(\n      \"<select multiple v-model=\\\"\" + (binding.expression) + \"\\\"> \" +\n      \"expects an Array value for its binding, but got \" + (Object.prototype.toString.call(value).slice(8, -1)),\n      vm\n    );\n    return\n  }\n  var selected, option;\n  for (var i = 0, l = el.options.length; i < l; i++) {\n    option = el.options[i];\n    if (isMultiple) {\n      selected = looseIndexOf(value, getValue(option)) > -1;\n      if (option.selected !== selected) {\n        option.selected = selected;\n      }\n    } else {\n      if (looseEqual(getValue(option), value)) {\n        if (el.selectedIndex !== i) {\n          el.selectedIndex = i;\n        }\n        return\n      }\n    }\n  }\n  if (!isMultiple) {\n    el.selectedIndex = -1;\n  }\n}\n\nfunction hasNoMatchingOption (value, options) {\n  for (var i = 0, l = options.length; i < l; i++) {\n    if (looseEqual(getValue(options[i]), value)) {\n      return false\n    }\n  }\n  return true\n}\n\nfunction getValue (option) {\n  return '_value' in option\n    ? option._value\n    : option.value\n}\n\nfunction onCompositionStart (e) {\n  e.target.composing = true;\n}\n\nfunction onCompositionEnd (e) {\n  e.target.composing = false;\n  trigger(e.target, 'input');\n}\n\nfunction trigger (el, type) {\n  var e = document.createEvent('HTMLEvents');\n  e.initEvent(type, true, true);\n  el.dispatchEvent(e);\n}\n\n/*  */\n\n// recursively search for possible transition defined inside the component root\nfunction locateNode (vnode) {\n  return vnode.componentInstance && (!vnode.data || !vnode.data.transition)\n    ? locateNode(vnode.componentInstance._vnode)\n    : vnode\n}\n\nvar show = {\n  bind: function bind (el, ref, vnode) {\n    var value = ref.value;\n\n    vnode = locateNode(vnode);\n    var transition = vnode.data && vnode.data.transition;\n    var originalDisplay = el.__vOriginalDisplay =\n      el.style.display === 'none' ? '' : el.style.display;\n    if (value && transition && !isIE9) {\n      vnode.data.show = true;\n      enter(vnode, function () {\n        el.style.display = originalDisplay;\n      });\n    } else {\n      el.style.display = value ? originalDisplay : 'none';\n    }\n  },\n\n  update: function update (el, ref, vnode) {\n    var value = ref.value;\n    var oldValue = ref.oldValue;\n\n    /* istanbul ignore if */\n    if (value === oldValue) { return }\n    vnode = locateNode(vnode);\n    var transition = vnode.data && vnode.data.transition;\n    if (transition && !isIE9) {\n      vnode.data.show = true;\n      if (value) {\n        enter(vnode, function () {\n          el.style.display = el.__vOriginalDisplay;\n        });\n      } else {\n        leave(vnode, function () {\n          el.style.display = 'none';\n        });\n      }\n    } else {\n      el.style.display = value ? el.__vOriginalDisplay : 'none';\n    }\n  },\n\n  unbind: function unbind (\n    el,\n    binding,\n    vnode,\n    oldVnode,\n    isDestroy\n  ) {\n    if (!isDestroy) {\n      el.style.display = el.__vOriginalDisplay;\n    }\n  }\n};\n\nvar platformDirectives = {\n  model: model$1,\n  show: show\n};\n\n/*  */\n\n// Provides transition support for a single element/component.\n// supports transition mode (out-in / in-out)\n\nvar transitionProps = {\n  name: String,\n  appear: Boolean,\n  css: Boolean,\n  mode: String,\n  type: String,\n  enterClass: String,\n  leaveClass: String,\n  enterToClass: String,\n  leaveToClass: String,\n  enterActiveClass: String,\n  leaveActiveClass: String,\n  appearClass: String,\n  appearActiveClass: String,\n  appearToClass: String,\n  duration: [Number, String, Object]\n};\n\n// in case the child is also an abstract component, e.g. <keep-alive>\n// we want to recursively retrieve the real component to be rendered\nfunction getRealChild (vnode) {\n  var compOptions = vnode && vnode.componentOptions;\n  if (compOptions && compOptions.Ctor.options.abstract) {\n    return getRealChild(getFirstComponentChild(compOptions.children))\n  } else {\n    return vnode\n  }\n}\n\nfunction extractTransitionData (comp) {\n  var data = {};\n  var options = comp.$options;\n  // props\n  for (var key in options.propsData) {\n    data[key] = comp[key];\n  }\n  // events.\n  // extract listeners and pass them directly to the transition methods\n  var listeners = options._parentListeners;\n  for (var key$1 in listeners) {\n    data[camelize(key$1)] = listeners[key$1];\n  }\n  return data\n}\n\nfunction placeholder (h, rawChild) {\n  if (/\\d-keep-alive$/.test(rawChild.tag)) {\n    return h('keep-alive', {\n      props: rawChild.componentOptions.propsData\n    })\n  }\n}\n\nfunction hasParentTransition (vnode) {\n  while ((vnode = vnode.parent)) {\n    if (vnode.data.transition) {\n      return true\n    }\n  }\n}\n\nfunction isSameChild (child, oldChild) {\n  return oldChild.key === child.key && oldChild.tag === child.tag\n}\n\nvar Transition = {\n  name: 'transition',\n  props: transitionProps,\n  abstract: true,\n\n  render: function render (h) {\n    var this$1 = this;\n\n    var children = this.$slots.default;\n    if (!children) {\n      return\n    }\n\n    // filter out text nodes (possible whitespaces)\n    children = children.filter(function (c) { return c.tag; });\n    /* istanbul ignore if */\n    if (!children.length) {\n      return\n    }\n\n    // warn multiple elements\n    if (\"development\" !== 'production' && children.length > 1) {\n      warn(\n        '<transition> can only be used on a single element. Use ' +\n        '<transition-group> for lists.',\n        this.$parent\n      );\n    }\n\n    var mode = this.mode;\n\n    // warn invalid mode\n    if (\"development\" !== 'production' &&\n        mode && mode !== 'in-out' && mode !== 'out-in') {\n      warn(\n        'invalid <transition> mode: ' + mode,\n        this.$parent\n      );\n    }\n\n    var rawChild = children[0];\n\n    // if this is a component root node and the component's\n    // parent container node also has transition, skip.\n    if (hasParentTransition(this.$vnode)) {\n      return rawChild\n    }\n\n    // apply transition data to child\n    // use getRealChild() to ignore abstract components e.g. keep-alive\n    var child = getRealChild(rawChild);\n    /* istanbul ignore if */\n    if (!child) {\n      return rawChild\n    }\n\n    if (this._leaving) {\n      return placeholder(h, rawChild)\n    }\n\n    // ensure a key that is unique to the vnode type and to this transition\n    // component instance. This key will be used to remove pending leaving nodes\n    // during entering.\n    var id = \"__transition-\" + (this._uid) + \"-\";\n    child.key = child.key == null\n      ? id + child.tag\n      : isPrimitive(child.key)\n        ? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key)\n        : child.key;\n\n    var data = (child.data || (child.data = {})).transition = extractTransitionData(this);\n    var oldRawChild = this._vnode;\n    var oldChild = getRealChild(oldRawChild);\n\n    // mark v-show\n    // so that the transition module can hand over the control to the directive\n    if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {\n      child.data.show = true;\n    }\n\n    if (oldChild && oldChild.data && !isSameChild(child, oldChild)) {\n      // replace old child transition data with fresh one\n      // important for dynamic transitions!\n      var oldData = oldChild && (oldChild.data.transition = extend({}, data));\n      // handle transition mode\n      if (mode === 'out-in') {\n        // return placeholder node and queue update when leave finishes\n        this._leaving = true;\n        mergeVNodeHook(oldData, 'afterLeave', function () {\n          this$1._leaving = false;\n          this$1.$forceUpdate();\n        });\n        return placeholder(h, rawChild)\n      } else if (mode === 'in-out') {\n        var delayedLeave;\n        var performLeave = function () { delayedLeave(); };\n        mergeVNodeHook(data, 'afterEnter', performLeave);\n        mergeVNodeHook(data, 'enterCancelled', performLeave);\n        mergeVNodeHook(oldData, 'delayLeave', function (leave) { delayedLeave = leave; });\n      }\n    }\n\n    return rawChild\n  }\n};\n\n/*  */\n\n// Provides transition support for list items.\n// supports move transitions using the FLIP technique.\n\n// Because the vdom's children update algorithm is \"unstable\" - i.e.\n// it doesn't guarantee the relative positioning of removed elements,\n// we force transition-group to update its children into two passes:\n// in the first pass, we remove all nodes that need to be removed,\n// triggering their leaving transition; in the second pass, we insert/move\n// into the final desired state. This way in the second pass removed\n// nodes will remain where they should be.\n\nvar props = extend({\n  tag: String,\n  moveClass: String\n}, transitionProps);\n\ndelete props.mode;\n\nvar TransitionGroup = {\n  props: props,\n\n  render: function render (h) {\n    var tag = this.tag || this.$vnode.data.tag || 'span';\n    var map = Object.create(null);\n    var prevChildren = this.prevChildren = this.children;\n    var rawChildren = this.$slots.default || [];\n    var children = this.children = [];\n    var transitionData = extractTransitionData(this);\n\n    for (var i = 0; i < rawChildren.length; i++) {\n      var c = rawChildren[i];\n      if (c.tag) {\n        if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {\n          children.push(c);\n          map[c.key] = c\n          ;(c.data || (c.data = {})).transition = transitionData;\n        } else {\n          var opts = c.componentOptions;\n          var name = opts ? (opts.Ctor.options.name || opts.tag || '') : c.tag;\n          warn((\"<transition-group> children must be keyed: <\" + name + \">\"));\n        }\n      }\n    }\n\n    if (prevChildren) {\n      var kept = [];\n      var removed = [];\n      for (var i$1 = 0; i$1 < prevChildren.length; i$1++) {\n        var c$1 = prevChildren[i$1];\n        c$1.data.transition = transitionData;\n        c$1.data.pos = c$1.elm.getBoundingClientRect();\n        if (map[c$1.key]) {\n          kept.push(c$1);\n        } else {\n          removed.push(c$1);\n        }\n      }\n      this.kept = h(tag, null, kept);\n      this.removed = removed;\n    }\n\n    return h(tag, null, children)\n  },\n\n  beforeUpdate: function beforeUpdate () {\n    // force removing pass\n    this.__patch__(\n      this._vnode,\n      this.kept,\n      false, // hydrating\n      true // removeOnly (!important, avoids unnecessary moves)\n    );\n    this._vnode = this.kept;\n  },\n\n  updated: function updated () {\n    var children = this.prevChildren;\n    var moveClass = this.moveClass || ((this.name || 'v') + '-move');\n    if (!children.length || !this.hasMove(children[0].elm, moveClass)) {\n      return\n    }\n\n    // we divide the work into three loops to avoid mixing DOM reads and writes\n    // in each iteration - which helps prevent layout thrashing.\n    children.forEach(callPendingCbs);\n    children.forEach(recordPosition);\n    children.forEach(applyTranslation);\n\n    // force reflow to put everything in position\n    var body = document.body;\n    var f = body.offsetHeight; // eslint-disable-line\n\n    children.forEach(function (c) {\n      if (c.data.moved) {\n        var el = c.elm;\n        var s = el.style;\n        addTransitionClass(el, moveClass);\n        s.transform = s.WebkitTransform = s.transitionDuration = '';\n        el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {\n          if (!e || /transform$/.test(e.propertyName)) {\n            el.removeEventListener(transitionEndEvent, cb);\n            el._moveCb = null;\n            removeTransitionClass(el, moveClass);\n          }\n        });\n      }\n    });\n  },\n\n  methods: {\n    hasMove: function hasMove (el, moveClass) {\n      /* istanbul ignore if */\n      if (!hasTransition) {\n        return false\n      }\n      if (this._hasMove != null) {\n        return this._hasMove\n      }\n      // Detect whether an element with the move class applied has\n      // CSS transitions. Since the element may be inside an entering\n      // transition at this very moment, we make a clone of it and remove\n      // all other transition classes applied to ensure only the move class\n      // is applied.\n      var clone = el.cloneNode();\n      if (el._transitionClasses) {\n        el._transitionClasses.forEach(function (cls) { removeClass(clone, cls); });\n      }\n      addClass(clone, moveClass);\n      clone.style.display = 'none';\n      this.$el.appendChild(clone);\n      var info = getTransitionInfo(clone);\n      this.$el.removeChild(clone);\n      return (this._hasMove = info.hasTransform)\n    }\n  }\n};\n\nfunction callPendingCbs (c) {\n  /* istanbul ignore if */\n  if (c.elm._moveCb) {\n    c.elm._moveCb();\n  }\n  /* istanbul ignore if */\n  if (c.elm._enterCb) {\n    c.elm._enterCb();\n  }\n}\n\nfunction recordPosition (c) {\n  c.data.newPos = c.elm.getBoundingClientRect();\n}\n\nfunction applyTranslation (c) {\n  var oldPos = c.data.pos;\n  var newPos = c.data.newPos;\n  var dx = oldPos.left - newPos.left;\n  var dy = oldPos.top - newPos.top;\n  if (dx || dy) {\n    c.data.moved = true;\n    var s = c.elm.style;\n    s.transform = s.WebkitTransform = \"translate(\" + dx + \"px,\" + dy + \"px)\";\n    s.transitionDuration = '0s';\n  }\n}\n\nvar platformComponents = {\n  Transition: Transition,\n  TransitionGroup: TransitionGroup\n};\n\n/*  */\n\n// install platform specific utils\nVue$3.config.mustUseProp = mustUseProp;\nVue$3.config.isReservedTag = isReservedTag;\nVue$3.config.isReservedAttr = isReservedAttr;\nVue$3.config.getTagNamespace = getTagNamespace;\nVue$3.config.isUnknownElement = isUnknownElement;\n\n// install platform runtime directives & components\nextend(Vue$3.options.directives, platformDirectives);\nextend(Vue$3.options.components, platformComponents);\n\n// install platform patch function\nVue$3.prototype.__patch__ = inBrowser ? patch : noop;\n\n// public mount method\nVue$3.prototype.$mount = function (\n  el,\n  hydrating\n) {\n  el = el && inBrowser ? query(el) : undefined;\n  return mountComponent(this, el, hydrating)\n};\n\n// devtools global hook\n/* istanbul ignore next */\nsetTimeout(function () {\n  if (config.devtools) {\n    if (devtools) {\n      devtools.emit('init', Vue$3);\n    } else if (\"development\" !== 'production' && isChrome) {\n      console[console.info ? 'info' : 'log'](\n        'Download the Vue Devtools extension for a better development experience:\\n' +\n        'https://github.com/vuejs/vue-devtools'\n      );\n    }\n  }\n  if (\"development\" !== 'production' &&\n      config.productionTip !== false &&\n      inBrowser && typeof console !== 'undefined') {\n    console[console.info ? 'info' : 'log'](\n      \"You are running Vue in development mode.\\n\" +\n      \"Make sure to turn on production mode when deploying for production.\\n\" +\n      \"See more tips at https://vuejs.org/guide/deployment.html\"\n    );\n  }\n}, 0);\n\n/*  */\n\n// check whether current browser encodes a char inside attribute values\nfunction shouldDecode (content, encoded) {\n  var div = document.createElement('div');\n  div.innerHTML = \"<div a=\\\"\" + content + \"\\\">\";\n  return div.innerHTML.indexOf(encoded) > 0\n}\n\n// #3663\n// IE encodes newlines inside attribute values while other browsers don't\nvar shouldDecodeNewlines = inBrowser ? shouldDecode('\\n', '&#10;') : false;\n\n/*  */\n\nvar isUnaryTag = makeMap(\n  'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +\n  'link,meta,param,source,track,wbr'\n);\n\n// Elements that you can, intentionally, leave open\n// (and which close themselves)\nvar canBeLeftOpenTag = makeMap(\n  'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'\n);\n\n// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3\n// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content\nvar isNonPhrasingTag = makeMap(\n  'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +\n  'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +\n  'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +\n  'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +\n  'title,tr,track'\n);\n\n/*  */\n\nvar decoder;\n\nfunction decode (html) {\n  decoder = decoder || document.createElement('div');\n  decoder.innerHTML = html;\n  return decoder.textContent\n}\n\n/**\n * Not type-checking this file because it's mostly vendor code.\n */\n\n/*!\n * HTML Parser By John Resig (ejohn.org)\n * Modified by Juriy \"kangax\" Zaytsev\n * Original code by Erik Arvidsson, Mozilla Public License\n * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js\n */\n\n// Regular Expressions for parsing tags and attributes\nvar singleAttrIdentifier = /([^\\s\"'<>/=]+)/;\nvar singleAttrAssign = /(?:=)/;\nvar singleAttrValues = [\n  // attr value double quotes\n  /\"([^\"]*)\"+/.source,\n  // attr value, single quotes\n  /'([^']*)'+/.source,\n  // attr value, no quotes\n  /([^\\s\"'=<>`]+)/.source\n];\nvar attribute = new RegExp(\n  '^\\\\s*' + singleAttrIdentifier.source +\n  '(?:\\\\s*(' + singleAttrAssign.source + ')' +\n  '\\\\s*(?:' + singleAttrValues.join('|') + '))?'\n);\n\n// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName\n// but for Vue templates we can enforce a simple charset\nvar ncname = '[a-zA-Z_][\\\\w\\\\-\\\\.]*';\nvar qnameCapture = '((?:' + ncname + '\\\\:)?' + ncname + ')';\nvar startTagOpen = new RegExp('^<' + qnameCapture);\nvar startTagClose = /^\\s*(\\/?)>/;\nvar endTag = new RegExp('^<\\\\/' + qnameCapture + '[^>]*>');\nvar doctype = /^<!DOCTYPE [^>]+>/i;\nvar comment = /^<!--/;\nvar conditionalComment = /^<!\\[/;\n\nvar IS_REGEX_CAPTURING_BROKEN = false;\n'x'.replace(/x(.)?/g, function (m, g) {\n  IS_REGEX_CAPTURING_BROKEN = g === '';\n});\n\n// Special Elements (can contain anything)\nvar isPlainTextElement = makeMap('script,style,textarea', true);\nvar reCache = {};\n\nvar decodingMap = {\n  '&lt;': '<',\n  '&gt;': '>',\n  '&quot;': '\"',\n  '&amp;': '&',\n  '&#10;': '\\n'\n};\nvar encodedAttr = /&(?:lt|gt|quot|amp);/g;\nvar encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10);/g;\n\nfunction decodeAttr (value, shouldDecodeNewlines) {\n  var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;\n  return value.replace(re, function (match) { return decodingMap[match]; })\n}\n\nfunction parseHTML (html, options) {\n  var stack = [];\n  var expectHTML = options.expectHTML;\n  var isUnaryTag$$1 = options.isUnaryTag || no;\n  var canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no;\n  var index = 0;\n  var last, lastTag;\n  while (html) {\n    last = html;\n    // Make sure we're not in a plaintext content element like script/style\n    if (!lastTag || !isPlainTextElement(lastTag)) {\n      var textEnd = html.indexOf('<');\n      if (textEnd === 0) {\n        // Comment:\n        if (comment.test(html)) {\n          var commentEnd = html.indexOf('-->');\n\n          if (commentEnd >= 0) {\n            advance(commentEnd + 3);\n            continue\n          }\n        }\n\n        // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment\n        if (conditionalComment.test(html)) {\n          var conditionalEnd = html.indexOf(']>');\n\n          if (conditionalEnd >= 0) {\n            advance(conditionalEnd + 2);\n            continue\n          }\n        }\n\n        // Doctype:\n        var doctypeMatch = html.match(doctype);\n        if (doctypeMatch) {\n          advance(doctypeMatch[0].length);\n          continue\n        }\n\n        // End tag:\n        var endTagMatch = html.match(endTag);\n        if (endTagMatch) {\n          var curIndex = index;\n          advance(endTagMatch[0].length);\n          parseEndTag(endTagMatch[1], curIndex, index);\n          continue\n        }\n\n        // Start tag:\n        var startTagMatch = parseStartTag();\n        if (startTagMatch) {\n          handleStartTag(startTagMatch);\n          continue\n        }\n      }\n\n      var text = (void 0), rest$1 = (void 0), next = (void 0);\n      if (textEnd >= 0) {\n        rest$1 = html.slice(textEnd);\n        while (\n          !endTag.test(rest$1) &&\n          !startTagOpen.test(rest$1) &&\n          !comment.test(rest$1) &&\n          !conditionalComment.test(rest$1)\n        ) {\n          // < in plain text, be forgiving and treat it as text\n          next = rest$1.indexOf('<', 1);\n          if (next < 0) { break }\n          textEnd += next;\n          rest$1 = html.slice(textEnd);\n        }\n        text = html.substring(0, textEnd);\n        advance(textEnd);\n      }\n\n      if (textEnd < 0) {\n        text = html;\n        html = '';\n      }\n\n      if (options.chars && text) {\n        options.chars(text);\n      }\n    } else {\n      var stackedTag = lastTag.toLowerCase();\n      var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\\\s\\\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));\n      var endTagLength = 0;\n      var rest = html.replace(reStackedTag, function (all, text, endTag) {\n        endTagLength = endTag.length;\n        if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {\n          text = text\n            .replace(/<!--([\\s\\S]*?)-->/g, '$1')\n            .replace(/<!\\[CDATA\\[([\\s\\S]*?)]]>/g, '$1');\n        }\n        if (options.chars) {\n          options.chars(text);\n        }\n        return ''\n      });\n      index += html.length - rest.length;\n      html = rest;\n      parseEndTag(stackedTag, index - endTagLength, index);\n    }\n\n    if (html === last) {\n      options.chars && options.chars(html);\n      if (\"development\" !== 'production' && !stack.length && options.warn) {\n        options.warn((\"Mal-formatted tag at end of template: \\\"\" + html + \"\\\"\"));\n      }\n      break\n    }\n  }\n\n  // Clean up any remaining tags\n  parseEndTag();\n\n  function advance (n) {\n    index += n;\n    html = html.substring(n);\n  }\n\n  function parseStartTag () {\n    var start = html.match(startTagOpen);\n    if (start) {\n      var match = {\n        tagName: start[1],\n        attrs: [],\n        start: index\n      };\n      advance(start[0].length);\n      var end, attr;\n      while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {\n        advance(attr[0].length);\n        match.attrs.push(attr);\n      }\n      if (end) {\n        match.unarySlash = end[1];\n        advance(end[0].length);\n        match.end = index;\n        return match\n      }\n    }\n  }\n\n  function handleStartTag (match) {\n    var tagName = match.tagName;\n    var unarySlash = match.unarySlash;\n\n    if (expectHTML) {\n      if (lastTag === 'p' && isNonPhrasingTag(tagName)) {\n        parseEndTag(lastTag);\n      }\n      if (canBeLeftOpenTag$$1(tagName) && lastTag === tagName) {\n        parseEndTag(tagName);\n      }\n    }\n\n    var unary = isUnaryTag$$1(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;\n\n    var l = match.attrs.length;\n    var attrs = new Array(l);\n    for (var i = 0; i < l; i++) {\n      var args = match.attrs[i];\n      // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778\n      if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('\"\"') === -1) {\n        if (args[3] === '') { delete args[3]; }\n        if (args[4] === '') { delete args[4]; }\n        if (args[5] === '') { delete args[5]; }\n      }\n      var value = args[3] || args[4] || args[5] || '';\n      attrs[i] = {\n        name: args[1],\n        value: decodeAttr(\n          value,\n          options.shouldDecodeNewlines\n        )\n      };\n    }\n\n    if (!unary) {\n      stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs });\n      lastTag = tagName;\n    }\n\n    if (options.start) {\n      options.start(tagName, attrs, unary, match.start, match.end);\n    }\n  }\n\n  function parseEndTag (tagName, start, end) {\n    var pos, lowerCasedTagName;\n    if (start == null) { start = index; }\n    if (end == null) { end = index; }\n\n    if (tagName) {\n      lowerCasedTagName = tagName.toLowerCase();\n    }\n\n    // Find the closest opened tag of the same type\n    if (tagName) {\n      for (pos = stack.length - 1; pos >= 0; pos--) {\n        if (stack[pos].lowerCasedTag === lowerCasedTagName) {\n          break\n        }\n      }\n    } else {\n      // If no tag name is provided, clean shop\n      pos = 0;\n    }\n\n    if (pos >= 0) {\n      // Close all the open elements, up the stack\n      for (var i = stack.length - 1; i >= pos; i--) {\n        if (\"development\" !== 'production' &&\n            (i > pos || !tagName) &&\n            options.warn) {\n          options.warn(\n            (\"tag <\" + (stack[i].tag) + \"> has no matching end tag.\")\n          );\n        }\n        if (options.end) {\n          options.end(stack[i].tag, start, end);\n        }\n      }\n\n      // Remove the open elements from the stack\n      stack.length = pos;\n      lastTag = pos && stack[pos - 1].tag;\n    } else if (lowerCasedTagName === 'br') {\n      if (options.start) {\n        options.start(tagName, [], true, start, end);\n      }\n    } else if (lowerCasedTagName === 'p') {\n      if (options.start) {\n        options.start(tagName, [], false, start, end);\n      }\n      if (options.end) {\n        options.end(tagName, start, end);\n      }\n    }\n  }\n}\n\n/*  */\n\nvar defaultTagRE = /\\{\\{((?:.|\\n)+?)\\}\\}/g;\nvar regexEscapeRE = /[-.*+?^${}()|[\\]\\/\\\\]/g;\n\nvar buildRegex = cached(function (delimiters) {\n  var open = delimiters[0].replace(regexEscapeRE, '\\\\$&');\n  var close = delimiters[1].replace(regexEscapeRE, '\\\\$&');\n  return new RegExp(open + '((?:.|\\\\n)+?)' + close, 'g')\n});\n\nfunction parseText (\n  text,\n  delimiters\n) {\n  var tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;\n  if (!tagRE.test(text)) {\n    return\n  }\n  var tokens = [];\n  var lastIndex = tagRE.lastIndex = 0;\n  var match, index;\n  while ((match = tagRE.exec(text))) {\n    index = match.index;\n    // push text token\n    if (index > lastIndex) {\n      tokens.push(JSON.stringify(text.slice(lastIndex, index)));\n    }\n    // tag token\n    var exp = parseFilters(match[1].trim());\n    tokens.push((\"_s(\" + exp + \")\"));\n    lastIndex = index + match[0].length;\n  }\n  if (lastIndex < text.length) {\n    tokens.push(JSON.stringify(text.slice(lastIndex)));\n  }\n  return tokens.join('+')\n}\n\n/*  */\n\nvar onRE = /^@|^v-on:/;\nvar dirRE = /^v-|^@|^:/;\nvar forAliasRE = /(.*?)\\s+(?:in|of)\\s+(.*)/;\nvar forIteratorRE = /\\((\\{[^}]*\\}|[^,]*),([^,]*)(?:,([^,]*))?\\)/;\n\nvar argRE = /:(.*)$/;\nvar bindRE = /^:|^v-bind:/;\nvar modifierRE = /\\.[^.]+/g;\n\nvar decodeHTMLCached = cached(decode);\n\n// configurable state\nvar warn$2;\nvar delimiters;\nvar transforms;\nvar preTransforms;\nvar postTransforms;\nvar platformIsPreTag;\nvar platformMustUseProp;\nvar platformGetTagNamespace;\n\n/**\n * Convert HTML string to AST.\n */\nfunction parse (\n  template,\n  options\n) {\n  warn$2 = options.warn || baseWarn;\n  platformGetTagNamespace = options.getTagNamespace || no;\n  platformMustUseProp = options.mustUseProp || no;\n  platformIsPreTag = options.isPreTag || no;\n  preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');\n  transforms = pluckModuleFunction(options.modules, 'transformNode');\n  postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');\n  delimiters = options.delimiters;\n\n  var stack = [];\n  var preserveWhitespace = options.preserveWhitespace !== false;\n  var root;\n  var currentParent;\n  var inVPre = false;\n  var inPre = false;\n  var warned = false;\n\n  function warnOnce (msg) {\n    if (!warned) {\n      warned = true;\n      warn$2(msg);\n    }\n  }\n\n  function endPre (element) {\n    // check pre state\n    if (element.pre) {\n      inVPre = false;\n    }\n    if (platformIsPreTag(element.tag)) {\n      inPre = false;\n    }\n  }\n\n  parseHTML(template, {\n    warn: warn$2,\n    expectHTML: options.expectHTML,\n    isUnaryTag: options.isUnaryTag,\n    canBeLeftOpenTag: options.canBeLeftOpenTag,\n    shouldDecodeNewlines: options.shouldDecodeNewlines,\n    start: function start (tag, attrs, unary) {\n      // check namespace.\n      // inherit parent ns if there is one\n      var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);\n\n      // handle IE svg bug\n      /* istanbul ignore if */\n      if (isIE && ns === 'svg') {\n        attrs = guardIESVGBug(attrs);\n      }\n\n      var element = {\n        type: 1,\n        tag: tag,\n        attrsList: attrs,\n        attrsMap: makeAttrsMap(attrs),\n        parent: currentParent,\n        children: []\n      };\n      if (ns) {\n        element.ns = ns;\n      }\n\n      if (isForbiddenTag(element) && !isServerRendering()) {\n        element.forbidden = true;\n        \"development\" !== 'production' && warn$2(\n          'Templates should only be responsible for mapping the state to the ' +\n          'UI. Avoid placing tags with side-effects in your templates, such as ' +\n          \"<\" + tag + \">\" + ', as they will not be parsed.'\n        );\n      }\n\n      // apply pre-transforms\n      for (var i = 0; i < preTransforms.length; i++) {\n        preTransforms[i](element, options);\n      }\n\n      if (!inVPre) {\n        processPre(element);\n        if (element.pre) {\n          inVPre = true;\n        }\n      }\n      if (platformIsPreTag(element.tag)) {\n        inPre = true;\n      }\n      if (inVPre) {\n        processRawAttrs(element);\n      } else {\n        processFor(element);\n        processIf(element);\n        processOnce(element);\n        processKey(element);\n\n        // determine whether this is a plain element after\n        // removing structural attributes\n        element.plain = !element.key && !attrs.length;\n\n        processRef(element);\n        processSlot(element);\n        processComponent(element);\n        for (var i$1 = 0; i$1 < transforms.length; i$1++) {\n          transforms[i$1](element, options);\n        }\n        processAttrs(element);\n      }\n\n      function checkRootConstraints (el) {\n        {\n          if (el.tag === 'slot' || el.tag === 'template') {\n            warnOnce(\n              \"Cannot use <\" + (el.tag) + \"> as component root element because it may \" +\n              'contain multiple nodes.'\n            );\n          }\n          if (el.attrsMap.hasOwnProperty('v-for')) {\n            warnOnce(\n              'Cannot use v-for on stateful component root element because ' +\n              'it renders multiple elements.'\n            );\n          }\n        }\n      }\n\n      // tree management\n      if (!root) {\n        root = element;\n        checkRootConstraints(root);\n      } else if (!stack.length) {\n        // allow root elements with v-if, v-else-if and v-else\n        if (root.if && (element.elseif || element.else)) {\n          checkRootConstraints(element);\n          addIfCondition(root, {\n            exp: element.elseif,\n            block: element\n          });\n        } else {\n          warnOnce(\n            \"Component template should contain exactly one root element. \" +\n            \"If you are using v-if on multiple elements, \" +\n            \"use v-else-if to chain them instead.\"\n          );\n        }\n      }\n      if (currentParent && !element.forbidden) {\n        if (element.elseif || element.else) {\n          processIfConditions(element, currentParent);\n        } else if (element.slotScope) { // scoped slot\n          currentParent.plain = false;\n          var name = element.slotTarget || '\"default\"';(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;\n        } else {\n          currentParent.children.push(element);\n          element.parent = currentParent;\n        }\n      }\n      if (!unary) {\n        currentParent = element;\n        stack.push(element);\n      } else {\n        endPre(element);\n      }\n      // apply post-transforms\n      for (var i$2 = 0; i$2 < postTransforms.length; i$2++) {\n        postTransforms[i$2](element, options);\n      }\n    },\n\n    end: function end () {\n      // remove trailing whitespace\n      var element = stack[stack.length - 1];\n      var lastNode = element.children[element.children.length - 1];\n      if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {\n        element.children.pop();\n      }\n      // pop stack\n      stack.length -= 1;\n      currentParent = stack[stack.length - 1];\n      endPre(element);\n    },\n\n    chars: function chars (text) {\n      if (!currentParent) {\n        {\n          if (text === template) {\n            warnOnce(\n              'Component template requires a root element, rather than just text.'\n            );\n          } else if ((text = text.trim())) {\n            warnOnce(\n              (\"text \\\"\" + text + \"\\\" outside root element will be ignored.\")\n            );\n          }\n        }\n        return\n      }\n      // IE textarea placeholder bug\n      /* istanbul ignore if */\n      if (isIE &&\n          currentParent.tag === 'textarea' &&\n          currentParent.attrsMap.placeholder === text) {\n        return\n      }\n      var children = currentParent.children;\n      text = inPre || text.trim()\n        ? isTextTag(currentParent) ? text : decodeHTMLCached(text)\n        // only preserve whitespace if its not right after a starting tag\n        : preserveWhitespace && children.length ? ' ' : '';\n      if (text) {\n        var expression;\n        if (!inVPre && text !== ' ' && (expression = parseText(text, delimiters))) {\n          children.push({\n            type: 2,\n            expression: expression,\n            text: text\n          });\n        } else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {\n          children.push({\n            type: 3,\n            text: text\n          });\n        }\n      }\n    }\n  });\n  return root\n}\n\nfunction processPre (el) {\n  if (getAndRemoveAttr(el, 'v-pre') != null) {\n    el.pre = true;\n  }\n}\n\nfunction processRawAttrs (el) {\n  var l = el.attrsList.length;\n  if (l) {\n    var attrs = el.attrs = new Array(l);\n    for (var i = 0; i < l; i++) {\n      attrs[i] = {\n        name: el.attrsList[i].name,\n        value: JSON.stringify(el.attrsList[i].value)\n      };\n    }\n  } else if (!el.pre) {\n    // non root node in pre blocks with no attributes\n    el.plain = true;\n  }\n}\n\nfunction processKey (el) {\n  var exp = getBindingAttr(el, 'key');\n  if (exp) {\n    if (\"development\" !== 'production' && el.tag === 'template') {\n      warn$2(\"<template> cannot be keyed. Place the key on real elements instead.\");\n    }\n    el.key = exp;\n  }\n}\n\nfunction processRef (el) {\n  var ref = getBindingAttr(el, 'ref');\n  if (ref) {\n    el.ref = ref;\n    el.refInFor = checkInFor(el);\n  }\n}\n\nfunction processFor (el) {\n  var exp;\n  if ((exp = getAndRemoveAttr(el, 'v-for'))) {\n    var inMatch = exp.match(forAliasRE);\n    if (!inMatch) {\n      \"development\" !== 'production' && warn$2(\n        (\"Invalid v-for expression: \" + exp)\n      );\n      return\n    }\n    el.for = inMatch[2].trim();\n    var alias = inMatch[1].trim();\n    var iteratorMatch = alias.match(forIteratorRE);\n    if (iteratorMatch) {\n      el.alias = iteratorMatch[1].trim();\n      el.iterator1 = iteratorMatch[2].trim();\n      if (iteratorMatch[3]) {\n        el.iterator2 = iteratorMatch[3].trim();\n      }\n    } else {\n      el.alias = alias;\n    }\n  }\n}\n\nfunction processIf (el) {\n  var exp = getAndRemoveAttr(el, 'v-if');\n  if (exp) {\n    el.if = exp;\n    addIfCondition(el, {\n      exp: exp,\n      block: el\n    });\n  } else {\n    if (getAndRemoveAttr(el, 'v-else') != null) {\n      el.else = true;\n    }\n    var elseif = getAndRemoveAttr(el, 'v-else-if');\n    if (elseif) {\n      el.elseif = elseif;\n    }\n  }\n}\n\nfunction processIfConditions (el, parent) {\n  var prev = findPrevElement(parent.children);\n  if (prev && prev.if) {\n    addIfCondition(prev, {\n      exp: el.elseif,\n      block: el\n    });\n  } else {\n    warn$2(\n      \"v-\" + (el.elseif ? ('else-if=\"' + el.elseif + '\"') : 'else') + \" \" +\n      \"used on element <\" + (el.tag) + \"> without corresponding v-if.\"\n    );\n  }\n}\n\nfunction findPrevElement (children) {\n  var i = children.length;\n  while (i--) {\n    if (children[i].type === 1) {\n      return children[i]\n    } else {\n      if (\"development\" !== 'production' && children[i].text !== ' ') {\n        warn$2(\n          \"text \\\"\" + (children[i].text.trim()) + \"\\\" between v-if and v-else(-if) \" +\n          \"will be ignored.\"\n        );\n      }\n      children.pop();\n    }\n  }\n}\n\nfunction addIfCondition (el, condition) {\n  if (!el.ifConditions) {\n    el.ifConditions = [];\n  }\n  el.ifConditions.push(condition);\n}\n\nfunction processOnce (el) {\n  var once$$1 = getAndRemoveAttr(el, 'v-once');\n  if (once$$1 != null) {\n    el.once = true;\n  }\n}\n\nfunction processSlot (el) {\n  if (el.tag === 'slot') {\n    el.slotName = getBindingAttr(el, 'name');\n    if (\"development\" !== 'production' && el.key) {\n      warn$2(\n        \"`key` does not work on <slot> because slots are abstract outlets \" +\n        \"and can possibly expand into multiple elements. \" +\n        \"Use the key on a wrapping element instead.\"\n      );\n    }\n  } else {\n    var slotTarget = getBindingAttr(el, 'slot');\n    if (slotTarget) {\n      el.slotTarget = slotTarget === '\"\"' ? '\"default\"' : slotTarget;\n    }\n    if (el.tag === 'template') {\n      el.slotScope = getAndRemoveAttr(el, 'scope');\n    }\n  }\n}\n\nfunction processComponent (el) {\n  var binding;\n  if ((binding = getBindingAttr(el, 'is'))) {\n    el.component = binding;\n  }\n  if (getAndRemoveAttr(el, 'inline-template') != null) {\n    el.inlineTemplate = true;\n  }\n}\n\nfunction processAttrs (el) {\n  var list = el.attrsList;\n  var i, l, name, rawName, value, modifiers, isProp;\n  for (i = 0, l = list.length; i < l; i++) {\n    name = rawName = list[i].name;\n    value = list[i].value;\n    if (dirRE.test(name)) {\n      // mark element as dynamic\n      el.hasBindings = true;\n      // modifiers\n      modifiers = parseModifiers(name);\n      if (modifiers) {\n        name = name.replace(modifierRE, '');\n      }\n      if (bindRE.test(name)) { // v-bind\n        name = name.replace(bindRE, '');\n        value = parseFilters(value);\n        isProp = false;\n        if (modifiers) {\n          if (modifiers.prop) {\n            isProp = true;\n            name = camelize(name);\n            if (name === 'innerHtml') { name = 'innerHTML'; }\n          }\n          if (modifiers.camel) {\n            name = camelize(name);\n          }\n          if (modifiers.sync) {\n            addHandler(\n              el,\n              (\"update:\" + (camelize(name))),\n              genAssignmentCode(value, \"$event\")\n            );\n          }\n        }\n        if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) {\n          addProp(el, name, value);\n        } else {\n          addAttr(el, name, value);\n        }\n      } else if (onRE.test(name)) { // v-on\n        name = name.replace(onRE, '');\n        addHandler(el, name, value, modifiers, false, warn$2);\n      } else { // normal directives\n        name = name.replace(dirRE, '');\n        // parse arg\n        var argMatch = name.match(argRE);\n        var arg = argMatch && argMatch[1];\n        if (arg) {\n          name = name.slice(0, -(arg.length + 1));\n        }\n        addDirective(el, name, rawName, value, arg, modifiers);\n        if (\"development\" !== 'production' && name === 'model') {\n          checkForAliasModel(el, value);\n        }\n      }\n    } else {\n      // literal attribute\n      {\n        var expression = parseText(value, delimiters);\n        if (expression) {\n          warn$2(\n            name + \"=\\\"\" + value + \"\\\": \" +\n            'Interpolation inside attributes has been removed. ' +\n            'Use v-bind or the colon shorthand instead. For example, ' +\n            'instead of <div id=\"{{ val }}\">, use <div :id=\"val\">.'\n          );\n        }\n      }\n      addAttr(el, name, JSON.stringify(value));\n    }\n  }\n}\n\nfunction checkInFor (el) {\n  var parent = el;\n  while (parent) {\n    if (parent.for !== undefined) {\n      return true\n    }\n    parent = parent.parent;\n  }\n  return false\n}\n\nfunction parseModifiers (name) {\n  var match = name.match(modifierRE);\n  if (match) {\n    var ret = {};\n    match.forEach(function (m) { ret[m.slice(1)] = true; });\n    return ret\n  }\n}\n\nfunction makeAttrsMap (attrs) {\n  var map = {};\n  for (var i = 0, l = attrs.length; i < l; i++) {\n    if (\n      \"development\" !== 'production' &&\n      map[attrs[i].name] && !isIE && !isEdge\n    ) {\n      warn$2('duplicate attribute: ' + attrs[i].name);\n    }\n    map[attrs[i].name] = attrs[i].value;\n  }\n  return map\n}\n\n// for script (e.g. type=\"x/template\") or style, do not decode content\nfunction isTextTag (el) {\n  return el.tag === 'script' || el.tag === 'style'\n}\n\nfunction isForbiddenTag (el) {\n  return (\n    el.tag === 'style' ||\n    (el.tag === 'script' && (\n      !el.attrsMap.type ||\n      el.attrsMap.type === 'text/javascript'\n    ))\n  )\n}\n\nvar ieNSBug = /^xmlns:NS\\d+/;\nvar ieNSPrefix = /^NS\\d+:/;\n\n/* istanbul ignore next */\nfunction guardIESVGBug (attrs) {\n  var res = [];\n  for (var i = 0; i < attrs.length; i++) {\n    var attr = attrs[i];\n    if (!ieNSBug.test(attr.name)) {\n      attr.name = attr.name.replace(ieNSPrefix, '');\n      res.push(attr);\n    }\n  }\n  return res\n}\n\nfunction checkForAliasModel (el, value) {\n  var _el = el;\n  while (_el) {\n    if (_el.for && _el.alias === value) {\n      warn$2(\n        \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\">: \" +\n        \"You are binding v-model directly to a v-for iteration alias. \" +\n        \"This will not be able to modify the v-for source array because \" +\n        \"writing to the alias is like modifying a function local variable. \" +\n        \"Consider using an array of objects and use v-model on an object property instead.\"\n      );\n    }\n    _el = _el.parent;\n  }\n}\n\n/*  */\n\nvar isStaticKey;\nvar isPlatformReservedTag;\n\nvar genStaticKeysCached = cached(genStaticKeys$1);\n\n/**\n * Goal of the optimizer: walk the generated template AST tree\n * and detect sub-trees that are purely static, i.e. parts of\n * the DOM that never needs to change.\n *\n * Once we detect these sub-trees, we can:\n *\n * 1. Hoist them into constants, so that we no longer need to\n *    create fresh nodes for them on each re-render;\n * 2. Completely skip them in the patching process.\n */\nfunction optimize (root, options) {\n  if (!root) { return }\n  isStaticKey = genStaticKeysCached(options.staticKeys || '');\n  isPlatformReservedTag = options.isReservedTag || no;\n  // first pass: mark all non-static nodes.\n  markStatic$1(root);\n  // second pass: mark static roots.\n  markStaticRoots(root, false);\n}\n\nfunction genStaticKeys$1 (keys) {\n  return makeMap(\n    'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +\n    (keys ? ',' + keys : '')\n  )\n}\n\nfunction markStatic$1 (node) {\n  node.static = isStatic(node);\n  if (node.type === 1) {\n    // do not make component slot content static. this avoids\n    // 1. components not able to mutate slot nodes\n    // 2. static slot content fails for hot-reloading\n    if (\n      !isPlatformReservedTag(node.tag) &&\n      node.tag !== 'slot' &&\n      node.attrsMap['inline-template'] == null\n    ) {\n      return\n    }\n    for (var i = 0, l = node.children.length; i < l; i++) {\n      var child = node.children[i];\n      markStatic$1(child);\n      if (!child.static) {\n        node.static = false;\n      }\n    }\n  }\n}\n\nfunction markStaticRoots (node, isInFor) {\n  if (node.type === 1) {\n    if (node.static || node.once) {\n      node.staticInFor = isInFor;\n    }\n    // For a node to qualify as a static root, it should have children that\n    // are not just static text. Otherwise the cost of hoisting out will\n    // outweigh the benefits and it's better off to just always render it fresh.\n    if (node.static && node.children.length && !(\n      node.children.length === 1 &&\n      node.children[0].type === 3\n    )) {\n      node.staticRoot = true;\n      return\n    } else {\n      node.staticRoot = false;\n    }\n    if (node.children) {\n      for (var i = 0, l = node.children.length; i < l; i++) {\n        markStaticRoots(node.children[i], isInFor || !!node.for);\n      }\n    }\n    if (node.ifConditions) {\n      walkThroughConditionsBlocks(node.ifConditions, isInFor);\n    }\n  }\n}\n\nfunction walkThroughConditionsBlocks (conditionBlocks, isInFor) {\n  for (var i = 1, len = conditionBlocks.length; i < len; i++) {\n    markStaticRoots(conditionBlocks[i].block, isInFor);\n  }\n}\n\nfunction isStatic (node) {\n  if (node.type === 2) { // expression\n    return false\n  }\n  if (node.type === 3) { // text\n    return true\n  }\n  return !!(node.pre || (\n    !node.hasBindings && // no dynamic bindings\n    !node.if && !node.for && // not v-if or v-for or v-else\n    !isBuiltInTag(node.tag) && // not a built-in\n    isPlatformReservedTag(node.tag) && // not a component\n    !isDirectChildOfTemplateFor(node) &&\n    Object.keys(node).every(isStaticKey)\n  ))\n}\n\nfunction isDirectChildOfTemplateFor (node) {\n  while (node.parent) {\n    node = node.parent;\n    if (node.tag !== 'template') {\n      return false\n    }\n    if (node.for) {\n      return true\n    }\n  }\n  return false\n}\n\n/*  */\n\nvar fnExpRE = /^\\s*([\\w$_]+|\\([^)]*?\\))\\s*=>|^function\\s*\\(/;\nvar simplePathRE = /^\\s*[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*|\\['.*?']|\\[\".*?\"]|\\[\\d+]|\\[[A-Za-z_$][\\w$]*])*\\s*$/;\n\n// keyCode aliases\nvar keyCodes = {\n  esc: 27,\n  tab: 9,\n  enter: 13,\n  space: 32,\n  up: 38,\n  left: 37,\n  right: 39,\n  down: 40,\n  'delete': [8, 46]\n};\n\n// #4868: modifiers that prevent the execution of the listener\n// need to explicitly return null so that we can determine whether to remove\n// the listener for .once\nvar genGuard = function (condition) { return (\"if(\" + condition + \")return null;\"); };\n\nvar modifierCode = {\n  stop: '$event.stopPropagation();',\n  prevent: '$event.preventDefault();',\n  self: genGuard(\"$event.target !== $event.currentTarget\"),\n  ctrl: genGuard(\"!$event.ctrlKey\"),\n  shift: genGuard(\"!$event.shiftKey\"),\n  alt: genGuard(\"!$event.altKey\"),\n  meta: genGuard(\"!$event.metaKey\"),\n  left: genGuard(\"'button' in $event && $event.button !== 0\"),\n  middle: genGuard(\"'button' in $event && $event.button !== 1\"),\n  right: genGuard(\"'button' in $event && $event.button !== 2\")\n};\n\nfunction genHandlers (\n  events,\n  native,\n  warn\n) {\n  var res = native ? 'nativeOn:{' : 'on:{';\n  for (var name in events) {\n    var handler = events[name];\n    // #5330: warn click.right, since right clicks do not actually fire click events.\n    if (\"development\" !== 'production' &&\n        name === 'click' &&\n        handler && handler.modifiers && handler.modifiers.right\n      ) {\n      warn(\n        \"Use \\\"contextmenu\\\" instead of \\\"click.right\\\" since right clicks \" +\n        \"do not actually fire \\\"click\\\" events.\"\n      );\n    }\n    res += \"\\\"\" + name + \"\\\":\" + (genHandler(name, handler)) + \",\";\n  }\n  return res.slice(0, -1) + '}'\n}\n\nfunction genHandler (\n  name,\n  handler\n) {\n  if (!handler) {\n    return 'function(){}'\n  }\n\n  if (Array.isArray(handler)) {\n    return (\"[\" + (handler.map(function (handler) { return genHandler(name, handler); }).join(',')) + \"]\")\n  }\n\n  var isMethodPath = simplePathRE.test(handler.value);\n  var isFunctionExpression = fnExpRE.test(handler.value);\n\n  if (!handler.modifiers) {\n    return isMethodPath || isFunctionExpression\n      ? handler.value\n      : (\"function($event){\" + (handler.value) + \"}\") // inline statement\n  } else {\n    var code = '';\n    var genModifierCode = '';\n    var keys = [];\n    for (var key in handler.modifiers) {\n      if (modifierCode[key]) {\n        genModifierCode += modifierCode[key];\n        // left/right\n        if (keyCodes[key]) {\n          keys.push(key);\n        }\n      } else {\n        keys.push(key);\n      }\n    }\n    if (keys.length) {\n      code += genKeyFilter(keys);\n    }\n    // Make sure modifiers like prevent and stop get executed after key filtering\n    if (genModifierCode) {\n      code += genModifierCode;\n    }\n    var handlerCode = isMethodPath\n      ? handler.value + '($event)'\n      : isFunctionExpression\n        ? (\"(\" + (handler.value) + \")($event)\")\n        : handler.value;\n    return (\"function($event){\" + code + handlerCode + \"}\")\n  }\n}\n\nfunction genKeyFilter (keys) {\n  return (\"if(!('button' in $event)&&\" + (keys.map(genFilterCode).join('&&')) + \")return null;\")\n}\n\nfunction genFilterCode (key) {\n  var keyVal = parseInt(key, 10);\n  if (keyVal) {\n    return (\"$event.keyCode!==\" + keyVal)\n  }\n  var alias = keyCodes[key];\n  return (\"_k($event.keyCode,\" + (JSON.stringify(key)) + (alias ? ',' + JSON.stringify(alias) : '') + \")\")\n}\n\n/*  */\n\nfunction bind$1 (el, dir) {\n  el.wrapData = function (code) {\n    return (\"_b(\" + code + \",'\" + (el.tag) + \"',\" + (dir.value) + (dir.modifiers && dir.modifiers.prop ? ',true' : '') + \")\")\n  };\n}\n\n/*  */\n\nvar baseDirectives = {\n  bind: bind$1,\n  cloak: noop\n};\n\n/*  */\n\n// configurable state\nvar warn$3;\nvar transforms$1;\nvar dataGenFns;\nvar platformDirectives$1;\nvar isPlatformReservedTag$1;\nvar staticRenderFns;\nvar onceCount;\nvar currentOptions;\n\nfunction generate (\n  ast,\n  options\n) {\n  // save previous staticRenderFns so generate calls can be nested\n  var prevStaticRenderFns = staticRenderFns;\n  var currentStaticRenderFns = staticRenderFns = [];\n  var prevOnceCount = onceCount;\n  onceCount = 0;\n  currentOptions = options;\n  warn$3 = options.warn || baseWarn;\n  transforms$1 = pluckModuleFunction(options.modules, 'transformCode');\n  dataGenFns = pluckModuleFunction(options.modules, 'genData');\n  platformDirectives$1 = options.directives || {};\n  isPlatformReservedTag$1 = options.isReservedTag || no;\n  var code = ast ? genElement(ast) : '_c(\"div\")';\n  staticRenderFns = prevStaticRenderFns;\n  onceCount = prevOnceCount;\n  return {\n    render: (\"with(this){return \" + code + \"}\"),\n    staticRenderFns: currentStaticRenderFns\n  }\n}\n\nfunction genElement (el) {\n  if (el.staticRoot && !el.staticProcessed) {\n    return genStatic(el)\n  } else if (el.once && !el.onceProcessed) {\n    return genOnce(el)\n  } else if (el.for && !el.forProcessed) {\n    return genFor(el)\n  } else if (el.if && !el.ifProcessed) {\n    return genIf(el)\n  } else if (el.tag === 'template' && !el.slotTarget) {\n    return genChildren(el) || 'void 0'\n  } else if (el.tag === 'slot') {\n    return genSlot(el)\n  } else {\n    // component or element\n    var code;\n    if (el.component) {\n      code = genComponent(el.component, el);\n    } else {\n      var data = el.plain ? undefined : genData(el);\n\n      var children = el.inlineTemplate ? null : genChildren(el, true);\n      code = \"_c('\" + (el.tag) + \"'\" + (data ? (\",\" + data) : '') + (children ? (\",\" + children) : '') + \")\";\n    }\n    // module transforms\n    for (var i = 0; i < transforms$1.length; i++) {\n      code = transforms$1[i](el, code);\n    }\n    return code\n  }\n}\n\n// hoist static sub-trees out\nfunction genStatic (el) {\n  el.staticProcessed = true;\n  staticRenderFns.push((\"with(this){return \" + (genElement(el)) + \"}\"));\n  return (\"_m(\" + (staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + \")\")\n}\n\n// v-once\nfunction genOnce (el) {\n  el.onceProcessed = true;\n  if (el.if && !el.ifProcessed) {\n    return genIf(el)\n  } else if (el.staticInFor) {\n    var key = '';\n    var parent = el.parent;\n    while (parent) {\n      if (parent.for) {\n        key = parent.key;\n        break\n      }\n      parent = parent.parent;\n    }\n    if (!key) {\n      \"development\" !== 'production' && warn$3(\n        \"v-once can only be used inside v-for that is keyed. \"\n      );\n      return genElement(el)\n    }\n    return (\"_o(\" + (genElement(el)) + \",\" + (onceCount++) + (key ? (\",\" + key) : \"\") + \")\")\n  } else {\n    return genStatic(el)\n  }\n}\n\nfunction genIf (el) {\n  el.ifProcessed = true; // avoid recursion\n  return genIfConditions(el.ifConditions.slice())\n}\n\nfunction genIfConditions (conditions) {\n  if (!conditions.length) {\n    return '_e()'\n  }\n\n  var condition = conditions.shift();\n  if (condition.exp) {\n    return (\"(\" + (condition.exp) + \")?\" + (genTernaryExp(condition.block)) + \":\" + (genIfConditions(conditions)))\n  } else {\n    return (\"\" + (genTernaryExp(condition.block)))\n  }\n\n  // v-if with v-once should generate code like (a)?_m(0):_m(1)\n  function genTernaryExp (el) {\n    return el.once ? genOnce(el) : genElement(el)\n  }\n}\n\nfunction genFor (el) {\n  var exp = el.for;\n  var alias = el.alias;\n  var iterator1 = el.iterator1 ? (\",\" + (el.iterator1)) : '';\n  var iterator2 = el.iterator2 ? (\",\" + (el.iterator2)) : '';\n\n  if (\n    \"development\" !== 'production' &&\n    maybeComponent(el) && el.tag !== 'slot' && el.tag !== 'template' && !el.key\n  ) {\n    warn$3(\n      \"<\" + (el.tag) + \" v-for=\\\"\" + alias + \" in \" + exp + \"\\\">: component lists rendered with \" +\n      \"v-for should have explicit keys. \" +\n      \"See https://vuejs.org/guide/list.html#key for more info.\",\n      true /* tip */\n    );\n  }\n\n  el.forProcessed = true; // avoid recursion\n  return \"_l((\" + exp + \"),\" +\n    \"function(\" + alias + iterator1 + iterator2 + \"){\" +\n      \"return \" + (genElement(el)) +\n    '})'\n}\n\nfunction genData (el) {\n  var data = '{';\n\n  // directives first.\n  // directives may mutate the el's other properties before they are generated.\n  var dirs = genDirectives(el);\n  if (dirs) { data += dirs + ','; }\n\n  // key\n  if (el.key) {\n    data += \"key:\" + (el.key) + \",\";\n  }\n  // ref\n  if (el.ref) {\n    data += \"ref:\" + (el.ref) + \",\";\n  }\n  if (el.refInFor) {\n    data += \"refInFor:true,\";\n  }\n  // pre\n  if (el.pre) {\n    data += \"pre:true,\";\n  }\n  // record original tag name for components using \"is\" attribute\n  if (el.component) {\n    data += \"tag:\\\"\" + (el.tag) + \"\\\",\";\n  }\n  // module data generation functions\n  for (var i = 0; i < dataGenFns.length; i++) {\n    data += dataGenFns[i](el);\n  }\n  // attributes\n  if (el.attrs) {\n    data += \"attrs:{\" + (genProps(el.attrs)) + \"},\";\n  }\n  // DOM props\n  if (el.props) {\n    data += \"domProps:{\" + (genProps(el.props)) + \"},\";\n  }\n  // event handlers\n  if (el.events) {\n    data += (genHandlers(el.events, false, warn$3)) + \",\";\n  }\n  if (el.nativeEvents) {\n    data += (genHandlers(el.nativeEvents, true, warn$3)) + \",\";\n  }\n  // slot target\n  if (el.slotTarget) {\n    data += \"slot:\" + (el.slotTarget) + \",\";\n  }\n  // scoped slots\n  if (el.scopedSlots) {\n    data += (genScopedSlots(el.scopedSlots)) + \",\";\n  }\n  // component v-model\n  if (el.model) {\n    data += \"model:{value:\" + (el.model.value) + \",callback:\" + (el.model.callback) + \",expression:\" + (el.model.expression) + \"},\";\n  }\n  // inline-template\n  if (el.inlineTemplate) {\n    var inlineTemplate = genInlineTemplate(el);\n    if (inlineTemplate) {\n      data += inlineTemplate + \",\";\n    }\n  }\n  data = data.replace(/,$/, '') + '}';\n  // v-bind data wrap\n  if (el.wrapData) {\n    data = el.wrapData(data);\n  }\n  return data\n}\n\nfunction genDirectives (el) {\n  var dirs = el.directives;\n  if (!dirs) { return }\n  var res = 'directives:[';\n  var hasRuntime = false;\n  var i, l, dir, needRuntime;\n  for (i = 0, l = dirs.length; i < l; i++) {\n    dir = dirs[i];\n    needRuntime = true;\n    var gen = platformDirectives$1[dir.name] || baseDirectives[dir.name];\n    if (gen) {\n      // compile-time directive that manipulates AST.\n      // returns true if it also needs a runtime counterpart.\n      needRuntime = !!gen(el, dir, warn$3);\n    }\n    if (needRuntime) {\n      hasRuntime = true;\n      res += \"{name:\\\"\" + (dir.name) + \"\\\",rawName:\\\"\" + (dir.rawName) + \"\\\"\" + (dir.value ? (\",value:(\" + (dir.value) + \"),expression:\" + (JSON.stringify(dir.value))) : '') + (dir.arg ? (\",arg:\\\"\" + (dir.arg) + \"\\\"\") : '') + (dir.modifiers ? (\",modifiers:\" + (JSON.stringify(dir.modifiers))) : '') + \"},\";\n    }\n  }\n  if (hasRuntime) {\n    return res.slice(0, -1) + ']'\n  }\n}\n\nfunction genInlineTemplate (el) {\n  var ast = el.children[0];\n  if (\"development\" !== 'production' && (\n    el.children.length > 1 || ast.type !== 1\n  )) {\n    warn$3('Inline-template components must have exactly one child element.');\n  }\n  if (ast.type === 1) {\n    var inlineRenderFns = generate(ast, currentOptions);\n    return (\"inlineTemplate:{render:function(){\" + (inlineRenderFns.render) + \"},staticRenderFns:[\" + (inlineRenderFns.staticRenderFns.map(function (code) { return (\"function(){\" + code + \"}\"); }).join(',')) + \"]}\")\n  }\n}\n\nfunction genScopedSlots (slots) {\n  return (\"scopedSlots:_u([\" + (Object.keys(slots).map(function (key) { return genScopedSlot(key, slots[key]); }).join(',')) + \"])\")\n}\n\nfunction genScopedSlot (key, el) {\n  return \"[\" + key + \",function(\" + (String(el.attrsMap.scope)) + \"){\" +\n    \"return \" + (el.tag === 'template'\n      ? genChildren(el) || 'void 0'\n      : genElement(el)) + \"}]\"\n}\n\nfunction genChildren (el, checkSkip) {\n  var children = el.children;\n  if (children.length) {\n    var el$1 = children[0];\n    // optimize single v-for\n    if (children.length === 1 &&\n        el$1.for &&\n        el$1.tag !== 'template' &&\n        el$1.tag !== 'slot') {\n      return genElement(el$1)\n    }\n    var normalizationType = checkSkip ? getNormalizationType(children) : 0;\n    return (\"[\" + (children.map(genNode).join(',')) + \"]\" + (normalizationType ? (\",\" + normalizationType) : ''))\n  }\n}\n\n// determine the normalization needed for the children array.\n// 0: no normalization needed\n// 1: simple normalization needed (possible 1-level deep nested array)\n// 2: full normalization needed\nfunction getNormalizationType (children) {\n  var res = 0;\n  for (var i = 0; i < children.length; i++) {\n    var el = children[i];\n    if (el.type !== 1) {\n      continue\n    }\n    if (needsNormalization(el) ||\n        (el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {\n      res = 2;\n      break\n    }\n    if (maybeComponent(el) ||\n        (el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {\n      res = 1;\n    }\n  }\n  return res\n}\n\nfunction needsNormalization (el) {\n  return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'\n}\n\nfunction maybeComponent (el) {\n  return !isPlatformReservedTag$1(el.tag)\n}\n\nfunction genNode (node) {\n  if (node.type === 1) {\n    return genElement(node)\n  } else {\n    return genText(node)\n  }\n}\n\nfunction genText (text) {\n  return (\"_v(\" + (text.type === 2\n    ? text.expression // no need for () because already wrapped in _s()\n    : transformSpecialNewlines(JSON.stringify(text.text))) + \")\")\n}\n\nfunction genSlot (el) {\n  var slotName = el.slotName || '\"default\"';\n  var children = genChildren(el);\n  var res = \"_t(\" + slotName + (children ? (\",\" + children) : '');\n  var attrs = el.attrs && (\"{\" + (el.attrs.map(function (a) { return ((camelize(a.name)) + \":\" + (a.value)); }).join(',')) + \"}\");\n  var bind$$1 = el.attrsMap['v-bind'];\n  if ((attrs || bind$$1) && !children) {\n    res += \",null\";\n  }\n  if (attrs) {\n    res += \",\" + attrs;\n  }\n  if (bind$$1) {\n    res += (attrs ? '' : ',null') + \",\" + bind$$1;\n  }\n  return res + ')'\n}\n\n// componentName is el.component, take it as argument to shun flow's pessimistic refinement\nfunction genComponent (componentName, el) {\n  var children = el.inlineTemplate ? null : genChildren(el, true);\n  return (\"_c(\" + componentName + \",\" + (genData(el)) + (children ? (\",\" + children) : '') + \")\")\n}\n\nfunction genProps (props) {\n  var res = '';\n  for (var i = 0; i < props.length; i++) {\n    var prop = props[i];\n    res += \"\\\"\" + (prop.name) + \"\\\":\" + (transformSpecialNewlines(prop.value)) + \",\";\n  }\n  return res.slice(0, -1)\n}\n\n// #3895, #4268\nfunction transformSpecialNewlines (text) {\n  return text\n    .replace(/\\u2028/g, '\\\\u2028')\n    .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/*  */\n\n// these keywords should not appear inside expressions, but operators like\n// typeof, instanceof and in are allowed\nvar prohibitedKeywordRE = new RegExp('\\\\b' + (\n  'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +\n  'super,throw,while,yield,delete,export,import,return,switch,default,' +\n  'extends,finally,continue,debugger,function,arguments'\n).split(',').join('\\\\b|\\\\b') + '\\\\b');\n\n// these unary operators should not be used as property/method names\nvar unaryOperatorsRE = new RegExp('\\\\b' + (\n  'delete,typeof,void'\n).split(',').join('\\\\s*\\\\([^\\\\)]*\\\\)|\\\\b') + '\\\\s*\\\\([^\\\\)]*\\\\)');\n\n// check valid identifier for v-for\nvar identRE = /[A-Za-z_$][\\w$]*/;\n\n// strip strings in expressions\nvar stripStringRE = /'(?:[^'\\\\]|\\\\.)*'|\"(?:[^\"\\\\]|\\\\.)*\"|`(?:[^`\\\\]|\\\\.)*\\$\\{|\\}(?:[^`\\\\]|\\\\.)*`|`(?:[^`\\\\]|\\\\.)*`/g;\n\n// detect problematic expressions in a template\nfunction detectErrors (ast) {\n  var errors = [];\n  if (ast) {\n    checkNode(ast, errors);\n  }\n  return errors\n}\n\nfunction checkNode (node, errors) {\n  if (node.type === 1) {\n    for (var name in node.attrsMap) {\n      if (dirRE.test(name)) {\n        var value = node.attrsMap[name];\n        if (value) {\n          if (name === 'v-for') {\n            checkFor(node, (\"v-for=\\\"\" + value + \"\\\"\"), errors);\n          } else if (onRE.test(name)) {\n            checkEvent(value, (name + \"=\\\"\" + value + \"\\\"\"), errors);\n          } else {\n            checkExpression(value, (name + \"=\\\"\" + value + \"\\\"\"), errors);\n          }\n        }\n      }\n    }\n    if (node.children) {\n      for (var i = 0; i < node.children.length; i++) {\n        checkNode(node.children[i], errors);\n      }\n    }\n  } else if (node.type === 2) {\n    checkExpression(node.expression, node.text, errors);\n  }\n}\n\nfunction checkEvent (exp, text, errors) {\n  var stipped = exp.replace(stripStringRE, '');\n  var keywordMatch = stipped.match(unaryOperatorsRE);\n  if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {\n    errors.push(\n      \"avoid using JavaScript unary operator as property name: \" +\n      \"\\\"\" + (keywordMatch[0]) + \"\\\" in expression \" + (text.trim())\n    );\n  }\n  checkExpression(exp, text, errors);\n}\n\nfunction checkFor (node, text, errors) {\n  checkExpression(node.for || '', text, errors);\n  checkIdentifier(node.alias, 'v-for alias', text, errors);\n  checkIdentifier(node.iterator1, 'v-for iterator', text, errors);\n  checkIdentifier(node.iterator2, 'v-for iterator', text, errors);\n}\n\nfunction checkIdentifier (ident, type, text, errors) {\n  if (typeof ident === 'string' && !identRE.test(ident)) {\n    errors.push((\"invalid \" + type + \" \\\"\" + ident + \"\\\" in expression: \" + (text.trim())));\n  }\n}\n\nfunction checkExpression (exp, text, errors) {\n  try {\n    new Function((\"return \" + exp));\n  } catch (e) {\n    var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE);\n    if (keywordMatch) {\n      errors.push(\n        \"avoid using JavaScript keyword as property name: \" +\n        \"\\\"\" + (keywordMatch[0]) + \"\\\" in expression \" + (text.trim())\n      );\n    } else {\n      errors.push((\"invalid expression: \" + (text.trim())));\n    }\n  }\n}\n\n/*  */\n\nfunction baseCompile (\n  template,\n  options\n) {\n  var ast = parse(template.trim(), options);\n  optimize(ast, options);\n  var code = generate(ast, options);\n  return {\n    ast: ast,\n    render: code.render,\n    staticRenderFns: code.staticRenderFns\n  }\n}\n\nfunction makeFunction (code, errors) {\n  try {\n    return new Function(code)\n  } catch (err) {\n    errors.push({ err: err, code: code });\n    return noop\n  }\n}\n\nfunction createCompiler (baseOptions) {\n  var functionCompileCache = Object.create(null);\n\n  function compile (\n    template,\n    options\n  ) {\n    var finalOptions = Object.create(baseOptions);\n    var errors = [];\n    var tips = [];\n    finalOptions.warn = function (msg, tip$$1) {\n      (tip$$1 ? tips : errors).push(msg);\n    };\n\n    if (options) {\n      // merge custom modules\n      if (options.modules) {\n        finalOptions.modules = (baseOptions.modules || []).concat(options.modules);\n      }\n      // merge custom directives\n      if (options.directives) {\n        finalOptions.directives = extend(\n          Object.create(baseOptions.directives),\n          options.directives\n        );\n      }\n      // copy other options\n      for (var key in options) {\n        if (key !== 'modules' && key !== 'directives') {\n          finalOptions[key] = options[key];\n        }\n      }\n    }\n\n    var compiled = baseCompile(template, finalOptions);\n    {\n      errors.push.apply(errors, detectErrors(compiled.ast));\n    }\n    compiled.errors = errors;\n    compiled.tips = tips;\n    return compiled\n  }\n\n  function compileToFunctions (\n    template,\n    options,\n    vm\n  ) {\n    options = options || {};\n\n    /* istanbul ignore if */\n    {\n      // detect possible CSP restriction\n      try {\n        new Function('return 1');\n      } catch (e) {\n        if (e.toString().match(/unsafe-eval|CSP/)) {\n          warn(\n            'It seems you are using the standalone build of Vue.js in an ' +\n            'environment with Content Security Policy that prohibits unsafe-eval. ' +\n            'The template compiler cannot work in this environment. Consider ' +\n            'relaxing the policy to allow unsafe-eval or pre-compiling your ' +\n            'templates into render functions.'\n          );\n        }\n      }\n    }\n\n    // check cache\n    var key = options.delimiters\n      ? String(options.delimiters) + template\n      : template;\n    if (functionCompileCache[key]) {\n      return functionCompileCache[key]\n    }\n\n    // compile\n    var compiled = compile(template, options);\n\n    // check compilation errors/tips\n    {\n      if (compiled.errors && compiled.errors.length) {\n        warn(\n          \"Error compiling template:\\n\\n\" + template + \"\\n\\n\" +\n          compiled.errors.map(function (e) { return (\"- \" + e); }).join('\\n') + '\\n',\n          vm\n        );\n      }\n      if (compiled.tips && compiled.tips.length) {\n        compiled.tips.forEach(function (msg) { return tip(msg, vm); });\n      }\n    }\n\n    // turn code into functions\n    var res = {};\n    var fnGenErrors = [];\n    res.render = makeFunction(compiled.render, fnGenErrors);\n    var l = compiled.staticRenderFns.length;\n    res.staticRenderFns = new Array(l);\n    for (var i = 0; i < l; i++) {\n      res.staticRenderFns[i] = makeFunction(compiled.staticRenderFns[i], fnGenErrors);\n    }\n\n    // check function generation errors.\n    // this should only happen if there is a bug in the compiler itself.\n    // mostly for codegen development use\n    /* istanbul ignore if */\n    {\n      if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {\n        warn(\n          \"Failed to generate render function:\\n\\n\" +\n          fnGenErrors.map(function (ref) {\n            var err = ref.err;\n            var code = ref.code;\n\n            return ((err.toString()) + \" in\\n\\n\" + code + \"\\n\");\n        }).join('\\n'),\n          vm\n        );\n      }\n    }\n\n    return (functionCompileCache[key] = res)\n  }\n\n  return {\n    compile: compile,\n    compileToFunctions: compileToFunctions\n  }\n}\n\n/*  */\n\nfunction transformNode (el, options) {\n  var warn = options.warn || baseWarn;\n  var staticClass = getAndRemoveAttr(el, 'class');\n  if (\"development\" !== 'production' && staticClass) {\n    var expression = parseText(staticClass, options.delimiters);\n    if (expression) {\n      warn(\n        \"class=\\\"\" + staticClass + \"\\\": \" +\n        'Interpolation inside attributes has been removed. ' +\n        'Use v-bind or the colon shorthand instead. For example, ' +\n        'instead of <div class=\"{{ val }}\">, use <div :class=\"val\">.'\n      );\n    }\n  }\n  if (staticClass) {\n    el.staticClass = JSON.stringify(staticClass);\n  }\n  var classBinding = getBindingAttr(el, 'class', false /* getStatic */);\n  if (classBinding) {\n    el.classBinding = classBinding;\n  }\n}\n\nfunction genData$1 (el) {\n  var data = '';\n  if (el.staticClass) {\n    data += \"staticClass:\" + (el.staticClass) + \",\";\n  }\n  if (el.classBinding) {\n    data += \"class:\" + (el.classBinding) + \",\";\n  }\n  return data\n}\n\nvar klass$1 = {\n  staticKeys: ['staticClass'],\n  transformNode: transformNode,\n  genData: genData$1\n};\n\n/*  */\n\nfunction transformNode$1 (el, options) {\n  var warn = options.warn || baseWarn;\n  var staticStyle = getAndRemoveAttr(el, 'style');\n  if (staticStyle) {\n    /* istanbul ignore if */\n    {\n      var expression = parseText(staticStyle, options.delimiters);\n      if (expression) {\n        warn(\n          \"style=\\\"\" + staticStyle + \"\\\": \" +\n          'Interpolation inside attributes has been removed. ' +\n          'Use v-bind or the colon shorthand instead. For example, ' +\n          'instead of <div style=\"{{ val }}\">, use <div :style=\"val\">.'\n        );\n      }\n    }\n    el.staticStyle = JSON.stringify(parseStyleText(staticStyle));\n  }\n\n  var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);\n  if (styleBinding) {\n    el.styleBinding = styleBinding;\n  }\n}\n\nfunction genData$2 (el) {\n  var data = '';\n  if (el.staticStyle) {\n    data += \"staticStyle:\" + (el.staticStyle) + \",\";\n  }\n  if (el.styleBinding) {\n    data += \"style:(\" + (el.styleBinding) + \"),\";\n  }\n  return data\n}\n\nvar style$1 = {\n  staticKeys: ['staticStyle'],\n  transformNode: transformNode$1,\n  genData: genData$2\n};\n\nvar modules$1 = [\n  klass$1,\n  style$1\n];\n\n/*  */\n\nfunction text (el, dir) {\n  if (dir.value) {\n    addProp(el, 'textContent', (\"_s(\" + (dir.value) + \")\"));\n  }\n}\n\n/*  */\n\nfunction html (el, dir) {\n  if (dir.value) {\n    addProp(el, 'innerHTML', (\"_s(\" + (dir.value) + \")\"));\n  }\n}\n\nvar directives$1 = {\n  model: model,\n  text: text,\n  html: html\n};\n\n/*  */\n\nvar baseOptions = {\n  expectHTML: true,\n  modules: modules$1,\n  directives: directives$1,\n  isPreTag: isPreTag,\n  isUnaryTag: isUnaryTag,\n  mustUseProp: mustUseProp,\n  canBeLeftOpenTag: canBeLeftOpenTag,\n  isReservedTag: isReservedTag,\n  getTagNamespace: getTagNamespace,\n  staticKeys: genStaticKeys(modules$1)\n};\n\nvar ref$1 = createCompiler(baseOptions);\nvar compileToFunctions = ref$1.compileToFunctions;\n\n/*  */\n\nvar idToTemplate = cached(function (id) {\n  var el = query(id);\n  return el && el.innerHTML\n});\n\nvar mount = Vue$3.prototype.$mount;\nVue$3.prototype.$mount = function (\n  el,\n  hydrating\n) {\n  el = el && query(el);\n\n  /* istanbul ignore if */\n  if (el === document.body || el === document.documentElement) {\n    \"development\" !== 'production' && warn(\n      \"Do not mount Vue to <html> or <body> - mount to normal elements instead.\"\n    );\n    return this\n  }\n\n  var options = this.$options;\n  // resolve template/el and convert to render function\n  if (!options.render) {\n    var template = options.template;\n    if (template) {\n      if (typeof template === 'string') {\n        if (template.charAt(0) === '#') {\n          template = idToTemplate(template);\n          /* istanbul ignore if */\n          if (\"development\" !== 'production' && !template) {\n            warn(\n              (\"Template element not found or is empty: \" + (options.template)),\n              this\n            );\n          }\n        }\n      } else if (template.nodeType) {\n        template = template.innerHTML;\n      } else {\n        {\n          warn('invalid template option:' + template, this);\n        }\n        return this\n      }\n    } else if (el) {\n      template = getOuterHTML(el);\n    }\n    if (template) {\n      /* istanbul ignore if */\n      if (\"development\" !== 'production' && config.performance && mark) {\n        mark('compile');\n      }\n\n      var ref = compileToFunctions(template, {\n        shouldDecodeNewlines: shouldDecodeNewlines,\n        delimiters: options.delimiters\n      }, this);\n      var render = ref.render;\n      var staticRenderFns = ref.staticRenderFns;\n      options.render = render;\n      options.staticRenderFns = staticRenderFns;\n\n      /* istanbul ignore if */\n      if (\"development\" !== 'production' && config.performance && mark) {\n        mark('compile end');\n        measure(((this._name) + \" compile\"), 'compile', 'compile end');\n      }\n    }\n  }\n  return mount.call(this, el, hydrating)\n};\n\n/**\n * Get outerHTML of elements, taking care\n * of SVG elements in IE as well.\n */\nfunction getOuterHTML (el) {\n  if (el.outerHTML) {\n    return el.outerHTML\n  } else {\n    var container = document.createElement('div');\n    container.appendChild(el.cloneNode(true));\n    return container.innerHTML\n  }\n}\n\nVue$3.compile = compileToFunctions;\n\nreturn Vue$3;\n\n})));"
  },
  {
    "path": "docs/public/readme.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>可以使用的markdown — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"主标题\"><a href=\"#主标题\" class=\"headerlink\" title=\"主标题\"></a>主标题</h2><p>title 为标题<br>type 固定为guide宝宝埋的坑<br>order 为左侧导航排序，但是注意，假设0开始是基础的区域，100后是教程的区域，如果你想把文章放到基础区域，那么order必须小于100</p>\n<blockquote>\n<p>这是小提示框用法</p>\n</blockquote>\n<p><img src=\"https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/xLua.png\" alt=\"图片用法\"></p>\n<p>ps：markdown的图片不会调整大小所以如果要使用调整大小的图片应该用：</p>\n<p><img width=\"173\" height=\"57\" src=\"https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/xLua.png\"></p>\n<h3 id=\"子标题会被索引\"><a href=\"#子标题会被索引\" class=\"headerlink\" title=\"子标题会被索引\"></a>子标题会被索引</h3><p>正常的文本内容哈哈哈哈哈<br><code>这是高光内容</code>哈哈哈哈</p>\n<h3 id=\"子标题2\"><a href=\"#子标题2\" class=\"headerlink\" title=\"子标题2\"></a>子标题2</h3><p><a href=\"https://github.com/tencent/xlua\">超链接用法</a></p>\n<ul>\n<li>列表用法</li>\n<li>列表用法</li>\n<li>列表用法</li>\n<li>列表用法</li>\n<li>列表用法</li>\n</ul>\n<p><strong>加粗用法</strong></p>\n<p class=\"tip\">大提示框用法</p>\n\n<ol>\n<li>有序列表用法</li>\n<li>有序列表用法</li>\n<li>有序列表用法</li>\n</ol>\n<p>下面是分割线用法</p>\n<hr>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">这是代码块，支持的代码格式有：csharp ，lua，html, js, bash, css</div></pre></td></tr></table></figure>\n<p>下面是列表使用：</p>\n<table>\n<thead>\n<tr>\n<th>Helloworld</th>\n<th style=\"text-align:center\">Helloworld</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>Helloworld</code></td>\n<td style=\"text-align:center\">Helloworld</td>\n</tr>\n<tr>\n<td><code>Helloworld</code></td>\n<td style=\"text-align:center\">Helloworld</td>\n</tr>\n</tbody>\n</table>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/readme.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/api.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>C# API — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link current\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"C-API\"><a href=\"#C-API\" class=\"headerlink\" title=\"C# API\"></a>C# API</h2><blockquote>\n<p>Todo:请在此处输入内容</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/api.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/configure.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>XLua的配置 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link current\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"XLua的配置\"><a href=\"#XLua的配置\" class=\"headerlink\" title=\"XLua的配置\"></a>XLua的配置</h2><p>xLua所有的配置都支持三种方式：<code>打标签</code>, <code>静态列表</code>, <code>动态列表</code>。</p>\n<p>配置有两必须两建议：</p>\n<ul>\n<li>列表方式均必须是static的字段/属性</li>\n<li>列表方式均必须放到一个static类</li>\n<li>建议不用标签方式</li>\n<li>建议列表方式配置放Editor目录</li>\n</ul>\n<h3 id=\"打标签\"><a href=\"#打标签\" class=\"headerlink\" title=\"打标签\"></a>打标签</h3><p>xLua用白名单来指明生成哪些代码，而白名单通过attribute来配置，比如你想从lua调用c#的某个类，希望生成适配代码，你可以为这个类型打一个LuaCallCSharp标签：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">LuaCallCSharp</span>]</div><div class=\"line\">publicclassA</div><div class=\"line\">&#123;</div><div class=\"line\"></div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<p>该方式方便，但在il2cpp下会增加不少的代码量，不建议使用。</p>\n<h3 id=\"静态列表\"><a href=\"#静态列表\" class=\"headerlink\" title=\"静态列表\"></a>静态列表</h3><p>有时我们无法直接给一个类型打标签，比如系统api，没源码的库，或者实例化的泛化类型，这时你可以在一个静态类里声明一个静态字段，该字段的类型除BlackList和AdditionalProperties之外只要实现了IEnumerable&lt;Type&gt;就可以了（这两个例外后面具体会说），然后为这字段加上标签：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">LuaCallCSharp</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> List&lt;Type&gt; mymodule_lua_call_cs_list = <span class=\"keyword\">new</span> List&lt;Type&gt;()</div><div class=\"line\">&#123;</div><div class=\"line\">    <span class=\"keyword\">typeof</span>(GameObject),</div><div class=\"line\">    <span class=\"keyword\">typeof</span>(Dictionary&lt;<span class=\"keyword\">string</span>, <span class=\"keyword\">int</span>&gt;),</div><div class=\"line\">&#125;;</div></pre></td></tr></table></figure>\n<p>这个字段需要放到一个 <strong>静态类</strong> 里头，建议放到 <strong>Editor目录</strong> 。</p>\n<h3 id=\"动态列表\"><a href=\"#动态列表\" class=\"headerlink\" title=\"动态列表\"></a>动态列表</h3><p>声明一个静态属性，打上相应的标签即可。</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">Hotfix</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> List&lt;Type&gt; by_property</div><div class=\"line\">&#123;</div><div class=\"line\">    <span class=\"keyword\">get</span></div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">return</span> (<span class=\"keyword\">from</span> type <span class=\"keyword\">in</span> Assembly.GetExecutingAssembly().GetTypes()</div><div class=\"line\">                <span class=\"keyword\">where</span> type.Namespace == <span class=\"string\">\"XXXX\"</span></div><div class=\"line\">                <span class=\"keyword\">select</span> type).ToList();</div><div class=\"line\">    &#125;</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<p>Getter是代码，你可以实现很多效果，比如按名字空间配置，按程序集配置等等。</p>\n<p>这个属性需要放到一个 <strong>静态类</strong> 里头，建议放到 <strong>Editor目录</strong> 。</p>\n<h3 id=\"LuaCallCSharp\"><a href=\"#LuaCallCSharp\" class=\"headerlink\" title=\"LuaCallCSharp\"></a>LuaCallCSharp</h3><p>一个C#类型加了这个配置，xLua会生成这个类型的适配代码（包括构造该类型实例，访问其成员属性、方法，静态属性、方法），否则将会尝试用性能较低的反射方式来访问。</p>\n<p>一个类型的扩展方法（Extension Methods）加了这配置，也会生成适配代码并追加到被扩展类型的成员方法上。</p>\n<p>xLua只会生成加了该配置的类型，不会自动生成其父类的适配代码，当访问子类对象的父类方法，如果该父类加了LuaCallCSharp配置，则执行父类的适配代码，否则会尝试用反射来访问。</p>\n<p>反射访问除了性能不佳之外，在il2cpp下还有可能因为代码剪裁而导致无法访问，后者可以通过下面介绍的ReflectionUse标签来避免。</p>\n<h3 id=\"ReflectionUse\"><a href=\"#ReflectionUse\" class=\"headerlink\" title=\"ReflectionUse\"></a>ReflectionUse</h3><p>一个C#类型类型加了这个配置，xLua会生成link.xml阻止il2cpp的代码剪裁。</p>\n<p>对于扩展方法，必须加上LuaCallCSharp或者ReflectionUse才可以被访问到。</p>\n<p>建议所有要在Lua访问的类型，要么加LuaCallCSharp，要么加上ReflectionUse，这才能够保证在各平台都能正常运行。</p>\n<h3 id=\"CSharpCallLua\"><a href=\"#CSharpCallLua\" class=\"headerlink\" title=\"CSharpCallLua\"></a>CSharpCallLua</h3><p>如果希望把一个lua函数适配到一个C# delegate（一类是C#侧各种回调：UI事件，delegate参数，比如List&lt;T&gt;:ForEach；另外一类场景是通过LuaTable的Get函数指明一个lua函数绑定到一个delegate）。或者把一个lua table适配到一个C# interface，该delegate或者interface需要加上该配置。</p>\n<h3 id=\"GCOptimize\"><a href=\"#GCOptimize\" class=\"headerlink\" title=\"GCOptimize\"></a>GCOptimize</h3><p>一个C#纯值类型（注：指的是一个只包含值类型的struct，可以嵌套其它只包含值类型的struct）或者C#枚举值加上了这个配置。xLua会为该类型生成gc优化代码，效果是该值类型在lua和c#间传递不产生（C#）gc alloc，该类型的数组访问也不产生gc。各种无GC的场景，可以参考05_NoGc例子。</p>\n<p>除枚举之外，包含无参构造函数的复杂类型，都会生成lua table到该类型，以及改类型的一维数组的转换代码，这将会优化这个转换的性能，包括更少的gc alloc。</p>\n<h3 id=\"AdditionalProperties\"><a href=\"#AdditionalProperties\" class=\"headerlink\" title=\"AdditionalProperties\"></a>AdditionalProperties</h3><p>这个是GCOptimize的扩展配置，有的时候，一些struct喜欢把field做成是私有的，通过property来访问field，这时就需要用到该配置（默认情况下GCOptimize只对public的field打解包）。</p>\n<p>标签方式比较简单，配置方式复杂一点，要求是Dictionary&lt;Type, List&lt;string&gt;&gt;类型，Dictionary的Key是要生效的类型，Value是属性名列表。可以参考XLua对几个UnityEngine下值类型的配置，SysGCOptimize类。</p>\n<h3 id=\"BlackList\"><a href=\"#BlackList\" class=\"headerlink\" title=\"BlackList\"></a>BlackList</h3><p>如果你不要生成一个类型的一些成员的适配代码，你可以通过这个配置来实现。</p>\n<p>标签方式比较简单，对应的成员上加就可以了。</p>\n<p>由于考虑到有可能需要把重载函数的其中一个重载列入黑名单，配置方式比较复杂，类型是List&lt;List&lt;string&gt;&gt;，对于每个成员，在第一层List有一个条目，第二层List是个string的列表，第一个string是类型的全路径名，第二个string是成员名，如果成员是一个方法，还需要从第三个string开始，把其参数的类型全路径全列出来。</p>\n<p>例如下面是对GameObject的一个属性以及FileInfo的一个方法列入黑名单：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\"></div><div class=\"line\">[<span class=\"meta\">BlackList</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> List&lt;List&lt;<span class=\"keyword\">string</span>&gt;&gt; BlackList = <span class=\"keyword\">new</span> List&lt;List&lt;<span class=\"keyword\">string</span>&gt;&gt;()  &#123;</div><div class=\"line\">    <span class=\"keyword\">new</span> List&lt;<span class=\"keyword\">string</span>&gt;()&#123;<span class=\"string\">\"UnityEngine.GameObject\"</span>, <span class=\"string\">\"networkView\"</span>&#125;,</div><div class=\"line\">    <span class=\"keyword\">new</span> List&lt;<span class=\"keyword\">string</span>&gt;()&#123;<span class=\"string\">\"System.IO.FileInfo\"</span>, <span class=\"string\">\"GetAccessControl\"</span>, <span class=\"string\">\"System.Security.AccessControl.AccessControlSections\"</span>&#125;,</div><div class=\"line\">&#125;;</div></pre></td></tr></table></figure>\n<h3 id=\"下面是生成期配置，必须放到Editor目录下\"><a href=\"#下面是生成期配置，必须放到Editor目录下\" class=\"headerlink\" title=\"下面是生成期配置，必须放到Editor目录下\"></a>下面是生成期配置，必须放到Editor目录下</h3><p><strong>CSObjectWrapEditor.GenPath</strong></p>\n<p>配置生成代码的放置路径，类型是string。默认放在&quot;Assets/XLua/Gen/&quot;下。</p>\n<p><strong>CSObjectWrapEditor.GenCodeMenu</strong></p>\n<p>该配置用于生成引擎的二次开发，一个无参数函数加了这个标签，在执行&quot;XLua/Generate Code&quot;菜单时会触发这个函数的调用。</p>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/configure.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/crtdel-3rd.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>添加删除第三方库 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link current\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"添加删除第三方库\"><a href=\"#添加删除第三方库\" class=\"headerlink\" title=\"添加删除第三方库\"></a>添加删除第三方库</h2><blockquote>\n<p>Todo:请在此处输入内容</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/crtdel-3rd.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/faq.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>FAQ — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link current\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"FAQ\"><a href=\"#FAQ\" class=\"headerlink\" title=\"FAQ\"></a>FAQ</h2><h3 id=\"xLua发布包怎么用？\"><a href=\"#xLua发布包怎么用？\" class=\"headerlink\" title=\"xLua发布包怎么用？\"></a>xLua发布包怎么用？</h3><p>xLua目前以zip包形式发布，在工程目录下解压即可。</p>\n<h3 id=\"xLua可以放别的目录吗？\"><a href=\"#xLua可以放别的目录吗？\" class=\"headerlink\" title=\"xLua可以放别的目录吗？\"></a>xLua可以放别的目录吗？</h3><p>可以，但生成代码目录需要配置一下（默认放<code>Assets\\XLua\\Gen</code>目录），具体可以看《XLua的配置.doc》的GenPath配置介绍。</p>\n<h3 id=\"lua源码只能以txt后缀？\"><a href=\"#lua源码只能以txt后缀？\" class=\"headerlink\" title=\"lua源码只能以txt后缀？\"></a>lua源码只能以txt后缀？</h3><p>什么后缀都可以。</p>\n<p>如果你想以<code>TextAsset</code>打包到安装包（比如放到<code>Resources</code>目录），Unity不认<code>lua</code>后缀，这是Unity的规则。</p>\n<p>如果你不打包到安装包，就没有后缀的限制：比如自行下载到某个目录（这也是热更的正确姿势），然后通过CustomLoader或者设置package.path去读这个目录。</p>\n<p>那为啥xLua本身带的lua源码（包括示例）为什么都是txt结尾呢？因为xLua本身就一个库，不含下载功能，也不方便运行时去某个地方下载代码，通过TextAsset是较简单的方式。</p>\n<h3 id=\"Plugins源码在哪里可以找到，怎么使用？\"><a href=\"#Plugins源码在哪里可以找到，怎么使用？\" class=\"headerlink\" title=\"Plugins源码在哪里可以找到，怎么使用？\"></a>Plugins源码在哪里可以找到，怎么使用？</h3><p>Plugins源码位于<code>xLua_Project_Root/build</code>下。</p>\n<p>源码编译依赖cmake，安装cmake后执行make_xxxx_yyyy.zz即可，xxxx代表平台，比如ios，android等，yyyy是要集成的虚拟机，有lua53和luajit两者，zz是后缀，windows下是bat，其它平台是sh。</p>\n<p>windows编译依赖Visual Studio 2015。</p>\n<p>android编译在linux下执行，依赖NDK，并且需要把脚本中ANDROID_NDK指向NDK的安装目录。</p>\n<p>ios和osx需要在mac下编译。</p>\n<h3 id=\"报类似“xlua-access-no-field-Hitfix0-Update”的错误怎么解决？\"><a href=\"#报类似“xlua-access-no-field-Hitfix0-Update”的错误怎么解决？\" class=\"headerlink\" title=\"报类似“xlua.access, no field __Hitfix0_Update”的错误怎么解决？\"></a>报类似“xlua.access, no field __Hitfix0_Update”的错误怎么解决？</h3><p>按<a href=\"hotfix.html\">Hotfix操作指南</a>一步步操作。</p>\n<h3 id=\"报“please-install-the-Tools”\"><a href=\"#报“please-install-the-Tools”\" class=\"headerlink\" title=\"报“please install the Tools”\"></a>报“please install the Tools”</h3><p>没有把Tools安装到Assets平级目录，安装包，或者master下都能找到这个目录。</p>\n<h3 id=\"报“This-delegate-interface-must-add-to-CSharpCallLua-XXX”异常怎么解决？\"><a href=\"#报“This-delegate-interface-must-add-to-CSharpCallLua-XXX”异常怎么解决？\" class=\"headerlink\" title=\"报“This delegate/interface must add to CSharpCallLua : XXX”异常怎么解决？\"></a>报“This delegate/interface must add to CSharpCallLua : XXX”异常怎么解决？</h3><p>在编辑器下xLua不生成代码都可以运行，出现这种提示，要么是该类型没加CSharpCallLua，要么是加之前生成过代码，没重新执行生成。</p>\n<p>解决办法，确认XXX（类型名）加上CSharpCallLua后，清除代码后运行。</p>\n<h3 id=\"hotfix下怎么触发一个event\"><a href=\"#hotfix下怎么触发一个event\" class=\"headerlink\" title=\"hotfix下怎么触发一个event\"></a>hotfix下怎么触发一个event</h3><p>首先通过xlua.private_accessible开启私有成员访问。</p>\n<p>跟着通过对象的”&amp;事件名”字段调用delegate，例如self[‘&amp;MyEvent’]()，其中MyEvent是事件名。</p>\n<h3 id=\"怎么对Unity-Coroutine的实现函数打补丁？\"><a href=\"#怎么对Unity-Coroutine的实现函数打补丁？\" class=\"headerlink\" title=\"怎么对Unity Coroutine的实现函数打补丁？\"></a>怎么对Unity Coroutine的实现函数打补丁？</h3><p>见<a href=\"hotfix.html\">Hotfix操作指南</a>相应章节。</p>\n<h3 id=\"支持NGUI（或者UGUI-DOTween等等）么？\"><a href=\"#支持NGUI（或者UGUI-DOTween等等）么？\" class=\"headerlink\" title=\"支持NGUI（或者UGUI/DOTween等等）么？\"></a>支持NGUI（或者UGUI/DOTween等等）么？</h3><p>支持，xLua最主要的特性是让你原来用C#写的地方可以换成用lua写，你C#能用的插件，基本都能用。</p>\n<h3 id=\"如果需要调试，CustomLoader的filepath参数该如何处理？\"><a href=\"#如果需要调试，CustomLoader的filepath参数该如何处理？\" class=\"headerlink\" title=\"如果需要调试，CustomLoader的filepath参数该如何处理？\"></a>如果需要调试，CustomLoader的filepath参数该如何处理？</h3><p>lua里头调用require ‘a.b’时，CustomLoader会被调用，并传入字符串”a.b”，你需要理解这字符串，（从文件/内存/网络等）加载好lua文件，返回两个东西，第一个是调试器可以理解的路径，比如：a/b.lua，这个通过设置ref类型的filepath参数返回，第二个是UTF8格式的源码的字节流（byte[]），通过返回值返回。</p>\n<h3 id=\"什么是生成代码？\"><a href=\"#什么是生成代码？\" class=\"headerlink\" title=\"什么是生成代码？\"></a>什么是生成代码？</h3><p>xLua支持的lua和C#间交互技术之一，这种技术通过生成两者间的适配代码来实现交互，性能较好，是推荐的方式。</p>\n<p>另一种交互技术是反射，这种方式对安装包的影响更少，可以在性能要求不高或者对安装包大小很敏感的场景下使用。</p>\n<h3 id=\"改了接口后，之前生成的代码出现错误怎么办？\"><a href=\"#改了接口后，之前生成的代码出现错误怎么办？\" class=\"headerlink\" title=\"改了接口后，之前生成的代码出现错误怎么办？\"></a>改了接口后，之前生成的代码出现错误怎么办？</h3><p>清除掉生成代码（执行“Clear Generated Code”菜单，如果你重启过，会找不到这个菜单，这时你可以手动删除整个生成代码目录），等编译完成后重新生成。</p>\n<h3 id=\"应该什么时候生成代码？\"><a href=\"#应该什么时候生成代码？\" class=\"headerlink\" title=\"应该什么时候生成代码？\"></a>应该什么时候生成代码？</h3><p>开发期不建议生成代码，可以避免很多由于不一致导致的编译失败，以及生成代码本身的编译等待。</p>\n<p>build手机版本前必须执行生成代码，建议做成自动化的。</p>\n<p>做性能调优，性能测试前必须执行生成代码，因为生成和不生成性能的区别还是很大的。</p>\n<h3 id=\"CS名字空间下有所有C-API是不是很占内存？\"><a href=\"#CS名字空间下有所有C-API是不是很占内存？\" class=\"headerlink\" title=\"CS名字空间下有所有C# API是不是很占内存？\"></a>CS名字空间下有所有C# API是不是很占内存？</h3><p>由于用了lazyload，这个“有”只是个虚拟的概念，比如UnityEngine.GameObject，是访问第一次CS.UnityEngine.GameObject或者第一个实例往lua传送才加载该类型方法，属性等。</p>\n<h3 id=\"LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？\"><a href=\"#LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？\" class=\"headerlink\" title=\"LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？\"></a>LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？</h3><p>看调用者和被调用者，比如要在lua调用C#的GameObject.Find函数，或者调用gameobject的实例方法，属性等，GameObject类要加LuaCallSharp，而想把一个lua函数挂到UI回调，这是调用者是C#，被调用的是一个lua函数，所以回调声明的delegate要加CSharpCallLua。</p>\n<p>有时会比较迷惑人，比如<code>List&lt;int&gt;.Find(Predicate&lt;int&gt; match)</code>的调用，<code>List&lt;int&gt;</code>当然是加LuaCallSharp，而<code>Predicate&lt;int&gt;</code>却要加CSharpCallLua，因为match的调用者在C#，被调用的是一个lua函数。</p>\n<p>更无脑一点的方式是看到“This delegate/interface must add to CSharpCallLua : XXX”，就把XXX加到CSharpCallLua即可。</p>\n<h3 id=\"值类型传递会有gc-alloc么？\"><a href=\"#值类型传递会有gc-alloc么？\" class=\"headerlink\" title=\"值类型传递会有gc alloc么？\"></a>值类型传递会有gc alloc么？</h3><p>如果你使用的是delegate调用lua函数，或者用LuaTable、LuaFunction的无gc接口，或者数组的话，以下值类型都是没gc的：</p>\n<p>1、所有的基本值类型（所有整数，所有浮点数，decimal）；</p>\n<p>2、所有的枚举类型；</p>\n<p>3、字段只包含值类型的struct，可嵌套其它只包含值类型struct；</p>\n<p>其中2、3需要把该类型加到GCOptimize。</p>\n<h3 id=\"反射在ios下可用吗？\"><a href=\"#反射在ios下可用吗？\" class=\"headerlink\" title=\"反射在ios下可用吗？\"></a>反射在ios下可用吗？</h3><p>ios下的限制有两个：1、没有jit；2、代码剪裁（stripping）；</p>\n<p>对于C#通过delegate或者interface调用lua，如果不生成代码是用反射的emit，这依赖jit，所以这目前只在编辑器可用。</p>\n<p>对于lua调用C#，主要会被代码剪裁影响，这时你可以配置ReflectionUse（不要配LuaCallSharp），执行“Generate Code”，这时不会对该类生成封装代码，而是生成link.xml把该类配置为不剪裁。</p>\n<p>简而言之，除了CSharpCallLua是必须的（这类生成代码往往不多），LuaCallSharp生成都可以改为用反射。</p>\n<h3 id=\"支持泛化方法的调用么？\"><a href=\"#支持泛化方法的调用么？\" class=\"headerlink\" title=\"支持泛化方法的调用么？\"></a>支持泛化方法的调用么？</h3><p>不直接支持，但能调用到。如果是静态方法，可以自己写个封装来实例化泛化方法。</p>\n<p>如果是成员方法，xLua支持扩展方法，你可以添加一个扩展方法来实例化泛化方法。该扩展方法使用起来就和普通成员方法一样。</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"comment\">// C#</span></div><div class=\"line\"><span class=\"function\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> Button <span class=\"title\">GetButton</span>(<span class=\"params\"><span class=\"keyword\">this</span> GameObject go</span>)</span></div><div class=\"line\">&#123;</div><div class=\"line\">    <span class=\"keyword\">return</span> go.GetComponent&lt;Button&gt;();</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"comment\">-- lua</span></div><div class=\"line\"><span class=\"keyword\">local</span> go = CS.UnityEngine.GameObject.Find(<span class=\"string\">\"button\"</span>)</div><div class=\"line\">go:GetButton().onClick:AddListener(<span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">()</span></span></div><div class=\"line\">    <span class=\"built_in\">print</span>(<span class=\"string\">'onClick'</span>)</div><div class=\"line\"><span class=\"keyword\">end</span>)</div></pre></td></tr></table></figure>\n<h3 id=\"支持lua调用C-重载函数吗？\"><a href=\"#支持lua调用C-重载函数吗？\" class=\"headerlink\" title=\"支持lua调用C#重载函数吗？\"></a>支持lua调用C#重载函数吗？</h3><p>支持，但没有C#端支持的那么完善，比如重载方法void Foo(int a)和void Foo(short a)，由于int和short都对应lua的number，是没法根据参数判断调用的是哪个重载。这时你可以借助扩展方法来为其中一个起一个别名。</p>\n<h3 id=\"编辑器下运行正常，打包的时候生成代码报“没有某方法-属性-字段定义”怎么办？\"><a href=\"#编辑器下运行正常，打包的时候生成代码报“没有某方法-属性-字段定义”怎么办？\" class=\"headerlink\" title=\"编辑器下运行正常，打包的时候生成代码报“没有某方法/属性/字段定义”怎么办？\"></a>编辑器下运行正常，打包的时候生成代码报“没有某方法/属性/字段定义”怎么办？</h3><p>往往是由于该方法/属性/字段是扩在条件编译里头，只在UNITY_EDITOR下有效，这是可以通过把这方法/属性/字段加到黑名单来解决，加了之后要等编译完成后重新执行代码生成。</p>\n<h3 id=\"this-string-field-或者this-object-field-操作符重载为什么在lua无法访问？（比如Dictionary-lt-string-xxx-gt-Dictionary-lt-object-xxx-gt-在lua中无法通过dic-‘abc’-或者dic-abc检索值）\"><a href=\"#this-string-field-或者this-object-field-操作符重载为什么在lua无法访问？（比如Dictionary-lt-string-xxx-gt-Dictionary-lt-object-xxx-gt-在lua中无法通过dic-‘abc’-或者dic-abc检索值）\" class=\"headerlink\" title=\"this[string field]或者this[object field]操作符重载为什么在lua无法访问？（比如Dictionary&lt;string, xxx&gt;, Dictionary&lt;object, xxx&gt;在lua中无法通过dic[‘abc’]或者dic.abc检索值）\"></a>this[string field]或者this[object field]操作符重载为什么在lua无法访问？（比如<code>Dictionary&lt;string, xxx&gt;</code>, <code>Dictionary&lt;object, xxx&gt;</code>在lua中无法通过dic[‘abc’]或者dic.abc检索值）</h3><p>在2.1.5~2.1.6版本把这个特性去掉，因为：1、这个特性会导致基类定义的方法、属性、字段等无法访问（比如Animation无法访问到GetComponent方法）；2、key为当前类某方法、属性、字段的名字的数据无法检索，比如Dictionary类型，dic[‘TryGetValue’]返回的是一个函数，指向Dictionary的TryGetValue方法。</p>\n<p>建议直接方法该操作符的等效方法，比如Dictionary的TryGetValue，如果该方法没有提供，可以在C#那通过Extension method封装一个使用。</p>\n<h3 id=\"有的Unity对象，在C-为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject\"><a href=\"#有的Unity对象，在C-为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject\" class=\"headerlink\" title=\"有的Unity对象，在C#为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject\"></a>有的Unity对象，在C#为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject</h3><p>其实那C#对象并不为null，是UnityEngine.Object重载的==操作符，当一个对象被Destroy，未初始化等情况，obj == null返回true，但这C#对象并不为null，可以通过System.Object.ReferenceEquals(null, obj)来验证下。</p>\n<p>对应这种情况，可以为UnityEngine.Object写一个扩展方法：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">LuaCallCSharp</span>]</div><div class=\"line\">[<span class=\"meta\">ReflectionUse</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> <span class=\"keyword\">class</span> <span class=\"title\">UnityEngineObjectExtention</span></div><div class=\"line\">&#123;</div><div class=\"line\">    <span class=\"function\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> <span class=\"keyword\">bool</span> <span class=\"title\">IsNull</span>(<span class=\"params\"><span class=\"keyword\">this</span> UnityEngine.Object o</span>) <span class=\"comment\">// 或者名字叫IsDestroyed等等</span></span></div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">return</span> o == <span class=\"literal\">null</span>;</div><div class=\"line\">    &#125;</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<p>然后在lua那你对所有UnityEngine.Object实例都使用IsNull判断</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"built_in\">print</span>(go:GetComponent(<span class=\"string\">'Animator'</span>):IsNull())</div></pre></td></tr></table></figure>\n<h3 id=\"泛型实例怎么构造\"><a href=\"#泛型实例怎么构造\" class=\"headerlink\" title=\"泛型实例怎么构造\"></a>泛型实例怎么构造</h3><p>涉及的类型都在mscorlib，Assembly-CSharp程序集的话，泛型实例的构造和普通类型是一样的，都是CS.namespace.typename()，可能比较特殊的是typename的表达，泛型实例的typename的表达包含了标识符非法符号，最后一部分要换成[“typename”]，以<code>List&lt;string&gt;</code>为例</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"keyword\">local</span> lst = CS.System.Collections.Generic[<span class=\"string\">\"List`1[System.String]\"</span>]()</div></pre></td></tr></table></figure>\n<p>如果某个泛型实例的typename不确定，可以在C#测打印下typeof(不确定的类型).ToString()</p>\n<p>如果涉及mscorlib，Assembly-CSharp程序集之外的类型的话，可以用C#的反射来做：</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"keyword\">local</span> dic = CS.System.Activator.CreateInstance(CS.System.Type.GetType(<span class=\"string\">'System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UnityEngine.Vector3, UnityEngine]],mscorlib'</span>))</div><div class=\"line\">dic:Add(<span class=\"string\">'a'</span>, CS.UnityEngine.Vector3(<span class=\"number\">1</span>, <span class=\"number\">2</span>, <span class=\"number\">3</span>))</div><div class=\"line\"><span class=\"built_in\">print</span>(dic:TryGetValue(<span class=\"string\">'a'</span>))</div></pre></td></tr></table></figure>\n<h3 id=\"调用LuaEnv-Dispose时，报“try-to-dispose-a-LuaEnv-with-C-callback-”错是什么原因？\"><a href=\"#调用LuaEnv-Dispose时，报“try-to-dispose-a-LuaEnv-with-C-callback-”错是什么原因？\" class=\"headerlink\" title=\"调用LuaEnv.Dispose时，报“try to dispose a LuaEnv with C# callback!”错是什么原因？\"></a>调用LuaEnv.Dispose时，报“try to dispose a LuaEnv with C# callback!”错是什么原因？</h3><p>这是由于C#还存在指向lua虚拟机里头某个函数的delegate，为了防止业务在虚拟机释放后调用这些无效（因为其引用的lua函数所在虚拟机都释放了）delegate导致的异常甚至崩溃，做了这个检查。</p>\n<p>怎么解决？释放这些delegate即可，所谓释放，在C#中，就是没有引用：</p>\n<p>你是在C#通过LuaTable.Get获取并保存到对象成员，赋值该成员为null；</p>\n<p>你是在lua那把lua函数注册到一些事件事件回调，反注册这些回调；</p>\n<p>如果你是通过xlua.hotfix(class, method, func)注入到C#，则通过xlua.hotfix(class, method, nil)删除；</p>\n<p>要注意以上操作在Dispose之前完成。</p>\n<h3 id=\"C-参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int\"><a href=\"#C-参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int\" class=\"headerlink\" title=\"C#参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int\"></a>C#参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int</h3><p>看<a href=\"https://github.com/Tencent/xLua/blob/master/Assets/XLua/Examples/11_RawObject/RawObjectTest.cs\">例子11</a></p>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/faq.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/features.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>特性 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link current\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"特性\"><a href=\"#特性\" class=\"headerlink\" title=\"特性\"></a>特性</h2><h3 id=\"总体\"><a href=\"#总体\" class=\"headerlink\" title=\"总体\"></a>总体</h3><ul>\n<li><strong>Lua虚拟机支持</strong><ul>\n<li>Lua5.3.3</li>\n<li>Luajit2.1beta2<br><br></li>\n</ul>\n</li>\n<li><strong>Unity3D版本支持</strong><ul>\n<li>Unity5</li>\n<li>Unity4<br><br></li>\n</ul>\n</li>\n<li><strong>平台支持</strong><ul>\n<li>windows 64/32</li>\n<li>android</li>\n<li>ios 64/32/bitcode</li>\n<li>osx<br><br></li>\n</ul>\n</li>\n<li><strong>互访技术</strong><ul>\n<li>生成适配代码</li>\n<li>反射<br><br></li>\n</ul>\n</li>\n<li><strong>易用性</strong><ul>\n<li>解压即可用</li>\n<li>开发期无需生成代码</li>\n<li>生成代码和反射间可无缝切换</li>\n<li>更简单的无GC api</li>\n<li>菜单简单易懂</li>\n<li>配置可以多份，按模块划分，也可以直接在目标类型上打Attribute标签</li>\n<li>自动生成link.xml防止代码剪裁</li>\n<li>Plugins部分采用cmake编译，更简单</li>\n<li>核心代码不依赖生成代码，可以随时删除生成目录<br><br></li>\n</ul>\n</li>\n<li><strong>性能</strong><ul>\n<li>Lazyload技术，避免用不上的类型的开销</li>\n<li>lua函数映射到c# delegate，lua table映射到interface，可实现接口层面无C# gc alloc开销</li>\n<li>所有基本值类型，所有枚举，字段都是值类型的struct，在Lua和C#间传递无C# gc alloc</li>\n<li>LuaTable，LuaFunction提供无gc访问接口</li>\n<li>通过代码生成期的静态分析，生成最优代码</li>\n<li>支持C#和Lua间指针传递</li>\n<li>自动解除已经Destroy的UnityEngine.Object的引用<br><br></li>\n</ul>\n</li>\n<li><strong>扩展性</strong><ul>\n<li>不用改代码就可以加入Lua第三方扩展</li>\n<li>生成引擎提供接口做二次开发</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"支持为如下C-实现打补丁\"><a href=\"#支持为如下C-实现打补丁\" class=\"headerlink\" title=\"支持为如下C#实现打补丁\"></a>支持为如下C#实现打补丁</h3><ul>\n<li>构造函数</li>\n<li>析构函数</li>\n<li>成员函数</li>\n<li>静态函数</li>\n<li>泛化函数</li>\n<li>操作符重载</li>\n<li>成员属性</li>\n<li>静态属性</li>\n<li>事件</li>\n</ul>\n<h3 id=\"Lua代码加载\"><a href=\"#Lua代码加载\" class=\"headerlink\" title=\"Lua代码加载\"></a>Lua代码加载</h3><ul>\n<li><strong>加载字符串</strong><ul>\n<li>支持加载后立即执行</li>\n<li>支持加载后返回一个delegate或者LuaFunction，调用delegate或者LuaFunction后可传脚本参数<br><br></li>\n</ul>\n</li>\n<li><strong>Resources目录的文件</strong><ul>\n<li>直接require<br><br></li>\n</ul>\n</li>\n<li><strong>自定义loader</strong><ul>\n<li>Lua里头require时触发</li>\n<li>require参数透传给loader，loader读取Lua代码返回<br><br></li>\n</ul>\n</li>\n<li><strong>Lua原有的方式</strong><ul>\n<li>Lua原有的方式都保留</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"Lua调用C\"><a href=\"#Lua调用C\" class=\"headerlink\" title=\"Lua调用C\"></a>Lua调用C</h3><ul>\n<li>创建C#对象</li>\n<li>C#静态属性，字段</li>\n<li>C#静态方法</li>\n<li>C#成员属性，字段</li>\n<li>C#成员方法<br><br></li>\n<li><strong>C#继承</strong><ul>\n<li>子类对象可以直接调用父类的方法，访问父类属性</li>\n<li>子类模块可以直接调用父类的静态方法，静态属性<br><br></li>\n</ul>\n</li>\n<li><strong>扩展方法（Extension methods）</strong><ul>\n<li>就像普通成员方法一样使用<br><br></li>\n</ul>\n</li>\n<li><strong>参数的输入输出属性（out，ref）</strong><ul>\n<li>out对应一个lua返回值</li>\n<li>ref对应一个lua参数以及一个lua返回值<br><br></li>\n</ul>\n</li>\n<li><strong>函数重载</strong><ul>\n<li>支持重载</li>\n<li>由于lua数据类型远比C#要少，会出现无法判断的情况，可通过扩展方法来来调用。<br><br></li>\n</ul>\n</li>\n<li><strong>操作符重载</strong><ul>\n<li>支持的操作符：+，-，*，/，==，一元-，&lt;，&lt;=， %，[]</li>\n<li>其它操作符可以借助扩展方法调用<br><br></li>\n</ul>\n</li>\n<li><strong>参数默认值</strong><ul>\n<li>C#参数有默认值，在lua可以不传<br><br></li>\n</ul>\n</li>\n<li><strong>可变参数</strong><ul>\n<li>在对应可变参数部分，直接输入一个个参数即可，不需要把这些参数扩到一个数组里头<br><br></li>\n</ul>\n</li>\n<li><strong>泛化方法调用</strong><ul>\n<li>静态方法可以自行封装使用</li>\n<li>成员函数可通过扩展方法封装使用<br><br></li>\n</ul>\n</li>\n<li><strong>枚举类型</strong><ul>\n<li>数字或字符串到枚举的转换<br><br></li>\n</ul>\n</li>\n<li><strong>delegate</strong><ul>\n<li>调用一个C# delegate</li>\n<li>+操作符</li>\n<li>-操作符</li>\n<li>把一个lua函数作为一个c# delegate传递给c#<br><br></li>\n</ul>\n</li>\n<li><strong>event</strong><ul>\n<li>增加事件回调</li>\n<li>移除事件回调<br><br></li>\n</ul>\n</li>\n<li><strong>64位整数</strong><ul>\n<li>传递无gc而且无精度损失</li>\n<li>lua53下使用原生64位支持</li>\n<li>可以和number运算</li>\n<li>以java的方式支持无符号64位整数<br><br></li>\n</ul>\n</li>\n<li><strong>table的自动转换到C#复杂类型</strong><ul>\n<li>obj.complexField = {a = 1, b = {c = 1}}，obj是一个C#对象，complexField是两层嵌套的struct或者class<br><br></li>\n</ul>\n</li>\n<li><strong>typeof</strong><ul>\n<li>对应C#的typeof操作符，返回Type对象<br><br></li>\n</ul>\n</li>\n<li>lua侧直接clone<br><br></li>\n<li><strong>decimal</strong><ul>\n<li>传递无gc而且无精度损失</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"C-调用Lua\"><a href=\"#C-调用Lua\" class=\"headerlink\" title=\"C#调用Lua\"></a>C#调用Lua</h3><ul>\n<li><strong>调用Lua函数</strong><ul>\n<li>以delegate方式调用Lua函数</li>\n<li>以LuaFunction调用lua函数<br><br></li>\n</ul>\n</li>\n<li><strong>访问Lua的table</strong><ul>\n<li>LuaTable的泛化Get/Set接口，调用无gc，可指明Key，Value的类型</li>\n<li>用标注了CSharpCallLua的interface访问</li>\n<li>值拷贝到struct，class</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"Lua虚拟机\"><a href=\"#Lua虚拟机\" class=\"headerlink\" title=\"Lua虚拟机\"></a>Lua虚拟机</h3><ul>\n<li>虚拟机gc参数读取及设置</li>\n</ul>\n<h3 id=\"工具链\"><a href=\"#工具链\" class=\"headerlink\" title=\"工具链\"></a>工具链</h3><ul>\n<li><strong>Lua Profiler</strong><ul>\n<li>可根据函数调用总时长，平均每次调用时长，调用次数排序</li>\n<li>显示lua函数名及其所在文件的名字及行号</li>\n<li>如果C#函数，会显示这个是C#函数<br><br></li>\n</ul>\n</li>\n<li>支持真机调试</li>\n</ul>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/features.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/gc-optimization.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>GC优化指南 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link current\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"GC优化指南\"><a href=\"#GC优化指南\" class=\"headerlink\" title=\"GC优化指南\"></a>GC优化指南</h2><blockquote>\n<p>Todo:请在此处输入内容</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/gc-optimization.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/hotfix.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>热标识 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link current\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"热标识\"><a href=\"#热标识\" class=\"headerlink\" title=\"热标识\"></a>热标识</h2><h3 id=\"使用方式\"><a href=\"#使用方式\" class=\"headerlink\" title=\"使用方式\"></a>使用方式</h3><p>1、添加HOTFIX_ENABLE宏打开该特性（在Unity3D的File-&gt;Build Setting-&gt;Scripting Define Symbols下添加）。编辑器、各手机平台这个宏要分别设置！如果是自动化打包，要注意在代码里头用API设置的宏是不生效的，需要在编辑器设置。</p>\n<p>（建议平时开发业务代码不打开HOTFIX_ENABLE，只在build手机版本或者要在编译器下开发补丁时打开HOTFIX_ENABLE）</p>\n<p>2、执行XLua/Generate Code菜单。</p>\n<p>3、注入，构建手机包这个步骤会在构建时自动进行，编辑器下开发补丁需要手动执行”XLua/Hotfix Inject In Editor”菜单。注入成功会打印“hotfix inject finish!”或者“had injected!”。</p>\n<h3 id=\"内嵌模式\"><a href=\"#内嵌模式\" class=\"headerlink\" title=\"内嵌模式\"></a>内嵌模式</h3><p>默认通过小工具执行代码注入，也可以采用内嵌到编辑器的方式，定义INJECT_WITHOUT_TOOL宏即可。</p>\n<p>定义INJECT_WITHOUT_TOOL宏后，热补丁特性依赖Cecil，添加HOTFIX_ENABLE宏之后，可能会报找不到Cecil。这时你需要到Unity安装目录下找到Mono.Cecil.dll，Mono.Cecil.Pdb.dll，Mono.Cecil.Mdb.dll，拷贝到项目里头。</p>\n<p>注意：如果你的Unity安装目录没有Mono.Cecil.Pdb.dll，Mono.Cecil.Mdb.dll（往往是一些老版本），那就只拷贝Mono.Cecil.dll（你从别的版本的Unity拷贝一套可能会导致编辑器不稳定），这时你需要定义HOTFIX_SYMBOLS_DISABLE，这会导致C#代码没法调试以及Log的栈源文件及行号错乱（所以赶紧升级Unity）。</p>\n<p>参考命令（可能Unity版本不同会略有不同）：</p>\n<figure class=\"highlight shell\"><table><tr><td class=\"code\"><pre><div class=\"line\">OSX命令行 cp /Applications/Unity/Unity.app/Contents/Managed/Mono.Cecil.* Project/Assets/XLua/Src/Editor/</div><div class=\"line\">Win命令行 copy UnityPath\\Editor\\Data\\Managed\\Mono.Cecil.* Project\\Assets\\XLua\\Src\\Editor\\</div></pre></td></tr></table></figure>\n<h3 id=\"约束\"><a href=\"#约束\" class=\"headerlink\" title=\"约束\"></a>约束</h3><p>不支持静态构造函数。</p>\n<p>不支持在子类override函数通过base调用父类实现。</p>\n<p>目前只支持Assets下代码的热补丁，不支持引擎，c#系统库的热补丁。</p>\n<h3 id=\"API\"><a href=\"#API\" class=\"headerlink\" title=\"API\"></a>API</h3><p>xlua.hotfix(class, [method_name], fix)</p>\n<ul>\n<li>描述         ： 注入lua补丁</li>\n<li>class        ： C#类，两种表示方法，CS.Namespace.TypeName或者字符串方式”Namespace.TypeName”，字符串格式和C#的Type.GetType要求一致，如果是内嵌类型（Nested Type）是非Public类型的话，只能用字符串方式表示”Namespace.TypeName+NestedTypeName”；</li>\n<li>method_name  ： 方法名，可选；</li>\n<li>fix          ： 如果传了method_name，fix将会是一个function，否则通过table提供一组函数。table的组织按key是method_name，value是function的方式。</li>\n</ul>\n<p>xlua.private_accessible(class)</p>\n<ul>\n<li>描述          ： 让一个类的私有字段，属性，方法等可用</li>\n<li>class         ： 同xlua.hotfix的class参数</li>\n</ul>\n<h3 id=\"标识要热更新的类型\"><a href=\"#标识要热更新的类型\" class=\"headerlink\" title=\"标识要热更新的类型\"></a>标识要热更新的类型</h3><p>和其它配置一样，有两种方式</p>\n<p>方式一：直接在类里头打Hotfix标签；</p>\n<p>方式二：在一个static类的static字段或者属性里头配置一个列表。属性可以用于实现的比较复杂的配置，比如根据Namespace做白名单。</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">static</span> <span class=\"keyword\">class</span> <span class=\"title\">HotfixCfg</span></div><div class=\"line\">&#123;</div><div class=\"line\">    [<span class=\"meta\">Hotfix</span>]</div><div class=\"line\">    <span class=\"keyword\">public</span> <span class=\"keyword\">static</span> List&lt;Type&gt; by_field = <span class=\"keyword\">new</span> List&lt;Type&gt;()</div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">typeof</span>(HotFixSubClass),</div><div class=\"line\">        <span class=\"keyword\">typeof</span>(GenericClass&lt;&gt;),</div><div class=\"line\">    &#125;;</div><div class=\"line\"></div><div class=\"line\">    [<span class=\"meta\">Hotfix</span>]</div><div class=\"line\">    <span class=\"keyword\">public</span> <span class=\"keyword\">static</span> List&lt;Type&gt; by_property</div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">get</span></div><div class=\"line\">        &#123;</div><div class=\"line\">            <span class=\"keyword\">return</span> (<span class=\"keyword\">from</span> type <span class=\"keyword\">in</span> Assembly.Load(<span class=\"string\">\"Assembly-CSharp\"</span>).GetTypes()</div><div class=\"line\">                    <span class=\"keyword\">where</span> type.Namespace == <span class=\"string\">\"XXXX\"</span></div><div class=\"line\">                    <span class=\"keyword\">select</span> type).ToList();</div><div class=\"line\">        &#125;</div><div class=\"line\">    &#125;</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<h3 id=\"Hotfix-Flag\"><a href=\"#Hotfix-Flag\" class=\"headerlink\" title=\"Hotfix Flag\"></a>Hotfix Flag</h3><p>Hotfix标签可以设置一些标志位对生成代码及插桩定制化</p>\n<ul>\n<li>Stateless</li>\n</ul>\n<p>Stateless和Stateful的区别请看下下节。</p>\n<ul>\n<li>Stateful</li>\n</ul>\n<p>同上。</p>\n<ul>\n<li>ValueTypeBoxing</li>\n</ul>\n<p>值类型的适配delegate会收敛到object，好处是代码量更少，不好的是值类型会产生boxing及gc，适用于对text段敏感的业务。</p>\n<ul>\n<li>IgnoreProperty</li>\n</ul>\n<p>不对属性注入及生成适配代码，一般而言，大多数属性的实现都很简单，出错几率比较小，建议不注入。</p>\n<ul>\n<li>IgnoreNotPublic</li>\n</ul>\n<p>不对非public的方法注入及生成适配代码。除了像MonoBehaviour那种会被反射调用的私有方法必须得注入，其它仅被本类调用的非public方法可以不注入，只不过修复时会工作量稍大，所有引用到这个函数的public方法都要重写。</p>\n<ul>\n<li>Inline</li>\n</ul>\n<p>不生成适配delegate，直接在函数体注入处理代码。</p>\n<ul>\n<li>IntKey</li>\n</ul>\n<p>不生成静态字段，而是把所有注入点放到一个数组集中管理。</p>\n<p>好处：对text段影响小。</p>\n<p>坏处：使用不像默认方式那么方便，需要通过id来指明hotfix哪个函数，而这个id是代码注入工具时分配的，函数到id的映射会保存在Gen/Resources/hotfix_id_map.lua.txt，并且自动加时间戳备份到hotfix_id_map.lua.txt同级目录，发布手机版本后请妥善保存该文件。</p>\n<p>该文件的格式大概如下：</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"keyword\">return</span> &#123;</div><div class=\"line\">    [<span class=\"string\">\"HotfixTest\"</span>] = &#123;</div><div class=\"line\">        [<span class=\"string\">\".ctor\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">5</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">        [<span class=\"string\">\"Start\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">6</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">        [<span class=\"string\">\"Update\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">7</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">        [<span class=\"string\">\"FixedUpdate\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">8</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">        [<span class=\"string\">\"Add\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">9</span>,<span class=\"number\">10</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">        [<span class=\"string\">\"OnGUI\"</span>] = &#123;</div><div class=\"line\">            <span class=\"number\">11</span></div><div class=\"line\">        &#125;,</div><div class=\"line\">    &#125;,</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<p>想要替换HotfixTest的Update函数，你得</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\">CS.XLua.HotfixDelegateBridge.Set(<span class=\"number\">7</span>, func)</div></pre></td></tr></table></figure>\n<p>如果是重载函数，将会一个函数名对应多个id，比如上面的Add函数。</p>\n<p>能不能自动化一些呢？可以，xlua.util提供了auto_id_map函数，执行一次后你就可以像以前那样直接用类，方法名去指明修补的函数。</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\">(<span class=\"built_in\">require</span> <span class=\"string\">'xlua.util'</span>).auto_id_map()</div><div class=\"line\">xlua.hotfix(CS.HotfixTest, <span class=\"string\">'Update'</span>, <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self)</span></span></div><div class=\"line\">\t\tself.tick = self.tick + <span class=\"number\">1</span></div><div class=\"line\">\t\t<span class=\"keyword\">if</span> (self.tick % <span class=\"number\">50</span>) == <span class=\"number\">0</span> <span class=\"keyword\">then</span></div><div class=\"line\">\t\t\t<span class=\"built_in\">print</span>(<span class=\"string\">'&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;Update in lua, tick = '</span> .. self.tick)</div><div class=\"line\">\t\t<span class=\"keyword\">end</span></div><div class=\"line\">\t<span class=\"keyword\">end</span>)</div></pre></td></tr></table></figure>\n<p>前提是hotfix_id_map.lua.txt放到可以通过require ‘hotfix_id_map’引用到的地方。</p>\n<p>ps：虽然xlua执行代码注入时会把hotfix_id_map.lua.txt放到Resources下，但那时似乎Unity已经不再处理新增的文件。貌似可以通过提前执行“Hotfix inject in Editor”来提前生成，但id不一定一样，比如有的类型里头有平台/编辑器专用的api，编辑器下和真机下的id将不一样。</p>\n<h3 id=\"使用建议\"><a href=\"#使用建议\" class=\"headerlink\" title=\"使用建议\"></a>使用建议</h3><ul>\n<li>对所有较大可能变动的类型加上Hotfix标识；</li>\n<li>建议用反射找出所有函数参数、字段、属性、事件涉及的delegate类型，标注CSharpCallLua；</li>\n<li>业务代码、引擎API、系统API，需要在Lua补丁里头高性能访问的类型，加上LuaCallCSharp；</li>\n<li>引擎API、系统API可能被代码剪裁调（C#无引用的地方都会被剪裁），如果觉得可能会新增C#代码之外的API调用，这些API所在的类型要么加LuaCallCSharp，要么加ReflectionUse；</li>\n</ul>\n<h3 id=\"Stateless和Stateful\"><a href=\"#Stateless和Stateful\" class=\"headerlink\" title=\"Stateless和Stateful\"></a>Stateless和Stateful</h3><p>打Hotfix标签时，默认是Stateless方式，你也可以选Stateful方式，我们先说区别，再说使用场景。</p>\n<p>Stateless方式是指用Lua对成员函数修复时，C#对象直接透传给作为Lua函数的第一个参数。</p>\n<p>Stateful方式下你可以在Lua的构造函数返回一个table，然后后续成员函数调用会把这个table给传递过去。</p>\n<p>Stateless比较适合无状态的类，有状态的话，你得通过反射去操作私有成员，也没法新增状态（field）。Stateless有个好处，可以运行的任意时刻执行替换。</p>\n<p>Stateful的代价是会在类增加一个LuaTable类型的字段（中间层面增加，不会改源代码）。但这种方式是适用性更广，比如你不想要lua状态，可以在构造函数拦截那返回空。而且操作状态性能比反射操作C#私有变量要好，也可以随意新增任意的状态信息。缺点是，执行成员函数之前就new好的对象，接收到的状态会是空，所以需要重启，在一开始就执行替换。</p>\n<h3 id=\"打补丁\"><a href=\"#打补丁\" class=\"headerlink\" title=\"打补丁\"></a>打补丁</h3><p>xlua可以用lua函数替换C#的构造函数，函数，属性，事件的替换。lua实现都是函数，比如属性对于一个getter函数和一个setter函数，事件对应一个add函数和一个remove函数。</p>\n<ul>\n<li>函数</li>\n</ul>\n<p>method_name传函数名，支持重载，不同重载都是转发到同一个lua函数。</p>\n<p>比如：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\"></div><div class=\"line\"><span class=\"comment\">// 要fix的C#类</span></div><div class=\"line\">[<span class=\"meta\">Hotfix</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">class</span> <span class=\"title\">HotfixCalc</span></div><div class=\"line\">&#123;</div><div class=\"line\">    <span class=\"function\"><span class=\"keyword\">public</span> <span class=\"keyword\">int</span> <span class=\"title\">Add</span>(<span class=\"params\"><span class=\"keyword\">int</span> a, <span class=\"keyword\">int</span> b</span>)</span></div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">return</span> a - b;</div><div class=\"line\">    &#125;</div><div class=\"line\"></div><div class=\"line\">    <span class=\"function\"><span class=\"keyword\">public</span> Vector3 <span class=\"title\">Add</span>(<span class=\"params\">Vector3 a, Vector3 b</span>)</span></div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">return</span> a - b;</div><div class=\"line\">    &#125;</div><div class=\"line\">｝</div></pre></td></tr></table></figure>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"></div><div class=\"line\">xlua.hotfix(CS.HotfixCalc, <span class=\"string\">'Add'</span>, <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, a, b)</span></span></div><div class=\"line\">    <span class=\"keyword\">return</span> a + b</div><div class=\"line\"><span class=\"keyword\">end</span>)</div></pre></td></tr></table></figure>\n<p>静态函数和成员函数的区别是，成员函数会加一个self参数，这个self在Stateless方式下是C#对象本身（对应C#的this），Stateful方式下传lua构造函数实现的返回值（一个table或者nil）</p>\n<p>普通参数对于lua的参数，ref参数对应lua的一个参数和一个返回值，out参数对于lua的一个返回值。</p>\n<p>泛化函数的打补丁规则和普通函数一样。</p>\n<ul>\n<li>构造函数</li>\n</ul>\n<p>构造函数对应的method_name是<code>.ctor</code>。</p>\n<p>如果是Stateful方式，你可以返回一个table作为这个对象的状态。</p>\n<p>和普通函数不一样的是，构造函数的热补丁并不是替换，而是执行原有逻辑后调用lua。</p>\n<ul>\n<li>属性</li>\n</ul>\n<p>对于名为“AProp”的属性，会对应一个getter，method_name等于get_AProp，setter的method_name等于set_AProp。</p>\n<ul>\n<li>[]操作符</li>\n</ul>\n<p>赋值对应set_Item，取值对应get_Item。第一个参数是self，赋值后面跟key，value，取值只有key参数，返回值是取出的值。</p>\n<ul>\n<li>其它操作符</li>\n</ul>\n<p>C#的操作符都有一套内部表示，比如+号的操作符函数名是op_Addition（其它操作符的内部表示可以去请参照相关资料），覆盖这函数就覆盖了C#的+号操作符。</p>\n<ul>\n<li>事件</li>\n</ul>\n<p>比如对于事件“AEvent”，+=操作符是add_AEvent，-=对应的是remove_AEvent。这两个函数均是第一个参数是self，第二个参数是操作符后面跟的delegate。</p>\n<p>通过xlua.private_accessible来直接访问事件对应的私有delegate的直接访问后，可以通过对象的”&amp;事件名”字段直接触发事件，例如self[‘&amp;MyEvent’]()，其中MyEvent是事件名。</p>\n<ul>\n<li>析构函数</li>\n</ul>\n<p>method_name是”Finalize”，传一个self参数。</p>\n<p>和普通函数不一样的是，析构函数的热补丁并不是替换，而是开头调用lua函数后继续原有逻辑。</p>\n<ul>\n<li>泛化类型</li>\n</ul>\n<p>其它规则一致，需要说明的是，每个泛化类型实例化后都是一个独立的类型，只能针对实例化后的类型分别打补丁。比如：</p>\n<figure class=\"highlight\"><table><tr><td class=\"code\"><pre><div class=\"line\">public class GenericClass&lt;T&gt;</div><div class=\"line\">&#123;</div><div class=\"line\">｝</div></pre></td></tr></table></figure>\n<p>你只能对GenericClass<code>&lt;double&gt;</code>，GenericClass<code>&lt;int&gt;</code>这些类，而不是对GenericClass打补丁。</p>\n<p>另外值得一提的是，要注意泛化类型的命名方式，比如GenericClass<code>&lt;double&gt;</code>的命名是GenericClass`1[System.Double]，具体可以看<a href=\"https://msdn.microsoft.com/en-us/library/w3f99sx1.aspx\" target=\"_blank\" rel=\"external\">MSDN</a>。</p>\n<p>对GenericClass<code>&lt;double&gt;</code>打补丁的实例如下：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">luaenv.DoString(<span class=\"string\">@\"</span></div><div class=\"line\">    xlua.hotfix(CS['GenericClass`1[System.Double]'], &#123;</div><div class=\"line\">        ['.ctor'] = function(obj, a)</div><div class=\"line\">            print('GenericClass&lt;double&gt;', obj, a)</div><div class=\"line\">        end;</div><div class=\"line\">        Func1 = function(obj)</div><div class=\"line\">            print('GenericClass&lt;double&gt;.Func1', obj)</div><div class=\"line\">        end;</div><div class=\"line\">        Func2 = function(obj)</div><div class=\"line\">            print('GenericClass&lt;double&gt;.Func2', obj)</div><div class=\"line\">            return 1314</div><div class=\"line\">        end</div><div class=\"line\">    &#125;)</div><div class=\"line\">\");</div></pre></td></tr></table></figure>\n<ul>\n<li>Unity协程</li>\n</ul>\n<p>通过util.cs_generator可以用一个function模拟一个IEnumerator，在里头用coroutine.yield，就类似C#里头的yield return。比如下面的C#代码和对应的hotfix代码是等同效果的</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">XLua.Hotfix</span>]</div><div class=\"line\"><span class=\"keyword\">public</span> <span class=\"keyword\">class</span> <span class=\"title\">HotFixSubClass</span> : <span class=\"title\">MonoBehaviour</span> &#123;</div><div class=\"line\">    <span class=\"function\">IEnumerator <span class=\"title\">Start</span>(<span class=\"params\"></span>)</span></div><div class=\"line\">    &#123;</div><div class=\"line\">        <span class=\"keyword\">while</span> (<span class=\"literal\">true</span>)</div><div class=\"line\">        &#123;</div><div class=\"line\">            <span class=\"function\"><span class=\"keyword\">yield</span> return new <span class=\"title\">WaitForSeconds</span>(<span class=\"params\"><span class=\"number\">3</span></span>)</span>;</div><div class=\"line\">            Debug.Log(<span class=\"string\">\"Wait for 3 seconds\"</span>);</div><div class=\"line\">        &#125;</div><div class=\"line\">    &#125;</div><div class=\"line\">&#125;</div></pre></td></tr></table></figure>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">luaenv.DoString(<span class=\"string\">@\"</span></div><div class=\"line\">    local util = require 'xlua.util'</div><div class=\"line\">\txlua.hotfix(CS.HotFixSubClass,&#123;</div><div class=\"line\">\t\tStart = function(self)</div><div class=\"line\">\t\t\treturn util.cs_generator(function()</div><div class=\"line\">\t\t\t    while true do</div><div class=\"line\">\t\t\t\t    coroutine.yield(CS.UnityEngine.WaitForSeconds(3))</div><div class=\"line\">                    print('Wait for 3 seconds')</div><div class=\"line\">                end\t\t\t\t</div><div class=\"line\">\t\t\tend</div><div class=\"line\">\t\tend;</div><div class=\"line\">\t&#125;)</div><div class=\"line\">\");</div></pre></td></tr></table></figure>\n<ul>\n<li>整个类</li>\n</ul>\n<p>如果要替换整个类，不需要一次次的调用xlua.hotfix去替换，可以整个一次完成。只要给一个table，按method_name = function组织即可</p>\n<figure class=\"highlight lua\"><table><tr><td class=\"code\"><pre><div class=\"line\"></div><div class=\"line\">xlua.hotfix(CS.StatefullTest, &#123;</div><div class=\"line\">    [<span class=\"string\">'.ctor'</span>] = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(csobj)</span></span></div><div class=\"line\">        <span class=\"keyword\">return</span> &#123;evt = &#123;&#125;, start = <span class=\"number\">0</span>&#125;</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    set_AProp = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, v)</span></span></div><div class=\"line\">        <span class=\"built_in\">print</span>(<span class=\"string\">'set_AProp'</span>, v)</div><div class=\"line\">        self.AProp = v</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    get_AProp = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self)</span></span></div><div class=\"line\">        <span class=\"keyword\">return</span> self.AProp</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    get_Item = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, k)</span></span></div><div class=\"line\">        <span class=\"built_in\">print</span>(<span class=\"string\">'get_Item'</span>, k)</div><div class=\"line\">        <span class=\"keyword\">return</span> <span class=\"number\">1024</span></div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    set_Item = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, k, v)</span></span></div><div class=\"line\">        <span class=\"built_in\">print</span>(<span class=\"string\">'set_Item'</span>, k, v)</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    add_AEvent = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, cb)</span></span></div><div class=\"line\">        <span class=\"built_in\">print</span>(<span class=\"string\">'add_AEvent'</span>, cb)</div><div class=\"line\">        <span class=\"built_in\">table</span>.<span class=\"built_in\">insert</span>(self.evt, cb)</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    remove_AEvent = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self, cb)</span></span></div><div class=\"line\">       <span class=\"built_in\">print</span>(<span class=\"string\">'remove_AEvent'</span>, cb)</div><div class=\"line\">       <span class=\"keyword\">for</span> i, v <span class=\"keyword\">in</span> <span class=\"built_in\">ipairs</span>(self.evt) <span class=\"keyword\">do</span></div><div class=\"line\">           <span class=\"keyword\">if</span> v == cb <span class=\"keyword\">then</span></div><div class=\"line\">               <span class=\"built_in\">table</span>.<span class=\"built_in\">remove</span>(self.evt, i)</div><div class=\"line\">               <span class=\"keyword\">break</span></div><div class=\"line\">           <span class=\"keyword\">end</span></div><div class=\"line\">       <span class=\"keyword\">end</span></div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    Start = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self)</span></span></div><div class=\"line\">        <span class=\"built_in\">print</span>(<span class=\"string\">'Start'</span>)</div><div class=\"line\">        <span class=\"keyword\">for</span> _, cb <span class=\"keyword\">in</span> <span class=\"built_in\">ipairs</span>(self.evt) <span class=\"keyword\">do</span></div><div class=\"line\">            cb(self.start, <span class=\"number\">2</span>)</div><div class=\"line\">        <span class=\"keyword\">end</span></div><div class=\"line\">        self.start = self.start + <span class=\"number\">1</span></div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    StaticFunc = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(a, b, c)</span></span></div><div class=\"line\">       <span class=\"built_in\">print</span>(a, b, c)</div><div class=\"line\">    <span class=\"keyword\">end</span>;</div><div class=\"line\">    Finalize = <span class=\"function\"><span class=\"keyword\">function</span><span class=\"params\">(self)</span></span></div><div class=\"line\">       <span class=\"built_in\">print</span>(<span class=\"string\">'Finalize'</span>, self)</div><div class=\"line\">    <span class=\"keyword\">end</span></div><div class=\"line\">&#125;)</div></pre></td></tr></table></figure>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/hotfix.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/index.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>介绍 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li current\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link current\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"XLua\"><a href=\"#XLua\" class=\"headerlink\" title=\"XLua\"></a>XLua</h2><p><a href=\"https://github.com/Tencent/xLua/blob/master/LICENSE.TXT\"><img src=\"http://img.shields.io/badge/license-MIT-blue.svg\" alt=\"license\"></a> <a href=\"https://github.com/Tencent/xLua/releases\"><img src=\"https://img.shields.io/badge/release-v2.1.8-blue.svg\" alt=\"release\"></a> <a href=\"https://github.com/Tencent/xLua/pulls\"><img src=\"https://img.shields.io/badge/PRs-welcome-blue.svg\" alt=\"PRs Welcome\"></a></p>\n<h3 id=\"C-下Lua编程支持\"><a href=\"#C-下Lua编程支持\" class=\"headerlink\" title=\"C#下Lua编程支持\"></a>C#下Lua编程支持</h3><p>xLua为Unity、 .Net、 Mono等C#环境增加Lua脚本编程的能力，借助xLua，这些Lua代码可以方便的和C#相互调用。</p>\n<h3 id=\"xLua的突破\"><a href=\"#xLua的突破\" class=\"headerlink\" title=\"xLua的突破\"></a>xLua的突破</h3><p>xLua在功能、性能、易用性都有不少突破，这几方面分别最具代表性的是：</p>\n<ul>\n<li>可以运行时把C#实现（方法，操作符，属性，事件等等）替换成lua实现；</li>\n<li>出色的GC优化，自定义struct，枚举在Lua和C#间传递无C# gc alloc；</li>\n<li>编辑器下无需生成代码，开发更轻量；</li>\n</ul>\n<blockquote>\n<p>更详细的特性、平台支持介绍请看<a href=\"features.html\">这里</a>。</p>\n</blockquote>\n<h3 id=\"安装\"><a href=\"#安装\" class=\"headerlink\" title=\"安装\"></a>安装</h3><p>打开zip包，你会看到一个Assets目录，这目录就对应Unity工程的Assets目录，保持这目录结构放到你的Unity工程。</p>\n<p>如果希望安装到其它目录，请看<a href=\"faq.html\">FAQ</a>相关介绍。</p>\n<h3 id=\"lua5-3-vs-luajit\"><a href=\"#lua5-3-vs-luajit\" class=\"headerlink\" title=\"lua5.3 vs luajit\"></a>lua5.3 vs luajit</h3><p>xLua有两个版本，分别集成了lua5.3和luajit，一个项目只能选择其一。这两个版本C#代码是一样的，不同的是Plugins部分。</p>\n<p>lua5.3的特性更丰富些，比如支持原生64位整数，支持苹果bitcode，支持utf8等。出现问题因为是纯c代码，也好定位。比起luajit，lua对安装包的影响也更小。</p>\n<p>而luajit胜在性能，如果其jit不出问题的话，可以比lua高一个数量级。目前luajit作者不打算维护luajit，在找人接替其维护，后续发展不太明朗。</p>\n<p>项目可以根据自己情况判断哪个更适合。因为目前lua53版本使用较多，所以xLua工程Plugins目录下默认配套是lua53版本。</p>\n<h3 id=\"快速入门\"><a href=\"#快速入门\" class=\"headerlink\" title=\"快速入门\"></a>快速入门</h3><p>一个完整的例子仅需3行代码：</p>\n<p>安装好xLua，建一个MonoBehaviour拖到场景，在Start加入如下代码：</p>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">XLua.LuaEnv luaenv = <span class=\"keyword\">new</span> XLua.LuaEnv();</div><div class=\"line\">luaenv.DoString(<span class=\"string\">\"CS.UnityEngine.Debug.Log('hello world')\"</span>);</div><div class=\"line\">luaenv.Dispose();</div></pre></td></tr></table></figure>\n<p>1、DoString参数为string，可输入任意合法的Lua代码，本示例在lua里调用C#的UnityEngine.Debug.Log打印了个日志。</p>\n<p>2、一个LuaEnv实例对应Lua虚拟机，出于开销的考虑，建议全局唯一。</p>\n<p>C#主动调用lua也很简单，比如要调用lua的系统函数，推荐方式是：</p>\n<ul>\n<li>声明</li>\n</ul>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">[<span class=\"meta\">XLua.CSharpCallLua</span>]</div><div class=\"line\"><span class=\"function\"><span class=\"keyword\">public</span> <span class=\"keyword\">delegate</span> <span class=\"keyword\">double</span> <span class=\"title\">LuaMax</span>(<span class=\"params\"><span class=\"keyword\">double</span> a, <span class=\"keyword\">double</span> b</span>)</span>;</div></pre></td></tr></table></figure>\n<ul>\n<li>绑定</li>\n</ul>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\"><span class=\"keyword\">var</span> max = luaenv.Global.GetInPath&lt;LuaMax&gt;(<span class=\"string\">\"math.max\"</span>);</div></pre></td></tr></table></figure>\n<ul>\n<li>调用</li>\n</ul>\n<figure class=\"highlight csharp\"><table><tr><td class=\"code\"><pre><div class=\"line\">Debug.Log(<span class=\"string\">\"max:\"</span> + max(<span class=\"number\">32</span>, <span class=\"number\">12</span>));</div></pre></td></tr></table></figure>\n<p>建议绑定一次，重复使用。生成了代码的话，调用max是不产生gc alloc的。</p>\n<h3 id=\"热补丁\"><a href=\"#热补丁\" class=\"headerlink\" title=\"热补丁\"></a>热补丁</h3><ul>\n<li>侵入性小，老项目原有代码不做任何调整就可使用。</li>\n<li>运行时影响小，不打补丁基本和原有程序一样。</li>\n<li>出问题了可以用Lua来打补丁，这时才会走到lua代码逻辑；</li>\n</ul>\n<blockquote>\n<p><a href=\"hotfix.html\">这里</a>是使用指南。</p>\n</blockquote>\n<h3 id=\"更多示例\"><a href=\"#更多示例\" class=\"headerlink\" title=\"更多示例\"></a>更多示例</h3><ul>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/01_Helloworld/\">01_Helloworld</a>: 快速入门的例子。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/02_U3DScripting/\">02_U3DScripting</a>: 展示怎么用lua来写MonoBehaviour。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/03_UIEvent/\">03_UIEvent</a>: 展示怎么用lua来写UI逻辑。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/04_LuaObjectOrented/\">04_LuaObjectOrented</a>: 展示lua面向对象和C#的配合。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/05_NoGc/\">05_NoGc</a>: 展示怎么去避免值类型的GC。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/06_Coroutine/\">06_Coroutine</a>: 展示lua协程怎么和Unity协程相配合。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/07_AsyncTest/\">07_AsyncTest</a>: 展示怎么用lua协程来把异步逻辑同步化。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/08_Hotfix/\">08_Hotfix</a>: 热补丁的示例（需要开启热补丁特性，如何开启请看<a href=\"Assets/XLua/Doc/hotfix.md\">指南</a>）。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/09_GenericMethod/\">09_GenericMethod</a>: 泛化函数支持的演示。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/10_SignatureLoader/\">10_SignatureLoader</a>: 展示如何读取经数字签名的lua脚本，参见<a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/signature.md\">数字签名</a>的文档介绍。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/11_RawObject/\">11_RawObject</a>: 当C#参数是object时，如何把一个lua number指定以boxing后的int传递过去。</li>\n</ul>\n<h3 id=\"文档\"><a href=\"#文档\" class=\"headerlink\" title=\"文档\"></a>文档</h3><ul>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua教程.doc\">XLua教程.doc</a>：教程，其配套代码<a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Tutorial/\">这里</a>。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/configure.md\">XLua的配置</a>：介绍如何配置xLua。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua增加删除第三方lua库.doc\">XLua增加删除第三方lua库.doc</a>：如何增删第三方lua扩展库。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua_API.doc\">XLua API.doc</a>：API文档。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/custom_generate.md\">生成引擎二次开发指南</a>：介绍如何做生成引擎的二次开发。</li>\n<li><a href=\"https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/hotfix.md\">热补丁操作指南</a>：介绍如何使用热补丁特性。</li>\n</ul>\n<h3 id=\"技术支持\"><a href=\"#技术支持\" class=\"headerlink\" title=\"技术支持\"></a>技术支持</h3><blockquote>\n<p>QQ群：612705778 验证答案：有问题先找FAQ</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/index.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/performance-analysis.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>性能分析工具 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link current\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"性能分析工具\"><a href=\"#性能分析工具\" class=\"headerlink\" title=\"性能分析工具\"></a>性能分析工具</h2><blockquote>\n<p>Todo:请在此处输入内容</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/performance-analysis.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/signature.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>数字签名 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link current\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"数字签名\"><a href=\"#数字签名\" class=\"headerlink\" title=\"数字签名\"></a>数字签名</h2><blockquote>\n<p>Todo:请在此处输入内容</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/signature.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/tutorial.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>从零开始 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link current\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"从零开始\"><a href=\"#从零开始\" class=\"headerlink\" title=\"从零开始\"></a>从零开始</h2><blockquote>\n<p>文章等待完善</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/tutorial.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/use.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>商业案例 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li current\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link current\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"商业案例\"><a href=\"#商业案例\" class=\"headerlink\" title=\"商业案例\"></a>商业案例</h2><blockquote>\n<p>这份文档等待您进行完善</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/use.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/public/v1/guide/version.html",
    "content": "\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title>更新记录 — XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"XLua\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <link rel=\"stylesheet\" href=\"/xLua/public/css/page.css\">\n\n    <script src=\"/xLua/public/js/vue.js\"></script>\n    <script src=\"/xLua/public/js/jquery.js\"></script>\n    </head>\n\n    <body>\n        \n            <nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"/xLua/public/images/logo.png\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li\">下载项目</a></li>\n            <li><a href=\"/xLua/public/v1/guide/use.html\" class=\"nav-link-li\">使用案例</a></li>\n            <li><a href=\"/xLua/public/v1/guide/version.html\" class=\"nav-link-li current\">更新记录</a></li>\n            <li><a href=\"/xLua/public/v1/guide/contribution.html\" class=\"nav-link-li\">贡献指南</li>\n            <li><a href=\"/xLua/public/v1/guide/index.html\" class=\"nav-link-li\">教程</a></li>\n            <li><a href=\"/xLua/public/\" class=\"nav-link-li current\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <section class=\"sidebar clearfix\">\n    <ul>\n        \n            \n            \n                <li><h3>基础</h3></li>\n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/index.html\" class=\"sidebar-link\">介绍</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/version.html\" class=\"sidebar-link current\">更新记录</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/use.html\" class=\"sidebar-link\">商业案例</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/faq.html\" class=\"sidebar-link\">FAQ</a></p>\n            </li>\n        \n            \n            \n            \n                <li><h3>教程</h3></li>\n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/tutorial.html\" class=\"sidebar-link\">从零开始</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/configure.html\" class=\"sidebar-link\">XLua的配置</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/api.html\" class=\"sidebar-link\">C# API</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/crtdel-3rd.html\" class=\"sidebar-link\">添加删除第三方库</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/gc-optimization.html\" class=\"sidebar-link\">GC优化指南</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/performance-analysis.html\" class=\"sidebar-link\">性能分析工具</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/signature.html\" class=\"sidebar-link\">数字签名</a></p>\n            </li>\n        \n            \n            \n            \n            \n                <li><h3>其他</h3></li>\n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/hotfix.html\" class=\"sidebar-link\">热标识</a></p>\n            </li>\n        \n            \n            \n            \n            \n            <li>\n                <p><a href=\"/xLua/public/v1/guide/features.html\" class=\"sidebar-link\">特性</a></p>\n            </li>\n        \n    </ul>\n</section>\n    <article class=\"clearfix\">\n    <h2 id=\"更新记录\"><a href=\"#更新记录\" class=\"headerlink\" title=\"更新记录\"></a>更新记录</h2><blockquote>\n<p>这份文档等待您进行完善</p>\n</blockquote>\n\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"https://github.com/Tencent/xLua/tree/master/docs/source/src/v1/guide/version.md\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> \n</div>\n\n<footer>\n    <div>\n        <p>© Copyright 2017 Tencent All Rights Reserved</p>\n        <p>Tencent 2017</p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>\n        \n    </body>\n</html>"
  },
  {
    "path": "docs/source/.npmignore",
    "content": ".DS_Store\nThumbs.db\ndb.json\n*.log\nnode_modules/\npublic/\n.deploy*/"
  },
  {
    "path": "docs/source/README.md",
    "content": "# XLua 教程文档\n\n这是XLua的教程文档网站，文档是使用[hexo](http://hexo.io/)构建的。 文档内容在[src](src)文件夹中，使用Markdown格式编写。\n\n## 搭建本地文档环境\n\n* 首先您必须安装[nodejs](http://nodejs.cn/)及[npm](https://www.npmjs.com/)\n\n* 安装hexo，在docs/source下执行\n\n```\n$ npm install -g hexo-cli\n$ npm install\n```\n\n* 如下指令在 `localhost:4000` 启动文档网站：\n\n```\n$ hexo server\n```\n\n\n## 修改Markdown后生成静态网页\n\n* 已经安装了hexo的话，执行如下指令：\n\n```\n$ hexo g\n```\n\n"
  },
  {
    "path": "docs/source/_config.yml",
    "content": "# Hexo Configuration\n## Docs: https://hexo.io/docs/configuration.html\n## Source: https://github.com/hexojs/hexo/\n\n# Site\ntitle: XLua\nsubtitle: Tencent XLua\ndescription: Tencent XLua\nauthor: Tencent\nlanguage: zh-CN\ntimezone: Asia/Shanghai\n\n# URL\n## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'\nurl: https://github.com/Tencent/xLua\nroot: /xLua/public\npermalink: :year/:month/:day/:title/\npermalink_defaults:\n\n# Directory\nsource_dir: src\npublic_dir: ../public\ntag_dir: tags\narchive_dir: archives\ncategory_dir: categories\ncode_dir: downloads/code\ni18n_dir: :lang\nskip_render:\n\n# Writing\nnew_post_name: :title.md # File name of new posts\ndefault_layout: post\ntitlecase: false # Transform title into titlecase\nexternal_link: true # Open external links in new tab\nfilename_case: 0\nrender_drafts: false\npost_asset_folder: false\nrelative_link: false\nfuture: true\nhighlight:\n  enable: true\n  line_number: false\n  auto_detect: false\n  tab_replace:\n\n# Category & Tag\ndefault_category: uncategorized\ncategory_map:\ntag_map:\n\n# Date / Time format\n## Hexo uses Moment.js to parse and display date\n## You can customize the date format as defined in\n## http://momentjs.com/docs/#/displaying/format/\ndate_format: YYYY-MM-DD\ntime_format: HH:mm:ss\n\n# Pagination\n## Set per_page to 0 to disable pagination\nper_page: 10\npagination_dir: page\n\n# Extensions\n## Plugins: https://hexo.io/plugins/\n## Themes: https://hexo.io/themes/\ntheme: catlib\n\n# Deployment\n## Docs: https://hexo.io/docs/deployment.html\ndeploy:\n  type:\n  repo:\n  branch: \n"
  },
  {
    "path": "docs/source/package.json",
    "content": "{\n  \"name\": \"hexo-site\",\n  \"version\": \"0.0.0\",\n  \"private\": true,\n  \"hexo\": {\n    \"version\": \"3.3.7\"\n  },\n  \"dependencies\": {\n    \"hexo\": \"^3.3.7\",\n    \"hexo-cli\": \"^1.0.3\",\n    \"hexo-generator-archive\": \"^0.1.4\",\n    \"hexo-generator-category\": \"^0.1.3\",\n    \"hexo-generator-index\": \"^0.2.0\",\n    \"hexo-generator-tag\": \"^0.2.0\",\n    \"hexo-renderer-ejs\": \"^0.2.0\",\n    \"hexo-renderer-marked\": \"^0.2.10\",\n    \"hexo-renderer-stylus\": \"^0.3.1\",\n    \"hexo-server\": \"^0.2.1\"\n  }\n}\n"
  },
  {
    "path": "docs/source/patch/highlight.js/lib/languages/cs.js",
    "content": "module.exports = function(hljs) {\n  var KEYWORDS = {\n    keyword:\n      // Normal keywords.\n      'abstract as base bool break byte case catch char checked const continue decimal ' +\n      'default delegate do double enum event explicit extern finally fixed float ' +\n      'for foreach goto if implicit in int interface internal is lock long nameof ' +\n      'object operator out override params private protected public readonly ref sbyte ' +\n      'sealed short sizeof stackalloc static string struct switch this try typeof ' +\n      'uint ulong unchecked unsafe ushort using virtual void volatile while ' +\n      // Contextual keywords.\n      'add alias ascending async await by descending dynamic equals from get global group into join ' +\n      'let on orderby partial remove select set value var where yield',\n    literal:\n      'null false true'\n  };\n\n  var VERBATIM_STRING = {\n    className: 'string',\n    begin: '@\"', end: '\"',\n    contains: [{begin: '\"\"'}]\n  };\n  var VERBATIM_STRING_NO_LF = hljs.inherit(VERBATIM_STRING, {illegal: /\\n/});\n  var SUBST = {\n    className: 'subst',\n    begin: '{', end: '}',\n    keywords: KEYWORDS\n  };\n  var SUBST_NO_LF = hljs.inherit(SUBST, {illegal: /\\n/});\n  var INTERPOLATED_STRING = {\n    className: 'string',\n    begin: /\\$\"/, end: '\"',\n    illegal: /\\n/,\n    contains: [{begin: '{{'}, {begin: '}}'}, hljs.BACKSLASH_ESCAPE, SUBST_NO_LF]\n  };\n  var INTERPOLATED_VERBATIM_STRING = {\n    className: 'string',\n    begin: /\\$@\"/, end: '\"',\n    contains: [{begin: '{{'}, {begin: '}}'}, {begin: '\"\"'}, SUBST]\n  };\n  var INTERPOLATED_VERBATIM_STRING_NO_LF = hljs.inherit(INTERPOLATED_VERBATIM_STRING, {\n    illegal: /\\n/,\n    contains: [{begin: '{{'}, {begin: '}}'}, {begin: '\"\"'}, SUBST_NO_LF]\n  });\n  SUBST.contains = [\n    INTERPOLATED_VERBATIM_STRING,\n    INTERPOLATED_STRING,\n    VERBATIM_STRING,\n    hljs.APOS_STRING_MODE,\n    hljs.QUOTE_STRING_MODE,\n    hljs.C_NUMBER_MODE,\n    hljs.C_BLOCK_COMMENT_MODE\n  ];\n  SUBST_NO_LF.contains = [\n    INTERPOLATED_VERBATIM_STRING_NO_LF,\n    INTERPOLATED_STRING,\n    VERBATIM_STRING_NO_LF,\n    hljs.APOS_STRING_MODE,\n    hljs.QUOTE_STRING_MODE,\n    hljs.C_NUMBER_MODE,\n    hljs.inherit(hljs.C_BLOCK_COMMENT_MODE, {illegal: /\\n/})\n  ];\n  var STRING = {\n    variants: [\n      INTERPOLATED_VERBATIM_STRING,\n      INTERPOLATED_STRING,\n      VERBATIM_STRING,\n      hljs.APOS_STRING_MODE,\n      hljs.QUOTE_STRING_MODE\n    ]\n  };\n\n  var TYPE_IDENT_RE = hljs.IDENT_RE + '(<' + hljs.IDENT_RE + '(\\\\s*,\\\\s*' + hljs.IDENT_RE + ')*>)?(\\\\[\\\\])?';\n\n  return {\n    aliases: ['csharp'],\n    keywords: KEYWORDS,\n    illegal: /::/,\n    contains: [\n      hljs.COMMENT(\n        '///',\n        '$',\n        {\n          returnBegin: true,\n          contains: [\n            {\n              className: 'doctag',\n              variants: [\n                {\n                  begin: '///', relevance: 0\n                },\n                {\n                  begin: '<!--|-->'\n                },\n                {\n                  begin: '</?', end: '>'\n                }\n              ]\n            }\n          ]\n        }\n      ),\n      hljs.C_LINE_COMMENT_MODE,\n      hljs.C_BLOCK_COMMENT_MODE,\n      {\n        className: 'meta',\n        begin: '#', end: '$',\n        keywords: {\n          'meta-keyword': 'if else elif endif define undef warning error line region endregion pragma checksum'\n        }\n      },\n      STRING,\n      hljs.C_NUMBER_MODE,\n      {\n        beginKeywords: 'class interface', end: /[{;=]/,\n        illegal: /[^\\s:,]/,\n        contains: [\n          hljs.TITLE_MODE,\n          hljs.C_LINE_COMMENT_MODE,\n          hljs.C_BLOCK_COMMENT_MODE\n        ]\n      },\n      {\n        beginKeywords: 'namespace', end: /[{;=]/,\n        illegal: /[^\\s:]/,\n        contains: [\n          hljs.inherit(hljs.TITLE_MODE, {begin: '[a-zA-Z](\\\\.?\\\\w)*'}),\n          hljs.C_LINE_COMMENT_MODE,\n          hljs.C_BLOCK_COMMENT_MODE\n        ]\n      },\n      {\n        // [Attributes(\"\")]\n        className: 'meta',\n        begin: '^\\\\s*\\\\[', excludeBegin: true, end: '\\\\]', excludeEnd: true,\n        contains: [\n          {className: 'meta-string', begin: /\"/, end: /\"/}\n        ]\n      },\n      {\n        // Expression keywords prevent 'keyword Name(...)' from being\n        // recognized as a function definition\n        beginKeywords: 'new return throw await else',\n        relevance: 0\n      },\n      {\n        className: 'function',\n        begin: '(' + TYPE_IDENT_RE + '\\\\s+)+' + hljs.IDENT_RE + '\\\\s*\\\\(', returnBegin: true,\n        end: /[{;=]/, excludeEnd: true,\n        keywords: KEYWORDS,\n        contains: [\n          {\n            begin: hljs.IDENT_RE + '\\\\s*\\\\(', returnBegin: true,\n            contains: [hljs.TITLE_MODE],\n            relevance: 0\n          },\n          {\n            className: 'params',\n            begin: /\\(/, end: /\\)/,\n            excludeBegin: true,\n            excludeEnd: true,\n            keywords: KEYWORDS,\n            relevance: 0,\n            contains: [\n              STRING,\n              hljs.C_NUMBER_MODE,\n              hljs.C_BLOCK_COMMENT_MODE\n            ]\n          },\n          hljs.C_LINE_COMMENT_MODE,\n          hljs.C_BLOCK_COMMENT_MODE\n        ]\n      }\n    ]\n  };\n}\n"
  },
  {
    "path": "docs/source/patch.ps1",
    "content": "$path = Split-Path -Parent $MyInvocation.MyCommand.Definition\nrm $path/node_modules/highlight.js/lib/languages/cs.js\ncp $path/patch/highlight.js/lib/languages/cs.js $path/node_modules/highlight.js/lib/languages/cs.js"
  },
  {
    "path": "docs/source/src/index.md",
    "content": "---\ntitle: XLua\ntype: index\norder: 0\n---"
  },
  {
    "path": "docs/source/src/readme.md",
    "content": "---\ntitle: 可以使用的markdown\ntype: detail\norder: 0\n---\n\n## 主标题\n\ntitle 为标题\ntype 固定为guide宝宝埋的坑\norder 为左侧导航排序，但是注意，假设0开始是基础的区域，100后是教程的区域，如果你想把文章放到基础区域，那么order必须小于100\n\n> 这是小提示框用法\n\n![图片用法](https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/xLua.png)\n\nps：markdown的图片不会调整大小所以如果要使用调整大小的图片应该用：\n\n<img width=\"173\" height=\"57\" src=\"https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/xLua.png\">\n\n\n### 子标题会被索引\n\n正常的文本内容哈哈哈哈哈\n`这是高光内容`哈哈哈哈\n\n### 子标题2\n\n[超链接用法](https://github.com/tencent/xlua)\n\n- 列表用法\n- 列表用法\n- 列表用法\n- 列表用法\n- 列表用法\n\n**加粗用法**\n\n<p class=\"tip\">大提示框用法</p>\n\n1. 有序列表用法\n2. 有序列表用法\n3. 有序列表用法\n\n下面是分割线用法\n***\n\n``` csharp\n这是代码块，支持的代码格式有：csharp ，lua，html, js, bash, css\n```\n\n下面是列表使用：\n\n| Helloworld       | Helloworld   |\n| ---------------- |:------------:|\n| `Helloworld`     | Helloworld   |\n| `Helloworld`     | Helloworld   |"
  },
  {
    "path": "docs/source/src/v1/guide/api.md",
    "content": "---\ntitle: C# API\ntype: guide\norder: 101\n---\n\n## C# API\n\n### LuaEnv类\n\n#### DoString\n\n`object[] DoString(string chunk, string chunkName = \"chuck\", LuaTable env = null)`\n\n执行一个代码块。\n\n**参数**\n\n* chunk - Lua代码的字符串\n* chunkName - 发生error时的debug显示信息中使用，指明某某代码块的某行错误\n* env - 这个代码块的环境变量\n\n**返回值**\n\n代码块里return语句的返回值。\n\n比如：`return 1, \"hello\"`中，DoString将返回包含两个object的数组， 一个是double类型的1， 一个是string类型的hello。\n\n**示例**\n\n```csharp\nLuaEnv luaenv = new LuaEnv();\nobject[] ret = luaenv.DoString(\"print('hello')\\r\\nreturn 1\");\nUnityEngine.Debug.Log(\"ret=\" + ret[0]);\nluaenv.Dispose();\n```\n\n#### LoadString\n\n`T LoadString<T>(string chunk, string chunkName = \"chunk\", LuaTable env = null)`\n\n加载一个代码块，但不执行，只返回类型。\n\n可以指定为一个delegate或者一个LuaFunction。\n\n**参数**\n\n* chunk - Lua代码的字符串\n* chunkName - 发生error时的debug显示信息中使用，指明某某代码块的某行错误\n* env - 这个代码块的环境变量\n\n**返回值**\n\n代表该代码块的delegate或LuaFunction。\n\n#### Global\n\n`LuaTable Global`\n\n代表lua全局环境的LuaTable。\n\n#### Tick\n\n`void Tick()`\n\n清除Lua的未手动释放的LuaBase对象（如：LuaTable、LuaFunction），以及其它一些事情。\n\n需要定期调用，比如每秒在MonoBehaviour的Update中调用。\n\n参考示例：[XLua Example - U3D Scripting - LuaBehaviour.cs L82](https://github.com/Tencent/xLua/blob/master/Assets/XLua/Examples/02_U3DScripting/LuaBehaviour.cs#L82)\n\n#### AddLoader\n\n`void AddLoader(CustomLoader loader)`\n\n添加一个自定义loader。\n\n**参数**\n\n* loader - 一个包括了加载函数的委托，其类型为delegate byte\\[\\] CustomLoader\\(ref string filepath\\)。\n\n当一个文件被require时，这个loader会被回调，其参数是调用require所使用的参数。如果该loader找到文件，可以将其读进内存，返回一个byte数组。如果需要支持调试的话，filepath要设置成IDE能找到的路径（相对或者绝对都可以）。\n\n#### Dispose\n\n`void Dispose()`\n\nDispose该LuaEnv。\n\n**使用建议**\n\n全局只创建一个LuaEnv实例，并在Update中调用GC方法，完全不需要时调用Dispose。\n\n### LuaTable类\n\n#### Get\n\n`T Get<T>(string key)`\n\n获取在key下，类型为T的value，如果不存在或者类型不匹配，返回null。\n\n#### GetInPath\n\n`T GetInPath<T>(string path)`\n\n和Get的区别是，这个函数会识别path里的`.`。\n\n比如`var i = tbl.GetInPath<int>(\"a.b.c\")`相当于在lua里执行`i = tbl.a.b.c`，避免仅为了获取中间变量而多次调用Get，执行效率更高。\n\n#### SetInPath\n\n`void SetInPath<T>(string path, T val)`\n\n和`GetInPath`对应的setter。\n\n#### Get\n\n`void Get<TKey, TValue>(TKey key, out TValue value)`\n\n和上面API的区别是，上面的API的Key都只能是string，而这个API无此限制。\n\n#### Set\n\n`void Set<TKey, TValue>(TKey key, TValue value)`\n\n对应Get的setter。\n\n#### Cast\n\n`T Cast<T>()`\n\n把该table转成一个T指明的类型。\n\n可以是一个加了CSharpCallLua声明的interface，一个有默认构造函数的class或者struct，一个Dictionary，List等等。\n\n#### SetMetaTable\n\n`void SetMetaTable(LuaTable metaTable)`\n\n设置metaTable为table的metatable。\n\n### LuaFunction类\n\n用该类访问Lua函数会有boxing，unboxing的开销。\n\n为了性能考虑，需要频繁调用的地方不要用该类。\n\n建议通过`table.Get<FooDelegate>`获取一个delegate调用。\n\n在使用`table.Get<FooDelegate>`之前，注意先把`FooDelegate`添加到代码生成列表。\n\n#### Call\n\n`object[] Call(params object[] args)`\n\n以可变参数调用Lua函数，并返回该调用的返回值。\n\n#### Call\n\n`object[] Call(object[] args, Type[] returnTypes)`\n\n调用Lua函数，并指明返回参数的类型，系统会自动按指定类型进行转换。\n\n#### SetEnv\n\n`void SetEnv(LuaTable env)`\n\n相当于lua的setfenv函数。\n\n## Lua API\n\n### CS对象\n\n#### CS.namespace.class\\(...\\)\n\n调用一个C\\#类型的构造函数,并返回类型实例\n\n**示例**\n\n```lua\nlocal v1 = CS.UnityEngine.Vector3(1,1,1)\n```\n\n#### CS.namespace.class.field\n\n访问一个C\\#静态成员\n\n**示例**\n\n```lua\nPrint(CS.UnityEngine.Vector3.one)\n```\n\n#### CS.namespace.enum.field\n\n访问一个枚举值\n\n#### typeof函数\n\n类似C\\#的typeof关键字，返回一个Type对象。\n\n**示例**\n\n比如GameObject.AddComponent其中一个重载需要一个Type参数。\n\n```lua\nnewGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))\n```\n\n#### 无符号64位支持\n\n**uint64.tostring**\n\n无符号数转字符串。\n\n**uint64.divide**\n\n无符号数除法。\n\n**uint64.compare**\n\n无符号比较，相对返回0，大于返回正数，小于返回负数。\n\n**uint64.remainder**\n\n无符号数取模。\n\n**uint64.parse**\n\n字符串转无符号数。\n\n#### xlua.structclone\n\n克隆一个c\\#结构体\n\n#### xlua.private\\_accessible\\(class\\)\n\n让一个类的私有字段，属性，方法等可用\n\n#### cast函数\n\n指明以特定的接口访问对象，这在实现类无法访问的时候（比如internal修饰）很有用，这时可以这么来（假设下面的calc对象实现了C\\#的PerformentTest.ICalc接口）\n\n**示例**\n\n```lua\ncast(calc, typeof(CS.PerformentTest.ICalc))\n```\n\n#### 其它\n\n访问csharp对象和访问一个table一样，调用函数跟调用lua函数一样，也可以通过操作符访问c\\#的操作符，示例：\n\n```lua\nlocal v1=CS.UnityEngine.Vector3(1,1,1)\nlocal v2=CS.UnityEngine.Vector3(1,1,1)\nv1.x = 100\nv2.y = 100\nprint(v1, v2)\nlocal v3 = v1 + v2\nprint(v1.x, v2.x)\nprint(CS.UnityEngine.Vector3.one)\nprint(CS.UnityEngine.Vector3.Distance(v1, v2))\n```\n\n## 类型映射\n\n### 基本数据类型\n\n| C\\#类型 | Lua类型 |\n| :--- | :--- |\n| sbyte，byte，short，ushort，int，uint，double，char，float | number |\n| decimal | userdata |\n| long，ulong | userdata/lua\\_Integer\\(lua53\\) |\n| bytes\\[\\] | string |\n| bool | boolean |\n| string | string |\n\n### 复杂数据类型\n\n| C\\#类型 | Lua类型 |\n| :--- | :--- |\n| LuaTable | table |\n| LuaFunction | function |\n| class或struct的实例 | userdata，table |\n| method，delegate | function |\n\n#### LuaTable\n\nC\\#侧指明从Lua侧输入（包括C\\#方法的输入参数或者Lua方法的返回值）LuaTable类型，则要求Lua侧为table。或者Lua侧的table，在C\\#侧未指明类型的情况下转换成LuaTable。\n\n#### LuaFunction\n\nC\\#侧指明从Lua侧输入（包括C\\#方法的输入参数或者Lua方法的返回值）LuaFunction类型，则要求Lua侧为function。或者Lua侧的function，在C\\#侧未指明类型的情况下转换成LuaFunction。\n\n#### LuaUserData\n\n对应非C\\# Managered对象的lua userdata。\n\n#### class或struct的实例\n\n从C\\#传一个class或者struct的实例，将映射到Lua的userdata，并通过\\_\\_index访问该userdata的成员 C\\#侧指明从Lua侧输入指定类型对象，Lua侧为该类型实例的userdata可以直接使用；如果该指明类型有默认构造函数，Lua侧是table则会自动转换，转换规则是：调用构造函数构造实例，并用table对应字段转换到c\\#对应值后赋值各成员。\n\n#### method， delegate\n\n成员方法以及delegate都是对应lua侧的函数。 C\\#侧的普通参数以及引用参数，对应lua侧函数参数；C\\#侧的返回值对应于Lua的第一个返回值；引用参数和out参数则按序对应于Lua的第2到第N个参数。\n\n## 宏\n\n### HOTFIX\\_ENABLE\n\n打开hotfix功能。\n\n### NOT\\_GEN\\_WARNING\n\n反射时打印warning。\n\n### GEN\\_CODE\\_MINIMIZE\n\n以偏向减少代码段的方式生成代码。\n\n"
  },
  {
    "path": "docs/source/src/v1/guide/configure.md",
    "content": "---\ntitle: XLua的配置\ntype: guide\norder: 100\n---\n\n## XLua的配置\n\nxLua所有的配置都支持三种方式：`打标签`, `静态列表`, `动态列表`。\n\n配置有两必须两建议：\n\n* 列表方式均必须是static的字段/属性\n* 列表方式均必须放到一个static类\n* 建议不用标签方式\n* 建议列表方式配置放Editor目录\n\n### 打标签\n\nxLua用白名单来指明生成哪些代码，而白名单通过attribute来配置，比如你想从lua调用c#的某个类，希望生成适配代码，你可以为这个类型打一个LuaCallCSharp标签：\n\n~~~csharp\n[LuaCallCSharp]\npublicclassA\n{\n\n}\n~~~\n\n该方式方便，但在il2cpp下会增加不少的代码量，不建议使用。\n\n### 静态列表\n\n有时我们无法直接给一个类型打标签，比如系统api，没源码的库，或者实例化的泛化类型，这时你可以在一个静态类里声明一个静态字段，该字段的类型除BlackList和AdditionalProperties之外只要实现了IEnumerable&lt;Type&gt;就可以了（这两个例外后面具体会说），然后为这字段加上标签：\n\n~~~csharp\n[LuaCallCSharp]\npublic static List<Type> mymodule_lua_call_cs_list = new List<Type>()\n{\n    typeof(GameObject),\n    typeof(Dictionary<string, int>),\n};\n~~~\n\n这个字段需要放到一个 **静态类** 里头，建议放到 **Editor目录** 。\n\n### 动态列表\n\n声明一个静态属性，打上相应的标签即可。\n\n```csharp\n[Hotfix]\npublic static List<Type> by_property\n{\n    get\n    {\n        return (from type in Assembly.GetExecutingAssembly().GetTypes()\n                where type.Namespace == \"XXXX\"\n                select type).ToList();\n    }\n}\n```\n\nGetter是代码，你可以实现很多效果，比如按名字空间配置，按程序集配置等等。\n\n这个属性需要放到一个 **静态类** 里头，建议放到 **Editor目录** 。\n\n### LuaCallCSharp\n\n一个C#类型加了这个配置，xLua会生成这个类型的适配代码（包括构造该类型实例，访问其成员属性、方法，静态属性、方法），否则将会尝试用性能较低的反射方式来访问。\n\n一个类型的扩展方法（Extension Methods）加了这配置，也会生成适配代码并追加到被扩展类型的成员方法上。\n\nxLua只会生成加了该配置的类型，不会自动生成其父类的适配代码，当访问子类对象的父类方法，如果该父类加了LuaCallCSharp配置，则执行父类的适配代码，否则会尝试用反射来访问。\n\n反射访问除了性能不佳之外，在il2cpp下还有可能因为代码剪裁而导致无法访问，后者可以通过下面介绍的ReflectionUse标签来避免。\n\n### ReflectionUse\n\n一个C#类型类型加了这个配置，xLua会生成link.xml阻止il2cpp的代码剪裁。\n\n对于扩展方法，必须加上LuaCallCSharp或者ReflectionUse才可以被访问到。\n\n建议所有要在Lua访问的类型，要么加LuaCallCSharp，要么加上ReflectionUse，这才能够保证在各平台都能正常运行。\n\n### CSharpCallLua\n\n如果希望把一个lua函数适配到一个C# delegate（一类是C#侧各种回调：UI事件，delegate参数，比如List&lt;T&gt;:ForEach；另外一类场景是通过LuaTable的Get函数指明一个lua函数绑定到一个delegate）。或者把一个lua table适配到一个C# interface，该delegate或者interface需要加上该配置。\n\n### GCOptimize\n\n一个C#纯值类型（注：指的是一个只包含值类型的struct，可以嵌套其它只包含值类型的struct）或者C#枚举值加上了这个配置。xLua会为该类型生成gc优化代码，效果是该值类型在lua和c#间传递不产生（C#）gc alloc，该类型的数组访问也不产生gc。各种无GC的场景，可以参考05\\_NoGc例子。\n\n除枚举之外，包含无参构造函数的复杂类型，都会生成lua table到该类型，以及改类型的一维数组的转换代码，这将会优化这个转换的性能，包括更少的gc alloc。\n\n### AdditionalProperties\n\n这个是GCOptimize的扩展配置，有的时候，一些struct喜欢把field做成是私有的，通过property来访问field，这时就需要用到该配置（默认情况下GCOptimize只对public的field打解包）。\n\n标签方式比较简单，配置方式复杂一点，要求是Dictionary&lt;Type, List&lt;string&gt;&gt;类型，Dictionary的Key是要生效的类型，Value是属性名列表。可以参考XLua对几个UnityEngine下值类型的配置，SysGCOptimize类。\n\n### BlackList\n\n如果你不要生成一个类型的一些成员的适配代码，你可以通过这个配置来实现。\n\n标签方式比较简单，对应的成员上加就可以了。\n\n由于考虑到有可能需要把重载函数的其中一个重载列入黑名单，配置方式比较复杂，类型是List&lt;List&lt;string&gt;&gt;，对于每个成员，在第一层List有一个条目，第二层List是个string的列表，第一个string是类型的全路径名，第二个string是成员名，如果成员是一个方法，还需要从第三个string开始，把其参数的类型全路径全列出来。\n\n例如下面是对GameObject的一个属性以及FileInfo的一个方法列入黑名单：\n\n```csharp\n\n[BlackList]\npublic static List<List<string>> BlackList = new List<List<string>>()  {\n    new List<string>(){\"UnityEngine.GameObject\", \"networkView\"},\n    new List<string>(){\"System.IO.FileInfo\", \"GetAccessControl\", \"System.Security.AccessControl.AccessControlSections\"},\n};\n\n```\n\n### 下面是生成期配置，必须放到Editor目录下\n\n**CSObjectWrapEditor.GenPath**\n\n配置生成代码的放置路径，类型是string。默认放在&quot;Assets/XLua/Gen/&quot;下。\n\n**CSObjectWrapEditor.GenCodeMenu**\n\n该配置用于生成引擎的二次开发，一个无参数函数加了这个标签，在执行&quot;XLua/Generate Code&quot;菜单时会触发这个函数的调用。"
  },
  {
    "path": "docs/source/src/v1/guide/crtdel-3rd.md",
    "content": "---\ntitle: 添加删除第三方库\ntype: guide\norder: 101\n---\n\n## 添加删除第三方库\n\n> Todo:请在此处输入内容"
  },
  {
    "path": "docs/source/src/v1/guide/faq.md",
    "content": "---\ntitle: FAQ\ntype: guide\norder: 3\n---\n\n## FAQ\n\n### xLua发布包怎么用？\n\nxLua目前以zip包形式发布，在工程目录下解压即可。\n\n### xLua可以放别的目录吗？\n\n可以，但生成代码目录需要配置一下（默认放`Assets\\XLua\\Gen`目录），具体可以看《XLua的配置.doc》的GenPath配置介绍。\n\n### lua源码只能以txt后缀？\n\n什么后缀都可以。\n\n如果你想以`TextAsset`打包到安装包（比如放到`Resources`目录），Unity不认`lua`后缀，这是Unity的规则。\n\n如果你不打包到安装包，就没有后缀的限制：比如自行下载到某个目录（这也是热更的正确姿势），然后通过CustomLoader或者设置package.path去读这个目录。\n\n那为啥xLua本身带的lua源码（包括示例）为什么都是txt结尾呢？因为xLua本身就一个库，不含下载功能，也不方便运行时去某个地方下载代码，通过TextAsset是较简单的方式。\n\n### Plugins源码在哪里可以找到，怎么使用？\n\nPlugins源码位于`xLua_Project_Root/build`下。\n\n源码编译依赖cmake，安装cmake后执行make_xxxx_yyyy.zz即可，xxxx代表平台，比如ios，android等，yyyy是要集成的虚拟机，有lua53和luajit两者，zz是后缀，windows下是bat，其它平台是sh。\n\nwindows编译依赖Visual Studio 2015。\n\nandroid编译在linux下执行，依赖NDK，并且需要把脚本中ANDROID_NDK指向NDK的安装目录。\n\nios和osx需要在mac下编译。\n\n### 报类似“xlua.access, no field __Hitfix0_Update”的错误怎么解决？\n\n按[Hotfix操作指南](hotfix.html)一步步操作。\n\n### 报“please install the Tools”\n\n没有把Tools安装到Assets平级目录，安装包，或者master下都能找到这个目录。\n\n### 报“This delegate/interface must add to CSharpCallLua : XXX”异常怎么解决？\n\n在编辑器下xLua不生成代码都可以运行，出现这种提示，要么是该类型没加CSharpCallLua，要么是加之前生成过代码，没重新执行生成。\n\n解决办法，确认XXX（类型名）加上CSharpCallLua后，清除代码后运行。\n\n### hotfix下怎么触发一个event\n\n首先通过xlua.private_accessible开启私有成员访问。\n\n跟着通过对象的\"&事件名\"字段调用delegate，例如self\\['&MyEvent'\\]()，其中MyEvent是事件名。\n\n### 怎么对Unity Coroutine的实现函数打补丁？\n\n见[Hotfix操作指南](hotfix.html)相应章节。\n\n### 支持NGUI（或者UGUI/DOTween等等）么？\n\n支持，xLua最主要的特性是让你原来用C#写的地方可以换成用lua写，你C#能用的插件，基本都能用。\n\n### 如果需要调试，CustomLoader的filepath参数该如何处理？\n\nlua里头调用require 'a.b'时，CustomLoader会被调用，并传入字符串\"a.b\"，你需要理解这字符串，（从文件/内存/网络等）加载好lua文件，返回两个东西，第一个是调试器可以理解的路径，比如：a/b.lua，这个通过设置ref类型的filepath参数返回，第二个是UTF8格式的源码的字节流（byte[]），通过返回值返回。\n\n### 什么是生成代码？\n\nxLua支持的lua和C#间交互技术之一，这种技术通过生成两者间的适配代码来实现交互，性能较好，是推荐的方式。\n\n另一种交互技术是反射，这种方式对安装包的影响更少，可以在性能要求不高或者对安装包大小很敏感的场景下使用。\n\n### 改了接口后，之前生成的代码出现错误怎么办？\n\n清除掉生成代码（执行“Clear Generated Code”菜单，如果你重启过，会找不到这个菜单，这时你可以手动删除整个生成代码目录），等编译完成后重新生成。\n\n### 应该什么时候生成代码？\n\n开发期不建议生成代码，可以避免很多由于不一致导致的编译失败，以及生成代码本身的编译等待。\n\nbuild手机版本前必须执行生成代码，建议做成自动化的。\n\n做性能调优，性能测试前必须执行生成代码，因为生成和不生成性能的区别还是很大的。\n\n### CS名字空间下有所有C# API是不是很占内存？\n\n由于用了lazyload，这个“有”只是个虚拟的概念，比如UnityEngine.GameObject，是访问第一次CS.UnityEngine.GameObject或者第一个实例往lua传送才加载该类型方法，属性等。\n\n### LuaCallSharp以及CSharpCallLua两种生成各在什么场景下用？\n\n看调用者和被调用者，比如要在lua调用C#的GameObject.Find函数，或者调用gameobject的实例方法，属性等，GameObject类要加LuaCallSharp，而想把一个lua函数挂到UI回调，这是调用者是C#，被调用的是一个lua函数，所以回调声明的delegate要加CSharpCallLua。\n\n有时会比较迷惑人，比如`List<int>.Find(Predicate<int> match)`的调用，`List<int>`当然是加LuaCallSharp，而`Predicate<int>`却要加CSharpCallLua，因为match的调用者在C#，被调用的是一个lua函数。\n\n更无脑一点的方式是看到“This delegate/interface must add to CSharpCallLua : XXX”，就把XXX加到CSharpCallLua即可。\n\n### 值类型传递会有gc alloc么？\n\n如果你使用的是delegate调用lua函数，或者用LuaTable、LuaFunction的无gc接口，或者数组的话，以下值类型都是没gc的：\n\n1、所有的基本值类型（所有整数，所有浮点数，decimal）；\n\n2、所有的枚举类型；\n\n3、字段只包含值类型的struct，可嵌套其它只包含值类型struct；\n\n其中2、3需要把该类型加到GCOptimize。\n\n### 反射在ios下可用吗？\n\nios下的限制有两个：1、没有jit；2、代码剪裁（stripping）；\n\n对于C#通过delegate或者interface调用lua，如果不生成代码是用反射的emit，这依赖jit，所以这目前只在编辑器可用。\n\n对于lua调用C#，主要会被代码剪裁影响，这时你可以配置ReflectionUse（不要配LuaCallSharp），执行“Generate Code”，这时不会对该类生成封装代码，而是生成link.xml把该类配置为不剪裁。\n\n简而言之，除了CSharpCallLua是必须的（这类生成代码往往不多），LuaCallSharp生成都可以改为用反射。\n\n### 支持泛化方法的调用么？\n\n不直接支持，但能调用到。如果是静态方法，可以自己写个封装来实例化泛化方法。\n\n如果是成员方法，xLua支持扩展方法，你可以添加一个扩展方法来实例化泛化方法。该扩展方法使用起来就和普通成员方法一样。\n\n```csharp\n// C#\npublic static Button GetButton(this GameObject go)\n{\n    return go.GetComponent<Button>();\n}\n```\n\n```lua\n-- lua\nlocal go = CS.UnityEngine.GameObject.Find(\"button\")\ngo:GetButton().onClick:AddListener(function()\n    print('onClick')\nend)\n```\n\n### 支持lua调用C#重载函数吗？\n\n支持，但没有C#端支持的那么完善，比如重载方法void Foo(int a)和void Foo(short a)，由于int和short都对应lua的number，是没法根据参数判断调用的是哪个重载。这时你可以借助扩展方法来为其中一个起一个别名。\n\n### 编辑器下运行正常，打包的时候生成代码报“没有某方法/属性/字段定义”怎么办？\n\n往往是由于该方法/属性/字段是扩在条件编译里头，只在UNITY_EDITOR下有效，这是可以通过把这方法/属性/字段加到黑名单来解决，加了之后要等编译完成后重新执行代码生成。\n\n### this[string field]或者this[object field]操作符重载为什么在lua无法访问？（比如`Dictionary<string, xxx>`, `Dictionary<object, xxx>`在lua中无法通过dic['abc']或者dic.abc检索值）\n\n在2.1.5~2.1.6版本把这个特性去掉，因为：1、这个特性会导致基类定义的方法、属性、字段等无法访问（比如Animation无法访问到GetComponent方法）；2、key为当前类某方法、属性、字段的名字的数据无法检索，比如Dictionary类型，dic['TryGetValue']返回的是一个函数，指向Dictionary的TryGetValue方法。\n\n建议直接方法该操作符的等效方法，比如Dictionary的TryGetValue，如果该方法没有提供，可以在C#那通过Extension method封装一个使用。\n\n### 有的Unity对象，在C#为null，在lua为啥不为nil呢？比如一个已经Destroy的GameObject\n\n其实那C#对象并不为null，是UnityEngine.Object重载的==操作符，当一个对象被Destroy，未初始化等情况，obj == null返回true，但这C#对象并不为null，可以通过System.Object.ReferenceEquals(null, obj)来验证下。\n\n对应这种情况，可以为UnityEngine.Object写一个扩展方法：\n\n~~~csharp\n[LuaCallCSharp]\n[ReflectionUse]\npublic static class UnityEngineObjectExtention\n{\n    public static bool IsNull(this UnityEngine.Object o) // 或者名字叫IsDestroyed等等\n    {\n        return o == null;\n    }\n}\n~~~\n\n然后在lua那你对所有UnityEngine.Object实例都使用IsNull判断\n\n~~~lua\nprint(go:GetComponent('Animator'):IsNull())\n~~~\n\n### 泛型实例怎么构造\n\n涉及的类型都在mscorlib，Assembly-CSharp程序集的话，泛型实例的构造和普通类型是一样的，都是CS.namespace.typename()，可能比较特殊的是typename的表达，泛型实例的typename的表达包含了标识符非法符号，最后一部分要换成[\"typename\"]，以`List<string>`为例\n\n~~~lua\nlocal lst = CS.System.Collections.Generic[\"List`1[System.String]\"]()\n~~~\n\n如果某个泛型实例的typename不确定，可以在C#测打印下typeof(不确定的类型).ToString()\n\n如果涉及mscorlib，Assembly-CSharp程序集之外的类型的话，可以用C#的反射来做：\n\n~~~lua\nlocal dic = CS.System.Activator.CreateInstance(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UnityEngine.Vector3, UnityEngine]],mscorlib'))\ndic:Add('a', CS.UnityEngine.Vector3(1, 2, 3))\nprint(dic:TryGetValue('a'))\n~~~\n\n### 调用LuaEnv.Dispose时，报“try to dispose a LuaEnv with C# callback!”错是什么原因？\n\n这是由于C#还存在指向lua虚拟机里头某个函数的delegate，为了防止业务在虚拟机释放后调用这些无效（因为其引用的lua函数所在虚拟机都释放了）delegate导致的异常甚至崩溃，做了这个检查。\n\n怎么解决？释放这些delegate即可，所谓释放，在C#中，就是没有引用：\n\n你是在C#通过LuaTable.Get获取并保存到对象成员，赋值该成员为null；\n\n你是在lua那把lua函数注册到一些事件事件回调，反注册这些回调；\n\n如果你是通过xlua.hotfix(class, method, func)注入到C#，则通过xlua.hotfix(class, method, nil)删除；\n\n要注意以上操作在Dispose之前完成。\n\n### C#参数（或字段）类型是object时，传递整数默认是以long类型传递，如何指明其它类型？比如int\n\n看[例子11](https://github.com/Tencent/xLua/blob/master/Assets/XLua/Examples/11_RawObject/RawObjectTest.cs)\n\n\n"
  },
  {
    "path": "docs/source/src/v1/guide/features.md",
    "content": "---\ntitle: 特性\ntype: guide\norder: 1001\n---\n\n## 特性\n\n### 总体\n\n* **Lua虚拟机支持**\n * Lua5.3.3\n * Luajit2.1beta2\n<br>\n* **Unity3D版本支持**\n * Unity5\n * Unity4\n<br>\n* **平台支持**\n * windows 64/32\n * android\n * ios 64/32/bitcode\n * osx\n<br>\n* **互访技术**\n * 生成适配代码\n * 反射\n<br>\n* **易用性**\n * 解压即可用\n * 开发期无需生成代码\n * 生成代码和反射间可无缝切换\n * 更简单的无GC api\n * 菜单简单易懂\n * 配置可以多份，按模块划分，也可以直接在目标类型上打Attribute标签\n * 自动生成link.xml防止代码剪裁\n * Plugins部分采用cmake编译，更简单\n * 核心代码不依赖生成代码，可以随时删除生成目录\n<br>\n* **性能**\n * Lazyload技术，避免用不上的类型的开销\n * lua函数映射到c# delegate，lua table映射到interface，可实现接口层面无C# gc alloc开销\n * 所有基本值类型，所有枚举，字段都是值类型的struct，在Lua和C#间传递无C# gc alloc\n * LuaTable，LuaFunction提供无gc访问接口\n * 通过代码生成期的静态分析，生成最优代码\n * 支持C#和Lua间指针传递\n * 自动解除已经Destroy的UnityEngine.Object的引用\n<br>\n* **扩展性**\n * 不用改代码就可以加入Lua第三方扩展\n * 生成引擎提供接口做二次开发\n \n### 支持为如下C#实现打补丁\n\n * 构造函数\n * 析构函数\n * 成员函数\n * 静态函数\n * 泛化函数\n * 操作符重载\n * 成员属性\n * 静态属性\n * 事件\n \n### Lua代码加载\n\n* **加载字符串**\n * 支持加载后立即执行\n * 支持加载后返回一个delegate或者LuaFunction，调用delegate或者LuaFunction后可传脚本参数\n<br>\n* **Resources目录的文件**\n * 直接require\n<br>\n* **自定义loader**\n * Lua里头require时触发\n * require参数透传给loader，loader读取Lua代码返回\n<br>\n* **Lua原有的方式**\n * Lua原有的方式都保留\n \n### Lua调用C#\n\n* 创建C#对象\n* C#静态属性，字段\n* C#静态方法\n* C#成员属性，字段\n* C#成员方法\n<br>\n* **C#继承**\n * 子类对象可以直接调用父类的方法，访问父类属性\n * 子类模块可以直接调用父类的静态方法，静态属性\n<br>\n* **扩展方法（Extension methods）**\n * 就像普通成员方法一样使用\n<br>\n* **参数的输入输出属性（out，ref）**\n * out对应一个lua返回值\n * ref对应一个lua参数以及一个lua返回值\n<br>\n* **函数重载**\n * 支持重载\n * 由于lua数据类型远比C#要少，会出现无法判断的情况，可通过扩展方法来来调用。\n<br>\n* **操作符重载**\n * 支持的操作符：+，-，*，/，==，一元-，<，<=， %，[]\n * 其它操作符可以借助扩展方法调用\n<br>\n* **参数默认值**\n * C#参数有默认值，在lua可以不传\n<br>\n* **可变参数**\n * 在对应可变参数部分，直接输入一个个参数即可，不需要把这些参数扩到一个数组里头\n<br>\n* **泛化方法调用**\n * 静态方法可以自行封装使用\n * 成员函数可通过扩展方法封装使用\n<br>\n* **枚举类型**\n * 数字或字符串到枚举的转换\n<br>\n* **delegate**\n * 调用一个C# delegate\n * +操作符\n * -操作符\n * 把一个lua函数作为一个c# delegate传递给c#\n<br>\n* **event**\n * 增加事件回调\n * 移除事件回调\n<br>\n* **64位整数**\n * 传递无gc而且无精度损失\n * lua53下使用原生64位支持\n * 可以和number运算\n * 以java的方式支持无符号64位整数\n<br>\n* **table的自动转换到C#复杂类型**\n * obj.complexField = {a = 1, b = {c = 1}}，obj是一个C#对象，complexField是两层嵌套的struct或者class\n<br>\n* **typeof**\n * 对应C#的typeof操作符，返回Type对象\n<br>\n* lua侧直接clone\n<br>\n* **decimal**\n * 传递无gc而且无精度损失\n\n### C#调用Lua\n\n* **调用Lua函数**\n * 以delegate方式调用Lua函数\n * 以LuaFunction调用lua函数\n<br>\n* **访问Lua的table**\n * LuaTable的泛化Get/Set接口，调用无gc，可指明Key，Value的类型\n * 用标注了CSharpCallLua的interface访问\n * 值拷贝到struct，class\n \n### Lua虚拟机\n\n* 虚拟机gc参数读取及设置\n\n### 工具链\n\n* **Lua Profiler**\n * 可根据函数调用总时长，平均每次调用时长，调用次数排序\n * 显示lua函数名及其所在文件的名字及行号\n * 如果C#函数，会显示这个是C#函数\n<br>\n* 支持真机调试\n\n"
  },
  {
    "path": "docs/source/src/v1/guide/gc-optimization.md",
    "content": "---\ntitle: GC优化指南\ntype: guide\norder: 102\n---\n\n## GC优化指南\n\n> Todo:请在此处输入内容"
  },
  {
    "path": "docs/source/src/v1/guide/hotfix.md",
    "content": "---\ntitle: 热标识\ntype: guide\norder: 1000\n---\n\n## 热标识\n\n### 使用方式\n\n1、添加HOTFIX_ENABLE宏打开该特性（在Unity3D的File->Build Setting->Scripting Define Symbols下添加）。编辑器、各手机平台这个宏要分别设置！如果是自动化打包，要注意在代码里头用API设置的宏是不生效的，需要在编辑器设置。\n\n（建议平时开发业务代码不打开HOTFIX_ENABLE，只在build手机版本或者要在编译器下开发补丁时打开HOTFIX_ENABLE）\n\n2、执行XLua/Generate Code菜单。\n\n3、注入，构建手机包这个步骤会在构建时自动进行，编辑器下开发补丁需要手动执行\"XLua/Hotfix Inject In Editor\"菜单。注入成功会打印“hotfix inject finish!”或者“had injected!”。\n\n### 内嵌模式\n\n默认通过小工具执行代码注入，也可以采用内嵌到编辑器的方式，定义INJECT_WITHOUT_TOOL宏即可。\n\n定义INJECT_WITHOUT_TOOL宏后，热补丁特性依赖Cecil，添加HOTFIX_ENABLE宏之后，可能会报找不到Cecil。这时你需要到Unity安装目录下找到Mono.Cecil.dll，Mono.Cecil.Pdb.dll，Mono.Cecil.Mdb.dll，拷贝到项目里头。\n\n注意：如果你的Unity安装目录没有Mono.Cecil.Pdb.dll，Mono.Cecil.Mdb.dll（往往是一些老版本），那就只拷贝Mono.Cecil.dll（你从别的版本的Unity拷贝一套可能会导致编辑器不稳定），这时你需要定义HOTFIX_SYMBOLS_DISABLE，这会导致C#代码没法调试以及Log的栈源文件及行号错乱（所以赶紧升级Unity）。\n\n参考命令（可能Unity版本不同会略有不同）：\n\n```shell\nOSX命令行 cp /Applications/Unity/Unity.app/Contents/Managed/Mono.Cecil.* Project/Assets/XLua/Src/Editor/\nWin命令行 copy UnityPath\\Editor\\Data\\Managed\\Mono.Cecil.* Project\\Assets\\XLua\\Src\\Editor\\\n```\n\n### 约束\n\n不支持静态构造函数。\n\n不支持在子类override函数通过base调用父类实现。\n\n目前只支持Assets下代码的热补丁，不支持引擎，c#系统库的热补丁。\n\n### API\nxlua.hotfix(class, [method_name], fix)\n\n* 描述         ： 注入lua补丁\n* class        ： C#类，两种表示方法，CS.Namespace.TypeName或者字符串方式\"Namespace.TypeName\"，字符串格式和C#的Type.GetType要求一致，如果是内嵌类型（Nested Type）是非Public类型的话，只能用字符串方式表示\"Namespace.TypeName+NestedTypeName\"；\n* method_name  ： 方法名，可选；\n* fix          ： 如果传了method_name，fix将会是一个function，否则通过table提供一组函数。table的组织按key是method_name，value是function的方式。\n\nxlua.private_accessible(class)\n\n* 描述          ： 让一个类的私有字段，属性，方法等可用\n* class         ： 同xlua.hotfix的class参数\n\n### 标识要热更新的类型\n\n和其它配置一样，有两种方式\n\n方式一：直接在类里头打Hotfix标签；\n\n方式二：在一个static类的static字段或者属性里头配置一个列表。属性可以用于实现的比较复杂的配置，比如根据Namespace做白名单。\n\n```csharp\npublic static class HotfixCfg\n{\n    [Hotfix]\n    public static List<Type> by_field = new List<Type>()\n    {\n        typeof(HotFixSubClass),\n        typeof(GenericClass<>),\n    };\n\n    [Hotfix]\n    public static List<Type> by_property\n    {\n        get\n        {\n            return (from type in Assembly.Load(\"Assembly-CSharp\").GetTypes()\n                    where type.Namespace == \"XXXX\"\n                    select type).ToList();\n        }\n    }\n}\n```\n\n### Hotfix Flag\n\nHotfix标签可以设置一些标志位对生成代码及插桩定制化\n\n* Stateless\n\nStateless和Stateful的区别请看下下节。\n\n* Stateful\n\n同上。\n\n* ValueTypeBoxing\n\n值类型的适配delegate会收敛到object，好处是代码量更少，不好的是值类型会产生boxing及gc，适用于对text段敏感的业务。\n\n* IgnoreProperty\n\n不对属性注入及生成适配代码，一般而言，大多数属性的实现都很简单，出错几率比较小，建议不注入。\n\n* IgnoreNotPublic\n\n不对非public的方法注入及生成适配代码。除了像MonoBehaviour那种会被反射调用的私有方法必须得注入，其它仅被本类调用的非public方法可以不注入，只不过修复时会工作量稍大，所有引用到这个函数的public方法都要重写。\n\n* Inline\n\n不生成适配delegate，直接在函数体注入处理代码。\n\n* IntKey\n\n不生成静态字段，而是把所有注入点放到一个数组集中管理。\n\n好处：对text段影响小。\n\n坏处：使用不像默认方式那么方便，需要通过id来指明hotfix哪个函数，而这个id是代码注入工具时分配的，函数到id的映射会保存在Gen/Resources/hotfix_id_map.lua.txt，并且自动加时间戳备份到hotfix_id_map.lua.txt同级目录，发布手机版本后请妥善保存该文件。\n\n该文件的格式大概如下：\n\n```lua\nreturn {\n    [\"HotfixTest\"] = {\n        [\".ctor\"] = {\n            5\n        },\n        [\"Start\"] = {\n            6\n        },\n        [\"Update\"] = {\n            7\n        },\n        [\"FixedUpdate\"] = {\n            8\n        },\n        [\"Add\"] = {\n            9,10\n        },\n        [\"OnGUI\"] = {\n            11\n        },\n    },\n}\n```\n\n想要替换HotfixTest的Update函数，你得\n\n```lua\nCS.XLua.HotfixDelegateBridge.Set(7, func)\n```\n\n如果是重载函数，将会一个函数名对应多个id，比如上面的Add函数。\n\n能不能自动化一些呢？可以，xlua.util提供了auto_id_map函数，执行一次后你就可以像以前那样直接用类，方法名去指明修补的函数。\n\n```lua\n(require 'xlua.util').auto_id_map()\nxlua.hotfix(CS.HotfixTest, 'Update', function(self)\n\t\tself.tick = self.tick + 1\n\t\tif (self.tick % 50) == 0 then\n\t\t\tprint('<<<<<<<<Update in lua, tick = ' .. self.tick)\n\t\tend\n\tend)\n```\n\n前提是hotfix_id_map.lua.txt放到可以通过require 'hotfix_id_map'引用到的地方。\n\nps：虽然xlua执行代码注入时会把hotfix_id_map.lua.txt放到Resources下，但那时似乎Unity已经不再处理新增的文件。貌似可以通过提前执行“Hotfix inject in Editor”来提前生成，但id不一定一样，比如有的类型里头有平台/编辑器专用的api，编辑器下和真机下的id将不一样。\n\n### 使用建议\n\n* 对所有较大可能变动的类型加上Hotfix标识；\n* 建议用反射找出所有函数参数、字段、属性、事件涉及的delegate类型，标注CSharpCallLua；\n* 业务代码、引擎API、系统API，需要在Lua补丁里头高性能访问的类型，加上LuaCallCSharp；\n* 引擎API、系统API可能被代码剪裁调（C#无引用的地方都会被剪裁），如果觉得可能会新增C#代码之外的API调用，这些API所在的类型要么加LuaCallCSharp，要么加ReflectionUse；\n\n### Stateless和Stateful\n\n打Hotfix标签时，默认是Stateless方式，你也可以选Stateful方式，我们先说区别，再说使用场景。\n\nStateless方式是指用Lua对成员函数修复时，C#对象直接透传给作为Lua函数的第一个参数。\n\nStateful方式下你可以在Lua的构造函数返回一个table，然后后续成员函数调用会把这个table给传递过去。\n\nStateless比较适合无状态的类，有状态的话，你得通过反射去操作私有成员，也没法新增状态（field）。Stateless有个好处，可以运行的任意时刻执行替换。\n\nStateful的代价是会在类增加一个LuaTable类型的字段（中间层面增加，不会改源代码）。但这种方式是适用性更广，比如你不想要lua状态，可以在构造函数拦截那返回空。而且操作状态性能比反射操作C#私有变量要好，也可以随意新增任意的状态信息。缺点是，执行成员函数之前就new好的对象，接收到的状态会是空，所以需要重启，在一开始就执行替换。\n\n### 打补丁\n\nxlua可以用lua函数替换C#的构造函数，函数，属性，事件的替换。lua实现都是函数，比如属性对于一个getter函数和一个setter函数，事件对应一个add函数和一个remove函数。\n\n* 函数\n\nmethod_name传函数名，支持重载，不同重载都是转发到同一个lua函数。\n\n比如：\n\n```csharp\n\n// 要fix的C#类\n[Hotfix]\npublic class HotfixCalc\n{\n    public int Add(int a, int b)\n    {\n        return a - b;\n    }\n\n    public Vector3 Add(Vector3 a, Vector3 b)\n    {\n        return a - b;\n    }\n｝\n\n```\n\n```lua\n\nxlua.hotfix(CS.HotfixCalc, 'Add', function(self, a, b)\n    return a + b\nend)\n\n```\n\n静态函数和成员函数的区别是，成员函数会加一个self参数，这个self在Stateless方式下是C#对象本身（对应C#的this），Stateful方式下传lua构造函数实现的返回值（一个table或者nil）\n\n普通参数对于lua的参数，ref参数对应lua的一个参数和一个返回值，out参数对于lua的一个返回值。\n\n泛化函数的打补丁规则和普通函数一样。\n\n* 构造函数\n\n构造函数对应的method_name是`.ctor`。\n\n如果是Stateful方式，你可以返回一个table作为这个对象的状态。\n\n和普通函数不一样的是，构造函数的热补丁并不是替换，而是执行原有逻辑后调用lua。\n\n* 属性\n\n对于名为“AProp”的属性，会对应一个getter，method_name等于get_AProp，setter的method_name等于set_AProp。\n\n* []操作符\n\n赋值对应set_Item，取值对应get_Item。第一个参数是self，赋值后面跟key，value，取值只有key参数，返回值是取出的值。\n\n* 其它操作符\n\nC#的操作符都有一套内部表示，比如+号的操作符函数名是op_Addition（其它操作符的内部表示可以去请参照相关资料），覆盖这函数就覆盖了C#的+号操作符。\n\n* 事件\n\n比如对于事件“AEvent”，+=操作符是add_AEvent，-=对应的是remove_AEvent。这两个函数均是第一个参数是self，第二个参数是操作符后面跟的delegate。\n\n通过xlua.private_accessible来直接访问事件对应的私有delegate的直接访问后，可以通过对象的\"&事件名\"字段直接触发事件，例如self\\['&MyEvent'\\]()，其中MyEvent是事件名。\n\n* 析构函数\n\nmethod_name是\"Finalize\"，传一个self参数。\n\n和普通函数不一样的是，析构函数的热补丁并不是替换，而是开头调用lua函数后继续原有逻辑。\n\n* 泛化类型\n\n其它规则一致，需要说明的是，每个泛化类型实例化后都是一个独立的类型，只能针对实例化后的类型分别打补丁。比如：\n\n```csharp\npublic class GenericClass<T>\n{\n｝\n```\n\n你只能对GenericClass`<double>`，GenericClass`<int>`这些类，而不是对GenericClass打补丁。\n\n另外值得一提的是，要注意泛化类型的命名方式，比如GenericClass`<double>`的命名是GenericClass`1[System.Double]，具体可以看[MSDN](https://msdn.microsoft.com/en-us/library/w3f99sx1.aspx)。\n\n对GenericClass`<double>`打补丁的实例如下：\n\n```csharp\nluaenv.DoString(@\"\n    xlua.hotfix(CS['GenericClass`1[System.Double]'], {\n        ['.ctor'] = function(obj, a)\n            print('GenericClass<double>', obj, a)\n        end;\n        Func1 = function(obj)\n            print('GenericClass<double>.Func1', obj)\n        end;\n        Func2 = function(obj)\n            print('GenericClass<double>.Func2', obj)\n            return 1314\n        end\n    })\n\");\n```\n\n* Unity协程\n\n通过util.cs_generator可以用一个function模拟一个IEnumerator，在里头用coroutine.yield，就类似C#里头的yield return。比如下面的C#代码和对应的hotfix代码是等同效果的\n\n```csharp\n[XLua.Hotfix]\npublic class HotFixSubClass : MonoBehaviour {\n    IEnumerator Start()\n    {\n        while (true)\n        {\n            yield return new WaitForSeconds(3);\n            Debug.Log(\"Wait for 3 seconds\");\n        }\n    }\n}\n```\n\n```csharp\nluaenv.DoString(@\"\n    local util = require 'xlua.util'\n\txlua.hotfix(CS.HotFixSubClass,{\n\t\tStart = function(self)\n\t\t\treturn util.cs_generator(function()\n\t\t\t    while true do\n\t\t\t\t    coroutine.yield(CS.UnityEngine.WaitForSeconds(3))\n                    print('Wait for 3 seconds')\n                end\t\t\t\t\n\t\t\tend\n\t\tend;\n\t})\n\");\n```\n\n* 整个类\n\n如果要替换整个类，不需要一次次的调用xlua.hotfix去替换，可以整个一次完成。只要给一个table，按method_name = function组织即可\n\n```lua\n\nxlua.hotfix(CS.StatefullTest, {\n    ['.ctor'] = function(csobj)\n        return {evt = {}, start = 0}\n    end;\n    set_AProp = function(self, v)\n        print('set_AProp', v)\n        self.AProp = v\n    end;\n    get_AProp = function(self)\n        return self.AProp\n    end;\n    get_Item = function(self, k)\n        print('get_Item', k)\n        return 1024\n    end;\n    set_Item = function(self, k, v)\n        print('set_Item', k, v)\n    end;\n    add_AEvent = function(self, cb)\n        print('add_AEvent', cb)\n        table.insert(self.evt, cb)\n    end;\n    remove_AEvent = function(self, cb)\n       print('remove_AEvent', cb)\n       for i, v in ipairs(self.evt) do\n           if v == cb then\n               table.remove(self.evt, i)\n               break\n           end\n       end\n    end;\n    Start = function(self)\n        print('Start')\n        for _, cb in ipairs(self.evt) do\n            cb(self.start, 2)\n        end\n        self.start = self.start + 1\n    end;\n    StaticFunc = function(a, b, c)\n       print(a, b, c)\n    end;\n    Finalize = function(self)\n       print('Finalize', self)\n    end\n})\n\n```\n\n"
  },
  {
    "path": "docs/source/src/v1/guide/index.md",
    "content": "---\ntitle: 介绍\ntype: guide\norder: 0\n---\n\n## XLua\n\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Tencent/xLua/blob/master/LICENSE.TXT) [![release](https://img.shields.io/badge/release-v2.1.8-blue.svg)](https://github.com/Tencent/xLua/releases) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/Tencent/xLua/pulls)\n\n### C#下Lua编程支持\n\nxLua为Unity、 .Net、 Mono等C#环境增加Lua脚本编程的能力，借助xLua，这些Lua代码可以方便的和C#相互调用。\n\n### xLua的突破\n\nxLua在功能、性能、易用性都有不少突破，这几方面分别最具代表性的是：\n\n* 可以运行时把C#实现（方法，操作符，属性，事件等等）替换成lua实现；\n* 出色的GC优化，自定义struct，枚举在Lua和C#间传递无C# gc alloc；\n* 编辑器下无需生成代码，开发更轻量；\n\n> 更详细的特性、平台支持介绍请看[这里](features.html)。\n\n### 安装\n\n打开zip包，你会看到一个Assets目录，这目录就对应Unity工程的Assets目录，保持这目录结构放到你的Unity工程。\n\n如果希望安装到其它目录，请看[FAQ](faq.html)相关介绍。\n\n### lua5.3 vs luajit\n\nxLua有两个版本，分别集成了lua5.3和luajit，一个项目只能选择其一。这两个版本C#代码是一样的，不同的是Plugins部分。\n\nlua5.3的特性更丰富些，比如支持原生64位整数，支持苹果bitcode，支持utf8等。出现问题因为是纯c代码，也好定位。比起luajit，lua对安装包的影响也更小。\n\n而luajit胜在性能，如果其jit不出问题的话，可以比lua高一个数量级。目前luajit作者不打算维护luajit，在找人接替其维护，后续发展不太明朗。\n\n项目可以根据自己情况判断哪个更适合。因为目前lua53版本使用较多，所以xLua工程Plugins目录下默认配套是lua53版本。\n\n### 快速入门\n\n一个完整的例子仅需3行代码：\n\n安装好xLua，建一个MonoBehaviour拖到场景，在Start加入如下代码：\n\n```csharp\nXLua.LuaEnv luaenv = new XLua.LuaEnv();\nluaenv.DoString(\"CS.UnityEngine.Debug.Log('hello world')\");\nluaenv.Dispose();\n```\n\n1、DoString参数为string，可输入任意合法的Lua代码，本示例在lua里调用C#的UnityEngine.Debug.Log打印了个日志。\n\n2、一个LuaEnv实例对应Lua虚拟机，出于开销的考虑，建议全局唯一。\n\nC#主动调用lua也很简单，比如要调用lua的系统函数，推荐方式是：\n\n* 声明\n\n```csharp\n[XLua.CSharpCallLua]\npublic delegate double LuaMax(double a, double b);\n```\n\n* 绑定\n\n```csharp\nvar max = luaenv.Global.GetInPath<LuaMax>(\"math.max\");\n```\n\n* 调用\n\n```csharp\nDebug.Log(\"max:\" + max(32, 12));\n```\n\n建议绑定一次，重复使用。生成了代码的话，调用max是不产生gc alloc的。\n\n### 热补丁\n\n* 侵入性小，老项目原有代码不做任何调整就可使用。\n* 运行时影响小，不打补丁基本和原有程序一样。\n* 出问题了可以用Lua来打补丁，这时才会走到lua代码逻辑；\n\n> [这里](hotfix.html)是使用指南。\n\n### 更多示例\n\n* [01_Helloworld](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/01_Helloworld/): 快速入门的例子。\n* [02_U3DScripting](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/02_U3DScripting/): 展示怎么用lua来写MonoBehaviour。\n* [03_UIEvent](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/03_UIEvent/): 展示怎么用lua来写UI逻辑。\n* [04_LuaObjectOrented](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/04_LuaObjectOrented/): 展示lua面向对象和C#的配合。\n* [05_NoGc](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/05_NoGc/): 展示怎么去避免值类型的GC。\n* [06_Coroutine](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/06_Coroutine/): 展示lua协程怎么和Unity协程相配合。\n* [07_AsyncTest](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/07_AsyncTest/): 展示怎么用lua协程来把异步逻辑同步化。\n* [08_Hotfix](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/08_Hotfix/): 热补丁的示例（需要开启热补丁特性，如何开启请看[指南](Assets/XLua/Doc/hotfix.md)）。\n* [09_GenericMethod](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/09_GenericMethod/): 泛化函数支持的演示。\n* [10_SignatureLoader](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/10_SignatureLoader/): 展示如何读取经数字签名的lua脚本，参见[数字签名](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/signature.md)的文档介绍。\n* [11_RawObject](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Examples/11_RawObject/): 当C#参数是object时，如何把一个lua number指定以boxing后的int传递过去。\n\n### 文档\n\n* [XLua教程.doc](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua教程.doc)：教程，其配套代码[这里](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Tutorial/)。\n* [XLua的配置](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/configure.md)：介绍如何配置xLua。\n* [XLua增加删除第三方lua库.doc](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua增加删除第三方lua库.doc)：如何增删第三方lua扩展库。\n* [XLua API.doc](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/XLua_API.doc)：API文档。\n* [生成引擎二次开发指南](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/custom_generate.md)：介绍如何做生成引擎的二次开发。\n* [热补丁操作指南](https://github.com/Tencent/xLua/tree/master/Assets/XLua/Doc/hotfix.md)：介绍如何使用热补丁特性。\n\n### 技术支持\n\n> QQ群：612705778 验证答案：有问题先找FAQ"
  },
  {
    "path": "docs/source/src/v1/guide/performance-analysis.md",
    "content": "---\ntitle: 性能分析工具\ntype: guide\norder: 103\n---\n\n## 性能分析工具\n\n> Todo:请在此处输入内容"
  },
  {
    "path": "docs/source/src/v1/guide/signature.md",
    "content": "---\ntitle: 数字签名\ntype: guide\norder: 104\n---\n\n## 数字签名\n\n> Todo:请在此处输入内容"
  },
  {
    "path": "docs/source/src/v1/guide/tutorial.md",
    "content": "---\ntitle: 从零开始\ntype: guide\norder: 100\n---\n\n## 从零开始\n\n> 文章等待完善"
  },
  {
    "path": "docs/source/src/v1/guide/use.md",
    "content": "---\ntitle: 商业案例\ntype: guide\norder: 2\n---\n\n## 商业案例\n\n> 这份文档等待您进行完善"
  },
  {
    "path": "docs/source/src/v1/guide/version.md",
    "content": "---\ntitle: 更新记录\ntype: guide\norder: 1\n---\n\n## 更新记录\n\n> 这份文档等待您进行完善"
  },
  {
    "path": "docs/source/themes/catlib/_config.yml",
    "content": "site_description: \"XLua\"\ngithub: https://github.com/Tencent/xLua\nmodify_github: https://github.com/Tencent/xLua/tree/master/docs/source/src/\ncopyright: © Copyright 2017 Tencent All Rights Reserved\ncopyright_desc: Tencent 2017"
  },
  {
    "path": "docs/source/themes/catlib/layout/index.ejs",
    "content": "<div id=\"mobile-header\">\n    <a id=\"mobile-nav-toggle\" href=\"#\">\n      <span class=\"mobile-nav-toggle-bar\"></span>\n      <span class=\"mobile-nav-toggle-bar\"></span>\n      <span class=\"mobile-nav-toggle-bar\"></span>\n    </a>\n    <a id=\"github\" href=\"<%- theme.github %>\">\n      <img src=\"<%- url_for(\"/images/github.png\") %>\">\n    </a>\n</div>\n\n<div id=\"footer\">\n    <p>© 2017 <a href=\"<%- theme.github %>\">XLua</a></p>\n    <p>Power by XLua / BSD 3 licensed</p>\n</div>"
  },
  {
    "path": "docs/source/themes/catlib/layout/layout.ejs",
    "content": "<% var isIndex = page.path === 'index.html' %>\n<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n\n    <title><%- page.title ? page.title + ' — ' : '' %>XLua</title>\n    <meta charset=\"utf-8\">\n    <meta name=\"description\" content=\"<%- theme.site_description %>\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n\n    <%- css(isIndex ? '/css/index' : '/css/page') %>\n\n    <script src=\"<%- url_for(\"/js/vue.js\") %>\"></script>\n    <script src=\"<%- url_for(\"/js/jquery.js\") %>\"></script>\n    </head>\n\n    <body>\n        <% if(isIndex){ %>\n            <script>window.location.href='v1/guide/index.html';</script>\n        <% }else{ %>\n            <%- partial('page') %>\n        <% } %>\n    </body>\n</html>"
  },
  {
    "path": "docs/source/themes/catlib/layout/page.ejs",
    "content": "<nav class=\"nav\">\n    <div class=\"border\">\n        <img src=\"<%- url_for('images/logo.png')%>\" />\n        <button class=\"hiden-in-phone\">V2.1</button>\n        <button id=\"btn-menu\" class=\"hiden-in-pc\">菜单</button>\n        <ul class=\"nav-link hiden-in-phone\">\n            <!--li>\n                <form id=\"search-form\">\n                    <input type=\"text\" id=\"search-query\" class=\"search-query\">\n                </form>\n            </li!-->\n            <li><a href=\"https://github.com/Tencent/xLua\" class=\"nav-link-li<%- page.path.match(/download/) ? ' current' : '' %>\">下载项目</a></li>\n            <li><a href=\"<%- url_for(\"/v1/guide/use.html\") %>\" class=\"nav-link-li<%- page.path.match(/use/) ? ' current' : '' %>\">使用案例</a></li>\n            <li><a href=\"<%- url_for(\"/v1/guide/version.html\") %>\" class=\"nav-link-li<%- page.path.match(/version/) ? ' current' : '' %>\">更新记录</a></li>\n            <li><a href=\"<%- url_for(\"/v1/guide/contribution.html\") %>\" class=\"nav-link-li<%- page.path.match(/contribution/) ? ' current' : '' %>\">贡献指南</li>\n            <li><a href=\"<%- url_for(\"/v1/guide/index.html\") %>\" class=\"nav-link-li<%- page.path.match(/index/) ? ' current' : '' %>\">教程</a></li>\n            <li><a href=\"<%- url_for(\"/\") %>\" class=\"nav-link-li<%- page.path.match(/\\//) ? ' current' : '' %>\">首页</a></li>\n        </ul>\n    </div>\n</nav>\n\n<div id=\"container\" class=\"container clear\">\n    <%- partial('partials/sidebar') %>\n    <%- partial('partials/article') %>\n</div>\n\n<footer>\n    <div>\n        <p><%- theme.copyright %></p>\n        <p><%- theme.copyright_desc %></p>\n    </div>\n</footer>\n\n\n<script>\nvar vm = new Vue({\n    el : '#container',\n    data: {\n        sub_nav : [ ]\n    },\n    created:function(){\n        var obj = [];\n        $(\"article h3\").each(function(){\n            obj.push({name :  $(this).find(\"a\").attr(\"title\") , href : \"#\"+$(this).attr(\"id\") });\n        });\n\n        this.sub_nav = obj;       \n    }\n});\n\nvar isShow = false;\n$(\"nav\").on(\"click\",\"#btn-menu\" , function(){\n\n    if(!isShow){\n        \n        if($(document).scrollTop() > $(\".sidebar\").height() - 100){\n\n            $('html, body').animate({scrollTop:0} , 300, \"swing\",function(){\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n            });\n        }else{\n\n                $(\".sidebar\").fadeIn();\n                $(\".container\").animate({\"left\" : \"15rem\"}, 500,\"swing\");\n\n        }\n\n    }else{\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n    }\n    isShow = !isShow;\n\n});\n\n$(\".container\").on(\"click\" , \"article\" , function(){\n\n    if(isShow){\n        $(\".sidebar\").fadeOut();\n        $(\".container\").animate({\"left\" : \"0rem\"}, 500,\"swing\");\n        isShow = false;    \n    }\n\n});\n</script>"
  },
  {
    "path": "docs/source/themes/catlib/layout/partials/article.ejs",
    "content": "<article class=\"clearfix\">\n    <%- page.content %>\n    <div class=\"footer\">\n        发现错误？想参与编辑？ \n        <a href=\"<%- theme.modify_github %><%- page.path.replace(/\\.html$/, '.md') %>\" target=\"_blank\">\n            在 Github 上编辑此页！\n        </a>\n    </div>\n</article>\n\n<div class=\"sub-nav hiden-in-phone\">\n    <dl id=\"sub-nav\">\n        <dt>本文内容</dt>\n        <dd v-for=\"(ele, index) in sub_nav\">\n           <a v-bind:href=\"ele.href\">{{ ele.name }}</a>\n        </dd>\n    </dl>\n</div> "
  },
  {
    "path": "docs/source/themes/catlib/layout/partials/sidebar.ejs",
    "content": "<section class=\"sidebar clearfix\">\n    <ul>\n        <% site.pages.find({type: 'guide' , lang: page.lang}).sort('order').each(function (p) { %>\n            <% var fileName = p.path.replace(/^.+?\\/([\\w-]+)\\.html/, '$1') %>\n            <% if(fileName == 'index'){%>\n                <li><h3>基础</h3></li>\n            <%}%>\n            <% if(fileName == 'tutorial'){%>\n                <li><h3>教程</h3></li>\n            <%}%>\n            <% if(fileName == 'hotfix'){%>\n                <li><h3>其他</h3></li>\n            <%}%>\n            <li>\n                <p><a href=\"<%- url_for(p.path) %>\" class=\"sidebar-link<%- page.title === p.title ? ' current' : '' %><%- p.is_new ? ' new' : '' %>\"><%- p.title %></a></p>\n            </li>\n        <% }) %>\n    </ul>\n</section>"
  },
  {
    "path": "docs/source/themes/catlib/source/css/_common.styl",
    "content": "@import \"_settings\"\n\nbody,footer,header, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, form, fieldset, legend, button, input, textarea, th, td\n    margin 0\n    padding 0\n\ttext-align center\n\t-webkit-text-size-adjust none\n\tcolor: $main-color\n\nbody,button, input, select, textarea, ol,p, blockquote, dl, dt, dd, ul, ol, li, form, fieldset, legend, button, input, textarea, th, td\n    outline none \n    font 1em \"Helvetica Neue\",\"Helvetica\",\"Lucida Grande\",\"Arial\",\"Hiragino Sans GB\",\"Microsoft Yahei\",\"WenQuanYi Micro Hei\",\"sans-serif\",arial,sans-serif; \n    text-align left\n    color: $main-color\n\nbody\n    background-color white \n    background-attachment fixed\n\nul, ol \n    list-style none\n\na\n\ttext-decoration none\n    transition all 0.5s\n    -moz-transition all 0.5s\n    -webkit-transition all 0.5s\n    -o-transition all 0.5s\n    cursor pointer\n\tcolor: $main-color\n\ttext-decoration none\n\na:hover\n    text-decoration underline \n    outline 0 \n    color: $main-color\n\n.abs \n    position absolute\n\n.clear:after\n    content \".\"  \n    display block  \n    height 0 \n    clear both \n    visibility hidden\n\n.clear\n     zoom 1\n\nbutton\n    border none\n\nhtml\n    overflow-x hidden\n    \nbody \n    min-width 20rem  \n    overflow-x hidden\n\n.border\n    padding-left 1rem \n    padding-right 1rem"
  },
  {
    "path": "docs/source/themes/catlib/source/css/_markdown.styl",
    "content": "article\n    color:rgb(82,82,82); \n    text-align left\n    h1,h2\n        font-size 2.25rem \n        font-weight 500\n        margin-bottom 3rem\n    h3,h4,h5\n        font-weight 400\n    h3\n        font-size 1.375rem \n        margin-top 3.125rem\n        margin-bottom 1.875rem\n    h3:before\n        content \"#\"\n        margin-right 0.25rem \n        color $main-color \n        opacity 0.3\n    h4\n        font-size 1rem  \n        margin-top 2.125rem\n        margin-bottom 1.25rem\n    h5\n        font-size 1rem\n        margin-left 1.25rem\n        margin-top 2.125rem\n    p\n        font-size 1rem\n        margin-bottom 1.25rem \n        margin-top 0.625rem \n        line-height 1.8\n        color rgb(82,82,82)\n    ul\n        padding-left 2 rem\n        position inherit\n        list-style disc\n        font-size 0.9rem\n        li\n            padding-top 0.25rem\n            color rgb(82,82,82);\n    table\n        width 100%\n        border-collapse collapse \n        border 0\n        border-spacing 0  \n        margin-bottom 1rem\n        margin-top 1rem;\n        tr:nth-child(even) \n            td\n                background-color rgb(247,247,247)\n        .title-row \n            background-color #ededed\n        tr \n            th, td\n                padding 0.5rem 1rem 0.5rem 1rem\n                color rgb(82,82,82)\n            th\n                background-color #e8e8e8\n                font-weight bold\n                font-size 0.85rem\n            td\n                font-size 0.75rem\n    blockquote\n        padding 12px 24px 12px 30px\n        margin 2em 0\n        border-left 4px solid $main-color\n        background-color rgb(248,248,248)\n        position relative\n        p\n            padding 0\n            margin 0\n        &:before\n            position absolute\n            top 14px\n            left -12px\n            background-color $main-color\n            color #fff\n            content \"!\"\n            width 20px\n            height 20px\n            border-radius 100%\n            text-align center\n            line-height 20px\n            font-weight bold\n            font-family $code-font\n            font-size 14px\n        code\n            background-color #efefef\n        em\n            color $medium\n    code\n        border-radius 3px \n        background-color rgb(240, 242, 241) \n        font-size 0.75rem\n        line-height 1.8 \n        padding 1px 5px 1px 5px \n        color: $main-color \n        font-family source-code-pro, monospace\n        margin-left 5px \n        margin-right 5px\n        text-shadow 0px 1px white\n    p.tip\n        background-color: $main-color\n        border-radius 3px\n        color #fff\n        padding 10px 15px 10px 15px\n        margin-bottom 50px\n        a\n            color #FFF\n        p\n            color #FFF\n            margin 0 auto\n        p a\n            text-decoration underline\n            color #FFF\n        p a:hover\n            color:rgb(252,216,214);\n    ol\n        list-style-type:none;\n        counter-reset:sectioncounter;\n        padding-left 1 rem\n        position inherit\n        font-size 0.9rem\n        li\n            color rgb(82,82,82);\n            padding-top 0.25rem\n        li:before\n            content:counter(sectioncounter) \". \"\n            counter-increment:sectioncounter \n    hr\n        height:1px;\n        border:none;\n        border-top:1px dashed rgb(220,220,220);\n    figure\n        margin 1.2rem 0\n    .highlight\n        overflow-x auto\n        position relative\n        padding 0\n        background-color rgb(248,248,248)\n        padding .8rem .8rem .4rem\n        line-height 1.1rem\n        border-radius $radius\n        font-size 0.85rem\n        table, tr, td\n            width 100%\n            border-collapse collapse\n            padding 0\n            margin 0\n        .gutter\n            width 1.5rem\n        .code\n            $code-line-height = 1.5rem\n            color #525252\n            font-size 0.825rem\n            pre\n                padding 1.2rem 1.4rem\n                line-height $code-line-height\n                margin 0\n            .line\n                min-height $code-line-height\n        &.html, &.js, &.bash, &.css, &.csharp, &.lua\n            .code:after\n                position absolute\n                top 0\n                right 0\n                color #ccc\n                text-align right\n                font-size .75rem\n                padding 5px 10px 0\n                line-height 15px\n                height 15px\n                font-weight 600\n        &.html .code:after\n            content 'HTML'\n        &.csharp .code:after\n            content 'C#'\n        &.lua .code:after\n            content 'Lua'\n        &.js .code:after\n            content 'JS'\n        &.bash .code:after\n            content 'Shell'\n        &.css .code:after\n            content 'CSS'\n    .gutter pre\n        color #999\n    pre\n        color: #525252\n        .function .keyword,\n        .constant\n            color: $main-color\n        .keyword,\n        .attribute\n            color: $main-color\n        .number,\n        .literal\n            color: #AE81FF\n        .tag,\n        .tag .title,\n        .change,\n        .winutils,\n        .flow,\n        .lisp .title,\n        .clojure .built_in,\n        .nginx .title,\n        .tex .special\n            color: #2973b7\n        .class .title\n            color: white\n        .symbol,\n        .symbol .string,\n        .value,\n        .regexp\n            color: $main-color\n        .title\n            color: #2973b7\n        .tag .value,\n        .string,\n        .subst,\n        .haskell .type,\n        .preprocessor,\n        .ruby .class .parent,\n        .built_in,\n        .sql .aggregate,\n        .django .template_tag,\n        .django .variable,\n        .smalltalk .class,\n        .javadoc,\n        .django .filter .argument,\n        .smalltalk .localvars,\n        .smalltalk .array,\n        .attr_selector,\n        .pseudo,\n        .addition,\n        .stream,\n        .envvar,\n        .apache .tag,\n        .apache .cbracket,\n        .tex .command,\n        .prompt\n            color: $main-color\n        .comment,\n        .java .annotation,\n        .python .decorator,\n        .template_comment,\n        .pi,\n        .doctype,\n        .deletion,\n        .shebang,\n        .apache .sqbracket,\n        .tex .formula\n            color: #b3b3b3\n        .coffeescript .javascript,\n        .javascript .xml,\n        .tex .formula,\n        .xml .javascript,\n        .xml .vbscript,\n        .xml .css,\n        .xml .cdata\n            opacity: 0.5\n\n@media screen and (min-width: 960px)\n    article\n        .highlight\n            font-size 1.125rem"
  },
  {
    "path": "docs/source/themes/catlib/source/css/_settings.styl",
    "content": "// font faces\n$body-font = 'Source Sans Pro', 'Helvetica Neue', \"微软雅黑\", \"黑体\", serif , Arial, sans-serif\n$code-font = 'Roboto Mono', Monaco, courier, monospace\n\n// font sizes\n$body-font-size = 15px\n\n// colors\n$main-color      = #3d9cff\n$contrast-color  = #ffffff\n$main-bg-color   = #fafafa\n\n$main-font-color = #2c3e50\n$sub-font-color = rgb(200,200,200)\n\n//header\n$heading-padding-vertical = 6px\n$header-height = 32px"
  },
  {
    "path": "docs/source/themes/catlib/source/css/_sidebar.styl",
    "content": ".sidebar \n    ul\n        padding-bottom 0.9375rem\n        h3\n            color #525252 \n            font-size 1.125rem \n            padding-bottom 0.625rem \n            margin-bottom 0.625rem\n            padding-top 1.25rem\n            font-weight normal\n        li\n            font-size 0.875rem \n            padding-bottom 0.5rem \n            text-indent 1em\n            p\n                padding-left: 1rem;\n\n.sub-nav \n    ul \n        h3\n            color #525252 \n            font-weight 700 \n            margin-bottom 1rem\n            padding-left 0.5rem\n        \n        li\n            margin-bottom 0.25rem \n            padding-left 0.5rem\n            p\n                padding-left: 1rem;\n        \n        li.select\n            border-left 0.125rem #f4645f solid \n            padding-left 0.375rem"
  },
  {
    "path": "docs/source/themes/catlib/source/css/index.styl",
    "content": "@import \"_common\"\n\n#footer\n    color rgb(125,125,125)\n    background-color #171f26\n    text-align center\n    font-size 14px\n    padding 85px\n    p\n        padding-top 5px\n        a\n            color rgb(125,125,125)\n\n#mobile-header\n    display none\n\n#header\n    background-color: $main-color;\n    height: $header-height\n    padding $heading-padding-vertical 20px\n    position relative\n    z-index 999\n\n #nav\n    list-style-type none\n    margin 0\n    padding 0\n    position absolute\n    right 30px\n    top $heading-padding-vertical\n    height $header-height\n    line-height $header-height\n    .break\n        display none\n    li\n        display inline-block\n        position relative\n        margin 0 .6em\n        color: $contrast-color\n        a\n            color: $contrast-color\n\n#logo\n    display inline-block\n    font-size 1.5em\n    line-height $header-height\n    color $main-font-color\n    font-family $logo-font\n    font-weight 500\n    img\n        vertical-align middle\n        margin-right 6px\n        width $header-height\n        height $header-height\n\n.search-query\n    height 26px\n    line-height 30px\n    padding 0 15px 0 30px\n    margin-bottom 3px\n    border 1px solid #fff\n    color $main-font-color\n    outline none\n    border-radius 15px\n    margin-right 5px\n    transition .2s ease\n    background url(../images/search.png) 8px 4px no-repeat\n    background-size 20px\n    vertical-align middle !important\n    &:focus\n        background #fff url(../images/search.focus.png) 8px 4px no-repeat\n        background-size 20px\n\n@media screen and (max-width: 899px)\n    #mobile-header\n        position relative\n        padding $heading-padding-vertical 20px\n        height: $header-height\n        display block\n        background-color: $main-color;\n        #github\n            display block\n            float right\n            img\n                width: $header-height\n                height: $header-height\n                \n        #mobile-nav-toggle\n            padding-top 4px\n            float left\n            .mobile-nav-toggle-bar\n                border-bottom: 2px solid $contrast-color\n                display block\n                width 25px\n                height 2px\n                margin-bottom 4px\n\n    #header\n        display: none\n\n\n#index-body\n    background: $main-color\n    height 325px\n    text-align center\n    h2\n        color: $contrast-color\n        padding 40px 40px\n        line-height: 50px\n        font-size 24px\n        margin-bottom 30px\n    #get-start\n        border: 1px solid $contrast-color\n        padding 12px 40px\n        color: $contrast-color\n    \n    #get-start:hover\n        background-color: $contrast-color\n        color: $main-color\n\n@media screen and (max-width: 699px)\n    #index-content\n        padding 60px 40px 40px 40px\n        text-align center\n        .intro-feature\n            height 135px\n            padding-bottom 60px\n            text-align center\n            img\n                width 45px\n                height 45px\n            h3\n                color: $main-color\n                font-size 20px\n                padding-bottom 20px;\n            p\n                text-align center\n                font-size 14px\n\n@media screen and (min-width: 700px)\n    #index-body\n        height 500px\n        h2\n            padding 120px 80px 80px 80px\n            font-size 36px\n\n    #index-content\n        padding 60px 40px 40px 40px\n        text-align center\n        li\n            width 50%\n            float left\n            .intro-feature\n                text-align center\n                height 135px\n                padding-bottom 60px\n                img\n                    width 45px\n                    height 45px\n                h3\n                    color: $main-color\n                    font-size 24px\n                p\n                    text-align center\n                    font-size 15px\n\n    #index-content\n        ul\n            margin 0 auto\n            max-width 1150px"
  },
  {
    "path": "docs/source/themes/catlib/source/css/page.styl",
    "content": "@import \"_common\"\n@import \"_sidebar\"\n@import \"_markdown\"\n\nnav\n    height 5rem\n    background-color $main-bg-color\n    position absolute\n    width 100%\n    z-index 9999\n    img\n        width 140px\n        height 42px \n        float left \n        position absolute  \n        margin-top 1rem\n    \n    .nav-link\n        li\n            float right \n            padding 1.75rem 1rem\n            a\n                color $main-color\n    \n    button\n        float right\n        margin-top 1rem\n        padding 0.75rem 1.25rem\n        background-color $main-color\n        color $contrast-color\n        border-radius 5px\n        margin-top 0.4rem\n\n.container\n    margin 0 auto \n    max-width 80rem \n    padding 0rem 10rem 3rem 15rem \n    position relative\n\n.sidebar\n    padding 2.187rem \n    padding-top 7rem \n    width 11.25rem \n    margin-left -15rem \n    float left\n\narticle \n    padding 7.75rem 7.75rem 0rem 3.25rem \n    margin-left 1.25rem\n\n.sub-nav\n    position absolute\n    top 15rem \n    right 0 \n    width 10rem\n\n    dl \n        dt\n            color #525252 \n            font-weight 700\n            margin-bottom 1rem\n            padding-left 0.5rem\n        \n        dd\n            margin-bottom 0.25rem\n            padding-left 0.5rem\n            overflow hidden\n            text-overflow ellipsis\n        dd.select\n            border-left:0.125rem #f4645f solid; \n            padding-left:0.375rem;\n\n.footer\n    text-align center;\n    margin-top 2.75rem;\n    color: $sub-font-color\n    font-size 0.75rem\n\nfooter\n    background-color rgb(52,52,52) \n    height 3.125rem \n    padding 1.875rem\n\nfooter p\n    text-align center \n    color rgb(174,174,174) \n    font-size 0.8125rem \n    line-height 1.8\n\n.disable\n    color rgb(175,175,175)\n\n.disable:hover \n    color rgb(175,175,175) \n    text-decoration none\n\n@media screen and (min-width: 960px)\n    .hiden-in-pc \n        display none\n\n    .hiden-in-phone \n        display inline\n\n    nav \n        button\n            margin-top 1rem\n        button:hover\n            background-color #dc504b\n    \n    footer\n        padding 3.125rem\n\n@media screen and (max-width: 960px)\n    .hiden-in-pc \n        display inline\n    \n    .hiden-in-phone \n        display none\n        \n    nav\n        height 3rem\n        position fixed\n        button\n            margin-top 0.4rem \n            padding 0.35rem 0.75rem\n        img\n            width 110px\n            height 30px\n            margin-top 0.5rem\n\n    .container\n        margin 0\n        padding 0rem 0rem 3rem 0rem\n\n    .sidebar\n        display none\n        \n    article\n        padding 5.5rem 1.75rem 0.2rem 0.2rem \n        min-height 35rem"
  },
  {
    "path": "docs/source/themes/catlib/source/js/jquery.js",
    "content": "/*! jQuery v3.2.1 | (c) JS Foundation and other contributors | jquery.org/license */\n!function(a,b){\"use strict\";\"object\"==typeof module&&\"object\"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error(\"jQuery requires a window with a document\");return b(a)}:b(a)}(\"undefined\"!=typeof window?window:this,function(a,b){\"use strict\";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement(\"script\");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q=\"3.2.1\",r=function(a,b){return new r.fn.init(a,b)},s=/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null==a?f.call(this):a<0?this[a+this.length]:this[a]},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.prevObject=this,b},each:function(a){return r.each(this,a)},map:function(a){return this.pushStack(r.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(f.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(a<0?b:0);return this.pushStack(c>=0&&c<b?[this[c]]:[])},end:function(){return this.prevObject||this.constructor()},push:h,sort:c.sort,splice:c.splice},r.extend=r.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for(\"boolean\"==typeof g&&(j=g,g=arguments[h]||{},h++),\"object\"==typeof g||r.isFunction(g)||(g={}),h===i&&(g=this,h--);h<i;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(r.isPlainObject(d)||(e=Array.isArray(d)))?(e?(e=!1,f=c&&Array.isArray(c)?c:[]):f=c&&r.isPlainObject(c)?c:{},g[b]=r.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},r.extend({expando:\"jQuery\"+(q+Math.random()).replace(/\\D/g,\"\"),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return\"function\"===r.type(a)},isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){var b=r.type(a);return(\"number\"===b||\"string\"===b)&&!isNaN(a-parseFloat(a))},isPlainObject:function(a){var b,c;return!(!a||\"[object Object]\"!==k.call(a))&&(!(b=e(a))||(c=l.call(b,\"constructor\")&&b.constructor,\"function\"==typeof c&&m.call(c)===n))},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+\"\":\"object\"==typeof a||\"function\"==typeof a?j[k.call(a)]||\"object\":typeof a},globalEval:function(a){p(a)},camelCase:function(a){return a.replace(t,\"ms-\").replace(u,v)},each:function(a,b){var c,d=0;if(w(a)){for(c=a.length;d<c;d++)if(b.call(a[d],d,a[d])===!1)break}else for(d in a)if(b.call(a[d],d,a[d])===!1)break;return a},trim:function(a){return null==a?\"\":(a+\"\").replace(s,\"\")},makeArray:function(a,b){var c=b||[];return null!=a&&(w(Object(a))?r.merge(c,\"string\"==typeof a?[a]:a):h.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:i.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;d<c;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;f<g;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,e,f=0,h=[];if(w(a))for(d=a.length;f<d;f++)e=b(a[f],f,c),null!=e&&h.push(e);else for(f in a)e=b(a[f],f,c),null!=e&&h.push(e);return g.apply([],h)},guid:1,proxy:function(a,b){var c,d,e;if(\"string\"==typeof b&&(c=a[b],b=a,a=c),r.isFunction(a))return d=f.call(arguments,2),e=function(){return a.apply(b||this,d.concat(f.call(arguments)))},e.guid=a.guid=a.guid||r.guid++,e},now:Date.now,support:o}),\"function\"==typeof Symbol&&(r.fn[Symbol.iterator]=c[Symbol.iterator]),r.each(\"Boolean Number String Function Array Date RegExp Object Error Symbol\".split(\" \"),function(a,b){j[\"[object \"+b+\"]\"]=b.toLowerCase()});function w(a){var b=!!a&&\"length\"in a&&a.length,c=r.type(a);return\"function\"!==c&&!r.isWindow(a)&&(\"array\"===c||0===b||\"number\"==typeof b&&b>0&&b-1 in a)}var x=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u=\"sizzle\"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c]===b)return c;return-1},J=\"checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped\",K=\"[\\\\x20\\\\t\\\\r\\\\n\\\\f]\",L=\"(?:\\\\\\\\.|[\\\\w-]|[^\\0-\\\\xa0])+\",M=\"\\\\[\"+K+\"*(\"+L+\")(?:\"+K+\"*([*^$|!~]?=)\"+K+\"*(?:'((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\"|(\"+L+\"))|)\"+K+\"*\\\\]\",N=\":(\"+L+\")(?:\\\\((('((?:\\\\\\\\.|[^\\\\\\\\'])*)'|\\\"((?:\\\\\\\\.|[^\\\\\\\\\\\"])*)\\\")|((?:\\\\\\\\.|[^\\\\\\\\()[\\\\]]|\"+M+\")*)|.*)\\\\)|)\",O=new RegExp(K+\"+\",\"g\"),P=new RegExp(\"^\"+K+\"+|((?:^|[^\\\\\\\\])(?:\\\\\\\\.)*)\"+K+\"+$\",\"g\"),Q=new RegExp(\"^\"+K+\"*,\"+K+\"*\"),R=new RegExp(\"^\"+K+\"*([>+~]|\"+K+\")\"+K+\"*\"),S=new RegExp(\"=\"+K+\"*([^\\\\]'\\\"]*?)\"+K+\"*\\\\]\",\"g\"),T=new RegExp(N),U=new RegExp(\"^\"+L+\"$\"),V={ID:new RegExp(\"^#(\"+L+\")\"),CLASS:new RegExp(\"^\\\\.(\"+L+\")\"),TAG:new RegExp(\"^(\"+L+\"|[*])\"),ATTR:new RegExp(\"^\"+M),PSEUDO:new RegExp(\"^\"+N),CHILD:new RegExp(\"^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\\\(\"+K+\"*(even|odd|(([+-]|)(\\\\d*)n|)\"+K+\"*(?:([+-]|)\"+K+\"*(\\\\d+)|))\"+K+\"*\\\\)|)\",\"i\"),bool:new RegExp(\"^(?:\"+J+\")$\",\"i\"),needsContext:new RegExp(\"^\"+K+\"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\\\(\"+K+\"*((?:-\\\\d)?\\\\d*)\"+K+\"*\\\\)|)(?=[^-]|$)\",\"i\")},W=/^(?:input|select|textarea|button)$/i,X=/^h\\d$/i,Y=/^[^{]+\\{\\s*\\[native \\w/,Z=/^(?:#([\\w-]+)|(\\w+)|\\.([\\w-]+))$/,$=/[+~]/,_=new RegExp(\"\\\\\\\\([\\\\da-f]{1,6}\"+K+\"?|(\"+K+\")|.)\",\"ig\"),aa=function(a,b,c){var d=\"0x\"+b-65536;return d!==d||c?b:d<0?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ba=/([\\0-\\x1f\\x7f]|^-?\\d)|^-$|[^\\0-\\x1f\\x7f-\\uFFFF\\w-]/g,ca=function(a,b){return b?\"\\0\"===a?\"\\ufffd\":a.slice(0,-1)+\"\\\\\"+a.charCodeAt(a.length-1).toString(16)+\" \":\"\\\\\"+a},da=function(){m()},ea=ta(function(a){return a.disabled===!0&&(\"form\"in a||\"label\"in a)},{dir:\"parentNode\",next:\"legend\"});try{G.apply(D=H.call(v.childNodes),v.childNodes),D[v.childNodes.length].nodeType}catch(fa){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s=b&&b.ownerDocument,w=b?b.nodeType:9;if(d=d||[],\"string\"!=typeof a||!a||1!==w&&9!==w&&11!==w)return d;if(!e&&((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,p)){if(11!==w&&(l=Z.exec(a)))if(f=l[1]){if(9===w){if(!(j=b.getElementById(f)))return d;if(j.id===f)return d.push(j),d}else if(s&&(j=s.getElementById(f))&&t(b,j)&&j.id===f)return d.push(j),d}else{if(l[2])return G.apply(d,b.getElementsByTagName(a)),d;if((f=l[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(f)),d}if(c.qsa&&!A[a+\" \"]&&(!q||!q.test(a))){if(1!==w)s=b,r=a;else if(\"object\"!==b.nodeName.toLowerCase()){(k=b.getAttribute(\"id\"))?k=k.replace(ba,ca):b.setAttribute(\"id\",k=u),o=g(a),h=o.length;while(h--)o[h]=\"#\"+k+\" \"+sa(o[h]);r=o.join(\",\"),s=$.test(a)&&qa(b.parentNode)||b}if(r)try{return G.apply(d,s.querySelectorAll(r)),d}catch(x){}finally{k===u&&b.removeAttribute(\"id\")}}}return i(a.replace(P,\"$1\"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+\" \")>d.cacheLength&&delete b[a.shift()],b[c+\" \"]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement(\"fieldset\");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split(\"|\"),e=c.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&a.sourceIndex-b.sourceIndex;if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return\"input\"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return(\"input\"===c||\"button\"===c)&&b.type===a}}function oa(a){return function(b){return\"form\"in b?b.parentNode&&b.disabled===!1?\"label\"in b?\"label\"in b.parentNode?b.parentNode.disabled===a:b.disabled===a:b.isDisabled===a||b.isDisabled!==!a&&ea(b)===a:b.disabled===a:\"label\"in b&&b.disabled===a}}function pa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function qa(a){return a&&\"undefined\"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return!!b&&\"HTML\"!==b.nodeName},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=n.documentElement,p=!f(n),v!==n&&(e=n.defaultView)&&e.top!==e&&(e.addEventListener?e.addEventListener(\"unload\",da,!1):e.attachEvent&&e.attachEvent(\"onunload\",da)),c.attributes=ja(function(a){return a.className=\"i\",!a.getAttribute(\"className\")}),c.getElementsByTagName=ja(function(a){return a.appendChild(n.createComment(\"\")),!a.getElementsByTagName(\"*\").length}),c.getElementsByClassName=Y.test(n.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!n.getElementsByName||!n.getElementsByName(u).length}),c.getById?(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){return a.getAttribute(\"id\")===b}},d.find.ID=function(a,b){if(\"undefined\"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c?[c]:[]}}):(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){var c=\"undefined\"!=typeof a.getAttributeNode&&a.getAttributeNode(\"id\");return c&&c.value===b}},d.find.ID=function(a,b){if(\"undefined\"!=typeof b.getElementById&&p){var c,d,e,f=b.getElementById(a);if(f){if(c=f.getAttributeNode(\"id\"),c&&c.value===a)return[f];e=b.getElementsByName(a),d=0;while(f=e[d++])if(c=f.getAttributeNode(\"id\"),c&&c.value===a)return[f]}return[]}}),d.find.TAG=c.getElementsByTagName?function(a,b){return\"undefined\"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if(\"*\"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){if(\"undefined\"!=typeof b.getElementsByClassName&&p)return b.getElementsByClassName(a)},r=[],q=[],(c.qsa=Y.test(n.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML=\"<a id='\"+u+\"'></a><select id='\"+u+\"-\\r\\\\' msallowcapture=''><option selected=''></option></select>\",a.querySelectorAll(\"[msallowcapture^='']\").length&&q.push(\"[*^$]=\"+K+\"*(?:''|\\\"\\\")\"),a.querySelectorAll(\"[selected]\").length||q.push(\"\\\\[\"+K+\"*(?:value|\"+J+\")\"),a.querySelectorAll(\"[id~=\"+u+\"-]\").length||q.push(\"~=\"),a.querySelectorAll(\":checked\").length||q.push(\":checked\"),a.querySelectorAll(\"a#\"+u+\"+*\").length||q.push(\".#.+[+~]\")}),ja(function(a){a.innerHTML=\"<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>\";var b=n.createElement(\"input\");b.setAttribute(\"type\",\"hidden\"),a.appendChild(b).setAttribute(\"name\",\"D\"),a.querySelectorAll(\"[name=d]\").length&&q.push(\"name\"+K+\"*[*^$|!~]?=\"),2!==a.querySelectorAll(\":enabled\").length&&q.push(\":enabled\",\":disabled\"),o.appendChild(a).disabled=!0,2!==a.querySelectorAll(\":disabled\").length&&q.push(\":enabled\",\":disabled\"),a.querySelectorAll(\"*,:x\"),q.push(\",.*:\")})),(c.matchesSelector=Y.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,\"*\"),s.call(a,\"[s!='']:x\"),r.push(\"!=\",N)}),q=q.length&&new RegExp(q.join(\"|\")),r=r.length&&new RegExp(r.join(\"|\")),b=Y.test(o.compareDocumentPosition),t=b||Y.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===n||a.ownerDocument===v&&t(v,a)?-1:b===n||b.ownerDocument===v&&t(v,b)?1:k?I(k,a)-I(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,g=[a],h=[b];if(!e||!f)return a===n?-1:b===n?1:e?-1:f?1:k?I(k,a)-I(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)g.unshift(c);c=b;while(c=c.parentNode)h.unshift(c);while(g[d]===h[d])d++;return d?la(g[d],h[d]):g[d]===v?-1:h[d]===v?1:0},n):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(S,\"='$1']\"),c.matchesSelector&&p&&!A[b+\" \"]&&(!r||!r.test(b))&&(!q||!q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.escape=function(a){return(a+\"\").replace(ba,ca)},ga.error=function(a){throw new Error(\"Syntax error, unrecognized expression: \"+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c=\"\",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if(\"string\"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:V,attrHandle:{},find:{},relative:{\">\":{dir:\"parentNode\",first:!0},\" \":{dir:\"parentNode\"},\"+\":{dir:\"previousSibling\",first:!0},\"~\":{dir:\"previousSibling\"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(_,aa),a[3]=(a[3]||a[4]||a[5]||\"\").replace(_,aa),\"~=\"===a[2]&&(a[3]=\" \"+a[3]+\" \"),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),\"nth\"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*(\"even\"===a[3]||\"odd\"===a[3])),a[5]=+(a[7]+a[8]||\"odd\"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return V.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||\"\":c&&T.test(c)&&(b=g(c,!0))&&(b=c.indexOf(\")\",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(_,aa).toLowerCase();return\"*\"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+\" \"];return b||(b=new RegExp(\"(^|\"+K+\")\"+a+\"(\"+K+\"|$)\"))&&y(a,function(a){return b.test(\"string\"==typeof a.className&&a.className||\"undefined\"!=typeof a.getAttribute&&a.getAttribute(\"class\")||\"\")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?\"!=\"===b:!b||(e+=\"\",\"=\"===b?e===c:\"!=\"===b?e!==c:\"^=\"===b?c&&0===e.indexOf(c):\"*=\"===b?c&&e.indexOf(c)>-1:\"$=\"===b?c&&e.slice(-c.length)===c:\"~=\"===b?(\" \"+e.replace(O,\" \")+\" \").indexOf(c)>-1:\"|=\"===b&&(e===c||e.slice(0,c.length+1)===c+\"-\"))}},CHILD:function(a,b,c,d,e){var f=\"nth\"!==a.slice(0,3),g=\"last\"!==a.slice(-4),h=\"of-type\"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?\"nextSibling\":\"previousSibling\",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h,t=!1;if(q){if(f){while(p){m=b;while(m=m[p])if(h?m.nodeName.toLowerCase()===r:1===m.nodeType)return!1;o=p=\"only\"===a&&!o&&\"nextSibling\"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){m=q,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n&&j[2],m=n&&q.childNodes[n];while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if(1===m.nodeType&&++t&&m===b){k[a]=[w,n,t];break}}else if(s&&(m=b,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n),t===!1)while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if((h?m.nodeName.toLowerCase()===r:1===m.nodeType)&&++t&&(s&&(l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),k[a]=[w,t]),m===b))break;return t-=e,t===d||t%d===0&&t/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error(\"unsupported pseudo: \"+a);return e[u]?e(b):e.length>1?(c=[a,a,\"\",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(P,\"$1\"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(_,aa),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return U.test(a||\"\")||ga.error(\"unsupported lang: \"+a),a=a.replace(_,aa).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute(\"xml:lang\")||b.getAttribute(\"lang\"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+\"-\");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:oa(!1),disabled:oa(!0),checked:function(a){var b=a.nodeName.toLowerCase();return\"input\"===b&&!!a.checked||\"option\"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return\"input\"===b&&\"button\"===a.type||\"button\"===b},text:function(a){var b;return\"input\"===a.nodeName.toLowerCase()&&\"text\"===a.type&&(null==(b=a.getAttribute(\"type\"))||\"text\"===b.toLowerCase())},first:pa(function(){return[0]}),last:pa(function(a,b){return[b-1]}),eq:pa(function(a,b,c){return[c<0?c+b:c]}),even:pa(function(a,b){for(var c=0;c<b;c+=2)a.push(c);return a}),odd:pa(function(a,b){for(var c=1;c<b;c+=2)a.push(c);return a}),lt:pa(function(a,b,c){for(var d=c<0?c+b:c;--d>=0;)a.push(d);return a}),gt:pa(function(a,b,c){for(var d=c<0?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=ma(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=na(b);function ra(){}ra.prototype=d.filters=d.pseudos,d.setFilters=new ra,g=ga.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+\" \"];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){c&&!(e=Q.exec(h))||(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=R.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(P,\" \")}),h=h.slice(c.length));for(g in d.filter)!(e=V[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?ga.error(a):z(a,i).slice(0)};function sa(a){for(var b=0,c=a.length,d=\"\";b<c;b++)d+=a[b].value;return d}function ta(a,b,c){var d=b.dir,e=b.next,f=e||d,g=c&&\"parentNode\"===f,h=x++;return b.first?function(b,c,e){while(b=b[d])if(1===b.nodeType||g)return a(b,c,e);return!1}:function(b,c,i){var j,k,l,m=[w,h];if(i){while(b=b[d])if((1===b.nodeType||g)&&a(b,c,i))return!0}else while(b=b[d])if(1===b.nodeType||g)if(l=b[u]||(b[u]={}),k=l[b.uniqueID]||(l[b.uniqueID]={}),e&&e===b.nodeName.toLowerCase())b=b[d]||b;else{if((j=k[f])&&j[0]===w&&j[1]===h)return m[2]=j[2];if(k[f]=m,m[2]=a(b,c,i))return!0}return!1}}function ua(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function va(a,b,c){for(var d=0,e=b.length;d<e;d++)ga(a,b[d],c);return c}function wa(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;h<i;h++)(f=a[h])&&(c&&!c(f,d,e)||(g.push(f),j&&b.push(h)));return g}function xa(a,b,c,d,e,f){return d&&!d[u]&&(d=xa(d)),e&&!e[u]&&(e=xa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||va(b||\"*\",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:wa(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=wa(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?I(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=wa(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ya(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[\" \"],i=g?1:0,k=ta(function(a){return a===b},h,!0),l=ta(function(a){return I(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];i<f;i++)if(c=d.relative[a[i].type])m=[ta(ua(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;e<f;e++)if(d.relative[a[e].type])break;return xa(i>1&&ua(m),i>1&&sa(a.slice(0,i-1).concat({value:\" \"===a[i-2].type?\"*\":\"\"})).replace(P,\"$1\"),c,i<e&&ya(a.slice(i,e)),e<f&&ya(a=a.slice(e)),e<f&&sa(a))}m.push(c)}return ua(m)}function za(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,o,q,r=0,s=\"0\",t=f&&[],u=[],v=j,x=f||e&&d.find.TAG(\"*\",k),y=w+=null==v?1:Math.random()||.1,z=x.length;for(k&&(j=g===n||g||k);s!==z&&null!=(l=x[s]);s++){if(e&&l){o=0,g||l.ownerDocument===n||(m(l),h=!p);while(q=a[o++])if(q(l,g||n,h)){i.push(l);break}k&&(w=y)}c&&((l=!q&&l)&&r--,f&&t.push(l))}if(r+=s,c&&s!==r){o=0;while(q=b[o++])q(t,u,g,h);if(f){if(r>0)while(s--)t[s]||u[s]||(u[s]=E.call(i));u=wa(u)}G.apply(i,u),k&&!f&&u.length>0&&r+b.length>1&&ga.uniqueSort(i)}return k&&(w=y,j=v),t};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+\" \"];if(!f){b||(b=g(a)),c=b.length;while(c--)f=ya(b[c]),f[u]?d.push(f):e.push(f);f=A(a,za(e,d)),f.selector=a}return f},i=ga.select=function(a,b,c,e){var f,i,j,k,l,m=\"function\"==typeof a&&a,n=!e&&g(a=m.selector||a);if(c=c||[],1===n.length){if(i=n[0]=n[0].slice(0),i.length>2&&\"ID\"===(j=i[0]).type&&9===b.nodeType&&p&&d.relative[i[1].type]){if(b=(d.find.ID(j.matches[0].replace(_,aa),b)||[])[0],!b)return c;m&&(b=b.parentNode),a=a.slice(i.shift().value.length)}f=V.needsContext.test(a)?0:i.length;while(f--){if(j=i[f],d.relative[k=j.type])break;if((l=d.find[k])&&(e=l(j.matches[0].replace(_,aa),$.test(i[0].type)&&qa(b.parentNode)||b))){if(i.splice(f,1),a=e.length&&sa(i),!a)return G.apply(c,e),c;break}}}return(m||h(a,n))(e,b,!p,c,!b||$.test(a)&&qa(b.parentNode)||b),c},c.sortStable=u.split(\"\").sort(B).join(\"\")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement(\"fieldset\"))}),ja(function(a){return a.innerHTML=\"<a href='#'></a>\",\"#\"===a.firstChild.getAttribute(\"href\")})||ka(\"type|href|height|width\",function(a,b,c){if(!c)return a.getAttribute(b,\"type\"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML=\"<input/>\",a.firstChild.setAttribute(\"value\",\"\"),\"\"===a.firstChild.getAttribute(\"value\")})||ka(\"value\",function(a,b,c){if(!c&&\"input\"===a.nodeName.toLowerCase())return a.defaultValue}),ja(function(a){return null==a.getAttribute(\"disabled\")})||ka(J,function(a,b,c){var d;if(!c)return a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);r.find=x,r.expr=x.selectors,r.expr[\":\"]=r.expr.pseudos,r.uniqueSort=r.unique=x.uniqueSort,r.text=x.getText,r.isXMLDoc=x.isXML,r.contains=x.contains,r.escapeSelector=x.escape;var y=function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&r(a).is(c))break;d.push(a)}return d},z=function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c},A=r.expr.match.needsContext;function B(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()}var C=/^<([a-z][^\\/\\0>:\\x20\\t\\r\\n\\f]*)[\\x20\\t\\r\\n\\f]*\\/?>(?:<\\/\\1>|)$/i,D=/^.[^:#\\[\\.,]*$/;function E(a,b,c){return r.isFunction(b)?r.grep(a,function(a,d){return!!b.call(a,d,a)!==c}):b.nodeType?r.grep(a,function(a){return a===b!==c}):\"string\"!=typeof b?r.grep(a,function(a){return i.call(b,a)>-1!==c}):D.test(b)?r.filter(b,a,c):(b=r.filter(b,a),r.grep(a,function(a){return i.call(b,a)>-1!==c&&1===a.nodeType}))}r.filter=function(a,b,c){var d=b[0];return c&&(a=\":not(\"+a+\")\"),1===b.length&&1===d.nodeType?r.find.matchesSelector(d,a)?[d]:[]:r.find.matches(a,r.grep(b,function(a){return 1===a.nodeType}))},r.fn.extend({find:function(a){var b,c,d=this.length,e=this;if(\"string\"!=typeof a)return this.pushStack(r(a).filter(function(){for(b=0;b<d;b++)if(r.contains(e[b],this))return!0}));for(c=this.pushStack([]),b=0;b<d;b++)r.find(a,e[b],c);return d>1?r.uniqueSort(c):c},filter:function(a){return this.pushStack(E(this,a||[],!1))},not:function(a){return this.pushStack(E(this,a||[],!0))},is:function(a){return!!E(this,\"string\"==typeof a&&A.test(a)?r(a):a||[],!1).length}});var F,G=/^(?:\\s*(<[\\w\\W]+>)[^>]*|#([\\w-]+))$/,H=r.fn.init=function(a,b,c){var e,f;if(!a)return this;if(c=c||F,\"string\"==typeof a){if(e=\"<\"===a[0]&&\">\"===a[a.length-1]&&a.length>=3?[null,a,null]:G.exec(a),!e||!e[1]&&b)return!b||b.jquery?(b||c).find(a):this.constructor(b).find(a);if(e[1]){if(b=b instanceof r?b[0]:b,r.merge(this,r.parseHTML(e[1],b&&b.nodeType?b.ownerDocument||b:d,!0)),C.test(e[1])&&r.isPlainObject(b))for(e in b)r.isFunction(this[e])?this[e](b[e]):this.attr(e,b[e]);return this}return f=d.getElementById(e[2]),f&&(this[0]=f,this.length=1),this}return a.nodeType?(this[0]=a,this.length=1,this):r.isFunction(a)?void 0!==c.ready?c.ready(a):a(r):r.makeArray(a,this)};H.prototype=r.fn,F=r(d);var I=/^(?:parents|prev(?:Until|All))/,J={children:!0,contents:!0,next:!0,prev:!0};r.fn.extend({has:function(a){var b=r(a,this),c=b.length;return this.filter(function(){for(var a=0;a<c;a++)if(r.contains(this,b[a]))return!0})},closest:function(a,b){var c,d=0,e=this.length,f=[],g=\"string\"!=typeof a&&r(a);if(!A.test(a))for(;d<e;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&r.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?r.uniqueSort(f):f)},index:function(a){return a?\"string\"==typeof a?i.call(r(a),this[0]):i.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(r.uniqueSort(r.merge(this.get(),r(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function K(a,b){while((a=a[b])&&1!==a.nodeType);return a}r.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return y(a,\"parentNode\")},parentsUntil:function(a,b,c){return y(a,\"parentNode\",c)},next:function(a){return K(a,\"nextSibling\")},prev:function(a){return K(a,\"previousSibling\")},nextAll:function(a){return y(a,\"nextSibling\")},prevAll:function(a){return y(a,\"previousSibling\")},nextUntil:function(a,b,c){return y(a,\"nextSibling\",c)},prevUntil:function(a,b,c){return y(a,\"previousSibling\",c)},siblings:function(a){return z((a.parentNode||{}).firstChild,a)},children:function(a){return z(a.firstChild)},contents:function(a){return B(a,\"iframe\")?a.contentDocument:(B(a,\"template\")&&(a=a.content||a),r.merge([],a.childNodes))}},function(a,b){r.fn[a]=function(c,d){var e=r.map(this,b,c);return\"Until\"!==a.slice(-5)&&(d=c),d&&\"string\"==typeof d&&(e=r.filter(d,e)),this.length>1&&(J[a]||r.uniqueSort(e),I.test(a)&&e.reverse()),this.pushStack(e)}});var L=/[^\\x20\\t\\r\\n\\f]+/g;function M(a){var b={};return r.each(a.match(L)||[],function(a,c){b[c]=!0}),b}r.Callbacks=function(a){a=\"string\"==typeof a?M(a):r.extend({},a);var b,c,d,e,f=[],g=[],h=-1,i=function(){for(e=e||a.once,d=b=!0;g.length;h=-1){c=g.shift();while(++h<f.length)f[h].apply(c[0],c[1])===!1&&a.stopOnFalse&&(h=f.length,c=!1)}a.memory||(c=!1),b=!1,e&&(f=c?[]:\"\")},j={add:function(){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&\"string\"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this},remove:function(){return r.each(arguments,function(a,b){var c;while((c=r.inArray(b,f,c))>-1)f.splice(c,1),c<=h&&h--}),this},has:function(a){return a?r.inArray(a,f)>-1:f.length>0},empty:function(){return f&&(f=[]),this},disable:function(){return e=g=[],f=c=\"\",this},disabled:function(){return!f},lock:function(){return e=g=[],c||b||(f=c=\"\"),this},locked:function(){return!!e},fireWith:function(a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this},fire:function(){return j.fireWith(this,arguments),this},fired:function(){return!!d}};return j};function N(a){return a}function O(a){throw a}function P(a,b,c,d){var e;try{a&&r.isFunction(e=a.promise)?e.call(a).done(b).fail(c):a&&r.isFunction(e=a.then)?e.call(a,b,c):b.apply(void 0,[a].slice(d))}catch(a){c.apply(void 0,[a])}}r.extend({Deferred:function(b){var c=[[\"notify\",\"progress\",r.Callbacks(\"memory\"),r.Callbacks(\"memory\"),2],[\"resolve\",\"done\",r.Callbacks(\"once memory\"),r.Callbacks(\"once memory\"),0,\"resolved\"],[\"reject\",\"fail\",r.Callbacks(\"once memory\"),r.Callbacks(\"once memory\"),1,\"rejected\"]],d=\"pending\",e={state:function(){return d},always:function(){return f.done(arguments).fail(arguments),this},\"catch\":function(a){return e.then(null,a)},pipe:function(){var a=arguments;return r.Deferred(function(b){r.each(c,function(c,d){var e=r.isFunction(a[d[4]])&&a[d[4]];f[d[1]](function(){var a=e&&e.apply(this,arguments);a&&r.isFunction(a.promise)?a.promise().progress(b.notify).done(b.resolve).fail(b.reject):b[d[0]+\"With\"](this,e?[a]:arguments)})}),a=null}).promise()},then:function(b,d,e){var f=0;function g(b,c,d,e){return function(){var h=this,i=arguments,j=function(){var a,j;if(!(b<f)){if(a=d.apply(h,i),a===c.promise())throw new TypeError(\"Thenable self-resolution\");j=a&&(\"object\"==typeof a||\"function\"==typeof a)&&a.then,r.isFunction(j)?e?j.call(a,g(f,c,N,e),g(f,c,O,e)):(f++,j.call(a,g(f,c,N,e),g(f,c,O,e),g(f,c,N,c.notifyWith))):(d!==N&&(h=void 0,i=[a]),(e||c.resolveWith)(h,i))}},k=e?j:function(){try{j()}catch(a){r.Deferred.exceptionHook&&r.Deferred.exceptionHook(a,k.stackTrace),b+1>=f&&(d!==O&&(h=void 0,i=[a]),c.rejectWith(h,i))}};b?k():(r.Deferred.getStackHook&&(k.stackTrace=r.Deferred.getStackHook()),a.setTimeout(k))}}return r.Deferred(function(a){c[0][3].add(g(0,a,r.isFunction(e)?e:N,a.notifyWith)),c[1][3].add(g(0,a,r.isFunction(b)?b:N)),c[2][3].add(g(0,a,r.isFunction(d)?d:O))}).promise()},promise:function(a){return null!=a?r.extend(a,e):e}},f={};return r.each(c,function(a,b){var g=b[2],h=b[5];e[b[1]]=g.add,h&&g.add(function(){d=h},c[3-a][2].disable,c[0][2].lock),g.add(b[3].fire),f[b[0]]=function(){return f[b[0]+\"With\"](this===f?void 0:this,arguments),this},f[b[0]+\"With\"]=g.fireWith}),e.promise(f),b&&b.call(f,f),f},when:function(a){var b=arguments.length,c=b,d=Array(c),e=f.call(arguments),g=r.Deferred(),h=function(a){return function(c){d[a]=this,e[a]=arguments.length>1?f.call(arguments):c,--b||g.resolveWith(d,e)}};if(b<=1&&(P(a,g.done(h(c)).resolve,g.reject,!b),\"pending\"===g.state()||r.isFunction(e[c]&&e[c].then)))return g.then();while(c--)P(e[c],h(c),g.reject);return g.promise()}});var Q=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;r.Deferred.exceptionHook=function(b,c){a.console&&a.console.warn&&b&&Q.test(b.name)&&a.console.warn(\"jQuery.Deferred exception: \"+b.message,b.stack,c)},r.readyException=function(b){a.setTimeout(function(){throw b})};var R=r.Deferred();r.fn.ready=function(a){return R.then(a)[\"catch\"](function(a){r.readyException(a)}),this},r.extend({isReady:!1,readyWait:1,ready:function(a){(a===!0?--r.readyWait:r.isReady)||(r.isReady=!0,a!==!0&&--r.readyWait>0||R.resolveWith(d,[r]))}}),r.ready.then=R.then;function S(){d.removeEventListener(\"DOMContentLoaded\",S),\na.removeEventListener(\"load\",S),r.ready()}\"complete\"===d.readyState||\"loading\"!==d.readyState&&!d.documentElement.doScroll?a.setTimeout(r.ready):(d.addEventListener(\"DOMContentLoaded\",S),a.addEventListener(\"load\",S));var T=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if(\"object\"===r.type(c)){e=!0;for(h in c)T(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,r.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(r(a),c)})),b))for(;h<i;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},U=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function V(){this.expando=r.expando+V.uid++}V.uid=1,V.prototype={cache:function(a){var b=a[this.expando];return b||(b={},U(a)&&(a.nodeType?a[this.expando]=b:Object.defineProperty(a,this.expando,{value:b,configurable:!0}))),b},set:function(a,b,c){var d,e=this.cache(a);if(\"string\"==typeof b)e[r.camelCase(b)]=c;else for(d in b)e[r.camelCase(d)]=b[d];return e},get:function(a,b){return void 0===b?this.cache(a):a[this.expando]&&a[this.expando][r.camelCase(b)]},access:function(a,b,c){return void 0===b||b&&\"string\"==typeof b&&void 0===c?this.get(a,b):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d=a[this.expando];if(void 0!==d){if(void 0!==b){Array.isArray(b)?b=b.map(r.camelCase):(b=r.camelCase(b),b=b in d?[b]:b.match(L)||[]),c=b.length;while(c--)delete d[b[c]]}(void 0===b||r.isEmptyObject(d))&&(a.nodeType?a[this.expando]=void 0:delete a[this.expando])}},hasData:function(a){var b=a[this.expando];return void 0!==b&&!r.isEmptyObject(b)}};var W=new V,X=new V,Y=/^(?:\\{[\\w\\W]*\\}|\\[[\\w\\W]*\\])$/,Z=/[A-Z]/g;function $(a){return\"true\"===a||\"false\"!==a&&(\"null\"===a?null:a===+a+\"\"?+a:Y.test(a)?JSON.parse(a):a)}function _(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d=\"data-\"+b.replace(Z,\"-$&\").toLowerCase(),c=a.getAttribute(d),\"string\"==typeof c){try{c=$(c)}catch(e){}X.set(a,b,c)}else c=void 0;return c}r.extend({hasData:function(a){return X.hasData(a)||W.hasData(a)},data:function(a,b,c){return X.access(a,b,c)},removeData:function(a,b){X.remove(a,b)},_data:function(a,b,c){return W.access(a,b,c)},_removeData:function(a,b){W.remove(a,b)}}),r.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=X.get(f),1===f.nodeType&&!W.get(f,\"hasDataAttrs\"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf(\"data-\")&&(d=r.camelCase(d.slice(5)),_(f,d,e[d])));W.set(f,\"hasDataAttrs\",!0)}return e}return\"object\"==typeof a?this.each(function(){X.set(this,a)}):T(this,function(b){var c;if(f&&void 0===b){if(c=X.get(f,a),void 0!==c)return c;if(c=_(f,a),void 0!==c)return c}else this.each(function(){X.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){X.remove(this,a)})}}),r.extend({queue:function(a,b,c){var d;if(a)return b=(b||\"fx\")+\"queue\",d=W.get(a,b),c&&(!d||Array.isArray(c)?d=W.access(a,b,r.makeArray(c)):d.push(c)),d||[]},dequeue:function(a,b){b=b||\"fx\";var c=r.queue(a,b),d=c.length,e=c.shift(),f=r._queueHooks(a,b),g=function(){r.dequeue(a,b)};\"inprogress\"===e&&(e=c.shift(),d--),e&&(\"fx\"===b&&c.unshift(\"inprogress\"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+\"queueHooks\";return W.get(a,c)||W.access(a,c,{empty:r.Callbacks(\"once memory\").add(function(){W.remove(a,[b+\"queue\",c])})})}}),r.fn.extend({queue:function(a,b){var c=2;return\"string\"!=typeof a&&(b=a,a=\"fx\",c--),arguments.length<c?r.queue(this[0],a):void 0===b?this:this.each(function(){var c=r.queue(this,a,b);r._queueHooks(this,a),\"fx\"===a&&\"inprogress\"!==c[0]&&r.dequeue(this,a)})},dequeue:function(a){return this.each(function(){r.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||\"fx\",[])},promise:function(a,b){var c,d=1,e=r.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};\"string\"!=typeof a&&(b=a,a=void 0),a=a||\"fx\";while(g--)c=W.get(f[g],a+\"queueHooks\"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var aa=/[+-]?(?:\\d*\\.|)\\d+(?:[eE][+-]?\\d+|)/.source,ba=new RegExp(\"^(?:([+-])=|)(\"+aa+\")([a-z%]*)$\",\"i\"),ca=[\"Top\",\"Right\",\"Bottom\",\"Left\"],da=function(a,b){return a=b||a,\"none\"===a.style.display||\"\"===a.style.display&&r.contains(a.ownerDocument,a)&&\"none\"===r.css(a,\"display\")},ea=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};function fa(a,b,c,d){var e,f=1,g=20,h=d?function(){return d.cur()}:function(){return r.css(a,b,\"\")},i=h(),j=c&&c[3]||(r.cssNumber[b]?\"\":\"px\"),k=(r.cssNumber[b]||\"px\"!==j&&+i)&&ba.exec(r.css(a,b));if(k&&k[3]!==j){j=j||k[3],c=c||[],k=+i||1;do f=f||\".5\",k/=f,r.style(a,b,k+j);while(f!==(f=h()/i)&&1!==f&&--g)}return c&&(k=+k||+i||0,e=c[1]?k+(c[1]+1)*c[2]:+c[2],d&&(d.unit=j,d.start=k,d.end=e)),e}var ga={};function ha(a){var b,c=a.ownerDocument,d=a.nodeName,e=ga[d];return e?e:(b=c.body.appendChild(c.createElement(d)),e=r.css(b,\"display\"),b.parentNode.removeChild(b),\"none\"===e&&(e=\"block\"),ga[d]=e,e)}function ia(a,b){for(var c,d,e=[],f=0,g=a.length;f<g;f++)d=a[f],d.style&&(c=d.style.display,b?(\"none\"===c&&(e[f]=W.get(d,\"display\")||null,e[f]||(d.style.display=\"\")),\"\"===d.style.display&&da(d)&&(e[f]=ha(d))):\"none\"!==c&&(e[f]=\"none\",W.set(d,\"display\",c)));for(f=0;f<g;f++)null!=e[f]&&(a[f].style.display=e[f]);return a}r.fn.extend({show:function(){return ia(this,!0)},hide:function(){return ia(this)},toggle:function(a){return\"boolean\"==typeof a?a?this.show():this.hide():this.each(function(){da(this)?r(this).show():r(this).hide()})}});var ja=/^(?:checkbox|radio)$/i,ka=/<([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]+)/i,la=/^$|\\/(?:java|ecma)script/i,ma={option:[1,\"<select multiple='multiple'>\",\"</select>\"],thead:[1,\"<table>\",\"</table>\"],col:[2,\"<table><colgroup>\",\"</colgroup></table>\"],tr:[2,\"<table><tbody>\",\"</tbody></table>\"],td:[3,\"<table><tbody><tr>\",\"</tr></tbody></table>\"],_default:[0,\"\",\"\"]};ma.optgroup=ma.option,ma.tbody=ma.tfoot=ma.colgroup=ma.caption=ma.thead,ma.th=ma.td;function na(a,b){var c;return c=\"undefined\"!=typeof a.getElementsByTagName?a.getElementsByTagName(b||\"*\"):\"undefined\"!=typeof a.querySelectorAll?a.querySelectorAll(b||\"*\"):[],void 0===b||b&&B(a,b)?r.merge([a],c):c}function oa(a,b){for(var c=0,d=a.length;c<d;c++)W.set(a[c],\"globalEval\",!b||W.get(b[c],\"globalEval\"))}var pa=/<|&#?\\w+;/;function qa(a,b,c,d,e){for(var f,g,h,i,j,k,l=b.createDocumentFragment(),m=[],n=0,o=a.length;n<o;n++)if(f=a[n],f||0===f)if(\"object\"===r.type(f))r.merge(m,f.nodeType?[f]:f);else if(pa.test(f)){g=g||l.appendChild(b.createElement(\"div\")),h=(ka.exec(f)||[\"\",\"\"])[1].toLowerCase(),i=ma[h]||ma._default,g.innerHTML=i[1]+r.htmlPrefilter(f)+i[2],k=i[0];while(k--)g=g.lastChild;r.merge(m,g.childNodes),g=l.firstChild,g.textContent=\"\"}else m.push(b.createTextNode(f));l.textContent=\"\",n=0;while(f=m[n++])if(d&&r.inArray(f,d)>-1)e&&e.push(f);else if(j=r.contains(f.ownerDocument,f),g=na(l.appendChild(f),\"script\"),j&&oa(g),c){k=0;while(f=g[k++])la.test(f.type||\"\")&&c.push(f)}return l}!function(){var a=d.createDocumentFragment(),b=a.appendChild(d.createElement(\"div\")),c=d.createElement(\"input\");c.setAttribute(\"type\",\"radio\"),c.setAttribute(\"checked\",\"checked\"),c.setAttribute(\"name\",\"t\"),b.appendChild(c),o.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML=\"<textarea>x</textarea>\",o.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var ra=d.documentElement,sa=/^key/,ta=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,ua=/^([^.]*)(?:\\.(.+)|)/;function va(){return!0}function wa(){return!1}function xa(){try{return d.activeElement}catch(a){}}function ya(a,b,c,d,e,f){var g,h;if(\"object\"==typeof b){\"string\"!=typeof c&&(d=d||c,c=void 0);for(h in b)ya(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&(\"string\"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=wa;else if(!e)return a;return 1===f&&(g=e,e=function(a){return r().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=r.guid++)),a.each(function(){r.event.add(this,b,e,d,c)})}r.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.get(a);if(q){c.handler&&(f=c,c=f.handler,e=f.selector),e&&r.find.matchesSelector(ra,e),c.guid||(c.guid=r.guid++),(i=q.events)||(i=q.events={}),(g=q.handle)||(g=q.handle=function(b){return\"undefined\"!=typeof r&&r.event.triggered!==b.type?r.event.dispatch.apply(a,arguments):void 0}),b=(b||\"\").match(L)||[\"\"],j=b.length;while(j--)h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||\"\").split(\".\").sort(),n&&(l=r.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=r.event.special[n]||{},k=r.extend({type:n,origType:p,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&r.expr.match.needsContext.test(e),namespace:o.join(\".\")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,o,g)!==!1||a.addEventListener&&a.addEventListener(n,g)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),r.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.hasData(a)&&W.get(a);if(q&&(i=q.events)){b=(b||\"\").match(L)||[\"\"],j=b.length;while(j--)if(h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||\"\").split(\".\").sort(),n){l=r.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp(\"(^|\\\\.)\"+o.join(\"\\\\.(?:.*\\\\.|)\")+\"(\\\\.|$)\"),g=f=m.length;while(f--)k=m[f],!e&&p!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&(\"**\"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,o,q.handle)!==!1||r.removeEvent(a,n,q.handle),delete i[n])}else for(n in i)r.event.remove(a,n+b[j],c,d,!0);r.isEmptyObject(i)&&W.remove(a,\"handle events\")}},dispatch:function(a){var b=r.event.fix(a),c,d,e,f,g,h,i=new Array(arguments.length),j=(W.get(this,\"events\")||{})[b.type]||[],k=r.event.special[b.type]||{};for(i[0]=b,c=1;c<arguments.length;c++)i[c]=arguments[c];if(b.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,b)!==!1){h=r.event.handlers.call(this,b,j),c=0;while((f=h[c++])&&!b.isPropagationStopped()){b.currentTarget=f.elem,d=0;while((g=f.handlers[d++])&&!b.isImmediatePropagationStopped())b.rnamespace&&!b.rnamespace.test(g.namespace)||(b.handleObj=g,b.data=g.data,e=((r.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(b.result=e)===!1&&(b.preventDefault(),b.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,b),b.result}},handlers:function(a,b){var c,d,e,f,g,h=[],i=b.delegateCount,j=a.target;if(i&&j.nodeType&&!(\"click\"===a.type&&a.button>=1))for(;j!==this;j=j.parentNode||this)if(1===j.nodeType&&(\"click\"!==a.type||j.disabled!==!0)){for(f=[],g={},c=0;c<i;c++)d=b[c],e=d.selector+\" \",void 0===g[e]&&(g[e]=d.needsContext?r(e,this).index(j)>-1:r.find(e,this,null,[j]).length),g[e]&&f.push(d);f.length&&h.push({elem:j,handlers:f})}return j=this,i<b.length&&h.push({elem:j,handlers:b.slice(i)}),h},addProp:function(a,b){Object.defineProperty(r.Event.prototype,a,{enumerable:!0,configurable:!0,get:r.isFunction(b)?function(){if(this.originalEvent)return b(this.originalEvent)}:function(){if(this.originalEvent)return this.originalEvent[a]},set:function(b){Object.defineProperty(this,a,{enumerable:!0,configurable:!0,writable:!0,value:b})}})},fix:function(a){return a[r.expando]?a:new r.Event(a)},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==xa()&&this.focus)return this.focus(),!1},delegateType:\"focusin\"},blur:{trigger:function(){if(this===xa()&&this.blur)return this.blur(),!1},delegateType:\"focusout\"},click:{trigger:function(){if(\"checkbox\"===this.type&&this.click&&B(this,\"input\"))return this.click(),!1},_default:function(a){return B(a.target,\"a\")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}}},r.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c)},r.Event=function(a,b){return this instanceof r.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?va:wa,this.target=a.target&&3===a.target.nodeType?a.target.parentNode:a.target,this.currentTarget=a.currentTarget,this.relatedTarget=a.relatedTarget):this.type=a,b&&r.extend(this,b),this.timeStamp=a&&a.timeStamp||r.now(),void(this[r.expando]=!0)):new r.Event(a,b)},r.Event.prototype={constructor:r.Event,isDefaultPrevented:wa,isPropagationStopped:wa,isImmediatePropagationStopped:wa,isSimulated:!1,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=va,a&&!this.isSimulated&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=va,a&&!this.isSimulated&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=va,a&&!this.isSimulated&&a.stopImmediatePropagation(),this.stopPropagation()}},r.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,\"char\":!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(a){var b=a.button;return null==a.which&&sa.test(a.type)?null!=a.charCode?a.charCode:a.keyCode:!a.which&&void 0!==b&&ta.test(a.type)?1&b?1:2&b?3:4&b?2:0:a.which}},r.event.addProp),r.each({mouseenter:\"mouseover\",mouseleave:\"mouseout\",pointerenter:\"pointerover\",pointerleave:\"pointerout\"},function(a,b){r.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return e&&(e===d||r.contains(d,e))||(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),r.fn.extend({on:function(a,b,c,d){return ya(this,a,b,c,d)},one:function(a,b,c,d){return ya(this,a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,r(a.delegateTarget).off(d.namespace?d.origType+\".\"+d.namespace:d.origType,d.selector,d.handler),this;if(\"object\"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return b!==!1&&\"function\"!=typeof b||(c=b,b=void 0),c===!1&&(c=wa),this.each(function(){r.event.remove(this,a,c,b)})}});var za=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\\/\\0>\\x20\\t\\r\\n\\f]*)[^>]*)\\/>/gi,Aa=/<script|<style|<link/i,Ba=/checked\\s*(?:[^=]|=\\s*.checked.)/i,Ca=/^true\\/(.*)/,Da=/^\\s*<!(?:\\[CDATA\\[|--)|(?:\\]\\]|--)>\\s*$/g;function Ea(a,b){return B(a,\"table\")&&B(11!==b.nodeType?b:b.firstChild,\"tr\")?r(\">tbody\",a)[0]||a:a}function Fa(a){return a.type=(null!==a.getAttribute(\"type\"))+\"/\"+a.type,a}function Ga(a){var b=Ca.exec(a.type);return b?a.type=b[1]:a.removeAttribute(\"type\"),a}function Ha(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(W.hasData(a)&&(f=W.access(a),g=W.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;c<d;c++)r.event.add(b,e,j[e][c])}X.hasData(a)&&(h=X.access(a),i=r.extend({},h),X.set(b,i))}}function Ia(a,b){var c=b.nodeName.toLowerCase();\"input\"===c&&ja.test(a.type)?b.checked=a.checked:\"input\"!==c&&\"textarea\"!==c||(b.defaultValue=a.defaultValue)}function Ja(a,b,c,d){b=g.apply([],b);var e,f,h,i,j,k,l=0,m=a.length,n=m-1,q=b[0],s=r.isFunction(q);if(s||m>1&&\"string\"==typeof q&&!o.checkClone&&Ba.test(q))return a.each(function(e){var f=a.eq(e);s&&(b[0]=q.call(this,e,f.html())),Ja(f,b,c,d)});if(m&&(e=qa(b,a[0].ownerDocument,!1,a,d),f=e.firstChild,1===e.childNodes.length&&(e=f),f||d)){for(h=r.map(na(e,\"script\"),Fa),i=h.length;l<m;l++)j=e,l!==n&&(j=r.clone(j,!0,!0),i&&r.merge(h,na(j,\"script\"))),c.call(a[l],j,l);if(i)for(k=h[h.length-1].ownerDocument,r.map(h,Ga),l=0;l<i;l++)j=h[l],la.test(j.type||\"\")&&!W.access(j,\"globalEval\")&&r.contains(k,j)&&(j.src?r._evalUrl&&r._evalUrl(j.src):p(j.textContent.replace(Da,\"\"),k))}return a}function Ka(a,b,c){for(var d,e=b?r.filter(b,a):a,f=0;null!=(d=e[f]);f++)c||1!==d.nodeType||r.cleanData(na(d)),d.parentNode&&(c&&r.contains(d.ownerDocument,d)&&oa(na(d,\"script\")),d.parentNode.removeChild(d));return a}r.extend({htmlPrefilter:function(a){return a.replace(za,\"<$1></$2>\")},clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=r.contains(a.ownerDocument,a);if(!(o.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||r.isXMLDoc(a)))for(g=na(h),f=na(a),d=0,e=f.length;d<e;d++)Ia(f[d],g[d]);if(b)if(c)for(f=f||na(a),g=g||na(h),d=0,e=f.length;d<e;d++)Ha(f[d],g[d]);else Ha(a,h);return g=na(h,\"script\"),g.length>0&&oa(g,!i&&na(a,\"script\")),h},cleanData:function(a){for(var b,c,d,e=r.event.special,f=0;void 0!==(c=a[f]);f++)if(U(c)){if(b=c[W.expando]){if(b.events)for(d in b.events)e[d]?r.event.remove(c,d):r.removeEvent(c,d,b.handle);c[W.expando]=void 0}c[X.expando]&&(c[X.expando]=void 0)}}}),r.fn.extend({detach:function(a){return Ka(this,a,!0)},remove:function(a){return Ka(this,a)},text:function(a){return T(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)},append:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.appendChild(a)}})},prepend:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(r.cleanData(na(a,!1)),a.textContent=\"\");return this},clone:function(a,b){return a=null!=a&&a,b=null==b?a:b,this.map(function(){return r.clone(this,a,b)})},html:function(a){return T(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if(\"string\"==typeof a&&!Aa.test(a)&&!ma[(ka.exec(a)||[\"\",\"\"])[1].toLowerCase()]){a=r.htmlPrefilter(a);try{for(;c<d;c++)b=this[c]||{},1===b.nodeType&&(r.cleanData(na(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=[];return Ja(this,arguments,function(b){var c=this.parentNode;r.inArray(this,a)<0&&(r.cleanData(na(this)),c&&c.replaceChild(b,this))},a)}}),r.each({appendTo:\"append\",prependTo:\"prepend\",insertBefore:\"before\",insertAfter:\"after\",replaceAll:\"replaceWith\"},function(a,b){r.fn[a]=function(a){for(var c,d=[],e=r(a),f=e.length-1,g=0;g<=f;g++)c=g===f?this:this.clone(!0),r(e[g])[b](c),h.apply(d,c.get());return this.pushStack(d)}});var La=/^margin/,Ma=new RegExp(\"^(\"+aa+\")(?!px)[a-z%]+$\",\"i\"),Na=function(b){var c=b.ownerDocument.defaultView;return c&&c.opener||(c=a),c.getComputedStyle(b)};!function(){function b(){if(i){i.style.cssText=\"box-sizing:border-box;position:relative;display:block;margin:auto;border:1px;padding:1px;top:1%;width:50%\",i.innerHTML=\"\",ra.appendChild(h);var b=a.getComputedStyle(i);c=\"1%\"!==b.top,g=\"2px\"===b.marginLeft,e=\"4px\"===b.width,i.style.marginRight=\"50%\",f=\"4px\"===b.marginRight,ra.removeChild(h),i=null}}var c,e,f,g,h=d.createElement(\"div\"),i=d.createElement(\"div\");i.style&&(i.style.backgroundClip=\"content-box\",i.cloneNode(!0).style.backgroundClip=\"\",o.clearCloneStyle=\"content-box\"===i.style.backgroundClip,h.style.cssText=\"border:0;width:8px;height:0;top:0;left:-9999px;padding:0;margin-top:1px;position:absolute\",h.appendChild(i),r.extend(o,{pixelPosition:function(){return b(),c},boxSizingReliable:function(){return b(),e},pixelMarginRight:function(){return b(),f},reliableMarginLeft:function(){return b(),g}}))}();function Oa(a,b,c){var d,e,f,g,h=a.style;return c=c||Na(a),c&&(g=c.getPropertyValue(b)||c[b],\"\"!==g||r.contains(a.ownerDocument,a)||(g=r.style(a,b)),!o.pixelMarginRight()&&Ma.test(g)&&La.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+\"\":g}function Pa(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}var Qa=/^(none|table(?!-c[ea]).+)/,Ra=/^--/,Sa={position:\"absolute\",visibility:\"hidden\",display:\"block\"},Ta={letterSpacing:\"0\",fontWeight:\"400\"},Ua=[\"Webkit\",\"Moz\",\"ms\"],Va=d.createElement(\"div\").style;function Wa(a){if(a in Va)return a;var b=a[0].toUpperCase()+a.slice(1),c=Ua.length;while(c--)if(a=Ua[c]+b,a in Va)return a}function Xa(a){var b=r.cssProps[a];return b||(b=r.cssProps[a]=Wa(a)||a),b}function Ya(a,b,c){var d=ba.exec(b);return d?Math.max(0,d[2]-(c||0))+(d[3]||\"px\"):b}function Za(a,b,c,d,e){var f,g=0;for(f=c===(d?\"border\":\"content\")?4:\"width\"===b?1:0;f<4;f+=2)\"margin\"===c&&(g+=r.css(a,c+ca[f],!0,e)),d?(\"content\"===c&&(g-=r.css(a,\"padding\"+ca[f],!0,e)),\"margin\"!==c&&(g-=r.css(a,\"border\"+ca[f]+\"Width\",!0,e))):(g+=r.css(a,\"padding\"+ca[f],!0,e),\"padding\"!==c&&(g+=r.css(a,\"border\"+ca[f]+\"Width\",!0,e)));return g}function $a(a,b,c){var d,e=Na(a),f=Oa(a,b,e),g=\"border-box\"===r.css(a,\"boxSizing\",!1,e);return Ma.test(f)?f:(d=g&&(o.boxSizingReliable()||f===a.style[b]),\"auto\"===f&&(f=a[\"offset\"+b[0].toUpperCase()+b.slice(1)]),f=parseFloat(f)||0,f+Za(a,b,c||(g?\"border\":\"content\"),d,e)+\"px\")}r.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Oa(a,\"opacity\");return\"\"===c?\"1\":c}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{\"float\":\"cssFloat\"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=r.camelCase(b),i=Ra.test(b),j=a.style;return i||(b=Xa(h)),g=r.cssHooks[b]||r.cssHooks[h],void 0===c?g&&\"get\"in g&&void 0!==(e=g.get(a,!1,d))?e:j[b]:(f=typeof c,\"string\"===f&&(e=ba.exec(c))&&e[1]&&(c=fa(a,b,e),f=\"number\"),null!=c&&c===c&&(\"number\"===f&&(c+=e&&e[3]||(r.cssNumber[h]?\"\":\"px\")),o.clearCloneStyle||\"\"!==c||0!==b.indexOf(\"background\")||(j[b]=\"inherit\"),g&&\"set\"in g&&void 0===(c=g.set(a,c,d))||(i?j.setProperty(b,c):j[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=r.camelCase(b),i=Ra.test(b);return i||(b=Xa(h)),g=r.cssHooks[b]||r.cssHooks[h],g&&\"get\"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=Oa(a,b,d)),\"normal\"===e&&b in Ta&&(e=Ta[b]),\"\"===c||c?(f=parseFloat(e),c===!0||isFinite(f)?f||0:e):e}}),r.each([\"height\",\"width\"],function(a,b){r.cssHooks[b]={get:function(a,c,d){if(c)return!Qa.test(r.css(a,\"display\"))||a.getClientRects().length&&a.getBoundingClientRect().width?$a(a,b,d):ea(a,Sa,function(){return $a(a,b,d)})},set:function(a,c,d){var e,f=d&&Na(a),g=d&&Za(a,b,d,\"border-box\"===r.css(a,\"boxSizing\",!1,f),f);return g&&(e=ba.exec(c))&&\"px\"!==(e[3]||\"px\")&&(a.style[b]=c,c=r.css(a,b)),Ya(a,c,g)}}}),r.cssHooks.marginLeft=Pa(o.reliableMarginLeft,function(a,b){if(b)return(parseFloat(Oa(a,\"marginLeft\"))||a.getBoundingClientRect().left-ea(a,{marginLeft:0},function(){return a.getBoundingClientRect().left}))+\"px\"}),r.each({margin:\"\",padding:\"\",border:\"Width\"},function(a,b){r.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f=\"string\"==typeof c?c.split(\" \"):[c];d<4;d++)e[a+ca[d]+b]=f[d]||f[d-2]||f[0];return e}},La.test(a)||(r.cssHooks[a+b].set=Ya)}),r.fn.extend({css:function(a,b){return T(this,function(a,b,c){var d,e,f={},g=0;if(Array.isArray(b)){for(d=Na(a),e=b.length;g<e;g++)f[b[g]]=r.css(a,b[g],!1,d);return f}return void 0!==c?r.style(a,b,c):r.css(a,b)},a,b,arguments.length>1)}});function _a(a,b,c,d,e){return new _a.prototype.init(a,b,c,d,e)}r.Tween=_a,_a.prototype={constructor:_a,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||r.easing._default,this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(r.cssNumber[c]?\"\":\"px\")},cur:function(){var a=_a.propHooks[this.prop];return a&&a.get?a.get(this):_a.propHooks._default.get(this)},run:function(a){var b,c=_a.propHooks[this.prop];return this.options.duration?this.pos=b=r.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):_a.propHooks._default.set(this),this}},_a.prototype.init.prototype=_a.prototype,_a.propHooks={_default:{get:function(a){var b;return 1!==a.elem.nodeType||null!=a.elem[a.prop]&&null==a.elem.style[a.prop]?a.elem[a.prop]:(b=r.css(a.elem,a.prop,\"\"),b&&\"auto\"!==b?b:0)},set:function(a){r.fx.step[a.prop]?r.fx.step[a.prop](a):1!==a.elem.nodeType||null==a.elem.style[r.cssProps[a.prop]]&&!r.cssHooks[a.prop]?a.elem[a.prop]=a.now:r.style(a.elem,a.prop,a.now+a.unit)}}},_a.propHooks.scrollTop=_a.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},r.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2},_default:\"swing\"},r.fx=_a.prototype.init,r.fx.step={};var ab,bb,cb=/^(?:toggle|show|hide)$/,db=/queueHooks$/;function eb(){bb&&(d.hidden===!1&&a.requestAnimationFrame?a.requestAnimationFrame(eb):a.setTimeout(eb,r.fx.interval),r.fx.tick())}function fb(){return a.setTimeout(function(){ab=void 0}),ab=r.now()}function gb(a,b){var c,d=0,e={height:a};for(b=b?1:0;d<4;d+=2-b)c=ca[d],e[\"margin\"+c]=e[\"padding\"+c]=a;return b&&(e.opacity=e.width=a),e}function hb(a,b,c){for(var d,e=(kb.tweeners[b]||[]).concat(kb.tweeners[\"*\"]),f=0,g=e.length;f<g;f++)if(d=e[f].call(c,b,a))return d}function ib(a,b,c){var d,e,f,g,h,i,j,k,l=\"width\"in b||\"height\"in b,m=this,n={},o=a.style,p=a.nodeType&&da(a),q=W.get(a,\"fxshow\");c.queue||(g=r._queueHooks(a,\"fx\"),null==g.unqueued&&(g.unqueued=0,h=g.empty.fire,g.empty.fire=function(){g.unqueued||h()}),g.unqueued++,m.always(function(){m.always(function(){g.unqueued--,r.queue(a,\"fx\").length||g.empty.fire()})}));for(d in b)if(e=b[d],cb.test(e)){if(delete b[d],f=f||\"toggle\"===e,e===(p?\"hide\":\"show\")){if(\"show\"!==e||!q||void 0===q[d])continue;p=!0}n[d]=q&&q[d]||r.style(a,d)}if(i=!r.isEmptyObject(b),i||!r.isEmptyObject(n)){l&&1===a.nodeType&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=q&&q.display,null==j&&(j=W.get(a,\"display\")),k=r.css(a,\"display\"),\"none\"===k&&(j?k=j:(ia([a],!0),j=a.style.display||j,k=r.css(a,\"display\"),ia([a]))),(\"inline\"===k||\"inline-block\"===k&&null!=j)&&\"none\"===r.css(a,\"float\")&&(i||(m.done(function(){o.display=j}),null==j&&(k=o.display,j=\"none\"===k?\"\":k)),o.display=\"inline-block\")),c.overflow&&(o.overflow=\"hidden\",m.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]})),i=!1;for(d in n)i||(q?\"hidden\"in q&&(p=q.hidden):q=W.access(a,\"fxshow\",{display:j}),f&&(q.hidden=!p),p&&ia([a],!0),m.done(function(){p||ia([a]),W.remove(a,\"fxshow\");for(d in n)r.style(a,d,n[d])})),i=hb(p?q[d]:0,d,m),d in q||(q[d]=i.start,p&&(i.end=i.start,i.start=0))}}function jb(a,b){var c,d,e,f,g;for(c in a)if(d=r.camelCase(c),e=b[d],f=a[c],Array.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=r.cssHooks[d],g&&\"expand\"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function kb(a,b,c){var d,e,f=0,g=kb.prefilters.length,h=r.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=ab||fb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;g<i;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),f<1&&i?c:(i||h.notifyWith(a,[j,1,0]),h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:r.extend({},b),opts:r.extend(!0,{specialEasing:{},easing:r.easing._default},c),originalProperties:b,originalOptions:c,startTime:ab||fb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=r.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;c<d;c++)j.tweens[c].run(1);return b?(h.notifyWith(a,[j,1,0]),h.resolveWith(a,[j,b])):h.rejectWith(a,[j,b]),this}}),k=j.props;for(jb(k,j.opts.specialEasing);f<g;f++)if(d=kb.prefilters[f].call(j,a,k,j.opts))return r.isFunction(d.stop)&&(r._queueHooks(j.elem,j.opts.queue).stop=r.proxy(d.stop,d)),d;return r.map(k,hb,j),r.isFunction(j.opts.start)&&j.opts.start.call(a,j),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always),r.fx.timer(r.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j}r.Animation=r.extend(kb,{tweeners:{\"*\":[function(a,b){var c=this.createTween(a,b);return fa(c.elem,a,ba.exec(b),c),c}]},tweener:function(a,b){r.isFunction(a)?(b=a,a=[\"*\"]):a=a.match(L);for(var c,d=0,e=a.length;d<e;d++)c=a[d],kb.tweeners[c]=kb.tweeners[c]||[],kb.tweeners[c].unshift(b)},prefilters:[ib],prefilter:function(a,b){b?kb.prefilters.unshift(a):kb.prefilters.push(a)}}),r.speed=function(a,b,c){var d=a&&\"object\"==typeof a?r.extend({},a):{complete:c||!c&&b||r.isFunction(a)&&a,duration:a,easing:c&&b||b&&!r.isFunction(b)&&b};return r.fx.off?d.duration=0:\"number\"!=typeof d.duration&&(d.duration in r.fx.speeds?d.duration=r.fx.speeds[d.duration]:d.duration=r.fx.speeds._default),null!=d.queue&&d.queue!==!0||(d.queue=\"fx\"),d.old=d.complete,d.complete=function(){r.isFunction(d.old)&&d.old.call(this),d.queue&&r.dequeue(this,d.queue)},d},r.fn.extend({fadeTo:function(a,b,c,d){return this.filter(da).css(\"opacity\",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=r.isEmptyObject(a),f=r.speed(b,c,d),g=function(){var b=kb(this,r.extend({},a),f);(e||W.get(this,\"finish\"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return\"string\"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||\"fx\",[]),this.each(function(){var b=!0,e=null!=a&&a+\"queueHooks\",f=r.timers,g=W.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&db.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));!b&&c||r.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||\"fx\"),this.each(function(){var b,c=W.get(this),d=c[a+\"queue\"],e=c[a+\"queueHooks\"],f=r.timers,g=d?d.length:0;for(c.finish=!0,r.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;b<g;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),r.each([\"toggle\",\"show\",\"hide\"],function(a,b){var c=r.fn[b];r.fn[b]=function(a,d,e){return null==a||\"boolean\"==typeof a?c.apply(this,arguments):this.animate(gb(b,!0),a,d,e)}}),r.each({slideDown:gb(\"show\"),slideUp:gb(\"hide\"),slideToggle:gb(\"toggle\"),fadeIn:{opacity:\"show\"},fadeOut:{opacity:\"hide\"},fadeToggle:{opacity:\"toggle\"}},function(a,b){r.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),r.timers=[],r.fx.tick=function(){var a,b=0,c=r.timers;for(ab=r.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||r.fx.stop(),ab=void 0},r.fx.timer=function(a){r.timers.push(a),r.fx.start()},r.fx.interval=13,r.fx.start=function(){bb||(bb=!0,eb())},r.fx.stop=function(){bb=null},r.fx.speeds={slow:600,fast:200,_default:400},r.fn.delay=function(b,c){return b=r.fx?r.fx.speeds[b]||b:b,c=c||\"fx\",this.queue(c,function(c,d){var e=a.setTimeout(c,b);d.stop=function(){a.clearTimeout(e)}})},function(){var a=d.createElement(\"input\"),b=d.createElement(\"select\"),c=b.appendChild(d.createElement(\"option\"));a.type=\"checkbox\",o.checkOn=\"\"!==a.value,o.optSelected=c.selected,a=d.createElement(\"input\"),a.value=\"t\",a.type=\"radio\",o.radioValue=\"t\"===a.value}();var lb,mb=r.expr.attrHandle;r.fn.extend({attr:function(a,b){return T(this,r.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){r.removeAttr(this,a)})}}),r.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return\"undefined\"==typeof a.getAttribute?r.prop(a,b,c):(1===f&&r.isXMLDoc(a)||(e=r.attrHooks[b.toLowerCase()]||(r.expr.match.bool.test(b)?lb:void 0)),void 0!==c?null===c?void r.removeAttr(a,b):e&&\"set\"in e&&void 0!==(d=e.set(a,c,b))?d:(a.setAttribute(b,c+\"\"),c):e&&\"get\"in e&&null!==(d=e.get(a,b))?d:(d=r.find.attr(a,b),\nnull==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&\"radio\"===b&&B(a,\"input\")){var c=a.value;return a.setAttribute(\"type\",b),c&&(a.value=c),b}}}},removeAttr:function(a,b){var c,d=0,e=b&&b.match(L);if(e&&1===a.nodeType)while(c=e[d++])a.removeAttribute(c)}}),lb={set:function(a,b,c){return b===!1?r.removeAttr(a,c):a.setAttribute(c,c),c}},r.each(r.expr.match.bool.source.match(/\\w+/g),function(a,b){var c=mb[b]||r.find.attr;mb[b]=function(a,b,d){var e,f,g=b.toLowerCase();return d||(f=mb[g],mb[g]=e,e=null!=c(a,b,d)?g:null,mb[g]=f),e}});var nb=/^(?:input|select|textarea|button)$/i,ob=/^(?:a|area)$/i;r.fn.extend({prop:function(a,b){return T(this,r.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[r.propFix[a]||a]})}}),r.extend({prop:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return 1===f&&r.isXMLDoc(a)||(b=r.propFix[b]||b,e=r.propHooks[b]),void 0!==c?e&&\"set\"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&\"get\"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=r.find.attr(a,\"tabindex\");return b?parseInt(b,10):nb.test(a.nodeName)||ob.test(a.nodeName)&&a.href?0:-1}}},propFix:{\"for\":\"htmlFor\",\"class\":\"className\"}}),o.optSelected||(r.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null},set:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex)}}),r.each([\"tabIndex\",\"readOnly\",\"maxLength\",\"cellSpacing\",\"cellPadding\",\"rowSpan\",\"colSpan\",\"useMap\",\"frameBorder\",\"contentEditable\"],function(){r.propFix[this.toLowerCase()]=this});function pb(a){var b=a.match(L)||[];return b.join(\" \")}function qb(a){return a.getAttribute&&a.getAttribute(\"class\")||\"\"}r.fn.extend({addClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).addClass(a.call(this,b,qb(this)))});if(\"string\"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&\" \"+pb(e)+\" \"){g=0;while(f=b[g++])d.indexOf(\" \"+f+\" \")<0&&(d+=f+\" \");h=pb(d),e!==h&&c.setAttribute(\"class\",h)}}return this},removeClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).removeClass(a.call(this,b,qb(this)))});if(!arguments.length)return this.attr(\"class\",\"\");if(\"string\"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&\" \"+pb(e)+\" \"){g=0;while(f=b[g++])while(d.indexOf(\" \"+f+\" \")>-1)d=d.replace(\" \"+f+\" \",\" \");h=pb(d),e!==h&&c.setAttribute(\"class\",h)}}return this},toggleClass:function(a,b){var c=typeof a;return\"boolean\"==typeof b&&\"string\"===c?b?this.addClass(a):this.removeClass(a):r.isFunction(a)?this.each(function(c){r(this).toggleClass(a.call(this,c,qb(this),b),b)}):this.each(function(){var b,d,e,f;if(\"string\"===c){d=0,e=r(this),f=a.match(L)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else void 0!==a&&\"boolean\"!==c||(b=qb(this),b&&W.set(this,\"__className__\",b),this.setAttribute&&this.setAttribute(\"class\",b||a===!1?\"\":W.get(this,\"__className__\")||\"\"))})},hasClass:function(a){var b,c,d=0;b=\" \"+a+\" \";while(c=this[d++])if(1===c.nodeType&&(\" \"+pb(qb(c))+\" \").indexOf(b)>-1)return!0;return!1}});var rb=/\\r/g;r.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=r.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,r(this).val()):a,null==e?e=\"\":\"number\"==typeof e?e+=\"\":Array.isArray(e)&&(e=r.map(e,function(a){return null==a?\"\":a+\"\"})),b=r.valHooks[this.type]||r.valHooks[this.nodeName.toLowerCase()],b&&\"set\"in b&&void 0!==b.set(this,e,\"value\")||(this.value=e))});if(e)return b=r.valHooks[e.type]||r.valHooks[e.nodeName.toLowerCase()],b&&\"get\"in b&&void 0!==(c=b.get(e,\"value\"))?c:(c=e.value,\"string\"==typeof c?c.replace(rb,\"\"):null==c?\"\":c)}}}),r.extend({valHooks:{option:{get:function(a){var b=r.find.attr(a,\"value\");return null!=b?b:pb(r.text(a))}},select:{get:function(a){var b,c,d,e=a.options,f=a.selectedIndex,g=\"select-one\"===a.type,h=g?null:[],i=g?f+1:e.length;for(d=f<0?i:g?f:0;d<i;d++)if(c=e[d],(c.selected||d===f)&&!c.disabled&&(!c.parentNode.disabled||!B(c.parentNode,\"optgroup\"))){if(b=r(c).val(),g)return b;h.push(b)}return h},set:function(a,b){var c,d,e=a.options,f=r.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=r.inArray(r.valHooks.option.get(d),f)>-1)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),r.each([\"radio\",\"checkbox\"],function(){r.valHooks[this]={set:function(a,b){if(Array.isArray(b))return a.checked=r.inArray(r(a).val(),b)>-1}},o.checkOn||(r.valHooks[this].get=function(a){return null===a.getAttribute(\"value\")?\"on\":a.value})});var sb=/^(?:focusinfocus|focusoutblur)$/;r.extend(r.event,{trigger:function(b,c,e,f){var g,h,i,j,k,m,n,o=[e||d],p=l.call(b,\"type\")?b.type:b,q=l.call(b,\"namespace\")?b.namespace.split(\".\"):[];if(h=i=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!sb.test(p+r.event.triggered)&&(p.indexOf(\".\")>-1&&(q=p.split(\".\"),p=q.shift(),q.sort()),k=p.indexOf(\":\")<0&&\"on\"+p,b=b[r.expando]?b:new r.Event(p,\"object\"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=q.join(\".\"),b.rnamespace=b.namespace?new RegExp(\"(^|\\\\.)\"+q.join(\"\\\\.(?:.*\\\\.|)\")+\"(\\\\.|$)\"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:r.makeArray(c,[b]),n=r.event.special[p]||{},f||!n.trigger||n.trigger.apply(e,c)!==!1)){if(!f&&!n.noBubble&&!r.isWindow(e)){for(j=n.delegateType||p,sb.test(j+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),i=h;i===(e.ownerDocument||d)&&o.push(i.defaultView||i.parentWindow||a)}g=0;while((h=o[g++])&&!b.isPropagationStopped())b.type=g>1?j:n.bindType||p,m=(W.get(h,\"events\")||{})[b.type]&&W.get(h,\"handle\"),m&&m.apply(h,c),m=k&&h[k],m&&m.apply&&U(h)&&(b.result=m.apply(h,c),b.result===!1&&b.preventDefault());return b.type=p,f||b.isDefaultPrevented()||n._default&&n._default.apply(o.pop(),c)!==!1||!U(e)||k&&r.isFunction(e[p])&&!r.isWindow(e)&&(i=e[k],i&&(e[k]=null),r.event.triggered=p,e[p](),r.event.triggered=void 0,i&&(e[k]=i)),b.result}},simulate:function(a,b,c){var d=r.extend(new r.Event,c,{type:a,isSimulated:!0});r.event.trigger(d,null,b)}}),r.fn.extend({trigger:function(a,b){return this.each(function(){r.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];if(c)return r.event.trigger(a,b,c,!0)}}),r.each(\"blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu\".split(\" \"),function(a,b){r.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),r.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),o.focusin=\"onfocusin\"in a,o.focusin||r.each({focus:\"focusin\",blur:\"focusout\"},function(a,b){var c=function(a){r.event.simulate(b,a.target,r.event.fix(a))};r.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=W.access(d,b);e||d.addEventListener(a,c,!0),W.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=W.access(d,b)-1;e?W.access(d,b,e):(d.removeEventListener(a,c,!0),W.remove(d,b))}}});var tb=a.location,ub=r.now(),vb=/\\?/;r.parseXML=function(b){var c;if(!b||\"string\"!=typeof b)return null;try{c=(new a.DOMParser).parseFromString(b,\"text/xml\")}catch(d){c=void 0}return c&&!c.getElementsByTagName(\"parsererror\").length||r.error(\"Invalid XML: \"+b),c};var wb=/\\[\\]$/,xb=/\\r?\\n/g,yb=/^(?:submit|button|image|reset|file)$/i,zb=/^(?:input|select|textarea|keygen)/i;function Ab(a,b,c,d){var e;if(Array.isArray(b))r.each(b,function(b,e){c||wb.test(a)?d(a,e):Ab(a+\"[\"+(\"object\"==typeof e&&null!=e?b:\"\")+\"]\",e,c,d)});else if(c||\"object\"!==r.type(b))d(a,b);else for(e in b)Ab(a+\"[\"+e+\"]\",b[e],c,d)}r.param=function(a,b){var c,d=[],e=function(a,b){var c=r.isFunction(b)?b():b;d[d.length]=encodeURIComponent(a)+\"=\"+encodeURIComponent(null==c?\"\":c)};if(Array.isArray(a)||a.jquery&&!r.isPlainObject(a))r.each(a,function(){e(this.name,this.value)});else for(c in a)Ab(c,a[c],b,e);return d.join(\"&\")},r.fn.extend({serialize:function(){return r.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=r.prop(this,\"elements\");return a?r.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!r(this).is(\":disabled\")&&zb.test(this.nodeName)&&!yb.test(a)&&(this.checked||!ja.test(a))}).map(function(a,b){var c=r(this).val();return null==c?null:Array.isArray(c)?r.map(c,function(a){return{name:b.name,value:a.replace(xb,\"\\r\\n\")}}):{name:b.name,value:c.replace(xb,\"\\r\\n\")}}).get()}});var Bb=/%20/g,Cb=/#.*$/,Db=/([?&])_=[^&]*/,Eb=/^(.*?):[ \\t]*([^\\r\\n]*)$/gm,Fb=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Gb=/^(?:GET|HEAD)$/,Hb=/^\\/\\//,Ib={},Jb={},Kb=\"*/\".concat(\"*\"),Lb=d.createElement(\"a\");Lb.href=tb.href;function Mb(a){return function(b,c){\"string\"!=typeof b&&(c=b,b=\"*\");var d,e=0,f=b.toLowerCase().match(L)||[];if(r.isFunction(c))while(d=f[e++])\"+\"===d[0]?(d=d.slice(1)||\"*\",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Nb(a,b,c,d){var e={},f=a===Jb;function g(h){var i;return e[h]=!0,r.each(a[h]||[],function(a,h){var j=h(b,c,d);return\"string\"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e[\"*\"]&&g(\"*\")}function Ob(a,b){var c,d,e=r.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&r.extend(!0,a,d),a}function Pb(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while(\"*\"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader(\"Content-Type\"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+\" \"+i[0]]){f=e;break}g||(g=e)}f=f||g}if(f)return f!==i[0]&&i.unshift(f),c[f]}function Qb(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if(\"*\"===f)f=i;else if(\"*\"!==i&&i!==f){if(g=j[i+\" \"+f]||j[\"* \"+f],!g)for(e in j)if(h=e.split(\" \"),h[1]===f&&(g=j[i+\" \"+h[0]]||j[\"* \"+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a[\"throws\"])b=g(b);else try{b=g(b)}catch(l){return{state:\"parsererror\",error:g?l:\"No conversion from \"+i+\" to \"+f}}}return{state:\"success\",data:b}}r.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:tb.href,type:\"GET\",isLocal:Fb.test(tb.protocol),global:!0,processData:!0,async:!0,contentType:\"application/x-www-form-urlencoded; charset=UTF-8\",accepts:{\"*\":Kb,text:\"text/plain\",html:\"text/html\",xml:\"application/xml, text/xml\",json:\"application/json, text/javascript\"},contents:{xml:/\\bxml\\b/,html:/\\bhtml/,json:/\\bjson\\b/},responseFields:{xml:\"responseXML\",text:\"responseText\",json:\"responseJSON\"},converters:{\"* text\":String,\"text html\":!0,\"text json\":JSON.parse,\"text xml\":r.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Ob(Ob(a,r.ajaxSettings),b):Ob(r.ajaxSettings,a)},ajaxPrefilter:Mb(Ib),ajaxTransport:Mb(Jb),ajax:function(b,c){\"object\"==typeof b&&(c=b,b=void 0),c=c||{};var e,f,g,h,i,j,k,l,m,n,o=r.ajaxSetup({},c),p=o.context||o,q=o.context&&(p.nodeType||p.jquery)?r(p):r.event,s=r.Deferred(),t=r.Callbacks(\"once memory\"),u=o.statusCode||{},v={},w={},x=\"canceled\",y={readyState:0,getResponseHeader:function(a){var b;if(k){if(!h){h={};while(b=Eb.exec(g))h[b[1].toLowerCase()]=b[2]}b=h[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return k?g:null},setRequestHeader:function(a,b){return null==k&&(a=w[a.toLowerCase()]=w[a.toLowerCase()]||a,v[a]=b),this},overrideMimeType:function(a){return null==k&&(o.mimeType=a),this},statusCode:function(a){var b;if(a)if(k)y.always(a[y.status]);else for(b in a)u[b]=[u[b],a[b]];return this},abort:function(a){var b=a||x;return e&&e.abort(b),A(0,b),this}};if(s.promise(y),o.url=((b||o.url||tb.href)+\"\").replace(Hb,tb.protocol+\"//\"),o.type=c.method||c.type||o.method||o.type,o.dataTypes=(o.dataType||\"*\").toLowerCase().match(L)||[\"\"],null==o.crossDomain){j=d.createElement(\"a\");try{j.href=o.url,j.href=j.href,o.crossDomain=Lb.protocol+\"//\"+Lb.host!=j.protocol+\"//\"+j.host}catch(z){o.crossDomain=!0}}if(o.data&&o.processData&&\"string\"!=typeof o.data&&(o.data=r.param(o.data,o.traditional)),Nb(Ib,o,c,y),k)return y;l=r.event&&o.global,l&&0===r.active++&&r.event.trigger(\"ajaxStart\"),o.type=o.type.toUpperCase(),o.hasContent=!Gb.test(o.type),f=o.url.replace(Cb,\"\"),o.hasContent?o.data&&o.processData&&0===(o.contentType||\"\").indexOf(\"application/x-www-form-urlencoded\")&&(o.data=o.data.replace(Bb,\"+\")):(n=o.url.slice(f.length),o.data&&(f+=(vb.test(f)?\"&\":\"?\")+o.data,delete o.data),o.cache===!1&&(f=f.replace(Db,\"$1\"),n=(vb.test(f)?\"&\":\"?\")+\"_=\"+ub++ +n),o.url=f+n),o.ifModified&&(r.lastModified[f]&&y.setRequestHeader(\"If-Modified-Since\",r.lastModified[f]),r.etag[f]&&y.setRequestHeader(\"If-None-Match\",r.etag[f])),(o.data&&o.hasContent&&o.contentType!==!1||c.contentType)&&y.setRequestHeader(\"Content-Type\",o.contentType),y.setRequestHeader(\"Accept\",o.dataTypes[0]&&o.accepts[o.dataTypes[0]]?o.accepts[o.dataTypes[0]]+(\"*\"!==o.dataTypes[0]?\", \"+Kb+\"; q=0.01\":\"\"):o.accepts[\"*\"]);for(m in o.headers)y.setRequestHeader(m,o.headers[m]);if(o.beforeSend&&(o.beforeSend.call(p,y,o)===!1||k))return y.abort();if(x=\"abort\",t.add(o.complete),y.done(o.success),y.fail(o.error),e=Nb(Jb,o,c,y)){if(y.readyState=1,l&&q.trigger(\"ajaxSend\",[y,o]),k)return y;o.async&&o.timeout>0&&(i=a.setTimeout(function(){y.abort(\"timeout\")},o.timeout));try{k=!1,e.send(v,A)}catch(z){if(k)throw z;A(-1,z)}}else A(-1,\"No Transport\");function A(b,c,d,h){var j,m,n,v,w,x=c;k||(k=!0,i&&a.clearTimeout(i),e=void 0,g=h||\"\",y.readyState=b>0?4:0,j=b>=200&&b<300||304===b,d&&(v=Pb(o,y,d)),v=Qb(o,v,y,j),j?(o.ifModified&&(w=y.getResponseHeader(\"Last-Modified\"),w&&(r.lastModified[f]=w),w=y.getResponseHeader(\"etag\"),w&&(r.etag[f]=w)),204===b||\"HEAD\"===o.type?x=\"nocontent\":304===b?x=\"notmodified\":(x=v.state,m=v.data,n=v.error,j=!n)):(n=x,!b&&x||(x=\"error\",b<0&&(b=0))),y.status=b,y.statusText=(c||x)+\"\",j?s.resolveWith(p,[m,x,y]):s.rejectWith(p,[y,x,n]),y.statusCode(u),u=void 0,l&&q.trigger(j?\"ajaxSuccess\":\"ajaxError\",[y,o,j?m:n]),t.fireWith(p,[y,x]),l&&(q.trigger(\"ajaxComplete\",[y,o]),--r.active||r.event.trigger(\"ajaxStop\")))}return y},getJSON:function(a,b,c){return r.get(a,b,c,\"json\")},getScript:function(a,b){return r.get(a,void 0,b,\"script\")}}),r.each([\"get\",\"post\"],function(a,b){r[b]=function(a,c,d,e){return r.isFunction(c)&&(e=e||d,d=c,c=void 0),r.ajax(r.extend({url:a,type:b,dataType:e,data:c,success:d},r.isPlainObject(a)&&a))}}),r._evalUrl=function(a){return r.ajax({url:a,type:\"GET\",dataType:\"script\",cache:!0,async:!1,global:!1,\"throws\":!0})},r.fn.extend({wrapAll:function(a){var b;return this[0]&&(r.isFunction(a)&&(a=a.call(this[0])),b=r(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this},wrapInner:function(a){return r.isFunction(a)?this.each(function(b){r(this).wrapInner(a.call(this,b))}):this.each(function(){var b=r(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=r.isFunction(a);return this.each(function(c){r(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(a){return this.parent(a).not(\"body\").each(function(){r(this).replaceWith(this.childNodes)}),this}}),r.expr.pseudos.hidden=function(a){return!r.expr.pseudos.visible(a)},r.expr.pseudos.visible=function(a){return!!(a.offsetWidth||a.offsetHeight||a.getClientRects().length)},r.ajaxSettings.xhr=function(){try{return new a.XMLHttpRequest}catch(b){}};var Rb={0:200,1223:204},Sb=r.ajaxSettings.xhr();o.cors=!!Sb&&\"withCredentials\"in Sb,o.ajax=Sb=!!Sb,r.ajaxTransport(function(b){var c,d;if(o.cors||Sb&&!b.crossDomain)return{send:function(e,f){var g,h=b.xhr();if(h.open(b.type,b.url,b.async,b.username,b.password),b.xhrFields)for(g in b.xhrFields)h[g]=b.xhrFields[g];b.mimeType&&h.overrideMimeType&&h.overrideMimeType(b.mimeType),b.crossDomain||e[\"X-Requested-With\"]||(e[\"X-Requested-With\"]=\"XMLHttpRequest\");for(g in e)h.setRequestHeader(g,e[g]);c=function(a){return function(){c&&(c=d=h.onload=h.onerror=h.onabort=h.onreadystatechange=null,\"abort\"===a?h.abort():\"error\"===a?\"number\"!=typeof h.status?f(0,\"error\"):f(h.status,h.statusText):f(Rb[h.status]||h.status,h.statusText,\"text\"!==(h.responseType||\"text\")||\"string\"!=typeof h.responseText?{binary:h.response}:{text:h.responseText},h.getAllResponseHeaders()))}},h.onload=c(),d=h.onerror=c(\"error\"),void 0!==h.onabort?h.onabort=d:h.onreadystatechange=function(){4===h.readyState&&a.setTimeout(function(){c&&d()})},c=c(\"abort\");try{h.send(b.hasContent&&b.data||null)}catch(i){if(c)throw i}},abort:function(){c&&c()}}}),r.ajaxPrefilter(function(a){a.crossDomain&&(a.contents.script=!1)}),r.ajaxSetup({accepts:{script:\"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript\"},contents:{script:/\\b(?:java|ecma)script\\b/},converters:{\"text script\":function(a){return r.globalEval(a),a}}}),r.ajaxPrefilter(\"script\",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type=\"GET\")}),r.ajaxTransport(\"script\",function(a){if(a.crossDomain){var b,c;return{send:function(e,f){b=r(\"<script>\").prop({charset:a.scriptCharset,src:a.url}).on(\"load error\",c=function(a){b.remove(),c=null,a&&f(\"error\"===a.type?404:200,a.type)}),d.head.appendChild(b[0])},abort:function(){c&&c()}}}});var Tb=[],Ub=/(=)\\?(?=&|$)|\\?\\?/;r.ajaxSetup({jsonp:\"callback\",jsonpCallback:function(){var a=Tb.pop()||r.expando+\"_\"+ub++;return this[a]=!0,a}}),r.ajaxPrefilter(\"json jsonp\",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(Ub.test(b.url)?\"url\":\"string\"==typeof b.data&&0===(b.contentType||\"\").indexOf(\"application/x-www-form-urlencoded\")&&Ub.test(b.data)&&\"data\");if(h||\"jsonp\"===b.dataTypes[0])return e=b.jsonpCallback=r.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(Ub,\"$1\"+e):b.jsonp!==!1&&(b.url+=(vb.test(b.url)?\"&\":\"?\")+b.jsonp+\"=\"+e),b.converters[\"script json\"]=function(){return g||r.error(e+\" was not called\"),g[0]},b.dataTypes[0]=\"json\",f=a[e],a[e]=function(){g=arguments},d.always(function(){void 0===f?r(a).removeProp(e):a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,Tb.push(e)),g&&r.isFunction(f)&&f(g[0]),g=f=void 0}),\"script\"}),o.createHTMLDocument=function(){var a=d.implementation.createHTMLDocument(\"\").body;return a.innerHTML=\"<form></form><form></form>\",2===a.childNodes.length}(),r.parseHTML=function(a,b,c){if(\"string\"!=typeof a)return[];\"boolean\"==typeof b&&(c=b,b=!1);var e,f,g;return b||(o.createHTMLDocument?(b=d.implementation.createHTMLDocument(\"\"),e=b.createElement(\"base\"),e.href=d.location.href,b.head.appendChild(e)):b=d),f=C.exec(a),g=!c&&[],f?[b.createElement(f[1])]:(f=qa([a],b,g),g&&g.length&&r(g).remove(),r.merge([],f.childNodes))},r.fn.load=function(a,b,c){var d,e,f,g=this,h=a.indexOf(\" \");return h>-1&&(d=pb(a.slice(h)),a=a.slice(0,h)),r.isFunction(b)?(c=b,b=void 0):b&&\"object\"==typeof b&&(e=\"POST\"),g.length>0&&r.ajax({url:a,type:e||\"GET\",dataType:\"html\",data:b}).done(function(a){f=arguments,g.html(d?r(\"<div>\").append(r.parseHTML(a)).find(d):a)}).always(c&&function(a,b){g.each(function(){c.apply(this,f||[a.responseText,b,a])})}),this},r.each([\"ajaxStart\",\"ajaxStop\",\"ajaxComplete\",\"ajaxError\",\"ajaxSuccess\",\"ajaxSend\"],function(a,b){r.fn[b]=function(a){return this.on(b,a)}}),r.expr.pseudos.animated=function(a){return r.grep(r.timers,function(b){return a===b.elem}).length},r.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=r.css(a,\"position\"),l=r(a),m={};\"static\"===k&&(a.style.position=\"relative\"),h=l.offset(),f=r.css(a,\"top\"),i=r.css(a,\"left\"),j=(\"absolute\"===k||\"fixed\"===k)&&(f+i).indexOf(\"auto\")>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),r.isFunction(b)&&(b=b.call(a,c,r.extend({},h))),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),\"using\"in b?b.using.call(a,m):l.css(m)}},r.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){r.offset.setOffset(this,a,b)});var b,c,d,e,f=this[0];if(f)return f.getClientRects().length?(d=f.getBoundingClientRect(),b=f.ownerDocument,c=b.documentElement,e=b.defaultView,{top:d.top+e.pageYOffset-c.clientTop,left:d.left+e.pageXOffset-c.clientLeft}):{top:0,left:0}},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return\"fixed\"===r.css(c,\"position\")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),B(a[0],\"html\")||(d=a.offset()),d={top:d.top+r.css(a[0],\"borderTopWidth\",!0),left:d.left+r.css(a[0],\"borderLeftWidth\",!0)}),{top:b.top-d.top-r.css(c,\"marginTop\",!0),left:b.left-d.left-r.css(c,\"marginLeft\",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent;while(a&&\"static\"===r.css(a,\"position\"))a=a.offsetParent;return a||ra})}}),r.each({scrollLeft:\"pageXOffset\",scrollTop:\"pageYOffset\"},function(a,b){var c=\"pageYOffset\"===b;r.fn[a]=function(d){return T(this,function(a,d,e){var f;return r.isWindow(a)?f=a:9===a.nodeType&&(f=a.defaultView),void 0===e?f?f[b]:a[d]:void(f?f.scrollTo(c?f.pageXOffset:e,c?e:f.pageYOffset):a[d]=e)},a,d,arguments.length)}}),r.each([\"top\",\"left\"],function(a,b){r.cssHooks[b]=Pa(o.pixelPosition,function(a,c){if(c)return c=Oa(a,b),Ma.test(c)?r(a).position()[b]+\"px\":c})}),r.each({Height:\"height\",Width:\"width\"},function(a,b){r.each({padding:\"inner\"+a,content:b,\"\":\"outer\"+a},function(c,d){r.fn[d]=function(e,f){var g=arguments.length&&(c||\"boolean\"!=typeof e),h=c||(e===!0||f===!0?\"margin\":\"border\");return T(this,function(b,c,e){var f;return r.isWindow(b)?0===d.indexOf(\"outer\")?b[\"inner\"+a]:b.document.documentElement[\"client\"+a]:9===b.nodeType?(f=b.documentElement,Math.max(b.body[\"scroll\"+a],f[\"scroll\"+a],b.body[\"offset\"+a],f[\"offset\"+a],f[\"client\"+a])):void 0===e?r.css(b,c,h):r.style(b,c,e,h)},b,g?e:void 0,g)}})}),r.fn.extend({bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,\"**\"):this.off(b,a||\"**\",c)}}),r.holdReady=function(a){a?r.readyWait++:r.ready(!0)},r.isArray=Array.isArray,r.parseJSON=JSON.parse,r.nodeName=B,\"function\"==typeof define&&define.amd&&define(\"jquery\",[],function(){return r});var Vb=a.jQuery,Wb=a.$;return r.noConflict=function(b){return a.$===r&&(a.$=Wb),b&&a.jQuery===r&&(a.jQuery=Vb),r},b||(a.jQuery=a.$=r),r});"
  },
  {
    "path": "docs/source/themes/catlib/source/js/vue.js",
    "content": "/*!\n * Vue.js v2.3.0\n * (c) 2014-2017 Evan You\n * Released under the MIT License.\n */\n(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\t(global.Vue = factory());\n}(this, (function () { 'use strict';\n\n/*  */\n\n// these helpers produces better vm code in JS engines due to their\n// explicitness and function inlining\nfunction isUndef (v) {\n  return v === undefined || v === null\n}\n\nfunction isDef (v) {\n  return v !== undefined && v !== null\n}\n\nfunction isTrue (v) {\n  return v === true\n}\n\n/**\n * Check if value is primitive\n */\nfunction isPrimitive (value) {\n  return typeof value === 'string' || typeof value === 'number'\n}\n\n/**\n * Quick object check - this is primarily used to tell\n * Objects from primitive values when we know the value\n * is a JSON-compliant type.\n */\nfunction isObject (obj) {\n  return obj !== null && typeof obj === 'object'\n}\n\nvar toString = Object.prototype.toString;\n\n/**\n * Strict object type check. Only returns true\n * for plain JavaScript objects.\n */\nfunction isPlainObject (obj) {\n  return toString.call(obj) === '[object Object]'\n}\n\nfunction isRegExp (v) {\n  return toString.call(v) === '[object RegExp]'\n}\n\n/**\n * Convert a value to a string that is actually rendered.\n */\nfunction _toString (val) {\n  return val == null\n    ? ''\n    : typeof val === 'object'\n      ? JSON.stringify(val, null, 2)\n      : String(val)\n}\n\n/**\n * Convert a input value to a number for persistence.\n * If the conversion fails, return original string.\n */\nfunction toNumber (val) {\n  var n = parseFloat(val);\n  return isNaN(n) ? val : n\n}\n\n/**\n * Make a map and return a function for checking if a key\n * is in that map.\n */\nfunction makeMap (\n  str,\n  expectsLowerCase\n) {\n  var map = Object.create(null);\n  var list = str.split(',');\n  for (var i = 0; i < list.length; i++) {\n    map[list[i]] = true;\n  }\n  return expectsLowerCase\n    ? function (val) { return map[val.toLowerCase()]; }\n    : function (val) { return map[val]; }\n}\n\n/**\n * Check if a tag is a built-in tag.\n */\nvar isBuiltInTag = makeMap('slot,component', true);\n\n/**\n * Remove an item from an array\n */\nfunction remove (arr, item) {\n  if (arr.length) {\n    var index = arr.indexOf(item);\n    if (index > -1) {\n      return arr.splice(index, 1)\n    }\n  }\n}\n\n/**\n * Check whether the object has the property.\n */\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nfunction hasOwn (obj, key) {\n  return hasOwnProperty.call(obj, key)\n}\n\n/**\n * Create a cached version of a pure function.\n */\nfunction cached (fn) {\n  var cache = Object.create(null);\n  return (function cachedFn (str) {\n    var hit = cache[str];\n    return hit || (cache[str] = fn(str))\n  })\n}\n\n/**\n * Camelize a hyphen-delimited string.\n */\nvar camelizeRE = /-(\\w)/g;\nvar camelize = cached(function (str) {\n  return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })\n});\n\n/**\n * Capitalize a string.\n */\nvar capitalize = cached(function (str) {\n  return str.charAt(0).toUpperCase() + str.slice(1)\n});\n\n/**\n * Hyphenate a camelCase string.\n */\nvar hyphenateRE = /([^-])([A-Z])/g;\nvar hyphenate = cached(function (str) {\n  return str\n    .replace(hyphenateRE, '$1-$2')\n    .replace(hyphenateRE, '$1-$2')\n    .toLowerCase()\n});\n\n/**\n * Simple bind, faster than native\n */\nfunction bind (fn, ctx) {\n  function boundFn (a) {\n    var l = arguments.length;\n    return l\n      ? l > 1\n        ? fn.apply(ctx, arguments)\n        : fn.call(ctx, a)\n      : fn.call(ctx)\n  }\n  // record original fn length\n  boundFn._length = fn.length;\n  return boundFn\n}\n\n/**\n * Convert an Array-like object to a real Array.\n */\nfunction toArray (list, start) {\n  start = start || 0;\n  var i = list.length - start;\n  var ret = new Array(i);\n  while (i--) {\n    ret[i] = list[i + start];\n  }\n  return ret\n}\n\n/**\n * Mix properties into target object.\n */\nfunction extend (to, _from) {\n  for (var key in _from) {\n    to[key] = _from[key];\n  }\n  return to\n}\n\n/**\n * Merge an Array of Objects into a single Object.\n */\nfunction toObject (arr) {\n  var res = {};\n  for (var i = 0; i < arr.length; i++) {\n    if (arr[i]) {\n      extend(res, arr[i]);\n    }\n  }\n  return res\n}\n\n/**\n * Perform no operation.\n */\nfunction noop () {}\n\n/**\n * Always return false.\n */\nvar no = function () { return false; };\n\n/**\n * Return same value\n */\nvar identity = function (_) { return _; };\n\n/**\n * Generate a static keys string from compiler modules.\n */\nfunction genStaticKeys (modules) {\n  return modules.reduce(function (keys, m) {\n    return keys.concat(m.staticKeys || [])\n  }, []).join(',')\n}\n\n/**\n * Check if two values are loosely equal - that is,\n * if they are plain objects, do they have the same shape?\n */\nfunction looseEqual (a, b) {\n  var isObjectA = isObject(a);\n  var isObjectB = isObject(b);\n  if (isObjectA && isObjectB) {\n    try {\n      return JSON.stringify(a) === JSON.stringify(b)\n    } catch (e) {\n      // possible circular reference\n      return a === b\n    }\n  } else if (!isObjectA && !isObjectB) {\n    return String(a) === String(b)\n  } else {\n    return false\n  }\n}\n\nfunction looseIndexOf (arr, val) {\n  for (var i = 0; i < arr.length; i++) {\n    if (looseEqual(arr[i], val)) { return i }\n  }\n  return -1\n}\n\n/**\n * Ensure a function is called only once.\n */\nfunction once (fn) {\n  var called = false;\n  return function () {\n    if (!called) {\n      called = true;\n      fn.apply(this, arguments);\n    }\n  }\n}\n\nvar SSR_ATTR = 'data-server-rendered';\n\nvar ASSET_TYPES = [\n  'component',\n  'directive',\n  'filter'\n];\n\nvar LIFECYCLE_HOOKS = [\n  'beforeCreate',\n  'created',\n  'beforeMount',\n  'mounted',\n  'beforeUpdate',\n  'updated',\n  'beforeDestroy',\n  'destroyed',\n  'activated',\n  'deactivated'\n];\n\n/*  */\n\nvar config = ({\n  /**\n   * Option merge strategies (used in core/util/options)\n   */\n  optionMergeStrategies: Object.create(null),\n\n  /**\n   * Whether to suppress warnings.\n   */\n  silent: false,\n\n  /**\n   * Show production mode tip message on boot?\n   */\n  productionTip: \"development\" !== 'production',\n\n  /**\n   * Whether to enable devtools\n   */\n  devtools: \"development\" !== 'production',\n\n  /**\n   * Whether to record perf\n   */\n  performance: false,\n\n  /**\n   * Error handler for watcher errors\n   */\n  errorHandler: null,\n\n  /**\n   * Ignore certain custom elements\n   */\n  ignoredElements: [],\n\n  /**\n   * Custom user key aliases for v-on\n   */\n  keyCodes: Object.create(null),\n\n  /**\n   * Check if a tag is reserved so that it cannot be registered as a\n   * component. This is platform-dependent and may be overwritten.\n   */\n  isReservedTag: no,\n\n  /**\n   * Check if an attribute is reserved so that it cannot be used as a component\n   * prop. This is platform-dependent and may be overwritten.\n   */\n  isReservedAttr: no,\n\n  /**\n   * Check if a tag is an unknown element.\n   * Platform-dependent.\n   */\n  isUnknownElement: no,\n\n  /**\n   * Get the namespace of an element\n   */\n  getTagNamespace: noop,\n\n  /**\n   * Parse the real tag name for the specific platform.\n   */\n  parsePlatformTagName: identity,\n\n  /**\n   * Check if an attribute must be bound using property, e.g. value\n   * Platform-dependent.\n   */\n  mustUseProp: no,\n\n  /**\n   * Exposed for legacy reasons\n   */\n  _lifecycleHooks: LIFECYCLE_HOOKS\n});\n\n/*  */\n\nvar emptyObject = Object.freeze({});\n\n/**\n * Check if a string starts with $ or _\n */\nfunction isReserved (str) {\n  var c = (str + '').charCodeAt(0);\n  return c === 0x24 || c === 0x5F\n}\n\n/**\n * Define a property.\n */\nfunction def (obj, key, val, enumerable) {\n  Object.defineProperty(obj, key, {\n    value: val,\n    enumerable: !!enumerable,\n    writable: true,\n    configurable: true\n  });\n}\n\n/**\n * Parse simple path.\n */\nvar bailRE = /[^\\w.$]/;\nfunction parsePath (path) {\n  if (bailRE.test(path)) {\n    return\n  }\n  var segments = path.split('.');\n  return function (obj) {\n    for (var i = 0; i < segments.length; i++) {\n      if (!obj) { return }\n      obj = obj[segments[i]];\n    }\n    return obj\n  }\n}\n\nvar warn = noop;\nvar tip = noop;\nvar formatComponentName;\n\n{\n  var hasConsole = typeof console !== 'undefined';\n  var classifyRE = /(?:^|[-_])(\\w)/g;\n  var classify = function (str) { return str\n    .replace(classifyRE, function (c) { return c.toUpperCase(); })\n    .replace(/[-_]/g, ''); };\n\n  warn = function (msg, vm) {\n    if (hasConsole && (!config.silent)) {\n      console.error(\"[Vue warn]: \" + msg + (\n        vm ? generateComponentTrace(vm) : ''\n      ));\n    }\n  };\n\n  tip = function (msg, vm) {\n    if (hasConsole && (!config.silent)) {\n      console.warn(\"[Vue tip]: \" + msg + (\n        vm ? generateComponentTrace(vm) : ''\n      ));\n    }\n  };\n\n  formatComponentName = function (vm, includeFile) {\n    if (vm.$root === vm) {\n      return '<Root>'\n    }\n    var name = typeof vm === 'string'\n      ? vm\n      : typeof vm === 'function' && vm.options\n        ? vm.options.name\n        : vm._isVue\n          ? vm.$options.name || vm.$options._componentTag\n          : vm.name;\n\n    var file = vm._isVue && vm.$options.__file;\n    if (!name && file) {\n      var match = file.match(/([^/\\\\]+)\\.vue$/);\n      name = match && match[1];\n    }\n\n    return (\n      (name ? (\"<\" + (classify(name)) + \">\") : \"<Anonymous>\") +\n      (file && includeFile !== false ? (\" at \" + file) : '')\n    )\n  };\n\n  var repeat = function (str, n) {\n    var res = '';\n    while (n) {\n      if (n % 2 === 1) { res += str; }\n      if (n > 1) { str += str; }\n      n >>= 1;\n    }\n    return res\n  };\n\n  var generateComponentTrace = function (vm) {\n    if (vm._isVue && vm.$parent) {\n      var tree = [];\n      var currentRecursiveSequence = 0;\n      while (vm) {\n        if (tree.length > 0) {\n          var last = tree[tree.length - 1];\n          if (last.constructor === vm.constructor) {\n            currentRecursiveSequence++;\n            vm = vm.$parent;\n            continue\n          } else if (currentRecursiveSequence > 0) {\n            tree[tree.length - 1] = [last, currentRecursiveSequence];\n            currentRecursiveSequence = 0;\n          }\n        }\n        tree.push(vm);\n        vm = vm.$parent;\n      }\n      return '\\n\\nfound in\\n\\n' + tree\n        .map(function (vm, i) { return (\"\" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm)\n            ? ((formatComponentName(vm[0])) + \"... (\" + (vm[1]) + \" recursive calls)\")\n            : formatComponentName(vm))); })\n        .join('\\n')\n    } else {\n      return (\"\\n\\n(found in \" + (formatComponentName(vm)) + \")\")\n    }\n  };\n}\n\nfunction handleError (err, vm, info) {\n  if (config.errorHandler) {\n    config.errorHandler.call(null, err, vm, info);\n  } else {\n    {\n      warn((\"Error in \" + info + \": \\\"\" + (err.toString()) + \"\\\"\"), vm);\n    }\n    /* istanbul ignore else */\n    if (inBrowser && typeof console !== 'undefined') {\n      console.error(err);\n    } else {\n      throw err\n    }\n  }\n}\n\n/*  */\n/* globals MutationObserver */\n\n// can we use __proto__?\nvar hasProto = '__proto__' in {};\n\n// Browser environment sniffing\nvar inBrowser = typeof window !== 'undefined';\nvar UA = inBrowser && window.navigator.userAgent.toLowerCase();\nvar isIE = UA && /msie|trident/.test(UA);\nvar isIE9 = UA && UA.indexOf('msie 9.0') > 0;\nvar isEdge = UA && UA.indexOf('edge/') > 0;\nvar isAndroid = UA && UA.indexOf('android') > 0;\nvar isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);\nvar isChrome = UA && /chrome\\/\\d+/.test(UA) && !isEdge;\n\nvar supportsPassive = false;\nif (inBrowser) {\n  try {\n    var opts = {};\n    Object.defineProperty(opts, 'passive', ({\n      get: function get () {\n        /* istanbul ignore next */\n        supportsPassive = true;\n      }\n    } )); // https://github.com/facebook/flow/issues/285\n    window.addEventListener('test-passive', null, opts);\n  } catch (e) {}\n}\n\n// this needs to be lazy-evaled because vue may be required before\n// vue-server-renderer can set VUE_ENV\nvar _isServer;\nvar isServerRendering = function () {\n  if (_isServer === undefined) {\n    /* istanbul ignore if */\n    if (!inBrowser && typeof global !== 'undefined') {\n      // detect presence of vue-server-renderer and avoid\n      // Webpack shimming the process\n      _isServer = global['process'].env.VUE_ENV === 'server';\n    } else {\n      _isServer = false;\n    }\n  }\n  return _isServer\n};\n\n// detect devtools\nvar devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;\n\n/* istanbul ignore next */\nfunction isNative (Ctor) {\n  return typeof Ctor === 'function' && /native code/.test(Ctor.toString())\n}\n\nvar hasSymbol =\n  typeof Symbol !== 'undefined' && isNative(Symbol) &&\n  typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);\n\n/**\n * Defer a task to execute it asynchronously.\n */\nvar nextTick = (function () {\n  var callbacks = [];\n  var pending = false;\n  var timerFunc;\n\n  function nextTickHandler () {\n    pending = false;\n    var copies = callbacks.slice(0);\n    callbacks.length = 0;\n    for (var i = 0; i < copies.length; i++) {\n      copies[i]();\n    }\n  }\n\n  // the nextTick behavior leverages the microtask queue, which can be accessed\n  // via either native Promise.then or MutationObserver.\n  // MutationObserver has wider support, however it is seriously bugged in\n  // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It\n  // completely stops working after triggering a few times... so, if native\n  // Promise is available, we will use it:\n  /* istanbul ignore if */\n  if (typeof Promise !== 'undefined' && isNative(Promise)) {\n    var p = Promise.resolve();\n    var logError = function (err) { console.error(err); };\n    timerFunc = function () {\n      p.then(nextTickHandler).catch(logError);\n      // in problematic UIWebViews, Promise.then doesn't completely break, but\n      // it can get stuck in a weird state where callbacks are pushed into the\n      // microtask queue but the queue isn't being flushed, until the browser\n      // needs to do some other work, e.g. handle a timer. Therefore we can\n      // \"force\" the microtask queue to be flushed by adding an empty timer.\n      if (isIOS) { setTimeout(noop); }\n    };\n  } else if (typeof MutationObserver !== 'undefined' && (\n    isNative(MutationObserver) ||\n    // PhantomJS and iOS 7.x\n    MutationObserver.toString() === '[object MutationObserverConstructor]'\n  )) {\n    // use MutationObserver where native Promise is not available,\n    // e.g. PhantomJS IE11, iOS7, Android 4.4\n    var counter = 1;\n    var observer = new MutationObserver(nextTickHandler);\n    var textNode = document.createTextNode(String(counter));\n    observer.observe(textNode, {\n      characterData: true\n    });\n    timerFunc = function () {\n      counter = (counter + 1) % 2;\n      textNode.data = String(counter);\n    };\n  } else {\n    // fallback to setTimeout\n    /* istanbul ignore next */\n    timerFunc = function () {\n      setTimeout(nextTickHandler, 0);\n    };\n  }\n\n  return function queueNextTick (cb, ctx) {\n    var _resolve;\n    callbacks.push(function () {\n      if (cb) {\n        try {\n          cb.call(ctx);\n        } catch (e) {\n          handleError(e, ctx, 'nextTick');\n        }\n      } else if (_resolve) {\n        _resolve(ctx);\n      }\n    });\n    if (!pending) {\n      pending = true;\n      timerFunc();\n    }\n    if (!cb && typeof Promise !== 'undefined') {\n      return new Promise(function (resolve, reject) {\n        _resolve = resolve;\n      })\n    }\n  }\n})();\n\nvar _Set;\n/* istanbul ignore if */\nif (typeof Set !== 'undefined' && isNative(Set)) {\n  // use native Set when available.\n  _Set = Set;\n} else {\n  // a non-standard Set polyfill that only works with primitive keys.\n  _Set = (function () {\n    function Set () {\n      this.set = Object.create(null);\n    }\n    Set.prototype.has = function has (key) {\n      return this.set[key] === true\n    };\n    Set.prototype.add = function add (key) {\n      this.set[key] = true;\n    };\n    Set.prototype.clear = function clear () {\n      this.set = Object.create(null);\n    };\n\n    return Set;\n  }());\n}\n\n/*  */\n\n\nvar uid = 0;\n\n/**\n * A dep is an observable that can have multiple\n * directives subscribing to it.\n */\nvar Dep = function Dep () {\n  this.id = uid++;\n  this.subs = [];\n};\n\nDep.prototype.addSub = function addSub (sub) {\n  this.subs.push(sub);\n};\n\nDep.prototype.removeSub = function removeSub (sub) {\n  remove(this.subs, sub);\n};\n\nDep.prototype.depend = function depend () {\n  if (Dep.target) {\n    Dep.target.addDep(this);\n  }\n};\n\nDep.prototype.notify = function notify () {\n  // stabilize the subscriber list first\n  var subs = this.subs.slice();\n  for (var i = 0, l = subs.length; i < l; i++) {\n    subs[i].update();\n  }\n};\n\n// the current target watcher being evaluated.\n// this is globally unique because there could be only one\n// watcher being evaluated at any time.\nDep.target = null;\nvar targetStack = [];\n\nfunction pushTarget (_target) {\n  if (Dep.target) { targetStack.push(Dep.target); }\n  Dep.target = _target;\n}\n\nfunction popTarget () {\n  Dep.target = targetStack.pop();\n}\n\n/*\n * not type checking this file because flow doesn't play well with\n * dynamically accessing methods on Array prototype\n */\n\nvar arrayProto = Array.prototype;\nvar arrayMethods = Object.create(arrayProto);[\n  'push',\n  'pop',\n  'shift',\n  'unshift',\n  'splice',\n  'sort',\n  'reverse'\n]\n.forEach(function (method) {\n  // cache original method\n  var original = arrayProto[method];\n  def(arrayMethods, method, function mutator () {\n    var arguments$1 = arguments;\n\n    // avoid leaking arguments:\n    // http://jsperf.com/closure-with-arguments\n    var i = arguments.length;\n    var args = new Array(i);\n    while (i--) {\n      args[i] = arguments$1[i];\n    }\n    var result = original.apply(this, args);\n    var ob = this.__ob__;\n    var inserted;\n    switch (method) {\n      case 'push':\n        inserted = args;\n        break\n      case 'unshift':\n        inserted = args;\n        break\n      case 'splice':\n        inserted = args.slice(2);\n        break\n    }\n    if (inserted) { ob.observeArray(inserted); }\n    // notify change\n    ob.dep.notify();\n    return result\n  });\n});\n\n/*  */\n\nvar arrayKeys = Object.getOwnPropertyNames(arrayMethods);\n\n/**\n * By default, when a reactive property is set, the new value is\n * also converted to become reactive. However when passing down props,\n * we don't want to force conversion because the value may be a nested value\n * under a frozen data structure. Converting it would defeat the optimization.\n */\nvar observerState = {\n  shouldConvert: true,\n  isSettingProps: false\n};\n\n/**\n * Observer class that are attached to each observed\n * object. Once attached, the observer converts target\n * object's property keys into getter/setters that\n * collect dependencies and dispatches updates.\n */\nvar Observer = function Observer (value) {\n  this.value = value;\n  this.dep = new Dep();\n  this.vmCount = 0;\n  def(value, '__ob__', this);\n  if (Array.isArray(value)) {\n    var augment = hasProto\n      ? protoAugment\n      : copyAugment;\n    augment(value, arrayMethods, arrayKeys);\n    this.observeArray(value);\n  } else {\n    this.walk(value);\n  }\n};\n\n/**\n * Walk through each property and convert them into\n * getter/setters. This method should only be called when\n * value type is Object.\n */\nObserver.prototype.walk = function walk (obj) {\n  var keys = Object.keys(obj);\n  for (var i = 0; i < keys.length; i++) {\n    defineReactive$$1(obj, keys[i], obj[keys[i]]);\n  }\n};\n\n/**\n * Observe a list of Array items.\n */\nObserver.prototype.observeArray = function observeArray (items) {\n  for (var i = 0, l = items.length; i < l; i++) {\n    observe(items[i]);\n  }\n};\n\n// helpers\n\n/**\n * Augment an target Object or Array by intercepting\n * the prototype chain using __proto__\n */\nfunction protoAugment (target, src) {\n  /* eslint-disable no-proto */\n  target.__proto__ = src;\n  /* eslint-enable no-proto */\n}\n\n/**\n * Augment an target Object or Array by defining\n * hidden properties.\n */\n/* istanbul ignore next */\nfunction copyAugment (target, src, keys) {\n  for (var i = 0, l = keys.length; i < l; i++) {\n    var key = keys[i];\n    def(target, key, src[key]);\n  }\n}\n\n/**\n * Attempt to create an observer instance for a value,\n * returns the new observer if successfully observed,\n * or the existing observer if the value already has one.\n */\nfunction observe (value, asRootData) {\n  if (!isObject(value)) {\n    return\n  }\n  var ob;\n  if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {\n    ob = value.__ob__;\n  } else if (\n    observerState.shouldConvert &&\n    !isServerRendering() &&\n    (Array.isArray(value) || isPlainObject(value)) &&\n    Object.isExtensible(value) &&\n    !value._isVue\n  ) {\n    ob = new Observer(value);\n  }\n  if (asRootData && ob) {\n    ob.vmCount++;\n  }\n  return ob\n}\n\n/**\n * Define a reactive property on an Object.\n */\nfunction defineReactive$$1 (\n  obj,\n  key,\n  val,\n  customSetter\n) {\n  var dep = new Dep();\n\n  var property = Object.getOwnPropertyDescriptor(obj, key);\n  if (property && property.configurable === false) {\n    return\n  }\n\n  // cater for pre-defined getter/setters\n  var getter = property && property.get;\n  var setter = property && property.set;\n\n  var childOb = observe(val);\n  Object.defineProperty(obj, key, {\n    enumerable: true,\n    configurable: true,\n    get: function reactiveGetter () {\n      var value = getter ? getter.call(obj) : val;\n      if (Dep.target) {\n        dep.depend();\n        if (childOb) {\n          childOb.dep.depend();\n        }\n        if (Array.isArray(value)) {\n          dependArray(value);\n        }\n      }\n      return value\n    },\n    set: function reactiveSetter (newVal) {\n      var value = getter ? getter.call(obj) : val;\n      /* eslint-disable no-self-compare */\n      if (newVal === value || (newVal !== newVal && value !== value)) {\n        return\n      }\n      /* eslint-enable no-self-compare */\n      if (\"development\" !== 'production' && customSetter) {\n        customSetter();\n      }\n      if (setter) {\n        setter.call(obj, newVal);\n      } else {\n        val = newVal;\n      }\n      childOb = observe(newVal);\n      dep.notify();\n    }\n  });\n}\n\n/**\n * Set a property on an object. Adds the new property and\n * triggers change notification if the property doesn't\n * already exist.\n */\nfunction set (target, key, val) {\n  if (Array.isArray(target) && typeof key === 'number') {\n    target.length = Math.max(target.length, key);\n    target.splice(key, 1, val);\n    return val\n  }\n  if (hasOwn(target, key)) {\n    target[key] = val;\n    return val\n  }\n  var ob = (target ).__ob__;\n  if (target._isVue || (ob && ob.vmCount)) {\n    \"development\" !== 'production' && warn(\n      'Avoid adding reactive properties to a Vue instance or its root $data ' +\n      'at runtime - declare it upfront in the data option.'\n    );\n    return val\n  }\n  if (!ob) {\n    target[key] = val;\n    return val\n  }\n  defineReactive$$1(ob.value, key, val);\n  ob.dep.notify();\n  return val\n}\n\n/**\n * Delete a property and trigger change if necessary.\n */\nfunction del (target, key) {\n  if (Array.isArray(target) && typeof key === 'number') {\n    target.splice(key, 1);\n    return\n  }\n  var ob = (target ).__ob__;\n  if (target._isVue || (ob && ob.vmCount)) {\n    \"development\" !== 'production' && warn(\n      'Avoid deleting properties on a Vue instance or its root $data ' +\n      '- just set it to null.'\n    );\n    return\n  }\n  if (!hasOwn(target, key)) {\n    return\n  }\n  delete target[key];\n  if (!ob) {\n    return\n  }\n  ob.dep.notify();\n}\n\n/**\n * Collect dependencies on array elements when the array is touched, since\n * we cannot intercept array element access like property getters.\n */\nfunction dependArray (value) {\n  for (var e = (void 0), i = 0, l = value.length; i < l; i++) {\n    e = value[i];\n    e && e.__ob__ && e.__ob__.dep.depend();\n    if (Array.isArray(e)) {\n      dependArray(e);\n    }\n  }\n}\n\n/*  */\n\n/**\n * Option overwriting strategies are functions that handle\n * how to merge a parent option value and a child option\n * value into the final value.\n */\nvar strats = config.optionMergeStrategies;\n\n/**\n * Options with restrictions\n */\n{\n  strats.el = strats.propsData = function (parent, child, vm, key) {\n    if (!vm) {\n      warn(\n        \"option \\\"\" + key + \"\\\" can only be used during instance \" +\n        'creation with the `new` keyword.'\n      );\n    }\n    return defaultStrat(parent, child)\n  };\n}\n\n/**\n * Helper that recursively merges two data objects together.\n */\nfunction mergeData (to, from) {\n  if (!from) { return to }\n  var key, toVal, fromVal;\n  var keys = Object.keys(from);\n  for (var i = 0; i < keys.length; i++) {\n    key = keys[i];\n    toVal = to[key];\n    fromVal = from[key];\n    if (!hasOwn(to, key)) {\n      set(to, key, fromVal);\n    } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {\n      mergeData(toVal, fromVal);\n    }\n  }\n  return to\n}\n\n/**\n * Data\n */\nstrats.data = function (\n  parentVal,\n  childVal,\n  vm\n) {\n  if (!vm) {\n    // in a Vue.extend merge, both should be functions\n    if (!childVal) {\n      return parentVal\n    }\n    if (typeof childVal !== 'function') {\n      \"development\" !== 'production' && warn(\n        'The \"data\" option should be a function ' +\n        'that returns a per-instance value in component ' +\n        'definitions.',\n        vm\n      );\n      return parentVal\n    }\n    if (!parentVal) {\n      return childVal\n    }\n    // when parentVal & childVal are both present,\n    // we need to return a function that returns the\n    // merged result of both functions... no need to\n    // check if parentVal is a function here because\n    // it has to be a function to pass previous merges.\n    return function mergedDataFn () {\n      return mergeData(\n        childVal.call(this),\n        parentVal.call(this)\n      )\n    }\n  } else if (parentVal || childVal) {\n    return function mergedInstanceDataFn () {\n      // instance merge\n      var instanceData = typeof childVal === 'function'\n        ? childVal.call(vm)\n        : childVal;\n      var defaultData = typeof parentVal === 'function'\n        ? parentVal.call(vm)\n        : undefined;\n      if (instanceData) {\n        return mergeData(instanceData, defaultData)\n      } else {\n        return defaultData\n      }\n    }\n  }\n};\n\n/**\n * Hooks and props are merged as arrays.\n */\nfunction mergeHook (\n  parentVal,\n  childVal\n) {\n  return childVal\n    ? parentVal\n      ? parentVal.concat(childVal)\n      : Array.isArray(childVal)\n        ? childVal\n        : [childVal]\n    : parentVal\n}\n\nLIFECYCLE_HOOKS.forEach(function (hook) {\n  strats[hook] = mergeHook;\n});\n\n/**\n * Assets\n *\n * When a vm is present (instance creation), we need to do\n * a three-way merge between constructor options, instance\n * options and parent options.\n */\nfunction mergeAssets (parentVal, childVal) {\n  var res = Object.create(parentVal || null);\n  return childVal\n    ? extend(res, childVal)\n    : res\n}\n\nASSET_TYPES.forEach(function (type) {\n  strats[type + 's'] = mergeAssets;\n});\n\n/**\n * Watchers.\n *\n * Watchers hashes should not overwrite one\n * another, so we merge them as arrays.\n */\nstrats.watch = function (parentVal, childVal) {\n  /* istanbul ignore if */\n  if (!childVal) { return Object.create(parentVal || null) }\n  if (!parentVal) { return childVal }\n  var ret = {};\n  extend(ret, parentVal);\n  for (var key in childVal) {\n    var parent = ret[key];\n    var child = childVal[key];\n    if (parent && !Array.isArray(parent)) {\n      parent = [parent];\n    }\n    ret[key] = parent\n      ? parent.concat(child)\n      : [child];\n  }\n  return ret\n};\n\n/**\n * Other object hashes.\n */\nstrats.props =\nstrats.methods =\nstrats.computed = function (parentVal, childVal) {\n  if (!childVal) { return Object.create(parentVal || null) }\n  if (!parentVal) { return childVal }\n  var ret = Object.create(null);\n  extend(ret, parentVal);\n  extend(ret, childVal);\n  return ret\n};\n\n/**\n * Default strategy.\n */\nvar defaultStrat = function (parentVal, childVal) {\n  return childVal === undefined\n    ? parentVal\n    : childVal\n};\n\n/**\n * Validate component names\n */\nfunction checkComponents (options) {\n  for (var key in options.components) {\n    var lower = key.toLowerCase();\n    if (isBuiltInTag(lower) || config.isReservedTag(lower)) {\n      warn(\n        'Do not use built-in or reserved HTML elements as component ' +\n        'id: ' + key\n      );\n    }\n  }\n}\n\n/**\n * Ensure all props option syntax are normalized into the\n * Object-based format.\n */\nfunction normalizeProps (options) {\n  var props = options.props;\n  if (!props) { return }\n  var res = {};\n  var i, val, name;\n  if (Array.isArray(props)) {\n    i = props.length;\n    while (i--) {\n      val = props[i];\n      if (typeof val === 'string') {\n        name = camelize(val);\n        res[name] = { type: null };\n      } else {\n        warn('props must be strings when using array syntax.');\n      }\n    }\n  } else if (isPlainObject(props)) {\n    for (var key in props) {\n      val = props[key];\n      name = camelize(key);\n      res[name] = isPlainObject(val)\n        ? val\n        : { type: val };\n    }\n  }\n  options.props = res;\n}\n\n/**\n * Normalize raw function directives into object format.\n */\nfunction normalizeDirectives (options) {\n  var dirs = options.directives;\n  if (dirs) {\n    for (var key in dirs) {\n      var def = dirs[key];\n      if (typeof def === 'function') {\n        dirs[key] = { bind: def, update: def };\n      }\n    }\n  }\n}\n\n/**\n * Merge two option objects into a new one.\n * Core utility used in both instantiation and inheritance.\n */\nfunction mergeOptions (\n  parent,\n  child,\n  vm\n) {\n  {\n    checkComponents(child);\n  }\n\n  if (typeof child === 'function') {\n    child = child.options;\n  }\n\n  normalizeProps(child);\n  normalizeDirectives(child);\n  var extendsFrom = child.extends;\n  if (extendsFrom) {\n    parent = mergeOptions(parent, extendsFrom, vm);\n  }\n  if (child.mixins) {\n    for (var i = 0, l = child.mixins.length; i < l; i++) {\n      parent = mergeOptions(parent, child.mixins[i], vm);\n    }\n  }\n  var options = {};\n  var key;\n  for (key in parent) {\n    mergeField(key);\n  }\n  for (key in child) {\n    if (!hasOwn(parent, key)) {\n      mergeField(key);\n    }\n  }\n  function mergeField (key) {\n    var strat = strats[key] || defaultStrat;\n    options[key] = strat(parent[key], child[key], vm, key);\n  }\n  return options\n}\n\n/**\n * Resolve an asset.\n * This function is used because child instances need access\n * to assets defined in its ancestor chain.\n */\nfunction resolveAsset (\n  options,\n  type,\n  id,\n  warnMissing\n) {\n  /* istanbul ignore if */\n  if (typeof id !== 'string') {\n    return\n  }\n  var assets = options[type];\n  // check local registration variations first\n  if (hasOwn(assets, id)) { return assets[id] }\n  var camelizedId = camelize(id);\n  if (hasOwn(assets, camelizedId)) { return assets[camelizedId] }\n  var PascalCaseId = capitalize(camelizedId);\n  if (hasOwn(assets, PascalCaseId)) { return assets[PascalCaseId] }\n  // fallback to prototype chain\n  var res = assets[id] || assets[camelizedId] || assets[PascalCaseId];\n  if (\"development\" !== 'production' && warnMissing && !res) {\n    warn(\n      'Failed to resolve ' + type.slice(0, -1) + ': ' + id,\n      options\n    );\n  }\n  return res\n}\n\n/*  */\n\nfunction validateProp (\n  key,\n  propOptions,\n  propsData,\n  vm\n) {\n  var prop = propOptions[key];\n  var absent = !hasOwn(propsData, key);\n  var value = propsData[key];\n  // handle boolean props\n  if (isType(Boolean, prop.type)) {\n    if (absent && !hasOwn(prop, 'default')) {\n      value = false;\n    } else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) {\n      value = true;\n    }\n  }\n  // check default value\n  if (value === undefined) {\n    value = getPropDefaultValue(vm, prop, key);\n    // since the default value is a fresh copy,\n    // make sure to observe it.\n    var prevShouldConvert = observerState.shouldConvert;\n    observerState.shouldConvert = true;\n    observe(value);\n    observerState.shouldConvert = prevShouldConvert;\n  }\n  {\n    assertProp(prop, key, value, vm, absent);\n  }\n  return value\n}\n\n/**\n * Get the default value of a prop.\n */\nfunction getPropDefaultValue (vm, prop, key) {\n  // no default, return undefined\n  if (!hasOwn(prop, 'default')) {\n    return undefined\n  }\n  var def = prop.default;\n  // warn against non-factory defaults for Object & Array\n  if (\"development\" !== 'production' && isObject(def)) {\n    warn(\n      'Invalid default value for prop \"' + key + '\": ' +\n      'Props with type Object/Array must use a factory function ' +\n      'to return the default value.',\n      vm\n    );\n  }\n  // the raw prop value was also undefined from previous render,\n  // return previous default value to avoid unnecessary watcher trigger\n  if (vm && vm.$options.propsData &&\n    vm.$options.propsData[key] === undefined &&\n    vm._props[key] !== undefined) {\n    return vm._props[key]\n  }\n  // call factory function for non-Function types\n  // a value is Function if its prototype is function even across different execution context\n  return typeof def === 'function' && getType(prop.type) !== 'Function'\n    ? def.call(vm)\n    : def\n}\n\n/**\n * Assert whether a prop is valid.\n */\nfunction assertProp (\n  prop,\n  name,\n  value,\n  vm,\n  absent\n) {\n  if (prop.required && absent) {\n    warn(\n      'Missing required prop: \"' + name + '\"',\n      vm\n    );\n    return\n  }\n  if (value == null && !prop.required) {\n    return\n  }\n  var type = prop.type;\n  var valid = !type || type === true;\n  var expectedTypes = [];\n  if (type) {\n    if (!Array.isArray(type)) {\n      type = [type];\n    }\n    for (var i = 0; i < type.length && !valid; i++) {\n      var assertedType = assertType(value, type[i]);\n      expectedTypes.push(assertedType.expectedType || '');\n      valid = assertedType.valid;\n    }\n  }\n  if (!valid) {\n    warn(\n      'Invalid prop: type check failed for prop \"' + name + '\".' +\n      ' Expected ' + expectedTypes.map(capitalize).join(', ') +\n      ', got ' + Object.prototype.toString.call(value).slice(8, -1) + '.',\n      vm\n    );\n    return\n  }\n  var validator = prop.validator;\n  if (validator) {\n    if (!validator(value)) {\n      warn(\n        'Invalid prop: custom validator check failed for prop \"' + name + '\".',\n        vm\n      );\n    }\n  }\n}\n\nvar simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/;\n\nfunction assertType (value, type) {\n  var valid;\n  var expectedType = getType(type);\n  if (simpleCheckRE.test(expectedType)) {\n    valid = typeof value === expectedType.toLowerCase();\n  } else if (expectedType === 'Object') {\n    valid = isPlainObject(value);\n  } else if (expectedType === 'Array') {\n    valid = Array.isArray(value);\n  } else {\n    valid = value instanceof type;\n  }\n  return {\n    valid: valid,\n    expectedType: expectedType\n  }\n}\n\n/**\n * Use function string name to check built-in types,\n * because a simple equality check will fail when running\n * across different vms / iframes.\n */\nfunction getType (fn) {\n  var match = fn && fn.toString().match(/^\\s*function (\\w+)/);\n  return match ? match[1] : ''\n}\n\nfunction isType (type, fn) {\n  if (!Array.isArray(fn)) {\n    return getType(fn) === getType(type)\n  }\n  for (var i = 0, len = fn.length; i < len; i++) {\n    if (getType(fn[i]) === getType(type)) {\n      return true\n    }\n  }\n  /* istanbul ignore next */\n  return false\n}\n\nvar mark;\nvar measure;\n\n{\n  var perf = inBrowser && window.performance;\n  /* istanbul ignore if */\n  if (\n    perf &&\n    perf.mark &&\n    perf.measure &&\n    perf.clearMarks &&\n    perf.clearMeasures\n  ) {\n    mark = function (tag) { return perf.mark(tag); };\n    measure = function (name, startTag, endTag) {\n      perf.measure(name, startTag, endTag);\n      perf.clearMarks(startTag);\n      perf.clearMarks(endTag);\n      perf.clearMeasures(name);\n    };\n  }\n}\n\n/* not type checking this file because flow doesn't play well with Proxy */\n\nvar initProxy;\n\n{\n  var allowedGlobals = makeMap(\n    'Infinity,undefined,NaN,isFinite,isNaN,' +\n    'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +\n    'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +\n    'require' // for Webpack/Browserify\n  );\n\n  var warnNonPresent = function (target, key) {\n    warn(\n      \"Property or method \\\"\" + key + \"\\\" is not defined on the instance but \" +\n      \"referenced during render. Make sure to declare reactive data \" +\n      \"properties in the data option.\",\n      target\n    );\n  };\n\n  var hasProxy =\n    typeof Proxy !== 'undefined' &&\n    Proxy.toString().match(/native code/);\n\n  if (hasProxy) {\n    var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta');\n    config.keyCodes = new Proxy(config.keyCodes, {\n      set: function set (target, key, value) {\n        if (isBuiltInModifier(key)) {\n          warn((\"Avoid overwriting built-in modifier in config.keyCodes: .\" + key));\n          return false\n        } else {\n          target[key] = value;\n          return true\n        }\n      }\n    });\n  }\n\n  var hasHandler = {\n    has: function has (target, key) {\n      var has = key in target;\n      var isAllowed = allowedGlobals(key) || key.charAt(0) === '_';\n      if (!has && !isAllowed) {\n        warnNonPresent(target, key);\n      }\n      return has || !isAllowed\n    }\n  };\n\n  var getHandler = {\n    get: function get (target, key) {\n      if (typeof key === 'string' && !(key in target)) {\n        warnNonPresent(target, key);\n      }\n      return target[key]\n    }\n  };\n\n  initProxy = function initProxy (vm) {\n    if (hasProxy) {\n      // determine which proxy handler to use\n      var options = vm.$options;\n      var handlers = options.render && options.render._withStripped\n        ? getHandler\n        : hasHandler;\n      vm._renderProxy = new Proxy(vm, handlers);\n    } else {\n      vm._renderProxy = vm;\n    }\n  };\n}\n\n/*  */\n\nvar VNode = function VNode (\n  tag,\n  data,\n  children,\n  text,\n  elm,\n  context,\n  componentOptions\n) {\n  this.tag = tag;\n  this.data = data;\n  this.children = children;\n  this.text = text;\n  this.elm = elm;\n  this.ns = undefined;\n  this.context = context;\n  this.functionalContext = undefined;\n  this.key = data && data.key;\n  this.componentOptions = componentOptions;\n  this.componentInstance = undefined;\n  this.parent = undefined;\n  this.raw = false;\n  this.isStatic = false;\n  this.isRootInsert = true;\n  this.isComment = false;\n  this.isCloned = false;\n  this.isOnce = false;\n};\n\nvar prototypeAccessors = { child: {} };\n\n// DEPRECATED: alias for componentInstance for backwards compat.\n/* istanbul ignore next */\nprototypeAccessors.child.get = function () {\n  return this.componentInstance\n};\n\nObject.defineProperties( VNode.prototype, prototypeAccessors );\n\nvar createEmptyVNode = function () {\n  var node = new VNode();\n  node.text = '';\n  node.isComment = true;\n  return node\n};\n\nfunction createTextVNode (val) {\n  return new VNode(undefined, undefined, undefined, String(val))\n}\n\n// optimized shallow clone\n// used for static nodes and slot nodes because they may be reused across\n// multiple renders, cloning them avoids errors when DOM manipulations rely\n// on their elm reference.\nfunction cloneVNode (vnode) {\n  var cloned = new VNode(\n    vnode.tag,\n    vnode.data,\n    vnode.children,\n    vnode.text,\n    vnode.elm,\n    vnode.context,\n    vnode.componentOptions\n  );\n  cloned.ns = vnode.ns;\n  cloned.isStatic = vnode.isStatic;\n  cloned.key = vnode.key;\n  cloned.isCloned = true;\n  return cloned\n}\n\nfunction cloneVNodes (vnodes) {\n  var len = vnodes.length;\n  var res = new Array(len);\n  for (var i = 0; i < len; i++) {\n    res[i] = cloneVNode(vnodes[i]);\n  }\n  return res\n}\n\n/*  */\n\nvar normalizeEvent = cached(function (name) {\n  var passive = name.charAt(0) === '&';\n  name = passive ? name.slice(1) : name;\n  var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first\n  name = once$$1 ? name.slice(1) : name;\n  var capture = name.charAt(0) === '!';\n  name = capture ? name.slice(1) : name;\n  return {\n    name: name,\n    once: once$$1,\n    capture: capture,\n    passive: passive\n  }\n});\n\nfunction createFnInvoker (fns) {\n  function invoker () {\n    var arguments$1 = arguments;\n\n    var fns = invoker.fns;\n    if (Array.isArray(fns)) {\n      for (var i = 0; i < fns.length; i++) {\n        fns[i].apply(null, arguments$1);\n      }\n    } else {\n      // return handler return value for single handlers\n      return fns.apply(null, arguments)\n    }\n  }\n  invoker.fns = fns;\n  return invoker\n}\n\nfunction updateListeners (\n  on,\n  oldOn,\n  add,\n  remove$$1,\n  vm\n) {\n  var name, cur, old, event;\n  for (name in on) {\n    cur = on[name];\n    old = oldOn[name];\n    event = normalizeEvent(name);\n    if (isUndef(cur)) {\n      \"development\" !== 'production' && warn(\n        \"Invalid handler for event \\\"\" + (event.name) + \"\\\": got \" + String(cur),\n        vm\n      );\n    } else if (isUndef(old)) {\n      if (isUndef(cur.fns)) {\n        cur = on[name] = createFnInvoker(cur);\n      }\n      add(event.name, cur, event.once, event.capture, event.passive);\n    } else if (cur !== old) {\n      old.fns = cur;\n      on[name] = old;\n    }\n  }\n  for (name in oldOn) {\n    if (isUndef(on[name])) {\n      event = normalizeEvent(name);\n      remove$$1(event.name, oldOn[name], event.capture);\n    }\n  }\n}\n\n/*  */\n\nfunction mergeVNodeHook (def, hookKey, hook) {\n  var invoker;\n  var oldHook = def[hookKey];\n\n  function wrappedHook () {\n    hook.apply(this, arguments);\n    // important: remove merged hook to ensure it's called only once\n    // and prevent memory leak\n    remove(invoker.fns, wrappedHook);\n  }\n\n  if (isUndef(oldHook)) {\n    // no existing hook\n    invoker = createFnInvoker([wrappedHook]);\n  } else {\n    /* istanbul ignore if */\n    if (isDef(oldHook.fns) && isTrue(oldHook.merged)) {\n      // already a merged invoker\n      invoker = oldHook;\n      invoker.fns.push(wrappedHook);\n    } else {\n      // existing plain hook\n      invoker = createFnInvoker([oldHook, wrappedHook]);\n    }\n  }\n\n  invoker.merged = true;\n  def[hookKey] = invoker;\n}\n\n/*  */\n\nfunction extractPropsFromVNodeData (\n  data,\n  Ctor,\n  tag\n) {\n  // we are only extracting raw values here.\n  // validation and default values are handled in the child\n  // component itself.\n  var propOptions = Ctor.options.props;\n  if (isUndef(propOptions)) {\n    return\n  }\n  var res = {};\n  var attrs = data.attrs;\n  var props = data.props;\n  if (isDef(attrs) || isDef(props)) {\n    for (var key in propOptions) {\n      var altKey = hyphenate(key);\n      {\n        var keyInLowerCase = key.toLowerCase();\n        if (\n          key !== keyInLowerCase &&\n          attrs && hasOwn(attrs, keyInLowerCase)\n        ) {\n          tip(\n            \"Prop \\\"\" + keyInLowerCase + \"\\\" is passed to component \" +\n            (formatComponentName(tag || Ctor)) + \", but the declared prop name is\" +\n            \" \\\"\" + key + \"\\\". \" +\n            \"Note that HTML attributes are case-insensitive and camelCased \" +\n            \"props need to use their kebab-case equivalents when using in-DOM \" +\n            \"templates. You should probably use \\\"\" + altKey + \"\\\" instead of \\\"\" + key + \"\\\".\"\n          );\n        }\n      }\n      checkProp(res, props, key, altKey, true) ||\n      checkProp(res, attrs, key, altKey, false);\n    }\n  }\n  return res\n}\n\nfunction checkProp (\n  res,\n  hash,\n  key,\n  altKey,\n  preserve\n) {\n  if (isDef(hash)) {\n    if (hasOwn(hash, key)) {\n      res[key] = hash[key];\n      if (!preserve) {\n        delete hash[key];\n      }\n      return true\n    } else if (hasOwn(hash, altKey)) {\n      res[key] = hash[altKey];\n      if (!preserve) {\n        delete hash[altKey];\n      }\n      return true\n    }\n  }\n  return false\n}\n\n/*  */\n\n// The template compiler attempts to minimize the need for normalization by\n// statically analyzing the template at compile time.\n//\n// For plain HTML markup, normalization can be completely skipped because the\n// generated render function is guaranteed to return Array<VNode>. There are\n// two cases where extra normalization is needed:\n\n// 1. When the children contains components - because a functional component\n// may return an Array instead of a single root. In this case, just a simple\n// normalization is needed - if any child is an Array, we flatten the whole\n// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep\n// because functional components already normalize their own children.\nfunction simpleNormalizeChildren (children) {\n  for (var i = 0; i < children.length; i++) {\n    if (Array.isArray(children[i])) {\n      return Array.prototype.concat.apply([], children)\n    }\n  }\n  return children\n}\n\n// 2. When the children contains constructs that always generated nested Arrays,\n// e.g. <template>, <slot>, v-for, or when the children is provided by user\n// with hand-written render functions / JSX. In such cases a full normalization\n// is needed to cater to all possible types of children values.\nfunction normalizeChildren (children) {\n  return isPrimitive(children)\n    ? [createTextVNode(children)]\n    : Array.isArray(children)\n      ? normalizeArrayChildren(children)\n      : undefined\n}\n\nfunction normalizeArrayChildren (children, nestedIndex) {\n  var res = [];\n  var i, c, last;\n  for (i = 0; i < children.length; i++) {\n    c = children[i];\n    if (isUndef(c) || typeof c === 'boolean') { continue }\n    last = res[res.length - 1];\n    //  nested\n    if (Array.isArray(c)) {\n      res.push.apply(res, normalizeArrayChildren(c, ((nestedIndex || '') + \"_\" + i)));\n    } else if (isPrimitive(c)) {\n      if (isDef(last) && isDef(last.text)) {\n        (last).text += String(c);\n      } else if (c !== '') {\n        // convert primitive to vnode\n        res.push(createTextVNode(c));\n      }\n    } else {\n      if (isDef(c.text) && isDef(last) && isDef(last.text)) {\n        res[res.length - 1] = createTextVNode(last.text + c.text);\n      } else {\n        // default key for nested array children (likely generated by v-for)\n        if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {\n          c.key = \"__vlist\" + ((nestedIndex)) + \"_\" + i + \"__\";\n        }\n        res.push(c);\n      }\n    }\n  }\n  return res\n}\n\n/*  */\n\nfunction ensureCtor (comp, base) {\n  return isObject(comp)\n    ? base.extend(comp)\n    : comp\n}\n\nfunction resolveAsyncComponent (\n  factory,\n  baseCtor,\n  context\n) {\n  if (isTrue(factory.error) && isDef(factory.errorComp)) {\n    return factory.errorComp\n  }\n\n  if (isDef(factory.resolved)) {\n    return factory.resolved\n  }\n\n  if (isTrue(factory.loading) && isDef(factory.loadingComp)) {\n    return factory.loadingComp\n  }\n\n  if (isDef(factory.contexts)) {\n    // already pending\n    factory.contexts.push(context);\n  } else {\n    var contexts = factory.contexts = [context];\n    var sync = true;\n\n    var forceRender = function () {\n      for (var i = 0, l = contexts.length; i < l; i++) {\n        contexts[i].$forceUpdate();\n      }\n    };\n\n    var resolve = once(function (res) {\n      // cache resolved\n      factory.resolved = ensureCtor(res, baseCtor);\n      // invoke callbacks only if this is not a synchronous resolve\n      // (async resolves are shimmed as synchronous during SSR)\n      if (!sync) {\n        forceRender();\n      }\n    });\n\n    var reject = once(function (reason) {\n      \"development\" !== 'production' && warn(\n        \"Failed to resolve async component: \" + (String(factory)) +\n        (reason ? (\"\\nReason: \" + reason) : '')\n      );\n      if (isDef(factory.errorComp)) {\n        factory.error = true;\n        forceRender();\n      }\n    });\n\n    var res = factory(resolve, reject);\n\n    if (isObject(res)) {\n      if (typeof res.then === 'function') {\n        // () => Promise\n        if (isUndef(factory.resolved)) {\n          res.then(resolve, reject);\n        }\n      } else if (isDef(res.component) && typeof res.component.then === 'function') {\n        res.component.then(resolve, reject);\n\n        if (isDef(res.error)) {\n          factory.errorComp = ensureCtor(res.error, baseCtor);\n        }\n\n        if (isDef(res.loading)) {\n          factory.loadingComp = ensureCtor(res.loading, baseCtor);\n          if (res.delay === 0) {\n            factory.loading = true;\n          } else {\n            setTimeout(function () {\n              if (isUndef(factory.resolved) && isUndef(factory.error)) {\n                factory.loading = true;\n                forceRender();\n              }\n            }, res.delay || 200);\n          }\n        }\n\n        if (isDef(res.timeout)) {\n          setTimeout(function () {\n            reject(\n              \"timeout (\" + (res.timeout) + \"ms)\"\n            );\n          }, res.timeout);\n        }\n      }\n    }\n\n    sync = false;\n    // return in case resolved synchronously\n    return factory.loading\n      ? factory.loadingComp\n      : factory.resolved\n  }\n}\n\n/*  */\n\nfunction getFirstComponentChild (children) {\n  if (Array.isArray(children)) {\n    for (var i = 0; i < children.length; i++) {\n      var c = children[i];\n      if (isDef(c) && isDef(c.componentOptions)) {\n        return c\n      }\n    }\n  }\n}\n\n/*  */\n\n/*  */\n\nfunction initEvents (vm) {\n  vm._events = Object.create(null);\n  vm._hasHookEvent = false;\n  // init parent attached events\n  var listeners = vm.$options._parentListeners;\n  if (listeners) {\n    updateComponentListeners(vm, listeners);\n  }\n}\n\nvar target;\n\nfunction add (event, fn, once$$1) {\n  if (once$$1) {\n    target.$once(event, fn);\n  } else {\n    target.$on(event, fn);\n  }\n}\n\nfunction remove$1 (event, fn) {\n  target.$off(event, fn);\n}\n\nfunction updateComponentListeners (\n  vm,\n  listeners,\n  oldListeners\n) {\n  target = vm;\n  updateListeners(listeners, oldListeners || {}, add, remove$1, vm);\n}\n\nfunction eventsMixin (Vue) {\n  var hookRE = /^hook:/;\n  Vue.prototype.$on = function (event, fn) {\n    var this$1 = this;\n\n    var vm = this;\n    if (Array.isArray(event)) {\n      for (var i = 0, l = event.length; i < l; i++) {\n        this$1.$on(event[i], fn);\n      }\n    } else {\n      (vm._events[event] || (vm._events[event] = [])).push(fn);\n      // optimize hook:event cost by using a boolean flag marked at registration\n      // instead of a hash lookup\n      if (hookRE.test(event)) {\n        vm._hasHookEvent = true;\n      }\n    }\n    return vm\n  };\n\n  Vue.prototype.$once = function (event, fn) {\n    var vm = this;\n    function on () {\n      vm.$off(event, on);\n      fn.apply(vm, arguments);\n    }\n    on.fn = fn;\n    vm.$on(event, on);\n    return vm\n  };\n\n  Vue.prototype.$off = function (event, fn) {\n    var this$1 = this;\n\n    var vm = this;\n    // all\n    if (!arguments.length) {\n      vm._events = Object.create(null);\n      return vm\n    }\n    // array of events\n    if (Array.isArray(event)) {\n      for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {\n        this$1.$off(event[i$1], fn);\n      }\n      return vm\n    }\n    // specific event\n    var cbs = vm._events[event];\n    if (!cbs) {\n      return vm\n    }\n    if (arguments.length === 1) {\n      vm._events[event] = null;\n      return vm\n    }\n    // specific handler\n    var cb;\n    var i = cbs.length;\n    while (i--) {\n      cb = cbs[i];\n      if (cb === fn || cb.fn === fn) {\n        cbs.splice(i, 1);\n        break\n      }\n    }\n    return vm\n  };\n\n  Vue.prototype.$emit = function (event) {\n    var vm = this;\n    {\n      var lowerCaseEvent = event.toLowerCase();\n      if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {\n        tip(\n          \"Event \\\"\" + lowerCaseEvent + \"\\\" is emitted in component \" +\n          (formatComponentName(vm)) + \" but the handler is registered for \\\"\" + event + \"\\\". \" +\n          \"Note that HTML attributes are case-insensitive and you cannot use \" +\n          \"v-on to listen to camelCase events when using in-DOM templates. \" +\n          \"You should probably use \\\"\" + (hyphenate(event)) + \"\\\" instead of \\\"\" + event + \"\\\".\"\n        );\n      }\n    }\n    var cbs = vm._events[event];\n    if (cbs) {\n      cbs = cbs.length > 1 ? toArray(cbs) : cbs;\n      var args = toArray(arguments, 1);\n      for (var i = 0, l = cbs.length; i < l; i++) {\n        cbs[i].apply(vm, args);\n      }\n    }\n    return vm\n  };\n}\n\n/*  */\n\n/**\n * Runtime helper for resolving raw children VNodes into a slot object.\n */\nfunction resolveSlots (\n  children,\n  context\n) {\n  var slots = {};\n  if (!children) {\n    return slots\n  }\n  var defaultSlot = [];\n  for (var i = 0, l = children.length; i < l; i++) {\n    var child = children[i];\n    // named slots should only be respected if the vnode was rendered in the\n    // same context.\n    if ((child.context === context || child.functionalContext === context) &&\n        child.data && child.data.slot != null) {\n      var name = child.data.slot;\n      var slot = (slots[name] || (slots[name] = []));\n      if (child.tag === 'template') {\n        slot.push.apply(slot, child.children);\n      } else {\n        slot.push(child);\n      }\n    } else {\n      defaultSlot.push(child);\n    }\n  }\n  // ignore whitespace\n  if (!defaultSlot.every(isWhitespace)) {\n    slots.default = defaultSlot;\n  }\n  return slots\n}\n\nfunction isWhitespace (node) {\n  return node.isComment || node.text === ' '\n}\n\nfunction resolveScopedSlots (\n  fns\n) {\n  var res = {};\n  for (var i = 0; i < fns.length; i++) {\n    res[fns[i][0]] = fns[i][1];\n  }\n  return res\n}\n\n/*  */\n\nvar activeInstance = null;\n\nfunction initLifecycle (vm) {\n  var options = vm.$options;\n\n  // locate first non-abstract parent\n  var parent = options.parent;\n  if (parent && !options.abstract) {\n    while (parent.$options.abstract && parent.$parent) {\n      parent = parent.$parent;\n    }\n    parent.$children.push(vm);\n  }\n\n  vm.$parent = parent;\n  vm.$root = parent ? parent.$root : vm;\n\n  vm.$children = [];\n  vm.$refs = {};\n\n  vm._watcher = null;\n  vm._inactive = null;\n  vm._directInactive = false;\n  vm._isMounted = false;\n  vm._isDestroyed = false;\n  vm._isBeingDestroyed = false;\n}\n\nfunction lifecycleMixin (Vue) {\n  Vue.prototype._update = function (vnode, hydrating) {\n    var vm = this;\n    if (vm._isMounted) {\n      callHook(vm, 'beforeUpdate');\n    }\n    var prevEl = vm.$el;\n    var prevVnode = vm._vnode;\n    var prevActiveInstance = activeInstance;\n    activeInstance = vm;\n    vm._vnode = vnode;\n    // Vue.prototype.__patch__ is injected in entry points\n    // based on the rendering backend used.\n    if (!prevVnode) {\n      // initial render\n      vm.$el = vm.__patch__(\n        vm.$el, vnode, hydrating, false /* removeOnly */,\n        vm.$options._parentElm,\n        vm.$options._refElm\n      );\n    } else {\n      // updates\n      vm.$el = vm.__patch__(prevVnode, vnode);\n    }\n    activeInstance = prevActiveInstance;\n    // update __vue__ reference\n    if (prevEl) {\n      prevEl.__vue__ = null;\n    }\n    if (vm.$el) {\n      vm.$el.__vue__ = vm;\n    }\n    // if parent is an HOC, update its $el as well\n    if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {\n      vm.$parent.$el = vm.$el;\n    }\n    // updated hook is called by the scheduler to ensure that children are\n    // updated in a parent's updated hook.\n  };\n\n  Vue.prototype.$forceUpdate = function () {\n    var vm = this;\n    if (vm._watcher) {\n      vm._watcher.update();\n    }\n  };\n\n  Vue.prototype.$destroy = function () {\n    var vm = this;\n    if (vm._isBeingDestroyed) {\n      return\n    }\n    callHook(vm, 'beforeDestroy');\n    vm._isBeingDestroyed = true;\n    // remove self from parent\n    var parent = vm.$parent;\n    if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {\n      remove(parent.$children, vm);\n    }\n    // teardown watchers\n    if (vm._watcher) {\n      vm._watcher.teardown();\n    }\n    var i = vm._watchers.length;\n    while (i--) {\n      vm._watchers[i].teardown();\n    }\n    // remove reference from data ob\n    // frozen object may not have observer.\n    if (vm._data.__ob__) {\n      vm._data.__ob__.vmCount--;\n    }\n    // call the last hook...\n    vm._isDestroyed = true;\n    // invoke destroy hooks on current rendered tree\n    vm.__patch__(vm._vnode, null);\n    // fire destroyed hook\n    callHook(vm, 'destroyed');\n    // turn off all instance listeners.\n    vm.$off();\n    // remove __vue__ reference\n    if (vm.$el) {\n      vm.$el.__vue__ = null;\n    }\n    // remove reference to DOM nodes (prevents leak)\n    vm.$options._parentElm = vm.$options._refElm = null;\n  };\n}\n\nfunction mountComponent (\n  vm,\n  el,\n  hydrating\n) {\n  vm.$el = el;\n  if (!vm.$options.render) {\n    vm.$options.render = createEmptyVNode;\n    {\n      /* istanbul ignore if */\n      if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') ||\n        vm.$options.el || el) {\n        warn(\n          'You are using the runtime-only build of Vue where the template ' +\n          'compiler is not available. Either pre-compile the templates into ' +\n          'render functions, or use the compiler-included build.',\n          vm\n        );\n      } else {\n        warn(\n          'Failed to mount component: template or render function not defined.',\n          vm\n        );\n      }\n    }\n  }\n  callHook(vm, 'beforeMount');\n\n  var updateComponent;\n  /* istanbul ignore if */\n  if (\"development\" !== 'production' && config.performance && mark) {\n    updateComponent = function () {\n      var name = vm._name;\n      var id = vm._uid;\n      var startTag = \"vue-perf-start:\" + id;\n      var endTag = \"vue-perf-end:\" + id;\n\n      mark(startTag);\n      var vnode = vm._render();\n      mark(endTag);\n      measure((name + \" render\"), startTag, endTag);\n\n      mark(startTag);\n      vm._update(vnode, hydrating);\n      mark(endTag);\n      measure((name + \" patch\"), startTag, endTag);\n    };\n  } else {\n    updateComponent = function () {\n      vm._update(vm._render(), hydrating);\n    };\n  }\n\n  vm._watcher = new Watcher(vm, updateComponent, noop);\n  hydrating = false;\n\n  // manually mounted instance, call mounted on self\n  // mounted is called for render-created child components in its inserted hook\n  if (vm.$vnode == null) {\n    vm._isMounted = true;\n    callHook(vm, 'mounted');\n  }\n  return vm\n}\n\nfunction updateChildComponent (\n  vm,\n  propsData,\n  listeners,\n  parentVnode,\n  renderChildren\n) {\n  // determine whether component has slot children\n  // we need to do this before overwriting $options._renderChildren\n  var hasChildren = !!(\n    renderChildren ||               // has new static slots\n    vm.$options._renderChildren ||  // has old static slots\n    parentVnode.data.scopedSlots || // has new scoped slots\n    vm.$scopedSlots !== emptyObject // has old scoped slots\n  );\n\n  vm.$options._parentVnode = parentVnode;\n  vm.$vnode = parentVnode; // update vm's placeholder node without re-render\n  if (vm._vnode) { // update child tree's parent\n    vm._vnode.parent = parentVnode;\n  }\n  vm.$options._renderChildren = renderChildren;\n\n  // update props\n  if (propsData && vm.$options.props) {\n    observerState.shouldConvert = false;\n    {\n      observerState.isSettingProps = true;\n    }\n    var props = vm._props;\n    var propKeys = vm.$options._propKeys || [];\n    for (var i = 0; i < propKeys.length; i++) {\n      var key = propKeys[i];\n      props[key] = validateProp(key, vm.$options.props, propsData, vm);\n    }\n    observerState.shouldConvert = true;\n    {\n      observerState.isSettingProps = false;\n    }\n    // keep a copy of raw propsData\n    vm.$options.propsData = propsData;\n  }\n  // update listeners\n  if (listeners) {\n    var oldListeners = vm.$options._parentListeners;\n    vm.$options._parentListeners = listeners;\n    updateComponentListeners(vm, listeners, oldListeners);\n  }\n  // resolve slots + force update if has children\n  if (hasChildren) {\n    vm.$slots = resolveSlots(renderChildren, parentVnode.context);\n    vm.$forceUpdate();\n  }\n}\n\nfunction isInInactiveTree (vm) {\n  while (vm && (vm = vm.$parent)) {\n    if (vm._inactive) { return true }\n  }\n  return false\n}\n\nfunction activateChildComponent (vm, direct) {\n  if (direct) {\n    vm._directInactive = false;\n    if (isInInactiveTree(vm)) {\n      return\n    }\n  } else if (vm._directInactive) {\n    return\n  }\n  if (vm._inactive || vm._inactive === null) {\n    vm._inactive = false;\n    for (var i = 0; i < vm.$children.length; i++) {\n      activateChildComponent(vm.$children[i]);\n    }\n    callHook(vm, 'activated');\n  }\n}\n\nfunction deactivateChildComponent (vm, direct) {\n  if (direct) {\n    vm._directInactive = true;\n    if (isInInactiveTree(vm)) {\n      return\n    }\n  }\n  if (!vm._inactive) {\n    vm._inactive = true;\n    for (var i = 0; i < vm.$children.length; i++) {\n      deactivateChildComponent(vm.$children[i]);\n    }\n    callHook(vm, 'deactivated');\n  }\n}\n\nfunction callHook (vm, hook) {\n  var handlers = vm.$options[hook];\n  if (handlers) {\n    for (var i = 0, j = handlers.length; i < j; i++) {\n      try {\n        handlers[i].call(vm);\n      } catch (e) {\n        handleError(e, vm, (hook + \" hook\"));\n      }\n    }\n  }\n  if (vm._hasHookEvent) {\n    vm.$emit('hook:' + hook);\n  }\n}\n\n/*  */\n\n\nvar MAX_UPDATE_COUNT = 100;\n\nvar queue = [];\nvar activatedChildren = [];\nvar has = {};\nvar circular = {};\nvar waiting = false;\nvar flushing = false;\nvar index = 0;\n\n/**\n * Reset the scheduler's state.\n */\nfunction resetSchedulerState () {\n  queue.length = activatedChildren.length = 0;\n  has = {};\n  {\n    circular = {};\n  }\n  waiting = flushing = false;\n}\n\n/**\n * Flush both queues and run the watchers.\n */\nfunction flushSchedulerQueue () {\n  flushing = true;\n  var watcher, id;\n\n  // Sort queue before flush.\n  // This ensures that:\n  // 1. Components are updated from parent to child. (because parent is always\n  //    created before the child)\n  // 2. A component's user watchers are run before its render watcher (because\n  //    user watchers are created before the render watcher)\n  // 3. If a component is destroyed during a parent component's watcher run,\n  //    its watchers can be skipped.\n  queue.sort(function (a, b) { return a.id - b.id; });\n\n  // do not cache length because more watchers might be pushed\n  // as we run existing watchers\n  for (index = 0; index < queue.length; index++) {\n    watcher = queue[index];\n    id = watcher.id;\n    has[id] = null;\n    watcher.run();\n    // in dev build, check and stop circular updates.\n    if (\"development\" !== 'production' && has[id] != null) {\n      circular[id] = (circular[id] || 0) + 1;\n      if (circular[id] > MAX_UPDATE_COUNT) {\n        warn(\n          'You may have an infinite update loop ' + (\n            watcher.user\n              ? (\"in watcher with expression \\\"\" + (watcher.expression) + \"\\\"\")\n              : \"in a component render function.\"\n          ),\n          watcher.vm\n        );\n        break\n      }\n    }\n  }\n\n  // keep copies of post queues before resetting state\n  var activatedQueue = activatedChildren.slice();\n  var updatedQueue = queue.slice();\n\n  resetSchedulerState();\n\n  // call component updated and activated hooks\n  callActivatedHooks(activatedQueue);\n  callUpdateHooks(updatedQueue);\n\n  // devtool hook\n  /* istanbul ignore if */\n  if (devtools && config.devtools) {\n    devtools.emit('flush');\n  }\n}\n\nfunction callUpdateHooks (queue) {\n  var i = queue.length;\n  while (i--) {\n    var watcher = queue[i];\n    var vm = watcher.vm;\n    if (vm._watcher === watcher && vm._isMounted) {\n      callHook(vm, 'updated');\n    }\n  }\n}\n\n/**\n * Queue a kept-alive component that was activated during patch.\n * The queue will be processed after the entire tree has been patched.\n */\nfunction queueActivatedComponent (vm) {\n  // setting _inactive to false here so that a render function can\n  // rely on checking whether it's in an inactive tree (e.g. router-view)\n  vm._inactive = false;\n  activatedChildren.push(vm);\n}\n\nfunction callActivatedHooks (queue) {\n  for (var i = 0; i < queue.length; i++) {\n    queue[i]._inactive = true;\n    activateChildComponent(queue[i], true /* true */);\n  }\n}\n\n/**\n * Push a watcher into the watcher queue.\n * Jobs with duplicate IDs will be skipped unless it's\n * pushed when the queue is being flushed.\n */\nfunction queueWatcher (watcher) {\n  var id = watcher.id;\n  if (has[id] == null) {\n    has[id] = true;\n    if (!flushing) {\n      queue.push(watcher);\n    } else {\n      // if already flushing, splice the watcher based on its id\n      // if already past its id, it will be run next immediately.\n      var i = queue.length - 1;\n      while (i >= 0 && queue[i].id > watcher.id) {\n        i--;\n      }\n      queue.splice(Math.max(i, index) + 1, 0, watcher);\n    }\n    // queue the flush\n    if (!waiting) {\n      waiting = true;\n      nextTick(flushSchedulerQueue);\n    }\n  }\n}\n\n/*  */\n\nvar uid$2 = 0;\n\n/**\n * A watcher parses an expression, collects dependencies,\n * and fires callback when the expression value changes.\n * This is used for both the $watch() api and directives.\n */\nvar Watcher = function Watcher (\n  vm,\n  expOrFn,\n  cb,\n  options\n) {\n  this.vm = vm;\n  vm._watchers.push(this);\n  // options\n  if (options) {\n    this.deep = !!options.deep;\n    this.user = !!options.user;\n    this.lazy = !!options.lazy;\n    this.sync = !!options.sync;\n  } else {\n    this.deep = this.user = this.lazy = this.sync = false;\n  }\n  this.cb = cb;\n  this.id = ++uid$2; // uid for batching\n  this.active = true;\n  this.dirty = this.lazy; // for lazy watchers\n  this.deps = [];\n  this.newDeps = [];\n  this.depIds = new _Set();\n  this.newDepIds = new _Set();\n  this.expression = expOrFn.toString();\n  // parse expression for getter\n  if (typeof expOrFn === 'function') {\n    this.getter = expOrFn;\n  } else {\n    this.getter = parsePath(expOrFn);\n    if (!this.getter) {\n      this.getter = function () {};\n      \"development\" !== 'production' && warn(\n        \"Failed watching path: \\\"\" + expOrFn + \"\\\" \" +\n        'Watcher only accepts simple dot-delimited paths. ' +\n        'For full control, use a function instead.',\n        vm\n      );\n    }\n  }\n  this.value = this.lazy\n    ? undefined\n    : this.get();\n};\n\n/**\n * Evaluate the getter, and re-collect dependencies.\n */\nWatcher.prototype.get = function get () {\n  pushTarget(this);\n  var value;\n  var vm = this.vm;\n  if (this.user) {\n    try {\n      value = this.getter.call(vm, vm);\n    } catch (e) {\n      handleError(e, vm, (\"getter for watcher \\\"\" + (this.expression) + \"\\\"\"));\n    }\n  } else {\n    value = this.getter.call(vm, vm);\n  }\n  // \"touch\" every property so they are all tracked as\n  // dependencies for deep watching\n  if (this.deep) {\n    traverse(value);\n  }\n  popTarget();\n  this.cleanupDeps();\n  return value\n};\n\n/**\n * Add a dependency to this directive.\n */\nWatcher.prototype.addDep = function addDep (dep) {\n  var id = dep.id;\n  if (!this.newDepIds.has(id)) {\n    this.newDepIds.add(id);\n    this.newDeps.push(dep);\n    if (!this.depIds.has(id)) {\n      dep.addSub(this);\n    }\n  }\n};\n\n/**\n * Clean up for dependency collection.\n */\nWatcher.prototype.cleanupDeps = function cleanupDeps () {\n    var this$1 = this;\n\n  var i = this.deps.length;\n  while (i--) {\n    var dep = this$1.deps[i];\n    if (!this$1.newDepIds.has(dep.id)) {\n      dep.removeSub(this$1);\n    }\n  }\n  var tmp = this.depIds;\n  this.depIds = this.newDepIds;\n  this.newDepIds = tmp;\n  this.newDepIds.clear();\n  tmp = this.deps;\n  this.deps = this.newDeps;\n  this.newDeps = tmp;\n  this.newDeps.length = 0;\n};\n\n/**\n * Subscriber interface.\n * Will be called when a dependency changes.\n */\nWatcher.prototype.update = function update () {\n  /* istanbul ignore else */\n  if (this.lazy) {\n    this.dirty = true;\n  } else if (this.sync) {\n    this.run();\n  } else {\n    queueWatcher(this);\n  }\n};\n\n/**\n * Scheduler job interface.\n * Will be called by the scheduler.\n */\nWatcher.prototype.run = function run () {\n  if (this.active) {\n    var value = this.get();\n    if (\n      value !== this.value ||\n      // Deep watchers and watchers on Object/Arrays should fire even\n      // when the value is the same, because the value may\n      // have mutated.\n      isObject(value) ||\n      this.deep\n    ) {\n      // set new value\n      var oldValue = this.value;\n      this.value = value;\n      if (this.user) {\n        try {\n          this.cb.call(this.vm, value, oldValue);\n        } catch (e) {\n          handleError(e, this.vm, (\"callback for watcher \\\"\" + (this.expression) + \"\\\"\"));\n        }\n      } else {\n        this.cb.call(this.vm, value, oldValue);\n      }\n    }\n  }\n};\n\n/**\n * Evaluate the value of the watcher.\n * This only gets called for lazy watchers.\n */\nWatcher.prototype.evaluate = function evaluate () {\n  this.value = this.get();\n  this.dirty = false;\n};\n\n/**\n * Depend on all deps collected by this watcher.\n */\nWatcher.prototype.depend = function depend () {\n    var this$1 = this;\n\n  var i = this.deps.length;\n  while (i--) {\n    this$1.deps[i].depend();\n  }\n};\n\n/**\n * Remove self from all dependencies' subscriber list.\n */\nWatcher.prototype.teardown = function teardown () {\n    var this$1 = this;\n\n  if (this.active) {\n    // remove self from vm's watcher list\n    // this is a somewhat expensive operation so we skip it\n    // if the vm is being destroyed.\n    if (!this.vm._isBeingDestroyed) {\n      remove(this.vm._watchers, this);\n    }\n    var i = this.deps.length;\n    while (i--) {\n      this$1.deps[i].removeSub(this$1);\n    }\n    this.active = false;\n  }\n};\n\n/**\n * Recursively traverse an object to evoke all converted\n * getters, so that every nested property inside the object\n * is collected as a \"deep\" dependency.\n */\nvar seenObjects = new _Set();\nfunction traverse (val) {\n  seenObjects.clear();\n  _traverse(val, seenObjects);\n}\n\nfunction _traverse (val, seen) {\n  var i, keys;\n  var isA = Array.isArray(val);\n  if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {\n    return\n  }\n  if (val.__ob__) {\n    var depId = val.__ob__.dep.id;\n    if (seen.has(depId)) {\n      return\n    }\n    seen.add(depId);\n  }\n  if (isA) {\n    i = val.length;\n    while (i--) { _traverse(val[i], seen); }\n  } else {\n    keys = Object.keys(val);\n    i = keys.length;\n    while (i--) { _traverse(val[keys[i]], seen); }\n  }\n}\n\n/*  */\n\nvar sharedPropertyDefinition = {\n  enumerable: true,\n  configurable: true,\n  get: noop,\n  set: noop\n};\n\nfunction proxy (target, sourceKey, key) {\n  sharedPropertyDefinition.get = function proxyGetter () {\n    return this[sourceKey][key]\n  };\n  sharedPropertyDefinition.set = function proxySetter (val) {\n    this[sourceKey][key] = val;\n  };\n  Object.defineProperty(target, key, sharedPropertyDefinition);\n}\n\nfunction initState (vm) {\n  vm._watchers = [];\n  var opts = vm.$options;\n  if (opts.props) { initProps(vm, opts.props); }\n  if (opts.methods) { initMethods(vm, opts.methods); }\n  if (opts.data) {\n    initData(vm);\n  } else {\n    observe(vm._data = {}, true /* asRootData */);\n  }\n  if (opts.computed) { initComputed(vm, opts.computed); }\n  if (opts.watch) { initWatch(vm, opts.watch); }\n}\n\nvar isReservedProp = {\n  key: 1,\n  ref: 1,\n  slot: 1\n};\n\nfunction initProps (vm, propsOptions) {\n  var propsData = vm.$options.propsData || {};\n  var props = vm._props = {};\n  // cache prop keys so that future props updates can iterate using Array\n  // instead of dynamic object key enumeration.\n  var keys = vm.$options._propKeys = [];\n  var isRoot = !vm.$parent;\n  // root instance props should be converted\n  observerState.shouldConvert = isRoot;\n  var loop = function ( key ) {\n    keys.push(key);\n    var value = validateProp(key, propsOptions, propsData, vm);\n    /* istanbul ignore else */\n    {\n      if (isReservedProp[key] || config.isReservedAttr(key)) {\n        warn(\n          (\"\\\"\" + key + \"\\\" is a reserved attribute and cannot be used as component prop.\"),\n          vm\n        );\n      }\n      defineReactive$$1(props, key, value, function () {\n        if (vm.$parent && !observerState.isSettingProps) {\n          warn(\n            \"Avoid mutating a prop directly since the value will be \" +\n            \"overwritten whenever the parent component re-renders. \" +\n            \"Instead, use a data or computed property based on the prop's \" +\n            \"value. Prop being mutated: \\\"\" + key + \"\\\"\",\n            vm\n          );\n        }\n      });\n    }\n    // static props are already proxied on the component's prototype\n    // during Vue.extend(). We only need to proxy props defined at\n    // instantiation here.\n    if (!(key in vm)) {\n      proxy(vm, \"_props\", key);\n    }\n  };\n\n  for (var key in propsOptions) loop( key );\n  observerState.shouldConvert = true;\n}\n\nfunction initData (vm) {\n  var data = vm.$options.data;\n  data = vm._data = typeof data === 'function'\n    ? getData(data, vm)\n    : data || {};\n  if (!isPlainObject(data)) {\n    data = {};\n    \"development\" !== 'production' && warn(\n      'data functions should return an object:\\n' +\n      'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',\n      vm\n    );\n  }\n  // proxy data on instance\n  var keys = Object.keys(data);\n  var props = vm.$options.props;\n  var i = keys.length;\n  while (i--) {\n    if (props && hasOwn(props, keys[i])) {\n      \"development\" !== 'production' && warn(\n        \"The data property \\\"\" + (keys[i]) + \"\\\" is already declared as a prop. \" +\n        \"Use prop default value instead.\",\n        vm\n      );\n    } else if (!isReserved(keys[i])) {\n      proxy(vm, \"_data\", keys[i]);\n    }\n  }\n  // observe data\n  observe(data, true /* asRootData */);\n}\n\nfunction getData (data, vm) {\n  try {\n    return data.call(vm)\n  } catch (e) {\n    handleError(e, vm, \"data()\");\n    return {}\n  }\n}\n\nvar computedWatcherOptions = { lazy: true };\n\nfunction initComputed (vm, computed) {\n  var watchers = vm._computedWatchers = Object.create(null);\n\n  for (var key in computed) {\n    var userDef = computed[key];\n    var getter = typeof userDef === 'function' ? userDef : userDef.get;\n    {\n      if (getter === undefined) {\n        warn(\n          (\"No getter function has been defined for computed property \\\"\" + key + \"\\\".\"),\n          vm\n        );\n        getter = noop;\n      }\n    }\n    // create internal watcher for the computed property.\n    watchers[key] = new Watcher(vm, getter, noop, computedWatcherOptions);\n\n    // component-defined computed properties are already defined on the\n    // component prototype. We only need to define computed properties defined\n    // at instantiation here.\n    if (!(key in vm)) {\n      defineComputed(vm, key, userDef);\n    } else {\n      if (key in vm.$data) {\n        warn((\"The computed property \\\"\" + key + \"\\\" is already defined in data.\"), vm);\n      } else if (vm.$options.props && key in vm.$options.props) {\n        warn((\"The computed property \\\"\" + key + \"\\\" is already defined as a prop.\"), vm);\n      }\n    }\n  }\n}\n\nfunction defineComputed (target, key, userDef) {\n  if (typeof userDef === 'function') {\n    sharedPropertyDefinition.get = createComputedGetter(key);\n    sharedPropertyDefinition.set = noop;\n  } else {\n    sharedPropertyDefinition.get = userDef.get\n      ? userDef.cache !== false\n        ? createComputedGetter(key)\n        : userDef.get\n      : noop;\n    sharedPropertyDefinition.set = userDef.set\n      ? userDef.set\n      : noop;\n  }\n  Object.defineProperty(target, key, sharedPropertyDefinition);\n}\n\nfunction createComputedGetter (key) {\n  return function computedGetter () {\n    var watcher = this._computedWatchers && this._computedWatchers[key];\n    if (watcher) {\n      if (watcher.dirty) {\n        watcher.evaluate();\n      }\n      if (Dep.target) {\n        watcher.depend();\n      }\n      return watcher.value\n    }\n  }\n}\n\nfunction initMethods (vm, methods) {\n  var props = vm.$options.props;\n  for (var key in methods) {\n    vm[key] = methods[key] == null ? noop : bind(methods[key], vm);\n    {\n      if (methods[key] == null) {\n        warn(\n          \"method \\\"\" + key + \"\\\" has an undefined value in the component definition. \" +\n          \"Did you reference the function correctly?\",\n          vm\n        );\n      }\n      if (props && hasOwn(props, key)) {\n        warn(\n          (\"method \\\"\" + key + \"\\\" has already been defined as a prop.\"),\n          vm\n        );\n      }\n    }\n  }\n}\n\nfunction initWatch (vm, watch) {\n  for (var key in watch) {\n    var handler = watch[key];\n    if (Array.isArray(handler)) {\n      for (var i = 0; i < handler.length; i++) {\n        createWatcher(vm, key, handler[i]);\n      }\n    } else {\n      createWatcher(vm, key, handler);\n    }\n  }\n}\n\nfunction createWatcher (vm, key, handler) {\n  var options;\n  if (isPlainObject(handler)) {\n    options = handler;\n    handler = handler.handler;\n  }\n  if (typeof handler === 'string') {\n    handler = vm[handler];\n  }\n  vm.$watch(key, handler, options);\n}\n\nfunction stateMixin (Vue) {\n  // flow somehow has problems with directly declared definition object\n  // when using Object.defineProperty, so we have to procedurally build up\n  // the object here.\n  var dataDef = {};\n  dataDef.get = function () { return this._data };\n  var propsDef = {};\n  propsDef.get = function () { return this._props };\n  {\n    dataDef.set = function (newData) {\n      warn(\n        'Avoid replacing instance root $data. ' +\n        'Use nested data properties instead.',\n        this\n      );\n    };\n    propsDef.set = function () {\n      warn(\"$props is readonly.\", this);\n    };\n  }\n  Object.defineProperty(Vue.prototype, '$data', dataDef);\n  Object.defineProperty(Vue.prototype, '$props', propsDef);\n\n  Vue.prototype.$set = set;\n  Vue.prototype.$delete = del;\n\n  Vue.prototype.$watch = function (\n    expOrFn,\n    cb,\n    options\n  ) {\n    var vm = this;\n    options = options || {};\n    options.user = true;\n    var watcher = new Watcher(vm, expOrFn, cb, options);\n    if (options.immediate) {\n      cb.call(vm, watcher.value);\n    }\n    return function unwatchFn () {\n      watcher.teardown();\n    }\n  };\n}\n\n/*  */\n\nfunction initProvide (vm) {\n  var provide = vm.$options.provide;\n  if (provide) {\n    vm._provided = typeof provide === 'function'\n      ? provide.call(vm)\n      : provide;\n  }\n}\n\nfunction initInjections (vm) {\n  var result = resolveInject(vm.$options.inject, vm);\n  if (result) {\n    Object.keys(result).forEach(function (key) {\n      /* istanbul ignore else */\n      {\n        defineReactive$$1(vm, key, result[key], function () {\n          warn(\n            \"Avoid mutating an injected value directly since the changes will be \" +\n            \"overwritten whenever the provided component re-renders. \" +\n            \"injection being mutated: \\\"\" + key + \"\\\"\",\n            vm\n          );\n        });\n      }\n    });\n  }\n}\n\nfunction resolveInject (inject, vm) {\n  if (inject) {\n    // inject is :any because flow is not smart enough to figure out cached\n    // isArray here\n    var isArray = Array.isArray(inject);\n    var result = Object.create(null);\n    var keys = isArray\n      ? inject\n      : hasSymbol\n        ? Reflect.ownKeys(inject)\n        : Object.keys(inject);\n\n    for (var i = 0; i < keys.length; i++) {\n      var key = keys[i];\n      var provideKey = isArray ? key : inject[key];\n      var source = vm;\n      while (source) {\n        if (source._provided && provideKey in source._provided) {\n          result[key] = source._provided[provideKey];\n          break\n        }\n        source = source.$parent;\n      }\n    }\n    return result\n  }\n}\n\n/*  */\n\nfunction createFunctionalComponent (\n  Ctor,\n  propsData,\n  data,\n  context,\n  children\n) {\n  var props = {};\n  var propOptions = Ctor.options.props;\n  if (isDef(propOptions)) {\n    for (var key in propOptions) {\n      props[key] = validateProp(key, propOptions, propsData);\n    }\n  } else {\n    if (isDef(data.attrs)) { mergeProps(props, data.attrs); }\n    if (isDef(data.props)) { mergeProps(props, data.props); }\n  }\n  // ensure the createElement function in functional components\n  // gets a unique context - this is necessary for correct named slot check\n  var _context = Object.create(context);\n  var h = function (a, b, c, d) { return createElement(_context, a, b, c, d, true); };\n  var vnode = Ctor.options.render.call(null, h, {\n    data: data,\n    props: props,\n    children: children,\n    parent: context,\n    listeners: data.on || {},\n    injections: resolveInject(Ctor.options.inject, context),\n    slots: function () { return resolveSlots(children, context); }\n  });\n  if (vnode instanceof VNode) {\n    vnode.functionalContext = context;\n    if (data.slot) {\n      (vnode.data || (vnode.data = {})).slot = data.slot;\n    }\n  }\n  return vnode\n}\n\nfunction mergeProps (to, from) {\n  for (var key in from) {\n    to[camelize(key)] = from[key];\n  }\n}\n\n/*  */\n\n// hooks to be invoked on component VNodes during patch\nvar componentVNodeHooks = {\n  init: function init (\n    vnode,\n    hydrating,\n    parentElm,\n    refElm\n  ) {\n    if (!vnode.componentInstance || vnode.componentInstance._isDestroyed) {\n      var child = vnode.componentInstance = createComponentInstanceForVnode(\n        vnode,\n        activeInstance,\n        parentElm,\n        refElm\n      );\n      child.$mount(hydrating ? vnode.elm : undefined, hydrating);\n    } else if (vnode.data.keepAlive) {\n      // kept-alive components, treat as a patch\n      var mountedNode = vnode; // work around flow\n      componentVNodeHooks.prepatch(mountedNode, mountedNode);\n    }\n  },\n\n  prepatch: function prepatch (oldVnode, vnode) {\n    var options = vnode.componentOptions;\n    var child = vnode.componentInstance = oldVnode.componentInstance;\n    updateChildComponent(\n      child,\n      options.propsData, // updated props\n      options.listeners, // updated listeners\n      vnode, // new parent vnode\n      options.children // new children\n    );\n  },\n\n  insert: function insert (vnode) {\n    var context = vnode.context;\n    var componentInstance = vnode.componentInstance;\n    if (!componentInstance._isMounted) {\n      componentInstance._isMounted = true;\n      callHook(componentInstance, 'mounted');\n    }\n    if (vnode.data.keepAlive) {\n      if (context._isMounted) {\n        // vue-router#1212\n        // During updates, a kept-alive component's child components may\n        // change, so directly walking the tree here may call activated hooks\n        // on incorrect children. Instead we push them into a queue which will\n        // be processed after the whole patch process ended.\n        queueActivatedComponent(componentInstance);\n      } else {\n        activateChildComponent(componentInstance, true /* direct */);\n      }\n    }\n  },\n\n  destroy: function destroy (vnode) {\n    var componentInstance = vnode.componentInstance;\n    if (!componentInstance._isDestroyed) {\n      if (!vnode.data.keepAlive) {\n        componentInstance.$destroy();\n      } else {\n        deactivateChildComponent(componentInstance, true /* direct */);\n      }\n    }\n  }\n};\n\nvar hooksToMerge = Object.keys(componentVNodeHooks);\n\nfunction createComponent (\n  Ctor,\n  data,\n  context,\n  children,\n  tag\n) {\n  if (isUndef(Ctor)) {\n    return\n  }\n\n  var baseCtor = context.$options._base;\n\n  // plain options object: turn it into a constructor\n  if (isObject(Ctor)) {\n    Ctor = baseCtor.extend(Ctor);\n  }\n\n  // if at this stage it's not a constructor or an async component factory,\n  // reject.\n  if (typeof Ctor !== 'function') {\n    {\n      warn((\"Invalid Component definition: \" + (String(Ctor))), context);\n    }\n    return\n  }\n\n  // async component\n  if (isUndef(Ctor.cid)) {\n    Ctor = resolveAsyncComponent(Ctor, baseCtor, context);\n    if (Ctor === undefined) {\n      // return nothing if this is indeed an async component\n      // wait for the callback to trigger parent update.\n      return\n    }\n  }\n\n  // resolve constructor options in case global mixins are applied after\n  // component constructor creation\n  resolveConstructorOptions(Ctor);\n\n  data = data || {};\n\n  // transform component v-model data into props & events\n  if (isDef(data.model)) {\n    transformModel(Ctor.options, data);\n  }\n\n  // extract props\n  var propsData = extractPropsFromVNodeData(data, Ctor, tag);\n\n  // functional component\n  if (isTrue(Ctor.options.functional)) {\n    return createFunctionalComponent(Ctor, propsData, data, context, children)\n  }\n\n  // extract listeners, since these needs to be treated as\n  // child component listeners instead of DOM listeners\n  var listeners = data.on;\n  // replace with listeners with .native modifier\n  data.on = data.nativeOn;\n\n  if (isTrue(Ctor.options.abstract)) {\n    // abstract components do not keep anything\n    // other than props & listeners\n    data = {};\n  }\n\n  // merge component management hooks onto the placeholder node\n  mergeHooks(data);\n\n  // return a placeholder vnode\n  var name = Ctor.options.name || tag;\n  var vnode = new VNode(\n    (\"vue-component-\" + (Ctor.cid) + (name ? (\"-\" + name) : '')),\n    data, undefined, undefined, undefined, context,\n    { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children }\n  );\n  return vnode\n}\n\nfunction createComponentInstanceForVnode (\n  vnode, // we know it's MountedComponentVNode but flow doesn't\n  parent, // activeInstance in lifecycle state\n  parentElm,\n  refElm\n) {\n  var vnodeComponentOptions = vnode.componentOptions;\n  var options = {\n    _isComponent: true,\n    parent: parent,\n    propsData: vnodeComponentOptions.propsData,\n    _componentTag: vnodeComponentOptions.tag,\n    _parentVnode: vnode,\n    _parentListeners: vnodeComponentOptions.listeners,\n    _renderChildren: vnodeComponentOptions.children,\n    _parentElm: parentElm || null,\n    _refElm: refElm || null\n  };\n  // check inline-template render functions\n  var inlineTemplate = vnode.data.inlineTemplate;\n  if (isDef(inlineTemplate)) {\n    options.render = inlineTemplate.render;\n    options.staticRenderFns = inlineTemplate.staticRenderFns;\n  }\n  return new vnodeComponentOptions.Ctor(options)\n}\n\nfunction mergeHooks (data) {\n  if (!data.hook) {\n    data.hook = {};\n  }\n  for (var i = 0; i < hooksToMerge.length; i++) {\n    var key = hooksToMerge[i];\n    var fromParent = data.hook[key];\n    var ours = componentVNodeHooks[key];\n    data.hook[key] = fromParent ? mergeHook$1(ours, fromParent) : ours;\n  }\n}\n\nfunction mergeHook$1 (one, two) {\n  return function (a, b, c, d) {\n    one(a, b, c, d);\n    two(a, b, c, d);\n  }\n}\n\n// transform component v-model info (value and callback) into\n// prop and event handler respectively.\nfunction transformModel (options, data) {\n  var prop = (options.model && options.model.prop) || 'value';\n  var event = (options.model && options.model.event) || 'input';(data.props || (data.props = {}))[prop] = data.model.value;\n  var on = data.on || (data.on = {});\n  if (isDef(on[event])) {\n    on[event] = [data.model.callback].concat(on[event]);\n  } else {\n    on[event] = data.model.callback;\n  }\n}\n\n/*  */\n\nvar SIMPLE_NORMALIZE = 1;\nvar ALWAYS_NORMALIZE = 2;\n\n// wrapper function for providing a more flexible interface\n// without getting yelled at by flow\nfunction createElement (\n  context,\n  tag,\n  data,\n  children,\n  normalizationType,\n  alwaysNormalize\n) {\n  if (Array.isArray(data) || isPrimitive(data)) {\n    normalizationType = children;\n    children = data;\n    data = undefined;\n  }\n  if (isTrue(alwaysNormalize)) {\n    normalizationType = ALWAYS_NORMALIZE;\n  }\n  return _createElement(context, tag, data, children, normalizationType)\n}\n\nfunction _createElement (\n  context,\n  tag,\n  data,\n  children,\n  normalizationType\n) {\n  if (isDef(data) && isDef((data).__ob__)) {\n    \"development\" !== 'production' && warn(\n      \"Avoid using observed data object as vnode data: \" + (JSON.stringify(data)) + \"\\n\" +\n      'Always create fresh vnode data objects in each render!',\n      context\n    );\n    return createEmptyVNode()\n  }\n  if (!tag) {\n    // in case of component :is set to falsy value\n    return createEmptyVNode()\n  }\n  // support single function children as default scoped slot\n  if (Array.isArray(children) &&\n      typeof children[0] === 'function') {\n    data = data || {};\n    data.scopedSlots = { default: children[0] };\n    children.length = 0;\n  }\n  if (normalizationType === ALWAYS_NORMALIZE) {\n    children = normalizeChildren(children);\n  } else if (normalizationType === SIMPLE_NORMALIZE) {\n    children = simpleNormalizeChildren(children);\n  }\n  var vnode, ns;\n  if (typeof tag === 'string') {\n    var Ctor;\n    ns = config.getTagNamespace(tag);\n    if (config.isReservedTag(tag)) {\n      // platform built-in elements\n      vnode = new VNode(\n        config.parsePlatformTagName(tag), data, children,\n        undefined, undefined, context\n      );\n    } else if (isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {\n      // component\n      vnode = createComponent(Ctor, data, context, children, tag);\n    } else {\n      // unknown or unlisted namespaced elements\n      // check at runtime because it may get assigned a namespace when its\n      // parent normalizes children\n      vnode = new VNode(\n        tag, data, children,\n        undefined, undefined, context\n      );\n    }\n  } else {\n    // direct component options / constructor\n    vnode = createComponent(tag, data, context, children);\n  }\n  if (vnode !== undefined) {\n    if (ns) { applyNS(vnode, ns); }\n    return vnode\n  } else {\n    return createEmptyVNode()\n  }\n}\n\nfunction applyNS (vnode, ns) {\n  vnode.ns = ns;\n  if (vnode.tag === 'foreignObject') {\n    // use default namespace inside foreignObject\n    return\n  }\n  if (Array.isArray(vnode.children)) {\n    for (var i = 0, l = vnode.children.length; i < l; i++) {\n      var child = vnode.children[i];\n      if (isDef(child.tag) && isUndef(child.ns)) {\n        applyNS(child, ns);\n      }\n    }\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering v-for lists.\n */\nfunction renderList (\n  val,\n  render\n) {\n  var ret, i, l, keys, key;\n  if (Array.isArray(val) || typeof val === 'string') {\n    ret = new Array(val.length);\n    for (i = 0, l = val.length; i < l; i++) {\n      ret[i] = render(val[i], i);\n    }\n  } else if (typeof val === 'number') {\n    ret = new Array(val);\n    for (i = 0; i < val; i++) {\n      ret[i] = render(i + 1, i);\n    }\n  } else if (isObject(val)) {\n    keys = Object.keys(val);\n    ret = new Array(keys.length);\n    for (i = 0, l = keys.length; i < l; i++) {\n      key = keys[i];\n      ret[i] = render(val[key], key, i);\n    }\n  }\n  return ret\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering <slot>\n */\nfunction renderSlot (\n  name,\n  fallback,\n  props,\n  bindObject\n) {\n  var scopedSlotFn = this.$scopedSlots[name];\n  if (scopedSlotFn) { // scoped slot\n    props = props || {};\n    if (bindObject) {\n      extend(props, bindObject);\n    }\n    return scopedSlotFn(props) || fallback\n  } else {\n    var slotNodes = this.$slots[name];\n    // warn duplicate slot usage\n    if (slotNodes && \"development\" !== 'production') {\n      slotNodes._rendered && warn(\n        \"Duplicate presence of slot \\\"\" + name + \"\\\" found in the same render tree \" +\n        \"- this will likely cause render errors.\",\n        this\n      );\n      slotNodes._rendered = true;\n    }\n    return slotNodes || fallback\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for resolving filters\n */\nfunction resolveFilter (id) {\n  return resolveAsset(this.$options, 'filters', id, true) || identity\n}\n\n/*  */\n\n/**\n * Runtime helper for checking keyCodes from config.\n */\nfunction checkKeyCodes (\n  eventKeyCode,\n  key,\n  builtInAlias\n) {\n  var keyCodes = config.keyCodes[key] || builtInAlias;\n  if (Array.isArray(keyCodes)) {\n    return keyCodes.indexOf(eventKeyCode) === -1\n  } else {\n    return keyCodes !== eventKeyCode\n  }\n}\n\n/*  */\n\n/**\n * Runtime helper for merging v-bind=\"object\" into a VNode's data.\n */\nfunction bindObjectProps (\n  data,\n  tag,\n  value,\n  asProp\n) {\n  if (value) {\n    if (!isObject(value)) {\n      \"development\" !== 'production' && warn(\n        'v-bind without argument expects an Object or Array value',\n        this\n      );\n    } else {\n      if (Array.isArray(value)) {\n        value = toObject(value);\n      }\n      var hash;\n      for (var key in value) {\n        if (key === 'class' || key === 'style') {\n          hash = data;\n        } else {\n          var type = data.attrs && data.attrs.type;\n          hash = asProp || config.mustUseProp(tag, type, key)\n            ? data.domProps || (data.domProps = {})\n            : data.attrs || (data.attrs = {});\n        }\n        if (!(key in hash)) {\n          hash[key] = value[key];\n        }\n      }\n    }\n  }\n  return data\n}\n\n/*  */\n\n/**\n * Runtime helper for rendering static trees.\n */\nfunction renderStatic (\n  index,\n  isInFor\n) {\n  var tree = this._staticTrees[index];\n  // if has already-rendered static tree and not inside v-for,\n  // we can reuse the same tree by doing a shallow clone.\n  if (tree && !isInFor) {\n    return Array.isArray(tree)\n      ? cloneVNodes(tree)\n      : cloneVNode(tree)\n  }\n  // otherwise, render a fresh tree.\n  tree = this._staticTrees[index] =\n    this.$options.staticRenderFns[index].call(this._renderProxy);\n  markStatic(tree, (\"__static__\" + index), false);\n  return tree\n}\n\n/**\n * Runtime helper for v-once.\n * Effectively it means marking the node as static with a unique key.\n */\nfunction markOnce (\n  tree,\n  index,\n  key\n) {\n  markStatic(tree, (\"__once__\" + index + (key ? (\"_\" + key) : \"\")), true);\n  return tree\n}\n\nfunction markStatic (\n  tree,\n  key,\n  isOnce\n) {\n  if (Array.isArray(tree)) {\n    for (var i = 0; i < tree.length; i++) {\n      if (tree[i] && typeof tree[i] !== 'string') {\n        markStaticNode(tree[i], (key + \"_\" + i), isOnce);\n      }\n    }\n  } else {\n    markStaticNode(tree, key, isOnce);\n  }\n}\n\nfunction markStaticNode (node, key, isOnce) {\n  node.isStatic = true;\n  node.key = key;\n  node.isOnce = isOnce;\n}\n\n/*  */\n\nfunction initRender (vm) {\n  vm._vnode = null; // the root of the child tree\n  vm._staticTrees = null;\n  var parentVnode = vm.$vnode = vm.$options._parentVnode; // the placeholder node in parent tree\n  var renderContext = parentVnode && parentVnode.context;\n  vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext);\n  vm.$scopedSlots = emptyObject;\n  // bind the createElement fn to this instance\n  // so that we get proper render context inside it.\n  // args order: tag, data, children, normalizationType, alwaysNormalize\n  // internal version is used by render functions compiled from templates\n  vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); };\n  // normalization is always applied for the public version, used in\n  // user-written render functions.\n  vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); };\n}\n\nfunction renderMixin (Vue) {\n  Vue.prototype.$nextTick = function (fn) {\n    return nextTick(fn, this)\n  };\n\n  Vue.prototype._render = function () {\n    var vm = this;\n    var ref = vm.$options;\n    var render = ref.render;\n    var staticRenderFns = ref.staticRenderFns;\n    var _parentVnode = ref._parentVnode;\n\n    if (vm._isMounted) {\n      // clone slot nodes on re-renders\n      for (var key in vm.$slots) {\n        vm.$slots[key] = cloneVNodes(vm.$slots[key]);\n      }\n    }\n\n    vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject;\n\n    if (staticRenderFns && !vm._staticTrees) {\n      vm._staticTrees = [];\n    }\n    // set parent vnode. this allows render functions to have access\n    // to the data on the placeholder node.\n    vm.$vnode = _parentVnode;\n    // render self\n    var vnode;\n    try {\n      vnode = render.call(vm._renderProxy, vm.$createElement);\n    } catch (e) {\n      handleError(e, vm, \"render function\");\n      // return error render result,\n      // or previous vnode to prevent render error causing blank component\n      /* istanbul ignore else */\n      {\n        vnode = vm.$options.renderError\n          ? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e)\n          : vm._vnode;\n      }\n    }\n    // return empty vnode in case the render function errored out\n    if (!(vnode instanceof VNode)) {\n      if (\"development\" !== 'production' && Array.isArray(vnode)) {\n        warn(\n          'Multiple root nodes returned from render function. Render function ' +\n          'should return a single root node.',\n          vm\n        );\n      }\n      vnode = createEmptyVNode();\n    }\n    // set parent\n    vnode.parent = _parentVnode;\n    return vnode\n  };\n\n  // internal render helpers.\n  // these are exposed on the instance prototype to reduce generated render\n  // code size.\n  Vue.prototype._o = markOnce;\n  Vue.prototype._n = toNumber;\n  Vue.prototype._s = _toString;\n  Vue.prototype._l = renderList;\n  Vue.prototype._t = renderSlot;\n  Vue.prototype._q = looseEqual;\n  Vue.prototype._i = looseIndexOf;\n  Vue.prototype._m = renderStatic;\n  Vue.prototype._f = resolveFilter;\n  Vue.prototype._k = checkKeyCodes;\n  Vue.prototype._b = bindObjectProps;\n  Vue.prototype._v = createTextVNode;\n  Vue.prototype._e = createEmptyVNode;\n  Vue.prototype._u = resolveScopedSlots;\n}\n\n/*  */\n\nvar uid$1 = 0;\n\nfunction initMixin (Vue) {\n  Vue.prototype._init = function (options) {\n    var vm = this;\n    // a uid\n    vm._uid = uid$1++;\n\n    var startTag, endTag;\n    /* istanbul ignore if */\n    if (\"development\" !== 'production' && config.performance && mark) {\n      startTag = \"vue-perf-init:\" + (vm._uid);\n      endTag = \"vue-perf-end:\" + (vm._uid);\n      mark(startTag);\n    }\n\n    // a flag to avoid this being observed\n    vm._isVue = true;\n    // merge options\n    if (options && options._isComponent) {\n      // optimize internal component instantiation\n      // since dynamic options merging is pretty slow, and none of the\n      // internal component options needs special treatment.\n      initInternalComponent(vm, options);\n    } else {\n      vm.$options = mergeOptions(\n        resolveConstructorOptions(vm.constructor),\n        options || {},\n        vm\n      );\n    }\n    /* istanbul ignore else */\n    {\n      initProxy(vm);\n    }\n    // expose real self\n    vm._self = vm;\n    initLifecycle(vm);\n    initEvents(vm);\n    initRender(vm);\n    callHook(vm, 'beforeCreate');\n    initInjections(vm); // resolve injections before data/props\n    initState(vm);\n    initProvide(vm); // resolve provide after data/props\n    callHook(vm, 'created');\n\n    /* istanbul ignore if */\n    if (\"development\" !== 'production' && config.performance && mark) {\n      vm._name = formatComponentName(vm, false);\n      mark(endTag);\n      measure(((vm._name) + \" init\"), startTag, endTag);\n    }\n\n    if (vm.$options.el) {\n      vm.$mount(vm.$options.el);\n    }\n  };\n}\n\nfunction initInternalComponent (vm, options) {\n  var opts = vm.$options = Object.create(vm.constructor.options);\n  // doing this because it's faster than dynamic enumeration.\n  opts.parent = options.parent;\n  opts.propsData = options.propsData;\n  opts._parentVnode = options._parentVnode;\n  opts._parentListeners = options._parentListeners;\n  opts._renderChildren = options._renderChildren;\n  opts._componentTag = options._componentTag;\n  opts._parentElm = options._parentElm;\n  opts._refElm = options._refElm;\n  if (options.render) {\n    opts.render = options.render;\n    opts.staticRenderFns = options.staticRenderFns;\n  }\n}\n\nfunction resolveConstructorOptions (Ctor) {\n  var options = Ctor.options;\n  if (Ctor.super) {\n    var superOptions = resolveConstructorOptions(Ctor.super);\n    var cachedSuperOptions = Ctor.superOptions;\n    if (superOptions !== cachedSuperOptions) {\n      // super option changed,\n      // need to resolve new options.\n      Ctor.superOptions = superOptions;\n      // check if there are any late-modified/attached options (#4976)\n      var modifiedOptions = resolveModifiedOptions(Ctor);\n      // update base extend options\n      if (modifiedOptions) {\n        extend(Ctor.extendOptions, modifiedOptions);\n      }\n      options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);\n      if (options.name) {\n        options.components[options.name] = Ctor;\n      }\n    }\n  }\n  return options\n}\n\nfunction resolveModifiedOptions (Ctor) {\n  var modified;\n  var latest = Ctor.options;\n  var extended = Ctor.extendOptions;\n  var sealed = Ctor.sealedOptions;\n  for (var key in latest) {\n    if (latest[key] !== sealed[key]) {\n      if (!modified) { modified = {}; }\n      modified[key] = dedupe(latest[key], extended[key], sealed[key]);\n    }\n  }\n  return modified\n}\n\nfunction dedupe (latest, extended, sealed) {\n  // compare latest and sealed to ensure lifecycle hooks won't be duplicated\n  // between merges\n  if (Array.isArray(latest)) {\n    var res = [];\n    sealed = Array.isArray(sealed) ? sealed : [sealed];\n    extended = Array.isArray(extended) ? extended : [extended];\n    for (var i = 0; i < latest.length; i++) {\n      // push original options and not sealed options to exclude duplicated options\n      if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) {\n        res.push(latest[i]);\n      }\n    }\n    return res\n  } else {\n    return latest\n  }\n}\n\nfunction Vue$3 (options) {\n  if (\"development\" !== 'production' &&\n    !(this instanceof Vue$3)) {\n    warn('Vue is a constructor and should be called with the `new` keyword');\n  }\n  this._init(options);\n}\n\ninitMixin(Vue$3);\nstateMixin(Vue$3);\neventsMixin(Vue$3);\nlifecycleMixin(Vue$3);\nrenderMixin(Vue$3);\n\n/*  */\n\nfunction initUse (Vue) {\n  Vue.use = function (plugin) {\n    /* istanbul ignore if */\n    if (plugin.installed) {\n      return\n    }\n    // additional parameters\n    var args = toArray(arguments, 1);\n    args.unshift(this);\n    if (typeof plugin.install === 'function') {\n      plugin.install.apply(plugin, args);\n    } else if (typeof plugin === 'function') {\n      plugin.apply(null, args);\n    }\n    plugin.installed = true;\n    return this\n  };\n}\n\n/*  */\n\nfunction initMixin$1 (Vue) {\n  Vue.mixin = function (mixin) {\n    this.options = mergeOptions(this.options, mixin);\n  };\n}\n\n/*  */\n\nfunction initExtend (Vue) {\n  /**\n   * Each instance constructor, including Vue, has a unique\n   * cid. This enables us to create wrapped \"child\n   * constructors\" for prototypal inheritance and cache them.\n   */\n  Vue.cid = 0;\n  var cid = 1;\n\n  /**\n   * Class inheritance\n   */\n  Vue.extend = function (extendOptions) {\n    extendOptions = extendOptions || {};\n    var Super = this;\n    var SuperId = Super.cid;\n    var cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {});\n    if (cachedCtors[SuperId]) {\n      return cachedCtors[SuperId]\n    }\n\n    var name = extendOptions.name || Super.options.name;\n    {\n      if (!/^[a-zA-Z][\\w-]*$/.test(name)) {\n        warn(\n          'Invalid component name: \"' + name + '\". Component names ' +\n          'can only contain alphanumeric characters and the hyphen, ' +\n          'and must start with a letter.'\n        );\n      }\n    }\n\n    var Sub = function VueComponent (options) {\n      this._init(options);\n    };\n    Sub.prototype = Object.create(Super.prototype);\n    Sub.prototype.constructor = Sub;\n    Sub.cid = cid++;\n    Sub.options = mergeOptions(\n      Super.options,\n      extendOptions\n    );\n    Sub['super'] = Super;\n\n    // For props and computed properties, we define the proxy getters on\n    // the Vue instances at extension time, on the extended prototype. This\n    // avoids Object.defineProperty calls for each instance created.\n    if (Sub.options.props) {\n      initProps$1(Sub);\n    }\n    if (Sub.options.computed) {\n      initComputed$1(Sub);\n    }\n\n    // allow further extension/mixin/plugin usage\n    Sub.extend = Super.extend;\n    Sub.mixin = Super.mixin;\n    Sub.use = Super.use;\n\n    // create asset registers, so extended classes\n    // can have their private assets too.\n    ASSET_TYPES.forEach(function (type) {\n      Sub[type] = Super[type];\n    });\n    // enable recursive self-lookup\n    if (name) {\n      Sub.options.components[name] = Sub;\n    }\n\n    // keep a reference to the super options at extension time.\n    // later at instantiation we can check if Super's options have\n    // been updated.\n    Sub.superOptions = Super.options;\n    Sub.extendOptions = extendOptions;\n    Sub.sealedOptions = extend({}, Sub.options);\n\n    // cache constructor\n    cachedCtors[SuperId] = Sub;\n    return Sub\n  };\n}\n\nfunction initProps$1 (Comp) {\n  var props = Comp.options.props;\n  for (var key in props) {\n    proxy(Comp.prototype, \"_props\", key);\n  }\n}\n\nfunction initComputed$1 (Comp) {\n  var computed = Comp.options.computed;\n  for (var key in computed) {\n    defineComputed(Comp.prototype, key, computed[key]);\n  }\n}\n\n/*  */\n\nfunction initAssetRegisters (Vue) {\n  /**\n   * Create asset registration methods.\n   */\n  ASSET_TYPES.forEach(function (type) {\n    Vue[type] = function (\n      id,\n      definition\n    ) {\n      if (!definition) {\n        return this.options[type + 's'][id]\n      } else {\n        /* istanbul ignore if */\n        {\n          if (type === 'component' && config.isReservedTag(id)) {\n            warn(\n              'Do not use built-in or reserved HTML elements as component ' +\n              'id: ' + id\n            );\n          }\n        }\n        if (type === 'component' && isPlainObject(definition)) {\n          definition.name = definition.name || id;\n          definition = this.options._base.extend(definition);\n        }\n        if (type === 'directive' && typeof definition === 'function') {\n          definition = { bind: definition, update: definition };\n        }\n        this.options[type + 's'][id] = definition;\n        return definition\n      }\n    };\n  });\n}\n\n/*  */\n\nvar patternTypes = [String, RegExp];\n\nfunction getComponentName (opts) {\n  return opts && (opts.Ctor.options.name || opts.tag)\n}\n\nfunction matches (pattern, name) {\n  if (typeof pattern === 'string') {\n    return pattern.split(',').indexOf(name) > -1\n  } else if (isRegExp(pattern)) {\n    return pattern.test(name)\n  }\n  /* istanbul ignore next */\n  return false\n}\n\nfunction pruneCache (cache, current, filter) {\n  for (var key in cache) {\n    var cachedNode = cache[key];\n    if (cachedNode) {\n      var name = getComponentName(cachedNode.componentOptions);\n      if (name && !filter(name)) {\n        if (cachedNode !== current) {\n          pruneCacheEntry(cachedNode);\n        }\n        cache[key] = null;\n      }\n    }\n  }\n}\n\nfunction pruneCacheEntry (vnode) {\n  if (vnode) {\n    vnode.componentInstance.$destroy();\n  }\n}\n\nvar KeepAlive = {\n  name: 'keep-alive',\n  abstract: true,\n\n  props: {\n    include: patternTypes,\n    exclude: patternTypes\n  },\n\n  created: function created () {\n    this.cache = Object.create(null);\n  },\n\n  destroyed: function destroyed () {\n    var this$1 = this;\n\n    for (var key in this$1.cache) {\n      pruneCacheEntry(this$1.cache[key]);\n    }\n  },\n\n  watch: {\n    include: function include (val) {\n      pruneCache(this.cache, this._vnode, function (name) { return matches(val, name); });\n    },\n    exclude: function exclude (val) {\n      pruneCache(this.cache, this._vnode, function (name) { return !matches(val, name); });\n    }\n  },\n\n  render: function render () {\n    var vnode = getFirstComponentChild(this.$slots.default);\n    var componentOptions = vnode && vnode.componentOptions;\n    if (componentOptions) {\n      // check pattern\n      var name = getComponentName(componentOptions);\n      if (name && (\n        (this.include && !matches(this.include, name)) ||\n        (this.exclude && matches(this.exclude, name))\n      )) {\n        return vnode\n      }\n      var key = vnode.key == null\n        // same constructor may get registered as different local components\n        // so cid alone is not enough (#3269)\n        ? componentOptions.Ctor.cid + (componentOptions.tag ? (\"::\" + (componentOptions.tag)) : '')\n        : vnode.key;\n      if (this.cache[key]) {\n        vnode.componentInstance = this.cache[key].componentInstance;\n      } else {\n        this.cache[key] = vnode;\n      }\n      vnode.data.keepAlive = true;\n    }\n    return vnode\n  }\n};\n\nvar builtInComponents = {\n  KeepAlive: KeepAlive\n};\n\n/*  */\n\nfunction initGlobalAPI (Vue) {\n  // config\n  var configDef = {};\n  configDef.get = function () { return config; };\n  {\n    configDef.set = function () {\n      warn(\n        'Do not replace the Vue.config object, set individual fields instead.'\n      );\n    };\n  }\n  Object.defineProperty(Vue, 'config', configDef);\n\n  // exposed util methods.\n  // NOTE: these are not considered part of the public API - avoid relying on\n  // them unless you are aware of the risk.\n  Vue.util = {\n    warn: warn,\n    extend: extend,\n    mergeOptions: mergeOptions,\n    defineReactive: defineReactive$$1\n  };\n\n  Vue.set = set;\n  Vue.delete = del;\n  Vue.nextTick = nextTick;\n\n  Vue.options = Object.create(null);\n  ASSET_TYPES.forEach(function (type) {\n    Vue.options[type + 's'] = Object.create(null);\n  });\n\n  // this is used to identify the \"base\" constructor to extend all plain-object\n  // components with in Weex's multi-instance scenarios.\n  Vue.options._base = Vue;\n\n  extend(Vue.options.components, builtInComponents);\n\n  initUse(Vue);\n  initMixin$1(Vue);\n  initExtend(Vue);\n  initAssetRegisters(Vue);\n}\n\ninitGlobalAPI(Vue$3);\n\nObject.defineProperty(Vue$3.prototype, '$isServer', {\n  get: isServerRendering\n});\n\nVue$3.version = '2.3.0';\n\n/*  */\n\n// these are reserved for web because they are directly compiled away\n// during template compilation\nvar isReservedAttr = makeMap('style,class');\n\n// attributes that should be using props for binding\nvar acceptValue = makeMap('input,textarea,option,select');\nvar mustUseProp = function (tag, type, attr) {\n  return (\n    (attr === 'value' && acceptValue(tag)) && type !== 'button' ||\n    (attr === 'selected' && tag === 'option') ||\n    (attr === 'checked' && tag === 'input') ||\n    (attr === 'muted' && tag === 'video')\n  )\n};\n\nvar isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');\n\nvar isBooleanAttr = makeMap(\n  'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +\n  'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +\n  'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +\n  'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +\n  'required,reversed,scoped,seamless,selected,sortable,translate,' +\n  'truespeed,typemustmatch,visible'\n);\n\nvar xlinkNS = 'http://www.w3.org/1999/xlink';\n\nvar isXlink = function (name) {\n  return name.charAt(5) === ':' && name.slice(0, 5) === 'xlink'\n};\n\nvar getXlinkProp = function (name) {\n  return isXlink(name) ? name.slice(6, name.length) : ''\n};\n\nvar isFalsyAttrValue = function (val) {\n  return val == null || val === false\n};\n\n/*  */\n\nfunction genClassForVnode (vnode) {\n  var data = vnode.data;\n  var parentNode = vnode;\n  var childNode = vnode;\n  while (isDef(childNode.componentInstance)) {\n    childNode = childNode.componentInstance._vnode;\n    if (childNode.data) {\n      data = mergeClassData(childNode.data, data);\n    }\n  }\n  while (isDef(parentNode = parentNode.parent)) {\n    if (parentNode.data) {\n      data = mergeClassData(data, parentNode.data);\n    }\n  }\n  return genClassFromData(data)\n}\n\nfunction mergeClassData (child, parent) {\n  return {\n    staticClass: concat(child.staticClass, parent.staticClass),\n    class: isDef(child.class)\n      ? [child.class, parent.class]\n      : parent.class\n  }\n}\n\nfunction genClassFromData (data) {\n  var dynamicClass = data.class;\n  var staticClass = data.staticClass;\n  if (isDef(staticClass) || isDef(dynamicClass)) {\n    return concat(staticClass, stringifyClass(dynamicClass))\n  }\n  /* istanbul ignore next */\n  return ''\n}\n\nfunction concat (a, b) {\n  return a ? b ? (a + ' ' + b) : a : (b || '')\n}\n\nfunction stringifyClass (value) {\n  if (isUndef(value)) {\n    return ''\n  }\n  if (typeof value === 'string') {\n    return value\n  }\n  var res = '';\n  if (Array.isArray(value)) {\n    var stringified;\n    for (var i = 0, l = value.length; i < l; i++) {\n      if (isDef(value[i])) {\n        if (isDef(stringified = stringifyClass(value[i])) && stringified !== '') {\n          res += stringified + ' ';\n        }\n      }\n    }\n    return res.slice(0, -1)\n  }\n  if (isObject(value)) {\n    for (var key in value) {\n      if (value[key]) { res += key + ' '; }\n    }\n    return res.slice(0, -1)\n  }\n  /* istanbul ignore next */\n  return res\n}\n\n/*  */\n\nvar namespaceMap = {\n  svg: 'http://www.w3.org/2000/svg',\n  math: 'http://www.w3.org/1998/Math/MathML'\n};\n\nvar isHTMLTag = makeMap(\n  'html,body,base,head,link,meta,style,title,' +\n  'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +\n  'div,dd,dl,dt,figcaption,figure,hr,img,li,main,ol,p,pre,ul,' +\n  'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +\n  's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +\n  'embed,object,param,source,canvas,script,noscript,del,ins,' +\n  'caption,col,colgroup,table,thead,tbody,td,th,tr,' +\n  'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +\n  'output,progress,select,textarea,' +\n  'details,dialog,menu,menuitem,summary,' +\n  'content,element,shadow,template'\n);\n\n// this map is intentionally selective, only covering SVG elements that may\n// contain child elements.\nvar isSVG = makeMap(\n  'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +\n  'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +\n  'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',\n  true\n);\n\nvar isPreTag = function (tag) { return tag === 'pre'; };\n\nvar isReservedTag = function (tag) {\n  return isHTMLTag(tag) || isSVG(tag)\n};\n\nfunction getTagNamespace (tag) {\n  if (isSVG(tag)) {\n    return 'svg'\n  }\n  // basic support for MathML\n  // note it doesn't support other MathML elements being component roots\n  if (tag === 'math') {\n    return 'math'\n  }\n}\n\nvar unknownElementCache = Object.create(null);\nfunction isUnknownElement (tag) {\n  /* istanbul ignore if */\n  if (!inBrowser) {\n    return true\n  }\n  if (isReservedTag(tag)) {\n    return false\n  }\n  tag = tag.toLowerCase();\n  /* istanbul ignore if */\n  if (unknownElementCache[tag] != null) {\n    return unknownElementCache[tag]\n  }\n  var el = document.createElement(tag);\n  if (tag.indexOf('-') > -1) {\n    // http://stackoverflow.com/a/28210364/1070244\n    return (unknownElementCache[tag] = (\n      el.constructor === window.HTMLUnknownElement ||\n      el.constructor === window.HTMLElement\n    ))\n  } else {\n    return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()))\n  }\n}\n\n/*  */\n\n/**\n * Query an element selector if it's not an element already.\n */\nfunction query (el) {\n  if (typeof el === 'string') {\n    var selected = document.querySelector(el);\n    if (!selected) {\n      \"development\" !== 'production' && warn(\n        'Cannot find element: ' + el\n      );\n      return document.createElement('div')\n    }\n    return selected\n  } else {\n    return el\n  }\n}\n\n/*  */\n\nfunction createElement$1 (tagName, vnode) {\n  var elm = document.createElement(tagName);\n  if (tagName !== 'select') {\n    return elm\n  }\n  // false or null will remove the attribute but undefined will not\n  if (vnode.data && vnode.data.attrs && vnode.data.attrs.multiple !== undefined) {\n    elm.setAttribute('multiple', 'multiple');\n  }\n  return elm\n}\n\nfunction createElementNS (namespace, tagName) {\n  return document.createElementNS(namespaceMap[namespace], tagName)\n}\n\nfunction createTextNode (text) {\n  return document.createTextNode(text)\n}\n\nfunction createComment (text) {\n  return document.createComment(text)\n}\n\nfunction insertBefore (parentNode, newNode, referenceNode) {\n  parentNode.insertBefore(newNode, referenceNode);\n}\n\nfunction removeChild (node, child) {\n  node.removeChild(child);\n}\n\nfunction appendChild (node, child) {\n  node.appendChild(child);\n}\n\nfunction parentNode (node) {\n  return node.parentNode\n}\n\nfunction nextSibling (node) {\n  return node.nextSibling\n}\n\nfunction tagName (node) {\n  return node.tagName\n}\n\nfunction setTextContent (node, text) {\n  node.textContent = text;\n}\n\nfunction setAttribute (node, key, val) {\n  node.setAttribute(key, val);\n}\n\n\nvar nodeOps = Object.freeze({\n\tcreateElement: createElement$1,\n\tcreateElementNS: createElementNS,\n\tcreateTextNode: createTextNode,\n\tcreateComment: createComment,\n\tinsertBefore: insertBefore,\n\tremoveChild: removeChild,\n\tappendChild: appendChild,\n\tparentNode: parentNode,\n\tnextSibling: nextSibling,\n\ttagName: tagName,\n\tsetTextContent: setTextContent,\n\tsetAttribute: setAttribute\n});\n\n/*  */\n\nvar ref = {\n  create: function create (_, vnode) {\n    registerRef(vnode);\n  },\n  update: function update (oldVnode, vnode) {\n    if (oldVnode.data.ref !== vnode.data.ref) {\n      registerRef(oldVnode, true);\n      registerRef(vnode);\n    }\n  },\n  destroy: function destroy (vnode) {\n    registerRef(vnode, true);\n  }\n};\n\nfunction registerRef (vnode, isRemoval) {\n  var key = vnode.data.ref;\n  if (!key) { return }\n\n  var vm = vnode.context;\n  var ref = vnode.componentInstance || vnode.elm;\n  var refs = vm.$refs;\n  if (isRemoval) {\n    if (Array.isArray(refs[key])) {\n      remove(refs[key], ref);\n    } else if (refs[key] === ref) {\n      refs[key] = undefined;\n    }\n  } else {\n    if (vnode.data.refInFor) {\n      if (Array.isArray(refs[key]) && refs[key].indexOf(ref) < 0) {\n        refs[key].push(ref);\n      } else {\n        refs[key] = [ref];\n      }\n    } else {\n      refs[key] = ref;\n    }\n  }\n}\n\n/**\n * Virtual DOM patching algorithm based on Snabbdom by\n * Simon Friis Vindum (@paldepind)\n * Licensed under the MIT License\n * https://github.com/paldepind/snabbdom/blob/master/LICENSE\n *\n * modified by Evan You (@yyx990803)\n *\n\n/*\n * Not type-checking this because this file is perf-critical and the cost\n * of making flow understand it is not worth it.\n */\n\nvar emptyNode = new VNode('', {}, []);\n\nvar hooks = ['create', 'activate', 'update', 'remove', 'destroy'];\n\nfunction sameVnode (a, b) {\n  return (\n    a.key === b.key &&\n    a.tag === b.tag &&\n    a.isComment === b.isComment &&\n    isDef(a.data) === isDef(b.data) &&\n    sameInputType(a, b)\n  )\n}\n\n// Some browsers do not support dynamically changing type for <input>\n// so they need to be treated as different nodes\nfunction sameInputType (a, b) {\n  if (a.tag !== 'input') { return true }\n  var i;\n  var typeA = isDef(i = a.data) && isDef(i = i.attrs) && i.type;\n  var typeB = isDef(i = b.data) && isDef(i = i.attrs) && i.type;\n  return typeA === typeB\n}\n\nfunction createKeyToOldIdx (children, beginIdx, endIdx) {\n  var i, key;\n  var map = {};\n  for (i = beginIdx; i <= endIdx; ++i) {\n    key = children[i].key;\n    if (isDef(key)) { map[key] = i; }\n  }\n  return map\n}\n\nfunction createPatchFunction (backend) {\n  var i, j;\n  var cbs = {};\n\n  var modules = backend.modules;\n  var nodeOps = backend.nodeOps;\n\n  for (i = 0; i < hooks.length; ++i) {\n    cbs[hooks[i]] = [];\n    for (j = 0; j < modules.length; ++j) {\n      if (isDef(modules[j][hooks[i]])) {\n        cbs[hooks[i]].push(modules[j][hooks[i]]);\n      }\n    }\n  }\n\n  function emptyNodeAt (elm) {\n    return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)\n  }\n\n  function createRmCb (childElm, listeners) {\n    function remove$$1 () {\n      if (--remove$$1.listeners === 0) {\n        removeNode(childElm);\n      }\n    }\n    remove$$1.listeners = listeners;\n    return remove$$1\n  }\n\n  function removeNode (el) {\n    var parent = nodeOps.parentNode(el);\n    // element may have already been removed due to v-html / v-text\n    if (isDef(parent)) {\n      nodeOps.removeChild(parent, el);\n    }\n  }\n\n  var inPre = 0;\n  function createElm (vnode, insertedVnodeQueue, parentElm, refElm, nested) {\n    vnode.isRootInsert = !nested; // for transition enter check\n    if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {\n      return\n    }\n\n    var data = vnode.data;\n    var children = vnode.children;\n    var tag = vnode.tag;\n    if (isDef(tag)) {\n      {\n        if (data && data.pre) {\n          inPre++;\n        }\n        if (\n          !inPre &&\n          !vnode.ns &&\n          !(config.ignoredElements.length && config.ignoredElements.indexOf(tag) > -1) &&\n          config.isUnknownElement(tag)\n        ) {\n          warn(\n            'Unknown custom element: <' + tag + '> - did you ' +\n            'register the component correctly? For recursive components, ' +\n            'make sure to provide the \"name\" option.',\n            vnode.context\n          );\n        }\n      }\n      vnode.elm = vnode.ns\n        ? nodeOps.createElementNS(vnode.ns, tag)\n        : nodeOps.createElement(tag, vnode);\n      setScope(vnode);\n\n      /* istanbul ignore if */\n      {\n        createChildren(vnode, children, insertedVnodeQueue);\n        if (isDef(data)) {\n          invokeCreateHooks(vnode, insertedVnodeQueue);\n        }\n        insert(parentElm, vnode.elm, refElm);\n      }\n\n      if (\"development\" !== 'production' && data && data.pre) {\n        inPre--;\n      }\n    } else if (isTrue(vnode.isComment)) {\n      vnode.elm = nodeOps.createComment(vnode.text);\n      insert(parentElm, vnode.elm, refElm);\n    } else {\n      vnode.elm = nodeOps.createTextNode(vnode.text);\n      insert(parentElm, vnode.elm, refElm);\n    }\n  }\n\n  function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) {\n    var i = vnode.data;\n    if (isDef(i)) {\n      var isReactivated = isDef(vnode.componentInstance) && i.keepAlive;\n      if (isDef(i = i.hook) && isDef(i = i.init)) {\n        i(vnode, false /* hydrating */, parentElm, refElm);\n      }\n      // after calling the init hook, if the vnode is a child component\n      // it should've created a child instance and mounted it. the child\n      // component also has set the placeholder vnode's elm.\n      // in that case we can just return the element and be done.\n      if (isDef(vnode.componentInstance)) {\n        initComponent(vnode, insertedVnodeQueue);\n        if (isTrue(isReactivated)) {\n          reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm);\n        }\n        return true\n      }\n    }\n  }\n\n  function initComponent (vnode, insertedVnodeQueue) {\n    if (isDef(vnode.data.pendingInsert)) {\n      insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert);\n    }\n    vnode.elm = vnode.componentInstance.$el;\n    if (isPatchable(vnode)) {\n      invokeCreateHooks(vnode, insertedVnodeQueue);\n      setScope(vnode);\n    } else {\n      // empty component root.\n      // skip all element-related modules except for ref (#3455)\n      registerRef(vnode);\n      // make sure to invoke the insert hook\n      insertedVnodeQueue.push(vnode);\n    }\n  }\n\n  function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) {\n    var i;\n    // hack for #4339: a reactivated component with inner transition\n    // does not trigger because the inner node's created hooks are not called\n    // again. It's not ideal to involve module-specific logic in here but\n    // there doesn't seem to be a better way to do it.\n    var innerNode = vnode;\n    while (innerNode.componentInstance) {\n      innerNode = innerNode.componentInstance._vnode;\n      if (isDef(i = innerNode.data) && isDef(i = i.transition)) {\n        for (i = 0; i < cbs.activate.length; ++i) {\n          cbs.activate[i](emptyNode, innerNode);\n        }\n        insertedVnodeQueue.push(innerNode);\n        break\n      }\n    }\n    // unlike a newly created component,\n    // a reactivated keep-alive component doesn't insert itself\n    insert(parentElm, vnode.elm, refElm);\n  }\n\n  function insert (parent, elm, ref) {\n    if (isDef(parent)) {\n      if (isDef(ref)) {\n        if (ref.parentNode === parent) {\n          nodeOps.insertBefore(parent, elm, ref);\n        }\n      } else {\n        nodeOps.appendChild(parent, elm);\n      }\n    }\n  }\n\n  function createChildren (vnode, children, insertedVnodeQueue) {\n    if (Array.isArray(children)) {\n      for (var i = 0; i < children.length; ++i) {\n        createElm(children[i], insertedVnodeQueue, vnode.elm, null, true);\n      }\n    } else if (isPrimitive(vnode.text)) {\n      nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text));\n    }\n  }\n\n  function isPatchable (vnode) {\n    while (vnode.componentInstance) {\n      vnode = vnode.componentInstance._vnode;\n    }\n    return isDef(vnode.tag)\n  }\n\n  function invokeCreateHooks (vnode, insertedVnodeQueue) {\n    for (var i$1 = 0; i$1 < cbs.create.length; ++i$1) {\n      cbs.create[i$1](emptyNode, vnode);\n    }\n    i = vnode.data.hook; // Reuse variable\n    if (isDef(i)) {\n      if (isDef(i.create)) { i.create(emptyNode, vnode); }\n      if (isDef(i.insert)) { insertedVnodeQueue.push(vnode); }\n    }\n  }\n\n  // set scope id attribute for scoped CSS.\n  // this is implemented as a special case to avoid the overhead\n  // of going through the normal attribute patching process.\n  function setScope (vnode) {\n    var i;\n    var ancestor = vnode;\n    while (ancestor) {\n      if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) {\n        nodeOps.setAttribute(vnode.elm, i, '');\n      }\n      ancestor = ancestor.parent;\n    }\n    // for slot content they should also get the scopeId from the host instance.\n    if (isDef(i = activeInstance) &&\n        i !== vnode.context &&\n        isDef(i = i.$options._scopeId)) {\n      nodeOps.setAttribute(vnode.elm, i, '');\n    }\n  }\n\n  function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx, insertedVnodeQueue) {\n    for (; startIdx <= endIdx; ++startIdx) {\n      createElm(vnodes[startIdx], insertedVnodeQueue, parentElm, refElm);\n    }\n  }\n\n  function invokeDestroyHook (vnode) {\n    var i, j;\n    var data = vnode.data;\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.destroy)) { i(vnode); }\n      for (i = 0; i < cbs.destroy.length; ++i) { cbs.destroy[i](vnode); }\n    }\n    if (isDef(i = vnode.children)) {\n      for (j = 0; j < vnode.children.length; ++j) {\n        invokeDestroyHook(vnode.children[j]);\n      }\n    }\n  }\n\n  function removeVnodes (parentElm, vnodes, startIdx, endIdx) {\n    for (; startIdx <= endIdx; ++startIdx) {\n      var ch = vnodes[startIdx];\n      if (isDef(ch)) {\n        if (isDef(ch.tag)) {\n          removeAndInvokeRemoveHook(ch);\n          invokeDestroyHook(ch);\n        } else { // Text node\n          removeNode(ch.elm);\n        }\n      }\n    }\n  }\n\n  function removeAndInvokeRemoveHook (vnode, rm) {\n    if (isDef(rm) || isDef(vnode.data)) {\n      var i;\n      var listeners = cbs.remove.length + 1;\n      if (isDef(rm)) {\n        // we have a recursively passed down rm callback\n        // increase the listeners count\n        rm.listeners += listeners;\n      } else {\n        // directly removing\n        rm = createRmCb(vnode.elm, listeners);\n      }\n      // recursively invoke hooks on child component root node\n      if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) {\n        removeAndInvokeRemoveHook(i, rm);\n      }\n      for (i = 0; i < cbs.remove.length; ++i) {\n        cbs.remove[i](vnode, rm);\n      }\n      if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {\n        i(vnode, rm);\n      } else {\n        rm();\n      }\n    } else {\n      removeNode(vnode.elm);\n    }\n  }\n\n  function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {\n    var oldStartIdx = 0;\n    var newStartIdx = 0;\n    var oldEndIdx = oldCh.length - 1;\n    var oldStartVnode = oldCh[0];\n    var oldEndVnode = oldCh[oldEndIdx];\n    var newEndIdx = newCh.length - 1;\n    var newStartVnode = newCh[0];\n    var newEndVnode = newCh[newEndIdx];\n    var oldKeyToIdx, idxInOld, elmToMove, refElm;\n\n    // removeOnly is a special flag used only by <transition-group>\n    // to ensure removed elements stay in correct relative positions\n    // during leaving transitions\n    var canMove = !removeOnly;\n\n    while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {\n      if (isUndef(oldStartVnode)) {\n        oldStartVnode = oldCh[++oldStartIdx]; // Vnode has been moved left\n      } else if (isUndef(oldEndVnode)) {\n        oldEndVnode = oldCh[--oldEndIdx];\n      } else if (sameVnode(oldStartVnode, newStartVnode)) {\n        patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);\n        oldStartVnode = oldCh[++oldStartIdx];\n        newStartVnode = newCh[++newStartIdx];\n      } else if (sameVnode(oldEndVnode, newEndVnode)) {\n        patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);\n        oldEndVnode = oldCh[--oldEndIdx];\n        newEndVnode = newCh[--newEndIdx];\n      } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right\n        patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);\n        canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));\n        oldStartVnode = oldCh[++oldStartIdx];\n        newEndVnode = newCh[--newEndIdx];\n      } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left\n        patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);\n        canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);\n        oldEndVnode = oldCh[--oldEndIdx];\n        newStartVnode = newCh[++newStartIdx];\n      } else {\n        if (isUndef(oldKeyToIdx)) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); }\n        idxInOld = isDef(newStartVnode.key) ? oldKeyToIdx[newStartVnode.key] : null;\n        if (isUndef(idxInOld)) { // New element\n          createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);\n          newStartVnode = newCh[++newStartIdx];\n        } else {\n          elmToMove = oldCh[idxInOld];\n          /* istanbul ignore if */\n          if (\"development\" !== 'production' && !elmToMove) {\n            warn(\n              'It seems there are duplicate keys that is causing an update error. ' +\n              'Make sure each v-for item has a unique key.'\n            );\n          }\n          if (sameVnode(elmToMove, newStartVnode)) {\n            patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);\n            oldCh[idxInOld] = undefined;\n            canMove && nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);\n            newStartVnode = newCh[++newStartIdx];\n          } else {\n            // same key but different element. treat as new element\n            createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm);\n            newStartVnode = newCh[++newStartIdx];\n          }\n        }\n      }\n    }\n    if (oldStartIdx > oldEndIdx) {\n      refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;\n      addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);\n    } else if (newStartIdx > newEndIdx) {\n      removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);\n    }\n  }\n\n  function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {\n    if (oldVnode === vnode) {\n      return\n    }\n    // reuse element for static trees.\n    // note we only do this if the vnode is cloned -\n    // if the new node is not cloned it means the render functions have been\n    // reset by the hot-reload-api and we need to do a proper re-render.\n    if (isTrue(vnode.isStatic) &&\n        isTrue(oldVnode.isStatic) &&\n        vnode.key === oldVnode.key &&\n        (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))) {\n      vnode.elm = oldVnode.elm;\n      vnode.componentInstance = oldVnode.componentInstance;\n      return\n    }\n    var i;\n    var data = vnode.data;\n    if (isDef(data) && isDef(i = data.hook) && isDef(i = i.prepatch)) {\n      i(oldVnode, vnode);\n    }\n    var elm = vnode.elm = oldVnode.elm;\n    var oldCh = oldVnode.children;\n    var ch = vnode.children;\n    if (isDef(data) && isPatchable(vnode)) {\n      for (i = 0; i < cbs.update.length; ++i) { cbs.update[i](oldVnode, vnode); }\n      if (isDef(i = data.hook) && isDef(i = i.update)) { i(oldVnode, vnode); }\n    }\n    if (isUndef(vnode.text)) {\n      if (isDef(oldCh) && isDef(ch)) {\n        if (oldCh !== ch) { updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly); }\n      } else if (isDef(ch)) {\n        if (isDef(oldVnode.text)) { nodeOps.setTextContent(elm, ''); }\n        addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);\n      } else if (isDef(oldCh)) {\n        removeVnodes(elm, oldCh, 0, oldCh.length - 1);\n      } else if (isDef(oldVnode.text)) {\n        nodeOps.setTextContent(elm, '');\n      }\n    } else if (oldVnode.text !== vnode.text) {\n      nodeOps.setTextContent(elm, vnode.text);\n    }\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.postpatch)) { i(oldVnode, vnode); }\n    }\n  }\n\n  function invokeInsertHook (vnode, queue, initial) {\n    // delay insert hooks for component root nodes, invoke them after the\n    // element is really inserted\n    if (isTrue(initial) && isDef(vnode.parent)) {\n      vnode.parent.data.pendingInsert = queue;\n    } else {\n      for (var i = 0; i < queue.length; ++i) {\n        queue[i].data.hook.insert(queue[i]);\n      }\n    }\n  }\n\n  var bailed = false;\n  // list of modules that can skip create hook during hydration because they\n  // are already rendered on the client or has no need for initialization\n  var isRenderedModule = makeMap('attrs,style,class,staticClass,staticStyle,key');\n\n  // Note: this is a browser-only function so we can assume elms are DOM nodes.\n  function hydrate (elm, vnode, insertedVnodeQueue) {\n    {\n      if (!assertNodeMatch(elm, vnode)) {\n        return false\n      }\n    }\n    vnode.elm = elm;\n    var tag = vnode.tag;\n    var data = vnode.data;\n    var children = vnode.children;\n    if (isDef(data)) {\n      if (isDef(i = data.hook) && isDef(i = i.init)) { i(vnode, true /* hydrating */); }\n      if (isDef(i = vnode.componentInstance)) {\n        // child component. it should have hydrated its own tree.\n        initComponent(vnode, insertedVnodeQueue);\n        return true\n      }\n    }\n    if (isDef(tag)) {\n      if (isDef(children)) {\n        // empty element, allow client to pick up and populate children\n        if (!elm.hasChildNodes()) {\n          createChildren(vnode, children, insertedVnodeQueue);\n        } else {\n          var childrenMatch = true;\n          var childNode = elm.firstChild;\n          for (var i$1 = 0; i$1 < children.length; i$1++) {\n            if (!childNode || !hydrate(childNode, children[i$1], insertedVnodeQueue)) {\n              childrenMatch = false;\n              break\n            }\n            childNode = childNode.nextSibling;\n          }\n          // if childNode is not null, it means the actual childNodes list is\n          // longer than the virtual children list.\n          if (!childrenMatch || childNode) {\n            if (\"development\" !== 'production' &&\n                typeof console !== 'undefined' &&\n                !bailed) {\n              bailed = true;\n              console.warn('Parent: ', elm);\n              console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children);\n            }\n            return false\n          }\n        }\n      }\n      if (isDef(data)) {\n        for (var key in data) {\n          if (!isRenderedModule(key)) {\n            invokeCreateHooks(vnode, insertedVnodeQueue);\n            break\n          }\n        }\n      }\n    } else if (elm.data !== vnode.text) {\n      elm.data = vnode.text;\n    }\n    return true\n  }\n\n  function assertNodeMatch (node, vnode) {\n    if (isDef(vnode.tag)) {\n      return (\n        vnode.tag.indexOf('vue-component') === 0 ||\n        vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase())\n      )\n    } else {\n      return node.nodeType === (vnode.isComment ? 8 : 3)\n    }\n  }\n\n  return function patch (oldVnode, vnode, hydrating, removeOnly, parentElm, refElm) {\n    if (isUndef(vnode)) {\n      if (isDef(oldVnode)) { invokeDestroyHook(oldVnode); }\n      return\n    }\n\n    var isInitialPatch = false;\n    var insertedVnodeQueue = [];\n\n    if (isUndef(oldVnode)) {\n      // empty mount (likely as component), create new root element\n      isInitialPatch = true;\n      createElm(vnode, insertedVnodeQueue, parentElm, refElm);\n    } else {\n      var isRealElement = isDef(oldVnode.nodeType);\n      if (!isRealElement && sameVnode(oldVnode, vnode)) {\n        // patch existing root node\n        patchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly);\n      } else {\n        if (isRealElement) {\n          // mounting to a real element\n          // check if this is server-rendered content and if we can perform\n          // a successful hydration.\n          if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {\n            oldVnode.removeAttribute(SSR_ATTR);\n            hydrating = true;\n          }\n          if (isTrue(hydrating)) {\n            if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {\n              invokeInsertHook(vnode, insertedVnodeQueue, true);\n              return oldVnode\n            } else {\n              warn(\n                'The client-side rendered virtual DOM tree is not matching ' +\n                'server-rendered content. This is likely caused by incorrect ' +\n                'HTML markup, for example nesting block-level elements inside ' +\n                '<p>, or missing <tbody>. Bailing hydration and performing ' +\n                'full client-side render.'\n              );\n            }\n          }\n          // either not server-rendered, or hydration failed.\n          // create an empty node and replace it\n          oldVnode = emptyNodeAt(oldVnode);\n        }\n        // replacing existing element\n        var oldElm = oldVnode.elm;\n        var parentElm$1 = nodeOps.parentNode(oldElm);\n        createElm(\n          vnode,\n          insertedVnodeQueue,\n          // extremely rare edge case: do not insert if old element is in a\n          // leaving transition. Only happens when combining transition +\n          // keep-alive + HOCs. (#4590)\n          oldElm._leaveCb ? null : parentElm$1,\n          nodeOps.nextSibling(oldElm)\n        );\n\n        if (isDef(vnode.parent)) {\n          // component root element replaced.\n          // update parent placeholder node element, recursively\n          var ancestor = vnode.parent;\n          while (ancestor) {\n            ancestor.elm = vnode.elm;\n            ancestor = ancestor.parent;\n          }\n          if (isPatchable(vnode)) {\n            for (var i = 0; i < cbs.create.length; ++i) {\n              cbs.create[i](emptyNode, vnode.parent);\n            }\n          }\n        }\n\n        if (isDef(parentElm$1)) {\n          removeVnodes(parentElm$1, [oldVnode], 0, 0);\n        } else if (isDef(oldVnode.tag)) {\n          invokeDestroyHook(oldVnode);\n        }\n      }\n    }\n\n    invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch);\n    return vnode.elm\n  }\n}\n\n/*  */\n\nvar directives = {\n  create: updateDirectives,\n  update: updateDirectives,\n  destroy: function unbindDirectives (vnode) {\n    updateDirectives(vnode, emptyNode);\n  }\n};\n\nfunction updateDirectives (oldVnode, vnode) {\n  if (oldVnode.data.directives || vnode.data.directives) {\n    _update(oldVnode, vnode);\n  }\n}\n\nfunction _update (oldVnode, vnode) {\n  var isCreate = oldVnode === emptyNode;\n  var isDestroy = vnode === emptyNode;\n  var oldDirs = normalizeDirectives$1(oldVnode.data.directives, oldVnode.context);\n  var newDirs = normalizeDirectives$1(vnode.data.directives, vnode.context);\n\n  var dirsWithInsert = [];\n  var dirsWithPostpatch = [];\n\n  var key, oldDir, dir;\n  for (key in newDirs) {\n    oldDir = oldDirs[key];\n    dir = newDirs[key];\n    if (!oldDir) {\n      // new directive, bind\n      callHook$1(dir, 'bind', vnode, oldVnode);\n      if (dir.def && dir.def.inserted) {\n        dirsWithInsert.push(dir);\n      }\n    } else {\n      // existing directive, update\n      dir.oldValue = oldDir.value;\n      callHook$1(dir, 'update', vnode, oldVnode);\n      if (dir.def && dir.def.componentUpdated) {\n        dirsWithPostpatch.push(dir);\n      }\n    }\n  }\n\n  if (dirsWithInsert.length) {\n    var callInsert = function () {\n      for (var i = 0; i < dirsWithInsert.length; i++) {\n        callHook$1(dirsWithInsert[i], 'inserted', vnode, oldVnode);\n      }\n    };\n    if (isCreate) {\n      mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert);\n    } else {\n      callInsert();\n    }\n  }\n\n  if (dirsWithPostpatch.length) {\n    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', function () {\n      for (var i = 0; i < dirsWithPostpatch.length; i++) {\n        callHook$1(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode);\n      }\n    });\n  }\n\n  if (!isCreate) {\n    for (key in oldDirs) {\n      if (!newDirs[key]) {\n        // no longer present, unbind\n        callHook$1(oldDirs[key], 'unbind', oldVnode, oldVnode, isDestroy);\n      }\n    }\n  }\n}\n\nvar emptyModifiers = Object.create(null);\n\nfunction normalizeDirectives$1 (\n  dirs,\n  vm\n) {\n  var res = Object.create(null);\n  if (!dirs) {\n    return res\n  }\n  var i, dir;\n  for (i = 0; i < dirs.length; i++) {\n    dir = dirs[i];\n    if (!dir.modifiers) {\n      dir.modifiers = emptyModifiers;\n    }\n    res[getRawDirName(dir)] = dir;\n    dir.def = resolveAsset(vm.$options, 'directives', dir.name, true);\n  }\n  return res\n}\n\nfunction getRawDirName (dir) {\n  return dir.rawName || ((dir.name) + \".\" + (Object.keys(dir.modifiers || {}).join('.')))\n}\n\nfunction callHook$1 (dir, hook, vnode, oldVnode, isDestroy) {\n  var fn = dir.def && dir.def[hook];\n  if (fn) {\n    try {\n      fn(vnode.elm, dir, vnode, oldVnode, isDestroy);\n    } catch (e) {\n      handleError(e, vnode.context, (\"directive \" + (dir.name) + \" \" + hook + \" hook\"));\n    }\n  }\n}\n\nvar baseModules = [\n  ref,\n  directives\n];\n\n/*  */\n\nfunction updateAttrs (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.attrs) && isUndef(vnode.data.attrs)) {\n    return\n  }\n  var key, cur, old;\n  var elm = vnode.elm;\n  var oldAttrs = oldVnode.data.attrs || {};\n  var attrs = vnode.data.attrs || {};\n  // clone observed objects, as the user probably wants to mutate it\n  if (isDef(attrs.__ob__)) {\n    attrs = vnode.data.attrs = extend({}, attrs);\n  }\n\n  for (key in attrs) {\n    cur = attrs[key];\n    old = oldAttrs[key];\n    if (old !== cur) {\n      setAttr(elm, key, cur);\n    }\n  }\n  // #4391: in IE9, setting type can reset value for input[type=radio]\n  /* istanbul ignore if */\n  if (isIE9 && attrs.value !== oldAttrs.value) {\n    setAttr(elm, 'value', attrs.value);\n  }\n  for (key in oldAttrs) {\n    if (isUndef(attrs[key])) {\n      if (isXlink(key)) {\n        elm.removeAttributeNS(xlinkNS, getXlinkProp(key));\n      } else if (!isEnumeratedAttr(key)) {\n        elm.removeAttribute(key);\n      }\n    }\n  }\n}\n\nfunction setAttr (el, key, value) {\n  if (isBooleanAttr(key)) {\n    // set attribute for blank value\n    // e.g. <option disabled>Select one</option>\n    if (isFalsyAttrValue(value)) {\n      el.removeAttribute(key);\n    } else {\n      el.setAttribute(key, key);\n    }\n  } else if (isEnumeratedAttr(key)) {\n    el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true');\n  } else if (isXlink(key)) {\n    if (isFalsyAttrValue(value)) {\n      el.removeAttributeNS(xlinkNS, getXlinkProp(key));\n    } else {\n      el.setAttributeNS(xlinkNS, key, value);\n    }\n  } else {\n    if (isFalsyAttrValue(value)) {\n      el.removeAttribute(key);\n    } else {\n      el.setAttribute(key, value);\n    }\n  }\n}\n\nvar attrs = {\n  create: updateAttrs,\n  update: updateAttrs\n};\n\n/*  */\n\nfunction updateClass (oldVnode, vnode) {\n  var el = vnode.elm;\n  var data = vnode.data;\n  var oldData = oldVnode.data;\n  if (\n    isUndef(data.staticClass) &&\n    isUndef(data.class) && (\n      isUndef(oldData) || (\n        isUndef(oldData.staticClass) &&\n        isUndef(oldData.class)\n      )\n    )\n  ) {\n    return\n  }\n\n  var cls = genClassForVnode(vnode);\n\n  // handle transition classes\n  var transitionClass = el._transitionClasses;\n  if (isDef(transitionClass)) {\n    cls = concat(cls, stringifyClass(transitionClass));\n  }\n\n  // set the class\n  if (cls !== el._prevClass) {\n    el.setAttribute('class', cls);\n    el._prevClass = cls;\n  }\n}\n\nvar klass = {\n  create: updateClass,\n  update: updateClass\n};\n\n/*  */\n\nvar validDivisionCharRE = /[\\w).+\\-_$\\]]/;\n\nfunction parseFilters (exp) {\n  var inSingle = false;\n  var inDouble = false;\n  var inTemplateString = false;\n  var inRegex = false;\n  var curly = 0;\n  var square = 0;\n  var paren = 0;\n  var lastFilterIndex = 0;\n  var c, prev, i, expression, filters;\n\n  for (i = 0; i < exp.length; i++) {\n    prev = c;\n    c = exp.charCodeAt(i);\n    if (inSingle) {\n      if (c === 0x27 && prev !== 0x5C) { inSingle = false; }\n    } else if (inDouble) {\n      if (c === 0x22 && prev !== 0x5C) { inDouble = false; }\n    } else if (inTemplateString) {\n      if (c === 0x60 && prev !== 0x5C) { inTemplateString = false; }\n    } else if (inRegex) {\n      if (c === 0x2f && prev !== 0x5C) { inRegex = false; }\n    } else if (\n      c === 0x7C && // pipe\n      exp.charCodeAt(i + 1) !== 0x7C &&\n      exp.charCodeAt(i - 1) !== 0x7C &&\n      !curly && !square && !paren\n    ) {\n      if (expression === undefined) {\n        // first filter, end of expression\n        lastFilterIndex = i + 1;\n        expression = exp.slice(0, i).trim();\n      } else {\n        pushFilter();\n      }\n    } else {\n      switch (c) {\n        case 0x22: inDouble = true; break         // \"\n        case 0x27: inSingle = true; break         // '\n        case 0x60: inTemplateString = true; break // `\n        case 0x28: paren++; break                 // (\n        case 0x29: paren--; break                 // )\n        case 0x5B: square++; break                // [\n        case 0x5D: square--; break                // ]\n        case 0x7B: curly++; break                 // {\n        case 0x7D: curly--; break                 // }\n      }\n      if (c === 0x2f) { // /\n        var j = i - 1;\n        var p = (void 0);\n        // find first non-whitespace prev char\n        for (; j >= 0; j--) {\n          p = exp.charAt(j);\n          if (p !== ' ') { break }\n        }\n        if (!p || !validDivisionCharRE.test(p)) {\n          inRegex = true;\n        }\n      }\n    }\n  }\n\n  if (expression === undefined) {\n    expression = exp.slice(0, i).trim();\n  } else if (lastFilterIndex !== 0) {\n    pushFilter();\n  }\n\n  function pushFilter () {\n    (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());\n    lastFilterIndex = i + 1;\n  }\n\n  if (filters) {\n    for (i = 0; i < filters.length; i++) {\n      expression = wrapFilter(expression, filters[i]);\n    }\n  }\n\n  return expression\n}\n\nfunction wrapFilter (exp, filter) {\n  var i = filter.indexOf('(');\n  if (i < 0) {\n    // _f: resolveFilter\n    return (\"_f(\\\"\" + filter + \"\\\")(\" + exp + \")\")\n  } else {\n    var name = filter.slice(0, i);\n    var args = filter.slice(i + 1);\n    return (\"_f(\\\"\" + name + \"\\\")(\" + exp + \",\" + args)\n  }\n}\n\n/*  */\n\nfunction baseWarn (msg) {\n  console.error((\"[Vue compiler]: \" + msg));\n}\n\nfunction pluckModuleFunction (\n  modules,\n  key\n) {\n  return modules\n    ? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; })\n    : []\n}\n\nfunction addProp (el, name, value) {\n  (el.props || (el.props = [])).push({ name: name, value: value });\n}\n\nfunction addAttr (el, name, value) {\n  (el.attrs || (el.attrs = [])).push({ name: name, value: value });\n}\n\nfunction addDirective (\n  el,\n  name,\n  rawName,\n  value,\n  arg,\n  modifiers\n) {\n  (el.directives || (el.directives = [])).push({ name: name, rawName: rawName, value: value, arg: arg, modifiers: modifiers });\n}\n\nfunction addHandler (\n  el,\n  name,\n  value,\n  modifiers,\n  important,\n  warn\n) {\n  // warn prevent and passive modifier\n  /* istanbul ignore if */\n  if (\n    \"development\" !== 'production' && warn &&\n    modifiers && modifiers.prevent && modifiers.passive\n  ) {\n    warn(\n      'passive and prevent can\\'t be used together. ' +\n      'Passive handler can\\'t prevent default event.'\n    );\n  }\n  // check capture modifier\n  if (modifiers && modifiers.capture) {\n    delete modifiers.capture;\n    name = '!' + name; // mark the event as captured\n  }\n  if (modifiers && modifiers.once) {\n    delete modifiers.once;\n    name = '~' + name; // mark the event as once\n  }\n  /* istanbul ignore if */\n  if (modifiers && modifiers.passive) {\n    delete modifiers.passive;\n    name = '&' + name; // mark the event as passive\n  }\n  var events;\n  if (modifiers && modifiers.native) {\n    delete modifiers.native;\n    events = el.nativeEvents || (el.nativeEvents = {});\n  } else {\n    events = el.events || (el.events = {});\n  }\n  var newHandler = { value: value, modifiers: modifiers };\n  var handlers = events[name];\n  /* istanbul ignore if */\n  if (Array.isArray(handlers)) {\n    important ? handlers.unshift(newHandler) : handlers.push(newHandler);\n  } else if (handlers) {\n    events[name] = important ? [newHandler, handlers] : [handlers, newHandler];\n  } else {\n    events[name] = newHandler;\n  }\n}\n\nfunction getBindingAttr (\n  el,\n  name,\n  getStatic\n) {\n  var dynamicValue =\n    getAndRemoveAttr(el, ':' + name) ||\n    getAndRemoveAttr(el, 'v-bind:' + name);\n  if (dynamicValue != null) {\n    return parseFilters(dynamicValue)\n  } else if (getStatic !== false) {\n    var staticValue = getAndRemoveAttr(el, name);\n    if (staticValue != null) {\n      return JSON.stringify(staticValue)\n    }\n  }\n}\n\nfunction getAndRemoveAttr (el, name) {\n  var val;\n  if ((val = el.attrsMap[name]) != null) {\n    var list = el.attrsList;\n    for (var i = 0, l = list.length; i < l; i++) {\n      if (list[i].name === name) {\n        list.splice(i, 1);\n        break\n      }\n    }\n  }\n  return val\n}\n\n/*  */\n\n/**\n * Cross-platform code generation for component v-model\n */\nfunction genComponentModel (\n  el,\n  value,\n  modifiers\n) {\n  var ref = modifiers || {};\n  var number = ref.number;\n  var trim = ref.trim;\n\n  var baseValueExpression = '$$v';\n  var valueExpression = baseValueExpression;\n  if (trim) {\n    valueExpression =\n      \"(typeof \" + baseValueExpression + \" === 'string'\" +\n        \"? \" + baseValueExpression + \".trim()\" +\n        \": \" + baseValueExpression + \")\";\n  }\n  if (number) {\n    valueExpression = \"_n(\" + valueExpression + \")\";\n  }\n  var assignment = genAssignmentCode(value, valueExpression);\n\n  el.model = {\n    value: (\"(\" + value + \")\"),\n    expression: (\"\\\"\" + value + \"\\\"\"),\n    callback: (\"function (\" + baseValueExpression + \") {\" + assignment + \"}\")\n  };\n}\n\n/**\n * Cross-platform codegen helper for generating v-model value assignment code.\n */\nfunction genAssignmentCode (\n  value,\n  assignment\n) {\n  var modelRs = parseModel(value);\n  if (modelRs.idx === null) {\n    return (value + \"=\" + assignment)\n  } else {\n    return \"var $$exp = \" + (modelRs.exp) + \", $$idx = \" + (modelRs.idx) + \";\" +\n      \"if (!Array.isArray($$exp)){\" +\n        value + \"=\" + assignment + \"}\" +\n      \"else{$$exp.splice($$idx, 1, \" + assignment + \")}\"\n  }\n}\n\n/**\n * parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val)\n *\n * for loop possible cases:\n *\n * - test\n * - test[idx]\n * - test[test1[idx]]\n * - test[\"a\"][idx]\n * - xxx.test[a[a].test1[idx]]\n * - test.xxx.a[\"asa\"][test1[idx]]\n *\n */\n\nvar len;\nvar str;\nvar chr;\nvar index$1;\nvar expressionPos;\nvar expressionEndPos;\n\nfunction parseModel (val) {\n  str = val;\n  len = str.length;\n  index$1 = expressionPos = expressionEndPos = 0;\n\n  if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {\n    return {\n      exp: val,\n      idx: null\n    }\n  }\n\n  while (!eof()) {\n    chr = next();\n    /* istanbul ignore if */\n    if (isStringStart(chr)) {\n      parseString(chr);\n    } else if (chr === 0x5B) {\n      parseBracket(chr);\n    }\n  }\n\n  return {\n    exp: val.substring(0, expressionPos),\n    idx: val.substring(expressionPos + 1, expressionEndPos)\n  }\n}\n\nfunction next () {\n  return str.charCodeAt(++index$1)\n}\n\nfunction eof () {\n  return index$1 >= len\n}\n\nfunction isStringStart (chr) {\n  return chr === 0x22 || chr === 0x27\n}\n\nfunction parseBracket (chr) {\n  var inBracket = 1;\n  expressionPos = index$1;\n  while (!eof()) {\n    chr = next();\n    if (isStringStart(chr)) {\n      parseString(chr);\n      continue\n    }\n    if (chr === 0x5B) { inBracket++; }\n    if (chr === 0x5D) { inBracket--; }\n    if (inBracket === 0) {\n      expressionEndPos = index$1;\n      break\n    }\n  }\n}\n\nfunction parseString (chr) {\n  var stringQuote = chr;\n  while (!eof()) {\n    chr = next();\n    if (chr === stringQuote) {\n      break\n    }\n  }\n}\n\n/*  */\n\nvar warn$1;\n\n// in some cases, the event used has to be determined at runtime\n// so we used some reserved tokens during compile.\nvar RANGE_TOKEN = '__r';\nvar CHECKBOX_RADIO_TOKEN = '__c';\n\nfunction model (\n  el,\n  dir,\n  _warn\n) {\n  warn$1 = _warn;\n  var value = dir.value;\n  var modifiers = dir.modifiers;\n  var tag = el.tag;\n  var type = el.attrsMap.type;\n\n  {\n    var dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type'];\n    if (tag === 'input' && dynamicType) {\n      warn$1(\n        \"<input :type=\\\"\" + dynamicType + \"\\\" v-model=\\\"\" + value + \"\\\">:\\n\" +\n        \"v-model does not support dynamic input types. Use v-if branches instead.\"\n      );\n    }\n    // inputs with type=\"file\" are read only and setting the input's\n    // value will throw an error.\n    if (tag === 'input' && type === 'file') {\n      warn$1(\n        \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\" type=\\\"file\\\">:\\n\" +\n        \"File inputs are read only. Use a v-on:change listener instead.\"\n      );\n    }\n  }\n\n  if (tag === 'select') {\n    genSelect(el, value, modifiers);\n  } else if (tag === 'input' && type === 'checkbox') {\n    genCheckboxModel(el, value, modifiers);\n  } else if (tag === 'input' && type === 'radio') {\n    genRadioModel(el, value, modifiers);\n  } else if (tag === 'input' || tag === 'textarea') {\n    genDefaultModel(el, value, modifiers);\n  } else if (!config.isReservedTag(tag)) {\n    genComponentModel(el, value, modifiers);\n    // component v-model doesn't need extra runtime\n    return false\n  } else {\n    warn$1(\n      \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\">: \" +\n      \"v-model is not supported on this element type. \" +\n      'If you are working with contenteditable, it\\'s recommended to ' +\n      'wrap a library dedicated for that purpose inside a custom component.'\n    );\n  }\n\n  // ensure runtime directive metadata\n  return true\n}\n\nfunction genCheckboxModel (\n  el,\n  value,\n  modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var valueBinding = getBindingAttr(el, 'value') || 'null';\n  var trueValueBinding = getBindingAttr(el, 'true-value') || 'true';\n  var falseValueBinding = getBindingAttr(el, 'false-value') || 'false';\n  addProp(el, 'checked',\n    \"Array.isArray(\" + value + \")\" +\n      \"?_i(\" + value + \",\" + valueBinding + \")>-1\" + (\n        trueValueBinding === 'true'\n          ? (\":(\" + value + \")\")\n          : (\":_q(\" + value + \",\" + trueValueBinding + \")\")\n      )\n  );\n  addHandler(el, CHECKBOX_RADIO_TOKEN,\n    \"var $$a=\" + value + \",\" +\n        '$$el=$event.target,' +\n        \"$$c=$$el.checked?(\" + trueValueBinding + \"):(\" + falseValueBinding + \");\" +\n    'if(Array.isArray($$a)){' +\n      \"var $$v=\" + (number ? '_n(' + valueBinding + ')' : valueBinding) + \",\" +\n          '$$i=_i($$a,$$v);' +\n      \"if($$c){$$i<0&&(\" + value + \"=$$a.concat($$v))}\" +\n      \"else{$$i>-1&&(\" + value + \"=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}\" +\n    \"}else{\" + (genAssignmentCode(value, '$$c')) + \"}\",\n    null, true\n  );\n}\n\nfunction genRadioModel (\n    el,\n    value,\n    modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var valueBinding = getBindingAttr(el, 'value') || 'null';\n  valueBinding = number ? (\"_n(\" + valueBinding + \")\") : valueBinding;\n  addProp(el, 'checked', (\"_q(\" + value + \",\" + valueBinding + \")\"));\n  addHandler(el, CHECKBOX_RADIO_TOKEN, genAssignmentCode(value, valueBinding), null, true);\n}\n\nfunction genSelect (\n    el,\n    value,\n    modifiers\n) {\n  var number = modifiers && modifiers.number;\n  var selectedVal = \"Array.prototype.filter\" +\n    \".call($event.target.options,function(o){return o.selected})\" +\n    \".map(function(o){var val = \\\"_value\\\" in o ? o._value : o.value;\" +\n    \"return \" + (number ? '_n(val)' : 'val') + \"})\";\n\n  var assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';\n  var code = \"var $$selectedVal = \" + selectedVal + \";\";\n  code = code + \" \" + (genAssignmentCode(value, assignment));\n  addHandler(el, 'change', code, null, true);\n}\n\nfunction genDefaultModel (\n  el,\n  value,\n  modifiers\n) {\n  var type = el.attrsMap.type;\n  var ref = modifiers || {};\n  var lazy = ref.lazy;\n  var number = ref.number;\n  var trim = ref.trim;\n  var needCompositionGuard = !lazy && type !== 'range';\n  var event = lazy\n    ? 'change'\n    : type === 'range'\n      ? RANGE_TOKEN\n      : 'input';\n\n  var valueExpression = '$event.target.value';\n  if (trim) {\n    valueExpression = \"$event.target.value.trim()\";\n  }\n  if (number) {\n    valueExpression = \"_n(\" + valueExpression + \")\";\n  }\n\n  var code = genAssignmentCode(value, valueExpression);\n  if (needCompositionGuard) {\n    code = \"if($event.target.composing)return;\" + code;\n  }\n\n  addProp(el, 'value', (\"(\" + value + \")\"));\n  addHandler(el, event, code, null, true);\n  if (trim || number || type === 'number') {\n    addHandler(el, 'blur', '$forceUpdate()');\n  }\n}\n\n/*  */\n\n// normalize v-model event tokens that can only be determined at runtime.\n// it's important to place the event as the first in the array because\n// the whole point is ensuring the v-model callback gets called before\n// user-attached handlers.\nfunction normalizeEvents (on) {\n  var event;\n  /* istanbul ignore if */\n  if (isDef(on[RANGE_TOKEN])) {\n    // IE input[type=range] only supports `change` event\n    event = isIE ? 'change' : 'input';\n    on[event] = [].concat(on[RANGE_TOKEN], on[event] || []);\n    delete on[RANGE_TOKEN];\n  }\n  if (isDef(on[CHECKBOX_RADIO_TOKEN])) {\n    // Chrome fires microtasks in between click/change, leads to #4521\n    event = isChrome ? 'click' : 'change';\n    on[event] = [].concat(on[CHECKBOX_RADIO_TOKEN], on[event] || []);\n    delete on[CHECKBOX_RADIO_TOKEN];\n  }\n}\n\nvar target$1;\n\nfunction add$1 (\n  event,\n  handler,\n  once$$1,\n  capture,\n  passive\n) {\n  if (once$$1) {\n    var oldHandler = handler;\n    var _target = target$1; // save current target element in closure\n    handler = function (ev) {\n      var res = arguments.length === 1\n        ? oldHandler(ev)\n        : oldHandler.apply(null, arguments);\n      if (res !== null) {\n        remove$2(event, handler, capture, _target);\n      }\n    };\n  }\n  target$1.addEventListener(\n    event,\n    handler,\n    supportsPassive\n      ? { capture: capture, passive: passive }\n      : capture\n  );\n}\n\nfunction remove$2 (\n  event,\n  handler,\n  capture,\n  _target\n) {\n  (_target || target$1).removeEventListener(event, handler, capture);\n}\n\nfunction updateDOMListeners (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) {\n    return\n  }\n  var on = vnode.data.on || {};\n  var oldOn = oldVnode.data.on || {};\n  target$1 = vnode.elm;\n  normalizeEvents(on);\n  updateListeners(on, oldOn, add$1, remove$2, vnode.context);\n}\n\nvar events = {\n  create: updateDOMListeners,\n  update: updateDOMListeners\n};\n\n/*  */\n\nfunction updateDOMProps (oldVnode, vnode) {\n  if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {\n    return\n  }\n  var key, cur;\n  var elm = vnode.elm;\n  var oldProps = oldVnode.data.domProps || {};\n  var props = vnode.data.domProps || {};\n  // clone observed objects, as the user probably wants to mutate it\n  if (isDef(props.__ob__)) {\n    props = vnode.data.domProps = extend({}, props);\n  }\n\n  for (key in oldProps) {\n    if (isUndef(props[key])) {\n      elm[key] = '';\n    }\n  }\n  for (key in props) {\n    cur = props[key];\n    // ignore children if the node has textContent or innerHTML,\n    // as these will throw away existing DOM nodes and cause removal errors\n    // on subsequent patches (#3360)\n    if (key === 'textContent' || key === 'innerHTML') {\n      if (vnode.children) { vnode.children.length = 0; }\n      if (cur === oldProps[key]) { continue }\n    }\n\n    if (key === 'value') {\n      // store value as _value as well since\n      // non-string values will be stringified\n      elm._value = cur;\n      // avoid resetting cursor position when value is the same\n      var strCur = cur == null ? '' : String(cur);\n      if (shouldUpdateValue(elm, vnode, strCur)) {\n        elm.value = strCur;\n      }\n    } else {\n      elm[key] = cur;\n    }\n  }\n}\n\n// check platforms/web/util/attrs.js acceptValue\n\n\nfunction shouldUpdateValue (\n  elm,\n  vnode,\n  checkVal\n) {\n  return (!elm.composing && (\n    vnode.tag === 'option' ||\n    isDirty(elm, checkVal) ||\n    isInputChanged(elm, checkVal)\n  ))\n}\n\nfunction isDirty (elm, checkVal) {\n  // return true when textbox (.number and .trim) loses focus and its value is not equal to the updated value\n  return document.activeElement !== elm && elm.value !== checkVal\n}\n\nfunction isInputChanged (elm, newVal) {\n  var value = elm.value;\n  var modifiers = elm._vModifiers; // injected by v-model runtime\n  if ((isDef(modifiers) && modifiers.number) || elm.type === 'number') {\n    return toNumber(value) !== toNumber(newVal)\n  }\n  if (isDef(modifiers) && modifiers.trim) {\n    return value.trim() !== newVal.trim()\n  }\n  return value !== newVal\n}\n\nvar domProps = {\n  create: updateDOMProps,\n  update: updateDOMProps\n};\n\n/*  */\n\nvar parseStyleText = cached(function (cssText) {\n  var res = {};\n  var listDelimiter = /;(?![^(]*\\))/g;\n  var propertyDelimiter = /:(.+)/;\n  cssText.split(listDelimiter).forEach(function (item) {\n    if (item) {\n      var tmp = item.split(propertyDelimiter);\n      tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());\n    }\n  });\n  return res\n});\n\n// merge static and dynamic style data on the same vnode\nfunction normalizeStyleData (data) {\n  var style = normalizeStyleBinding(data.style);\n  // static style is pre-processed into an object during compilation\n  // and is always a fresh object, so it's safe to merge into it\n  return data.staticStyle\n    ? extend(data.staticStyle, style)\n    : style\n}\n\n// normalize possible array / string values into Object\nfunction normalizeStyleBinding (bindingStyle) {\n  if (Array.isArray(bindingStyle)) {\n    return toObject(bindingStyle)\n  }\n  if (typeof bindingStyle === 'string') {\n    return parseStyleText(bindingStyle)\n  }\n  return bindingStyle\n}\n\n/**\n * parent component style should be after child's\n * so that parent component's style could override it\n */\nfunction getStyle (vnode, checkChild) {\n  var res = {};\n  var styleData;\n\n  if (checkChild) {\n    var childNode = vnode;\n    while (childNode.componentInstance) {\n      childNode = childNode.componentInstance._vnode;\n      if (childNode.data && (styleData = normalizeStyleData(childNode.data))) {\n        extend(res, styleData);\n      }\n    }\n  }\n\n  if ((styleData = normalizeStyleData(vnode.data))) {\n    extend(res, styleData);\n  }\n\n  var parentNode = vnode;\n  while ((parentNode = parentNode.parent)) {\n    if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {\n      extend(res, styleData);\n    }\n  }\n  return res\n}\n\n/*  */\n\nvar cssVarRE = /^--/;\nvar importantRE = /\\s*!important$/;\nvar setProp = function (el, name, val) {\n  /* istanbul ignore if */\n  if (cssVarRE.test(name)) {\n    el.style.setProperty(name, val);\n  } else if (importantRE.test(val)) {\n    el.style.setProperty(name, val.replace(importantRE, ''), 'important');\n  } else {\n    var normalizedName = normalize(name);\n    if (Array.isArray(val)) {\n      // Support values array created by autoprefixer, e.g.\n      // {display: [\"-webkit-box\", \"-ms-flexbox\", \"flex\"]}\n      // Set them one by one, and the browser will only set those it can recognize\n      for (var i = 0, len = val.length; i < len; i++) {\n        el.style[normalizedName] = val[i];\n      }\n    } else {\n      el.style[normalizedName] = val;\n    }\n  }\n};\n\nvar prefixes = ['Webkit', 'Moz', 'ms'];\n\nvar testEl;\nvar normalize = cached(function (prop) {\n  testEl = testEl || document.createElement('div');\n  prop = camelize(prop);\n  if (prop !== 'filter' && (prop in testEl.style)) {\n    return prop\n  }\n  var upper = prop.charAt(0).toUpperCase() + prop.slice(1);\n  for (var i = 0; i < prefixes.length; i++) {\n    var prefixed = prefixes[i] + upper;\n    if (prefixed in testEl.style) {\n      return prefixed\n    }\n  }\n});\n\nfunction updateStyle (oldVnode, vnode) {\n  var data = vnode.data;\n  var oldData = oldVnode.data;\n\n  if (isUndef(data.staticStyle) && isUndef(data.style) &&\n      isUndef(oldData.staticStyle) && isUndef(oldData.style)) {\n    return\n  }\n\n  var cur, name;\n  var el = vnode.elm;\n  var oldStaticStyle = oldData.staticStyle;\n  var oldStyleBinding = oldData.normalizedStyle || oldData.style || {};\n\n  // if static style exists, stylebinding already merged into it when doing normalizeStyleData\n  var oldStyle = oldStaticStyle || oldStyleBinding;\n\n  var style = normalizeStyleBinding(vnode.data.style) || {};\n\n  // store normalized style under a different key for next diff\n  // make sure to clone it if it's reactive, since the user likley wants\n  // to mutate it.\n  vnode.data.normalizedStyle = isDef(style.__ob__)\n    ? extend({}, style)\n    : style;\n\n  var newStyle = getStyle(vnode, true);\n\n  for (name in oldStyle) {\n    if (isUndef(newStyle[name])) {\n      setProp(el, name, '');\n    }\n  }\n  for (name in newStyle) {\n    cur = newStyle[name];\n    if (cur !== oldStyle[name]) {\n      // ie9 setting to null has no effect, must use empty string\n      setProp(el, name, cur == null ? '' : cur);\n    }\n  }\n}\n\nvar style = {\n  create: updateStyle,\n  update: updateStyle\n};\n\n/*  */\n\n/**\n * Add class with compatibility for SVG since classList is not supported on\n * SVG elements in IE\n */\nfunction addClass (el, cls) {\n  /* istanbul ignore if */\n  if (!cls || !(cls = cls.trim())) {\n    return\n  }\n\n  /* istanbul ignore else */\n  if (el.classList) {\n    if (cls.indexOf(' ') > -1) {\n      cls.split(/\\s+/).forEach(function (c) { return el.classList.add(c); });\n    } else {\n      el.classList.add(cls);\n    }\n  } else {\n    var cur = \" \" + (el.getAttribute('class') || '') + \" \";\n    if (cur.indexOf(' ' + cls + ' ') < 0) {\n      el.setAttribute('class', (cur + cls).trim());\n    }\n  }\n}\n\n/**\n * Remove class with compatibility for SVG since classList is not supported on\n * SVG elements in IE\n */\nfunction removeClass (el, cls) {\n  /* istanbul ignore if */\n  if (!cls || !(cls = cls.trim())) {\n    return\n  }\n\n  /* istanbul ignore else */\n  if (el.classList) {\n    if (cls.indexOf(' ') > -1) {\n      cls.split(/\\s+/).forEach(function (c) { return el.classList.remove(c); });\n    } else {\n      el.classList.remove(cls);\n    }\n  } else {\n    var cur = \" \" + (el.getAttribute('class') || '') + \" \";\n    var tar = ' ' + cls + ' ';\n    while (cur.indexOf(tar) >= 0) {\n      cur = cur.replace(tar, ' ');\n    }\n    el.setAttribute('class', cur.trim());\n  }\n}\n\n/*  */\n\nfunction resolveTransition (def$$1) {\n  if (!def$$1) {\n    return\n  }\n  /* istanbul ignore else */\n  if (typeof def$$1 === 'object') {\n    var res = {};\n    if (def$$1.css !== false) {\n      extend(res, autoCssTransition(def$$1.name || 'v'));\n    }\n    extend(res, def$$1);\n    return res\n  } else if (typeof def$$1 === 'string') {\n    return autoCssTransition(def$$1)\n  }\n}\n\nvar autoCssTransition = cached(function (name) {\n  return {\n    enterClass: (name + \"-enter\"),\n    enterToClass: (name + \"-enter-to\"),\n    enterActiveClass: (name + \"-enter-active\"),\n    leaveClass: (name + \"-leave\"),\n    leaveToClass: (name + \"-leave-to\"),\n    leaveActiveClass: (name + \"-leave-active\")\n  }\n});\n\nvar hasTransition = inBrowser && !isIE9;\nvar TRANSITION = 'transition';\nvar ANIMATION = 'animation';\n\n// Transition property/event sniffing\nvar transitionProp = 'transition';\nvar transitionEndEvent = 'transitionend';\nvar animationProp = 'animation';\nvar animationEndEvent = 'animationend';\nif (hasTransition) {\n  /* istanbul ignore if */\n  if (window.ontransitionend === undefined &&\n    window.onwebkittransitionend !== undefined) {\n    transitionProp = 'WebkitTransition';\n    transitionEndEvent = 'webkitTransitionEnd';\n  }\n  if (window.onanimationend === undefined &&\n    window.onwebkitanimationend !== undefined) {\n    animationProp = 'WebkitAnimation';\n    animationEndEvent = 'webkitAnimationEnd';\n  }\n}\n\n// binding to window is necessary to make hot reload work in IE in strict mode\nvar raf = inBrowser && window.requestAnimationFrame\n  ? window.requestAnimationFrame.bind(window)\n  : setTimeout;\n\nfunction nextFrame (fn) {\n  raf(function () {\n    raf(fn);\n  });\n}\n\nfunction addTransitionClass (el, cls) {\n  (el._transitionClasses || (el._transitionClasses = [])).push(cls);\n  addClass(el, cls);\n}\n\nfunction removeTransitionClass (el, cls) {\n  if (el._transitionClasses) {\n    remove(el._transitionClasses, cls);\n  }\n  removeClass(el, cls);\n}\n\nfunction whenTransitionEnds (\n  el,\n  expectedType,\n  cb\n) {\n  var ref = getTransitionInfo(el, expectedType);\n  var type = ref.type;\n  var timeout = ref.timeout;\n  var propCount = ref.propCount;\n  if (!type) { return cb() }\n  var event = type === TRANSITION ? transitionEndEvent : animationEndEvent;\n  var ended = 0;\n  var end = function () {\n    el.removeEventListener(event, onEnd);\n    cb();\n  };\n  var onEnd = function (e) {\n    if (e.target === el) {\n      if (++ended >= propCount) {\n        end();\n      }\n    }\n  };\n  setTimeout(function () {\n    if (ended < propCount) {\n      end();\n    }\n  }, timeout + 1);\n  el.addEventListener(event, onEnd);\n}\n\nvar transformRE = /\\b(transform|all)(,|$)/;\n\nfunction getTransitionInfo (el, expectedType) {\n  var styles = window.getComputedStyle(el);\n  var transitionDelays = styles[transitionProp + 'Delay'].split(', ');\n  var transitionDurations = styles[transitionProp + 'Duration'].split(', ');\n  var transitionTimeout = getTimeout(transitionDelays, transitionDurations);\n  var animationDelays = styles[animationProp + 'Delay'].split(', ');\n  var animationDurations = styles[animationProp + 'Duration'].split(', ');\n  var animationTimeout = getTimeout(animationDelays, animationDurations);\n\n  var type;\n  var timeout = 0;\n  var propCount = 0;\n  /* istanbul ignore if */\n  if (expectedType === TRANSITION) {\n    if (transitionTimeout > 0) {\n      type = TRANSITION;\n      timeout = transitionTimeout;\n      propCount = transitionDurations.length;\n    }\n  } else if (expectedType === ANIMATION) {\n    if (animationTimeout > 0) {\n      type = ANIMATION;\n      timeout = animationTimeout;\n      propCount = animationDurations.length;\n    }\n  } else {\n    timeout = Math.max(transitionTimeout, animationTimeout);\n    type = timeout > 0\n      ? transitionTimeout > animationTimeout\n        ? TRANSITION\n        : ANIMATION\n      : null;\n    propCount = type\n      ? type === TRANSITION\n        ? transitionDurations.length\n        : animationDurations.length\n      : 0;\n  }\n  var hasTransform =\n    type === TRANSITION &&\n    transformRE.test(styles[transitionProp + 'Property']);\n  return {\n    type: type,\n    timeout: timeout,\n    propCount: propCount,\n    hasTransform: hasTransform\n  }\n}\n\nfunction getTimeout (delays, durations) {\n  /* istanbul ignore next */\n  while (delays.length < durations.length) {\n    delays = delays.concat(delays);\n  }\n\n  return Math.max.apply(null, durations.map(function (d, i) {\n    return toMs(d) + toMs(delays[i])\n  }))\n}\n\nfunction toMs (s) {\n  return Number(s.slice(0, -1)) * 1000\n}\n\n/*  */\n\nfunction enter (vnode, toggleDisplay) {\n  var el = vnode.elm;\n\n  // call leave callback now\n  if (isDef(el._leaveCb)) {\n    el._leaveCb.cancelled = true;\n    el._leaveCb();\n  }\n\n  var data = resolveTransition(vnode.data.transition);\n  if (isUndef(data)) {\n    return\n  }\n\n  /* istanbul ignore if */\n  if (isDef(el._enterCb) || el.nodeType !== 1) {\n    return\n  }\n\n  var ref = (data);\n  var css = ref.css;\n  var type = ref.type;\n  var enterClass = ref.enterClass;\n  var enterToClass = ref.enterToClass;\n  var enterActiveClass = ref.enterActiveClass;\n  var appearClass = ref.appearClass;\n  var appearToClass = ref.appearToClass;\n  var appearActiveClass = ref.appearActiveClass;\n  var beforeEnter = ref.beforeEnter;\n  var enter = ref.enter;\n  var afterEnter = ref.afterEnter;\n  var enterCancelled = ref.enterCancelled;\n  var beforeAppear = ref.beforeAppear;\n  var appear = ref.appear;\n  var afterAppear = ref.afterAppear;\n  var appearCancelled = ref.appearCancelled;\n  var duration = ref.duration;\n\n  // activeInstance will always be the <transition> component managing this\n  // transition. One edge case to check is when the <transition> is placed\n  // as the root node of a child component. In that case we need to check\n  // <transition>'s parent for appear check.\n  var context = activeInstance;\n  var transitionNode = activeInstance.$vnode;\n  while (transitionNode && transitionNode.parent) {\n    transitionNode = transitionNode.parent;\n    context = transitionNode.context;\n  }\n\n  var isAppear = !context._isMounted || !vnode.isRootInsert;\n\n  if (isAppear && !appear && appear !== '') {\n    return\n  }\n\n  var startClass = isAppear && appearClass\n    ? appearClass\n    : enterClass;\n  var activeClass = isAppear && appearActiveClass\n    ? appearActiveClass\n    : enterActiveClass;\n  var toClass = isAppear && appearToClass\n    ? appearToClass\n    : enterToClass;\n\n  var beforeEnterHook = isAppear\n    ? (beforeAppear || beforeEnter)\n    : beforeEnter;\n  var enterHook = isAppear\n    ? (typeof appear === 'function' ? appear : enter)\n    : enter;\n  var afterEnterHook = isAppear\n    ? (afterAppear || afterEnter)\n    : afterEnter;\n  var enterCancelledHook = isAppear\n    ? (appearCancelled || enterCancelled)\n    : enterCancelled;\n\n  var explicitEnterDuration = toNumber(\n    isObject(duration)\n      ? duration.enter\n      : duration\n  );\n\n  if (\"development\" !== 'production' && explicitEnterDuration != null) {\n    checkDuration(explicitEnterDuration, 'enter', vnode);\n  }\n\n  var expectsCSS = css !== false && !isIE9;\n  var userWantsControl = getHookArgumentsLength(enterHook);\n\n  var cb = el._enterCb = once(function () {\n    if (expectsCSS) {\n      removeTransitionClass(el, toClass);\n      removeTransitionClass(el, activeClass);\n    }\n    if (cb.cancelled) {\n      if (expectsCSS) {\n        removeTransitionClass(el, startClass);\n      }\n      enterCancelledHook && enterCancelledHook(el);\n    } else {\n      afterEnterHook && afterEnterHook(el);\n    }\n    el._enterCb = null;\n  });\n\n  if (!vnode.data.show) {\n    // remove pending leave element on enter by injecting an insert hook\n    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', function () {\n      var parent = el.parentNode;\n      var pendingNode = parent && parent._pending && parent._pending[vnode.key];\n      if (pendingNode &&\n          pendingNode.tag === vnode.tag &&\n          pendingNode.elm._leaveCb) {\n        pendingNode.elm._leaveCb();\n      }\n      enterHook && enterHook(el, cb);\n    });\n  }\n\n  // start enter transition\n  beforeEnterHook && beforeEnterHook(el);\n  if (expectsCSS) {\n    addTransitionClass(el, startClass);\n    addTransitionClass(el, activeClass);\n    nextFrame(function () {\n      addTransitionClass(el, toClass);\n      removeTransitionClass(el, startClass);\n      if (!cb.cancelled && !userWantsControl) {\n        if (isValidDuration(explicitEnterDuration)) {\n          setTimeout(cb, explicitEnterDuration);\n        } else {\n          whenTransitionEnds(el, type, cb);\n        }\n      }\n    });\n  }\n\n  if (vnode.data.show) {\n    toggleDisplay && toggleDisplay();\n    enterHook && enterHook(el, cb);\n  }\n\n  if (!expectsCSS && !userWantsControl) {\n    cb();\n  }\n}\n\nfunction leave (vnode, rm) {\n  var el = vnode.elm;\n\n  // call enter callback now\n  if (isDef(el._enterCb)) {\n    el._enterCb.cancelled = true;\n    el._enterCb();\n  }\n\n  var data = resolveTransition(vnode.data.transition);\n  if (isUndef(data)) {\n    return rm()\n  }\n\n  /* istanbul ignore if */\n  if (isDef(el._leaveCb) || el.nodeType !== 1) {\n    return\n  }\n\n  var ref = (data);\n  var css = ref.css;\n  var type = ref.type;\n  var leaveClass = ref.leaveClass;\n  var leaveToClass = ref.leaveToClass;\n  var leaveActiveClass = ref.leaveActiveClass;\n  var beforeLeave = ref.beforeLeave;\n  var leave = ref.leave;\n  var afterLeave = ref.afterLeave;\n  var leaveCancelled = ref.leaveCancelled;\n  var delayLeave = ref.delayLeave;\n  var duration = ref.duration;\n\n  var expectsCSS = css !== false && !isIE9;\n  var userWantsControl = getHookArgumentsLength(leave);\n\n  var explicitLeaveDuration = toNumber(\n    isObject(duration)\n      ? duration.leave\n      : duration\n  );\n\n  if (\"development\" !== 'production' && explicitLeaveDuration != null) {\n    checkDuration(explicitLeaveDuration, 'leave', vnode);\n  }\n\n  var cb = el._leaveCb = once(function () {\n    if (el.parentNode && el.parentNode._pending) {\n      el.parentNode._pending[vnode.key] = null;\n    }\n    if (expectsCSS) {\n      removeTransitionClass(el, leaveToClass);\n      removeTransitionClass(el, leaveActiveClass);\n    }\n    if (cb.cancelled) {\n      if (expectsCSS) {\n        removeTransitionClass(el, leaveClass);\n      }\n      leaveCancelled && leaveCancelled(el);\n    } else {\n      rm();\n      afterLeave && afterLeave(el);\n    }\n    el._leaveCb = null;\n  });\n\n  if (delayLeave) {\n    delayLeave(performLeave);\n  } else {\n    performLeave();\n  }\n\n  function performLeave () {\n    // the delayed leave may have already been cancelled\n    if (cb.cancelled) {\n      return\n    }\n    // record leaving element\n    if (!vnode.data.show) {\n      (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode;\n    }\n    beforeLeave && beforeLeave(el);\n    if (expectsCSS) {\n      addTransitionClass(el, leaveClass);\n      addTransitionClass(el, leaveActiveClass);\n      nextFrame(function () {\n        addTransitionClass(el, leaveToClass);\n        removeTransitionClass(el, leaveClass);\n        if (!cb.cancelled && !userWantsControl) {\n          if (isValidDuration(explicitLeaveDuration)) {\n            setTimeout(cb, explicitLeaveDuration);\n          } else {\n            whenTransitionEnds(el, type, cb);\n          }\n        }\n      });\n    }\n    leave && leave(el, cb);\n    if (!expectsCSS && !userWantsControl) {\n      cb();\n    }\n  }\n}\n\n// only used in dev mode\nfunction checkDuration (val, name, vnode) {\n  if (typeof val !== 'number') {\n    warn(\n      \"<transition> explicit \" + name + \" duration is not a valid number - \" +\n      \"got \" + (JSON.stringify(val)) + \".\",\n      vnode.context\n    );\n  } else if (isNaN(val)) {\n    warn(\n      \"<transition> explicit \" + name + \" duration is NaN - \" +\n      'the duration expression might be incorrect.',\n      vnode.context\n    );\n  }\n}\n\nfunction isValidDuration (val) {\n  return typeof val === 'number' && !isNaN(val)\n}\n\n/**\n * Normalize a transition hook's argument length. The hook may be:\n * - a merged hook (invoker) with the original in .fns\n * - a wrapped component method (check ._length)\n * - a plain function (.length)\n */\nfunction getHookArgumentsLength (fn) {\n  if (isUndef(fn)) {\n    return false\n  }\n  var invokerFns = fn.fns;\n  if (isDef(invokerFns)) {\n    // invoker\n    return getHookArgumentsLength(\n      Array.isArray(invokerFns)\n        ? invokerFns[0]\n        : invokerFns\n    )\n  } else {\n    return (fn._length || fn.length) > 1\n  }\n}\n\nfunction _enter (_, vnode) {\n  if (vnode.data.show !== true) {\n    enter(vnode);\n  }\n}\n\nvar transition = inBrowser ? {\n  create: _enter,\n  activate: _enter,\n  remove: function remove$$1 (vnode, rm) {\n    /* istanbul ignore else */\n    if (vnode.data.show !== true) {\n      leave(vnode, rm);\n    } else {\n      rm();\n    }\n  }\n} : {};\n\nvar platformModules = [\n  attrs,\n  klass,\n  events,\n  domProps,\n  style,\n  transition\n];\n\n/*  */\n\n// the directive module should be applied last, after all\n// built-in modules have been applied.\nvar modules = platformModules.concat(baseModules);\n\nvar patch = createPatchFunction({ nodeOps: nodeOps, modules: modules });\n\n/**\n * Not type checking this file because flow doesn't like attaching\n * properties to Elements.\n */\n\n/* istanbul ignore if */\nif (isIE9) {\n  // http://www.matts411.com/post/internet-explorer-9-oninput/\n  document.addEventListener('selectionchange', function () {\n    var el = document.activeElement;\n    if (el && el.vmodel) {\n      trigger(el, 'input');\n    }\n  });\n}\n\nvar model$1 = {\n  inserted: function inserted (el, binding, vnode) {\n    if (vnode.tag === 'select') {\n      var cb = function () {\n        setSelected(el, binding, vnode.context);\n      };\n      cb();\n      /* istanbul ignore if */\n      if (isIE || isEdge) {\n        setTimeout(cb, 0);\n      }\n    } else if (vnode.tag === 'textarea' || el.type === 'text' || el.type === 'password') {\n      el._vModifiers = binding.modifiers;\n      if (!binding.modifiers.lazy) {\n        // Safari < 10.2 & UIWebView doesn't fire compositionend when\n        // switching focus before confirming composition choice\n        // this also fixes the issue where some browsers e.g. iOS Chrome\n        // fires \"change\" instead of \"input\" on autocomplete.\n        el.addEventListener('change', onCompositionEnd);\n        if (!isAndroid) {\n          el.addEventListener('compositionstart', onCompositionStart);\n          el.addEventListener('compositionend', onCompositionEnd);\n        }\n        /* istanbul ignore if */\n        if (isIE9) {\n          el.vmodel = true;\n        }\n      }\n    }\n  },\n  componentUpdated: function componentUpdated (el, binding, vnode) {\n    if (vnode.tag === 'select') {\n      setSelected(el, binding, vnode.context);\n      // in case the options rendered by v-for have changed,\n      // it's possible that the value is out-of-sync with the rendered options.\n      // detect such cases and filter out values that no longer has a matching\n      // option in the DOM.\n      var needReset = el.multiple\n        ? binding.value.some(function (v) { return hasNoMatchingOption(v, el.options); })\n        : binding.value !== binding.oldValue && hasNoMatchingOption(binding.value, el.options);\n      if (needReset) {\n        trigger(el, 'change');\n      }\n    }\n  }\n};\n\nfunction setSelected (el, binding, vm) {\n  var value = binding.value;\n  var isMultiple = el.multiple;\n  if (isMultiple && !Array.isArray(value)) {\n    \"development\" !== 'production' && warn(\n      \"<select multiple v-model=\\\"\" + (binding.expression) + \"\\\"> \" +\n      \"expects an Array value for its binding, but got \" + (Object.prototype.toString.call(value).slice(8, -1)),\n      vm\n    );\n    return\n  }\n  var selected, option;\n  for (var i = 0, l = el.options.length; i < l; i++) {\n    option = el.options[i];\n    if (isMultiple) {\n      selected = looseIndexOf(value, getValue(option)) > -1;\n      if (option.selected !== selected) {\n        option.selected = selected;\n      }\n    } else {\n      if (looseEqual(getValue(option), value)) {\n        if (el.selectedIndex !== i) {\n          el.selectedIndex = i;\n        }\n        return\n      }\n    }\n  }\n  if (!isMultiple) {\n    el.selectedIndex = -1;\n  }\n}\n\nfunction hasNoMatchingOption (value, options) {\n  for (var i = 0, l = options.length; i < l; i++) {\n    if (looseEqual(getValue(options[i]), value)) {\n      return false\n    }\n  }\n  return true\n}\n\nfunction getValue (option) {\n  return '_value' in option\n    ? option._value\n    : option.value\n}\n\nfunction onCompositionStart (e) {\n  e.target.composing = true;\n}\n\nfunction onCompositionEnd (e) {\n  e.target.composing = false;\n  trigger(e.target, 'input');\n}\n\nfunction trigger (el, type) {\n  var e = document.createEvent('HTMLEvents');\n  e.initEvent(type, true, true);\n  el.dispatchEvent(e);\n}\n\n/*  */\n\n// recursively search for possible transition defined inside the component root\nfunction locateNode (vnode) {\n  return vnode.componentInstance && (!vnode.data || !vnode.data.transition)\n    ? locateNode(vnode.componentInstance._vnode)\n    : vnode\n}\n\nvar show = {\n  bind: function bind (el, ref, vnode) {\n    var value = ref.value;\n\n    vnode = locateNode(vnode);\n    var transition = vnode.data && vnode.data.transition;\n    var originalDisplay = el.__vOriginalDisplay =\n      el.style.display === 'none' ? '' : el.style.display;\n    if (value && transition && !isIE9) {\n      vnode.data.show = true;\n      enter(vnode, function () {\n        el.style.display = originalDisplay;\n      });\n    } else {\n      el.style.display = value ? originalDisplay : 'none';\n    }\n  },\n\n  update: function update (el, ref, vnode) {\n    var value = ref.value;\n    var oldValue = ref.oldValue;\n\n    /* istanbul ignore if */\n    if (value === oldValue) { return }\n    vnode = locateNode(vnode);\n    var transition = vnode.data && vnode.data.transition;\n    if (transition && !isIE9) {\n      vnode.data.show = true;\n      if (value) {\n        enter(vnode, function () {\n          el.style.display = el.__vOriginalDisplay;\n        });\n      } else {\n        leave(vnode, function () {\n          el.style.display = 'none';\n        });\n      }\n    } else {\n      el.style.display = value ? el.__vOriginalDisplay : 'none';\n    }\n  },\n\n  unbind: function unbind (\n    el,\n    binding,\n    vnode,\n    oldVnode,\n    isDestroy\n  ) {\n    if (!isDestroy) {\n      el.style.display = el.__vOriginalDisplay;\n    }\n  }\n};\n\nvar platformDirectives = {\n  model: model$1,\n  show: show\n};\n\n/*  */\n\n// Provides transition support for a single element/component.\n// supports transition mode (out-in / in-out)\n\nvar transitionProps = {\n  name: String,\n  appear: Boolean,\n  css: Boolean,\n  mode: String,\n  type: String,\n  enterClass: String,\n  leaveClass: String,\n  enterToClass: String,\n  leaveToClass: String,\n  enterActiveClass: String,\n  leaveActiveClass: String,\n  appearClass: String,\n  appearActiveClass: String,\n  appearToClass: String,\n  duration: [Number, String, Object]\n};\n\n// in case the child is also an abstract component, e.g. <keep-alive>\n// we want to recursively retrieve the real component to be rendered\nfunction getRealChild (vnode) {\n  var compOptions = vnode && vnode.componentOptions;\n  if (compOptions && compOptions.Ctor.options.abstract) {\n    return getRealChild(getFirstComponentChild(compOptions.children))\n  } else {\n    return vnode\n  }\n}\n\nfunction extractTransitionData (comp) {\n  var data = {};\n  var options = comp.$options;\n  // props\n  for (var key in options.propsData) {\n    data[key] = comp[key];\n  }\n  // events.\n  // extract listeners and pass them directly to the transition methods\n  var listeners = options._parentListeners;\n  for (var key$1 in listeners) {\n    data[camelize(key$1)] = listeners[key$1];\n  }\n  return data\n}\n\nfunction placeholder (h, rawChild) {\n  if (/\\d-keep-alive$/.test(rawChild.tag)) {\n    return h('keep-alive', {\n      props: rawChild.componentOptions.propsData\n    })\n  }\n}\n\nfunction hasParentTransition (vnode) {\n  while ((vnode = vnode.parent)) {\n    if (vnode.data.transition) {\n      return true\n    }\n  }\n}\n\nfunction isSameChild (child, oldChild) {\n  return oldChild.key === child.key && oldChild.tag === child.tag\n}\n\nvar Transition = {\n  name: 'transition',\n  props: transitionProps,\n  abstract: true,\n\n  render: function render (h) {\n    var this$1 = this;\n\n    var children = this.$slots.default;\n    if (!children) {\n      return\n    }\n\n    // filter out text nodes (possible whitespaces)\n    children = children.filter(function (c) { return c.tag; });\n    /* istanbul ignore if */\n    if (!children.length) {\n      return\n    }\n\n    // warn multiple elements\n    if (\"development\" !== 'production' && children.length > 1) {\n      warn(\n        '<transition> can only be used on a single element. Use ' +\n        '<transition-group> for lists.',\n        this.$parent\n      );\n    }\n\n    var mode = this.mode;\n\n    // warn invalid mode\n    if (\"development\" !== 'production' &&\n        mode && mode !== 'in-out' && mode !== 'out-in') {\n      warn(\n        'invalid <transition> mode: ' + mode,\n        this.$parent\n      );\n    }\n\n    var rawChild = children[0];\n\n    // if this is a component root node and the component's\n    // parent container node also has transition, skip.\n    if (hasParentTransition(this.$vnode)) {\n      return rawChild\n    }\n\n    // apply transition data to child\n    // use getRealChild() to ignore abstract components e.g. keep-alive\n    var child = getRealChild(rawChild);\n    /* istanbul ignore if */\n    if (!child) {\n      return rawChild\n    }\n\n    if (this._leaving) {\n      return placeholder(h, rawChild)\n    }\n\n    // ensure a key that is unique to the vnode type and to this transition\n    // component instance. This key will be used to remove pending leaving nodes\n    // during entering.\n    var id = \"__transition-\" + (this._uid) + \"-\";\n    child.key = child.key == null\n      ? id + child.tag\n      : isPrimitive(child.key)\n        ? (String(child.key).indexOf(id) === 0 ? child.key : id + child.key)\n        : child.key;\n\n    var data = (child.data || (child.data = {})).transition = extractTransitionData(this);\n    var oldRawChild = this._vnode;\n    var oldChild = getRealChild(oldRawChild);\n\n    // mark v-show\n    // so that the transition module can hand over the control to the directive\n    if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {\n      child.data.show = true;\n    }\n\n    if (oldChild && oldChild.data && !isSameChild(child, oldChild)) {\n      // replace old child transition data with fresh one\n      // important for dynamic transitions!\n      var oldData = oldChild && (oldChild.data.transition = extend({}, data));\n      // handle transition mode\n      if (mode === 'out-in') {\n        // return placeholder node and queue update when leave finishes\n        this._leaving = true;\n        mergeVNodeHook(oldData, 'afterLeave', function () {\n          this$1._leaving = false;\n          this$1.$forceUpdate();\n        });\n        return placeholder(h, rawChild)\n      } else if (mode === 'in-out') {\n        var delayedLeave;\n        var performLeave = function () { delayedLeave(); };\n        mergeVNodeHook(data, 'afterEnter', performLeave);\n        mergeVNodeHook(data, 'enterCancelled', performLeave);\n        mergeVNodeHook(oldData, 'delayLeave', function (leave) { delayedLeave = leave; });\n      }\n    }\n\n    return rawChild\n  }\n};\n\n/*  */\n\n// Provides transition support for list items.\n// supports move transitions using the FLIP technique.\n\n// Because the vdom's children update algorithm is \"unstable\" - i.e.\n// it doesn't guarantee the relative positioning of removed elements,\n// we force transition-group to update its children into two passes:\n// in the first pass, we remove all nodes that need to be removed,\n// triggering their leaving transition; in the second pass, we insert/move\n// into the final desired state. This way in the second pass removed\n// nodes will remain where they should be.\n\nvar props = extend({\n  tag: String,\n  moveClass: String\n}, transitionProps);\n\ndelete props.mode;\n\nvar TransitionGroup = {\n  props: props,\n\n  render: function render (h) {\n    var tag = this.tag || this.$vnode.data.tag || 'span';\n    var map = Object.create(null);\n    var prevChildren = this.prevChildren = this.children;\n    var rawChildren = this.$slots.default || [];\n    var children = this.children = [];\n    var transitionData = extractTransitionData(this);\n\n    for (var i = 0; i < rawChildren.length; i++) {\n      var c = rawChildren[i];\n      if (c.tag) {\n        if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {\n          children.push(c);\n          map[c.key] = c\n          ;(c.data || (c.data = {})).transition = transitionData;\n        } else {\n          var opts = c.componentOptions;\n          var name = opts ? (opts.Ctor.options.name || opts.tag || '') : c.tag;\n          warn((\"<transition-group> children must be keyed: <\" + name + \">\"));\n        }\n      }\n    }\n\n    if (prevChildren) {\n      var kept = [];\n      var removed = [];\n      for (var i$1 = 0; i$1 < prevChildren.length; i$1++) {\n        var c$1 = prevChildren[i$1];\n        c$1.data.transition = transitionData;\n        c$1.data.pos = c$1.elm.getBoundingClientRect();\n        if (map[c$1.key]) {\n          kept.push(c$1);\n        } else {\n          removed.push(c$1);\n        }\n      }\n      this.kept = h(tag, null, kept);\n      this.removed = removed;\n    }\n\n    return h(tag, null, children)\n  },\n\n  beforeUpdate: function beforeUpdate () {\n    // force removing pass\n    this.__patch__(\n      this._vnode,\n      this.kept,\n      false, // hydrating\n      true // removeOnly (!important, avoids unnecessary moves)\n    );\n    this._vnode = this.kept;\n  },\n\n  updated: function updated () {\n    var children = this.prevChildren;\n    var moveClass = this.moveClass || ((this.name || 'v') + '-move');\n    if (!children.length || !this.hasMove(children[0].elm, moveClass)) {\n      return\n    }\n\n    // we divide the work into three loops to avoid mixing DOM reads and writes\n    // in each iteration - which helps prevent layout thrashing.\n    children.forEach(callPendingCbs);\n    children.forEach(recordPosition);\n    children.forEach(applyTranslation);\n\n    // force reflow to put everything in position\n    var body = document.body;\n    var f = body.offsetHeight; // eslint-disable-line\n\n    children.forEach(function (c) {\n      if (c.data.moved) {\n        var el = c.elm;\n        var s = el.style;\n        addTransitionClass(el, moveClass);\n        s.transform = s.WebkitTransform = s.transitionDuration = '';\n        el.addEventListener(transitionEndEvent, el._moveCb = function cb (e) {\n          if (!e || /transform$/.test(e.propertyName)) {\n            el.removeEventListener(transitionEndEvent, cb);\n            el._moveCb = null;\n            removeTransitionClass(el, moveClass);\n          }\n        });\n      }\n    });\n  },\n\n  methods: {\n    hasMove: function hasMove (el, moveClass) {\n      /* istanbul ignore if */\n      if (!hasTransition) {\n        return false\n      }\n      if (this._hasMove != null) {\n        return this._hasMove\n      }\n      // Detect whether an element with the move class applied has\n      // CSS transitions. Since the element may be inside an entering\n      // transition at this very moment, we make a clone of it and remove\n      // all other transition classes applied to ensure only the move class\n      // is applied.\n      var clone = el.cloneNode();\n      if (el._transitionClasses) {\n        el._transitionClasses.forEach(function (cls) { removeClass(clone, cls); });\n      }\n      addClass(clone, moveClass);\n      clone.style.display = 'none';\n      this.$el.appendChild(clone);\n      var info = getTransitionInfo(clone);\n      this.$el.removeChild(clone);\n      return (this._hasMove = info.hasTransform)\n    }\n  }\n};\n\nfunction callPendingCbs (c) {\n  /* istanbul ignore if */\n  if (c.elm._moveCb) {\n    c.elm._moveCb();\n  }\n  /* istanbul ignore if */\n  if (c.elm._enterCb) {\n    c.elm._enterCb();\n  }\n}\n\nfunction recordPosition (c) {\n  c.data.newPos = c.elm.getBoundingClientRect();\n}\n\nfunction applyTranslation (c) {\n  var oldPos = c.data.pos;\n  var newPos = c.data.newPos;\n  var dx = oldPos.left - newPos.left;\n  var dy = oldPos.top - newPos.top;\n  if (dx || dy) {\n    c.data.moved = true;\n    var s = c.elm.style;\n    s.transform = s.WebkitTransform = \"translate(\" + dx + \"px,\" + dy + \"px)\";\n    s.transitionDuration = '0s';\n  }\n}\n\nvar platformComponents = {\n  Transition: Transition,\n  TransitionGroup: TransitionGroup\n};\n\n/*  */\n\n// install platform specific utils\nVue$3.config.mustUseProp = mustUseProp;\nVue$3.config.isReservedTag = isReservedTag;\nVue$3.config.isReservedAttr = isReservedAttr;\nVue$3.config.getTagNamespace = getTagNamespace;\nVue$3.config.isUnknownElement = isUnknownElement;\n\n// install platform runtime directives & components\nextend(Vue$3.options.directives, platformDirectives);\nextend(Vue$3.options.components, platformComponents);\n\n// install platform patch function\nVue$3.prototype.__patch__ = inBrowser ? patch : noop;\n\n// public mount method\nVue$3.prototype.$mount = function (\n  el,\n  hydrating\n) {\n  el = el && inBrowser ? query(el) : undefined;\n  return mountComponent(this, el, hydrating)\n};\n\n// devtools global hook\n/* istanbul ignore next */\nsetTimeout(function () {\n  if (config.devtools) {\n    if (devtools) {\n      devtools.emit('init', Vue$3);\n    } else if (\"development\" !== 'production' && isChrome) {\n      console[console.info ? 'info' : 'log'](\n        'Download the Vue Devtools extension for a better development experience:\\n' +\n        'https://github.com/vuejs/vue-devtools'\n      );\n    }\n  }\n  if (\"development\" !== 'production' &&\n      config.productionTip !== false &&\n      inBrowser && typeof console !== 'undefined') {\n    console[console.info ? 'info' : 'log'](\n      \"You are running Vue in development mode.\\n\" +\n      \"Make sure to turn on production mode when deploying for production.\\n\" +\n      \"See more tips at https://vuejs.org/guide/deployment.html\"\n    );\n  }\n}, 0);\n\n/*  */\n\n// check whether current browser encodes a char inside attribute values\nfunction shouldDecode (content, encoded) {\n  var div = document.createElement('div');\n  div.innerHTML = \"<div a=\\\"\" + content + \"\\\">\";\n  return div.innerHTML.indexOf(encoded) > 0\n}\n\n// #3663\n// IE encodes newlines inside attribute values while other browsers don't\nvar shouldDecodeNewlines = inBrowser ? shouldDecode('\\n', '&#10;') : false;\n\n/*  */\n\nvar isUnaryTag = makeMap(\n  'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +\n  'link,meta,param,source,track,wbr'\n);\n\n// Elements that you can, intentionally, leave open\n// (and which close themselves)\nvar canBeLeftOpenTag = makeMap(\n  'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'\n);\n\n// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3\n// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content\nvar isNonPhrasingTag = makeMap(\n  'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +\n  'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +\n  'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +\n  'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +\n  'title,tr,track'\n);\n\n/*  */\n\nvar decoder;\n\nfunction decode (html) {\n  decoder = decoder || document.createElement('div');\n  decoder.innerHTML = html;\n  return decoder.textContent\n}\n\n/**\n * Not type-checking this file because it's mostly vendor code.\n */\n\n/*!\n * HTML Parser By John Resig (ejohn.org)\n * Modified by Juriy \"kangax\" Zaytsev\n * Original code by Erik Arvidsson, Mozilla Public License\n * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js\n */\n\n// Regular Expressions for parsing tags and attributes\nvar singleAttrIdentifier = /([^\\s\"'<>/=]+)/;\nvar singleAttrAssign = /(?:=)/;\nvar singleAttrValues = [\n  // attr value double quotes\n  /\"([^\"]*)\"+/.source,\n  // attr value, single quotes\n  /'([^']*)'+/.source,\n  // attr value, no quotes\n  /([^\\s\"'=<>`]+)/.source\n];\nvar attribute = new RegExp(\n  '^\\\\s*' + singleAttrIdentifier.source +\n  '(?:\\\\s*(' + singleAttrAssign.source + ')' +\n  '\\\\s*(?:' + singleAttrValues.join('|') + '))?'\n);\n\n// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName\n// but for Vue templates we can enforce a simple charset\nvar ncname = '[a-zA-Z_][\\\\w\\\\-\\\\.]*';\nvar qnameCapture = '((?:' + ncname + '\\\\:)?' + ncname + ')';\nvar startTagOpen = new RegExp('^<' + qnameCapture);\nvar startTagClose = /^\\s*(\\/?)>/;\nvar endTag = new RegExp('^<\\\\/' + qnameCapture + '[^>]*>');\nvar doctype = /^<!DOCTYPE [^>]+>/i;\nvar comment = /^<!--/;\nvar conditionalComment = /^<!\\[/;\n\nvar IS_REGEX_CAPTURING_BROKEN = false;\n'x'.replace(/x(.)?/g, function (m, g) {\n  IS_REGEX_CAPTURING_BROKEN = g === '';\n});\n\n// Special Elements (can contain anything)\nvar isPlainTextElement = makeMap('script,style,textarea', true);\nvar reCache = {};\n\nvar decodingMap = {\n  '&lt;': '<',\n  '&gt;': '>',\n  '&quot;': '\"',\n  '&amp;': '&',\n  '&#10;': '\\n'\n};\nvar encodedAttr = /&(?:lt|gt|quot|amp);/g;\nvar encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10);/g;\n\nfunction decodeAttr (value, shouldDecodeNewlines) {\n  var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;\n  return value.replace(re, function (match) { return decodingMap[match]; })\n}\n\nfunction parseHTML (html, options) {\n  var stack = [];\n  var expectHTML = options.expectHTML;\n  var isUnaryTag$$1 = options.isUnaryTag || no;\n  var canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no;\n  var index = 0;\n  var last, lastTag;\n  while (html) {\n    last = html;\n    // Make sure we're not in a plaintext content element like script/style\n    if (!lastTag || !isPlainTextElement(lastTag)) {\n      var textEnd = html.indexOf('<');\n      if (textEnd === 0) {\n        // Comment:\n        if (comment.test(html)) {\n          var commentEnd = html.indexOf('-->');\n\n          if (commentEnd >= 0) {\n            advance(commentEnd + 3);\n            continue\n          }\n        }\n\n        // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment\n        if (conditionalComment.test(html)) {\n          var conditionalEnd = html.indexOf(']>');\n\n          if (conditionalEnd >= 0) {\n            advance(conditionalEnd + 2);\n            continue\n          }\n        }\n\n        // Doctype:\n        var doctypeMatch = html.match(doctype);\n        if (doctypeMatch) {\n          advance(doctypeMatch[0].length);\n          continue\n        }\n\n        // End tag:\n        var endTagMatch = html.match(endTag);\n        if (endTagMatch) {\n          var curIndex = index;\n          advance(endTagMatch[0].length);\n          parseEndTag(endTagMatch[1], curIndex, index);\n          continue\n        }\n\n        // Start tag:\n        var startTagMatch = parseStartTag();\n        if (startTagMatch) {\n          handleStartTag(startTagMatch);\n          continue\n        }\n      }\n\n      var text = (void 0), rest$1 = (void 0), next = (void 0);\n      if (textEnd >= 0) {\n        rest$1 = html.slice(textEnd);\n        while (\n          !endTag.test(rest$1) &&\n          !startTagOpen.test(rest$1) &&\n          !comment.test(rest$1) &&\n          !conditionalComment.test(rest$1)\n        ) {\n          // < in plain text, be forgiving and treat it as text\n          next = rest$1.indexOf('<', 1);\n          if (next < 0) { break }\n          textEnd += next;\n          rest$1 = html.slice(textEnd);\n        }\n        text = html.substring(0, textEnd);\n        advance(textEnd);\n      }\n\n      if (textEnd < 0) {\n        text = html;\n        html = '';\n      }\n\n      if (options.chars && text) {\n        options.chars(text);\n      }\n    } else {\n      var stackedTag = lastTag.toLowerCase();\n      var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\\\s\\\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));\n      var endTagLength = 0;\n      var rest = html.replace(reStackedTag, function (all, text, endTag) {\n        endTagLength = endTag.length;\n        if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {\n          text = text\n            .replace(/<!--([\\s\\S]*?)-->/g, '$1')\n            .replace(/<!\\[CDATA\\[([\\s\\S]*?)]]>/g, '$1');\n        }\n        if (options.chars) {\n          options.chars(text);\n        }\n        return ''\n      });\n      index += html.length - rest.length;\n      html = rest;\n      parseEndTag(stackedTag, index - endTagLength, index);\n    }\n\n    if (html === last) {\n      options.chars && options.chars(html);\n      if (\"development\" !== 'production' && !stack.length && options.warn) {\n        options.warn((\"Mal-formatted tag at end of template: \\\"\" + html + \"\\\"\"));\n      }\n      break\n    }\n  }\n\n  // Clean up any remaining tags\n  parseEndTag();\n\n  function advance (n) {\n    index += n;\n    html = html.substring(n);\n  }\n\n  function parseStartTag () {\n    var start = html.match(startTagOpen);\n    if (start) {\n      var match = {\n        tagName: start[1],\n        attrs: [],\n        start: index\n      };\n      advance(start[0].length);\n      var end, attr;\n      while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {\n        advance(attr[0].length);\n        match.attrs.push(attr);\n      }\n      if (end) {\n        match.unarySlash = end[1];\n        advance(end[0].length);\n        match.end = index;\n        return match\n      }\n    }\n  }\n\n  function handleStartTag (match) {\n    var tagName = match.tagName;\n    var unarySlash = match.unarySlash;\n\n    if (expectHTML) {\n      if (lastTag === 'p' && isNonPhrasingTag(tagName)) {\n        parseEndTag(lastTag);\n      }\n      if (canBeLeftOpenTag$$1(tagName) && lastTag === tagName) {\n        parseEndTag(tagName);\n      }\n    }\n\n    var unary = isUnaryTag$$1(tagName) || tagName === 'html' && lastTag === 'head' || !!unarySlash;\n\n    var l = match.attrs.length;\n    var attrs = new Array(l);\n    for (var i = 0; i < l; i++) {\n      var args = match.attrs[i];\n      // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778\n      if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('\"\"') === -1) {\n        if (args[3] === '') { delete args[3]; }\n        if (args[4] === '') { delete args[4]; }\n        if (args[5] === '') { delete args[5]; }\n      }\n      var value = args[3] || args[4] || args[5] || '';\n      attrs[i] = {\n        name: args[1],\n        value: decodeAttr(\n          value,\n          options.shouldDecodeNewlines\n        )\n      };\n    }\n\n    if (!unary) {\n      stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs });\n      lastTag = tagName;\n    }\n\n    if (options.start) {\n      options.start(tagName, attrs, unary, match.start, match.end);\n    }\n  }\n\n  function parseEndTag (tagName, start, end) {\n    var pos, lowerCasedTagName;\n    if (start == null) { start = index; }\n    if (end == null) { end = index; }\n\n    if (tagName) {\n      lowerCasedTagName = tagName.toLowerCase();\n    }\n\n    // Find the closest opened tag of the same type\n    if (tagName) {\n      for (pos = stack.length - 1; pos >= 0; pos--) {\n        if (stack[pos].lowerCasedTag === lowerCasedTagName) {\n          break\n        }\n      }\n    } else {\n      // If no tag name is provided, clean shop\n      pos = 0;\n    }\n\n    if (pos >= 0) {\n      // Close all the open elements, up the stack\n      for (var i = stack.length - 1; i >= pos; i--) {\n        if (\"development\" !== 'production' &&\n            (i > pos || !tagName) &&\n            options.warn) {\n          options.warn(\n            (\"tag <\" + (stack[i].tag) + \"> has no matching end tag.\")\n          );\n        }\n        if (options.end) {\n          options.end(stack[i].tag, start, end);\n        }\n      }\n\n      // Remove the open elements from the stack\n      stack.length = pos;\n      lastTag = pos && stack[pos - 1].tag;\n    } else if (lowerCasedTagName === 'br') {\n      if (options.start) {\n        options.start(tagName, [], true, start, end);\n      }\n    } else if (lowerCasedTagName === 'p') {\n      if (options.start) {\n        options.start(tagName, [], false, start, end);\n      }\n      if (options.end) {\n        options.end(tagName, start, end);\n      }\n    }\n  }\n}\n\n/*  */\n\nvar defaultTagRE = /\\{\\{((?:.|\\n)+?)\\}\\}/g;\nvar regexEscapeRE = /[-.*+?^${}()|[\\]\\/\\\\]/g;\n\nvar buildRegex = cached(function (delimiters) {\n  var open = delimiters[0].replace(regexEscapeRE, '\\\\$&');\n  var close = delimiters[1].replace(regexEscapeRE, '\\\\$&');\n  return new RegExp(open + '((?:.|\\\\n)+?)' + close, 'g')\n});\n\nfunction parseText (\n  text,\n  delimiters\n) {\n  var tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;\n  if (!tagRE.test(text)) {\n    return\n  }\n  var tokens = [];\n  var lastIndex = tagRE.lastIndex = 0;\n  var match, index;\n  while ((match = tagRE.exec(text))) {\n    index = match.index;\n    // push text token\n    if (index > lastIndex) {\n      tokens.push(JSON.stringify(text.slice(lastIndex, index)));\n    }\n    // tag token\n    var exp = parseFilters(match[1].trim());\n    tokens.push((\"_s(\" + exp + \")\"));\n    lastIndex = index + match[0].length;\n  }\n  if (lastIndex < text.length) {\n    tokens.push(JSON.stringify(text.slice(lastIndex)));\n  }\n  return tokens.join('+')\n}\n\n/*  */\n\nvar onRE = /^@|^v-on:/;\nvar dirRE = /^v-|^@|^:/;\nvar forAliasRE = /(.*?)\\s+(?:in|of)\\s+(.*)/;\nvar forIteratorRE = /\\((\\{[^}]*\\}|[^,]*),([^,]*)(?:,([^,]*))?\\)/;\n\nvar argRE = /:(.*)$/;\nvar bindRE = /^:|^v-bind:/;\nvar modifierRE = /\\.[^.]+/g;\n\nvar decodeHTMLCached = cached(decode);\n\n// configurable state\nvar warn$2;\nvar delimiters;\nvar transforms;\nvar preTransforms;\nvar postTransforms;\nvar platformIsPreTag;\nvar platformMustUseProp;\nvar platformGetTagNamespace;\n\n/**\n * Convert HTML string to AST.\n */\nfunction parse (\n  template,\n  options\n) {\n  warn$2 = options.warn || baseWarn;\n  platformGetTagNamespace = options.getTagNamespace || no;\n  platformMustUseProp = options.mustUseProp || no;\n  platformIsPreTag = options.isPreTag || no;\n  preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');\n  transforms = pluckModuleFunction(options.modules, 'transformNode');\n  postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');\n  delimiters = options.delimiters;\n\n  var stack = [];\n  var preserveWhitespace = options.preserveWhitespace !== false;\n  var root;\n  var currentParent;\n  var inVPre = false;\n  var inPre = false;\n  var warned = false;\n\n  function warnOnce (msg) {\n    if (!warned) {\n      warned = true;\n      warn$2(msg);\n    }\n  }\n\n  function endPre (element) {\n    // check pre state\n    if (element.pre) {\n      inVPre = false;\n    }\n    if (platformIsPreTag(element.tag)) {\n      inPre = false;\n    }\n  }\n\n  parseHTML(template, {\n    warn: warn$2,\n    expectHTML: options.expectHTML,\n    isUnaryTag: options.isUnaryTag,\n    canBeLeftOpenTag: options.canBeLeftOpenTag,\n    shouldDecodeNewlines: options.shouldDecodeNewlines,\n    start: function start (tag, attrs, unary) {\n      // check namespace.\n      // inherit parent ns if there is one\n      var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);\n\n      // handle IE svg bug\n      /* istanbul ignore if */\n      if (isIE && ns === 'svg') {\n        attrs = guardIESVGBug(attrs);\n      }\n\n      var element = {\n        type: 1,\n        tag: tag,\n        attrsList: attrs,\n        attrsMap: makeAttrsMap(attrs),\n        parent: currentParent,\n        children: []\n      };\n      if (ns) {\n        element.ns = ns;\n      }\n\n      if (isForbiddenTag(element) && !isServerRendering()) {\n        element.forbidden = true;\n        \"development\" !== 'production' && warn$2(\n          'Templates should only be responsible for mapping the state to the ' +\n          'UI. Avoid placing tags with side-effects in your templates, such as ' +\n          \"<\" + tag + \">\" + ', as they will not be parsed.'\n        );\n      }\n\n      // apply pre-transforms\n      for (var i = 0; i < preTransforms.length; i++) {\n        preTransforms[i](element, options);\n      }\n\n      if (!inVPre) {\n        processPre(element);\n        if (element.pre) {\n          inVPre = true;\n        }\n      }\n      if (platformIsPreTag(element.tag)) {\n        inPre = true;\n      }\n      if (inVPre) {\n        processRawAttrs(element);\n      } else {\n        processFor(element);\n        processIf(element);\n        processOnce(element);\n        processKey(element);\n\n        // determine whether this is a plain element after\n        // removing structural attributes\n        element.plain = !element.key && !attrs.length;\n\n        processRef(element);\n        processSlot(element);\n        processComponent(element);\n        for (var i$1 = 0; i$1 < transforms.length; i$1++) {\n          transforms[i$1](element, options);\n        }\n        processAttrs(element);\n      }\n\n      function checkRootConstraints (el) {\n        {\n          if (el.tag === 'slot' || el.tag === 'template') {\n            warnOnce(\n              \"Cannot use <\" + (el.tag) + \"> as component root element because it may \" +\n              'contain multiple nodes.'\n            );\n          }\n          if (el.attrsMap.hasOwnProperty('v-for')) {\n            warnOnce(\n              'Cannot use v-for on stateful component root element because ' +\n              'it renders multiple elements.'\n            );\n          }\n        }\n      }\n\n      // tree management\n      if (!root) {\n        root = element;\n        checkRootConstraints(root);\n      } else if (!stack.length) {\n        // allow root elements with v-if, v-else-if and v-else\n        if (root.if && (element.elseif || element.else)) {\n          checkRootConstraints(element);\n          addIfCondition(root, {\n            exp: element.elseif,\n            block: element\n          });\n        } else {\n          warnOnce(\n            \"Component template should contain exactly one root element. \" +\n            \"If you are using v-if on multiple elements, \" +\n            \"use v-else-if to chain them instead.\"\n          );\n        }\n      }\n      if (currentParent && !element.forbidden) {\n        if (element.elseif || element.else) {\n          processIfConditions(element, currentParent);\n        } else if (element.slotScope) { // scoped slot\n          currentParent.plain = false;\n          var name = element.slotTarget || '\"default\"';(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;\n        } else {\n          currentParent.children.push(element);\n          element.parent = currentParent;\n        }\n      }\n      if (!unary) {\n        currentParent = element;\n        stack.push(element);\n      } else {\n        endPre(element);\n      }\n      // apply post-transforms\n      for (var i$2 = 0; i$2 < postTransforms.length; i$2++) {\n        postTransforms[i$2](element, options);\n      }\n    },\n\n    end: function end () {\n      // remove trailing whitespace\n      var element = stack[stack.length - 1];\n      var lastNode = element.children[element.children.length - 1];\n      if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {\n        element.children.pop();\n      }\n      // pop stack\n      stack.length -= 1;\n      currentParent = stack[stack.length - 1];\n      endPre(element);\n    },\n\n    chars: function chars (text) {\n      if (!currentParent) {\n        {\n          if (text === template) {\n            warnOnce(\n              'Component template requires a root element, rather than just text.'\n            );\n          } else if ((text = text.trim())) {\n            warnOnce(\n              (\"text \\\"\" + text + \"\\\" outside root element will be ignored.\")\n            );\n          }\n        }\n        return\n      }\n      // IE textarea placeholder bug\n      /* istanbul ignore if */\n      if (isIE &&\n          currentParent.tag === 'textarea' &&\n          currentParent.attrsMap.placeholder === text) {\n        return\n      }\n      var children = currentParent.children;\n      text = inPre || text.trim()\n        ? isTextTag(currentParent) ? text : decodeHTMLCached(text)\n        // only preserve whitespace if its not right after a starting tag\n        : preserveWhitespace && children.length ? ' ' : '';\n      if (text) {\n        var expression;\n        if (!inVPre && text !== ' ' && (expression = parseText(text, delimiters))) {\n          children.push({\n            type: 2,\n            expression: expression,\n            text: text\n          });\n        } else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {\n          children.push({\n            type: 3,\n            text: text\n          });\n        }\n      }\n    }\n  });\n  return root\n}\n\nfunction processPre (el) {\n  if (getAndRemoveAttr(el, 'v-pre') != null) {\n    el.pre = true;\n  }\n}\n\nfunction processRawAttrs (el) {\n  var l = el.attrsList.length;\n  if (l) {\n    var attrs = el.attrs = new Array(l);\n    for (var i = 0; i < l; i++) {\n      attrs[i] = {\n        name: el.attrsList[i].name,\n        value: JSON.stringify(el.attrsList[i].value)\n      };\n    }\n  } else if (!el.pre) {\n    // non root node in pre blocks with no attributes\n    el.plain = true;\n  }\n}\n\nfunction processKey (el) {\n  var exp = getBindingAttr(el, 'key');\n  if (exp) {\n    if (\"development\" !== 'production' && el.tag === 'template') {\n      warn$2(\"<template> cannot be keyed. Place the key on real elements instead.\");\n    }\n    el.key = exp;\n  }\n}\n\nfunction processRef (el) {\n  var ref = getBindingAttr(el, 'ref');\n  if (ref) {\n    el.ref = ref;\n    el.refInFor = checkInFor(el);\n  }\n}\n\nfunction processFor (el) {\n  var exp;\n  if ((exp = getAndRemoveAttr(el, 'v-for'))) {\n    var inMatch = exp.match(forAliasRE);\n    if (!inMatch) {\n      \"development\" !== 'production' && warn$2(\n        (\"Invalid v-for expression: \" + exp)\n      );\n      return\n    }\n    el.for = inMatch[2].trim();\n    var alias = inMatch[1].trim();\n    var iteratorMatch = alias.match(forIteratorRE);\n    if (iteratorMatch) {\n      el.alias = iteratorMatch[1].trim();\n      el.iterator1 = iteratorMatch[2].trim();\n      if (iteratorMatch[3]) {\n        el.iterator2 = iteratorMatch[3].trim();\n      }\n    } else {\n      el.alias = alias;\n    }\n  }\n}\n\nfunction processIf (el) {\n  var exp = getAndRemoveAttr(el, 'v-if');\n  if (exp) {\n    el.if = exp;\n    addIfCondition(el, {\n      exp: exp,\n      block: el\n    });\n  } else {\n    if (getAndRemoveAttr(el, 'v-else') != null) {\n      el.else = true;\n    }\n    var elseif = getAndRemoveAttr(el, 'v-else-if');\n    if (elseif) {\n      el.elseif = elseif;\n    }\n  }\n}\n\nfunction processIfConditions (el, parent) {\n  var prev = findPrevElement(parent.children);\n  if (prev && prev.if) {\n    addIfCondition(prev, {\n      exp: el.elseif,\n      block: el\n    });\n  } else {\n    warn$2(\n      \"v-\" + (el.elseif ? ('else-if=\"' + el.elseif + '\"') : 'else') + \" \" +\n      \"used on element <\" + (el.tag) + \"> without corresponding v-if.\"\n    );\n  }\n}\n\nfunction findPrevElement (children) {\n  var i = children.length;\n  while (i--) {\n    if (children[i].type === 1) {\n      return children[i]\n    } else {\n      if (\"development\" !== 'production' && children[i].text !== ' ') {\n        warn$2(\n          \"text \\\"\" + (children[i].text.trim()) + \"\\\" between v-if and v-else(-if) \" +\n          \"will be ignored.\"\n        );\n      }\n      children.pop();\n    }\n  }\n}\n\nfunction addIfCondition (el, condition) {\n  if (!el.ifConditions) {\n    el.ifConditions = [];\n  }\n  el.ifConditions.push(condition);\n}\n\nfunction processOnce (el) {\n  var once$$1 = getAndRemoveAttr(el, 'v-once');\n  if (once$$1 != null) {\n    el.once = true;\n  }\n}\n\nfunction processSlot (el) {\n  if (el.tag === 'slot') {\n    el.slotName = getBindingAttr(el, 'name');\n    if (\"development\" !== 'production' && el.key) {\n      warn$2(\n        \"`key` does not work on <slot> because slots are abstract outlets \" +\n        \"and can possibly expand into multiple elements. \" +\n        \"Use the key on a wrapping element instead.\"\n      );\n    }\n  } else {\n    var slotTarget = getBindingAttr(el, 'slot');\n    if (slotTarget) {\n      el.slotTarget = slotTarget === '\"\"' ? '\"default\"' : slotTarget;\n    }\n    if (el.tag === 'template') {\n      el.slotScope = getAndRemoveAttr(el, 'scope');\n    }\n  }\n}\n\nfunction processComponent (el) {\n  var binding;\n  if ((binding = getBindingAttr(el, 'is'))) {\n    el.component = binding;\n  }\n  if (getAndRemoveAttr(el, 'inline-template') != null) {\n    el.inlineTemplate = true;\n  }\n}\n\nfunction processAttrs (el) {\n  var list = el.attrsList;\n  var i, l, name, rawName, value, modifiers, isProp;\n  for (i = 0, l = list.length; i < l; i++) {\n    name = rawName = list[i].name;\n    value = list[i].value;\n    if (dirRE.test(name)) {\n      // mark element as dynamic\n      el.hasBindings = true;\n      // modifiers\n      modifiers = parseModifiers(name);\n      if (modifiers) {\n        name = name.replace(modifierRE, '');\n      }\n      if (bindRE.test(name)) { // v-bind\n        name = name.replace(bindRE, '');\n        value = parseFilters(value);\n        isProp = false;\n        if (modifiers) {\n          if (modifiers.prop) {\n            isProp = true;\n            name = camelize(name);\n            if (name === 'innerHtml') { name = 'innerHTML'; }\n          }\n          if (modifiers.camel) {\n            name = camelize(name);\n          }\n          if (modifiers.sync) {\n            addHandler(\n              el,\n              (\"update:\" + (camelize(name))),\n              genAssignmentCode(value, \"$event\")\n            );\n          }\n        }\n        if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) {\n          addProp(el, name, value);\n        } else {\n          addAttr(el, name, value);\n        }\n      } else if (onRE.test(name)) { // v-on\n        name = name.replace(onRE, '');\n        addHandler(el, name, value, modifiers, false, warn$2);\n      } else { // normal directives\n        name = name.replace(dirRE, '');\n        // parse arg\n        var argMatch = name.match(argRE);\n        var arg = argMatch && argMatch[1];\n        if (arg) {\n          name = name.slice(0, -(arg.length + 1));\n        }\n        addDirective(el, name, rawName, value, arg, modifiers);\n        if (\"development\" !== 'production' && name === 'model') {\n          checkForAliasModel(el, value);\n        }\n      }\n    } else {\n      // literal attribute\n      {\n        var expression = parseText(value, delimiters);\n        if (expression) {\n          warn$2(\n            name + \"=\\\"\" + value + \"\\\": \" +\n            'Interpolation inside attributes has been removed. ' +\n            'Use v-bind or the colon shorthand instead. For example, ' +\n            'instead of <div id=\"{{ val }}\">, use <div :id=\"val\">.'\n          );\n        }\n      }\n      addAttr(el, name, JSON.stringify(value));\n    }\n  }\n}\n\nfunction checkInFor (el) {\n  var parent = el;\n  while (parent) {\n    if (parent.for !== undefined) {\n      return true\n    }\n    parent = parent.parent;\n  }\n  return false\n}\n\nfunction parseModifiers (name) {\n  var match = name.match(modifierRE);\n  if (match) {\n    var ret = {};\n    match.forEach(function (m) { ret[m.slice(1)] = true; });\n    return ret\n  }\n}\n\nfunction makeAttrsMap (attrs) {\n  var map = {};\n  for (var i = 0, l = attrs.length; i < l; i++) {\n    if (\n      \"development\" !== 'production' &&\n      map[attrs[i].name] && !isIE && !isEdge\n    ) {\n      warn$2('duplicate attribute: ' + attrs[i].name);\n    }\n    map[attrs[i].name] = attrs[i].value;\n  }\n  return map\n}\n\n// for script (e.g. type=\"x/template\") or style, do not decode content\nfunction isTextTag (el) {\n  return el.tag === 'script' || el.tag === 'style'\n}\n\nfunction isForbiddenTag (el) {\n  return (\n    el.tag === 'style' ||\n    (el.tag === 'script' && (\n      !el.attrsMap.type ||\n      el.attrsMap.type === 'text/javascript'\n    ))\n  )\n}\n\nvar ieNSBug = /^xmlns:NS\\d+/;\nvar ieNSPrefix = /^NS\\d+:/;\n\n/* istanbul ignore next */\nfunction guardIESVGBug (attrs) {\n  var res = [];\n  for (var i = 0; i < attrs.length; i++) {\n    var attr = attrs[i];\n    if (!ieNSBug.test(attr.name)) {\n      attr.name = attr.name.replace(ieNSPrefix, '');\n      res.push(attr);\n    }\n  }\n  return res\n}\n\nfunction checkForAliasModel (el, value) {\n  var _el = el;\n  while (_el) {\n    if (_el.for && _el.alias === value) {\n      warn$2(\n        \"<\" + (el.tag) + \" v-model=\\\"\" + value + \"\\\">: \" +\n        \"You are binding v-model directly to a v-for iteration alias. \" +\n        \"This will not be able to modify the v-for source array because \" +\n        \"writing to the alias is like modifying a function local variable. \" +\n        \"Consider using an array of objects and use v-model on an object property instead.\"\n      );\n    }\n    _el = _el.parent;\n  }\n}\n\n/*  */\n\nvar isStaticKey;\nvar isPlatformReservedTag;\n\nvar genStaticKeysCached = cached(genStaticKeys$1);\n\n/**\n * Goal of the optimizer: walk the generated template AST tree\n * and detect sub-trees that are purely static, i.e. parts of\n * the DOM that never needs to change.\n *\n * Once we detect these sub-trees, we can:\n *\n * 1. Hoist them into constants, so that we no longer need to\n *    create fresh nodes for them on each re-render;\n * 2. Completely skip them in the patching process.\n */\nfunction optimize (root, options) {\n  if (!root) { return }\n  isStaticKey = genStaticKeysCached(options.staticKeys || '');\n  isPlatformReservedTag = options.isReservedTag || no;\n  // first pass: mark all non-static nodes.\n  markStatic$1(root);\n  // second pass: mark static roots.\n  markStaticRoots(root, false);\n}\n\nfunction genStaticKeys$1 (keys) {\n  return makeMap(\n    'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +\n    (keys ? ',' + keys : '')\n  )\n}\n\nfunction markStatic$1 (node) {\n  node.static = isStatic(node);\n  if (node.type === 1) {\n    // do not make component slot content static. this avoids\n    // 1. components not able to mutate slot nodes\n    // 2. static slot content fails for hot-reloading\n    if (\n      !isPlatformReservedTag(node.tag) &&\n      node.tag !== 'slot' &&\n      node.attrsMap['inline-template'] == null\n    ) {\n      return\n    }\n    for (var i = 0, l = node.children.length; i < l; i++) {\n      var child = node.children[i];\n      markStatic$1(child);\n      if (!child.static) {\n        node.static = false;\n      }\n    }\n  }\n}\n\nfunction markStaticRoots (node, isInFor) {\n  if (node.type === 1) {\n    if (node.static || node.once) {\n      node.staticInFor = isInFor;\n    }\n    // For a node to qualify as a static root, it should have children that\n    // are not just static text. Otherwise the cost of hoisting out will\n    // outweigh the benefits and it's better off to just always render it fresh.\n    if (node.static && node.children.length && !(\n      node.children.length === 1 &&\n      node.children[0].type === 3\n    )) {\n      node.staticRoot = true;\n      return\n    } else {\n      node.staticRoot = false;\n    }\n    if (node.children) {\n      for (var i = 0, l = node.children.length; i < l; i++) {\n        markStaticRoots(node.children[i], isInFor || !!node.for);\n      }\n    }\n    if (node.ifConditions) {\n      walkThroughConditionsBlocks(node.ifConditions, isInFor);\n    }\n  }\n}\n\nfunction walkThroughConditionsBlocks (conditionBlocks, isInFor) {\n  for (var i = 1, len = conditionBlocks.length; i < len; i++) {\n    markStaticRoots(conditionBlocks[i].block, isInFor);\n  }\n}\n\nfunction isStatic (node) {\n  if (node.type === 2) { // expression\n    return false\n  }\n  if (node.type === 3) { // text\n    return true\n  }\n  return !!(node.pre || (\n    !node.hasBindings && // no dynamic bindings\n    !node.if && !node.for && // not v-if or v-for or v-else\n    !isBuiltInTag(node.tag) && // not a built-in\n    isPlatformReservedTag(node.tag) && // not a component\n    !isDirectChildOfTemplateFor(node) &&\n    Object.keys(node).every(isStaticKey)\n  ))\n}\n\nfunction isDirectChildOfTemplateFor (node) {\n  while (node.parent) {\n    node = node.parent;\n    if (node.tag !== 'template') {\n      return false\n    }\n    if (node.for) {\n      return true\n    }\n  }\n  return false\n}\n\n/*  */\n\nvar fnExpRE = /^\\s*([\\w$_]+|\\([^)]*?\\))\\s*=>|^function\\s*\\(/;\nvar simplePathRE = /^\\s*[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*|\\['.*?']|\\[\".*?\"]|\\[\\d+]|\\[[A-Za-z_$][\\w$]*])*\\s*$/;\n\n// keyCode aliases\nvar keyCodes = {\n  esc: 27,\n  tab: 9,\n  enter: 13,\n  space: 32,\n  up: 38,\n  left: 37,\n  right: 39,\n  down: 40,\n  'delete': [8, 46]\n};\n\n// #4868: modifiers that prevent the execution of the listener\n// need to explicitly return null so that we can determine whether to remove\n// the listener for .once\nvar genGuard = function (condition) { return (\"if(\" + condition + \")return null;\"); };\n\nvar modifierCode = {\n  stop: '$event.stopPropagation();',\n  prevent: '$event.preventDefault();',\n  self: genGuard(\"$event.target !== $event.currentTarget\"),\n  ctrl: genGuard(\"!$event.ctrlKey\"),\n  shift: genGuard(\"!$event.shiftKey\"),\n  alt: genGuard(\"!$event.altKey\"),\n  meta: genGuard(\"!$event.metaKey\"),\n  left: genGuard(\"'button' in $event && $event.button !== 0\"),\n  middle: genGuard(\"'button' in $event && $event.button !== 1\"),\n  right: genGuard(\"'button' in $event && $event.button !== 2\")\n};\n\nfunction genHandlers (\n  events,\n  native,\n  warn\n) {\n  var res = native ? 'nativeOn:{' : 'on:{';\n  for (var name in events) {\n    var handler = events[name];\n    // #5330: warn click.right, since right clicks do not actually fire click events.\n    if (\"development\" !== 'production' &&\n        name === 'click' &&\n        handler && handler.modifiers && handler.modifiers.right\n      ) {\n      warn(\n        \"Use \\\"contextmenu\\\" instead of \\\"click.right\\\" since right clicks \" +\n        \"do not actually fire \\\"click\\\" events.\"\n      );\n    }\n    res += \"\\\"\" + name + \"\\\":\" + (genHandler(name, handler)) + \",\";\n  }\n  return res.slice(0, -1) + '}'\n}\n\nfunction genHandler (\n  name,\n  handler\n) {\n  if (!handler) {\n    return 'function(){}'\n  }\n\n  if (Array.isArray(handler)) {\n    return (\"[\" + (handler.map(function (handler) { return genHandler(name, handler); }).join(',')) + \"]\")\n  }\n\n  var isMethodPath = simplePathRE.test(handler.value);\n  var isFunctionExpression = fnExpRE.test(handler.value);\n\n  if (!handler.modifiers) {\n    return isMethodPath || isFunctionExpression\n      ? handler.value\n      : (\"function($event){\" + (handler.value) + \"}\") // inline statement\n  } else {\n    var code = '';\n    var genModifierCode = '';\n    var keys = [];\n    for (var key in handler.modifiers) {\n      if (modifierCode[key]) {\n        genModifierCode += modifierCode[key];\n        // left/right\n        if (keyCodes[key]) {\n          keys.push(key);\n        }\n      } else {\n        keys.push(key);\n      }\n    }\n    if (keys.length) {\n      code += genKeyFilter(keys);\n    }\n    // Make sure modifiers like prevent and stop get executed after key filtering\n    if (genModifierCode) {\n      code += genModifierCode;\n    }\n    var handlerCode = isMethodPath\n      ? handler.value + '($event)'\n      : isFunctionExpression\n        ? (\"(\" + (handler.value) + \")($event)\")\n        : handler.value;\n    return (\"function($event){\" + code + handlerCode + \"}\")\n  }\n}\n\nfunction genKeyFilter (keys) {\n  return (\"if(!('button' in $event)&&\" + (keys.map(genFilterCode).join('&&')) + \")return null;\")\n}\n\nfunction genFilterCode (key) {\n  var keyVal = parseInt(key, 10);\n  if (keyVal) {\n    return (\"$event.keyCode!==\" + keyVal)\n  }\n  var alias = keyCodes[key];\n  return (\"_k($event.keyCode,\" + (JSON.stringify(key)) + (alias ? ',' + JSON.stringify(alias) : '') + \")\")\n}\n\n/*  */\n\nfunction bind$1 (el, dir) {\n  el.wrapData = function (code) {\n    return (\"_b(\" + code + \",'\" + (el.tag) + \"',\" + (dir.value) + (dir.modifiers && dir.modifiers.prop ? ',true' : '') + \")\")\n  };\n}\n\n/*  */\n\nvar baseDirectives = {\n  bind: bind$1,\n  cloak: noop\n};\n\n/*  */\n\n// configurable state\nvar warn$3;\nvar transforms$1;\nvar dataGenFns;\nvar platformDirectives$1;\nvar isPlatformReservedTag$1;\nvar staticRenderFns;\nvar onceCount;\nvar currentOptions;\n\nfunction generate (\n  ast,\n  options\n) {\n  // save previous staticRenderFns so generate calls can be nested\n  var prevStaticRenderFns = staticRenderFns;\n  var currentStaticRenderFns = staticRenderFns = [];\n  var prevOnceCount = onceCount;\n  onceCount = 0;\n  currentOptions = options;\n  warn$3 = options.warn || baseWarn;\n  transforms$1 = pluckModuleFunction(options.modules, 'transformCode');\n  dataGenFns = pluckModuleFunction(options.modules, 'genData');\n  platformDirectives$1 = options.directives || {};\n  isPlatformReservedTag$1 = options.isReservedTag || no;\n  var code = ast ? genElement(ast) : '_c(\"div\")';\n  staticRenderFns = prevStaticRenderFns;\n  onceCount = prevOnceCount;\n  return {\n    render: (\"with(this){return \" + code + \"}\"),\n    staticRenderFns: currentStaticRenderFns\n  }\n}\n\nfunction genElement (el) {\n  if (el.staticRoot && !el.staticProcessed) {\n    return genStatic(el)\n  } else if (el.once && !el.onceProcessed) {\n    return genOnce(el)\n  } else if (el.for && !el.forProcessed) {\n    return genFor(el)\n  } else if (el.if && !el.ifProcessed) {\n    return genIf(el)\n  } else if (el.tag === 'template' && !el.slotTarget) {\n    return genChildren(el) || 'void 0'\n  } else if (el.tag === 'slot') {\n    return genSlot(el)\n  } else {\n    // component or element\n    var code;\n    if (el.component) {\n      code = genComponent(el.component, el);\n    } else {\n      var data = el.plain ? undefined : genData(el);\n\n      var children = el.inlineTemplate ? null : genChildren(el, true);\n      code = \"_c('\" + (el.tag) + \"'\" + (data ? (\",\" + data) : '') + (children ? (\",\" + children) : '') + \")\";\n    }\n    // module transforms\n    for (var i = 0; i < transforms$1.length; i++) {\n      code = transforms$1[i](el, code);\n    }\n    return code\n  }\n}\n\n// hoist static sub-trees out\nfunction genStatic (el) {\n  el.staticProcessed = true;\n  staticRenderFns.push((\"with(this){return \" + (genElement(el)) + \"}\"));\n  return (\"_m(\" + (staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + \")\")\n}\n\n// v-once\nfunction genOnce (el) {\n  el.onceProcessed = true;\n  if (el.if && !el.ifProcessed) {\n    return genIf(el)\n  } else if (el.staticInFor) {\n    var key = '';\n    var parent = el.parent;\n    while (parent) {\n      if (parent.for) {\n        key = parent.key;\n        break\n      }\n      parent = parent.parent;\n    }\n    if (!key) {\n      \"development\" !== 'production' && warn$3(\n        \"v-once can only be used inside v-for that is keyed. \"\n      );\n      return genElement(el)\n    }\n    return (\"_o(\" + (genElement(el)) + \",\" + (onceCount++) + (key ? (\",\" + key) : \"\") + \")\")\n  } else {\n    return genStatic(el)\n  }\n}\n\nfunction genIf (el) {\n  el.ifProcessed = true; // avoid recursion\n  return genIfConditions(el.ifConditions.slice())\n}\n\nfunction genIfConditions (conditions) {\n  if (!conditions.length) {\n    return '_e()'\n  }\n\n  var condition = conditions.shift();\n  if (condition.exp) {\n    return (\"(\" + (condition.exp) + \")?\" + (genTernaryExp(condition.block)) + \":\" + (genIfConditions(conditions)))\n  } else {\n    return (\"\" + (genTernaryExp(condition.block)))\n  }\n\n  // v-if with v-once should generate code like (a)?_m(0):_m(1)\n  function genTernaryExp (el) {\n    return el.once ? genOnce(el) : genElement(el)\n  }\n}\n\nfunction genFor (el) {\n  var exp = el.for;\n  var alias = el.alias;\n  var iterator1 = el.iterator1 ? (\",\" + (el.iterator1)) : '';\n  var iterator2 = el.iterator2 ? (\",\" + (el.iterator2)) : '';\n\n  if (\n    \"development\" !== 'production' &&\n    maybeComponent(el) && el.tag !== 'slot' && el.tag !== 'template' && !el.key\n  ) {\n    warn$3(\n      \"<\" + (el.tag) + \" v-for=\\\"\" + alias + \" in \" + exp + \"\\\">: component lists rendered with \" +\n      \"v-for should have explicit keys. \" +\n      \"See https://vuejs.org/guide/list.html#key for more info.\",\n      true /* tip */\n    );\n  }\n\n  el.forProcessed = true; // avoid recursion\n  return \"_l((\" + exp + \"),\" +\n    \"function(\" + alias + iterator1 + iterator2 + \"){\" +\n      \"return \" + (genElement(el)) +\n    '})'\n}\n\nfunction genData (el) {\n  var data = '{';\n\n  // directives first.\n  // directives may mutate the el's other properties before they are generated.\n  var dirs = genDirectives(el);\n  if (dirs) { data += dirs + ','; }\n\n  // key\n  if (el.key) {\n    data += \"key:\" + (el.key) + \",\";\n  }\n  // ref\n  if (el.ref) {\n    data += \"ref:\" + (el.ref) + \",\";\n  }\n  if (el.refInFor) {\n    data += \"refInFor:true,\";\n  }\n  // pre\n  if (el.pre) {\n    data += \"pre:true,\";\n  }\n  // record original tag name for components using \"is\" attribute\n  if (el.component) {\n    data += \"tag:\\\"\" + (el.tag) + \"\\\",\";\n  }\n  // module data generation functions\n  for (var i = 0; i < dataGenFns.length; i++) {\n    data += dataGenFns[i](el);\n  }\n  // attributes\n  if (el.attrs) {\n    data += \"attrs:{\" + (genProps(el.attrs)) + \"},\";\n  }\n  // DOM props\n  if (el.props) {\n    data += \"domProps:{\" + (genProps(el.props)) + \"},\";\n  }\n  // event handlers\n  if (el.events) {\n    data += (genHandlers(el.events, false, warn$3)) + \",\";\n  }\n  if (el.nativeEvents) {\n    data += (genHandlers(el.nativeEvents, true, warn$3)) + \",\";\n  }\n  // slot target\n  if (el.slotTarget) {\n    data += \"slot:\" + (el.slotTarget) + \",\";\n  }\n  // scoped slots\n  if (el.scopedSlots) {\n    data += (genScopedSlots(el.scopedSlots)) + \",\";\n  }\n  // component v-model\n  if (el.model) {\n    data += \"model:{value:\" + (el.model.value) + \",callback:\" + (el.model.callback) + \",expression:\" + (el.model.expression) + \"},\";\n  }\n  // inline-template\n  if (el.inlineTemplate) {\n    var inlineTemplate = genInlineTemplate(el);\n    if (inlineTemplate) {\n      data += inlineTemplate + \",\";\n    }\n  }\n  data = data.replace(/,$/, '') + '}';\n  // v-bind data wrap\n  if (el.wrapData) {\n    data = el.wrapData(data);\n  }\n  return data\n}\n\nfunction genDirectives (el) {\n  var dirs = el.directives;\n  if (!dirs) { return }\n  var res = 'directives:[';\n  var hasRuntime = false;\n  var i, l, dir, needRuntime;\n  for (i = 0, l = dirs.length; i < l; i++) {\n    dir = dirs[i];\n    needRuntime = true;\n    var gen = platformDirectives$1[dir.name] || baseDirectives[dir.name];\n    if (gen) {\n      // compile-time directive that manipulates AST.\n      // returns true if it also needs a runtime counterpart.\n      needRuntime = !!gen(el, dir, warn$3);\n    }\n    if (needRuntime) {\n      hasRuntime = true;\n      res += \"{name:\\\"\" + (dir.name) + \"\\\",rawName:\\\"\" + (dir.rawName) + \"\\\"\" + (dir.value ? (\",value:(\" + (dir.value) + \"),expression:\" + (JSON.stringify(dir.value))) : '') + (dir.arg ? (\",arg:\\\"\" + (dir.arg) + \"\\\"\") : '') + (dir.modifiers ? (\",modifiers:\" + (JSON.stringify(dir.modifiers))) : '') + \"},\";\n    }\n  }\n  if (hasRuntime) {\n    return res.slice(0, -1) + ']'\n  }\n}\n\nfunction genInlineTemplate (el) {\n  var ast = el.children[0];\n  if (\"development\" !== 'production' && (\n    el.children.length > 1 || ast.type !== 1\n  )) {\n    warn$3('Inline-template components must have exactly one child element.');\n  }\n  if (ast.type === 1) {\n    var inlineRenderFns = generate(ast, currentOptions);\n    return (\"inlineTemplate:{render:function(){\" + (inlineRenderFns.render) + \"},staticRenderFns:[\" + (inlineRenderFns.staticRenderFns.map(function (code) { return (\"function(){\" + code + \"}\"); }).join(',')) + \"]}\")\n  }\n}\n\nfunction genScopedSlots (slots) {\n  return (\"scopedSlots:_u([\" + (Object.keys(slots).map(function (key) { return genScopedSlot(key, slots[key]); }).join(',')) + \"])\")\n}\n\nfunction genScopedSlot (key, el) {\n  return \"[\" + key + \",function(\" + (String(el.attrsMap.scope)) + \"){\" +\n    \"return \" + (el.tag === 'template'\n      ? genChildren(el) || 'void 0'\n      : genElement(el)) + \"}]\"\n}\n\nfunction genChildren (el, checkSkip) {\n  var children = el.children;\n  if (children.length) {\n    var el$1 = children[0];\n    // optimize single v-for\n    if (children.length === 1 &&\n        el$1.for &&\n        el$1.tag !== 'template' &&\n        el$1.tag !== 'slot') {\n      return genElement(el$1)\n    }\n    var normalizationType = checkSkip ? getNormalizationType(children) : 0;\n    return (\"[\" + (children.map(genNode).join(',')) + \"]\" + (normalizationType ? (\",\" + normalizationType) : ''))\n  }\n}\n\n// determine the normalization needed for the children array.\n// 0: no normalization needed\n// 1: simple normalization needed (possible 1-level deep nested array)\n// 2: full normalization needed\nfunction getNormalizationType (children) {\n  var res = 0;\n  for (var i = 0; i < children.length; i++) {\n    var el = children[i];\n    if (el.type !== 1) {\n      continue\n    }\n    if (needsNormalization(el) ||\n        (el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {\n      res = 2;\n      break\n    }\n    if (maybeComponent(el) ||\n        (el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {\n      res = 1;\n    }\n  }\n  return res\n}\n\nfunction needsNormalization (el) {\n  return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'\n}\n\nfunction maybeComponent (el) {\n  return !isPlatformReservedTag$1(el.tag)\n}\n\nfunction genNode (node) {\n  if (node.type === 1) {\n    return genElement(node)\n  } else {\n    return genText(node)\n  }\n}\n\nfunction genText (text) {\n  return (\"_v(\" + (text.type === 2\n    ? text.expression // no need for () because already wrapped in _s()\n    : transformSpecialNewlines(JSON.stringify(text.text))) + \")\")\n}\n\nfunction genSlot (el) {\n  var slotName = el.slotName || '\"default\"';\n  var children = genChildren(el);\n  var res = \"_t(\" + slotName + (children ? (\",\" + children) : '');\n  var attrs = el.attrs && (\"{\" + (el.attrs.map(function (a) { return ((camelize(a.name)) + \":\" + (a.value)); }).join(',')) + \"}\");\n  var bind$$1 = el.attrsMap['v-bind'];\n  if ((attrs || bind$$1) && !children) {\n    res += \",null\";\n  }\n  if (attrs) {\n    res += \",\" + attrs;\n  }\n  if (bind$$1) {\n    res += (attrs ? '' : ',null') + \",\" + bind$$1;\n  }\n  return res + ')'\n}\n\n// componentName is el.component, take it as argument to shun flow's pessimistic refinement\nfunction genComponent (componentName, el) {\n  var children = el.inlineTemplate ? null : genChildren(el, true);\n  return (\"_c(\" + componentName + \",\" + (genData(el)) + (children ? (\",\" + children) : '') + \")\")\n}\n\nfunction genProps (props) {\n  var res = '';\n  for (var i = 0; i < props.length; i++) {\n    var prop = props[i];\n    res += \"\\\"\" + (prop.name) + \"\\\":\" + (transformSpecialNewlines(prop.value)) + \",\";\n  }\n  return res.slice(0, -1)\n}\n\n// #3895, #4268\nfunction transformSpecialNewlines (text) {\n  return text\n    .replace(/\\u2028/g, '\\\\u2028')\n    .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/*  */\n\n// these keywords should not appear inside expressions, but operators like\n// typeof, instanceof and in are allowed\nvar prohibitedKeywordRE = new RegExp('\\\\b' + (\n  'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +\n  'super,throw,while,yield,delete,export,import,return,switch,default,' +\n  'extends,finally,continue,debugger,function,arguments'\n).split(',').join('\\\\b|\\\\b') + '\\\\b');\n\n// these unary operators should not be used as property/method names\nvar unaryOperatorsRE = new RegExp('\\\\b' + (\n  'delete,typeof,void'\n).split(',').join('\\\\s*\\\\([^\\\\)]*\\\\)|\\\\b') + '\\\\s*\\\\([^\\\\)]*\\\\)');\n\n// check valid identifier for v-for\nvar identRE = /[A-Za-z_$][\\w$]*/;\n\n// strip strings in expressions\nvar stripStringRE = /'(?:[^'\\\\]|\\\\.)*'|\"(?:[^\"\\\\]|\\\\.)*\"|`(?:[^`\\\\]|\\\\.)*\\$\\{|\\}(?:[^`\\\\]|\\\\.)*`|`(?:[^`\\\\]|\\\\.)*`/g;\n\n// detect problematic expressions in a template\nfunction detectErrors (ast) {\n  var errors = [];\n  if (ast) {\n    checkNode(ast, errors);\n  }\n  return errors\n}\n\nfunction checkNode (node, errors) {\n  if (node.type === 1) {\n    for (var name in node.attrsMap) {\n      if (dirRE.test(name)) {\n        var value = node.attrsMap[name];\n        if (value) {\n          if (name === 'v-for') {\n            checkFor(node, (\"v-for=\\\"\" + value + \"\\\"\"), errors);\n          } else if (onRE.test(name)) {\n            checkEvent(value, (name + \"=\\\"\" + value + \"\\\"\"), errors);\n          } else {\n            checkExpression(value, (name + \"=\\\"\" + value + \"\\\"\"), errors);\n          }\n        }\n      }\n    }\n    if (node.children) {\n      for (var i = 0; i < node.children.length; i++) {\n        checkNode(node.children[i], errors);\n      }\n    }\n  } else if (node.type === 2) {\n    checkExpression(node.expression, node.text, errors);\n  }\n}\n\nfunction checkEvent (exp, text, errors) {\n  var stipped = exp.replace(stripStringRE, '');\n  var keywordMatch = stipped.match(unaryOperatorsRE);\n  if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {\n    errors.push(\n      \"avoid using JavaScript unary operator as property name: \" +\n      \"\\\"\" + (keywordMatch[0]) + \"\\\" in expression \" + (text.trim())\n    );\n  }\n  checkExpression(exp, text, errors);\n}\n\nfunction checkFor (node, text, errors) {\n  checkExpression(node.for || '', text, errors);\n  checkIdentifier(node.alias, 'v-for alias', text, errors);\n  checkIdentifier(node.iterator1, 'v-for iterator', text, errors);\n  checkIdentifier(node.iterator2, 'v-for iterator', text, errors);\n}\n\nfunction checkIdentifier (ident, type, text, errors) {\n  if (typeof ident === 'string' && !identRE.test(ident)) {\n    errors.push((\"invalid \" + type + \" \\\"\" + ident + \"\\\" in expression: \" + (text.trim())));\n  }\n}\n\nfunction checkExpression (exp, text, errors) {\n  try {\n    new Function((\"return \" + exp));\n  } catch (e) {\n    var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE);\n    if (keywordMatch) {\n      errors.push(\n        \"avoid using JavaScript keyword as property name: \" +\n        \"\\\"\" + (keywordMatch[0]) + \"\\\" in expression \" + (text.trim())\n      );\n    } else {\n      errors.push((\"invalid expression: \" + (text.trim())));\n    }\n  }\n}\n\n/*  */\n\nfunction baseCompile (\n  template,\n  options\n) {\n  var ast = parse(template.trim(), options);\n  optimize(ast, options);\n  var code = generate(ast, options);\n  return {\n    ast: ast,\n    render: code.render,\n    staticRenderFns: code.staticRenderFns\n  }\n}\n\nfunction makeFunction (code, errors) {\n  try {\n    return new Function(code)\n  } catch (err) {\n    errors.push({ err: err, code: code });\n    return noop\n  }\n}\n\nfunction createCompiler (baseOptions) {\n  var functionCompileCache = Object.create(null);\n\n  function compile (\n    template,\n    options\n  ) {\n    var finalOptions = Object.create(baseOptions);\n    var errors = [];\n    var tips = [];\n    finalOptions.warn = function (msg, tip$$1) {\n      (tip$$1 ? tips : errors).push(msg);\n    };\n\n    if (options) {\n      // merge custom modules\n      if (options.modules) {\n        finalOptions.modules = (baseOptions.modules || []).concat(options.modules);\n      }\n      // merge custom directives\n      if (options.directives) {\n        finalOptions.directives = extend(\n          Object.create(baseOptions.directives),\n          options.directives\n        );\n      }\n      // copy other options\n      for (var key in options) {\n        if (key !== 'modules' && key !== 'directives') {\n          finalOptions[key] = options[key];\n        }\n      }\n    }\n\n    var compiled = baseCompile(template, finalOptions);\n    {\n      errors.push.apply(errors, detectErrors(compiled.ast));\n    }\n    compiled.errors = errors;\n    compiled.tips = tips;\n    return compiled\n  }\n\n  function compileToFunctions (\n    template,\n    options,\n    vm\n  ) {\n    options = options || {};\n\n    /* istanbul ignore if */\n    {\n      // detect possible CSP restriction\n      try {\n        new Function('return 1');\n      } catch (e) {\n        if (e.toString().match(/unsafe-eval|CSP/)) {\n          warn(\n            'It seems you are using the standalone build of Vue.js in an ' +\n            'environment with Content Security Policy that prohibits unsafe-eval. ' +\n            'The template compiler cannot work in this environment. Consider ' +\n            'relaxing the policy to allow unsafe-eval or pre-compiling your ' +\n            'templates into render functions.'\n          );\n        }\n      }\n    }\n\n    // check cache\n    var key = options.delimiters\n      ? String(options.delimiters) + template\n      : template;\n    if (functionCompileCache[key]) {\n      return functionCompileCache[key]\n    }\n\n    // compile\n    var compiled = compile(template, options);\n\n    // check compilation errors/tips\n    {\n      if (compiled.errors && compiled.errors.length) {\n        warn(\n          \"Error compiling template:\\n\\n\" + template + \"\\n\\n\" +\n          compiled.errors.map(function (e) { return (\"- \" + e); }).join('\\n') + '\\n',\n          vm\n        );\n      }\n      if (compiled.tips && compiled.tips.length) {\n        compiled.tips.forEach(function (msg) { return tip(msg, vm); });\n      }\n    }\n\n    // turn code into functions\n    var res = {};\n    var fnGenErrors = [];\n    res.render = makeFunction(compiled.render, fnGenErrors);\n    var l = compiled.staticRenderFns.length;\n    res.staticRenderFns = new Array(l);\n    for (var i = 0; i < l; i++) {\n      res.staticRenderFns[i] = makeFunction(compiled.staticRenderFns[i], fnGenErrors);\n    }\n\n    // check function generation errors.\n    // this should only happen if there is a bug in the compiler itself.\n    // mostly for codegen development use\n    /* istanbul ignore if */\n    {\n      if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {\n        warn(\n          \"Failed to generate render function:\\n\\n\" +\n          fnGenErrors.map(function (ref) {\n            var err = ref.err;\n            var code = ref.code;\n\n            return ((err.toString()) + \" in\\n\\n\" + code + \"\\n\");\n        }).join('\\n'),\n          vm\n        );\n      }\n    }\n\n    return (functionCompileCache[key] = res)\n  }\n\n  return {\n    compile: compile,\n    compileToFunctions: compileToFunctions\n  }\n}\n\n/*  */\n\nfunction transformNode (el, options) {\n  var warn = options.warn || baseWarn;\n  var staticClass = getAndRemoveAttr(el, 'class');\n  if (\"development\" !== 'production' && staticClass) {\n    var expression = parseText(staticClass, options.delimiters);\n    if (expression) {\n      warn(\n        \"class=\\\"\" + staticClass + \"\\\": \" +\n        'Interpolation inside attributes has been removed. ' +\n        'Use v-bind or the colon shorthand instead. For example, ' +\n        'instead of <div class=\"{{ val }}\">, use <div :class=\"val\">.'\n      );\n    }\n  }\n  if (staticClass) {\n    el.staticClass = JSON.stringify(staticClass);\n  }\n  var classBinding = getBindingAttr(el, 'class', false /* getStatic */);\n  if (classBinding) {\n    el.classBinding = classBinding;\n  }\n}\n\nfunction genData$1 (el) {\n  var data = '';\n  if (el.staticClass) {\n    data += \"staticClass:\" + (el.staticClass) + \",\";\n  }\n  if (el.classBinding) {\n    data += \"class:\" + (el.classBinding) + \",\";\n  }\n  return data\n}\n\nvar klass$1 = {\n  staticKeys: ['staticClass'],\n  transformNode: transformNode,\n  genData: genData$1\n};\n\n/*  */\n\nfunction transformNode$1 (el, options) {\n  var warn = options.warn || baseWarn;\n  var staticStyle = getAndRemoveAttr(el, 'style');\n  if (staticStyle) {\n    /* istanbul ignore if */\n    {\n      var expression = parseText(staticStyle, options.delimiters);\n      if (expression) {\n        warn(\n          \"style=\\\"\" + staticStyle + \"\\\": \" +\n          'Interpolation inside attributes has been removed. ' +\n          'Use v-bind or the colon shorthand instead. For example, ' +\n          'instead of <div style=\"{{ val }}\">, use <div :style=\"val\">.'\n        );\n      }\n    }\n    el.staticStyle = JSON.stringify(parseStyleText(staticStyle));\n  }\n\n  var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);\n  if (styleBinding) {\n    el.styleBinding = styleBinding;\n  }\n}\n\nfunction genData$2 (el) {\n  var data = '';\n  if (el.staticStyle) {\n    data += \"staticStyle:\" + (el.staticStyle) + \",\";\n  }\n  if (el.styleBinding) {\n    data += \"style:(\" + (el.styleBinding) + \"),\";\n  }\n  return data\n}\n\nvar style$1 = {\n  staticKeys: ['staticStyle'],\n  transformNode: transformNode$1,\n  genData: genData$2\n};\n\nvar modules$1 = [\n  klass$1,\n  style$1\n];\n\n/*  */\n\nfunction text (el, dir) {\n  if (dir.value) {\n    addProp(el, 'textContent', (\"_s(\" + (dir.value) + \")\"));\n  }\n}\n\n/*  */\n\nfunction html (el, dir) {\n  if (dir.value) {\n    addProp(el, 'innerHTML', (\"_s(\" + (dir.value) + \")\"));\n  }\n}\n\nvar directives$1 = {\n  model: model,\n  text: text,\n  html: html\n};\n\n/*  */\n\nvar baseOptions = {\n  expectHTML: true,\n  modules: modules$1,\n  directives: directives$1,\n  isPreTag: isPreTag,\n  isUnaryTag: isUnaryTag,\n  mustUseProp: mustUseProp,\n  canBeLeftOpenTag: canBeLeftOpenTag,\n  isReservedTag: isReservedTag,\n  getTagNamespace: getTagNamespace,\n  staticKeys: genStaticKeys(modules$1)\n};\n\nvar ref$1 = createCompiler(baseOptions);\nvar compileToFunctions = ref$1.compileToFunctions;\n\n/*  */\n\nvar idToTemplate = cached(function (id) {\n  var el = query(id);\n  return el && el.innerHTML\n});\n\nvar mount = Vue$3.prototype.$mount;\nVue$3.prototype.$mount = function (\n  el,\n  hydrating\n) {\n  el = el && query(el);\n\n  /* istanbul ignore if */\n  if (el === document.body || el === document.documentElement) {\n    \"development\" !== 'production' && warn(\n      \"Do not mount Vue to <html> or <body> - mount to normal elements instead.\"\n    );\n    return this\n  }\n\n  var options = this.$options;\n  // resolve template/el and convert to render function\n  if (!options.render) {\n    var template = options.template;\n    if (template) {\n      if (typeof template === 'string') {\n        if (template.charAt(0) === '#') {\n          template = idToTemplate(template);\n          /* istanbul ignore if */\n          if (\"development\" !== 'production' && !template) {\n            warn(\n              (\"Template element not found or is empty: \" + (options.template)),\n              this\n            );\n          }\n        }\n      } else if (template.nodeType) {\n        template = template.innerHTML;\n      } else {\n        {\n          warn('invalid template option:' + template, this);\n        }\n        return this\n      }\n    } else if (el) {\n      template = getOuterHTML(el);\n    }\n    if (template) {\n      /* istanbul ignore if */\n      if (\"development\" !== 'production' && config.performance && mark) {\n        mark('compile');\n      }\n\n      var ref = compileToFunctions(template, {\n        shouldDecodeNewlines: shouldDecodeNewlines,\n        delimiters: options.delimiters\n      }, this);\n      var render = ref.render;\n      var staticRenderFns = ref.staticRenderFns;\n      options.render = render;\n      options.staticRenderFns = staticRenderFns;\n\n      /* istanbul ignore if */\n      if (\"development\" !== 'production' && config.performance && mark) {\n        mark('compile end');\n        measure(((this._name) + \" compile\"), 'compile', 'compile end');\n      }\n    }\n  }\n  return mount.call(this, el, hydrating)\n};\n\n/**\n * Get outerHTML of elements, taking care\n * of SVG elements in IE as well.\n */\nfunction getOuterHTML (el) {\n  if (el.outerHTML) {\n    return el.outerHTML\n  } else {\n    var container = document.createElement('div');\n    container.appendChild(el.cloneNode(true));\n    return container.innerHTML\n  }\n}\n\nVue$3.compile = compileToFunctions;\n\nreturn Vue$3;\n\n})));"
  }
]